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
;
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 /* Name of the file. */
813 /* File format version. */
819 /* Section info for this file. */
820 struct dwp_sections sections
;
822 /* Table of CUs in the file. */
823 const struct dwp_hash_table
*cus
;
825 /* Table of TUs in the file. */
826 const struct dwp_hash_table
*tus
;
828 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
832 /* Table to map ELF section numbers to their sections.
833 This is only needed for the DWP V1 file format. */
834 unsigned int num_sections
;
835 asection
**elf_sections
;
838 /* This represents a '.dwz' file. */
842 /* A dwz file can only contain a few sections. */
843 struct dwarf2_section_info abbrev
;
844 struct dwarf2_section_info info
;
845 struct dwarf2_section_info str
;
846 struct dwarf2_section_info line
;
847 struct dwarf2_section_info macro
;
848 struct dwarf2_section_info gdb_index
;
849 struct dwarf2_section_info debug_names
;
855 /* Struct used to pass misc. parameters to read_die_and_children, et
856 al. which are used for both .debug_info and .debug_types dies.
857 All parameters here are unchanging for the life of the call. This
858 struct exists to abstract away the constant parameters of die reading. */
860 struct die_reader_specs
862 /* The bfd of die_section. */
865 /* The CU of the DIE we are parsing. */
866 struct dwarf2_cu
*cu
;
868 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
869 struct dwo_file
*dwo_file
;
871 /* The section the die comes from.
872 This is either .debug_info or .debug_types, or the .dwo variants. */
873 struct dwarf2_section_info
*die_section
;
875 /* die_section->buffer. */
876 const gdb_byte
*buffer
;
878 /* The end of the buffer. */
879 const gdb_byte
*buffer_end
;
881 /* The value of the DW_AT_comp_dir attribute. */
882 const char *comp_dir
;
884 /* The abbreviation table to use when reading the DIEs. */
885 struct abbrev_table
*abbrev_table
;
888 /* Type of function passed to init_cutu_and_read_dies, et.al. */
889 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
890 const gdb_byte
*info_ptr
,
891 struct die_info
*comp_unit_die
,
895 /* A 1-based directory index. This is a strong typedef to prevent
896 accidentally using a directory index as a 0-based index into an
898 enum class dir_index
: unsigned int {};
900 /* Likewise, a 1-based file name index. */
901 enum class file_name_index
: unsigned int {};
905 file_entry () = default;
907 file_entry (const char *name_
, dir_index d_index_
,
908 unsigned int mod_time_
, unsigned int length_
)
911 mod_time (mod_time_
),
915 /* Return the include directory at D_INDEX stored in LH. Returns
916 NULL if D_INDEX is out of bounds. */
917 const char *include_dir (const line_header
*lh
) const;
919 /* The file name. Note this is an observing pointer. The memory is
920 owned by debug_line_buffer. */
923 /* The directory index (1-based). */
924 dir_index d_index
{};
926 unsigned int mod_time
{};
928 unsigned int length
{};
930 /* True if referenced by the Line Number Program. */
933 /* The associated symbol table, if any. */
934 struct symtab
*symtab
{};
937 /* The line number information for a compilation unit (found in the
938 .debug_line section) begins with a "statement program header",
939 which contains the following information. */
946 /* Add an entry to the include directory table. */
947 void add_include_dir (const char *include_dir
);
949 /* Add an entry to the file name table. */
950 void add_file_name (const char *name
, dir_index d_index
,
951 unsigned int mod_time
, unsigned int length
);
953 /* Return the include dir at INDEX (1-based). Returns NULL if INDEX
955 const char *include_dir_at (dir_index index
) const
957 /* Convert directory index number (1-based) to vector index
959 size_t vec_index
= to_underlying (index
) - 1;
961 if (vec_index
>= include_dirs
.size ())
963 return include_dirs
[vec_index
];
966 /* Return the file name at INDEX (1-based). Returns NULL if INDEX
968 file_entry
*file_name_at (file_name_index index
)
970 /* Convert file name index number (1-based) to vector index
972 size_t vec_index
= to_underlying (index
) - 1;
974 if (vec_index
>= file_names
.size ())
976 return &file_names
[vec_index
];
979 /* Const version of the above. */
980 const file_entry
*file_name_at (unsigned int index
) const
982 if (index
>= file_names
.size ())
984 return &file_names
[index
];
987 /* Offset of line number information in .debug_line section. */
988 sect_offset sect_off
{};
990 /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile. */
991 unsigned offset_in_dwz
: 1; /* Can't initialize bitfields in-class. */
993 unsigned int total_length
{};
994 unsigned short version
{};
995 unsigned int header_length
{};
996 unsigned char minimum_instruction_length
{};
997 unsigned char maximum_ops_per_instruction
{};
998 unsigned char default_is_stmt
{};
1000 unsigned char line_range
{};
1001 unsigned char opcode_base
{};
1003 /* standard_opcode_lengths[i] is the number of operands for the
1004 standard opcode whose value is i. This means that
1005 standard_opcode_lengths[0] is unused, and the last meaningful
1006 element is standard_opcode_lengths[opcode_base - 1]. */
1007 std::unique_ptr
<unsigned char[]> standard_opcode_lengths
;
1009 /* The include_directories table. Note these are observing
1010 pointers. The memory is owned by debug_line_buffer. */
1011 std::vector
<const char *> include_dirs
;
1013 /* The file_names table. */
1014 std::vector
<file_entry
> file_names
;
1016 /* The start and end of the statement program following this
1017 header. These point into dwarf2_per_objfile->line_buffer. */
1018 const gdb_byte
*statement_program_start
{}, *statement_program_end
{};
1021 typedef std::unique_ptr
<line_header
> line_header_up
;
1024 file_entry::include_dir (const line_header
*lh
) const
1026 return lh
->include_dir_at (d_index
);
1029 /* When we construct a partial symbol table entry we only
1030 need this much information. */
1031 struct partial_die_info
: public allocate_on_obstack
1033 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
1035 /* Disable assign but still keep copy ctor, which is needed
1036 load_partial_dies. */
1037 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
1039 /* Adjust the partial die before generating a symbol for it. This
1040 function may set the is_external flag or change the DIE's
1042 void fixup (struct dwarf2_cu
*cu
);
1044 /* Read a minimal amount of information into the minimal die
1046 const gdb_byte
*read (const struct die_reader_specs
*reader
,
1047 const struct abbrev_info
&abbrev
,
1048 const gdb_byte
*info_ptr
);
1050 /* Offset of this DIE. */
1051 const sect_offset sect_off
;
1053 /* DWARF-2 tag for this DIE. */
1054 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1056 /* Assorted flags describing the data found in this DIE. */
1057 const unsigned int has_children
: 1;
1059 unsigned int is_external
: 1;
1060 unsigned int is_declaration
: 1;
1061 unsigned int has_type
: 1;
1062 unsigned int has_specification
: 1;
1063 unsigned int has_pc_info
: 1;
1064 unsigned int may_be_inlined
: 1;
1066 /* This DIE has been marked DW_AT_main_subprogram. */
1067 unsigned int main_subprogram
: 1;
1069 /* Flag set if the SCOPE field of this structure has been
1071 unsigned int scope_set
: 1;
1073 /* Flag set if the DIE has a byte_size attribute. */
1074 unsigned int has_byte_size
: 1;
1076 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1077 unsigned int has_const_value
: 1;
1079 /* Flag set if any of the DIE's children are template arguments. */
1080 unsigned int has_template_arguments
: 1;
1082 /* Flag set if fixup has been called on this die. */
1083 unsigned int fixup_called
: 1;
1085 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1086 unsigned int is_dwz
: 1;
1088 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1089 unsigned int spec_is_dwz
: 1;
1091 /* The name of this DIE. Normally the value of DW_AT_name, but
1092 sometimes a default name for unnamed DIEs. */
1093 const char *name
= nullptr;
1095 /* The linkage name, if present. */
1096 const char *linkage_name
= nullptr;
1098 /* The scope to prepend to our children. This is generally
1099 allocated on the comp_unit_obstack, so will disappear
1100 when this compilation unit leaves the cache. */
1101 const char *scope
= nullptr;
1103 /* Some data associated with the partial DIE. The tag determines
1104 which field is live. */
1107 /* The location description associated with this DIE, if any. */
1108 struct dwarf_block
*locdesc
;
1109 /* The offset of an import, for DW_TAG_imported_unit. */
1110 sect_offset sect_off
;
1113 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1114 CORE_ADDR lowpc
= 0;
1115 CORE_ADDR highpc
= 0;
1117 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1118 DW_AT_sibling, if any. */
1119 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1120 could return DW_AT_sibling values to its caller load_partial_dies. */
1121 const gdb_byte
*sibling
= nullptr;
1123 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1124 DW_AT_specification (or DW_AT_abstract_origin or
1125 DW_AT_extension). */
1126 sect_offset spec_offset
{};
1128 /* Pointers to this DIE's parent, first child, and next sibling,
1130 struct partial_die_info
*die_parent
= nullptr;
1131 struct partial_die_info
*die_child
= nullptr;
1132 struct partial_die_info
*die_sibling
= nullptr;
1134 friend struct partial_die_info
*
1135 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1138 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1139 partial_die_info (sect_offset sect_off
)
1140 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1144 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1146 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1151 has_specification
= 0;
1154 main_subprogram
= 0;
1157 has_const_value
= 0;
1158 has_template_arguments
= 0;
1165 /* This data structure holds the information of an abbrev. */
1168 unsigned int number
; /* number identifying abbrev */
1169 enum dwarf_tag tag
; /* dwarf tag */
1170 unsigned short has_children
; /* boolean */
1171 unsigned short num_attrs
; /* number of attributes */
1172 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
1173 struct abbrev_info
*next
; /* next in chain */
1178 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1179 ENUM_BITFIELD(dwarf_form
) form
: 16;
1181 /* It is valid only if FORM is DW_FORM_implicit_const. */
1182 LONGEST implicit_const
;
1185 /* Size of abbrev_table.abbrev_hash_table. */
1186 #define ABBREV_HASH_SIZE 121
1188 /* Top level data structure to contain an abbreviation table. */
1192 explicit abbrev_table (sect_offset off
)
1196 XOBNEWVEC (&abbrev_obstack
, struct abbrev_info
*, ABBREV_HASH_SIZE
);
1197 memset (m_abbrevs
, 0, ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
1200 DISABLE_COPY_AND_ASSIGN (abbrev_table
);
1202 /* Allocate space for a struct abbrev_info object in
1204 struct abbrev_info
*alloc_abbrev ();
1206 /* Add an abbreviation to the table. */
1207 void add_abbrev (unsigned int abbrev_number
, struct abbrev_info
*abbrev
);
1209 /* Look up an abbrev in the table.
1210 Returns NULL if the abbrev is not found. */
1212 struct abbrev_info
*lookup_abbrev (unsigned int abbrev_number
);
1215 /* Where the abbrev table came from.
1216 This is used as a sanity check when the table is used. */
1217 const sect_offset sect_off
;
1219 /* Storage for the abbrev table. */
1220 auto_obstack abbrev_obstack
;
1224 /* Hash table of abbrevs.
1225 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1226 It could be statically allocated, but the previous code didn't so we
1228 struct abbrev_info
**m_abbrevs
;
1231 typedef std::unique_ptr
<struct abbrev_table
> abbrev_table_up
;
1233 /* Attributes have a name and a value. */
1236 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1237 ENUM_BITFIELD(dwarf_form
) form
: 15;
1239 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1240 field should be in u.str (existing only for DW_STRING) but it is kept
1241 here for better struct attribute alignment. */
1242 unsigned int string_is_canonical
: 1;
1247 struct dwarf_block
*blk
;
1256 /* This data structure holds a complete die structure. */
1259 /* DWARF-2 tag for this DIE. */
1260 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1262 /* Number of attributes */
1263 unsigned char num_attrs
;
1265 /* True if we're presently building the full type name for the
1266 type derived from this DIE. */
1267 unsigned char building_fullname
: 1;
1269 /* True if this die is in process. PR 16581. */
1270 unsigned char in_process
: 1;
1273 unsigned int abbrev
;
1275 /* Offset in .debug_info or .debug_types section. */
1276 sect_offset sect_off
;
1278 /* The dies in a compilation unit form an n-ary tree. PARENT
1279 points to this die's parent; CHILD points to the first child of
1280 this node; and all the children of a given node are chained
1281 together via their SIBLING fields. */
1282 struct die_info
*child
; /* Its first child, if any. */
1283 struct die_info
*sibling
; /* Its next sibling, if any. */
1284 struct die_info
*parent
; /* Its parent, if any. */
1286 /* An array of attributes, with NUM_ATTRS elements. There may be
1287 zero, but it's not common and zero-sized arrays are not
1288 sufficiently portable C. */
1289 struct attribute attrs
[1];
1292 /* Get at parts of an attribute structure. */
1294 #define DW_STRING(attr) ((attr)->u.str)
1295 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1296 #define DW_UNSND(attr) ((attr)->u.unsnd)
1297 #define DW_BLOCK(attr) ((attr)->u.blk)
1298 #define DW_SND(attr) ((attr)->u.snd)
1299 #define DW_ADDR(attr) ((attr)->u.addr)
1300 #define DW_SIGNATURE(attr) ((attr)->u.signature)
1302 /* Blocks are a bunch of untyped bytes. */
1307 /* Valid only if SIZE is not zero. */
1308 const gdb_byte
*data
;
1311 #ifndef ATTR_ALLOC_CHUNK
1312 #define ATTR_ALLOC_CHUNK 4
1315 /* Allocate fields for structs, unions and enums in this size. */
1316 #ifndef DW_FIELD_ALLOC_CHUNK
1317 #define DW_FIELD_ALLOC_CHUNK 4
1320 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1321 but this would require a corresponding change in unpack_field_as_long
1323 static int bits_per_byte
= 8;
1325 /* When reading a variant or variant part, we track a bit more
1326 information about the field, and store it in an object of this
1329 struct variant_field
1331 /* If we see a DW_TAG_variant, then this will be the discriminant
1333 ULONGEST discriminant_value
;
1334 /* If we see a DW_TAG_variant, then this will be set if this is the
1336 bool default_branch
;
1337 /* While reading a DW_TAG_variant_part, this will be set if this
1338 field is the discriminant. */
1339 bool is_discriminant
;
1344 int accessibility
= 0;
1346 /* Extra information to describe a variant or variant part. */
1347 struct variant_field variant
{};
1348 struct field field
{};
1353 const char *name
= nullptr;
1354 std::vector
<struct fn_field
> fnfields
;
1357 /* The routines that read and process dies for a C struct or C++ class
1358 pass lists of data member fields and lists of member function fields
1359 in an instance of a field_info structure, as defined below. */
1362 /* List of data member and baseclasses fields. */
1363 std::vector
<struct nextfield
> fields
;
1364 std::vector
<struct nextfield
> baseclasses
;
1366 /* Number of fields (including baseclasses). */
1369 /* Set if the accesibility of one of the fields is not public. */
1370 int non_public_fields
= 0;
1372 /* Member function fieldlist array, contains name of possibly overloaded
1373 member function, number of overloaded member functions and a pointer
1374 to the head of the member function field chain. */
1375 std::vector
<struct fnfieldlist
> fnfieldlists
;
1377 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1378 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1379 std::vector
<struct decl_field
> typedef_field_list
;
1381 /* Nested types defined by this class and the number of elements in this
1383 std::vector
<struct decl_field
> nested_types_list
;
1386 /* One item on the queue of compilation units to read in full symbols
1388 struct dwarf2_queue_item
1390 struct dwarf2_per_cu_data
*per_cu
;
1391 enum language pretend_language
;
1392 struct dwarf2_queue_item
*next
;
1395 /* The current queue. */
1396 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1398 /* Loaded secondary compilation units are kept in memory until they
1399 have not been referenced for the processing of this many
1400 compilation units. Set this to zero to disable caching. Cache
1401 sizes of up to at least twenty will improve startup time for
1402 typical inter-CU-reference binaries, at an obvious memory cost. */
1403 static int dwarf_max_cache_age
= 5;
1405 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1406 struct cmd_list_element
*c
, const char *value
)
1408 fprintf_filtered (file
, _("The upper bound on the age of cached "
1409 "DWARF compilation units is %s.\n"),
1413 /* local function prototypes */
1415 static const char *get_section_name (const struct dwarf2_section_info
*);
1417 static const char *get_section_file_name (const struct dwarf2_section_info
*);
1419 static void dwarf2_find_base_address (struct die_info
*die
,
1420 struct dwarf2_cu
*cu
);
1422 static struct partial_symtab
*create_partial_symtab
1423 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1425 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1426 const gdb_byte
*info_ptr
,
1427 struct die_info
*type_unit_die
,
1428 int has_children
, void *data
);
1430 static void dwarf2_build_psymtabs_hard
1431 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1433 static void scan_partial_symbols (struct partial_die_info
*,
1434 CORE_ADDR
*, CORE_ADDR
*,
1435 int, struct dwarf2_cu
*);
1437 static void add_partial_symbol (struct partial_die_info
*,
1438 struct dwarf2_cu
*);
1440 static void add_partial_namespace (struct partial_die_info
*pdi
,
1441 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1442 int set_addrmap
, struct dwarf2_cu
*cu
);
1444 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1445 CORE_ADDR
*highpc
, int set_addrmap
,
1446 struct dwarf2_cu
*cu
);
1448 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1449 struct dwarf2_cu
*cu
);
1451 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1452 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1453 int need_pc
, struct dwarf2_cu
*cu
);
1455 static void dwarf2_read_symtab (struct partial_symtab
*,
1458 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1460 static abbrev_table_up abbrev_table_read_table
1461 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, struct dwarf2_section_info
*,
1464 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1466 static struct partial_die_info
*load_partial_dies
1467 (const struct die_reader_specs
*, const gdb_byte
*, int);
1469 static struct partial_die_info
*find_partial_die (sect_offset
, int,
1470 struct dwarf2_cu
*);
1472 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1473 struct attribute
*, struct attr_abbrev
*,
1476 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1478 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1480 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1482 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1484 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1486 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1489 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1491 static LONGEST read_checked_initial_length_and_offset
1492 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1493 unsigned int *, unsigned int *);
1495 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1496 const struct comp_unit_head
*,
1499 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1501 static sect_offset read_abbrev_offset
1502 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1503 struct dwarf2_section_info
*, sect_offset
);
1505 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1507 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1509 static const char *read_indirect_string
1510 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1511 const struct comp_unit_head
*, unsigned int *);
1513 static const char *read_indirect_line_string
1514 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1515 const struct comp_unit_head
*, unsigned int *);
1517 static const char *read_indirect_string_at_offset
1518 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
1519 LONGEST str_offset
);
1521 static const char *read_indirect_string_from_dwz
1522 (struct objfile
*objfile
, struct dwz_file
*, LONGEST
);
1524 static LONGEST
read_signed_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1526 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1530 static const char *read_str_index (const struct die_reader_specs
*reader
,
1531 ULONGEST str_index
);
1533 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1535 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1536 struct dwarf2_cu
*);
1538 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1541 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1542 struct dwarf2_cu
*cu
);
1544 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1545 struct dwarf2_cu
*cu
);
1547 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1549 static struct die_info
*die_specification (struct die_info
*die
,
1550 struct dwarf2_cu
**);
1552 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1553 struct dwarf2_cu
*cu
);
1555 static void dwarf_decode_lines (struct line_header
*, const char *,
1556 struct dwarf2_cu
*, struct partial_symtab
*,
1557 CORE_ADDR
, int decode_mapping
);
1559 static void dwarf2_start_subfile (const char *, const char *);
1561 static struct compunit_symtab
*dwarf2_start_symtab (struct dwarf2_cu
*,
1562 const char *, const char *,
1565 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1566 struct dwarf2_cu
*, struct symbol
* = NULL
);
1568 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1569 struct dwarf2_cu
*);
1571 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1574 struct obstack
*obstack
,
1575 struct dwarf2_cu
*cu
, LONGEST
*value
,
1576 const gdb_byte
**bytes
,
1577 struct dwarf2_locexpr_baton
**baton
);
1579 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1581 static int need_gnat_info (struct dwarf2_cu
*);
1583 static struct type
*die_descriptive_type (struct die_info
*,
1584 struct dwarf2_cu
*);
1586 static void set_descriptive_type (struct type
*, struct die_info
*,
1587 struct dwarf2_cu
*);
1589 static struct type
*die_containing_type (struct die_info
*,
1590 struct dwarf2_cu
*);
1592 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1593 struct dwarf2_cu
*);
1595 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1597 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1599 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1601 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1602 const char *suffix
, int physname
,
1603 struct dwarf2_cu
*cu
);
1605 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1607 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1609 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1611 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1613 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1615 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1617 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1618 struct dwarf2_cu
*, struct partial_symtab
*);
1620 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1621 values. Keep the items ordered with increasing constraints compliance. */
1624 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1625 PC_BOUNDS_NOT_PRESENT
,
1627 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1628 were present but they do not form a valid range of PC addresses. */
1631 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1634 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1638 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1639 CORE_ADDR
*, CORE_ADDR
*,
1641 struct partial_symtab
*);
1643 static void get_scope_pc_bounds (struct die_info
*,
1644 CORE_ADDR
*, CORE_ADDR
*,
1645 struct dwarf2_cu
*);
1647 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1648 CORE_ADDR
, struct dwarf2_cu
*);
1650 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1651 struct dwarf2_cu
*);
1653 static void dwarf2_attach_fields_to_type (struct field_info
*,
1654 struct type
*, struct dwarf2_cu
*);
1656 static void dwarf2_add_member_fn (struct field_info
*,
1657 struct die_info
*, struct type
*,
1658 struct dwarf2_cu
*);
1660 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1662 struct dwarf2_cu
*);
1664 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1666 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1668 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1670 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1672 static struct using_direct
**using_directives (enum language
);
1674 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1676 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1678 static struct type
*read_module_type (struct die_info
*die
,
1679 struct dwarf2_cu
*cu
);
1681 static const char *namespace_name (struct die_info
*die
,
1682 int *is_anonymous
, struct dwarf2_cu
*);
1684 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1686 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1688 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1689 struct dwarf2_cu
*);
1691 static struct die_info
*read_die_and_siblings_1
1692 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1695 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1696 const gdb_byte
*info_ptr
,
1697 const gdb_byte
**new_info_ptr
,
1698 struct die_info
*parent
);
1700 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1701 struct die_info
**, const gdb_byte
*,
1704 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1705 struct die_info
**, const gdb_byte
*,
1708 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1710 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1713 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1715 static const char *dwarf2_full_name (const char *name
,
1716 struct die_info
*die
,
1717 struct dwarf2_cu
*cu
);
1719 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1720 struct dwarf2_cu
*cu
);
1722 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1723 struct dwarf2_cu
**);
1725 static const char *dwarf_tag_name (unsigned int);
1727 static const char *dwarf_attr_name (unsigned int);
1729 static const char *dwarf_form_name (unsigned int);
1731 static const char *dwarf_bool_name (unsigned int);
1733 static const char *dwarf_type_encoding_name (unsigned int);
1735 static struct die_info
*sibling_die (struct die_info
*);
1737 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1739 static void dump_die_for_error (struct die_info
*);
1741 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1744 /*static*/ void dump_die (struct die_info
*, int max_level
);
1746 static void store_in_ref_table (struct die_info
*,
1747 struct dwarf2_cu
*);
1749 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1751 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1753 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1754 const struct attribute
*,
1755 struct dwarf2_cu
**);
1757 static struct die_info
*follow_die_ref (struct die_info
*,
1758 const struct attribute
*,
1759 struct dwarf2_cu
**);
1761 static struct die_info
*follow_die_sig (struct die_info
*,
1762 const struct attribute
*,
1763 struct dwarf2_cu
**);
1765 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1766 struct dwarf2_cu
*);
1768 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1769 const struct attribute
*,
1770 struct dwarf2_cu
*);
1772 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1774 static void read_signatured_type (struct signatured_type
*);
1776 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1777 struct die_info
*die
, struct dwarf2_cu
*cu
,
1778 struct dynamic_prop
*prop
);
1780 /* memory allocation interface */
1782 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1784 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1786 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1788 static int attr_form_is_block (const struct attribute
*);
1790 static int attr_form_is_section_offset (const struct attribute
*);
1792 static int attr_form_is_constant (const struct attribute
*);
1794 static int attr_form_is_ref (const struct attribute
*);
1796 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1797 struct dwarf2_loclist_baton
*baton
,
1798 const struct attribute
*attr
);
1800 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1802 struct dwarf2_cu
*cu
,
1805 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1806 const gdb_byte
*info_ptr
,
1807 struct abbrev_info
*abbrev
);
1809 static hashval_t
partial_die_hash (const void *item
);
1811 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1813 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1814 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1815 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1817 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1818 struct die_info
*comp_unit_die
,
1819 enum language pretend_language
);
1821 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1823 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1825 static struct type
*set_die_type (struct die_info
*, struct type
*,
1826 struct dwarf2_cu
*);
1828 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1830 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1832 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1835 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1838 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1841 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1842 struct dwarf2_per_cu_data
*);
1844 static void dwarf2_mark (struct dwarf2_cu
*);
1846 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1848 static struct type
*get_die_type_at_offset (sect_offset
,
1849 struct dwarf2_per_cu_data
*);
1851 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1853 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1854 enum language pretend_language
);
1856 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1858 /* Class, the destructor of which frees all allocated queue entries. This
1859 will only have work to do if an error was thrown while processing the
1860 dwarf. If no error was thrown then the queue entries should have all
1861 been processed, and freed, as we went along. */
1863 class dwarf2_queue_guard
1866 dwarf2_queue_guard () = default;
1868 /* Free any entries remaining on the queue. There should only be
1869 entries left if we hit an error while processing the dwarf. */
1870 ~dwarf2_queue_guard ()
1872 struct dwarf2_queue_item
*item
, *last
;
1874 item
= dwarf2_queue
;
1877 /* Anything still marked queued is likely to be in an
1878 inconsistent state, so discard it. */
1879 if (item
->per_cu
->queued
)
1881 if (item
->per_cu
->cu
!= NULL
)
1882 free_one_cached_comp_unit (item
->per_cu
);
1883 item
->per_cu
->queued
= 0;
1891 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
1895 /* The return type of find_file_and_directory. Note, the enclosed
1896 string pointers are only valid while this object is valid. */
1898 struct file_and_directory
1900 /* The filename. This is never NULL. */
1903 /* The compilation directory. NULL if not known. If we needed to
1904 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1905 points directly to the DW_AT_comp_dir string attribute owned by
1906 the obstack that owns the DIE. */
1907 const char *comp_dir
;
1909 /* If we needed to build a new string for comp_dir, this is what
1910 owns the storage. */
1911 std::string comp_dir_storage
;
1914 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1915 struct dwarf2_cu
*cu
);
1917 static char *file_full_name (int file
, struct line_header
*lh
,
1918 const char *comp_dir
);
1920 /* Expected enum dwarf_unit_type for read_comp_unit_head. */
1921 enum class rcuh_kind
{ COMPILE
, TYPE
};
1923 static const gdb_byte
*read_and_check_comp_unit_head
1924 (struct dwarf2_per_objfile
* dwarf2_per_objfile
,
1925 struct comp_unit_head
*header
,
1926 struct dwarf2_section_info
*section
,
1927 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
1928 rcuh_kind section_kind
);
1930 static void init_cutu_and_read_dies
1931 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
1932 int use_existing_cu
, int keep
, bool skip_partial
,
1933 die_reader_func_ftype
*die_reader_func
, void *data
);
1935 static void init_cutu_and_read_dies_simple
1936 (struct dwarf2_per_cu_data
*this_cu
,
1937 die_reader_func_ftype
*die_reader_func
, void *data
);
1939 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1941 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1943 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1944 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1945 struct dwp_file
*dwp_file
, const char *comp_dir
,
1946 ULONGEST signature
, int is_debug_types
);
1948 static struct dwp_file
*get_dwp_file
1949 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1951 static struct dwo_unit
*lookup_dwo_comp_unit
1952 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1954 static struct dwo_unit
*lookup_dwo_type_unit
1955 (struct signatured_type
*, const char *, const char *);
1957 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1959 static void free_dwo_file (struct dwo_file
*);
1961 /* A unique_ptr helper to free a dwo_file. */
1963 struct dwo_file_deleter
1965 void operator() (struct dwo_file
*df
) const
1971 /* A unique pointer to a dwo_file. */
1973 typedef std::unique_ptr
<struct dwo_file
, dwo_file_deleter
> dwo_file_up
;
1975 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1977 static void check_producer (struct dwarf2_cu
*cu
);
1979 static void free_line_header_voidp (void *arg
);
1981 /* Various complaints about symbol reading that don't abort the process. */
1984 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1986 complaint (&symfile_complaints
,
1987 _("statement list doesn't fit in .debug_line section"));
1991 dwarf2_debug_line_missing_file_complaint (void)
1993 complaint (&symfile_complaints
,
1994 _(".debug_line section has line data without a file"));
1998 dwarf2_debug_line_missing_end_sequence_complaint (void)
2000 complaint (&symfile_complaints
,
2001 _(".debug_line section has line "
2002 "program sequence without an end"));
2006 dwarf2_complex_location_expr_complaint (void)
2008 complaint (&symfile_complaints
, _("location expression too complex"));
2012 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
2015 complaint (&symfile_complaints
,
2016 _("const value length mismatch for '%s', got %d, expected %d"),
2021 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
2023 complaint (&symfile_complaints
,
2024 _("debug info runs off end of %s section"
2026 get_section_name (section
),
2027 get_section_file_name (section
));
2031 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
2033 complaint (&symfile_complaints
,
2034 _("macro debug info contains a "
2035 "malformed macro definition:\n`%s'"),
2040 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
2042 complaint (&symfile_complaints
,
2043 _("invalid attribute class or form for '%s' in '%s'"),
2047 /* Hash function for line_header_hash. */
2050 line_header_hash (const struct line_header
*ofs
)
2052 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
2055 /* Hash function for htab_create_alloc_ex for line_header_hash. */
2058 line_header_hash_voidp (const void *item
)
2060 const struct line_header
*ofs
= (const struct line_header
*) item
;
2062 return line_header_hash (ofs
);
2065 /* Equality function for line_header_hash. */
2068 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
2070 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
2071 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
2073 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
2074 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
2079 /* Read the given attribute value as an address, taking the attribute's
2080 form into account. */
2083 attr_value_as_address (struct attribute
*attr
)
2087 if (attr
->form
!= DW_FORM_addr
&& attr
->form
!= DW_FORM_GNU_addr_index
)
2089 /* Aside from a few clearly defined exceptions, attributes that
2090 contain an address must always be in DW_FORM_addr form.
2091 Unfortunately, some compilers happen to be violating this
2092 requirement by encoding addresses using other forms, such
2093 as DW_FORM_data4 for example. For those broken compilers,
2094 we try to do our best, without any guarantee of success,
2095 to interpret the address correctly. It would also be nice
2096 to generate a complaint, but that would require us to maintain
2097 a list of legitimate cases where a non-address form is allowed,
2098 as well as update callers to pass in at least the CU's DWARF
2099 version. This is more overhead than what we're willing to
2100 expand for a pretty rare case. */
2101 addr
= DW_UNSND (attr
);
2104 addr
= DW_ADDR (attr
);
2109 /* See declaration. */
2111 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
2112 const dwarf2_debug_sections
*names
)
2113 : objfile (objfile_
)
2116 names
= &dwarf2_elf_names
;
2118 bfd
*obfd
= objfile
->obfd
;
2120 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2121 locate_sections (obfd
, sec
, *names
);
2124 static void free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
);
2126 dwarf2_per_objfile::~dwarf2_per_objfile ()
2128 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
2129 free_cached_comp_units ();
2131 if (quick_file_names_table
)
2132 htab_delete (quick_file_names_table
);
2134 if (line_header_hash
)
2135 htab_delete (line_header_hash
);
2137 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
2138 VEC_free (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
);
2140 for (signatured_type
*sig_type
: all_type_units
)
2141 VEC_free (dwarf2_per_cu_ptr
, sig_type
->per_cu
.imported_symtabs
);
2143 VEC_free (dwarf2_section_info_def
, types
);
2145 if (dwo_files
!= NULL
)
2146 free_dwo_files (dwo_files
, objfile
);
2147 if (dwp_file
!= NULL
)
2148 gdb_bfd_unref (dwp_file
->dbfd
);
2150 if (dwz_file
!= NULL
&& dwz_file
->dwz_bfd
)
2151 gdb_bfd_unref (dwz_file
->dwz_bfd
);
2153 if (index_table
!= NULL
)
2154 index_table
->~mapped_index ();
2156 /* Everything else should be on the objfile obstack. */
2159 /* See declaration. */
2162 dwarf2_per_objfile::free_cached_comp_units ()
2164 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
2165 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
2166 while (per_cu
!= NULL
)
2168 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
2171 *last_chain
= next_cu
;
2176 /* A helper class that calls free_cached_comp_units on
2179 class free_cached_comp_units
2183 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
2184 : m_per_objfile (per_objfile
)
2188 ~free_cached_comp_units ()
2190 m_per_objfile
->free_cached_comp_units ();
2193 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
2197 dwarf2_per_objfile
*m_per_objfile
;
2200 /* Try to locate the sections we need for DWARF 2 debugging
2201 information and return true if we have enough to do something.
2202 NAMES points to the dwarf2 section names, or is NULL if the standard
2203 ELF names are used. */
2206 dwarf2_has_info (struct objfile
*objfile
,
2207 const struct dwarf2_debug_sections
*names
)
2209 if (objfile
->flags
& OBJF_READNEVER
)
2212 struct dwarf2_per_objfile
*dwarf2_per_objfile
2213 = get_dwarf2_per_objfile (objfile
);
2215 if (dwarf2_per_objfile
== NULL
)
2217 /* Initialize per-objfile state. */
2219 = new (&objfile
->objfile_obstack
) struct dwarf2_per_objfile (objfile
,
2221 set_dwarf2_per_objfile (objfile
, dwarf2_per_objfile
);
2223 return (!dwarf2_per_objfile
->info
.is_virtual
2224 && dwarf2_per_objfile
->info
.s
.section
!= NULL
2225 && !dwarf2_per_objfile
->abbrev
.is_virtual
2226 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
2229 /* Return the containing section of virtual section SECTION. */
2231 static struct dwarf2_section_info
*
2232 get_containing_section (const struct dwarf2_section_info
*section
)
2234 gdb_assert (section
->is_virtual
);
2235 return section
->s
.containing_section
;
2238 /* Return the bfd owner of SECTION. */
2241 get_section_bfd_owner (const struct dwarf2_section_info
*section
)
2243 if (section
->is_virtual
)
2245 section
= get_containing_section (section
);
2246 gdb_assert (!section
->is_virtual
);
2248 return section
->s
.section
->owner
;
2251 /* Return the bfd section of SECTION.
2252 Returns NULL if the section is not present. */
2255 get_section_bfd_section (const struct dwarf2_section_info
*section
)
2257 if (section
->is_virtual
)
2259 section
= get_containing_section (section
);
2260 gdb_assert (!section
->is_virtual
);
2262 return section
->s
.section
;
2265 /* Return the name of SECTION. */
2268 get_section_name (const struct dwarf2_section_info
*section
)
2270 asection
*sectp
= get_section_bfd_section (section
);
2272 gdb_assert (sectp
!= NULL
);
2273 return bfd_section_name (get_section_bfd_owner (section
), sectp
);
2276 /* Return the name of the file SECTION is in. */
2279 get_section_file_name (const struct dwarf2_section_info
*section
)
2281 bfd
*abfd
= get_section_bfd_owner (section
);
2283 return bfd_get_filename (abfd
);
2286 /* Return the id of SECTION.
2287 Returns 0 if SECTION doesn't exist. */
2290 get_section_id (const struct dwarf2_section_info
*section
)
2292 asection
*sectp
= get_section_bfd_section (section
);
2299 /* Return the flags of SECTION.
2300 SECTION (or containing section if this is a virtual section) must exist. */
2303 get_section_flags (const struct dwarf2_section_info
*section
)
2305 asection
*sectp
= get_section_bfd_section (section
);
2307 gdb_assert (sectp
!= NULL
);
2308 return bfd_get_section_flags (sectp
->owner
, sectp
);
2311 /* When loading sections, we look either for uncompressed section or for
2312 compressed section names. */
2315 section_is_p (const char *section_name
,
2316 const struct dwarf2_section_names
*names
)
2318 if (names
->normal
!= NULL
2319 && strcmp (section_name
, names
->normal
) == 0)
2321 if (names
->compressed
!= NULL
2322 && strcmp (section_name
, names
->compressed
) == 0)
2327 /* See declaration. */
2330 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
2331 const dwarf2_debug_sections
&names
)
2333 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
2335 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2338 else if (section_is_p (sectp
->name
, &names
.info
))
2340 this->info
.s
.section
= sectp
;
2341 this->info
.size
= bfd_get_section_size (sectp
);
2343 else if (section_is_p (sectp
->name
, &names
.abbrev
))
2345 this->abbrev
.s
.section
= sectp
;
2346 this->abbrev
.size
= bfd_get_section_size (sectp
);
2348 else if (section_is_p (sectp
->name
, &names
.line
))
2350 this->line
.s
.section
= sectp
;
2351 this->line
.size
= bfd_get_section_size (sectp
);
2353 else if (section_is_p (sectp
->name
, &names
.loc
))
2355 this->loc
.s
.section
= sectp
;
2356 this->loc
.size
= bfd_get_section_size (sectp
);
2358 else if (section_is_p (sectp
->name
, &names
.loclists
))
2360 this->loclists
.s
.section
= sectp
;
2361 this->loclists
.size
= bfd_get_section_size (sectp
);
2363 else if (section_is_p (sectp
->name
, &names
.macinfo
))
2365 this->macinfo
.s
.section
= sectp
;
2366 this->macinfo
.size
= bfd_get_section_size (sectp
);
2368 else if (section_is_p (sectp
->name
, &names
.macro
))
2370 this->macro
.s
.section
= sectp
;
2371 this->macro
.size
= bfd_get_section_size (sectp
);
2373 else if (section_is_p (sectp
->name
, &names
.str
))
2375 this->str
.s
.section
= sectp
;
2376 this->str
.size
= bfd_get_section_size (sectp
);
2378 else if (section_is_p (sectp
->name
, &names
.line_str
))
2380 this->line_str
.s
.section
= sectp
;
2381 this->line_str
.size
= bfd_get_section_size (sectp
);
2383 else if (section_is_p (sectp
->name
, &names
.addr
))
2385 this->addr
.s
.section
= sectp
;
2386 this->addr
.size
= bfd_get_section_size (sectp
);
2388 else if (section_is_p (sectp
->name
, &names
.frame
))
2390 this->frame
.s
.section
= sectp
;
2391 this->frame
.size
= bfd_get_section_size (sectp
);
2393 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2395 this->eh_frame
.s
.section
= sectp
;
2396 this->eh_frame
.size
= bfd_get_section_size (sectp
);
2398 else if (section_is_p (sectp
->name
, &names
.ranges
))
2400 this->ranges
.s
.section
= sectp
;
2401 this->ranges
.size
= bfd_get_section_size (sectp
);
2403 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2405 this->rnglists
.s
.section
= sectp
;
2406 this->rnglists
.size
= bfd_get_section_size (sectp
);
2408 else if (section_is_p (sectp
->name
, &names
.types
))
2410 struct dwarf2_section_info type_section
;
2412 memset (&type_section
, 0, sizeof (type_section
));
2413 type_section
.s
.section
= sectp
;
2414 type_section
.size
= bfd_get_section_size (sectp
);
2416 VEC_safe_push (dwarf2_section_info_def
, this->types
,
2419 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2421 this->gdb_index
.s
.section
= sectp
;
2422 this->gdb_index
.size
= bfd_get_section_size (sectp
);
2424 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2426 this->debug_names
.s
.section
= sectp
;
2427 this->debug_names
.size
= bfd_get_section_size (sectp
);
2429 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2431 this->debug_aranges
.s
.section
= sectp
;
2432 this->debug_aranges
.size
= bfd_get_section_size (sectp
);
2435 if ((bfd_get_section_flags (abfd
, sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2436 && bfd_section_vma (abfd
, sectp
) == 0)
2437 this->has_section_at_zero
= true;
2440 /* A helper function that decides whether a section is empty,
2444 dwarf2_section_empty_p (const struct dwarf2_section_info
*section
)
2446 if (section
->is_virtual
)
2447 return section
->size
== 0;
2448 return section
->s
.section
== NULL
|| section
->size
== 0;
2451 /* See dwarf2read.h. */
2454 dwarf2_read_section (struct objfile
*objfile
, dwarf2_section_info
*info
)
2458 gdb_byte
*buf
, *retbuf
;
2462 info
->buffer
= NULL
;
2465 if (dwarf2_section_empty_p (info
))
2468 sectp
= get_section_bfd_section (info
);
2470 /* If this is a virtual section we need to read in the real one first. */
2471 if (info
->is_virtual
)
2473 struct dwarf2_section_info
*containing_section
=
2474 get_containing_section (info
);
2476 gdb_assert (sectp
!= NULL
);
2477 if ((sectp
->flags
& SEC_RELOC
) != 0)
2479 error (_("Dwarf Error: DWP format V2 with relocations is not"
2480 " supported in section %s [in module %s]"),
2481 get_section_name (info
), get_section_file_name (info
));
2483 dwarf2_read_section (objfile
, containing_section
);
2484 /* Other code should have already caught virtual sections that don't
2486 gdb_assert (info
->virtual_offset
+ info
->size
2487 <= containing_section
->size
);
2488 /* If the real section is empty or there was a problem reading the
2489 section we shouldn't get here. */
2490 gdb_assert (containing_section
->buffer
!= NULL
);
2491 info
->buffer
= containing_section
->buffer
+ info
->virtual_offset
;
2495 /* If the section has relocations, we must read it ourselves.
2496 Otherwise we attach it to the BFD. */
2497 if ((sectp
->flags
& SEC_RELOC
) == 0)
2499 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
2503 buf
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
2506 /* When debugging .o files, we may need to apply relocations; see
2507 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2508 We never compress sections in .o files, so we only need to
2509 try this when the section is not compressed. */
2510 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
2513 info
->buffer
= retbuf
;
2517 abfd
= get_section_bfd_owner (info
);
2518 gdb_assert (abfd
!= NULL
);
2520 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
2521 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
2523 error (_("Dwarf Error: Can't read DWARF data"
2524 " in section %s [in module %s]"),
2525 bfd_section_name (abfd
, sectp
), bfd_get_filename (abfd
));
2529 /* A helper function that returns the size of a section in a safe way.
2530 If you are positive that the section has been read before using the
2531 size, then it is safe to refer to the dwarf2_section_info object's
2532 "size" field directly. In other cases, you must call this
2533 function, because for compressed sections the size field is not set
2534 correctly until the section has been read. */
2536 static bfd_size_type
2537 dwarf2_section_size (struct objfile
*objfile
,
2538 struct dwarf2_section_info
*info
)
2541 dwarf2_read_section (objfile
, info
);
2545 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2549 dwarf2_get_section_info (struct objfile
*objfile
,
2550 enum dwarf2_section_enum sect
,
2551 asection
**sectp
, const gdb_byte
**bufp
,
2552 bfd_size_type
*sizep
)
2554 struct dwarf2_per_objfile
*data
2555 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
2556 dwarf2_objfile_data_key
);
2557 struct dwarf2_section_info
*info
;
2559 /* We may see an objfile without any DWARF, in which case we just
2570 case DWARF2_DEBUG_FRAME
:
2571 info
= &data
->frame
;
2573 case DWARF2_EH_FRAME
:
2574 info
= &data
->eh_frame
;
2577 gdb_assert_not_reached ("unexpected section");
2580 dwarf2_read_section (objfile
, info
);
2582 *sectp
= get_section_bfd_section (info
);
2583 *bufp
= info
->buffer
;
2584 *sizep
= info
->size
;
2587 /* A helper function to find the sections for a .dwz file. */
2590 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2592 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2594 /* Note that we only support the standard ELF names, because .dwz
2595 is ELF-only (at the time of writing). */
2596 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2598 dwz_file
->abbrev
.s
.section
= sectp
;
2599 dwz_file
->abbrev
.size
= bfd_get_section_size (sectp
);
2601 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2603 dwz_file
->info
.s
.section
= sectp
;
2604 dwz_file
->info
.size
= bfd_get_section_size (sectp
);
2606 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2608 dwz_file
->str
.s
.section
= sectp
;
2609 dwz_file
->str
.size
= bfd_get_section_size (sectp
);
2611 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2613 dwz_file
->line
.s
.section
= sectp
;
2614 dwz_file
->line
.size
= bfd_get_section_size (sectp
);
2616 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2618 dwz_file
->macro
.s
.section
= sectp
;
2619 dwz_file
->macro
.size
= bfd_get_section_size (sectp
);
2621 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2623 dwz_file
->gdb_index
.s
.section
= sectp
;
2624 dwz_file
->gdb_index
.size
= bfd_get_section_size (sectp
);
2626 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2628 dwz_file
->debug_names
.s
.section
= sectp
;
2629 dwz_file
->debug_names
.size
= bfd_get_section_size (sectp
);
2633 /* Open the separate '.dwz' debug file, if needed. Return NULL if
2634 there is no .gnu_debugaltlink section in the file. Error if there
2635 is such a section but the file cannot be found. */
2637 static struct dwz_file
*
2638 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2640 const char *filename
;
2641 struct dwz_file
*result
;
2642 bfd_size_type buildid_len_arg
;
2646 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2647 return dwarf2_per_objfile
->dwz_file
;
2649 bfd_set_error (bfd_error_no_error
);
2650 gdb::unique_xmalloc_ptr
<char> data
2651 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2652 &buildid_len_arg
, &buildid
));
2655 if (bfd_get_error () == bfd_error_no_error
)
2657 error (_("could not read '.gnu_debugaltlink' section: %s"),
2658 bfd_errmsg (bfd_get_error ()));
2661 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2663 buildid_len
= (size_t) buildid_len_arg
;
2665 filename
= data
.get ();
2667 std::string abs_storage
;
2668 if (!IS_ABSOLUTE_PATH (filename
))
2670 gdb::unique_xmalloc_ptr
<char> abs
2671 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2673 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2674 filename
= abs_storage
.c_str ();
2677 /* First try the file name given in the section. If that doesn't
2678 work, try to use the build-id instead. */
2679 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2680 if (dwz_bfd
!= NULL
)
2682 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2686 if (dwz_bfd
== NULL
)
2687 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2689 if (dwz_bfd
== NULL
)
2690 error (_("could not find '.gnu_debugaltlink' file for %s"),
2691 objfile_name (dwarf2_per_objfile
->objfile
));
2693 result
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
2695 result
->dwz_bfd
= dwz_bfd
.release ();
2697 bfd_map_over_sections (result
->dwz_bfd
, locate_dwz_sections
, result
);
2699 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, result
->dwz_bfd
);
2700 dwarf2_per_objfile
->dwz_file
= result
;
2704 /* DWARF quick_symbols_functions support. */
2706 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2707 unique line tables, so we maintain a separate table of all .debug_line
2708 derived entries to support the sharing.
2709 All the quick functions need is the list of file names. We discard the
2710 line_header when we're done and don't need to record it here. */
2711 struct quick_file_names
2713 /* The data used to construct the hash key. */
2714 struct stmt_list_hash hash
;
2716 /* The number of entries in file_names, real_names. */
2717 unsigned int num_file_names
;
2719 /* The file names from the line table, after being run through
2721 const char **file_names
;
2723 /* The file names from the line table after being run through
2724 gdb_realpath. These are computed lazily. */
2725 const char **real_names
;
2728 /* When using the index (and thus not using psymtabs), each CU has an
2729 object of this type. This is used to hold information needed by
2730 the various "quick" methods. */
2731 struct dwarf2_per_cu_quick_data
2733 /* The file table. This can be NULL if there was no file table
2734 or it's currently not read in.
2735 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2736 struct quick_file_names
*file_names
;
2738 /* The corresponding symbol table. This is NULL if symbols for this
2739 CU have not yet been read. */
2740 struct compunit_symtab
*compunit_symtab
;
2742 /* A temporary mark bit used when iterating over all CUs in
2743 expand_symtabs_matching. */
2744 unsigned int mark
: 1;
2746 /* True if we've tried to read the file table and found there isn't one.
2747 There will be no point in trying to read it again next time. */
2748 unsigned int no_file_data
: 1;
2751 /* Utility hash function for a stmt_list_hash. */
2754 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2758 if (stmt_list_hash
->dwo_unit
!= NULL
)
2759 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2760 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2764 /* Utility equality function for a stmt_list_hash. */
2767 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2768 const struct stmt_list_hash
*rhs
)
2770 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2772 if (lhs
->dwo_unit
!= NULL
2773 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2776 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2779 /* Hash function for a quick_file_names. */
2782 hash_file_name_entry (const void *e
)
2784 const struct quick_file_names
*file_data
2785 = (const struct quick_file_names
*) e
;
2787 return hash_stmt_list_entry (&file_data
->hash
);
2790 /* Equality function for a quick_file_names. */
2793 eq_file_name_entry (const void *a
, const void *b
)
2795 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2796 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2798 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2801 /* Delete function for a quick_file_names. */
2804 delete_file_name_entry (void *e
)
2806 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2809 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2811 xfree ((void*) file_data
->file_names
[i
]);
2812 if (file_data
->real_names
)
2813 xfree ((void*) file_data
->real_names
[i
]);
2816 /* The space for the struct itself lives on objfile_obstack,
2817 so we don't free it here. */
2820 /* Create a quick_file_names hash table. */
2823 create_quick_file_names_table (unsigned int nr_initial_entries
)
2825 return htab_create_alloc (nr_initial_entries
,
2826 hash_file_name_entry
, eq_file_name_entry
,
2827 delete_file_name_entry
, xcalloc
, xfree
);
2830 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2831 have to be created afterwards. You should call age_cached_comp_units after
2832 processing PER_CU->CU. dw2_setup must have been already called. */
2835 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2837 if (per_cu
->is_debug_types
)
2838 load_full_type_unit (per_cu
);
2840 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2842 if (per_cu
->cu
== NULL
)
2843 return; /* Dummy CU. */
2845 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2848 /* Read in the symbols for PER_CU. */
2851 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2853 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2855 /* Skip type_unit_groups, reading the type units they contain
2856 is handled elsewhere. */
2857 if (IS_TYPE_UNIT_GROUP (per_cu
))
2860 /* The destructor of dwarf2_queue_guard frees any entries left on
2861 the queue. After this point we're guaranteed to leave this function
2862 with the dwarf queue empty. */
2863 dwarf2_queue_guard q_guard
;
2865 if (dwarf2_per_objfile
->using_index
2866 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2867 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2869 queue_comp_unit (per_cu
, language_minimal
);
2870 load_cu (per_cu
, skip_partial
);
2872 /* If we just loaded a CU from a DWO, and we're working with an index
2873 that may badly handle TUs, load all the TUs in that DWO as well.
2874 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2875 if (!per_cu
->is_debug_types
2876 && per_cu
->cu
!= NULL
2877 && per_cu
->cu
->dwo_unit
!= NULL
2878 && dwarf2_per_objfile
->index_table
!= NULL
2879 && dwarf2_per_objfile
->index_table
->version
<= 7
2880 /* DWP files aren't supported yet. */
2881 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2882 queue_and_load_all_dwo_tus (per_cu
);
2885 process_queue (dwarf2_per_objfile
);
2887 /* Age the cache, releasing compilation units that have not
2888 been used recently. */
2889 age_cached_comp_units (dwarf2_per_objfile
);
2892 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2893 the objfile from which this CU came. Returns the resulting symbol
2896 static struct compunit_symtab
*
2897 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2899 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2901 gdb_assert (dwarf2_per_objfile
->using_index
);
2902 if (!per_cu
->v
.quick
->compunit_symtab
)
2904 free_cached_comp_units
freer (dwarf2_per_objfile
);
2905 scoped_restore decrementer
= increment_reading_symtab ();
2906 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2907 process_cu_includes (dwarf2_per_objfile
);
2910 return per_cu
->v
.quick
->compunit_symtab
;
2913 /* See declaration. */
2915 dwarf2_per_cu_data
*
2916 dwarf2_per_objfile::get_cutu (int index
)
2918 if (index
>= this->all_comp_units
.size ())
2920 index
-= this->all_comp_units
.size ();
2921 gdb_assert (index
< this->all_type_units
.size ());
2922 return &this->all_type_units
[index
]->per_cu
;
2925 return this->all_comp_units
[index
];
2928 /* See declaration. */
2930 dwarf2_per_cu_data
*
2931 dwarf2_per_objfile::get_cu (int index
)
2933 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2935 return this->all_comp_units
[index
];
2938 /* See declaration. */
2941 dwarf2_per_objfile::get_tu (int index
)
2943 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2945 return this->all_type_units
[index
];
2948 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2949 objfile_obstack, and constructed with the specified field
2952 static dwarf2_per_cu_data
*
2953 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2954 struct dwarf2_section_info
*section
,
2956 sect_offset sect_off
, ULONGEST length
)
2958 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2959 dwarf2_per_cu_data
*the_cu
2960 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2961 struct dwarf2_per_cu_data
);
2962 the_cu
->sect_off
= sect_off
;
2963 the_cu
->length
= length
;
2964 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2965 the_cu
->section
= section
;
2966 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2967 struct dwarf2_per_cu_quick_data
);
2968 the_cu
->is_dwz
= is_dwz
;
2972 /* A helper for create_cus_from_index that handles a given list of
2976 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2977 const gdb_byte
*cu_list
, offset_type n_elements
,
2978 struct dwarf2_section_info
*section
,
2981 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2983 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2985 sect_offset sect_off
2986 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2987 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2990 dwarf2_per_cu_data
*per_cu
2991 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
2993 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
2997 /* Read the CU list from the mapped index, and use it to create all
2998 the CU objects for this objfile. */
3001 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3002 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
3003 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
3005 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
3006 dwarf2_per_objfile
->all_comp_units
.reserve
3007 ((cu_list_elements
+ dwz_elements
) / 2);
3009 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3010 &dwarf2_per_objfile
->info
, 0);
3012 if (dwz_elements
== 0)
3015 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3016 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
3020 /* Create the signatured type hash table from the index. */
3023 create_signatured_type_table_from_index
3024 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3025 struct dwarf2_section_info
*section
,
3026 const gdb_byte
*bytes
,
3027 offset_type elements
)
3029 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3031 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
3032 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
3034 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3036 for (offset_type i
= 0; i
< elements
; i
+= 3)
3038 struct signatured_type
*sig_type
;
3041 cu_offset type_offset_in_tu
;
3043 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3044 sect_offset sect_off
3045 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
3047 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
3049 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
3052 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3053 struct signatured_type
);
3054 sig_type
->signature
= signature
;
3055 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3056 sig_type
->per_cu
.is_debug_types
= 1;
3057 sig_type
->per_cu
.section
= section
;
3058 sig_type
->per_cu
.sect_off
= sect_off
;
3059 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3060 sig_type
->per_cu
.v
.quick
3061 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3062 struct dwarf2_per_cu_quick_data
);
3064 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3067 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
3070 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3073 /* Create the signatured type hash table from .debug_names. */
3076 create_signatured_type_table_from_debug_names
3077 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3078 const mapped_debug_names
&map
,
3079 struct dwarf2_section_info
*section
,
3080 struct dwarf2_section_info
*abbrev_section
)
3082 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3084 dwarf2_read_section (objfile
, section
);
3085 dwarf2_read_section (objfile
, abbrev_section
);
3087 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
3088 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
3090 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3092 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
3094 struct signatured_type
*sig_type
;
3097 sect_offset sect_off
3098 = (sect_offset
) (extract_unsigned_integer
3099 (map
.tu_table_reordered
+ i
* map
.offset_size
,
3101 map
.dwarf5_byte_order
));
3103 comp_unit_head cu_header
;
3104 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
3106 section
->buffer
+ to_underlying (sect_off
),
3109 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3110 struct signatured_type
);
3111 sig_type
->signature
= cu_header
.signature
;
3112 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
3113 sig_type
->per_cu
.is_debug_types
= 1;
3114 sig_type
->per_cu
.section
= section
;
3115 sig_type
->per_cu
.sect_off
= sect_off
;
3116 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3117 sig_type
->per_cu
.v
.quick
3118 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3119 struct dwarf2_per_cu_quick_data
);
3121 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3124 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
3127 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3130 /* Read the address map data from the mapped index, and use it to
3131 populate the objfile's psymtabs_addrmap. */
3134 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3135 struct mapped_index
*index
)
3137 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3138 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3139 const gdb_byte
*iter
, *end
;
3140 struct addrmap
*mutable_map
;
3143 auto_obstack temp_obstack
;
3145 mutable_map
= addrmap_create_mutable (&temp_obstack
);
3147 iter
= index
->address_table
.data ();
3148 end
= iter
+ index
->address_table
.size ();
3150 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3154 ULONGEST hi
, lo
, cu_index
;
3155 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3157 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3159 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
3164 complaint (&symfile_complaints
,
3165 _(".gdb_index address table has invalid range (%s - %s)"),
3166 hex_string (lo
), hex_string (hi
));
3170 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
3172 complaint (&symfile_complaints
,
3173 _(".gdb_index address table has invalid CU number %u"),
3174 (unsigned) cu_index
);
3178 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
);
3179 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
);
3180 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
3181 dwarf2_per_objfile
->get_cu (cu_index
));
3184 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
3185 &objfile
->objfile_obstack
);
3188 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
3189 populate the objfile's psymtabs_addrmap. */
3192 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3193 struct dwarf2_section_info
*section
)
3195 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3196 bfd
*abfd
= objfile
->obfd
;
3197 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3198 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
3199 SECT_OFF_TEXT (objfile
));
3201 auto_obstack temp_obstack
;
3202 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
3204 std::unordered_map
<sect_offset
,
3205 dwarf2_per_cu_data
*,
3206 gdb::hash_enum
<sect_offset
>>
3207 debug_info_offset_to_per_cu
;
3208 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3210 const auto insertpair
3211 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
3212 if (!insertpair
.second
)
3214 warning (_("Section .debug_aranges in %s has duplicate "
3215 "debug_info_offset %s, ignoring .debug_aranges."),
3216 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
3221 dwarf2_read_section (objfile
, section
);
3223 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
3225 const gdb_byte
*addr
= section
->buffer
;
3227 while (addr
< section
->buffer
+ section
->size
)
3229 const gdb_byte
*const entry_addr
= addr
;
3230 unsigned int bytes_read
;
3232 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
3236 const gdb_byte
*const entry_end
= addr
+ entry_length
;
3237 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
3238 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
3239 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
3241 warning (_("Section .debug_aranges in %s entry at offset %zu "
3242 "length %s exceeds section length %s, "
3243 "ignoring .debug_aranges."),
3244 objfile_name (objfile
), entry_addr
- section
->buffer
,
3245 plongest (bytes_read
+ entry_length
),
3246 pulongest (section
->size
));
3250 /* The version number. */
3251 const uint16_t version
= read_2_bytes (abfd
, addr
);
3255 warning (_("Section .debug_aranges in %s entry at offset %zu "
3256 "has unsupported version %d, ignoring .debug_aranges."),
3257 objfile_name (objfile
), entry_addr
- section
->buffer
,
3262 const uint64_t debug_info_offset
3263 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
3264 addr
+= offset_size
;
3265 const auto per_cu_it
3266 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
3267 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
3269 warning (_("Section .debug_aranges in %s entry at offset %zu "
3270 "debug_info_offset %s does not exists, "
3271 "ignoring .debug_aranges."),
3272 objfile_name (objfile
), entry_addr
- section
->buffer
,
3273 pulongest (debug_info_offset
));
3276 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
3278 const uint8_t address_size
= *addr
++;
3279 if (address_size
< 1 || address_size
> 8)
3281 warning (_("Section .debug_aranges in %s entry at offset %zu "
3282 "address_size %u is invalid, ignoring .debug_aranges."),
3283 objfile_name (objfile
), entry_addr
- section
->buffer
,
3288 const uint8_t segment_selector_size
= *addr
++;
3289 if (segment_selector_size
!= 0)
3291 warning (_("Section .debug_aranges in %s entry at offset %zu "
3292 "segment_selector_size %u is not supported, "
3293 "ignoring .debug_aranges."),
3294 objfile_name (objfile
), entry_addr
- section
->buffer
,
3295 segment_selector_size
);
3299 /* Must pad to an alignment boundary that is twice the address
3300 size. It is undocumented by the DWARF standard but GCC does
3302 for (size_t padding
= ((-(addr
- section
->buffer
))
3303 & (2 * address_size
- 1));
3304 padding
> 0; padding
--)
3307 warning (_("Section .debug_aranges in %s entry at offset %zu "
3308 "padding is not zero, ignoring .debug_aranges."),
3309 objfile_name (objfile
), entry_addr
- section
->buffer
);
3315 if (addr
+ 2 * address_size
> entry_end
)
3317 warning (_("Section .debug_aranges in %s entry at offset %zu "
3318 "address list is not properly terminated, "
3319 "ignoring .debug_aranges."),
3320 objfile_name (objfile
), entry_addr
- section
->buffer
);
3323 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
3325 addr
+= address_size
;
3326 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
3328 addr
+= address_size
;
3329 if (start
== 0 && length
== 0)
3331 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3333 /* Symbol was eliminated due to a COMDAT group. */
3336 ULONGEST end
= start
+ length
;
3337 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
);
3338 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
);
3339 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
3343 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
3344 &objfile
->objfile_obstack
);
3347 /* Find a slot in the mapped index INDEX for the object named NAME.
3348 If NAME is found, set *VEC_OUT to point to the CU vector in the
3349 constant pool and return true. If NAME cannot be found, return
3353 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3354 offset_type
**vec_out
)
3357 offset_type slot
, step
;
3358 int (*cmp
) (const char *, const char *);
3360 gdb::unique_xmalloc_ptr
<char> without_params
;
3361 if (current_language
->la_language
== language_cplus
3362 || current_language
->la_language
== language_fortran
3363 || current_language
->la_language
== language_d
)
3365 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3368 if (strchr (name
, '(') != NULL
)
3370 without_params
= cp_remove_params (name
);
3372 if (without_params
!= NULL
)
3373 name
= without_params
.get ();
3377 /* Index version 4 did not support case insensitive searches. But the
3378 indices for case insensitive languages are built in lowercase, therefore
3379 simulate our NAME being searched is also lowercased. */
3380 hash
= mapped_index_string_hash ((index
->version
== 4
3381 && case_sensitivity
== case_sensitive_off
3382 ? 5 : index
->version
),
3385 slot
= hash
& (index
->symbol_table
.size () - 1);
3386 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
3387 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3393 const auto &bucket
= index
->symbol_table
[slot
];
3394 if (bucket
.name
== 0 && bucket
.vec
== 0)
3397 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
3398 if (!cmp (name
, str
))
3400 *vec_out
= (offset_type
*) (index
->constant_pool
3401 + MAYBE_SWAP (bucket
.vec
));
3405 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
3409 /* A helper function that reads the .gdb_index from SECTION and fills
3410 in MAP. FILENAME is the name of the file containing the section;
3411 it is used for error reporting. DEPRECATED_OK is true if it is
3412 ok to use deprecated sections.
3414 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3415 out parameters that are filled in with information about the CU and
3416 TU lists in the section.
3418 Returns 1 if all went well, 0 otherwise. */
3421 read_index_from_section (struct objfile
*objfile
,
3422 const char *filename
,
3424 struct dwarf2_section_info
*section
,
3425 struct mapped_index
*map
,
3426 const gdb_byte
**cu_list
,
3427 offset_type
*cu_list_elements
,
3428 const gdb_byte
**types_list
,
3429 offset_type
*types_list_elements
)
3431 const gdb_byte
*addr
;
3432 offset_type version
;
3433 offset_type
*metadata
;
3436 if (dwarf2_section_empty_p (section
))
3439 /* Older elfutils strip versions could keep the section in the main
3440 executable while splitting it for the separate debug info file. */
3441 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
3444 dwarf2_read_section (objfile
, section
);
3446 addr
= section
->buffer
;
3447 /* Version check. */
3448 version
= MAYBE_SWAP (*(offset_type
*) addr
);
3449 /* Versions earlier than 3 emitted every copy of a psymbol. This
3450 causes the index to behave very poorly for certain requests. Version 3
3451 contained incomplete addrmap. So, it seems better to just ignore such
3455 static int warning_printed
= 0;
3456 if (!warning_printed
)
3458 warning (_("Skipping obsolete .gdb_index section in %s."),
3460 warning_printed
= 1;
3464 /* Index version 4 uses a different hash function than index version
3467 Versions earlier than 6 did not emit psymbols for inlined
3468 functions. Using these files will cause GDB not to be able to
3469 set breakpoints on inlined functions by name, so we ignore these
3470 indices unless the user has done
3471 "set use-deprecated-index-sections on". */
3472 if (version
< 6 && !deprecated_ok
)
3474 static int warning_printed
= 0;
3475 if (!warning_printed
)
3478 Skipping deprecated .gdb_index section in %s.\n\
3479 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3480 to use the section anyway."),
3482 warning_printed
= 1;
3486 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3487 of the TU (for symbols coming from TUs),
3488 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3489 Plus gold-generated indices can have duplicate entries for global symbols,
3490 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3491 These are just performance bugs, and we can't distinguish gdb-generated
3492 indices from gold-generated ones, so issue no warning here. */
3494 /* Indexes with higher version than the one supported by GDB may be no
3495 longer backward compatible. */
3499 map
->version
= version
;
3501 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3504 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3505 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3509 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3510 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3511 - MAYBE_SWAP (metadata
[i
]))
3515 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3516 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3518 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3521 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3522 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3524 = gdb::array_view
<mapped_index::symbol_table_slot
>
3525 ((mapped_index::symbol_table_slot
*) symbol_table
,
3526 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3529 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3534 /* Read .gdb_index. If everything went ok, initialize the "quick"
3535 elements of all the CUs and return 1. Otherwise, return 0. */
3538 dwarf2_read_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
3540 struct mapped_index local_map
, *map
;
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 if (!read_index_from_section (objfile
, objfile_name (objfile
),
3547 use_deprecated_index_sections
,
3548 &dwarf2_per_objfile
->gdb_index
, &local_map
,
3549 &cu_list
, &cu_list_elements
,
3550 &types_list
, &types_list_elements
))
3553 /* Don't use the index if it's empty. */
3554 if (local_map
.symbol_table
.empty ())
3557 /* If there is a .dwz file, read it so we can get its CU list as
3559 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3562 struct mapped_index dwz_map
;
3563 const gdb_byte
*dwz_types_ignore
;
3564 offset_type dwz_types_elements_ignore
;
3566 if (!read_index_from_section (objfile
, bfd_get_filename (dwz
->dwz_bfd
),
3568 &dwz
->gdb_index
, &dwz_map
,
3569 &dwz_list
, &dwz_list_elements
,
3571 &dwz_types_elements_ignore
))
3573 warning (_("could not read '.gdb_index' section from %s; skipping"),
3574 bfd_get_filename (dwz
->dwz_bfd
));
3579 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3580 dwz_list
, dwz_list_elements
);
3582 if (types_list_elements
)
3584 struct dwarf2_section_info
*section
;
3586 /* We can only handle a single .debug_types when we have an
3588 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
3591 section
= VEC_index (dwarf2_section_info_def
,
3592 dwarf2_per_objfile
->types
, 0);
3594 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3595 types_list
, types_list_elements
);
3598 create_addrmap_from_index (dwarf2_per_objfile
, &local_map
);
3600 map
= XOBNEW (&objfile
->objfile_obstack
, struct mapped_index
);
3601 map
= new (map
) mapped_index ();
3604 dwarf2_per_objfile
->index_table
= map
;
3605 dwarf2_per_objfile
->using_index
= 1;
3606 dwarf2_per_objfile
->quick_file_names_table
=
3607 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3612 /* die_reader_func for dw2_get_file_names. */
3615 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3616 const gdb_byte
*info_ptr
,
3617 struct die_info
*comp_unit_die
,
3621 struct dwarf2_cu
*cu
= reader
->cu
;
3622 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3623 struct dwarf2_per_objfile
*dwarf2_per_objfile
3624 = cu
->per_cu
->dwarf2_per_objfile
;
3625 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3626 struct dwarf2_per_cu_data
*lh_cu
;
3627 struct attribute
*attr
;
3630 struct quick_file_names
*qfn
;
3632 gdb_assert (! this_cu
->is_debug_types
);
3634 /* Our callers never want to match partial units -- instead they
3635 will match the enclosing full CU. */
3636 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3638 this_cu
->v
.quick
->no_file_data
= 1;
3646 sect_offset line_offset
{};
3648 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3651 struct quick_file_names find_entry
;
3653 line_offset
= (sect_offset
) DW_UNSND (attr
);
3655 /* We may have already read in this line header (TU line header sharing).
3656 If we have we're done. */
3657 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3658 find_entry
.hash
.line_sect_off
= line_offset
;
3659 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
3660 &find_entry
, INSERT
);
3663 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3667 lh
= dwarf_decode_line_header (line_offset
, cu
);
3671 lh_cu
->v
.quick
->no_file_data
= 1;
3675 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3676 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3677 qfn
->hash
.line_sect_off
= line_offset
;
3678 gdb_assert (slot
!= NULL
);
3681 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3683 qfn
->num_file_names
= lh
->file_names
.size ();
3685 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, lh
->file_names
.size ());
3686 for (i
= 0; i
< lh
->file_names
.size (); ++i
)
3687 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
.get (), fnd
.comp_dir
);
3688 qfn
->real_names
= NULL
;
3690 lh_cu
->v
.quick
->file_names
= qfn
;
3693 /* A helper for the "quick" functions which attempts to read the line
3694 table for THIS_CU. */
3696 static struct quick_file_names
*
3697 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3699 /* This should never be called for TUs. */
3700 gdb_assert (! this_cu
->is_debug_types
);
3701 /* Nor type unit groups. */
3702 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3704 if (this_cu
->v
.quick
->file_names
!= NULL
)
3705 return this_cu
->v
.quick
->file_names
;
3706 /* If we know there is no line data, no point in looking again. */
3707 if (this_cu
->v
.quick
->no_file_data
)
3710 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
3712 if (this_cu
->v
.quick
->no_file_data
)
3714 return this_cu
->v
.quick
->file_names
;
3717 /* A helper for the "quick" functions which computes and caches the
3718 real path for a given file name from the line table. */
3721 dw2_get_real_path (struct objfile
*objfile
,
3722 struct quick_file_names
*qfn
, int index
)
3724 if (qfn
->real_names
== NULL
)
3725 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3726 qfn
->num_file_names
, const char *);
3728 if (qfn
->real_names
[index
] == NULL
)
3729 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3731 return qfn
->real_names
[index
];
3734 static struct symtab
*
3735 dw2_find_last_source_symtab (struct objfile
*objfile
)
3737 struct dwarf2_per_objfile
*dwarf2_per_objfile
3738 = get_dwarf2_per_objfile (objfile
);
3739 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3740 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3745 return compunit_primary_filetab (cust
);
3748 /* Traversal function for dw2_forget_cached_source_info. */
3751 dw2_free_cached_file_names (void **slot
, void *info
)
3753 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3755 if (file_data
->real_names
)
3759 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3761 xfree ((void*) file_data
->real_names
[i
]);
3762 file_data
->real_names
[i
] = NULL
;
3770 dw2_forget_cached_source_info (struct objfile
*objfile
)
3772 struct dwarf2_per_objfile
*dwarf2_per_objfile
3773 = get_dwarf2_per_objfile (objfile
);
3775 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3776 dw2_free_cached_file_names
, NULL
);
3779 /* Helper function for dw2_map_symtabs_matching_filename that expands
3780 the symtabs and calls the iterator. */
3783 dw2_map_expand_apply (struct objfile
*objfile
,
3784 struct dwarf2_per_cu_data
*per_cu
,
3785 const char *name
, const char *real_path
,
3786 gdb::function_view
<bool (symtab
*)> callback
)
3788 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3790 /* Don't visit already-expanded CUs. */
3791 if (per_cu
->v
.quick
->compunit_symtab
)
3794 /* This may expand more than one symtab, and we want to iterate over
3796 dw2_instantiate_symtab (per_cu
, false);
3798 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3799 last_made
, callback
);
3802 /* Implementation of the map_symtabs_matching_filename method. */
3805 dw2_map_symtabs_matching_filename
3806 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3807 gdb::function_view
<bool (symtab
*)> callback
)
3809 const char *name_basename
= lbasename (name
);
3810 struct dwarf2_per_objfile
*dwarf2_per_objfile
3811 = get_dwarf2_per_objfile (objfile
);
3813 /* The rule is CUs specify all the files, including those used by
3814 any TU, so there's no need to scan TUs here. */
3816 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3818 /* We only need to look at symtabs not already expanded. */
3819 if (per_cu
->v
.quick
->compunit_symtab
)
3822 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3823 if (file_data
== NULL
)
3826 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3828 const char *this_name
= file_data
->file_names
[j
];
3829 const char *this_real_name
;
3831 if (compare_filenames_for_search (this_name
, name
))
3833 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3839 /* Before we invoke realpath, which can get expensive when many
3840 files are involved, do a quick comparison of the basenames. */
3841 if (! basenames_may_differ
3842 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3845 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3846 if (compare_filenames_for_search (this_real_name
, name
))
3848 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3854 if (real_path
!= NULL
)
3856 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3857 gdb_assert (IS_ABSOLUTE_PATH (name
));
3858 if (this_real_name
!= NULL
3859 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3861 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3873 /* Struct used to manage iterating over all CUs looking for a symbol. */
3875 struct dw2_symtab_iterator
3877 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3878 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3879 /* If non-zero, only look for symbols that match BLOCK_INDEX. */
3880 int want_specific_block
;
3881 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
3882 Unused if !WANT_SPECIFIC_BLOCK. */
3884 /* The kind of symbol we're looking for. */
3886 /* The list of CUs from the index entry of the symbol,
3887 or NULL if not found. */
3889 /* The next element in VEC to look at. */
3891 /* The number of elements in VEC, or zero if there is no match. */
3893 /* Have we seen a global version of the symbol?
3894 If so we can ignore all further global instances.
3895 This is to work around gold/15646, inefficient gold-generated
3900 /* Initialize the index symtab iterator ITER.
3901 If WANT_SPECIFIC_BLOCK is non-zero, only look for symbols
3902 in block BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
3905 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3906 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3907 int want_specific_block
,
3912 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3913 iter
->want_specific_block
= want_specific_block
;
3914 iter
->block_index
= block_index
;
3915 iter
->domain
= domain
;
3917 iter
->global_seen
= 0;
3919 mapped_index
*index
= dwarf2_per_objfile
->index_table
;
3921 /* index is NULL if OBJF_READNOW. */
3922 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3923 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3931 /* Return the next matching CU or NULL if there are no more. */
3933 static struct dwarf2_per_cu_data
*
3934 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3936 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3938 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3940 offset_type cu_index_and_attrs
=
3941 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3942 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3943 int want_static
= iter
->block_index
!= GLOBAL_BLOCK
;
3944 /* This value is only valid for index versions >= 7. */
3945 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3946 gdb_index_symbol_kind symbol_kind
=
3947 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3948 /* Only check the symbol attributes if they're present.
3949 Indices prior to version 7 don't record them,
3950 and indices >= 7 may elide them for certain symbols
3951 (gold does this). */
3953 (dwarf2_per_objfile
->index_table
->version
>= 7
3954 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3956 /* Don't crash on bad data. */
3957 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
3958 + dwarf2_per_objfile
->all_type_units
.size ()))
3960 complaint (&symfile_complaints
,
3961 _(".gdb_index entry has bad CU index"
3963 objfile_name (dwarf2_per_objfile
->objfile
));
3967 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
3969 /* Skip if already read in. */
3970 if (per_cu
->v
.quick
->compunit_symtab
)
3973 /* Check static vs global. */
3976 if (iter
->want_specific_block
3977 && want_static
!= is_static
)
3979 /* Work around gold/15646. */
3980 if (!is_static
&& iter
->global_seen
)
3983 iter
->global_seen
= 1;
3986 /* Only check the symbol's kind if it has one. */
3989 switch (iter
->domain
)
3992 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3993 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3994 /* Some types are also in VAR_DOMAIN. */
3995 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3999 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4003 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4018 static struct compunit_symtab
*
4019 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
4020 const char *name
, domain_enum domain
)
4022 struct compunit_symtab
*stab_best
= NULL
;
4023 struct dwarf2_per_objfile
*dwarf2_per_objfile
4024 = get_dwarf2_per_objfile (objfile
);
4026 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
4028 struct dw2_symtab_iterator iter
;
4029 struct dwarf2_per_cu_data
*per_cu
;
4031 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, 1, block_index
, domain
, name
);
4033 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4035 struct symbol
*sym
, *with_opaque
= NULL
;
4036 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
4037 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
4038 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
4040 sym
= block_find_symbol (block
, name
, domain
,
4041 block_find_non_opaque_type_preferred
,
4044 /* Some caution must be observed with overloaded functions
4045 and methods, since the index will not contain any overload
4046 information (but NAME might contain it). */
4049 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
4051 if (with_opaque
!= NULL
4052 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
4055 /* Keep looking through other CUs. */
4062 dw2_print_stats (struct objfile
*objfile
)
4064 struct dwarf2_per_objfile
*dwarf2_per_objfile
4065 = get_dwarf2_per_objfile (objfile
);
4066 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
4067 + dwarf2_per_objfile
->all_type_units
.size ());
4070 for (int i
= 0; i
< total
; ++i
)
4072 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4074 if (!per_cu
->v
.quick
->compunit_symtab
)
4077 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
4078 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
4081 /* This dumps minimal information about the index.
4082 It is called via "mt print objfiles".
4083 One use is to verify .gdb_index has been loaded by the
4084 gdb.dwarf2/gdb-index.exp testcase. */
4087 dw2_dump (struct objfile
*objfile
)
4089 struct dwarf2_per_objfile
*dwarf2_per_objfile
4090 = get_dwarf2_per_objfile (objfile
);
4092 gdb_assert (dwarf2_per_objfile
->using_index
);
4093 printf_filtered (".gdb_index:");
4094 if (dwarf2_per_objfile
->index_table
!= NULL
)
4096 printf_filtered (" version %d\n",
4097 dwarf2_per_objfile
->index_table
->version
);
4100 printf_filtered (" faked for \"readnow\"\n");
4101 printf_filtered ("\n");
4105 dw2_relocate (struct objfile
*objfile
,
4106 const struct section_offsets
*new_offsets
,
4107 const struct section_offsets
*delta
)
4109 /* There's nothing to relocate here. */
4113 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
4114 const char *func_name
)
4116 struct dwarf2_per_objfile
*dwarf2_per_objfile
4117 = get_dwarf2_per_objfile (objfile
);
4119 struct dw2_symtab_iterator iter
;
4120 struct dwarf2_per_cu_data
*per_cu
;
4122 /* Note: It doesn't matter what we pass for block_index here. */
4123 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, 0, GLOBAL_BLOCK
, VAR_DOMAIN
,
4126 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4127 dw2_instantiate_symtab (per_cu
, false);
4132 dw2_expand_all_symtabs (struct objfile
*objfile
)
4134 struct dwarf2_per_objfile
*dwarf2_per_objfile
4135 = get_dwarf2_per_objfile (objfile
);
4136 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
4137 + dwarf2_per_objfile
->all_type_units
.size ());
4139 for (int i
= 0; i
< total_units
; ++i
)
4141 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4143 /* We don't want to directly expand a partial CU, because if we
4144 read it with the wrong language, then assertion failures can
4145 be triggered later on. See PR symtab/23010. So, tell
4146 dw2_instantiate_symtab to skip partial CUs -- any important
4147 partial CU will be read via DW_TAG_imported_unit anyway. */
4148 dw2_instantiate_symtab (per_cu
, true);
4153 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
4154 const char *fullname
)
4156 struct dwarf2_per_objfile
*dwarf2_per_objfile
4157 = get_dwarf2_per_objfile (objfile
);
4159 /* We don't need to consider type units here.
4160 This is only called for examining code, e.g. expand_line_sal.
4161 There can be an order of magnitude (or more) more type units
4162 than comp units, and we avoid them if we can. */
4164 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4166 /* We only need to look at symtabs not already expanded. */
4167 if (per_cu
->v
.quick
->compunit_symtab
)
4170 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4171 if (file_data
== NULL
)
4174 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4176 const char *this_fullname
= file_data
->file_names
[j
];
4178 if (filename_cmp (this_fullname
, fullname
) == 0)
4180 dw2_instantiate_symtab (per_cu
, false);
4188 dw2_map_matching_symbols (struct objfile
*objfile
,
4189 const char * name
, domain_enum domain
,
4191 int (*callback
) (struct block
*,
4192 struct symbol
*, void *),
4193 void *data
, symbol_name_match_type match
,
4194 symbol_compare_ftype
*ordered_compare
)
4196 /* Currently unimplemented; used for Ada. The function can be called if the
4197 current language is Ada for a non-Ada objfile using GNU index. As Ada
4198 does not look for non-Ada symbols this function should just return. */
4201 /* Symbol name matcher for .gdb_index names.
4203 Symbol names in .gdb_index have a few particularities:
4205 - There's no indication of which is the language of each symbol.
4207 Since each language has its own symbol name matching algorithm,
4208 and we don't know which language is the right one, we must match
4209 each symbol against all languages. This would be a potential
4210 performance problem if it were not mitigated by the
4211 mapped_index::name_components lookup table, which significantly
4212 reduces the number of times we need to call into this matcher,
4213 making it a non-issue.
4215 - Symbol names in the index have no overload (parameter)
4216 information. I.e., in C++, "foo(int)" and "foo(long)" both
4217 appear as "foo" in the index, for example.
4219 This means that the lookup names passed to the symbol name
4220 matcher functions must have no parameter information either
4221 because (e.g.) symbol search name "foo" does not match
4222 lookup-name "foo(int)" [while swapping search name for lookup
4225 class gdb_index_symbol_name_matcher
4228 /* Prepares the vector of comparison functions for LOOKUP_NAME. */
4229 gdb_index_symbol_name_matcher (const lookup_name_info
&lookup_name
);
4231 /* Walk all the matcher routines and match SYMBOL_NAME against them.
4232 Returns true if any matcher matches. */
4233 bool matches (const char *symbol_name
);
4236 /* A reference to the lookup name we're matching against. */
4237 const lookup_name_info
&m_lookup_name
;
4239 /* A vector holding all the different symbol name matchers, for all
4241 std::vector
<symbol_name_matcher_ftype
*> m_symbol_name_matcher_funcs
;
4244 gdb_index_symbol_name_matcher::gdb_index_symbol_name_matcher
4245 (const lookup_name_info
&lookup_name
)
4246 : m_lookup_name (lookup_name
)
4248 /* Prepare the vector of comparison functions upfront, to avoid
4249 doing the same work for each symbol. Care is taken to avoid
4250 matching with the same matcher more than once if/when multiple
4251 languages use the same matcher function. */
4252 auto &matchers
= m_symbol_name_matcher_funcs
;
4253 matchers
.reserve (nr_languages
);
4255 matchers
.push_back (default_symbol_name_matcher
);
4257 for (int i
= 0; i
< nr_languages
; i
++)
4259 const language_defn
*lang
= language_def ((enum language
) i
);
4260 symbol_name_matcher_ftype
*name_matcher
4261 = get_symbol_name_matcher (lang
, m_lookup_name
);
4263 /* Don't insert the same comparison routine more than once.
4264 Note that we do this linear walk instead of a seemingly
4265 cheaper sorted insert, or use a std::set or something like
4266 that, because relative order of function addresses is not
4267 stable. This is not a problem in practice because the number
4268 of supported languages is low, and the cost here is tiny
4269 compared to the number of searches we'll do afterwards using
4271 if (name_matcher
!= default_symbol_name_matcher
4272 && (std::find (matchers
.begin (), matchers
.end (), name_matcher
)
4273 == matchers
.end ()))
4274 matchers
.push_back (name_matcher
);
4279 gdb_index_symbol_name_matcher::matches (const char *symbol_name
)
4281 for (auto matches_name
: m_symbol_name_matcher_funcs
)
4282 if (matches_name (symbol_name
, m_lookup_name
, NULL
))
4288 /* Starting from a search name, return the string that finds the upper
4289 bound of all strings that start with SEARCH_NAME in a sorted name
4290 list. Returns the empty string to indicate that the upper bound is
4291 the end of the list. */
4294 make_sort_after_prefix_name (const char *search_name
)
4296 /* When looking to complete "func", we find the upper bound of all
4297 symbols that start with "func" by looking for where we'd insert
4298 the closest string that would follow "func" in lexicographical
4299 order. Usually, that's "func"-with-last-character-incremented,
4300 i.e. "fund". Mind non-ASCII characters, though. Usually those
4301 will be UTF-8 multi-byte sequences, but we can't be certain.
4302 Especially mind the 0xff character, which is a valid character in
4303 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
4304 rule out compilers allowing it in identifiers. Note that
4305 conveniently, strcmp/strcasecmp are specified to compare
4306 characters interpreted as unsigned char. So what we do is treat
4307 the whole string as a base 256 number composed of a sequence of
4308 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
4309 to 0, and carries 1 to the following more-significant position.
4310 If the very first character in SEARCH_NAME ends up incremented
4311 and carries/overflows, then the upper bound is the end of the
4312 list. The string after the empty string is also the empty
4315 Some examples of this operation:
4317 SEARCH_NAME => "+1" RESULT
4321 "\xff" "a" "\xff" => "\xff" "b"
4326 Then, with these symbols for example:
4332 completing "func" looks for symbols between "func" and
4333 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
4334 which finds "func" and "func1", but not "fund".
4338 funcÿ (Latin1 'ÿ' [0xff])
4342 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
4343 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
4347 ÿÿ (Latin1 'ÿ' [0xff])
4350 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
4351 the end of the list.
4353 std::string after
= search_name
;
4354 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
4356 if (!after
.empty ())
4357 after
.back () = (unsigned char) after
.back () + 1;
4361 /* See declaration. */
4363 std::pair
<std::vector
<name_component
>::const_iterator
,
4364 std::vector
<name_component
>::const_iterator
>
4365 mapped_index_base::find_name_components_bounds
4366 (const lookup_name_info
&lookup_name_without_params
) const
4369 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4372 = lookup_name_without_params
.cplus ().lookup_name ().c_str ();
4374 /* Comparison function object for lower_bound that matches against a
4375 given symbol name. */
4376 auto lookup_compare_lower
= [&] (const name_component
&elem
,
4379 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4380 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4381 return name_cmp (elem_name
, name
) < 0;
4384 /* Comparison function object for upper_bound that matches against a
4385 given symbol name. */
4386 auto lookup_compare_upper
= [&] (const char *name
,
4387 const name_component
&elem
)
4389 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4390 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4391 return name_cmp (name
, elem_name
) < 0;
4394 auto begin
= this->name_components
.begin ();
4395 auto end
= this->name_components
.end ();
4397 /* Find the lower bound. */
4400 if (lookup_name_without_params
.completion_mode () && cplus
[0] == '\0')
4403 return std::lower_bound (begin
, end
, cplus
, lookup_compare_lower
);
4406 /* Find the upper bound. */
4409 if (lookup_name_without_params
.completion_mode ())
4411 /* In completion mode, we want UPPER to point past all
4412 symbols names that have the same prefix. I.e., with
4413 these symbols, and completing "func":
4415 function << lower bound
4417 other_function << upper bound
4419 We find the upper bound by looking for the insertion
4420 point of "func"-with-last-character-incremented,
4422 std::string after
= make_sort_after_prefix_name (cplus
);
4425 return std::lower_bound (lower
, end
, after
.c_str (),
4426 lookup_compare_lower
);
4429 return std::upper_bound (lower
, end
, cplus
, lookup_compare_upper
);
4432 return {lower
, upper
};
4435 /* See declaration. */
4438 mapped_index_base::build_name_components ()
4440 if (!this->name_components
.empty ())
4443 this->name_components_casing
= case_sensitivity
;
4445 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4447 /* The code below only knows how to break apart components of C++
4448 symbol names (and other languages that use '::' as
4449 namespace/module separator). If we add support for wild matching
4450 to some language that uses some other operator (E.g., Ada, Go and
4451 D use '.'), then we'll need to try splitting the symbol name
4452 according to that language too. Note that Ada does support wild
4453 matching, but doesn't currently support .gdb_index. */
4454 auto count
= this->symbol_name_count ();
4455 for (offset_type idx
= 0; idx
< count
; idx
++)
4457 if (this->symbol_name_slot_invalid (idx
))
4460 const char *name
= this->symbol_name_at (idx
);
4462 /* Add each name component to the name component table. */
4463 unsigned int previous_len
= 0;
4464 for (unsigned int current_len
= cp_find_first_component (name
);
4465 name
[current_len
] != '\0';
4466 current_len
+= cp_find_first_component (name
+ current_len
))
4468 gdb_assert (name
[current_len
] == ':');
4469 this->name_components
.push_back ({previous_len
, idx
});
4470 /* Skip the '::'. */
4472 previous_len
= current_len
;
4474 this->name_components
.push_back ({previous_len
, idx
});
4477 /* Sort name_components elements by name. */
4478 auto name_comp_compare
= [&] (const name_component
&left
,
4479 const name_component
&right
)
4481 const char *left_qualified
= this->symbol_name_at (left
.idx
);
4482 const char *right_qualified
= this->symbol_name_at (right
.idx
);
4484 const char *left_name
= left_qualified
+ left
.name_offset
;
4485 const char *right_name
= right_qualified
+ right
.name_offset
;
4487 return name_cmp (left_name
, right_name
) < 0;
4490 std::sort (this->name_components
.begin (),
4491 this->name_components
.end (),
4495 /* Helper for dw2_expand_symtabs_matching that works with a
4496 mapped_index_base instead of the containing objfile. This is split
4497 to a separate function in order to be able to unit test the
4498 name_components matching using a mock mapped_index_base. For each
4499 symbol name that matches, calls MATCH_CALLBACK, passing it the
4500 symbol's index in the mapped_index_base symbol table. */
4503 dw2_expand_symtabs_matching_symbol
4504 (mapped_index_base
&index
,
4505 const lookup_name_info
&lookup_name_in
,
4506 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4507 enum search_domain kind
,
4508 gdb::function_view
<void (offset_type
)> match_callback
)
4510 lookup_name_info lookup_name_without_params
4511 = lookup_name_in
.make_ignore_params ();
4512 gdb_index_symbol_name_matcher lookup_name_matcher
4513 (lookup_name_without_params
);
4515 /* Build the symbol name component sorted vector, if we haven't
4517 index
.build_name_components ();
4519 auto bounds
= index
.find_name_components_bounds (lookup_name_without_params
);
4521 /* Now for each symbol name in range, check to see if we have a name
4522 match, and if so, call the MATCH_CALLBACK callback. */
4524 /* The same symbol may appear more than once in the range though.
4525 E.g., if we're looking for symbols that complete "w", and we have
4526 a symbol named "w1::w2", we'll find the two name components for
4527 that same symbol in the range. To be sure we only call the
4528 callback once per symbol, we first collect the symbol name
4529 indexes that matched in a temporary vector and ignore
4531 std::vector
<offset_type
> matches
;
4532 matches
.reserve (std::distance (bounds
.first
, bounds
.second
));
4534 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4536 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
4538 if (!lookup_name_matcher
.matches (qualified
)
4539 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4542 matches
.push_back (bounds
.first
->idx
);
4545 std::sort (matches
.begin (), matches
.end ());
4547 /* Finally call the callback, once per match. */
4549 for (offset_type idx
: matches
)
4553 match_callback (idx
);
4558 /* Above we use a type wider than idx's for 'prev', since 0 and
4559 (offset_type)-1 are both possible values. */
4560 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4565 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4567 /* A mock .gdb_index/.debug_names-like name index table, enough to
4568 exercise dw2_expand_symtabs_matching_symbol, which works with the
4569 mapped_index_base interface. Builds an index from the symbol list
4570 passed as parameter to the constructor. */
4571 class mock_mapped_index
: public mapped_index_base
4574 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4575 : m_symbol_table (symbols
)
4578 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4580 /* Return the number of names in the symbol table. */
4581 size_t symbol_name_count () const override
4583 return m_symbol_table
.size ();
4586 /* Get the name of the symbol at IDX in the symbol table. */
4587 const char *symbol_name_at (offset_type idx
) const override
4589 return m_symbol_table
[idx
];
4593 gdb::array_view
<const char *> m_symbol_table
;
4596 /* Convenience function that converts a NULL pointer to a "<null>"
4597 string, to pass to print routines. */
4600 string_or_null (const char *str
)
4602 return str
!= NULL
? str
: "<null>";
4605 /* Check if a lookup_name_info built from
4606 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4607 index. EXPECTED_LIST is the list of expected matches, in expected
4608 matching order. If no match expected, then an empty list is
4609 specified. Returns true on success. On failure prints a warning
4610 indicating the file:line that failed, and returns false. */
4613 check_match (const char *file
, int line
,
4614 mock_mapped_index
&mock_index
,
4615 const char *name
, symbol_name_match_type match_type
,
4616 bool completion_mode
,
4617 std::initializer_list
<const char *> expected_list
)
4619 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4621 bool matched
= true;
4623 auto mismatch
= [&] (const char *expected_str
,
4626 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4627 "expected=\"%s\", got=\"%s\"\n"),
4629 (match_type
== symbol_name_match_type::FULL
4631 name
, string_or_null (expected_str
), string_or_null (got
));
4635 auto expected_it
= expected_list
.begin ();
4636 auto expected_end
= expected_list
.end ();
4638 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4640 [&] (offset_type idx
)
4642 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4643 const char *expected_str
4644 = expected_it
== expected_end
? NULL
: *expected_it
++;
4646 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4647 mismatch (expected_str
, matched_name
);
4650 const char *expected_str
4651 = expected_it
== expected_end
? NULL
: *expected_it
++;
4652 if (expected_str
!= NULL
)
4653 mismatch (expected_str
, NULL
);
4658 /* The symbols added to the mock mapped_index for testing (in
4660 static const char *test_symbols
[] = {
4669 "ns2::tmpl<int>::foo2",
4670 "(anonymous namespace)::A::B::C",
4672 /* These are used to check that the increment-last-char in the
4673 matching algorithm for completion doesn't match "t1_fund" when
4674 completing "t1_func". */
4680 /* A UTF-8 name with multi-byte sequences to make sure that
4681 cp-name-parser understands this as a single identifier ("função"
4682 is "function" in PT). */
4685 /* \377 (0xff) is Latin1 'ÿ'. */
4688 /* \377 (0xff) is Latin1 'ÿ'. */
4692 /* A name with all sorts of complications. Starts with "z" to make
4693 it easier for the completion tests below. */
4694 #define Z_SYM_NAME \
4695 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4696 "::tuple<(anonymous namespace)::ui*, " \
4697 "std::default_delete<(anonymous namespace)::ui>, void>"
4702 /* Returns true if the mapped_index_base::find_name_component_bounds
4703 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4704 in completion mode. */
4707 check_find_bounds_finds (mapped_index_base
&index
,
4708 const char *search_name
,
4709 gdb::array_view
<const char *> expected_syms
)
4711 lookup_name_info
lookup_name (search_name
,
4712 symbol_name_match_type::FULL
, true);
4714 auto bounds
= index
.find_name_components_bounds (lookup_name
);
4716 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4717 if (distance
!= expected_syms
.size ())
4720 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4722 auto nc_elem
= bounds
.first
+ exp_elem
;
4723 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4724 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4731 /* Test the lower-level mapped_index::find_name_component_bounds
4735 test_mapped_index_find_name_component_bounds ()
4737 mock_mapped_index
mock_index (test_symbols
);
4739 mock_index
.build_name_components ();
4741 /* Test the lower-level mapped_index::find_name_component_bounds
4742 method in completion mode. */
4744 static const char *expected_syms
[] = {
4749 SELF_CHECK (check_find_bounds_finds (mock_index
,
4750 "t1_func", expected_syms
));
4753 /* Check that the increment-last-char in the name matching algorithm
4754 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4756 static const char *expected_syms1
[] = {
4760 SELF_CHECK (check_find_bounds_finds (mock_index
,
4761 "\377", expected_syms1
));
4763 static const char *expected_syms2
[] = {
4766 SELF_CHECK (check_find_bounds_finds (mock_index
,
4767 "\377\377", expected_syms2
));
4771 /* Test dw2_expand_symtabs_matching_symbol. */
4774 test_dw2_expand_symtabs_matching_symbol ()
4776 mock_mapped_index
mock_index (test_symbols
);
4778 /* We let all tests run until the end even if some fails, for debug
4780 bool any_mismatch
= false;
4782 /* Create the expected symbols list (an initializer_list). Needed
4783 because lists have commas, and we need to pass them to CHECK,
4784 which is a macro. */
4785 #define EXPECT(...) { __VA_ARGS__ }
4787 /* Wrapper for check_match that passes down the current
4788 __FILE__/__LINE__. */
4789 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4790 any_mismatch |= !check_match (__FILE__, __LINE__, \
4792 NAME, MATCH_TYPE, COMPLETION_MODE, \
4795 /* Identity checks. */
4796 for (const char *sym
: test_symbols
)
4798 /* Should be able to match all existing symbols. */
4799 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4802 /* Should be able to match all existing symbols with
4804 std::string with_params
= std::string (sym
) + "(int)";
4805 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4808 /* Should be able to match all existing symbols with
4809 parameters and qualifiers. */
4810 with_params
= std::string (sym
) + " ( int ) const";
4811 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4814 /* This should really find sym, but cp-name-parser.y doesn't
4815 know about lvalue/rvalue qualifiers yet. */
4816 with_params
= std::string (sym
) + " ( int ) &&";
4817 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4821 /* Check that the name matching algorithm for completion doesn't get
4822 confused with Latin1 'ÿ' / 0xff. */
4824 static const char str
[] = "\377";
4825 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4826 EXPECT ("\377", "\377\377123"));
4829 /* Check that the increment-last-char in the matching algorithm for
4830 completion doesn't match "t1_fund" when completing "t1_func". */
4832 static const char str
[] = "t1_func";
4833 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4834 EXPECT ("t1_func", "t1_func1"));
4837 /* Check that completion mode works at each prefix of the expected
4840 static const char str
[] = "function(int)";
4841 size_t len
= strlen (str
);
4844 for (size_t i
= 1; i
< len
; i
++)
4846 lookup
.assign (str
, i
);
4847 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4848 EXPECT ("function"));
4852 /* While "w" is a prefix of both components, the match function
4853 should still only be called once. */
4855 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4857 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4861 /* Same, with a "complicated" symbol. */
4863 static const char str
[] = Z_SYM_NAME
;
4864 size_t len
= strlen (str
);
4867 for (size_t i
= 1; i
< len
; i
++)
4869 lookup
.assign (str
, i
);
4870 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4871 EXPECT (Z_SYM_NAME
));
4875 /* In FULL mode, an incomplete symbol doesn't match. */
4877 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4881 /* A complete symbol with parameters matches any overload, since the
4882 index has no overload info. */
4884 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4885 EXPECT ("std::zfunction", "std::zfunction2"));
4886 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4887 EXPECT ("std::zfunction", "std::zfunction2"));
4888 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4889 EXPECT ("std::zfunction", "std::zfunction2"));
4892 /* Check that whitespace is ignored appropriately. A symbol with a
4893 template argument list. */
4895 static const char expected
[] = "ns::foo<int>";
4896 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4898 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4902 /* Check that whitespace is ignored appropriately. A symbol with a
4903 template argument list that includes a pointer. */
4905 static const char expected
[] = "ns::foo<char*>";
4906 /* Try both completion and non-completion modes. */
4907 static const bool completion_mode
[2] = {false, true};
4908 for (size_t i
= 0; i
< 2; i
++)
4910 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4911 completion_mode
[i
], EXPECT (expected
));
4912 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4913 completion_mode
[i
], EXPECT (expected
));
4915 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4916 completion_mode
[i
], EXPECT (expected
));
4917 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4918 completion_mode
[i
], EXPECT (expected
));
4923 /* Check method qualifiers are ignored. */
4924 static const char expected
[] = "ns::foo<char*>";
4925 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4926 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4927 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4928 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4929 CHECK_MATCH ("foo < char * > ( int ) const",
4930 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4931 CHECK_MATCH ("foo < char * > ( int ) &&",
4932 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4935 /* Test lookup names that don't match anything. */
4937 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4940 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4944 /* Some wild matching tests, exercising "(anonymous namespace)",
4945 which should not be confused with a parameter list. */
4947 static const char *syms
[] = {
4951 "A :: B :: C ( int )",
4956 for (const char *s
: syms
)
4958 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4959 EXPECT ("(anonymous namespace)::A::B::C"));
4964 static const char expected
[] = "ns2::tmpl<int>::foo2";
4965 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4967 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4971 SELF_CHECK (!any_mismatch
);
4980 test_mapped_index_find_name_component_bounds ();
4981 test_dw2_expand_symtabs_matching_symbol ();
4984 }} // namespace selftests::dw2_expand_symtabs_matching
4986 #endif /* GDB_SELF_TEST */
4988 /* If FILE_MATCHER is NULL or if PER_CU has
4989 dwarf2_per_cu_quick_data::MARK set (see
4990 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4991 EXPANSION_NOTIFY on it. */
4994 dw2_expand_symtabs_matching_one
4995 (struct dwarf2_per_cu_data
*per_cu
,
4996 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4997 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4999 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
5001 bool symtab_was_null
5002 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
5004 dw2_instantiate_symtab (per_cu
, false);
5006 if (expansion_notify
!= NULL
5008 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
5009 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
5013 /* Helper for dw2_expand_matching symtabs. Called on each symbol
5014 matched, to expand corresponding CUs that were marked. IDX is the
5015 index of the symbol name that matched. */
5018 dw2_expand_marked_cus
5019 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
5020 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5021 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5024 offset_type
*vec
, vec_len
, vec_idx
;
5025 bool global_seen
= false;
5026 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5028 vec
= (offset_type
*) (index
.constant_pool
5029 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
5030 vec_len
= MAYBE_SWAP (vec
[0]);
5031 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
5033 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
5034 /* This value is only valid for index versions >= 7. */
5035 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
5036 gdb_index_symbol_kind symbol_kind
=
5037 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
5038 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
5039 /* Only check the symbol attributes if they're present.
5040 Indices prior to version 7 don't record them,
5041 and indices >= 7 may elide them for certain symbols
5042 (gold does this). */
5045 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
5047 /* Work around gold/15646. */
5050 if (!is_static
&& global_seen
)
5056 /* Only check the symbol's kind if it has one. */
5061 case VARIABLES_DOMAIN
:
5062 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
5065 case FUNCTIONS_DOMAIN
:
5066 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
5070 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
5078 /* Don't crash on bad data. */
5079 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
5080 + dwarf2_per_objfile
->all_type_units
.size ()))
5082 complaint (&symfile_complaints
,
5083 _(".gdb_index entry has bad CU index"
5085 objfile_name (dwarf2_per_objfile
->objfile
));
5089 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
5090 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5095 /* If FILE_MATCHER is non-NULL, set all the
5096 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
5097 that match FILE_MATCHER. */
5100 dw_expand_symtabs_matching_file_matcher
5101 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5102 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
5104 if (file_matcher
== NULL
)
5107 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
5109 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
5111 NULL
, xcalloc
, xfree
));
5112 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
5114 NULL
, xcalloc
, xfree
));
5116 /* The rule is CUs specify all the files, including those used by
5117 any TU, so there's no need to scan TUs here. */
5119 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5123 per_cu
->v
.quick
->mark
= 0;
5125 /* We only need to look at symtabs not already expanded. */
5126 if (per_cu
->v
.quick
->compunit_symtab
)
5129 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5130 if (file_data
== NULL
)
5133 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
5135 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
5137 per_cu
->v
.quick
->mark
= 1;
5141 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5143 const char *this_real_name
;
5145 if (file_matcher (file_data
->file_names
[j
], false))
5147 per_cu
->v
.quick
->mark
= 1;
5151 /* Before we invoke realpath, which can get expensive when many
5152 files are involved, do a quick comparison of the basenames. */
5153 if (!basenames_may_differ
5154 && !file_matcher (lbasename (file_data
->file_names
[j
]),
5158 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
5159 if (file_matcher (this_real_name
, false))
5161 per_cu
->v
.quick
->mark
= 1;
5166 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
5167 ? visited_found
.get ()
5168 : visited_not_found
.get (),
5175 dw2_expand_symtabs_matching
5176 (struct objfile
*objfile
,
5177 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5178 const lookup_name_info
&lookup_name
,
5179 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5180 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5181 enum search_domain kind
)
5183 struct dwarf2_per_objfile
*dwarf2_per_objfile
5184 = get_dwarf2_per_objfile (objfile
);
5186 /* index_table is NULL if OBJF_READNOW. */
5187 if (!dwarf2_per_objfile
->index_table
)
5190 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5192 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5194 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
5196 kind
, [&] (offset_type idx
)
5198 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
5199 expansion_notify
, kind
);
5203 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
5206 static struct compunit_symtab
*
5207 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
5212 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
5213 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
5216 if (cust
->includes
== NULL
)
5219 for (i
= 0; cust
->includes
[i
]; ++i
)
5221 struct compunit_symtab
*s
= cust
->includes
[i
];
5223 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
5231 static struct compunit_symtab
*
5232 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
5233 struct bound_minimal_symbol msymbol
,
5235 struct obj_section
*section
,
5238 struct dwarf2_per_cu_data
*data
;
5239 struct compunit_symtab
*result
;
5241 if (!objfile
->psymtabs_addrmap
)
5244 data
= (struct dwarf2_per_cu_data
*) addrmap_find (objfile
->psymtabs_addrmap
,
5249 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
5250 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
5251 paddress (get_objfile_arch (objfile
), pc
));
5254 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
5257 gdb_assert (result
!= NULL
);
5262 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
5263 void *data
, int need_fullname
)
5265 struct dwarf2_per_objfile
*dwarf2_per_objfile
5266 = get_dwarf2_per_objfile (objfile
);
5268 if (!dwarf2_per_objfile
->filenames_cache
)
5270 dwarf2_per_objfile
->filenames_cache
.emplace ();
5272 htab_up
visited (htab_create_alloc (10,
5273 htab_hash_pointer
, htab_eq_pointer
,
5274 NULL
, xcalloc
, xfree
));
5276 /* The rule is CUs specify all the files, including those used
5277 by any TU, so there's no need to scan TUs here. We can
5278 ignore file names coming from already-expanded CUs. */
5280 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5282 if (per_cu
->v
.quick
->compunit_symtab
)
5284 void **slot
= htab_find_slot (visited
.get (),
5285 per_cu
->v
.quick
->file_names
,
5288 *slot
= per_cu
->v
.quick
->file_names
;
5292 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5294 /* We only need to look at symtabs not already expanded. */
5295 if (per_cu
->v
.quick
->compunit_symtab
)
5298 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5299 if (file_data
== NULL
)
5302 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
5305 /* Already visited. */
5310 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5312 const char *filename
= file_data
->file_names
[j
];
5313 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
5318 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
5320 gdb::unique_xmalloc_ptr
<char> this_real_name
;
5323 this_real_name
= gdb_realpath (filename
);
5324 (*fun
) (filename
, this_real_name
.get (), data
);
5329 dw2_has_symbols (struct objfile
*objfile
)
5334 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
5337 dw2_find_last_source_symtab
,
5338 dw2_forget_cached_source_info
,
5339 dw2_map_symtabs_matching_filename
,
5344 dw2_expand_symtabs_for_function
,
5345 dw2_expand_all_symtabs
,
5346 dw2_expand_symtabs_with_fullname
,
5347 dw2_map_matching_symbols
,
5348 dw2_expand_symtabs_matching
,
5349 dw2_find_pc_sect_compunit_symtab
,
5351 dw2_map_symbol_filenames
5354 /* DWARF-5 debug_names reader. */
5356 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
5357 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
5359 /* A helper function that reads the .debug_names section in SECTION
5360 and fills in MAP. FILENAME is the name of the file containing the
5361 section; it is used for error reporting.
5363 Returns true if all went well, false otherwise. */
5366 read_debug_names_from_section (struct objfile
*objfile
,
5367 const char *filename
,
5368 struct dwarf2_section_info
*section
,
5369 mapped_debug_names
&map
)
5371 if (dwarf2_section_empty_p (section
))
5374 /* Older elfutils strip versions could keep the section in the main
5375 executable while splitting it for the separate debug info file. */
5376 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
5379 dwarf2_read_section (objfile
, section
);
5381 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
5383 const gdb_byte
*addr
= section
->buffer
;
5385 bfd
*const abfd
= get_section_bfd_owner (section
);
5387 unsigned int bytes_read
;
5388 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5391 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5392 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5393 if (bytes_read
+ length
!= section
->size
)
5395 /* There may be multiple per-CU indices. */
5396 warning (_("Section .debug_names in %s length %s does not match "
5397 "section length %s, ignoring .debug_names."),
5398 filename
, plongest (bytes_read
+ length
),
5399 pulongest (section
->size
));
5403 /* The version number. */
5404 uint16_t version
= read_2_bytes (abfd
, addr
);
5408 warning (_("Section .debug_names in %s has unsupported version %d, "
5409 "ignoring .debug_names."),
5415 uint16_t padding
= read_2_bytes (abfd
, addr
);
5419 warning (_("Section .debug_names in %s has unsupported padding %d, "
5420 "ignoring .debug_names."),
5425 /* comp_unit_count - The number of CUs in the CU list. */
5426 map
.cu_count
= read_4_bytes (abfd
, addr
);
5429 /* local_type_unit_count - The number of TUs in the local TU
5431 map
.tu_count
= read_4_bytes (abfd
, addr
);
5434 /* foreign_type_unit_count - The number of TUs in the foreign TU
5436 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5438 if (foreign_tu_count
!= 0)
5440 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5441 "ignoring .debug_names."),
5442 filename
, static_cast<unsigned long> (foreign_tu_count
));
5446 /* bucket_count - The number of hash buckets in the hash lookup
5448 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5451 /* name_count - The number of unique names in the index. */
5452 map
.name_count
= read_4_bytes (abfd
, addr
);
5455 /* abbrev_table_size - The size in bytes of the abbreviations
5457 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5460 /* augmentation_string_size - The size in bytes of the augmentation
5461 string. This value is rounded up to a multiple of 4. */
5462 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5464 map
.augmentation_is_gdb
= ((augmentation_string_size
5465 == sizeof (dwarf5_augmentation
))
5466 && memcmp (addr
, dwarf5_augmentation
,
5467 sizeof (dwarf5_augmentation
)) == 0);
5468 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5469 addr
+= augmentation_string_size
;
5472 map
.cu_table_reordered
= addr
;
5473 addr
+= map
.cu_count
* map
.offset_size
;
5475 /* List of Local TUs */
5476 map
.tu_table_reordered
= addr
;
5477 addr
+= map
.tu_count
* map
.offset_size
;
5479 /* Hash Lookup Table */
5480 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5481 addr
+= map
.bucket_count
* 4;
5482 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5483 addr
+= map
.name_count
* 4;
5486 map
.name_table_string_offs_reordered
= addr
;
5487 addr
+= map
.name_count
* map
.offset_size
;
5488 map
.name_table_entry_offs_reordered
= addr
;
5489 addr
+= map
.name_count
* map
.offset_size
;
5491 const gdb_byte
*abbrev_table_start
= addr
;
5494 unsigned int bytes_read
;
5495 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5500 const auto insertpair
5501 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5502 if (!insertpair
.second
)
5504 warning (_("Section .debug_names in %s has duplicate index %s, "
5505 "ignoring .debug_names."),
5506 filename
, pulongest (index_num
));
5509 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5510 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5515 mapped_debug_names::index_val::attr attr
;
5516 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5518 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5520 if (attr
.form
== DW_FORM_implicit_const
)
5522 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5526 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5528 indexval
.attr_vec
.push_back (std::move (attr
));
5531 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5533 warning (_("Section .debug_names in %s has abbreviation_table "
5534 "of size %zu vs. written as %u, ignoring .debug_names."),
5535 filename
, addr
- abbrev_table_start
, abbrev_table_size
);
5538 map
.entry_pool
= addr
;
5543 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5547 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5548 const mapped_debug_names
&map
,
5549 dwarf2_section_info
§ion
,
5552 sect_offset sect_off_prev
;
5553 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5555 sect_offset sect_off_next
;
5556 if (i
< map
.cu_count
)
5559 = (sect_offset
) (extract_unsigned_integer
5560 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5562 map
.dwarf5_byte_order
));
5565 sect_off_next
= (sect_offset
) section
.size
;
5568 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5569 dwarf2_per_cu_data
*per_cu
5570 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5571 sect_off_prev
, length
);
5572 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5574 sect_off_prev
= sect_off_next
;
5578 /* Read the CU list from the mapped index, and use it to create all
5579 the CU objects for this dwarf2_per_objfile. */
5582 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5583 const mapped_debug_names
&map
,
5584 const mapped_debug_names
&dwz_map
)
5586 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
5587 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5589 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5590 dwarf2_per_objfile
->info
,
5591 false /* is_dwz */);
5593 if (dwz_map
.cu_count
== 0)
5596 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5597 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5601 /* Read .debug_names. If everything went ok, initialize the "quick"
5602 elements of all the CUs and return true. Otherwise, return false. */
5605 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5607 mapped_debug_names
local_map (dwarf2_per_objfile
);
5608 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5609 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5611 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5612 &dwarf2_per_objfile
->debug_names
,
5616 /* Don't use the index if it's empty. */
5617 if (local_map
.name_count
== 0)
5620 /* If there is a .dwz file, read it so we can get its CU list as
5622 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5625 if (!read_debug_names_from_section (objfile
,
5626 bfd_get_filename (dwz
->dwz_bfd
),
5627 &dwz
->debug_names
, dwz_map
))
5629 warning (_("could not read '.debug_names' section from %s; skipping"),
5630 bfd_get_filename (dwz
->dwz_bfd
));
5635 create_cus_from_debug_names (dwarf2_per_objfile
, local_map
, dwz_map
);
5637 if (local_map
.tu_count
!= 0)
5639 /* We can only handle a single .debug_types when we have an
5641 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
5644 dwarf2_section_info
*section
= VEC_index (dwarf2_section_info_def
,
5645 dwarf2_per_objfile
->types
, 0);
5647 create_signatured_type_table_from_debug_names
5648 (dwarf2_per_objfile
, local_map
, section
, &dwarf2_per_objfile
->abbrev
);
5651 create_addrmap_from_aranges (dwarf2_per_objfile
,
5652 &dwarf2_per_objfile
->debug_aranges
);
5654 dwarf2_per_objfile
->debug_names_table
.reset
5655 (new mapped_debug_names (dwarf2_per_objfile
));
5656 *dwarf2_per_objfile
->debug_names_table
= std::move (local_map
);
5657 dwarf2_per_objfile
->using_index
= 1;
5658 dwarf2_per_objfile
->quick_file_names_table
=
5659 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5664 /* Type used to manage iterating over all CUs looking for a symbol for
5667 class dw2_debug_names_iterator
5670 /* If WANT_SPECIFIC_BLOCK is true, only look for symbols in block
5671 BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
5672 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5673 bool want_specific_block
,
5674 block_enum block_index
, domain_enum domain
,
5676 : m_map (map
), m_want_specific_block (want_specific_block
),
5677 m_block_index (block_index
), m_domain (domain
),
5678 m_addr (find_vec_in_debug_names (map
, name
))
5681 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5682 search_domain search
, uint32_t namei
)
5685 m_addr (find_vec_in_debug_names (map
, namei
))
5688 /* Return the next matching CU or NULL if there are no more. */
5689 dwarf2_per_cu_data
*next ();
5692 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5694 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5697 /* The internalized form of .debug_names. */
5698 const mapped_debug_names
&m_map
;
5700 /* If true, only look for symbols that match BLOCK_INDEX. */
5701 const bool m_want_specific_block
= false;
5703 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
5704 Unused if !WANT_SPECIFIC_BLOCK - FIRST_LOCAL_BLOCK is an invalid
5706 const block_enum m_block_index
= FIRST_LOCAL_BLOCK
;
5708 /* The kind of symbol we're looking for. */
5709 const domain_enum m_domain
= UNDEF_DOMAIN
;
5710 const search_domain m_search
= ALL_DOMAIN
;
5712 /* The list of CUs from the index entry of the symbol, or NULL if
5714 const gdb_byte
*m_addr
;
5718 mapped_debug_names::namei_to_name (uint32_t namei
) const
5720 const ULONGEST namei_string_offs
5721 = extract_unsigned_integer ((name_table_string_offs_reordered
5722 + namei
* offset_size
),
5725 return read_indirect_string_at_offset
5726 (dwarf2_per_objfile
, dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
5729 /* Find a slot in .debug_names for the object named NAME. If NAME is
5730 found, return pointer to its pool data. If NAME cannot be found,
5734 dw2_debug_names_iterator::find_vec_in_debug_names
5735 (const mapped_debug_names
&map
, const char *name
)
5737 int (*cmp
) (const char *, const char *);
5739 if (current_language
->la_language
== language_cplus
5740 || current_language
->la_language
== language_fortran
5741 || current_language
->la_language
== language_d
)
5743 /* NAME is already canonical. Drop any qualifiers as
5744 .debug_names does not contain any. */
5746 if (strchr (name
, '(') != NULL
)
5748 gdb::unique_xmalloc_ptr
<char> without_params
5749 = cp_remove_params (name
);
5751 if (without_params
!= NULL
)
5753 name
= without_params
.get();
5758 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5760 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5762 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5763 (map
.bucket_table_reordered
5764 + (full_hash
% map
.bucket_count
)), 4,
5765 map
.dwarf5_byte_order
);
5769 if (namei
>= map
.name_count
)
5771 complaint (&symfile_complaints
,
5772 _("Wrong .debug_names with name index %u but name_count=%u "
5774 namei
, map
.name_count
,
5775 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5781 const uint32_t namei_full_hash
5782 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5783 (map
.hash_table_reordered
+ namei
), 4,
5784 map
.dwarf5_byte_order
);
5785 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5788 if (full_hash
== namei_full_hash
)
5790 const char *const namei_string
= map
.namei_to_name (namei
);
5792 #if 0 /* An expensive sanity check. */
5793 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5795 complaint (&symfile_complaints
,
5796 _("Wrong .debug_names hash for string at index %u "
5798 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5803 if (cmp (namei_string
, name
) == 0)
5805 const ULONGEST namei_entry_offs
5806 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5807 + namei
* map
.offset_size
),
5808 map
.offset_size
, map
.dwarf5_byte_order
);
5809 return map
.entry_pool
+ namei_entry_offs
;
5814 if (namei
>= map
.name_count
)
5820 dw2_debug_names_iterator::find_vec_in_debug_names
5821 (const mapped_debug_names
&map
, uint32_t namei
)
5823 if (namei
>= map
.name_count
)
5825 complaint (&symfile_complaints
,
5826 _("Wrong .debug_names with name index %u but name_count=%u "
5828 namei
, map
.name_count
,
5829 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5833 const ULONGEST namei_entry_offs
5834 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5835 + namei
* map
.offset_size
),
5836 map
.offset_size
, map
.dwarf5_byte_order
);
5837 return map
.entry_pool
+ namei_entry_offs
;
5840 /* See dw2_debug_names_iterator. */
5842 dwarf2_per_cu_data
*
5843 dw2_debug_names_iterator::next ()
5848 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5849 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5850 bfd
*const abfd
= objfile
->obfd
;
5854 unsigned int bytes_read
;
5855 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5856 m_addr
+= bytes_read
;
5860 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5861 if (indexval_it
== m_map
.abbrev_map
.cend ())
5863 complaint (&symfile_complaints
,
5864 _("Wrong .debug_names undefined abbrev code %s "
5866 pulongest (abbrev
), objfile_name (objfile
));
5869 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5870 bool have_is_static
= false;
5872 dwarf2_per_cu_data
*per_cu
= NULL
;
5873 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5878 case DW_FORM_implicit_const
:
5879 ull
= attr
.implicit_const
;
5881 case DW_FORM_flag_present
:
5885 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5886 m_addr
+= bytes_read
;
5889 complaint (&symfile_complaints
,
5890 _("Unsupported .debug_names form %s [in module %s]"),
5891 dwarf_form_name (attr
.form
),
5892 objfile_name (objfile
));
5895 switch (attr
.dw_idx
)
5897 case DW_IDX_compile_unit
:
5898 /* Don't crash on bad data. */
5899 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5901 complaint (&symfile_complaints
,
5902 _(".debug_names entry has bad CU index %s"
5905 objfile_name (dwarf2_per_objfile
->objfile
));
5908 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5910 case DW_IDX_type_unit
:
5911 /* Don't crash on bad data. */
5912 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5914 complaint (&symfile_complaints
,
5915 _(".debug_names entry has bad TU index %s"
5918 objfile_name (dwarf2_per_objfile
->objfile
));
5921 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5923 case DW_IDX_GNU_internal
:
5924 if (!m_map
.augmentation_is_gdb
)
5926 have_is_static
= true;
5929 case DW_IDX_GNU_external
:
5930 if (!m_map
.augmentation_is_gdb
)
5932 have_is_static
= true;
5938 /* Skip if already read in. */
5939 if (per_cu
->v
.quick
->compunit_symtab
)
5942 /* Check static vs global. */
5945 const bool want_static
= m_block_index
!= GLOBAL_BLOCK
;
5946 if (m_want_specific_block
&& want_static
!= is_static
)
5950 /* Match dw2_symtab_iter_next, symbol_kind
5951 and debug_names::psymbol_tag. */
5955 switch (indexval
.dwarf_tag
)
5957 case DW_TAG_variable
:
5958 case DW_TAG_subprogram
:
5959 /* Some types are also in VAR_DOMAIN. */
5960 case DW_TAG_typedef
:
5961 case DW_TAG_structure_type
:
5968 switch (indexval
.dwarf_tag
)
5970 case DW_TAG_typedef
:
5971 case DW_TAG_structure_type
:
5978 switch (indexval
.dwarf_tag
)
5981 case DW_TAG_variable
:
5991 /* Match dw2_expand_symtabs_matching, symbol_kind and
5992 debug_names::psymbol_tag. */
5995 case VARIABLES_DOMAIN
:
5996 switch (indexval
.dwarf_tag
)
5998 case DW_TAG_variable
:
6004 case FUNCTIONS_DOMAIN
:
6005 switch (indexval
.dwarf_tag
)
6007 case DW_TAG_subprogram
:
6014 switch (indexval
.dwarf_tag
)
6016 case DW_TAG_typedef
:
6017 case DW_TAG_structure_type
:
6030 static struct compunit_symtab
*
6031 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, int block_index_int
,
6032 const char *name
, domain_enum domain
)
6034 const block_enum block_index
= static_cast<block_enum
> (block_index_int
);
6035 struct dwarf2_per_objfile
*dwarf2_per_objfile
6036 = get_dwarf2_per_objfile (objfile
);
6038 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
6041 /* index is NULL if OBJF_READNOW. */
6044 const auto &map
= *mapp
;
6046 dw2_debug_names_iterator
iter (map
, true /* want_specific_block */,
6047 block_index
, domain
, name
);
6049 struct compunit_symtab
*stab_best
= NULL
;
6050 struct dwarf2_per_cu_data
*per_cu
;
6051 while ((per_cu
= iter
.next ()) != NULL
)
6053 struct symbol
*sym
, *with_opaque
= NULL
;
6054 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
6055 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
6056 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
6058 sym
= block_find_symbol (block
, name
, domain
,
6059 block_find_non_opaque_type_preferred
,
6062 /* Some caution must be observed with overloaded functions and
6063 methods, since the index will not contain any overload
6064 information (but NAME might contain it). */
6067 && strcmp_iw (SYMBOL_SEARCH_NAME (sym
), name
) == 0)
6069 if (with_opaque
!= NULL
6070 && strcmp_iw (SYMBOL_SEARCH_NAME (with_opaque
), name
) == 0)
6073 /* Keep looking through other CUs. */
6079 /* This dumps minimal information about .debug_names. It is called
6080 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
6081 uses this to verify that .debug_names has been loaded. */
6084 dw2_debug_names_dump (struct objfile
*objfile
)
6086 struct dwarf2_per_objfile
*dwarf2_per_objfile
6087 = get_dwarf2_per_objfile (objfile
);
6089 gdb_assert (dwarf2_per_objfile
->using_index
);
6090 printf_filtered (".debug_names:");
6091 if (dwarf2_per_objfile
->debug_names_table
)
6092 printf_filtered (" exists\n");
6094 printf_filtered (" faked for \"readnow\"\n");
6095 printf_filtered ("\n");
6099 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
6100 const char *func_name
)
6102 struct dwarf2_per_objfile
*dwarf2_per_objfile
6103 = get_dwarf2_per_objfile (objfile
);
6105 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
6106 if (dwarf2_per_objfile
->debug_names_table
)
6108 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6110 /* Note: It doesn't matter what we pass for block_index here. */
6111 dw2_debug_names_iterator
iter (map
, false /* want_specific_block */,
6112 GLOBAL_BLOCK
, VAR_DOMAIN
, func_name
);
6114 struct dwarf2_per_cu_data
*per_cu
;
6115 while ((per_cu
= iter
.next ()) != NULL
)
6116 dw2_instantiate_symtab (per_cu
, false);
6121 dw2_debug_names_expand_symtabs_matching
6122 (struct objfile
*objfile
,
6123 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
6124 const lookup_name_info
&lookup_name
,
6125 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
6126 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
6127 enum search_domain kind
)
6129 struct dwarf2_per_objfile
*dwarf2_per_objfile
6130 = get_dwarf2_per_objfile (objfile
);
6132 /* debug_names_table is NULL if OBJF_READNOW. */
6133 if (!dwarf2_per_objfile
->debug_names_table
)
6136 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
6138 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6140 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
6142 kind
, [&] (offset_type namei
)
6144 /* The name was matched, now expand corresponding CUs that were
6146 dw2_debug_names_iterator
iter (map
, kind
, namei
);
6148 struct dwarf2_per_cu_data
*per_cu
;
6149 while ((per_cu
= iter
.next ()) != NULL
)
6150 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
6155 const struct quick_symbol_functions dwarf2_debug_names_functions
=
6158 dw2_find_last_source_symtab
,
6159 dw2_forget_cached_source_info
,
6160 dw2_map_symtabs_matching_filename
,
6161 dw2_debug_names_lookup_symbol
,
6163 dw2_debug_names_dump
,
6165 dw2_debug_names_expand_symtabs_for_function
,
6166 dw2_expand_all_symtabs
,
6167 dw2_expand_symtabs_with_fullname
,
6168 dw2_map_matching_symbols
,
6169 dw2_debug_names_expand_symtabs_matching
,
6170 dw2_find_pc_sect_compunit_symtab
,
6172 dw2_map_symbol_filenames
6175 /* See symfile.h. */
6178 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
6180 struct dwarf2_per_objfile
*dwarf2_per_objfile
6181 = get_dwarf2_per_objfile (objfile
);
6183 /* If we're about to read full symbols, don't bother with the
6184 indices. In this case we also don't care if some other debug
6185 format is making psymtabs, because they are all about to be
6187 if ((objfile
->flags
& OBJF_READNOW
))
6189 dwarf2_per_objfile
->using_index
= 1;
6190 create_all_comp_units (dwarf2_per_objfile
);
6191 create_all_type_units (dwarf2_per_objfile
);
6192 dwarf2_per_objfile
->quick_file_names_table
6193 = create_quick_file_names_table
6194 (dwarf2_per_objfile
->all_comp_units
.size ());
6196 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
6197 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
6199 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
6201 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6202 struct dwarf2_per_cu_quick_data
);
6205 /* Return 1 so that gdb sees the "quick" functions. However,
6206 these functions will be no-ops because we will have expanded
6208 *index_kind
= dw_index_kind::GDB_INDEX
;
6212 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
6214 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6218 if (dwarf2_read_index (dwarf2_per_objfile
))
6220 *index_kind
= dw_index_kind::GDB_INDEX
;
6229 /* Build a partial symbol table. */
6232 dwarf2_build_psymtabs (struct objfile
*objfile
)
6234 struct dwarf2_per_objfile
*dwarf2_per_objfile
6235 = get_dwarf2_per_objfile (objfile
);
6237 if (objfile
->global_psymbols
.capacity () == 0
6238 && objfile
->static_psymbols
.capacity () == 0)
6239 init_psymbol_list (objfile
, 1024);
6243 /* This isn't really ideal: all the data we allocate on the
6244 objfile's obstack is still uselessly kept around. However,
6245 freeing it seems unsafe. */
6246 psymtab_discarder
psymtabs (objfile
);
6247 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
6250 CATCH (except
, RETURN_MASK_ERROR
)
6252 exception_print (gdb_stderr
, except
);
6257 /* Return the total length of the CU described by HEADER. */
6260 get_cu_length (const struct comp_unit_head
*header
)
6262 return header
->initial_length_size
+ header
->length
;
6265 /* Return TRUE if SECT_OFF is within CU_HEADER. */
6268 offset_in_cu_p (const comp_unit_head
*cu_header
, sect_offset sect_off
)
6270 sect_offset bottom
= cu_header
->sect_off
;
6271 sect_offset top
= cu_header
->sect_off
+ get_cu_length (cu_header
);
6273 return sect_off
>= bottom
&& sect_off
< top
;
6276 /* Find the base address of the compilation unit for range lists and
6277 location lists. It will normally be specified by DW_AT_low_pc.
6278 In DWARF-3 draft 4, the base address could be overridden by
6279 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6280 compilation units with discontinuous ranges. */
6283 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6285 struct attribute
*attr
;
6288 cu
->base_address
= 0;
6290 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6293 cu
->base_address
= attr_value_as_address (attr
);
6298 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6301 cu
->base_address
= attr_value_as_address (attr
);
6307 /* Read in the comp unit header information from the debug_info at info_ptr.
6308 Use rcuh_kind::COMPILE as the default type if not known by the caller.
6309 NOTE: This leaves members offset, first_die_offset to be filled in
6312 static const gdb_byte
*
6313 read_comp_unit_head (struct comp_unit_head
*cu_header
,
6314 const gdb_byte
*info_ptr
,
6315 struct dwarf2_section_info
*section
,
6316 rcuh_kind section_kind
)
6319 unsigned int bytes_read
;
6320 const char *filename
= get_section_file_name (section
);
6321 bfd
*abfd
= get_section_bfd_owner (section
);
6323 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
6324 cu_header
->initial_length_size
= bytes_read
;
6325 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
6326 info_ptr
+= bytes_read
;
6327 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
6329 if (cu_header
->version
< 5)
6330 switch (section_kind
)
6332 case rcuh_kind::COMPILE
:
6333 cu_header
->unit_type
= DW_UT_compile
;
6335 case rcuh_kind::TYPE
:
6336 cu_header
->unit_type
= DW_UT_type
;
6339 internal_error (__FILE__
, __LINE__
,
6340 _("read_comp_unit_head: invalid section_kind"));
6344 cu_header
->unit_type
= static_cast<enum dwarf_unit_type
>
6345 (read_1_byte (abfd
, info_ptr
));
6347 switch (cu_header
->unit_type
)
6350 if (section_kind
!= rcuh_kind::COMPILE
)
6351 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6352 "(is DW_UT_compile, should be DW_UT_type) [in module %s]"),
6356 section_kind
= rcuh_kind::TYPE
;
6359 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6360 "(is %d, should be %d or %d) [in module %s]"),
6361 cu_header
->unit_type
, DW_UT_compile
, DW_UT_type
, filename
);
6364 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6367 cu_header
->abbrev_sect_off
= (sect_offset
) read_offset (abfd
, info_ptr
,
6370 info_ptr
+= bytes_read
;
6371 if (cu_header
->version
< 5)
6373 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6376 signed_addr
= bfd_get_sign_extend_vma (abfd
);
6377 if (signed_addr
< 0)
6378 internal_error (__FILE__
, __LINE__
,
6379 _("read_comp_unit_head: dwarf from non elf file"));
6380 cu_header
->signed_addr_p
= signed_addr
;
6382 if (section_kind
== rcuh_kind::TYPE
)
6384 LONGEST type_offset
;
6386 cu_header
->signature
= read_8_bytes (abfd
, info_ptr
);
6389 type_offset
= read_offset (abfd
, info_ptr
, cu_header
, &bytes_read
);
6390 info_ptr
+= bytes_read
;
6391 cu_header
->type_cu_offset_in_tu
= (cu_offset
) type_offset
;
6392 if (to_underlying (cu_header
->type_cu_offset_in_tu
) != type_offset
)
6393 error (_("Dwarf Error: Too big type_offset in compilation unit "
6394 "header (is %s) [in module %s]"), plongest (type_offset
),
6401 /* Helper function that returns the proper abbrev section for
6404 static struct dwarf2_section_info
*
6405 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6407 struct dwarf2_section_info
*abbrev
;
6408 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6410 if (this_cu
->is_dwz
)
6411 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
6413 abbrev
= &dwarf2_per_objfile
->abbrev
;
6418 /* Subroutine of read_and_check_comp_unit_head and
6419 read_and_check_type_unit_head to simplify them.
6420 Perform various error checking on the header. */
6423 error_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6424 struct comp_unit_head
*header
,
6425 struct dwarf2_section_info
*section
,
6426 struct dwarf2_section_info
*abbrev_section
)
6428 const char *filename
= get_section_file_name (section
);
6430 if (header
->version
< 2 || header
->version
> 5)
6431 error (_("Dwarf Error: wrong version in compilation unit header "
6432 "(is %d, should be 2, 3, 4 or 5) [in module %s]"), header
->version
,
6435 if (to_underlying (header
->abbrev_sect_off
)
6436 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
6437 error (_("Dwarf Error: bad offset (%s) in compilation unit header "
6438 "(offset %s + 6) [in module %s]"),
6439 sect_offset_str (header
->abbrev_sect_off
),
6440 sect_offset_str (header
->sect_off
),
6443 /* Cast to ULONGEST to use 64-bit arithmetic when possible to
6444 avoid potential 32-bit overflow. */
6445 if (((ULONGEST
) header
->sect_off
+ get_cu_length (header
))
6447 error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
6448 "(offset %s + 0) [in module %s]"),
6449 header
->length
, sect_offset_str (header
->sect_off
),
6453 /* Read in a CU/TU header and perform some basic error checking.
6454 The contents of the header are stored in HEADER.
6455 The result is a pointer to the start of the first DIE. */
6457 static const gdb_byte
*
6458 read_and_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6459 struct comp_unit_head
*header
,
6460 struct dwarf2_section_info
*section
,
6461 struct dwarf2_section_info
*abbrev_section
,
6462 const gdb_byte
*info_ptr
,
6463 rcuh_kind section_kind
)
6465 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
6467 header
->sect_off
= (sect_offset
) (beg_of_comp_unit
- section
->buffer
);
6469 info_ptr
= read_comp_unit_head (header
, info_ptr
, section
, section_kind
);
6471 header
->first_die_cu_offset
= (cu_offset
) (info_ptr
- beg_of_comp_unit
);
6473 error_check_comp_unit_head (dwarf2_per_objfile
, header
, section
,
6479 /* Fetch the abbreviation table offset from a comp or type unit header. */
6482 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6483 struct dwarf2_section_info
*section
,
6484 sect_offset sect_off
)
6486 bfd
*abfd
= get_section_bfd_owner (section
);
6487 const gdb_byte
*info_ptr
;
6488 unsigned int initial_length_size
, offset_size
;
6491 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
6492 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6493 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6494 offset_size
= initial_length_size
== 4 ? 4 : 8;
6495 info_ptr
+= initial_length_size
;
6497 version
= read_2_bytes (abfd
, info_ptr
);
6501 /* Skip unit type and address size. */
6505 return (sect_offset
) read_offset_1 (abfd
, info_ptr
, offset_size
);
6508 /* Allocate a new partial symtab for file named NAME and mark this new
6509 partial symtab as being an include of PST. */
6512 dwarf2_create_include_psymtab (const char *name
, struct partial_symtab
*pst
,
6513 struct objfile
*objfile
)
6515 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
6517 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6519 /* It shares objfile->objfile_obstack. */
6520 subpst
->dirname
= pst
->dirname
;
6523 subpst
->textlow
= 0;
6524 subpst
->texthigh
= 0;
6526 subpst
->dependencies
6527 = XOBNEW (&objfile
->objfile_obstack
, struct partial_symtab
*);
6528 subpst
->dependencies
[0] = pst
;
6529 subpst
->number_of_dependencies
= 1;
6531 subpst
->globals_offset
= 0;
6532 subpst
->n_global_syms
= 0;
6533 subpst
->statics_offset
= 0;
6534 subpst
->n_static_syms
= 0;
6535 subpst
->compunit_symtab
= NULL
;
6536 subpst
->read_symtab
= pst
->read_symtab
;
6539 /* No private part is necessary for include psymtabs. This property
6540 can be used to differentiate between such include psymtabs and
6541 the regular ones. */
6542 subpst
->read_symtab_private
= NULL
;
6545 /* Read the Line Number Program data and extract the list of files
6546 included by the source file represented by PST. Build an include
6547 partial symtab for each of these included files. */
6550 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6551 struct die_info
*die
,
6552 struct partial_symtab
*pst
)
6555 struct attribute
*attr
;
6557 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6559 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6561 return; /* No linetable, so no includes. */
6563 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
6564 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
, pst
->textlow
, 1);
6568 hash_signatured_type (const void *item
)
6570 const struct signatured_type
*sig_type
6571 = (const struct signatured_type
*) item
;
6573 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6574 return sig_type
->signature
;
6578 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6580 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6581 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6583 return lhs
->signature
== rhs
->signature
;
6586 /* Allocate a hash table for signatured types. */
6589 allocate_signatured_type_table (struct objfile
*objfile
)
6591 return htab_create_alloc_ex (41,
6592 hash_signatured_type
,
6595 &objfile
->objfile_obstack
,
6596 hashtab_obstack_allocate
,
6597 dummy_obstack_deallocate
);
6600 /* A helper function to add a signatured type CU to a table. */
6603 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6605 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6606 std::vector
<signatured_type
*> *all_type_units
6607 = (std::vector
<signatured_type
*> *) datum
;
6609 all_type_units
->push_back (sigt
);
6614 /* A helper for create_debug_types_hash_table. Read types from SECTION
6615 and fill them into TYPES_HTAB. It will process only type units,
6616 therefore DW_UT_type. */
6619 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6620 struct dwo_file
*dwo_file
,
6621 dwarf2_section_info
*section
, htab_t
&types_htab
,
6622 rcuh_kind section_kind
)
6624 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6625 struct dwarf2_section_info
*abbrev_section
;
6627 const gdb_byte
*info_ptr
, *end_ptr
;
6629 abbrev_section
= (dwo_file
!= NULL
6630 ? &dwo_file
->sections
.abbrev
6631 : &dwarf2_per_objfile
->abbrev
);
6633 if (dwarf_read_debug
)
6634 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6635 get_section_name (section
),
6636 get_section_file_name (abbrev_section
));
6638 dwarf2_read_section (objfile
, section
);
6639 info_ptr
= section
->buffer
;
6641 if (info_ptr
== NULL
)
6644 /* We can't set abfd until now because the section may be empty or
6645 not present, in which case the bfd is unknown. */
6646 abfd
= get_section_bfd_owner (section
);
6648 /* We don't use init_cutu_and_read_dies_simple, or some such, here
6649 because we don't need to read any dies: the signature is in the
6652 end_ptr
= info_ptr
+ section
->size
;
6653 while (info_ptr
< end_ptr
)
6655 struct signatured_type
*sig_type
;
6656 struct dwo_unit
*dwo_tu
;
6658 const gdb_byte
*ptr
= info_ptr
;
6659 struct comp_unit_head header
;
6660 unsigned int length
;
6662 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6664 /* Initialize it due to a false compiler warning. */
6665 header
.signature
= -1;
6666 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6668 /* We need to read the type's signature in order to build the hash
6669 table, but we don't need anything else just yet. */
6671 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6672 abbrev_section
, ptr
, section_kind
);
6674 length
= get_cu_length (&header
);
6676 /* Skip dummy type units. */
6677 if (ptr
>= info_ptr
+ length
6678 || peek_abbrev_code (abfd
, ptr
) == 0
6679 || header
.unit_type
!= DW_UT_type
)
6685 if (types_htab
== NULL
)
6688 types_htab
= allocate_dwo_unit_table (objfile
);
6690 types_htab
= allocate_signatured_type_table (objfile
);
6696 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6698 dwo_tu
->dwo_file
= dwo_file
;
6699 dwo_tu
->signature
= header
.signature
;
6700 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6701 dwo_tu
->section
= section
;
6702 dwo_tu
->sect_off
= sect_off
;
6703 dwo_tu
->length
= length
;
6707 /* N.B.: type_offset is not usable if this type uses a DWO file.
6708 The real type_offset is in the DWO file. */
6710 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6711 struct signatured_type
);
6712 sig_type
->signature
= header
.signature
;
6713 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6714 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6715 sig_type
->per_cu
.is_debug_types
= 1;
6716 sig_type
->per_cu
.section
= section
;
6717 sig_type
->per_cu
.sect_off
= sect_off
;
6718 sig_type
->per_cu
.length
= length
;
6721 slot
= htab_find_slot (types_htab
,
6722 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6724 gdb_assert (slot
!= NULL
);
6727 sect_offset dup_sect_off
;
6731 const struct dwo_unit
*dup_tu
6732 = (const struct dwo_unit
*) *slot
;
6734 dup_sect_off
= dup_tu
->sect_off
;
6738 const struct signatured_type
*dup_tu
6739 = (const struct signatured_type
*) *slot
;
6741 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6744 complaint (&symfile_complaints
,
6745 _("debug type entry at offset %s is duplicate to"
6746 " the entry at offset %s, signature %s"),
6747 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6748 hex_string (header
.signature
));
6750 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6752 if (dwarf_read_debug
> 1)
6753 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6754 sect_offset_str (sect_off
),
6755 hex_string (header
.signature
));
6761 /* Create the hash table of all entries in the .debug_types
6762 (or .debug_types.dwo) section(s).
6763 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6764 otherwise it is NULL.
6766 The result is a pointer to the hash table or NULL if there are no types.
6768 Note: This function processes DWO files only, not DWP files. */
6771 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6772 struct dwo_file
*dwo_file
,
6773 VEC (dwarf2_section_info_def
) *types
,
6777 struct dwarf2_section_info
*section
;
6779 if (VEC_empty (dwarf2_section_info_def
, types
))
6783 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
6785 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, section
,
6786 types_htab
, rcuh_kind::TYPE
);
6789 /* Create the hash table of all entries in the .debug_types section,
6790 and initialize all_type_units.
6791 The result is zero if there is an error (e.g. missing .debug_types section),
6792 otherwise non-zero. */
6795 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6797 htab_t types_htab
= NULL
;
6799 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6800 &dwarf2_per_objfile
->info
, types_htab
,
6801 rcuh_kind::COMPILE
);
6802 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6803 dwarf2_per_objfile
->types
, types_htab
);
6804 if (types_htab
== NULL
)
6806 dwarf2_per_objfile
->signatured_types
= NULL
;
6810 dwarf2_per_objfile
->signatured_types
= types_htab
;
6812 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6813 dwarf2_per_objfile
->all_type_units
.reserve (htab_elements (types_htab
));
6815 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
,
6816 &dwarf2_per_objfile
->all_type_units
);
6821 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6822 If SLOT is non-NULL, it is the entry to use in the hash table.
6823 Otherwise we find one. */
6825 static struct signatured_type
*
6826 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6829 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6831 if (dwarf2_per_objfile
->all_type_units
.size ()
6832 == dwarf2_per_objfile
->all_type_units
.capacity ())
6833 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6835 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6836 struct signatured_type
);
6838 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6839 sig_type
->signature
= sig
;
6840 sig_type
->per_cu
.is_debug_types
= 1;
6841 if (dwarf2_per_objfile
->using_index
)
6843 sig_type
->per_cu
.v
.quick
=
6844 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6845 struct dwarf2_per_cu_quick_data
);
6850 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
6853 gdb_assert (*slot
== NULL
);
6855 /* The rest of sig_type must be filled in by the caller. */
6859 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6860 Fill in SIG_ENTRY with DWO_ENTRY. */
6863 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6864 struct signatured_type
*sig_entry
,
6865 struct dwo_unit
*dwo_entry
)
6867 /* Make sure we're not clobbering something we don't expect to. */
6868 gdb_assert (! sig_entry
->per_cu
.queued
);
6869 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6870 if (dwarf2_per_objfile
->using_index
)
6872 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6873 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
6876 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6877 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6878 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6879 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6880 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6882 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6883 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6884 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6885 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6886 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6887 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6888 sig_entry
->dwo_unit
= dwo_entry
;
6891 /* Subroutine of lookup_signatured_type.
6892 If we haven't read the TU yet, create the signatured_type data structure
6893 for a TU to be read in directly from a DWO file, bypassing the stub.
6894 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6895 using .gdb_index, then when reading a CU we want to stay in the DWO file
6896 containing that CU. Otherwise we could end up reading several other DWO
6897 files (due to comdat folding) to process the transitive closure of all the
6898 mentioned TUs, and that can be slow. The current DWO file will have every
6899 type signature that it needs.
6900 We only do this for .gdb_index because in the psymtab case we already have
6901 to read all the DWOs to build the type unit groups. */
6903 static struct signatured_type
*
6904 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6906 struct dwarf2_per_objfile
*dwarf2_per_objfile
6907 = cu
->per_cu
->dwarf2_per_objfile
;
6908 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6909 struct dwo_file
*dwo_file
;
6910 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6911 struct signatured_type find_sig_entry
, *sig_entry
;
6914 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6916 /* If TU skeletons have been removed then we may not have read in any
6918 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6920 dwarf2_per_objfile
->signatured_types
6921 = allocate_signatured_type_table (objfile
);
6924 /* We only ever need to read in one copy of a signatured type.
6925 Use the global signatured_types array to do our own comdat-folding
6926 of types. If this is the first time we're reading this TU, and
6927 the TU has an entry in .gdb_index, replace the recorded data from
6928 .gdb_index with this TU. */
6930 find_sig_entry
.signature
= sig
;
6931 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
6932 &find_sig_entry
, INSERT
);
6933 sig_entry
= (struct signatured_type
*) *slot
;
6935 /* We can get here with the TU already read, *or* in the process of being
6936 read. Don't reassign the global entry to point to this DWO if that's
6937 the case. Also note that if the TU is already being read, it may not
6938 have come from a DWO, the program may be a mix of Fission-compiled
6939 code and non-Fission-compiled code. */
6941 /* Have we already tried to read this TU?
6942 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6943 needn't exist in the global table yet). */
6944 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6947 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6948 dwo_unit of the TU itself. */
6949 dwo_file
= cu
->dwo_unit
->dwo_file
;
6951 /* Ok, this is the first time we're reading this TU. */
6952 if (dwo_file
->tus
== NULL
)
6954 find_dwo_entry
.signature
= sig
;
6955 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_entry
);
6956 if (dwo_entry
== NULL
)
6959 /* If the global table doesn't have an entry for this TU, add one. */
6960 if (sig_entry
== NULL
)
6961 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6963 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6964 sig_entry
->per_cu
.tu_read
= 1;
6968 /* Subroutine of lookup_signatured_type.
6969 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6970 then try the DWP file. If the TU stub (skeleton) has been removed then
6971 it won't be in .gdb_index. */
6973 static struct signatured_type
*
6974 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6976 struct dwarf2_per_objfile
*dwarf2_per_objfile
6977 = cu
->per_cu
->dwarf2_per_objfile
;
6978 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6979 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
6980 struct dwo_unit
*dwo_entry
;
6981 struct signatured_type find_sig_entry
, *sig_entry
;
6984 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6985 gdb_assert (dwp_file
!= NULL
);
6987 /* If TU skeletons have been removed then we may not have read in any
6989 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6991 dwarf2_per_objfile
->signatured_types
6992 = allocate_signatured_type_table (objfile
);
6995 find_sig_entry
.signature
= sig
;
6996 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
6997 &find_sig_entry
, INSERT
);
6998 sig_entry
= (struct signatured_type
*) *slot
;
7000 /* Have we already tried to read this TU?
7001 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7002 needn't exist in the global table yet). */
7003 if (sig_entry
!= NULL
)
7006 if (dwp_file
->tus
== NULL
)
7008 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
7009 sig
, 1 /* is_debug_types */);
7010 if (dwo_entry
== NULL
)
7013 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7014 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7019 /* Lookup a signature based type for DW_FORM_ref_sig8.
7020 Returns NULL if signature SIG is not present in the table.
7021 It is up to the caller to complain about this. */
7023 static struct signatured_type
*
7024 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7026 struct dwarf2_per_objfile
*dwarf2_per_objfile
7027 = cu
->per_cu
->dwarf2_per_objfile
;
7030 && dwarf2_per_objfile
->using_index
)
7032 /* We're in a DWO/DWP file, and we're using .gdb_index.
7033 These cases require special processing. */
7034 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
7035 return lookup_dwo_signatured_type (cu
, sig
);
7037 return lookup_dwp_signatured_type (cu
, sig
);
7041 struct signatured_type find_entry
, *entry
;
7043 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7045 find_entry
.signature
= sig
;
7046 entry
= ((struct signatured_type
*)
7047 htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
));
7052 /* Low level DIE reading support. */
7054 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
7057 init_cu_die_reader (struct die_reader_specs
*reader
,
7058 struct dwarf2_cu
*cu
,
7059 struct dwarf2_section_info
*section
,
7060 struct dwo_file
*dwo_file
,
7061 struct abbrev_table
*abbrev_table
)
7063 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
7064 reader
->abfd
= get_section_bfd_owner (section
);
7066 reader
->dwo_file
= dwo_file
;
7067 reader
->die_section
= section
;
7068 reader
->buffer
= section
->buffer
;
7069 reader
->buffer_end
= section
->buffer
+ section
->size
;
7070 reader
->comp_dir
= NULL
;
7071 reader
->abbrev_table
= abbrev_table
;
7074 /* Subroutine of init_cutu_and_read_dies to simplify it.
7075 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
7076 There's just a lot of work to do, and init_cutu_and_read_dies is big enough
7079 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
7080 from it to the DIE in the DWO. If NULL we are skipping the stub.
7081 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
7082 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
7083 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
7084 STUB_COMP_DIR may be non-NULL.
7085 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
7086 are filled in with the info of the DIE from the DWO file.
7087 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
7088 from the dwo. Since *RESULT_READER references this abbrev table, it must be
7089 kept around for at least as long as *RESULT_READER.
7091 The result is non-zero if a valid (non-dummy) DIE was found. */
7094 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
7095 struct dwo_unit
*dwo_unit
,
7096 struct die_info
*stub_comp_unit_die
,
7097 const char *stub_comp_dir
,
7098 struct die_reader_specs
*result_reader
,
7099 const gdb_byte
**result_info_ptr
,
7100 struct die_info
**result_comp_unit_die
,
7101 int *result_has_children
,
7102 abbrev_table_up
*result_dwo_abbrev_table
)
7104 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7105 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7106 struct dwarf2_cu
*cu
= this_cu
->cu
;
7108 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7109 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
7110 int i
,num_extra_attrs
;
7111 struct dwarf2_section_info
*dwo_abbrev_section
;
7112 struct attribute
*attr
;
7113 struct die_info
*comp_unit_die
;
7115 /* At most one of these may be provided. */
7116 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
7118 /* These attributes aren't processed until later:
7119 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
7120 DW_AT_comp_dir is used now, to find the DWO file, but it is also
7121 referenced later. However, these attributes are found in the stub
7122 which we won't have later. In order to not impose this complication
7123 on the rest of the code, we read them here and copy them to the
7132 if (stub_comp_unit_die
!= NULL
)
7134 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
7136 if (! this_cu
->is_debug_types
)
7137 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
7138 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
7139 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
7140 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
7141 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
7143 /* There should be a DW_AT_addr_base attribute here (if needed).
7144 We need the value before we can process DW_FORM_GNU_addr_index. */
7146 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
7148 cu
->addr_base
= DW_UNSND (attr
);
7150 /* There should be a DW_AT_ranges_base attribute here (if needed).
7151 We need the value before we can process DW_AT_ranges. */
7152 cu
->ranges_base
= 0;
7153 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
7155 cu
->ranges_base
= DW_UNSND (attr
);
7157 else if (stub_comp_dir
!= NULL
)
7159 /* Reconstruct the comp_dir attribute to simplify the code below. */
7160 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
7161 comp_dir
->name
= DW_AT_comp_dir
;
7162 comp_dir
->form
= DW_FORM_string
;
7163 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
7164 DW_STRING (comp_dir
) = stub_comp_dir
;
7167 /* Set up for reading the DWO CU/TU. */
7168 cu
->dwo_unit
= dwo_unit
;
7169 dwarf2_section_info
*section
= dwo_unit
->section
;
7170 dwarf2_read_section (objfile
, section
);
7171 abfd
= get_section_bfd_owner (section
);
7172 begin_info_ptr
= info_ptr
= (section
->buffer
7173 + to_underlying (dwo_unit
->sect_off
));
7174 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
7176 if (this_cu
->is_debug_types
)
7178 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
7180 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7181 &cu
->header
, section
,
7183 info_ptr
, rcuh_kind::TYPE
);
7184 /* This is not an assert because it can be caused by bad debug info. */
7185 if (sig_type
->signature
!= cu
->header
.signature
)
7187 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
7188 " TU at offset %s [in module %s]"),
7189 hex_string (sig_type
->signature
),
7190 hex_string (cu
->header
.signature
),
7191 sect_offset_str (dwo_unit
->sect_off
),
7192 bfd_get_filename (abfd
));
7194 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7195 /* For DWOs coming from DWP files, we don't know the CU length
7196 nor the type's offset in the TU until now. */
7197 dwo_unit
->length
= get_cu_length (&cu
->header
);
7198 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
7200 /* Establish the type offset that can be used to lookup the type.
7201 For DWO files, we don't know it until now. */
7202 sig_type
->type_offset_in_section
7203 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
7207 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7208 &cu
->header
, section
,
7210 info_ptr
, rcuh_kind::COMPILE
);
7211 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7212 /* For DWOs coming from DWP files, we don't know the CU length
7214 dwo_unit
->length
= get_cu_length (&cu
->header
);
7217 *result_dwo_abbrev_table
7218 = abbrev_table_read_table (dwarf2_per_objfile
, dwo_abbrev_section
,
7219 cu
->header
.abbrev_sect_off
);
7220 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
7221 result_dwo_abbrev_table
->get ());
7223 /* Read in the die, but leave space to copy over the attributes
7224 from the stub. This has the benefit of simplifying the rest of
7225 the code - all the work to maintain the illusion of a single
7226 DW_TAG_{compile,type}_unit DIE is done here. */
7227 num_extra_attrs
= ((stmt_list
!= NULL
)
7231 + (comp_dir
!= NULL
));
7232 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
7233 result_has_children
, num_extra_attrs
);
7235 /* Copy over the attributes from the stub to the DIE we just read in. */
7236 comp_unit_die
= *result_comp_unit_die
;
7237 i
= comp_unit_die
->num_attrs
;
7238 if (stmt_list
!= NULL
)
7239 comp_unit_die
->attrs
[i
++] = *stmt_list
;
7241 comp_unit_die
->attrs
[i
++] = *low_pc
;
7242 if (high_pc
!= NULL
)
7243 comp_unit_die
->attrs
[i
++] = *high_pc
;
7245 comp_unit_die
->attrs
[i
++] = *ranges
;
7246 if (comp_dir
!= NULL
)
7247 comp_unit_die
->attrs
[i
++] = *comp_dir
;
7248 comp_unit_die
->num_attrs
+= num_extra_attrs
;
7250 if (dwarf_die_debug
)
7252 fprintf_unfiltered (gdb_stdlog
,
7253 "Read die from %s@0x%x of %s:\n",
7254 get_section_name (section
),
7255 (unsigned) (begin_info_ptr
- section
->buffer
),
7256 bfd_get_filename (abfd
));
7257 dump_die (comp_unit_die
, dwarf_die_debug
);
7260 /* Save the comp_dir attribute. If there is no DWP file then we'll read
7261 TUs by skipping the stub and going directly to the entry in the DWO file.
7262 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
7263 to get it via circuitous means. Blech. */
7264 if (comp_dir
!= NULL
)
7265 result_reader
->comp_dir
= DW_STRING (comp_dir
);
7267 /* Skip dummy compilation units. */
7268 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
7269 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7272 *result_info_ptr
= info_ptr
;
7276 /* Subroutine of init_cutu_and_read_dies to simplify it.
7277 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
7278 Returns NULL if the specified DWO unit cannot be found. */
7280 static struct dwo_unit
*
7281 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
7282 struct die_info
*comp_unit_die
)
7284 struct dwarf2_cu
*cu
= this_cu
->cu
;
7286 struct dwo_unit
*dwo_unit
;
7287 const char *comp_dir
, *dwo_name
;
7289 gdb_assert (cu
!= NULL
);
7291 /* Yeah, we look dwo_name up again, but it simplifies the code. */
7292 dwo_name
= dwarf2_string_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
7293 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7295 if (this_cu
->is_debug_types
)
7297 struct signatured_type
*sig_type
;
7299 /* Since this_cu is the first member of struct signatured_type,
7300 we can go from a pointer to one to a pointer to the other. */
7301 sig_type
= (struct signatured_type
*) this_cu
;
7302 signature
= sig_type
->signature
;
7303 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
7307 struct attribute
*attr
;
7309 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7311 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
7313 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
7314 signature
= DW_UNSND (attr
);
7315 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
7322 /* Subroutine of init_cutu_and_read_dies to simplify it.
7323 See it for a description of the parameters.
7324 Read a TU directly from a DWO file, bypassing the stub. */
7327 init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
7328 int use_existing_cu
, int keep
,
7329 die_reader_func_ftype
*die_reader_func
,
7332 std::unique_ptr
<dwarf2_cu
> new_cu
;
7333 struct signatured_type
*sig_type
;
7334 struct die_reader_specs reader
;
7335 const gdb_byte
*info_ptr
;
7336 struct die_info
*comp_unit_die
;
7338 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7340 /* Verify we can do the following downcast, and that we have the
7342 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7343 sig_type
= (struct signatured_type
*) this_cu
;
7344 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7346 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7348 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
7349 /* There's no need to do the rereading_dwo_cu handling that
7350 init_cutu_and_read_dies does since we don't read the stub. */
7354 /* If !use_existing_cu, this_cu->cu must be NULL. */
7355 gdb_assert (this_cu
->cu
== NULL
);
7356 new_cu
.reset (new dwarf2_cu (this_cu
));
7359 /* A future optimization, if needed, would be to use an existing
7360 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7361 could share abbrev tables. */
7363 /* The abbreviation table used by READER, this must live at least as long as
7365 abbrev_table_up dwo_abbrev_table
;
7367 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
7368 NULL
/* stub_comp_unit_die */,
7369 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7371 &comp_unit_die
, &has_children
,
7372 &dwo_abbrev_table
) == 0)
7378 /* All the "real" work is done here. */
7379 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7381 /* This duplicates the code in init_cutu_and_read_dies,
7382 but the alternative is making the latter more complex.
7383 This function is only for the special case of using DWO files directly:
7384 no point in overly complicating the general case just to handle this. */
7385 if (new_cu
!= NULL
&& keep
)
7387 /* Link this CU into read_in_chain. */
7388 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7389 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7390 /* The chain owns it now. */
7395 /* Initialize a CU (or TU) and read its DIEs.
7396 If the CU defers to a DWO file, read the DWO file as well.
7398 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7399 Otherwise the table specified in the comp unit header is read in and used.
7400 This is an optimization for when we already have the abbrev table.
7402 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
7403 Otherwise, a new CU is allocated with xmalloc.
7405 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
7406 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
7408 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7409 linker) then DIE_READER_FUNC will not get called. */
7412 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
7413 struct abbrev_table
*abbrev_table
,
7414 int use_existing_cu
, int keep
,
7416 die_reader_func_ftype
*die_reader_func
,
7419 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7420 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7421 struct dwarf2_section_info
*section
= this_cu
->section
;
7422 bfd
*abfd
= get_section_bfd_owner (section
);
7423 struct dwarf2_cu
*cu
;
7424 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7425 struct die_reader_specs reader
;
7426 struct die_info
*comp_unit_die
;
7428 struct attribute
*attr
;
7429 struct signatured_type
*sig_type
= NULL
;
7430 struct dwarf2_section_info
*abbrev_section
;
7431 /* Non-zero if CU currently points to a DWO file and we need to
7432 reread it. When this happens we need to reread the skeleton die
7433 before we can reread the DWO file (this only applies to CUs, not TUs). */
7434 int rereading_dwo_cu
= 0;
7436 if (dwarf_die_debug
)
7437 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7438 this_cu
->is_debug_types
? "type" : "comp",
7439 sect_offset_str (this_cu
->sect_off
));
7441 if (use_existing_cu
)
7444 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7445 file (instead of going through the stub), short-circuit all of this. */
7446 if (this_cu
->reading_dwo_directly
)
7448 /* Narrow down the scope of possibilities to have to understand. */
7449 gdb_assert (this_cu
->is_debug_types
);
7450 gdb_assert (abbrev_table
== NULL
);
7451 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
,
7452 die_reader_func
, data
);
7456 /* This is cheap if the section is already read in. */
7457 dwarf2_read_section (objfile
, section
);
7459 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7461 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7463 std::unique_ptr
<dwarf2_cu
> new_cu
;
7464 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7467 /* If this CU is from a DWO file we need to start over, we need to
7468 refetch the attributes from the skeleton CU.
7469 This could be optimized by retrieving those attributes from when we
7470 were here the first time: the previous comp_unit_die was stored in
7471 comp_unit_obstack. But there's no data yet that we need this
7473 if (cu
->dwo_unit
!= NULL
)
7474 rereading_dwo_cu
= 1;
7478 /* If !use_existing_cu, this_cu->cu must be NULL. */
7479 gdb_assert (this_cu
->cu
== NULL
);
7480 new_cu
.reset (new dwarf2_cu (this_cu
));
7484 /* Get the header. */
7485 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7487 /* We already have the header, there's no need to read it in again. */
7488 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7492 if (this_cu
->is_debug_types
)
7494 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7495 &cu
->header
, section
,
7496 abbrev_section
, info_ptr
,
7499 /* Since per_cu is the first member of struct signatured_type,
7500 we can go from a pointer to one to a pointer to the other. */
7501 sig_type
= (struct signatured_type
*) this_cu
;
7502 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7503 gdb_assert (sig_type
->type_offset_in_tu
7504 == cu
->header
.type_cu_offset_in_tu
);
7505 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7507 /* LENGTH has not been set yet for type units if we're
7508 using .gdb_index. */
7509 this_cu
->length
= get_cu_length (&cu
->header
);
7511 /* Establish the type offset that can be used to lookup the type. */
7512 sig_type
->type_offset_in_section
=
7513 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7515 this_cu
->dwarf_version
= cu
->header
.version
;
7519 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7520 &cu
->header
, section
,
7523 rcuh_kind::COMPILE
);
7525 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7526 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
7527 this_cu
->dwarf_version
= cu
->header
.version
;
7531 /* Skip dummy compilation units. */
7532 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7533 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7536 /* If we don't have them yet, read the abbrevs for this compilation unit.
7537 And if we need to read them now, make sure they're freed when we're
7538 done (own the table through ABBREV_TABLE_HOLDER). */
7539 abbrev_table_up abbrev_table_holder
;
7540 if (abbrev_table
!= NULL
)
7541 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7545 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7546 cu
->header
.abbrev_sect_off
);
7547 abbrev_table
= abbrev_table_holder
.get ();
7550 /* Read the top level CU/TU die. */
7551 init_cu_die_reader (&reader
, cu
, section
, NULL
, abbrev_table
);
7552 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
7554 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7557 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7558 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7559 table from the DWO file and pass the ownership over to us. It will be
7560 referenced from READER, so we must make sure to free it after we're done
7563 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7564 DWO CU, that this test will fail (the attribute will not be present). */
7565 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
7566 abbrev_table_up dwo_abbrev_table
;
7569 struct dwo_unit
*dwo_unit
;
7570 struct die_info
*dwo_comp_unit_die
;
7574 complaint (&symfile_complaints
,
7575 _("compilation unit with DW_AT_GNU_dwo_name"
7576 " has children (offset %s) [in module %s]"),
7577 sect_offset_str (this_cu
->sect_off
),
7578 bfd_get_filename (abfd
));
7580 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
);
7581 if (dwo_unit
!= NULL
)
7583 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
7584 comp_unit_die
, NULL
,
7586 &dwo_comp_unit_die
, &has_children
,
7587 &dwo_abbrev_table
) == 0)
7592 comp_unit_die
= dwo_comp_unit_die
;
7596 /* Yikes, we couldn't find the rest of the DIE, we only have
7597 the stub. A complaint has already been logged. There's
7598 not much more we can do except pass on the stub DIE to
7599 die_reader_func. We don't want to throw an error on bad
7604 /* All of the above is setup for this call. Yikes. */
7605 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7607 /* Done, clean up. */
7608 if (new_cu
!= NULL
&& keep
)
7610 /* Link this CU into read_in_chain. */
7611 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7612 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7613 /* The chain owns it now. */
7618 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name if present.
7619 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed
7620 to have already done the lookup to find the DWO file).
7622 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7623 THIS_CU->is_debug_types, but nothing else.
7625 We fill in THIS_CU->length.
7627 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7628 linker) then DIE_READER_FUNC will not get called.
7630 THIS_CU->cu is always freed when done.
7631 This is done in order to not leave THIS_CU->cu in a state where we have
7632 to care whether it refers to the "main" CU or the DWO CU. */
7635 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
7636 struct dwo_file
*dwo_file
,
7637 die_reader_func_ftype
*die_reader_func
,
7640 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7641 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7642 struct dwarf2_section_info
*section
= this_cu
->section
;
7643 bfd
*abfd
= get_section_bfd_owner (section
);
7644 struct dwarf2_section_info
*abbrev_section
;
7645 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7646 struct die_reader_specs reader
;
7647 struct die_info
*comp_unit_die
;
7650 if (dwarf_die_debug
)
7651 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7652 this_cu
->is_debug_types
? "type" : "comp",
7653 sect_offset_str (this_cu
->sect_off
));
7655 gdb_assert (this_cu
->cu
== NULL
);
7657 abbrev_section
= (dwo_file
!= NULL
7658 ? &dwo_file
->sections
.abbrev
7659 : get_abbrev_section_for_cu (this_cu
));
7661 /* This is cheap if the section is already read in. */
7662 dwarf2_read_section (objfile
, section
);
7664 struct dwarf2_cu
cu (this_cu
);
7666 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7667 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7668 &cu
.header
, section
,
7669 abbrev_section
, info_ptr
,
7670 (this_cu
->is_debug_types
7672 : rcuh_kind::COMPILE
));
7674 this_cu
->length
= get_cu_length (&cu
.header
);
7676 /* Skip dummy compilation units. */
7677 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7678 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7681 abbrev_table_up abbrev_table
7682 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7683 cu
.header
.abbrev_sect_off
);
7685 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
, abbrev_table
.get ());
7686 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
7688 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7691 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
7692 does not lookup the specified DWO file.
7693 This cannot be used to read DWO files.
7695 THIS_CU->cu is always freed when done.
7696 This is done in order to not leave THIS_CU->cu in a state where we have
7697 to care whether it refers to the "main" CU or the DWO CU.
7698 We can revisit this if the data shows there's a performance issue. */
7701 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
7702 die_reader_func_ftype
*die_reader_func
,
7705 init_cutu_and_read_dies_no_follow (this_cu
, NULL
, die_reader_func
, data
);
7708 /* Type Unit Groups.
7710 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7711 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7712 so that all types coming from the same compilation (.o file) are grouped
7713 together. A future step could be to put the types in the same symtab as
7714 the CU the types ultimately came from. */
7717 hash_type_unit_group (const void *item
)
7719 const struct type_unit_group
*tu_group
7720 = (const struct type_unit_group
*) item
;
7722 return hash_stmt_list_entry (&tu_group
->hash
);
7726 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7728 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7729 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7731 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7734 /* Allocate a hash table for type unit groups. */
7737 allocate_type_unit_groups_table (struct objfile
*objfile
)
7739 return htab_create_alloc_ex (3,
7740 hash_type_unit_group
,
7743 &objfile
->objfile_obstack
,
7744 hashtab_obstack_allocate
,
7745 dummy_obstack_deallocate
);
7748 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7749 partial symtabs. We combine several TUs per psymtab to not let the size
7750 of any one psymtab grow too big. */
7751 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7752 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7754 /* Helper routine for get_type_unit_group.
7755 Create the type_unit_group object used to hold one or more TUs. */
7757 static struct type_unit_group
*
7758 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7760 struct dwarf2_per_objfile
*dwarf2_per_objfile
7761 = cu
->per_cu
->dwarf2_per_objfile
;
7762 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7763 struct dwarf2_per_cu_data
*per_cu
;
7764 struct type_unit_group
*tu_group
;
7766 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7767 struct type_unit_group
);
7768 per_cu
= &tu_group
->per_cu
;
7769 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7771 if (dwarf2_per_objfile
->using_index
)
7773 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7774 struct dwarf2_per_cu_quick_data
);
7778 unsigned int line_offset
= to_underlying (line_offset_struct
);
7779 struct partial_symtab
*pst
;
7782 /* Give the symtab a useful name for debug purposes. */
7783 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7784 name
= xstrprintf ("<type_units_%d>",
7785 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7787 name
= xstrprintf ("<type_units_at_0x%x>", line_offset
);
7789 pst
= create_partial_symtab (per_cu
, name
);
7795 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7796 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7801 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7802 STMT_LIST is a DW_AT_stmt_list attribute. */
7804 static struct type_unit_group
*
7805 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7807 struct dwarf2_per_objfile
*dwarf2_per_objfile
7808 = cu
->per_cu
->dwarf2_per_objfile
;
7809 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7810 struct type_unit_group
*tu_group
;
7812 unsigned int line_offset
;
7813 struct type_unit_group type_unit_group_for_lookup
;
7815 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7817 dwarf2_per_objfile
->type_unit_groups
=
7818 allocate_type_unit_groups_table (dwarf2_per_objfile
->objfile
);
7821 /* Do we need to create a new group, or can we use an existing one? */
7825 line_offset
= DW_UNSND (stmt_list
);
7826 ++tu_stats
->nr_symtab_sharers
;
7830 /* Ugh, no stmt_list. Rare, but we have to handle it.
7831 We can do various things here like create one group per TU or
7832 spread them over multiple groups to split up the expansion work.
7833 To avoid worst case scenarios (too many groups or too large groups)
7834 we, umm, group them in bunches. */
7835 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7836 | (tu_stats
->nr_stmt_less_type_units
7837 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7838 ++tu_stats
->nr_stmt_less_type_units
;
7841 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7842 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7843 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
7844 &type_unit_group_for_lookup
, INSERT
);
7847 tu_group
= (struct type_unit_group
*) *slot
;
7848 gdb_assert (tu_group
!= NULL
);
7852 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7853 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7855 ++tu_stats
->nr_symtabs
;
7861 /* Partial symbol tables. */
7863 /* Create a psymtab named NAME and assign it to PER_CU.
7865 The caller must fill in the following details:
7866 dirname, textlow, texthigh. */
7868 static struct partial_symtab
*
7869 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
7871 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
7872 struct partial_symtab
*pst
;
7874 pst
= start_psymtab_common (objfile
, name
, 0,
7875 objfile
->global_psymbols
,
7876 objfile
->static_psymbols
);
7878 pst
->psymtabs_addrmap_supported
= 1;
7880 /* This is the glue that links PST into GDB's symbol API. */
7881 pst
->read_symtab_private
= per_cu
;
7882 pst
->read_symtab
= dwarf2_read_symtab
;
7883 per_cu
->v
.psymtab
= pst
;
7888 /* The DATA object passed to process_psymtab_comp_unit_reader has this
7891 struct process_psymtab_comp_unit_data
7893 /* True if we are reading a DW_TAG_partial_unit. */
7895 int want_partial_unit
;
7897 /* The "pretend" language that is used if the CU doesn't declare a
7900 enum language pretend_language
;
7903 /* die_reader_func for process_psymtab_comp_unit. */
7906 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7907 const gdb_byte
*info_ptr
,
7908 struct die_info
*comp_unit_die
,
7912 struct dwarf2_cu
*cu
= reader
->cu
;
7913 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
7914 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7915 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7917 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7918 struct partial_symtab
*pst
;
7919 enum pc_bounds_kind cu_bounds_kind
;
7920 const char *filename
;
7921 struct process_psymtab_comp_unit_data
*info
7922 = (struct process_psymtab_comp_unit_data
*) data
;
7924 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !info
->want_partial_unit
)
7927 gdb_assert (! per_cu
->is_debug_types
);
7929 prepare_one_comp_unit (cu
, comp_unit_die
, info
->pretend_language
);
7931 cu
->list_in_scope
= &file_symbols
;
7933 /* Allocate a new partial symbol table structure. */
7934 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7935 if (filename
== NULL
)
7938 pst
= create_partial_symtab (per_cu
, filename
);
7940 /* This must be done before calling dwarf2_build_include_psymtabs. */
7941 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7943 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7945 dwarf2_find_base_address (comp_unit_die
, cu
);
7947 /* Possibly set the default values of LOWPC and HIGHPC from
7949 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7950 &best_highpc
, cu
, pst
);
7951 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7952 /* Store the contiguous range if it is not empty; it can be empty for
7953 CUs with no code. */
7954 addrmap_set_empty (objfile
->psymtabs_addrmap
,
7955 gdbarch_adjust_dwarf2_addr (gdbarch
,
7956 best_lowpc
+ baseaddr
),
7957 gdbarch_adjust_dwarf2_addr (gdbarch
,
7958 best_highpc
+ baseaddr
) - 1,
7961 /* Check if comp unit has_children.
7962 If so, read the rest of the partial symbols from this comp unit.
7963 If not, there's no more debug_info for this comp unit. */
7966 struct partial_die_info
*first_die
;
7967 CORE_ADDR lowpc
, highpc
;
7969 lowpc
= ((CORE_ADDR
) -1);
7970 highpc
= ((CORE_ADDR
) 0);
7972 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7974 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7975 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7977 /* If we didn't find a lowpc, set it to highpc to avoid
7978 complaints from `maint check'. */
7979 if (lowpc
== ((CORE_ADDR
) -1))
7982 /* If the compilation unit didn't have an explicit address range,
7983 then use the information extracted from its child dies. */
7984 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7987 best_highpc
= highpc
;
7990 pst
->textlow
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
);
7991 pst
->texthigh
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
);
7993 end_psymtab_common (objfile
, pst
);
7995 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
))
7998 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
7999 struct dwarf2_per_cu_data
*iter
;
8001 /* Fill in 'dependencies' here; we fill in 'users' in a
8003 pst
->number_of_dependencies
= len
;
8005 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
8007 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
8010 pst
->dependencies
[i
] = iter
->v
.psymtab
;
8012 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
8015 /* Get the list of files included in the current compilation unit,
8016 and build a psymtab for each of them. */
8017 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
8019 if (dwarf_read_debug
)
8021 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8023 fprintf_unfiltered (gdb_stdlog
,
8024 "Psymtab for %s unit @%s: %s - %s"
8025 ", %d global, %d static syms\n",
8026 per_cu
->is_debug_types
? "type" : "comp",
8027 sect_offset_str (per_cu
->sect_off
),
8028 paddress (gdbarch
, pst
->textlow
),
8029 paddress (gdbarch
, pst
->texthigh
),
8030 pst
->n_global_syms
, pst
->n_static_syms
);
8034 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8035 Process compilation unit THIS_CU for a psymtab. */
8038 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8039 int want_partial_unit
,
8040 enum language pretend_language
)
8042 /* If this compilation unit was already read in, free the
8043 cached copy in order to read it in again. This is
8044 necessary because we skipped some symbols when we first
8045 read in the compilation unit (see load_partial_dies).
8046 This problem could be avoided, but the benefit is unclear. */
8047 if (this_cu
->cu
!= NULL
)
8048 free_one_cached_comp_unit (this_cu
);
8050 if (this_cu
->is_debug_types
)
8051 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0, false,
8052 build_type_psymtabs_reader
, NULL
);
8055 process_psymtab_comp_unit_data info
;
8056 info
.want_partial_unit
= want_partial_unit
;
8057 info
.pretend_language
= pretend_language
;
8058 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0, false,
8059 process_psymtab_comp_unit_reader
, &info
);
8062 /* Age out any secondary CUs. */
8063 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
8066 /* Reader function for build_type_psymtabs. */
8069 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
8070 const gdb_byte
*info_ptr
,
8071 struct die_info
*type_unit_die
,
8075 struct dwarf2_per_objfile
*dwarf2_per_objfile
8076 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
8077 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8078 struct dwarf2_cu
*cu
= reader
->cu
;
8079 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8080 struct signatured_type
*sig_type
;
8081 struct type_unit_group
*tu_group
;
8082 struct attribute
*attr
;
8083 struct partial_die_info
*first_die
;
8084 CORE_ADDR lowpc
, highpc
;
8085 struct partial_symtab
*pst
;
8087 gdb_assert (data
== NULL
);
8088 gdb_assert (per_cu
->is_debug_types
);
8089 sig_type
= (struct signatured_type
*) per_cu
;
8094 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
8095 tu_group
= get_type_unit_group (cu
, attr
);
8097 VEC_safe_push (sig_type_ptr
, tu_group
->tus
, sig_type
);
8099 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
8100 cu
->list_in_scope
= &file_symbols
;
8101 pst
= create_partial_symtab (per_cu
, "");
8104 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8106 lowpc
= (CORE_ADDR
) -1;
8107 highpc
= (CORE_ADDR
) 0;
8108 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
8110 end_psymtab_common (objfile
, pst
);
8113 /* Struct used to sort TUs by their abbreviation table offset. */
8115 struct tu_abbrev_offset
8117 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
8118 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
8121 signatured_type
*sig_type
;
8122 sect_offset abbrev_offset
;
8125 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
8128 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
8129 const struct tu_abbrev_offset
&b
)
8131 return a
.abbrev_offset
< b
.abbrev_offset
;
8134 /* Efficiently read all the type units.
8135 This does the bulk of the work for build_type_psymtabs.
8137 The efficiency is because we sort TUs by the abbrev table they use and
8138 only read each abbrev table once. In one program there are 200K TUs
8139 sharing 8K abbrev tables.
8141 The main purpose of this function is to support building the
8142 dwarf2_per_objfile->type_unit_groups table.
8143 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
8144 can collapse the search space by grouping them by stmt_list.
8145 The savings can be significant, in the same program from above the 200K TUs
8146 share 8K stmt_list tables.
8148 FUNC is expected to call get_type_unit_group, which will create the
8149 struct type_unit_group if necessary and add it to
8150 dwarf2_per_objfile->type_unit_groups. */
8153 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8155 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8156 abbrev_table_up abbrev_table
;
8157 sect_offset abbrev_offset
;
8159 /* It's up to the caller to not call us multiple times. */
8160 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
8162 if (dwarf2_per_objfile
->all_type_units
.empty ())
8165 /* TUs typically share abbrev tables, and there can be way more TUs than
8166 abbrev tables. Sort by abbrev table to reduce the number of times we
8167 read each abbrev table in.
8168 Alternatives are to punt or to maintain a cache of abbrev tables.
8169 This is simpler and efficient enough for now.
8171 Later we group TUs by their DW_AT_stmt_list value (as this defines the
8172 symtab to use). Typically TUs with the same abbrev offset have the same
8173 stmt_list value too so in practice this should work well.
8175 The basic algorithm here is:
8177 sort TUs by abbrev table
8178 for each TU with same abbrev table:
8179 read abbrev table if first user
8180 read TU top level DIE
8181 [IWBN if DWO skeletons had DW_AT_stmt_list]
8184 if (dwarf_read_debug
)
8185 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
8187 /* Sort in a separate table to maintain the order of all_type_units
8188 for .gdb_index: TU indices directly index all_type_units. */
8189 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
8190 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
8192 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
8193 sorted_by_abbrev
.emplace_back
8194 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
8195 sig_type
->per_cu
.section
,
8196 sig_type
->per_cu
.sect_off
));
8198 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
8199 sort_tu_by_abbrev_offset
);
8201 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
8203 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
8205 /* Switch to the next abbrev table if necessary. */
8206 if (abbrev_table
== NULL
8207 || tu
.abbrev_offset
!= abbrev_offset
)
8209 abbrev_offset
= tu
.abbrev_offset
;
8211 abbrev_table_read_table (dwarf2_per_objfile
,
8212 &dwarf2_per_objfile
->abbrev
,
8214 ++tu_stats
->nr_uniq_abbrev_tables
;
8217 init_cutu_and_read_dies (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
8218 0, 0, false, build_type_psymtabs_reader
, NULL
);
8222 /* Print collected type unit statistics. */
8225 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8227 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8229 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
8230 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
8231 dwarf2_per_objfile
->all_type_units
.size ());
8232 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
8233 tu_stats
->nr_uniq_abbrev_tables
);
8234 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
8235 tu_stats
->nr_symtabs
);
8236 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
8237 tu_stats
->nr_symtab_sharers
);
8238 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
8239 tu_stats
->nr_stmt_less_type_units
);
8240 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
8241 tu_stats
->nr_all_type_units_reallocs
);
8244 /* Traversal function for build_type_psymtabs. */
8247 build_type_psymtab_dependencies (void **slot
, void *info
)
8249 struct dwarf2_per_objfile
*dwarf2_per_objfile
8250 = (struct dwarf2_per_objfile
*) info
;
8251 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8252 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
8253 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
8254 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8255 int len
= VEC_length (sig_type_ptr
, tu_group
->tus
);
8256 struct signatured_type
*iter
;
8259 gdb_assert (len
> 0);
8260 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
8262 pst
->number_of_dependencies
= len
;
8264 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
8266 VEC_iterate (sig_type_ptr
, tu_group
->tus
, i
, iter
);
8269 gdb_assert (iter
->per_cu
.is_debug_types
);
8270 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
8271 iter
->type_unit_group
= tu_group
;
8274 VEC_free (sig_type_ptr
, tu_group
->tus
);
8279 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8280 Build partial symbol tables for the .debug_types comp-units. */
8283 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8285 if (! create_all_type_units (dwarf2_per_objfile
))
8288 build_type_psymtabs_1 (dwarf2_per_objfile
);
8291 /* Traversal function for process_skeletonless_type_unit.
8292 Read a TU in a DWO file and build partial symbols for it. */
8295 process_skeletonless_type_unit (void **slot
, void *info
)
8297 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
8298 struct dwarf2_per_objfile
*dwarf2_per_objfile
8299 = (struct dwarf2_per_objfile
*) info
;
8300 struct signatured_type find_entry
, *entry
;
8302 /* If this TU doesn't exist in the global table, add it and read it in. */
8304 if (dwarf2_per_objfile
->signatured_types
== NULL
)
8306 dwarf2_per_objfile
->signatured_types
8307 = allocate_signatured_type_table (dwarf2_per_objfile
->objfile
);
8310 find_entry
.signature
= dwo_unit
->signature
;
8311 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
8313 /* If we've already seen this type there's nothing to do. What's happening
8314 is we're doing our own version of comdat-folding here. */
8318 /* This does the job that create_all_type_units would have done for
8320 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
8321 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
8324 /* This does the job that build_type_psymtabs_1 would have done. */
8325 init_cutu_and_read_dies (&entry
->per_cu
, NULL
, 0, 0, false,
8326 build_type_psymtabs_reader
, NULL
);
8331 /* Traversal function for process_skeletonless_type_units. */
8334 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
8336 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8338 if (dwo_file
->tus
!= NULL
)
8340 htab_traverse_noresize (dwo_file
->tus
,
8341 process_skeletonless_type_unit
, info
);
8347 /* Scan all TUs of DWO files, verifying we've processed them.
8348 This is needed in case a TU was emitted without its skeleton.
8349 Note: This can't be done until we know what all the DWO files are. */
8352 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8354 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
8355 if (get_dwp_file (dwarf2_per_objfile
) == NULL
8356 && dwarf2_per_objfile
->dwo_files
!= NULL
)
8358 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
,
8359 process_dwo_file_for_skeletonless_type_units
,
8360 dwarf2_per_objfile
);
8364 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
8367 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8369 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8371 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8376 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
8378 /* Set the 'user' field only if it is not already set. */
8379 if (pst
->dependencies
[j
]->user
== NULL
)
8380 pst
->dependencies
[j
]->user
= pst
;
8385 /* Build the partial symbol table by doing a quick pass through the
8386 .debug_info and .debug_abbrev sections. */
8389 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8391 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8393 if (dwarf_read_debug
)
8395 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
8396 objfile_name (objfile
));
8399 dwarf2_per_objfile
->reading_partial_symbols
= 1;
8401 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
8403 /* Any cached compilation units will be linked by the per-objfile
8404 read_in_chain. Make sure to free them when we're done. */
8405 free_cached_comp_units
freer (dwarf2_per_objfile
);
8407 build_type_psymtabs (dwarf2_per_objfile
);
8409 create_all_comp_units (dwarf2_per_objfile
);
8411 /* Create a temporary address map on a temporary obstack. We later
8412 copy this to the final obstack. */
8413 auto_obstack temp_obstack
;
8415 scoped_restore save_psymtabs_addrmap
8416 = make_scoped_restore (&objfile
->psymtabs_addrmap
,
8417 addrmap_create_mutable (&temp_obstack
));
8419 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8420 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
8422 /* This has to wait until we read the CUs, we need the list of DWOs. */
8423 process_skeletonless_type_units (dwarf2_per_objfile
);
8425 /* Now that all TUs have been processed we can fill in the dependencies. */
8426 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
8428 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
8429 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
8432 if (dwarf_read_debug
)
8433 print_tu_stats (dwarf2_per_objfile
);
8435 set_partial_user (dwarf2_per_objfile
);
8437 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
8438 &objfile
->objfile_obstack
);
8439 /* At this point we want to keep the address map. */
8440 save_psymtabs_addrmap
.release ();
8442 if (dwarf_read_debug
)
8443 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8444 objfile_name (objfile
));
8447 /* die_reader_func for load_partial_comp_unit. */
8450 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
8451 const gdb_byte
*info_ptr
,
8452 struct die_info
*comp_unit_die
,
8456 struct dwarf2_cu
*cu
= reader
->cu
;
8458 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
8460 /* Check if comp unit has_children.
8461 If so, read the rest of the partial symbols from this comp unit.
8462 If not, there's no more debug_info for this comp unit. */
8464 load_partial_dies (reader
, info_ptr
, 0);
8467 /* Load the partial DIEs for a secondary CU into memory.
8468 This is also used when rereading a primary CU with load_all_dies. */
8471 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
8473 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1, false,
8474 load_partial_comp_unit_reader
, NULL
);
8478 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
8479 struct dwarf2_section_info
*section
,
8480 struct dwarf2_section_info
*abbrev_section
,
8481 unsigned int is_dwz
)
8483 const gdb_byte
*info_ptr
;
8484 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8486 if (dwarf_read_debug
)
8487 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8488 get_section_name (section
),
8489 get_section_file_name (section
));
8491 dwarf2_read_section (objfile
, section
);
8493 info_ptr
= section
->buffer
;
8495 while (info_ptr
< section
->buffer
+ section
->size
)
8497 struct dwarf2_per_cu_data
*this_cu
;
8499 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8501 comp_unit_head cu_header
;
8502 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
8503 abbrev_section
, info_ptr
,
8504 rcuh_kind::COMPILE
);
8506 /* Save the compilation unit for later lookup. */
8507 if (cu_header
.unit_type
!= DW_UT_type
)
8509 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
8510 struct dwarf2_per_cu_data
);
8511 memset (this_cu
, 0, sizeof (*this_cu
));
8515 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
8516 struct signatured_type
);
8517 memset (sig_type
, 0, sizeof (*sig_type
));
8518 sig_type
->signature
= cu_header
.signature
;
8519 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8520 this_cu
= &sig_type
->per_cu
;
8522 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8523 this_cu
->sect_off
= sect_off
;
8524 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8525 this_cu
->is_dwz
= is_dwz
;
8526 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
8527 this_cu
->section
= section
;
8529 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
8531 info_ptr
= info_ptr
+ this_cu
->length
;
8535 /* Create a list of all compilation units in OBJFILE.
8536 This is only done for -readnow and building partial symtabs. */
8539 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8541 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
8542 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
8543 &dwarf2_per_objfile
->abbrev
, 0);
8545 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
8547 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
8551 /* Process all loaded DIEs for compilation unit CU, starting at
8552 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8553 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8554 DW_AT_ranges). See the comments of add_partial_subprogram on how
8555 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8558 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8559 CORE_ADDR
*highpc
, int set_addrmap
,
8560 struct dwarf2_cu
*cu
)
8562 struct partial_die_info
*pdi
;
8564 /* Now, march along the PDI's, descending into ones which have
8565 interesting children but skipping the children of the other ones,
8566 until we reach the end of the compilation unit. */
8574 /* Anonymous namespaces or modules have no name but have interesting
8575 children, so we need to look at them. Ditto for anonymous
8578 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8579 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8580 || pdi
->tag
== DW_TAG_imported_unit
8581 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8585 case DW_TAG_subprogram
:
8586 case DW_TAG_inlined_subroutine
:
8587 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8589 case DW_TAG_constant
:
8590 case DW_TAG_variable
:
8591 case DW_TAG_typedef
:
8592 case DW_TAG_union_type
:
8593 if (!pdi
->is_declaration
)
8595 add_partial_symbol (pdi
, cu
);
8598 case DW_TAG_class_type
:
8599 case DW_TAG_interface_type
:
8600 case DW_TAG_structure_type
:
8601 if (!pdi
->is_declaration
)
8603 add_partial_symbol (pdi
, cu
);
8605 if ((cu
->language
== language_rust
8606 || cu
->language
== language_cplus
) && pdi
->has_children
)
8607 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8610 case DW_TAG_enumeration_type
:
8611 if (!pdi
->is_declaration
)
8612 add_partial_enumeration (pdi
, cu
);
8614 case DW_TAG_base_type
:
8615 case DW_TAG_subrange_type
:
8616 /* File scope base type definitions are added to the partial
8618 add_partial_symbol (pdi
, cu
);
8620 case DW_TAG_namespace
:
8621 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8624 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8626 case DW_TAG_imported_unit
:
8628 struct dwarf2_per_cu_data
*per_cu
;
8630 /* For now we don't handle imported units in type units. */
8631 if (cu
->per_cu
->is_debug_types
)
8633 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8634 " supported in type units [in module %s]"),
8635 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
8638 per_cu
= dwarf2_find_containing_comp_unit
8639 (pdi
->d
.sect_off
, pdi
->is_dwz
,
8640 cu
->per_cu
->dwarf2_per_objfile
);
8642 /* Go read the partial unit, if needed. */
8643 if (per_cu
->v
.psymtab
== NULL
)
8644 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
8646 VEC_safe_push (dwarf2_per_cu_ptr
,
8647 cu
->per_cu
->imported_symtabs
, per_cu
);
8650 case DW_TAG_imported_declaration
:
8651 add_partial_symbol (pdi
, cu
);
8658 /* If the die has a sibling, skip to the sibling. */
8660 pdi
= pdi
->die_sibling
;
8664 /* Functions used to compute the fully scoped name of a partial DIE.
8666 Normally, this is simple. For C++, the parent DIE's fully scoped
8667 name is concatenated with "::" and the partial DIE's name.
8668 Enumerators are an exception; they use the scope of their parent
8669 enumeration type, i.e. the name of the enumeration type is not
8670 prepended to the enumerator.
8672 There are two complexities. One is DW_AT_specification; in this
8673 case "parent" means the parent of the target of the specification,
8674 instead of the direct parent of the DIE. The other is compilers
8675 which do not emit DW_TAG_namespace; in this case we try to guess
8676 the fully qualified name of structure types from their members'
8677 linkage names. This must be done using the DIE's children rather
8678 than the children of any DW_AT_specification target. We only need
8679 to do this for structures at the top level, i.e. if the target of
8680 any DW_AT_specification (if any; otherwise the DIE itself) does not
8683 /* Compute the scope prefix associated with PDI's parent, in
8684 compilation unit CU. The result will be allocated on CU's
8685 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8686 field. NULL is returned if no prefix is necessary. */
8688 partial_die_parent_scope (struct partial_die_info
*pdi
,
8689 struct dwarf2_cu
*cu
)
8691 const char *grandparent_scope
;
8692 struct partial_die_info
*parent
, *real_pdi
;
8694 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8695 then this means the parent of the specification DIE. */
8698 while (real_pdi
->has_specification
)
8699 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
8700 real_pdi
->spec_is_dwz
, cu
);
8702 parent
= real_pdi
->die_parent
;
8706 if (parent
->scope_set
)
8707 return parent
->scope
;
8711 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8713 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8714 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8715 Work around this problem here. */
8716 if (cu
->language
== language_cplus
8717 && parent
->tag
== DW_TAG_namespace
8718 && strcmp (parent
->name
, "::") == 0
8719 && grandparent_scope
== NULL
)
8721 parent
->scope
= NULL
;
8722 parent
->scope_set
= 1;
8726 if (pdi
->tag
== DW_TAG_enumerator
)
8727 /* Enumerators should not get the name of the enumeration as a prefix. */
8728 parent
->scope
= grandparent_scope
;
8729 else if (parent
->tag
== DW_TAG_namespace
8730 || parent
->tag
== DW_TAG_module
8731 || parent
->tag
== DW_TAG_structure_type
8732 || parent
->tag
== DW_TAG_class_type
8733 || parent
->tag
== DW_TAG_interface_type
8734 || parent
->tag
== DW_TAG_union_type
8735 || parent
->tag
== DW_TAG_enumeration_type
)
8737 if (grandparent_scope
== NULL
)
8738 parent
->scope
= parent
->name
;
8740 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8742 parent
->name
, 0, cu
);
8746 /* FIXME drow/2004-04-01: What should we be doing with
8747 function-local names? For partial symbols, we should probably be
8749 complaint (&symfile_complaints
,
8750 _("unhandled containing DIE tag %d for DIE at %s"),
8751 parent
->tag
, sect_offset_str (pdi
->sect_off
));
8752 parent
->scope
= grandparent_scope
;
8755 parent
->scope_set
= 1;
8756 return parent
->scope
;
8759 /* Return the fully scoped name associated with PDI, from compilation unit
8760 CU. The result will be allocated with malloc. */
8763 partial_die_full_name (struct partial_die_info
*pdi
,
8764 struct dwarf2_cu
*cu
)
8766 const char *parent_scope
;
8768 /* If this is a template instantiation, we can not work out the
8769 template arguments from partial DIEs. So, unfortunately, we have
8770 to go through the full DIEs. At least any work we do building
8771 types here will be reused if full symbols are loaded later. */
8772 if (pdi
->has_template_arguments
)
8776 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8778 struct die_info
*die
;
8779 struct attribute attr
;
8780 struct dwarf2_cu
*ref_cu
= cu
;
8782 /* DW_FORM_ref_addr is using section offset. */
8783 attr
.name
= (enum dwarf_attribute
) 0;
8784 attr
.form
= DW_FORM_ref_addr
;
8785 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8786 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8788 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8792 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8793 if (parent_scope
== NULL
)
8796 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
8800 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8802 struct dwarf2_per_objfile
*dwarf2_per_objfile
8803 = cu
->per_cu
->dwarf2_per_objfile
;
8804 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8805 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8807 const char *actual_name
= NULL
;
8809 char *built_actual_name
;
8811 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8813 built_actual_name
= partial_die_full_name (pdi
, cu
);
8814 if (built_actual_name
!= NULL
)
8815 actual_name
= built_actual_name
;
8817 if (actual_name
== NULL
)
8818 actual_name
= pdi
->name
;
8822 case DW_TAG_inlined_subroutine
:
8823 case DW_TAG_subprogram
:
8824 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
);
8825 if (pdi
->is_external
|| cu
->language
== language_ada
)
8827 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
8828 of the global scope. But in Ada, we want to be able to access
8829 nested procedures globally. So all Ada subprograms are stored
8830 in the global scope. */
8831 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8832 built_actual_name
!= NULL
,
8833 VAR_DOMAIN
, LOC_BLOCK
,
8834 &objfile
->global_psymbols
,
8835 addr
, cu
->language
, objfile
);
8839 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8840 built_actual_name
!= NULL
,
8841 VAR_DOMAIN
, LOC_BLOCK
,
8842 &objfile
->static_psymbols
,
8843 addr
, cu
->language
, objfile
);
8846 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8847 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8849 case DW_TAG_constant
:
8851 std::vector
<partial_symbol
*> *list
;
8853 if (pdi
->is_external
)
8854 list
= &objfile
->global_psymbols
;
8856 list
= &objfile
->static_psymbols
;
8857 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8858 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8859 list
, 0, cu
->language
, objfile
);
8862 case DW_TAG_variable
:
8864 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8868 && !dwarf2_per_objfile
->has_section_at_zero
)
8870 /* A global or static variable may also have been stripped
8871 out by the linker if unused, in which case its address
8872 will be nullified; do not add such variables into partial
8873 symbol table then. */
8875 else if (pdi
->is_external
)
8878 Don't enter into the minimal symbol tables as there is
8879 a minimal symbol table entry from the ELF symbols already.
8880 Enter into partial symbol table if it has a location
8881 descriptor or a type.
8882 If the location descriptor is missing, new_symbol will create
8883 a LOC_UNRESOLVED symbol, the address of the variable will then
8884 be determined from the minimal symbol table whenever the variable
8886 The address for the partial symbol table entry is not
8887 used by GDB, but it comes in handy for debugging partial symbol
8890 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8891 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8892 built_actual_name
!= NULL
,
8893 VAR_DOMAIN
, LOC_STATIC
,
8894 &objfile
->global_psymbols
,
8896 cu
->language
, objfile
);
8900 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8902 /* Static Variable. Skip symbols whose value we cannot know (those
8903 without location descriptors or constant values). */
8904 if (!has_loc
&& !pdi
->has_const_value
)
8906 xfree (built_actual_name
);
8910 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8911 built_actual_name
!= NULL
,
8912 VAR_DOMAIN
, LOC_STATIC
,
8913 &objfile
->static_psymbols
,
8914 has_loc
? addr
+ baseaddr
: (CORE_ADDR
) 0,
8915 cu
->language
, objfile
);
8918 case DW_TAG_typedef
:
8919 case DW_TAG_base_type
:
8920 case DW_TAG_subrange_type
:
8921 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8922 built_actual_name
!= NULL
,
8923 VAR_DOMAIN
, LOC_TYPEDEF
,
8924 &objfile
->static_psymbols
,
8925 0, cu
->language
, objfile
);
8927 case DW_TAG_imported_declaration
:
8928 case DW_TAG_namespace
:
8929 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8930 built_actual_name
!= NULL
,
8931 VAR_DOMAIN
, LOC_TYPEDEF
,
8932 &objfile
->global_psymbols
,
8933 0, cu
->language
, objfile
);
8936 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8937 built_actual_name
!= NULL
,
8938 MODULE_DOMAIN
, LOC_TYPEDEF
,
8939 &objfile
->global_psymbols
,
8940 0, cu
->language
, objfile
);
8942 case DW_TAG_class_type
:
8943 case DW_TAG_interface_type
:
8944 case DW_TAG_structure_type
:
8945 case DW_TAG_union_type
:
8946 case DW_TAG_enumeration_type
:
8947 /* Skip external references. The DWARF standard says in the section
8948 about "Structure, Union, and Class Type Entries": "An incomplete
8949 structure, union or class type is represented by a structure,
8950 union or class entry that does not have a byte size attribute
8951 and that has a DW_AT_declaration attribute." */
8952 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8954 xfree (built_actual_name
);
8958 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8959 static vs. global. */
8960 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8961 built_actual_name
!= NULL
,
8962 STRUCT_DOMAIN
, LOC_TYPEDEF
,
8963 cu
->language
== language_cplus
8964 ? &objfile
->global_psymbols
8965 : &objfile
->static_psymbols
,
8966 0, cu
->language
, objfile
);
8969 case DW_TAG_enumerator
:
8970 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8971 built_actual_name
!= NULL
,
8972 VAR_DOMAIN
, LOC_CONST
,
8973 cu
->language
== language_cplus
8974 ? &objfile
->global_psymbols
8975 : &objfile
->static_psymbols
,
8976 0, cu
->language
, objfile
);
8982 xfree (built_actual_name
);
8985 /* Read a partial die corresponding to a namespace; also, add a symbol
8986 corresponding to that namespace to the symbol table. NAMESPACE is
8987 the name of the enclosing namespace. */
8990 add_partial_namespace (struct partial_die_info
*pdi
,
8991 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8992 int set_addrmap
, struct dwarf2_cu
*cu
)
8994 /* Add a symbol for the namespace. */
8996 add_partial_symbol (pdi
, cu
);
8998 /* Now scan partial symbols in that namespace. */
9000 if (pdi
->has_children
)
9001 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9004 /* Read a partial die corresponding to a Fortran module. */
9007 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
9008 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
9010 /* Add a symbol for the namespace. */
9012 add_partial_symbol (pdi
, cu
);
9014 /* Now scan partial symbols in that module. */
9016 if (pdi
->has_children
)
9017 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9020 /* Read a partial die corresponding to a subprogram or an inlined
9021 subprogram and create a partial symbol for that subprogram.
9022 When the CU language allows it, this routine also defines a partial
9023 symbol for each nested subprogram that this subprogram contains.
9024 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
9025 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
9027 PDI may also be a lexical block, in which case we simply search
9028 recursively for subprograms defined inside that lexical block.
9029 Again, this is only performed when the CU language allows this
9030 type of definitions. */
9033 add_partial_subprogram (struct partial_die_info
*pdi
,
9034 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9035 int set_addrmap
, struct dwarf2_cu
*cu
)
9037 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
9039 if (pdi
->has_pc_info
)
9041 if (pdi
->lowpc
< *lowpc
)
9042 *lowpc
= pdi
->lowpc
;
9043 if (pdi
->highpc
> *highpc
)
9044 *highpc
= pdi
->highpc
;
9047 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9048 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9053 baseaddr
= ANOFFSET (objfile
->section_offsets
,
9054 SECT_OFF_TEXT (objfile
));
9055 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
9056 pdi
->lowpc
+ baseaddr
);
9057 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
9058 pdi
->highpc
+ baseaddr
);
9059 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
9060 cu
->per_cu
->v
.psymtab
);
9064 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
9066 if (!pdi
->is_declaration
)
9067 /* Ignore subprogram DIEs that do not have a name, they are
9068 illegal. Do not emit a complaint at this point, we will
9069 do so when we convert this psymtab into a symtab. */
9071 add_partial_symbol (pdi
, cu
);
9075 if (! pdi
->has_children
)
9078 if (cu
->language
== language_ada
)
9080 pdi
= pdi
->die_child
;
9084 if (pdi
->tag
== DW_TAG_subprogram
9085 || pdi
->tag
== DW_TAG_inlined_subroutine
9086 || pdi
->tag
== DW_TAG_lexical_block
)
9087 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9088 pdi
= pdi
->die_sibling
;
9093 /* Read a partial die corresponding to an enumeration type. */
9096 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
9097 struct dwarf2_cu
*cu
)
9099 struct partial_die_info
*pdi
;
9101 if (enum_pdi
->name
!= NULL
)
9102 add_partial_symbol (enum_pdi
, cu
);
9104 pdi
= enum_pdi
->die_child
;
9107 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
9108 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
9110 add_partial_symbol (pdi
, cu
);
9111 pdi
= pdi
->die_sibling
;
9115 /* Return the initial uleb128 in the die at INFO_PTR. */
9118 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
9120 unsigned int bytes_read
;
9122 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9125 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
9126 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
9128 Return the corresponding abbrev, or NULL if the number is zero (indicating
9129 an empty DIE). In either case *BYTES_READ will be set to the length of
9130 the initial number. */
9132 static struct abbrev_info
*
9133 peek_die_abbrev (const die_reader_specs
&reader
,
9134 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
9136 dwarf2_cu
*cu
= reader
.cu
;
9137 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
9138 unsigned int abbrev_number
9139 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
9141 if (abbrev_number
== 0)
9144 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
9147 error (_("Dwarf Error: Could not find abbrev number %d in %s"
9148 " at offset %s [in module %s]"),
9149 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
9150 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
9156 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9157 Returns a pointer to the end of a series of DIEs, terminated by an empty
9158 DIE. Any children of the skipped DIEs will also be skipped. */
9160 static const gdb_byte
*
9161 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
9165 unsigned int bytes_read
;
9166 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
9169 return info_ptr
+ bytes_read
;
9171 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
9175 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9176 INFO_PTR should point just after the initial uleb128 of a DIE, and the
9177 abbrev corresponding to that skipped uleb128 should be passed in
9178 ABBREV. Returns a pointer to this DIE's sibling, skipping any
9181 static const gdb_byte
*
9182 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
9183 struct abbrev_info
*abbrev
)
9185 unsigned int bytes_read
;
9186 struct attribute attr
;
9187 bfd
*abfd
= reader
->abfd
;
9188 struct dwarf2_cu
*cu
= reader
->cu
;
9189 const gdb_byte
*buffer
= reader
->buffer
;
9190 const gdb_byte
*buffer_end
= reader
->buffer_end
;
9191 unsigned int form
, i
;
9193 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
9195 /* The only abbrev we care about is DW_AT_sibling. */
9196 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
9198 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
9199 if (attr
.form
== DW_FORM_ref_addr
)
9200 complaint (&symfile_complaints
,
9201 _("ignoring absolute DW_AT_sibling"));
9204 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
9205 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
9207 if (sibling_ptr
< info_ptr
)
9208 complaint (&symfile_complaints
,
9209 _("DW_AT_sibling points backwards"));
9210 else if (sibling_ptr
> reader
->buffer_end
)
9211 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
9217 /* If it isn't DW_AT_sibling, skip this attribute. */
9218 form
= abbrev
->attrs
[i
].form
;
9222 case DW_FORM_ref_addr
:
9223 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
9224 and later it is offset sized. */
9225 if (cu
->header
.version
== 2)
9226 info_ptr
+= cu
->header
.addr_size
;
9228 info_ptr
+= cu
->header
.offset_size
;
9230 case DW_FORM_GNU_ref_alt
:
9231 info_ptr
+= cu
->header
.offset_size
;
9234 info_ptr
+= cu
->header
.addr_size
;
9241 case DW_FORM_flag_present
:
9242 case DW_FORM_implicit_const
:
9254 case DW_FORM_ref_sig8
:
9257 case DW_FORM_data16
:
9260 case DW_FORM_string
:
9261 read_direct_string (abfd
, info_ptr
, &bytes_read
);
9262 info_ptr
+= bytes_read
;
9264 case DW_FORM_sec_offset
:
9266 case DW_FORM_GNU_strp_alt
:
9267 info_ptr
+= cu
->header
.offset_size
;
9269 case DW_FORM_exprloc
:
9271 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9272 info_ptr
+= bytes_read
;
9274 case DW_FORM_block1
:
9275 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
9277 case DW_FORM_block2
:
9278 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
9280 case DW_FORM_block4
:
9281 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
9285 case DW_FORM_ref_udata
:
9286 case DW_FORM_GNU_addr_index
:
9287 case DW_FORM_GNU_str_index
:
9288 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
9290 case DW_FORM_indirect
:
9291 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9292 info_ptr
+= bytes_read
;
9293 /* We need to continue parsing from here, so just go back to
9295 goto skip_attribute
;
9298 error (_("Dwarf Error: Cannot handle %s "
9299 "in DWARF reader [in module %s]"),
9300 dwarf_form_name (form
),
9301 bfd_get_filename (abfd
));
9305 if (abbrev
->has_children
)
9306 return skip_children (reader
, info_ptr
);
9311 /* Locate ORIG_PDI's sibling.
9312 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
9314 static const gdb_byte
*
9315 locate_pdi_sibling (const struct die_reader_specs
*reader
,
9316 struct partial_die_info
*orig_pdi
,
9317 const gdb_byte
*info_ptr
)
9319 /* Do we know the sibling already? */
9321 if (orig_pdi
->sibling
)
9322 return orig_pdi
->sibling
;
9324 /* Are there any children to deal with? */
9326 if (!orig_pdi
->has_children
)
9329 /* Skip the children the long way. */
9331 return skip_children (reader
, info_ptr
);
9334 /* Expand this partial symbol table into a full symbol table. SELF is
9338 dwarf2_read_symtab (struct partial_symtab
*self
,
9339 struct objfile
*objfile
)
9341 struct dwarf2_per_objfile
*dwarf2_per_objfile
9342 = get_dwarf2_per_objfile (objfile
);
9346 warning (_("bug: psymtab for %s is already read in."),
9353 printf_filtered (_("Reading in symbols for %s..."),
9355 gdb_flush (gdb_stdout
);
9358 /* If this psymtab is constructed from a debug-only objfile, the
9359 has_section_at_zero flag will not necessarily be correct. We
9360 can get the correct value for this flag by looking at the data
9361 associated with the (presumably stripped) associated objfile. */
9362 if (objfile
->separate_debug_objfile_backlink
)
9364 struct dwarf2_per_objfile
*dpo_backlink
9365 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
9367 dwarf2_per_objfile
->has_section_at_zero
9368 = dpo_backlink
->has_section_at_zero
;
9371 dwarf2_per_objfile
->reading_partial_symbols
= 0;
9373 psymtab_to_symtab_1 (self
);
9375 /* Finish up the debug error message. */
9377 printf_filtered (_("done.\n"));
9380 process_cu_includes (dwarf2_per_objfile
);
9383 /* Reading in full CUs. */
9385 /* Add PER_CU to the queue. */
9388 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9389 enum language pretend_language
)
9391 struct dwarf2_queue_item
*item
;
9394 item
= XNEW (struct dwarf2_queue_item
);
9395 item
->per_cu
= per_cu
;
9396 item
->pretend_language
= pretend_language
;
9399 if (dwarf2_queue
== NULL
)
9400 dwarf2_queue
= item
;
9402 dwarf2_queue_tail
->next
= item
;
9404 dwarf2_queue_tail
= item
;
9407 /* If PER_CU is not yet queued, add it to the queue.
9408 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9410 The result is non-zero if PER_CU was queued, otherwise the result is zero
9411 meaning either PER_CU is already queued or it is already loaded.
9413 N.B. There is an invariant here that if a CU is queued then it is loaded.
9414 The caller is required to load PER_CU if we return non-zero. */
9417 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9418 struct dwarf2_per_cu_data
*per_cu
,
9419 enum language pretend_language
)
9421 /* We may arrive here during partial symbol reading, if we need full
9422 DIEs to process an unusual case (e.g. template arguments). Do
9423 not queue PER_CU, just tell our caller to load its DIEs. */
9424 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
9426 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
9431 /* Mark the dependence relation so that we don't flush PER_CU
9433 if (dependent_cu
!= NULL
)
9434 dwarf2_add_dependence (dependent_cu
, per_cu
);
9436 /* If it's already on the queue, we have nothing to do. */
9440 /* If the compilation unit is already loaded, just mark it as
9442 if (per_cu
->cu
!= NULL
)
9444 per_cu
->cu
->last_used
= 0;
9448 /* Add it to the queue. */
9449 queue_comp_unit (per_cu
, pretend_language
);
9454 /* Process the queue. */
9457 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9459 struct dwarf2_queue_item
*item
, *next_item
;
9461 if (dwarf_read_debug
)
9463 fprintf_unfiltered (gdb_stdlog
,
9464 "Expanding one or more symtabs of objfile %s ...\n",
9465 objfile_name (dwarf2_per_objfile
->objfile
));
9468 /* The queue starts out with one item, but following a DIE reference
9469 may load a new CU, adding it to the end of the queue. */
9470 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
9472 if ((dwarf2_per_objfile
->using_index
9473 ? !item
->per_cu
->v
.quick
->compunit_symtab
9474 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
9475 /* Skip dummy CUs. */
9476 && item
->per_cu
->cu
!= NULL
)
9478 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
9479 unsigned int debug_print_threshold
;
9482 if (per_cu
->is_debug_types
)
9484 struct signatured_type
*sig_type
=
9485 (struct signatured_type
*) per_cu
;
9487 sprintf (buf
, "TU %s at offset %s",
9488 hex_string (sig_type
->signature
),
9489 sect_offset_str (per_cu
->sect_off
));
9490 /* There can be 100s of TUs.
9491 Only print them in verbose mode. */
9492 debug_print_threshold
= 2;
9496 sprintf (buf
, "CU at offset %s",
9497 sect_offset_str (per_cu
->sect_off
));
9498 debug_print_threshold
= 1;
9501 if (dwarf_read_debug
>= debug_print_threshold
)
9502 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9504 if (per_cu
->is_debug_types
)
9505 process_full_type_unit (per_cu
, item
->pretend_language
);
9507 process_full_comp_unit (per_cu
, item
->pretend_language
);
9509 if (dwarf_read_debug
>= debug_print_threshold
)
9510 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9513 item
->per_cu
->queued
= 0;
9514 next_item
= item
->next
;
9518 dwarf2_queue_tail
= NULL
;
9520 if (dwarf_read_debug
)
9522 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9523 objfile_name (dwarf2_per_objfile
->objfile
));
9527 /* Read in full symbols for PST, and anything it depends on. */
9530 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
9532 struct dwarf2_per_cu_data
*per_cu
;
9538 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
9539 if (!pst
->dependencies
[i
]->readin
9540 && pst
->dependencies
[i
]->user
== NULL
)
9542 /* Inform about additional files that need to be read in. */
9545 /* FIXME: i18n: Need to make this a single string. */
9546 fputs_filtered (" ", gdb_stdout
);
9548 fputs_filtered ("and ", gdb_stdout
);
9550 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
9551 wrap_here (""); /* Flush output. */
9552 gdb_flush (gdb_stdout
);
9554 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
9557 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
9561 /* It's an include file, no symbols to read for it.
9562 Everything is in the parent symtab. */
9567 dw2_do_instantiate_symtab (per_cu
, false);
9570 /* Trivial hash function for die_info: the hash value of a DIE
9571 is its offset in .debug_info for this objfile. */
9574 die_hash (const void *item
)
9576 const struct die_info
*die
= (const struct die_info
*) item
;
9578 return to_underlying (die
->sect_off
);
9581 /* Trivial comparison function for die_info structures: two DIEs
9582 are equal if they have the same offset. */
9585 die_eq (const void *item_lhs
, const void *item_rhs
)
9587 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9588 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9590 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9593 /* die_reader_func for load_full_comp_unit.
9594 This is identical to read_signatured_type_reader,
9595 but is kept separate for now. */
9598 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
9599 const gdb_byte
*info_ptr
,
9600 struct die_info
*comp_unit_die
,
9604 struct dwarf2_cu
*cu
= reader
->cu
;
9605 enum language
*language_ptr
= (enum language
*) data
;
9607 gdb_assert (cu
->die_hash
== NULL
);
9609 htab_create_alloc_ex (cu
->header
.length
/ 12,
9613 &cu
->comp_unit_obstack
,
9614 hashtab_obstack_allocate
,
9615 dummy_obstack_deallocate
);
9618 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
9619 &info_ptr
, comp_unit_die
);
9620 cu
->dies
= comp_unit_die
;
9621 /* comp_unit_die is not stored in die_hash, no need. */
9623 /* We try not to read any attributes in this function, because not
9624 all CUs needed for references have been loaded yet, and symbol
9625 table processing isn't initialized. But we have to set the CU language,
9626 or we won't be able to build types correctly.
9627 Similarly, if we do not read the producer, we can not apply
9628 producer-specific interpretation. */
9629 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
9632 /* Load the DIEs associated with PER_CU into memory. */
9635 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
9637 enum language pretend_language
)
9639 gdb_assert (! this_cu
->is_debug_types
);
9641 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1, skip_partial
,
9642 load_full_comp_unit_reader
, &pretend_language
);
9645 /* Add a DIE to the delayed physname list. */
9648 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9649 const char *name
, struct die_info
*die
,
9650 struct dwarf2_cu
*cu
)
9652 struct delayed_method_info mi
;
9654 mi
.fnfield_index
= fnfield_index
;
9658 cu
->method_list
.push_back (mi
);
9661 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9662 "const" / "volatile". If so, decrements LEN by the length of the
9663 modifier and return true. Otherwise return false. */
9667 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9669 size_t mod_len
= sizeof (mod
) - 1;
9670 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9678 /* Compute the physnames of any methods on the CU's method list.
9680 The computation of method physnames is delayed in order to avoid the
9681 (bad) condition that one of the method's formal parameters is of an as yet
9685 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9687 /* Only C++ delays computing physnames. */
9688 if (cu
->method_list
.empty ())
9690 gdb_assert (cu
->language
== language_cplus
);
9692 for (struct delayed_method_info
&mi
: cu
->method_list
)
9694 const char *physname
;
9695 struct fn_fieldlist
*fn_flp
9696 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9697 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9698 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9699 = physname
? physname
: "";
9701 /* Since there's no tag to indicate whether a method is a
9702 const/volatile overload, extract that information out of the
9704 if (physname
!= NULL
)
9706 size_t len
= strlen (physname
);
9710 if (physname
[len
] == ')') /* shortcut */
9712 else if (check_modifier (physname
, len
, " const"))
9713 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9714 else if (check_modifier (physname
, len
, " volatile"))
9715 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9722 /* The list is no longer needed. */
9723 cu
->method_list
.clear ();
9726 /* Go objects should be embedded in a DW_TAG_module DIE,
9727 and it's not clear if/how imported objects will appear.
9728 To keep Go support simple until that's worked out,
9729 go back through what we've read and create something usable.
9730 We could do this while processing each DIE, and feels kinda cleaner,
9731 but that way is more invasive.
9732 This is to, for example, allow the user to type "p var" or "b main"
9733 without having to specify the package name, and allow lookups
9734 of module.object to work in contexts that use the expression
9738 fixup_go_packaging (struct dwarf2_cu
*cu
)
9740 char *package_name
= NULL
;
9741 struct pending
*list
;
9744 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
9746 for (i
= 0; i
< list
->nsyms
; ++i
)
9748 struct symbol
*sym
= list
->symbol
[i
];
9750 if (SYMBOL_LANGUAGE (sym
) == language_go
9751 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9753 char *this_package_name
= go_symbol_package_name (sym
);
9755 if (this_package_name
== NULL
)
9757 if (package_name
== NULL
)
9758 package_name
= this_package_name
;
9761 struct objfile
*objfile
9762 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9763 if (strcmp (package_name
, this_package_name
) != 0)
9764 complaint (&symfile_complaints
,
9765 _("Symtab %s has objects from two different Go packages: %s and %s"),
9766 (symbol_symtab (sym
) != NULL
9767 ? symtab_to_filename_for_display
9768 (symbol_symtab (sym
))
9769 : objfile_name (objfile
)),
9770 this_package_name
, package_name
);
9771 xfree (this_package_name
);
9777 if (package_name
!= NULL
)
9779 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9780 const char *saved_package_name
9781 = (const char *) obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
9783 strlen (package_name
));
9784 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9785 saved_package_name
);
9788 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
9790 sym
= allocate_symbol (objfile
);
9791 SYMBOL_SET_LANGUAGE (sym
, language_go
, &objfile
->objfile_obstack
);
9792 SYMBOL_SET_NAMES (sym
, saved_package_name
,
9793 strlen (saved_package_name
), 0, objfile
);
9794 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9795 e.g., "main" finds the "main" module and not C's main(). */
9796 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9797 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9798 SYMBOL_TYPE (sym
) = type
;
9800 add_symbol_to_list (sym
, &global_symbols
);
9802 xfree (package_name
);
9806 /* Allocate a fully-qualified name consisting of the two parts on the
9810 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9812 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9815 /* A helper that allocates a struct discriminant_info to attach to a
9818 static struct discriminant_info
*
9819 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9822 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9823 gdb_assert (discriminant_index
== -1
9824 || (discriminant_index
>= 0
9825 && discriminant_index
< TYPE_NFIELDS (type
)));
9826 gdb_assert (default_index
== -1
9827 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9829 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9831 struct discriminant_info
*disc
9832 = ((struct discriminant_info
*)
9834 offsetof (struct discriminant_info
, discriminants
)
9835 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9836 disc
->default_index
= default_index
;
9837 disc
->discriminant_index
= discriminant_index
;
9839 struct dynamic_prop prop
;
9840 prop
.kind
= PROP_UNDEFINED
;
9841 prop
.data
.baton
= disc
;
9843 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9848 /* Some versions of rustc emitted enums in an unusual way.
9850 Ordinary enums were emitted as unions. The first element of each
9851 structure in the union was named "RUST$ENUM$DISR". This element
9852 held the discriminant.
9854 These versions of Rust also implemented the "non-zero"
9855 optimization. When the enum had two values, and one is empty and
9856 the other holds a pointer that cannot be zero, the pointer is used
9857 as the discriminant, with a zero value meaning the empty variant.
9858 Here, the union's first member is of the form
9859 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9860 where the fieldnos are the indices of the fields that should be
9861 traversed in order to find the field (which may be several fields deep)
9862 and the variantname is the name of the variant of the case when the
9865 This function recognizes whether TYPE is of one of these forms,
9866 and, if so, smashes it to be a variant type. */
9869 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9871 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9873 /* We don't need to deal with empty enums. */
9874 if (TYPE_NFIELDS (type
) == 0)
9877 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9878 if (TYPE_NFIELDS (type
) == 1
9879 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9881 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9883 /* Decode the field name to find the offset of the
9885 ULONGEST bit_offset
= 0;
9886 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9887 while (name
[0] >= '0' && name
[0] <= '9')
9890 unsigned long index
= strtoul (name
, &tail
, 10);
9893 || index
>= TYPE_NFIELDS (field_type
)
9894 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9895 != FIELD_LOC_KIND_BITPOS
))
9897 complaint (&symfile_complaints
,
9898 _("Could not parse Rust enum encoding string \"%s\""
9900 TYPE_FIELD_NAME (type
, 0),
9901 objfile_name (objfile
));
9906 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9907 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9910 /* Make a union to hold the variants. */
9911 struct type
*union_type
= alloc_type (objfile
);
9912 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9913 TYPE_NFIELDS (union_type
) = 3;
9914 TYPE_FIELDS (union_type
)
9915 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
9916 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9917 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9919 /* Put the discriminant must at index 0. */
9920 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
9921 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9922 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9923 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
9925 /* The order of fields doesn't really matter, so put the real
9926 field at index 1 and the data-less field at index 2. */
9927 struct discriminant_info
*disc
9928 = alloc_discriminant_info (union_type
, 0, 1);
9929 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
9930 TYPE_FIELD_NAME (union_type
, 1)
9931 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
9932 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
9933 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9934 TYPE_FIELD_NAME (union_type
, 1));
9936 const char *dataless_name
9937 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9939 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9941 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
9942 /* NAME points into the original discriminant name, which
9943 already has the correct lifetime. */
9944 TYPE_FIELD_NAME (union_type
, 2) = name
;
9945 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
9946 disc
->discriminants
[2] = 0;
9948 /* Smash this type to be a structure type. We have to do this
9949 because the type has already been recorded. */
9950 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9951 TYPE_NFIELDS (type
) = 1;
9953 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
9955 /* Install the variant part. */
9956 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9957 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9958 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9960 else if (TYPE_NFIELDS (type
) == 1)
9962 /* We assume that a union with a single field is a univariant
9964 /* Smash this type to be a structure type. We have to do this
9965 because the type has already been recorded. */
9966 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9968 /* Make a union to hold the variants. */
9969 struct type
*union_type
= alloc_type (objfile
);
9970 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9971 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
9972 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9973 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9974 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
9976 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
9977 const char *variant_name
9978 = rust_last_path_segment (TYPE_NAME (field_type
));
9979 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
9980 TYPE_NAME (field_type
)
9981 = rust_fully_qualify (&objfile
->objfile_obstack
,
9982 TYPE_NAME (type
), variant_name
);
9984 /* Install the union in the outer struct type. */
9985 TYPE_NFIELDS (type
) = 1;
9987 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
9988 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9989 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9990 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9992 alloc_discriminant_info (union_type
, -1, 0);
9996 struct type
*disr_type
= nullptr;
9997 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
9999 disr_type
= TYPE_FIELD_TYPE (type
, i
);
10001 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
10003 /* All fields of a true enum will be structs. */
10006 else if (TYPE_NFIELDS (disr_type
) == 0)
10008 /* Could be data-less variant, so keep going. */
10009 disr_type
= nullptr;
10011 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
10012 "RUST$ENUM$DISR") != 0)
10014 /* Not a Rust enum. */
10024 /* If we got here without a discriminant, then it's probably
10026 if (disr_type
== nullptr)
10029 /* Smash this type to be a structure type. We have to do this
10030 because the type has already been recorded. */
10031 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10033 /* Make a union to hold the variants. */
10034 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
10035 struct type
*union_type
= alloc_type (objfile
);
10036 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10037 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
10038 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10039 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10040 TYPE_FIELDS (union_type
)
10041 = (struct field
*) TYPE_ZALLOC (union_type
,
10042 (TYPE_NFIELDS (union_type
)
10043 * sizeof (struct field
)));
10045 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
10046 TYPE_NFIELDS (type
) * sizeof (struct field
));
10048 /* Install the discriminant at index 0 in the union. */
10049 TYPE_FIELD (union_type
, 0) = *disr_field
;
10050 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10051 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10053 /* Install the union in the outer struct type. */
10054 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10055 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10056 TYPE_NFIELDS (type
) = 1;
10058 /* Set the size and offset of the union type. */
10059 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10061 /* We need a way to find the correct discriminant given a
10062 variant name. For convenience we build a map here. */
10063 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
10064 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
10065 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
10067 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
10070 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
10071 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
10075 int n_fields
= TYPE_NFIELDS (union_type
);
10076 struct discriminant_info
*disc
10077 = alloc_discriminant_info (union_type
, 0, -1);
10078 /* Skip the discriminant here. */
10079 for (int i
= 1; i
< n_fields
; ++i
)
10081 /* Find the final word in the name of this variant's type.
10082 That name can be used to look up the correct
10084 const char *variant_name
10085 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
10088 auto iter
= discriminant_map
.find (variant_name
);
10089 if (iter
!= discriminant_map
.end ())
10090 disc
->discriminants
[i
] = iter
->second
;
10092 /* Remove the discriminant field, if it exists. */
10093 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
10094 if (TYPE_NFIELDS (sub_type
) > 0)
10096 --TYPE_NFIELDS (sub_type
);
10097 ++TYPE_FIELDS (sub_type
);
10099 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
10100 TYPE_NAME (sub_type
)
10101 = rust_fully_qualify (&objfile
->objfile_obstack
,
10102 TYPE_NAME (type
), variant_name
);
10107 /* Rewrite some Rust unions to be structures with variants parts. */
10110 rust_union_quirks (struct dwarf2_cu
*cu
)
10112 gdb_assert (cu
->language
== language_rust
);
10113 for (struct type
*type
: cu
->rust_unions
)
10114 quirk_rust_enum (type
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
10115 /* We don't need this any more. */
10116 cu
->rust_unions
.clear ();
10119 /* Return the symtab for PER_CU. This works properly regardless of
10120 whether we're using the index or psymtabs. */
10122 static struct compunit_symtab
*
10123 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
10125 return (per_cu
->dwarf2_per_objfile
->using_index
10126 ? per_cu
->v
.quick
->compunit_symtab
10127 : per_cu
->v
.psymtab
->compunit_symtab
);
10130 /* A helper function for computing the list of all symbol tables
10131 included by PER_CU. */
10134 recursively_compute_inclusions (VEC (compunit_symtab_ptr
) **result
,
10135 htab_t all_children
, htab_t all_type_symtabs
,
10136 struct dwarf2_per_cu_data
*per_cu
,
10137 struct compunit_symtab
*immediate_parent
)
10141 struct compunit_symtab
*cust
;
10142 struct dwarf2_per_cu_data
*iter
;
10144 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
10147 /* This inclusion and its children have been processed. */
10152 /* Only add a CU if it has a symbol table. */
10153 cust
= get_compunit_symtab (per_cu
);
10156 /* If this is a type unit only add its symbol table if we haven't
10157 seen it yet (type unit per_cu's can share symtabs). */
10158 if (per_cu
->is_debug_types
)
10160 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
10164 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
10165 if (cust
->user
== NULL
)
10166 cust
->user
= immediate_parent
;
10171 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
10172 if (cust
->user
== NULL
)
10173 cust
->user
= immediate_parent
;
10178 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, ix
, iter
);
10181 recursively_compute_inclusions (result
, all_children
,
10182 all_type_symtabs
, iter
, cust
);
10186 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
10190 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
10192 gdb_assert (! per_cu
->is_debug_types
);
10194 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
))
10197 struct dwarf2_per_cu_data
*per_cu_iter
;
10198 struct compunit_symtab
*compunit_symtab_iter
;
10199 VEC (compunit_symtab_ptr
) *result_symtabs
= NULL
;
10200 htab_t all_children
, all_type_symtabs
;
10201 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
10203 /* If we don't have a symtab, we can just skip this case. */
10207 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10208 NULL
, xcalloc
, xfree
);
10209 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10210 NULL
, xcalloc
, xfree
);
10213 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
,
10217 recursively_compute_inclusions (&result_symtabs
, all_children
,
10218 all_type_symtabs
, per_cu_iter
,
10222 /* Now we have a transitive closure of all the included symtabs. */
10223 len
= VEC_length (compunit_symtab_ptr
, result_symtabs
);
10225 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
10226 struct compunit_symtab
*, len
+ 1);
10228 VEC_iterate (compunit_symtab_ptr
, result_symtabs
, ix
,
10229 compunit_symtab_iter
);
10231 cust
->includes
[ix
] = compunit_symtab_iter
;
10232 cust
->includes
[len
] = NULL
;
10234 VEC_free (compunit_symtab_ptr
, result_symtabs
);
10235 htab_delete (all_children
);
10236 htab_delete (all_type_symtabs
);
10240 /* Compute the 'includes' field for the symtabs of all the CUs we just
10244 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
10247 struct dwarf2_per_cu_data
*iter
;
10250 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
10254 if (! iter
->is_debug_types
)
10255 compute_compunit_symtab_includes (iter
);
10258 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
10261 /* Generate full symbol information for PER_CU, whose DIEs have
10262 already been loaded into memory. */
10265 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
10266 enum language pretend_language
)
10268 struct dwarf2_cu
*cu
= per_cu
->cu
;
10269 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10270 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10271 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10272 CORE_ADDR lowpc
, highpc
;
10273 struct compunit_symtab
*cust
;
10274 CORE_ADDR baseaddr
;
10275 struct block
*static_block
;
10278 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10281 scoped_free_pendings free_pending
;
10283 /* Clear the list here in case something was left over. */
10284 cu
->method_list
.clear ();
10286 cu
->list_in_scope
= &file_symbols
;
10288 cu
->language
= pretend_language
;
10289 cu
->language_defn
= language_def (cu
->language
);
10291 /* Do line number decoding in read_file_scope () */
10292 process_die (cu
->dies
, cu
);
10294 /* For now fudge the Go package. */
10295 if (cu
->language
== language_go
)
10296 fixup_go_packaging (cu
);
10298 /* Now that we have processed all the DIEs in the CU, all the types
10299 should be complete, and it should now be safe to compute all of the
10301 compute_delayed_physnames (cu
);
10303 if (cu
->language
== language_rust
)
10304 rust_union_quirks (cu
);
10306 /* Some compilers don't define a DW_AT_high_pc attribute for the
10307 compilation unit. If the DW_AT_high_pc is missing, synthesize
10308 it, by scanning the DIE's below the compilation unit. */
10309 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
10311 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
10312 static_block
= end_symtab_get_static_block (addr
, 0, 1);
10314 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
10315 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
10316 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
10317 addrmap to help ensure it has an accurate map of pc values belonging to
10319 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
10321 cust
= end_symtab_from_static_block (static_block
,
10322 SECT_OFF_TEXT (objfile
), 0);
10326 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
10328 /* Set symtab language to language from DW_AT_language. If the
10329 compilation is from a C file generated by language preprocessors, do
10330 not set the language if it was already deduced by start_subfile. */
10331 if (!(cu
->language
== language_c
10332 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
10333 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10335 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
10336 produce DW_AT_location with location lists but it can be possibly
10337 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
10338 there were bugs in prologue debug info, fixed later in GCC-4.5
10339 by "unwind info for epilogues" patch (which is not directly related).
10341 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
10342 needed, it would be wrong due to missing DW_AT_producer there.
10344 Still one can confuse GDB by using non-standard GCC compilation
10345 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
10347 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
10348 cust
->locations_valid
= 1;
10350 if (gcc_4_minor
>= 5)
10351 cust
->epilogue_unwind_valid
= 1;
10353 cust
->call_site_htab
= cu
->call_site_htab
;
10356 if (dwarf2_per_objfile
->using_index
)
10357 per_cu
->v
.quick
->compunit_symtab
= cust
;
10360 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10361 pst
->compunit_symtab
= cust
;
10365 /* Push it for inclusion processing later. */
10366 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
10369 /* Generate full symbol information for type unit PER_CU, whose DIEs have
10370 already been loaded into memory. */
10373 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
10374 enum language pretend_language
)
10376 struct dwarf2_cu
*cu
= per_cu
->cu
;
10377 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10378 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10379 struct compunit_symtab
*cust
;
10380 struct signatured_type
*sig_type
;
10382 gdb_assert (per_cu
->is_debug_types
);
10383 sig_type
= (struct signatured_type
*) per_cu
;
10386 scoped_free_pendings free_pending
;
10388 /* Clear the list here in case something was left over. */
10389 cu
->method_list
.clear ();
10391 cu
->list_in_scope
= &file_symbols
;
10393 cu
->language
= pretend_language
;
10394 cu
->language_defn
= language_def (cu
->language
);
10396 /* The symbol tables are set up in read_type_unit_scope. */
10397 process_die (cu
->dies
, cu
);
10399 /* For now fudge the Go package. */
10400 if (cu
->language
== language_go
)
10401 fixup_go_packaging (cu
);
10403 /* Now that we have processed all the DIEs in the CU, all the types
10404 should be complete, and it should now be safe to compute all of the
10406 compute_delayed_physnames (cu
);
10408 if (cu
->language
== language_rust
)
10409 rust_union_quirks (cu
);
10411 /* TUs share symbol tables.
10412 If this is the first TU to use this symtab, complete the construction
10413 of it with end_expandable_symtab. Otherwise, complete the addition of
10414 this TU's symbols to the existing symtab. */
10415 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
10417 cust
= end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10418 sig_type
->type_unit_group
->compunit_symtab
= cust
;
10422 /* Set symtab language to language from DW_AT_language. If the
10423 compilation is from a C file generated by language preprocessors,
10424 do not set the language if it was already deduced by
10426 if (!(cu
->language
== language_c
10427 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10428 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10433 augment_type_symtab ();
10434 cust
= sig_type
->type_unit_group
->compunit_symtab
;
10437 if (dwarf2_per_objfile
->using_index
)
10438 per_cu
->v
.quick
->compunit_symtab
= cust
;
10441 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10442 pst
->compunit_symtab
= cust
;
10447 /* Process an imported unit DIE. */
10450 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10452 struct attribute
*attr
;
10454 /* For now we don't handle imported units in type units. */
10455 if (cu
->per_cu
->is_debug_types
)
10457 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10458 " supported in type units [in module %s]"),
10459 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
10462 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10465 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10466 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10467 dwarf2_per_cu_data
*per_cu
10468 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
10469 cu
->per_cu
->dwarf2_per_objfile
);
10471 /* If necessary, add it to the queue and load its DIEs. */
10472 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
10473 load_full_comp_unit (per_cu
, false, cu
->language
);
10475 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
10480 /* RAII object that represents a process_die scope: i.e.,
10481 starts/finishes processing a DIE. */
10482 class process_die_scope
10485 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10486 : m_die (die
), m_cu (cu
)
10488 /* We should only be processing DIEs not already in process. */
10489 gdb_assert (!m_die
->in_process
);
10490 m_die
->in_process
= true;
10493 ~process_die_scope ()
10495 m_die
->in_process
= false;
10497 /* If we're done processing the DIE for the CU that owns the line
10498 header, we don't need the line header anymore. */
10499 if (m_cu
->line_header_die_owner
== m_die
)
10501 delete m_cu
->line_header
;
10502 m_cu
->line_header
= NULL
;
10503 m_cu
->line_header_die_owner
= NULL
;
10512 /* Process a die and its children. */
10515 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10517 process_die_scope
scope (die
, cu
);
10521 case DW_TAG_padding
:
10523 case DW_TAG_compile_unit
:
10524 case DW_TAG_partial_unit
:
10525 read_file_scope (die
, cu
);
10527 case DW_TAG_type_unit
:
10528 read_type_unit_scope (die
, cu
);
10530 case DW_TAG_subprogram
:
10531 case DW_TAG_inlined_subroutine
:
10532 read_func_scope (die
, cu
);
10534 case DW_TAG_lexical_block
:
10535 case DW_TAG_try_block
:
10536 case DW_TAG_catch_block
:
10537 read_lexical_block_scope (die
, cu
);
10539 case DW_TAG_call_site
:
10540 case DW_TAG_GNU_call_site
:
10541 read_call_site_scope (die
, cu
);
10543 case DW_TAG_class_type
:
10544 case DW_TAG_interface_type
:
10545 case DW_TAG_structure_type
:
10546 case DW_TAG_union_type
:
10547 process_structure_scope (die
, cu
);
10549 case DW_TAG_enumeration_type
:
10550 process_enumeration_scope (die
, cu
);
10553 /* These dies have a type, but processing them does not create
10554 a symbol or recurse to process the children. Therefore we can
10555 read them on-demand through read_type_die. */
10556 case DW_TAG_subroutine_type
:
10557 case DW_TAG_set_type
:
10558 case DW_TAG_array_type
:
10559 case DW_TAG_pointer_type
:
10560 case DW_TAG_ptr_to_member_type
:
10561 case DW_TAG_reference_type
:
10562 case DW_TAG_rvalue_reference_type
:
10563 case DW_TAG_string_type
:
10566 case DW_TAG_base_type
:
10567 case DW_TAG_subrange_type
:
10568 case DW_TAG_typedef
:
10569 /* Add a typedef symbol for the type definition, if it has a
10571 new_symbol (die
, read_type_die (die
, cu
), cu
);
10573 case DW_TAG_common_block
:
10574 read_common_block (die
, cu
);
10576 case DW_TAG_common_inclusion
:
10578 case DW_TAG_namespace
:
10579 cu
->processing_has_namespace_info
= 1;
10580 read_namespace (die
, cu
);
10582 case DW_TAG_module
:
10583 cu
->processing_has_namespace_info
= 1;
10584 read_module (die
, cu
);
10586 case DW_TAG_imported_declaration
:
10587 cu
->processing_has_namespace_info
= 1;
10588 if (read_namespace_alias (die
, cu
))
10590 /* The declaration is not a global namespace alias. */
10591 /* Fall through. */
10592 case DW_TAG_imported_module
:
10593 cu
->processing_has_namespace_info
= 1;
10594 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10595 || cu
->language
!= language_fortran
))
10596 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
10597 dwarf_tag_name (die
->tag
));
10598 read_import_statement (die
, cu
);
10601 case DW_TAG_imported_unit
:
10602 process_imported_unit_die (die
, cu
);
10605 case DW_TAG_variable
:
10606 read_variable (die
, cu
);
10610 new_symbol (die
, NULL
, cu
);
10615 /* DWARF name computation. */
10617 /* A helper function for dwarf2_compute_name which determines whether DIE
10618 needs to have the name of the scope prepended to the name listed in the
10622 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10624 struct attribute
*attr
;
10628 case DW_TAG_namespace
:
10629 case DW_TAG_typedef
:
10630 case DW_TAG_class_type
:
10631 case DW_TAG_interface_type
:
10632 case DW_TAG_structure_type
:
10633 case DW_TAG_union_type
:
10634 case DW_TAG_enumeration_type
:
10635 case DW_TAG_enumerator
:
10636 case DW_TAG_subprogram
:
10637 case DW_TAG_inlined_subroutine
:
10638 case DW_TAG_member
:
10639 case DW_TAG_imported_declaration
:
10642 case DW_TAG_variable
:
10643 case DW_TAG_constant
:
10644 /* We only need to prefix "globally" visible variables. These include
10645 any variable marked with DW_AT_external or any variable that
10646 lives in a namespace. [Variables in anonymous namespaces
10647 require prefixing, but they are not DW_AT_external.] */
10649 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10651 struct dwarf2_cu
*spec_cu
= cu
;
10653 return die_needs_namespace (die_specification (die
, &spec_cu
),
10657 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10658 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10659 && die
->parent
->tag
!= DW_TAG_module
)
10661 /* A variable in a lexical block of some kind does not need a
10662 namespace, even though in C++ such variables may be external
10663 and have a mangled name. */
10664 if (die
->parent
->tag
== DW_TAG_lexical_block
10665 || die
->parent
->tag
== DW_TAG_try_block
10666 || die
->parent
->tag
== DW_TAG_catch_block
10667 || die
->parent
->tag
== DW_TAG_subprogram
)
10676 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10677 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10678 defined for the given DIE. */
10680 static struct attribute
*
10681 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10683 struct attribute
*attr
;
10685 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10687 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10692 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10693 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10694 defined for the given DIE. */
10696 static const char *
10697 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10699 const char *linkage_name
;
10701 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10702 if (linkage_name
== NULL
)
10703 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10705 return linkage_name
;
10708 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10709 compute the physname for the object, which include a method's:
10710 - formal parameters (C++),
10711 - receiver type (Go),
10713 The term "physname" is a bit confusing.
10714 For C++, for example, it is the demangled name.
10715 For Go, for example, it's the mangled name.
10717 For Ada, return the DIE's linkage name rather than the fully qualified
10718 name. PHYSNAME is ignored..
10720 The result is allocated on the objfile_obstack and canonicalized. */
10722 static const char *
10723 dwarf2_compute_name (const char *name
,
10724 struct die_info
*die
, struct dwarf2_cu
*cu
,
10727 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10730 name
= dwarf2_name (die
, cu
);
10732 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10733 but otherwise compute it by typename_concat inside GDB.
10734 FIXME: Actually this is not really true, or at least not always true.
10735 It's all very confusing. SYMBOL_SET_NAMES doesn't try to demangle
10736 Fortran names because there is no mangling standard. So new_symbol
10737 will set the demangled name to the result of dwarf2_full_name, and it is
10738 the demangled name that GDB uses if it exists. */
10739 if (cu
->language
== language_ada
10740 || (cu
->language
== language_fortran
&& physname
))
10742 /* For Ada unit, we prefer the linkage name over the name, as
10743 the former contains the exported name, which the user expects
10744 to be able to reference. Ideally, we want the user to be able
10745 to reference this entity using either natural or linkage name,
10746 but we haven't started looking at this enhancement yet. */
10747 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10749 if (linkage_name
!= NULL
)
10750 return linkage_name
;
10753 /* These are the only languages we know how to qualify names in. */
10755 && (cu
->language
== language_cplus
10756 || cu
->language
== language_fortran
|| cu
->language
== language_d
10757 || cu
->language
== language_rust
))
10759 if (die_needs_namespace (die
, cu
))
10761 const char *prefix
;
10762 const char *canonical_name
= NULL
;
10766 prefix
= determine_prefix (die
, cu
);
10767 if (*prefix
!= '\0')
10769 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
10772 buf
.puts (prefixed_name
);
10773 xfree (prefixed_name
);
10778 /* Template parameters may be specified in the DIE's DW_AT_name, or
10779 as children with DW_TAG_template_type_param or
10780 DW_TAG_value_type_param. If the latter, add them to the name
10781 here. If the name already has template parameters, then
10782 skip this step; some versions of GCC emit both, and
10783 it is more efficient to use the pre-computed name.
10785 Something to keep in mind about this process: it is very
10786 unlikely, or in some cases downright impossible, to produce
10787 something that will match the mangled name of a function.
10788 If the definition of the function has the same debug info,
10789 we should be able to match up with it anyway. But fallbacks
10790 using the minimal symbol, for instance to find a method
10791 implemented in a stripped copy of libstdc++, will not work.
10792 If we do not have debug info for the definition, we will have to
10793 match them up some other way.
10795 When we do name matching there is a related problem with function
10796 templates; two instantiated function templates are allowed to
10797 differ only by their return types, which we do not add here. */
10799 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10801 struct attribute
*attr
;
10802 struct die_info
*child
;
10805 die
->building_fullname
= 1;
10807 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10811 const gdb_byte
*bytes
;
10812 struct dwarf2_locexpr_baton
*baton
;
10815 if (child
->tag
!= DW_TAG_template_type_param
10816 && child
->tag
!= DW_TAG_template_value_param
)
10827 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10830 complaint (&symfile_complaints
,
10831 _("template parameter missing DW_AT_type"));
10832 buf
.puts ("UNKNOWN_TYPE");
10835 type
= die_type (child
, cu
);
10837 if (child
->tag
== DW_TAG_template_type_param
)
10839 c_print_type (type
, "", &buf
, -1, 0, &type_print_raw_options
);
10843 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10846 complaint (&symfile_complaints
,
10847 _("template parameter missing "
10848 "DW_AT_const_value"));
10849 buf
.puts ("UNKNOWN_VALUE");
10853 dwarf2_const_value_attr (attr
, type
, name
,
10854 &cu
->comp_unit_obstack
, cu
,
10855 &value
, &bytes
, &baton
);
10857 if (TYPE_NOSIGN (type
))
10858 /* GDB prints characters as NUMBER 'CHAR'. If that's
10859 changed, this can use value_print instead. */
10860 c_printchar (value
, type
, &buf
);
10863 struct value_print_options opts
;
10866 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10870 else if (bytes
!= NULL
)
10872 v
= allocate_value (type
);
10873 memcpy (value_contents_writeable (v
), bytes
,
10874 TYPE_LENGTH (type
));
10877 v
= value_from_longest (type
, value
);
10879 /* Specify decimal so that we do not depend on
10881 get_formatted_print_options (&opts
, 'd');
10883 value_print (v
, &buf
, &opts
);
10888 die
->building_fullname
= 0;
10892 /* Close the argument list, with a space if necessary
10893 (nested templates). */
10894 if (!buf
.empty () && buf
.string ().back () == '>')
10901 /* For C++ methods, append formal parameter type
10902 information, if PHYSNAME. */
10904 if (physname
&& die
->tag
== DW_TAG_subprogram
10905 && cu
->language
== language_cplus
)
10907 struct type
*type
= read_type_die (die
, cu
);
10909 c_type_print_args (type
, &buf
, 1, cu
->language
,
10910 &type_print_raw_options
);
10912 if (cu
->language
== language_cplus
)
10914 /* Assume that an artificial first parameter is
10915 "this", but do not crash if it is not. RealView
10916 marks unnamed (and thus unused) parameters as
10917 artificial; there is no way to differentiate
10919 if (TYPE_NFIELDS (type
) > 0
10920 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10921 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
10922 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10924 buf
.puts (" const");
10928 const std::string
&intermediate_name
= buf
.string ();
10930 if (cu
->language
== language_cplus
)
10932 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10933 &objfile
->per_bfd
->storage_obstack
);
10935 /* If we only computed INTERMEDIATE_NAME, or if
10936 INTERMEDIATE_NAME is already canonical, then we need to
10937 copy it to the appropriate obstack. */
10938 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10939 name
= ((const char *)
10940 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
10941 intermediate_name
.c_str (),
10942 intermediate_name
.length ()));
10944 name
= canonical_name
;
10951 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10952 If scope qualifiers are appropriate they will be added. The result
10953 will be allocated on the storage_obstack, or NULL if the DIE does
10954 not have a name. NAME may either be from a previous call to
10955 dwarf2_name or NULL.
10957 The output string will be canonicalized (if C++). */
10959 static const char *
10960 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10962 return dwarf2_compute_name (name
, die
, cu
, 0);
10965 /* Construct a physname for the given DIE in CU. NAME may either be
10966 from a previous call to dwarf2_name or NULL. The result will be
10967 allocated on the objfile_objstack or NULL if the DIE does not have a
10970 The output string will be canonicalized (if C++). */
10972 static const char *
10973 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10975 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10976 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10979 /* In this case dwarf2_compute_name is just a shortcut not building anything
10981 if (!die_needs_namespace (die
, cu
))
10982 return dwarf2_compute_name (name
, die
, cu
, 1);
10984 mangled
= dw2_linkage_name (die
, cu
);
10986 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10987 See https://github.com/rust-lang/rust/issues/32925. */
10988 if (cu
->language
== language_rust
&& mangled
!= NULL
10989 && strchr (mangled
, '{') != NULL
)
10992 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10994 gdb::unique_xmalloc_ptr
<char> demangled
;
10995 if (mangled
!= NULL
)
10998 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
11000 /* Do nothing (do not demangle the symbol name). */
11002 else if (cu
->language
== language_go
)
11004 /* This is a lie, but we already lie to the caller new_symbol.
11005 new_symbol assumes we return the mangled name.
11006 This just undoes that lie until things are cleaned up. */
11010 /* Use DMGL_RET_DROP for C++ template functions to suppress
11011 their return type. It is easier for GDB users to search
11012 for such functions as `name(params)' than `long name(params)'.
11013 In such case the minimal symbol names do not match the full
11014 symbol names but for template functions there is never a need
11015 to look up their definition from their declaration so
11016 the only disadvantage remains the minimal symbol variant
11017 `long name(params)' does not have the proper inferior type. */
11018 demangled
.reset (gdb_demangle (mangled
,
11019 (DMGL_PARAMS
| DMGL_ANSI
11020 | DMGL_RET_DROP
)));
11023 canon
= demangled
.get ();
11031 if (canon
== NULL
|| check_physname
)
11033 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
11035 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
11037 /* It may not mean a bug in GDB. The compiler could also
11038 compute DW_AT_linkage_name incorrectly. But in such case
11039 GDB would need to be bug-to-bug compatible. */
11041 complaint (&symfile_complaints
,
11042 _("Computed physname <%s> does not match demangled <%s> "
11043 "(from linkage <%s>) - DIE at %s [in module %s]"),
11044 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
11045 objfile_name (objfile
));
11047 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
11048 is available here - over computed PHYSNAME. It is safer
11049 against both buggy GDB and buggy compilers. */
11063 retval
= ((const char *)
11064 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
11065 retval
, strlen (retval
)));
11070 /* Inspect DIE in CU for a namespace alias. If one exists, record
11071 a new symbol for it.
11073 Returns 1 if a namespace alias was recorded, 0 otherwise. */
11076 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
11078 struct attribute
*attr
;
11080 /* If the die does not have a name, this is not a namespace
11082 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11086 struct die_info
*d
= die
;
11087 struct dwarf2_cu
*imported_cu
= cu
;
11089 /* If the compiler has nested DW_AT_imported_declaration DIEs,
11090 keep inspecting DIEs until we hit the underlying import. */
11091 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
11092 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
11094 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
11098 d
= follow_die_ref (d
, attr
, &imported_cu
);
11099 if (d
->tag
!= DW_TAG_imported_declaration
)
11103 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
11105 complaint (&symfile_complaints
,
11106 _("DIE at %s has too many recursively imported "
11107 "declarations"), sect_offset_str (d
->sect_off
));
11114 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
11116 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
11117 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
11119 /* This declaration is a global namespace alias. Add
11120 a symbol for it whose type is the aliased namespace. */
11121 new_symbol (die
, type
, cu
);
11130 /* Return the using directives repository (global or local?) to use in the
11131 current context for LANGUAGE.
11133 For Ada, imported declarations can materialize renamings, which *may* be
11134 global. However it is impossible (for now?) in DWARF to distinguish
11135 "external" imported declarations and "static" ones. As all imported
11136 declarations seem to be static in all other languages, make them all CU-wide
11137 global only in Ada. */
11139 static struct using_direct
**
11140 using_directives (enum language language
)
11142 if (language
== language_ada
&& context_stack_depth
== 0)
11143 return &global_using_directives
;
11145 return &local_using_directives
;
11148 /* Read the import statement specified by the given die and record it. */
11151 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
11153 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11154 struct attribute
*import_attr
;
11155 struct die_info
*imported_die
, *child_die
;
11156 struct dwarf2_cu
*imported_cu
;
11157 const char *imported_name
;
11158 const char *imported_name_prefix
;
11159 const char *canonical_name
;
11160 const char *import_alias
;
11161 const char *imported_declaration
= NULL
;
11162 const char *import_prefix
;
11163 std::vector
<const char *> excludes
;
11165 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
11166 if (import_attr
== NULL
)
11168 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
11169 dwarf_tag_name (die
->tag
));
11174 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
11175 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11176 if (imported_name
== NULL
)
11178 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
11180 The import in the following code:
11194 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
11195 <52> DW_AT_decl_file : 1
11196 <53> DW_AT_decl_line : 6
11197 <54> DW_AT_import : <0x75>
11198 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
11199 <59> DW_AT_name : B
11200 <5b> DW_AT_decl_file : 1
11201 <5c> DW_AT_decl_line : 2
11202 <5d> DW_AT_type : <0x6e>
11204 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
11205 <76> DW_AT_byte_size : 4
11206 <77> DW_AT_encoding : 5 (signed)
11208 imports the wrong die ( 0x75 instead of 0x58 ).
11209 This case will be ignored until the gcc bug is fixed. */
11213 /* Figure out the local name after import. */
11214 import_alias
= dwarf2_name (die
, cu
);
11216 /* Figure out where the statement is being imported to. */
11217 import_prefix
= determine_prefix (die
, cu
);
11219 /* Figure out what the scope of the imported die is and prepend it
11220 to the name of the imported die. */
11221 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
11223 if (imported_die
->tag
!= DW_TAG_namespace
11224 && imported_die
->tag
!= DW_TAG_module
)
11226 imported_declaration
= imported_name
;
11227 canonical_name
= imported_name_prefix
;
11229 else if (strlen (imported_name_prefix
) > 0)
11230 canonical_name
= obconcat (&objfile
->objfile_obstack
,
11231 imported_name_prefix
,
11232 (cu
->language
== language_d
? "." : "::"),
11233 imported_name
, (char *) NULL
);
11235 canonical_name
= imported_name
;
11237 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
11238 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11239 child_die
= sibling_die (child_die
))
11241 /* DWARF-4: A Fortran use statement with a “rename list” may be
11242 represented by an imported module entry with an import attribute
11243 referring to the module and owned entries corresponding to those
11244 entities that are renamed as part of being imported. */
11246 if (child_die
->tag
!= DW_TAG_imported_declaration
)
11248 complaint (&symfile_complaints
,
11249 _("child DW_TAG_imported_declaration expected "
11250 "- DIE at %s [in module %s]"),
11251 sect_offset_str (child_die
->sect_off
),
11252 objfile_name (objfile
));
11256 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
11257 if (import_attr
== NULL
)
11259 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
11260 dwarf_tag_name (child_die
->tag
));
11265 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
11267 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11268 if (imported_name
== NULL
)
11270 complaint (&symfile_complaints
,
11271 _("child DW_TAG_imported_declaration has unknown "
11272 "imported name - DIE at %s [in module %s]"),
11273 sect_offset_str (child_die
->sect_off
),
11274 objfile_name (objfile
));
11278 excludes
.push_back (imported_name
);
11280 process_die (child_die
, cu
);
11283 add_using_directive (using_directives (cu
->language
),
11287 imported_declaration
,
11290 &objfile
->objfile_obstack
);
11293 /* ICC<14 does not output the required DW_AT_declaration on incomplete
11294 types, but gives them a size of zero. Starting with version 14,
11295 ICC is compatible with GCC. */
11298 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
11300 if (!cu
->checked_producer
)
11301 check_producer (cu
);
11303 return cu
->producer_is_icc_lt_14
;
11306 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
11307 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
11308 this, it was first present in GCC release 4.3.0. */
11311 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
11313 if (!cu
->checked_producer
)
11314 check_producer (cu
);
11316 return cu
->producer_is_gcc_lt_4_3
;
11319 static file_and_directory
11320 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
11322 file_and_directory res
;
11324 /* Find the filename. Do not use dwarf2_name here, since the filename
11325 is not a source language identifier. */
11326 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
11327 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
11329 if (res
.comp_dir
== NULL
11330 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
11331 && IS_ABSOLUTE_PATH (res
.name
))
11333 res
.comp_dir_storage
= ldirname (res
.name
);
11334 if (!res
.comp_dir_storage
.empty ())
11335 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
11337 if (res
.comp_dir
!= NULL
)
11339 /* Irix 6.2 native cc prepends <machine>.: to the compilation
11340 directory, get rid of it. */
11341 const char *cp
= strchr (res
.comp_dir
, ':');
11343 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
11344 res
.comp_dir
= cp
+ 1;
11347 if (res
.name
== NULL
)
11348 res
.name
= "<unknown>";
11353 /* Handle DW_AT_stmt_list for a compilation unit.
11354 DIE is the DW_TAG_compile_unit die for CU.
11355 COMP_DIR is the compilation directory. LOWPC is passed to
11356 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11359 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11360 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
11362 struct dwarf2_per_objfile
*dwarf2_per_objfile
11363 = cu
->per_cu
->dwarf2_per_objfile
;
11364 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11365 struct attribute
*attr
;
11366 struct line_header line_header_local
;
11367 hashval_t line_header_local_hash
;
11369 int decode_mapping
;
11371 gdb_assert (! cu
->per_cu
->is_debug_types
);
11373 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11377 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11379 /* The line header hash table is only created if needed (it exists to
11380 prevent redundant reading of the line table for partial_units).
11381 If we're given a partial_unit, we'll need it. If we're given a
11382 compile_unit, then use the line header hash table if it's already
11383 created, but don't create one just yet. */
11385 if (dwarf2_per_objfile
->line_header_hash
== NULL
11386 && die
->tag
== DW_TAG_partial_unit
)
11388 dwarf2_per_objfile
->line_header_hash
11389 = htab_create_alloc_ex (127, line_header_hash_voidp
,
11390 line_header_eq_voidp
,
11391 free_line_header_voidp
,
11392 &objfile
->objfile_obstack
,
11393 hashtab_obstack_allocate
,
11394 dummy_obstack_deallocate
);
11397 line_header_local
.sect_off
= line_offset
;
11398 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11399 line_header_local_hash
= line_header_hash (&line_header_local
);
11400 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
11402 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11403 &line_header_local
,
11404 line_header_local_hash
, NO_INSERT
);
11406 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11407 is not present in *SLOT (since if there is something in *SLOT then
11408 it will be for a partial_unit). */
11409 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11411 gdb_assert (*slot
!= NULL
);
11412 cu
->line_header
= (struct line_header
*) *slot
;
11417 /* dwarf_decode_line_header does not yet provide sufficient information.
11418 We always have to call also dwarf_decode_lines for it. */
11419 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11423 cu
->line_header
= lh
.release ();
11424 cu
->line_header_die_owner
= die
;
11426 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
11430 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11431 &line_header_local
,
11432 line_header_local_hash
, INSERT
);
11433 gdb_assert (slot
!= NULL
);
11435 if (slot
!= NULL
&& *slot
== NULL
)
11437 /* This newly decoded line number information unit will be owned
11438 by line_header_hash hash table. */
11439 *slot
= cu
->line_header
;
11440 cu
->line_header_die_owner
= NULL
;
11444 /* We cannot free any current entry in (*slot) as that struct line_header
11445 may be already used by multiple CUs. Create only temporary decoded
11446 line_header for this CU - it may happen at most once for each line
11447 number information unit. And if we're not using line_header_hash
11448 then this is what we want as well. */
11449 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11451 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11452 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11457 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11460 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11462 struct dwarf2_per_objfile
*dwarf2_per_objfile
11463 = cu
->per_cu
->dwarf2_per_objfile
;
11464 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11465 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11466 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11467 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11468 struct attribute
*attr
;
11469 struct die_info
*child_die
;
11470 CORE_ADDR baseaddr
;
11472 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11474 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11476 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11477 from finish_block. */
11478 if (lowpc
== ((CORE_ADDR
) -1))
11480 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11482 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11484 prepare_one_comp_unit (cu
, die
, cu
->language
);
11486 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11487 standardised yet. As a workaround for the language detection we fall
11488 back to the DW_AT_producer string. */
11489 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11490 cu
->language
= language_opencl
;
11492 /* Similar hack for Go. */
11493 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11494 set_cu_language (DW_LANG_Go
, cu
);
11496 dwarf2_start_symtab (cu
, fnd
.name
, fnd
.comp_dir
, lowpc
);
11498 /* Decode line number information if present. We do this before
11499 processing child DIEs, so that the line header table is available
11500 for DW_AT_decl_file. */
11501 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11503 /* Process all dies in compilation unit. */
11504 if (die
->child
!= NULL
)
11506 child_die
= die
->child
;
11507 while (child_die
&& child_die
->tag
)
11509 process_die (child_die
, cu
);
11510 child_die
= sibling_die (child_die
);
11514 /* Decode macro information, if present. Dwarf 2 macro information
11515 refers to information in the line number info statement program
11516 header, so we can only read it if we've read the header
11518 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11520 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11521 if (attr
&& cu
->line_header
)
11523 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11524 complaint (&symfile_complaints
,
11525 _("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11527 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11531 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11532 if (attr
&& cu
->line_header
)
11534 unsigned int macro_offset
= DW_UNSND (attr
);
11536 dwarf_decode_macros (cu
, macro_offset
, 0);
11541 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
11542 Create the set of symtabs used by this TU, or if this TU is sharing
11543 symtabs with another TU and the symtabs have already been created
11544 then restore those symtabs in the line header.
11545 We don't need the pc/line-number mapping for type units. */
11548 setup_type_unit_groups (struct die_info
*die
, struct dwarf2_cu
*cu
)
11550 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
11551 struct type_unit_group
*tu_group
;
11553 struct attribute
*attr
;
11555 struct signatured_type
*sig_type
;
11557 gdb_assert (per_cu
->is_debug_types
);
11558 sig_type
= (struct signatured_type
*) per_cu
;
11560 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11562 /* If we're using .gdb_index (includes -readnow) then
11563 per_cu->type_unit_group may not have been set up yet. */
11564 if (sig_type
->type_unit_group
== NULL
)
11565 sig_type
->type_unit_group
= get_type_unit_group (cu
, attr
);
11566 tu_group
= sig_type
->type_unit_group
;
11568 /* If we've already processed this stmt_list there's no real need to
11569 do it again, we could fake it and just recreate the part we need
11570 (file name,index -> symtab mapping). If data shows this optimization
11571 is useful we can do it then. */
11572 first_time
= tu_group
->compunit_symtab
== NULL
;
11574 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11579 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11580 lh
= dwarf_decode_line_header (line_offset
, cu
);
11585 dwarf2_start_symtab (cu
, "", NULL
, 0);
11588 gdb_assert (tu_group
->symtabs
== NULL
);
11589 restart_symtab (tu_group
->compunit_symtab
, "", 0);
11594 cu
->line_header
= lh
.release ();
11595 cu
->line_header_die_owner
= die
;
11599 struct compunit_symtab
*cust
= dwarf2_start_symtab (cu
, "", NULL
, 0);
11601 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11602 still initializing it, and our caller (a few levels up)
11603 process_full_type_unit still needs to know if this is the first
11606 tu_group
->num_symtabs
= cu
->line_header
->file_names
.size ();
11607 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
11608 cu
->line_header
->file_names
.size ());
11610 for (i
= 0; i
< cu
->line_header
->file_names
.size (); ++i
)
11612 file_entry
&fe
= cu
->line_header
->file_names
[i
];
11614 dwarf2_start_subfile (fe
.name
, fe
.include_dir (cu
->line_header
));
11616 if (current_subfile
->symtab
== NULL
)
11618 /* NOTE: start_subfile will recognize when it's been
11619 passed a file it has already seen. So we can't
11620 assume there's a simple mapping from
11621 cu->line_header->file_names to subfiles, plus
11622 cu->line_header->file_names may contain dups. */
11623 current_subfile
->symtab
11624 = allocate_symtab (cust
, current_subfile
->name
);
11627 fe
.symtab
= current_subfile
->symtab
;
11628 tu_group
->symtabs
[i
] = fe
.symtab
;
11633 restart_symtab (tu_group
->compunit_symtab
, "", 0);
11635 for (i
= 0; i
< cu
->line_header
->file_names
.size (); ++i
)
11637 file_entry
&fe
= cu
->line_header
->file_names
[i
];
11639 fe
.symtab
= tu_group
->symtabs
[i
];
11643 /* The main symtab is allocated last. Type units don't have DW_AT_name
11644 so they don't have a "real" (so to speak) symtab anyway.
11645 There is later code that will assign the main symtab to all symbols
11646 that don't have one. We need to handle the case of a symbol with a
11647 missing symtab (DW_AT_decl_file) anyway. */
11650 /* Process DW_TAG_type_unit.
11651 For TUs we want to skip the first top level sibling if it's not the
11652 actual type being defined by this TU. In this case the first top
11653 level sibling is there to provide context only. */
11656 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11658 struct die_info
*child_die
;
11660 prepare_one_comp_unit (cu
, die
, language_minimal
);
11662 /* Initialize (or reinitialize) the machinery for building symtabs.
11663 We do this before processing child DIEs, so that the line header table
11664 is available for DW_AT_decl_file. */
11665 setup_type_unit_groups (die
, cu
);
11667 if (die
->child
!= NULL
)
11669 child_die
= die
->child
;
11670 while (child_die
&& child_die
->tag
)
11672 process_die (child_die
, cu
);
11673 child_die
= sibling_die (child_die
);
11680 http://gcc.gnu.org/wiki/DebugFission
11681 http://gcc.gnu.org/wiki/DebugFissionDWP
11683 To simplify handling of both DWO files ("object" files with the DWARF info)
11684 and DWP files (a file with the DWOs packaged up into one file), we treat
11685 DWP files as having a collection of virtual DWO files. */
11688 hash_dwo_file (const void *item
)
11690 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11693 hash
= htab_hash_string (dwo_file
->dwo_name
);
11694 if (dwo_file
->comp_dir
!= NULL
)
11695 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11700 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11702 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11703 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11705 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11707 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11708 return lhs
->comp_dir
== rhs
->comp_dir
;
11709 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11712 /* Allocate a hash table for DWO files. */
11715 allocate_dwo_file_hash_table (struct objfile
*objfile
)
11717 return htab_create_alloc_ex (41,
11721 &objfile
->objfile_obstack
,
11722 hashtab_obstack_allocate
,
11723 dummy_obstack_deallocate
);
11726 /* Lookup DWO file DWO_NAME. */
11729 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11730 const char *dwo_name
,
11731 const char *comp_dir
)
11733 struct dwo_file find_entry
;
11736 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11737 dwarf2_per_objfile
->dwo_files
11738 = allocate_dwo_file_hash_table (dwarf2_per_objfile
->objfile
);
11740 memset (&find_entry
, 0, sizeof (find_entry
));
11741 find_entry
.dwo_name
= dwo_name
;
11742 find_entry
.comp_dir
= comp_dir
;
11743 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
11749 hash_dwo_unit (const void *item
)
11751 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11753 /* This drops the top 32 bits of the id, but is ok for a hash. */
11754 return dwo_unit
->signature
;
11758 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11760 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11761 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11763 /* The signature is assumed to be unique within the DWO file.
11764 So while object file CU dwo_id's always have the value zero,
11765 that's OK, assuming each object file DWO file has only one CU,
11766 and that's the rule for now. */
11767 return lhs
->signature
== rhs
->signature
;
11770 /* Allocate a hash table for DWO CUs,TUs.
11771 There is one of these tables for each of CUs,TUs for each DWO file. */
11774 allocate_dwo_unit_table (struct objfile
*objfile
)
11776 /* Start out with a pretty small number.
11777 Generally DWO files contain only one CU and maybe some TUs. */
11778 return htab_create_alloc_ex (3,
11782 &objfile
->objfile_obstack
,
11783 hashtab_obstack_allocate
,
11784 dummy_obstack_deallocate
);
11787 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
11789 struct create_dwo_cu_data
11791 struct dwo_file
*dwo_file
;
11792 struct dwo_unit dwo_unit
;
11795 /* die_reader_func for create_dwo_cu. */
11798 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11799 const gdb_byte
*info_ptr
,
11800 struct die_info
*comp_unit_die
,
11804 struct dwarf2_cu
*cu
= reader
->cu
;
11805 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11806 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11807 struct create_dwo_cu_data
*data
= (struct create_dwo_cu_data
*) datap
;
11808 struct dwo_file
*dwo_file
= data
->dwo_file
;
11809 struct dwo_unit
*dwo_unit
= &data
->dwo_unit
;
11810 struct attribute
*attr
;
11812 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
11815 complaint (&symfile_complaints
,
11816 _("Dwarf Error: debug entry at offset %s is missing"
11817 " its dwo_id [in module %s]"),
11818 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11822 dwo_unit
->dwo_file
= dwo_file
;
11823 dwo_unit
->signature
= DW_UNSND (attr
);
11824 dwo_unit
->section
= section
;
11825 dwo_unit
->sect_off
= sect_off
;
11826 dwo_unit
->length
= cu
->per_cu
->length
;
11828 if (dwarf_read_debug
)
11829 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11830 sect_offset_str (sect_off
),
11831 hex_string (dwo_unit
->signature
));
11834 /* Create the dwo_units for the CUs in a DWO_FILE.
11835 Note: This function processes DWO files only, not DWP files. */
11838 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11839 struct dwo_file
&dwo_file
, dwarf2_section_info
§ion
,
11842 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11843 const gdb_byte
*info_ptr
, *end_ptr
;
11845 dwarf2_read_section (objfile
, §ion
);
11846 info_ptr
= section
.buffer
;
11848 if (info_ptr
== NULL
)
11851 if (dwarf_read_debug
)
11853 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11854 get_section_name (§ion
),
11855 get_section_file_name (§ion
));
11858 end_ptr
= info_ptr
+ section
.size
;
11859 while (info_ptr
< end_ptr
)
11861 struct dwarf2_per_cu_data per_cu
;
11862 struct create_dwo_cu_data create_dwo_cu_data
;
11863 struct dwo_unit
*dwo_unit
;
11865 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11867 memset (&create_dwo_cu_data
.dwo_unit
, 0,
11868 sizeof (create_dwo_cu_data
.dwo_unit
));
11869 memset (&per_cu
, 0, sizeof (per_cu
));
11870 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11871 per_cu
.is_debug_types
= 0;
11872 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11873 per_cu
.section
= §ion
;
11874 create_dwo_cu_data
.dwo_file
= &dwo_file
;
11876 init_cutu_and_read_dies_no_follow (
11877 &per_cu
, &dwo_file
, create_dwo_cu_reader
, &create_dwo_cu_data
);
11878 info_ptr
+= per_cu
.length
;
11880 // If the unit could not be parsed, skip it.
11881 if (create_dwo_cu_data
.dwo_unit
.dwo_file
== NULL
)
11884 if (cus_htab
== NULL
)
11885 cus_htab
= allocate_dwo_unit_table (objfile
);
11887 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11888 *dwo_unit
= create_dwo_cu_data
.dwo_unit
;
11889 slot
= htab_find_slot (cus_htab
, dwo_unit
, INSERT
);
11890 gdb_assert (slot
!= NULL
);
11893 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11894 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11896 complaint (&symfile_complaints
,
11897 _("debug cu entry at offset %s is duplicate to"
11898 " the entry at offset %s, signature %s"),
11899 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11900 hex_string (dwo_unit
->signature
));
11902 *slot
= (void *)dwo_unit
;
11906 /* DWP file .debug_{cu,tu}_index section format:
11907 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11911 Both index sections have the same format, and serve to map a 64-bit
11912 signature to a set of section numbers. Each section begins with a header,
11913 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11914 indexes, and a pool of 32-bit section numbers. The index sections will be
11915 aligned at 8-byte boundaries in the file.
11917 The index section header consists of:
11919 V, 32 bit version number
11921 N, 32 bit number of compilation units or type units in the index
11922 M, 32 bit number of slots in the hash table
11924 Numbers are recorded using the byte order of the application binary.
11926 The hash table begins at offset 16 in the section, and consists of an array
11927 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11928 order of the application binary). Unused slots in the hash table are 0.
11929 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11931 The parallel table begins immediately after the hash table
11932 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11933 array of 32-bit indexes (using the byte order of the application binary),
11934 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11935 table contains a 32-bit index into the pool of section numbers. For unused
11936 hash table slots, the corresponding entry in the parallel table will be 0.
11938 The pool of section numbers begins immediately following the hash table
11939 (at offset 16 + 12 * M from the beginning of the section). The pool of
11940 section numbers consists of an array of 32-bit words (using the byte order
11941 of the application binary). Each item in the array is indexed starting
11942 from 0. The hash table entry provides the index of the first section
11943 number in the set. Additional section numbers in the set follow, and the
11944 set is terminated by a 0 entry (section number 0 is not used in ELF).
11946 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11947 section must be the first entry in the set, and the .debug_abbrev.dwo must
11948 be the second entry. Other members of the set may follow in any order.
11954 DWP Version 2 combines all the .debug_info, etc. sections into one,
11955 and the entries in the index tables are now offsets into these sections.
11956 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11959 Index Section Contents:
11961 Hash Table of Signatures dwp_hash_table.hash_table
11962 Parallel Table of Indices dwp_hash_table.unit_table
11963 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11964 Table of Section Sizes dwp_hash_table.v2.sizes
11966 The index section header consists of:
11968 V, 32 bit version number
11969 L, 32 bit number of columns in the table of section offsets
11970 N, 32 bit number of compilation units or type units in the index
11971 M, 32 bit number of slots in the hash table
11973 Numbers are recorded using the byte order of the application binary.
11975 The hash table has the same format as version 1.
11976 The parallel table of indices has the same format as version 1,
11977 except that the entries are origin-1 indices into the table of sections
11978 offsets and the table of section sizes.
11980 The table of offsets begins immediately following the parallel table
11981 (at offset 16 + 12 * M from the beginning of the section). The table is
11982 a two-dimensional array of 32-bit words (using the byte order of the
11983 application binary), with L columns and N+1 rows, in row-major order.
11984 Each row in the array is indexed starting from 0. The first row provides
11985 a key to the remaining rows: each column in this row provides an identifier
11986 for a debug section, and the offsets in the same column of subsequent rows
11987 refer to that section. The section identifiers are:
11989 DW_SECT_INFO 1 .debug_info.dwo
11990 DW_SECT_TYPES 2 .debug_types.dwo
11991 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11992 DW_SECT_LINE 4 .debug_line.dwo
11993 DW_SECT_LOC 5 .debug_loc.dwo
11994 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11995 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11996 DW_SECT_MACRO 8 .debug_macro.dwo
11998 The offsets provided by the CU and TU index sections are the base offsets
11999 for the contributions made by each CU or TU to the corresponding section
12000 in the package file. Each CU and TU header contains an abbrev_offset
12001 field, used to find the abbreviations table for that CU or TU within the
12002 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
12003 be interpreted as relative to the base offset given in the index section.
12004 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
12005 should be interpreted as relative to the base offset for .debug_line.dwo,
12006 and offsets into other debug sections obtained from DWARF attributes should
12007 also be interpreted as relative to the corresponding base offset.
12009 The table of sizes begins immediately following the table of offsets.
12010 Like the table of offsets, it is a two-dimensional array of 32-bit words,
12011 with L columns and N rows, in row-major order. Each row in the array is
12012 indexed starting from 1 (row 0 is shared by the two tables).
12016 Hash table lookup is handled the same in version 1 and 2:
12018 We assume that N and M will not exceed 2^32 - 1.
12019 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
12021 Given a 64-bit compilation unit signature or a type signature S, an entry
12022 in the hash table is located as follows:
12024 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
12025 the low-order k bits all set to 1.
12027 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
12029 3) If the hash table entry at index H matches the signature, use that
12030 entry. If the hash table entry at index H is unused (all zeroes),
12031 terminate the search: the signature is not present in the table.
12033 4) Let H = (H + H') modulo M. Repeat at Step 3.
12035 Because M > N and H' and M are relatively prime, the search is guaranteed
12036 to stop at an unused slot or find the match. */
12038 /* Create a hash table to map DWO IDs to their CU/TU entry in
12039 .debug_{info,types}.dwo in DWP_FILE.
12040 Returns NULL if there isn't one.
12041 Note: This function processes DWP files only, not DWO files. */
12043 static struct dwp_hash_table
*
12044 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12045 struct dwp_file
*dwp_file
, int is_debug_types
)
12047 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12048 bfd
*dbfd
= dwp_file
->dbfd
;
12049 const gdb_byte
*index_ptr
, *index_end
;
12050 struct dwarf2_section_info
*index
;
12051 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
12052 struct dwp_hash_table
*htab
;
12054 if (is_debug_types
)
12055 index
= &dwp_file
->sections
.tu_index
;
12057 index
= &dwp_file
->sections
.cu_index
;
12059 if (dwarf2_section_empty_p (index
))
12061 dwarf2_read_section (objfile
, index
);
12063 index_ptr
= index
->buffer
;
12064 index_end
= index_ptr
+ index
->size
;
12066 version
= read_4_bytes (dbfd
, index_ptr
);
12069 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
12073 nr_units
= read_4_bytes (dbfd
, index_ptr
);
12075 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
12078 if (version
!= 1 && version
!= 2)
12080 error (_("Dwarf Error: unsupported DWP file version (%s)"
12081 " [in module %s]"),
12082 pulongest (version
), dwp_file
->name
);
12084 if (nr_slots
!= (nr_slots
& -nr_slots
))
12086 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
12087 " is not power of 2 [in module %s]"),
12088 pulongest (nr_slots
), dwp_file
->name
);
12091 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
12092 htab
->version
= version
;
12093 htab
->nr_columns
= nr_columns
;
12094 htab
->nr_units
= nr_units
;
12095 htab
->nr_slots
= nr_slots
;
12096 htab
->hash_table
= index_ptr
;
12097 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
12099 /* Exit early if the table is empty. */
12100 if (nr_slots
== 0 || nr_units
== 0
12101 || (version
== 2 && nr_columns
== 0))
12103 /* All must be zero. */
12104 if (nr_slots
!= 0 || nr_units
!= 0
12105 || (version
== 2 && nr_columns
!= 0))
12107 complaint (&symfile_complaints
,
12108 _("Empty DWP but nr_slots,nr_units,nr_columns not"
12109 " all zero [in modules %s]"),
12117 htab
->section_pool
.v1
.indices
=
12118 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12119 /* It's harder to decide whether the section is too small in v1.
12120 V1 is deprecated anyway so we punt. */
12124 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12125 int *ids
= htab
->section_pool
.v2
.section_ids
;
12126 /* Reverse map for error checking. */
12127 int ids_seen
[DW_SECT_MAX
+ 1];
12130 if (nr_columns
< 2)
12132 error (_("Dwarf Error: bad DWP hash table, too few columns"
12133 " in section table [in module %s]"),
12136 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
12138 error (_("Dwarf Error: bad DWP hash table, too many columns"
12139 " in section table [in module %s]"),
12142 memset (ids
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
12143 memset (ids_seen
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
12144 for (i
= 0; i
< nr_columns
; ++i
)
12146 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
12148 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
12150 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
12151 " in section table [in module %s]"),
12152 id
, dwp_file
->name
);
12154 if (ids_seen
[id
] != -1)
12156 error (_("Dwarf Error: bad DWP hash table, duplicate section"
12157 " id %d in section table [in module %s]"),
12158 id
, dwp_file
->name
);
12163 /* Must have exactly one info or types section. */
12164 if (((ids_seen
[DW_SECT_INFO
] != -1)
12165 + (ids_seen
[DW_SECT_TYPES
] != -1))
12168 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
12169 " DWO info/types section [in module %s]"),
12172 /* Must have an abbrev section. */
12173 if (ids_seen
[DW_SECT_ABBREV
] == -1)
12175 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
12176 " section [in module %s]"),
12179 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
12180 htab
->section_pool
.v2
.sizes
=
12181 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
12182 * nr_units
* nr_columns
);
12183 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
12184 * nr_units
* nr_columns
))
12187 error (_("Dwarf Error: DWP index section is corrupt (too small)"
12188 " [in module %s]"),
12196 /* Update SECTIONS with the data from SECTP.
12198 This function is like the other "locate" section routines that are
12199 passed to bfd_map_over_sections, but in this context the sections to
12200 read comes from the DWP V1 hash table, not the full ELF section table.
12202 The result is non-zero for success, or zero if an error was found. */
12205 locate_v1_virtual_dwo_sections (asection
*sectp
,
12206 struct virtual_v1_dwo_sections
*sections
)
12208 const struct dwop_section_names
*names
= &dwop_section_names
;
12210 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12212 /* There can be only one. */
12213 if (sections
->abbrev
.s
.section
!= NULL
)
12215 sections
->abbrev
.s
.section
= sectp
;
12216 sections
->abbrev
.size
= bfd_get_section_size (sectp
);
12218 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
12219 || section_is_p (sectp
->name
, &names
->types_dwo
))
12221 /* There can be only one. */
12222 if (sections
->info_or_types
.s
.section
!= NULL
)
12224 sections
->info_or_types
.s
.section
= sectp
;
12225 sections
->info_or_types
.size
= bfd_get_section_size (sectp
);
12227 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12229 /* There can be only one. */
12230 if (sections
->line
.s
.section
!= NULL
)
12232 sections
->line
.s
.section
= sectp
;
12233 sections
->line
.size
= bfd_get_section_size (sectp
);
12235 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12237 /* There can be only one. */
12238 if (sections
->loc
.s
.section
!= NULL
)
12240 sections
->loc
.s
.section
= sectp
;
12241 sections
->loc
.size
= bfd_get_section_size (sectp
);
12243 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12245 /* There can be only one. */
12246 if (sections
->macinfo
.s
.section
!= NULL
)
12248 sections
->macinfo
.s
.section
= sectp
;
12249 sections
->macinfo
.size
= bfd_get_section_size (sectp
);
12251 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12253 /* There can be only one. */
12254 if (sections
->macro
.s
.section
!= NULL
)
12256 sections
->macro
.s
.section
= sectp
;
12257 sections
->macro
.size
= bfd_get_section_size (sectp
);
12259 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12261 /* There can be only one. */
12262 if (sections
->str_offsets
.s
.section
!= NULL
)
12264 sections
->str_offsets
.s
.section
= sectp
;
12265 sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
12269 /* No other kind of section is valid. */
12276 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12277 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12278 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12279 This is for DWP version 1 files. */
12281 static struct dwo_unit
*
12282 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12283 struct dwp_file
*dwp_file
,
12284 uint32_t unit_index
,
12285 const char *comp_dir
,
12286 ULONGEST signature
, int is_debug_types
)
12288 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12289 const struct dwp_hash_table
*dwp_htab
=
12290 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12291 bfd
*dbfd
= dwp_file
->dbfd
;
12292 const char *kind
= is_debug_types
? "TU" : "CU";
12293 struct dwo_file
*dwo_file
;
12294 struct dwo_unit
*dwo_unit
;
12295 struct virtual_v1_dwo_sections sections
;
12296 void **dwo_file_slot
;
12299 gdb_assert (dwp_file
->version
== 1);
12301 if (dwarf_read_debug
)
12303 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
12305 pulongest (unit_index
), hex_string (signature
),
12309 /* Fetch the sections of this DWO unit.
12310 Put a limit on the number of sections we look for so that bad data
12311 doesn't cause us to loop forever. */
12313 #define MAX_NR_V1_DWO_SECTIONS \
12314 (1 /* .debug_info or .debug_types */ \
12315 + 1 /* .debug_abbrev */ \
12316 + 1 /* .debug_line */ \
12317 + 1 /* .debug_loc */ \
12318 + 1 /* .debug_str_offsets */ \
12319 + 1 /* .debug_macro or .debug_macinfo */ \
12320 + 1 /* trailing zero */)
12322 memset (§ions
, 0, sizeof (sections
));
12324 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12327 uint32_t section_nr
=
12328 read_4_bytes (dbfd
,
12329 dwp_htab
->section_pool
.v1
.indices
12330 + (unit_index
+ i
) * sizeof (uint32_t));
12332 if (section_nr
== 0)
12334 if (section_nr
>= dwp_file
->num_sections
)
12336 error (_("Dwarf Error: bad DWP hash table, section number too large"
12337 " [in module %s]"),
12341 sectp
= dwp_file
->elf_sections
[section_nr
];
12342 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12344 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12345 " [in module %s]"),
12351 || dwarf2_section_empty_p (§ions
.info_or_types
)
12352 || dwarf2_section_empty_p (§ions
.abbrev
))
12354 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12355 " [in module %s]"),
12358 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12360 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12361 " [in module %s]"),
12365 /* It's easier for the rest of the code if we fake a struct dwo_file and
12366 have dwo_unit "live" in that. At least for now.
12368 The DWP file can be made up of a random collection of CUs and TUs.
12369 However, for each CU + set of TUs that came from the same original DWO
12370 file, we can combine them back into a virtual DWO file to save space
12371 (fewer struct dwo_file objects to allocate). Remember that for really
12372 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12374 std::string virtual_dwo_name
=
12375 string_printf ("virtual-dwo/%d-%d-%d-%d",
12376 get_section_id (§ions
.abbrev
),
12377 get_section_id (§ions
.line
),
12378 get_section_id (§ions
.loc
),
12379 get_section_id (§ions
.str_offsets
));
12380 /* Can we use an existing virtual DWO file? */
12381 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12382 virtual_dwo_name
.c_str (),
12384 /* Create one if necessary. */
12385 if (*dwo_file_slot
== NULL
)
12387 if (dwarf_read_debug
)
12389 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12390 virtual_dwo_name
.c_str ());
12392 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
12394 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
12395 virtual_dwo_name
.c_str (),
12396 virtual_dwo_name
.size ());
12397 dwo_file
->comp_dir
= comp_dir
;
12398 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12399 dwo_file
->sections
.line
= sections
.line
;
12400 dwo_file
->sections
.loc
= sections
.loc
;
12401 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12402 dwo_file
->sections
.macro
= sections
.macro
;
12403 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12404 /* The "str" section is global to the entire DWP file. */
12405 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12406 /* The info or types section is assigned below to dwo_unit,
12407 there's no need to record it in dwo_file.
12408 Also, we can't simply record type sections in dwo_file because
12409 we record a pointer into the vector in dwo_unit. As we collect more
12410 types we'll grow the vector and eventually have to reallocate space
12411 for it, invalidating all copies of pointers into the previous
12413 *dwo_file_slot
= dwo_file
;
12417 if (dwarf_read_debug
)
12419 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12420 virtual_dwo_name
.c_str ());
12422 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12425 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12426 dwo_unit
->dwo_file
= dwo_file
;
12427 dwo_unit
->signature
= signature
;
12428 dwo_unit
->section
=
12429 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12430 *dwo_unit
->section
= sections
.info_or_types
;
12431 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12436 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
12437 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
12438 piece within that section used by a TU/CU, return a virtual section
12439 of just that piece. */
12441 static struct dwarf2_section_info
12442 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12443 struct dwarf2_section_info
*section
,
12444 bfd_size_type offset
, bfd_size_type size
)
12446 struct dwarf2_section_info result
;
12449 gdb_assert (section
!= NULL
);
12450 gdb_assert (!section
->is_virtual
);
12452 memset (&result
, 0, sizeof (result
));
12453 result
.s
.containing_section
= section
;
12454 result
.is_virtual
= 1;
12459 sectp
= get_section_bfd_section (section
);
12461 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12462 bounds of the real section. This is a pretty-rare event, so just
12463 flag an error (easier) instead of a warning and trying to cope. */
12465 || offset
+ size
> bfd_get_section_size (sectp
))
12467 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12468 " in section %s [in module %s]"),
12469 sectp
? bfd_section_name (abfd
, sectp
) : "<unknown>",
12470 objfile_name (dwarf2_per_objfile
->objfile
));
12473 result
.virtual_offset
= offset
;
12474 result
.size
= size
;
12478 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12479 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12480 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12481 This is for DWP version 2 files. */
12483 static struct dwo_unit
*
12484 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12485 struct dwp_file
*dwp_file
,
12486 uint32_t unit_index
,
12487 const char *comp_dir
,
12488 ULONGEST signature
, int is_debug_types
)
12490 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12491 const struct dwp_hash_table
*dwp_htab
=
12492 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12493 bfd
*dbfd
= dwp_file
->dbfd
;
12494 const char *kind
= is_debug_types
? "TU" : "CU";
12495 struct dwo_file
*dwo_file
;
12496 struct dwo_unit
*dwo_unit
;
12497 struct virtual_v2_dwo_sections sections
;
12498 void **dwo_file_slot
;
12501 gdb_assert (dwp_file
->version
== 2);
12503 if (dwarf_read_debug
)
12505 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
12507 pulongest (unit_index
), hex_string (signature
),
12511 /* Fetch the section offsets of this DWO unit. */
12513 memset (§ions
, 0, sizeof (sections
));
12515 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12517 uint32_t offset
= read_4_bytes (dbfd
,
12518 dwp_htab
->section_pool
.v2
.offsets
12519 + (((unit_index
- 1) * dwp_htab
->nr_columns
12521 * sizeof (uint32_t)));
12522 uint32_t size
= read_4_bytes (dbfd
,
12523 dwp_htab
->section_pool
.v2
.sizes
12524 + (((unit_index
- 1) * dwp_htab
->nr_columns
12526 * sizeof (uint32_t)));
12528 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12531 case DW_SECT_TYPES
:
12532 sections
.info_or_types_offset
= offset
;
12533 sections
.info_or_types_size
= size
;
12535 case DW_SECT_ABBREV
:
12536 sections
.abbrev_offset
= offset
;
12537 sections
.abbrev_size
= size
;
12540 sections
.line_offset
= offset
;
12541 sections
.line_size
= size
;
12544 sections
.loc_offset
= offset
;
12545 sections
.loc_size
= size
;
12547 case DW_SECT_STR_OFFSETS
:
12548 sections
.str_offsets_offset
= offset
;
12549 sections
.str_offsets_size
= size
;
12551 case DW_SECT_MACINFO
:
12552 sections
.macinfo_offset
= offset
;
12553 sections
.macinfo_size
= size
;
12555 case DW_SECT_MACRO
:
12556 sections
.macro_offset
= offset
;
12557 sections
.macro_size
= size
;
12562 /* It's easier for the rest of the code if we fake a struct dwo_file and
12563 have dwo_unit "live" in that. At least for now.
12565 The DWP file can be made up of a random collection of CUs and TUs.
12566 However, for each CU + set of TUs that came from the same original DWO
12567 file, we can combine them back into a virtual DWO file to save space
12568 (fewer struct dwo_file objects to allocate). Remember that for really
12569 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12571 std::string virtual_dwo_name
=
12572 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12573 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12574 (long) (sections
.line_size
? sections
.line_offset
: 0),
12575 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12576 (long) (sections
.str_offsets_size
12577 ? sections
.str_offsets_offset
: 0));
12578 /* Can we use an existing virtual DWO file? */
12579 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12580 virtual_dwo_name
.c_str (),
12582 /* Create one if necessary. */
12583 if (*dwo_file_slot
== NULL
)
12585 if (dwarf_read_debug
)
12587 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12588 virtual_dwo_name
.c_str ());
12590 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
12592 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
12593 virtual_dwo_name
.c_str (),
12594 virtual_dwo_name
.size ());
12595 dwo_file
->comp_dir
= comp_dir
;
12596 dwo_file
->sections
.abbrev
=
12597 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
12598 sections
.abbrev_offset
, sections
.abbrev_size
);
12599 dwo_file
->sections
.line
=
12600 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
12601 sections
.line_offset
, sections
.line_size
);
12602 dwo_file
->sections
.loc
=
12603 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
12604 sections
.loc_offset
, sections
.loc_size
);
12605 dwo_file
->sections
.macinfo
=
12606 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
12607 sections
.macinfo_offset
, sections
.macinfo_size
);
12608 dwo_file
->sections
.macro
=
12609 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
12610 sections
.macro_offset
, sections
.macro_size
);
12611 dwo_file
->sections
.str_offsets
=
12612 create_dwp_v2_section (dwarf2_per_objfile
,
12613 &dwp_file
->sections
.str_offsets
,
12614 sections
.str_offsets_offset
,
12615 sections
.str_offsets_size
);
12616 /* The "str" section is global to the entire DWP file. */
12617 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12618 /* The info or types section is assigned below to dwo_unit,
12619 there's no need to record it in dwo_file.
12620 Also, we can't simply record type sections in dwo_file because
12621 we record a pointer into the vector in dwo_unit. As we collect more
12622 types we'll grow the vector and eventually have to reallocate space
12623 for it, invalidating all copies of pointers into the previous
12625 *dwo_file_slot
= dwo_file
;
12629 if (dwarf_read_debug
)
12631 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12632 virtual_dwo_name
.c_str ());
12634 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12637 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12638 dwo_unit
->dwo_file
= dwo_file
;
12639 dwo_unit
->signature
= signature
;
12640 dwo_unit
->section
=
12641 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12642 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
12644 ? &dwp_file
->sections
.types
12645 : &dwp_file
->sections
.info
,
12646 sections
.info_or_types_offset
,
12647 sections
.info_or_types_size
);
12648 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12653 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12654 Returns NULL if the signature isn't found. */
12656 static struct dwo_unit
*
12657 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12658 struct dwp_file
*dwp_file
, const char *comp_dir
,
12659 ULONGEST signature
, int is_debug_types
)
12661 const struct dwp_hash_table
*dwp_htab
=
12662 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12663 bfd
*dbfd
= dwp_file
->dbfd
;
12664 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12665 uint32_t hash
= signature
& mask
;
12666 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12669 struct dwo_unit find_dwo_cu
;
12671 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12672 find_dwo_cu
.signature
= signature
;
12673 slot
= htab_find_slot (is_debug_types
12674 ? dwp_file
->loaded_tus
12675 : dwp_file
->loaded_cus
,
12676 &find_dwo_cu
, INSERT
);
12679 return (struct dwo_unit
*) *slot
;
12681 /* Use a for loop so that we don't loop forever on bad debug info. */
12682 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12684 ULONGEST signature_in_table
;
12686 signature_in_table
=
12687 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12688 if (signature_in_table
== signature
)
12690 uint32_t unit_index
=
12691 read_4_bytes (dbfd
,
12692 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12694 if (dwp_file
->version
== 1)
12696 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
12697 dwp_file
, unit_index
,
12698 comp_dir
, signature
,
12703 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
12704 dwp_file
, unit_index
,
12705 comp_dir
, signature
,
12708 return (struct dwo_unit
*) *slot
;
12710 if (signature_in_table
== 0)
12712 hash
= (hash
+ hash2
) & mask
;
12715 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12716 " [in module %s]"),
12720 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12721 Open the file specified by FILE_NAME and hand it off to BFD for
12722 preliminary analysis. Return a newly initialized bfd *, which
12723 includes a canonicalized copy of FILE_NAME.
12724 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12725 SEARCH_CWD is true if the current directory is to be searched.
12726 It will be searched before debug-file-directory.
12727 If successful, the file is added to the bfd include table of the
12728 objfile's bfd (see gdb_bfd_record_inclusion).
12729 If unable to find/open the file, return NULL.
12730 NOTE: This function is derived from symfile_bfd_open. */
12732 static gdb_bfd_ref_ptr
12733 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12734 const char *file_name
, int is_dwp
, int search_cwd
)
12737 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12738 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12739 to debug_file_directory. */
12740 const char *search_path
;
12741 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12743 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12746 if (*debug_file_directory
!= '\0')
12748 search_path_holder
.reset (concat (".", dirname_separator_string
,
12749 debug_file_directory
,
12751 search_path
= search_path_holder
.get ();
12757 search_path
= debug_file_directory
;
12759 openp_flags flags
= OPF_RETURN_REALPATH
;
12761 flags
|= OPF_SEARCH_IN_PATH
;
12763 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12764 desc
= openp (search_path
, flags
, file_name
,
12765 O_RDONLY
| O_BINARY
, &absolute_name
);
12769 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12771 if (sym_bfd
== NULL
)
12773 bfd_set_cacheable (sym_bfd
.get (), 1);
12775 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12778 /* Success. Record the bfd as having been included by the objfile's bfd.
12779 This is important because things like demangled_names_hash lives in the
12780 objfile's per_bfd space and may have references to things like symbol
12781 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12782 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12787 /* Try to open DWO file FILE_NAME.
12788 COMP_DIR is the DW_AT_comp_dir attribute.
12789 The result is the bfd handle of the file.
12790 If there is a problem finding or opening the file, return NULL.
12791 Upon success, the canonicalized path of the file is stored in the bfd,
12792 same as symfile_bfd_open. */
12794 static gdb_bfd_ref_ptr
12795 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12796 const char *file_name
, const char *comp_dir
)
12798 if (IS_ABSOLUTE_PATH (file_name
))
12799 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12800 0 /*is_dwp*/, 0 /*search_cwd*/);
12802 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12804 if (comp_dir
!= NULL
)
12806 char *path_to_try
= concat (comp_dir
, SLASH_STRING
,
12807 file_name
, (char *) NULL
);
12809 /* NOTE: If comp_dir is a relative path, this will also try the
12810 search path, which seems useful. */
12811 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12814 1 /*search_cwd*/));
12815 xfree (path_to_try
);
12820 /* That didn't work, try debug-file-directory, which, despite its name,
12821 is a list of paths. */
12823 if (*debug_file_directory
== '\0')
12826 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12827 0 /*is_dwp*/, 1 /*search_cwd*/);
12830 /* This function is mapped across the sections and remembers the offset and
12831 size of each of the DWO debugging sections we are interested in. */
12834 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12836 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12837 const struct dwop_section_names
*names
= &dwop_section_names
;
12839 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12841 dwo_sections
->abbrev
.s
.section
= sectp
;
12842 dwo_sections
->abbrev
.size
= bfd_get_section_size (sectp
);
12844 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12846 dwo_sections
->info
.s
.section
= sectp
;
12847 dwo_sections
->info
.size
= bfd_get_section_size (sectp
);
12849 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12851 dwo_sections
->line
.s
.section
= sectp
;
12852 dwo_sections
->line
.size
= bfd_get_section_size (sectp
);
12854 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12856 dwo_sections
->loc
.s
.section
= sectp
;
12857 dwo_sections
->loc
.size
= bfd_get_section_size (sectp
);
12859 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12861 dwo_sections
->macinfo
.s
.section
= sectp
;
12862 dwo_sections
->macinfo
.size
= bfd_get_section_size (sectp
);
12864 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12866 dwo_sections
->macro
.s
.section
= sectp
;
12867 dwo_sections
->macro
.size
= bfd_get_section_size (sectp
);
12869 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12871 dwo_sections
->str
.s
.section
= sectp
;
12872 dwo_sections
->str
.size
= bfd_get_section_size (sectp
);
12874 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12876 dwo_sections
->str_offsets
.s
.section
= sectp
;
12877 dwo_sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
12879 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12881 struct dwarf2_section_info type_section
;
12883 memset (&type_section
, 0, sizeof (type_section
));
12884 type_section
.s
.section
= sectp
;
12885 type_section
.size
= bfd_get_section_size (sectp
);
12886 VEC_safe_push (dwarf2_section_info_def
, dwo_sections
->types
,
12891 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12892 by PER_CU. This is for the non-DWP case.
12893 The result is NULL if DWO_NAME can't be found. */
12895 static struct dwo_file
*
12896 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12897 const char *dwo_name
, const char *comp_dir
)
12899 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12900 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12902 gdb_bfd_ref_ptr
dbfd (open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
));
12905 if (dwarf_read_debug
)
12906 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12910 /* We use a unique pointer here, despite the obstack allocation,
12911 because a dwo_file needs some cleanup if it is abandoned. */
12912 dwo_file_up
dwo_file (OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
12914 dwo_file
->dwo_name
= dwo_name
;
12915 dwo_file
->comp_dir
= comp_dir
;
12916 dwo_file
->dbfd
= dbfd
.release ();
12918 bfd_map_over_sections (dwo_file
->dbfd
, dwarf2_locate_dwo_sections
,
12919 &dwo_file
->sections
);
12921 create_cus_hash_table (dwarf2_per_objfile
, *dwo_file
, dwo_file
->sections
.info
,
12924 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12925 dwo_file
->sections
.types
, dwo_file
->tus
);
12927 if (dwarf_read_debug
)
12928 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12930 return dwo_file
.release ();
12933 /* This function is mapped across the sections and remembers the offset and
12934 size of each of the DWP debugging sections common to version 1 and 2 that
12935 we are interested in. */
12938 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12939 void *dwp_file_ptr
)
12941 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12942 const struct dwop_section_names
*names
= &dwop_section_names
;
12943 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12945 /* Record the ELF section number for later lookup: this is what the
12946 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12947 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12948 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12950 /* Look for specific sections that we need. */
12951 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12953 dwp_file
->sections
.str
.s
.section
= sectp
;
12954 dwp_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
12956 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12958 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12959 dwp_file
->sections
.cu_index
.size
= bfd_get_section_size (sectp
);
12961 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12963 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12964 dwp_file
->sections
.tu_index
.size
= bfd_get_section_size (sectp
);
12968 /* This function is mapped across the sections and remembers the offset and
12969 size of each of the DWP version 2 debugging sections that we are interested
12970 in. This is split into a separate function because we don't know if we
12971 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12974 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12976 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12977 const struct dwop_section_names
*names
= &dwop_section_names
;
12978 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12980 /* Record the ELF section number for later lookup: this is what the
12981 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12982 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12983 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12985 /* Look for specific sections that we need. */
12986 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12988 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12989 dwp_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
12991 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12993 dwp_file
->sections
.info
.s
.section
= sectp
;
12994 dwp_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
12996 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12998 dwp_file
->sections
.line
.s
.section
= sectp
;
12999 dwp_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
13001 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
13003 dwp_file
->sections
.loc
.s
.section
= sectp
;
13004 dwp_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
13006 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
13008 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
13009 dwp_file
->sections
.macinfo
.size
= bfd_get_section_size (sectp
);
13011 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13013 dwp_file
->sections
.macro
.s
.section
= sectp
;
13014 dwp_file
->sections
.macro
.size
= bfd_get_section_size (sectp
);
13016 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13018 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
13019 dwp_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
13021 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13023 dwp_file
->sections
.types
.s
.section
= sectp
;
13024 dwp_file
->sections
.types
.size
= bfd_get_section_size (sectp
);
13028 /* Hash function for dwp_file loaded CUs/TUs. */
13031 hash_dwp_loaded_cutus (const void *item
)
13033 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
13035 /* This drops the top 32 bits of the signature, but is ok for a hash. */
13036 return dwo_unit
->signature
;
13039 /* Equality function for dwp_file loaded CUs/TUs. */
13042 eq_dwp_loaded_cutus (const void *a
, const void *b
)
13044 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
13045 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
13047 return dua
->signature
== dub
->signature
;
13050 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
13053 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
13055 return htab_create_alloc_ex (3,
13056 hash_dwp_loaded_cutus
,
13057 eq_dwp_loaded_cutus
,
13059 &objfile
->objfile_obstack
,
13060 hashtab_obstack_allocate
,
13061 dummy_obstack_deallocate
);
13064 /* Try to open DWP file FILE_NAME.
13065 The result is the bfd handle of the file.
13066 If there is a problem finding or opening the file, return NULL.
13067 Upon success, the canonicalized path of the file is stored in the bfd,
13068 same as symfile_bfd_open. */
13070 static gdb_bfd_ref_ptr
13071 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13072 const char *file_name
)
13074 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
13076 1 /*search_cwd*/));
13080 /* Work around upstream bug 15652.
13081 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
13082 [Whether that's a "bug" is debatable, but it is getting in our way.]
13083 We have no real idea where the dwp file is, because gdb's realpath-ing
13084 of the executable's path may have discarded the needed info.
13085 [IWBN if the dwp file name was recorded in the executable, akin to
13086 .gnu_debuglink, but that doesn't exist yet.]
13087 Strip the directory from FILE_NAME and search again. */
13088 if (*debug_file_directory
!= '\0')
13090 /* Don't implicitly search the current directory here.
13091 If the user wants to search "." to handle this case,
13092 it must be added to debug-file-directory. */
13093 return try_open_dwop_file (dwarf2_per_objfile
,
13094 lbasename (file_name
), 1 /*is_dwp*/,
13101 /* Initialize the use of the DWP file for the current objfile.
13102 By convention the name of the DWP file is ${objfile}.dwp.
13103 The result is NULL if it can't be found. */
13105 static struct dwp_file
*
13106 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13108 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13109 struct dwp_file
*dwp_file
;
13111 /* Try to find first .dwp for the binary file before any symbolic links
13114 /* If the objfile is a debug file, find the name of the real binary
13115 file and get the name of dwp file from there. */
13116 std::string dwp_name
;
13117 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
13119 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
13120 const char *backlink_basename
= lbasename (backlink
->original_name
);
13122 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
13125 dwp_name
= objfile
->original_name
;
13127 dwp_name
+= ".dwp";
13129 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
13131 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
13133 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
13134 dwp_name
= objfile_name (objfile
);
13135 dwp_name
+= ".dwp";
13136 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
13141 if (dwarf_read_debug
)
13142 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
13145 dwp_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_file
);
13146 dwp_file
->name
= bfd_get_filename (dbfd
.get ());
13147 dwp_file
->dbfd
= dbfd
.release ();
13149 /* +1: section 0 is unused */
13150 dwp_file
->num_sections
= bfd_count_sections (dwp_file
->dbfd
) + 1;
13151 dwp_file
->elf_sections
=
13152 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
13153 dwp_file
->num_sections
, asection
*);
13155 bfd_map_over_sections (dwp_file
->dbfd
, dwarf2_locate_common_dwp_sections
,
13158 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
, 0);
13160 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
, 1);
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
, dwarf2_locate_v2_dwp_sections
,
13186 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
13187 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
13189 if (dwarf_read_debug
)
13191 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
13192 fprintf_unfiltered (gdb_stdlog
,
13193 " %s CUs, %s TUs\n",
13194 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13195 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13201 /* Wrapper around open_and_init_dwp_file, only open it once. */
13203 static struct dwp_file
*
13204 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13206 if (! dwarf2_per_objfile
->dwp_checked
)
13208 dwarf2_per_objfile
->dwp_file
13209 = open_and_init_dwp_file (dwarf2_per_objfile
);
13210 dwarf2_per_objfile
->dwp_checked
= 1;
13212 return dwarf2_per_objfile
->dwp_file
;
13215 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13216 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13217 or in the DWP file for the objfile, referenced by THIS_UNIT.
13218 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13219 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13221 This is called, for example, when wanting to read a variable with a
13222 complex location. Therefore we don't want to do file i/o for every call.
13223 Therefore we don't want to look for a DWO file on every call.
13224 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13225 then we check if we've already seen DWO_NAME, and only THEN do we check
13228 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13229 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13231 static struct dwo_unit
*
13232 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
13233 const char *dwo_name
, const char *comp_dir
,
13234 ULONGEST signature
, int is_debug_types
)
13236 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
13237 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13238 const char *kind
= is_debug_types
? "TU" : "CU";
13239 void **dwo_file_slot
;
13240 struct dwo_file
*dwo_file
;
13241 struct dwp_file
*dwp_file
;
13243 /* First see if there's a DWP file.
13244 If we have a DWP file but didn't find the DWO inside it, don't
13245 look for the original DWO file. It makes gdb behave differently
13246 depending on whether one is debugging in the build tree. */
13248 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
13249 if (dwp_file
!= NULL
)
13251 const struct dwp_hash_table
*dwp_htab
=
13252 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13254 if (dwp_htab
!= NULL
)
13256 struct dwo_unit
*dwo_cutu
=
13257 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
13258 signature
, is_debug_types
);
13260 if (dwo_cutu
!= NULL
)
13262 if (dwarf_read_debug
)
13264 fprintf_unfiltered (gdb_stdlog
,
13265 "Virtual DWO %s %s found: @%s\n",
13266 kind
, hex_string (signature
),
13267 host_address_to_string (dwo_cutu
));
13275 /* No DWP file, look for the DWO file. */
13277 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
13278 dwo_name
, comp_dir
);
13279 if (*dwo_file_slot
== NULL
)
13281 /* Read in the file and build a table of the CUs/TUs it contains. */
13282 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
13284 /* NOTE: This will be NULL if unable to open the file. */
13285 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13287 if (dwo_file
!= NULL
)
13289 struct dwo_unit
*dwo_cutu
= NULL
;
13291 if (is_debug_types
&& dwo_file
->tus
)
13293 struct dwo_unit find_dwo_cutu
;
13295 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13296 find_dwo_cutu
.signature
= signature
;
13298 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
13300 else if (!is_debug_types
&& dwo_file
->cus
)
13302 struct dwo_unit find_dwo_cutu
;
13304 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13305 find_dwo_cutu
.signature
= signature
;
13306 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
,
13310 if (dwo_cutu
!= NULL
)
13312 if (dwarf_read_debug
)
13314 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
13315 kind
, dwo_name
, hex_string (signature
),
13316 host_address_to_string (dwo_cutu
));
13323 /* We didn't find it. This could mean a dwo_id mismatch, or
13324 someone deleted the DWO/DWP file, or the search path isn't set up
13325 correctly to find the file. */
13327 if (dwarf_read_debug
)
13329 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
13330 kind
, dwo_name
, hex_string (signature
));
13333 /* This is a warning and not a complaint because it can be caused by
13334 pilot error (e.g., user accidentally deleting the DWO). */
13336 /* Print the name of the DWP file if we looked there, helps the user
13337 better diagnose the problem. */
13338 std::string dwp_text
;
13340 if (dwp_file
!= NULL
)
13341 dwp_text
= string_printf (" [in DWP file %s]",
13342 lbasename (dwp_file
->name
));
13344 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13345 " [in module %s]"),
13346 kind
, dwo_name
, hex_string (signature
),
13348 this_unit
->is_debug_types
? "TU" : "CU",
13349 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
13354 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13355 See lookup_dwo_cutu_unit for details. */
13357 static struct dwo_unit
*
13358 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
13359 const char *dwo_name
, const char *comp_dir
,
13360 ULONGEST signature
)
13362 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
13365 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13366 See lookup_dwo_cutu_unit for details. */
13368 static struct dwo_unit
*
13369 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
13370 const char *dwo_name
, const char *comp_dir
)
13372 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
13375 /* Traversal function for queue_and_load_all_dwo_tus. */
13378 queue_and_load_dwo_tu (void **slot
, void *info
)
13380 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13381 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
13382 ULONGEST signature
= dwo_unit
->signature
;
13383 struct signatured_type
*sig_type
=
13384 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
13386 if (sig_type
!= NULL
)
13388 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13390 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13391 a real dependency of PER_CU on SIG_TYPE. That is detected later
13392 while processing PER_CU. */
13393 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
13394 load_full_type_unit (sig_cu
);
13395 VEC_safe_push (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, sig_cu
);
13401 /* Queue all TUs contained in the DWO of PER_CU to be read in.
13402 The DWO may have the only definition of the type, though it may not be
13403 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13404 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13407 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
13409 struct dwo_unit
*dwo_unit
;
13410 struct dwo_file
*dwo_file
;
13412 gdb_assert (!per_cu
->is_debug_types
);
13413 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
13414 gdb_assert (per_cu
->cu
!= NULL
);
13416 dwo_unit
= per_cu
->cu
->dwo_unit
;
13417 gdb_assert (dwo_unit
!= NULL
);
13419 dwo_file
= dwo_unit
->dwo_file
;
13420 if (dwo_file
->tus
!= NULL
)
13421 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
13424 /* Free all resources associated with DWO_FILE.
13425 Close the DWO file and munmap the sections. */
13428 free_dwo_file (struct dwo_file
*dwo_file
)
13430 /* Note: dbfd is NULL for virtual DWO files. */
13431 gdb_bfd_unref (dwo_file
->dbfd
);
13433 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
13436 /* Traversal function for free_dwo_files. */
13439 free_dwo_file_from_slot (void **slot
, void *info
)
13441 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
13443 free_dwo_file (dwo_file
);
13448 /* Free all resources associated with DWO_FILES. */
13451 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
13453 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
13456 /* Read in various DIEs. */
13458 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13459 Inherit only the children of the DW_AT_abstract_origin DIE not being
13460 already referenced by DW_AT_abstract_origin from the children of the
13464 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13466 struct die_info
*child_die
;
13467 sect_offset
*offsetp
;
13468 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13469 struct die_info
*origin_die
;
13470 /* Iterator of the ORIGIN_DIE children. */
13471 struct die_info
*origin_child_die
;
13472 struct attribute
*attr
;
13473 struct dwarf2_cu
*origin_cu
;
13474 struct pending
**origin_previous_list_in_scope
;
13476 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13480 /* Note that following die references may follow to a die in a
13484 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13486 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13488 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13489 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13491 if (die
->tag
!= origin_die
->tag
13492 && !(die
->tag
== DW_TAG_inlined_subroutine
13493 && origin_die
->tag
== DW_TAG_subprogram
))
13494 complaint (&symfile_complaints
,
13495 _("DIE %s and its abstract origin %s have different tags"),
13496 sect_offset_str (die
->sect_off
),
13497 sect_offset_str (origin_die
->sect_off
));
13499 std::vector
<sect_offset
> offsets
;
13501 for (child_die
= die
->child
;
13502 child_die
&& child_die
->tag
;
13503 child_die
= sibling_die (child_die
))
13505 struct die_info
*child_origin_die
;
13506 struct dwarf2_cu
*child_origin_cu
;
13508 /* We are trying to process concrete instance entries:
13509 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13510 it's not relevant to our analysis here. i.e. detecting DIEs that are
13511 present in the abstract instance but not referenced in the concrete
13513 if (child_die
->tag
== DW_TAG_call_site
13514 || child_die
->tag
== DW_TAG_GNU_call_site
)
13517 /* For each CHILD_DIE, find the corresponding child of
13518 ORIGIN_DIE. If there is more than one layer of
13519 DW_AT_abstract_origin, follow them all; there shouldn't be,
13520 but GCC versions at least through 4.4 generate this (GCC PR
13522 child_origin_die
= child_die
;
13523 child_origin_cu
= cu
;
13526 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13530 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13534 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13535 counterpart may exist. */
13536 if (child_origin_die
!= child_die
)
13538 if (child_die
->tag
!= child_origin_die
->tag
13539 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13540 && child_origin_die
->tag
== DW_TAG_subprogram
))
13541 complaint (&symfile_complaints
,
13542 _("Child DIE %s and its abstract origin %s have "
13544 sect_offset_str (child_die
->sect_off
),
13545 sect_offset_str (child_origin_die
->sect_off
));
13546 if (child_origin_die
->parent
!= origin_die
)
13547 complaint (&symfile_complaints
,
13548 _("Child DIE %s and its abstract origin %s have "
13549 "different parents"),
13550 sect_offset_str (child_die
->sect_off
),
13551 sect_offset_str (child_origin_die
->sect_off
));
13553 offsets
.push_back (child_origin_die
->sect_off
);
13556 std::sort (offsets
.begin (), offsets
.end ());
13557 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13558 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13559 if (offsetp
[-1] == *offsetp
)
13560 complaint (&symfile_complaints
,
13561 _("Multiple children of DIE %s refer "
13562 "to DIE %s as their abstract origin"),
13563 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13565 offsetp
= offsets
.data ();
13566 origin_child_die
= origin_die
->child
;
13567 while (origin_child_die
&& origin_child_die
->tag
)
13569 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13570 while (offsetp
< offsets_end
13571 && *offsetp
< origin_child_die
->sect_off
)
13573 if (offsetp
>= offsets_end
13574 || *offsetp
> origin_child_die
->sect_off
)
13576 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13577 Check whether we're already processing ORIGIN_CHILD_DIE.
13578 This can happen with mutually referenced abstract_origins.
13580 if (!origin_child_die
->in_process
)
13581 process_die (origin_child_die
, origin_cu
);
13583 origin_child_die
= sibling_die (origin_child_die
);
13585 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13589 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13591 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13592 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13593 struct context_stack
*newobj
;
13596 struct die_info
*child_die
;
13597 struct attribute
*attr
, *call_line
, *call_file
;
13599 CORE_ADDR baseaddr
;
13600 struct block
*block
;
13601 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13602 std::vector
<struct symbol
*> template_args
;
13603 struct template_symbol
*templ_func
= NULL
;
13607 /* If we do not have call site information, we can't show the
13608 caller of this inlined function. That's too confusing, so
13609 only use the scope for local variables. */
13610 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13611 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13612 if (call_line
== NULL
|| call_file
== NULL
)
13614 read_lexical_block_scope (die
, cu
);
13619 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13621 name
= dwarf2_name (die
, cu
);
13623 /* Ignore functions with missing or empty names. These are actually
13624 illegal according to the DWARF standard. */
13627 complaint (&symfile_complaints
,
13628 _("missing name for subprogram DIE at %s"),
13629 sect_offset_str (die
->sect_off
));
13633 /* Ignore functions with missing or invalid low and high pc attributes. */
13634 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13635 <= PC_BOUNDS_INVALID
)
13637 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13638 if (!attr
|| !DW_UNSND (attr
))
13639 complaint (&symfile_complaints
,
13640 _("cannot get low and high bounds "
13641 "for subprogram DIE at %s"),
13642 sect_offset_str (die
->sect_off
));
13646 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13647 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13649 /* If we have any template arguments, then we must allocate a
13650 different sort of symbol. */
13651 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
13653 if (child_die
->tag
== DW_TAG_template_type_param
13654 || child_die
->tag
== DW_TAG_template_value_param
)
13656 templ_func
= allocate_template_symbol (objfile
);
13657 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13662 newobj
= push_context (0, lowpc
);
13663 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13664 (struct symbol
*) templ_func
);
13666 /* If there is a location expression for DW_AT_frame_base, record
13668 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13670 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13672 /* If there is a location for the static link, record it. */
13673 newobj
->static_link
= NULL
;
13674 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13677 newobj
->static_link
13678 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13679 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
);
13682 cu
->list_in_scope
= &local_symbols
;
13684 if (die
->child
!= NULL
)
13686 child_die
= die
->child
;
13687 while (child_die
&& child_die
->tag
)
13689 if (child_die
->tag
== DW_TAG_template_type_param
13690 || child_die
->tag
== DW_TAG_template_value_param
)
13692 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13695 template_args
.push_back (arg
);
13698 process_die (child_die
, cu
);
13699 child_die
= sibling_die (child_die
);
13703 inherit_abstract_dies (die
, cu
);
13705 /* If we have a DW_AT_specification, we might need to import using
13706 directives from the context of the specification DIE. See the
13707 comment in determine_prefix. */
13708 if (cu
->language
== language_cplus
13709 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13711 struct dwarf2_cu
*spec_cu
= cu
;
13712 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13716 child_die
= spec_die
->child
;
13717 while (child_die
&& child_die
->tag
)
13719 if (child_die
->tag
== DW_TAG_imported_module
)
13720 process_die (child_die
, spec_cu
);
13721 child_die
= sibling_die (child_die
);
13724 /* In some cases, GCC generates specification DIEs that
13725 themselves contain DW_AT_specification attributes. */
13726 spec_die
= die_specification (spec_die
, &spec_cu
);
13730 newobj
= pop_context ();
13731 /* Make a block for the local symbols within. */
13732 block
= finish_block (newobj
->name
, &local_symbols
, newobj
->old_blocks
,
13733 newobj
->static_link
, lowpc
, highpc
);
13735 /* For C++, set the block's scope. */
13736 if ((cu
->language
== language_cplus
13737 || cu
->language
== language_fortran
13738 || cu
->language
== language_d
13739 || cu
->language
== language_rust
)
13740 && cu
->processing_has_namespace_info
)
13741 block_set_scope (block
, determine_prefix (die
, cu
),
13742 &objfile
->objfile_obstack
);
13744 /* If we have address ranges, record them. */
13745 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13747 gdbarch_make_symbol_special (gdbarch
, newobj
->name
, objfile
);
13749 /* Attach template arguments to function. */
13750 if (!template_args
.empty ())
13752 gdb_assert (templ_func
!= NULL
);
13754 templ_func
->n_template_arguments
= template_args
.size ();
13755 templ_func
->template_arguments
13756 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13757 templ_func
->n_template_arguments
);
13758 memcpy (templ_func
->template_arguments
,
13759 template_args
.data (),
13760 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13763 /* In C++, we can have functions nested inside functions (e.g., when
13764 a function declares a class that has methods). This means that
13765 when we finish processing a function scope, we may need to go
13766 back to building a containing block's symbol lists. */
13767 local_symbols
= newobj
->locals
;
13768 local_using_directives
= newobj
->local_using_directives
;
13770 /* If we've finished processing a top-level function, subsequent
13771 symbols go in the file symbol list. */
13772 if (outermost_context_p ())
13773 cu
->list_in_scope
= &file_symbols
;
13776 /* Process all the DIES contained within a lexical block scope. Start
13777 a new scope, process the dies, and then close the scope. */
13780 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13782 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13783 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13784 struct context_stack
*newobj
;
13785 CORE_ADDR lowpc
, highpc
;
13786 struct die_info
*child_die
;
13787 CORE_ADDR baseaddr
;
13789 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13791 /* Ignore blocks with missing or invalid low and high pc attributes. */
13792 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13793 as multiple lexical blocks? Handling children in a sane way would
13794 be nasty. Might be easier to properly extend generic blocks to
13795 describe ranges. */
13796 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13798 case PC_BOUNDS_NOT_PRESENT
:
13799 /* DW_TAG_lexical_block has no attributes, process its children as if
13800 there was no wrapping by that DW_TAG_lexical_block.
13801 GCC does no longer produces such DWARF since GCC r224161. */
13802 for (child_die
= die
->child
;
13803 child_die
!= NULL
&& child_die
->tag
;
13804 child_die
= sibling_die (child_die
))
13805 process_die (child_die
, cu
);
13807 case PC_BOUNDS_INVALID
:
13810 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13811 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13813 push_context (0, lowpc
);
13814 if (die
->child
!= NULL
)
13816 child_die
= die
->child
;
13817 while (child_die
&& child_die
->tag
)
13819 process_die (child_die
, cu
);
13820 child_die
= sibling_die (child_die
);
13823 inherit_abstract_dies (die
, cu
);
13824 newobj
= pop_context ();
13826 if (local_symbols
!= NULL
|| local_using_directives
!= NULL
)
13828 struct block
*block
13829 = finish_block (0, &local_symbols
, newobj
->old_blocks
, NULL
,
13830 newobj
->start_addr
, highpc
);
13832 /* Note that recording ranges after traversing children, as we
13833 do here, means that recording a parent's ranges entails
13834 walking across all its children's ranges as they appear in
13835 the address map, which is quadratic behavior.
13837 It would be nicer to record the parent's ranges before
13838 traversing its children, simply overriding whatever you find
13839 there. But since we don't even decide whether to create a
13840 block until after we've traversed its children, that's hard
13842 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13844 local_symbols
= newobj
->locals
;
13845 local_using_directives
= newobj
->local_using_directives
;
13848 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13851 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13853 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13854 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13855 CORE_ADDR pc
, baseaddr
;
13856 struct attribute
*attr
;
13857 struct call_site
*call_site
, call_site_local
;
13860 struct die_info
*child_die
;
13862 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13864 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13867 /* This was a pre-DWARF-5 GNU extension alias
13868 for DW_AT_call_return_pc. */
13869 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13873 complaint (&symfile_complaints
,
13874 _("missing DW_AT_call_return_pc for DW_TAG_call_site "
13875 "DIE %s [in module %s]"),
13876 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13879 pc
= attr_value_as_address (attr
) + baseaddr
;
13880 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13882 if (cu
->call_site_htab
== NULL
)
13883 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13884 NULL
, &objfile
->objfile_obstack
,
13885 hashtab_obstack_allocate
, NULL
);
13886 call_site_local
.pc
= pc
;
13887 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13890 complaint (&symfile_complaints
,
13891 _("Duplicate PC %s for DW_TAG_call_site "
13892 "DIE %s [in module %s]"),
13893 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13894 objfile_name (objfile
));
13898 /* Count parameters at the caller. */
13901 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13902 child_die
= sibling_die (child_die
))
13904 if (child_die
->tag
!= DW_TAG_call_site_parameter
13905 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13907 complaint (&symfile_complaints
,
13908 _("Tag %d is not DW_TAG_call_site_parameter in "
13909 "DW_TAG_call_site child DIE %s [in module %s]"),
13910 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13911 objfile_name (objfile
));
13919 = ((struct call_site
*)
13920 obstack_alloc (&objfile
->objfile_obstack
,
13921 sizeof (*call_site
)
13922 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13924 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13925 call_site
->pc
= pc
;
13927 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13928 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13930 struct die_info
*func_die
;
13932 /* Skip also over DW_TAG_inlined_subroutine. */
13933 for (func_die
= die
->parent
;
13934 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13935 && func_die
->tag
!= DW_TAG_subroutine_type
;
13936 func_die
= func_die
->parent
);
13938 /* DW_AT_call_all_calls is a superset
13939 of DW_AT_call_all_tail_calls. */
13941 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13942 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13943 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13944 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13946 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13947 not complete. But keep CALL_SITE for look ups via call_site_htab,
13948 both the initial caller containing the real return address PC and
13949 the final callee containing the current PC of a chain of tail
13950 calls do not need to have the tail call list complete. But any
13951 function candidate for a virtual tail call frame searched via
13952 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13953 determined unambiguously. */
13957 struct type
*func_type
= NULL
;
13960 func_type
= get_die_type (func_die
, cu
);
13961 if (func_type
!= NULL
)
13963 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
13965 /* Enlist this call site to the function. */
13966 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13967 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13970 complaint (&symfile_complaints
,
13971 _("Cannot find function owning DW_TAG_call_site "
13972 "DIE %s [in module %s]"),
13973 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13977 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13979 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13981 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13984 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13985 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13987 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13988 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
13989 /* Keep NULL DWARF_BLOCK. */;
13990 else if (attr_form_is_block (attr
))
13992 struct dwarf2_locexpr_baton
*dlbaton
;
13994 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13995 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13996 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13997 dlbaton
->per_cu
= cu
->per_cu
;
13999 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
14001 else if (attr_form_is_ref (attr
))
14003 struct dwarf2_cu
*target_cu
= cu
;
14004 struct die_info
*target_die
;
14006 target_die
= follow_die_ref (die
, attr
, &target_cu
);
14007 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
14008 if (die_is_declaration (target_die
, target_cu
))
14010 const char *target_physname
;
14012 /* Prefer the mangled name; otherwise compute the demangled one. */
14013 target_physname
= dw2_linkage_name (target_die
, target_cu
);
14014 if (target_physname
== NULL
)
14015 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
14016 if (target_physname
== NULL
)
14017 complaint (&symfile_complaints
,
14018 _("DW_AT_call_target target DIE has invalid "
14019 "physname, for referencing DIE %s [in module %s]"),
14020 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14022 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
14028 /* DW_AT_entry_pc should be preferred. */
14029 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
14030 <= PC_BOUNDS_INVALID
)
14031 complaint (&symfile_complaints
,
14032 _("DW_AT_call_target target DIE has invalid "
14033 "low pc, for referencing DIE %s [in module %s]"),
14034 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14037 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14038 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
14043 complaint (&symfile_complaints
,
14044 _("DW_TAG_call_site DW_AT_call_target is neither "
14045 "block nor reference, for DIE %s [in module %s]"),
14046 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14048 call_site
->per_cu
= cu
->per_cu
;
14050 for (child_die
= die
->child
;
14051 child_die
&& child_die
->tag
;
14052 child_die
= sibling_die (child_die
))
14054 struct call_site_parameter
*parameter
;
14055 struct attribute
*loc
, *origin
;
14057 if (child_die
->tag
!= DW_TAG_call_site_parameter
14058 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14060 /* Already printed the complaint above. */
14064 gdb_assert (call_site
->parameter_count
< nparams
);
14065 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
14067 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
14068 specifies DW_TAG_formal_parameter. Value of the data assumed for the
14069 register is contained in DW_AT_call_value. */
14071 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
14072 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
14073 if (origin
== NULL
)
14075 /* This was a pre-DWARF-5 GNU extension alias
14076 for DW_AT_call_parameter. */
14077 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
14079 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
14081 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
14083 sect_offset sect_off
14084 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
14085 if (!offset_in_cu_p (&cu
->header
, sect_off
))
14087 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
14088 binding can be done only inside one CU. Such referenced DIE
14089 therefore cannot be even moved to DW_TAG_partial_unit. */
14090 complaint (&symfile_complaints
,
14091 _("DW_AT_call_parameter offset is not in CU for "
14092 "DW_TAG_call_site child DIE %s [in module %s]"),
14093 sect_offset_str (child_die
->sect_off
),
14094 objfile_name (objfile
));
14097 parameter
->u
.param_cu_off
14098 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
14100 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
14102 complaint (&symfile_complaints
,
14103 _("No DW_FORM_block* DW_AT_location for "
14104 "DW_TAG_call_site child DIE %s [in module %s]"),
14105 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
14110 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
14111 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
14112 if (parameter
->u
.dwarf_reg
!= -1)
14113 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
14114 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
14115 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
14116 ¶meter
->u
.fb_offset
))
14117 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
14120 complaint (&symfile_complaints
,
14121 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
14122 "for DW_FORM_block* DW_AT_location is supported for "
14123 "DW_TAG_call_site child DIE %s "
14125 sect_offset_str (child_die
->sect_off
),
14126 objfile_name (objfile
));
14131 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
14133 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
14134 if (!attr_form_is_block (attr
))
14136 complaint (&symfile_complaints
,
14137 _("No DW_FORM_block* DW_AT_call_value for "
14138 "DW_TAG_call_site child DIE %s [in module %s]"),
14139 sect_offset_str (child_die
->sect_off
),
14140 objfile_name (objfile
));
14143 parameter
->value
= DW_BLOCK (attr
)->data
;
14144 parameter
->value_size
= DW_BLOCK (attr
)->size
;
14146 /* Parameters are not pre-cleared by memset above. */
14147 parameter
->data_value
= NULL
;
14148 parameter
->data_value_size
= 0;
14149 call_site
->parameter_count
++;
14151 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
14153 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
14156 if (!attr_form_is_block (attr
))
14157 complaint (&symfile_complaints
,
14158 _("No DW_FORM_block* DW_AT_call_data_value for "
14159 "DW_TAG_call_site child DIE %s [in module %s]"),
14160 sect_offset_str (child_die
->sect_off
),
14161 objfile_name (objfile
));
14164 parameter
->data_value
= DW_BLOCK (attr
)->data
;
14165 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
14171 /* Helper function for read_variable. If DIE represents a virtual
14172 table, then return the type of the concrete object that is
14173 associated with the virtual table. Otherwise, return NULL. */
14175 static struct type
*
14176 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14178 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14182 /* Find the type DIE. */
14183 struct die_info
*type_die
= NULL
;
14184 struct dwarf2_cu
*type_cu
= cu
;
14186 if (attr_form_is_ref (attr
))
14187 type_die
= follow_die_ref (die
, attr
, &type_cu
);
14188 if (type_die
== NULL
)
14191 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
14193 return die_containing_type (type_die
, type_cu
);
14196 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
14199 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
14201 struct rust_vtable_symbol
*storage
= NULL
;
14203 if (cu
->language
== language_rust
)
14205 struct type
*containing_type
= rust_containing_type (die
, cu
);
14207 if (containing_type
!= NULL
)
14209 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14211 storage
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
14212 struct rust_vtable_symbol
);
14213 initialize_objfile_symbol (storage
);
14214 storage
->concrete_type
= containing_type
;
14215 storage
->subclass
= SYMBOL_RUST_VTABLE
;
14219 new_symbol (die
, NULL
, cu
, storage
);
14222 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14223 reading .debug_rnglists.
14224 Callback's type should be:
14225 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14226 Return true if the attributes are present and valid, otherwise,
14229 template <typename Callback
>
14231 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14232 Callback
&&callback
)
14234 struct dwarf2_per_objfile
*dwarf2_per_objfile
14235 = cu
->per_cu
->dwarf2_per_objfile
;
14236 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14237 bfd
*obfd
= objfile
->obfd
;
14238 /* Base address selection entry. */
14241 const gdb_byte
*buffer
;
14242 CORE_ADDR baseaddr
;
14243 bool overflow
= false;
14245 found_base
= cu
->base_known
;
14246 base
= cu
->base_address
;
14248 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->rnglists
);
14249 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
14251 complaint (&symfile_complaints
,
14252 _("Offset %d out of bounds for DW_AT_ranges attribute"),
14256 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
14258 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14262 /* Initialize it due to a false compiler warning. */
14263 CORE_ADDR range_beginning
= 0, range_end
= 0;
14264 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
14265 + dwarf2_per_objfile
->rnglists
.size
);
14266 unsigned int bytes_read
;
14268 if (buffer
== buf_end
)
14273 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14276 case DW_RLE_end_of_list
:
14278 case DW_RLE_base_address
:
14279 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14284 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14286 buffer
+= bytes_read
;
14288 case DW_RLE_start_length
:
14289 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14294 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14295 buffer
+= bytes_read
;
14296 range_end
= (range_beginning
14297 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14298 buffer
+= bytes_read
;
14299 if (buffer
> buf_end
)
14305 case DW_RLE_offset_pair
:
14306 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14307 buffer
+= bytes_read
;
14308 if (buffer
> buf_end
)
14313 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14314 buffer
+= bytes_read
;
14315 if (buffer
> buf_end
)
14321 case DW_RLE_start_end
:
14322 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14327 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14328 buffer
+= bytes_read
;
14329 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14330 buffer
+= bytes_read
;
14333 complaint (&symfile_complaints
,
14334 _("Invalid .debug_rnglists data (no base address)"));
14337 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14339 if (rlet
== DW_RLE_base_address
)
14344 /* We have no valid base address for the ranges
14346 complaint (&symfile_complaints
,
14347 _("Invalid .debug_rnglists data (no base address)"));
14351 if (range_beginning
> range_end
)
14353 /* Inverted range entries are invalid. */
14354 complaint (&symfile_complaints
,
14355 _("Invalid .debug_rnglists data (inverted range)"));
14359 /* Empty range entries have no effect. */
14360 if (range_beginning
== range_end
)
14363 range_beginning
+= base
;
14366 /* A not-uncommon case of bad debug info.
14367 Don't pollute the addrmap with bad data. */
14368 if (range_beginning
+ baseaddr
== 0
14369 && !dwarf2_per_objfile
->has_section_at_zero
)
14371 complaint (&symfile_complaints
,
14372 _(".debug_rnglists entry has start address of zero"
14373 " [in module %s]"), objfile_name (objfile
));
14377 callback (range_beginning
, range_end
);
14382 complaint (&symfile_complaints
,
14383 _("Offset %d is not terminated "
14384 "for DW_AT_ranges attribute"),
14392 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14393 Callback's type should be:
14394 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14395 Return 1 if the attributes are present and valid, otherwise, return 0. */
14397 template <typename Callback
>
14399 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
14400 Callback
&&callback
)
14402 struct dwarf2_per_objfile
*dwarf2_per_objfile
14403 = cu
->per_cu
->dwarf2_per_objfile
;
14404 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14405 struct comp_unit_head
*cu_header
= &cu
->header
;
14406 bfd
*obfd
= objfile
->obfd
;
14407 unsigned int addr_size
= cu_header
->addr_size
;
14408 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14409 /* Base address selection entry. */
14412 unsigned int dummy
;
14413 const gdb_byte
*buffer
;
14414 CORE_ADDR baseaddr
;
14416 if (cu_header
->version
>= 5)
14417 return dwarf2_rnglists_process (offset
, cu
, callback
);
14419 found_base
= cu
->base_known
;
14420 base
= cu
->base_address
;
14422 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
14423 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
14425 complaint (&symfile_complaints
,
14426 _("Offset %d out of bounds for DW_AT_ranges attribute"),
14430 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
14432 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14436 CORE_ADDR range_beginning
, range_end
;
14438 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
14439 buffer
+= addr_size
;
14440 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
14441 buffer
+= addr_size
;
14442 offset
+= 2 * addr_size
;
14444 /* An end of list marker is a pair of zero addresses. */
14445 if (range_beginning
== 0 && range_end
== 0)
14446 /* Found the end of list entry. */
14449 /* Each base address selection entry is a pair of 2 values.
14450 The first is the largest possible address, the second is
14451 the base address. Check for a base address here. */
14452 if ((range_beginning
& mask
) == mask
)
14454 /* If we found the largest possible address, then we already
14455 have the base address in range_end. */
14463 /* We have no valid base address for the ranges
14465 complaint (&symfile_complaints
,
14466 _("Invalid .debug_ranges data (no base address)"));
14470 if (range_beginning
> range_end
)
14472 /* Inverted range entries are invalid. */
14473 complaint (&symfile_complaints
,
14474 _("Invalid .debug_ranges data (inverted range)"));
14478 /* Empty range entries have no effect. */
14479 if (range_beginning
== range_end
)
14482 range_beginning
+= base
;
14485 /* A not-uncommon case of bad debug info.
14486 Don't pollute the addrmap with bad data. */
14487 if (range_beginning
+ baseaddr
== 0
14488 && !dwarf2_per_objfile
->has_section_at_zero
)
14490 complaint (&symfile_complaints
,
14491 _(".debug_ranges entry has start address of zero"
14492 " [in module %s]"), objfile_name (objfile
));
14496 callback (range_beginning
, range_end
);
14502 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14503 Return 1 if the attributes are present and valid, otherwise, return 0.
14504 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14507 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14508 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14509 struct partial_symtab
*ranges_pst
)
14511 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14512 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14513 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
14514 SECT_OFF_TEXT (objfile
));
14517 CORE_ADDR high
= 0;
14520 retval
= dwarf2_ranges_process (offset
, cu
,
14521 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14523 if (ranges_pst
!= NULL
)
14528 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
14529 range_beginning
+ baseaddr
);
14530 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
14531 range_end
+ baseaddr
);
14532 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
14536 /* FIXME: This is recording everything as a low-high
14537 segment of consecutive addresses. We should have a
14538 data structure for discontiguous block ranges
14542 low
= range_beginning
;
14548 if (range_beginning
< low
)
14549 low
= range_beginning
;
14550 if (range_end
> high
)
14558 /* If the first entry is an end-of-list marker, the range
14559 describes an empty scope, i.e. no instructions. */
14565 *high_return
= high
;
14569 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14570 definition for the return value. *LOWPC and *HIGHPC are set iff
14571 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14573 static enum pc_bounds_kind
14574 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14575 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14576 struct partial_symtab
*pst
)
14578 struct dwarf2_per_objfile
*dwarf2_per_objfile
14579 = cu
->per_cu
->dwarf2_per_objfile
;
14580 struct attribute
*attr
;
14581 struct attribute
*attr_high
;
14583 CORE_ADDR high
= 0;
14584 enum pc_bounds_kind ret
;
14586 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14589 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14592 low
= attr_value_as_address (attr
);
14593 high
= attr_value_as_address (attr_high
);
14594 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14598 /* Found high w/o low attribute. */
14599 return PC_BOUNDS_INVALID
;
14601 /* Found consecutive range of addresses. */
14602 ret
= PC_BOUNDS_HIGH_LOW
;
14606 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14609 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
14610 We take advantage of the fact that DW_AT_ranges does not appear
14611 in DW_TAG_compile_unit of DWO files. */
14612 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14613 unsigned int ranges_offset
= (DW_UNSND (attr
)
14614 + (need_ranges_base
14618 /* Value of the DW_AT_ranges attribute is the offset in the
14619 .debug_ranges section. */
14620 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14621 return PC_BOUNDS_INVALID
;
14622 /* Found discontinuous range of addresses. */
14623 ret
= PC_BOUNDS_RANGES
;
14626 return PC_BOUNDS_NOT_PRESENT
;
14629 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14631 return PC_BOUNDS_INVALID
;
14633 /* When using the GNU linker, .gnu.linkonce. sections are used to
14634 eliminate duplicate copies of functions and vtables and such.
14635 The linker will arbitrarily choose one and discard the others.
14636 The AT_*_pc values for such functions refer to local labels in
14637 these sections. If the section from that file was discarded, the
14638 labels are not in the output, so the relocs get a value of 0.
14639 If this is a discarded function, mark the pc bounds as invalid,
14640 so that GDB will ignore it. */
14641 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
14642 return PC_BOUNDS_INVALID
;
14650 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14651 its low and high PC addresses. Do nothing if these addresses could not
14652 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14653 and HIGHPC to the high address if greater than HIGHPC. */
14656 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14657 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14658 struct dwarf2_cu
*cu
)
14660 CORE_ADDR low
, high
;
14661 struct die_info
*child
= die
->child
;
14663 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14665 *lowpc
= std::min (*lowpc
, low
);
14666 *highpc
= std::max (*highpc
, high
);
14669 /* If the language does not allow nested subprograms (either inside
14670 subprograms or lexical blocks), we're done. */
14671 if (cu
->language
!= language_ada
)
14674 /* Check all the children of the given DIE. If it contains nested
14675 subprograms, then check their pc bounds. Likewise, we need to
14676 check lexical blocks as well, as they may also contain subprogram
14678 while (child
&& child
->tag
)
14680 if (child
->tag
== DW_TAG_subprogram
14681 || child
->tag
== DW_TAG_lexical_block
)
14682 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14683 child
= sibling_die (child
);
14687 /* Get the low and high pc's represented by the scope DIE, and store
14688 them in *LOWPC and *HIGHPC. If the correct values can't be
14689 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14692 get_scope_pc_bounds (struct die_info
*die
,
14693 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14694 struct dwarf2_cu
*cu
)
14696 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14697 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14698 CORE_ADDR current_low
, current_high
;
14700 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14701 >= PC_BOUNDS_RANGES
)
14703 best_low
= current_low
;
14704 best_high
= current_high
;
14708 struct die_info
*child
= die
->child
;
14710 while (child
&& child
->tag
)
14712 switch (child
->tag
) {
14713 case DW_TAG_subprogram
:
14714 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14716 case DW_TAG_namespace
:
14717 case DW_TAG_module
:
14718 /* FIXME: carlton/2004-01-16: Should we do this for
14719 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14720 that current GCC's always emit the DIEs corresponding
14721 to definitions of methods of classes as children of a
14722 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14723 the DIEs giving the declarations, which could be
14724 anywhere). But I don't see any reason why the
14725 standards says that they have to be there. */
14726 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14728 if (current_low
!= ((CORE_ADDR
) -1))
14730 best_low
= std::min (best_low
, current_low
);
14731 best_high
= std::max (best_high
, current_high
);
14739 child
= sibling_die (child
);
14744 *highpc
= best_high
;
14747 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14751 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14752 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14754 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14755 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14756 struct attribute
*attr
;
14757 struct attribute
*attr_high
;
14759 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14762 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14765 CORE_ADDR low
= attr_value_as_address (attr
);
14766 CORE_ADDR high
= attr_value_as_address (attr_high
);
14768 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14771 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14772 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14773 record_block_range (block
, low
, high
- 1);
14777 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14780 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
14781 We take advantage of the fact that DW_AT_ranges does not appear
14782 in DW_TAG_compile_unit of DWO files. */
14783 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14785 /* The value of the DW_AT_ranges attribute is the offset of the
14786 address range list in the .debug_ranges section. */
14787 unsigned long offset
= (DW_UNSND (attr
)
14788 + (need_ranges_base
? cu
->ranges_base
: 0));
14790 dwarf2_ranges_process (offset
, cu
,
14791 [&] (CORE_ADDR start
, CORE_ADDR end
)
14795 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14796 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14797 record_block_range (block
, start
, end
- 1);
14802 /* Check whether the producer field indicates either of GCC < 4.6, or the
14803 Intel C/C++ compiler, and cache the result in CU. */
14806 check_producer (struct dwarf2_cu
*cu
)
14810 if (cu
->producer
== NULL
)
14812 /* For unknown compilers expect their behavior is DWARF version
14815 GCC started to support .debug_types sections by -gdwarf-4 since
14816 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14817 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14818 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14819 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14821 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14823 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14824 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14826 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14827 cu
->producer_is_icc_lt_14
= major
< 14;
14830 /* For other non-GCC compilers, expect their behavior is DWARF version
14834 cu
->checked_producer
= 1;
14837 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14838 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14839 during 4.6.0 experimental. */
14842 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14844 if (!cu
->checked_producer
)
14845 check_producer (cu
);
14847 return cu
->producer_is_gxx_lt_4_6
;
14850 /* Return the default accessibility type if it is not overriden by
14851 DW_AT_accessibility. */
14853 static enum dwarf_access_attribute
14854 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14856 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14858 /* The default DWARF 2 accessibility for members is public, the default
14859 accessibility for inheritance is private. */
14861 if (die
->tag
!= DW_TAG_inheritance
)
14862 return DW_ACCESS_public
;
14864 return DW_ACCESS_private
;
14868 /* DWARF 3+ defines the default accessibility a different way. The same
14869 rules apply now for DW_TAG_inheritance as for the members and it only
14870 depends on the container kind. */
14872 if (die
->parent
->tag
== DW_TAG_class_type
)
14873 return DW_ACCESS_private
;
14875 return DW_ACCESS_public
;
14879 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14880 offset. If the attribute was not found return 0, otherwise return
14881 1. If it was found but could not properly be handled, set *OFFSET
14885 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14888 struct attribute
*attr
;
14890 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14895 /* Note that we do not check for a section offset first here.
14896 This is because DW_AT_data_member_location is new in DWARF 4,
14897 so if we see it, we can assume that a constant form is really
14898 a constant and not a section offset. */
14899 if (attr_form_is_constant (attr
))
14900 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
14901 else if (attr_form_is_section_offset (attr
))
14902 dwarf2_complex_location_expr_complaint ();
14903 else if (attr_form_is_block (attr
))
14904 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14906 dwarf2_complex_location_expr_complaint ();
14914 /* Add an aggregate field to the field list. */
14917 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14918 struct dwarf2_cu
*cu
)
14920 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14921 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14922 struct nextfield
*new_field
;
14923 struct attribute
*attr
;
14925 const char *fieldname
= "";
14927 if (die
->tag
== DW_TAG_inheritance
)
14929 fip
->baseclasses
.emplace_back ();
14930 new_field
= &fip
->baseclasses
.back ();
14934 fip
->fields
.emplace_back ();
14935 new_field
= &fip
->fields
.back ();
14940 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14942 new_field
->accessibility
= DW_UNSND (attr
);
14944 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14945 if (new_field
->accessibility
!= DW_ACCESS_public
)
14946 fip
->non_public_fields
= 1;
14948 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14950 new_field
->virtuality
= DW_UNSND (attr
);
14952 new_field
->virtuality
= DW_VIRTUALITY_none
;
14954 fp
= &new_field
->field
;
14956 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14960 /* Data member other than a C++ static data member. */
14962 /* Get type of field. */
14963 fp
->type
= die_type (die
, cu
);
14965 SET_FIELD_BITPOS (*fp
, 0);
14967 /* Get bit size of field (zero if none). */
14968 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14971 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14975 FIELD_BITSIZE (*fp
) = 0;
14978 /* Get bit offset of field. */
14979 if (handle_data_member_location (die
, cu
, &offset
))
14980 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14981 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14984 if (gdbarch_bits_big_endian (gdbarch
))
14986 /* For big endian bits, the DW_AT_bit_offset gives the
14987 additional bit offset from the MSB of the containing
14988 anonymous object to the MSB of the field. We don't
14989 have to do anything special since we don't need to
14990 know the size of the anonymous object. */
14991 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14995 /* For little endian bits, compute the bit offset to the
14996 MSB of the anonymous object, subtract off the number of
14997 bits from the MSB of the field to the MSB of the
14998 object, and then subtract off the number of bits of
14999 the field itself. The result is the bit offset of
15000 the LSB of the field. */
15001 int anonymous_size
;
15002 int bit_offset
= DW_UNSND (attr
);
15004 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15007 /* The size of the anonymous object containing
15008 the bit field is explicit, so use the
15009 indicated size (in bytes). */
15010 anonymous_size
= DW_UNSND (attr
);
15014 /* The size of the anonymous object containing
15015 the bit field must be inferred from the type
15016 attribute of the data member containing the
15018 anonymous_size
= TYPE_LENGTH (fp
->type
);
15020 SET_FIELD_BITPOS (*fp
,
15021 (FIELD_BITPOS (*fp
)
15022 + anonymous_size
* bits_per_byte
15023 - bit_offset
- FIELD_BITSIZE (*fp
)));
15026 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15028 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15029 + dwarf2_get_attr_constant_value (attr
, 0)));
15031 /* Get name of field. */
15032 fieldname
= dwarf2_name (die
, cu
);
15033 if (fieldname
== NULL
)
15036 /* The name is already allocated along with this objfile, so we don't
15037 need to duplicate it for the type. */
15038 fp
->name
= fieldname
;
15040 /* Change accessibility for artificial fields (e.g. virtual table
15041 pointer or virtual base class pointer) to private. */
15042 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
15044 FIELD_ARTIFICIAL (*fp
) = 1;
15045 new_field
->accessibility
= DW_ACCESS_private
;
15046 fip
->non_public_fields
= 1;
15049 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
15051 /* C++ static member. */
15053 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
15054 is a declaration, but all versions of G++ as of this writing
15055 (so through at least 3.2.1) incorrectly generate
15056 DW_TAG_variable tags. */
15058 const char *physname
;
15060 /* Get name of field. */
15061 fieldname
= dwarf2_name (die
, cu
);
15062 if (fieldname
== NULL
)
15065 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15067 /* Only create a symbol if this is an external value.
15068 new_symbol checks this and puts the value in the global symbol
15069 table, which we want. If it is not external, new_symbol
15070 will try to put the value in cu->list_in_scope which is wrong. */
15071 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
15073 /* A static const member, not much different than an enum as far as
15074 we're concerned, except that we can support more types. */
15075 new_symbol (die
, NULL
, cu
);
15078 /* Get physical name. */
15079 physname
= dwarf2_physname (fieldname
, die
, cu
);
15081 /* The name is already allocated along with this objfile, so we don't
15082 need to duplicate it for the type. */
15083 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
15084 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15085 FIELD_NAME (*fp
) = fieldname
;
15087 else if (die
->tag
== DW_TAG_inheritance
)
15091 /* C++ base class field. */
15092 if (handle_data_member_location (die
, cu
, &offset
))
15093 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15094 FIELD_BITSIZE (*fp
) = 0;
15095 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15096 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
15098 else if (die
->tag
== DW_TAG_variant_part
)
15100 /* process_structure_scope will treat this DIE as a union. */
15101 process_structure_scope (die
, cu
);
15103 /* The variant part is relative to the start of the enclosing
15105 SET_FIELD_BITPOS (*fp
, 0);
15106 fp
->type
= get_die_type (die
, cu
);
15107 fp
->artificial
= 1;
15108 fp
->name
= "<<variant>>";
15111 gdb_assert_not_reached ("missing case in dwarf2_add_field");
15114 /* Can the type given by DIE define another type? */
15117 type_can_define_types (const struct die_info
*die
)
15121 case DW_TAG_typedef
:
15122 case DW_TAG_class_type
:
15123 case DW_TAG_structure_type
:
15124 case DW_TAG_union_type
:
15125 case DW_TAG_enumeration_type
:
15133 /* Add a type definition defined in the scope of the FIP's class. */
15136 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
15137 struct dwarf2_cu
*cu
)
15139 struct decl_field fp
;
15140 memset (&fp
, 0, sizeof (fp
));
15142 gdb_assert (type_can_define_types (die
));
15144 /* Get name of field. NULL is okay here, meaning an anonymous type. */
15145 fp
.name
= dwarf2_name (die
, cu
);
15146 fp
.type
= read_type_die (die
, cu
);
15148 /* Save accessibility. */
15149 enum dwarf_access_attribute accessibility
;
15150 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15152 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15154 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15155 switch (accessibility
)
15157 case DW_ACCESS_public
:
15158 /* The assumed value if neither private nor protected. */
15160 case DW_ACCESS_private
:
15163 case DW_ACCESS_protected
:
15164 fp
.is_protected
= 1;
15167 complaint (&symfile_complaints
,
15168 _("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
15171 if (die
->tag
== DW_TAG_typedef
)
15172 fip
->typedef_field_list
.push_back (fp
);
15174 fip
->nested_types_list
.push_back (fp
);
15177 /* Create the vector of fields, and attach it to the type. */
15180 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15181 struct dwarf2_cu
*cu
)
15183 int nfields
= fip
->nfields
;
15185 /* Record the field count, allocate space for the array of fields,
15186 and create blank accessibility bitfields if necessary. */
15187 TYPE_NFIELDS (type
) = nfields
;
15188 TYPE_FIELDS (type
) = (struct field
*)
15189 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
15191 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15193 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15195 TYPE_FIELD_PRIVATE_BITS (type
) =
15196 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15197 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15199 TYPE_FIELD_PROTECTED_BITS (type
) =
15200 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15201 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15203 TYPE_FIELD_IGNORE_BITS (type
) =
15204 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15205 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15208 /* If the type has baseclasses, allocate and clear a bit vector for
15209 TYPE_FIELD_VIRTUAL_BITS. */
15210 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15212 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15213 unsigned char *pointer
;
15215 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15216 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15217 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15218 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15219 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15222 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
15224 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
15226 for (int index
= 0; index
< nfields
; ++index
)
15228 struct nextfield
&field
= fip
->fields
[index
];
15230 if (field
.variant
.is_discriminant
)
15231 di
->discriminant_index
= index
;
15232 else if (field
.variant
.default_branch
)
15233 di
->default_index
= index
;
15235 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
15239 /* Copy the saved-up fields into the field vector. */
15240 for (int i
= 0; i
< nfields
; ++i
)
15242 struct nextfield
&field
15243 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15244 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15246 TYPE_FIELD (type
, i
) = field
.field
;
15247 switch (field
.accessibility
)
15249 case DW_ACCESS_private
:
15250 if (cu
->language
!= language_ada
)
15251 SET_TYPE_FIELD_PRIVATE (type
, i
);
15254 case DW_ACCESS_protected
:
15255 if (cu
->language
!= language_ada
)
15256 SET_TYPE_FIELD_PROTECTED (type
, i
);
15259 case DW_ACCESS_public
:
15263 /* Unknown accessibility. Complain and treat it as public. */
15265 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
15266 field
.accessibility
);
15270 if (i
< fip
->baseclasses
.size ())
15272 switch (field
.virtuality
)
15274 case DW_VIRTUALITY_virtual
:
15275 case DW_VIRTUALITY_pure_virtual
:
15276 if (cu
->language
== language_ada
)
15277 error (_("unexpected virtuality in component of Ada type"));
15278 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15285 /* Return true if this member function is a constructor, false
15289 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15291 const char *fieldname
;
15292 const char *type_name
;
15295 if (die
->parent
== NULL
)
15298 if (die
->parent
->tag
!= DW_TAG_structure_type
15299 && die
->parent
->tag
!= DW_TAG_union_type
15300 && die
->parent
->tag
!= DW_TAG_class_type
)
15303 fieldname
= dwarf2_name (die
, cu
);
15304 type_name
= dwarf2_name (die
->parent
, cu
);
15305 if (fieldname
== NULL
|| type_name
== NULL
)
15308 len
= strlen (fieldname
);
15309 return (strncmp (fieldname
, type_name
, len
) == 0
15310 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15313 /* Add a member function to the proper fieldlist. */
15316 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15317 struct type
*type
, struct dwarf2_cu
*cu
)
15319 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15320 struct attribute
*attr
;
15322 struct fnfieldlist
*flp
= nullptr;
15323 struct fn_field
*fnp
;
15324 const char *fieldname
;
15325 struct type
*this_type
;
15326 enum dwarf_access_attribute accessibility
;
15328 if (cu
->language
== language_ada
)
15329 error (_("unexpected member function in Ada type"));
15331 /* Get name of member function. */
15332 fieldname
= dwarf2_name (die
, cu
);
15333 if (fieldname
== NULL
)
15336 /* Look up member function name in fieldlist. */
15337 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15339 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15341 flp
= &fip
->fnfieldlists
[i
];
15346 /* Create a new fnfieldlist if necessary. */
15347 if (flp
== nullptr)
15349 fip
->fnfieldlists
.emplace_back ();
15350 flp
= &fip
->fnfieldlists
.back ();
15351 flp
->name
= fieldname
;
15352 i
= fip
->fnfieldlists
.size () - 1;
15355 /* Create a new member function field and add it to the vector of
15357 flp
->fnfields
.emplace_back ();
15358 fnp
= &flp
->fnfields
.back ();
15360 /* Delay processing of the physname until later. */
15361 if (cu
->language
== language_cplus
)
15362 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15366 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15367 fnp
->physname
= physname
? physname
: "";
15370 fnp
->type
= alloc_type (objfile
);
15371 this_type
= read_type_die (die
, cu
);
15372 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
15374 int nparams
= TYPE_NFIELDS (this_type
);
15376 /* TYPE is the domain of this method, and THIS_TYPE is the type
15377 of the method itself (TYPE_CODE_METHOD). */
15378 smash_to_method_type (fnp
->type
, type
,
15379 TYPE_TARGET_TYPE (this_type
),
15380 TYPE_FIELDS (this_type
),
15381 TYPE_NFIELDS (this_type
),
15382 TYPE_VARARGS (this_type
));
15384 /* Handle static member functions.
15385 Dwarf2 has no clean way to discern C++ static and non-static
15386 member functions. G++ helps GDB by marking the first
15387 parameter for non-static member functions (which is the this
15388 pointer) as artificial. We obtain this information from
15389 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15390 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15391 fnp
->voffset
= VOFFSET_STATIC
;
15394 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
15395 dwarf2_full_name (fieldname
, die
, cu
));
15397 /* Get fcontext from DW_AT_containing_type if present. */
15398 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15399 fnp
->fcontext
= die_containing_type (die
, cu
);
15401 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15402 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15404 /* Get accessibility. */
15405 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15407 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15409 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15410 switch (accessibility
)
15412 case DW_ACCESS_private
:
15413 fnp
->is_private
= 1;
15415 case DW_ACCESS_protected
:
15416 fnp
->is_protected
= 1;
15420 /* Check for artificial methods. */
15421 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15422 if (attr
&& DW_UNSND (attr
) != 0)
15423 fnp
->is_artificial
= 1;
15425 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15427 /* Get index in virtual function table if it is a virtual member
15428 function. For older versions of GCC, this is an offset in the
15429 appropriate virtual table, as specified by DW_AT_containing_type.
15430 For everyone else, it is an expression to be evaluated relative
15431 to the object address. */
15433 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15436 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
15438 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15440 /* Old-style GCC. */
15441 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15443 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15444 || (DW_BLOCK (attr
)->size
> 1
15445 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15446 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15448 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15449 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15450 dwarf2_complex_location_expr_complaint ();
15452 fnp
->voffset
/= cu
->header
.addr_size
;
15456 dwarf2_complex_location_expr_complaint ();
15458 if (!fnp
->fcontext
)
15460 /* If there is no `this' field and no DW_AT_containing_type,
15461 we cannot actually find a base class context for the
15463 if (TYPE_NFIELDS (this_type
) == 0
15464 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15466 complaint (&symfile_complaints
,
15467 _("cannot determine context for virtual member "
15468 "function \"%s\" (offset %s)"),
15469 fieldname
, sect_offset_str (die
->sect_off
));
15474 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15478 else if (attr_form_is_section_offset (attr
))
15480 dwarf2_complex_location_expr_complaint ();
15484 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15490 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15491 if (attr
&& DW_UNSND (attr
))
15493 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15494 complaint (&symfile_complaints
,
15495 _("Member function \"%s\" (offset %s) is virtual "
15496 "but the vtable offset is not specified"),
15497 fieldname
, sect_offset_str (die
->sect_off
));
15498 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15499 TYPE_CPLUS_DYNAMIC (type
) = 1;
15504 /* Create the vector of member function fields, and attach it to the type. */
15507 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15508 struct dwarf2_cu
*cu
)
15510 if (cu
->language
== language_ada
)
15511 error (_("unexpected member functions in Ada type"));
15513 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15514 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15516 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15518 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15520 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15521 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15523 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15524 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15525 fn_flp
->fn_fields
= (struct fn_field
*)
15526 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15528 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15529 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15532 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15535 /* Returns non-zero if NAME is the name of a vtable member in CU's
15536 language, zero otherwise. */
15538 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15540 static const char vptr
[] = "_vptr";
15542 /* Look for the C++ form of the vtable. */
15543 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15549 /* GCC outputs unnamed structures that are really pointers to member
15550 functions, with the ABI-specified layout. If TYPE describes
15551 such a structure, smash it into a member function type.
15553 GCC shouldn't do this; it should just output pointer to member DIEs.
15554 This is GCC PR debug/28767. */
15557 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15559 struct type
*pfn_type
, *self_type
, *new_type
;
15561 /* Check for a structure with no name and two children. */
15562 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
15565 /* Check for __pfn and __delta members. */
15566 if (TYPE_FIELD_NAME (type
, 0) == NULL
15567 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15568 || TYPE_FIELD_NAME (type
, 1) == NULL
15569 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15572 /* Find the type of the method. */
15573 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15574 if (pfn_type
== NULL
15575 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
15576 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
15579 /* Look for the "this" argument. */
15580 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15581 if (TYPE_NFIELDS (pfn_type
) == 0
15582 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15583 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
15586 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15587 new_type
= alloc_type (objfile
);
15588 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15589 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
15590 TYPE_VARARGS (pfn_type
));
15591 smash_to_methodptr_type (type
, new_type
);
15594 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15595 appropriate error checking and issuing complaints if there is a
15599 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15601 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15603 if (attr
== nullptr)
15606 if (!attr_form_is_constant (attr
))
15608 complaint (&symfile_complaints
,
15609 _("DW_AT_alignment must have constant form"
15610 " - DIE at %s [in module %s]"),
15611 sect_offset_str (die
->sect_off
),
15612 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15617 if (attr
->form
== DW_FORM_sdata
)
15619 LONGEST val
= DW_SND (attr
);
15622 complaint (&symfile_complaints
,
15623 _("DW_AT_alignment value must not be negative"
15624 " - DIE at %s [in module %s]"),
15625 sect_offset_str (die
->sect_off
),
15626 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15632 align
= DW_UNSND (attr
);
15636 complaint (&symfile_complaints
,
15637 _("DW_AT_alignment value must not be zero"
15638 " - DIE at %s [in module %s]"),
15639 sect_offset_str (die
->sect_off
),
15640 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15643 if ((align
& (align
- 1)) != 0)
15645 complaint (&symfile_complaints
,
15646 _("DW_AT_alignment value must be a power of 2"
15647 " - DIE at %s [in module %s]"),
15648 sect_offset_str (die
->sect_off
),
15649 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15656 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15657 the alignment for TYPE. */
15660 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15663 if (!set_type_align (type
, get_alignment (cu
, die
)))
15664 complaint (&symfile_complaints
,
15665 _("DW_AT_alignment value too large"
15666 " - DIE at %s [in module %s]"),
15667 sect_offset_str (die
->sect_off
),
15668 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15671 /* Called when we find the DIE that starts a structure or union scope
15672 (definition) to create a type for the structure or union. Fill in
15673 the type's name and general properties; the members will not be
15674 processed until process_structure_scope. A symbol table entry for
15675 the type will also not be done until process_structure_scope (assuming
15676 the type has a name).
15678 NOTE: we need to call these functions regardless of whether or not the
15679 DIE has a DW_AT_name attribute, since it might be an anonymous
15680 structure or union. This gets the type entered into our set of
15681 user defined types. */
15683 static struct type
*
15684 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15686 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15688 struct attribute
*attr
;
15691 /* If the definition of this type lives in .debug_types, read that type.
15692 Don't follow DW_AT_specification though, that will take us back up
15693 the chain and we want to go down. */
15694 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15697 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15699 /* The type's CU may not be the same as CU.
15700 Ensure TYPE is recorded with CU in die_type_hash. */
15701 return set_die_type (die
, type
, cu
);
15704 type
= alloc_type (objfile
);
15705 INIT_CPLUS_SPECIFIC (type
);
15707 name
= dwarf2_name (die
, cu
);
15710 if (cu
->language
== language_cplus
15711 || cu
->language
== language_d
15712 || cu
->language
== language_rust
)
15714 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15716 /* dwarf2_full_name might have already finished building the DIE's
15717 type. If so, there is no need to continue. */
15718 if (get_die_type (die
, cu
) != NULL
)
15719 return get_die_type (die
, cu
);
15721 TYPE_TAG_NAME (type
) = full_name
;
15722 if (die
->tag
== DW_TAG_structure_type
15723 || die
->tag
== DW_TAG_class_type
)
15724 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
15728 /* The name is already allocated along with this objfile, so
15729 we don't need to duplicate it for the type. */
15730 TYPE_TAG_NAME (type
) = name
;
15731 if (die
->tag
== DW_TAG_class_type
)
15732 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
15736 if (die
->tag
== DW_TAG_structure_type
)
15738 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15740 else if (die
->tag
== DW_TAG_union_type
)
15742 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15744 else if (die
->tag
== DW_TAG_variant_part
)
15746 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15747 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15751 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15754 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15755 TYPE_DECLARED_CLASS (type
) = 1;
15757 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15760 if (attr_form_is_constant (attr
))
15761 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15764 /* For the moment, dynamic type sizes are not supported
15765 by GDB's struct type. The actual size is determined
15766 on-demand when resolving the type of a given object,
15767 so set the type's length to zero for now. Otherwise,
15768 we record an expression as the length, and that expression
15769 could lead to a very large value, which could eventually
15770 lead to us trying to allocate that much memory when creating
15771 a value of that type. */
15772 TYPE_LENGTH (type
) = 0;
15777 TYPE_LENGTH (type
) = 0;
15780 maybe_set_alignment (cu
, die
, type
);
15782 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15784 /* ICC<14 does not output the required DW_AT_declaration on
15785 incomplete types, but gives them a size of zero. */
15786 TYPE_STUB (type
) = 1;
15789 TYPE_STUB_SUPPORTED (type
) = 1;
15791 if (die_is_declaration (die
, cu
))
15792 TYPE_STUB (type
) = 1;
15793 else if (attr
== NULL
&& die
->child
== NULL
15794 && producer_is_realview (cu
->producer
))
15795 /* RealView does not output the required DW_AT_declaration
15796 on incomplete types. */
15797 TYPE_STUB (type
) = 1;
15799 /* We need to add the type field to the die immediately so we don't
15800 infinitely recurse when dealing with pointers to the structure
15801 type within the structure itself. */
15802 set_die_type (die
, type
, cu
);
15804 /* set_die_type should be already done. */
15805 set_descriptive_type (type
, die
, cu
);
15810 /* A helper for process_structure_scope that handles a single member
15814 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15815 struct field_info
*fi
,
15816 std::vector
<struct symbol
*> *template_args
,
15817 struct dwarf2_cu
*cu
)
15819 if (child_die
->tag
== DW_TAG_member
15820 || child_die
->tag
== DW_TAG_variable
15821 || child_die
->tag
== DW_TAG_variant_part
)
15823 /* NOTE: carlton/2002-11-05: A C++ static data member
15824 should be a DW_TAG_member that is a declaration, but
15825 all versions of G++ as of this writing (so through at
15826 least 3.2.1) incorrectly generate DW_TAG_variable
15827 tags for them instead. */
15828 dwarf2_add_field (fi
, child_die
, cu
);
15830 else if (child_die
->tag
== DW_TAG_subprogram
)
15832 /* Rust doesn't have member functions in the C++ sense.
15833 However, it does emit ordinary functions as children
15834 of a struct DIE. */
15835 if (cu
->language
== language_rust
)
15836 read_func_scope (child_die
, cu
);
15839 /* C++ member function. */
15840 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15843 else if (child_die
->tag
== DW_TAG_inheritance
)
15845 /* C++ base class field. */
15846 dwarf2_add_field (fi
, child_die
, cu
);
15848 else if (type_can_define_types (child_die
))
15849 dwarf2_add_type_defn (fi
, child_die
, cu
);
15850 else if (child_die
->tag
== DW_TAG_template_type_param
15851 || child_die
->tag
== DW_TAG_template_value_param
)
15853 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15856 template_args
->push_back (arg
);
15858 else if (child_die
->tag
== DW_TAG_variant
)
15860 /* In a variant we want to get the discriminant and also add a
15861 field for our sole member child. */
15862 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
15864 for (struct die_info
*variant_child
= child_die
->child
;
15865 variant_child
!= NULL
;
15866 variant_child
= sibling_die (variant_child
))
15868 if (variant_child
->tag
== DW_TAG_member
)
15870 handle_struct_member_die (variant_child
, type
, fi
,
15871 template_args
, cu
);
15872 /* Only handle the one. */
15877 /* We don't handle this but we might as well report it if we see
15879 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
15880 complaint (&symfile_complaints
,
15881 _("DW_AT_discr_list is not supported yet"
15882 " - DIE at %s [in module %s]"),
15883 sect_offset_str (child_die
->sect_off
),
15884 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15886 /* The first field was just added, so we can stash the
15887 discriminant there. */
15888 gdb_assert (!fi
->fields
.empty ());
15890 fi
->fields
.back ().variant
.default_branch
= true;
15892 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
15896 /* Finish creating a structure or union type, including filling in
15897 its members and creating a symbol for it. */
15900 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15902 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15903 struct die_info
*child_die
;
15906 type
= get_die_type (die
, cu
);
15908 type
= read_structure_type (die
, cu
);
15910 /* When reading a DW_TAG_variant_part, we need to notice when we
15911 read the discriminant member, so we can record it later in the
15912 discriminant_info. */
15913 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
15914 sect_offset discr_offset
;
15916 if (is_variant_part
)
15918 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15921 /* Maybe it's a univariant form, an extension we support.
15922 In this case arrange not to check the offset. */
15923 is_variant_part
= false;
15925 else if (attr_form_is_ref (discr
))
15927 struct dwarf2_cu
*target_cu
= cu
;
15928 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15930 discr_offset
= target_die
->sect_off
;
15934 complaint (&symfile_complaints
,
15935 _("DW_AT_discr does not have DIE reference form"
15936 " - DIE at %s [in module %s]"),
15937 sect_offset_str (die
->sect_off
),
15938 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15939 is_variant_part
= false;
15943 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15945 struct field_info fi
;
15946 std::vector
<struct symbol
*> template_args
;
15948 child_die
= die
->child
;
15950 while (child_die
&& child_die
->tag
)
15952 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15954 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
15955 fi
.fields
.back ().variant
.is_discriminant
= true;
15957 child_die
= sibling_die (child_die
);
15960 /* Attach template arguments to type. */
15961 if (!template_args
.empty ())
15963 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15964 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15965 TYPE_TEMPLATE_ARGUMENTS (type
)
15966 = XOBNEWVEC (&objfile
->objfile_obstack
,
15968 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15969 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15970 template_args
.data (),
15971 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15972 * sizeof (struct symbol
*)));
15975 /* Attach fields and member functions to the type. */
15977 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15978 if (!fi
.fnfieldlists
.empty ())
15980 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15982 /* Get the type which refers to the base class (possibly this
15983 class itself) which contains the vtable pointer for the current
15984 class from the DW_AT_containing_type attribute. This use of
15985 DW_AT_containing_type is a GNU extension. */
15987 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15989 struct type
*t
= die_containing_type (die
, cu
);
15991 set_type_vptr_basetype (type
, t
);
15996 /* Our own class provides vtbl ptr. */
15997 for (i
= TYPE_NFIELDS (t
) - 1;
15998 i
>= TYPE_N_BASECLASSES (t
);
16001 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
16003 if (is_vtable_name (fieldname
, cu
))
16005 set_type_vptr_fieldno (type
, i
);
16010 /* Complain if virtual function table field not found. */
16011 if (i
< TYPE_N_BASECLASSES (t
))
16012 complaint (&symfile_complaints
,
16013 _("virtual function table pointer "
16014 "not found when defining class '%s'"),
16015 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
16020 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16023 else if (cu
->producer
16024 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16026 /* The IBM XLC compiler does not provide direct indication
16027 of the containing type, but the vtable pointer is
16028 always named __vfp. */
16032 for (i
= TYPE_NFIELDS (type
) - 1;
16033 i
>= TYPE_N_BASECLASSES (type
);
16036 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
16038 set_type_vptr_fieldno (type
, i
);
16039 set_type_vptr_basetype (type
, type
);
16046 /* Copy fi.typedef_field_list linked list elements content into the
16047 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16048 if (!fi
.typedef_field_list
.empty ())
16050 int count
= fi
.typedef_field_list
.size ();
16052 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16053 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16054 = ((struct decl_field
*)
16056 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16057 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16059 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16060 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16063 /* Copy fi.nested_types_list linked list elements content into the
16064 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16065 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
16067 int count
= fi
.nested_types_list
.size ();
16069 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16070 TYPE_NESTED_TYPES_ARRAY (type
)
16071 = ((struct decl_field
*)
16072 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16073 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16075 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16076 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16080 quirk_gcc_member_function_pointer (type
, objfile
);
16081 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16082 cu
->rust_unions
.push_back (type
);
16084 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16085 snapshots) has been known to create a die giving a declaration
16086 for a class that has, as a child, a die giving a definition for a
16087 nested class. So we have to process our children even if the
16088 current die is a declaration. Normally, of course, a declaration
16089 won't have any children at all. */
16091 child_die
= die
->child
;
16093 while (child_die
!= NULL
&& child_die
->tag
)
16095 if (child_die
->tag
== DW_TAG_member
16096 || child_die
->tag
== DW_TAG_variable
16097 || child_die
->tag
== DW_TAG_inheritance
16098 || child_die
->tag
== DW_TAG_template_value_param
16099 || child_die
->tag
== DW_TAG_template_type_param
)
16104 process_die (child_die
, cu
);
16106 child_die
= sibling_die (child_die
);
16109 /* Do not consider external references. According to the DWARF standard,
16110 these DIEs are identified by the fact that they have no byte_size
16111 attribute, and a declaration attribute. */
16112 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16113 || !die_is_declaration (die
, cu
))
16114 new_symbol (die
, type
, cu
);
16117 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
16118 update TYPE using some information only available in DIE's children. */
16121 update_enumeration_type_from_children (struct die_info
*die
,
16123 struct dwarf2_cu
*cu
)
16125 struct die_info
*child_die
;
16126 int unsigned_enum
= 1;
16130 auto_obstack obstack
;
16132 for (child_die
= die
->child
;
16133 child_die
!= NULL
&& child_die
->tag
;
16134 child_die
= sibling_die (child_die
))
16136 struct attribute
*attr
;
16138 const gdb_byte
*bytes
;
16139 struct dwarf2_locexpr_baton
*baton
;
16142 if (child_die
->tag
!= DW_TAG_enumerator
)
16145 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16149 name
= dwarf2_name (child_die
, cu
);
16151 name
= "<anonymous enumerator>";
16153 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16154 &value
, &bytes
, &baton
);
16160 else if ((mask
& value
) != 0)
16165 /* If we already know that the enum type is neither unsigned, nor
16166 a flag type, no need to look at the rest of the enumerates. */
16167 if (!unsigned_enum
&& !flag_enum
)
16172 TYPE_UNSIGNED (type
) = 1;
16174 TYPE_FLAG_ENUM (type
) = 1;
16177 /* Given a DW_AT_enumeration_type die, set its type. We do not
16178 complete the type's fields yet, or create any symbols. */
16180 static struct type
*
16181 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16183 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16185 struct attribute
*attr
;
16188 /* If the definition of this type lives in .debug_types, read that type.
16189 Don't follow DW_AT_specification though, that will take us back up
16190 the chain and we want to go down. */
16191 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
16194 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16196 /* The type's CU may not be the same as CU.
16197 Ensure TYPE is recorded with CU in die_type_hash. */
16198 return set_die_type (die
, type
, cu
);
16201 type
= alloc_type (objfile
);
16203 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
16204 name
= dwarf2_full_name (NULL
, die
, cu
);
16206 TYPE_TAG_NAME (type
) = name
;
16208 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16211 struct type
*underlying_type
= die_type (die
, cu
);
16213 TYPE_TARGET_TYPE (type
) = underlying_type
;
16216 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16219 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16223 TYPE_LENGTH (type
) = 0;
16226 maybe_set_alignment (cu
, die
, type
);
16228 /* The enumeration DIE can be incomplete. In Ada, any type can be
16229 declared as private in the package spec, and then defined only
16230 inside the package body. Such types are known as Taft Amendment
16231 Types. When another package uses such a type, an incomplete DIE
16232 may be generated by the compiler. */
16233 if (die_is_declaration (die
, cu
))
16234 TYPE_STUB (type
) = 1;
16236 /* Finish the creation of this type by using the enum's children.
16237 We must call this even when the underlying type has been provided
16238 so that we can determine if we're looking at a "flag" enum. */
16239 update_enumeration_type_from_children (die
, type
, cu
);
16241 /* If this type has an underlying type that is not a stub, then we
16242 may use its attributes. We always use the "unsigned" attribute
16243 in this situation, because ordinarily we guess whether the type
16244 is unsigned -- but the guess can be wrong and the underlying type
16245 can tell us the reality. However, we defer to a local size
16246 attribute if one exists, because this lets the compiler override
16247 the underlying type if needed. */
16248 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16250 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
16251 if (TYPE_LENGTH (type
) == 0)
16252 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
16253 if (TYPE_RAW_ALIGN (type
) == 0
16254 && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)) != 0)
16255 set_type_align (type
, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)));
16258 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16260 return set_die_type (die
, type
, cu
);
16263 /* Given a pointer to a die which begins an enumeration, process all
16264 the dies that define the members of the enumeration, and create the
16265 symbol for the enumeration type.
16267 NOTE: We reverse the order of the element list. */
16270 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16272 struct type
*this_type
;
16274 this_type
= get_die_type (die
, cu
);
16275 if (this_type
== NULL
)
16276 this_type
= read_enumeration_type (die
, cu
);
16278 if (die
->child
!= NULL
)
16280 struct die_info
*child_die
;
16281 struct symbol
*sym
;
16282 struct field
*fields
= NULL
;
16283 int num_fields
= 0;
16286 child_die
= die
->child
;
16287 while (child_die
&& child_die
->tag
)
16289 if (child_die
->tag
!= DW_TAG_enumerator
)
16291 process_die (child_die
, cu
);
16295 name
= dwarf2_name (child_die
, cu
);
16298 sym
= new_symbol (child_die
, this_type
, cu
);
16300 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
16302 fields
= (struct field
*)
16304 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
16305 * sizeof (struct field
));
16308 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
16309 FIELD_TYPE (fields
[num_fields
]) = NULL
;
16310 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
16311 FIELD_BITSIZE (fields
[num_fields
]) = 0;
16317 child_die
= sibling_die (child_die
);
16322 TYPE_NFIELDS (this_type
) = num_fields
;
16323 TYPE_FIELDS (this_type
) = (struct field
*)
16324 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
16325 memcpy (TYPE_FIELDS (this_type
), fields
,
16326 sizeof (struct field
) * num_fields
);
16331 /* If we are reading an enum from a .debug_types unit, and the enum
16332 is a declaration, and the enum is not the signatured type in the
16333 unit, then we do not want to add a symbol for it. Adding a
16334 symbol would in some cases obscure the true definition of the
16335 enum, giving users an incomplete type when the definition is
16336 actually available. Note that we do not want to do this for all
16337 enums which are just declarations, because C++0x allows forward
16338 enum declarations. */
16339 if (cu
->per_cu
->is_debug_types
16340 && die_is_declaration (die
, cu
))
16342 struct signatured_type
*sig_type
;
16344 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16345 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16346 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16350 new_symbol (die
, this_type
, cu
);
16353 /* Extract all information from a DW_TAG_array_type DIE and put it in
16354 the DIE's type field. For now, this only handles one dimensional
16357 static struct type
*
16358 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16360 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16361 struct die_info
*child_die
;
16363 struct type
*element_type
, *range_type
, *index_type
;
16364 struct attribute
*attr
;
16366 struct dynamic_prop
*byte_stride_prop
= NULL
;
16367 unsigned int bit_stride
= 0;
16369 element_type
= die_type (die
, cu
);
16371 /* The die_type call above may have already set the type for this DIE. */
16372 type
= get_die_type (die
, cu
);
16376 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16382 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16383 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
);
16386 complaint (&symfile_complaints
,
16387 _("unable to read array DW_AT_byte_stride "
16388 " - DIE at %s [in module %s]"),
16389 sect_offset_str (die
->sect_off
),
16390 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16391 /* Ignore this attribute. We will likely not be able to print
16392 arrays of this type correctly, but there is little we can do
16393 to help if we cannot read the attribute's value. */
16394 byte_stride_prop
= NULL
;
16398 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16400 bit_stride
= DW_UNSND (attr
);
16402 /* Irix 6.2 native cc creates array types without children for
16403 arrays with unspecified length. */
16404 if (die
->child
== NULL
)
16406 index_type
= objfile_type (objfile
)->builtin_int
;
16407 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16408 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16409 byte_stride_prop
, bit_stride
);
16410 return set_die_type (die
, type
, cu
);
16413 std::vector
<struct type
*> range_types
;
16414 child_die
= die
->child
;
16415 while (child_die
&& child_die
->tag
)
16417 if (child_die
->tag
== DW_TAG_subrange_type
)
16419 struct type
*child_type
= read_type_die (child_die
, cu
);
16421 if (child_type
!= NULL
)
16423 /* The range type was succesfully read. Save it for the
16424 array type creation. */
16425 range_types
.push_back (child_type
);
16428 child_die
= sibling_die (child_die
);
16431 /* Dwarf2 dimensions are output from left to right, create the
16432 necessary array types in backwards order. */
16434 type
= element_type
;
16436 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16440 while (i
< range_types
.size ())
16441 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16442 byte_stride_prop
, bit_stride
);
16446 size_t ndim
= range_types
.size ();
16448 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16449 byte_stride_prop
, bit_stride
);
16452 /* Understand Dwarf2 support for vector types (like they occur on
16453 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16454 array type. This is not part of the Dwarf2/3 standard yet, but a
16455 custom vendor extension. The main difference between a regular
16456 array and the vector variant is that vectors are passed by value
16458 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16460 make_vector_type (type
);
16462 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16463 implementation may choose to implement triple vectors using this
16465 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16468 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16469 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16471 complaint (&symfile_complaints
,
16472 _("DW_AT_byte_size for array type smaller "
16473 "than the total size of elements"));
16476 name
= dwarf2_name (die
, cu
);
16478 TYPE_NAME (type
) = name
;
16480 maybe_set_alignment (cu
, die
, type
);
16482 /* Install the type in the die. */
16483 set_die_type (die
, type
, cu
);
16485 /* set_die_type should be already done. */
16486 set_descriptive_type (type
, die
, cu
);
16491 static enum dwarf_array_dim_ordering
16492 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16494 struct attribute
*attr
;
16496 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16499 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16501 /* GNU F77 is a special case, as at 08/2004 array type info is the
16502 opposite order to the dwarf2 specification, but data is still
16503 laid out as per normal fortran.
16505 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16506 version checking. */
16508 if (cu
->language
== language_fortran
16509 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16511 return DW_ORD_row_major
;
16514 switch (cu
->language_defn
->la_array_ordering
)
16516 case array_column_major
:
16517 return DW_ORD_col_major
;
16518 case array_row_major
:
16520 return DW_ORD_row_major
;
16524 /* Extract all information from a DW_TAG_set_type DIE and put it in
16525 the DIE's type field. */
16527 static struct type
*
16528 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16530 struct type
*domain_type
, *set_type
;
16531 struct attribute
*attr
;
16533 domain_type
= die_type (die
, cu
);
16535 /* The die_type call above may have already set the type for this DIE. */
16536 set_type
= get_die_type (die
, cu
);
16540 set_type
= create_set_type (NULL
, domain_type
);
16542 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16544 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16546 maybe_set_alignment (cu
, die
, set_type
);
16548 return set_die_type (die
, set_type
, cu
);
16551 /* A helper for read_common_block that creates a locexpr baton.
16552 SYM is the symbol which we are marking as computed.
16553 COMMON_DIE is the DIE for the common block.
16554 COMMON_LOC is the location expression attribute for the common
16556 MEMBER_LOC is the location expression attribute for the particular
16557 member of the common block that we are processing.
16558 CU is the CU from which the above come. */
16561 mark_common_block_symbol_computed (struct symbol
*sym
,
16562 struct die_info
*common_die
,
16563 struct attribute
*common_loc
,
16564 struct attribute
*member_loc
,
16565 struct dwarf2_cu
*cu
)
16567 struct dwarf2_per_objfile
*dwarf2_per_objfile
16568 = cu
->per_cu
->dwarf2_per_objfile
;
16569 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16570 struct dwarf2_locexpr_baton
*baton
;
16572 unsigned int cu_off
;
16573 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
16574 LONGEST offset
= 0;
16576 gdb_assert (common_loc
&& member_loc
);
16577 gdb_assert (attr_form_is_block (common_loc
));
16578 gdb_assert (attr_form_is_block (member_loc
)
16579 || attr_form_is_constant (member_loc
));
16581 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16582 baton
->per_cu
= cu
->per_cu
;
16583 gdb_assert (baton
->per_cu
);
16585 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16587 if (attr_form_is_constant (member_loc
))
16589 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
16590 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16593 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16595 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16598 *ptr
++ = DW_OP_call4
;
16599 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16600 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16603 if (attr_form_is_constant (member_loc
))
16605 *ptr
++ = DW_OP_addr
;
16606 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16607 ptr
+= cu
->header
.addr_size
;
16611 /* We have to copy the data here, because DW_OP_call4 will only
16612 use a DW_AT_location attribute. */
16613 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16614 ptr
+= DW_BLOCK (member_loc
)->size
;
16617 *ptr
++ = DW_OP_plus
;
16618 gdb_assert (ptr
- baton
->data
== baton
->size
);
16620 SYMBOL_LOCATION_BATON (sym
) = baton
;
16621 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16624 /* Create appropriate locally-scoped variables for all the
16625 DW_TAG_common_block entries. Also create a struct common_block
16626 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16627 is used to sepate the common blocks name namespace from regular
16631 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16633 struct attribute
*attr
;
16635 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16638 /* Support the .debug_loc offsets. */
16639 if (attr_form_is_block (attr
))
16643 else if (attr_form_is_section_offset (attr
))
16645 dwarf2_complex_location_expr_complaint ();
16650 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16651 "common block member");
16656 if (die
->child
!= NULL
)
16658 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16659 struct die_info
*child_die
;
16660 size_t n_entries
= 0, size
;
16661 struct common_block
*common_block
;
16662 struct symbol
*sym
;
16664 for (child_die
= die
->child
;
16665 child_die
&& child_die
->tag
;
16666 child_die
= sibling_die (child_die
))
16669 size
= (sizeof (struct common_block
)
16670 + (n_entries
- 1) * sizeof (struct symbol
*));
16672 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16674 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16675 common_block
->n_entries
= 0;
16677 for (child_die
= die
->child
;
16678 child_die
&& child_die
->tag
;
16679 child_die
= sibling_die (child_die
))
16681 /* Create the symbol in the DW_TAG_common_block block in the current
16683 sym
= new_symbol (child_die
, NULL
, cu
);
16686 struct attribute
*member_loc
;
16688 common_block
->contents
[common_block
->n_entries
++] = sym
;
16690 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16694 /* GDB has handled this for a long time, but it is
16695 not specified by DWARF. It seems to have been
16696 emitted by gfortran at least as recently as:
16697 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16698 complaint (&symfile_complaints
,
16699 _("Variable in common block has "
16700 "DW_AT_data_member_location "
16701 "- DIE at %s [in module %s]"),
16702 sect_offset_str (child_die
->sect_off
),
16703 objfile_name (objfile
));
16705 if (attr_form_is_section_offset (member_loc
))
16706 dwarf2_complex_location_expr_complaint ();
16707 else if (attr_form_is_constant (member_loc
)
16708 || attr_form_is_block (member_loc
))
16711 mark_common_block_symbol_computed (sym
, die
, attr
,
16715 dwarf2_complex_location_expr_complaint ();
16720 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16721 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16725 /* Create a type for a C++ namespace. */
16727 static struct type
*
16728 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16730 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16731 const char *previous_prefix
, *name
;
16735 /* For extensions, reuse the type of the original namespace. */
16736 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16738 struct die_info
*ext_die
;
16739 struct dwarf2_cu
*ext_cu
= cu
;
16741 ext_die
= dwarf2_extension (die
, &ext_cu
);
16742 type
= read_type_die (ext_die
, ext_cu
);
16744 /* EXT_CU may not be the same as CU.
16745 Ensure TYPE is recorded with CU in die_type_hash. */
16746 return set_die_type (die
, type
, cu
);
16749 name
= namespace_name (die
, &is_anonymous
, cu
);
16751 /* Now build the name of the current namespace. */
16753 previous_prefix
= determine_prefix (die
, cu
);
16754 if (previous_prefix
[0] != '\0')
16755 name
= typename_concat (&objfile
->objfile_obstack
,
16756 previous_prefix
, name
, 0, cu
);
16758 /* Create the type. */
16759 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16760 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
16762 return set_die_type (die
, type
, cu
);
16765 /* Read a namespace scope. */
16768 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16770 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16773 /* Add a symbol associated to this if we haven't seen the namespace
16774 before. Also, add a using directive if it's an anonymous
16777 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16781 type
= read_type_die (die
, cu
);
16782 new_symbol (die
, type
, cu
);
16784 namespace_name (die
, &is_anonymous
, cu
);
16787 const char *previous_prefix
= determine_prefix (die
, cu
);
16789 std::vector
<const char *> excludes
;
16790 add_using_directive (using_directives (cu
->language
),
16791 previous_prefix
, TYPE_NAME (type
), NULL
,
16792 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16796 if (die
->child
!= NULL
)
16798 struct die_info
*child_die
= die
->child
;
16800 while (child_die
&& child_die
->tag
)
16802 process_die (child_die
, cu
);
16803 child_die
= sibling_die (child_die
);
16808 /* Read a Fortran module as type. This DIE can be only a declaration used for
16809 imported module. Still we need that type as local Fortran "use ... only"
16810 declaration imports depend on the created type in determine_prefix. */
16812 static struct type
*
16813 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16815 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16816 const char *module_name
;
16819 module_name
= dwarf2_name (die
, cu
);
16821 complaint (&symfile_complaints
,
16822 _("DW_TAG_module has no name, offset %s"),
16823 sect_offset_str (die
->sect_off
));
16824 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16826 /* determine_prefix uses TYPE_TAG_NAME. */
16827 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
16829 return set_die_type (die
, type
, cu
);
16832 /* Read a Fortran module. */
16835 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16837 struct die_info
*child_die
= die
->child
;
16840 type
= read_type_die (die
, cu
);
16841 new_symbol (die
, type
, cu
);
16843 while (child_die
&& child_die
->tag
)
16845 process_die (child_die
, cu
);
16846 child_die
= sibling_die (child_die
);
16850 /* Return the name of the namespace represented by DIE. Set
16851 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16854 static const char *
16855 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16857 struct die_info
*current_die
;
16858 const char *name
= NULL
;
16860 /* Loop through the extensions until we find a name. */
16862 for (current_die
= die
;
16863 current_die
!= NULL
;
16864 current_die
= dwarf2_extension (die
, &cu
))
16866 /* We don't use dwarf2_name here so that we can detect the absence
16867 of a name -> anonymous namespace. */
16868 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16874 /* Is it an anonymous namespace? */
16876 *is_anonymous
= (name
== NULL
);
16878 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16883 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16884 the user defined type vector. */
16886 static struct type
*
16887 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16889 struct gdbarch
*gdbarch
16890 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16891 struct comp_unit_head
*cu_header
= &cu
->header
;
16893 struct attribute
*attr_byte_size
;
16894 struct attribute
*attr_address_class
;
16895 int byte_size
, addr_class
;
16896 struct type
*target_type
;
16898 target_type
= die_type (die
, cu
);
16900 /* The die_type call above may have already set the type for this DIE. */
16901 type
= get_die_type (die
, cu
);
16905 type
= lookup_pointer_type (target_type
);
16907 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16908 if (attr_byte_size
)
16909 byte_size
= DW_UNSND (attr_byte_size
);
16911 byte_size
= cu_header
->addr_size
;
16913 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16914 if (attr_address_class
)
16915 addr_class
= DW_UNSND (attr_address_class
);
16917 addr_class
= DW_ADDR_none
;
16919 ULONGEST alignment
= get_alignment (cu
, die
);
16921 /* If the pointer size, alignment, or address class is different
16922 than the default, create a type variant marked as such and set
16923 the length accordingly. */
16924 if (TYPE_LENGTH (type
) != byte_size
16925 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16926 && alignment
!= TYPE_RAW_ALIGN (type
))
16927 || addr_class
!= DW_ADDR_none
)
16929 if (gdbarch_address_class_type_flags_p (gdbarch
))
16933 type_flags
= gdbarch_address_class_type_flags
16934 (gdbarch
, byte_size
, addr_class
);
16935 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16937 type
= make_type_with_address_space (type
, type_flags
);
16939 else if (TYPE_LENGTH (type
) != byte_size
)
16941 complaint (&symfile_complaints
,
16942 _("invalid pointer size %d"), byte_size
);
16944 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16946 complaint (&symfile_complaints
,
16947 _("Invalid DW_AT_alignment"
16948 " - DIE at %s [in module %s]"),
16949 sect_offset_str (die
->sect_off
),
16950 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16954 /* Should we also complain about unhandled address classes? */
16958 TYPE_LENGTH (type
) = byte_size
;
16959 set_type_align (type
, alignment
);
16960 return set_die_type (die
, type
, cu
);
16963 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16964 the user defined type vector. */
16966 static struct type
*
16967 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16970 struct type
*to_type
;
16971 struct type
*domain
;
16973 to_type
= die_type (die
, cu
);
16974 domain
= die_containing_type (die
, cu
);
16976 /* The calls above may have already set the type for this DIE. */
16977 type
= get_die_type (die
, cu
);
16981 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
16982 type
= lookup_methodptr_type (to_type
);
16983 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
16985 struct type
*new_type
16986 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16988 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16989 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
16990 TYPE_VARARGS (to_type
));
16991 type
= lookup_methodptr_type (new_type
);
16994 type
= lookup_memberptr_type (to_type
, domain
);
16996 return set_die_type (die
, type
, cu
);
16999 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17000 the user defined type vector. */
17002 static struct type
*
17003 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17004 enum type_code refcode
)
17006 struct comp_unit_head
*cu_header
= &cu
->header
;
17007 struct type
*type
, *target_type
;
17008 struct attribute
*attr
;
17010 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17012 target_type
= die_type (die
, cu
);
17014 /* The die_type call above may have already set the type for this DIE. */
17015 type
= get_die_type (die
, cu
);
17019 type
= lookup_reference_type (target_type
, refcode
);
17020 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17023 TYPE_LENGTH (type
) = DW_UNSND (attr
);
17027 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17029 maybe_set_alignment (cu
, die
, type
);
17030 return set_die_type (die
, type
, cu
);
17033 /* Add the given cv-qualifiers to the element type of the array. GCC
17034 outputs DWARF type qualifiers that apply to an array, not the
17035 element type. But GDB relies on the array element type to carry
17036 the cv-qualifiers. This mimics section 6.7.3 of the C99
17039 static struct type
*
17040 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17041 struct type
*base_type
, int cnst
, int voltl
)
17043 struct type
*el_type
, *inner_array
;
17045 base_type
= copy_type (base_type
);
17046 inner_array
= base_type
;
17048 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
17050 TYPE_TARGET_TYPE (inner_array
) =
17051 copy_type (TYPE_TARGET_TYPE (inner_array
));
17052 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17055 el_type
= TYPE_TARGET_TYPE (inner_array
);
17056 cnst
|= TYPE_CONST (el_type
);
17057 voltl
|= TYPE_VOLATILE (el_type
);
17058 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17060 return set_die_type (die
, base_type
, cu
);
17063 static struct type
*
17064 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17066 struct type
*base_type
, *cv_type
;
17068 base_type
= die_type (die
, cu
);
17070 /* The die_type call above may have already set the type for this DIE. */
17071 cv_type
= get_die_type (die
, cu
);
17075 /* In case the const qualifier is applied to an array type, the element type
17076 is so qualified, not the array type (section 6.7.3 of C99). */
17077 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17078 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17080 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17081 return set_die_type (die
, cv_type
, cu
);
17084 static struct type
*
17085 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17087 struct type
*base_type
, *cv_type
;
17089 base_type
= die_type (die
, cu
);
17091 /* The die_type call above may have already set the type for this DIE. */
17092 cv_type
= get_die_type (die
, cu
);
17096 /* In case the volatile qualifier is applied to an array type, the
17097 element type is so qualified, not the array type (section 6.7.3
17099 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17100 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17102 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17103 return set_die_type (die
, cv_type
, cu
);
17106 /* Handle DW_TAG_restrict_type. */
17108 static struct type
*
17109 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17111 struct type
*base_type
, *cv_type
;
17113 base_type
= die_type (die
, cu
);
17115 /* The die_type call above may have already set the type for this DIE. */
17116 cv_type
= get_die_type (die
, cu
);
17120 cv_type
= make_restrict_type (base_type
);
17121 return set_die_type (die
, cv_type
, cu
);
17124 /* Handle DW_TAG_atomic_type. */
17126 static struct type
*
17127 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17129 struct type
*base_type
, *cv_type
;
17131 base_type
= die_type (die
, cu
);
17133 /* The die_type call above may have already set the type for this DIE. */
17134 cv_type
= get_die_type (die
, cu
);
17138 cv_type
= make_atomic_type (base_type
);
17139 return set_die_type (die
, cv_type
, cu
);
17142 /* Extract all information from a DW_TAG_string_type DIE and add to
17143 the user defined type vector. It isn't really a user defined type,
17144 but it behaves like one, with other DIE's using an AT_user_def_type
17145 attribute to reference it. */
17147 static struct type
*
17148 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17150 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17151 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17152 struct type
*type
, *range_type
, *index_type
, *char_type
;
17153 struct attribute
*attr
;
17154 unsigned int length
;
17156 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17159 length
= DW_UNSND (attr
);
17163 /* Check for the DW_AT_byte_size attribute. */
17164 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17167 length
= DW_UNSND (attr
);
17175 index_type
= objfile_type (objfile
)->builtin_int
;
17176 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17177 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17178 type
= create_string_type (NULL
, char_type
, range_type
);
17180 return set_die_type (die
, type
, cu
);
17183 /* Assuming that DIE corresponds to a function, returns nonzero
17184 if the function is prototyped. */
17187 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17189 struct attribute
*attr
;
17191 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17192 if (attr
&& (DW_UNSND (attr
) != 0))
17195 /* The DWARF standard implies that the DW_AT_prototyped attribute
17196 is only meaninful for C, but the concept also extends to other
17197 languages that allow unprototyped functions (Eg: Objective C).
17198 For all other languages, assume that functions are always
17200 if (cu
->language
!= language_c
17201 && cu
->language
!= language_objc
17202 && cu
->language
!= language_opencl
)
17205 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17206 prototyped and unprototyped functions; default to prototyped,
17207 since that is more common in modern code (and RealView warns
17208 about unprototyped functions). */
17209 if (producer_is_realview (cu
->producer
))
17215 /* Handle DIES due to C code like:
17219 int (*funcp)(int a, long l);
17223 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17225 static struct type
*
17226 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17228 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17229 struct type
*type
; /* Type that this function returns. */
17230 struct type
*ftype
; /* Function that returns above type. */
17231 struct attribute
*attr
;
17233 type
= die_type (die
, cu
);
17235 /* The die_type call above may have already set the type for this DIE. */
17236 ftype
= get_die_type (die
, cu
);
17240 ftype
= lookup_function_type (type
);
17242 if (prototyped_function_p (die
, cu
))
17243 TYPE_PROTOTYPED (ftype
) = 1;
17245 /* Store the calling convention in the type if it's available in
17246 the subroutine die. Otherwise set the calling convention to
17247 the default value DW_CC_normal. */
17248 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17250 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
17251 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17252 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17254 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17256 /* Record whether the function returns normally to its caller or not
17257 if the DWARF producer set that information. */
17258 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17259 if (attr
&& (DW_UNSND (attr
) != 0))
17260 TYPE_NO_RETURN (ftype
) = 1;
17262 /* We need to add the subroutine type to the die immediately so
17263 we don't infinitely recurse when dealing with parameters
17264 declared as the same subroutine type. */
17265 set_die_type (die
, ftype
, cu
);
17267 if (die
->child
!= NULL
)
17269 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17270 struct die_info
*child_die
;
17271 int nparams
, iparams
;
17273 /* Count the number of parameters.
17274 FIXME: GDB currently ignores vararg functions, but knows about
17275 vararg member functions. */
17277 child_die
= die
->child
;
17278 while (child_die
&& child_die
->tag
)
17280 if (child_die
->tag
== DW_TAG_formal_parameter
)
17282 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17283 TYPE_VARARGS (ftype
) = 1;
17284 child_die
= sibling_die (child_die
);
17287 /* Allocate storage for parameters and fill them in. */
17288 TYPE_NFIELDS (ftype
) = nparams
;
17289 TYPE_FIELDS (ftype
) = (struct field
*)
17290 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
17292 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17293 even if we error out during the parameters reading below. */
17294 for (iparams
= 0; iparams
< nparams
; iparams
++)
17295 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17298 child_die
= die
->child
;
17299 while (child_die
&& child_die
->tag
)
17301 if (child_die
->tag
== DW_TAG_formal_parameter
)
17303 struct type
*arg_type
;
17305 /* DWARF version 2 has no clean way to discern C++
17306 static and non-static member functions. G++ helps
17307 GDB by marking the first parameter for non-static
17308 member functions (which is the this pointer) as
17309 artificial. We pass this information to
17310 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17312 DWARF version 3 added DW_AT_object_pointer, which GCC
17313 4.5 does not yet generate. */
17314 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17316 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17318 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17319 arg_type
= die_type (child_die
, cu
);
17321 /* RealView does not mark THIS as const, which the testsuite
17322 expects. GCC marks THIS as const in method definitions,
17323 but not in the class specifications (GCC PR 43053). */
17324 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17325 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17328 struct dwarf2_cu
*arg_cu
= cu
;
17329 const char *name
= dwarf2_name (child_die
, cu
);
17331 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17334 /* If the compiler emits this, use it. */
17335 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17338 else if (name
&& strcmp (name
, "this") == 0)
17339 /* Function definitions will have the argument names. */
17341 else if (name
== NULL
&& iparams
== 0)
17342 /* Declarations may not have the names, so like
17343 elsewhere in GDB, assume an artificial first
17344 argument is "this". */
17348 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17352 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17355 child_die
= sibling_die (child_die
);
17362 static struct type
*
17363 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17365 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17366 const char *name
= NULL
;
17367 struct type
*this_type
, *target_type
;
17369 name
= dwarf2_full_name (NULL
, die
, cu
);
17370 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17371 TYPE_TARGET_STUB (this_type
) = 1;
17372 set_die_type (die
, this_type
, cu
);
17373 target_type
= die_type (die
, cu
);
17374 if (target_type
!= this_type
)
17375 TYPE_TARGET_TYPE (this_type
) = target_type
;
17378 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17379 spec and cause infinite loops in GDB. */
17380 complaint (&symfile_complaints
,
17381 _("Self-referential DW_TAG_typedef "
17382 "- DIE at %s [in module %s]"),
17383 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17384 TYPE_TARGET_TYPE (this_type
) = NULL
;
17389 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17390 (which may be different from NAME) to the architecture back-end to allow
17391 it to guess the correct format if necessary. */
17393 static struct type
*
17394 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17395 const char *name_hint
)
17397 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17398 const struct floatformat
**format
;
17401 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17403 type
= init_float_type (objfile
, bits
, name
, format
);
17405 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17410 /* Find a representation of a given base type and install
17411 it in the TYPE field of the die. */
17413 static struct type
*
17414 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17416 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17418 struct attribute
*attr
;
17419 int encoding
= 0, bits
= 0;
17422 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17425 encoding
= DW_UNSND (attr
);
17427 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17430 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17432 name
= dwarf2_name (die
, cu
);
17435 complaint (&symfile_complaints
,
17436 _("DW_AT_name missing from DW_TAG_base_type"));
17441 case DW_ATE_address
:
17442 /* Turn DW_ATE_address into a void * pointer. */
17443 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17444 type
= init_pointer_type (objfile
, bits
, name
, type
);
17446 case DW_ATE_boolean
:
17447 type
= init_boolean_type (objfile
, bits
, 1, name
);
17449 case DW_ATE_complex_float
:
17450 type
= dwarf2_init_float_type (objfile
, bits
/ 2, NULL
, name
);
17451 type
= init_complex_type (objfile
, name
, type
);
17453 case DW_ATE_decimal_float
:
17454 type
= init_decfloat_type (objfile
, bits
, name
);
17457 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
);
17459 case DW_ATE_signed
:
17460 type
= init_integer_type (objfile
, bits
, 0, name
);
17462 case DW_ATE_unsigned
:
17463 if (cu
->language
== language_fortran
17465 && startswith (name
, "character("))
17466 type
= init_character_type (objfile
, bits
, 1, name
);
17468 type
= init_integer_type (objfile
, bits
, 1, name
);
17470 case DW_ATE_signed_char
:
17471 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17472 || cu
->language
== language_pascal
17473 || cu
->language
== language_fortran
)
17474 type
= init_character_type (objfile
, bits
, 0, name
);
17476 type
= init_integer_type (objfile
, bits
, 0, name
);
17478 case DW_ATE_unsigned_char
:
17479 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17480 || cu
->language
== language_pascal
17481 || cu
->language
== language_fortran
17482 || cu
->language
== language_rust
)
17483 type
= init_character_type (objfile
, bits
, 1, name
);
17485 type
= init_integer_type (objfile
, bits
, 1, name
);
17489 gdbarch
*arch
= get_objfile_arch (objfile
);
17492 type
= builtin_type (arch
)->builtin_char16
;
17493 else if (bits
== 32)
17494 type
= builtin_type (arch
)->builtin_char32
;
17497 complaint (&symfile_complaints
,
17498 _("unsupported DW_ATE_UTF bit size: '%d'"),
17500 type
= init_integer_type (objfile
, bits
, 1, name
);
17502 return set_die_type (die
, type
, cu
);
17507 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
17508 dwarf_type_encoding_name (encoding
));
17509 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17513 if (name
&& strcmp (name
, "char") == 0)
17514 TYPE_NOSIGN (type
) = 1;
17516 maybe_set_alignment (cu
, die
, type
);
17518 return set_die_type (die
, type
, cu
);
17521 /* Parse dwarf attribute if it's a block, reference or constant and put the
17522 resulting value of the attribute into struct bound_prop.
17523 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17526 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17527 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
)
17529 struct dwarf2_property_baton
*baton
;
17530 struct obstack
*obstack
17531 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17533 if (attr
== NULL
|| prop
== NULL
)
17536 if (attr_form_is_block (attr
))
17538 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17539 baton
->referenced_type
= NULL
;
17540 baton
->locexpr
.per_cu
= cu
->per_cu
;
17541 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17542 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17543 prop
->data
.baton
= baton
;
17544 prop
->kind
= PROP_LOCEXPR
;
17545 gdb_assert (prop
->data
.baton
!= NULL
);
17547 else if (attr_form_is_ref (attr
))
17549 struct dwarf2_cu
*target_cu
= cu
;
17550 struct die_info
*target_die
;
17551 struct attribute
*target_attr
;
17553 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17554 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17555 if (target_attr
== NULL
)
17556 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17558 if (target_attr
== NULL
)
17561 switch (target_attr
->name
)
17563 case DW_AT_location
:
17564 if (attr_form_is_section_offset (target_attr
))
17566 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17567 baton
->referenced_type
= die_type (target_die
, target_cu
);
17568 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17569 prop
->data
.baton
= baton
;
17570 prop
->kind
= PROP_LOCLIST
;
17571 gdb_assert (prop
->data
.baton
!= NULL
);
17573 else if (attr_form_is_block (target_attr
))
17575 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17576 baton
->referenced_type
= die_type (target_die
, target_cu
);
17577 baton
->locexpr
.per_cu
= cu
->per_cu
;
17578 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17579 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17580 prop
->data
.baton
= baton
;
17581 prop
->kind
= PROP_LOCEXPR
;
17582 gdb_assert (prop
->data
.baton
!= NULL
);
17586 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17587 "dynamic property");
17591 case DW_AT_data_member_location
:
17595 if (!handle_data_member_location (target_die
, target_cu
,
17599 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17600 baton
->referenced_type
= read_type_die (target_die
->parent
,
17602 baton
->offset_info
.offset
= offset
;
17603 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17604 prop
->data
.baton
= baton
;
17605 prop
->kind
= PROP_ADDR_OFFSET
;
17610 else if (attr_form_is_constant (attr
))
17612 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
17613 prop
->kind
= PROP_CONST
;
17617 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17618 dwarf2_name (die
, cu
));
17625 /* Read the given DW_AT_subrange DIE. */
17627 static struct type
*
17628 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17630 struct type
*base_type
, *orig_base_type
;
17631 struct type
*range_type
;
17632 struct attribute
*attr
;
17633 struct dynamic_prop low
, high
;
17634 int low_default_is_valid
;
17635 int high_bound_is_count
= 0;
17637 LONGEST negative_mask
;
17639 orig_base_type
= die_type (die
, cu
);
17640 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17641 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17642 creating the range type, but we use the result of check_typedef
17643 when examining properties of the type. */
17644 base_type
= check_typedef (orig_base_type
);
17646 /* The die_type call above may have already set the type for this DIE. */
17647 range_type
= get_die_type (die
, cu
);
17651 low
.kind
= PROP_CONST
;
17652 high
.kind
= PROP_CONST
;
17653 high
.data
.const_val
= 0;
17655 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17656 omitting DW_AT_lower_bound. */
17657 switch (cu
->language
)
17660 case language_cplus
:
17661 low
.data
.const_val
= 0;
17662 low_default_is_valid
= 1;
17664 case language_fortran
:
17665 low
.data
.const_val
= 1;
17666 low_default_is_valid
= 1;
17669 case language_objc
:
17670 case language_rust
:
17671 low
.data
.const_val
= 0;
17672 low_default_is_valid
= (cu
->header
.version
>= 4);
17676 case language_pascal
:
17677 low
.data
.const_val
= 1;
17678 low_default_is_valid
= (cu
->header
.version
>= 4);
17681 low
.data
.const_val
= 0;
17682 low_default_is_valid
= 0;
17686 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17688 attr_to_dynamic_prop (attr
, die
, cu
, &low
);
17689 else if (!low_default_is_valid
)
17690 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
17691 "- DIE at %s [in module %s]"),
17692 sect_offset_str (die
->sect_off
),
17693 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17695 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17696 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
))
17698 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
17699 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
))
17701 /* If bounds are constant do the final calculation here. */
17702 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17703 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17705 high_bound_is_count
= 1;
17709 /* Dwarf-2 specifications explicitly allows to create subrange types
17710 without specifying a base type.
17711 In that case, the base type must be set to the type of
17712 the lower bound, upper bound or count, in that order, if any of these
17713 three attributes references an object that has a type.
17714 If no base type is found, the Dwarf-2 specifications say that
17715 a signed integer type of size equal to the size of an address should
17717 For the following C code: `extern char gdb_int [];'
17718 GCC produces an empty range DIE.
17719 FIXME: muller/2010-05-28: Possible references to object for low bound,
17720 high bound or count are not yet handled by this code. */
17721 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
17723 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17724 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17725 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
17726 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
17728 /* Test "int", "long int", and "long long int" objfile types,
17729 and select the first one having a size above or equal to the
17730 architecture address size. */
17731 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
17732 base_type
= int_type
;
17735 int_type
= objfile_type (objfile
)->builtin_long
;
17736 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
17737 base_type
= int_type
;
17740 int_type
= objfile_type (objfile
)->builtin_long_long
;
17741 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
17742 base_type
= int_type
;
17747 /* Normally, the DWARF producers are expected to use a signed
17748 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17749 But this is unfortunately not always the case, as witnessed
17750 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17751 is used instead. To work around that ambiguity, we treat
17752 the bounds as signed, and thus sign-extend their values, when
17753 the base type is signed. */
17755 -((LONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17756 if (low
.kind
== PROP_CONST
17757 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17758 low
.data
.const_val
|= negative_mask
;
17759 if (high
.kind
== PROP_CONST
17760 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17761 high
.data
.const_val
|= negative_mask
;
17763 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
);
17765 if (high_bound_is_count
)
17766 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17768 /* Ada expects an empty array on no boundary attributes. */
17769 if (attr
== NULL
&& cu
->language
!= language_ada
)
17770 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17772 name
= dwarf2_name (die
, cu
);
17774 TYPE_NAME (range_type
) = name
;
17776 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17778 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17780 maybe_set_alignment (cu
, die
, range_type
);
17782 set_die_type (die
, range_type
, cu
);
17784 /* set_die_type should be already done. */
17785 set_descriptive_type (range_type
, die
, cu
);
17790 static struct type
*
17791 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17795 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
17797 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
17799 /* In Ada, an unspecified type is typically used when the description
17800 of the type is defered to a different unit. When encountering
17801 such a type, we treat it as a stub, and try to resolve it later on,
17803 if (cu
->language
== language_ada
)
17804 TYPE_STUB (type
) = 1;
17806 return set_die_type (die
, type
, cu
);
17809 /* Read a single die and all its descendents. Set the die's sibling
17810 field to NULL; set other fields in the die correctly, and set all
17811 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17812 location of the info_ptr after reading all of those dies. PARENT
17813 is the parent of the die in question. */
17815 static struct die_info
*
17816 read_die_and_children (const struct die_reader_specs
*reader
,
17817 const gdb_byte
*info_ptr
,
17818 const gdb_byte
**new_info_ptr
,
17819 struct die_info
*parent
)
17821 struct die_info
*die
;
17822 const gdb_byte
*cur_ptr
;
17825 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
17828 *new_info_ptr
= cur_ptr
;
17831 store_in_ref_table (die
, reader
->cu
);
17834 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17838 *new_info_ptr
= cur_ptr
;
17841 die
->sibling
= NULL
;
17842 die
->parent
= parent
;
17846 /* Read a die, all of its descendents, and all of its siblings; set
17847 all of the fields of all of the dies correctly. Arguments are as
17848 in read_die_and_children. */
17850 static struct die_info
*
17851 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17852 const gdb_byte
*info_ptr
,
17853 const gdb_byte
**new_info_ptr
,
17854 struct die_info
*parent
)
17856 struct die_info
*first_die
, *last_sibling
;
17857 const gdb_byte
*cur_ptr
;
17859 cur_ptr
= info_ptr
;
17860 first_die
= last_sibling
= NULL
;
17864 struct die_info
*die
17865 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17869 *new_info_ptr
= cur_ptr
;
17876 last_sibling
->sibling
= die
;
17878 last_sibling
= die
;
17882 /* Read a die, all of its descendents, and all of its siblings; set
17883 all of the fields of all of the dies correctly. Arguments are as
17884 in read_die_and_children.
17885 This the main entry point for reading a DIE and all its children. */
17887 static struct die_info
*
17888 read_die_and_siblings (const struct die_reader_specs
*reader
,
17889 const gdb_byte
*info_ptr
,
17890 const gdb_byte
**new_info_ptr
,
17891 struct die_info
*parent
)
17893 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17894 new_info_ptr
, parent
);
17896 if (dwarf_die_debug
)
17898 fprintf_unfiltered (gdb_stdlog
,
17899 "Read die from %s@0x%x of %s:\n",
17900 get_section_name (reader
->die_section
),
17901 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17902 bfd_get_filename (reader
->abfd
));
17903 dump_die (die
, dwarf_die_debug
);
17909 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
17911 The caller is responsible for filling in the extra attributes
17912 and updating (*DIEP)->num_attrs.
17913 Set DIEP to point to a newly allocated die with its information,
17914 except for its child, sibling, and parent fields.
17915 Set HAS_CHILDREN to tell whether the die has children or not. */
17917 static const gdb_byte
*
17918 read_full_die_1 (const struct die_reader_specs
*reader
,
17919 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17920 int *has_children
, int num_extra_attrs
)
17922 unsigned int abbrev_number
, bytes_read
, i
;
17923 struct abbrev_info
*abbrev
;
17924 struct die_info
*die
;
17925 struct dwarf2_cu
*cu
= reader
->cu
;
17926 bfd
*abfd
= reader
->abfd
;
17928 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
17929 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17930 info_ptr
+= bytes_read
;
17931 if (!abbrev_number
)
17938 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
17940 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
17942 bfd_get_filename (abfd
));
17944 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
17945 die
->sect_off
= sect_off
;
17946 die
->tag
= abbrev
->tag
;
17947 die
->abbrev
= abbrev_number
;
17949 /* Make the result usable.
17950 The caller needs to update num_attrs after adding the extra
17952 die
->num_attrs
= abbrev
->num_attrs
;
17954 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
17955 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
17959 *has_children
= abbrev
->has_children
;
17963 /* Read a die and all its attributes.
17964 Set DIEP to point to a newly allocated die with its information,
17965 except for its child, sibling, and parent fields.
17966 Set HAS_CHILDREN to tell whether the die has children or not. */
17968 static const gdb_byte
*
17969 read_full_die (const struct die_reader_specs
*reader
,
17970 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17973 const gdb_byte
*result
;
17975 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
17977 if (dwarf_die_debug
)
17979 fprintf_unfiltered (gdb_stdlog
,
17980 "Read die from %s@0x%x of %s:\n",
17981 get_section_name (reader
->die_section
),
17982 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17983 bfd_get_filename (reader
->abfd
));
17984 dump_die (*diep
, dwarf_die_debug
);
17990 /* Abbreviation tables.
17992 In DWARF version 2, the description of the debugging information is
17993 stored in a separate .debug_abbrev section. Before we read any
17994 dies from a section we read in all abbreviations and install them
17995 in a hash table. */
17997 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
17999 struct abbrev_info
*
18000 abbrev_table::alloc_abbrev ()
18002 struct abbrev_info
*abbrev
;
18004 abbrev
= XOBNEW (&abbrev_obstack
, struct abbrev_info
);
18005 memset (abbrev
, 0, sizeof (struct abbrev_info
));
18010 /* Add an abbreviation to the table. */
18013 abbrev_table::add_abbrev (unsigned int abbrev_number
,
18014 struct abbrev_info
*abbrev
)
18016 unsigned int hash_number
;
18018 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18019 abbrev
->next
= m_abbrevs
[hash_number
];
18020 m_abbrevs
[hash_number
] = abbrev
;
18023 /* Look up an abbrev in the table.
18024 Returns NULL if the abbrev is not found. */
18026 struct abbrev_info
*
18027 abbrev_table::lookup_abbrev (unsigned int abbrev_number
)
18029 unsigned int hash_number
;
18030 struct abbrev_info
*abbrev
;
18032 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18033 abbrev
= m_abbrevs
[hash_number
];
18037 if (abbrev
->number
== abbrev_number
)
18039 abbrev
= abbrev
->next
;
18044 /* Read in an abbrev table. */
18046 static abbrev_table_up
18047 abbrev_table_read_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18048 struct dwarf2_section_info
*section
,
18049 sect_offset sect_off
)
18051 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18052 bfd
*abfd
= get_section_bfd_owner (section
);
18053 const gdb_byte
*abbrev_ptr
;
18054 struct abbrev_info
*cur_abbrev
;
18055 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
18056 unsigned int abbrev_form
;
18057 struct attr_abbrev
*cur_attrs
;
18058 unsigned int allocated_attrs
;
18060 abbrev_table_up
abbrev_table (new struct abbrev_table (sect_off
));
18062 dwarf2_read_section (objfile
, section
);
18063 abbrev_ptr
= section
->buffer
+ to_underlying (sect_off
);
18064 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18065 abbrev_ptr
+= bytes_read
;
18067 allocated_attrs
= ATTR_ALLOC_CHUNK
;
18068 cur_attrs
= XNEWVEC (struct attr_abbrev
, allocated_attrs
);
18070 /* Loop until we reach an abbrev number of 0. */
18071 while (abbrev_number
)
18073 cur_abbrev
= abbrev_table
->alloc_abbrev ();
18075 /* read in abbrev header */
18076 cur_abbrev
->number
= abbrev_number
;
18078 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18079 abbrev_ptr
+= bytes_read
;
18080 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
18083 /* now read in declarations */
18086 LONGEST implicit_const
;
18088 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18089 abbrev_ptr
+= bytes_read
;
18090 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18091 abbrev_ptr
+= bytes_read
;
18092 if (abbrev_form
== DW_FORM_implicit_const
)
18094 implicit_const
= read_signed_leb128 (abfd
, abbrev_ptr
,
18096 abbrev_ptr
+= bytes_read
;
18100 /* Initialize it due to a false compiler warning. */
18101 implicit_const
= -1;
18104 if (abbrev_name
== 0)
18107 if (cur_abbrev
->num_attrs
== allocated_attrs
)
18109 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
18111 = XRESIZEVEC (struct attr_abbrev
, cur_attrs
, allocated_attrs
);
18114 cur_attrs
[cur_abbrev
->num_attrs
].name
18115 = (enum dwarf_attribute
) abbrev_name
;
18116 cur_attrs
[cur_abbrev
->num_attrs
].form
18117 = (enum dwarf_form
) abbrev_form
;
18118 cur_attrs
[cur_abbrev
->num_attrs
].implicit_const
= implicit_const
;
18119 ++cur_abbrev
->num_attrs
;
18122 cur_abbrev
->attrs
=
18123 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
18124 cur_abbrev
->num_attrs
);
18125 memcpy (cur_abbrev
->attrs
, cur_attrs
,
18126 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
18128 abbrev_table
->add_abbrev (abbrev_number
, cur_abbrev
);
18130 /* Get next abbreviation.
18131 Under Irix6 the abbreviations for a compilation unit are not
18132 always properly terminated with an abbrev number of 0.
18133 Exit loop if we encounter an abbreviation which we have
18134 already read (which means we are about to read the abbreviations
18135 for the next compile unit) or if the end of the abbreviation
18136 table is reached. */
18137 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
18139 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18140 abbrev_ptr
+= bytes_read
;
18141 if (abbrev_table
->lookup_abbrev (abbrev_number
) != NULL
)
18146 return abbrev_table
;
18149 /* Returns nonzero if TAG represents a type that we might generate a partial
18153 is_type_tag_for_partial (int tag
)
18158 /* Some types that would be reasonable to generate partial symbols for,
18159 that we don't at present. */
18160 case DW_TAG_array_type
:
18161 case DW_TAG_file_type
:
18162 case DW_TAG_ptr_to_member_type
:
18163 case DW_TAG_set_type
:
18164 case DW_TAG_string_type
:
18165 case DW_TAG_subroutine_type
:
18167 case DW_TAG_base_type
:
18168 case DW_TAG_class_type
:
18169 case DW_TAG_interface_type
:
18170 case DW_TAG_enumeration_type
:
18171 case DW_TAG_structure_type
:
18172 case DW_TAG_subrange_type
:
18173 case DW_TAG_typedef
:
18174 case DW_TAG_union_type
:
18181 /* Load all DIEs that are interesting for partial symbols into memory. */
18183 static struct partial_die_info
*
18184 load_partial_dies (const struct die_reader_specs
*reader
,
18185 const gdb_byte
*info_ptr
, int building_psymtab
)
18187 struct dwarf2_cu
*cu
= reader
->cu
;
18188 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18189 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18190 unsigned int bytes_read
;
18191 unsigned int load_all
= 0;
18192 int nesting_level
= 1;
18197 gdb_assert (cu
->per_cu
!= NULL
);
18198 if (cu
->per_cu
->load_all_dies
)
18202 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18206 &cu
->comp_unit_obstack
,
18207 hashtab_obstack_allocate
,
18208 dummy_obstack_deallocate
);
18212 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18214 /* A NULL abbrev means the end of a series of children. */
18215 if (abbrev
== NULL
)
18217 if (--nesting_level
== 0)
18220 info_ptr
+= bytes_read
;
18221 last_die
= parent_die
;
18222 parent_die
= parent_die
->die_parent
;
18226 /* Check for template arguments. We never save these; if
18227 they're seen, we just mark the parent, and go on our way. */
18228 if (parent_die
!= NULL
18229 && cu
->language
== language_cplus
18230 && (abbrev
->tag
== DW_TAG_template_type_param
18231 || abbrev
->tag
== DW_TAG_template_value_param
))
18233 parent_die
->has_template_arguments
= 1;
18237 /* We don't need a partial DIE for the template argument. */
18238 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18243 /* We only recurse into c++ subprograms looking for template arguments.
18244 Skip their other children. */
18246 && cu
->language
== language_cplus
18247 && parent_die
!= NULL
18248 && parent_die
->tag
== DW_TAG_subprogram
)
18250 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18254 /* Check whether this DIE is interesting enough to save. Normally
18255 we would not be interested in members here, but there may be
18256 later variables referencing them via DW_AT_specification (for
18257 static members). */
18259 && !is_type_tag_for_partial (abbrev
->tag
)
18260 && abbrev
->tag
!= DW_TAG_constant
18261 && abbrev
->tag
!= DW_TAG_enumerator
18262 && abbrev
->tag
!= DW_TAG_subprogram
18263 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18264 && abbrev
->tag
!= DW_TAG_lexical_block
18265 && abbrev
->tag
!= DW_TAG_variable
18266 && abbrev
->tag
!= DW_TAG_namespace
18267 && abbrev
->tag
!= DW_TAG_module
18268 && abbrev
->tag
!= DW_TAG_member
18269 && abbrev
->tag
!= DW_TAG_imported_unit
18270 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18272 /* Otherwise we skip to the next sibling, if any. */
18273 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18277 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18280 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18282 /* This two-pass algorithm for processing partial symbols has a
18283 high cost in cache pressure. Thus, handle some simple cases
18284 here which cover the majority of C partial symbols. DIEs
18285 which neither have specification tags in them, nor could have
18286 specification tags elsewhere pointing at them, can simply be
18287 processed and discarded.
18289 This segment is also optional; scan_partial_symbols and
18290 add_partial_symbol will handle these DIEs if we chain
18291 them in normally. When compilers which do not emit large
18292 quantities of duplicate debug information are more common,
18293 this code can probably be removed. */
18295 /* Any complete simple types at the top level (pretty much all
18296 of them, for a language without namespaces), can be processed
18298 if (parent_die
== NULL
18299 && pdi
.has_specification
== 0
18300 && pdi
.is_declaration
== 0
18301 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18302 || pdi
.tag
== DW_TAG_base_type
18303 || pdi
.tag
== DW_TAG_subrange_type
))
18305 if (building_psymtab
&& pdi
.name
!= NULL
)
18306 add_psymbol_to_list (pdi
.name
, strlen (pdi
.name
), 0,
18307 VAR_DOMAIN
, LOC_TYPEDEF
,
18308 &objfile
->static_psymbols
,
18309 0, cu
->language
, objfile
);
18310 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18314 /* The exception for DW_TAG_typedef with has_children above is
18315 a workaround of GCC PR debug/47510. In the case of this complaint
18316 type_name_no_tag_or_error will error on such types later.
18318 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18319 it could not find the child DIEs referenced later, this is checked
18320 above. In correct DWARF DW_TAG_typedef should have no children. */
18322 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18323 complaint (&symfile_complaints
,
18324 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18325 "- DIE at %s [in module %s]"),
18326 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18328 /* If we're at the second level, and we're an enumerator, and
18329 our parent has no specification (meaning possibly lives in a
18330 namespace elsewhere), then we can add the partial symbol now
18331 instead of queueing it. */
18332 if (pdi
.tag
== DW_TAG_enumerator
18333 && parent_die
!= NULL
18334 && parent_die
->die_parent
== NULL
18335 && parent_die
->tag
== DW_TAG_enumeration_type
18336 && parent_die
->has_specification
== 0)
18338 if (pdi
.name
== NULL
)
18339 complaint (&symfile_complaints
,
18340 _("malformed enumerator DIE ignored"));
18341 else if (building_psymtab
)
18342 add_psymbol_to_list (pdi
.name
, strlen (pdi
.name
), 0,
18343 VAR_DOMAIN
, LOC_CONST
,
18344 cu
->language
== language_cplus
18345 ? &objfile
->global_psymbols
18346 : &objfile
->static_psymbols
,
18347 0, cu
->language
, objfile
);
18349 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18353 struct partial_die_info
*part_die
18354 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18356 /* We'll save this DIE so link it in. */
18357 part_die
->die_parent
= parent_die
;
18358 part_die
->die_sibling
= NULL
;
18359 part_die
->die_child
= NULL
;
18361 if (last_die
&& last_die
== parent_die
)
18362 last_die
->die_child
= part_die
;
18364 last_die
->die_sibling
= part_die
;
18366 last_die
= part_die
;
18368 if (first_die
== NULL
)
18369 first_die
= part_die
;
18371 /* Maybe add the DIE to the hash table. Not all DIEs that we
18372 find interesting need to be in the hash table, because we
18373 also have the parent/sibling/child chains; only those that we
18374 might refer to by offset later during partial symbol reading.
18376 For now this means things that might have be the target of a
18377 DW_AT_specification, DW_AT_abstract_origin, or
18378 DW_AT_extension. DW_AT_extension will refer only to
18379 namespaces; DW_AT_abstract_origin refers to functions (and
18380 many things under the function DIE, but we do not recurse
18381 into function DIEs during partial symbol reading) and
18382 possibly variables as well; DW_AT_specification refers to
18383 declarations. Declarations ought to have the DW_AT_declaration
18384 flag. It happens that GCC forgets to put it in sometimes, but
18385 only for functions, not for types.
18387 Adding more things than necessary to the hash table is harmless
18388 except for the performance cost. Adding too few will result in
18389 wasted time in find_partial_die, when we reread the compilation
18390 unit with load_all_dies set. */
18393 || abbrev
->tag
== DW_TAG_constant
18394 || abbrev
->tag
== DW_TAG_subprogram
18395 || abbrev
->tag
== DW_TAG_variable
18396 || abbrev
->tag
== DW_TAG_namespace
18397 || part_die
->is_declaration
)
18401 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18402 to_underlying (part_die
->sect_off
),
18407 /* For some DIEs we want to follow their children (if any). For C
18408 we have no reason to follow the children of structures; for other
18409 languages we have to, so that we can get at method physnames
18410 to infer fully qualified class names, for DW_AT_specification,
18411 and for C++ template arguments. For C++, we also look one level
18412 inside functions to find template arguments (if the name of the
18413 function does not already contain the template arguments).
18415 For Ada, we need to scan the children of subprograms and lexical
18416 blocks as well because Ada allows the definition of nested
18417 entities that could be interesting for the debugger, such as
18418 nested subprograms for instance. */
18419 if (last_die
->has_children
18421 || last_die
->tag
== DW_TAG_namespace
18422 || last_die
->tag
== DW_TAG_module
18423 || last_die
->tag
== DW_TAG_enumeration_type
18424 || (cu
->language
== language_cplus
18425 && last_die
->tag
== DW_TAG_subprogram
18426 && (last_die
->name
== NULL
18427 || strchr (last_die
->name
, '<') == NULL
))
18428 || (cu
->language
!= language_c
18429 && (last_die
->tag
== DW_TAG_class_type
18430 || last_die
->tag
== DW_TAG_interface_type
18431 || last_die
->tag
== DW_TAG_structure_type
18432 || last_die
->tag
== DW_TAG_union_type
))
18433 || (cu
->language
== language_ada
18434 && (last_die
->tag
== DW_TAG_subprogram
18435 || last_die
->tag
== DW_TAG_lexical_block
))))
18438 parent_die
= last_die
;
18442 /* Otherwise we skip to the next sibling, if any. */
18443 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18445 /* Back to the top, do it again. */
18449 partial_die_info::partial_die_info (sect_offset sect_off_
,
18450 struct abbrev_info
*abbrev
)
18451 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18455 /* Read a minimal amount of information into the minimal die structure.
18456 INFO_PTR should point just after the initial uleb128 of a DIE. */
18459 partial_die_info::read (const struct die_reader_specs
*reader
,
18460 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18462 struct dwarf2_cu
*cu
= reader
->cu
;
18463 struct dwarf2_per_objfile
*dwarf2_per_objfile
18464 = cu
->per_cu
->dwarf2_per_objfile
;
18466 int has_low_pc_attr
= 0;
18467 int has_high_pc_attr
= 0;
18468 int high_pc_relative
= 0;
18470 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18472 struct attribute attr
;
18474 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
18476 /* Store the data if it is of an attribute we want to keep in a
18477 partial symbol table. */
18483 case DW_TAG_compile_unit
:
18484 case DW_TAG_partial_unit
:
18485 case DW_TAG_type_unit
:
18486 /* Compilation units have a DW_AT_name that is a filename, not
18487 a source language identifier. */
18488 case DW_TAG_enumeration_type
:
18489 case DW_TAG_enumerator
:
18490 /* These tags always have simple identifiers already; no need
18491 to canonicalize them. */
18492 name
= DW_STRING (&attr
);
18496 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18499 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
18500 &objfile
->per_bfd
->storage_obstack
);
18505 case DW_AT_linkage_name
:
18506 case DW_AT_MIPS_linkage_name
:
18507 /* Note that both forms of linkage name might appear. We
18508 assume they will be the same, and we only store the last
18510 if (cu
->language
== language_ada
)
18511 name
= DW_STRING (&attr
);
18512 linkage_name
= DW_STRING (&attr
);
18515 has_low_pc_attr
= 1;
18516 lowpc
= attr_value_as_address (&attr
);
18518 case DW_AT_high_pc
:
18519 has_high_pc_attr
= 1;
18520 highpc
= attr_value_as_address (&attr
);
18521 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
18522 high_pc_relative
= 1;
18524 case DW_AT_location
:
18525 /* Support the .debug_loc offsets. */
18526 if (attr_form_is_block (&attr
))
18528 d
.locdesc
= DW_BLOCK (&attr
);
18530 else if (attr_form_is_section_offset (&attr
))
18532 dwarf2_complex_location_expr_complaint ();
18536 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18537 "partial symbol information");
18540 case DW_AT_external
:
18541 is_external
= DW_UNSND (&attr
);
18543 case DW_AT_declaration
:
18544 is_declaration
= DW_UNSND (&attr
);
18549 case DW_AT_abstract_origin
:
18550 case DW_AT_specification
:
18551 case DW_AT_extension
:
18552 has_specification
= 1;
18553 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
18554 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18555 || cu
->per_cu
->is_dwz
);
18557 case DW_AT_sibling
:
18558 /* Ignore absolute siblings, they might point outside of
18559 the current compile unit. */
18560 if (attr
.form
== DW_FORM_ref_addr
)
18561 complaint (&symfile_complaints
,
18562 _("ignoring absolute DW_AT_sibling"));
18565 const gdb_byte
*buffer
= reader
->buffer
;
18566 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
18567 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18569 if (sibling_ptr
< info_ptr
)
18570 complaint (&symfile_complaints
,
18571 _("DW_AT_sibling points backwards"));
18572 else if (sibling_ptr
> reader
->buffer_end
)
18573 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
18575 sibling
= sibling_ptr
;
18578 case DW_AT_byte_size
:
18581 case DW_AT_const_value
:
18582 has_const_value
= 1;
18584 case DW_AT_calling_convention
:
18585 /* DWARF doesn't provide a way to identify a program's source-level
18586 entry point. DW_AT_calling_convention attributes are only meant
18587 to describe functions' calling conventions.
18589 However, because it's a necessary piece of information in
18590 Fortran, and before DWARF 4 DW_CC_program was the only
18591 piece of debugging information whose definition refers to
18592 a 'main program' at all, several compilers marked Fortran
18593 main programs with DW_CC_program --- even when those
18594 functions use the standard calling conventions.
18596 Although DWARF now specifies a way to provide this
18597 information, we support this practice for backward
18599 if (DW_UNSND (&attr
) == DW_CC_program
18600 && cu
->language
== language_fortran
)
18601 main_subprogram
= 1;
18604 if (DW_UNSND (&attr
) == DW_INL_inlined
18605 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18606 may_be_inlined
= 1;
18610 if (tag
== DW_TAG_imported_unit
)
18612 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
18613 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18614 || cu
->per_cu
->is_dwz
);
18618 case DW_AT_main_subprogram
:
18619 main_subprogram
= DW_UNSND (&attr
);
18627 if (high_pc_relative
)
18630 if (has_low_pc_attr
&& has_high_pc_attr
)
18632 /* When using the GNU linker, .gnu.linkonce. sections are used to
18633 eliminate duplicate copies of functions and vtables and such.
18634 The linker will arbitrarily choose one and discard the others.
18635 The AT_*_pc values for such functions refer to local labels in
18636 these sections. If the section from that file was discarded, the
18637 labels are not in the output, so the relocs get a value of 0.
18638 If this is a discarded function, mark the pc bounds as invalid,
18639 so that GDB will ignore it. */
18640 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18642 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18643 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18645 complaint (&symfile_complaints
,
18646 _("DW_AT_low_pc %s is zero "
18647 "for DIE at %s [in module %s]"),
18648 paddress (gdbarch
, lowpc
),
18649 sect_offset_str (sect_off
),
18650 objfile_name (objfile
));
18652 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18653 else if (lowpc
>= highpc
)
18655 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18656 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18658 complaint (&symfile_complaints
,
18659 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18660 "for DIE at %s [in module %s]"),
18661 paddress (gdbarch
, lowpc
),
18662 paddress (gdbarch
, highpc
),
18663 sect_offset_str (sect_off
),
18664 objfile_name (objfile
));
18673 /* Find a cached partial DIE at OFFSET in CU. */
18675 struct partial_die_info
*
18676 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18678 struct partial_die_info
*lookup_die
= NULL
;
18679 struct partial_die_info
part_die (sect_off
);
18681 lookup_die
= ((struct partial_die_info
*)
18682 htab_find_with_hash (partial_dies
, &part_die
,
18683 to_underlying (sect_off
)));
18688 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18689 except in the case of .debug_types DIEs which do not reference
18690 outside their CU (they do however referencing other types via
18691 DW_FORM_ref_sig8). */
18693 static struct partial_die_info
*
18694 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18696 struct dwarf2_per_objfile
*dwarf2_per_objfile
18697 = cu
->per_cu
->dwarf2_per_objfile
;
18698 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18699 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18700 struct partial_die_info
*pd
= NULL
;
18702 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18703 && offset_in_cu_p (&cu
->header
, sect_off
))
18705 pd
= cu
->find_partial_die (sect_off
);
18708 /* We missed recording what we needed.
18709 Load all dies and try again. */
18710 per_cu
= cu
->per_cu
;
18714 /* TUs don't reference other CUs/TUs (except via type signatures). */
18715 if (cu
->per_cu
->is_debug_types
)
18717 error (_("Dwarf Error: Type Unit at offset %s contains"
18718 " external reference to offset %s [in module %s].\n"),
18719 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18720 bfd_get_filename (objfile
->obfd
));
18722 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18723 dwarf2_per_objfile
);
18725 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18726 load_partial_comp_unit (per_cu
);
18728 per_cu
->cu
->last_used
= 0;
18729 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18732 /* If we didn't find it, and not all dies have been loaded,
18733 load them all and try again. */
18735 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18737 per_cu
->load_all_dies
= 1;
18739 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18740 THIS_CU->cu may already be in use. So we can't just free it and
18741 replace its DIEs with the ones we read in. Instead, we leave those
18742 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18743 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18745 load_partial_comp_unit (per_cu
);
18747 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18751 internal_error (__FILE__
, __LINE__
,
18752 _("could not find partial DIE %s "
18753 "in cache [from module %s]\n"),
18754 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18758 /* See if we can figure out if the class lives in a namespace. We do
18759 this by looking for a member function; its demangled name will
18760 contain namespace info, if there is any. */
18763 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18764 struct dwarf2_cu
*cu
)
18766 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18767 what template types look like, because the demangler
18768 frequently doesn't give the same name as the debug info. We
18769 could fix this by only using the demangled name to get the
18770 prefix (but see comment in read_structure_type). */
18772 struct partial_die_info
*real_pdi
;
18773 struct partial_die_info
*child_pdi
;
18775 /* If this DIE (this DIE's specification, if any) has a parent, then
18776 we should not do this. We'll prepend the parent's fully qualified
18777 name when we create the partial symbol. */
18779 real_pdi
= struct_pdi
;
18780 while (real_pdi
->has_specification
)
18781 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
18782 real_pdi
->spec_is_dwz
, cu
);
18784 if (real_pdi
->die_parent
!= NULL
)
18787 for (child_pdi
= struct_pdi
->die_child
;
18789 child_pdi
= child_pdi
->die_sibling
)
18791 if (child_pdi
->tag
== DW_TAG_subprogram
18792 && child_pdi
->linkage_name
!= NULL
)
18794 char *actual_class_name
18795 = language_class_name_from_physname (cu
->language_defn
,
18796 child_pdi
->linkage_name
);
18797 if (actual_class_name
!= NULL
)
18799 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18802 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
18804 strlen (actual_class_name
)));
18805 xfree (actual_class_name
);
18813 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18815 /* Once we've fixed up a die, there's no point in doing so again.
18816 This also avoids a memory leak if we were to call
18817 guess_partial_die_structure_name multiple times. */
18821 /* If we found a reference attribute and the DIE has no name, try
18822 to find a name in the referred to DIE. */
18824 if (name
== NULL
&& has_specification
)
18826 struct partial_die_info
*spec_die
;
18828 spec_die
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18830 spec_die
->fixup (cu
);
18832 if (spec_die
->name
)
18834 name
= spec_die
->name
;
18836 /* Copy DW_AT_external attribute if it is set. */
18837 if (spec_die
->is_external
)
18838 is_external
= spec_die
->is_external
;
18842 /* Set default names for some unnamed DIEs. */
18844 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18845 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18847 /* If there is no parent die to provide a namespace, and there are
18848 children, see if we can determine the namespace from their linkage
18850 if (cu
->language
== language_cplus
18851 && !VEC_empty (dwarf2_section_info_def
,
18852 cu
->per_cu
->dwarf2_per_objfile
->types
)
18853 && die_parent
== NULL
18855 && (tag
== DW_TAG_class_type
18856 || tag
== DW_TAG_structure_type
18857 || tag
== DW_TAG_union_type
))
18858 guess_partial_die_structure_name (this, cu
);
18860 /* GCC might emit a nameless struct or union that has a linkage
18861 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18863 && (tag
== DW_TAG_class_type
18864 || tag
== DW_TAG_interface_type
18865 || tag
== DW_TAG_structure_type
18866 || tag
== DW_TAG_union_type
)
18867 && linkage_name
!= NULL
)
18871 demangled
= gdb_demangle (linkage_name
, DMGL_TYPES
);
18876 /* Strip any leading namespaces/classes, keep only the base name.
18877 DW_AT_name for named DIEs does not contain the prefixes. */
18878 base
= strrchr (demangled
, ':');
18879 if (base
&& base
> demangled
&& base
[-1] == ':')
18884 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18887 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
18888 base
, strlen (base
)));
18896 /* Read an attribute value described by an attribute form. */
18898 static const gdb_byte
*
18899 read_attribute_value (const struct die_reader_specs
*reader
,
18900 struct attribute
*attr
, unsigned form
,
18901 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
18903 struct dwarf2_cu
*cu
= reader
->cu
;
18904 struct dwarf2_per_objfile
*dwarf2_per_objfile
18905 = cu
->per_cu
->dwarf2_per_objfile
;
18906 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18907 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18908 bfd
*abfd
= reader
->abfd
;
18909 struct comp_unit_head
*cu_header
= &cu
->header
;
18910 unsigned int bytes_read
;
18911 struct dwarf_block
*blk
;
18913 attr
->form
= (enum dwarf_form
) form
;
18916 case DW_FORM_ref_addr
:
18917 if (cu
->header
.version
== 2)
18918 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
18920 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
18921 &cu
->header
, &bytes_read
);
18922 info_ptr
+= bytes_read
;
18924 case DW_FORM_GNU_ref_alt
:
18925 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
18926 info_ptr
+= bytes_read
;
18929 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
18930 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
18931 info_ptr
+= bytes_read
;
18933 case DW_FORM_block2
:
18934 blk
= dwarf_alloc_block (cu
);
18935 blk
->size
= read_2_bytes (abfd
, info_ptr
);
18937 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18938 info_ptr
+= blk
->size
;
18939 DW_BLOCK (attr
) = blk
;
18941 case DW_FORM_block4
:
18942 blk
= dwarf_alloc_block (cu
);
18943 blk
->size
= read_4_bytes (abfd
, info_ptr
);
18945 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18946 info_ptr
+= blk
->size
;
18947 DW_BLOCK (attr
) = blk
;
18949 case DW_FORM_data2
:
18950 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
18953 case DW_FORM_data4
:
18954 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
18957 case DW_FORM_data8
:
18958 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
18961 case DW_FORM_data16
:
18962 blk
= dwarf_alloc_block (cu
);
18964 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
18966 DW_BLOCK (attr
) = blk
;
18968 case DW_FORM_sec_offset
:
18969 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
18970 info_ptr
+= bytes_read
;
18972 case DW_FORM_string
:
18973 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
18974 DW_STRING_IS_CANONICAL (attr
) = 0;
18975 info_ptr
+= bytes_read
;
18978 if (!cu
->per_cu
->is_dwz
)
18980 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
18981 abfd
, info_ptr
, cu_header
,
18983 DW_STRING_IS_CANONICAL (attr
) = 0;
18984 info_ptr
+= bytes_read
;
18988 case DW_FORM_line_strp
:
18989 if (!cu
->per_cu
->is_dwz
)
18991 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
18993 cu_header
, &bytes_read
);
18994 DW_STRING_IS_CANONICAL (attr
) = 0;
18995 info_ptr
+= bytes_read
;
18999 case DW_FORM_GNU_strp_alt
:
19001 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19002 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
19005 DW_STRING (attr
) = read_indirect_string_from_dwz (objfile
,
19007 DW_STRING_IS_CANONICAL (attr
) = 0;
19008 info_ptr
+= bytes_read
;
19011 case DW_FORM_exprloc
:
19012 case DW_FORM_block
:
19013 blk
= dwarf_alloc_block (cu
);
19014 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19015 info_ptr
+= bytes_read
;
19016 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19017 info_ptr
+= blk
->size
;
19018 DW_BLOCK (attr
) = blk
;
19020 case DW_FORM_block1
:
19021 blk
= dwarf_alloc_block (cu
);
19022 blk
->size
= read_1_byte (abfd
, info_ptr
);
19024 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19025 info_ptr
+= blk
->size
;
19026 DW_BLOCK (attr
) = blk
;
19028 case DW_FORM_data1
:
19029 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19033 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19036 case DW_FORM_flag_present
:
19037 DW_UNSND (attr
) = 1;
19039 case DW_FORM_sdata
:
19040 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19041 info_ptr
+= bytes_read
;
19043 case DW_FORM_udata
:
19044 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19045 info_ptr
+= bytes_read
;
19048 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19049 + read_1_byte (abfd
, info_ptr
));
19053 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19054 + read_2_bytes (abfd
, info_ptr
));
19058 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19059 + read_4_bytes (abfd
, info_ptr
));
19063 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19064 + read_8_bytes (abfd
, info_ptr
));
19067 case DW_FORM_ref_sig8
:
19068 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19071 case DW_FORM_ref_udata
:
19072 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19073 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19074 info_ptr
+= bytes_read
;
19076 case DW_FORM_indirect
:
19077 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19078 info_ptr
+= bytes_read
;
19079 if (form
== DW_FORM_implicit_const
)
19081 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19082 info_ptr
+= bytes_read
;
19084 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19087 case DW_FORM_implicit_const
:
19088 DW_SND (attr
) = implicit_const
;
19090 case DW_FORM_GNU_addr_index
:
19091 if (reader
->dwo_file
== NULL
)
19093 /* For now flag a hard error.
19094 Later we can turn this into a complaint. */
19095 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19096 dwarf_form_name (form
),
19097 bfd_get_filename (abfd
));
19099 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
19100 info_ptr
+= bytes_read
;
19102 case DW_FORM_GNU_str_index
:
19103 if (reader
->dwo_file
== NULL
)
19105 /* For now flag a hard error.
19106 Later we can turn this into a complaint if warranted. */
19107 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19108 dwarf_form_name (form
),
19109 bfd_get_filename (abfd
));
19112 ULONGEST str_index
=
19113 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19115 DW_STRING (attr
) = read_str_index (reader
, str_index
);
19116 DW_STRING_IS_CANONICAL (attr
) = 0;
19117 info_ptr
+= bytes_read
;
19121 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19122 dwarf_form_name (form
),
19123 bfd_get_filename (abfd
));
19127 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
19128 attr
->form
= DW_FORM_GNU_ref_alt
;
19130 /* We have seen instances where the compiler tried to emit a byte
19131 size attribute of -1 which ended up being encoded as an unsigned
19132 0xffffffff. Although 0xffffffff is technically a valid size value,
19133 an object of this size seems pretty unlikely so we can relatively
19134 safely treat these cases as if the size attribute was invalid and
19135 treat them as zero by default. */
19136 if (attr
->name
== DW_AT_byte_size
19137 && form
== DW_FORM_data4
19138 && DW_UNSND (attr
) >= 0xffffffff)
19141 (&symfile_complaints
,
19142 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19143 hex_string (DW_UNSND (attr
)));
19144 DW_UNSND (attr
) = 0;
19150 /* Read an attribute described by an abbreviated attribute. */
19152 static const gdb_byte
*
19153 read_attribute (const struct die_reader_specs
*reader
,
19154 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19155 const gdb_byte
*info_ptr
)
19157 attr
->name
= abbrev
->name
;
19158 return read_attribute_value (reader
, attr
, abbrev
->form
,
19159 abbrev
->implicit_const
, info_ptr
);
19162 /* Read dwarf information from a buffer. */
19164 static unsigned int
19165 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
19167 return bfd_get_8 (abfd
, buf
);
19171 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
19173 return bfd_get_signed_8 (abfd
, buf
);
19176 static unsigned int
19177 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19179 return bfd_get_16 (abfd
, buf
);
19183 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19185 return bfd_get_signed_16 (abfd
, buf
);
19188 static unsigned int
19189 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19191 return bfd_get_32 (abfd
, buf
);
19195 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19197 return bfd_get_signed_32 (abfd
, buf
);
19201 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19203 return bfd_get_64 (abfd
, buf
);
19207 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
19208 unsigned int *bytes_read
)
19210 struct comp_unit_head
*cu_header
= &cu
->header
;
19211 CORE_ADDR retval
= 0;
19213 if (cu_header
->signed_addr_p
)
19215 switch (cu_header
->addr_size
)
19218 retval
= bfd_get_signed_16 (abfd
, buf
);
19221 retval
= bfd_get_signed_32 (abfd
, buf
);
19224 retval
= bfd_get_signed_64 (abfd
, buf
);
19227 internal_error (__FILE__
, __LINE__
,
19228 _("read_address: bad switch, signed [in module %s]"),
19229 bfd_get_filename (abfd
));
19234 switch (cu_header
->addr_size
)
19237 retval
= bfd_get_16 (abfd
, buf
);
19240 retval
= bfd_get_32 (abfd
, buf
);
19243 retval
= bfd_get_64 (abfd
, buf
);
19246 internal_error (__FILE__
, __LINE__
,
19247 _("read_address: bad switch, "
19248 "unsigned [in module %s]"),
19249 bfd_get_filename (abfd
));
19253 *bytes_read
= cu_header
->addr_size
;
19257 /* Read the initial length from a section. The (draft) DWARF 3
19258 specification allows the initial length to take up either 4 bytes
19259 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
19260 bytes describe the length and all offsets will be 8 bytes in length
19263 An older, non-standard 64-bit format is also handled by this
19264 function. The older format in question stores the initial length
19265 as an 8-byte quantity without an escape value. Lengths greater
19266 than 2^32 aren't very common which means that the initial 4 bytes
19267 is almost always zero. Since a length value of zero doesn't make
19268 sense for the 32-bit format, this initial zero can be considered to
19269 be an escape value which indicates the presence of the older 64-bit
19270 format. As written, the code can't detect (old format) lengths
19271 greater than 4GB. If it becomes necessary to handle lengths
19272 somewhat larger than 4GB, we could allow other small values (such
19273 as the non-sensical values of 1, 2, and 3) to also be used as
19274 escape values indicating the presence of the old format.
19276 The value returned via bytes_read should be used to increment the
19277 relevant pointer after calling read_initial_length().
19279 [ Note: read_initial_length() and read_offset() are based on the
19280 document entitled "DWARF Debugging Information Format", revision
19281 3, draft 8, dated November 19, 2001. This document was obtained
19284 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
19286 This document is only a draft and is subject to change. (So beware.)
19288 Details regarding the older, non-standard 64-bit format were
19289 determined empirically by examining 64-bit ELF files produced by
19290 the SGI toolchain on an IRIX 6.5 machine.
19292 - Kevin, July 16, 2002
19296 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
19298 LONGEST length
= bfd_get_32 (abfd
, buf
);
19300 if (length
== 0xffffffff)
19302 length
= bfd_get_64 (abfd
, buf
+ 4);
19305 else if (length
== 0)
19307 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
19308 length
= bfd_get_64 (abfd
, buf
);
19319 /* Cover function for read_initial_length.
19320 Returns the length of the object at BUF, and stores the size of the
19321 initial length in *BYTES_READ and stores the size that offsets will be in
19323 If the initial length size is not equivalent to that specified in
19324 CU_HEADER then issue a complaint.
19325 This is useful when reading non-comp-unit headers. */
19328 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
19329 const struct comp_unit_head
*cu_header
,
19330 unsigned int *bytes_read
,
19331 unsigned int *offset_size
)
19333 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
19335 gdb_assert (cu_header
->initial_length_size
== 4
19336 || cu_header
->initial_length_size
== 8
19337 || cu_header
->initial_length_size
== 12);
19339 if (cu_header
->initial_length_size
!= *bytes_read
)
19340 complaint (&symfile_complaints
,
19341 _("intermixed 32-bit and 64-bit DWARF sections"));
19343 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
19347 /* Read an offset from the data stream. The size of the offset is
19348 given by cu_header->offset_size. */
19351 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
19352 const struct comp_unit_head
*cu_header
,
19353 unsigned int *bytes_read
)
19355 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
19357 *bytes_read
= cu_header
->offset_size
;
19361 /* Read an offset from the data stream. */
19364 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
19366 LONGEST retval
= 0;
19368 switch (offset_size
)
19371 retval
= bfd_get_32 (abfd
, buf
);
19374 retval
= bfd_get_64 (abfd
, buf
);
19377 internal_error (__FILE__
, __LINE__
,
19378 _("read_offset_1: bad switch [in module %s]"),
19379 bfd_get_filename (abfd
));
19385 static const gdb_byte
*
19386 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
19388 /* If the size of a host char is 8 bits, we can return a pointer
19389 to the buffer, otherwise we have to copy the data to a buffer
19390 allocated on the temporary obstack. */
19391 gdb_assert (HOST_CHAR_BIT
== 8);
19395 static const char *
19396 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
19397 unsigned int *bytes_read_ptr
)
19399 /* If the size of a host char is 8 bits, we can return a pointer
19400 to the string, otherwise we have to copy the string to a buffer
19401 allocated on the temporary obstack. */
19402 gdb_assert (HOST_CHAR_BIT
== 8);
19405 *bytes_read_ptr
= 1;
19408 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
19409 return (const char *) buf
;
19412 /* Return pointer to string at section SECT offset STR_OFFSET with error
19413 reporting strings FORM_NAME and SECT_NAME. */
19415 static const char *
19416 read_indirect_string_at_offset_from (struct objfile
*objfile
,
19417 bfd
*abfd
, LONGEST str_offset
,
19418 struct dwarf2_section_info
*sect
,
19419 const char *form_name
,
19420 const char *sect_name
)
19422 dwarf2_read_section (objfile
, sect
);
19423 if (sect
->buffer
== NULL
)
19424 error (_("%s used without %s section [in module %s]"),
19425 form_name
, sect_name
, bfd_get_filename (abfd
));
19426 if (str_offset
>= sect
->size
)
19427 error (_("%s pointing outside of %s section [in module %s]"),
19428 form_name
, sect_name
, bfd_get_filename (abfd
));
19429 gdb_assert (HOST_CHAR_BIT
== 8);
19430 if (sect
->buffer
[str_offset
] == '\0')
19432 return (const char *) (sect
->buffer
+ str_offset
);
19435 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19437 static const char *
19438 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19439 bfd
*abfd
, LONGEST str_offset
)
19441 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19443 &dwarf2_per_objfile
->str
,
19444 "DW_FORM_strp", ".debug_str");
19447 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
19449 static const char *
19450 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19451 bfd
*abfd
, LONGEST str_offset
)
19453 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19455 &dwarf2_per_objfile
->line_str
,
19456 "DW_FORM_line_strp",
19457 ".debug_line_str");
19460 /* Read a string at offset STR_OFFSET in the .debug_str section from
19461 the .dwz file DWZ. Throw an error if the offset is too large. If
19462 the string consists of a single NUL byte, return NULL; otherwise
19463 return a pointer to the string. */
19465 static const char *
19466 read_indirect_string_from_dwz (struct objfile
*objfile
, struct dwz_file
*dwz
,
19467 LONGEST str_offset
)
19469 dwarf2_read_section (objfile
, &dwz
->str
);
19471 if (dwz
->str
.buffer
== NULL
)
19472 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
19473 "section [in module %s]"),
19474 bfd_get_filename (dwz
->dwz_bfd
));
19475 if (str_offset
>= dwz
->str
.size
)
19476 error (_("DW_FORM_GNU_strp_alt pointing outside of "
19477 ".debug_str section [in module %s]"),
19478 bfd_get_filename (dwz
->dwz_bfd
));
19479 gdb_assert (HOST_CHAR_BIT
== 8);
19480 if (dwz
->str
.buffer
[str_offset
] == '\0')
19482 return (const char *) (dwz
->str
.buffer
+ str_offset
);
19485 /* Return pointer to string at .debug_str offset as read from BUF.
19486 BUF is assumed to be in a compilation unit described by CU_HEADER.
19487 Return *BYTES_READ_PTR count of bytes read from BUF. */
19489 static const char *
19490 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
19491 const gdb_byte
*buf
,
19492 const struct comp_unit_head
*cu_header
,
19493 unsigned int *bytes_read_ptr
)
19495 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19497 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
19500 /* Return pointer to string at .debug_line_str offset as read from BUF.
19501 BUF is assumed to be in a compilation unit described by CU_HEADER.
19502 Return *BYTES_READ_PTR count of bytes read from BUF. */
19504 static const char *
19505 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19506 bfd
*abfd
, const gdb_byte
*buf
,
19507 const struct comp_unit_head
*cu_header
,
19508 unsigned int *bytes_read_ptr
)
19510 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19512 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
19517 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
19518 unsigned int *bytes_read_ptr
)
19521 unsigned int num_read
;
19523 unsigned char byte
;
19530 byte
= bfd_get_8 (abfd
, buf
);
19533 result
|= ((ULONGEST
) (byte
& 127) << shift
);
19534 if ((byte
& 128) == 0)
19540 *bytes_read_ptr
= num_read
;
19545 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
19546 unsigned int *bytes_read_ptr
)
19549 int shift
, num_read
;
19550 unsigned char byte
;
19557 byte
= bfd_get_8 (abfd
, buf
);
19560 result
|= ((LONGEST
) (byte
& 127) << shift
);
19562 if ((byte
& 128) == 0)
19567 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
19568 result
|= -(((LONGEST
) 1) << shift
);
19569 *bytes_read_ptr
= num_read
;
19573 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
19574 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
19575 ADDR_SIZE is the size of addresses from the CU header. */
19578 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19579 unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
19581 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19582 bfd
*abfd
= objfile
->obfd
;
19583 const gdb_byte
*info_ptr
;
19585 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
19586 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
19587 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
19588 objfile_name (objfile
));
19589 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
19590 error (_("DW_FORM_addr_index pointing outside of "
19591 ".debug_addr section [in module %s]"),
19592 objfile_name (objfile
));
19593 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
19594 + addr_base
+ addr_index
* addr_size
);
19595 if (addr_size
== 4)
19596 return bfd_get_32 (abfd
, info_ptr
);
19598 return bfd_get_64 (abfd
, info_ptr
);
19601 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
19604 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
19606 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
19607 cu
->addr_base
, cu
->header
.addr_size
);
19610 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
19613 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
19614 unsigned int *bytes_read
)
19616 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
19617 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
19619 return read_addr_index (cu
, addr_index
);
19622 /* Data structure to pass results from dwarf2_read_addr_index_reader
19623 back to dwarf2_read_addr_index. */
19625 struct dwarf2_read_addr_index_data
19627 ULONGEST addr_base
;
19631 /* die_reader_func for dwarf2_read_addr_index. */
19634 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
19635 const gdb_byte
*info_ptr
,
19636 struct die_info
*comp_unit_die
,
19640 struct dwarf2_cu
*cu
= reader
->cu
;
19641 struct dwarf2_read_addr_index_data
*aidata
=
19642 (struct dwarf2_read_addr_index_data
*) data
;
19644 aidata
->addr_base
= cu
->addr_base
;
19645 aidata
->addr_size
= cu
->header
.addr_size
;
19648 /* Given an index in .debug_addr, fetch the value.
19649 NOTE: This can be called during dwarf expression evaluation,
19650 long after the debug information has been read, and thus per_cu->cu
19651 may no longer exist. */
19654 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
19655 unsigned int addr_index
)
19657 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
19658 struct dwarf2_cu
*cu
= per_cu
->cu
;
19659 ULONGEST addr_base
;
19662 /* We need addr_base and addr_size.
19663 If we don't have PER_CU->cu, we have to get it.
19664 Nasty, but the alternative is storing the needed info in PER_CU,
19665 which at this point doesn't seem justified: it's not clear how frequently
19666 it would get used and it would increase the size of every PER_CU.
19667 Entry points like dwarf2_per_cu_addr_size do a similar thing
19668 so we're not in uncharted territory here.
19669 Alas we need to be a bit more complicated as addr_base is contained
19672 We don't need to read the entire CU(/TU).
19673 We just need the header and top level die.
19675 IWBN to use the aging mechanism to let us lazily later discard the CU.
19676 For now we skip this optimization. */
19680 addr_base
= cu
->addr_base
;
19681 addr_size
= cu
->header
.addr_size
;
19685 struct dwarf2_read_addr_index_data aidata
;
19687 /* Note: We can't use init_cutu_and_read_dies_simple here,
19688 we need addr_base. */
19689 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0, false,
19690 dwarf2_read_addr_index_reader
, &aidata
);
19691 addr_base
= aidata
.addr_base
;
19692 addr_size
= aidata
.addr_size
;
19695 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
19699 /* Given a DW_FORM_GNU_str_index, fetch the string.
19700 This is only used by the Fission support. */
19702 static const char *
19703 read_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
19705 struct dwarf2_cu
*cu
= reader
->cu
;
19706 struct dwarf2_per_objfile
*dwarf2_per_objfile
19707 = cu
->per_cu
->dwarf2_per_objfile
;
19708 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19709 const char *objf_name
= objfile_name (objfile
);
19710 bfd
*abfd
= objfile
->obfd
;
19711 struct dwarf2_section_info
*str_section
= &reader
->dwo_file
->sections
.str
;
19712 struct dwarf2_section_info
*str_offsets_section
=
19713 &reader
->dwo_file
->sections
.str_offsets
;
19714 const gdb_byte
*info_ptr
;
19715 ULONGEST str_offset
;
19716 static const char form_name
[] = "DW_FORM_GNU_str_index";
19718 dwarf2_read_section (objfile
, str_section
);
19719 dwarf2_read_section (objfile
, str_offsets_section
);
19720 if (str_section
->buffer
== NULL
)
19721 error (_("%s used without .debug_str.dwo section"
19722 " in CU at offset %s [in module %s]"),
19723 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19724 if (str_offsets_section
->buffer
== NULL
)
19725 error (_("%s used without .debug_str_offsets.dwo section"
19726 " in CU at offset %s [in module %s]"),
19727 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19728 if (str_index
* cu
->header
.offset_size
>= str_offsets_section
->size
)
19729 error (_("%s pointing outside of .debug_str_offsets.dwo"
19730 " section in CU at offset %s [in module %s]"),
19731 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19732 info_ptr
= (str_offsets_section
->buffer
19733 + str_index
* cu
->header
.offset_size
);
19734 if (cu
->header
.offset_size
== 4)
19735 str_offset
= bfd_get_32 (abfd
, info_ptr
);
19737 str_offset
= bfd_get_64 (abfd
, info_ptr
);
19738 if (str_offset
>= str_section
->size
)
19739 error (_("Offset from %s pointing outside of"
19740 " .debug_str.dwo section in CU at offset %s [in module %s]"),
19741 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19742 return (const char *) (str_section
->buffer
+ str_offset
);
19745 /* Return the length of an LEB128 number in BUF. */
19748 leb128_size (const gdb_byte
*buf
)
19750 const gdb_byte
*begin
= buf
;
19756 if ((byte
& 128) == 0)
19757 return buf
- begin
;
19762 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19771 cu
->language
= language_c
;
19774 case DW_LANG_C_plus_plus
:
19775 case DW_LANG_C_plus_plus_11
:
19776 case DW_LANG_C_plus_plus_14
:
19777 cu
->language
= language_cplus
;
19780 cu
->language
= language_d
;
19782 case DW_LANG_Fortran77
:
19783 case DW_LANG_Fortran90
:
19784 case DW_LANG_Fortran95
:
19785 case DW_LANG_Fortran03
:
19786 case DW_LANG_Fortran08
:
19787 cu
->language
= language_fortran
;
19790 cu
->language
= language_go
;
19792 case DW_LANG_Mips_Assembler
:
19793 cu
->language
= language_asm
;
19795 case DW_LANG_Ada83
:
19796 case DW_LANG_Ada95
:
19797 cu
->language
= language_ada
;
19799 case DW_LANG_Modula2
:
19800 cu
->language
= language_m2
;
19802 case DW_LANG_Pascal83
:
19803 cu
->language
= language_pascal
;
19806 cu
->language
= language_objc
;
19809 case DW_LANG_Rust_old
:
19810 cu
->language
= language_rust
;
19812 case DW_LANG_Cobol74
:
19813 case DW_LANG_Cobol85
:
19815 cu
->language
= language_minimal
;
19818 cu
->language_defn
= language_def (cu
->language
);
19821 /* Return the named attribute or NULL if not there. */
19823 static struct attribute
*
19824 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19829 struct attribute
*spec
= NULL
;
19831 for (i
= 0; i
< die
->num_attrs
; ++i
)
19833 if (die
->attrs
[i
].name
== name
)
19834 return &die
->attrs
[i
];
19835 if (die
->attrs
[i
].name
== DW_AT_specification
19836 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19837 spec
= &die
->attrs
[i
];
19843 die
= follow_die_ref (die
, spec
, &cu
);
19849 /* Return the named attribute or NULL if not there,
19850 but do not follow DW_AT_specification, etc.
19851 This is for use in contexts where we're reading .debug_types dies.
19852 Following DW_AT_specification, DW_AT_abstract_origin will take us
19853 back up the chain, and we want to go down. */
19855 static struct attribute
*
19856 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
19860 for (i
= 0; i
< die
->num_attrs
; ++i
)
19861 if (die
->attrs
[i
].name
== name
)
19862 return &die
->attrs
[i
];
19867 /* Return the string associated with a string-typed attribute, or NULL if it
19868 is either not found or is of an incorrect type. */
19870 static const char *
19871 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19873 struct attribute
*attr
;
19874 const char *str
= NULL
;
19876 attr
= dwarf2_attr (die
, name
, cu
);
19880 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
19881 || attr
->form
== DW_FORM_string
19882 || attr
->form
== DW_FORM_GNU_str_index
19883 || attr
->form
== DW_FORM_GNU_strp_alt
)
19884 str
= DW_STRING (attr
);
19886 complaint (&symfile_complaints
,
19887 _("string type expected for attribute %s for "
19888 "DIE at %s in module %s"),
19889 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19890 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
19896 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19897 and holds a non-zero value. This function should only be used for
19898 DW_FORM_flag or DW_FORM_flag_present attributes. */
19901 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19903 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19905 return (attr
&& DW_UNSND (attr
));
19909 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19911 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19912 which value is non-zero. However, we have to be careful with
19913 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19914 (via dwarf2_flag_true_p) follows this attribute. So we may
19915 end up accidently finding a declaration attribute that belongs
19916 to a different DIE referenced by the specification attribute,
19917 even though the given DIE does not have a declaration attribute. */
19918 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19919 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19922 /* Return the die giving the specification for DIE, if there is
19923 one. *SPEC_CU is the CU containing DIE on input, and the CU
19924 containing the return value on output. If there is no
19925 specification, but there is an abstract origin, that is
19928 static struct die_info
*
19929 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19931 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19934 if (spec_attr
== NULL
)
19935 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19937 if (spec_attr
== NULL
)
19940 return follow_die_ref (die
, spec_attr
, spec_cu
);
19943 /* Stub for free_line_header to match void * callback types. */
19946 free_line_header_voidp (void *arg
)
19948 struct line_header
*lh
= (struct line_header
*) arg
;
19954 line_header::add_include_dir (const char *include_dir
)
19956 if (dwarf_line_debug
>= 2)
19957 fprintf_unfiltered (gdb_stdlog
, "Adding dir %zu: %s\n",
19958 include_dirs
.size () + 1, include_dir
);
19960 include_dirs
.push_back (include_dir
);
19964 line_header::add_file_name (const char *name
,
19966 unsigned int mod_time
,
19967 unsigned int length
)
19969 if (dwarf_line_debug
>= 2)
19970 fprintf_unfiltered (gdb_stdlog
, "Adding file %u: %s\n",
19971 (unsigned) file_names
.size () + 1, name
);
19973 file_names
.emplace_back (name
, d_index
, mod_time
, length
);
19976 /* A convenience function to find the proper .debug_line section for a CU. */
19978 static struct dwarf2_section_info
*
19979 get_debug_line_section (struct dwarf2_cu
*cu
)
19981 struct dwarf2_section_info
*section
;
19982 struct dwarf2_per_objfile
*dwarf2_per_objfile
19983 = cu
->per_cu
->dwarf2_per_objfile
;
19985 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19987 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19988 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19989 else if (cu
->per_cu
->is_dwz
)
19991 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19993 section
= &dwz
->line
;
19996 section
= &dwarf2_per_objfile
->line
;
20001 /* Read directory or file name entry format, starting with byte of
20002 format count entries, ULEB128 pairs of entry formats, ULEB128 of
20003 entries count and the entries themselves in the described entry
20007 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20008 bfd
*abfd
, const gdb_byte
**bufp
,
20009 struct line_header
*lh
,
20010 const struct comp_unit_head
*cu_header
,
20011 void (*callback
) (struct line_header
*lh
,
20014 unsigned int mod_time
,
20015 unsigned int length
))
20017 gdb_byte format_count
, formati
;
20018 ULONGEST data_count
, datai
;
20019 const gdb_byte
*buf
= *bufp
;
20020 const gdb_byte
*format_header_data
;
20021 unsigned int bytes_read
;
20023 format_count
= read_1_byte (abfd
, buf
);
20025 format_header_data
= buf
;
20026 for (formati
= 0; formati
< format_count
; formati
++)
20028 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20030 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20034 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20036 for (datai
= 0; datai
< data_count
; datai
++)
20038 const gdb_byte
*format
= format_header_data
;
20039 struct file_entry fe
;
20041 for (formati
= 0; formati
< format_count
; formati
++)
20043 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20044 format
+= bytes_read
;
20046 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20047 format
+= bytes_read
;
20049 gdb::optional
<const char *> string
;
20050 gdb::optional
<unsigned int> uint
;
20054 case DW_FORM_string
:
20055 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
20059 case DW_FORM_line_strp
:
20060 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
20067 case DW_FORM_data1
:
20068 uint
.emplace (read_1_byte (abfd
, buf
));
20072 case DW_FORM_data2
:
20073 uint
.emplace (read_2_bytes (abfd
, buf
));
20077 case DW_FORM_data4
:
20078 uint
.emplace (read_4_bytes (abfd
, buf
));
20082 case DW_FORM_data8
:
20083 uint
.emplace (read_8_bytes (abfd
, buf
));
20087 case DW_FORM_udata
:
20088 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
20092 case DW_FORM_block
:
20093 /* It is valid only for DW_LNCT_timestamp which is ignored by
20098 switch (content_type
)
20101 if (string
.has_value ())
20104 case DW_LNCT_directory_index
:
20105 if (uint
.has_value ())
20106 fe
.d_index
= (dir_index
) *uint
;
20108 case DW_LNCT_timestamp
:
20109 if (uint
.has_value ())
20110 fe
.mod_time
= *uint
;
20113 if (uint
.has_value ())
20119 complaint (&symfile_complaints
,
20120 _("Unknown format content type %s"),
20121 pulongest (content_type
));
20125 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
20131 /* Read the statement program header starting at OFFSET in
20132 .debug_line, or .debug_line.dwo. Return a pointer
20133 to a struct line_header, allocated using xmalloc.
20134 Returns NULL if there is a problem reading the header, e.g., if it
20135 has a version we don't understand.
20137 NOTE: the strings in the include directory and file name tables of
20138 the returned object point into the dwarf line section buffer,
20139 and must not be freed. */
20141 static line_header_up
20142 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20144 const gdb_byte
*line_ptr
;
20145 unsigned int bytes_read
, offset_size
;
20147 const char *cur_dir
, *cur_file
;
20148 struct dwarf2_section_info
*section
;
20150 struct dwarf2_per_objfile
*dwarf2_per_objfile
20151 = cu
->per_cu
->dwarf2_per_objfile
;
20153 section
= get_debug_line_section (cu
);
20154 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
20155 if (section
->buffer
== NULL
)
20157 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20158 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
20160 complaint (&symfile_complaints
, _("missing .debug_line section"));
20164 /* We can't do this until we know the section is non-empty.
20165 Only then do we know we have such a section. */
20166 abfd
= get_section_bfd_owner (section
);
20168 /* Make sure that at least there's room for the total_length field.
20169 That could be 12 bytes long, but we're just going to fudge that. */
20170 if (to_underlying (sect_off
) + 4 >= section
->size
)
20172 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20176 line_header_up
lh (new line_header ());
20178 lh
->sect_off
= sect_off
;
20179 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
20181 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
20183 /* Read in the header. */
20185 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
20186 &bytes_read
, &offset_size
);
20187 line_ptr
+= bytes_read
;
20188 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
20190 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20193 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
20194 lh
->version
= read_2_bytes (abfd
, line_ptr
);
20196 if (lh
->version
> 5)
20198 /* This is a version we don't understand. The format could have
20199 changed in ways we don't handle properly so just punt. */
20200 complaint (&symfile_complaints
,
20201 _("unsupported version in .debug_line section"));
20204 if (lh
->version
>= 5)
20206 gdb_byte segment_selector_size
;
20208 /* Skip address size. */
20209 read_1_byte (abfd
, line_ptr
);
20212 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
20214 if (segment_selector_size
!= 0)
20216 complaint (&symfile_complaints
,
20217 _("unsupported segment selector size %u "
20218 "in .debug_line section"),
20219 segment_selector_size
);
20223 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
20224 line_ptr
+= offset_size
;
20225 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
20227 if (lh
->version
>= 4)
20229 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
20233 lh
->maximum_ops_per_instruction
= 1;
20235 if (lh
->maximum_ops_per_instruction
== 0)
20237 lh
->maximum_ops_per_instruction
= 1;
20238 complaint (&symfile_complaints
,
20239 _("invalid maximum_ops_per_instruction "
20240 "in `.debug_line' section"));
20243 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
20245 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
20247 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
20249 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
20251 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
20253 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
20254 for (i
= 1; i
< lh
->opcode_base
; ++i
)
20256 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
20260 if (lh
->version
>= 5)
20262 /* Read directory table. */
20263 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20265 [] (struct line_header
*lh
, const char *name
,
20266 dir_index d_index
, unsigned int mod_time
,
20267 unsigned int length
)
20269 lh
->add_include_dir (name
);
20272 /* Read file name table. */
20273 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20275 [] (struct line_header
*lh
, const char *name
,
20276 dir_index d_index
, unsigned int mod_time
,
20277 unsigned int length
)
20279 lh
->add_file_name (name
, d_index
, mod_time
, length
);
20284 /* Read directory table. */
20285 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20287 line_ptr
+= bytes_read
;
20288 lh
->add_include_dir (cur_dir
);
20290 line_ptr
+= bytes_read
;
20292 /* Read file name table. */
20293 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20295 unsigned int mod_time
, length
;
20298 line_ptr
+= bytes_read
;
20299 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20300 line_ptr
+= bytes_read
;
20301 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20302 line_ptr
+= bytes_read
;
20303 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20304 line_ptr
+= bytes_read
;
20306 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
20308 line_ptr
+= bytes_read
;
20310 lh
->statement_program_start
= line_ptr
;
20312 if (line_ptr
> (section
->buffer
+ section
->size
))
20313 complaint (&symfile_complaints
,
20314 _("line number info header doesn't "
20315 "fit in `.debug_line' section"));
20320 /* Subroutine of dwarf_decode_lines to simplify it.
20321 Return the file name of the psymtab for included file FILE_INDEX
20322 in line header LH of PST.
20323 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20324 If space for the result is malloc'd, *NAME_HOLDER will be set.
20325 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20327 static const char *
20328 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
20329 const struct partial_symtab
*pst
,
20330 const char *comp_dir
,
20331 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20333 const file_entry
&fe
= lh
->file_names
[file_index
];
20334 const char *include_name
= fe
.name
;
20335 const char *include_name_to_compare
= include_name
;
20336 const char *pst_filename
;
20339 const char *dir_name
= fe
.include_dir (lh
);
20341 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20342 if (!IS_ABSOLUTE_PATH (include_name
)
20343 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20345 /* Avoid creating a duplicate psymtab for PST.
20346 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20347 Before we do the comparison, however, we need to account
20348 for DIR_NAME and COMP_DIR.
20349 First prepend dir_name (if non-NULL). If we still don't
20350 have an absolute path prepend comp_dir (if non-NULL).
20351 However, the directory we record in the include-file's
20352 psymtab does not contain COMP_DIR (to match the
20353 corresponding symtab(s)).
20358 bash$ gcc -g ./hello.c
20359 include_name = "hello.c"
20361 DW_AT_comp_dir = comp_dir = "/tmp"
20362 DW_AT_name = "./hello.c"
20366 if (dir_name
!= NULL
)
20368 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20369 include_name
, (char *) NULL
));
20370 include_name
= name_holder
->get ();
20371 include_name_to_compare
= include_name
;
20373 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20375 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20376 include_name
, (char *) NULL
));
20377 include_name_to_compare
= hold_compare
.get ();
20381 pst_filename
= pst
->filename
;
20382 gdb::unique_xmalloc_ptr
<char> copied_name
;
20383 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20385 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20386 pst_filename
, (char *) NULL
));
20387 pst_filename
= copied_name
.get ();
20390 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20394 return include_name
;
20397 /* State machine to track the state of the line number program. */
20399 class lnp_state_machine
20402 /* Initialize a machine state for the start of a line number
20404 lnp_state_machine (gdbarch
*arch
, line_header
*lh
, bool record_lines_p
);
20406 file_entry
*current_file ()
20408 /* lh->file_names is 0-based, but the file name numbers in the
20409 statement program are 1-based. */
20410 return m_line_header
->file_name_at (m_file
);
20413 /* Record the line in the state machine. END_SEQUENCE is true if
20414 we're processing the end of a sequence. */
20415 void record_line (bool end_sequence
);
20417 /* Check address and if invalid nop-out the rest of the lines in this
20419 void check_line_address (struct dwarf2_cu
*cu
,
20420 const gdb_byte
*line_ptr
,
20421 CORE_ADDR lowpc
, CORE_ADDR address
);
20423 void handle_set_discriminator (unsigned int discriminator
)
20425 m_discriminator
= discriminator
;
20426 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20429 /* Handle DW_LNE_set_address. */
20430 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20433 address
+= baseaddr
;
20434 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20437 /* Handle DW_LNS_advance_pc. */
20438 void handle_advance_pc (CORE_ADDR adjust
);
20440 /* Handle a special opcode. */
20441 void handle_special_opcode (unsigned char op_code
);
20443 /* Handle DW_LNS_advance_line. */
20444 void handle_advance_line (int line_delta
)
20446 advance_line (line_delta
);
20449 /* Handle DW_LNS_set_file. */
20450 void handle_set_file (file_name_index file
);
20452 /* Handle DW_LNS_negate_stmt. */
20453 void handle_negate_stmt ()
20455 m_is_stmt
= !m_is_stmt
;
20458 /* Handle DW_LNS_const_add_pc. */
20459 void handle_const_add_pc ();
20461 /* Handle DW_LNS_fixed_advance_pc. */
20462 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20464 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20468 /* Handle DW_LNS_copy. */
20469 void handle_copy ()
20471 record_line (false);
20472 m_discriminator
= 0;
20475 /* Handle DW_LNE_end_sequence. */
20476 void handle_end_sequence ()
20478 m_record_line_callback
= ::record_line
;
20482 /* Advance the line by LINE_DELTA. */
20483 void advance_line (int line_delta
)
20485 m_line
+= line_delta
;
20487 if (line_delta
!= 0)
20488 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20491 gdbarch
*m_gdbarch
;
20493 /* True if we're recording lines.
20494 Otherwise we're building partial symtabs and are just interested in
20495 finding include files mentioned by the line number program. */
20496 bool m_record_lines_p
;
20498 /* The line number header. */
20499 line_header
*m_line_header
;
20501 /* These are part of the standard DWARF line number state machine,
20502 and initialized according to the DWARF spec. */
20504 unsigned char m_op_index
= 0;
20505 /* The line table index (1-based) of the current file. */
20506 file_name_index m_file
= (file_name_index
) 1;
20507 unsigned int m_line
= 1;
20509 /* These are initialized in the constructor. */
20511 CORE_ADDR m_address
;
20513 unsigned int m_discriminator
;
20515 /* Additional bits of state we need to track. */
20517 /* The last file that we called dwarf2_start_subfile for.
20518 This is only used for TLLs. */
20519 unsigned int m_last_file
= 0;
20520 /* The last file a line number was recorded for. */
20521 struct subfile
*m_last_subfile
= NULL
;
20523 /* The function to call to record a line. */
20524 record_line_ftype
*m_record_line_callback
= NULL
;
20526 /* The last line number that was recorded, used to coalesce
20527 consecutive entries for the same line. This can happen, for
20528 example, when discriminators are present. PR 17276. */
20529 unsigned int m_last_line
= 0;
20530 bool m_line_has_non_zero_discriminator
= false;
20534 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20536 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20537 / m_line_header
->maximum_ops_per_instruction
)
20538 * m_line_header
->minimum_instruction_length
);
20539 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20540 m_op_index
= ((m_op_index
+ adjust
)
20541 % m_line_header
->maximum_ops_per_instruction
);
20545 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20547 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20548 CORE_ADDR addr_adj
= (((m_op_index
20549 + (adj_opcode
/ m_line_header
->line_range
))
20550 / m_line_header
->maximum_ops_per_instruction
)
20551 * m_line_header
->minimum_instruction_length
);
20552 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20553 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
20554 % m_line_header
->maximum_ops_per_instruction
);
20556 int line_delta
= (m_line_header
->line_base
20557 + (adj_opcode
% m_line_header
->line_range
));
20558 advance_line (line_delta
);
20559 record_line (false);
20560 m_discriminator
= 0;
20564 lnp_state_machine::handle_set_file (file_name_index file
)
20568 const file_entry
*fe
= current_file ();
20570 dwarf2_debug_line_missing_file_complaint ();
20571 else if (m_record_lines_p
)
20573 const char *dir
= fe
->include_dir (m_line_header
);
20575 m_last_subfile
= current_subfile
;
20576 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20577 dwarf2_start_subfile (fe
->name
, dir
);
20582 lnp_state_machine::handle_const_add_pc ()
20585 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20588 = (((m_op_index
+ adjust
)
20589 / m_line_header
->maximum_ops_per_instruction
)
20590 * m_line_header
->minimum_instruction_length
);
20592 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20593 m_op_index
= ((m_op_index
+ adjust
)
20594 % m_line_header
->maximum_ops_per_instruction
);
20597 /* Ignore this record_line request. */
20600 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
20605 /* Return non-zero if we should add LINE to the line number table.
20606 LINE is the line to add, LAST_LINE is the last line that was added,
20607 LAST_SUBFILE is the subfile for LAST_LINE.
20608 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20609 had a non-zero discriminator.
20611 We have to be careful in the presence of discriminators.
20612 E.g., for this line:
20614 for (i = 0; i < 100000; i++);
20616 clang can emit four line number entries for that one line,
20617 each with a different discriminator.
20618 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20620 However, we want gdb to coalesce all four entries into one.
20621 Otherwise the user could stepi into the middle of the line and
20622 gdb would get confused about whether the pc really was in the
20623 middle of the line.
20625 Things are further complicated by the fact that two consecutive
20626 line number entries for the same line is a heuristic used by gcc
20627 to denote the end of the prologue. So we can't just discard duplicate
20628 entries, we have to be selective about it. The heuristic we use is
20629 that we only collapse consecutive entries for the same line if at least
20630 one of those entries has a non-zero discriminator. PR 17276.
20632 Note: Addresses in the line number state machine can never go backwards
20633 within one sequence, thus this coalescing is ok. */
20636 dwarf_record_line_p (unsigned int line
, unsigned int last_line
,
20637 int line_has_non_zero_discriminator
,
20638 struct subfile
*last_subfile
)
20640 if (current_subfile
!= last_subfile
)
20642 if (line
!= last_line
)
20644 /* Same line for the same file that we've seen already.
20645 As a last check, for pr 17276, only record the line if the line
20646 has never had a non-zero discriminator. */
20647 if (!line_has_non_zero_discriminator
)
20652 /* Use P_RECORD_LINE to record line number LINE beginning at address ADDRESS
20653 in the line table of subfile SUBFILE. */
20656 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20657 unsigned int line
, CORE_ADDR address
,
20658 record_line_ftype p_record_line
)
20660 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20662 if (dwarf_line_debug
)
20664 fprintf_unfiltered (gdb_stdlog
,
20665 "Recording line %u, file %s, address %s\n",
20666 line
, lbasename (subfile
->name
),
20667 paddress (gdbarch
, address
));
20670 (*p_record_line
) (subfile
, line
, addr
);
20673 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20674 Mark the end of a set of line number records.
20675 The arguments are the same as for dwarf_record_line_1.
20676 If SUBFILE is NULL the request is ignored. */
20679 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20680 CORE_ADDR address
, record_line_ftype p_record_line
)
20682 if (subfile
== NULL
)
20685 if (dwarf_line_debug
)
20687 fprintf_unfiltered (gdb_stdlog
,
20688 "Finishing current line, file %s, address %s\n",
20689 lbasename (subfile
->name
),
20690 paddress (gdbarch
, address
));
20693 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, p_record_line
);
20697 lnp_state_machine::record_line (bool end_sequence
)
20699 if (dwarf_line_debug
)
20701 fprintf_unfiltered (gdb_stdlog
,
20702 "Processing actual line %u: file %u,"
20703 " address %s, is_stmt %u, discrim %u\n",
20704 m_line
, to_underlying (m_file
),
20705 paddress (m_gdbarch
, m_address
),
20706 m_is_stmt
, m_discriminator
);
20709 file_entry
*fe
= current_file ();
20712 dwarf2_debug_line_missing_file_complaint ();
20713 /* For now we ignore lines not starting on an instruction boundary.
20714 But not when processing end_sequence for compatibility with the
20715 previous version of the code. */
20716 else if (m_op_index
== 0 || end_sequence
)
20718 fe
->included_p
= 1;
20719 if (m_record_lines_p
&& m_is_stmt
)
20721 if (m_last_subfile
!= current_subfile
|| end_sequence
)
20723 dwarf_finish_line (m_gdbarch
, m_last_subfile
,
20724 m_address
, m_record_line_callback
);
20729 if (dwarf_record_line_p (m_line
, m_last_line
,
20730 m_line_has_non_zero_discriminator
,
20733 dwarf_record_line_1 (m_gdbarch
, current_subfile
,
20735 m_record_line_callback
);
20737 m_last_subfile
= current_subfile
;
20738 m_last_line
= m_line
;
20744 lnp_state_machine::lnp_state_machine (gdbarch
*arch
, line_header
*lh
,
20745 bool record_lines_p
)
20748 m_record_lines_p
= record_lines_p
;
20749 m_line_header
= lh
;
20751 m_record_line_callback
= ::record_line
;
20753 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20754 was a line entry for it so that the backend has a chance to adjust it
20755 and also record it in case it needs it. This is currently used by MIPS
20756 code, cf. `mips_adjust_dwarf2_line'. */
20757 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20758 m_is_stmt
= lh
->default_is_stmt
;
20759 m_discriminator
= 0;
20763 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20764 const gdb_byte
*line_ptr
,
20765 CORE_ADDR lowpc
, CORE_ADDR address
)
20767 /* If address < lowpc then it's not a usable value, it's outside the
20768 pc range of the CU. However, we restrict the test to only address
20769 values of zero to preserve GDB's previous behaviour which is to
20770 handle the specific case of a function being GC'd by the linker. */
20772 if (address
== 0 && address
< lowpc
)
20774 /* This line table is for a function which has been
20775 GCd by the linker. Ignore it. PR gdb/12528 */
20777 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20778 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20780 complaint (&symfile_complaints
,
20781 _(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20782 line_offset
, objfile_name (objfile
));
20783 m_record_line_callback
= noop_record_line
;
20784 /* Note: record_line_callback is left as noop_record_line until
20785 we see DW_LNE_end_sequence. */
20789 /* Subroutine of dwarf_decode_lines to simplify it.
20790 Process the line number information in LH.
20791 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20792 program in order to set included_p for every referenced header. */
20795 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20796 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20798 const gdb_byte
*line_ptr
, *extended_end
;
20799 const gdb_byte
*line_end
;
20800 unsigned int bytes_read
, extended_len
;
20801 unsigned char op_code
, extended_op
;
20802 CORE_ADDR baseaddr
;
20803 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20804 bfd
*abfd
= objfile
->obfd
;
20805 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20806 /* True if we're recording line info (as opposed to building partial
20807 symtabs and just interested in finding include files mentioned by
20808 the line number program). */
20809 bool record_lines_p
= !decode_for_pst_p
;
20811 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
20813 line_ptr
= lh
->statement_program_start
;
20814 line_end
= lh
->statement_program_end
;
20816 /* Read the statement sequences until there's nothing left. */
20817 while (line_ptr
< line_end
)
20819 /* The DWARF line number program state machine. Reset the state
20820 machine at the start of each sequence. */
20821 lnp_state_machine
state_machine (gdbarch
, lh
, record_lines_p
);
20822 bool end_sequence
= false;
20824 if (record_lines_p
)
20826 /* Start a subfile for the current file of the state
20828 const file_entry
*fe
= state_machine
.current_file ();
20831 dwarf2_start_subfile (fe
->name
, fe
->include_dir (lh
));
20834 /* Decode the table. */
20835 while (line_ptr
< line_end
&& !end_sequence
)
20837 op_code
= read_1_byte (abfd
, line_ptr
);
20840 if (op_code
>= lh
->opcode_base
)
20842 /* Special opcode. */
20843 state_machine
.handle_special_opcode (op_code
);
20845 else switch (op_code
)
20847 case DW_LNS_extended_op
:
20848 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20850 line_ptr
+= bytes_read
;
20851 extended_end
= line_ptr
+ extended_len
;
20852 extended_op
= read_1_byte (abfd
, line_ptr
);
20854 switch (extended_op
)
20856 case DW_LNE_end_sequence
:
20857 state_machine
.handle_end_sequence ();
20858 end_sequence
= true;
20860 case DW_LNE_set_address
:
20863 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
20864 line_ptr
+= bytes_read
;
20866 state_machine
.check_line_address (cu
, line_ptr
,
20868 state_machine
.handle_set_address (baseaddr
, address
);
20871 case DW_LNE_define_file
:
20873 const char *cur_file
;
20874 unsigned int mod_time
, length
;
20877 cur_file
= read_direct_string (abfd
, line_ptr
,
20879 line_ptr
+= bytes_read
;
20880 dindex
= (dir_index
)
20881 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20882 line_ptr
+= bytes_read
;
20884 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20885 line_ptr
+= bytes_read
;
20887 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20888 line_ptr
+= bytes_read
;
20889 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20892 case DW_LNE_set_discriminator
:
20894 /* The discriminator is not interesting to the
20895 debugger; just ignore it. We still need to
20896 check its value though:
20897 if there are consecutive entries for the same
20898 (non-prologue) line we want to coalesce them.
20901 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20902 line_ptr
+= bytes_read
;
20904 state_machine
.handle_set_discriminator (discr
);
20908 complaint (&symfile_complaints
,
20909 _("mangled .debug_line section"));
20912 /* Make sure that we parsed the extended op correctly. If e.g.
20913 we expected a different address size than the producer used,
20914 we may have read the wrong number of bytes. */
20915 if (line_ptr
!= extended_end
)
20917 complaint (&symfile_complaints
,
20918 _("mangled .debug_line section"));
20923 state_machine
.handle_copy ();
20925 case DW_LNS_advance_pc
:
20928 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20929 line_ptr
+= bytes_read
;
20931 state_machine
.handle_advance_pc (adjust
);
20934 case DW_LNS_advance_line
:
20937 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20938 line_ptr
+= bytes_read
;
20940 state_machine
.handle_advance_line (line_delta
);
20943 case DW_LNS_set_file
:
20945 file_name_index file
20946 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20948 line_ptr
+= bytes_read
;
20950 state_machine
.handle_set_file (file
);
20953 case DW_LNS_set_column
:
20954 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20955 line_ptr
+= bytes_read
;
20957 case DW_LNS_negate_stmt
:
20958 state_machine
.handle_negate_stmt ();
20960 case DW_LNS_set_basic_block
:
20962 /* Add to the address register of the state machine the
20963 address increment value corresponding to special opcode
20964 255. I.e., this value is scaled by the minimum
20965 instruction length since special opcode 255 would have
20966 scaled the increment. */
20967 case DW_LNS_const_add_pc
:
20968 state_machine
.handle_const_add_pc ();
20970 case DW_LNS_fixed_advance_pc
:
20972 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20975 state_machine
.handle_fixed_advance_pc (addr_adj
);
20980 /* Unknown standard opcode, ignore it. */
20983 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
20985 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20986 line_ptr
+= bytes_read
;
20993 dwarf2_debug_line_missing_end_sequence_complaint ();
20995 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
20996 in which case we still finish recording the last line). */
20997 state_machine
.record_line (true);
21001 /* Decode the Line Number Program (LNP) for the given line_header
21002 structure and CU. The actual information extracted and the type
21003 of structures created from the LNP depends on the value of PST.
21005 1. If PST is NULL, then this procedure uses the data from the program
21006 to create all necessary symbol tables, and their linetables.
21008 2. If PST is not NULL, this procedure reads the program to determine
21009 the list of files included by the unit represented by PST, and
21010 builds all the associated partial symbol tables.
21012 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21013 It is used for relative paths in the line table.
21014 NOTE: When processing partial symtabs (pst != NULL),
21015 comp_dir == pst->dirname.
21017 NOTE: It is important that psymtabs have the same file name (via strcmp)
21018 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21019 symtab we don't use it in the name of the psymtabs we create.
21020 E.g. expand_line_sal requires this when finding psymtabs to expand.
21021 A good testcase for this is mb-inline.exp.
21023 LOWPC is the lowest address in CU (or 0 if not known).
21025 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21026 for its PC<->lines mapping information. Otherwise only the filename
21027 table is read in. */
21030 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21031 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
21032 CORE_ADDR lowpc
, int decode_mapping
)
21034 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21035 const int decode_for_pst_p
= (pst
!= NULL
);
21037 if (decode_mapping
)
21038 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21040 if (decode_for_pst_p
)
21044 /* Now that we're done scanning the Line Header Program, we can
21045 create the psymtab of each included file. */
21046 for (file_index
= 0; file_index
< lh
->file_names
.size (); file_index
++)
21047 if (lh
->file_names
[file_index
].included_p
== 1)
21049 gdb::unique_xmalloc_ptr
<char> name_holder
;
21050 const char *include_name
=
21051 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
,
21053 if (include_name
!= NULL
)
21054 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
21059 /* Make sure a symtab is created for every file, even files
21060 which contain only variables (i.e. no code with associated
21062 struct compunit_symtab
*cust
= buildsym_compunit_symtab ();
21065 for (i
= 0; i
< lh
->file_names
.size (); i
++)
21067 file_entry
&fe
= lh
->file_names
[i
];
21069 dwarf2_start_subfile (fe
.name
, fe
.include_dir (lh
));
21071 if (current_subfile
->symtab
== NULL
)
21073 current_subfile
->symtab
21074 = allocate_symtab (cust
, current_subfile
->name
);
21076 fe
.symtab
= current_subfile
->symtab
;
21081 /* Start a subfile for DWARF. FILENAME is the name of the file and
21082 DIRNAME the name of the source directory which contains FILENAME
21083 or NULL if not known.
21084 This routine tries to keep line numbers from identical absolute and
21085 relative file names in a common subfile.
21087 Using the `list' example from the GDB testsuite, which resides in
21088 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21089 of /srcdir/list0.c yields the following debugging information for list0.c:
21091 DW_AT_name: /srcdir/list0.c
21092 DW_AT_comp_dir: /compdir
21093 files.files[0].name: list0.h
21094 files.files[0].dir: /srcdir
21095 files.files[1].name: list0.c
21096 files.files[1].dir: /srcdir
21098 The line number information for list0.c has to end up in a single
21099 subfile, so that `break /srcdir/list0.c:1' works as expected.
21100 start_subfile will ensure that this happens provided that we pass the
21101 concatenation of files.files[1].dir and files.files[1].name as the
21105 dwarf2_start_subfile (const char *filename
, const char *dirname
)
21109 /* In order not to lose the line information directory,
21110 we concatenate it to the filename when it makes sense.
21111 Note that the Dwarf3 standard says (speaking of filenames in line
21112 information): ``The directory index is ignored for file names
21113 that represent full path names''. Thus ignoring dirname in the
21114 `else' branch below isn't an issue. */
21116 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21118 copy
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
21122 start_subfile (filename
);
21128 /* Start a symtab for DWARF.
21129 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
21131 static struct compunit_symtab
*
21132 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
21133 const char *name
, const char *comp_dir
, CORE_ADDR low_pc
)
21135 struct compunit_symtab
*cust
21136 = start_symtab (cu
->per_cu
->dwarf2_per_objfile
->objfile
, name
, comp_dir
,
21137 low_pc
, cu
->language
);
21139 record_debugformat ("DWARF 2");
21140 record_producer (cu
->producer
);
21142 /* We assume that we're processing GCC output. */
21143 processing_gcc_compilation
= 2;
21145 cu
->processing_has_namespace_info
= 0;
21151 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21152 struct dwarf2_cu
*cu
)
21154 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21155 struct comp_unit_head
*cu_header
= &cu
->header
;
21157 /* NOTE drow/2003-01-30: There used to be a comment and some special
21158 code here to turn a symbol with DW_AT_external and a
21159 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21160 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21161 with some versions of binutils) where shared libraries could have
21162 relocations against symbols in their debug information - the
21163 minimal symbol would have the right address, but the debug info
21164 would not. It's no longer necessary, because we will explicitly
21165 apply relocations when we read in the debug information now. */
21167 /* A DW_AT_location attribute with no contents indicates that a
21168 variable has been optimized away. */
21169 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
21171 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21175 /* Handle one degenerate form of location expression specially, to
21176 preserve GDB's previous behavior when section offsets are
21177 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
21178 then mark this symbol as LOC_STATIC. */
21180 if (attr_form_is_block (attr
)
21181 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
21182 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
21183 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
21184 && (DW_BLOCK (attr
)->size
21185 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
21187 unsigned int dummy
;
21189 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
21190 SYMBOL_VALUE_ADDRESS (sym
) =
21191 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
21193 SYMBOL_VALUE_ADDRESS (sym
) =
21194 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
21195 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21196 fixup_symbol_section (sym
, objfile
);
21197 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
21198 SYMBOL_SECTION (sym
));
21202 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21203 expression evaluator, and use LOC_COMPUTED only when necessary
21204 (i.e. when the value of a register or memory location is
21205 referenced, or a thread-local block, etc.). Then again, it might
21206 not be worthwhile. I'm assuming that it isn't unless performance
21207 or memory numbers show me otherwise. */
21209 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21211 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21212 cu
->has_loclist
= 1;
21215 /* Given a pointer to a DWARF information entry, figure out if we need
21216 to make a symbol table entry for it, and if so, create a new entry
21217 and return a pointer to it.
21218 If TYPE is NULL, determine symbol type from the die, otherwise
21219 used the passed type.
21220 If SPACE is not NULL, use it to hold the new symbol. If it is
21221 NULL, allocate a new symbol on the objfile's obstack. */
21223 static struct symbol
*
21224 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21225 struct symbol
*space
)
21227 struct dwarf2_per_objfile
*dwarf2_per_objfile
21228 = cu
->per_cu
->dwarf2_per_objfile
;
21229 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21230 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21231 struct symbol
*sym
= NULL
;
21233 struct attribute
*attr
= NULL
;
21234 struct attribute
*attr2
= NULL
;
21235 CORE_ADDR baseaddr
;
21236 struct pending
**list_to_add
= NULL
;
21238 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21240 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
21242 name
= dwarf2_name (die
, cu
);
21245 const char *linkagename
;
21246 int suppress_add
= 0;
21251 sym
= allocate_symbol (objfile
);
21252 OBJSTAT (objfile
, n_syms
++);
21254 /* Cache this symbol's name and the name's demangled form (if any). */
21255 SYMBOL_SET_LANGUAGE (sym
, cu
->language
, &objfile
->objfile_obstack
);
21256 linkagename
= dwarf2_physname (name
, die
, cu
);
21257 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
21259 /* Fortran does not have mangling standard and the mangling does differ
21260 between gfortran, iFort etc. */
21261 if (cu
->language
== language_fortran
21262 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
21263 symbol_set_demangled_name (&(sym
->ginfo
),
21264 dwarf2_full_name (name
, die
, cu
),
21267 /* Default assumptions.
21268 Use the passed type or decode it from the die. */
21269 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21270 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21272 SYMBOL_TYPE (sym
) = type
;
21274 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21275 attr
= dwarf2_attr (die
,
21276 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21280 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
21283 attr
= dwarf2_attr (die
,
21284 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21288 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
21289 struct file_entry
*fe
;
21291 if (cu
->line_header
!= NULL
)
21292 fe
= cu
->line_header
->file_name_at (file_index
);
21297 complaint (&symfile_complaints
,
21298 _("file index out of range"));
21300 symbol_set_symtab (sym
, fe
->symtab
);
21306 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21311 addr
= attr_value_as_address (attr
);
21312 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21313 SYMBOL_VALUE_ADDRESS (sym
) = addr
;
21315 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21316 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21317 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21318 add_symbol_to_list (sym
, cu
->list_in_scope
);
21320 case DW_TAG_subprogram
:
21321 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21323 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21324 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21325 if ((attr2
&& (DW_UNSND (attr2
) != 0))
21326 || cu
->language
== language_ada
)
21328 /* Subprograms marked external are stored as a global symbol.
21329 Ada subprograms, whether marked external or not, are always
21330 stored as a global symbol, because we want to be able to
21331 access them globally. For instance, we want to be able
21332 to break on a nested subprogram without having to
21333 specify the context. */
21334 list_to_add
= &global_symbols
;
21338 list_to_add
= cu
->list_in_scope
;
21341 case DW_TAG_inlined_subroutine
:
21342 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21344 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21345 SYMBOL_INLINED (sym
) = 1;
21346 list_to_add
= cu
->list_in_scope
;
21348 case DW_TAG_template_value_param
:
21350 /* Fall through. */
21351 case DW_TAG_constant
:
21352 case DW_TAG_variable
:
21353 case DW_TAG_member
:
21354 /* Compilation with minimal debug info may result in
21355 variables with missing type entries. Change the
21356 misleading `void' type to something sensible. */
21357 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
21358 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21360 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21361 /* In the case of DW_TAG_member, we should only be called for
21362 static const members. */
21363 if (die
->tag
== DW_TAG_member
)
21365 /* dwarf2_add_field uses die_is_declaration,
21366 so we do the same. */
21367 gdb_assert (die_is_declaration (die
, cu
));
21372 dwarf2_const_value (attr
, sym
, cu
);
21373 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21376 if (attr2
&& (DW_UNSND (attr2
) != 0))
21377 list_to_add
= &global_symbols
;
21379 list_to_add
= cu
->list_in_scope
;
21383 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21386 var_decode_location (attr
, sym
, cu
);
21387 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21389 /* Fortran explicitly imports any global symbols to the local
21390 scope by DW_TAG_common_block. */
21391 if (cu
->language
== language_fortran
&& die
->parent
21392 && die
->parent
->tag
== DW_TAG_common_block
)
21395 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21396 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21397 && !dwarf2_per_objfile
->has_section_at_zero
)
21399 /* When a static variable is eliminated by the linker,
21400 the corresponding debug information is not stripped
21401 out, but the variable address is set to null;
21402 do not add such variables into symbol table. */
21404 else if (attr2
&& (DW_UNSND (attr2
) != 0))
21406 /* Workaround gfortran PR debug/40040 - it uses
21407 DW_AT_location for variables in -fPIC libraries which may
21408 get overriden by other libraries/executable and get
21409 a different address. Resolve it by the minimal symbol
21410 which may come from inferior's executable using copy
21411 relocation. Make this workaround only for gfortran as for
21412 other compilers GDB cannot guess the minimal symbol
21413 Fortran mangling kind. */
21414 if (cu
->language
== language_fortran
&& die
->parent
21415 && die
->parent
->tag
== DW_TAG_module
21417 && startswith (cu
->producer
, "GNU Fortran"))
21418 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21420 /* A variable with DW_AT_external is never static,
21421 but it may be block-scoped. */
21422 list_to_add
= (cu
->list_in_scope
== &file_symbols
21423 ? &global_symbols
: cu
->list_in_scope
);
21426 list_to_add
= cu
->list_in_scope
;
21430 /* We do not know the address of this symbol.
21431 If it is an external symbol and we have type information
21432 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21433 The address of the variable will then be determined from
21434 the minimal symbol table whenever the variable is
21436 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21438 /* Fortran explicitly imports any global symbols to the local
21439 scope by DW_TAG_common_block. */
21440 if (cu
->language
== language_fortran
&& die
->parent
21441 && die
->parent
->tag
== DW_TAG_common_block
)
21443 /* SYMBOL_CLASS doesn't matter here because
21444 read_common_block is going to reset it. */
21446 list_to_add
= cu
->list_in_scope
;
21448 else if (attr2
&& (DW_UNSND (attr2
) != 0)
21449 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21451 /* A variable with DW_AT_external is never static, but it
21452 may be block-scoped. */
21453 list_to_add
= (cu
->list_in_scope
== &file_symbols
21454 ? &global_symbols
: cu
->list_in_scope
);
21456 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21458 else if (!die_is_declaration (die
, cu
))
21460 /* Use the default LOC_OPTIMIZED_OUT class. */
21461 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21463 list_to_add
= cu
->list_in_scope
;
21467 case DW_TAG_formal_parameter
:
21468 /* If we are inside a function, mark this as an argument. If
21469 not, we might be looking at an argument to an inlined function
21470 when we do not have enough information to show inlined frames;
21471 pretend it's a local variable in that case so that the user can
21473 if (context_stack_depth
> 0
21474 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
21475 SYMBOL_IS_ARGUMENT (sym
) = 1;
21476 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21479 var_decode_location (attr
, sym
, cu
);
21481 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21484 dwarf2_const_value (attr
, sym
, cu
);
21487 list_to_add
= cu
->list_in_scope
;
21489 case DW_TAG_unspecified_parameters
:
21490 /* From varargs functions; gdb doesn't seem to have any
21491 interest in this information, so just ignore it for now.
21494 case DW_TAG_template_type_param
:
21496 /* Fall through. */
21497 case DW_TAG_class_type
:
21498 case DW_TAG_interface_type
:
21499 case DW_TAG_structure_type
:
21500 case DW_TAG_union_type
:
21501 case DW_TAG_set_type
:
21502 case DW_TAG_enumeration_type
:
21503 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21504 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21507 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21508 really ever be static objects: otherwise, if you try
21509 to, say, break of a class's method and you're in a file
21510 which doesn't mention that class, it won't work unless
21511 the check for all static symbols in lookup_symbol_aux
21512 saves you. See the OtherFileClass tests in
21513 gdb.c++/namespace.exp. */
21517 list_to_add
= (cu
->list_in_scope
== &file_symbols
21518 && cu
->language
== language_cplus
21519 ? &global_symbols
: cu
->list_in_scope
);
21521 /* The semantics of C++ state that "struct foo {
21522 ... }" also defines a typedef for "foo". */
21523 if (cu
->language
== language_cplus
21524 || cu
->language
== language_ada
21525 || cu
->language
== language_d
21526 || cu
->language
== language_rust
)
21528 /* The symbol's name is already allocated along
21529 with this objfile, so we don't need to
21530 duplicate it for the type. */
21531 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
21532 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
21537 case DW_TAG_typedef
:
21538 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21539 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21540 list_to_add
= cu
->list_in_scope
;
21542 case DW_TAG_base_type
:
21543 case DW_TAG_subrange_type
:
21544 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21545 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21546 list_to_add
= cu
->list_in_scope
;
21548 case DW_TAG_enumerator
:
21549 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21552 dwarf2_const_value (attr
, sym
, cu
);
21555 /* NOTE: carlton/2003-11-10: See comment above in the
21556 DW_TAG_class_type, etc. block. */
21558 list_to_add
= (cu
->list_in_scope
== &file_symbols
21559 && cu
->language
== language_cplus
21560 ? &global_symbols
: cu
->list_in_scope
);
21563 case DW_TAG_imported_declaration
:
21564 case DW_TAG_namespace
:
21565 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21566 list_to_add
= &global_symbols
;
21568 case DW_TAG_module
:
21569 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21570 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21571 list_to_add
= &global_symbols
;
21573 case DW_TAG_common_block
:
21574 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21575 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21576 add_symbol_to_list (sym
, cu
->list_in_scope
);
21579 /* Not a tag we recognize. Hopefully we aren't processing
21580 trash data, but since we must specifically ignore things
21581 we don't recognize, there is nothing else we should do at
21583 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
21584 dwarf_tag_name (die
->tag
));
21590 sym
->hash_next
= objfile
->template_symbols
;
21591 objfile
->template_symbols
= sym
;
21592 list_to_add
= NULL
;
21595 if (list_to_add
!= NULL
)
21596 add_symbol_to_list (sym
, list_to_add
);
21598 /* For the benefit of old versions of GCC, check for anonymous
21599 namespaces based on the demangled name. */
21600 if (!cu
->processing_has_namespace_info
21601 && cu
->language
== language_cplus
)
21602 cp_scan_for_anonymous_namespaces (sym
, objfile
);
21607 /* Given an attr with a DW_FORM_dataN value in host byte order,
21608 zero-extend it as appropriate for the symbol's type. The DWARF
21609 standard (v4) is not entirely clear about the meaning of using
21610 DW_FORM_dataN for a constant with a signed type, where the type is
21611 wider than the data. The conclusion of a discussion on the DWARF
21612 list was that this is unspecified. We choose to always zero-extend
21613 because that is the interpretation long in use by GCC. */
21616 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21617 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21619 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21620 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21621 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21622 LONGEST l
= DW_UNSND (attr
);
21624 if (bits
< sizeof (*value
) * 8)
21626 l
&= ((LONGEST
) 1 << bits
) - 1;
21629 else if (bits
== sizeof (*value
) * 8)
21633 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21634 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21641 /* Read a constant value from an attribute. Either set *VALUE, or if
21642 the value does not fit in *VALUE, set *BYTES - either already
21643 allocated on the objfile obstack, or newly allocated on OBSTACK,
21644 or, set *BATON, if we translated the constant to a location
21648 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21649 const char *name
, struct obstack
*obstack
,
21650 struct dwarf2_cu
*cu
,
21651 LONGEST
*value
, const gdb_byte
**bytes
,
21652 struct dwarf2_locexpr_baton
**baton
)
21654 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21655 struct comp_unit_head
*cu_header
= &cu
->header
;
21656 struct dwarf_block
*blk
;
21657 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21658 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21664 switch (attr
->form
)
21667 case DW_FORM_GNU_addr_index
:
21671 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21672 dwarf2_const_value_length_mismatch_complaint (name
,
21673 cu_header
->addr_size
,
21674 TYPE_LENGTH (type
));
21675 /* Symbols of this form are reasonably rare, so we just
21676 piggyback on the existing location code rather than writing
21677 a new implementation of symbol_computed_ops. */
21678 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21679 (*baton
)->per_cu
= cu
->per_cu
;
21680 gdb_assert ((*baton
)->per_cu
);
21682 (*baton
)->size
= 2 + cu_header
->addr_size
;
21683 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
21684 (*baton
)->data
= data
;
21686 data
[0] = DW_OP_addr
;
21687 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
21688 byte_order
, DW_ADDR (attr
));
21689 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
21692 case DW_FORM_string
:
21694 case DW_FORM_GNU_str_index
:
21695 case DW_FORM_GNU_strp_alt
:
21696 /* DW_STRING is already allocated on the objfile obstack, point
21698 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
21700 case DW_FORM_block1
:
21701 case DW_FORM_block2
:
21702 case DW_FORM_block4
:
21703 case DW_FORM_block
:
21704 case DW_FORM_exprloc
:
21705 case DW_FORM_data16
:
21706 blk
= DW_BLOCK (attr
);
21707 if (TYPE_LENGTH (type
) != blk
->size
)
21708 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
21709 TYPE_LENGTH (type
));
21710 *bytes
= blk
->data
;
21713 /* The DW_AT_const_value attributes are supposed to carry the
21714 symbol's value "represented as it would be on the target
21715 architecture." By the time we get here, it's already been
21716 converted to host endianness, so we just need to sign- or
21717 zero-extend it as appropriate. */
21718 case DW_FORM_data1
:
21719 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21721 case DW_FORM_data2
:
21722 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21724 case DW_FORM_data4
:
21725 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21727 case DW_FORM_data8
:
21728 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21731 case DW_FORM_sdata
:
21732 case DW_FORM_implicit_const
:
21733 *value
= DW_SND (attr
);
21736 case DW_FORM_udata
:
21737 *value
= DW_UNSND (attr
);
21741 complaint (&symfile_complaints
,
21742 _("unsupported const value attribute form: '%s'"),
21743 dwarf_form_name (attr
->form
));
21750 /* Copy constant value from an attribute to a symbol. */
21753 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21754 struct dwarf2_cu
*cu
)
21756 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21758 const gdb_byte
*bytes
;
21759 struct dwarf2_locexpr_baton
*baton
;
21761 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21762 SYMBOL_PRINT_NAME (sym
),
21763 &objfile
->objfile_obstack
, cu
,
21764 &value
, &bytes
, &baton
);
21768 SYMBOL_LOCATION_BATON (sym
) = baton
;
21769 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21771 else if (bytes
!= NULL
)
21773 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21774 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21778 SYMBOL_VALUE (sym
) = value
;
21779 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21783 /* Return the type of the die in question using its DW_AT_type attribute. */
21785 static struct type
*
21786 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21788 struct attribute
*type_attr
;
21790 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21793 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21794 /* A missing DW_AT_type represents a void type. */
21795 return objfile_type (objfile
)->builtin_void
;
21798 return lookup_die_type (die
, type_attr
, cu
);
21801 /* True iff CU's producer generates GNAT Ada auxiliary information
21802 that allows to find parallel types through that information instead
21803 of having to do expensive parallel lookups by type name. */
21806 need_gnat_info (struct dwarf2_cu
*cu
)
21808 /* Assume that the Ada compiler was GNAT, which always produces
21809 the auxiliary information. */
21810 return (cu
->language
== language_ada
);
21813 /* Return the auxiliary type of the die in question using its
21814 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21815 attribute is not present. */
21817 static struct type
*
21818 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21820 struct attribute
*type_attr
;
21822 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21826 return lookup_die_type (die
, type_attr
, cu
);
21829 /* If DIE has a descriptive_type attribute, then set the TYPE's
21830 descriptive type accordingly. */
21833 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21834 struct dwarf2_cu
*cu
)
21836 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21838 if (descriptive_type
)
21840 ALLOCATE_GNAT_AUX_TYPE (type
);
21841 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21845 /* Return the containing type of the die in question using its
21846 DW_AT_containing_type attribute. */
21848 static struct type
*
21849 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21851 struct attribute
*type_attr
;
21852 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21854 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21856 error (_("Dwarf Error: Problem turning containing type into gdb type "
21857 "[in module %s]"), objfile_name (objfile
));
21859 return lookup_die_type (die
, type_attr
, cu
);
21862 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21864 static struct type
*
21865 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21867 struct dwarf2_per_objfile
*dwarf2_per_objfile
21868 = cu
->per_cu
->dwarf2_per_objfile
;
21869 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21870 char *message
, *saved
;
21872 message
= xstrprintf (_("<unknown type in %s, CU %s, DIE %s>"),
21873 objfile_name (objfile
),
21874 sect_offset_str (cu
->header
.sect_off
),
21875 sect_offset_str (die
->sect_off
));
21876 saved
= (char *) obstack_copy0 (&objfile
->objfile_obstack
,
21877 message
, strlen (message
));
21880 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21883 /* Look up the type of DIE in CU using its type attribute ATTR.
21884 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21885 DW_AT_containing_type.
21886 If there is no type substitute an error marker. */
21888 static struct type
*
21889 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21890 struct dwarf2_cu
*cu
)
21892 struct dwarf2_per_objfile
*dwarf2_per_objfile
21893 = cu
->per_cu
->dwarf2_per_objfile
;
21894 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21895 struct type
*this_type
;
21897 gdb_assert (attr
->name
== DW_AT_type
21898 || attr
->name
== DW_AT_GNAT_descriptive_type
21899 || attr
->name
== DW_AT_containing_type
);
21901 /* First see if we have it cached. */
21903 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21905 struct dwarf2_per_cu_data
*per_cu
;
21906 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21908 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
21909 dwarf2_per_objfile
);
21910 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
21912 else if (attr_form_is_ref (attr
))
21914 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21916 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
21918 else if (attr
->form
== DW_FORM_ref_sig8
)
21920 ULONGEST signature
= DW_SIGNATURE (attr
);
21922 return get_signatured_type (die
, signature
, cu
);
21926 complaint (&symfile_complaints
,
21927 _("Dwarf Error: Bad type attribute %s in DIE"
21928 " at %s [in module %s]"),
21929 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
21930 objfile_name (objfile
));
21931 return build_error_marker_type (cu
, die
);
21934 /* If not cached we need to read it in. */
21936 if (this_type
== NULL
)
21938 struct die_info
*type_die
= NULL
;
21939 struct dwarf2_cu
*type_cu
= cu
;
21941 if (attr_form_is_ref (attr
))
21942 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21943 if (type_die
== NULL
)
21944 return build_error_marker_type (cu
, die
);
21945 /* If we find the type now, it's probably because the type came
21946 from an inter-CU reference and the type's CU got expanded before
21948 this_type
= read_type_die (type_die
, type_cu
);
21951 /* If we still don't have a type use an error marker. */
21953 if (this_type
== NULL
)
21954 return build_error_marker_type (cu
, die
);
21959 /* Return the type in DIE, CU.
21960 Returns NULL for invalid types.
21962 This first does a lookup in die_type_hash,
21963 and only reads the die in if necessary.
21965 NOTE: This can be called when reading in partial or full symbols. */
21967 static struct type
*
21968 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21970 struct type
*this_type
;
21972 this_type
= get_die_type (die
, cu
);
21976 return read_type_die_1 (die
, cu
);
21979 /* Read the type in DIE, CU.
21980 Returns NULL for invalid types. */
21982 static struct type
*
21983 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
21985 struct type
*this_type
= NULL
;
21989 case DW_TAG_class_type
:
21990 case DW_TAG_interface_type
:
21991 case DW_TAG_structure_type
:
21992 case DW_TAG_union_type
:
21993 this_type
= read_structure_type (die
, cu
);
21995 case DW_TAG_enumeration_type
:
21996 this_type
= read_enumeration_type (die
, cu
);
21998 case DW_TAG_subprogram
:
21999 case DW_TAG_subroutine_type
:
22000 case DW_TAG_inlined_subroutine
:
22001 this_type
= read_subroutine_type (die
, cu
);
22003 case DW_TAG_array_type
:
22004 this_type
= read_array_type (die
, cu
);
22006 case DW_TAG_set_type
:
22007 this_type
= read_set_type (die
, cu
);
22009 case DW_TAG_pointer_type
:
22010 this_type
= read_tag_pointer_type (die
, cu
);
22012 case DW_TAG_ptr_to_member_type
:
22013 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22015 case DW_TAG_reference_type
:
22016 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22018 case DW_TAG_rvalue_reference_type
:
22019 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22021 case DW_TAG_const_type
:
22022 this_type
= read_tag_const_type (die
, cu
);
22024 case DW_TAG_volatile_type
:
22025 this_type
= read_tag_volatile_type (die
, cu
);
22027 case DW_TAG_restrict_type
:
22028 this_type
= read_tag_restrict_type (die
, cu
);
22030 case DW_TAG_string_type
:
22031 this_type
= read_tag_string_type (die
, cu
);
22033 case DW_TAG_typedef
:
22034 this_type
= read_typedef (die
, cu
);
22036 case DW_TAG_subrange_type
:
22037 this_type
= read_subrange_type (die
, cu
);
22039 case DW_TAG_base_type
:
22040 this_type
= read_base_type (die
, cu
);
22042 case DW_TAG_unspecified_type
:
22043 this_type
= read_unspecified_type (die
, cu
);
22045 case DW_TAG_namespace
:
22046 this_type
= read_namespace_type (die
, cu
);
22048 case DW_TAG_module
:
22049 this_type
= read_module_type (die
, cu
);
22051 case DW_TAG_atomic_type
:
22052 this_type
= read_tag_atomic_type (die
, cu
);
22055 complaint (&symfile_complaints
,
22056 _("unexpected tag in read_type_die: '%s'"),
22057 dwarf_tag_name (die
->tag
));
22064 /* See if we can figure out if the class lives in a namespace. We do
22065 this by looking for a member function; its demangled name will
22066 contain namespace info, if there is any.
22067 Return the computed name or NULL.
22068 Space for the result is allocated on the objfile's obstack.
22069 This is the full-die version of guess_partial_die_structure_name.
22070 In this case we know DIE has no useful parent. */
22073 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22075 struct die_info
*spec_die
;
22076 struct dwarf2_cu
*spec_cu
;
22077 struct die_info
*child
;
22078 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22081 spec_die
= die_specification (die
, &spec_cu
);
22082 if (spec_die
!= NULL
)
22088 for (child
= die
->child
;
22090 child
= child
->sibling
)
22092 if (child
->tag
== DW_TAG_subprogram
)
22094 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22096 if (linkage_name
!= NULL
)
22099 = language_class_name_from_physname (cu
->language_defn
,
22103 if (actual_name
!= NULL
)
22105 const char *die_name
= dwarf2_name (die
, cu
);
22107 if (die_name
!= NULL
22108 && strcmp (die_name
, actual_name
) != 0)
22110 /* Strip off the class name from the full name.
22111 We want the prefix. */
22112 int die_name_len
= strlen (die_name
);
22113 int actual_name_len
= strlen (actual_name
);
22115 /* Test for '::' as a sanity check. */
22116 if (actual_name_len
> die_name_len
+ 2
22117 && actual_name
[actual_name_len
22118 - die_name_len
- 1] == ':')
22119 name
= (char *) obstack_copy0 (
22120 &objfile
->per_bfd
->storage_obstack
,
22121 actual_name
, actual_name_len
- die_name_len
- 2);
22124 xfree (actual_name
);
22133 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22134 prefix part in such case. See
22135 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22137 static const char *
22138 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22140 struct attribute
*attr
;
22143 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22144 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22147 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22150 attr
= dw2_linkage_name_attr (die
, cu
);
22151 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22154 /* dwarf2_name had to be already called. */
22155 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
22157 /* Strip the base name, keep any leading namespaces/classes. */
22158 base
= strrchr (DW_STRING (attr
), ':');
22159 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
22162 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22163 return (char *) obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
22165 &base
[-1] - DW_STRING (attr
));
22168 /* Return the name of the namespace/class that DIE is defined within,
22169 or "" if we can't tell. The caller should not xfree the result.
22171 For example, if we're within the method foo() in the following
22181 then determine_prefix on foo's die will return "N::C". */
22183 static const char *
22184 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22186 struct dwarf2_per_objfile
*dwarf2_per_objfile
22187 = cu
->per_cu
->dwarf2_per_objfile
;
22188 struct die_info
*parent
, *spec_die
;
22189 struct dwarf2_cu
*spec_cu
;
22190 struct type
*parent_type
;
22191 const char *retval
;
22193 if (cu
->language
!= language_cplus
22194 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22195 && cu
->language
!= language_rust
)
22198 retval
= anonymous_struct_prefix (die
, cu
);
22202 /* We have to be careful in the presence of DW_AT_specification.
22203 For example, with GCC 3.4, given the code
22207 // Definition of N::foo.
22211 then we'll have a tree of DIEs like this:
22213 1: DW_TAG_compile_unit
22214 2: DW_TAG_namespace // N
22215 3: DW_TAG_subprogram // declaration of N::foo
22216 4: DW_TAG_subprogram // definition of N::foo
22217 DW_AT_specification // refers to die #3
22219 Thus, when processing die #4, we have to pretend that we're in
22220 the context of its DW_AT_specification, namely the contex of die
22223 spec_die
= die_specification (die
, &spec_cu
);
22224 if (spec_die
== NULL
)
22225 parent
= die
->parent
;
22228 parent
= spec_die
->parent
;
22232 if (parent
== NULL
)
22234 else if (parent
->building_fullname
)
22237 const char *parent_name
;
22239 /* It has been seen on RealView 2.2 built binaries,
22240 DW_TAG_template_type_param types actually _defined_ as
22241 children of the parent class:
22244 template class <class Enum> Class{};
22245 Class<enum E> class_e;
22247 1: DW_TAG_class_type (Class)
22248 2: DW_TAG_enumeration_type (E)
22249 3: DW_TAG_enumerator (enum1:0)
22250 3: DW_TAG_enumerator (enum2:1)
22252 2: DW_TAG_template_type_param
22253 DW_AT_type DW_FORM_ref_udata (E)
22255 Besides being broken debug info, it can put GDB into an
22256 infinite loop. Consider:
22258 When we're building the full name for Class<E>, we'll start
22259 at Class, and go look over its template type parameters,
22260 finding E. We'll then try to build the full name of E, and
22261 reach here. We're now trying to build the full name of E,
22262 and look over the parent DIE for containing scope. In the
22263 broken case, if we followed the parent DIE of E, we'd again
22264 find Class, and once again go look at its template type
22265 arguments, etc., etc. Simply don't consider such parent die
22266 as source-level parent of this die (it can't be, the language
22267 doesn't allow it), and break the loop here. */
22268 name
= dwarf2_name (die
, cu
);
22269 parent_name
= dwarf2_name (parent
, cu
);
22270 complaint (&symfile_complaints
,
22271 _("template param type '%s' defined within parent '%s'"),
22272 name
? name
: "<unknown>",
22273 parent_name
? parent_name
: "<unknown>");
22277 switch (parent
->tag
)
22279 case DW_TAG_namespace
:
22280 parent_type
= read_type_die (parent
, cu
);
22281 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22282 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22283 Work around this problem here. */
22284 if (cu
->language
== language_cplus
22285 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
22287 /* We give a name to even anonymous namespaces. */
22288 return TYPE_TAG_NAME (parent_type
);
22289 case DW_TAG_class_type
:
22290 case DW_TAG_interface_type
:
22291 case DW_TAG_structure_type
:
22292 case DW_TAG_union_type
:
22293 case DW_TAG_module
:
22294 parent_type
= read_type_die (parent
, cu
);
22295 if (TYPE_TAG_NAME (parent_type
) != NULL
)
22296 return TYPE_TAG_NAME (parent_type
);
22298 /* An anonymous structure is only allowed non-static data
22299 members; no typedefs, no member functions, et cetera.
22300 So it does not need a prefix. */
22302 case DW_TAG_compile_unit
:
22303 case DW_TAG_partial_unit
:
22304 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22305 if (cu
->language
== language_cplus
22306 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
22307 && die
->child
!= NULL
22308 && (die
->tag
== DW_TAG_class_type
22309 || die
->tag
== DW_TAG_structure_type
22310 || die
->tag
== DW_TAG_union_type
))
22312 char *name
= guess_full_die_structure_name (die
, cu
);
22317 case DW_TAG_enumeration_type
:
22318 parent_type
= read_type_die (parent
, cu
);
22319 if (TYPE_DECLARED_CLASS (parent_type
))
22321 if (TYPE_TAG_NAME (parent_type
) != NULL
)
22322 return TYPE_TAG_NAME (parent_type
);
22325 /* Fall through. */
22327 return determine_prefix (parent
, cu
);
22331 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22332 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22333 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22334 an obconcat, otherwise allocate storage for the result. The CU argument is
22335 used to determine the language and hence, the appropriate separator. */
22337 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22340 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22341 int physname
, struct dwarf2_cu
*cu
)
22343 const char *lead
= "";
22346 if (suffix
== NULL
|| suffix
[0] == '\0'
22347 || prefix
== NULL
|| prefix
[0] == '\0')
22349 else if (cu
->language
== language_d
)
22351 /* For D, the 'main' function could be defined in any module, but it
22352 should never be prefixed. */
22353 if (strcmp (suffix
, "D main") == 0)
22361 else if (cu
->language
== language_fortran
&& physname
)
22363 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22364 DW_AT_MIPS_linkage_name is preferred and used instead. */
22372 if (prefix
== NULL
)
22374 if (suffix
== NULL
)
22381 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22383 strcpy (retval
, lead
);
22384 strcat (retval
, prefix
);
22385 strcat (retval
, sep
);
22386 strcat (retval
, suffix
);
22391 /* We have an obstack. */
22392 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22396 /* Return sibling of die, NULL if no sibling. */
22398 static struct die_info
*
22399 sibling_die (struct die_info
*die
)
22401 return die
->sibling
;
22404 /* Get name of a die, return NULL if not found. */
22406 static const char *
22407 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22408 struct obstack
*obstack
)
22410 if (name
&& cu
->language
== language_cplus
)
22412 std::string canon_name
= cp_canonicalize_string (name
);
22414 if (!canon_name
.empty ())
22416 if (canon_name
!= name
)
22417 name
= (const char *) obstack_copy0 (obstack
,
22418 canon_name
.c_str (),
22419 canon_name
.length ());
22426 /* Get name of a die, return NULL if not found.
22427 Anonymous namespaces are converted to their magic string. */
22429 static const char *
22430 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22432 struct attribute
*attr
;
22433 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22435 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22436 if ((!attr
|| !DW_STRING (attr
))
22437 && die
->tag
!= DW_TAG_namespace
22438 && die
->tag
!= DW_TAG_class_type
22439 && die
->tag
!= DW_TAG_interface_type
22440 && die
->tag
!= DW_TAG_structure_type
22441 && die
->tag
!= DW_TAG_union_type
)
22446 case DW_TAG_compile_unit
:
22447 case DW_TAG_partial_unit
:
22448 /* Compilation units have a DW_AT_name that is a filename, not
22449 a source language identifier. */
22450 case DW_TAG_enumeration_type
:
22451 case DW_TAG_enumerator
:
22452 /* These tags always have simple identifiers already; no need
22453 to canonicalize them. */
22454 return DW_STRING (attr
);
22456 case DW_TAG_namespace
:
22457 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
22458 return DW_STRING (attr
);
22459 return CP_ANONYMOUS_NAMESPACE_STR
;
22461 case DW_TAG_class_type
:
22462 case DW_TAG_interface_type
:
22463 case DW_TAG_structure_type
:
22464 case DW_TAG_union_type
:
22465 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22466 structures or unions. These were of the form "._%d" in GCC 4.1,
22467 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22468 and GCC 4.4. We work around this problem by ignoring these. */
22469 if (attr
&& DW_STRING (attr
)
22470 && (startswith (DW_STRING (attr
), "._")
22471 || startswith (DW_STRING (attr
), "<anonymous")))
22474 /* GCC might emit a nameless typedef that has a linkage name. See
22475 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22476 if (!attr
|| DW_STRING (attr
) == NULL
)
22478 char *demangled
= NULL
;
22480 attr
= dw2_linkage_name_attr (die
, cu
);
22481 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22484 /* Avoid demangling DW_STRING (attr) the second time on a second
22485 call for the same DIE. */
22486 if (!DW_STRING_IS_CANONICAL (attr
))
22487 demangled
= gdb_demangle (DW_STRING (attr
), DMGL_TYPES
);
22493 /* FIXME: we already did this for the partial symbol... */
22496 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
22497 demangled
, strlen (demangled
)));
22498 DW_STRING_IS_CANONICAL (attr
) = 1;
22501 /* Strip any leading namespaces/classes, keep only the base name.
22502 DW_AT_name for named DIEs does not contain the prefixes. */
22503 base
= strrchr (DW_STRING (attr
), ':');
22504 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
22507 return DW_STRING (attr
);
22516 if (!DW_STRING_IS_CANONICAL (attr
))
22519 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
22520 &objfile
->per_bfd
->storage_obstack
);
22521 DW_STRING_IS_CANONICAL (attr
) = 1;
22523 return DW_STRING (attr
);
22526 /* Return the die that this die in an extension of, or NULL if there
22527 is none. *EXT_CU is the CU containing DIE on input, and the CU
22528 containing the return value on output. */
22530 static struct die_info
*
22531 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22533 struct attribute
*attr
;
22535 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22539 return follow_die_ref (die
, attr
, ext_cu
);
22542 /* Convert a DIE tag into its string name. */
22544 static const char *
22545 dwarf_tag_name (unsigned tag
)
22547 const char *name
= get_DW_TAG_name (tag
);
22550 return "DW_TAG_<unknown>";
22555 /* Convert a DWARF attribute code into its string name. */
22557 static const char *
22558 dwarf_attr_name (unsigned attr
)
22562 #ifdef MIPS /* collides with DW_AT_HP_block_index */
22563 if (attr
== DW_AT_MIPS_fde
)
22564 return "DW_AT_MIPS_fde";
22566 if (attr
== DW_AT_HP_block_index
)
22567 return "DW_AT_HP_block_index";
22570 name
= get_DW_AT_name (attr
);
22573 return "DW_AT_<unknown>";
22578 /* Convert a DWARF value form code into its string name. */
22580 static const char *
22581 dwarf_form_name (unsigned form
)
22583 const char *name
= get_DW_FORM_name (form
);
22586 return "DW_FORM_<unknown>";
22591 static const char *
22592 dwarf_bool_name (unsigned mybool
)
22600 /* Convert a DWARF type code into its string name. */
22602 static const char *
22603 dwarf_type_encoding_name (unsigned enc
)
22605 const char *name
= get_DW_ATE_name (enc
);
22608 return "DW_ATE_<unknown>";
22614 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22618 print_spaces (indent
, f
);
22619 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
22620 dwarf_tag_name (die
->tag
), die
->abbrev
,
22621 sect_offset_str (die
->sect_off
));
22623 if (die
->parent
!= NULL
)
22625 print_spaces (indent
, f
);
22626 fprintf_unfiltered (f
, " parent at offset: %s\n",
22627 sect_offset_str (die
->parent
->sect_off
));
22630 print_spaces (indent
, f
);
22631 fprintf_unfiltered (f
, " has children: %s\n",
22632 dwarf_bool_name (die
->child
!= NULL
));
22634 print_spaces (indent
, f
);
22635 fprintf_unfiltered (f
, " attributes:\n");
22637 for (i
= 0; i
< die
->num_attrs
; ++i
)
22639 print_spaces (indent
, f
);
22640 fprintf_unfiltered (f
, " %s (%s) ",
22641 dwarf_attr_name (die
->attrs
[i
].name
),
22642 dwarf_form_name (die
->attrs
[i
].form
));
22644 switch (die
->attrs
[i
].form
)
22647 case DW_FORM_GNU_addr_index
:
22648 fprintf_unfiltered (f
, "address: ");
22649 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
22651 case DW_FORM_block2
:
22652 case DW_FORM_block4
:
22653 case DW_FORM_block
:
22654 case DW_FORM_block1
:
22655 fprintf_unfiltered (f
, "block: size %s",
22656 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22658 case DW_FORM_exprloc
:
22659 fprintf_unfiltered (f
, "expression: size %s",
22660 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22662 case DW_FORM_data16
:
22663 fprintf_unfiltered (f
, "constant of 16 bytes");
22665 case DW_FORM_ref_addr
:
22666 fprintf_unfiltered (f
, "ref address: ");
22667 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22669 case DW_FORM_GNU_ref_alt
:
22670 fprintf_unfiltered (f
, "alt ref address: ");
22671 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22677 case DW_FORM_ref_udata
:
22678 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
22679 (long) (DW_UNSND (&die
->attrs
[i
])));
22681 case DW_FORM_data1
:
22682 case DW_FORM_data2
:
22683 case DW_FORM_data4
:
22684 case DW_FORM_data8
:
22685 case DW_FORM_udata
:
22686 case DW_FORM_sdata
:
22687 fprintf_unfiltered (f
, "constant: %s",
22688 pulongest (DW_UNSND (&die
->attrs
[i
])));
22690 case DW_FORM_sec_offset
:
22691 fprintf_unfiltered (f
, "section offset: %s",
22692 pulongest (DW_UNSND (&die
->attrs
[i
])));
22694 case DW_FORM_ref_sig8
:
22695 fprintf_unfiltered (f
, "signature: %s",
22696 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
22698 case DW_FORM_string
:
22700 case DW_FORM_line_strp
:
22701 case DW_FORM_GNU_str_index
:
22702 case DW_FORM_GNU_strp_alt
:
22703 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22704 DW_STRING (&die
->attrs
[i
])
22705 ? DW_STRING (&die
->attrs
[i
]) : "",
22706 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
22709 if (DW_UNSND (&die
->attrs
[i
]))
22710 fprintf_unfiltered (f
, "flag: TRUE");
22712 fprintf_unfiltered (f
, "flag: FALSE");
22714 case DW_FORM_flag_present
:
22715 fprintf_unfiltered (f
, "flag: TRUE");
22717 case DW_FORM_indirect
:
22718 /* The reader will have reduced the indirect form to
22719 the "base form" so this form should not occur. */
22720 fprintf_unfiltered (f
,
22721 "unexpected attribute form: DW_FORM_indirect");
22723 case DW_FORM_implicit_const
:
22724 fprintf_unfiltered (f
, "constant: %s",
22725 plongest (DW_SND (&die
->attrs
[i
])));
22728 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22729 die
->attrs
[i
].form
);
22732 fprintf_unfiltered (f
, "\n");
22737 dump_die_for_error (struct die_info
*die
)
22739 dump_die_shallow (gdb_stderr
, 0, die
);
22743 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22745 int indent
= level
* 4;
22747 gdb_assert (die
!= NULL
);
22749 if (level
>= max_level
)
22752 dump_die_shallow (f
, indent
, die
);
22754 if (die
->child
!= NULL
)
22756 print_spaces (indent
, f
);
22757 fprintf_unfiltered (f
, " Children:");
22758 if (level
+ 1 < max_level
)
22760 fprintf_unfiltered (f
, "\n");
22761 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22765 fprintf_unfiltered (f
,
22766 " [not printed, max nesting level reached]\n");
22770 if (die
->sibling
!= NULL
&& level
> 0)
22772 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22776 /* This is called from the pdie macro in gdbinit.in.
22777 It's not static so gcc will keep a copy callable from gdb. */
22780 dump_die (struct die_info
*die
, int max_level
)
22782 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22786 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22790 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22791 to_underlying (die
->sect_off
),
22797 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
22801 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
22803 if (attr_form_is_ref (attr
))
22804 return (sect_offset
) DW_UNSND (attr
);
22806 complaint (&symfile_complaints
,
22807 _("unsupported die ref attribute form: '%s'"),
22808 dwarf_form_name (attr
->form
));
22812 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
22813 * the value held by the attribute is not constant. */
22816 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
22818 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
22819 return DW_SND (attr
);
22820 else if (attr
->form
== DW_FORM_udata
22821 || attr
->form
== DW_FORM_data1
22822 || attr
->form
== DW_FORM_data2
22823 || attr
->form
== DW_FORM_data4
22824 || attr
->form
== DW_FORM_data8
)
22825 return DW_UNSND (attr
);
22828 /* For DW_FORM_data16 see attr_form_is_constant. */
22829 complaint (&symfile_complaints
,
22830 _("Attribute value is not a constant (%s)"),
22831 dwarf_form_name (attr
->form
));
22832 return default_value
;
22836 /* Follow reference or signature attribute ATTR of SRC_DIE.
22837 On entry *REF_CU is the CU of SRC_DIE.
22838 On exit *REF_CU is the CU of the result. */
22840 static struct die_info
*
22841 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22842 struct dwarf2_cu
**ref_cu
)
22844 struct die_info
*die
;
22846 if (attr_form_is_ref (attr
))
22847 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22848 else if (attr
->form
== DW_FORM_ref_sig8
)
22849 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22852 dump_die_for_error (src_die
);
22853 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22854 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22860 /* Follow reference OFFSET.
22861 On entry *REF_CU is the CU of the source die referencing OFFSET.
22862 On exit *REF_CU is the CU of the result.
22863 Returns NULL if OFFSET is invalid. */
22865 static struct die_info
*
22866 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22867 struct dwarf2_cu
**ref_cu
)
22869 struct die_info temp_die
;
22870 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22871 struct dwarf2_per_objfile
*dwarf2_per_objfile
22872 = cu
->per_cu
->dwarf2_per_objfile
;
22874 gdb_assert (cu
->per_cu
!= NULL
);
22878 if (cu
->per_cu
->is_debug_types
)
22880 /* .debug_types CUs cannot reference anything outside their CU.
22881 If they need to, they have to reference a signatured type via
22882 DW_FORM_ref_sig8. */
22883 if (!offset_in_cu_p (&cu
->header
, sect_off
))
22886 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22887 || !offset_in_cu_p (&cu
->header
, sect_off
))
22889 struct dwarf2_per_cu_data
*per_cu
;
22891 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22892 dwarf2_per_objfile
);
22894 /* If necessary, add it to the queue and load its DIEs. */
22895 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
22896 load_full_comp_unit (per_cu
, false, cu
->language
);
22898 target_cu
= per_cu
->cu
;
22900 else if (cu
->dies
== NULL
)
22902 /* We're loading full DIEs during partial symbol reading. */
22903 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
22904 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
22907 *ref_cu
= target_cu
;
22908 temp_die
.sect_off
= sect_off
;
22909 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22911 to_underlying (sect_off
));
22914 /* Follow reference attribute ATTR of SRC_DIE.
22915 On entry *REF_CU is the CU of SRC_DIE.
22916 On exit *REF_CU is the CU of the result. */
22918 static struct die_info
*
22919 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22920 struct dwarf2_cu
**ref_cu
)
22922 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22923 struct dwarf2_cu
*cu
= *ref_cu
;
22924 struct die_info
*die
;
22926 die
= follow_die_offset (sect_off
,
22927 (attr
->form
== DW_FORM_GNU_ref_alt
22928 || cu
->per_cu
->is_dwz
),
22931 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22932 "at %s [in module %s]"),
22933 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22934 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
22939 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
22940 Returned value is intended for DW_OP_call*. Returned
22941 dwarf2_locexpr_baton->data has lifetime of
22942 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
22944 struct dwarf2_locexpr_baton
22945 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22946 struct dwarf2_per_cu_data
*per_cu
,
22947 CORE_ADDR (*get_frame_pc
) (void *baton
),
22950 struct dwarf2_cu
*cu
;
22951 struct die_info
*die
;
22952 struct attribute
*attr
;
22953 struct dwarf2_locexpr_baton retval
;
22954 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
22955 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22957 if (per_cu
->cu
== NULL
)
22958 load_cu (per_cu
, false);
22962 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22963 Instead just throw an error, not much else we can do. */
22964 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22965 sect_offset_str (sect_off
), objfile_name (objfile
));
22968 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22970 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22971 sect_offset_str (sect_off
), objfile_name (objfile
));
22973 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22976 /* DWARF: "If there is no such attribute, then there is no effect.".
22977 DATA is ignored if SIZE is 0. */
22979 retval
.data
= NULL
;
22982 else if (attr_form_is_section_offset (attr
))
22984 struct dwarf2_loclist_baton loclist_baton
;
22985 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22988 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
22990 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
22992 retval
.size
= size
;
22996 if (!attr_form_is_block (attr
))
22997 error (_("Dwarf Error: DIE at %s referenced in module %s "
22998 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
22999 sect_offset_str (sect_off
), objfile_name (objfile
));
23001 retval
.data
= DW_BLOCK (attr
)->data
;
23002 retval
.size
= DW_BLOCK (attr
)->size
;
23004 retval
.per_cu
= cu
->per_cu
;
23006 age_cached_comp_units (dwarf2_per_objfile
);
23011 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
23014 struct dwarf2_locexpr_baton
23015 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23016 struct dwarf2_per_cu_data
*per_cu
,
23017 CORE_ADDR (*get_frame_pc
) (void *baton
),
23020 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23022 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
23025 /* Write a constant of a given type as target-ordered bytes into
23028 static const gdb_byte
*
23029 write_constant_as_bytes (struct obstack
*obstack
,
23030 enum bfd_endian byte_order
,
23037 *len
= TYPE_LENGTH (type
);
23038 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23039 store_unsigned_integer (result
, *len
, byte_order
, value
);
23044 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
23045 pointer to the constant bytes and set LEN to the length of the
23046 data. If memory is needed, allocate it on OBSTACK. If the DIE
23047 does not have a DW_AT_const_value, return NULL. */
23050 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23051 struct dwarf2_per_cu_data
*per_cu
,
23052 struct obstack
*obstack
,
23055 struct dwarf2_cu
*cu
;
23056 struct die_info
*die
;
23057 struct attribute
*attr
;
23058 const gdb_byte
*result
= NULL
;
23061 enum bfd_endian byte_order
;
23062 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
23064 if (per_cu
->cu
== NULL
)
23065 load_cu (per_cu
, false);
23069 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23070 Instead just throw an error, not much else we can do. */
23071 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23072 sect_offset_str (sect_off
), objfile_name (objfile
));
23075 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23077 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23078 sect_offset_str (sect_off
), objfile_name (objfile
));
23080 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23084 byte_order
= (bfd_big_endian (objfile
->obfd
)
23085 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23087 switch (attr
->form
)
23090 case DW_FORM_GNU_addr_index
:
23094 *len
= cu
->header
.addr_size
;
23095 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23096 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
23100 case DW_FORM_string
:
23102 case DW_FORM_GNU_str_index
:
23103 case DW_FORM_GNU_strp_alt
:
23104 /* DW_STRING is already allocated on the objfile obstack, point
23106 result
= (const gdb_byte
*) DW_STRING (attr
);
23107 *len
= strlen (DW_STRING (attr
));
23109 case DW_FORM_block1
:
23110 case DW_FORM_block2
:
23111 case DW_FORM_block4
:
23112 case DW_FORM_block
:
23113 case DW_FORM_exprloc
:
23114 case DW_FORM_data16
:
23115 result
= DW_BLOCK (attr
)->data
;
23116 *len
= DW_BLOCK (attr
)->size
;
23119 /* The DW_AT_const_value attributes are supposed to carry the
23120 symbol's value "represented as it would be on the target
23121 architecture." By the time we get here, it's already been
23122 converted to host endianness, so we just need to sign- or
23123 zero-extend it as appropriate. */
23124 case DW_FORM_data1
:
23125 type
= die_type (die
, cu
);
23126 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23127 if (result
== NULL
)
23128 result
= write_constant_as_bytes (obstack
, byte_order
,
23131 case DW_FORM_data2
:
23132 type
= die_type (die
, cu
);
23133 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23134 if (result
== NULL
)
23135 result
= write_constant_as_bytes (obstack
, byte_order
,
23138 case DW_FORM_data4
:
23139 type
= die_type (die
, cu
);
23140 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23141 if (result
== NULL
)
23142 result
= write_constant_as_bytes (obstack
, byte_order
,
23145 case DW_FORM_data8
:
23146 type
= die_type (die
, cu
);
23147 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23148 if (result
== NULL
)
23149 result
= write_constant_as_bytes (obstack
, byte_order
,
23153 case DW_FORM_sdata
:
23154 case DW_FORM_implicit_const
:
23155 type
= die_type (die
, cu
);
23156 result
= write_constant_as_bytes (obstack
, byte_order
,
23157 type
, DW_SND (attr
), len
);
23160 case DW_FORM_udata
:
23161 type
= die_type (die
, cu
);
23162 result
= write_constant_as_bytes (obstack
, byte_order
,
23163 type
, DW_UNSND (attr
), len
);
23167 complaint (&symfile_complaints
,
23168 _("unsupported const value attribute form: '%s'"),
23169 dwarf_form_name (attr
->form
));
23176 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
23177 valid type for this die is found. */
23180 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23181 struct dwarf2_per_cu_data
*per_cu
)
23183 struct dwarf2_cu
*cu
;
23184 struct die_info
*die
;
23186 if (per_cu
->cu
== NULL
)
23187 load_cu (per_cu
, false);
23192 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23196 return die_type (die
, cu
);
23199 /* Return the type of the DIE at DIE_OFFSET in the CU named by
23203 dwarf2_get_die_type (cu_offset die_offset
,
23204 struct dwarf2_per_cu_data
*per_cu
)
23206 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23207 return get_die_type_at_offset (die_offset_sect
, per_cu
);
23210 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23211 On entry *REF_CU is the CU of SRC_DIE.
23212 On exit *REF_CU is the CU of the result.
23213 Returns NULL if the referenced DIE isn't found. */
23215 static struct die_info
*
23216 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23217 struct dwarf2_cu
**ref_cu
)
23219 struct die_info temp_die
;
23220 struct dwarf2_cu
*sig_cu
;
23221 struct die_info
*die
;
23223 /* While it might be nice to assert sig_type->type == NULL here,
23224 we can get here for DW_AT_imported_declaration where we need
23225 the DIE not the type. */
23227 /* If necessary, add it to the queue and load its DIEs. */
23229 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
23230 read_signatured_type (sig_type
);
23232 sig_cu
= sig_type
->per_cu
.cu
;
23233 gdb_assert (sig_cu
!= NULL
);
23234 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23235 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23236 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23237 to_underlying (temp_die
.sect_off
));
23240 struct dwarf2_per_objfile
*dwarf2_per_objfile
23241 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
23243 /* For .gdb_index version 7 keep track of included TUs.
23244 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23245 if (dwarf2_per_objfile
->index_table
!= NULL
23246 && dwarf2_per_objfile
->index_table
->version
<= 7)
23248 VEC_safe_push (dwarf2_per_cu_ptr
,
23249 (*ref_cu
)->per_cu
->imported_symtabs
,
23260 /* Follow signatured type referenced by ATTR in SRC_DIE.
23261 On entry *REF_CU is the CU of SRC_DIE.
23262 On exit *REF_CU is the CU of the result.
23263 The result is the DIE of the type.
23264 If the referenced type cannot be found an error is thrown. */
23266 static struct die_info
*
23267 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23268 struct dwarf2_cu
**ref_cu
)
23270 ULONGEST signature
= DW_SIGNATURE (attr
);
23271 struct signatured_type
*sig_type
;
23272 struct die_info
*die
;
23274 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23276 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23277 /* sig_type will be NULL if the signatured type is missing from
23279 if (sig_type
== NULL
)
23281 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23282 " from DIE at %s [in module %s]"),
23283 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23284 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23287 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23290 dump_die_for_error (src_die
);
23291 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23292 " from DIE at %s [in module %s]"),
23293 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23294 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23300 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23301 reading in and processing the type unit if necessary. */
23303 static struct type
*
23304 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23305 struct dwarf2_cu
*cu
)
23307 struct dwarf2_per_objfile
*dwarf2_per_objfile
23308 = cu
->per_cu
->dwarf2_per_objfile
;
23309 struct signatured_type
*sig_type
;
23310 struct dwarf2_cu
*type_cu
;
23311 struct die_info
*type_die
;
23314 sig_type
= lookup_signatured_type (cu
, signature
);
23315 /* sig_type will be NULL if the signatured type is missing from
23317 if (sig_type
== NULL
)
23319 complaint (&symfile_complaints
,
23320 _("Dwarf Error: Cannot find signatured DIE %s referenced"
23321 " from DIE at %s [in module %s]"),
23322 hex_string (signature
), sect_offset_str (die
->sect_off
),
23323 objfile_name (dwarf2_per_objfile
->objfile
));
23324 return build_error_marker_type (cu
, die
);
23327 /* If we already know the type we're done. */
23328 if (sig_type
->type
!= NULL
)
23329 return sig_type
->type
;
23332 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23333 if (type_die
!= NULL
)
23335 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23336 is created. This is important, for example, because for c++ classes
23337 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23338 type
= read_type_die (type_die
, type_cu
);
23341 complaint (&symfile_complaints
,
23342 _("Dwarf Error: Cannot build signatured type %s"
23343 " referenced from DIE at %s [in module %s]"),
23344 hex_string (signature
), sect_offset_str (die
->sect_off
),
23345 objfile_name (dwarf2_per_objfile
->objfile
));
23346 type
= build_error_marker_type (cu
, die
);
23351 complaint (&symfile_complaints
,
23352 _("Dwarf Error: Problem reading signatured DIE %s referenced"
23353 " from DIE at %s [in module %s]"),
23354 hex_string (signature
), sect_offset_str (die
->sect_off
),
23355 objfile_name (dwarf2_per_objfile
->objfile
));
23356 type
= build_error_marker_type (cu
, die
);
23358 sig_type
->type
= type
;
23363 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23364 reading in and processing the type unit if necessary. */
23366 static struct type
*
23367 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23368 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23370 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23371 if (attr_form_is_ref (attr
))
23373 struct dwarf2_cu
*type_cu
= cu
;
23374 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23376 return read_type_die (type_die
, type_cu
);
23378 else if (attr
->form
== DW_FORM_ref_sig8
)
23380 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
23384 struct dwarf2_per_objfile
*dwarf2_per_objfile
23385 = cu
->per_cu
->dwarf2_per_objfile
;
23387 complaint (&symfile_complaints
,
23388 _("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23389 " at %s [in module %s]"),
23390 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
23391 objfile_name (dwarf2_per_objfile
->objfile
));
23392 return build_error_marker_type (cu
, die
);
23396 /* Load the DIEs associated with type unit PER_CU into memory. */
23399 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
23401 struct signatured_type
*sig_type
;
23403 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23404 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
23406 /* We have the per_cu, but we need the signatured_type.
23407 Fortunately this is an easy translation. */
23408 gdb_assert (per_cu
->is_debug_types
);
23409 sig_type
= (struct signatured_type
*) per_cu
;
23411 gdb_assert (per_cu
->cu
== NULL
);
23413 read_signatured_type (sig_type
);
23415 gdb_assert (per_cu
->cu
!= NULL
);
23418 /* die_reader_func for read_signatured_type.
23419 This is identical to load_full_comp_unit_reader,
23420 but is kept separate for now. */
23423 read_signatured_type_reader (const struct die_reader_specs
*reader
,
23424 const gdb_byte
*info_ptr
,
23425 struct die_info
*comp_unit_die
,
23429 struct dwarf2_cu
*cu
= reader
->cu
;
23431 gdb_assert (cu
->die_hash
== NULL
);
23433 htab_create_alloc_ex (cu
->header
.length
/ 12,
23437 &cu
->comp_unit_obstack
,
23438 hashtab_obstack_allocate
,
23439 dummy_obstack_deallocate
);
23442 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
23443 &info_ptr
, comp_unit_die
);
23444 cu
->dies
= comp_unit_die
;
23445 /* comp_unit_die is not stored in die_hash, no need. */
23447 /* We try not to read any attributes in this function, because not
23448 all CUs needed for references have been loaded yet, and symbol
23449 table processing isn't initialized. But we have to set the CU language,
23450 or we won't be able to build types correctly.
23451 Similarly, if we do not read the producer, we can not apply
23452 producer-specific interpretation. */
23453 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23456 /* Read in a signatured type and build its CU and DIEs.
23457 If the type is a stub for the real type in a DWO file,
23458 read in the real type from the DWO file as well. */
23461 read_signatured_type (struct signatured_type
*sig_type
)
23463 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
23465 gdb_assert (per_cu
->is_debug_types
);
23466 gdb_assert (per_cu
->cu
== NULL
);
23468 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1, false,
23469 read_signatured_type_reader
, NULL
);
23470 sig_type
->per_cu
.tu_read
= 1;
23473 /* Decode simple location descriptions.
23474 Given a pointer to a dwarf block that defines a location, compute
23475 the location and return the value.
23477 NOTE drow/2003-11-18: This function is called in two situations
23478 now: for the address of static or global variables (partial symbols
23479 only) and for offsets into structures which are expected to be
23480 (more or less) constant. The partial symbol case should go away,
23481 and only the constant case should remain. That will let this
23482 function complain more accurately. A few special modes are allowed
23483 without complaint for global variables (for instance, global
23484 register values and thread-local values).
23486 A location description containing no operations indicates that the
23487 object is optimized out. The return value is 0 for that case.
23488 FIXME drow/2003-11-16: No callers check for this case any more; soon all
23489 callers will only want a very basic result and this can become a
23492 Note that stack[0] is unused except as a default error return. */
23495 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
23497 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
23499 size_t size
= blk
->size
;
23500 const gdb_byte
*data
= blk
->data
;
23501 CORE_ADDR stack
[64];
23503 unsigned int bytes_read
, unsnd
;
23509 stack
[++stacki
] = 0;
23548 stack
[++stacki
] = op
- DW_OP_lit0
;
23583 stack
[++stacki
] = op
- DW_OP_reg0
;
23585 dwarf2_complex_location_expr_complaint ();
23589 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
23591 stack
[++stacki
] = unsnd
;
23593 dwarf2_complex_location_expr_complaint ();
23597 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
23602 case DW_OP_const1u
:
23603 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
23607 case DW_OP_const1s
:
23608 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
23612 case DW_OP_const2u
:
23613 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
23617 case DW_OP_const2s
:
23618 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
23622 case DW_OP_const4u
:
23623 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
23627 case DW_OP_const4s
:
23628 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
23632 case DW_OP_const8u
:
23633 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
23638 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
23644 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
23649 stack
[stacki
+ 1] = stack
[stacki
];
23654 stack
[stacki
- 1] += stack
[stacki
];
23658 case DW_OP_plus_uconst
:
23659 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
23665 stack
[stacki
- 1] -= stack
[stacki
];
23670 /* If we're not the last op, then we definitely can't encode
23671 this using GDB's address_class enum. This is valid for partial
23672 global symbols, although the variable's address will be bogus
23675 dwarf2_complex_location_expr_complaint ();
23678 case DW_OP_GNU_push_tls_address
:
23679 case DW_OP_form_tls_address
:
23680 /* The top of the stack has the offset from the beginning
23681 of the thread control block at which the variable is located. */
23682 /* Nothing should follow this operator, so the top of stack would
23684 /* This is valid for partial global symbols, but the variable's
23685 address will be bogus in the psymtab. Make it always at least
23686 non-zero to not look as a variable garbage collected by linker
23687 which have DW_OP_addr 0. */
23689 dwarf2_complex_location_expr_complaint ();
23693 case DW_OP_GNU_uninit
:
23696 case DW_OP_GNU_addr_index
:
23697 case DW_OP_GNU_const_index
:
23698 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23705 const char *name
= get_DW_OP_name (op
);
23708 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
23711 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
23715 return (stack
[stacki
]);
23718 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23719 outside of the allocated space. Also enforce minimum>0. */
23720 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23722 complaint (&symfile_complaints
,
23723 _("location description stack overflow"));
23729 complaint (&symfile_complaints
,
23730 _("location description stack underflow"));
23734 return (stack
[stacki
]);
23737 /* memory allocation interface */
23739 static struct dwarf_block
*
23740 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23742 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23745 static struct die_info
*
23746 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23748 struct die_info
*die
;
23749 size_t size
= sizeof (struct die_info
);
23752 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23754 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23755 memset (die
, 0, sizeof (struct die_info
));
23760 /* Macro support. */
23762 /* Return file name relative to the compilation directory of file number I in
23763 *LH's file name table. The result is allocated using xmalloc; the caller is
23764 responsible for freeing it. */
23767 file_file_name (int file
, struct line_header
*lh
)
23769 /* Is the file number a valid index into the line header's file name
23770 table? Remember that file numbers start with one, not zero. */
23771 if (1 <= file
&& file
<= lh
->file_names
.size ())
23773 const file_entry
&fe
= lh
->file_names
[file
- 1];
23775 if (!IS_ABSOLUTE_PATH (fe
.name
))
23777 const char *dir
= fe
.include_dir (lh
);
23779 return concat (dir
, SLASH_STRING
, fe
.name
, (char *) NULL
);
23781 return xstrdup (fe
.name
);
23785 /* The compiler produced a bogus file number. We can at least
23786 record the macro definitions made in the file, even if we
23787 won't be able to find the file by name. */
23788 char fake_name
[80];
23790 xsnprintf (fake_name
, sizeof (fake_name
),
23791 "<bad macro file number %d>", file
);
23793 complaint (&symfile_complaints
,
23794 _("bad file number in macro information (%d)"),
23797 return xstrdup (fake_name
);
23801 /* Return the full name of file number I in *LH's file name table.
23802 Use COMP_DIR as the name of the current directory of the
23803 compilation. The result is allocated using xmalloc; the caller is
23804 responsible for freeing it. */
23806 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
23808 /* Is the file number a valid index into the line header's file name
23809 table? Remember that file numbers start with one, not zero. */
23810 if (1 <= file
&& file
<= lh
->file_names
.size ())
23812 char *relative
= file_file_name (file
, lh
);
23814 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
23816 return reconcat (relative
, comp_dir
, SLASH_STRING
,
23817 relative
, (char *) NULL
);
23820 return file_file_name (file
, lh
);
23824 static struct macro_source_file
*
23825 macro_start_file (int file
, int line
,
23826 struct macro_source_file
*current_file
,
23827 struct line_header
*lh
)
23829 /* File name relative to the compilation directory of this source file. */
23830 char *file_name
= file_file_name (file
, lh
);
23832 if (! current_file
)
23834 /* Note: We don't create a macro table for this compilation unit
23835 at all until we actually get a filename. */
23836 struct macro_table
*macro_table
= get_macro_table ();
23838 /* If we have no current file, then this must be the start_file
23839 directive for the compilation unit's main source file. */
23840 current_file
= macro_set_main (macro_table
, file_name
);
23841 macro_define_special (macro_table
);
23844 current_file
= macro_include (current_file
, line
, file_name
);
23848 return current_file
;
23851 static const char *
23852 consume_improper_spaces (const char *p
, const char *body
)
23856 complaint (&symfile_complaints
,
23857 _("macro definition contains spaces "
23858 "in formal argument list:\n`%s'"),
23870 parse_macro_definition (struct macro_source_file
*file
, int line
,
23875 /* The body string takes one of two forms. For object-like macro
23876 definitions, it should be:
23878 <macro name> " " <definition>
23880 For function-like macro definitions, it should be:
23882 <macro name> "() " <definition>
23884 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
23886 Spaces may appear only where explicitly indicated, and in the
23889 The Dwarf 2 spec says that an object-like macro's name is always
23890 followed by a space, but versions of GCC around March 2002 omit
23891 the space when the macro's definition is the empty string.
23893 The Dwarf 2 spec says that there should be no spaces between the
23894 formal arguments in a function-like macro's formal argument list,
23895 but versions of GCC around March 2002 include spaces after the
23899 /* Find the extent of the macro name. The macro name is terminated
23900 by either a space or null character (for an object-like macro) or
23901 an opening paren (for a function-like macro). */
23902 for (p
= body
; *p
; p
++)
23903 if (*p
== ' ' || *p
== '(')
23906 if (*p
== ' ' || *p
== '\0')
23908 /* It's an object-like macro. */
23909 int name_len
= p
- body
;
23910 char *name
= savestring (body
, name_len
);
23911 const char *replacement
;
23914 replacement
= body
+ name_len
+ 1;
23917 dwarf2_macro_malformed_definition_complaint (body
);
23918 replacement
= body
+ name_len
;
23921 macro_define_object (file
, line
, name
, replacement
);
23925 else if (*p
== '(')
23927 /* It's a function-like macro. */
23928 char *name
= savestring (body
, p
- body
);
23931 char **argv
= XNEWVEC (char *, argv_size
);
23935 p
= consume_improper_spaces (p
, body
);
23937 /* Parse the formal argument list. */
23938 while (*p
&& *p
!= ')')
23940 /* Find the extent of the current argument name. */
23941 const char *arg_start
= p
;
23943 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
23946 if (! *p
|| p
== arg_start
)
23947 dwarf2_macro_malformed_definition_complaint (body
);
23950 /* Make sure argv has room for the new argument. */
23951 if (argc
>= argv_size
)
23954 argv
= XRESIZEVEC (char *, argv
, argv_size
);
23957 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
23960 p
= consume_improper_spaces (p
, body
);
23962 /* Consume the comma, if present. */
23967 p
= consume_improper_spaces (p
, body
);
23976 /* Perfectly formed definition, no complaints. */
23977 macro_define_function (file
, line
, name
,
23978 argc
, (const char **) argv
,
23980 else if (*p
== '\0')
23982 /* Complain, but do define it. */
23983 dwarf2_macro_malformed_definition_complaint (body
);
23984 macro_define_function (file
, line
, name
,
23985 argc
, (const char **) argv
,
23989 /* Just complain. */
23990 dwarf2_macro_malformed_definition_complaint (body
);
23993 /* Just complain. */
23994 dwarf2_macro_malformed_definition_complaint (body
);
24000 for (i
= 0; i
< argc
; i
++)
24006 dwarf2_macro_malformed_definition_complaint (body
);
24009 /* Skip some bytes from BYTES according to the form given in FORM.
24010 Returns the new pointer. */
24012 static const gdb_byte
*
24013 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
24014 enum dwarf_form form
,
24015 unsigned int offset_size
,
24016 struct dwarf2_section_info
*section
)
24018 unsigned int bytes_read
;
24022 case DW_FORM_data1
:
24027 case DW_FORM_data2
:
24031 case DW_FORM_data4
:
24035 case DW_FORM_data8
:
24039 case DW_FORM_data16
:
24043 case DW_FORM_string
:
24044 read_direct_string (abfd
, bytes
, &bytes_read
);
24045 bytes
+= bytes_read
;
24048 case DW_FORM_sec_offset
:
24050 case DW_FORM_GNU_strp_alt
:
24051 bytes
+= offset_size
;
24054 case DW_FORM_block
:
24055 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
24056 bytes
+= bytes_read
;
24059 case DW_FORM_block1
:
24060 bytes
+= 1 + read_1_byte (abfd
, bytes
);
24062 case DW_FORM_block2
:
24063 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
24065 case DW_FORM_block4
:
24066 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
24069 case DW_FORM_sdata
:
24070 case DW_FORM_udata
:
24071 case DW_FORM_GNU_addr_index
:
24072 case DW_FORM_GNU_str_index
:
24073 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
24076 dwarf2_section_buffer_overflow_complaint (section
);
24081 case DW_FORM_implicit_const
:
24086 complaint (&symfile_complaints
,
24087 _("invalid form 0x%x in `%s'"),
24088 form
, get_section_name (section
));
24096 /* A helper for dwarf_decode_macros that handles skipping an unknown
24097 opcode. Returns an updated pointer to the macro data buffer; or,
24098 on error, issues a complaint and returns NULL. */
24100 static const gdb_byte
*
24101 skip_unknown_opcode (unsigned int opcode
,
24102 const gdb_byte
**opcode_definitions
,
24103 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24105 unsigned int offset_size
,
24106 struct dwarf2_section_info
*section
)
24108 unsigned int bytes_read
, i
;
24110 const gdb_byte
*defn
;
24112 if (opcode_definitions
[opcode
] == NULL
)
24114 complaint (&symfile_complaints
,
24115 _("unrecognized DW_MACFINO opcode 0x%x"),
24120 defn
= opcode_definitions
[opcode
];
24121 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
24122 defn
+= bytes_read
;
24124 for (i
= 0; i
< arg
; ++i
)
24126 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
24127 (enum dwarf_form
) defn
[i
], offset_size
,
24129 if (mac_ptr
== NULL
)
24131 /* skip_form_bytes already issued the complaint. */
24139 /* A helper function which parses the header of a macro section.
24140 If the macro section is the extended (for now called "GNU") type,
24141 then this updates *OFFSET_SIZE. Returns a pointer to just after
24142 the header, or issues a complaint and returns NULL on error. */
24144 static const gdb_byte
*
24145 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
24147 const gdb_byte
*mac_ptr
,
24148 unsigned int *offset_size
,
24149 int section_is_gnu
)
24151 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
24153 if (section_is_gnu
)
24155 unsigned int version
, flags
;
24157 version
= read_2_bytes (abfd
, mac_ptr
);
24158 if (version
!= 4 && version
!= 5)
24160 complaint (&symfile_complaints
,
24161 _("unrecognized version `%d' in .debug_macro section"),
24167 flags
= read_1_byte (abfd
, mac_ptr
);
24169 *offset_size
= (flags
& 1) ? 8 : 4;
24171 if ((flags
& 2) != 0)
24172 /* We don't need the line table offset. */
24173 mac_ptr
+= *offset_size
;
24175 /* Vendor opcode descriptions. */
24176 if ((flags
& 4) != 0)
24178 unsigned int i
, count
;
24180 count
= read_1_byte (abfd
, mac_ptr
);
24182 for (i
= 0; i
< count
; ++i
)
24184 unsigned int opcode
, bytes_read
;
24187 opcode
= read_1_byte (abfd
, mac_ptr
);
24189 opcode_definitions
[opcode
] = mac_ptr
;
24190 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24191 mac_ptr
+= bytes_read
;
24200 /* A helper for dwarf_decode_macros that handles the GNU extensions,
24201 including DW_MACRO_import. */
24204 dwarf_decode_macro_bytes (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
24206 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24207 struct macro_source_file
*current_file
,
24208 struct line_header
*lh
,
24209 struct dwarf2_section_info
*section
,
24210 int section_is_gnu
, int section_is_dwz
,
24211 unsigned int offset_size
,
24212 htab_t include_hash
)
24214 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24215 enum dwarf_macro_record_type macinfo_type
;
24216 int at_commandline
;
24217 const gdb_byte
*opcode_definitions
[256];
24219 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24220 &offset_size
, section_is_gnu
);
24221 if (mac_ptr
== NULL
)
24223 /* We already issued a complaint. */
24227 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
24228 GDB is still reading the definitions from command line. First
24229 DW_MACINFO_start_file will need to be ignored as it was already executed
24230 to create CURRENT_FILE for the main source holding also the command line
24231 definitions. On first met DW_MACINFO_start_file this flag is reset to
24232 normally execute all the remaining DW_MACINFO_start_file macinfos. */
24234 at_commandline
= 1;
24238 /* Do we at least have room for a macinfo type byte? */
24239 if (mac_ptr
>= mac_end
)
24241 dwarf2_section_buffer_overflow_complaint (section
);
24245 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24248 /* Note that we rely on the fact that the corresponding GNU and
24249 DWARF constants are the same. */
24251 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24252 switch (macinfo_type
)
24254 /* A zero macinfo type indicates the end of the macro
24259 case DW_MACRO_define
:
24260 case DW_MACRO_undef
:
24261 case DW_MACRO_define_strp
:
24262 case DW_MACRO_undef_strp
:
24263 case DW_MACRO_define_sup
:
24264 case DW_MACRO_undef_sup
:
24266 unsigned int bytes_read
;
24271 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24272 mac_ptr
+= bytes_read
;
24274 if (macinfo_type
== DW_MACRO_define
24275 || macinfo_type
== DW_MACRO_undef
)
24277 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24278 mac_ptr
+= bytes_read
;
24282 LONGEST str_offset
;
24284 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24285 mac_ptr
+= offset_size
;
24287 if (macinfo_type
== DW_MACRO_define_sup
24288 || macinfo_type
== DW_MACRO_undef_sup
24291 struct dwz_file
*dwz
24292 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
24294 body
= read_indirect_string_from_dwz (objfile
,
24298 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
24302 is_define
= (macinfo_type
== DW_MACRO_define
24303 || macinfo_type
== DW_MACRO_define_strp
24304 || macinfo_type
== DW_MACRO_define_sup
);
24305 if (! current_file
)
24307 /* DWARF violation as no main source is present. */
24308 complaint (&symfile_complaints
,
24309 _("debug info with no main source gives macro %s "
24311 is_define
? _("definition") : _("undefinition"),
24315 if ((line
== 0 && !at_commandline
)
24316 || (line
!= 0 && at_commandline
))
24317 complaint (&symfile_complaints
,
24318 _("debug info gives %s macro %s with %s line %d: %s"),
24319 at_commandline
? _("command-line") : _("in-file"),
24320 is_define
? _("definition") : _("undefinition"),
24321 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
24324 parse_macro_definition (current_file
, line
, body
);
24327 gdb_assert (macinfo_type
== DW_MACRO_undef
24328 || macinfo_type
== DW_MACRO_undef_strp
24329 || macinfo_type
== DW_MACRO_undef_sup
);
24330 macro_undef (current_file
, line
, body
);
24335 case DW_MACRO_start_file
:
24337 unsigned int bytes_read
;
24340 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24341 mac_ptr
+= bytes_read
;
24342 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24343 mac_ptr
+= bytes_read
;
24345 if ((line
== 0 && !at_commandline
)
24346 || (line
!= 0 && at_commandline
))
24347 complaint (&symfile_complaints
,
24348 _("debug info gives source %d included "
24349 "from %s at %s line %d"),
24350 file
, at_commandline
? _("command-line") : _("file"),
24351 line
== 0 ? _("zero") : _("non-zero"), line
);
24353 if (at_commandline
)
24355 /* This DW_MACRO_start_file was executed in the
24357 at_commandline
= 0;
24360 current_file
= macro_start_file (file
, line
, current_file
, lh
);
24364 case DW_MACRO_end_file
:
24365 if (! current_file
)
24366 complaint (&symfile_complaints
,
24367 _("macro debug info has an unmatched "
24368 "`close_file' directive"));
24371 current_file
= current_file
->included_by
;
24372 if (! current_file
)
24374 enum dwarf_macro_record_type next_type
;
24376 /* GCC circa March 2002 doesn't produce the zero
24377 type byte marking the end of the compilation
24378 unit. Complain if it's not there, but exit no
24381 /* Do we at least have room for a macinfo type byte? */
24382 if (mac_ptr
>= mac_end
)
24384 dwarf2_section_buffer_overflow_complaint (section
);
24388 /* We don't increment mac_ptr here, so this is just
24391 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
24393 if (next_type
!= 0)
24394 complaint (&symfile_complaints
,
24395 _("no terminating 0-type entry for "
24396 "macros in `.debug_macinfo' section"));
24403 case DW_MACRO_import
:
24404 case DW_MACRO_import_sup
:
24408 bfd
*include_bfd
= abfd
;
24409 struct dwarf2_section_info
*include_section
= section
;
24410 const gdb_byte
*include_mac_end
= mac_end
;
24411 int is_dwz
= section_is_dwz
;
24412 const gdb_byte
*new_mac_ptr
;
24414 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24415 mac_ptr
+= offset_size
;
24417 if (macinfo_type
== DW_MACRO_import_sup
)
24419 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
24421 dwarf2_read_section (objfile
, &dwz
->macro
);
24423 include_section
= &dwz
->macro
;
24424 include_bfd
= get_section_bfd_owner (include_section
);
24425 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
24429 new_mac_ptr
= include_section
->buffer
+ offset
;
24430 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
24434 /* This has actually happened; see
24435 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
24436 complaint (&symfile_complaints
,
24437 _("recursive DW_MACRO_import in "
24438 ".debug_macro section"));
24442 *slot
= (void *) new_mac_ptr
;
24444 dwarf_decode_macro_bytes (dwarf2_per_objfile
,
24445 include_bfd
, new_mac_ptr
,
24446 include_mac_end
, current_file
, lh
,
24447 section
, section_is_gnu
, is_dwz
,
24448 offset_size
, include_hash
);
24450 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
24455 case DW_MACINFO_vendor_ext
:
24456 if (!section_is_gnu
)
24458 unsigned int bytes_read
;
24460 /* This reads the constant, but since we don't recognize
24461 any vendor extensions, we ignore it. */
24462 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24463 mac_ptr
+= bytes_read
;
24464 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24465 mac_ptr
+= bytes_read
;
24467 /* We don't recognize any vendor extensions. */
24473 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
24474 mac_ptr
, mac_end
, abfd
, offset_size
,
24476 if (mac_ptr
== NULL
)
24481 } while (macinfo_type
!= 0);
24485 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24486 int section_is_gnu
)
24488 struct dwarf2_per_objfile
*dwarf2_per_objfile
24489 = cu
->per_cu
->dwarf2_per_objfile
;
24490 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24491 struct line_header
*lh
= cu
->line_header
;
24493 const gdb_byte
*mac_ptr
, *mac_end
;
24494 struct macro_source_file
*current_file
= 0;
24495 enum dwarf_macro_record_type macinfo_type
;
24496 unsigned int offset_size
= cu
->header
.offset_size
;
24497 const gdb_byte
*opcode_definitions
[256];
24499 struct dwarf2_section_info
*section
;
24500 const char *section_name
;
24502 if (cu
->dwo_unit
!= NULL
)
24504 if (section_is_gnu
)
24506 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24507 section_name
= ".debug_macro.dwo";
24511 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24512 section_name
= ".debug_macinfo.dwo";
24517 if (section_is_gnu
)
24519 section
= &dwarf2_per_objfile
->macro
;
24520 section_name
= ".debug_macro";
24524 section
= &dwarf2_per_objfile
->macinfo
;
24525 section_name
= ".debug_macinfo";
24529 dwarf2_read_section (objfile
, section
);
24530 if (section
->buffer
== NULL
)
24532 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
24535 abfd
= get_section_bfd_owner (section
);
24537 /* First pass: Find the name of the base filename.
24538 This filename is needed in order to process all macros whose definition
24539 (or undefinition) comes from the command line. These macros are defined
24540 before the first DW_MACINFO_start_file entry, and yet still need to be
24541 associated to the base file.
24543 To determine the base file name, we scan the macro definitions until we
24544 reach the first DW_MACINFO_start_file entry. We then initialize
24545 CURRENT_FILE accordingly so that any macro definition found before the
24546 first DW_MACINFO_start_file can still be associated to the base file. */
24548 mac_ptr
= section
->buffer
+ offset
;
24549 mac_end
= section
->buffer
+ section
->size
;
24551 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24552 &offset_size
, section_is_gnu
);
24553 if (mac_ptr
== NULL
)
24555 /* We already issued a complaint. */
24561 /* Do we at least have room for a macinfo type byte? */
24562 if (mac_ptr
>= mac_end
)
24564 /* Complaint is printed during the second pass as GDB will probably
24565 stop the first pass earlier upon finding
24566 DW_MACINFO_start_file. */
24570 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24573 /* Note that we rely on the fact that the corresponding GNU and
24574 DWARF constants are the same. */
24576 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24577 switch (macinfo_type
)
24579 /* A zero macinfo type indicates the end of the macro
24584 case DW_MACRO_define
:
24585 case DW_MACRO_undef
:
24586 /* Only skip the data by MAC_PTR. */
24588 unsigned int bytes_read
;
24590 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24591 mac_ptr
+= bytes_read
;
24592 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24593 mac_ptr
+= bytes_read
;
24597 case DW_MACRO_start_file
:
24599 unsigned int bytes_read
;
24602 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24603 mac_ptr
+= bytes_read
;
24604 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24605 mac_ptr
+= bytes_read
;
24607 current_file
= macro_start_file (file
, line
, current_file
, lh
);
24611 case DW_MACRO_end_file
:
24612 /* No data to skip by MAC_PTR. */
24615 case DW_MACRO_define_strp
:
24616 case DW_MACRO_undef_strp
:
24617 case DW_MACRO_define_sup
:
24618 case DW_MACRO_undef_sup
:
24620 unsigned int bytes_read
;
24622 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24623 mac_ptr
+= bytes_read
;
24624 mac_ptr
+= offset_size
;
24628 case DW_MACRO_import
:
24629 case DW_MACRO_import_sup
:
24630 /* Note that, according to the spec, a transparent include
24631 chain cannot call DW_MACRO_start_file. So, we can just
24632 skip this opcode. */
24633 mac_ptr
+= offset_size
;
24636 case DW_MACINFO_vendor_ext
:
24637 /* Only skip the data by MAC_PTR. */
24638 if (!section_is_gnu
)
24640 unsigned int bytes_read
;
24642 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24643 mac_ptr
+= bytes_read
;
24644 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24645 mac_ptr
+= bytes_read
;
24650 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
24651 mac_ptr
, mac_end
, abfd
, offset_size
,
24653 if (mac_ptr
== NULL
)
24658 } while (macinfo_type
!= 0 && current_file
== NULL
);
24660 /* Second pass: Process all entries.
24662 Use the AT_COMMAND_LINE flag to determine whether we are still processing
24663 command-line macro definitions/undefinitions. This flag is unset when we
24664 reach the first DW_MACINFO_start_file entry. */
24666 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
24668 NULL
, xcalloc
, xfree
));
24669 mac_ptr
= section
->buffer
+ offset
;
24670 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
24671 *slot
= (void *) mac_ptr
;
24672 dwarf_decode_macro_bytes (dwarf2_per_objfile
,
24673 abfd
, mac_ptr
, mac_end
,
24674 current_file
, lh
, section
,
24675 section_is_gnu
, 0, offset_size
,
24676 include_hash
.get ());
24679 /* Check if the attribute's form is a DW_FORM_block*
24680 if so return true else false. */
24683 attr_form_is_block (const struct attribute
*attr
)
24685 return (attr
== NULL
? 0 :
24686 attr
->form
== DW_FORM_block1
24687 || attr
->form
== DW_FORM_block2
24688 || attr
->form
== DW_FORM_block4
24689 || attr
->form
== DW_FORM_block
24690 || attr
->form
== DW_FORM_exprloc
);
24693 /* Return non-zero if ATTR's value is a section offset --- classes
24694 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
24695 You may use DW_UNSND (attr) to retrieve such offsets.
24697 Section 7.5.4, "Attribute Encodings", explains that no attribute
24698 may have a value that belongs to more than one of these classes; it
24699 would be ambiguous if we did, because we use the same forms for all
24703 attr_form_is_section_offset (const struct attribute
*attr
)
24705 return (attr
->form
== DW_FORM_data4
24706 || attr
->form
== DW_FORM_data8
24707 || attr
->form
== DW_FORM_sec_offset
);
24710 /* Return non-zero if ATTR's value falls in the 'constant' class, or
24711 zero otherwise. When this function returns true, you can apply
24712 dwarf2_get_attr_constant_value to it.
24714 However, note that for some attributes you must check
24715 attr_form_is_section_offset before using this test. DW_FORM_data4
24716 and DW_FORM_data8 are members of both the constant class, and of
24717 the classes that contain offsets into other debug sections
24718 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
24719 that, if an attribute's can be either a constant or one of the
24720 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
24721 taken as section offsets, not constants.
24723 DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
24724 cannot handle that. */
24727 attr_form_is_constant (const struct attribute
*attr
)
24729 switch (attr
->form
)
24731 case DW_FORM_sdata
:
24732 case DW_FORM_udata
:
24733 case DW_FORM_data1
:
24734 case DW_FORM_data2
:
24735 case DW_FORM_data4
:
24736 case DW_FORM_data8
:
24737 case DW_FORM_implicit_const
:
24745 /* DW_ADDR is always stored already as sect_offset; despite for the forms
24746 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
24749 attr_form_is_ref (const struct attribute
*attr
)
24751 switch (attr
->form
)
24753 case DW_FORM_ref_addr
:
24758 case DW_FORM_ref_udata
:
24759 case DW_FORM_GNU_ref_alt
:
24766 /* Return the .debug_loc section to use for CU.
24767 For DWO files use .debug_loc.dwo. */
24769 static struct dwarf2_section_info
*
24770 cu_debug_loc_section (struct dwarf2_cu
*cu
)
24772 struct dwarf2_per_objfile
*dwarf2_per_objfile
24773 = cu
->per_cu
->dwarf2_per_objfile
;
24777 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24779 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
24781 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
24782 : &dwarf2_per_objfile
->loc
);
24785 /* A helper function that fills in a dwarf2_loclist_baton. */
24788 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
24789 struct dwarf2_loclist_baton
*baton
,
24790 const struct attribute
*attr
)
24792 struct dwarf2_per_objfile
*dwarf2_per_objfile
24793 = cu
->per_cu
->dwarf2_per_objfile
;
24794 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24796 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
24798 baton
->per_cu
= cu
->per_cu
;
24799 gdb_assert (baton
->per_cu
);
24800 /* We don't know how long the location list is, but make sure we
24801 don't run off the edge of the section. */
24802 baton
->size
= section
->size
- DW_UNSND (attr
);
24803 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
24804 baton
->base_address
= cu
->base_address
;
24805 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
24809 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
24810 struct dwarf2_cu
*cu
, int is_block
)
24812 struct dwarf2_per_objfile
*dwarf2_per_objfile
24813 = cu
->per_cu
->dwarf2_per_objfile
;
24814 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24815 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24817 if (attr_form_is_section_offset (attr
)
24818 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24819 the section. If so, fall through to the complaint in the
24821 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
24823 struct dwarf2_loclist_baton
*baton
;
24825 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24827 fill_in_loclist_baton (cu
, baton
, attr
);
24829 if (cu
->base_known
== 0)
24830 complaint (&symfile_complaints
,
24831 _("Location list used without "
24832 "specifying the CU base address."));
24834 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24835 ? dwarf2_loclist_block_index
24836 : dwarf2_loclist_index
);
24837 SYMBOL_LOCATION_BATON (sym
) = baton
;
24841 struct dwarf2_locexpr_baton
*baton
;
24843 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24844 baton
->per_cu
= cu
->per_cu
;
24845 gdb_assert (baton
->per_cu
);
24847 if (attr_form_is_block (attr
))
24849 /* Note that we're just copying the block's data pointer
24850 here, not the actual data. We're still pointing into the
24851 info_buffer for SYM's objfile; right now we never release
24852 that buffer, but when we do clean up properly this may
24854 baton
->size
= DW_BLOCK (attr
)->size
;
24855 baton
->data
= DW_BLOCK (attr
)->data
;
24859 dwarf2_invalid_attrib_class_complaint ("location description",
24860 SYMBOL_NATURAL_NAME (sym
));
24864 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24865 ? dwarf2_locexpr_block_index
24866 : dwarf2_locexpr_index
);
24867 SYMBOL_LOCATION_BATON (sym
) = baton
;
24871 /* Return the OBJFILE associated with the compilation unit CU. If CU
24872 came from a separate debuginfo file, then the master objfile is
24876 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
24878 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
24880 /* Return the master objfile, so that we can report and look up the
24881 correct file containing this variable. */
24882 if (objfile
->separate_debug_objfile_backlink
)
24883 objfile
= objfile
->separate_debug_objfile_backlink
;
24888 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
24889 (CU_HEADERP is unused in such case) or prepare a temporary copy at
24890 CU_HEADERP first. */
24892 static const struct comp_unit_head
*
24893 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
24894 struct dwarf2_per_cu_data
*per_cu
)
24896 const gdb_byte
*info_ptr
;
24899 return &per_cu
->cu
->header
;
24901 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
24903 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
24904 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
24905 rcuh_kind::COMPILE
);
24910 /* Return the address size given in the compilation unit header for CU. */
24913 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
24915 struct comp_unit_head cu_header_local
;
24916 const struct comp_unit_head
*cu_headerp
;
24918 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
24920 return cu_headerp
->addr_size
;
24923 /* Return the offset size given in the compilation unit header for CU. */
24926 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
24928 struct comp_unit_head cu_header_local
;
24929 const struct comp_unit_head
*cu_headerp
;
24931 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
24933 return cu_headerp
->offset_size
;
24936 /* See its dwarf2loc.h declaration. */
24939 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
24941 struct comp_unit_head cu_header_local
;
24942 const struct comp_unit_head
*cu_headerp
;
24944 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
24946 if (cu_headerp
->version
== 2)
24947 return cu_headerp
->addr_size
;
24949 return cu_headerp
->offset_size
;
24952 /* Return the text offset of the CU. The returned offset comes from
24953 this CU's objfile. If this objfile came from a separate debuginfo
24954 file, then the offset may be different from the corresponding
24955 offset in the parent objfile. */
24958 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
24960 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
24962 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
24965 /* Return DWARF version number of PER_CU. */
24968 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
24970 return per_cu
->dwarf_version
;
24973 /* Locate the .debug_info compilation unit from CU's objfile which contains
24974 the DIE at OFFSET. Raises an error on failure. */
24976 static struct dwarf2_per_cu_data
*
24977 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24978 unsigned int offset_in_dwz
,
24979 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
24981 struct dwarf2_per_cu_data
*this_cu
;
24983 const sect_offset
*cu_off
;
24986 high
= dwarf2_per_objfile
->all_comp_units
.size () - 1;
24989 struct dwarf2_per_cu_data
*mid_cu
;
24990 int mid
= low
+ (high
- low
) / 2;
24992 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
24993 cu_off
= &mid_cu
->sect_off
;
24994 if (mid_cu
->is_dwz
> offset_in_dwz
24995 || (mid_cu
->is_dwz
== offset_in_dwz
&& *cu_off
>= sect_off
))
25000 gdb_assert (low
== high
);
25001 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
25002 cu_off
= &this_cu
->sect_off
;
25003 if (this_cu
->is_dwz
!= offset_in_dwz
|| *cu_off
> sect_off
)
25005 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
25006 error (_("Dwarf Error: could not find partial DIE containing "
25007 "offset %s [in module %s]"),
25008 sect_offset_str (sect_off
),
25009 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
25011 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
25013 return dwarf2_per_objfile
->all_comp_units
[low
-1];
25017 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
25018 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
25019 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
25020 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
25021 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
25026 /* Initialize dwarf2_cu CU, owned by PER_CU. */
25028 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
25029 : per_cu (per_cu_
),
25032 checked_producer (0),
25033 producer_is_gxx_lt_4_6 (0),
25034 producer_is_gcc_lt_4_3 (0),
25035 producer_is_icc_lt_14 (0),
25036 processing_has_namespace_info (0)
25041 /* Destroy a dwarf2_cu. */
25043 dwarf2_cu::~dwarf2_cu ()
25048 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
25051 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
25052 enum language pretend_language
)
25054 struct attribute
*attr
;
25056 /* Set the language we're debugging. */
25057 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
25059 set_cu_language (DW_UNSND (attr
), cu
);
25062 cu
->language
= pretend_language
;
25063 cu
->language_defn
= language_def (cu
->language
);
25066 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
25069 /* Increase the age counter on each cached compilation unit, and free
25070 any that are too old. */
25073 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25075 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25077 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
25078 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25079 while (per_cu
!= NULL
)
25081 per_cu
->cu
->last_used
++;
25082 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
25083 dwarf2_mark (per_cu
->cu
);
25084 per_cu
= per_cu
->cu
->read_in_chain
;
25087 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25088 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25089 while (per_cu
!= NULL
)
25091 struct dwarf2_per_cu_data
*next_cu
;
25093 next_cu
= per_cu
->cu
->read_in_chain
;
25095 if (!per_cu
->cu
->mark
)
25098 *last_chain
= next_cu
;
25101 last_chain
= &per_cu
->cu
->read_in_chain
;
25107 /* Remove a single compilation unit from the cache. */
25110 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
25112 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25113 struct dwarf2_per_objfile
*dwarf2_per_objfile
25114 = target_per_cu
->dwarf2_per_objfile
;
25116 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25117 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25118 while (per_cu
!= NULL
)
25120 struct dwarf2_per_cu_data
*next_cu
;
25122 next_cu
= per_cu
->cu
->read_in_chain
;
25124 if (per_cu
== target_per_cu
)
25128 *last_chain
= next_cu
;
25132 last_chain
= &per_cu
->cu
->read_in_chain
;
25138 /* Release all extra memory associated with OBJFILE. */
25141 dwarf2_free_objfile (struct objfile
*objfile
)
25143 struct dwarf2_per_objfile
*dwarf2_per_objfile
25144 = get_dwarf2_per_objfile (objfile
);
25146 delete dwarf2_per_objfile
;
25149 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
25150 We store these in a hash table separate from the DIEs, and preserve them
25151 when the DIEs are flushed out of cache.
25153 The CU "per_cu" pointer is needed because offset alone is not enough to
25154 uniquely identify the type. A file may have multiple .debug_types sections,
25155 or the type may come from a DWO file. Furthermore, while it's more logical
25156 to use per_cu->section+offset, with Fission the section with the data is in
25157 the DWO file but we don't know that section at the point we need it.
25158 We have to use something in dwarf2_per_cu_data (or the pointer to it)
25159 because we can enter the lookup routine, get_die_type_at_offset, from
25160 outside this file, and thus won't necessarily have PER_CU->cu.
25161 Fortunately, PER_CU is stable for the life of the objfile. */
25163 struct dwarf2_per_cu_offset_and_type
25165 const struct dwarf2_per_cu_data
*per_cu
;
25166 sect_offset sect_off
;
25170 /* Hash function for a dwarf2_per_cu_offset_and_type. */
25173 per_cu_offset_and_type_hash (const void *item
)
25175 const struct dwarf2_per_cu_offset_and_type
*ofs
25176 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
25178 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
25181 /* Equality function for a dwarf2_per_cu_offset_and_type. */
25184 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
25186 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
25187 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
25188 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25189 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25191 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25192 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25195 /* Set the type associated with DIE to TYPE. Save it in CU's hash
25196 table if necessary. For convenience, return TYPE.
25198 The DIEs reading must have careful ordering to:
25199 * Not cause infite loops trying to read in DIEs as a prerequisite for
25200 reading current DIE.
25201 * Not trying to dereference contents of still incompletely read in types
25202 while reading in other DIEs.
25203 * Enable referencing still incompletely read in types just by a pointer to
25204 the type without accessing its fields.
25206 Therefore caller should follow these rules:
25207 * Try to fetch any prerequisite types we may need to build this DIE type
25208 before building the type and calling set_die_type.
25209 * After building type call set_die_type for current DIE as soon as
25210 possible before fetching more types to complete the current type.
25211 * Make the type as complete as possible before fetching more types. */
25213 static struct type
*
25214 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
25216 struct dwarf2_per_objfile
*dwarf2_per_objfile
25217 = cu
->per_cu
->dwarf2_per_objfile
;
25218 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
25219 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25220 struct attribute
*attr
;
25221 struct dynamic_prop prop
;
25223 /* For Ada types, make sure that the gnat-specific data is always
25224 initialized (if not already set). There are a few types where
25225 we should not be doing so, because the type-specific area is
25226 already used to hold some other piece of info (eg: TYPE_CODE_FLT
25227 where the type-specific area is used to store the floatformat).
25228 But this is not a problem, because the gnat-specific information
25229 is actually not needed for these types. */
25230 if (need_gnat_info (cu
)
25231 && TYPE_CODE (type
) != TYPE_CODE_FUNC
25232 && TYPE_CODE (type
) != TYPE_CODE_FLT
25233 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
25234 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
25235 && TYPE_CODE (type
) != TYPE_CODE_METHOD
25236 && !HAVE_GNAT_AUX_INFO (type
))
25237 INIT_GNAT_SPECIFIC (type
);
25239 /* Read DW_AT_allocated and set in type. */
25240 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
25241 if (attr_form_is_block (attr
))
25243 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25244 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
25246 else if (attr
!= NULL
)
25248 complaint (&symfile_complaints
,
25249 _("DW_AT_allocated has the wrong form (%s) at DIE %s"),
25250 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25251 sect_offset_str (die
->sect_off
));
25254 /* Read DW_AT_associated and set in type. */
25255 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
25256 if (attr_form_is_block (attr
))
25258 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25259 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
25261 else if (attr
!= NULL
)
25263 complaint (&symfile_complaints
,
25264 _("DW_AT_associated has the wrong form (%s) at DIE %s"),
25265 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25266 sect_offset_str (die
->sect_off
));
25269 /* Read DW_AT_data_location and set in type. */
25270 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
25271 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25272 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
25274 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25276 dwarf2_per_objfile
->die_type_hash
=
25277 htab_create_alloc_ex (127,
25278 per_cu_offset_and_type_hash
,
25279 per_cu_offset_and_type_eq
,
25281 &objfile
->objfile_obstack
,
25282 hashtab_obstack_allocate
,
25283 dummy_obstack_deallocate
);
25286 ofs
.per_cu
= cu
->per_cu
;
25287 ofs
.sect_off
= die
->sect_off
;
25289 slot
= (struct dwarf2_per_cu_offset_and_type
**)
25290 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
25292 complaint (&symfile_complaints
,
25293 _("A problem internal to GDB: DIE %s has type already set"),
25294 sect_offset_str (die
->sect_off
));
25295 *slot
= XOBNEW (&objfile
->objfile_obstack
,
25296 struct dwarf2_per_cu_offset_and_type
);
25301 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
25302 or return NULL if the die does not have a saved type. */
25304 static struct type
*
25305 get_die_type_at_offset (sect_offset sect_off
,
25306 struct dwarf2_per_cu_data
*per_cu
)
25308 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
25309 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
25311 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25314 ofs
.per_cu
= per_cu
;
25315 ofs
.sect_off
= sect_off
;
25316 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
25317 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
25324 /* Look up the type for DIE in CU in die_type_hash,
25325 or return NULL if DIE does not have a saved type. */
25327 static struct type
*
25328 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
25330 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
25333 /* Add a dependence relationship from CU to REF_PER_CU. */
25336 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
25337 struct dwarf2_per_cu_data
*ref_per_cu
)
25341 if (cu
->dependencies
== NULL
)
25343 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
25344 NULL
, &cu
->comp_unit_obstack
,
25345 hashtab_obstack_allocate
,
25346 dummy_obstack_deallocate
);
25348 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
25350 *slot
= ref_per_cu
;
25353 /* Subroutine of dwarf2_mark to pass to htab_traverse.
25354 Set the mark field in every compilation unit in the
25355 cache that we must keep because we are keeping CU. */
25358 dwarf2_mark_helper (void **slot
, void *data
)
25360 struct dwarf2_per_cu_data
*per_cu
;
25362 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
25364 /* cu->dependencies references may not yet have been ever read if QUIT aborts
25365 reading of the chain. As such dependencies remain valid it is not much
25366 useful to track and undo them during QUIT cleanups. */
25367 if (per_cu
->cu
== NULL
)
25370 if (per_cu
->cu
->mark
)
25372 per_cu
->cu
->mark
= 1;
25374 if (per_cu
->cu
->dependencies
!= NULL
)
25375 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25380 /* Set the mark field in CU and in every other compilation unit in the
25381 cache that we must keep because we are keeping CU. */
25384 dwarf2_mark (struct dwarf2_cu
*cu
)
25389 if (cu
->dependencies
!= NULL
)
25390 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25394 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
25398 per_cu
->cu
->mark
= 0;
25399 per_cu
= per_cu
->cu
->read_in_chain
;
25403 /* Trivial hash function for partial_die_info: the hash value of a DIE
25404 is its offset in .debug_info for this objfile. */
25407 partial_die_hash (const void *item
)
25409 const struct partial_die_info
*part_die
25410 = (const struct partial_die_info
*) item
;
25412 return to_underlying (part_die
->sect_off
);
25415 /* Trivial comparison function for partial_die_info structures: two DIEs
25416 are equal if they have the same offset. */
25419 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
25421 const struct partial_die_info
*part_die_lhs
25422 = (const struct partial_die_info
*) item_lhs
;
25423 const struct partial_die_info
*part_die_rhs
25424 = (const struct partial_die_info
*) item_rhs
;
25426 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
25429 static struct cmd_list_element
*set_dwarf_cmdlist
;
25430 static struct cmd_list_element
*show_dwarf_cmdlist
;
25433 set_dwarf_cmd (const char *args
, int from_tty
)
25435 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
25440 show_dwarf_cmd (const char *args
, int from_tty
)
25442 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
25445 int dwarf_always_disassemble
;
25448 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
25449 struct cmd_list_element
*c
, const char *value
)
25451 fprintf_filtered (file
,
25452 _("Whether to always disassemble "
25453 "DWARF expressions is %s.\n"),
25458 show_check_physname (struct ui_file
*file
, int from_tty
,
25459 struct cmd_list_element
*c
, const char *value
)
25461 fprintf_filtered (file
,
25462 _("Whether to check \"physname\" is %s.\n"),
25467 _initialize_dwarf2_read (void)
25470 dwarf2_objfile_data_key
= register_objfile_data ();
25472 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
25473 Set DWARF specific variables.\n\
25474 Configure DWARF variables such as the cache size"),
25475 &set_dwarf_cmdlist
, "maintenance set dwarf ",
25476 0/*allow-unknown*/, &maintenance_set_cmdlist
);
25478 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
25479 Show DWARF specific variables\n\
25480 Show DWARF variables such as the cache size"),
25481 &show_dwarf_cmdlist
, "maintenance show dwarf ",
25482 0/*allow-unknown*/, &maintenance_show_cmdlist
);
25484 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
25485 &dwarf_max_cache_age
, _("\
25486 Set the upper bound on the age of cached DWARF compilation units."), _("\
25487 Show the upper bound on the age of cached DWARF compilation units."), _("\
25488 A higher limit means that cached compilation units will be stored\n\
25489 in memory longer, and more total memory will be used. Zero disables\n\
25490 caching, which can slow down startup."),
25492 show_dwarf_max_cache_age
,
25493 &set_dwarf_cmdlist
,
25494 &show_dwarf_cmdlist
);
25496 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
25497 &dwarf_always_disassemble
, _("\
25498 Set whether `info address' always disassembles DWARF expressions."), _("\
25499 Show whether `info address' always disassembles DWARF expressions."), _("\
25500 When enabled, DWARF expressions are always printed in an assembly-like\n\
25501 syntax. When disabled, expressions will be printed in a more\n\
25502 conversational style, when possible."),
25504 show_dwarf_always_disassemble
,
25505 &set_dwarf_cmdlist
,
25506 &show_dwarf_cmdlist
);
25508 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
25509 Set debugging of the DWARF reader."), _("\
25510 Show debugging of the DWARF reader."), _("\
25511 When enabled (non-zero), debugging messages are printed during DWARF\n\
25512 reading and symtab expansion. A value of 1 (one) provides basic\n\
25513 information. A value greater than 1 provides more verbose information."),
25516 &setdebuglist
, &showdebuglist
);
25518 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
25519 Set debugging of the DWARF DIE reader."), _("\
25520 Show debugging of the DWARF DIE reader."), _("\
25521 When enabled (non-zero), DIEs are dumped after they are read in.\n\
25522 The value is the maximum depth to print."),
25525 &setdebuglist
, &showdebuglist
);
25527 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
25528 Set debugging of the dwarf line reader."), _("\
25529 Show debugging of the dwarf line reader."), _("\
25530 When enabled (non-zero), line number entries are dumped as they are read in.\n\
25531 A value of 1 (one) provides basic information.\n\
25532 A value greater than 1 provides more verbose information."),
25535 &setdebuglist
, &showdebuglist
);
25537 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
25538 Set cross-checking of \"physname\" code against demangler."), _("\
25539 Show cross-checking of \"physname\" code against demangler."), _("\
25540 When enabled, GDB's internal \"physname\" code is checked against\n\
25542 NULL
, show_check_physname
,
25543 &setdebuglist
, &showdebuglist
);
25545 add_setshow_boolean_cmd ("use-deprecated-index-sections",
25546 no_class
, &use_deprecated_index_sections
, _("\
25547 Set whether to use deprecated gdb_index sections."), _("\
25548 Show whether to use deprecated gdb_index sections."), _("\
25549 When enabled, deprecated .gdb_index sections are used anyway.\n\
25550 Normally they are ignored either because of a missing feature or\n\
25551 performance issue.\n\
25552 Warning: This option must be enabled before gdb reads the file."),
25555 &setlist
, &showlist
);
25557 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25558 &dwarf2_locexpr_funcs
);
25559 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25560 &dwarf2_loclist_funcs
);
25562 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25563 &dwarf2_block_frame_base_locexpr_funcs
);
25564 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25565 &dwarf2_block_frame_base_loclist_funcs
);
25568 selftests::register_test ("dw2_expand_symtabs_matching",
25569 selftests::dw2_expand_symtabs_matching::run_test
);