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 total length of the buffer. */
203 /* The address table data. */
204 gdb::array_view
<const gdb_byte
> address_table
;
206 /* The symbol table, implemented as a hash table. */
207 gdb::array_view
<symbol_table_slot
> symbol_table
;
209 /* A pointer to the constant pool. */
210 const char *constant_pool
;
212 bool symbol_name_slot_invalid (offset_type idx
) const override
214 const auto &bucket
= this->symbol_table
[idx
];
215 return bucket
.name
== 0 && bucket
.vec
;
218 /* Convenience method to get at the name of the symbol at IDX in the
220 const char *symbol_name_at (offset_type idx
) const override
221 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
223 size_t symbol_name_count () const override
224 { return this->symbol_table
.size (); }
227 /* A description of the mapped .debug_names.
228 Uninitialized map has CU_COUNT 0. */
229 struct mapped_debug_names final
: public mapped_index_base
231 mapped_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile_
)
232 : dwarf2_per_objfile (dwarf2_per_objfile_
)
235 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
236 bfd_endian dwarf5_byte_order
;
237 bool dwarf5_is_dwarf64
;
238 bool augmentation_is_gdb
;
240 uint32_t cu_count
= 0;
241 uint32_t tu_count
, bucket_count
, name_count
;
242 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
243 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
244 const gdb_byte
*name_table_string_offs_reordered
;
245 const gdb_byte
*name_table_entry_offs_reordered
;
246 const gdb_byte
*entry_pool
;
253 /* Attribute name DW_IDX_*. */
256 /* Attribute form DW_FORM_*. */
259 /* Value if FORM is DW_FORM_implicit_const. */
260 LONGEST implicit_const
;
262 std::vector
<attr
> attr_vec
;
265 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
267 const char *namei_to_name (uint32_t namei
) const;
269 /* Implementation of the mapped_index_base virtual interface, for
270 the name_components cache. */
272 const char *symbol_name_at (offset_type idx
) const override
273 { return namei_to_name (idx
); }
275 size_t symbol_name_count () const override
276 { return this->name_count
; }
279 /* See dwarf2read.h. */
282 get_dwarf2_per_objfile (struct objfile
*objfile
)
284 return ((struct dwarf2_per_objfile
*)
285 objfile_data (objfile
, dwarf2_objfile_data_key
));
288 /* Set the dwarf2_per_objfile associated to OBJFILE. */
291 set_dwarf2_per_objfile (struct objfile
*objfile
,
292 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
294 gdb_assert (get_dwarf2_per_objfile (objfile
) == NULL
);
295 set_objfile_data (objfile
, dwarf2_objfile_data_key
, dwarf2_per_objfile
);
298 /* Default names of the debugging sections. */
300 /* Note that if the debugging section has been compressed, it might
301 have a name like .zdebug_info. */
303 static const struct dwarf2_debug_sections dwarf2_elf_names
=
305 { ".debug_info", ".zdebug_info" },
306 { ".debug_abbrev", ".zdebug_abbrev" },
307 { ".debug_line", ".zdebug_line" },
308 { ".debug_loc", ".zdebug_loc" },
309 { ".debug_loclists", ".zdebug_loclists" },
310 { ".debug_macinfo", ".zdebug_macinfo" },
311 { ".debug_macro", ".zdebug_macro" },
312 { ".debug_str", ".zdebug_str" },
313 { ".debug_line_str", ".zdebug_line_str" },
314 { ".debug_ranges", ".zdebug_ranges" },
315 { ".debug_rnglists", ".zdebug_rnglists" },
316 { ".debug_types", ".zdebug_types" },
317 { ".debug_addr", ".zdebug_addr" },
318 { ".debug_frame", ".zdebug_frame" },
319 { ".eh_frame", NULL
},
320 { ".gdb_index", ".zgdb_index" },
321 { ".debug_names", ".zdebug_names" },
322 { ".debug_aranges", ".zdebug_aranges" },
326 /* List of DWO/DWP sections. */
328 static const struct dwop_section_names
330 struct dwarf2_section_names abbrev_dwo
;
331 struct dwarf2_section_names info_dwo
;
332 struct dwarf2_section_names line_dwo
;
333 struct dwarf2_section_names loc_dwo
;
334 struct dwarf2_section_names loclists_dwo
;
335 struct dwarf2_section_names macinfo_dwo
;
336 struct dwarf2_section_names macro_dwo
;
337 struct dwarf2_section_names str_dwo
;
338 struct dwarf2_section_names str_offsets_dwo
;
339 struct dwarf2_section_names types_dwo
;
340 struct dwarf2_section_names cu_index
;
341 struct dwarf2_section_names tu_index
;
345 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
346 { ".debug_info.dwo", ".zdebug_info.dwo" },
347 { ".debug_line.dwo", ".zdebug_line.dwo" },
348 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
349 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
350 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
351 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
352 { ".debug_str.dwo", ".zdebug_str.dwo" },
353 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
354 { ".debug_types.dwo", ".zdebug_types.dwo" },
355 { ".debug_cu_index", ".zdebug_cu_index" },
356 { ".debug_tu_index", ".zdebug_tu_index" },
359 /* local data types */
361 /* The data in a compilation unit header, after target2host
362 translation, looks like this. */
363 struct comp_unit_head
367 unsigned char addr_size
;
368 unsigned char signed_addr_p
;
369 sect_offset abbrev_sect_off
;
371 /* Size of file offsets; either 4 or 8. */
372 unsigned int offset_size
;
374 /* Size of the length field; either 4 or 12. */
375 unsigned int initial_length_size
;
377 enum dwarf_unit_type unit_type
;
379 /* Offset to the first byte of this compilation unit header in the
380 .debug_info section, for resolving relative reference dies. */
381 sect_offset sect_off
;
383 /* Offset to first die in this cu from the start of the cu.
384 This will be the first byte following the compilation unit header. */
385 cu_offset first_die_cu_offset
;
387 /* 64-bit signature of this type unit - it is valid only for
388 UNIT_TYPE DW_UT_type. */
391 /* For types, offset in the type's DIE of the type defined by this TU. */
392 cu_offset type_cu_offset_in_tu
;
395 /* Type used for delaying computation of method physnames.
396 See comments for compute_delayed_physnames. */
397 struct delayed_method_info
399 /* The type to which the method is attached, i.e., its parent class. */
402 /* The index of the method in the type's function fieldlists. */
405 /* The index of the method in the fieldlist. */
408 /* The name of the DIE. */
411 /* The DIE associated with this method. */
412 struct die_info
*die
;
415 /* Internal state when decoding a particular compilation unit. */
418 explicit dwarf2_cu (struct dwarf2_per_cu_data
*per_cu
);
421 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
423 /* The header of the compilation unit. */
424 struct comp_unit_head header
{};
426 /* Base address of this compilation unit. */
427 CORE_ADDR base_address
= 0;
429 /* Non-zero if base_address has been set. */
432 /* The language we are debugging. */
433 enum language language
= language_unknown
;
434 const struct language_defn
*language_defn
= nullptr;
436 const char *producer
= nullptr;
438 /* The generic symbol table building routines have separate lists for
439 file scope symbols and all all other scopes (local scopes). So
440 we need to select the right one to pass to add_symbol_to_list().
441 We do it by keeping a pointer to the correct list in list_in_scope.
443 FIXME: The original dwarf code just treated the file scope as the
444 first local scope, and all other local scopes as nested local
445 scopes, and worked fine. Check to see if we really need to
446 distinguish these in buildsym.c. */
447 struct pending
**list_in_scope
= nullptr;
449 /* Hash table holding all the loaded partial DIEs
450 with partial_die->offset.SECT_OFF as hash. */
451 htab_t partial_dies
= nullptr;
453 /* Storage for things with the same lifetime as this read-in compilation
454 unit, including partial DIEs. */
455 auto_obstack comp_unit_obstack
;
457 /* When multiple dwarf2_cu structures are living in memory, this field
458 chains them all together, so that they can be released efficiently.
459 We will probably also want a generation counter so that most-recently-used
460 compilation units are cached... */
461 struct dwarf2_per_cu_data
*read_in_chain
= nullptr;
463 /* Backlink to our per_cu entry. */
464 struct dwarf2_per_cu_data
*per_cu
;
466 /* How many compilation units ago was this CU last referenced? */
469 /* A hash table of DIE cu_offset for following references with
470 die_info->offset.sect_off as hash. */
471 htab_t die_hash
= nullptr;
473 /* Full DIEs if read in. */
474 struct die_info
*dies
= nullptr;
476 /* A set of pointers to dwarf2_per_cu_data objects for compilation
477 units referenced by this one. Only set during full symbol processing;
478 partial symbol tables do not have dependencies. */
479 htab_t dependencies
= nullptr;
481 /* Header data from the line table, during full symbol processing. */
482 struct line_header
*line_header
= nullptr;
483 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
484 it's owned by dwarf2_per_objfile::line_header_hash. If non-NULL,
485 this is the DW_TAG_compile_unit die for this CU. We'll hold on
486 to the line header as long as this DIE is being processed. See
487 process_die_scope. */
488 die_info
*line_header_die_owner
= nullptr;
490 /* A list of methods which need to have physnames computed
491 after all type information has been read. */
492 std::vector
<delayed_method_info
> method_list
;
494 /* To be copied to symtab->call_site_htab. */
495 htab_t call_site_htab
= nullptr;
497 /* Non-NULL if this CU came from a DWO file.
498 There is an invariant here that is important to remember:
499 Except for attributes copied from the top level DIE in the "main"
500 (or "stub") file in preparation for reading the DWO file
501 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
502 Either there isn't a DWO file (in which case this is NULL and the point
503 is moot), or there is and either we're not going to read it (in which
504 case this is NULL) or there is and we are reading it (in which case this
506 struct dwo_unit
*dwo_unit
= nullptr;
508 /* The DW_AT_addr_base attribute if present, zero otherwise
509 (zero is a valid value though).
510 Note this value comes from the Fission stub CU/TU's DIE. */
511 ULONGEST addr_base
= 0;
513 /* The DW_AT_ranges_base attribute if present, zero otherwise
514 (zero is a valid value though).
515 Note this value comes from the Fission stub CU/TU's DIE.
516 Also note that the value is zero in the non-DWO case so this value can
517 be used without needing to know whether DWO files are in use or not.
518 N.B. This does not apply to DW_AT_ranges appearing in
519 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
520 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
521 DW_AT_ranges_base *would* have to be applied, and we'd have to care
522 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
523 ULONGEST ranges_base
= 0;
525 /* When reading debug info generated by older versions of rustc, we
526 have to rewrite some union types to be struct types with a
527 variant part. This rewriting must be done after the CU is fully
528 read in, because otherwise at the point of rewriting some struct
529 type might not have been fully processed. So, we keep a list of
530 all such types here and process them after expansion. */
531 std::vector
<struct type
*> rust_unions
;
533 /* Mark used when releasing cached dies. */
534 unsigned int mark
: 1;
536 /* This CU references .debug_loc. See the symtab->locations_valid field.
537 This test is imperfect as there may exist optimized debug code not using
538 any location list and still facing inlining issues if handled as
539 unoptimized code. For a future better test see GCC PR other/32998. */
540 unsigned int has_loclist
: 1;
542 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is set
543 if all the producer_is_* fields are valid. This information is cached
544 because profiling CU expansion showed excessive time spent in
545 producer_is_gxx_lt_4_6. */
546 unsigned int checked_producer
: 1;
547 unsigned int producer_is_gxx_lt_4_6
: 1;
548 unsigned int producer_is_gcc_lt_4_3
: 1;
549 unsigned int producer_is_icc_lt_14
: 1;
551 /* When set, the file that we're processing is known to have
552 debugging info for C++ namespaces. GCC 3.3.x did not produce
553 this information, but later versions do. */
555 unsigned int processing_has_namespace_info
: 1;
557 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
560 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
561 This includes type_unit_group and quick_file_names. */
563 struct stmt_list_hash
565 /* The DWO unit this table is from or NULL if there is none. */
566 struct dwo_unit
*dwo_unit
;
568 /* Offset in .debug_line or .debug_line.dwo. */
569 sect_offset line_sect_off
;
572 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
573 an object of this type. */
575 struct type_unit_group
577 /* dwarf2read.c's main "handle" on a TU symtab.
578 To simplify things we create an artificial CU that "includes" all the
579 type units using this stmt_list so that the rest of the code still has
580 a "per_cu" handle on the symtab.
581 This PER_CU is recognized by having no section. */
582 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->section == NULL)
583 struct dwarf2_per_cu_data per_cu
;
585 /* The TUs that share this DW_AT_stmt_list entry.
586 This is added to while parsing type units to build partial symtabs,
587 and is deleted afterwards and not used again. */
588 VEC (sig_type_ptr
) *tus
;
590 /* The compunit symtab.
591 Type units in a group needn't all be defined in the same source file,
592 so we create an essentially anonymous symtab as the compunit symtab. */
593 struct compunit_symtab
*compunit_symtab
;
595 /* The data used to construct the hash key. */
596 struct stmt_list_hash hash
;
598 /* The number of symtabs from the line header.
599 The value here must match line_header.num_file_names. */
600 unsigned int num_symtabs
;
602 /* The symbol tables for this TU (obtained from the files listed in
604 WARNING: The order of entries here must match the order of entries
605 in the line header. After the first TU using this type_unit_group, the
606 line header for the subsequent TUs is recreated from this. This is done
607 because we need to use the same symtabs for each TU using the same
608 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
609 there's no guarantee the line header doesn't have duplicate entries. */
610 struct symtab
**symtabs
;
613 /* These sections are what may appear in a (real or virtual) DWO file. */
617 struct dwarf2_section_info abbrev
;
618 struct dwarf2_section_info line
;
619 struct dwarf2_section_info loc
;
620 struct dwarf2_section_info loclists
;
621 struct dwarf2_section_info macinfo
;
622 struct dwarf2_section_info macro
;
623 struct dwarf2_section_info str
;
624 struct dwarf2_section_info str_offsets
;
625 /* In the case of a virtual DWO file, these two are unused. */
626 struct dwarf2_section_info info
;
627 VEC (dwarf2_section_info_def
) *types
;
630 /* CUs/TUs in DWP/DWO files. */
634 /* Backlink to the containing struct dwo_file. */
635 struct dwo_file
*dwo_file
;
637 /* The "id" that distinguishes this CU/TU.
638 .debug_info calls this "dwo_id", .debug_types calls this "signature".
639 Since signatures came first, we stick with it for consistency. */
642 /* The section this CU/TU lives in, in the DWO file. */
643 struct dwarf2_section_info
*section
;
645 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
646 sect_offset sect_off
;
649 /* For types, offset in the type's DIE of the type defined by this TU. */
650 cu_offset type_offset_in_tu
;
653 /* include/dwarf2.h defines the DWP section codes.
654 It defines a max value but it doesn't define a min value, which we
655 use for error checking, so provide one. */
657 enum dwp_v2_section_ids
662 /* Data for one DWO file.
664 This includes virtual DWO files (a virtual DWO file is a DWO file as it
665 appears in a DWP file). DWP files don't really have DWO files per se -
666 comdat folding of types "loses" the DWO file they came from, and from
667 a high level view DWP files appear to contain a mass of random types.
668 However, to maintain consistency with the non-DWP case we pretend DWP
669 files contain virtual DWO files, and we assign each TU with one virtual
670 DWO file (generally based on the line and abbrev section offsets -
671 a heuristic that seems to work in practice). */
675 /* The DW_AT_GNU_dwo_name attribute.
676 For virtual DWO files the name is constructed from the section offsets
677 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
678 from related CU+TUs. */
679 const char *dwo_name
;
681 /* The DW_AT_comp_dir attribute. */
682 const char *comp_dir
;
684 /* The bfd, when the file is open. Otherwise this is NULL.
685 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
688 /* The sections that make up this DWO file.
689 Remember that for virtual DWO files in DWP V2, these are virtual
690 sections (for lack of a better name). */
691 struct dwo_sections sections
;
693 /* The CUs in the file.
694 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
695 an extension to handle LLVM's Link Time Optimization output (where
696 multiple source files may be compiled into a single object/dwo pair). */
699 /* Table of TUs in the file.
700 Each element is a struct dwo_unit. */
704 /* These sections are what may appear in a DWP file. */
708 /* These are used by both DWP version 1 and 2. */
709 struct dwarf2_section_info str
;
710 struct dwarf2_section_info cu_index
;
711 struct dwarf2_section_info tu_index
;
713 /* These are only used by DWP version 2 files.
714 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
715 sections are referenced by section number, and are not recorded here.
716 In DWP version 2 there is at most one copy of all these sections, each
717 section being (effectively) comprised of the concatenation of all of the
718 individual sections that exist in the version 1 format.
719 To keep the code simple we treat each of these concatenated pieces as a
720 section itself (a virtual section?). */
721 struct dwarf2_section_info abbrev
;
722 struct dwarf2_section_info info
;
723 struct dwarf2_section_info line
;
724 struct dwarf2_section_info loc
;
725 struct dwarf2_section_info macinfo
;
726 struct dwarf2_section_info macro
;
727 struct dwarf2_section_info str_offsets
;
728 struct dwarf2_section_info types
;
731 /* These sections are what may appear in a virtual DWO file in DWP version 1.
732 A virtual DWO file is a DWO file as it appears in a DWP file. */
734 struct virtual_v1_dwo_sections
736 struct dwarf2_section_info abbrev
;
737 struct dwarf2_section_info line
;
738 struct dwarf2_section_info loc
;
739 struct dwarf2_section_info macinfo
;
740 struct dwarf2_section_info macro
;
741 struct dwarf2_section_info str_offsets
;
742 /* Each DWP hash table entry records one CU or one TU.
743 That is recorded here, and copied to dwo_unit.section. */
744 struct dwarf2_section_info info_or_types
;
747 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
748 In version 2, the sections of the DWO files are concatenated together
749 and stored in one section of that name. Thus each ELF section contains
750 several "virtual" sections. */
752 struct virtual_v2_dwo_sections
754 bfd_size_type abbrev_offset
;
755 bfd_size_type abbrev_size
;
757 bfd_size_type line_offset
;
758 bfd_size_type line_size
;
760 bfd_size_type loc_offset
;
761 bfd_size_type loc_size
;
763 bfd_size_type macinfo_offset
;
764 bfd_size_type macinfo_size
;
766 bfd_size_type macro_offset
;
767 bfd_size_type macro_size
;
769 bfd_size_type str_offsets_offset
;
770 bfd_size_type str_offsets_size
;
772 /* Each DWP hash table entry records one CU or one TU.
773 That is recorded here, and copied to dwo_unit.section. */
774 bfd_size_type info_or_types_offset
;
775 bfd_size_type info_or_types_size
;
778 /* Contents of DWP hash tables. */
780 struct dwp_hash_table
782 uint32_t version
, nr_columns
;
783 uint32_t nr_units
, nr_slots
;
784 const gdb_byte
*hash_table
, *unit_table
;
789 const gdb_byte
*indices
;
793 /* This is indexed by column number and gives the id of the section
795 #define MAX_NR_V2_DWO_SECTIONS \
796 (1 /* .debug_info or .debug_types */ \
797 + 1 /* .debug_abbrev */ \
798 + 1 /* .debug_line */ \
799 + 1 /* .debug_loc */ \
800 + 1 /* .debug_str_offsets */ \
801 + 1 /* .debug_macro or .debug_macinfo */)
802 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
803 const gdb_byte
*offsets
;
804 const gdb_byte
*sizes
;
809 /* Data for one DWP file. */
813 /* Name of the file. */
816 /* File format version. */
822 /* Section info for this file. */
823 struct dwp_sections sections
;
825 /* Table of CUs in the file. */
826 const struct dwp_hash_table
*cus
;
828 /* Table of TUs in the file. */
829 const struct dwp_hash_table
*tus
;
831 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
835 /* Table to map ELF section numbers to their sections.
836 This is only needed for the DWP V1 file format. */
837 unsigned int num_sections
;
838 asection
**elf_sections
;
841 /* This represents a '.dwz' file. */
845 /* A dwz file can only contain a few sections. */
846 struct dwarf2_section_info abbrev
;
847 struct dwarf2_section_info info
;
848 struct dwarf2_section_info str
;
849 struct dwarf2_section_info line
;
850 struct dwarf2_section_info macro
;
851 struct dwarf2_section_info gdb_index
;
852 struct dwarf2_section_info debug_names
;
858 /* Struct used to pass misc. parameters to read_die_and_children, et
859 al. which are used for both .debug_info and .debug_types dies.
860 All parameters here are unchanging for the life of the call. This
861 struct exists to abstract away the constant parameters of die reading. */
863 struct die_reader_specs
865 /* The bfd of die_section. */
868 /* The CU of the DIE we are parsing. */
869 struct dwarf2_cu
*cu
;
871 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
872 struct dwo_file
*dwo_file
;
874 /* The section the die comes from.
875 This is either .debug_info or .debug_types, or the .dwo variants. */
876 struct dwarf2_section_info
*die_section
;
878 /* die_section->buffer. */
879 const gdb_byte
*buffer
;
881 /* The end of the buffer. */
882 const gdb_byte
*buffer_end
;
884 /* The value of the DW_AT_comp_dir attribute. */
885 const char *comp_dir
;
887 /* The abbreviation table to use when reading the DIEs. */
888 struct abbrev_table
*abbrev_table
;
891 /* Type of function passed to init_cutu_and_read_dies, et.al. */
892 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
893 const gdb_byte
*info_ptr
,
894 struct die_info
*comp_unit_die
,
898 /* A 1-based directory index. This is a strong typedef to prevent
899 accidentally using a directory index as a 0-based index into an
901 enum class dir_index
: unsigned int {};
903 /* Likewise, a 1-based file name index. */
904 enum class file_name_index
: unsigned int {};
908 file_entry () = default;
910 file_entry (const char *name_
, dir_index d_index_
,
911 unsigned int mod_time_
, unsigned int length_
)
914 mod_time (mod_time_
),
918 /* Return the include directory at D_INDEX stored in LH. Returns
919 NULL if D_INDEX is out of bounds. */
920 const char *include_dir (const line_header
*lh
) const;
922 /* The file name. Note this is an observing pointer. The memory is
923 owned by debug_line_buffer. */
926 /* The directory index (1-based). */
927 dir_index d_index
{};
929 unsigned int mod_time
{};
931 unsigned int length
{};
933 /* True if referenced by the Line Number Program. */
936 /* The associated symbol table, if any. */
937 struct symtab
*symtab
{};
940 /* The line number information for a compilation unit (found in the
941 .debug_line section) begins with a "statement program header",
942 which contains the following information. */
949 /* Add an entry to the include directory table. */
950 void add_include_dir (const char *include_dir
);
952 /* Add an entry to the file name table. */
953 void add_file_name (const char *name
, dir_index d_index
,
954 unsigned int mod_time
, unsigned int length
);
956 /* Return the include dir at INDEX (1-based). Returns NULL if INDEX
958 const char *include_dir_at (dir_index index
) const
960 /* Convert directory index number (1-based) to vector index
962 size_t vec_index
= to_underlying (index
) - 1;
964 if (vec_index
>= include_dirs
.size ())
966 return include_dirs
[vec_index
];
969 /* Return the file name at INDEX (1-based). Returns NULL if INDEX
971 file_entry
*file_name_at (file_name_index index
)
973 /* Convert file name index number (1-based) to vector index
975 size_t vec_index
= to_underlying (index
) - 1;
977 if (vec_index
>= file_names
.size ())
979 return &file_names
[vec_index
];
982 /* Const version of the above. */
983 const file_entry
*file_name_at (unsigned int index
) const
985 if (index
>= file_names
.size ())
987 return &file_names
[index
];
990 /* Offset of line number information in .debug_line section. */
991 sect_offset sect_off
{};
993 /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile. */
994 unsigned offset_in_dwz
: 1; /* Can't initialize bitfields in-class. */
996 unsigned int total_length
{};
997 unsigned short version
{};
998 unsigned int header_length
{};
999 unsigned char minimum_instruction_length
{};
1000 unsigned char maximum_ops_per_instruction
{};
1001 unsigned char default_is_stmt
{};
1003 unsigned char line_range
{};
1004 unsigned char opcode_base
{};
1006 /* standard_opcode_lengths[i] is the number of operands for the
1007 standard opcode whose value is i. This means that
1008 standard_opcode_lengths[0] is unused, and the last meaningful
1009 element is standard_opcode_lengths[opcode_base - 1]. */
1010 std::unique_ptr
<unsigned char[]> standard_opcode_lengths
;
1012 /* The include_directories table. Note these are observing
1013 pointers. The memory is owned by debug_line_buffer. */
1014 std::vector
<const char *> include_dirs
;
1016 /* The file_names table. */
1017 std::vector
<file_entry
> file_names
;
1019 /* The start and end of the statement program following this
1020 header. These point into dwarf2_per_objfile->line_buffer. */
1021 const gdb_byte
*statement_program_start
{}, *statement_program_end
{};
1024 typedef std::unique_ptr
<line_header
> line_header_up
;
1027 file_entry::include_dir (const line_header
*lh
) const
1029 return lh
->include_dir_at (d_index
);
1032 /* When we construct a partial symbol table entry we only
1033 need this much information. */
1034 struct partial_die_info
: public allocate_on_obstack
1036 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
1038 /* Disable assign but still keep copy ctor, which is needed
1039 load_partial_dies. */
1040 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
1042 /* Adjust the partial die before generating a symbol for it. This
1043 function may set the is_external flag or change the DIE's
1045 void fixup (struct dwarf2_cu
*cu
);
1047 /* Read a minimal amount of information into the minimal die
1049 const gdb_byte
*read (const struct die_reader_specs
*reader
,
1050 const struct abbrev_info
&abbrev
,
1051 const gdb_byte
*info_ptr
);
1053 /* Offset of this DIE. */
1054 const sect_offset sect_off
;
1056 /* DWARF-2 tag for this DIE. */
1057 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1059 /* Assorted flags describing the data found in this DIE. */
1060 const unsigned int has_children
: 1;
1062 unsigned int is_external
: 1;
1063 unsigned int is_declaration
: 1;
1064 unsigned int has_type
: 1;
1065 unsigned int has_specification
: 1;
1066 unsigned int has_pc_info
: 1;
1067 unsigned int may_be_inlined
: 1;
1069 /* This DIE has been marked DW_AT_main_subprogram. */
1070 unsigned int main_subprogram
: 1;
1072 /* Flag set if the SCOPE field of this structure has been
1074 unsigned int scope_set
: 1;
1076 /* Flag set if the DIE has a byte_size attribute. */
1077 unsigned int has_byte_size
: 1;
1079 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1080 unsigned int has_const_value
: 1;
1082 /* Flag set if any of the DIE's children are template arguments. */
1083 unsigned int has_template_arguments
: 1;
1085 /* Flag set if fixup has been called on this die. */
1086 unsigned int fixup_called
: 1;
1088 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1089 unsigned int is_dwz
: 1;
1091 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1092 unsigned int spec_is_dwz
: 1;
1094 /* The name of this DIE. Normally the value of DW_AT_name, but
1095 sometimes a default name for unnamed DIEs. */
1096 const char *name
= nullptr;
1098 /* The linkage name, if present. */
1099 const char *linkage_name
= nullptr;
1101 /* The scope to prepend to our children. This is generally
1102 allocated on the comp_unit_obstack, so will disappear
1103 when this compilation unit leaves the cache. */
1104 const char *scope
= nullptr;
1106 /* Some data associated with the partial DIE. The tag determines
1107 which field is live. */
1110 /* The location description associated with this DIE, if any. */
1111 struct dwarf_block
*locdesc
;
1112 /* The offset of an import, for DW_TAG_imported_unit. */
1113 sect_offset sect_off
;
1116 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1117 CORE_ADDR lowpc
= 0;
1118 CORE_ADDR highpc
= 0;
1120 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1121 DW_AT_sibling, if any. */
1122 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1123 could return DW_AT_sibling values to its caller load_partial_dies. */
1124 const gdb_byte
*sibling
= nullptr;
1126 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1127 DW_AT_specification (or DW_AT_abstract_origin or
1128 DW_AT_extension). */
1129 sect_offset spec_offset
{};
1131 /* Pointers to this DIE's parent, first child, and next sibling,
1133 struct partial_die_info
*die_parent
= nullptr;
1134 struct partial_die_info
*die_child
= nullptr;
1135 struct partial_die_info
*die_sibling
= nullptr;
1137 friend struct partial_die_info
*
1138 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1141 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1142 partial_die_info (sect_offset sect_off
)
1143 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1147 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1149 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1154 has_specification
= 0;
1157 main_subprogram
= 0;
1160 has_const_value
= 0;
1161 has_template_arguments
= 0;
1168 /* This data structure holds the information of an abbrev. */
1171 unsigned int number
; /* number identifying abbrev */
1172 enum dwarf_tag tag
; /* dwarf tag */
1173 unsigned short has_children
; /* boolean */
1174 unsigned short num_attrs
; /* number of attributes */
1175 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
1176 struct abbrev_info
*next
; /* next in chain */
1181 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1182 ENUM_BITFIELD(dwarf_form
) form
: 16;
1184 /* It is valid only if FORM is DW_FORM_implicit_const. */
1185 LONGEST implicit_const
;
1188 /* Size of abbrev_table.abbrev_hash_table. */
1189 #define ABBREV_HASH_SIZE 121
1191 /* Top level data structure to contain an abbreviation table. */
1195 explicit abbrev_table (sect_offset off
)
1199 XOBNEWVEC (&abbrev_obstack
, struct abbrev_info
*, ABBREV_HASH_SIZE
);
1200 memset (m_abbrevs
, 0, ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
1203 DISABLE_COPY_AND_ASSIGN (abbrev_table
);
1205 /* Allocate space for a struct abbrev_info object in
1207 struct abbrev_info
*alloc_abbrev ();
1209 /* Add an abbreviation to the table. */
1210 void add_abbrev (unsigned int abbrev_number
, struct abbrev_info
*abbrev
);
1212 /* Look up an abbrev in the table.
1213 Returns NULL if the abbrev is not found. */
1215 struct abbrev_info
*lookup_abbrev (unsigned int abbrev_number
);
1218 /* Where the abbrev table came from.
1219 This is used as a sanity check when the table is used. */
1220 const sect_offset sect_off
;
1222 /* Storage for the abbrev table. */
1223 auto_obstack abbrev_obstack
;
1227 /* Hash table of abbrevs.
1228 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1229 It could be statically allocated, but the previous code didn't so we
1231 struct abbrev_info
**m_abbrevs
;
1234 typedef std::unique_ptr
<struct abbrev_table
> abbrev_table_up
;
1236 /* Attributes have a name and a value. */
1239 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1240 ENUM_BITFIELD(dwarf_form
) form
: 15;
1242 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1243 field should be in u.str (existing only for DW_STRING) but it is kept
1244 here for better struct attribute alignment. */
1245 unsigned int string_is_canonical
: 1;
1250 struct dwarf_block
*blk
;
1259 /* This data structure holds a complete die structure. */
1262 /* DWARF-2 tag for this DIE. */
1263 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1265 /* Number of attributes */
1266 unsigned char num_attrs
;
1268 /* True if we're presently building the full type name for the
1269 type derived from this DIE. */
1270 unsigned char building_fullname
: 1;
1272 /* True if this die is in process. PR 16581. */
1273 unsigned char in_process
: 1;
1276 unsigned int abbrev
;
1278 /* Offset in .debug_info or .debug_types section. */
1279 sect_offset sect_off
;
1281 /* The dies in a compilation unit form an n-ary tree. PARENT
1282 points to this die's parent; CHILD points to the first child of
1283 this node; and all the children of a given node are chained
1284 together via their SIBLING fields. */
1285 struct die_info
*child
; /* Its first child, if any. */
1286 struct die_info
*sibling
; /* Its next sibling, if any. */
1287 struct die_info
*parent
; /* Its parent, if any. */
1289 /* An array of attributes, with NUM_ATTRS elements. There may be
1290 zero, but it's not common and zero-sized arrays are not
1291 sufficiently portable C. */
1292 struct attribute attrs
[1];
1295 /* Get at parts of an attribute structure. */
1297 #define DW_STRING(attr) ((attr)->u.str)
1298 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1299 #define DW_UNSND(attr) ((attr)->u.unsnd)
1300 #define DW_BLOCK(attr) ((attr)->u.blk)
1301 #define DW_SND(attr) ((attr)->u.snd)
1302 #define DW_ADDR(attr) ((attr)->u.addr)
1303 #define DW_SIGNATURE(attr) ((attr)->u.signature)
1305 /* Blocks are a bunch of untyped bytes. */
1310 /* Valid only if SIZE is not zero. */
1311 const gdb_byte
*data
;
1314 #ifndef ATTR_ALLOC_CHUNK
1315 #define ATTR_ALLOC_CHUNK 4
1318 /* Allocate fields for structs, unions and enums in this size. */
1319 #ifndef DW_FIELD_ALLOC_CHUNK
1320 #define DW_FIELD_ALLOC_CHUNK 4
1323 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1324 but this would require a corresponding change in unpack_field_as_long
1326 static int bits_per_byte
= 8;
1328 /* When reading a variant or variant part, we track a bit more
1329 information about the field, and store it in an object of this
1332 struct variant_field
1334 /* If we see a DW_TAG_variant, then this will be the discriminant
1336 ULONGEST discriminant_value
;
1337 /* If we see a DW_TAG_variant, then this will be set if this is the
1339 bool default_branch
;
1340 /* While reading a DW_TAG_variant_part, this will be set if this
1341 field is the discriminant. */
1342 bool is_discriminant
;
1347 int accessibility
= 0;
1349 /* Extra information to describe a variant or variant part. */
1350 struct variant_field variant
{};
1351 struct field field
{};
1356 const char *name
= nullptr;
1357 std::vector
<struct fn_field
> fnfields
;
1360 /* The routines that read and process dies for a C struct or C++ class
1361 pass lists of data member fields and lists of member function fields
1362 in an instance of a field_info structure, as defined below. */
1365 /* List of data member and baseclasses fields. */
1366 std::vector
<struct nextfield
> fields
;
1367 std::vector
<struct nextfield
> baseclasses
;
1369 /* Number of fields (including baseclasses). */
1372 /* Set if the accesibility of one of the fields is not public. */
1373 int non_public_fields
= 0;
1375 /* Member function fieldlist array, contains name of possibly overloaded
1376 member function, number of overloaded member functions and a pointer
1377 to the head of the member function field chain. */
1378 std::vector
<struct fnfieldlist
> fnfieldlists
;
1380 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1381 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1382 std::vector
<struct decl_field
> typedef_field_list
;
1384 /* Nested types defined by this class and the number of elements in this
1386 std::vector
<struct decl_field
> nested_types_list
;
1389 /* One item on the queue of compilation units to read in full symbols
1391 struct dwarf2_queue_item
1393 struct dwarf2_per_cu_data
*per_cu
;
1394 enum language pretend_language
;
1395 struct dwarf2_queue_item
*next
;
1398 /* The current queue. */
1399 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1401 /* Loaded secondary compilation units are kept in memory until they
1402 have not been referenced for the processing of this many
1403 compilation units. Set this to zero to disable caching. Cache
1404 sizes of up to at least twenty will improve startup time for
1405 typical inter-CU-reference binaries, at an obvious memory cost. */
1406 static int dwarf_max_cache_age
= 5;
1408 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1409 struct cmd_list_element
*c
, const char *value
)
1411 fprintf_filtered (file
, _("The upper bound on the age of cached "
1412 "DWARF compilation units is %s.\n"),
1416 /* local function prototypes */
1418 static const char *get_section_name (const struct dwarf2_section_info
*);
1420 static const char *get_section_file_name (const struct dwarf2_section_info
*);
1422 static void dwarf2_find_base_address (struct die_info
*die
,
1423 struct dwarf2_cu
*cu
);
1425 static struct partial_symtab
*create_partial_symtab
1426 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1428 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1429 const gdb_byte
*info_ptr
,
1430 struct die_info
*type_unit_die
,
1431 int has_children
, void *data
);
1433 static void dwarf2_build_psymtabs_hard
1434 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1436 static void scan_partial_symbols (struct partial_die_info
*,
1437 CORE_ADDR
*, CORE_ADDR
*,
1438 int, struct dwarf2_cu
*);
1440 static void add_partial_symbol (struct partial_die_info
*,
1441 struct dwarf2_cu
*);
1443 static void add_partial_namespace (struct partial_die_info
*pdi
,
1444 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1445 int set_addrmap
, struct dwarf2_cu
*cu
);
1447 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1448 CORE_ADDR
*highpc
, int set_addrmap
,
1449 struct dwarf2_cu
*cu
);
1451 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1452 struct dwarf2_cu
*cu
);
1454 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1455 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1456 int need_pc
, struct dwarf2_cu
*cu
);
1458 static void dwarf2_read_symtab (struct partial_symtab
*,
1461 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1463 static abbrev_table_up abbrev_table_read_table
1464 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, struct dwarf2_section_info
*,
1467 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1469 static struct partial_die_info
*load_partial_dies
1470 (const struct die_reader_specs
*, const gdb_byte
*, int);
1472 static struct partial_die_info
*find_partial_die (sect_offset
, int,
1473 struct dwarf2_cu
*);
1475 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1476 struct attribute
*, struct attr_abbrev
*,
1479 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1481 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1483 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1485 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1487 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1489 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1492 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1494 static LONGEST read_checked_initial_length_and_offset
1495 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1496 unsigned int *, unsigned int *);
1498 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1499 const struct comp_unit_head
*,
1502 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1504 static sect_offset read_abbrev_offset
1505 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1506 struct dwarf2_section_info
*, sect_offset
);
1508 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1510 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1512 static const char *read_indirect_string
1513 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1514 const struct comp_unit_head
*, unsigned int *);
1516 static const char *read_indirect_line_string
1517 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1518 const struct comp_unit_head
*, unsigned int *);
1520 static const char *read_indirect_string_at_offset
1521 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
1522 LONGEST str_offset
);
1524 static const char *read_indirect_string_from_dwz
1525 (struct objfile
*objfile
, struct dwz_file
*, LONGEST
);
1527 static LONGEST
read_signed_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1529 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1533 static const char *read_str_index (const struct die_reader_specs
*reader
,
1534 ULONGEST str_index
);
1536 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1538 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1539 struct dwarf2_cu
*);
1541 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1544 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1545 struct dwarf2_cu
*cu
);
1547 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1548 struct dwarf2_cu
*cu
);
1550 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1552 static struct die_info
*die_specification (struct die_info
*die
,
1553 struct dwarf2_cu
**);
1555 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1556 struct dwarf2_cu
*cu
);
1558 static void dwarf_decode_lines (struct line_header
*, const char *,
1559 struct dwarf2_cu
*, struct partial_symtab
*,
1560 CORE_ADDR
, int decode_mapping
);
1562 static void dwarf2_start_subfile (const char *, const char *);
1564 static struct compunit_symtab
*dwarf2_start_symtab (struct dwarf2_cu
*,
1565 const char *, const char *,
1568 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1569 struct dwarf2_cu
*, struct symbol
* = NULL
);
1571 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1572 struct dwarf2_cu
*);
1574 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1577 struct obstack
*obstack
,
1578 struct dwarf2_cu
*cu
, LONGEST
*value
,
1579 const gdb_byte
**bytes
,
1580 struct dwarf2_locexpr_baton
**baton
);
1582 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1584 static int need_gnat_info (struct dwarf2_cu
*);
1586 static struct type
*die_descriptive_type (struct die_info
*,
1587 struct dwarf2_cu
*);
1589 static void set_descriptive_type (struct type
*, struct die_info
*,
1590 struct dwarf2_cu
*);
1592 static struct type
*die_containing_type (struct die_info
*,
1593 struct dwarf2_cu
*);
1595 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1596 struct dwarf2_cu
*);
1598 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1600 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1602 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1604 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1605 const char *suffix
, int physname
,
1606 struct dwarf2_cu
*cu
);
1608 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1610 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1612 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1614 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1616 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1618 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1620 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1621 struct dwarf2_cu
*, struct partial_symtab
*);
1623 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1624 values. Keep the items ordered with increasing constraints compliance. */
1627 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1628 PC_BOUNDS_NOT_PRESENT
,
1630 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1631 were present but they do not form a valid range of PC addresses. */
1634 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1637 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1641 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1642 CORE_ADDR
*, CORE_ADDR
*,
1644 struct partial_symtab
*);
1646 static void get_scope_pc_bounds (struct die_info
*,
1647 CORE_ADDR
*, CORE_ADDR
*,
1648 struct dwarf2_cu
*);
1650 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1651 CORE_ADDR
, struct dwarf2_cu
*);
1653 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1654 struct dwarf2_cu
*);
1656 static void dwarf2_attach_fields_to_type (struct field_info
*,
1657 struct type
*, struct dwarf2_cu
*);
1659 static void dwarf2_add_member_fn (struct field_info
*,
1660 struct die_info
*, struct type
*,
1661 struct dwarf2_cu
*);
1663 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1665 struct dwarf2_cu
*);
1667 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1669 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1671 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1673 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1675 static struct using_direct
**using_directives (enum language
);
1677 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1679 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1681 static struct type
*read_module_type (struct die_info
*die
,
1682 struct dwarf2_cu
*cu
);
1684 static const char *namespace_name (struct die_info
*die
,
1685 int *is_anonymous
, struct dwarf2_cu
*);
1687 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1689 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1691 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1692 struct dwarf2_cu
*);
1694 static struct die_info
*read_die_and_siblings_1
1695 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1698 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1699 const gdb_byte
*info_ptr
,
1700 const gdb_byte
**new_info_ptr
,
1701 struct die_info
*parent
);
1703 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1704 struct die_info
**, const gdb_byte
*,
1707 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1708 struct die_info
**, const gdb_byte
*,
1711 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1713 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1716 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1718 static const char *dwarf2_full_name (const char *name
,
1719 struct die_info
*die
,
1720 struct dwarf2_cu
*cu
);
1722 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1723 struct dwarf2_cu
*cu
);
1725 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1726 struct dwarf2_cu
**);
1728 static const char *dwarf_tag_name (unsigned int);
1730 static const char *dwarf_attr_name (unsigned int);
1732 static const char *dwarf_form_name (unsigned int);
1734 static const char *dwarf_bool_name (unsigned int);
1736 static const char *dwarf_type_encoding_name (unsigned int);
1738 static struct die_info
*sibling_die (struct die_info
*);
1740 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1742 static void dump_die_for_error (struct die_info
*);
1744 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1747 /*static*/ void dump_die (struct die_info
*, int max_level
);
1749 static void store_in_ref_table (struct die_info
*,
1750 struct dwarf2_cu
*);
1752 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1754 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1756 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1757 const struct attribute
*,
1758 struct dwarf2_cu
**);
1760 static struct die_info
*follow_die_ref (struct die_info
*,
1761 const struct attribute
*,
1762 struct dwarf2_cu
**);
1764 static struct die_info
*follow_die_sig (struct die_info
*,
1765 const struct attribute
*,
1766 struct dwarf2_cu
**);
1768 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1769 struct dwarf2_cu
*);
1771 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1772 const struct attribute
*,
1773 struct dwarf2_cu
*);
1775 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1777 static void read_signatured_type (struct signatured_type
*);
1779 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1780 struct die_info
*die
, struct dwarf2_cu
*cu
,
1781 struct dynamic_prop
*prop
);
1783 /* memory allocation interface */
1785 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1787 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1789 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1791 static int attr_form_is_block (const struct attribute
*);
1793 static int attr_form_is_section_offset (const struct attribute
*);
1795 static int attr_form_is_constant (const struct attribute
*);
1797 static int attr_form_is_ref (const struct attribute
*);
1799 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1800 struct dwarf2_loclist_baton
*baton
,
1801 const struct attribute
*attr
);
1803 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1805 struct dwarf2_cu
*cu
,
1808 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1809 const gdb_byte
*info_ptr
,
1810 struct abbrev_info
*abbrev
);
1812 static hashval_t
partial_die_hash (const void *item
);
1814 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1816 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1817 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1818 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1820 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1821 struct die_info
*comp_unit_die
,
1822 enum language pretend_language
);
1824 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1826 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1828 static struct type
*set_die_type (struct die_info
*, struct type
*,
1829 struct dwarf2_cu
*);
1831 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1833 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1835 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1838 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1841 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1844 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1845 struct dwarf2_per_cu_data
*);
1847 static void dwarf2_mark (struct dwarf2_cu
*);
1849 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1851 static struct type
*get_die_type_at_offset (sect_offset
,
1852 struct dwarf2_per_cu_data
*);
1854 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1856 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1857 enum language pretend_language
);
1859 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1861 /* Class, the destructor of which frees all allocated queue entries. This
1862 will only have work to do if an error was thrown while processing the
1863 dwarf. If no error was thrown then the queue entries should have all
1864 been processed, and freed, as we went along. */
1866 class dwarf2_queue_guard
1869 dwarf2_queue_guard () = default;
1871 /* Free any entries remaining on the queue. There should only be
1872 entries left if we hit an error while processing the dwarf. */
1873 ~dwarf2_queue_guard ()
1875 struct dwarf2_queue_item
*item
, *last
;
1877 item
= dwarf2_queue
;
1880 /* Anything still marked queued is likely to be in an
1881 inconsistent state, so discard it. */
1882 if (item
->per_cu
->queued
)
1884 if (item
->per_cu
->cu
!= NULL
)
1885 free_one_cached_comp_unit (item
->per_cu
);
1886 item
->per_cu
->queued
= 0;
1894 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
1898 /* The return type of find_file_and_directory. Note, the enclosed
1899 string pointers are only valid while this object is valid. */
1901 struct file_and_directory
1903 /* The filename. This is never NULL. */
1906 /* The compilation directory. NULL if not known. If we needed to
1907 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1908 points directly to the DW_AT_comp_dir string attribute owned by
1909 the obstack that owns the DIE. */
1910 const char *comp_dir
;
1912 /* If we needed to build a new string for comp_dir, this is what
1913 owns the storage. */
1914 std::string comp_dir_storage
;
1917 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1918 struct dwarf2_cu
*cu
);
1920 static char *file_full_name (int file
, struct line_header
*lh
,
1921 const char *comp_dir
);
1923 /* Expected enum dwarf_unit_type for read_comp_unit_head. */
1924 enum class rcuh_kind
{ COMPILE
, TYPE
};
1926 static const gdb_byte
*read_and_check_comp_unit_head
1927 (struct dwarf2_per_objfile
* dwarf2_per_objfile
,
1928 struct comp_unit_head
*header
,
1929 struct dwarf2_section_info
*section
,
1930 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
1931 rcuh_kind section_kind
);
1933 static void init_cutu_and_read_dies
1934 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
1935 int use_existing_cu
, int keep
,
1936 die_reader_func_ftype
*die_reader_func
, void *data
);
1938 static void init_cutu_and_read_dies_simple
1939 (struct dwarf2_per_cu_data
*this_cu
,
1940 die_reader_func_ftype
*die_reader_func
, void *data
);
1942 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1944 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1946 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1947 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1948 struct dwp_file
*dwp_file
, const char *comp_dir
,
1949 ULONGEST signature
, int is_debug_types
);
1951 static struct dwp_file
*get_dwp_file
1952 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1954 static struct dwo_unit
*lookup_dwo_comp_unit
1955 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1957 static struct dwo_unit
*lookup_dwo_type_unit
1958 (struct signatured_type
*, const char *, const char *);
1960 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1962 static void free_dwo_file (struct dwo_file
*);
1964 /* A unique_ptr helper to free a dwo_file. */
1966 struct dwo_file_deleter
1968 void operator() (struct dwo_file
*df
) const
1974 /* A unique pointer to a dwo_file. */
1976 typedef std::unique_ptr
<struct dwo_file
, dwo_file_deleter
> dwo_file_up
;
1978 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1980 static void check_producer (struct dwarf2_cu
*cu
);
1982 static void free_line_header_voidp (void *arg
);
1984 /* Various complaints about symbol reading that don't abort the process. */
1987 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1989 complaint (&symfile_complaints
,
1990 _("statement list doesn't fit in .debug_line section"));
1994 dwarf2_debug_line_missing_file_complaint (void)
1996 complaint (&symfile_complaints
,
1997 _(".debug_line section has line data without a file"));
2001 dwarf2_debug_line_missing_end_sequence_complaint (void)
2003 complaint (&symfile_complaints
,
2004 _(".debug_line section has line "
2005 "program sequence without an end"));
2009 dwarf2_complex_location_expr_complaint (void)
2011 complaint (&symfile_complaints
, _("location expression too complex"));
2015 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
2018 complaint (&symfile_complaints
,
2019 _("const value length mismatch for '%s', got %d, expected %d"),
2024 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
2026 complaint (&symfile_complaints
,
2027 _("debug info runs off end of %s section"
2029 get_section_name (section
),
2030 get_section_file_name (section
));
2034 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
2036 complaint (&symfile_complaints
,
2037 _("macro debug info contains a "
2038 "malformed macro definition:\n`%s'"),
2043 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
2045 complaint (&symfile_complaints
,
2046 _("invalid attribute class or form for '%s' in '%s'"),
2050 /* Hash function for line_header_hash. */
2053 line_header_hash (const struct line_header
*ofs
)
2055 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
2058 /* Hash function for htab_create_alloc_ex for line_header_hash. */
2061 line_header_hash_voidp (const void *item
)
2063 const struct line_header
*ofs
= (const struct line_header
*) item
;
2065 return line_header_hash (ofs
);
2068 /* Equality function for line_header_hash. */
2071 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
2073 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
2074 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
2076 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
2077 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
2082 /* Read the given attribute value as an address, taking the attribute's
2083 form into account. */
2086 attr_value_as_address (struct attribute
*attr
)
2090 if (attr
->form
!= DW_FORM_addr
&& attr
->form
!= DW_FORM_GNU_addr_index
)
2092 /* Aside from a few clearly defined exceptions, attributes that
2093 contain an address must always be in DW_FORM_addr form.
2094 Unfortunately, some compilers happen to be violating this
2095 requirement by encoding addresses using other forms, such
2096 as DW_FORM_data4 for example. For those broken compilers,
2097 we try to do our best, without any guarantee of success,
2098 to interpret the address correctly. It would also be nice
2099 to generate a complaint, but that would require us to maintain
2100 a list of legitimate cases where a non-address form is allowed,
2101 as well as update callers to pass in at least the CU's DWARF
2102 version. This is more overhead than what we're willing to
2103 expand for a pretty rare case. */
2104 addr
= DW_UNSND (attr
);
2107 addr
= DW_ADDR (attr
);
2112 /* See declaration. */
2114 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
2115 const dwarf2_debug_sections
*names
)
2116 : objfile (objfile_
)
2119 names
= &dwarf2_elf_names
;
2121 bfd
*obfd
= objfile
->obfd
;
2123 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2124 locate_sections (obfd
, sec
, *names
);
2127 static void free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
);
2129 dwarf2_per_objfile::~dwarf2_per_objfile ()
2131 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
2132 free_cached_comp_units ();
2134 if (quick_file_names_table
)
2135 htab_delete (quick_file_names_table
);
2137 if (line_header_hash
)
2138 htab_delete (line_header_hash
);
2140 for (int ix
= 0; ix
< n_comp_units
; ++ix
)
2141 VEC_free (dwarf2_per_cu_ptr
, all_comp_units
[ix
]->imported_symtabs
);
2143 for (int ix
= 0; ix
< n_type_units
; ++ix
)
2144 VEC_free (dwarf2_per_cu_ptr
,
2145 all_type_units
[ix
]->per_cu
.imported_symtabs
);
2146 xfree (all_type_units
);
2148 VEC_free (dwarf2_section_info_def
, types
);
2150 if (dwo_files
!= NULL
)
2151 free_dwo_files (dwo_files
, objfile
);
2152 if (dwp_file
!= NULL
)
2153 gdb_bfd_unref (dwp_file
->dbfd
);
2155 if (dwz_file
!= NULL
&& dwz_file
->dwz_bfd
)
2156 gdb_bfd_unref (dwz_file
->dwz_bfd
);
2158 if (index_table
!= NULL
)
2159 index_table
->~mapped_index ();
2161 /* Everything else should be on the objfile obstack. */
2164 /* See declaration. */
2167 dwarf2_per_objfile::free_cached_comp_units ()
2169 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
2170 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
2171 while (per_cu
!= NULL
)
2173 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
2176 *last_chain
= next_cu
;
2181 /* A helper class that calls free_cached_comp_units on
2184 class free_cached_comp_units
2188 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
2189 : m_per_objfile (per_objfile
)
2193 ~free_cached_comp_units ()
2195 m_per_objfile
->free_cached_comp_units ();
2198 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
2202 dwarf2_per_objfile
*m_per_objfile
;
2205 /* Try to locate the sections we need for DWARF 2 debugging
2206 information and return true if we have enough to do something.
2207 NAMES points to the dwarf2 section names, or is NULL if the standard
2208 ELF names are used. */
2211 dwarf2_has_info (struct objfile
*objfile
,
2212 const struct dwarf2_debug_sections
*names
)
2214 if (objfile
->flags
& OBJF_READNEVER
)
2217 struct dwarf2_per_objfile
*dwarf2_per_objfile
2218 = get_dwarf2_per_objfile (objfile
);
2220 if (dwarf2_per_objfile
== NULL
)
2222 /* Initialize per-objfile state. */
2224 = new (&objfile
->objfile_obstack
) struct dwarf2_per_objfile (objfile
,
2226 set_dwarf2_per_objfile (objfile
, dwarf2_per_objfile
);
2228 return (!dwarf2_per_objfile
->info
.is_virtual
2229 && dwarf2_per_objfile
->info
.s
.section
!= NULL
2230 && !dwarf2_per_objfile
->abbrev
.is_virtual
2231 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
2234 /* Return the containing section of virtual section SECTION. */
2236 static struct dwarf2_section_info
*
2237 get_containing_section (const struct dwarf2_section_info
*section
)
2239 gdb_assert (section
->is_virtual
);
2240 return section
->s
.containing_section
;
2243 /* Return the bfd owner of SECTION. */
2246 get_section_bfd_owner (const struct dwarf2_section_info
*section
)
2248 if (section
->is_virtual
)
2250 section
= get_containing_section (section
);
2251 gdb_assert (!section
->is_virtual
);
2253 return section
->s
.section
->owner
;
2256 /* Return the bfd section of SECTION.
2257 Returns NULL if the section is not present. */
2260 get_section_bfd_section (const struct dwarf2_section_info
*section
)
2262 if (section
->is_virtual
)
2264 section
= get_containing_section (section
);
2265 gdb_assert (!section
->is_virtual
);
2267 return section
->s
.section
;
2270 /* Return the name of SECTION. */
2273 get_section_name (const struct dwarf2_section_info
*section
)
2275 asection
*sectp
= get_section_bfd_section (section
);
2277 gdb_assert (sectp
!= NULL
);
2278 return bfd_section_name (get_section_bfd_owner (section
), sectp
);
2281 /* Return the name of the file SECTION is in. */
2284 get_section_file_name (const struct dwarf2_section_info
*section
)
2286 bfd
*abfd
= get_section_bfd_owner (section
);
2288 return bfd_get_filename (abfd
);
2291 /* Return the id of SECTION.
2292 Returns 0 if SECTION doesn't exist. */
2295 get_section_id (const struct dwarf2_section_info
*section
)
2297 asection
*sectp
= get_section_bfd_section (section
);
2304 /* Return the flags of SECTION.
2305 SECTION (or containing section if this is a virtual section) must exist. */
2308 get_section_flags (const struct dwarf2_section_info
*section
)
2310 asection
*sectp
= get_section_bfd_section (section
);
2312 gdb_assert (sectp
!= NULL
);
2313 return bfd_get_section_flags (sectp
->owner
, sectp
);
2316 /* When loading sections, we look either for uncompressed section or for
2317 compressed section names. */
2320 section_is_p (const char *section_name
,
2321 const struct dwarf2_section_names
*names
)
2323 if (names
->normal
!= NULL
2324 && strcmp (section_name
, names
->normal
) == 0)
2326 if (names
->compressed
!= NULL
2327 && strcmp (section_name
, names
->compressed
) == 0)
2332 /* See declaration. */
2335 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
2336 const dwarf2_debug_sections
&names
)
2338 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
2340 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2343 else if (section_is_p (sectp
->name
, &names
.info
))
2345 this->info
.s
.section
= sectp
;
2346 this->info
.size
= bfd_get_section_size (sectp
);
2348 else if (section_is_p (sectp
->name
, &names
.abbrev
))
2350 this->abbrev
.s
.section
= sectp
;
2351 this->abbrev
.size
= bfd_get_section_size (sectp
);
2353 else if (section_is_p (sectp
->name
, &names
.line
))
2355 this->line
.s
.section
= sectp
;
2356 this->line
.size
= bfd_get_section_size (sectp
);
2358 else if (section_is_p (sectp
->name
, &names
.loc
))
2360 this->loc
.s
.section
= sectp
;
2361 this->loc
.size
= bfd_get_section_size (sectp
);
2363 else if (section_is_p (sectp
->name
, &names
.loclists
))
2365 this->loclists
.s
.section
= sectp
;
2366 this->loclists
.size
= bfd_get_section_size (sectp
);
2368 else if (section_is_p (sectp
->name
, &names
.macinfo
))
2370 this->macinfo
.s
.section
= sectp
;
2371 this->macinfo
.size
= bfd_get_section_size (sectp
);
2373 else if (section_is_p (sectp
->name
, &names
.macro
))
2375 this->macro
.s
.section
= sectp
;
2376 this->macro
.size
= bfd_get_section_size (sectp
);
2378 else if (section_is_p (sectp
->name
, &names
.str
))
2380 this->str
.s
.section
= sectp
;
2381 this->str
.size
= bfd_get_section_size (sectp
);
2383 else if (section_is_p (sectp
->name
, &names
.line_str
))
2385 this->line_str
.s
.section
= sectp
;
2386 this->line_str
.size
= bfd_get_section_size (sectp
);
2388 else if (section_is_p (sectp
->name
, &names
.addr
))
2390 this->addr
.s
.section
= sectp
;
2391 this->addr
.size
= bfd_get_section_size (sectp
);
2393 else if (section_is_p (sectp
->name
, &names
.frame
))
2395 this->frame
.s
.section
= sectp
;
2396 this->frame
.size
= bfd_get_section_size (sectp
);
2398 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2400 this->eh_frame
.s
.section
= sectp
;
2401 this->eh_frame
.size
= bfd_get_section_size (sectp
);
2403 else if (section_is_p (sectp
->name
, &names
.ranges
))
2405 this->ranges
.s
.section
= sectp
;
2406 this->ranges
.size
= bfd_get_section_size (sectp
);
2408 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2410 this->rnglists
.s
.section
= sectp
;
2411 this->rnglists
.size
= bfd_get_section_size (sectp
);
2413 else if (section_is_p (sectp
->name
, &names
.types
))
2415 struct dwarf2_section_info type_section
;
2417 memset (&type_section
, 0, sizeof (type_section
));
2418 type_section
.s
.section
= sectp
;
2419 type_section
.size
= bfd_get_section_size (sectp
);
2421 VEC_safe_push (dwarf2_section_info_def
, this->types
,
2424 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2426 this->gdb_index
.s
.section
= sectp
;
2427 this->gdb_index
.size
= bfd_get_section_size (sectp
);
2429 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2431 this->debug_names
.s
.section
= sectp
;
2432 this->debug_names
.size
= bfd_get_section_size (sectp
);
2434 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2436 this->debug_aranges
.s
.section
= sectp
;
2437 this->debug_aranges
.size
= bfd_get_section_size (sectp
);
2440 if ((bfd_get_section_flags (abfd
, sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2441 && bfd_section_vma (abfd
, sectp
) == 0)
2442 this->has_section_at_zero
= true;
2445 /* A helper function that decides whether a section is empty,
2449 dwarf2_section_empty_p (const struct dwarf2_section_info
*section
)
2451 if (section
->is_virtual
)
2452 return section
->size
== 0;
2453 return section
->s
.section
== NULL
|| section
->size
== 0;
2456 /* See dwarf2read.h. */
2459 dwarf2_read_section (struct objfile
*objfile
, dwarf2_section_info
*info
)
2463 gdb_byte
*buf
, *retbuf
;
2467 info
->buffer
= NULL
;
2470 if (dwarf2_section_empty_p (info
))
2473 sectp
= get_section_bfd_section (info
);
2475 /* If this is a virtual section we need to read in the real one first. */
2476 if (info
->is_virtual
)
2478 struct dwarf2_section_info
*containing_section
=
2479 get_containing_section (info
);
2481 gdb_assert (sectp
!= NULL
);
2482 if ((sectp
->flags
& SEC_RELOC
) != 0)
2484 error (_("Dwarf Error: DWP format V2 with relocations is not"
2485 " supported in section %s [in module %s]"),
2486 get_section_name (info
), get_section_file_name (info
));
2488 dwarf2_read_section (objfile
, containing_section
);
2489 /* Other code should have already caught virtual sections that don't
2491 gdb_assert (info
->virtual_offset
+ info
->size
2492 <= containing_section
->size
);
2493 /* If the real section is empty or there was a problem reading the
2494 section we shouldn't get here. */
2495 gdb_assert (containing_section
->buffer
!= NULL
);
2496 info
->buffer
= containing_section
->buffer
+ info
->virtual_offset
;
2500 /* If the section has relocations, we must read it ourselves.
2501 Otherwise we attach it to the BFD. */
2502 if ((sectp
->flags
& SEC_RELOC
) == 0)
2504 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
2508 buf
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
2511 /* When debugging .o files, we may need to apply relocations; see
2512 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2513 We never compress sections in .o files, so we only need to
2514 try this when the section is not compressed. */
2515 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
2518 info
->buffer
= retbuf
;
2522 abfd
= get_section_bfd_owner (info
);
2523 gdb_assert (abfd
!= NULL
);
2525 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
2526 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
2528 error (_("Dwarf Error: Can't read DWARF data"
2529 " in section %s [in module %s]"),
2530 bfd_section_name (abfd
, sectp
), bfd_get_filename (abfd
));
2534 /* A helper function that returns the size of a section in a safe way.
2535 If you are positive that the section has been read before using the
2536 size, then it is safe to refer to the dwarf2_section_info object's
2537 "size" field directly. In other cases, you must call this
2538 function, because for compressed sections the size field is not set
2539 correctly until the section has been read. */
2541 static bfd_size_type
2542 dwarf2_section_size (struct objfile
*objfile
,
2543 struct dwarf2_section_info
*info
)
2546 dwarf2_read_section (objfile
, info
);
2550 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2554 dwarf2_get_section_info (struct objfile
*objfile
,
2555 enum dwarf2_section_enum sect
,
2556 asection
**sectp
, const gdb_byte
**bufp
,
2557 bfd_size_type
*sizep
)
2559 struct dwarf2_per_objfile
*data
2560 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
2561 dwarf2_objfile_data_key
);
2562 struct dwarf2_section_info
*info
;
2564 /* We may see an objfile without any DWARF, in which case we just
2575 case DWARF2_DEBUG_FRAME
:
2576 info
= &data
->frame
;
2578 case DWARF2_EH_FRAME
:
2579 info
= &data
->eh_frame
;
2582 gdb_assert_not_reached ("unexpected section");
2585 dwarf2_read_section (objfile
, info
);
2587 *sectp
= get_section_bfd_section (info
);
2588 *bufp
= info
->buffer
;
2589 *sizep
= info
->size
;
2592 /* A helper function to find the sections for a .dwz file. */
2595 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2597 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2599 /* Note that we only support the standard ELF names, because .dwz
2600 is ELF-only (at the time of writing). */
2601 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2603 dwz_file
->abbrev
.s
.section
= sectp
;
2604 dwz_file
->abbrev
.size
= bfd_get_section_size (sectp
);
2606 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2608 dwz_file
->info
.s
.section
= sectp
;
2609 dwz_file
->info
.size
= bfd_get_section_size (sectp
);
2611 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2613 dwz_file
->str
.s
.section
= sectp
;
2614 dwz_file
->str
.size
= bfd_get_section_size (sectp
);
2616 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2618 dwz_file
->line
.s
.section
= sectp
;
2619 dwz_file
->line
.size
= bfd_get_section_size (sectp
);
2621 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2623 dwz_file
->macro
.s
.section
= sectp
;
2624 dwz_file
->macro
.size
= bfd_get_section_size (sectp
);
2626 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2628 dwz_file
->gdb_index
.s
.section
= sectp
;
2629 dwz_file
->gdb_index
.size
= bfd_get_section_size (sectp
);
2631 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2633 dwz_file
->debug_names
.s
.section
= sectp
;
2634 dwz_file
->debug_names
.size
= bfd_get_section_size (sectp
);
2638 /* Open the separate '.dwz' debug file, if needed. Return NULL if
2639 there is no .gnu_debugaltlink section in the file. Error if there
2640 is such a section but the file cannot be found. */
2642 static struct dwz_file
*
2643 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2645 const char *filename
;
2646 struct dwz_file
*result
;
2647 bfd_size_type buildid_len_arg
;
2651 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2652 return dwarf2_per_objfile
->dwz_file
;
2654 bfd_set_error (bfd_error_no_error
);
2655 gdb::unique_xmalloc_ptr
<char> data
2656 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2657 &buildid_len_arg
, &buildid
));
2660 if (bfd_get_error () == bfd_error_no_error
)
2662 error (_("could not read '.gnu_debugaltlink' section: %s"),
2663 bfd_errmsg (bfd_get_error ()));
2666 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2668 buildid_len
= (size_t) buildid_len_arg
;
2670 filename
= data
.get ();
2672 std::string abs_storage
;
2673 if (!IS_ABSOLUTE_PATH (filename
))
2675 gdb::unique_xmalloc_ptr
<char> abs
2676 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2678 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2679 filename
= abs_storage
.c_str ();
2682 /* First try the file name given in the section. If that doesn't
2683 work, try to use the build-id instead. */
2684 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2685 if (dwz_bfd
!= NULL
)
2687 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2691 if (dwz_bfd
== NULL
)
2692 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2694 if (dwz_bfd
== NULL
)
2695 error (_("could not find '.gnu_debugaltlink' file for %s"),
2696 objfile_name (dwarf2_per_objfile
->objfile
));
2698 result
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
2700 result
->dwz_bfd
= dwz_bfd
.release ();
2702 bfd_map_over_sections (result
->dwz_bfd
, locate_dwz_sections
, result
);
2704 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, result
->dwz_bfd
);
2705 dwarf2_per_objfile
->dwz_file
= result
;
2709 /* DWARF quick_symbols_functions support. */
2711 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2712 unique line tables, so we maintain a separate table of all .debug_line
2713 derived entries to support the sharing.
2714 All the quick functions need is the list of file names. We discard the
2715 line_header when we're done and don't need to record it here. */
2716 struct quick_file_names
2718 /* The data used to construct the hash key. */
2719 struct stmt_list_hash hash
;
2721 /* The number of entries in file_names, real_names. */
2722 unsigned int num_file_names
;
2724 /* The file names from the line table, after being run through
2726 const char **file_names
;
2728 /* The file names from the line table after being run through
2729 gdb_realpath. These are computed lazily. */
2730 const char **real_names
;
2733 /* When using the index (and thus not using psymtabs), each CU has an
2734 object of this type. This is used to hold information needed by
2735 the various "quick" methods. */
2736 struct dwarf2_per_cu_quick_data
2738 /* The file table. This can be NULL if there was no file table
2739 or it's currently not read in.
2740 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2741 struct quick_file_names
*file_names
;
2743 /* The corresponding symbol table. This is NULL if symbols for this
2744 CU have not yet been read. */
2745 struct compunit_symtab
*compunit_symtab
;
2747 /* A temporary mark bit used when iterating over all CUs in
2748 expand_symtabs_matching. */
2749 unsigned int mark
: 1;
2751 /* True if we've tried to read the file table and found there isn't one.
2752 There will be no point in trying to read it again next time. */
2753 unsigned int no_file_data
: 1;
2756 /* Utility hash function for a stmt_list_hash. */
2759 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2763 if (stmt_list_hash
->dwo_unit
!= NULL
)
2764 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2765 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2769 /* Utility equality function for a stmt_list_hash. */
2772 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2773 const struct stmt_list_hash
*rhs
)
2775 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2777 if (lhs
->dwo_unit
!= NULL
2778 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2781 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2784 /* Hash function for a quick_file_names. */
2787 hash_file_name_entry (const void *e
)
2789 const struct quick_file_names
*file_data
2790 = (const struct quick_file_names
*) e
;
2792 return hash_stmt_list_entry (&file_data
->hash
);
2795 /* Equality function for a quick_file_names. */
2798 eq_file_name_entry (const void *a
, const void *b
)
2800 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2801 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2803 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2806 /* Delete function for a quick_file_names. */
2809 delete_file_name_entry (void *e
)
2811 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2814 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2816 xfree ((void*) file_data
->file_names
[i
]);
2817 if (file_data
->real_names
)
2818 xfree ((void*) file_data
->real_names
[i
]);
2821 /* The space for the struct itself lives on objfile_obstack,
2822 so we don't free it here. */
2825 /* Create a quick_file_names hash table. */
2828 create_quick_file_names_table (unsigned int nr_initial_entries
)
2830 return htab_create_alloc (nr_initial_entries
,
2831 hash_file_name_entry
, eq_file_name_entry
,
2832 delete_file_name_entry
, xcalloc
, xfree
);
2835 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2836 have to be created afterwards. You should call age_cached_comp_units after
2837 processing PER_CU->CU. dw2_setup must have been already called. */
2840 load_cu (struct dwarf2_per_cu_data
*per_cu
)
2842 if (per_cu
->is_debug_types
)
2843 load_full_type_unit (per_cu
);
2845 load_full_comp_unit (per_cu
, language_minimal
);
2847 if (per_cu
->cu
== NULL
)
2848 return; /* Dummy CU. */
2850 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2853 /* Read in the symbols for PER_CU. */
2856 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2858 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2860 /* Skip type_unit_groups, reading the type units they contain
2861 is handled elsewhere. */
2862 if (IS_TYPE_UNIT_GROUP (per_cu
))
2865 /* The destructor of dwarf2_queue_guard frees any entries left on
2866 the queue. After this point we're guaranteed to leave this function
2867 with the dwarf queue empty. */
2868 dwarf2_queue_guard q_guard
;
2870 if (dwarf2_per_objfile
->using_index
2871 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2872 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2874 queue_comp_unit (per_cu
, language_minimal
);
2877 /* If we just loaded a CU from a DWO, and we're working with an index
2878 that may badly handle TUs, load all the TUs in that DWO as well.
2879 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2880 if (!per_cu
->is_debug_types
2881 && per_cu
->cu
!= NULL
2882 && per_cu
->cu
->dwo_unit
!= NULL
2883 && dwarf2_per_objfile
->index_table
!= NULL
2884 && dwarf2_per_objfile
->index_table
->version
<= 7
2885 /* DWP files aren't supported yet. */
2886 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2887 queue_and_load_all_dwo_tus (per_cu
);
2890 process_queue (dwarf2_per_objfile
);
2892 /* Age the cache, releasing compilation units that have not
2893 been used recently. */
2894 age_cached_comp_units (dwarf2_per_objfile
);
2897 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2898 the objfile from which this CU came. Returns the resulting symbol
2901 static struct compunit_symtab
*
2902 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2904 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2906 gdb_assert (dwarf2_per_objfile
->using_index
);
2907 if (!per_cu
->v
.quick
->compunit_symtab
)
2909 free_cached_comp_units
freer (dwarf2_per_objfile
);
2910 scoped_restore decrementer
= increment_reading_symtab ();
2911 dw2_do_instantiate_symtab (per_cu
);
2912 process_cu_includes (dwarf2_per_objfile
);
2915 return per_cu
->v
.quick
->compunit_symtab
;
2918 /* Return the CU/TU given its index.
2920 This is intended for loops like:
2922 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2923 + dwarf2_per_objfile->n_type_units); ++i)
2925 struct dwarf2_per_cu_data *per_cu = dw2_get_cutu (i);
2931 static struct dwarf2_per_cu_data
*
2932 dw2_get_cutu (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2935 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2937 index
-= dwarf2_per_objfile
->n_comp_units
;
2938 gdb_assert (index
< dwarf2_per_objfile
->n_type_units
);
2939 return &dwarf2_per_objfile
->all_type_units
[index
]->per_cu
;
2942 return dwarf2_per_objfile
->all_comp_units
[index
];
2945 /* Return the CU given its index.
2946 This differs from dw2_get_cutu in that it's for when you know INDEX
2949 static struct dwarf2_per_cu_data
*
2950 dw2_get_cu (struct dwarf2_per_objfile
*dwarf2_per_objfile
, int index
)
2952 gdb_assert (index
>= 0 && index
< dwarf2_per_objfile
->n_comp_units
);
2954 return dwarf2_per_objfile
->all_comp_units
[index
];
2957 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2958 objfile_obstack, and constructed with the specified field
2961 static dwarf2_per_cu_data
*
2962 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2963 struct dwarf2_section_info
*section
,
2965 sect_offset sect_off
, ULONGEST length
)
2967 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2968 dwarf2_per_cu_data
*the_cu
2969 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2970 struct dwarf2_per_cu_data
);
2971 the_cu
->sect_off
= sect_off
;
2972 the_cu
->length
= length
;
2973 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2974 the_cu
->section
= section
;
2975 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2976 struct dwarf2_per_cu_quick_data
);
2977 the_cu
->is_dwz
= is_dwz
;
2981 /* A helper for create_cus_from_index that handles a given list of
2985 create_cus_from_index_list (struct objfile
*objfile
,
2986 const gdb_byte
*cu_list
, offset_type n_elements
,
2987 struct dwarf2_section_info
*section
,
2992 struct dwarf2_per_objfile
*dwarf2_per_objfile
2993 = get_dwarf2_per_objfile (objfile
);
2995 for (i
= 0; i
< n_elements
; i
+= 2)
2997 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2999 sect_offset sect_off
3000 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
3001 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
3004 dwarf2_per_objfile
->all_comp_units
[base_offset
+ i
/ 2]
3005 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
3010 /* Read the CU list from the mapped index, and use it to create all
3011 the CU objects for this objfile. */
3014 create_cus_from_index (struct objfile
*objfile
,
3015 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
3016 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
3018 struct dwz_file
*dwz
;
3019 struct dwarf2_per_objfile
*dwarf2_per_objfile
3020 = get_dwarf2_per_objfile (objfile
);
3022 dwarf2_per_objfile
->n_comp_units
= (cu_list_elements
+ dwz_elements
) / 2;
3023 dwarf2_per_objfile
->all_comp_units
=
3024 XOBNEWVEC (&objfile
->objfile_obstack
, struct dwarf2_per_cu_data
*,
3025 dwarf2_per_objfile
->n_comp_units
);
3027 create_cus_from_index_list (objfile
, cu_list
, cu_list_elements
,
3028 &dwarf2_per_objfile
->info
, 0, 0);
3030 if (dwz_elements
== 0)
3033 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3034 create_cus_from_index_list (objfile
, dwz_list
, dwz_elements
, &dwz
->info
, 1,
3035 cu_list_elements
/ 2);
3038 /* Create the signatured type hash table from the index. */
3041 create_signatured_type_table_from_index (struct objfile
*objfile
,
3042 struct dwarf2_section_info
*section
,
3043 const gdb_byte
*bytes
,
3044 offset_type elements
)
3047 htab_t sig_types_hash
;
3048 struct dwarf2_per_objfile
*dwarf2_per_objfile
3049 = get_dwarf2_per_objfile (objfile
);
3051 dwarf2_per_objfile
->n_type_units
3052 = dwarf2_per_objfile
->n_allocated_type_units
3054 dwarf2_per_objfile
->all_type_units
=
3055 XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
3057 sig_types_hash
= allocate_signatured_type_table (objfile
);
3059 for (i
= 0; i
< elements
; i
+= 3)
3061 struct signatured_type
*sig_type
;
3064 cu_offset type_offset_in_tu
;
3066 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3067 sect_offset sect_off
3068 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
3070 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
3072 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
3075 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3076 struct signatured_type
);
3077 sig_type
->signature
= signature
;
3078 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3079 sig_type
->per_cu
.is_debug_types
= 1;
3080 sig_type
->per_cu
.section
= section
;
3081 sig_type
->per_cu
.sect_off
= sect_off
;
3082 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3083 sig_type
->per_cu
.v
.quick
3084 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3085 struct dwarf2_per_cu_quick_data
);
3087 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3090 dwarf2_per_objfile
->all_type_units
[i
/ 3] = sig_type
;
3093 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3096 /* Create the signatured type hash table from .debug_names. */
3099 create_signatured_type_table_from_debug_names
3100 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3101 const mapped_debug_names
&map
,
3102 struct dwarf2_section_info
*section
,
3103 struct dwarf2_section_info
*abbrev_section
)
3105 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3107 dwarf2_read_section (objfile
, section
);
3108 dwarf2_read_section (objfile
, abbrev_section
);
3110 dwarf2_per_objfile
->n_type_units
3111 = dwarf2_per_objfile
->n_allocated_type_units
3113 dwarf2_per_objfile
->all_type_units
3114 = XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
3116 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3118 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
3120 struct signatured_type
*sig_type
;
3123 cu_offset type_offset_in_tu
;
3125 sect_offset sect_off
3126 = (sect_offset
) (extract_unsigned_integer
3127 (map
.tu_table_reordered
+ i
* map
.offset_size
,
3129 map
.dwarf5_byte_order
));
3131 comp_unit_head cu_header
;
3132 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
3134 section
->buffer
+ to_underlying (sect_off
),
3137 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3138 struct signatured_type
);
3139 sig_type
->signature
= cu_header
.signature
;
3140 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
3141 sig_type
->per_cu
.is_debug_types
= 1;
3142 sig_type
->per_cu
.section
= section
;
3143 sig_type
->per_cu
.sect_off
= sect_off
;
3144 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3145 sig_type
->per_cu
.v
.quick
3146 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3147 struct dwarf2_per_cu_quick_data
);
3149 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3152 dwarf2_per_objfile
->all_type_units
[i
] = sig_type
;
3155 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3158 /* Read the address map data from the mapped index, and use it to
3159 populate the objfile's psymtabs_addrmap. */
3162 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3163 struct mapped_index
*index
)
3165 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3166 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3167 const gdb_byte
*iter
, *end
;
3168 struct addrmap
*mutable_map
;
3171 auto_obstack temp_obstack
;
3173 mutable_map
= addrmap_create_mutable (&temp_obstack
);
3175 iter
= index
->address_table
.data ();
3176 end
= iter
+ index
->address_table
.size ();
3178 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3182 ULONGEST hi
, lo
, cu_index
;
3183 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3185 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3187 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
3192 complaint (&symfile_complaints
,
3193 _(".gdb_index address table has invalid range (%s - %s)"),
3194 hex_string (lo
), hex_string (hi
));
3198 if (cu_index
>= dwarf2_per_objfile
->n_comp_units
)
3200 complaint (&symfile_complaints
,
3201 _(".gdb_index address table has invalid CU number %u"),
3202 (unsigned) cu_index
);
3206 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
);
3207 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
);
3208 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
3209 dw2_get_cutu (dwarf2_per_objfile
, cu_index
));
3212 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
3213 &objfile
->objfile_obstack
);
3216 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
3217 populate the objfile's psymtabs_addrmap. */
3220 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3221 struct dwarf2_section_info
*section
)
3223 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3224 bfd
*abfd
= objfile
->obfd
;
3225 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3226 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
3227 SECT_OFF_TEXT (objfile
));
3229 auto_obstack temp_obstack
;
3230 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
3232 std::unordered_map
<sect_offset
,
3233 dwarf2_per_cu_data
*,
3234 gdb::hash_enum
<sect_offset
>>
3235 debug_info_offset_to_per_cu
;
3236 for (int cui
= 0; cui
< dwarf2_per_objfile
->n_comp_units
; ++cui
)
3238 dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, cui
);
3239 const auto insertpair
3240 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
3241 if (!insertpair
.second
)
3243 warning (_("Section .debug_aranges in %s has duplicate "
3244 "debug_info_offset %s, ignoring .debug_aranges."),
3245 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
3250 dwarf2_read_section (objfile
, section
);
3252 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
3254 const gdb_byte
*addr
= section
->buffer
;
3256 while (addr
< section
->buffer
+ section
->size
)
3258 const gdb_byte
*const entry_addr
= addr
;
3259 unsigned int bytes_read
;
3261 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
3265 const gdb_byte
*const entry_end
= addr
+ entry_length
;
3266 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
3267 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
3268 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
3270 warning (_("Section .debug_aranges in %s entry at offset %zu "
3271 "length %s exceeds section length %s, "
3272 "ignoring .debug_aranges."),
3273 objfile_name (objfile
), entry_addr
- section
->buffer
,
3274 plongest (bytes_read
+ entry_length
),
3275 pulongest (section
->size
));
3279 /* The version number. */
3280 const uint16_t version
= read_2_bytes (abfd
, addr
);
3284 warning (_("Section .debug_aranges in %s entry at offset %zu "
3285 "has unsupported version %d, ignoring .debug_aranges."),
3286 objfile_name (objfile
), entry_addr
- section
->buffer
,
3291 const uint64_t debug_info_offset
3292 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
3293 addr
+= offset_size
;
3294 const auto per_cu_it
3295 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
3296 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
3298 warning (_("Section .debug_aranges in %s entry at offset %zu "
3299 "debug_info_offset %s does not exists, "
3300 "ignoring .debug_aranges."),
3301 objfile_name (objfile
), entry_addr
- section
->buffer
,
3302 pulongest (debug_info_offset
));
3305 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
3307 const uint8_t address_size
= *addr
++;
3308 if (address_size
< 1 || address_size
> 8)
3310 warning (_("Section .debug_aranges in %s entry at offset %zu "
3311 "address_size %u is invalid, ignoring .debug_aranges."),
3312 objfile_name (objfile
), entry_addr
- section
->buffer
,
3317 const uint8_t segment_selector_size
= *addr
++;
3318 if (segment_selector_size
!= 0)
3320 warning (_("Section .debug_aranges in %s entry at offset %zu "
3321 "segment_selector_size %u is not supported, "
3322 "ignoring .debug_aranges."),
3323 objfile_name (objfile
), entry_addr
- section
->buffer
,
3324 segment_selector_size
);
3328 /* Must pad to an alignment boundary that is twice the address
3329 size. It is undocumented by the DWARF standard but GCC does
3331 for (size_t padding
= ((-(addr
- section
->buffer
))
3332 & (2 * address_size
- 1));
3333 padding
> 0; padding
--)
3336 warning (_("Section .debug_aranges in %s entry at offset %zu "
3337 "padding is not zero, ignoring .debug_aranges."),
3338 objfile_name (objfile
), entry_addr
- section
->buffer
);
3344 if (addr
+ 2 * address_size
> entry_end
)
3346 warning (_("Section .debug_aranges in %s entry at offset %zu "
3347 "address list is not properly terminated, "
3348 "ignoring .debug_aranges."),
3349 objfile_name (objfile
), entry_addr
- section
->buffer
);
3352 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
3354 addr
+= address_size
;
3355 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
3357 addr
+= address_size
;
3358 if (start
== 0 && length
== 0)
3360 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3362 /* Symbol was eliminated due to a COMDAT group. */
3365 ULONGEST end
= start
+ length
;
3366 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
);
3367 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
);
3368 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
3372 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
3373 &objfile
->objfile_obstack
);
3376 /* Find a slot in the mapped index INDEX for the object named NAME.
3377 If NAME is found, set *VEC_OUT to point to the CU vector in the
3378 constant pool and return true. If NAME cannot be found, return
3382 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3383 offset_type
**vec_out
)
3386 offset_type slot
, step
;
3387 int (*cmp
) (const char *, const char *);
3389 gdb::unique_xmalloc_ptr
<char> without_params
;
3390 if (current_language
->la_language
== language_cplus
3391 || current_language
->la_language
== language_fortran
3392 || current_language
->la_language
== language_d
)
3394 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3397 if (strchr (name
, '(') != NULL
)
3399 without_params
= cp_remove_params (name
);
3401 if (without_params
!= NULL
)
3402 name
= without_params
.get ();
3406 /* Index version 4 did not support case insensitive searches. But the
3407 indices for case insensitive languages are built in lowercase, therefore
3408 simulate our NAME being searched is also lowercased. */
3409 hash
= mapped_index_string_hash ((index
->version
== 4
3410 && case_sensitivity
== case_sensitive_off
3411 ? 5 : index
->version
),
3414 slot
= hash
& (index
->symbol_table
.size () - 1);
3415 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
3416 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3422 const auto &bucket
= index
->symbol_table
[slot
];
3423 if (bucket
.name
== 0 && bucket
.vec
== 0)
3426 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
3427 if (!cmp (name
, str
))
3429 *vec_out
= (offset_type
*) (index
->constant_pool
3430 + MAYBE_SWAP (bucket
.vec
));
3434 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
3438 /* A helper function that reads the .gdb_index from SECTION and fills
3439 in MAP. FILENAME is the name of the file containing the section;
3440 it is used for error reporting. DEPRECATED_OK is nonzero if it is
3441 ok to use deprecated sections.
3443 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3444 out parameters that are filled in with information about the CU and
3445 TU lists in the section.
3447 Returns 1 if all went well, 0 otherwise. */
3450 read_index_from_section (struct objfile
*objfile
,
3451 const char *filename
,
3453 struct dwarf2_section_info
*section
,
3454 struct mapped_index
*map
,
3455 const gdb_byte
**cu_list
,
3456 offset_type
*cu_list_elements
,
3457 const gdb_byte
**types_list
,
3458 offset_type
*types_list_elements
)
3460 const gdb_byte
*addr
;
3461 offset_type version
;
3462 offset_type
*metadata
;
3465 if (dwarf2_section_empty_p (section
))
3468 /* Older elfutils strip versions could keep the section in the main
3469 executable while splitting it for the separate debug info file. */
3470 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
3473 dwarf2_read_section (objfile
, section
);
3475 addr
= section
->buffer
;
3476 /* Version check. */
3477 version
= MAYBE_SWAP (*(offset_type
*) addr
);
3478 /* Versions earlier than 3 emitted every copy of a psymbol. This
3479 causes the index to behave very poorly for certain requests. Version 3
3480 contained incomplete addrmap. So, it seems better to just ignore such
3484 static int warning_printed
= 0;
3485 if (!warning_printed
)
3487 warning (_("Skipping obsolete .gdb_index section in %s."),
3489 warning_printed
= 1;
3493 /* Index version 4 uses a different hash function than index version
3496 Versions earlier than 6 did not emit psymbols for inlined
3497 functions. Using these files will cause GDB not to be able to
3498 set breakpoints on inlined functions by name, so we ignore these
3499 indices unless the user has done
3500 "set use-deprecated-index-sections on". */
3501 if (version
< 6 && !deprecated_ok
)
3503 static int warning_printed
= 0;
3504 if (!warning_printed
)
3507 Skipping deprecated .gdb_index section in %s.\n\
3508 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3509 to use the section anyway."),
3511 warning_printed
= 1;
3515 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3516 of the TU (for symbols coming from TUs),
3517 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3518 Plus gold-generated indices can have duplicate entries for global symbols,
3519 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3520 These are just performance bugs, and we can't distinguish gdb-generated
3521 indices from gold-generated ones, so issue no warning here. */
3523 /* Indexes with higher version than the one supported by GDB may be no
3524 longer backward compatible. */
3528 map
->version
= version
;
3529 map
->total_size
= section
->size
;
3531 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3534 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3535 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3539 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3540 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3541 - MAYBE_SWAP (metadata
[i
]))
3545 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3546 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3548 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3551 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3552 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3554 = gdb::array_view
<mapped_index::symbol_table_slot
>
3555 ((mapped_index::symbol_table_slot
*) symbol_table
,
3556 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3559 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3564 /* Read .gdb_index. If everything went ok, initialize the "quick"
3565 elements of all the CUs and return 1. Otherwise, return 0. */
3568 dwarf2_read_index (struct objfile
*objfile
)
3570 struct mapped_index local_map
, *map
;
3571 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3572 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3573 struct dwz_file
*dwz
;
3574 struct dwarf2_per_objfile
*dwarf2_per_objfile
3575 = get_dwarf2_per_objfile (objfile
);
3577 if (!read_index_from_section (objfile
, objfile_name (objfile
),
3578 use_deprecated_index_sections
,
3579 &dwarf2_per_objfile
->gdb_index
, &local_map
,
3580 &cu_list
, &cu_list_elements
,
3581 &types_list
, &types_list_elements
))
3584 /* Don't use the index if it's empty. */
3585 if (local_map
.symbol_table
.empty ())
3588 /* If there is a .dwz file, read it so we can get its CU list as
3590 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3593 struct mapped_index dwz_map
;
3594 const gdb_byte
*dwz_types_ignore
;
3595 offset_type dwz_types_elements_ignore
;
3597 if (!read_index_from_section (objfile
, bfd_get_filename (dwz
->dwz_bfd
),
3599 &dwz
->gdb_index
, &dwz_map
,
3600 &dwz_list
, &dwz_list_elements
,
3602 &dwz_types_elements_ignore
))
3604 warning (_("could not read '.gdb_index' section from %s; skipping"),
3605 bfd_get_filename (dwz
->dwz_bfd
));
3610 create_cus_from_index (objfile
, cu_list
, cu_list_elements
, dwz_list
,
3613 if (types_list_elements
)
3615 struct dwarf2_section_info
*section
;
3617 /* We can only handle a single .debug_types when we have an
3619 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
3622 section
= VEC_index (dwarf2_section_info_def
,
3623 dwarf2_per_objfile
->types
, 0);
3625 create_signatured_type_table_from_index (objfile
, section
, types_list
,
3626 types_list_elements
);
3629 create_addrmap_from_index (dwarf2_per_objfile
, &local_map
);
3631 map
= XOBNEW (&objfile
->objfile_obstack
, struct mapped_index
);
3632 map
= new (map
) mapped_index ();
3635 dwarf2_per_objfile
->index_table
= map
;
3636 dwarf2_per_objfile
->using_index
= 1;
3637 dwarf2_per_objfile
->quick_file_names_table
=
3638 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3643 /* die_reader_func for dw2_get_file_names. */
3646 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3647 const gdb_byte
*info_ptr
,
3648 struct die_info
*comp_unit_die
,
3652 struct dwarf2_cu
*cu
= reader
->cu
;
3653 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3654 struct dwarf2_per_objfile
*dwarf2_per_objfile
3655 = cu
->per_cu
->dwarf2_per_objfile
;
3656 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3657 struct dwarf2_per_cu_data
*lh_cu
;
3658 struct attribute
*attr
;
3661 struct quick_file_names
*qfn
;
3663 gdb_assert (! this_cu
->is_debug_types
);
3665 /* Our callers never want to match partial units -- instead they
3666 will match the enclosing full CU. */
3667 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3669 this_cu
->v
.quick
->no_file_data
= 1;
3677 sect_offset line_offset
{};
3679 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3682 struct quick_file_names find_entry
;
3684 line_offset
= (sect_offset
) DW_UNSND (attr
);
3686 /* We may have already read in this line header (TU line header sharing).
3687 If we have we're done. */
3688 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3689 find_entry
.hash
.line_sect_off
= line_offset
;
3690 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
3691 &find_entry
, INSERT
);
3694 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3698 lh
= dwarf_decode_line_header (line_offset
, cu
);
3702 lh_cu
->v
.quick
->no_file_data
= 1;
3706 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3707 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3708 qfn
->hash
.line_sect_off
= line_offset
;
3709 gdb_assert (slot
!= NULL
);
3712 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3714 qfn
->num_file_names
= lh
->file_names
.size ();
3716 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, lh
->file_names
.size ());
3717 for (i
= 0; i
< lh
->file_names
.size (); ++i
)
3718 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
.get (), fnd
.comp_dir
);
3719 qfn
->real_names
= NULL
;
3721 lh_cu
->v
.quick
->file_names
= qfn
;
3724 /* A helper for the "quick" functions which attempts to read the line
3725 table for THIS_CU. */
3727 static struct quick_file_names
*
3728 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3730 /* This should never be called for TUs. */
3731 gdb_assert (! this_cu
->is_debug_types
);
3732 /* Nor type unit groups. */
3733 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3735 if (this_cu
->v
.quick
->file_names
!= NULL
)
3736 return this_cu
->v
.quick
->file_names
;
3737 /* If we know there is no line data, no point in looking again. */
3738 if (this_cu
->v
.quick
->no_file_data
)
3741 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
3743 if (this_cu
->v
.quick
->no_file_data
)
3745 return this_cu
->v
.quick
->file_names
;
3748 /* A helper for the "quick" functions which computes and caches the
3749 real path for a given file name from the line table. */
3752 dw2_get_real_path (struct objfile
*objfile
,
3753 struct quick_file_names
*qfn
, int index
)
3755 if (qfn
->real_names
== NULL
)
3756 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3757 qfn
->num_file_names
, const char *);
3759 if (qfn
->real_names
[index
] == NULL
)
3760 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3762 return qfn
->real_names
[index
];
3765 static struct symtab
*
3766 dw2_find_last_source_symtab (struct objfile
*objfile
)
3768 struct dwarf2_per_objfile
*dwarf2_per_objfile
3769 = get_dwarf2_per_objfile (objfile
);
3770 int index
= dwarf2_per_objfile
->n_comp_units
- 1;
3771 dwarf2_per_cu_data
*dwarf_cu
= dw2_get_cutu (dwarf2_per_objfile
, index
);
3772 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
);
3777 return compunit_primary_filetab (cust
);
3780 /* Traversal function for dw2_forget_cached_source_info. */
3783 dw2_free_cached_file_names (void **slot
, void *info
)
3785 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3787 if (file_data
->real_names
)
3791 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3793 xfree ((void*) file_data
->real_names
[i
]);
3794 file_data
->real_names
[i
] = NULL
;
3802 dw2_forget_cached_source_info (struct objfile
*objfile
)
3804 struct dwarf2_per_objfile
*dwarf2_per_objfile
3805 = get_dwarf2_per_objfile (objfile
);
3807 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3808 dw2_free_cached_file_names
, NULL
);
3811 /* Helper function for dw2_map_symtabs_matching_filename that expands
3812 the symtabs and calls the iterator. */
3815 dw2_map_expand_apply (struct objfile
*objfile
,
3816 struct dwarf2_per_cu_data
*per_cu
,
3817 const char *name
, const char *real_path
,
3818 gdb::function_view
<bool (symtab
*)> callback
)
3820 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3822 /* Don't visit already-expanded CUs. */
3823 if (per_cu
->v
.quick
->compunit_symtab
)
3826 /* This may expand more than one symtab, and we want to iterate over
3828 dw2_instantiate_symtab (per_cu
);
3830 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3831 last_made
, callback
);
3834 /* Implementation of the map_symtabs_matching_filename method. */
3837 dw2_map_symtabs_matching_filename
3838 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3839 gdb::function_view
<bool (symtab
*)> callback
)
3842 const char *name_basename
= lbasename (name
);
3843 struct dwarf2_per_objfile
*dwarf2_per_objfile
3844 = get_dwarf2_per_objfile (objfile
);
3846 /* The rule is CUs specify all the files, including those used by
3847 any TU, so there's no need to scan TUs here. */
3849 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3852 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (dwarf2_per_objfile
, i
);
3853 struct quick_file_names
*file_data
;
3855 /* We only need to look at symtabs not already expanded. */
3856 if (per_cu
->v
.quick
->compunit_symtab
)
3859 file_data
= dw2_get_file_names (per_cu
);
3860 if (file_data
== NULL
)
3863 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3865 const char *this_name
= file_data
->file_names
[j
];
3866 const char *this_real_name
;
3868 if (compare_filenames_for_search (this_name
, name
))
3870 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3876 /* Before we invoke realpath, which can get expensive when many
3877 files are involved, do a quick comparison of the basenames. */
3878 if (! basenames_may_differ
3879 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3882 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3883 if (compare_filenames_for_search (this_real_name
, name
))
3885 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3891 if (real_path
!= NULL
)
3893 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3894 gdb_assert (IS_ABSOLUTE_PATH (name
));
3895 if (this_real_name
!= NULL
3896 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3898 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3910 /* Struct used to manage iterating over all CUs looking for a symbol. */
3912 struct dw2_symtab_iterator
3914 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3915 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3916 /* If non-zero, only look for symbols that match BLOCK_INDEX. */
3917 int want_specific_block
;
3918 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
3919 Unused if !WANT_SPECIFIC_BLOCK. */
3921 /* The kind of symbol we're looking for. */
3923 /* The list of CUs from the index entry of the symbol,
3924 or NULL if not found. */
3926 /* The next element in VEC to look at. */
3928 /* The number of elements in VEC, or zero if there is no match. */
3930 /* Have we seen a global version of the symbol?
3931 If so we can ignore all further global instances.
3932 This is to work around gold/15646, inefficient gold-generated
3937 /* Initialize the index symtab iterator ITER.
3938 If WANT_SPECIFIC_BLOCK is non-zero, only look for symbols
3939 in block BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
3942 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3943 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3944 int want_specific_block
,
3949 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3950 iter
->want_specific_block
= want_specific_block
;
3951 iter
->block_index
= block_index
;
3952 iter
->domain
= domain
;
3954 iter
->global_seen
= 0;
3956 mapped_index
*index
= dwarf2_per_objfile
->index_table
;
3958 /* index is NULL if OBJF_READNOW. */
3959 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3960 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3968 /* Return the next matching CU or NULL if there are no more. */
3970 static struct dwarf2_per_cu_data
*
3971 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3973 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3975 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3977 offset_type cu_index_and_attrs
=
3978 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3979 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3980 struct dwarf2_per_cu_data
*per_cu
;
3981 int want_static
= iter
->block_index
!= GLOBAL_BLOCK
;
3982 /* This value is only valid for index versions >= 7. */
3983 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3984 gdb_index_symbol_kind symbol_kind
=
3985 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3986 /* Only check the symbol attributes if they're present.
3987 Indices prior to version 7 don't record them,
3988 and indices >= 7 may elide them for certain symbols
3989 (gold does this). */
3991 (dwarf2_per_objfile
->index_table
->version
>= 7
3992 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3994 /* Don't crash on bad data. */
3995 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
3996 + dwarf2_per_objfile
->n_type_units
))
3998 complaint (&symfile_complaints
,
3999 _(".gdb_index entry has bad CU index"
4001 objfile_name (dwarf2_per_objfile
->objfile
));
4005 per_cu
= dw2_get_cutu (dwarf2_per_objfile
, cu_index
);
4007 /* Skip if already read in. */
4008 if (per_cu
->v
.quick
->compunit_symtab
)
4011 /* Check static vs global. */
4014 if (iter
->want_specific_block
4015 && want_static
!= is_static
)
4017 /* Work around gold/15646. */
4018 if (!is_static
&& iter
->global_seen
)
4021 iter
->global_seen
= 1;
4024 /* Only check the symbol's kind if it has one. */
4027 switch (iter
->domain
)
4030 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
4031 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
4032 /* Some types are also in VAR_DOMAIN. */
4033 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4037 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4041 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4056 static struct compunit_symtab
*
4057 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
4058 const char *name
, domain_enum domain
)
4060 struct compunit_symtab
*stab_best
= NULL
;
4061 struct dwarf2_per_objfile
*dwarf2_per_objfile
4062 = get_dwarf2_per_objfile (objfile
);
4064 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
4066 struct dw2_symtab_iterator iter
;
4067 struct dwarf2_per_cu_data
*per_cu
;
4069 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, 1, block_index
, domain
, name
);
4071 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4073 struct symbol
*sym
, *with_opaque
= NULL
;
4074 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
);
4075 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
4076 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
4078 sym
= block_find_symbol (block
, name
, domain
,
4079 block_find_non_opaque_type_preferred
,
4082 /* Some caution must be observed with overloaded functions
4083 and methods, since the index will not contain any overload
4084 information (but NAME might contain it). */
4087 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
4089 if (with_opaque
!= NULL
4090 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
4093 /* Keep looking through other CUs. */
4100 dw2_print_stats (struct objfile
*objfile
)
4102 struct dwarf2_per_objfile
*dwarf2_per_objfile
4103 = get_dwarf2_per_objfile (objfile
);
4104 int total
= dwarf2_per_objfile
->n_comp_units
+ dwarf2_per_objfile
->n_type_units
;
4107 for (int i
= 0; i
< total
; ++i
)
4109 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
4111 if (!per_cu
->v
.quick
->compunit_symtab
)
4114 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
4115 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
4118 /* This dumps minimal information about the index.
4119 It is called via "mt print objfiles".
4120 One use is to verify .gdb_index has been loaded by the
4121 gdb.dwarf2/gdb-index.exp testcase. */
4124 dw2_dump (struct objfile
*objfile
)
4126 struct dwarf2_per_objfile
*dwarf2_per_objfile
4127 = get_dwarf2_per_objfile (objfile
);
4129 gdb_assert (dwarf2_per_objfile
->using_index
);
4130 printf_filtered (".gdb_index:");
4131 if (dwarf2_per_objfile
->index_table
!= NULL
)
4133 printf_filtered (" version %d\n",
4134 dwarf2_per_objfile
->index_table
->version
);
4137 printf_filtered (" faked for \"readnow\"\n");
4138 printf_filtered ("\n");
4142 dw2_relocate (struct objfile
*objfile
,
4143 const struct section_offsets
*new_offsets
,
4144 const struct section_offsets
*delta
)
4146 /* There's nothing to relocate here. */
4150 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
4151 const char *func_name
)
4153 struct dwarf2_per_objfile
*dwarf2_per_objfile
4154 = get_dwarf2_per_objfile (objfile
);
4156 struct dw2_symtab_iterator iter
;
4157 struct dwarf2_per_cu_data
*per_cu
;
4159 /* Note: It doesn't matter what we pass for block_index here. */
4160 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, 0, GLOBAL_BLOCK
, VAR_DOMAIN
,
4163 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4164 dw2_instantiate_symtab (per_cu
);
4169 dw2_expand_all_symtabs (struct objfile
*objfile
)
4171 struct dwarf2_per_objfile
*dwarf2_per_objfile
4172 = get_dwarf2_per_objfile (objfile
);
4173 int total_units
= (dwarf2_per_objfile
->n_comp_units
4174 + dwarf2_per_objfile
->n_type_units
);
4176 for (int i
= 0; i
< total_units
; ++i
)
4178 struct dwarf2_per_cu_data
*per_cu
4179 = dw2_get_cutu (dwarf2_per_objfile
, i
);
4181 dw2_instantiate_symtab (per_cu
);
4186 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
4187 const char *fullname
)
4189 struct dwarf2_per_objfile
*dwarf2_per_objfile
4190 = get_dwarf2_per_objfile (objfile
);
4192 /* We don't need to consider type units here.
4193 This is only called for examining code, e.g. expand_line_sal.
4194 There can be an order of magnitude (or more) more type units
4195 than comp units, and we avoid them if we can. */
4197 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4200 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
4201 struct quick_file_names
*file_data
;
4203 /* We only need to look at symtabs not already expanded. */
4204 if (per_cu
->v
.quick
->compunit_symtab
)
4207 file_data
= dw2_get_file_names (per_cu
);
4208 if (file_data
== NULL
)
4211 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
4213 const char *this_fullname
= file_data
->file_names
[j
];
4215 if (filename_cmp (this_fullname
, fullname
) == 0)
4217 dw2_instantiate_symtab (per_cu
);
4225 dw2_map_matching_symbols (struct objfile
*objfile
,
4226 const char * name
, domain_enum domain
,
4228 int (*callback
) (struct block
*,
4229 struct symbol
*, void *),
4230 void *data
, symbol_name_match_type match
,
4231 symbol_compare_ftype
*ordered_compare
)
4233 /* Currently unimplemented; used for Ada. The function can be called if the
4234 current language is Ada for a non-Ada objfile using GNU index. As Ada
4235 does not look for non-Ada symbols this function should just return. */
4238 /* Symbol name matcher for .gdb_index names.
4240 Symbol names in .gdb_index have a few particularities:
4242 - There's no indication of which is the language of each symbol.
4244 Since each language has its own symbol name matching algorithm,
4245 and we don't know which language is the right one, we must match
4246 each symbol against all languages. This would be a potential
4247 performance problem if it were not mitigated by the
4248 mapped_index::name_components lookup table, which significantly
4249 reduces the number of times we need to call into this matcher,
4250 making it a non-issue.
4252 - Symbol names in the index have no overload (parameter)
4253 information. I.e., in C++, "foo(int)" and "foo(long)" both
4254 appear as "foo" in the index, for example.
4256 This means that the lookup names passed to the symbol name
4257 matcher functions must have no parameter information either
4258 because (e.g.) symbol search name "foo" does not match
4259 lookup-name "foo(int)" [while swapping search name for lookup
4262 class gdb_index_symbol_name_matcher
4265 /* Prepares the vector of comparison functions for LOOKUP_NAME. */
4266 gdb_index_symbol_name_matcher (const lookup_name_info
&lookup_name
);
4268 /* Walk all the matcher routines and match SYMBOL_NAME against them.
4269 Returns true if any matcher matches. */
4270 bool matches (const char *symbol_name
);
4273 /* A reference to the lookup name we're matching against. */
4274 const lookup_name_info
&m_lookup_name
;
4276 /* A vector holding all the different symbol name matchers, for all
4278 std::vector
<symbol_name_matcher_ftype
*> m_symbol_name_matcher_funcs
;
4281 gdb_index_symbol_name_matcher::gdb_index_symbol_name_matcher
4282 (const lookup_name_info
&lookup_name
)
4283 : m_lookup_name (lookup_name
)
4285 /* Prepare the vector of comparison functions upfront, to avoid
4286 doing the same work for each symbol. Care is taken to avoid
4287 matching with the same matcher more than once if/when multiple
4288 languages use the same matcher function. */
4289 auto &matchers
= m_symbol_name_matcher_funcs
;
4290 matchers
.reserve (nr_languages
);
4292 matchers
.push_back (default_symbol_name_matcher
);
4294 for (int i
= 0; i
< nr_languages
; i
++)
4296 const language_defn
*lang
= language_def ((enum language
) i
);
4297 symbol_name_matcher_ftype
*name_matcher
4298 = get_symbol_name_matcher (lang
, m_lookup_name
);
4300 /* Don't insert the same comparison routine more than once.
4301 Note that we do this linear walk instead of a seemingly
4302 cheaper sorted insert, or use a std::set or something like
4303 that, because relative order of function addresses is not
4304 stable. This is not a problem in practice because the number
4305 of supported languages is low, and the cost here is tiny
4306 compared to the number of searches we'll do afterwards using
4308 if (name_matcher
!= default_symbol_name_matcher
4309 && (std::find (matchers
.begin (), matchers
.end (), name_matcher
)
4310 == matchers
.end ()))
4311 matchers
.push_back (name_matcher
);
4316 gdb_index_symbol_name_matcher::matches (const char *symbol_name
)
4318 for (auto matches_name
: m_symbol_name_matcher_funcs
)
4319 if (matches_name (symbol_name
, m_lookup_name
, NULL
))
4325 /* Starting from a search name, return the string that finds the upper
4326 bound of all strings that start with SEARCH_NAME in a sorted name
4327 list. Returns the empty string to indicate that the upper bound is
4328 the end of the list. */
4331 make_sort_after_prefix_name (const char *search_name
)
4333 /* When looking to complete "func", we find the upper bound of all
4334 symbols that start with "func" by looking for where we'd insert
4335 the closest string that would follow "func" in lexicographical
4336 order. Usually, that's "func"-with-last-character-incremented,
4337 i.e. "fund". Mind non-ASCII characters, though. Usually those
4338 will be UTF-8 multi-byte sequences, but we can't be certain.
4339 Especially mind the 0xff character, which is a valid character in
4340 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
4341 rule out compilers allowing it in identifiers. Note that
4342 conveniently, strcmp/strcasecmp are specified to compare
4343 characters interpreted as unsigned char. So what we do is treat
4344 the whole string as a base 256 number composed of a sequence of
4345 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
4346 to 0, and carries 1 to the following more-significant position.
4347 If the very first character in SEARCH_NAME ends up incremented
4348 and carries/overflows, then the upper bound is the end of the
4349 list. The string after the empty string is also the empty
4352 Some examples of this operation:
4354 SEARCH_NAME => "+1" RESULT
4358 "\xff" "a" "\xff" => "\xff" "b"
4363 Then, with these symbols for example:
4369 completing "func" looks for symbols between "func" and
4370 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
4371 which finds "func" and "func1", but not "fund".
4375 funcÿ (Latin1 'ÿ' [0xff])
4379 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
4380 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
4384 ÿÿ (Latin1 'ÿ' [0xff])
4387 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
4388 the end of the list.
4390 std::string after
= search_name
;
4391 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
4393 if (!after
.empty ())
4394 after
.back () = (unsigned char) after
.back () + 1;
4398 /* See declaration. */
4400 std::pair
<std::vector
<name_component
>::const_iterator
,
4401 std::vector
<name_component
>::const_iterator
>
4402 mapped_index_base::find_name_components_bounds
4403 (const lookup_name_info
&lookup_name_without_params
) const
4406 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4409 = lookup_name_without_params
.cplus ().lookup_name ().c_str ();
4411 /* Comparison function object for lower_bound that matches against a
4412 given symbol name. */
4413 auto lookup_compare_lower
= [&] (const name_component
&elem
,
4416 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4417 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4418 return name_cmp (elem_name
, name
) < 0;
4421 /* Comparison function object for upper_bound that matches against a
4422 given symbol name. */
4423 auto lookup_compare_upper
= [&] (const char *name
,
4424 const name_component
&elem
)
4426 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4427 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4428 return name_cmp (name
, elem_name
) < 0;
4431 auto begin
= this->name_components
.begin ();
4432 auto end
= this->name_components
.end ();
4434 /* Find the lower bound. */
4437 if (lookup_name_without_params
.completion_mode () && cplus
[0] == '\0')
4440 return std::lower_bound (begin
, end
, cplus
, lookup_compare_lower
);
4443 /* Find the upper bound. */
4446 if (lookup_name_without_params
.completion_mode ())
4448 /* In completion mode, we want UPPER to point past all
4449 symbols names that have the same prefix. I.e., with
4450 these symbols, and completing "func":
4452 function << lower bound
4454 other_function << upper bound
4456 We find the upper bound by looking for the insertion
4457 point of "func"-with-last-character-incremented,
4459 std::string after
= make_sort_after_prefix_name (cplus
);
4462 return std::lower_bound (lower
, end
, after
.c_str (),
4463 lookup_compare_lower
);
4466 return std::upper_bound (lower
, end
, cplus
, lookup_compare_upper
);
4469 return {lower
, upper
};
4472 /* See declaration. */
4475 mapped_index_base::build_name_components ()
4477 if (!this->name_components
.empty ())
4480 this->name_components_casing
= case_sensitivity
;
4482 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4484 /* The code below only knows how to break apart components of C++
4485 symbol names (and other languages that use '::' as
4486 namespace/module separator). If we add support for wild matching
4487 to some language that uses some other operator (E.g., Ada, Go and
4488 D use '.'), then we'll need to try splitting the symbol name
4489 according to that language too. Note that Ada does support wild
4490 matching, but doesn't currently support .gdb_index. */
4491 auto count
= this->symbol_name_count ();
4492 for (offset_type idx
= 0; idx
< count
; idx
++)
4494 if (this->symbol_name_slot_invalid (idx
))
4497 const char *name
= this->symbol_name_at (idx
);
4499 /* Add each name component to the name component table. */
4500 unsigned int previous_len
= 0;
4501 for (unsigned int current_len
= cp_find_first_component (name
);
4502 name
[current_len
] != '\0';
4503 current_len
+= cp_find_first_component (name
+ current_len
))
4505 gdb_assert (name
[current_len
] == ':');
4506 this->name_components
.push_back ({previous_len
, idx
});
4507 /* Skip the '::'. */
4509 previous_len
= current_len
;
4511 this->name_components
.push_back ({previous_len
, idx
});
4514 /* Sort name_components elements by name. */
4515 auto name_comp_compare
= [&] (const name_component
&left
,
4516 const name_component
&right
)
4518 const char *left_qualified
= this->symbol_name_at (left
.idx
);
4519 const char *right_qualified
= this->symbol_name_at (right
.idx
);
4521 const char *left_name
= left_qualified
+ left
.name_offset
;
4522 const char *right_name
= right_qualified
+ right
.name_offset
;
4524 return name_cmp (left_name
, right_name
) < 0;
4527 std::sort (this->name_components
.begin (),
4528 this->name_components
.end (),
4532 /* Helper for dw2_expand_symtabs_matching that works with a
4533 mapped_index_base instead of the containing objfile. This is split
4534 to a separate function in order to be able to unit test the
4535 name_components matching using a mock mapped_index_base. For each
4536 symbol name that matches, calls MATCH_CALLBACK, passing it the
4537 symbol's index in the mapped_index_base symbol table. */
4540 dw2_expand_symtabs_matching_symbol
4541 (mapped_index_base
&index
,
4542 const lookup_name_info
&lookup_name_in
,
4543 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4544 enum search_domain kind
,
4545 gdb::function_view
<void (offset_type
)> match_callback
)
4547 lookup_name_info lookup_name_without_params
4548 = lookup_name_in
.make_ignore_params ();
4549 gdb_index_symbol_name_matcher lookup_name_matcher
4550 (lookup_name_without_params
);
4552 /* Build the symbol name component sorted vector, if we haven't
4554 index
.build_name_components ();
4556 auto bounds
= index
.find_name_components_bounds (lookup_name_without_params
);
4558 /* Now for each symbol name in range, check to see if we have a name
4559 match, and if so, call the MATCH_CALLBACK callback. */
4561 /* The same symbol may appear more than once in the range though.
4562 E.g., if we're looking for symbols that complete "w", and we have
4563 a symbol named "w1::w2", we'll find the two name components for
4564 that same symbol in the range. To be sure we only call the
4565 callback once per symbol, we first collect the symbol name
4566 indexes that matched in a temporary vector and ignore
4568 std::vector
<offset_type
> matches
;
4569 matches
.reserve (std::distance (bounds
.first
, bounds
.second
));
4571 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4573 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
4575 if (!lookup_name_matcher
.matches (qualified
)
4576 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4579 matches
.push_back (bounds
.first
->idx
);
4582 std::sort (matches
.begin (), matches
.end ());
4584 /* Finally call the callback, once per match. */
4586 for (offset_type idx
: matches
)
4590 match_callback (idx
);
4595 /* Above we use a type wider than idx's for 'prev', since 0 and
4596 (offset_type)-1 are both possible values. */
4597 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4602 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4604 /* A mock .gdb_index/.debug_names-like name index table, enough to
4605 exercise dw2_expand_symtabs_matching_symbol, which works with the
4606 mapped_index_base interface. Builds an index from the symbol list
4607 passed as parameter to the constructor. */
4608 class mock_mapped_index
: public mapped_index_base
4611 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4612 : m_symbol_table (symbols
)
4615 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4617 /* Return the number of names in the symbol table. */
4618 virtual size_t symbol_name_count () const
4620 return m_symbol_table
.size ();
4623 /* Get the name of the symbol at IDX in the symbol table. */
4624 virtual const char *symbol_name_at (offset_type idx
) const
4626 return m_symbol_table
[idx
];
4630 gdb::array_view
<const char *> m_symbol_table
;
4633 /* Convenience function that converts a NULL pointer to a "<null>"
4634 string, to pass to print routines. */
4637 string_or_null (const char *str
)
4639 return str
!= NULL
? str
: "<null>";
4642 /* Check if a lookup_name_info built from
4643 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4644 index. EXPECTED_LIST is the list of expected matches, in expected
4645 matching order. If no match expected, then an empty list is
4646 specified. Returns true on success. On failure prints a warning
4647 indicating the file:line that failed, and returns false. */
4650 check_match (const char *file
, int line
,
4651 mock_mapped_index
&mock_index
,
4652 const char *name
, symbol_name_match_type match_type
,
4653 bool completion_mode
,
4654 std::initializer_list
<const char *> expected_list
)
4656 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4658 bool matched
= true;
4660 auto mismatch
= [&] (const char *expected_str
,
4663 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4664 "expected=\"%s\", got=\"%s\"\n"),
4666 (match_type
== symbol_name_match_type::FULL
4668 name
, string_or_null (expected_str
), string_or_null (got
));
4672 auto expected_it
= expected_list
.begin ();
4673 auto expected_end
= expected_list
.end ();
4675 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4677 [&] (offset_type idx
)
4679 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4680 const char *expected_str
4681 = expected_it
== expected_end
? NULL
: *expected_it
++;
4683 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4684 mismatch (expected_str
, matched_name
);
4687 const char *expected_str
4688 = expected_it
== expected_end
? NULL
: *expected_it
++;
4689 if (expected_str
!= NULL
)
4690 mismatch (expected_str
, NULL
);
4695 /* The symbols added to the mock mapped_index for testing (in
4697 static const char *test_symbols
[] = {
4706 "ns2::tmpl<int>::foo2",
4707 "(anonymous namespace)::A::B::C",
4709 /* These are used to check that the increment-last-char in the
4710 matching algorithm for completion doesn't match "t1_fund" when
4711 completing "t1_func". */
4717 /* A UTF-8 name with multi-byte sequences to make sure that
4718 cp-name-parser understands this as a single identifier ("função"
4719 is "function" in PT). */
4722 /* \377 (0xff) is Latin1 'ÿ'. */
4725 /* \377 (0xff) is Latin1 'ÿ'. */
4729 /* A name with all sorts of complications. Starts with "z" to make
4730 it easier for the completion tests below. */
4731 #define Z_SYM_NAME \
4732 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4733 "::tuple<(anonymous namespace)::ui*, " \
4734 "std::default_delete<(anonymous namespace)::ui>, void>"
4739 /* Returns true if the mapped_index_base::find_name_component_bounds
4740 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4741 in completion mode. */
4744 check_find_bounds_finds (mapped_index_base
&index
,
4745 const char *search_name
,
4746 gdb::array_view
<const char *> expected_syms
)
4748 lookup_name_info
lookup_name (search_name
,
4749 symbol_name_match_type::FULL
, true);
4751 auto bounds
= index
.find_name_components_bounds (lookup_name
);
4753 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4754 if (distance
!= expected_syms
.size ())
4757 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4759 auto nc_elem
= bounds
.first
+ exp_elem
;
4760 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4761 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4768 /* Test the lower-level mapped_index::find_name_component_bounds
4772 test_mapped_index_find_name_component_bounds ()
4774 mock_mapped_index
mock_index (test_symbols
);
4776 mock_index
.build_name_components ();
4778 /* Test the lower-level mapped_index::find_name_component_bounds
4779 method in completion mode. */
4781 static const char *expected_syms
[] = {
4786 SELF_CHECK (check_find_bounds_finds (mock_index
,
4787 "t1_func", expected_syms
));
4790 /* Check that the increment-last-char in the name matching algorithm
4791 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4793 static const char *expected_syms1
[] = {
4797 SELF_CHECK (check_find_bounds_finds (mock_index
,
4798 "\377", expected_syms1
));
4800 static const char *expected_syms2
[] = {
4803 SELF_CHECK (check_find_bounds_finds (mock_index
,
4804 "\377\377", expected_syms2
));
4808 /* Test dw2_expand_symtabs_matching_symbol. */
4811 test_dw2_expand_symtabs_matching_symbol ()
4813 mock_mapped_index
mock_index (test_symbols
);
4815 /* We let all tests run until the end even if some fails, for debug
4817 bool any_mismatch
= false;
4819 /* Create the expected symbols list (an initializer_list). Needed
4820 because lists have commas, and we need to pass them to CHECK,
4821 which is a macro. */
4822 #define EXPECT(...) { __VA_ARGS__ }
4824 /* Wrapper for check_match that passes down the current
4825 __FILE__/__LINE__. */
4826 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4827 any_mismatch |= !check_match (__FILE__, __LINE__, \
4829 NAME, MATCH_TYPE, COMPLETION_MODE, \
4832 /* Identity checks. */
4833 for (const char *sym
: test_symbols
)
4835 /* Should be able to match all existing symbols. */
4836 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4839 /* Should be able to match all existing symbols with
4841 std::string with_params
= std::string (sym
) + "(int)";
4842 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4845 /* Should be able to match all existing symbols with
4846 parameters and qualifiers. */
4847 with_params
= std::string (sym
) + " ( int ) const";
4848 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4851 /* This should really find sym, but cp-name-parser.y doesn't
4852 know about lvalue/rvalue qualifiers yet. */
4853 with_params
= std::string (sym
) + " ( int ) &&";
4854 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4858 /* Check that the name matching algorithm for completion doesn't get
4859 confused with Latin1 'ÿ' / 0xff. */
4861 static const char str
[] = "\377";
4862 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4863 EXPECT ("\377", "\377\377123"));
4866 /* Check that the increment-last-char in the matching algorithm for
4867 completion doesn't match "t1_fund" when completing "t1_func". */
4869 static const char str
[] = "t1_func";
4870 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4871 EXPECT ("t1_func", "t1_func1"));
4874 /* Check that completion mode works at each prefix of the expected
4877 static const char str
[] = "function(int)";
4878 size_t len
= strlen (str
);
4881 for (size_t i
= 1; i
< len
; i
++)
4883 lookup
.assign (str
, i
);
4884 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4885 EXPECT ("function"));
4889 /* While "w" is a prefix of both components, the match function
4890 should still only be called once. */
4892 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4894 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4898 /* Same, with a "complicated" symbol. */
4900 static const char str
[] = Z_SYM_NAME
;
4901 size_t len
= strlen (str
);
4904 for (size_t i
= 1; i
< len
; i
++)
4906 lookup
.assign (str
, i
);
4907 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4908 EXPECT (Z_SYM_NAME
));
4912 /* In FULL mode, an incomplete symbol doesn't match. */
4914 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4918 /* A complete symbol with parameters matches any overload, since the
4919 index has no overload info. */
4921 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4922 EXPECT ("std::zfunction", "std::zfunction2"));
4923 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4924 EXPECT ("std::zfunction", "std::zfunction2"));
4925 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4926 EXPECT ("std::zfunction", "std::zfunction2"));
4929 /* Check that whitespace is ignored appropriately. A symbol with a
4930 template argument list. */
4932 static const char expected
[] = "ns::foo<int>";
4933 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4935 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4939 /* Check that whitespace is ignored appropriately. A symbol with a
4940 template argument list that includes a pointer. */
4942 static const char expected
[] = "ns::foo<char*>";
4943 /* Try both completion and non-completion modes. */
4944 static const bool completion_mode
[2] = {false, true};
4945 for (size_t i
= 0; i
< 2; i
++)
4947 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4948 completion_mode
[i
], EXPECT (expected
));
4949 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4950 completion_mode
[i
], EXPECT (expected
));
4952 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4953 completion_mode
[i
], EXPECT (expected
));
4954 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4955 completion_mode
[i
], EXPECT (expected
));
4960 /* Check method qualifiers are ignored. */
4961 static const char expected
[] = "ns::foo<char*>";
4962 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4963 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4964 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4965 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4966 CHECK_MATCH ("foo < char * > ( int ) const",
4967 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4968 CHECK_MATCH ("foo < char * > ( int ) &&",
4969 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4972 /* Test lookup names that don't match anything. */
4974 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4977 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4981 /* Some wild matching tests, exercising "(anonymous namespace)",
4982 which should not be confused with a parameter list. */
4984 static const char *syms
[] = {
4988 "A :: B :: C ( int )",
4993 for (const char *s
: syms
)
4995 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4996 EXPECT ("(anonymous namespace)::A::B::C"));
5001 static const char expected
[] = "ns2::tmpl<int>::foo2";
5002 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
5004 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
5008 SELF_CHECK (!any_mismatch
);
5017 test_mapped_index_find_name_component_bounds ();
5018 test_dw2_expand_symtabs_matching_symbol ();
5021 }} // namespace selftests::dw2_expand_symtabs_matching
5023 #endif /* GDB_SELF_TEST */
5025 /* If FILE_MATCHER is NULL or if PER_CU has
5026 dwarf2_per_cu_quick_data::MARK set (see
5027 dw_expand_symtabs_matching_file_matcher), expand the CU and call
5028 EXPANSION_NOTIFY on it. */
5031 dw2_expand_symtabs_matching_one
5032 (struct dwarf2_per_cu_data
*per_cu
,
5033 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5034 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
5036 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
5038 bool symtab_was_null
5039 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
5041 dw2_instantiate_symtab (per_cu
);
5043 if (expansion_notify
!= NULL
5045 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
5046 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
5050 /* Helper for dw2_expand_matching symtabs. Called on each symbol
5051 matched, to expand corresponding CUs that were marked. IDX is the
5052 index of the symbol name that matched. */
5055 dw2_expand_marked_cus
5056 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
5057 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5058 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5061 offset_type
*vec
, vec_len
, vec_idx
;
5062 bool global_seen
= false;
5063 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5065 vec
= (offset_type
*) (index
.constant_pool
5066 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
5067 vec_len
= MAYBE_SWAP (vec
[0]);
5068 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
5070 struct dwarf2_per_cu_data
*per_cu
;
5071 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
5072 /* This value is only valid for index versions >= 7. */
5073 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
5074 gdb_index_symbol_kind symbol_kind
=
5075 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
5076 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
5077 /* Only check the symbol attributes if they're present.
5078 Indices prior to version 7 don't record them,
5079 and indices >= 7 may elide them for certain symbols
5080 (gold does this). */
5083 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
5085 /* Work around gold/15646. */
5088 if (!is_static
&& global_seen
)
5094 /* Only check the symbol's kind if it has one. */
5099 case VARIABLES_DOMAIN
:
5100 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
5103 case FUNCTIONS_DOMAIN
:
5104 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
5108 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
5116 /* Don't crash on bad data. */
5117 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
5118 + dwarf2_per_objfile
->n_type_units
))
5120 complaint (&symfile_complaints
,
5121 _(".gdb_index entry has bad CU index"
5123 objfile_name (dwarf2_per_objfile
->objfile
));
5127 per_cu
= dw2_get_cutu (dwarf2_per_objfile
, cu_index
);
5128 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5133 /* If FILE_MATCHER is non-NULL, set all the
5134 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
5135 that match FILE_MATCHER. */
5138 dw_expand_symtabs_matching_file_matcher
5139 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5140 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
5142 if (file_matcher
== NULL
)
5145 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
5147 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
5149 NULL
, xcalloc
, xfree
));
5150 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
5152 NULL
, xcalloc
, xfree
));
5154 /* The rule is CUs specify all the files, including those used by
5155 any TU, so there's no need to scan TUs here. */
5157 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5160 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (dwarf2_per_objfile
, i
);
5161 struct quick_file_names
*file_data
;
5166 per_cu
->v
.quick
->mark
= 0;
5168 /* We only need to look at symtabs not already expanded. */
5169 if (per_cu
->v
.quick
->compunit_symtab
)
5172 file_data
= dw2_get_file_names (per_cu
);
5173 if (file_data
== NULL
)
5176 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
5178 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
5180 per_cu
->v
.quick
->mark
= 1;
5184 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
5186 const char *this_real_name
;
5188 if (file_matcher (file_data
->file_names
[j
], false))
5190 per_cu
->v
.quick
->mark
= 1;
5194 /* Before we invoke realpath, which can get expensive when many
5195 files are involved, do a quick comparison of the basenames. */
5196 if (!basenames_may_differ
5197 && !file_matcher (lbasename (file_data
->file_names
[j
]),
5201 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
5202 if (file_matcher (this_real_name
, false))
5204 per_cu
->v
.quick
->mark
= 1;
5209 slot
= htab_find_slot (per_cu
->v
.quick
->mark
5210 ? visited_found
.get ()
5211 : visited_not_found
.get (),
5218 dw2_expand_symtabs_matching
5219 (struct objfile
*objfile
,
5220 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5221 const lookup_name_info
&lookup_name
,
5222 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5223 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5224 enum search_domain kind
)
5226 struct dwarf2_per_objfile
*dwarf2_per_objfile
5227 = get_dwarf2_per_objfile (objfile
);
5229 /* index_table is NULL if OBJF_READNOW. */
5230 if (!dwarf2_per_objfile
->index_table
)
5233 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5235 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5237 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
5239 kind
, [&] (offset_type idx
)
5241 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
5242 expansion_notify
, kind
);
5246 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
5249 static struct compunit_symtab
*
5250 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
5255 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
5256 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
5259 if (cust
->includes
== NULL
)
5262 for (i
= 0; cust
->includes
[i
]; ++i
)
5264 struct compunit_symtab
*s
= cust
->includes
[i
];
5266 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
5274 static struct compunit_symtab
*
5275 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
5276 struct bound_minimal_symbol msymbol
,
5278 struct obj_section
*section
,
5281 struct dwarf2_per_cu_data
*data
;
5282 struct compunit_symtab
*result
;
5284 if (!objfile
->psymtabs_addrmap
)
5287 data
= (struct dwarf2_per_cu_data
*) addrmap_find (objfile
->psymtabs_addrmap
,
5292 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
5293 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
5294 paddress (get_objfile_arch (objfile
), pc
));
5297 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
),
5299 gdb_assert (result
!= NULL
);
5304 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
5305 void *data
, int need_fullname
)
5307 struct dwarf2_per_objfile
*dwarf2_per_objfile
5308 = get_dwarf2_per_objfile (objfile
);
5310 if (!dwarf2_per_objfile
->filenames_cache
)
5312 dwarf2_per_objfile
->filenames_cache
.emplace ();
5314 htab_up
visited (htab_create_alloc (10,
5315 htab_hash_pointer
, htab_eq_pointer
,
5316 NULL
, xcalloc
, xfree
));
5318 /* The rule is CUs specify all the files, including those used
5319 by any TU, so there's no need to scan TUs here. We can
5320 ignore file names coming from already-expanded CUs. */
5322 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5324 dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
5326 if (per_cu
->v
.quick
->compunit_symtab
)
5328 void **slot
= htab_find_slot (visited
.get (),
5329 per_cu
->v
.quick
->file_names
,
5332 *slot
= per_cu
->v
.quick
->file_names
;
5336 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5338 dwarf2_per_cu_data
*per_cu
= dw2_get_cu (dwarf2_per_objfile
, i
);
5339 struct quick_file_names
*file_data
;
5342 /* We only need to look at symtabs not already expanded. */
5343 if (per_cu
->v
.quick
->compunit_symtab
)
5346 file_data
= dw2_get_file_names (per_cu
);
5347 if (file_data
== NULL
)
5350 slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
5353 /* Already visited. */
5358 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5360 const char *filename
= file_data
->file_names
[j
];
5361 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
5366 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
5368 gdb::unique_xmalloc_ptr
<char> this_real_name
;
5371 this_real_name
= gdb_realpath (filename
);
5372 (*fun
) (filename
, this_real_name
.get (), data
);
5377 dw2_has_symbols (struct objfile
*objfile
)
5382 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
5385 dw2_find_last_source_symtab
,
5386 dw2_forget_cached_source_info
,
5387 dw2_map_symtabs_matching_filename
,
5392 dw2_expand_symtabs_for_function
,
5393 dw2_expand_all_symtabs
,
5394 dw2_expand_symtabs_with_fullname
,
5395 dw2_map_matching_symbols
,
5396 dw2_expand_symtabs_matching
,
5397 dw2_find_pc_sect_compunit_symtab
,
5399 dw2_map_symbol_filenames
5402 /* DWARF-5 debug_names reader. */
5404 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
5405 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
5407 /* A helper function that reads the .debug_names section in SECTION
5408 and fills in MAP. FILENAME is the name of the file containing the
5409 section; it is used for error reporting.
5411 Returns true if all went well, false otherwise. */
5414 read_debug_names_from_section (struct objfile
*objfile
,
5415 const char *filename
,
5416 struct dwarf2_section_info
*section
,
5417 mapped_debug_names
&map
)
5419 if (dwarf2_section_empty_p (section
))
5422 /* Older elfutils strip versions could keep the section in the main
5423 executable while splitting it for the separate debug info file. */
5424 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
5427 dwarf2_read_section (objfile
, section
);
5429 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
5431 const gdb_byte
*addr
= section
->buffer
;
5433 bfd
*const abfd
= get_section_bfd_owner (section
);
5435 unsigned int bytes_read
;
5436 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5439 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5440 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5441 if (bytes_read
+ length
!= section
->size
)
5443 /* There may be multiple per-CU indices. */
5444 warning (_("Section .debug_names in %s length %s does not match "
5445 "section length %s, ignoring .debug_names."),
5446 filename
, plongest (bytes_read
+ length
),
5447 pulongest (section
->size
));
5451 /* The version number. */
5452 uint16_t version
= read_2_bytes (abfd
, addr
);
5456 warning (_("Section .debug_names in %s has unsupported version %d, "
5457 "ignoring .debug_names."),
5463 uint16_t padding
= read_2_bytes (abfd
, addr
);
5467 warning (_("Section .debug_names in %s has unsupported padding %d, "
5468 "ignoring .debug_names."),
5473 /* comp_unit_count - The number of CUs in the CU list. */
5474 map
.cu_count
= read_4_bytes (abfd
, addr
);
5477 /* local_type_unit_count - The number of TUs in the local TU
5479 map
.tu_count
= read_4_bytes (abfd
, addr
);
5482 /* foreign_type_unit_count - The number of TUs in the foreign TU
5484 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5486 if (foreign_tu_count
!= 0)
5488 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5489 "ignoring .debug_names."),
5490 filename
, static_cast<unsigned long> (foreign_tu_count
));
5494 /* bucket_count - The number of hash buckets in the hash lookup
5496 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5499 /* name_count - The number of unique names in the index. */
5500 map
.name_count
= read_4_bytes (abfd
, addr
);
5503 /* abbrev_table_size - The size in bytes of the abbreviations
5505 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5508 /* augmentation_string_size - The size in bytes of the augmentation
5509 string. This value is rounded up to a multiple of 4. */
5510 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5512 map
.augmentation_is_gdb
= ((augmentation_string_size
5513 == sizeof (dwarf5_augmentation
))
5514 && memcmp (addr
, dwarf5_augmentation
,
5515 sizeof (dwarf5_augmentation
)) == 0);
5516 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5517 addr
+= augmentation_string_size
;
5520 map
.cu_table_reordered
= addr
;
5521 addr
+= map
.cu_count
* map
.offset_size
;
5523 /* List of Local TUs */
5524 map
.tu_table_reordered
= addr
;
5525 addr
+= map
.tu_count
* map
.offset_size
;
5527 /* Hash Lookup Table */
5528 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5529 addr
+= map
.bucket_count
* 4;
5530 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5531 addr
+= map
.name_count
* 4;
5534 map
.name_table_string_offs_reordered
= addr
;
5535 addr
+= map
.name_count
* map
.offset_size
;
5536 map
.name_table_entry_offs_reordered
= addr
;
5537 addr
+= map
.name_count
* map
.offset_size
;
5539 const gdb_byte
*abbrev_table_start
= addr
;
5542 unsigned int bytes_read
;
5543 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5548 const auto insertpair
5549 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5550 if (!insertpair
.second
)
5552 warning (_("Section .debug_names in %s has duplicate index %s, "
5553 "ignoring .debug_names."),
5554 filename
, pulongest (index_num
));
5557 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5558 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5563 mapped_debug_names::index_val::attr attr
;
5564 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5566 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5568 if (attr
.form
== DW_FORM_implicit_const
)
5570 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5574 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5576 indexval
.attr_vec
.push_back (std::move (attr
));
5579 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5581 warning (_("Section .debug_names in %s has abbreviation_table "
5582 "of size %zu vs. written as %u, ignoring .debug_names."),
5583 filename
, addr
- abbrev_table_start
, abbrev_table_size
);
5586 map
.entry_pool
= addr
;
5591 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5595 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5596 const mapped_debug_names
&map
,
5597 dwarf2_section_info
§ion
,
5598 bool is_dwz
, int base_offset
)
5600 sect_offset sect_off_prev
;
5601 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5603 sect_offset sect_off_next
;
5604 if (i
< map
.cu_count
)
5607 = (sect_offset
) (extract_unsigned_integer
5608 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5610 map
.dwarf5_byte_order
));
5613 sect_off_next
= (sect_offset
) section
.size
;
5616 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5617 dwarf2_per_objfile
->all_comp_units
[base_offset
+ (i
- 1)]
5618 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5619 sect_off_prev
, length
);
5621 sect_off_prev
= sect_off_next
;
5625 /* Read the CU list from the mapped index, and use it to create all
5626 the CU objects for this dwarf2_per_objfile. */
5629 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5630 const mapped_debug_names
&map
,
5631 const mapped_debug_names
&dwz_map
)
5633 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5635 dwarf2_per_objfile
->n_comp_units
= map
.cu_count
+ dwz_map
.cu_count
;
5636 dwarf2_per_objfile
->all_comp_units
5637 = XOBNEWVEC (&objfile
->objfile_obstack
, struct dwarf2_per_cu_data
*,
5638 dwarf2_per_objfile
->n_comp_units
);
5640 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5641 dwarf2_per_objfile
->info
,
5643 0 /* base_offset */);
5645 if (dwz_map
.cu_count
== 0)
5648 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5649 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5651 map
.cu_count
/* base_offset */);
5654 /* Read .debug_names. If everything went ok, initialize the "quick"
5655 elements of all the CUs and return true. Otherwise, return false. */
5658 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5660 mapped_debug_names
local_map (dwarf2_per_objfile
);
5661 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5662 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5664 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5665 &dwarf2_per_objfile
->debug_names
,
5669 /* Don't use the index if it's empty. */
5670 if (local_map
.name_count
== 0)
5673 /* If there is a .dwz file, read it so we can get its CU list as
5675 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5678 if (!read_debug_names_from_section (objfile
,
5679 bfd_get_filename (dwz
->dwz_bfd
),
5680 &dwz
->debug_names
, dwz_map
))
5682 warning (_("could not read '.debug_names' section from %s; skipping"),
5683 bfd_get_filename (dwz
->dwz_bfd
));
5688 create_cus_from_debug_names (dwarf2_per_objfile
, local_map
, dwz_map
);
5690 if (local_map
.tu_count
!= 0)
5692 /* We can only handle a single .debug_types when we have an
5694 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
5697 dwarf2_section_info
*section
= VEC_index (dwarf2_section_info_def
,
5698 dwarf2_per_objfile
->types
, 0);
5700 create_signatured_type_table_from_debug_names
5701 (dwarf2_per_objfile
, local_map
, section
, &dwarf2_per_objfile
->abbrev
);
5704 create_addrmap_from_aranges (dwarf2_per_objfile
,
5705 &dwarf2_per_objfile
->debug_aranges
);
5707 dwarf2_per_objfile
->debug_names_table
.reset
5708 (new mapped_debug_names (dwarf2_per_objfile
));
5709 *dwarf2_per_objfile
->debug_names_table
= std::move (local_map
);
5710 dwarf2_per_objfile
->using_index
= 1;
5711 dwarf2_per_objfile
->quick_file_names_table
=
5712 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
5717 /* Type used to manage iterating over all CUs looking for a symbol for
5720 class dw2_debug_names_iterator
5723 /* If WANT_SPECIFIC_BLOCK is true, only look for symbols in block
5724 BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
5725 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5726 bool want_specific_block
,
5727 block_enum block_index
, domain_enum domain
,
5729 : m_map (map
), m_want_specific_block (want_specific_block
),
5730 m_block_index (block_index
), m_domain (domain
),
5731 m_addr (find_vec_in_debug_names (map
, name
))
5734 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5735 search_domain search
, uint32_t namei
)
5738 m_addr (find_vec_in_debug_names (map
, namei
))
5741 /* Return the next matching CU or NULL if there are no more. */
5742 dwarf2_per_cu_data
*next ();
5745 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5747 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5750 /* The internalized form of .debug_names. */
5751 const mapped_debug_names
&m_map
;
5753 /* If true, only look for symbols that match BLOCK_INDEX. */
5754 const bool m_want_specific_block
= false;
5756 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
5757 Unused if !WANT_SPECIFIC_BLOCK - FIRST_LOCAL_BLOCK is an invalid
5759 const block_enum m_block_index
= FIRST_LOCAL_BLOCK
;
5761 /* The kind of symbol we're looking for. */
5762 const domain_enum m_domain
= UNDEF_DOMAIN
;
5763 const search_domain m_search
= ALL_DOMAIN
;
5765 /* The list of CUs from the index entry of the symbol, or NULL if
5767 const gdb_byte
*m_addr
;
5771 mapped_debug_names::namei_to_name (uint32_t namei
) const
5773 const ULONGEST namei_string_offs
5774 = extract_unsigned_integer ((name_table_string_offs_reordered
5775 + namei
* offset_size
),
5778 return read_indirect_string_at_offset
5779 (dwarf2_per_objfile
, dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
5782 /* Find a slot in .debug_names for the object named NAME. If NAME is
5783 found, return pointer to its pool data. If NAME cannot be found,
5787 dw2_debug_names_iterator::find_vec_in_debug_names
5788 (const mapped_debug_names
&map
, const char *name
)
5790 int (*cmp
) (const char *, const char *);
5792 if (current_language
->la_language
== language_cplus
5793 || current_language
->la_language
== language_fortran
5794 || current_language
->la_language
== language_d
)
5796 /* NAME is already canonical. Drop any qualifiers as
5797 .debug_names does not contain any. */
5799 if (strchr (name
, '(') != NULL
)
5801 gdb::unique_xmalloc_ptr
<char> without_params
5802 = cp_remove_params (name
);
5804 if (without_params
!= NULL
)
5806 name
= without_params
.get();
5811 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5813 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5815 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5816 (map
.bucket_table_reordered
5817 + (full_hash
% map
.bucket_count
)), 4,
5818 map
.dwarf5_byte_order
);
5822 if (namei
>= map
.name_count
)
5824 complaint (&symfile_complaints
,
5825 _("Wrong .debug_names with name index %u but name_count=%u "
5827 namei
, map
.name_count
,
5828 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5834 const uint32_t namei_full_hash
5835 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5836 (map
.hash_table_reordered
+ namei
), 4,
5837 map
.dwarf5_byte_order
);
5838 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5841 if (full_hash
== namei_full_hash
)
5843 const char *const namei_string
= map
.namei_to_name (namei
);
5845 #if 0 /* An expensive sanity check. */
5846 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5848 complaint (&symfile_complaints
,
5849 _("Wrong .debug_names hash for string at index %u "
5851 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5856 if (cmp (namei_string
, name
) == 0)
5858 const ULONGEST namei_entry_offs
5859 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5860 + namei
* map
.offset_size
),
5861 map
.offset_size
, map
.dwarf5_byte_order
);
5862 return map
.entry_pool
+ namei_entry_offs
;
5867 if (namei
>= map
.name_count
)
5873 dw2_debug_names_iterator::find_vec_in_debug_names
5874 (const mapped_debug_names
&map
, uint32_t namei
)
5876 if (namei
>= map
.name_count
)
5878 complaint (&symfile_complaints
,
5879 _("Wrong .debug_names with name index %u but name_count=%u "
5881 namei
, map
.name_count
,
5882 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5886 const ULONGEST namei_entry_offs
5887 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5888 + namei
* map
.offset_size
),
5889 map
.offset_size
, map
.dwarf5_byte_order
);
5890 return map
.entry_pool
+ namei_entry_offs
;
5893 /* See dw2_debug_names_iterator. */
5895 dwarf2_per_cu_data
*
5896 dw2_debug_names_iterator::next ()
5901 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5902 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5903 bfd
*const abfd
= objfile
->obfd
;
5907 unsigned int bytes_read
;
5908 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5909 m_addr
+= bytes_read
;
5913 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5914 if (indexval_it
== m_map
.abbrev_map
.cend ())
5916 complaint (&symfile_complaints
,
5917 _("Wrong .debug_names undefined abbrev code %s "
5919 pulongest (abbrev
), objfile_name (objfile
));
5922 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5923 bool have_is_static
= false;
5925 dwarf2_per_cu_data
*per_cu
= NULL
;
5926 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5931 case DW_FORM_implicit_const
:
5932 ull
= attr
.implicit_const
;
5934 case DW_FORM_flag_present
:
5938 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5939 m_addr
+= bytes_read
;
5942 complaint (&symfile_complaints
,
5943 _("Unsupported .debug_names form %s [in module %s]"),
5944 dwarf_form_name (attr
.form
),
5945 objfile_name (objfile
));
5948 switch (attr
.dw_idx
)
5950 case DW_IDX_compile_unit
:
5951 /* Don't crash on bad data. */
5952 if (ull
>= dwarf2_per_objfile
->n_comp_units
)
5954 complaint (&symfile_complaints
,
5955 _(".debug_names entry has bad CU index %s"
5958 objfile_name (dwarf2_per_objfile
->objfile
));
5961 per_cu
= dw2_get_cutu (dwarf2_per_objfile
, ull
);
5963 case DW_IDX_type_unit
:
5964 /* Don't crash on bad data. */
5965 if (ull
>= dwarf2_per_objfile
->n_type_units
)
5967 complaint (&symfile_complaints
,
5968 _(".debug_names entry has bad TU index %s"
5971 objfile_name (dwarf2_per_objfile
->objfile
));
5974 per_cu
= dw2_get_cutu (dwarf2_per_objfile
,
5975 dwarf2_per_objfile
->n_comp_units
+ ull
);
5977 case DW_IDX_GNU_internal
:
5978 if (!m_map
.augmentation_is_gdb
)
5980 have_is_static
= true;
5983 case DW_IDX_GNU_external
:
5984 if (!m_map
.augmentation_is_gdb
)
5986 have_is_static
= true;
5992 /* Skip if already read in. */
5993 if (per_cu
->v
.quick
->compunit_symtab
)
5996 /* Check static vs global. */
5999 const bool want_static
= m_block_index
!= GLOBAL_BLOCK
;
6000 if (m_want_specific_block
&& want_static
!= is_static
)
6004 /* Match dw2_symtab_iter_next, symbol_kind
6005 and debug_names::psymbol_tag. */
6009 switch (indexval
.dwarf_tag
)
6011 case DW_TAG_variable
:
6012 case DW_TAG_subprogram
:
6013 /* Some types are also in VAR_DOMAIN. */
6014 case DW_TAG_typedef
:
6015 case DW_TAG_structure_type
:
6022 switch (indexval
.dwarf_tag
)
6024 case DW_TAG_typedef
:
6025 case DW_TAG_structure_type
:
6032 switch (indexval
.dwarf_tag
)
6035 case DW_TAG_variable
:
6045 /* Match dw2_expand_symtabs_matching, symbol_kind and
6046 debug_names::psymbol_tag. */
6049 case VARIABLES_DOMAIN
:
6050 switch (indexval
.dwarf_tag
)
6052 case DW_TAG_variable
:
6058 case FUNCTIONS_DOMAIN
:
6059 switch (indexval
.dwarf_tag
)
6061 case DW_TAG_subprogram
:
6068 switch (indexval
.dwarf_tag
)
6070 case DW_TAG_typedef
:
6071 case DW_TAG_structure_type
:
6084 static struct compunit_symtab
*
6085 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, int block_index_int
,
6086 const char *name
, domain_enum domain
)
6088 const block_enum block_index
= static_cast<block_enum
> (block_index_int
);
6089 struct dwarf2_per_objfile
*dwarf2_per_objfile
6090 = get_dwarf2_per_objfile (objfile
);
6092 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
6095 /* index is NULL if OBJF_READNOW. */
6098 const auto &map
= *mapp
;
6100 dw2_debug_names_iterator
iter (map
, true /* want_specific_block */,
6101 block_index
, domain
, name
);
6103 struct compunit_symtab
*stab_best
= NULL
;
6104 struct dwarf2_per_cu_data
*per_cu
;
6105 while ((per_cu
= iter
.next ()) != NULL
)
6107 struct symbol
*sym
, *with_opaque
= NULL
;
6108 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
);
6109 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
6110 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
6112 sym
= block_find_symbol (block
, name
, domain
,
6113 block_find_non_opaque_type_preferred
,
6116 /* Some caution must be observed with overloaded functions and
6117 methods, since the index will not contain any overload
6118 information (but NAME might contain it). */
6121 && strcmp_iw (SYMBOL_SEARCH_NAME (sym
), name
) == 0)
6123 if (with_opaque
!= NULL
6124 && strcmp_iw (SYMBOL_SEARCH_NAME (with_opaque
), name
) == 0)
6127 /* Keep looking through other CUs. */
6133 /* This dumps minimal information about .debug_names. It is called
6134 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
6135 uses this to verify that .debug_names has been loaded. */
6138 dw2_debug_names_dump (struct objfile
*objfile
)
6140 struct dwarf2_per_objfile
*dwarf2_per_objfile
6141 = get_dwarf2_per_objfile (objfile
);
6143 gdb_assert (dwarf2_per_objfile
->using_index
);
6144 printf_filtered (".debug_names:");
6145 if (dwarf2_per_objfile
->debug_names_table
)
6146 printf_filtered (" exists\n");
6148 printf_filtered (" faked for \"readnow\"\n");
6149 printf_filtered ("\n");
6153 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
6154 const char *func_name
)
6156 struct dwarf2_per_objfile
*dwarf2_per_objfile
6157 = get_dwarf2_per_objfile (objfile
);
6159 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
6160 if (dwarf2_per_objfile
->debug_names_table
)
6162 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6164 /* Note: It doesn't matter what we pass for block_index here. */
6165 dw2_debug_names_iterator
iter (map
, false /* want_specific_block */,
6166 GLOBAL_BLOCK
, VAR_DOMAIN
, func_name
);
6168 struct dwarf2_per_cu_data
*per_cu
;
6169 while ((per_cu
= iter
.next ()) != NULL
)
6170 dw2_instantiate_symtab (per_cu
);
6175 dw2_debug_names_expand_symtabs_matching
6176 (struct objfile
*objfile
,
6177 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
6178 const lookup_name_info
&lookup_name
,
6179 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
6180 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
6181 enum search_domain kind
)
6183 struct dwarf2_per_objfile
*dwarf2_per_objfile
6184 = get_dwarf2_per_objfile (objfile
);
6186 /* debug_names_table is NULL if OBJF_READNOW. */
6187 if (!dwarf2_per_objfile
->debug_names_table
)
6190 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
6192 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6194 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
6196 kind
, [&] (offset_type namei
)
6198 /* The name was matched, now expand corresponding CUs that were
6200 dw2_debug_names_iterator
iter (map
, kind
, namei
);
6202 struct dwarf2_per_cu_data
*per_cu
;
6203 while ((per_cu
= iter
.next ()) != NULL
)
6204 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
6209 const struct quick_symbol_functions dwarf2_debug_names_functions
=
6212 dw2_find_last_source_symtab
,
6213 dw2_forget_cached_source_info
,
6214 dw2_map_symtabs_matching_filename
,
6215 dw2_debug_names_lookup_symbol
,
6217 dw2_debug_names_dump
,
6219 dw2_debug_names_expand_symtabs_for_function
,
6220 dw2_expand_all_symtabs
,
6221 dw2_expand_symtabs_with_fullname
,
6222 dw2_map_matching_symbols
,
6223 dw2_debug_names_expand_symtabs_matching
,
6224 dw2_find_pc_sect_compunit_symtab
,
6226 dw2_map_symbol_filenames
6229 /* See symfile.h. */
6232 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
6234 struct dwarf2_per_objfile
*dwarf2_per_objfile
6235 = get_dwarf2_per_objfile (objfile
);
6237 /* If we're about to read full symbols, don't bother with the
6238 indices. In this case we also don't care if some other debug
6239 format is making psymtabs, because they are all about to be
6241 if ((objfile
->flags
& OBJF_READNOW
))
6245 dwarf2_per_objfile
->using_index
= 1;
6246 create_all_comp_units (dwarf2_per_objfile
);
6247 create_all_type_units (dwarf2_per_objfile
);
6248 dwarf2_per_objfile
->quick_file_names_table
=
6249 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
6251 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
6252 + dwarf2_per_objfile
->n_type_units
); ++i
)
6254 dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
6256 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6257 struct dwarf2_per_cu_quick_data
);
6260 /* Return 1 so that gdb sees the "quick" functions. However,
6261 these functions will be no-ops because we will have expanded
6263 *index_kind
= dw_index_kind::GDB_INDEX
;
6267 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
6269 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6273 if (dwarf2_read_index (objfile
))
6275 *index_kind
= dw_index_kind::GDB_INDEX
;
6284 /* Build a partial symbol table. */
6287 dwarf2_build_psymtabs (struct objfile
*objfile
)
6289 struct dwarf2_per_objfile
*dwarf2_per_objfile
6290 = get_dwarf2_per_objfile (objfile
);
6292 if (objfile
->global_psymbols
.capacity () == 0
6293 && objfile
->static_psymbols
.capacity () == 0)
6294 init_psymbol_list (objfile
, 1024);
6298 /* This isn't really ideal: all the data we allocate on the
6299 objfile's obstack is still uselessly kept around. However,
6300 freeing it seems unsafe. */
6301 psymtab_discarder
psymtabs (objfile
);
6302 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
6305 CATCH (except
, RETURN_MASK_ERROR
)
6307 exception_print (gdb_stderr
, except
);
6312 /* Return the total length of the CU described by HEADER. */
6315 get_cu_length (const struct comp_unit_head
*header
)
6317 return header
->initial_length_size
+ header
->length
;
6320 /* Return TRUE if SECT_OFF is within CU_HEADER. */
6323 offset_in_cu_p (const comp_unit_head
*cu_header
, sect_offset sect_off
)
6325 sect_offset bottom
= cu_header
->sect_off
;
6326 sect_offset top
= cu_header
->sect_off
+ get_cu_length (cu_header
);
6328 return sect_off
>= bottom
&& sect_off
< top
;
6331 /* Find the base address of the compilation unit for range lists and
6332 location lists. It will normally be specified by DW_AT_low_pc.
6333 In DWARF-3 draft 4, the base address could be overridden by
6334 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6335 compilation units with discontinuous ranges. */
6338 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6340 struct attribute
*attr
;
6343 cu
->base_address
= 0;
6345 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6348 cu
->base_address
= attr_value_as_address (attr
);
6353 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6356 cu
->base_address
= attr_value_as_address (attr
);
6362 /* Read in the comp unit header information from the debug_info at info_ptr.
6363 Use rcuh_kind::COMPILE as the default type if not known by the caller.
6364 NOTE: This leaves members offset, first_die_offset to be filled in
6367 static const gdb_byte
*
6368 read_comp_unit_head (struct comp_unit_head
*cu_header
,
6369 const gdb_byte
*info_ptr
,
6370 struct dwarf2_section_info
*section
,
6371 rcuh_kind section_kind
)
6374 unsigned int bytes_read
;
6375 const char *filename
= get_section_file_name (section
);
6376 bfd
*abfd
= get_section_bfd_owner (section
);
6378 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
6379 cu_header
->initial_length_size
= bytes_read
;
6380 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
6381 info_ptr
+= bytes_read
;
6382 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
6384 if (cu_header
->version
< 5)
6385 switch (section_kind
)
6387 case rcuh_kind::COMPILE
:
6388 cu_header
->unit_type
= DW_UT_compile
;
6390 case rcuh_kind::TYPE
:
6391 cu_header
->unit_type
= DW_UT_type
;
6394 internal_error (__FILE__
, __LINE__
,
6395 _("read_comp_unit_head: invalid section_kind"));
6399 cu_header
->unit_type
= static_cast<enum dwarf_unit_type
>
6400 (read_1_byte (abfd
, info_ptr
));
6402 switch (cu_header
->unit_type
)
6405 if (section_kind
!= rcuh_kind::COMPILE
)
6406 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6407 "(is DW_UT_compile, should be DW_UT_type) [in module %s]"),
6411 section_kind
= rcuh_kind::TYPE
;
6414 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6415 "(is %d, should be %d or %d) [in module %s]"),
6416 cu_header
->unit_type
, DW_UT_compile
, DW_UT_type
, filename
);
6419 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6422 cu_header
->abbrev_sect_off
= (sect_offset
) read_offset (abfd
, info_ptr
,
6425 info_ptr
+= bytes_read
;
6426 if (cu_header
->version
< 5)
6428 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6431 signed_addr
= bfd_get_sign_extend_vma (abfd
);
6432 if (signed_addr
< 0)
6433 internal_error (__FILE__
, __LINE__
,
6434 _("read_comp_unit_head: dwarf from non elf file"));
6435 cu_header
->signed_addr_p
= signed_addr
;
6437 if (section_kind
== rcuh_kind::TYPE
)
6439 LONGEST type_offset
;
6441 cu_header
->signature
= read_8_bytes (abfd
, info_ptr
);
6444 type_offset
= read_offset (abfd
, info_ptr
, cu_header
, &bytes_read
);
6445 info_ptr
+= bytes_read
;
6446 cu_header
->type_cu_offset_in_tu
= (cu_offset
) type_offset
;
6447 if (to_underlying (cu_header
->type_cu_offset_in_tu
) != type_offset
)
6448 error (_("Dwarf Error: Too big type_offset in compilation unit "
6449 "header (is %s) [in module %s]"), plongest (type_offset
),
6456 /* Helper function that returns the proper abbrev section for
6459 static struct dwarf2_section_info
*
6460 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6462 struct dwarf2_section_info
*abbrev
;
6463 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6465 if (this_cu
->is_dwz
)
6466 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
6468 abbrev
= &dwarf2_per_objfile
->abbrev
;
6473 /* Subroutine of read_and_check_comp_unit_head and
6474 read_and_check_type_unit_head to simplify them.
6475 Perform various error checking on the header. */
6478 error_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6479 struct comp_unit_head
*header
,
6480 struct dwarf2_section_info
*section
,
6481 struct dwarf2_section_info
*abbrev_section
)
6483 const char *filename
= get_section_file_name (section
);
6485 if (header
->version
< 2 || header
->version
> 5)
6486 error (_("Dwarf Error: wrong version in compilation unit header "
6487 "(is %d, should be 2, 3, 4 or 5) [in module %s]"), header
->version
,
6490 if (to_underlying (header
->abbrev_sect_off
)
6491 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
6492 error (_("Dwarf Error: bad offset (%s) in compilation unit header "
6493 "(offset %s + 6) [in module %s]"),
6494 sect_offset_str (header
->abbrev_sect_off
),
6495 sect_offset_str (header
->sect_off
),
6498 /* Cast to ULONGEST to use 64-bit arithmetic when possible to
6499 avoid potential 32-bit overflow. */
6500 if (((ULONGEST
) header
->sect_off
+ get_cu_length (header
))
6502 error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
6503 "(offset %s + 0) [in module %s]"),
6504 header
->length
, sect_offset_str (header
->sect_off
),
6508 /* Read in a CU/TU header and perform some basic error checking.
6509 The contents of the header are stored in HEADER.
6510 The result is a pointer to the start of the first DIE. */
6512 static const gdb_byte
*
6513 read_and_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6514 struct comp_unit_head
*header
,
6515 struct dwarf2_section_info
*section
,
6516 struct dwarf2_section_info
*abbrev_section
,
6517 const gdb_byte
*info_ptr
,
6518 rcuh_kind section_kind
)
6520 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
6522 header
->sect_off
= (sect_offset
) (beg_of_comp_unit
- section
->buffer
);
6524 info_ptr
= read_comp_unit_head (header
, info_ptr
, section
, section_kind
);
6526 header
->first_die_cu_offset
= (cu_offset
) (info_ptr
- beg_of_comp_unit
);
6528 error_check_comp_unit_head (dwarf2_per_objfile
, header
, section
,
6534 /* Fetch the abbreviation table offset from a comp or type unit header. */
6537 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6538 struct dwarf2_section_info
*section
,
6539 sect_offset sect_off
)
6541 bfd
*abfd
= get_section_bfd_owner (section
);
6542 const gdb_byte
*info_ptr
;
6543 unsigned int initial_length_size
, offset_size
;
6546 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
6547 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6548 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6549 offset_size
= initial_length_size
== 4 ? 4 : 8;
6550 info_ptr
+= initial_length_size
;
6552 version
= read_2_bytes (abfd
, info_ptr
);
6556 /* Skip unit type and address size. */
6560 return (sect_offset
) read_offset_1 (abfd
, info_ptr
, offset_size
);
6563 /* Allocate a new partial symtab for file named NAME and mark this new
6564 partial symtab as being an include of PST. */
6567 dwarf2_create_include_psymtab (const char *name
, struct partial_symtab
*pst
,
6568 struct objfile
*objfile
)
6570 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
6572 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6574 /* It shares objfile->objfile_obstack. */
6575 subpst
->dirname
= pst
->dirname
;
6578 subpst
->textlow
= 0;
6579 subpst
->texthigh
= 0;
6581 subpst
->dependencies
6582 = XOBNEW (&objfile
->objfile_obstack
, struct partial_symtab
*);
6583 subpst
->dependencies
[0] = pst
;
6584 subpst
->number_of_dependencies
= 1;
6586 subpst
->globals_offset
= 0;
6587 subpst
->n_global_syms
= 0;
6588 subpst
->statics_offset
= 0;
6589 subpst
->n_static_syms
= 0;
6590 subpst
->compunit_symtab
= NULL
;
6591 subpst
->read_symtab
= pst
->read_symtab
;
6594 /* No private part is necessary for include psymtabs. This property
6595 can be used to differentiate between such include psymtabs and
6596 the regular ones. */
6597 subpst
->read_symtab_private
= NULL
;
6600 /* Read the Line Number Program data and extract the list of files
6601 included by the source file represented by PST. Build an include
6602 partial symtab for each of these included files. */
6605 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6606 struct die_info
*die
,
6607 struct partial_symtab
*pst
)
6610 struct attribute
*attr
;
6612 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6614 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6616 return; /* No linetable, so no includes. */
6618 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
6619 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
, pst
->textlow
, 1);
6623 hash_signatured_type (const void *item
)
6625 const struct signatured_type
*sig_type
6626 = (const struct signatured_type
*) item
;
6628 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6629 return sig_type
->signature
;
6633 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6635 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6636 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6638 return lhs
->signature
== rhs
->signature
;
6641 /* Allocate a hash table for signatured types. */
6644 allocate_signatured_type_table (struct objfile
*objfile
)
6646 return htab_create_alloc_ex (41,
6647 hash_signatured_type
,
6650 &objfile
->objfile_obstack
,
6651 hashtab_obstack_allocate
,
6652 dummy_obstack_deallocate
);
6655 /* A helper function to add a signatured type CU to a table. */
6658 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6660 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6661 struct signatured_type
***datap
= (struct signatured_type
***) datum
;
6669 /* A helper for create_debug_types_hash_table. Read types from SECTION
6670 and fill them into TYPES_HTAB. It will process only type units,
6671 therefore DW_UT_type. */
6674 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6675 struct dwo_file
*dwo_file
,
6676 dwarf2_section_info
*section
, htab_t
&types_htab
,
6677 rcuh_kind section_kind
)
6679 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6680 struct dwarf2_section_info
*abbrev_section
;
6682 const gdb_byte
*info_ptr
, *end_ptr
;
6684 abbrev_section
= (dwo_file
!= NULL
6685 ? &dwo_file
->sections
.abbrev
6686 : &dwarf2_per_objfile
->abbrev
);
6688 if (dwarf_read_debug
)
6689 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6690 get_section_name (section
),
6691 get_section_file_name (abbrev_section
));
6693 dwarf2_read_section (objfile
, section
);
6694 info_ptr
= section
->buffer
;
6696 if (info_ptr
== NULL
)
6699 /* We can't set abfd until now because the section may be empty or
6700 not present, in which case the bfd is unknown. */
6701 abfd
= get_section_bfd_owner (section
);
6703 /* We don't use init_cutu_and_read_dies_simple, or some such, here
6704 because we don't need to read any dies: the signature is in the
6707 end_ptr
= info_ptr
+ section
->size
;
6708 while (info_ptr
< end_ptr
)
6710 struct signatured_type
*sig_type
;
6711 struct dwo_unit
*dwo_tu
;
6713 const gdb_byte
*ptr
= info_ptr
;
6714 struct comp_unit_head header
;
6715 unsigned int length
;
6717 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6719 /* Initialize it due to a false compiler warning. */
6720 header
.signature
= -1;
6721 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6723 /* We need to read the type's signature in order to build the hash
6724 table, but we don't need anything else just yet. */
6726 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6727 abbrev_section
, ptr
, section_kind
);
6729 length
= get_cu_length (&header
);
6731 /* Skip dummy type units. */
6732 if (ptr
>= info_ptr
+ length
6733 || peek_abbrev_code (abfd
, ptr
) == 0
6734 || header
.unit_type
!= DW_UT_type
)
6740 if (types_htab
== NULL
)
6743 types_htab
= allocate_dwo_unit_table (objfile
);
6745 types_htab
= allocate_signatured_type_table (objfile
);
6751 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6753 dwo_tu
->dwo_file
= dwo_file
;
6754 dwo_tu
->signature
= header
.signature
;
6755 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6756 dwo_tu
->section
= section
;
6757 dwo_tu
->sect_off
= sect_off
;
6758 dwo_tu
->length
= length
;
6762 /* N.B.: type_offset is not usable if this type uses a DWO file.
6763 The real type_offset is in the DWO file. */
6765 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6766 struct signatured_type
);
6767 sig_type
->signature
= header
.signature
;
6768 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6769 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6770 sig_type
->per_cu
.is_debug_types
= 1;
6771 sig_type
->per_cu
.section
= section
;
6772 sig_type
->per_cu
.sect_off
= sect_off
;
6773 sig_type
->per_cu
.length
= length
;
6776 slot
= htab_find_slot (types_htab
,
6777 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6779 gdb_assert (slot
!= NULL
);
6782 sect_offset dup_sect_off
;
6786 const struct dwo_unit
*dup_tu
6787 = (const struct dwo_unit
*) *slot
;
6789 dup_sect_off
= dup_tu
->sect_off
;
6793 const struct signatured_type
*dup_tu
6794 = (const struct signatured_type
*) *slot
;
6796 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6799 complaint (&symfile_complaints
,
6800 _("debug type entry at offset %s is duplicate to"
6801 " the entry at offset %s, signature %s"),
6802 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6803 hex_string (header
.signature
));
6805 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6807 if (dwarf_read_debug
> 1)
6808 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6809 sect_offset_str (sect_off
),
6810 hex_string (header
.signature
));
6816 /* Create the hash table of all entries in the .debug_types
6817 (or .debug_types.dwo) section(s).
6818 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6819 otherwise it is NULL.
6821 The result is a pointer to the hash table or NULL if there are no types.
6823 Note: This function processes DWO files only, not DWP files. */
6826 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6827 struct dwo_file
*dwo_file
,
6828 VEC (dwarf2_section_info_def
) *types
,
6832 struct dwarf2_section_info
*section
;
6834 if (VEC_empty (dwarf2_section_info_def
, types
))
6838 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
6840 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, section
,
6841 types_htab
, rcuh_kind::TYPE
);
6844 /* Create the hash table of all entries in the .debug_types section,
6845 and initialize all_type_units.
6846 The result is zero if there is an error (e.g. missing .debug_types section),
6847 otherwise non-zero. */
6850 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6852 htab_t types_htab
= NULL
;
6853 struct signatured_type
**iter
;
6855 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6856 &dwarf2_per_objfile
->info
, types_htab
,
6857 rcuh_kind::COMPILE
);
6858 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6859 dwarf2_per_objfile
->types
, types_htab
);
6860 if (types_htab
== NULL
)
6862 dwarf2_per_objfile
->signatured_types
= NULL
;
6866 dwarf2_per_objfile
->signatured_types
= types_htab
;
6868 dwarf2_per_objfile
->n_type_units
6869 = dwarf2_per_objfile
->n_allocated_type_units
6870 = htab_elements (types_htab
);
6871 dwarf2_per_objfile
->all_type_units
=
6872 XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
6873 iter
= &dwarf2_per_objfile
->all_type_units
[0];
6874 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
6875 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
6876 == dwarf2_per_objfile
->n_type_units
);
6881 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6882 If SLOT is non-NULL, it is the entry to use in the hash table.
6883 Otherwise we find one. */
6885 static struct signatured_type
*
6886 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6889 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6890 int n_type_units
= dwarf2_per_objfile
->n_type_units
;
6891 struct signatured_type
*sig_type
;
6893 gdb_assert (n_type_units
<= dwarf2_per_objfile
->n_allocated_type_units
);
6895 if (n_type_units
> dwarf2_per_objfile
->n_allocated_type_units
)
6897 if (dwarf2_per_objfile
->n_allocated_type_units
== 0)
6898 dwarf2_per_objfile
->n_allocated_type_units
= 1;
6899 dwarf2_per_objfile
->n_allocated_type_units
*= 2;
6900 dwarf2_per_objfile
->all_type_units
6901 = XRESIZEVEC (struct signatured_type
*,
6902 dwarf2_per_objfile
->all_type_units
,
6903 dwarf2_per_objfile
->n_allocated_type_units
);
6904 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6906 dwarf2_per_objfile
->n_type_units
= n_type_units
;
6908 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6909 struct signatured_type
);
6910 dwarf2_per_objfile
->all_type_units
[n_type_units
- 1] = sig_type
;
6911 sig_type
->signature
= sig
;
6912 sig_type
->per_cu
.is_debug_types
= 1;
6913 if (dwarf2_per_objfile
->using_index
)
6915 sig_type
->per_cu
.v
.quick
=
6916 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6917 struct dwarf2_per_cu_quick_data
);
6922 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
6925 gdb_assert (*slot
== NULL
);
6927 /* The rest of sig_type must be filled in by the caller. */
6931 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6932 Fill in SIG_ENTRY with DWO_ENTRY. */
6935 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6936 struct signatured_type
*sig_entry
,
6937 struct dwo_unit
*dwo_entry
)
6939 /* Make sure we're not clobbering something we don't expect to. */
6940 gdb_assert (! sig_entry
->per_cu
.queued
);
6941 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6942 if (dwarf2_per_objfile
->using_index
)
6944 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6945 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
6948 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6949 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6950 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6951 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6952 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6954 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6955 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6956 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6957 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6958 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6959 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6960 sig_entry
->dwo_unit
= dwo_entry
;
6963 /* Subroutine of lookup_signatured_type.
6964 If we haven't read the TU yet, create the signatured_type data structure
6965 for a TU to be read in directly from a DWO file, bypassing the stub.
6966 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6967 using .gdb_index, then when reading a CU we want to stay in the DWO file
6968 containing that CU. Otherwise we could end up reading several other DWO
6969 files (due to comdat folding) to process the transitive closure of all the
6970 mentioned TUs, and that can be slow. The current DWO file will have every
6971 type signature that it needs.
6972 We only do this for .gdb_index because in the psymtab case we already have
6973 to read all the DWOs to build the type unit groups. */
6975 static struct signatured_type
*
6976 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6978 struct dwarf2_per_objfile
*dwarf2_per_objfile
6979 = cu
->per_cu
->dwarf2_per_objfile
;
6980 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6981 struct dwo_file
*dwo_file
;
6982 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6983 struct signatured_type find_sig_entry
, *sig_entry
;
6986 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6988 /* If TU skeletons have been removed then we may not have read in any
6990 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6992 dwarf2_per_objfile
->signatured_types
6993 = allocate_signatured_type_table (objfile
);
6996 /* We only ever need to read in one copy of a signatured type.
6997 Use the global signatured_types array to do our own comdat-folding
6998 of types. If this is the first time we're reading this TU, and
6999 the TU has an entry in .gdb_index, replace the recorded data from
7000 .gdb_index with this TU. */
7002 find_sig_entry
.signature
= sig
;
7003 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7004 &find_sig_entry
, INSERT
);
7005 sig_entry
= (struct signatured_type
*) *slot
;
7007 /* We can get here with the TU already read, *or* in the process of being
7008 read. Don't reassign the global entry to point to this DWO if that's
7009 the case. Also note that if the TU is already being read, it may not
7010 have come from a DWO, the program may be a mix of Fission-compiled
7011 code and non-Fission-compiled code. */
7013 /* Have we already tried to read this TU?
7014 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7015 needn't exist in the global table yet). */
7016 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
7019 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
7020 dwo_unit of the TU itself. */
7021 dwo_file
= cu
->dwo_unit
->dwo_file
;
7023 /* Ok, this is the first time we're reading this TU. */
7024 if (dwo_file
->tus
== NULL
)
7026 find_dwo_entry
.signature
= sig
;
7027 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_entry
);
7028 if (dwo_entry
== NULL
)
7031 /* If the global table doesn't have an entry for this TU, add one. */
7032 if (sig_entry
== NULL
)
7033 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7035 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7036 sig_entry
->per_cu
.tu_read
= 1;
7040 /* Subroutine of lookup_signatured_type.
7041 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
7042 then try the DWP file. If the TU stub (skeleton) has been removed then
7043 it won't be in .gdb_index. */
7045 static struct signatured_type
*
7046 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7048 struct dwarf2_per_objfile
*dwarf2_per_objfile
7049 = cu
->per_cu
->dwarf2_per_objfile
;
7050 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7051 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
7052 struct dwo_unit
*dwo_entry
;
7053 struct signatured_type find_sig_entry
, *sig_entry
;
7056 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7057 gdb_assert (dwp_file
!= NULL
);
7059 /* If TU skeletons have been removed then we may not have read in any
7061 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7063 dwarf2_per_objfile
->signatured_types
7064 = allocate_signatured_type_table (objfile
);
7067 find_sig_entry
.signature
= sig
;
7068 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7069 &find_sig_entry
, INSERT
);
7070 sig_entry
= (struct signatured_type
*) *slot
;
7072 /* Have we already tried to read this TU?
7073 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7074 needn't exist in the global table yet). */
7075 if (sig_entry
!= NULL
)
7078 if (dwp_file
->tus
== NULL
)
7080 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
7081 sig
, 1 /* is_debug_types */);
7082 if (dwo_entry
== NULL
)
7085 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7086 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7091 /* Lookup a signature based type for DW_FORM_ref_sig8.
7092 Returns NULL if signature SIG is not present in the table.
7093 It is up to the caller to complain about this. */
7095 static struct signatured_type
*
7096 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7098 struct dwarf2_per_objfile
*dwarf2_per_objfile
7099 = cu
->per_cu
->dwarf2_per_objfile
;
7102 && dwarf2_per_objfile
->using_index
)
7104 /* We're in a DWO/DWP file, and we're using .gdb_index.
7105 These cases require special processing. */
7106 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
7107 return lookup_dwo_signatured_type (cu
, sig
);
7109 return lookup_dwp_signatured_type (cu
, sig
);
7113 struct signatured_type find_entry
, *entry
;
7115 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7117 find_entry
.signature
= sig
;
7118 entry
= ((struct signatured_type
*)
7119 htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
));
7124 /* Low level DIE reading support. */
7126 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
7129 init_cu_die_reader (struct die_reader_specs
*reader
,
7130 struct dwarf2_cu
*cu
,
7131 struct dwarf2_section_info
*section
,
7132 struct dwo_file
*dwo_file
,
7133 struct abbrev_table
*abbrev_table
)
7135 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
7136 reader
->abfd
= get_section_bfd_owner (section
);
7138 reader
->dwo_file
= dwo_file
;
7139 reader
->die_section
= section
;
7140 reader
->buffer
= section
->buffer
;
7141 reader
->buffer_end
= section
->buffer
+ section
->size
;
7142 reader
->comp_dir
= NULL
;
7143 reader
->abbrev_table
= abbrev_table
;
7146 /* Subroutine of init_cutu_and_read_dies to simplify it.
7147 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
7148 There's just a lot of work to do, and init_cutu_and_read_dies is big enough
7151 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
7152 from it to the DIE in the DWO. If NULL we are skipping the stub.
7153 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
7154 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
7155 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
7156 STUB_COMP_DIR may be non-NULL.
7157 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
7158 are filled in with the info of the DIE from the DWO file.
7159 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
7160 from the dwo. Since *RESULT_READER references this abbrev table, it must be
7161 kept around for at least as long as *RESULT_READER.
7163 The result is non-zero if a valid (non-dummy) DIE was found. */
7166 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
7167 struct dwo_unit
*dwo_unit
,
7168 struct die_info
*stub_comp_unit_die
,
7169 const char *stub_comp_dir
,
7170 struct die_reader_specs
*result_reader
,
7171 const gdb_byte
**result_info_ptr
,
7172 struct die_info
**result_comp_unit_die
,
7173 int *result_has_children
,
7174 abbrev_table_up
*result_dwo_abbrev_table
)
7176 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7177 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7178 struct dwarf2_cu
*cu
= this_cu
->cu
;
7180 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7181 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
7182 int i
,num_extra_attrs
;
7183 struct dwarf2_section_info
*dwo_abbrev_section
;
7184 struct attribute
*attr
;
7185 struct die_info
*comp_unit_die
;
7187 /* At most one of these may be provided. */
7188 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
7190 /* These attributes aren't processed until later:
7191 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
7192 DW_AT_comp_dir is used now, to find the DWO file, but it is also
7193 referenced later. However, these attributes are found in the stub
7194 which we won't have later. In order to not impose this complication
7195 on the rest of the code, we read them here and copy them to the
7204 if (stub_comp_unit_die
!= NULL
)
7206 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
7208 if (! this_cu
->is_debug_types
)
7209 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
7210 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
7211 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
7212 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
7213 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
7215 /* There should be a DW_AT_addr_base attribute here (if needed).
7216 We need the value before we can process DW_FORM_GNU_addr_index. */
7218 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
7220 cu
->addr_base
= DW_UNSND (attr
);
7222 /* There should be a DW_AT_ranges_base attribute here (if needed).
7223 We need the value before we can process DW_AT_ranges. */
7224 cu
->ranges_base
= 0;
7225 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
7227 cu
->ranges_base
= DW_UNSND (attr
);
7229 else if (stub_comp_dir
!= NULL
)
7231 /* Reconstruct the comp_dir attribute to simplify the code below. */
7232 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
7233 comp_dir
->name
= DW_AT_comp_dir
;
7234 comp_dir
->form
= DW_FORM_string
;
7235 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
7236 DW_STRING (comp_dir
) = stub_comp_dir
;
7239 /* Set up for reading the DWO CU/TU. */
7240 cu
->dwo_unit
= dwo_unit
;
7241 dwarf2_section_info
*section
= dwo_unit
->section
;
7242 dwarf2_read_section (objfile
, section
);
7243 abfd
= get_section_bfd_owner (section
);
7244 begin_info_ptr
= info_ptr
= (section
->buffer
7245 + to_underlying (dwo_unit
->sect_off
));
7246 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
7248 if (this_cu
->is_debug_types
)
7250 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
7252 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7253 &cu
->header
, section
,
7255 info_ptr
, rcuh_kind::TYPE
);
7256 /* This is not an assert because it can be caused by bad debug info. */
7257 if (sig_type
->signature
!= cu
->header
.signature
)
7259 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
7260 " TU at offset %s [in module %s]"),
7261 hex_string (sig_type
->signature
),
7262 hex_string (cu
->header
.signature
),
7263 sect_offset_str (dwo_unit
->sect_off
),
7264 bfd_get_filename (abfd
));
7266 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7267 /* For DWOs coming from DWP files, we don't know the CU length
7268 nor the type's offset in the TU until now. */
7269 dwo_unit
->length
= get_cu_length (&cu
->header
);
7270 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
7272 /* Establish the type offset that can be used to lookup the type.
7273 For DWO files, we don't know it until now. */
7274 sig_type
->type_offset_in_section
7275 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
7279 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7280 &cu
->header
, section
,
7282 info_ptr
, rcuh_kind::COMPILE
);
7283 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7284 /* For DWOs coming from DWP files, we don't know the CU length
7286 dwo_unit
->length
= get_cu_length (&cu
->header
);
7289 *result_dwo_abbrev_table
7290 = abbrev_table_read_table (dwarf2_per_objfile
, dwo_abbrev_section
,
7291 cu
->header
.abbrev_sect_off
);
7292 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
7293 result_dwo_abbrev_table
->get ());
7295 /* Read in the die, but leave space to copy over the attributes
7296 from the stub. This has the benefit of simplifying the rest of
7297 the code - all the work to maintain the illusion of a single
7298 DW_TAG_{compile,type}_unit DIE is done here. */
7299 num_extra_attrs
= ((stmt_list
!= NULL
)
7303 + (comp_dir
!= NULL
));
7304 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
7305 result_has_children
, num_extra_attrs
);
7307 /* Copy over the attributes from the stub to the DIE we just read in. */
7308 comp_unit_die
= *result_comp_unit_die
;
7309 i
= comp_unit_die
->num_attrs
;
7310 if (stmt_list
!= NULL
)
7311 comp_unit_die
->attrs
[i
++] = *stmt_list
;
7313 comp_unit_die
->attrs
[i
++] = *low_pc
;
7314 if (high_pc
!= NULL
)
7315 comp_unit_die
->attrs
[i
++] = *high_pc
;
7317 comp_unit_die
->attrs
[i
++] = *ranges
;
7318 if (comp_dir
!= NULL
)
7319 comp_unit_die
->attrs
[i
++] = *comp_dir
;
7320 comp_unit_die
->num_attrs
+= num_extra_attrs
;
7322 if (dwarf_die_debug
)
7324 fprintf_unfiltered (gdb_stdlog
,
7325 "Read die from %s@0x%x of %s:\n",
7326 get_section_name (section
),
7327 (unsigned) (begin_info_ptr
- section
->buffer
),
7328 bfd_get_filename (abfd
));
7329 dump_die (comp_unit_die
, dwarf_die_debug
);
7332 /* Save the comp_dir attribute. If there is no DWP file then we'll read
7333 TUs by skipping the stub and going directly to the entry in the DWO file.
7334 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
7335 to get it via circuitous means. Blech. */
7336 if (comp_dir
!= NULL
)
7337 result_reader
->comp_dir
= DW_STRING (comp_dir
);
7339 /* Skip dummy compilation units. */
7340 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
7341 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7344 *result_info_ptr
= info_ptr
;
7348 /* Subroutine of init_cutu_and_read_dies to simplify it.
7349 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
7350 Returns NULL if the specified DWO unit cannot be found. */
7352 static struct dwo_unit
*
7353 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
7354 struct die_info
*comp_unit_die
)
7356 struct dwarf2_cu
*cu
= this_cu
->cu
;
7358 struct dwo_unit
*dwo_unit
;
7359 const char *comp_dir
, *dwo_name
;
7361 gdb_assert (cu
!= NULL
);
7363 /* Yeah, we look dwo_name up again, but it simplifies the code. */
7364 dwo_name
= dwarf2_string_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
7365 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7367 if (this_cu
->is_debug_types
)
7369 struct signatured_type
*sig_type
;
7371 /* Since this_cu is the first member of struct signatured_type,
7372 we can go from a pointer to one to a pointer to the other. */
7373 sig_type
= (struct signatured_type
*) this_cu
;
7374 signature
= sig_type
->signature
;
7375 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
7379 struct attribute
*attr
;
7381 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7383 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
7385 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
7386 signature
= DW_UNSND (attr
);
7387 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
7394 /* Subroutine of init_cutu_and_read_dies to simplify it.
7395 See it for a description of the parameters.
7396 Read a TU directly from a DWO file, bypassing the stub. */
7399 init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
7400 int use_existing_cu
, int keep
,
7401 die_reader_func_ftype
*die_reader_func
,
7404 std::unique_ptr
<dwarf2_cu
> new_cu
;
7405 struct signatured_type
*sig_type
;
7406 struct die_reader_specs reader
;
7407 const gdb_byte
*info_ptr
;
7408 struct die_info
*comp_unit_die
;
7410 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7412 /* Verify we can do the following downcast, and that we have the
7414 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7415 sig_type
= (struct signatured_type
*) this_cu
;
7416 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7418 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7420 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
7421 /* There's no need to do the rereading_dwo_cu handling that
7422 init_cutu_and_read_dies does since we don't read the stub. */
7426 /* If !use_existing_cu, this_cu->cu must be NULL. */
7427 gdb_assert (this_cu
->cu
== NULL
);
7428 new_cu
.reset (new dwarf2_cu (this_cu
));
7431 /* A future optimization, if needed, would be to use an existing
7432 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7433 could share abbrev tables. */
7435 /* The abbreviation table used by READER, this must live at least as long as
7437 abbrev_table_up dwo_abbrev_table
;
7439 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
7440 NULL
/* stub_comp_unit_die */,
7441 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7443 &comp_unit_die
, &has_children
,
7444 &dwo_abbrev_table
) == 0)
7450 /* All the "real" work is done here. */
7451 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7453 /* This duplicates the code in init_cutu_and_read_dies,
7454 but the alternative is making the latter more complex.
7455 This function is only for the special case of using DWO files directly:
7456 no point in overly complicating the general case just to handle this. */
7457 if (new_cu
!= NULL
&& keep
)
7459 /* Link this CU into read_in_chain. */
7460 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7461 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7462 /* The chain owns it now. */
7467 /* Initialize a CU (or TU) and read its DIEs.
7468 If the CU defers to a DWO file, read the DWO file as well.
7470 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7471 Otherwise the table specified in the comp unit header is read in and used.
7472 This is an optimization for when we already have the abbrev table.
7474 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
7475 Otherwise, a new CU is allocated with xmalloc.
7477 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
7478 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
7480 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7481 linker) then DIE_READER_FUNC will not get called. */
7484 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
7485 struct abbrev_table
*abbrev_table
,
7486 int use_existing_cu
, int keep
,
7487 die_reader_func_ftype
*die_reader_func
,
7490 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7491 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7492 struct dwarf2_section_info
*section
= this_cu
->section
;
7493 bfd
*abfd
= get_section_bfd_owner (section
);
7494 struct dwarf2_cu
*cu
;
7495 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7496 struct die_reader_specs reader
;
7497 struct die_info
*comp_unit_die
;
7499 struct attribute
*attr
;
7500 struct signatured_type
*sig_type
= NULL
;
7501 struct dwarf2_section_info
*abbrev_section
;
7502 /* Non-zero if CU currently points to a DWO file and we need to
7503 reread it. When this happens we need to reread the skeleton die
7504 before we can reread the DWO file (this only applies to CUs, not TUs). */
7505 int rereading_dwo_cu
= 0;
7507 if (dwarf_die_debug
)
7508 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7509 this_cu
->is_debug_types
? "type" : "comp",
7510 sect_offset_str (this_cu
->sect_off
));
7512 if (use_existing_cu
)
7515 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7516 file (instead of going through the stub), short-circuit all of this. */
7517 if (this_cu
->reading_dwo_directly
)
7519 /* Narrow down the scope of possibilities to have to understand. */
7520 gdb_assert (this_cu
->is_debug_types
);
7521 gdb_assert (abbrev_table
== NULL
);
7522 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
,
7523 die_reader_func
, data
);
7527 /* This is cheap if the section is already read in. */
7528 dwarf2_read_section (objfile
, section
);
7530 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7532 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7534 std::unique_ptr
<dwarf2_cu
> new_cu
;
7535 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7538 /* If this CU is from a DWO file we need to start over, we need to
7539 refetch the attributes from the skeleton CU.
7540 This could be optimized by retrieving those attributes from when we
7541 were here the first time: the previous comp_unit_die was stored in
7542 comp_unit_obstack. But there's no data yet that we need this
7544 if (cu
->dwo_unit
!= NULL
)
7545 rereading_dwo_cu
= 1;
7549 /* If !use_existing_cu, this_cu->cu must be NULL. */
7550 gdb_assert (this_cu
->cu
== NULL
);
7551 new_cu
.reset (new dwarf2_cu (this_cu
));
7555 /* Get the header. */
7556 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7558 /* We already have the header, there's no need to read it in again. */
7559 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7563 if (this_cu
->is_debug_types
)
7565 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7566 &cu
->header
, section
,
7567 abbrev_section
, info_ptr
,
7570 /* Since per_cu is the first member of struct signatured_type,
7571 we can go from a pointer to one to a pointer to the other. */
7572 sig_type
= (struct signatured_type
*) this_cu
;
7573 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7574 gdb_assert (sig_type
->type_offset_in_tu
7575 == cu
->header
.type_cu_offset_in_tu
);
7576 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7578 /* LENGTH has not been set yet for type units if we're
7579 using .gdb_index. */
7580 this_cu
->length
= get_cu_length (&cu
->header
);
7582 /* Establish the type offset that can be used to lookup the type. */
7583 sig_type
->type_offset_in_section
=
7584 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7586 this_cu
->dwarf_version
= cu
->header
.version
;
7590 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7591 &cu
->header
, section
,
7594 rcuh_kind::COMPILE
);
7596 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7597 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
7598 this_cu
->dwarf_version
= cu
->header
.version
;
7602 /* Skip dummy compilation units. */
7603 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7604 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7607 /* If we don't have them yet, read the abbrevs for this compilation unit.
7608 And if we need to read them now, make sure they're freed when we're
7609 done (own the table through ABBREV_TABLE_HOLDER). */
7610 abbrev_table_up abbrev_table_holder
;
7611 if (abbrev_table
!= NULL
)
7612 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7616 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7617 cu
->header
.abbrev_sect_off
);
7618 abbrev_table
= abbrev_table_holder
.get ();
7621 /* Read the top level CU/TU die. */
7622 init_cu_die_reader (&reader
, cu
, section
, NULL
, abbrev_table
);
7623 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
7625 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7626 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7627 table from the DWO file and pass the ownership over to us. It will be
7628 referenced from READER, so we must make sure to free it after we're done
7631 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7632 DWO CU, that this test will fail (the attribute will not be present). */
7633 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
7634 abbrev_table_up dwo_abbrev_table
;
7637 struct dwo_unit
*dwo_unit
;
7638 struct die_info
*dwo_comp_unit_die
;
7642 complaint (&symfile_complaints
,
7643 _("compilation unit with DW_AT_GNU_dwo_name"
7644 " has children (offset %s) [in module %s]"),
7645 sect_offset_str (this_cu
->sect_off
),
7646 bfd_get_filename (abfd
));
7648 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
);
7649 if (dwo_unit
!= NULL
)
7651 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
7652 comp_unit_die
, NULL
,
7654 &dwo_comp_unit_die
, &has_children
,
7655 &dwo_abbrev_table
) == 0)
7660 comp_unit_die
= dwo_comp_unit_die
;
7664 /* Yikes, we couldn't find the rest of the DIE, we only have
7665 the stub. A complaint has already been logged. There's
7666 not much more we can do except pass on the stub DIE to
7667 die_reader_func. We don't want to throw an error on bad
7672 /* All of the above is setup for this call. Yikes. */
7673 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7675 /* Done, clean up. */
7676 if (new_cu
!= NULL
&& keep
)
7678 /* Link this CU into read_in_chain. */
7679 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7680 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7681 /* The chain owns it now. */
7686 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name if present.
7687 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed
7688 to have already done the lookup to find the DWO file).
7690 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7691 THIS_CU->is_debug_types, but nothing else.
7693 We fill in THIS_CU->length.
7695 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7696 linker) then DIE_READER_FUNC will not get called.
7698 THIS_CU->cu is always freed when done.
7699 This is done in order to not leave THIS_CU->cu in a state where we have
7700 to care whether it refers to the "main" CU or the DWO CU. */
7703 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
7704 struct dwo_file
*dwo_file
,
7705 die_reader_func_ftype
*die_reader_func
,
7708 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7709 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7710 struct dwarf2_section_info
*section
= this_cu
->section
;
7711 bfd
*abfd
= get_section_bfd_owner (section
);
7712 struct dwarf2_section_info
*abbrev_section
;
7713 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7714 struct die_reader_specs reader
;
7715 struct die_info
*comp_unit_die
;
7718 if (dwarf_die_debug
)
7719 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7720 this_cu
->is_debug_types
? "type" : "comp",
7721 sect_offset_str (this_cu
->sect_off
));
7723 gdb_assert (this_cu
->cu
== NULL
);
7725 abbrev_section
= (dwo_file
!= NULL
7726 ? &dwo_file
->sections
.abbrev
7727 : get_abbrev_section_for_cu (this_cu
));
7729 /* This is cheap if the section is already read in. */
7730 dwarf2_read_section (objfile
, section
);
7732 struct dwarf2_cu
cu (this_cu
);
7734 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7735 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7736 &cu
.header
, section
,
7737 abbrev_section
, info_ptr
,
7738 (this_cu
->is_debug_types
7740 : rcuh_kind::COMPILE
));
7742 this_cu
->length
= get_cu_length (&cu
.header
);
7744 /* Skip dummy compilation units. */
7745 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7746 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7749 abbrev_table_up abbrev_table
7750 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7751 cu
.header
.abbrev_sect_off
);
7753 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
, abbrev_table
.get ());
7754 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
7756 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7759 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
7760 does not lookup the specified DWO file.
7761 This cannot be used to read DWO files.
7763 THIS_CU->cu is always freed when done.
7764 This is done in order to not leave THIS_CU->cu in a state where we have
7765 to care whether it refers to the "main" CU or the DWO CU.
7766 We can revisit this if the data shows there's a performance issue. */
7769 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
7770 die_reader_func_ftype
*die_reader_func
,
7773 init_cutu_and_read_dies_no_follow (this_cu
, NULL
, die_reader_func
, data
);
7776 /* Type Unit Groups.
7778 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7779 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7780 so that all types coming from the same compilation (.o file) are grouped
7781 together. A future step could be to put the types in the same symtab as
7782 the CU the types ultimately came from. */
7785 hash_type_unit_group (const void *item
)
7787 const struct type_unit_group
*tu_group
7788 = (const struct type_unit_group
*) item
;
7790 return hash_stmt_list_entry (&tu_group
->hash
);
7794 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7796 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7797 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7799 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7802 /* Allocate a hash table for type unit groups. */
7805 allocate_type_unit_groups_table (struct objfile
*objfile
)
7807 return htab_create_alloc_ex (3,
7808 hash_type_unit_group
,
7811 &objfile
->objfile_obstack
,
7812 hashtab_obstack_allocate
,
7813 dummy_obstack_deallocate
);
7816 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7817 partial symtabs. We combine several TUs per psymtab to not let the size
7818 of any one psymtab grow too big. */
7819 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7820 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7822 /* Helper routine for get_type_unit_group.
7823 Create the type_unit_group object used to hold one or more TUs. */
7825 static struct type_unit_group
*
7826 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7828 struct dwarf2_per_objfile
*dwarf2_per_objfile
7829 = cu
->per_cu
->dwarf2_per_objfile
;
7830 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7831 struct dwarf2_per_cu_data
*per_cu
;
7832 struct type_unit_group
*tu_group
;
7834 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7835 struct type_unit_group
);
7836 per_cu
= &tu_group
->per_cu
;
7837 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7839 if (dwarf2_per_objfile
->using_index
)
7841 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7842 struct dwarf2_per_cu_quick_data
);
7846 unsigned int line_offset
= to_underlying (line_offset_struct
);
7847 struct partial_symtab
*pst
;
7850 /* Give the symtab a useful name for debug purposes. */
7851 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7852 name
= xstrprintf ("<type_units_%d>",
7853 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7855 name
= xstrprintf ("<type_units_at_0x%x>", line_offset
);
7857 pst
= create_partial_symtab (per_cu
, name
);
7863 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7864 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7869 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7870 STMT_LIST is a DW_AT_stmt_list attribute. */
7872 static struct type_unit_group
*
7873 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7875 struct dwarf2_per_objfile
*dwarf2_per_objfile
7876 = cu
->per_cu
->dwarf2_per_objfile
;
7877 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7878 struct type_unit_group
*tu_group
;
7880 unsigned int line_offset
;
7881 struct type_unit_group type_unit_group_for_lookup
;
7883 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7885 dwarf2_per_objfile
->type_unit_groups
=
7886 allocate_type_unit_groups_table (dwarf2_per_objfile
->objfile
);
7889 /* Do we need to create a new group, or can we use an existing one? */
7893 line_offset
= DW_UNSND (stmt_list
);
7894 ++tu_stats
->nr_symtab_sharers
;
7898 /* Ugh, no stmt_list. Rare, but we have to handle it.
7899 We can do various things here like create one group per TU or
7900 spread them over multiple groups to split up the expansion work.
7901 To avoid worst case scenarios (too many groups or too large groups)
7902 we, umm, group them in bunches. */
7903 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7904 | (tu_stats
->nr_stmt_less_type_units
7905 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7906 ++tu_stats
->nr_stmt_less_type_units
;
7909 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7910 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7911 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
7912 &type_unit_group_for_lookup
, INSERT
);
7915 tu_group
= (struct type_unit_group
*) *slot
;
7916 gdb_assert (tu_group
!= NULL
);
7920 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7921 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7923 ++tu_stats
->nr_symtabs
;
7929 /* Partial symbol tables. */
7931 /* Create a psymtab named NAME and assign it to PER_CU.
7933 The caller must fill in the following details:
7934 dirname, textlow, texthigh. */
7936 static struct partial_symtab
*
7937 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
7939 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
7940 struct partial_symtab
*pst
;
7942 pst
= start_psymtab_common (objfile
, name
, 0,
7943 objfile
->global_psymbols
,
7944 objfile
->static_psymbols
);
7946 pst
->psymtabs_addrmap_supported
= 1;
7948 /* This is the glue that links PST into GDB's symbol API. */
7949 pst
->read_symtab_private
= per_cu
;
7950 pst
->read_symtab
= dwarf2_read_symtab
;
7951 per_cu
->v
.psymtab
= pst
;
7956 /* The DATA object passed to process_psymtab_comp_unit_reader has this
7959 struct process_psymtab_comp_unit_data
7961 /* True if we are reading a DW_TAG_partial_unit. */
7963 int want_partial_unit
;
7965 /* The "pretend" language that is used if the CU doesn't declare a
7968 enum language pretend_language
;
7971 /* die_reader_func for process_psymtab_comp_unit. */
7974 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7975 const gdb_byte
*info_ptr
,
7976 struct die_info
*comp_unit_die
,
7980 struct dwarf2_cu
*cu
= reader
->cu
;
7981 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
7982 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7983 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7985 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7986 struct partial_symtab
*pst
;
7987 enum pc_bounds_kind cu_bounds_kind
;
7988 const char *filename
;
7989 struct process_psymtab_comp_unit_data
*info
7990 = (struct process_psymtab_comp_unit_data
*) data
;
7992 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !info
->want_partial_unit
)
7995 gdb_assert (! per_cu
->is_debug_types
);
7997 prepare_one_comp_unit (cu
, comp_unit_die
, info
->pretend_language
);
7999 cu
->list_in_scope
= &file_symbols
;
8001 /* Allocate a new partial symbol table structure. */
8002 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
8003 if (filename
== NULL
)
8006 pst
= create_partial_symtab (per_cu
, filename
);
8008 /* This must be done before calling dwarf2_build_include_psymtabs. */
8009 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
8011 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8013 dwarf2_find_base_address (comp_unit_die
, cu
);
8015 /* Possibly set the default values of LOWPC and HIGHPC from
8017 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
8018 &best_highpc
, cu
, pst
);
8019 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
8020 /* Store the contiguous range if it is not empty; it can be empty for
8021 CUs with no code. */
8022 addrmap_set_empty (objfile
->psymtabs_addrmap
,
8023 gdbarch_adjust_dwarf2_addr (gdbarch
,
8024 best_lowpc
+ baseaddr
),
8025 gdbarch_adjust_dwarf2_addr (gdbarch
,
8026 best_highpc
+ baseaddr
) - 1,
8029 /* Check if comp unit has_children.
8030 If so, read the rest of the partial symbols from this comp unit.
8031 If not, there's no more debug_info for this comp unit. */
8034 struct partial_die_info
*first_die
;
8035 CORE_ADDR lowpc
, highpc
;
8037 lowpc
= ((CORE_ADDR
) -1);
8038 highpc
= ((CORE_ADDR
) 0);
8040 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8042 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
8043 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
8045 /* If we didn't find a lowpc, set it to highpc to avoid
8046 complaints from `maint check'. */
8047 if (lowpc
== ((CORE_ADDR
) -1))
8050 /* If the compilation unit didn't have an explicit address range,
8051 then use the information extracted from its child dies. */
8052 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
8055 best_highpc
= highpc
;
8058 pst
->textlow
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
);
8059 pst
->texthigh
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
);
8061 end_psymtab_common (objfile
, pst
);
8063 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
))
8066 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
8067 struct dwarf2_per_cu_data
*iter
;
8069 /* Fill in 'dependencies' here; we fill in 'users' in a
8071 pst
->number_of_dependencies
= len
;
8073 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
8075 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
8078 pst
->dependencies
[i
] = iter
->v
.psymtab
;
8080 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
8083 /* Get the list of files included in the current compilation unit,
8084 and build a psymtab for each of them. */
8085 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
8087 if (dwarf_read_debug
)
8089 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8091 fprintf_unfiltered (gdb_stdlog
,
8092 "Psymtab for %s unit @%s: %s - %s"
8093 ", %d global, %d static syms\n",
8094 per_cu
->is_debug_types
? "type" : "comp",
8095 sect_offset_str (per_cu
->sect_off
),
8096 paddress (gdbarch
, pst
->textlow
),
8097 paddress (gdbarch
, pst
->texthigh
),
8098 pst
->n_global_syms
, pst
->n_static_syms
);
8102 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8103 Process compilation unit THIS_CU for a psymtab. */
8106 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8107 int want_partial_unit
,
8108 enum language pretend_language
)
8110 /* If this compilation unit was already read in, free the
8111 cached copy in order to read it in again. This is
8112 necessary because we skipped some symbols when we first
8113 read in the compilation unit (see load_partial_dies).
8114 This problem could be avoided, but the benefit is unclear. */
8115 if (this_cu
->cu
!= NULL
)
8116 free_one_cached_comp_unit (this_cu
);
8118 if (this_cu
->is_debug_types
)
8119 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0, build_type_psymtabs_reader
,
8123 process_psymtab_comp_unit_data info
;
8124 info
.want_partial_unit
= want_partial_unit
;
8125 info
.pretend_language
= pretend_language
;
8126 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0,
8127 process_psymtab_comp_unit_reader
, &info
);
8130 /* Age out any secondary CUs. */
8131 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
8134 /* Reader function for build_type_psymtabs. */
8137 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
8138 const gdb_byte
*info_ptr
,
8139 struct die_info
*type_unit_die
,
8143 struct dwarf2_per_objfile
*dwarf2_per_objfile
8144 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
8145 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8146 struct dwarf2_cu
*cu
= reader
->cu
;
8147 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8148 struct signatured_type
*sig_type
;
8149 struct type_unit_group
*tu_group
;
8150 struct attribute
*attr
;
8151 struct partial_die_info
*first_die
;
8152 CORE_ADDR lowpc
, highpc
;
8153 struct partial_symtab
*pst
;
8155 gdb_assert (data
== NULL
);
8156 gdb_assert (per_cu
->is_debug_types
);
8157 sig_type
= (struct signatured_type
*) per_cu
;
8162 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
8163 tu_group
= get_type_unit_group (cu
, attr
);
8165 VEC_safe_push (sig_type_ptr
, tu_group
->tus
, sig_type
);
8167 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
8168 cu
->list_in_scope
= &file_symbols
;
8169 pst
= create_partial_symtab (per_cu
, "");
8172 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8174 lowpc
= (CORE_ADDR
) -1;
8175 highpc
= (CORE_ADDR
) 0;
8176 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
8178 end_psymtab_common (objfile
, pst
);
8181 /* Struct used to sort TUs by their abbreviation table offset. */
8183 struct tu_abbrev_offset
8185 struct signatured_type
*sig_type
;
8186 sect_offset abbrev_offset
;
8189 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
8192 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
8193 const struct tu_abbrev_offset
&b
)
8195 return a
.abbrev_offset
< b
.abbrev_offset
;
8198 /* Efficiently read all the type units.
8199 This does the bulk of the work for build_type_psymtabs.
8201 The efficiency is because we sort TUs by the abbrev table they use and
8202 only read each abbrev table once. In one program there are 200K TUs
8203 sharing 8K abbrev tables.
8205 The main purpose of this function is to support building the
8206 dwarf2_per_objfile->type_unit_groups table.
8207 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
8208 can collapse the search space by grouping them by stmt_list.
8209 The savings can be significant, in the same program from above the 200K TUs
8210 share 8K stmt_list tables.
8212 FUNC is expected to call get_type_unit_group, which will create the
8213 struct type_unit_group if necessary and add it to
8214 dwarf2_per_objfile->type_unit_groups. */
8217 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8219 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8220 abbrev_table_up abbrev_table
;
8221 sect_offset abbrev_offset
;
8224 /* It's up to the caller to not call us multiple times. */
8225 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
8227 if (dwarf2_per_objfile
->n_type_units
== 0)
8230 /* TUs typically share abbrev tables, and there can be way more TUs than
8231 abbrev tables. Sort by abbrev table to reduce the number of times we
8232 read each abbrev table in.
8233 Alternatives are to punt or to maintain a cache of abbrev tables.
8234 This is simpler and efficient enough for now.
8236 Later we group TUs by their DW_AT_stmt_list value (as this defines the
8237 symtab to use). Typically TUs with the same abbrev offset have the same
8238 stmt_list value too so in practice this should work well.
8240 The basic algorithm here is:
8242 sort TUs by abbrev table
8243 for each TU with same abbrev table:
8244 read abbrev table if first user
8245 read TU top level DIE
8246 [IWBN if DWO skeletons had DW_AT_stmt_list]
8249 if (dwarf_read_debug
)
8250 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
8252 /* Sort in a separate table to maintain the order of all_type_units
8253 for .gdb_index: TU indices directly index all_type_units. */
8254 std::vector
<struct tu_abbrev_offset
> sorted_by_abbrev
8255 (dwarf2_per_objfile
->n_type_units
);
8256 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
8258 struct signatured_type
*sig_type
= dwarf2_per_objfile
->all_type_units
[i
];
8260 sorted_by_abbrev
[i
].sig_type
= sig_type
;
8261 sorted_by_abbrev
[i
].abbrev_offset
=
8262 read_abbrev_offset (dwarf2_per_objfile
,
8263 sig_type
->per_cu
.section
,
8264 sig_type
->per_cu
.sect_off
);
8266 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
8267 sort_tu_by_abbrev_offset
);
8269 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
8271 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
8273 const struct tu_abbrev_offset
*tu
= &sorted_by_abbrev
[i
];
8275 /* Switch to the next abbrev table if necessary. */
8276 if (abbrev_table
== NULL
8277 || tu
->abbrev_offset
!= abbrev_offset
)
8279 abbrev_offset
= tu
->abbrev_offset
;
8281 abbrev_table_read_table (dwarf2_per_objfile
,
8282 &dwarf2_per_objfile
->abbrev
,
8284 ++tu_stats
->nr_uniq_abbrev_tables
;
8287 init_cutu_and_read_dies (&tu
->sig_type
->per_cu
, abbrev_table
.get (),
8288 0, 0, build_type_psymtabs_reader
, NULL
);
8292 /* Print collected type unit statistics. */
8295 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8297 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8299 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
8300 fprintf_unfiltered (gdb_stdlog
, " %d TUs\n",
8301 dwarf2_per_objfile
->n_type_units
);
8302 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
8303 tu_stats
->nr_uniq_abbrev_tables
);
8304 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
8305 tu_stats
->nr_symtabs
);
8306 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
8307 tu_stats
->nr_symtab_sharers
);
8308 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
8309 tu_stats
->nr_stmt_less_type_units
);
8310 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
8311 tu_stats
->nr_all_type_units_reallocs
);
8314 /* Traversal function for build_type_psymtabs. */
8317 build_type_psymtab_dependencies (void **slot
, void *info
)
8319 struct dwarf2_per_objfile
*dwarf2_per_objfile
8320 = (struct dwarf2_per_objfile
*) info
;
8321 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8322 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
8323 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
8324 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8325 int len
= VEC_length (sig_type_ptr
, tu_group
->tus
);
8326 struct signatured_type
*iter
;
8329 gdb_assert (len
> 0);
8330 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
8332 pst
->number_of_dependencies
= len
;
8334 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
8336 VEC_iterate (sig_type_ptr
, tu_group
->tus
, i
, iter
);
8339 gdb_assert (iter
->per_cu
.is_debug_types
);
8340 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
8341 iter
->type_unit_group
= tu_group
;
8344 VEC_free (sig_type_ptr
, tu_group
->tus
);
8349 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8350 Build partial symbol tables for the .debug_types comp-units. */
8353 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8355 if (! create_all_type_units (dwarf2_per_objfile
))
8358 build_type_psymtabs_1 (dwarf2_per_objfile
);
8361 /* Traversal function for process_skeletonless_type_unit.
8362 Read a TU in a DWO file and build partial symbols for it. */
8365 process_skeletonless_type_unit (void **slot
, void *info
)
8367 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
8368 struct dwarf2_per_objfile
*dwarf2_per_objfile
8369 = (struct dwarf2_per_objfile
*) info
;
8370 struct signatured_type find_entry
, *entry
;
8372 /* If this TU doesn't exist in the global table, add it and read it in. */
8374 if (dwarf2_per_objfile
->signatured_types
== NULL
)
8376 dwarf2_per_objfile
->signatured_types
8377 = allocate_signatured_type_table (dwarf2_per_objfile
->objfile
);
8380 find_entry
.signature
= dwo_unit
->signature
;
8381 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
8383 /* If we've already seen this type there's nothing to do. What's happening
8384 is we're doing our own version of comdat-folding here. */
8388 /* This does the job that create_all_type_units would have done for
8390 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
8391 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
8394 /* This does the job that build_type_psymtabs_1 would have done. */
8395 init_cutu_and_read_dies (&entry
->per_cu
, NULL
, 0, 0,
8396 build_type_psymtabs_reader
, NULL
);
8401 /* Traversal function for process_skeletonless_type_units. */
8404 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
8406 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8408 if (dwo_file
->tus
!= NULL
)
8410 htab_traverse_noresize (dwo_file
->tus
,
8411 process_skeletonless_type_unit
, info
);
8417 /* Scan all TUs of DWO files, verifying we've processed them.
8418 This is needed in case a TU was emitted without its skeleton.
8419 Note: This can't be done until we know what all the DWO files are. */
8422 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8424 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
8425 if (get_dwp_file (dwarf2_per_objfile
) == NULL
8426 && dwarf2_per_objfile
->dwo_files
!= NULL
)
8428 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
,
8429 process_dwo_file_for_skeletonless_type_units
,
8430 dwarf2_per_objfile
);
8434 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
8437 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8441 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
8443 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
8444 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8450 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
8452 /* Set the 'user' field only if it is not already set. */
8453 if (pst
->dependencies
[j
]->user
== NULL
)
8454 pst
->dependencies
[j
]->user
= pst
;
8459 /* Build the partial symbol table by doing a quick pass through the
8460 .debug_info and .debug_abbrev sections. */
8463 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8466 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8468 if (dwarf_read_debug
)
8470 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
8471 objfile_name (objfile
));
8474 dwarf2_per_objfile
->reading_partial_symbols
= 1;
8476 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
8478 /* Any cached compilation units will be linked by the per-objfile
8479 read_in_chain. Make sure to free them when we're done. */
8480 free_cached_comp_units
freer (dwarf2_per_objfile
);
8482 build_type_psymtabs (dwarf2_per_objfile
);
8484 create_all_comp_units (dwarf2_per_objfile
);
8486 /* Create a temporary address map on a temporary obstack. We later
8487 copy this to the final obstack. */
8488 auto_obstack temp_obstack
;
8490 scoped_restore save_psymtabs_addrmap
8491 = make_scoped_restore (&objfile
->psymtabs_addrmap
,
8492 addrmap_create_mutable (&temp_obstack
));
8494 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
8496 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
8498 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
8501 /* This has to wait until we read the CUs, we need the list of DWOs. */
8502 process_skeletonless_type_units (dwarf2_per_objfile
);
8504 /* Now that all TUs have been processed we can fill in the dependencies. */
8505 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
8507 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
8508 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
8511 if (dwarf_read_debug
)
8512 print_tu_stats (dwarf2_per_objfile
);
8514 set_partial_user (dwarf2_per_objfile
);
8516 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
8517 &objfile
->objfile_obstack
);
8518 /* At this point we want to keep the address map. */
8519 save_psymtabs_addrmap
.release ();
8521 if (dwarf_read_debug
)
8522 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8523 objfile_name (objfile
));
8526 /* die_reader_func for load_partial_comp_unit. */
8529 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
8530 const gdb_byte
*info_ptr
,
8531 struct die_info
*comp_unit_die
,
8535 struct dwarf2_cu
*cu
= reader
->cu
;
8537 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
8539 /* Check if comp unit has_children.
8540 If so, read the rest of the partial symbols from this comp unit.
8541 If not, there's no more debug_info for this comp unit. */
8543 load_partial_dies (reader
, info_ptr
, 0);
8546 /* Load the partial DIEs for a secondary CU into memory.
8547 This is also used when rereading a primary CU with load_all_dies. */
8550 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
8552 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
8553 load_partial_comp_unit_reader
, NULL
);
8557 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
8558 struct dwarf2_section_info
*section
,
8559 struct dwarf2_section_info
*abbrev_section
,
8560 unsigned int is_dwz
,
8563 struct dwarf2_per_cu_data
***all_comp_units
)
8565 const gdb_byte
*info_ptr
;
8566 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8568 if (dwarf_read_debug
)
8569 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8570 get_section_name (section
),
8571 get_section_file_name (section
));
8573 dwarf2_read_section (objfile
, section
);
8575 info_ptr
= section
->buffer
;
8577 while (info_ptr
< section
->buffer
+ section
->size
)
8579 struct dwarf2_per_cu_data
*this_cu
;
8581 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8583 comp_unit_head cu_header
;
8584 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
8585 abbrev_section
, info_ptr
,
8586 rcuh_kind::COMPILE
);
8588 /* Save the compilation unit for later lookup. */
8589 if (cu_header
.unit_type
!= DW_UT_type
)
8591 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
8592 struct dwarf2_per_cu_data
);
8593 memset (this_cu
, 0, sizeof (*this_cu
));
8597 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
8598 struct signatured_type
);
8599 memset (sig_type
, 0, sizeof (*sig_type
));
8600 sig_type
->signature
= cu_header
.signature
;
8601 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8602 this_cu
= &sig_type
->per_cu
;
8604 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8605 this_cu
->sect_off
= sect_off
;
8606 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8607 this_cu
->is_dwz
= is_dwz
;
8608 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
8609 this_cu
->section
= section
;
8611 if (*n_comp_units
== *n_allocated
)
8614 *all_comp_units
= XRESIZEVEC (struct dwarf2_per_cu_data
*,
8615 *all_comp_units
, *n_allocated
);
8617 (*all_comp_units
)[*n_comp_units
] = this_cu
;
8620 info_ptr
= info_ptr
+ this_cu
->length
;
8624 /* Create a list of all compilation units in OBJFILE.
8625 This is only done for -readnow and building partial symtabs. */
8628 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8632 struct dwarf2_per_cu_data
**all_comp_units
;
8633 struct dwz_file
*dwz
;
8634 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8638 all_comp_units
= XNEWVEC (struct dwarf2_per_cu_data
*, n_allocated
);
8640 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
8641 &dwarf2_per_objfile
->abbrev
, 0,
8642 &n_allocated
, &n_comp_units
, &all_comp_units
);
8644 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
8646 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
8647 1, &n_allocated
, &n_comp_units
,
8650 dwarf2_per_objfile
->all_comp_units
= XOBNEWVEC (&objfile
->objfile_obstack
,
8651 struct dwarf2_per_cu_data
*,
8653 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
8654 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
8655 xfree (all_comp_units
);
8656 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
8659 /* Process all loaded DIEs for compilation unit CU, starting at
8660 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8661 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8662 DW_AT_ranges). See the comments of add_partial_subprogram on how
8663 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8666 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8667 CORE_ADDR
*highpc
, int set_addrmap
,
8668 struct dwarf2_cu
*cu
)
8670 struct partial_die_info
*pdi
;
8672 /* Now, march along the PDI's, descending into ones which have
8673 interesting children but skipping the children of the other ones,
8674 until we reach the end of the compilation unit. */
8682 /* Anonymous namespaces or modules have no name but have interesting
8683 children, so we need to look at them. Ditto for anonymous
8686 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8687 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8688 || pdi
->tag
== DW_TAG_imported_unit
8689 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8693 case DW_TAG_subprogram
:
8694 case DW_TAG_inlined_subroutine
:
8695 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8697 case DW_TAG_constant
:
8698 case DW_TAG_variable
:
8699 case DW_TAG_typedef
:
8700 case DW_TAG_union_type
:
8701 if (!pdi
->is_declaration
)
8703 add_partial_symbol (pdi
, cu
);
8706 case DW_TAG_class_type
:
8707 case DW_TAG_interface_type
:
8708 case DW_TAG_structure_type
:
8709 if (!pdi
->is_declaration
)
8711 add_partial_symbol (pdi
, cu
);
8713 if ((cu
->language
== language_rust
8714 || cu
->language
== language_cplus
) && pdi
->has_children
)
8715 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8718 case DW_TAG_enumeration_type
:
8719 if (!pdi
->is_declaration
)
8720 add_partial_enumeration (pdi
, cu
);
8722 case DW_TAG_base_type
:
8723 case DW_TAG_subrange_type
:
8724 /* File scope base type definitions are added to the partial
8726 add_partial_symbol (pdi
, cu
);
8728 case DW_TAG_namespace
:
8729 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8732 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8734 case DW_TAG_imported_unit
:
8736 struct dwarf2_per_cu_data
*per_cu
;
8738 /* For now we don't handle imported units in type units. */
8739 if (cu
->per_cu
->is_debug_types
)
8741 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8742 " supported in type units [in module %s]"),
8743 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
8746 per_cu
= dwarf2_find_containing_comp_unit
8747 (pdi
->d
.sect_off
, pdi
->is_dwz
,
8748 cu
->per_cu
->dwarf2_per_objfile
);
8750 /* Go read the partial unit, if needed. */
8751 if (per_cu
->v
.psymtab
== NULL
)
8752 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
8754 VEC_safe_push (dwarf2_per_cu_ptr
,
8755 cu
->per_cu
->imported_symtabs
, per_cu
);
8758 case DW_TAG_imported_declaration
:
8759 add_partial_symbol (pdi
, cu
);
8766 /* If the die has a sibling, skip to the sibling. */
8768 pdi
= pdi
->die_sibling
;
8772 /* Functions used to compute the fully scoped name of a partial DIE.
8774 Normally, this is simple. For C++, the parent DIE's fully scoped
8775 name is concatenated with "::" and the partial DIE's name.
8776 Enumerators are an exception; they use the scope of their parent
8777 enumeration type, i.e. the name of the enumeration type is not
8778 prepended to the enumerator.
8780 There are two complexities. One is DW_AT_specification; in this
8781 case "parent" means the parent of the target of the specification,
8782 instead of the direct parent of the DIE. The other is compilers
8783 which do not emit DW_TAG_namespace; in this case we try to guess
8784 the fully qualified name of structure types from their members'
8785 linkage names. This must be done using the DIE's children rather
8786 than the children of any DW_AT_specification target. We only need
8787 to do this for structures at the top level, i.e. if the target of
8788 any DW_AT_specification (if any; otherwise the DIE itself) does not
8791 /* Compute the scope prefix associated with PDI's parent, in
8792 compilation unit CU. The result will be allocated on CU's
8793 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8794 field. NULL is returned if no prefix is necessary. */
8796 partial_die_parent_scope (struct partial_die_info
*pdi
,
8797 struct dwarf2_cu
*cu
)
8799 const char *grandparent_scope
;
8800 struct partial_die_info
*parent
, *real_pdi
;
8802 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8803 then this means the parent of the specification DIE. */
8806 while (real_pdi
->has_specification
)
8807 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
8808 real_pdi
->spec_is_dwz
, cu
);
8810 parent
= real_pdi
->die_parent
;
8814 if (parent
->scope_set
)
8815 return parent
->scope
;
8819 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8821 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8822 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8823 Work around this problem here. */
8824 if (cu
->language
== language_cplus
8825 && parent
->tag
== DW_TAG_namespace
8826 && strcmp (parent
->name
, "::") == 0
8827 && grandparent_scope
== NULL
)
8829 parent
->scope
= NULL
;
8830 parent
->scope_set
= 1;
8834 if (pdi
->tag
== DW_TAG_enumerator
)
8835 /* Enumerators should not get the name of the enumeration as a prefix. */
8836 parent
->scope
= grandparent_scope
;
8837 else if (parent
->tag
== DW_TAG_namespace
8838 || parent
->tag
== DW_TAG_module
8839 || parent
->tag
== DW_TAG_structure_type
8840 || parent
->tag
== DW_TAG_class_type
8841 || parent
->tag
== DW_TAG_interface_type
8842 || parent
->tag
== DW_TAG_union_type
8843 || parent
->tag
== DW_TAG_enumeration_type
)
8845 if (grandparent_scope
== NULL
)
8846 parent
->scope
= parent
->name
;
8848 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8850 parent
->name
, 0, cu
);
8854 /* FIXME drow/2004-04-01: What should we be doing with
8855 function-local names? For partial symbols, we should probably be
8857 complaint (&symfile_complaints
,
8858 _("unhandled containing DIE tag %d for DIE at %s"),
8859 parent
->tag
, sect_offset_str (pdi
->sect_off
));
8860 parent
->scope
= grandparent_scope
;
8863 parent
->scope_set
= 1;
8864 return parent
->scope
;
8867 /* Return the fully scoped name associated with PDI, from compilation unit
8868 CU. The result will be allocated with malloc. */
8871 partial_die_full_name (struct partial_die_info
*pdi
,
8872 struct dwarf2_cu
*cu
)
8874 const char *parent_scope
;
8876 /* If this is a template instantiation, we can not work out the
8877 template arguments from partial DIEs. So, unfortunately, we have
8878 to go through the full DIEs. At least any work we do building
8879 types here will be reused if full symbols are loaded later. */
8880 if (pdi
->has_template_arguments
)
8884 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8886 struct die_info
*die
;
8887 struct attribute attr
;
8888 struct dwarf2_cu
*ref_cu
= cu
;
8890 /* DW_FORM_ref_addr is using section offset. */
8891 attr
.name
= (enum dwarf_attribute
) 0;
8892 attr
.form
= DW_FORM_ref_addr
;
8893 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8894 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8896 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8900 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8901 if (parent_scope
== NULL
)
8904 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
8908 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8910 struct dwarf2_per_objfile
*dwarf2_per_objfile
8911 = cu
->per_cu
->dwarf2_per_objfile
;
8912 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8913 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8915 const char *actual_name
= NULL
;
8917 char *built_actual_name
;
8919 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8921 built_actual_name
= partial_die_full_name (pdi
, cu
);
8922 if (built_actual_name
!= NULL
)
8923 actual_name
= built_actual_name
;
8925 if (actual_name
== NULL
)
8926 actual_name
= pdi
->name
;
8930 case DW_TAG_inlined_subroutine
:
8931 case DW_TAG_subprogram
:
8932 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
);
8933 if (pdi
->is_external
|| cu
->language
== language_ada
)
8935 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
8936 of the global scope. But in Ada, we want to be able to access
8937 nested procedures globally. So all Ada subprograms are stored
8938 in the global scope. */
8939 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8940 built_actual_name
!= NULL
,
8941 VAR_DOMAIN
, LOC_BLOCK
,
8942 &objfile
->global_psymbols
,
8943 addr
, cu
->language
, objfile
);
8947 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8948 built_actual_name
!= NULL
,
8949 VAR_DOMAIN
, LOC_BLOCK
,
8950 &objfile
->static_psymbols
,
8951 addr
, cu
->language
, objfile
);
8954 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8955 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8957 case DW_TAG_constant
:
8959 std::vector
<partial_symbol
*> *list
;
8961 if (pdi
->is_external
)
8962 list
= &objfile
->global_psymbols
;
8964 list
= &objfile
->static_psymbols
;
8965 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8966 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8967 list
, 0, cu
->language
, objfile
);
8970 case DW_TAG_variable
:
8972 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8976 && !dwarf2_per_objfile
->has_section_at_zero
)
8978 /* A global or static variable may also have been stripped
8979 out by the linker if unused, in which case its address
8980 will be nullified; do not add such variables into partial
8981 symbol table then. */
8983 else if (pdi
->is_external
)
8986 Don't enter into the minimal symbol tables as there is
8987 a minimal symbol table entry from the ELF symbols already.
8988 Enter into partial symbol table if it has a location
8989 descriptor or a type.
8990 If the location descriptor is missing, new_symbol will create
8991 a LOC_UNRESOLVED symbol, the address of the variable will then
8992 be determined from the minimal symbol table whenever the variable
8994 The address for the partial symbol table entry is not
8995 used by GDB, but it comes in handy for debugging partial symbol
8998 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8999 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9000 built_actual_name
!= NULL
,
9001 VAR_DOMAIN
, LOC_STATIC
,
9002 &objfile
->global_psymbols
,
9004 cu
->language
, objfile
);
9008 int has_loc
= pdi
->d
.locdesc
!= NULL
;
9010 /* Static Variable. Skip symbols whose value we cannot know (those
9011 without location descriptors or constant values). */
9012 if (!has_loc
&& !pdi
->has_const_value
)
9014 xfree (built_actual_name
);
9018 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9019 built_actual_name
!= NULL
,
9020 VAR_DOMAIN
, LOC_STATIC
,
9021 &objfile
->static_psymbols
,
9022 has_loc
? addr
+ baseaddr
: (CORE_ADDR
) 0,
9023 cu
->language
, objfile
);
9026 case DW_TAG_typedef
:
9027 case DW_TAG_base_type
:
9028 case DW_TAG_subrange_type
:
9029 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9030 built_actual_name
!= NULL
,
9031 VAR_DOMAIN
, LOC_TYPEDEF
,
9032 &objfile
->static_psymbols
,
9033 0, cu
->language
, objfile
);
9035 case DW_TAG_imported_declaration
:
9036 case DW_TAG_namespace
:
9037 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9038 built_actual_name
!= NULL
,
9039 VAR_DOMAIN
, LOC_TYPEDEF
,
9040 &objfile
->global_psymbols
,
9041 0, cu
->language
, objfile
);
9044 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9045 built_actual_name
!= NULL
,
9046 MODULE_DOMAIN
, LOC_TYPEDEF
,
9047 &objfile
->global_psymbols
,
9048 0, cu
->language
, objfile
);
9050 case DW_TAG_class_type
:
9051 case DW_TAG_interface_type
:
9052 case DW_TAG_structure_type
:
9053 case DW_TAG_union_type
:
9054 case DW_TAG_enumeration_type
:
9055 /* Skip external references. The DWARF standard says in the section
9056 about "Structure, Union, and Class Type Entries": "An incomplete
9057 structure, union or class type is represented by a structure,
9058 union or class entry that does not have a byte size attribute
9059 and that has a DW_AT_declaration attribute." */
9060 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
9062 xfree (built_actual_name
);
9066 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
9067 static vs. global. */
9068 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9069 built_actual_name
!= NULL
,
9070 STRUCT_DOMAIN
, LOC_TYPEDEF
,
9071 cu
->language
== language_cplus
9072 ? &objfile
->global_psymbols
9073 : &objfile
->static_psymbols
,
9074 0, cu
->language
, objfile
);
9077 case DW_TAG_enumerator
:
9078 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9079 built_actual_name
!= NULL
,
9080 VAR_DOMAIN
, LOC_CONST
,
9081 cu
->language
== language_cplus
9082 ? &objfile
->global_psymbols
9083 : &objfile
->static_psymbols
,
9084 0, cu
->language
, objfile
);
9090 xfree (built_actual_name
);
9093 /* Read a partial die corresponding to a namespace; also, add a symbol
9094 corresponding to that namespace to the symbol table. NAMESPACE is
9095 the name of the enclosing namespace. */
9098 add_partial_namespace (struct partial_die_info
*pdi
,
9099 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9100 int set_addrmap
, struct dwarf2_cu
*cu
)
9102 /* Add a symbol for the namespace. */
9104 add_partial_symbol (pdi
, cu
);
9106 /* Now scan partial symbols in that namespace. */
9108 if (pdi
->has_children
)
9109 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9112 /* Read a partial die corresponding to a Fortran module. */
9115 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
9116 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
9118 /* Add a symbol for the namespace. */
9120 add_partial_symbol (pdi
, cu
);
9122 /* Now scan partial symbols in that module. */
9124 if (pdi
->has_children
)
9125 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9128 /* Read a partial die corresponding to a subprogram or an inlined
9129 subprogram and create a partial symbol for that subprogram.
9130 When the CU language allows it, this routine also defines a partial
9131 symbol for each nested subprogram that this subprogram contains.
9132 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
9133 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
9135 PDI may also be a lexical block, in which case we simply search
9136 recursively for subprograms defined inside that lexical block.
9137 Again, this is only performed when the CU language allows this
9138 type of definitions. */
9141 add_partial_subprogram (struct partial_die_info
*pdi
,
9142 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9143 int set_addrmap
, struct dwarf2_cu
*cu
)
9145 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
9147 if (pdi
->has_pc_info
)
9149 if (pdi
->lowpc
< *lowpc
)
9150 *lowpc
= pdi
->lowpc
;
9151 if (pdi
->highpc
> *highpc
)
9152 *highpc
= pdi
->highpc
;
9155 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9156 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9161 baseaddr
= ANOFFSET (objfile
->section_offsets
,
9162 SECT_OFF_TEXT (objfile
));
9163 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
9164 pdi
->lowpc
+ baseaddr
);
9165 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
9166 pdi
->highpc
+ baseaddr
);
9167 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
9168 cu
->per_cu
->v
.psymtab
);
9172 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
9174 if (!pdi
->is_declaration
)
9175 /* Ignore subprogram DIEs that do not have a name, they are
9176 illegal. Do not emit a complaint at this point, we will
9177 do so when we convert this psymtab into a symtab. */
9179 add_partial_symbol (pdi
, cu
);
9183 if (! pdi
->has_children
)
9186 if (cu
->language
== language_ada
)
9188 pdi
= pdi
->die_child
;
9192 if (pdi
->tag
== DW_TAG_subprogram
9193 || pdi
->tag
== DW_TAG_inlined_subroutine
9194 || pdi
->tag
== DW_TAG_lexical_block
)
9195 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9196 pdi
= pdi
->die_sibling
;
9201 /* Read a partial die corresponding to an enumeration type. */
9204 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
9205 struct dwarf2_cu
*cu
)
9207 struct partial_die_info
*pdi
;
9209 if (enum_pdi
->name
!= NULL
)
9210 add_partial_symbol (enum_pdi
, cu
);
9212 pdi
= enum_pdi
->die_child
;
9215 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
9216 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
9218 add_partial_symbol (pdi
, cu
);
9219 pdi
= pdi
->die_sibling
;
9223 /* Return the initial uleb128 in the die at INFO_PTR. */
9226 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
9228 unsigned int bytes_read
;
9230 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9233 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
9234 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
9236 Return the corresponding abbrev, or NULL if the number is zero (indicating
9237 an empty DIE). In either case *BYTES_READ will be set to the length of
9238 the initial number. */
9240 static struct abbrev_info
*
9241 peek_die_abbrev (const die_reader_specs
&reader
,
9242 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
9244 dwarf2_cu
*cu
= reader
.cu
;
9245 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
9246 unsigned int abbrev_number
9247 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
9249 if (abbrev_number
== 0)
9252 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
9255 error (_("Dwarf Error: Could not find abbrev number %d in %s"
9256 " at offset %s [in module %s]"),
9257 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
9258 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
9264 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9265 Returns a pointer to the end of a series of DIEs, terminated by an empty
9266 DIE. Any children of the skipped DIEs will also be skipped. */
9268 static const gdb_byte
*
9269 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
9273 unsigned int bytes_read
;
9274 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
9277 return info_ptr
+ bytes_read
;
9279 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
9283 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9284 INFO_PTR should point just after the initial uleb128 of a DIE, and the
9285 abbrev corresponding to that skipped uleb128 should be passed in
9286 ABBREV. Returns a pointer to this DIE's sibling, skipping any
9289 static const gdb_byte
*
9290 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
9291 struct abbrev_info
*abbrev
)
9293 unsigned int bytes_read
;
9294 struct attribute attr
;
9295 bfd
*abfd
= reader
->abfd
;
9296 struct dwarf2_cu
*cu
= reader
->cu
;
9297 const gdb_byte
*buffer
= reader
->buffer
;
9298 const gdb_byte
*buffer_end
= reader
->buffer_end
;
9299 unsigned int form
, i
;
9301 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
9303 /* The only abbrev we care about is DW_AT_sibling. */
9304 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
9306 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
9307 if (attr
.form
== DW_FORM_ref_addr
)
9308 complaint (&symfile_complaints
,
9309 _("ignoring absolute DW_AT_sibling"));
9312 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
9313 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
9315 if (sibling_ptr
< info_ptr
)
9316 complaint (&symfile_complaints
,
9317 _("DW_AT_sibling points backwards"));
9318 else if (sibling_ptr
> reader
->buffer_end
)
9319 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
9325 /* If it isn't DW_AT_sibling, skip this attribute. */
9326 form
= abbrev
->attrs
[i
].form
;
9330 case DW_FORM_ref_addr
:
9331 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
9332 and later it is offset sized. */
9333 if (cu
->header
.version
== 2)
9334 info_ptr
+= cu
->header
.addr_size
;
9336 info_ptr
+= cu
->header
.offset_size
;
9338 case DW_FORM_GNU_ref_alt
:
9339 info_ptr
+= cu
->header
.offset_size
;
9342 info_ptr
+= cu
->header
.addr_size
;
9349 case DW_FORM_flag_present
:
9350 case DW_FORM_implicit_const
:
9362 case DW_FORM_ref_sig8
:
9365 case DW_FORM_data16
:
9368 case DW_FORM_string
:
9369 read_direct_string (abfd
, info_ptr
, &bytes_read
);
9370 info_ptr
+= bytes_read
;
9372 case DW_FORM_sec_offset
:
9374 case DW_FORM_GNU_strp_alt
:
9375 info_ptr
+= cu
->header
.offset_size
;
9377 case DW_FORM_exprloc
:
9379 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9380 info_ptr
+= bytes_read
;
9382 case DW_FORM_block1
:
9383 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
9385 case DW_FORM_block2
:
9386 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
9388 case DW_FORM_block4
:
9389 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
9393 case DW_FORM_ref_udata
:
9394 case DW_FORM_GNU_addr_index
:
9395 case DW_FORM_GNU_str_index
:
9396 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
9398 case DW_FORM_indirect
:
9399 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9400 info_ptr
+= bytes_read
;
9401 /* We need to continue parsing from here, so just go back to
9403 goto skip_attribute
;
9406 error (_("Dwarf Error: Cannot handle %s "
9407 "in DWARF reader [in module %s]"),
9408 dwarf_form_name (form
),
9409 bfd_get_filename (abfd
));
9413 if (abbrev
->has_children
)
9414 return skip_children (reader
, info_ptr
);
9419 /* Locate ORIG_PDI's sibling.
9420 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
9422 static const gdb_byte
*
9423 locate_pdi_sibling (const struct die_reader_specs
*reader
,
9424 struct partial_die_info
*orig_pdi
,
9425 const gdb_byte
*info_ptr
)
9427 /* Do we know the sibling already? */
9429 if (orig_pdi
->sibling
)
9430 return orig_pdi
->sibling
;
9432 /* Are there any children to deal with? */
9434 if (!orig_pdi
->has_children
)
9437 /* Skip the children the long way. */
9439 return skip_children (reader
, info_ptr
);
9442 /* Expand this partial symbol table into a full symbol table. SELF is
9446 dwarf2_read_symtab (struct partial_symtab
*self
,
9447 struct objfile
*objfile
)
9449 struct dwarf2_per_objfile
*dwarf2_per_objfile
9450 = get_dwarf2_per_objfile (objfile
);
9454 warning (_("bug: psymtab for %s is already read in."),
9461 printf_filtered (_("Reading in symbols for %s..."),
9463 gdb_flush (gdb_stdout
);
9466 /* If this psymtab is constructed from a debug-only objfile, the
9467 has_section_at_zero flag will not necessarily be correct. We
9468 can get the correct value for this flag by looking at the data
9469 associated with the (presumably stripped) associated objfile. */
9470 if (objfile
->separate_debug_objfile_backlink
)
9472 struct dwarf2_per_objfile
*dpo_backlink
9473 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
9475 dwarf2_per_objfile
->has_section_at_zero
9476 = dpo_backlink
->has_section_at_zero
;
9479 dwarf2_per_objfile
->reading_partial_symbols
= 0;
9481 psymtab_to_symtab_1 (self
);
9483 /* Finish up the debug error message. */
9485 printf_filtered (_("done.\n"));
9488 process_cu_includes (dwarf2_per_objfile
);
9491 /* Reading in full CUs. */
9493 /* Add PER_CU to the queue. */
9496 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9497 enum language pretend_language
)
9499 struct dwarf2_queue_item
*item
;
9502 item
= XNEW (struct dwarf2_queue_item
);
9503 item
->per_cu
= per_cu
;
9504 item
->pretend_language
= pretend_language
;
9507 if (dwarf2_queue
== NULL
)
9508 dwarf2_queue
= item
;
9510 dwarf2_queue_tail
->next
= item
;
9512 dwarf2_queue_tail
= item
;
9515 /* If PER_CU is not yet queued, add it to the queue.
9516 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9518 The result is non-zero if PER_CU was queued, otherwise the result is zero
9519 meaning either PER_CU is already queued or it is already loaded.
9521 N.B. There is an invariant here that if a CU is queued then it is loaded.
9522 The caller is required to load PER_CU if we return non-zero. */
9525 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9526 struct dwarf2_per_cu_data
*per_cu
,
9527 enum language pretend_language
)
9529 /* We may arrive here during partial symbol reading, if we need full
9530 DIEs to process an unusual case (e.g. template arguments). Do
9531 not queue PER_CU, just tell our caller to load its DIEs. */
9532 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
9534 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
9539 /* Mark the dependence relation so that we don't flush PER_CU
9541 if (dependent_cu
!= NULL
)
9542 dwarf2_add_dependence (dependent_cu
, per_cu
);
9544 /* If it's already on the queue, we have nothing to do. */
9548 /* If the compilation unit is already loaded, just mark it as
9550 if (per_cu
->cu
!= NULL
)
9552 per_cu
->cu
->last_used
= 0;
9556 /* Add it to the queue. */
9557 queue_comp_unit (per_cu
, pretend_language
);
9562 /* Process the queue. */
9565 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9567 struct dwarf2_queue_item
*item
, *next_item
;
9569 if (dwarf_read_debug
)
9571 fprintf_unfiltered (gdb_stdlog
,
9572 "Expanding one or more symtabs of objfile %s ...\n",
9573 objfile_name (dwarf2_per_objfile
->objfile
));
9576 /* The queue starts out with one item, but following a DIE reference
9577 may load a new CU, adding it to the end of the queue. */
9578 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
9580 if ((dwarf2_per_objfile
->using_index
9581 ? !item
->per_cu
->v
.quick
->compunit_symtab
9582 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
9583 /* Skip dummy CUs. */
9584 && item
->per_cu
->cu
!= NULL
)
9586 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
9587 unsigned int debug_print_threshold
;
9590 if (per_cu
->is_debug_types
)
9592 struct signatured_type
*sig_type
=
9593 (struct signatured_type
*) per_cu
;
9595 sprintf (buf
, "TU %s at offset %s",
9596 hex_string (sig_type
->signature
),
9597 sect_offset_str (per_cu
->sect_off
));
9598 /* There can be 100s of TUs.
9599 Only print them in verbose mode. */
9600 debug_print_threshold
= 2;
9604 sprintf (buf
, "CU at offset %s",
9605 sect_offset_str (per_cu
->sect_off
));
9606 debug_print_threshold
= 1;
9609 if (dwarf_read_debug
>= debug_print_threshold
)
9610 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9612 if (per_cu
->is_debug_types
)
9613 process_full_type_unit (per_cu
, item
->pretend_language
);
9615 process_full_comp_unit (per_cu
, item
->pretend_language
);
9617 if (dwarf_read_debug
>= debug_print_threshold
)
9618 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9621 item
->per_cu
->queued
= 0;
9622 next_item
= item
->next
;
9626 dwarf2_queue_tail
= NULL
;
9628 if (dwarf_read_debug
)
9630 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9631 objfile_name (dwarf2_per_objfile
->objfile
));
9635 /* Read in full symbols for PST, and anything it depends on. */
9638 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
9640 struct dwarf2_per_cu_data
*per_cu
;
9646 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
9647 if (!pst
->dependencies
[i
]->readin
9648 && pst
->dependencies
[i
]->user
== NULL
)
9650 /* Inform about additional files that need to be read in. */
9653 /* FIXME: i18n: Need to make this a single string. */
9654 fputs_filtered (" ", gdb_stdout
);
9656 fputs_filtered ("and ", gdb_stdout
);
9658 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
9659 wrap_here (""); /* Flush output. */
9660 gdb_flush (gdb_stdout
);
9662 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
9665 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
9669 /* It's an include file, no symbols to read for it.
9670 Everything is in the parent symtab. */
9675 dw2_do_instantiate_symtab (per_cu
);
9678 /* Trivial hash function for die_info: the hash value of a DIE
9679 is its offset in .debug_info for this objfile. */
9682 die_hash (const void *item
)
9684 const struct die_info
*die
= (const struct die_info
*) item
;
9686 return to_underlying (die
->sect_off
);
9689 /* Trivial comparison function for die_info structures: two DIEs
9690 are equal if they have the same offset. */
9693 die_eq (const void *item_lhs
, const void *item_rhs
)
9695 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9696 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9698 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9701 /* die_reader_func for load_full_comp_unit.
9702 This is identical to read_signatured_type_reader,
9703 but is kept separate for now. */
9706 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
9707 const gdb_byte
*info_ptr
,
9708 struct die_info
*comp_unit_die
,
9712 struct dwarf2_cu
*cu
= reader
->cu
;
9713 enum language
*language_ptr
= (enum language
*) data
;
9715 gdb_assert (cu
->die_hash
== NULL
);
9717 htab_create_alloc_ex (cu
->header
.length
/ 12,
9721 &cu
->comp_unit_obstack
,
9722 hashtab_obstack_allocate
,
9723 dummy_obstack_deallocate
);
9726 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
9727 &info_ptr
, comp_unit_die
);
9728 cu
->dies
= comp_unit_die
;
9729 /* comp_unit_die is not stored in die_hash, no need. */
9731 /* We try not to read any attributes in this function, because not
9732 all CUs needed for references have been loaded yet, and symbol
9733 table processing isn't initialized. But we have to set the CU language,
9734 or we won't be able to build types correctly.
9735 Similarly, if we do not read the producer, we can not apply
9736 producer-specific interpretation. */
9737 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
9740 /* Load the DIEs associated with PER_CU into memory. */
9743 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
9744 enum language pretend_language
)
9746 gdb_assert (! this_cu
->is_debug_types
);
9748 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
9749 load_full_comp_unit_reader
, &pretend_language
);
9752 /* Add a DIE to the delayed physname list. */
9755 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9756 const char *name
, struct die_info
*die
,
9757 struct dwarf2_cu
*cu
)
9759 struct delayed_method_info mi
;
9761 mi
.fnfield_index
= fnfield_index
;
9765 cu
->method_list
.push_back (mi
);
9768 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9769 "const" / "volatile". If so, decrements LEN by the length of the
9770 modifier and return true. Otherwise return false. */
9774 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9776 size_t mod_len
= sizeof (mod
) - 1;
9777 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9785 /* Compute the physnames of any methods on the CU's method list.
9787 The computation of method physnames is delayed in order to avoid the
9788 (bad) condition that one of the method's formal parameters is of an as yet
9792 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9794 /* Only C++ delays computing physnames. */
9795 if (cu
->method_list
.empty ())
9797 gdb_assert (cu
->language
== language_cplus
);
9799 for (struct delayed_method_info
&mi
: cu
->method_list
)
9801 const char *physname
;
9802 struct fn_fieldlist
*fn_flp
9803 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9804 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9805 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9806 = physname
? physname
: "";
9808 /* Since there's no tag to indicate whether a method is a
9809 const/volatile overload, extract that information out of the
9811 if (physname
!= NULL
)
9813 size_t len
= strlen (physname
);
9817 if (physname
[len
] == ')') /* shortcut */
9819 else if (check_modifier (physname
, len
, " const"))
9820 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9821 else if (check_modifier (physname
, len
, " volatile"))
9822 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9829 /* The list is no longer needed. */
9830 cu
->method_list
.clear ();
9833 /* Go objects should be embedded in a DW_TAG_module DIE,
9834 and it's not clear if/how imported objects will appear.
9835 To keep Go support simple until that's worked out,
9836 go back through what we've read and create something usable.
9837 We could do this while processing each DIE, and feels kinda cleaner,
9838 but that way is more invasive.
9839 This is to, for example, allow the user to type "p var" or "b main"
9840 without having to specify the package name, and allow lookups
9841 of module.object to work in contexts that use the expression
9845 fixup_go_packaging (struct dwarf2_cu
*cu
)
9847 char *package_name
= NULL
;
9848 struct pending
*list
;
9851 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
9853 for (i
= 0; i
< list
->nsyms
; ++i
)
9855 struct symbol
*sym
= list
->symbol
[i
];
9857 if (SYMBOL_LANGUAGE (sym
) == language_go
9858 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9860 char *this_package_name
= go_symbol_package_name (sym
);
9862 if (this_package_name
== NULL
)
9864 if (package_name
== NULL
)
9865 package_name
= this_package_name
;
9868 struct objfile
*objfile
9869 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9870 if (strcmp (package_name
, this_package_name
) != 0)
9871 complaint (&symfile_complaints
,
9872 _("Symtab %s has objects from two different Go packages: %s and %s"),
9873 (symbol_symtab (sym
) != NULL
9874 ? symtab_to_filename_for_display
9875 (symbol_symtab (sym
))
9876 : objfile_name (objfile
)),
9877 this_package_name
, package_name
);
9878 xfree (this_package_name
);
9884 if (package_name
!= NULL
)
9886 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9887 const char *saved_package_name
9888 = (const char *) obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
9890 strlen (package_name
));
9891 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9892 saved_package_name
);
9895 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
9897 sym
= allocate_symbol (objfile
);
9898 SYMBOL_SET_LANGUAGE (sym
, language_go
, &objfile
->objfile_obstack
);
9899 SYMBOL_SET_NAMES (sym
, saved_package_name
,
9900 strlen (saved_package_name
), 0, objfile
);
9901 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9902 e.g., "main" finds the "main" module and not C's main(). */
9903 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9904 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9905 SYMBOL_TYPE (sym
) = type
;
9907 add_symbol_to_list (sym
, &global_symbols
);
9909 xfree (package_name
);
9913 /* Allocate a fully-qualified name consisting of the two parts on the
9917 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9919 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9922 /* A helper that allocates a struct discriminant_info to attach to a
9925 static struct discriminant_info
*
9926 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9929 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9930 gdb_assert (discriminant_index
== -1
9931 || (discriminant_index
>= 0
9932 && discriminant_index
< TYPE_NFIELDS (type
)));
9933 gdb_assert (default_index
== -1
9934 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9936 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9938 struct discriminant_info
*disc
9939 = ((struct discriminant_info
*)
9941 offsetof (struct discriminant_info
, discriminants
)
9942 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9943 disc
->default_index
= default_index
;
9944 disc
->discriminant_index
= discriminant_index
;
9946 struct dynamic_prop prop
;
9947 prop
.kind
= PROP_UNDEFINED
;
9948 prop
.data
.baton
= disc
;
9950 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9955 /* Some versions of rustc emitted enums in an unusual way.
9957 Ordinary enums were emitted as unions. The first element of each
9958 structure in the union was named "RUST$ENUM$DISR". This element
9959 held the discriminant.
9961 These versions of Rust also implemented the "non-zero"
9962 optimization. When the enum had two values, and one is empty and
9963 the other holds a pointer that cannot be zero, the pointer is used
9964 as the discriminant, with a zero value meaning the empty variant.
9965 Here, the union's first member is of the form
9966 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9967 where the fieldnos are the indices of the fields that should be
9968 traversed in order to find the field (which may be several fields deep)
9969 and the variantname is the name of the variant of the case when the
9972 This function recognizes whether TYPE is of one of these forms,
9973 and, if so, smashes it to be a variant type. */
9976 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9978 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9980 /* We don't need to deal with empty enums. */
9981 if (TYPE_NFIELDS (type
) == 0)
9984 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9985 if (TYPE_NFIELDS (type
) == 1
9986 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9988 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9990 /* Decode the field name to find the offset of the
9992 ULONGEST bit_offset
= 0;
9993 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9994 while (name
[0] >= '0' && name
[0] <= '9')
9997 unsigned long index
= strtoul (name
, &tail
, 10);
10000 || index
>= TYPE_NFIELDS (field_type
)
10001 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
10002 != FIELD_LOC_KIND_BITPOS
))
10004 complaint (&symfile_complaints
,
10005 _("Could not parse Rust enum encoding string \"%s\""
10007 TYPE_FIELD_NAME (type
, 0),
10008 objfile_name (objfile
));
10013 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
10014 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
10017 /* Make a union to hold the variants. */
10018 struct type
*union_type
= alloc_type (objfile
);
10019 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10020 TYPE_NFIELDS (union_type
) = 3;
10021 TYPE_FIELDS (union_type
)
10022 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
10023 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10025 /* Put the discriminant must at index 0. */
10026 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
10027 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10028 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10029 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
10031 /* The order of fields doesn't really matter, so put the real
10032 field at index 1 and the data-less field at index 2. */
10033 struct discriminant_info
*disc
10034 = alloc_discriminant_info (union_type
, 0, 1);
10035 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
10036 TYPE_FIELD_NAME (union_type
, 1)
10037 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
10038 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
10039 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10040 TYPE_FIELD_NAME (union_type
, 1));
10042 const char *dataless_name
10043 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10045 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
10047 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
10048 /* NAME points into the original discriminant name, which
10049 already has the correct lifetime. */
10050 TYPE_FIELD_NAME (union_type
, 2) = name
;
10051 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
10052 disc
->discriminants
[2] = 0;
10054 /* Smash this type to be a structure type. We have to do this
10055 because the type has already been recorded. */
10056 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10057 TYPE_NFIELDS (type
) = 1;
10059 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
10061 /* Install the variant part. */
10062 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10063 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10064 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10066 else if (TYPE_NFIELDS (type
) == 1)
10068 /* We assume that a union with a single field is a univariant
10070 /* Smash this type to be a structure type. We have to do this
10071 because the type has already been recorded. */
10072 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10074 /* Make a union to hold the variants. */
10075 struct type
*union_type
= alloc_type (objfile
);
10076 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10077 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
10078 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10079 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
10081 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
10082 const char *variant_name
10083 = rust_last_path_segment (TYPE_NAME (field_type
));
10084 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
10085 TYPE_NAME (field_type
)
10086 = rust_fully_qualify (&objfile
->objfile_obstack
,
10087 TYPE_NAME (type
), variant_name
);
10089 /* Install the union in the outer struct type. */
10090 TYPE_NFIELDS (type
) = 1;
10092 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
10093 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10094 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10095 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10097 alloc_discriminant_info (union_type
, -1, 0);
10101 struct type
*disr_type
= nullptr;
10102 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
10104 disr_type
= TYPE_FIELD_TYPE (type
, i
);
10106 if (TYPE_NFIELDS (disr_type
) == 0)
10108 /* Could be data-less variant, so keep going. */
10110 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
10111 "RUST$ENUM$DISR") != 0)
10113 /* Not a Rust enum. */
10123 /* If we got here without a discriminant, then it's probably
10125 if (disr_type
== nullptr)
10128 /* Smash this type to be a structure type. We have to do this
10129 because the type has already been recorded. */
10130 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10132 /* Make a union to hold the variants. */
10133 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
10134 struct type
*union_type
= alloc_type (objfile
);
10135 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10136 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
10137 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10138 TYPE_FIELDS (union_type
)
10139 = (struct field
*) TYPE_ZALLOC (union_type
,
10140 (TYPE_NFIELDS (union_type
)
10141 * sizeof (struct field
)));
10143 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
10144 TYPE_NFIELDS (type
) * sizeof (struct field
));
10146 /* Install the discriminant at index 0 in the union. */
10147 TYPE_FIELD (union_type
, 0) = *disr_field
;
10148 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10149 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10151 /* Install the union in the outer struct type. */
10152 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10153 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10154 TYPE_NFIELDS (type
) = 1;
10156 /* Set the size and offset of the union type. */
10157 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10159 /* We need a way to find the correct discriminant given a
10160 variant name. For convenience we build a map here. */
10161 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
10162 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
10163 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
10165 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
10168 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
10169 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
10173 int n_fields
= TYPE_NFIELDS (union_type
);
10174 struct discriminant_info
*disc
10175 = alloc_discriminant_info (union_type
, 0, -1);
10176 /* Skip the discriminant here. */
10177 for (int i
= 1; i
< n_fields
; ++i
)
10179 /* Find the final word in the name of this variant's type.
10180 That name can be used to look up the correct
10182 const char *variant_name
10183 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
10186 auto iter
= discriminant_map
.find (variant_name
);
10187 if (iter
!= discriminant_map
.end ())
10188 disc
->discriminants
[i
] = iter
->second
;
10190 /* Remove the discriminant field. */
10191 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
10192 --TYPE_NFIELDS (sub_type
);
10193 ++TYPE_FIELDS (sub_type
);
10194 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
10195 TYPE_NAME (sub_type
)
10196 = rust_fully_qualify (&objfile
->objfile_obstack
,
10197 TYPE_NAME (type
), variant_name
);
10202 /* Rewrite some Rust unions to be structures with variants parts. */
10205 rust_union_quirks (struct dwarf2_cu
*cu
)
10207 gdb_assert (cu
->language
== language_rust
);
10208 for (struct type
*type
: cu
->rust_unions
)
10209 quirk_rust_enum (type
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
10212 /* Return the symtab for PER_CU. This works properly regardless of
10213 whether we're using the index or psymtabs. */
10215 static struct compunit_symtab
*
10216 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
10218 return (per_cu
->dwarf2_per_objfile
->using_index
10219 ? per_cu
->v
.quick
->compunit_symtab
10220 : per_cu
->v
.psymtab
->compunit_symtab
);
10223 /* A helper function for computing the list of all symbol tables
10224 included by PER_CU. */
10227 recursively_compute_inclusions (VEC (compunit_symtab_ptr
) **result
,
10228 htab_t all_children
, htab_t all_type_symtabs
,
10229 struct dwarf2_per_cu_data
*per_cu
,
10230 struct compunit_symtab
*immediate_parent
)
10234 struct compunit_symtab
*cust
;
10235 struct dwarf2_per_cu_data
*iter
;
10237 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
10240 /* This inclusion and its children have been processed. */
10245 /* Only add a CU if it has a symbol table. */
10246 cust
= get_compunit_symtab (per_cu
);
10249 /* If this is a type unit only add its symbol table if we haven't
10250 seen it yet (type unit per_cu's can share symtabs). */
10251 if (per_cu
->is_debug_types
)
10253 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
10257 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
10258 if (cust
->user
== NULL
)
10259 cust
->user
= immediate_parent
;
10264 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
10265 if (cust
->user
== NULL
)
10266 cust
->user
= immediate_parent
;
10271 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, ix
, iter
);
10274 recursively_compute_inclusions (result
, all_children
,
10275 all_type_symtabs
, iter
, cust
);
10279 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
10283 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
10285 gdb_assert (! per_cu
->is_debug_types
);
10287 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
))
10290 struct dwarf2_per_cu_data
*per_cu_iter
;
10291 struct compunit_symtab
*compunit_symtab_iter
;
10292 VEC (compunit_symtab_ptr
) *result_symtabs
= NULL
;
10293 htab_t all_children
, all_type_symtabs
;
10294 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
10296 /* If we don't have a symtab, we can just skip this case. */
10300 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10301 NULL
, xcalloc
, xfree
);
10302 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10303 NULL
, xcalloc
, xfree
);
10306 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
,
10310 recursively_compute_inclusions (&result_symtabs
, all_children
,
10311 all_type_symtabs
, per_cu_iter
,
10315 /* Now we have a transitive closure of all the included symtabs. */
10316 len
= VEC_length (compunit_symtab_ptr
, result_symtabs
);
10318 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
10319 struct compunit_symtab
*, len
+ 1);
10321 VEC_iterate (compunit_symtab_ptr
, result_symtabs
, ix
,
10322 compunit_symtab_iter
);
10324 cust
->includes
[ix
] = compunit_symtab_iter
;
10325 cust
->includes
[len
] = NULL
;
10327 VEC_free (compunit_symtab_ptr
, result_symtabs
);
10328 htab_delete (all_children
);
10329 htab_delete (all_type_symtabs
);
10333 /* Compute the 'includes' field for the symtabs of all the CUs we just
10337 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
10340 struct dwarf2_per_cu_data
*iter
;
10343 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
10347 if (! iter
->is_debug_types
)
10348 compute_compunit_symtab_includes (iter
);
10351 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
10354 /* Generate full symbol information for PER_CU, whose DIEs have
10355 already been loaded into memory. */
10358 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
10359 enum language pretend_language
)
10361 struct dwarf2_cu
*cu
= per_cu
->cu
;
10362 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10363 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10364 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10365 CORE_ADDR lowpc
, highpc
;
10366 struct compunit_symtab
*cust
;
10367 CORE_ADDR baseaddr
;
10368 struct block
*static_block
;
10371 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10374 scoped_free_pendings free_pending
;
10376 /* Clear the list here in case something was left over. */
10377 cu
->method_list
.clear ();
10379 cu
->list_in_scope
= &file_symbols
;
10381 cu
->language
= pretend_language
;
10382 cu
->language_defn
= language_def (cu
->language
);
10384 /* Do line number decoding in read_file_scope () */
10385 process_die (cu
->dies
, cu
);
10387 /* For now fudge the Go package. */
10388 if (cu
->language
== language_go
)
10389 fixup_go_packaging (cu
);
10391 /* Now that we have processed all the DIEs in the CU, all the types
10392 should be complete, and it should now be safe to compute all of the
10394 compute_delayed_physnames (cu
);
10396 if (cu
->language
== language_rust
)
10397 rust_union_quirks (cu
);
10399 /* Some compilers don't define a DW_AT_high_pc attribute for the
10400 compilation unit. If the DW_AT_high_pc is missing, synthesize
10401 it, by scanning the DIE's below the compilation unit. */
10402 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
10404 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
10405 static_block
= end_symtab_get_static_block (addr
, 0, 1);
10407 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
10408 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
10409 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
10410 addrmap to help ensure it has an accurate map of pc values belonging to
10412 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
10414 cust
= end_symtab_from_static_block (static_block
,
10415 SECT_OFF_TEXT (objfile
), 0);
10419 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
10421 /* Set symtab language to language from DW_AT_language. If the
10422 compilation is from a C file generated by language preprocessors, do
10423 not set the language if it was already deduced by start_subfile. */
10424 if (!(cu
->language
== language_c
10425 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
10426 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10428 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
10429 produce DW_AT_location with location lists but it can be possibly
10430 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
10431 there were bugs in prologue debug info, fixed later in GCC-4.5
10432 by "unwind info for epilogues" patch (which is not directly related).
10434 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
10435 needed, it would be wrong due to missing DW_AT_producer there.
10437 Still one can confuse GDB by using non-standard GCC compilation
10438 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
10440 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
10441 cust
->locations_valid
= 1;
10443 if (gcc_4_minor
>= 5)
10444 cust
->epilogue_unwind_valid
= 1;
10446 cust
->call_site_htab
= cu
->call_site_htab
;
10449 if (dwarf2_per_objfile
->using_index
)
10450 per_cu
->v
.quick
->compunit_symtab
= cust
;
10453 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10454 pst
->compunit_symtab
= cust
;
10458 /* Push it for inclusion processing later. */
10459 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
10462 /* Generate full symbol information for type unit PER_CU, whose DIEs have
10463 already been loaded into memory. */
10466 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
10467 enum language pretend_language
)
10469 struct dwarf2_cu
*cu
= per_cu
->cu
;
10470 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10471 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10472 struct compunit_symtab
*cust
;
10473 struct signatured_type
*sig_type
;
10475 gdb_assert (per_cu
->is_debug_types
);
10476 sig_type
= (struct signatured_type
*) per_cu
;
10479 scoped_free_pendings free_pending
;
10481 /* Clear the list here in case something was left over. */
10482 cu
->method_list
.clear ();
10484 cu
->list_in_scope
= &file_symbols
;
10486 cu
->language
= pretend_language
;
10487 cu
->language_defn
= language_def (cu
->language
);
10489 /* The symbol tables are set up in read_type_unit_scope. */
10490 process_die (cu
->dies
, cu
);
10492 /* For now fudge the Go package. */
10493 if (cu
->language
== language_go
)
10494 fixup_go_packaging (cu
);
10496 /* Now that we have processed all the DIEs in the CU, all the types
10497 should be complete, and it should now be safe to compute all of the
10499 compute_delayed_physnames (cu
);
10501 if (cu
->language
== language_rust
)
10502 rust_union_quirks (cu
);
10504 /* TUs share symbol tables.
10505 If this is the first TU to use this symtab, complete the construction
10506 of it with end_expandable_symtab. Otherwise, complete the addition of
10507 this TU's symbols to the existing symtab. */
10508 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
10510 cust
= end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10511 sig_type
->type_unit_group
->compunit_symtab
= cust
;
10515 /* Set symtab language to language from DW_AT_language. If the
10516 compilation is from a C file generated by language preprocessors,
10517 do not set the language if it was already deduced by
10519 if (!(cu
->language
== language_c
10520 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10521 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10526 augment_type_symtab ();
10527 cust
= sig_type
->type_unit_group
->compunit_symtab
;
10530 if (dwarf2_per_objfile
->using_index
)
10531 per_cu
->v
.quick
->compunit_symtab
= cust
;
10534 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10535 pst
->compunit_symtab
= cust
;
10540 /* Process an imported unit DIE. */
10543 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10545 struct attribute
*attr
;
10547 /* For now we don't handle imported units in type units. */
10548 if (cu
->per_cu
->is_debug_types
)
10550 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10551 " supported in type units [in module %s]"),
10552 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
10555 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10558 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10559 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10560 dwarf2_per_cu_data
*per_cu
10561 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
10562 cu
->per_cu
->dwarf2_per_objfile
);
10564 /* If necessary, add it to the queue and load its DIEs. */
10565 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
10566 load_full_comp_unit (per_cu
, cu
->language
);
10568 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
10573 /* RAII object that represents a process_die scope: i.e.,
10574 starts/finishes processing a DIE. */
10575 class process_die_scope
10578 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10579 : m_die (die
), m_cu (cu
)
10581 /* We should only be processing DIEs not already in process. */
10582 gdb_assert (!m_die
->in_process
);
10583 m_die
->in_process
= true;
10586 ~process_die_scope ()
10588 m_die
->in_process
= false;
10590 /* If we're done processing the DIE for the CU that owns the line
10591 header, we don't need the line header anymore. */
10592 if (m_cu
->line_header_die_owner
== m_die
)
10594 delete m_cu
->line_header
;
10595 m_cu
->line_header
= NULL
;
10596 m_cu
->line_header_die_owner
= NULL
;
10605 /* Process a die and its children. */
10608 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10610 process_die_scope
scope (die
, cu
);
10614 case DW_TAG_padding
:
10616 case DW_TAG_compile_unit
:
10617 case DW_TAG_partial_unit
:
10618 read_file_scope (die
, cu
);
10620 case DW_TAG_type_unit
:
10621 read_type_unit_scope (die
, cu
);
10623 case DW_TAG_subprogram
:
10624 case DW_TAG_inlined_subroutine
:
10625 read_func_scope (die
, cu
);
10627 case DW_TAG_lexical_block
:
10628 case DW_TAG_try_block
:
10629 case DW_TAG_catch_block
:
10630 read_lexical_block_scope (die
, cu
);
10632 case DW_TAG_call_site
:
10633 case DW_TAG_GNU_call_site
:
10634 read_call_site_scope (die
, cu
);
10636 case DW_TAG_class_type
:
10637 case DW_TAG_interface_type
:
10638 case DW_TAG_structure_type
:
10639 case DW_TAG_union_type
:
10640 process_structure_scope (die
, cu
);
10642 case DW_TAG_enumeration_type
:
10643 process_enumeration_scope (die
, cu
);
10646 /* These dies have a type, but processing them does not create
10647 a symbol or recurse to process the children. Therefore we can
10648 read them on-demand through read_type_die. */
10649 case DW_TAG_subroutine_type
:
10650 case DW_TAG_set_type
:
10651 case DW_TAG_array_type
:
10652 case DW_TAG_pointer_type
:
10653 case DW_TAG_ptr_to_member_type
:
10654 case DW_TAG_reference_type
:
10655 case DW_TAG_rvalue_reference_type
:
10656 case DW_TAG_string_type
:
10659 case DW_TAG_base_type
:
10660 case DW_TAG_subrange_type
:
10661 case DW_TAG_typedef
:
10662 /* Add a typedef symbol for the type definition, if it has a
10664 new_symbol (die
, read_type_die (die
, cu
), cu
);
10666 case DW_TAG_common_block
:
10667 read_common_block (die
, cu
);
10669 case DW_TAG_common_inclusion
:
10671 case DW_TAG_namespace
:
10672 cu
->processing_has_namespace_info
= 1;
10673 read_namespace (die
, cu
);
10675 case DW_TAG_module
:
10676 cu
->processing_has_namespace_info
= 1;
10677 read_module (die
, cu
);
10679 case DW_TAG_imported_declaration
:
10680 cu
->processing_has_namespace_info
= 1;
10681 if (read_namespace_alias (die
, cu
))
10683 /* The declaration is not a global namespace alias: fall through. */
10684 case DW_TAG_imported_module
:
10685 cu
->processing_has_namespace_info
= 1;
10686 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10687 || cu
->language
!= language_fortran
))
10688 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
10689 dwarf_tag_name (die
->tag
));
10690 read_import_statement (die
, cu
);
10693 case DW_TAG_imported_unit
:
10694 process_imported_unit_die (die
, cu
);
10697 case DW_TAG_variable
:
10698 read_variable (die
, cu
);
10702 new_symbol (die
, NULL
, cu
);
10707 /* DWARF name computation. */
10709 /* A helper function for dwarf2_compute_name which determines whether DIE
10710 needs to have the name of the scope prepended to the name listed in the
10714 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10716 struct attribute
*attr
;
10720 case DW_TAG_namespace
:
10721 case DW_TAG_typedef
:
10722 case DW_TAG_class_type
:
10723 case DW_TAG_interface_type
:
10724 case DW_TAG_structure_type
:
10725 case DW_TAG_union_type
:
10726 case DW_TAG_enumeration_type
:
10727 case DW_TAG_enumerator
:
10728 case DW_TAG_subprogram
:
10729 case DW_TAG_inlined_subroutine
:
10730 case DW_TAG_member
:
10731 case DW_TAG_imported_declaration
:
10734 case DW_TAG_variable
:
10735 case DW_TAG_constant
:
10736 /* We only need to prefix "globally" visible variables. These include
10737 any variable marked with DW_AT_external or any variable that
10738 lives in a namespace. [Variables in anonymous namespaces
10739 require prefixing, but they are not DW_AT_external.] */
10741 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10743 struct dwarf2_cu
*spec_cu
= cu
;
10745 return die_needs_namespace (die_specification (die
, &spec_cu
),
10749 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10750 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10751 && die
->parent
->tag
!= DW_TAG_module
)
10753 /* A variable in a lexical block of some kind does not need a
10754 namespace, even though in C++ such variables may be external
10755 and have a mangled name. */
10756 if (die
->parent
->tag
== DW_TAG_lexical_block
10757 || die
->parent
->tag
== DW_TAG_try_block
10758 || die
->parent
->tag
== DW_TAG_catch_block
10759 || die
->parent
->tag
== DW_TAG_subprogram
)
10768 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10769 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10770 defined for the given DIE. */
10772 static struct attribute
*
10773 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10775 struct attribute
*attr
;
10777 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10779 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10784 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10785 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10786 defined for the given DIE. */
10788 static const char *
10789 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10791 const char *linkage_name
;
10793 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10794 if (linkage_name
== NULL
)
10795 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10797 return linkage_name
;
10800 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10801 compute the physname for the object, which include a method's:
10802 - formal parameters (C++),
10803 - receiver type (Go),
10805 The term "physname" is a bit confusing.
10806 For C++, for example, it is the demangled name.
10807 For Go, for example, it's the mangled name.
10809 For Ada, return the DIE's linkage name rather than the fully qualified
10810 name. PHYSNAME is ignored..
10812 The result is allocated on the objfile_obstack and canonicalized. */
10814 static const char *
10815 dwarf2_compute_name (const char *name
,
10816 struct die_info
*die
, struct dwarf2_cu
*cu
,
10819 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10822 name
= dwarf2_name (die
, cu
);
10824 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10825 but otherwise compute it by typename_concat inside GDB.
10826 FIXME: Actually this is not really true, or at least not always true.
10827 It's all very confusing. SYMBOL_SET_NAMES doesn't try to demangle
10828 Fortran names because there is no mangling standard. So new_symbol
10829 will set the demangled name to the result of dwarf2_full_name, and it is
10830 the demangled name that GDB uses if it exists. */
10831 if (cu
->language
== language_ada
10832 || (cu
->language
== language_fortran
&& physname
))
10834 /* For Ada unit, we prefer the linkage name over the name, as
10835 the former contains the exported name, which the user expects
10836 to be able to reference. Ideally, we want the user to be able
10837 to reference this entity using either natural or linkage name,
10838 but we haven't started looking at this enhancement yet. */
10839 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10841 if (linkage_name
!= NULL
)
10842 return linkage_name
;
10845 /* These are the only languages we know how to qualify names in. */
10847 && (cu
->language
== language_cplus
10848 || cu
->language
== language_fortran
|| cu
->language
== language_d
10849 || cu
->language
== language_rust
))
10851 if (die_needs_namespace (die
, cu
))
10853 const char *prefix
;
10854 const char *canonical_name
= NULL
;
10858 prefix
= determine_prefix (die
, cu
);
10859 if (*prefix
!= '\0')
10861 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
10864 buf
.puts (prefixed_name
);
10865 xfree (prefixed_name
);
10870 /* Template parameters may be specified in the DIE's DW_AT_name, or
10871 as children with DW_TAG_template_type_param or
10872 DW_TAG_value_type_param. If the latter, add them to the name
10873 here. If the name already has template parameters, then
10874 skip this step; some versions of GCC emit both, and
10875 it is more efficient to use the pre-computed name.
10877 Something to keep in mind about this process: it is very
10878 unlikely, or in some cases downright impossible, to produce
10879 something that will match the mangled name of a function.
10880 If the definition of the function has the same debug info,
10881 we should be able to match up with it anyway. But fallbacks
10882 using the minimal symbol, for instance to find a method
10883 implemented in a stripped copy of libstdc++, will not work.
10884 If we do not have debug info for the definition, we will have to
10885 match them up some other way.
10887 When we do name matching there is a related problem with function
10888 templates; two instantiated function templates are allowed to
10889 differ only by their return types, which we do not add here. */
10891 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10893 struct attribute
*attr
;
10894 struct die_info
*child
;
10897 die
->building_fullname
= 1;
10899 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10903 const gdb_byte
*bytes
;
10904 struct dwarf2_locexpr_baton
*baton
;
10907 if (child
->tag
!= DW_TAG_template_type_param
10908 && child
->tag
!= DW_TAG_template_value_param
)
10919 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10922 complaint (&symfile_complaints
,
10923 _("template parameter missing DW_AT_type"));
10924 buf
.puts ("UNKNOWN_TYPE");
10927 type
= die_type (child
, cu
);
10929 if (child
->tag
== DW_TAG_template_type_param
)
10931 c_print_type (type
, "", &buf
, -1, 0, &type_print_raw_options
);
10935 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10938 complaint (&symfile_complaints
,
10939 _("template parameter missing "
10940 "DW_AT_const_value"));
10941 buf
.puts ("UNKNOWN_VALUE");
10945 dwarf2_const_value_attr (attr
, type
, name
,
10946 &cu
->comp_unit_obstack
, cu
,
10947 &value
, &bytes
, &baton
);
10949 if (TYPE_NOSIGN (type
))
10950 /* GDB prints characters as NUMBER 'CHAR'. If that's
10951 changed, this can use value_print instead. */
10952 c_printchar (value
, type
, &buf
);
10955 struct value_print_options opts
;
10958 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10962 else if (bytes
!= NULL
)
10964 v
= allocate_value (type
);
10965 memcpy (value_contents_writeable (v
), bytes
,
10966 TYPE_LENGTH (type
));
10969 v
= value_from_longest (type
, value
);
10971 /* Specify decimal so that we do not depend on
10973 get_formatted_print_options (&opts
, 'd');
10975 value_print (v
, &buf
, &opts
);
10981 die
->building_fullname
= 0;
10985 /* Close the argument list, with a space if necessary
10986 (nested templates). */
10987 if (!buf
.empty () && buf
.string ().back () == '>')
10994 /* For C++ methods, append formal parameter type
10995 information, if PHYSNAME. */
10997 if (physname
&& die
->tag
== DW_TAG_subprogram
10998 && cu
->language
== language_cplus
)
11000 struct type
*type
= read_type_die (die
, cu
);
11002 c_type_print_args (type
, &buf
, 1, cu
->language
,
11003 &type_print_raw_options
);
11005 if (cu
->language
== language_cplus
)
11007 /* Assume that an artificial first parameter is
11008 "this", but do not crash if it is not. RealView
11009 marks unnamed (and thus unused) parameters as
11010 artificial; there is no way to differentiate
11012 if (TYPE_NFIELDS (type
) > 0
11013 && TYPE_FIELD_ARTIFICIAL (type
, 0)
11014 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
11015 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
11017 buf
.puts (" const");
11021 const std::string
&intermediate_name
= buf
.string ();
11023 if (cu
->language
== language_cplus
)
11025 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
11026 &objfile
->per_bfd
->storage_obstack
);
11028 /* If we only computed INTERMEDIATE_NAME, or if
11029 INTERMEDIATE_NAME is already canonical, then we need to
11030 copy it to the appropriate obstack. */
11031 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
11032 name
= ((const char *)
11033 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
11034 intermediate_name
.c_str (),
11035 intermediate_name
.length ()));
11037 name
= canonical_name
;
11044 /* Return the fully qualified name of DIE, based on its DW_AT_name.
11045 If scope qualifiers are appropriate they will be added. The result
11046 will be allocated on the storage_obstack, or NULL if the DIE does
11047 not have a name. NAME may either be from a previous call to
11048 dwarf2_name or NULL.
11050 The output string will be canonicalized (if C++). */
11052 static const char *
11053 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11055 return dwarf2_compute_name (name
, die
, cu
, 0);
11058 /* Construct a physname for the given DIE in CU. NAME may either be
11059 from a previous call to dwarf2_name or NULL. The result will be
11060 allocated on the objfile_objstack or NULL if the DIE does not have a
11063 The output string will be canonicalized (if C++). */
11065 static const char *
11066 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11068 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11069 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
11072 /* In this case dwarf2_compute_name is just a shortcut not building anything
11074 if (!die_needs_namespace (die
, cu
))
11075 return dwarf2_compute_name (name
, die
, cu
, 1);
11077 mangled
= dw2_linkage_name (die
, cu
);
11079 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
11080 See https://github.com/rust-lang/rust/issues/32925. */
11081 if (cu
->language
== language_rust
&& mangled
!= NULL
11082 && strchr (mangled
, '{') != NULL
)
11085 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
11087 gdb::unique_xmalloc_ptr
<char> demangled
;
11088 if (mangled
!= NULL
)
11091 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
11093 /* Do nothing (do not demangle the symbol name). */
11095 else if (cu
->language
== language_go
)
11097 /* This is a lie, but we already lie to the caller new_symbol.
11098 new_symbol assumes we return the mangled name.
11099 This just undoes that lie until things are cleaned up. */
11103 /* Use DMGL_RET_DROP for C++ template functions to suppress
11104 their return type. It is easier for GDB users to search
11105 for such functions as `name(params)' than `long name(params)'.
11106 In such case the minimal symbol names do not match the full
11107 symbol names but for template functions there is never a need
11108 to look up their definition from their declaration so
11109 the only disadvantage remains the minimal symbol variant
11110 `long name(params)' does not have the proper inferior type. */
11111 demangled
.reset (gdb_demangle (mangled
,
11112 (DMGL_PARAMS
| DMGL_ANSI
11113 | DMGL_RET_DROP
)));
11116 canon
= demangled
.get ();
11124 if (canon
== NULL
|| check_physname
)
11126 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
11128 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
11130 /* It may not mean a bug in GDB. The compiler could also
11131 compute DW_AT_linkage_name incorrectly. But in such case
11132 GDB would need to be bug-to-bug compatible. */
11134 complaint (&symfile_complaints
,
11135 _("Computed physname <%s> does not match demangled <%s> "
11136 "(from linkage <%s>) - DIE at %s [in module %s]"),
11137 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
11138 objfile_name (objfile
));
11140 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
11141 is available here - over computed PHYSNAME. It is safer
11142 against both buggy GDB and buggy compilers. */
11156 retval
= ((const char *)
11157 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
11158 retval
, strlen (retval
)));
11163 /* Inspect DIE in CU for a namespace alias. If one exists, record
11164 a new symbol for it.
11166 Returns 1 if a namespace alias was recorded, 0 otherwise. */
11169 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
11171 struct attribute
*attr
;
11173 /* If the die does not have a name, this is not a namespace
11175 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11179 struct die_info
*d
= die
;
11180 struct dwarf2_cu
*imported_cu
= cu
;
11182 /* If the compiler has nested DW_AT_imported_declaration DIEs,
11183 keep inspecting DIEs until we hit the underlying import. */
11184 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
11185 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
11187 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
11191 d
= follow_die_ref (d
, attr
, &imported_cu
);
11192 if (d
->tag
!= DW_TAG_imported_declaration
)
11196 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
11198 complaint (&symfile_complaints
,
11199 _("DIE at %s has too many recursively imported "
11200 "declarations"), sect_offset_str (d
->sect_off
));
11207 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
11209 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
11210 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
11212 /* This declaration is a global namespace alias. Add
11213 a symbol for it whose type is the aliased namespace. */
11214 new_symbol (die
, type
, cu
);
11223 /* Return the using directives repository (global or local?) to use in the
11224 current context for LANGUAGE.
11226 For Ada, imported declarations can materialize renamings, which *may* be
11227 global. However it is impossible (for now?) in DWARF to distinguish
11228 "external" imported declarations and "static" ones. As all imported
11229 declarations seem to be static in all other languages, make them all CU-wide
11230 global only in Ada. */
11232 static struct using_direct
**
11233 using_directives (enum language language
)
11235 if (language
== language_ada
&& context_stack_depth
== 0)
11236 return &global_using_directives
;
11238 return &local_using_directives
;
11241 /* Read the import statement specified by the given die and record it. */
11244 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
11246 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11247 struct attribute
*import_attr
;
11248 struct die_info
*imported_die
, *child_die
;
11249 struct dwarf2_cu
*imported_cu
;
11250 const char *imported_name
;
11251 const char *imported_name_prefix
;
11252 const char *canonical_name
;
11253 const char *import_alias
;
11254 const char *imported_declaration
= NULL
;
11255 const char *import_prefix
;
11256 std::vector
<const char *> excludes
;
11258 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
11259 if (import_attr
== NULL
)
11261 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
11262 dwarf_tag_name (die
->tag
));
11267 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
11268 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11269 if (imported_name
== NULL
)
11271 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
11273 The import in the following code:
11287 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
11288 <52> DW_AT_decl_file : 1
11289 <53> DW_AT_decl_line : 6
11290 <54> DW_AT_import : <0x75>
11291 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
11292 <59> DW_AT_name : B
11293 <5b> DW_AT_decl_file : 1
11294 <5c> DW_AT_decl_line : 2
11295 <5d> DW_AT_type : <0x6e>
11297 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
11298 <76> DW_AT_byte_size : 4
11299 <77> DW_AT_encoding : 5 (signed)
11301 imports the wrong die ( 0x75 instead of 0x58 ).
11302 This case will be ignored until the gcc bug is fixed. */
11306 /* Figure out the local name after import. */
11307 import_alias
= dwarf2_name (die
, cu
);
11309 /* Figure out where the statement is being imported to. */
11310 import_prefix
= determine_prefix (die
, cu
);
11312 /* Figure out what the scope of the imported die is and prepend it
11313 to the name of the imported die. */
11314 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
11316 if (imported_die
->tag
!= DW_TAG_namespace
11317 && imported_die
->tag
!= DW_TAG_module
)
11319 imported_declaration
= imported_name
;
11320 canonical_name
= imported_name_prefix
;
11322 else if (strlen (imported_name_prefix
) > 0)
11323 canonical_name
= obconcat (&objfile
->objfile_obstack
,
11324 imported_name_prefix
,
11325 (cu
->language
== language_d
? "." : "::"),
11326 imported_name
, (char *) NULL
);
11328 canonical_name
= imported_name
;
11330 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
11331 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11332 child_die
= sibling_die (child_die
))
11334 /* DWARF-4: A Fortran use statement with a “rename list” may be
11335 represented by an imported module entry with an import attribute
11336 referring to the module and owned entries corresponding to those
11337 entities that are renamed as part of being imported. */
11339 if (child_die
->tag
!= DW_TAG_imported_declaration
)
11341 complaint (&symfile_complaints
,
11342 _("child DW_TAG_imported_declaration expected "
11343 "- DIE at %s [in module %s]"),
11344 sect_offset_str (child_die
->sect_off
),
11345 objfile_name (objfile
));
11349 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
11350 if (import_attr
== NULL
)
11352 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
11353 dwarf_tag_name (child_die
->tag
));
11358 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
11360 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11361 if (imported_name
== NULL
)
11363 complaint (&symfile_complaints
,
11364 _("child DW_TAG_imported_declaration has unknown "
11365 "imported name - DIE at %s [in module %s]"),
11366 sect_offset_str (child_die
->sect_off
),
11367 objfile_name (objfile
));
11371 excludes
.push_back (imported_name
);
11373 process_die (child_die
, cu
);
11376 add_using_directive (using_directives (cu
->language
),
11380 imported_declaration
,
11383 &objfile
->objfile_obstack
);
11386 /* ICC<14 does not output the required DW_AT_declaration on incomplete
11387 types, but gives them a size of zero. Starting with version 14,
11388 ICC is compatible with GCC. */
11391 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
11393 if (!cu
->checked_producer
)
11394 check_producer (cu
);
11396 return cu
->producer_is_icc_lt_14
;
11399 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
11400 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
11401 this, it was first present in GCC release 4.3.0. */
11404 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
11406 if (!cu
->checked_producer
)
11407 check_producer (cu
);
11409 return cu
->producer_is_gcc_lt_4_3
;
11412 static file_and_directory
11413 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
11415 file_and_directory res
;
11417 /* Find the filename. Do not use dwarf2_name here, since the filename
11418 is not a source language identifier. */
11419 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
11420 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
11422 if (res
.comp_dir
== NULL
11423 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
11424 && IS_ABSOLUTE_PATH (res
.name
))
11426 res
.comp_dir_storage
= ldirname (res
.name
);
11427 if (!res
.comp_dir_storage
.empty ())
11428 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
11430 if (res
.comp_dir
!= NULL
)
11432 /* Irix 6.2 native cc prepends <machine>.: to the compilation
11433 directory, get rid of it. */
11434 const char *cp
= strchr (res
.comp_dir
, ':');
11436 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
11437 res
.comp_dir
= cp
+ 1;
11440 if (res
.name
== NULL
)
11441 res
.name
= "<unknown>";
11446 /* Handle DW_AT_stmt_list for a compilation unit.
11447 DIE is the DW_TAG_compile_unit die for CU.
11448 COMP_DIR is the compilation directory. LOWPC is passed to
11449 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11452 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11453 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
11455 struct dwarf2_per_objfile
*dwarf2_per_objfile
11456 = cu
->per_cu
->dwarf2_per_objfile
;
11457 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11458 struct attribute
*attr
;
11459 struct line_header line_header_local
;
11460 hashval_t line_header_local_hash
;
11462 int decode_mapping
;
11464 gdb_assert (! cu
->per_cu
->is_debug_types
);
11466 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11470 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11472 /* The line header hash table is only created if needed (it exists to
11473 prevent redundant reading of the line table for partial_units).
11474 If we're given a partial_unit, we'll need it. If we're given a
11475 compile_unit, then use the line header hash table if it's already
11476 created, but don't create one just yet. */
11478 if (dwarf2_per_objfile
->line_header_hash
== NULL
11479 && die
->tag
== DW_TAG_partial_unit
)
11481 dwarf2_per_objfile
->line_header_hash
11482 = htab_create_alloc_ex (127, line_header_hash_voidp
,
11483 line_header_eq_voidp
,
11484 free_line_header_voidp
,
11485 &objfile
->objfile_obstack
,
11486 hashtab_obstack_allocate
,
11487 dummy_obstack_deallocate
);
11490 line_header_local
.sect_off
= line_offset
;
11491 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11492 line_header_local_hash
= line_header_hash (&line_header_local
);
11493 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
11495 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11496 &line_header_local
,
11497 line_header_local_hash
, NO_INSERT
);
11499 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11500 is not present in *SLOT (since if there is something in *SLOT then
11501 it will be for a partial_unit). */
11502 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11504 gdb_assert (*slot
!= NULL
);
11505 cu
->line_header
= (struct line_header
*) *slot
;
11510 /* dwarf_decode_line_header does not yet provide sufficient information.
11511 We always have to call also dwarf_decode_lines for it. */
11512 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11516 cu
->line_header
= lh
.release ();
11517 cu
->line_header_die_owner
= die
;
11519 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
11523 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11524 &line_header_local
,
11525 line_header_local_hash
, INSERT
);
11526 gdb_assert (slot
!= NULL
);
11528 if (slot
!= NULL
&& *slot
== NULL
)
11530 /* This newly decoded line number information unit will be owned
11531 by line_header_hash hash table. */
11532 *slot
= cu
->line_header
;
11533 cu
->line_header_die_owner
= NULL
;
11537 /* We cannot free any current entry in (*slot) as that struct line_header
11538 may be already used by multiple CUs. Create only temporary decoded
11539 line_header for this CU - it may happen at most once for each line
11540 number information unit. And if we're not using line_header_hash
11541 then this is what we want as well. */
11542 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11544 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11545 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11550 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11553 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11555 struct dwarf2_per_objfile
*dwarf2_per_objfile
11556 = cu
->per_cu
->dwarf2_per_objfile
;
11557 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11558 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11559 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11560 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11561 struct attribute
*attr
;
11562 struct die_info
*child_die
;
11563 CORE_ADDR baseaddr
;
11565 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11567 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11569 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11570 from finish_block. */
11571 if (lowpc
== ((CORE_ADDR
) -1))
11573 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11575 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11577 prepare_one_comp_unit (cu
, die
, cu
->language
);
11579 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11580 standardised yet. As a workaround for the language detection we fall
11581 back to the DW_AT_producer string. */
11582 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11583 cu
->language
= language_opencl
;
11585 /* Similar hack for Go. */
11586 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11587 set_cu_language (DW_LANG_Go
, cu
);
11589 dwarf2_start_symtab (cu
, fnd
.name
, fnd
.comp_dir
, lowpc
);
11591 /* Decode line number information if present. We do this before
11592 processing child DIEs, so that the line header table is available
11593 for DW_AT_decl_file. */
11594 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11596 /* Process all dies in compilation unit. */
11597 if (die
->child
!= NULL
)
11599 child_die
= die
->child
;
11600 while (child_die
&& child_die
->tag
)
11602 process_die (child_die
, cu
);
11603 child_die
= sibling_die (child_die
);
11607 /* Decode macro information, if present. Dwarf 2 macro information
11608 refers to information in the line number info statement program
11609 header, so we can only read it if we've read the header
11611 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11613 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11614 if (attr
&& cu
->line_header
)
11616 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11617 complaint (&symfile_complaints
,
11618 _("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11620 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11624 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11625 if (attr
&& cu
->line_header
)
11627 unsigned int macro_offset
= DW_UNSND (attr
);
11629 dwarf_decode_macros (cu
, macro_offset
, 0);
11634 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
11635 Create the set of symtabs used by this TU, or if this TU is sharing
11636 symtabs with another TU and the symtabs have already been created
11637 then restore those symtabs in the line header.
11638 We don't need the pc/line-number mapping for type units. */
11641 setup_type_unit_groups (struct die_info
*die
, struct dwarf2_cu
*cu
)
11643 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
11644 struct type_unit_group
*tu_group
;
11646 struct attribute
*attr
;
11648 struct signatured_type
*sig_type
;
11650 gdb_assert (per_cu
->is_debug_types
);
11651 sig_type
= (struct signatured_type
*) per_cu
;
11653 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11655 /* If we're using .gdb_index (includes -readnow) then
11656 per_cu->type_unit_group may not have been set up yet. */
11657 if (sig_type
->type_unit_group
== NULL
)
11658 sig_type
->type_unit_group
= get_type_unit_group (cu
, attr
);
11659 tu_group
= sig_type
->type_unit_group
;
11661 /* If we've already processed this stmt_list there's no real need to
11662 do it again, we could fake it and just recreate the part we need
11663 (file name,index -> symtab mapping). If data shows this optimization
11664 is useful we can do it then. */
11665 first_time
= tu_group
->compunit_symtab
== NULL
;
11667 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11672 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11673 lh
= dwarf_decode_line_header (line_offset
, cu
);
11678 dwarf2_start_symtab (cu
, "", NULL
, 0);
11681 gdb_assert (tu_group
->symtabs
== NULL
);
11682 restart_symtab (tu_group
->compunit_symtab
, "", 0);
11687 cu
->line_header
= lh
.release ();
11688 cu
->line_header_die_owner
= die
;
11692 struct compunit_symtab
*cust
= dwarf2_start_symtab (cu
, "", NULL
, 0);
11694 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11695 still initializing it, and our caller (a few levels up)
11696 process_full_type_unit still needs to know if this is the first
11699 tu_group
->num_symtabs
= cu
->line_header
->file_names
.size ();
11700 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
11701 cu
->line_header
->file_names
.size ());
11703 for (i
= 0; i
< cu
->line_header
->file_names
.size (); ++i
)
11705 file_entry
&fe
= cu
->line_header
->file_names
[i
];
11707 dwarf2_start_subfile (fe
.name
, fe
.include_dir (cu
->line_header
));
11709 if (current_subfile
->symtab
== NULL
)
11711 /* NOTE: start_subfile will recognize when it's been
11712 passed a file it has already seen. So we can't
11713 assume there's a simple mapping from
11714 cu->line_header->file_names to subfiles, plus
11715 cu->line_header->file_names may contain dups. */
11716 current_subfile
->symtab
11717 = allocate_symtab (cust
, current_subfile
->name
);
11720 fe
.symtab
= current_subfile
->symtab
;
11721 tu_group
->symtabs
[i
] = fe
.symtab
;
11726 restart_symtab (tu_group
->compunit_symtab
, "", 0);
11728 for (i
= 0; i
< cu
->line_header
->file_names
.size (); ++i
)
11730 file_entry
&fe
= cu
->line_header
->file_names
[i
];
11732 fe
.symtab
= tu_group
->symtabs
[i
];
11736 /* The main symtab is allocated last. Type units don't have DW_AT_name
11737 so they don't have a "real" (so to speak) symtab anyway.
11738 There is later code that will assign the main symtab to all symbols
11739 that don't have one. We need to handle the case of a symbol with a
11740 missing symtab (DW_AT_decl_file) anyway. */
11743 /* Process DW_TAG_type_unit.
11744 For TUs we want to skip the first top level sibling if it's not the
11745 actual type being defined by this TU. In this case the first top
11746 level sibling is there to provide context only. */
11749 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11751 struct die_info
*child_die
;
11753 prepare_one_comp_unit (cu
, die
, language_minimal
);
11755 /* Initialize (or reinitialize) the machinery for building symtabs.
11756 We do this before processing child DIEs, so that the line header table
11757 is available for DW_AT_decl_file. */
11758 setup_type_unit_groups (die
, cu
);
11760 if (die
->child
!= NULL
)
11762 child_die
= die
->child
;
11763 while (child_die
&& child_die
->tag
)
11765 process_die (child_die
, cu
);
11766 child_die
= sibling_die (child_die
);
11773 http://gcc.gnu.org/wiki/DebugFission
11774 http://gcc.gnu.org/wiki/DebugFissionDWP
11776 To simplify handling of both DWO files ("object" files with the DWARF info)
11777 and DWP files (a file with the DWOs packaged up into one file), we treat
11778 DWP files as having a collection of virtual DWO files. */
11781 hash_dwo_file (const void *item
)
11783 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11786 hash
= htab_hash_string (dwo_file
->dwo_name
);
11787 if (dwo_file
->comp_dir
!= NULL
)
11788 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11793 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11795 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11796 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11798 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11800 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11801 return lhs
->comp_dir
== rhs
->comp_dir
;
11802 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11805 /* Allocate a hash table for DWO files. */
11808 allocate_dwo_file_hash_table (struct objfile
*objfile
)
11810 return htab_create_alloc_ex (41,
11814 &objfile
->objfile_obstack
,
11815 hashtab_obstack_allocate
,
11816 dummy_obstack_deallocate
);
11819 /* Lookup DWO file DWO_NAME. */
11822 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11823 const char *dwo_name
,
11824 const char *comp_dir
)
11826 struct dwo_file find_entry
;
11829 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11830 dwarf2_per_objfile
->dwo_files
11831 = allocate_dwo_file_hash_table (dwarf2_per_objfile
->objfile
);
11833 memset (&find_entry
, 0, sizeof (find_entry
));
11834 find_entry
.dwo_name
= dwo_name
;
11835 find_entry
.comp_dir
= comp_dir
;
11836 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
11842 hash_dwo_unit (const void *item
)
11844 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11846 /* This drops the top 32 bits of the id, but is ok for a hash. */
11847 return dwo_unit
->signature
;
11851 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11853 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11854 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11856 /* The signature is assumed to be unique within the DWO file.
11857 So while object file CU dwo_id's always have the value zero,
11858 that's OK, assuming each object file DWO file has only one CU,
11859 and that's the rule for now. */
11860 return lhs
->signature
== rhs
->signature
;
11863 /* Allocate a hash table for DWO CUs,TUs.
11864 There is one of these tables for each of CUs,TUs for each DWO file. */
11867 allocate_dwo_unit_table (struct objfile
*objfile
)
11869 /* Start out with a pretty small number.
11870 Generally DWO files contain only one CU and maybe some TUs. */
11871 return htab_create_alloc_ex (3,
11875 &objfile
->objfile_obstack
,
11876 hashtab_obstack_allocate
,
11877 dummy_obstack_deallocate
);
11880 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
11882 struct create_dwo_cu_data
11884 struct dwo_file
*dwo_file
;
11885 struct dwo_unit dwo_unit
;
11888 /* die_reader_func for create_dwo_cu. */
11891 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11892 const gdb_byte
*info_ptr
,
11893 struct die_info
*comp_unit_die
,
11897 struct dwarf2_cu
*cu
= reader
->cu
;
11898 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11899 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11900 struct create_dwo_cu_data
*data
= (struct create_dwo_cu_data
*) datap
;
11901 struct dwo_file
*dwo_file
= data
->dwo_file
;
11902 struct dwo_unit
*dwo_unit
= &data
->dwo_unit
;
11903 struct attribute
*attr
;
11905 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
11908 complaint (&symfile_complaints
,
11909 _("Dwarf Error: debug entry at offset %s is missing"
11910 " its dwo_id [in module %s]"),
11911 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11915 dwo_unit
->dwo_file
= dwo_file
;
11916 dwo_unit
->signature
= DW_UNSND (attr
);
11917 dwo_unit
->section
= section
;
11918 dwo_unit
->sect_off
= sect_off
;
11919 dwo_unit
->length
= cu
->per_cu
->length
;
11921 if (dwarf_read_debug
)
11922 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11923 sect_offset_str (sect_off
),
11924 hex_string (dwo_unit
->signature
));
11927 /* Create the dwo_units for the CUs in a DWO_FILE.
11928 Note: This function processes DWO files only, not DWP files. */
11931 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11932 struct dwo_file
&dwo_file
, dwarf2_section_info
§ion
,
11935 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11936 const gdb_byte
*info_ptr
, *end_ptr
;
11938 dwarf2_read_section (objfile
, §ion
);
11939 info_ptr
= section
.buffer
;
11941 if (info_ptr
== NULL
)
11944 if (dwarf_read_debug
)
11946 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11947 get_section_name (§ion
),
11948 get_section_file_name (§ion
));
11951 end_ptr
= info_ptr
+ section
.size
;
11952 while (info_ptr
< end_ptr
)
11954 struct dwarf2_per_cu_data per_cu
;
11955 struct create_dwo_cu_data create_dwo_cu_data
;
11956 struct dwo_unit
*dwo_unit
;
11958 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11960 memset (&create_dwo_cu_data
.dwo_unit
, 0,
11961 sizeof (create_dwo_cu_data
.dwo_unit
));
11962 memset (&per_cu
, 0, sizeof (per_cu
));
11963 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11964 per_cu
.is_debug_types
= 0;
11965 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11966 per_cu
.section
= §ion
;
11967 create_dwo_cu_data
.dwo_file
= &dwo_file
;
11969 init_cutu_and_read_dies_no_follow (
11970 &per_cu
, &dwo_file
, create_dwo_cu_reader
, &create_dwo_cu_data
);
11971 info_ptr
+= per_cu
.length
;
11973 // If the unit could not be parsed, skip it.
11974 if (create_dwo_cu_data
.dwo_unit
.dwo_file
== NULL
)
11977 if (cus_htab
== NULL
)
11978 cus_htab
= allocate_dwo_unit_table (objfile
);
11980 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11981 *dwo_unit
= create_dwo_cu_data
.dwo_unit
;
11982 slot
= htab_find_slot (cus_htab
, dwo_unit
, INSERT
);
11983 gdb_assert (slot
!= NULL
);
11986 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11987 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11989 complaint (&symfile_complaints
,
11990 _("debug cu entry at offset %s is duplicate to"
11991 " the entry at offset %s, signature %s"),
11992 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11993 hex_string (dwo_unit
->signature
));
11995 *slot
= (void *)dwo_unit
;
11999 /* DWP file .debug_{cu,tu}_index section format:
12000 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
12004 Both index sections have the same format, and serve to map a 64-bit
12005 signature to a set of section numbers. Each section begins with a header,
12006 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
12007 indexes, and a pool of 32-bit section numbers. The index sections will be
12008 aligned at 8-byte boundaries in the file.
12010 The index section header consists of:
12012 V, 32 bit version number
12014 N, 32 bit number of compilation units or type units in the index
12015 M, 32 bit number of slots in the hash table
12017 Numbers are recorded using the byte order of the application binary.
12019 The hash table begins at offset 16 in the section, and consists of an array
12020 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
12021 order of the application binary). Unused slots in the hash table are 0.
12022 (We rely on the extreme unlikeliness of a signature being exactly 0.)
12024 The parallel table begins immediately after the hash table
12025 (at offset 16 + 8 * M from the beginning of the section), and consists of an
12026 array of 32-bit indexes (using the byte order of the application binary),
12027 corresponding 1-1 with slots in the hash table. Each entry in the parallel
12028 table contains a 32-bit index into the pool of section numbers. For unused
12029 hash table slots, the corresponding entry in the parallel table will be 0.
12031 The pool of section numbers begins immediately following the hash table
12032 (at offset 16 + 12 * M from the beginning of the section). The pool of
12033 section numbers consists of an array of 32-bit words (using the byte order
12034 of the application binary). Each item in the array is indexed starting
12035 from 0. The hash table entry provides the index of the first section
12036 number in the set. Additional section numbers in the set follow, and the
12037 set is terminated by a 0 entry (section number 0 is not used in ELF).
12039 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
12040 section must be the first entry in the set, and the .debug_abbrev.dwo must
12041 be the second entry. Other members of the set may follow in any order.
12047 DWP Version 2 combines all the .debug_info, etc. sections into one,
12048 and the entries in the index tables are now offsets into these sections.
12049 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
12052 Index Section Contents:
12054 Hash Table of Signatures dwp_hash_table.hash_table
12055 Parallel Table of Indices dwp_hash_table.unit_table
12056 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
12057 Table of Section Sizes dwp_hash_table.v2.sizes
12059 The index section header consists of:
12061 V, 32 bit version number
12062 L, 32 bit number of columns in the table of section offsets
12063 N, 32 bit number of compilation units or type units in the index
12064 M, 32 bit number of slots in the hash table
12066 Numbers are recorded using the byte order of the application binary.
12068 The hash table has the same format as version 1.
12069 The parallel table of indices has the same format as version 1,
12070 except that the entries are origin-1 indices into the table of sections
12071 offsets and the table of section sizes.
12073 The table of offsets begins immediately following the parallel table
12074 (at offset 16 + 12 * M from the beginning of the section). The table is
12075 a two-dimensional array of 32-bit words (using the byte order of the
12076 application binary), with L columns and N+1 rows, in row-major order.
12077 Each row in the array is indexed starting from 0. The first row provides
12078 a key to the remaining rows: each column in this row provides an identifier
12079 for a debug section, and the offsets in the same column of subsequent rows
12080 refer to that section. The section identifiers are:
12082 DW_SECT_INFO 1 .debug_info.dwo
12083 DW_SECT_TYPES 2 .debug_types.dwo
12084 DW_SECT_ABBREV 3 .debug_abbrev.dwo
12085 DW_SECT_LINE 4 .debug_line.dwo
12086 DW_SECT_LOC 5 .debug_loc.dwo
12087 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
12088 DW_SECT_MACINFO 7 .debug_macinfo.dwo
12089 DW_SECT_MACRO 8 .debug_macro.dwo
12091 The offsets provided by the CU and TU index sections are the base offsets
12092 for the contributions made by each CU or TU to the corresponding section
12093 in the package file. Each CU and TU header contains an abbrev_offset
12094 field, used to find the abbreviations table for that CU or TU within the
12095 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
12096 be interpreted as relative to the base offset given in the index section.
12097 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
12098 should be interpreted as relative to the base offset for .debug_line.dwo,
12099 and offsets into other debug sections obtained from DWARF attributes should
12100 also be interpreted as relative to the corresponding base offset.
12102 The table of sizes begins immediately following the table of offsets.
12103 Like the table of offsets, it is a two-dimensional array of 32-bit words,
12104 with L columns and N rows, in row-major order. Each row in the array is
12105 indexed starting from 1 (row 0 is shared by the two tables).
12109 Hash table lookup is handled the same in version 1 and 2:
12111 We assume that N and M will not exceed 2^32 - 1.
12112 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
12114 Given a 64-bit compilation unit signature or a type signature S, an entry
12115 in the hash table is located as follows:
12117 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
12118 the low-order k bits all set to 1.
12120 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
12122 3) If the hash table entry at index H matches the signature, use that
12123 entry. If the hash table entry at index H is unused (all zeroes),
12124 terminate the search: the signature is not present in the table.
12126 4) Let H = (H + H') modulo M. Repeat at Step 3.
12128 Because M > N and H' and M are relatively prime, the search is guaranteed
12129 to stop at an unused slot or find the match. */
12131 /* Create a hash table to map DWO IDs to their CU/TU entry in
12132 .debug_{info,types}.dwo in DWP_FILE.
12133 Returns NULL if there isn't one.
12134 Note: This function processes DWP files only, not DWO files. */
12136 static struct dwp_hash_table
*
12137 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12138 struct dwp_file
*dwp_file
, int is_debug_types
)
12140 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12141 bfd
*dbfd
= dwp_file
->dbfd
;
12142 const gdb_byte
*index_ptr
, *index_end
;
12143 struct dwarf2_section_info
*index
;
12144 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
12145 struct dwp_hash_table
*htab
;
12147 if (is_debug_types
)
12148 index
= &dwp_file
->sections
.tu_index
;
12150 index
= &dwp_file
->sections
.cu_index
;
12152 if (dwarf2_section_empty_p (index
))
12154 dwarf2_read_section (objfile
, index
);
12156 index_ptr
= index
->buffer
;
12157 index_end
= index_ptr
+ index
->size
;
12159 version
= read_4_bytes (dbfd
, index_ptr
);
12162 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
12166 nr_units
= read_4_bytes (dbfd
, index_ptr
);
12168 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
12171 if (version
!= 1 && version
!= 2)
12173 error (_("Dwarf Error: unsupported DWP file version (%s)"
12174 " [in module %s]"),
12175 pulongest (version
), dwp_file
->name
);
12177 if (nr_slots
!= (nr_slots
& -nr_slots
))
12179 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
12180 " is not power of 2 [in module %s]"),
12181 pulongest (nr_slots
), dwp_file
->name
);
12184 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
12185 htab
->version
= version
;
12186 htab
->nr_columns
= nr_columns
;
12187 htab
->nr_units
= nr_units
;
12188 htab
->nr_slots
= nr_slots
;
12189 htab
->hash_table
= index_ptr
;
12190 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
12192 /* Exit early if the table is empty. */
12193 if (nr_slots
== 0 || nr_units
== 0
12194 || (version
== 2 && nr_columns
== 0))
12196 /* All must be zero. */
12197 if (nr_slots
!= 0 || nr_units
!= 0
12198 || (version
== 2 && nr_columns
!= 0))
12200 complaint (&symfile_complaints
,
12201 _("Empty DWP but nr_slots,nr_units,nr_columns not"
12202 " all zero [in modules %s]"),
12210 htab
->section_pool
.v1
.indices
=
12211 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12212 /* It's harder to decide whether the section is too small in v1.
12213 V1 is deprecated anyway so we punt. */
12217 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12218 int *ids
= htab
->section_pool
.v2
.section_ids
;
12219 /* Reverse map for error checking. */
12220 int ids_seen
[DW_SECT_MAX
+ 1];
12223 if (nr_columns
< 2)
12225 error (_("Dwarf Error: bad DWP hash table, too few columns"
12226 " in section table [in module %s]"),
12229 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
12231 error (_("Dwarf Error: bad DWP hash table, too many columns"
12232 " in section table [in module %s]"),
12235 memset (ids
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
12236 memset (ids_seen
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
12237 for (i
= 0; i
< nr_columns
; ++i
)
12239 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
12241 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
12243 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
12244 " in section table [in module %s]"),
12245 id
, dwp_file
->name
);
12247 if (ids_seen
[id
] != -1)
12249 error (_("Dwarf Error: bad DWP hash table, duplicate section"
12250 " id %d in section table [in module %s]"),
12251 id
, dwp_file
->name
);
12256 /* Must have exactly one info or types section. */
12257 if (((ids_seen
[DW_SECT_INFO
] != -1)
12258 + (ids_seen
[DW_SECT_TYPES
] != -1))
12261 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
12262 " DWO info/types section [in module %s]"),
12265 /* Must have an abbrev section. */
12266 if (ids_seen
[DW_SECT_ABBREV
] == -1)
12268 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
12269 " section [in module %s]"),
12272 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
12273 htab
->section_pool
.v2
.sizes
=
12274 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
12275 * nr_units
* nr_columns
);
12276 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
12277 * nr_units
* nr_columns
))
12280 error (_("Dwarf Error: DWP index section is corrupt (too small)"
12281 " [in module %s]"),
12289 /* Update SECTIONS with the data from SECTP.
12291 This function is like the other "locate" section routines that are
12292 passed to bfd_map_over_sections, but in this context the sections to
12293 read comes from the DWP V1 hash table, not the full ELF section table.
12295 The result is non-zero for success, or zero if an error was found. */
12298 locate_v1_virtual_dwo_sections (asection
*sectp
,
12299 struct virtual_v1_dwo_sections
*sections
)
12301 const struct dwop_section_names
*names
= &dwop_section_names
;
12303 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12305 /* There can be only one. */
12306 if (sections
->abbrev
.s
.section
!= NULL
)
12308 sections
->abbrev
.s
.section
= sectp
;
12309 sections
->abbrev
.size
= bfd_get_section_size (sectp
);
12311 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
12312 || section_is_p (sectp
->name
, &names
->types_dwo
))
12314 /* There can be only one. */
12315 if (sections
->info_or_types
.s
.section
!= NULL
)
12317 sections
->info_or_types
.s
.section
= sectp
;
12318 sections
->info_or_types
.size
= bfd_get_section_size (sectp
);
12320 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12322 /* There can be only one. */
12323 if (sections
->line
.s
.section
!= NULL
)
12325 sections
->line
.s
.section
= sectp
;
12326 sections
->line
.size
= bfd_get_section_size (sectp
);
12328 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12330 /* There can be only one. */
12331 if (sections
->loc
.s
.section
!= NULL
)
12333 sections
->loc
.s
.section
= sectp
;
12334 sections
->loc
.size
= bfd_get_section_size (sectp
);
12336 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12338 /* There can be only one. */
12339 if (sections
->macinfo
.s
.section
!= NULL
)
12341 sections
->macinfo
.s
.section
= sectp
;
12342 sections
->macinfo
.size
= bfd_get_section_size (sectp
);
12344 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12346 /* There can be only one. */
12347 if (sections
->macro
.s
.section
!= NULL
)
12349 sections
->macro
.s
.section
= sectp
;
12350 sections
->macro
.size
= bfd_get_section_size (sectp
);
12352 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12354 /* There can be only one. */
12355 if (sections
->str_offsets
.s
.section
!= NULL
)
12357 sections
->str_offsets
.s
.section
= sectp
;
12358 sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
12362 /* No other kind of section is valid. */
12369 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12370 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12371 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12372 This is for DWP version 1 files. */
12374 static struct dwo_unit
*
12375 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12376 struct dwp_file
*dwp_file
,
12377 uint32_t unit_index
,
12378 const char *comp_dir
,
12379 ULONGEST signature
, int is_debug_types
)
12381 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12382 const struct dwp_hash_table
*dwp_htab
=
12383 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12384 bfd
*dbfd
= dwp_file
->dbfd
;
12385 const char *kind
= is_debug_types
? "TU" : "CU";
12386 struct dwo_file
*dwo_file
;
12387 struct dwo_unit
*dwo_unit
;
12388 struct virtual_v1_dwo_sections sections
;
12389 void **dwo_file_slot
;
12392 gdb_assert (dwp_file
->version
== 1);
12394 if (dwarf_read_debug
)
12396 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
12398 pulongest (unit_index
), hex_string (signature
),
12402 /* Fetch the sections of this DWO unit.
12403 Put a limit on the number of sections we look for so that bad data
12404 doesn't cause us to loop forever. */
12406 #define MAX_NR_V1_DWO_SECTIONS \
12407 (1 /* .debug_info or .debug_types */ \
12408 + 1 /* .debug_abbrev */ \
12409 + 1 /* .debug_line */ \
12410 + 1 /* .debug_loc */ \
12411 + 1 /* .debug_str_offsets */ \
12412 + 1 /* .debug_macro or .debug_macinfo */ \
12413 + 1 /* trailing zero */)
12415 memset (§ions
, 0, sizeof (sections
));
12417 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12420 uint32_t section_nr
=
12421 read_4_bytes (dbfd
,
12422 dwp_htab
->section_pool
.v1
.indices
12423 + (unit_index
+ i
) * sizeof (uint32_t));
12425 if (section_nr
== 0)
12427 if (section_nr
>= dwp_file
->num_sections
)
12429 error (_("Dwarf Error: bad DWP hash table, section number too large"
12430 " [in module %s]"),
12434 sectp
= dwp_file
->elf_sections
[section_nr
];
12435 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12437 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12438 " [in module %s]"),
12444 || dwarf2_section_empty_p (§ions
.info_or_types
)
12445 || dwarf2_section_empty_p (§ions
.abbrev
))
12447 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12448 " [in module %s]"),
12451 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12453 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12454 " [in module %s]"),
12458 /* It's easier for the rest of the code if we fake a struct dwo_file and
12459 have dwo_unit "live" in that. At least for now.
12461 The DWP file can be made up of a random collection of CUs and TUs.
12462 However, for each CU + set of TUs that came from the same original DWO
12463 file, we can combine them back into a virtual DWO file to save space
12464 (fewer struct dwo_file objects to allocate). Remember that for really
12465 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12467 std::string virtual_dwo_name
=
12468 string_printf ("virtual-dwo/%d-%d-%d-%d",
12469 get_section_id (§ions
.abbrev
),
12470 get_section_id (§ions
.line
),
12471 get_section_id (§ions
.loc
),
12472 get_section_id (§ions
.str_offsets
));
12473 /* Can we use an existing virtual DWO file? */
12474 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12475 virtual_dwo_name
.c_str (),
12477 /* Create one if necessary. */
12478 if (*dwo_file_slot
== NULL
)
12480 if (dwarf_read_debug
)
12482 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12483 virtual_dwo_name
.c_str ());
12485 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
12487 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
12488 virtual_dwo_name
.c_str (),
12489 virtual_dwo_name
.size ());
12490 dwo_file
->comp_dir
= comp_dir
;
12491 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12492 dwo_file
->sections
.line
= sections
.line
;
12493 dwo_file
->sections
.loc
= sections
.loc
;
12494 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12495 dwo_file
->sections
.macro
= sections
.macro
;
12496 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12497 /* The "str" section is global to the entire DWP file. */
12498 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12499 /* The info or types section is assigned below to dwo_unit,
12500 there's no need to record it in dwo_file.
12501 Also, we can't simply record type sections in dwo_file because
12502 we record a pointer into the vector in dwo_unit. As we collect more
12503 types we'll grow the vector and eventually have to reallocate space
12504 for it, invalidating all copies of pointers into the previous
12506 *dwo_file_slot
= dwo_file
;
12510 if (dwarf_read_debug
)
12512 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12513 virtual_dwo_name
.c_str ());
12515 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12518 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12519 dwo_unit
->dwo_file
= dwo_file
;
12520 dwo_unit
->signature
= signature
;
12521 dwo_unit
->section
=
12522 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12523 *dwo_unit
->section
= sections
.info_or_types
;
12524 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12529 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
12530 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
12531 piece within that section used by a TU/CU, return a virtual section
12532 of just that piece. */
12534 static struct dwarf2_section_info
12535 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12536 struct dwarf2_section_info
*section
,
12537 bfd_size_type offset
, bfd_size_type size
)
12539 struct dwarf2_section_info result
;
12542 gdb_assert (section
!= NULL
);
12543 gdb_assert (!section
->is_virtual
);
12545 memset (&result
, 0, sizeof (result
));
12546 result
.s
.containing_section
= section
;
12547 result
.is_virtual
= 1;
12552 sectp
= get_section_bfd_section (section
);
12554 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12555 bounds of the real section. This is a pretty-rare event, so just
12556 flag an error (easier) instead of a warning and trying to cope. */
12558 || offset
+ size
> bfd_get_section_size (sectp
))
12560 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12561 " in section %s [in module %s]"),
12562 sectp
? bfd_section_name (abfd
, sectp
) : "<unknown>",
12563 objfile_name (dwarf2_per_objfile
->objfile
));
12566 result
.virtual_offset
= offset
;
12567 result
.size
= size
;
12571 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12572 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12573 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12574 This is for DWP version 2 files. */
12576 static struct dwo_unit
*
12577 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12578 struct dwp_file
*dwp_file
,
12579 uint32_t unit_index
,
12580 const char *comp_dir
,
12581 ULONGEST signature
, int is_debug_types
)
12583 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12584 const struct dwp_hash_table
*dwp_htab
=
12585 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12586 bfd
*dbfd
= dwp_file
->dbfd
;
12587 const char *kind
= is_debug_types
? "TU" : "CU";
12588 struct dwo_file
*dwo_file
;
12589 struct dwo_unit
*dwo_unit
;
12590 struct virtual_v2_dwo_sections sections
;
12591 void **dwo_file_slot
;
12594 gdb_assert (dwp_file
->version
== 2);
12596 if (dwarf_read_debug
)
12598 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
12600 pulongest (unit_index
), hex_string (signature
),
12604 /* Fetch the section offsets of this DWO unit. */
12606 memset (§ions
, 0, sizeof (sections
));
12608 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12610 uint32_t offset
= read_4_bytes (dbfd
,
12611 dwp_htab
->section_pool
.v2
.offsets
12612 + (((unit_index
- 1) * dwp_htab
->nr_columns
12614 * sizeof (uint32_t)));
12615 uint32_t size
= read_4_bytes (dbfd
,
12616 dwp_htab
->section_pool
.v2
.sizes
12617 + (((unit_index
- 1) * dwp_htab
->nr_columns
12619 * sizeof (uint32_t)));
12621 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12624 case DW_SECT_TYPES
:
12625 sections
.info_or_types_offset
= offset
;
12626 sections
.info_or_types_size
= size
;
12628 case DW_SECT_ABBREV
:
12629 sections
.abbrev_offset
= offset
;
12630 sections
.abbrev_size
= size
;
12633 sections
.line_offset
= offset
;
12634 sections
.line_size
= size
;
12637 sections
.loc_offset
= offset
;
12638 sections
.loc_size
= size
;
12640 case DW_SECT_STR_OFFSETS
:
12641 sections
.str_offsets_offset
= offset
;
12642 sections
.str_offsets_size
= size
;
12644 case DW_SECT_MACINFO
:
12645 sections
.macinfo_offset
= offset
;
12646 sections
.macinfo_size
= size
;
12648 case DW_SECT_MACRO
:
12649 sections
.macro_offset
= offset
;
12650 sections
.macro_size
= size
;
12655 /* It's easier for the rest of the code if we fake a struct dwo_file and
12656 have dwo_unit "live" in that. At least for now.
12658 The DWP file can be made up of a random collection of CUs and TUs.
12659 However, for each CU + set of TUs that came from the same original DWO
12660 file, we can combine them back into a virtual DWO file to save space
12661 (fewer struct dwo_file objects to allocate). Remember that for really
12662 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12664 std::string virtual_dwo_name
=
12665 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12666 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12667 (long) (sections
.line_size
? sections
.line_offset
: 0),
12668 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12669 (long) (sections
.str_offsets_size
12670 ? sections
.str_offsets_offset
: 0));
12671 /* Can we use an existing virtual DWO file? */
12672 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12673 virtual_dwo_name
.c_str (),
12675 /* Create one if necessary. */
12676 if (*dwo_file_slot
== NULL
)
12678 if (dwarf_read_debug
)
12680 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12681 virtual_dwo_name
.c_str ());
12683 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
12685 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
12686 virtual_dwo_name
.c_str (),
12687 virtual_dwo_name
.size ());
12688 dwo_file
->comp_dir
= comp_dir
;
12689 dwo_file
->sections
.abbrev
=
12690 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
12691 sections
.abbrev_offset
, sections
.abbrev_size
);
12692 dwo_file
->sections
.line
=
12693 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
12694 sections
.line_offset
, sections
.line_size
);
12695 dwo_file
->sections
.loc
=
12696 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
12697 sections
.loc_offset
, sections
.loc_size
);
12698 dwo_file
->sections
.macinfo
=
12699 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
12700 sections
.macinfo_offset
, sections
.macinfo_size
);
12701 dwo_file
->sections
.macro
=
12702 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
12703 sections
.macro_offset
, sections
.macro_size
);
12704 dwo_file
->sections
.str_offsets
=
12705 create_dwp_v2_section (dwarf2_per_objfile
,
12706 &dwp_file
->sections
.str_offsets
,
12707 sections
.str_offsets_offset
,
12708 sections
.str_offsets_size
);
12709 /* The "str" section is global to the entire DWP file. */
12710 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12711 /* The info or types section is assigned below to dwo_unit,
12712 there's no need to record it in dwo_file.
12713 Also, we can't simply record type sections in dwo_file because
12714 we record a pointer into the vector in dwo_unit. As we collect more
12715 types we'll grow the vector and eventually have to reallocate space
12716 for it, invalidating all copies of pointers into the previous
12718 *dwo_file_slot
= dwo_file
;
12722 if (dwarf_read_debug
)
12724 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12725 virtual_dwo_name
.c_str ());
12727 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12730 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12731 dwo_unit
->dwo_file
= dwo_file
;
12732 dwo_unit
->signature
= signature
;
12733 dwo_unit
->section
=
12734 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12735 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
12737 ? &dwp_file
->sections
.types
12738 : &dwp_file
->sections
.info
,
12739 sections
.info_or_types_offset
,
12740 sections
.info_or_types_size
);
12741 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12746 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12747 Returns NULL if the signature isn't found. */
12749 static struct dwo_unit
*
12750 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12751 struct dwp_file
*dwp_file
, const char *comp_dir
,
12752 ULONGEST signature
, int is_debug_types
)
12754 const struct dwp_hash_table
*dwp_htab
=
12755 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12756 bfd
*dbfd
= dwp_file
->dbfd
;
12757 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12758 uint32_t hash
= signature
& mask
;
12759 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12762 struct dwo_unit find_dwo_cu
;
12764 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12765 find_dwo_cu
.signature
= signature
;
12766 slot
= htab_find_slot (is_debug_types
12767 ? dwp_file
->loaded_tus
12768 : dwp_file
->loaded_cus
,
12769 &find_dwo_cu
, INSERT
);
12772 return (struct dwo_unit
*) *slot
;
12774 /* Use a for loop so that we don't loop forever on bad debug info. */
12775 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12777 ULONGEST signature_in_table
;
12779 signature_in_table
=
12780 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12781 if (signature_in_table
== signature
)
12783 uint32_t unit_index
=
12784 read_4_bytes (dbfd
,
12785 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12787 if (dwp_file
->version
== 1)
12789 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
12790 dwp_file
, unit_index
,
12791 comp_dir
, signature
,
12796 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
12797 dwp_file
, unit_index
,
12798 comp_dir
, signature
,
12801 return (struct dwo_unit
*) *slot
;
12803 if (signature_in_table
== 0)
12805 hash
= (hash
+ hash2
) & mask
;
12808 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12809 " [in module %s]"),
12813 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12814 Open the file specified by FILE_NAME and hand it off to BFD for
12815 preliminary analysis. Return a newly initialized bfd *, which
12816 includes a canonicalized copy of FILE_NAME.
12817 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12818 SEARCH_CWD is true if the current directory is to be searched.
12819 It will be searched before debug-file-directory.
12820 If successful, the file is added to the bfd include table of the
12821 objfile's bfd (see gdb_bfd_record_inclusion).
12822 If unable to find/open the file, return NULL.
12823 NOTE: This function is derived from symfile_bfd_open. */
12825 static gdb_bfd_ref_ptr
12826 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12827 const char *file_name
, int is_dwp
, int search_cwd
)
12830 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12831 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12832 to debug_file_directory. */
12833 const char *search_path
;
12834 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12836 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12839 if (*debug_file_directory
!= '\0')
12841 search_path_holder
.reset (concat (".", dirname_separator_string
,
12842 debug_file_directory
,
12844 search_path
= search_path_holder
.get ();
12850 search_path
= debug_file_directory
;
12852 openp_flags flags
= OPF_RETURN_REALPATH
;
12854 flags
|= OPF_SEARCH_IN_PATH
;
12856 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12857 desc
= openp (search_path
, flags
, file_name
,
12858 O_RDONLY
| O_BINARY
, &absolute_name
);
12862 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12864 if (sym_bfd
== NULL
)
12866 bfd_set_cacheable (sym_bfd
.get (), 1);
12868 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12871 /* Success. Record the bfd as having been included by the objfile's bfd.
12872 This is important because things like demangled_names_hash lives in the
12873 objfile's per_bfd space and may have references to things like symbol
12874 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12875 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12880 /* Try to open DWO file FILE_NAME.
12881 COMP_DIR is the DW_AT_comp_dir attribute.
12882 The result is the bfd handle of the file.
12883 If there is a problem finding or opening the file, return NULL.
12884 Upon success, the canonicalized path of the file is stored in the bfd,
12885 same as symfile_bfd_open. */
12887 static gdb_bfd_ref_ptr
12888 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12889 const char *file_name
, const char *comp_dir
)
12891 if (IS_ABSOLUTE_PATH (file_name
))
12892 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12893 0 /*is_dwp*/, 0 /*search_cwd*/);
12895 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12897 if (comp_dir
!= NULL
)
12899 char *path_to_try
= concat (comp_dir
, SLASH_STRING
,
12900 file_name
, (char *) NULL
);
12902 /* NOTE: If comp_dir is a relative path, this will also try the
12903 search path, which seems useful. */
12904 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12907 1 /*search_cwd*/));
12908 xfree (path_to_try
);
12913 /* That didn't work, try debug-file-directory, which, despite its name,
12914 is a list of paths. */
12916 if (*debug_file_directory
== '\0')
12919 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12920 0 /*is_dwp*/, 1 /*search_cwd*/);
12923 /* This function is mapped across the sections and remembers the offset and
12924 size of each of the DWO debugging sections we are interested in. */
12927 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12929 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12930 const struct dwop_section_names
*names
= &dwop_section_names
;
12932 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12934 dwo_sections
->abbrev
.s
.section
= sectp
;
12935 dwo_sections
->abbrev
.size
= bfd_get_section_size (sectp
);
12937 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12939 dwo_sections
->info
.s
.section
= sectp
;
12940 dwo_sections
->info
.size
= bfd_get_section_size (sectp
);
12942 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12944 dwo_sections
->line
.s
.section
= sectp
;
12945 dwo_sections
->line
.size
= bfd_get_section_size (sectp
);
12947 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12949 dwo_sections
->loc
.s
.section
= sectp
;
12950 dwo_sections
->loc
.size
= bfd_get_section_size (sectp
);
12952 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12954 dwo_sections
->macinfo
.s
.section
= sectp
;
12955 dwo_sections
->macinfo
.size
= bfd_get_section_size (sectp
);
12957 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12959 dwo_sections
->macro
.s
.section
= sectp
;
12960 dwo_sections
->macro
.size
= bfd_get_section_size (sectp
);
12962 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12964 dwo_sections
->str
.s
.section
= sectp
;
12965 dwo_sections
->str
.size
= bfd_get_section_size (sectp
);
12967 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12969 dwo_sections
->str_offsets
.s
.section
= sectp
;
12970 dwo_sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
12972 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12974 struct dwarf2_section_info type_section
;
12976 memset (&type_section
, 0, sizeof (type_section
));
12977 type_section
.s
.section
= sectp
;
12978 type_section
.size
= bfd_get_section_size (sectp
);
12979 VEC_safe_push (dwarf2_section_info_def
, dwo_sections
->types
,
12984 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12985 by PER_CU. This is for the non-DWP case.
12986 The result is NULL if DWO_NAME can't be found. */
12988 static struct dwo_file
*
12989 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12990 const char *dwo_name
, const char *comp_dir
)
12992 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12993 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12995 gdb_bfd_ref_ptr
dbfd (open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
));
12998 if (dwarf_read_debug
)
12999 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
13003 /* We use a unique pointer here, despite the obstack allocation,
13004 because a dwo_file needs some cleanup if it is abandoned. */
13005 dwo_file_up
dwo_file (OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
13007 dwo_file
->dwo_name
= dwo_name
;
13008 dwo_file
->comp_dir
= comp_dir
;
13009 dwo_file
->dbfd
= dbfd
.release ();
13011 bfd_map_over_sections (dwo_file
->dbfd
, dwarf2_locate_dwo_sections
,
13012 &dwo_file
->sections
);
13014 create_cus_hash_table (dwarf2_per_objfile
, *dwo_file
, dwo_file
->sections
.info
,
13017 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
13018 dwo_file
->sections
.types
, dwo_file
->tus
);
13020 if (dwarf_read_debug
)
13021 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
13023 return dwo_file
.release ();
13026 /* This function is mapped across the sections and remembers the offset and
13027 size of each of the DWP debugging sections common to version 1 and 2 that
13028 we are interested in. */
13031 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
13032 void *dwp_file_ptr
)
13034 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13035 const struct dwop_section_names
*names
= &dwop_section_names
;
13036 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13038 /* Record the ELF section number for later lookup: this is what the
13039 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13040 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13041 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13043 /* Look for specific sections that we need. */
13044 if (section_is_p (sectp
->name
, &names
->str_dwo
))
13046 dwp_file
->sections
.str
.s
.section
= sectp
;
13047 dwp_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
13049 else if (section_is_p (sectp
->name
, &names
->cu_index
))
13051 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
13052 dwp_file
->sections
.cu_index
.size
= bfd_get_section_size (sectp
);
13054 else if (section_is_p (sectp
->name
, &names
->tu_index
))
13056 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
13057 dwp_file
->sections
.tu_index
.size
= bfd_get_section_size (sectp
);
13061 /* This function is mapped across the sections and remembers the offset and
13062 size of each of the DWP version 2 debugging sections that we are interested
13063 in. This is split into a separate function because we don't know if we
13064 have version 1 or 2 until we parse the cu_index/tu_index sections. */
13067 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
13069 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13070 const struct dwop_section_names
*names
= &dwop_section_names
;
13071 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13073 /* Record the ELF section number for later lookup: this is what the
13074 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13075 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13076 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13078 /* Look for specific sections that we need. */
13079 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
13081 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
13082 dwp_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
13084 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
13086 dwp_file
->sections
.info
.s
.section
= sectp
;
13087 dwp_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
13089 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
13091 dwp_file
->sections
.line
.s
.section
= sectp
;
13092 dwp_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
13094 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
13096 dwp_file
->sections
.loc
.s
.section
= sectp
;
13097 dwp_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
13099 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
13101 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
13102 dwp_file
->sections
.macinfo
.size
= bfd_get_section_size (sectp
);
13104 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13106 dwp_file
->sections
.macro
.s
.section
= sectp
;
13107 dwp_file
->sections
.macro
.size
= bfd_get_section_size (sectp
);
13109 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13111 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
13112 dwp_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
13114 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13116 dwp_file
->sections
.types
.s
.section
= sectp
;
13117 dwp_file
->sections
.types
.size
= bfd_get_section_size (sectp
);
13121 /* Hash function for dwp_file loaded CUs/TUs. */
13124 hash_dwp_loaded_cutus (const void *item
)
13126 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
13128 /* This drops the top 32 bits of the signature, but is ok for a hash. */
13129 return dwo_unit
->signature
;
13132 /* Equality function for dwp_file loaded CUs/TUs. */
13135 eq_dwp_loaded_cutus (const void *a
, const void *b
)
13137 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
13138 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
13140 return dua
->signature
== dub
->signature
;
13143 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
13146 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
13148 return htab_create_alloc_ex (3,
13149 hash_dwp_loaded_cutus
,
13150 eq_dwp_loaded_cutus
,
13152 &objfile
->objfile_obstack
,
13153 hashtab_obstack_allocate
,
13154 dummy_obstack_deallocate
);
13157 /* Try to open DWP file FILE_NAME.
13158 The result is the bfd handle of the file.
13159 If there is a problem finding or opening the file, return NULL.
13160 Upon success, the canonicalized path of the file is stored in the bfd,
13161 same as symfile_bfd_open. */
13163 static gdb_bfd_ref_ptr
13164 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13165 const char *file_name
)
13167 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
13169 1 /*search_cwd*/));
13173 /* Work around upstream bug 15652.
13174 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
13175 [Whether that's a "bug" is debatable, but it is getting in our way.]
13176 We have no real idea where the dwp file is, because gdb's realpath-ing
13177 of the executable's path may have discarded the needed info.
13178 [IWBN if the dwp file name was recorded in the executable, akin to
13179 .gnu_debuglink, but that doesn't exist yet.]
13180 Strip the directory from FILE_NAME and search again. */
13181 if (*debug_file_directory
!= '\0')
13183 /* Don't implicitly search the current directory here.
13184 If the user wants to search "." to handle this case,
13185 it must be added to debug-file-directory. */
13186 return try_open_dwop_file (dwarf2_per_objfile
,
13187 lbasename (file_name
), 1 /*is_dwp*/,
13194 /* Initialize the use of the DWP file for the current objfile.
13195 By convention the name of the DWP file is ${objfile}.dwp.
13196 The result is NULL if it can't be found. */
13198 static struct dwp_file
*
13199 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13201 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13202 struct dwp_file
*dwp_file
;
13204 /* Try to find first .dwp for the binary file before any symbolic links
13207 /* If the objfile is a debug file, find the name of the real binary
13208 file and get the name of dwp file from there. */
13209 std::string dwp_name
;
13210 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
13212 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
13213 const char *backlink_basename
= lbasename (backlink
->original_name
);
13215 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
13218 dwp_name
= objfile
->original_name
;
13220 dwp_name
+= ".dwp";
13222 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
13224 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
13226 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
13227 dwp_name
= objfile_name (objfile
);
13228 dwp_name
+= ".dwp";
13229 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
13234 if (dwarf_read_debug
)
13235 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
13238 dwp_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_file
);
13239 dwp_file
->name
= bfd_get_filename (dbfd
.get ());
13240 dwp_file
->dbfd
= dbfd
.release ();
13242 /* +1: section 0 is unused */
13243 dwp_file
->num_sections
= bfd_count_sections (dwp_file
->dbfd
) + 1;
13244 dwp_file
->elf_sections
=
13245 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
13246 dwp_file
->num_sections
, asection
*);
13248 bfd_map_over_sections (dwp_file
->dbfd
, dwarf2_locate_common_dwp_sections
,
13251 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
, 0);
13253 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
, 1);
13255 /* The DWP file version is stored in the hash table. Oh well. */
13256 if (dwp_file
->cus
&& dwp_file
->tus
13257 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
13259 /* Technically speaking, we should try to limp along, but this is
13260 pretty bizarre. We use pulongest here because that's the established
13261 portability solution (e.g, we cannot use %u for uint32_t). */
13262 error (_("Dwarf Error: DWP file CU version %s doesn't match"
13263 " TU version %s [in DWP file %s]"),
13264 pulongest (dwp_file
->cus
->version
),
13265 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
13269 dwp_file
->version
= dwp_file
->cus
->version
;
13270 else if (dwp_file
->tus
)
13271 dwp_file
->version
= dwp_file
->tus
->version
;
13273 dwp_file
->version
= 2;
13275 if (dwp_file
->version
== 2)
13276 bfd_map_over_sections (dwp_file
->dbfd
, dwarf2_locate_v2_dwp_sections
,
13279 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
13280 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
13282 if (dwarf_read_debug
)
13284 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
13285 fprintf_unfiltered (gdb_stdlog
,
13286 " %s CUs, %s TUs\n",
13287 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13288 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13294 /* Wrapper around open_and_init_dwp_file, only open it once. */
13296 static struct dwp_file
*
13297 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13299 if (! dwarf2_per_objfile
->dwp_checked
)
13301 dwarf2_per_objfile
->dwp_file
13302 = open_and_init_dwp_file (dwarf2_per_objfile
);
13303 dwarf2_per_objfile
->dwp_checked
= 1;
13305 return dwarf2_per_objfile
->dwp_file
;
13308 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13309 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13310 or in the DWP file for the objfile, referenced by THIS_UNIT.
13311 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13312 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13314 This is called, for example, when wanting to read a variable with a
13315 complex location. Therefore we don't want to do file i/o for every call.
13316 Therefore we don't want to look for a DWO file on every call.
13317 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13318 then we check if we've already seen DWO_NAME, and only THEN do we check
13321 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13322 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13324 static struct dwo_unit
*
13325 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
13326 const char *dwo_name
, const char *comp_dir
,
13327 ULONGEST signature
, int is_debug_types
)
13329 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
13330 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13331 const char *kind
= is_debug_types
? "TU" : "CU";
13332 void **dwo_file_slot
;
13333 struct dwo_file
*dwo_file
;
13334 struct dwp_file
*dwp_file
;
13336 /* First see if there's a DWP file.
13337 If we have a DWP file but didn't find the DWO inside it, don't
13338 look for the original DWO file. It makes gdb behave differently
13339 depending on whether one is debugging in the build tree. */
13341 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
13342 if (dwp_file
!= NULL
)
13344 const struct dwp_hash_table
*dwp_htab
=
13345 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13347 if (dwp_htab
!= NULL
)
13349 struct dwo_unit
*dwo_cutu
=
13350 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
13351 signature
, is_debug_types
);
13353 if (dwo_cutu
!= NULL
)
13355 if (dwarf_read_debug
)
13357 fprintf_unfiltered (gdb_stdlog
,
13358 "Virtual DWO %s %s found: @%s\n",
13359 kind
, hex_string (signature
),
13360 host_address_to_string (dwo_cutu
));
13368 /* No DWP file, look for the DWO file. */
13370 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
13371 dwo_name
, comp_dir
);
13372 if (*dwo_file_slot
== NULL
)
13374 /* Read in the file and build a table of the CUs/TUs it contains. */
13375 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
13377 /* NOTE: This will be NULL if unable to open the file. */
13378 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13380 if (dwo_file
!= NULL
)
13382 struct dwo_unit
*dwo_cutu
= NULL
;
13384 if (is_debug_types
&& dwo_file
->tus
)
13386 struct dwo_unit find_dwo_cutu
;
13388 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13389 find_dwo_cutu
.signature
= signature
;
13391 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
13393 else if (!is_debug_types
&& dwo_file
->cus
)
13395 struct dwo_unit find_dwo_cutu
;
13397 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13398 find_dwo_cutu
.signature
= signature
;
13399 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
,
13403 if (dwo_cutu
!= NULL
)
13405 if (dwarf_read_debug
)
13407 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
13408 kind
, dwo_name
, hex_string (signature
),
13409 host_address_to_string (dwo_cutu
));
13416 /* We didn't find it. This could mean a dwo_id mismatch, or
13417 someone deleted the DWO/DWP file, or the search path isn't set up
13418 correctly to find the file. */
13420 if (dwarf_read_debug
)
13422 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
13423 kind
, dwo_name
, hex_string (signature
));
13426 /* This is a warning and not a complaint because it can be caused by
13427 pilot error (e.g., user accidentally deleting the DWO). */
13429 /* Print the name of the DWP file if we looked there, helps the user
13430 better diagnose the problem. */
13431 std::string dwp_text
;
13433 if (dwp_file
!= NULL
)
13434 dwp_text
= string_printf (" [in DWP file %s]",
13435 lbasename (dwp_file
->name
));
13437 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13438 " [in module %s]"),
13439 kind
, dwo_name
, hex_string (signature
),
13441 this_unit
->is_debug_types
? "TU" : "CU",
13442 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
13447 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13448 See lookup_dwo_cutu_unit for details. */
13450 static struct dwo_unit
*
13451 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
13452 const char *dwo_name
, const char *comp_dir
,
13453 ULONGEST signature
)
13455 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
13458 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13459 See lookup_dwo_cutu_unit for details. */
13461 static struct dwo_unit
*
13462 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
13463 const char *dwo_name
, const char *comp_dir
)
13465 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
13468 /* Traversal function for queue_and_load_all_dwo_tus. */
13471 queue_and_load_dwo_tu (void **slot
, void *info
)
13473 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13474 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
13475 ULONGEST signature
= dwo_unit
->signature
;
13476 struct signatured_type
*sig_type
=
13477 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
13479 if (sig_type
!= NULL
)
13481 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13483 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13484 a real dependency of PER_CU on SIG_TYPE. That is detected later
13485 while processing PER_CU. */
13486 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
13487 load_full_type_unit (sig_cu
);
13488 VEC_safe_push (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, sig_cu
);
13494 /* Queue all TUs contained in the DWO of PER_CU to be read in.
13495 The DWO may have the only definition of the type, though it may not be
13496 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13497 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13500 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
13502 struct dwo_unit
*dwo_unit
;
13503 struct dwo_file
*dwo_file
;
13505 gdb_assert (!per_cu
->is_debug_types
);
13506 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
13507 gdb_assert (per_cu
->cu
!= NULL
);
13509 dwo_unit
= per_cu
->cu
->dwo_unit
;
13510 gdb_assert (dwo_unit
!= NULL
);
13512 dwo_file
= dwo_unit
->dwo_file
;
13513 if (dwo_file
->tus
!= NULL
)
13514 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
13517 /* Free all resources associated with DWO_FILE.
13518 Close the DWO file and munmap the sections. */
13521 free_dwo_file (struct dwo_file
*dwo_file
)
13523 /* Note: dbfd is NULL for virtual DWO files. */
13524 gdb_bfd_unref (dwo_file
->dbfd
);
13526 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
13529 /* Traversal function for free_dwo_files. */
13532 free_dwo_file_from_slot (void **slot
, void *info
)
13534 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
13536 free_dwo_file (dwo_file
);
13541 /* Free all resources associated with DWO_FILES. */
13544 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
13546 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
13549 /* Read in various DIEs. */
13551 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13552 Inherit only the children of the DW_AT_abstract_origin DIE not being
13553 already referenced by DW_AT_abstract_origin from the children of the
13557 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13559 struct die_info
*child_die
;
13560 sect_offset
*offsetp
;
13561 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13562 struct die_info
*origin_die
;
13563 /* Iterator of the ORIGIN_DIE children. */
13564 struct die_info
*origin_child_die
;
13565 struct attribute
*attr
;
13566 struct dwarf2_cu
*origin_cu
;
13567 struct pending
**origin_previous_list_in_scope
;
13569 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13573 /* Note that following die references may follow to a die in a
13577 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13579 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13581 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13582 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13584 if (die
->tag
!= origin_die
->tag
13585 && !(die
->tag
== DW_TAG_inlined_subroutine
13586 && origin_die
->tag
== DW_TAG_subprogram
))
13587 complaint (&symfile_complaints
,
13588 _("DIE %s and its abstract origin %s have different tags"),
13589 sect_offset_str (die
->sect_off
),
13590 sect_offset_str (origin_die
->sect_off
));
13592 std::vector
<sect_offset
> offsets
;
13594 for (child_die
= die
->child
;
13595 child_die
&& child_die
->tag
;
13596 child_die
= sibling_die (child_die
))
13598 struct die_info
*child_origin_die
;
13599 struct dwarf2_cu
*child_origin_cu
;
13601 /* We are trying to process concrete instance entries:
13602 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13603 it's not relevant to our analysis here. i.e. detecting DIEs that are
13604 present in the abstract instance but not referenced in the concrete
13606 if (child_die
->tag
== DW_TAG_call_site
13607 || child_die
->tag
== DW_TAG_GNU_call_site
)
13610 /* For each CHILD_DIE, find the corresponding child of
13611 ORIGIN_DIE. If there is more than one layer of
13612 DW_AT_abstract_origin, follow them all; there shouldn't be,
13613 but GCC versions at least through 4.4 generate this (GCC PR
13615 child_origin_die
= child_die
;
13616 child_origin_cu
= cu
;
13619 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13623 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13627 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13628 counterpart may exist. */
13629 if (child_origin_die
!= child_die
)
13631 if (child_die
->tag
!= child_origin_die
->tag
13632 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13633 && child_origin_die
->tag
== DW_TAG_subprogram
))
13634 complaint (&symfile_complaints
,
13635 _("Child DIE %s and its abstract origin %s have "
13637 sect_offset_str (child_die
->sect_off
),
13638 sect_offset_str (child_origin_die
->sect_off
));
13639 if (child_origin_die
->parent
!= origin_die
)
13640 complaint (&symfile_complaints
,
13641 _("Child DIE %s and its abstract origin %s have "
13642 "different parents"),
13643 sect_offset_str (child_die
->sect_off
),
13644 sect_offset_str (child_origin_die
->sect_off
));
13646 offsets
.push_back (child_origin_die
->sect_off
);
13649 std::sort (offsets
.begin (), offsets
.end ());
13650 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13651 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13652 if (offsetp
[-1] == *offsetp
)
13653 complaint (&symfile_complaints
,
13654 _("Multiple children of DIE %s refer "
13655 "to DIE %s as their abstract origin"),
13656 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13658 offsetp
= offsets
.data ();
13659 origin_child_die
= origin_die
->child
;
13660 while (origin_child_die
&& origin_child_die
->tag
)
13662 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13663 while (offsetp
< offsets_end
13664 && *offsetp
< origin_child_die
->sect_off
)
13666 if (offsetp
>= offsets_end
13667 || *offsetp
> origin_child_die
->sect_off
)
13669 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13670 Check whether we're already processing ORIGIN_CHILD_DIE.
13671 This can happen with mutually referenced abstract_origins.
13673 if (!origin_child_die
->in_process
)
13674 process_die (origin_child_die
, origin_cu
);
13676 origin_child_die
= sibling_die (origin_child_die
);
13678 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13682 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13684 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13685 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13686 struct context_stack
*newobj
;
13689 struct die_info
*child_die
;
13690 struct attribute
*attr
, *call_line
, *call_file
;
13692 CORE_ADDR baseaddr
;
13693 struct block
*block
;
13694 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13695 std::vector
<struct symbol
*> template_args
;
13696 struct template_symbol
*templ_func
= NULL
;
13700 /* If we do not have call site information, we can't show the
13701 caller of this inlined function. That's too confusing, so
13702 only use the scope for local variables. */
13703 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13704 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13705 if (call_line
== NULL
|| call_file
== NULL
)
13707 read_lexical_block_scope (die
, cu
);
13712 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13714 name
= dwarf2_name (die
, cu
);
13716 /* Ignore functions with missing or empty names. These are actually
13717 illegal according to the DWARF standard. */
13720 complaint (&symfile_complaints
,
13721 _("missing name for subprogram DIE at %s"),
13722 sect_offset_str (die
->sect_off
));
13726 /* Ignore functions with missing or invalid low and high pc attributes. */
13727 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13728 <= PC_BOUNDS_INVALID
)
13730 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13731 if (!attr
|| !DW_UNSND (attr
))
13732 complaint (&symfile_complaints
,
13733 _("cannot get low and high bounds "
13734 "for subprogram DIE at %s"),
13735 sect_offset_str (die
->sect_off
));
13739 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13740 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13742 /* If we have any template arguments, then we must allocate a
13743 different sort of symbol. */
13744 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
13746 if (child_die
->tag
== DW_TAG_template_type_param
13747 || child_die
->tag
== DW_TAG_template_value_param
)
13749 templ_func
= allocate_template_symbol (objfile
);
13750 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13755 newobj
= push_context (0, lowpc
);
13756 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13757 (struct symbol
*) templ_func
);
13759 /* If there is a location expression for DW_AT_frame_base, record
13761 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13763 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13765 /* If there is a location for the static link, record it. */
13766 newobj
->static_link
= NULL
;
13767 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13770 newobj
->static_link
13771 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13772 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
);
13775 cu
->list_in_scope
= &local_symbols
;
13777 if (die
->child
!= NULL
)
13779 child_die
= die
->child
;
13780 while (child_die
&& child_die
->tag
)
13782 if (child_die
->tag
== DW_TAG_template_type_param
13783 || child_die
->tag
== DW_TAG_template_value_param
)
13785 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13788 template_args
.push_back (arg
);
13791 process_die (child_die
, cu
);
13792 child_die
= sibling_die (child_die
);
13796 inherit_abstract_dies (die
, cu
);
13798 /* If we have a DW_AT_specification, we might need to import using
13799 directives from the context of the specification DIE. See the
13800 comment in determine_prefix. */
13801 if (cu
->language
== language_cplus
13802 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13804 struct dwarf2_cu
*spec_cu
= cu
;
13805 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13809 child_die
= spec_die
->child
;
13810 while (child_die
&& child_die
->tag
)
13812 if (child_die
->tag
== DW_TAG_imported_module
)
13813 process_die (child_die
, spec_cu
);
13814 child_die
= sibling_die (child_die
);
13817 /* In some cases, GCC generates specification DIEs that
13818 themselves contain DW_AT_specification attributes. */
13819 spec_die
= die_specification (spec_die
, &spec_cu
);
13823 newobj
= pop_context ();
13824 /* Make a block for the local symbols within. */
13825 block
= finish_block (newobj
->name
, &local_symbols
, newobj
->old_blocks
,
13826 newobj
->static_link
, lowpc
, highpc
);
13828 /* For C++, set the block's scope. */
13829 if ((cu
->language
== language_cplus
13830 || cu
->language
== language_fortran
13831 || cu
->language
== language_d
13832 || cu
->language
== language_rust
)
13833 && cu
->processing_has_namespace_info
)
13834 block_set_scope (block
, determine_prefix (die
, cu
),
13835 &objfile
->objfile_obstack
);
13837 /* If we have address ranges, record them. */
13838 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13840 gdbarch_make_symbol_special (gdbarch
, newobj
->name
, objfile
);
13842 /* Attach template arguments to function. */
13843 if (!template_args
.empty ())
13845 gdb_assert (templ_func
!= NULL
);
13847 templ_func
->n_template_arguments
= template_args
.size ();
13848 templ_func
->template_arguments
13849 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13850 templ_func
->n_template_arguments
);
13851 memcpy (templ_func
->template_arguments
,
13852 template_args
.data (),
13853 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13856 /* In C++, we can have functions nested inside functions (e.g., when
13857 a function declares a class that has methods). This means that
13858 when we finish processing a function scope, we may need to go
13859 back to building a containing block's symbol lists. */
13860 local_symbols
= newobj
->locals
;
13861 local_using_directives
= newobj
->local_using_directives
;
13863 /* If we've finished processing a top-level function, subsequent
13864 symbols go in the file symbol list. */
13865 if (outermost_context_p ())
13866 cu
->list_in_scope
= &file_symbols
;
13869 /* Process all the DIES contained within a lexical block scope. Start
13870 a new scope, process the dies, and then close the scope. */
13873 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13875 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13876 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13877 struct context_stack
*newobj
;
13878 CORE_ADDR lowpc
, highpc
;
13879 struct die_info
*child_die
;
13880 CORE_ADDR baseaddr
;
13882 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13884 /* Ignore blocks with missing or invalid low and high pc attributes. */
13885 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13886 as multiple lexical blocks? Handling children in a sane way would
13887 be nasty. Might be easier to properly extend generic blocks to
13888 describe ranges. */
13889 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13891 case PC_BOUNDS_NOT_PRESENT
:
13892 /* DW_TAG_lexical_block has no attributes, process its children as if
13893 there was no wrapping by that DW_TAG_lexical_block.
13894 GCC does no longer produces such DWARF since GCC r224161. */
13895 for (child_die
= die
->child
;
13896 child_die
!= NULL
&& child_die
->tag
;
13897 child_die
= sibling_die (child_die
))
13898 process_die (child_die
, cu
);
13900 case PC_BOUNDS_INVALID
:
13903 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13904 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13906 push_context (0, lowpc
);
13907 if (die
->child
!= NULL
)
13909 child_die
= die
->child
;
13910 while (child_die
&& child_die
->tag
)
13912 process_die (child_die
, cu
);
13913 child_die
= sibling_die (child_die
);
13916 inherit_abstract_dies (die
, cu
);
13917 newobj
= pop_context ();
13919 if (local_symbols
!= NULL
|| local_using_directives
!= NULL
)
13921 struct block
*block
13922 = finish_block (0, &local_symbols
, newobj
->old_blocks
, NULL
,
13923 newobj
->start_addr
, highpc
);
13925 /* Note that recording ranges after traversing children, as we
13926 do here, means that recording a parent's ranges entails
13927 walking across all its children's ranges as they appear in
13928 the address map, which is quadratic behavior.
13930 It would be nicer to record the parent's ranges before
13931 traversing its children, simply overriding whatever you find
13932 there. But since we don't even decide whether to create a
13933 block until after we've traversed its children, that's hard
13935 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13937 local_symbols
= newobj
->locals
;
13938 local_using_directives
= newobj
->local_using_directives
;
13941 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13944 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13946 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13947 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13948 CORE_ADDR pc
, baseaddr
;
13949 struct attribute
*attr
;
13950 struct call_site
*call_site
, call_site_local
;
13953 struct die_info
*child_die
;
13955 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13957 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13960 /* This was a pre-DWARF-5 GNU extension alias
13961 for DW_AT_call_return_pc. */
13962 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13966 complaint (&symfile_complaints
,
13967 _("missing DW_AT_call_return_pc for DW_TAG_call_site "
13968 "DIE %s [in module %s]"),
13969 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13972 pc
= attr_value_as_address (attr
) + baseaddr
;
13973 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13975 if (cu
->call_site_htab
== NULL
)
13976 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13977 NULL
, &objfile
->objfile_obstack
,
13978 hashtab_obstack_allocate
, NULL
);
13979 call_site_local
.pc
= pc
;
13980 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13983 complaint (&symfile_complaints
,
13984 _("Duplicate PC %s for DW_TAG_call_site "
13985 "DIE %s [in module %s]"),
13986 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13987 objfile_name (objfile
));
13991 /* Count parameters at the caller. */
13994 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13995 child_die
= sibling_die (child_die
))
13997 if (child_die
->tag
!= DW_TAG_call_site_parameter
13998 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14000 complaint (&symfile_complaints
,
14001 _("Tag %d is not DW_TAG_call_site_parameter in "
14002 "DW_TAG_call_site child DIE %s [in module %s]"),
14003 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
14004 objfile_name (objfile
));
14012 = ((struct call_site
*)
14013 obstack_alloc (&objfile
->objfile_obstack
,
14014 sizeof (*call_site
)
14015 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
14017 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
14018 call_site
->pc
= pc
;
14020 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
14021 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
14023 struct die_info
*func_die
;
14025 /* Skip also over DW_TAG_inlined_subroutine. */
14026 for (func_die
= die
->parent
;
14027 func_die
&& func_die
->tag
!= DW_TAG_subprogram
14028 && func_die
->tag
!= DW_TAG_subroutine_type
;
14029 func_die
= func_die
->parent
);
14031 /* DW_AT_call_all_calls is a superset
14032 of DW_AT_call_all_tail_calls. */
14034 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
14035 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
14036 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
14037 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
14039 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
14040 not complete. But keep CALL_SITE for look ups via call_site_htab,
14041 both the initial caller containing the real return address PC and
14042 the final callee containing the current PC of a chain of tail
14043 calls do not need to have the tail call list complete. But any
14044 function candidate for a virtual tail call frame searched via
14045 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
14046 determined unambiguously. */
14050 struct type
*func_type
= NULL
;
14053 func_type
= get_die_type (func_die
, cu
);
14054 if (func_type
!= NULL
)
14056 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
14058 /* Enlist this call site to the function. */
14059 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
14060 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
14063 complaint (&symfile_complaints
,
14064 _("Cannot find function owning DW_TAG_call_site "
14065 "DIE %s [in module %s]"),
14066 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14070 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
14072 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
14074 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
14077 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
14078 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14080 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
14081 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
14082 /* Keep NULL DWARF_BLOCK. */;
14083 else if (attr_form_is_block (attr
))
14085 struct dwarf2_locexpr_baton
*dlbaton
;
14087 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
14088 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14089 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14090 dlbaton
->per_cu
= cu
->per_cu
;
14092 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
14094 else if (attr_form_is_ref (attr
))
14096 struct dwarf2_cu
*target_cu
= cu
;
14097 struct die_info
*target_die
;
14099 target_die
= follow_die_ref (die
, attr
, &target_cu
);
14100 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
14101 if (die_is_declaration (target_die
, target_cu
))
14103 const char *target_physname
;
14105 /* Prefer the mangled name; otherwise compute the demangled one. */
14106 target_physname
= dw2_linkage_name (target_die
, target_cu
);
14107 if (target_physname
== NULL
)
14108 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
14109 if (target_physname
== NULL
)
14110 complaint (&symfile_complaints
,
14111 _("DW_AT_call_target target DIE has invalid "
14112 "physname, for referencing DIE %s [in module %s]"),
14113 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14115 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
14121 /* DW_AT_entry_pc should be preferred. */
14122 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
14123 <= PC_BOUNDS_INVALID
)
14124 complaint (&symfile_complaints
,
14125 _("DW_AT_call_target target DIE has invalid "
14126 "low pc, for referencing DIE %s [in module %s]"),
14127 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14130 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14131 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
14136 complaint (&symfile_complaints
,
14137 _("DW_TAG_call_site DW_AT_call_target is neither "
14138 "block nor reference, for DIE %s [in module %s]"),
14139 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14141 call_site
->per_cu
= cu
->per_cu
;
14143 for (child_die
= die
->child
;
14144 child_die
&& child_die
->tag
;
14145 child_die
= sibling_die (child_die
))
14147 struct call_site_parameter
*parameter
;
14148 struct attribute
*loc
, *origin
;
14150 if (child_die
->tag
!= DW_TAG_call_site_parameter
14151 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14153 /* Already printed the complaint above. */
14157 gdb_assert (call_site
->parameter_count
< nparams
);
14158 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
14160 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
14161 specifies DW_TAG_formal_parameter. Value of the data assumed for the
14162 register is contained in DW_AT_call_value. */
14164 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
14165 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
14166 if (origin
== NULL
)
14168 /* This was a pre-DWARF-5 GNU extension alias
14169 for DW_AT_call_parameter. */
14170 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
14172 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
14174 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
14176 sect_offset sect_off
14177 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
14178 if (!offset_in_cu_p (&cu
->header
, sect_off
))
14180 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
14181 binding can be done only inside one CU. Such referenced DIE
14182 therefore cannot be even moved to DW_TAG_partial_unit. */
14183 complaint (&symfile_complaints
,
14184 _("DW_AT_call_parameter offset is not in CU for "
14185 "DW_TAG_call_site child DIE %s [in module %s]"),
14186 sect_offset_str (child_die
->sect_off
),
14187 objfile_name (objfile
));
14190 parameter
->u
.param_cu_off
14191 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
14193 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
14195 complaint (&symfile_complaints
,
14196 _("No DW_FORM_block* DW_AT_location for "
14197 "DW_TAG_call_site child DIE %s [in module %s]"),
14198 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
14203 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
14204 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
14205 if (parameter
->u
.dwarf_reg
!= -1)
14206 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
14207 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
14208 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
14209 ¶meter
->u
.fb_offset
))
14210 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
14213 complaint (&symfile_complaints
,
14214 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
14215 "for DW_FORM_block* DW_AT_location is supported for "
14216 "DW_TAG_call_site child DIE %s "
14218 sect_offset_str (child_die
->sect_off
),
14219 objfile_name (objfile
));
14224 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
14226 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
14227 if (!attr_form_is_block (attr
))
14229 complaint (&symfile_complaints
,
14230 _("No DW_FORM_block* DW_AT_call_value for "
14231 "DW_TAG_call_site child DIE %s [in module %s]"),
14232 sect_offset_str (child_die
->sect_off
),
14233 objfile_name (objfile
));
14236 parameter
->value
= DW_BLOCK (attr
)->data
;
14237 parameter
->value_size
= DW_BLOCK (attr
)->size
;
14239 /* Parameters are not pre-cleared by memset above. */
14240 parameter
->data_value
= NULL
;
14241 parameter
->data_value_size
= 0;
14242 call_site
->parameter_count
++;
14244 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
14246 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
14249 if (!attr_form_is_block (attr
))
14250 complaint (&symfile_complaints
,
14251 _("No DW_FORM_block* DW_AT_call_data_value for "
14252 "DW_TAG_call_site child DIE %s [in module %s]"),
14253 sect_offset_str (child_die
->sect_off
),
14254 objfile_name (objfile
));
14257 parameter
->data_value
= DW_BLOCK (attr
)->data
;
14258 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
14264 /* Helper function for read_variable. If DIE represents a virtual
14265 table, then return the type of the concrete object that is
14266 associated with the virtual table. Otherwise, return NULL. */
14268 static struct type
*
14269 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14271 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14275 /* Find the type DIE. */
14276 struct die_info
*type_die
= NULL
;
14277 struct dwarf2_cu
*type_cu
= cu
;
14279 if (attr_form_is_ref (attr
))
14280 type_die
= follow_die_ref (die
, attr
, &type_cu
);
14281 if (type_die
== NULL
)
14284 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
14286 return die_containing_type (type_die
, type_cu
);
14289 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
14292 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
14294 struct rust_vtable_symbol
*storage
= NULL
;
14296 if (cu
->language
== language_rust
)
14298 struct type
*containing_type
= rust_containing_type (die
, cu
);
14300 if (containing_type
!= NULL
)
14302 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14304 storage
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
14305 struct rust_vtable_symbol
);
14306 initialize_objfile_symbol (storage
);
14307 storage
->concrete_type
= containing_type
;
14308 storage
->subclass
= SYMBOL_RUST_VTABLE
;
14312 new_symbol (die
, NULL
, cu
, storage
);
14315 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14316 reading .debug_rnglists.
14317 Callback's type should be:
14318 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14319 Return true if the attributes are present and valid, otherwise,
14322 template <typename Callback
>
14324 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14325 Callback
&&callback
)
14327 struct dwarf2_per_objfile
*dwarf2_per_objfile
14328 = cu
->per_cu
->dwarf2_per_objfile
;
14329 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14330 bfd
*obfd
= objfile
->obfd
;
14331 /* Base address selection entry. */
14334 const gdb_byte
*buffer
;
14335 CORE_ADDR baseaddr
;
14336 bool overflow
= false;
14338 found_base
= cu
->base_known
;
14339 base
= cu
->base_address
;
14341 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->rnglists
);
14342 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
14344 complaint (&symfile_complaints
,
14345 _("Offset %d out of bounds for DW_AT_ranges attribute"),
14349 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
14351 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14355 /* Initialize it due to a false compiler warning. */
14356 CORE_ADDR range_beginning
= 0, range_end
= 0;
14357 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
14358 + dwarf2_per_objfile
->rnglists
.size
);
14359 unsigned int bytes_read
;
14361 if (buffer
== buf_end
)
14366 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14369 case DW_RLE_end_of_list
:
14371 case DW_RLE_base_address
:
14372 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14377 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14379 buffer
+= bytes_read
;
14381 case DW_RLE_start_length
:
14382 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14387 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14388 buffer
+= bytes_read
;
14389 range_end
= (range_beginning
14390 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14391 buffer
+= bytes_read
;
14392 if (buffer
> buf_end
)
14398 case DW_RLE_offset_pair
:
14399 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14400 buffer
+= bytes_read
;
14401 if (buffer
> buf_end
)
14406 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14407 buffer
+= bytes_read
;
14408 if (buffer
> buf_end
)
14414 case DW_RLE_start_end
:
14415 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14420 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14421 buffer
+= bytes_read
;
14422 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14423 buffer
+= bytes_read
;
14426 complaint (&symfile_complaints
,
14427 _("Invalid .debug_rnglists data (no base address)"));
14430 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14432 if (rlet
== DW_RLE_base_address
)
14437 /* We have no valid base address for the ranges
14439 complaint (&symfile_complaints
,
14440 _("Invalid .debug_rnglists data (no base address)"));
14444 if (range_beginning
> range_end
)
14446 /* Inverted range entries are invalid. */
14447 complaint (&symfile_complaints
,
14448 _("Invalid .debug_rnglists data (inverted range)"));
14452 /* Empty range entries have no effect. */
14453 if (range_beginning
== range_end
)
14456 range_beginning
+= base
;
14459 /* A not-uncommon case of bad debug info.
14460 Don't pollute the addrmap with bad data. */
14461 if (range_beginning
+ baseaddr
== 0
14462 && !dwarf2_per_objfile
->has_section_at_zero
)
14464 complaint (&symfile_complaints
,
14465 _(".debug_rnglists entry has start address of zero"
14466 " [in module %s]"), objfile_name (objfile
));
14470 callback (range_beginning
, range_end
);
14475 complaint (&symfile_complaints
,
14476 _("Offset %d is not terminated "
14477 "for DW_AT_ranges attribute"),
14485 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14486 Callback's type should be:
14487 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14488 Return 1 if the attributes are present and valid, otherwise, return 0. */
14490 template <typename Callback
>
14492 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
14493 Callback
&&callback
)
14495 struct dwarf2_per_objfile
*dwarf2_per_objfile
14496 = cu
->per_cu
->dwarf2_per_objfile
;
14497 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14498 struct comp_unit_head
*cu_header
= &cu
->header
;
14499 bfd
*obfd
= objfile
->obfd
;
14500 unsigned int addr_size
= cu_header
->addr_size
;
14501 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14502 /* Base address selection entry. */
14505 unsigned int dummy
;
14506 const gdb_byte
*buffer
;
14507 CORE_ADDR baseaddr
;
14509 if (cu_header
->version
>= 5)
14510 return dwarf2_rnglists_process (offset
, cu
, callback
);
14512 found_base
= cu
->base_known
;
14513 base
= cu
->base_address
;
14515 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
14516 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
14518 complaint (&symfile_complaints
,
14519 _("Offset %d out of bounds for DW_AT_ranges attribute"),
14523 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
14525 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14529 CORE_ADDR range_beginning
, range_end
;
14531 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
14532 buffer
+= addr_size
;
14533 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
14534 buffer
+= addr_size
;
14535 offset
+= 2 * addr_size
;
14537 /* An end of list marker is a pair of zero addresses. */
14538 if (range_beginning
== 0 && range_end
== 0)
14539 /* Found the end of list entry. */
14542 /* Each base address selection entry is a pair of 2 values.
14543 The first is the largest possible address, the second is
14544 the base address. Check for a base address here. */
14545 if ((range_beginning
& mask
) == mask
)
14547 /* If we found the largest possible address, then we already
14548 have the base address in range_end. */
14556 /* We have no valid base address for the ranges
14558 complaint (&symfile_complaints
,
14559 _("Invalid .debug_ranges data (no base address)"));
14563 if (range_beginning
> range_end
)
14565 /* Inverted range entries are invalid. */
14566 complaint (&symfile_complaints
,
14567 _("Invalid .debug_ranges data (inverted range)"));
14571 /* Empty range entries have no effect. */
14572 if (range_beginning
== range_end
)
14575 range_beginning
+= base
;
14578 /* A not-uncommon case of bad debug info.
14579 Don't pollute the addrmap with bad data. */
14580 if (range_beginning
+ baseaddr
== 0
14581 && !dwarf2_per_objfile
->has_section_at_zero
)
14583 complaint (&symfile_complaints
,
14584 _(".debug_ranges entry has start address of zero"
14585 " [in module %s]"), objfile_name (objfile
));
14589 callback (range_beginning
, range_end
);
14595 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14596 Return 1 if the attributes are present and valid, otherwise, return 0.
14597 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14600 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14601 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14602 struct partial_symtab
*ranges_pst
)
14604 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14605 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14606 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
14607 SECT_OFF_TEXT (objfile
));
14610 CORE_ADDR high
= 0;
14613 retval
= dwarf2_ranges_process (offset
, cu
,
14614 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14616 if (ranges_pst
!= NULL
)
14621 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
14622 range_beginning
+ baseaddr
);
14623 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
14624 range_end
+ baseaddr
);
14625 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
14629 /* FIXME: This is recording everything as a low-high
14630 segment of consecutive addresses. We should have a
14631 data structure for discontiguous block ranges
14635 low
= range_beginning
;
14641 if (range_beginning
< low
)
14642 low
= range_beginning
;
14643 if (range_end
> high
)
14651 /* If the first entry is an end-of-list marker, the range
14652 describes an empty scope, i.e. no instructions. */
14658 *high_return
= high
;
14662 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14663 definition for the return value. *LOWPC and *HIGHPC are set iff
14664 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14666 static enum pc_bounds_kind
14667 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14668 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14669 struct partial_symtab
*pst
)
14671 struct dwarf2_per_objfile
*dwarf2_per_objfile
14672 = cu
->per_cu
->dwarf2_per_objfile
;
14673 struct attribute
*attr
;
14674 struct attribute
*attr_high
;
14676 CORE_ADDR high
= 0;
14677 enum pc_bounds_kind ret
;
14679 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14682 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14685 low
= attr_value_as_address (attr
);
14686 high
= attr_value_as_address (attr_high
);
14687 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14691 /* Found high w/o low attribute. */
14692 return PC_BOUNDS_INVALID
;
14694 /* Found consecutive range of addresses. */
14695 ret
= PC_BOUNDS_HIGH_LOW
;
14699 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14702 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
14703 We take advantage of the fact that DW_AT_ranges does not appear
14704 in DW_TAG_compile_unit of DWO files. */
14705 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14706 unsigned int ranges_offset
= (DW_UNSND (attr
)
14707 + (need_ranges_base
14711 /* Value of the DW_AT_ranges attribute is the offset in the
14712 .debug_ranges section. */
14713 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14714 return PC_BOUNDS_INVALID
;
14715 /* Found discontinuous range of addresses. */
14716 ret
= PC_BOUNDS_RANGES
;
14719 return PC_BOUNDS_NOT_PRESENT
;
14722 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14724 return PC_BOUNDS_INVALID
;
14726 /* When using the GNU linker, .gnu.linkonce. sections are used to
14727 eliminate duplicate copies of functions and vtables and such.
14728 The linker will arbitrarily choose one and discard the others.
14729 The AT_*_pc values for such functions refer to local labels in
14730 these sections. If the section from that file was discarded, the
14731 labels are not in the output, so the relocs get a value of 0.
14732 If this is a discarded function, mark the pc bounds as invalid,
14733 so that GDB will ignore it. */
14734 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
14735 return PC_BOUNDS_INVALID
;
14743 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14744 its low and high PC addresses. Do nothing if these addresses could not
14745 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14746 and HIGHPC to the high address if greater than HIGHPC. */
14749 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14750 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14751 struct dwarf2_cu
*cu
)
14753 CORE_ADDR low
, high
;
14754 struct die_info
*child
= die
->child
;
14756 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14758 *lowpc
= std::min (*lowpc
, low
);
14759 *highpc
= std::max (*highpc
, high
);
14762 /* If the language does not allow nested subprograms (either inside
14763 subprograms or lexical blocks), we're done. */
14764 if (cu
->language
!= language_ada
)
14767 /* Check all the children of the given DIE. If it contains nested
14768 subprograms, then check their pc bounds. Likewise, we need to
14769 check lexical blocks as well, as they may also contain subprogram
14771 while (child
&& child
->tag
)
14773 if (child
->tag
== DW_TAG_subprogram
14774 || child
->tag
== DW_TAG_lexical_block
)
14775 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14776 child
= sibling_die (child
);
14780 /* Get the low and high pc's represented by the scope DIE, and store
14781 them in *LOWPC and *HIGHPC. If the correct values can't be
14782 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14785 get_scope_pc_bounds (struct die_info
*die
,
14786 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14787 struct dwarf2_cu
*cu
)
14789 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14790 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14791 CORE_ADDR current_low
, current_high
;
14793 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14794 >= PC_BOUNDS_RANGES
)
14796 best_low
= current_low
;
14797 best_high
= current_high
;
14801 struct die_info
*child
= die
->child
;
14803 while (child
&& child
->tag
)
14805 switch (child
->tag
) {
14806 case DW_TAG_subprogram
:
14807 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14809 case DW_TAG_namespace
:
14810 case DW_TAG_module
:
14811 /* FIXME: carlton/2004-01-16: Should we do this for
14812 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14813 that current GCC's always emit the DIEs corresponding
14814 to definitions of methods of classes as children of a
14815 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14816 the DIEs giving the declarations, which could be
14817 anywhere). But I don't see any reason why the
14818 standards says that they have to be there. */
14819 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14821 if (current_low
!= ((CORE_ADDR
) -1))
14823 best_low
= std::min (best_low
, current_low
);
14824 best_high
= std::max (best_high
, current_high
);
14832 child
= sibling_die (child
);
14837 *highpc
= best_high
;
14840 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14844 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14845 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14847 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14848 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14849 struct attribute
*attr
;
14850 struct attribute
*attr_high
;
14852 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14855 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14858 CORE_ADDR low
= attr_value_as_address (attr
);
14859 CORE_ADDR high
= attr_value_as_address (attr_high
);
14861 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14864 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14865 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14866 record_block_range (block
, low
, high
- 1);
14870 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14873 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
14874 We take advantage of the fact that DW_AT_ranges does not appear
14875 in DW_TAG_compile_unit of DWO files. */
14876 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14878 /* The value of the DW_AT_ranges attribute is the offset of the
14879 address range list in the .debug_ranges section. */
14880 unsigned long offset
= (DW_UNSND (attr
)
14881 + (need_ranges_base
? cu
->ranges_base
: 0));
14882 const gdb_byte
*buffer
;
14884 /* For some target architectures, but not others, the
14885 read_address function sign-extends the addresses it returns.
14886 To recognize base address selection entries, we need a
14888 unsigned int addr_size
= cu
->header
.addr_size
;
14889 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14891 /* The base address, to which the next pair is relative. Note
14892 that this 'base' is a DWARF concept: most entries in a range
14893 list are relative, to reduce the number of relocs against the
14894 debugging information. This is separate from this function's
14895 'baseaddr' argument, which GDB uses to relocate debugging
14896 information from a shared library based on the address at
14897 which the library was loaded. */
14898 CORE_ADDR base
= cu
->base_address
;
14899 int base_known
= cu
->base_known
;
14901 dwarf2_ranges_process (offset
, cu
,
14902 [&] (CORE_ADDR start
, CORE_ADDR end
)
14906 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14907 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14908 record_block_range (block
, start
, end
- 1);
14913 /* Check whether the producer field indicates either of GCC < 4.6, or the
14914 Intel C/C++ compiler, and cache the result in CU. */
14917 check_producer (struct dwarf2_cu
*cu
)
14921 if (cu
->producer
== NULL
)
14923 /* For unknown compilers expect their behavior is DWARF version
14926 GCC started to support .debug_types sections by -gdwarf-4 since
14927 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14928 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14929 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14930 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14932 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14934 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14935 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14937 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14938 cu
->producer_is_icc_lt_14
= major
< 14;
14941 /* For other non-GCC compilers, expect their behavior is DWARF version
14945 cu
->checked_producer
= 1;
14948 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14949 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14950 during 4.6.0 experimental. */
14953 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14955 if (!cu
->checked_producer
)
14956 check_producer (cu
);
14958 return cu
->producer_is_gxx_lt_4_6
;
14961 /* Return the default accessibility type if it is not overriden by
14962 DW_AT_accessibility. */
14964 static enum dwarf_access_attribute
14965 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14967 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14969 /* The default DWARF 2 accessibility for members is public, the default
14970 accessibility for inheritance is private. */
14972 if (die
->tag
!= DW_TAG_inheritance
)
14973 return DW_ACCESS_public
;
14975 return DW_ACCESS_private
;
14979 /* DWARF 3+ defines the default accessibility a different way. The same
14980 rules apply now for DW_TAG_inheritance as for the members and it only
14981 depends on the container kind. */
14983 if (die
->parent
->tag
== DW_TAG_class_type
)
14984 return DW_ACCESS_private
;
14986 return DW_ACCESS_public
;
14990 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14991 offset. If the attribute was not found return 0, otherwise return
14992 1. If it was found but could not properly be handled, set *OFFSET
14996 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14999 struct attribute
*attr
;
15001 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
15006 /* Note that we do not check for a section offset first here.
15007 This is because DW_AT_data_member_location is new in DWARF 4,
15008 so if we see it, we can assume that a constant form is really
15009 a constant and not a section offset. */
15010 if (attr_form_is_constant (attr
))
15011 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
15012 else if (attr_form_is_section_offset (attr
))
15013 dwarf2_complex_location_expr_complaint ();
15014 else if (attr_form_is_block (attr
))
15015 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15017 dwarf2_complex_location_expr_complaint ();
15025 /* Add an aggregate field to the field list. */
15028 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
15029 struct dwarf2_cu
*cu
)
15031 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15032 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15033 struct nextfield
*new_field
;
15034 struct attribute
*attr
;
15036 const char *fieldname
= "";
15038 if (die
->tag
== DW_TAG_inheritance
)
15040 fip
->baseclasses
.emplace_back ();
15041 new_field
= &fip
->baseclasses
.back ();
15045 fip
->fields
.emplace_back ();
15046 new_field
= &fip
->fields
.back ();
15051 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15053 new_field
->accessibility
= DW_UNSND (attr
);
15055 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
15056 if (new_field
->accessibility
!= DW_ACCESS_public
)
15057 fip
->non_public_fields
= 1;
15059 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15061 new_field
->virtuality
= DW_UNSND (attr
);
15063 new_field
->virtuality
= DW_VIRTUALITY_none
;
15065 fp
= &new_field
->field
;
15067 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
15071 /* Data member other than a C++ static data member. */
15073 /* Get type of field. */
15074 fp
->type
= die_type (die
, cu
);
15076 SET_FIELD_BITPOS (*fp
, 0);
15078 /* Get bit size of field (zero if none). */
15079 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
15082 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
15086 FIELD_BITSIZE (*fp
) = 0;
15089 /* Get bit offset of field. */
15090 if (handle_data_member_location (die
, cu
, &offset
))
15091 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15092 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
15095 if (gdbarch_bits_big_endian (gdbarch
))
15097 /* For big endian bits, the DW_AT_bit_offset gives the
15098 additional bit offset from the MSB of the containing
15099 anonymous object to the MSB of the field. We don't
15100 have to do anything special since we don't need to
15101 know the size of the anonymous object. */
15102 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
15106 /* For little endian bits, compute the bit offset to the
15107 MSB of the anonymous object, subtract off the number of
15108 bits from the MSB of the field to the MSB of the
15109 object, and then subtract off the number of bits of
15110 the field itself. The result is the bit offset of
15111 the LSB of the field. */
15112 int anonymous_size
;
15113 int bit_offset
= DW_UNSND (attr
);
15115 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15118 /* The size of the anonymous object containing
15119 the bit field is explicit, so use the
15120 indicated size (in bytes). */
15121 anonymous_size
= DW_UNSND (attr
);
15125 /* The size of the anonymous object containing
15126 the bit field must be inferred from the type
15127 attribute of the data member containing the
15129 anonymous_size
= TYPE_LENGTH (fp
->type
);
15131 SET_FIELD_BITPOS (*fp
,
15132 (FIELD_BITPOS (*fp
)
15133 + anonymous_size
* bits_per_byte
15134 - bit_offset
- FIELD_BITSIZE (*fp
)));
15137 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15139 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15140 + dwarf2_get_attr_constant_value (attr
, 0)));
15142 /* Get name of field. */
15143 fieldname
= dwarf2_name (die
, cu
);
15144 if (fieldname
== NULL
)
15147 /* The name is already allocated along with this objfile, so we don't
15148 need to duplicate it for the type. */
15149 fp
->name
= fieldname
;
15151 /* Change accessibility for artificial fields (e.g. virtual table
15152 pointer or virtual base class pointer) to private. */
15153 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
15155 FIELD_ARTIFICIAL (*fp
) = 1;
15156 new_field
->accessibility
= DW_ACCESS_private
;
15157 fip
->non_public_fields
= 1;
15160 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
15162 /* C++ static member. */
15164 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
15165 is a declaration, but all versions of G++ as of this writing
15166 (so through at least 3.2.1) incorrectly generate
15167 DW_TAG_variable tags. */
15169 const char *physname
;
15171 /* Get name of field. */
15172 fieldname
= dwarf2_name (die
, cu
);
15173 if (fieldname
== NULL
)
15176 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15178 /* Only create a symbol if this is an external value.
15179 new_symbol checks this and puts the value in the global symbol
15180 table, which we want. If it is not external, new_symbol
15181 will try to put the value in cu->list_in_scope which is wrong. */
15182 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
15184 /* A static const member, not much different than an enum as far as
15185 we're concerned, except that we can support more types. */
15186 new_symbol (die
, NULL
, cu
);
15189 /* Get physical name. */
15190 physname
= dwarf2_physname (fieldname
, die
, cu
);
15192 /* The name is already allocated along with this objfile, so we don't
15193 need to duplicate it for the type. */
15194 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
15195 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15196 FIELD_NAME (*fp
) = fieldname
;
15198 else if (die
->tag
== DW_TAG_inheritance
)
15202 /* C++ base class field. */
15203 if (handle_data_member_location (die
, cu
, &offset
))
15204 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15205 FIELD_BITSIZE (*fp
) = 0;
15206 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15207 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
15209 else if (die
->tag
== DW_TAG_variant_part
)
15211 /* process_structure_scope will treat this DIE as a union. */
15212 process_structure_scope (die
, cu
);
15214 /* The variant part is relative to the start of the enclosing
15216 SET_FIELD_BITPOS (*fp
, 0);
15217 fp
->type
= get_die_type (die
, cu
);
15218 fp
->artificial
= 1;
15219 fp
->name
= "<<variant>>";
15222 gdb_assert_not_reached ("missing case in dwarf2_add_field");
15225 /* Can the type given by DIE define another type? */
15228 type_can_define_types (const struct die_info
*die
)
15232 case DW_TAG_typedef
:
15233 case DW_TAG_class_type
:
15234 case DW_TAG_structure_type
:
15235 case DW_TAG_union_type
:
15236 case DW_TAG_enumeration_type
:
15244 /* Add a type definition defined in the scope of the FIP's class. */
15247 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
15248 struct dwarf2_cu
*cu
)
15250 struct decl_field fp
;
15251 memset (&fp
, 0, sizeof (fp
));
15253 gdb_assert (type_can_define_types (die
));
15255 /* Get name of field. NULL is okay here, meaning an anonymous type. */
15256 fp
.name
= dwarf2_name (die
, cu
);
15257 fp
.type
= read_type_die (die
, cu
);
15259 /* Save accessibility. */
15260 enum dwarf_access_attribute accessibility
;
15261 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15263 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15265 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15266 switch (accessibility
)
15268 case DW_ACCESS_public
:
15269 /* The assumed value if neither private nor protected. */
15271 case DW_ACCESS_private
:
15274 case DW_ACCESS_protected
:
15275 fp
.is_protected
= 1;
15278 complaint (&symfile_complaints
,
15279 _("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
15282 if (die
->tag
== DW_TAG_typedef
)
15283 fip
->typedef_field_list
.push_back (fp
);
15285 fip
->nested_types_list
.push_back (fp
);
15288 /* Create the vector of fields, and attach it to the type. */
15291 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15292 struct dwarf2_cu
*cu
)
15294 int nfields
= fip
->nfields
;
15296 /* Record the field count, allocate space for the array of fields,
15297 and create blank accessibility bitfields if necessary. */
15298 TYPE_NFIELDS (type
) = nfields
;
15299 TYPE_FIELDS (type
) = (struct field
*)
15300 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
15302 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15304 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15306 TYPE_FIELD_PRIVATE_BITS (type
) =
15307 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15308 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15310 TYPE_FIELD_PROTECTED_BITS (type
) =
15311 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15312 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15314 TYPE_FIELD_IGNORE_BITS (type
) =
15315 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15316 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15319 /* If the type has baseclasses, allocate and clear a bit vector for
15320 TYPE_FIELD_VIRTUAL_BITS. */
15321 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15323 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15324 unsigned char *pointer
;
15326 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15327 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15328 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15329 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15330 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15333 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
15335 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
15337 for (int index
= 0; index
< nfields
; ++index
)
15339 struct nextfield
&field
= fip
->fields
[index
];
15341 if (field
.variant
.is_discriminant
)
15342 di
->discriminant_index
= index
;
15343 else if (field
.variant
.default_branch
)
15344 di
->default_index
= index
;
15346 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
15350 /* Copy the saved-up fields into the field vector. */
15351 for (int i
= 0; i
< nfields
; ++i
)
15353 struct nextfield
&field
15354 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15355 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15357 TYPE_FIELD (type
, i
) = field
.field
;
15358 switch (field
.accessibility
)
15360 case DW_ACCESS_private
:
15361 if (cu
->language
!= language_ada
)
15362 SET_TYPE_FIELD_PRIVATE (type
, i
);
15365 case DW_ACCESS_protected
:
15366 if (cu
->language
!= language_ada
)
15367 SET_TYPE_FIELD_PROTECTED (type
, i
);
15370 case DW_ACCESS_public
:
15374 /* Unknown accessibility. Complain and treat it as public. */
15376 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
15377 field
.accessibility
);
15381 if (i
< fip
->baseclasses
.size ())
15383 switch (field
.virtuality
)
15385 case DW_VIRTUALITY_virtual
:
15386 case DW_VIRTUALITY_pure_virtual
:
15387 if (cu
->language
== language_ada
)
15388 error (_("unexpected virtuality in component of Ada type"));
15389 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15396 /* Return true if this member function is a constructor, false
15400 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15402 const char *fieldname
;
15403 const char *type_name
;
15406 if (die
->parent
== NULL
)
15409 if (die
->parent
->tag
!= DW_TAG_structure_type
15410 && die
->parent
->tag
!= DW_TAG_union_type
15411 && die
->parent
->tag
!= DW_TAG_class_type
)
15414 fieldname
= dwarf2_name (die
, cu
);
15415 type_name
= dwarf2_name (die
->parent
, cu
);
15416 if (fieldname
== NULL
|| type_name
== NULL
)
15419 len
= strlen (fieldname
);
15420 return (strncmp (fieldname
, type_name
, len
) == 0
15421 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15424 /* Add a member function to the proper fieldlist. */
15427 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15428 struct type
*type
, struct dwarf2_cu
*cu
)
15430 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15431 struct attribute
*attr
;
15433 struct fnfieldlist
*flp
= nullptr;
15434 struct fn_field
*fnp
;
15435 const char *fieldname
;
15436 struct type
*this_type
;
15437 enum dwarf_access_attribute accessibility
;
15439 if (cu
->language
== language_ada
)
15440 error (_("unexpected member function in Ada type"));
15442 /* Get name of member function. */
15443 fieldname
= dwarf2_name (die
, cu
);
15444 if (fieldname
== NULL
)
15447 /* Look up member function name in fieldlist. */
15448 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15450 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15452 flp
= &fip
->fnfieldlists
[i
];
15457 /* Create a new fnfieldlist if necessary. */
15458 if (flp
== nullptr)
15460 fip
->fnfieldlists
.emplace_back ();
15461 flp
= &fip
->fnfieldlists
.back ();
15462 flp
->name
= fieldname
;
15463 i
= fip
->fnfieldlists
.size () - 1;
15466 /* Create a new member function field and add it to the vector of
15468 flp
->fnfields
.emplace_back ();
15469 fnp
= &flp
->fnfields
.back ();
15471 /* Delay processing of the physname until later. */
15472 if (cu
->language
== language_cplus
)
15473 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15477 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15478 fnp
->physname
= physname
? physname
: "";
15481 fnp
->type
= alloc_type (objfile
);
15482 this_type
= read_type_die (die
, cu
);
15483 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
15485 int nparams
= TYPE_NFIELDS (this_type
);
15487 /* TYPE is the domain of this method, and THIS_TYPE is the type
15488 of the method itself (TYPE_CODE_METHOD). */
15489 smash_to_method_type (fnp
->type
, type
,
15490 TYPE_TARGET_TYPE (this_type
),
15491 TYPE_FIELDS (this_type
),
15492 TYPE_NFIELDS (this_type
),
15493 TYPE_VARARGS (this_type
));
15495 /* Handle static member functions.
15496 Dwarf2 has no clean way to discern C++ static and non-static
15497 member functions. G++ helps GDB by marking the first
15498 parameter for non-static member functions (which is the this
15499 pointer) as artificial. We obtain this information from
15500 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15501 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15502 fnp
->voffset
= VOFFSET_STATIC
;
15505 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
15506 dwarf2_full_name (fieldname
, die
, cu
));
15508 /* Get fcontext from DW_AT_containing_type if present. */
15509 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15510 fnp
->fcontext
= die_containing_type (die
, cu
);
15512 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15513 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15515 /* Get accessibility. */
15516 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15518 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15520 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15521 switch (accessibility
)
15523 case DW_ACCESS_private
:
15524 fnp
->is_private
= 1;
15526 case DW_ACCESS_protected
:
15527 fnp
->is_protected
= 1;
15531 /* Check for artificial methods. */
15532 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15533 if (attr
&& DW_UNSND (attr
) != 0)
15534 fnp
->is_artificial
= 1;
15536 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15538 /* Get index in virtual function table if it is a virtual member
15539 function. For older versions of GCC, this is an offset in the
15540 appropriate virtual table, as specified by DW_AT_containing_type.
15541 For everyone else, it is an expression to be evaluated relative
15542 to the object address. */
15544 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15547 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
15549 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15551 /* Old-style GCC. */
15552 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15554 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15555 || (DW_BLOCK (attr
)->size
> 1
15556 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15557 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15559 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15560 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15561 dwarf2_complex_location_expr_complaint ();
15563 fnp
->voffset
/= cu
->header
.addr_size
;
15567 dwarf2_complex_location_expr_complaint ();
15569 if (!fnp
->fcontext
)
15571 /* If there is no `this' field and no DW_AT_containing_type,
15572 we cannot actually find a base class context for the
15574 if (TYPE_NFIELDS (this_type
) == 0
15575 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15577 complaint (&symfile_complaints
,
15578 _("cannot determine context for virtual member "
15579 "function \"%s\" (offset %s)"),
15580 fieldname
, sect_offset_str (die
->sect_off
));
15585 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15589 else if (attr_form_is_section_offset (attr
))
15591 dwarf2_complex_location_expr_complaint ();
15595 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15601 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15602 if (attr
&& DW_UNSND (attr
))
15604 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15605 complaint (&symfile_complaints
,
15606 _("Member function \"%s\" (offset %s) is virtual "
15607 "but the vtable offset is not specified"),
15608 fieldname
, sect_offset_str (die
->sect_off
));
15609 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15610 TYPE_CPLUS_DYNAMIC (type
) = 1;
15615 /* Create the vector of member function fields, and attach it to the type. */
15618 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15619 struct dwarf2_cu
*cu
)
15621 if (cu
->language
== language_ada
)
15622 error (_("unexpected member functions in Ada type"));
15624 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15625 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15627 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15629 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15631 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15632 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15634 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15635 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15636 fn_flp
->fn_fields
= (struct fn_field
*)
15637 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15639 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15640 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15643 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15646 /* Returns non-zero if NAME is the name of a vtable member in CU's
15647 language, zero otherwise. */
15649 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15651 static const char vptr
[] = "_vptr";
15653 /* Look for the C++ form of the vtable. */
15654 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15660 /* GCC outputs unnamed structures that are really pointers to member
15661 functions, with the ABI-specified layout. If TYPE describes
15662 such a structure, smash it into a member function type.
15664 GCC shouldn't do this; it should just output pointer to member DIEs.
15665 This is GCC PR debug/28767. */
15668 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15670 struct type
*pfn_type
, *self_type
, *new_type
;
15672 /* Check for a structure with no name and two children. */
15673 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
15676 /* Check for __pfn and __delta members. */
15677 if (TYPE_FIELD_NAME (type
, 0) == NULL
15678 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15679 || TYPE_FIELD_NAME (type
, 1) == NULL
15680 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15683 /* Find the type of the method. */
15684 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15685 if (pfn_type
== NULL
15686 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
15687 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
15690 /* Look for the "this" argument. */
15691 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15692 if (TYPE_NFIELDS (pfn_type
) == 0
15693 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15694 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
15697 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15698 new_type
= alloc_type (objfile
);
15699 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15700 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
15701 TYPE_VARARGS (pfn_type
));
15702 smash_to_methodptr_type (type
, new_type
);
15706 /* Called when we find the DIE that starts a structure or union scope
15707 (definition) to create a type for the structure or union. Fill in
15708 the type's name and general properties; the members will not be
15709 processed until process_structure_scope. A symbol table entry for
15710 the type will also not be done until process_structure_scope (assuming
15711 the type has a name).
15713 NOTE: we need to call these functions regardless of whether or not the
15714 DIE has a DW_AT_name attribute, since it might be an anonymous
15715 structure or union. This gets the type entered into our set of
15716 user defined types. */
15718 static struct type
*
15719 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15721 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15723 struct attribute
*attr
;
15726 /* If the definition of this type lives in .debug_types, read that type.
15727 Don't follow DW_AT_specification though, that will take us back up
15728 the chain and we want to go down. */
15729 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15732 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15734 /* The type's CU may not be the same as CU.
15735 Ensure TYPE is recorded with CU in die_type_hash. */
15736 return set_die_type (die
, type
, cu
);
15739 type
= alloc_type (objfile
);
15740 INIT_CPLUS_SPECIFIC (type
);
15742 name
= dwarf2_name (die
, cu
);
15745 if (cu
->language
== language_cplus
15746 || cu
->language
== language_d
15747 || cu
->language
== language_rust
)
15749 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15751 /* dwarf2_full_name might have already finished building the DIE's
15752 type. If so, there is no need to continue. */
15753 if (get_die_type (die
, cu
) != NULL
)
15754 return get_die_type (die
, cu
);
15756 TYPE_TAG_NAME (type
) = full_name
;
15757 if (die
->tag
== DW_TAG_structure_type
15758 || die
->tag
== DW_TAG_class_type
)
15759 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
15763 /* The name is already allocated along with this objfile, so
15764 we don't need to duplicate it for the type. */
15765 TYPE_TAG_NAME (type
) = name
;
15766 if (die
->tag
== DW_TAG_class_type
)
15767 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
15771 if (die
->tag
== DW_TAG_structure_type
)
15773 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15775 else if (die
->tag
== DW_TAG_union_type
)
15777 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15779 else if (die
->tag
== DW_TAG_variant_part
)
15781 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15782 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15786 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15789 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15790 TYPE_DECLARED_CLASS (type
) = 1;
15792 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15795 if (attr_form_is_constant (attr
))
15796 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15799 /* For the moment, dynamic type sizes are not supported
15800 by GDB's struct type. The actual size is determined
15801 on-demand when resolving the type of a given object,
15802 so set the type's length to zero for now. Otherwise,
15803 we record an expression as the length, and that expression
15804 could lead to a very large value, which could eventually
15805 lead to us trying to allocate that much memory when creating
15806 a value of that type. */
15807 TYPE_LENGTH (type
) = 0;
15812 TYPE_LENGTH (type
) = 0;
15815 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15817 /* ICC<14 does not output the required DW_AT_declaration on
15818 incomplete types, but gives them a size of zero. */
15819 TYPE_STUB (type
) = 1;
15822 TYPE_STUB_SUPPORTED (type
) = 1;
15824 if (die_is_declaration (die
, cu
))
15825 TYPE_STUB (type
) = 1;
15826 else if (attr
== NULL
&& die
->child
== NULL
15827 && producer_is_realview (cu
->producer
))
15828 /* RealView does not output the required DW_AT_declaration
15829 on incomplete types. */
15830 TYPE_STUB (type
) = 1;
15832 /* We need to add the type field to the die immediately so we don't
15833 infinitely recurse when dealing with pointers to the structure
15834 type within the structure itself. */
15835 set_die_type (die
, type
, cu
);
15837 /* set_die_type should be already done. */
15838 set_descriptive_type (type
, die
, cu
);
15843 /* A helper for process_structure_scope that handles a single member
15847 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15848 struct field_info
*fi
,
15849 std::vector
<struct symbol
*> *template_args
,
15850 struct dwarf2_cu
*cu
)
15852 if (child_die
->tag
== DW_TAG_member
15853 || child_die
->tag
== DW_TAG_variable
15854 || child_die
->tag
== DW_TAG_variant_part
)
15856 /* NOTE: carlton/2002-11-05: A C++ static data member
15857 should be a DW_TAG_member that is a declaration, but
15858 all versions of G++ as of this writing (so through at
15859 least 3.2.1) incorrectly generate DW_TAG_variable
15860 tags for them instead. */
15861 dwarf2_add_field (fi
, child_die
, cu
);
15863 else if (child_die
->tag
== DW_TAG_subprogram
)
15865 /* Rust doesn't have member functions in the C++ sense.
15866 However, it does emit ordinary functions as children
15867 of a struct DIE. */
15868 if (cu
->language
== language_rust
)
15869 read_func_scope (child_die
, cu
);
15872 /* C++ member function. */
15873 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15876 else if (child_die
->tag
== DW_TAG_inheritance
)
15878 /* C++ base class field. */
15879 dwarf2_add_field (fi
, child_die
, cu
);
15881 else if (type_can_define_types (child_die
))
15882 dwarf2_add_type_defn (fi
, child_die
, cu
);
15883 else if (child_die
->tag
== DW_TAG_template_type_param
15884 || child_die
->tag
== DW_TAG_template_value_param
)
15886 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15889 template_args
->push_back (arg
);
15891 else if (child_die
->tag
== DW_TAG_variant
)
15893 /* In a variant we want to get the discriminant and also add a
15894 field for our sole member child. */
15895 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
15897 for (struct die_info
*variant_child
= child_die
->child
;
15898 variant_child
!= NULL
;
15899 variant_child
= sibling_die (variant_child
))
15901 if (variant_child
->tag
== DW_TAG_member
)
15903 handle_struct_member_die (variant_child
, type
, fi
,
15904 template_args
, cu
);
15905 /* Only handle the one. */
15910 /* We don't handle this but we might as well report it if we see
15912 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
15913 complaint (&symfile_complaints
,
15914 _("DW_AT_discr_list is not supported yet"
15915 " - DIE at %s [in module %s]"),
15916 sect_offset_str (child_die
->sect_off
),
15917 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15919 /* The first field was just added, so we can stash the
15920 discriminant there. */
15921 gdb_assert (!fi
->fields
.empty ());
15923 fi
->fields
.back ().variant
.default_branch
= true;
15925 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
15929 /* Finish creating a structure or union type, including filling in
15930 its members and creating a symbol for it. */
15933 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15935 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15936 struct die_info
*child_die
;
15939 type
= get_die_type (die
, cu
);
15941 type
= read_structure_type (die
, cu
);
15943 /* When reading a DW_TAG_variant_part, we need to notice when we
15944 read the discriminant member, so we can record it later in the
15945 discriminant_info. */
15946 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
15947 sect_offset discr_offset
;
15949 if (is_variant_part
)
15951 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15954 /* Maybe it's a univariant form, an extension we support.
15955 In this case arrange not to check the offset. */
15956 is_variant_part
= false;
15958 else if (attr_form_is_ref (discr
))
15960 struct dwarf2_cu
*target_cu
= cu
;
15961 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15963 discr_offset
= target_die
->sect_off
;
15967 complaint (&symfile_complaints
,
15968 _("DW_AT_discr does not have DIE reference form"
15969 " - DIE at %s [in module %s]"),
15970 sect_offset_str (die
->sect_off
),
15971 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15972 is_variant_part
= false;
15976 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15978 struct field_info fi
;
15979 std::vector
<struct symbol
*> template_args
;
15981 child_die
= die
->child
;
15983 while (child_die
&& child_die
->tag
)
15985 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15987 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
15988 fi
.fields
.back ().variant
.is_discriminant
= true;
15990 child_die
= sibling_die (child_die
);
15993 /* Attach template arguments to type. */
15994 if (!template_args
.empty ())
15996 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15997 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15998 TYPE_TEMPLATE_ARGUMENTS (type
)
15999 = XOBNEWVEC (&objfile
->objfile_obstack
,
16001 TYPE_N_TEMPLATE_ARGUMENTS (type
));
16002 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
16003 template_args
.data (),
16004 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
16005 * sizeof (struct symbol
*)));
16008 /* Attach fields and member functions to the type. */
16010 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
16011 if (!fi
.fnfieldlists
.empty ())
16013 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
16015 /* Get the type which refers to the base class (possibly this
16016 class itself) which contains the vtable pointer for the current
16017 class from the DW_AT_containing_type attribute. This use of
16018 DW_AT_containing_type is a GNU extension. */
16020 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
16022 struct type
*t
= die_containing_type (die
, cu
);
16024 set_type_vptr_basetype (type
, t
);
16029 /* Our own class provides vtbl ptr. */
16030 for (i
= TYPE_NFIELDS (t
) - 1;
16031 i
>= TYPE_N_BASECLASSES (t
);
16034 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
16036 if (is_vtable_name (fieldname
, cu
))
16038 set_type_vptr_fieldno (type
, i
);
16043 /* Complain if virtual function table field not found. */
16044 if (i
< TYPE_N_BASECLASSES (t
))
16045 complaint (&symfile_complaints
,
16046 _("virtual function table pointer "
16047 "not found when defining class '%s'"),
16048 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
16053 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16056 else if (cu
->producer
16057 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16059 /* The IBM XLC compiler does not provide direct indication
16060 of the containing type, but the vtable pointer is
16061 always named __vfp. */
16065 for (i
= TYPE_NFIELDS (type
) - 1;
16066 i
>= TYPE_N_BASECLASSES (type
);
16069 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
16071 set_type_vptr_fieldno (type
, i
);
16072 set_type_vptr_basetype (type
, type
);
16079 /* Copy fi.typedef_field_list linked list elements content into the
16080 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16081 if (!fi
.typedef_field_list
.empty ())
16083 int count
= fi
.typedef_field_list
.size ();
16085 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16086 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16087 = ((struct decl_field
*)
16089 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16090 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16092 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16093 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16096 /* Copy fi.nested_types_list linked list elements content into the
16097 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16098 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
16100 int count
= fi
.nested_types_list
.size ();
16102 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16103 TYPE_NESTED_TYPES_ARRAY (type
)
16104 = ((struct decl_field
*)
16105 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16106 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16108 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16109 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16113 quirk_gcc_member_function_pointer (type
, objfile
);
16114 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16115 cu
->rust_unions
.push_back (type
);
16117 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16118 snapshots) has been known to create a die giving a declaration
16119 for a class that has, as a child, a die giving a definition for a
16120 nested class. So we have to process our children even if the
16121 current die is a declaration. Normally, of course, a declaration
16122 won't have any children at all. */
16124 child_die
= die
->child
;
16126 while (child_die
!= NULL
&& child_die
->tag
)
16128 if (child_die
->tag
== DW_TAG_member
16129 || child_die
->tag
== DW_TAG_variable
16130 || child_die
->tag
== DW_TAG_inheritance
16131 || child_die
->tag
== DW_TAG_template_value_param
16132 || child_die
->tag
== DW_TAG_template_type_param
)
16137 process_die (child_die
, cu
);
16139 child_die
= sibling_die (child_die
);
16142 /* Do not consider external references. According to the DWARF standard,
16143 these DIEs are identified by the fact that they have no byte_size
16144 attribute, and a declaration attribute. */
16145 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16146 || !die_is_declaration (die
, cu
))
16147 new_symbol (die
, type
, cu
);
16150 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
16151 update TYPE using some information only available in DIE's children. */
16154 update_enumeration_type_from_children (struct die_info
*die
,
16156 struct dwarf2_cu
*cu
)
16158 struct die_info
*child_die
;
16159 int unsigned_enum
= 1;
16163 auto_obstack obstack
;
16165 for (child_die
= die
->child
;
16166 child_die
!= NULL
&& child_die
->tag
;
16167 child_die
= sibling_die (child_die
))
16169 struct attribute
*attr
;
16171 const gdb_byte
*bytes
;
16172 struct dwarf2_locexpr_baton
*baton
;
16175 if (child_die
->tag
!= DW_TAG_enumerator
)
16178 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16182 name
= dwarf2_name (child_die
, cu
);
16184 name
= "<anonymous enumerator>";
16186 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16187 &value
, &bytes
, &baton
);
16193 else if ((mask
& value
) != 0)
16198 /* If we already know that the enum type is neither unsigned, nor
16199 a flag type, no need to look at the rest of the enumerates. */
16200 if (!unsigned_enum
&& !flag_enum
)
16205 TYPE_UNSIGNED (type
) = 1;
16207 TYPE_FLAG_ENUM (type
) = 1;
16210 /* Given a DW_AT_enumeration_type die, set its type. We do not
16211 complete the type's fields yet, or create any symbols. */
16213 static struct type
*
16214 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16216 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16218 struct attribute
*attr
;
16221 /* If the definition of this type lives in .debug_types, read that type.
16222 Don't follow DW_AT_specification though, that will take us back up
16223 the chain and we want to go down. */
16224 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
16227 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16229 /* The type's CU may not be the same as CU.
16230 Ensure TYPE is recorded with CU in die_type_hash. */
16231 return set_die_type (die
, type
, cu
);
16234 type
= alloc_type (objfile
);
16236 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
16237 name
= dwarf2_full_name (NULL
, die
, cu
);
16239 TYPE_TAG_NAME (type
) = name
;
16241 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16244 struct type
*underlying_type
= die_type (die
, cu
);
16246 TYPE_TARGET_TYPE (type
) = underlying_type
;
16249 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16252 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16256 TYPE_LENGTH (type
) = 0;
16259 /* The enumeration DIE can be incomplete. In Ada, any type can be
16260 declared as private in the package spec, and then defined only
16261 inside the package body. Such types are known as Taft Amendment
16262 Types. When another package uses such a type, an incomplete DIE
16263 may be generated by the compiler. */
16264 if (die_is_declaration (die
, cu
))
16265 TYPE_STUB (type
) = 1;
16267 /* Finish the creation of this type by using the enum's children.
16268 We must call this even when the underlying type has been provided
16269 so that we can determine if we're looking at a "flag" enum. */
16270 update_enumeration_type_from_children (die
, type
, cu
);
16272 /* If this type has an underlying type that is not a stub, then we
16273 may use its attributes. We always use the "unsigned" attribute
16274 in this situation, because ordinarily we guess whether the type
16275 is unsigned -- but the guess can be wrong and the underlying type
16276 can tell us the reality. However, we defer to a local size
16277 attribute if one exists, because this lets the compiler override
16278 the underlying type if needed. */
16279 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16281 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
16282 if (TYPE_LENGTH (type
) == 0)
16283 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
16286 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16288 return set_die_type (die
, type
, cu
);
16291 /* Given a pointer to a die which begins an enumeration, process all
16292 the dies that define the members of the enumeration, and create the
16293 symbol for the enumeration type.
16295 NOTE: We reverse the order of the element list. */
16298 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16300 struct type
*this_type
;
16302 this_type
= get_die_type (die
, cu
);
16303 if (this_type
== NULL
)
16304 this_type
= read_enumeration_type (die
, cu
);
16306 if (die
->child
!= NULL
)
16308 struct die_info
*child_die
;
16309 struct symbol
*sym
;
16310 struct field
*fields
= NULL
;
16311 int num_fields
= 0;
16314 child_die
= die
->child
;
16315 while (child_die
&& child_die
->tag
)
16317 if (child_die
->tag
!= DW_TAG_enumerator
)
16319 process_die (child_die
, cu
);
16323 name
= dwarf2_name (child_die
, cu
);
16326 sym
= new_symbol (child_die
, this_type
, cu
);
16328 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
16330 fields
= (struct field
*)
16332 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
16333 * sizeof (struct field
));
16336 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
16337 FIELD_TYPE (fields
[num_fields
]) = NULL
;
16338 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
16339 FIELD_BITSIZE (fields
[num_fields
]) = 0;
16345 child_die
= sibling_die (child_die
);
16350 TYPE_NFIELDS (this_type
) = num_fields
;
16351 TYPE_FIELDS (this_type
) = (struct field
*)
16352 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
16353 memcpy (TYPE_FIELDS (this_type
), fields
,
16354 sizeof (struct field
) * num_fields
);
16359 /* If we are reading an enum from a .debug_types unit, and the enum
16360 is a declaration, and the enum is not the signatured type in the
16361 unit, then we do not want to add a symbol for it. Adding a
16362 symbol would in some cases obscure the true definition of the
16363 enum, giving users an incomplete type when the definition is
16364 actually available. Note that we do not want to do this for all
16365 enums which are just declarations, because C++0x allows forward
16366 enum declarations. */
16367 if (cu
->per_cu
->is_debug_types
16368 && die_is_declaration (die
, cu
))
16370 struct signatured_type
*sig_type
;
16372 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16373 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16374 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16378 new_symbol (die
, this_type
, cu
);
16381 /* Extract all information from a DW_TAG_array_type DIE and put it in
16382 the DIE's type field. For now, this only handles one dimensional
16385 static struct type
*
16386 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16388 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16389 struct die_info
*child_die
;
16391 struct type
*element_type
, *range_type
, *index_type
;
16392 struct attribute
*attr
;
16394 struct dynamic_prop
*byte_stride_prop
= NULL
;
16395 unsigned int bit_stride
= 0;
16397 element_type
= die_type (die
, cu
);
16399 /* The die_type call above may have already set the type for this DIE. */
16400 type
= get_die_type (die
, cu
);
16404 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16410 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16411 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
);
16414 complaint (&symfile_complaints
,
16415 _("unable to read array DW_AT_byte_stride "
16416 " - DIE at %s [in module %s]"),
16417 sect_offset_str (die
->sect_off
),
16418 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16419 /* Ignore this attribute. We will likely not be able to print
16420 arrays of this type correctly, but there is little we can do
16421 to help if we cannot read the attribute's value. */
16422 byte_stride_prop
= NULL
;
16426 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16428 bit_stride
= DW_UNSND (attr
);
16430 /* Irix 6.2 native cc creates array types without children for
16431 arrays with unspecified length. */
16432 if (die
->child
== NULL
)
16434 index_type
= objfile_type (objfile
)->builtin_int
;
16435 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16436 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16437 byte_stride_prop
, bit_stride
);
16438 return set_die_type (die
, type
, cu
);
16441 std::vector
<struct type
*> range_types
;
16442 child_die
= die
->child
;
16443 while (child_die
&& child_die
->tag
)
16445 if (child_die
->tag
== DW_TAG_subrange_type
)
16447 struct type
*child_type
= read_type_die (child_die
, cu
);
16449 if (child_type
!= NULL
)
16451 /* The range type was succesfully read. Save it for the
16452 array type creation. */
16453 range_types
.push_back (child_type
);
16456 child_die
= sibling_die (child_die
);
16459 /* Dwarf2 dimensions are output from left to right, create the
16460 necessary array types in backwards order. */
16462 type
= element_type
;
16464 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16468 while (i
< range_types
.size ())
16469 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16470 byte_stride_prop
, bit_stride
);
16474 size_t ndim
= range_types
.size ();
16476 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16477 byte_stride_prop
, bit_stride
);
16480 /* Understand Dwarf2 support for vector types (like they occur on
16481 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16482 array type. This is not part of the Dwarf2/3 standard yet, but a
16483 custom vendor extension. The main difference between a regular
16484 array and the vector variant is that vectors are passed by value
16486 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16488 make_vector_type (type
);
16490 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16491 implementation may choose to implement triple vectors using this
16493 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16496 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16497 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16499 complaint (&symfile_complaints
,
16500 _("DW_AT_byte_size for array type smaller "
16501 "than the total size of elements"));
16504 name
= dwarf2_name (die
, cu
);
16506 TYPE_NAME (type
) = name
;
16508 /* Install the type in the die. */
16509 set_die_type (die
, type
, cu
);
16511 /* set_die_type should be already done. */
16512 set_descriptive_type (type
, die
, cu
);
16517 static enum dwarf_array_dim_ordering
16518 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16520 struct attribute
*attr
;
16522 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16525 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16527 /* GNU F77 is a special case, as at 08/2004 array type info is the
16528 opposite order to the dwarf2 specification, but data is still
16529 laid out as per normal fortran.
16531 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16532 version checking. */
16534 if (cu
->language
== language_fortran
16535 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16537 return DW_ORD_row_major
;
16540 switch (cu
->language_defn
->la_array_ordering
)
16542 case array_column_major
:
16543 return DW_ORD_col_major
;
16544 case array_row_major
:
16546 return DW_ORD_row_major
;
16550 /* Extract all information from a DW_TAG_set_type DIE and put it in
16551 the DIE's type field. */
16553 static struct type
*
16554 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16556 struct type
*domain_type
, *set_type
;
16557 struct attribute
*attr
;
16559 domain_type
= die_type (die
, cu
);
16561 /* The die_type call above may have already set the type for this DIE. */
16562 set_type
= get_die_type (die
, cu
);
16566 set_type
= create_set_type (NULL
, domain_type
);
16568 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16570 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16572 return set_die_type (die
, set_type
, cu
);
16575 /* A helper for read_common_block that creates a locexpr baton.
16576 SYM is the symbol which we are marking as computed.
16577 COMMON_DIE is the DIE for the common block.
16578 COMMON_LOC is the location expression attribute for the common
16580 MEMBER_LOC is the location expression attribute for the particular
16581 member of the common block that we are processing.
16582 CU is the CU from which the above come. */
16585 mark_common_block_symbol_computed (struct symbol
*sym
,
16586 struct die_info
*common_die
,
16587 struct attribute
*common_loc
,
16588 struct attribute
*member_loc
,
16589 struct dwarf2_cu
*cu
)
16591 struct dwarf2_per_objfile
*dwarf2_per_objfile
16592 = cu
->per_cu
->dwarf2_per_objfile
;
16593 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16594 struct dwarf2_locexpr_baton
*baton
;
16596 unsigned int cu_off
;
16597 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
16598 LONGEST offset
= 0;
16600 gdb_assert (common_loc
&& member_loc
);
16601 gdb_assert (attr_form_is_block (common_loc
));
16602 gdb_assert (attr_form_is_block (member_loc
)
16603 || attr_form_is_constant (member_loc
));
16605 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16606 baton
->per_cu
= cu
->per_cu
;
16607 gdb_assert (baton
->per_cu
);
16609 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16611 if (attr_form_is_constant (member_loc
))
16613 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
16614 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16617 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16619 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16622 *ptr
++ = DW_OP_call4
;
16623 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16624 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16627 if (attr_form_is_constant (member_loc
))
16629 *ptr
++ = DW_OP_addr
;
16630 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16631 ptr
+= cu
->header
.addr_size
;
16635 /* We have to copy the data here, because DW_OP_call4 will only
16636 use a DW_AT_location attribute. */
16637 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16638 ptr
+= DW_BLOCK (member_loc
)->size
;
16641 *ptr
++ = DW_OP_plus
;
16642 gdb_assert (ptr
- baton
->data
== baton
->size
);
16644 SYMBOL_LOCATION_BATON (sym
) = baton
;
16645 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16648 /* Create appropriate locally-scoped variables for all the
16649 DW_TAG_common_block entries. Also create a struct common_block
16650 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16651 is used to sepate the common blocks name namespace from regular
16655 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16657 struct attribute
*attr
;
16659 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16662 /* Support the .debug_loc offsets. */
16663 if (attr_form_is_block (attr
))
16667 else if (attr_form_is_section_offset (attr
))
16669 dwarf2_complex_location_expr_complaint ();
16674 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16675 "common block member");
16680 if (die
->child
!= NULL
)
16682 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16683 struct die_info
*child_die
;
16684 size_t n_entries
= 0, size
;
16685 struct common_block
*common_block
;
16686 struct symbol
*sym
;
16688 for (child_die
= die
->child
;
16689 child_die
&& child_die
->tag
;
16690 child_die
= sibling_die (child_die
))
16693 size
= (sizeof (struct common_block
)
16694 + (n_entries
- 1) * sizeof (struct symbol
*));
16696 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16698 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16699 common_block
->n_entries
= 0;
16701 for (child_die
= die
->child
;
16702 child_die
&& child_die
->tag
;
16703 child_die
= sibling_die (child_die
))
16705 /* Create the symbol in the DW_TAG_common_block block in the current
16707 sym
= new_symbol (child_die
, NULL
, cu
);
16710 struct attribute
*member_loc
;
16712 common_block
->contents
[common_block
->n_entries
++] = sym
;
16714 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16718 /* GDB has handled this for a long time, but it is
16719 not specified by DWARF. It seems to have been
16720 emitted by gfortran at least as recently as:
16721 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16722 complaint (&symfile_complaints
,
16723 _("Variable in common block has "
16724 "DW_AT_data_member_location "
16725 "- DIE at %s [in module %s]"),
16726 sect_offset_str (child_die
->sect_off
),
16727 objfile_name (objfile
));
16729 if (attr_form_is_section_offset (member_loc
))
16730 dwarf2_complex_location_expr_complaint ();
16731 else if (attr_form_is_constant (member_loc
)
16732 || attr_form_is_block (member_loc
))
16735 mark_common_block_symbol_computed (sym
, die
, attr
,
16739 dwarf2_complex_location_expr_complaint ();
16744 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16745 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16749 /* Create a type for a C++ namespace. */
16751 static struct type
*
16752 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16754 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16755 const char *previous_prefix
, *name
;
16759 /* For extensions, reuse the type of the original namespace. */
16760 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16762 struct die_info
*ext_die
;
16763 struct dwarf2_cu
*ext_cu
= cu
;
16765 ext_die
= dwarf2_extension (die
, &ext_cu
);
16766 type
= read_type_die (ext_die
, ext_cu
);
16768 /* EXT_CU may not be the same as CU.
16769 Ensure TYPE is recorded with CU in die_type_hash. */
16770 return set_die_type (die
, type
, cu
);
16773 name
= namespace_name (die
, &is_anonymous
, cu
);
16775 /* Now build the name of the current namespace. */
16777 previous_prefix
= determine_prefix (die
, cu
);
16778 if (previous_prefix
[0] != '\0')
16779 name
= typename_concat (&objfile
->objfile_obstack
,
16780 previous_prefix
, name
, 0, cu
);
16782 /* Create the type. */
16783 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16784 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
16786 return set_die_type (die
, type
, cu
);
16789 /* Read a namespace scope. */
16792 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16794 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16797 /* Add a symbol associated to this if we haven't seen the namespace
16798 before. Also, add a using directive if it's an anonymous
16801 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16805 type
= read_type_die (die
, cu
);
16806 new_symbol (die
, type
, cu
);
16808 namespace_name (die
, &is_anonymous
, cu
);
16811 const char *previous_prefix
= determine_prefix (die
, cu
);
16813 std::vector
<const char *> excludes
;
16814 add_using_directive (using_directives (cu
->language
),
16815 previous_prefix
, TYPE_NAME (type
), NULL
,
16816 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16820 if (die
->child
!= NULL
)
16822 struct die_info
*child_die
= die
->child
;
16824 while (child_die
&& child_die
->tag
)
16826 process_die (child_die
, cu
);
16827 child_die
= sibling_die (child_die
);
16832 /* Read a Fortran module as type. This DIE can be only a declaration used for
16833 imported module. Still we need that type as local Fortran "use ... only"
16834 declaration imports depend on the created type in determine_prefix. */
16836 static struct type
*
16837 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16839 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16840 const char *module_name
;
16843 module_name
= dwarf2_name (die
, cu
);
16845 complaint (&symfile_complaints
,
16846 _("DW_TAG_module has no name, offset %s"),
16847 sect_offset_str (die
->sect_off
));
16848 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16850 /* determine_prefix uses TYPE_TAG_NAME. */
16851 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
16853 return set_die_type (die
, type
, cu
);
16856 /* Read a Fortran module. */
16859 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16861 struct die_info
*child_die
= die
->child
;
16864 type
= read_type_die (die
, cu
);
16865 new_symbol (die
, type
, cu
);
16867 while (child_die
&& child_die
->tag
)
16869 process_die (child_die
, cu
);
16870 child_die
= sibling_die (child_die
);
16874 /* Return the name of the namespace represented by DIE. Set
16875 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16878 static const char *
16879 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16881 struct die_info
*current_die
;
16882 const char *name
= NULL
;
16884 /* Loop through the extensions until we find a name. */
16886 for (current_die
= die
;
16887 current_die
!= NULL
;
16888 current_die
= dwarf2_extension (die
, &cu
))
16890 /* We don't use dwarf2_name here so that we can detect the absence
16891 of a name -> anonymous namespace. */
16892 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16898 /* Is it an anonymous namespace? */
16900 *is_anonymous
= (name
== NULL
);
16902 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16907 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16908 the user defined type vector. */
16910 static struct type
*
16911 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16913 struct gdbarch
*gdbarch
16914 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16915 struct comp_unit_head
*cu_header
= &cu
->header
;
16917 struct attribute
*attr_byte_size
;
16918 struct attribute
*attr_address_class
;
16919 int byte_size
, addr_class
;
16920 struct type
*target_type
;
16922 target_type
= die_type (die
, cu
);
16924 /* The die_type call above may have already set the type for this DIE. */
16925 type
= get_die_type (die
, cu
);
16929 type
= lookup_pointer_type (target_type
);
16931 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16932 if (attr_byte_size
)
16933 byte_size
= DW_UNSND (attr_byte_size
);
16935 byte_size
= cu_header
->addr_size
;
16937 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16938 if (attr_address_class
)
16939 addr_class
= DW_UNSND (attr_address_class
);
16941 addr_class
= DW_ADDR_none
;
16943 /* If the pointer size or address class is different than the
16944 default, create a type variant marked as such and set the
16945 length accordingly. */
16946 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
16948 if (gdbarch_address_class_type_flags_p (gdbarch
))
16952 type_flags
= gdbarch_address_class_type_flags
16953 (gdbarch
, byte_size
, addr_class
);
16954 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16956 type
= make_type_with_address_space (type
, type_flags
);
16958 else if (TYPE_LENGTH (type
) != byte_size
)
16960 complaint (&symfile_complaints
,
16961 _("invalid pointer size %d"), byte_size
);
16965 /* Should we also complain about unhandled address classes? */
16969 TYPE_LENGTH (type
) = byte_size
;
16970 return set_die_type (die
, type
, cu
);
16973 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16974 the user defined type vector. */
16976 static struct type
*
16977 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16980 struct type
*to_type
;
16981 struct type
*domain
;
16983 to_type
= die_type (die
, cu
);
16984 domain
= die_containing_type (die
, cu
);
16986 /* The calls above may have already set the type for this DIE. */
16987 type
= get_die_type (die
, cu
);
16991 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
16992 type
= lookup_methodptr_type (to_type
);
16993 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
16995 struct type
*new_type
16996 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16998 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16999 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
17000 TYPE_VARARGS (to_type
));
17001 type
= lookup_methodptr_type (new_type
);
17004 type
= lookup_memberptr_type (to_type
, domain
);
17006 return set_die_type (die
, type
, cu
);
17009 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17010 the user defined type vector. */
17012 static struct type
*
17013 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17014 enum type_code refcode
)
17016 struct comp_unit_head
*cu_header
= &cu
->header
;
17017 struct type
*type
, *target_type
;
17018 struct attribute
*attr
;
17020 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17022 target_type
= die_type (die
, cu
);
17024 /* The die_type call above may have already set the type for this DIE. */
17025 type
= get_die_type (die
, cu
);
17029 type
= lookup_reference_type (target_type
, refcode
);
17030 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17033 TYPE_LENGTH (type
) = DW_UNSND (attr
);
17037 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17039 return set_die_type (die
, type
, cu
);
17042 /* Add the given cv-qualifiers to the element type of the array. GCC
17043 outputs DWARF type qualifiers that apply to an array, not the
17044 element type. But GDB relies on the array element type to carry
17045 the cv-qualifiers. This mimics section 6.7.3 of the C99
17048 static struct type
*
17049 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17050 struct type
*base_type
, int cnst
, int voltl
)
17052 struct type
*el_type
, *inner_array
;
17054 base_type
= copy_type (base_type
);
17055 inner_array
= base_type
;
17057 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
17059 TYPE_TARGET_TYPE (inner_array
) =
17060 copy_type (TYPE_TARGET_TYPE (inner_array
));
17061 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17064 el_type
= TYPE_TARGET_TYPE (inner_array
);
17065 cnst
|= TYPE_CONST (el_type
);
17066 voltl
|= TYPE_VOLATILE (el_type
);
17067 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17069 return set_die_type (die
, base_type
, cu
);
17072 static struct type
*
17073 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17075 struct type
*base_type
, *cv_type
;
17077 base_type
= die_type (die
, cu
);
17079 /* The die_type call above may have already set the type for this DIE. */
17080 cv_type
= get_die_type (die
, cu
);
17084 /* In case the const qualifier is applied to an array type, the element type
17085 is so qualified, not the array type (section 6.7.3 of C99). */
17086 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17087 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17089 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17090 return set_die_type (die
, cv_type
, cu
);
17093 static struct type
*
17094 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17096 struct type
*base_type
, *cv_type
;
17098 base_type
= die_type (die
, cu
);
17100 /* The die_type call above may have already set the type for this DIE. */
17101 cv_type
= get_die_type (die
, cu
);
17105 /* In case the volatile qualifier is applied to an array type, the
17106 element type is so qualified, not the array type (section 6.7.3
17108 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17109 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17111 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17112 return set_die_type (die
, cv_type
, cu
);
17115 /* Handle DW_TAG_restrict_type. */
17117 static struct type
*
17118 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17120 struct type
*base_type
, *cv_type
;
17122 base_type
= die_type (die
, cu
);
17124 /* The die_type call above may have already set the type for this DIE. */
17125 cv_type
= get_die_type (die
, cu
);
17129 cv_type
= make_restrict_type (base_type
);
17130 return set_die_type (die
, cv_type
, cu
);
17133 /* Handle DW_TAG_atomic_type. */
17135 static struct type
*
17136 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17138 struct type
*base_type
, *cv_type
;
17140 base_type
= die_type (die
, cu
);
17142 /* The die_type call above may have already set the type for this DIE. */
17143 cv_type
= get_die_type (die
, cu
);
17147 cv_type
= make_atomic_type (base_type
);
17148 return set_die_type (die
, cv_type
, cu
);
17151 /* Extract all information from a DW_TAG_string_type DIE and add to
17152 the user defined type vector. It isn't really a user defined type,
17153 but it behaves like one, with other DIE's using an AT_user_def_type
17154 attribute to reference it. */
17156 static struct type
*
17157 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17159 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17160 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17161 struct type
*type
, *range_type
, *index_type
, *char_type
;
17162 struct attribute
*attr
;
17163 unsigned int length
;
17165 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17168 length
= DW_UNSND (attr
);
17172 /* Check for the DW_AT_byte_size attribute. */
17173 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17176 length
= DW_UNSND (attr
);
17184 index_type
= objfile_type (objfile
)->builtin_int
;
17185 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17186 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17187 type
= create_string_type (NULL
, char_type
, range_type
);
17189 return set_die_type (die
, type
, cu
);
17192 /* Assuming that DIE corresponds to a function, returns nonzero
17193 if the function is prototyped. */
17196 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17198 struct attribute
*attr
;
17200 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17201 if (attr
&& (DW_UNSND (attr
) != 0))
17204 /* The DWARF standard implies that the DW_AT_prototyped attribute
17205 is only meaninful for C, but the concept also extends to other
17206 languages that allow unprototyped functions (Eg: Objective C).
17207 For all other languages, assume that functions are always
17209 if (cu
->language
!= language_c
17210 && cu
->language
!= language_objc
17211 && cu
->language
!= language_opencl
)
17214 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17215 prototyped and unprototyped functions; default to prototyped,
17216 since that is more common in modern code (and RealView warns
17217 about unprototyped functions). */
17218 if (producer_is_realview (cu
->producer
))
17224 /* Handle DIES due to C code like:
17228 int (*funcp)(int a, long l);
17232 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17234 static struct type
*
17235 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17237 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17238 struct type
*type
; /* Type that this function returns. */
17239 struct type
*ftype
; /* Function that returns above type. */
17240 struct attribute
*attr
;
17242 type
= die_type (die
, cu
);
17244 /* The die_type call above may have already set the type for this DIE. */
17245 ftype
= get_die_type (die
, cu
);
17249 ftype
= lookup_function_type (type
);
17251 if (prototyped_function_p (die
, cu
))
17252 TYPE_PROTOTYPED (ftype
) = 1;
17254 /* Store the calling convention in the type if it's available in
17255 the subroutine die. Otherwise set the calling convention to
17256 the default value DW_CC_normal. */
17257 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17259 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
17260 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17261 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17263 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17265 /* Record whether the function returns normally to its caller or not
17266 if the DWARF producer set that information. */
17267 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17268 if (attr
&& (DW_UNSND (attr
) != 0))
17269 TYPE_NO_RETURN (ftype
) = 1;
17271 /* We need to add the subroutine type to the die immediately so
17272 we don't infinitely recurse when dealing with parameters
17273 declared as the same subroutine type. */
17274 set_die_type (die
, ftype
, cu
);
17276 if (die
->child
!= NULL
)
17278 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17279 struct die_info
*child_die
;
17280 int nparams
, iparams
;
17282 /* Count the number of parameters.
17283 FIXME: GDB currently ignores vararg functions, but knows about
17284 vararg member functions. */
17286 child_die
= die
->child
;
17287 while (child_die
&& child_die
->tag
)
17289 if (child_die
->tag
== DW_TAG_formal_parameter
)
17291 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17292 TYPE_VARARGS (ftype
) = 1;
17293 child_die
= sibling_die (child_die
);
17296 /* Allocate storage for parameters and fill them in. */
17297 TYPE_NFIELDS (ftype
) = nparams
;
17298 TYPE_FIELDS (ftype
) = (struct field
*)
17299 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
17301 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17302 even if we error out during the parameters reading below. */
17303 for (iparams
= 0; iparams
< nparams
; iparams
++)
17304 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17307 child_die
= die
->child
;
17308 while (child_die
&& child_die
->tag
)
17310 if (child_die
->tag
== DW_TAG_formal_parameter
)
17312 struct type
*arg_type
;
17314 /* DWARF version 2 has no clean way to discern C++
17315 static and non-static member functions. G++ helps
17316 GDB by marking the first parameter for non-static
17317 member functions (which is the this pointer) as
17318 artificial. We pass this information to
17319 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17321 DWARF version 3 added DW_AT_object_pointer, which GCC
17322 4.5 does not yet generate. */
17323 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17325 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17327 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17328 arg_type
= die_type (child_die
, cu
);
17330 /* RealView does not mark THIS as const, which the testsuite
17331 expects. GCC marks THIS as const in method definitions,
17332 but not in the class specifications (GCC PR 43053). */
17333 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17334 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17337 struct dwarf2_cu
*arg_cu
= cu
;
17338 const char *name
= dwarf2_name (child_die
, cu
);
17340 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17343 /* If the compiler emits this, use it. */
17344 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17347 else if (name
&& strcmp (name
, "this") == 0)
17348 /* Function definitions will have the argument names. */
17350 else if (name
== NULL
&& iparams
== 0)
17351 /* Declarations may not have the names, so like
17352 elsewhere in GDB, assume an artificial first
17353 argument is "this". */
17357 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17361 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17364 child_die
= sibling_die (child_die
);
17371 static struct type
*
17372 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17374 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17375 const char *name
= NULL
;
17376 struct type
*this_type
, *target_type
;
17378 name
= dwarf2_full_name (NULL
, die
, cu
);
17379 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17380 TYPE_TARGET_STUB (this_type
) = 1;
17381 set_die_type (die
, this_type
, cu
);
17382 target_type
= die_type (die
, cu
);
17383 if (target_type
!= this_type
)
17384 TYPE_TARGET_TYPE (this_type
) = target_type
;
17387 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17388 spec and cause infinite loops in GDB. */
17389 complaint (&symfile_complaints
,
17390 _("Self-referential DW_TAG_typedef "
17391 "- DIE at %s [in module %s]"),
17392 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17393 TYPE_TARGET_TYPE (this_type
) = NULL
;
17398 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17399 (which may be different from NAME) to the architecture back-end to allow
17400 it to guess the correct format if necessary. */
17402 static struct type
*
17403 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17404 const char *name_hint
)
17406 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17407 const struct floatformat
**format
;
17410 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17412 type
= init_float_type (objfile
, bits
, name
, format
);
17414 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17419 /* Find a representation of a given base type and install
17420 it in the TYPE field of the die. */
17422 static struct type
*
17423 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17425 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17427 struct attribute
*attr
;
17428 int encoding
= 0, bits
= 0;
17431 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17434 encoding
= DW_UNSND (attr
);
17436 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17439 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17441 name
= dwarf2_name (die
, cu
);
17444 complaint (&symfile_complaints
,
17445 _("DW_AT_name missing from DW_TAG_base_type"));
17450 case DW_ATE_address
:
17451 /* Turn DW_ATE_address into a void * pointer. */
17452 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17453 type
= init_pointer_type (objfile
, bits
, name
, type
);
17455 case DW_ATE_boolean
:
17456 type
= init_boolean_type (objfile
, bits
, 1, name
);
17458 case DW_ATE_complex_float
:
17459 type
= dwarf2_init_float_type (objfile
, bits
/ 2, NULL
, name
);
17460 type
= init_complex_type (objfile
, name
, type
);
17462 case DW_ATE_decimal_float
:
17463 type
= init_decfloat_type (objfile
, bits
, name
);
17466 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
);
17468 case DW_ATE_signed
:
17469 type
= init_integer_type (objfile
, bits
, 0, name
);
17471 case DW_ATE_unsigned
:
17472 if (cu
->language
== language_fortran
17474 && startswith (name
, "character("))
17475 type
= init_character_type (objfile
, bits
, 1, name
);
17477 type
= init_integer_type (objfile
, bits
, 1, name
);
17479 case DW_ATE_signed_char
:
17480 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17481 || cu
->language
== language_pascal
17482 || cu
->language
== language_fortran
)
17483 type
= init_character_type (objfile
, bits
, 0, name
);
17485 type
= init_integer_type (objfile
, bits
, 0, name
);
17487 case DW_ATE_unsigned_char
:
17488 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17489 || cu
->language
== language_pascal
17490 || cu
->language
== language_fortran
17491 || cu
->language
== language_rust
)
17492 type
= init_character_type (objfile
, bits
, 1, name
);
17494 type
= init_integer_type (objfile
, bits
, 1, name
);
17498 gdbarch
*arch
= get_objfile_arch (objfile
);
17501 type
= builtin_type (arch
)->builtin_char16
;
17502 else if (bits
== 32)
17503 type
= builtin_type (arch
)->builtin_char32
;
17506 complaint (&symfile_complaints
,
17507 _("unsupported DW_ATE_UTF bit size: '%d'"),
17509 type
= init_integer_type (objfile
, bits
, 1, name
);
17511 return set_die_type (die
, type
, cu
);
17516 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
17517 dwarf_type_encoding_name (encoding
));
17518 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17522 if (name
&& strcmp (name
, "char") == 0)
17523 TYPE_NOSIGN (type
) = 1;
17525 return set_die_type (die
, type
, cu
);
17528 /* Parse dwarf attribute if it's a block, reference or constant and put the
17529 resulting value of the attribute into struct bound_prop.
17530 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17533 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17534 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
)
17536 struct dwarf2_property_baton
*baton
;
17537 struct obstack
*obstack
17538 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17540 if (attr
== NULL
|| prop
== NULL
)
17543 if (attr_form_is_block (attr
))
17545 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17546 baton
->referenced_type
= NULL
;
17547 baton
->locexpr
.per_cu
= cu
->per_cu
;
17548 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17549 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17550 prop
->data
.baton
= baton
;
17551 prop
->kind
= PROP_LOCEXPR
;
17552 gdb_assert (prop
->data
.baton
!= NULL
);
17554 else if (attr_form_is_ref (attr
))
17556 struct dwarf2_cu
*target_cu
= cu
;
17557 struct die_info
*target_die
;
17558 struct attribute
*target_attr
;
17560 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17561 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17562 if (target_attr
== NULL
)
17563 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17565 if (target_attr
== NULL
)
17568 switch (target_attr
->name
)
17570 case DW_AT_location
:
17571 if (attr_form_is_section_offset (target_attr
))
17573 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17574 baton
->referenced_type
= die_type (target_die
, target_cu
);
17575 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17576 prop
->data
.baton
= baton
;
17577 prop
->kind
= PROP_LOCLIST
;
17578 gdb_assert (prop
->data
.baton
!= NULL
);
17580 else if (attr_form_is_block (target_attr
))
17582 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17583 baton
->referenced_type
= die_type (target_die
, target_cu
);
17584 baton
->locexpr
.per_cu
= cu
->per_cu
;
17585 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17586 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17587 prop
->data
.baton
= baton
;
17588 prop
->kind
= PROP_LOCEXPR
;
17589 gdb_assert (prop
->data
.baton
!= NULL
);
17593 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17594 "dynamic property");
17598 case DW_AT_data_member_location
:
17602 if (!handle_data_member_location (target_die
, target_cu
,
17606 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17607 baton
->referenced_type
= read_type_die (target_die
->parent
,
17609 baton
->offset_info
.offset
= offset
;
17610 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17611 prop
->data
.baton
= baton
;
17612 prop
->kind
= PROP_ADDR_OFFSET
;
17617 else if (attr_form_is_constant (attr
))
17619 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
17620 prop
->kind
= PROP_CONST
;
17624 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17625 dwarf2_name (die
, cu
));
17632 /* Read the given DW_AT_subrange DIE. */
17634 static struct type
*
17635 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17637 struct type
*base_type
, *orig_base_type
;
17638 struct type
*range_type
;
17639 struct attribute
*attr
;
17640 struct dynamic_prop low
, high
;
17641 int low_default_is_valid
;
17642 int high_bound_is_count
= 0;
17644 LONGEST negative_mask
;
17646 orig_base_type
= die_type (die
, cu
);
17647 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17648 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17649 creating the range type, but we use the result of check_typedef
17650 when examining properties of the type. */
17651 base_type
= check_typedef (orig_base_type
);
17653 /* The die_type call above may have already set the type for this DIE. */
17654 range_type
= get_die_type (die
, cu
);
17658 low
.kind
= PROP_CONST
;
17659 high
.kind
= PROP_CONST
;
17660 high
.data
.const_val
= 0;
17662 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17663 omitting DW_AT_lower_bound. */
17664 switch (cu
->language
)
17667 case language_cplus
:
17668 low
.data
.const_val
= 0;
17669 low_default_is_valid
= 1;
17671 case language_fortran
:
17672 low
.data
.const_val
= 1;
17673 low_default_is_valid
= 1;
17676 case language_objc
:
17677 case language_rust
:
17678 low
.data
.const_val
= 0;
17679 low_default_is_valid
= (cu
->header
.version
>= 4);
17683 case language_pascal
:
17684 low
.data
.const_val
= 1;
17685 low_default_is_valid
= (cu
->header
.version
>= 4);
17688 low
.data
.const_val
= 0;
17689 low_default_is_valid
= 0;
17693 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17695 attr_to_dynamic_prop (attr
, die
, cu
, &low
);
17696 else if (!low_default_is_valid
)
17697 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
17698 "- DIE at %s [in module %s]"),
17699 sect_offset_str (die
->sect_off
),
17700 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17702 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17703 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
))
17705 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
17706 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
))
17708 /* If bounds are constant do the final calculation here. */
17709 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17710 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17712 high_bound_is_count
= 1;
17716 /* Dwarf-2 specifications explicitly allows to create subrange types
17717 without specifying a base type.
17718 In that case, the base type must be set to the type of
17719 the lower bound, upper bound or count, in that order, if any of these
17720 three attributes references an object that has a type.
17721 If no base type is found, the Dwarf-2 specifications say that
17722 a signed integer type of size equal to the size of an address should
17724 For the following C code: `extern char gdb_int [];'
17725 GCC produces an empty range DIE.
17726 FIXME: muller/2010-05-28: Possible references to object for low bound,
17727 high bound or count are not yet handled by this code. */
17728 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
17730 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17731 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17732 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
17733 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
17735 /* Test "int", "long int", and "long long int" objfile types,
17736 and select the first one having a size above or equal to the
17737 architecture address size. */
17738 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
17739 base_type
= int_type
;
17742 int_type
= objfile_type (objfile
)->builtin_long
;
17743 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
17744 base_type
= int_type
;
17747 int_type
= objfile_type (objfile
)->builtin_long_long
;
17748 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
17749 base_type
= int_type
;
17754 /* Normally, the DWARF producers are expected to use a signed
17755 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17756 But this is unfortunately not always the case, as witnessed
17757 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17758 is used instead. To work around that ambiguity, we treat
17759 the bounds as signed, and thus sign-extend their values, when
17760 the base type is signed. */
17762 -((LONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17763 if (low
.kind
== PROP_CONST
17764 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17765 low
.data
.const_val
|= negative_mask
;
17766 if (high
.kind
== PROP_CONST
17767 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17768 high
.data
.const_val
|= negative_mask
;
17770 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
);
17772 if (high_bound_is_count
)
17773 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17775 /* Ada expects an empty array on no boundary attributes. */
17776 if (attr
== NULL
&& cu
->language
!= language_ada
)
17777 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17779 name
= dwarf2_name (die
, cu
);
17781 TYPE_NAME (range_type
) = name
;
17783 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17785 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17787 set_die_type (die
, range_type
, cu
);
17789 /* set_die_type should be already done. */
17790 set_descriptive_type (range_type
, die
, cu
);
17795 static struct type
*
17796 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17800 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
17802 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
17804 /* In Ada, an unspecified type is typically used when the description
17805 of the type is defered to a different unit. When encountering
17806 such a type, we treat it as a stub, and try to resolve it later on,
17808 if (cu
->language
== language_ada
)
17809 TYPE_STUB (type
) = 1;
17811 return set_die_type (die
, type
, cu
);
17814 /* Read a single die and all its descendents. Set the die's sibling
17815 field to NULL; set other fields in the die correctly, and set all
17816 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17817 location of the info_ptr after reading all of those dies. PARENT
17818 is the parent of the die in question. */
17820 static struct die_info
*
17821 read_die_and_children (const struct die_reader_specs
*reader
,
17822 const gdb_byte
*info_ptr
,
17823 const gdb_byte
**new_info_ptr
,
17824 struct die_info
*parent
)
17826 struct die_info
*die
;
17827 const gdb_byte
*cur_ptr
;
17830 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
17833 *new_info_ptr
= cur_ptr
;
17836 store_in_ref_table (die
, reader
->cu
);
17839 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17843 *new_info_ptr
= cur_ptr
;
17846 die
->sibling
= NULL
;
17847 die
->parent
= parent
;
17851 /* Read a die, all of its descendents, and all of its siblings; set
17852 all of the fields of all of the dies correctly. Arguments are as
17853 in read_die_and_children. */
17855 static struct die_info
*
17856 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17857 const gdb_byte
*info_ptr
,
17858 const gdb_byte
**new_info_ptr
,
17859 struct die_info
*parent
)
17861 struct die_info
*first_die
, *last_sibling
;
17862 const gdb_byte
*cur_ptr
;
17864 cur_ptr
= info_ptr
;
17865 first_die
= last_sibling
= NULL
;
17869 struct die_info
*die
17870 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17874 *new_info_ptr
= cur_ptr
;
17881 last_sibling
->sibling
= die
;
17883 last_sibling
= die
;
17887 /* Read a die, all of its descendents, and all of its siblings; set
17888 all of the fields of all of the dies correctly. Arguments are as
17889 in read_die_and_children.
17890 This the main entry point for reading a DIE and all its children. */
17892 static struct die_info
*
17893 read_die_and_siblings (const struct die_reader_specs
*reader
,
17894 const gdb_byte
*info_ptr
,
17895 const gdb_byte
**new_info_ptr
,
17896 struct die_info
*parent
)
17898 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17899 new_info_ptr
, parent
);
17901 if (dwarf_die_debug
)
17903 fprintf_unfiltered (gdb_stdlog
,
17904 "Read die from %s@0x%x of %s:\n",
17905 get_section_name (reader
->die_section
),
17906 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17907 bfd_get_filename (reader
->abfd
));
17908 dump_die (die
, dwarf_die_debug
);
17914 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
17916 The caller is responsible for filling in the extra attributes
17917 and updating (*DIEP)->num_attrs.
17918 Set DIEP to point to a newly allocated die with its information,
17919 except for its child, sibling, and parent fields.
17920 Set HAS_CHILDREN to tell whether the die has children or not. */
17922 static const gdb_byte
*
17923 read_full_die_1 (const struct die_reader_specs
*reader
,
17924 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17925 int *has_children
, int num_extra_attrs
)
17927 unsigned int abbrev_number
, bytes_read
, i
;
17928 struct abbrev_info
*abbrev
;
17929 struct die_info
*die
;
17930 struct dwarf2_cu
*cu
= reader
->cu
;
17931 bfd
*abfd
= reader
->abfd
;
17933 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
17934 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17935 info_ptr
+= bytes_read
;
17936 if (!abbrev_number
)
17943 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
17945 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
17947 bfd_get_filename (abfd
));
17949 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
17950 die
->sect_off
= sect_off
;
17951 die
->tag
= abbrev
->tag
;
17952 die
->abbrev
= abbrev_number
;
17954 /* Make the result usable.
17955 The caller needs to update num_attrs after adding the extra
17957 die
->num_attrs
= abbrev
->num_attrs
;
17959 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
17960 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
17964 *has_children
= abbrev
->has_children
;
17968 /* Read a die and all its attributes.
17969 Set DIEP to point to a newly allocated die with its information,
17970 except for its child, sibling, and parent fields.
17971 Set HAS_CHILDREN to tell whether the die has children or not. */
17973 static const gdb_byte
*
17974 read_full_die (const struct die_reader_specs
*reader
,
17975 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17978 const gdb_byte
*result
;
17980 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
17982 if (dwarf_die_debug
)
17984 fprintf_unfiltered (gdb_stdlog
,
17985 "Read die from %s@0x%x of %s:\n",
17986 get_section_name (reader
->die_section
),
17987 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17988 bfd_get_filename (reader
->abfd
));
17989 dump_die (*diep
, dwarf_die_debug
);
17995 /* Abbreviation tables.
17997 In DWARF version 2, the description of the debugging information is
17998 stored in a separate .debug_abbrev section. Before we read any
17999 dies from a section we read in all abbreviations and install them
18000 in a hash table. */
18002 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
18004 struct abbrev_info
*
18005 abbrev_table::alloc_abbrev ()
18007 struct abbrev_info
*abbrev
;
18009 abbrev
= XOBNEW (&abbrev_obstack
, struct abbrev_info
);
18010 memset (abbrev
, 0, sizeof (struct abbrev_info
));
18015 /* Add an abbreviation to the table. */
18018 abbrev_table::add_abbrev (unsigned int abbrev_number
,
18019 struct abbrev_info
*abbrev
)
18021 unsigned int hash_number
;
18023 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18024 abbrev
->next
= m_abbrevs
[hash_number
];
18025 m_abbrevs
[hash_number
] = abbrev
;
18028 /* Look up an abbrev in the table.
18029 Returns NULL if the abbrev is not found. */
18031 struct abbrev_info
*
18032 abbrev_table::lookup_abbrev (unsigned int abbrev_number
)
18034 unsigned int hash_number
;
18035 struct abbrev_info
*abbrev
;
18037 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18038 abbrev
= m_abbrevs
[hash_number
];
18042 if (abbrev
->number
== abbrev_number
)
18044 abbrev
= abbrev
->next
;
18049 /* Read in an abbrev table. */
18051 static abbrev_table_up
18052 abbrev_table_read_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18053 struct dwarf2_section_info
*section
,
18054 sect_offset sect_off
)
18056 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18057 bfd
*abfd
= get_section_bfd_owner (section
);
18058 const gdb_byte
*abbrev_ptr
;
18059 struct abbrev_info
*cur_abbrev
;
18060 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
18061 unsigned int abbrev_form
;
18062 struct attr_abbrev
*cur_attrs
;
18063 unsigned int allocated_attrs
;
18065 abbrev_table_up
abbrev_table (new struct abbrev_table (sect_off
));
18067 dwarf2_read_section (objfile
, section
);
18068 abbrev_ptr
= section
->buffer
+ to_underlying (sect_off
);
18069 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18070 abbrev_ptr
+= bytes_read
;
18072 allocated_attrs
= ATTR_ALLOC_CHUNK
;
18073 cur_attrs
= XNEWVEC (struct attr_abbrev
, allocated_attrs
);
18075 /* Loop until we reach an abbrev number of 0. */
18076 while (abbrev_number
)
18078 cur_abbrev
= abbrev_table
->alloc_abbrev ();
18080 /* read in abbrev header */
18081 cur_abbrev
->number
= abbrev_number
;
18083 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18084 abbrev_ptr
+= bytes_read
;
18085 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
18088 /* now read in declarations */
18091 LONGEST implicit_const
;
18093 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18094 abbrev_ptr
+= bytes_read
;
18095 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18096 abbrev_ptr
+= bytes_read
;
18097 if (abbrev_form
== DW_FORM_implicit_const
)
18099 implicit_const
= read_signed_leb128 (abfd
, abbrev_ptr
,
18101 abbrev_ptr
+= bytes_read
;
18105 /* Initialize it due to a false compiler warning. */
18106 implicit_const
= -1;
18109 if (abbrev_name
== 0)
18112 if (cur_abbrev
->num_attrs
== allocated_attrs
)
18114 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
18116 = XRESIZEVEC (struct attr_abbrev
, cur_attrs
, allocated_attrs
);
18119 cur_attrs
[cur_abbrev
->num_attrs
].name
18120 = (enum dwarf_attribute
) abbrev_name
;
18121 cur_attrs
[cur_abbrev
->num_attrs
].form
18122 = (enum dwarf_form
) abbrev_form
;
18123 cur_attrs
[cur_abbrev
->num_attrs
].implicit_const
= implicit_const
;
18124 ++cur_abbrev
->num_attrs
;
18127 cur_abbrev
->attrs
=
18128 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
18129 cur_abbrev
->num_attrs
);
18130 memcpy (cur_abbrev
->attrs
, cur_attrs
,
18131 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
18133 abbrev_table
->add_abbrev (abbrev_number
, cur_abbrev
);
18135 /* Get next abbreviation.
18136 Under Irix6 the abbreviations for a compilation unit are not
18137 always properly terminated with an abbrev number of 0.
18138 Exit loop if we encounter an abbreviation which we have
18139 already read (which means we are about to read the abbreviations
18140 for the next compile unit) or if the end of the abbreviation
18141 table is reached. */
18142 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
18144 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18145 abbrev_ptr
+= bytes_read
;
18146 if (abbrev_table
->lookup_abbrev (abbrev_number
) != NULL
)
18151 return abbrev_table
;
18154 /* Returns nonzero if TAG represents a type that we might generate a partial
18158 is_type_tag_for_partial (int tag
)
18163 /* Some types that would be reasonable to generate partial symbols for,
18164 that we don't at present. */
18165 case DW_TAG_array_type
:
18166 case DW_TAG_file_type
:
18167 case DW_TAG_ptr_to_member_type
:
18168 case DW_TAG_set_type
:
18169 case DW_TAG_string_type
:
18170 case DW_TAG_subroutine_type
:
18172 case DW_TAG_base_type
:
18173 case DW_TAG_class_type
:
18174 case DW_TAG_interface_type
:
18175 case DW_TAG_enumeration_type
:
18176 case DW_TAG_structure_type
:
18177 case DW_TAG_subrange_type
:
18178 case DW_TAG_typedef
:
18179 case DW_TAG_union_type
:
18186 /* Load all DIEs that are interesting for partial symbols into memory. */
18188 static struct partial_die_info
*
18189 load_partial_dies (const struct die_reader_specs
*reader
,
18190 const gdb_byte
*info_ptr
, int building_psymtab
)
18192 struct dwarf2_cu
*cu
= reader
->cu
;
18193 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18194 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18195 unsigned int bytes_read
;
18196 unsigned int load_all
= 0;
18197 int nesting_level
= 1;
18202 gdb_assert (cu
->per_cu
!= NULL
);
18203 if (cu
->per_cu
->load_all_dies
)
18207 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18211 &cu
->comp_unit_obstack
,
18212 hashtab_obstack_allocate
,
18213 dummy_obstack_deallocate
);
18217 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18219 /* A NULL abbrev means the end of a series of children. */
18220 if (abbrev
== NULL
)
18222 if (--nesting_level
== 0)
18225 info_ptr
+= bytes_read
;
18226 last_die
= parent_die
;
18227 parent_die
= parent_die
->die_parent
;
18231 /* Check for template arguments. We never save these; if
18232 they're seen, we just mark the parent, and go on our way. */
18233 if (parent_die
!= NULL
18234 && cu
->language
== language_cplus
18235 && (abbrev
->tag
== DW_TAG_template_type_param
18236 || abbrev
->tag
== DW_TAG_template_value_param
))
18238 parent_die
->has_template_arguments
= 1;
18242 /* We don't need a partial DIE for the template argument. */
18243 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18248 /* We only recurse into c++ subprograms looking for template arguments.
18249 Skip their other children. */
18251 && cu
->language
== language_cplus
18252 && parent_die
!= NULL
18253 && parent_die
->tag
== DW_TAG_subprogram
)
18255 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18259 /* Check whether this DIE is interesting enough to save. Normally
18260 we would not be interested in members here, but there may be
18261 later variables referencing them via DW_AT_specification (for
18262 static members). */
18264 && !is_type_tag_for_partial (abbrev
->tag
)
18265 && abbrev
->tag
!= DW_TAG_constant
18266 && abbrev
->tag
!= DW_TAG_enumerator
18267 && abbrev
->tag
!= DW_TAG_subprogram
18268 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18269 && abbrev
->tag
!= DW_TAG_lexical_block
18270 && abbrev
->tag
!= DW_TAG_variable
18271 && abbrev
->tag
!= DW_TAG_namespace
18272 && abbrev
->tag
!= DW_TAG_module
18273 && abbrev
->tag
!= DW_TAG_member
18274 && abbrev
->tag
!= DW_TAG_imported_unit
18275 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18277 /* Otherwise we skip to the next sibling, if any. */
18278 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18282 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18285 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18287 /* This two-pass algorithm for processing partial symbols has a
18288 high cost in cache pressure. Thus, handle some simple cases
18289 here which cover the majority of C partial symbols. DIEs
18290 which neither have specification tags in them, nor could have
18291 specification tags elsewhere pointing at them, can simply be
18292 processed and discarded.
18294 This segment is also optional; scan_partial_symbols and
18295 add_partial_symbol will handle these DIEs if we chain
18296 them in normally. When compilers which do not emit large
18297 quantities of duplicate debug information are more common,
18298 this code can probably be removed. */
18300 /* Any complete simple types at the top level (pretty much all
18301 of them, for a language without namespaces), can be processed
18303 if (parent_die
== NULL
18304 && pdi
.has_specification
== 0
18305 && pdi
.is_declaration
== 0
18306 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18307 || pdi
.tag
== DW_TAG_base_type
18308 || pdi
.tag
== DW_TAG_subrange_type
))
18310 if (building_psymtab
&& pdi
.name
!= NULL
)
18311 add_psymbol_to_list (pdi
.name
, strlen (pdi
.name
), 0,
18312 VAR_DOMAIN
, LOC_TYPEDEF
,
18313 &objfile
->static_psymbols
,
18314 0, cu
->language
, objfile
);
18315 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18319 /* The exception for DW_TAG_typedef with has_children above is
18320 a workaround of GCC PR debug/47510. In the case of this complaint
18321 type_name_no_tag_or_error will error on such types later.
18323 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18324 it could not find the child DIEs referenced later, this is checked
18325 above. In correct DWARF DW_TAG_typedef should have no children. */
18327 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18328 complaint (&symfile_complaints
,
18329 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18330 "- DIE at %s [in module %s]"),
18331 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18333 /* If we're at the second level, and we're an enumerator, and
18334 our parent has no specification (meaning possibly lives in a
18335 namespace elsewhere), then we can add the partial symbol now
18336 instead of queueing it. */
18337 if (pdi
.tag
== DW_TAG_enumerator
18338 && parent_die
!= NULL
18339 && parent_die
->die_parent
== NULL
18340 && parent_die
->tag
== DW_TAG_enumeration_type
18341 && parent_die
->has_specification
== 0)
18343 if (pdi
.name
== NULL
)
18344 complaint (&symfile_complaints
,
18345 _("malformed enumerator DIE ignored"));
18346 else if (building_psymtab
)
18347 add_psymbol_to_list (pdi
.name
, strlen (pdi
.name
), 0,
18348 VAR_DOMAIN
, LOC_CONST
,
18349 cu
->language
== language_cplus
18350 ? &objfile
->global_psymbols
18351 : &objfile
->static_psymbols
,
18352 0, cu
->language
, objfile
);
18354 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18358 struct partial_die_info
*part_die
18359 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18361 /* We'll save this DIE so link it in. */
18362 part_die
->die_parent
= parent_die
;
18363 part_die
->die_sibling
= NULL
;
18364 part_die
->die_child
= NULL
;
18366 if (last_die
&& last_die
== parent_die
)
18367 last_die
->die_child
= part_die
;
18369 last_die
->die_sibling
= part_die
;
18371 last_die
= part_die
;
18373 if (first_die
== NULL
)
18374 first_die
= part_die
;
18376 /* Maybe add the DIE to the hash table. Not all DIEs that we
18377 find interesting need to be in the hash table, because we
18378 also have the parent/sibling/child chains; only those that we
18379 might refer to by offset later during partial symbol reading.
18381 For now this means things that might have be the target of a
18382 DW_AT_specification, DW_AT_abstract_origin, or
18383 DW_AT_extension. DW_AT_extension will refer only to
18384 namespaces; DW_AT_abstract_origin refers to functions (and
18385 many things under the function DIE, but we do not recurse
18386 into function DIEs during partial symbol reading) and
18387 possibly variables as well; DW_AT_specification refers to
18388 declarations. Declarations ought to have the DW_AT_declaration
18389 flag. It happens that GCC forgets to put it in sometimes, but
18390 only for functions, not for types.
18392 Adding more things than necessary to the hash table is harmless
18393 except for the performance cost. Adding too few will result in
18394 wasted time in find_partial_die, when we reread the compilation
18395 unit with load_all_dies set. */
18398 || abbrev
->tag
== DW_TAG_constant
18399 || abbrev
->tag
== DW_TAG_subprogram
18400 || abbrev
->tag
== DW_TAG_variable
18401 || abbrev
->tag
== DW_TAG_namespace
18402 || part_die
->is_declaration
)
18406 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18407 to_underlying (part_die
->sect_off
),
18412 /* For some DIEs we want to follow their children (if any). For C
18413 we have no reason to follow the children of structures; for other
18414 languages we have to, so that we can get at method physnames
18415 to infer fully qualified class names, for DW_AT_specification,
18416 and for C++ template arguments. For C++, we also look one level
18417 inside functions to find template arguments (if the name of the
18418 function does not already contain the template arguments).
18420 For Ada, we need to scan the children of subprograms and lexical
18421 blocks as well because Ada allows the definition of nested
18422 entities that could be interesting for the debugger, such as
18423 nested subprograms for instance. */
18424 if (last_die
->has_children
18426 || last_die
->tag
== DW_TAG_namespace
18427 || last_die
->tag
== DW_TAG_module
18428 || last_die
->tag
== DW_TAG_enumeration_type
18429 || (cu
->language
== language_cplus
18430 && last_die
->tag
== DW_TAG_subprogram
18431 && (last_die
->name
== NULL
18432 || strchr (last_die
->name
, '<') == NULL
))
18433 || (cu
->language
!= language_c
18434 && (last_die
->tag
== DW_TAG_class_type
18435 || last_die
->tag
== DW_TAG_interface_type
18436 || last_die
->tag
== DW_TAG_structure_type
18437 || last_die
->tag
== DW_TAG_union_type
))
18438 || (cu
->language
== language_ada
18439 && (last_die
->tag
== DW_TAG_subprogram
18440 || last_die
->tag
== DW_TAG_lexical_block
))))
18443 parent_die
= last_die
;
18447 /* Otherwise we skip to the next sibling, if any. */
18448 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18450 /* Back to the top, do it again. */
18454 partial_die_info::partial_die_info (sect_offset sect_off_
,
18455 struct abbrev_info
*abbrev
)
18456 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18460 /* Read a minimal amount of information into the minimal die structure.
18461 INFO_PTR should point just after the initial uleb128 of a DIE. */
18464 partial_die_info::read (const struct die_reader_specs
*reader
,
18465 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18467 struct dwarf2_cu
*cu
= reader
->cu
;
18468 struct dwarf2_per_objfile
*dwarf2_per_objfile
18469 = cu
->per_cu
->dwarf2_per_objfile
;
18471 int has_low_pc_attr
= 0;
18472 int has_high_pc_attr
= 0;
18473 int high_pc_relative
= 0;
18475 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18477 struct attribute attr
;
18479 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
18481 /* Store the data if it is of an attribute we want to keep in a
18482 partial symbol table. */
18488 case DW_TAG_compile_unit
:
18489 case DW_TAG_partial_unit
:
18490 case DW_TAG_type_unit
:
18491 /* Compilation units have a DW_AT_name that is a filename, not
18492 a source language identifier. */
18493 case DW_TAG_enumeration_type
:
18494 case DW_TAG_enumerator
:
18495 /* These tags always have simple identifiers already; no need
18496 to canonicalize them. */
18497 name
= DW_STRING (&attr
);
18501 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18504 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
18505 &objfile
->per_bfd
->storage_obstack
);
18510 case DW_AT_linkage_name
:
18511 case DW_AT_MIPS_linkage_name
:
18512 /* Note that both forms of linkage name might appear. We
18513 assume they will be the same, and we only store the last
18515 if (cu
->language
== language_ada
)
18516 name
= DW_STRING (&attr
);
18517 linkage_name
= DW_STRING (&attr
);
18520 has_low_pc_attr
= 1;
18521 lowpc
= attr_value_as_address (&attr
);
18523 case DW_AT_high_pc
:
18524 has_high_pc_attr
= 1;
18525 highpc
= attr_value_as_address (&attr
);
18526 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
18527 high_pc_relative
= 1;
18529 case DW_AT_location
:
18530 /* Support the .debug_loc offsets. */
18531 if (attr_form_is_block (&attr
))
18533 d
.locdesc
= DW_BLOCK (&attr
);
18535 else if (attr_form_is_section_offset (&attr
))
18537 dwarf2_complex_location_expr_complaint ();
18541 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18542 "partial symbol information");
18545 case DW_AT_external
:
18546 is_external
= DW_UNSND (&attr
);
18548 case DW_AT_declaration
:
18549 is_declaration
= DW_UNSND (&attr
);
18554 case DW_AT_abstract_origin
:
18555 case DW_AT_specification
:
18556 case DW_AT_extension
:
18557 has_specification
= 1;
18558 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
18559 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18560 || cu
->per_cu
->is_dwz
);
18562 case DW_AT_sibling
:
18563 /* Ignore absolute siblings, they might point outside of
18564 the current compile unit. */
18565 if (attr
.form
== DW_FORM_ref_addr
)
18566 complaint (&symfile_complaints
,
18567 _("ignoring absolute DW_AT_sibling"));
18570 const gdb_byte
*buffer
= reader
->buffer
;
18571 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
18572 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18574 if (sibling_ptr
< info_ptr
)
18575 complaint (&symfile_complaints
,
18576 _("DW_AT_sibling points backwards"));
18577 else if (sibling_ptr
> reader
->buffer_end
)
18578 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
18580 sibling
= sibling_ptr
;
18583 case DW_AT_byte_size
:
18586 case DW_AT_const_value
:
18587 has_const_value
= 1;
18589 case DW_AT_calling_convention
:
18590 /* DWARF doesn't provide a way to identify a program's source-level
18591 entry point. DW_AT_calling_convention attributes are only meant
18592 to describe functions' calling conventions.
18594 However, because it's a necessary piece of information in
18595 Fortran, and before DWARF 4 DW_CC_program was the only
18596 piece of debugging information whose definition refers to
18597 a 'main program' at all, several compilers marked Fortran
18598 main programs with DW_CC_program --- even when those
18599 functions use the standard calling conventions.
18601 Although DWARF now specifies a way to provide this
18602 information, we support this practice for backward
18604 if (DW_UNSND (&attr
) == DW_CC_program
18605 && cu
->language
== language_fortran
)
18606 main_subprogram
= 1;
18609 if (DW_UNSND (&attr
) == DW_INL_inlined
18610 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18611 may_be_inlined
= 1;
18615 if (tag
== DW_TAG_imported_unit
)
18617 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
18618 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18619 || cu
->per_cu
->is_dwz
);
18623 case DW_AT_main_subprogram
:
18624 main_subprogram
= DW_UNSND (&attr
);
18632 if (high_pc_relative
)
18635 if (has_low_pc_attr
&& has_high_pc_attr
)
18637 /* When using the GNU linker, .gnu.linkonce. sections are used to
18638 eliminate duplicate copies of functions and vtables and such.
18639 The linker will arbitrarily choose one and discard the others.
18640 The AT_*_pc values for such functions refer to local labels in
18641 these sections. If the section from that file was discarded, the
18642 labels are not in the output, so the relocs get a value of 0.
18643 If this is a discarded function, mark the pc bounds as invalid,
18644 so that GDB will ignore it. */
18645 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18647 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18648 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18650 complaint (&symfile_complaints
,
18651 _("DW_AT_low_pc %s is zero "
18652 "for DIE at %s [in module %s]"),
18653 paddress (gdbarch
, lowpc
),
18654 sect_offset_str (sect_off
),
18655 objfile_name (objfile
));
18657 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18658 else if (lowpc
>= highpc
)
18660 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18661 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18663 complaint (&symfile_complaints
,
18664 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18665 "for DIE at %s [in module %s]"),
18666 paddress (gdbarch
, lowpc
),
18667 paddress (gdbarch
, highpc
),
18668 sect_offset_str (sect_off
),
18669 objfile_name (objfile
));
18678 /* Find a cached partial DIE at OFFSET in CU. */
18680 struct partial_die_info
*
18681 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18683 struct partial_die_info
*lookup_die
= NULL
;
18684 struct partial_die_info
part_die (sect_off
);
18686 lookup_die
= ((struct partial_die_info
*)
18687 htab_find_with_hash (partial_dies
, &part_die
,
18688 to_underlying (sect_off
)));
18693 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18694 except in the case of .debug_types DIEs which do not reference
18695 outside their CU (they do however referencing other types via
18696 DW_FORM_ref_sig8). */
18698 static struct partial_die_info
*
18699 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18701 struct dwarf2_per_objfile
*dwarf2_per_objfile
18702 = cu
->per_cu
->dwarf2_per_objfile
;
18703 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18704 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18705 struct partial_die_info
*pd
= NULL
;
18707 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18708 && offset_in_cu_p (&cu
->header
, sect_off
))
18710 pd
= cu
->find_partial_die (sect_off
);
18713 /* We missed recording what we needed.
18714 Load all dies and try again. */
18715 per_cu
= cu
->per_cu
;
18719 /* TUs don't reference other CUs/TUs (except via type signatures). */
18720 if (cu
->per_cu
->is_debug_types
)
18722 error (_("Dwarf Error: Type Unit at offset %s contains"
18723 " external reference to offset %s [in module %s].\n"),
18724 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18725 bfd_get_filename (objfile
->obfd
));
18727 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18728 dwarf2_per_objfile
);
18730 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18731 load_partial_comp_unit (per_cu
);
18733 per_cu
->cu
->last_used
= 0;
18734 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18737 /* If we didn't find it, and not all dies have been loaded,
18738 load them all and try again. */
18740 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18742 per_cu
->load_all_dies
= 1;
18744 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18745 THIS_CU->cu may already be in use. So we can't just free it and
18746 replace its DIEs with the ones we read in. Instead, we leave those
18747 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18748 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18750 load_partial_comp_unit (per_cu
);
18752 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18756 internal_error (__FILE__
, __LINE__
,
18757 _("could not find partial DIE %s "
18758 "in cache [from module %s]\n"),
18759 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18763 /* See if we can figure out if the class lives in a namespace. We do
18764 this by looking for a member function; its demangled name will
18765 contain namespace info, if there is any. */
18768 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18769 struct dwarf2_cu
*cu
)
18771 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18772 what template types look like, because the demangler
18773 frequently doesn't give the same name as the debug info. We
18774 could fix this by only using the demangled name to get the
18775 prefix (but see comment in read_structure_type). */
18777 struct partial_die_info
*real_pdi
;
18778 struct partial_die_info
*child_pdi
;
18780 /* If this DIE (this DIE's specification, if any) has a parent, then
18781 we should not do this. We'll prepend the parent's fully qualified
18782 name when we create the partial symbol. */
18784 real_pdi
= struct_pdi
;
18785 while (real_pdi
->has_specification
)
18786 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
18787 real_pdi
->spec_is_dwz
, cu
);
18789 if (real_pdi
->die_parent
!= NULL
)
18792 for (child_pdi
= struct_pdi
->die_child
;
18794 child_pdi
= child_pdi
->die_sibling
)
18796 if (child_pdi
->tag
== DW_TAG_subprogram
18797 && child_pdi
->linkage_name
!= NULL
)
18799 char *actual_class_name
18800 = language_class_name_from_physname (cu
->language_defn
,
18801 child_pdi
->linkage_name
);
18802 if (actual_class_name
!= NULL
)
18804 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18807 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
18809 strlen (actual_class_name
)));
18810 xfree (actual_class_name
);
18818 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18820 /* Once we've fixed up a die, there's no point in doing so again.
18821 This also avoids a memory leak if we were to call
18822 guess_partial_die_structure_name multiple times. */
18826 /* If we found a reference attribute and the DIE has no name, try
18827 to find a name in the referred to DIE. */
18829 if (name
== NULL
&& has_specification
)
18831 struct partial_die_info
*spec_die
;
18833 spec_die
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18835 spec_die
->fixup (cu
);
18837 if (spec_die
->name
)
18839 name
= spec_die
->name
;
18841 /* Copy DW_AT_external attribute if it is set. */
18842 if (spec_die
->is_external
)
18843 is_external
= spec_die
->is_external
;
18847 /* Set default names for some unnamed DIEs. */
18849 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18850 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18852 /* If there is no parent die to provide a namespace, and there are
18853 children, see if we can determine the namespace from their linkage
18855 if (cu
->language
== language_cplus
18856 && !VEC_empty (dwarf2_section_info_def
,
18857 cu
->per_cu
->dwarf2_per_objfile
->types
)
18858 && die_parent
== NULL
18860 && (tag
== DW_TAG_class_type
18861 || tag
== DW_TAG_structure_type
18862 || tag
== DW_TAG_union_type
))
18863 guess_partial_die_structure_name (this, cu
);
18865 /* GCC might emit a nameless struct or union that has a linkage
18866 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18868 && (tag
== DW_TAG_class_type
18869 || tag
== DW_TAG_interface_type
18870 || tag
== DW_TAG_structure_type
18871 || tag
== DW_TAG_union_type
)
18872 && linkage_name
!= NULL
)
18876 demangled
= gdb_demangle (linkage_name
, DMGL_TYPES
);
18881 /* Strip any leading namespaces/classes, keep only the base name.
18882 DW_AT_name for named DIEs does not contain the prefixes. */
18883 base
= strrchr (demangled
, ':');
18884 if (base
&& base
> demangled
&& base
[-1] == ':')
18889 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18892 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
18893 base
, strlen (base
)));
18901 /* Read an attribute value described by an attribute form. */
18903 static const gdb_byte
*
18904 read_attribute_value (const struct die_reader_specs
*reader
,
18905 struct attribute
*attr
, unsigned form
,
18906 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
18908 struct dwarf2_cu
*cu
= reader
->cu
;
18909 struct dwarf2_per_objfile
*dwarf2_per_objfile
18910 = cu
->per_cu
->dwarf2_per_objfile
;
18911 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18912 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18913 bfd
*abfd
= reader
->abfd
;
18914 struct comp_unit_head
*cu_header
= &cu
->header
;
18915 unsigned int bytes_read
;
18916 struct dwarf_block
*blk
;
18918 attr
->form
= (enum dwarf_form
) form
;
18921 case DW_FORM_ref_addr
:
18922 if (cu
->header
.version
== 2)
18923 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
18925 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
18926 &cu
->header
, &bytes_read
);
18927 info_ptr
+= bytes_read
;
18929 case DW_FORM_GNU_ref_alt
:
18930 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
18931 info_ptr
+= bytes_read
;
18934 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
18935 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
18936 info_ptr
+= bytes_read
;
18938 case DW_FORM_block2
:
18939 blk
= dwarf_alloc_block (cu
);
18940 blk
->size
= read_2_bytes (abfd
, info_ptr
);
18942 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18943 info_ptr
+= blk
->size
;
18944 DW_BLOCK (attr
) = blk
;
18946 case DW_FORM_block4
:
18947 blk
= dwarf_alloc_block (cu
);
18948 blk
->size
= read_4_bytes (abfd
, info_ptr
);
18950 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18951 info_ptr
+= blk
->size
;
18952 DW_BLOCK (attr
) = blk
;
18954 case DW_FORM_data2
:
18955 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
18958 case DW_FORM_data4
:
18959 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
18962 case DW_FORM_data8
:
18963 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
18966 case DW_FORM_data16
:
18967 blk
= dwarf_alloc_block (cu
);
18969 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
18971 DW_BLOCK (attr
) = blk
;
18973 case DW_FORM_sec_offset
:
18974 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
18975 info_ptr
+= bytes_read
;
18977 case DW_FORM_string
:
18978 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
18979 DW_STRING_IS_CANONICAL (attr
) = 0;
18980 info_ptr
+= bytes_read
;
18983 if (!cu
->per_cu
->is_dwz
)
18985 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
18986 abfd
, info_ptr
, cu_header
,
18988 DW_STRING_IS_CANONICAL (attr
) = 0;
18989 info_ptr
+= bytes_read
;
18993 case DW_FORM_line_strp
:
18994 if (!cu
->per_cu
->is_dwz
)
18996 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
18998 cu_header
, &bytes_read
);
18999 DW_STRING_IS_CANONICAL (attr
) = 0;
19000 info_ptr
+= bytes_read
;
19004 case DW_FORM_GNU_strp_alt
:
19006 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19007 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
19010 DW_STRING (attr
) = read_indirect_string_from_dwz (objfile
,
19012 DW_STRING_IS_CANONICAL (attr
) = 0;
19013 info_ptr
+= bytes_read
;
19016 case DW_FORM_exprloc
:
19017 case DW_FORM_block
:
19018 blk
= dwarf_alloc_block (cu
);
19019 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19020 info_ptr
+= bytes_read
;
19021 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19022 info_ptr
+= blk
->size
;
19023 DW_BLOCK (attr
) = blk
;
19025 case DW_FORM_block1
:
19026 blk
= dwarf_alloc_block (cu
);
19027 blk
->size
= read_1_byte (abfd
, info_ptr
);
19029 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19030 info_ptr
+= blk
->size
;
19031 DW_BLOCK (attr
) = blk
;
19033 case DW_FORM_data1
:
19034 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19038 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19041 case DW_FORM_flag_present
:
19042 DW_UNSND (attr
) = 1;
19044 case DW_FORM_sdata
:
19045 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19046 info_ptr
+= bytes_read
;
19048 case DW_FORM_udata
:
19049 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19050 info_ptr
+= bytes_read
;
19053 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19054 + read_1_byte (abfd
, info_ptr
));
19058 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19059 + read_2_bytes (abfd
, info_ptr
));
19063 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19064 + read_4_bytes (abfd
, info_ptr
));
19068 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19069 + read_8_bytes (abfd
, info_ptr
));
19072 case DW_FORM_ref_sig8
:
19073 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19076 case DW_FORM_ref_udata
:
19077 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19078 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19079 info_ptr
+= bytes_read
;
19081 case DW_FORM_indirect
:
19082 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19083 info_ptr
+= bytes_read
;
19084 if (form
== DW_FORM_implicit_const
)
19086 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19087 info_ptr
+= bytes_read
;
19089 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19092 case DW_FORM_implicit_const
:
19093 DW_SND (attr
) = implicit_const
;
19095 case DW_FORM_GNU_addr_index
:
19096 if (reader
->dwo_file
== NULL
)
19098 /* For now flag a hard error.
19099 Later we can turn this into a complaint. */
19100 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19101 dwarf_form_name (form
),
19102 bfd_get_filename (abfd
));
19104 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
19105 info_ptr
+= bytes_read
;
19107 case DW_FORM_GNU_str_index
:
19108 if (reader
->dwo_file
== NULL
)
19110 /* For now flag a hard error.
19111 Later we can turn this into a complaint if warranted. */
19112 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19113 dwarf_form_name (form
),
19114 bfd_get_filename (abfd
));
19117 ULONGEST str_index
=
19118 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19120 DW_STRING (attr
) = read_str_index (reader
, str_index
);
19121 DW_STRING_IS_CANONICAL (attr
) = 0;
19122 info_ptr
+= bytes_read
;
19126 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19127 dwarf_form_name (form
),
19128 bfd_get_filename (abfd
));
19132 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
19133 attr
->form
= DW_FORM_GNU_ref_alt
;
19135 /* We have seen instances where the compiler tried to emit a byte
19136 size attribute of -1 which ended up being encoded as an unsigned
19137 0xffffffff. Although 0xffffffff is technically a valid size value,
19138 an object of this size seems pretty unlikely so we can relatively
19139 safely treat these cases as if the size attribute was invalid and
19140 treat them as zero by default. */
19141 if (attr
->name
== DW_AT_byte_size
19142 && form
== DW_FORM_data4
19143 && DW_UNSND (attr
) >= 0xffffffff)
19146 (&symfile_complaints
,
19147 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19148 hex_string (DW_UNSND (attr
)));
19149 DW_UNSND (attr
) = 0;
19155 /* Read an attribute described by an abbreviated attribute. */
19157 static const gdb_byte
*
19158 read_attribute (const struct die_reader_specs
*reader
,
19159 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19160 const gdb_byte
*info_ptr
)
19162 attr
->name
= abbrev
->name
;
19163 return read_attribute_value (reader
, attr
, abbrev
->form
,
19164 abbrev
->implicit_const
, info_ptr
);
19167 /* Read dwarf information from a buffer. */
19169 static unsigned int
19170 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
19172 return bfd_get_8 (abfd
, buf
);
19176 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
19178 return bfd_get_signed_8 (abfd
, buf
);
19181 static unsigned int
19182 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19184 return bfd_get_16 (abfd
, buf
);
19188 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19190 return bfd_get_signed_16 (abfd
, buf
);
19193 static unsigned int
19194 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19196 return bfd_get_32 (abfd
, buf
);
19200 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19202 return bfd_get_signed_32 (abfd
, buf
);
19206 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19208 return bfd_get_64 (abfd
, buf
);
19212 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
19213 unsigned int *bytes_read
)
19215 struct comp_unit_head
*cu_header
= &cu
->header
;
19216 CORE_ADDR retval
= 0;
19218 if (cu_header
->signed_addr_p
)
19220 switch (cu_header
->addr_size
)
19223 retval
= bfd_get_signed_16 (abfd
, buf
);
19226 retval
= bfd_get_signed_32 (abfd
, buf
);
19229 retval
= bfd_get_signed_64 (abfd
, buf
);
19232 internal_error (__FILE__
, __LINE__
,
19233 _("read_address: bad switch, signed [in module %s]"),
19234 bfd_get_filename (abfd
));
19239 switch (cu_header
->addr_size
)
19242 retval
= bfd_get_16 (abfd
, buf
);
19245 retval
= bfd_get_32 (abfd
, buf
);
19248 retval
= bfd_get_64 (abfd
, buf
);
19251 internal_error (__FILE__
, __LINE__
,
19252 _("read_address: bad switch, "
19253 "unsigned [in module %s]"),
19254 bfd_get_filename (abfd
));
19258 *bytes_read
= cu_header
->addr_size
;
19262 /* Read the initial length from a section. The (draft) DWARF 3
19263 specification allows the initial length to take up either 4 bytes
19264 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
19265 bytes describe the length and all offsets will be 8 bytes in length
19268 An older, non-standard 64-bit format is also handled by this
19269 function. The older format in question stores the initial length
19270 as an 8-byte quantity without an escape value. Lengths greater
19271 than 2^32 aren't very common which means that the initial 4 bytes
19272 is almost always zero. Since a length value of zero doesn't make
19273 sense for the 32-bit format, this initial zero can be considered to
19274 be an escape value which indicates the presence of the older 64-bit
19275 format. As written, the code can't detect (old format) lengths
19276 greater than 4GB. If it becomes necessary to handle lengths
19277 somewhat larger than 4GB, we could allow other small values (such
19278 as the non-sensical values of 1, 2, and 3) to also be used as
19279 escape values indicating the presence of the old format.
19281 The value returned via bytes_read should be used to increment the
19282 relevant pointer after calling read_initial_length().
19284 [ Note: read_initial_length() and read_offset() are based on the
19285 document entitled "DWARF Debugging Information Format", revision
19286 3, draft 8, dated November 19, 2001. This document was obtained
19289 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
19291 This document is only a draft and is subject to change. (So beware.)
19293 Details regarding the older, non-standard 64-bit format were
19294 determined empirically by examining 64-bit ELF files produced by
19295 the SGI toolchain on an IRIX 6.5 machine.
19297 - Kevin, July 16, 2002
19301 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
19303 LONGEST length
= bfd_get_32 (abfd
, buf
);
19305 if (length
== 0xffffffff)
19307 length
= bfd_get_64 (abfd
, buf
+ 4);
19310 else if (length
== 0)
19312 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
19313 length
= bfd_get_64 (abfd
, buf
);
19324 /* Cover function for read_initial_length.
19325 Returns the length of the object at BUF, and stores the size of the
19326 initial length in *BYTES_READ and stores the size that offsets will be in
19328 If the initial length size is not equivalent to that specified in
19329 CU_HEADER then issue a complaint.
19330 This is useful when reading non-comp-unit headers. */
19333 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
19334 const struct comp_unit_head
*cu_header
,
19335 unsigned int *bytes_read
,
19336 unsigned int *offset_size
)
19338 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
19340 gdb_assert (cu_header
->initial_length_size
== 4
19341 || cu_header
->initial_length_size
== 8
19342 || cu_header
->initial_length_size
== 12);
19344 if (cu_header
->initial_length_size
!= *bytes_read
)
19345 complaint (&symfile_complaints
,
19346 _("intermixed 32-bit and 64-bit DWARF sections"));
19348 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
19352 /* Read an offset from the data stream. The size of the offset is
19353 given by cu_header->offset_size. */
19356 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
19357 const struct comp_unit_head
*cu_header
,
19358 unsigned int *bytes_read
)
19360 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
19362 *bytes_read
= cu_header
->offset_size
;
19366 /* Read an offset from the data stream. */
19369 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
19371 LONGEST retval
= 0;
19373 switch (offset_size
)
19376 retval
= bfd_get_32 (abfd
, buf
);
19379 retval
= bfd_get_64 (abfd
, buf
);
19382 internal_error (__FILE__
, __LINE__
,
19383 _("read_offset_1: bad switch [in module %s]"),
19384 bfd_get_filename (abfd
));
19390 static const gdb_byte
*
19391 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
19393 /* If the size of a host char is 8 bits, we can return a pointer
19394 to the buffer, otherwise we have to copy the data to a buffer
19395 allocated on the temporary obstack. */
19396 gdb_assert (HOST_CHAR_BIT
== 8);
19400 static const char *
19401 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
19402 unsigned int *bytes_read_ptr
)
19404 /* If the size of a host char is 8 bits, we can return a pointer
19405 to the string, otherwise we have to copy the string to a buffer
19406 allocated on the temporary obstack. */
19407 gdb_assert (HOST_CHAR_BIT
== 8);
19410 *bytes_read_ptr
= 1;
19413 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
19414 return (const char *) buf
;
19417 /* Return pointer to string at section SECT offset STR_OFFSET with error
19418 reporting strings FORM_NAME and SECT_NAME. */
19420 static const char *
19421 read_indirect_string_at_offset_from (struct objfile
*objfile
,
19422 bfd
*abfd
, LONGEST str_offset
,
19423 struct dwarf2_section_info
*sect
,
19424 const char *form_name
,
19425 const char *sect_name
)
19427 dwarf2_read_section (objfile
, sect
);
19428 if (sect
->buffer
== NULL
)
19429 error (_("%s used without %s section [in module %s]"),
19430 form_name
, sect_name
, bfd_get_filename (abfd
));
19431 if (str_offset
>= sect
->size
)
19432 error (_("%s pointing outside of %s section [in module %s]"),
19433 form_name
, sect_name
, bfd_get_filename (abfd
));
19434 gdb_assert (HOST_CHAR_BIT
== 8);
19435 if (sect
->buffer
[str_offset
] == '\0')
19437 return (const char *) (sect
->buffer
+ str_offset
);
19440 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19442 static const char *
19443 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19444 bfd
*abfd
, LONGEST str_offset
)
19446 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19448 &dwarf2_per_objfile
->str
,
19449 "DW_FORM_strp", ".debug_str");
19452 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
19454 static const char *
19455 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19456 bfd
*abfd
, LONGEST str_offset
)
19458 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19460 &dwarf2_per_objfile
->line_str
,
19461 "DW_FORM_line_strp",
19462 ".debug_line_str");
19465 /* Read a string at offset STR_OFFSET in the .debug_str section from
19466 the .dwz file DWZ. Throw an error if the offset is too large. If
19467 the string consists of a single NUL byte, return NULL; otherwise
19468 return a pointer to the string. */
19470 static const char *
19471 read_indirect_string_from_dwz (struct objfile
*objfile
, struct dwz_file
*dwz
,
19472 LONGEST str_offset
)
19474 dwarf2_read_section (objfile
, &dwz
->str
);
19476 if (dwz
->str
.buffer
== NULL
)
19477 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
19478 "section [in module %s]"),
19479 bfd_get_filename (dwz
->dwz_bfd
));
19480 if (str_offset
>= dwz
->str
.size
)
19481 error (_("DW_FORM_GNU_strp_alt pointing outside of "
19482 ".debug_str section [in module %s]"),
19483 bfd_get_filename (dwz
->dwz_bfd
));
19484 gdb_assert (HOST_CHAR_BIT
== 8);
19485 if (dwz
->str
.buffer
[str_offset
] == '\0')
19487 return (const char *) (dwz
->str
.buffer
+ str_offset
);
19490 /* Return pointer to string at .debug_str offset as read from BUF.
19491 BUF is assumed to be in a compilation unit described by CU_HEADER.
19492 Return *BYTES_READ_PTR count of bytes read from BUF. */
19494 static const char *
19495 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
19496 const gdb_byte
*buf
,
19497 const struct comp_unit_head
*cu_header
,
19498 unsigned int *bytes_read_ptr
)
19500 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19502 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
19505 /* Return pointer to string at .debug_line_str offset as read from BUF.
19506 BUF is assumed to be in a compilation unit described by CU_HEADER.
19507 Return *BYTES_READ_PTR count of bytes read from BUF. */
19509 static const char *
19510 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19511 bfd
*abfd
, const gdb_byte
*buf
,
19512 const struct comp_unit_head
*cu_header
,
19513 unsigned int *bytes_read_ptr
)
19515 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19517 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
19522 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
19523 unsigned int *bytes_read_ptr
)
19526 unsigned int num_read
;
19528 unsigned char byte
;
19535 byte
= bfd_get_8 (abfd
, buf
);
19538 result
|= ((ULONGEST
) (byte
& 127) << shift
);
19539 if ((byte
& 128) == 0)
19545 *bytes_read_ptr
= num_read
;
19550 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
19551 unsigned int *bytes_read_ptr
)
19554 int shift
, num_read
;
19555 unsigned char byte
;
19562 byte
= bfd_get_8 (abfd
, buf
);
19565 result
|= ((LONGEST
) (byte
& 127) << shift
);
19567 if ((byte
& 128) == 0)
19572 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
19573 result
|= -(((LONGEST
) 1) << shift
);
19574 *bytes_read_ptr
= num_read
;
19578 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
19579 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
19580 ADDR_SIZE is the size of addresses from the CU header. */
19583 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19584 unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
19586 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19587 bfd
*abfd
= objfile
->obfd
;
19588 const gdb_byte
*info_ptr
;
19590 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
19591 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
19592 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
19593 objfile_name (objfile
));
19594 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
19595 error (_("DW_FORM_addr_index pointing outside of "
19596 ".debug_addr section [in module %s]"),
19597 objfile_name (objfile
));
19598 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
19599 + addr_base
+ addr_index
* addr_size
);
19600 if (addr_size
== 4)
19601 return bfd_get_32 (abfd
, info_ptr
);
19603 return bfd_get_64 (abfd
, info_ptr
);
19606 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
19609 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
19611 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
19612 cu
->addr_base
, cu
->header
.addr_size
);
19615 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
19618 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
19619 unsigned int *bytes_read
)
19621 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
19622 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
19624 return read_addr_index (cu
, addr_index
);
19627 /* Data structure to pass results from dwarf2_read_addr_index_reader
19628 back to dwarf2_read_addr_index. */
19630 struct dwarf2_read_addr_index_data
19632 ULONGEST addr_base
;
19636 /* die_reader_func for dwarf2_read_addr_index. */
19639 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
19640 const gdb_byte
*info_ptr
,
19641 struct die_info
*comp_unit_die
,
19645 struct dwarf2_cu
*cu
= reader
->cu
;
19646 struct dwarf2_read_addr_index_data
*aidata
=
19647 (struct dwarf2_read_addr_index_data
*) data
;
19649 aidata
->addr_base
= cu
->addr_base
;
19650 aidata
->addr_size
= cu
->header
.addr_size
;
19653 /* Given an index in .debug_addr, fetch the value.
19654 NOTE: This can be called during dwarf expression evaluation,
19655 long after the debug information has been read, and thus per_cu->cu
19656 may no longer exist. */
19659 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
19660 unsigned int addr_index
)
19662 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
19663 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19664 struct dwarf2_cu
*cu
= per_cu
->cu
;
19665 ULONGEST addr_base
;
19668 /* We need addr_base and addr_size.
19669 If we don't have PER_CU->cu, we have to get it.
19670 Nasty, but the alternative is storing the needed info in PER_CU,
19671 which at this point doesn't seem justified: it's not clear how frequently
19672 it would get used and it would increase the size of every PER_CU.
19673 Entry points like dwarf2_per_cu_addr_size do a similar thing
19674 so we're not in uncharted territory here.
19675 Alas we need to be a bit more complicated as addr_base is contained
19678 We don't need to read the entire CU(/TU).
19679 We just need the header and top level die.
19681 IWBN to use the aging mechanism to let us lazily later discard the CU.
19682 For now we skip this optimization. */
19686 addr_base
= cu
->addr_base
;
19687 addr_size
= cu
->header
.addr_size
;
19691 struct dwarf2_read_addr_index_data aidata
;
19693 /* Note: We can't use init_cutu_and_read_dies_simple here,
19694 we need addr_base. */
19695 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
19696 dwarf2_read_addr_index_reader
, &aidata
);
19697 addr_base
= aidata
.addr_base
;
19698 addr_size
= aidata
.addr_size
;
19701 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
19705 /* Given a DW_FORM_GNU_str_index, fetch the string.
19706 This is only used by the Fission support. */
19708 static const char *
19709 read_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
19711 struct dwarf2_cu
*cu
= reader
->cu
;
19712 struct dwarf2_per_objfile
*dwarf2_per_objfile
19713 = cu
->per_cu
->dwarf2_per_objfile
;
19714 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19715 const char *objf_name
= objfile_name (objfile
);
19716 bfd
*abfd
= objfile
->obfd
;
19717 struct dwarf2_section_info
*str_section
= &reader
->dwo_file
->sections
.str
;
19718 struct dwarf2_section_info
*str_offsets_section
=
19719 &reader
->dwo_file
->sections
.str_offsets
;
19720 const gdb_byte
*info_ptr
;
19721 ULONGEST str_offset
;
19722 static const char form_name
[] = "DW_FORM_GNU_str_index";
19724 dwarf2_read_section (objfile
, str_section
);
19725 dwarf2_read_section (objfile
, str_offsets_section
);
19726 if (str_section
->buffer
== NULL
)
19727 error (_("%s used without .debug_str.dwo section"
19728 " in CU at offset %s [in module %s]"),
19729 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19730 if (str_offsets_section
->buffer
== NULL
)
19731 error (_("%s used without .debug_str_offsets.dwo section"
19732 " in CU at offset %s [in module %s]"),
19733 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19734 if (str_index
* cu
->header
.offset_size
>= str_offsets_section
->size
)
19735 error (_("%s pointing outside of .debug_str_offsets.dwo"
19736 " section in CU at offset %s [in module %s]"),
19737 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19738 info_ptr
= (str_offsets_section
->buffer
19739 + str_index
* cu
->header
.offset_size
);
19740 if (cu
->header
.offset_size
== 4)
19741 str_offset
= bfd_get_32 (abfd
, info_ptr
);
19743 str_offset
= bfd_get_64 (abfd
, info_ptr
);
19744 if (str_offset
>= str_section
->size
)
19745 error (_("Offset from %s pointing outside of"
19746 " .debug_str.dwo section in CU at offset %s [in module %s]"),
19747 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19748 return (const char *) (str_section
->buffer
+ str_offset
);
19751 /* Return the length of an LEB128 number in BUF. */
19754 leb128_size (const gdb_byte
*buf
)
19756 const gdb_byte
*begin
= buf
;
19762 if ((byte
& 128) == 0)
19763 return buf
- begin
;
19768 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19777 cu
->language
= language_c
;
19780 case DW_LANG_C_plus_plus
:
19781 case DW_LANG_C_plus_plus_11
:
19782 case DW_LANG_C_plus_plus_14
:
19783 cu
->language
= language_cplus
;
19786 cu
->language
= language_d
;
19788 case DW_LANG_Fortran77
:
19789 case DW_LANG_Fortran90
:
19790 case DW_LANG_Fortran95
:
19791 case DW_LANG_Fortran03
:
19792 case DW_LANG_Fortran08
:
19793 cu
->language
= language_fortran
;
19796 cu
->language
= language_go
;
19798 case DW_LANG_Mips_Assembler
:
19799 cu
->language
= language_asm
;
19801 case DW_LANG_Ada83
:
19802 case DW_LANG_Ada95
:
19803 cu
->language
= language_ada
;
19805 case DW_LANG_Modula2
:
19806 cu
->language
= language_m2
;
19808 case DW_LANG_Pascal83
:
19809 cu
->language
= language_pascal
;
19812 cu
->language
= language_objc
;
19815 case DW_LANG_Rust_old
:
19816 cu
->language
= language_rust
;
19818 case DW_LANG_Cobol74
:
19819 case DW_LANG_Cobol85
:
19821 cu
->language
= language_minimal
;
19824 cu
->language_defn
= language_def (cu
->language
);
19827 /* Return the named attribute or NULL if not there. */
19829 static struct attribute
*
19830 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19835 struct attribute
*spec
= NULL
;
19837 for (i
= 0; i
< die
->num_attrs
; ++i
)
19839 if (die
->attrs
[i
].name
== name
)
19840 return &die
->attrs
[i
];
19841 if (die
->attrs
[i
].name
== DW_AT_specification
19842 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19843 spec
= &die
->attrs
[i
];
19849 die
= follow_die_ref (die
, spec
, &cu
);
19855 /* Return the named attribute or NULL if not there,
19856 but do not follow DW_AT_specification, etc.
19857 This is for use in contexts where we're reading .debug_types dies.
19858 Following DW_AT_specification, DW_AT_abstract_origin will take us
19859 back up the chain, and we want to go down. */
19861 static struct attribute
*
19862 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
19866 for (i
= 0; i
< die
->num_attrs
; ++i
)
19867 if (die
->attrs
[i
].name
== name
)
19868 return &die
->attrs
[i
];
19873 /* Return the string associated with a string-typed attribute, or NULL if it
19874 is either not found or is of an incorrect type. */
19876 static const char *
19877 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19879 struct attribute
*attr
;
19880 const char *str
= NULL
;
19882 attr
= dwarf2_attr (die
, name
, cu
);
19886 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
19887 || attr
->form
== DW_FORM_string
19888 || attr
->form
== DW_FORM_GNU_str_index
19889 || attr
->form
== DW_FORM_GNU_strp_alt
)
19890 str
= DW_STRING (attr
);
19892 complaint (&symfile_complaints
,
19893 _("string type expected for attribute %s for "
19894 "DIE at %s in module %s"),
19895 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19896 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
19902 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19903 and holds a non-zero value. This function should only be used for
19904 DW_FORM_flag or DW_FORM_flag_present attributes. */
19907 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19909 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19911 return (attr
&& DW_UNSND (attr
));
19915 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19917 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19918 which value is non-zero. However, we have to be careful with
19919 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19920 (via dwarf2_flag_true_p) follows this attribute. So we may
19921 end up accidently finding a declaration attribute that belongs
19922 to a different DIE referenced by the specification attribute,
19923 even though the given DIE does not have a declaration attribute. */
19924 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19925 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19928 /* Return the die giving the specification for DIE, if there is
19929 one. *SPEC_CU is the CU containing DIE on input, and the CU
19930 containing the return value on output. If there is no
19931 specification, but there is an abstract origin, that is
19934 static struct die_info
*
19935 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19937 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19940 if (spec_attr
== NULL
)
19941 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19943 if (spec_attr
== NULL
)
19946 return follow_die_ref (die
, spec_attr
, spec_cu
);
19949 /* Stub for free_line_header to match void * callback types. */
19952 free_line_header_voidp (void *arg
)
19954 struct line_header
*lh
= (struct line_header
*) arg
;
19960 line_header::add_include_dir (const char *include_dir
)
19962 if (dwarf_line_debug
>= 2)
19963 fprintf_unfiltered (gdb_stdlog
, "Adding dir %zu: %s\n",
19964 include_dirs
.size () + 1, include_dir
);
19966 include_dirs
.push_back (include_dir
);
19970 line_header::add_file_name (const char *name
,
19972 unsigned int mod_time
,
19973 unsigned int length
)
19975 if (dwarf_line_debug
>= 2)
19976 fprintf_unfiltered (gdb_stdlog
, "Adding file %u: %s\n",
19977 (unsigned) file_names
.size () + 1, name
);
19979 file_names
.emplace_back (name
, d_index
, mod_time
, length
);
19982 /* A convenience function to find the proper .debug_line section for a CU. */
19984 static struct dwarf2_section_info
*
19985 get_debug_line_section (struct dwarf2_cu
*cu
)
19987 struct dwarf2_section_info
*section
;
19988 struct dwarf2_per_objfile
*dwarf2_per_objfile
19989 = cu
->per_cu
->dwarf2_per_objfile
;
19991 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19993 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19994 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19995 else if (cu
->per_cu
->is_dwz
)
19997 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19999 section
= &dwz
->line
;
20002 section
= &dwarf2_per_objfile
->line
;
20007 /* Read directory or file name entry format, starting with byte of
20008 format count entries, ULEB128 pairs of entry formats, ULEB128 of
20009 entries count and the entries themselves in the described entry
20013 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20014 bfd
*abfd
, const gdb_byte
**bufp
,
20015 struct line_header
*lh
,
20016 const struct comp_unit_head
*cu_header
,
20017 void (*callback
) (struct line_header
*lh
,
20020 unsigned int mod_time
,
20021 unsigned int length
))
20023 gdb_byte format_count
, formati
;
20024 ULONGEST data_count
, datai
;
20025 const gdb_byte
*buf
= *bufp
;
20026 const gdb_byte
*format_header_data
;
20027 unsigned int bytes_read
;
20029 format_count
= read_1_byte (abfd
, buf
);
20031 format_header_data
= buf
;
20032 for (formati
= 0; formati
< format_count
; formati
++)
20034 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20036 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20040 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20042 for (datai
= 0; datai
< data_count
; datai
++)
20044 const gdb_byte
*format
= format_header_data
;
20045 struct file_entry fe
;
20047 for (formati
= 0; formati
< format_count
; formati
++)
20049 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20050 format
+= bytes_read
;
20052 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20053 format
+= bytes_read
;
20055 gdb::optional
<const char *> string
;
20056 gdb::optional
<unsigned int> uint
;
20060 case DW_FORM_string
:
20061 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
20065 case DW_FORM_line_strp
:
20066 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
20073 case DW_FORM_data1
:
20074 uint
.emplace (read_1_byte (abfd
, buf
));
20078 case DW_FORM_data2
:
20079 uint
.emplace (read_2_bytes (abfd
, buf
));
20083 case DW_FORM_data4
:
20084 uint
.emplace (read_4_bytes (abfd
, buf
));
20088 case DW_FORM_data8
:
20089 uint
.emplace (read_8_bytes (abfd
, buf
));
20093 case DW_FORM_udata
:
20094 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
20098 case DW_FORM_block
:
20099 /* It is valid only for DW_LNCT_timestamp which is ignored by
20104 switch (content_type
)
20107 if (string
.has_value ())
20110 case DW_LNCT_directory_index
:
20111 if (uint
.has_value ())
20112 fe
.d_index
= (dir_index
) *uint
;
20114 case DW_LNCT_timestamp
:
20115 if (uint
.has_value ())
20116 fe
.mod_time
= *uint
;
20119 if (uint
.has_value ())
20125 complaint (&symfile_complaints
,
20126 _("Unknown format content type %s"),
20127 pulongest (content_type
));
20131 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
20137 /* Read the statement program header starting at OFFSET in
20138 .debug_line, or .debug_line.dwo. Return a pointer
20139 to a struct line_header, allocated using xmalloc.
20140 Returns NULL if there is a problem reading the header, e.g., if it
20141 has a version we don't understand.
20143 NOTE: the strings in the include directory and file name tables of
20144 the returned object point into the dwarf line section buffer,
20145 and must not be freed. */
20147 static line_header_up
20148 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20150 const gdb_byte
*line_ptr
;
20151 unsigned int bytes_read
, offset_size
;
20153 const char *cur_dir
, *cur_file
;
20154 struct dwarf2_section_info
*section
;
20156 struct dwarf2_per_objfile
*dwarf2_per_objfile
20157 = cu
->per_cu
->dwarf2_per_objfile
;
20159 section
= get_debug_line_section (cu
);
20160 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
20161 if (section
->buffer
== NULL
)
20163 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20164 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
20166 complaint (&symfile_complaints
, _("missing .debug_line section"));
20170 /* We can't do this until we know the section is non-empty.
20171 Only then do we know we have such a section. */
20172 abfd
= get_section_bfd_owner (section
);
20174 /* Make sure that at least there's room for the total_length field.
20175 That could be 12 bytes long, but we're just going to fudge that. */
20176 if (to_underlying (sect_off
) + 4 >= section
->size
)
20178 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20182 line_header_up
lh (new line_header ());
20184 lh
->sect_off
= sect_off
;
20185 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
20187 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
20189 /* Read in the header. */
20191 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
20192 &bytes_read
, &offset_size
);
20193 line_ptr
+= bytes_read
;
20194 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
20196 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20199 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
20200 lh
->version
= read_2_bytes (abfd
, line_ptr
);
20202 if (lh
->version
> 5)
20204 /* This is a version we don't understand. The format could have
20205 changed in ways we don't handle properly so just punt. */
20206 complaint (&symfile_complaints
,
20207 _("unsupported version in .debug_line section"));
20210 if (lh
->version
>= 5)
20212 gdb_byte segment_selector_size
;
20214 /* Skip address size. */
20215 read_1_byte (abfd
, line_ptr
);
20218 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
20220 if (segment_selector_size
!= 0)
20222 complaint (&symfile_complaints
,
20223 _("unsupported segment selector size %u "
20224 "in .debug_line section"),
20225 segment_selector_size
);
20229 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
20230 line_ptr
+= offset_size
;
20231 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
20233 if (lh
->version
>= 4)
20235 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
20239 lh
->maximum_ops_per_instruction
= 1;
20241 if (lh
->maximum_ops_per_instruction
== 0)
20243 lh
->maximum_ops_per_instruction
= 1;
20244 complaint (&symfile_complaints
,
20245 _("invalid maximum_ops_per_instruction "
20246 "in `.debug_line' section"));
20249 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
20251 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
20253 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
20255 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
20257 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
20259 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
20260 for (i
= 1; i
< lh
->opcode_base
; ++i
)
20262 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
20266 if (lh
->version
>= 5)
20268 /* Read directory table. */
20269 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20271 [] (struct line_header
*lh
, const char *name
,
20272 dir_index d_index
, unsigned int mod_time
,
20273 unsigned int length
)
20275 lh
->add_include_dir (name
);
20278 /* Read file name table. */
20279 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20281 [] (struct line_header
*lh
, const char *name
,
20282 dir_index d_index
, unsigned int mod_time
,
20283 unsigned int length
)
20285 lh
->add_file_name (name
, d_index
, mod_time
, length
);
20290 /* Read directory table. */
20291 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20293 line_ptr
+= bytes_read
;
20294 lh
->add_include_dir (cur_dir
);
20296 line_ptr
+= bytes_read
;
20298 /* Read file name table. */
20299 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20301 unsigned int mod_time
, length
;
20304 line_ptr
+= bytes_read
;
20305 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20306 line_ptr
+= bytes_read
;
20307 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20308 line_ptr
+= bytes_read
;
20309 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20310 line_ptr
+= bytes_read
;
20312 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
20314 line_ptr
+= bytes_read
;
20316 lh
->statement_program_start
= line_ptr
;
20318 if (line_ptr
> (section
->buffer
+ section
->size
))
20319 complaint (&symfile_complaints
,
20320 _("line number info header doesn't "
20321 "fit in `.debug_line' section"));
20326 /* Subroutine of dwarf_decode_lines to simplify it.
20327 Return the file name of the psymtab for included file FILE_INDEX
20328 in line header LH of PST.
20329 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20330 If space for the result is malloc'd, *NAME_HOLDER will be set.
20331 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20333 static const char *
20334 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
20335 const struct partial_symtab
*pst
,
20336 const char *comp_dir
,
20337 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20339 const file_entry
&fe
= lh
->file_names
[file_index
];
20340 const char *include_name
= fe
.name
;
20341 const char *include_name_to_compare
= include_name
;
20342 const char *pst_filename
;
20345 const char *dir_name
= fe
.include_dir (lh
);
20347 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20348 if (!IS_ABSOLUTE_PATH (include_name
)
20349 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20351 /* Avoid creating a duplicate psymtab for PST.
20352 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20353 Before we do the comparison, however, we need to account
20354 for DIR_NAME and COMP_DIR.
20355 First prepend dir_name (if non-NULL). If we still don't
20356 have an absolute path prepend comp_dir (if non-NULL).
20357 However, the directory we record in the include-file's
20358 psymtab does not contain COMP_DIR (to match the
20359 corresponding symtab(s)).
20364 bash$ gcc -g ./hello.c
20365 include_name = "hello.c"
20367 DW_AT_comp_dir = comp_dir = "/tmp"
20368 DW_AT_name = "./hello.c"
20372 if (dir_name
!= NULL
)
20374 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20375 include_name
, (char *) NULL
));
20376 include_name
= name_holder
->get ();
20377 include_name_to_compare
= include_name
;
20379 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20381 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20382 include_name
, (char *) NULL
));
20383 include_name_to_compare
= hold_compare
.get ();
20387 pst_filename
= pst
->filename
;
20388 gdb::unique_xmalloc_ptr
<char> copied_name
;
20389 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20391 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20392 pst_filename
, (char *) NULL
));
20393 pst_filename
= copied_name
.get ();
20396 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20400 return include_name
;
20403 /* State machine to track the state of the line number program. */
20405 class lnp_state_machine
20408 /* Initialize a machine state for the start of a line number
20410 lnp_state_machine (gdbarch
*arch
, line_header
*lh
, bool record_lines_p
);
20412 file_entry
*current_file ()
20414 /* lh->file_names is 0-based, but the file name numbers in the
20415 statement program are 1-based. */
20416 return m_line_header
->file_name_at (m_file
);
20419 /* Record the line in the state machine. END_SEQUENCE is true if
20420 we're processing the end of a sequence. */
20421 void record_line (bool end_sequence
);
20423 /* Check address and if invalid nop-out the rest of the lines in this
20425 void check_line_address (struct dwarf2_cu
*cu
,
20426 const gdb_byte
*line_ptr
,
20427 CORE_ADDR lowpc
, CORE_ADDR address
);
20429 void handle_set_discriminator (unsigned int discriminator
)
20431 m_discriminator
= discriminator
;
20432 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20435 /* Handle DW_LNE_set_address. */
20436 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20439 address
+= baseaddr
;
20440 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20443 /* Handle DW_LNS_advance_pc. */
20444 void handle_advance_pc (CORE_ADDR adjust
);
20446 /* Handle a special opcode. */
20447 void handle_special_opcode (unsigned char op_code
);
20449 /* Handle DW_LNS_advance_line. */
20450 void handle_advance_line (int line_delta
)
20452 advance_line (line_delta
);
20455 /* Handle DW_LNS_set_file. */
20456 void handle_set_file (file_name_index file
);
20458 /* Handle DW_LNS_negate_stmt. */
20459 void handle_negate_stmt ()
20461 m_is_stmt
= !m_is_stmt
;
20464 /* Handle DW_LNS_const_add_pc. */
20465 void handle_const_add_pc ();
20467 /* Handle DW_LNS_fixed_advance_pc. */
20468 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20470 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20474 /* Handle DW_LNS_copy. */
20475 void handle_copy ()
20477 record_line (false);
20478 m_discriminator
= 0;
20481 /* Handle DW_LNE_end_sequence. */
20482 void handle_end_sequence ()
20484 m_record_line_callback
= ::record_line
;
20488 /* Advance the line by LINE_DELTA. */
20489 void advance_line (int line_delta
)
20491 m_line
+= line_delta
;
20493 if (line_delta
!= 0)
20494 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20497 gdbarch
*m_gdbarch
;
20499 /* True if we're recording lines.
20500 Otherwise we're building partial symtabs and are just interested in
20501 finding include files mentioned by the line number program. */
20502 bool m_record_lines_p
;
20504 /* The line number header. */
20505 line_header
*m_line_header
;
20507 /* These are part of the standard DWARF line number state machine,
20508 and initialized according to the DWARF spec. */
20510 unsigned char m_op_index
= 0;
20511 /* The line table index (1-based) of the current file. */
20512 file_name_index m_file
= (file_name_index
) 1;
20513 unsigned int m_line
= 1;
20515 /* These are initialized in the constructor. */
20517 CORE_ADDR m_address
;
20519 unsigned int m_discriminator
;
20521 /* Additional bits of state we need to track. */
20523 /* The last file that we called dwarf2_start_subfile for.
20524 This is only used for TLLs. */
20525 unsigned int m_last_file
= 0;
20526 /* The last file a line number was recorded for. */
20527 struct subfile
*m_last_subfile
= NULL
;
20529 /* The function to call to record a line. */
20530 record_line_ftype
*m_record_line_callback
= NULL
;
20532 /* The last line number that was recorded, used to coalesce
20533 consecutive entries for the same line. This can happen, for
20534 example, when discriminators are present. PR 17276. */
20535 unsigned int m_last_line
= 0;
20536 bool m_line_has_non_zero_discriminator
= false;
20540 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20542 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20543 / m_line_header
->maximum_ops_per_instruction
)
20544 * m_line_header
->minimum_instruction_length
);
20545 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20546 m_op_index
= ((m_op_index
+ adjust
)
20547 % m_line_header
->maximum_ops_per_instruction
);
20551 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20553 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20554 CORE_ADDR addr_adj
= (((m_op_index
20555 + (adj_opcode
/ m_line_header
->line_range
))
20556 / m_line_header
->maximum_ops_per_instruction
)
20557 * m_line_header
->minimum_instruction_length
);
20558 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20559 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
20560 % m_line_header
->maximum_ops_per_instruction
);
20562 int line_delta
= (m_line_header
->line_base
20563 + (adj_opcode
% m_line_header
->line_range
));
20564 advance_line (line_delta
);
20565 record_line (false);
20566 m_discriminator
= 0;
20570 lnp_state_machine::handle_set_file (file_name_index file
)
20574 const file_entry
*fe
= current_file ();
20576 dwarf2_debug_line_missing_file_complaint ();
20577 else if (m_record_lines_p
)
20579 const char *dir
= fe
->include_dir (m_line_header
);
20581 m_last_subfile
= current_subfile
;
20582 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20583 dwarf2_start_subfile (fe
->name
, dir
);
20588 lnp_state_machine::handle_const_add_pc ()
20591 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20594 = (((m_op_index
+ adjust
)
20595 / m_line_header
->maximum_ops_per_instruction
)
20596 * m_line_header
->minimum_instruction_length
);
20598 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20599 m_op_index
= ((m_op_index
+ adjust
)
20600 % m_line_header
->maximum_ops_per_instruction
);
20603 /* Ignore this record_line request. */
20606 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
20611 /* Return non-zero if we should add LINE to the line number table.
20612 LINE is the line to add, LAST_LINE is the last line that was added,
20613 LAST_SUBFILE is the subfile for LAST_LINE.
20614 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20615 had a non-zero discriminator.
20617 We have to be careful in the presence of discriminators.
20618 E.g., for this line:
20620 for (i = 0; i < 100000; i++);
20622 clang can emit four line number entries for that one line,
20623 each with a different discriminator.
20624 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20626 However, we want gdb to coalesce all four entries into one.
20627 Otherwise the user could stepi into the middle of the line and
20628 gdb would get confused about whether the pc really was in the
20629 middle of the line.
20631 Things are further complicated by the fact that two consecutive
20632 line number entries for the same line is a heuristic used by gcc
20633 to denote the end of the prologue. So we can't just discard duplicate
20634 entries, we have to be selective about it. The heuristic we use is
20635 that we only collapse consecutive entries for the same line if at least
20636 one of those entries has a non-zero discriminator. PR 17276.
20638 Note: Addresses in the line number state machine can never go backwards
20639 within one sequence, thus this coalescing is ok. */
20642 dwarf_record_line_p (unsigned int line
, unsigned int last_line
,
20643 int line_has_non_zero_discriminator
,
20644 struct subfile
*last_subfile
)
20646 if (current_subfile
!= last_subfile
)
20648 if (line
!= last_line
)
20650 /* Same line for the same file that we've seen already.
20651 As a last check, for pr 17276, only record the line if the line
20652 has never had a non-zero discriminator. */
20653 if (!line_has_non_zero_discriminator
)
20658 /* Use P_RECORD_LINE to record line number LINE beginning at address ADDRESS
20659 in the line table of subfile SUBFILE. */
20662 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20663 unsigned int line
, CORE_ADDR address
,
20664 record_line_ftype p_record_line
)
20666 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20668 if (dwarf_line_debug
)
20670 fprintf_unfiltered (gdb_stdlog
,
20671 "Recording line %u, file %s, address %s\n",
20672 line
, lbasename (subfile
->name
),
20673 paddress (gdbarch
, address
));
20676 (*p_record_line
) (subfile
, line
, addr
);
20679 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20680 Mark the end of a set of line number records.
20681 The arguments are the same as for dwarf_record_line_1.
20682 If SUBFILE is NULL the request is ignored. */
20685 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20686 CORE_ADDR address
, record_line_ftype p_record_line
)
20688 if (subfile
== NULL
)
20691 if (dwarf_line_debug
)
20693 fprintf_unfiltered (gdb_stdlog
,
20694 "Finishing current line, file %s, address %s\n",
20695 lbasename (subfile
->name
),
20696 paddress (gdbarch
, address
));
20699 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, p_record_line
);
20703 lnp_state_machine::record_line (bool end_sequence
)
20705 if (dwarf_line_debug
)
20707 fprintf_unfiltered (gdb_stdlog
,
20708 "Processing actual line %u: file %u,"
20709 " address %s, is_stmt %u, discrim %u\n",
20710 m_line
, to_underlying (m_file
),
20711 paddress (m_gdbarch
, m_address
),
20712 m_is_stmt
, m_discriminator
);
20715 file_entry
*fe
= current_file ();
20718 dwarf2_debug_line_missing_file_complaint ();
20719 /* For now we ignore lines not starting on an instruction boundary.
20720 But not when processing end_sequence for compatibility with the
20721 previous version of the code. */
20722 else if (m_op_index
== 0 || end_sequence
)
20724 fe
->included_p
= 1;
20725 if (m_record_lines_p
&& m_is_stmt
)
20727 if (m_last_subfile
!= current_subfile
|| end_sequence
)
20729 dwarf_finish_line (m_gdbarch
, m_last_subfile
,
20730 m_address
, m_record_line_callback
);
20735 if (dwarf_record_line_p (m_line
, m_last_line
,
20736 m_line_has_non_zero_discriminator
,
20739 dwarf_record_line_1 (m_gdbarch
, current_subfile
,
20741 m_record_line_callback
);
20743 m_last_subfile
= current_subfile
;
20744 m_last_line
= m_line
;
20750 lnp_state_machine::lnp_state_machine (gdbarch
*arch
, line_header
*lh
,
20751 bool record_lines_p
)
20754 m_record_lines_p
= record_lines_p
;
20755 m_line_header
= lh
;
20757 m_record_line_callback
= ::record_line
;
20759 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20760 was a line entry for it so that the backend has a chance to adjust it
20761 and also record it in case it needs it. This is currently used by MIPS
20762 code, cf. `mips_adjust_dwarf2_line'. */
20763 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20764 m_is_stmt
= lh
->default_is_stmt
;
20765 m_discriminator
= 0;
20769 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20770 const gdb_byte
*line_ptr
,
20771 CORE_ADDR lowpc
, CORE_ADDR address
)
20773 /* If address < lowpc then it's not a usable value, it's outside the
20774 pc range of the CU. However, we restrict the test to only address
20775 values of zero to preserve GDB's previous behaviour which is to
20776 handle the specific case of a function being GC'd by the linker. */
20778 if (address
== 0 && address
< lowpc
)
20780 /* This line table is for a function which has been
20781 GCd by the linker. Ignore it. PR gdb/12528 */
20783 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20784 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20786 complaint (&symfile_complaints
,
20787 _(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20788 line_offset
, objfile_name (objfile
));
20789 m_record_line_callback
= noop_record_line
;
20790 /* Note: record_line_callback is left as noop_record_line until
20791 we see DW_LNE_end_sequence. */
20795 /* Subroutine of dwarf_decode_lines to simplify it.
20796 Process the line number information in LH.
20797 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20798 program in order to set included_p for every referenced header. */
20801 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20802 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20804 const gdb_byte
*line_ptr
, *extended_end
;
20805 const gdb_byte
*line_end
;
20806 unsigned int bytes_read
, extended_len
;
20807 unsigned char op_code
, extended_op
;
20808 CORE_ADDR baseaddr
;
20809 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20810 bfd
*abfd
= objfile
->obfd
;
20811 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20812 /* True if we're recording line info (as opposed to building partial
20813 symtabs and just interested in finding include files mentioned by
20814 the line number program). */
20815 bool record_lines_p
= !decode_for_pst_p
;
20817 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
20819 line_ptr
= lh
->statement_program_start
;
20820 line_end
= lh
->statement_program_end
;
20822 /* Read the statement sequences until there's nothing left. */
20823 while (line_ptr
< line_end
)
20825 /* The DWARF line number program state machine. Reset the state
20826 machine at the start of each sequence. */
20827 lnp_state_machine
state_machine (gdbarch
, lh
, record_lines_p
);
20828 bool end_sequence
= false;
20830 if (record_lines_p
)
20832 /* Start a subfile for the current file of the state
20834 const file_entry
*fe
= state_machine
.current_file ();
20837 dwarf2_start_subfile (fe
->name
, fe
->include_dir (lh
));
20840 /* Decode the table. */
20841 while (line_ptr
< line_end
&& !end_sequence
)
20843 op_code
= read_1_byte (abfd
, line_ptr
);
20846 if (op_code
>= lh
->opcode_base
)
20848 /* Special opcode. */
20849 state_machine
.handle_special_opcode (op_code
);
20851 else switch (op_code
)
20853 case DW_LNS_extended_op
:
20854 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20856 line_ptr
+= bytes_read
;
20857 extended_end
= line_ptr
+ extended_len
;
20858 extended_op
= read_1_byte (abfd
, line_ptr
);
20860 switch (extended_op
)
20862 case DW_LNE_end_sequence
:
20863 state_machine
.handle_end_sequence ();
20864 end_sequence
= true;
20866 case DW_LNE_set_address
:
20869 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
20870 line_ptr
+= bytes_read
;
20872 state_machine
.check_line_address (cu
, line_ptr
,
20874 state_machine
.handle_set_address (baseaddr
, address
);
20877 case DW_LNE_define_file
:
20879 const char *cur_file
;
20880 unsigned int mod_time
, length
;
20883 cur_file
= read_direct_string (abfd
, line_ptr
,
20885 line_ptr
+= bytes_read
;
20886 dindex
= (dir_index
)
20887 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20888 line_ptr
+= bytes_read
;
20890 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20891 line_ptr
+= bytes_read
;
20893 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20894 line_ptr
+= bytes_read
;
20895 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20898 case DW_LNE_set_discriminator
:
20900 /* The discriminator is not interesting to the
20901 debugger; just ignore it. We still need to
20902 check its value though:
20903 if there are consecutive entries for the same
20904 (non-prologue) line we want to coalesce them.
20907 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20908 line_ptr
+= bytes_read
;
20910 state_machine
.handle_set_discriminator (discr
);
20914 complaint (&symfile_complaints
,
20915 _("mangled .debug_line section"));
20918 /* Make sure that we parsed the extended op correctly. If e.g.
20919 we expected a different address size than the producer used,
20920 we may have read the wrong number of bytes. */
20921 if (line_ptr
!= extended_end
)
20923 complaint (&symfile_complaints
,
20924 _("mangled .debug_line section"));
20929 state_machine
.handle_copy ();
20931 case DW_LNS_advance_pc
:
20934 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20935 line_ptr
+= bytes_read
;
20937 state_machine
.handle_advance_pc (adjust
);
20940 case DW_LNS_advance_line
:
20943 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20944 line_ptr
+= bytes_read
;
20946 state_machine
.handle_advance_line (line_delta
);
20949 case DW_LNS_set_file
:
20951 file_name_index file
20952 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20954 line_ptr
+= bytes_read
;
20956 state_machine
.handle_set_file (file
);
20959 case DW_LNS_set_column
:
20960 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20961 line_ptr
+= bytes_read
;
20963 case DW_LNS_negate_stmt
:
20964 state_machine
.handle_negate_stmt ();
20966 case DW_LNS_set_basic_block
:
20968 /* Add to the address register of the state machine the
20969 address increment value corresponding to special opcode
20970 255. I.e., this value is scaled by the minimum
20971 instruction length since special opcode 255 would have
20972 scaled the increment. */
20973 case DW_LNS_const_add_pc
:
20974 state_machine
.handle_const_add_pc ();
20976 case DW_LNS_fixed_advance_pc
:
20978 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20981 state_machine
.handle_fixed_advance_pc (addr_adj
);
20986 /* Unknown standard opcode, ignore it. */
20989 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
20991 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20992 line_ptr
+= bytes_read
;
20999 dwarf2_debug_line_missing_end_sequence_complaint ();
21001 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21002 in which case we still finish recording the last line). */
21003 state_machine
.record_line (true);
21007 /* Decode the Line Number Program (LNP) for the given line_header
21008 structure and CU. The actual information extracted and the type
21009 of structures created from the LNP depends on the value of PST.
21011 1. If PST is NULL, then this procedure uses the data from the program
21012 to create all necessary symbol tables, and their linetables.
21014 2. If PST is not NULL, this procedure reads the program to determine
21015 the list of files included by the unit represented by PST, and
21016 builds all the associated partial symbol tables.
21018 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21019 It is used for relative paths in the line table.
21020 NOTE: When processing partial symtabs (pst != NULL),
21021 comp_dir == pst->dirname.
21023 NOTE: It is important that psymtabs have the same file name (via strcmp)
21024 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21025 symtab we don't use it in the name of the psymtabs we create.
21026 E.g. expand_line_sal requires this when finding psymtabs to expand.
21027 A good testcase for this is mb-inline.exp.
21029 LOWPC is the lowest address in CU (or 0 if not known).
21031 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21032 for its PC<->lines mapping information. Otherwise only the filename
21033 table is read in. */
21036 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21037 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
21038 CORE_ADDR lowpc
, int decode_mapping
)
21040 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21041 const int decode_for_pst_p
= (pst
!= NULL
);
21043 if (decode_mapping
)
21044 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21046 if (decode_for_pst_p
)
21050 /* Now that we're done scanning the Line Header Program, we can
21051 create the psymtab of each included file. */
21052 for (file_index
= 0; file_index
< lh
->file_names
.size (); file_index
++)
21053 if (lh
->file_names
[file_index
].included_p
== 1)
21055 gdb::unique_xmalloc_ptr
<char> name_holder
;
21056 const char *include_name
=
21057 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
,
21059 if (include_name
!= NULL
)
21060 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
21065 /* Make sure a symtab is created for every file, even files
21066 which contain only variables (i.e. no code with associated
21068 struct compunit_symtab
*cust
= buildsym_compunit_symtab ();
21071 for (i
= 0; i
< lh
->file_names
.size (); i
++)
21073 file_entry
&fe
= lh
->file_names
[i
];
21075 dwarf2_start_subfile (fe
.name
, fe
.include_dir (lh
));
21077 if (current_subfile
->symtab
== NULL
)
21079 current_subfile
->symtab
21080 = allocate_symtab (cust
, current_subfile
->name
);
21082 fe
.symtab
= current_subfile
->symtab
;
21087 /* Start a subfile for DWARF. FILENAME is the name of the file and
21088 DIRNAME the name of the source directory which contains FILENAME
21089 or NULL if not known.
21090 This routine tries to keep line numbers from identical absolute and
21091 relative file names in a common subfile.
21093 Using the `list' example from the GDB testsuite, which resides in
21094 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21095 of /srcdir/list0.c yields the following debugging information for list0.c:
21097 DW_AT_name: /srcdir/list0.c
21098 DW_AT_comp_dir: /compdir
21099 files.files[0].name: list0.h
21100 files.files[0].dir: /srcdir
21101 files.files[1].name: list0.c
21102 files.files[1].dir: /srcdir
21104 The line number information for list0.c has to end up in a single
21105 subfile, so that `break /srcdir/list0.c:1' works as expected.
21106 start_subfile will ensure that this happens provided that we pass the
21107 concatenation of files.files[1].dir and files.files[1].name as the
21111 dwarf2_start_subfile (const char *filename
, const char *dirname
)
21115 /* In order not to lose the line information directory,
21116 we concatenate it to the filename when it makes sense.
21117 Note that the Dwarf3 standard says (speaking of filenames in line
21118 information): ``The directory index is ignored for file names
21119 that represent full path names''. Thus ignoring dirname in the
21120 `else' branch below isn't an issue. */
21122 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21124 copy
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
21128 start_subfile (filename
);
21134 /* Start a symtab for DWARF.
21135 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
21137 static struct compunit_symtab
*
21138 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
21139 const char *name
, const char *comp_dir
, CORE_ADDR low_pc
)
21141 struct compunit_symtab
*cust
21142 = start_symtab (cu
->per_cu
->dwarf2_per_objfile
->objfile
, name
, comp_dir
,
21143 low_pc
, cu
->language
);
21145 record_debugformat ("DWARF 2");
21146 record_producer (cu
->producer
);
21148 /* We assume that we're processing GCC output. */
21149 processing_gcc_compilation
= 2;
21151 cu
->processing_has_namespace_info
= 0;
21157 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21158 struct dwarf2_cu
*cu
)
21160 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21161 struct comp_unit_head
*cu_header
= &cu
->header
;
21163 /* NOTE drow/2003-01-30: There used to be a comment and some special
21164 code here to turn a symbol with DW_AT_external and a
21165 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21166 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21167 with some versions of binutils) where shared libraries could have
21168 relocations against symbols in their debug information - the
21169 minimal symbol would have the right address, but the debug info
21170 would not. It's no longer necessary, because we will explicitly
21171 apply relocations when we read in the debug information now. */
21173 /* A DW_AT_location attribute with no contents indicates that a
21174 variable has been optimized away. */
21175 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
21177 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21181 /* Handle one degenerate form of location expression specially, to
21182 preserve GDB's previous behavior when section offsets are
21183 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
21184 then mark this symbol as LOC_STATIC. */
21186 if (attr_form_is_block (attr
)
21187 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
21188 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
21189 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
21190 && (DW_BLOCK (attr
)->size
21191 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
21193 unsigned int dummy
;
21195 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
21196 SYMBOL_VALUE_ADDRESS (sym
) =
21197 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
21199 SYMBOL_VALUE_ADDRESS (sym
) =
21200 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
21201 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21202 fixup_symbol_section (sym
, objfile
);
21203 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
21204 SYMBOL_SECTION (sym
));
21208 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21209 expression evaluator, and use LOC_COMPUTED only when necessary
21210 (i.e. when the value of a register or memory location is
21211 referenced, or a thread-local block, etc.). Then again, it might
21212 not be worthwhile. I'm assuming that it isn't unless performance
21213 or memory numbers show me otherwise. */
21215 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21217 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21218 cu
->has_loclist
= 1;
21221 /* Given a pointer to a DWARF information entry, figure out if we need
21222 to make a symbol table entry for it, and if so, create a new entry
21223 and return a pointer to it.
21224 If TYPE is NULL, determine symbol type from the die, otherwise
21225 used the passed type.
21226 If SPACE is not NULL, use it to hold the new symbol. If it is
21227 NULL, allocate a new symbol on the objfile's obstack. */
21229 static struct symbol
*
21230 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21231 struct symbol
*space
)
21233 struct dwarf2_per_objfile
*dwarf2_per_objfile
21234 = cu
->per_cu
->dwarf2_per_objfile
;
21235 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21236 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21237 struct symbol
*sym
= NULL
;
21239 struct attribute
*attr
= NULL
;
21240 struct attribute
*attr2
= NULL
;
21241 CORE_ADDR baseaddr
;
21242 struct pending
**list_to_add
= NULL
;
21244 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21246 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
21248 name
= dwarf2_name (die
, cu
);
21251 const char *linkagename
;
21252 int suppress_add
= 0;
21257 sym
= allocate_symbol (objfile
);
21258 OBJSTAT (objfile
, n_syms
++);
21260 /* Cache this symbol's name and the name's demangled form (if any). */
21261 SYMBOL_SET_LANGUAGE (sym
, cu
->language
, &objfile
->objfile_obstack
);
21262 linkagename
= dwarf2_physname (name
, die
, cu
);
21263 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
21265 /* Fortran does not have mangling standard and the mangling does differ
21266 between gfortran, iFort etc. */
21267 if (cu
->language
== language_fortran
21268 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
21269 symbol_set_demangled_name (&(sym
->ginfo
),
21270 dwarf2_full_name (name
, die
, cu
),
21273 /* Default assumptions.
21274 Use the passed type or decode it from the die. */
21275 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21276 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21278 SYMBOL_TYPE (sym
) = type
;
21280 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21281 attr
= dwarf2_attr (die
,
21282 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21286 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
21289 attr
= dwarf2_attr (die
,
21290 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21294 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
21295 struct file_entry
*fe
;
21297 if (cu
->line_header
!= NULL
)
21298 fe
= cu
->line_header
->file_name_at (file_index
);
21303 complaint (&symfile_complaints
,
21304 _("file index out of range"));
21306 symbol_set_symtab (sym
, fe
->symtab
);
21312 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21317 addr
= attr_value_as_address (attr
);
21318 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21319 SYMBOL_VALUE_ADDRESS (sym
) = addr
;
21321 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21322 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21323 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21324 add_symbol_to_list (sym
, cu
->list_in_scope
);
21326 case DW_TAG_subprogram
:
21327 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21329 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21330 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21331 if ((attr2
&& (DW_UNSND (attr2
) != 0))
21332 || cu
->language
== language_ada
)
21334 /* Subprograms marked external are stored as a global symbol.
21335 Ada subprograms, whether marked external or not, are always
21336 stored as a global symbol, because we want to be able to
21337 access them globally. For instance, we want to be able
21338 to break on a nested subprogram without having to
21339 specify the context. */
21340 list_to_add
= &global_symbols
;
21344 list_to_add
= cu
->list_in_scope
;
21347 case DW_TAG_inlined_subroutine
:
21348 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21350 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21351 SYMBOL_INLINED (sym
) = 1;
21352 list_to_add
= cu
->list_in_scope
;
21354 case DW_TAG_template_value_param
:
21356 /* Fall through. */
21357 case DW_TAG_constant
:
21358 case DW_TAG_variable
:
21359 case DW_TAG_member
:
21360 /* Compilation with minimal debug info may result in
21361 variables with missing type entries. Change the
21362 misleading `void' type to something sensible. */
21363 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
21364 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21366 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21367 /* In the case of DW_TAG_member, we should only be called for
21368 static const members. */
21369 if (die
->tag
== DW_TAG_member
)
21371 /* dwarf2_add_field uses die_is_declaration,
21372 so we do the same. */
21373 gdb_assert (die_is_declaration (die
, cu
));
21378 dwarf2_const_value (attr
, sym
, cu
);
21379 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21382 if (attr2
&& (DW_UNSND (attr2
) != 0))
21383 list_to_add
= &global_symbols
;
21385 list_to_add
= cu
->list_in_scope
;
21389 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21392 var_decode_location (attr
, sym
, cu
);
21393 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21395 /* Fortran explicitly imports any global symbols to the local
21396 scope by DW_TAG_common_block. */
21397 if (cu
->language
== language_fortran
&& die
->parent
21398 && die
->parent
->tag
== DW_TAG_common_block
)
21401 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21402 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21403 && !dwarf2_per_objfile
->has_section_at_zero
)
21405 /* When a static variable is eliminated by the linker,
21406 the corresponding debug information is not stripped
21407 out, but the variable address is set to null;
21408 do not add such variables into symbol table. */
21410 else if (attr2
&& (DW_UNSND (attr2
) != 0))
21412 /* Workaround gfortran PR debug/40040 - it uses
21413 DW_AT_location for variables in -fPIC libraries which may
21414 get overriden by other libraries/executable and get
21415 a different address. Resolve it by the minimal symbol
21416 which may come from inferior's executable using copy
21417 relocation. Make this workaround only for gfortran as for
21418 other compilers GDB cannot guess the minimal symbol
21419 Fortran mangling kind. */
21420 if (cu
->language
== language_fortran
&& die
->parent
21421 && die
->parent
->tag
== DW_TAG_module
21423 && startswith (cu
->producer
, "GNU Fortran"))
21424 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21426 /* A variable with DW_AT_external is never static,
21427 but it may be block-scoped. */
21428 list_to_add
= (cu
->list_in_scope
== &file_symbols
21429 ? &global_symbols
: cu
->list_in_scope
);
21432 list_to_add
= cu
->list_in_scope
;
21436 /* We do not know the address of this symbol.
21437 If it is an external symbol and we have type information
21438 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21439 The address of the variable will then be determined from
21440 the minimal symbol table whenever the variable is
21442 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21444 /* Fortran explicitly imports any global symbols to the local
21445 scope by DW_TAG_common_block. */
21446 if (cu
->language
== language_fortran
&& die
->parent
21447 && die
->parent
->tag
== DW_TAG_common_block
)
21449 /* SYMBOL_CLASS doesn't matter here because
21450 read_common_block is going to reset it. */
21452 list_to_add
= cu
->list_in_scope
;
21454 else if (attr2
&& (DW_UNSND (attr2
) != 0)
21455 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21457 /* A variable with DW_AT_external is never static, but it
21458 may be block-scoped. */
21459 list_to_add
= (cu
->list_in_scope
== &file_symbols
21460 ? &global_symbols
: cu
->list_in_scope
);
21462 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21464 else if (!die_is_declaration (die
, cu
))
21466 /* Use the default LOC_OPTIMIZED_OUT class. */
21467 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21469 list_to_add
= cu
->list_in_scope
;
21473 case DW_TAG_formal_parameter
:
21474 /* If we are inside a function, mark this as an argument. If
21475 not, we might be looking at an argument to an inlined function
21476 when we do not have enough information to show inlined frames;
21477 pretend it's a local variable in that case so that the user can
21479 if (context_stack_depth
> 0
21480 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
21481 SYMBOL_IS_ARGUMENT (sym
) = 1;
21482 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21485 var_decode_location (attr
, sym
, cu
);
21487 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21490 dwarf2_const_value (attr
, sym
, cu
);
21493 list_to_add
= cu
->list_in_scope
;
21495 case DW_TAG_unspecified_parameters
:
21496 /* From varargs functions; gdb doesn't seem to have any
21497 interest in this information, so just ignore it for now.
21500 case DW_TAG_template_type_param
:
21502 /* Fall through. */
21503 case DW_TAG_class_type
:
21504 case DW_TAG_interface_type
:
21505 case DW_TAG_structure_type
:
21506 case DW_TAG_union_type
:
21507 case DW_TAG_set_type
:
21508 case DW_TAG_enumeration_type
:
21509 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21510 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21513 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21514 really ever be static objects: otherwise, if you try
21515 to, say, break of a class's method and you're in a file
21516 which doesn't mention that class, it won't work unless
21517 the check for all static symbols in lookup_symbol_aux
21518 saves you. See the OtherFileClass tests in
21519 gdb.c++/namespace.exp. */
21523 list_to_add
= (cu
->list_in_scope
== &file_symbols
21524 && cu
->language
== language_cplus
21525 ? &global_symbols
: cu
->list_in_scope
);
21527 /* The semantics of C++ state that "struct foo {
21528 ... }" also defines a typedef for "foo". */
21529 if (cu
->language
== language_cplus
21530 || cu
->language
== language_ada
21531 || cu
->language
== language_d
21532 || cu
->language
== language_rust
)
21534 /* The symbol's name is already allocated along
21535 with this objfile, so we don't need to
21536 duplicate it for the type. */
21537 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
21538 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
21543 case DW_TAG_typedef
:
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_base_type
:
21549 case DW_TAG_subrange_type
:
21550 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21551 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21552 list_to_add
= cu
->list_in_scope
;
21554 case DW_TAG_enumerator
:
21555 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21558 dwarf2_const_value (attr
, sym
, cu
);
21561 /* NOTE: carlton/2003-11-10: See comment above in the
21562 DW_TAG_class_type, etc. block. */
21564 list_to_add
= (cu
->list_in_scope
== &file_symbols
21565 && cu
->language
== language_cplus
21566 ? &global_symbols
: cu
->list_in_scope
);
21569 case DW_TAG_imported_declaration
:
21570 case DW_TAG_namespace
:
21571 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21572 list_to_add
= &global_symbols
;
21574 case DW_TAG_module
:
21575 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21576 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21577 list_to_add
= &global_symbols
;
21579 case DW_TAG_common_block
:
21580 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21581 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21582 add_symbol_to_list (sym
, cu
->list_in_scope
);
21585 /* Not a tag we recognize. Hopefully we aren't processing
21586 trash data, but since we must specifically ignore things
21587 we don't recognize, there is nothing else we should do at
21589 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
21590 dwarf_tag_name (die
->tag
));
21596 sym
->hash_next
= objfile
->template_symbols
;
21597 objfile
->template_symbols
= sym
;
21598 list_to_add
= NULL
;
21601 if (list_to_add
!= NULL
)
21602 add_symbol_to_list (sym
, list_to_add
);
21604 /* For the benefit of old versions of GCC, check for anonymous
21605 namespaces based on the demangled name. */
21606 if (!cu
->processing_has_namespace_info
21607 && cu
->language
== language_cplus
)
21608 cp_scan_for_anonymous_namespaces (sym
, objfile
);
21613 /* Given an attr with a DW_FORM_dataN value in host byte order,
21614 zero-extend it as appropriate for the symbol's type. The DWARF
21615 standard (v4) is not entirely clear about the meaning of using
21616 DW_FORM_dataN for a constant with a signed type, where the type is
21617 wider than the data. The conclusion of a discussion on the DWARF
21618 list was that this is unspecified. We choose to always zero-extend
21619 because that is the interpretation long in use by GCC. */
21622 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21623 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21625 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21626 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21627 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21628 LONGEST l
= DW_UNSND (attr
);
21630 if (bits
< sizeof (*value
) * 8)
21632 l
&= ((LONGEST
) 1 << bits
) - 1;
21635 else if (bits
== sizeof (*value
) * 8)
21639 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21640 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21647 /* Read a constant value from an attribute. Either set *VALUE, or if
21648 the value does not fit in *VALUE, set *BYTES - either already
21649 allocated on the objfile obstack, or newly allocated on OBSTACK,
21650 or, set *BATON, if we translated the constant to a location
21654 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21655 const char *name
, struct obstack
*obstack
,
21656 struct dwarf2_cu
*cu
,
21657 LONGEST
*value
, const gdb_byte
**bytes
,
21658 struct dwarf2_locexpr_baton
**baton
)
21660 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21661 struct comp_unit_head
*cu_header
= &cu
->header
;
21662 struct dwarf_block
*blk
;
21663 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21664 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21670 switch (attr
->form
)
21673 case DW_FORM_GNU_addr_index
:
21677 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21678 dwarf2_const_value_length_mismatch_complaint (name
,
21679 cu_header
->addr_size
,
21680 TYPE_LENGTH (type
));
21681 /* Symbols of this form are reasonably rare, so we just
21682 piggyback on the existing location code rather than writing
21683 a new implementation of symbol_computed_ops. */
21684 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21685 (*baton
)->per_cu
= cu
->per_cu
;
21686 gdb_assert ((*baton
)->per_cu
);
21688 (*baton
)->size
= 2 + cu_header
->addr_size
;
21689 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
21690 (*baton
)->data
= data
;
21692 data
[0] = DW_OP_addr
;
21693 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
21694 byte_order
, DW_ADDR (attr
));
21695 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
21698 case DW_FORM_string
:
21700 case DW_FORM_GNU_str_index
:
21701 case DW_FORM_GNU_strp_alt
:
21702 /* DW_STRING is already allocated on the objfile obstack, point
21704 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
21706 case DW_FORM_block1
:
21707 case DW_FORM_block2
:
21708 case DW_FORM_block4
:
21709 case DW_FORM_block
:
21710 case DW_FORM_exprloc
:
21711 case DW_FORM_data16
:
21712 blk
= DW_BLOCK (attr
);
21713 if (TYPE_LENGTH (type
) != blk
->size
)
21714 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
21715 TYPE_LENGTH (type
));
21716 *bytes
= blk
->data
;
21719 /* The DW_AT_const_value attributes are supposed to carry the
21720 symbol's value "represented as it would be on the target
21721 architecture." By the time we get here, it's already been
21722 converted to host endianness, so we just need to sign- or
21723 zero-extend it as appropriate. */
21724 case DW_FORM_data1
:
21725 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21727 case DW_FORM_data2
:
21728 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21730 case DW_FORM_data4
:
21731 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21733 case DW_FORM_data8
:
21734 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21737 case DW_FORM_sdata
:
21738 case DW_FORM_implicit_const
:
21739 *value
= DW_SND (attr
);
21742 case DW_FORM_udata
:
21743 *value
= DW_UNSND (attr
);
21747 complaint (&symfile_complaints
,
21748 _("unsupported const value attribute form: '%s'"),
21749 dwarf_form_name (attr
->form
));
21756 /* Copy constant value from an attribute to a symbol. */
21759 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21760 struct dwarf2_cu
*cu
)
21762 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21764 const gdb_byte
*bytes
;
21765 struct dwarf2_locexpr_baton
*baton
;
21767 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21768 SYMBOL_PRINT_NAME (sym
),
21769 &objfile
->objfile_obstack
, cu
,
21770 &value
, &bytes
, &baton
);
21774 SYMBOL_LOCATION_BATON (sym
) = baton
;
21775 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21777 else if (bytes
!= NULL
)
21779 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21780 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21784 SYMBOL_VALUE (sym
) = value
;
21785 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21789 /* Return the type of the die in question using its DW_AT_type attribute. */
21791 static struct type
*
21792 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21794 struct attribute
*type_attr
;
21796 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21799 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21800 /* A missing DW_AT_type represents a void type. */
21801 return objfile_type (objfile
)->builtin_void
;
21804 return lookup_die_type (die
, type_attr
, cu
);
21807 /* True iff CU's producer generates GNAT Ada auxiliary information
21808 that allows to find parallel types through that information instead
21809 of having to do expensive parallel lookups by type name. */
21812 need_gnat_info (struct dwarf2_cu
*cu
)
21814 /* Assume that the Ada compiler was GNAT, which always produces
21815 the auxiliary information. */
21816 return (cu
->language
== language_ada
);
21819 /* Return the auxiliary type of the die in question using its
21820 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21821 attribute is not present. */
21823 static struct type
*
21824 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21826 struct attribute
*type_attr
;
21828 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21832 return lookup_die_type (die
, type_attr
, cu
);
21835 /* If DIE has a descriptive_type attribute, then set the TYPE's
21836 descriptive type accordingly. */
21839 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21840 struct dwarf2_cu
*cu
)
21842 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21844 if (descriptive_type
)
21846 ALLOCATE_GNAT_AUX_TYPE (type
);
21847 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21851 /* Return the containing type of the die in question using its
21852 DW_AT_containing_type attribute. */
21854 static struct type
*
21855 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21857 struct attribute
*type_attr
;
21858 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21860 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21862 error (_("Dwarf Error: Problem turning containing type into gdb type "
21863 "[in module %s]"), objfile_name (objfile
));
21865 return lookup_die_type (die
, type_attr
, cu
);
21868 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21870 static struct type
*
21871 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21873 struct dwarf2_per_objfile
*dwarf2_per_objfile
21874 = cu
->per_cu
->dwarf2_per_objfile
;
21875 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21876 char *message
, *saved
;
21878 message
= xstrprintf (_("<unknown type in %s, CU %s, DIE %s>"),
21879 objfile_name (objfile
),
21880 sect_offset_str (cu
->header
.sect_off
),
21881 sect_offset_str (die
->sect_off
));
21882 saved
= (char *) obstack_copy0 (&objfile
->objfile_obstack
,
21883 message
, strlen (message
));
21886 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21889 /* Look up the type of DIE in CU using its type attribute ATTR.
21890 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21891 DW_AT_containing_type.
21892 If there is no type substitute an error marker. */
21894 static struct type
*
21895 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21896 struct dwarf2_cu
*cu
)
21898 struct dwarf2_per_objfile
*dwarf2_per_objfile
21899 = cu
->per_cu
->dwarf2_per_objfile
;
21900 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21901 struct type
*this_type
;
21903 gdb_assert (attr
->name
== DW_AT_type
21904 || attr
->name
== DW_AT_GNAT_descriptive_type
21905 || attr
->name
== DW_AT_containing_type
);
21907 /* First see if we have it cached. */
21909 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21911 struct dwarf2_per_cu_data
*per_cu
;
21912 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21914 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
21915 dwarf2_per_objfile
);
21916 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
21918 else if (attr_form_is_ref (attr
))
21920 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21922 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
21924 else if (attr
->form
== DW_FORM_ref_sig8
)
21926 ULONGEST signature
= DW_SIGNATURE (attr
);
21928 return get_signatured_type (die
, signature
, cu
);
21932 complaint (&symfile_complaints
,
21933 _("Dwarf Error: Bad type attribute %s in DIE"
21934 " at %s [in module %s]"),
21935 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
21936 objfile_name (objfile
));
21937 return build_error_marker_type (cu
, die
);
21940 /* If not cached we need to read it in. */
21942 if (this_type
== NULL
)
21944 struct die_info
*type_die
= NULL
;
21945 struct dwarf2_cu
*type_cu
= cu
;
21947 if (attr_form_is_ref (attr
))
21948 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21949 if (type_die
== NULL
)
21950 return build_error_marker_type (cu
, die
);
21951 /* If we find the type now, it's probably because the type came
21952 from an inter-CU reference and the type's CU got expanded before
21954 this_type
= read_type_die (type_die
, type_cu
);
21957 /* If we still don't have a type use an error marker. */
21959 if (this_type
== NULL
)
21960 return build_error_marker_type (cu
, die
);
21965 /* Return the type in DIE, CU.
21966 Returns NULL for invalid types.
21968 This first does a lookup in die_type_hash,
21969 and only reads the die in if necessary.
21971 NOTE: This can be called when reading in partial or full symbols. */
21973 static struct type
*
21974 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21976 struct type
*this_type
;
21978 this_type
= get_die_type (die
, cu
);
21982 return read_type_die_1 (die
, cu
);
21985 /* Read the type in DIE, CU.
21986 Returns NULL for invalid types. */
21988 static struct type
*
21989 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
21991 struct type
*this_type
= NULL
;
21995 case DW_TAG_class_type
:
21996 case DW_TAG_interface_type
:
21997 case DW_TAG_structure_type
:
21998 case DW_TAG_union_type
:
21999 this_type
= read_structure_type (die
, cu
);
22001 case DW_TAG_enumeration_type
:
22002 this_type
= read_enumeration_type (die
, cu
);
22004 case DW_TAG_subprogram
:
22005 case DW_TAG_subroutine_type
:
22006 case DW_TAG_inlined_subroutine
:
22007 this_type
= read_subroutine_type (die
, cu
);
22009 case DW_TAG_array_type
:
22010 this_type
= read_array_type (die
, cu
);
22012 case DW_TAG_set_type
:
22013 this_type
= read_set_type (die
, cu
);
22015 case DW_TAG_pointer_type
:
22016 this_type
= read_tag_pointer_type (die
, cu
);
22018 case DW_TAG_ptr_to_member_type
:
22019 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22021 case DW_TAG_reference_type
:
22022 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22024 case DW_TAG_rvalue_reference_type
:
22025 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22027 case DW_TAG_const_type
:
22028 this_type
= read_tag_const_type (die
, cu
);
22030 case DW_TAG_volatile_type
:
22031 this_type
= read_tag_volatile_type (die
, cu
);
22033 case DW_TAG_restrict_type
:
22034 this_type
= read_tag_restrict_type (die
, cu
);
22036 case DW_TAG_string_type
:
22037 this_type
= read_tag_string_type (die
, cu
);
22039 case DW_TAG_typedef
:
22040 this_type
= read_typedef (die
, cu
);
22042 case DW_TAG_subrange_type
:
22043 this_type
= read_subrange_type (die
, cu
);
22045 case DW_TAG_base_type
:
22046 this_type
= read_base_type (die
, cu
);
22048 case DW_TAG_unspecified_type
:
22049 this_type
= read_unspecified_type (die
, cu
);
22051 case DW_TAG_namespace
:
22052 this_type
= read_namespace_type (die
, cu
);
22054 case DW_TAG_module
:
22055 this_type
= read_module_type (die
, cu
);
22057 case DW_TAG_atomic_type
:
22058 this_type
= read_tag_atomic_type (die
, cu
);
22061 complaint (&symfile_complaints
,
22062 _("unexpected tag in read_type_die: '%s'"),
22063 dwarf_tag_name (die
->tag
));
22070 /* See if we can figure out if the class lives in a namespace. We do
22071 this by looking for a member function; its demangled name will
22072 contain namespace info, if there is any.
22073 Return the computed name or NULL.
22074 Space for the result is allocated on the objfile's obstack.
22075 This is the full-die version of guess_partial_die_structure_name.
22076 In this case we know DIE has no useful parent. */
22079 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22081 struct die_info
*spec_die
;
22082 struct dwarf2_cu
*spec_cu
;
22083 struct die_info
*child
;
22084 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22087 spec_die
= die_specification (die
, &spec_cu
);
22088 if (spec_die
!= NULL
)
22094 for (child
= die
->child
;
22096 child
= child
->sibling
)
22098 if (child
->tag
== DW_TAG_subprogram
)
22100 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22102 if (linkage_name
!= NULL
)
22105 = language_class_name_from_physname (cu
->language_defn
,
22109 if (actual_name
!= NULL
)
22111 const char *die_name
= dwarf2_name (die
, cu
);
22113 if (die_name
!= NULL
22114 && strcmp (die_name
, actual_name
) != 0)
22116 /* Strip off the class name from the full name.
22117 We want the prefix. */
22118 int die_name_len
= strlen (die_name
);
22119 int actual_name_len
= strlen (actual_name
);
22121 /* Test for '::' as a sanity check. */
22122 if (actual_name_len
> die_name_len
+ 2
22123 && actual_name
[actual_name_len
22124 - die_name_len
- 1] == ':')
22125 name
= (char *) obstack_copy0 (
22126 &objfile
->per_bfd
->storage_obstack
,
22127 actual_name
, actual_name_len
- die_name_len
- 2);
22130 xfree (actual_name
);
22139 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22140 prefix part in such case. See
22141 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22143 static const char *
22144 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22146 struct attribute
*attr
;
22149 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22150 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22153 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22156 attr
= dw2_linkage_name_attr (die
, cu
);
22157 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22160 /* dwarf2_name had to be already called. */
22161 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
22163 /* Strip the base name, keep any leading namespaces/classes. */
22164 base
= strrchr (DW_STRING (attr
), ':');
22165 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
22168 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22169 return (char *) obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
22171 &base
[-1] - DW_STRING (attr
));
22174 /* Return the name of the namespace/class that DIE is defined within,
22175 or "" if we can't tell. The caller should not xfree the result.
22177 For example, if we're within the method foo() in the following
22187 then determine_prefix on foo's die will return "N::C". */
22189 static const char *
22190 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22192 struct dwarf2_per_objfile
*dwarf2_per_objfile
22193 = cu
->per_cu
->dwarf2_per_objfile
;
22194 struct die_info
*parent
, *spec_die
;
22195 struct dwarf2_cu
*spec_cu
;
22196 struct type
*parent_type
;
22197 const char *retval
;
22199 if (cu
->language
!= language_cplus
22200 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22201 && cu
->language
!= language_rust
)
22204 retval
= anonymous_struct_prefix (die
, cu
);
22208 /* We have to be careful in the presence of DW_AT_specification.
22209 For example, with GCC 3.4, given the code
22213 // Definition of N::foo.
22217 then we'll have a tree of DIEs like this:
22219 1: DW_TAG_compile_unit
22220 2: DW_TAG_namespace // N
22221 3: DW_TAG_subprogram // declaration of N::foo
22222 4: DW_TAG_subprogram // definition of N::foo
22223 DW_AT_specification // refers to die #3
22225 Thus, when processing die #4, we have to pretend that we're in
22226 the context of its DW_AT_specification, namely the contex of die
22229 spec_die
= die_specification (die
, &spec_cu
);
22230 if (spec_die
== NULL
)
22231 parent
= die
->parent
;
22234 parent
= spec_die
->parent
;
22238 if (parent
== NULL
)
22240 else if (parent
->building_fullname
)
22243 const char *parent_name
;
22245 /* It has been seen on RealView 2.2 built binaries,
22246 DW_TAG_template_type_param types actually _defined_ as
22247 children of the parent class:
22250 template class <class Enum> Class{};
22251 Class<enum E> class_e;
22253 1: DW_TAG_class_type (Class)
22254 2: DW_TAG_enumeration_type (E)
22255 3: DW_TAG_enumerator (enum1:0)
22256 3: DW_TAG_enumerator (enum2:1)
22258 2: DW_TAG_template_type_param
22259 DW_AT_type DW_FORM_ref_udata (E)
22261 Besides being broken debug info, it can put GDB into an
22262 infinite loop. Consider:
22264 When we're building the full name for Class<E>, we'll start
22265 at Class, and go look over its template type parameters,
22266 finding E. We'll then try to build the full name of E, and
22267 reach here. We're now trying to build the full name of E,
22268 and look over the parent DIE for containing scope. In the
22269 broken case, if we followed the parent DIE of E, we'd again
22270 find Class, and once again go look at its template type
22271 arguments, etc., etc. Simply don't consider such parent die
22272 as source-level parent of this die (it can't be, the language
22273 doesn't allow it), and break the loop here. */
22274 name
= dwarf2_name (die
, cu
);
22275 parent_name
= dwarf2_name (parent
, cu
);
22276 complaint (&symfile_complaints
,
22277 _("template param type '%s' defined within parent '%s'"),
22278 name
? name
: "<unknown>",
22279 parent_name
? parent_name
: "<unknown>");
22283 switch (parent
->tag
)
22285 case DW_TAG_namespace
:
22286 parent_type
= read_type_die (parent
, cu
);
22287 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22288 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22289 Work around this problem here. */
22290 if (cu
->language
== language_cplus
22291 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
22293 /* We give a name to even anonymous namespaces. */
22294 return TYPE_TAG_NAME (parent_type
);
22295 case DW_TAG_class_type
:
22296 case DW_TAG_interface_type
:
22297 case DW_TAG_structure_type
:
22298 case DW_TAG_union_type
:
22299 case DW_TAG_module
:
22300 parent_type
= read_type_die (parent
, cu
);
22301 if (TYPE_TAG_NAME (parent_type
) != NULL
)
22302 return TYPE_TAG_NAME (parent_type
);
22304 /* An anonymous structure is only allowed non-static data
22305 members; no typedefs, no member functions, et cetera.
22306 So it does not need a prefix. */
22308 case DW_TAG_compile_unit
:
22309 case DW_TAG_partial_unit
:
22310 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22311 if (cu
->language
== language_cplus
22312 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
22313 && die
->child
!= NULL
22314 && (die
->tag
== DW_TAG_class_type
22315 || die
->tag
== DW_TAG_structure_type
22316 || die
->tag
== DW_TAG_union_type
))
22318 char *name
= guess_full_die_structure_name (die
, cu
);
22323 case DW_TAG_enumeration_type
:
22324 parent_type
= read_type_die (parent
, cu
);
22325 if (TYPE_DECLARED_CLASS (parent_type
))
22327 if (TYPE_TAG_NAME (parent_type
) != NULL
)
22328 return TYPE_TAG_NAME (parent_type
);
22331 /* Fall through. */
22333 return determine_prefix (parent
, cu
);
22337 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22338 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22339 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22340 an obconcat, otherwise allocate storage for the result. The CU argument is
22341 used to determine the language and hence, the appropriate separator. */
22343 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22346 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22347 int physname
, struct dwarf2_cu
*cu
)
22349 const char *lead
= "";
22352 if (suffix
== NULL
|| suffix
[0] == '\0'
22353 || prefix
== NULL
|| prefix
[0] == '\0')
22355 else if (cu
->language
== language_d
)
22357 /* For D, the 'main' function could be defined in any module, but it
22358 should never be prefixed. */
22359 if (strcmp (suffix
, "D main") == 0)
22367 else if (cu
->language
== language_fortran
&& physname
)
22369 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22370 DW_AT_MIPS_linkage_name is preferred and used instead. */
22378 if (prefix
== NULL
)
22380 if (suffix
== NULL
)
22387 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22389 strcpy (retval
, lead
);
22390 strcat (retval
, prefix
);
22391 strcat (retval
, sep
);
22392 strcat (retval
, suffix
);
22397 /* We have an obstack. */
22398 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22402 /* Return sibling of die, NULL if no sibling. */
22404 static struct die_info
*
22405 sibling_die (struct die_info
*die
)
22407 return die
->sibling
;
22410 /* Get name of a die, return NULL if not found. */
22412 static const char *
22413 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22414 struct obstack
*obstack
)
22416 if (name
&& cu
->language
== language_cplus
)
22418 std::string canon_name
= cp_canonicalize_string (name
);
22420 if (!canon_name
.empty ())
22422 if (canon_name
!= name
)
22423 name
= (const char *) obstack_copy0 (obstack
,
22424 canon_name
.c_str (),
22425 canon_name
.length ());
22432 /* Get name of a die, return NULL if not found.
22433 Anonymous namespaces are converted to their magic string. */
22435 static const char *
22436 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22438 struct attribute
*attr
;
22439 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22441 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22442 if ((!attr
|| !DW_STRING (attr
))
22443 && die
->tag
!= DW_TAG_namespace
22444 && die
->tag
!= DW_TAG_class_type
22445 && die
->tag
!= DW_TAG_interface_type
22446 && die
->tag
!= DW_TAG_structure_type
22447 && die
->tag
!= DW_TAG_union_type
)
22452 case DW_TAG_compile_unit
:
22453 case DW_TAG_partial_unit
:
22454 /* Compilation units have a DW_AT_name that is a filename, not
22455 a source language identifier. */
22456 case DW_TAG_enumeration_type
:
22457 case DW_TAG_enumerator
:
22458 /* These tags always have simple identifiers already; no need
22459 to canonicalize them. */
22460 return DW_STRING (attr
);
22462 case DW_TAG_namespace
:
22463 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
22464 return DW_STRING (attr
);
22465 return CP_ANONYMOUS_NAMESPACE_STR
;
22467 case DW_TAG_class_type
:
22468 case DW_TAG_interface_type
:
22469 case DW_TAG_structure_type
:
22470 case DW_TAG_union_type
:
22471 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22472 structures or unions. These were of the form "._%d" in GCC 4.1,
22473 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22474 and GCC 4.4. We work around this problem by ignoring these. */
22475 if (attr
&& DW_STRING (attr
)
22476 && (startswith (DW_STRING (attr
), "._")
22477 || startswith (DW_STRING (attr
), "<anonymous")))
22480 /* GCC might emit a nameless typedef that has a linkage name. See
22481 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22482 if (!attr
|| DW_STRING (attr
) == NULL
)
22484 char *demangled
= NULL
;
22486 attr
= dw2_linkage_name_attr (die
, cu
);
22487 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22490 /* Avoid demangling DW_STRING (attr) the second time on a second
22491 call for the same DIE. */
22492 if (!DW_STRING_IS_CANONICAL (attr
))
22493 demangled
= gdb_demangle (DW_STRING (attr
), DMGL_TYPES
);
22499 /* FIXME: we already did this for the partial symbol... */
22502 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
22503 demangled
, strlen (demangled
)));
22504 DW_STRING_IS_CANONICAL (attr
) = 1;
22507 /* Strip any leading namespaces/classes, keep only the base name.
22508 DW_AT_name for named DIEs does not contain the prefixes. */
22509 base
= strrchr (DW_STRING (attr
), ':');
22510 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
22513 return DW_STRING (attr
);
22522 if (!DW_STRING_IS_CANONICAL (attr
))
22525 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
22526 &objfile
->per_bfd
->storage_obstack
);
22527 DW_STRING_IS_CANONICAL (attr
) = 1;
22529 return DW_STRING (attr
);
22532 /* Return the die that this die in an extension of, or NULL if there
22533 is none. *EXT_CU is the CU containing DIE on input, and the CU
22534 containing the return value on output. */
22536 static struct die_info
*
22537 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22539 struct attribute
*attr
;
22541 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22545 return follow_die_ref (die
, attr
, ext_cu
);
22548 /* Convert a DIE tag into its string name. */
22550 static const char *
22551 dwarf_tag_name (unsigned tag
)
22553 const char *name
= get_DW_TAG_name (tag
);
22556 return "DW_TAG_<unknown>";
22561 /* Convert a DWARF attribute code into its string name. */
22563 static const char *
22564 dwarf_attr_name (unsigned attr
)
22568 #ifdef MIPS /* collides with DW_AT_HP_block_index */
22569 if (attr
== DW_AT_MIPS_fde
)
22570 return "DW_AT_MIPS_fde";
22572 if (attr
== DW_AT_HP_block_index
)
22573 return "DW_AT_HP_block_index";
22576 name
= get_DW_AT_name (attr
);
22579 return "DW_AT_<unknown>";
22584 /* Convert a DWARF value form code into its string name. */
22586 static const char *
22587 dwarf_form_name (unsigned form
)
22589 const char *name
= get_DW_FORM_name (form
);
22592 return "DW_FORM_<unknown>";
22597 static const char *
22598 dwarf_bool_name (unsigned mybool
)
22606 /* Convert a DWARF type code into its string name. */
22608 static const char *
22609 dwarf_type_encoding_name (unsigned enc
)
22611 const char *name
= get_DW_ATE_name (enc
);
22614 return "DW_ATE_<unknown>";
22620 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22624 print_spaces (indent
, f
);
22625 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
22626 dwarf_tag_name (die
->tag
), die
->abbrev
,
22627 sect_offset_str (die
->sect_off
));
22629 if (die
->parent
!= NULL
)
22631 print_spaces (indent
, f
);
22632 fprintf_unfiltered (f
, " parent at offset: %s\n",
22633 sect_offset_str (die
->parent
->sect_off
));
22636 print_spaces (indent
, f
);
22637 fprintf_unfiltered (f
, " has children: %s\n",
22638 dwarf_bool_name (die
->child
!= NULL
));
22640 print_spaces (indent
, f
);
22641 fprintf_unfiltered (f
, " attributes:\n");
22643 for (i
= 0; i
< die
->num_attrs
; ++i
)
22645 print_spaces (indent
, f
);
22646 fprintf_unfiltered (f
, " %s (%s) ",
22647 dwarf_attr_name (die
->attrs
[i
].name
),
22648 dwarf_form_name (die
->attrs
[i
].form
));
22650 switch (die
->attrs
[i
].form
)
22653 case DW_FORM_GNU_addr_index
:
22654 fprintf_unfiltered (f
, "address: ");
22655 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
22657 case DW_FORM_block2
:
22658 case DW_FORM_block4
:
22659 case DW_FORM_block
:
22660 case DW_FORM_block1
:
22661 fprintf_unfiltered (f
, "block: size %s",
22662 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22664 case DW_FORM_exprloc
:
22665 fprintf_unfiltered (f
, "expression: size %s",
22666 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22668 case DW_FORM_data16
:
22669 fprintf_unfiltered (f
, "constant of 16 bytes");
22671 case DW_FORM_ref_addr
:
22672 fprintf_unfiltered (f
, "ref address: ");
22673 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22675 case DW_FORM_GNU_ref_alt
:
22676 fprintf_unfiltered (f
, "alt ref address: ");
22677 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22683 case DW_FORM_ref_udata
:
22684 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
22685 (long) (DW_UNSND (&die
->attrs
[i
])));
22687 case DW_FORM_data1
:
22688 case DW_FORM_data2
:
22689 case DW_FORM_data4
:
22690 case DW_FORM_data8
:
22691 case DW_FORM_udata
:
22692 case DW_FORM_sdata
:
22693 fprintf_unfiltered (f
, "constant: %s",
22694 pulongest (DW_UNSND (&die
->attrs
[i
])));
22696 case DW_FORM_sec_offset
:
22697 fprintf_unfiltered (f
, "section offset: %s",
22698 pulongest (DW_UNSND (&die
->attrs
[i
])));
22700 case DW_FORM_ref_sig8
:
22701 fprintf_unfiltered (f
, "signature: %s",
22702 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
22704 case DW_FORM_string
:
22706 case DW_FORM_line_strp
:
22707 case DW_FORM_GNU_str_index
:
22708 case DW_FORM_GNU_strp_alt
:
22709 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22710 DW_STRING (&die
->attrs
[i
])
22711 ? DW_STRING (&die
->attrs
[i
]) : "",
22712 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
22715 if (DW_UNSND (&die
->attrs
[i
]))
22716 fprintf_unfiltered (f
, "flag: TRUE");
22718 fprintf_unfiltered (f
, "flag: FALSE");
22720 case DW_FORM_flag_present
:
22721 fprintf_unfiltered (f
, "flag: TRUE");
22723 case DW_FORM_indirect
:
22724 /* The reader will have reduced the indirect form to
22725 the "base form" so this form should not occur. */
22726 fprintf_unfiltered (f
,
22727 "unexpected attribute form: DW_FORM_indirect");
22729 case DW_FORM_implicit_const
:
22730 fprintf_unfiltered (f
, "constant: %s",
22731 plongest (DW_SND (&die
->attrs
[i
])));
22734 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22735 die
->attrs
[i
].form
);
22738 fprintf_unfiltered (f
, "\n");
22743 dump_die_for_error (struct die_info
*die
)
22745 dump_die_shallow (gdb_stderr
, 0, die
);
22749 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22751 int indent
= level
* 4;
22753 gdb_assert (die
!= NULL
);
22755 if (level
>= max_level
)
22758 dump_die_shallow (f
, indent
, die
);
22760 if (die
->child
!= NULL
)
22762 print_spaces (indent
, f
);
22763 fprintf_unfiltered (f
, " Children:");
22764 if (level
+ 1 < max_level
)
22766 fprintf_unfiltered (f
, "\n");
22767 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22771 fprintf_unfiltered (f
,
22772 " [not printed, max nesting level reached]\n");
22776 if (die
->sibling
!= NULL
&& level
> 0)
22778 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22782 /* This is called from the pdie macro in gdbinit.in.
22783 It's not static so gcc will keep a copy callable from gdb. */
22786 dump_die (struct die_info
*die
, int max_level
)
22788 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22792 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22796 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22797 to_underlying (die
->sect_off
),
22803 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
22807 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
22809 if (attr_form_is_ref (attr
))
22810 return (sect_offset
) DW_UNSND (attr
);
22812 complaint (&symfile_complaints
,
22813 _("unsupported die ref attribute form: '%s'"),
22814 dwarf_form_name (attr
->form
));
22818 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
22819 * the value held by the attribute is not constant. */
22822 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
22824 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
22825 return DW_SND (attr
);
22826 else if (attr
->form
== DW_FORM_udata
22827 || attr
->form
== DW_FORM_data1
22828 || attr
->form
== DW_FORM_data2
22829 || attr
->form
== DW_FORM_data4
22830 || attr
->form
== DW_FORM_data8
)
22831 return DW_UNSND (attr
);
22834 /* For DW_FORM_data16 see attr_form_is_constant. */
22835 complaint (&symfile_complaints
,
22836 _("Attribute value is not a constant (%s)"),
22837 dwarf_form_name (attr
->form
));
22838 return default_value
;
22842 /* Follow reference or signature attribute ATTR of SRC_DIE.
22843 On entry *REF_CU is the CU of SRC_DIE.
22844 On exit *REF_CU is the CU of the result. */
22846 static struct die_info
*
22847 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22848 struct dwarf2_cu
**ref_cu
)
22850 struct die_info
*die
;
22852 if (attr_form_is_ref (attr
))
22853 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22854 else if (attr
->form
== DW_FORM_ref_sig8
)
22855 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22858 dump_die_for_error (src_die
);
22859 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22860 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22866 /* Follow reference OFFSET.
22867 On entry *REF_CU is the CU of the source die referencing OFFSET.
22868 On exit *REF_CU is the CU of the result.
22869 Returns NULL if OFFSET is invalid. */
22871 static struct die_info
*
22872 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22873 struct dwarf2_cu
**ref_cu
)
22875 struct die_info temp_die
;
22876 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22877 struct dwarf2_per_objfile
*dwarf2_per_objfile
22878 = cu
->per_cu
->dwarf2_per_objfile
;
22879 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22881 gdb_assert (cu
->per_cu
!= NULL
);
22885 if (cu
->per_cu
->is_debug_types
)
22887 /* .debug_types CUs cannot reference anything outside their CU.
22888 If they need to, they have to reference a signatured type via
22889 DW_FORM_ref_sig8. */
22890 if (!offset_in_cu_p (&cu
->header
, sect_off
))
22893 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22894 || !offset_in_cu_p (&cu
->header
, sect_off
))
22896 struct dwarf2_per_cu_data
*per_cu
;
22898 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22899 dwarf2_per_objfile
);
22901 /* If necessary, add it to the queue and load its DIEs. */
22902 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
22903 load_full_comp_unit (per_cu
, cu
->language
);
22905 target_cu
= per_cu
->cu
;
22907 else if (cu
->dies
== NULL
)
22909 /* We're loading full DIEs during partial symbol reading. */
22910 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
22911 load_full_comp_unit (cu
->per_cu
, language_minimal
);
22914 *ref_cu
= target_cu
;
22915 temp_die
.sect_off
= sect_off
;
22916 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22918 to_underlying (sect_off
));
22921 /* Follow reference attribute ATTR of SRC_DIE.
22922 On entry *REF_CU is the CU of SRC_DIE.
22923 On exit *REF_CU is the CU of the result. */
22925 static struct die_info
*
22926 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22927 struct dwarf2_cu
**ref_cu
)
22929 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22930 struct dwarf2_cu
*cu
= *ref_cu
;
22931 struct die_info
*die
;
22933 die
= follow_die_offset (sect_off
,
22934 (attr
->form
== DW_FORM_GNU_ref_alt
22935 || cu
->per_cu
->is_dwz
),
22938 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22939 "at %s [in module %s]"),
22940 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22941 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
22946 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
22947 Returned value is intended for DW_OP_call*. Returned
22948 dwarf2_locexpr_baton->data has lifetime of
22949 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
22951 struct dwarf2_locexpr_baton
22952 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22953 struct dwarf2_per_cu_data
*per_cu
,
22954 CORE_ADDR (*get_frame_pc
) (void *baton
),
22957 struct dwarf2_cu
*cu
;
22958 struct die_info
*die
;
22959 struct attribute
*attr
;
22960 struct dwarf2_locexpr_baton retval
;
22961 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
22962 struct dwarf2_per_objfile
*dwarf2_per_objfile
22963 = get_dwarf2_per_objfile (objfile
);
22965 if (per_cu
->cu
== NULL
)
22970 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22971 Instead just throw an error, not much else we can do. */
22972 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22973 sect_offset_str (sect_off
), objfile_name (objfile
));
22976 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22978 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22979 sect_offset_str (sect_off
), objfile_name (objfile
));
22981 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22984 /* DWARF: "If there is no such attribute, then there is no effect.".
22985 DATA is ignored if SIZE is 0. */
22987 retval
.data
= NULL
;
22990 else if (attr_form_is_section_offset (attr
))
22992 struct dwarf2_loclist_baton loclist_baton
;
22993 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22996 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
22998 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23000 retval
.size
= size
;
23004 if (!attr_form_is_block (attr
))
23005 error (_("Dwarf Error: DIE at %s referenced in module %s "
23006 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23007 sect_offset_str (sect_off
), objfile_name (objfile
));
23009 retval
.data
= DW_BLOCK (attr
)->data
;
23010 retval
.size
= DW_BLOCK (attr
)->size
;
23012 retval
.per_cu
= cu
->per_cu
;
23014 age_cached_comp_units (dwarf2_per_objfile
);
23019 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
23022 struct dwarf2_locexpr_baton
23023 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23024 struct dwarf2_per_cu_data
*per_cu
,
23025 CORE_ADDR (*get_frame_pc
) (void *baton
),
23028 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23030 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
23033 /* Write a constant of a given type as target-ordered bytes into
23036 static const gdb_byte
*
23037 write_constant_as_bytes (struct obstack
*obstack
,
23038 enum bfd_endian byte_order
,
23045 *len
= TYPE_LENGTH (type
);
23046 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23047 store_unsigned_integer (result
, *len
, byte_order
, value
);
23052 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
23053 pointer to the constant bytes and set LEN to the length of the
23054 data. If memory is needed, allocate it on OBSTACK. If the DIE
23055 does not have a DW_AT_const_value, return NULL. */
23058 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23059 struct dwarf2_per_cu_data
*per_cu
,
23060 struct obstack
*obstack
,
23063 struct dwarf2_cu
*cu
;
23064 struct die_info
*die
;
23065 struct attribute
*attr
;
23066 const gdb_byte
*result
= NULL
;
23069 enum bfd_endian byte_order
;
23070 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
23072 if (per_cu
->cu
== NULL
)
23077 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23078 Instead just throw an error, not much else we can do. */
23079 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23080 sect_offset_str (sect_off
), objfile_name (objfile
));
23083 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23085 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23086 sect_offset_str (sect_off
), objfile_name (objfile
));
23088 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23092 byte_order
= (bfd_big_endian (objfile
->obfd
)
23093 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23095 switch (attr
->form
)
23098 case DW_FORM_GNU_addr_index
:
23102 *len
= cu
->header
.addr_size
;
23103 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23104 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
23108 case DW_FORM_string
:
23110 case DW_FORM_GNU_str_index
:
23111 case DW_FORM_GNU_strp_alt
:
23112 /* DW_STRING is already allocated on the objfile obstack, point
23114 result
= (const gdb_byte
*) DW_STRING (attr
);
23115 *len
= strlen (DW_STRING (attr
));
23117 case DW_FORM_block1
:
23118 case DW_FORM_block2
:
23119 case DW_FORM_block4
:
23120 case DW_FORM_block
:
23121 case DW_FORM_exprloc
:
23122 case DW_FORM_data16
:
23123 result
= DW_BLOCK (attr
)->data
;
23124 *len
= DW_BLOCK (attr
)->size
;
23127 /* The DW_AT_const_value attributes are supposed to carry the
23128 symbol's value "represented as it would be on the target
23129 architecture." By the time we get here, it's already been
23130 converted to host endianness, so we just need to sign- or
23131 zero-extend it as appropriate. */
23132 case DW_FORM_data1
:
23133 type
= die_type (die
, cu
);
23134 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23135 if (result
== NULL
)
23136 result
= write_constant_as_bytes (obstack
, byte_order
,
23139 case DW_FORM_data2
:
23140 type
= die_type (die
, cu
);
23141 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23142 if (result
== NULL
)
23143 result
= write_constant_as_bytes (obstack
, byte_order
,
23146 case DW_FORM_data4
:
23147 type
= die_type (die
, cu
);
23148 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23149 if (result
== NULL
)
23150 result
= write_constant_as_bytes (obstack
, byte_order
,
23153 case DW_FORM_data8
:
23154 type
= die_type (die
, cu
);
23155 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23156 if (result
== NULL
)
23157 result
= write_constant_as_bytes (obstack
, byte_order
,
23161 case DW_FORM_sdata
:
23162 case DW_FORM_implicit_const
:
23163 type
= die_type (die
, cu
);
23164 result
= write_constant_as_bytes (obstack
, byte_order
,
23165 type
, DW_SND (attr
), len
);
23168 case DW_FORM_udata
:
23169 type
= die_type (die
, cu
);
23170 result
= write_constant_as_bytes (obstack
, byte_order
,
23171 type
, DW_UNSND (attr
), len
);
23175 complaint (&symfile_complaints
,
23176 _("unsupported const value attribute form: '%s'"),
23177 dwarf_form_name (attr
->form
));
23184 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
23185 valid type for this die is found. */
23188 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23189 struct dwarf2_per_cu_data
*per_cu
)
23191 struct dwarf2_cu
*cu
;
23192 struct die_info
*die
;
23194 if (per_cu
->cu
== NULL
)
23200 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23204 return die_type (die
, cu
);
23207 /* Return the type of the DIE at DIE_OFFSET in the CU named by
23211 dwarf2_get_die_type (cu_offset die_offset
,
23212 struct dwarf2_per_cu_data
*per_cu
)
23214 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23215 return get_die_type_at_offset (die_offset_sect
, per_cu
);
23218 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23219 On entry *REF_CU is the CU of SRC_DIE.
23220 On exit *REF_CU is the CU of the result.
23221 Returns NULL if the referenced DIE isn't found. */
23223 static struct die_info
*
23224 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23225 struct dwarf2_cu
**ref_cu
)
23227 struct die_info temp_die
;
23228 struct dwarf2_cu
*sig_cu
;
23229 struct die_info
*die
;
23231 /* While it might be nice to assert sig_type->type == NULL here,
23232 we can get here for DW_AT_imported_declaration where we need
23233 the DIE not the type. */
23235 /* If necessary, add it to the queue and load its DIEs. */
23237 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
23238 read_signatured_type (sig_type
);
23240 sig_cu
= sig_type
->per_cu
.cu
;
23241 gdb_assert (sig_cu
!= NULL
);
23242 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23243 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23244 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23245 to_underlying (temp_die
.sect_off
));
23248 struct dwarf2_per_objfile
*dwarf2_per_objfile
23249 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
23251 /* For .gdb_index version 7 keep track of included TUs.
23252 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23253 if (dwarf2_per_objfile
->index_table
!= NULL
23254 && dwarf2_per_objfile
->index_table
->version
<= 7)
23256 VEC_safe_push (dwarf2_per_cu_ptr
,
23257 (*ref_cu
)->per_cu
->imported_symtabs
,
23268 /* Follow signatured type referenced by ATTR in SRC_DIE.
23269 On entry *REF_CU is the CU of SRC_DIE.
23270 On exit *REF_CU is the CU of the result.
23271 The result is the DIE of the type.
23272 If the referenced type cannot be found an error is thrown. */
23274 static struct die_info
*
23275 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23276 struct dwarf2_cu
**ref_cu
)
23278 ULONGEST signature
= DW_SIGNATURE (attr
);
23279 struct signatured_type
*sig_type
;
23280 struct die_info
*die
;
23282 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23284 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23285 /* sig_type will be NULL if the signatured type is missing from
23287 if (sig_type
== NULL
)
23289 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23290 " from DIE at %s [in module %s]"),
23291 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23292 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23295 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23298 dump_die_for_error (src_die
);
23299 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23300 " from DIE at %s [in module %s]"),
23301 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23302 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23308 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23309 reading in and processing the type unit if necessary. */
23311 static struct type
*
23312 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23313 struct dwarf2_cu
*cu
)
23315 struct dwarf2_per_objfile
*dwarf2_per_objfile
23316 = cu
->per_cu
->dwarf2_per_objfile
;
23317 struct signatured_type
*sig_type
;
23318 struct dwarf2_cu
*type_cu
;
23319 struct die_info
*type_die
;
23322 sig_type
= lookup_signatured_type (cu
, signature
);
23323 /* sig_type will be NULL if the signatured type is missing from
23325 if (sig_type
== NULL
)
23327 complaint (&symfile_complaints
,
23328 _("Dwarf Error: Cannot find signatured DIE %s referenced"
23329 " from DIE at %s [in module %s]"),
23330 hex_string (signature
), sect_offset_str (die
->sect_off
),
23331 objfile_name (dwarf2_per_objfile
->objfile
));
23332 return build_error_marker_type (cu
, die
);
23335 /* If we already know the type we're done. */
23336 if (sig_type
->type
!= NULL
)
23337 return sig_type
->type
;
23340 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23341 if (type_die
!= NULL
)
23343 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23344 is created. This is important, for example, because for c++ classes
23345 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23346 type
= read_type_die (type_die
, type_cu
);
23349 complaint (&symfile_complaints
,
23350 _("Dwarf Error: Cannot build signatured type %s"
23351 " referenced from DIE at %s [in module %s]"),
23352 hex_string (signature
), sect_offset_str (die
->sect_off
),
23353 objfile_name (dwarf2_per_objfile
->objfile
));
23354 type
= build_error_marker_type (cu
, die
);
23359 complaint (&symfile_complaints
,
23360 _("Dwarf Error: Problem reading signatured DIE %s referenced"
23361 " from DIE at %s [in module %s]"),
23362 hex_string (signature
), sect_offset_str (die
->sect_off
),
23363 objfile_name (dwarf2_per_objfile
->objfile
));
23364 type
= build_error_marker_type (cu
, die
);
23366 sig_type
->type
= type
;
23371 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23372 reading in and processing the type unit if necessary. */
23374 static struct type
*
23375 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23376 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23378 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23379 if (attr_form_is_ref (attr
))
23381 struct dwarf2_cu
*type_cu
= cu
;
23382 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23384 return read_type_die (type_die
, type_cu
);
23386 else if (attr
->form
== DW_FORM_ref_sig8
)
23388 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
23392 struct dwarf2_per_objfile
*dwarf2_per_objfile
23393 = cu
->per_cu
->dwarf2_per_objfile
;
23395 complaint (&symfile_complaints
,
23396 _("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23397 " at %s [in module %s]"),
23398 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
23399 objfile_name (dwarf2_per_objfile
->objfile
));
23400 return build_error_marker_type (cu
, die
);
23404 /* Load the DIEs associated with type unit PER_CU into memory. */
23407 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
23409 struct signatured_type
*sig_type
;
23411 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23412 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
23414 /* We have the per_cu, but we need the signatured_type.
23415 Fortunately this is an easy translation. */
23416 gdb_assert (per_cu
->is_debug_types
);
23417 sig_type
= (struct signatured_type
*) per_cu
;
23419 gdb_assert (per_cu
->cu
== NULL
);
23421 read_signatured_type (sig_type
);
23423 gdb_assert (per_cu
->cu
!= NULL
);
23426 /* die_reader_func for read_signatured_type.
23427 This is identical to load_full_comp_unit_reader,
23428 but is kept separate for now. */
23431 read_signatured_type_reader (const struct die_reader_specs
*reader
,
23432 const gdb_byte
*info_ptr
,
23433 struct die_info
*comp_unit_die
,
23437 struct dwarf2_cu
*cu
= reader
->cu
;
23439 gdb_assert (cu
->die_hash
== NULL
);
23441 htab_create_alloc_ex (cu
->header
.length
/ 12,
23445 &cu
->comp_unit_obstack
,
23446 hashtab_obstack_allocate
,
23447 dummy_obstack_deallocate
);
23450 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
23451 &info_ptr
, comp_unit_die
);
23452 cu
->dies
= comp_unit_die
;
23453 /* comp_unit_die is not stored in die_hash, no need. */
23455 /* We try not to read any attributes in this function, because not
23456 all CUs needed for references have been loaded yet, and symbol
23457 table processing isn't initialized. But we have to set the CU language,
23458 or we won't be able to build types correctly.
23459 Similarly, if we do not read the producer, we can not apply
23460 producer-specific interpretation. */
23461 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23464 /* Read in a signatured type and build its CU and DIEs.
23465 If the type is a stub for the real type in a DWO file,
23466 read in the real type from the DWO file as well. */
23469 read_signatured_type (struct signatured_type
*sig_type
)
23471 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
23473 gdb_assert (per_cu
->is_debug_types
);
23474 gdb_assert (per_cu
->cu
== NULL
);
23476 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1,
23477 read_signatured_type_reader
, NULL
);
23478 sig_type
->per_cu
.tu_read
= 1;
23481 /* Decode simple location descriptions.
23482 Given a pointer to a dwarf block that defines a location, compute
23483 the location and return the value.
23485 NOTE drow/2003-11-18: This function is called in two situations
23486 now: for the address of static or global variables (partial symbols
23487 only) and for offsets into structures which are expected to be
23488 (more or less) constant. The partial symbol case should go away,
23489 and only the constant case should remain. That will let this
23490 function complain more accurately. A few special modes are allowed
23491 without complaint for global variables (for instance, global
23492 register values and thread-local values).
23494 A location description containing no operations indicates that the
23495 object is optimized out. The return value is 0 for that case.
23496 FIXME drow/2003-11-16: No callers check for this case any more; soon all
23497 callers will only want a very basic result and this can become a
23500 Note that stack[0] is unused except as a default error return. */
23503 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
23505 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
23507 size_t size
= blk
->size
;
23508 const gdb_byte
*data
= blk
->data
;
23509 CORE_ADDR stack
[64];
23511 unsigned int bytes_read
, unsnd
;
23517 stack
[++stacki
] = 0;
23556 stack
[++stacki
] = op
- DW_OP_lit0
;
23591 stack
[++stacki
] = op
- DW_OP_reg0
;
23593 dwarf2_complex_location_expr_complaint ();
23597 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
23599 stack
[++stacki
] = unsnd
;
23601 dwarf2_complex_location_expr_complaint ();
23605 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
23610 case DW_OP_const1u
:
23611 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
23615 case DW_OP_const1s
:
23616 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
23620 case DW_OP_const2u
:
23621 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
23625 case DW_OP_const2s
:
23626 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
23630 case DW_OP_const4u
:
23631 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
23635 case DW_OP_const4s
:
23636 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
23640 case DW_OP_const8u
:
23641 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
23646 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
23652 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
23657 stack
[stacki
+ 1] = stack
[stacki
];
23662 stack
[stacki
- 1] += stack
[stacki
];
23666 case DW_OP_plus_uconst
:
23667 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
23673 stack
[stacki
- 1] -= stack
[stacki
];
23678 /* If we're not the last op, then we definitely can't encode
23679 this using GDB's address_class enum. This is valid for partial
23680 global symbols, although the variable's address will be bogus
23683 dwarf2_complex_location_expr_complaint ();
23686 case DW_OP_GNU_push_tls_address
:
23687 case DW_OP_form_tls_address
:
23688 /* The top of the stack has the offset from the beginning
23689 of the thread control block at which the variable is located. */
23690 /* Nothing should follow this operator, so the top of stack would
23692 /* This is valid for partial global symbols, but the variable's
23693 address will be bogus in the psymtab. Make it always at least
23694 non-zero to not look as a variable garbage collected by linker
23695 which have DW_OP_addr 0. */
23697 dwarf2_complex_location_expr_complaint ();
23701 case DW_OP_GNU_uninit
:
23704 case DW_OP_GNU_addr_index
:
23705 case DW_OP_GNU_const_index
:
23706 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23713 const char *name
= get_DW_OP_name (op
);
23716 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
23719 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
23723 return (stack
[stacki
]);
23726 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23727 outside of the allocated space. Also enforce minimum>0. */
23728 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23730 complaint (&symfile_complaints
,
23731 _("location description stack overflow"));
23737 complaint (&symfile_complaints
,
23738 _("location description stack underflow"));
23742 return (stack
[stacki
]);
23745 /* memory allocation interface */
23747 static struct dwarf_block
*
23748 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23750 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23753 static struct die_info
*
23754 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23756 struct die_info
*die
;
23757 size_t size
= sizeof (struct die_info
);
23760 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23762 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23763 memset (die
, 0, sizeof (struct die_info
));
23768 /* Macro support. */
23770 /* Return file name relative to the compilation directory of file number I in
23771 *LH's file name table. The result is allocated using xmalloc; the caller is
23772 responsible for freeing it. */
23775 file_file_name (int file
, struct line_header
*lh
)
23777 /* Is the file number a valid index into the line header's file name
23778 table? Remember that file numbers start with one, not zero. */
23779 if (1 <= file
&& file
<= lh
->file_names
.size ())
23781 const file_entry
&fe
= lh
->file_names
[file
- 1];
23783 if (!IS_ABSOLUTE_PATH (fe
.name
))
23785 const char *dir
= fe
.include_dir (lh
);
23787 return concat (dir
, SLASH_STRING
, fe
.name
, (char *) NULL
);
23789 return xstrdup (fe
.name
);
23793 /* The compiler produced a bogus file number. We can at least
23794 record the macro definitions made in the file, even if we
23795 won't be able to find the file by name. */
23796 char fake_name
[80];
23798 xsnprintf (fake_name
, sizeof (fake_name
),
23799 "<bad macro file number %d>", file
);
23801 complaint (&symfile_complaints
,
23802 _("bad file number in macro information (%d)"),
23805 return xstrdup (fake_name
);
23809 /* Return the full name of file number I in *LH's file name table.
23810 Use COMP_DIR as the name of the current directory of the
23811 compilation. The result is allocated using xmalloc; the caller is
23812 responsible for freeing it. */
23814 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
23816 /* Is the file number a valid index into the line header's file name
23817 table? Remember that file numbers start with one, not zero. */
23818 if (1 <= file
&& file
<= lh
->file_names
.size ())
23820 char *relative
= file_file_name (file
, lh
);
23822 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
23824 return reconcat (relative
, comp_dir
, SLASH_STRING
,
23825 relative
, (char *) NULL
);
23828 return file_file_name (file
, lh
);
23832 static struct macro_source_file
*
23833 macro_start_file (int file
, int line
,
23834 struct macro_source_file
*current_file
,
23835 struct line_header
*lh
)
23837 /* File name relative to the compilation directory of this source file. */
23838 char *file_name
= file_file_name (file
, lh
);
23840 if (! current_file
)
23842 /* Note: We don't create a macro table for this compilation unit
23843 at all until we actually get a filename. */
23844 struct macro_table
*macro_table
= get_macro_table ();
23846 /* If we have no current file, then this must be the start_file
23847 directive for the compilation unit's main source file. */
23848 current_file
= macro_set_main (macro_table
, file_name
);
23849 macro_define_special (macro_table
);
23852 current_file
= macro_include (current_file
, line
, file_name
);
23856 return current_file
;
23859 static const char *
23860 consume_improper_spaces (const char *p
, const char *body
)
23864 complaint (&symfile_complaints
,
23865 _("macro definition contains spaces "
23866 "in formal argument list:\n`%s'"),
23878 parse_macro_definition (struct macro_source_file
*file
, int line
,
23883 /* The body string takes one of two forms. For object-like macro
23884 definitions, it should be:
23886 <macro name> " " <definition>
23888 For function-like macro definitions, it should be:
23890 <macro name> "() " <definition>
23892 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
23894 Spaces may appear only where explicitly indicated, and in the
23897 The Dwarf 2 spec says that an object-like macro's name is always
23898 followed by a space, but versions of GCC around March 2002 omit
23899 the space when the macro's definition is the empty string.
23901 The Dwarf 2 spec says that there should be no spaces between the
23902 formal arguments in a function-like macro's formal argument list,
23903 but versions of GCC around March 2002 include spaces after the
23907 /* Find the extent of the macro name. The macro name is terminated
23908 by either a space or null character (for an object-like macro) or
23909 an opening paren (for a function-like macro). */
23910 for (p
= body
; *p
; p
++)
23911 if (*p
== ' ' || *p
== '(')
23914 if (*p
== ' ' || *p
== '\0')
23916 /* It's an object-like macro. */
23917 int name_len
= p
- body
;
23918 char *name
= savestring (body
, name_len
);
23919 const char *replacement
;
23922 replacement
= body
+ name_len
+ 1;
23925 dwarf2_macro_malformed_definition_complaint (body
);
23926 replacement
= body
+ name_len
;
23929 macro_define_object (file
, line
, name
, replacement
);
23933 else if (*p
== '(')
23935 /* It's a function-like macro. */
23936 char *name
= savestring (body
, p
- body
);
23939 char **argv
= XNEWVEC (char *, argv_size
);
23943 p
= consume_improper_spaces (p
, body
);
23945 /* Parse the formal argument list. */
23946 while (*p
&& *p
!= ')')
23948 /* Find the extent of the current argument name. */
23949 const char *arg_start
= p
;
23951 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
23954 if (! *p
|| p
== arg_start
)
23955 dwarf2_macro_malformed_definition_complaint (body
);
23958 /* Make sure argv has room for the new argument. */
23959 if (argc
>= argv_size
)
23962 argv
= XRESIZEVEC (char *, argv
, argv_size
);
23965 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
23968 p
= consume_improper_spaces (p
, body
);
23970 /* Consume the comma, if present. */
23975 p
= consume_improper_spaces (p
, body
);
23984 /* Perfectly formed definition, no complaints. */
23985 macro_define_function (file
, line
, name
,
23986 argc
, (const char **) argv
,
23988 else if (*p
== '\0')
23990 /* Complain, but do define it. */
23991 dwarf2_macro_malformed_definition_complaint (body
);
23992 macro_define_function (file
, line
, name
,
23993 argc
, (const char **) argv
,
23997 /* Just complain. */
23998 dwarf2_macro_malformed_definition_complaint (body
);
24001 /* Just complain. */
24002 dwarf2_macro_malformed_definition_complaint (body
);
24008 for (i
= 0; i
< argc
; i
++)
24014 dwarf2_macro_malformed_definition_complaint (body
);
24017 /* Skip some bytes from BYTES according to the form given in FORM.
24018 Returns the new pointer. */
24020 static const gdb_byte
*
24021 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
24022 enum dwarf_form form
,
24023 unsigned int offset_size
,
24024 struct dwarf2_section_info
*section
)
24026 unsigned int bytes_read
;
24030 case DW_FORM_data1
:
24035 case DW_FORM_data2
:
24039 case DW_FORM_data4
:
24043 case DW_FORM_data8
:
24047 case DW_FORM_data16
:
24051 case DW_FORM_string
:
24052 read_direct_string (abfd
, bytes
, &bytes_read
);
24053 bytes
+= bytes_read
;
24056 case DW_FORM_sec_offset
:
24058 case DW_FORM_GNU_strp_alt
:
24059 bytes
+= offset_size
;
24062 case DW_FORM_block
:
24063 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
24064 bytes
+= bytes_read
;
24067 case DW_FORM_block1
:
24068 bytes
+= 1 + read_1_byte (abfd
, bytes
);
24070 case DW_FORM_block2
:
24071 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
24073 case DW_FORM_block4
:
24074 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
24077 case DW_FORM_sdata
:
24078 case DW_FORM_udata
:
24079 case DW_FORM_GNU_addr_index
:
24080 case DW_FORM_GNU_str_index
:
24081 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
24084 dwarf2_section_buffer_overflow_complaint (section
);
24089 case DW_FORM_implicit_const
:
24094 complaint (&symfile_complaints
,
24095 _("invalid form 0x%x in `%s'"),
24096 form
, get_section_name (section
));
24104 /* A helper for dwarf_decode_macros that handles skipping an unknown
24105 opcode. Returns an updated pointer to the macro data buffer; or,
24106 on error, issues a complaint and returns NULL. */
24108 static const gdb_byte
*
24109 skip_unknown_opcode (unsigned int opcode
,
24110 const gdb_byte
**opcode_definitions
,
24111 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24113 unsigned int offset_size
,
24114 struct dwarf2_section_info
*section
)
24116 unsigned int bytes_read
, i
;
24118 const gdb_byte
*defn
;
24120 if (opcode_definitions
[opcode
] == NULL
)
24122 complaint (&symfile_complaints
,
24123 _("unrecognized DW_MACFINO opcode 0x%x"),
24128 defn
= opcode_definitions
[opcode
];
24129 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
24130 defn
+= bytes_read
;
24132 for (i
= 0; i
< arg
; ++i
)
24134 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
24135 (enum dwarf_form
) defn
[i
], offset_size
,
24137 if (mac_ptr
== NULL
)
24139 /* skip_form_bytes already issued the complaint. */
24147 /* A helper function which parses the header of a macro section.
24148 If the macro section is the extended (for now called "GNU") type,
24149 then this updates *OFFSET_SIZE. Returns a pointer to just after
24150 the header, or issues a complaint and returns NULL on error. */
24152 static const gdb_byte
*
24153 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
24155 const gdb_byte
*mac_ptr
,
24156 unsigned int *offset_size
,
24157 int section_is_gnu
)
24159 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
24161 if (section_is_gnu
)
24163 unsigned int version
, flags
;
24165 version
= read_2_bytes (abfd
, mac_ptr
);
24166 if (version
!= 4 && version
!= 5)
24168 complaint (&symfile_complaints
,
24169 _("unrecognized version `%d' in .debug_macro section"),
24175 flags
= read_1_byte (abfd
, mac_ptr
);
24177 *offset_size
= (flags
& 1) ? 8 : 4;
24179 if ((flags
& 2) != 0)
24180 /* We don't need the line table offset. */
24181 mac_ptr
+= *offset_size
;
24183 /* Vendor opcode descriptions. */
24184 if ((flags
& 4) != 0)
24186 unsigned int i
, count
;
24188 count
= read_1_byte (abfd
, mac_ptr
);
24190 for (i
= 0; i
< count
; ++i
)
24192 unsigned int opcode
, bytes_read
;
24195 opcode
= read_1_byte (abfd
, mac_ptr
);
24197 opcode_definitions
[opcode
] = mac_ptr
;
24198 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24199 mac_ptr
+= bytes_read
;
24208 /* A helper for dwarf_decode_macros that handles the GNU extensions,
24209 including DW_MACRO_import. */
24212 dwarf_decode_macro_bytes (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
24214 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24215 struct macro_source_file
*current_file
,
24216 struct line_header
*lh
,
24217 struct dwarf2_section_info
*section
,
24218 int section_is_gnu
, int section_is_dwz
,
24219 unsigned int offset_size
,
24220 htab_t include_hash
)
24222 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24223 enum dwarf_macro_record_type macinfo_type
;
24224 int at_commandline
;
24225 const gdb_byte
*opcode_definitions
[256];
24227 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24228 &offset_size
, section_is_gnu
);
24229 if (mac_ptr
== NULL
)
24231 /* We already issued a complaint. */
24235 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
24236 GDB is still reading the definitions from command line. First
24237 DW_MACINFO_start_file will need to be ignored as it was already executed
24238 to create CURRENT_FILE for the main source holding also the command line
24239 definitions. On first met DW_MACINFO_start_file this flag is reset to
24240 normally execute all the remaining DW_MACINFO_start_file macinfos. */
24242 at_commandline
= 1;
24246 /* Do we at least have room for a macinfo type byte? */
24247 if (mac_ptr
>= mac_end
)
24249 dwarf2_section_buffer_overflow_complaint (section
);
24253 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24256 /* Note that we rely on the fact that the corresponding GNU and
24257 DWARF constants are the same. */
24259 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24260 switch (macinfo_type
)
24262 /* A zero macinfo type indicates the end of the macro
24267 case DW_MACRO_define
:
24268 case DW_MACRO_undef
:
24269 case DW_MACRO_define_strp
:
24270 case DW_MACRO_undef_strp
:
24271 case DW_MACRO_define_sup
:
24272 case DW_MACRO_undef_sup
:
24274 unsigned int bytes_read
;
24279 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24280 mac_ptr
+= bytes_read
;
24282 if (macinfo_type
== DW_MACRO_define
24283 || macinfo_type
== DW_MACRO_undef
)
24285 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24286 mac_ptr
+= bytes_read
;
24290 LONGEST str_offset
;
24292 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24293 mac_ptr
+= offset_size
;
24295 if (macinfo_type
== DW_MACRO_define_sup
24296 || macinfo_type
== DW_MACRO_undef_sup
24299 struct dwz_file
*dwz
24300 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
24302 body
= read_indirect_string_from_dwz (objfile
,
24306 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
24310 is_define
= (macinfo_type
== DW_MACRO_define
24311 || macinfo_type
== DW_MACRO_define_strp
24312 || macinfo_type
== DW_MACRO_define_sup
);
24313 if (! current_file
)
24315 /* DWARF violation as no main source is present. */
24316 complaint (&symfile_complaints
,
24317 _("debug info with no main source gives macro %s "
24319 is_define
? _("definition") : _("undefinition"),
24323 if ((line
== 0 && !at_commandline
)
24324 || (line
!= 0 && at_commandline
))
24325 complaint (&symfile_complaints
,
24326 _("debug info gives %s macro %s with %s line %d: %s"),
24327 at_commandline
? _("command-line") : _("in-file"),
24328 is_define
? _("definition") : _("undefinition"),
24329 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
24332 parse_macro_definition (current_file
, line
, body
);
24335 gdb_assert (macinfo_type
== DW_MACRO_undef
24336 || macinfo_type
== DW_MACRO_undef_strp
24337 || macinfo_type
== DW_MACRO_undef_sup
);
24338 macro_undef (current_file
, line
, body
);
24343 case DW_MACRO_start_file
:
24345 unsigned int bytes_read
;
24348 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24349 mac_ptr
+= bytes_read
;
24350 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24351 mac_ptr
+= bytes_read
;
24353 if ((line
== 0 && !at_commandline
)
24354 || (line
!= 0 && at_commandline
))
24355 complaint (&symfile_complaints
,
24356 _("debug info gives source %d included "
24357 "from %s at %s line %d"),
24358 file
, at_commandline
? _("command-line") : _("file"),
24359 line
== 0 ? _("zero") : _("non-zero"), line
);
24361 if (at_commandline
)
24363 /* This DW_MACRO_start_file was executed in the
24365 at_commandline
= 0;
24368 current_file
= macro_start_file (file
, line
, current_file
, lh
);
24372 case DW_MACRO_end_file
:
24373 if (! current_file
)
24374 complaint (&symfile_complaints
,
24375 _("macro debug info has an unmatched "
24376 "`close_file' directive"));
24379 current_file
= current_file
->included_by
;
24380 if (! current_file
)
24382 enum dwarf_macro_record_type next_type
;
24384 /* GCC circa March 2002 doesn't produce the zero
24385 type byte marking the end of the compilation
24386 unit. Complain if it's not there, but exit no
24389 /* Do we at least have room for a macinfo type byte? */
24390 if (mac_ptr
>= mac_end
)
24392 dwarf2_section_buffer_overflow_complaint (section
);
24396 /* We don't increment mac_ptr here, so this is just
24399 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
24401 if (next_type
!= 0)
24402 complaint (&symfile_complaints
,
24403 _("no terminating 0-type entry for "
24404 "macros in `.debug_macinfo' section"));
24411 case DW_MACRO_import
:
24412 case DW_MACRO_import_sup
:
24416 bfd
*include_bfd
= abfd
;
24417 struct dwarf2_section_info
*include_section
= section
;
24418 const gdb_byte
*include_mac_end
= mac_end
;
24419 int is_dwz
= section_is_dwz
;
24420 const gdb_byte
*new_mac_ptr
;
24422 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24423 mac_ptr
+= offset_size
;
24425 if (macinfo_type
== DW_MACRO_import_sup
)
24427 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
24429 dwarf2_read_section (objfile
, &dwz
->macro
);
24431 include_section
= &dwz
->macro
;
24432 include_bfd
= get_section_bfd_owner (include_section
);
24433 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
24437 new_mac_ptr
= include_section
->buffer
+ offset
;
24438 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
24442 /* This has actually happened; see
24443 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
24444 complaint (&symfile_complaints
,
24445 _("recursive DW_MACRO_import in "
24446 ".debug_macro section"));
24450 *slot
= (void *) new_mac_ptr
;
24452 dwarf_decode_macro_bytes (dwarf2_per_objfile
,
24453 include_bfd
, new_mac_ptr
,
24454 include_mac_end
, current_file
, lh
,
24455 section
, section_is_gnu
, is_dwz
,
24456 offset_size
, include_hash
);
24458 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
24463 case DW_MACINFO_vendor_ext
:
24464 if (!section_is_gnu
)
24466 unsigned int bytes_read
;
24468 /* This reads the constant, but since we don't recognize
24469 any vendor extensions, we ignore it. */
24470 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24471 mac_ptr
+= bytes_read
;
24472 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24473 mac_ptr
+= bytes_read
;
24475 /* We don't recognize any vendor extensions. */
24481 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
24482 mac_ptr
, mac_end
, abfd
, offset_size
,
24484 if (mac_ptr
== NULL
)
24489 } while (macinfo_type
!= 0);
24493 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24494 int section_is_gnu
)
24496 struct dwarf2_per_objfile
*dwarf2_per_objfile
24497 = cu
->per_cu
->dwarf2_per_objfile
;
24498 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24499 struct line_header
*lh
= cu
->line_header
;
24501 const gdb_byte
*mac_ptr
, *mac_end
;
24502 struct macro_source_file
*current_file
= 0;
24503 enum dwarf_macro_record_type macinfo_type
;
24504 unsigned int offset_size
= cu
->header
.offset_size
;
24505 const gdb_byte
*opcode_definitions
[256];
24507 struct dwarf2_section_info
*section
;
24508 const char *section_name
;
24510 if (cu
->dwo_unit
!= NULL
)
24512 if (section_is_gnu
)
24514 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24515 section_name
= ".debug_macro.dwo";
24519 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24520 section_name
= ".debug_macinfo.dwo";
24525 if (section_is_gnu
)
24527 section
= &dwarf2_per_objfile
->macro
;
24528 section_name
= ".debug_macro";
24532 section
= &dwarf2_per_objfile
->macinfo
;
24533 section_name
= ".debug_macinfo";
24537 dwarf2_read_section (objfile
, section
);
24538 if (section
->buffer
== NULL
)
24540 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
24543 abfd
= get_section_bfd_owner (section
);
24545 /* First pass: Find the name of the base filename.
24546 This filename is needed in order to process all macros whose definition
24547 (or undefinition) comes from the command line. These macros are defined
24548 before the first DW_MACINFO_start_file entry, and yet still need to be
24549 associated to the base file.
24551 To determine the base file name, we scan the macro definitions until we
24552 reach the first DW_MACINFO_start_file entry. We then initialize
24553 CURRENT_FILE accordingly so that any macro definition found before the
24554 first DW_MACINFO_start_file can still be associated to the base file. */
24556 mac_ptr
= section
->buffer
+ offset
;
24557 mac_end
= section
->buffer
+ section
->size
;
24559 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24560 &offset_size
, section_is_gnu
);
24561 if (mac_ptr
== NULL
)
24563 /* We already issued a complaint. */
24569 /* Do we at least have room for a macinfo type byte? */
24570 if (mac_ptr
>= mac_end
)
24572 /* Complaint is printed during the second pass as GDB will probably
24573 stop the first pass earlier upon finding
24574 DW_MACINFO_start_file. */
24578 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24581 /* Note that we rely on the fact that the corresponding GNU and
24582 DWARF constants are the same. */
24584 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24585 switch (macinfo_type
)
24587 /* A zero macinfo type indicates the end of the macro
24592 case DW_MACRO_define
:
24593 case DW_MACRO_undef
:
24594 /* Only skip the data by MAC_PTR. */
24596 unsigned int bytes_read
;
24598 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24599 mac_ptr
+= bytes_read
;
24600 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24601 mac_ptr
+= bytes_read
;
24605 case DW_MACRO_start_file
:
24607 unsigned int bytes_read
;
24610 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24611 mac_ptr
+= bytes_read
;
24612 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24613 mac_ptr
+= bytes_read
;
24615 current_file
= macro_start_file (file
, line
, current_file
, lh
);
24619 case DW_MACRO_end_file
:
24620 /* No data to skip by MAC_PTR. */
24623 case DW_MACRO_define_strp
:
24624 case DW_MACRO_undef_strp
:
24625 case DW_MACRO_define_sup
:
24626 case DW_MACRO_undef_sup
:
24628 unsigned int bytes_read
;
24630 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24631 mac_ptr
+= bytes_read
;
24632 mac_ptr
+= offset_size
;
24636 case DW_MACRO_import
:
24637 case DW_MACRO_import_sup
:
24638 /* Note that, according to the spec, a transparent include
24639 chain cannot call DW_MACRO_start_file. So, we can just
24640 skip this opcode. */
24641 mac_ptr
+= offset_size
;
24644 case DW_MACINFO_vendor_ext
:
24645 /* Only skip the data by MAC_PTR. */
24646 if (!section_is_gnu
)
24648 unsigned int bytes_read
;
24650 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24651 mac_ptr
+= bytes_read
;
24652 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24653 mac_ptr
+= bytes_read
;
24658 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
24659 mac_ptr
, mac_end
, abfd
, offset_size
,
24661 if (mac_ptr
== NULL
)
24666 } while (macinfo_type
!= 0 && current_file
== NULL
);
24668 /* Second pass: Process all entries.
24670 Use the AT_COMMAND_LINE flag to determine whether we are still processing
24671 command-line macro definitions/undefinitions. This flag is unset when we
24672 reach the first DW_MACINFO_start_file entry. */
24674 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
24676 NULL
, xcalloc
, xfree
));
24677 mac_ptr
= section
->buffer
+ offset
;
24678 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
24679 *slot
= (void *) mac_ptr
;
24680 dwarf_decode_macro_bytes (dwarf2_per_objfile
,
24681 abfd
, mac_ptr
, mac_end
,
24682 current_file
, lh
, section
,
24683 section_is_gnu
, 0, offset_size
,
24684 include_hash
.get ());
24687 /* Check if the attribute's form is a DW_FORM_block*
24688 if so return true else false. */
24691 attr_form_is_block (const struct attribute
*attr
)
24693 return (attr
== NULL
? 0 :
24694 attr
->form
== DW_FORM_block1
24695 || attr
->form
== DW_FORM_block2
24696 || attr
->form
== DW_FORM_block4
24697 || attr
->form
== DW_FORM_block
24698 || attr
->form
== DW_FORM_exprloc
);
24701 /* Return non-zero if ATTR's value is a section offset --- classes
24702 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
24703 You may use DW_UNSND (attr) to retrieve such offsets.
24705 Section 7.5.4, "Attribute Encodings", explains that no attribute
24706 may have a value that belongs to more than one of these classes; it
24707 would be ambiguous if we did, because we use the same forms for all
24711 attr_form_is_section_offset (const struct attribute
*attr
)
24713 return (attr
->form
== DW_FORM_data4
24714 || attr
->form
== DW_FORM_data8
24715 || attr
->form
== DW_FORM_sec_offset
);
24718 /* Return non-zero if ATTR's value falls in the 'constant' class, or
24719 zero otherwise. When this function returns true, you can apply
24720 dwarf2_get_attr_constant_value to it.
24722 However, note that for some attributes you must check
24723 attr_form_is_section_offset before using this test. DW_FORM_data4
24724 and DW_FORM_data8 are members of both the constant class, and of
24725 the classes that contain offsets into other debug sections
24726 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
24727 that, if an attribute's can be either a constant or one of the
24728 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
24729 taken as section offsets, not constants.
24731 DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
24732 cannot handle that. */
24735 attr_form_is_constant (const struct attribute
*attr
)
24737 switch (attr
->form
)
24739 case DW_FORM_sdata
:
24740 case DW_FORM_udata
:
24741 case DW_FORM_data1
:
24742 case DW_FORM_data2
:
24743 case DW_FORM_data4
:
24744 case DW_FORM_data8
:
24745 case DW_FORM_implicit_const
:
24753 /* DW_ADDR is always stored already as sect_offset; despite for the forms
24754 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
24757 attr_form_is_ref (const struct attribute
*attr
)
24759 switch (attr
->form
)
24761 case DW_FORM_ref_addr
:
24766 case DW_FORM_ref_udata
:
24767 case DW_FORM_GNU_ref_alt
:
24774 /* Return the .debug_loc section to use for CU.
24775 For DWO files use .debug_loc.dwo. */
24777 static struct dwarf2_section_info
*
24778 cu_debug_loc_section (struct dwarf2_cu
*cu
)
24780 struct dwarf2_per_objfile
*dwarf2_per_objfile
24781 = cu
->per_cu
->dwarf2_per_objfile
;
24785 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24787 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
24789 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
24790 : &dwarf2_per_objfile
->loc
);
24793 /* A helper function that fills in a dwarf2_loclist_baton. */
24796 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
24797 struct dwarf2_loclist_baton
*baton
,
24798 const struct attribute
*attr
)
24800 struct dwarf2_per_objfile
*dwarf2_per_objfile
24801 = cu
->per_cu
->dwarf2_per_objfile
;
24802 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24804 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
24806 baton
->per_cu
= cu
->per_cu
;
24807 gdb_assert (baton
->per_cu
);
24808 /* We don't know how long the location list is, but make sure we
24809 don't run off the edge of the section. */
24810 baton
->size
= section
->size
- DW_UNSND (attr
);
24811 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
24812 baton
->base_address
= cu
->base_address
;
24813 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
24817 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
24818 struct dwarf2_cu
*cu
, int is_block
)
24820 struct dwarf2_per_objfile
*dwarf2_per_objfile
24821 = cu
->per_cu
->dwarf2_per_objfile
;
24822 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24823 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24825 if (attr_form_is_section_offset (attr
)
24826 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24827 the section. If so, fall through to the complaint in the
24829 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
24831 struct dwarf2_loclist_baton
*baton
;
24833 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24835 fill_in_loclist_baton (cu
, baton
, attr
);
24837 if (cu
->base_known
== 0)
24838 complaint (&symfile_complaints
,
24839 _("Location list used without "
24840 "specifying the CU base address."));
24842 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24843 ? dwarf2_loclist_block_index
24844 : dwarf2_loclist_index
);
24845 SYMBOL_LOCATION_BATON (sym
) = baton
;
24849 struct dwarf2_locexpr_baton
*baton
;
24851 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24852 baton
->per_cu
= cu
->per_cu
;
24853 gdb_assert (baton
->per_cu
);
24855 if (attr_form_is_block (attr
))
24857 /* Note that we're just copying the block's data pointer
24858 here, not the actual data. We're still pointing into the
24859 info_buffer for SYM's objfile; right now we never release
24860 that buffer, but when we do clean up properly this may
24862 baton
->size
= DW_BLOCK (attr
)->size
;
24863 baton
->data
= DW_BLOCK (attr
)->data
;
24867 dwarf2_invalid_attrib_class_complaint ("location description",
24868 SYMBOL_NATURAL_NAME (sym
));
24872 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24873 ? dwarf2_locexpr_block_index
24874 : dwarf2_locexpr_index
);
24875 SYMBOL_LOCATION_BATON (sym
) = baton
;
24879 /* Return the OBJFILE associated with the compilation unit CU. If CU
24880 came from a separate debuginfo file, then the master objfile is
24884 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
24886 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
24888 /* Return the master objfile, so that we can report and look up the
24889 correct file containing this variable. */
24890 if (objfile
->separate_debug_objfile_backlink
)
24891 objfile
= objfile
->separate_debug_objfile_backlink
;
24896 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
24897 (CU_HEADERP is unused in such case) or prepare a temporary copy at
24898 CU_HEADERP first. */
24900 static const struct comp_unit_head
*
24901 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
24902 struct dwarf2_per_cu_data
*per_cu
)
24904 const gdb_byte
*info_ptr
;
24907 return &per_cu
->cu
->header
;
24909 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
24911 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
24912 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
24913 rcuh_kind::COMPILE
);
24918 /* Return the address size given in the compilation unit header for CU. */
24921 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
24923 struct comp_unit_head cu_header_local
;
24924 const struct comp_unit_head
*cu_headerp
;
24926 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
24928 return cu_headerp
->addr_size
;
24931 /* Return the offset size given in the compilation unit header for CU. */
24934 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
24936 struct comp_unit_head cu_header_local
;
24937 const struct comp_unit_head
*cu_headerp
;
24939 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
24941 return cu_headerp
->offset_size
;
24944 /* See its dwarf2loc.h declaration. */
24947 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
24949 struct comp_unit_head cu_header_local
;
24950 const struct comp_unit_head
*cu_headerp
;
24952 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
24954 if (cu_headerp
->version
== 2)
24955 return cu_headerp
->addr_size
;
24957 return cu_headerp
->offset_size
;
24960 /* Return the text offset of the CU. The returned offset comes from
24961 this CU's objfile. If this objfile came from a separate debuginfo
24962 file, then the offset may be different from the corresponding
24963 offset in the parent objfile. */
24966 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
24968 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
24970 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
24973 /* Return DWARF version number of PER_CU. */
24976 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
24978 return per_cu
->dwarf_version
;
24981 /* Locate the .debug_info compilation unit from CU's objfile which contains
24982 the DIE at OFFSET. Raises an error on failure. */
24984 static struct dwarf2_per_cu_data
*
24985 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24986 unsigned int offset_in_dwz
,
24987 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
24989 struct dwarf2_per_cu_data
*this_cu
;
24991 const sect_offset
*cu_off
;
24994 high
= dwarf2_per_objfile
->n_comp_units
- 1;
24997 struct dwarf2_per_cu_data
*mid_cu
;
24998 int mid
= low
+ (high
- low
) / 2;
25000 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
25001 cu_off
= &mid_cu
->sect_off
;
25002 if (mid_cu
->is_dwz
> offset_in_dwz
25003 || (mid_cu
->is_dwz
== offset_in_dwz
&& *cu_off
>= sect_off
))
25008 gdb_assert (low
== high
);
25009 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
25010 cu_off
= &this_cu
->sect_off
;
25011 if (this_cu
->is_dwz
!= offset_in_dwz
|| *cu_off
> sect_off
)
25013 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
25014 error (_("Dwarf Error: could not find partial DIE containing "
25015 "offset %s [in module %s]"),
25016 sect_offset_str (sect_off
),
25017 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
25019 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
25021 return dwarf2_per_objfile
->all_comp_units
[low
-1];
25025 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
25026 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
25027 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
25028 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
25029 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
25034 /* Initialize dwarf2_cu CU, owned by PER_CU. */
25036 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
25037 : per_cu (per_cu_
),
25040 checked_producer (0),
25041 producer_is_gxx_lt_4_6 (0),
25042 producer_is_gcc_lt_4_3 (0),
25043 producer_is_icc_lt_14 (0),
25044 processing_has_namespace_info (0)
25049 /* Destroy a dwarf2_cu. */
25051 dwarf2_cu::~dwarf2_cu ()
25056 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
25059 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
25060 enum language pretend_language
)
25062 struct attribute
*attr
;
25064 /* Set the language we're debugging. */
25065 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
25067 set_cu_language (DW_UNSND (attr
), cu
);
25070 cu
->language
= pretend_language
;
25071 cu
->language_defn
= language_def (cu
->language
);
25074 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
25077 /* Increase the age counter on each cached compilation unit, and free
25078 any that are too old. */
25081 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25083 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25085 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
25086 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25087 while (per_cu
!= NULL
)
25089 per_cu
->cu
->last_used
++;
25090 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
25091 dwarf2_mark (per_cu
->cu
);
25092 per_cu
= per_cu
->cu
->read_in_chain
;
25095 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25096 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25097 while (per_cu
!= NULL
)
25099 struct dwarf2_per_cu_data
*next_cu
;
25101 next_cu
= per_cu
->cu
->read_in_chain
;
25103 if (!per_cu
->cu
->mark
)
25106 *last_chain
= next_cu
;
25109 last_chain
= &per_cu
->cu
->read_in_chain
;
25115 /* Remove a single compilation unit from the cache. */
25118 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
25120 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25121 struct dwarf2_per_objfile
*dwarf2_per_objfile
25122 = target_per_cu
->dwarf2_per_objfile
;
25124 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25125 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25126 while (per_cu
!= NULL
)
25128 struct dwarf2_per_cu_data
*next_cu
;
25130 next_cu
= per_cu
->cu
->read_in_chain
;
25132 if (per_cu
== target_per_cu
)
25136 *last_chain
= next_cu
;
25140 last_chain
= &per_cu
->cu
->read_in_chain
;
25146 /* Release all extra memory associated with OBJFILE. */
25149 dwarf2_free_objfile (struct objfile
*objfile
)
25151 struct dwarf2_per_objfile
*dwarf2_per_objfile
25152 = get_dwarf2_per_objfile (objfile
);
25154 delete dwarf2_per_objfile
;
25157 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
25158 We store these in a hash table separate from the DIEs, and preserve them
25159 when the DIEs are flushed out of cache.
25161 The CU "per_cu" pointer is needed because offset alone is not enough to
25162 uniquely identify the type. A file may have multiple .debug_types sections,
25163 or the type may come from a DWO file. Furthermore, while it's more logical
25164 to use per_cu->section+offset, with Fission the section with the data is in
25165 the DWO file but we don't know that section at the point we need it.
25166 We have to use something in dwarf2_per_cu_data (or the pointer to it)
25167 because we can enter the lookup routine, get_die_type_at_offset, from
25168 outside this file, and thus won't necessarily have PER_CU->cu.
25169 Fortunately, PER_CU is stable for the life of the objfile. */
25171 struct dwarf2_per_cu_offset_and_type
25173 const struct dwarf2_per_cu_data
*per_cu
;
25174 sect_offset sect_off
;
25178 /* Hash function for a dwarf2_per_cu_offset_and_type. */
25181 per_cu_offset_and_type_hash (const void *item
)
25183 const struct dwarf2_per_cu_offset_and_type
*ofs
25184 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
25186 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
25189 /* Equality function for a dwarf2_per_cu_offset_and_type. */
25192 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
25194 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
25195 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
25196 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25197 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25199 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25200 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25203 /* Set the type associated with DIE to TYPE. Save it in CU's hash
25204 table if necessary. For convenience, return TYPE.
25206 The DIEs reading must have careful ordering to:
25207 * Not cause infite loops trying to read in DIEs as a prerequisite for
25208 reading current DIE.
25209 * Not trying to dereference contents of still incompletely read in types
25210 while reading in other DIEs.
25211 * Enable referencing still incompletely read in types just by a pointer to
25212 the type without accessing its fields.
25214 Therefore caller should follow these rules:
25215 * Try to fetch any prerequisite types we may need to build this DIE type
25216 before building the type and calling set_die_type.
25217 * After building type call set_die_type for current DIE as soon as
25218 possible before fetching more types to complete the current type.
25219 * Make the type as complete as possible before fetching more types. */
25221 static struct type
*
25222 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
25224 struct dwarf2_per_objfile
*dwarf2_per_objfile
25225 = cu
->per_cu
->dwarf2_per_objfile
;
25226 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
25227 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25228 struct attribute
*attr
;
25229 struct dynamic_prop prop
;
25231 /* For Ada types, make sure that the gnat-specific data is always
25232 initialized (if not already set). There are a few types where
25233 we should not be doing so, because the type-specific area is
25234 already used to hold some other piece of info (eg: TYPE_CODE_FLT
25235 where the type-specific area is used to store the floatformat).
25236 But this is not a problem, because the gnat-specific information
25237 is actually not needed for these types. */
25238 if (need_gnat_info (cu
)
25239 && TYPE_CODE (type
) != TYPE_CODE_FUNC
25240 && TYPE_CODE (type
) != TYPE_CODE_FLT
25241 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
25242 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
25243 && TYPE_CODE (type
) != TYPE_CODE_METHOD
25244 && !HAVE_GNAT_AUX_INFO (type
))
25245 INIT_GNAT_SPECIFIC (type
);
25247 /* Read DW_AT_allocated and set in type. */
25248 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
25249 if (attr_form_is_block (attr
))
25251 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25252 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
25254 else if (attr
!= NULL
)
25256 complaint (&symfile_complaints
,
25257 _("DW_AT_allocated has the wrong form (%s) at DIE %s"),
25258 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25259 sect_offset_str (die
->sect_off
));
25262 /* Read DW_AT_associated and set in type. */
25263 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
25264 if (attr_form_is_block (attr
))
25266 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25267 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
25269 else if (attr
!= NULL
)
25271 complaint (&symfile_complaints
,
25272 _("DW_AT_associated has the wrong form (%s) at DIE %s"),
25273 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25274 sect_offset_str (die
->sect_off
));
25277 /* Read DW_AT_data_location and set in type. */
25278 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
25279 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25280 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
25282 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25284 dwarf2_per_objfile
->die_type_hash
=
25285 htab_create_alloc_ex (127,
25286 per_cu_offset_and_type_hash
,
25287 per_cu_offset_and_type_eq
,
25289 &objfile
->objfile_obstack
,
25290 hashtab_obstack_allocate
,
25291 dummy_obstack_deallocate
);
25294 ofs
.per_cu
= cu
->per_cu
;
25295 ofs
.sect_off
= die
->sect_off
;
25297 slot
= (struct dwarf2_per_cu_offset_and_type
**)
25298 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
25300 complaint (&symfile_complaints
,
25301 _("A problem internal to GDB: DIE %s has type already set"),
25302 sect_offset_str (die
->sect_off
));
25303 *slot
= XOBNEW (&objfile
->objfile_obstack
,
25304 struct dwarf2_per_cu_offset_and_type
);
25309 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
25310 or return NULL if the die does not have a saved type. */
25312 static struct type
*
25313 get_die_type_at_offset (sect_offset sect_off
,
25314 struct dwarf2_per_cu_data
*per_cu
)
25316 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
25317 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
25319 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25322 ofs
.per_cu
= per_cu
;
25323 ofs
.sect_off
= sect_off
;
25324 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
25325 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
25332 /* Look up the type for DIE in CU in die_type_hash,
25333 or return NULL if DIE does not have a saved type. */
25335 static struct type
*
25336 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
25338 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
25341 /* Add a dependence relationship from CU to REF_PER_CU. */
25344 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
25345 struct dwarf2_per_cu_data
*ref_per_cu
)
25349 if (cu
->dependencies
== NULL
)
25351 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
25352 NULL
, &cu
->comp_unit_obstack
,
25353 hashtab_obstack_allocate
,
25354 dummy_obstack_deallocate
);
25356 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
25358 *slot
= ref_per_cu
;
25361 /* Subroutine of dwarf2_mark to pass to htab_traverse.
25362 Set the mark field in every compilation unit in the
25363 cache that we must keep because we are keeping CU. */
25366 dwarf2_mark_helper (void **slot
, void *data
)
25368 struct dwarf2_per_cu_data
*per_cu
;
25370 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
25372 /* cu->dependencies references may not yet have been ever read if QUIT aborts
25373 reading of the chain. As such dependencies remain valid it is not much
25374 useful to track and undo them during QUIT cleanups. */
25375 if (per_cu
->cu
== NULL
)
25378 if (per_cu
->cu
->mark
)
25380 per_cu
->cu
->mark
= 1;
25382 if (per_cu
->cu
->dependencies
!= NULL
)
25383 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25388 /* Set the mark field in CU and in every other compilation unit in the
25389 cache that we must keep because we are keeping CU. */
25392 dwarf2_mark (struct dwarf2_cu
*cu
)
25397 if (cu
->dependencies
!= NULL
)
25398 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25402 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
25406 per_cu
->cu
->mark
= 0;
25407 per_cu
= per_cu
->cu
->read_in_chain
;
25411 /* Trivial hash function for partial_die_info: the hash value of a DIE
25412 is its offset in .debug_info for this objfile. */
25415 partial_die_hash (const void *item
)
25417 const struct partial_die_info
*part_die
25418 = (const struct partial_die_info
*) item
;
25420 return to_underlying (part_die
->sect_off
);
25423 /* Trivial comparison function for partial_die_info structures: two DIEs
25424 are equal if they have the same offset. */
25427 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
25429 const struct partial_die_info
*part_die_lhs
25430 = (const struct partial_die_info
*) item_lhs
;
25431 const struct partial_die_info
*part_die_rhs
25432 = (const struct partial_die_info
*) item_rhs
;
25434 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
25437 static struct cmd_list_element
*set_dwarf_cmdlist
;
25438 static struct cmd_list_element
*show_dwarf_cmdlist
;
25441 set_dwarf_cmd (const char *args
, int from_tty
)
25443 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
25448 show_dwarf_cmd (const char *args
, int from_tty
)
25450 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
25453 int dwarf_always_disassemble
;
25456 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
25457 struct cmd_list_element
*c
, const char *value
)
25459 fprintf_filtered (file
,
25460 _("Whether to always disassemble "
25461 "DWARF expressions is %s.\n"),
25466 show_check_physname (struct ui_file
*file
, int from_tty
,
25467 struct cmd_list_element
*c
, const char *value
)
25469 fprintf_filtered (file
,
25470 _("Whether to check \"physname\" is %s.\n"),
25475 _initialize_dwarf2_read (void)
25478 dwarf2_objfile_data_key
= register_objfile_data ();
25480 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
25481 Set DWARF specific variables.\n\
25482 Configure DWARF variables such as the cache size"),
25483 &set_dwarf_cmdlist
, "maintenance set dwarf ",
25484 0/*allow-unknown*/, &maintenance_set_cmdlist
);
25486 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
25487 Show DWARF specific variables\n\
25488 Show DWARF variables such as the cache size"),
25489 &show_dwarf_cmdlist
, "maintenance show dwarf ",
25490 0/*allow-unknown*/, &maintenance_show_cmdlist
);
25492 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
25493 &dwarf_max_cache_age
, _("\
25494 Set the upper bound on the age of cached DWARF compilation units."), _("\
25495 Show the upper bound on the age of cached DWARF compilation units."), _("\
25496 A higher limit means that cached compilation units will be stored\n\
25497 in memory longer, and more total memory will be used. Zero disables\n\
25498 caching, which can slow down startup."),
25500 show_dwarf_max_cache_age
,
25501 &set_dwarf_cmdlist
,
25502 &show_dwarf_cmdlist
);
25504 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
25505 &dwarf_always_disassemble
, _("\
25506 Set whether `info address' always disassembles DWARF expressions."), _("\
25507 Show whether `info address' always disassembles DWARF expressions."), _("\
25508 When enabled, DWARF expressions are always printed in an assembly-like\n\
25509 syntax. When disabled, expressions will be printed in a more\n\
25510 conversational style, when possible."),
25512 show_dwarf_always_disassemble
,
25513 &set_dwarf_cmdlist
,
25514 &show_dwarf_cmdlist
);
25516 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
25517 Set debugging of the DWARF reader."), _("\
25518 Show debugging of the DWARF reader."), _("\
25519 When enabled (non-zero), debugging messages are printed during DWARF\n\
25520 reading and symtab expansion. A value of 1 (one) provides basic\n\
25521 information. A value greater than 1 provides more verbose information."),
25524 &setdebuglist
, &showdebuglist
);
25526 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
25527 Set debugging of the DWARF DIE reader."), _("\
25528 Show debugging of the DWARF DIE reader."), _("\
25529 When enabled (non-zero), DIEs are dumped after they are read in.\n\
25530 The value is the maximum depth to print."),
25533 &setdebuglist
, &showdebuglist
);
25535 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
25536 Set debugging of the dwarf line reader."), _("\
25537 Show debugging of the dwarf line reader."), _("\
25538 When enabled (non-zero), line number entries are dumped as they are read in.\n\
25539 A value of 1 (one) provides basic information.\n\
25540 A value greater than 1 provides more verbose information."),
25543 &setdebuglist
, &showdebuglist
);
25545 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
25546 Set cross-checking of \"physname\" code against demangler."), _("\
25547 Show cross-checking of \"physname\" code against demangler."), _("\
25548 When enabled, GDB's internal \"physname\" code is checked against\n\
25550 NULL
, show_check_physname
,
25551 &setdebuglist
, &showdebuglist
);
25553 add_setshow_boolean_cmd ("use-deprecated-index-sections",
25554 no_class
, &use_deprecated_index_sections
, _("\
25555 Set whether to use deprecated gdb_index sections."), _("\
25556 Show whether to use deprecated gdb_index sections."), _("\
25557 When enabled, deprecated .gdb_index sections are used anyway.\n\
25558 Normally they are ignored either because of a missing feature or\n\
25559 performance issue.\n\
25560 Warning: This option must be enabled before gdb reads the file."),
25563 &setlist
, &showlist
);
25565 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25566 &dwarf2_locexpr_funcs
);
25567 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25568 &dwarf2_loclist_funcs
);
25570 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25571 &dwarf2_block_frame_base_locexpr_funcs
);
25572 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25573 &dwarf2_block_frame_base_loclist_funcs
);
25576 selftests::register_test ("dw2_expand_symtabs_matching",
25577 selftests::dw2_expand_symtabs_matching::run_test
);