1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2018 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
32 #include "dwarf2read.h"
33 #include "dwarf-index-common.h"
42 #include "gdb-demangle.h"
43 #include "expression.h"
44 #include "filenames.h" /* for DOSish file names */
47 #include "complaints.h"
49 #include "dwarf2expr.h"
50 #include "dwarf2loc.h"
51 #include "cp-support.h"
57 #include "typeprint.h"
60 #include "completer.h"
65 #include "gdbcore.h" /* for gnutarget */
66 #include "gdb/gdb-index.h"
71 #include "filestuff.h"
73 #include "namespace.h"
74 #include "common/gdb_unlinker.h"
75 #include "common/function-view.h"
76 #include "common/gdb_optional.h"
77 #include "common/underlying.h"
78 #include "common/byte-vector.h"
79 #include "common/hash_enum.h"
80 #include "filename-seen-cache.h"
83 #include <sys/types.h>
85 #include <unordered_set>
86 #include <unordered_map>
90 #include <forward_list>
91 #include "rust-lang.h"
92 #include "common/pathstuff.h"
94 /* When == 1, print basic high level tracing messages.
95 When > 1, be more verbose.
96 This is in contrast to the low level DIE reading of dwarf_die_debug. */
97 static unsigned int dwarf_read_debug
= 0;
99 /* When non-zero, dump DIEs after they are read in. */
100 static unsigned int dwarf_die_debug
= 0;
102 /* When non-zero, dump line number entries as they are read in. */
103 static unsigned int dwarf_line_debug
= 0;
105 /* When non-zero, cross-check physname against demangler. */
106 static int check_physname
= 0;
108 /* When non-zero, do not reject deprecated .gdb_index sections. */
109 static int use_deprecated_index_sections
= 0;
111 static const struct objfile_data
*dwarf2_objfile_data_key
;
113 /* The "aclass" indices for various kinds of computed DWARF symbols. */
115 static int dwarf2_locexpr_index
;
116 static int dwarf2_loclist_index
;
117 static int dwarf2_locexpr_block_index
;
118 static int dwarf2_loclist_block_index
;
120 /* An index into a (C++) symbol name component in a symbol name as
121 recorded in the mapped_index's symbol table. For each C++ symbol
122 in the symbol table, we record one entry for the start of each
123 component in the symbol in a table of name components, and then
124 sort the table, in order to be able to binary search symbol names,
125 ignoring leading namespaces, both completion and regular look up.
126 For example, for symbol "A::B::C", we'll have an entry that points
127 to "A::B::C", another that points to "B::C", and another for "C".
128 Note that function symbols in GDB index have no parameter
129 information, just the function/method names. You can convert a
130 name_component to a "const char *" using the
131 'mapped_index::symbol_name_at(offset_type)' method. */
133 struct name_component
135 /* Offset in the symbol name where the component starts. Stored as
136 a (32-bit) offset instead of a pointer to save memory and improve
137 locality on 64-bit architectures. */
138 offset_type name_offset
;
140 /* The symbol's index in the symbol and constant pool tables of a
145 /* Base class containing bits shared by both .gdb_index and
146 .debug_name indexes. */
148 struct mapped_index_base
150 /* The name_component table (a sorted vector). See name_component's
151 description above. */
152 std::vector
<name_component
> name_components
;
154 /* How NAME_COMPONENTS is sorted. */
155 enum case_sensitivity name_components_casing
;
157 /* Return the number of names in the symbol table. */
158 virtual size_t symbol_name_count () const = 0;
160 /* Get the name of the symbol at IDX in the symbol table. */
161 virtual const char *symbol_name_at (offset_type idx
) const = 0;
163 /* Return whether the name at IDX in the symbol table should be
165 virtual bool symbol_name_slot_invalid (offset_type idx
) const
170 /* Build the symbol name component sorted vector, if we haven't
172 void build_name_components ();
174 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
175 possible matches for LN_NO_PARAMS in the name component
177 std::pair
<std::vector
<name_component
>::const_iterator
,
178 std::vector
<name_component
>::const_iterator
>
179 find_name_components_bounds (const lookup_name_info
&ln_no_params
) const;
181 /* Prevent deleting/destroying via a base class pointer. */
183 ~mapped_index_base() = default;
186 /* A description of the mapped index. The file format is described in
187 a comment by the code that writes the index. */
188 struct mapped_index final
: public mapped_index_base
190 /* A slot/bucket in the symbol table hash. */
191 struct symbol_table_slot
193 const offset_type name
;
194 const offset_type vec
;
197 /* Index data format version. */
200 /* The address table data. */
201 gdb::array_view
<const gdb_byte
> address_table
;
203 /* The symbol table, implemented as a hash table. */
204 gdb::array_view
<symbol_table_slot
> symbol_table
;
206 /* A pointer to the constant pool. */
207 const char *constant_pool
= nullptr;
209 bool symbol_name_slot_invalid (offset_type idx
) const override
211 const auto &bucket
= this->symbol_table
[idx
];
212 return bucket
.name
== 0 && bucket
.vec
;
215 /* Convenience method to get at the name of the symbol at IDX in the
217 const char *symbol_name_at (offset_type idx
) const override
218 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
220 size_t symbol_name_count () const override
221 { return this->symbol_table
.size (); }
224 /* A description of the mapped .debug_names.
225 Uninitialized map has CU_COUNT 0. */
226 struct mapped_debug_names final
: public mapped_index_base
228 mapped_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile_
)
229 : dwarf2_per_objfile (dwarf2_per_objfile_
)
232 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
233 bfd_endian dwarf5_byte_order
;
234 bool dwarf5_is_dwarf64
;
235 bool augmentation_is_gdb
;
237 uint32_t cu_count
= 0;
238 uint32_t tu_count
, bucket_count
, name_count
;
239 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
240 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
241 const gdb_byte
*name_table_string_offs_reordered
;
242 const gdb_byte
*name_table_entry_offs_reordered
;
243 const gdb_byte
*entry_pool
;
250 /* Attribute name DW_IDX_*. */
253 /* Attribute form DW_FORM_*. */
256 /* Value if FORM is DW_FORM_implicit_const. */
257 LONGEST implicit_const
;
259 std::vector
<attr
> attr_vec
;
262 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
264 const char *namei_to_name (uint32_t namei
) const;
266 /* Implementation of the mapped_index_base virtual interface, for
267 the name_components cache. */
269 const char *symbol_name_at (offset_type idx
) const override
270 { return namei_to_name (idx
); }
272 size_t symbol_name_count () const override
273 { return this->name_count
; }
276 /* See dwarf2read.h. */
279 get_dwarf2_per_objfile (struct objfile
*objfile
)
281 return ((struct dwarf2_per_objfile
*)
282 objfile_data (objfile
, dwarf2_objfile_data_key
));
285 /* Set the dwarf2_per_objfile associated to OBJFILE. */
288 set_dwarf2_per_objfile (struct objfile
*objfile
,
289 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
291 gdb_assert (get_dwarf2_per_objfile (objfile
) == NULL
);
292 set_objfile_data (objfile
, dwarf2_objfile_data_key
, dwarf2_per_objfile
);
295 /* Default names of the debugging sections. */
297 /* Note that if the debugging section has been compressed, it might
298 have a name like .zdebug_info. */
300 static const struct dwarf2_debug_sections dwarf2_elf_names
=
302 { ".debug_info", ".zdebug_info" },
303 { ".debug_abbrev", ".zdebug_abbrev" },
304 { ".debug_line", ".zdebug_line" },
305 { ".debug_loc", ".zdebug_loc" },
306 { ".debug_loclists", ".zdebug_loclists" },
307 { ".debug_macinfo", ".zdebug_macinfo" },
308 { ".debug_macro", ".zdebug_macro" },
309 { ".debug_str", ".zdebug_str" },
310 { ".debug_line_str", ".zdebug_line_str" },
311 { ".debug_ranges", ".zdebug_ranges" },
312 { ".debug_rnglists", ".zdebug_rnglists" },
313 { ".debug_types", ".zdebug_types" },
314 { ".debug_addr", ".zdebug_addr" },
315 { ".debug_frame", ".zdebug_frame" },
316 { ".eh_frame", NULL
},
317 { ".gdb_index", ".zgdb_index" },
318 { ".debug_names", ".zdebug_names" },
319 { ".debug_aranges", ".zdebug_aranges" },
323 /* List of DWO/DWP sections. */
325 static const struct dwop_section_names
327 struct dwarf2_section_names abbrev_dwo
;
328 struct dwarf2_section_names info_dwo
;
329 struct dwarf2_section_names line_dwo
;
330 struct dwarf2_section_names loc_dwo
;
331 struct dwarf2_section_names loclists_dwo
;
332 struct dwarf2_section_names macinfo_dwo
;
333 struct dwarf2_section_names macro_dwo
;
334 struct dwarf2_section_names str_dwo
;
335 struct dwarf2_section_names str_offsets_dwo
;
336 struct dwarf2_section_names types_dwo
;
337 struct dwarf2_section_names cu_index
;
338 struct dwarf2_section_names tu_index
;
342 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
343 { ".debug_info.dwo", ".zdebug_info.dwo" },
344 { ".debug_line.dwo", ".zdebug_line.dwo" },
345 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
346 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
347 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
348 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
349 { ".debug_str.dwo", ".zdebug_str.dwo" },
350 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
351 { ".debug_types.dwo", ".zdebug_types.dwo" },
352 { ".debug_cu_index", ".zdebug_cu_index" },
353 { ".debug_tu_index", ".zdebug_tu_index" },
356 /* local data types */
358 /* The data in a compilation unit header, after target2host
359 translation, looks like this. */
360 struct comp_unit_head
364 unsigned char addr_size
;
365 unsigned char signed_addr_p
;
366 sect_offset abbrev_sect_off
;
368 /* Size of file offsets; either 4 or 8. */
369 unsigned int offset_size
;
371 /* Size of the length field; either 4 or 12. */
372 unsigned int initial_length_size
;
374 enum dwarf_unit_type unit_type
;
376 /* Offset to the first byte of this compilation unit header in the
377 .debug_info section, for resolving relative reference dies. */
378 sect_offset sect_off
;
380 /* Offset to first die in this cu from the start of the cu.
381 This will be the first byte following the compilation unit header. */
382 cu_offset first_die_cu_offset
;
384 /* 64-bit signature of this type unit - it is valid only for
385 UNIT_TYPE DW_UT_type. */
388 /* For types, offset in the type's DIE of the type defined by this TU. */
389 cu_offset type_cu_offset_in_tu
;
392 /* Type used for delaying computation of method physnames.
393 See comments for compute_delayed_physnames. */
394 struct delayed_method_info
396 /* The type to which the method is attached, i.e., its parent class. */
399 /* The index of the method in the type's function fieldlists. */
402 /* The index of the method in the fieldlist. */
405 /* The name of the DIE. */
408 /* The DIE associated with this method. */
409 struct die_info
*die
;
412 /* Internal state when decoding a particular compilation unit. */
415 explicit dwarf2_cu (struct dwarf2_per_cu_data
*per_cu
);
418 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
420 /* The header of the compilation unit. */
421 struct comp_unit_head header
{};
423 /* Base address of this compilation unit. */
424 CORE_ADDR base_address
= 0;
426 /* Non-zero if base_address has been set. */
429 /* The language we are debugging. */
430 enum language language
= language_unknown
;
431 const struct language_defn
*language_defn
= nullptr;
433 const char *producer
= nullptr;
435 /* The generic symbol table building routines have separate lists for
436 file scope symbols and all all other scopes (local scopes). So
437 we need to select the right one to pass to add_symbol_to_list().
438 We do it by keeping a pointer to the correct list in list_in_scope.
440 FIXME: The original dwarf code just treated the file scope as the
441 first local scope, and all other local scopes as nested local
442 scopes, and worked fine. Check to see if we really need to
443 distinguish these in buildsym.c. */
444 struct pending
**list_in_scope
= nullptr;
446 /* Hash table holding all the loaded partial DIEs
447 with partial_die->offset.SECT_OFF as hash. */
448 htab_t partial_dies
= nullptr;
450 /* Storage for things with the same lifetime as this read-in compilation
451 unit, including partial DIEs. */
452 auto_obstack comp_unit_obstack
;
454 /* When multiple dwarf2_cu structures are living in memory, this field
455 chains them all together, so that they can be released efficiently.
456 We will probably also want a generation counter so that most-recently-used
457 compilation units are cached... */
458 struct dwarf2_per_cu_data
*read_in_chain
= nullptr;
460 /* Backlink to our per_cu entry. */
461 struct dwarf2_per_cu_data
*per_cu
;
463 /* How many compilation units ago was this CU last referenced? */
466 /* A hash table of DIE cu_offset for following references with
467 die_info->offset.sect_off as hash. */
468 htab_t die_hash
= nullptr;
470 /* Full DIEs if read in. */
471 struct die_info
*dies
= nullptr;
473 /* A set of pointers to dwarf2_per_cu_data objects for compilation
474 units referenced by this one. Only set during full symbol processing;
475 partial symbol tables do not have dependencies. */
476 htab_t dependencies
= nullptr;
478 /* Header data from the line table, during full symbol processing. */
479 struct line_header
*line_header
= nullptr;
480 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
481 it's owned by dwarf2_per_objfile::line_header_hash. If non-NULL,
482 this is the DW_TAG_compile_unit die for this CU. We'll hold on
483 to the line header as long as this DIE is being processed. See
484 process_die_scope. */
485 die_info
*line_header_die_owner
= nullptr;
487 /* A list of methods which need to have physnames computed
488 after all type information has been read. */
489 std::vector
<delayed_method_info
> method_list
;
491 /* To be copied to symtab->call_site_htab. */
492 htab_t call_site_htab
= nullptr;
494 /* Non-NULL if this CU came from a DWO file.
495 There is an invariant here that is important to remember:
496 Except for attributes copied from the top level DIE in the "main"
497 (or "stub") file in preparation for reading the DWO file
498 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
499 Either there isn't a DWO file (in which case this is NULL and the point
500 is moot), or there is and either we're not going to read it (in which
501 case this is NULL) or there is and we are reading it (in which case this
503 struct dwo_unit
*dwo_unit
= nullptr;
505 /* The DW_AT_addr_base attribute if present, zero otherwise
506 (zero is a valid value though).
507 Note this value comes from the Fission stub CU/TU's DIE. */
508 ULONGEST addr_base
= 0;
510 /* The DW_AT_ranges_base attribute if present, zero otherwise
511 (zero is a valid value though).
512 Note this value comes from the Fission stub CU/TU's DIE.
513 Also note that the value is zero in the non-DWO case so this value can
514 be used without needing to know whether DWO files are in use or not.
515 N.B. This does not apply to DW_AT_ranges appearing in
516 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
517 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
518 DW_AT_ranges_base *would* have to be applied, and we'd have to care
519 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
520 ULONGEST ranges_base
= 0;
522 /* When reading debug info generated by older versions of rustc, we
523 have to rewrite some union types to be struct types with a
524 variant part. This rewriting must be done after the CU is fully
525 read in, because otherwise at the point of rewriting some struct
526 type might not have been fully processed. So, we keep a list of
527 all such types here and process them after expansion. */
528 std::vector
<struct type
*> rust_unions
;
530 /* Mark used when releasing cached dies. */
531 unsigned int mark
: 1;
533 /* This CU references .debug_loc. See the symtab->locations_valid field.
534 This test is imperfect as there may exist optimized debug code not using
535 any location list and still facing inlining issues if handled as
536 unoptimized code. For a future better test see GCC PR other/32998. */
537 unsigned int has_loclist
: 1;
539 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is set
540 if all the producer_is_* fields are valid. This information is cached
541 because profiling CU expansion showed excessive time spent in
542 producer_is_gxx_lt_4_6. */
543 unsigned int checked_producer
: 1;
544 unsigned int producer_is_gxx_lt_4_6
: 1;
545 unsigned int producer_is_gcc_lt_4_3
: 1;
546 unsigned int producer_is_icc_lt_14
: 1;
548 /* When set, the file that we're processing is known to have
549 debugging info for C++ namespaces. GCC 3.3.x did not produce
550 this information, but later versions do. */
552 unsigned int processing_has_namespace_info
: 1;
554 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
557 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
558 This includes type_unit_group and quick_file_names. */
560 struct stmt_list_hash
562 /* The DWO unit this table is from or NULL if there is none. */
563 struct dwo_unit
*dwo_unit
;
565 /* Offset in .debug_line or .debug_line.dwo. */
566 sect_offset line_sect_off
;
569 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
570 an object of this type. */
572 struct type_unit_group
574 /* dwarf2read.c's main "handle" on a TU symtab.
575 To simplify things we create an artificial CU that "includes" all the
576 type units using this stmt_list so that the rest of the code still has
577 a "per_cu" handle on the symtab.
578 This PER_CU is recognized by having no section. */
579 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->section == NULL)
580 struct dwarf2_per_cu_data per_cu
;
582 /* The TUs that share this DW_AT_stmt_list entry.
583 This is added to while parsing type units to build partial symtabs,
584 and is deleted afterwards and not used again. */
585 VEC (sig_type_ptr
) *tus
;
587 /* The compunit symtab.
588 Type units in a group needn't all be defined in the same source file,
589 so we create an essentially anonymous symtab as the compunit symtab. */
590 struct compunit_symtab
*compunit_symtab
;
592 /* The data used to construct the hash key. */
593 struct stmt_list_hash hash
;
595 /* The number of symtabs from the line header.
596 The value here must match line_header.num_file_names. */
597 unsigned int num_symtabs
;
599 /* The symbol tables for this TU (obtained from the files listed in
601 WARNING: The order of entries here must match the order of entries
602 in the line header. After the first TU using this type_unit_group, the
603 line header for the subsequent TUs is recreated from this. This is done
604 because we need to use the same symtabs for each TU using the same
605 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
606 there's no guarantee the line header doesn't have duplicate entries. */
607 struct symtab
**symtabs
;
610 /* These sections are what may appear in a (real or virtual) DWO file. */
614 struct dwarf2_section_info abbrev
;
615 struct dwarf2_section_info line
;
616 struct dwarf2_section_info loc
;
617 struct dwarf2_section_info loclists
;
618 struct dwarf2_section_info macinfo
;
619 struct dwarf2_section_info macro
;
620 struct dwarf2_section_info str
;
621 struct dwarf2_section_info str_offsets
;
622 /* In the case of a virtual DWO file, these two are unused. */
623 struct dwarf2_section_info info
;
624 VEC (dwarf2_section_info_def
) *types
;
627 /* CUs/TUs in DWP/DWO files. */
631 /* Backlink to the containing struct dwo_file. */
632 struct dwo_file
*dwo_file
;
634 /* The "id" that distinguishes this CU/TU.
635 .debug_info calls this "dwo_id", .debug_types calls this "signature".
636 Since signatures came first, we stick with it for consistency. */
639 /* The section this CU/TU lives in, in the DWO file. */
640 struct dwarf2_section_info
*section
;
642 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
643 sect_offset sect_off
;
646 /* For types, offset in the type's DIE of the type defined by this TU. */
647 cu_offset type_offset_in_tu
;
650 /* include/dwarf2.h defines the DWP section codes.
651 It defines a max value but it doesn't define a min value, which we
652 use for error checking, so provide one. */
654 enum dwp_v2_section_ids
659 /* Data for one DWO file.
661 This includes virtual DWO files (a virtual DWO file is a DWO file as it
662 appears in a DWP file). DWP files don't really have DWO files per se -
663 comdat folding of types "loses" the DWO file they came from, and from
664 a high level view DWP files appear to contain a mass of random types.
665 However, to maintain consistency with the non-DWP case we pretend DWP
666 files contain virtual DWO files, and we assign each TU with one virtual
667 DWO file (generally based on the line and abbrev section offsets -
668 a heuristic that seems to work in practice). */
672 /* The DW_AT_GNU_dwo_name attribute.
673 For virtual DWO files the name is constructed from the section offsets
674 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
675 from related CU+TUs. */
676 const char *dwo_name
;
678 /* The DW_AT_comp_dir attribute. */
679 const char *comp_dir
;
681 /* The bfd, when the file is open. Otherwise this is NULL.
682 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
685 /* The sections that make up this DWO file.
686 Remember that for virtual DWO files in DWP V2, these are virtual
687 sections (for lack of a better name). */
688 struct dwo_sections sections
;
690 /* The CUs in the file.
691 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
692 an extension to handle LLVM's Link Time Optimization output (where
693 multiple source files may be compiled into a single object/dwo pair). */
696 /* Table of TUs in the file.
697 Each element is a struct dwo_unit. */
701 /* These sections are what may appear in a DWP file. */
705 /* These are used by both DWP version 1 and 2. */
706 struct dwarf2_section_info str
;
707 struct dwarf2_section_info cu_index
;
708 struct dwarf2_section_info tu_index
;
710 /* These are only used by DWP version 2 files.
711 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
712 sections are referenced by section number, and are not recorded here.
713 In DWP version 2 there is at most one copy of all these sections, each
714 section being (effectively) comprised of the concatenation of all of the
715 individual sections that exist in the version 1 format.
716 To keep the code simple we treat each of these concatenated pieces as a
717 section itself (a virtual section?). */
718 struct dwarf2_section_info abbrev
;
719 struct dwarf2_section_info info
;
720 struct dwarf2_section_info line
;
721 struct dwarf2_section_info loc
;
722 struct dwarf2_section_info macinfo
;
723 struct dwarf2_section_info macro
;
724 struct dwarf2_section_info str_offsets
;
725 struct dwarf2_section_info types
;
728 /* These sections are what may appear in a virtual DWO file in DWP version 1.
729 A virtual DWO file is a DWO file as it appears in a DWP file. */
731 struct virtual_v1_dwo_sections
733 struct dwarf2_section_info abbrev
;
734 struct dwarf2_section_info line
;
735 struct dwarf2_section_info loc
;
736 struct dwarf2_section_info macinfo
;
737 struct dwarf2_section_info macro
;
738 struct dwarf2_section_info str_offsets
;
739 /* Each DWP hash table entry records one CU or one TU.
740 That is recorded here, and copied to dwo_unit.section. */
741 struct dwarf2_section_info info_or_types
;
744 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
745 In version 2, the sections of the DWO files are concatenated together
746 and stored in one section of that name. Thus each ELF section contains
747 several "virtual" sections. */
749 struct virtual_v2_dwo_sections
751 bfd_size_type abbrev_offset
;
752 bfd_size_type abbrev_size
;
754 bfd_size_type line_offset
;
755 bfd_size_type line_size
;
757 bfd_size_type loc_offset
;
758 bfd_size_type loc_size
;
760 bfd_size_type macinfo_offset
;
761 bfd_size_type macinfo_size
;
763 bfd_size_type macro_offset
;
764 bfd_size_type macro_size
;
766 bfd_size_type str_offsets_offset
;
767 bfd_size_type str_offsets_size
;
769 /* Each DWP hash table entry records one CU or one TU.
770 That is recorded here, and copied to dwo_unit.section. */
771 bfd_size_type info_or_types_offset
;
772 bfd_size_type info_or_types_size
;
775 /* Contents of DWP hash tables. */
777 struct dwp_hash_table
779 uint32_t version
, nr_columns
;
780 uint32_t nr_units
, nr_slots
;
781 const gdb_byte
*hash_table
, *unit_table
;
786 const gdb_byte
*indices
;
790 /* This is indexed by column number and gives the id of the section
792 #define MAX_NR_V2_DWO_SECTIONS \
793 (1 /* .debug_info or .debug_types */ \
794 + 1 /* .debug_abbrev */ \
795 + 1 /* .debug_line */ \
796 + 1 /* .debug_loc */ \
797 + 1 /* .debug_str_offsets */ \
798 + 1 /* .debug_macro or .debug_macinfo */)
799 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
800 const gdb_byte
*offsets
;
801 const gdb_byte
*sizes
;
806 /* Data for one DWP file. */
810 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
812 dbfd (std::move (abfd
))
816 /* Name of the file. */
819 /* File format version. */
823 gdb_bfd_ref_ptr dbfd
;
825 /* Section info for this file. */
826 struct dwp_sections sections
{};
828 /* Table of CUs in the file. */
829 const struct dwp_hash_table
*cus
= nullptr;
831 /* Table of TUs in the file. */
832 const struct dwp_hash_table
*tus
= nullptr;
834 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
835 htab_t loaded_cus
{};
836 htab_t loaded_tus
{};
838 /* Table to map ELF section numbers to their sections.
839 This is only needed for the DWP V1 file format. */
840 unsigned int num_sections
= 0;
841 asection
**elf_sections
= nullptr;
844 /* This represents a '.dwz' file. */
848 /* A dwz file can only contain a few sections. */
849 struct dwarf2_section_info abbrev
;
850 struct dwarf2_section_info info
;
851 struct dwarf2_section_info str
;
852 struct dwarf2_section_info line
;
853 struct dwarf2_section_info macro
;
854 struct dwarf2_section_info gdb_index
;
855 struct dwarf2_section_info debug_names
;
861 /* Struct used to pass misc. parameters to read_die_and_children, et
862 al. which are used for both .debug_info and .debug_types dies.
863 All parameters here are unchanging for the life of the call. This
864 struct exists to abstract away the constant parameters of die reading. */
866 struct die_reader_specs
868 /* The bfd of die_section. */
871 /* The CU of the DIE we are parsing. */
872 struct dwarf2_cu
*cu
;
874 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
875 struct dwo_file
*dwo_file
;
877 /* The section the die comes from.
878 This is either .debug_info or .debug_types, or the .dwo variants. */
879 struct dwarf2_section_info
*die_section
;
881 /* die_section->buffer. */
882 const gdb_byte
*buffer
;
884 /* The end of the buffer. */
885 const gdb_byte
*buffer_end
;
887 /* The value of the DW_AT_comp_dir attribute. */
888 const char *comp_dir
;
890 /* The abbreviation table to use when reading the DIEs. */
891 struct abbrev_table
*abbrev_table
;
894 /* Type of function passed to init_cutu_and_read_dies, et.al. */
895 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
896 const gdb_byte
*info_ptr
,
897 struct die_info
*comp_unit_die
,
901 /* A 1-based directory index. This is a strong typedef to prevent
902 accidentally using a directory index as a 0-based index into an
904 enum class dir_index
: unsigned int {};
906 /* Likewise, a 1-based file name index. */
907 enum class file_name_index
: unsigned int {};
911 file_entry () = default;
913 file_entry (const char *name_
, dir_index d_index_
,
914 unsigned int mod_time_
, unsigned int length_
)
917 mod_time (mod_time_
),
921 /* Return the include directory at D_INDEX stored in LH. Returns
922 NULL if D_INDEX is out of bounds. */
923 const char *include_dir (const line_header
*lh
) const;
925 /* The file name. Note this is an observing pointer. The memory is
926 owned by debug_line_buffer. */
929 /* The directory index (1-based). */
930 dir_index d_index
{};
932 unsigned int mod_time
{};
934 unsigned int length
{};
936 /* True if referenced by the Line Number Program. */
939 /* The associated symbol table, if any. */
940 struct symtab
*symtab
{};
943 /* The line number information for a compilation unit (found in the
944 .debug_line section) begins with a "statement program header",
945 which contains the following information. */
952 /* Add an entry to the include directory table. */
953 void add_include_dir (const char *include_dir
);
955 /* Add an entry to the file name table. */
956 void add_file_name (const char *name
, dir_index d_index
,
957 unsigned int mod_time
, unsigned int length
);
959 /* Return the include dir at INDEX (1-based). Returns NULL if INDEX
961 const char *include_dir_at (dir_index index
) const
963 /* Convert directory index number (1-based) to vector index
965 size_t vec_index
= to_underlying (index
) - 1;
967 if (vec_index
>= include_dirs
.size ())
969 return include_dirs
[vec_index
];
972 /* Return the file name at INDEX (1-based). Returns NULL if INDEX
974 file_entry
*file_name_at (file_name_index index
)
976 /* Convert file name index number (1-based) to vector index
978 size_t vec_index
= to_underlying (index
) - 1;
980 if (vec_index
>= file_names
.size ())
982 return &file_names
[vec_index
];
985 /* Const version of the above. */
986 const file_entry
*file_name_at (unsigned int index
) const
988 if (index
>= file_names
.size ())
990 return &file_names
[index
];
993 /* Offset of line number information in .debug_line section. */
994 sect_offset sect_off
{};
996 /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile. */
997 unsigned offset_in_dwz
: 1; /* Can't initialize bitfields in-class. */
999 unsigned int total_length
{};
1000 unsigned short version
{};
1001 unsigned int header_length
{};
1002 unsigned char minimum_instruction_length
{};
1003 unsigned char maximum_ops_per_instruction
{};
1004 unsigned char default_is_stmt
{};
1006 unsigned char line_range
{};
1007 unsigned char opcode_base
{};
1009 /* standard_opcode_lengths[i] is the number of operands for the
1010 standard opcode whose value is i. This means that
1011 standard_opcode_lengths[0] is unused, and the last meaningful
1012 element is standard_opcode_lengths[opcode_base - 1]. */
1013 std::unique_ptr
<unsigned char[]> standard_opcode_lengths
;
1015 /* The include_directories table. Note these are observing
1016 pointers. The memory is owned by debug_line_buffer. */
1017 std::vector
<const char *> include_dirs
;
1019 /* The file_names table. */
1020 std::vector
<file_entry
> file_names
;
1022 /* The start and end of the statement program following this
1023 header. These point into dwarf2_per_objfile->line_buffer. */
1024 const gdb_byte
*statement_program_start
{}, *statement_program_end
{};
1027 typedef std::unique_ptr
<line_header
> line_header_up
;
1030 file_entry::include_dir (const line_header
*lh
) const
1032 return lh
->include_dir_at (d_index
);
1035 /* When we construct a partial symbol table entry we only
1036 need this much information. */
1037 struct partial_die_info
: public allocate_on_obstack
1039 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
1041 /* Disable assign but still keep copy ctor, which is needed
1042 load_partial_dies. */
1043 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
1045 /* Adjust the partial die before generating a symbol for it. This
1046 function may set the is_external flag or change the DIE's
1048 void fixup (struct dwarf2_cu
*cu
);
1050 /* Read a minimal amount of information into the minimal die
1052 const gdb_byte
*read (const struct die_reader_specs
*reader
,
1053 const struct abbrev_info
&abbrev
,
1054 const gdb_byte
*info_ptr
);
1056 /* Offset of this DIE. */
1057 const sect_offset sect_off
;
1059 /* DWARF-2 tag for this DIE. */
1060 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1062 /* Assorted flags describing the data found in this DIE. */
1063 const unsigned int has_children
: 1;
1065 unsigned int is_external
: 1;
1066 unsigned int is_declaration
: 1;
1067 unsigned int has_type
: 1;
1068 unsigned int has_specification
: 1;
1069 unsigned int has_pc_info
: 1;
1070 unsigned int may_be_inlined
: 1;
1072 /* This DIE has been marked DW_AT_main_subprogram. */
1073 unsigned int main_subprogram
: 1;
1075 /* Flag set if the SCOPE field of this structure has been
1077 unsigned int scope_set
: 1;
1079 /* Flag set if the DIE has a byte_size attribute. */
1080 unsigned int has_byte_size
: 1;
1082 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1083 unsigned int has_const_value
: 1;
1085 /* Flag set if any of the DIE's children are template arguments. */
1086 unsigned int has_template_arguments
: 1;
1088 /* Flag set if fixup has been called on this die. */
1089 unsigned int fixup_called
: 1;
1091 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1092 unsigned int is_dwz
: 1;
1094 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1095 unsigned int spec_is_dwz
: 1;
1097 /* The name of this DIE. Normally the value of DW_AT_name, but
1098 sometimes a default name for unnamed DIEs. */
1099 const char *name
= nullptr;
1101 /* The linkage name, if present. */
1102 const char *linkage_name
= nullptr;
1104 /* The scope to prepend to our children. This is generally
1105 allocated on the comp_unit_obstack, so will disappear
1106 when this compilation unit leaves the cache. */
1107 const char *scope
= nullptr;
1109 /* Some data associated with the partial DIE. The tag determines
1110 which field is live. */
1113 /* The location description associated with this DIE, if any. */
1114 struct dwarf_block
*locdesc
;
1115 /* The offset of an import, for DW_TAG_imported_unit. */
1116 sect_offset sect_off
;
1119 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1120 CORE_ADDR lowpc
= 0;
1121 CORE_ADDR highpc
= 0;
1123 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1124 DW_AT_sibling, if any. */
1125 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1126 could return DW_AT_sibling values to its caller load_partial_dies. */
1127 const gdb_byte
*sibling
= nullptr;
1129 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1130 DW_AT_specification (or DW_AT_abstract_origin or
1131 DW_AT_extension). */
1132 sect_offset spec_offset
{};
1134 /* Pointers to this DIE's parent, first child, and next sibling,
1136 struct partial_die_info
*die_parent
= nullptr;
1137 struct partial_die_info
*die_child
= nullptr;
1138 struct partial_die_info
*die_sibling
= nullptr;
1140 friend struct partial_die_info
*
1141 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1144 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1145 partial_die_info (sect_offset sect_off
)
1146 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1150 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1152 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1157 has_specification
= 0;
1160 main_subprogram
= 0;
1163 has_const_value
= 0;
1164 has_template_arguments
= 0;
1171 /* This data structure holds the information of an abbrev. */
1174 unsigned int number
; /* number identifying abbrev */
1175 enum dwarf_tag tag
; /* dwarf tag */
1176 unsigned short has_children
; /* boolean */
1177 unsigned short num_attrs
; /* number of attributes */
1178 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
1179 struct abbrev_info
*next
; /* next in chain */
1184 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1185 ENUM_BITFIELD(dwarf_form
) form
: 16;
1187 /* It is valid only if FORM is DW_FORM_implicit_const. */
1188 LONGEST implicit_const
;
1191 /* Size of abbrev_table.abbrev_hash_table. */
1192 #define ABBREV_HASH_SIZE 121
1194 /* Top level data structure to contain an abbreviation table. */
1198 explicit abbrev_table (sect_offset off
)
1202 XOBNEWVEC (&abbrev_obstack
, struct abbrev_info
*, ABBREV_HASH_SIZE
);
1203 memset (m_abbrevs
, 0, ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
1206 DISABLE_COPY_AND_ASSIGN (abbrev_table
);
1208 /* Allocate space for a struct abbrev_info object in
1210 struct abbrev_info
*alloc_abbrev ();
1212 /* Add an abbreviation to the table. */
1213 void add_abbrev (unsigned int abbrev_number
, struct abbrev_info
*abbrev
);
1215 /* Look up an abbrev in the table.
1216 Returns NULL if the abbrev is not found. */
1218 struct abbrev_info
*lookup_abbrev (unsigned int abbrev_number
);
1221 /* Where the abbrev table came from.
1222 This is used as a sanity check when the table is used. */
1223 const sect_offset sect_off
;
1225 /* Storage for the abbrev table. */
1226 auto_obstack abbrev_obstack
;
1230 /* Hash table of abbrevs.
1231 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1232 It could be statically allocated, but the previous code didn't so we
1234 struct abbrev_info
**m_abbrevs
;
1237 typedef std::unique_ptr
<struct abbrev_table
> abbrev_table_up
;
1239 /* Attributes have a name and a value. */
1242 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1243 ENUM_BITFIELD(dwarf_form
) form
: 15;
1245 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1246 field should be in u.str (existing only for DW_STRING) but it is kept
1247 here for better struct attribute alignment. */
1248 unsigned int string_is_canonical
: 1;
1253 struct dwarf_block
*blk
;
1262 /* This data structure holds a complete die structure. */
1265 /* DWARF-2 tag for this DIE. */
1266 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1268 /* Number of attributes */
1269 unsigned char num_attrs
;
1271 /* True if we're presently building the full type name for the
1272 type derived from this DIE. */
1273 unsigned char building_fullname
: 1;
1275 /* True if this die is in process. PR 16581. */
1276 unsigned char in_process
: 1;
1279 unsigned int abbrev
;
1281 /* Offset in .debug_info or .debug_types section. */
1282 sect_offset sect_off
;
1284 /* The dies in a compilation unit form an n-ary tree. PARENT
1285 points to this die's parent; CHILD points to the first child of
1286 this node; and all the children of a given node are chained
1287 together via their SIBLING fields. */
1288 struct die_info
*child
; /* Its first child, if any. */
1289 struct die_info
*sibling
; /* Its next sibling, if any. */
1290 struct die_info
*parent
; /* Its parent, if any. */
1292 /* An array of attributes, with NUM_ATTRS elements. There may be
1293 zero, but it's not common and zero-sized arrays are not
1294 sufficiently portable C. */
1295 struct attribute attrs
[1];
1298 /* Get at parts of an attribute structure. */
1300 #define DW_STRING(attr) ((attr)->u.str)
1301 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1302 #define DW_UNSND(attr) ((attr)->u.unsnd)
1303 #define DW_BLOCK(attr) ((attr)->u.blk)
1304 #define DW_SND(attr) ((attr)->u.snd)
1305 #define DW_ADDR(attr) ((attr)->u.addr)
1306 #define DW_SIGNATURE(attr) ((attr)->u.signature)
1308 /* Blocks are a bunch of untyped bytes. */
1313 /* Valid only if SIZE is not zero. */
1314 const gdb_byte
*data
;
1317 #ifndef ATTR_ALLOC_CHUNK
1318 #define ATTR_ALLOC_CHUNK 4
1321 /* Allocate fields for structs, unions and enums in this size. */
1322 #ifndef DW_FIELD_ALLOC_CHUNK
1323 #define DW_FIELD_ALLOC_CHUNK 4
1326 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1327 but this would require a corresponding change in unpack_field_as_long
1329 static int bits_per_byte
= 8;
1331 /* When reading a variant or variant part, we track a bit more
1332 information about the field, and store it in an object of this
1335 struct variant_field
1337 /* If we see a DW_TAG_variant, then this will be the discriminant
1339 ULONGEST discriminant_value
;
1340 /* If we see a DW_TAG_variant, then this will be set if this is the
1342 bool default_branch
;
1343 /* While reading a DW_TAG_variant_part, this will be set if this
1344 field is the discriminant. */
1345 bool is_discriminant
;
1350 int accessibility
= 0;
1352 /* Extra information to describe a variant or variant part. */
1353 struct variant_field variant
{};
1354 struct field field
{};
1359 const char *name
= nullptr;
1360 std::vector
<struct fn_field
> fnfields
;
1363 /* The routines that read and process dies for a C struct or C++ class
1364 pass lists of data member fields and lists of member function fields
1365 in an instance of a field_info structure, as defined below. */
1368 /* List of data member and baseclasses fields. */
1369 std::vector
<struct nextfield
> fields
;
1370 std::vector
<struct nextfield
> baseclasses
;
1372 /* Number of fields (including baseclasses). */
1375 /* Set if the accesibility of one of the fields is not public. */
1376 int non_public_fields
= 0;
1378 /* Member function fieldlist array, contains name of possibly overloaded
1379 member function, number of overloaded member functions and a pointer
1380 to the head of the member function field chain. */
1381 std::vector
<struct fnfieldlist
> fnfieldlists
;
1383 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1384 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1385 std::vector
<struct decl_field
> typedef_field_list
;
1387 /* Nested types defined by this class and the number of elements in this
1389 std::vector
<struct decl_field
> nested_types_list
;
1392 /* One item on the queue of compilation units to read in full symbols
1394 struct dwarf2_queue_item
1396 struct dwarf2_per_cu_data
*per_cu
;
1397 enum language pretend_language
;
1398 struct dwarf2_queue_item
*next
;
1401 /* The current queue. */
1402 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1404 /* Loaded secondary compilation units are kept in memory until they
1405 have not been referenced for the processing of this many
1406 compilation units. Set this to zero to disable caching. Cache
1407 sizes of up to at least twenty will improve startup time for
1408 typical inter-CU-reference binaries, at an obvious memory cost. */
1409 static int dwarf_max_cache_age
= 5;
1411 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1412 struct cmd_list_element
*c
, const char *value
)
1414 fprintf_filtered (file
, _("The upper bound on the age of cached "
1415 "DWARF compilation units is %s.\n"),
1419 /* local function prototypes */
1421 static const char *get_section_name (const struct dwarf2_section_info
*);
1423 static const char *get_section_file_name (const struct dwarf2_section_info
*);
1425 static void dwarf2_find_base_address (struct die_info
*die
,
1426 struct dwarf2_cu
*cu
);
1428 static struct partial_symtab
*create_partial_symtab
1429 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1431 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1432 const gdb_byte
*info_ptr
,
1433 struct die_info
*type_unit_die
,
1434 int has_children
, void *data
);
1436 static void dwarf2_build_psymtabs_hard
1437 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1439 static void scan_partial_symbols (struct partial_die_info
*,
1440 CORE_ADDR
*, CORE_ADDR
*,
1441 int, struct dwarf2_cu
*);
1443 static void add_partial_symbol (struct partial_die_info
*,
1444 struct dwarf2_cu
*);
1446 static void add_partial_namespace (struct partial_die_info
*pdi
,
1447 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1448 int set_addrmap
, struct dwarf2_cu
*cu
);
1450 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1451 CORE_ADDR
*highpc
, int set_addrmap
,
1452 struct dwarf2_cu
*cu
);
1454 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1455 struct dwarf2_cu
*cu
);
1457 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1458 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1459 int need_pc
, struct dwarf2_cu
*cu
);
1461 static void dwarf2_read_symtab (struct partial_symtab
*,
1464 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1466 static abbrev_table_up abbrev_table_read_table
1467 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, struct dwarf2_section_info
*,
1470 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1472 static struct partial_die_info
*load_partial_dies
1473 (const struct die_reader_specs
*, const gdb_byte
*, int);
1475 static struct partial_die_info
*find_partial_die (sect_offset
, int,
1476 struct dwarf2_cu
*);
1478 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1479 struct attribute
*, struct attr_abbrev
*,
1482 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1484 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1486 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1488 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1490 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1492 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1495 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1497 static LONGEST read_checked_initial_length_and_offset
1498 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1499 unsigned int *, unsigned int *);
1501 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1502 const struct comp_unit_head
*,
1505 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1507 static sect_offset read_abbrev_offset
1508 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1509 struct dwarf2_section_info
*, sect_offset
);
1511 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1513 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1515 static const char *read_indirect_string
1516 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1517 const struct comp_unit_head
*, unsigned int *);
1519 static const char *read_indirect_line_string
1520 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1521 const struct comp_unit_head
*, unsigned int *);
1523 static const char *read_indirect_string_at_offset
1524 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
1525 LONGEST str_offset
);
1527 static const char *read_indirect_string_from_dwz
1528 (struct objfile
*objfile
, struct dwz_file
*, LONGEST
);
1530 static LONGEST
read_signed_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1532 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1536 static const char *read_str_index (const struct die_reader_specs
*reader
,
1537 ULONGEST str_index
);
1539 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1541 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1542 struct dwarf2_cu
*);
1544 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1547 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1548 struct dwarf2_cu
*cu
);
1550 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1551 struct dwarf2_cu
*cu
);
1553 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1555 static struct die_info
*die_specification (struct die_info
*die
,
1556 struct dwarf2_cu
**);
1558 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1559 struct dwarf2_cu
*cu
);
1561 static void dwarf_decode_lines (struct line_header
*, const char *,
1562 struct dwarf2_cu
*, struct partial_symtab
*,
1563 CORE_ADDR
, int decode_mapping
);
1565 static void dwarf2_start_subfile (const char *, const char *);
1567 static struct compunit_symtab
*dwarf2_start_symtab (struct dwarf2_cu
*,
1568 const char *, const char *,
1571 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1572 struct dwarf2_cu
*, struct symbol
* = NULL
);
1574 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1575 struct dwarf2_cu
*);
1577 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1580 struct obstack
*obstack
,
1581 struct dwarf2_cu
*cu
, LONGEST
*value
,
1582 const gdb_byte
**bytes
,
1583 struct dwarf2_locexpr_baton
**baton
);
1585 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1587 static int need_gnat_info (struct dwarf2_cu
*);
1589 static struct type
*die_descriptive_type (struct die_info
*,
1590 struct dwarf2_cu
*);
1592 static void set_descriptive_type (struct type
*, struct die_info
*,
1593 struct dwarf2_cu
*);
1595 static struct type
*die_containing_type (struct die_info
*,
1596 struct dwarf2_cu
*);
1598 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1599 struct dwarf2_cu
*);
1601 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1603 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1605 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1607 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1608 const char *suffix
, int physname
,
1609 struct dwarf2_cu
*cu
);
1611 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1613 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1615 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1617 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1619 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1621 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1623 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1624 struct dwarf2_cu
*, struct partial_symtab
*);
1626 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1627 values. Keep the items ordered with increasing constraints compliance. */
1630 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1631 PC_BOUNDS_NOT_PRESENT
,
1633 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1634 were present but they do not form a valid range of PC addresses. */
1637 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1640 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1644 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1645 CORE_ADDR
*, CORE_ADDR
*,
1647 struct partial_symtab
*);
1649 static void get_scope_pc_bounds (struct die_info
*,
1650 CORE_ADDR
*, CORE_ADDR
*,
1651 struct dwarf2_cu
*);
1653 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1654 CORE_ADDR
, struct dwarf2_cu
*);
1656 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1657 struct dwarf2_cu
*);
1659 static void dwarf2_attach_fields_to_type (struct field_info
*,
1660 struct type
*, struct dwarf2_cu
*);
1662 static void dwarf2_add_member_fn (struct field_info
*,
1663 struct die_info
*, struct type
*,
1664 struct dwarf2_cu
*);
1666 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1668 struct dwarf2_cu
*);
1670 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1672 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1674 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1676 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1678 static struct using_direct
**using_directives (enum language
);
1680 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1682 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1684 static struct type
*read_module_type (struct die_info
*die
,
1685 struct dwarf2_cu
*cu
);
1687 static const char *namespace_name (struct die_info
*die
,
1688 int *is_anonymous
, struct dwarf2_cu
*);
1690 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1692 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1694 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1695 struct dwarf2_cu
*);
1697 static struct die_info
*read_die_and_siblings_1
1698 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1701 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1702 const gdb_byte
*info_ptr
,
1703 const gdb_byte
**new_info_ptr
,
1704 struct die_info
*parent
);
1706 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1707 struct die_info
**, const gdb_byte
*,
1710 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1711 struct die_info
**, const gdb_byte
*,
1714 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1716 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1719 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1721 static const char *dwarf2_full_name (const char *name
,
1722 struct die_info
*die
,
1723 struct dwarf2_cu
*cu
);
1725 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1726 struct dwarf2_cu
*cu
);
1728 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1729 struct dwarf2_cu
**);
1731 static const char *dwarf_tag_name (unsigned int);
1733 static const char *dwarf_attr_name (unsigned int);
1735 static const char *dwarf_form_name (unsigned int);
1737 static const char *dwarf_bool_name (unsigned int);
1739 static const char *dwarf_type_encoding_name (unsigned int);
1741 static struct die_info
*sibling_die (struct die_info
*);
1743 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1745 static void dump_die_for_error (struct die_info
*);
1747 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1750 /*static*/ void dump_die (struct die_info
*, int max_level
);
1752 static void store_in_ref_table (struct die_info
*,
1753 struct dwarf2_cu
*);
1755 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1757 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1759 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1760 const struct attribute
*,
1761 struct dwarf2_cu
**);
1763 static struct die_info
*follow_die_ref (struct die_info
*,
1764 const struct attribute
*,
1765 struct dwarf2_cu
**);
1767 static struct die_info
*follow_die_sig (struct die_info
*,
1768 const struct attribute
*,
1769 struct dwarf2_cu
**);
1771 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1772 struct dwarf2_cu
*);
1774 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1775 const struct attribute
*,
1776 struct dwarf2_cu
*);
1778 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1780 static void read_signatured_type (struct signatured_type
*);
1782 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1783 struct die_info
*die
, struct dwarf2_cu
*cu
,
1784 struct dynamic_prop
*prop
);
1786 /* memory allocation interface */
1788 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1790 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1792 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1794 static int attr_form_is_block (const struct attribute
*);
1796 static int attr_form_is_section_offset (const struct attribute
*);
1798 static int attr_form_is_constant (const struct attribute
*);
1800 static int attr_form_is_ref (const struct attribute
*);
1802 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1803 struct dwarf2_loclist_baton
*baton
,
1804 const struct attribute
*attr
);
1806 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1808 struct dwarf2_cu
*cu
,
1811 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1812 const gdb_byte
*info_ptr
,
1813 struct abbrev_info
*abbrev
);
1815 static hashval_t
partial_die_hash (const void *item
);
1817 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1819 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1820 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1821 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1823 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1824 struct die_info
*comp_unit_die
,
1825 enum language pretend_language
);
1827 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1829 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1831 static struct type
*set_die_type (struct die_info
*, struct type
*,
1832 struct dwarf2_cu
*);
1834 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1836 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1838 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1841 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1844 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1847 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1848 struct dwarf2_per_cu_data
*);
1850 static void dwarf2_mark (struct dwarf2_cu
*);
1852 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1854 static struct type
*get_die_type_at_offset (sect_offset
,
1855 struct dwarf2_per_cu_data
*);
1857 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1859 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1860 enum language pretend_language
);
1862 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1864 /* Class, the destructor of which frees all allocated queue entries. This
1865 will only have work to do if an error was thrown while processing the
1866 dwarf. If no error was thrown then the queue entries should have all
1867 been processed, and freed, as we went along. */
1869 class dwarf2_queue_guard
1872 dwarf2_queue_guard () = default;
1874 /* Free any entries remaining on the queue. There should only be
1875 entries left if we hit an error while processing the dwarf. */
1876 ~dwarf2_queue_guard ()
1878 struct dwarf2_queue_item
*item
, *last
;
1880 item
= dwarf2_queue
;
1883 /* Anything still marked queued is likely to be in an
1884 inconsistent state, so discard it. */
1885 if (item
->per_cu
->queued
)
1887 if (item
->per_cu
->cu
!= NULL
)
1888 free_one_cached_comp_unit (item
->per_cu
);
1889 item
->per_cu
->queued
= 0;
1897 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
1901 /* The return type of find_file_and_directory. Note, the enclosed
1902 string pointers are only valid while this object is valid. */
1904 struct file_and_directory
1906 /* The filename. This is never NULL. */
1909 /* The compilation directory. NULL if not known. If we needed to
1910 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1911 points directly to the DW_AT_comp_dir string attribute owned by
1912 the obstack that owns the DIE. */
1913 const char *comp_dir
;
1915 /* If we needed to build a new string for comp_dir, this is what
1916 owns the storage. */
1917 std::string comp_dir_storage
;
1920 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1921 struct dwarf2_cu
*cu
);
1923 static char *file_full_name (int file
, struct line_header
*lh
,
1924 const char *comp_dir
);
1926 /* Expected enum dwarf_unit_type for read_comp_unit_head. */
1927 enum class rcuh_kind
{ COMPILE
, TYPE
};
1929 static const gdb_byte
*read_and_check_comp_unit_head
1930 (struct dwarf2_per_objfile
* dwarf2_per_objfile
,
1931 struct comp_unit_head
*header
,
1932 struct dwarf2_section_info
*section
,
1933 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
1934 rcuh_kind section_kind
);
1936 static void init_cutu_and_read_dies
1937 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
1938 int use_existing_cu
, int keep
, bool skip_partial
,
1939 die_reader_func_ftype
*die_reader_func
, void *data
);
1941 static void init_cutu_and_read_dies_simple
1942 (struct dwarf2_per_cu_data
*this_cu
,
1943 die_reader_func_ftype
*die_reader_func
, void *data
);
1945 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1947 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1949 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1950 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1951 struct dwp_file
*dwp_file
, const char *comp_dir
,
1952 ULONGEST signature
, int is_debug_types
);
1954 static struct dwp_file
*get_dwp_file
1955 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1957 static struct dwo_unit
*lookup_dwo_comp_unit
1958 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1960 static struct dwo_unit
*lookup_dwo_type_unit
1961 (struct signatured_type
*, const char *, const char *);
1963 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1965 static void free_dwo_file (struct dwo_file
*);
1967 /* A unique_ptr helper to free a dwo_file. */
1969 struct dwo_file_deleter
1971 void operator() (struct dwo_file
*df
) const
1977 /* A unique pointer to a dwo_file. */
1979 typedef std::unique_ptr
<struct dwo_file
, dwo_file_deleter
> dwo_file_up
;
1981 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1983 static void check_producer (struct dwarf2_cu
*cu
);
1985 static void free_line_header_voidp (void *arg
);
1987 /* Various complaints about symbol reading that don't abort the process. */
1990 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1992 complaint (&symfile_complaints
,
1993 _("statement list doesn't fit in .debug_line section"));
1997 dwarf2_debug_line_missing_file_complaint (void)
1999 complaint (&symfile_complaints
,
2000 _(".debug_line section has line data without a file"));
2004 dwarf2_debug_line_missing_end_sequence_complaint (void)
2006 complaint (&symfile_complaints
,
2007 _(".debug_line section has line "
2008 "program sequence without an end"));
2012 dwarf2_complex_location_expr_complaint (void)
2014 complaint (&symfile_complaints
, _("location expression too complex"));
2018 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
2021 complaint (&symfile_complaints
,
2022 _("const value length mismatch for '%s', got %d, expected %d"),
2027 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
2029 complaint (&symfile_complaints
,
2030 _("debug info runs off end of %s section"
2032 get_section_name (section
),
2033 get_section_file_name (section
));
2037 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
2039 complaint (&symfile_complaints
,
2040 _("macro debug info contains a "
2041 "malformed macro definition:\n`%s'"),
2046 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
2048 complaint (&symfile_complaints
,
2049 _("invalid attribute class or form for '%s' in '%s'"),
2053 /* Hash function for line_header_hash. */
2056 line_header_hash (const struct line_header
*ofs
)
2058 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
2061 /* Hash function for htab_create_alloc_ex for line_header_hash. */
2064 line_header_hash_voidp (const void *item
)
2066 const struct line_header
*ofs
= (const struct line_header
*) item
;
2068 return line_header_hash (ofs
);
2071 /* Equality function for line_header_hash. */
2074 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
2076 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
2077 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
2079 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
2080 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
2085 /* Read the given attribute value as an address, taking the attribute's
2086 form into account. */
2089 attr_value_as_address (struct attribute
*attr
)
2093 if (attr
->form
!= DW_FORM_addr
&& attr
->form
!= DW_FORM_GNU_addr_index
)
2095 /* Aside from a few clearly defined exceptions, attributes that
2096 contain an address must always be in DW_FORM_addr form.
2097 Unfortunately, some compilers happen to be violating this
2098 requirement by encoding addresses using other forms, such
2099 as DW_FORM_data4 for example. For those broken compilers,
2100 we try to do our best, without any guarantee of success,
2101 to interpret the address correctly. It would also be nice
2102 to generate a complaint, but that would require us to maintain
2103 a list of legitimate cases where a non-address form is allowed,
2104 as well as update callers to pass in at least the CU's DWARF
2105 version. This is more overhead than what we're willing to
2106 expand for a pretty rare case. */
2107 addr
= DW_UNSND (attr
);
2110 addr
= DW_ADDR (attr
);
2115 /* See declaration. */
2117 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
2118 const dwarf2_debug_sections
*names
)
2119 : objfile (objfile_
)
2122 names
= &dwarf2_elf_names
;
2124 bfd
*obfd
= objfile
->obfd
;
2126 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2127 locate_sections (obfd
, sec
, *names
);
2130 static void free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
);
2132 dwarf2_per_objfile::~dwarf2_per_objfile ()
2134 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
2135 free_cached_comp_units ();
2137 if (quick_file_names_table
)
2138 htab_delete (quick_file_names_table
);
2140 if (line_header_hash
)
2141 htab_delete (line_header_hash
);
2143 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
2144 VEC_free (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
);
2146 for (signatured_type
*sig_type
: all_type_units
)
2147 VEC_free (dwarf2_per_cu_ptr
, sig_type
->per_cu
.imported_symtabs
);
2149 VEC_free (dwarf2_section_info_def
, types
);
2151 if (dwo_files
!= NULL
)
2152 free_dwo_files (dwo_files
, objfile
);
2154 if (dwz_file
!= NULL
&& dwz_file
->dwz_bfd
)
2155 gdb_bfd_unref (dwz_file
->dwz_bfd
);
2157 /* Everything else should be on the objfile obstack. */
2160 /* See declaration. */
2163 dwarf2_per_objfile::free_cached_comp_units ()
2165 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
2166 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
2167 while (per_cu
!= NULL
)
2169 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
2172 *last_chain
= next_cu
;
2177 /* A helper class that calls free_cached_comp_units on
2180 class free_cached_comp_units
2184 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
2185 : m_per_objfile (per_objfile
)
2189 ~free_cached_comp_units ()
2191 m_per_objfile
->free_cached_comp_units ();
2194 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
2198 dwarf2_per_objfile
*m_per_objfile
;
2201 /* Try to locate the sections we need for DWARF 2 debugging
2202 information and return true if we have enough to do something.
2203 NAMES points to the dwarf2 section names, or is NULL if the standard
2204 ELF names are used. */
2207 dwarf2_has_info (struct objfile
*objfile
,
2208 const struct dwarf2_debug_sections
*names
)
2210 if (objfile
->flags
& OBJF_READNEVER
)
2213 struct dwarf2_per_objfile
*dwarf2_per_objfile
2214 = get_dwarf2_per_objfile (objfile
);
2216 if (dwarf2_per_objfile
== NULL
)
2218 /* Initialize per-objfile state. */
2220 = new (&objfile
->objfile_obstack
) struct dwarf2_per_objfile (objfile
,
2222 set_dwarf2_per_objfile (objfile
, dwarf2_per_objfile
);
2224 return (!dwarf2_per_objfile
->info
.is_virtual
2225 && dwarf2_per_objfile
->info
.s
.section
!= NULL
2226 && !dwarf2_per_objfile
->abbrev
.is_virtual
2227 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
2230 /* Return the containing section of virtual section SECTION. */
2232 static struct dwarf2_section_info
*
2233 get_containing_section (const struct dwarf2_section_info
*section
)
2235 gdb_assert (section
->is_virtual
);
2236 return section
->s
.containing_section
;
2239 /* Return the bfd owner of SECTION. */
2242 get_section_bfd_owner (const struct dwarf2_section_info
*section
)
2244 if (section
->is_virtual
)
2246 section
= get_containing_section (section
);
2247 gdb_assert (!section
->is_virtual
);
2249 return section
->s
.section
->owner
;
2252 /* Return the bfd section of SECTION.
2253 Returns NULL if the section is not present. */
2256 get_section_bfd_section (const struct dwarf2_section_info
*section
)
2258 if (section
->is_virtual
)
2260 section
= get_containing_section (section
);
2261 gdb_assert (!section
->is_virtual
);
2263 return section
->s
.section
;
2266 /* Return the name of SECTION. */
2269 get_section_name (const struct dwarf2_section_info
*section
)
2271 asection
*sectp
= get_section_bfd_section (section
);
2273 gdb_assert (sectp
!= NULL
);
2274 return bfd_section_name (get_section_bfd_owner (section
), sectp
);
2277 /* Return the name of the file SECTION is in. */
2280 get_section_file_name (const struct dwarf2_section_info
*section
)
2282 bfd
*abfd
= get_section_bfd_owner (section
);
2284 return bfd_get_filename (abfd
);
2287 /* Return the id of SECTION.
2288 Returns 0 if SECTION doesn't exist. */
2291 get_section_id (const struct dwarf2_section_info
*section
)
2293 asection
*sectp
= get_section_bfd_section (section
);
2300 /* Return the flags of SECTION.
2301 SECTION (or containing section if this is a virtual section) must exist. */
2304 get_section_flags (const struct dwarf2_section_info
*section
)
2306 asection
*sectp
= get_section_bfd_section (section
);
2308 gdb_assert (sectp
!= NULL
);
2309 return bfd_get_section_flags (sectp
->owner
, sectp
);
2312 /* When loading sections, we look either for uncompressed section or for
2313 compressed section names. */
2316 section_is_p (const char *section_name
,
2317 const struct dwarf2_section_names
*names
)
2319 if (names
->normal
!= NULL
2320 && strcmp (section_name
, names
->normal
) == 0)
2322 if (names
->compressed
!= NULL
2323 && strcmp (section_name
, names
->compressed
) == 0)
2328 /* See declaration. */
2331 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
2332 const dwarf2_debug_sections
&names
)
2334 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
2336 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2339 else if (section_is_p (sectp
->name
, &names
.info
))
2341 this->info
.s
.section
= sectp
;
2342 this->info
.size
= bfd_get_section_size (sectp
);
2344 else if (section_is_p (sectp
->name
, &names
.abbrev
))
2346 this->abbrev
.s
.section
= sectp
;
2347 this->abbrev
.size
= bfd_get_section_size (sectp
);
2349 else if (section_is_p (sectp
->name
, &names
.line
))
2351 this->line
.s
.section
= sectp
;
2352 this->line
.size
= bfd_get_section_size (sectp
);
2354 else if (section_is_p (sectp
->name
, &names
.loc
))
2356 this->loc
.s
.section
= sectp
;
2357 this->loc
.size
= bfd_get_section_size (sectp
);
2359 else if (section_is_p (sectp
->name
, &names
.loclists
))
2361 this->loclists
.s
.section
= sectp
;
2362 this->loclists
.size
= bfd_get_section_size (sectp
);
2364 else if (section_is_p (sectp
->name
, &names
.macinfo
))
2366 this->macinfo
.s
.section
= sectp
;
2367 this->macinfo
.size
= bfd_get_section_size (sectp
);
2369 else if (section_is_p (sectp
->name
, &names
.macro
))
2371 this->macro
.s
.section
= sectp
;
2372 this->macro
.size
= bfd_get_section_size (sectp
);
2374 else if (section_is_p (sectp
->name
, &names
.str
))
2376 this->str
.s
.section
= sectp
;
2377 this->str
.size
= bfd_get_section_size (sectp
);
2379 else if (section_is_p (sectp
->name
, &names
.line_str
))
2381 this->line_str
.s
.section
= sectp
;
2382 this->line_str
.size
= bfd_get_section_size (sectp
);
2384 else if (section_is_p (sectp
->name
, &names
.addr
))
2386 this->addr
.s
.section
= sectp
;
2387 this->addr
.size
= bfd_get_section_size (sectp
);
2389 else if (section_is_p (sectp
->name
, &names
.frame
))
2391 this->frame
.s
.section
= sectp
;
2392 this->frame
.size
= bfd_get_section_size (sectp
);
2394 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2396 this->eh_frame
.s
.section
= sectp
;
2397 this->eh_frame
.size
= bfd_get_section_size (sectp
);
2399 else if (section_is_p (sectp
->name
, &names
.ranges
))
2401 this->ranges
.s
.section
= sectp
;
2402 this->ranges
.size
= bfd_get_section_size (sectp
);
2404 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2406 this->rnglists
.s
.section
= sectp
;
2407 this->rnglists
.size
= bfd_get_section_size (sectp
);
2409 else if (section_is_p (sectp
->name
, &names
.types
))
2411 struct dwarf2_section_info type_section
;
2413 memset (&type_section
, 0, sizeof (type_section
));
2414 type_section
.s
.section
= sectp
;
2415 type_section
.size
= bfd_get_section_size (sectp
);
2417 VEC_safe_push (dwarf2_section_info_def
, this->types
,
2420 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2422 this->gdb_index
.s
.section
= sectp
;
2423 this->gdb_index
.size
= bfd_get_section_size (sectp
);
2425 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2427 this->debug_names
.s
.section
= sectp
;
2428 this->debug_names
.size
= bfd_get_section_size (sectp
);
2430 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2432 this->debug_aranges
.s
.section
= sectp
;
2433 this->debug_aranges
.size
= bfd_get_section_size (sectp
);
2436 if ((bfd_get_section_flags (abfd
, sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2437 && bfd_section_vma (abfd
, sectp
) == 0)
2438 this->has_section_at_zero
= true;
2441 /* A helper function that decides whether a section is empty,
2445 dwarf2_section_empty_p (const struct dwarf2_section_info
*section
)
2447 if (section
->is_virtual
)
2448 return section
->size
== 0;
2449 return section
->s
.section
== NULL
|| section
->size
== 0;
2452 /* See dwarf2read.h. */
2455 dwarf2_read_section (struct objfile
*objfile
, dwarf2_section_info
*info
)
2459 gdb_byte
*buf
, *retbuf
;
2463 info
->buffer
= NULL
;
2466 if (dwarf2_section_empty_p (info
))
2469 sectp
= get_section_bfd_section (info
);
2471 /* If this is a virtual section we need to read in the real one first. */
2472 if (info
->is_virtual
)
2474 struct dwarf2_section_info
*containing_section
=
2475 get_containing_section (info
);
2477 gdb_assert (sectp
!= NULL
);
2478 if ((sectp
->flags
& SEC_RELOC
) != 0)
2480 error (_("Dwarf Error: DWP format V2 with relocations is not"
2481 " supported in section %s [in module %s]"),
2482 get_section_name (info
), get_section_file_name (info
));
2484 dwarf2_read_section (objfile
, containing_section
);
2485 /* Other code should have already caught virtual sections that don't
2487 gdb_assert (info
->virtual_offset
+ info
->size
2488 <= containing_section
->size
);
2489 /* If the real section is empty or there was a problem reading the
2490 section we shouldn't get here. */
2491 gdb_assert (containing_section
->buffer
!= NULL
);
2492 info
->buffer
= containing_section
->buffer
+ info
->virtual_offset
;
2496 /* If the section has relocations, we must read it ourselves.
2497 Otherwise we attach it to the BFD. */
2498 if ((sectp
->flags
& SEC_RELOC
) == 0)
2500 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
2504 buf
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
2507 /* When debugging .o files, we may need to apply relocations; see
2508 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2509 We never compress sections in .o files, so we only need to
2510 try this when the section is not compressed. */
2511 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
2514 info
->buffer
= retbuf
;
2518 abfd
= get_section_bfd_owner (info
);
2519 gdb_assert (abfd
!= NULL
);
2521 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
2522 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
2524 error (_("Dwarf Error: Can't read DWARF data"
2525 " in section %s [in module %s]"),
2526 bfd_section_name (abfd
, sectp
), bfd_get_filename (abfd
));
2530 /* A helper function that returns the size of a section in a safe way.
2531 If you are positive that the section has been read before using the
2532 size, then it is safe to refer to the dwarf2_section_info object's
2533 "size" field directly. In other cases, you must call this
2534 function, because for compressed sections the size field is not set
2535 correctly until the section has been read. */
2537 static bfd_size_type
2538 dwarf2_section_size (struct objfile
*objfile
,
2539 struct dwarf2_section_info
*info
)
2542 dwarf2_read_section (objfile
, info
);
2546 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2550 dwarf2_get_section_info (struct objfile
*objfile
,
2551 enum dwarf2_section_enum sect
,
2552 asection
**sectp
, const gdb_byte
**bufp
,
2553 bfd_size_type
*sizep
)
2555 struct dwarf2_per_objfile
*data
2556 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
2557 dwarf2_objfile_data_key
);
2558 struct dwarf2_section_info
*info
;
2560 /* We may see an objfile without any DWARF, in which case we just
2571 case DWARF2_DEBUG_FRAME
:
2572 info
= &data
->frame
;
2574 case DWARF2_EH_FRAME
:
2575 info
= &data
->eh_frame
;
2578 gdb_assert_not_reached ("unexpected section");
2581 dwarf2_read_section (objfile
, info
);
2583 *sectp
= get_section_bfd_section (info
);
2584 *bufp
= info
->buffer
;
2585 *sizep
= info
->size
;
2588 /* A helper function to find the sections for a .dwz file. */
2591 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2593 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2595 /* Note that we only support the standard ELF names, because .dwz
2596 is ELF-only (at the time of writing). */
2597 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2599 dwz_file
->abbrev
.s
.section
= sectp
;
2600 dwz_file
->abbrev
.size
= bfd_get_section_size (sectp
);
2602 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2604 dwz_file
->info
.s
.section
= sectp
;
2605 dwz_file
->info
.size
= bfd_get_section_size (sectp
);
2607 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2609 dwz_file
->str
.s
.section
= sectp
;
2610 dwz_file
->str
.size
= bfd_get_section_size (sectp
);
2612 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2614 dwz_file
->line
.s
.section
= sectp
;
2615 dwz_file
->line
.size
= bfd_get_section_size (sectp
);
2617 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2619 dwz_file
->macro
.s
.section
= sectp
;
2620 dwz_file
->macro
.size
= bfd_get_section_size (sectp
);
2622 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2624 dwz_file
->gdb_index
.s
.section
= sectp
;
2625 dwz_file
->gdb_index
.size
= bfd_get_section_size (sectp
);
2627 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2629 dwz_file
->debug_names
.s
.section
= sectp
;
2630 dwz_file
->debug_names
.size
= bfd_get_section_size (sectp
);
2634 /* Open the separate '.dwz' debug file, if needed. Return NULL if
2635 there is no .gnu_debugaltlink section in the file. Error if there
2636 is such a section but the file cannot be found. */
2638 static struct dwz_file
*
2639 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2641 const char *filename
;
2642 struct dwz_file
*result
;
2643 bfd_size_type buildid_len_arg
;
2647 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2648 return dwarf2_per_objfile
->dwz_file
;
2650 bfd_set_error (bfd_error_no_error
);
2651 gdb::unique_xmalloc_ptr
<char> data
2652 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2653 &buildid_len_arg
, &buildid
));
2656 if (bfd_get_error () == bfd_error_no_error
)
2658 error (_("could not read '.gnu_debugaltlink' section: %s"),
2659 bfd_errmsg (bfd_get_error ()));
2662 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2664 buildid_len
= (size_t) buildid_len_arg
;
2666 filename
= data
.get ();
2668 std::string abs_storage
;
2669 if (!IS_ABSOLUTE_PATH (filename
))
2671 gdb::unique_xmalloc_ptr
<char> abs
2672 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2674 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2675 filename
= abs_storage
.c_str ();
2678 /* First try the file name given in the section. If that doesn't
2679 work, try to use the build-id instead. */
2680 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2681 if (dwz_bfd
!= NULL
)
2683 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2687 if (dwz_bfd
== NULL
)
2688 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2690 if (dwz_bfd
== NULL
)
2691 error (_("could not find '.gnu_debugaltlink' file for %s"),
2692 objfile_name (dwarf2_per_objfile
->objfile
));
2694 result
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
2696 result
->dwz_bfd
= dwz_bfd
.release ();
2698 bfd_map_over_sections (result
->dwz_bfd
, locate_dwz_sections
, result
);
2700 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, result
->dwz_bfd
);
2701 dwarf2_per_objfile
->dwz_file
= result
;
2705 /* DWARF quick_symbols_functions support. */
2707 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2708 unique line tables, so we maintain a separate table of all .debug_line
2709 derived entries to support the sharing.
2710 All the quick functions need is the list of file names. We discard the
2711 line_header when we're done and don't need to record it here. */
2712 struct quick_file_names
2714 /* The data used to construct the hash key. */
2715 struct stmt_list_hash hash
;
2717 /* The number of entries in file_names, real_names. */
2718 unsigned int num_file_names
;
2720 /* The file names from the line table, after being run through
2722 const char **file_names
;
2724 /* The file names from the line table after being run through
2725 gdb_realpath. These are computed lazily. */
2726 const char **real_names
;
2729 /* When using the index (and thus not using psymtabs), each CU has an
2730 object of this type. This is used to hold information needed by
2731 the various "quick" methods. */
2732 struct dwarf2_per_cu_quick_data
2734 /* The file table. This can be NULL if there was no file table
2735 or it's currently not read in.
2736 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2737 struct quick_file_names
*file_names
;
2739 /* The corresponding symbol table. This is NULL if symbols for this
2740 CU have not yet been read. */
2741 struct compunit_symtab
*compunit_symtab
;
2743 /* A temporary mark bit used when iterating over all CUs in
2744 expand_symtabs_matching. */
2745 unsigned int mark
: 1;
2747 /* True if we've tried to read the file table and found there isn't one.
2748 There will be no point in trying to read it again next time. */
2749 unsigned int no_file_data
: 1;
2752 /* Utility hash function for a stmt_list_hash. */
2755 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2759 if (stmt_list_hash
->dwo_unit
!= NULL
)
2760 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2761 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2765 /* Utility equality function for a stmt_list_hash. */
2768 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2769 const struct stmt_list_hash
*rhs
)
2771 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2773 if (lhs
->dwo_unit
!= NULL
2774 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2777 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2780 /* Hash function for a quick_file_names. */
2783 hash_file_name_entry (const void *e
)
2785 const struct quick_file_names
*file_data
2786 = (const struct quick_file_names
*) e
;
2788 return hash_stmt_list_entry (&file_data
->hash
);
2791 /* Equality function for a quick_file_names. */
2794 eq_file_name_entry (const void *a
, const void *b
)
2796 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2797 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2799 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2802 /* Delete function for a quick_file_names. */
2805 delete_file_name_entry (void *e
)
2807 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2810 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2812 xfree ((void*) file_data
->file_names
[i
]);
2813 if (file_data
->real_names
)
2814 xfree ((void*) file_data
->real_names
[i
]);
2817 /* The space for the struct itself lives on objfile_obstack,
2818 so we don't free it here. */
2821 /* Create a quick_file_names hash table. */
2824 create_quick_file_names_table (unsigned int nr_initial_entries
)
2826 return htab_create_alloc (nr_initial_entries
,
2827 hash_file_name_entry
, eq_file_name_entry
,
2828 delete_file_name_entry
, xcalloc
, xfree
);
2831 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2832 have to be created afterwards. You should call age_cached_comp_units after
2833 processing PER_CU->CU. dw2_setup must have been already called. */
2836 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2838 if (per_cu
->is_debug_types
)
2839 load_full_type_unit (per_cu
);
2841 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2843 if (per_cu
->cu
== NULL
)
2844 return; /* Dummy CU. */
2846 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2849 /* Read in the symbols for PER_CU. */
2852 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2854 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2856 /* Skip type_unit_groups, reading the type units they contain
2857 is handled elsewhere. */
2858 if (IS_TYPE_UNIT_GROUP (per_cu
))
2861 /* The destructor of dwarf2_queue_guard frees any entries left on
2862 the queue. After this point we're guaranteed to leave this function
2863 with the dwarf queue empty. */
2864 dwarf2_queue_guard q_guard
;
2866 if (dwarf2_per_objfile
->using_index
2867 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2868 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2870 queue_comp_unit (per_cu
, language_minimal
);
2871 load_cu (per_cu
, skip_partial
);
2873 /* If we just loaded a CU from a DWO, and we're working with an index
2874 that may badly handle TUs, load all the TUs in that DWO as well.
2875 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2876 if (!per_cu
->is_debug_types
2877 && per_cu
->cu
!= NULL
2878 && per_cu
->cu
->dwo_unit
!= NULL
2879 && dwarf2_per_objfile
->index_table
!= NULL
2880 && dwarf2_per_objfile
->index_table
->version
<= 7
2881 /* DWP files aren't supported yet. */
2882 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2883 queue_and_load_all_dwo_tus (per_cu
);
2886 process_queue (dwarf2_per_objfile
);
2888 /* Age the cache, releasing compilation units that have not
2889 been used recently. */
2890 age_cached_comp_units (dwarf2_per_objfile
);
2893 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2894 the objfile from which this CU came. Returns the resulting symbol
2897 static struct compunit_symtab
*
2898 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2900 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2902 gdb_assert (dwarf2_per_objfile
->using_index
);
2903 if (!per_cu
->v
.quick
->compunit_symtab
)
2905 free_cached_comp_units
freer (dwarf2_per_objfile
);
2906 scoped_restore decrementer
= increment_reading_symtab ();
2907 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2908 process_cu_includes (dwarf2_per_objfile
);
2911 return per_cu
->v
.quick
->compunit_symtab
;
2914 /* See declaration. */
2916 dwarf2_per_cu_data
*
2917 dwarf2_per_objfile::get_cutu (int index
)
2919 if (index
>= this->all_comp_units
.size ())
2921 index
-= this->all_comp_units
.size ();
2922 gdb_assert (index
< this->all_type_units
.size ());
2923 return &this->all_type_units
[index
]->per_cu
;
2926 return this->all_comp_units
[index
];
2929 /* See declaration. */
2931 dwarf2_per_cu_data
*
2932 dwarf2_per_objfile::get_cu (int index
)
2934 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2936 return this->all_comp_units
[index
];
2939 /* See declaration. */
2942 dwarf2_per_objfile::get_tu (int index
)
2944 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2946 return this->all_type_units
[index
];
2949 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2950 objfile_obstack, and constructed with the specified field
2953 static dwarf2_per_cu_data
*
2954 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2955 struct dwarf2_section_info
*section
,
2957 sect_offset sect_off
, ULONGEST length
)
2959 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2960 dwarf2_per_cu_data
*the_cu
2961 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2962 struct dwarf2_per_cu_data
);
2963 the_cu
->sect_off
= sect_off
;
2964 the_cu
->length
= length
;
2965 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2966 the_cu
->section
= section
;
2967 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2968 struct dwarf2_per_cu_quick_data
);
2969 the_cu
->is_dwz
= is_dwz
;
2973 /* A helper for create_cus_from_index that handles a given list of
2977 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2978 const gdb_byte
*cu_list
, offset_type n_elements
,
2979 struct dwarf2_section_info
*section
,
2982 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2984 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2986 sect_offset sect_off
2987 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2988 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2991 dwarf2_per_cu_data
*per_cu
2992 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
2994 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
2998 /* Read the CU list from the mapped index, and use it to create all
2999 the CU objects for this objfile. */
3002 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3003 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
3004 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
3006 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
3007 dwarf2_per_objfile
->all_comp_units
.reserve
3008 ((cu_list_elements
+ dwz_elements
) / 2);
3010 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3011 &dwarf2_per_objfile
->info
, 0);
3013 if (dwz_elements
== 0)
3016 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3017 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
3021 /* Create the signatured type hash table from the index. */
3024 create_signatured_type_table_from_index
3025 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3026 struct dwarf2_section_info
*section
,
3027 const gdb_byte
*bytes
,
3028 offset_type elements
)
3030 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3032 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
3033 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
3035 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3037 for (offset_type i
= 0; i
< elements
; i
+= 3)
3039 struct signatured_type
*sig_type
;
3042 cu_offset type_offset_in_tu
;
3044 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3045 sect_offset sect_off
3046 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
3048 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
3050 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
3053 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3054 struct signatured_type
);
3055 sig_type
->signature
= signature
;
3056 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3057 sig_type
->per_cu
.is_debug_types
= 1;
3058 sig_type
->per_cu
.section
= section
;
3059 sig_type
->per_cu
.sect_off
= sect_off
;
3060 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3061 sig_type
->per_cu
.v
.quick
3062 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3063 struct dwarf2_per_cu_quick_data
);
3065 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3068 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
3071 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3074 /* Create the signatured type hash table from .debug_names. */
3077 create_signatured_type_table_from_debug_names
3078 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3079 const mapped_debug_names
&map
,
3080 struct dwarf2_section_info
*section
,
3081 struct dwarf2_section_info
*abbrev_section
)
3083 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3085 dwarf2_read_section (objfile
, section
);
3086 dwarf2_read_section (objfile
, abbrev_section
);
3088 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
3089 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
3091 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3093 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
3095 struct signatured_type
*sig_type
;
3098 sect_offset sect_off
3099 = (sect_offset
) (extract_unsigned_integer
3100 (map
.tu_table_reordered
+ i
* map
.offset_size
,
3102 map
.dwarf5_byte_order
));
3104 comp_unit_head cu_header
;
3105 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
3107 section
->buffer
+ to_underlying (sect_off
),
3110 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3111 struct signatured_type
);
3112 sig_type
->signature
= cu_header
.signature
;
3113 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
3114 sig_type
->per_cu
.is_debug_types
= 1;
3115 sig_type
->per_cu
.section
= section
;
3116 sig_type
->per_cu
.sect_off
= sect_off
;
3117 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3118 sig_type
->per_cu
.v
.quick
3119 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3120 struct dwarf2_per_cu_quick_data
);
3122 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3125 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
3128 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3131 /* Read the address map data from the mapped index, and use it to
3132 populate the objfile's psymtabs_addrmap. */
3135 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3136 struct mapped_index
*index
)
3138 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3139 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3140 const gdb_byte
*iter
, *end
;
3141 struct addrmap
*mutable_map
;
3144 auto_obstack temp_obstack
;
3146 mutable_map
= addrmap_create_mutable (&temp_obstack
);
3148 iter
= index
->address_table
.data ();
3149 end
= iter
+ index
->address_table
.size ();
3151 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3155 ULONGEST hi
, lo
, cu_index
;
3156 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3158 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3160 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
3165 complaint (&symfile_complaints
,
3166 _(".gdb_index address table has invalid range (%s - %s)"),
3167 hex_string (lo
), hex_string (hi
));
3171 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
3173 complaint (&symfile_complaints
,
3174 _(".gdb_index address table has invalid CU number %u"),
3175 (unsigned) cu_index
);
3179 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
);
3180 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
);
3181 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
3182 dwarf2_per_objfile
->get_cu (cu_index
));
3185 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
3186 &objfile
->objfile_obstack
);
3189 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
3190 populate the objfile's psymtabs_addrmap. */
3193 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3194 struct dwarf2_section_info
*section
)
3196 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3197 bfd
*abfd
= objfile
->obfd
;
3198 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3199 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
3200 SECT_OFF_TEXT (objfile
));
3202 auto_obstack temp_obstack
;
3203 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
3205 std::unordered_map
<sect_offset
,
3206 dwarf2_per_cu_data
*,
3207 gdb::hash_enum
<sect_offset
>>
3208 debug_info_offset_to_per_cu
;
3209 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3211 const auto insertpair
3212 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
3213 if (!insertpair
.second
)
3215 warning (_("Section .debug_aranges in %s has duplicate "
3216 "debug_info_offset %s, ignoring .debug_aranges."),
3217 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
3222 dwarf2_read_section (objfile
, section
);
3224 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
3226 const gdb_byte
*addr
= section
->buffer
;
3228 while (addr
< section
->buffer
+ section
->size
)
3230 const gdb_byte
*const entry_addr
= addr
;
3231 unsigned int bytes_read
;
3233 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
3237 const gdb_byte
*const entry_end
= addr
+ entry_length
;
3238 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
3239 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
3240 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
3242 warning (_("Section .debug_aranges in %s entry at offset %zu "
3243 "length %s exceeds section length %s, "
3244 "ignoring .debug_aranges."),
3245 objfile_name (objfile
), entry_addr
- section
->buffer
,
3246 plongest (bytes_read
+ entry_length
),
3247 pulongest (section
->size
));
3251 /* The version number. */
3252 const uint16_t version
= read_2_bytes (abfd
, addr
);
3256 warning (_("Section .debug_aranges in %s entry at offset %zu "
3257 "has unsupported version %d, ignoring .debug_aranges."),
3258 objfile_name (objfile
), entry_addr
- section
->buffer
,
3263 const uint64_t debug_info_offset
3264 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
3265 addr
+= offset_size
;
3266 const auto per_cu_it
3267 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
3268 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
3270 warning (_("Section .debug_aranges in %s entry at offset %zu "
3271 "debug_info_offset %s does not exists, "
3272 "ignoring .debug_aranges."),
3273 objfile_name (objfile
), entry_addr
- section
->buffer
,
3274 pulongest (debug_info_offset
));
3277 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
3279 const uint8_t address_size
= *addr
++;
3280 if (address_size
< 1 || address_size
> 8)
3282 warning (_("Section .debug_aranges in %s entry at offset %zu "
3283 "address_size %u is invalid, ignoring .debug_aranges."),
3284 objfile_name (objfile
), entry_addr
- section
->buffer
,
3289 const uint8_t segment_selector_size
= *addr
++;
3290 if (segment_selector_size
!= 0)
3292 warning (_("Section .debug_aranges in %s entry at offset %zu "
3293 "segment_selector_size %u is not supported, "
3294 "ignoring .debug_aranges."),
3295 objfile_name (objfile
), entry_addr
- section
->buffer
,
3296 segment_selector_size
);
3300 /* Must pad to an alignment boundary that is twice the address
3301 size. It is undocumented by the DWARF standard but GCC does
3303 for (size_t padding
= ((-(addr
- section
->buffer
))
3304 & (2 * address_size
- 1));
3305 padding
> 0; padding
--)
3308 warning (_("Section .debug_aranges in %s entry at offset %zu "
3309 "padding is not zero, ignoring .debug_aranges."),
3310 objfile_name (objfile
), entry_addr
- section
->buffer
);
3316 if (addr
+ 2 * address_size
> entry_end
)
3318 warning (_("Section .debug_aranges in %s entry at offset %zu "
3319 "address list is not properly terminated, "
3320 "ignoring .debug_aranges."),
3321 objfile_name (objfile
), entry_addr
- section
->buffer
);
3324 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
3326 addr
+= address_size
;
3327 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
3329 addr
+= address_size
;
3330 if (start
== 0 && length
== 0)
3332 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3334 /* Symbol was eliminated due to a COMDAT group. */
3337 ULONGEST end
= start
+ length
;
3338 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
);
3339 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
);
3340 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
3344 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
3345 &objfile
->objfile_obstack
);
3348 /* Find a slot in the mapped index INDEX for the object named NAME.
3349 If NAME is found, set *VEC_OUT to point to the CU vector in the
3350 constant pool and return true. If NAME cannot be found, return
3354 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3355 offset_type
**vec_out
)
3358 offset_type slot
, step
;
3359 int (*cmp
) (const char *, const char *);
3361 gdb::unique_xmalloc_ptr
<char> without_params
;
3362 if (current_language
->la_language
== language_cplus
3363 || current_language
->la_language
== language_fortran
3364 || current_language
->la_language
== language_d
)
3366 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3369 if (strchr (name
, '(') != NULL
)
3371 without_params
= cp_remove_params (name
);
3373 if (without_params
!= NULL
)
3374 name
= without_params
.get ();
3378 /* Index version 4 did not support case insensitive searches. But the
3379 indices for case insensitive languages are built in lowercase, therefore
3380 simulate our NAME being searched is also lowercased. */
3381 hash
= mapped_index_string_hash ((index
->version
== 4
3382 && case_sensitivity
== case_sensitive_off
3383 ? 5 : index
->version
),
3386 slot
= hash
& (index
->symbol_table
.size () - 1);
3387 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
3388 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3394 const auto &bucket
= index
->symbol_table
[slot
];
3395 if (bucket
.name
== 0 && bucket
.vec
== 0)
3398 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
3399 if (!cmp (name
, str
))
3401 *vec_out
= (offset_type
*) (index
->constant_pool
3402 + MAYBE_SWAP (bucket
.vec
));
3406 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
3410 /* A helper function that reads the .gdb_index from SECTION and fills
3411 in MAP. FILENAME is the name of the file containing the section;
3412 it is used for error reporting. DEPRECATED_OK is true if it is
3413 ok to use deprecated sections.
3415 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3416 out parameters that are filled in with information about the CU and
3417 TU lists in the section.
3419 Returns 1 if all went well, 0 otherwise. */
3422 read_index_from_section (struct objfile
*objfile
,
3423 const char *filename
,
3425 struct dwarf2_section_info
*section
,
3426 struct mapped_index
*map
,
3427 const gdb_byte
**cu_list
,
3428 offset_type
*cu_list_elements
,
3429 const gdb_byte
**types_list
,
3430 offset_type
*types_list_elements
)
3432 const gdb_byte
*addr
;
3433 offset_type version
;
3434 offset_type
*metadata
;
3437 if (dwarf2_section_empty_p (section
))
3440 /* Older elfutils strip versions could keep the section in the main
3441 executable while splitting it for the separate debug info file. */
3442 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
3445 dwarf2_read_section (objfile
, section
);
3447 addr
= section
->buffer
;
3448 /* Version check. */
3449 version
= MAYBE_SWAP (*(offset_type
*) addr
);
3450 /* Versions earlier than 3 emitted every copy of a psymbol. This
3451 causes the index to behave very poorly for certain requests. Version 3
3452 contained incomplete addrmap. So, it seems better to just ignore such
3456 static int warning_printed
= 0;
3457 if (!warning_printed
)
3459 warning (_("Skipping obsolete .gdb_index section in %s."),
3461 warning_printed
= 1;
3465 /* Index version 4 uses a different hash function than index version
3468 Versions earlier than 6 did not emit psymbols for inlined
3469 functions. Using these files will cause GDB not to be able to
3470 set breakpoints on inlined functions by name, so we ignore these
3471 indices unless the user has done
3472 "set use-deprecated-index-sections on". */
3473 if (version
< 6 && !deprecated_ok
)
3475 static int warning_printed
= 0;
3476 if (!warning_printed
)
3479 Skipping deprecated .gdb_index section in %s.\n\
3480 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3481 to use the section anyway."),
3483 warning_printed
= 1;
3487 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3488 of the TU (for symbols coming from TUs),
3489 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3490 Plus gold-generated indices can have duplicate entries for global symbols,
3491 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3492 These are just performance bugs, and we can't distinguish gdb-generated
3493 indices from gold-generated ones, so issue no warning here. */
3495 /* Indexes with higher version than the one supported by GDB may be no
3496 longer backward compatible. */
3500 map
->version
= version
;
3502 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3505 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3506 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3510 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3511 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3512 - MAYBE_SWAP (metadata
[i
]))
3516 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3517 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3519 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3522 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3523 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3525 = gdb::array_view
<mapped_index::symbol_table_slot
>
3526 ((mapped_index::symbol_table_slot
*) symbol_table
,
3527 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3530 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3535 /* Read .gdb_index. If everything went ok, initialize the "quick"
3536 elements of all the CUs and return 1. Otherwise, return 0. */
3539 dwarf2_read_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
3541 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3542 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3543 struct dwz_file
*dwz
;
3544 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3546 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3547 if (!read_index_from_section (objfile
, objfile_name (objfile
),
3548 use_deprecated_index_sections
,
3549 &dwarf2_per_objfile
->gdb_index
, map
.get (),
3550 &cu_list
, &cu_list_elements
,
3551 &types_list
, &types_list_elements
))
3554 /* Don't use the index if it's empty. */
3555 if (map
->symbol_table
.empty ())
3558 /* If there is a .dwz file, read it so we can get its CU list as
3560 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3563 struct mapped_index dwz_map
;
3564 const gdb_byte
*dwz_types_ignore
;
3565 offset_type dwz_types_elements_ignore
;
3567 if (!read_index_from_section (objfile
, bfd_get_filename (dwz
->dwz_bfd
),
3569 &dwz
->gdb_index
, &dwz_map
,
3570 &dwz_list
, &dwz_list_elements
,
3572 &dwz_types_elements_ignore
))
3574 warning (_("could not read '.gdb_index' section from %s; skipping"),
3575 bfd_get_filename (dwz
->dwz_bfd
));
3580 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3581 dwz_list
, dwz_list_elements
);
3583 if (types_list_elements
)
3585 struct dwarf2_section_info
*section
;
3587 /* We can only handle a single .debug_types when we have an
3589 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
3592 section
= VEC_index (dwarf2_section_info_def
,
3593 dwarf2_per_objfile
->types
, 0);
3595 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3596 types_list
, types_list_elements
);
3599 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3601 dwarf2_per_objfile
->index_table
= std::move (map
);
3602 dwarf2_per_objfile
->using_index
= 1;
3603 dwarf2_per_objfile
->quick_file_names_table
=
3604 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3609 /* die_reader_func for dw2_get_file_names. */
3612 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3613 const gdb_byte
*info_ptr
,
3614 struct die_info
*comp_unit_die
,
3618 struct dwarf2_cu
*cu
= reader
->cu
;
3619 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3620 struct dwarf2_per_objfile
*dwarf2_per_objfile
3621 = cu
->per_cu
->dwarf2_per_objfile
;
3622 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3623 struct dwarf2_per_cu_data
*lh_cu
;
3624 struct attribute
*attr
;
3627 struct quick_file_names
*qfn
;
3629 gdb_assert (! this_cu
->is_debug_types
);
3631 /* Our callers never want to match partial units -- instead they
3632 will match the enclosing full CU. */
3633 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3635 this_cu
->v
.quick
->no_file_data
= 1;
3643 sect_offset line_offset
{};
3645 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3648 struct quick_file_names find_entry
;
3650 line_offset
= (sect_offset
) DW_UNSND (attr
);
3652 /* We may have already read in this line header (TU line header sharing).
3653 If we have we're done. */
3654 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3655 find_entry
.hash
.line_sect_off
= line_offset
;
3656 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
3657 &find_entry
, INSERT
);
3660 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3664 lh
= dwarf_decode_line_header (line_offset
, cu
);
3668 lh_cu
->v
.quick
->no_file_data
= 1;
3672 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3673 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3674 qfn
->hash
.line_sect_off
= line_offset
;
3675 gdb_assert (slot
!= NULL
);
3678 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3680 qfn
->num_file_names
= lh
->file_names
.size ();
3682 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, lh
->file_names
.size ());
3683 for (i
= 0; i
< lh
->file_names
.size (); ++i
)
3684 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
.get (), fnd
.comp_dir
);
3685 qfn
->real_names
= NULL
;
3687 lh_cu
->v
.quick
->file_names
= qfn
;
3690 /* A helper for the "quick" functions which attempts to read the line
3691 table for THIS_CU. */
3693 static struct quick_file_names
*
3694 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3696 /* This should never be called for TUs. */
3697 gdb_assert (! this_cu
->is_debug_types
);
3698 /* Nor type unit groups. */
3699 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3701 if (this_cu
->v
.quick
->file_names
!= NULL
)
3702 return this_cu
->v
.quick
->file_names
;
3703 /* If we know there is no line data, no point in looking again. */
3704 if (this_cu
->v
.quick
->no_file_data
)
3707 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
3709 if (this_cu
->v
.quick
->no_file_data
)
3711 return this_cu
->v
.quick
->file_names
;
3714 /* A helper for the "quick" functions which computes and caches the
3715 real path for a given file name from the line table. */
3718 dw2_get_real_path (struct objfile
*objfile
,
3719 struct quick_file_names
*qfn
, int index
)
3721 if (qfn
->real_names
== NULL
)
3722 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3723 qfn
->num_file_names
, const char *);
3725 if (qfn
->real_names
[index
] == NULL
)
3726 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3728 return qfn
->real_names
[index
];
3731 static struct symtab
*
3732 dw2_find_last_source_symtab (struct objfile
*objfile
)
3734 struct dwarf2_per_objfile
*dwarf2_per_objfile
3735 = get_dwarf2_per_objfile (objfile
);
3736 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3737 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3742 return compunit_primary_filetab (cust
);
3745 /* Traversal function for dw2_forget_cached_source_info. */
3748 dw2_free_cached_file_names (void **slot
, void *info
)
3750 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3752 if (file_data
->real_names
)
3756 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3758 xfree ((void*) file_data
->real_names
[i
]);
3759 file_data
->real_names
[i
] = NULL
;
3767 dw2_forget_cached_source_info (struct objfile
*objfile
)
3769 struct dwarf2_per_objfile
*dwarf2_per_objfile
3770 = get_dwarf2_per_objfile (objfile
);
3772 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3773 dw2_free_cached_file_names
, NULL
);
3776 /* Helper function for dw2_map_symtabs_matching_filename that expands
3777 the symtabs and calls the iterator. */
3780 dw2_map_expand_apply (struct objfile
*objfile
,
3781 struct dwarf2_per_cu_data
*per_cu
,
3782 const char *name
, const char *real_path
,
3783 gdb::function_view
<bool (symtab
*)> callback
)
3785 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3787 /* Don't visit already-expanded CUs. */
3788 if (per_cu
->v
.quick
->compunit_symtab
)
3791 /* This may expand more than one symtab, and we want to iterate over
3793 dw2_instantiate_symtab (per_cu
, false);
3795 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3796 last_made
, callback
);
3799 /* Implementation of the map_symtabs_matching_filename method. */
3802 dw2_map_symtabs_matching_filename
3803 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3804 gdb::function_view
<bool (symtab
*)> callback
)
3806 const char *name_basename
= lbasename (name
);
3807 struct dwarf2_per_objfile
*dwarf2_per_objfile
3808 = get_dwarf2_per_objfile (objfile
);
3810 /* The rule is CUs specify all the files, including those used by
3811 any TU, so there's no need to scan TUs here. */
3813 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3815 /* We only need to look at symtabs not already expanded. */
3816 if (per_cu
->v
.quick
->compunit_symtab
)
3819 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3820 if (file_data
== NULL
)
3823 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3825 const char *this_name
= file_data
->file_names
[j
];
3826 const char *this_real_name
;
3828 if (compare_filenames_for_search (this_name
, name
))
3830 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3836 /* Before we invoke realpath, which can get expensive when many
3837 files are involved, do a quick comparison of the basenames. */
3838 if (! basenames_may_differ
3839 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3842 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3843 if (compare_filenames_for_search (this_real_name
, name
))
3845 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3851 if (real_path
!= NULL
)
3853 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3854 gdb_assert (IS_ABSOLUTE_PATH (name
));
3855 if (this_real_name
!= NULL
3856 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3858 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3870 /* Struct used to manage iterating over all CUs looking for a symbol. */
3872 struct dw2_symtab_iterator
3874 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3875 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3876 /* If non-zero, only look for symbols that match BLOCK_INDEX. */
3877 int want_specific_block
;
3878 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
3879 Unused if !WANT_SPECIFIC_BLOCK. */
3881 /* The kind of symbol we're looking for. */
3883 /* The list of CUs from the index entry of the symbol,
3884 or NULL if not found. */
3886 /* The next element in VEC to look at. */
3888 /* The number of elements in VEC, or zero if there is no match. */
3890 /* Have we seen a global version of the symbol?
3891 If so we can ignore all further global instances.
3892 This is to work around gold/15646, inefficient gold-generated
3897 /* Initialize the index symtab iterator ITER.
3898 If WANT_SPECIFIC_BLOCK is non-zero, only look for symbols
3899 in block BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
3902 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3903 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3904 int want_specific_block
,
3909 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3910 iter
->want_specific_block
= want_specific_block
;
3911 iter
->block_index
= block_index
;
3912 iter
->domain
= domain
;
3914 iter
->global_seen
= 0;
3916 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3918 /* index is NULL if OBJF_READNOW. */
3919 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3920 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3928 /* Return the next matching CU or NULL if there are no more. */
3930 static struct dwarf2_per_cu_data
*
3931 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3933 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3935 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3937 offset_type cu_index_and_attrs
=
3938 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3939 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3940 int want_static
= iter
->block_index
!= GLOBAL_BLOCK
;
3941 /* This value is only valid for index versions >= 7. */
3942 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3943 gdb_index_symbol_kind symbol_kind
=
3944 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3945 /* Only check the symbol attributes if they're present.
3946 Indices prior to version 7 don't record them,
3947 and indices >= 7 may elide them for certain symbols
3948 (gold does this). */
3950 (dwarf2_per_objfile
->index_table
->version
>= 7
3951 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3953 /* Don't crash on bad data. */
3954 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
3955 + dwarf2_per_objfile
->all_type_units
.size ()))
3957 complaint (&symfile_complaints
,
3958 _(".gdb_index entry has bad CU index"
3960 objfile_name (dwarf2_per_objfile
->objfile
));
3964 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
3966 /* Skip if already read in. */
3967 if (per_cu
->v
.quick
->compunit_symtab
)
3970 /* Check static vs global. */
3973 if (iter
->want_specific_block
3974 && want_static
!= is_static
)
3976 /* Work around gold/15646. */
3977 if (!is_static
&& iter
->global_seen
)
3980 iter
->global_seen
= 1;
3983 /* Only check the symbol's kind if it has one. */
3986 switch (iter
->domain
)
3989 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3990 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3991 /* Some types are also in VAR_DOMAIN. */
3992 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3996 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4000 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4015 static struct compunit_symtab
*
4016 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
4017 const char *name
, domain_enum domain
)
4019 struct compunit_symtab
*stab_best
= NULL
;
4020 struct dwarf2_per_objfile
*dwarf2_per_objfile
4021 = get_dwarf2_per_objfile (objfile
);
4023 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
4025 struct dw2_symtab_iterator iter
;
4026 struct dwarf2_per_cu_data
*per_cu
;
4028 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, 1, block_index
, domain
, name
);
4030 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4032 struct symbol
*sym
, *with_opaque
= NULL
;
4033 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
4034 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
4035 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
4037 sym
= block_find_symbol (block
, name
, domain
,
4038 block_find_non_opaque_type_preferred
,
4041 /* Some caution must be observed with overloaded functions
4042 and methods, since the index will not contain any overload
4043 information (but NAME might contain it). */
4046 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
4048 if (with_opaque
!= NULL
4049 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
4052 /* Keep looking through other CUs. */
4059 dw2_print_stats (struct objfile
*objfile
)
4061 struct dwarf2_per_objfile
*dwarf2_per_objfile
4062 = get_dwarf2_per_objfile (objfile
);
4063 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
4064 + dwarf2_per_objfile
->all_type_units
.size ());
4067 for (int i
= 0; i
< total
; ++i
)
4069 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4071 if (!per_cu
->v
.quick
->compunit_symtab
)
4074 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
4075 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
4078 /* This dumps minimal information about the index.
4079 It is called via "mt print objfiles".
4080 One use is to verify .gdb_index has been loaded by the
4081 gdb.dwarf2/gdb-index.exp testcase. */
4084 dw2_dump (struct objfile
*objfile
)
4086 struct dwarf2_per_objfile
*dwarf2_per_objfile
4087 = get_dwarf2_per_objfile (objfile
);
4089 gdb_assert (dwarf2_per_objfile
->using_index
);
4090 printf_filtered (".gdb_index:");
4091 if (dwarf2_per_objfile
->index_table
!= NULL
)
4093 printf_filtered (" version %d\n",
4094 dwarf2_per_objfile
->index_table
->version
);
4097 printf_filtered (" faked for \"readnow\"\n");
4098 printf_filtered ("\n");
4102 dw2_relocate (struct objfile
*objfile
,
4103 const struct section_offsets
*new_offsets
,
4104 const struct section_offsets
*delta
)
4106 /* There's nothing to relocate here. */
4110 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
4111 const char *func_name
)
4113 struct dwarf2_per_objfile
*dwarf2_per_objfile
4114 = get_dwarf2_per_objfile (objfile
);
4116 struct dw2_symtab_iterator iter
;
4117 struct dwarf2_per_cu_data
*per_cu
;
4119 /* Note: It doesn't matter what we pass for block_index here. */
4120 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, 0, GLOBAL_BLOCK
, VAR_DOMAIN
,
4123 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4124 dw2_instantiate_symtab (per_cu
, false);
4129 dw2_expand_all_symtabs (struct objfile
*objfile
)
4131 struct dwarf2_per_objfile
*dwarf2_per_objfile
4132 = get_dwarf2_per_objfile (objfile
);
4133 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
4134 + dwarf2_per_objfile
->all_type_units
.size ());
4136 for (int i
= 0; i
< total_units
; ++i
)
4138 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4140 /* We don't want to directly expand a partial CU, because if we
4141 read it with the wrong language, then assertion failures can
4142 be triggered later on. See PR symtab/23010. So, tell
4143 dw2_instantiate_symtab to skip partial CUs -- any important
4144 partial CU will be read via DW_TAG_imported_unit anyway. */
4145 dw2_instantiate_symtab (per_cu
, true);
4150 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
4151 const char *fullname
)
4153 struct dwarf2_per_objfile
*dwarf2_per_objfile
4154 = get_dwarf2_per_objfile (objfile
);
4156 /* We don't need to consider type units here.
4157 This is only called for examining code, e.g. expand_line_sal.
4158 There can be an order of magnitude (or more) more type units
4159 than comp units, and we avoid them if we can. */
4161 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4163 /* We only need to look at symtabs not already expanded. */
4164 if (per_cu
->v
.quick
->compunit_symtab
)
4167 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4168 if (file_data
== NULL
)
4171 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4173 const char *this_fullname
= file_data
->file_names
[j
];
4175 if (filename_cmp (this_fullname
, fullname
) == 0)
4177 dw2_instantiate_symtab (per_cu
, false);
4185 dw2_map_matching_symbols (struct objfile
*objfile
,
4186 const char * name
, domain_enum domain
,
4188 int (*callback
) (struct block
*,
4189 struct symbol
*, void *),
4190 void *data
, symbol_name_match_type match
,
4191 symbol_compare_ftype
*ordered_compare
)
4193 /* Currently unimplemented; used for Ada. The function can be called if the
4194 current language is Ada for a non-Ada objfile using GNU index. As Ada
4195 does not look for non-Ada symbols this function should just return. */
4198 /* Symbol name matcher for .gdb_index names.
4200 Symbol names in .gdb_index have a few particularities:
4202 - There's no indication of which is the language of each symbol.
4204 Since each language has its own symbol name matching algorithm,
4205 and we don't know which language is the right one, we must match
4206 each symbol against all languages. This would be a potential
4207 performance problem if it were not mitigated by the
4208 mapped_index::name_components lookup table, which significantly
4209 reduces the number of times we need to call into this matcher,
4210 making it a non-issue.
4212 - Symbol names in the index have no overload (parameter)
4213 information. I.e., in C++, "foo(int)" and "foo(long)" both
4214 appear as "foo" in the index, for example.
4216 This means that the lookup names passed to the symbol name
4217 matcher functions must have no parameter information either
4218 because (e.g.) symbol search name "foo" does not match
4219 lookup-name "foo(int)" [while swapping search name for lookup
4222 class gdb_index_symbol_name_matcher
4225 /* Prepares the vector of comparison functions for LOOKUP_NAME. */
4226 gdb_index_symbol_name_matcher (const lookup_name_info
&lookup_name
);
4228 /* Walk all the matcher routines and match SYMBOL_NAME against them.
4229 Returns true if any matcher matches. */
4230 bool matches (const char *symbol_name
);
4233 /* A reference to the lookup name we're matching against. */
4234 const lookup_name_info
&m_lookup_name
;
4236 /* A vector holding all the different symbol name matchers, for all
4238 std::vector
<symbol_name_matcher_ftype
*> m_symbol_name_matcher_funcs
;
4241 gdb_index_symbol_name_matcher::gdb_index_symbol_name_matcher
4242 (const lookup_name_info
&lookup_name
)
4243 : m_lookup_name (lookup_name
)
4245 /* Prepare the vector of comparison functions upfront, to avoid
4246 doing the same work for each symbol. Care is taken to avoid
4247 matching with the same matcher more than once if/when multiple
4248 languages use the same matcher function. */
4249 auto &matchers
= m_symbol_name_matcher_funcs
;
4250 matchers
.reserve (nr_languages
);
4252 matchers
.push_back (default_symbol_name_matcher
);
4254 for (int i
= 0; i
< nr_languages
; i
++)
4256 const language_defn
*lang
= language_def ((enum language
) i
);
4257 symbol_name_matcher_ftype
*name_matcher
4258 = get_symbol_name_matcher (lang
, m_lookup_name
);
4260 /* Don't insert the same comparison routine more than once.
4261 Note that we do this linear walk instead of a seemingly
4262 cheaper sorted insert, or use a std::set or something like
4263 that, because relative order of function addresses is not
4264 stable. This is not a problem in practice because the number
4265 of supported languages is low, and the cost here is tiny
4266 compared to the number of searches we'll do afterwards using
4268 if (name_matcher
!= default_symbol_name_matcher
4269 && (std::find (matchers
.begin (), matchers
.end (), name_matcher
)
4270 == matchers
.end ()))
4271 matchers
.push_back (name_matcher
);
4276 gdb_index_symbol_name_matcher::matches (const char *symbol_name
)
4278 for (auto matches_name
: m_symbol_name_matcher_funcs
)
4279 if (matches_name (symbol_name
, m_lookup_name
, NULL
))
4285 /* Starting from a search name, return the string that finds the upper
4286 bound of all strings that start with SEARCH_NAME in a sorted name
4287 list. Returns the empty string to indicate that the upper bound is
4288 the end of the list. */
4291 make_sort_after_prefix_name (const char *search_name
)
4293 /* When looking to complete "func", we find the upper bound of all
4294 symbols that start with "func" by looking for where we'd insert
4295 the closest string that would follow "func" in lexicographical
4296 order. Usually, that's "func"-with-last-character-incremented,
4297 i.e. "fund". Mind non-ASCII characters, though. Usually those
4298 will be UTF-8 multi-byte sequences, but we can't be certain.
4299 Especially mind the 0xff character, which is a valid character in
4300 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
4301 rule out compilers allowing it in identifiers. Note that
4302 conveniently, strcmp/strcasecmp are specified to compare
4303 characters interpreted as unsigned char. So what we do is treat
4304 the whole string as a base 256 number composed of a sequence of
4305 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
4306 to 0, and carries 1 to the following more-significant position.
4307 If the very first character in SEARCH_NAME ends up incremented
4308 and carries/overflows, then the upper bound is the end of the
4309 list. The string after the empty string is also the empty
4312 Some examples of this operation:
4314 SEARCH_NAME => "+1" RESULT
4318 "\xff" "a" "\xff" => "\xff" "b"
4323 Then, with these symbols for example:
4329 completing "func" looks for symbols between "func" and
4330 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
4331 which finds "func" and "func1", but not "fund".
4335 funcÿ (Latin1 'ÿ' [0xff])
4339 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
4340 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
4344 ÿÿ (Latin1 'ÿ' [0xff])
4347 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
4348 the end of the list.
4350 std::string after
= search_name
;
4351 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
4353 if (!after
.empty ())
4354 after
.back () = (unsigned char) after
.back () + 1;
4358 /* See declaration. */
4360 std::pair
<std::vector
<name_component
>::const_iterator
,
4361 std::vector
<name_component
>::const_iterator
>
4362 mapped_index_base::find_name_components_bounds
4363 (const lookup_name_info
&lookup_name_without_params
) const
4366 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4369 = lookup_name_without_params
.cplus ().lookup_name ().c_str ();
4371 /* Comparison function object for lower_bound that matches against a
4372 given symbol name. */
4373 auto lookup_compare_lower
= [&] (const name_component
&elem
,
4376 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4377 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4378 return name_cmp (elem_name
, name
) < 0;
4381 /* Comparison function object for upper_bound that matches against a
4382 given symbol name. */
4383 auto lookup_compare_upper
= [&] (const char *name
,
4384 const name_component
&elem
)
4386 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4387 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4388 return name_cmp (name
, elem_name
) < 0;
4391 auto begin
= this->name_components
.begin ();
4392 auto end
= this->name_components
.end ();
4394 /* Find the lower bound. */
4397 if (lookup_name_without_params
.completion_mode () && cplus
[0] == '\0')
4400 return std::lower_bound (begin
, end
, cplus
, lookup_compare_lower
);
4403 /* Find the upper bound. */
4406 if (lookup_name_without_params
.completion_mode ())
4408 /* In completion mode, we want UPPER to point past all
4409 symbols names that have the same prefix. I.e., with
4410 these symbols, and completing "func":
4412 function << lower bound
4414 other_function << upper bound
4416 We find the upper bound by looking for the insertion
4417 point of "func"-with-last-character-incremented,
4419 std::string after
= make_sort_after_prefix_name (cplus
);
4422 return std::lower_bound (lower
, end
, after
.c_str (),
4423 lookup_compare_lower
);
4426 return std::upper_bound (lower
, end
, cplus
, lookup_compare_upper
);
4429 return {lower
, upper
};
4432 /* See declaration. */
4435 mapped_index_base::build_name_components ()
4437 if (!this->name_components
.empty ())
4440 this->name_components_casing
= case_sensitivity
;
4442 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4444 /* The code below only knows how to break apart components of C++
4445 symbol names (and other languages that use '::' as
4446 namespace/module separator). If we add support for wild matching
4447 to some language that uses some other operator (E.g., Ada, Go and
4448 D use '.'), then we'll need to try splitting the symbol name
4449 according to that language too. Note that Ada does support wild
4450 matching, but doesn't currently support .gdb_index. */
4451 auto count
= this->symbol_name_count ();
4452 for (offset_type idx
= 0; idx
< count
; idx
++)
4454 if (this->symbol_name_slot_invalid (idx
))
4457 const char *name
= this->symbol_name_at (idx
);
4459 /* Add each name component to the name component table. */
4460 unsigned int previous_len
= 0;
4461 for (unsigned int current_len
= cp_find_first_component (name
);
4462 name
[current_len
] != '\0';
4463 current_len
+= cp_find_first_component (name
+ current_len
))
4465 gdb_assert (name
[current_len
] == ':');
4466 this->name_components
.push_back ({previous_len
, idx
});
4467 /* Skip the '::'. */
4469 previous_len
= current_len
;
4471 this->name_components
.push_back ({previous_len
, idx
});
4474 /* Sort name_components elements by name. */
4475 auto name_comp_compare
= [&] (const name_component
&left
,
4476 const name_component
&right
)
4478 const char *left_qualified
= this->symbol_name_at (left
.idx
);
4479 const char *right_qualified
= this->symbol_name_at (right
.idx
);
4481 const char *left_name
= left_qualified
+ left
.name_offset
;
4482 const char *right_name
= right_qualified
+ right
.name_offset
;
4484 return name_cmp (left_name
, right_name
) < 0;
4487 std::sort (this->name_components
.begin (),
4488 this->name_components
.end (),
4492 /* Helper for dw2_expand_symtabs_matching that works with a
4493 mapped_index_base instead of the containing objfile. This is split
4494 to a separate function in order to be able to unit test the
4495 name_components matching using a mock mapped_index_base. For each
4496 symbol name that matches, calls MATCH_CALLBACK, passing it the
4497 symbol's index in the mapped_index_base symbol table. */
4500 dw2_expand_symtabs_matching_symbol
4501 (mapped_index_base
&index
,
4502 const lookup_name_info
&lookup_name_in
,
4503 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4504 enum search_domain kind
,
4505 gdb::function_view
<void (offset_type
)> match_callback
)
4507 lookup_name_info lookup_name_without_params
4508 = lookup_name_in
.make_ignore_params ();
4509 gdb_index_symbol_name_matcher lookup_name_matcher
4510 (lookup_name_without_params
);
4512 /* Build the symbol name component sorted vector, if we haven't
4514 index
.build_name_components ();
4516 auto bounds
= index
.find_name_components_bounds (lookup_name_without_params
);
4518 /* Now for each symbol name in range, check to see if we have a name
4519 match, and if so, call the MATCH_CALLBACK callback. */
4521 /* The same symbol may appear more than once in the range though.
4522 E.g., if we're looking for symbols that complete "w", and we have
4523 a symbol named "w1::w2", we'll find the two name components for
4524 that same symbol in the range. To be sure we only call the
4525 callback once per symbol, we first collect the symbol name
4526 indexes that matched in a temporary vector and ignore
4528 std::vector
<offset_type
> matches
;
4529 matches
.reserve (std::distance (bounds
.first
, bounds
.second
));
4531 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4533 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
4535 if (!lookup_name_matcher
.matches (qualified
)
4536 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4539 matches
.push_back (bounds
.first
->idx
);
4542 std::sort (matches
.begin (), matches
.end ());
4544 /* Finally call the callback, once per match. */
4546 for (offset_type idx
: matches
)
4550 match_callback (idx
);
4555 /* Above we use a type wider than idx's for 'prev', since 0 and
4556 (offset_type)-1 are both possible values. */
4557 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4562 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4564 /* A mock .gdb_index/.debug_names-like name index table, enough to
4565 exercise dw2_expand_symtabs_matching_symbol, which works with the
4566 mapped_index_base interface. Builds an index from the symbol list
4567 passed as parameter to the constructor. */
4568 class mock_mapped_index
: public mapped_index_base
4571 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4572 : m_symbol_table (symbols
)
4575 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4577 /* Return the number of names in the symbol table. */
4578 size_t symbol_name_count () const override
4580 return m_symbol_table
.size ();
4583 /* Get the name of the symbol at IDX in the symbol table. */
4584 const char *symbol_name_at (offset_type idx
) const override
4586 return m_symbol_table
[idx
];
4590 gdb::array_view
<const char *> m_symbol_table
;
4593 /* Convenience function that converts a NULL pointer to a "<null>"
4594 string, to pass to print routines. */
4597 string_or_null (const char *str
)
4599 return str
!= NULL
? str
: "<null>";
4602 /* Check if a lookup_name_info built from
4603 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4604 index. EXPECTED_LIST is the list of expected matches, in expected
4605 matching order. If no match expected, then an empty list is
4606 specified. Returns true on success. On failure prints a warning
4607 indicating the file:line that failed, and returns false. */
4610 check_match (const char *file
, int line
,
4611 mock_mapped_index
&mock_index
,
4612 const char *name
, symbol_name_match_type match_type
,
4613 bool completion_mode
,
4614 std::initializer_list
<const char *> expected_list
)
4616 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4618 bool matched
= true;
4620 auto mismatch
= [&] (const char *expected_str
,
4623 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4624 "expected=\"%s\", got=\"%s\"\n"),
4626 (match_type
== symbol_name_match_type::FULL
4628 name
, string_or_null (expected_str
), string_or_null (got
));
4632 auto expected_it
= expected_list
.begin ();
4633 auto expected_end
= expected_list
.end ();
4635 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4637 [&] (offset_type idx
)
4639 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4640 const char *expected_str
4641 = expected_it
== expected_end
? NULL
: *expected_it
++;
4643 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4644 mismatch (expected_str
, matched_name
);
4647 const char *expected_str
4648 = expected_it
== expected_end
? NULL
: *expected_it
++;
4649 if (expected_str
!= NULL
)
4650 mismatch (expected_str
, NULL
);
4655 /* The symbols added to the mock mapped_index for testing (in
4657 static const char *test_symbols
[] = {
4666 "ns2::tmpl<int>::foo2",
4667 "(anonymous namespace)::A::B::C",
4669 /* These are used to check that the increment-last-char in the
4670 matching algorithm for completion doesn't match "t1_fund" when
4671 completing "t1_func". */
4677 /* A UTF-8 name with multi-byte sequences to make sure that
4678 cp-name-parser understands this as a single identifier ("função"
4679 is "function" in PT). */
4682 /* \377 (0xff) is Latin1 'ÿ'. */
4685 /* \377 (0xff) is Latin1 'ÿ'. */
4689 /* A name with all sorts of complications. Starts with "z" to make
4690 it easier for the completion tests below. */
4691 #define Z_SYM_NAME \
4692 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4693 "::tuple<(anonymous namespace)::ui*, " \
4694 "std::default_delete<(anonymous namespace)::ui>, void>"
4699 /* Returns true if the mapped_index_base::find_name_component_bounds
4700 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4701 in completion mode. */
4704 check_find_bounds_finds (mapped_index_base
&index
,
4705 const char *search_name
,
4706 gdb::array_view
<const char *> expected_syms
)
4708 lookup_name_info
lookup_name (search_name
,
4709 symbol_name_match_type::FULL
, true);
4711 auto bounds
= index
.find_name_components_bounds (lookup_name
);
4713 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4714 if (distance
!= expected_syms
.size ())
4717 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4719 auto nc_elem
= bounds
.first
+ exp_elem
;
4720 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4721 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4728 /* Test the lower-level mapped_index::find_name_component_bounds
4732 test_mapped_index_find_name_component_bounds ()
4734 mock_mapped_index
mock_index (test_symbols
);
4736 mock_index
.build_name_components ();
4738 /* Test the lower-level mapped_index::find_name_component_bounds
4739 method in completion mode. */
4741 static const char *expected_syms
[] = {
4746 SELF_CHECK (check_find_bounds_finds (mock_index
,
4747 "t1_func", expected_syms
));
4750 /* Check that the increment-last-char in the name matching algorithm
4751 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4753 static const char *expected_syms1
[] = {
4757 SELF_CHECK (check_find_bounds_finds (mock_index
,
4758 "\377", expected_syms1
));
4760 static const char *expected_syms2
[] = {
4763 SELF_CHECK (check_find_bounds_finds (mock_index
,
4764 "\377\377", expected_syms2
));
4768 /* Test dw2_expand_symtabs_matching_symbol. */
4771 test_dw2_expand_symtabs_matching_symbol ()
4773 mock_mapped_index
mock_index (test_symbols
);
4775 /* We let all tests run until the end even if some fails, for debug
4777 bool any_mismatch
= false;
4779 /* Create the expected symbols list (an initializer_list). Needed
4780 because lists have commas, and we need to pass them to CHECK,
4781 which is a macro. */
4782 #define EXPECT(...) { __VA_ARGS__ }
4784 /* Wrapper for check_match that passes down the current
4785 __FILE__/__LINE__. */
4786 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4787 any_mismatch |= !check_match (__FILE__, __LINE__, \
4789 NAME, MATCH_TYPE, COMPLETION_MODE, \
4792 /* Identity checks. */
4793 for (const char *sym
: test_symbols
)
4795 /* Should be able to match all existing symbols. */
4796 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4799 /* Should be able to match all existing symbols with
4801 std::string with_params
= std::string (sym
) + "(int)";
4802 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4805 /* Should be able to match all existing symbols with
4806 parameters and qualifiers. */
4807 with_params
= std::string (sym
) + " ( int ) const";
4808 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4811 /* This should really find sym, but cp-name-parser.y doesn't
4812 know about lvalue/rvalue qualifiers yet. */
4813 with_params
= std::string (sym
) + " ( int ) &&";
4814 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4818 /* Check that the name matching algorithm for completion doesn't get
4819 confused with Latin1 'ÿ' / 0xff. */
4821 static const char str
[] = "\377";
4822 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4823 EXPECT ("\377", "\377\377123"));
4826 /* Check that the increment-last-char in the matching algorithm for
4827 completion doesn't match "t1_fund" when completing "t1_func". */
4829 static const char str
[] = "t1_func";
4830 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4831 EXPECT ("t1_func", "t1_func1"));
4834 /* Check that completion mode works at each prefix of the expected
4837 static const char str
[] = "function(int)";
4838 size_t len
= strlen (str
);
4841 for (size_t i
= 1; i
< len
; i
++)
4843 lookup
.assign (str
, i
);
4844 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4845 EXPECT ("function"));
4849 /* While "w" is a prefix of both components, the match function
4850 should still only be called once. */
4852 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4854 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4858 /* Same, with a "complicated" symbol. */
4860 static const char str
[] = Z_SYM_NAME
;
4861 size_t len
= strlen (str
);
4864 for (size_t i
= 1; i
< len
; i
++)
4866 lookup
.assign (str
, i
);
4867 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4868 EXPECT (Z_SYM_NAME
));
4872 /* In FULL mode, an incomplete symbol doesn't match. */
4874 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4878 /* A complete symbol with parameters matches any overload, since the
4879 index has no overload info. */
4881 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4882 EXPECT ("std::zfunction", "std::zfunction2"));
4883 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4884 EXPECT ("std::zfunction", "std::zfunction2"));
4885 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4886 EXPECT ("std::zfunction", "std::zfunction2"));
4889 /* Check that whitespace is ignored appropriately. A symbol with a
4890 template argument list. */
4892 static const char expected
[] = "ns::foo<int>";
4893 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4895 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4899 /* Check that whitespace is ignored appropriately. A symbol with a
4900 template argument list that includes a pointer. */
4902 static const char expected
[] = "ns::foo<char*>";
4903 /* Try both completion and non-completion modes. */
4904 static const bool completion_mode
[2] = {false, true};
4905 for (size_t i
= 0; i
< 2; i
++)
4907 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4908 completion_mode
[i
], EXPECT (expected
));
4909 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4910 completion_mode
[i
], EXPECT (expected
));
4912 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4913 completion_mode
[i
], EXPECT (expected
));
4914 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4915 completion_mode
[i
], EXPECT (expected
));
4920 /* Check method qualifiers are ignored. */
4921 static const char expected
[] = "ns::foo<char*>";
4922 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4923 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4924 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4925 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4926 CHECK_MATCH ("foo < char * > ( int ) const",
4927 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4928 CHECK_MATCH ("foo < char * > ( int ) &&",
4929 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4932 /* Test lookup names that don't match anything. */
4934 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4937 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4941 /* Some wild matching tests, exercising "(anonymous namespace)",
4942 which should not be confused with a parameter list. */
4944 static const char *syms
[] = {
4948 "A :: B :: C ( int )",
4953 for (const char *s
: syms
)
4955 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4956 EXPECT ("(anonymous namespace)::A::B::C"));
4961 static const char expected
[] = "ns2::tmpl<int>::foo2";
4962 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4964 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4968 SELF_CHECK (!any_mismatch
);
4977 test_mapped_index_find_name_component_bounds ();
4978 test_dw2_expand_symtabs_matching_symbol ();
4981 }} // namespace selftests::dw2_expand_symtabs_matching
4983 #endif /* GDB_SELF_TEST */
4985 /* If FILE_MATCHER is NULL or if PER_CU has
4986 dwarf2_per_cu_quick_data::MARK set (see
4987 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4988 EXPANSION_NOTIFY on it. */
4991 dw2_expand_symtabs_matching_one
4992 (struct dwarf2_per_cu_data
*per_cu
,
4993 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4994 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4996 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4998 bool symtab_was_null
4999 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
5001 dw2_instantiate_symtab (per_cu
, false);
5003 if (expansion_notify
!= NULL
5005 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
5006 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
5010 /* Helper for dw2_expand_matching symtabs. Called on each symbol
5011 matched, to expand corresponding CUs that were marked. IDX is the
5012 index of the symbol name that matched. */
5015 dw2_expand_marked_cus
5016 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
5017 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5018 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5021 offset_type
*vec
, vec_len
, vec_idx
;
5022 bool global_seen
= false;
5023 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5025 vec
= (offset_type
*) (index
.constant_pool
5026 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
5027 vec_len
= MAYBE_SWAP (vec
[0]);
5028 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
5030 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
5031 /* This value is only valid for index versions >= 7. */
5032 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
5033 gdb_index_symbol_kind symbol_kind
=
5034 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
5035 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
5036 /* Only check the symbol attributes if they're present.
5037 Indices prior to version 7 don't record them,
5038 and indices >= 7 may elide them for certain symbols
5039 (gold does this). */
5042 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
5044 /* Work around gold/15646. */
5047 if (!is_static
&& global_seen
)
5053 /* Only check the symbol's kind if it has one. */
5058 case VARIABLES_DOMAIN
:
5059 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
5062 case FUNCTIONS_DOMAIN
:
5063 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
5067 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
5075 /* Don't crash on bad data. */
5076 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
5077 + dwarf2_per_objfile
->all_type_units
.size ()))
5079 complaint (&symfile_complaints
,
5080 _(".gdb_index entry has bad CU index"
5082 objfile_name (dwarf2_per_objfile
->objfile
));
5086 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
5087 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5092 /* If FILE_MATCHER is non-NULL, set all the
5093 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
5094 that match FILE_MATCHER. */
5097 dw_expand_symtabs_matching_file_matcher
5098 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5099 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
5101 if (file_matcher
== NULL
)
5104 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
5106 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
5108 NULL
, xcalloc
, xfree
));
5109 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
5111 NULL
, xcalloc
, xfree
));
5113 /* The rule is CUs specify all the files, including those used by
5114 any TU, so there's no need to scan TUs here. */
5116 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5120 per_cu
->v
.quick
->mark
= 0;
5122 /* We only need to look at symtabs not already expanded. */
5123 if (per_cu
->v
.quick
->compunit_symtab
)
5126 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5127 if (file_data
== NULL
)
5130 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
5132 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
5134 per_cu
->v
.quick
->mark
= 1;
5138 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5140 const char *this_real_name
;
5142 if (file_matcher (file_data
->file_names
[j
], false))
5144 per_cu
->v
.quick
->mark
= 1;
5148 /* Before we invoke realpath, which can get expensive when many
5149 files are involved, do a quick comparison of the basenames. */
5150 if (!basenames_may_differ
5151 && !file_matcher (lbasename (file_data
->file_names
[j
]),
5155 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
5156 if (file_matcher (this_real_name
, false))
5158 per_cu
->v
.quick
->mark
= 1;
5163 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
5164 ? visited_found
.get ()
5165 : visited_not_found
.get (),
5172 dw2_expand_symtabs_matching
5173 (struct objfile
*objfile
,
5174 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5175 const lookup_name_info
&lookup_name
,
5176 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5177 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5178 enum search_domain kind
)
5180 struct dwarf2_per_objfile
*dwarf2_per_objfile
5181 = get_dwarf2_per_objfile (objfile
);
5183 /* index_table is NULL if OBJF_READNOW. */
5184 if (!dwarf2_per_objfile
->index_table
)
5187 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5189 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5191 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
5193 kind
, [&] (offset_type idx
)
5195 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
5196 expansion_notify
, kind
);
5200 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
5203 static struct compunit_symtab
*
5204 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
5209 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
5210 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
5213 if (cust
->includes
== NULL
)
5216 for (i
= 0; cust
->includes
[i
]; ++i
)
5218 struct compunit_symtab
*s
= cust
->includes
[i
];
5220 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
5228 static struct compunit_symtab
*
5229 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
5230 struct bound_minimal_symbol msymbol
,
5232 struct obj_section
*section
,
5235 struct dwarf2_per_cu_data
*data
;
5236 struct compunit_symtab
*result
;
5238 if (!objfile
->psymtabs_addrmap
)
5241 data
= (struct dwarf2_per_cu_data
*) addrmap_find (objfile
->psymtabs_addrmap
,
5246 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
5247 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
5248 paddress (get_objfile_arch (objfile
), pc
));
5251 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
5254 gdb_assert (result
!= NULL
);
5259 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
5260 void *data
, int need_fullname
)
5262 struct dwarf2_per_objfile
*dwarf2_per_objfile
5263 = get_dwarf2_per_objfile (objfile
);
5265 if (!dwarf2_per_objfile
->filenames_cache
)
5267 dwarf2_per_objfile
->filenames_cache
.emplace ();
5269 htab_up
visited (htab_create_alloc (10,
5270 htab_hash_pointer
, htab_eq_pointer
,
5271 NULL
, xcalloc
, xfree
));
5273 /* The rule is CUs specify all the files, including those used
5274 by any TU, so there's no need to scan TUs here. We can
5275 ignore file names coming from already-expanded CUs. */
5277 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5279 if (per_cu
->v
.quick
->compunit_symtab
)
5281 void **slot
= htab_find_slot (visited
.get (),
5282 per_cu
->v
.quick
->file_names
,
5285 *slot
= per_cu
->v
.quick
->file_names
;
5289 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5291 /* We only need to look at symtabs not already expanded. */
5292 if (per_cu
->v
.quick
->compunit_symtab
)
5295 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5296 if (file_data
== NULL
)
5299 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
5302 /* Already visited. */
5307 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5309 const char *filename
= file_data
->file_names
[j
];
5310 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
5315 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
5317 gdb::unique_xmalloc_ptr
<char> this_real_name
;
5320 this_real_name
= gdb_realpath (filename
);
5321 (*fun
) (filename
, this_real_name
.get (), data
);
5326 dw2_has_symbols (struct objfile
*objfile
)
5331 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
5334 dw2_find_last_source_symtab
,
5335 dw2_forget_cached_source_info
,
5336 dw2_map_symtabs_matching_filename
,
5341 dw2_expand_symtabs_for_function
,
5342 dw2_expand_all_symtabs
,
5343 dw2_expand_symtabs_with_fullname
,
5344 dw2_map_matching_symbols
,
5345 dw2_expand_symtabs_matching
,
5346 dw2_find_pc_sect_compunit_symtab
,
5348 dw2_map_symbol_filenames
5351 /* DWARF-5 debug_names reader. */
5353 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
5354 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
5356 /* A helper function that reads the .debug_names section in SECTION
5357 and fills in MAP. FILENAME is the name of the file containing the
5358 section; it is used for error reporting.
5360 Returns true if all went well, false otherwise. */
5363 read_debug_names_from_section (struct objfile
*objfile
,
5364 const char *filename
,
5365 struct dwarf2_section_info
*section
,
5366 mapped_debug_names
&map
)
5368 if (dwarf2_section_empty_p (section
))
5371 /* Older elfutils strip versions could keep the section in the main
5372 executable while splitting it for the separate debug info file. */
5373 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
5376 dwarf2_read_section (objfile
, section
);
5378 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
5380 const gdb_byte
*addr
= section
->buffer
;
5382 bfd
*const abfd
= get_section_bfd_owner (section
);
5384 unsigned int bytes_read
;
5385 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5388 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5389 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5390 if (bytes_read
+ length
!= section
->size
)
5392 /* There may be multiple per-CU indices. */
5393 warning (_("Section .debug_names in %s length %s does not match "
5394 "section length %s, ignoring .debug_names."),
5395 filename
, plongest (bytes_read
+ length
),
5396 pulongest (section
->size
));
5400 /* The version number. */
5401 uint16_t version
= read_2_bytes (abfd
, addr
);
5405 warning (_("Section .debug_names in %s has unsupported version %d, "
5406 "ignoring .debug_names."),
5412 uint16_t padding
= read_2_bytes (abfd
, addr
);
5416 warning (_("Section .debug_names in %s has unsupported padding %d, "
5417 "ignoring .debug_names."),
5422 /* comp_unit_count - The number of CUs in the CU list. */
5423 map
.cu_count
= read_4_bytes (abfd
, addr
);
5426 /* local_type_unit_count - The number of TUs in the local TU
5428 map
.tu_count
= read_4_bytes (abfd
, addr
);
5431 /* foreign_type_unit_count - The number of TUs in the foreign TU
5433 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5435 if (foreign_tu_count
!= 0)
5437 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5438 "ignoring .debug_names."),
5439 filename
, static_cast<unsigned long> (foreign_tu_count
));
5443 /* bucket_count - The number of hash buckets in the hash lookup
5445 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5448 /* name_count - The number of unique names in the index. */
5449 map
.name_count
= read_4_bytes (abfd
, addr
);
5452 /* abbrev_table_size - The size in bytes of the abbreviations
5454 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5457 /* augmentation_string_size - The size in bytes of the augmentation
5458 string. This value is rounded up to a multiple of 4. */
5459 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5461 map
.augmentation_is_gdb
= ((augmentation_string_size
5462 == sizeof (dwarf5_augmentation
))
5463 && memcmp (addr
, dwarf5_augmentation
,
5464 sizeof (dwarf5_augmentation
)) == 0);
5465 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5466 addr
+= augmentation_string_size
;
5469 map
.cu_table_reordered
= addr
;
5470 addr
+= map
.cu_count
* map
.offset_size
;
5472 /* List of Local TUs */
5473 map
.tu_table_reordered
= addr
;
5474 addr
+= map
.tu_count
* map
.offset_size
;
5476 /* Hash Lookup Table */
5477 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5478 addr
+= map
.bucket_count
* 4;
5479 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5480 addr
+= map
.name_count
* 4;
5483 map
.name_table_string_offs_reordered
= addr
;
5484 addr
+= map
.name_count
* map
.offset_size
;
5485 map
.name_table_entry_offs_reordered
= addr
;
5486 addr
+= map
.name_count
* map
.offset_size
;
5488 const gdb_byte
*abbrev_table_start
= addr
;
5491 unsigned int bytes_read
;
5492 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5497 const auto insertpair
5498 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5499 if (!insertpair
.second
)
5501 warning (_("Section .debug_names in %s has duplicate index %s, "
5502 "ignoring .debug_names."),
5503 filename
, pulongest (index_num
));
5506 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5507 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5512 mapped_debug_names::index_val::attr attr
;
5513 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5515 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5517 if (attr
.form
== DW_FORM_implicit_const
)
5519 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5523 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5525 indexval
.attr_vec
.push_back (std::move (attr
));
5528 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5530 warning (_("Section .debug_names in %s has abbreviation_table "
5531 "of size %zu vs. written as %u, ignoring .debug_names."),
5532 filename
, addr
- abbrev_table_start
, abbrev_table_size
);
5535 map
.entry_pool
= addr
;
5540 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5544 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5545 const mapped_debug_names
&map
,
5546 dwarf2_section_info
§ion
,
5549 sect_offset sect_off_prev
;
5550 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5552 sect_offset sect_off_next
;
5553 if (i
< map
.cu_count
)
5556 = (sect_offset
) (extract_unsigned_integer
5557 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5559 map
.dwarf5_byte_order
));
5562 sect_off_next
= (sect_offset
) section
.size
;
5565 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5566 dwarf2_per_cu_data
*per_cu
5567 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5568 sect_off_prev
, length
);
5569 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5571 sect_off_prev
= sect_off_next
;
5575 /* Read the CU list from the mapped index, and use it to create all
5576 the CU objects for this dwarf2_per_objfile. */
5579 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5580 const mapped_debug_names
&map
,
5581 const mapped_debug_names
&dwz_map
)
5583 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
5584 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5586 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5587 dwarf2_per_objfile
->info
,
5588 false /* is_dwz */);
5590 if (dwz_map
.cu_count
== 0)
5593 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5594 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5598 /* Read .debug_names. If everything went ok, initialize the "quick"
5599 elements of all the CUs and return true. Otherwise, return false. */
5602 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5604 mapped_debug_names
local_map (dwarf2_per_objfile
);
5605 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5606 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5608 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5609 &dwarf2_per_objfile
->debug_names
,
5613 /* Don't use the index if it's empty. */
5614 if (local_map
.name_count
== 0)
5617 /* If there is a .dwz file, read it so we can get its CU list as
5619 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5622 if (!read_debug_names_from_section (objfile
,
5623 bfd_get_filename (dwz
->dwz_bfd
),
5624 &dwz
->debug_names
, dwz_map
))
5626 warning (_("could not read '.debug_names' section from %s; skipping"),
5627 bfd_get_filename (dwz
->dwz_bfd
));
5632 create_cus_from_debug_names (dwarf2_per_objfile
, local_map
, dwz_map
);
5634 if (local_map
.tu_count
!= 0)
5636 /* We can only handle a single .debug_types when we have an
5638 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
5641 dwarf2_section_info
*section
= VEC_index (dwarf2_section_info_def
,
5642 dwarf2_per_objfile
->types
, 0);
5644 create_signatured_type_table_from_debug_names
5645 (dwarf2_per_objfile
, local_map
, section
, &dwarf2_per_objfile
->abbrev
);
5648 create_addrmap_from_aranges (dwarf2_per_objfile
,
5649 &dwarf2_per_objfile
->debug_aranges
);
5651 dwarf2_per_objfile
->debug_names_table
.reset
5652 (new mapped_debug_names (dwarf2_per_objfile
));
5653 *dwarf2_per_objfile
->debug_names_table
= std::move (local_map
);
5654 dwarf2_per_objfile
->using_index
= 1;
5655 dwarf2_per_objfile
->quick_file_names_table
=
5656 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5661 /* Type used to manage iterating over all CUs looking for a symbol for
5664 class dw2_debug_names_iterator
5667 /* If WANT_SPECIFIC_BLOCK is true, only look for symbols in block
5668 BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
5669 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5670 bool want_specific_block
,
5671 block_enum block_index
, domain_enum domain
,
5673 : m_map (map
), m_want_specific_block (want_specific_block
),
5674 m_block_index (block_index
), m_domain (domain
),
5675 m_addr (find_vec_in_debug_names (map
, name
))
5678 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5679 search_domain search
, uint32_t namei
)
5682 m_addr (find_vec_in_debug_names (map
, namei
))
5685 /* Return the next matching CU or NULL if there are no more. */
5686 dwarf2_per_cu_data
*next ();
5689 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5691 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5694 /* The internalized form of .debug_names. */
5695 const mapped_debug_names
&m_map
;
5697 /* If true, only look for symbols that match BLOCK_INDEX. */
5698 const bool m_want_specific_block
= false;
5700 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
5701 Unused if !WANT_SPECIFIC_BLOCK - FIRST_LOCAL_BLOCK is an invalid
5703 const block_enum m_block_index
= FIRST_LOCAL_BLOCK
;
5705 /* The kind of symbol we're looking for. */
5706 const domain_enum m_domain
= UNDEF_DOMAIN
;
5707 const search_domain m_search
= ALL_DOMAIN
;
5709 /* The list of CUs from the index entry of the symbol, or NULL if
5711 const gdb_byte
*m_addr
;
5715 mapped_debug_names::namei_to_name (uint32_t namei
) const
5717 const ULONGEST namei_string_offs
5718 = extract_unsigned_integer ((name_table_string_offs_reordered
5719 + namei
* offset_size
),
5722 return read_indirect_string_at_offset
5723 (dwarf2_per_objfile
, dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
5726 /* Find a slot in .debug_names for the object named NAME. If NAME is
5727 found, return pointer to its pool data. If NAME cannot be found,
5731 dw2_debug_names_iterator::find_vec_in_debug_names
5732 (const mapped_debug_names
&map
, const char *name
)
5734 int (*cmp
) (const char *, const char *);
5736 if (current_language
->la_language
== language_cplus
5737 || current_language
->la_language
== language_fortran
5738 || current_language
->la_language
== language_d
)
5740 /* NAME is already canonical. Drop any qualifiers as
5741 .debug_names does not contain any. */
5743 if (strchr (name
, '(') != NULL
)
5745 gdb::unique_xmalloc_ptr
<char> without_params
5746 = cp_remove_params (name
);
5748 if (without_params
!= NULL
)
5750 name
= without_params
.get();
5755 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5757 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5759 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5760 (map
.bucket_table_reordered
5761 + (full_hash
% map
.bucket_count
)), 4,
5762 map
.dwarf5_byte_order
);
5766 if (namei
>= map
.name_count
)
5768 complaint (&symfile_complaints
,
5769 _("Wrong .debug_names with name index %u but name_count=%u "
5771 namei
, map
.name_count
,
5772 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5778 const uint32_t namei_full_hash
5779 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5780 (map
.hash_table_reordered
+ namei
), 4,
5781 map
.dwarf5_byte_order
);
5782 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5785 if (full_hash
== namei_full_hash
)
5787 const char *const namei_string
= map
.namei_to_name (namei
);
5789 #if 0 /* An expensive sanity check. */
5790 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5792 complaint (&symfile_complaints
,
5793 _("Wrong .debug_names hash for string at index %u "
5795 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5800 if (cmp (namei_string
, name
) == 0)
5802 const ULONGEST namei_entry_offs
5803 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5804 + namei
* map
.offset_size
),
5805 map
.offset_size
, map
.dwarf5_byte_order
);
5806 return map
.entry_pool
+ namei_entry_offs
;
5811 if (namei
>= map
.name_count
)
5817 dw2_debug_names_iterator::find_vec_in_debug_names
5818 (const mapped_debug_names
&map
, uint32_t namei
)
5820 if (namei
>= map
.name_count
)
5822 complaint (&symfile_complaints
,
5823 _("Wrong .debug_names with name index %u but name_count=%u "
5825 namei
, map
.name_count
,
5826 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5830 const ULONGEST namei_entry_offs
5831 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5832 + namei
* map
.offset_size
),
5833 map
.offset_size
, map
.dwarf5_byte_order
);
5834 return map
.entry_pool
+ namei_entry_offs
;
5837 /* See dw2_debug_names_iterator. */
5839 dwarf2_per_cu_data
*
5840 dw2_debug_names_iterator::next ()
5845 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5846 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5847 bfd
*const abfd
= objfile
->obfd
;
5851 unsigned int bytes_read
;
5852 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5853 m_addr
+= bytes_read
;
5857 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5858 if (indexval_it
== m_map
.abbrev_map
.cend ())
5860 complaint (&symfile_complaints
,
5861 _("Wrong .debug_names undefined abbrev code %s "
5863 pulongest (abbrev
), objfile_name (objfile
));
5866 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5867 bool have_is_static
= false;
5869 dwarf2_per_cu_data
*per_cu
= NULL
;
5870 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5875 case DW_FORM_implicit_const
:
5876 ull
= attr
.implicit_const
;
5878 case DW_FORM_flag_present
:
5882 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5883 m_addr
+= bytes_read
;
5886 complaint (&symfile_complaints
,
5887 _("Unsupported .debug_names form %s [in module %s]"),
5888 dwarf_form_name (attr
.form
),
5889 objfile_name (objfile
));
5892 switch (attr
.dw_idx
)
5894 case DW_IDX_compile_unit
:
5895 /* Don't crash on bad data. */
5896 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5898 complaint (&symfile_complaints
,
5899 _(".debug_names entry has bad CU index %s"
5902 objfile_name (dwarf2_per_objfile
->objfile
));
5905 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5907 case DW_IDX_type_unit
:
5908 /* Don't crash on bad data. */
5909 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5911 complaint (&symfile_complaints
,
5912 _(".debug_names entry has bad TU index %s"
5915 objfile_name (dwarf2_per_objfile
->objfile
));
5918 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5920 case DW_IDX_GNU_internal
:
5921 if (!m_map
.augmentation_is_gdb
)
5923 have_is_static
= true;
5926 case DW_IDX_GNU_external
:
5927 if (!m_map
.augmentation_is_gdb
)
5929 have_is_static
= true;
5935 /* Skip if already read in. */
5936 if (per_cu
->v
.quick
->compunit_symtab
)
5939 /* Check static vs global. */
5942 const bool want_static
= m_block_index
!= GLOBAL_BLOCK
;
5943 if (m_want_specific_block
&& want_static
!= is_static
)
5947 /* Match dw2_symtab_iter_next, symbol_kind
5948 and debug_names::psymbol_tag. */
5952 switch (indexval
.dwarf_tag
)
5954 case DW_TAG_variable
:
5955 case DW_TAG_subprogram
:
5956 /* Some types are also in VAR_DOMAIN. */
5957 case DW_TAG_typedef
:
5958 case DW_TAG_structure_type
:
5965 switch (indexval
.dwarf_tag
)
5967 case DW_TAG_typedef
:
5968 case DW_TAG_structure_type
:
5975 switch (indexval
.dwarf_tag
)
5978 case DW_TAG_variable
:
5988 /* Match dw2_expand_symtabs_matching, symbol_kind and
5989 debug_names::psymbol_tag. */
5992 case VARIABLES_DOMAIN
:
5993 switch (indexval
.dwarf_tag
)
5995 case DW_TAG_variable
:
6001 case FUNCTIONS_DOMAIN
:
6002 switch (indexval
.dwarf_tag
)
6004 case DW_TAG_subprogram
:
6011 switch (indexval
.dwarf_tag
)
6013 case DW_TAG_typedef
:
6014 case DW_TAG_structure_type
:
6027 static struct compunit_symtab
*
6028 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, int block_index_int
,
6029 const char *name
, domain_enum domain
)
6031 const block_enum block_index
= static_cast<block_enum
> (block_index_int
);
6032 struct dwarf2_per_objfile
*dwarf2_per_objfile
6033 = get_dwarf2_per_objfile (objfile
);
6035 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
6038 /* index is NULL if OBJF_READNOW. */
6041 const auto &map
= *mapp
;
6043 dw2_debug_names_iterator
iter (map
, true /* want_specific_block */,
6044 block_index
, domain
, name
);
6046 struct compunit_symtab
*stab_best
= NULL
;
6047 struct dwarf2_per_cu_data
*per_cu
;
6048 while ((per_cu
= iter
.next ()) != NULL
)
6050 struct symbol
*sym
, *with_opaque
= NULL
;
6051 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
6052 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
6053 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
6055 sym
= block_find_symbol (block
, name
, domain
,
6056 block_find_non_opaque_type_preferred
,
6059 /* Some caution must be observed with overloaded functions and
6060 methods, since the index will not contain any overload
6061 information (but NAME might contain it). */
6064 && strcmp_iw (SYMBOL_SEARCH_NAME (sym
), name
) == 0)
6066 if (with_opaque
!= NULL
6067 && strcmp_iw (SYMBOL_SEARCH_NAME (with_opaque
), name
) == 0)
6070 /* Keep looking through other CUs. */
6076 /* This dumps minimal information about .debug_names. It is called
6077 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
6078 uses this to verify that .debug_names has been loaded. */
6081 dw2_debug_names_dump (struct objfile
*objfile
)
6083 struct dwarf2_per_objfile
*dwarf2_per_objfile
6084 = get_dwarf2_per_objfile (objfile
);
6086 gdb_assert (dwarf2_per_objfile
->using_index
);
6087 printf_filtered (".debug_names:");
6088 if (dwarf2_per_objfile
->debug_names_table
)
6089 printf_filtered (" exists\n");
6091 printf_filtered (" faked for \"readnow\"\n");
6092 printf_filtered ("\n");
6096 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
6097 const char *func_name
)
6099 struct dwarf2_per_objfile
*dwarf2_per_objfile
6100 = get_dwarf2_per_objfile (objfile
);
6102 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
6103 if (dwarf2_per_objfile
->debug_names_table
)
6105 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6107 /* Note: It doesn't matter what we pass for block_index here. */
6108 dw2_debug_names_iterator
iter (map
, false /* want_specific_block */,
6109 GLOBAL_BLOCK
, VAR_DOMAIN
, func_name
);
6111 struct dwarf2_per_cu_data
*per_cu
;
6112 while ((per_cu
= iter
.next ()) != NULL
)
6113 dw2_instantiate_symtab (per_cu
, false);
6118 dw2_debug_names_expand_symtabs_matching
6119 (struct objfile
*objfile
,
6120 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
6121 const lookup_name_info
&lookup_name
,
6122 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
6123 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
6124 enum search_domain kind
)
6126 struct dwarf2_per_objfile
*dwarf2_per_objfile
6127 = get_dwarf2_per_objfile (objfile
);
6129 /* debug_names_table is NULL if OBJF_READNOW. */
6130 if (!dwarf2_per_objfile
->debug_names_table
)
6133 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
6135 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6137 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
6139 kind
, [&] (offset_type namei
)
6141 /* The name was matched, now expand corresponding CUs that were
6143 dw2_debug_names_iterator
iter (map
, kind
, namei
);
6145 struct dwarf2_per_cu_data
*per_cu
;
6146 while ((per_cu
= iter
.next ()) != NULL
)
6147 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
6152 const struct quick_symbol_functions dwarf2_debug_names_functions
=
6155 dw2_find_last_source_symtab
,
6156 dw2_forget_cached_source_info
,
6157 dw2_map_symtabs_matching_filename
,
6158 dw2_debug_names_lookup_symbol
,
6160 dw2_debug_names_dump
,
6162 dw2_debug_names_expand_symtabs_for_function
,
6163 dw2_expand_all_symtabs
,
6164 dw2_expand_symtabs_with_fullname
,
6165 dw2_map_matching_symbols
,
6166 dw2_debug_names_expand_symtabs_matching
,
6167 dw2_find_pc_sect_compunit_symtab
,
6169 dw2_map_symbol_filenames
6172 /* See symfile.h. */
6175 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
6177 struct dwarf2_per_objfile
*dwarf2_per_objfile
6178 = get_dwarf2_per_objfile (objfile
);
6180 /* If we're about to read full symbols, don't bother with the
6181 indices. In this case we also don't care if some other debug
6182 format is making psymtabs, because they are all about to be
6184 if ((objfile
->flags
& OBJF_READNOW
))
6186 dwarf2_per_objfile
->using_index
= 1;
6187 create_all_comp_units (dwarf2_per_objfile
);
6188 create_all_type_units (dwarf2_per_objfile
);
6189 dwarf2_per_objfile
->quick_file_names_table
6190 = create_quick_file_names_table
6191 (dwarf2_per_objfile
->all_comp_units
.size ());
6193 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
6194 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
6196 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
6198 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6199 struct dwarf2_per_cu_quick_data
);
6202 /* Return 1 so that gdb sees the "quick" functions. However,
6203 these functions will be no-ops because we will have expanded
6205 *index_kind
= dw_index_kind::GDB_INDEX
;
6209 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
6211 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6215 if (dwarf2_read_index (dwarf2_per_objfile
))
6217 *index_kind
= dw_index_kind::GDB_INDEX
;
6226 /* Build a partial symbol table. */
6229 dwarf2_build_psymtabs (struct objfile
*objfile
)
6231 struct dwarf2_per_objfile
*dwarf2_per_objfile
6232 = get_dwarf2_per_objfile (objfile
);
6234 if (objfile
->global_psymbols
.capacity () == 0
6235 && objfile
->static_psymbols
.capacity () == 0)
6236 init_psymbol_list (objfile
, 1024);
6240 /* This isn't really ideal: all the data we allocate on the
6241 objfile's obstack is still uselessly kept around. However,
6242 freeing it seems unsafe. */
6243 psymtab_discarder
psymtabs (objfile
);
6244 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
6247 CATCH (except
, RETURN_MASK_ERROR
)
6249 exception_print (gdb_stderr
, except
);
6254 /* Return the total length of the CU described by HEADER. */
6257 get_cu_length (const struct comp_unit_head
*header
)
6259 return header
->initial_length_size
+ header
->length
;
6262 /* Return TRUE if SECT_OFF is within CU_HEADER. */
6265 offset_in_cu_p (const comp_unit_head
*cu_header
, sect_offset sect_off
)
6267 sect_offset bottom
= cu_header
->sect_off
;
6268 sect_offset top
= cu_header
->sect_off
+ get_cu_length (cu_header
);
6270 return sect_off
>= bottom
&& sect_off
< top
;
6273 /* Find the base address of the compilation unit for range lists and
6274 location lists. It will normally be specified by DW_AT_low_pc.
6275 In DWARF-3 draft 4, the base address could be overridden by
6276 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6277 compilation units with discontinuous ranges. */
6280 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6282 struct attribute
*attr
;
6285 cu
->base_address
= 0;
6287 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6290 cu
->base_address
= attr_value_as_address (attr
);
6295 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6298 cu
->base_address
= attr_value_as_address (attr
);
6304 /* Read in the comp unit header information from the debug_info at info_ptr.
6305 Use rcuh_kind::COMPILE as the default type if not known by the caller.
6306 NOTE: This leaves members offset, first_die_offset to be filled in
6309 static const gdb_byte
*
6310 read_comp_unit_head (struct comp_unit_head
*cu_header
,
6311 const gdb_byte
*info_ptr
,
6312 struct dwarf2_section_info
*section
,
6313 rcuh_kind section_kind
)
6316 unsigned int bytes_read
;
6317 const char *filename
= get_section_file_name (section
);
6318 bfd
*abfd
= get_section_bfd_owner (section
);
6320 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
6321 cu_header
->initial_length_size
= bytes_read
;
6322 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
6323 info_ptr
+= bytes_read
;
6324 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
6326 if (cu_header
->version
< 5)
6327 switch (section_kind
)
6329 case rcuh_kind::COMPILE
:
6330 cu_header
->unit_type
= DW_UT_compile
;
6332 case rcuh_kind::TYPE
:
6333 cu_header
->unit_type
= DW_UT_type
;
6336 internal_error (__FILE__
, __LINE__
,
6337 _("read_comp_unit_head: invalid section_kind"));
6341 cu_header
->unit_type
= static_cast<enum dwarf_unit_type
>
6342 (read_1_byte (abfd
, info_ptr
));
6344 switch (cu_header
->unit_type
)
6347 if (section_kind
!= rcuh_kind::COMPILE
)
6348 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6349 "(is DW_UT_compile, should be DW_UT_type) [in module %s]"),
6353 section_kind
= rcuh_kind::TYPE
;
6356 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6357 "(is %d, should be %d or %d) [in module %s]"),
6358 cu_header
->unit_type
, DW_UT_compile
, DW_UT_type
, filename
);
6361 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6364 cu_header
->abbrev_sect_off
= (sect_offset
) read_offset (abfd
, info_ptr
,
6367 info_ptr
+= bytes_read
;
6368 if (cu_header
->version
< 5)
6370 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6373 signed_addr
= bfd_get_sign_extend_vma (abfd
);
6374 if (signed_addr
< 0)
6375 internal_error (__FILE__
, __LINE__
,
6376 _("read_comp_unit_head: dwarf from non elf file"));
6377 cu_header
->signed_addr_p
= signed_addr
;
6379 if (section_kind
== rcuh_kind::TYPE
)
6381 LONGEST type_offset
;
6383 cu_header
->signature
= read_8_bytes (abfd
, info_ptr
);
6386 type_offset
= read_offset (abfd
, info_ptr
, cu_header
, &bytes_read
);
6387 info_ptr
+= bytes_read
;
6388 cu_header
->type_cu_offset_in_tu
= (cu_offset
) type_offset
;
6389 if (to_underlying (cu_header
->type_cu_offset_in_tu
) != type_offset
)
6390 error (_("Dwarf Error: Too big type_offset in compilation unit "
6391 "header (is %s) [in module %s]"), plongest (type_offset
),
6398 /* Helper function that returns the proper abbrev section for
6401 static struct dwarf2_section_info
*
6402 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6404 struct dwarf2_section_info
*abbrev
;
6405 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6407 if (this_cu
->is_dwz
)
6408 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
6410 abbrev
= &dwarf2_per_objfile
->abbrev
;
6415 /* Subroutine of read_and_check_comp_unit_head and
6416 read_and_check_type_unit_head to simplify them.
6417 Perform various error checking on the header. */
6420 error_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6421 struct comp_unit_head
*header
,
6422 struct dwarf2_section_info
*section
,
6423 struct dwarf2_section_info
*abbrev_section
)
6425 const char *filename
= get_section_file_name (section
);
6427 if (header
->version
< 2 || header
->version
> 5)
6428 error (_("Dwarf Error: wrong version in compilation unit header "
6429 "(is %d, should be 2, 3, 4 or 5) [in module %s]"), header
->version
,
6432 if (to_underlying (header
->abbrev_sect_off
)
6433 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
6434 error (_("Dwarf Error: bad offset (%s) in compilation unit header "
6435 "(offset %s + 6) [in module %s]"),
6436 sect_offset_str (header
->abbrev_sect_off
),
6437 sect_offset_str (header
->sect_off
),
6440 /* Cast to ULONGEST to use 64-bit arithmetic when possible to
6441 avoid potential 32-bit overflow. */
6442 if (((ULONGEST
) header
->sect_off
+ get_cu_length (header
))
6444 error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
6445 "(offset %s + 0) [in module %s]"),
6446 header
->length
, sect_offset_str (header
->sect_off
),
6450 /* Read in a CU/TU header and perform some basic error checking.
6451 The contents of the header are stored in HEADER.
6452 The result is a pointer to the start of the first DIE. */
6454 static const gdb_byte
*
6455 read_and_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6456 struct comp_unit_head
*header
,
6457 struct dwarf2_section_info
*section
,
6458 struct dwarf2_section_info
*abbrev_section
,
6459 const gdb_byte
*info_ptr
,
6460 rcuh_kind section_kind
)
6462 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
6464 header
->sect_off
= (sect_offset
) (beg_of_comp_unit
- section
->buffer
);
6466 info_ptr
= read_comp_unit_head (header
, info_ptr
, section
, section_kind
);
6468 header
->first_die_cu_offset
= (cu_offset
) (info_ptr
- beg_of_comp_unit
);
6470 error_check_comp_unit_head (dwarf2_per_objfile
, header
, section
,
6476 /* Fetch the abbreviation table offset from a comp or type unit header. */
6479 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6480 struct dwarf2_section_info
*section
,
6481 sect_offset sect_off
)
6483 bfd
*abfd
= get_section_bfd_owner (section
);
6484 const gdb_byte
*info_ptr
;
6485 unsigned int initial_length_size
, offset_size
;
6488 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
6489 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6490 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6491 offset_size
= initial_length_size
== 4 ? 4 : 8;
6492 info_ptr
+= initial_length_size
;
6494 version
= read_2_bytes (abfd
, info_ptr
);
6498 /* Skip unit type and address size. */
6502 return (sect_offset
) read_offset_1 (abfd
, info_ptr
, offset_size
);
6505 /* Allocate a new partial symtab for file named NAME and mark this new
6506 partial symtab as being an include of PST. */
6509 dwarf2_create_include_psymtab (const char *name
, struct partial_symtab
*pst
,
6510 struct objfile
*objfile
)
6512 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
6514 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6516 /* It shares objfile->objfile_obstack. */
6517 subpst
->dirname
= pst
->dirname
;
6520 subpst
->textlow
= 0;
6521 subpst
->texthigh
= 0;
6523 subpst
->dependencies
6524 = XOBNEW (&objfile
->objfile_obstack
, struct partial_symtab
*);
6525 subpst
->dependencies
[0] = pst
;
6526 subpst
->number_of_dependencies
= 1;
6528 subpst
->globals_offset
= 0;
6529 subpst
->n_global_syms
= 0;
6530 subpst
->statics_offset
= 0;
6531 subpst
->n_static_syms
= 0;
6532 subpst
->compunit_symtab
= NULL
;
6533 subpst
->read_symtab
= pst
->read_symtab
;
6536 /* No private part is necessary for include psymtabs. This property
6537 can be used to differentiate between such include psymtabs and
6538 the regular ones. */
6539 subpst
->read_symtab_private
= NULL
;
6542 /* Read the Line Number Program data and extract the list of files
6543 included by the source file represented by PST. Build an include
6544 partial symtab for each of these included files. */
6547 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6548 struct die_info
*die
,
6549 struct partial_symtab
*pst
)
6552 struct attribute
*attr
;
6554 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6556 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6558 return; /* No linetable, so no includes. */
6560 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
6561 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
, pst
->textlow
, 1);
6565 hash_signatured_type (const void *item
)
6567 const struct signatured_type
*sig_type
6568 = (const struct signatured_type
*) item
;
6570 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6571 return sig_type
->signature
;
6575 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6577 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6578 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6580 return lhs
->signature
== rhs
->signature
;
6583 /* Allocate a hash table for signatured types. */
6586 allocate_signatured_type_table (struct objfile
*objfile
)
6588 return htab_create_alloc_ex (41,
6589 hash_signatured_type
,
6592 &objfile
->objfile_obstack
,
6593 hashtab_obstack_allocate
,
6594 dummy_obstack_deallocate
);
6597 /* A helper function to add a signatured type CU to a table. */
6600 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6602 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6603 std::vector
<signatured_type
*> *all_type_units
6604 = (std::vector
<signatured_type
*> *) datum
;
6606 all_type_units
->push_back (sigt
);
6611 /* A helper for create_debug_types_hash_table. Read types from SECTION
6612 and fill them into TYPES_HTAB. It will process only type units,
6613 therefore DW_UT_type. */
6616 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6617 struct dwo_file
*dwo_file
,
6618 dwarf2_section_info
*section
, htab_t
&types_htab
,
6619 rcuh_kind section_kind
)
6621 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6622 struct dwarf2_section_info
*abbrev_section
;
6624 const gdb_byte
*info_ptr
, *end_ptr
;
6626 abbrev_section
= (dwo_file
!= NULL
6627 ? &dwo_file
->sections
.abbrev
6628 : &dwarf2_per_objfile
->abbrev
);
6630 if (dwarf_read_debug
)
6631 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6632 get_section_name (section
),
6633 get_section_file_name (abbrev_section
));
6635 dwarf2_read_section (objfile
, section
);
6636 info_ptr
= section
->buffer
;
6638 if (info_ptr
== NULL
)
6641 /* We can't set abfd until now because the section may be empty or
6642 not present, in which case the bfd is unknown. */
6643 abfd
= get_section_bfd_owner (section
);
6645 /* We don't use init_cutu_and_read_dies_simple, or some such, here
6646 because we don't need to read any dies: the signature is in the
6649 end_ptr
= info_ptr
+ section
->size
;
6650 while (info_ptr
< end_ptr
)
6652 struct signatured_type
*sig_type
;
6653 struct dwo_unit
*dwo_tu
;
6655 const gdb_byte
*ptr
= info_ptr
;
6656 struct comp_unit_head header
;
6657 unsigned int length
;
6659 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6661 /* Initialize it due to a false compiler warning. */
6662 header
.signature
= -1;
6663 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6665 /* We need to read the type's signature in order to build the hash
6666 table, but we don't need anything else just yet. */
6668 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6669 abbrev_section
, ptr
, section_kind
);
6671 length
= get_cu_length (&header
);
6673 /* Skip dummy type units. */
6674 if (ptr
>= info_ptr
+ length
6675 || peek_abbrev_code (abfd
, ptr
) == 0
6676 || header
.unit_type
!= DW_UT_type
)
6682 if (types_htab
== NULL
)
6685 types_htab
= allocate_dwo_unit_table (objfile
);
6687 types_htab
= allocate_signatured_type_table (objfile
);
6693 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6695 dwo_tu
->dwo_file
= dwo_file
;
6696 dwo_tu
->signature
= header
.signature
;
6697 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6698 dwo_tu
->section
= section
;
6699 dwo_tu
->sect_off
= sect_off
;
6700 dwo_tu
->length
= length
;
6704 /* N.B.: type_offset is not usable if this type uses a DWO file.
6705 The real type_offset is in the DWO file. */
6707 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6708 struct signatured_type
);
6709 sig_type
->signature
= header
.signature
;
6710 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6711 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6712 sig_type
->per_cu
.is_debug_types
= 1;
6713 sig_type
->per_cu
.section
= section
;
6714 sig_type
->per_cu
.sect_off
= sect_off
;
6715 sig_type
->per_cu
.length
= length
;
6718 slot
= htab_find_slot (types_htab
,
6719 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6721 gdb_assert (slot
!= NULL
);
6724 sect_offset dup_sect_off
;
6728 const struct dwo_unit
*dup_tu
6729 = (const struct dwo_unit
*) *slot
;
6731 dup_sect_off
= dup_tu
->sect_off
;
6735 const struct signatured_type
*dup_tu
6736 = (const struct signatured_type
*) *slot
;
6738 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6741 complaint (&symfile_complaints
,
6742 _("debug type entry at offset %s is duplicate to"
6743 " the entry at offset %s, signature %s"),
6744 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6745 hex_string (header
.signature
));
6747 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6749 if (dwarf_read_debug
> 1)
6750 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6751 sect_offset_str (sect_off
),
6752 hex_string (header
.signature
));
6758 /* Create the hash table of all entries in the .debug_types
6759 (or .debug_types.dwo) section(s).
6760 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6761 otherwise it is NULL.
6763 The result is a pointer to the hash table or NULL if there are no types.
6765 Note: This function processes DWO files only, not DWP files. */
6768 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6769 struct dwo_file
*dwo_file
,
6770 VEC (dwarf2_section_info_def
) *types
,
6774 struct dwarf2_section_info
*section
;
6776 if (VEC_empty (dwarf2_section_info_def
, types
))
6780 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
6782 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, section
,
6783 types_htab
, rcuh_kind::TYPE
);
6786 /* Create the hash table of all entries in the .debug_types section,
6787 and initialize all_type_units.
6788 The result is zero if there is an error (e.g. missing .debug_types section),
6789 otherwise non-zero. */
6792 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6794 htab_t types_htab
= NULL
;
6796 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6797 &dwarf2_per_objfile
->info
, types_htab
,
6798 rcuh_kind::COMPILE
);
6799 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6800 dwarf2_per_objfile
->types
, types_htab
);
6801 if (types_htab
== NULL
)
6803 dwarf2_per_objfile
->signatured_types
= NULL
;
6807 dwarf2_per_objfile
->signatured_types
= types_htab
;
6809 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6810 dwarf2_per_objfile
->all_type_units
.reserve (htab_elements (types_htab
));
6812 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
,
6813 &dwarf2_per_objfile
->all_type_units
);
6818 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6819 If SLOT is non-NULL, it is the entry to use in the hash table.
6820 Otherwise we find one. */
6822 static struct signatured_type
*
6823 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6826 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6828 if (dwarf2_per_objfile
->all_type_units
.size ()
6829 == dwarf2_per_objfile
->all_type_units
.capacity ())
6830 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6832 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6833 struct signatured_type
);
6835 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6836 sig_type
->signature
= sig
;
6837 sig_type
->per_cu
.is_debug_types
= 1;
6838 if (dwarf2_per_objfile
->using_index
)
6840 sig_type
->per_cu
.v
.quick
=
6841 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6842 struct dwarf2_per_cu_quick_data
);
6847 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
6850 gdb_assert (*slot
== NULL
);
6852 /* The rest of sig_type must be filled in by the caller. */
6856 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6857 Fill in SIG_ENTRY with DWO_ENTRY. */
6860 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6861 struct signatured_type
*sig_entry
,
6862 struct dwo_unit
*dwo_entry
)
6864 /* Make sure we're not clobbering something we don't expect to. */
6865 gdb_assert (! sig_entry
->per_cu
.queued
);
6866 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6867 if (dwarf2_per_objfile
->using_index
)
6869 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6870 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
6873 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6874 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6875 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6876 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6877 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6879 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6880 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6881 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6882 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6883 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6884 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6885 sig_entry
->dwo_unit
= dwo_entry
;
6888 /* Subroutine of lookup_signatured_type.
6889 If we haven't read the TU yet, create the signatured_type data structure
6890 for a TU to be read in directly from a DWO file, bypassing the stub.
6891 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6892 using .gdb_index, then when reading a CU we want to stay in the DWO file
6893 containing that CU. Otherwise we could end up reading several other DWO
6894 files (due to comdat folding) to process the transitive closure of all the
6895 mentioned TUs, and that can be slow. The current DWO file will have every
6896 type signature that it needs.
6897 We only do this for .gdb_index because in the psymtab case we already have
6898 to read all the DWOs to build the type unit groups. */
6900 static struct signatured_type
*
6901 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6903 struct dwarf2_per_objfile
*dwarf2_per_objfile
6904 = cu
->per_cu
->dwarf2_per_objfile
;
6905 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6906 struct dwo_file
*dwo_file
;
6907 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6908 struct signatured_type find_sig_entry
, *sig_entry
;
6911 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6913 /* If TU skeletons have been removed then we may not have read in any
6915 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6917 dwarf2_per_objfile
->signatured_types
6918 = allocate_signatured_type_table (objfile
);
6921 /* We only ever need to read in one copy of a signatured type.
6922 Use the global signatured_types array to do our own comdat-folding
6923 of types. If this is the first time we're reading this TU, and
6924 the TU has an entry in .gdb_index, replace the recorded data from
6925 .gdb_index with this TU. */
6927 find_sig_entry
.signature
= sig
;
6928 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
6929 &find_sig_entry
, INSERT
);
6930 sig_entry
= (struct signatured_type
*) *slot
;
6932 /* We can get here with the TU already read, *or* in the process of being
6933 read. Don't reassign the global entry to point to this DWO if that's
6934 the case. Also note that if the TU is already being read, it may not
6935 have come from a DWO, the program may be a mix of Fission-compiled
6936 code and non-Fission-compiled code. */
6938 /* Have we already tried to read this TU?
6939 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6940 needn't exist in the global table yet). */
6941 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6944 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6945 dwo_unit of the TU itself. */
6946 dwo_file
= cu
->dwo_unit
->dwo_file
;
6948 /* Ok, this is the first time we're reading this TU. */
6949 if (dwo_file
->tus
== NULL
)
6951 find_dwo_entry
.signature
= sig
;
6952 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_entry
);
6953 if (dwo_entry
== NULL
)
6956 /* If the global table doesn't have an entry for this TU, add one. */
6957 if (sig_entry
== NULL
)
6958 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6960 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6961 sig_entry
->per_cu
.tu_read
= 1;
6965 /* Subroutine of lookup_signatured_type.
6966 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6967 then try the DWP file. If the TU stub (skeleton) has been removed then
6968 it won't be in .gdb_index. */
6970 static struct signatured_type
*
6971 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6973 struct dwarf2_per_objfile
*dwarf2_per_objfile
6974 = cu
->per_cu
->dwarf2_per_objfile
;
6975 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6976 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
6977 struct dwo_unit
*dwo_entry
;
6978 struct signatured_type find_sig_entry
, *sig_entry
;
6981 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6982 gdb_assert (dwp_file
!= NULL
);
6984 /* If TU skeletons have been removed then we may not have read in any
6986 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6988 dwarf2_per_objfile
->signatured_types
6989 = allocate_signatured_type_table (objfile
);
6992 find_sig_entry
.signature
= sig
;
6993 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
6994 &find_sig_entry
, INSERT
);
6995 sig_entry
= (struct signatured_type
*) *slot
;
6997 /* Have we already tried to read this TU?
6998 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6999 needn't exist in the global table yet). */
7000 if (sig_entry
!= NULL
)
7003 if (dwp_file
->tus
== NULL
)
7005 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
7006 sig
, 1 /* is_debug_types */);
7007 if (dwo_entry
== NULL
)
7010 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7011 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7016 /* Lookup a signature based type for DW_FORM_ref_sig8.
7017 Returns NULL if signature SIG is not present in the table.
7018 It is up to the caller to complain about this. */
7020 static struct signatured_type
*
7021 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7023 struct dwarf2_per_objfile
*dwarf2_per_objfile
7024 = cu
->per_cu
->dwarf2_per_objfile
;
7027 && dwarf2_per_objfile
->using_index
)
7029 /* We're in a DWO/DWP file, and we're using .gdb_index.
7030 These cases require special processing. */
7031 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
7032 return lookup_dwo_signatured_type (cu
, sig
);
7034 return lookup_dwp_signatured_type (cu
, sig
);
7038 struct signatured_type find_entry
, *entry
;
7040 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7042 find_entry
.signature
= sig
;
7043 entry
= ((struct signatured_type
*)
7044 htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
));
7049 /* Low level DIE reading support. */
7051 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
7054 init_cu_die_reader (struct die_reader_specs
*reader
,
7055 struct dwarf2_cu
*cu
,
7056 struct dwarf2_section_info
*section
,
7057 struct dwo_file
*dwo_file
,
7058 struct abbrev_table
*abbrev_table
)
7060 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
7061 reader
->abfd
= get_section_bfd_owner (section
);
7063 reader
->dwo_file
= dwo_file
;
7064 reader
->die_section
= section
;
7065 reader
->buffer
= section
->buffer
;
7066 reader
->buffer_end
= section
->buffer
+ section
->size
;
7067 reader
->comp_dir
= NULL
;
7068 reader
->abbrev_table
= abbrev_table
;
7071 /* Subroutine of init_cutu_and_read_dies to simplify it.
7072 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
7073 There's just a lot of work to do, and init_cutu_and_read_dies is big enough
7076 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
7077 from it to the DIE in the DWO. If NULL we are skipping the stub.
7078 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
7079 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
7080 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
7081 STUB_COMP_DIR may be non-NULL.
7082 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
7083 are filled in with the info of the DIE from the DWO file.
7084 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
7085 from the dwo. Since *RESULT_READER references this abbrev table, it must be
7086 kept around for at least as long as *RESULT_READER.
7088 The result is non-zero if a valid (non-dummy) DIE was found. */
7091 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
7092 struct dwo_unit
*dwo_unit
,
7093 struct die_info
*stub_comp_unit_die
,
7094 const char *stub_comp_dir
,
7095 struct die_reader_specs
*result_reader
,
7096 const gdb_byte
**result_info_ptr
,
7097 struct die_info
**result_comp_unit_die
,
7098 int *result_has_children
,
7099 abbrev_table_up
*result_dwo_abbrev_table
)
7101 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7102 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7103 struct dwarf2_cu
*cu
= this_cu
->cu
;
7105 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7106 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
7107 int i
,num_extra_attrs
;
7108 struct dwarf2_section_info
*dwo_abbrev_section
;
7109 struct attribute
*attr
;
7110 struct die_info
*comp_unit_die
;
7112 /* At most one of these may be provided. */
7113 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
7115 /* These attributes aren't processed until later:
7116 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
7117 DW_AT_comp_dir is used now, to find the DWO file, but it is also
7118 referenced later. However, these attributes are found in the stub
7119 which we won't have later. In order to not impose this complication
7120 on the rest of the code, we read them here and copy them to the
7129 if (stub_comp_unit_die
!= NULL
)
7131 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
7133 if (! this_cu
->is_debug_types
)
7134 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
7135 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
7136 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
7137 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
7138 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
7140 /* There should be a DW_AT_addr_base attribute here (if needed).
7141 We need the value before we can process DW_FORM_GNU_addr_index. */
7143 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
7145 cu
->addr_base
= DW_UNSND (attr
);
7147 /* There should be a DW_AT_ranges_base attribute here (if needed).
7148 We need the value before we can process DW_AT_ranges. */
7149 cu
->ranges_base
= 0;
7150 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
7152 cu
->ranges_base
= DW_UNSND (attr
);
7154 else if (stub_comp_dir
!= NULL
)
7156 /* Reconstruct the comp_dir attribute to simplify the code below. */
7157 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
7158 comp_dir
->name
= DW_AT_comp_dir
;
7159 comp_dir
->form
= DW_FORM_string
;
7160 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
7161 DW_STRING (comp_dir
) = stub_comp_dir
;
7164 /* Set up for reading the DWO CU/TU. */
7165 cu
->dwo_unit
= dwo_unit
;
7166 dwarf2_section_info
*section
= dwo_unit
->section
;
7167 dwarf2_read_section (objfile
, section
);
7168 abfd
= get_section_bfd_owner (section
);
7169 begin_info_ptr
= info_ptr
= (section
->buffer
7170 + to_underlying (dwo_unit
->sect_off
));
7171 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
7173 if (this_cu
->is_debug_types
)
7175 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
7177 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7178 &cu
->header
, section
,
7180 info_ptr
, rcuh_kind::TYPE
);
7181 /* This is not an assert because it can be caused by bad debug info. */
7182 if (sig_type
->signature
!= cu
->header
.signature
)
7184 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
7185 " TU at offset %s [in module %s]"),
7186 hex_string (sig_type
->signature
),
7187 hex_string (cu
->header
.signature
),
7188 sect_offset_str (dwo_unit
->sect_off
),
7189 bfd_get_filename (abfd
));
7191 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7192 /* For DWOs coming from DWP files, we don't know the CU length
7193 nor the type's offset in the TU until now. */
7194 dwo_unit
->length
= get_cu_length (&cu
->header
);
7195 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
7197 /* Establish the type offset that can be used to lookup the type.
7198 For DWO files, we don't know it until now. */
7199 sig_type
->type_offset_in_section
7200 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
7204 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7205 &cu
->header
, section
,
7207 info_ptr
, rcuh_kind::COMPILE
);
7208 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7209 /* For DWOs coming from DWP files, we don't know the CU length
7211 dwo_unit
->length
= get_cu_length (&cu
->header
);
7214 *result_dwo_abbrev_table
7215 = abbrev_table_read_table (dwarf2_per_objfile
, dwo_abbrev_section
,
7216 cu
->header
.abbrev_sect_off
);
7217 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
7218 result_dwo_abbrev_table
->get ());
7220 /* Read in the die, but leave space to copy over the attributes
7221 from the stub. This has the benefit of simplifying the rest of
7222 the code - all the work to maintain the illusion of a single
7223 DW_TAG_{compile,type}_unit DIE is done here. */
7224 num_extra_attrs
= ((stmt_list
!= NULL
)
7228 + (comp_dir
!= NULL
));
7229 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
7230 result_has_children
, num_extra_attrs
);
7232 /* Copy over the attributes from the stub to the DIE we just read in. */
7233 comp_unit_die
= *result_comp_unit_die
;
7234 i
= comp_unit_die
->num_attrs
;
7235 if (stmt_list
!= NULL
)
7236 comp_unit_die
->attrs
[i
++] = *stmt_list
;
7238 comp_unit_die
->attrs
[i
++] = *low_pc
;
7239 if (high_pc
!= NULL
)
7240 comp_unit_die
->attrs
[i
++] = *high_pc
;
7242 comp_unit_die
->attrs
[i
++] = *ranges
;
7243 if (comp_dir
!= NULL
)
7244 comp_unit_die
->attrs
[i
++] = *comp_dir
;
7245 comp_unit_die
->num_attrs
+= num_extra_attrs
;
7247 if (dwarf_die_debug
)
7249 fprintf_unfiltered (gdb_stdlog
,
7250 "Read die from %s@0x%x of %s:\n",
7251 get_section_name (section
),
7252 (unsigned) (begin_info_ptr
- section
->buffer
),
7253 bfd_get_filename (abfd
));
7254 dump_die (comp_unit_die
, dwarf_die_debug
);
7257 /* Save the comp_dir attribute. If there is no DWP file then we'll read
7258 TUs by skipping the stub and going directly to the entry in the DWO file.
7259 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
7260 to get it via circuitous means. Blech. */
7261 if (comp_dir
!= NULL
)
7262 result_reader
->comp_dir
= DW_STRING (comp_dir
);
7264 /* Skip dummy compilation units. */
7265 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
7266 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7269 *result_info_ptr
= info_ptr
;
7273 /* Subroutine of init_cutu_and_read_dies to simplify it.
7274 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
7275 Returns NULL if the specified DWO unit cannot be found. */
7277 static struct dwo_unit
*
7278 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
7279 struct die_info
*comp_unit_die
)
7281 struct dwarf2_cu
*cu
= this_cu
->cu
;
7283 struct dwo_unit
*dwo_unit
;
7284 const char *comp_dir
, *dwo_name
;
7286 gdb_assert (cu
!= NULL
);
7288 /* Yeah, we look dwo_name up again, but it simplifies the code. */
7289 dwo_name
= dwarf2_string_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
7290 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7292 if (this_cu
->is_debug_types
)
7294 struct signatured_type
*sig_type
;
7296 /* Since this_cu is the first member of struct signatured_type,
7297 we can go from a pointer to one to a pointer to the other. */
7298 sig_type
= (struct signatured_type
*) this_cu
;
7299 signature
= sig_type
->signature
;
7300 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
7304 struct attribute
*attr
;
7306 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7308 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
7310 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
7311 signature
= DW_UNSND (attr
);
7312 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
7319 /* Subroutine of init_cutu_and_read_dies to simplify it.
7320 See it for a description of the parameters.
7321 Read a TU directly from a DWO file, bypassing the stub. */
7324 init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
7325 int use_existing_cu
, int keep
,
7326 die_reader_func_ftype
*die_reader_func
,
7329 std::unique_ptr
<dwarf2_cu
> new_cu
;
7330 struct signatured_type
*sig_type
;
7331 struct die_reader_specs reader
;
7332 const gdb_byte
*info_ptr
;
7333 struct die_info
*comp_unit_die
;
7335 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7337 /* Verify we can do the following downcast, and that we have the
7339 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7340 sig_type
= (struct signatured_type
*) this_cu
;
7341 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7343 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7345 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
7346 /* There's no need to do the rereading_dwo_cu handling that
7347 init_cutu_and_read_dies does since we don't read the stub. */
7351 /* If !use_existing_cu, this_cu->cu must be NULL. */
7352 gdb_assert (this_cu
->cu
== NULL
);
7353 new_cu
.reset (new dwarf2_cu (this_cu
));
7356 /* A future optimization, if needed, would be to use an existing
7357 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7358 could share abbrev tables. */
7360 /* The abbreviation table used by READER, this must live at least as long as
7362 abbrev_table_up dwo_abbrev_table
;
7364 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
7365 NULL
/* stub_comp_unit_die */,
7366 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7368 &comp_unit_die
, &has_children
,
7369 &dwo_abbrev_table
) == 0)
7375 /* All the "real" work is done here. */
7376 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7378 /* This duplicates the code in init_cutu_and_read_dies,
7379 but the alternative is making the latter more complex.
7380 This function is only for the special case of using DWO files directly:
7381 no point in overly complicating the general case just to handle this. */
7382 if (new_cu
!= NULL
&& keep
)
7384 /* Link this CU into read_in_chain. */
7385 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7386 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7387 /* The chain owns it now. */
7392 /* Initialize a CU (or TU) and read its DIEs.
7393 If the CU defers to a DWO file, read the DWO file as well.
7395 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7396 Otherwise the table specified in the comp unit header is read in and used.
7397 This is an optimization for when we already have the abbrev table.
7399 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
7400 Otherwise, a new CU is allocated with xmalloc.
7402 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
7403 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
7405 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7406 linker) then DIE_READER_FUNC will not get called. */
7409 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
7410 struct abbrev_table
*abbrev_table
,
7411 int use_existing_cu
, int keep
,
7413 die_reader_func_ftype
*die_reader_func
,
7416 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7417 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7418 struct dwarf2_section_info
*section
= this_cu
->section
;
7419 bfd
*abfd
= get_section_bfd_owner (section
);
7420 struct dwarf2_cu
*cu
;
7421 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7422 struct die_reader_specs reader
;
7423 struct die_info
*comp_unit_die
;
7425 struct attribute
*attr
;
7426 struct signatured_type
*sig_type
= NULL
;
7427 struct dwarf2_section_info
*abbrev_section
;
7428 /* Non-zero if CU currently points to a DWO file and we need to
7429 reread it. When this happens we need to reread the skeleton die
7430 before we can reread the DWO file (this only applies to CUs, not TUs). */
7431 int rereading_dwo_cu
= 0;
7433 if (dwarf_die_debug
)
7434 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7435 this_cu
->is_debug_types
? "type" : "comp",
7436 sect_offset_str (this_cu
->sect_off
));
7438 if (use_existing_cu
)
7441 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7442 file (instead of going through the stub), short-circuit all of this. */
7443 if (this_cu
->reading_dwo_directly
)
7445 /* Narrow down the scope of possibilities to have to understand. */
7446 gdb_assert (this_cu
->is_debug_types
);
7447 gdb_assert (abbrev_table
== NULL
);
7448 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
,
7449 die_reader_func
, data
);
7453 /* This is cheap if the section is already read in. */
7454 dwarf2_read_section (objfile
, section
);
7456 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7458 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7460 std::unique_ptr
<dwarf2_cu
> new_cu
;
7461 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7464 /* If this CU is from a DWO file we need to start over, we need to
7465 refetch the attributes from the skeleton CU.
7466 This could be optimized by retrieving those attributes from when we
7467 were here the first time: the previous comp_unit_die was stored in
7468 comp_unit_obstack. But there's no data yet that we need this
7470 if (cu
->dwo_unit
!= NULL
)
7471 rereading_dwo_cu
= 1;
7475 /* If !use_existing_cu, this_cu->cu must be NULL. */
7476 gdb_assert (this_cu
->cu
== NULL
);
7477 new_cu
.reset (new dwarf2_cu (this_cu
));
7481 /* Get the header. */
7482 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7484 /* We already have the header, there's no need to read it in again. */
7485 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7489 if (this_cu
->is_debug_types
)
7491 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7492 &cu
->header
, section
,
7493 abbrev_section
, info_ptr
,
7496 /* Since per_cu is the first member of struct signatured_type,
7497 we can go from a pointer to one to a pointer to the other. */
7498 sig_type
= (struct signatured_type
*) this_cu
;
7499 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7500 gdb_assert (sig_type
->type_offset_in_tu
7501 == cu
->header
.type_cu_offset_in_tu
);
7502 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7504 /* LENGTH has not been set yet for type units if we're
7505 using .gdb_index. */
7506 this_cu
->length
= get_cu_length (&cu
->header
);
7508 /* Establish the type offset that can be used to lookup the type. */
7509 sig_type
->type_offset_in_section
=
7510 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7512 this_cu
->dwarf_version
= cu
->header
.version
;
7516 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7517 &cu
->header
, section
,
7520 rcuh_kind::COMPILE
);
7522 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7523 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
7524 this_cu
->dwarf_version
= cu
->header
.version
;
7528 /* Skip dummy compilation units. */
7529 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7530 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7533 /* If we don't have them yet, read the abbrevs for this compilation unit.
7534 And if we need to read them now, make sure they're freed when we're
7535 done (own the table through ABBREV_TABLE_HOLDER). */
7536 abbrev_table_up abbrev_table_holder
;
7537 if (abbrev_table
!= NULL
)
7538 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7542 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7543 cu
->header
.abbrev_sect_off
);
7544 abbrev_table
= abbrev_table_holder
.get ();
7547 /* Read the top level CU/TU die. */
7548 init_cu_die_reader (&reader
, cu
, section
, NULL
, abbrev_table
);
7549 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
7551 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7554 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7555 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7556 table from the DWO file and pass the ownership over to us. It will be
7557 referenced from READER, so we must make sure to free it after we're done
7560 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7561 DWO CU, that this test will fail (the attribute will not be present). */
7562 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
7563 abbrev_table_up dwo_abbrev_table
;
7566 struct dwo_unit
*dwo_unit
;
7567 struct die_info
*dwo_comp_unit_die
;
7571 complaint (&symfile_complaints
,
7572 _("compilation unit with DW_AT_GNU_dwo_name"
7573 " has children (offset %s) [in module %s]"),
7574 sect_offset_str (this_cu
->sect_off
),
7575 bfd_get_filename (abfd
));
7577 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
);
7578 if (dwo_unit
!= NULL
)
7580 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
7581 comp_unit_die
, NULL
,
7583 &dwo_comp_unit_die
, &has_children
,
7584 &dwo_abbrev_table
) == 0)
7589 comp_unit_die
= dwo_comp_unit_die
;
7593 /* Yikes, we couldn't find the rest of the DIE, we only have
7594 the stub. A complaint has already been logged. There's
7595 not much more we can do except pass on the stub DIE to
7596 die_reader_func. We don't want to throw an error on bad
7601 /* All of the above is setup for this call. Yikes. */
7602 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7604 /* Done, clean up. */
7605 if (new_cu
!= NULL
&& keep
)
7607 /* Link this CU into read_in_chain. */
7608 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7609 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7610 /* The chain owns it now. */
7615 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name if present.
7616 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed
7617 to have already done the lookup to find the DWO file).
7619 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7620 THIS_CU->is_debug_types, but nothing else.
7622 We fill in THIS_CU->length.
7624 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7625 linker) then DIE_READER_FUNC will not get called.
7627 THIS_CU->cu is always freed when done.
7628 This is done in order to not leave THIS_CU->cu in a state where we have
7629 to care whether it refers to the "main" CU or the DWO CU. */
7632 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
7633 struct dwo_file
*dwo_file
,
7634 die_reader_func_ftype
*die_reader_func
,
7637 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7638 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7639 struct dwarf2_section_info
*section
= this_cu
->section
;
7640 bfd
*abfd
= get_section_bfd_owner (section
);
7641 struct dwarf2_section_info
*abbrev_section
;
7642 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7643 struct die_reader_specs reader
;
7644 struct die_info
*comp_unit_die
;
7647 if (dwarf_die_debug
)
7648 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7649 this_cu
->is_debug_types
? "type" : "comp",
7650 sect_offset_str (this_cu
->sect_off
));
7652 gdb_assert (this_cu
->cu
== NULL
);
7654 abbrev_section
= (dwo_file
!= NULL
7655 ? &dwo_file
->sections
.abbrev
7656 : get_abbrev_section_for_cu (this_cu
));
7658 /* This is cheap if the section is already read in. */
7659 dwarf2_read_section (objfile
, section
);
7661 struct dwarf2_cu
cu (this_cu
);
7663 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7664 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7665 &cu
.header
, section
,
7666 abbrev_section
, info_ptr
,
7667 (this_cu
->is_debug_types
7669 : rcuh_kind::COMPILE
));
7671 this_cu
->length
= get_cu_length (&cu
.header
);
7673 /* Skip dummy compilation units. */
7674 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7675 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7678 abbrev_table_up abbrev_table
7679 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7680 cu
.header
.abbrev_sect_off
);
7682 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
, abbrev_table
.get ());
7683 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
7685 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7688 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
7689 does not lookup the specified DWO file.
7690 This cannot be used to read DWO files.
7692 THIS_CU->cu is always freed when done.
7693 This is done in order to not leave THIS_CU->cu in a state where we have
7694 to care whether it refers to the "main" CU or the DWO CU.
7695 We can revisit this if the data shows there's a performance issue. */
7698 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
7699 die_reader_func_ftype
*die_reader_func
,
7702 init_cutu_and_read_dies_no_follow (this_cu
, NULL
, die_reader_func
, data
);
7705 /* Type Unit Groups.
7707 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7708 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7709 so that all types coming from the same compilation (.o file) are grouped
7710 together. A future step could be to put the types in the same symtab as
7711 the CU the types ultimately came from. */
7714 hash_type_unit_group (const void *item
)
7716 const struct type_unit_group
*tu_group
7717 = (const struct type_unit_group
*) item
;
7719 return hash_stmt_list_entry (&tu_group
->hash
);
7723 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7725 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7726 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7728 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7731 /* Allocate a hash table for type unit groups. */
7734 allocate_type_unit_groups_table (struct objfile
*objfile
)
7736 return htab_create_alloc_ex (3,
7737 hash_type_unit_group
,
7740 &objfile
->objfile_obstack
,
7741 hashtab_obstack_allocate
,
7742 dummy_obstack_deallocate
);
7745 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7746 partial symtabs. We combine several TUs per psymtab to not let the size
7747 of any one psymtab grow too big. */
7748 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7749 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7751 /* Helper routine for get_type_unit_group.
7752 Create the type_unit_group object used to hold one or more TUs. */
7754 static struct type_unit_group
*
7755 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7757 struct dwarf2_per_objfile
*dwarf2_per_objfile
7758 = cu
->per_cu
->dwarf2_per_objfile
;
7759 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7760 struct dwarf2_per_cu_data
*per_cu
;
7761 struct type_unit_group
*tu_group
;
7763 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7764 struct type_unit_group
);
7765 per_cu
= &tu_group
->per_cu
;
7766 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7768 if (dwarf2_per_objfile
->using_index
)
7770 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7771 struct dwarf2_per_cu_quick_data
);
7775 unsigned int line_offset
= to_underlying (line_offset_struct
);
7776 struct partial_symtab
*pst
;
7779 /* Give the symtab a useful name for debug purposes. */
7780 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7781 name
= xstrprintf ("<type_units_%d>",
7782 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7784 name
= xstrprintf ("<type_units_at_0x%x>", line_offset
);
7786 pst
= create_partial_symtab (per_cu
, name
);
7792 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7793 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7798 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7799 STMT_LIST is a DW_AT_stmt_list attribute. */
7801 static struct type_unit_group
*
7802 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7804 struct dwarf2_per_objfile
*dwarf2_per_objfile
7805 = cu
->per_cu
->dwarf2_per_objfile
;
7806 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7807 struct type_unit_group
*tu_group
;
7809 unsigned int line_offset
;
7810 struct type_unit_group type_unit_group_for_lookup
;
7812 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7814 dwarf2_per_objfile
->type_unit_groups
=
7815 allocate_type_unit_groups_table (dwarf2_per_objfile
->objfile
);
7818 /* Do we need to create a new group, or can we use an existing one? */
7822 line_offset
= DW_UNSND (stmt_list
);
7823 ++tu_stats
->nr_symtab_sharers
;
7827 /* Ugh, no stmt_list. Rare, but we have to handle it.
7828 We can do various things here like create one group per TU or
7829 spread them over multiple groups to split up the expansion work.
7830 To avoid worst case scenarios (too many groups or too large groups)
7831 we, umm, group them in bunches. */
7832 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7833 | (tu_stats
->nr_stmt_less_type_units
7834 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7835 ++tu_stats
->nr_stmt_less_type_units
;
7838 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7839 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7840 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
7841 &type_unit_group_for_lookup
, INSERT
);
7844 tu_group
= (struct type_unit_group
*) *slot
;
7845 gdb_assert (tu_group
!= NULL
);
7849 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7850 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7852 ++tu_stats
->nr_symtabs
;
7858 /* Partial symbol tables. */
7860 /* Create a psymtab named NAME and assign it to PER_CU.
7862 The caller must fill in the following details:
7863 dirname, textlow, texthigh. */
7865 static struct partial_symtab
*
7866 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
7868 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
7869 struct partial_symtab
*pst
;
7871 pst
= start_psymtab_common (objfile
, name
, 0,
7872 objfile
->global_psymbols
,
7873 objfile
->static_psymbols
);
7875 pst
->psymtabs_addrmap_supported
= 1;
7877 /* This is the glue that links PST into GDB's symbol API. */
7878 pst
->read_symtab_private
= per_cu
;
7879 pst
->read_symtab
= dwarf2_read_symtab
;
7880 per_cu
->v
.psymtab
= pst
;
7885 /* The DATA object passed to process_psymtab_comp_unit_reader has this
7888 struct process_psymtab_comp_unit_data
7890 /* True if we are reading a DW_TAG_partial_unit. */
7892 int want_partial_unit
;
7894 /* The "pretend" language that is used if the CU doesn't declare a
7897 enum language pretend_language
;
7900 /* die_reader_func for process_psymtab_comp_unit. */
7903 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7904 const gdb_byte
*info_ptr
,
7905 struct die_info
*comp_unit_die
,
7909 struct dwarf2_cu
*cu
= reader
->cu
;
7910 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
7911 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7912 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7914 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7915 struct partial_symtab
*pst
;
7916 enum pc_bounds_kind cu_bounds_kind
;
7917 const char *filename
;
7918 struct process_psymtab_comp_unit_data
*info
7919 = (struct process_psymtab_comp_unit_data
*) data
;
7921 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !info
->want_partial_unit
)
7924 gdb_assert (! per_cu
->is_debug_types
);
7926 prepare_one_comp_unit (cu
, comp_unit_die
, info
->pretend_language
);
7928 cu
->list_in_scope
= &file_symbols
;
7930 /* Allocate a new partial symbol table structure. */
7931 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7932 if (filename
== NULL
)
7935 pst
= create_partial_symtab (per_cu
, filename
);
7937 /* This must be done before calling dwarf2_build_include_psymtabs. */
7938 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7940 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7942 dwarf2_find_base_address (comp_unit_die
, cu
);
7944 /* Possibly set the default values of LOWPC and HIGHPC from
7946 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7947 &best_highpc
, cu
, pst
);
7948 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7949 /* Store the contiguous range if it is not empty; it can be empty for
7950 CUs with no code. */
7951 addrmap_set_empty (objfile
->psymtabs_addrmap
,
7952 gdbarch_adjust_dwarf2_addr (gdbarch
,
7953 best_lowpc
+ baseaddr
),
7954 gdbarch_adjust_dwarf2_addr (gdbarch
,
7955 best_highpc
+ baseaddr
) - 1,
7958 /* Check if comp unit has_children.
7959 If so, read the rest of the partial symbols from this comp unit.
7960 If not, there's no more debug_info for this comp unit. */
7963 struct partial_die_info
*first_die
;
7964 CORE_ADDR lowpc
, highpc
;
7966 lowpc
= ((CORE_ADDR
) -1);
7967 highpc
= ((CORE_ADDR
) 0);
7969 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7971 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7972 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7974 /* If we didn't find a lowpc, set it to highpc to avoid
7975 complaints from `maint check'. */
7976 if (lowpc
== ((CORE_ADDR
) -1))
7979 /* If the compilation unit didn't have an explicit address range,
7980 then use the information extracted from its child dies. */
7981 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7984 best_highpc
= highpc
;
7987 pst
->textlow
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
);
7988 pst
->texthigh
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
);
7990 end_psymtab_common (objfile
, pst
);
7992 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
))
7995 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
7996 struct dwarf2_per_cu_data
*iter
;
7998 /* Fill in 'dependencies' here; we fill in 'users' in a
8000 pst
->number_of_dependencies
= len
;
8002 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
8004 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
8007 pst
->dependencies
[i
] = iter
->v
.psymtab
;
8009 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
8012 /* Get the list of files included in the current compilation unit,
8013 and build a psymtab for each of them. */
8014 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
8016 if (dwarf_read_debug
)
8018 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8020 fprintf_unfiltered (gdb_stdlog
,
8021 "Psymtab for %s unit @%s: %s - %s"
8022 ", %d global, %d static syms\n",
8023 per_cu
->is_debug_types
? "type" : "comp",
8024 sect_offset_str (per_cu
->sect_off
),
8025 paddress (gdbarch
, pst
->textlow
),
8026 paddress (gdbarch
, pst
->texthigh
),
8027 pst
->n_global_syms
, pst
->n_static_syms
);
8031 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8032 Process compilation unit THIS_CU for a psymtab. */
8035 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8036 int want_partial_unit
,
8037 enum language pretend_language
)
8039 /* If this compilation unit was already read in, free the
8040 cached copy in order to read it in again. This is
8041 necessary because we skipped some symbols when we first
8042 read in the compilation unit (see load_partial_dies).
8043 This problem could be avoided, but the benefit is unclear. */
8044 if (this_cu
->cu
!= NULL
)
8045 free_one_cached_comp_unit (this_cu
);
8047 if (this_cu
->is_debug_types
)
8048 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0, false,
8049 build_type_psymtabs_reader
, NULL
);
8052 process_psymtab_comp_unit_data info
;
8053 info
.want_partial_unit
= want_partial_unit
;
8054 info
.pretend_language
= pretend_language
;
8055 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0, false,
8056 process_psymtab_comp_unit_reader
, &info
);
8059 /* Age out any secondary CUs. */
8060 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
8063 /* Reader function for build_type_psymtabs. */
8066 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
8067 const gdb_byte
*info_ptr
,
8068 struct die_info
*type_unit_die
,
8072 struct dwarf2_per_objfile
*dwarf2_per_objfile
8073 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
8074 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8075 struct dwarf2_cu
*cu
= reader
->cu
;
8076 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8077 struct signatured_type
*sig_type
;
8078 struct type_unit_group
*tu_group
;
8079 struct attribute
*attr
;
8080 struct partial_die_info
*first_die
;
8081 CORE_ADDR lowpc
, highpc
;
8082 struct partial_symtab
*pst
;
8084 gdb_assert (data
== NULL
);
8085 gdb_assert (per_cu
->is_debug_types
);
8086 sig_type
= (struct signatured_type
*) per_cu
;
8091 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
8092 tu_group
= get_type_unit_group (cu
, attr
);
8094 VEC_safe_push (sig_type_ptr
, tu_group
->tus
, sig_type
);
8096 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
8097 cu
->list_in_scope
= &file_symbols
;
8098 pst
= create_partial_symtab (per_cu
, "");
8101 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8103 lowpc
= (CORE_ADDR
) -1;
8104 highpc
= (CORE_ADDR
) 0;
8105 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
8107 end_psymtab_common (objfile
, pst
);
8110 /* Struct used to sort TUs by their abbreviation table offset. */
8112 struct tu_abbrev_offset
8114 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
8115 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
8118 signatured_type
*sig_type
;
8119 sect_offset abbrev_offset
;
8122 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
8125 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
8126 const struct tu_abbrev_offset
&b
)
8128 return a
.abbrev_offset
< b
.abbrev_offset
;
8131 /* Efficiently read all the type units.
8132 This does the bulk of the work for build_type_psymtabs.
8134 The efficiency is because we sort TUs by the abbrev table they use and
8135 only read each abbrev table once. In one program there are 200K TUs
8136 sharing 8K abbrev tables.
8138 The main purpose of this function is to support building the
8139 dwarf2_per_objfile->type_unit_groups table.
8140 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
8141 can collapse the search space by grouping them by stmt_list.
8142 The savings can be significant, in the same program from above the 200K TUs
8143 share 8K stmt_list tables.
8145 FUNC is expected to call get_type_unit_group, which will create the
8146 struct type_unit_group if necessary and add it to
8147 dwarf2_per_objfile->type_unit_groups. */
8150 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8152 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8153 abbrev_table_up abbrev_table
;
8154 sect_offset abbrev_offset
;
8156 /* It's up to the caller to not call us multiple times. */
8157 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
8159 if (dwarf2_per_objfile
->all_type_units
.empty ())
8162 /* TUs typically share abbrev tables, and there can be way more TUs than
8163 abbrev tables. Sort by abbrev table to reduce the number of times we
8164 read each abbrev table in.
8165 Alternatives are to punt or to maintain a cache of abbrev tables.
8166 This is simpler and efficient enough for now.
8168 Later we group TUs by their DW_AT_stmt_list value (as this defines the
8169 symtab to use). Typically TUs with the same abbrev offset have the same
8170 stmt_list value too so in practice this should work well.
8172 The basic algorithm here is:
8174 sort TUs by abbrev table
8175 for each TU with same abbrev table:
8176 read abbrev table if first user
8177 read TU top level DIE
8178 [IWBN if DWO skeletons had DW_AT_stmt_list]
8181 if (dwarf_read_debug
)
8182 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
8184 /* Sort in a separate table to maintain the order of all_type_units
8185 for .gdb_index: TU indices directly index all_type_units. */
8186 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
8187 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
8189 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
8190 sorted_by_abbrev
.emplace_back
8191 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
8192 sig_type
->per_cu
.section
,
8193 sig_type
->per_cu
.sect_off
));
8195 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
8196 sort_tu_by_abbrev_offset
);
8198 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
8200 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
8202 /* Switch to the next abbrev table if necessary. */
8203 if (abbrev_table
== NULL
8204 || tu
.abbrev_offset
!= abbrev_offset
)
8206 abbrev_offset
= tu
.abbrev_offset
;
8208 abbrev_table_read_table (dwarf2_per_objfile
,
8209 &dwarf2_per_objfile
->abbrev
,
8211 ++tu_stats
->nr_uniq_abbrev_tables
;
8214 init_cutu_and_read_dies (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
8215 0, 0, false, build_type_psymtabs_reader
, NULL
);
8219 /* Print collected type unit statistics. */
8222 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8224 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8226 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
8227 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
8228 dwarf2_per_objfile
->all_type_units
.size ());
8229 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
8230 tu_stats
->nr_uniq_abbrev_tables
);
8231 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
8232 tu_stats
->nr_symtabs
);
8233 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
8234 tu_stats
->nr_symtab_sharers
);
8235 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
8236 tu_stats
->nr_stmt_less_type_units
);
8237 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
8238 tu_stats
->nr_all_type_units_reallocs
);
8241 /* Traversal function for build_type_psymtabs. */
8244 build_type_psymtab_dependencies (void **slot
, void *info
)
8246 struct dwarf2_per_objfile
*dwarf2_per_objfile
8247 = (struct dwarf2_per_objfile
*) info
;
8248 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8249 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
8250 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
8251 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8252 int len
= VEC_length (sig_type_ptr
, tu_group
->tus
);
8253 struct signatured_type
*iter
;
8256 gdb_assert (len
> 0);
8257 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
8259 pst
->number_of_dependencies
= len
;
8261 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
8263 VEC_iterate (sig_type_ptr
, tu_group
->tus
, i
, iter
);
8266 gdb_assert (iter
->per_cu
.is_debug_types
);
8267 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
8268 iter
->type_unit_group
= tu_group
;
8271 VEC_free (sig_type_ptr
, tu_group
->tus
);
8276 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8277 Build partial symbol tables for the .debug_types comp-units. */
8280 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8282 if (! create_all_type_units (dwarf2_per_objfile
))
8285 build_type_psymtabs_1 (dwarf2_per_objfile
);
8288 /* Traversal function for process_skeletonless_type_unit.
8289 Read a TU in a DWO file and build partial symbols for it. */
8292 process_skeletonless_type_unit (void **slot
, void *info
)
8294 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
8295 struct dwarf2_per_objfile
*dwarf2_per_objfile
8296 = (struct dwarf2_per_objfile
*) info
;
8297 struct signatured_type find_entry
, *entry
;
8299 /* If this TU doesn't exist in the global table, add it and read it in. */
8301 if (dwarf2_per_objfile
->signatured_types
== NULL
)
8303 dwarf2_per_objfile
->signatured_types
8304 = allocate_signatured_type_table (dwarf2_per_objfile
->objfile
);
8307 find_entry
.signature
= dwo_unit
->signature
;
8308 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
8310 /* If we've already seen this type there's nothing to do. What's happening
8311 is we're doing our own version of comdat-folding here. */
8315 /* This does the job that create_all_type_units would have done for
8317 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
8318 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
8321 /* This does the job that build_type_psymtabs_1 would have done. */
8322 init_cutu_and_read_dies (&entry
->per_cu
, NULL
, 0, 0, false,
8323 build_type_psymtabs_reader
, NULL
);
8328 /* Traversal function for process_skeletonless_type_units. */
8331 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
8333 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8335 if (dwo_file
->tus
!= NULL
)
8337 htab_traverse_noresize (dwo_file
->tus
,
8338 process_skeletonless_type_unit
, info
);
8344 /* Scan all TUs of DWO files, verifying we've processed them.
8345 This is needed in case a TU was emitted without its skeleton.
8346 Note: This can't be done until we know what all the DWO files are. */
8349 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8351 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
8352 if (get_dwp_file (dwarf2_per_objfile
) == NULL
8353 && dwarf2_per_objfile
->dwo_files
!= NULL
)
8355 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
,
8356 process_dwo_file_for_skeletonless_type_units
,
8357 dwarf2_per_objfile
);
8361 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
8364 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8366 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8368 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8373 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
8375 /* Set the 'user' field only if it is not already set. */
8376 if (pst
->dependencies
[j
]->user
== NULL
)
8377 pst
->dependencies
[j
]->user
= pst
;
8382 /* Build the partial symbol table by doing a quick pass through the
8383 .debug_info and .debug_abbrev sections. */
8386 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8388 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8390 if (dwarf_read_debug
)
8392 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
8393 objfile_name (objfile
));
8396 dwarf2_per_objfile
->reading_partial_symbols
= 1;
8398 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
8400 /* Any cached compilation units will be linked by the per-objfile
8401 read_in_chain. Make sure to free them when we're done. */
8402 free_cached_comp_units
freer (dwarf2_per_objfile
);
8404 build_type_psymtabs (dwarf2_per_objfile
);
8406 create_all_comp_units (dwarf2_per_objfile
);
8408 /* Create a temporary address map on a temporary obstack. We later
8409 copy this to the final obstack. */
8410 auto_obstack temp_obstack
;
8412 scoped_restore save_psymtabs_addrmap
8413 = make_scoped_restore (&objfile
->psymtabs_addrmap
,
8414 addrmap_create_mutable (&temp_obstack
));
8416 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8417 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
8419 /* This has to wait until we read the CUs, we need the list of DWOs. */
8420 process_skeletonless_type_units (dwarf2_per_objfile
);
8422 /* Now that all TUs have been processed we can fill in the dependencies. */
8423 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
8425 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
8426 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
8429 if (dwarf_read_debug
)
8430 print_tu_stats (dwarf2_per_objfile
);
8432 set_partial_user (dwarf2_per_objfile
);
8434 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
8435 &objfile
->objfile_obstack
);
8436 /* At this point we want to keep the address map. */
8437 save_psymtabs_addrmap
.release ();
8439 if (dwarf_read_debug
)
8440 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8441 objfile_name (objfile
));
8444 /* die_reader_func for load_partial_comp_unit. */
8447 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
8448 const gdb_byte
*info_ptr
,
8449 struct die_info
*comp_unit_die
,
8453 struct dwarf2_cu
*cu
= reader
->cu
;
8455 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
8457 /* Check if comp unit has_children.
8458 If so, read the rest of the partial symbols from this comp unit.
8459 If not, there's no more debug_info for this comp unit. */
8461 load_partial_dies (reader
, info_ptr
, 0);
8464 /* Load the partial DIEs for a secondary CU into memory.
8465 This is also used when rereading a primary CU with load_all_dies. */
8468 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
8470 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1, false,
8471 load_partial_comp_unit_reader
, NULL
);
8475 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
8476 struct dwarf2_section_info
*section
,
8477 struct dwarf2_section_info
*abbrev_section
,
8478 unsigned int is_dwz
)
8480 const gdb_byte
*info_ptr
;
8481 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8483 if (dwarf_read_debug
)
8484 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8485 get_section_name (section
),
8486 get_section_file_name (section
));
8488 dwarf2_read_section (objfile
, section
);
8490 info_ptr
= section
->buffer
;
8492 while (info_ptr
< section
->buffer
+ section
->size
)
8494 struct dwarf2_per_cu_data
*this_cu
;
8496 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8498 comp_unit_head cu_header
;
8499 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
8500 abbrev_section
, info_ptr
,
8501 rcuh_kind::COMPILE
);
8503 /* Save the compilation unit for later lookup. */
8504 if (cu_header
.unit_type
!= DW_UT_type
)
8506 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
8507 struct dwarf2_per_cu_data
);
8508 memset (this_cu
, 0, sizeof (*this_cu
));
8512 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
8513 struct signatured_type
);
8514 memset (sig_type
, 0, sizeof (*sig_type
));
8515 sig_type
->signature
= cu_header
.signature
;
8516 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8517 this_cu
= &sig_type
->per_cu
;
8519 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8520 this_cu
->sect_off
= sect_off
;
8521 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8522 this_cu
->is_dwz
= is_dwz
;
8523 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
8524 this_cu
->section
= section
;
8526 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
8528 info_ptr
= info_ptr
+ this_cu
->length
;
8532 /* Create a list of all compilation units in OBJFILE.
8533 This is only done for -readnow and building partial symtabs. */
8536 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8538 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
8539 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
8540 &dwarf2_per_objfile
->abbrev
, 0);
8542 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
8544 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
8548 /* Process all loaded DIEs for compilation unit CU, starting at
8549 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8550 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8551 DW_AT_ranges). See the comments of add_partial_subprogram on how
8552 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8555 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8556 CORE_ADDR
*highpc
, int set_addrmap
,
8557 struct dwarf2_cu
*cu
)
8559 struct partial_die_info
*pdi
;
8561 /* Now, march along the PDI's, descending into ones which have
8562 interesting children but skipping the children of the other ones,
8563 until we reach the end of the compilation unit. */
8571 /* Anonymous namespaces or modules have no name but have interesting
8572 children, so we need to look at them. Ditto for anonymous
8575 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8576 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8577 || pdi
->tag
== DW_TAG_imported_unit
8578 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8582 case DW_TAG_subprogram
:
8583 case DW_TAG_inlined_subroutine
:
8584 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8586 case DW_TAG_constant
:
8587 case DW_TAG_variable
:
8588 case DW_TAG_typedef
:
8589 case DW_TAG_union_type
:
8590 if (!pdi
->is_declaration
)
8592 add_partial_symbol (pdi
, cu
);
8595 case DW_TAG_class_type
:
8596 case DW_TAG_interface_type
:
8597 case DW_TAG_structure_type
:
8598 if (!pdi
->is_declaration
)
8600 add_partial_symbol (pdi
, cu
);
8602 if ((cu
->language
== language_rust
8603 || cu
->language
== language_cplus
) && pdi
->has_children
)
8604 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8607 case DW_TAG_enumeration_type
:
8608 if (!pdi
->is_declaration
)
8609 add_partial_enumeration (pdi
, cu
);
8611 case DW_TAG_base_type
:
8612 case DW_TAG_subrange_type
:
8613 /* File scope base type definitions are added to the partial
8615 add_partial_symbol (pdi
, cu
);
8617 case DW_TAG_namespace
:
8618 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8621 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8623 case DW_TAG_imported_unit
:
8625 struct dwarf2_per_cu_data
*per_cu
;
8627 /* For now we don't handle imported units in type units. */
8628 if (cu
->per_cu
->is_debug_types
)
8630 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8631 " supported in type units [in module %s]"),
8632 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
8635 per_cu
= dwarf2_find_containing_comp_unit
8636 (pdi
->d
.sect_off
, pdi
->is_dwz
,
8637 cu
->per_cu
->dwarf2_per_objfile
);
8639 /* Go read the partial unit, if needed. */
8640 if (per_cu
->v
.psymtab
== NULL
)
8641 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
8643 VEC_safe_push (dwarf2_per_cu_ptr
,
8644 cu
->per_cu
->imported_symtabs
, per_cu
);
8647 case DW_TAG_imported_declaration
:
8648 add_partial_symbol (pdi
, cu
);
8655 /* If the die has a sibling, skip to the sibling. */
8657 pdi
= pdi
->die_sibling
;
8661 /* Functions used to compute the fully scoped name of a partial DIE.
8663 Normally, this is simple. For C++, the parent DIE's fully scoped
8664 name is concatenated with "::" and the partial DIE's name.
8665 Enumerators are an exception; they use the scope of their parent
8666 enumeration type, i.e. the name of the enumeration type is not
8667 prepended to the enumerator.
8669 There are two complexities. One is DW_AT_specification; in this
8670 case "parent" means the parent of the target of the specification,
8671 instead of the direct parent of the DIE. The other is compilers
8672 which do not emit DW_TAG_namespace; in this case we try to guess
8673 the fully qualified name of structure types from their members'
8674 linkage names. This must be done using the DIE's children rather
8675 than the children of any DW_AT_specification target. We only need
8676 to do this for structures at the top level, i.e. if the target of
8677 any DW_AT_specification (if any; otherwise the DIE itself) does not
8680 /* Compute the scope prefix associated with PDI's parent, in
8681 compilation unit CU. The result will be allocated on CU's
8682 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8683 field. NULL is returned if no prefix is necessary. */
8685 partial_die_parent_scope (struct partial_die_info
*pdi
,
8686 struct dwarf2_cu
*cu
)
8688 const char *grandparent_scope
;
8689 struct partial_die_info
*parent
, *real_pdi
;
8691 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8692 then this means the parent of the specification DIE. */
8695 while (real_pdi
->has_specification
)
8696 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
8697 real_pdi
->spec_is_dwz
, cu
);
8699 parent
= real_pdi
->die_parent
;
8703 if (parent
->scope_set
)
8704 return parent
->scope
;
8708 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8710 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8711 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8712 Work around this problem here. */
8713 if (cu
->language
== language_cplus
8714 && parent
->tag
== DW_TAG_namespace
8715 && strcmp (parent
->name
, "::") == 0
8716 && grandparent_scope
== NULL
)
8718 parent
->scope
= NULL
;
8719 parent
->scope_set
= 1;
8723 if (pdi
->tag
== DW_TAG_enumerator
)
8724 /* Enumerators should not get the name of the enumeration as a prefix. */
8725 parent
->scope
= grandparent_scope
;
8726 else if (parent
->tag
== DW_TAG_namespace
8727 || parent
->tag
== DW_TAG_module
8728 || parent
->tag
== DW_TAG_structure_type
8729 || parent
->tag
== DW_TAG_class_type
8730 || parent
->tag
== DW_TAG_interface_type
8731 || parent
->tag
== DW_TAG_union_type
8732 || parent
->tag
== DW_TAG_enumeration_type
)
8734 if (grandparent_scope
== NULL
)
8735 parent
->scope
= parent
->name
;
8737 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8739 parent
->name
, 0, cu
);
8743 /* FIXME drow/2004-04-01: What should we be doing with
8744 function-local names? For partial symbols, we should probably be
8746 complaint (&symfile_complaints
,
8747 _("unhandled containing DIE tag %d for DIE at %s"),
8748 parent
->tag
, sect_offset_str (pdi
->sect_off
));
8749 parent
->scope
= grandparent_scope
;
8752 parent
->scope_set
= 1;
8753 return parent
->scope
;
8756 /* Return the fully scoped name associated with PDI, from compilation unit
8757 CU. The result will be allocated with malloc. */
8760 partial_die_full_name (struct partial_die_info
*pdi
,
8761 struct dwarf2_cu
*cu
)
8763 const char *parent_scope
;
8765 /* If this is a template instantiation, we can not work out the
8766 template arguments from partial DIEs. So, unfortunately, we have
8767 to go through the full DIEs. At least any work we do building
8768 types here will be reused if full symbols are loaded later. */
8769 if (pdi
->has_template_arguments
)
8773 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8775 struct die_info
*die
;
8776 struct attribute attr
;
8777 struct dwarf2_cu
*ref_cu
= cu
;
8779 /* DW_FORM_ref_addr is using section offset. */
8780 attr
.name
= (enum dwarf_attribute
) 0;
8781 attr
.form
= DW_FORM_ref_addr
;
8782 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8783 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8785 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8789 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8790 if (parent_scope
== NULL
)
8793 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
8797 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8799 struct dwarf2_per_objfile
*dwarf2_per_objfile
8800 = cu
->per_cu
->dwarf2_per_objfile
;
8801 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8802 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8804 const char *actual_name
= NULL
;
8806 char *built_actual_name
;
8808 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8810 built_actual_name
= partial_die_full_name (pdi
, cu
);
8811 if (built_actual_name
!= NULL
)
8812 actual_name
= built_actual_name
;
8814 if (actual_name
== NULL
)
8815 actual_name
= pdi
->name
;
8819 case DW_TAG_inlined_subroutine
:
8820 case DW_TAG_subprogram
:
8821 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
);
8822 if (pdi
->is_external
|| cu
->language
== language_ada
)
8824 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
8825 of the global scope. But in Ada, we want to be able to access
8826 nested procedures globally. So all Ada subprograms are stored
8827 in the global scope. */
8828 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8829 built_actual_name
!= NULL
,
8830 VAR_DOMAIN
, LOC_BLOCK
,
8831 &objfile
->global_psymbols
,
8832 addr
, cu
->language
, objfile
);
8836 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8837 built_actual_name
!= NULL
,
8838 VAR_DOMAIN
, LOC_BLOCK
,
8839 &objfile
->static_psymbols
,
8840 addr
, cu
->language
, objfile
);
8843 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8844 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8846 case DW_TAG_constant
:
8848 std::vector
<partial_symbol
*> *list
;
8850 if (pdi
->is_external
)
8851 list
= &objfile
->global_psymbols
;
8853 list
= &objfile
->static_psymbols
;
8854 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8855 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8856 list
, 0, cu
->language
, objfile
);
8859 case DW_TAG_variable
:
8861 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8865 && !dwarf2_per_objfile
->has_section_at_zero
)
8867 /* A global or static variable may also have been stripped
8868 out by the linker if unused, in which case its address
8869 will be nullified; do not add such variables into partial
8870 symbol table then. */
8872 else if (pdi
->is_external
)
8875 Don't enter into the minimal symbol tables as there is
8876 a minimal symbol table entry from the ELF symbols already.
8877 Enter into partial symbol table if it has a location
8878 descriptor or a type.
8879 If the location descriptor is missing, new_symbol will create
8880 a LOC_UNRESOLVED symbol, the address of the variable will then
8881 be determined from the minimal symbol table whenever the variable
8883 The address for the partial symbol table entry is not
8884 used by GDB, but it comes in handy for debugging partial symbol
8887 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8888 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8889 built_actual_name
!= NULL
,
8890 VAR_DOMAIN
, LOC_STATIC
,
8891 &objfile
->global_psymbols
,
8893 cu
->language
, objfile
);
8897 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8899 /* Static Variable. Skip symbols whose value we cannot know (those
8900 without location descriptors or constant values). */
8901 if (!has_loc
&& !pdi
->has_const_value
)
8903 xfree (built_actual_name
);
8907 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8908 built_actual_name
!= NULL
,
8909 VAR_DOMAIN
, LOC_STATIC
,
8910 &objfile
->static_psymbols
,
8911 has_loc
? addr
+ baseaddr
: (CORE_ADDR
) 0,
8912 cu
->language
, objfile
);
8915 case DW_TAG_typedef
:
8916 case DW_TAG_base_type
:
8917 case DW_TAG_subrange_type
:
8918 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8919 built_actual_name
!= NULL
,
8920 VAR_DOMAIN
, LOC_TYPEDEF
,
8921 &objfile
->static_psymbols
,
8922 0, cu
->language
, objfile
);
8924 case DW_TAG_imported_declaration
:
8925 case DW_TAG_namespace
:
8926 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8927 built_actual_name
!= NULL
,
8928 VAR_DOMAIN
, LOC_TYPEDEF
,
8929 &objfile
->global_psymbols
,
8930 0, cu
->language
, objfile
);
8933 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8934 built_actual_name
!= NULL
,
8935 MODULE_DOMAIN
, LOC_TYPEDEF
,
8936 &objfile
->global_psymbols
,
8937 0, cu
->language
, objfile
);
8939 case DW_TAG_class_type
:
8940 case DW_TAG_interface_type
:
8941 case DW_TAG_structure_type
:
8942 case DW_TAG_union_type
:
8943 case DW_TAG_enumeration_type
:
8944 /* Skip external references. The DWARF standard says in the section
8945 about "Structure, Union, and Class Type Entries": "An incomplete
8946 structure, union or class type is represented by a structure,
8947 union or class entry that does not have a byte size attribute
8948 and that has a DW_AT_declaration attribute." */
8949 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8951 xfree (built_actual_name
);
8955 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8956 static vs. global. */
8957 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8958 built_actual_name
!= NULL
,
8959 STRUCT_DOMAIN
, LOC_TYPEDEF
,
8960 cu
->language
== language_cplus
8961 ? &objfile
->global_psymbols
8962 : &objfile
->static_psymbols
,
8963 0, cu
->language
, objfile
);
8966 case DW_TAG_enumerator
:
8967 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8968 built_actual_name
!= NULL
,
8969 VAR_DOMAIN
, LOC_CONST
,
8970 cu
->language
== language_cplus
8971 ? &objfile
->global_psymbols
8972 : &objfile
->static_psymbols
,
8973 0, cu
->language
, objfile
);
8979 xfree (built_actual_name
);
8982 /* Read a partial die corresponding to a namespace; also, add a symbol
8983 corresponding to that namespace to the symbol table. NAMESPACE is
8984 the name of the enclosing namespace. */
8987 add_partial_namespace (struct partial_die_info
*pdi
,
8988 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8989 int set_addrmap
, struct dwarf2_cu
*cu
)
8991 /* Add a symbol for the namespace. */
8993 add_partial_symbol (pdi
, cu
);
8995 /* Now scan partial symbols in that namespace. */
8997 if (pdi
->has_children
)
8998 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9001 /* Read a partial die corresponding to a Fortran module. */
9004 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
9005 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
9007 /* Add a symbol for the namespace. */
9009 add_partial_symbol (pdi
, cu
);
9011 /* Now scan partial symbols in that module. */
9013 if (pdi
->has_children
)
9014 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9017 /* Read a partial die corresponding to a subprogram or an inlined
9018 subprogram and create a partial symbol for that subprogram.
9019 When the CU language allows it, this routine also defines a partial
9020 symbol for each nested subprogram that this subprogram contains.
9021 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
9022 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
9024 PDI may also be a lexical block, in which case we simply search
9025 recursively for subprograms defined inside that lexical block.
9026 Again, this is only performed when the CU language allows this
9027 type of definitions. */
9030 add_partial_subprogram (struct partial_die_info
*pdi
,
9031 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9032 int set_addrmap
, struct dwarf2_cu
*cu
)
9034 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
9036 if (pdi
->has_pc_info
)
9038 if (pdi
->lowpc
< *lowpc
)
9039 *lowpc
= pdi
->lowpc
;
9040 if (pdi
->highpc
> *highpc
)
9041 *highpc
= pdi
->highpc
;
9044 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9045 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9050 baseaddr
= ANOFFSET (objfile
->section_offsets
,
9051 SECT_OFF_TEXT (objfile
));
9052 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
9053 pdi
->lowpc
+ baseaddr
);
9054 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
9055 pdi
->highpc
+ baseaddr
);
9056 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
9057 cu
->per_cu
->v
.psymtab
);
9061 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
9063 if (!pdi
->is_declaration
)
9064 /* Ignore subprogram DIEs that do not have a name, they are
9065 illegal. Do not emit a complaint at this point, we will
9066 do so when we convert this psymtab into a symtab. */
9068 add_partial_symbol (pdi
, cu
);
9072 if (! pdi
->has_children
)
9075 if (cu
->language
== language_ada
)
9077 pdi
= pdi
->die_child
;
9081 if (pdi
->tag
== DW_TAG_subprogram
9082 || pdi
->tag
== DW_TAG_inlined_subroutine
9083 || pdi
->tag
== DW_TAG_lexical_block
)
9084 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9085 pdi
= pdi
->die_sibling
;
9090 /* Read a partial die corresponding to an enumeration type. */
9093 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
9094 struct dwarf2_cu
*cu
)
9096 struct partial_die_info
*pdi
;
9098 if (enum_pdi
->name
!= NULL
)
9099 add_partial_symbol (enum_pdi
, cu
);
9101 pdi
= enum_pdi
->die_child
;
9104 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
9105 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
9107 add_partial_symbol (pdi
, cu
);
9108 pdi
= pdi
->die_sibling
;
9112 /* Return the initial uleb128 in the die at INFO_PTR. */
9115 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
9117 unsigned int bytes_read
;
9119 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9122 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
9123 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
9125 Return the corresponding abbrev, or NULL if the number is zero (indicating
9126 an empty DIE). In either case *BYTES_READ will be set to the length of
9127 the initial number. */
9129 static struct abbrev_info
*
9130 peek_die_abbrev (const die_reader_specs
&reader
,
9131 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
9133 dwarf2_cu
*cu
= reader
.cu
;
9134 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
9135 unsigned int abbrev_number
9136 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
9138 if (abbrev_number
== 0)
9141 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
9144 error (_("Dwarf Error: Could not find abbrev number %d in %s"
9145 " at offset %s [in module %s]"),
9146 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
9147 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
9153 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9154 Returns a pointer to the end of a series of DIEs, terminated by an empty
9155 DIE. Any children of the skipped DIEs will also be skipped. */
9157 static const gdb_byte
*
9158 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
9162 unsigned int bytes_read
;
9163 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
9166 return info_ptr
+ bytes_read
;
9168 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
9172 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9173 INFO_PTR should point just after the initial uleb128 of a DIE, and the
9174 abbrev corresponding to that skipped uleb128 should be passed in
9175 ABBREV. Returns a pointer to this DIE's sibling, skipping any
9178 static const gdb_byte
*
9179 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
9180 struct abbrev_info
*abbrev
)
9182 unsigned int bytes_read
;
9183 struct attribute attr
;
9184 bfd
*abfd
= reader
->abfd
;
9185 struct dwarf2_cu
*cu
= reader
->cu
;
9186 const gdb_byte
*buffer
= reader
->buffer
;
9187 const gdb_byte
*buffer_end
= reader
->buffer_end
;
9188 unsigned int form
, i
;
9190 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
9192 /* The only abbrev we care about is DW_AT_sibling. */
9193 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
9195 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
9196 if (attr
.form
== DW_FORM_ref_addr
)
9197 complaint (&symfile_complaints
,
9198 _("ignoring absolute DW_AT_sibling"));
9201 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
9202 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
9204 if (sibling_ptr
< info_ptr
)
9205 complaint (&symfile_complaints
,
9206 _("DW_AT_sibling points backwards"));
9207 else if (sibling_ptr
> reader
->buffer_end
)
9208 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
9214 /* If it isn't DW_AT_sibling, skip this attribute. */
9215 form
= abbrev
->attrs
[i
].form
;
9219 case DW_FORM_ref_addr
:
9220 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
9221 and later it is offset sized. */
9222 if (cu
->header
.version
== 2)
9223 info_ptr
+= cu
->header
.addr_size
;
9225 info_ptr
+= cu
->header
.offset_size
;
9227 case DW_FORM_GNU_ref_alt
:
9228 info_ptr
+= cu
->header
.offset_size
;
9231 info_ptr
+= cu
->header
.addr_size
;
9238 case DW_FORM_flag_present
:
9239 case DW_FORM_implicit_const
:
9251 case DW_FORM_ref_sig8
:
9254 case DW_FORM_data16
:
9257 case DW_FORM_string
:
9258 read_direct_string (abfd
, info_ptr
, &bytes_read
);
9259 info_ptr
+= bytes_read
;
9261 case DW_FORM_sec_offset
:
9263 case DW_FORM_GNU_strp_alt
:
9264 info_ptr
+= cu
->header
.offset_size
;
9266 case DW_FORM_exprloc
:
9268 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9269 info_ptr
+= bytes_read
;
9271 case DW_FORM_block1
:
9272 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
9274 case DW_FORM_block2
:
9275 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
9277 case DW_FORM_block4
:
9278 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
9282 case DW_FORM_ref_udata
:
9283 case DW_FORM_GNU_addr_index
:
9284 case DW_FORM_GNU_str_index
:
9285 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
9287 case DW_FORM_indirect
:
9288 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9289 info_ptr
+= bytes_read
;
9290 /* We need to continue parsing from here, so just go back to
9292 goto skip_attribute
;
9295 error (_("Dwarf Error: Cannot handle %s "
9296 "in DWARF reader [in module %s]"),
9297 dwarf_form_name (form
),
9298 bfd_get_filename (abfd
));
9302 if (abbrev
->has_children
)
9303 return skip_children (reader
, info_ptr
);
9308 /* Locate ORIG_PDI's sibling.
9309 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
9311 static const gdb_byte
*
9312 locate_pdi_sibling (const struct die_reader_specs
*reader
,
9313 struct partial_die_info
*orig_pdi
,
9314 const gdb_byte
*info_ptr
)
9316 /* Do we know the sibling already? */
9318 if (orig_pdi
->sibling
)
9319 return orig_pdi
->sibling
;
9321 /* Are there any children to deal with? */
9323 if (!orig_pdi
->has_children
)
9326 /* Skip the children the long way. */
9328 return skip_children (reader
, info_ptr
);
9331 /* Expand this partial symbol table into a full symbol table. SELF is
9335 dwarf2_read_symtab (struct partial_symtab
*self
,
9336 struct objfile
*objfile
)
9338 struct dwarf2_per_objfile
*dwarf2_per_objfile
9339 = get_dwarf2_per_objfile (objfile
);
9343 warning (_("bug: psymtab for %s is already read in."),
9350 printf_filtered (_("Reading in symbols for %s..."),
9352 gdb_flush (gdb_stdout
);
9355 /* If this psymtab is constructed from a debug-only objfile, the
9356 has_section_at_zero flag will not necessarily be correct. We
9357 can get the correct value for this flag by looking at the data
9358 associated with the (presumably stripped) associated objfile. */
9359 if (objfile
->separate_debug_objfile_backlink
)
9361 struct dwarf2_per_objfile
*dpo_backlink
9362 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
9364 dwarf2_per_objfile
->has_section_at_zero
9365 = dpo_backlink
->has_section_at_zero
;
9368 dwarf2_per_objfile
->reading_partial_symbols
= 0;
9370 psymtab_to_symtab_1 (self
);
9372 /* Finish up the debug error message. */
9374 printf_filtered (_("done.\n"));
9377 process_cu_includes (dwarf2_per_objfile
);
9380 /* Reading in full CUs. */
9382 /* Add PER_CU to the queue. */
9385 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9386 enum language pretend_language
)
9388 struct dwarf2_queue_item
*item
;
9391 item
= XNEW (struct dwarf2_queue_item
);
9392 item
->per_cu
= per_cu
;
9393 item
->pretend_language
= pretend_language
;
9396 if (dwarf2_queue
== NULL
)
9397 dwarf2_queue
= item
;
9399 dwarf2_queue_tail
->next
= item
;
9401 dwarf2_queue_tail
= item
;
9404 /* If PER_CU is not yet queued, add it to the queue.
9405 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9407 The result is non-zero if PER_CU was queued, otherwise the result is zero
9408 meaning either PER_CU is already queued or it is already loaded.
9410 N.B. There is an invariant here that if a CU is queued then it is loaded.
9411 The caller is required to load PER_CU if we return non-zero. */
9414 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9415 struct dwarf2_per_cu_data
*per_cu
,
9416 enum language pretend_language
)
9418 /* We may arrive here during partial symbol reading, if we need full
9419 DIEs to process an unusual case (e.g. template arguments). Do
9420 not queue PER_CU, just tell our caller to load its DIEs. */
9421 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
9423 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
9428 /* Mark the dependence relation so that we don't flush PER_CU
9430 if (dependent_cu
!= NULL
)
9431 dwarf2_add_dependence (dependent_cu
, per_cu
);
9433 /* If it's already on the queue, we have nothing to do. */
9437 /* If the compilation unit is already loaded, just mark it as
9439 if (per_cu
->cu
!= NULL
)
9441 per_cu
->cu
->last_used
= 0;
9445 /* Add it to the queue. */
9446 queue_comp_unit (per_cu
, pretend_language
);
9451 /* Process the queue. */
9454 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9456 struct dwarf2_queue_item
*item
, *next_item
;
9458 if (dwarf_read_debug
)
9460 fprintf_unfiltered (gdb_stdlog
,
9461 "Expanding one or more symtabs of objfile %s ...\n",
9462 objfile_name (dwarf2_per_objfile
->objfile
));
9465 /* The queue starts out with one item, but following a DIE reference
9466 may load a new CU, adding it to the end of the queue. */
9467 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
9469 if ((dwarf2_per_objfile
->using_index
9470 ? !item
->per_cu
->v
.quick
->compunit_symtab
9471 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
9472 /* Skip dummy CUs. */
9473 && item
->per_cu
->cu
!= NULL
)
9475 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
9476 unsigned int debug_print_threshold
;
9479 if (per_cu
->is_debug_types
)
9481 struct signatured_type
*sig_type
=
9482 (struct signatured_type
*) per_cu
;
9484 sprintf (buf
, "TU %s at offset %s",
9485 hex_string (sig_type
->signature
),
9486 sect_offset_str (per_cu
->sect_off
));
9487 /* There can be 100s of TUs.
9488 Only print them in verbose mode. */
9489 debug_print_threshold
= 2;
9493 sprintf (buf
, "CU at offset %s",
9494 sect_offset_str (per_cu
->sect_off
));
9495 debug_print_threshold
= 1;
9498 if (dwarf_read_debug
>= debug_print_threshold
)
9499 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9501 if (per_cu
->is_debug_types
)
9502 process_full_type_unit (per_cu
, item
->pretend_language
);
9504 process_full_comp_unit (per_cu
, item
->pretend_language
);
9506 if (dwarf_read_debug
>= debug_print_threshold
)
9507 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9510 item
->per_cu
->queued
= 0;
9511 next_item
= item
->next
;
9515 dwarf2_queue_tail
= NULL
;
9517 if (dwarf_read_debug
)
9519 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9520 objfile_name (dwarf2_per_objfile
->objfile
));
9524 /* Read in full symbols for PST, and anything it depends on. */
9527 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
9529 struct dwarf2_per_cu_data
*per_cu
;
9535 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
9536 if (!pst
->dependencies
[i
]->readin
9537 && pst
->dependencies
[i
]->user
== NULL
)
9539 /* Inform about additional files that need to be read in. */
9542 /* FIXME: i18n: Need to make this a single string. */
9543 fputs_filtered (" ", gdb_stdout
);
9545 fputs_filtered ("and ", gdb_stdout
);
9547 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
9548 wrap_here (""); /* Flush output. */
9549 gdb_flush (gdb_stdout
);
9551 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
9554 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
9558 /* It's an include file, no symbols to read for it.
9559 Everything is in the parent symtab. */
9564 dw2_do_instantiate_symtab (per_cu
, false);
9567 /* Trivial hash function for die_info: the hash value of a DIE
9568 is its offset in .debug_info for this objfile. */
9571 die_hash (const void *item
)
9573 const struct die_info
*die
= (const struct die_info
*) item
;
9575 return to_underlying (die
->sect_off
);
9578 /* Trivial comparison function for die_info structures: two DIEs
9579 are equal if they have the same offset. */
9582 die_eq (const void *item_lhs
, const void *item_rhs
)
9584 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9585 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9587 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9590 /* die_reader_func for load_full_comp_unit.
9591 This is identical to read_signatured_type_reader,
9592 but is kept separate for now. */
9595 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
9596 const gdb_byte
*info_ptr
,
9597 struct die_info
*comp_unit_die
,
9601 struct dwarf2_cu
*cu
= reader
->cu
;
9602 enum language
*language_ptr
= (enum language
*) data
;
9604 gdb_assert (cu
->die_hash
== NULL
);
9606 htab_create_alloc_ex (cu
->header
.length
/ 12,
9610 &cu
->comp_unit_obstack
,
9611 hashtab_obstack_allocate
,
9612 dummy_obstack_deallocate
);
9615 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
9616 &info_ptr
, comp_unit_die
);
9617 cu
->dies
= comp_unit_die
;
9618 /* comp_unit_die is not stored in die_hash, no need. */
9620 /* We try not to read any attributes in this function, because not
9621 all CUs needed for references have been loaded yet, and symbol
9622 table processing isn't initialized. But we have to set the CU language,
9623 or we won't be able to build types correctly.
9624 Similarly, if we do not read the producer, we can not apply
9625 producer-specific interpretation. */
9626 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
9629 /* Load the DIEs associated with PER_CU into memory. */
9632 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
9634 enum language pretend_language
)
9636 gdb_assert (! this_cu
->is_debug_types
);
9638 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1, skip_partial
,
9639 load_full_comp_unit_reader
, &pretend_language
);
9642 /* Add a DIE to the delayed physname list. */
9645 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9646 const char *name
, struct die_info
*die
,
9647 struct dwarf2_cu
*cu
)
9649 struct delayed_method_info mi
;
9651 mi
.fnfield_index
= fnfield_index
;
9655 cu
->method_list
.push_back (mi
);
9658 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9659 "const" / "volatile". If so, decrements LEN by the length of the
9660 modifier and return true. Otherwise return false. */
9664 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9666 size_t mod_len
= sizeof (mod
) - 1;
9667 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9675 /* Compute the physnames of any methods on the CU's method list.
9677 The computation of method physnames is delayed in order to avoid the
9678 (bad) condition that one of the method's formal parameters is of an as yet
9682 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9684 /* Only C++ delays computing physnames. */
9685 if (cu
->method_list
.empty ())
9687 gdb_assert (cu
->language
== language_cplus
);
9689 for (struct delayed_method_info
&mi
: cu
->method_list
)
9691 const char *physname
;
9692 struct fn_fieldlist
*fn_flp
9693 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9694 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9695 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9696 = physname
? physname
: "";
9698 /* Since there's no tag to indicate whether a method is a
9699 const/volatile overload, extract that information out of the
9701 if (physname
!= NULL
)
9703 size_t len
= strlen (physname
);
9707 if (physname
[len
] == ')') /* shortcut */
9709 else if (check_modifier (physname
, len
, " const"))
9710 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9711 else if (check_modifier (physname
, len
, " volatile"))
9712 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9719 /* The list is no longer needed. */
9720 cu
->method_list
.clear ();
9723 /* Go objects should be embedded in a DW_TAG_module DIE,
9724 and it's not clear if/how imported objects will appear.
9725 To keep Go support simple until that's worked out,
9726 go back through what we've read and create something usable.
9727 We could do this while processing each DIE, and feels kinda cleaner,
9728 but that way is more invasive.
9729 This is to, for example, allow the user to type "p var" or "b main"
9730 without having to specify the package name, and allow lookups
9731 of module.object to work in contexts that use the expression
9735 fixup_go_packaging (struct dwarf2_cu
*cu
)
9737 char *package_name
= NULL
;
9738 struct pending
*list
;
9741 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
9743 for (i
= 0; i
< list
->nsyms
; ++i
)
9745 struct symbol
*sym
= list
->symbol
[i
];
9747 if (SYMBOL_LANGUAGE (sym
) == language_go
9748 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9750 char *this_package_name
= go_symbol_package_name (sym
);
9752 if (this_package_name
== NULL
)
9754 if (package_name
== NULL
)
9755 package_name
= this_package_name
;
9758 struct objfile
*objfile
9759 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9760 if (strcmp (package_name
, this_package_name
) != 0)
9761 complaint (&symfile_complaints
,
9762 _("Symtab %s has objects from two different Go packages: %s and %s"),
9763 (symbol_symtab (sym
) != NULL
9764 ? symtab_to_filename_for_display
9765 (symbol_symtab (sym
))
9766 : objfile_name (objfile
)),
9767 this_package_name
, package_name
);
9768 xfree (this_package_name
);
9774 if (package_name
!= NULL
)
9776 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9777 const char *saved_package_name
9778 = (const char *) obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
9780 strlen (package_name
));
9781 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9782 saved_package_name
);
9785 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
9787 sym
= allocate_symbol (objfile
);
9788 SYMBOL_SET_LANGUAGE (sym
, language_go
, &objfile
->objfile_obstack
);
9789 SYMBOL_SET_NAMES (sym
, saved_package_name
,
9790 strlen (saved_package_name
), 0, objfile
);
9791 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9792 e.g., "main" finds the "main" module and not C's main(). */
9793 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9794 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9795 SYMBOL_TYPE (sym
) = type
;
9797 add_symbol_to_list (sym
, &global_symbols
);
9799 xfree (package_name
);
9803 /* Allocate a fully-qualified name consisting of the two parts on the
9807 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9809 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9812 /* A helper that allocates a struct discriminant_info to attach to a
9815 static struct discriminant_info
*
9816 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9819 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9820 gdb_assert (discriminant_index
== -1
9821 || (discriminant_index
>= 0
9822 && discriminant_index
< TYPE_NFIELDS (type
)));
9823 gdb_assert (default_index
== -1
9824 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9826 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9828 struct discriminant_info
*disc
9829 = ((struct discriminant_info
*)
9831 offsetof (struct discriminant_info
, discriminants
)
9832 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9833 disc
->default_index
= default_index
;
9834 disc
->discriminant_index
= discriminant_index
;
9836 struct dynamic_prop prop
;
9837 prop
.kind
= PROP_UNDEFINED
;
9838 prop
.data
.baton
= disc
;
9840 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9845 /* Some versions of rustc emitted enums in an unusual way.
9847 Ordinary enums were emitted as unions. The first element of each
9848 structure in the union was named "RUST$ENUM$DISR". This element
9849 held the discriminant.
9851 These versions of Rust also implemented the "non-zero"
9852 optimization. When the enum had two values, and one is empty and
9853 the other holds a pointer that cannot be zero, the pointer is used
9854 as the discriminant, with a zero value meaning the empty variant.
9855 Here, the union's first member is of the form
9856 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9857 where the fieldnos are the indices of the fields that should be
9858 traversed in order to find the field (which may be several fields deep)
9859 and the variantname is the name of the variant of the case when the
9862 This function recognizes whether TYPE is of one of these forms,
9863 and, if so, smashes it to be a variant type. */
9866 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9868 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9870 /* We don't need to deal with empty enums. */
9871 if (TYPE_NFIELDS (type
) == 0)
9874 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9875 if (TYPE_NFIELDS (type
) == 1
9876 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9878 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9880 /* Decode the field name to find the offset of the
9882 ULONGEST bit_offset
= 0;
9883 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9884 while (name
[0] >= '0' && name
[0] <= '9')
9887 unsigned long index
= strtoul (name
, &tail
, 10);
9890 || index
>= TYPE_NFIELDS (field_type
)
9891 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9892 != FIELD_LOC_KIND_BITPOS
))
9894 complaint (&symfile_complaints
,
9895 _("Could not parse Rust enum encoding string \"%s\""
9897 TYPE_FIELD_NAME (type
, 0),
9898 objfile_name (objfile
));
9903 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9904 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9907 /* Make a union to hold the variants. */
9908 struct type
*union_type
= alloc_type (objfile
);
9909 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9910 TYPE_NFIELDS (union_type
) = 3;
9911 TYPE_FIELDS (union_type
)
9912 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
9913 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9914 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9916 /* Put the discriminant must at index 0. */
9917 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
9918 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9919 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9920 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
9922 /* The order of fields doesn't really matter, so put the real
9923 field at index 1 and the data-less field at index 2. */
9924 struct discriminant_info
*disc
9925 = alloc_discriminant_info (union_type
, 0, 1);
9926 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
9927 TYPE_FIELD_NAME (union_type
, 1)
9928 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
9929 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
9930 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9931 TYPE_FIELD_NAME (union_type
, 1));
9933 const char *dataless_name
9934 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9936 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9938 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
9939 /* NAME points into the original discriminant name, which
9940 already has the correct lifetime. */
9941 TYPE_FIELD_NAME (union_type
, 2) = name
;
9942 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
9943 disc
->discriminants
[2] = 0;
9945 /* Smash this type to be a structure type. We have to do this
9946 because the type has already been recorded. */
9947 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9948 TYPE_NFIELDS (type
) = 1;
9950 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
9952 /* Install the variant part. */
9953 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9954 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9955 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9957 else if (TYPE_NFIELDS (type
) == 1)
9959 /* We assume that a union with a single field is a univariant
9961 /* Smash this type to be a structure type. We have to do this
9962 because the type has already been recorded. */
9963 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9965 /* Make a union to hold the variants. */
9966 struct type
*union_type
= alloc_type (objfile
);
9967 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9968 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
9969 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9970 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9971 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
9973 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
9974 const char *variant_name
9975 = rust_last_path_segment (TYPE_NAME (field_type
));
9976 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
9977 TYPE_NAME (field_type
)
9978 = rust_fully_qualify (&objfile
->objfile_obstack
,
9979 TYPE_NAME (type
), variant_name
);
9981 /* Install the union in the outer struct type. */
9982 TYPE_NFIELDS (type
) = 1;
9984 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
9985 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9986 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9987 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9989 alloc_discriminant_info (union_type
, -1, 0);
9993 struct type
*disr_type
= nullptr;
9994 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
9996 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9998 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
10000 /* All fields of a true enum will be structs. */
10003 else if (TYPE_NFIELDS (disr_type
) == 0)
10005 /* Could be data-less variant, so keep going. */
10006 disr_type
= nullptr;
10008 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
10009 "RUST$ENUM$DISR") != 0)
10011 /* Not a Rust enum. */
10021 /* If we got here without a discriminant, then it's probably
10023 if (disr_type
== nullptr)
10026 /* Smash this type to be a structure type. We have to do this
10027 because the type has already been recorded. */
10028 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10030 /* Make a union to hold the variants. */
10031 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
10032 struct type
*union_type
= alloc_type (objfile
);
10033 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10034 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
10035 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10036 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10037 TYPE_FIELDS (union_type
)
10038 = (struct field
*) TYPE_ZALLOC (union_type
,
10039 (TYPE_NFIELDS (union_type
)
10040 * sizeof (struct field
)));
10042 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
10043 TYPE_NFIELDS (type
) * sizeof (struct field
));
10045 /* Install the discriminant at index 0 in the union. */
10046 TYPE_FIELD (union_type
, 0) = *disr_field
;
10047 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10048 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10050 /* Install the union in the outer struct type. */
10051 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10052 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10053 TYPE_NFIELDS (type
) = 1;
10055 /* Set the size and offset of the union type. */
10056 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10058 /* We need a way to find the correct discriminant given a
10059 variant name. For convenience we build a map here. */
10060 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
10061 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
10062 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
10064 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
10067 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
10068 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
10072 int n_fields
= TYPE_NFIELDS (union_type
);
10073 struct discriminant_info
*disc
10074 = alloc_discriminant_info (union_type
, 0, -1);
10075 /* Skip the discriminant here. */
10076 for (int i
= 1; i
< n_fields
; ++i
)
10078 /* Find the final word in the name of this variant's type.
10079 That name can be used to look up the correct
10081 const char *variant_name
10082 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
10085 auto iter
= discriminant_map
.find (variant_name
);
10086 if (iter
!= discriminant_map
.end ())
10087 disc
->discriminants
[i
] = iter
->second
;
10089 /* Remove the discriminant field, if it exists. */
10090 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
10091 if (TYPE_NFIELDS (sub_type
) > 0)
10093 --TYPE_NFIELDS (sub_type
);
10094 ++TYPE_FIELDS (sub_type
);
10096 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
10097 TYPE_NAME (sub_type
)
10098 = rust_fully_qualify (&objfile
->objfile_obstack
,
10099 TYPE_NAME (type
), variant_name
);
10104 /* Rewrite some Rust unions to be structures with variants parts. */
10107 rust_union_quirks (struct dwarf2_cu
*cu
)
10109 gdb_assert (cu
->language
== language_rust
);
10110 for (struct type
*type
: cu
->rust_unions
)
10111 quirk_rust_enum (type
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
10112 /* We don't need this any more. */
10113 cu
->rust_unions
.clear ();
10116 /* Return the symtab for PER_CU. This works properly regardless of
10117 whether we're using the index or psymtabs. */
10119 static struct compunit_symtab
*
10120 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
10122 return (per_cu
->dwarf2_per_objfile
->using_index
10123 ? per_cu
->v
.quick
->compunit_symtab
10124 : per_cu
->v
.psymtab
->compunit_symtab
);
10127 /* A helper function for computing the list of all symbol tables
10128 included by PER_CU. */
10131 recursively_compute_inclusions (VEC (compunit_symtab_ptr
) **result
,
10132 htab_t all_children
, htab_t all_type_symtabs
,
10133 struct dwarf2_per_cu_data
*per_cu
,
10134 struct compunit_symtab
*immediate_parent
)
10138 struct compunit_symtab
*cust
;
10139 struct dwarf2_per_cu_data
*iter
;
10141 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
10144 /* This inclusion and its children have been processed. */
10149 /* Only add a CU if it has a symbol table. */
10150 cust
= get_compunit_symtab (per_cu
);
10153 /* If this is a type unit only add its symbol table if we haven't
10154 seen it yet (type unit per_cu's can share symtabs). */
10155 if (per_cu
->is_debug_types
)
10157 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
10161 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
10162 if (cust
->user
== NULL
)
10163 cust
->user
= immediate_parent
;
10168 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
10169 if (cust
->user
== NULL
)
10170 cust
->user
= immediate_parent
;
10175 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, ix
, iter
);
10178 recursively_compute_inclusions (result
, all_children
,
10179 all_type_symtabs
, iter
, cust
);
10183 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
10187 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
10189 gdb_assert (! per_cu
->is_debug_types
);
10191 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
))
10194 struct dwarf2_per_cu_data
*per_cu_iter
;
10195 struct compunit_symtab
*compunit_symtab_iter
;
10196 VEC (compunit_symtab_ptr
) *result_symtabs
= NULL
;
10197 htab_t all_children
, all_type_symtabs
;
10198 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
10200 /* If we don't have a symtab, we can just skip this case. */
10204 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10205 NULL
, xcalloc
, xfree
);
10206 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10207 NULL
, xcalloc
, xfree
);
10210 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
,
10214 recursively_compute_inclusions (&result_symtabs
, all_children
,
10215 all_type_symtabs
, per_cu_iter
,
10219 /* Now we have a transitive closure of all the included symtabs. */
10220 len
= VEC_length (compunit_symtab_ptr
, result_symtabs
);
10222 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
10223 struct compunit_symtab
*, len
+ 1);
10225 VEC_iterate (compunit_symtab_ptr
, result_symtabs
, ix
,
10226 compunit_symtab_iter
);
10228 cust
->includes
[ix
] = compunit_symtab_iter
;
10229 cust
->includes
[len
] = NULL
;
10231 VEC_free (compunit_symtab_ptr
, result_symtabs
);
10232 htab_delete (all_children
);
10233 htab_delete (all_type_symtabs
);
10237 /* Compute the 'includes' field for the symtabs of all the CUs we just
10241 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
10244 struct dwarf2_per_cu_data
*iter
;
10247 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
10251 if (! iter
->is_debug_types
)
10252 compute_compunit_symtab_includes (iter
);
10255 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
10258 /* Generate full symbol information for PER_CU, whose DIEs have
10259 already been loaded into memory. */
10262 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
10263 enum language pretend_language
)
10265 struct dwarf2_cu
*cu
= per_cu
->cu
;
10266 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10267 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10268 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10269 CORE_ADDR lowpc
, highpc
;
10270 struct compunit_symtab
*cust
;
10271 CORE_ADDR baseaddr
;
10272 struct block
*static_block
;
10275 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10278 scoped_free_pendings free_pending
;
10280 /* Clear the list here in case something was left over. */
10281 cu
->method_list
.clear ();
10283 cu
->list_in_scope
= &file_symbols
;
10285 cu
->language
= pretend_language
;
10286 cu
->language_defn
= language_def (cu
->language
);
10288 /* Do line number decoding in read_file_scope () */
10289 process_die (cu
->dies
, cu
);
10291 /* For now fudge the Go package. */
10292 if (cu
->language
== language_go
)
10293 fixup_go_packaging (cu
);
10295 /* Now that we have processed all the DIEs in the CU, all the types
10296 should be complete, and it should now be safe to compute all of the
10298 compute_delayed_physnames (cu
);
10300 if (cu
->language
== language_rust
)
10301 rust_union_quirks (cu
);
10303 /* Some compilers don't define a DW_AT_high_pc attribute for the
10304 compilation unit. If the DW_AT_high_pc is missing, synthesize
10305 it, by scanning the DIE's below the compilation unit. */
10306 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
10308 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
10309 static_block
= end_symtab_get_static_block (addr
, 0, 1);
10311 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
10312 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
10313 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
10314 addrmap to help ensure it has an accurate map of pc values belonging to
10316 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
10318 cust
= end_symtab_from_static_block (static_block
,
10319 SECT_OFF_TEXT (objfile
), 0);
10323 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
10325 /* Set symtab language to language from DW_AT_language. If the
10326 compilation is from a C file generated by language preprocessors, do
10327 not set the language if it was already deduced by start_subfile. */
10328 if (!(cu
->language
== language_c
10329 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
10330 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10332 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
10333 produce DW_AT_location with location lists but it can be possibly
10334 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
10335 there were bugs in prologue debug info, fixed later in GCC-4.5
10336 by "unwind info for epilogues" patch (which is not directly related).
10338 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
10339 needed, it would be wrong due to missing DW_AT_producer there.
10341 Still one can confuse GDB by using non-standard GCC compilation
10342 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
10344 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
10345 cust
->locations_valid
= 1;
10347 if (gcc_4_minor
>= 5)
10348 cust
->epilogue_unwind_valid
= 1;
10350 cust
->call_site_htab
= cu
->call_site_htab
;
10353 if (dwarf2_per_objfile
->using_index
)
10354 per_cu
->v
.quick
->compunit_symtab
= cust
;
10357 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10358 pst
->compunit_symtab
= cust
;
10362 /* Push it for inclusion processing later. */
10363 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
10366 /* Generate full symbol information for type unit PER_CU, whose DIEs have
10367 already been loaded into memory. */
10370 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
10371 enum language pretend_language
)
10373 struct dwarf2_cu
*cu
= per_cu
->cu
;
10374 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10375 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10376 struct compunit_symtab
*cust
;
10377 struct signatured_type
*sig_type
;
10379 gdb_assert (per_cu
->is_debug_types
);
10380 sig_type
= (struct signatured_type
*) per_cu
;
10383 scoped_free_pendings free_pending
;
10385 /* Clear the list here in case something was left over. */
10386 cu
->method_list
.clear ();
10388 cu
->list_in_scope
= &file_symbols
;
10390 cu
->language
= pretend_language
;
10391 cu
->language_defn
= language_def (cu
->language
);
10393 /* The symbol tables are set up in read_type_unit_scope. */
10394 process_die (cu
->dies
, cu
);
10396 /* For now fudge the Go package. */
10397 if (cu
->language
== language_go
)
10398 fixup_go_packaging (cu
);
10400 /* Now that we have processed all the DIEs in the CU, all the types
10401 should be complete, and it should now be safe to compute all of the
10403 compute_delayed_physnames (cu
);
10405 if (cu
->language
== language_rust
)
10406 rust_union_quirks (cu
);
10408 /* TUs share symbol tables.
10409 If this is the first TU to use this symtab, complete the construction
10410 of it with end_expandable_symtab. Otherwise, complete the addition of
10411 this TU's symbols to the existing symtab. */
10412 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
10414 cust
= end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10415 sig_type
->type_unit_group
->compunit_symtab
= cust
;
10419 /* Set symtab language to language from DW_AT_language. If the
10420 compilation is from a C file generated by language preprocessors,
10421 do not set the language if it was already deduced by
10423 if (!(cu
->language
== language_c
10424 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10425 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10430 augment_type_symtab ();
10431 cust
= sig_type
->type_unit_group
->compunit_symtab
;
10434 if (dwarf2_per_objfile
->using_index
)
10435 per_cu
->v
.quick
->compunit_symtab
= cust
;
10438 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10439 pst
->compunit_symtab
= cust
;
10444 /* Process an imported unit DIE. */
10447 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10449 struct attribute
*attr
;
10451 /* For now we don't handle imported units in type units. */
10452 if (cu
->per_cu
->is_debug_types
)
10454 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10455 " supported in type units [in module %s]"),
10456 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
10459 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10462 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10463 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10464 dwarf2_per_cu_data
*per_cu
10465 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
10466 cu
->per_cu
->dwarf2_per_objfile
);
10468 /* If necessary, add it to the queue and load its DIEs. */
10469 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
10470 load_full_comp_unit (per_cu
, false, cu
->language
);
10472 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
10477 /* RAII object that represents a process_die scope: i.e.,
10478 starts/finishes processing a DIE. */
10479 class process_die_scope
10482 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10483 : m_die (die
), m_cu (cu
)
10485 /* We should only be processing DIEs not already in process. */
10486 gdb_assert (!m_die
->in_process
);
10487 m_die
->in_process
= true;
10490 ~process_die_scope ()
10492 m_die
->in_process
= false;
10494 /* If we're done processing the DIE for the CU that owns the line
10495 header, we don't need the line header anymore. */
10496 if (m_cu
->line_header_die_owner
== m_die
)
10498 delete m_cu
->line_header
;
10499 m_cu
->line_header
= NULL
;
10500 m_cu
->line_header_die_owner
= NULL
;
10509 /* Process a die and its children. */
10512 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10514 process_die_scope
scope (die
, cu
);
10518 case DW_TAG_padding
:
10520 case DW_TAG_compile_unit
:
10521 case DW_TAG_partial_unit
:
10522 read_file_scope (die
, cu
);
10524 case DW_TAG_type_unit
:
10525 read_type_unit_scope (die
, cu
);
10527 case DW_TAG_subprogram
:
10528 case DW_TAG_inlined_subroutine
:
10529 read_func_scope (die
, cu
);
10531 case DW_TAG_lexical_block
:
10532 case DW_TAG_try_block
:
10533 case DW_TAG_catch_block
:
10534 read_lexical_block_scope (die
, cu
);
10536 case DW_TAG_call_site
:
10537 case DW_TAG_GNU_call_site
:
10538 read_call_site_scope (die
, cu
);
10540 case DW_TAG_class_type
:
10541 case DW_TAG_interface_type
:
10542 case DW_TAG_structure_type
:
10543 case DW_TAG_union_type
:
10544 process_structure_scope (die
, cu
);
10546 case DW_TAG_enumeration_type
:
10547 process_enumeration_scope (die
, cu
);
10550 /* These dies have a type, but processing them does not create
10551 a symbol or recurse to process the children. Therefore we can
10552 read them on-demand through read_type_die. */
10553 case DW_TAG_subroutine_type
:
10554 case DW_TAG_set_type
:
10555 case DW_TAG_array_type
:
10556 case DW_TAG_pointer_type
:
10557 case DW_TAG_ptr_to_member_type
:
10558 case DW_TAG_reference_type
:
10559 case DW_TAG_rvalue_reference_type
:
10560 case DW_TAG_string_type
:
10563 case DW_TAG_base_type
:
10564 case DW_TAG_subrange_type
:
10565 case DW_TAG_typedef
:
10566 /* Add a typedef symbol for the type definition, if it has a
10568 new_symbol (die
, read_type_die (die
, cu
), cu
);
10570 case DW_TAG_common_block
:
10571 read_common_block (die
, cu
);
10573 case DW_TAG_common_inclusion
:
10575 case DW_TAG_namespace
:
10576 cu
->processing_has_namespace_info
= 1;
10577 read_namespace (die
, cu
);
10579 case DW_TAG_module
:
10580 cu
->processing_has_namespace_info
= 1;
10581 read_module (die
, cu
);
10583 case DW_TAG_imported_declaration
:
10584 cu
->processing_has_namespace_info
= 1;
10585 if (read_namespace_alias (die
, cu
))
10587 /* The declaration is not a global namespace alias. */
10588 /* Fall through. */
10589 case DW_TAG_imported_module
:
10590 cu
->processing_has_namespace_info
= 1;
10591 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10592 || cu
->language
!= language_fortran
))
10593 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
10594 dwarf_tag_name (die
->tag
));
10595 read_import_statement (die
, cu
);
10598 case DW_TAG_imported_unit
:
10599 process_imported_unit_die (die
, cu
);
10602 case DW_TAG_variable
:
10603 read_variable (die
, cu
);
10607 new_symbol (die
, NULL
, cu
);
10612 /* DWARF name computation. */
10614 /* A helper function for dwarf2_compute_name which determines whether DIE
10615 needs to have the name of the scope prepended to the name listed in the
10619 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10621 struct attribute
*attr
;
10625 case DW_TAG_namespace
:
10626 case DW_TAG_typedef
:
10627 case DW_TAG_class_type
:
10628 case DW_TAG_interface_type
:
10629 case DW_TAG_structure_type
:
10630 case DW_TAG_union_type
:
10631 case DW_TAG_enumeration_type
:
10632 case DW_TAG_enumerator
:
10633 case DW_TAG_subprogram
:
10634 case DW_TAG_inlined_subroutine
:
10635 case DW_TAG_member
:
10636 case DW_TAG_imported_declaration
:
10639 case DW_TAG_variable
:
10640 case DW_TAG_constant
:
10641 /* We only need to prefix "globally" visible variables. These include
10642 any variable marked with DW_AT_external or any variable that
10643 lives in a namespace. [Variables in anonymous namespaces
10644 require prefixing, but they are not DW_AT_external.] */
10646 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10648 struct dwarf2_cu
*spec_cu
= cu
;
10650 return die_needs_namespace (die_specification (die
, &spec_cu
),
10654 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10655 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10656 && die
->parent
->tag
!= DW_TAG_module
)
10658 /* A variable in a lexical block of some kind does not need a
10659 namespace, even though in C++ such variables may be external
10660 and have a mangled name. */
10661 if (die
->parent
->tag
== DW_TAG_lexical_block
10662 || die
->parent
->tag
== DW_TAG_try_block
10663 || die
->parent
->tag
== DW_TAG_catch_block
10664 || die
->parent
->tag
== DW_TAG_subprogram
)
10673 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10674 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10675 defined for the given DIE. */
10677 static struct attribute
*
10678 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10680 struct attribute
*attr
;
10682 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10684 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10689 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10690 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10691 defined for the given DIE. */
10693 static const char *
10694 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10696 const char *linkage_name
;
10698 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10699 if (linkage_name
== NULL
)
10700 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10702 return linkage_name
;
10705 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10706 compute the physname for the object, which include a method's:
10707 - formal parameters (C++),
10708 - receiver type (Go),
10710 The term "physname" is a bit confusing.
10711 For C++, for example, it is the demangled name.
10712 For Go, for example, it's the mangled name.
10714 For Ada, return the DIE's linkage name rather than the fully qualified
10715 name. PHYSNAME is ignored..
10717 The result is allocated on the objfile_obstack and canonicalized. */
10719 static const char *
10720 dwarf2_compute_name (const char *name
,
10721 struct die_info
*die
, struct dwarf2_cu
*cu
,
10724 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10727 name
= dwarf2_name (die
, cu
);
10729 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10730 but otherwise compute it by typename_concat inside GDB.
10731 FIXME: Actually this is not really true, or at least not always true.
10732 It's all very confusing. SYMBOL_SET_NAMES doesn't try to demangle
10733 Fortran names because there is no mangling standard. So new_symbol
10734 will set the demangled name to the result of dwarf2_full_name, and it is
10735 the demangled name that GDB uses if it exists. */
10736 if (cu
->language
== language_ada
10737 || (cu
->language
== language_fortran
&& physname
))
10739 /* For Ada unit, we prefer the linkage name over the name, as
10740 the former contains the exported name, which the user expects
10741 to be able to reference. Ideally, we want the user to be able
10742 to reference this entity using either natural or linkage name,
10743 but we haven't started looking at this enhancement yet. */
10744 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10746 if (linkage_name
!= NULL
)
10747 return linkage_name
;
10750 /* These are the only languages we know how to qualify names in. */
10752 && (cu
->language
== language_cplus
10753 || cu
->language
== language_fortran
|| cu
->language
== language_d
10754 || cu
->language
== language_rust
))
10756 if (die_needs_namespace (die
, cu
))
10758 const char *prefix
;
10759 const char *canonical_name
= NULL
;
10763 prefix
= determine_prefix (die
, cu
);
10764 if (*prefix
!= '\0')
10766 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
10769 buf
.puts (prefixed_name
);
10770 xfree (prefixed_name
);
10775 /* Template parameters may be specified in the DIE's DW_AT_name, or
10776 as children with DW_TAG_template_type_param or
10777 DW_TAG_value_type_param. If the latter, add them to the name
10778 here. If the name already has template parameters, then
10779 skip this step; some versions of GCC emit both, and
10780 it is more efficient to use the pre-computed name.
10782 Something to keep in mind about this process: it is very
10783 unlikely, or in some cases downright impossible, to produce
10784 something that will match the mangled name of a function.
10785 If the definition of the function has the same debug info,
10786 we should be able to match up with it anyway. But fallbacks
10787 using the minimal symbol, for instance to find a method
10788 implemented in a stripped copy of libstdc++, will not work.
10789 If we do not have debug info for the definition, we will have to
10790 match them up some other way.
10792 When we do name matching there is a related problem with function
10793 templates; two instantiated function templates are allowed to
10794 differ only by their return types, which we do not add here. */
10796 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10798 struct attribute
*attr
;
10799 struct die_info
*child
;
10802 die
->building_fullname
= 1;
10804 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10808 const gdb_byte
*bytes
;
10809 struct dwarf2_locexpr_baton
*baton
;
10812 if (child
->tag
!= DW_TAG_template_type_param
10813 && child
->tag
!= DW_TAG_template_value_param
)
10824 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10827 complaint (&symfile_complaints
,
10828 _("template parameter missing DW_AT_type"));
10829 buf
.puts ("UNKNOWN_TYPE");
10832 type
= die_type (child
, cu
);
10834 if (child
->tag
== DW_TAG_template_type_param
)
10836 c_print_type (type
, "", &buf
, -1, 0, &type_print_raw_options
);
10840 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10843 complaint (&symfile_complaints
,
10844 _("template parameter missing "
10845 "DW_AT_const_value"));
10846 buf
.puts ("UNKNOWN_VALUE");
10850 dwarf2_const_value_attr (attr
, type
, name
,
10851 &cu
->comp_unit_obstack
, cu
,
10852 &value
, &bytes
, &baton
);
10854 if (TYPE_NOSIGN (type
))
10855 /* GDB prints characters as NUMBER 'CHAR'. If that's
10856 changed, this can use value_print instead. */
10857 c_printchar (value
, type
, &buf
);
10860 struct value_print_options opts
;
10863 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10867 else if (bytes
!= NULL
)
10869 v
= allocate_value (type
);
10870 memcpy (value_contents_writeable (v
), bytes
,
10871 TYPE_LENGTH (type
));
10874 v
= value_from_longest (type
, value
);
10876 /* Specify decimal so that we do not depend on
10878 get_formatted_print_options (&opts
, 'd');
10880 value_print (v
, &buf
, &opts
);
10885 die
->building_fullname
= 0;
10889 /* Close the argument list, with a space if necessary
10890 (nested templates). */
10891 if (!buf
.empty () && buf
.string ().back () == '>')
10898 /* For C++ methods, append formal parameter type
10899 information, if PHYSNAME. */
10901 if (physname
&& die
->tag
== DW_TAG_subprogram
10902 && cu
->language
== language_cplus
)
10904 struct type
*type
= read_type_die (die
, cu
);
10906 c_type_print_args (type
, &buf
, 1, cu
->language
,
10907 &type_print_raw_options
);
10909 if (cu
->language
== language_cplus
)
10911 /* Assume that an artificial first parameter is
10912 "this", but do not crash if it is not. RealView
10913 marks unnamed (and thus unused) parameters as
10914 artificial; there is no way to differentiate
10916 if (TYPE_NFIELDS (type
) > 0
10917 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10918 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
10919 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10921 buf
.puts (" const");
10925 const std::string
&intermediate_name
= buf
.string ();
10927 if (cu
->language
== language_cplus
)
10929 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10930 &objfile
->per_bfd
->storage_obstack
);
10932 /* If we only computed INTERMEDIATE_NAME, or if
10933 INTERMEDIATE_NAME is already canonical, then we need to
10934 copy it to the appropriate obstack. */
10935 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10936 name
= ((const char *)
10937 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
10938 intermediate_name
.c_str (),
10939 intermediate_name
.length ()));
10941 name
= canonical_name
;
10948 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10949 If scope qualifiers are appropriate they will be added. The result
10950 will be allocated on the storage_obstack, or NULL if the DIE does
10951 not have a name. NAME may either be from a previous call to
10952 dwarf2_name or NULL.
10954 The output string will be canonicalized (if C++). */
10956 static const char *
10957 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10959 return dwarf2_compute_name (name
, die
, cu
, 0);
10962 /* Construct a physname for the given DIE in CU. NAME may either be
10963 from a previous call to dwarf2_name or NULL. The result will be
10964 allocated on the objfile_objstack or NULL if the DIE does not have a
10967 The output string will be canonicalized (if C++). */
10969 static const char *
10970 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10972 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10973 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10976 /* In this case dwarf2_compute_name is just a shortcut not building anything
10978 if (!die_needs_namespace (die
, cu
))
10979 return dwarf2_compute_name (name
, die
, cu
, 1);
10981 mangled
= dw2_linkage_name (die
, cu
);
10983 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10984 See https://github.com/rust-lang/rust/issues/32925. */
10985 if (cu
->language
== language_rust
&& mangled
!= NULL
10986 && strchr (mangled
, '{') != NULL
)
10989 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10991 gdb::unique_xmalloc_ptr
<char> demangled
;
10992 if (mangled
!= NULL
)
10995 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10997 /* Do nothing (do not demangle the symbol name). */
10999 else if (cu
->language
== language_go
)
11001 /* This is a lie, but we already lie to the caller new_symbol.
11002 new_symbol assumes we return the mangled name.
11003 This just undoes that lie until things are cleaned up. */
11007 /* Use DMGL_RET_DROP for C++ template functions to suppress
11008 their return type. It is easier for GDB users to search
11009 for such functions as `name(params)' than `long name(params)'.
11010 In such case the minimal symbol names do not match the full
11011 symbol names but for template functions there is never a need
11012 to look up their definition from their declaration so
11013 the only disadvantage remains the minimal symbol variant
11014 `long name(params)' does not have the proper inferior type. */
11015 demangled
.reset (gdb_demangle (mangled
,
11016 (DMGL_PARAMS
| DMGL_ANSI
11017 | DMGL_RET_DROP
)));
11020 canon
= demangled
.get ();
11028 if (canon
== NULL
|| check_physname
)
11030 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
11032 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
11034 /* It may not mean a bug in GDB. The compiler could also
11035 compute DW_AT_linkage_name incorrectly. But in such case
11036 GDB would need to be bug-to-bug compatible. */
11038 complaint (&symfile_complaints
,
11039 _("Computed physname <%s> does not match demangled <%s> "
11040 "(from linkage <%s>) - DIE at %s [in module %s]"),
11041 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
11042 objfile_name (objfile
));
11044 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
11045 is available here - over computed PHYSNAME. It is safer
11046 against both buggy GDB and buggy compilers. */
11060 retval
= ((const char *)
11061 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
11062 retval
, strlen (retval
)));
11067 /* Inspect DIE in CU for a namespace alias. If one exists, record
11068 a new symbol for it.
11070 Returns 1 if a namespace alias was recorded, 0 otherwise. */
11073 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
11075 struct attribute
*attr
;
11077 /* If the die does not have a name, this is not a namespace
11079 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11083 struct die_info
*d
= die
;
11084 struct dwarf2_cu
*imported_cu
= cu
;
11086 /* If the compiler has nested DW_AT_imported_declaration DIEs,
11087 keep inspecting DIEs until we hit the underlying import. */
11088 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
11089 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
11091 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
11095 d
= follow_die_ref (d
, attr
, &imported_cu
);
11096 if (d
->tag
!= DW_TAG_imported_declaration
)
11100 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
11102 complaint (&symfile_complaints
,
11103 _("DIE at %s has too many recursively imported "
11104 "declarations"), sect_offset_str (d
->sect_off
));
11111 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
11113 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
11114 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
11116 /* This declaration is a global namespace alias. Add
11117 a symbol for it whose type is the aliased namespace. */
11118 new_symbol (die
, type
, cu
);
11127 /* Return the using directives repository (global or local?) to use in the
11128 current context for LANGUAGE.
11130 For Ada, imported declarations can materialize renamings, which *may* be
11131 global. However it is impossible (for now?) in DWARF to distinguish
11132 "external" imported declarations and "static" ones. As all imported
11133 declarations seem to be static in all other languages, make them all CU-wide
11134 global only in Ada. */
11136 static struct using_direct
**
11137 using_directives (enum language language
)
11139 if (language
== language_ada
&& context_stack_depth
== 0)
11140 return &global_using_directives
;
11142 return &local_using_directives
;
11145 /* Read the import statement specified by the given die and record it. */
11148 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
11150 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11151 struct attribute
*import_attr
;
11152 struct die_info
*imported_die
, *child_die
;
11153 struct dwarf2_cu
*imported_cu
;
11154 const char *imported_name
;
11155 const char *imported_name_prefix
;
11156 const char *canonical_name
;
11157 const char *import_alias
;
11158 const char *imported_declaration
= NULL
;
11159 const char *import_prefix
;
11160 std::vector
<const char *> excludes
;
11162 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
11163 if (import_attr
== NULL
)
11165 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
11166 dwarf_tag_name (die
->tag
));
11171 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
11172 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11173 if (imported_name
== NULL
)
11175 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
11177 The import in the following code:
11191 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
11192 <52> DW_AT_decl_file : 1
11193 <53> DW_AT_decl_line : 6
11194 <54> DW_AT_import : <0x75>
11195 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
11196 <59> DW_AT_name : B
11197 <5b> DW_AT_decl_file : 1
11198 <5c> DW_AT_decl_line : 2
11199 <5d> DW_AT_type : <0x6e>
11201 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
11202 <76> DW_AT_byte_size : 4
11203 <77> DW_AT_encoding : 5 (signed)
11205 imports the wrong die ( 0x75 instead of 0x58 ).
11206 This case will be ignored until the gcc bug is fixed. */
11210 /* Figure out the local name after import. */
11211 import_alias
= dwarf2_name (die
, cu
);
11213 /* Figure out where the statement is being imported to. */
11214 import_prefix
= determine_prefix (die
, cu
);
11216 /* Figure out what the scope of the imported die is and prepend it
11217 to the name of the imported die. */
11218 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
11220 if (imported_die
->tag
!= DW_TAG_namespace
11221 && imported_die
->tag
!= DW_TAG_module
)
11223 imported_declaration
= imported_name
;
11224 canonical_name
= imported_name_prefix
;
11226 else if (strlen (imported_name_prefix
) > 0)
11227 canonical_name
= obconcat (&objfile
->objfile_obstack
,
11228 imported_name_prefix
,
11229 (cu
->language
== language_d
? "." : "::"),
11230 imported_name
, (char *) NULL
);
11232 canonical_name
= imported_name
;
11234 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
11235 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11236 child_die
= sibling_die (child_die
))
11238 /* DWARF-4: A Fortran use statement with a “rename list” may be
11239 represented by an imported module entry with an import attribute
11240 referring to the module and owned entries corresponding to those
11241 entities that are renamed as part of being imported. */
11243 if (child_die
->tag
!= DW_TAG_imported_declaration
)
11245 complaint (&symfile_complaints
,
11246 _("child DW_TAG_imported_declaration expected "
11247 "- DIE at %s [in module %s]"),
11248 sect_offset_str (child_die
->sect_off
),
11249 objfile_name (objfile
));
11253 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
11254 if (import_attr
== NULL
)
11256 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
11257 dwarf_tag_name (child_die
->tag
));
11262 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
11264 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11265 if (imported_name
== NULL
)
11267 complaint (&symfile_complaints
,
11268 _("child DW_TAG_imported_declaration has unknown "
11269 "imported name - DIE at %s [in module %s]"),
11270 sect_offset_str (child_die
->sect_off
),
11271 objfile_name (objfile
));
11275 excludes
.push_back (imported_name
);
11277 process_die (child_die
, cu
);
11280 add_using_directive (using_directives (cu
->language
),
11284 imported_declaration
,
11287 &objfile
->objfile_obstack
);
11290 /* ICC<14 does not output the required DW_AT_declaration on incomplete
11291 types, but gives them a size of zero. Starting with version 14,
11292 ICC is compatible with GCC. */
11295 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
11297 if (!cu
->checked_producer
)
11298 check_producer (cu
);
11300 return cu
->producer_is_icc_lt_14
;
11303 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
11304 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
11305 this, it was first present in GCC release 4.3.0. */
11308 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
11310 if (!cu
->checked_producer
)
11311 check_producer (cu
);
11313 return cu
->producer_is_gcc_lt_4_3
;
11316 static file_and_directory
11317 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
11319 file_and_directory res
;
11321 /* Find the filename. Do not use dwarf2_name here, since the filename
11322 is not a source language identifier. */
11323 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
11324 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
11326 if (res
.comp_dir
== NULL
11327 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
11328 && IS_ABSOLUTE_PATH (res
.name
))
11330 res
.comp_dir_storage
= ldirname (res
.name
);
11331 if (!res
.comp_dir_storage
.empty ())
11332 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
11334 if (res
.comp_dir
!= NULL
)
11336 /* Irix 6.2 native cc prepends <machine>.: to the compilation
11337 directory, get rid of it. */
11338 const char *cp
= strchr (res
.comp_dir
, ':');
11340 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
11341 res
.comp_dir
= cp
+ 1;
11344 if (res
.name
== NULL
)
11345 res
.name
= "<unknown>";
11350 /* Handle DW_AT_stmt_list for a compilation unit.
11351 DIE is the DW_TAG_compile_unit die for CU.
11352 COMP_DIR is the compilation directory. LOWPC is passed to
11353 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11356 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11357 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
11359 struct dwarf2_per_objfile
*dwarf2_per_objfile
11360 = cu
->per_cu
->dwarf2_per_objfile
;
11361 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11362 struct attribute
*attr
;
11363 struct line_header line_header_local
;
11364 hashval_t line_header_local_hash
;
11366 int decode_mapping
;
11368 gdb_assert (! cu
->per_cu
->is_debug_types
);
11370 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11374 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11376 /* The line header hash table is only created if needed (it exists to
11377 prevent redundant reading of the line table for partial_units).
11378 If we're given a partial_unit, we'll need it. If we're given a
11379 compile_unit, then use the line header hash table if it's already
11380 created, but don't create one just yet. */
11382 if (dwarf2_per_objfile
->line_header_hash
== NULL
11383 && die
->tag
== DW_TAG_partial_unit
)
11385 dwarf2_per_objfile
->line_header_hash
11386 = htab_create_alloc_ex (127, line_header_hash_voidp
,
11387 line_header_eq_voidp
,
11388 free_line_header_voidp
,
11389 &objfile
->objfile_obstack
,
11390 hashtab_obstack_allocate
,
11391 dummy_obstack_deallocate
);
11394 line_header_local
.sect_off
= line_offset
;
11395 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11396 line_header_local_hash
= line_header_hash (&line_header_local
);
11397 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
11399 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11400 &line_header_local
,
11401 line_header_local_hash
, NO_INSERT
);
11403 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11404 is not present in *SLOT (since if there is something in *SLOT then
11405 it will be for a partial_unit). */
11406 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11408 gdb_assert (*slot
!= NULL
);
11409 cu
->line_header
= (struct line_header
*) *slot
;
11414 /* dwarf_decode_line_header does not yet provide sufficient information.
11415 We always have to call also dwarf_decode_lines for it. */
11416 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11420 cu
->line_header
= lh
.release ();
11421 cu
->line_header_die_owner
= die
;
11423 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
11427 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11428 &line_header_local
,
11429 line_header_local_hash
, INSERT
);
11430 gdb_assert (slot
!= NULL
);
11432 if (slot
!= NULL
&& *slot
== NULL
)
11434 /* This newly decoded line number information unit will be owned
11435 by line_header_hash hash table. */
11436 *slot
= cu
->line_header
;
11437 cu
->line_header_die_owner
= NULL
;
11441 /* We cannot free any current entry in (*slot) as that struct line_header
11442 may be already used by multiple CUs. Create only temporary decoded
11443 line_header for this CU - it may happen at most once for each line
11444 number information unit. And if we're not using line_header_hash
11445 then this is what we want as well. */
11446 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11448 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11449 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11454 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11457 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11459 struct dwarf2_per_objfile
*dwarf2_per_objfile
11460 = cu
->per_cu
->dwarf2_per_objfile
;
11461 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11462 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11463 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11464 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11465 struct attribute
*attr
;
11466 struct die_info
*child_die
;
11467 CORE_ADDR baseaddr
;
11469 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11471 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11473 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11474 from finish_block. */
11475 if (lowpc
== ((CORE_ADDR
) -1))
11477 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11479 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11481 prepare_one_comp_unit (cu
, die
, cu
->language
);
11483 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11484 standardised yet. As a workaround for the language detection we fall
11485 back to the DW_AT_producer string. */
11486 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11487 cu
->language
= language_opencl
;
11489 /* Similar hack for Go. */
11490 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11491 set_cu_language (DW_LANG_Go
, cu
);
11493 dwarf2_start_symtab (cu
, fnd
.name
, fnd
.comp_dir
, lowpc
);
11495 /* Decode line number information if present. We do this before
11496 processing child DIEs, so that the line header table is available
11497 for DW_AT_decl_file. */
11498 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11500 /* Process all dies in compilation unit. */
11501 if (die
->child
!= NULL
)
11503 child_die
= die
->child
;
11504 while (child_die
&& child_die
->tag
)
11506 process_die (child_die
, cu
);
11507 child_die
= sibling_die (child_die
);
11511 /* Decode macro information, if present. Dwarf 2 macro information
11512 refers to information in the line number info statement program
11513 header, so we can only read it if we've read the header
11515 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11517 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11518 if (attr
&& cu
->line_header
)
11520 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11521 complaint (&symfile_complaints
,
11522 _("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11524 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11528 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11529 if (attr
&& cu
->line_header
)
11531 unsigned int macro_offset
= DW_UNSND (attr
);
11533 dwarf_decode_macros (cu
, macro_offset
, 0);
11538 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
11539 Create the set of symtabs used by this TU, or if this TU is sharing
11540 symtabs with another TU and the symtabs have already been created
11541 then restore those symtabs in the line header.
11542 We don't need the pc/line-number mapping for type units. */
11545 setup_type_unit_groups (struct die_info
*die
, struct dwarf2_cu
*cu
)
11547 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
11548 struct type_unit_group
*tu_group
;
11550 struct attribute
*attr
;
11552 struct signatured_type
*sig_type
;
11554 gdb_assert (per_cu
->is_debug_types
);
11555 sig_type
= (struct signatured_type
*) per_cu
;
11557 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11559 /* If we're using .gdb_index (includes -readnow) then
11560 per_cu->type_unit_group may not have been set up yet. */
11561 if (sig_type
->type_unit_group
== NULL
)
11562 sig_type
->type_unit_group
= get_type_unit_group (cu
, attr
);
11563 tu_group
= sig_type
->type_unit_group
;
11565 /* If we've already processed this stmt_list there's no real need to
11566 do it again, we could fake it and just recreate the part we need
11567 (file name,index -> symtab mapping). If data shows this optimization
11568 is useful we can do it then. */
11569 first_time
= tu_group
->compunit_symtab
== NULL
;
11571 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11576 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11577 lh
= dwarf_decode_line_header (line_offset
, cu
);
11582 dwarf2_start_symtab (cu
, "", NULL
, 0);
11585 gdb_assert (tu_group
->symtabs
== NULL
);
11586 restart_symtab (tu_group
->compunit_symtab
, "", 0);
11591 cu
->line_header
= lh
.release ();
11592 cu
->line_header_die_owner
= die
;
11596 struct compunit_symtab
*cust
= dwarf2_start_symtab (cu
, "", NULL
, 0);
11598 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11599 still initializing it, and our caller (a few levels up)
11600 process_full_type_unit still needs to know if this is the first
11603 tu_group
->num_symtabs
= cu
->line_header
->file_names
.size ();
11604 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
11605 cu
->line_header
->file_names
.size ());
11607 for (i
= 0; i
< cu
->line_header
->file_names
.size (); ++i
)
11609 file_entry
&fe
= cu
->line_header
->file_names
[i
];
11611 dwarf2_start_subfile (fe
.name
, fe
.include_dir (cu
->line_header
));
11613 if (current_subfile
->symtab
== NULL
)
11615 /* NOTE: start_subfile will recognize when it's been
11616 passed a file it has already seen. So we can't
11617 assume there's a simple mapping from
11618 cu->line_header->file_names to subfiles, plus
11619 cu->line_header->file_names may contain dups. */
11620 current_subfile
->symtab
11621 = allocate_symtab (cust
, current_subfile
->name
);
11624 fe
.symtab
= current_subfile
->symtab
;
11625 tu_group
->symtabs
[i
] = fe
.symtab
;
11630 restart_symtab (tu_group
->compunit_symtab
, "", 0);
11632 for (i
= 0; i
< cu
->line_header
->file_names
.size (); ++i
)
11634 file_entry
&fe
= cu
->line_header
->file_names
[i
];
11636 fe
.symtab
= tu_group
->symtabs
[i
];
11640 /* The main symtab is allocated last. Type units don't have DW_AT_name
11641 so they don't have a "real" (so to speak) symtab anyway.
11642 There is later code that will assign the main symtab to all symbols
11643 that don't have one. We need to handle the case of a symbol with a
11644 missing symtab (DW_AT_decl_file) anyway. */
11647 /* Process DW_TAG_type_unit.
11648 For TUs we want to skip the first top level sibling if it's not the
11649 actual type being defined by this TU. In this case the first top
11650 level sibling is there to provide context only. */
11653 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11655 struct die_info
*child_die
;
11657 prepare_one_comp_unit (cu
, die
, language_minimal
);
11659 /* Initialize (or reinitialize) the machinery for building symtabs.
11660 We do this before processing child DIEs, so that the line header table
11661 is available for DW_AT_decl_file. */
11662 setup_type_unit_groups (die
, cu
);
11664 if (die
->child
!= NULL
)
11666 child_die
= die
->child
;
11667 while (child_die
&& child_die
->tag
)
11669 process_die (child_die
, cu
);
11670 child_die
= sibling_die (child_die
);
11677 http://gcc.gnu.org/wiki/DebugFission
11678 http://gcc.gnu.org/wiki/DebugFissionDWP
11680 To simplify handling of both DWO files ("object" files with the DWARF info)
11681 and DWP files (a file with the DWOs packaged up into one file), we treat
11682 DWP files as having a collection of virtual DWO files. */
11685 hash_dwo_file (const void *item
)
11687 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11690 hash
= htab_hash_string (dwo_file
->dwo_name
);
11691 if (dwo_file
->comp_dir
!= NULL
)
11692 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11697 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11699 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11700 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11702 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11704 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11705 return lhs
->comp_dir
== rhs
->comp_dir
;
11706 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11709 /* Allocate a hash table for DWO files. */
11712 allocate_dwo_file_hash_table (struct objfile
*objfile
)
11714 return htab_create_alloc_ex (41,
11718 &objfile
->objfile_obstack
,
11719 hashtab_obstack_allocate
,
11720 dummy_obstack_deallocate
);
11723 /* Lookup DWO file DWO_NAME. */
11726 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11727 const char *dwo_name
,
11728 const char *comp_dir
)
11730 struct dwo_file find_entry
;
11733 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11734 dwarf2_per_objfile
->dwo_files
11735 = allocate_dwo_file_hash_table (dwarf2_per_objfile
->objfile
);
11737 memset (&find_entry
, 0, sizeof (find_entry
));
11738 find_entry
.dwo_name
= dwo_name
;
11739 find_entry
.comp_dir
= comp_dir
;
11740 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
11746 hash_dwo_unit (const void *item
)
11748 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11750 /* This drops the top 32 bits of the id, but is ok for a hash. */
11751 return dwo_unit
->signature
;
11755 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11757 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11758 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11760 /* The signature is assumed to be unique within the DWO file.
11761 So while object file CU dwo_id's always have the value zero,
11762 that's OK, assuming each object file DWO file has only one CU,
11763 and that's the rule for now. */
11764 return lhs
->signature
== rhs
->signature
;
11767 /* Allocate a hash table for DWO CUs,TUs.
11768 There is one of these tables for each of CUs,TUs for each DWO file. */
11771 allocate_dwo_unit_table (struct objfile
*objfile
)
11773 /* Start out with a pretty small number.
11774 Generally DWO files contain only one CU and maybe some TUs. */
11775 return htab_create_alloc_ex (3,
11779 &objfile
->objfile_obstack
,
11780 hashtab_obstack_allocate
,
11781 dummy_obstack_deallocate
);
11784 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
11786 struct create_dwo_cu_data
11788 struct dwo_file
*dwo_file
;
11789 struct dwo_unit dwo_unit
;
11792 /* die_reader_func for create_dwo_cu. */
11795 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11796 const gdb_byte
*info_ptr
,
11797 struct die_info
*comp_unit_die
,
11801 struct dwarf2_cu
*cu
= reader
->cu
;
11802 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11803 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11804 struct create_dwo_cu_data
*data
= (struct create_dwo_cu_data
*) datap
;
11805 struct dwo_file
*dwo_file
= data
->dwo_file
;
11806 struct dwo_unit
*dwo_unit
= &data
->dwo_unit
;
11807 struct attribute
*attr
;
11809 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
11812 complaint (&symfile_complaints
,
11813 _("Dwarf Error: debug entry at offset %s is missing"
11814 " its dwo_id [in module %s]"),
11815 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11819 dwo_unit
->dwo_file
= dwo_file
;
11820 dwo_unit
->signature
= DW_UNSND (attr
);
11821 dwo_unit
->section
= section
;
11822 dwo_unit
->sect_off
= sect_off
;
11823 dwo_unit
->length
= cu
->per_cu
->length
;
11825 if (dwarf_read_debug
)
11826 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11827 sect_offset_str (sect_off
),
11828 hex_string (dwo_unit
->signature
));
11831 /* Create the dwo_units for the CUs in a DWO_FILE.
11832 Note: This function processes DWO files only, not DWP files. */
11835 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11836 struct dwo_file
&dwo_file
, dwarf2_section_info
§ion
,
11839 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11840 const gdb_byte
*info_ptr
, *end_ptr
;
11842 dwarf2_read_section (objfile
, §ion
);
11843 info_ptr
= section
.buffer
;
11845 if (info_ptr
== NULL
)
11848 if (dwarf_read_debug
)
11850 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11851 get_section_name (§ion
),
11852 get_section_file_name (§ion
));
11855 end_ptr
= info_ptr
+ section
.size
;
11856 while (info_ptr
< end_ptr
)
11858 struct dwarf2_per_cu_data per_cu
;
11859 struct create_dwo_cu_data create_dwo_cu_data
;
11860 struct dwo_unit
*dwo_unit
;
11862 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11864 memset (&create_dwo_cu_data
.dwo_unit
, 0,
11865 sizeof (create_dwo_cu_data
.dwo_unit
));
11866 memset (&per_cu
, 0, sizeof (per_cu
));
11867 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11868 per_cu
.is_debug_types
= 0;
11869 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11870 per_cu
.section
= §ion
;
11871 create_dwo_cu_data
.dwo_file
= &dwo_file
;
11873 init_cutu_and_read_dies_no_follow (
11874 &per_cu
, &dwo_file
, create_dwo_cu_reader
, &create_dwo_cu_data
);
11875 info_ptr
+= per_cu
.length
;
11877 // If the unit could not be parsed, skip it.
11878 if (create_dwo_cu_data
.dwo_unit
.dwo_file
== NULL
)
11881 if (cus_htab
== NULL
)
11882 cus_htab
= allocate_dwo_unit_table (objfile
);
11884 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11885 *dwo_unit
= create_dwo_cu_data
.dwo_unit
;
11886 slot
= htab_find_slot (cus_htab
, dwo_unit
, INSERT
);
11887 gdb_assert (slot
!= NULL
);
11890 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11891 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11893 complaint (&symfile_complaints
,
11894 _("debug cu entry at offset %s is duplicate to"
11895 " the entry at offset %s, signature %s"),
11896 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11897 hex_string (dwo_unit
->signature
));
11899 *slot
= (void *)dwo_unit
;
11903 /* DWP file .debug_{cu,tu}_index section format:
11904 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11908 Both index sections have the same format, and serve to map a 64-bit
11909 signature to a set of section numbers. Each section begins with a header,
11910 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11911 indexes, and a pool of 32-bit section numbers. The index sections will be
11912 aligned at 8-byte boundaries in the file.
11914 The index section header consists of:
11916 V, 32 bit version number
11918 N, 32 bit number of compilation units or type units in the index
11919 M, 32 bit number of slots in the hash table
11921 Numbers are recorded using the byte order of the application binary.
11923 The hash table begins at offset 16 in the section, and consists of an array
11924 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11925 order of the application binary). Unused slots in the hash table are 0.
11926 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11928 The parallel table begins immediately after the hash table
11929 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11930 array of 32-bit indexes (using the byte order of the application binary),
11931 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11932 table contains a 32-bit index into the pool of section numbers. For unused
11933 hash table slots, the corresponding entry in the parallel table will be 0.
11935 The pool of section numbers begins immediately following the hash table
11936 (at offset 16 + 12 * M from the beginning of the section). The pool of
11937 section numbers consists of an array of 32-bit words (using the byte order
11938 of the application binary). Each item in the array is indexed starting
11939 from 0. The hash table entry provides the index of the first section
11940 number in the set. Additional section numbers in the set follow, and the
11941 set is terminated by a 0 entry (section number 0 is not used in ELF).
11943 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11944 section must be the first entry in the set, and the .debug_abbrev.dwo must
11945 be the second entry. Other members of the set may follow in any order.
11951 DWP Version 2 combines all the .debug_info, etc. sections into one,
11952 and the entries in the index tables are now offsets into these sections.
11953 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11956 Index Section Contents:
11958 Hash Table of Signatures dwp_hash_table.hash_table
11959 Parallel Table of Indices dwp_hash_table.unit_table
11960 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11961 Table of Section Sizes dwp_hash_table.v2.sizes
11963 The index section header consists of:
11965 V, 32 bit version number
11966 L, 32 bit number of columns in the table of section offsets
11967 N, 32 bit number of compilation units or type units in the index
11968 M, 32 bit number of slots in the hash table
11970 Numbers are recorded using the byte order of the application binary.
11972 The hash table has the same format as version 1.
11973 The parallel table of indices has the same format as version 1,
11974 except that the entries are origin-1 indices into the table of sections
11975 offsets and the table of section sizes.
11977 The table of offsets begins immediately following the parallel table
11978 (at offset 16 + 12 * M from the beginning of the section). The table is
11979 a two-dimensional array of 32-bit words (using the byte order of the
11980 application binary), with L columns and N+1 rows, in row-major order.
11981 Each row in the array is indexed starting from 0. The first row provides
11982 a key to the remaining rows: each column in this row provides an identifier
11983 for a debug section, and the offsets in the same column of subsequent rows
11984 refer to that section. The section identifiers are:
11986 DW_SECT_INFO 1 .debug_info.dwo
11987 DW_SECT_TYPES 2 .debug_types.dwo
11988 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11989 DW_SECT_LINE 4 .debug_line.dwo
11990 DW_SECT_LOC 5 .debug_loc.dwo
11991 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11992 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11993 DW_SECT_MACRO 8 .debug_macro.dwo
11995 The offsets provided by the CU and TU index sections are the base offsets
11996 for the contributions made by each CU or TU to the corresponding section
11997 in the package file. Each CU and TU header contains an abbrev_offset
11998 field, used to find the abbreviations table for that CU or TU within the
11999 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
12000 be interpreted as relative to the base offset given in the index section.
12001 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
12002 should be interpreted as relative to the base offset for .debug_line.dwo,
12003 and offsets into other debug sections obtained from DWARF attributes should
12004 also be interpreted as relative to the corresponding base offset.
12006 The table of sizes begins immediately following the table of offsets.
12007 Like the table of offsets, it is a two-dimensional array of 32-bit words,
12008 with L columns and N rows, in row-major order. Each row in the array is
12009 indexed starting from 1 (row 0 is shared by the two tables).
12013 Hash table lookup is handled the same in version 1 and 2:
12015 We assume that N and M will not exceed 2^32 - 1.
12016 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
12018 Given a 64-bit compilation unit signature or a type signature S, an entry
12019 in the hash table is located as follows:
12021 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
12022 the low-order k bits all set to 1.
12024 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
12026 3) If the hash table entry at index H matches the signature, use that
12027 entry. If the hash table entry at index H is unused (all zeroes),
12028 terminate the search: the signature is not present in the table.
12030 4) Let H = (H + H') modulo M. Repeat at Step 3.
12032 Because M > N and H' and M are relatively prime, the search is guaranteed
12033 to stop at an unused slot or find the match. */
12035 /* Create a hash table to map DWO IDs to their CU/TU entry in
12036 .debug_{info,types}.dwo in DWP_FILE.
12037 Returns NULL if there isn't one.
12038 Note: This function processes DWP files only, not DWO files. */
12040 static struct dwp_hash_table
*
12041 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12042 struct dwp_file
*dwp_file
, int is_debug_types
)
12044 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12045 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12046 const gdb_byte
*index_ptr
, *index_end
;
12047 struct dwarf2_section_info
*index
;
12048 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
12049 struct dwp_hash_table
*htab
;
12051 if (is_debug_types
)
12052 index
= &dwp_file
->sections
.tu_index
;
12054 index
= &dwp_file
->sections
.cu_index
;
12056 if (dwarf2_section_empty_p (index
))
12058 dwarf2_read_section (objfile
, index
);
12060 index_ptr
= index
->buffer
;
12061 index_end
= index_ptr
+ index
->size
;
12063 version
= read_4_bytes (dbfd
, index_ptr
);
12066 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
12070 nr_units
= read_4_bytes (dbfd
, index_ptr
);
12072 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
12075 if (version
!= 1 && version
!= 2)
12077 error (_("Dwarf Error: unsupported DWP file version (%s)"
12078 " [in module %s]"),
12079 pulongest (version
), dwp_file
->name
);
12081 if (nr_slots
!= (nr_slots
& -nr_slots
))
12083 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
12084 " is not power of 2 [in module %s]"),
12085 pulongest (nr_slots
), dwp_file
->name
);
12088 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
12089 htab
->version
= version
;
12090 htab
->nr_columns
= nr_columns
;
12091 htab
->nr_units
= nr_units
;
12092 htab
->nr_slots
= nr_slots
;
12093 htab
->hash_table
= index_ptr
;
12094 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
12096 /* Exit early if the table is empty. */
12097 if (nr_slots
== 0 || nr_units
== 0
12098 || (version
== 2 && nr_columns
== 0))
12100 /* All must be zero. */
12101 if (nr_slots
!= 0 || nr_units
!= 0
12102 || (version
== 2 && nr_columns
!= 0))
12104 complaint (&symfile_complaints
,
12105 _("Empty DWP but nr_slots,nr_units,nr_columns not"
12106 " all zero [in modules %s]"),
12114 htab
->section_pool
.v1
.indices
=
12115 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12116 /* It's harder to decide whether the section is too small in v1.
12117 V1 is deprecated anyway so we punt. */
12121 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12122 int *ids
= htab
->section_pool
.v2
.section_ids
;
12123 /* Reverse map for error checking. */
12124 int ids_seen
[DW_SECT_MAX
+ 1];
12127 if (nr_columns
< 2)
12129 error (_("Dwarf Error: bad DWP hash table, too few columns"
12130 " in section table [in module %s]"),
12133 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
12135 error (_("Dwarf Error: bad DWP hash table, too many columns"
12136 " in section table [in module %s]"),
12139 memset (ids
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
12140 memset (ids_seen
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
12141 for (i
= 0; i
< nr_columns
; ++i
)
12143 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
12145 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
12147 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
12148 " in section table [in module %s]"),
12149 id
, dwp_file
->name
);
12151 if (ids_seen
[id
] != -1)
12153 error (_("Dwarf Error: bad DWP hash table, duplicate section"
12154 " id %d in section table [in module %s]"),
12155 id
, dwp_file
->name
);
12160 /* Must have exactly one info or types section. */
12161 if (((ids_seen
[DW_SECT_INFO
] != -1)
12162 + (ids_seen
[DW_SECT_TYPES
] != -1))
12165 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
12166 " DWO info/types section [in module %s]"),
12169 /* Must have an abbrev section. */
12170 if (ids_seen
[DW_SECT_ABBREV
] == -1)
12172 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
12173 " section [in module %s]"),
12176 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
12177 htab
->section_pool
.v2
.sizes
=
12178 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
12179 * nr_units
* nr_columns
);
12180 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
12181 * nr_units
* nr_columns
))
12184 error (_("Dwarf Error: DWP index section is corrupt (too small)"
12185 " [in module %s]"),
12193 /* Update SECTIONS with the data from SECTP.
12195 This function is like the other "locate" section routines that are
12196 passed to bfd_map_over_sections, but in this context the sections to
12197 read comes from the DWP V1 hash table, not the full ELF section table.
12199 The result is non-zero for success, or zero if an error was found. */
12202 locate_v1_virtual_dwo_sections (asection
*sectp
,
12203 struct virtual_v1_dwo_sections
*sections
)
12205 const struct dwop_section_names
*names
= &dwop_section_names
;
12207 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12209 /* There can be only one. */
12210 if (sections
->abbrev
.s
.section
!= NULL
)
12212 sections
->abbrev
.s
.section
= sectp
;
12213 sections
->abbrev
.size
= bfd_get_section_size (sectp
);
12215 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
12216 || section_is_p (sectp
->name
, &names
->types_dwo
))
12218 /* There can be only one. */
12219 if (sections
->info_or_types
.s
.section
!= NULL
)
12221 sections
->info_or_types
.s
.section
= sectp
;
12222 sections
->info_or_types
.size
= bfd_get_section_size (sectp
);
12224 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12226 /* There can be only one. */
12227 if (sections
->line
.s
.section
!= NULL
)
12229 sections
->line
.s
.section
= sectp
;
12230 sections
->line
.size
= bfd_get_section_size (sectp
);
12232 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12234 /* There can be only one. */
12235 if (sections
->loc
.s
.section
!= NULL
)
12237 sections
->loc
.s
.section
= sectp
;
12238 sections
->loc
.size
= bfd_get_section_size (sectp
);
12240 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12242 /* There can be only one. */
12243 if (sections
->macinfo
.s
.section
!= NULL
)
12245 sections
->macinfo
.s
.section
= sectp
;
12246 sections
->macinfo
.size
= bfd_get_section_size (sectp
);
12248 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12250 /* There can be only one. */
12251 if (sections
->macro
.s
.section
!= NULL
)
12253 sections
->macro
.s
.section
= sectp
;
12254 sections
->macro
.size
= bfd_get_section_size (sectp
);
12256 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12258 /* There can be only one. */
12259 if (sections
->str_offsets
.s
.section
!= NULL
)
12261 sections
->str_offsets
.s
.section
= sectp
;
12262 sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
12266 /* No other kind of section is valid. */
12273 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12274 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12275 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12276 This is for DWP version 1 files. */
12278 static struct dwo_unit
*
12279 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12280 struct dwp_file
*dwp_file
,
12281 uint32_t unit_index
,
12282 const char *comp_dir
,
12283 ULONGEST signature
, int is_debug_types
)
12285 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12286 const struct dwp_hash_table
*dwp_htab
=
12287 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12288 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12289 const char *kind
= is_debug_types
? "TU" : "CU";
12290 struct dwo_file
*dwo_file
;
12291 struct dwo_unit
*dwo_unit
;
12292 struct virtual_v1_dwo_sections sections
;
12293 void **dwo_file_slot
;
12296 gdb_assert (dwp_file
->version
== 1);
12298 if (dwarf_read_debug
)
12300 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
12302 pulongest (unit_index
), hex_string (signature
),
12306 /* Fetch the sections of this DWO unit.
12307 Put a limit on the number of sections we look for so that bad data
12308 doesn't cause us to loop forever. */
12310 #define MAX_NR_V1_DWO_SECTIONS \
12311 (1 /* .debug_info or .debug_types */ \
12312 + 1 /* .debug_abbrev */ \
12313 + 1 /* .debug_line */ \
12314 + 1 /* .debug_loc */ \
12315 + 1 /* .debug_str_offsets */ \
12316 + 1 /* .debug_macro or .debug_macinfo */ \
12317 + 1 /* trailing zero */)
12319 memset (§ions
, 0, sizeof (sections
));
12321 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12324 uint32_t section_nr
=
12325 read_4_bytes (dbfd
,
12326 dwp_htab
->section_pool
.v1
.indices
12327 + (unit_index
+ i
) * sizeof (uint32_t));
12329 if (section_nr
== 0)
12331 if (section_nr
>= dwp_file
->num_sections
)
12333 error (_("Dwarf Error: bad DWP hash table, section number too large"
12334 " [in module %s]"),
12338 sectp
= dwp_file
->elf_sections
[section_nr
];
12339 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12341 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12342 " [in module %s]"),
12348 || dwarf2_section_empty_p (§ions
.info_or_types
)
12349 || dwarf2_section_empty_p (§ions
.abbrev
))
12351 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12352 " [in module %s]"),
12355 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12357 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12358 " [in module %s]"),
12362 /* It's easier for the rest of the code if we fake a struct dwo_file and
12363 have dwo_unit "live" in that. At least for now.
12365 The DWP file can be made up of a random collection of CUs and TUs.
12366 However, for each CU + set of TUs that came from the same original DWO
12367 file, we can combine them back into a virtual DWO file to save space
12368 (fewer struct dwo_file objects to allocate). Remember that for really
12369 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12371 std::string virtual_dwo_name
=
12372 string_printf ("virtual-dwo/%d-%d-%d-%d",
12373 get_section_id (§ions
.abbrev
),
12374 get_section_id (§ions
.line
),
12375 get_section_id (§ions
.loc
),
12376 get_section_id (§ions
.str_offsets
));
12377 /* Can we use an existing virtual DWO file? */
12378 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12379 virtual_dwo_name
.c_str (),
12381 /* Create one if necessary. */
12382 if (*dwo_file_slot
== NULL
)
12384 if (dwarf_read_debug
)
12386 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12387 virtual_dwo_name
.c_str ());
12389 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
12391 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
12392 virtual_dwo_name
.c_str (),
12393 virtual_dwo_name
.size ());
12394 dwo_file
->comp_dir
= comp_dir
;
12395 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12396 dwo_file
->sections
.line
= sections
.line
;
12397 dwo_file
->sections
.loc
= sections
.loc
;
12398 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12399 dwo_file
->sections
.macro
= sections
.macro
;
12400 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12401 /* The "str" section is global to the entire DWP file. */
12402 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12403 /* The info or types section is assigned below to dwo_unit,
12404 there's no need to record it in dwo_file.
12405 Also, we can't simply record type sections in dwo_file because
12406 we record a pointer into the vector in dwo_unit. As we collect more
12407 types we'll grow the vector and eventually have to reallocate space
12408 for it, invalidating all copies of pointers into the previous
12410 *dwo_file_slot
= dwo_file
;
12414 if (dwarf_read_debug
)
12416 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12417 virtual_dwo_name
.c_str ());
12419 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12422 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12423 dwo_unit
->dwo_file
= dwo_file
;
12424 dwo_unit
->signature
= signature
;
12425 dwo_unit
->section
=
12426 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12427 *dwo_unit
->section
= sections
.info_or_types
;
12428 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12433 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
12434 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
12435 piece within that section used by a TU/CU, return a virtual section
12436 of just that piece. */
12438 static struct dwarf2_section_info
12439 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12440 struct dwarf2_section_info
*section
,
12441 bfd_size_type offset
, bfd_size_type size
)
12443 struct dwarf2_section_info result
;
12446 gdb_assert (section
!= NULL
);
12447 gdb_assert (!section
->is_virtual
);
12449 memset (&result
, 0, sizeof (result
));
12450 result
.s
.containing_section
= section
;
12451 result
.is_virtual
= 1;
12456 sectp
= get_section_bfd_section (section
);
12458 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12459 bounds of the real section. This is a pretty-rare event, so just
12460 flag an error (easier) instead of a warning and trying to cope. */
12462 || offset
+ size
> bfd_get_section_size (sectp
))
12464 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12465 " in section %s [in module %s]"),
12466 sectp
? bfd_section_name (abfd
, sectp
) : "<unknown>",
12467 objfile_name (dwarf2_per_objfile
->objfile
));
12470 result
.virtual_offset
= offset
;
12471 result
.size
= size
;
12475 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12476 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12477 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12478 This is for DWP version 2 files. */
12480 static struct dwo_unit
*
12481 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12482 struct dwp_file
*dwp_file
,
12483 uint32_t unit_index
,
12484 const char *comp_dir
,
12485 ULONGEST signature
, int is_debug_types
)
12487 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12488 const struct dwp_hash_table
*dwp_htab
=
12489 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12490 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12491 const char *kind
= is_debug_types
? "TU" : "CU";
12492 struct dwo_file
*dwo_file
;
12493 struct dwo_unit
*dwo_unit
;
12494 struct virtual_v2_dwo_sections sections
;
12495 void **dwo_file_slot
;
12498 gdb_assert (dwp_file
->version
== 2);
12500 if (dwarf_read_debug
)
12502 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
12504 pulongest (unit_index
), hex_string (signature
),
12508 /* Fetch the section offsets of this DWO unit. */
12510 memset (§ions
, 0, sizeof (sections
));
12512 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12514 uint32_t offset
= read_4_bytes (dbfd
,
12515 dwp_htab
->section_pool
.v2
.offsets
12516 + (((unit_index
- 1) * dwp_htab
->nr_columns
12518 * sizeof (uint32_t)));
12519 uint32_t size
= read_4_bytes (dbfd
,
12520 dwp_htab
->section_pool
.v2
.sizes
12521 + (((unit_index
- 1) * dwp_htab
->nr_columns
12523 * sizeof (uint32_t)));
12525 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12528 case DW_SECT_TYPES
:
12529 sections
.info_or_types_offset
= offset
;
12530 sections
.info_or_types_size
= size
;
12532 case DW_SECT_ABBREV
:
12533 sections
.abbrev_offset
= offset
;
12534 sections
.abbrev_size
= size
;
12537 sections
.line_offset
= offset
;
12538 sections
.line_size
= size
;
12541 sections
.loc_offset
= offset
;
12542 sections
.loc_size
= size
;
12544 case DW_SECT_STR_OFFSETS
:
12545 sections
.str_offsets_offset
= offset
;
12546 sections
.str_offsets_size
= size
;
12548 case DW_SECT_MACINFO
:
12549 sections
.macinfo_offset
= offset
;
12550 sections
.macinfo_size
= size
;
12552 case DW_SECT_MACRO
:
12553 sections
.macro_offset
= offset
;
12554 sections
.macro_size
= size
;
12559 /* It's easier for the rest of the code if we fake a struct dwo_file and
12560 have dwo_unit "live" in that. At least for now.
12562 The DWP file can be made up of a random collection of CUs and TUs.
12563 However, for each CU + set of TUs that came from the same original DWO
12564 file, we can combine them back into a virtual DWO file to save space
12565 (fewer struct dwo_file objects to allocate). Remember that for really
12566 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12568 std::string virtual_dwo_name
=
12569 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12570 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12571 (long) (sections
.line_size
? sections
.line_offset
: 0),
12572 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12573 (long) (sections
.str_offsets_size
12574 ? sections
.str_offsets_offset
: 0));
12575 /* Can we use an existing virtual DWO file? */
12576 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12577 virtual_dwo_name
.c_str (),
12579 /* Create one if necessary. */
12580 if (*dwo_file_slot
== NULL
)
12582 if (dwarf_read_debug
)
12584 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12585 virtual_dwo_name
.c_str ());
12587 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
12589 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
12590 virtual_dwo_name
.c_str (),
12591 virtual_dwo_name
.size ());
12592 dwo_file
->comp_dir
= comp_dir
;
12593 dwo_file
->sections
.abbrev
=
12594 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
12595 sections
.abbrev_offset
, sections
.abbrev_size
);
12596 dwo_file
->sections
.line
=
12597 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
12598 sections
.line_offset
, sections
.line_size
);
12599 dwo_file
->sections
.loc
=
12600 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
12601 sections
.loc_offset
, sections
.loc_size
);
12602 dwo_file
->sections
.macinfo
=
12603 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
12604 sections
.macinfo_offset
, sections
.macinfo_size
);
12605 dwo_file
->sections
.macro
=
12606 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
12607 sections
.macro_offset
, sections
.macro_size
);
12608 dwo_file
->sections
.str_offsets
=
12609 create_dwp_v2_section (dwarf2_per_objfile
,
12610 &dwp_file
->sections
.str_offsets
,
12611 sections
.str_offsets_offset
,
12612 sections
.str_offsets_size
);
12613 /* The "str" section is global to the entire DWP file. */
12614 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12615 /* The info or types section is assigned below to dwo_unit,
12616 there's no need to record it in dwo_file.
12617 Also, we can't simply record type sections in dwo_file because
12618 we record a pointer into the vector in dwo_unit. As we collect more
12619 types we'll grow the vector and eventually have to reallocate space
12620 for it, invalidating all copies of pointers into the previous
12622 *dwo_file_slot
= dwo_file
;
12626 if (dwarf_read_debug
)
12628 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12629 virtual_dwo_name
.c_str ());
12631 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12634 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12635 dwo_unit
->dwo_file
= dwo_file
;
12636 dwo_unit
->signature
= signature
;
12637 dwo_unit
->section
=
12638 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12639 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
12641 ? &dwp_file
->sections
.types
12642 : &dwp_file
->sections
.info
,
12643 sections
.info_or_types_offset
,
12644 sections
.info_or_types_size
);
12645 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12650 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12651 Returns NULL if the signature isn't found. */
12653 static struct dwo_unit
*
12654 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12655 struct dwp_file
*dwp_file
, const char *comp_dir
,
12656 ULONGEST signature
, int is_debug_types
)
12658 const struct dwp_hash_table
*dwp_htab
=
12659 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12660 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12661 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12662 uint32_t hash
= signature
& mask
;
12663 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12666 struct dwo_unit find_dwo_cu
;
12668 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12669 find_dwo_cu
.signature
= signature
;
12670 slot
= htab_find_slot (is_debug_types
12671 ? dwp_file
->loaded_tus
12672 : dwp_file
->loaded_cus
,
12673 &find_dwo_cu
, INSERT
);
12676 return (struct dwo_unit
*) *slot
;
12678 /* Use a for loop so that we don't loop forever on bad debug info. */
12679 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12681 ULONGEST signature_in_table
;
12683 signature_in_table
=
12684 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12685 if (signature_in_table
== signature
)
12687 uint32_t unit_index
=
12688 read_4_bytes (dbfd
,
12689 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12691 if (dwp_file
->version
== 1)
12693 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
12694 dwp_file
, unit_index
,
12695 comp_dir
, signature
,
12700 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
12701 dwp_file
, unit_index
,
12702 comp_dir
, signature
,
12705 return (struct dwo_unit
*) *slot
;
12707 if (signature_in_table
== 0)
12709 hash
= (hash
+ hash2
) & mask
;
12712 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12713 " [in module %s]"),
12717 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12718 Open the file specified by FILE_NAME and hand it off to BFD for
12719 preliminary analysis. Return a newly initialized bfd *, which
12720 includes a canonicalized copy of FILE_NAME.
12721 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12722 SEARCH_CWD is true if the current directory is to be searched.
12723 It will be searched before debug-file-directory.
12724 If successful, the file is added to the bfd include table of the
12725 objfile's bfd (see gdb_bfd_record_inclusion).
12726 If unable to find/open the file, return NULL.
12727 NOTE: This function is derived from symfile_bfd_open. */
12729 static gdb_bfd_ref_ptr
12730 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12731 const char *file_name
, int is_dwp
, int search_cwd
)
12734 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12735 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12736 to debug_file_directory. */
12737 const char *search_path
;
12738 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12740 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12743 if (*debug_file_directory
!= '\0')
12745 search_path_holder
.reset (concat (".", dirname_separator_string
,
12746 debug_file_directory
,
12748 search_path
= search_path_holder
.get ();
12754 search_path
= debug_file_directory
;
12756 openp_flags flags
= OPF_RETURN_REALPATH
;
12758 flags
|= OPF_SEARCH_IN_PATH
;
12760 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12761 desc
= openp (search_path
, flags
, file_name
,
12762 O_RDONLY
| O_BINARY
, &absolute_name
);
12766 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12768 if (sym_bfd
== NULL
)
12770 bfd_set_cacheable (sym_bfd
.get (), 1);
12772 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12775 /* Success. Record the bfd as having been included by the objfile's bfd.
12776 This is important because things like demangled_names_hash lives in the
12777 objfile's per_bfd space and may have references to things like symbol
12778 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12779 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12784 /* Try to open DWO file FILE_NAME.
12785 COMP_DIR is the DW_AT_comp_dir attribute.
12786 The result is the bfd handle of the file.
12787 If there is a problem finding or opening the file, return NULL.
12788 Upon success, the canonicalized path of the file is stored in the bfd,
12789 same as symfile_bfd_open. */
12791 static gdb_bfd_ref_ptr
12792 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12793 const char *file_name
, const char *comp_dir
)
12795 if (IS_ABSOLUTE_PATH (file_name
))
12796 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12797 0 /*is_dwp*/, 0 /*search_cwd*/);
12799 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12801 if (comp_dir
!= NULL
)
12803 char *path_to_try
= concat (comp_dir
, SLASH_STRING
,
12804 file_name
, (char *) NULL
);
12806 /* NOTE: If comp_dir is a relative path, this will also try the
12807 search path, which seems useful. */
12808 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12811 1 /*search_cwd*/));
12812 xfree (path_to_try
);
12817 /* That didn't work, try debug-file-directory, which, despite its name,
12818 is a list of paths. */
12820 if (*debug_file_directory
== '\0')
12823 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12824 0 /*is_dwp*/, 1 /*search_cwd*/);
12827 /* This function is mapped across the sections and remembers the offset and
12828 size of each of the DWO debugging sections we are interested in. */
12831 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12833 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12834 const struct dwop_section_names
*names
= &dwop_section_names
;
12836 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12838 dwo_sections
->abbrev
.s
.section
= sectp
;
12839 dwo_sections
->abbrev
.size
= bfd_get_section_size (sectp
);
12841 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12843 dwo_sections
->info
.s
.section
= sectp
;
12844 dwo_sections
->info
.size
= bfd_get_section_size (sectp
);
12846 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12848 dwo_sections
->line
.s
.section
= sectp
;
12849 dwo_sections
->line
.size
= bfd_get_section_size (sectp
);
12851 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12853 dwo_sections
->loc
.s
.section
= sectp
;
12854 dwo_sections
->loc
.size
= bfd_get_section_size (sectp
);
12856 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12858 dwo_sections
->macinfo
.s
.section
= sectp
;
12859 dwo_sections
->macinfo
.size
= bfd_get_section_size (sectp
);
12861 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12863 dwo_sections
->macro
.s
.section
= sectp
;
12864 dwo_sections
->macro
.size
= bfd_get_section_size (sectp
);
12866 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12868 dwo_sections
->str
.s
.section
= sectp
;
12869 dwo_sections
->str
.size
= bfd_get_section_size (sectp
);
12871 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12873 dwo_sections
->str_offsets
.s
.section
= sectp
;
12874 dwo_sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
12876 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12878 struct dwarf2_section_info type_section
;
12880 memset (&type_section
, 0, sizeof (type_section
));
12881 type_section
.s
.section
= sectp
;
12882 type_section
.size
= bfd_get_section_size (sectp
);
12883 VEC_safe_push (dwarf2_section_info_def
, dwo_sections
->types
,
12888 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12889 by PER_CU. This is for the non-DWP case.
12890 The result is NULL if DWO_NAME can't be found. */
12892 static struct dwo_file
*
12893 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12894 const char *dwo_name
, const char *comp_dir
)
12896 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12897 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12899 gdb_bfd_ref_ptr
dbfd (open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
));
12902 if (dwarf_read_debug
)
12903 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12907 /* We use a unique pointer here, despite the obstack allocation,
12908 because a dwo_file needs some cleanup if it is abandoned. */
12909 dwo_file_up
dwo_file (OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
12911 dwo_file
->dwo_name
= dwo_name
;
12912 dwo_file
->comp_dir
= comp_dir
;
12913 dwo_file
->dbfd
= dbfd
.release ();
12915 bfd_map_over_sections (dwo_file
->dbfd
, dwarf2_locate_dwo_sections
,
12916 &dwo_file
->sections
);
12918 create_cus_hash_table (dwarf2_per_objfile
, *dwo_file
, dwo_file
->sections
.info
,
12921 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12922 dwo_file
->sections
.types
, dwo_file
->tus
);
12924 if (dwarf_read_debug
)
12925 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12927 return dwo_file
.release ();
12930 /* This function is mapped across the sections and remembers the offset and
12931 size of each of the DWP debugging sections common to version 1 and 2 that
12932 we are interested in. */
12935 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12936 void *dwp_file_ptr
)
12938 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12939 const struct dwop_section_names
*names
= &dwop_section_names
;
12940 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12942 /* Record the ELF section number for later lookup: this is what the
12943 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12944 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12945 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12947 /* Look for specific sections that we need. */
12948 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12950 dwp_file
->sections
.str
.s
.section
= sectp
;
12951 dwp_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
12953 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12955 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12956 dwp_file
->sections
.cu_index
.size
= bfd_get_section_size (sectp
);
12958 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12960 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12961 dwp_file
->sections
.tu_index
.size
= bfd_get_section_size (sectp
);
12965 /* This function is mapped across the sections and remembers the offset and
12966 size of each of the DWP version 2 debugging sections that we are interested
12967 in. This is split into a separate function because we don't know if we
12968 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12971 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12973 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12974 const struct dwop_section_names
*names
= &dwop_section_names
;
12975 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12977 /* Record the ELF section number for later lookup: this is what the
12978 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12979 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12980 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12982 /* Look for specific sections that we need. */
12983 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12985 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12986 dwp_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
12988 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12990 dwp_file
->sections
.info
.s
.section
= sectp
;
12991 dwp_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
12993 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12995 dwp_file
->sections
.line
.s
.section
= sectp
;
12996 dwp_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
12998 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
13000 dwp_file
->sections
.loc
.s
.section
= sectp
;
13001 dwp_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
13003 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
13005 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
13006 dwp_file
->sections
.macinfo
.size
= bfd_get_section_size (sectp
);
13008 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13010 dwp_file
->sections
.macro
.s
.section
= sectp
;
13011 dwp_file
->sections
.macro
.size
= bfd_get_section_size (sectp
);
13013 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13015 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
13016 dwp_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
13018 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13020 dwp_file
->sections
.types
.s
.section
= sectp
;
13021 dwp_file
->sections
.types
.size
= bfd_get_section_size (sectp
);
13025 /* Hash function for dwp_file loaded CUs/TUs. */
13028 hash_dwp_loaded_cutus (const void *item
)
13030 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
13032 /* This drops the top 32 bits of the signature, but is ok for a hash. */
13033 return dwo_unit
->signature
;
13036 /* Equality function for dwp_file loaded CUs/TUs. */
13039 eq_dwp_loaded_cutus (const void *a
, const void *b
)
13041 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
13042 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
13044 return dua
->signature
== dub
->signature
;
13047 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
13050 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
13052 return htab_create_alloc_ex (3,
13053 hash_dwp_loaded_cutus
,
13054 eq_dwp_loaded_cutus
,
13056 &objfile
->objfile_obstack
,
13057 hashtab_obstack_allocate
,
13058 dummy_obstack_deallocate
);
13061 /* Try to open DWP file FILE_NAME.
13062 The result is the bfd handle of the file.
13063 If there is a problem finding or opening the file, return NULL.
13064 Upon success, the canonicalized path of the file is stored in the bfd,
13065 same as symfile_bfd_open. */
13067 static gdb_bfd_ref_ptr
13068 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13069 const char *file_name
)
13071 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
13073 1 /*search_cwd*/));
13077 /* Work around upstream bug 15652.
13078 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
13079 [Whether that's a "bug" is debatable, but it is getting in our way.]
13080 We have no real idea where the dwp file is, because gdb's realpath-ing
13081 of the executable's path may have discarded the needed info.
13082 [IWBN if the dwp file name was recorded in the executable, akin to
13083 .gnu_debuglink, but that doesn't exist yet.]
13084 Strip the directory from FILE_NAME and search again. */
13085 if (*debug_file_directory
!= '\0')
13087 /* Don't implicitly search the current directory here.
13088 If the user wants to search "." to handle this case,
13089 it must be added to debug-file-directory. */
13090 return try_open_dwop_file (dwarf2_per_objfile
,
13091 lbasename (file_name
), 1 /*is_dwp*/,
13098 /* Initialize the use of the DWP file for the current objfile.
13099 By convention the name of the DWP file is ${objfile}.dwp.
13100 The result is NULL if it can't be found. */
13102 static std::unique_ptr
<struct dwp_file
>
13103 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13105 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13107 /* Try to find first .dwp for the binary file before any symbolic links
13110 /* If the objfile is a debug file, find the name of the real binary
13111 file and get the name of dwp file from there. */
13112 std::string dwp_name
;
13113 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
13115 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
13116 const char *backlink_basename
= lbasename (backlink
->original_name
);
13118 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
13121 dwp_name
= objfile
->original_name
;
13123 dwp_name
+= ".dwp";
13125 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
13127 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
13129 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
13130 dwp_name
= objfile_name (objfile
);
13131 dwp_name
+= ".dwp";
13132 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
13137 if (dwarf_read_debug
)
13138 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
13139 return std::unique_ptr
<dwp_file
> ();
13142 const char *name
= bfd_get_filename (dbfd
.get ());
13143 std::unique_ptr
<struct dwp_file
> dwp_file
13144 (new struct dwp_file (name
, std::move (dbfd
)));
13146 /* +1: section 0 is unused */
13147 dwp_file
->num_sections
= bfd_count_sections (dwp_file
->dbfd
) + 1;
13148 dwp_file
->elf_sections
=
13149 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
13150 dwp_file
->num_sections
, asection
*);
13152 bfd_map_over_sections (dwp_file
->dbfd
.get (),
13153 dwarf2_locate_common_dwp_sections
,
13156 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
13159 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
13162 /* The DWP file version is stored in the hash table. Oh well. */
13163 if (dwp_file
->cus
&& dwp_file
->tus
13164 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
13166 /* Technically speaking, we should try to limp along, but this is
13167 pretty bizarre. We use pulongest here because that's the established
13168 portability solution (e.g, we cannot use %u for uint32_t). */
13169 error (_("Dwarf Error: DWP file CU version %s doesn't match"
13170 " TU version %s [in DWP file %s]"),
13171 pulongest (dwp_file
->cus
->version
),
13172 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
13176 dwp_file
->version
= dwp_file
->cus
->version
;
13177 else if (dwp_file
->tus
)
13178 dwp_file
->version
= dwp_file
->tus
->version
;
13180 dwp_file
->version
= 2;
13182 if (dwp_file
->version
== 2)
13183 bfd_map_over_sections (dwp_file
->dbfd
.get (),
13184 dwarf2_locate_v2_dwp_sections
,
13187 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
13188 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
13190 if (dwarf_read_debug
)
13192 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
13193 fprintf_unfiltered (gdb_stdlog
,
13194 " %s CUs, %s TUs\n",
13195 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13196 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13202 /* Wrapper around open_and_init_dwp_file, only open it once. */
13204 static struct dwp_file
*
13205 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13207 if (! dwarf2_per_objfile
->dwp_checked
)
13209 dwarf2_per_objfile
->dwp_file
13210 = open_and_init_dwp_file (dwarf2_per_objfile
);
13211 dwarf2_per_objfile
->dwp_checked
= 1;
13213 return dwarf2_per_objfile
->dwp_file
.get ();
13216 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13217 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13218 or in the DWP file for the objfile, referenced by THIS_UNIT.
13219 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13220 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13222 This is called, for example, when wanting to read a variable with a
13223 complex location. Therefore we don't want to do file i/o for every call.
13224 Therefore we don't want to look for a DWO file on every call.
13225 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13226 then we check if we've already seen DWO_NAME, and only THEN do we check
13229 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13230 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13232 static struct dwo_unit
*
13233 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
13234 const char *dwo_name
, const char *comp_dir
,
13235 ULONGEST signature
, int is_debug_types
)
13237 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
13238 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13239 const char *kind
= is_debug_types
? "TU" : "CU";
13240 void **dwo_file_slot
;
13241 struct dwo_file
*dwo_file
;
13242 struct dwp_file
*dwp_file
;
13244 /* First see if there's a DWP file.
13245 If we have a DWP file but didn't find the DWO inside it, don't
13246 look for the original DWO file. It makes gdb behave differently
13247 depending on whether one is debugging in the build tree. */
13249 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
13250 if (dwp_file
!= NULL
)
13252 const struct dwp_hash_table
*dwp_htab
=
13253 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13255 if (dwp_htab
!= NULL
)
13257 struct dwo_unit
*dwo_cutu
=
13258 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
13259 signature
, is_debug_types
);
13261 if (dwo_cutu
!= NULL
)
13263 if (dwarf_read_debug
)
13265 fprintf_unfiltered (gdb_stdlog
,
13266 "Virtual DWO %s %s found: @%s\n",
13267 kind
, hex_string (signature
),
13268 host_address_to_string (dwo_cutu
));
13276 /* No DWP file, look for the DWO file. */
13278 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
13279 dwo_name
, comp_dir
);
13280 if (*dwo_file_slot
== NULL
)
13282 /* Read in the file and build a table of the CUs/TUs it contains. */
13283 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
13285 /* NOTE: This will be NULL if unable to open the file. */
13286 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13288 if (dwo_file
!= NULL
)
13290 struct dwo_unit
*dwo_cutu
= NULL
;
13292 if (is_debug_types
&& dwo_file
->tus
)
13294 struct dwo_unit find_dwo_cutu
;
13296 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13297 find_dwo_cutu
.signature
= signature
;
13299 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
13301 else if (!is_debug_types
&& dwo_file
->cus
)
13303 struct dwo_unit find_dwo_cutu
;
13305 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13306 find_dwo_cutu
.signature
= signature
;
13307 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
,
13311 if (dwo_cutu
!= NULL
)
13313 if (dwarf_read_debug
)
13315 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
13316 kind
, dwo_name
, hex_string (signature
),
13317 host_address_to_string (dwo_cutu
));
13324 /* We didn't find it. This could mean a dwo_id mismatch, or
13325 someone deleted the DWO/DWP file, or the search path isn't set up
13326 correctly to find the file. */
13328 if (dwarf_read_debug
)
13330 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
13331 kind
, dwo_name
, hex_string (signature
));
13334 /* This is a warning and not a complaint because it can be caused by
13335 pilot error (e.g., user accidentally deleting the DWO). */
13337 /* Print the name of the DWP file if we looked there, helps the user
13338 better diagnose the problem. */
13339 std::string dwp_text
;
13341 if (dwp_file
!= NULL
)
13342 dwp_text
= string_printf (" [in DWP file %s]",
13343 lbasename (dwp_file
->name
));
13345 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13346 " [in module %s]"),
13347 kind
, dwo_name
, hex_string (signature
),
13349 this_unit
->is_debug_types
? "TU" : "CU",
13350 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
13355 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13356 See lookup_dwo_cutu_unit for details. */
13358 static struct dwo_unit
*
13359 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
13360 const char *dwo_name
, const char *comp_dir
,
13361 ULONGEST signature
)
13363 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
13366 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13367 See lookup_dwo_cutu_unit for details. */
13369 static struct dwo_unit
*
13370 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
13371 const char *dwo_name
, const char *comp_dir
)
13373 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
13376 /* Traversal function for queue_and_load_all_dwo_tus. */
13379 queue_and_load_dwo_tu (void **slot
, void *info
)
13381 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13382 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
13383 ULONGEST signature
= dwo_unit
->signature
;
13384 struct signatured_type
*sig_type
=
13385 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
13387 if (sig_type
!= NULL
)
13389 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13391 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13392 a real dependency of PER_CU on SIG_TYPE. That is detected later
13393 while processing PER_CU. */
13394 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
13395 load_full_type_unit (sig_cu
);
13396 VEC_safe_push (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, sig_cu
);
13402 /* Queue all TUs contained in the DWO of PER_CU to be read in.
13403 The DWO may have the only definition of the type, though it may not be
13404 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13405 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13408 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
13410 struct dwo_unit
*dwo_unit
;
13411 struct dwo_file
*dwo_file
;
13413 gdb_assert (!per_cu
->is_debug_types
);
13414 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
13415 gdb_assert (per_cu
->cu
!= NULL
);
13417 dwo_unit
= per_cu
->cu
->dwo_unit
;
13418 gdb_assert (dwo_unit
!= NULL
);
13420 dwo_file
= dwo_unit
->dwo_file
;
13421 if (dwo_file
->tus
!= NULL
)
13422 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
13425 /* Free all resources associated with DWO_FILE.
13426 Close the DWO file and munmap the sections. */
13429 free_dwo_file (struct dwo_file
*dwo_file
)
13431 /* Note: dbfd is NULL for virtual DWO files. */
13432 gdb_bfd_unref (dwo_file
->dbfd
);
13434 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
13437 /* Traversal function for free_dwo_files. */
13440 free_dwo_file_from_slot (void **slot
, void *info
)
13442 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
13444 free_dwo_file (dwo_file
);
13449 /* Free all resources associated with DWO_FILES. */
13452 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
13454 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
13457 /* Read in various DIEs. */
13459 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13460 Inherit only the children of the DW_AT_abstract_origin DIE not being
13461 already referenced by DW_AT_abstract_origin from the children of the
13465 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13467 struct die_info
*child_die
;
13468 sect_offset
*offsetp
;
13469 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13470 struct die_info
*origin_die
;
13471 /* Iterator of the ORIGIN_DIE children. */
13472 struct die_info
*origin_child_die
;
13473 struct attribute
*attr
;
13474 struct dwarf2_cu
*origin_cu
;
13475 struct pending
**origin_previous_list_in_scope
;
13477 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13481 /* Note that following die references may follow to a die in a
13485 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13487 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13489 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13490 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13492 if (die
->tag
!= origin_die
->tag
13493 && !(die
->tag
== DW_TAG_inlined_subroutine
13494 && origin_die
->tag
== DW_TAG_subprogram
))
13495 complaint (&symfile_complaints
,
13496 _("DIE %s and its abstract origin %s have different tags"),
13497 sect_offset_str (die
->sect_off
),
13498 sect_offset_str (origin_die
->sect_off
));
13500 std::vector
<sect_offset
> offsets
;
13502 for (child_die
= die
->child
;
13503 child_die
&& child_die
->tag
;
13504 child_die
= sibling_die (child_die
))
13506 struct die_info
*child_origin_die
;
13507 struct dwarf2_cu
*child_origin_cu
;
13509 /* We are trying to process concrete instance entries:
13510 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13511 it's not relevant to our analysis here. i.e. detecting DIEs that are
13512 present in the abstract instance but not referenced in the concrete
13514 if (child_die
->tag
== DW_TAG_call_site
13515 || child_die
->tag
== DW_TAG_GNU_call_site
)
13518 /* For each CHILD_DIE, find the corresponding child of
13519 ORIGIN_DIE. If there is more than one layer of
13520 DW_AT_abstract_origin, follow them all; there shouldn't be,
13521 but GCC versions at least through 4.4 generate this (GCC PR
13523 child_origin_die
= child_die
;
13524 child_origin_cu
= cu
;
13527 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13531 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13535 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13536 counterpart may exist. */
13537 if (child_origin_die
!= child_die
)
13539 if (child_die
->tag
!= child_origin_die
->tag
13540 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13541 && child_origin_die
->tag
== DW_TAG_subprogram
))
13542 complaint (&symfile_complaints
,
13543 _("Child DIE %s and its abstract origin %s have "
13545 sect_offset_str (child_die
->sect_off
),
13546 sect_offset_str (child_origin_die
->sect_off
));
13547 if (child_origin_die
->parent
!= origin_die
)
13548 complaint (&symfile_complaints
,
13549 _("Child DIE %s and its abstract origin %s have "
13550 "different parents"),
13551 sect_offset_str (child_die
->sect_off
),
13552 sect_offset_str (child_origin_die
->sect_off
));
13554 offsets
.push_back (child_origin_die
->sect_off
);
13557 std::sort (offsets
.begin (), offsets
.end ());
13558 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13559 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13560 if (offsetp
[-1] == *offsetp
)
13561 complaint (&symfile_complaints
,
13562 _("Multiple children of DIE %s refer "
13563 "to DIE %s as their abstract origin"),
13564 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13566 offsetp
= offsets
.data ();
13567 origin_child_die
= origin_die
->child
;
13568 while (origin_child_die
&& origin_child_die
->tag
)
13570 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13571 while (offsetp
< offsets_end
13572 && *offsetp
< origin_child_die
->sect_off
)
13574 if (offsetp
>= offsets_end
13575 || *offsetp
> origin_child_die
->sect_off
)
13577 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13578 Check whether we're already processing ORIGIN_CHILD_DIE.
13579 This can happen with mutually referenced abstract_origins.
13581 if (!origin_child_die
->in_process
)
13582 process_die (origin_child_die
, origin_cu
);
13584 origin_child_die
= sibling_die (origin_child_die
);
13586 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13590 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13592 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13593 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13594 struct context_stack
*newobj
;
13597 struct die_info
*child_die
;
13598 struct attribute
*attr
, *call_line
, *call_file
;
13600 CORE_ADDR baseaddr
;
13601 struct block
*block
;
13602 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13603 std::vector
<struct symbol
*> template_args
;
13604 struct template_symbol
*templ_func
= NULL
;
13608 /* If we do not have call site information, we can't show the
13609 caller of this inlined function. That's too confusing, so
13610 only use the scope for local variables. */
13611 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13612 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13613 if (call_line
== NULL
|| call_file
== NULL
)
13615 read_lexical_block_scope (die
, cu
);
13620 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13622 name
= dwarf2_name (die
, cu
);
13624 /* Ignore functions with missing or empty names. These are actually
13625 illegal according to the DWARF standard. */
13628 complaint (&symfile_complaints
,
13629 _("missing name for subprogram DIE at %s"),
13630 sect_offset_str (die
->sect_off
));
13634 /* Ignore functions with missing or invalid low and high pc attributes. */
13635 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13636 <= PC_BOUNDS_INVALID
)
13638 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13639 if (!attr
|| !DW_UNSND (attr
))
13640 complaint (&symfile_complaints
,
13641 _("cannot get low and high bounds "
13642 "for subprogram DIE at %s"),
13643 sect_offset_str (die
->sect_off
));
13647 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13648 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13650 /* If we have any template arguments, then we must allocate a
13651 different sort of symbol. */
13652 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
13654 if (child_die
->tag
== DW_TAG_template_type_param
13655 || child_die
->tag
== DW_TAG_template_value_param
)
13657 templ_func
= allocate_template_symbol (objfile
);
13658 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13663 newobj
= push_context (0, lowpc
);
13664 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13665 (struct symbol
*) templ_func
);
13667 /* If there is a location expression for DW_AT_frame_base, record
13669 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13671 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13673 /* If there is a location for the static link, record it. */
13674 newobj
->static_link
= NULL
;
13675 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13678 newobj
->static_link
13679 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13680 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
);
13683 cu
->list_in_scope
= &local_symbols
;
13685 if (die
->child
!= NULL
)
13687 child_die
= die
->child
;
13688 while (child_die
&& child_die
->tag
)
13690 if (child_die
->tag
== DW_TAG_template_type_param
13691 || child_die
->tag
== DW_TAG_template_value_param
)
13693 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13696 template_args
.push_back (arg
);
13699 process_die (child_die
, cu
);
13700 child_die
= sibling_die (child_die
);
13704 inherit_abstract_dies (die
, cu
);
13706 /* If we have a DW_AT_specification, we might need to import using
13707 directives from the context of the specification DIE. See the
13708 comment in determine_prefix. */
13709 if (cu
->language
== language_cplus
13710 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13712 struct dwarf2_cu
*spec_cu
= cu
;
13713 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13717 child_die
= spec_die
->child
;
13718 while (child_die
&& child_die
->tag
)
13720 if (child_die
->tag
== DW_TAG_imported_module
)
13721 process_die (child_die
, spec_cu
);
13722 child_die
= sibling_die (child_die
);
13725 /* In some cases, GCC generates specification DIEs that
13726 themselves contain DW_AT_specification attributes. */
13727 spec_die
= die_specification (spec_die
, &spec_cu
);
13731 newobj
= pop_context ();
13732 /* Make a block for the local symbols within. */
13733 block
= finish_block (newobj
->name
, &local_symbols
, newobj
->old_blocks
,
13734 newobj
->static_link
, lowpc
, highpc
);
13736 /* For C++, set the block's scope. */
13737 if ((cu
->language
== language_cplus
13738 || cu
->language
== language_fortran
13739 || cu
->language
== language_d
13740 || cu
->language
== language_rust
)
13741 && cu
->processing_has_namespace_info
)
13742 block_set_scope (block
, determine_prefix (die
, cu
),
13743 &objfile
->objfile_obstack
);
13745 /* If we have address ranges, record them. */
13746 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13748 gdbarch_make_symbol_special (gdbarch
, newobj
->name
, objfile
);
13750 /* Attach template arguments to function. */
13751 if (!template_args
.empty ())
13753 gdb_assert (templ_func
!= NULL
);
13755 templ_func
->n_template_arguments
= template_args
.size ();
13756 templ_func
->template_arguments
13757 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13758 templ_func
->n_template_arguments
);
13759 memcpy (templ_func
->template_arguments
,
13760 template_args
.data (),
13761 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13764 /* In C++, we can have functions nested inside functions (e.g., when
13765 a function declares a class that has methods). This means that
13766 when we finish processing a function scope, we may need to go
13767 back to building a containing block's symbol lists. */
13768 local_symbols
= newobj
->locals
;
13769 local_using_directives
= newobj
->local_using_directives
;
13771 /* If we've finished processing a top-level function, subsequent
13772 symbols go in the file symbol list. */
13773 if (outermost_context_p ())
13774 cu
->list_in_scope
= &file_symbols
;
13777 /* Process all the DIES contained within a lexical block scope. Start
13778 a new scope, process the dies, and then close the scope. */
13781 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13783 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13784 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13785 struct context_stack
*newobj
;
13786 CORE_ADDR lowpc
, highpc
;
13787 struct die_info
*child_die
;
13788 CORE_ADDR baseaddr
;
13790 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13792 /* Ignore blocks with missing or invalid low and high pc attributes. */
13793 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13794 as multiple lexical blocks? Handling children in a sane way would
13795 be nasty. Might be easier to properly extend generic blocks to
13796 describe ranges. */
13797 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13799 case PC_BOUNDS_NOT_PRESENT
:
13800 /* DW_TAG_lexical_block has no attributes, process its children as if
13801 there was no wrapping by that DW_TAG_lexical_block.
13802 GCC does no longer produces such DWARF since GCC r224161. */
13803 for (child_die
= die
->child
;
13804 child_die
!= NULL
&& child_die
->tag
;
13805 child_die
= sibling_die (child_die
))
13806 process_die (child_die
, cu
);
13808 case PC_BOUNDS_INVALID
:
13811 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13812 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13814 push_context (0, lowpc
);
13815 if (die
->child
!= NULL
)
13817 child_die
= die
->child
;
13818 while (child_die
&& child_die
->tag
)
13820 process_die (child_die
, cu
);
13821 child_die
= sibling_die (child_die
);
13824 inherit_abstract_dies (die
, cu
);
13825 newobj
= pop_context ();
13827 if (local_symbols
!= NULL
|| local_using_directives
!= NULL
)
13829 struct block
*block
13830 = finish_block (0, &local_symbols
, newobj
->old_blocks
, NULL
,
13831 newobj
->start_addr
, highpc
);
13833 /* Note that recording ranges after traversing children, as we
13834 do here, means that recording a parent's ranges entails
13835 walking across all its children's ranges as they appear in
13836 the address map, which is quadratic behavior.
13838 It would be nicer to record the parent's ranges before
13839 traversing its children, simply overriding whatever you find
13840 there. But since we don't even decide whether to create a
13841 block until after we've traversed its children, that's hard
13843 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13845 local_symbols
= newobj
->locals
;
13846 local_using_directives
= newobj
->local_using_directives
;
13849 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13852 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13854 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13855 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13856 CORE_ADDR pc
, baseaddr
;
13857 struct attribute
*attr
;
13858 struct call_site
*call_site
, call_site_local
;
13861 struct die_info
*child_die
;
13863 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13865 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13868 /* This was a pre-DWARF-5 GNU extension alias
13869 for DW_AT_call_return_pc. */
13870 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13874 complaint (&symfile_complaints
,
13875 _("missing DW_AT_call_return_pc for DW_TAG_call_site "
13876 "DIE %s [in module %s]"),
13877 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13880 pc
= attr_value_as_address (attr
) + baseaddr
;
13881 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13883 if (cu
->call_site_htab
== NULL
)
13884 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13885 NULL
, &objfile
->objfile_obstack
,
13886 hashtab_obstack_allocate
, NULL
);
13887 call_site_local
.pc
= pc
;
13888 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13891 complaint (&symfile_complaints
,
13892 _("Duplicate PC %s for DW_TAG_call_site "
13893 "DIE %s [in module %s]"),
13894 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13895 objfile_name (objfile
));
13899 /* Count parameters at the caller. */
13902 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13903 child_die
= sibling_die (child_die
))
13905 if (child_die
->tag
!= DW_TAG_call_site_parameter
13906 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13908 complaint (&symfile_complaints
,
13909 _("Tag %d is not DW_TAG_call_site_parameter in "
13910 "DW_TAG_call_site child DIE %s [in module %s]"),
13911 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13912 objfile_name (objfile
));
13920 = ((struct call_site
*)
13921 obstack_alloc (&objfile
->objfile_obstack
,
13922 sizeof (*call_site
)
13923 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13925 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13926 call_site
->pc
= pc
;
13928 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13929 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13931 struct die_info
*func_die
;
13933 /* Skip also over DW_TAG_inlined_subroutine. */
13934 for (func_die
= die
->parent
;
13935 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13936 && func_die
->tag
!= DW_TAG_subroutine_type
;
13937 func_die
= func_die
->parent
);
13939 /* DW_AT_call_all_calls is a superset
13940 of DW_AT_call_all_tail_calls. */
13942 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13943 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13944 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13945 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13947 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13948 not complete. But keep CALL_SITE for look ups via call_site_htab,
13949 both the initial caller containing the real return address PC and
13950 the final callee containing the current PC of a chain of tail
13951 calls do not need to have the tail call list complete. But any
13952 function candidate for a virtual tail call frame searched via
13953 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13954 determined unambiguously. */
13958 struct type
*func_type
= NULL
;
13961 func_type
= get_die_type (func_die
, cu
);
13962 if (func_type
!= NULL
)
13964 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
13966 /* Enlist this call site to the function. */
13967 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13968 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13971 complaint (&symfile_complaints
,
13972 _("Cannot find function owning DW_TAG_call_site "
13973 "DIE %s [in module %s]"),
13974 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13978 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13980 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13982 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13985 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13986 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13988 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13989 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
13990 /* Keep NULL DWARF_BLOCK. */;
13991 else if (attr_form_is_block (attr
))
13993 struct dwarf2_locexpr_baton
*dlbaton
;
13995 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13996 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13997 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13998 dlbaton
->per_cu
= cu
->per_cu
;
14000 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
14002 else if (attr_form_is_ref (attr
))
14004 struct dwarf2_cu
*target_cu
= cu
;
14005 struct die_info
*target_die
;
14007 target_die
= follow_die_ref (die
, attr
, &target_cu
);
14008 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
14009 if (die_is_declaration (target_die
, target_cu
))
14011 const char *target_physname
;
14013 /* Prefer the mangled name; otherwise compute the demangled one. */
14014 target_physname
= dw2_linkage_name (target_die
, target_cu
);
14015 if (target_physname
== NULL
)
14016 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
14017 if (target_physname
== NULL
)
14018 complaint (&symfile_complaints
,
14019 _("DW_AT_call_target target DIE has invalid "
14020 "physname, for referencing DIE %s [in module %s]"),
14021 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14023 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
14029 /* DW_AT_entry_pc should be preferred. */
14030 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
14031 <= PC_BOUNDS_INVALID
)
14032 complaint (&symfile_complaints
,
14033 _("DW_AT_call_target target DIE has invalid "
14034 "low pc, for referencing DIE %s [in module %s]"),
14035 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14038 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14039 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
14044 complaint (&symfile_complaints
,
14045 _("DW_TAG_call_site DW_AT_call_target is neither "
14046 "block nor reference, for DIE %s [in module %s]"),
14047 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14049 call_site
->per_cu
= cu
->per_cu
;
14051 for (child_die
= die
->child
;
14052 child_die
&& child_die
->tag
;
14053 child_die
= sibling_die (child_die
))
14055 struct call_site_parameter
*parameter
;
14056 struct attribute
*loc
, *origin
;
14058 if (child_die
->tag
!= DW_TAG_call_site_parameter
14059 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14061 /* Already printed the complaint above. */
14065 gdb_assert (call_site
->parameter_count
< nparams
);
14066 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
14068 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
14069 specifies DW_TAG_formal_parameter. Value of the data assumed for the
14070 register is contained in DW_AT_call_value. */
14072 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
14073 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
14074 if (origin
== NULL
)
14076 /* This was a pre-DWARF-5 GNU extension alias
14077 for DW_AT_call_parameter. */
14078 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
14080 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
14082 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
14084 sect_offset sect_off
14085 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
14086 if (!offset_in_cu_p (&cu
->header
, sect_off
))
14088 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
14089 binding can be done only inside one CU. Such referenced DIE
14090 therefore cannot be even moved to DW_TAG_partial_unit. */
14091 complaint (&symfile_complaints
,
14092 _("DW_AT_call_parameter offset is not in CU for "
14093 "DW_TAG_call_site child DIE %s [in module %s]"),
14094 sect_offset_str (child_die
->sect_off
),
14095 objfile_name (objfile
));
14098 parameter
->u
.param_cu_off
14099 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
14101 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
14103 complaint (&symfile_complaints
,
14104 _("No DW_FORM_block* DW_AT_location for "
14105 "DW_TAG_call_site child DIE %s [in module %s]"),
14106 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
14111 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
14112 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
14113 if (parameter
->u
.dwarf_reg
!= -1)
14114 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
14115 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
14116 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
14117 ¶meter
->u
.fb_offset
))
14118 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
14121 complaint (&symfile_complaints
,
14122 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
14123 "for DW_FORM_block* DW_AT_location is supported for "
14124 "DW_TAG_call_site child DIE %s "
14126 sect_offset_str (child_die
->sect_off
),
14127 objfile_name (objfile
));
14132 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
14134 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
14135 if (!attr_form_is_block (attr
))
14137 complaint (&symfile_complaints
,
14138 _("No DW_FORM_block* DW_AT_call_value for "
14139 "DW_TAG_call_site child DIE %s [in module %s]"),
14140 sect_offset_str (child_die
->sect_off
),
14141 objfile_name (objfile
));
14144 parameter
->value
= DW_BLOCK (attr
)->data
;
14145 parameter
->value_size
= DW_BLOCK (attr
)->size
;
14147 /* Parameters are not pre-cleared by memset above. */
14148 parameter
->data_value
= NULL
;
14149 parameter
->data_value_size
= 0;
14150 call_site
->parameter_count
++;
14152 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
14154 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
14157 if (!attr_form_is_block (attr
))
14158 complaint (&symfile_complaints
,
14159 _("No DW_FORM_block* DW_AT_call_data_value for "
14160 "DW_TAG_call_site child DIE %s [in module %s]"),
14161 sect_offset_str (child_die
->sect_off
),
14162 objfile_name (objfile
));
14165 parameter
->data_value
= DW_BLOCK (attr
)->data
;
14166 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
14172 /* Helper function for read_variable. If DIE represents a virtual
14173 table, then return the type of the concrete object that is
14174 associated with the virtual table. Otherwise, return NULL. */
14176 static struct type
*
14177 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14179 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14183 /* Find the type DIE. */
14184 struct die_info
*type_die
= NULL
;
14185 struct dwarf2_cu
*type_cu
= cu
;
14187 if (attr_form_is_ref (attr
))
14188 type_die
= follow_die_ref (die
, attr
, &type_cu
);
14189 if (type_die
== NULL
)
14192 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
14194 return die_containing_type (type_die
, type_cu
);
14197 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
14200 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
14202 struct rust_vtable_symbol
*storage
= NULL
;
14204 if (cu
->language
== language_rust
)
14206 struct type
*containing_type
= rust_containing_type (die
, cu
);
14208 if (containing_type
!= NULL
)
14210 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14212 storage
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
14213 struct rust_vtable_symbol
);
14214 initialize_objfile_symbol (storage
);
14215 storage
->concrete_type
= containing_type
;
14216 storage
->subclass
= SYMBOL_RUST_VTABLE
;
14220 new_symbol (die
, NULL
, cu
, storage
);
14223 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14224 reading .debug_rnglists.
14225 Callback's type should be:
14226 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14227 Return true if the attributes are present and valid, otherwise,
14230 template <typename Callback
>
14232 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14233 Callback
&&callback
)
14235 struct dwarf2_per_objfile
*dwarf2_per_objfile
14236 = cu
->per_cu
->dwarf2_per_objfile
;
14237 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14238 bfd
*obfd
= objfile
->obfd
;
14239 /* Base address selection entry. */
14242 const gdb_byte
*buffer
;
14243 CORE_ADDR baseaddr
;
14244 bool overflow
= false;
14246 found_base
= cu
->base_known
;
14247 base
= cu
->base_address
;
14249 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->rnglists
);
14250 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
14252 complaint (&symfile_complaints
,
14253 _("Offset %d out of bounds for DW_AT_ranges attribute"),
14257 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
14259 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14263 /* Initialize it due to a false compiler warning. */
14264 CORE_ADDR range_beginning
= 0, range_end
= 0;
14265 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
14266 + dwarf2_per_objfile
->rnglists
.size
);
14267 unsigned int bytes_read
;
14269 if (buffer
== buf_end
)
14274 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14277 case DW_RLE_end_of_list
:
14279 case DW_RLE_base_address
:
14280 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14285 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14287 buffer
+= bytes_read
;
14289 case DW_RLE_start_length
:
14290 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14295 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14296 buffer
+= bytes_read
;
14297 range_end
= (range_beginning
14298 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14299 buffer
+= bytes_read
;
14300 if (buffer
> buf_end
)
14306 case DW_RLE_offset_pair
:
14307 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14308 buffer
+= bytes_read
;
14309 if (buffer
> buf_end
)
14314 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14315 buffer
+= bytes_read
;
14316 if (buffer
> buf_end
)
14322 case DW_RLE_start_end
:
14323 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14328 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14329 buffer
+= bytes_read
;
14330 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14331 buffer
+= bytes_read
;
14334 complaint (&symfile_complaints
,
14335 _("Invalid .debug_rnglists data (no base address)"));
14338 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14340 if (rlet
== DW_RLE_base_address
)
14345 /* We have no valid base address for the ranges
14347 complaint (&symfile_complaints
,
14348 _("Invalid .debug_rnglists data (no base address)"));
14352 if (range_beginning
> range_end
)
14354 /* Inverted range entries are invalid. */
14355 complaint (&symfile_complaints
,
14356 _("Invalid .debug_rnglists data (inverted range)"));
14360 /* Empty range entries have no effect. */
14361 if (range_beginning
== range_end
)
14364 range_beginning
+= base
;
14367 /* A not-uncommon case of bad debug info.
14368 Don't pollute the addrmap with bad data. */
14369 if (range_beginning
+ baseaddr
== 0
14370 && !dwarf2_per_objfile
->has_section_at_zero
)
14372 complaint (&symfile_complaints
,
14373 _(".debug_rnglists entry has start address of zero"
14374 " [in module %s]"), objfile_name (objfile
));
14378 callback (range_beginning
, range_end
);
14383 complaint (&symfile_complaints
,
14384 _("Offset %d is not terminated "
14385 "for DW_AT_ranges attribute"),
14393 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14394 Callback's type should be:
14395 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14396 Return 1 if the attributes are present and valid, otherwise, return 0. */
14398 template <typename Callback
>
14400 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
14401 Callback
&&callback
)
14403 struct dwarf2_per_objfile
*dwarf2_per_objfile
14404 = cu
->per_cu
->dwarf2_per_objfile
;
14405 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14406 struct comp_unit_head
*cu_header
= &cu
->header
;
14407 bfd
*obfd
= objfile
->obfd
;
14408 unsigned int addr_size
= cu_header
->addr_size
;
14409 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14410 /* Base address selection entry. */
14413 unsigned int dummy
;
14414 const gdb_byte
*buffer
;
14415 CORE_ADDR baseaddr
;
14417 if (cu_header
->version
>= 5)
14418 return dwarf2_rnglists_process (offset
, cu
, callback
);
14420 found_base
= cu
->base_known
;
14421 base
= cu
->base_address
;
14423 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
14424 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
14426 complaint (&symfile_complaints
,
14427 _("Offset %d out of bounds for DW_AT_ranges attribute"),
14431 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
14433 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14437 CORE_ADDR range_beginning
, range_end
;
14439 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
14440 buffer
+= addr_size
;
14441 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
14442 buffer
+= addr_size
;
14443 offset
+= 2 * addr_size
;
14445 /* An end of list marker is a pair of zero addresses. */
14446 if (range_beginning
== 0 && range_end
== 0)
14447 /* Found the end of list entry. */
14450 /* Each base address selection entry is a pair of 2 values.
14451 The first is the largest possible address, the second is
14452 the base address. Check for a base address here. */
14453 if ((range_beginning
& mask
) == mask
)
14455 /* If we found the largest possible address, then we already
14456 have the base address in range_end. */
14464 /* We have no valid base address for the ranges
14466 complaint (&symfile_complaints
,
14467 _("Invalid .debug_ranges data (no base address)"));
14471 if (range_beginning
> range_end
)
14473 /* Inverted range entries are invalid. */
14474 complaint (&symfile_complaints
,
14475 _("Invalid .debug_ranges data (inverted range)"));
14479 /* Empty range entries have no effect. */
14480 if (range_beginning
== range_end
)
14483 range_beginning
+= base
;
14486 /* A not-uncommon case of bad debug info.
14487 Don't pollute the addrmap with bad data. */
14488 if (range_beginning
+ baseaddr
== 0
14489 && !dwarf2_per_objfile
->has_section_at_zero
)
14491 complaint (&symfile_complaints
,
14492 _(".debug_ranges entry has start address of zero"
14493 " [in module %s]"), objfile_name (objfile
));
14497 callback (range_beginning
, range_end
);
14503 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14504 Return 1 if the attributes are present and valid, otherwise, return 0.
14505 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14508 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14509 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14510 struct partial_symtab
*ranges_pst
)
14512 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14513 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14514 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
14515 SECT_OFF_TEXT (objfile
));
14518 CORE_ADDR high
= 0;
14521 retval
= dwarf2_ranges_process (offset
, cu
,
14522 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14524 if (ranges_pst
!= NULL
)
14529 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
14530 range_beginning
+ baseaddr
);
14531 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
14532 range_end
+ baseaddr
);
14533 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
14537 /* FIXME: This is recording everything as a low-high
14538 segment of consecutive addresses. We should have a
14539 data structure for discontiguous block ranges
14543 low
= range_beginning
;
14549 if (range_beginning
< low
)
14550 low
= range_beginning
;
14551 if (range_end
> high
)
14559 /* If the first entry is an end-of-list marker, the range
14560 describes an empty scope, i.e. no instructions. */
14566 *high_return
= high
;
14570 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14571 definition for the return value. *LOWPC and *HIGHPC are set iff
14572 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14574 static enum pc_bounds_kind
14575 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14576 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14577 struct partial_symtab
*pst
)
14579 struct dwarf2_per_objfile
*dwarf2_per_objfile
14580 = cu
->per_cu
->dwarf2_per_objfile
;
14581 struct attribute
*attr
;
14582 struct attribute
*attr_high
;
14584 CORE_ADDR high
= 0;
14585 enum pc_bounds_kind ret
;
14587 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14590 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14593 low
= attr_value_as_address (attr
);
14594 high
= attr_value_as_address (attr_high
);
14595 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14599 /* Found high w/o low attribute. */
14600 return PC_BOUNDS_INVALID
;
14602 /* Found consecutive range of addresses. */
14603 ret
= PC_BOUNDS_HIGH_LOW
;
14607 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14610 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
14611 We take advantage of the fact that DW_AT_ranges does not appear
14612 in DW_TAG_compile_unit of DWO files. */
14613 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14614 unsigned int ranges_offset
= (DW_UNSND (attr
)
14615 + (need_ranges_base
14619 /* Value of the DW_AT_ranges attribute is the offset in the
14620 .debug_ranges section. */
14621 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14622 return PC_BOUNDS_INVALID
;
14623 /* Found discontinuous range of addresses. */
14624 ret
= PC_BOUNDS_RANGES
;
14627 return PC_BOUNDS_NOT_PRESENT
;
14630 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14632 return PC_BOUNDS_INVALID
;
14634 /* When using the GNU linker, .gnu.linkonce. sections are used to
14635 eliminate duplicate copies of functions and vtables and such.
14636 The linker will arbitrarily choose one and discard the others.
14637 The AT_*_pc values for such functions refer to local labels in
14638 these sections. If the section from that file was discarded, the
14639 labels are not in the output, so the relocs get a value of 0.
14640 If this is a discarded function, mark the pc bounds as invalid,
14641 so that GDB will ignore it. */
14642 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
14643 return PC_BOUNDS_INVALID
;
14651 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14652 its low and high PC addresses. Do nothing if these addresses could not
14653 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14654 and HIGHPC to the high address if greater than HIGHPC. */
14657 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14658 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14659 struct dwarf2_cu
*cu
)
14661 CORE_ADDR low
, high
;
14662 struct die_info
*child
= die
->child
;
14664 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14666 *lowpc
= std::min (*lowpc
, low
);
14667 *highpc
= std::max (*highpc
, high
);
14670 /* If the language does not allow nested subprograms (either inside
14671 subprograms or lexical blocks), we're done. */
14672 if (cu
->language
!= language_ada
)
14675 /* Check all the children of the given DIE. If it contains nested
14676 subprograms, then check their pc bounds. Likewise, we need to
14677 check lexical blocks as well, as they may also contain subprogram
14679 while (child
&& child
->tag
)
14681 if (child
->tag
== DW_TAG_subprogram
14682 || child
->tag
== DW_TAG_lexical_block
)
14683 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14684 child
= sibling_die (child
);
14688 /* Get the low and high pc's represented by the scope DIE, and store
14689 them in *LOWPC and *HIGHPC. If the correct values can't be
14690 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14693 get_scope_pc_bounds (struct die_info
*die
,
14694 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14695 struct dwarf2_cu
*cu
)
14697 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14698 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14699 CORE_ADDR current_low
, current_high
;
14701 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14702 >= PC_BOUNDS_RANGES
)
14704 best_low
= current_low
;
14705 best_high
= current_high
;
14709 struct die_info
*child
= die
->child
;
14711 while (child
&& child
->tag
)
14713 switch (child
->tag
) {
14714 case DW_TAG_subprogram
:
14715 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14717 case DW_TAG_namespace
:
14718 case DW_TAG_module
:
14719 /* FIXME: carlton/2004-01-16: Should we do this for
14720 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14721 that current GCC's always emit the DIEs corresponding
14722 to definitions of methods of classes as children of a
14723 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14724 the DIEs giving the declarations, which could be
14725 anywhere). But I don't see any reason why the
14726 standards says that they have to be there. */
14727 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14729 if (current_low
!= ((CORE_ADDR
) -1))
14731 best_low
= std::min (best_low
, current_low
);
14732 best_high
= std::max (best_high
, current_high
);
14740 child
= sibling_die (child
);
14745 *highpc
= best_high
;
14748 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14752 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14753 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14755 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14756 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14757 struct attribute
*attr
;
14758 struct attribute
*attr_high
;
14760 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14763 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14766 CORE_ADDR low
= attr_value_as_address (attr
);
14767 CORE_ADDR high
= attr_value_as_address (attr_high
);
14769 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14772 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14773 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14774 record_block_range (block
, low
, high
- 1);
14778 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14781 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
14782 We take advantage of the fact that DW_AT_ranges does not appear
14783 in DW_TAG_compile_unit of DWO files. */
14784 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14786 /* The value of the DW_AT_ranges attribute is the offset of the
14787 address range list in the .debug_ranges section. */
14788 unsigned long offset
= (DW_UNSND (attr
)
14789 + (need_ranges_base
? cu
->ranges_base
: 0));
14791 dwarf2_ranges_process (offset
, cu
,
14792 [&] (CORE_ADDR start
, CORE_ADDR end
)
14796 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14797 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14798 record_block_range (block
, start
, end
- 1);
14803 /* Check whether the producer field indicates either of GCC < 4.6, or the
14804 Intel C/C++ compiler, and cache the result in CU. */
14807 check_producer (struct dwarf2_cu
*cu
)
14811 if (cu
->producer
== NULL
)
14813 /* For unknown compilers expect their behavior is DWARF version
14816 GCC started to support .debug_types sections by -gdwarf-4 since
14817 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14818 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14819 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14820 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14822 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14824 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14825 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14827 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14828 cu
->producer_is_icc_lt_14
= major
< 14;
14831 /* For other non-GCC compilers, expect their behavior is DWARF version
14835 cu
->checked_producer
= 1;
14838 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14839 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14840 during 4.6.0 experimental. */
14843 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14845 if (!cu
->checked_producer
)
14846 check_producer (cu
);
14848 return cu
->producer_is_gxx_lt_4_6
;
14851 /* Return the default accessibility type if it is not overriden by
14852 DW_AT_accessibility. */
14854 static enum dwarf_access_attribute
14855 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14857 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14859 /* The default DWARF 2 accessibility for members is public, the default
14860 accessibility for inheritance is private. */
14862 if (die
->tag
!= DW_TAG_inheritance
)
14863 return DW_ACCESS_public
;
14865 return DW_ACCESS_private
;
14869 /* DWARF 3+ defines the default accessibility a different way. The same
14870 rules apply now for DW_TAG_inheritance as for the members and it only
14871 depends on the container kind. */
14873 if (die
->parent
->tag
== DW_TAG_class_type
)
14874 return DW_ACCESS_private
;
14876 return DW_ACCESS_public
;
14880 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14881 offset. If the attribute was not found return 0, otherwise return
14882 1. If it was found but could not properly be handled, set *OFFSET
14886 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14889 struct attribute
*attr
;
14891 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14896 /* Note that we do not check for a section offset first here.
14897 This is because DW_AT_data_member_location is new in DWARF 4,
14898 so if we see it, we can assume that a constant form is really
14899 a constant and not a section offset. */
14900 if (attr_form_is_constant (attr
))
14901 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
14902 else if (attr_form_is_section_offset (attr
))
14903 dwarf2_complex_location_expr_complaint ();
14904 else if (attr_form_is_block (attr
))
14905 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14907 dwarf2_complex_location_expr_complaint ();
14915 /* Add an aggregate field to the field list. */
14918 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14919 struct dwarf2_cu
*cu
)
14921 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14922 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14923 struct nextfield
*new_field
;
14924 struct attribute
*attr
;
14926 const char *fieldname
= "";
14928 if (die
->tag
== DW_TAG_inheritance
)
14930 fip
->baseclasses
.emplace_back ();
14931 new_field
= &fip
->baseclasses
.back ();
14935 fip
->fields
.emplace_back ();
14936 new_field
= &fip
->fields
.back ();
14941 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14943 new_field
->accessibility
= DW_UNSND (attr
);
14945 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14946 if (new_field
->accessibility
!= DW_ACCESS_public
)
14947 fip
->non_public_fields
= 1;
14949 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14951 new_field
->virtuality
= DW_UNSND (attr
);
14953 new_field
->virtuality
= DW_VIRTUALITY_none
;
14955 fp
= &new_field
->field
;
14957 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14961 /* Data member other than a C++ static data member. */
14963 /* Get type of field. */
14964 fp
->type
= die_type (die
, cu
);
14966 SET_FIELD_BITPOS (*fp
, 0);
14968 /* Get bit size of field (zero if none). */
14969 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14972 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14976 FIELD_BITSIZE (*fp
) = 0;
14979 /* Get bit offset of field. */
14980 if (handle_data_member_location (die
, cu
, &offset
))
14981 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14982 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14985 if (gdbarch_bits_big_endian (gdbarch
))
14987 /* For big endian bits, the DW_AT_bit_offset gives the
14988 additional bit offset from the MSB of the containing
14989 anonymous object to the MSB of the field. We don't
14990 have to do anything special since we don't need to
14991 know the size of the anonymous object. */
14992 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14996 /* For little endian bits, compute the bit offset to the
14997 MSB of the anonymous object, subtract off the number of
14998 bits from the MSB of the field to the MSB of the
14999 object, and then subtract off the number of bits of
15000 the field itself. The result is the bit offset of
15001 the LSB of the field. */
15002 int anonymous_size
;
15003 int bit_offset
= DW_UNSND (attr
);
15005 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15008 /* The size of the anonymous object containing
15009 the bit field is explicit, so use the
15010 indicated size (in bytes). */
15011 anonymous_size
= DW_UNSND (attr
);
15015 /* The size of the anonymous object containing
15016 the bit field must be inferred from the type
15017 attribute of the data member containing the
15019 anonymous_size
= TYPE_LENGTH (fp
->type
);
15021 SET_FIELD_BITPOS (*fp
,
15022 (FIELD_BITPOS (*fp
)
15023 + anonymous_size
* bits_per_byte
15024 - bit_offset
- FIELD_BITSIZE (*fp
)));
15027 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15029 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15030 + dwarf2_get_attr_constant_value (attr
, 0)));
15032 /* Get name of field. */
15033 fieldname
= dwarf2_name (die
, cu
);
15034 if (fieldname
== NULL
)
15037 /* The name is already allocated along with this objfile, so we don't
15038 need to duplicate it for the type. */
15039 fp
->name
= fieldname
;
15041 /* Change accessibility for artificial fields (e.g. virtual table
15042 pointer or virtual base class pointer) to private. */
15043 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
15045 FIELD_ARTIFICIAL (*fp
) = 1;
15046 new_field
->accessibility
= DW_ACCESS_private
;
15047 fip
->non_public_fields
= 1;
15050 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
15052 /* C++ static member. */
15054 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
15055 is a declaration, but all versions of G++ as of this writing
15056 (so through at least 3.2.1) incorrectly generate
15057 DW_TAG_variable tags. */
15059 const char *physname
;
15061 /* Get name of field. */
15062 fieldname
= dwarf2_name (die
, cu
);
15063 if (fieldname
== NULL
)
15066 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15068 /* Only create a symbol if this is an external value.
15069 new_symbol checks this and puts the value in the global symbol
15070 table, which we want. If it is not external, new_symbol
15071 will try to put the value in cu->list_in_scope which is wrong. */
15072 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
15074 /* A static const member, not much different than an enum as far as
15075 we're concerned, except that we can support more types. */
15076 new_symbol (die
, NULL
, cu
);
15079 /* Get physical name. */
15080 physname
= dwarf2_physname (fieldname
, die
, cu
);
15082 /* The name is already allocated along with this objfile, so we don't
15083 need to duplicate it for the type. */
15084 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
15085 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15086 FIELD_NAME (*fp
) = fieldname
;
15088 else if (die
->tag
== DW_TAG_inheritance
)
15092 /* C++ base class field. */
15093 if (handle_data_member_location (die
, cu
, &offset
))
15094 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15095 FIELD_BITSIZE (*fp
) = 0;
15096 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15097 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
15099 else if (die
->tag
== DW_TAG_variant_part
)
15101 /* process_structure_scope will treat this DIE as a union. */
15102 process_structure_scope (die
, cu
);
15104 /* The variant part is relative to the start of the enclosing
15106 SET_FIELD_BITPOS (*fp
, 0);
15107 fp
->type
= get_die_type (die
, cu
);
15108 fp
->artificial
= 1;
15109 fp
->name
= "<<variant>>";
15112 gdb_assert_not_reached ("missing case in dwarf2_add_field");
15115 /* Can the type given by DIE define another type? */
15118 type_can_define_types (const struct die_info
*die
)
15122 case DW_TAG_typedef
:
15123 case DW_TAG_class_type
:
15124 case DW_TAG_structure_type
:
15125 case DW_TAG_union_type
:
15126 case DW_TAG_enumeration_type
:
15134 /* Add a type definition defined in the scope of the FIP's class. */
15137 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
15138 struct dwarf2_cu
*cu
)
15140 struct decl_field fp
;
15141 memset (&fp
, 0, sizeof (fp
));
15143 gdb_assert (type_can_define_types (die
));
15145 /* Get name of field. NULL is okay here, meaning an anonymous type. */
15146 fp
.name
= dwarf2_name (die
, cu
);
15147 fp
.type
= read_type_die (die
, cu
);
15149 /* Save accessibility. */
15150 enum dwarf_access_attribute accessibility
;
15151 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15153 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15155 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15156 switch (accessibility
)
15158 case DW_ACCESS_public
:
15159 /* The assumed value if neither private nor protected. */
15161 case DW_ACCESS_private
:
15164 case DW_ACCESS_protected
:
15165 fp
.is_protected
= 1;
15168 complaint (&symfile_complaints
,
15169 _("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
15172 if (die
->tag
== DW_TAG_typedef
)
15173 fip
->typedef_field_list
.push_back (fp
);
15175 fip
->nested_types_list
.push_back (fp
);
15178 /* Create the vector of fields, and attach it to the type. */
15181 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15182 struct dwarf2_cu
*cu
)
15184 int nfields
= fip
->nfields
;
15186 /* Record the field count, allocate space for the array of fields,
15187 and create blank accessibility bitfields if necessary. */
15188 TYPE_NFIELDS (type
) = nfields
;
15189 TYPE_FIELDS (type
) = (struct field
*)
15190 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
15192 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15194 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15196 TYPE_FIELD_PRIVATE_BITS (type
) =
15197 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15198 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15200 TYPE_FIELD_PROTECTED_BITS (type
) =
15201 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15202 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15204 TYPE_FIELD_IGNORE_BITS (type
) =
15205 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15206 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15209 /* If the type has baseclasses, allocate and clear a bit vector for
15210 TYPE_FIELD_VIRTUAL_BITS. */
15211 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15213 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15214 unsigned char *pointer
;
15216 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15217 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15218 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15219 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15220 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15223 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
15225 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
15227 for (int index
= 0; index
< nfields
; ++index
)
15229 struct nextfield
&field
= fip
->fields
[index
];
15231 if (field
.variant
.is_discriminant
)
15232 di
->discriminant_index
= index
;
15233 else if (field
.variant
.default_branch
)
15234 di
->default_index
= index
;
15236 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
15240 /* Copy the saved-up fields into the field vector. */
15241 for (int i
= 0; i
< nfields
; ++i
)
15243 struct nextfield
&field
15244 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15245 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15247 TYPE_FIELD (type
, i
) = field
.field
;
15248 switch (field
.accessibility
)
15250 case DW_ACCESS_private
:
15251 if (cu
->language
!= language_ada
)
15252 SET_TYPE_FIELD_PRIVATE (type
, i
);
15255 case DW_ACCESS_protected
:
15256 if (cu
->language
!= language_ada
)
15257 SET_TYPE_FIELD_PROTECTED (type
, i
);
15260 case DW_ACCESS_public
:
15264 /* Unknown accessibility. Complain and treat it as public. */
15266 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
15267 field
.accessibility
);
15271 if (i
< fip
->baseclasses
.size ())
15273 switch (field
.virtuality
)
15275 case DW_VIRTUALITY_virtual
:
15276 case DW_VIRTUALITY_pure_virtual
:
15277 if (cu
->language
== language_ada
)
15278 error (_("unexpected virtuality in component of Ada type"));
15279 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15286 /* Return true if this member function is a constructor, false
15290 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15292 const char *fieldname
;
15293 const char *type_name
;
15296 if (die
->parent
== NULL
)
15299 if (die
->parent
->tag
!= DW_TAG_structure_type
15300 && die
->parent
->tag
!= DW_TAG_union_type
15301 && die
->parent
->tag
!= DW_TAG_class_type
)
15304 fieldname
= dwarf2_name (die
, cu
);
15305 type_name
= dwarf2_name (die
->parent
, cu
);
15306 if (fieldname
== NULL
|| type_name
== NULL
)
15309 len
= strlen (fieldname
);
15310 return (strncmp (fieldname
, type_name
, len
) == 0
15311 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15314 /* Add a member function to the proper fieldlist. */
15317 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15318 struct type
*type
, struct dwarf2_cu
*cu
)
15320 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15321 struct attribute
*attr
;
15323 struct fnfieldlist
*flp
= nullptr;
15324 struct fn_field
*fnp
;
15325 const char *fieldname
;
15326 struct type
*this_type
;
15327 enum dwarf_access_attribute accessibility
;
15329 if (cu
->language
== language_ada
)
15330 error (_("unexpected member function in Ada type"));
15332 /* Get name of member function. */
15333 fieldname
= dwarf2_name (die
, cu
);
15334 if (fieldname
== NULL
)
15337 /* Look up member function name in fieldlist. */
15338 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15340 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15342 flp
= &fip
->fnfieldlists
[i
];
15347 /* Create a new fnfieldlist if necessary. */
15348 if (flp
== nullptr)
15350 fip
->fnfieldlists
.emplace_back ();
15351 flp
= &fip
->fnfieldlists
.back ();
15352 flp
->name
= fieldname
;
15353 i
= fip
->fnfieldlists
.size () - 1;
15356 /* Create a new member function field and add it to the vector of
15358 flp
->fnfields
.emplace_back ();
15359 fnp
= &flp
->fnfields
.back ();
15361 /* Delay processing of the physname until later. */
15362 if (cu
->language
== language_cplus
)
15363 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15367 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15368 fnp
->physname
= physname
? physname
: "";
15371 fnp
->type
= alloc_type (objfile
);
15372 this_type
= read_type_die (die
, cu
);
15373 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
15375 int nparams
= TYPE_NFIELDS (this_type
);
15377 /* TYPE is the domain of this method, and THIS_TYPE is the type
15378 of the method itself (TYPE_CODE_METHOD). */
15379 smash_to_method_type (fnp
->type
, type
,
15380 TYPE_TARGET_TYPE (this_type
),
15381 TYPE_FIELDS (this_type
),
15382 TYPE_NFIELDS (this_type
),
15383 TYPE_VARARGS (this_type
));
15385 /* Handle static member functions.
15386 Dwarf2 has no clean way to discern C++ static and non-static
15387 member functions. G++ helps GDB by marking the first
15388 parameter for non-static member functions (which is the this
15389 pointer) as artificial. We obtain this information from
15390 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15391 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15392 fnp
->voffset
= VOFFSET_STATIC
;
15395 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
15396 dwarf2_full_name (fieldname
, die
, cu
));
15398 /* Get fcontext from DW_AT_containing_type if present. */
15399 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15400 fnp
->fcontext
= die_containing_type (die
, cu
);
15402 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15403 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15405 /* Get accessibility. */
15406 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15408 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15410 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15411 switch (accessibility
)
15413 case DW_ACCESS_private
:
15414 fnp
->is_private
= 1;
15416 case DW_ACCESS_protected
:
15417 fnp
->is_protected
= 1;
15421 /* Check for artificial methods. */
15422 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15423 if (attr
&& DW_UNSND (attr
) != 0)
15424 fnp
->is_artificial
= 1;
15426 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15428 /* Get index in virtual function table if it is a virtual member
15429 function. For older versions of GCC, this is an offset in the
15430 appropriate virtual table, as specified by DW_AT_containing_type.
15431 For everyone else, it is an expression to be evaluated relative
15432 to the object address. */
15434 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15437 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
15439 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15441 /* Old-style GCC. */
15442 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15444 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15445 || (DW_BLOCK (attr
)->size
> 1
15446 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15447 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15449 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15450 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15451 dwarf2_complex_location_expr_complaint ();
15453 fnp
->voffset
/= cu
->header
.addr_size
;
15457 dwarf2_complex_location_expr_complaint ();
15459 if (!fnp
->fcontext
)
15461 /* If there is no `this' field and no DW_AT_containing_type,
15462 we cannot actually find a base class context for the
15464 if (TYPE_NFIELDS (this_type
) == 0
15465 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15467 complaint (&symfile_complaints
,
15468 _("cannot determine context for virtual member "
15469 "function \"%s\" (offset %s)"),
15470 fieldname
, sect_offset_str (die
->sect_off
));
15475 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15479 else if (attr_form_is_section_offset (attr
))
15481 dwarf2_complex_location_expr_complaint ();
15485 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15491 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15492 if (attr
&& DW_UNSND (attr
))
15494 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15495 complaint (&symfile_complaints
,
15496 _("Member function \"%s\" (offset %s) is virtual "
15497 "but the vtable offset is not specified"),
15498 fieldname
, sect_offset_str (die
->sect_off
));
15499 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15500 TYPE_CPLUS_DYNAMIC (type
) = 1;
15505 /* Create the vector of member function fields, and attach it to the type. */
15508 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15509 struct dwarf2_cu
*cu
)
15511 if (cu
->language
== language_ada
)
15512 error (_("unexpected member functions in Ada type"));
15514 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15515 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15517 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15519 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15521 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15522 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15524 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15525 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15526 fn_flp
->fn_fields
= (struct fn_field
*)
15527 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15529 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15530 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15533 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15536 /* Returns non-zero if NAME is the name of a vtable member in CU's
15537 language, zero otherwise. */
15539 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15541 static const char vptr
[] = "_vptr";
15543 /* Look for the C++ form of the vtable. */
15544 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15550 /* GCC outputs unnamed structures that are really pointers to member
15551 functions, with the ABI-specified layout. If TYPE describes
15552 such a structure, smash it into a member function type.
15554 GCC shouldn't do this; it should just output pointer to member DIEs.
15555 This is GCC PR debug/28767. */
15558 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15560 struct type
*pfn_type
, *self_type
, *new_type
;
15562 /* Check for a structure with no name and two children. */
15563 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
15566 /* Check for __pfn and __delta members. */
15567 if (TYPE_FIELD_NAME (type
, 0) == NULL
15568 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15569 || TYPE_FIELD_NAME (type
, 1) == NULL
15570 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15573 /* Find the type of the method. */
15574 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15575 if (pfn_type
== NULL
15576 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
15577 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
15580 /* Look for the "this" argument. */
15581 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15582 if (TYPE_NFIELDS (pfn_type
) == 0
15583 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15584 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
15587 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15588 new_type
= alloc_type (objfile
);
15589 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15590 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
15591 TYPE_VARARGS (pfn_type
));
15592 smash_to_methodptr_type (type
, new_type
);
15595 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15596 appropriate error checking and issuing complaints if there is a
15600 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15602 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15604 if (attr
== nullptr)
15607 if (!attr_form_is_constant (attr
))
15609 complaint (&symfile_complaints
,
15610 _("DW_AT_alignment must have constant form"
15611 " - DIE at %s [in module %s]"),
15612 sect_offset_str (die
->sect_off
),
15613 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15618 if (attr
->form
== DW_FORM_sdata
)
15620 LONGEST val
= DW_SND (attr
);
15623 complaint (&symfile_complaints
,
15624 _("DW_AT_alignment value must not be negative"
15625 " - DIE at %s [in module %s]"),
15626 sect_offset_str (die
->sect_off
),
15627 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15633 align
= DW_UNSND (attr
);
15637 complaint (&symfile_complaints
,
15638 _("DW_AT_alignment value must not be zero"
15639 " - DIE at %s [in module %s]"),
15640 sect_offset_str (die
->sect_off
),
15641 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15644 if ((align
& (align
- 1)) != 0)
15646 complaint (&symfile_complaints
,
15647 _("DW_AT_alignment value must be a power of 2"
15648 " - DIE at %s [in module %s]"),
15649 sect_offset_str (die
->sect_off
),
15650 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15657 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15658 the alignment for TYPE. */
15661 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15664 if (!set_type_align (type
, get_alignment (cu
, die
)))
15665 complaint (&symfile_complaints
,
15666 _("DW_AT_alignment value too large"
15667 " - DIE at %s [in module %s]"),
15668 sect_offset_str (die
->sect_off
),
15669 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15672 /* Called when we find the DIE that starts a structure or union scope
15673 (definition) to create a type for the structure or union. Fill in
15674 the type's name and general properties; the members will not be
15675 processed until process_structure_scope. A symbol table entry for
15676 the type will also not be done until process_structure_scope (assuming
15677 the type has a name).
15679 NOTE: we need to call these functions regardless of whether or not the
15680 DIE has a DW_AT_name attribute, since it might be an anonymous
15681 structure or union. This gets the type entered into our set of
15682 user defined types. */
15684 static struct type
*
15685 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15687 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15689 struct attribute
*attr
;
15692 /* If the definition of this type lives in .debug_types, read that type.
15693 Don't follow DW_AT_specification though, that will take us back up
15694 the chain and we want to go down. */
15695 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15698 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15700 /* The type's CU may not be the same as CU.
15701 Ensure TYPE is recorded with CU in die_type_hash. */
15702 return set_die_type (die
, type
, cu
);
15705 type
= alloc_type (objfile
);
15706 INIT_CPLUS_SPECIFIC (type
);
15708 name
= dwarf2_name (die
, cu
);
15711 if (cu
->language
== language_cplus
15712 || cu
->language
== language_d
15713 || cu
->language
== language_rust
)
15715 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15717 /* dwarf2_full_name might have already finished building the DIE's
15718 type. If so, there is no need to continue. */
15719 if (get_die_type (die
, cu
) != NULL
)
15720 return get_die_type (die
, cu
);
15722 TYPE_TAG_NAME (type
) = full_name
;
15723 if (die
->tag
== DW_TAG_structure_type
15724 || die
->tag
== DW_TAG_class_type
)
15725 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
15729 /* The name is already allocated along with this objfile, so
15730 we don't need to duplicate it for the type. */
15731 TYPE_TAG_NAME (type
) = name
;
15732 if (die
->tag
== DW_TAG_class_type
)
15733 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
15737 if (die
->tag
== DW_TAG_structure_type
)
15739 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15741 else if (die
->tag
== DW_TAG_union_type
)
15743 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15745 else if (die
->tag
== DW_TAG_variant_part
)
15747 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15748 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15752 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15755 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15756 TYPE_DECLARED_CLASS (type
) = 1;
15758 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15761 if (attr_form_is_constant (attr
))
15762 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15765 /* For the moment, dynamic type sizes are not supported
15766 by GDB's struct type. The actual size is determined
15767 on-demand when resolving the type of a given object,
15768 so set the type's length to zero for now. Otherwise,
15769 we record an expression as the length, and that expression
15770 could lead to a very large value, which could eventually
15771 lead to us trying to allocate that much memory when creating
15772 a value of that type. */
15773 TYPE_LENGTH (type
) = 0;
15778 TYPE_LENGTH (type
) = 0;
15781 maybe_set_alignment (cu
, die
, type
);
15783 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15785 /* ICC<14 does not output the required DW_AT_declaration on
15786 incomplete types, but gives them a size of zero. */
15787 TYPE_STUB (type
) = 1;
15790 TYPE_STUB_SUPPORTED (type
) = 1;
15792 if (die_is_declaration (die
, cu
))
15793 TYPE_STUB (type
) = 1;
15794 else if (attr
== NULL
&& die
->child
== NULL
15795 && producer_is_realview (cu
->producer
))
15796 /* RealView does not output the required DW_AT_declaration
15797 on incomplete types. */
15798 TYPE_STUB (type
) = 1;
15800 /* We need to add the type field to the die immediately so we don't
15801 infinitely recurse when dealing with pointers to the structure
15802 type within the structure itself. */
15803 set_die_type (die
, type
, cu
);
15805 /* set_die_type should be already done. */
15806 set_descriptive_type (type
, die
, cu
);
15811 /* A helper for process_structure_scope that handles a single member
15815 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15816 struct field_info
*fi
,
15817 std::vector
<struct symbol
*> *template_args
,
15818 struct dwarf2_cu
*cu
)
15820 if (child_die
->tag
== DW_TAG_member
15821 || child_die
->tag
== DW_TAG_variable
15822 || child_die
->tag
== DW_TAG_variant_part
)
15824 /* NOTE: carlton/2002-11-05: A C++ static data member
15825 should be a DW_TAG_member that is a declaration, but
15826 all versions of G++ as of this writing (so through at
15827 least 3.2.1) incorrectly generate DW_TAG_variable
15828 tags for them instead. */
15829 dwarf2_add_field (fi
, child_die
, cu
);
15831 else if (child_die
->tag
== DW_TAG_subprogram
)
15833 /* Rust doesn't have member functions in the C++ sense.
15834 However, it does emit ordinary functions as children
15835 of a struct DIE. */
15836 if (cu
->language
== language_rust
)
15837 read_func_scope (child_die
, cu
);
15840 /* C++ member function. */
15841 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15844 else if (child_die
->tag
== DW_TAG_inheritance
)
15846 /* C++ base class field. */
15847 dwarf2_add_field (fi
, child_die
, cu
);
15849 else if (type_can_define_types (child_die
))
15850 dwarf2_add_type_defn (fi
, child_die
, cu
);
15851 else if (child_die
->tag
== DW_TAG_template_type_param
15852 || child_die
->tag
== DW_TAG_template_value_param
)
15854 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15857 template_args
->push_back (arg
);
15859 else if (child_die
->tag
== DW_TAG_variant
)
15861 /* In a variant we want to get the discriminant and also add a
15862 field for our sole member child. */
15863 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
15865 for (struct die_info
*variant_child
= child_die
->child
;
15866 variant_child
!= NULL
;
15867 variant_child
= sibling_die (variant_child
))
15869 if (variant_child
->tag
== DW_TAG_member
)
15871 handle_struct_member_die (variant_child
, type
, fi
,
15872 template_args
, cu
);
15873 /* Only handle the one. */
15878 /* We don't handle this but we might as well report it if we see
15880 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
15881 complaint (&symfile_complaints
,
15882 _("DW_AT_discr_list is not supported yet"
15883 " - DIE at %s [in module %s]"),
15884 sect_offset_str (child_die
->sect_off
),
15885 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15887 /* The first field was just added, so we can stash the
15888 discriminant there. */
15889 gdb_assert (!fi
->fields
.empty ());
15891 fi
->fields
.back ().variant
.default_branch
= true;
15893 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
15897 /* Finish creating a structure or union type, including filling in
15898 its members and creating a symbol for it. */
15901 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15903 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15904 struct die_info
*child_die
;
15907 type
= get_die_type (die
, cu
);
15909 type
= read_structure_type (die
, cu
);
15911 /* When reading a DW_TAG_variant_part, we need to notice when we
15912 read the discriminant member, so we can record it later in the
15913 discriminant_info. */
15914 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
15915 sect_offset discr_offset
;
15917 if (is_variant_part
)
15919 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15922 /* Maybe it's a univariant form, an extension we support.
15923 In this case arrange not to check the offset. */
15924 is_variant_part
= false;
15926 else if (attr_form_is_ref (discr
))
15928 struct dwarf2_cu
*target_cu
= cu
;
15929 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15931 discr_offset
= target_die
->sect_off
;
15935 complaint (&symfile_complaints
,
15936 _("DW_AT_discr does not have DIE reference form"
15937 " - DIE at %s [in module %s]"),
15938 sect_offset_str (die
->sect_off
),
15939 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15940 is_variant_part
= false;
15944 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15946 struct field_info fi
;
15947 std::vector
<struct symbol
*> template_args
;
15949 child_die
= die
->child
;
15951 while (child_die
&& child_die
->tag
)
15953 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15955 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
15956 fi
.fields
.back ().variant
.is_discriminant
= true;
15958 child_die
= sibling_die (child_die
);
15961 /* Attach template arguments to type. */
15962 if (!template_args
.empty ())
15964 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15965 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15966 TYPE_TEMPLATE_ARGUMENTS (type
)
15967 = XOBNEWVEC (&objfile
->objfile_obstack
,
15969 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15970 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15971 template_args
.data (),
15972 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15973 * sizeof (struct symbol
*)));
15976 /* Attach fields and member functions to the type. */
15978 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15979 if (!fi
.fnfieldlists
.empty ())
15981 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15983 /* Get the type which refers to the base class (possibly this
15984 class itself) which contains the vtable pointer for the current
15985 class from the DW_AT_containing_type attribute. This use of
15986 DW_AT_containing_type is a GNU extension. */
15988 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15990 struct type
*t
= die_containing_type (die
, cu
);
15992 set_type_vptr_basetype (type
, t
);
15997 /* Our own class provides vtbl ptr. */
15998 for (i
= TYPE_NFIELDS (t
) - 1;
15999 i
>= TYPE_N_BASECLASSES (t
);
16002 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
16004 if (is_vtable_name (fieldname
, cu
))
16006 set_type_vptr_fieldno (type
, i
);
16011 /* Complain if virtual function table field not found. */
16012 if (i
< TYPE_N_BASECLASSES (t
))
16013 complaint (&symfile_complaints
,
16014 _("virtual function table pointer "
16015 "not found when defining class '%s'"),
16016 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
16021 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16024 else if (cu
->producer
16025 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16027 /* The IBM XLC compiler does not provide direct indication
16028 of the containing type, but the vtable pointer is
16029 always named __vfp. */
16033 for (i
= TYPE_NFIELDS (type
) - 1;
16034 i
>= TYPE_N_BASECLASSES (type
);
16037 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
16039 set_type_vptr_fieldno (type
, i
);
16040 set_type_vptr_basetype (type
, type
);
16047 /* Copy fi.typedef_field_list linked list elements content into the
16048 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16049 if (!fi
.typedef_field_list
.empty ())
16051 int count
= fi
.typedef_field_list
.size ();
16053 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16054 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16055 = ((struct decl_field
*)
16057 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16058 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16060 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16061 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16064 /* Copy fi.nested_types_list linked list elements content into the
16065 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16066 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
16068 int count
= fi
.nested_types_list
.size ();
16070 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16071 TYPE_NESTED_TYPES_ARRAY (type
)
16072 = ((struct decl_field
*)
16073 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16074 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16076 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16077 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16081 quirk_gcc_member_function_pointer (type
, objfile
);
16082 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16083 cu
->rust_unions
.push_back (type
);
16085 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16086 snapshots) has been known to create a die giving a declaration
16087 for a class that has, as a child, a die giving a definition for a
16088 nested class. So we have to process our children even if the
16089 current die is a declaration. Normally, of course, a declaration
16090 won't have any children at all. */
16092 child_die
= die
->child
;
16094 while (child_die
!= NULL
&& child_die
->tag
)
16096 if (child_die
->tag
== DW_TAG_member
16097 || child_die
->tag
== DW_TAG_variable
16098 || child_die
->tag
== DW_TAG_inheritance
16099 || child_die
->tag
== DW_TAG_template_value_param
16100 || child_die
->tag
== DW_TAG_template_type_param
)
16105 process_die (child_die
, cu
);
16107 child_die
= sibling_die (child_die
);
16110 /* Do not consider external references. According to the DWARF standard,
16111 these DIEs are identified by the fact that they have no byte_size
16112 attribute, and a declaration attribute. */
16113 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16114 || !die_is_declaration (die
, cu
))
16115 new_symbol (die
, type
, cu
);
16118 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
16119 update TYPE using some information only available in DIE's children. */
16122 update_enumeration_type_from_children (struct die_info
*die
,
16124 struct dwarf2_cu
*cu
)
16126 struct die_info
*child_die
;
16127 int unsigned_enum
= 1;
16131 auto_obstack obstack
;
16133 for (child_die
= die
->child
;
16134 child_die
!= NULL
&& child_die
->tag
;
16135 child_die
= sibling_die (child_die
))
16137 struct attribute
*attr
;
16139 const gdb_byte
*bytes
;
16140 struct dwarf2_locexpr_baton
*baton
;
16143 if (child_die
->tag
!= DW_TAG_enumerator
)
16146 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16150 name
= dwarf2_name (child_die
, cu
);
16152 name
= "<anonymous enumerator>";
16154 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16155 &value
, &bytes
, &baton
);
16161 else if ((mask
& value
) != 0)
16166 /* If we already know that the enum type is neither unsigned, nor
16167 a flag type, no need to look at the rest of the enumerates. */
16168 if (!unsigned_enum
&& !flag_enum
)
16173 TYPE_UNSIGNED (type
) = 1;
16175 TYPE_FLAG_ENUM (type
) = 1;
16178 /* Given a DW_AT_enumeration_type die, set its type. We do not
16179 complete the type's fields yet, or create any symbols. */
16181 static struct type
*
16182 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16184 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16186 struct attribute
*attr
;
16189 /* If the definition of this type lives in .debug_types, read that type.
16190 Don't follow DW_AT_specification though, that will take us back up
16191 the chain and we want to go down. */
16192 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
16195 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16197 /* The type's CU may not be the same as CU.
16198 Ensure TYPE is recorded with CU in die_type_hash. */
16199 return set_die_type (die
, type
, cu
);
16202 type
= alloc_type (objfile
);
16204 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
16205 name
= dwarf2_full_name (NULL
, die
, cu
);
16207 TYPE_TAG_NAME (type
) = name
;
16209 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16212 struct type
*underlying_type
= die_type (die
, cu
);
16214 TYPE_TARGET_TYPE (type
) = underlying_type
;
16217 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16220 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16224 TYPE_LENGTH (type
) = 0;
16227 maybe_set_alignment (cu
, die
, type
);
16229 /* The enumeration DIE can be incomplete. In Ada, any type can be
16230 declared as private in the package spec, and then defined only
16231 inside the package body. Such types are known as Taft Amendment
16232 Types. When another package uses such a type, an incomplete DIE
16233 may be generated by the compiler. */
16234 if (die_is_declaration (die
, cu
))
16235 TYPE_STUB (type
) = 1;
16237 /* Finish the creation of this type by using the enum's children.
16238 We must call this even when the underlying type has been provided
16239 so that we can determine if we're looking at a "flag" enum. */
16240 update_enumeration_type_from_children (die
, type
, cu
);
16242 /* If this type has an underlying type that is not a stub, then we
16243 may use its attributes. We always use the "unsigned" attribute
16244 in this situation, because ordinarily we guess whether the type
16245 is unsigned -- but the guess can be wrong and the underlying type
16246 can tell us the reality. However, we defer to a local size
16247 attribute if one exists, because this lets the compiler override
16248 the underlying type if needed. */
16249 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16251 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
16252 if (TYPE_LENGTH (type
) == 0)
16253 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
16254 if (TYPE_RAW_ALIGN (type
) == 0
16255 && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)) != 0)
16256 set_type_align (type
, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)));
16259 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16261 return set_die_type (die
, type
, cu
);
16264 /* Given a pointer to a die which begins an enumeration, process all
16265 the dies that define the members of the enumeration, and create the
16266 symbol for the enumeration type.
16268 NOTE: We reverse the order of the element list. */
16271 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16273 struct type
*this_type
;
16275 this_type
= get_die_type (die
, cu
);
16276 if (this_type
== NULL
)
16277 this_type
= read_enumeration_type (die
, cu
);
16279 if (die
->child
!= NULL
)
16281 struct die_info
*child_die
;
16282 struct symbol
*sym
;
16283 struct field
*fields
= NULL
;
16284 int num_fields
= 0;
16287 child_die
= die
->child
;
16288 while (child_die
&& child_die
->tag
)
16290 if (child_die
->tag
!= DW_TAG_enumerator
)
16292 process_die (child_die
, cu
);
16296 name
= dwarf2_name (child_die
, cu
);
16299 sym
= new_symbol (child_die
, this_type
, cu
);
16301 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
16303 fields
= (struct field
*)
16305 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
16306 * sizeof (struct field
));
16309 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
16310 FIELD_TYPE (fields
[num_fields
]) = NULL
;
16311 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
16312 FIELD_BITSIZE (fields
[num_fields
]) = 0;
16318 child_die
= sibling_die (child_die
);
16323 TYPE_NFIELDS (this_type
) = num_fields
;
16324 TYPE_FIELDS (this_type
) = (struct field
*)
16325 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
16326 memcpy (TYPE_FIELDS (this_type
), fields
,
16327 sizeof (struct field
) * num_fields
);
16332 /* If we are reading an enum from a .debug_types unit, and the enum
16333 is a declaration, and the enum is not the signatured type in the
16334 unit, then we do not want to add a symbol for it. Adding a
16335 symbol would in some cases obscure the true definition of the
16336 enum, giving users an incomplete type when the definition is
16337 actually available. Note that we do not want to do this for all
16338 enums which are just declarations, because C++0x allows forward
16339 enum declarations. */
16340 if (cu
->per_cu
->is_debug_types
16341 && die_is_declaration (die
, cu
))
16343 struct signatured_type
*sig_type
;
16345 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16346 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16347 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16351 new_symbol (die
, this_type
, cu
);
16354 /* Extract all information from a DW_TAG_array_type DIE and put it in
16355 the DIE's type field. For now, this only handles one dimensional
16358 static struct type
*
16359 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16361 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16362 struct die_info
*child_die
;
16364 struct type
*element_type
, *range_type
, *index_type
;
16365 struct attribute
*attr
;
16367 struct dynamic_prop
*byte_stride_prop
= NULL
;
16368 unsigned int bit_stride
= 0;
16370 element_type
= die_type (die
, cu
);
16372 /* The die_type call above may have already set the type for this DIE. */
16373 type
= get_die_type (die
, cu
);
16377 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16383 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16384 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
);
16387 complaint (&symfile_complaints
,
16388 _("unable to read array DW_AT_byte_stride "
16389 " - DIE at %s [in module %s]"),
16390 sect_offset_str (die
->sect_off
),
16391 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16392 /* Ignore this attribute. We will likely not be able to print
16393 arrays of this type correctly, but there is little we can do
16394 to help if we cannot read the attribute's value. */
16395 byte_stride_prop
= NULL
;
16399 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16401 bit_stride
= DW_UNSND (attr
);
16403 /* Irix 6.2 native cc creates array types without children for
16404 arrays with unspecified length. */
16405 if (die
->child
== NULL
)
16407 index_type
= objfile_type (objfile
)->builtin_int
;
16408 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16409 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16410 byte_stride_prop
, bit_stride
);
16411 return set_die_type (die
, type
, cu
);
16414 std::vector
<struct type
*> range_types
;
16415 child_die
= die
->child
;
16416 while (child_die
&& child_die
->tag
)
16418 if (child_die
->tag
== DW_TAG_subrange_type
)
16420 struct type
*child_type
= read_type_die (child_die
, cu
);
16422 if (child_type
!= NULL
)
16424 /* The range type was succesfully read. Save it for the
16425 array type creation. */
16426 range_types
.push_back (child_type
);
16429 child_die
= sibling_die (child_die
);
16432 /* Dwarf2 dimensions are output from left to right, create the
16433 necessary array types in backwards order. */
16435 type
= element_type
;
16437 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16441 while (i
< range_types
.size ())
16442 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16443 byte_stride_prop
, bit_stride
);
16447 size_t ndim
= range_types
.size ();
16449 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16450 byte_stride_prop
, bit_stride
);
16453 /* Understand Dwarf2 support for vector types (like they occur on
16454 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16455 array type. This is not part of the Dwarf2/3 standard yet, but a
16456 custom vendor extension. The main difference between a regular
16457 array and the vector variant is that vectors are passed by value
16459 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16461 make_vector_type (type
);
16463 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16464 implementation may choose to implement triple vectors using this
16466 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16469 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16470 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16472 complaint (&symfile_complaints
,
16473 _("DW_AT_byte_size for array type smaller "
16474 "than the total size of elements"));
16477 name
= dwarf2_name (die
, cu
);
16479 TYPE_NAME (type
) = name
;
16481 maybe_set_alignment (cu
, die
, type
);
16483 /* Install the type in the die. */
16484 set_die_type (die
, type
, cu
);
16486 /* set_die_type should be already done. */
16487 set_descriptive_type (type
, die
, cu
);
16492 static enum dwarf_array_dim_ordering
16493 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16495 struct attribute
*attr
;
16497 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16500 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16502 /* GNU F77 is a special case, as at 08/2004 array type info is the
16503 opposite order to the dwarf2 specification, but data is still
16504 laid out as per normal fortran.
16506 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16507 version checking. */
16509 if (cu
->language
== language_fortran
16510 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16512 return DW_ORD_row_major
;
16515 switch (cu
->language_defn
->la_array_ordering
)
16517 case array_column_major
:
16518 return DW_ORD_col_major
;
16519 case array_row_major
:
16521 return DW_ORD_row_major
;
16525 /* Extract all information from a DW_TAG_set_type DIE and put it in
16526 the DIE's type field. */
16528 static struct type
*
16529 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16531 struct type
*domain_type
, *set_type
;
16532 struct attribute
*attr
;
16534 domain_type
= die_type (die
, cu
);
16536 /* The die_type call above may have already set the type for this DIE. */
16537 set_type
= get_die_type (die
, cu
);
16541 set_type
= create_set_type (NULL
, domain_type
);
16543 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16545 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16547 maybe_set_alignment (cu
, die
, set_type
);
16549 return set_die_type (die
, set_type
, cu
);
16552 /* A helper for read_common_block that creates a locexpr baton.
16553 SYM is the symbol which we are marking as computed.
16554 COMMON_DIE is the DIE for the common block.
16555 COMMON_LOC is the location expression attribute for the common
16557 MEMBER_LOC is the location expression attribute for the particular
16558 member of the common block that we are processing.
16559 CU is the CU from which the above come. */
16562 mark_common_block_symbol_computed (struct symbol
*sym
,
16563 struct die_info
*common_die
,
16564 struct attribute
*common_loc
,
16565 struct attribute
*member_loc
,
16566 struct dwarf2_cu
*cu
)
16568 struct dwarf2_per_objfile
*dwarf2_per_objfile
16569 = cu
->per_cu
->dwarf2_per_objfile
;
16570 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16571 struct dwarf2_locexpr_baton
*baton
;
16573 unsigned int cu_off
;
16574 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
16575 LONGEST offset
= 0;
16577 gdb_assert (common_loc
&& member_loc
);
16578 gdb_assert (attr_form_is_block (common_loc
));
16579 gdb_assert (attr_form_is_block (member_loc
)
16580 || attr_form_is_constant (member_loc
));
16582 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16583 baton
->per_cu
= cu
->per_cu
;
16584 gdb_assert (baton
->per_cu
);
16586 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16588 if (attr_form_is_constant (member_loc
))
16590 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
16591 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16594 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16596 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16599 *ptr
++ = DW_OP_call4
;
16600 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16601 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16604 if (attr_form_is_constant (member_loc
))
16606 *ptr
++ = DW_OP_addr
;
16607 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16608 ptr
+= cu
->header
.addr_size
;
16612 /* We have to copy the data here, because DW_OP_call4 will only
16613 use a DW_AT_location attribute. */
16614 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16615 ptr
+= DW_BLOCK (member_loc
)->size
;
16618 *ptr
++ = DW_OP_plus
;
16619 gdb_assert (ptr
- baton
->data
== baton
->size
);
16621 SYMBOL_LOCATION_BATON (sym
) = baton
;
16622 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16625 /* Create appropriate locally-scoped variables for all the
16626 DW_TAG_common_block entries. Also create a struct common_block
16627 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16628 is used to sepate the common blocks name namespace from regular
16632 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16634 struct attribute
*attr
;
16636 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16639 /* Support the .debug_loc offsets. */
16640 if (attr_form_is_block (attr
))
16644 else if (attr_form_is_section_offset (attr
))
16646 dwarf2_complex_location_expr_complaint ();
16651 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16652 "common block member");
16657 if (die
->child
!= NULL
)
16659 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16660 struct die_info
*child_die
;
16661 size_t n_entries
= 0, size
;
16662 struct common_block
*common_block
;
16663 struct symbol
*sym
;
16665 for (child_die
= die
->child
;
16666 child_die
&& child_die
->tag
;
16667 child_die
= sibling_die (child_die
))
16670 size
= (sizeof (struct common_block
)
16671 + (n_entries
- 1) * sizeof (struct symbol
*));
16673 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16675 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16676 common_block
->n_entries
= 0;
16678 for (child_die
= die
->child
;
16679 child_die
&& child_die
->tag
;
16680 child_die
= sibling_die (child_die
))
16682 /* Create the symbol in the DW_TAG_common_block block in the current
16684 sym
= new_symbol (child_die
, NULL
, cu
);
16687 struct attribute
*member_loc
;
16689 common_block
->contents
[common_block
->n_entries
++] = sym
;
16691 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16695 /* GDB has handled this for a long time, but it is
16696 not specified by DWARF. It seems to have been
16697 emitted by gfortran at least as recently as:
16698 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16699 complaint (&symfile_complaints
,
16700 _("Variable in common block has "
16701 "DW_AT_data_member_location "
16702 "- DIE at %s [in module %s]"),
16703 sect_offset_str (child_die
->sect_off
),
16704 objfile_name (objfile
));
16706 if (attr_form_is_section_offset (member_loc
))
16707 dwarf2_complex_location_expr_complaint ();
16708 else if (attr_form_is_constant (member_loc
)
16709 || attr_form_is_block (member_loc
))
16712 mark_common_block_symbol_computed (sym
, die
, attr
,
16716 dwarf2_complex_location_expr_complaint ();
16721 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16722 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16726 /* Create a type for a C++ namespace. */
16728 static struct type
*
16729 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16731 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16732 const char *previous_prefix
, *name
;
16736 /* For extensions, reuse the type of the original namespace. */
16737 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16739 struct die_info
*ext_die
;
16740 struct dwarf2_cu
*ext_cu
= cu
;
16742 ext_die
= dwarf2_extension (die
, &ext_cu
);
16743 type
= read_type_die (ext_die
, ext_cu
);
16745 /* EXT_CU may not be the same as CU.
16746 Ensure TYPE is recorded with CU in die_type_hash. */
16747 return set_die_type (die
, type
, cu
);
16750 name
= namespace_name (die
, &is_anonymous
, cu
);
16752 /* Now build the name of the current namespace. */
16754 previous_prefix
= determine_prefix (die
, cu
);
16755 if (previous_prefix
[0] != '\0')
16756 name
= typename_concat (&objfile
->objfile_obstack
,
16757 previous_prefix
, name
, 0, cu
);
16759 /* Create the type. */
16760 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16761 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
16763 return set_die_type (die
, type
, cu
);
16766 /* Read a namespace scope. */
16769 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16771 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16774 /* Add a symbol associated to this if we haven't seen the namespace
16775 before. Also, add a using directive if it's an anonymous
16778 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16782 type
= read_type_die (die
, cu
);
16783 new_symbol (die
, type
, cu
);
16785 namespace_name (die
, &is_anonymous
, cu
);
16788 const char *previous_prefix
= determine_prefix (die
, cu
);
16790 std::vector
<const char *> excludes
;
16791 add_using_directive (using_directives (cu
->language
),
16792 previous_prefix
, TYPE_NAME (type
), NULL
,
16793 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16797 if (die
->child
!= NULL
)
16799 struct die_info
*child_die
= die
->child
;
16801 while (child_die
&& child_die
->tag
)
16803 process_die (child_die
, cu
);
16804 child_die
= sibling_die (child_die
);
16809 /* Read a Fortran module as type. This DIE can be only a declaration used for
16810 imported module. Still we need that type as local Fortran "use ... only"
16811 declaration imports depend on the created type in determine_prefix. */
16813 static struct type
*
16814 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16816 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16817 const char *module_name
;
16820 module_name
= dwarf2_name (die
, cu
);
16822 complaint (&symfile_complaints
,
16823 _("DW_TAG_module has no name, offset %s"),
16824 sect_offset_str (die
->sect_off
));
16825 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16827 /* determine_prefix uses TYPE_TAG_NAME. */
16828 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
16830 return set_die_type (die
, type
, cu
);
16833 /* Read a Fortran module. */
16836 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16838 struct die_info
*child_die
= die
->child
;
16841 type
= read_type_die (die
, cu
);
16842 new_symbol (die
, type
, cu
);
16844 while (child_die
&& child_die
->tag
)
16846 process_die (child_die
, cu
);
16847 child_die
= sibling_die (child_die
);
16851 /* Return the name of the namespace represented by DIE. Set
16852 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16855 static const char *
16856 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16858 struct die_info
*current_die
;
16859 const char *name
= NULL
;
16861 /* Loop through the extensions until we find a name. */
16863 for (current_die
= die
;
16864 current_die
!= NULL
;
16865 current_die
= dwarf2_extension (die
, &cu
))
16867 /* We don't use dwarf2_name here so that we can detect the absence
16868 of a name -> anonymous namespace. */
16869 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16875 /* Is it an anonymous namespace? */
16877 *is_anonymous
= (name
== NULL
);
16879 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16884 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16885 the user defined type vector. */
16887 static struct type
*
16888 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16890 struct gdbarch
*gdbarch
16891 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16892 struct comp_unit_head
*cu_header
= &cu
->header
;
16894 struct attribute
*attr_byte_size
;
16895 struct attribute
*attr_address_class
;
16896 int byte_size
, addr_class
;
16897 struct type
*target_type
;
16899 target_type
= die_type (die
, cu
);
16901 /* The die_type call above may have already set the type for this DIE. */
16902 type
= get_die_type (die
, cu
);
16906 type
= lookup_pointer_type (target_type
);
16908 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16909 if (attr_byte_size
)
16910 byte_size
= DW_UNSND (attr_byte_size
);
16912 byte_size
= cu_header
->addr_size
;
16914 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16915 if (attr_address_class
)
16916 addr_class
= DW_UNSND (attr_address_class
);
16918 addr_class
= DW_ADDR_none
;
16920 ULONGEST alignment
= get_alignment (cu
, die
);
16922 /* If the pointer size, alignment, or address class is different
16923 than the default, create a type variant marked as such and set
16924 the length accordingly. */
16925 if (TYPE_LENGTH (type
) != byte_size
16926 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16927 && alignment
!= TYPE_RAW_ALIGN (type
))
16928 || addr_class
!= DW_ADDR_none
)
16930 if (gdbarch_address_class_type_flags_p (gdbarch
))
16934 type_flags
= gdbarch_address_class_type_flags
16935 (gdbarch
, byte_size
, addr_class
);
16936 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16938 type
= make_type_with_address_space (type
, type_flags
);
16940 else if (TYPE_LENGTH (type
) != byte_size
)
16942 complaint (&symfile_complaints
,
16943 _("invalid pointer size %d"), byte_size
);
16945 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16947 complaint (&symfile_complaints
,
16948 _("Invalid DW_AT_alignment"
16949 " - DIE at %s [in module %s]"),
16950 sect_offset_str (die
->sect_off
),
16951 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16955 /* Should we also complain about unhandled address classes? */
16959 TYPE_LENGTH (type
) = byte_size
;
16960 set_type_align (type
, alignment
);
16961 return set_die_type (die
, type
, cu
);
16964 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16965 the user defined type vector. */
16967 static struct type
*
16968 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16971 struct type
*to_type
;
16972 struct type
*domain
;
16974 to_type
= die_type (die
, cu
);
16975 domain
= die_containing_type (die
, cu
);
16977 /* The calls above may have already set the type for this DIE. */
16978 type
= get_die_type (die
, cu
);
16982 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
16983 type
= lookup_methodptr_type (to_type
);
16984 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
16986 struct type
*new_type
16987 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16989 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16990 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
16991 TYPE_VARARGS (to_type
));
16992 type
= lookup_methodptr_type (new_type
);
16995 type
= lookup_memberptr_type (to_type
, domain
);
16997 return set_die_type (die
, type
, cu
);
17000 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17001 the user defined type vector. */
17003 static struct type
*
17004 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17005 enum type_code refcode
)
17007 struct comp_unit_head
*cu_header
= &cu
->header
;
17008 struct type
*type
, *target_type
;
17009 struct attribute
*attr
;
17011 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17013 target_type
= die_type (die
, cu
);
17015 /* The die_type call above may have already set the type for this DIE. */
17016 type
= get_die_type (die
, cu
);
17020 type
= lookup_reference_type (target_type
, refcode
);
17021 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17024 TYPE_LENGTH (type
) = DW_UNSND (attr
);
17028 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17030 maybe_set_alignment (cu
, die
, type
);
17031 return set_die_type (die
, type
, cu
);
17034 /* Add the given cv-qualifiers to the element type of the array. GCC
17035 outputs DWARF type qualifiers that apply to an array, not the
17036 element type. But GDB relies on the array element type to carry
17037 the cv-qualifiers. This mimics section 6.7.3 of the C99
17040 static struct type
*
17041 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17042 struct type
*base_type
, int cnst
, int voltl
)
17044 struct type
*el_type
, *inner_array
;
17046 base_type
= copy_type (base_type
);
17047 inner_array
= base_type
;
17049 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
17051 TYPE_TARGET_TYPE (inner_array
) =
17052 copy_type (TYPE_TARGET_TYPE (inner_array
));
17053 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17056 el_type
= TYPE_TARGET_TYPE (inner_array
);
17057 cnst
|= TYPE_CONST (el_type
);
17058 voltl
|= TYPE_VOLATILE (el_type
);
17059 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17061 return set_die_type (die
, base_type
, cu
);
17064 static struct type
*
17065 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17067 struct type
*base_type
, *cv_type
;
17069 base_type
= die_type (die
, cu
);
17071 /* The die_type call above may have already set the type for this DIE. */
17072 cv_type
= get_die_type (die
, cu
);
17076 /* In case the const qualifier is applied to an array type, the element type
17077 is so qualified, not the array type (section 6.7.3 of C99). */
17078 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17079 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17081 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17082 return set_die_type (die
, cv_type
, cu
);
17085 static struct type
*
17086 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17088 struct type
*base_type
, *cv_type
;
17090 base_type
= die_type (die
, cu
);
17092 /* The die_type call above may have already set the type for this DIE. */
17093 cv_type
= get_die_type (die
, cu
);
17097 /* In case the volatile qualifier is applied to an array type, the
17098 element type is so qualified, not the array type (section 6.7.3
17100 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17101 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17103 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17104 return set_die_type (die
, cv_type
, cu
);
17107 /* Handle DW_TAG_restrict_type. */
17109 static struct type
*
17110 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17112 struct type
*base_type
, *cv_type
;
17114 base_type
= die_type (die
, cu
);
17116 /* The die_type call above may have already set the type for this DIE. */
17117 cv_type
= get_die_type (die
, cu
);
17121 cv_type
= make_restrict_type (base_type
);
17122 return set_die_type (die
, cv_type
, cu
);
17125 /* Handle DW_TAG_atomic_type. */
17127 static struct type
*
17128 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17130 struct type
*base_type
, *cv_type
;
17132 base_type
= die_type (die
, cu
);
17134 /* The die_type call above may have already set the type for this DIE. */
17135 cv_type
= get_die_type (die
, cu
);
17139 cv_type
= make_atomic_type (base_type
);
17140 return set_die_type (die
, cv_type
, cu
);
17143 /* Extract all information from a DW_TAG_string_type DIE and add to
17144 the user defined type vector. It isn't really a user defined type,
17145 but it behaves like one, with other DIE's using an AT_user_def_type
17146 attribute to reference it. */
17148 static struct type
*
17149 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17151 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17152 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17153 struct type
*type
, *range_type
, *index_type
, *char_type
;
17154 struct attribute
*attr
;
17155 unsigned int length
;
17157 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17160 length
= DW_UNSND (attr
);
17164 /* Check for the DW_AT_byte_size attribute. */
17165 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17168 length
= DW_UNSND (attr
);
17176 index_type
= objfile_type (objfile
)->builtin_int
;
17177 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17178 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17179 type
= create_string_type (NULL
, char_type
, range_type
);
17181 return set_die_type (die
, type
, cu
);
17184 /* Assuming that DIE corresponds to a function, returns nonzero
17185 if the function is prototyped. */
17188 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17190 struct attribute
*attr
;
17192 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17193 if (attr
&& (DW_UNSND (attr
) != 0))
17196 /* The DWARF standard implies that the DW_AT_prototyped attribute
17197 is only meaninful for C, but the concept also extends to other
17198 languages that allow unprototyped functions (Eg: Objective C).
17199 For all other languages, assume that functions are always
17201 if (cu
->language
!= language_c
17202 && cu
->language
!= language_objc
17203 && cu
->language
!= language_opencl
)
17206 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17207 prototyped and unprototyped functions; default to prototyped,
17208 since that is more common in modern code (and RealView warns
17209 about unprototyped functions). */
17210 if (producer_is_realview (cu
->producer
))
17216 /* Handle DIES due to C code like:
17220 int (*funcp)(int a, long l);
17224 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17226 static struct type
*
17227 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17229 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17230 struct type
*type
; /* Type that this function returns. */
17231 struct type
*ftype
; /* Function that returns above type. */
17232 struct attribute
*attr
;
17234 type
= die_type (die
, cu
);
17236 /* The die_type call above may have already set the type for this DIE. */
17237 ftype
= get_die_type (die
, cu
);
17241 ftype
= lookup_function_type (type
);
17243 if (prototyped_function_p (die
, cu
))
17244 TYPE_PROTOTYPED (ftype
) = 1;
17246 /* Store the calling convention in the type if it's available in
17247 the subroutine die. Otherwise set the calling convention to
17248 the default value DW_CC_normal. */
17249 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17251 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
17252 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17253 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17255 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17257 /* Record whether the function returns normally to its caller or not
17258 if the DWARF producer set that information. */
17259 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17260 if (attr
&& (DW_UNSND (attr
) != 0))
17261 TYPE_NO_RETURN (ftype
) = 1;
17263 /* We need to add the subroutine type to the die immediately so
17264 we don't infinitely recurse when dealing with parameters
17265 declared as the same subroutine type. */
17266 set_die_type (die
, ftype
, cu
);
17268 if (die
->child
!= NULL
)
17270 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17271 struct die_info
*child_die
;
17272 int nparams
, iparams
;
17274 /* Count the number of parameters.
17275 FIXME: GDB currently ignores vararg functions, but knows about
17276 vararg member functions. */
17278 child_die
= die
->child
;
17279 while (child_die
&& child_die
->tag
)
17281 if (child_die
->tag
== DW_TAG_formal_parameter
)
17283 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17284 TYPE_VARARGS (ftype
) = 1;
17285 child_die
= sibling_die (child_die
);
17288 /* Allocate storage for parameters and fill them in. */
17289 TYPE_NFIELDS (ftype
) = nparams
;
17290 TYPE_FIELDS (ftype
) = (struct field
*)
17291 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
17293 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17294 even if we error out during the parameters reading below. */
17295 for (iparams
= 0; iparams
< nparams
; iparams
++)
17296 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17299 child_die
= die
->child
;
17300 while (child_die
&& child_die
->tag
)
17302 if (child_die
->tag
== DW_TAG_formal_parameter
)
17304 struct type
*arg_type
;
17306 /* DWARF version 2 has no clean way to discern C++
17307 static and non-static member functions. G++ helps
17308 GDB by marking the first parameter for non-static
17309 member functions (which is the this pointer) as
17310 artificial. We pass this information to
17311 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17313 DWARF version 3 added DW_AT_object_pointer, which GCC
17314 4.5 does not yet generate. */
17315 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17317 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17319 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17320 arg_type
= die_type (child_die
, cu
);
17322 /* RealView does not mark THIS as const, which the testsuite
17323 expects. GCC marks THIS as const in method definitions,
17324 but not in the class specifications (GCC PR 43053). */
17325 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17326 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17329 struct dwarf2_cu
*arg_cu
= cu
;
17330 const char *name
= dwarf2_name (child_die
, cu
);
17332 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17335 /* If the compiler emits this, use it. */
17336 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17339 else if (name
&& strcmp (name
, "this") == 0)
17340 /* Function definitions will have the argument names. */
17342 else if (name
== NULL
&& iparams
== 0)
17343 /* Declarations may not have the names, so like
17344 elsewhere in GDB, assume an artificial first
17345 argument is "this". */
17349 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17353 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17356 child_die
= sibling_die (child_die
);
17363 static struct type
*
17364 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17366 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17367 const char *name
= NULL
;
17368 struct type
*this_type
, *target_type
;
17370 name
= dwarf2_full_name (NULL
, die
, cu
);
17371 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17372 TYPE_TARGET_STUB (this_type
) = 1;
17373 set_die_type (die
, this_type
, cu
);
17374 target_type
= die_type (die
, cu
);
17375 if (target_type
!= this_type
)
17376 TYPE_TARGET_TYPE (this_type
) = target_type
;
17379 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17380 spec and cause infinite loops in GDB. */
17381 complaint (&symfile_complaints
,
17382 _("Self-referential DW_TAG_typedef "
17383 "- DIE at %s [in module %s]"),
17384 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17385 TYPE_TARGET_TYPE (this_type
) = NULL
;
17390 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17391 (which may be different from NAME) to the architecture back-end to allow
17392 it to guess the correct format if necessary. */
17394 static struct type
*
17395 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17396 const char *name_hint
)
17398 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17399 const struct floatformat
**format
;
17402 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17404 type
= init_float_type (objfile
, bits
, name
, format
);
17406 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17411 /* Find a representation of a given base type and install
17412 it in the TYPE field of the die. */
17414 static struct type
*
17415 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17417 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17419 struct attribute
*attr
;
17420 int encoding
= 0, bits
= 0;
17423 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17426 encoding
= DW_UNSND (attr
);
17428 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17431 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17433 name
= dwarf2_name (die
, cu
);
17436 complaint (&symfile_complaints
,
17437 _("DW_AT_name missing from DW_TAG_base_type"));
17442 case DW_ATE_address
:
17443 /* Turn DW_ATE_address into a void * pointer. */
17444 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17445 type
= init_pointer_type (objfile
, bits
, name
, type
);
17447 case DW_ATE_boolean
:
17448 type
= init_boolean_type (objfile
, bits
, 1, name
);
17450 case DW_ATE_complex_float
:
17451 type
= dwarf2_init_float_type (objfile
, bits
/ 2, NULL
, name
);
17452 type
= init_complex_type (objfile
, name
, type
);
17454 case DW_ATE_decimal_float
:
17455 type
= init_decfloat_type (objfile
, bits
, name
);
17458 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
);
17460 case DW_ATE_signed
:
17461 type
= init_integer_type (objfile
, bits
, 0, name
);
17463 case DW_ATE_unsigned
:
17464 if (cu
->language
== language_fortran
17466 && startswith (name
, "character("))
17467 type
= init_character_type (objfile
, bits
, 1, name
);
17469 type
= init_integer_type (objfile
, bits
, 1, name
);
17471 case DW_ATE_signed_char
:
17472 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17473 || cu
->language
== language_pascal
17474 || cu
->language
== language_fortran
)
17475 type
= init_character_type (objfile
, bits
, 0, name
);
17477 type
= init_integer_type (objfile
, bits
, 0, name
);
17479 case DW_ATE_unsigned_char
:
17480 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17481 || cu
->language
== language_pascal
17482 || cu
->language
== language_fortran
17483 || cu
->language
== language_rust
)
17484 type
= init_character_type (objfile
, bits
, 1, name
);
17486 type
= init_integer_type (objfile
, bits
, 1, name
);
17490 gdbarch
*arch
= get_objfile_arch (objfile
);
17493 type
= builtin_type (arch
)->builtin_char16
;
17494 else if (bits
== 32)
17495 type
= builtin_type (arch
)->builtin_char32
;
17498 complaint (&symfile_complaints
,
17499 _("unsupported DW_ATE_UTF bit size: '%d'"),
17501 type
= init_integer_type (objfile
, bits
, 1, name
);
17503 return set_die_type (die
, type
, cu
);
17508 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
17509 dwarf_type_encoding_name (encoding
));
17510 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17514 if (name
&& strcmp (name
, "char") == 0)
17515 TYPE_NOSIGN (type
) = 1;
17517 maybe_set_alignment (cu
, die
, type
);
17519 return set_die_type (die
, type
, cu
);
17522 /* Parse dwarf attribute if it's a block, reference or constant and put the
17523 resulting value of the attribute into struct bound_prop.
17524 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17527 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17528 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
)
17530 struct dwarf2_property_baton
*baton
;
17531 struct obstack
*obstack
17532 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17534 if (attr
== NULL
|| prop
== NULL
)
17537 if (attr_form_is_block (attr
))
17539 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17540 baton
->referenced_type
= NULL
;
17541 baton
->locexpr
.per_cu
= cu
->per_cu
;
17542 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17543 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17544 prop
->data
.baton
= baton
;
17545 prop
->kind
= PROP_LOCEXPR
;
17546 gdb_assert (prop
->data
.baton
!= NULL
);
17548 else if (attr_form_is_ref (attr
))
17550 struct dwarf2_cu
*target_cu
= cu
;
17551 struct die_info
*target_die
;
17552 struct attribute
*target_attr
;
17554 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17555 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17556 if (target_attr
== NULL
)
17557 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17559 if (target_attr
== NULL
)
17562 switch (target_attr
->name
)
17564 case DW_AT_location
:
17565 if (attr_form_is_section_offset (target_attr
))
17567 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17568 baton
->referenced_type
= die_type (target_die
, target_cu
);
17569 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17570 prop
->data
.baton
= baton
;
17571 prop
->kind
= PROP_LOCLIST
;
17572 gdb_assert (prop
->data
.baton
!= NULL
);
17574 else if (attr_form_is_block (target_attr
))
17576 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17577 baton
->referenced_type
= die_type (target_die
, target_cu
);
17578 baton
->locexpr
.per_cu
= cu
->per_cu
;
17579 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17580 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17581 prop
->data
.baton
= baton
;
17582 prop
->kind
= PROP_LOCEXPR
;
17583 gdb_assert (prop
->data
.baton
!= NULL
);
17587 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17588 "dynamic property");
17592 case DW_AT_data_member_location
:
17596 if (!handle_data_member_location (target_die
, target_cu
,
17600 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17601 baton
->referenced_type
= read_type_die (target_die
->parent
,
17603 baton
->offset_info
.offset
= offset
;
17604 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17605 prop
->data
.baton
= baton
;
17606 prop
->kind
= PROP_ADDR_OFFSET
;
17611 else if (attr_form_is_constant (attr
))
17613 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
17614 prop
->kind
= PROP_CONST
;
17618 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17619 dwarf2_name (die
, cu
));
17626 /* Read the given DW_AT_subrange DIE. */
17628 static struct type
*
17629 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17631 struct type
*base_type
, *orig_base_type
;
17632 struct type
*range_type
;
17633 struct attribute
*attr
;
17634 struct dynamic_prop low
, high
;
17635 int low_default_is_valid
;
17636 int high_bound_is_count
= 0;
17638 LONGEST negative_mask
;
17640 orig_base_type
= die_type (die
, cu
);
17641 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17642 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17643 creating the range type, but we use the result of check_typedef
17644 when examining properties of the type. */
17645 base_type
= check_typedef (orig_base_type
);
17647 /* The die_type call above may have already set the type for this DIE. */
17648 range_type
= get_die_type (die
, cu
);
17652 low
.kind
= PROP_CONST
;
17653 high
.kind
= PROP_CONST
;
17654 high
.data
.const_val
= 0;
17656 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17657 omitting DW_AT_lower_bound. */
17658 switch (cu
->language
)
17661 case language_cplus
:
17662 low
.data
.const_val
= 0;
17663 low_default_is_valid
= 1;
17665 case language_fortran
:
17666 low
.data
.const_val
= 1;
17667 low_default_is_valid
= 1;
17670 case language_objc
:
17671 case language_rust
:
17672 low
.data
.const_val
= 0;
17673 low_default_is_valid
= (cu
->header
.version
>= 4);
17677 case language_pascal
:
17678 low
.data
.const_val
= 1;
17679 low_default_is_valid
= (cu
->header
.version
>= 4);
17682 low
.data
.const_val
= 0;
17683 low_default_is_valid
= 0;
17687 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17689 attr_to_dynamic_prop (attr
, die
, cu
, &low
);
17690 else if (!low_default_is_valid
)
17691 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
17692 "- DIE at %s [in module %s]"),
17693 sect_offset_str (die
->sect_off
),
17694 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17696 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17697 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
))
17699 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
17700 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
))
17702 /* If bounds are constant do the final calculation here. */
17703 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17704 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17706 high_bound_is_count
= 1;
17710 /* Dwarf-2 specifications explicitly allows to create subrange types
17711 without specifying a base type.
17712 In that case, the base type must be set to the type of
17713 the lower bound, upper bound or count, in that order, if any of these
17714 three attributes references an object that has a type.
17715 If no base type is found, the Dwarf-2 specifications say that
17716 a signed integer type of size equal to the size of an address should
17718 For the following C code: `extern char gdb_int [];'
17719 GCC produces an empty range DIE.
17720 FIXME: muller/2010-05-28: Possible references to object for low bound,
17721 high bound or count are not yet handled by this code. */
17722 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
17724 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17725 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17726 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
17727 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
17729 /* Test "int", "long int", and "long long int" objfile types,
17730 and select the first one having a size above or equal to the
17731 architecture address size. */
17732 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
17733 base_type
= int_type
;
17736 int_type
= objfile_type (objfile
)->builtin_long
;
17737 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
17738 base_type
= int_type
;
17741 int_type
= objfile_type (objfile
)->builtin_long_long
;
17742 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
17743 base_type
= int_type
;
17748 /* Normally, the DWARF producers are expected to use a signed
17749 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17750 But this is unfortunately not always the case, as witnessed
17751 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17752 is used instead. To work around that ambiguity, we treat
17753 the bounds as signed, and thus sign-extend their values, when
17754 the base type is signed. */
17756 -((LONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17757 if (low
.kind
== PROP_CONST
17758 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17759 low
.data
.const_val
|= negative_mask
;
17760 if (high
.kind
== PROP_CONST
17761 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17762 high
.data
.const_val
|= negative_mask
;
17764 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
);
17766 if (high_bound_is_count
)
17767 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17769 /* Ada expects an empty array on no boundary attributes. */
17770 if (attr
== NULL
&& cu
->language
!= language_ada
)
17771 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17773 name
= dwarf2_name (die
, cu
);
17775 TYPE_NAME (range_type
) = name
;
17777 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17779 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17781 maybe_set_alignment (cu
, die
, range_type
);
17783 set_die_type (die
, range_type
, cu
);
17785 /* set_die_type should be already done. */
17786 set_descriptive_type (range_type
, die
, cu
);
17791 static struct type
*
17792 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17796 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
17798 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
17800 /* In Ada, an unspecified type is typically used when the description
17801 of the type is defered to a different unit. When encountering
17802 such a type, we treat it as a stub, and try to resolve it later on,
17804 if (cu
->language
== language_ada
)
17805 TYPE_STUB (type
) = 1;
17807 return set_die_type (die
, type
, cu
);
17810 /* Read a single die and all its descendents. Set the die's sibling
17811 field to NULL; set other fields in the die correctly, and set all
17812 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17813 location of the info_ptr after reading all of those dies. PARENT
17814 is the parent of the die in question. */
17816 static struct die_info
*
17817 read_die_and_children (const struct die_reader_specs
*reader
,
17818 const gdb_byte
*info_ptr
,
17819 const gdb_byte
**new_info_ptr
,
17820 struct die_info
*parent
)
17822 struct die_info
*die
;
17823 const gdb_byte
*cur_ptr
;
17826 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
17829 *new_info_ptr
= cur_ptr
;
17832 store_in_ref_table (die
, reader
->cu
);
17835 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17839 *new_info_ptr
= cur_ptr
;
17842 die
->sibling
= NULL
;
17843 die
->parent
= parent
;
17847 /* Read a die, all of its descendents, and all of its siblings; set
17848 all of the fields of all of the dies correctly. Arguments are as
17849 in read_die_and_children. */
17851 static struct die_info
*
17852 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17853 const gdb_byte
*info_ptr
,
17854 const gdb_byte
**new_info_ptr
,
17855 struct die_info
*parent
)
17857 struct die_info
*first_die
, *last_sibling
;
17858 const gdb_byte
*cur_ptr
;
17860 cur_ptr
= info_ptr
;
17861 first_die
= last_sibling
= NULL
;
17865 struct die_info
*die
17866 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17870 *new_info_ptr
= cur_ptr
;
17877 last_sibling
->sibling
= die
;
17879 last_sibling
= die
;
17883 /* Read a die, all of its descendents, and all of its siblings; set
17884 all of the fields of all of the dies correctly. Arguments are as
17885 in read_die_and_children.
17886 This the main entry point for reading a DIE and all its children. */
17888 static struct die_info
*
17889 read_die_and_siblings (const struct die_reader_specs
*reader
,
17890 const gdb_byte
*info_ptr
,
17891 const gdb_byte
**new_info_ptr
,
17892 struct die_info
*parent
)
17894 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17895 new_info_ptr
, parent
);
17897 if (dwarf_die_debug
)
17899 fprintf_unfiltered (gdb_stdlog
,
17900 "Read die from %s@0x%x of %s:\n",
17901 get_section_name (reader
->die_section
),
17902 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17903 bfd_get_filename (reader
->abfd
));
17904 dump_die (die
, dwarf_die_debug
);
17910 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
17912 The caller is responsible for filling in the extra attributes
17913 and updating (*DIEP)->num_attrs.
17914 Set DIEP to point to a newly allocated die with its information,
17915 except for its child, sibling, and parent fields.
17916 Set HAS_CHILDREN to tell whether the die has children or not. */
17918 static const gdb_byte
*
17919 read_full_die_1 (const struct die_reader_specs
*reader
,
17920 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17921 int *has_children
, int num_extra_attrs
)
17923 unsigned int abbrev_number
, bytes_read
, i
;
17924 struct abbrev_info
*abbrev
;
17925 struct die_info
*die
;
17926 struct dwarf2_cu
*cu
= reader
->cu
;
17927 bfd
*abfd
= reader
->abfd
;
17929 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
17930 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17931 info_ptr
+= bytes_read
;
17932 if (!abbrev_number
)
17939 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
17941 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
17943 bfd_get_filename (abfd
));
17945 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
17946 die
->sect_off
= sect_off
;
17947 die
->tag
= abbrev
->tag
;
17948 die
->abbrev
= abbrev_number
;
17950 /* Make the result usable.
17951 The caller needs to update num_attrs after adding the extra
17953 die
->num_attrs
= abbrev
->num_attrs
;
17955 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
17956 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
17960 *has_children
= abbrev
->has_children
;
17964 /* Read a die and all its attributes.
17965 Set DIEP to point to a newly allocated die with its information,
17966 except for its child, sibling, and parent fields.
17967 Set HAS_CHILDREN to tell whether the die has children or not. */
17969 static const gdb_byte
*
17970 read_full_die (const struct die_reader_specs
*reader
,
17971 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17974 const gdb_byte
*result
;
17976 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
17978 if (dwarf_die_debug
)
17980 fprintf_unfiltered (gdb_stdlog
,
17981 "Read die from %s@0x%x of %s:\n",
17982 get_section_name (reader
->die_section
),
17983 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17984 bfd_get_filename (reader
->abfd
));
17985 dump_die (*diep
, dwarf_die_debug
);
17991 /* Abbreviation tables.
17993 In DWARF version 2, the description of the debugging information is
17994 stored in a separate .debug_abbrev section. Before we read any
17995 dies from a section we read in all abbreviations and install them
17996 in a hash table. */
17998 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
18000 struct abbrev_info
*
18001 abbrev_table::alloc_abbrev ()
18003 struct abbrev_info
*abbrev
;
18005 abbrev
= XOBNEW (&abbrev_obstack
, struct abbrev_info
);
18006 memset (abbrev
, 0, sizeof (struct abbrev_info
));
18011 /* Add an abbreviation to the table. */
18014 abbrev_table::add_abbrev (unsigned int abbrev_number
,
18015 struct abbrev_info
*abbrev
)
18017 unsigned int hash_number
;
18019 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18020 abbrev
->next
= m_abbrevs
[hash_number
];
18021 m_abbrevs
[hash_number
] = abbrev
;
18024 /* Look up an abbrev in the table.
18025 Returns NULL if the abbrev is not found. */
18027 struct abbrev_info
*
18028 abbrev_table::lookup_abbrev (unsigned int abbrev_number
)
18030 unsigned int hash_number
;
18031 struct abbrev_info
*abbrev
;
18033 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18034 abbrev
= m_abbrevs
[hash_number
];
18038 if (abbrev
->number
== abbrev_number
)
18040 abbrev
= abbrev
->next
;
18045 /* Read in an abbrev table. */
18047 static abbrev_table_up
18048 abbrev_table_read_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18049 struct dwarf2_section_info
*section
,
18050 sect_offset sect_off
)
18052 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18053 bfd
*abfd
= get_section_bfd_owner (section
);
18054 const gdb_byte
*abbrev_ptr
;
18055 struct abbrev_info
*cur_abbrev
;
18056 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
18057 unsigned int abbrev_form
;
18058 struct attr_abbrev
*cur_attrs
;
18059 unsigned int allocated_attrs
;
18061 abbrev_table_up
abbrev_table (new struct abbrev_table (sect_off
));
18063 dwarf2_read_section (objfile
, section
);
18064 abbrev_ptr
= section
->buffer
+ to_underlying (sect_off
);
18065 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18066 abbrev_ptr
+= bytes_read
;
18068 allocated_attrs
= ATTR_ALLOC_CHUNK
;
18069 cur_attrs
= XNEWVEC (struct attr_abbrev
, allocated_attrs
);
18071 /* Loop until we reach an abbrev number of 0. */
18072 while (abbrev_number
)
18074 cur_abbrev
= abbrev_table
->alloc_abbrev ();
18076 /* read in abbrev header */
18077 cur_abbrev
->number
= abbrev_number
;
18079 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18080 abbrev_ptr
+= bytes_read
;
18081 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
18084 /* now read in declarations */
18087 LONGEST implicit_const
;
18089 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18090 abbrev_ptr
+= bytes_read
;
18091 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18092 abbrev_ptr
+= bytes_read
;
18093 if (abbrev_form
== DW_FORM_implicit_const
)
18095 implicit_const
= read_signed_leb128 (abfd
, abbrev_ptr
,
18097 abbrev_ptr
+= bytes_read
;
18101 /* Initialize it due to a false compiler warning. */
18102 implicit_const
= -1;
18105 if (abbrev_name
== 0)
18108 if (cur_abbrev
->num_attrs
== allocated_attrs
)
18110 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
18112 = XRESIZEVEC (struct attr_abbrev
, cur_attrs
, allocated_attrs
);
18115 cur_attrs
[cur_abbrev
->num_attrs
].name
18116 = (enum dwarf_attribute
) abbrev_name
;
18117 cur_attrs
[cur_abbrev
->num_attrs
].form
18118 = (enum dwarf_form
) abbrev_form
;
18119 cur_attrs
[cur_abbrev
->num_attrs
].implicit_const
= implicit_const
;
18120 ++cur_abbrev
->num_attrs
;
18123 cur_abbrev
->attrs
=
18124 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
18125 cur_abbrev
->num_attrs
);
18126 memcpy (cur_abbrev
->attrs
, cur_attrs
,
18127 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
18129 abbrev_table
->add_abbrev (abbrev_number
, cur_abbrev
);
18131 /* Get next abbreviation.
18132 Under Irix6 the abbreviations for a compilation unit are not
18133 always properly terminated with an abbrev number of 0.
18134 Exit loop if we encounter an abbreviation which we have
18135 already read (which means we are about to read the abbreviations
18136 for the next compile unit) or if the end of the abbreviation
18137 table is reached. */
18138 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
18140 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18141 abbrev_ptr
+= bytes_read
;
18142 if (abbrev_table
->lookup_abbrev (abbrev_number
) != NULL
)
18147 return abbrev_table
;
18150 /* Returns nonzero if TAG represents a type that we might generate a partial
18154 is_type_tag_for_partial (int tag
)
18159 /* Some types that would be reasonable to generate partial symbols for,
18160 that we don't at present. */
18161 case DW_TAG_array_type
:
18162 case DW_TAG_file_type
:
18163 case DW_TAG_ptr_to_member_type
:
18164 case DW_TAG_set_type
:
18165 case DW_TAG_string_type
:
18166 case DW_TAG_subroutine_type
:
18168 case DW_TAG_base_type
:
18169 case DW_TAG_class_type
:
18170 case DW_TAG_interface_type
:
18171 case DW_TAG_enumeration_type
:
18172 case DW_TAG_structure_type
:
18173 case DW_TAG_subrange_type
:
18174 case DW_TAG_typedef
:
18175 case DW_TAG_union_type
:
18182 /* Load all DIEs that are interesting for partial symbols into memory. */
18184 static struct partial_die_info
*
18185 load_partial_dies (const struct die_reader_specs
*reader
,
18186 const gdb_byte
*info_ptr
, int building_psymtab
)
18188 struct dwarf2_cu
*cu
= reader
->cu
;
18189 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18190 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18191 unsigned int bytes_read
;
18192 unsigned int load_all
= 0;
18193 int nesting_level
= 1;
18198 gdb_assert (cu
->per_cu
!= NULL
);
18199 if (cu
->per_cu
->load_all_dies
)
18203 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18207 &cu
->comp_unit_obstack
,
18208 hashtab_obstack_allocate
,
18209 dummy_obstack_deallocate
);
18213 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18215 /* A NULL abbrev means the end of a series of children. */
18216 if (abbrev
== NULL
)
18218 if (--nesting_level
== 0)
18221 info_ptr
+= bytes_read
;
18222 last_die
= parent_die
;
18223 parent_die
= parent_die
->die_parent
;
18227 /* Check for template arguments. We never save these; if
18228 they're seen, we just mark the parent, and go on our way. */
18229 if (parent_die
!= NULL
18230 && cu
->language
== language_cplus
18231 && (abbrev
->tag
== DW_TAG_template_type_param
18232 || abbrev
->tag
== DW_TAG_template_value_param
))
18234 parent_die
->has_template_arguments
= 1;
18238 /* We don't need a partial DIE for the template argument. */
18239 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18244 /* We only recurse into c++ subprograms looking for template arguments.
18245 Skip their other children. */
18247 && cu
->language
== language_cplus
18248 && parent_die
!= NULL
18249 && parent_die
->tag
== DW_TAG_subprogram
)
18251 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18255 /* Check whether this DIE is interesting enough to save. Normally
18256 we would not be interested in members here, but there may be
18257 later variables referencing them via DW_AT_specification (for
18258 static members). */
18260 && !is_type_tag_for_partial (abbrev
->tag
)
18261 && abbrev
->tag
!= DW_TAG_constant
18262 && abbrev
->tag
!= DW_TAG_enumerator
18263 && abbrev
->tag
!= DW_TAG_subprogram
18264 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18265 && abbrev
->tag
!= DW_TAG_lexical_block
18266 && abbrev
->tag
!= DW_TAG_variable
18267 && abbrev
->tag
!= DW_TAG_namespace
18268 && abbrev
->tag
!= DW_TAG_module
18269 && abbrev
->tag
!= DW_TAG_member
18270 && abbrev
->tag
!= DW_TAG_imported_unit
18271 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18273 /* Otherwise we skip to the next sibling, if any. */
18274 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18278 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18281 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18283 /* This two-pass algorithm for processing partial symbols has a
18284 high cost in cache pressure. Thus, handle some simple cases
18285 here which cover the majority of C partial symbols. DIEs
18286 which neither have specification tags in them, nor could have
18287 specification tags elsewhere pointing at them, can simply be
18288 processed and discarded.
18290 This segment is also optional; scan_partial_symbols and
18291 add_partial_symbol will handle these DIEs if we chain
18292 them in normally. When compilers which do not emit large
18293 quantities of duplicate debug information are more common,
18294 this code can probably be removed. */
18296 /* Any complete simple types at the top level (pretty much all
18297 of them, for a language without namespaces), can be processed
18299 if (parent_die
== NULL
18300 && pdi
.has_specification
== 0
18301 && pdi
.is_declaration
== 0
18302 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18303 || pdi
.tag
== DW_TAG_base_type
18304 || pdi
.tag
== DW_TAG_subrange_type
))
18306 if (building_psymtab
&& pdi
.name
!= NULL
)
18307 add_psymbol_to_list (pdi
.name
, strlen (pdi
.name
), 0,
18308 VAR_DOMAIN
, LOC_TYPEDEF
,
18309 &objfile
->static_psymbols
,
18310 0, cu
->language
, objfile
);
18311 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18315 /* The exception for DW_TAG_typedef with has_children above is
18316 a workaround of GCC PR debug/47510. In the case of this complaint
18317 type_name_no_tag_or_error will error on such types later.
18319 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18320 it could not find the child DIEs referenced later, this is checked
18321 above. In correct DWARF DW_TAG_typedef should have no children. */
18323 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18324 complaint (&symfile_complaints
,
18325 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18326 "- DIE at %s [in module %s]"),
18327 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18329 /* If we're at the second level, and we're an enumerator, and
18330 our parent has no specification (meaning possibly lives in a
18331 namespace elsewhere), then we can add the partial symbol now
18332 instead of queueing it. */
18333 if (pdi
.tag
== DW_TAG_enumerator
18334 && parent_die
!= NULL
18335 && parent_die
->die_parent
== NULL
18336 && parent_die
->tag
== DW_TAG_enumeration_type
18337 && parent_die
->has_specification
== 0)
18339 if (pdi
.name
== NULL
)
18340 complaint (&symfile_complaints
,
18341 _("malformed enumerator DIE ignored"));
18342 else if (building_psymtab
)
18343 add_psymbol_to_list (pdi
.name
, strlen (pdi
.name
), 0,
18344 VAR_DOMAIN
, LOC_CONST
,
18345 cu
->language
== language_cplus
18346 ? &objfile
->global_psymbols
18347 : &objfile
->static_psymbols
,
18348 0, cu
->language
, objfile
);
18350 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18354 struct partial_die_info
*part_die
18355 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18357 /* We'll save this DIE so link it in. */
18358 part_die
->die_parent
= parent_die
;
18359 part_die
->die_sibling
= NULL
;
18360 part_die
->die_child
= NULL
;
18362 if (last_die
&& last_die
== parent_die
)
18363 last_die
->die_child
= part_die
;
18365 last_die
->die_sibling
= part_die
;
18367 last_die
= part_die
;
18369 if (first_die
== NULL
)
18370 first_die
= part_die
;
18372 /* Maybe add the DIE to the hash table. Not all DIEs that we
18373 find interesting need to be in the hash table, because we
18374 also have the parent/sibling/child chains; only those that we
18375 might refer to by offset later during partial symbol reading.
18377 For now this means things that might have be the target of a
18378 DW_AT_specification, DW_AT_abstract_origin, or
18379 DW_AT_extension. DW_AT_extension will refer only to
18380 namespaces; DW_AT_abstract_origin refers to functions (and
18381 many things under the function DIE, but we do not recurse
18382 into function DIEs during partial symbol reading) and
18383 possibly variables as well; DW_AT_specification refers to
18384 declarations. Declarations ought to have the DW_AT_declaration
18385 flag. It happens that GCC forgets to put it in sometimes, but
18386 only for functions, not for types.
18388 Adding more things than necessary to the hash table is harmless
18389 except for the performance cost. Adding too few will result in
18390 wasted time in find_partial_die, when we reread the compilation
18391 unit with load_all_dies set. */
18394 || abbrev
->tag
== DW_TAG_constant
18395 || abbrev
->tag
== DW_TAG_subprogram
18396 || abbrev
->tag
== DW_TAG_variable
18397 || abbrev
->tag
== DW_TAG_namespace
18398 || part_die
->is_declaration
)
18402 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18403 to_underlying (part_die
->sect_off
),
18408 /* For some DIEs we want to follow their children (if any). For C
18409 we have no reason to follow the children of structures; for other
18410 languages we have to, so that we can get at method physnames
18411 to infer fully qualified class names, for DW_AT_specification,
18412 and for C++ template arguments. For C++, we also look one level
18413 inside functions to find template arguments (if the name of the
18414 function does not already contain the template arguments).
18416 For Ada, we need to scan the children of subprograms and lexical
18417 blocks as well because Ada allows the definition of nested
18418 entities that could be interesting for the debugger, such as
18419 nested subprograms for instance. */
18420 if (last_die
->has_children
18422 || last_die
->tag
== DW_TAG_namespace
18423 || last_die
->tag
== DW_TAG_module
18424 || last_die
->tag
== DW_TAG_enumeration_type
18425 || (cu
->language
== language_cplus
18426 && last_die
->tag
== DW_TAG_subprogram
18427 && (last_die
->name
== NULL
18428 || strchr (last_die
->name
, '<') == NULL
))
18429 || (cu
->language
!= language_c
18430 && (last_die
->tag
== DW_TAG_class_type
18431 || last_die
->tag
== DW_TAG_interface_type
18432 || last_die
->tag
== DW_TAG_structure_type
18433 || last_die
->tag
== DW_TAG_union_type
))
18434 || (cu
->language
== language_ada
18435 && (last_die
->tag
== DW_TAG_subprogram
18436 || last_die
->tag
== DW_TAG_lexical_block
))))
18439 parent_die
= last_die
;
18443 /* Otherwise we skip to the next sibling, if any. */
18444 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18446 /* Back to the top, do it again. */
18450 partial_die_info::partial_die_info (sect_offset sect_off_
,
18451 struct abbrev_info
*abbrev
)
18452 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18456 /* Read a minimal amount of information into the minimal die structure.
18457 INFO_PTR should point just after the initial uleb128 of a DIE. */
18460 partial_die_info::read (const struct die_reader_specs
*reader
,
18461 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18463 struct dwarf2_cu
*cu
= reader
->cu
;
18464 struct dwarf2_per_objfile
*dwarf2_per_objfile
18465 = cu
->per_cu
->dwarf2_per_objfile
;
18467 int has_low_pc_attr
= 0;
18468 int has_high_pc_attr
= 0;
18469 int high_pc_relative
= 0;
18471 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18473 struct attribute attr
;
18475 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
18477 /* Store the data if it is of an attribute we want to keep in a
18478 partial symbol table. */
18484 case DW_TAG_compile_unit
:
18485 case DW_TAG_partial_unit
:
18486 case DW_TAG_type_unit
:
18487 /* Compilation units have a DW_AT_name that is a filename, not
18488 a source language identifier. */
18489 case DW_TAG_enumeration_type
:
18490 case DW_TAG_enumerator
:
18491 /* These tags always have simple identifiers already; no need
18492 to canonicalize them. */
18493 name
= DW_STRING (&attr
);
18497 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18500 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
18501 &objfile
->per_bfd
->storage_obstack
);
18506 case DW_AT_linkage_name
:
18507 case DW_AT_MIPS_linkage_name
:
18508 /* Note that both forms of linkage name might appear. We
18509 assume they will be the same, and we only store the last
18511 if (cu
->language
== language_ada
)
18512 name
= DW_STRING (&attr
);
18513 linkage_name
= DW_STRING (&attr
);
18516 has_low_pc_attr
= 1;
18517 lowpc
= attr_value_as_address (&attr
);
18519 case DW_AT_high_pc
:
18520 has_high_pc_attr
= 1;
18521 highpc
= attr_value_as_address (&attr
);
18522 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
18523 high_pc_relative
= 1;
18525 case DW_AT_location
:
18526 /* Support the .debug_loc offsets. */
18527 if (attr_form_is_block (&attr
))
18529 d
.locdesc
= DW_BLOCK (&attr
);
18531 else if (attr_form_is_section_offset (&attr
))
18533 dwarf2_complex_location_expr_complaint ();
18537 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18538 "partial symbol information");
18541 case DW_AT_external
:
18542 is_external
= DW_UNSND (&attr
);
18544 case DW_AT_declaration
:
18545 is_declaration
= DW_UNSND (&attr
);
18550 case DW_AT_abstract_origin
:
18551 case DW_AT_specification
:
18552 case DW_AT_extension
:
18553 has_specification
= 1;
18554 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
18555 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18556 || cu
->per_cu
->is_dwz
);
18558 case DW_AT_sibling
:
18559 /* Ignore absolute siblings, they might point outside of
18560 the current compile unit. */
18561 if (attr
.form
== DW_FORM_ref_addr
)
18562 complaint (&symfile_complaints
,
18563 _("ignoring absolute DW_AT_sibling"));
18566 const gdb_byte
*buffer
= reader
->buffer
;
18567 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
18568 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18570 if (sibling_ptr
< info_ptr
)
18571 complaint (&symfile_complaints
,
18572 _("DW_AT_sibling points backwards"));
18573 else if (sibling_ptr
> reader
->buffer_end
)
18574 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
18576 sibling
= sibling_ptr
;
18579 case DW_AT_byte_size
:
18582 case DW_AT_const_value
:
18583 has_const_value
= 1;
18585 case DW_AT_calling_convention
:
18586 /* DWARF doesn't provide a way to identify a program's source-level
18587 entry point. DW_AT_calling_convention attributes are only meant
18588 to describe functions' calling conventions.
18590 However, because it's a necessary piece of information in
18591 Fortran, and before DWARF 4 DW_CC_program was the only
18592 piece of debugging information whose definition refers to
18593 a 'main program' at all, several compilers marked Fortran
18594 main programs with DW_CC_program --- even when those
18595 functions use the standard calling conventions.
18597 Although DWARF now specifies a way to provide this
18598 information, we support this practice for backward
18600 if (DW_UNSND (&attr
) == DW_CC_program
18601 && cu
->language
== language_fortran
)
18602 main_subprogram
= 1;
18605 if (DW_UNSND (&attr
) == DW_INL_inlined
18606 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18607 may_be_inlined
= 1;
18611 if (tag
== DW_TAG_imported_unit
)
18613 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
18614 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18615 || cu
->per_cu
->is_dwz
);
18619 case DW_AT_main_subprogram
:
18620 main_subprogram
= DW_UNSND (&attr
);
18628 if (high_pc_relative
)
18631 if (has_low_pc_attr
&& has_high_pc_attr
)
18633 /* When using the GNU linker, .gnu.linkonce. sections are used to
18634 eliminate duplicate copies of functions and vtables and such.
18635 The linker will arbitrarily choose one and discard the others.
18636 The AT_*_pc values for such functions refer to local labels in
18637 these sections. If the section from that file was discarded, the
18638 labels are not in the output, so the relocs get a value of 0.
18639 If this is a discarded function, mark the pc bounds as invalid,
18640 so that GDB will ignore it. */
18641 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18643 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18644 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18646 complaint (&symfile_complaints
,
18647 _("DW_AT_low_pc %s is zero "
18648 "for DIE at %s [in module %s]"),
18649 paddress (gdbarch
, lowpc
),
18650 sect_offset_str (sect_off
),
18651 objfile_name (objfile
));
18653 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18654 else if (lowpc
>= highpc
)
18656 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18657 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18659 complaint (&symfile_complaints
,
18660 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18661 "for DIE at %s [in module %s]"),
18662 paddress (gdbarch
, lowpc
),
18663 paddress (gdbarch
, highpc
),
18664 sect_offset_str (sect_off
),
18665 objfile_name (objfile
));
18674 /* Find a cached partial DIE at OFFSET in CU. */
18676 struct partial_die_info
*
18677 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18679 struct partial_die_info
*lookup_die
= NULL
;
18680 struct partial_die_info
part_die (sect_off
);
18682 lookup_die
= ((struct partial_die_info
*)
18683 htab_find_with_hash (partial_dies
, &part_die
,
18684 to_underlying (sect_off
)));
18689 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18690 except in the case of .debug_types DIEs which do not reference
18691 outside their CU (they do however referencing other types via
18692 DW_FORM_ref_sig8). */
18694 static struct partial_die_info
*
18695 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18697 struct dwarf2_per_objfile
*dwarf2_per_objfile
18698 = cu
->per_cu
->dwarf2_per_objfile
;
18699 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18700 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18701 struct partial_die_info
*pd
= NULL
;
18703 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18704 && offset_in_cu_p (&cu
->header
, sect_off
))
18706 pd
= cu
->find_partial_die (sect_off
);
18709 /* We missed recording what we needed.
18710 Load all dies and try again. */
18711 per_cu
= cu
->per_cu
;
18715 /* TUs don't reference other CUs/TUs (except via type signatures). */
18716 if (cu
->per_cu
->is_debug_types
)
18718 error (_("Dwarf Error: Type Unit at offset %s contains"
18719 " external reference to offset %s [in module %s].\n"),
18720 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18721 bfd_get_filename (objfile
->obfd
));
18723 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18724 dwarf2_per_objfile
);
18726 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18727 load_partial_comp_unit (per_cu
);
18729 per_cu
->cu
->last_used
= 0;
18730 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18733 /* If we didn't find it, and not all dies have been loaded,
18734 load them all and try again. */
18736 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18738 per_cu
->load_all_dies
= 1;
18740 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18741 THIS_CU->cu may already be in use. So we can't just free it and
18742 replace its DIEs with the ones we read in. Instead, we leave those
18743 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18744 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18746 load_partial_comp_unit (per_cu
);
18748 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18752 internal_error (__FILE__
, __LINE__
,
18753 _("could not find partial DIE %s "
18754 "in cache [from module %s]\n"),
18755 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18759 /* See if we can figure out if the class lives in a namespace. We do
18760 this by looking for a member function; its demangled name will
18761 contain namespace info, if there is any. */
18764 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18765 struct dwarf2_cu
*cu
)
18767 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18768 what template types look like, because the demangler
18769 frequently doesn't give the same name as the debug info. We
18770 could fix this by only using the demangled name to get the
18771 prefix (but see comment in read_structure_type). */
18773 struct partial_die_info
*real_pdi
;
18774 struct partial_die_info
*child_pdi
;
18776 /* If this DIE (this DIE's specification, if any) has a parent, then
18777 we should not do this. We'll prepend the parent's fully qualified
18778 name when we create the partial symbol. */
18780 real_pdi
= struct_pdi
;
18781 while (real_pdi
->has_specification
)
18782 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
18783 real_pdi
->spec_is_dwz
, cu
);
18785 if (real_pdi
->die_parent
!= NULL
)
18788 for (child_pdi
= struct_pdi
->die_child
;
18790 child_pdi
= child_pdi
->die_sibling
)
18792 if (child_pdi
->tag
== DW_TAG_subprogram
18793 && child_pdi
->linkage_name
!= NULL
)
18795 char *actual_class_name
18796 = language_class_name_from_physname (cu
->language_defn
,
18797 child_pdi
->linkage_name
);
18798 if (actual_class_name
!= NULL
)
18800 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18803 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
18805 strlen (actual_class_name
)));
18806 xfree (actual_class_name
);
18814 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18816 /* Once we've fixed up a die, there's no point in doing so again.
18817 This also avoids a memory leak if we were to call
18818 guess_partial_die_structure_name multiple times. */
18822 /* If we found a reference attribute and the DIE has no name, try
18823 to find a name in the referred to DIE. */
18825 if (name
== NULL
&& has_specification
)
18827 struct partial_die_info
*spec_die
;
18829 spec_die
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18831 spec_die
->fixup (cu
);
18833 if (spec_die
->name
)
18835 name
= spec_die
->name
;
18837 /* Copy DW_AT_external attribute if it is set. */
18838 if (spec_die
->is_external
)
18839 is_external
= spec_die
->is_external
;
18843 /* Set default names for some unnamed DIEs. */
18845 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18846 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18848 /* If there is no parent die to provide a namespace, and there are
18849 children, see if we can determine the namespace from their linkage
18851 if (cu
->language
== language_cplus
18852 && !VEC_empty (dwarf2_section_info_def
,
18853 cu
->per_cu
->dwarf2_per_objfile
->types
)
18854 && die_parent
== NULL
18856 && (tag
== DW_TAG_class_type
18857 || tag
== DW_TAG_structure_type
18858 || tag
== DW_TAG_union_type
))
18859 guess_partial_die_structure_name (this, cu
);
18861 /* GCC might emit a nameless struct or union that has a linkage
18862 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18864 && (tag
== DW_TAG_class_type
18865 || tag
== DW_TAG_interface_type
18866 || tag
== DW_TAG_structure_type
18867 || tag
== DW_TAG_union_type
)
18868 && linkage_name
!= NULL
)
18872 demangled
= gdb_demangle (linkage_name
, DMGL_TYPES
);
18877 /* Strip any leading namespaces/classes, keep only the base name.
18878 DW_AT_name for named DIEs does not contain the prefixes. */
18879 base
= strrchr (demangled
, ':');
18880 if (base
&& base
> demangled
&& base
[-1] == ':')
18885 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18888 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
18889 base
, strlen (base
)));
18897 /* Read an attribute value described by an attribute form. */
18899 static const gdb_byte
*
18900 read_attribute_value (const struct die_reader_specs
*reader
,
18901 struct attribute
*attr
, unsigned form
,
18902 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
18904 struct dwarf2_cu
*cu
= reader
->cu
;
18905 struct dwarf2_per_objfile
*dwarf2_per_objfile
18906 = cu
->per_cu
->dwarf2_per_objfile
;
18907 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18908 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18909 bfd
*abfd
= reader
->abfd
;
18910 struct comp_unit_head
*cu_header
= &cu
->header
;
18911 unsigned int bytes_read
;
18912 struct dwarf_block
*blk
;
18914 attr
->form
= (enum dwarf_form
) form
;
18917 case DW_FORM_ref_addr
:
18918 if (cu
->header
.version
== 2)
18919 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
18921 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
18922 &cu
->header
, &bytes_read
);
18923 info_ptr
+= bytes_read
;
18925 case DW_FORM_GNU_ref_alt
:
18926 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
18927 info_ptr
+= bytes_read
;
18930 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
18931 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
18932 info_ptr
+= bytes_read
;
18934 case DW_FORM_block2
:
18935 blk
= dwarf_alloc_block (cu
);
18936 blk
->size
= read_2_bytes (abfd
, info_ptr
);
18938 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18939 info_ptr
+= blk
->size
;
18940 DW_BLOCK (attr
) = blk
;
18942 case DW_FORM_block4
:
18943 blk
= dwarf_alloc_block (cu
);
18944 blk
->size
= read_4_bytes (abfd
, info_ptr
);
18946 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18947 info_ptr
+= blk
->size
;
18948 DW_BLOCK (attr
) = blk
;
18950 case DW_FORM_data2
:
18951 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
18954 case DW_FORM_data4
:
18955 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
18958 case DW_FORM_data8
:
18959 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
18962 case DW_FORM_data16
:
18963 blk
= dwarf_alloc_block (cu
);
18965 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
18967 DW_BLOCK (attr
) = blk
;
18969 case DW_FORM_sec_offset
:
18970 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
18971 info_ptr
+= bytes_read
;
18973 case DW_FORM_string
:
18974 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
18975 DW_STRING_IS_CANONICAL (attr
) = 0;
18976 info_ptr
+= bytes_read
;
18979 if (!cu
->per_cu
->is_dwz
)
18981 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
18982 abfd
, info_ptr
, cu_header
,
18984 DW_STRING_IS_CANONICAL (attr
) = 0;
18985 info_ptr
+= bytes_read
;
18989 case DW_FORM_line_strp
:
18990 if (!cu
->per_cu
->is_dwz
)
18992 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
18994 cu_header
, &bytes_read
);
18995 DW_STRING_IS_CANONICAL (attr
) = 0;
18996 info_ptr
+= bytes_read
;
19000 case DW_FORM_GNU_strp_alt
:
19002 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19003 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
19006 DW_STRING (attr
) = read_indirect_string_from_dwz (objfile
,
19008 DW_STRING_IS_CANONICAL (attr
) = 0;
19009 info_ptr
+= bytes_read
;
19012 case DW_FORM_exprloc
:
19013 case DW_FORM_block
:
19014 blk
= dwarf_alloc_block (cu
);
19015 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19016 info_ptr
+= bytes_read
;
19017 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19018 info_ptr
+= blk
->size
;
19019 DW_BLOCK (attr
) = blk
;
19021 case DW_FORM_block1
:
19022 blk
= dwarf_alloc_block (cu
);
19023 blk
->size
= read_1_byte (abfd
, info_ptr
);
19025 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19026 info_ptr
+= blk
->size
;
19027 DW_BLOCK (attr
) = blk
;
19029 case DW_FORM_data1
:
19030 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19034 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19037 case DW_FORM_flag_present
:
19038 DW_UNSND (attr
) = 1;
19040 case DW_FORM_sdata
:
19041 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19042 info_ptr
+= bytes_read
;
19044 case DW_FORM_udata
:
19045 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19046 info_ptr
+= bytes_read
;
19049 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19050 + read_1_byte (abfd
, info_ptr
));
19054 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19055 + read_2_bytes (abfd
, info_ptr
));
19059 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19060 + read_4_bytes (abfd
, info_ptr
));
19064 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19065 + read_8_bytes (abfd
, info_ptr
));
19068 case DW_FORM_ref_sig8
:
19069 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19072 case DW_FORM_ref_udata
:
19073 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19074 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19075 info_ptr
+= bytes_read
;
19077 case DW_FORM_indirect
:
19078 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19079 info_ptr
+= bytes_read
;
19080 if (form
== DW_FORM_implicit_const
)
19082 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19083 info_ptr
+= bytes_read
;
19085 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19088 case DW_FORM_implicit_const
:
19089 DW_SND (attr
) = implicit_const
;
19091 case DW_FORM_GNU_addr_index
:
19092 if (reader
->dwo_file
== NULL
)
19094 /* For now flag a hard error.
19095 Later we can turn this into a complaint. */
19096 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19097 dwarf_form_name (form
),
19098 bfd_get_filename (abfd
));
19100 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
19101 info_ptr
+= bytes_read
;
19103 case DW_FORM_GNU_str_index
:
19104 if (reader
->dwo_file
== NULL
)
19106 /* For now flag a hard error.
19107 Later we can turn this into a complaint if warranted. */
19108 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19109 dwarf_form_name (form
),
19110 bfd_get_filename (abfd
));
19113 ULONGEST str_index
=
19114 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19116 DW_STRING (attr
) = read_str_index (reader
, str_index
);
19117 DW_STRING_IS_CANONICAL (attr
) = 0;
19118 info_ptr
+= bytes_read
;
19122 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19123 dwarf_form_name (form
),
19124 bfd_get_filename (abfd
));
19128 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
19129 attr
->form
= DW_FORM_GNU_ref_alt
;
19131 /* We have seen instances where the compiler tried to emit a byte
19132 size attribute of -1 which ended up being encoded as an unsigned
19133 0xffffffff. Although 0xffffffff is technically a valid size value,
19134 an object of this size seems pretty unlikely so we can relatively
19135 safely treat these cases as if the size attribute was invalid and
19136 treat them as zero by default. */
19137 if (attr
->name
== DW_AT_byte_size
19138 && form
== DW_FORM_data4
19139 && DW_UNSND (attr
) >= 0xffffffff)
19142 (&symfile_complaints
,
19143 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19144 hex_string (DW_UNSND (attr
)));
19145 DW_UNSND (attr
) = 0;
19151 /* Read an attribute described by an abbreviated attribute. */
19153 static const gdb_byte
*
19154 read_attribute (const struct die_reader_specs
*reader
,
19155 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19156 const gdb_byte
*info_ptr
)
19158 attr
->name
= abbrev
->name
;
19159 return read_attribute_value (reader
, attr
, abbrev
->form
,
19160 abbrev
->implicit_const
, info_ptr
);
19163 /* Read dwarf information from a buffer. */
19165 static unsigned int
19166 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
19168 return bfd_get_8 (abfd
, buf
);
19172 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
19174 return bfd_get_signed_8 (abfd
, buf
);
19177 static unsigned int
19178 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19180 return bfd_get_16 (abfd
, buf
);
19184 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19186 return bfd_get_signed_16 (abfd
, buf
);
19189 static unsigned int
19190 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19192 return bfd_get_32 (abfd
, buf
);
19196 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19198 return bfd_get_signed_32 (abfd
, buf
);
19202 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19204 return bfd_get_64 (abfd
, buf
);
19208 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
19209 unsigned int *bytes_read
)
19211 struct comp_unit_head
*cu_header
= &cu
->header
;
19212 CORE_ADDR retval
= 0;
19214 if (cu_header
->signed_addr_p
)
19216 switch (cu_header
->addr_size
)
19219 retval
= bfd_get_signed_16 (abfd
, buf
);
19222 retval
= bfd_get_signed_32 (abfd
, buf
);
19225 retval
= bfd_get_signed_64 (abfd
, buf
);
19228 internal_error (__FILE__
, __LINE__
,
19229 _("read_address: bad switch, signed [in module %s]"),
19230 bfd_get_filename (abfd
));
19235 switch (cu_header
->addr_size
)
19238 retval
= bfd_get_16 (abfd
, buf
);
19241 retval
= bfd_get_32 (abfd
, buf
);
19244 retval
= bfd_get_64 (abfd
, buf
);
19247 internal_error (__FILE__
, __LINE__
,
19248 _("read_address: bad switch, "
19249 "unsigned [in module %s]"),
19250 bfd_get_filename (abfd
));
19254 *bytes_read
= cu_header
->addr_size
;
19258 /* Read the initial length from a section. The (draft) DWARF 3
19259 specification allows the initial length to take up either 4 bytes
19260 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
19261 bytes describe the length and all offsets will be 8 bytes in length
19264 An older, non-standard 64-bit format is also handled by this
19265 function. The older format in question stores the initial length
19266 as an 8-byte quantity without an escape value. Lengths greater
19267 than 2^32 aren't very common which means that the initial 4 bytes
19268 is almost always zero. Since a length value of zero doesn't make
19269 sense for the 32-bit format, this initial zero can be considered to
19270 be an escape value which indicates the presence of the older 64-bit
19271 format. As written, the code can't detect (old format) lengths
19272 greater than 4GB. If it becomes necessary to handle lengths
19273 somewhat larger than 4GB, we could allow other small values (such
19274 as the non-sensical values of 1, 2, and 3) to also be used as
19275 escape values indicating the presence of the old format.
19277 The value returned via bytes_read should be used to increment the
19278 relevant pointer after calling read_initial_length().
19280 [ Note: read_initial_length() and read_offset() are based on the
19281 document entitled "DWARF Debugging Information Format", revision
19282 3, draft 8, dated November 19, 2001. This document was obtained
19285 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
19287 This document is only a draft and is subject to change. (So beware.)
19289 Details regarding the older, non-standard 64-bit format were
19290 determined empirically by examining 64-bit ELF files produced by
19291 the SGI toolchain on an IRIX 6.5 machine.
19293 - Kevin, July 16, 2002
19297 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
19299 LONGEST length
= bfd_get_32 (abfd
, buf
);
19301 if (length
== 0xffffffff)
19303 length
= bfd_get_64 (abfd
, buf
+ 4);
19306 else if (length
== 0)
19308 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
19309 length
= bfd_get_64 (abfd
, buf
);
19320 /* Cover function for read_initial_length.
19321 Returns the length of the object at BUF, and stores the size of the
19322 initial length in *BYTES_READ and stores the size that offsets will be in
19324 If the initial length size is not equivalent to that specified in
19325 CU_HEADER then issue a complaint.
19326 This is useful when reading non-comp-unit headers. */
19329 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
19330 const struct comp_unit_head
*cu_header
,
19331 unsigned int *bytes_read
,
19332 unsigned int *offset_size
)
19334 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
19336 gdb_assert (cu_header
->initial_length_size
== 4
19337 || cu_header
->initial_length_size
== 8
19338 || cu_header
->initial_length_size
== 12);
19340 if (cu_header
->initial_length_size
!= *bytes_read
)
19341 complaint (&symfile_complaints
,
19342 _("intermixed 32-bit and 64-bit DWARF sections"));
19344 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
19348 /* Read an offset from the data stream. The size of the offset is
19349 given by cu_header->offset_size. */
19352 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
19353 const struct comp_unit_head
*cu_header
,
19354 unsigned int *bytes_read
)
19356 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
19358 *bytes_read
= cu_header
->offset_size
;
19362 /* Read an offset from the data stream. */
19365 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
19367 LONGEST retval
= 0;
19369 switch (offset_size
)
19372 retval
= bfd_get_32 (abfd
, buf
);
19375 retval
= bfd_get_64 (abfd
, buf
);
19378 internal_error (__FILE__
, __LINE__
,
19379 _("read_offset_1: bad switch [in module %s]"),
19380 bfd_get_filename (abfd
));
19386 static const gdb_byte
*
19387 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
19389 /* If the size of a host char is 8 bits, we can return a pointer
19390 to the buffer, otherwise we have to copy the data to a buffer
19391 allocated on the temporary obstack. */
19392 gdb_assert (HOST_CHAR_BIT
== 8);
19396 static const char *
19397 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
19398 unsigned int *bytes_read_ptr
)
19400 /* If the size of a host char is 8 bits, we can return a pointer
19401 to the string, otherwise we have to copy the string to a buffer
19402 allocated on the temporary obstack. */
19403 gdb_assert (HOST_CHAR_BIT
== 8);
19406 *bytes_read_ptr
= 1;
19409 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
19410 return (const char *) buf
;
19413 /* Return pointer to string at section SECT offset STR_OFFSET with error
19414 reporting strings FORM_NAME and SECT_NAME. */
19416 static const char *
19417 read_indirect_string_at_offset_from (struct objfile
*objfile
,
19418 bfd
*abfd
, LONGEST str_offset
,
19419 struct dwarf2_section_info
*sect
,
19420 const char *form_name
,
19421 const char *sect_name
)
19423 dwarf2_read_section (objfile
, sect
);
19424 if (sect
->buffer
== NULL
)
19425 error (_("%s used without %s section [in module %s]"),
19426 form_name
, sect_name
, bfd_get_filename (abfd
));
19427 if (str_offset
>= sect
->size
)
19428 error (_("%s pointing outside of %s section [in module %s]"),
19429 form_name
, sect_name
, bfd_get_filename (abfd
));
19430 gdb_assert (HOST_CHAR_BIT
== 8);
19431 if (sect
->buffer
[str_offset
] == '\0')
19433 return (const char *) (sect
->buffer
+ str_offset
);
19436 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19438 static const char *
19439 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19440 bfd
*abfd
, LONGEST str_offset
)
19442 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19444 &dwarf2_per_objfile
->str
,
19445 "DW_FORM_strp", ".debug_str");
19448 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
19450 static const char *
19451 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19452 bfd
*abfd
, LONGEST str_offset
)
19454 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19456 &dwarf2_per_objfile
->line_str
,
19457 "DW_FORM_line_strp",
19458 ".debug_line_str");
19461 /* Read a string at offset STR_OFFSET in the .debug_str section from
19462 the .dwz file DWZ. Throw an error if the offset is too large. If
19463 the string consists of a single NUL byte, return NULL; otherwise
19464 return a pointer to the string. */
19466 static const char *
19467 read_indirect_string_from_dwz (struct objfile
*objfile
, struct dwz_file
*dwz
,
19468 LONGEST str_offset
)
19470 dwarf2_read_section (objfile
, &dwz
->str
);
19472 if (dwz
->str
.buffer
== NULL
)
19473 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
19474 "section [in module %s]"),
19475 bfd_get_filename (dwz
->dwz_bfd
));
19476 if (str_offset
>= dwz
->str
.size
)
19477 error (_("DW_FORM_GNU_strp_alt pointing outside of "
19478 ".debug_str section [in module %s]"),
19479 bfd_get_filename (dwz
->dwz_bfd
));
19480 gdb_assert (HOST_CHAR_BIT
== 8);
19481 if (dwz
->str
.buffer
[str_offset
] == '\0')
19483 return (const char *) (dwz
->str
.buffer
+ str_offset
);
19486 /* Return pointer to string at .debug_str offset as read from BUF.
19487 BUF is assumed to be in a compilation unit described by CU_HEADER.
19488 Return *BYTES_READ_PTR count of bytes read from BUF. */
19490 static const char *
19491 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
19492 const gdb_byte
*buf
,
19493 const struct comp_unit_head
*cu_header
,
19494 unsigned int *bytes_read_ptr
)
19496 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19498 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
19501 /* Return pointer to string at .debug_line_str offset as read from BUF.
19502 BUF is assumed to be in a compilation unit described by CU_HEADER.
19503 Return *BYTES_READ_PTR count of bytes read from BUF. */
19505 static const char *
19506 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19507 bfd
*abfd
, const gdb_byte
*buf
,
19508 const struct comp_unit_head
*cu_header
,
19509 unsigned int *bytes_read_ptr
)
19511 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19513 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
19518 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
19519 unsigned int *bytes_read_ptr
)
19522 unsigned int num_read
;
19524 unsigned char byte
;
19531 byte
= bfd_get_8 (abfd
, buf
);
19534 result
|= ((ULONGEST
) (byte
& 127) << shift
);
19535 if ((byte
& 128) == 0)
19541 *bytes_read_ptr
= num_read
;
19546 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
19547 unsigned int *bytes_read_ptr
)
19550 int shift
, num_read
;
19551 unsigned char byte
;
19558 byte
= bfd_get_8 (abfd
, buf
);
19561 result
|= ((LONGEST
) (byte
& 127) << shift
);
19563 if ((byte
& 128) == 0)
19568 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
19569 result
|= -(((LONGEST
) 1) << shift
);
19570 *bytes_read_ptr
= num_read
;
19574 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
19575 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
19576 ADDR_SIZE is the size of addresses from the CU header. */
19579 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19580 unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
19582 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19583 bfd
*abfd
= objfile
->obfd
;
19584 const gdb_byte
*info_ptr
;
19586 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
19587 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
19588 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
19589 objfile_name (objfile
));
19590 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
19591 error (_("DW_FORM_addr_index pointing outside of "
19592 ".debug_addr section [in module %s]"),
19593 objfile_name (objfile
));
19594 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
19595 + addr_base
+ addr_index
* addr_size
);
19596 if (addr_size
== 4)
19597 return bfd_get_32 (abfd
, info_ptr
);
19599 return bfd_get_64 (abfd
, info_ptr
);
19602 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
19605 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
19607 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
19608 cu
->addr_base
, cu
->header
.addr_size
);
19611 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
19614 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
19615 unsigned int *bytes_read
)
19617 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
19618 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
19620 return read_addr_index (cu
, addr_index
);
19623 /* Data structure to pass results from dwarf2_read_addr_index_reader
19624 back to dwarf2_read_addr_index. */
19626 struct dwarf2_read_addr_index_data
19628 ULONGEST addr_base
;
19632 /* die_reader_func for dwarf2_read_addr_index. */
19635 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
19636 const gdb_byte
*info_ptr
,
19637 struct die_info
*comp_unit_die
,
19641 struct dwarf2_cu
*cu
= reader
->cu
;
19642 struct dwarf2_read_addr_index_data
*aidata
=
19643 (struct dwarf2_read_addr_index_data
*) data
;
19645 aidata
->addr_base
= cu
->addr_base
;
19646 aidata
->addr_size
= cu
->header
.addr_size
;
19649 /* Given an index in .debug_addr, fetch the value.
19650 NOTE: This can be called during dwarf expression evaluation,
19651 long after the debug information has been read, and thus per_cu->cu
19652 may no longer exist. */
19655 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
19656 unsigned int addr_index
)
19658 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
19659 struct dwarf2_cu
*cu
= per_cu
->cu
;
19660 ULONGEST addr_base
;
19663 /* We need addr_base and addr_size.
19664 If we don't have PER_CU->cu, we have to get it.
19665 Nasty, but the alternative is storing the needed info in PER_CU,
19666 which at this point doesn't seem justified: it's not clear how frequently
19667 it would get used and it would increase the size of every PER_CU.
19668 Entry points like dwarf2_per_cu_addr_size do a similar thing
19669 so we're not in uncharted territory here.
19670 Alas we need to be a bit more complicated as addr_base is contained
19673 We don't need to read the entire CU(/TU).
19674 We just need the header and top level die.
19676 IWBN to use the aging mechanism to let us lazily later discard the CU.
19677 For now we skip this optimization. */
19681 addr_base
= cu
->addr_base
;
19682 addr_size
= cu
->header
.addr_size
;
19686 struct dwarf2_read_addr_index_data aidata
;
19688 /* Note: We can't use init_cutu_and_read_dies_simple here,
19689 we need addr_base. */
19690 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0, false,
19691 dwarf2_read_addr_index_reader
, &aidata
);
19692 addr_base
= aidata
.addr_base
;
19693 addr_size
= aidata
.addr_size
;
19696 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
19700 /* Given a DW_FORM_GNU_str_index, fetch the string.
19701 This is only used by the Fission support. */
19703 static const char *
19704 read_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
19706 struct dwarf2_cu
*cu
= reader
->cu
;
19707 struct dwarf2_per_objfile
*dwarf2_per_objfile
19708 = cu
->per_cu
->dwarf2_per_objfile
;
19709 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19710 const char *objf_name
= objfile_name (objfile
);
19711 bfd
*abfd
= objfile
->obfd
;
19712 struct dwarf2_section_info
*str_section
= &reader
->dwo_file
->sections
.str
;
19713 struct dwarf2_section_info
*str_offsets_section
=
19714 &reader
->dwo_file
->sections
.str_offsets
;
19715 const gdb_byte
*info_ptr
;
19716 ULONGEST str_offset
;
19717 static const char form_name
[] = "DW_FORM_GNU_str_index";
19719 dwarf2_read_section (objfile
, str_section
);
19720 dwarf2_read_section (objfile
, str_offsets_section
);
19721 if (str_section
->buffer
== NULL
)
19722 error (_("%s used without .debug_str.dwo section"
19723 " in CU at offset %s [in module %s]"),
19724 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19725 if (str_offsets_section
->buffer
== NULL
)
19726 error (_("%s used without .debug_str_offsets.dwo section"
19727 " in CU at offset %s [in module %s]"),
19728 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19729 if (str_index
* cu
->header
.offset_size
>= str_offsets_section
->size
)
19730 error (_("%s pointing outside of .debug_str_offsets.dwo"
19731 " section in CU at offset %s [in module %s]"),
19732 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19733 info_ptr
= (str_offsets_section
->buffer
19734 + str_index
* cu
->header
.offset_size
);
19735 if (cu
->header
.offset_size
== 4)
19736 str_offset
= bfd_get_32 (abfd
, info_ptr
);
19738 str_offset
= bfd_get_64 (abfd
, info_ptr
);
19739 if (str_offset
>= str_section
->size
)
19740 error (_("Offset from %s pointing outside of"
19741 " .debug_str.dwo section in CU at offset %s [in module %s]"),
19742 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19743 return (const char *) (str_section
->buffer
+ str_offset
);
19746 /* Return the length of an LEB128 number in BUF. */
19749 leb128_size (const gdb_byte
*buf
)
19751 const gdb_byte
*begin
= buf
;
19757 if ((byte
& 128) == 0)
19758 return buf
- begin
;
19763 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19772 cu
->language
= language_c
;
19775 case DW_LANG_C_plus_plus
:
19776 case DW_LANG_C_plus_plus_11
:
19777 case DW_LANG_C_plus_plus_14
:
19778 cu
->language
= language_cplus
;
19781 cu
->language
= language_d
;
19783 case DW_LANG_Fortran77
:
19784 case DW_LANG_Fortran90
:
19785 case DW_LANG_Fortran95
:
19786 case DW_LANG_Fortran03
:
19787 case DW_LANG_Fortran08
:
19788 cu
->language
= language_fortran
;
19791 cu
->language
= language_go
;
19793 case DW_LANG_Mips_Assembler
:
19794 cu
->language
= language_asm
;
19796 case DW_LANG_Ada83
:
19797 case DW_LANG_Ada95
:
19798 cu
->language
= language_ada
;
19800 case DW_LANG_Modula2
:
19801 cu
->language
= language_m2
;
19803 case DW_LANG_Pascal83
:
19804 cu
->language
= language_pascal
;
19807 cu
->language
= language_objc
;
19810 case DW_LANG_Rust_old
:
19811 cu
->language
= language_rust
;
19813 case DW_LANG_Cobol74
:
19814 case DW_LANG_Cobol85
:
19816 cu
->language
= language_minimal
;
19819 cu
->language_defn
= language_def (cu
->language
);
19822 /* Return the named attribute or NULL if not there. */
19824 static struct attribute
*
19825 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19830 struct attribute
*spec
= NULL
;
19832 for (i
= 0; i
< die
->num_attrs
; ++i
)
19834 if (die
->attrs
[i
].name
== name
)
19835 return &die
->attrs
[i
];
19836 if (die
->attrs
[i
].name
== DW_AT_specification
19837 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19838 spec
= &die
->attrs
[i
];
19844 die
= follow_die_ref (die
, spec
, &cu
);
19850 /* Return the named attribute or NULL if not there,
19851 but do not follow DW_AT_specification, etc.
19852 This is for use in contexts where we're reading .debug_types dies.
19853 Following DW_AT_specification, DW_AT_abstract_origin will take us
19854 back up the chain, and we want to go down. */
19856 static struct attribute
*
19857 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
19861 for (i
= 0; i
< die
->num_attrs
; ++i
)
19862 if (die
->attrs
[i
].name
== name
)
19863 return &die
->attrs
[i
];
19868 /* Return the string associated with a string-typed attribute, or NULL if it
19869 is either not found or is of an incorrect type. */
19871 static const char *
19872 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19874 struct attribute
*attr
;
19875 const char *str
= NULL
;
19877 attr
= dwarf2_attr (die
, name
, cu
);
19881 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
19882 || attr
->form
== DW_FORM_string
19883 || attr
->form
== DW_FORM_GNU_str_index
19884 || attr
->form
== DW_FORM_GNU_strp_alt
)
19885 str
= DW_STRING (attr
);
19887 complaint (&symfile_complaints
,
19888 _("string type expected for attribute %s for "
19889 "DIE at %s in module %s"),
19890 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19891 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
19897 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19898 and holds a non-zero value. This function should only be used for
19899 DW_FORM_flag or DW_FORM_flag_present attributes. */
19902 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19904 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19906 return (attr
&& DW_UNSND (attr
));
19910 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19912 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19913 which value is non-zero. However, we have to be careful with
19914 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19915 (via dwarf2_flag_true_p) follows this attribute. So we may
19916 end up accidently finding a declaration attribute that belongs
19917 to a different DIE referenced by the specification attribute,
19918 even though the given DIE does not have a declaration attribute. */
19919 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19920 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19923 /* Return the die giving the specification for DIE, if there is
19924 one. *SPEC_CU is the CU containing DIE on input, and the CU
19925 containing the return value on output. If there is no
19926 specification, but there is an abstract origin, that is
19929 static struct die_info
*
19930 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19932 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19935 if (spec_attr
== NULL
)
19936 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19938 if (spec_attr
== NULL
)
19941 return follow_die_ref (die
, spec_attr
, spec_cu
);
19944 /* Stub for free_line_header to match void * callback types. */
19947 free_line_header_voidp (void *arg
)
19949 struct line_header
*lh
= (struct line_header
*) arg
;
19955 line_header::add_include_dir (const char *include_dir
)
19957 if (dwarf_line_debug
>= 2)
19958 fprintf_unfiltered (gdb_stdlog
, "Adding dir %zu: %s\n",
19959 include_dirs
.size () + 1, include_dir
);
19961 include_dirs
.push_back (include_dir
);
19965 line_header::add_file_name (const char *name
,
19967 unsigned int mod_time
,
19968 unsigned int length
)
19970 if (dwarf_line_debug
>= 2)
19971 fprintf_unfiltered (gdb_stdlog
, "Adding file %u: %s\n",
19972 (unsigned) file_names
.size () + 1, name
);
19974 file_names
.emplace_back (name
, d_index
, mod_time
, length
);
19977 /* A convenience function to find the proper .debug_line section for a CU. */
19979 static struct dwarf2_section_info
*
19980 get_debug_line_section (struct dwarf2_cu
*cu
)
19982 struct dwarf2_section_info
*section
;
19983 struct dwarf2_per_objfile
*dwarf2_per_objfile
19984 = cu
->per_cu
->dwarf2_per_objfile
;
19986 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19988 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19989 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19990 else if (cu
->per_cu
->is_dwz
)
19992 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19994 section
= &dwz
->line
;
19997 section
= &dwarf2_per_objfile
->line
;
20002 /* Read directory or file name entry format, starting with byte of
20003 format count entries, ULEB128 pairs of entry formats, ULEB128 of
20004 entries count and the entries themselves in the described entry
20008 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20009 bfd
*abfd
, const gdb_byte
**bufp
,
20010 struct line_header
*lh
,
20011 const struct comp_unit_head
*cu_header
,
20012 void (*callback
) (struct line_header
*lh
,
20015 unsigned int mod_time
,
20016 unsigned int length
))
20018 gdb_byte format_count
, formati
;
20019 ULONGEST data_count
, datai
;
20020 const gdb_byte
*buf
= *bufp
;
20021 const gdb_byte
*format_header_data
;
20022 unsigned int bytes_read
;
20024 format_count
= read_1_byte (abfd
, buf
);
20026 format_header_data
= buf
;
20027 for (formati
= 0; formati
< format_count
; formati
++)
20029 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20031 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20035 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20037 for (datai
= 0; datai
< data_count
; datai
++)
20039 const gdb_byte
*format
= format_header_data
;
20040 struct file_entry fe
;
20042 for (formati
= 0; formati
< format_count
; formati
++)
20044 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20045 format
+= bytes_read
;
20047 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20048 format
+= bytes_read
;
20050 gdb::optional
<const char *> string
;
20051 gdb::optional
<unsigned int> uint
;
20055 case DW_FORM_string
:
20056 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
20060 case DW_FORM_line_strp
:
20061 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
20068 case DW_FORM_data1
:
20069 uint
.emplace (read_1_byte (abfd
, buf
));
20073 case DW_FORM_data2
:
20074 uint
.emplace (read_2_bytes (abfd
, buf
));
20078 case DW_FORM_data4
:
20079 uint
.emplace (read_4_bytes (abfd
, buf
));
20083 case DW_FORM_data8
:
20084 uint
.emplace (read_8_bytes (abfd
, buf
));
20088 case DW_FORM_udata
:
20089 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
20093 case DW_FORM_block
:
20094 /* It is valid only for DW_LNCT_timestamp which is ignored by
20099 switch (content_type
)
20102 if (string
.has_value ())
20105 case DW_LNCT_directory_index
:
20106 if (uint
.has_value ())
20107 fe
.d_index
= (dir_index
) *uint
;
20109 case DW_LNCT_timestamp
:
20110 if (uint
.has_value ())
20111 fe
.mod_time
= *uint
;
20114 if (uint
.has_value ())
20120 complaint (&symfile_complaints
,
20121 _("Unknown format content type %s"),
20122 pulongest (content_type
));
20126 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
20132 /* Read the statement program header starting at OFFSET in
20133 .debug_line, or .debug_line.dwo. Return a pointer
20134 to a struct line_header, allocated using xmalloc.
20135 Returns NULL if there is a problem reading the header, e.g., if it
20136 has a version we don't understand.
20138 NOTE: the strings in the include directory and file name tables of
20139 the returned object point into the dwarf line section buffer,
20140 and must not be freed. */
20142 static line_header_up
20143 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20145 const gdb_byte
*line_ptr
;
20146 unsigned int bytes_read
, offset_size
;
20148 const char *cur_dir
, *cur_file
;
20149 struct dwarf2_section_info
*section
;
20151 struct dwarf2_per_objfile
*dwarf2_per_objfile
20152 = cu
->per_cu
->dwarf2_per_objfile
;
20154 section
= get_debug_line_section (cu
);
20155 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
20156 if (section
->buffer
== NULL
)
20158 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20159 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
20161 complaint (&symfile_complaints
, _("missing .debug_line section"));
20165 /* We can't do this until we know the section is non-empty.
20166 Only then do we know we have such a section. */
20167 abfd
= get_section_bfd_owner (section
);
20169 /* Make sure that at least there's room for the total_length field.
20170 That could be 12 bytes long, but we're just going to fudge that. */
20171 if (to_underlying (sect_off
) + 4 >= section
->size
)
20173 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20177 line_header_up
lh (new line_header ());
20179 lh
->sect_off
= sect_off
;
20180 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
20182 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
20184 /* Read in the header. */
20186 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
20187 &bytes_read
, &offset_size
);
20188 line_ptr
+= bytes_read
;
20189 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
20191 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20194 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
20195 lh
->version
= read_2_bytes (abfd
, line_ptr
);
20197 if (lh
->version
> 5)
20199 /* This is a version we don't understand. The format could have
20200 changed in ways we don't handle properly so just punt. */
20201 complaint (&symfile_complaints
,
20202 _("unsupported version in .debug_line section"));
20205 if (lh
->version
>= 5)
20207 gdb_byte segment_selector_size
;
20209 /* Skip address size. */
20210 read_1_byte (abfd
, line_ptr
);
20213 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
20215 if (segment_selector_size
!= 0)
20217 complaint (&symfile_complaints
,
20218 _("unsupported segment selector size %u "
20219 "in .debug_line section"),
20220 segment_selector_size
);
20224 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
20225 line_ptr
+= offset_size
;
20226 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
20228 if (lh
->version
>= 4)
20230 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
20234 lh
->maximum_ops_per_instruction
= 1;
20236 if (lh
->maximum_ops_per_instruction
== 0)
20238 lh
->maximum_ops_per_instruction
= 1;
20239 complaint (&symfile_complaints
,
20240 _("invalid maximum_ops_per_instruction "
20241 "in `.debug_line' section"));
20244 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
20246 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
20248 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
20250 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
20252 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
20254 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
20255 for (i
= 1; i
< lh
->opcode_base
; ++i
)
20257 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
20261 if (lh
->version
>= 5)
20263 /* Read directory table. */
20264 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20266 [] (struct line_header
*lh
, const char *name
,
20267 dir_index d_index
, unsigned int mod_time
,
20268 unsigned int length
)
20270 lh
->add_include_dir (name
);
20273 /* Read file name table. */
20274 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20276 [] (struct line_header
*lh
, const char *name
,
20277 dir_index d_index
, unsigned int mod_time
,
20278 unsigned int length
)
20280 lh
->add_file_name (name
, d_index
, mod_time
, length
);
20285 /* Read directory table. */
20286 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20288 line_ptr
+= bytes_read
;
20289 lh
->add_include_dir (cur_dir
);
20291 line_ptr
+= bytes_read
;
20293 /* Read file name table. */
20294 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20296 unsigned int mod_time
, length
;
20299 line_ptr
+= bytes_read
;
20300 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20301 line_ptr
+= bytes_read
;
20302 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20303 line_ptr
+= bytes_read
;
20304 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20305 line_ptr
+= bytes_read
;
20307 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
20309 line_ptr
+= bytes_read
;
20311 lh
->statement_program_start
= line_ptr
;
20313 if (line_ptr
> (section
->buffer
+ section
->size
))
20314 complaint (&symfile_complaints
,
20315 _("line number info header doesn't "
20316 "fit in `.debug_line' section"));
20321 /* Subroutine of dwarf_decode_lines to simplify it.
20322 Return the file name of the psymtab for included file FILE_INDEX
20323 in line header LH of PST.
20324 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20325 If space for the result is malloc'd, *NAME_HOLDER will be set.
20326 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20328 static const char *
20329 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
20330 const struct partial_symtab
*pst
,
20331 const char *comp_dir
,
20332 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20334 const file_entry
&fe
= lh
->file_names
[file_index
];
20335 const char *include_name
= fe
.name
;
20336 const char *include_name_to_compare
= include_name
;
20337 const char *pst_filename
;
20340 const char *dir_name
= fe
.include_dir (lh
);
20342 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20343 if (!IS_ABSOLUTE_PATH (include_name
)
20344 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20346 /* Avoid creating a duplicate psymtab for PST.
20347 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20348 Before we do the comparison, however, we need to account
20349 for DIR_NAME and COMP_DIR.
20350 First prepend dir_name (if non-NULL). If we still don't
20351 have an absolute path prepend comp_dir (if non-NULL).
20352 However, the directory we record in the include-file's
20353 psymtab does not contain COMP_DIR (to match the
20354 corresponding symtab(s)).
20359 bash$ gcc -g ./hello.c
20360 include_name = "hello.c"
20362 DW_AT_comp_dir = comp_dir = "/tmp"
20363 DW_AT_name = "./hello.c"
20367 if (dir_name
!= NULL
)
20369 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20370 include_name
, (char *) NULL
));
20371 include_name
= name_holder
->get ();
20372 include_name_to_compare
= include_name
;
20374 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20376 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20377 include_name
, (char *) NULL
));
20378 include_name_to_compare
= hold_compare
.get ();
20382 pst_filename
= pst
->filename
;
20383 gdb::unique_xmalloc_ptr
<char> copied_name
;
20384 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20386 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20387 pst_filename
, (char *) NULL
));
20388 pst_filename
= copied_name
.get ();
20391 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20395 return include_name
;
20398 /* State machine to track the state of the line number program. */
20400 class lnp_state_machine
20403 /* Initialize a machine state for the start of a line number
20405 lnp_state_machine (gdbarch
*arch
, line_header
*lh
, bool record_lines_p
);
20407 file_entry
*current_file ()
20409 /* lh->file_names is 0-based, but the file name numbers in the
20410 statement program are 1-based. */
20411 return m_line_header
->file_name_at (m_file
);
20414 /* Record the line in the state machine. END_SEQUENCE is true if
20415 we're processing the end of a sequence. */
20416 void record_line (bool end_sequence
);
20418 /* Check address and if invalid nop-out the rest of the lines in this
20420 void check_line_address (struct dwarf2_cu
*cu
,
20421 const gdb_byte
*line_ptr
,
20422 CORE_ADDR lowpc
, CORE_ADDR address
);
20424 void handle_set_discriminator (unsigned int discriminator
)
20426 m_discriminator
= discriminator
;
20427 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20430 /* Handle DW_LNE_set_address. */
20431 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20434 address
+= baseaddr
;
20435 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20438 /* Handle DW_LNS_advance_pc. */
20439 void handle_advance_pc (CORE_ADDR adjust
);
20441 /* Handle a special opcode. */
20442 void handle_special_opcode (unsigned char op_code
);
20444 /* Handle DW_LNS_advance_line. */
20445 void handle_advance_line (int line_delta
)
20447 advance_line (line_delta
);
20450 /* Handle DW_LNS_set_file. */
20451 void handle_set_file (file_name_index file
);
20453 /* Handle DW_LNS_negate_stmt. */
20454 void handle_negate_stmt ()
20456 m_is_stmt
= !m_is_stmt
;
20459 /* Handle DW_LNS_const_add_pc. */
20460 void handle_const_add_pc ();
20462 /* Handle DW_LNS_fixed_advance_pc. */
20463 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20465 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20469 /* Handle DW_LNS_copy. */
20470 void handle_copy ()
20472 record_line (false);
20473 m_discriminator
= 0;
20476 /* Handle DW_LNE_end_sequence. */
20477 void handle_end_sequence ()
20479 m_record_line_callback
= ::record_line
;
20483 /* Advance the line by LINE_DELTA. */
20484 void advance_line (int line_delta
)
20486 m_line
+= line_delta
;
20488 if (line_delta
!= 0)
20489 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20492 gdbarch
*m_gdbarch
;
20494 /* True if we're recording lines.
20495 Otherwise we're building partial symtabs and are just interested in
20496 finding include files mentioned by the line number program. */
20497 bool m_record_lines_p
;
20499 /* The line number header. */
20500 line_header
*m_line_header
;
20502 /* These are part of the standard DWARF line number state machine,
20503 and initialized according to the DWARF spec. */
20505 unsigned char m_op_index
= 0;
20506 /* The line table index (1-based) of the current file. */
20507 file_name_index m_file
= (file_name_index
) 1;
20508 unsigned int m_line
= 1;
20510 /* These are initialized in the constructor. */
20512 CORE_ADDR m_address
;
20514 unsigned int m_discriminator
;
20516 /* Additional bits of state we need to track. */
20518 /* The last file that we called dwarf2_start_subfile for.
20519 This is only used for TLLs. */
20520 unsigned int m_last_file
= 0;
20521 /* The last file a line number was recorded for. */
20522 struct subfile
*m_last_subfile
= NULL
;
20524 /* The function to call to record a line. */
20525 record_line_ftype
*m_record_line_callback
= NULL
;
20527 /* The last line number that was recorded, used to coalesce
20528 consecutive entries for the same line. This can happen, for
20529 example, when discriminators are present. PR 17276. */
20530 unsigned int m_last_line
= 0;
20531 bool m_line_has_non_zero_discriminator
= false;
20535 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20537 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20538 / m_line_header
->maximum_ops_per_instruction
)
20539 * m_line_header
->minimum_instruction_length
);
20540 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20541 m_op_index
= ((m_op_index
+ adjust
)
20542 % m_line_header
->maximum_ops_per_instruction
);
20546 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20548 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20549 CORE_ADDR addr_adj
= (((m_op_index
20550 + (adj_opcode
/ m_line_header
->line_range
))
20551 / m_line_header
->maximum_ops_per_instruction
)
20552 * m_line_header
->minimum_instruction_length
);
20553 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20554 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
20555 % m_line_header
->maximum_ops_per_instruction
);
20557 int line_delta
= (m_line_header
->line_base
20558 + (adj_opcode
% m_line_header
->line_range
));
20559 advance_line (line_delta
);
20560 record_line (false);
20561 m_discriminator
= 0;
20565 lnp_state_machine::handle_set_file (file_name_index file
)
20569 const file_entry
*fe
= current_file ();
20571 dwarf2_debug_line_missing_file_complaint ();
20572 else if (m_record_lines_p
)
20574 const char *dir
= fe
->include_dir (m_line_header
);
20576 m_last_subfile
= current_subfile
;
20577 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20578 dwarf2_start_subfile (fe
->name
, dir
);
20583 lnp_state_machine::handle_const_add_pc ()
20586 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20589 = (((m_op_index
+ adjust
)
20590 / m_line_header
->maximum_ops_per_instruction
)
20591 * m_line_header
->minimum_instruction_length
);
20593 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20594 m_op_index
= ((m_op_index
+ adjust
)
20595 % m_line_header
->maximum_ops_per_instruction
);
20598 /* Ignore this record_line request. */
20601 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
20606 /* Return non-zero if we should add LINE to the line number table.
20607 LINE is the line to add, LAST_LINE is the last line that was added,
20608 LAST_SUBFILE is the subfile for LAST_LINE.
20609 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20610 had a non-zero discriminator.
20612 We have to be careful in the presence of discriminators.
20613 E.g., for this line:
20615 for (i = 0; i < 100000; i++);
20617 clang can emit four line number entries for that one line,
20618 each with a different discriminator.
20619 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20621 However, we want gdb to coalesce all four entries into one.
20622 Otherwise the user could stepi into the middle of the line and
20623 gdb would get confused about whether the pc really was in the
20624 middle of the line.
20626 Things are further complicated by the fact that two consecutive
20627 line number entries for the same line is a heuristic used by gcc
20628 to denote the end of the prologue. So we can't just discard duplicate
20629 entries, we have to be selective about it. The heuristic we use is
20630 that we only collapse consecutive entries for the same line if at least
20631 one of those entries has a non-zero discriminator. PR 17276.
20633 Note: Addresses in the line number state machine can never go backwards
20634 within one sequence, thus this coalescing is ok. */
20637 dwarf_record_line_p (unsigned int line
, unsigned int last_line
,
20638 int line_has_non_zero_discriminator
,
20639 struct subfile
*last_subfile
)
20641 if (current_subfile
!= last_subfile
)
20643 if (line
!= last_line
)
20645 /* Same line for the same file that we've seen already.
20646 As a last check, for pr 17276, only record the line if the line
20647 has never had a non-zero discriminator. */
20648 if (!line_has_non_zero_discriminator
)
20653 /* Use P_RECORD_LINE to record line number LINE beginning at address ADDRESS
20654 in the line table of subfile SUBFILE. */
20657 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20658 unsigned int line
, CORE_ADDR address
,
20659 record_line_ftype p_record_line
)
20661 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20663 if (dwarf_line_debug
)
20665 fprintf_unfiltered (gdb_stdlog
,
20666 "Recording line %u, file %s, address %s\n",
20667 line
, lbasename (subfile
->name
),
20668 paddress (gdbarch
, address
));
20671 (*p_record_line
) (subfile
, line
, addr
);
20674 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20675 Mark the end of a set of line number records.
20676 The arguments are the same as for dwarf_record_line_1.
20677 If SUBFILE is NULL the request is ignored. */
20680 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20681 CORE_ADDR address
, record_line_ftype p_record_line
)
20683 if (subfile
== NULL
)
20686 if (dwarf_line_debug
)
20688 fprintf_unfiltered (gdb_stdlog
,
20689 "Finishing current line, file %s, address %s\n",
20690 lbasename (subfile
->name
),
20691 paddress (gdbarch
, address
));
20694 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, p_record_line
);
20698 lnp_state_machine::record_line (bool end_sequence
)
20700 if (dwarf_line_debug
)
20702 fprintf_unfiltered (gdb_stdlog
,
20703 "Processing actual line %u: file %u,"
20704 " address %s, is_stmt %u, discrim %u\n",
20705 m_line
, to_underlying (m_file
),
20706 paddress (m_gdbarch
, m_address
),
20707 m_is_stmt
, m_discriminator
);
20710 file_entry
*fe
= current_file ();
20713 dwarf2_debug_line_missing_file_complaint ();
20714 /* For now we ignore lines not starting on an instruction boundary.
20715 But not when processing end_sequence for compatibility with the
20716 previous version of the code. */
20717 else if (m_op_index
== 0 || end_sequence
)
20719 fe
->included_p
= 1;
20720 if (m_record_lines_p
&& m_is_stmt
)
20722 if (m_last_subfile
!= current_subfile
|| end_sequence
)
20724 dwarf_finish_line (m_gdbarch
, m_last_subfile
,
20725 m_address
, m_record_line_callback
);
20730 if (dwarf_record_line_p (m_line
, m_last_line
,
20731 m_line_has_non_zero_discriminator
,
20734 dwarf_record_line_1 (m_gdbarch
, current_subfile
,
20736 m_record_line_callback
);
20738 m_last_subfile
= current_subfile
;
20739 m_last_line
= m_line
;
20745 lnp_state_machine::lnp_state_machine (gdbarch
*arch
, line_header
*lh
,
20746 bool record_lines_p
)
20749 m_record_lines_p
= record_lines_p
;
20750 m_line_header
= lh
;
20752 m_record_line_callback
= ::record_line
;
20754 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20755 was a line entry for it so that the backend has a chance to adjust it
20756 and also record it in case it needs it. This is currently used by MIPS
20757 code, cf. `mips_adjust_dwarf2_line'. */
20758 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20759 m_is_stmt
= lh
->default_is_stmt
;
20760 m_discriminator
= 0;
20764 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20765 const gdb_byte
*line_ptr
,
20766 CORE_ADDR lowpc
, CORE_ADDR address
)
20768 /* If address < lowpc then it's not a usable value, it's outside the
20769 pc range of the CU. However, we restrict the test to only address
20770 values of zero to preserve GDB's previous behaviour which is to
20771 handle the specific case of a function being GC'd by the linker. */
20773 if (address
== 0 && address
< lowpc
)
20775 /* This line table is for a function which has been
20776 GCd by the linker. Ignore it. PR gdb/12528 */
20778 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20779 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20781 complaint (&symfile_complaints
,
20782 _(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20783 line_offset
, objfile_name (objfile
));
20784 m_record_line_callback
= noop_record_line
;
20785 /* Note: record_line_callback is left as noop_record_line until
20786 we see DW_LNE_end_sequence. */
20790 /* Subroutine of dwarf_decode_lines to simplify it.
20791 Process the line number information in LH.
20792 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20793 program in order to set included_p for every referenced header. */
20796 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20797 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20799 const gdb_byte
*line_ptr
, *extended_end
;
20800 const gdb_byte
*line_end
;
20801 unsigned int bytes_read
, extended_len
;
20802 unsigned char op_code
, extended_op
;
20803 CORE_ADDR baseaddr
;
20804 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20805 bfd
*abfd
= objfile
->obfd
;
20806 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20807 /* True if we're recording line info (as opposed to building partial
20808 symtabs and just interested in finding include files mentioned by
20809 the line number program). */
20810 bool record_lines_p
= !decode_for_pst_p
;
20812 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
20814 line_ptr
= lh
->statement_program_start
;
20815 line_end
= lh
->statement_program_end
;
20817 /* Read the statement sequences until there's nothing left. */
20818 while (line_ptr
< line_end
)
20820 /* The DWARF line number program state machine. Reset the state
20821 machine at the start of each sequence. */
20822 lnp_state_machine
state_machine (gdbarch
, lh
, record_lines_p
);
20823 bool end_sequence
= false;
20825 if (record_lines_p
)
20827 /* Start a subfile for the current file of the state
20829 const file_entry
*fe
= state_machine
.current_file ();
20832 dwarf2_start_subfile (fe
->name
, fe
->include_dir (lh
));
20835 /* Decode the table. */
20836 while (line_ptr
< line_end
&& !end_sequence
)
20838 op_code
= read_1_byte (abfd
, line_ptr
);
20841 if (op_code
>= lh
->opcode_base
)
20843 /* Special opcode. */
20844 state_machine
.handle_special_opcode (op_code
);
20846 else switch (op_code
)
20848 case DW_LNS_extended_op
:
20849 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20851 line_ptr
+= bytes_read
;
20852 extended_end
= line_ptr
+ extended_len
;
20853 extended_op
= read_1_byte (abfd
, line_ptr
);
20855 switch (extended_op
)
20857 case DW_LNE_end_sequence
:
20858 state_machine
.handle_end_sequence ();
20859 end_sequence
= true;
20861 case DW_LNE_set_address
:
20864 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
20865 line_ptr
+= bytes_read
;
20867 state_machine
.check_line_address (cu
, line_ptr
,
20869 state_machine
.handle_set_address (baseaddr
, address
);
20872 case DW_LNE_define_file
:
20874 const char *cur_file
;
20875 unsigned int mod_time
, length
;
20878 cur_file
= read_direct_string (abfd
, line_ptr
,
20880 line_ptr
+= bytes_read
;
20881 dindex
= (dir_index
)
20882 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20883 line_ptr
+= bytes_read
;
20885 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20886 line_ptr
+= bytes_read
;
20888 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20889 line_ptr
+= bytes_read
;
20890 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20893 case DW_LNE_set_discriminator
:
20895 /* The discriminator is not interesting to the
20896 debugger; just ignore it. We still need to
20897 check its value though:
20898 if there are consecutive entries for the same
20899 (non-prologue) line we want to coalesce them.
20902 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20903 line_ptr
+= bytes_read
;
20905 state_machine
.handle_set_discriminator (discr
);
20909 complaint (&symfile_complaints
,
20910 _("mangled .debug_line section"));
20913 /* Make sure that we parsed the extended op correctly. If e.g.
20914 we expected a different address size than the producer used,
20915 we may have read the wrong number of bytes. */
20916 if (line_ptr
!= extended_end
)
20918 complaint (&symfile_complaints
,
20919 _("mangled .debug_line section"));
20924 state_machine
.handle_copy ();
20926 case DW_LNS_advance_pc
:
20929 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20930 line_ptr
+= bytes_read
;
20932 state_machine
.handle_advance_pc (adjust
);
20935 case DW_LNS_advance_line
:
20938 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20939 line_ptr
+= bytes_read
;
20941 state_machine
.handle_advance_line (line_delta
);
20944 case DW_LNS_set_file
:
20946 file_name_index file
20947 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20949 line_ptr
+= bytes_read
;
20951 state_machine
.handle_set_file (file
);
20954 case DW_LNS_set_column
:
20955 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20956 line_ptr
+= bytes_read
;
20958 case DW_LNS_negate_stmt
:
20959 state_machine
.handle_negate_stmt ();
20961 case DW_LNS_set_basic_block
:
20963 /* Add to the address register of the state machine the
20964 address increment value corresponding to special opcode
20965 255. I.e., this value is scaled by the minimum
20966 instruction length since special opcode 255 would have
20967 scaled the increment. */
20968 case DW_LNS_const_add_pc
:
20969 state_machine
.handle_const_add_pc ();
20971 case DW_LNS_fixed_advance_pc
:
20973 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20976 state_machine
.handle_fixed_advance_pc (addr_adj
);
20981 /* Unknown standard opcode, ignore it. */
20984 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
20986 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20987 line_ptr
+= bytes_read
;
20994 dwarf2_debug_line_missing_end_sequence_complaint ();
20996 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
20997 in which case we still finish recording the last line). */
20998 state_machine
.record_line (true);
21002 /* Decode the Line Number Program (LNP) for the given line_header
21003 structure and CU. The actual information extracted and the type
21004 of structures created from the LNP depends on the value of PST.
21006 1. If PST is NULL, then this procedure uses the data from the program
21007 to create all necessary symbol tables, and their linetables.
21009 2. If PST is not NULL, this procedure reads the program to determine
21010 the list of files included by the unit represented by PST, and
21011 builds all the associated partial symbol tables.
21013 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21014 It is used for relative paths in the line table.
21015 NOTE: When processing partial symtabs (pst != NULL),
21016 comp_dir == pst->dirname.
21018 NOTE: It is important that psymtabs have the same file name (via strcmp)
21019 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21020 symtab we don't use it in the name of the psymtabs we create.
21021 E.g. expand_line_sal requires this when finding psymtabs to expand.
21022 A good testcase for this is mb-inline.exp.
21024 LOWPC is the lowest address in CU (or 0 if not known).
21026 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21027 for its PC<->lines mapping information. Otherwise only the filename
21028 table is read in. */
21031 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21032 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
21033 CORE_ADDR lowpc
, int decode_mapping
)
21035 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21036 const int decode_for_pst_p
= (pst
!= NULL
);
21038 if (decode_mapping
)
21039 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21041 if (decode_for_pst_p
)
21045 /* Now that we're done scanning the Line Header Program, we can
21046 create the psymtab of each included file. */
21047 for (file_index
= 0; file_index
< lh
->file_names
.size (); file_index
++)
21048 if (lh
->file_names
[file_index
].included_p
== 1)
21050 gdb::unique_xmalloc_ptr
<char> name_holder
;
21051 const char *include_name
=
21052 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
,
21054 if (include_name
!= NULL
)
21055 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
21060 /* Make sure a symtab is created for every file, even files
21061 which contain only variables (i.e. no code with associated
21063 struct compunit_symtab
*cust
= buildsym_compunit_symtab ();
21066 for (i
= 0; i
< lh
->file_names
.size (); i
++)
21068 file_entry
&fe
= lh
->file_names
[i
];
21070 dwarf2_start_subfile (fe
.name
, fe
.include_dir (lh
));
21072 if (current_subfile
->symtab
== NULL
)
21074 current_subfile
->symtab
21075 = allocate_symtab (cust
, current_subfile
->name
);
21077 fe
.symtab
= current_subfile
->symtab
;
21082 /* Start a subfile for DWARF. FILENAME is the name of the file and
21083 DIRNAME the name of the source directory which contains FILENAME
21084 or NULL if not known.
21085 This routine tries to keep line numbers from identical absolute and
21086 relative file names in a common subfile.
21088 Using the `list' example from the GDB testsuite, which resides in
21089 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21090 of /srcdir/list0.c yields the following debugging information for list0.c:
21092 DW_AT_name: /srcdir/list0.c
21093 DW_AT_comp_dir: /compdir
21094 files.files[0].name: list0.h
21095 files.files[0].dir: /srcdir
21096 files.files[1].name: list0.c
21097 files.files[1].dir: /srcdir
21099 The line number information for list0.c has to end up in a single
21100 subfile, so that `break /srcdir/list0.c:1' works as expected.
21101 start_subfile will ensure that this happens provided that we pass the
21102 concatenation of files.files[1].dir and files.files[1].name as the
21106 dwarf2_start_subfile (const char *filename
, const char *dirname
)
21110 /* In order not to lose the line information directory,
21111 we concatenate it to the filename when it makes sense.
21112 Note that the Dwarf3 standard says (speaking of filenames in line
21113 information): ``The directory index is ignored for file names
21114 that represent full path names''. Thus ignoring dirname in the
21115 `else' branch below isn't an issue. */
21117 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21119 copy
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
21123 start_subfile (filename
);
21129 /* Start a symtab for DWARF.
21130 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
21132 static struct compunit_symtab
*
21133 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
21134 const char *name
, const char *comp_dir
, CORE_ADDR low_pc
)
21136 struct compunit_symtab
*cust
21137 = start_symtab (cu
->per_cu
->dwarf2_per_objfile
->objfile
, name
, comp_dir
,
21138 low_pc
, cu
->language
);
21140 record_debugformat ("DWARF 2");
21141 record_producer (cu
->producer
);
21143 /* We assume that we're processing GCC output. */
21144 processing_gcc_compilation
= 2;
21146 cu
->processing_has_namespace_info
= 0;
21152 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21153 struct dwarf2_cu
*cu
)
21155 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21156 struct comp_unit_head
*cu_header
= &cu
->header
;
21158 /* NOTE drow/2003-01-30: There used to be a comment and some special
21159 code here to turn a symbol with DW_AT_external and a
21160 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21161 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21162 with some versions of binutils) where shared libraries could have
21163 relocations against symbols in their debug information - the
21164 minimal symbol would have the right address, but the debug info
21165 would not. It's no longer necessary, because we will explicitly
21166 apply relocations when we read in the debug information now. */
21168 /* A DW_AT_location attribute with no contents indicates that a
21169 variable has been optimized away. */
21170 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
21172 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21176 /* Handle one degenerate form of location expression specially, to
21177 preserve GDB's previous behavior when section offsets are
21178 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
21179 then mark this symbol as LOC_STATIC. */
21181 if (attr_form_is_block (attr
)
21182 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
21183 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
21184 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
21185 && (DW_BLOCK (attr
)->size
21186 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
21188 unsigned int dummy
;
21190 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
21191 SYMBOL_VALUE_ADDRESS (sym
) =
21192 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
21194 SYMBOL_VALUE_ADDRESS (sym
) =
21195 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
21196 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21197 fixup_symbol_section (sym
, objfile
);
21198 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
21199 SYMBOL_SECTION (sym
));
21203 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21204 expression evaluator, and use LOC_COMPUTED only when necessary
21205 (i.e. when the value of a register or memory location is
21206 referenced, or a thread-local block, etc.). Then again, it might
21207 not be worthwhile. I'm assuming that it isn't unless performance
21208 or memory numbers show me otherwise. */
21210 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21212 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21213 cu
->has_loclist
= 1;
21216 /* Given a pointer to a DWARF information entry, figure out if we need
21217 to make a symbol table entry for it, and if so, create a new entry
21218 and return a pointer to it.
21219 If TYPE is NULL, determine symbol type from the die, otherwise
21220 used the passed type.
21221 If SPACE is not NULL, use it to hold the new symbol. If it is
21222 NULL, allocate a new symbol on the objfile's obstack. */
21224 static struct symbol
*
21225 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21226 struct symbol
*space
)
21228 struct dwarf2_per_objfile
*dwarf2_per_objfile
21229 = cu
->per_cu
->dwarf2_per_objfile
;
21230 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21231 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21232 struct symbol
*sym
= NULL
;
21234 struct attribute
*attr
= NULL
;
21235 struct attribute
*attr2
= NULL
;
21236 CORE_ADDR baseaddr
;
21237 struct pending
**list_to_add
= NULL
;
21239 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21241 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
21243 name
= dwarf2_name (die
, cu
);
21246 const char *linkagename
;
21247 int suppress_add
= 0;
21252 sym
= allocate_symbol (objfile
);
21253 OBJSTAT (objfile
, n_syms
++);
21255 /* Cache this symbol's name and the name's demangled form (if any). */
21256 SYMBOL_SET_LANGUAGE (sym
, cu
->language
, &objfile
->objfile_obstack
);
21257 linkagename
= dwarf2_physname (name
, die
, cu
);
21258 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
21260 /* Fortran does not have mangling standard and the mangling does differ
21261 between gfortran, iFort etc. */
21262 if (cu
->language
== language_fortran
21263 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
21264 symbol_set_demangled_name (&(sym
->ginfo
),
21265 dwarf2_full_name (name
, die
, cu
),
21268 /* Default assumptions.
21269 Use the passed type or decode it from the die. */
21270 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21271 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21273 SYMBOL_TYPE (sym
) = type
;
21275 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21276 attr
= dwarf2_attr (die
,
21277 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21281 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
21284 attr
= dwarf2_attr (die
,
21285 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21289 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
21290 struct file_entry
*fe
;
21292 if (cu
->line_header
!= NULL
)
21293 fe
= cu
->line_header
->file_name_at (file_index
);
21298 complaint (&symfile_complaints
,
21299 _("file index out of range"));
21301 symbol_set_symtab (sym
, fe
->symtab
);
21307 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21312 addr
= attr_value_as_address (attr
);
21313 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21314 SYMBOL_VALUE_ADDRESS (sym
) = addr
;
21316 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21317 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21318 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21319 add_symbol_to_list (sym
, cu
->list_in_scope
);
21321 case DW_TAG_subprogram
:
21322 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21324 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21325 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21326 if ((attr2
&& (DW_UNSND (attr2
) != 0))
21327 || cu
->language
== language_ada
)
21329 /* Subprograms marked external are stored as a global symbol.
21330 Ada subprograms, whether marked external or not, are always
21331 stored as a global symbol, because we want to be able to
21332 access them globally. For instance, we want to be able
21333 to break on a nested subprogram without having to
21334 specify the context. */
21335 list_to_add
= &global_symbols
;
21339 list_to_add
= cu
->list_in_scope
;
21342 case DW_TAG_inlined_subroutine
:
21343 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21345 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21346 SYMBOL_INLINED (sym
) = 1;
21347 list_to_add
= cu
->list_in_scope
;
21349 case DW_TAG_template_value_param
:
21351 /* Fall through. */
21352 case DW_TAG_constant
:
21353 case DW_TAG_variable
:
21354 case DW_TAG_member
:
21355 /* Compilation with minimal debug info may result in
21356 variables with missing type entries. Change the
21357 misleading `void' type to something sensible. */
21358 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
21359 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21361 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21362 /* In the case of DW_TAG_member, we should only be called for
21363 static const members. */
21364 if (die
->tag
== DW_TAG_member
)
21366 /* dwarf2_add_field uses die_is_declaration,
21367 so we do the same. */
21368 gdb_assert (die_is_declaration (die
, cu
));
21373 dwarf2_const_value (attr
, sym
, cu
);
21374 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21377 if (attr2
&& (DW_UNSND (attr2
) != 0))
21378 list_to_add
= &global_symbols
;
21380 list_to_add
= cu
->list_in_scope
;
21384 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21387 var_decode_location (attr
, sym
, cu
);
21388 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21390 /* Fortran explicitly imports any global symbols to the local
21391 scope by DW_TAG_common_block. */
21392 if (cu
->language
== language_fortran
&& die
->parent
21393 && die
->parent
->tag
== DW_TAG_common_block
)
21396 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21397 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21398 && !dwarf2_per_objfile
->has_section_at_zero
)
21400 /* When a static variable is eliminated by the linker,
21401 the corresponding debug information is not stripped
21402 out, but the variable address is set to null;
21403 do not add such variables into symbol table. */
21405 else if (attr2
&& (DW_UNSND (attr2
) != 0))
21407 /* Workaround gfortran PR debug/40040 - it uses
21408 DW_AT_location for variables in -fPIC libraries which may
21409 get overriden by other libraries/executable and get
21410 a different address. Resolve it by the minimal symbol
21411 which may come from inferior's executable using copy
21412 relocation. Make this workaround only for gfortran as for
21413 other compilers GDB cannot guess the minimal symbol
21414 Fortran mangling kind. */
21415 if (cu
->language
== language_fortran
&& die
->parent
21416 && die
->parent
->tag
== DW_TAG_module
21418 && startswith (cu
->producer
, "GNU Fortran"))
21419 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21421 /* A variable with DW_AT_external is never static,
21422 but it may be block-scoped. */
21423 list_to_add
= (cu
->list_in_scope
== &file_symbols
21424 ? &global_symbols
: cu
->list_in_scope
);
21427 list_to_add
= cu
->list_in_scope
;
21431 /* We do not know the address of this symbol.
21432 If it is an external symbol and we have type information
21433 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21434 The address of the variable will then be determined from
21435 the minimal symbol table whenever the variable is
21437 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21439 /* Fortran explicitly imports any global symbols to the local
21440 scope by DW_TAG_common_block. */
21441 if (cu
->language
== language_fortran
&& die
->parent
21442 && die
->parent
->tag
== DW_TAG_common_block
)
21444 /* SYMBOL_CLASS doesn't matter here because
21445 read_common_block is going to reset it. */
21447 list_to_add
= cu
->list_in_scope
;
21449 else if (attr2
&& (DW_UNSND (attr2
) != 0)
21450 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21452 /* A variable with DW_AT_external is never static, but it
21453 may be block-scoped. */
21454 list_to_add
= (cu
->list_in_scope
== &file_symbols
21455 ? &global_symbols
: cu
->list_in_scope
);
21457 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21459 else if (!die_is_declaration (die
, cu
))
21461 /* Use the default LOC_OPTIMIZED_OUT class. */
21462 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21464 list_to_add
= cu
->list_in_scope
;
21468 case DW_TAG_formal_parameter
:
21469 /* If we are inside a function, mark this as an argument. If
21470 not, we might be looking at an argument to an inlined function
21471 when we do not have enough information to show inlined frames;
21472 pretend it's a local variable in that case so that the user can
21474 if (context_stack_depth
> 0
21475 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
21476 SYMBOL_IS_ARGUMENT (sym
) = 1;
21477 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21480 var_decode_location (attr
, sym
, cu
);
21482 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21485 dwarf2_const_value (attr
, sym
, cu
);
21488 list_to_add
= cu
->list_in_scope
;
21490 case DW_TAG_unspecified_parameters
:
21491 /* From varargs functions; gdb doesn't seem to have any
21492 interest in this information, so just ignore it for now.
21495 case DW_TAG_template_type_param
:
21497 /* Fall through. */
21498 case DW_TAG_class_type
:
21499 case DW_TAG_interface_type
:
21500 case DW_TAG_structure_type
:
21501 case DW_TAG_union_type
:
21502 case DW_TAG_set_type
:
21503 case DW_TAG_enumeration_type
:
21504 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21505 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21508 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21509 really ever be static objects: otherwise, if you try
21510 to, say, break of a class's method and you're in a file
21511 which doesn't mention that class, it won't work unless
21512 the check for all static symbols in lookup_symbol_aux
21513 saves you. See the OtherFileClass tests in
21514 gdb.c++/namespace.exp. */
21518 list_to_add
= (cu
->list_in_scope
== &file_symbols
21519 && cu
->language
== language_cplus
21520 ? &global_symbols
: cu
->list_in_scope
);
21522 /* The semantics of C++ state that "struct foo {
21523 ... }" also defines a typedef for "foo". */
21524 if (cu
->language
== language_cplus
21525 || cu
->language
== language_ada
21526 || cu
->language
== language_d
21527 || cu
->language
== language_rust
)
21529 /* The symbol's name is already allocated along
21530 with this objfile, so we don't need to
21531 duplicate it for the type. */
21532 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
21533 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
21538 case DW_TAG_typedef
:
21539 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21540 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21541 list_to_add
= cu
->list_in_scope
;
21543 case DW_TAG_base_type
:
21544 case DW_TAG_subrange_type
:
21545 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21546 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21547 list_to_add
= cu
->list_in_scope
;
21549 case DW_TAG_enumerator
:
21550 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21553 dwarf2_const_value (attr
, sym
, cu
);
21556 /* NOTE: carlton/2003-11-10: See comment above in the
21557 DW_TAG_class_type, etc. block. */
21559 list_to_add
= (cu
->list_in_scope
== &file_symbols
21560 && cu
->language
== language_cplus
21561 ? &global_symbols
: cu
->list_in_scope
);
21564 case DW_TAG_imported_declaration
:
21565 case DW_TAG_namespace
:
21566 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21567 list_to_add
= &global_symbols
;
21569 case DW_TAG_module
:
21570 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21571 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21572 list_to_add
= &global_symbols
;
21574 case DW_TAG_common_block
:
21575 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21576 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21577 add_symbol_to_list (sym
, cu
->list_in_scope
);
21580 /* Not a tag we recognize. Hopefully we aren't processing
21581 trash data, but since we must specifically ignore things
21582 we don't recognize, there is nothing else we should do at
21584 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
21585 dwarf_tag_name (die
->tag
));
21591 sym
->hash_next
= objfile
->template_symbols
;
21592 objfile
->template_symbols
= sym
;
21593 list_to_add
= NULL
;
21596 if (list_to_add
!= NULL
)
21597 add_symbol_to_list (sym
, list_to_add
);
21599 /* For the benefit of old versions of GCC, check for anonymous
21600 namespaces based on the demangled name. */
21601 if (!cu
->processing_has_namespace_info
21602 && cu
->language
== language_cplus
)
21603 cp_scan_for_anonymous_namespaces (sym
, objfile
);
21608 /* Given an attr with a DW_FORM_dataN value in host byte order,
21609 zero-extend it as appropriate for the symbol's type. The DWARF
21610 standard (v4) is not entirely clear about the meaning of using
21611 DW_FORM_dataN for a constant with a signed type, where the type is
21612 wider than the data. The conclusion of a discussion on the DWARF
21613 list was that this is unspecified. We choose to always zero-extend
21614 because that is the interpretation long in use by GCC. */
21617 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21618 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21620 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21621 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21622 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21623 LONGEST l
= DW_UNSND (attr
);
21625 if (bits
< sizeof (*value
) * 8)
21627 l
&= ((LONGEST
) 1 << bits
) - 1;
21630 else if (bits
== sizeof (*value
) * 8)
21634 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21635 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21642 /* Read a constant value from an attribute. Either set *VALUE, or if
21643 the value does not fit in *VALUE, set *BYTES - either already
21644 allocated on the objfile obstack, or newly allocated on OBSTACK,
21645 or, set *BATON, if we translated the constant to a location
21649 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21650 const char *name
, struct obstack
*obstack
,
21651 struct dwarf2_cu
*cu
,
21652 LONGEST
*value
, const gdb_byte
**bytes
,
21653 struct dwarf2_locexpr_baton
**baton
)
21655 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21656 struct comp_unit_head
*cu_header
= &cu
->header
;
21657 struct dwarf_block
*blk
;
21658 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21659 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21665 switch (attr
->form
)
21668 case DW_FORM_GNU_addr_index
:
21672 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21673 dwarf2_const_value_length_mismatch_complaint (name
,
21674 cu_header
->addr_size
,
21675 TYPE_LENGTH (type
));
21676 /* Symbols of this form are reasonably rare, so we just
21677 piggyback on the existing location code rather than writing
21678 a new implementation of symbol_computed_ops. */
21679 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21680 (*baton
)->per_cu
= cu
->per_cu
;
21681 gdb_assert ((*baton
)->per_cu
);
21683 (*baton
)->size
= 2 + cu_header
->addr_size
;
21684 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
21685 (*baton
)->data
= data
;
21687 data
[0] = DW_OP_addr
;
21688 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
21689 byte_order
, DW_ADDR (attr
));
21690 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
21693 case DW_FORM_string
:
21695 case DW_FORM_GNU_str_index
:
21696 case DW_FORM_GNU_strp_alt
:
21697 /* DW_STRING is already allocated on the objfile obstack, point
21699 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
21701 case DW_FORM_block1
:
21702 case DW_FORM_block2
:
21703 case DW_FORM_block4
:
21704 case DW_FORM_block
:
21705 case DW_FORM_exprloc
:
21706 case DW_FORM_data16
:
21707 blk
= DW_BLOCK (attr
);
21708 if (TYPE_LENGTH (type
) != blk
->size
)
21709 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
21710 TYPE_LENGTH (type
));
21711 *bytes
= blk
->data
;
21714 /* The DW_AT_const_value attributes are supposed to carry the
21715 symbol's value "represented as it would be on the target
21716 architecture." By the time we get here, it's already been
21717 converted to host endianness, so we just need to sign- or
21718 zero-extend it as appropriate. */
21719 case DW_FORM_data1
:
21720 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21722 case DW_FORM_data2
:
21723 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21725 case DW_FORM_data4
:
21726 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21728 case DW_FORM_data8
:
21729 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21732 case DW_FORM_sdata
:
21733 case DW_FORM_implicit_const
:
21734 *value
= DW_SND (attr
);
21737 case DW_FORM_udata
:
21738 *value
= DW_UNSND (attr
);
21742 complaint (&symfile_complaints
,
21743 _("unsupported const value attribute form: '%s'"),
21744 dwarf_form_name (attr
->form
));
21751 /* Copy constant value from an attribute to a symbol. */
21754 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21755 struct dwarf2_cu
*cu
)
21757 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21759 const gdb_byte
*bytes
;
21760 struct dwarf2_locexpr_baton
*baton
;
21762 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21763 SYMBOL_PRINT_NAME (sym
),
21764 &objfile
->objfile_obstack
, cu
,
21765 &value
, &bytes
, &baton
);
21769 SYMBOL_LOCATION_BATON (sym
) = baton
;
21770 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21772 else if (bytes
!= NULL
)
21774 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21775 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21779 SYMBOL_VALUE (sym
) = value
;
21780 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21784 /* Return the type of the die in question using its DW_AT_type attribute. */
21786 static struct type
*
21787 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21789 struct attribute
*type_attr
;
21791 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21794 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21795 /* A missing DW_AT_type represents a void type. */
21796 return objfile_type (objfile
)->builtin_void
;
21799 return lookup_die_type (die
, type_attr
, cu
);
21802 /* True iff CU's producer generates GNAT Ada auxiliary information
21803 that allows to find parallel types through that information instead
21804 of having to do expensive parallel lookups by type name. */
21807 need_gnat_info (struct dwarf2_cu
*cu
)
21809 /* Assume that the Ada compiler was GNAT, which always produces
21810 the auxiliary information. */
21811 return (cu
->language
== language_ada
);
21814 /* Return the auxiliary type of the die in question using its
21815 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21816 attribute is not present. */
21818 static struct type
*
21819 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21821 struct attribute
*type_attr
;
21823 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21827 return lookup_die_type (die
, type_attr
, cu
);
21830 /* If DIE has a descriptive_type attribute, then set the TYPE's
21831 descriptive type accordingly. */
21834 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21835 struct dwarf2_cu
*cu
)
21837 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21839 if (descriptive_type
)
21841 ALLOCATE_GNAT_AUX_TYPE (type
);
21842 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21846 /* Return the containing type of the die in question using its
21847 DW_AT_containing_type attribute. */
21849 static struct type
*
21850 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21852 struct attribute
*type_attr
;
21853 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21855 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21857 error (_("Dwarf Error: Problem turning containing type into gdb type "
21858 "[in module %s]"), objfile_name (objfile
));
21860 return lookup_die_type (die
, type_attr
, cu
);
21863 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21865 static struct type
*
21866 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21868 struct dwarf2_per_objfile
*dwarf2_per_objfile
21869 = cu
->per_cu
->dwarf2_per_objfile
;
21870 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21871 char *message
, *saved
;
21873 message
= xstrprintf (_("<unknown type in %s, CU %s, DIE %s>"),
21874 objfile_name (objfile
),
21875 sect_offset_str (cu
->header
.sect_off
),
21876 sect_offset_str (die
->sect_off
));
21877 saved
= (char *) obstack_copy0 (&objfile
->objfile_obstack
,
21878 message
, strlen (message
));
21881 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21884 /* Look up the type of DIE in CU using its type attribute ATTR.
21885 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21886 DW_AT_containing_type.
21887 If there is no type substitute an error marker. */
21889 static struct type
*
21890 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21891 struct dwarf2_cu
*cu
)
21893 struct dwarf2_per_objfile
*dwarf2_per_objfile
21894 = cu
->per_cu
->dwarf2_per_objfile
;
21895 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21896 struct type
*this_type
;
21898 gdb_assert (attr
->name
== DW_AT_type
21899 || attr
->name
== DW_AT_GNAT_descriptive_type
21900 || attr
->name
== DW_AT_containing_type
);
21902 /* First see if we have it cached. */
21904 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21906 struct dwarf2_per_cu_data
*per_cu
;
21907 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21909 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
21910 dwarf2_per_objfile
);
21911 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
21913 else if (attr_form_is_ref (attr
))
21915 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21917 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
21919 else if (attr
->form
== DW_FORM_ref_sig8
)
21921 ULONGEST signature
= DW_SIGNATURE (attr
);
21923 return get_signatured_type (die
, signature
, cu
);
21927 complaint (&symfile_complaints
,
21928 _("Dwarf Error: Bad type attribute %s in DIE"
21929 " at %s [in module %s]"),
21930 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
21931 objfile_name (objfile
));
21932 return build_error_marker_type (cu
, die
);
21935 /* If not cached we need to read it in. */
21937 if (this_type
== NULL
)
21939 struct die_info
*type_die
= NULL
;
21940 struct dwarf2_cu
*type_cu
= cu
;
21942 if (attr_form_is_ref (attr
))
21943 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21944 if (type_die
== NULL
)
21945 return build_error_marker_type (cu
, die
);
21946 /* If we find the type now, it's probably because the type came
21947 from an inter-CU reference and the type's CU got expanded before
21949 this_type
= read_type_die (type_die
, type_cu
);
21952 /* If we still don't have a type use an error marker. */
21954 if (this_type
== NULL
)
21955 return build_error_marker_type (cu
, die
);
21960 /* Return the type in DIE, CU.
21961 Returns NULL for invalid types.
21963 This first does a lookup in die_type_hash,
21964 and only reads the die in if necessary.
21966 NOTE: This can be called when reading in partial or full symbols. */
21968 static struct type
*
21969 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21971 struct type
*this_type
;
21973 this_type
= get_die_type (die
, cu
);
21977 return read_type_die_1 (die
, cu
);
21980 /* Read the type in DIE, CU.
21981 Returns NULL for invalid types. */
21983 static struct type
*
21984 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
21986 struct type
*this_type
= NULL
;
21990 case DW_TAG_class_type
:
21991 case DW_TAG_interface_type
:
21992 case DW_TAG_structure_type
:
21993 case DW_TAG_union_type
:
21994 this_type
= read_structure_type (die
, cu
);
21996 case DW_TAG_enumeration_type
:
21997 this_type
= read_enumeration_type (die
, cu
);
21999 case DW_TAG_subprogram
:
22000 case DW_TAG_subroutine_type
:
22001 case DW_TAG_inlined_subroutine
:
22002 this_type
= read_subroutine_type (die
, cu
);
22004 case DW_TAG_array_type
:
22005 this_type
= read_array_type (die
, cu
);
22007 case DW_TAG_set_type
:
22008 this_type
= read_set_type (die
, cu
);
22010 case DW_TAG_pointer_type
:
22011 this_type
= read_tag_pointer_type (die
, cu
);
22013 case DW_TAG_ptr_to_member_type
:
22014 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22016 case DW_TAG_reference_type
:
22017 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22019 case DW_TAG_rvalue_reference_type
:
22020 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22022 case DW_TAG_const_type
:
22023 this_type
= read_tag_const_type (die
, cu
);
22025 case DW_TAG_volatile_type
:
22026 this_type
= read_tag_volatile_type (die
, cu
);
22028 case DW_TAG_restrict_type
:
22029 this_type
= read_tag_restrict_type (die
, cu
);
22031 case DW_TAG_string_type
:
22032 this_type
= read_tag_string_type (die
, cu
);
22034 case DW_TAG_typedef
:
22035 this_type
= read_typedef (die
, cu
);
22037 case DW_TAG_subrange_type
:
22038 this_type
= read_subrange_type (die
, cu
);
22040 case DW_TAG_base_type
:
22041 this_type
= read_base_type (die
, cu
);
22043 case DW_TAG_unspecified_type
:
22044 this_type
= read_unspecified_type (die
, cu
);
22046 case DW_TAG_namespace
:
22047 this_type
= read_namespace_type (die
, cu
);
22049 case DW_TAG_module
:
22050 this_type
= read_module_type (die
, cu
);
22052 case DW_TAG_atomic_type
:
22053 this_type
= read_tag_atomic_type (die
, cu
);
22056 complaint (&symfile_complaints
,
22057 _("unexpected tag in read_type_die: '%s'"),
22058 dwarf_tag_name (die
->tag
));
22065 /* See if we can figure out if the class lives in a namespace. We do
22066 this by looking for a member function; its demangled name will
22067 contain namespace info, if there is any.
22068 Return the computed name or NULL.
22069 Space for the result is allocated on the objfile's obstack.
22070 This is the full-die version of guess_partial_die_structure_name.
22071 In this case we know DIE has no useful parent. */
22074 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22076 struct die_info
*spec_die
;
22077 struct dwarf2_cu
*spec_cu
;
22078 struct die_info
*child
;
22079 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22082 spec_die
= die_specification (die
, &spec_cu
);
22083 if (spec_die
!= NULL
)
22089 for (child
= die
->child
;
22091 child
= child
->sibling
)
22093 if (child
->tag
== DW_TAG_subprogram
)
22095 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22097 if (linkage_name
!= NULL
)
22100 = language_class_name_from_physname (cu
->language_defn
,
22104 if (actual_name
!= NULL
)
22106 const char *die_name
= dwarf2_name (die
, cu
);
22108 if (die_name
!= NULL
22109 && strcmp (die_name
, actual_name
) != 0)
22111 /* Strip off the class name from the full name.
22112 We want the prefix. */
22113 int die_name_len
= strlen (die_name
);
22114 int actual_name_len
= strlen (actual_name
);
22116 /* Test for '::' as a sanity check. */
22117 if (actual_name_len
> die_name_len
+ 2
22118 && actual_name
[actual_name_len
22119 - die_name_len
- 1] == ':')
22120 name
= (char *) obstack_copy0 (
22121 &objfile
->per_bfd
->storage_obstack
,
22122 actual_name
, actual_name_len
- die_name_len
- 2);
22125 xfree (actual_name
);
22134 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22135 prefix part in such case. See
22136 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22138 static const char *
22139 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22141 struct attribute
*attr
;
22144 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22145 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22148 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22151 attr
= dw2_linkage_name_attr (die
, cu
);
22152 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22155 /* dwarf2_name had to be already called. */
22156 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
22158 /* Strip the base name, keep any leading namespaces/classes. */
22159 base
= strrchr (DW_STRING (attr
), ':');
22160 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
22163 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22164 return (char *) obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
22166 &base
[-1] - DW_STRING (attr
));
22169 /* Return the name of the namespace/class that DIE is defined within,
22170 or "" if we can't tell. The caller should not xfree the result.
22172 For example, if we're within the method foo() in the following
22182 then determine_prefix on foo's die will return "N::C". */
22184 static const char *
22185 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22187 struct dwarf2_per_objfile
*dwarf2_per_objfile
22188 = cu
->per_cu
->dwarf2_per_objfile
;
22189 struct die_info
*parent
, *spec_die
;
22190 struct dwarf2_cu
*spec_cu
;
22191 struct type
*parent_type
;
22192 const char *retval
;
22194 if (cu
->language
!= language_cplus
22195 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22196 && cu
->language
!= language_rust
)
22199 retval
= anonymous_struct_prefix (die
, cu
);
22203 /* We have to be careful in the presence of DW_AT_specification.
22204 For example, with GCC 3.4, given the code
22208 // Definition of N::foo.
22212 then we'll have a tree of DIEs like this:
22214 1: DW_TAG_compile_unit
22215 2: DW_TAG_namespace // N
22216 3: DW_TAG_subprogram // declaration of N::foo
22217 4: DW_TAG_subprogram // definition of N::foo
22218 DW_AT_specification // refers to die #3
22220 Thus, when processing die #4, we have to pretend that we're in
22221 the context of its DW_AT_specification, namely the contex of die
22224 spec_die
= die_specification (die
, &spec_cu
);
22225 if (spec_die
== NULL
)
22226 parent
= die
->parent
;
22229 parent
= spec_die
->parent
;
22233 if (parent
== NULL
)
22235 else if (parent
->building_fullname
)
22238 const char *parent_name
;
22240 /* It has been seen on RealView 2.2 built binaries,
22241 DW_TAG_template_type_param types actually _defined_ as
22242 children of the parent class:
22245 template class <class Enum> Class{};
22246 Class<enum E> class_e;
22248 1: DW_TAG_class_type (Class)
22249 2: DW_TAG_enumeration_type (E)
22250 3: DW_TAG_enumerator (enum1:0)
22251 3: DW_TAG_enumerator (enum2:1)
22253 2: DW_TAG_template_type_param
22254 DW_AT_type DW_FORM_ref_udata (E)
22256 Besides being broken debug info, it can put GDB into an
22257 infinite loop. Consider:
22259 When we're building the full name for Class<E>, we'll start
22260 at Class, and go look over its template type parameters,
22261 finding E. We'll then try to build the full name of E, and
22262 reach here. We're now trying to build the full name of E,
22263 and look over the parent DIE for containing scope. In the
22264 broken case, if we followed the parent DIE of E, we'd again
22265 find Class, and once again go look at its template type
22266 arguments, etc., etc. Simply don't consider such parent die
22267 as source-level parent of this die (it can't be, the language
22268 doesn't allow it), and break the loop here. */
22269 name
= dwarf2_name (die
, cu
);
22270 parent_name
= dwarf2_name (parent
, cu
);
22271 complaint (&symfile_complaints
,
22272 _("template param type '%s' defined within parent '%s'"),
22273 name
? name
: "<unknown>",
22274 parent_name
? parent_name
: "<unknown>");
22278 switch (parent
->tag
)
22280 case DW_TAG_namespace
:
22281 parent_type
= read_type_die (parent
, cu
);
22282 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22283 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22284 Work around this problem here. */
22285 if (cu
->language
== language_cplus
22286 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
22288 /* We give a name to even anonymous namespaces. */
22289 return TYPE_TAG_NAME (parent_type
);
22290 case DW_TAG_class_type
:
22291 case DW_TAG_interface_type
:
22292 case DW_TAG_structure_type
:
22293 case DW_TAG_union_type
:
22294 case DW_TAG_module
:
22295 parent_type
= read_type_die (parent
, cu
);
22296 if (TYPE_TAG_NAME (parent_type
) != NULL
)
22297 return TYPE_TAG_NAME (parent_type
);
22299 /* An anonymous structure is only allowed non-static data
22300 members; no typedefs, no member functions, et cetera.
22301 So it does not need a prefix. */
22303 case DW_TAG_compile_unit
:
22304 case DW_TAG_partial_unit
:
22305 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22306 if (cu
->language
== language_cplus
22307 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
22308 && die
->child
!= NULL
22309 && (die
->tag
== DW_TAG_class_type
22310 || die
->tag
== DW_TAG_structure_type
22311 || die
->tag
== DW_TAG_union_type
))
22313 char *name
= guess_full_die_structure_name (die
, cu
);
22318 case DW_TAG_enumeration_type
:
22319 parent_type
= read_type_die (parent
, cu
);
22320 if (TYPE_DECLARED_CLASS (parent_type
))
22322 if (TYPE_TAG_NAME (parent_type
) != NULL
)
22323 return TYPE_TAG_NAME (parent_type
);
22326 /* Fall through. */
22328 return determine_prefix (parent
, cu
);
22332 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22333 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22334 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22335 an obconcat, otherwise allocate storage for the result. The CU argument is
22336 used to determine the language and hence, the appropriate separator. */
22338 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22341 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22342 int physname
, struct dwarf2_cu
*cu
)
22344 const char *lead
= "";
22347 if (suffix
== NULL
|| suffix
[0] == '\0'
22348 || prefix
== NULL
|| prefix
[0] == '\0')
22350 else if (cu
->language
== language_d
)
22352 /* For D, the 'main' function could be defined in any module, but it
22353 should never be prefixed. */
22354 if (strcmp (suffix
, "D main") == 0)
22362 else if (cu
->language
== language_fortran
&& physname
)
22364 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22365 DW_AT_MIPS_linkage_name is preferred and used instead. */
22373 if (prefix
== NULL
)
22375 if (suffix
== NULL
)
22382 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22384 strcpy (retval
, lead
);
22385 strcat (retval
, prefix
);
22386 strcat (retval
, sep
);
22387 strcat (retval
, suffix
);
22392 /* We have an obstack. */
22393 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22397 /* Return sibling of die, NULL if no sibling. */
22399 static struct die_info
*
22400 sibling_die (struct die_info
*die
)
22402 return die
->sibling
;
22405 /* Get name of a die, return NULL if not found. */
22407 static const char *
22408 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22409 struct obstack
*obstack
)
22411 if (name
&& cu
->language
== language_cplus
)
22413 std::string canon_name
= cp_canonicalize_string (name
);
22415 if (!canon_name
.empty ())
22417 if (canon_name
!= name
)
22418 name
= (const char *) obstack_copy0 (obstack
,
22419 canon_name
.c_str (),
22420 canon_name
.length ());
22427 /* Get name of a die, return NULL if not found.
22428 Anonymous namespaces are converted to their magic string. */
22430 static const char *
22431 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22433 struct attribute
*attr
;
22434 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22436 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22437 if ((!attr
|| !DW_STRING (attr
))
22438 && die
->tag
!= DW_TAG_namespace
22439 && die
->tag
!= DW_TAG_class_type
22440 && die
->tag
!= DW_TAG_interface_type
22441 && die
->tag
!= DW_TAG_structure_type
22442 && die
->tag
!= DW_TAG_union_type
)
22447 case DW_TAG_compile_unit
:
22448 case DW_TAG_partial_unit
:
22449 /* Compilation units have a DW_AT_name that is a filename, not
22450 a source language identifier. */
22451 case DW_TAG_enumeration_type
:
22452 case DW_TAG_enumerator
:
22453 /* These tags always have simple identifiers already; no need
22454 to canonicalize them. */
22455 return DW_STRING (attr
);
22457 case DW_TAG_namespace
:
22458 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
22459 return DW_STRING (attr
);
22460 return CP_ANONYMOUS_NAMESPACE_STR
;
22462 case DW_TAG_class_type
:
22463 case DW_TAG_interface_type
:
22464 case DW_TAG_structure_type
:
22465 case DW_TAG_union_type
:
22466 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22467 structures or unions. These were of the form "._%d" in GCC 4.1,
22468 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22469 and GCC 4.4. We work around this problem by ignoring these. */
22470 if (attr
&& DW_STRING (attr
)
22471 && (startswith (DW_STRING (attr
), "._")
22472 || startswith (DW_STRING (attr
), "<anonymous")))
22475 /* GCC might emit a nameless typedef that has a linkage name. See
22476 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22477 if (!attr
|| DW_STRING (attr
) == NULL
)
22479 char *demangled
= NULL
;
22481 attr
= dw2_linkage_name_attr (die
, cu
);
22482 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22485 /* Avoid demangling DW_STRING (attr) the second time on a second
22486 call for the same DIE. */
22487 if (!DW_STRING_IS_CANONICAL (attr
))
22488 demangled
= gdb_demangle (DW_STRING (attr
), DMGL_TYPES
);
22494 /* FIXME: we already did this for the partial symbol... */
22497 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
22498 demangled
, strlen (demangled
)));
22499 DW_STRING_IS_CANONICAL (attr
) = 1;
22502 /* Strip any leading namespaces/classes, keep only the base name.
22503 DW_AT_name for named DIEs does not contain the prefixes. */
22504 base
= strrchr (DW_STRING (attr
), ':');
22505 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
22508 return DW_STRING (attr
);
22517 if (!DW_STRING_IS_CANONICAL (attr
))
22520 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
22521 &objfile
->per_bfd
->storage_obstack
);
22522 DW_STRING_IS_CANONICAL (attr
) = 1;
22524 return DW_STRING (attr
);
22527 /* Return the die that this die in an extension of, or NULL if there
22528 is none. *EXT_CU is the CU containing DIE on input, and the CU
22529 containing the return value on output. */
22531 static struct die_info
*
22532 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22534 struct attribute
*attr
;
22536 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22540 return follow_die_ref (die
, attr
, ext_cu
);
22543 /* Convert a DIE tag into its string name. */
22545 static const char *
22546 dwarf_tag_name (unsigned tag
)
22548 const char *name
= get_DW_TAG_name (tag
);
22551 return "DW_TAG_<unknown>";
22556 /* Convert a DWARF attribute code into its string name. */
22558 static const char *
22559 dwarf_attr_name (unsigned attr
)
22563 #ifdef MIPS /* collides with DW_AT_HP_block_index */
22564 if (attr
== DW_AT_MIPS_fde
)
22565 return "DW_AT_MIPS_fde";
22567 if (attr
== DW_AT_HP_block_index
)
22568 return "DW_AT_HP_block_index";
22571 name
= get_DW_AT_name (attr
);
22574 return "DW_AT_<unknown>";
22579 /* Convert a DWARF value form code into its string name. */
22581 static const char *
22582 dwarf_form_name (unsigned form
)
22584 const char *name
= get_DW_FORM_name (form
);
22587 return "DW_FORM_<unknown>";
22592 static const char *
22593 dwarf_bool_name (unsigned mybool
)
22601 /* Convert a DWARF type code into its string name. */
22603 static const char *
22604 dwarf_type_encoding_name (unsigned enc
)
22606 const char *name
= get_DW_ATE_name (enc
);
22609 return "DW_ATE_<unknown>";
22615 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22619 print_spaces (indent
, f
);
22620 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
22621 dwarf_tag_name (die
->tag
), die
->abbrev
,
22622 sect_offset_str (die
->sect_off
));
22624 if (die
->parent
!= NULL
)
22626 print_spaces (indent
, f
);
22627 fprintf_unfiltered (f
, " parent at offset: %s\n",
22628 sect_offset_str (die
->parent
->sect_off
));
22631 print_spaces (indent
, f
);
22632 fprintf_unfiltered (f
, " has children: %s\n",
22633 dwarf_bool_name (die
->child
!= NULL
));
22635 print_spaces (indent
, f
);
22636 fprintf_unfiltered (f
, " attributes:\n");
22638 for (i
= 0; i
< die
->num_attrs
; ++i
)
22640 print_spaces (indent
, f
);
22641 fprintf_unfiltered (f
, " %s (%s) ",
22642 dwarf_attr_name (die
->attrs
[i
].name
),
22643 dwarf_form_name (die
->attrs
[i
].form
));
22645 switch (die
->attrs
[i
].form
)
22648 case DW_FORM_GNU_addr_index
:
22649 fprintf_unfiltered (f
, "address: ");
22650 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
22652 case DW_FORM_block2
:
22653 case DW_FORM_block4
:
22654 case DW_FORM_block
:
22655 case DW_FORM_block1
:
22656 fprintf_unfiltered (f
, "block: size %s",
22657 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22659 case DW_FORM_exprloc
:
22660 fprintf_unfiltered (f
, "expression: size %s",
22661 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22663 case DW_FORM_data16
:
22664 fprintf_unfiltered (f
, "constant of 16 bytes");
22666 case DW_FORM_ref_addr
:
22667 fprintf_unfiltered (f
, "ref address: ");
22668 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22670 case DW_FORM_GNU_ref_alt
:
22671 fprintf_unfiltered (f
, "alt ref address: ");
22672 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22678 case DW_FORM_ref_udata
:
22679 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
22680 (long) (DW_UNSND (&die
->attrs
[i
])));
22682 case DW_FORM_data1
:
22683 case DW_FORM_data2
:
22684 case DW_FORM_data4
:
22685 case DW_FORM_data8
:
22686 case DW_FORM_udata
:
22687 case DW_FORM_sdata
:
22688 fprintf_unfiltered (f
, "constant: %s",
22689 pulongest (DW_UNSND (&die
->attrs
[i
])));
22691 case DW_FORM_sec_offset
:
22692 fprintf_unfiltered (f
, "section offset: %s",
22693 pulongest (DW_UNSND (&die
->attrs
[i
])));
22695 case DW_FORM_ref_sig8
:
22696 fprintf_unfiltered (f
, "signature: %s",
22697 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
22699 case DW_FORM_string
:
22701 case DW_FORM_line_strp
:
22702 case DW_FORM_GNU_str_index
:
22703 case DW_FORM_GNU_strp_alt
:
22704 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22705 DW_STRING (&die
->attrs
[i
])
22706 ? DW_STRING (&die
->attrs
[i
]) : "",
22707 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
22710 if (DW_UNSND (&die
->attrs
[i
]))
22711 fprintf_unfiltered (f
, "flag: TRUE");
22713 fprintf_unfiltered (f
, "flag: FALSE");
22715 case DW_FORM_flag_present
:
22716 fprintf_unfiltered (f
, "flag: TRUE");
22718 case DW_FORM_indirect
:
22719 /* The reader will have reduced the indirect form to
22720 the "base form" so this form should not occur. */
22721 fprintf_unfiltered (f
,
22722 "unexpected attribute form: DW_FORM_indirect");
22724 case DW_FORM_implicit_const
:
22725 fprintf_unfiltered (f
, "constant: %s",
22726 plongest (DW_SND (&die
->attrs
[i
])));
22729 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22730 die
->attrs
[i
].form
);
22733 fprintf_unfiltered (f
, "\n");
22738 dump_die_for_error (struct die_info
*die
)
22740 dump_die_shallow (gdb_stderr
, 0, die
);
22744 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22746 int indent
= level
* 4;
22748 gdb_assert (die
!= NULL
);
22750 if (level
>= max_level
)
22753 dump_die_shallow (f
, indent
, die
);
22755 if (die
->child
!= NULL
)
22757 print_spaces (indent
, f
);
22758 fprintf_unfiltered (f
, " Children:");
22759 if (level
+ 1 < max_level
)
22761 fprintf_unfiltered (f
, "\n");
22762 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22766 fprintf_unfiltered (f
,
22767 " [not printed, max nesting level reached]\n");
22771 if (die
->sibling
!= NULL
&& level
> 0)
22773 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22777 /* This is called from the pdie macro in gdbinit.in.
22778 It's not static so gcc will keep a copy callable from gdb. */
22781 dump_die (struct die_info
*die
, int max_level
)
22783 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22787 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22791 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22792 to_underlying (die
->sect_off
),
22798 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
22802 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
22804 if (attr_form_is_ref (attr
))
22805 return (sect_offset
) DW_UNSND (attr
);
22807 complaint (&symfile_complaints
,
22808 _("unsupported die ref attribute form: '%s'"),
22809 dwarf_form_name (attr
->form
));
22813 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
22814 * the value held by the attribute is not constant. */
22817 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
22819 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
22820 return DW_SND (attr
);
22821 else if (attr
->form
== DW_FORM_udata
22822 || attr
->form
== DW_FORM_data1
22823 || attr
->form
== DW_FORM_data2
22824 || attr
->form
== DW_FORM_data4
22825 || attr
->form
== DW_FORM_data8
)
22826 return DW_UNSND (attr
);
22829 /* For DW_FORM_data16 see attr_form_is_constant. */
22830 complaint (&symfile_complaints
,
22831 _("Attribute value is not a constant (%s)"),
22832 dwarf_form_name (attr
->form
));
22833 return default_value
;
22837 /* Follow reference or signature attribute ATTR of SRC_DIE.
22838 On entry *REF_CU is the CU of SRC_DIE.
22839 On exit *REF_CU is the CU of the result. */
22841 static struct die_info
*
22842 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22843 struct dwarf2_cu
**ref_cu
)
22845 struct die_info
*die
;
22847 if (attr_form_is_ref (attr
))
22848 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22849 else if (attr
->form
== DW_FORM_ref_sig8
)
22850 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22853 dump_die_for_error (src_die
);
22854 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22855 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22861 /* Follow reference OFFSET.
22862 On entry *REF_CU is the CU of the source die referencing OFFSET.
22863 On exit *REF_CU is the CU of the result.
22864 Returns NULL if OFFSET is invalid. */
22866 static struct die_info
*
22867 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22868 struct dwarf2_cu
**ref_cu
)
22870 struct die_info temp_die
;
22871 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22872 struct dwarf2_per_objfile
*dwarf2_per_objfile
22873 = cu
->per_cu
->dwarf2_per_objfile
;
22875 gdb_assert (cu
->per_cu
!= NULL
);
22879 if (cu
->per_cu
->is_debug_types
)
22881 /* .debug_types CUs cannot reference anything outside their CU.
22882 If they need to, they have to reference a signatured type via
22883 DW_FORM_ref_sig8. */
22884 if (!offset_in_cu_p (&cu
->header
, sect_off
))
22887 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22888 || !offset_in_cu_p (&cu
->header
, sect_off
))
22890 struct dwarf2_per_cu_data
*per_cu
;
22892 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22893 dwarf2_per_objfile
);
22895 /* If necessary, add it to the queue and load its DIEs. */
22896 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
22897 load_full_comp_unit (per_cu
, false, cu
->language
);
22899 target_cu
= per_cu
->cu
;
22901 else if (cu
->dies
== NULL
)
22903 /* We're loading full DIEs during partial symbol reading. */
22904 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
22905 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
22908 *ref_cu
= target_cu
;
22909 temp_die
.sect_off
= sect_off
;
22910 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22912 to_underlying (sect_off
));
22915 /* Follow reference attribute ATTR of SRC_DIE.
22916 On entry *REF_CU is the CU of SRC_DIE.
22917 On exit *REF_CU is the CU of the result. */
22919 static struct die_info
*
22920 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22921 struct dwarf2_cu
**ref_cu
)
22923 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22924 struct dwarf2_cu
*cu
= *ref_cu
;
22925 struct die_info
*die
;
22927 die
= follow_die_offset (sect_off
,
22928 (attr
->form
== DW_FORM_GNU_ref_alt
22929 || cu
->per_cu
->is_dwz
),
22932 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22933 "at %s [in module %s]"),
22934 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22935 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
22940 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
22941 Returned value is intended for DW_OP_call*. Returned
22942 dwarf2_locexpr_baton->data has lifetime of
22943 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
22945 struct dwarf2_locexpr_baton
22946 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22947 struct dwarf2_per_cu_data
*per_cu
,
22948 CORE_ADDR (*get_frame_pc
) (void *baton
),
22951 struct dwarf2_cu
*cu
;
22952 struct die_info
*die
;
22953 struct attribute
*attr
;
22954 struct dwarf2_locexpr_baton retval
;
22955 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
22956 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22958 if (per_cu
->cu
== NULL
)
22959 load_cu (per_cu
, false);
22963 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22964 Instead just throw an error, not much else we can do. */
22965 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22966 sect_offset_str (sect_off
), objfile_name (objfile
));
22969 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22971 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22972 sect_offset_str (sect_off
), objfile_name (objfile
));
22974 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22977 /* DWARF: "If there is no such attribute, then there is no effect.".
22978 DATA is ignored if SIZE is 0. */
22980 retval
.data
= NULL
;
22983 else if (attr_form_is_section_offset (attr
))
22985 struct dwarf2_loclist_baton loclist_baton
;
22986 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22989 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
22991 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
22993 retval
.size
= size
;
22997 if (!attr_form_is_block (attr
))
22998 error (_("Dwarf Error: DIE at %s referenced in module %s "
22999 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23000 sect_offset_str (sect_off
), objfile_name (objfile
));
23002 retval
.data
= DW_BLOCK (attr
)->data
;
23003 retval
.size
= DW_BLOCK (attr
)->size
;
23005 retval
.per_cu
= cu
->per_cu
;
23007 age_cached_comp_units (dwarf2_per_objfile
);
23012 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
23015 struct dwarf2_locexpr_baton
23016 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23017 struct dwarf2_per_cu_data
*per_cu
,
23018 CORE_ADDR (*get_frame_pc
) (void *baton
),
23021 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23023 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
23026 /* Write a constant of a given type as target-ordered bytes into
23029 static const gdb_byte
*
23030 write_constant_as_bytes (struct obstack
*obstack
,
23031 enum bfd_endian byte_order
,
23038 *len
= TYPE_LENGTH (type
);
23039 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23040 store_unsigned_integer (result
, *len
, byte_order
, value
);
23045 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
23046 pointer to the constant bytes and set LEN to the length of the
23047 data. If memory is needed, allocate it on OBSTACK. If the DIE
23048 does not have a DW_AT_const_value, return NULL. */
23051 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23052 struct dwarf2_per_cu_data
*per_cu
,
23053 struct obstack
*obstack
,
23056 struct dwarf2_cu
*cu
;
23057 struct die_info
*die
;
23058 struct attribute
*attr
;
23059 const gdb_byte
*result
= NULL
;
23062 enum bfd_endian byte_order
;
23063 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
23065 if (per_cu
->cu
== NULL
)
23066 load_cu (per_cu
, false);
23070 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23071 Instead just throw an error, not much else we can do. */
23072 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23073 sect_offset_str (sect_off
), objfile_name (objfile
));
23076 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23078 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23079 sect_offset_str (sect_off
), objfile_name (objfile
));
23081 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23085 byte_order
= (bfd_big_endian (objfile
->obfd
)
23086 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23088 switch (attr
->form
)
23091 case DW_FORM_GNU_addr_index
:
23095 *len
= cu
->header
.addr_size
;
23096 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23097 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
23101 case DW_FORM_string
:
23103 case DW_FORM_GNU_str_index
:
23104 case DW_FORM_GNU_strp_alt
:
23105 /* DW_STRING is already allocated on the objfile obstack, point
23107 result
= (const gdb_byte
*) DW_STRING (attr
);
23108 *len
= strlen (DW_STRING (attr
));
23110 case DW_FORM_block1
:
23111 case DW_FORM_block2
:
23112 case DW_FORM_block4
:
23113 case DW_FORM_block
:
23114 case DW_FORM_exprloc
:
23115 case DW_FORM_data16
:
23116 result
= DW_BLOCK (attr
)->data
;
23117 *len
= DW_BLOCK (attr
)->size
;
23120 /* The DW_AT_const_value attributes are supposed to carry the
23121 symbol's value "represented as it would be on the target
23122 architecture." By the time we get here, it's already been
23123 converted to host endianness, so we just need to sign- or
23124 zero-extend it as appropriate. */
23125 case DW_FORM_data1
:
23126 type
= die_type (die
, cu
);
23127 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23128 if (result
== NULL
)
23129 result
= write_constant_as_bytes (obstack
, byte_order
,
23132 case DW_FORM_data2
:
23133 type
= die_type (die
, cu
);
23134 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23135 if (result
== NULL
)
23136 result
= write_constant_as_bytes (obstack
, byte_order
,
23139 case DW_FORM_data4
:
23140 type
= die_type (die
, cu
);
23141 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23142 if (result
== NULL
)
23143 result
= write_constant_as_bytes (obstack
, byte_order
,
23146 case DW_FORM_data8
:
23147 type
= die_type (die
, cu
);
23148 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23149 if (result
== NULL
)
23150 result
= write_constant_as_bytes (obstack
, byte_order
,
23154 case DW_FORM_sdata
:
23155 case DW_FORM_implicit_const
:
23156 type
= die_type (die
, cu
);
23157 result
= write_constant_as_bytes (obstack
, byte_order
,
23158 type
, DW_SND (attr
), len
);
23161 case DW_FORM_udata
:
23162 type
= die_type (die
, cu
);
23163 result
= write_constant_as_bytes (obstack
, byte_order
,
23164 type
, DW_UNSND (attr
), len
);
23168 complaint (&symfile_complaints
,
23169 _("unsupported const value attribute form: '%s'"),
23170 dwarf_form_name (attr
->form
));
23177 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
23178 valid type for this die is found. */
23181 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23182 struct dwarf2_per_cu_data
*per_cu
)
23184 struct dwarf2_cu
*cu
;
23185 struct die_info
*die
;
23187 if (per_cu
->cu
== NULL
)
23188 load_cu (per_cu
, false);
23193 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23197 return die_type (die
, cu
);
23200 /* Return the type of the DIE at DIE_OFFSET in the CU named by
23204 dwarf2_get_die_type (cu_offset die_offset
,
23205 struct dwarf2_per_cu_data
*per_cu
)
23207 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23208 return get_die_type_at_offset (die_offset_sect
, per_cu
);
23211 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23212 On entry *REF_CU is the CU of SRC_DIE.
23213 On exit *REF_CU is the CU of the result.
23214 Returns NULL if the referenced DIE isn't found. */
23216 static struct die_info
*
23217 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23218 struct dwarf2_cu
**ref_cu
)
23220 struct die_info temp_die
;
23221 struct dwarf2_cu
*sig_cu
;
23222 struct die_info
*die
;
23224 /* While it might be nice to assert sig_type->type == NULL here,
23225 we can get here for DW_AT_imported_declaration where we need
23226 the DIE not the type. */
23228 /* If necessary, add it to the queue and load its DIEs. */
23230 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
23231 read_signatured_type (sig_type
);
23233 sig_cu
= sig_type
->per_cu
.cu
;
23234 gdb_assert (sig_cu
!= NULL
);
23235 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23236 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23237 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23238 to_underlying (temp_die
.sect_off
));
23241 struct dwarf2_per_objfile
*dwarf2_per_objfile
23242 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
23244 /* For .gdb_index version 7 keep track of included TUs.
23245 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23246 if (dwarf2_per_objfile
->index_table
!= NULL
23247 && dwarf2_per_objfile
->index_table
->version
<= 7)
23249 VEC_safe_push (dwarf2_per_cu_ptr
,
23250 (*ref_cu
)->per_cu
->imported_symtabs
,
23261 /* Follow signatured type referenced by ATTR in SRC_DIE.
23262 On entry *REF_CU is the CU of SRC_DIE.
23263 On exit *REF_CU is the CU of the result.
23264 The result is the DIE of the type.
23265 If the referenced type cannot be found an error is thrown. */
23267 static struct die_info
*
23268 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23269 struct dwarf2_cu
**ref_cu
)
23271 ULONGEST signature
= DW_SIGNATURE (attr
);
23272 struct signatured_type
*sig_type
;
23273 struct die_info
*die
;
23275 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23277 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23278 /* sig_type will be NULL if the signatured type is missing from
23280 if (sig_type
== NULL
)
23282 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23283 " from DIE at %s [in module %s]"),
23284 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23285 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23288 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23291 dump_die_for_error (src_die
);
23292 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23293 " from DIE at %s [in module %s]"),
23294 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23295 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23301 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23302 reading in and processing the type unit if necessary. */
23304 static struct type
*
23305 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23306 struct dwarf2_cu
*cu
)
23308 struct dwarf2_per_objfile
*dwarf2_per_objfile
23309 = cu
->per_cu
->dwarf2_per_objfile
;
23310 struct signatured_type
*sig_type
;
23311 struct dwarf2_cu
*type_cu
;
23312 struct die_info
*type_die
;
23315 sig_type
= lookup_signatured_type (cu
, signature
);
23316 /* sig_type will be NULL if the signatured type is missing from
23318 if (sig_type
== NULL
)
23320 complaint (&symfile_complaints
,
23321 _("Dwarf Error: Cannot find signatured DIE %s referenced"
23322 " from DIE at %s [in module %s]"),
23323 hex_string (signature
), sect_offset_str (die
->sect_off
),
23324 objfile_name (dwarf2_per_objfile
->objfile
));
23325 return build_error_marker_type (cu
, die
);
23328 /* If we already know the type we're done. */
23329 if (sig_type
->type
!= NULL
)
23330 return sig_type
->type
;
23333 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23334 if (type_die
!= NULL
)
23336 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23337 is created. This is important, for example, because for c++ classes
23338 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23339 type
= read_type_die (type_die
, type_cu
);
23342 complaint (&symfile_complaints
,
23343 _("Dwarf Error: Cannot build signatured type %s"
23344 " referenced from DIE at %s [in module %s]"),
23345 hex_string (signature
), sect_offset_str (die
->sect_off
),
23346 objfile_name (dwarf2_per_objfile
->objfile
));
23347 type
= build_error_marker_type (cu
, die
);
23352 complaint (&symfile_complaints
,
23353 _("Dwarf Error: Problem reading signatured DIE %s referenced"
23354 " from DIE at %s [in module %s]"),
23355 hex_string (signature
), sect_offset_str (die
->sect_off
),
23356 objfile_name (dwarf2_per_objfile
->objfile
));
23357 type
= build_error_marker_type (cu
, die
);
23359 sig_type
->type
= type
;
23364 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23365 reading in and processing the type unit if necessary. */
23367 static struct type
*
23368 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23369 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23371 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23372 if (attr_form_is_ref (attr
))
23374 struct dwarf2_cu
*type_cu
= cu
;
23375 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23377 return read_type_die (type_die
, type_cu
);
23379 else if (attr
->form
== DW_FORM_ref_sig8
)
23381 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
23385 struct dwarf2_per_objfile
*dwarf2_per_objfile
23386 = cu
->per_cu
->dwarf2_per_objfile
;
23388 complaint (&symfile_complaints
,
23389 _("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23390 " at %s [in module %s]"),
23391 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
23392 objfile_name (dwarf2_per_objfile
->objfile
));
23393 return build_error_marker_type (cu
, die
);
23397 /* Load the DIEs associated with type unit PER_CU into memory. */
23400 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
23402 struct signatured_type
*sig_type
;
23404 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23405 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
23407 /* We have the per_cu, but we need the signatured_type.
23408 Fortunately this is an easy translation. */
23409 gdb_assert (per_cu
->is_debug_types
);
23410 sig_type
= (struct signatured_type
*) per_cu
;
23412 gdb_assert (per_cu
->cu
== NULL
);
23414 read_signatured_type (sig_type
);
23416 gdb_assert (per_cu
->cu
!= NULL
);
23419 /* die_reader_func for read_signatured_type.
23420 This is identical to load_full_comp_unit_reader,
23421 but is kept separate for now. */
23424 read_signatured_type_reader (const struct die_reader_specs
*reader
,
23425 const gdb_byte
*info_ptr
,
23426 struct die_info
*comp_unit_die
,
23430 struct dwarf2_cu
*cu
= reader
->cu
;
23432 gdb_assert (cu
->die_hash
== NULL
);
23434 htab_create_alloc_ex (cu
->header
.length
/ 12,
23438 &cu
->comp_unit_obstack
,
23439 hashtab_obstack_allocate
,
23440 dummy_obstack_deallocate
);
23443 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
23444 &info_ptr
, comp_unit_die
);
23445 cu
->dies
= comp_unit_die
;
23446 /* comp_unit_die is not stored in die_hash, no need. */
23448 /* We try not to read any attributes in this function, because not
23449 all CUs needed for references have been loaded yet, and symbol
23450 table processing isn't initialized. But we have to set the CU language,
23451 or we won't be able to build types correctly.
23452 Similarly, if we do not read the producer, we can not apply
23453 producer-specific interpretation. */
23454 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23457 /* Read in a signatured type and build its CU and DIEs.
23458 If the type is a stub for the real type in a DWO file,
23459 read in the real type from the DWO file as well. */
23462 read_signatured_type (struct signatured_type
*sig_type
)
23464 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
23466 gdb_assert (per_cu
->is_debug_types
);
23467 gdb_assert (per_cu
->cu
== NULL
);
23469 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1, false,
23470 read_signatured_type_reader
, NULL
);
23471 sig_type
->per_cu
.tu_read
= 1;
23474 /* Decode simple location descriptions.
23475 Given a pointer to a dwarf block that defines a location, compute
23476 the location and return the value.
23478 NOTE drow/2003-11-18: This function is called in two situations
23479 now: for the address of static or global variables (partial symbols
23480 only) and for offsets into structures which are expected to be
23481 (more or less) constant. The partial symbol case should go away,
23482 and only the constant case should remain. That will let this
23483 function complain more accurately. A few special modes are allowed
23484 without complaint for global variables (for instance, global
23485 register values and thread-local values).
23487 A location description containing no operations indicates that the
23488 object is optimized out. The return value is 0 for that case.
23489 FIXME drow/2003-11-16: No callers check for this case any more; soon all
23490 callers will only want a very basic result and this can become a
23493 Note that stack[0] is unused except as a default error return. */
23496 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
23498 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
23500 size_t size
= blk
->size
;
23501 const gdb_byte
*data
= blk
->data
;
23502 CORE_ADDR stack
[64];
23504 unsigned int bytes_read
, unsnd
;
23510 stack
[++stacki
] = 0;
23549 stack
[++stacki
] = op
- DW_OP_lit0
;
23584 stack
[++stacki
] = op
- DW_OP_reg0
;
23586 dwarf2_complex_location_expr_complaint ();
23590 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
23592 stack
[++stacki
] = unsnd
;
23594 dwarf2_complex_location_expr_complaint ();
23598 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
23603 case DW_OP_const1u
:
23604 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
23608 case DW_OP_const1s
:
23609 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
23613 case DW_OP_const2u
:
23614 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
23618 case DW_OP_const2s
:
23619 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
23623 case DW_OP_const4u
:
23624 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
23628 case DW_OP_const4s
:
23629 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
23633 case DW_OP_const8u
:
23634 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
23639 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
23645 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
23650 stack
[stacki
+ 1] = stack
[stacki
];
23655 stack
[stacki
- 1] += stack
[stacki
];
23659 case DW_OP_plus_uconst
:
23660 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
23666 stack
[stacki
- 1] -= stack
[stacki
];
23671 /* If we're not the last op, then we definitely can't encode
23672 this using GDB's address_class enum. This is valid for partial
23673 global symbols, although the variable's address will be bogus
23676 dwarf2_complex_location_expr_complaint ();
23679 case DW_OP_GNU_push_tls_address
:
23680 case DW_OP_form_tls_address
:
23681 /* The top of the stack has the offset from the beginning
23682 of the thread control block at which the variable is located. */
23683 /* Nothing should follow this operator, so the top of stack would
23685 /* This is valid for partial global symbols, but the variable's
23686 address will be bogus in the psymtab. Make it always at least
23687 non-zero to not look as a variable garbage collected by linker
23688 which have DW_OP_addr 0. */
23690 dwarf2_complex_location_expr_complaint ();
23694 case DW_OP_GNU_uninit
:
23697 case DW_OP_GNU_addr_index
:
23698 case DW_OP_GNU_const_index
:
23699 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23706 const char *name
= get_DW_OP_name (op
);
23709 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
23712 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
23716 return (stack
[stacki
]);
23719 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23720 outside of the allocated space. Also enforce minimum>0. */
23721 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23723 complaint (&symfile_complaints
,
23724 _("location description stack overflow"));
23730 complaint (&symfile_complaints
,
23731 _("location description stack underflow"));
23735 return (stack
[stacki
]);
23738 /* memory allocation interface */
23740 static struct dwarf_block
*
23741 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23743 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23746 static struct die_info
*
23747 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23749 struct die_info
*die
;
23750 size_t size
= sizeof (struct die_info
);
23753 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23755 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23756 memset (die
, 0, sizeof (struct die_info
));
23761 /* Macro support. */
23763 /* Return file name relative to the compilation directory of file number I in
23764 *LH's file name table. The result is allocated using xmalloc; the caller is
23765 responsible for freeing it. */
23768 file_file_name (int file
, struct line_header
*lh
)
23770 /* Is the file number a valid index into the line header's file name
23771 table? Remember that file numbers start with one, not zero. */
23772 if (1 <= file
&& file
<= lh
->file_names
.size ())
23774 const file_entry
&fe
= lh
->file_names
[file
- 1];
23776 if (!IS_ABSOLUTE_PATH (fe
.name
))
23778 const char *dir
= fe
.include_dir (lh
);
23780 return concat (dir
, SLASH_STRING
, fe
.name
, (char *) NULL
);
23782 return xstrdup (fe
.name
);
23786 /* The compiler produced a bogus file number. We can at least
23787 record the macro definitions made in the file, even if we
23788 won't be able to find the file by name. */
23789 char fake_name
[80];
23791 xsnprintf (fake_name
, sizeof (fake_name
),
23792 "<bad macro file number %d>", file
);
23794 complaint (&symfile_complaints
,
23795 _("bad file number in macro information (%d)"),
23798 return xstrdup (fake_name
);
23802 /* Return the full name of file number I in *LH's file name table.
23803 Use COMP_DIR as the name of the current directory of the
23804 compilation. The result is allocated using xmalloc; the caller is
23805 responsible for freeing it. */
23807 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
23809 /* Is the file number a valid index into the line header's file name
23810 table? Remember that file numbers start with one, not zero. */
23811 if (1 <= file
&& file
<= lh
->file_names
.size ())
23813 char *relative
= file_file_name (file
, lh
);
23815 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
23817 return reconcat (relative
, comp_dir
, SLASH_STRING
,
23818 relative
, (char *) NULL
);
23821 return file_file_name (file
, lh
);
23825 static struct macro_source_file
*
23826 macro_start_file (int file
, int line
,
23827 struct macro_source_file
*current_file
,
23828 struct line_header
*lh
)
23830 /* File name relative to the compilation directory of this source file. */
23831 char *file_name
= file_file_name (file
, lh
);
23833 if (! current_file
)
23835 /* Note: We don't create a macro table for this compilation unit
23836 at all until we actually get a filename. */
23837 struct macro_table
*macro_table
= get_macro_table ();
23839 /* If we have no current file, then this must be the start_file
23840 directive for the compilation unit's main source file. */
23841 current_file
= macro_set_main (macro_table
, file_name
);
23842 macro_define_special (macro_table
);
23845 current_file
= macro_include (current_file
, line
, file_name
);
23849 return current_file
;
23852 static const char *
23853 consume_improper_spaces (const char *p
, const char *body
)
23857 complaint (&symfile_complaints
,
23858 _("macro definition contains spaces "
23859 "in formal argument list:\n`%s'"),
23871 parse_macro_definition (struct macro_source_file
*file
, int line
,
23876 /* The body string takes one of two forms. For object-like macro
23877 definitions, it should be:
23879 <macro name> " " <definition>
23881 For function-like macro definitions, it should be:
23883 <macro name> "() " <definition>
23885 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
23887 Spaces may appear only where explicitly indicated, and in the
23890 The Dwarf 2 spec says that an object-like macro's name is always
23891 followed by a space, but versions of GCC around March 2002 omit
23892 the space when the macro's definition is the empty string.
23894 The Dwarf 2 spec says that there should be no spaces between the
23895 formal arguments in a function-like macro's formal argument list,
23896 but versions of GCC around March 2002 include spaces after the
23900 /* Find the extent of the macro name. The macro name is terminated
23901 by either a space or null character (for an object-like macro) or
23902 an opening paren (for a function-like macro). */
23903 for (p
= body
; *p
; p
++)
23904 if (*p
== ' ' || *p
== '(')
23907 if (*p
== ' ' || *p
== '\0')
23909 /* It's an object-like macro. */
23910 int name_len
= p
- body
;
23911 char *name
= savestring (body
, name_len
);
23912 const char *replacement
;
23915 replacement
= body
+ name_len
+ 1;
23918 dwarf2_macro_malformed_definition_complaint (body
);
23919 replacement
= body
+ name_len
;
23922 macro_define_object (file
, line
, name
, replacement
);
23926 else if (*p
== '(')
23928 /* It's a function-like macro. */
23929 char *name
= savestring (body
, p
- body
);
23932 char **argv
= XNEWVEC (char *, argv_size
);
23936 p
= consume_improper_spaces (p
, body
);
23938 /* Parse the formal argument list. */
23939 while (*p
&& *p
!= ')')
23941 /* Find the extent of the current argument name. */
23942 const char *arg_start
= p
;
23944 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
23947 if (! *p
|| p
== arg_start
)
23948 dwarf2_macro_malformed_definition_complaint (body
);
23951 /* Make sure argv has room for the new argument. */
23952 if (argc
>= argv_size
)
23955 argv
= XRESIZEVEC (char *, argv
, argv_size
);
23958 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
23961 p
= consume_improper_spaces (p
, body
);
23963 /* Consume the comma, if present. */
23968 p
= consume_improper_spaces (p
, body
);
23977 /* Perfectly formed definition, no complaints. */
23978 macro_define_function (file
, line
, name
,
23979 argc
, (const char **) argv
,
23981 else if (*p
== '\0')
23983 /* Complain, but do define it. */
23984 dwarf2_macro_malformed_definition_complaint (body
);
23985 macro_define_function (file
, line
, name
,
23986 argc
, (const char **) argv
,
23990 /* Just complain. */
23991 dwarf2_macro_malformed_definition_complaint (body
);
23994 /* Just complain. */
23995 dwarf2_macro_malformed_definition_complaint (body
);
24001 for (i
= 0; i
< argc
; i
++)
24007 dwarf2_macro_malformed_definition_complaint (body
);
24010 /* Skip some bytes from BYTES according to the form given in FORM.
24011 Returns the new pointer. */
24013 static const gdb_byte
*
24014 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
24015 enum dwarf_form form
,
24016 unsigned int offset_size
,
24017 struct dwarf2_section_info
*section
)
24019 unsigned int bytes_read
;
24023 case DW_FORM_data1
:
24028 case DW_FORM_data2
:
24032 case DW_FORM_data4
:
24036 case DW_FORM_data8
:
24040 case DW_FORM_data16
:
24044 case DW_FORM_string
:
24045 read_direct_string (abfd
, bytes
, &bytes_read
);
24046 bytes
+= bytes_read
;
24049 case DW_FORM_sec_offset
:
24051 case DW_FORM_GNU_strp_alt
:
24052 bytes
+= offset_size
;
24055 case DW_FORM_block
:
24056 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
24057 bytes
+= bytes_read
;
24060 case DW_FORM_block1
:
24061 bytes
+= 1 + read_1_byte (abfd
, bytes
);
24063 case DW_FORM_block2
:
24064 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
24066 case DW_FORM_block4
:
24067 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
24070 case DW_FORM_sdata
:
24071 case DW_FORM_udata
:
24072 case DW_FORM_GNU_addr_index
:
24073 case DW_FORM_GNU_str_index
:
24074 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
24077 dwarf2_section_buffer_overflow_complaint (section
);
24082 case DW_FORM_implicit_const
:
24087 complaint (&symfile_complaints
,
24088 _("invalid form 0x%x in `%s'"),
24089 form
, get_section_name (section
));
24097 /* A helper for dwarf_decode_macros that handles skipping an unknown
24098 opcode. Returns an updated pointer to the macro data buffer; or,
24099 on error, issues a complaint and returns NULL. */
24101 static const gdb_byte
*
24102 skip_unknown_opcode (unsigned int opcode
,
24103 const gdb_byte
**opcode_definitions
,
24104 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24106 unsigned int offset_size
,
24107 struct dwarf2_section_info
*section
)
24109 unsigned int bytes_read
, i
;
24111 const gdb_byte
*defn
;
24113 if (opcode_definitions
[opcode
] == NULL
)
24115 complaint (&symfile_complaints
,
24116 _("unrecognized DW_MACFINO opcode 0x%x"),
24121 defn
= opcode_definitions
[opcode
];
24122 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
24123 defn
+= bytes_read
;
24125 for (i
= 0; i
< arg
; ++i
)
24127 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
24128 (enum dwarf_form
) defn
[i
], offset_size
,
24130 if (mac_ptr
== NULL
)
24132 /* skip_form_bytes already issued the complaint. */
24140 /* A helper function which parses the header of a macro section.
24141 If the macro section is the extended (for now called "GNU") type,
24142 then this updates *OFFSET_SIZE. Returns a pointer to just after
24143 the header, or issues a complaint and returns NULL on error. */
24145 static const gdb_byte
*
24146 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
24148 const gdb_byte
*mac_ptr
,
24149 unsigned int *offset_size
,
24150 int section_is_gnu
)
24152 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
24154 if (section_is_gnu
)
24156 unsigned int version
, flags
;
24158 version
= read_2_bytes (abfd
, mac_ptr
);
24159 if (version
!= 4 && version
!= 5)
24161 complaint (&symfile_complaints
,
24162 _("unrecognized version `%d' in .debug_macro section"),
24168 flags
= read_1_byte (abfd
, mac_ptr
);
24170 *offset_size
= (flags
& 1) ? 8 : 4;
24172 if ((flags
& 2) != 0)
24173 /* We don't need the line table offset. */
24174 mac_ptr
+= *offset_size
;
24176 /* Vendor opcode descriptions. */
24177 if ((flags
& 4) != 0)
24179 unsigned int i
, count
;
24181 count
= read_1_byte (abfd
, mac_ptr
);
24183 for (i
= 0; i
< count
; ++i
)
24185 unsigned int opcode
, bytes_read
;
24188 opcode
= read_1_byte (abfd
, mac_ptr
);
24190 opcode_definitions
[opcode
] = mac_ptr
;
24191 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24192 mac_ptr
+= bytes_read
;
24201 /* A helper for dwarf_decode_macros that handles the GNU extensions,
24202 including DW_MACRO_import. */
24205 dwarf_decode_macro_bytes (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
24207 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24208 struct macro_source_file
*current_file
,
24209 struct line_header
*lh
,
24210 struct dwarf2_section_info
*section
,
24211 int section_is_gnu
, int section_is_dwz
,
24212 unsigned int offset_size
,
24213 htab_t include_hash
)
24215 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24216 enum dwarf_macro_record_type macinfo_type
;
24217 int at_commandline
;
24218 const gdb_byte
*opcode_definitions
[256];
24220 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24221 &offset_size
, section_is_gnu
);
24222 if (mac_ptr
== NULL
)
24224 /* We already issued a complaint. */
24228 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
24229 GDB is still reading the definitions from command line. First
24230 DW_MACINFO_start_file will need to be ignored as it was already executed
24231 to create CURRENT_FILE for the main source holding also the command line
24232 definitions. On first met DW_MACINFO_start_file this flag is reset to
24233 normally execute all the remaining DW_MACINFO_start_file macinfos. */
24235 at_commandline
= 1;
24239 /* Do we at least have room for a macinfo type byte? */
24240 if (mac_ptr
>= mac_end
)
24242 dwarf2_section_buffer_overflow_complaint (section
);
24246 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24249 /* Note that we rely on the fact that the corresponding GNU and
24250 DWARF constants are the same. */
24252 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24253 switch (macinfo_type
)
24255 /* A zero macinfo type indicates the end of the macro
24260 case DW_MACRO_define
:
24261 case DW_MACRO_undef
:
24262 case DW_MACRO_define_strp
:
24263 case DW_MACRO_undef_strp
:
24264 case DW_MACRO_define_sup
:
24265 case DW_MACRO_undef_sup
:
24267 unsigned int bytes_read
;
24272 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24273 mac_ptr
+= bytes_read
;
24275 if (macinfo_type
== DW_MACRO_define
24276 || macinfo_type
== DW_MACRO_undef
)
24278 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24279 mac_ptr
+= bytes_read
;
24283 LONGEST str_offset
;
24285 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24286 mac_ptr
+= offset_size
;
24288 if (macinfo_type
== DW_MACRO_define_sup
24289 || macinfo_type
== DW_MACRO_undef_sup
24292 struct dwz_file
*dwz
24293 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
24295 body
= read_indirect_string_from_dwz (objfile
,
24299 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
24303 is_define
= (macinfo_type
== DW_MACRO_define
24304 || macinfo_type
== DW_MACRO_define_strp
24305 || macinfo_type
== DW_MACRO_define_sup
);
24306 if (! current_file
)
24308 /* DWARF violation as no main source is present. */
24309 complaint (&symfile_complaints
,
24310 _("debug info with no main source gives macro %s "
24312 is_define
? _("definition") : _("undefinition"),
24316 if ((line
== 0 && !at_commandline
)
24317 || (line
!= 0 && at_commandline
))
24318 complaint (&symfile_complaints
,
24319 _("debug info gives %s macro %s with %s line %d: %s"),
24320 at_commandline
? _("command-line") : _("in-file"),
24321 is_define
? _("definition") : _("undefinition"),
24322 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
24325 parse_macro_definition (current_file
, line
, body
);
24328 gdb_assert (macinfo_type
== DW_MACRO_undef
24329 || macinfo_type
== DW_MACRO_undef_strp
24330 || macinfo_type
== DW_MACRO_undef_sup
);
24331 macro_undef (current_file
, line
, body
);
24336 case DW_MACRO_start_file
:
24338 unsigned int bytes_read
;
24341 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24342 mac_ptr
+= bytes_read
;
24343 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24344 mac_ptr
+= bytes_read
;
24346 if ((line
== 0 && !at_commandline
)
24347 || (line
!= 0 && at_commandline
))
24348 complaint (&symfile_complaints
,
24349 _("debug info gives source %d included "
24350 "from %s at %s line %d"),
24351 file
, at_commandline
? _("command-line") : _("file"),
24352 line
== 0 ? _("zero") : _("non-zero"), line
);
24354 if (at_commandline
)
24356 /* This DW_MACRO_start_file was executed in the
24358 at_commandline
= 0;
24361 current_file
= macro_start_file (file
, line
, current_file
, lh
);
24365 case DW_MACRO_end_file
:
24366 if (! current_file
)
24367 complaint (&symfile_complaints
,
24368 _("macro debug info has an unmatched "
24369 "`close_file' directive"));
24372 current_file
= current_file
->included_by
;
24373 if (! current_file
)
24375 enum dwarf_macro_record_type next_type
;
24377 /* GCC circa March 2002 doesn't produce the zero
24378 type byte marking the end of the compilation
24379 unit. Complain if it's not there, but exit no
24382 /* Do we at least have room for a macinfo type byte? */
24383 if (mac_ptr
>= mac_end
)
24385 dwarf2_section_buffer_overflow_complaint (section
);
24389 /* We don't increment mac_ptr here, so this is just
24392 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
24394 if (next_type
!= 0)
24395 complaint (&symfile_complaints
,
24396 _("no terminating 0-type entry for "
24397 "macros in `.debug_macinfo' section"));
24404 case DW_MACRO_import
:
24405 case DW_MACRO_import_sup
:
24409 bfd
*include_bfd
= abfd
;
24410 struct dwarf2_section_info
*include_section
= section
;
24411 const gdb_byte
*include_mac_end
= mac_end
;
24412 int is_dwz
= section_is_dwz
;
24413 const gdb_byte
*new_mac_ptr
;
24415 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24416 mac_ptr
+= offset_size
;
24418 if (macinfo_type
== DW_MACRO_import_sup
)
24420 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
24422 dwarf2_read_section (objfile
, &dwz
->macro
);
24424 include_section
= &dwz
->macro
;
24425 include_bfd
= get_section_bfd_owner (include_section
);
24426 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
24430 new_mac_ptr
= include_section
->buffer
+ offset
;
24431 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
24435 /* This has actually happened; see
24436 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
24437 complaint (&symfile_complaints
,
24438 _("recursive DW_MACRO_import in "
24439 ".debug_macro section"));
24443 *slot
= (void *) new_mac_ptr
;
24445 dwarf_decode_macro_bytes (dwarf2_per_objfile
,
24446 include_bfd
, new_mac_ptr
,
24447 include_mac_end
, current_file
, lh
,
24448 section
, section_is_gnu
, is_dwz
,
24449 offset_size
, include_hash
);
24451 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
24456 case DW_MACINFO_vendor_ext
:
24457 if (!section_is_gnu
)
24459 unsigned int bytes_read
;
24461 /* This reads the constant, but since we don't recognize
24462 any vendor extensions, we ignore it. */
24463 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24464 mac_ptr
+= bytes_read
;
24465 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24466 mac_ptr
+= bytes_read
;
24468 /* We don't recognize any vendor extensions. */
24474 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
24475 mac_ptr
, mac_end
, abfd
, offset_size
,
24477 if (mac_ptr
== NULL
)
24482 } while (macinfo_type
!= 0);
24486 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24487 int section_is_gnu
)
24489 struct dwarf2_per_objfile
*dwarf2_per_objfile
24490 = cu
->per_cu
->dwarf2_per_objfile
;
24491 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24492 struct line_header
*lh
= cu
->line_header
;
24494 const gdb_byte
*mac_ptr
, *mac_end
;
24495 struct macro_source_file
*current_file
= 0;
24496 enum dwarf_macro_record_type macinfo_type
;
24497 unsigned int offset_size
= cu
->header
.offset_size
;
24498 const gdb_byte
*opcode_definitions
[256];
24500 struct dwarf2_section_info
*section
;
24501 const char *section_name
;
24503 if (cu
->dwo_unit
!= NULL
)
24505 if (section_is_gnu
)
24507 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24508 section_name
= ".debug_macro.dwo";
24512 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24513 section_name
= ".debug_macinfo.dwo";
24518 if (section_is_gnu
)
24520 section
= &dwarf2_per_objfile
->macro
;
24521 section_name
= ".debug_macro";
24525 section
= &dwarf2_per_objfile
->macinfo
;
24526 section_name
= ".debug_macinfo";
24530 dwarf2_read_section (objfile
, section
);
24531 if (section
->buffer
== NULL
)
24533 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
24536 abfd
= get_section_bfd_owner (section
);
24538 /* First pass: Find the name of the base filename.
24539 This filename is needed in order to process all macros whose definition
24540 (or undefinition) comes from the command line. These macros are defined
24541 before the first DW_MACINFO_start_file entry, and yet still need to be
24542 associated to the base file.
24544 To determine the base file name, we scan the macro definitions until we
24545 reach the first DW_MACINFO_start_file entry. We then initialize
24546 CURRENT_FILE accordingly so that any macro definition found before the
24547 first DW_MACINFO_start_file can still be associated to the base file. */
24549 mac_ptr
= section
->buffer
+ offset
;
24550 mac_end
= section
->buffer
+ section
->size
;
24552 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24553 &offset_size
, section_is_gnu
);
24554 if (mac_ptr
== NULL
)
24556 /* We already issued a complaint. */
24562 /* Do we at least have room for a macinfo type byte? */
24563 if (mac_ptr
>= mac_end
)
24565 /* Complaint is printed during the second pass as GDB will probably
24566 stop the first pass earlier upon finding
24567 DW_MACINFO_start_file. */
24571 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24574 /* Note that we rely on the fact that the corresponding GNU and
24575 DWARF constants are the same. */
24577 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24578 switch (macinfo_type
)
24580 /* A zero macinfo type indicates the end of the macro
24585 case DW_MACRO_define
:
24586 case DW_MACRO_undef
:
24587 /* Only skip the data by MAC_PTR. */
24589 unsigned int bytes_read
;
24591 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24592 mac_ptr
+= bytes_read
;
24593 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24594 mac_ptr
+= bytes_read
;
24598 case DW_MACRO_start_file
:
24600 unsigned int bytes_read
;
24603 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24604 mac_ptr
+= bytes_read
;
24605 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24606 mac_ptr
+= bytes_read
;
24608 current_file
= macro_start_file (file
, line
, current_file
, lh
);
24612 case DW_MACRO_end_file
:
24613 /* No data to skip by MAC_PTR. */
24616 case DW_MACRO_define_strp
:
24617 case DW_MACRO_undef_strp
:
24618 case DW_MACRO_define_sup
:
24619 case DW_MACRO_undef_sup
:
24621 unsigned int bytes_read
;
24623 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24624 mac_ptr
+= bytes_read
;
24625 mac_ptr
+= offset_size
;
24629 case DW_MACRO_import
:
24630 case DW_MACRO_import_sup
:
24631 /* Note that, according to the spec, a transparent include
24632 chain cannot call DW_MACRO_start_file. So, we can just
24633 skip this opcode. */
24634 mac_ptr
+= offset_size
;
24637 case DW_MACINFO_vendor_ext
:
24638 /* Only skip the data by MAC_PTR. */
24639 if (!section_is_gnu
)
24641 unsigned int bytes_read
;
24643 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24644 mac_ptr
+= bytes_read
;
24645 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24646 mac_ptr
+= bytes_read
;
24651 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
24652 mac_ptr
, mac_end
, abfd
, offset_size
,
24654 if (mac_ptr
== NULL
)
24659 } while (macinfo_type
!= 0 && current_file
== NULL
);
24661 /* Second pass: Process all entries.
24663 Use the AT_COMMAND_LINE flag to determine whether we are still processing
24664 command-line macro definitions/undefinitions. This flag is unset when we
24665 reach the first DW_MACINFO_start_file entry. */
24667 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
24669 NULL
, xcalloc
, xfree
));
24670 mac_ptr
= section
->buffer
+ offset
;
24671 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
24672 *slot
= (void *) mac_ptr
;
24673 dwarf_decode_macro_bytes (dwarf2_per_objfile
,
24674 abfd
, mac_ptr
, mac_end
,
24675 current_file
, lh
, section
,
24676 section_is_gnu
, 0, offset_size
,
24677 include_hash
.get ());
24680 /* Check if the attribute's form is a DW_FORM_block*
24681 if so return true else false. */
24684 attr_form_is_block (const struct attribute
*attr
)
24686 return (attr
== NULL
? 0 :
24687 attr
->form
== DW_FORM_block1
24688 || attr
->form
== DW_FORM_block2
24689 || attr
->form
== DW_FORM_block4
24690 || attr
->form
== DW_FORM_block
24691 || attr
->form
== DW_FORM_exprloc
);
24694 /* Return non-zero if ATTR's value is a section offset --- classes
24695 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
24696 You may use DW_UNSND (attr) to retrieve such offsets.
24698 Section 7.5.4, "Attribute Encodings", explains that no attribute
24699 may have a value that belongs to more than one of these classes; it
24700 would be ambiguous if we did, because we use the same forms for all
24704 attr_form_is_section_offset (const struct attribute
*attr
)
24706 return (attr
->form
== DW_FORM_data4
24707 || attr
->form
== DW_FORM_data8
24708 || attr
->form
== DW_FORM_sec_offset
);
24711 /* Return non-zero if ATTR's value falls in the 'constant' class, or
24712 zero otherwise. When this function returns true, you can apply
24713 dwarf2_get_attr_constant_value to it.
24715 However, note that for some attributes you must check
24716 attr_form_is_section_offset before using this test. DW_FORM_data4
24717 and DW_FORM_data8 are members of both the constant class, and of
24718 the classes that contain offsets into other debug sections
24719 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
24720 that, if an attribute's can be either a constant or one of the
24721 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
24722 taken as section offsets, not constants.
24724 DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
24725 cannot handle that. */
24728 attr_form_is_constant (const struct attribute
*attr
)
24730 switch (attr
->form
)
24732 case DW_FORM_sdata
:
24733 case DW_FORM_udata
:
24734 case DW_FORM_data1
:
24735 case DW_FORM_data2
:
24736 case DW_FORM_data4
:
24737 case DW_FORM_data8
:
24738 case DW_FORM_implicit_const
:
24746 /* DW_ADDR is always stored already as sect_offset; despite for the forms
24747 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
24750 attr_form_is_ref (const struct attribute
*attr
)
24752 switch (attr
->form
)
24754 case DW_FORM_ref_addr
:
24759 case DW_FORM_ref_udata
:
24760 case DW_FORM_GNU_ref_alt
:
24767 /* Return the .debug_loc section to use for CU.
24768 For DWO files use .debug_loc.dwo. */
24770 static struct dwarf2_section_info
*
24771 cu_debug_loc_section (struct dwarf2_cu
*cu
)
24773 struct dwarf2_per_objfile
*dwarf2_per_objfile
24774 = cu
->per_cu
->dwarf2_per_objfile
;
24778 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24780 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
24782 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
24783 : &dwarf2_per_objfile
->loc
);
24786 /* A helper function that fills in a dwarf2_loclist_baton. */
24789 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
24790 struct dwarf2_loclist_baton
*baton
,
24791 const struct attribute
*attr
)
24793 struct dwarf2_per_objfile
*dwarf2_per_objfile
24794 = cu
->per_cu
->dwarf2_per_objfile
;
24795 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24797 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
24799 baton
->per_cu
= cu
->per_cu
;
24800 gdb_assert (baton
->per_cu
);
24801 /* We don't know how long the location list is, but make sure we
24802 don't run off the edge of the section. */
24803 baton
->size
= section
->size
- DW_UNSND (attr
);
24804 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
24805 baton
->base_address
= cu
->base_address
;
24806 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
24810 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
24811 struct dwarf2_cu
*cu
, int is_block
)
24813 struct dwarf2_per_objfile
*dwarf2_per_objfile
24814 = cu
->per_cu
->dwarf2_per_objfile
;
24815 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24816 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24818 if (attr_form_is_section_offset (attr
)
24819 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24820 the section. If so, fall through to the complaint in the
24822 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
24824 struct dwarf2_loclist_baton
*baton
;
24826 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24828 fill_in_loclist_baton (cu
, baton
, attr
);
24830 if (cu
->base_known
== 0)
24831 complaint (&symfile_complaints
,
24832 _("Location list used without "
24833 "specifying the CU base address."));
24835 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24836 ? dwarf2_loclist_block_index
24837 : dwarf2_loclist_index
);
24838 SYMBOL_LOCATION_BATON (sym
) = baton
;
24842 struct dwarf2_locexpr_baton
*baton
;
24844 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24845 baton
->per_cu
= cu
->per_cu
;
24846 gdb_assert (baton
->per_cu
);
24848 if (attr_form_is_block (attr
))
24850 /* Note that we're just copying the block's data pointer
24851 here, not the actual data. We're still pointing into the
24852 info_buffer for SYM's objfile; right now we never release
24853 that buffer, but when we do clean up properly this may
24855 baton
->size
= DW_BLOCK (attr
)->size
;
24856 baton
->data
= DW_BLOCK (attr
)->data
;
24860 dwarf2_invalid_attrib_class_complaint ("location description",
24861 SYMBOL_NATURAL_NAME (sym
));
24865 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24866 ? dwarf2_locexpr_block_index
24867 : dwarf2_locexpr_index
);
24868 SYMBOL_LOCATION_BATON (sym
) = baton
;
24872 /* Return the OBJFILE associated with the compilation unit CU. If CU
24873 came from a separate debuginfo file, then the master objfile is
24877 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
24879 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
24881 /* Return the master objfile, so that we can report and look up the
24882 correct file containing this variable. */
24883 if (objfile
->separate_debug_objfile_backlink
)
24884 objfile
= objfile
->separate_debug_objfile_backlink
;
24889 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
24890 (CU_HEADERP is unused in such case) or prepare a temporary copy at
24891 CU_HEADERP first. */
24893 static const struct comp_unit_head
*
24894 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
24895 struct dwarf2_per_cu_data
*per_cu
)
24897 const gdb_byte
*info_ptr
;
24900 return &per_cu
->cu
->header
;
24902 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
24904 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
24905 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
24906 rcuh_kind::COMPILE
);
24911 /* Return the address size given in the compilation unit header for CU. */
24914 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
24916 struct comp_unit_head cu_header_local
;
24917 const struct comp_unit_head
*cu_headerp
;
24919 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
24921 return cu_headerp
->addr_size
;
24924 /* Return the offset size given in the compilation unit header for CU. */
24927 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
24929 struct comp_unit_head cu_header_local
;
24930 const struct comp_unit_head
*cu_headerp
;
24932 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
24934 return cu_headerp
->offset_size
;
24937 /* See its dwarf2loc.h declaration. */
24940 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
24942 struct comp_unit_head cu_header_local
;
24943 const struct comp_unit_head
*cu_headerp
;
24945 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
24947 if (cu_headerp
->version
== 2)
24948 return cu_headerp
->addr_size
;
24950 return cu_headerp
->offset_size
;
24953 /* Return the text offset of the CU. The returned offset comes from
24954 this CU's objfile. If this objfile came from a separate debuginfo
24955 file, then the offset may be different from the corresponding
24956 offset in the parent objfile. */
24959 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
24961 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
24963 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
24966 /* Return DWARF version number of PER_CU. */
24969 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
24971 return per_cu
->dwarf_version
;
24974 /* Locate the .debug_info compilation unit from CU's objfile which contains
24975 the DIE at OFFSET. Raises an error on failure. */
24977 static struct dwarf2_per_cu_data
*
24978 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24979 unsigned int offset_in_dwz
,
24980 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
24982 struct dwarf2_per_cu_data
*this_cu
;
24984 const sect_offset
*cu_off
;
24987 high
= dwarf2_per_objfile
->all_comp_units
.size () - 1;
24990 struct dwarf2_per_cu_data
*mid_cu
;
24991 int mid
= low
+ (high
- low
) / 2;
24993 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
24994 cu_off
= &mid_cu
->sect_off
;
24995 if (mid_cu
->is_dwz
> offset_in_dwz
24996 || (mid_cu
->is_dwz
== offset_in_dwz
&& *cu_off
>= sect_off
))
25001 gdb_assert (low
== high
);
25002 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
25003 cu_off
= &this_cu
->sect_off
;
25004 if (this_cu
->is_dwz
!= offset_in_dwz
|| *cu_off
> sect_off
)
25006 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
25007 error (_("Dwarf Error: could not find partial DIE containing "
25008 "offset %s [in module %s]"),
25009 sect_offset_str (sect_off
),
25010 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
25012 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
25014 return dwarf2_per_objfile
->all_comp_units
[low
-1];
25018 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
25019 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
25020 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
25021 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
25022 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
25027 /* Initialize dwarf2_cu CU, owned by PER_CU. */
25029 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
25030 : per_cu (per_cu_
),
25033 checked_producer (0),
25034 producer_is_gxx_lt_4_6 (0),
25035 producer_is_gcc_lt_4_3 (0),
25036 producer_is_icc_lt_14 (0),
25037 processing_has_namespace_info (0)
25042 /* Destroy a dwarf2_cu. */
25044 dwarf2_cu::~dwarf2_cu ()
25049 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
25052 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
25053 enum language pretend_language
)
25055 struct attribute
*attr
;
25057 /* Set the language we're debugging. */
25058 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
25060 set_cu_language (DW_UNSND (attr
), cu
);
25063 cu
->language
= pretend_language
;
25064 cu
->language_defn
= language_def (cu
->language
);
25067 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
25070 /* Increase the age counter on each cached compilation unit, and free
25071 any that are too old. */
25074 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25076 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25078 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
25079 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25080 while (per_cu
!= NULL
)
25082 per_cu
->cu
->last_used
++;
25083 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
25084 dwarf2_mark (per_cu
->cu
);
25085 per_cu
= per_cu
->cu
->read_in_chain
;
25088 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25089 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25090 while (per_cu
!= NULL
)
25092 struct dwarf2_per_cu_data
*next_cu
;
25094 next_cu
= per_cu
->cu
->read_in_chain
;
25096 if (!per_cu
->cu
->mark
)
25099 *last_chain
= next_cu
;
25102 last_chain
= &per_cu
->cu
->read_in_chain
;
25108 /* Remove a single compilation unit from the cache. */
25111 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
25113 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25114 struct dwarf2_per_objfile
*dwarf2_per_objfile
25115 = target_per_cu
->dwarf2_per_objfile
;
25117 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25118 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25119 while (per_cu
!= NULL
)
25121 struct dwarf2_per_cu_data
*next_cu
;
25123 next_cu
= per_cu
->cu
->read_in_chain
;
25125 if (per_cu
== target_per_cu
)
25129 *last_chain
= next_cu
;
25133 last_chain
= &per_cu
->cu
->read_in_chain
;
25139 /* Release all extra memory associated with OBJFILE. */
25142 dwarf2_free_objfile (struct objfile
*objfile
)
25144 struct dwarf2_per_objfile
*dwarf2_per_objfile
25145 = get_dwarf2_per_objfile (objfile
);
25147 delete dwarf2_per_objfile
;
25150 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
25151 We store these in a hash table separate from the DIEs, and preserve them
25152 when the DIEs are flushed out of cache.
25154 The CU "per_cu" pointer is needed because offset alone is not enough to
25155 uniquely identify the type. A file may have multiple .debug_types sections,
25156 or the type may come from a DWO file. Furthermore, while it's more logical
25157 to use per_cu->section+offset, with Fission the section with the data is in
25158 the DWO file but we don't know that section at the point we need it.
25159 We have to use something in dwarf2_per_cu_data (or the pointer to it)
25160 because we can enter the lookup routine, get_die_type_at_offset, from
25161 outside this file, and thus won't necessarily have PER_CU->cu.
25162 Fortunately, PER_CU is stable for the life of the objfile. */
25164 struct dwarf2_per_cu_offset_and_type
25166 const struct dwarf2_per_cu_data
*per_cu
;
25167 sect_offset sect_off
;
25171 /* Hash function for a dwarf2_per_cu_offset_and_type. */
25174 per_cu_offset_and_type_hash (const void *item
)
25176 const struct dwarf2_per_cu_offset_and_type
*ofs
25177 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
25179 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
25182 /* Equality function for a dwarf2_per_cu_offset_and_type. */
25185 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
25187 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
25188 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
25189 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25190 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25192 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25193 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25196 /* Set the type associated with DIE to TYPE. Save it in CU's hash
25197 table if necessary. For convenience, return TYPE.
25199 The DIEs reading must have careful ordering to:
25200 * Not cause infite loops trying to read in DIEs as a prerequisite for
25201 reading current DIE.
25202 * Not trying to dereference contents of still incompletely read in types
25203 while reading in other DIEs.
25204 * Enable referencing still incompletely read in types just by a pointer to
25205 the type without accessing its fields.
25207 Therefore caller should follow these rules:
25208 * Try to fetch any prerequisite types we may need to build this DIE type
25209 before building the type and calling set_die_type.
25210 * After building type call set_die_type for current DIE as soon as
25211 possible before fetching more types to complete the current type.
25212 * Make the type as complete as possible before fetching more types. */
25214 static struct type
*
25215 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
25217 struct dwarf2_per_objfile
*dwarf2_per_objfile
25218 = cu
->per_cu
->dwarf2_per_objfile
;
25219 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
25220 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25221 struct attribute
*attr
;
25222 struct dynamic_prop prop
;
25224 /* For Ada types, make sure that the gnat-specific data is always
25225 initialized (if not already set). There are a few types where
25226 we should not be doing so, because the type-specific area is
25227 already used to hold some other piece of info (eg: TYPE_CODE_FLT
25228 where the type-specific area is used to store the floatformat).
25229 But this is not a problem, because the gnat-specific information
25230 is actually not needed for these types. */
25231 if (need_gnat_info (cu
)
25232 && TYPE_CODE (type
) != TYPE_CODE_FUNC
25233 && TYPE_CODE (type
) != TYPE_CODE_FLT
25234 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
25235 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
25236 && TYPE_CODE (type
) != TYPE_CODE_METHOD
25237 && !HAVE_GNAT_AUX_INFO (type
))
25238 INIT_GNAT_SPECIFIC (type
);
25240 /* Read DW_AT_allocated and set in type. */
25241 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
25242 if (attr_form_is_block (attr
))
25244 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25245 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
25247 else if (attr
!= NULL
)
25249 complaint (&symfile_complaints
,
25250 _("DW_AT_allocated has the wrong form (%s) at DIE %s"),
25251 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25252 sect_offset_str (die
->sect_off
));
25255 /* Read DW_AT_associated and set in type. */
25256 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
25257 if (attr_form_is_block (attr
))
25259 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25260 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
25262 else if (attr
!= NULL
)
25264 complaint (&symfile_complaints
,
25265 _("DW_AT_associated has the wrong form (%s) at DIE %s"),
25266 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25267 sect_offset_str (die
->sect_off
));
25270 /* Read DW_AT_data_location and set in type. */
25271 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
25272 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25273 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
25275 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25277 dwarf2_per_objfile
->die_type_hash
=
25278 htab_create_alloc_ex (127,
25279 per_cu_offset_and_type_hash
,
25280 per_cu_offset_and_type_eq
,
25282 &objfile
->objfile_obstack
,
25283 hashtab_obstack_allocate
,
25284 dummy_obstack_deallocate
);
25287 ofs
.per_cu
= cu
->per_cu
;
25288 ofs
.sect_off
= die
->sect_off
;
25290 slot
= (struct dwarf2_per_cu_offset_and_type
**)
25291 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
25293 complaint (&symfile_complaints
,
25294 _("A problem internal to GDB: DIE %s has type already set"),
25295 sect_offset_str (die
->sect_off
));
25296 *slot
= XOBNEW (&objfile
->objfile_obstack
,
25297 struct dwarf2_per_cu_offset_and_type
);
25302 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
25303 or return NULL if the die does not have a saved type. */
25305 static struct type
*
25306 get_die_type_at_offset (sect_offset sect_off
,
25307 struct dwarf2_per_cu_data
*per_cu
)
25309 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
25310 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
25312 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25315 ofs
.per_cu
= per_cu
;
25316 ofs
.sect_off
= sect_off
;
25317 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
25318 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
25325 /* Look up the type for DIE in CU in die_type_hash,
25326 or return NULL if DIE does not have a saved type. */
25328 static struct type
*
25329 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
25331 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
25334 /* Add a dependence relationship from CU to REF_PER_CU. */
25337 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
25338 struct dwarf2_per_cu_data
*ref_per_cu
)
25342 if (cu
->dependencies
== NULL
)
25344 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
25345 NULL
, &cu
->comp_unit_obstack
,
25346 hashtab_obstack_allocate
,
25347 dummy_obstack_deallocate
);
25349 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
25351 *slot
= ref_per_cu
;
25354 /* Subroutine of dwarf2_mark to pass to htab_traverse.
25355 Set the mark field in every compilation unit in the
25356 cache that we must keep because we are keeping CU. */
25359 dwarf2_mark_helper (void **slot
, void *data
)
25361 struct dwarf2_per_cu_data
*per_cu
;
25363 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
25365 /* cu->dependencies references may not yet have been ever read if QUIT aborts
25366 reading of the chain. As such dependencies remain valid it is not much
25367 useful to track and undo them during QUIT cleanups. */
25368 if (per_cu
->cu
== NULL
)
25371 if (per_cu
->cu
->mark
)
25373 per_cu
->cu
->mark
= 1;
25375 if (per_cu
->cu
->dependencies
!= NULL
)
25376 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25381 /* Set the mark field in CU and in every other compilation unit in the
25382 cache that we must keep because we are keeping CU. */
25385 dwarf2_mark (struct dwarf2_cu
*cu
)
25390 if (cu
->dependencies
!= NULL
)
25391 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25395 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
25399 per_cu
->cu
->mark
= 0;
25400 per_cu
= per_cu
->cu
->read_in_chain
;
25404 /* Trivial hash function for partial_die_info: the hash value of a DIE
25405 is its offset in .debug_info for this objfile. */
25408 partial_die_hash (const void *item
)
25410 const struct partial_die_info
*part_die
25411 = (const struct partial_die_info
*) item
;
25413 return to_underlying (part_die
->sect_off
);
25416 /* Trivial comparison function for partial_die_info structures: two DIEs
25417 are equal if they have the same offset. */
25420 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
25422 const struct partial_die_info
*part_die_lhs
25423 = (const struct partial_die_info
*) item_lhs
;
25424 const struct partial_die_info
*part_die_rhs
25425 = (const struct partial_die_info
*) item_rhs
;
25427 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
25430 static struct cmd_list_element
*set_dwarf_cmdlist
;
25431 static struct cmd_list_element
*show_dwarf_cmdlist
;
25434 set_dwarf_cmd (const char *args
, int from_tty
)
25436 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
25441 show_dwarf_cmd (const char *args
, int from_tty
)
25443 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
25446 int dwarf_always_disassemble
;
25449 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
25450 struct cmd_list_element
*c
, const char *value
)
25452 fprintf_filtered (file
,
25453 _("Whether to always disassemble "
25454 "DWARF expressions is %s.\n"),
25459 show_check_physname (struct ui_file
*file
, int from_tty
,
25460 struct cmd_list_element
*c
, const char *value
)
25462 fprintf_filtered (file
,
25463 _("Whether to check \"physname\" is %s.\n"),
25468 _initialize_dwarf2_read (void)
25471 dwarf2_objfile_data_key
= register_objfile_data ();
25473 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
25474 Set DWARF specific variables.\n\
25475 Configure DWARF variables such as the cache size"),
25476 &set_dwarf_cmdlist
, "maintenance set dwarf ",
25477 0/*allow-unknown*/, &maintenance_set_cmdlist
);
25479 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
25480 Show DWARF specific variables\n\
25481 Show DWARF variables such as the cache size"),
25482 &show_dwarf_cmdlist
, "maintenance show dwarf ",
25483 0/*allow-unknown*/, &maintenance_show_cmdlist
);
25485 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
25486 &dwarf_max_cache_age
, _("\
25487 Set the upper bound on the age of cached DWARF compilation units."), _("\
25488 Show the upper bound on the age of cached DWARF compilation units."), _("\
25489 A higher limit means that cached compilation units will be stored\n\
25490 in memory longer, and more total memory will be used. Zero disables\n\
25491 caching, which can slow down startup."),
25493 show_dwarf_max_cache_age
,
25494 &set_dwarf_cmdlist
,
25495 &show_dwarf_cmdlist
);
25497 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
25498 &dwarf_always_disassemble
, _("\
25499 Set whether `info address' always disassembles DWARF expressions."), _("\
25500 Show whether `info address' always disassembles DWARF expressions."), _("\
25501 When enabled, DWARF expressions are always printed in an assembly-like\n\
25502 syntax. When disabled, expressions will be printed in a more\n\
25503 conversational style, when possible."),
25505 show_dwarf_always_disassemble
,
25506 &set_dwarf_cmdlist
,
25507 &show_dwarf_cmdlist
);
25509 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
25510 Set debugging of the DWARF reader."), _("\
25511 Show debugging of the DWARF reader."), _("\
25512 When enabled (non-zero), debugging messages are printed during DWARF\n\
25513 reading and symtab expansion. A value of 1 (one) provides basic\n\
25514 information. A value greater than 1 provides more verbose information."),
25517 &setdebuglist
, &showdebuglist
);
25519 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
25520 Set debugging of the DWARF DIE reader."), _("\
25521 Show debugging of the DWARF DIE reader."), _("\
25522 When enabled (non-zero), DIEs are dumped after they are read in.\n\
25523 The value is the maximum depth to print."),
25526 &setdebuglist
, &showdebuglist
);
25528 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
25529 Set debugging of the dwarf line reader."), _("\
25530 Show debugging of the dwarf line reader."), _("\
25531 When enabled (non-zero), line number entries are dumped as they are read in.\n\
25532 A value of 1 (one) provides basic information.\n\
25533 A value greater than 1 provides more verbose information."),
25536 &setdebuglist
, &showdebuglist
);
25538 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
25539 Set cross-checking of \"physname\" code against demangler."), _("\
25540 Show cross-checking of \"physname\" code against demangler."), _("\
25541 When enabled, GDB's internal \"physname\" code is checked against\n\
25543 NULL
, show_check_physname
,
25544 &setdebuglist
, &showdebuglist
);
25546 add_setshow_boolean_cmd ("use-deprecated-index-sections",
25547 no_class
, &use_deprecated_index_sections
, _("\
25548 Set whether to use deprecated gdb_index sections."), _("\
25549 Show whether to use deprecated gdb_index sections."), _("\
25550 When enabled, deprecated .gdb_index sections are used anyway.\n\
25551 Normally they are ignored either because of a missing feature or\n\
25552 performance issue.\n\
25553 Warning: This option must be enabled before gdb reads the file."),
25556 &setlist
, &showlist
);
25558 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25559 &dwarf2_locexpr_funcs
);
25560 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25561 &dwarf2_loclist_funcs
);
25563 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25564 &dwarf2_block_frame_base_locexpr_funcs
);
25565 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25566 &dwarf2_block_frame_base_loclist_funcs
);
25569 selftests::register_test ("dw2_expand_symtabs_matching",
25570 selftests::dw2_expand_symtabs_matching::run_test
);