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 (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
2141 VEC_free (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
);
2143 for (signatured_type
*sig_type
: all_type_units
)
2144 VEC_free (dwarf2_per_cu_ptr
, sig_type
->per_cu
.imported_symtabs
);
2146 VEC_free (dwarf2_section_info_def
, types
);
2148 if (dwo_files
!= NULL
)
2149 free_dwo_files (dwo_files
, objfile
);
2150 if (dwp_file
!= NULL
)
2151 gdb_bfd_unref (dwp_file
->dbfd
);
2153 if (dwz_file
!= NULL
&& dwz_file
->dwz_bfd
)
2154 gdb_bfd_unref (dwz_file
->dwz_bfd
);
2156 if (index_table
!= NULL
)
2157 index_table
->~mapped_index ();
2159 /* Everything else should be on the objfile obstack. */
2162 /* See declaration. */
2165 dwarf2_per_objfile::free_cached_comp_units ()
2167 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
2168 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
2169 while (per_cu
!= NULL
)
2171 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
2174 *last_chain
= next_cu
;
2179 /* A helper class that calls free_cached_comp_units on
2182 class free_cached_comp_units
2186 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
2187 : m_per_objfile (per_objfile
)
2191 ~free_cached_comp_units ()
2193 m_per_objfile
->free_cached_comp_units ();
2196 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
2200 dwarf2_per_objfile
*m_per_objfile
;
2203 /* Try to locate the sections we need for DWARF 2 debugging
2204 information and return true if we have enough to do something.
2205 NAMES points to the dwarf2 section names, or is NULL if the standard
2206 ELF names are used. */
2209 dwarf2_has_info (struct objfile
*objfile
,
2210 const struct dwarf2_debug_sections
*names
)
2212 if (objfile
->flags
& OBJF_READNEVER
)
2215 struct dwarf2_per_objfile
*dwarf2_per_objfile
2216 = get_dwarf2_per_objfile (objfile
);
2218 if (dwarf2_per_objfile
== NULL
)
2220 /* Initialize per-objfile state. */
2222 = new (&objfile
->objfile_obstack
) struct dwarf2_per_objfile (objfile
,
2224 set_dwarf2_per_objfile (objfile
, dwarf2_per_objfile
);
2226 return (!dwarf2_per_objfile
->info
.is_virtual
2227 && dwarf2_per_objfile
->info
.s
.section
!= NULL
2228 && !dwarf2_per_objfile
->abbrev
.is_virtual
2229 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
2232 /* Return the containing section of virtual section SECTION. */
2234 static struct dwarf2_section_info
*
2235 get_containing_section (const struct dwarf2_section_info
*section
)
2237 gdb_assert (section
->is_virtual
);
2238 return section
->s
.containing_section
;
2241 /* Return the bfd owner of SECTION. */
2244 get_section_bfd_owner (const struct dwarf2_section_info
*section
)
2246 if (section
->is_virtual
)
2248 section
= get_containing_section (section
);
2249 gdb_assert (!section
->is_virtual
);
2251 return section
->s
.section
->owner
;
2254 /* Return the bfd section of SECTION.
2255 Returns NULL if the section is not present. */
2258 get_section_bfd_section (const struct dwarf2_section_info
*section
)
2260 if (section
->is_virtual
)
2262 section
= get_containing_section (section
);
2263 gdb_assert (!section
->is_virtual
);
2265 return section
->s
.section
;
2268 /* Return the name of SECTION. */
2271 get_section_name (const struct dwarf2_section_info
*section
)
2273 asection
*sectp
= get_section_bfd_section (section
);
2275 gdb_assert (sectp
!= NULL
);
2276 return bfd_section_name (get_section_bfd_owner (section
), sectp
);
2279 /* Return the name of the file SECTION is in. */
2282 get_section_file_name (const struct dwarf2_section_info
*section
)
2284 bfd
*abfd
= get_section_bfd_owner (section
);
2286 return bfd_get_filename (abfd
);
2289 /* Return the id of SECTION.
2290 Returns 0 if SECTION doesn't exist. */
2293 get_section_id (const struct dwarf2_section_info
*section
)
2295 asection
*sectp
= get_section_bfd_section (section
);
2302 /* Return the flags of SECTION.
2303 SECTION (or containing section if this is a virtual section) must exist. */
2306 get_section_flags (const struct dwarf2_section_info
*section
)
2308 asection
*sectp
= get_section_bfd_section (section
);
2310 gdb_assert (sectp
!= NULL
);
2311 return bfd_get_section_flags (sectp
->owner
, sectp
);
2314 /* When loading sections, we look either for uncompressed section or for
2315 compressed section names. */
2318 section_is_p (const char *section_name
,
2319 const struct dwarf2_section_names
*names
)
2321 if (names
->normal
!= NULL
2322 && strcmp (section_name
, names
->normal
) == 0)
2324 if (names
->compressed
!= NULL
2325 && strcmp (section_name
, names
->compressed
) == 0)
2330 /* See declaration. */
2333 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
2334 const dwarf2_debug_sections
&names
)
2336 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
2338 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2341 else if (section_is_p (sectp
->name
, &names
.info
))
2343 this->info
.s
.section
= sectp
;
2344 this->info
.size
= bfd_get_section_size (sectp
);
2346 else if (section_is_p (sectp
->name
, &names
.abbrev
))
2348 this->abbrev
.s
.section
= sectp
;
2349 this->abbrev
.size
= bfd_get_section_size (sectp
);
2351 else if (section_is_p (sectp
->name
, &names
.line
))
2353 this->line
.s
.section
= sectp
;
2354 this->line
.size
= bfd_get_section_size (sectp
);
2356 else if (section_is_p (sectp
->name
, &names
.loc
))
2358 this->loc
.s
.section
= sectp
;
2359 this->loc
.size
= bfd_get_section_size (sectp
);
2361 else if (section_is_p (sectp
->name
, &names
.loclists
))
2363 this->loclists
.s
.section
= sectp
;
2364 this->loclists
.size
= bfd_get_section_size (sectp
);
2366 else if (section_is_p (sectp
->name
, &names
.macinfo
))
2368 this->macinfo
.s
.section
= sectp
;
2369 this->macinfo
.size
= bfd_get_section_size (sectp
);
2371 else if (section_is_p (sectp
->name
, &names
.macro
))
2373 this->macro
.s
.section
= sectp
;
2374 this->macro
.size
= bfd_get_section_size (sectp
);
2376 else if (section_is_p (sectp
->name
, &names
.str
))
2378 this->str
.s
.section
= sectp
;
2379 this->str
.size
= bfd_get_section_size (sectp
);
2381 else if (section_is_p (sectp
->name
, &names
.line_str
))
2383 this->line_str
.s
.section
= sectp
;
2384 this->line_str
.size
= bfd_get_section_size (sectp
);
2386 else if (section_is_p (sectp
->name
, &names
.addr
))
2388 this->addr
.s
.section
= sectp
;
2389 this->addr
.size
= bfd_get_section_size (sectp
);
2391 else if (section_is_p (sectp
->name
, &names
.frame
))
2393 this->frame
.s
.section
= sectp
;
2394 this->frame
.size
= bfd_get_section_size (sectp
);
2396 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2398 this->eh_frame
.s
.section
= sectp
;
2399 this->eh_frame
.size
= bfd_get_section_size (sectp
);
2401 else if (section_is_p (sectp
->name
, &names
.ranges
))
2403 this->ranges
.s
.section
= sectp
;
2404 this->ranges
.size
= bfd_get_section_size (sectp
);
2406 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2408 this->rnglists
.s
.section
= sectp
;
2409 this->rnglists
.size
= bfd_get_section_size (sectp
);
2411 else if (section_is_p (sectp
->name
, &names
.types
))
2413 struct dwarf2_section_info type_section
;
2415 memset (&type_section
, 0, sizeof (type_section
));
2416 type_section
.s
.section
= sectp
;
2417 type_section
.size
= bfd_get_section_size (sectp
);
2419 VEC_safe_push (dwarf2_section_info_def
, this->types
,
2422 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2424 this->gdb_index
.s
.section
= sectp
;
2425 this->gdb_index
.size
= bfd_get_section_size (sectp
);
2427 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2429 this->debug_names
.s
.section
= sectp
;
2430 this->debug_names
.size
= bfd_get_section_size (sectp
);
2432 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2434 this->debug_aranges
.s
.section
= sectp
;
2435 this->debug_aranges
.size
= bfd_get_section_size (sectp
);
2438 if ((bfd_get_section_flags (abfd
, sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2439 && bfd_section_vma (abfd
, sectp
) == 0)
2440 this->has_section_at_zero
= true;
2443 /* A helper function that decides whether a section is empty,
2447 dwarf2_section_empty_p (const struct dwarf2_section_info
*section
)
2449 if (section
->is_virtual
)
2450 return section
->size
== 0;
2451 return section
->s
.section
== NULL
|| section
->size
== 0;
2454 /* See dwarf2read.h. */
2457 dwarf2_read_section (struct objfile
*objfile
, dwarf2_section_info
*info
)
2461 gdb_byte
*buf
, *retbuf
;
2465 info
->buffer
= NULL
;
2468 if (dwarf2_section_empty_p (info
))
2471 sectp
= get_section_bfd_section (info
);
2473 /* If this is a virtual section we need to read in the real one first. */
2474 if (info
->is_virtual
)
2476 struct dwarf2_section_info
*containing_section
=
2477 get_containing_section (info
);
2479 gdb_assert (sectp
!= NULL
);
2480 if ((sectp
->flags
& SEC_RELOC
) != 0)
2482 error (_("Dwarf Error: DWP format V2 with relocations is not"
2483 " supported in section %s [in module %s]"),
2484 get_section_name (info
), get_section_file_name (info
));
2486 dwarf2_read_section (objfile
, containing_section
);
2487 /* Other code should have already caught virtual sections that don't
2489 gdb_assert (info
->virtual_offset
+ info
->size
2490 <= containing_section
->size
);
2491 /* If the real section is empty or there was a problem reading the
2492 section we shouldn't get here. */
2493 gdb_assert (containing_section
->buffer
!= NULL
);
2494 info
->buffer
= containing_section
->buffer
+ info
->virtual_offset
;
2498 /* If the section has relocations, we must read it ourselves.
2499 Otherwise we attach it to the BFD. */
2500 if ((sectp
->flags
& SEC_RELOC
) == 0)
2502 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
2506 buf
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
2509 /* When debugging .o files, we may need to apply relocations; see
2510 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2511 We never compress sections in .o files, so we only need to
2512 try this when the section is not compressed. */
2513 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
2516 info
->buffer
= retbuf
;
2520 abfd
= get_section_bfd_owner (info
);
2521 gdb_assert (abfd
!= NULL
);
2523 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
2524 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
2526 error (_("Dwarf Error: Can't read DWARF data"
2527 " in section %s [in module %s]"),
2528 bfd_section_name (abfd
, sectp
), bfd_get_filename (abfd
));
2532 /* A helper function that returns the size of a section in a safe way.
2533 If you are positive that the section has been read before using the
2534 size, then it is safe to refer to the dwarf2_section_info object's
2535 "size" field directly. In other cases, you must call this
2536 function, because for compressed sections the size field is not set
2537 correctly until the section has been read. */
2539 static bfd_size_type
2540 dwarf2_section_size (struct objfile
*objfile
,
2541 struct dwarf2_section_info
*info
)
2544 dwarf2_read_section (objfile
, info
);
2548 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2552 dwarf2_get_section_info (struct objfile
*objfile
,
2553 enum dwarf2_section_enum sect
,
2554 asection
**sectp
, const gdb_byte
**bufp
,
2555 bfd_size_type
*sizep
)
2557 struct dwarf2_per_objfile
*data
2558 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
2559 dwarf2_objfile_data_key
);
2560 struct dwarf2_section_info
*info
;
2562 /* We may see an objfile without any DWARF, in which case we just
2573 case DWARF2_DEBUG_FRAME
:
2574 info
= &data
->frame
;
2576 case DWARF2_EH_FRAME
:
2577 info
= &data
->eh_frame
;
2580 gdb_assert_not_reached ("unexpected section");
2583 dwarf2_read_section (objfile
, info
);
2585 *sectp
= get_section_bfd_section (info
);
2586 *bufp
= info
->buffer
;
2587 *sizep
= info
->size
;
2590 /* A helper function to find the sections for a .dwz file. */
2593 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2595 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2597 /* Note that we only support the standard ELF names, because .dwz
2598 is ELF-only (at the time of writing). */
2599 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2601 dwz_file
->abbrev
.s
.section
= sectp
;
2602 dwz_file
->abbrev
.size
= bfd_get_section_size (sectp
);
2604 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2606 dwz_file
->info
.s
.section
= sectp
;
2607 dwz_file
->info
.size
= bfd_get_section_size (sectp
);
2609 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2611 dwz_file
->str
.s
.section
= sectp
;
2612 dwz_file
->str
.size
= bfd_get_section_size (sectp
);
2614 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2616 dwz_file
->line
.s
.section
= sectp
;
2617 dwz_file
->line
.size
= bfd_get_section_size (sectp
);
2619 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2621 dwz_file
->macro
.s
.section
= sectp
;
2622 dwz_file
->macro
.size
= bfd_get_section_size (sectp
);
2624 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2626 dwz_file
->gdb_index
.s
.section
= sectp
;
2627 dwz_file
->gdb_index
.size
= bfd_get_section_size (sectp
);
2629 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2631 dwz_file
->debug_names
.s
.section
= sectp
;
2632 dwz_file
->debug_names
.size
= bfd_get_section_size (sectp
);
2636 /* Open the separate '.dwz' debug file, if needed. Return NULL if
2637 there is no .gnu_debugaltlink section in the file. Error if there
2638 is such a section but the file cannot be found. */
2640 static struct dwz_file
*
2641 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2643 const char *filename
;
2644 struct dwz_file
*result
;
2645 bfd_size_type buildid_len_arg
;
2649 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2650 return dwarf2_per_objfile
->dwz_file
;
2652 bfd_set_error (bfd_error_no_error
);
2653 gdb::unique_xmalloc_ptr
<char> data
2654 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2655 &buildid_len_arg
, &buildid
));
2658 if (bfd_get_error () == bfd_error_no_error
)
2660 error (_("could not read '.gnu_debugaltlink' section: %s"),
2661 bfd_errmsg (bfd_get_error ()));
2664 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2666 buildid_len
= (size_t) buildid_len_arg
;
2668 filename
= data
.get ();
2670 std::string abs_storage
;
2671 if (!IS_ABSOLUTE_PATH (filename
))
2673 gdb::unique_xmalloc_ptr
<char> abs
2674 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2676 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2677 filename
= abs_storage
.c_str ();
2680 /* First try the file name given in the section. If that doesn't
2681 work, try to use the build-id instead. */
2682 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2683 if (dwz_bfd
!= NULL
)
2685 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2689 if (dwz_bfd
== NULL
)
2690 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2692 if (dwz_bfd
== NULL
)
2693 error (_("could not find '.gnu_debugaltlink' file for %s"),
2694 objfile_name (dwarf2_per_objfile
->objfile
));
2696 result
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
2698 result
->dwz_bfd
= dwz_bfd
.release ();
2700 bfd_map_over_sections (result
->dwz_bfd
, locate_dwz_sections
, result
);
2702 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, result
->dwz_bfd
);
2703 dwarf2_per_objfile
->dwz_file
= result
;
2707 /* DWARF quick_symbols_functions support. */
2709 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2710 unique line tables, so we maintain a separate table of all .debug_line
2711 derived entries to support the sharing.
2712 All the quick functions need is the list of file names. We discard the
2713 line_header when we're done and don't need to record it here. */
2714 struct quick_file_names
2716 /* The data used to construct the hash key. */
2717 struct stmt_list_hash hash
;
2719 /* The number of entries in file_names, real_names. */
2720 unsigned int num_file_names
;
2722 /* The file names from the line table, after being run through
2724 const char **file_names
;
2726 /* The file names from the line table after being run through
2727 gdb_realpath. These are computed lazily. */
2728 const char **real_names
;
2731 /* When using the index (and thus not using psymtabs), each CU has an
2732 object of this type. This is used to hold information needed by
2733 the various "quick" methods. */
2734 struct dwarf2_per_cu_quick_data
2736 /* The file table. This can be NULL if there was no file table
2737 or it's currently not read in.
2738 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2739 struct quick_file_names
*file_names
;
2741 /* The corresponding symbol table. This is NULL if symbols for this
2742 CU have not yet been read. */
2743 struct compunit_symtab
*compunit_symtab
;
2745 /* A temporary mark bit used when iterating over all CUs in
2746 expand_symtabs_matching. */
2747 unsigned int mark
: 1;
2749 /* True if we've tried to read the file table and found there isn't one.
2750 There will be no point in trying to read it again next time. */
2751 unsigned int no_file_data
: 1;
2754 /* Utility hash function for a stmt_list_hash. */
2757 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2761 if (stmt_list_hash
->dwo_unit
!= NULL
)
2762 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2763 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2767 /* Utility equality function for a stmt_list_hash. */
2770 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2771 const struct stmt_list_hash
*rhs
)
2773 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2775 if (lhs
->dwo_unit
!= NULL
2776 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2779 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2782 /* Hash function for a quick_file_names. */
2785 hash_file_name_entry (const void *e
)
2787 const struct quick_file_names
*file_data
2788 = (const struct quick_file_names
*) e
;
2790 return hash_stmt_list_entry (&file_data
->hash
);
2793 /* Equality function for a quick_file_names. */
2796 eq_file_name_entry (const void *a
, const void *b
)
2798 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2799 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2801 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2804 /* Delete function for a quick_file_names. */
2807 delete_file_name_entry (void *e
)
2809 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2812 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2814 xfree ((void*) file_data
->file_names
[i
]);
2815 if (file_data
->real_names
)
2816 xfree ((void*) file_data
->real_names
[i
]);
2819 /* The space for the struct itself lives on objfile_obstack,
2820 so we don't free it here. */
2823 /* Create a quick_file_names hash table. */
2826 create_quick_file_names_table (unsigned int nr_initial_entries
)
2828 return htab_create_alloc (nr_initial_entries
,
2829 hash_file_name_entry
, eq_file_name_entry
,
2830 delete_file_name_entry
, xcalloc
, xfree
);
2833 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2834 have to be created afterwards. You should call age_cached_comp_units after
2835 processing PER_CU->CU. dw2_setup must have been already called. */
2838 load_cu (struct dwarf2_per_cu_data
*per_cu
)
2840 if (per_cu
->is_debug_types
)
2841 load_full_type_unit (per_cu
);
2843 load_full_comp_unit (per_cu
, language_minimal
);
2845 if (per_cu
->cu
== NULL
)
2846 return; /* Dummy CU. */
2848 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2851 /* Read in the symbols for PER_CU. */
2854 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2856 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2858 /* Skip type_unit_groups, reading the type units they contain
2859 is handled elsewhere. */
2860 if (IS_TYPE_UNIT_GROUP (per_cu
))
2863 /* The destructor of dwarf2_queue_guard frees any entries left on
2864 the queue. After this point we're guaranteed to leave this function
2865 with the dwarf queue empty. */
2866 dwarf2_queue_guard q_guard
;
2868 if (dwarf2_per_objfile
->using_index
2869 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2870 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2872 queue_comp_unit (per_cu
, language_minimal
);
2875 /* If we just loaded a CU from a DWO, and we're working with an index
2876 that may badly handle TUs, load all the TUs in that DWO as well.
2877 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2878 if (!per_cu
->is_debug_types
2879 && per_cu
->cu
!= NULL
2880 && per_cu
->cu
->dwo_unit
!= NULL
2881 && dwarf2_per_objfile
->index_table
!= NULL
2882 && dwarf2_per_objfile
->index_table
->version
<= 7
2883 /* DWP files aren't supported yet. */
2884 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2885 queue_and_load_all_dwo_tus (per_cu
);
2888 process_queue (dwarf2_per_objfile
);
2890 /* Age the cache, releasing compilation units that have not
2891 been used recently. */
2892 age_cached_comp_units (dwarf2_per_objfile
);
2895 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2896 the objfile from which this CU came. Returns the resulting symbol
2899 static struct compunit_symtab
*
2900 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2902 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2904 gdb_assert (dwarf2_per_objfile
->using_index
);
2905 if (!per_cu
->v
.quick
->compunit_symtab
)
2907 free_cached_comp_units
freer (dwarf2_per_objfile
);
2908 scoped_restore decrementer
= increment_reading_symtab ();
2909 dw2_do_instantiate_symtab (per_cu
);
2910 process_cu_includes (dwarf2_per_objfile
);
2913 return per_cu
->v
.quick
->compunit_symtab
;
2916 /* See declaration. */
2918 dwarf2_per_cu_data
*
2919 dwarf2_per_objfile::get_cutu (int index
)
2921 if (index
>= this->all_comp_units
.size ())
2923 index
-= this->all_comp_units
.size ();
2924 gdb_assert (index
< this->all_type_units
.size ());
2925 return &this->all_type_units
[index
]->per_cu
;
2928 return this->all_comp_units
[index
];
2931 /* See declaration. */
2933 dwarf2_per_cu_data
*
2934 dwarf2_per_objfile::get_cu (int index
)
2936 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2938 return this->all_comp_units
[index
];
2941 /* See declaration. */
2944 dwarf2_per_objfile::get_tu (int index
)
2946 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2948 return this->all_type_units
[index
];
2951 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2952 objfile_obstack, and constructed with the specified field
2955 static dwarf2_per_cu_data
*
2956 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2957 struct dwarf2_section_info
*section
,
2959 sect_offset sect_off
, ULONGEST length
)
2961 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2962 dwarf2_per_cu_data
*the_cu
2963 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2964 struct dwarf2_per_cu_data
);
2965 the_cu
->sect_off
= sect_off
;
2966 the_cu
->length
= length
;
2967 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2968 the_cu
->section
= section
;
2969 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2970 struct dwarf2_per_cu_quick_data
);
2971 the_cu
->is_dwz
= is_dwz
;
2975 /* A helper for create_cus_from_index that handles a given list of
2979 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2980 const gdb_byte
*cu_list
, offset_type n_elements
,
2981 struct dwarf2_section_info
*section
,
2984 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2986 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2988 sect_offset sect_off
2989 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2990 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2993 dwarf2_per_cu_data
*per_cu
2994 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
2996 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
3000 /* Read the CU list from the mapped index, and use it to create all
3001 the CU objects for this objfile. */
3004 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3005 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
3006 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
3008 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
3009 dwarf2_per_objfile
->all_comp_units
.reserve
3010 ((cu_list_elements
+ dwz_elements
) / 2);
3012 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3013 &dwarf2_per_objfile
->info
, 0);
3015 if (dwz_elements
== 0)
3018 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3019 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
3023 /* Create the signatured type hash table from the index. */
3026 create_signatured_type_table_from_index
3027 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3028 struct dwarf2_section_info
*section
,
3029 const gdb_byte
*bytes
,
3030 offset_type elements
)
3032 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3034 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
3035 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
3037 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3039 for (offset_type i
= 0; i
< elements
; i
+= 3)
3041 struct signatured_type
*sig_type
;
3044 cu_offset type_offset_in_tu
;
3046 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3047 sect_offset sect_off
3048 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
3050 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
3052 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
3055 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3056 struct signatured_type
);
3057 sig_type
->signature
= signature
;
3058 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3059 sig_type
->per_cu
.is_debug_types
= 1;
3060 sig_type
->per_cu
.section
= section
;
3061 sig_type
->per_cu
.sect_off
= sect_off
;
3062 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3063 sig_type
->per_cu
.v
.quick
3064 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3065 struct dwarf2_per_cu_quick_data
);
3067 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3070 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
3073 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3076 /* Create the signatured type hash table from .debug_names. */
3079 create_signatured_type_table_from_debug_names
3080 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3081 const mapped_debug_names
&map
,
3082 struct dwarf2_section_info
*section
,
3083 struct dwarf2_section_info
*abbrev_section
)
3085 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3087 dwarf2_read_section (objfile
, section
);
3088 dwarf2_read_section (objfile
, abbrev_section
);
3090 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
3091 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
3093 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3095 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
3097 struct signatured_type
*sig_type
;
3100 sect_offset sect_off
3101 = (sect_offset
) (extract_unsigned_integer
3102 (map
.tu_table_reordered
+ i
* map
.offset_size
,
3104 map
.dwarf5_byte_order
));
3106 comp_unit_head cu_header
;
3107 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
3109 section
->buffer
+ to_underlying (sect_off
),
3112 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3113 struct signatured_type
);
3114 sig_type
->signature
= cu_header
.signature
;
3115 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
3116 sig_type
->per_cu
.is_debug_types
= 1;
3117 sig_type
->per_cu
.section
= section
;
3118 sig_type
->per_cu
.sect_off
= sect_off
;
3119 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3120 sig_type
->per_cu
.v
.quick
3121 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3122 struct dwarf2_per_cu_quick_data
);
3124 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3127 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
3130 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3133 /* Read the address map data from the mapped index, and use it to
3134 populate the objfile's psymtabs_addrmap. */
3137 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3138 struct mapped_index
*index
)
3140 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3141 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3142 const gdb_byte
*iter
, *end
;
3143 struct addrmap
*mutable_map
;
3146 auto_obstack temp_obstack
;
3148 mutable_map
= addrmap_create_mutable (&temp_obstack
);
3150 iter
= index
->address_table
.data ();
3151 end
= iter
+ index
->address_table
.size ();
3153 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3157 ULONGEST hi
, lo
, cu_index
;
3158 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3160 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3162 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
3167 complaint (&symfile_complaints
,
3168 _(".gdb_index address table has invalid range (%s - %s)"),
3169 hex_string (lo
), hex_string (hi
));
3173 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
3175 complaint (&symfile_complaints
,
3176 _(".gdb_index address table has invalid CU number %u"),
3177 (unsigned) cu_index
);
3181 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
);
3182 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
);
3183 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
3184 dwarf2_per_objfile
->get_cu (cu_index
));
3187 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
3188 &objfile
->objfile_obstack
);
3191 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
3192 populate the objfile's psymtabs_addrmap. */
3195 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3196 struct dwarf2_section_info
*section
)
3198 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3199 bfd
*abfd
= objfile
->obfd
;
3200 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3201 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
3202 SECT_OFF_TEXT (objfile
));
3204 auto_obstack temp_obstack
;
3205 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
3207 std::unordered_map
<sect_offset
,
3208 dwarf2_per_cu_data
*,
3209 gdb::hash_enum
<sect_offset
>>
3210 debug_info_offset_to_per_cu
;
3211 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3213 const auto insertpair
3214 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
3215 if (!insertpair
.second
)
3217 warning (_("Section .debug_aranges in %s has duplicate "
3218 "debug_info_offset %s, ignoring .debug_aranges."),
3219 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
3224 dwarf2_read_section (objfile
, section
);
3226 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
3228 const gdb_byte
*addr
= section
->buffer
;
3230 while (addr
< section
->buffer
+ section
->size
)
3232 const gdb_byte
*const entry_addr
= addr
;
3233 unsigned int bytes_read
;
3235 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
3239 const gdb_byte
*const entry_end
= addr
+ entry_length
;
3240 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
3241 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
3242 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
3244 warning (_("Section .debug_aranges in %s entry at offset %zu "
3245 "length %s exceeds section length %s, "
3246 "ignoring .debug_aranges."),
3247 objfile_name (objfile
), entry_addr
- section
->buffer
,
3248 plongest (bytes_read
+ entry_length
),
3249 pulongest (section
->size
));
3253 /* The version number. */
3254 const uint16_t version
= read_2_bytes (abfd
, addr
);
3258 warning (_("Section .debug_aranges in %s entry at offset %zu "
3259 "has unsupported version %d, ignoring .debug_aranges."),
3260 objfile_name (objfile
), entry_addr
- section
->buffer
,
3265 const uint64_t debug_info_offset
3266 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
3267 addr
+= offset_size
;
3268 const auto per_cu_it
3269 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
3270 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
3272 warning (_("Section .debug_aranges in %s entry at offset %zu "
3273 "debug_info_offset %s does not exists, "
3274 "ignoring .debug_aranges."),
3275 objfile_name (objfile
), entry_addr
- section
->buffer
,
3276 pulongest (debug_info_offset
));
3279 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
3281 const uint8_t address_size
= *addr
++;
3282 if (address_size
< 1 || address_size
> 8)
3284 warning (_("Section .debug_aranges in %s entry at offset %zu "
3285 "address_size %u is invalid, ignoring .debug_aranges."),
3286 objfile_name (objfile
), entry_addr
- section
->buffer
,
3291 const uint8_t segment_selector_size
= *addr
++;
3292 if (segment_selector_size
!= 0)
3294 warning (_("Section .debug_aranges in %s entry at offset %zu "
3295 "segment_selector_size %u is not supported, "
3296 "ignoring .debug_aranges."),
3297 objfile_name (objfile
), entry_addr
- section
->buffer
,
3298 segment_selector_size
);
3302 /* Must pad to an alignment boundary that is twice the address
3303 size. It is undocumented by the DWARF standard but GCC does
3305 for (size_t padding
= ((-(addr
- section
->buffer
))
3306 & (2 * address_size
- 1));
3307 padding
> 0; padding
--)
3310 warning (_("Section .debug_aranges in %s entry at offset %zu "
3311 "padding is not zero, ignoring .debug_aranges."),
3312 objfile_name (objfile
), entry_addr
- section
->buffer
);
3318 if (addr
+ 2 * address_size
> entry_end
)
3320 warning (_("Section .debug_aranges in %s entry at offset %zu "
3321 "address list is not properly terminated, "
3322 "ignoring .debug_aranges."),
3323 objfile_name (objfile
), entry_addr
- section
->buffer
);
3326 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
3328 addr
+= address_size
;
3329 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
3331 addr
+= address_size
;
3332 if (start
== 0 && length
== 0)
3334 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3336 /* Symbol was eliminated due to a COMDAT group. */
3339 ULONGEST end
= start
+ length
;
3340 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
);
3341 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
);
3342 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
3346 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
3347 &objfile
->objfile_obstack
);
3350 /* Find a slot in the mapped index INDEX for the object named NAME.
3351 If NAME is found, set *VEC_OUT to point to the CU vector in the
3352 constant pool and return true. If NAME cannot be found, return
3356 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3357 offset_type
**vec_out
)
3360 offset_type slot
, step
;
3361 int (*cmp
) (const char *, const char *);
3363 gdb::unique_xmalloc_ptr
<char> without_params
;
3364 if (current_language
->la_language
== language_cplus
3365 || current_language
->la_language
== language_fortran
3366 || current_language
->la_language
== language_d
)
3368 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3371 if (strchr (name
, '(') != NULL
)
3373 without_params
= cp_remove_params (name
);
3375 if (without_params
!= NULL
)
3376 name
= without_params
.get ();
3380 /* Index version 4 did not support case insensitive searches. But the
3381 indices for case insensitive languages are built in lowercase, therefore
3382 simulate our NAME being searched is also lowercased. */
3383 hash
= mapped_index_string_hash ((index
->version
== 4
3384 && case_sensitivity
== case_sensitive_off
3385 ? 5 : index
->version
),
3388 slot
= hash
& (index
->symbol_table
.size () - 1);
3389 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
3390 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3396 const auto &bucket
= index
->symbol_table
[slot
];
3397 if (bucket
.name
== 0 && bucket
.vec
== 0)
3400 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
3401 if (!cmp (name
, str
))
3403 *vec_out
= (offset_type
*) (index
->constant_pool
3404 + MAYBE_SWAP (bucket
.vec
));
3408 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
3412 /* A helper function that reads the .gdb_index from SECTION and fills
3413 in MAP. FILENAME is the name of the file containing the section;
3414 it is used for error reporting. DEPRECATED_OK is true if it is
3415 ok to use deprecated sections.
3417 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3418 out parameters that are filled in with information about the CU and
3419 TU lists in the section.
3421 Returns 1 if all went well, 0 otherwise. */
3424 read_index_from_section (struct objfile
*objfile
,
3425 const char *filename
,
3427 struct dwarf2_section_info
*section
,
3428 struct mapped_index
*map
,
3429 const gdb_byte
**cu_list
,
3430 offset_type
*cu_list_elements
,
3431 const gdb_byte
**types_list
,
3432 offset_type
*types_list_elements
)
3434 const gdb_byte
*addr
;
3435 offset_type version
;
3436 offset_type
*metadata
;
3439 if (dwarf2_section_empty_p (section
))
3442 /* Older elfutils strip versions could keep the section in the main
3443 executable while splitting it for the separate debug info file. */
3444 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
3447 dwarf2_read_section (objfile
, section
);
3449 addr
= section
->buffer
;
3450 /* Version check. */
3451 version
= MAYBE_SWAP (*(offset_type
*) addr
);
3452 /* Versions earlier than 3 emitted every copy of a psymbol. This
3453 causes the index to behave very poorly for certain requests. Version 3
3454 contained incomplete addrmap. So, it seems better to just ignore such
3458 static int warning_printed
= 0;
3459 if (!warning_printed
)
3461 warning (_("Skipping obsolete .gdb_index section in %s."),
3463 warning_printed
= 1;
3467 /* Index version 4 uses a different hash function than index version
3470 Versions earlier than 6 did not emit psymbols for inlined
3471 functions. Using these files will cause GDB not to be able to
3472 set breakpoints on inlined functions by name, so we ignore these
3473 indices unless the user has done
3474 "set use-deprecated-index-sections on". */
3475 if (version
< 6 && !deprecated_ok
)
3477 static int warning_printed
= 0;
3478 if (!warning_printed
)
3481 Skipping deprecated .gdb_index section in %s.\n\
3482 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3483 to use the section anyway."),
3485 warning_printed
= 1;
3489 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3490 of the TU (for symbols coming from TUs),
3491 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3492 Plus gold-generated indices can have duplicate entries for global symbols,
3493 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3494 These are just performance bugs, and we can't distinguish gdb-generated
3495 indices from gold-generated ones, so issue no warning here. */
3497 /* Indexes with higher version than the one supported by GDB may be no
3498 longer backward compatible. */
3502 map
->version
= version
;
3503 map
->total_size
= section
->size
;
3505 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3508 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3509 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3513 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3514 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3515 - MAYBE_SWAP (metadata
[i
]))
3519 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3520 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3522 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3525 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3526 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3528 = gdb::array_view
<mapped_index::symbol_table_slot
>
3529 ((mapped_index::symbol_table_slot
*) symbol_table
,
3530 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3533 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3538 /* Read .gdb_index. If everything went ok, initialize the "quick"
3539 elements of all the CUs and return 1. Otherwise, return 0. */
3542 dwarf2_read_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
3544 struct mapped_index local_map
, *map
;
3545 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3546 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3547 struct dwz_file
*dwz
;
3548 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3550 if (!read_index_from_section (objfile
, objfile_name (objfile
),
3551 use_deprecated_index_sections
,
3552 &dwarf2_per_objfile
->gdb_index
, &local_map
,
3553 &cu_list
, &cu_list_elements
,
3554 &types_list
, &types_list_elements
))
3557 /* Don't use the index if it's empty. */
3558 if (local_map
.symbol_table
.empty ())
3561 /* If there is a .dwz file, read it so we can get its CU list as
3563 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3566 struct mapped_index dwz_map
;
3567 const gdb_byte
*dwz_types_ignore
;
3568 offset_type dwz_types_elements_ignore
;
3570 if (!read_index_from_section (objfile
, bfd_get_filename (dwz
->dwz_bfd
),
3572 &dwz
->gdb_index
, &dwz_map
,
3573 &dwz_list
, &dwz_list_elements
,
3575 &dwz_types_elements_ignore
))
3577 warning (_("could not read '.gdb_index' section from %s; skipping"),
3578 bfd_get_filename (dwz
->dwz_bfd
));
3583 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3584 dwz_list
, dwz_list_elements
);
3586 if (types_list_elements
)
3588 struct dwarf2_section_info
*section
;
3590 /* We can only handle a single .debug_types when we have an
3592 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
3595 section
= VEC_index (dwarf2_section_info_def
,
3596 dwarf2_per_objfile
->types
, 0);
3598 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3599 types_list
, types_list_elements
);
3602 create_addrmap_from_index (dwarf2_per_objfile
, &local_map
);
3604 map
= XOBNEW (&objfile
->objfile_obstack
, struct mapped_index
);
3605 map
= new (map
) mapped_index ();
3608 dwarf2_per_objfile
->index_table
= map
;
3609 dwarf2_per_objfile
->using_index
= 1;
3610 dwarf2_per_objfile
->quick_file_names_table
=
3611 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3616 /* die_reader_func for dw2_get_file_names. */
3619 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3620 const gdb_byte
*info_ptr
,
3621 struct die_info
*comp_unit_die
,
3625 struct dwarf2_cu
*cu
= reader
->cu
;
3626 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3627 struct dwarf2_per_objfile
*dwarf2_per_objfile
3628 = cu
->per_cu
->dwarf2_per_objfile
;
3629 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3630 struct dwarf2_per_cu_data
*lh_cu
;
3631 struct attribute
*attr
;
3634 struct quick_file_names
*qfn
;
3636 gdb_assert (! this_cu
->is_debug_types
);
3638 /* Our callers never want to match partial units -- instead they
3639 will match the enclosing full CU. */
3640 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3642 this_cu
->v
.quick
->no_file_data
= 1;
3650 sect_offset line_offset
{};
3652 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3655 struct quick_file_names find_entry
;
3657 line_offset
= (sect_offset
) DW_UNSND (attr
);
3659 /* We may have already read in this line header (TU line header sharing).
3660 If we have we're done. */
3661 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3662 find_entry
.hash
.line_sect_off
= line_offset
;
3663 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
3664 &find_entry
, INSERT
);
3667 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3671 lh
= dwarf_decode_line_header (line_offset
, cu
);
3675 lh_cu
->v
.quick
->no_file_data
= 1;
3679 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3680 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3681 qfn
->hash
.line_sect_off
= line_offset
;
3682 gdb_assert (slot
!= NULL
);
3685 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3687 qfn
->num_file_names
= lh
->file_names
.size ();
3689 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, lh
->file_names
.size ());
3690 for (i
= 0; i
< lh
->file_names
.size (); ++i
)
3691 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
.get (), fnd
.comp_dir
);
3692 qfn
->real_names
= NULL
;
3694 lh_cu
->v
.quick
->file_names
= qfn
;
3697 /* A helper for the "quick" functions which attempts to read the line
3698 table for THIS_CU. */
3700 static struct quick_file_names
*
3701 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3703 /* This should never be called for TUs. */
3704 gdb_assert (! this_cu
->is_debug_types
);
3705 /* Nor type unit groups. */
3706 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3708 if (this_cu
->v
.quick
->file_names
!= NULL
)
3709 return this_cu
->v
.quick
->file_names
;
3710 /* If we know there is no line data, no point in looking again. */
3711 if (this_cu
->v
.quick
->no_file_data
)
3714 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
3716 if (this_cu
->v
.quick
->no_file_data
)
3718 return this_cu
->v
.quick
->file_names
;
3721 /* A helper for the "quick" functions which computes and caches the
3722 real path for a given file name from the line table. */
3725 dw2_get_real_path (struct objfile
*objfile
,
3726 struct quick_file_names
*qfn
, int index
)
3728 if (qfn
->real_names
== NULL
)
3729 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3730 qfn
->num_file_names
, const char *);
3732 if (qfn
->real_names
[index
] == NULL
)
3733 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3735 return qfn
->real_names
[index
];
3738 static struct symtab
*
3739 dw2_find_last_source_symtab (struct objfile
*objfile
)
3741 struct dwarf2_per_objfile
*dwarf2_per_objfile
3742 = get_dwarf2_per_objfile (objfile
);
3743 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3744 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
);
3749 return compunit_primary_filetab (cust
);
3752 /* Traversal function for dw2_forget_cached_source_info. */
3755 dw2_free_cached_file_names (void **slot
, void *info
)
3757 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3759 if (file_data
->real_names
)
3763 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3765 xfree ((void*) file_data
->real_names
[i
]);
3766 file_data
->real_names
[i
] = NULL
;
3774 dw2_forget_cached_source_info (struct objfile
*objfile
)
3776 struct dwarf2_per_objfile
*dwarf2_per_objfile
3777 = get_dwarf2_per_objfile (objfile
);
3779 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3780 dw2_free_cached_file_names
, NULL
);
3783 /* Helper function for dw2_map_symtabs_matching_filename that expands
3784 the symtabs and calls the iterator. */
3787 dw2_map_expand_apply (struct objfile
*objfile
,
3788 struct dwarf2_per_cu_data
*per_cu
,
3789 const char *name
, const char *real_path
,
3790 gdb::function_view
<bool (symtab
*)> callback
)
3792 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3794 /* Don't visit already-expanded CUs. */
3795 if (per_cu
->v
.quick
->compunit_symtab
)
3798 /* This may expand more than one symtab, and we want to iterate over
3800 dw2_instantiate_symtab (per_cu
);
3802 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3803 last_made
, callback
);
3806 /* Implementation of the map_symtabs_matching_filename method. */
3809 dw2_map_symtabs_matching_filename
3810 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3811 gdb::function_view
<bool (symtab
*)> callback
)
3813 const char *name_basename
= lbasename (name
);
3814 struct dwarf2_per_objfile
*dwarf2_per_objfile
3815 = get_dwarf2_per_objfile (objfile
);
3817 /* The rule is CUs specify all the files, including those used by
3818 any TU, so there's no need to scan TUs here. */
3820 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3822 /* We only need to look at symtabs not already expanded. */
3823 if (per_cu
->v
.quick
->compunit_symtab
)
3826 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3827 if (file_data
== NULL
)
3830 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3832 const char *this_name
= file_data
->file_names
[j
];
3833 const char *this_real_name
;
3835 if (compare_filenames_for_search (this_name
, name
))
3837 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3843 /* Before we invoke realpath, which can get expensive when many
3844 files are involved, do a quick comparison of the basenames. */
3845 if (! basenames_may_differ
3846 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3849 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3850 if (compare_filenames_for_search (this_real_name
, name
))
3852 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3858 if (real_path
!= NULL
)
3860 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3861 gdb_assert (IS_ABSOLUTE_PATH (name
));
3862 if (this_real_name
!= NULL
3863 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3865 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3877 /* Struct used to manage iterating over all CUs looking for a symbol. */
3879 struct dw2_symtab_iterator
3881 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3882 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3883 /* If non-zero, only look for symbols that match BLOCK_INDEX. */
3884 int want_specific_block
;
3885 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
3886 Unused if !WANT_SPECIFIC_BLOCK. */
3888 /* The kind of symbol we're looking for. */
3890 /* The list of CUs from the index entry of the symbol,
3891 or NULL if not found. */
3893 /* The next element in VEC to look at. */
3895 /* The number of elements in VEC, or zero if there is no match. */
3897 /* Have we seen a global version of the symbol?
3898 If so we can ignore all further global instances.
3899 This is to work around gold/15646, inefficient gold-generated
3904 /* Initialize the index symtab iterator ITER.
3905 If WANT_SPECIFIC_BLOCK is non-zero, only look for symbols
3906 in block BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
3909 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3910 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3911 int want_specific_block
,
3916 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3917 iter
->want_specific_block
= want_specific_block
;
3918 iter
->block_index
= block_index
;
3919 iter
->domain
= domain
;
3921 iter
->global_seen
= 0;
3923 mapped_index
*index
= dwarf2_per_objfile
->index_table
;
3925 /* index is NULL if OBJF_READNOW. */
3926 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3927 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3935 /* Return the next matching CU or NULL if there are no more. */
3937 static struct dwarf2_per_cu_data
*
3938 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3940 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3942 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3944 offset_type cu_index_and_attrs
=
3945 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3946 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3947 int want_static
= iter
->block_index
!= GLOBAL_BLOCK
;
3948 /* This value is only valid for index versions >= 7. */
3949 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3950 gdb_index_symbol_kind symbol_kind
=
3951 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3952 /* Only check the symbol attributes if they're present.
3953 Indices prior to version 7 don't record them,
3954 and indices >= 7 may elide them for certain symbols
3955 (gold does this). */
3957 (dwarf2_per_objfile
->index_table
->version
>= 7
3958 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3960 /* Don't crash on bad data. */
3961 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
3962 + dwarf2_per_objfile
->all_type_units
.size ()))
3964 complaint (&symfile_complaints
,
3965 _(".gdb_index entry has bad CU index"
3967 objfile_name (dwarf2_per_objfile
->objfile
));
3971 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
3973 /* Skip if already read in. */
3974 if (per_cu
->v
.quick
->compunit_symtab
)
3977 /* Check static vs global. */
3980 if (iter
->want_specific_block
3981 && want_static
!= is_static
)
3983 /* Work around gold/15646. */
3984 if (!is_static
&& iter
->global_seen
)
3987 iter
->global_seen
= 1;
3990 /* Only check the symbol's kind if it has one. */
3993 switch (iter
->domain
)
3996 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3997 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3998 /* Some types are also in VAR_DOMAIN. */
3999 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4003 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4007 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4022 static struct compunit_symtab
*
4023 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
4024 const char *name
, domain_enum domain
)
4026 struct compunit_symtab
*stab_best
= NULL
;
4027 struct dwarf2_per_objfile
*dwarf2_per_objfile
4028 = get_dwarf2_per_objfile (objfile
);
4030 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
4032 struct dw2_symtab_iterator iter
;
4033 struct dwarf2_per_cu_data
*per_cu
;
4035 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, 1, block_index
, domain
, name
);
4037 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4039 struct symbol
*sym
, *with_opaque
= NULL
;
4040 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
);
4041 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
4042 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
4044 sym
= block_find_symbol (block
, name
, domain
,
4045 block_find_non_opaque_type_preferred
,
4048 /* Some caution must be observed with overloaded functions
4049 and methods, since the index will not contain any overload
4050 information (but NAME might contain it). */
4053 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
4055 if (with_opaque
!= NULL
4056 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
4059 /* Keep looking through other CUs. */
4066 dw2_print_stats (struct objfile
*objfile
)
4068 struct dwarf2_per_objfile
*dwarf2_per_objfile
4069 = get_dwarf2_per_objfile (objfile
);
4070 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
4071 + dwarf2_per_objfile
->all_type_units
.size ());
4074 for (int i
= 0; i
< total
; ++i
)
4076 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4078 if (!per_cu
->v
.quick
->compunit_symtab
)
4081 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
4082 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
4085 /* This dumps minimal information about the index.
4086 It is called via "mt print objfiles".
4087 One use is to verify .gdb_index has been loaded by the
4088 gdb.dwarf2/gdb-index.exp testcase. */
4091 dw2_dump (struct objfile
*objfile
)
4093 struct dwarf2_per_objfile
*dwarf2_per_objfile
4094 = get_dwarf2_per_objfile (objfile
);
4096 gdb_assert (dwarf2_per_objfile
->using_index
);
4097 printf_filtered (".gdb_index:");
4098 if (dwarf2_per_objfile
->index_table
!= NULL
)
4100 printf_filtered (" version %d\n",
4101 dwarf2_per_objfile
->index_table
->version
);
4104 printf_filtered (" faked for \"readnow\"\n");
4105 printf_filtered ("\n");
4109 dw2_relocate (struct objfile
*objfile
,
4110 const struct section_offsets
*new_offsets
,
4111 const struct section_offsets
*delta
)
4113 /* There's nothing to relocate here. */
4117 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
4118 const char *func_name
)
4120 struct dwarf2_per_objfile
*dwarf2_per_objfile
4121 = get_dwarf2_per_objfile (objfile
);
4123 struct dw2_symtab_iterator iter
;
4124 struct dwarf2_per_cu_data
*per_cu
;
4126 /* Note: It doesn't matter what we pass for block_index here. */
4127 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, 0, GLOBAL_BLOCK
, VAR_DOMAIN
,
4130 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4131 dw2_instantiate_symtab (per_cu
);
4136 dw2_expand_all_symtabs (struct objfile
*objfile
)
4138 struct dwarf2_per_objfile
*dwarf2_per_objfile
4139 = get_dwarf2_per_objfile (objfile
);
4140 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
4141 + dwarf2_per_objfile
->all_type_units
.size ());
4143 for (int i
= 0; i
< total_units
; ++i
)
4145 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4147 dw2_instantiate_symtab (per_cu
);
4152 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
4153 const char *fullname
)
4155 struct dwarf2_per_objfile
*dwarf2_per_objfile
4156 = get_dwarf2_per_objfile (objfile
);
4158 /* We don't need to consider type units here.
4159 This is only called for examining code, e.g. expand_line_sal.
4160 There can be an order of magnitude (or more) more type units
4161 than comp units, and we avoid them if we can. */
4163 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4165 /* We only need to look at symtabs not already expanded. */
4166 if (per_cu
->v
.quick
->compunit_symtab
)
4169 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4170 if (file_data
== NULL
)
4173 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4175 const char *this_fullname
= file_data
->file_names
[j
];
4177 if (filename_cmp (this_fullname
, fullname
) == 0)
4179 dw2_instantiate_symtab (per_cu
);
4187 dw2_map_matching_symbols (struct objfile
*objfile
,
4188 const char * name
, domain_enum domain
,
4190 int (*callback
) (struct block
*,
4191 struct symbol
*, void *),
4192 void *data
, symbol_name_match_type match
,
4193 symbol_compare_ftype
*ordered_compare
)
4195 /* Currently unimplemented; used for Ada. The function can be called if the
4196 current language is Ada for a non-Ada objfile using GNU index. As Ada
4197 does not look for non-Ada symbols this function should just return. */
4200 /* Symbol name matcher for .gdb_index names.
4202 Symbol names in .gdb_index have a few particularities:
4204 - There's no indication of which is the language of each symbol.
4206 Since each language has its own symbol name matching algorithm,
4207 and we don't know which language is the right one, we must match
4208 each symbol against all languages. This would be a potential
4209 performance problem if it were not mitigated by the
4210 mapped_index::name_components lookup table, which significantly
4211 reduces the number of times we need to call into this matcher,
4212 making it a non-issue.
4214 - Symbol names in the index have no overload (parameter)
4215 information. I.e., in C++, "foo(int)" and "foo(long)" both
4216 appear as "foo" in the index, for example.
4218 This means that the lookup names passed to the symbol name
4219 matcher functions must have no parameter information either
4220 because (e.g.) symbol search name "foo" does not match
4221 lookup-name "foo(int)" [while swapping search name for lookup
4224 class gdb_index_symbol_name_matcher
4227 /* Prepares the vector of comparison functions for LOOKUP_NAME. */
4228 gdb_index_symbol_name_matcher (const lookup_name_info
&lookup_name
);
4230 /* Walk all the matcher routines and match SYMBOL_NAME against them.
4231 Returns true if any matcher matches. */
4232 bool matches (const char *symbol_name
);
4235 /* A reference to the lookup name we're matching against. */
4236 const lookup_name_info
&m_lookup_name
;
4238 /* A vector holding all the different symbol name matchers, for all
4240 std::vector
<symbol_name_matcher_ftype
*> m_symbol_name_matcher_funcs
;
4243 gdb_index_symbol_name_matcher::gdb_index_symbol_name_matcher
4244 (const lookup_name_info
&lookup_name
)
4245 : m_lookup_name (lookup_name
)
4247 /* Prepare the vector of comparison functions upfront, to avoid
4248 doing the same work for each symbol. Care is taken to avoid
4249 matching with the same matcher more than once if/when multiple
4250 languages use the same matcher function. */
4251 auto &matchers
= m_symbol_name_matcher_funcs
;
4252 matchers
.reserve (nr_languages
);
4254 matchers
.push_back (default_symbol_name_matcher
);
4256 for (int i
= 0; i
< nr_languages
; i
++)
4258 const language_defn
*lang
= language_def ((enum language
) i
);
4259 symbol_name_matcher_ftype
*name_matcher
4260 = get_symbol_name_matcher (lang
, m_lookup_name
);
4262 /* Don't insert the same comparison routine more than once.
4263 Note that we do this linear walk instead of a seemingly
4264 cheaper sorted insert, or use a std::set or something like
4265 that, because relative order of function addresses is not
4266 stable. This is not a problem in practice because the number
4267 of supported languages is low, and the cost here is tiny
4268 compared to the number of searches we'll do afterwards using
4270 if (name_matcher
!= default_symbol_name_matcher
4271 && (std::find (matchers
.begin (), matchers
.end (), name_matcher
)
4272 == matchers
.end ()))
4273 matchers
.push_back (name_matcher
);
4278 gdb_index_symbol_name_matcher::matches (const char *symbol_name
)
4280 for (auto matches_name
: m_symbol_name_matcher_funcs
)
4281 if (matches_name (symbol_name
, m_lookup_name
, NULL
))
4287 /* Starting from a search name, return the string that finds the upper
4288 bound of all strings that start with SEARCH_NAME in a sorted name
4289 list. Returns the empty string to indicate that the upper bound is
4290 the end of the list. */
4293 make_sort_after_prefix_name (const char *search_name
)
4295 /* When looking to complete "func", we find the upper bound of all
4296 symbols that start with "func" by looking for where we'd insert
4297 the closest string that would follow "func" in lexicographical
4298 order. Usually, that's "func"-with-last-character-incremented,
4299 i.e. "fund". Mind non-ASCII characters, though. Usually those
4300 will be UTF-8 multi-byte sequences, but we can't be certain.
4301 Especially mind the 0xff character, which is a valid character in
4302 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
4303 rule out compilers allowing it in identifiers. Note that
4304 conveniently, strcmp/strcasecmp are specified to compare
4305 characters interpreted as unsigned char. So what we do is treat
4306 the whole string as a base 256 number composed of a sequence of
4307 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
4308 to 0, and carries 1 to the following more-significant position.
4309 If the very first character in SEARCH_NAME ends up incremented
4310 and carries/overflows, then the upper bound is the end of the
4311 list. The string after the empty string is also the empty
4314 Some examples of this operation:
4316 SEARCH_NAME => "+1" RESULT
4320 "\xff" "a" "\xff" => "\xff" "b"
4325 Then, with these symbols for example:
4331 completing "func" looks for symbols between "func" and
4332 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
4333 which finds "func" and "func1", but not "fund".
4337 funcÿ (Latin1 'ÿ' [0xff])
4341 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
4342 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
4346 ÿÿ (Latin1 'ÿ' [0xff])
4349 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
4350 the end of the list.
4352 std::string after
= search_name
;
4353 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
4355 if (!after
.empty ())
4356 after
.back () = (unsigned char) after
.back () + 1;
4360 /* See declaration. */
4362 std::pair
<std::vector
<name_component
>::const_iterator
,
4363 std::vector
<name_component
>::const_iterator
>
4364 mapped_index_base::find_name_components_bounds
4365 (const lookup_name_info
&lookup_name_without_params
) const
4368 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4371 = lookup_name_without_params
.cplus ().lookup_name ().c_str ();
4373 /* Comparison function object for lower_bound that matches against a
4374 given symbol name. */
4375 auto lookup_compare_lower
= [&] (const name_component
&elem
,
4378 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4379 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4380 return name_cmp (elem_name
, name
) < 0;
4383 /* Comparison function object for upper_bound that matches against a
4384 given symbol name. */
4385 auto lookup_compare_upper
= [&] (const char *name
,
4386 const name_component
&elem
)
4388 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4389 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4390 return name_cmp (name
, elem_name
) < 0;
4393 auto begin
= this->name_components
.begin ();
4394 auto end
= this->name_components
.end ();
4396 /* Find the lower bound. */
4399 if (lookup_name_without_params
.completion_mode () && cplus
[0] == '\0')
4402 return std::lower_bound (begin
, end
, cplus
, lookup_compare_lower
);
4405 /* Find the upper bound. */
4408 if (lookup_name_without_params
.completion_mode ())
4410 /* In completion mode, we want UPPER to point past all
4411 symbols names that have the same prefix. I.e., with
4412 these symbols, and completing "func":
4414 function << lower bound
4416 other_function << upper bound
4418 We find the upper bound by looking for the insertion
4419 point of "func"-with-last-character-incremented,
4421 std::string after
= make_sort_after_prefix_name (cplus
);
4424 return std::lower_bound (lower
, end
, after
.c_str (),
4425 lookup_compare_lower
);
4428 return std::upper_bound (lower
, end
, cplus
, lookup_compare_upper
);
4431 return {lower
, upper
};
4434 /* See declaration. */
4437 mapped_index_base::build_name_components ()
4439 if (!this->name_components
.empty ())
4442 this->name_components_casing
= case_sensitivity
;
4444 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4446 /* The code below only knows how to break apart components of C++
4447 symbol names (and other languages that use '::' as
4448 namespace/module separator). If we add support for wild matching
4449 to some language that uses some other operator (E.g., Ada, Go and
4450 D use '.'), then we'll need to try splitting the symbol name
4451 according to that language too. Note that Ada does support wild
4452 matching, but doesn't currently support .gdb_index. */
4453 auto count
= this->symbol_name_count ();
4454 for (offset_type idx
= 0; idx
< count
; idx
++)
4456 if (this->symbol_name_slot_invalid (idx
))
4459 const char *name
= this->symbol_name_at (idx
);
4461 /* Add each name component to the name component table. */
4462 unsigned int previous_len
= 0;
4463 for (unsigned int current_len
= cp_find_first_component (name
);
4464 name
[current_len
] != '\0';
4465 current_len
+= cp_find_first_component (name
+ current_len
))
4467 gdb_assert (name
[current_len
] == ':');
4468 this->name_components
.push_back ({previous_len
, idx
});
4469 /* Skip the '::'. */
4471 previous_len
= current_len
;
4473 this->name_components
.push_back ({previous_len
, idx
});
4476 /* Sort name_components elements by name. */
4477 auto name_comp_compare
= [&] (const name_component
&left
,
4478 const name_component
&right
)
4480 const char *left_qualified
= this->symbol_name_at (left
.idx
);
4481 const char *right_qualified
= this->symbol_name_at (right
.idx
);
4483 const char *left_name
= left_qualified
+ left
.name_offset
;
4484 const char *right_name
= right_qualified
+ right
.name_offset
;
4486 return name_cmp (left_name
, right_name
) < 0;
4489 std::sort (this->name_components
.begin (),
4490 this->name_components
.end (),
4494 /* Helper for dw2_expand_symtabs_matching that works with a
4495 mapped_index_base instead of the containing objfile. This is split
4496 to a separate function in order to be able to unit test the
4497 name_components matching using a mock mapped_index_base. For each
4498 symbol name that matches, calls MATCH_CALLBACK, passing it the
4499 symbol's index in the mapped_index_base symbol table. */
4502 dw2_expand_symtabs_matching_symbol
4503 (mapped_index_base
&index
,
4504 const lookup_name_info
&lookup_name_in
,
4505 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4506 enum search_domain kind
,
4507 gdb::function_view
<void (offset_type
)> match_callback
)
4509 lookup_name_info lookup_name_without_params
4510 = lookup_name_in
.make_ignore_params ();
4511 gdb_index_symbol_name_matcher lookup_name_matcher
4512 (lookup_name_without_params
);
4514 /* Build the symbol name component sorted vector, if we haven't
4516 index
.build_name_components ();
4518 auto bounds
= index
.find_name_components_bounds (lookup_name_without_params
);
4520 /* Now for each symbol name in range, check to see if we have a name
4521 match, and if so, call the MATCH_CALLBACK callback. */
4523 /* The same symbol may appear more than once in the range though.
4524 E.g., if we're looking for symbols that complete "w", and we have
4525 a symbol named "w1::w2", we'll find the two name components for
4526 that same symbol in the range. To be sure we only call the
4527 callback once per symbol, we first collect the symbol name
4528 indexes that matched in a temporary vector and ignore
4530 std::vector
<offset_type
> matches
;
4531 matches
.reserve (std::distance (bounds
.first
, bounds
.second
));
4533 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4535 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
4537 if (!lookup_name_matcher
.matches (qualified
)
4538 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4541 matches
.push_back (bounds
.first
->idx
);
4544 std::sort (matches
.begin (), matches
.end ());
4546 /* Finally call the callback, once per match. */
4548 for (offset_type idx
: matches
)
4552 match_callback (idx
);
4557 /* Above we use a type wider than idx's for 'prev', since 0 and
4558 (offset_type)-1 are both possible values. */
4559 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4564 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4566 /* A mock .gdb_index/.debug_names-like name index table, enough to
4567 exercise dw2_expand_symtabs_matching_symbol, which works with the
4568 mapped_index_base interface. Builds an index from the symbol list
4569 passed as parameter to the constructor. */
4570 class mock_mapped_index
: public mapped_index_base
4573 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4574 : m_symbol_table (symbols
)
4577 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4579 /* Return the number of names in the symbol table. */
4580 size_t symbol_name_count () const override
4582 return m_symbol_table
.size ();
4585 /* Get the name of the symbol at IDX in the symbol table. */
4586 const char *symbol_name_at (offset_type idx
) const override
4588 return m_symbol_table
[idx
];
4592 gdb::array_view
<const char *> m_symbol_table
;
4595 /* Convenience function that converts a NULL pointer to a "<null>"
4596 string, to pass to print routines. */
4599 string_or_null (const char *str
)
4601 return str
!= NULL
? str
: "<null>";
4604 /* Check if a lookup_name_info built from
4605 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4606 index. EXPECTED_LIST is the list of expected matches, in expected
4607 matching order. If no match expected, then an empty list is
4608 specified. Returns true on success. On failure prints a warning
4609 indicating the file:line that failed, and returns false. */
4612 check_match (const char *file
, int line
,
4613 mock_mapped_index
&mock_index
,
4614 const char *name
, symbol_name_match_type match_type
,
4615 bool completion_mode
,
4616 std::initializer_list
<const char *> expected_list
)
4618 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4620 bool matched
= true;
4622 auto mismatch
= [&] (const char *expected_str
,
4625 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4626 "expected=\"%s\", got=\"%s\"\n"),
4628 (match_type
== symbol_name_match_type::FULL
4630 name
, string_or_null (expected_str
), string_or_null (got
));
4634 auto expected_it
= expected_list
.begin ();
4635 auto expected_end
= expected_list
.end ();
4637 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4639 [&] (offset_type idx
)
4641 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4642 const char *expected_str
4643 = expected_it
== expected_end
? NULL
: *expected_it
++;
4645 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4646 mismatch (expected_str
, matched_name
);
4649 const char *expected_str
4650 = expected_it
== expected_end
? NULL
: *expected_it
++;
4651 if (expected_str
!= NULL
)
4652 mismatch (expected_str
, NULL
);
4657 /* The symbols added to the mock mapped_index for testing (in
4659 static const char *test_symbols
[] = {
4668 "ns2::tmpl<int>::foo2",
4669 "(anonymous namespace)::A::B::C",
4671 /* These are used to check that the increment-last-char in the
4672 matching algorithm for completion doesn't match "t1_fund" when
4673 completing "t1_func". */
4679 /* A UTF-8 name with multi-byte sequences to make sure that
4680 cp-name-parser understands this as a single identifier ("função"
4681 is "function" in PT). */
4684 /* \377 (0xff) is Latin1 'ÿ'. */
4687 /* \377 (0xff) is Latin1 'ÿ'. */
4691 /* A name with all sorts of complications. Starts with "z" to make
4692 it easier for the completion tests below. */
4693 #define Z_SYM_NAME \
4694 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4695 "::tuple<(anonymous namespace)::ui*, " \
4696 "std::default_delete<(anonymous namespace)::ui>, void>"
4701 /* Returns true if the mapped_index_base::find_name_component_bounds
4702 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4703 in completion mode. */
4706 check_find_bounds_finds (mapped_index_base
&index
,
4707 const char *search_name
,
4708 gdb::array_view
<const char *> expected_syms
)
4710 lookup_name_info
lookup_name (search_name
,
4711 symbol_name_match_type::FULL
, true);
4713 auto bounds
= index
.find_name_components_bounds (lookup_name
);
4715 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4716 if (distance
!= expected_syms
.size ())
4719 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4721 auto nc_elem
= bounds
.first
+ exp_elem
;
4722 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4723 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4730 /* Test the lower-level mapped_index::find_name_component_bounds
4734 test_mapped_index_find_name_component_bounds ()
4736 mock_mapped_index
mock_index (test_symbols
);
4738 mock_index
.build_name_components ();
4740 /* Test the lower-level mapped_index::find_name_component_bounds
4741 method in completion mode. */
4743 static const char *expected_syms
[] = {
4748 SELF_CHECK (check_find_bounds_finds (mock_index
,
4749 "t1_func", expected_syms
));
4752 /* Check that the increment-last-char in the name matching algorithm
4753 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4755 static const char *expected_syms1
[] = {
4759 SELF_CHECK (check_find_bounds_finds (mock_index
,
4760 "\377", expected_syms1
));
4762 static const char *expected_syms2
[] = {
4765 SELF_CHECK (check_find_bounds_finds (mock_index
,
4766 "\377\377", expected_syms2
));
4770 /* Test dw2_expand_symtabs_matching_symbol. */
4773 test_dw2_expand_symtabs_matching_symbol ()
4775 mock_mapped_index
mock_index (test_symbols
);
4777 /* We let all tests run until the end even if some fails, for debug
4779 bool any_mismatch
= false;
4781 /* Create the expected symbols list (an initializer_list). Needed
4782 because lists have commas, and we need to pass them to CHECK,
4783 which is a macro. */
4784 #define EXPECT(...) { __VA_ARGS__ }
4786 /* Wrapper for check_match that passes down the current
4787 __FILE__/__LINE__. */
4788 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4789 any_mismatch |= !check_match (__FILE__, __LINE__, \
4791 NAME, MATCH_TYPE, COMPLETION_MODE, \
4794 /* Identity checks. */
4795 for (const char *sym
: test_symbols
)
4797 /* Should be able to match all existing symbols. */
4798 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4801 /* Should be able to match all existing symbols with
4803 std::string with_params
= std::string (sym
) + "(int)";
4804 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4807 /* Should be able to match all existing symbols with
4808 parameters and qualifiers. */
4809 with_params
= std::string (sym
) + " ( int ) const";
4810 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4813 /* This should really find sym, but cp-name-parser.y doesn't
4814 know about lvalue/rvalue qualifiers yet. */
4815 with_params
= std::string (sym
) + " ( int ) &&";
4816 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4820 /* Check that the name matching algorithm for completion doesn't get
4821 confused with Latin1 'ÿ' / 0xff. */
4823 static const char str
[] = "\377";
4824 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4825 EXPECT ("\377", "\377\377123"));
4828 /* Check that the increment-last-char in the matching algorithm for
4829 completion doesn't match "t1_fund" when completing "t1_func". */
4831 static const char str
[] = "t1_func";
4832 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4833 EXPECT ("t1_func", "t1_func1"));
4836 /* Check that completion mode works at each prefix of the expected
4839 static const char str
[] = "function(int)";
4840 size_t len
= strlen (str
);
4843 for (size_t i
= 1; i
< len
; i
++)
4845 lookup
.assign (str
, i
);
4846 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4847 EXPECT ("function"));
4851 /* While "w" is a prefix of both components, the match function
4852 should still only be called once. */
4854 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4856 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4860 /* Same, with a "complicated" symbol. */
4862 static const char str
[] = Z_SYM_NAME
;
4863 size_t len
= strlen (str
);
4866 for (size_t i
= 1; i
< len
; i
++)
4868 lookup
.assign (str
, i
);
4869 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4870 EXPECT (Z_SYM_NAME
));
4874 /* In FULL mode, an incomplete symbol doesn't match. */
4876 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4880 /* A complete symbol with parameters matches any overload, since the
4881 index has no overload info. */
4883 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4884 EXPECT ("std::zfunction", "std::zfunction2"));
4885 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4886 EXPECT ("std::zfunction", "std::zfunction2"));
4887 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4888 EXPECT ("std::zfunction", "std::zfunction2"));
4891 /* Check that whitespace is ignored appropriately. A symbol with a
4892 template argument list. */
4894 static const char expected
[] = "ns::foo<int>";
4895 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4897 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4901 /* Check that whitespace is ignored appropriately. A symbol with a
4902 template argument list that includes a pointer. */
4904 static const char expected
[] = "ns::foo<char*>";
4905 /* Try both completion and non-completion modes. */
4906 static const bool completion_mode
[2] = {false, true};
4907 for (size_t i
= 0; i
< 2; i
++)
4909 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4910 completion_mode
[i
], EXPECT (expected
));
4911 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4912 completion_mode
[i
], EXPECT (expected
));
4914 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4915 completion_mode
[i
], EXPECT (expected
));
4916 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4917 completion_mode
[i
], EXPECT (expected
));
4922 /* Check method qualifiers are ignored. */
4923 static const char expected
[] = "ns::foo<char*>";
4924 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4925 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4926 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4927 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4928 CHECK_MATCH ("foo < char * > ( int ) const",
4929 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4930 CHECK_MATCH ("foo < char * > ( int ) &&",
4931 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4934 /* Test lookup names that don't match anything. */
4936 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4939 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4943 /* Some wild matching tests, exercising "(anonymous namespace)",
4944 which should not be confused with a parameter list. */
4946 static const char *syms
[] = {
4950 "A :: B :: C ( int )",
4955 for (const char *s
: syms
)
4957 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4958 EXPECT ("(anonymous namespace)::A::B::C"));
4963 static const char expected
[] = "ns2::tmpl<int>::foo2";
4964 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4966 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4970 SELF_CHECK (!any_mismatch
);
4979 test_mapped_index_find_name_component_bounds ();
4980 test_dw2_expand_symtabs_matching_symbol ();
4983 }} // namespace selftests::dw2_expand_symtabs_matching
4985 #endif /* GDB_SELF_TEST */
4987 /* If FILE_MATCHER is NULL or if PER_CU has
4988 dwarf2_per_cu_quick_data::MARK set (see
4989 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4990 EXPANSION_NOTIFY on it. */
4993 dw2_expand_symtabs_matching_one
4994 (struct dwarf2_per_cu_data
*per_cu
,
4995 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4996 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4998 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
5000 bool symtab_was_null
5001 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
5003 dw2_instantiate_symtab (per_cu
);
5005 if (expansion_notify
!= NULL
5007 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
5008 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
5012 /* Helper for dw2_expand_matching symtabs. Called on each symbol
5013 matched, to expand corresponding CUs that were marked. IDX is the
5014 index of the symbol name that matched. */
5017 dw2_expand_marked_cus
5018 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
5019 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5020 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5023 offset_type
*vec
, vec_len
, vec_idx
;
5024 bool global_seen
= false;
5025 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5027 vec
= (offset_type
*) (index
.constant_pool
5028 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
5029 vec_len
= MAYBE_SWAP (vec
[0]);
5030 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
5032 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
5033 /* This value is only valid for index versions >= 7. */
5034 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
5035 gdb_index_symbol_kind symbol_kind
=
5036 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
5037 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
5038 /* Only check the symbol attributes if they're present.
5039 Indices prior to version 7 don't record them,
5040 and indices >= 7 may elide them for certain symbols
5041 (gold does this). */
5044 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
5046 /* Work around gold/15646. */
5049 if (!is_static
&& global_seen
)
5055 /* Only check the symbol's kind if it has one. */
5060 case VARIABLES_DOMAIN
:
5061 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
5064 case FUNCTIONS_DOMAIN
:
5065 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
5069 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
5077 /* Don't crash on bad data. */
5078 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
5079 + dwarf2_per_objfile
->all_type_units
.size ()))
5081 complaint (&symfile_complaints
,
5082 _(".gdb_index entry has bad CU index"
5084 objfile_name (dwarf2_per_objfile
->objfile
));
5088 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
5089 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5094 /* If FILE_MATCHER is non-NULL, set all the
5095 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
5096 that match FILE_MATCHER. */
5099 dw_expand_symtabs_matching_file_matcher
5100 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5101 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
5103 if (file_matcher
== NULL
)
5106 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
5108 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
5110 NULL
, xcalloc
, xfree
));
5111 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
5113 NULL
, xcalloc
, xfree
));
5115 /* The rule is CUs specify all the files, including those used by
5116 any TU, so there's no need to scan TUs here. */
5118 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5122 per_cu
->v
.quick
->mark
= 0;
5124 /* We only need to look at symtabs not already expanded. */
5125 if (per_cu
->v
.quick
->compunit_symtab
)
5128 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5129 if (file_data
== NULL
)
5132 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
5134 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
5136 per_cu
->v
.quick
->mark
= 1;
5140 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5142 const char *this_real_name
;
5144 if (file_matcher (file_data
->file_names
[j
], false))
5146 per_cu
->v
.quick
->mark
= 1;
5150 /* Before we invoke realpath, which can get expensive when many
5151 files are involved, do a quick comparison of the basenames. */
5152 if (!basenames_may_differ
5153 && !file_matcher (lbasename (file_data
->file_names
[j
]),
5157 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
5158 if (file_matcher (this_real_name
, false))
5160 per_cu
->v
.quick
->mark
= 1;
5165 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
5166 ? visited_found
.get ()
5167 : visited_not_found
.get (),
5174 dw2_expand_symtabs_matching
5175 (struct objfile
*objfile
,
5176 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5177 const lookup_name_info
&lookup_name
,
5178 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5179 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5180 enum search_domain kind
)
5182 struct dwarf2_per_objfile
*dwarf2_per_objfile
5183 = get_dwarf2_per_objfile (objfile
);
5185 /* index_table is NULL if OBJF_READNOW. */
5186 if (!dwarf2_per_objfile
->index_table
)
5189 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5191 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5193 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
5195 kind
, [&] (offset_type idx
)
5197 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
5198 expansion_notify
, kind
);
5202 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
5205 static struct compunit_symtab
*
5206 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
5211 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
5212 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
5215 if (cust
->includes
== NULL
)
5218 for (i
= 0; cust
->includes
[i
]; ++i
)
5220 struct compunit_symtab
*s
= cust
->includes
[i
];
5222 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
5230 static struct compunit_symtab
*
5231 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
5232 struct bound_minimal_symbol msymbol
,
5234 struct obj_section
*section
,
5237 struct dwarf2_per_cu_data
*data
;
5238 struct compunit_symtab
*result
;
5240 if (!objfile
->psymtabs_addrmap
)
5243 data
= (struct dwarf2_per_cu_data
*) addrmap_find (objfile
->psymtabs_addrmap
,
5248 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
5249 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
5250 paddress (get_objfile_arch (objfile
), pc
));
5253 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
),
5255 gdb_assert (result
!= NULL
);
5260 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
5261 void *data
, int need_fullname
)
5263 struct dwarf2_per_objfile
*dwarf2_per_objfile
5264 = get_dwarf2_per_objfile (objfile
);
5266 if (!dwarf2_per_objfile
->filenames_cache
)
5268 dwarf2_per_objfile
->filenames_cache
.emplace ();
5270 htab_up
visited (htab_create_alloc (10,
5271 htab_hash_pointer
, htab_eq_pointer
,
5272 NULL
, xcalloc
, xfree
));
5274 /* The rule is CUs specify all the files, including those used
5275 by any TU, so there's no need to scan TUs here. We can
5276 ignore file names coming from already-expanded CUs. */
5278 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5280 if (per_cu
->v
.quick
->compunit_symtab
)
5282 void **slot
= htab_find_slot (visited
.get (),
5283 per_cu
->v
.quick
->file_names
,
5286 *slot
= per_cu
->v
.quick
->file_names
;
5290 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5292 /* We only need to look at symtabs not already expanded. */
5293 if (per_cu
->v
.quick
->compunit_symtab
)
5296 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5297 if (file_data
== NULL
)
5300 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
5303 /* Already visited. */
5308 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5310 const char *filename
= file_data
->file_names
[j
];
5311 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
5316 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
5318 gdb::unique_xmalloc_ptr
<char> this_real_name
;
5321 this_real_name
= gdb_realpath (filename
);
5322 (*fun
) (filename
, this_real_name
.get (), data
);
5327 dw2_has_symbols (struct objfile
*objfile
)
5332 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
5335 dw2_find_last_source_symtab
,
5336 dw2_forget_cached_source_info
,
5337 dw2_map_symtabs_matching_filename
,
5342 dw2_expand_symtabs_for_function
,
5343 dw2_expand_all_symtabs
,
5344 dw2_expand_symtabs_with_fullname
,
5345 dw2_map_matching_symbols
,
5346 dw2_expand_symtabs_matching
,
5347 dw2_find_pc_sect_compunit_symtab
,
5349 dw2_map_symbol_filenames
5352 /* DWARF-5 debug_names reader. */
5354 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
5355 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
5357 /* A helper function that reads the .debug_names section in SECTION
5358 and fills in MAP. FILENAME is the name of the file containing the
5359 section; it is used for error reporting.
5361 Returns true if all went well, false otherwise. */
5364 read_debug_names_from_section (struct objfile
*objfile
,
5365 const char *filename
,
5366 struct dwarf2_section_info
*section
,
5367 mapped_debug_names
&map
)
5369 if (dwarf2_section_empty_p (section
))
5372 /* Older elfutils strip versions could keep the section in the main
5373 executable while splitting it for the separate debug info file. */
5374 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
5377 dwarf2_read_section (objfile
, section
);
5379 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
5381 const gdb_byte
*addr
= section
->buffer
;
5383 bfd
*const abfd
= get_section_bfd_owner (section
);
5385 unsigned int bytes_read
;
5386 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5389 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5390 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5391 if (bytes_read
+ length
!= section
->size
)
5393 /* There may be multiple per-CU indices. */
5394 warning (_("Section .debug_names in %s length %s does not match "
5395 "section length %s, ignoring .debug_names."),
5396 filename
, plongest (bytes_read
+ length
),
5397 pulongest (section
->size
));
5401 /* The version number. */
5402 uint16_t version
= read_2_bytes (abfd
, addr
);
5406 warning (_("Section .debug_names in %s has unsupported version %d, "
5407 "ignoring .debug_names."),
5413 uint16_t padding
= read_2_bytes (abfd
, addr
);
5417 warning (_("Section .debug_names in %s has unsupported padding %d, "
5418 "ignoring .debug_names."),
5423 /* comp_unit_count - The number of CUs in the CU list. */
5424 map
.cu_count
= read_4_bytes (abfd
, addr
);
5427 /* local_type_unit_count - The number of TUs in the local TU
5429 map
.tu_count
= read_4_bytes (abfd
, addr
);
5432 /* foreign_type_unit_count - The number of TUs in the foreign TU
5434 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5436 if (foreign_tu_count
!= 0)
5438 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5439 "ignoring .debug_names."),
5440 filename
, static_cast<unsigned long> (foreign_tu_count
));
5444 /* bucket_count - The number of hash buckets in the hash lookup
5446 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5449 /* name_count - The number of unique names in the index. */
5450 map
.name_count
= read_4_bytes (abfd
, addr
);
5453 /* abbrev_table_size - The size in bytes of the abbreviations
5455 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5458 /* augmentation_string_size - The size in bytes of the augmentation
5459 string. This value is rounded up to a multiple of 4. */
5460 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5462 map
.augmentation_is_gdb
= ((augmentation_string_size
5463 == sizeof (dwarf5_augmentation
))
5464 && memcmp (addr
, dwarf5_augmentation
,
5465 sizeof (dwarf5_augmentation
)) == 0);
5466 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5467 addr
+= augmentation_string_size
;
5470 map
.cu_table_reordered
= addr
;
5471 addr
+= map
.cu_count
* map
.offset_size
;
5473 /* List of Local TUs */
5474 map
.tu_table_reordered
= addr
;
5475 addr
+= map
.tu_count
* map
.offset_size
;
5477 /* Hash Lookup Table */
5478 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5479 addr
+= map
.bucket_count
* 4;
5480 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5481 addr
+= map
.name_count
* 4;
5484 map
.name_table_string_offs_reordered
= addr
;
5485 addr
+= map
.name_count
* map
.offset_size
;
5486 map
.name_table_entry_offs_reordered
= addr
;
5487 addr
+= map
.name_count
* map
.offset_size
;
5489 const gdb_byte
*abbrev_table_start
= addr
;
5492 unsigned int bytes_read
;
5493 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5498 const auto insertpair
5499 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5500 if (!insertpair
.second
)
5502 warning (_("Section .debug_names in %s has duplicate index %s, "
5503 "ignoring .debug_names."),
5504 filename
, pulongest (index_num
));
5507 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5508 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5513 mapped_debug_names::index_val::attr attr
;
5514 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5516 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5518 if (attr
.form
== DW_FORM_implicit_const
)
5520 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5524 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5526 indexval
.attr_vec
.push_back (std::move (attr
));
5529 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5531 warning (_("Section .debug_names in %s has abbreviation_table "
5532 "of size %zu vs. written as %u, ignoring .debug_names."),
5533 filename
, addr
- abbrev_table_start
, abbrev_table_size
);
5536 map
.entry_pool
= addr
;
5541 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5545 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5546 const mapped_debug_names
&map
,
5547 dwarf2_section_info
§ion
,
5550 sect_offset sect_off_prev
;
5551 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5553 sect_offset sect_off_next
;
5554 if (i
< map
.cu_count
)
5557 = (sect_offset
) (extract_unsigned_integer
5558 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5560 map
.dwarf5_byte_order
));
5563 sect_off_next
= (sect_offset
) section
.size
;
5566 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5567 dwarf2_per_cu_data
*per_cu
5568 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5569 sect_off_prev
, length
);
5570 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5572 sect_off_prev
= sect_off_next
;
5576 /* Read the CU list from the mapped index, and use it to create all
5577 the CU objects for this dwarf2_per_objfile. */
5580 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5581 const mapped_debug_names
&map
,
5582 const mapped_debug_names
&dwz_map
)
5584 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
5585 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5587 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5588 dwarf2_per_objfile
->info
,
5589 false /* is_dwz */);
5591 if (dwz_map
.cu_count
== 0)
5594 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5595 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5599 /* Read .debug_names. If everything went ok, initialize the "quick"
5600 elements of all the CUs and return true. Otherwise, return false. */
5603 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5605 mapped_debug_names
local_map (dwarf2_per_objfile
);
5606 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5607 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5609 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5610 &dwarf2_per_objfile
->debug_names
,
5614 /* Don't use the index if it's empty. */
5615 if (local_map
.name_count
== 0)
5618 /* If there is a .dwz file, read it so we can get its CU list as
5620 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5623 if (!read_debug_names_from_section (objfile
,
5624 bfd_get_filename (dwz
->dwz_bfd
),
5625 &dwz
->debug_names
, dwz_map
))
5627 warning (_("could not read '.debug_names' section from %s; skipping"),
5628 bfd_get_filename (dwz
->dwz_bfd
));
5633 create_cus_from_debug_names (dwarf2_per_objfile
, local_map
, dwz_map
);
5635 if (local_map
.tu_count
!= 0)
5637 /* We can only handle a single .debug_types when we have an
5639 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
5642 dwarf2_section_info
*section
= VEC_index (dwarf2_section_info_def
,
5643 dwarf2_per_objfile
->types
, 0);
5645 create_signatured_type_table_from_debug_names
5646 (dwarf2_per_objfile
, local_map
, section
, &dwarf2_per_objfile
->abbrev
);
5649 create_addrmap_from_aranges (dwarf2_per_objfile
,
5650 &dwarf2_per_objfile
->debug_aranges
);
5652 dwarf2_per_objfile
->debug_names_table
.reset
5653 (new mapped_debug_names (dwarf2_per_objfile
));
5654 *dwarf2_per_objfile
->debug_names_table
= std::move (local_map
);
5655 dwarf2_per_objfile
->using_index
= 1;
5656 dwarf2_per_objfile
->quick_file_names_table
=
5657 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5662 /* Type used to manage iterating over all CUs looking for a symbol for
5665 class dw2_debug_names_iterator
5668 /* If WANT_SPECIFIC_BLOCK is true, only look for symbols in block
5669 BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
5670 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5671 bool want_specific_block
,
5672 block_enum block_index
, domain_enum domain
,
5674 : m_map (map
), m_want_specific_block (want_specific_block
),
5675 m_block_index (block_index
), m_domain (domain
),
5676 m_addr (find_vec_in_debug_names (map
, name
))
5679 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5680 search_domain search
, uint32_t namei
)
5683 m_addr (find_vec_in_debug_names (map
, namei
))
5686 /* Return the next matching CU or NULL if there are no more. */
5687 dwarf2_per_cu_data
*next ();
5690 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5692 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5695 /* The internalized form of .debug_names. */
5696 const mapped_debug_names
&m_map
;
5698 /* If true, only look for symbols that match BLOCK_INDEX. */
5699 const bool m_want_specific_block
= false;
5701 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
5702 Unused if !WANT_SPECIFIC_BLOCK - FIRST_LOCAL_BLOCK is an invalid
5704 const block_enum m_block_index
= FIRST_LOCAL_BLOCK
;
5706 /* The kind of symbol we're looking for. */
5707 const domain_enum m_domain
= UNDEF_DOMAIN
;
5708 const search_domain m_search
= ALL_DOMAIN
;
5710 /* The list of CUs from the index entry of the symbol, or NULL if
5712 const gdb_byte
*m_addr
;
5716 mapped_debug_names::namei_to_name (uint32_t namei
) const
5718 const ULONGEST namei_string_offs
5719 = extract_unsigned_integer ((name_table_string_offs_reordered
5720 + namei
* offset_size
),
5723 return read_indirect_string_at_offset
5724 (dwarf2_per_objfile
, dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
5727 /* Find a slot in .debug_names for the object named NAME. If NAME is
5728 found, return pointer to its pool data. If NAME cannot be found,
5732 dw2_debug_names_iterator::find_vec_in_debug_names
5733 (const mapped_debug_names
&map
, const char *name
)
5735 int (*cmp
) (const char *, const char *);
5737 if (current_language
->la_language
== language_cplus
5738 || current_language
->la_language
== language_fortran
5739 || current_language
->la_language
== language_d
)
5741 /* NAME is already canonical. Drop any qualifiers as
5742 .debug_names does not contain any. */
5744 if (strchr (name
, '(') != NULL
)
5746 gdb::unique_xmalloc_ptr
<char> without_params
5747 = cp_remove_params (name
);
5749 if (without_params
!= NULL
)
5751 name
= without_params
.get();
5756 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5758 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5760 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5761 (map
.bucket_table_reordered
5762 + (full_hash
% map
.bucket_count
)), 4,
5763 map
.dwarf5_byte_order
);
5767 if (namei
>= map
.name_count
)
5769 complaint (&symfile_complaints
,
5770 _("Wrong .debug_names with name index %u but name_count=%u "
5772 namei
, map
.name_count
,
5773 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5779 const uint32_t namei_full_hash
5780 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5781 (map
.hash_table_reordered
+ namei
), 4,
5782 map
.dwarf5_byte_order
);
5783 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5786 if (full_hash
== namei_full_hash
)
5788 const char *const namei_string
= map
.namei_to_name (namei
);
5790 #if 0 /* An expensive sanity check. */
5791 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5793 complaint (&symfile_complaints
,
5794 _("Wrong .debug_names hash for string at index %u "
5796 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5801 if (cmp (namei_string
, name
) == 0)
5803 const ULONGEST namei_entry_offs
5804 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5805 + namei
* map
.offset_size
),
5806 map
.offset_size
, map
.dwarf5_byte_order
);
5807 return map
.entry_pool
+ namei_entry_offs
;
5812 if (namei
>= map
.name_count
)
5818 dw2_debug_names_iterator::find_vec_in_debug_names
5819 (const mapped_debug_names
&map
, uint32_t namei
)
5821 if (namei
>= map
.name_count
)
5823 complaint (&symfile_complaints
,
5824 _("Wrong .debug_names with name index %u but name_count=%u "
5826 namei
, map
.name_count
,
5827 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5831 const ULONGEST namei_entry_offs
5832 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5833 + namei
* map
.offset_size
),
5834 map
.offset_size
, map
.dwarf5_byte_order
);
5835 return map
.entry_pool
+ namei_entry_offs
;
5838 /* See dw2_debug_names_iterator. */
5840 dwarf2_per_cu_data
*
5841 dw2_debug_names_iterator::next ()
5846 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5847 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5848 bfd
*const abfd
= objfile
->obfd
;
5852 unsigned int bytes_read
;
5853 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5854 m_addr
+= bytes_read
;
5858 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5859 if (indexval_it
== m_map
.abbrev_map
.cend ())
5861 complaint (&symfile_complaints
,
5862 _("Wrong .debug_names undefined abbrev code %s "
5864 pulongest (abbrev
), objfile_name (objfile
));
5867 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5868 bool have_is_static
= false;
5870 dwarf2_per_cu_data
*per_cu
= NULL
;
5871 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5876 case DW_FORM_implicit_const
:
5877 ull
= attr
.implicit_const
;
5879 case DW_FORM_flag_present
:
5883 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5884 m_addr
+= bytes_read
;
5887 complaint (&symfile_complaints
,
5888 _("Unsupported .debug_names form %s [in module %s]"),
5889 dwarf_form_name (attr
.form
),
5890 objfile_name (objfile
));
5893 switch (attr
.dw_idx
)
5895 case DW_IDX_compile_unit
:
5896 /* Don't crash on bad data. */
5897 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5899 complaint (&symfile_complaints
,
5900 _(".debug_names entry has bad CU index %s"
5903 objfile_name (dwarf2_per_objfile
->objfile
));
5906 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5908 case DW_IDX_type_unit
:
5909 /* Don't crash on bad data. */
5910 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5912 complaint (&symfile_complaints
,
5913 _(".debug_names entry has bad TU index %s"
5916 objfile_name (dwarf2_per_objfile
->objfile
));
5919 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5921 case DW_IDX_GNU_internal
:
5922 if (!m_map
.augmentation_is_gdb
)
5924 have_is_static
= true;
5927 case DW_IDX_GNU_external
:
5928 if (!m_map
.augmentation_is_gdb
)
5930 have_is_static
= true;
5936 /* Skip if already read in. */
5937 if (per_cu
->v
.quick
->compunit_symtab
)
5940 /* Check static vs global. */
5943 const bool want_static
= m_block_index
!= GLOBAL_BLOCK
;
5944 if (m_want_specific_block
&& want_static
!= is_static
)
5948 /* Match dw2_symtab_iter_next, symbol_kind
5949 and debug_names::psymbol_tag. */
5953 switch (indexval
.dwarf_tag
)
5955 case DW_TAG_variable
:
5956 case DW_TAG_subprogram
:
5957 /* Some types are also in VAR_DOMAIN. */
5958 case DW_TAG_typedef
:
5959 case DW_TAG_structure_type
:
5966 switch (indexval
.dwarf_tag
)
5968 case DW_TAG_typedef
:
5969 case DW_TAG_structure_type
:
5976 switch (indexval
.dwarf_tag
)
5979 case DW_TAG_variable
:
5989 /* Match dw2_expand_symtabs_matching, symbol_kind and
5990 debug_names::psymbol_tag. */
5993 case VARIABLES_DOMAIN
:
5994 switch (indexval
.dwarf_tag
)
5996 case DW_TAG_variable
:
6002 case FUNCTIONS_DOMAIN
:
6003 switch (indexval
.dwarf_tag
)
6005 case DW_TAG_subprogram
:
6012 switch (indexval
.dwarf_tag
)
6014 case DW_TAG_typedef
:
6015 case DW_TAG_structure_type
:
6028 static struct compunit_symtab
*
6029 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, int block_index_int
,
6030 const char *name
, domain_enum domain
)
6032 const block_enum block_index
= static_cast<block_enum
> (block_index_int
);
6033 struct dwarf2_per_objfile
*dwarf2_per_objfile
6034 = get_dwarf2_per_objfile (objfile
);
6036 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
6039 /* index is NULL if OBJF_READNOW. */
6042 const auto &map
= *mapp
;
6044 dw2_debug_names_iterator
iter (map
, true /* want_specific_block */,
6045 block_index
, domain
, name
);
6047 struct compunit_symtab
*stab_best
= NULL
;
6048 struct dwarf2_per_cu_data
*per_cu
;
6049 while ((per_cu
= iter
.next ()) != NULL
)
6051 struct symbol
*sym
, *with_opaque
= NULL
;
6052 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
);
6053 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
6054 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
6056 sym
= block_find_symbol (block
, name
, domain
,
6057 block_find_non_opaque_type_preferred
,
6060 /* Some caution must be observed with overloaded functions and
6061 methods, since the index will not contain any overload
6062 information (but NAME might contain it). */
6065 && strcmp_iw (SYMBOL_SEARCH_NAME (sym
), name
) == 0)
6067 if (with_opaque
!= NULL
6068 && strcmp_iw (SYMBOL_SEARCH_NAME (with_opaque
), name
) == 0)
6071 /* Keep looking through other CUs. */
6077 /* This dumps minimal information about .debug_names. It is called
6078 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
6079 uses this to verify that .debug_names has been loaded. */
6082 dw2_debug_names_dump (struct objfile
*objfile
)
6084 struct dwarf2_per_objfile
*dwarf2_per_objfile
6085 = get_dwarf2_per_objfile (objfile
);
6087 gdb_assert (dwarf2_per_objfile
->using_index
);
6088 printf_filtered (".debug_names:");
6089 if (dwarf2_per_objfile
->debug_names_table
)
6090 printf_filtered (" exists\n");
6092 printf_filtered (" faked for \"readnow\"\n");
6093 printf_filtered ("\n");
6097 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
6098 const char *func_name
)
6100 struct dwarf2_per_objfile
*dwarf2_per_objfile
6101 = get_dwarf2_per_objfile (objfile
);
6103 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
6104 if (dwarf2_per_objfile
->debug_names_table
)
6106 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6108 /* Note: It doesn't matter what we pass for block_index here. */
6109 dw2_debug_names_iterator
iter (map
, false /* want_specific_block */,
6110 GLOBAL_BLOCK
, VAR_DOMAIN
, func_name
);
6112 struct dwarf2_per_cu_data
*per_cu
;
6113 while ((per_cu
= iter
.next ()) != NULL
)
6114 dw2_instantiate_symtab (per_cu
);
6119 dw2_debug_names_expand_symtabs_matching
6120 (struct objfile
*objfile
,
6121 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
6122 const lookup_name_info
&lookup_name
,
6123 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
6124 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
6125 enum search_domain kind
)
6127 struct dwarf2_per_objfile
*dwarf2_per_objfile
6128 = get_dwarf2_per_objfile (objfile
);
6130 /* debug_names_table is NULL if OBJF_READNOW. */
6131 if (!dwarf2_per_objfile
->debug_names_table
)
6134 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
6136 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6138 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
6140 kind
, [&] (offset_type namei
)
6142 /* The name was matched, now expand corresponding CUs that were
6144 dw2_debug_names_iterator
iter (map
, kind
, namei
);
6146 struct dwarf2_per_cu_data
*per_cu
;
6147 while ((per_cu
= iter
.next ()) != NULL
)
6148 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
6153 const struct quick_symbol_functions dwarf2_debug_names_functions
=
6156 dw2_find_last_source_symtab
,
6157 dw2_forget_cached_source_info
,
6158 dw2_map_symtabs_matching_filename
,
6159 dw2_debug_names_lookup_symbol
,
6161 dw2_debug_names_dump
,
6163 dw2_debug_names_expand_symtabs_for_function
,
6164 dw2_expand_all_symtabs
,
6165 dw2_expand_symtabs_with_fullname
,
6166 dw2_map_matching_symbols
,
6167 dw2_debug_names_expand_symtabs_matching
,
6168 dw2_find_pc_sect_compunit_symtab
,
6170 dw2_map_symbol_filenames
6173 /* See symfile.h. */
6176 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
6178 struct dwarf2_per_objfile
*dwarf2_per_objfile
6179 = get_dwarf2_per_objfile (objfile
);
6181 /* If we're about to read full symbols, don't bother with the
6182 indices. In this case we also don't care if some other debug
6183 format is making psymtabs, because they are all about to be
6185 if ((objfile
->flags
& OBJF_READNOW
))
6187 dwarf2_per_objfile
->using_index
= 1;
6188 create_all_comp_units (dwarf2_per_objfile
);
6189 create_all_type_units (dwarf2_per_objfile
);
6190 dwarf2_per_objfile
->quick_file_names_table
6191 = create_quick_file_names_table
6192 (dwarf2_per_objfile
->all_comp_units
.size ());
6194 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
6195 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
6197 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
6199 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6200 struct dwarf2_per_cu_quick_data
);
6203 /* Return 1 so that gdb sees the "quick" functions. However,
6204 these functions will be no-ops because we will have expanded
6206 *index_kind
= dw_index_kind::GDB_INDEX
;
6210 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
6212 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6216 if (dwarf2_read_index (dwarf2_per_objfile
))
6218 *index_kind
= dw_index_kind::GDB_INDEX
;
6227 /* Build a partial symbol table. */
6230 dwarf2_build_psymtabs (struct objfile
*objfile
)
6232 struct dwarf2_per_objfile
*dwarf2_per_objfile
6233 = get_dwarf2_per_objfile (objfile
);
6235 if (objfile
->global_psymbols
.capacity () == 0
6236 && objfile
->static_psymbols
.capacity () == 0)
6237 init_psymbol_list (objfile
, 1024);
6241 /* This isn't really ideal: all the data we allocate on the
6242 objfile's obstack is still uselessly kept around. However,
6243 freeing it seems unsafe. */
6244 psymtab_discarder
psymtabs (objfile
);
6245 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
6248 CATCH (except
, RETURN_MASK_ERROR
)
6250 exception_print (gdb_stderr
, except
);
6255 /* Return the total length of the CU described by HEADER. */
6258 get_cu_length (const struct comp_unit_head
*header
)
6260 return header
->initial_length_size
+ header
->length
;
6263 /* Return TRUE if SECT_OFF is within CU_HEADER. */
6266 offset_in_cu_p (const comp_unit_head
*cu_header
, sect_offset sect_off
)
6268 sect_offset bottom
= cu_header
->sect_off
;
6269 sect_offset top
= cu_header
->sect_off
+ get_cu_length (cu_header
);
6271 return sect_off
>= bottom
&& sect_off
< top
;
6274 /* Find the base address of the compilation unit for range lists and
6275 location lists. It will normally be specified by DW_AT_low_pc.
6276 In DWARF-3 draft 4, the base address could be overridden by
6277 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6278 compilation units with discontinuous ranges. */
6281 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6283 struct attribute
*attr
;
6286 cu
->base_address
= 0;
6288 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6291 cu
->base_address
= attr_value_as_address (attr
);
6296 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6299 cu
->base_address
= attr_value_as_address (attr
);
6305 /* Read in the comp unit header information from the debug_info at info_ptr.
6306 Use rcuh_kind::COMPILE as the default type if not known by the caller.
6307 NOTE: This leaves members offset, first_die_offset to be filled in
6310 static const gdb_byte
*
6311 read_comp_unit_head (struct comp_unit_head
*cu_header
,
6312 const gdb_byte
*info_ptr
,
6313 struct dwarf2_section_info
*section
,
6314 rcuh_kind section_kind
)
6317 unsigned int bytes_read
;
6318 const char *filename
= get_section_file_name (section
);
6319 bfd
*abfd
= get_section_bfd_owner (section
);
6321 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
6322 cu_header
->initial_length_size
= bytes_read
;
6323 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
6324 info_ptr
+= bytes_read
;
6325 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
6327 if (cu_header
->version
< 5)
6328 switch (section_kind
)
6330 case rcuh_kind::COMPILE
:
6331 cu_header
->unit_type
= DW_UT_compile
;
6333 case rcuh_kind::TYPE
:
6334 cu_header
->unit_type
= DW_UT_type
;
6337 internal_error (__FILE__
, __LINE__
,
6338 _("read_comp_unit_head: invalid section_kind"));
6342 cu_header
->unit_type
= static_cast<enum dwarf_unit_type
>
6343 (read_1_byte (abfd
, info_ptr
));
6345 switch (cu_header
->unit_type
)
6348 if (section_kind
!= rcuh_kind::COMPILE
)
6349 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6350 "(is DW_UT_compile, should be DW_UT_type) [in module %s]"),
6354 section_kind
= rcuh_kind::TYPE
;
6357 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6358 "(is %d, should be %d or %d) [in module %s]"),
6359 cu_header
->unit_type
, DW_UT_compile
, DW_UT_type
, filename
);
6362 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6365 cu_header
->abbrev_sect_off
= (sect_offset
) read_offset (abfd
, info_ptr
,
6368 info_ptr
+= bytes_read
;
6369 if (cu_header
->version
< 5)
6371 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6374 signed_addr
= bfd_get_sign_extend_vma (abfd
);
6375 if (signed_addr
< 0)
6376 internal_error (__FILE__
, __LINE__
,
6377 _("read_comp_unit_head: dwarf from non elf file"));
6378 cu_header
->signed_addr_p
= signed_addr
;
6380 if (section_kind
== rcuh_kind::TYPE
)
6382 LONGEST type_offset
;
6384 cu_header
->signature
= read_8_bytes (abfd
, info_ptr
);
6387 type_offset
= read_offset (abfd
, info_ptr
, cu_header
, &bytes_read
);
6388 info_ptr
+= bytes_read
;
6389 cu_header
->type_cu_offset_in_tu
= (cu_offset
) type_offset
;
6390 if (to_underlying (cu_header
->type_cu_offset_in_tu
) != type_offset
)
6391 error (_("Dwarf Error: Too big type_offset in compilation unit "
6392 "header (is %s) [in module %s]"), plongest (type_offset
),
6399 /* Helper function that returns the proper abbrev section for
6402 static struct dwarf2_section_info
*
6403 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6405 struct dwarf2_section_info
*abbrev
;
6406 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6408 if (this_cu
->is_dwz
)
6409 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
6411 abbrev
= &dwarf2_per_objfile
->abbrev
;
6416 /* Subroutine of read_and_check_comp_unit_head and
6417 read_and_check_type_unit_head to simplify them.
6418 Perform various error checking on the header. */
6421 error_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6422 struct comp_unit_head
*header
,
6423 struct dwarf2_section_info
*section
,
6424 struct dwarf2_section_info
*abbrev_section
)
6426 const char *filename
= get_section_file_name (section
);
6428 if (header
->version
< 2 || header
->version
> 5)
6429 error (_("Dwarf Error: wrong version in compilation unit header "
6430 "(is %d, should be 2, 3, 4 or 5) [in module %s]"), header
->version
,
6433 if (to_underlying (header
->abbrev_sect_off
)
6434 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
6435 error (_("Dwarf Error: bad offset (%s) in compilation unit header "
6436 "(offset %s + 6) [in module %s]"),
6437 sect_offset_str (header
->abbrev_sect_off
),
6438 sect_offset_str (header
->sect_off
),
6441 /* Cast to ULONGEST to use 64-bit arithmetic when possible to
6442 avoid potential 32-bit overflow. */
6443 if (((ULONGEST
) header
->sect_off
+ get_cu_length (header
))
6445 error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
6446 "(offset %s + 0) [in module %s]"),
6447 header
->length
, sect_offset_str (header
->sect_off
),
6451 /* Read in a CU/TU header and perform some basic error checking.
6452 The contents of the header are stored in HEADER.
6453 The result is a pointer to the start of the first DIE. */
6455 static const gdb_byte
*
6456 read_and_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6457 struct comp_unit_head
*header
,
6458 struct dwarf2_section_info
*section
,
6459 struct dwarf2_section_info
*abbrev_section
,
6460 const gdb_byte
*info_ptr
,
6461 rcuh_kind section_kind
)
6463 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
6465 header
->sect_off
= (sect_offset
) (beg_of_comp_unit
- section
->buffer
);
6467 info_ptr
= read_comp_unit_head (header
, info_ptr
, section
, section_kind
);
6469 header
->first_die_cu_offset
= (cu_offset
) (info_ptr
- beg_of_comp_unit
);
6471 error_check_comp_unit_head (dwarf2_per_objfile
, header
, section
,
6477 /* Fetch the abbreviation table offset from a comp or type unit header. */
6480 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6481 struct dwarf2_section_info
*section
,
6482 sect_offset sect_off
)
6484 bfd
*abfd
= get_section_bfd_owner (section
);
6485 const gdb_byte
*info_ptr
;
6486 unsigned int initial_length_size
, offset_size
;
6489 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
6490 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6491 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6492 offset_size
= initial_length_size
== 4 ? 4 : 8;
6493 info_ptr
+= initial_length_size
;
6495 version
= read_2_bytes (abfd
, info_ptr
);
6499 /* Skip unit type and address size. */
6503 return (sect_offset
) read_offset_1 (abfd
, info_ptr
, offset_size
);
6506 /* Allocate a new partial symtab for file named NAME and mark this new
6507 partial symtab as being an include of PST. */
6510 dwarf2_create_include_psymtab (const char *name
, struct partial_symtab
*pst
,
6511 struct objfile
*objfile
)
6513 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
6515 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6517 /* It shares objfile->objfile_obstack. */
6518 subpst
->dirname
= pst
->dirname
;
6521 subpst
->textlow
= 0;
6522 subpst
->texthigh
= 0;
6524 subpst
->dependencies
6525 = XOBNEW (&objfile
->objfile_obstack
, struct partial_symtab
*);
6526 subpst
->dependencies
[0] = pst
;
6527 subpst
->number_of_dependencies
= 1;
6529 subpst
->globals_offset
= 0;
6530 subpst
->n_global_syms
= 0;
6531 subpst
->statics_offset
= 0;
6532 subpst
->n_static_syms
= 0;
6533 subpst
->compunit_symtab
= NULL
;
6534 subpst
->read_symtab
= pst
->read_symtab
;
6537 /* No private part is necessary for include psymtabs. This property
6538 can be used to differentiate between such include psymtabs and
6539 the regular ones. */
6540 subpst
->read_symtab_private
= NULL
;
6543 /* Read the Line Number Program data and extract the list of files
6544 included by the source file represented by PST. Build an include
6545 partial symtab for each of these included files. */
6548 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6549 struct die_info
*die
,
6550 struct partial_symtab
*pst
)
6553 struct attribute
*attr
;
6555 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6557 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6559 return; /* No linetable, so no includes. */
6561 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
6562 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
, pst
->textlow
, 1);
6566 hash_signatured_type (const void *item
)
6568 const struct signatured_type
*sig_type
6569 = (const struct signatured_type
*) item
;
6571 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6572 return sig_type
->signature
;
6576 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6578 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6579 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6581 return lhs
->signature
== rhs
->signature
;
6584 /* Allocate a hash table for signatured types. */
6587 allocate_signatured_type_table (struct objfile
*objfile
)
6589 return htab_create_alloc_ex (41,
6590 hash_signatured_type
,
6593 &objfile
->objfile_obstack
,
6594 hashtab_obstack_allocate
,
6595 dummy_obstack_deallocate
);
6598 /* A helper function to add a signatured type CU to a table. */
6601 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6603 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6604 std::vector
<signatured_type
*> *all_type_units
6605 = (std::vector
<signatured_type
*> *) datum
;
6607 all_type_units
->push_back (sigt
);
6612 /* A helper for create_debug_types_hash_table. Read types from SECTION
6613 and fill them into TYPES_HTAB. It will process only type units,
6614 therefore DW_UT_type. */
6617 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6618 struct dwo_file
*dwo_file
,
6619 dwarf2_section_info
*section
, htab_t
&types_htab
,
6620 rcuh_kind section_kind
)
6622 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6623 struct dwarf2_section_info
*abbrev_section
;
6625 const gdb_byte
*info_ptr
, *end_ptr
;
6627 abbrev_section
= (dwo_file
!= NULL
6628 ? &dwo_file
->sections
.abbrev
6629 : &dwarf2_per_objfile
->abbrev
);
6631 if (dwarf_read_debug
)
6632 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6633 get_section_name (section
),
6634 get_section_file_name (abbrev_section
));
6636 dwarf2_read_section (objfile
, section
);
6637 info_ptr
= section
->buffer
;
6639 if (info_ptr
== NULL
)
6642 /* We can't set abfd until now because the section may be empty or
6643 not present, in which case the bfd is unknown. */
6644 abfd
= get_section_bfd_owner (section
);
6646 /* We don't use init_cutu_and_read_dies_simple, or some such, here
6647 because we don't need to read any dies: the signature is in the
6650 end_ptr
= info_ptr
+ section
->size
;
6651 while (info_ptr
< end_ptr
)
6653 struct signatured_type
*sig_type
;
6654 struct dwo_unit
*dwo_tu
;
6656 const gdb_byte
*ptr
= info_ptr
;
6657 struct comp_unit_head header
;
6658 unsigned int length
;
6660 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6662 /* Initialize it due to a false compiler warning. */
6663 header
.signature
= -1;
6664 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6666 /* We need to read the type's signature in order to build the hash
6667 table, but we don't need anything else just yet. */
6669 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6670 abbrev_section
, ptr
, section_kind
);
6672 length
= get_cu_length (&header
);
6674 /* Skip dummy type units. */
6675 if (ptr
>= info_ptr
+ length
6676 || peek_abbrev_code (abfd
, ptr
) == 0
6677 || header
.unit_type
!= DW_UT_type
)
6683 if (types_htab
== NULL
)
6686 types_htab
= allocate_dwo_unit_table (objfile
);
6688 types_htab
= allocate_signatured_type_table (objfile
);
6694 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6696 dwo_tu
->dwo_file
= dwo_file
;
6697 dwo_tu
->signature
= header
.signature
;
6698 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6699 dwo_tu
->section
= section
;
6700 dwo_tu
->sect_off
= sect_off
;
6701 dwo_tu
->length
= length
;
6705 /* N.B.: type_offset is not usable if this type uses a DWO file.
6706 The real type_offset is in the DWO file. */
6708 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6709 struct signatured_type
);
6710 sig_type
->signature
= header
.signature
;
6711 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6712 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6713 sig_type
->per_cu
.is_debug_types
= 1;
6714 sig_type
->per_cu
.section
= section
;
6715 sig_type
->per_cu
.sect_off
= sect_off
;
6716 sig_type
->per_cu
.length
= length
;
6719 slot
= htab_find_slot (types_htab
,
6720 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6722 gdb_assert (slot
!= NULL
);
6725 sect_offset dup_sect_off
;
6729 const struct dwo_unit
*dup_tu
6730 = (const struct dwo_unit
*) *slot
;
6732 dup_sect_off
= dup_tu
->sect_off
;
6736 const struct signatured_type
*dup_tu
6737 = (const struct signatured_type
*) *slot
;
6739 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6742 complaint (&symfile_complaints
,
6743 _("debug type entry at offset %s is duplicate to"
6744 " the entry at offset %s, signature %s"),
6745 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6746 hex_string (header
.signature
));
6748 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6750 if (dwarf_read_debug
> 1)
6751 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6752 sect_offset_str (sect_off
),
6753 hex_string (header
.signature
));
6759 /* Create the hash table of all entries in the .debug_types
6760 (or .debug_types.dwo) section(s).
6761 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6762 otherwise it is NULL.
6764 The result is a pointer to the hash table or NULL if there are no types.
6766 Note: This function processes DWO files only, not DWP files. */
6769 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6770 struct dwo_file
*dwo_file
,
6771 VEC (dwarf2_section_info_def
) *types
,
6775 struct dwarf2_section_info
*section
;
6777 if (VEC_empty (dwarf2_section_info_def
, types
))
6781 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
6783 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, section
,
6784 types_htab
, rcuh_kind::TYPE
);
6787 /* Create the hash table of all entries in the .debug_types section,
6788 and initialize all_type_units.
6789 The result is zero if there is an error (e.g. missing .debug_types section),
6790 otherwise non-zero. */
6793 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6795 htab_t types_htab
= NULL
;
6797 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6798 &dwarf2_per_objfile
->info
, types_htab
,
6799 rcuh_kind::COMPILE
);
6800 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6801 dwarf2_per_objfile
->types
, types_htab
);
6802 if (types_htab
== NULL
)
6804 dwarf2_per_objfile
->signatured_types
= NULL
;
6808 dwarf2_per_objfile
->signatured_types
= types_htab
;
6810 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6811 dwarf2_per_objfile
->all_type_units
.reserve (htab_elements (types_htab
));
6813 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
,
6814 &dwarf2_per_objfile
->all_type_units
);
6819 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6820 If SLOT is non-NULL, it is the entry to use in the hash table.
6821 Otherwise we find one. */
6823 static struct signatured_type
*
6824 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6827 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6829 if (dwarf2_per_objfile
->all_type_units
.size ()
6830 == dwarf2_per_objfile
->all_type_units
.capacity ())
6831 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6833 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6834 struct signatured_type
);
6836 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6837 sig_type
->signature
= sig
;
6838 sig_type
->per_cu
.is_debug_types
= 1;
6839 if (dwarf2_per_objfile
->using_index
)
6841 sig_type
->per_cu
.v
.quick
=
6842 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6843 struct dwarf2_per_cu_quick_data
);
6848 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
6851 gdb_assert (*slot
== NULL
);
6853 /* The rest of sig_type must be filled in by the caller. */
6857 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6858 Fill in SIG_ENTRY with DWO_ENTRY. */
6861 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6862 struct signatured_type
*sig_entry
,
6863 struct dwo_unit
*dwo_entry
)
6865 /* Make sure we're not clobbering something we don't expect to. */
6866 gdb_assert (! sig_entry
->per_cu
.queued
);
6867 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6868 if (dwarf2_per_objfile
->using_index
)
6870 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6871 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
6874 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6875 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6876 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6877 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6878 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6880 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6881 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6882 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6883 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6884 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6885 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6886 sig_entry
->dwo_unit
= dwo_entry
;
6889 /* Subroutine of lookup_signatured_type.
6890 If we haven't read the TU yet, create the signatured_type data structure
6891 for a TU to be read in directly from a DWO file, bypassing the stub.
6892 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6893 using .gdb_index, then when reading a CU we want to stay in the DWO file
6894 containing that CU. Otherwise we could end up reading several other DWO
6895 files (due to comdat folding) to process the transitive closure of all the
6896 mentioned TUs, and that can be slow. The current DWO file will have every
6897 type signature that it needs.
6898 We only do this for .gdb_index because in the psymtab case we already have
6899 to read all the DWOs to build the type unit groups. */
6901 static struct signatured_type
*
6902 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6904 struct dwarf2_per_objfile
*dwarf2_per_objfile
6905 = cu
->per_cu
->dwarf2_per_objfile
;
6906 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6907 struct dwo_file
*dwo_file
;
6908 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6909 struct signatured_type find_sig_entry
, *sig_entry
;
6912 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6914 /* If TU skeletons have been removed then we may not have read in any
6916 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6918 dwarf2_per_objfile
->signatured_types
6919 = allocate_signatured_type_table (objfile
);
6922 /* We only ever need to read in one copy of a signatured type.
6923 Use the global signatured_types array to do our own comdat-folding
6924 of types. If this is the first time we're reading this TU, and
6925 the TU has an entry in .gdb_index, replace the recorded data from
6926 .gdb_index with this TU. */
6928 find_sig_entry
.signature
= sig
;
6929 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
6930 &find_sig_entry
, INSERT
);
6931 sig_entry
= (struct signatured_type
*) *slot
;
6933 /* We can get here with the TU already read, *or* in the process of being
6934 read. Don't reassign the global entry to point to this DWO if that's
6935 the case. Also note that if the TU is already being read, it may not
6936 have come from a DWO, the program may be a mix of Fission-compiled
6937 code and non-Fission-compiled code. */
6939 /* Have we already tried to read this TU?
6940 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6941 needn't exist in the global table yet). */
6942 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6945 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6946 dwo_unit of the TU itself. */
6947 dwo_file
= cu
->dwo_unit
->dwo_file
;
6949 /* Ok, this is the first time we're reading this TU. */
6950 if (dwo_file
->tus
== NULL
)
6952 find_dwo_entry
.signature
= sig
;
6953 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_entry
);
6954 if (dwo_entry
== NULL
)
6957 /* If the global table doesn't have an entry for this TU, add one. */
6958 if (sig_entry
== NULL
)
6959 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6961 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6962 sig_entry
->per_cu
.tu_read
= 1;
6966 /* Subroutine of lookup_signatured_type.
6967 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6968 then try the DWP file. If the TU stub (skeleton) has been removed then
6969 it won't be in .gdb_index. */
6971 static struct signatured_type
*
6972 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6974 struct dwarf2_per_objfile
*dwarf2_per_objfile
6975 = cu
->per_cu
->dwarf2_per_objfile
;
6976 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6977 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
6978 struct dwo_unit
*dwo_entry
;
6979 struct signatured_type find_sig_entry
, *sig_entry
;
6982 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6983 gdb_assert (dwp_file
!= NULL
);
6985 /* If TU skeletons have been removed then we may not have read in any
6987 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6989 dwarf2_per_objfile
->signatured_types
6990 = allocate_signatured_type_table (objfile
);
6993 find_sig_entry
.signature
= sig
;
6994 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
6995 &find_sig_entry
, INSERT
);
6996 sig_entry
= (struct signatured_type
*) *slot
;
6998 /* Have we already tried to read this TU?
6999 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7000 needn't exist in the global table yet). */
7001 if (sig_entry
!= NULL
)
7004 if (dwp_file
->tus
== NULL
)
7006 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
7007 sig
, 1 /* is_debug_types */);
7008 if (dwo_entry
== NULL
)
7011 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7012 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7017 /* Lookup a signature based type for DW_FORM_ref_sig8.
7018 Returns NULL if signature SIG is not present in the table.
7019 It is up to the caller to complain about this. */
7021 static struct signatured_type
*
7022 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7024 struct dwarf2_per_objfile
*dwarf2_per_objfile
7025 = cu
->per_cu
->dwarf2_per_objfile
;
7028 && dwarf2_per_objfile
->using_index
)
7030 /* We're in a DWO/DWP file, and we're using .gdb_index.
7031 These cases require special processing. */
7032 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
7033 return lookup_dwo_signatured_type (cu
, sig
);
7035 return lookup_dwp_signatured_type (cu
, sig
);
7039 struct signatured_type find_entry
, *entry
;
7041 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7043 find_entry
.signature
= sig
;
7044 entry
= ((struct signatured_type
*)
7045 htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
));
7050 /* Low level DIE reading support. */
7052 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
7055 init_cu_die_reader (struct die_reader_specs
*reader
,
7056 struct dwarf2_cu
*cu
,
7057 struct dwarf2_section_info
*section
,
7058 struct dwo_file
*dwo_file
,
7059 struct abbrev_table
*abbrev_table
)
7061 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
7062 reader
->abfd
= get_section_bfd_owner (section
);
7064 reader
->dwo_file
= dwo_file
;
7065 reader
->die_section
= section
;
7066 reader
->buffer
= section
->buffer
;
7067 reader
->buffer_end
= section
->buffer
+ section
->size
;
7068 reader
->comp_dir
= NULL
;
7069 reader
->abbrev_table
= abbrev_table
;
7072 /* Subroutine of init_cutu_and_read_dies to simplify it.
7073 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
7074 There's just a lot of work to do, and init_cutu_and_read_dies is big enough
7077 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
7078 from it to the DIE in the DWO. If NULL we are skipping the stub.
7079 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
7080 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
7081 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
7082 STUB_COMP_DIR may be non-NULL.
7083 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
7084 are filled in with the info of the DIE from the DWO file.
7085 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
7086 from the dwo. Since *RESULT_READER references this abbrev table, it must be
7087 kept around for at least as long as *RESULT_READER.
7089 The result is non-zero if a valid (non-dummy) DIE was found. */
7092 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
7093 struct dwo_unit
*dwo_unit
,
7094 struct die_info
*stub_comp_unit_die
,
7095 const char *stub_comp_dir
,
7096 struct die_reader_specs
*result_reader
,
7097 const gdb_byte
**result_info_ptr
,
7098 struct die_info
**result_comp_unit_die
,
7099 int *result_has_children
,
7100 abbrev_table_up
*result_dwo_abbrev_table
)
7102 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7103 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7104 struct dwarf2_cu
*cu
= this_cu
->cu
;
7106 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7107 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
7108 int i
,num_extra_attrs
;
7109 struct dwarf2_section_info
*dwo_abbrev_section
;
7110 struct attribute
*attr
;
7111 struct die_info
*comp_unit_die
;
7113 /* At most one of these may be provided. */
7114 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
7116 /* These attributes aren't processed until later:
7117 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
7118 DW_AT_comp_dir is used now, to find the DWO file, but it is also
7119 referenced later. However, these attributes are found in the stub
7120 which we won't have later. In order to not impose this complication
7121 on the rest of the code, we read them here and copy them to the
7130 if (stub_comp_unit_die
!= NULL
)
7132 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
7134 if (! this_cu
->is_debug_types
)
7135 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
7136 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
7137 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
7138 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
7139 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
7141 /* There should be a DW_AT_addr_base attribute here (if needed).
7142 We need the value before we can process DW_FORM_GNU_addr_index. */
7144 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
7146 cu
->addr_base
= DW_UNSND (attr
);
7148 /* There should be a DW_AT_ranges_base attribute here (if needed).
7149 We need the value before we can process DW_AT_ranges. */
7150 cu
->ranges_base
= 0;
7151 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
7153 cu
->ranges_base
= DW_UNSND (attr
);
7155 else if (stub_comp_dir
!= NULL
)
7157 /* Reconstruct the comp_dir attribute to simplify the code below. */
7158 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
7159 comp_dir
->name
= DW_AT_comp_dir
;
7160 comp_dir
->form
= DW_FORM_string
;
7161 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
7162 DW_STRING (comp_dir
) = stub_comp_dir
;
7165 /* Set up for reading the DWO CU/TU. */
7166 cu
->dwo_unit
= dwo_unit
;
7167 dwarf2_section_info
*section
= dwo_unit
->section
;
7168 dwarf2_read_section (objfile
, section
);
7169 abfd
= get_section_bfd_owner (section
);
7170 begin_info_ptr
= info_ptr
= (section
->buffer
7171 + to_underlying (dwo_unit
->sect_off
));
7172 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
7174 if (this_cu
->is_debug_types
)
7176 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
7178 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7179 &cu
->header
, section
,
7181 info_ptr
, rcuh_kind::TYPE
);
7182 /* This is not an assert because it can be caused by bad debug info. */
7183 if (sig_type
->signature
!= cu
->header
.signature
)
7185 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
7186 " TU at offset %s [in module %s]"),
7187 hex_string (sig_type
->signature
),
7188 hex_string (cu
->header
.signature
),
7189 sect_offset_str (dwo_unit
->sect_off
),
7190 bfd_get_filename (abfd
));
7192 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7193 /* For DWOs coming from DWP files, we don't know the CU length
7194 nor the type's offset in the TU until now. */
7195 dwo_unit
->length
= get_cu_length (&cu
->header
);
7196 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
7198 /* Establish the type offset that can be used to lookup the type.
7199 For DWO files, we don't know it until now. */
7200 sig_type
->type_offset_in_section
7201 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
7205 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7206 &cu
->header
, section
,
7208 info_ptr
, rcuh_kind::COMPILE
);
7209 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7210 /* For DWOs coming from DWP files, we don't know the CU length
7212 dwo_unit
->length
= get_cu_length (&cu
->header
);
7215 *result_dwo_abbrev_table
7216 = abbrev_table_read_table (dwarf2_per_objfile
, dwo_abbrev_section
,
7217 cu
->header
.abbrev_sect_off
);
7218 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
7219 result_dwo_abbrev_table
->get ());
7221 /* Read in the die, but leave space to copy over the attributes
7222 from the stub. This has the benefit of simplifying the rest of
7223 the code - all the work to maintain the illusion of a single
7224 DW_TAG_{compile,type}_unit DIE is done here. */
7225 num_extra_attrs
= ((stmt_list
!= NULL
)
7229 + (comp_dir
!= NULL
));
7230 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
7231 result_has_children
, num_extra_attrs
);
7233 /* Copy over the attributes from the stub to the DIE we just read in. */
7234 comp_unit_die
= *result_comp_unit_die
;
7235 i
= comp_unit_die
->num_attrs
;
7236 if (stmt_list
!= NULL
)
7237 comp_unit_die
->attrs
[i
++] = *stmt_list
;
7239 comp_unit_die
->attrs
[i
++] = *low_pc
;
7240 if (high_pc
!= NULL
)
7241 comp_unit_die
->attrs
[i
++] = *high_pc
;
7243 comp_unit_die
->attrs
[i
++] = *ranges
;
7244 if (comp_dir
!= NULL
)
7245 comp_unit_die
->attrs
[i
++] = *comp_dir
;
7246 comp_unit_die
->num_attrs
+= num_extra_attrs
;
7248 if (dwarf_die_debug
)
7250 fprintf_unfiltered (gdb_stdlog
,
7251 "Read die from %s@0x%x of %s:\n",
7252 get_section_name (section
),
7253 (unsigned) (begin_info_ptr
- section
->buffer
),
7254 bfd_get_filename (abfd
));
7255 dump_die (comp_unit_die
, dwarf_die_debug
);
7258 /* Save the comp_dir attribute. If there is no DWP file then we'll read
7259 TUs by skipping the stub and going directly to the entry in the DWO file.
7260 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
7261 to get it via circuitous means. Blech. */
7262 if (comp_dir
!= NULL
)
7263 result_reader
->comp_dir
= DW_STRING (comp_dir
);
7265 /* Skip dummy compilation units. */
7266 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
7267 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7270 *result_info_ptr
= info_ptr
;
7274 /* Subroutine of init_cutu_and_read_dies to simplify it.
7275 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
7276 Returns NULL if the specified DWO unit cannot be found. */
7278 static struct dwo_unit
*
7279 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
7280 struct die_info
*comp_unit_die
)
7282 struct dwarf2_cu
*cu
= this_cu
->cu
;
7284 struct dwo_unit
*dwo_unit
;
7285 const char *comp_dir
, *dwo_name
;
7287 gdb_assert (cu
!= NULL
);
7289 /* Yeah, we look dwo_name up again, but it simplifies the code. */
7290 dwo_name
= dwarf2_string_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
7291 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7293 if (this_cu
->is_debug_types
)
7295 struct signatured_type
*sig_type
;
7297 /* Since this_cu is the first member of struct signatured_type,
7298 we can go from a pointer to one to a pointer to the other. */
7299 sig_type
= (struct signatured_type
*) this_cu
;
7300 signature
= sig_type
->signature
;
7301 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
7305 struct attribute
*attr
;
7307 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7309 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
7311 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
7312 signature
= DW_UNSND (attr
);
7313 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
7320 /* Subroutine of init_cutu_and_read_dies to simplify it.
7321 See it for a description of the parameters.
7322 Read a TU directly from a DWO file, bypassing the stub. */
7325 init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
7326 int use_existing_cu
, int keep
,
7327 die_reader_func_ftype
*die_reader_func
,
7330 std::unique_ptr
<dwarf2_cu
> new_cu
;
7331 struct signatured_type
*sig_type
;
7332 struct die_reader_specs reader
;
7333 const gdb_byte
*info_ptr
;
7334 struct die_info
*comp_unit_die
;
7336 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7338 /* Verify we can do the following downcast, and that we have the
7340 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7341 sig_type
= (struct signatured_type
*) this_cu
;
7342 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7344 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7346 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
7347 /* There's no need to do the rereading_dwo_cu handling that
7348 init_cutu_and_read_dies does since we don't read the stub. */
7352 /* If !use_existing_cu, this_cu->cu must be NULL. */
7353 gdb_assert (this_cu
->cu
== NULL
);
7354 new_cu
.reset (new dwarf2_cu (this_cu
));
7357 /* A future optimization, if needed, would be to use an existing
7358 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7359 could share abbrev tables. */
7361 /* The abbreviation table used by READER, this must live at least as long as
7363 abbrev_table_up dwo_abbrev_table
;
7365 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
7366 NULL
/* stub_comp_unit_die */,
7367 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7369 &comp_unit_die
, &has_children
,
7370 &dwo_abbrev_table
) == 0)
7376 /* All the "real" work is done here. */
7377 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7379 /* This duplicates the code in init_cutu_and_read_dies,
7380 but the alternative is making the latter more complex.
7381 This function is only for the special case of using DWO files directly:
7382 no point in overly complicating the general case just to handle this. */
7383 if (new_cu
!= NULL
&& keep
)
7385 /* Link this CU into read_in_chain. */
7386 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7387 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7388 /* The chain owns it now. */
7393 /* Initialize a CU (or TU) and read its DIEs.
7394 If the CU defers to a DWO file, read the DWO file as well.
7396 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7397 Otherwise the table specified in the comp unit header is read in and used.
7398 This is an optimization for when we already have the abbrev table.
7400 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
7401 Otherwise, a new CU is allocated with xmalloc.
7403 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
7404 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
7406 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7407 linker) then DIE_READER_FUNC will not get called. */
7410 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
7411 struct abbrev_table
*abbrev_table
,
7412 int use_existing_cu
, int keep
,
7413 die_reader_func_ftype
*die_reader_func
,
7416 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7417 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7418 struct dwarf2_section_info
*section
= this_cu
->section
;
7419 bfd
*abfd
= get_section_bfd_owner (section
);
7420 struct dwarf2_cu
*cu
;
7421 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7422 struct die_reader_specs reader
;
7423 struct die_info
*comp_unit_die
;
7425 struct attribute
*attr
;
7426 struct signatured_type
*sig_type
= NULL
;
7427 struct dwarf2_section_info
*abbrev_section
;
7428 /* Non-zero if CU currently points to a DWO file and we need to
7429 reread it. When this happens we need to reread the skeleton die
7430 before we can reread the DWO file (this only applies to CUs, not TUs). */
7431 int rereading_dwo_cu
= 0;
7433 if (dwarf_die_debug
)
7434 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7435 this_cu
->is_debug_types
? "type" : "comp",
7436 sect_offset_str (this_cu
->sect_off
));
7438 if (use_existing_cu
)
7441 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7442 file (instead of going through the stub), short-circuit all of this. */
7443 if (this_cu
->reading_dwo_directly
)
7445 /* Narrow down the scope of possibilities to have to understand. */
7446 gdb_assert (this_cu
->is_debug_types
);
7447 gdb_assert (abbrev_table
== NULL
);
7448 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
,
7449 die_reader_func
, data
);
7453 /* This is cheap if the section is already read in. */
7454 dwarf2_read_section (objfile
, section
);
7456 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7458 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7460 std::unique_ptr
<dwarf2_cu
> new_cu
;
7461 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7464 /* If this CU is from a DWO file we need to start over, we need to
7465 refetch the attributes from the skeleton CU.
7466 This could be optimized by retrieving those attributes from when we
7467 were here the first time: the previous comp_unit_die was stored in
7468 comp_unit_obstack. But there's no data yet that we need this
7470 if (cu
->dwo_unit
!= NULL
)
7471 rereading_dwo_cu
= 1;
7475 /* If !use_existing_cu, this_cu->cu must be NULL. */
7476 gdb_assert (this_cu
->cu
== NULL
);
7477 new_cu
.reset (new dwarf2_cu (this_cu
));
7481 /* Get the header. */
7482 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7484 /* We already have the header, there's no need to read it in again. */
7485 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7489 if (this_cu
->is_debug_types
)
7491 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7492 &cu
->header
, section
,
7493 abbrev_section
, info_ptr
,
7496 /* Since per_cu is the first member of struct signatured_type,
7497 we can go from a pointer to one to a pointer to the other. */
7498 sig_type
= (struct signatured_type
*) this_cu
;
7499 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7500 gdb_assert (sig_type
->type_offset_in_tu
7501 == cu
->header
.type_cu_offset_in_tu
);
7502 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7504 /* LENGTH has not been set yet for type units if we're
7505 using .gdb_index. */
7506 this_cu
->length
= get_cu_length (&cu
->header
);
7508 /* Establish the type offset that can be used to lookup the type. */
7509 sig_type
->type_offset_in_section
=
7510 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7512 this_cu
->dwarf_version
= cu
->header
.version
;
7516 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7517 &cu
->header
, section
,
7520 rcuh_kind::COMPILE
);
7522 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7523 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
7524 this_cu
->dwarf_version
= cu
->header
.version
;
7528 /* Skip dummy compilation units. */
7529 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7530 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7533 /* If we don't have them yet, read the abbrevs for this compilation unit.
7534 And if we need to read them now, make sure they're freed when we're
7535 done (own the table through ABBREV_TABLE_HOLDER). */
7536 abbrev_table_up abbrev_table_holder
;
7537 if (abbrev_table
!= NULL
)
7538 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7542 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7543 cu
->header
.abbrev_sect_off
);
7544 abbrev_table
= abbrev_table_holder
.get ();
7547 /* Read the top level CU/TU die. */
7548 init_cu_die_reader (&reader
, cu
, section
, NULL
, abbrev_table
);
7549 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
7551 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7552 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7553 table from the DWO file and pass the ownership over to us. It will be
7554 referenced from READER, so we must make sure to free it after we're done
7557 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7558 DWO CU, that this test will fail (the attribute will not be present). */
7559 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
7560 abbrev_table_up dwo_abbrev_table
;
7563 struct dwo_unit
*dwo_unit
;
7564 struct die_info
*dwo_comp_unit_die
;
7568 complaint (&symfile_complaints
,
7569 _("compilation unit with DW_AT_GNU_dwo_name"
7570 " has children (offset %s) [in module %s]"),
7571 sect_offset_str (this_cu
->sect_off
),
7572 bfd_get_filename (abfd
));
7574 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
);
7575 if (dwo_unit
!= NULL
)
7577 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
7578 comp_unit_die
, NULL
,
7580 &dwo_comp_unit_die
, &has_children
,
7581 &dwo_abbrev_table
) == 0)
7586 comp_unit_die
= dwo_comp_unit_die
;
7590 /* Yikes, we couldn't find the rest of the DIE, we only have
7591 the stub. A complaint has already been logged. There's
7592 not much more we can do except pass on the stub DIE to
7593 die_reader_func. We don't want to throw an error on bad
7598 /* All of the above is setup for this call. Yikes. */
7599 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7601 /* Done, clean up. */
7602 if (new_cu
!= NULL
&& keep
)
7604 /* Link this CU into read_in_chain. */
7605 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7606 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7607 /* The chain owns it now. */
7612 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name if present.
7613 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed
7614 to have already done the lookup to find the DWO file).
7616 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7617 THIS_CU->is_debug_types, but nothing else.
7619 We fill in THIS_CU->length.
7621 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7622 linker) then DIE_READER_FUNC will not get called.
7624 THIS_CU->cu is always freed when done.
7625 This is done in order to not leave THIS_CU->cu in a state where we have
7626 to care whether it refers to the "main" CU or the DWO CU. */
7629 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
7630 struct dwo_file
*dwo_file
,
7631 die_reader_func_ftype
*die_reader_func
,
7634 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7635 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7636 struct dwarf2_section_info
*section
= this_cu
->section
;
7637 bfd
*abfd
= get_section_bfd_owner (section
);
7638 struct dwarf2_section_info
*abbrev_section
;
7639 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7640 struct die_reader_specs reader
;
7641 struct die_info
*comp_unit_die
;
7644 if (dwarf_die_debug
)
7645 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7646 this_cu
->is_debug_types
? "type" : "comp",
7647 sect_offset_str (this_cu
->sect_off
));
7649 gdb_assert (this_cu
->cu
== NULL
);
7651 abbrev_section
= (dwo_file
!= NULL
7652 ? &dwo_file
->sections
.abbrev
7653 : get_abbrev_section_for_cu (this_cu
));
7655 /* This is cheap if the section is already read in. */
7656 dwarf2_read_section (objfile
, section
);
7658 struct dwarf2_cu
cu (this_cu
);
7660 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7661 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7662 &cu
.header
, section
,
7663 abbrev_section
, info_ptr
,
7664 (this_cu
->is_debug_types
7666 : rcuh_kind::COMPILE
));
7668 this_cu
->length
= get_cu_length (&cu
.header
);
7670 /* Skip dummy compilation units. */
7671 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7672 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7675 abbrev_table_up abbrev_table
7676 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7677 cu
.header
.abbrev_sect_off
);
7679 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
, abbrev_table
.get ());
7680 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
7682 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7685 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
7686 does not lookup the specified DWO file.
7687 This cannot be used to read DWO files.
7689 THIS_CU->cu is always freed when done.
7690 This is done in order to not leave THIS_CU->cu in a state where we have
7691 to care whether it refers to the "main" CU or the DWO CU.
7692 We can revisit this if the data shows there's a performance issue. */
7695 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
7696 die_reader_func_ftype
*die_reader_func
,
7699 init_cutu_and_read_dies_no_follow (this_cu
, NULL
, die_reader_func
, data
);
7702 /* Type Unit Groups.
7704 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7705 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7706 so that all types coming from the same compilation (.o file) are grouped
7707 together. A future step could be to put the types in the same symtab as
7708 the CU the types ultimately came from. */
7711 hash_type_unit_group (const void *item
)
7713 const struct type_unit_group
*tu_group
7714 = (const struct type_unit_group
*) item
;
7716 return hash_stmt_list_entry (&tu_group
->hash
);
7720 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7722 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7723 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7725 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7728 /* Allocate a hash table for type unit groups. */
7731 allocate_type_unit_groups_table (struct objfile
*objfile
)
7733 return htab_create_alloc_ex (3,
7734 hash_type_unit_group
,
7737 &objfile
->objfile_obstack
,
7738 hashtab_obstack_allocate
,
7739 dummy_obstack_deallocate
);
7742 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7743 partial symtabs. We combine several TUs per psymtab to not let the size
7744 of any one psymtab grow too big. */
7745 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7746 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7748 /* Helper routine for get_type_unit_group.
7749 Create the type_unit_group object used to hold one or more TUs. */
7751 static struct type_unit_group
*
7752 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7754 struct dwarf2_per_objfile
*dwarf2_per_objfile
7755 = cu
->per_cu
->dwarf2_per_objfile
;
7756 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7757 struct dwarf2_per_cu_data
*per_cu
;
7758 struct type_unit_group
*tu_group
;
7760 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7761 struct type_unit_group
);
7762 per_cu
= &tu_group
->per_cu
;
7763 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7765 if (dwarf2_per_objfile
->using_index
)
7767 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7768 struct dwarf2_per_cu_quick_data
);
7772 unsigned int line_offset
= to_underlying (line_offset_struct
);
7773 struct partial_symtab
*pst
;
7776 /* Give the symtab a useful name for debug purposes. */
7777 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7778 name
= xstrprintf ("<type_units_%d>",
7779 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7781 name
= xstrprintf ("<type_units_at_0x%x>", line_offset
);
7783 pst
= create_partial_symtab (per_cu
, name
);
7789 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7790 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7795 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7796 STMT_LIST is a DW_AT_stmt_list attribute. */
7798 static struct type_unit_group
*
7799 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7801 struct dwarf2_per_objfile
*dwarf2_per_objfile
7802 = cu
->per_cu
->dwarf2_per_objfile
;
7803 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7804 struct type_unit_group
*tu_group
;
7806 unsigned int line_offset
;
7807 struct type_unit_group type_unit_group_for_lookup
;
7809 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7811 dwarf2_per_objfile
->type_unit_groups
=
7812 allocate_type_unit_groups_table (dwarf2_per_objfile
->objfile
);
7815 /* Do we need to create a new group, or can we use an existing one? */
7819 line_offset
= DW_UNSND (stmt_list
);
7820 ++tu_stats
->nr_symtab_sharers
;
7824 /* Ugh, no stmt_list. Rare, but we have to handle it.
7825 We can do various things here like create one group per TU or
7826 spread them over multiple groups to split up the expansion work.
7827 To avoid worst case scenarios (too many groups or too large groups)
7828 we, umm, group them in bunches. */
7829 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7830 | (tu_stats
->nr_stmt_less_type_units
7831 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7832 ++tu_stats
->nr_stmt_less_type_units
;
7835 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7836 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7837 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
7838 &type_unit_group_for_lookup
, INSERT
);
7841 tu_group
= (struct type_unit_group
*) *slot
;
7842 gdb_assert (tu_group
!= NULL
);
7846 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7847 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7849 ++tu_stats
->nr_symtabs
;
7855 /* Partial symbol tables. */
7857 /* Create a psymtab named NAME and assign it to PER_CU.
7859 The caller must fill in the following details:
7860 dirname, textlow, texthigh. */
7862 static struct partial_symtab
*
7863 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
7865 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
7866 struct partial_symtab
*pst
;
7868 pst
= start_psymtab_common (objfile
, name
, 0,
7869 objfile
->global_psymbols
,
7870 objfile
->static_psymbols
);
7872 pst
->psymtabs_addrmap_supported
= 1;
7874 /* This is the glue that links PST into GDB's symbol API. */
7875 pst
->read_symtab_private
= per_cu
;
7876 pst
->read_symtab
= dwarf2_read_symtab
;
7877 per_cu
->v
.psymtab
= pst
;
7882 /* The DATA object passed to process_psymtab_comp_unit_reader has this
7885 struct process_psymtab_comp_unit_data
7887 /* True if we are reading a DW_TAG_partial_unit. */
7889 int want_partial_unit
;
7891 /* The "pretend" language that is used if the CU doesn't declare a
7894 enum language pretend_language
;
7897 /* die_reader_func for process_psymtab_comp_unit. */
7900 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7901 const gdb_byte
*info_ptr
,
7902 struct die_info
*comp_unit_die
,
7906 struct dwarf2_cu
*cu
= reader
->cu
;
7907 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
7908 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7909 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7911 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7912 struct partial_symtab
*pst
;
7913 enum pc_bounds_kind cu_bounds_kind
;
7914 const char *filename
;
7915 struct process_psymtab_comp_unit_data
*info
7916 = (struct process_psymtab_comp_unit_data
*) data
;
7918 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !info
->want_partial_unit
)
7921 gdb_assert (! per_cu
->is_debug_types
);
7923 prepare_one_comp_unit (cu
, comp_unit_die
, info
->pretend_language
);
7925 cu
->list_in_scope
= &file_symbols
;
7927 /* Allocate a new partial symbol table structure. */
7928 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7929 if (filename
== NULL
)
7932 pst
= create_partial_symtab (per_cu
, filename
);
7934 /* This must be done before calling dwarf2_build_include_psymtabs. */
7935 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7937 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7939 dwarf2_find_base_address (comp_unit_die
, cu
);
7941 /* Possibly set the default values of LOWPC and HIGHPC from
7943 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7944 &best_highpc
, cu
, pst
);
7945 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7946 /* Store the contiguous range if it is not empty; it can be empty for
7947 CUs with no code. */
7948 addrmap_set_empty (objfile
->psymtabs_addrmap
,
7949 gdbarch_adjust_dwarf2_addr (gdbarch
,
7950 best_lowpc
+ baseaddr
),
7951 gdbarch_adjust_dwarf2_addr (gdbarch
,
7952 best_highpc
+ baseaddr
) - 1,
7955 /* Check if comp unit has_children.
7956 If so, read the rest of the partial symbols from this comp unit.
7957 If not, there's no more debug_info for this comp unit. */
7960 struct partial_die_info
*first_die
;
7961 CORE_ADDR lowpc
, highpc
;
7963 lowpc
= ((CORE_ADDR
) -1);
7964 highpc
= ((CORE_ADDR
) 0);
7966 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7968 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7969 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7971 /* If we didn't find a lowpc, set it to highpc to avoid
7972 complaints from `maint check'. */
7973 if (lowpc
== ((CORE_ADDR
) -1))
7976 /* If the compilation unit didn't have an explicit address range,
7977 then use the information extracted from its child dies. */
7978 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7981 best_highpc
= highpc
;
7984 pst
->textlow
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
);
7985 pst
->texthigh
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
);
7987 end_psymtab_common (objfile
, pst
);
7989 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
))
7992 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
7993 struct dwarf2_per_cu_data
*iter
;
7995 /* Fill in 'dependencies' here; we fill in 'users' in a
7997 pst
->number_of_dependencies
= len
;
7999 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
8001 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
8004 pst
->dependencies
[i
] = iter
->v
.psymtab
;
8006 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
8009 /* Get the list of files included in the current compilation unit,
8010 and build a psymtab for each of them. */
8011 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
8013 if (dwarf_read_debug
)
8015 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8017 fprintf_unfiltered (gdb_stdlog
,
8018 "Psymtab for %s unit @%s: %s - %s"
8019 ", %d global, %d static syms\n",
8020 per_cu
->is_debug_types
? "type" : "comp",
8021 sect_offset_str (per_cu
->sect_off
),
8022 paddress (gdbarch
, pst
->textlow
),
8023 paddress (gdbarch
, pst
->texthigh
),
8024 pst
->n_global_syms
, pst
->n_static_syms
);
8028 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8029 Process compilation unit THIS_CU for a psymtab. */
8032 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8033 int want_partial_unit
,
8034 enum language pretend_language
)
8036 /* If this compilation unit was already read in, free the
8037 cached copy in order to read it in again. This is
8038 necessary because we skipped some symbols when we first
8039 read in the compilation unit (see load_partial_dies).
8040 This problem could be avoided, but the benefit is unclear. */
8041 if (this_cu
->cu
!= NULL
)
8042 free_one_cached_comp_unit (this_cu
);
8044 if (this_cu
->is_debug_types
)
8045 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0, build_type_psymtabs_reader
,
8049 process_psymtab_comp_unit_data info
;
8050 info
.want_partial_unit
= want_partial_unit
;
8051 info
.pretend_language
= pretend_language
;
8052 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0,
8053 process_psymtab_comp_unit_reader
, &info
);
8056 /* Age out any secondary CUs. */
8057 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
8060 /* Reader function for build_type_psymtabs. */
8063 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
8064 const gdb_byte
*info_ptr
,
8065 struct die_info
*type_unit_die
,
8069 struct dwarf2_per_objfile
*dwarf2_per_objfile
8070 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
8071 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8072 struct dwarf2_cu
*cu
= reader
->cu
;
8073 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8074 struct signatured_type
*sig_type
;
8075 struct type_unit_group
*tu_group
;
8076 struct attribute
*attr
;
8077 struct partial_die_info
*first_die
;
8078 CORE_ADDR lowpc
, highpc
;
8079 struct partial_symtab
*pst
;
8081 gdb_assert (data
== NULL
);
8082 gdb_assert (per_cu
->is_debug_types
);
8083 sig_type
= (struct signatured_type
*) per_cu
;
8088 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
8089 tu_group
= get_type_unit_group (cu
, attr
);
8091 VEC_safe_push (sig_type_ptr
, tu_group
->tus
, sig_type
);
8093 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
8094 cu
->list_in_scope
= &file_symbols
;
8095 pst
= create_partial_symtab (per_cu
, "");
8098 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8100 lowpc
= (CORE_ADDR
) -1;
8101 highpc
= (CORE_ADDR
) 0;
8102 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
8104 end_psymtab_common (objfile
, pst
);
8107 /* Struct used to sort TUs by their abbreviation table offset. */
8109 struct tu_abbrev_offset
8111 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
8112 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
8115 signatured_type
*sig_type
;
8116 sect_offset abbrev_offset
;
8119 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
8122 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
8123 const struct tu_abbrev_offset
&b
)
8125 return a
.abbrev_offset
< b
.abbrev_offset
;
8128 /* Efficiently read all the type units.
8129 This does the bulk of the work for build_type_psymtabs.
8131 The efficiency is because we sort TUs by the abbrev table they use and
8132 only read each abbrev table once. In one program there are 200K TUs
8133 sharing 8K abbrev tables.
8135 The main purpose of this function is to support building the
8136 dwarf2_per_objfile->type_unit_groups table.
8137 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
8138 can collapse the search space by grouping them by stmt_list.
8139 The savings can be significant, in the same program from above the 200K TUs
8140 share 8K stmt_list tables.
8142 FUNC is expected to call get_type_unit_group, which will create the
8143 struct type_unit_group if necessary and add it to
8144 dwarf2_per_objfile->type_unit_groups. */
8147 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8149 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8150 abbrev_table_up abbrev_table
;
8151 sect_offset abbrev_offset
;
8153 /* It's up to the caller to not call us multiple times. */
8154 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
8156 if (dwarf2_per_objfile
->all_type_units
.empty ())
8159 /* TUs typically share abbrev tables, and there can be way more TUs than
8160 abbrev tables. Sort by abbrev table to reduce the number of times we
8161 read each abbrev table in.
8162 Alternatives are to punt or to maintain a cache of abbrev tables.
8163 This is simpler and efficient enough for now.
8165 Later we group TUs by their DW_AT_stmt_list value (as this defines the
8166 symtab to use). Typically TUs with the same abbrev offset have the same
8167 stmt_list value too so in practice this should work well.
8169 The basic algorithm here is:
8171 sort TUs by abbrev table
8172 for each TU with same abbrev table:
8173 read abbrev table if first user
8174 read TU top level DIE
8175 [IWBN if DWO skeletons had DW_AT_stmt_list]
8178 if (dwarf_read_debug
)
8179 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
8181 /* Sort in a separate table to maintain the order of all_type_units
8182 for .gdb_index: TU indices directly index all_type_units. */
8183 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
8184 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
8186 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
8187 sorted_by_abbrev
.emplace_back
8188 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
8189 sig_type
->per_cu
.section
,
8190 sig_type
->per_cu
.sect_off
));
8192 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
8193 sort_tu_by_abbrev_offset
);
8195 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
8197 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
8199 /* Switch to the next abbrev table if necessary. */
8200 if (abbrev_table
== NULL
8201 || tu
.abbrev_offset
!= abbrev_offset
)
8203 abbrev_offset
= tu
.abbrev_offset
;
8205 abbrev_table_read_table (dwarf2_per_objfile
,
8206 &dwarf2_per_objfile
->abbrev
,
8208 ++tu_stats
->nr_uniq_abbrev_tables
;
8211 init_cutu_and_read_dies (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
8212 0, 0, build_type_psymtabs_reader
, NULL
);
8216 /* Print collected type unit statistics. */
8219 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8221 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8223 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
8224 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
8225 dwarf2_per_objfile
->all_type_units
.size ());
8226 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
8227 tu_stats
->nr_uniq_abbrev_tables
);
8228 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
8229 tu_stats
->nr_symtabs
);
8230 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
8231 tu_stats
->nr_symtab_sharers
);
8232 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
8233 tu_stats
->nr_stmt_less_type_units
);
8234 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
8235 tu_stats
->nr_all_type_units_reallocs
);
8238 /* Traversal function for build_type_psymtabs. */
8241 build_type_psymtab_dependencies (void **slot
, void *info
)
8243 struct dwarf2_per_objfile
*dwarf2_per_objfile
8244 = (struct dwarf2_per_objfile
*) info
;
8245 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8246 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
8247 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
8248 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8249 int len
= VEC_length (sig_type_ptr
, tu_group
->tus
);
8250 struct signatured_type
*iter
;
8253 gdb_assert (len
> 0);
8254 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
8256 pst
->number_of_dependencies
= len
;
8258 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
8260 VEC_iterate (sig_type_ptr
, tu_group
->tus
, i
, iter
);
8263 gdb_assert (iter
->per_cu
.is_debug_types
);
8264 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
8265 iter
->type_unit_group
= tu_group
;
8268 VEC_free (sig_type_ptr
, tu_group
->tus
);
8273 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8274 Build partial symbol tables for the .debug_types comp-units. */
8277 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8279 if (! create_all_type_units (dwarf2_per_objfile
))
8282 build_type_psymtabs_1 (dwarf2_per_objfile
);
8285 /* Traversal function for process_skeletonless_type_unit.
8286 Read a TU in a DWO file and build partial symbols for it. */
8289 process_skeletonless_type_unit (void **slot
, void *info
)
8291 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
8292 struct dwarf2_per_objfile
*dwarf2_per_objfile
8293 = (struct dwarf2_per_objfile
*) info
;
8294 struct signatured_type find_entry
, *entry
;
8296 /* If this TU doesn't exist in the global table, add it and read it in. */
8298 if (dwarf2_per_objfile
->signatured_types
== NULL
)
8300 dwarf2_per_objfile
->signatured_types
8301 = allocate_signatured_type_table (dwarf2_per_objfile
->objfile
);
8304 find_entry
.signature
= dwo_unit
->signature
;
8305 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
8307 /* If we've already seen this type there's nothing to do. What's happening
8308 is we're doing our own version of comdat-folding here. */
8312 /* This does the job that create_all_type_units would have done for
8314 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
8315 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
8318 /* This does the job that build_type_psymtabs_1 would have done. */
8319 init_cutu_and_read_dies (&entry
->per_cu
, NULL
, 0, 0,
8320 build_type_psymtabs_reader
, NULL
);
8325 /* Traversal function for process_skeletonless_type_units. */
8328 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
8330 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8332 if (dwo_file
->tus
!= NULL
)
8334 htab_traverse_noresize (dwo_file
->tus
,
8335 process_skeletonless_type_unit
, info
);
8341 /* Scan all TUs of DWO files, verifying we've processed them.
8342 This is needed in case a TU was emitted without its skeleton.
8343 Note: This can't be done until we know what all the DWO files are. */
8346 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8348 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
8349 if (get_dwp_file (dwarf2_per_objfile
) == NULL
8350 && dwarf2_per_objfile
->dwo_files
!= NULL
)
8352 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
,
8353 process_dwo_file_for_skeletonless_type_units
,
8354 dwarf2_per_objfile
);
8358 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
8361 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8363 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8365 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8370 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
8372 /* Set the 'user' field only if it is not already set. */
8373 if (pst
->dependencies
[j
]->user
== NULL
)
8374 pst
->dependencies
[j
]->user
= pst
;
8379 /* Build the partial symbol table by doing a quick pass through the
8380 .debug_info and .debug_abbrev sections. */
8383 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8385 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8387 if (dwarf_read_debug
)
8389 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
8390 objfile_name (objfile
));
8393 dwarf2_per_objfile
->reading_partial_symbols
= 1;
8395 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
8397 /* Any cached compilation units will be linked by the per-objfile
8398 read_in_chain. Make sure to free them when we're done. */
8399 free_cached_comp_units
freer (dwarf2_per_objfile
);
8401 build_type_psymtabs (dwarf2_per_objfile
);
8403 create_all_comp_units (dwarf2_per_objfile
);
8405 /* Create a temporary address map on a temporary obstack. We later
8406 copy this to the final obstack. */
8407 auto_obstack temp_obstack
;
8409 scoped_restore save_psymtabs_addrmap
8410 = make_scoped_restore (&objfile
->psymtabs_addrmap
,
8411 addrmap_create_mutable (&temp_obstack
));
8413 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8414 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
8416 /* This has to wait until we read the CUs, we need the list of DWOs. */
8417 process_skeletonless_type_units (dwarf2_per_objfile
);
8419 /* Now that all TUs have been processed we can fill in the dependencies. */
8420 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
8422 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
8423 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
8426 if (dwarf_read_debug
)
8427 print_tu_stats (dwarf2_per_objfile
);
8429 set_partial_user (dwarf2_per_objfile
);
8431 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
8432 &objfile
->objfile_obstack
);
8433 /* At this point we want to keep the address map. */
8434 save_psymtabs_addrmap
.release ();
8436 if (dwarf_read_debug
)
8437 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8438 objfile_name (objfile
));
8441 /* die_reader_func for load_partial_comp_unit. */
8444 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
8445 const gdb_byte
*info_ptr
,
8446 struct die_info
*comp_unit_die
,
8450 struct dwarf2_cu
*cu
= reader
->cu
;
8452 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
8454 /* Check if comp unit has_children.
8455 If so, read the rest of the partial symbols from this comp unit.
8456 If not, there's no more debug_info for this comp unit. */
8458 load_partial_dies (reader
, info_ptr
, 0);
8461 /* Load the partial DIEs for a secondary CU into memory.
8462 This is also used when rereading a primary CU with load_all_dies. */
8465 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
8467 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
8468 load_partial_comp_unit_reader
, NULL
);
8472 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
8473 struct dwarf2_section_info
*section
,
8474 struct dwarf2_section_info
*abbrev_section
,
8475 unsigned int is_dwz
)
8477 const gdb_byte
*info_ptr
;
8478 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8480 if (dwarf_read_debug
)
8481 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8482 get_section_name (section
),
8483 get_section_file_name (section
));
8485 dwarf2_read_section (objfile
, section
);
8487 info_ptr
= section
->buffer
;
8489 while (info_ptr
< section
->buffer
+ section
->size
)
8491 struct dwarf2_per_cu_data
*this_cu
;
8493 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8495 comp_unit_head cu_header
;
8496 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
8497 abbrev_section
, info_ptr
,
8498 rcuh_kind::COMPILE
);
8500 /* Save the compilation unit for later lookup. */
8501 if (cu_header
.unit_type
!= DW_UT_type
)
8503 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
8504 struct dwarf2_per_cu_data
);
8505 memset (this_cu
, 0, sizeof (*this_cu
));
8509 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
8510 struct signatured_type
);
8511 memset (sig_type
, 0, sizeof (*sig_type
));
8512 sig_type
->signature
= cu_header
.signature
;
8513 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8514 this_cu
= &sig_type
->per_cu
;
8516 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8517 this_cu
->sect_off
= sect_off
;
8518 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8519 this_cu
->is_dwz
= is_dwz
;
8520 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
8521 this_cu
->section
= section
;
8523 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
8525 info_ptr
= info_ptr
+ this_cu
->length
;
8529 /* Create a list of all compilation units in OBJFILE.
8530 This is only done for -readnow and building partial symtabs. */
8533 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8535 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
8536 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
8537 &dwarf2_per_objfile
->abbrev
, 0);
8539 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
8541 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
8545 /* Process all loaded DIEs for compilation unit CU, starting at
8546 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8547 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8548 DW_AT_ranges). See the comments of add_partial_subprogram on how
8549 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8552 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8553 CORE_ADDR
*highpc
, int set_addrmap
,
8554 struct dwarf2_cu
*cu
)
8556 struct partial_die_info
*pdi
;
8558 /* Now, march along the PDI's, descending into ones which have
8559 interesting children but skipping the children of the other ones,
8560 until we reach the end of the compilation unit. */
8568 /* Anonymous namespaces or modules have no name but have interesting
8569 children, so we need to look at them. Ditto for anonymous
8572 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8573 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8574 || pdi
->tag
== DW_TAG_imported_unit
8575 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8579 case DW_TAG_subprogram
:
8580 case DW_TAG_inlined_subroutine
:
8581 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8583 case DW_TAG_constant
:
8584 case DW_TAG_variable
:
8585 case DW_TAG_typedef
:
8586 case DW_TAG_union_type
:
8587 if (!pdi
->is_declaration
)
8589 add_partial_symbol (pdi
, cu
);
8592 case DW_TAG_class_type
:
8593 case DW_TAG_interface_type
:
8594 case DW_TAG_structure_type
:
8595 if (!pdi
->is_declaration
)
8597 add_partial_symbol (pdi
, cu
);
8599 if ((cu
->language
== language_rust
8600 || cu
->language
== language_cplus
) && pdi
->has_children
)
8601 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8604 case DW_TAG_enumeration_type
:
8605 if (!pdi
->is_declaration
)
8606 add_partial_enumeration (pdi
, cu
);
8608 case DW_TAG_base_type
:
8609 case DW_TAG_subrange_type
:
8610 /* File scope base type definitions are added to the partial
8612 add_partial_symbol (pdi
, cu
);
8614 case DW_TAG_namespace
:
8615 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8618 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8620 case DW_TAG_imported_unit
:
8622 struct dwarf2_per_cu_data
*per_cu
;
8624 /* For now we don't handle imported units in type units. */
8625 if (cu
->per_cu
->is_debug_types
)
8627 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8628 " supported in type units [in module %s]"),
8629 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
8632 per_cu
= dwarf2_find_containing_comp_unit
8633 (pdi
->d
.sect_off
, pdi
->is_dwz
,
8634 cu
->per_cu
->dwarf2_per_objfile
);
8636 /* Go read the partial unit, if needed. */
8637 if (per_cu
->v
.psymtab
== NULL
)
8638 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
8640 VEC_safe_push (dwarf2_per_cu_ptr
,
8641 cu
->per_cu
->imported_symtabs
, per_cu
);
8644 case DW_TAG_imported_declaration
:
8645 add_partial_symbol (pdi
, cu
);
8652 /* If the die has a sibling, skip to the sibling. */
8654 pdi
= pdi
->die_sibling
;
8658 /* Functions used to compute the fully scoped name of a partial DIE.
8660 Normally, this is simple. For C++, the parent DIE's fully scoped
8661 name is concatenated with "::" and the partial DIE's name.
8662 Enumerators are an exception; they use the scope of their parent
8663 enumeration type, i.e. the name of the enumeration type is not
8664 prepended to the enumerator.
8666 There are two complexities. One is DW_AT_specification; in this
8667 case "parent" means the parent of the target of the specification,
8668 instead of the direct parent of the DIE. The other is compilers
8669 which do not emit DW_TAG_namespace; in this case we try to guess
8670 the fully qualified name of structure types from their members'
8671 linkage names. This must be done using the DIE's children rather
8672 than the children of any DW_AT_specification target. We only need
8673 to do this for structures at the top level, i.e. if the target of
8674 any DW_AT_specification (if any; otherwise the DIE itself) does not
8677 /* Compute the scope prefix associated with PDI's parent, in
8678 compilation unit CU. The result will be allocated on CU's
8679 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8680 field. NULL is returned if no prefix is necessary. */
8682 partial_die_parent_scope (struct partial_die_info
*pdi
,
8683 struct dwarf2_cu
*cu
)
8685 const char *grandparent_scope
;
8686 struct partial_die_info
*parent
, *real_pdi
;
8688 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8689 then this means the parent of the specification DIE. */
8692 while (real_pdi
->has_specification
)
8693 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
8694 real_pdi
->spec_is_dwz
, cu
);
8696 parent
= real_pdi
->die_parent
;
8700 if (parent
->scope_set
)
8701 return parent
->scope
;
8705 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8707 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8708 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8709 Work around this problem here. */
8710 if (cu
->language
== language_cplus
8711 && parent
->tag
== DW_TAG_namespace
8712 && strcmp (parent
->name
, "::") == 0
8713 && grandparent_scope
== NULL
)
8715 parent
->scope
= NULL
;
8716 parent
->scope_set
= 1;
8720 if (pdi
->tag
== DW_TAG_enumerator
)
8721 /* Enumerators should not get the name of the enumeration as a prefix. */
8722 parent
->scope
= grandparent_scope
;
8723 else if (parent
->tag
== DW_TAG_namespace
8724 || parent
->tag
== DW_TAG_module
8725 || parent
->tag
== DW_TAG_structure_type
8726 || parent
->tag
== DW_TAG_class_type
8727 || parent
->tag
== DW_TAG_interface_type
8728 || parent
->tag
== DW_TAG_union_type
8729 || parent
->tag
== DW_TAG_enumeration_type
)
8731 if (grandparent_scope
== NULL
)
8732 parent
->scope
= parent
->name
;
8734 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8736 parent
->name
, 0, cu
);
8740 /* FIXME drow/2004-04-01: What should we be doing with
8741 function-local names? For partial symbols, we should probably be
8743 complaint (&symfile_complaints
,
8744 _("unhandled containing DIE tag %d for DIE at %s"),
8745 parent
->tag
, sect_offset_str (pdi
->sect_off
));
8746 parent
->scope
= grandparent_scope
;
8749 parent
->scope_set
= 1;
8750 return parent
->scope
;
8753 /* Return the fully scoped name associated with PDI, from compilation unit
8754 CU. The result will be allocated with malloc. */
8757 partial_die_full_name (struct partial_die_info
*pdi
,
8758 struct dwarf2_cu
*cu
)
8760 const char *parent_scope
;
8762 /* If this is a template instantiation, we can not work out the
8763 template arguments from partial DIEs. So, unfortunately, we have
8764 to go through the full DIEs. At least any work we do building
8765 types here will be reused if full symbols are loaded later. */
8766 if (pdi
->has_template_arguments
)
8770 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8772 struct die_info
*die
;
8773 struct attribute attr
;
8774 struct dwarf2_cu
*ref_cu
= cu
;
8776 /* DW_FORM_ref_addr is using section offset. */
8777 attr
.name
= (enum dwarf_attribute
) 0;
8778 attr
.form
= DW_FORM_ref_addr
;
8779 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8780 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8782 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8786 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8787 if (parent_scope
== NULL
)
8790 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
8794 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8796 struct dwarf2_per_objfile
*dwarf2_per_objfile
8797 = cu
->per_cu
->dwarf2_per_objfile
;
8798 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8799 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8801 const char *actual_name
= NULL
;
8803 char *built_actual_name
;
8805 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8807 built_actual_name
= partial_die_full_name (pdi
, cu
);
8808 if (built_actual_name
!= NULL
)
8809 actual_name
= built_actual_name
;
8811 if (actual_name
== NULL
)
8812 actual_name
= pdi
->name
;
8816 case DW_TAG_inlined_subroutine
:
8817 case DW_TAG_subprogram
:
8818 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
);
8819 if (pdi
->is_external
|| cu
->language
== language_ada
)
8821 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
8822 of the global scope. But in Ada, we want to be able to access
8823 nested procedures globally. So all Ada subprograms are stored
8824 in the global scope. */
8825 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8826 built_actual_name
!= NULL
,
8827 VAR_DOMAIN
, LOC_BLOCK
,
8828 &objfile
->global_psymbols
,
8829 addr
, cu
->language
, objfile
);
8833 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8834 built_actual_name
!= NULL
,
8835 VAR_DOMAIN
, LOC_BLOCK
,
8836 &objfile
->static_psymbols
,
8837 addr
, cu
->language
, objfile
);
8840 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8841 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8843 case DW_TAG_constant
:
8845 std::vector
<partial_symbol
*> *list
;
8847 if (pdi
->is_external
)
8848 list
= &objfile
->global_psymbols
;
8850 list
= &objfile
->static_psymbols
;
8851 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8852 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8853 list
, 0, cu
->language
, objfile
);
8856 case DW_TAG_variable
:
8858 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8862 && !dwarf2_per_objfile
->has_section_at_zero
)
8864 /* A global or static variable may also have been stripped
8865 out by the linker if unused, in which case its address
8866 will be nullified; do not add such variables into partial
8867 symbol table then. */
8869 else if (pdi
->is_external
)
8872 Don't enter into the minimal symbol tables as there is
8873 a minimal symbol table entry from the ELF symbols already.
8874 Enter into partial symbol table if it has a location
8875 descriptor or a type.
8876 If the location descriptor is missing, new_symbol will create
8877 a LOC_UNRESOLVED symbol, the address of the variable will then
8878 be determined from the minimal symbol table whenever the variable
8880 The address for the partial symbol table entry is not
8881 used by GDB, but it comes in handy for debugging partial symbol
8884 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8885 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8886 built_actual_name
!= NULL
,
8887 VAR_DOMAIN
, LOC_STATIC
,
8888 &objfile
->global_psymbols
,
8890 cu
->language
, objfile
);
8894 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8896 /* Static Variable. Skip symbols whose value we cannot know (those
8897 without location descriptors or constant values). */
8898 if (!has_loc
&& !pdi
->has_const_value
)
8900 xfree (built_actual_name
);
8904 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8905 built_actual_name
!= NULL
,
8906 VAR_DOMAIN
, LOC_STATIC
,
8907 &objfile
->static_psymbols
,
8908 has_loc
? addr
+ baseaddr
: (CORE_ADDR
) 0,
8909 cu
->language
, objfile
);
8912 case DW_TAG_typedef
:
8913 case DW_TAG_base_type
:
8914 case DW_TAG_subrange_type
:
8915 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8916 built_actual_name
!= NULL
,
8917 VAR_DOMAIN
, LOC_TYPEDEF
,
8918 &objfile
->static_psymbols
,
8919 0, cu
->language
, objfile
);
8921 case DW_TAG_imported_declaration
:
8922 case DW_TAG_namespace
:
8923 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8924 built_actual_name
!= NULL
,
8925 VAR_DOMAIN
, LOC_TYPEDEF
,
8926 &objfile
->global_psymbols
,
8927 0, cu
->language
, objfile
);
8930 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8931 built_actual_name
!= NULL
,
8932 MODULE_DOMAIN
, LOC_TYPEDEF
,
8933 &objfile
->global_psymbols
,
8934 0, cu
->language
, objfile
);
8936 case DW_TAG_class_type
:
8937 case DW_TAG_interface_type
:
8938 case DW_TAG_structure_type
:
8939 case DW_TAG_union_type
:
8940 case DW_TAG_enumeration_type
:
8941 /* Skip external references. The DWARF standard says in the section
8942 about "Structure, Union, and Class Type Entries": "An incomplete
8943 structure, union or class type is represented by a structure,
8944 union or class entry that does not have a byte size attribute
8945 and that has a DW_AT_declaration attribute." */
8946 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8948 xfree (built_actual_name
);
8952 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8953 static vs. global. */
8954 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8955 built_actual_name
!= NULL
,
8956 STRUCT_DOMAIN
, LOC_TYPEDEF
,
8957 cu
->language
== language_cplus
8958 ? &objfile
->global_psymbols
8959 : &objfile
->static_psymbols
,
8960 0, cu
->language
, objfile
);
8963 case DW_TAG_enumerator
:
8964 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8965 built_actual_name
!= NULL
,
8966 VAR_DOMAIN
, LOC_CONST
,
8967 cu
->language
== language_cplus
8968 ? &objfile
->global_psymbols
8969 : &objfile
->static_psymbols
,
8970 0, cu
->language
, objfile
);
8976 xfree (built_actual_name
);
8979 /* Read a partial die corresponding to a namespace; also, add a symbol
8980 corresponding to that namespace to the symbol table. NAMESPACE is
8981 the name of the enclosing namespace. */
8984 add_partial_namespace (struct partial_die_info
*pdi
,
8985 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8986 int set_addrmap
, struct dwarf2_cu
*cu
)
8988 /* Add a symbol for the namespace. */
8990 add_partial_symbol (pdi
, cu
);
8992 /* Now scan partial symbols in that namespace. */
8994 if (pdi
->has_children
)
8995 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8998 /* Read a partial die corresponding to a Fortran module. */
9001 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
9002 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
9004 /* Add a symbol for the namespace. */
9006 add_partial_symbol (pdi
, cu
);
9008 /* Now scan partial symbols in that module. */
9010 if (pdi
->has_children
)
9011 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9014 /* Read a partial die corresponding to a subprogram or an inlined
9015 subprogram and create a partial symbol for that subprogram.
9016 When the CU language allows it, this routine also defines a partial
9017 symbol for each nested subprogram that this subprogram contains.
9018 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
9019 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
9021 PDI may also be a lexical block, in which case we simply search
9022 recursively for subprograms defined inside that lexical block.
9023 Again, this is only performed when the CU language allows this
9024 type of definitions. */
9027 add_partial_subprogram (struct partial_die_info
*pdi
,
9028 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9029 int set_addrmap
, struct dwarf2_cu
*cu
)
9031 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
9033 if (pdi
->has_pc_info
)
9035 if (pdi
->lowpc
< *lowpc
)
9036 *lowpc
= pdi
->lowpc
;
9037 if (pdi
->highpc
> *highpc
)
9038 *highpc
= pdi
->highpc
;
9041 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9042 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9047 baseaddr
= ANOFFSET (objfile
->section_offsets
,
9048 SECT_OFF_TEXT (objfile
));
9049 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
9050 pdi
->lowpc
+ baseaddr
);
9051 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
9052 pdi
->highpc
+ baseaddr
);
9053 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
9054 cu
->per_cu
->v
.psymtab
);
9058 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
9060 if (!pdi
->is_declaration
)
9061 /* Ignore subprogram DIEs that do not have a name, they are
9062 illegal. Do not emit a complaint at this point, we will
9063 do so when we convert this psymtab into a symtab. */
9065 add_partial_symbol (pdi
, cu
);
9069 if (! pdi
->has_children
)
9072 if (cu
->language
== language_ada
)
9074 pdi
= pdi
->die_child
;
9078 if (pdi
->tag
== DW_TAG_subprogram
9079 || pdi
->tag
== DW_TAG_inlined_subroutine
9080 || pdi
->tag
== DW_TAG_lexical_block
)
9081 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9082 pdi
= pdi
->die_sibling
;
9087 /* Read a partial die corresponding to an enumeration type. */
9090 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
9091 struct dwarf2_cu
*cu
)
9093 struct partial_die_info
*pdi
;
9095 if (enum_pdi
->name
!= NULL
)
9096 add_partial_symbol (enum_pdi
, cu
);
9098 pdi
= enum_pdi
->die_child
;
9101 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
9102 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
9104 add_partial_symbol (pdi
, cu
);
9105 pdi
= pdi
->die_sibling
;
9109 /* Return the initial uleb128 in the die at INFO_PTR. */
9112 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
9114 unsigned int bytes_read
;
9116 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9119 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
9120 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
9122 Return the corresponding abbrev, or NULL if the number is zero (indicating
9123 an empty DIE). In either case *BYTES_READ will be set to the length of
9124 the initial number. */
9126 static struct abbrev_info
*
9127 peek_die_abbrev (const die_reader_specs
&reader
,
9128 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
9130 dwarf2_cu
*cu
= reader
.cu
;
9131 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
9132 unsigned int abbrev_number
9133 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
9135 if (abbrev_number
== 0)
9138 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
9141 error (_("Dwarf Error: Could not find abbrev number %d in %s"
9142 " at offset %s [in module %s]"),
9143 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
9144 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
9150 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9151 Returns a pointer to the end of a series of DIEs, terminated by an empty
9152 DIE. Any children of the skipped DIEs will also be skipped. */
9154 static const gdb_byte
*
9155 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
9159 unsigned int bytes_read
;
9160 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
9163 return info_ptr
+ bytes_read
;
9165 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
9169 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9170 INFO_PTR should point just after the initial uleb128 of a DIE, and the
9171 abbrev corresponding to that skipped uleb128 should be passed in
9172 ABBREV. Returns a pointer to this DIE's sibling, skipping any
9175 static const gdb_byte
*
9176 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
9177 struct abbrev_info
*abbrev
)
9179 unsigned int bytes_read
;
9180 struct attribute attr
;
9181 bfd
*abfd
= reader
->abfd
;
9182 struct dwarf2_cu
*cu
= reader
->cu
;
9183 const gdb_byte
*buffer
= reader
->buffer
;
9184 const gdb_byte
*buffer_end
= reader
->buffer_end
;
9185 unsigned int form
, i
;
9187 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
9189 /* The only abbrev we care about is DW_AT_sibling. */
9190 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
9192 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
9193 if (attr
.form
== DW_FORM_ref_addr
)
9194 complaint (&symfile_complaints
,
9195 _("ignoring absolute DW_AT_sibling"));
9198 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
9199 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
9201 if (sibling_ptr
< info_ptr
)
9202 complaint (&symfile_complaints
,
9203 _("DW_AT_sibling points backwards"));
9204 else if (sibling_ptr
> reader
->buffer_end
)
9205 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
9211 /* If it isn't DW_AT_sibling, skip this attribute. */
9212 form
= abbrev
->attrs
[i
].form
;
9216 case DW_FORM_ref_addr
:
9217 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
9218 and later it is offset sized. */
9219 if (cu
->header
.version
== 2)
9220 info_ptr
+= cu
->header
.addr_size
;
9222 info_ptr
+= cu
->header
.offset_size
;
9224 case DW_FORM_GNU_ref_alt
:
9225 info_ptr
+= cu
->header
.offset_size
;
9228 info_ptr
+= cu
->header
.addr_size
;
9235 case DW_FORM_flag_present
:
9236 case DW_FORM_implicit_const
:
9248 case DW_FORM_ref_sig8
:
9251 case DW_FORM_data16
:
9254 case DW_FORM_string
:
9255 read_direct_string (abfd
, info_ptr
, &bytes_read
);
9256 info_ptr
+= bytes_read
;
9258 case DW_FORM_sec_offset
:
9260 case DW_FORM_GNU_strp_alt
:
9261 info_ptr
+= cu
->header
.offset_size
;
9263 case DW_FORM_exprloc
:
9265 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9266 info_ptr
+= bytes_read
;
9268 case DW_FORM_block1
:
9269 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
9271 case DW_FORM_block2
:
9272 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
9274 case DW_FORM_block4
:
9275 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
9279 case DW_FORM_ref_udata
:
9280 case DW_FORM_GNU_addr_index
:
9281 case DW_FORM_GNU_str_index
:
9282 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
9284 case DW_FORM_indirect
:
9285 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9286 info_ptr
+= bytes_read
;
9287 /* We need to continue parsing from here, so just go back to
9289 goto skip_attribute
;
9292 error (_("Dwarf Error: Cannot handle %s "
9293 "in DWARF reader [in module %s]"),
9294 dwarf_form_name (form
),
9295 bfd_get_filename (abfd
));
9299 if (abbrev
->has_children
)
9300 return skip_children (reader
, info_ptr
);
9305 /* Locate ORIG_PDI's sibling.
9306 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
9308 static const gdb_byte
*
9309 locate_pdi_sibling (const struct die_reader_specs
*reader
,
9310 struct partial_die_info
*orig_pdi
,
9311 const gdb_byte
*info_ptr
)
9313 /* Do we know the sibling already? */
9315 if (orig_pdi
->sibling
)
9316 return orig_pdi
->sibling
;
9318 /* Are there any children to deal with? */
9320 if (!orig_pdi
->has_children
)
9323 /* Skip the children the long way. */
9325 return skip_children (reader
, info_ptr
);
9328 /* Expand this partial symbol table into a full symbol table. SELF is
9332 dwarf2_read_symtab (struct partial_symtab
*self
,
9333 struct objfile
*objfile
)
9335 struct dwarf2_per_objfile
*dwarf2_per_objfile
9336 = get_dwarf2_per_objfile (objfile
);
9340 warning (_("bug: psymtab for %s is already read in."),
9347 printf_filtered (_("Reading in symbols for %s..."),
9349 gdb_flush (gdb_stdout
);
9352 /* If this psymtab is constructed from a debug-only objfile, the
9353 has_section_at_zero flag will not necessarily be correct. We
9354 can get the correct value for this flag by looking at the data
9355 associated with the (presumably stripped) associated objfile. */
9356 if (objfile
->separate_debug_objfile_backlink
)
9358 struct dwarf2_per_objfile
*dpo_backlink
9359 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
9361 dwarf2_per_objfile
->has_section_at_zero
9362 = dpo_backlink
->has_section_at_zero
;
9365 dwarf2_per_objfile
->reading_partial_symbols
= 0;
9367 psymtab_to_symtab_1 (self
);
9369 /* Finish up the debug error message. */
9371 printf_filtered (_("done.\n"));
9374 process_cu_includes (dwarf2_per_objfile
);
9377 /* Reading in full CUs. */
9379 /* Add PER_CU to the queue. */
9382 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9383 enum language pretend_language
)
9385 struct dwarf2_queue_item
*item
;
9388 item
= XNEW (struct dwarf2_queue_item
);
9389 item
->per_cu
= per_cu
;
9390 item
->pretend_language
= pretend_language
;
9393 if (dwarf2_queue
== NULL
)
9394 dwarf2_queue
= item
;
9396 dwarf2_queue_tail
->next
= item
;
9398 dwarf2_queue_tail
= item
;
9401 /* If PER_CU is not yet queued, add it to the queue.
9402 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9404 The result is non-zero if PER_CU was queued, otherwise the result is zero
9405 meaning either PER_CU is already queued or it is already loaded.
9407 N.B. There is an invariant here that if a CU is queued then it is loaded.
9408 The caller is required to load PER_CU if we return non-zero. */
9411 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9412 struct dwarf2_per_cu_data
*per_cu
,
9413 enum language pretend_language
)
9415 /* We may arrive here during partial symbol reading, if we need full
9416 DIEs to process an unusual case (e.g. template arguments). Do
9417 not queue PER_CU, just tell our caller to load its DIEs. */
9418 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
9420 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
9425 /* Mark the dependence relation so that we don't flush PER_CU
9427 if (dependent_cu
!= NULL
)
9428 dwarf2_add_dependence (dependent_cu
, per_cu
);
9430 /* If it's already on the queue, we have nothing to do. */
9434 /* If the compilation unit is already loaded, just mark it as
9436 if (per_cu
->cu
!= NULL
)
9438 per_cu
->cu
->last_used
= 0;
9442 /* Add it to the queue. */
9443 queue_comp_unit (per_cu
, pretend_language
);
9448 /* Process the queue. */
9451 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9453 struct dwarf2_queue_item
*item
, *next_item
;
9455 if (dwarf_read_debug
)
9457 fprintf_unfiltered (gdb_stdlog
,
9458 "Expanding one or more symtabs of objfile %s ...\n",
9459 objfile_name (dwarf2_per_objfile
->objfile
));
9462 /* The queue starts out with one item, but following a DIE reference
9463 may load a new CU, adding it to the end of the queue. */
9464 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
9466 if ((dwarf2_per_objfile
->using_index
9467 ? !item
->per_cu
->v
.quick
->compunit_symtab
9468 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
9469 /* Skip dummy CUs. */
9470 && item
->per_cu
->cu
!= NULL
)
9472 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
9473 unsigned int debug_print_threshold
;
9476 if (per_cu
->is_debug_types
)
9478 struct signatured_type
*sig_type
=
9479 (struct signatured_type
*) per_cu
;
9481 sprintf (buf
, "TU %s at offset %s",
9482 hex_string (sig_type
->signature
),
9483 sect_offset_str (per_cu
->sect_off
));
9484 /* There can be 100s of TUs.
9485 Only print them in verbose mode. */
9486 debug_print_threshold
= 2;
9490 sprintf (buf
, "CU at offset %s",
9491 sect_offset_str (per_cu
->sect_off
));
9492 debug_print_threshold
= 1;
9495 if (dwarf_read_debug
>= debug_print_threshold
)
9496 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9498 if (per_cu
->is_debug_types
)
9499 process_full_type_unit (per_cu
, item
->pretend_language
);
9501 process_full_comp_unit (per_cu
, item
->pretend_language
);
9503 if (dwarf_read_debug
>= debug_print_threshold
)
9504 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9507 item
->per_cu
->queued
= 0;
9508 next_item
= item
->next
;
9512 dwarf2_queue_tail
= NULL
;
9514 if (dwarf_read_debug
)
9516 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9517 objfile_name (dwarf2_per_objfile
->objfile
));
9521 /* Read in full symbols for PST, and anything it depends on. */
9524 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
9526 struct dwarf2_per_cu_data
*per_cu
;
9532 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
9533 if (!pst
->dependencies
[i
]->readin
9534 && pst
->dependencies
[i
]->user
== NULL
)
9536 /* Inform about additional files that need to be read in. */
9539 /* FIXME: i18n: Need to make this a single string. */
9540 fputs_filtered (" ", gdb_stdout
);
9542 fputs_filtered ("and ", gdb_stdout
);
9544 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
9545 wrap_here (""); /* Flush output. */
9546 gdb_flush (gdb_stdout
);
9548 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
9551 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
9555 /* It's an include file, no symbols to read for it.
9556 Everything is in the parent symtab. */
9561 dw2_do_instantiate_symtab (per_cu
);
9564 /* Trivial hash function for die_info: the hash value of a DIE
9565 is its offset in .debug_info for this objfile. */
9568 die_hash (const void *item
)
9570 const struct die_info
*die
= (const struct die_info
*) item
;
9572 return to_underlying (die
->sect_off
);
9575 /* Trivial comparison function for die_info structures: two DIEs
9576 are equal if they have the same offset. */
9579 die_eq (const void *item_lhs
, const void *item_rhs
)
9581 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9582 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9584 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9587 /* die_reader_func for load_full_comp_unit.
9588 This is identical to read_signatured_type_reader,
9589 but is kept separate for now. */
9592 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
9593 const gdb_byte
*info_ptr
,
9594 struct die_info
*comp_unit_die
,
9598 struct dwarf2_cu
*cu
= reader
->cu
;
9599 enum language
*language_ptr
= (enum language
*) data
;
9601 gdb_assert (cu
->die_hash
== NULL
);
9603 htab_create_alloc_ex (cu
->header
.length
/ 12,
9607 &cu
->comp_unit_obstack
,
9608 hashtab_obstack_allocate
,
9609 dummy_obstack_deallocate
);
9612 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
9613 &info_ptr
, comp_unit_die
);
9614 cu
->dies
= comp_unit_die
;
9615 /* comp_unit_die is not stored in die_hash, no need. */
9617 /* We try not to read any attributes in this function, because not
9618 all CUs needed for references have been loaded yet, and symbol
9619 table processing isn't initialized. But we have to set the CU language,
9620 or we won't be able to build types correctly.
9621 Similarly, if we do not read the producer, we can not apply
9622 producer-specific interpretation. */
9623 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
9626 /* Load the DIEs associated with PER_CU into memory. */
9629 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
9630 enum language pretend_language
)
9632 gdb_assert (! this_cu
->is_debug_types
);
9634 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
9635 load_full_comp_unit_reader
, &pretend_language
);
9638 /* Add a DIE to the delayed physname list. */
9641 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9642 const char *name
, struct die_info
*die
,
9643 struct dwarf2_cu
*cu
)
9645 struct delayed_method_info mi
;
9647 mi
.fnfield_index
= fnfield_index
;
9651 cu
->method_list
.push_back (mi
);
9654 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9655 "const" / "volatile". If so, decrements LEN by the length of the
9656 modifier and return true. Otherwise return false. */
9660 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9662 size_t mod_len
= sizeof (mod
) - 1;
9663 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9671 /* Compute the physnames of any methods on the CU's method list.
9673 The computation of method physnames is delayed in order to avoid the
9674 (bad) condition that one of the method's formal parameters is of an as yet
9678 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9680 /* Only C++ delays computing physnames. */
9681 if (cu
->method_list
.empty ())
9683 gdb_assert (cu
->language
== language_cplus
);
9685 for (struct delayed_method_info
&mi
: cu
->method_list
)
9687 const char *physname
;
9688 struct fn_fieldlist
*fn_flp
9689 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9690 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9691 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9692 = physname
? physname
: "";
9694 /* Since there's no tag to indicate whether a method is a
9695 const/volatile overload, extract that information out of the
9697 if (physname
!= NULL
)
9699 size_t len
= strlen (physname
);
9703 if (physname
[len
] == ')') /* shortcut */
9705 else if (check_modifier (physname
, len
, " const"))
9706 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9707 else if (check_modifier (physname
, len
, " volatile"))
9708 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9715 /* The list is no longer needed. */
9716 cu
->method_list
.clear ();
9719 /* Go objects should be embedded in a DW_TAG_module DIE,
9720 and it's not clear if/how imported objects will appear.
9721 To keep Go support simple until that's worked out,
9722 go back through what we've read and create something usable.
9723 We could do this while processing each DIE, and feels kinda cleaner,
9724 but that way is more invasive.
9725 This is to, for example, allow the user to type "p var" or "b main"
9726 without having to specify the package name, and allow lookups
9727 of module.object to work in contexts that use the expression
9731 fixup_go_packaging (struct dwarf2_cu
*cu
)
9733 char *package_name
= NULL
;
9734 struct pending
*list
;
9737 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
9739 for (i
= 0; i
< list
->nsyms
; ++i
)
9741 struct symbol
*sym
= list
->symbol
[i
];
9743 if (SYMBOL_LANGUAGE (sym
) == language_go
9744 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9746 char *this_package_name
= go_symbol_package_name (sym
);
9748 if (this_package_name
== NULL
)
9750 if (package_name
== NULL
)
9751 package_name
= this_package_name
;
9754 struct objfile
*objfile
9755 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9756 if (strcmp (package_name
, this_package_name
) != 0)
9757 complaint (&symfile_complaints
,
9758 _("Symtab %s has objects from two different Go packages: %s and %s"),
9759 (symbol_symtab (sym
) != NULL
9760 ? symtab_to_filename_for_display
9761 (symbol_symtab (sym
))
9762 : objfile_name (objfile
)),
9763 this_package_name
, package_name
);
9764 xfree (this_package_name
);
9770 if (package_name
!= NULL
)
9772 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9773 const char *saved_package_name
9774 = (const char *) obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
9776 strlen (package_name
));
9777 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9778 saved_package_name
);
9781 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
9783 sym
= allocate_symbol (objfile
);
9784 SYMBOL_SET_LANGUAGE (sym
, language_go
, &objfile
->objfile_obstack
);
9785 SYMBOL_SET_NAMES (sym
, saved_package_name
,
9786 strlen (saved_package_name
), 0, objfile
);
9787 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9788 e.g., "main" finds the "main" module and not C's main(). */
9789 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9790 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9791 SYMBOL_TYPE (sym
) = type
;
9793 add_symbol_to_list (sym
, &global_symbols
);
9795 xfree (package_name
);
9799 /* Allocate a fully-qualified name consisting of the two parts on the
9803 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9805 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9808 /* A helper that allocates a struct discriminant_info to attach to a
9811 static struct discriminant_info
*
9812 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9815 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9816 gdb_assert (discriminant_index
== -1
9817 || (discriminant_index
>= 0
9818 && discriminant_index
< TYPE_NFIELDS (type
)));
9819 gdb_assert (default_index
== -1
9820 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9822 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9824 struct discriminant_info
*disc
9825 = ((struct discriminant_info
*)
9827 offsetof (struct discriminant_info
, discriminants
)
9828 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9829 disc
->default_index
= default_index
;
9830 disc
->discriminant_index
= discriminant_index
;
9832 struct dynamic_prop prop
;
9833 prop
.kind
= PROP_UNDEFINED
;
9834 prop
.data
.baton
= disc
;
9836 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9841 /* Some versions of rustc emitted enums in an unusual way.
9843 Ordinary enums were emitted as unions. The first element of each
9844 structure in the union was named "RUST$ENUM$DISR". This element
9845 held the discriminant.
9847 These versions of Rust also implemented the "non-zero"
9848 optimization. When the enum had two values, and one is empty and
9849 the other holds a pointer that cannot be zero, the pointer is used
9850 as the discriminant, with a zero value meaning the empty variant.
9851 Here, the union's first member is of the form
9852 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9853 where the fieldnos are the indices of the fields that should be
9854 traversed in order to find the field (which may be several fields deep)
9855 and the variantname is the name of the variant of the case when the
9858 This function recognizes whether TYPE is of one of these forms,
9859 and, if so, smashes it to be a variant type. */
9862 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9864 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9866 /* We don't need to deal with empty enums. */
9867 if (TYPE_NFIELDS (type
) == 0)
9870 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9871 if (TYPE_NFIELDS (type
) == 1
9872 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9874 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9876 /* Decode the field name to find the offset of the
9878 ULONGEST bit_offset
= 0;
9879 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9880 while (name
[0] >= '0' && name
[0] <= '9')
9883 unsigned long index
= strtoul (name
, &tail
, 10);
9886 || index
>= TYPE_NFIELDS (field_type
)
9887 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9888 != FIELD_LOC_KIND_BITPOS
))
9890 complaint (&symfile_complaints
,
9891 _("Could not parse Rust enum encoding string \"%s\""
9893 TYPE_FIELD_NAME (type
, 0),
9894 objfile_name (objfile
));
9899 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9900 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9903 /* Make a union to hold the variants. */
9904 struct type
*union_type
= alloc_type (objfile
);
9905 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9906 TYPE_NFIELDS (union_type
) = 3;
9907 TYPE_FIELDS (union_type
)
9908 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
9909 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9911 /* Put the discriminant must at index 0. */
9912 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
9913 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9914 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9915 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
9917 /* The order of fields doesn't really matter, so put the real
9918 field at index 1 and the data-less field at index 2. */
9919 struct discriminant_info
*disc
9920 = alloc_discriminant_info (union_type
, 0, 1);
9921 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
9922 TYPE_FIELD_NAME (union_type
, 1)
9923 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
9924 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
9925 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9926 TYPE_FIELD_NAME (union_type
, 1));
9928 const char *dataless_name
9929 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9931 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9933 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
9934 /* NAME points into the original discriminant name, which
9935 already has the correct lifetime. */
9936 TYPE_FIELD_NAME (union_type
, 2) = name
;
9937 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
9938 disc
->discriminants
[2] = 0;
9940 /* Smash this type to be a structure type. We have to do this
9941 because the type has already been recorded. */
9942 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9943 TYPE_NFIELDS (type
) = 1;
9945 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
9947 /* Install the variant part. */
9948 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9949 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9950 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9952 else if (TYPE_NFIELDS (type
) == 1)
9954 /* We assume that a union with a single field is a univariant
9956 /* Smash this type to be a structure type. We have to do this
9957 because the type has already been recorded. */
9958 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9960 /* Make a union to hold the variants. */
9961 struct type
*union_type
= alloc_type (objfile
);
9962 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9963 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
9964 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9965 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
9967 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
9968 const char *variant_name
9969 = rust_last_path_segment (TYPE_NAME (field_type
));
9970 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
9971 TYPE_NAME (field_type
)
9972 = rust_fully_qualify (&objfile
->objfile_obstack
,
9973 TYPE_NAME (type
), variant_name
);
9975 /* Install the union in the outer struct type. */
9976 TYPE_NFIELDS (type
) = 1;
9978 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
9979 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9980 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9981 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9983 alloc_discriminant_info (union_type
, -1, 0);
9987 struct type
*disr_type
= nullptr;
9988 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
9990 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9992 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
9994 /* All fields of a true enum will be structs. */
9997 else if (TYPE_NFIELDS (disr_type
) == 0)
9999 /* Could be data-less variant, so keep going. */
10000 disr_type
= nullptr;
10002 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
10003 "RUST$ENUM$DISR") != 0)
10005 /* Not a Rust enum. */
10015 /* If we got here without a discriminant, then it's probably
10017 if (disr_type
== nullptr)
10020 /* Smash this type to be a structure type. We have to do this
10021 because the type has already been recorded. */
10022 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10024 /* Make a union to hold the variants. */
10025 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
10026 struct type
*union_type
= alloc_type (objfile
);
10027 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10028 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
10029 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10030 TYPE_FIELDS (union_type
)
10031 = (struct field
*) TYPE_ZALLOC (union_type
,
10032 (TYPE_NFIELDS (union_type
)
10033 * sizeof (struct field
)));
10035 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
10036 TYPE_NFIELDS (type
) * sizeof (struct field
));
10038 /* Install the discriminant at index 0 in the union. */
10039 TYPE_FIELD (union_type
, 0) = *disr_field
;
10040 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10041 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10043 /* Install the union in the outer struct type. */
10044 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10045 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10046 TYPE_NFIELDS (type
) = 1;
10048 /* Set the size and offset of the union type. */
10049 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10051 /* We need a way to find the correct discriminant given a
10052 variant name. For convenience we build a map here. */
10053 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
10054 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
10055 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
10057 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
10060 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
10061 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
10065 int n_fields
= TYPE_NFIELDS (union_type
);
10066 struct discriminant_info
*disc
10067 = alloc_discriminant_info (union_type
, 0, -1);
10068 /* Skip the discriminant here. */
10069 for (int i
= 1; i
< n_fields
; ++i
)
10071 /* Find the final word in the name of this variant's type.
10072 That name can be used to look up the correct
10074 const char *variant_name
10075 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
10078 auto iter
= discriminant_map
.find (variant_name
);
10079 if (iter
!= discriminant_map
.end ())
10080 disc
->discriminants
[i
] = iter
->second
;
10082 /* Remove the discriminant field, if it exists. */
10083 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
10084 if (TYPE_NFIELDS (sub_type
) > 0)
10086 --TYPE_NFIELDS (sub_type
);
10087 ++TYPE_FIELDS (sub_type
);
10089 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
10090 TYPE_NAME (sub_type
)
10091 = rust_fully_qualify (&objfile
->objfile_obstack
,
10092 TYPE_NAME (type
), variant_name
);
10097 /* Rewrite some Rust unions to be structures with variants parts. */
10100 rust_union_quirks (struct dwarf2_cu
*cu
)
10102 gdb_assert (cu
->language
== language_rust
);
10103 for (struct type
*type
: cu
->rust_unions
)
10104 quirk_rust_enum (type
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
10107 /* Return the symtab for PER_CU. This works properly regardless of
10108 whether we're using the index or psymtabs. */
10110 static struct compunit_symtab
*
10111 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
10113 return (per_cu
->dwarf2_per_objfile
->using_index
10114 ? per_cu
->v
.quick
->compunit_symtab
10115 : per_cu
->v
.psymtab
->compunit_symtab
);
10118 /* A helper function for computing the list of all symbol tables
10119 included by PER_CU. */
10122 recursively_compute_inclusions (VEC (compunit_symtab_ptr
) **result
,
10123 htab_t all_children
, htab_t all_type_symtabs
,
10124 struct dwarf2_per_cu_data
*per_cu
,
10125 struct compunit_symtab
*immediate_parent
)
10129 struct compunit_symtab
*cust
;
10130 struct dwarf2_per_cu_data
*iter
;
10132 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
10135 /* This inclusion and its children have been processed. */
10140 /* Only add a CU if it has a symbol table. */
10141 cust
= get_compunit_symtab (per_cu
);
10144 /* If this is a type unit only add its symbol table if we haven't
10145 seen it yet (type unit per_cu's can share symtabs). */
10146 if (per_cu
->is_debug_types
)
10148 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
10152 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
10153 if (cust
->user
== NULL
)
10154 cust
->user
= immediate_parent
;
10159 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
10160 if (cust
->user
== NULL
)
10161 cust
->user
= immediate_parent
;
10166 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, ix
, iter
);
10169 recursively_compute_inclusions (result
, all_children
,
10170 all_type_symtabs
, iter
, cust
);
10174 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
10178 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
10180 gdb_assert (! per_cu
->is_debug_types
);
10182 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
))
10185 struct dwarf2_per_cu_data
*per_cu_iter
;
10186 struct compunit_symtab
*compunit_symtab_iter
;
10187 VEC (compunit_symtab_ptr
) *result_symtabs
= NULL
;
10188 htab_t all_children
, all_type_symtabs
;
10189 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
10191 /* If we don't have a symtab, we can just skip this case. */
10195 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10196 NULL
, xcalloc
, xfree
);
10197 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10198 NULL
, xcalloc
, xfree
);
10201 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
,
10205 recursively_compute_inclusions (&result_symtabs
, all_children
,
10206 all_type_symtabs
, per_cu_iter
,
10210 /* Now we have a transitive closure of all the included symtabs. */
10211 len
= VEC_length (compunit_symtab_ptr
, result_symtabs
);
10213 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
10214 struct compunit_symtab
*, len
+ 1);
10216 VEC_iterate (compunit_symtab_ptr
, result_symtabs
, ix
,
10217 compunit_symtab_iter
);
10219 cust
->includes
[ix
] = compunit_symtab_iter
;
10220 cust
->includes
[len
] = NULL
;
10222 VEC_free (compunit_symtab_ptr
, result_symtabs
);
10223 htab_delete (all_children
);
10224 htab_delete (all_type_symtabs
);
10228 /* Compute the 'includes' field for the symtabs of all the CUs we just
10232 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
10235 struct dwarf2_per_cu_data
*iter
;
10238 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
10242 if (! iter
->is_debug_types
)
10243 compute_compunit_symtab_includes (iter
);
10246 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
10249 /* Generate full symbol information for PER_CU, whose DIEs have
10250 already been loaded into memory. */
10253 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
10254 enum language pretend_language
)
10256 struct dwarf2_cu
*cu
= per_cu
->cu
;
10257 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10258 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10259 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10260 CORE_ADDR lowpc
, highpc
;
10261 struct compunit_symtab
*cust
;
10262 CORE_ADDR baseaddr
;
10263 struct block
*static_block
;
10266 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10269 scoped_free_pendings free_pending
;
10271 /* Clear the list here in case something was left over. */
10272 cu
->method_list
.clear ();
10274 cu
->list_in_scope
= &file_symbols
;
10276 cu
->language
= pretend_language
;
10277 cu
->language_defn
= language_def (cu
->language
);
10279 /* Do line number decoding in read_file_scope () */
10280 process_die (cu
->dies
, cu
);
10282 /* For now fudge the Go package. */
10283 if (cu
->language
== language_go
)
10284 fixup_go_packaging (cu
);
10286 /* Now that we have processed all the DIEs in the CU, all the types
10287 should be complete, and it should now be safe to compute all of the
10289 compute_delayed_physnames (cu
);
10291 if (cu
->language
== language_rust
)
10292 rust_union_quirks (cu
);
10294 /* Some compilers don't define a DW_AT_high_pc attribute for the
10295 compilation unit. If the DW_AT_high_pc is missing, synthesize
10296 it, by scanning the DIE's below the compilation unit. */
10297 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
10299 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
10300 static_block
= end_symtab_get_static_block (addr
, 0, 1);
10302 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
10303 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
10304 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
10305 addrmap to help ensure it has an accurate map of pc values belonging to
10307 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
10309 cust
= end_symtab_from_static_block (static_block
,
10310 SECT_OFF_TEXT (objfile
), 0);
10314 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
10316 /* Set symtab language to language from DW_AT_language. If the
10317 compilation is from a C file generated by language preprocessors, do
10318 not set the language if it was already deduced by start_subfile. */
10319 if (!(cu
->language
== language_c
10320 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
10321 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10323 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
10324 produce DW_AT_location with location lists but it can be possibly
10325 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
10326 there were bugs in prologue debug info, fixed later in GCC-4.5
10327 by "unwind info for epilogues" patch (which is not directly related).
10329 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
10330 needed, it would be wrong due to missing DW_AT_producer there.
10332 Still one can confuse GDB by using non-standard GCC compilation
10333 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
10335 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
10336 cust
->locations_valid
= 1;
10338 if (gcc_4_minor
>= 5)
10339 cust
->epilogue_unwind_valid
= 1;
10341 cust
->call_site_htab
= cu
->call_site_htab
;
10344 if (dwarf2_per_objfile
->using_index
)
10345 per_cu
->v
.quick
->compunit_symtab
= cust
;
10348 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10349 pst
->compunit_symtab
= cust
;
10353 /* Push it for inclusion processing later. */
10354 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
10357 /* Generate full symbol information for type unit PER_CU, whose DIEs have
10358 already been loaded into memory. */
10361 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
10362 enum language pretend_language
)
10364 struct dwarf2_cu
*cu
= per_cu
->cu
;
10365 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10366 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10367 struct compunit_symtab
*cust
;
10368 struct signatured_type
*sig_type
;
10370 gdb_assert (per_cu
->is_debug_types
);
10371 sig_type
= (struct signatured_type
*) per_cu
;
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 /* The symbol tables are set up in read_type_unit_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 /* TUs share symbol tables.
10400 If this is the first TU to use this symtab, complete the construction
10401 of it with end_expandable_symtab. Otherwise, complete the addition of
10402 this TU's symbols to the existing symtab. */
10403 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
10405 cust
= end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10406 sig_type
->type_unit_group
->compunit_symtab
= cust
;
10410 /* Set symtab language to language from DW_AT_language. If the
10411 compilation is from a C file generated by language preprocessors,
10412 do not set the language if it was already deduced by
10414 if (!(cu
->language
== language_c
10415 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10416 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10421 augment_type_symtab ();
10422 cust
= sig_type
->type_unit_group
->compunit_symtab
;
10425 if (dwarf2_per_objfile
->using_index
)
10426 per_cu
->v
.quick
->compunit_symtab
= cust
;
10429 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10430 pst
->compunit_symtab
= cust
;
10435 /* Process an imported unit DIE. */
10438 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10440 struct attribute
*attr
;
10442 /* For now we don't handle imported units in type units. */
10443 if (cu
->per_cu
->is_debug_types
)
10445 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10446 " supported in type units [in module %s]"),
10447 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
10450 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10453 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10454 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10455 dwarf2_per_cu_data
*per_cu
10456 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
10457 cu
->per_cu
->dwarf2_per_objfile
);
10459 /* If necessary, add it to the queue and load its DIEs. */
10460 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
10461 load_full_comp_unit (per_cu
, cu
->language
);
10463 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
10468 /* RAII object that represents a process_die scope: i.e.,
10469 starts/finishes processing a DIE. */
10470 class process_die_scope
10473 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10474 : m_die (die
), m_cu (cu
)
10476 /* We should only be processing DIEs not already in process. */
10477 gdb_assert (!m_die
->in_process
);
10478 m_die
->in_process
= true;
10481 ~process_die_scope ()
10483 m_die
->in_process
= false;
10485 /* If we're done processing the DIE for the CU that owns the line
10486 header, we don't need the line header anymore. */
10487 if (m_cu
->line_header_die_owner
== m_die
)
10489 delete m_cu
->line_header
;
10490 m_cu
->line_header
= NULL
;
10491 m_cu
->line_header_die_owner
= NULL
;
10500 /* Process a die and its children. */
10503 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10505 process_die_scope
scope (die
, cu
);
10509 case DW_TAG_padding
:
10511 case DW_TAG_compile_unit
:
10512 case DW_TAG_partial_unit
:
10513 read_file_scope (die
, cu
);
10515 case DW_TAG_type_unit
:
10516 read_type_unit_scope (die
, cu
);
10518 case DW_TAG_subprogram
:
10519 case DW_TAG_inlined_subroutine
:
10520 read_func_scope (die
, cu
);
10522 case DW_TAG_lexical_block
:
10523 case DW_TAG_try_block
:
10524 case DW_TAG_catch_block
:
10525 read_lexical_block_scope (die
, cu
);
10527 case DW_TAG_call_site
:
10528 case DW_TAG_GNU_call_site
:
10529 read_call_site_scope (die
, cu
);
10531 case DW_TAG_class_type
:
10532 case DW_TAG_interface_type
:
10533 case DW_TAG_structure_type
:
10534 case DW_TAG_union_type
:
10535 process_structure_scope (die
, cu
);
10537 case DW_TAG_enumeration_type
:
10538 process_enumeration_scope (die
, cu
);
10541 /* These dies have a type, but processing them does not create
10542 a symbol or recurse to process the children. Therefore we can
10543 read them on-demand through read_type_die. */
10544 case DW_TAG_subroutine_type
:
10545 case DW_TAG_set_type
:
10546 case DW_TAG_array_type
:
10547 case DW_TAG_pointer_type
:
10548 case DW_TAG_ptr_to_member_type
:
10549 case DW_TAG_reference_type
:
10550 case DW_TAG_rvalue_reference_type
:
10551 case DW_TAG_string_type
:
10554 case DW_TAG_base_type
:
10555 case DW_TAG_subrange_type
:
10556 case DW_TAG_typedef
:
10557 /* Add a typedef symbol for the type definition, if it has a
10559 new_symbol (die
, read_type_die (die
, cu
), cu
);
10561 case DW_TAG_common_block
:
10562 read_common_block (die
, cu
);
10564 case DW_TAG_common_inclusion
:
10566 case DW_TAG_namespace
:
10567 cu
->processing_has_namespace_info
= 1;
10568 read_namespace (die
, cu
);
10570 case DW_TAG_module
:
10571 cu
->processing_has_namespace_info
= 1;
10572 read_module (die
, cu
);
10574 case DW_TAG_imported_declaration
:
10575 cu
->processing_has_namespace_info
= 1;
10576 if (read_namespace_alias (die
, cu
))
10578 /* The declaration is not a global namespace alias: fall through. */
10579 case DW_TAG_imported_module
:
10580 cu
->processing_has_namespace_info
= 1;
10581 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10582 || cu
->language
!= language_fortran
))
10583 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
10584 dwarf_tag_name (die
->tag
));
10585 read_import_statement (die
, cu
);
10588 case DW_TAG_imported_unit
:
10589 process_imported_unit_die (die
, cu
);
10592 case DW_TAG_variable
:
10593 read_variable (die
, cu
);
10597 new_symbol (die
, NULL
, cu
);
10602 /* DWARF name computation. */
10604 /* A helper function for dwarf2_compute_name which determines whether DIE
10605 needs to have the name of the scope prepended to the name listed in the
10609 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10611 struct attribute
*attr
;
10615 case DW_TAG_namespace
:
10616 case DW_TAG_typedef
:
10617 case DW_TAG_class_type
:
10618 case DW_TAG_interface_type
:
10619 case DW_TAG_structure_type
:
10620 case DW_TAG_union_type
:
10621 case DW_TAG_enumeration_type
:
10622 case DW_TAG_enumerator
:
10623 case DW_TAG_subprogram
:
10624 case DW_TAG_inlined_subroutine
:
10625 case DW_TAG_member
:
10626 case DW_TAG_imported_declaration
:
10629 case DW_TAG_variable
:
10630 case DW_TAG_constant
:
10631 /* We only need to prefix "globally" visible variables. These include
10632 any variable marked with DW_AT_external or any variable that
10633 lives in a namespace. [Variables in anonymous namespaces
10634 require prefixing, but they are not DW_AT_external.] */
10636 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10638 struct dwarf2_cu
*spec_cu
= cu
;
10640 return die_needs_namespace (die_specification (die
, &spec_cu
),
10644 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10645 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10646 && die
->parent
->tag
!= DW_TAG_module
)
10648 /* A variable in a lexical block of some kind does not need a
10649 namespace, even though in C++ such variables may be external
10650 and have a mangled name. */
10651 if (die
->parent
->tag
== DW_TAG_lexical_block
10652 || die
->parent
->tag
== DW_TAG_try_block
10653 || die
->parent
->tag
== DW_TAG_catch_block
10654 || die
->parent
->tag
== DW_TAG_subprogram
)
10663 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10664 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10665 defined for the given DIE. */
10667 static struct attribute
*
10668 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10670 struct attribute
*attr
;
10672 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10674 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10679 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10680 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10681 defined for the given DIE. */
10683 static const char *
10684 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10686 const char *linkage_name
;
10688 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10689 if (linkage_name
== NULL
)
10690 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10692 return linkage_name
;
10695 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10696 compute the physname for the object, which include a method's:
10697 - formal parameters (C++),
10698 - receiver type (Go),
10700 The term "physname" is a bit confusing.
10701 For C++, for example, it is the demangled name.
10702 For Go, for example, it's the mangled name.
10704 For Ada, return the DIE's linkage name rather than the fully qualified
10705 name. PHYSNAME is ignored..
10707 The result is allocated on the objfile_obstack and canonicalized. */
10709 static const char *
10710 dwarf2_compute_name (const char *name
,
10711 struct die_info
*die
, struct dwarf2_cu
*cu
,
10714 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10717 name
= dwarf2_name (die
, cu
);
10719 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10720 but otherwise compute it by typename_concat inside GDB.
10721 FIXME: Actually this is not really true, or at least not always true.
10722 It's all very confusing. SYMBOL_SET_NAMES doesn't try to demangle
10723 Fortran names because there is no mangling standard. So new_symbol
10724 will set the demangled name to the result of dwarf2_full_name, and it is
10725 the demangled name that GDB uses if it exists. */
10726 if (cu
->language
== language_ada
10727 || (cu
->language
== language_fortran
&& physname
))
10729 /* For Ada unit, we prefer the linkage name over the name, as
10730 the former contains the exported name, which the user expects
10731 to be able to reference. Ideally, we want the user to be able
10732 to reference this entity using either natural or linkage name,
10733 but we haven't started looking at this enhancement yet. */
10734 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10736 if (linkage_name
!= NULL
)
10737 return linkage_name
;
10740 /* These are the only languages we know how to qualify names in. */
10742 && (cu
->language
== language_cplus
10743 || cu
->language
== language_fortran
|| cu
->language
== language_d
10744 || cu
->language
== language_rust
))
10746 if (die_needs_namespace (die
, cu
))
10748 const char *prefix
;
10749 const char *canonical_name
= NULL
;
10753 prefix
= determine_prefix (die
, cu
);
10754 if (*prefix
!= '\0')
10756 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
10759 buf
.puts (prefixed_name
);
10760 xfree (prefixed_name
);
10765 /* Template parameters may be specified in the DIE's DW_AT_name, or
10766 as children with DW_TAG_template_type_param or
10767 DW_TAG_value_type_param. If the latter, add them to the name
10768 here. If the name already has template parameters, then
10769 skip this step; some versions of GCC emit both, and
10770 it is more efficient to use the pre-computed name.
10772 Something to keep in mind about this process: it is very
10773 unlikely, or in some cases downright impossible, to produce
10774 something that will match the mangled name of a function.
10775 If the definition of the function has the same debug info,
10776 we should be able to match up with it anyway. But fallbacks
10777 using the minimal symbol, for instance to find a method
10778 implemented in a stripped copy of libstdc++, will not work.
10779 If we do not have debug info for the definition, we will have to
10780 match them up some other way.
10782 When we do name matching there is a related problem with function
10783 templates; two instantiated function templates are allowed to
10784 differ only by their return types, which we do not add here. */
10786 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10788 struct attribute
*attr
;
10789 struct die_info
*child
;
10792 die
->building_fullname
= 1;
10794 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10798 const gdb_byte
*bytes
;
10799 struct dwarf2_locexpr_baton
*baton
;
10802 if (child
->tag
!= DW_TAG_template_type_param
10803 && child
->tag
!= DW_TAG_template_value_param
)
10814 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10817 complaint (&symfile_complaints
,
10818 _("template parameter missing DW_AT_type"));
10819 buf
.puts ("UNKNOWN_TYPE");
10822 type
= die_type (child
, cu
);
10824 if (child
->tag
== DW_TAG_template_type_param
)
10826 c_print_type (type
, "", &buf
, -1, 0, &type_print_raw_options
);
10830 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10833 complaint (&symfile_complaints
,
10834 _("template parameter missing "
10835 "DW_AT_const_value"));
10836 buf
.puts ("UNKNOWN_VALUE");
10840 dwarf2_const_value_attr (attr
, type
, name
,
10841 &cu
->comp_unit_obstack
, cu
,
10842 &value
, &bytes
, &baton
);
10844 if (TYPE_NOSIGN (type
))
10845 /* GDB prints characters as NUMBER 'CHAR'. If that's
10846 changed, this can use value_print instead. */
10847 c_printchar (value
, type
, &buf
);
10850 struct value_print_options opts
;
10853 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10857 else if (bytes
!= NULL
)
10859 v
= allocate_value (type
);
10860 memcpy (value_contents_writeable (v
), bytes
,
10861 TYPE_LENGTH (type
));
10864 v
= value_from_longest (type
, value
);
10866 /* Specify decimal so that we do not depend on
10868 get_formatted_print_options (&opts
, 'd');
10870 value_print (v
, &buf
, &opts
);
10875 die
->building_fullname
= 0;
10879 /* Close the argument list, with a space if necessary
10880 (nested templates). */
10881 if (!buf
.empty () && buf
.string ().back () == '>')
10888 /* For C++ methods, append formal parameter type
10889 information, if PHYSNAME. */
10891 if (physname
&& die
->tag
== DW_TAG_subprogram
10892 && cu
->language
== language_cplus
)
10894 struct type
*type
= read_type_die (die
, cu
);
10896 c_type_print_args (type
, &buf
, 1, cu
->language
,
10897 &type_print_raw_options
);
10899 if (cu
->language
== language_cplus
)
10901 /* Assume that an artificial first parameter is
10902 "this", but do not crash if it is not. RealView
10903 marks unnamed (and thus unused) parameters as
10904 artificial; there is no way to differentiate
10906 if (TYPE_NFIELDS (type
) > 0
10907 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10908 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
10909 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10911 buf
.puts (" const");
10915 const std::string
&intermediate_name
= buf
.string ();
10917 if (cu
->language
== language_cplus
)
10919 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10920 &objfile
->per_bfd
->storage_obstack
);
10922 /* If we only computed INTERMEDIATE_NAME, or if
10923 INTERMEDIATE_NAME is already canonical, then we need to
10924 copy it to the appropriate obstack. */
10925 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10926 name
= ((const char *)
10927 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
10928 intermediate_name
.c_str (),
10929 intermediate_name
.length ()));
10931 name
= canonical_name
;
10938 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10939 If scope qualifiers are appropriate they will be added. The result
10940 will be allocated on the storage_obstack, or NULL if the DIE does
10941 not have a name. NAME may either be from a previous call to
10942 dwarf2_name or NULL.
10944 The output string will be canonicalized (if C++). */
10946 static const char *
10947 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10949 return dwarf2_compute_name (name
, die
, cu
, 0);
10952 /* Construct a physname for the given DIE in CU. NAME may either be
10953 from a previous call to dwarf2_name or NULL. The result will be
10954 allocated on the objfile_objstack or NULL if the DIE does not have a
10957 The output string will be canonicalized (if C++). */
10959 static const char *
10960 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10962 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10963 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10966 /* In this case dwarf2_compute_name is just a shortcut not building anything
10968 if (!die_needs_namespace (die
, cu
))
10969 return dwarf2_compute_name (name
, die
, cu
, 1);
10971 mangled
= dw2_linkage_name (die
, cu
);
10973 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10974 See https://github.com/rust-lang/rust/issues/32925. */
10975 if (cu
->language
== language_rust
&& mangled
!= NULL
10976 && strchr (mangled
, '{') != NULL
)
10979 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10981 gdb::unique_xmalloc_ptr
<char> demangled
;
10982 if (mangled
!= NULL
)
10985 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10987 /* Do nothing (do not demangle the symbol name). */
10989 else if (cu
->language
== language_go
)
10991 /* This is a lie, but we already lie to the caller new_symbol.
10992 new_symbol assumes we return the mangled name.
10993 This just undoes that lie until things are cleaned up. */
10997 /* Use DMGL_RET_DROP for C++ template functions to suppress
10998 their return type. It is easier for GDB users to search
10999 for such functions as `name(params)' than `long name(params)'.
11000 In such case the minimal symbol names do not match the full
11001 symbol names but for template functions there is never a need
11002 to look up their definition from their declaration so
11003 the only disadvantage remains the minimal symbol variant
11004 `long name(params)' does not have the proper inferior type. */
11005 demangled
.reset (gdb_demangle (mangled
,
11006 (DMGL_PARAMS
| DMGL_ANSI
11007 | DMGL_RET_DROP
)));
11010 canon
= demangled
.get ();
11018 if (canon
== NULL
|| check_physname
)
11020 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
11022 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
11024 /* It may not mean a bug in GDB. The compiler could also
11025 compute DW_AT_linkage_name incorrectly. But in such case
11026 GDB would need to be bug-to-bug compatible. */
11028 complaint (&symfile_complaints
,
11029 _("Computed physname <%s> does not match demangled <%s> "
11030 "(from linkage <%s>) - DIE at %s [in module %s]"),
11031 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
11032 objfile_name (objfile
));
11034 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
11035 is available here - over computed PHYSNAME. It is safer
11036 against both buggy GDB and buggy compilers. */
11050 retval
= ((const char *)
11051 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
11052 retval
, strlen (retval
)));
11057 /* Inspect DIE in CU for a namespace alias. If one exists, record
11058 a new symbol for it.
11060 Returns 1 if a namespace alias was recorded, 0 otherwise. */
11063 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
11065 struct attribute
*attr
;
11067 /* If the die does not have a name, this is not a namespace
11069 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11073 struct die_info
*d
= die
;
11074 struct dwarf2_cu
*imported_cu
= cu
;
11076 /* If the compiler has nested DW_AT_imported_declaration DIEs,
11077 keep inspecting DIEs until we hit the underlying import. */
11078 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
11079 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
11081 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
11085 d
= follow_die_ref (d
, attr
, &imported_cu
);
11086 if (d
->tag
!= DW_TAG_imported_declaration
)
11090 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
11092 complaint (&symfile_complaints
,
11093 _("DIE at %s has too many recursively imported "
11094 "declarations"), sect_offset_str (d
->sect_off
));
11101 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
11103 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
11104 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
11106 /* This declaration is a global namespace alias. Add
11107 a symbol for it whose type is the aliased namespace. */
11108 new_symbol (die
, type
, cu
);
11117 /* Return the using directives repository (global or local?) to use in the
11118 current context for LANGUAGE.
11120 For Ada, imported declarations can materialize renamings, which *may* be
11121 global. However it is impossible (for now?) in DWARF to distinguish
11122 "external" imported declarations and "static" ones. As all imported
11123 declarations seem to be static in all other languages, make them all CU-wide
11124 global only in Ada. */
11126 static struct using_direct
**
11127 using_directives (enum language language
)
11129 if (language
== language_ada
&& context_stack_depth
== 0)
11130 return &global_using_directives
;
11132 return &local_using_directives
;
11135 /* Read the import statement specified by the given die and record it. */
11138 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
11140 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11141 struct attribute
*import_attr
;
11142 struct die_info
*imported_die
, *child_die
;
11143 struct dwarf2_cu
*imported_cu
;
11144 const char *imported_name
;
11145 const char *imported_name_prefix
;
11146 const char *canonical_name
;
11147 const char *import_alias
;
11148 const char *imported_declaration
= NULL
;
11149 const char *import_prefix
;
11150 std::vector
<const char *> excludes
;
11152 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
11153 if (import_attr
== NULL
)
11155 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
11156 dwarf_tag_name (die
->tag
));
11161 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
11162 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11163 if (imported_name
== NULL
)
11165 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
11167 The import in the following code:
11181 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
11182 <52> DW_AT_decl_file : 1
11183 <53> DW_AT_decl_line : 6
11184 <54> DW_AT_import : <0x75>
11185 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
11186 <59> DW_AT_name : B
11187 <5b> DW_AT_decl_file : 1
11188 <5c> DW_AT_decl_line : 2
11189 <5d> DW_AT_type : <0x6e>
11191 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
11192 <76> DW_AT_byte_size : 4
11193 <77> DW_AT_encoding : 5 (signed)
11195 imports the wrong die ( 0x75 instead of 0x58 ).
11196 This case will be ignored until the gcc bug is fixed. */
11200 /* Figure out the local name after import. */
11201 import_alias
= dwarf2_name (die
, cu
);
11203 /* Figure out where the statement is being imported to. */
11204 import_prefix
= determine_prefix (die
, cu
);
11206 /* Figure out what the scope of the imported die is and prepend it
11207 to the name of the imported die. */
11208 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
11210 if (imported_die
->tag
!= DW_TAG_namespace
11211 && imported_die
->tag
!= DW_TAG_module
)
11213 imported_declaration
= imported_name
;
11214 canonical_name
= imported_name_prefix
;
11216 else if (strlen (imported_name_prefix
) > 0)
11217 canonical_name
= obconcat (&objfile
->objfile_obstack
,
11218 imported_name_prefix
,
11219 (cu
->language
== language_d
? "." : "::"),
11220 imported_name
, (char *) NULL
);
11222 canonical_name
= imported_name
;
11224 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
11225 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11226 child_die
= sibling_die (child_die
))
11228 /* DWARF-4: A Fortran use statement with a “rename list” may be
11229 represented by an imported module entry with an import attribute
11230 referring to the module and owned entries corresponding to those
11231 entities that are renamed as part of being imported. */
11233 if (child_die
->tag
!= DW_TAG_imported_declaration
)
11235 complaint (&symfile_complaints
,
11236 _("child DW_TAG_imported_declaration expected "
11237 "- DIE at %s [in module %s]"),
11238 sect_offset_str (child_die
->sect_off
),
11239 objfile_name (objfile
));
11243 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
11244 if (import_attr
== NULL
)
11246 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
11247 dwarf_tag_name (child_die
->tag
));
11252 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
11254 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11255 if (imported_name
== NULL
)
11257 complaint (&symfile_complaints
,
11258 _("child DW_TAG_imported_declaration has unknown "
11259 "imported name - DIE at %s [in module %s]"),
11260 sect_offset_str (child_die
->sect_off
),
11261 objfile_name (objfile
));
11265 excludes
.push_back (imported_name
);
11267 process_die (child_die
, cu
);
11270 add_using_directive (using_directives (cu
->language
),
11274 imported_declaration
,
11277 &objfile
->objfile_obstack
);
11280 /* ICC<14 does not output the required DW_AT_declaration on incomplete
11281 types, but gives them a size of zero. Starting with version 14,
11282 ICC is compatible with GCC. */
11285 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
11287 if (!cu
->checked_producer
)
11288 check_producer (cu
);
11290 return cu
->producer_is_icc_lt_14
;
11293 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
11294 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
11295 this, it was first present in GCC release 4.3.0. */
11298 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
11300 if (!cu
->checked_producer
)
11301 check_producer (cu
);
11303 return cu
->producer_is_gcc_lt_4_3
;
11306 static file_and_directory
11307 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
11309 file_and_directory res
;
11311 /* Find the filename. Do not use dwarf2_name here, since the filename
11312 is not a source language identifier. */
11313 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
11314 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
11316 if (res
.comp_dir
== NULL
11317 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
11318 && IS_ABSOLUTE_PATH (res
.name
))
11320 res
.comp_dir_storage
= ldirname (res
.name
);
11321 if (!res
.comp_dir_storage
.empty ())
11322 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
11324 if (res
.comp_dir
!= NULL
)
11326 /* Irix 6.2 native cc prepends <machine>.: to the compilation
11327 directory, get rid of it. */
11328 const char *cp
= strchr (res
.comp_dir
, ':');
11330 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
11331 res
.comp_dir
= cp
+ 1;
11334 if (res
.name
== NULL
)
11335 res
.name
= "<unknown>";
11340 /* Handle DW_AT_stmt_list for a compilation unit.
11341 DIE is the DW_TAG_compile_unit die for CU.
11342 COMP_DIR is the compilation directory. LOWPC is passed to
11343 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11346 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11347 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
11349 struct dwarf2_per_objfile
*dwarf2_per_objfile
11350 = cu
->per_cu
->dwarf2_per_objfile
;
11351 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11352 struct attribute
*attr
;
11353 struct line_header line_header_local
;
11354 hashval_t line_header_local_hash
;
11356 int decode_mapping
;
11358 gdb_assert (! cu
->per_cu
->is_debug_types
);
11360 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11364 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11366 /* The line header hash table is only created if needed (it exists to
11367 prevent redundant reading of the line table for partial_units).
11368 If we're given a partial_unit, we'll need it. If we're given a
11369 compile_unit, then use the line header hash table if it's already
11370 created, but don't create one just yet. */
11372 if (dwarf2_per_objfile
->line_header_hash
== NULL
11373 && die
->tag
== DW_TAG_partial_unit
)
11375 dwarf2_per_objfile
->line_header_hash
11376 = htab_create_alloc_ex (127, line_header_hash_voidp
,
11377 line_header_eq_voidp
,
11378 free_line_header_voidp
,
11379 &objfile
->objfile_obstack
,
11380 hashtab_obstack_allocate
,
11381 dummy_obstack_deallocate
);
11384 line_header_local
.sect_off
= line_offset
;
11385 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11386 line_header_local_hash
= line_header_hash (&line_header_local
);
11387 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
11389 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11390 &line_header_local
,
11391 line_header_local_hash
, NO_INSERT
);
11393 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11394 is not present in *SLOT (since if there is something in *SLOT then
11395 it will be for a partial_unit). */
11396 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11398 gdb_assert (*slot
!= NULL
);
11399 cu
->line_header
= (struct line_header
*) *slot
;
11404 /* dwarf_decode_line_header does not yet provide sufficient information.
11405 We always have to call also dwarf_decode_lines for it. */
11406 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11410 cu
->line_header
= lh
.release ();
11411 cu
->line_header_die_owner
= die
;
11413 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
11417 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11418 &line_header_local
,
11419 line_header_local_hash
, INSERT
);
11420 gdb_assert (slot
!= NULL
);
11422 if (slot
!= NULL
&& *slot
== NULL
)
11424 /* This newly decoded line number information unit will be owned
11425 by line_header_hash hash table. */
11426 *slot
= cu
->line_header
;
11427 cu
->line_header_die_owner
= NULL
;
11431 /* We cannot free any current entry in (*slot) as that struct line_header
11432 may be already used by multiple CUs. Create only temporary decoded
11433 line_header for this CU - it may happen at most once for each line
11434 number information unit. And if we're not using line_header_hash
11435 then this is what we want as well. */
11436 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11438 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11439 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11444 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11447 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11449 struct dwarf2_per_objfile
*dwarf2_per_objfile
11450 = cu
->per_cu
->dwarf2_per_objfile
;
11451 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11452 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11453 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11454 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11455 struct attribute
*attr
;
11456 struct die_info
*child_die
;
11457 CORE_ADDR baseaddr
;
11459 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11461 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11463 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11464 from finish_block. */
11465 if (lowpc
== ((CORE_ADDR
) -1))
11467 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11469 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11471 prepare_one_comp_unit (cu
, die
, cu
->language
);
11473 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11474 standardised yet. As a workaround for the language detection we fall
11475 back to the DW_AT_producer string. */
11476 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11477 cu
->language
= language_opencl
;
11479 /* Similar hack for Go. */
11480 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11481 set_cu_language (DW_LANG_Go
, cu
);
11483 dwarf2_start_symtab (cu
, fnd
.name
, fnd
.comp_dir
, lowpc
);
11485 /* Decode line number information if present. We do this before
11486 processing child DIEs, so that the line header table is available
11487 for DW_AT_decl_file. */
11488 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11490 /* Process all dies in compilation unit. */
11491 if (die
->child
!= NULL
)
11493 child_die
= die
->child
;
11494 while (child_die
&& child_die
->tag
)
11496 process_die (child_die
, cu
);
11497 child_die
= sibling_die (child_die
);
11501 /* Decode macro information, if present. Dwarf 2 macro information
11502 refers to information in the line number info statement program
11503 header, so we can only read it if we've read the header
11505 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11507 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11508 if (attr
&& cu
->line_header
)
11510 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11511 complaint (&symfile_complaints
,
11512 _("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11514 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11518 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11519 if (attr
&& cu
->line_header
)
11521 unsigned int macro_offset
= DW_UNSND (attr
);
11523 dwarf_decode_macros (cu
, macro_offset
, 0);
11528 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
11529 Create the set of symtabs used by this TU, or if this TU is sharing
11530 symtabs with another TU and the symtabs have already been created
11531 then restore those symtabs in the line header.
11532 We don't need the pc/line-number mapping for type units. */
11535 setup_type_unit_groups (struct die_info
*die
, struct dwarf2_cu
*cu
)
11537 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
11538 struct type_unit_group
*tu_group
;
11540 struct attribute
*attr
;
11542 struct signatured_type
*sig_type
;
11544 gdb_assert (per_cu
->is_debug_types
);
11545 sig_type
= (struct signatured_type
*) per_cu
;
11547 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11549 /* If we're using .gdb_index (includes -readnow) then
11550 per_cu->type_unit_group may not have been set up yet. */
11551 if (sig_type
->type_unit_group
== NULL
)
11552 sig_type
->type_unit_group
= get_type_unit_group (cu
, attr
);
11553 tu_group
= sig_type
->type_unit_group
;
11555 /* If we've already processed this stmt_list there's no real need to
11556 do it again, we could fake it and just recreate the part we need
11557 (file name,index -> symtab mapping). If data shows this optimization
11558 is useful we can do it then. */
11559 first_time
= tu_group
->compunit_symtab
== NULL
;
11561 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11566 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11567 lh
= dwarf_decode_line_header (line_offset
, cu
);
11572 dwarf2_start_symtab (cu
, "", NULL
, 0);
11575 gdb_assert (tu_group
->symtabs
== NULL
);
11576 restart_symtab (tu_group
->compunit_symtab
, "", 0);
11581 cu
->line_header
= lh
.release ();
11582 cu
->line_header_die_owner
= die
;
11586 struct compunit_symtab
*cust
= dwarf2_start_symtab (cu
, "", NULL
, 0);
11588 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11589 still initializing it, and our caller (a few levels up)
11590 process_full_type_unit still needs to know if this is the first
11593 tu_group
->num_symtabs
= cu
->line_header
->file_names
.size ();
11594 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
11595 cu
->line_header
->file_names
.size ());
11597 for (i
= 0; i
< cu
->line_header
->file_names
.size (); ++i
)
11599 file_entry
&fe
= cu
->line_header
->file_names
[i
];
11601 dwarf2_start_subfile (fe
.name
, fe
.include_dir (cu
->line_header
));
11603 if (current_subfile
->symtab
== NULL
)
11605 /* NOTE: start_subfile will recognize when it's been
11606 passed a file it has already seen. So we can't
11607 assume there's a simple mapping from
11608 cu->line_header->file_names to subfiles, plus
11609 cu->line_header->file_names may contain dups. */
11610 current_subfile
->symtab
11611 = allocate_symtab (cust
, current_subfile
->name
);
11614 fe
.symtab
= current_subfile
->symtab
;
11615 tu_group
->symtabs
[i
] = fe
.symtab
;
11620 restart_symtab (tu_group
->compunit_symtab
, "", 0);
11622 for (i
= 0; i
< cu
->line_header
->file_names
.size (); ++i
)
11624 file_entry
&fe
= cu
->line_header
->file_names
[i
];
11626 fe
.symtab
= tu_group
->symtabs
[i
];
11630 /* The main symtab is allocated last. Type units don't have DW_AT_name
11631 so they don't have a "real" (so to speak) symtab anyway.
11632 There is later code that will assign the main symtab to all symbols
11633 that don't have one. We need to handle the case of a symbol with a
11634 missing symtab (DW_AT_decl_file) anyway. */
11637 /* Process DW_TAG_type_unit.
11638 For TUs we want to skip the first top level sibling if it's not the
11639 actual type being defined by this TU. In this case the first top
11640 level sibling is there to provide context only. */
11643 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11645 struct die_info
*child_die
;
11647 prepare_one_comp_unit (cu
, die
, language_minimal
);
11649 /* Initialize (or reinitialize) the machinery for building symtabs.
11650 We do this before processing child DIEs, so that the line header table
11651 is available for DW_AT_decl_file. */
11652 setup_type_unit_groups (die
, cu
);
11654 if (die
->child
!= NULL
)
11656 child_die
= die
->child
;
11657 while (child_die
&& child_die
->tag
)
11659 process_die (child_die
, cu
);
11660 child_die
= sibling_die (child_die
);
11667 http://gcc.gnu.org/wiki/DebugFission
11668 http://gcc.gnu.org/wiki/DebugFissionDWP
11670 To simplify handling of both DWO files ("object" files with the DWARF info)
11671 and DWP files (a file with the DWOs packaged up into one file), we treat
11672 DWP files as having a collection of virtual DWO files. */
11675 hash_dwo_file (const void *item
)
11677 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11680 hash
= htab_hash_string (dwo_file
->dwo_name
);
11681 if (dwo_file
->comp_dir
!= NULL
)
11682 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11687 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11689 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11690 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11692 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11694 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11695 return lhs
->comp_dir
== rhs
->comp_dir
;
11696 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11699 /* Allocate a hash table for DWO files. */
11702 allocate_dwo_file_hash_table (struct objfile
*objfile
)
11704 return htab_create_alloc_ex (41,
11708 &objfile
->objfile_obstack
,
11709 hashtab_obstack_allocate
,
11710 dummy_obstack_deallocate
);
11713 /* Lookup DWO file DWO_NAME. */
11716 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11717 const char *dwo_name
,
11718 const char *comp_dir
)
11720 struct dwo_file find_entry
;
11723 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11724 dwarf2_per_objfile
->dwo_files
11725 = allocate_dwo_file_hash_table (dwarf2_per_objfile
->objfile
);
11727 memset (&find_entry
, 0, sizeof (find_entry
));
11728 find_entry
.dwo_name
= dwo_name
;
11729 find_entry
.comp_dir
= comp_dir
;
11730 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
11736 hash_dwo_unit (const void *item
)
11738 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11740 /* This drops the top 32 bits of the id, but is ok for a hash. */
11741 return dwo_unit
->signature
;
11745 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11747 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11748 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11750 /* The signature is assumed to be unique within the DWO file.
11751 So while object file CU dwo_id's always have the value zero,
11752 that's OK, assuming each object file DWO file has only one CU,
11753 and that's the rule for now. */
11754 return lhs
->signature
== rhs
->signature
;
11757 /* Allocate a hash table for DWO CUs,TUs.
11758 There is one of these tables for each of CUs,TUs for each DWO file. */
11761 allocate_dwo_unit_table (struct objfile
*objfile
)
11763 /* Start out with a pretty small number.
11764 Generally DWO files contain only one CU and maybe some TUs. */
11765 return htab_create_alloc_ex (3,
11769 &objfile
->objfile_obstack
,
11770 hashtab_obstack_allocate
,
11771 dummy_obstack_deallocate
);
11774 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
11776 struct create_dwo_cu_data
11778 struct dwo_file
*dwo_file
;
11779 struct dwo_unit dwo_unit
;
11782 /* die_reader_func for create_dwo_cu. */
11785 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11786 const gdb_byte
*info_ptr
,
11787 struct die_info
*comp_unit_die
,
11791 struct dwarf2_cu
*cu
= reader
->cu
;
11792 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11793 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11794 struct create_dwo_cu_data
*data
= (struct create_dwo_cu_data
*) datap
;
11795 struct dwo_file
*dwo_file
= data
->dwo_file
;
11796 struct dwo_unit
*dwo_unit
= &data
->dwo_unit
;
11797 struct attribute
*attr
;
11799 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
11802 complaint (&symfile_complaints
,
11803 _("Dwarf Error: debug entry at offset %s is missing"
11804 " its dwo_id [in module %s]"),
11805 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11809 dwo_unit
->dwo_file
= dwo_file
;
11810 dwo_unit
->signature
= DW_UNSND (attr
);
11811 dwo_unit
->section
= section
;
11812 dwo_unit
->sect_off
= sect_off
;
11813 dwo_unit
->length
= cu
->per_cu
->length
;
11815 if (dwarf_read_debug
)
11816 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11817 sect_offset_str (sect_off
),
11818 hex_string (dwo_unit
->signature
));
11821 /* Create the dwo_units for the CUs in a DWO_FILE.
11822 Note: This function processes DWO files only, not DWP files. */
11825 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11826 struct dwo_file
&dwo_file
, dwarf2_section_info
§ion
,
11829 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11830 const gdb_byte
*info_ptr
, *end_ptr
;
11832 dwarf2_read_section (objfile
, §ion
);
11833 info_ptr
= section
.buffer
;
11835 if (info_ptr
== NULL
)
11838 if (dwarf_read_debug
)
11840 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11841 get_section_name (§ion
),
11842 get_section_file_name (§ion
));
11845 end_ptr
= info_ptr
+ section
.size
;
11846 while (info_ptr
< end_ptr
)
11848 struct dwarf2_per_cu_data per_cu
;
11849 struct create_dwo_cu_data create_dwo_cu_data
;
11850 struct dwo_unit
*dwo_unit
;
11852 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11854 memset (&create_dwo_cu_data
.dwo_unit
, 0,
11855 sizeof (create_dwo_cu_data
.dwo_unit
));
11856 memset (&per_cu
, 0, sizeof (per_cu
));
11857 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11858 per_cu
.is_debug_types
= 0;
11859 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11860 per_cu
.section
= §ion
;
11861 create_dwo_cu_data
.dwo_file
= &dwo_file
;
11863 init_cutu_and_read_dies_no_follow (
11864 &per_cu
, &dwo_file
, create_dwo_cu_reader
, &create_dwo_cu_data
);
11865 info_ptr
+= per_cu
.length
;
11867 // If the unit could not be parsed, skip it.
11868 if (create_dwo_cu_data
.dwo_unit
.dwo_file
== NULL
)
11871 if (cus_htab
== NULL
)
11872 cus_htab
= allocate_dwo_unit_table (objfile
);
11874 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11875 *dwo_unit
= create_dwo_cu_data
.dwo_unit
;
11876 slot
= htab_find_slot (cus_htab
, dwo_unit
, INSERT
);
11877 gdb_assert (slot
!= NULL
);
11880 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11881 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11883 complaint (&symfile_complaints
,
11884 _("debug cu entry at offset %s is duplicate to"
11885 " the entry at offset %s, signature %s"),
11886 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11887 hex_string (dwo_unit
->signature
));
11889 *slot
= (void *)dwo_unit
;
11893 /* DWP file .debug_{cu,tu}_index section format:
11894 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11898 Both index sections have the same format, and serve to map a 64-bit
11899 signature to a set of section numbers. Each section begins with a header,
11900 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11901 indexes, and a pool of 32-bit section numbers. The index sections will be
11902 aligned at 8-byte boundaries in the file.
11904 The index section header consists of:
11906 V, 32 bit version number
11908 N, 32 bit number of compilation units or type units in the index
11909 M, 32 bit number of slots in the hash table
11911 Numbers are recorded using the byte order of the application binary.
11913 The hash table begins at offset 16 in the section, and consists of an array
11914 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11915 order of the application binary). Unused slots in the hash table are 0.
11916 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11918 The parallel table begins immediately after the hash table
11919 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11920 array of 32-bit indexes (using the byte order of the application binary),
11921 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11922 table contains a 32-bit index into the pool of section numbers. For unused
11923 hash table slots, the corresponding entry in the parallel table will be 0.
11925 The pool of section numbers begins immediately following the hash table
11926 (at offset 16 + 12 * M from the beginning of the section). The pool of
11927 section numbers consists of an array of 32-bit words (using the byte order
11928 of the application binary). Each item in the array is indexed starting
11929 from 0. The hash table entry provides the index of the first section
11930 number in the set. Additional section numbers in the set follow, and the
11931 set is terminated by a 0 entry (section number 0 is not used in ELF).
11933 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11934 section must be the first entry in the set, and the .debug_abbrev.dwo must
11935 be the second entry. Other members of the set may follow in any order.
11941 DWP Version 2 combines all the .debug_info, etc. sections into one,
11942 and the entries in the index tables are now offsets into these sections.
11943 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11946 Index Section Contents:
11948 Hash Table of Signatures dwp_hash_table.hash_table
11949 Parallel Table of Indices dwp_hash_table.unit_table
11950 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11951 Table of Section Sizes dwp_hash_table.v2.sizes
11953 The index section header consists of:
11955 V, 32 bit version number
11956 L, 32 bit number of columns in the table of section offsets
11957 N, 32 bit number of compilation units or type units in the index
11958 M, 32 bit number of slots in the hash table
11960 Numbers are recorded using the byte order of the application binary.
11962 The hash table has the same format as version 1.
11963 The parallel table of indices has the same format as version 1,
11964 except that the entries are origin-1 indices into the table of sections
11965 offsets and the table of section sizes.
11967 The table of offsets begins immediately following the parallel table
11968 (at offset 16 + 12 * M from the beginning of the section). The table is
11969 a two-dimensional array of 32-bit words (using the byte order of the
11970 application binary), with L columns and N+1 rows, in row-major order.
11971 Each row in the array is indexed starting from 0. The first row provides
11972 a key to the remaining rows: each column in this row provides an identifier
11973 for a debug section, and the offsets in the same column of subsequent rows
11974 refer to that section. The section identifiers are:
11976 DW_SECT_INFO 1 .debug_info.dwo
11977 DW_SECT_TYPES 2 .debug_types.dwo
11978 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11979 DW_SECT_LINE 4 .debug_line.dwo
11980 DW_SECT_LOC 5 .debug_loc.dwo
11981 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11982 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11983 DW_SECT_MACRO 8 .debug_macro.dwo
11985 The offsets provided by the CU and TU index sections are the base offsets
11986 for the contributions made by each CU or TU to the corresponding section
11987 in the package file. Each CU and TU header contains an abbrev_offset
11988 field, used to find the abbreviations table for that CU or TU within the
11989 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11990 be interpreted as relative to the base offset given in the index section.
11991 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11992 should be interpreted as relative to the base offset for .debug_line.dwo,
11993 and offsets into other debug sections obtained from DWARF attributes should
11994 also be interpreted as relative to the corresponding base offset.
11996 The table of sizes begins immediately following the table of offsets.
11997 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11998 with L columns and N rows, in row-major order. Each row in the array is
11999 indexed starting from 1 (row 0 is shared by the two tables).
12003 Hash table lookup is handled the same in version 1 and 2:
12005 We assume that N and M will not exceed 2^32 - 1.
12006 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
12008 Given a 64-bit compilation unit signature or a type signature S, an entry
12009 in the hash table is located as follows:
12011 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
12012 the low-order k bits all set to 1.
12014 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
12016 3) If the hash table entry at index H matches the signature, use that
12017 entry. If the hash table entry at index H is unused (all zeroes),
12018 terminate the search: the signature is not present in the table.
12020 4) Let H = (H + H') modulo M. Repeat at Step 3.
12022 Because M > N and H' and M are relatively prime, the search is guaranteed
12023 to stop at an unused slot or find the match. */
12025 /* Create a hash table to map DWO IDs to their CU/TU entry in
12026 .debug_{info,types}.dwo in DWP_FILE.
12027 Returns NULL if there isn't one.
12028 Note: This function processes DWP files only, not DWO files. */
12030 static struct dwp_hash_table
*
12031 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12032 struct dwp_file
*dwp_file
, int is_debug_types
)
12034 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12035 bfd
*dbfd
= dwp_file
->dbfd
;
12036 const gdb_byte
*index_ptr
, *index_end
;
12037 struct dwarf2_section_info
*index
;
12038 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
12039 struct dwp_hash_table
*htab
;
12041 if (is_debug_types
)
12042 index
= &dwp_file
->sections
.tu_index
;
12044 index
= &dwp_file
->sections
.cu_index
;
12046 if (dwarf2_section_empty_p (index
))
12048 dwarf2_read_section (objfile
, index
);
12050 index_ptr
= index
->buffer
;
12051 index_end
= index_ptr
+ index
->size
;
12053 version
= read_4_bytes (dbfd
, index_ptr
);
12056 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
12060 nr_units
= read_4_bytes (dbfd
, index_ptr
);
12062 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
12065 if (version
!= 1 && version
!= 2)
12067 error (_("Dwarf Error: unsupported DWP file version (%s)"
12068 " [in module %s]"),
12069 pulongest (version
), dwp_file
->name
);
12071 if (nr_slots
!= (nr_slots
& -nr_slots
))
12073 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
12074 " is not power of 2 [in module %s]"),
12075 pulongest (nr_slots
), dwp_file
->name
);
12078 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
12079 htab
->version
= version
;
12080 htab
->nr_columns
= nr_columns
;
12081 htab
->nr_units
= nr_units
;
12082 htab
->nr_slots
= nr_slots
;
12083 htab
->hash_table
= index_ptr
;
12084 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
12086 /* Exit early if the table is empty. */
12087 if (nr_slots
== 0 || nr_units
== 0
12088 || (version
== 2 && nr_columns
== 0))
12090 /* All must be zero. */
12091 if (nr_slots
!= 0 || nr_units
!= 0
12092 || (version
== 2 && nr_columns
!= 0))
12094 complaint (&symfile_complaints
,
12095 _("Empty DWP but nr_slots,nr_units,nr_columns not"
12096 " all zero [in modules %s]"),
12104 htab
->section_pool
.v1
.indices
=
12105 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12106 /* It's harder to decide whether the section is too small in v1.
12107 V1 is deprecated anyway so we punt. */
12111 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12112 int *ids
= htab
->section_pool
.v2
.section_ids
;
12113 /* Reverse map for error checking. */
12114 int ids_seen
[DW_SECT_MAX
+ 1];
12117 if (nr_columns
< 2)
12119 error (_("Dwarf Error: bad DWP hash table, too few columns"
12120 " in section table [in module %s]"),
12123 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
12125 error (_("Dwarf Error: bad DWP hash table, too many columns"
12126 " in section table [in module %s]"),
12129 memset (ids
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
12130 memset (ids_seen
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
12131 for (i
= 0; i
< nr_columns
; ++i
)
12133 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
12135 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
12137 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
12138 " in section table [in module %s]"),
12139 id
, dwp_file
->name
);
12141 if (ids_seen
[id
] != -1)
12143 error (_("Dwarf Error: bad DWP hash table, duplicate section"
12144 " id %d in section table [in module %s]"),
12145 id
, dwp_file
->name
);
12150 /* Must have exactly one info or types section. */
12151 if (((ids_seen
[DW_SECT_INFO
] != -1)
12152 + (ids_seen
[DW_SECT_TYPES
] != -1))
12155 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
12156 " DWO info/types section [in module %s]"),
12159 /* Must have an abbrev section. */
12160 if (ids_seen
[DW_SECT_ABBREV
] == -1)
12162 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
12163 " section [in module %s]"),
12166 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
12167 htab
->section_pool
.v2
.sizes
=
12168 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
12169 * nr_units
* nr_columns
);
12170 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
12171 * nr_units
* nr_columns
))
12174 error (_("Dwarf Error: DWP index section is corrupt (too small)"
12175 " [in module %s]"),
12183 /* Update SECTIONS with the data from SECTP.
12185 This function is like the other "locate" section routines that are
12186 passed to bfd_map_over_sections, but in this context the sections to
12187 read comes from the DWP V1 hash table, not the full ELF section table.
12189 The result is non-zero for success, or zero if an error was found. */
12192 locate_v1_virtual_dwo_sections (asection
*sectp
,
12193 struct virtual_v1_dwo_sections
*sections
)
12195 const struct dwop_section_names
*names
= &dwop_section_names
;
12197 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12199 /* There can be only one. */
12200 if (sections
->abbrev
.s
.section
!= NULL
)
12202 sections
->abbrev
.s
.section
= sectp
;
12203 sections
->abbrev
.size
= bfd_get_section_size (sectp
);
12205 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
12206 || section_is_p (sectp
->name
, &names
->types_dwo
))
12208 /* There can be only one. */
12209 if (sections
->info_or_types
.s
.section
!= NULL
)
12211 sections
->info_or_types
.s
.section
= sectp
;
12212 sections
->info_or_types
.size
= bfd_get_section_size (sectp
);
12214 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12216 /* There can be only one. */
12217 if (sections
->line
.s
.section
!= NULL
)
12219 sections
->line
.s
.section
= sectp
;
12220 sections
->line
.size
= bfd_get_section_size (sectp
);
12222 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12224 /* There can be only one. */
12225 if (sections
->loc
.s
.section
!= NULL
)
12227 sections
->loc
.s
.section
= sectp
;
12228 sections
->loc
.size
= bfd_get_section_size (sectp
);
12230 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12232 /* There can be only one. */
12233 if (sections
->macinfo
.s
.section
!= NULL
)
12235 sections
->macinfo
.s
.section
= sectp
;
12236 sections
->macinfo
.size
= bfd_get_section_size (sectp
);
12238 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12240 /* There can be only one. */
12241 if (sections
->macro
.s
.section
!= NULL
)
12243 sections
->macro
.s
.section
= sectp
;
12244 sections
->macro
.size
= bfd_get_section_size (sectp
);
12246 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12248 /* There can be only one. */
12249 if (sections
->str_offsets
.s
.section
!= NULL
)
12251 sections
->str_offsets
.s
.section
= sectp
;
12252 sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
12256 /* No other kind of section is valid. */
12263 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12264 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12265 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12266 This is for DWP version 1 files. */
12268 static struct dwo_unit
*
12269 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12270 struct dwp_file
*dwp_file
,
12271 uint32_t unit_index
,
12272 const char *comp_dir
,
12273 ULONGEST signature
, int is_debug_types
)
12275 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12276 const struct dwp_hash_table
*dwp_htab
=
12277 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12278 bfd
*dbfd
= dwp_file
->dbfd
;
12279 const char *kind
= is_debug_types
? "TU" : "CU";
12280 struct dwo_file
*dwo_file
;
12281 struct dwo_unit
*dwo_unit
;
12282 struct virtual_v1_dwo_sections sections
;
12283 void **dwo_file_slot
;
12286 gdb_assert (dwp_file
->version
== 1);
12288 if (dwarf_read_debug
)
12290 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
12292 pulongest (unit_index
), hex_string (signature
),
12296 /* Fetch the sections of this DWO unit.
12297 Put a limit on the number of sections we look for so that bad data
12298 doesn't cause us to loop forever. */
12300 #define MAX_NR_V1_DWO_SECTIONS \
12301 (1 /* .debug_info or .debug_types */ \
12302 + 1 /* .debug_abbrev */ \
12303 + 1 /* .debug_line */ \
12304 + 1 /* .debug_loc */ \
12305 + 1 /* .debug_str_offsets */ \
12306 + 1 /* .debug_macro or .debug_macinfo */ \
12307 + 1 /* trailing zero */)
12309 memset (§ions
, 0, sizeof (sections
));
12311 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12314 uint32_t section_nr
=
12315 read_4_bytes (dbfd
,
12316 dwp_htab
->section_pool
.v1
.indices
12317 + (unit_index
+ i
) * sizeof (uint32_t));
12319 if (section_nr
== 0)
12321 if (section_nr
>= dwp_file
->num_sections
)
12323 error (_("Dwarf Error: bad DWP hash table, section number too large"
12324 " [in module %s]"),
12328 sectp
= dwp_file
->elf_sections
[section_nr
];
12329 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12331 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12332 " [in module %s]"),
12338 || dwarf2_section_empty_p (§ions
.info_or_types
)
12339 || dwarf2_section_empty_p (§ions
.abbrev
))
12341 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12342 " [in module %s]"),
12345 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12347 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12348 " [in module %s]"),
12352 /* It's easier for the rest of the code if we fake a struct dwo_file and
12353 have dwo_unit "live" in that. At least for now.
12355 The DWP file can be made up of a random collection of CUs and TUs.
12356 However, for each CU + set of TUs that came from the same original DWO
12357 file, we can combine them back into a virtual DWO file to save space
12358 (fewer struct dwo_file objects to allocate). Remember that for really
12359 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12361 std::string virtual_dwo_name
=
12362 string_printf ("virtual-dwo/%d-%d-%d-%d",
12363 get_section_id (§ions
.abbrev
),
12364 get_section_id (§ions
.line
),
12365 get_section_id (§ions
.loc
),
12366 get_section_id (§ions
.str_offsets
));
12367 /* Can we use an existing virtual DWO file? */
12368 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12369 virtual_dwo_name
.c_str (),
12371 /* Create one if necessary. */
12372 if (*dwo_file_slot
== NULL
)
12374 if (dwarf_read_debug
)
12376 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12377 virtual_dwo_name
.c_str ());
12379 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
12381 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
12382 virtual_dwo_name
.c_str (),
12383 virtual_dwo_name
.size ());
12384 dwo_file
->comp_dir
= comp_dir
;
12385 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12386 dwo_file
->sections
.line
= sections
.line
;
12387 dwo_file
->sections
.loc
= sections
.loc
;
12388 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12389 dwo_file
->sections
.macro
= sections
.macro
;
12390 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12391 /* The "str" section is global to the entire DWP file. */
12392 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12393 /* The info or types section is assigned below to dwo_unit,
12394 there's no need to record it in dwo_file.
12395 Also, we can't simply record type sections in dwo_file because
12396 we record a pointer into the vector in dwo_unit. As we collect more
12397 types we'll grow the vector and eventually have to reallocate space
12398 for it, invalidating all copies of pointers into the previous
12400 *dwo_file_slot
= dwo_file
;
12404 if (dwarf_read_debug
)
12406 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12407 virtual_dwo_name
.c_str ());
12409 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12412 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12413 dwo_unit
->dwo_file
= dwo_file
;
12414 dwo_unit
->signature
= signature
;
12415 dwo_unit
->section
=
12416 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12417 *dwo_unit
->section
= sections
.info_or_types
;
12418 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12423 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
12424 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
12425 piece within that section used by a TU/CU, return a virtual section
12426 of just that piece. */
12428 static struct dwarf2_section_info
12429 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12430 struct dwarf2_section_info
*section
,
12431 bfd_size_type offset
, bfd_size_type size
)
12433 struct dwarf2_section_info result
;
12436 gdb_assert (section
!= NULL
);
12437 gdb_assert (!section
->is_virtual
);
12439 memset (&result
, 0, sizeof (result
));
12440 result
.s
.containing_section
= section
;
12441 result
.is_virtual
= 1;
12446 sectp
= get_section_bfd_section (section
);
12448 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12449 bounds of the real section. This is a pretty-rare event, so just
12450 flag an error (easier) instead of a warning and trying to cope. */
12452 || offset
+ size
> bfd_get_section_size (sectp
))
12454 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12455 " in section %s [in module %s]"),
12456 sectp
? bfd_section_name (abfd
, sectp
) : "<unknown>",
12457 objfile_name (dwarf2_per_objfile
->objfile
));
12460 result
.virtual_offset
= offset
;
12461 result
.size
= size
;
12465 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12466 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12467 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12468 This is for DWP version 2 files. */
12470 static struct dwo_unit
*
12471 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12472 struct dwp_file
*dwp_file
,
12473 uint32_t unit_index
,
12474 const char *comp_dir
,
12475 ULONGEST signature
, int is_debug_types
)
12477 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12478 const struct dwp_hash_table
*dwp_htab
=
12479 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12480 bfd
*dbfd
= dwp_file
->dbfd
;
12481 const char *kind
= is_debug_types
? "TU" : "CU";
12482 struct dwo_file
*dwo_file
;
12483 struct dwo_unit
*dwo_unit
;
12484 struct virtual_v2_dwo_sections sections
;
12485 void **dwo_file_slot
;
12488 gdb_assert (dwp_file
->version
== 2);
12490 if (dwarf_read_debug
)
12492 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
12494 pulongest (unit_index
), hex_string (signature
),
12498 /* Fetch the section offsets of this DWO unit. */
12500 memset (§ions
, 0, sizeof (sections
));
12502 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12504 uint32_t offset
= read_4_bytes (dbfd
,
12505 dwp_htab
->section_pool
.v2
.offsets
12506 + (((unit_index
- 1) * dwp_htab
->nr_columns
12508 * sizeof (uint32_t)));
12509 uint32_t size
= read_4_bytes (dbfd
,
12510 dwp_htab
->section_pool
.v2
.sizes
12511 + (((unit_index
- 1) * dwp_htab
->nr_columns
12513 * sizeof (uint32_t)));
12515 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12518 case DW_SECT_TYPES
:
12519 sections
.info_or_types_offset
= offset
;
12520 sections
.info_or_types_size
= size
;
12522 case DW_SECT_ABBREV
:
12523 sections
.abbrev_offset
= offset
;
12524 sections
.abbrev_size
= size
;
12527 sections
.line_offset
= offset
;
12528 sections
.line_size
= size
;
12531 sections
.loc_offset
= offset
;
12532 sections
.loc_size
= size
;
12534 case DW_SECT_STR_OFFSETS
:
12535 sections
.str_offsets_offset
= offset
;
12536 sections
.str_offsets_size
= size
;
12538 case DW_SECT_MACINFO
:
12539 sections
.macinfo_offset
= offset
;
12540 sections
.macinfo_size
= size
;
12542 case DW_SECT_MACRO
:
12543 sections
.macro_offset
= offset
;
12544 sections
.macro_size
= size
;
12549 /* It's easier for the rest of the code if we fake a struct dwo_file and
12550 have dwo_unit "live" in that. At least for now.
12552 The DWP file can be made up of a random collection of CUs and TUs.
12553 However, for each CU + set of TUs that came from the same original DWO
12554 file, we can combine them back into a virtual DWO file to save space
12555 (fewer struct dwo_file objects to allocate). Remember that for really
12556 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12558 std::string virtual_dwo_name
=
12559 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12560 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12561 (long) (sections
.line_size
? sections
.line_offset
: 0),
12562 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12563 (long) (sections
.str_offsets_size
12564 ? sections
.str_offsets_offset
: 0));
12565 /* Can we use an existing virtual DWO file? */
12566 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12567 virtual_dwo_name
.c_str (),
12569 /* Create one if necessary. */
12570 if (*dwo_file_slot
== NULL
)
12572 if (dwarf_read_debug
)
12574 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12575 virtual_dwo_name
.c_str ());
12577 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
12579 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
12580 virtual_dwo_name
.c_str (),
12581 virtual_dwo_name
.size ());
12582 dwo_file
->comp_dir
= comp_dir
;
12583 dwo_file
->sections
.abbrev
=
12584 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
12585 sections
.abbrev_offset
, sections
.abbrev_size
);
12586 dwo_file
->sections
.line
=
12587 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
12588 sections
.line_offset
, sections
.line_size
);
12589 dwo_file
->sections
.loc
=
12590 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
12591 sections
.loc_offset
, sections
.loc_size
);
12592 dwo_file
->sections
.macinfo
=
12593 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
12594 sections
.macinfo_offset
, sections
.macinfo_size
);
12595 dwo_file
->sections
.macro
=
12596 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
12597 sections
.macro_offset
, sections
.macro_size
);
12598 dwo_file
->sections
.str_offsets
=
12599 create_dwp_v2_section (dwarf2_per_objfile
,
12600 &dwp_file
->sections
.str_offsets
,
12601 sections
.str_offsets_offset
,
12602 sections
.str_offsets_size
);
12603 /* The "str" section is global to the entire DWP file. */
12604 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12605 /* The info or types section is assigned below to dwo_unit,
12606 there's no need to record it in dwo_file.
12607 Also, we can't simply record type sections in dwo_file because
12608 we record a pointer into the vector in dwo_unit. As we collect more
12609 types we'll grow the vector and eventually have to reallocate space
12610 for it, invalidating all copies of pointers into the previous
12612 *dwo_file_slot
= dwo_file
;
12616 if (dwarf_read_debug
)
12618 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12619 virtual_dwo_name
.c_str ());
12621 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12624 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12625 dwo_unit
->dwo_file
= dwo_file
;
12626 dwo_unit
->signature
= signature
;
12627 dwo_unit
->section
=
12628 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12629 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
12631 ? &dwp_file
->sections
.types
12632 : &dwp_file
->sections
.info
,
12633 sections
.info_or_types_offset
,
12634 sections
.info_or_types_size
);
12635 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12640 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12641 Returns NULL if the signature isn't found. */
12643 static struct dwo_unit
*
12644 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12645 struct dwp_file
*dwp_file
, const char *comp_dir
,
12646 ULONGEST signature
, int is_debug_types
)
12648 const struct dwp_hash_table
*dwp_htab
=
12649 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12650 bfd
*dbfd
= dwp_file
->dbfd
;
12651 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12652 uint32_t hash
= signature
& mask
;
12653 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12656 struct dwo_unit find_dwo_cu
;
12658 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12659 find_dwo_cu
.signature
= signature
;
12660 slot
= htab_find_slot (is_debug_types
12661 ? dwp_file
->loaded_tus
12662 : dwp_file
->loaded_cus
,
12663 &find_dwo_cu
, INSERT
);
12666 return (struct dwo_unit
*) *slot
;
12668 /* Use a for loop so that we don't loop forever on bad debug info. */
12669 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12671 ULONGEST signature_in_table
;
12673 signature_in_table
=
12674 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12675 if (signature_in_table
== signature
)
12677 uint32_t unit_index
=
12678 read_4_bytes (dbfd
,
12679 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12681 if (dwp_file
->version
== 1)
12683 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
12684 dwp_file
, unit_index
,
12685 comp_dir
, signature
,
12690 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
12691 dwp_file
, unit_index
,
12692 comp_dir
, signature
,
12695 return (struct dwo_unit
*) *slot
;
12697 if (signature_in_table
== 0)
12699 hash
= (hash
+ hash2
) & mask
;
12702 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12703 " [in module %s]"),
12707 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12708 Open the file specified by FILE_NAME and hand it off to BFD for
12709 preliminary analysis. Return a newly initialized bfd *, which
12710 includes a canonicalized copy of FILE_NAME.
12711 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12712 SEARCH_CWD is true if the current directory is to be searched.
12713 It will be searched before debug-file-directory.
12714 If successful, the file is added to the bfd include table of the
12715 objfile's bfd (see gdb_bfd_record_inclusion).
12716 If unable to find/open the file, return NULL.
12717 NOTE: This function is derived from symfile_bfd_open. */
12719 static gdb_bfd_ref_ptr
12720 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12721 const char *file_name
, int is_dwp
, int search_cwd
)
12724 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12725 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12726 to debug_file_directory. */
12727 const char *search_path
;
12728 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12730 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12733 if (*debug_file_directory
!= '\0')
12735 search_path_holder
.reset (concat (".", dirname_separator_string
,
12736 debug_file_directory
,
12738 search_path
= search_path_holder
.get ();
12744 search_path
= debug_file_directory
;
12746 openp_flags flags
= OPF_RETURN_REALPATH
;
12748 flags
|= OPF_SEARCH_IN_PATH
;
12750 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12751 desc
= openp (search_path
, flags
, file_name
,
12752 O_RDONLY
| O_BINARY
, &absolute_name
);
12756 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12758 if (sym_bfd
== NULL
)
12760 bfd_set_cacheable (sym_bfd
.get (), 1);
12762 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12765 /* Success. Record the bfd as having been included by the objfile's bfd.
12766 This is important because things like demangled_names_hash lives in the
12767 objfile's per_bfd space and may have references to things like symbol
12768 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12769 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12774 /* Try to open DWO file FILE_NAME.
12775 COMP_DIR is the DW_AT_comp_dir attribute.
12776 The result is the bfd handle of the file.
12777 If there is a problem finding or opening the file, return NULL.
12778 Upon success, the canonicalized path of the file is stored in the bfd,
12779 same as symfile_bfd_open. */
12781 static gdb_bfd_ref_ptr
12782 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12783 const char *file_name
, const char *comp_dir
)
12785 if (IS_ABSOLUTE_PATH (file_name
))
12786 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12787 0 /*is_dwp*/, 0 /*search_cwd*/);
12789 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12791 if (comp_dir
!= NULL
)
12793 char *path_to_try
= concat (comp_dir
, SLASH_STRING
,
12794 file_name
, (char *) NULL
);
12796 /* NOTE: If comp_dir is a relative path, this will also try the
12797 search path, which seems useful. */
12798 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12801 1 /*search_cwd*/));
12802 xfree (path_to_try
);
12807 /* That didn't work, try debug-file-directory, which, despite its name,
12808 is a list of paths. */
12810 if (*debug_file_directory
== '\0')
12813 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12814 0 /*is_dwp*/, 1 /*search_cwd*/);
12817 /* This function is mapped across the sections and remembers the offset and
12818 size of each of the DWO debugging sections we are interested in. */
12821 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12823 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12824 const struct dwop_section_names
*names
= &dwop_section_names
;
12826 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12828 dwo_sections
->abbrev
.s
.section
= sectp
;
12829 dwo_sections
->abbrev
.size
= bfd_get_section_size (sectp
);
12831 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12833 dwo_sections
->info
.s
.section
= sectp
;
12834 dwo_sections
->info
.size
= bfd_get_section_size (sectp
);
12836 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12838 dwo_sections
->line
.s
.section
= sectp
;
12839 dwo_sections
->line
.size
= bfd_get_section_size (sectp
);
12841 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12843 dwo_sections
->loc
.s
.section
= sectp
;
12844 dwo_sections
->loc
.size
= bfd_get_section_size (sectp
);
12846 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12848 dwo_sections
->macinfo
.s
.section
= sectp
;
12849 dwo_sections
->macinfo
.size
= bfd_get_section_size (sectp
);
12851 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12853 dwo_sections
->macro
.s
.section
= sectp
;
12854 dwo_sections
->macro
.size
= bfd_get_section_size (sectp
);
12856 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12858 dwo_sections
->str
.s
.section
= sectp
;
12859 dwo_sections
->str
.size
= bfd_get_section_size (sectp
);
12861 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12863 dwo_sections
->str_offsets
.s
.section
= sectp
;
12864 dwo_sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
12866 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12868 struct dwarf2_section_info type_section
;
12870 memset (&type_section
, 0, sizeof (type_section
));
12871 type_section
.s
.section
= sectp
;
12872 type_section
.size
= bfd_get_section_size (sectp
);
12873 VEC_safe_push (dwarf2_section_info_def
, dwo_sections
->types
,
12878 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12879 by PER_CU. This is for the non-DWP case.
12880 The result is NULL if DWO_NAME can't be found. */
12882 static struct dwo_file
*
12883 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12884 const char *dwo_name
, const char *comp_dir
)
12886 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12887 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12889 gdb_bfd_ref_ptr
dbfd (open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
));
12892 if (dwarf_read_debug
)
12893 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12897 /* We use a unique pointer here, despite the obstack allocation,
12898 because a dwo_file needs some cleanup if it is abandoned. */
12899 dwo_file_up
dwo_file (OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
12901 dwo_file
->dwo_name
= dwo_name
;
12902 dwo_file
->comp_dir
= comp_dir
;
12903 dwo_file
->dbfd
= dbfd
.release ();
12905 bfd_map_over_sections (dwo_file
->dbfd
, dwarf2_locate_dwo_sections
,
12906 &dwo_file
->sections
);
12908 create_cus_hash_table (dwarf2_per_objfile
, *dwo_file
, dwo_file
->sections
.info
,
12911 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12912 dwo_file
->sections
.types
, dwo_file
->tus
);
12914 if (dwarf_read_debug
)
12915 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12917 return dwo_file
.release ();
12920 /* This function is mapped across the sections and remembers the offset and
12921 size of each of the DWP debugging sections common to version 1 and 2 that
12922 we are interested in. */
12925 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12926 void *dwp_file_ptr
)
12928 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12929 const struct dwop_section_names
*names
= &dwop_section_names
;
12930 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12932 /* Record the ELF section number for later lookup: this is what the
12933 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12934 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12935 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12937 /* Look for specific sections that we need. */
12938 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12940 dwp_file
->sections
.str
.s
.section
= sectp
;
12941 dwp_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
12943 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12945 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12946 dwp_file
->sections
.cu_index
.size
= bfd_get_section_size (sectp
);
12948 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12950 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12951 dwp_file
->sections
.tu_index
.size
= bfd_get_section_size (sectp
);
12955 /* This function is mapped across the sections and remembers the offset and
12956 size of each of the DWP version 2 debugging sections that we are interested
12957 in. This is split into a separate function because we don't know if we
12958 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12961 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12963 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12964 const struct dwop_section_names
*names
= &dwop_section_names
;
12965 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12967 /* Record the ELF section number for later lookup: this is what the
12968 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12969 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12970 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12972 /* Look for specific sections that we need. */
12973 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12975 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12976 dwp_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
12978 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12980 dwp_file
->sections
.info
.s
.section
= sectp
;
12981 dwp_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
12983 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12985 dwp_file
->sections
.line
.s
.section
= sectp
;
12986 dwp_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
12988 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12990 dwp_file
->sections
.loc
.s
.section
= sectp
;
12991 dwp_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
12993 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12995 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12996 dwp_file
->sections
.macinfo
.size
= bfd_get_section_size (sectp
);
12998 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13000 dwp_file
->sections
.macro
.s
.section
= sectp
;
13001 dwp_file
->sections
.macro
.size
= bfd_get_section_size (sectp
);
13003 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13005 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
13006 dwp_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
13008 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13010 dwp_file
->sections
.types
.s
.section
= sectp
;
13011 dwp_file
->sections
.types
.size
= bfd_get_section_size (sectp
);
13015 /* Hash function for dwp_file loaded CUs/TUs. */
13018 hash_dwp_loaded_cutus (const void *item
)
13020 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
13022 /* This drops the top 32 bits of the signature, but is ok for a hash. */
13023 return dwo_unit
->signature
;
13026 /* Equality function for dwp_file loaded CUs/TUs. */
13029 eq_dwp_loaded_cutus (const void *a
, const void *b
)
13031 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
13032 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
13034 return dua
->signature
== dub
->signature
;
13037 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
13040 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
13042 return htab_create_alloc_ex (3,
13043 hash_dwp_loaded_cutus
,
13044 eq_dwp_loaded_cutus
,
13046 &objfile
->objfile_obstack
,
13047 hashtab_obstack_allocate
,
13048 dummy_obstack_deallocate
);
13051 /* Try to open DWP file FILE_NAME.
13052 The result is the bfd handle of the file.
13053 If there is a problem finding or opening the file, return NULL.
13054 Upon success, the canonicalized path of the file is stored in the bfd,
13055 same as symfile_bfd_open. */
13057 static gdb_bfd_ref_ptr
13058 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13059 const char *file_name
)
13061 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
13063 1 /*search_cwd*/));
13067 /* Work around upstream bug 15652.
13068 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
13069 [Whether that's a "bug" is debatable, but it is getting in our way.]
13070 We have no real idea where the dwp file is, because gdb's realpath-ing
13071 of the executable's path may have discarded the needed info.
13072 [IWBN if the dwp file name was recorded in the executable, akin to
13073 .gnu_debuglink, but that doesn't exist yet.]
13074 Strip the directory from FILE_NAME and search again. */
13075 if (*debug_file_directory
!= '\0')
13077 /* Don't implicitly search the current directory here.
13078 If the user wants to search "." to handle this case,
13079 it must be added to debug-file-directory. */
13080 return try_open_dwop_file (dwarf2_per_objfile
,
13081 lbasename (file_name
), 1 /*is_dwp*/,
13088 /* Initialize the use of the DWP file for the current objfile.
13089 By convention the name of the DWP file is ${objfile}.dwp.
13090 The result is NULL if it can't be found. */
13092 static struct dwp_file
*
13093 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13095 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13096 struct dwp_file
*dwp_file
;
13098 /* Try to find first .dwp for the binary file before any symbolic links
13101 /* If the objfile is a debug file, find the name of the real binary
13102 file and get the name of dwp file from there. */
13103 std::string dwp_name
;
13104 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
13106 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
13107 const char *backlink_basename
= lbasename (backlink
->original_name
);
13109 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
13112 dwp_name
= objfile
->original_name
;
13114 dwp_name
+= ".dwp";
13116 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
13118 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
13120 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
13121 dwp_name
= objfile_name (objfile
);
13122 dwp_name
+= ".dwp";
13123 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
13128 if (dwarf_read_debug
)
13129 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
13132 dwp_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_file
);
13133 dwp_file
->name
= bfd_get_filename (dbfd
.get ());
13134 dwp_file
->dbfd
= dbfd
.release ();
13136 /* +1: section 0 is unused */
13137 dwp_file
->num_sections
= bfd_count_sections (dwp_file
->dbfd
) + 1;
13138 dwp_file
->elf_sections
=
13139 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
13140 dwp_file
->num_sections
, asection
*);
13142 bfd_map_over_sections (dwp_file
->dbfd
, dwarf2_locate_common_dwp_sections
,
13145 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
, 0);
13147 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
, 1);
13149 /* The DWP file version is stored in the hash table. Oh well. */
13150 if (dwp_file
->cus
&& dwp_file
->tus
13151 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
13153 /* Technically speaking, we should try to limp along, but this is
13154 pretty bizarre. We use pulongest here because that's the established
13155 portability solution (e.g, we cannot use %u for uint32_t). */
13156 error (_("Dwarf Error: DWP file CU version %s doesn't match"
13157 " TU version %s [in DWP file %s]"),
13158 pulongest (dwp_file
->cus
->version
),
13159 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
13163 dwp_file
->version
= dwp_file
->cus
->version
;
13164 else if (dwp_file
->tus
)
13165 dwp_file
->version
= dwp_file
->tus
->version
;
13167 dwp_file
->version
= 2;
13169 if (dwp_file
->version
== 2)
13170 bfd_map_over_sections (dwp_file
->dbfd
, dwarf2_locate_v2_dwp_sections
,
13173 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
13174 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
13176 if (dwarf_read_debug
)
13178 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
13179 fprintf_unfiltered (gdb_stdlog
,
13180 " %s CUs, %s TUs\n",
13181 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13182 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13188 /* Wrapper around open_and_init_dwp_file, only open it once. */
13190 static struct dwp_file
*
13191 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13193 if (! dwarf2_per_objfile
->dwp_checked
)
13195 dwarf2_per_objfile
->dwp_file
13196 = open_and_init_dwp_file (dwarf2_per_objfile
);
13197 dwarf2_per_objfile
->dwp_checked
= 1;
13199 return dwarf2_per_objfile
->dwp_file
;
13202 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13203 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13204 or in the DWP file for the objfile, referenced by THIS_UNIT.
13205 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13206 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13208 This is called, for example, when wanting to read a variable with a
13209 complex location. Therefore we don't want to do file i/o for every call.
13210 Therefore we don't want to look for a DWO file on every call.
13211 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13212 then we check if we've already seen DWO_NAME, and only THEN do we check
13215 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13216 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13218 static struct dwo_unit
*
13219 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
13220 const char *dwo_name
, const char *comp_dir
,
13221 ULONGEST signature
, int is_debug_types
)
13223 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
13224 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13225 const char *kind
= is_debug_types
? "TU" : "CU";
13226 void **dwo_file_slot
;
13227 struct dwo_file
*dwo_file
;
13228 struct dwp_file
*dwp_file
;
13230 /* First see if there's a DWP file.
13231 If we have a DWP file but didn't find the DWO inside it, don't
13232 look for the original DWO file. It makes gdb behave differently
13233 depending on whether one is debugging in the build tree. */
13235 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
13236 if (dwp_file
!= NULL
)
13238 const struct dwp_hash_table
*dwp_htab
=
13239 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13241 if (dwp_htab
!= NULL
)
13243 struct dwo_unit
*dwo_cutu
=
13244 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
13245 signature
, is_debug_types
);
13247 if (dwo_cutu
!= NULL
)
13249 if (dwarf_read_debug
)
13251 fprintf_unfiltered (gdb_stdlog
,
13252 "Virtual DWO %s %s found: @%s\n",
13253 kind
, hex_string (signature
),
13254 host_address_to_string (dwo_cutu
));
13262 /* No DWP file, look for the DWO file. */
13264 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
13265 dwo_name
, comp_dir
);
13266 if (*dwo_file_slot
== NULL
)
13268 /* Read in the file and build a table of the CUs/TUs it contains. */
13269 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
13271 /* NOTE: This will be NULL if unable to open the file. */
13272 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13274 if (dwo_file
!= NULL
)
13276 struct dwo_unit
*dwo_cutu
= NULL
;
13278 if (is_debug_types
&& dwo_file
->tus
)
13280 struct dwo_unit find_dwo_cutu
;
13282 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13283 find_dwo_cutu
.signature
= signature
;
13285 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
13287 else if (!is_debug_types
&& dwo_file
->cus
)
13289 struct dwo_unit find_dwo_cutu
;
13291 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13292 find_dwo_cutu
.signature
= signature
;
13293 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
,
13297 if (dwo_cutu
!= NULL
)
13299 if (dwarf_read_debug
)
13301 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
13302 kind
, dwo_name
, hex_string (signature
),
13303 host_address_to_string (dwo_cutu
));
13310 /* We didn't find it. This could mean a dwo_id mismatch, or
13311 someone deleted the DWO/DWP file, or the search path isn't set up
13312 correctly to find the file. */
13314 if (dwarf_read_debug
)
13316 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
13317 kind
, dwo_name
, hex_string (signature
));
13320 /* This is a warning and not a complaint because it can be caused by
13321 pilot error (e.g., user accidentally deleting the DWO). */
13323 /* Print the name of the DWP file if we looked there, helps the user
13324 better diagnose the problem. */
13325 std::string dwp_text
;
13327 if (dwp_file
!= NULL
)
13328 dwp_text
= string_printf (" [in DWP file %s]",
13329 lbasename (dwp_file
->name
));
13331 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13332 " [in module %s]"),
13333 kind
, dwo_name
, hex_string (signature
),
13335 this_unit
->is_debug_types
? "TU" : "CU",
13336 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
13341 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13342 See lookup_dwo_cutu_unit for details. */
13344 static struct dwo_unit
*
13345 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
13346 const char *dwo_name
, const char *comp_dir
,
13347 ULONGEST signature
)
13349 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
13352 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13353 See lookup_dwo_cutu_unit for details. */
13355 static struct dwo_unit
*
13356 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
13357 const char *dwo_name
, const char *comp_dir
)
13359 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
13362 /* Traversal function for queue_and_load_all_dwo_tus. */
13365 queue_and_load_dwo_tu (void **slot
, void *info
)
13367 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13368 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
13369 ULONGEST signature
= dwo_unit
->signature
;
13370 struct signatured_type
*sig_type
=
13371 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
13373 if (sig_type
!= NULL
)
13375 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13377 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13378 a real dependency of PER_CU on SIG_TYPE. That is detected later
13379 while processing PER_CU. */
13380 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
13381 load_full_type_unit (sig_cu
);
13382 VEC_safe_push (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, sig_cu
);
13388 /* Queue all TUs contained in the DWO of PER_CU to be read in.
13389 The DWO may have the only definition of the type, though it may not be
13390 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13391 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13394 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
13396 struct dwo_unit
*dwo_unit
;
13397 struct dwo_file
*dwo_file
;
13399 gdb_assert (!per_cu
->is_debug_types
);
13400 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
13401 gdb_assert (per_cu
->cu
!= NULL
);
13403 dwo_unit
= per_cu
->cu
->dwo_unit
;
13404 gdb_assert (dwo_unit
!= NULL
);
13406 dwo_file
= dwo_unit
->dwo_file
;
13407 if (dwo_file
->tus
!= NULL
)
13408 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
13411 /* Free all resources associated with DWO_FILE.
13412 Close the DWO file and munmap the sections. */
13415 free_dwo_file (struct dwo_file
*dwo_file
)
13417 /* Note: dbfd is NULL for virtual DWO files. */
13418 gdb_bfd_unref (dwo_file
->dbfd
);
13420 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
13423 /* Traversal function for free_dwo_files. */
13426 free_dwo_file_from_slot (void **slot
, void *info
)
13428 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
13430 free_dwo_file (dwo_file
);
13435 /* Free all resources associated with DWO_FILES. */
13438 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
13440 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
13443 /* Read in various DIEs. */
13445 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13446 Inherit only the children of the DW_AT_abstract_origin DIE not being
13447 already referenced by DW_AT_abstract_origin from the children of the
13451 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13453 struct die_info
*child_die
;
13454 sect_offset
*offsetp
;
13455 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13456 struct die_info
*origin_die
;
13457 /* Iterator of the ORIGIN_DIE children. */
13458 struct die_info
*origin_child_die
;
13459 struct attribute
*attr
;
13460 struct dwarf2_cu
*origin_cu
;
13461 struct pending
**origin_previous_list_in_scope
;
13463 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13467 /* Note that following die references may follow to a die in a
13471 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13473 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13475 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13476 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13478 if (die
->tag
!= origin_die
->tag
13479 && !(die
->tag
== DW_TAG_inlined_subroutine
13480 && origin_die
->tag
== DW_TAG_subprogram
))
13481 complaint (&symfile_complaints
,
13482 _("DIE %s and its abstract origin %s have different tags"),
13483 sect_offset_str (die
->sect_off
),
13484 sect_offset_str (origin_die
->sect_off
));
13486 std::vector
<sect_offset
> offsets
;
13488 for (child_die
= die
->child
;
13489 child_die
&& child_die
->tag
;
13490 child_die
= sibling_die (child_die
))
13492 struct die_info
*child_origin_die
;
13493 struct dwarf2_cu
*child_origin_cu
;
13495 /* We are trying to process concrete instance entries:
13496 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13497 it's not relevant to our analysis here. i.e. detecting DIEs that are
13498 present in the abstract instance but not referenced in the concrete
13500 if (child_die
->tag
== DW_TAG_call_site
13501 || child_die
->tag
== DW_TAG_GNU_call_site
)
13504 /* For each CHILD_DIE, find the corresponding child of
13505 ORIGIN_DIE. If there is more than one layer of
13506 DW_AT_abstract_origin, follow them all; there shouldn't be,
13507 but GCC versions at least through 4.4 generate this (GCC PR
13509 child_origin_die
= child_die
;
13510 child_origin_cu
= cu
;
13513 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13517 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13521 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13522 counterpart may exist. */
13523 if (child_origin_die
!= child_die
)
13525 if (child_die
->tag
!= child_origin_die
->tag
13526 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13527 && child_origin_die
->tag
== DW_TAG_subprogram
))
13528 complaint (&symfile_complaints
,
13529 _("Child DIE %s and its abstract origin %s have "
13531 sect_offset_str (child_die
->sect_off
),
13532 sect_offset_str (child_origin_die
->sect_off
));
13533 if (child_origin_die
->parent
!= origin_die
)
13534 complaint (&symfile_complaints
,
13535 _("Child DIE %s and its abstract origin %s have "
13536 "different parents"),
13537 sect_offset_str (child_die
->sect_off
),
13538 sect_offset_str (child_origin_die
->sect_off
));
13540 offsets
.push_back (child_origin_die
->sect_off
);
13543 std::sort (offsets
.begin (), offsets
.end ());
13544 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13545 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13546 if (offsetp
[-1] == *offsetp
)
13547 complaint (&symfile_complaints
,
13548 _("Multiple children of DIE %s refer "
13549 "to DIE %s as their abstract origin"),
13550 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13552 offsetp
= offsets
.data ();
13553 origin_child_die
= origin_die
->child
;
13554 while (origin_child_die
&& origin_child_die
->tag
)
13556 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13557 while (offsetp
< offsets_end
13558 && *offsetp
< origin_child_die
->sect_off
)
13560 if (offsetp
>= offsets_end
13561 || *offsetp
> origin_child_die
->sect_off
)
13563 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13564 Check whether we're already processing ORIGIN_CHILD_DIE.
13565 This can happen with mutually referenced abstract_origins.
13567 if (!origin_child_die
->in_process
)
13568 process_die (origin_child_die
, origin_cu
);
13570 origin_child_die
= sibling_die (origin_child_die
);
13572 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13576 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13578 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13579 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13580 struct context_stack
*newobj
;
13583 struct die_info
*child_die
;
13584 struct attribute
*attr
, *call_line
, *call_file
;
13586 CORE_ADDR baseaddr
;
13587 struct block
*block
;
13588 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13589 std::vector
<struct symbol
*> template_args
;
13590 struct template_symbol
*templ_func
= NULL
;
13594 /* If we do not have call site information, we can't show the
13595 caller of this inlined function. That's too confusing, so
13596 only use the scope for local variables. */
13597 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13598 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13599 if (call_line
== NULL
|| call_file
== NULL
)
13601 read_lexical_block_scope (die
, cu
);
13606 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13608 name
= dwarf2_name (die
, cu
);
13610 /* Ignore functions with missing or empty names. These are actually
13611 illegal according to the DWARF standard. */
13614 complaint (&symfile_complaints
,
13615 _("missing name for subprogram DIE at %s"),
13616 sect_offset_str (die
->sect_off
));
13620 /* Ignore functions with missing or invalid low and high pc attributes. */
13621 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13622 <= PC_BOUNDS_INVALID
)
13624 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13625 if (!attr
|| !DW_UNSND (attr
))
13626 complaint (&symfile_complaints
,
13627 _("cannot get low and high bounds "
13628 "for subprogram DIE at %s"),
13629 sect_offset_str (die
->sect_off
));
13633 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13634 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13636 /* If we have any template arguments, then we must allocate a
13637 different sort of symbol. */
13638 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
13640 if (child_die
->tag
== DW_TAG_template_type_param
13641 || child_die
->tag
== DW_TAG_template_value_param
)
13643 templ_func
= allocate_template_symbol (objfile
);
13644 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13649 newobj
= push_context (0, lowpc
);
13650 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13651 (struct symbol
*) templ_func
);
13653 /* If there is a location expression for DW_AT_frame_base, record
13655 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13657 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13659 /* If there is a location for the static link, record it. */
13660 newobj
->static_link
= NULL
;
13661 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13664 newobj
->static_link
13665 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13666 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
);
13669 cu
->list_in_scope
= &local_symbols
;
13671 if (die
->child
!= NULL
)
13673 child_die
= die
->child
;
13674 while (child_die
&& child_die
->tag
)
13676 if (child_die
->tag
== DW_TAG_template_type_param
13677 || child_die
->tag
== DW_TAG_template_value_param
)
13679 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13682 template_args
.push_back (arg
);
13685 process_die (child_die
, cu
);
13686 child_die
= sibling_die (child_die
);
13690 inherit_abstract_dies (die
, cu
);
13692 /* If we have a DW_AT_specification, we might need to import using
13693 directives from the context of the specification DIE. See the
13694 comment in determine_prefix. */
13695 if (cu
->language
== language_cplus
13696 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13698 struct dwarf2_cu
*spec_cu
= cu
;
13699 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13703 child_die
= spec_die
->child
;
13704 while (child_die
&& child_die
->tag
)
13706 if (child_die
->tag
== DW_TAG_imported_module
)
13707 process_die (child_die
, spec_cu
);
13708 child_die
= sibling_die (child_die
);
13711 /* In some cases, GCC generates specification DIEs that
13712 themselves contain DW_AT_specification attributes. */
13713 spec_die
= die_specification (spec_die
, &spec_cu
);
13717 newobj
= pop_context ();
13718 /* Make a block for the local symbols within. */
13719 block
= finish_block (newobj
->name
, &local_symbols
, newobj
->old_blocks
,
13720 newobj
->static_link
, lowpc
, highpc
);
13722 /* For C++, set the block's scope. */
13723 if ((cu
->language
== language_cplus
13724 || cu
->language
== language_fortran
13725 || cu
->language
== language_d
13726 || cu
->language
== language_rust
)
13727 && cu
->processing_has_namespace_info
)
13728 block_set_scope (block
, determine_prefix (die
, cu
),
13729 &objfile
->objfile_obstack
);
13731 /* If we have address ranges, record them. */
13732 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13734 gdbarch_make_symbol_special (gdbarch
, newobj
->name
, objfile
);
13736 /* Attach template arguments to function. */
13737 if (!template_args
.empty ())
13739 gdb_assert (templ_func
!= NULL
);
13741 templ_func
->n_template_arguments
= template_args
.size ();
13742 templ_func
->template_arguments
13743 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13744 templ_func
->n_template_arguments
);
13745 memcpy (templ_func
->template_arguments
,
13746 template_args
.data (),
13747 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13750 /* In C++, we can have functions nested inside functions (e.g., when
13751 a function declares a class that has methods). This means that
13752 when we finish processing a function scope, we may need to go
13753 back to building a containing block's symbol lists. */
13754 local_symbols
= newobj
->locals
;
13755 local_using_directives
= newobj
->local_using_directives
;
13757 /* If we've finished processing a top-level function, subsequent
13758 symbols go in the file symbol list. */
13759 if (outermost_context_p ())
13760 cu
->list_in_scope
= &file_symbols
;
13763 /* Process all the DIES contained within a lexical block scope. Start
13764 a new scope, process the dies, and then close the scope. */
13767 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13769 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13770 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13771 struct context_stack
*newobj
;
13772 CORE_ADDR lowpc
, highpc
;
13773 struct die_info
*child_die
;
13774 CORE_ADDR baseaddr
;
13776 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13778 /* Ignore blocks with missing or invalid low and high pc attributes. */
13779 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13780 as multiple lexical blocks? Handling children in a sane way would
13781 be nasty. Might be easier to properly extend generic blocks to
13782 describe ranges. */
13783 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13785 case PC_BOUNDS_NOT_PRESENT
:
13786 /* DW_TAG_lexical_block has no attributes, process its children as if
13787 there was no wrapping by that DW_TAG_lexical_block.
13788 GCC does no longer produces such DWARF since GCC r224161. */
13789 for (child_die
= die
->child
;
13790 child_die
!= NULL
&& child_die
->tag
;
13791 child_die
= sibling_die (child_die
))
13792 process_die (child_die
, cu
);
13794 case PC_BOUNDS_INVALID
:
13797 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13798 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13800 push_context (0, lowpc
);
13801 if (die
->child
!= NULL
)
13803 child_die
= die
->child
;
13804 while (child_die
&& child_die
->tag
)
13806 process_die (child_die
, cu
);
13807 child_die
= sibling_die (child_die
);
13810 inherit_abstract_dies (die
, cu
);
13811 newobj
= pop_context ();
13813 if (local_symbols
!= NULL
|| local_using_directives
!= NULL
)
13815 struct block
*block
13816 = finish_block (0, &local_symbols
, newobj
->old_blocks
, NULL
,
13817 newobj
->start_addr
, highpc
);
13819 /* Note that recording ranges after traversing children, as we
13820 do here, means that recording a parent's ranges entails
13821 walking across all its children's ranges as they appear in
13822 the address map, which is quadratic behavior.
13824 It would be nicer to record the parent's ranges before
13825 traversing its children, simply overriding whatever you find
13826 there. But since we don't even decide whether to create a
13827 block until after we've traversed its children, that's hard
13829 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13831 local_symbols
= newobj
->locals
;
13832 local_using_directives
= newobj
->local_using_directives
;
13835 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13838 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13840 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13841 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13842 CORE_ADDR pc
, baseaddr
;
13843 struct attribute
*attr
;
13844 struct call_site
*call_site
, call_site_local
;
13847 struct die_info
*child_die
;
13849 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13851 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13854 /* This was a pre-DWARF-5 GNU extension alias
13855 for DW_AT_call_return_pc. */
13856 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13860 complaint (&symfile_complaints
,
13861 _("missing DW_AT_call_return_pc for DW_TAG_call_site "
13862 "DIE %s [in module %s]"),
13863 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13866 pc
= attr_value_as_address (attr
) + baseaddr
;
13867 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13869 if (cu
->call_site_htab
== NULL
)
13870 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13871 NULL
, &objfile
->objfile_obstack
,
13872 hashtab_obstack_allocate
, NULL
);
13873 call_site_local
.pc
= pc
;
13874 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13877 complaint (&symfile_complaints
,
13878 _("Duplicate PC %s for DW_TAG_call_site "
13879 "DIE %s [in module %s]"),
13880 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13881 objfile_name (objfile
));
13885 /* Count parameters at the caller. */
13888 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13889 child_die
= sibling_die (child_die
))
13891 if (child_die
->tag
!= DW_TAG_call_site_parameter
13892 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13894 complaint (&symfile_complaints
,
13895 _("Tag %d is not DW_TAG_call_site_parameter in "
13896 "DW_TAG_call_site child DIE %s [in module %s]"),
13897 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13898 objfile_name (objfile
));
13906 = ((struct call_site
*)
13907 obstack_alloc (&objfile
->objfile_obstack
,
13908 sizeof (*call_site
)
13909 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13911 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13912 call_site
->pc
= pc
;
13914 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13915 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13917 struct die_info
*func_die
;
13919 /* Skip also over DW_TAG_inlined_subroutine. */
13920 for (func_die
= die
->parent
;
13921 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13922 && func_die
->tag
!= DW_TAG_subroutine_type
;
13923 func_die
= func_die
->parent
);
13925 /* DW_AT_call_all_calls is a superset
13926 of DW_AT_call_all_tail_calls. */
13928 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13929 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13930 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13931 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13933 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13934 not complete. But keep CALL_SITE for look ups via call_site_htab,
13935 both the initial caller containing the real return address PC and
13936 the final callee containing the current PC of a chain of tail
13937 calls do not need to have the tail call list complete. But any
13938 function candidate for a virtual tail call frame searched via
13939 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13940 determined unambiguously. */
13944 struct type
*func_type
= NULL
;
13947 func_type
= get_die_type (func_die
, cu
);
13948 if (func_type
!= NULL
)
13950 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
13952 /* Enlist this call site to the function. */
13953 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13954 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13957 complaint (&symfile_complaints
,
13958 _("Cannot find function owning DW_TAG_call_site "
13959 "DIE %s [in module %s]"),
13960 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13964 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13966 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13968 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13971 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13972 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13974 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13975 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
13976 /* Keep NULL DWARF_BLOCK. */;
13977 else if (attr_form_is_block (attr
))
13979 struct dwarf2_locexpr_baton
*dlbaton
;
13981 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13982 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13983 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13984 dlbaton
->per_cu
= cu
->per_cu
;
13986 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13988 else if (attr_form_is_ref (attr
))
13990 struct dwarf2_cu
*target_cu
= cu
;
13991 struct die_info
*target_die
;
13993 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13994 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
13995 if (die_is_declaration (target_die
, target_cu
))
13997 const char *target_physname
;
13999 /* Prefer the mangled name; otherwise compute the demangled one. */
14000 target_physname
= dw2_linkage_name (target_die
, target_cu
);
14001 if (target_physname
== NULL
)
14002 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
14003 if (target_physname
== NULL
)
14004 complaint (&symfile_complaints
,
14005 _("DW_AT_call_target target DIE has invalid "
14006 "physname, for referencing DIE %s [in module %s]"),
14007 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14009 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
14015 /* DW_AT_entry_pc should be preferred. */
14016 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
14017 <= PC_BOUNDS_INVALID
)
14018 complaint (&symfile_complaints
,
14019 _("DW_AT_call_target target DIE has invalid "
14020 "low pc, for referencing DIE %s [in module %s]"),
14021 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14024 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14025 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
14030 complaint (&symfile_complaints
,
14031 _("DW_TAG_call_site DW_AT_call_target is neither "
14032 "block nor reference, for DIE %s [in module %s]"),
14033 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14035 call_site
->per_cu
= cu
->per_cu
;
14037 for (child_die
= die
->child
;
14038 child_die
&& child_die
->tag
;
14039 child_die
= sibling_die (child_die
))
14041 struct call_site_parameter
*parameter
;
14042 struct attribute
*loc
, *origin
;
14044 if (child_die
->tag
!= DW_TAG_call_site_parameter
14045 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14047 /* Already printed the complaint above. */
14051 gdb_assert (call_site
->parameter_count
< nparams
);
14052 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
14054 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
14055 specifies DW_TAG_formal_parameter. Value of the data assumed for the
14056 register is contained in DW_AT_call_value. */
14058 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
14059 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
14060 if (origin
== NULL
)
14062 /* This was a pre-DWARF-5 GNU extension alias
14063 for DW_AT_call_parameter. */
14064 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
14066 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
14068 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
14070 sect_offset sect_off
14071 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
14072 if (!offset_in_cu_p (&cu
->header
, sect_off
))
14074 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
14075 binding can be done only inside one CU. Such referenced DIE
14076 therefore cannot be even moved to DW_TAG_partial_unit. */
14077 complaint (&symfile_complaints
,
14078 _("DW_AT_call_parameter offset is not in CU for "
14079 "DW_TAG_call_site child DIE %s [in module %s]"),
14080 sect_offset_str (child_die
->sect_off
),
14081 objfile_name (objfile
));
14084 parameter
->u
.param_cu_off
14085 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
14087 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
14089 complaint (&symfile_complaints
,
14090 _("No DW_FORM_block* DW_AT_location for "
14091 "DW_TAG_call_site child DIE %s [in module %s]"),
14092 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
14097 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
14098 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
14099 if (parameter
->u
.dwarf_reg
!= -1)
14100 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
14101 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
14102 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
14103 ¶meter
->u
.fb_offset
))
14104 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
14107 complaint (&symfile_complaints
,
14108 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
14109 "for DW_FORM_block* DW_AT_location is supported for "
14110 "DW_TAG_call_site child DIE %s "
14112 sect_offset_str (child_die
->sect_off
),
14113 objfile_name (objfile
));
14118 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
14120 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
14121 if (!attr_form_is_block (attr
))
14123 complaint (&symfile_complaints
,
14124 _("No DW_FORM_block* DW_AT_call_value for "
14125 "DW_TAG_call_site child DIE %s [in module %s]"),
14126 sect_offset_str (child_die
->sect_off
),
14127 objfile_name (objfile
));
14130 parameter
->value
= DW_BLOCK (attr
)->data
;
14131 parameter
->value_size
= DW_BLOCK (attr
)->size
;
14133 /* Parameters are not pre-cleared by memset above. */
14134 parameter
->data_value
= NULL
;
14135 parameter
->data_value_size
= 0;
14136 call_site
->parameter_count
++;
14138 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
14140 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
14143 if (!attr_form_is_block (attr
))
14144 complaint (&symfile_complaints
,
14145 _("No DW_FORM_block* DW_AT_call_data_value for "
14146 "DW_TAG_call_site child DIE %s [in module %s]"),
14147 sect_offset_str (child_die
->sect_off
),
14148 objfile_name (objfile
));
14151 parameter
->data_value
= DW_BLOCK (attr
)->data
;
14152 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
14158 /* Helper function for read_variable. If DIE represents a virtual
14159 table, then return the type of the concrete object that is
14160 associated with the virtual table. Otherwise, return NULL. */
14162 static struct type
*
14163 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14165 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14169 /* Find the type DIE. */
14170 struct die_info
*type_die
= NULL
;
14171 struct dwarf2_cu
*type_cu
= cu
;
14173 if (attr_form_is_ref (attr
))
14174 type_die
= follow_die_ref (die
, attr
, &type_cu
);
14175 if (type_die
== NULL
)
14178 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
14180 return die_containing_type (type_die
, type_cu
);
14183 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
14186 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
14188 struct rust_vtable_symbol
*storage
= NULL
;
14190 if (cu
->language
== language_rust
)
14192 struct type
*containing_type
= rust_containing_type (die
, cu
);
14194 if (containing_type
!= NULL
)
14196 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14198 storage
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
14199 struct rust_vtable_symbol
);
14200 initialize_objfile_symbol (storage
);
14201 storage
->concrete_type
= containing_type
;
14202 storage
->subclass
= SYMBOL_RUST_VTABLE
;
14206 new_symbol (die
, NULL
, cu
, storage
);
14209 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14210 reading .debug_rnglists.
14211 Callback's type should be:
14212 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14213 Return true if the attributes are present and valid, otherwise,
14216 template <typename Callback
>
14218 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14219 Callback
&&callback
)
14221 struct dwarf2_per_objfile
*dwarf2_per_objfile
14222 = cu
->per_cu
->dwarf2_per_objfile
;
14223 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14224 bfd
*obfd
= objfile
->obfd
;
14225 /* Base address selection entry. */
14228 const gdb_byte
*buffer
;
14229 CORE_ADDR baseaddr
;
14230 bool overflow
= false;
14232 found_base
= cu
->base_known
;
14233 base
= cu
->base_address
;
14235 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->rnglists
);
14236 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
14238 complaint (&symfile_complaints
,
14239 _("Offset %d out of bounds for DW_AT_ranges attribute"),
14243 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
14245 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14249 /* Initialize it due to a false compiler warning. */
14250 CORE_ADDR range_beginning
= 0, range_end
= 0;
14251 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
14252 + dwarf2_per_objfile
->rnglists
.size
);
14253 unsigned int bytes_read
;
14255 if (buffer
== buf_end
)
14260 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14263 case DW_RLE_end_of_list
:
14265 case DW_RLE_base_address
:
14266 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14271 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14273 buffer
+= bytes_read
;
14275 case DW_RLE_start_length
:
14276 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14281 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14282 buffer
+= bytes_read
;
14283 range_end
= (range_beginning
14284 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14285 buffer
+= bytes_read
;
14286 if (buffer
> buf_end
)
14292 case DW_RLE_offset_pair
:
14293 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14294 buffer
+= bytes_read
;
14295 if (buffer
> buf_end
)
14300 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14301 buffer
+= bytes_read
;
14302 if (buffer
> buf_end
)
14308 case DW_RLE_start_end
:
14309 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14314 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14315 buffer
+= bytes_read
;
14316 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14317 buffer
+= bytes_read
;
14320 complaint (&symfile_complaints
,
14321 _("Invalid .debug_rnglists data (no base address)"));
14324 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14326 if (rlet
== DW_RLE_base_address
)
14331 /* We have no valid base address for the ranges
14333 complaint (&symfile_complaints
,
14334 _("Invalid .debug_rnglists data (no base address)"));
14338 if (range_beginning
> range_end
)
14340 /* Inverted range entries are invalid. */
14341 complaint (&symfile_complaints
,
14342 _("Invalid .debug_rnglists data (inverted range)"));
14346 /* Empty range entries have no effect. */
14347 if (range_beginning
== range_end
)
14350 range_beginning
+= base
;
14353 /* A not-uncommon case of bad debug info.
14354 Don't pollute the addrmap with bad data. */
14355 if (range_beginning
+ baseaddr
== 0
14356 && !dwarf2_per_objfile
->has_section_at_zero
)
14358 complaint (&symfile_complaints
,
14359 _(".debug_rnglists entry has start address of zero"
14360 " [in module %s]"), objfile_name (objfile
));
14364 callback (range_beginning
, range_end
);
14369 complaint (&symfile_complaints
,
14370 _("Offset %d is not terminated "
14371 "for DW_AT_ranges attribute"),
14379 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14380 Callback's type should be:
14381 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14382 Return 1 if the attributes are present and valid, otherwise, return 0. */
14384 template <typename Callback
>
14386 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
14387 Callback
&&callback
)
14389 struct dwarf2_per_objfile
*dwarf2_per_objfile
14390 = cu
->per_cu
->dwarf2_per_objfile
;
14391 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14392 struct comp_unit_head
*cu_header
= &cu
->header
;
14393 bfd
*obfd
= objfile
->obfd
;
14394 unsigned int addr_size
= cu_header
->addr_size
;
14395 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14396 /* Base address selection entry. */
14399 unsigned int dummy
;
14400 const gdb_byte
*buffer
;
14401 CORE_ADDR baseaddr
;
14403 if (cu_header
->version
>= 5)
14404 return dwarf2_rnglists_process (offset
, cu
, callback
);
14406 found_base
= cu
->base_known
;
14407 base
= cu
->base_address
;
14409 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
14410 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
14412 complaint (&symfile_complaints
,
14413 _("Offset %d out of bounds for DW_AT_ranges attribute"),
14417 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
14419 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14423 CORE_ADDR range_beginning
, range_end
;
14425 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
14426 buffer
+= addr_size
;
14427 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
14428 buffer
+= addr_size
;
14429 offset
+= 2 * addr_size
;
14431 /* An end of list marker is a pair of zero addresses. */
14432 if (range_beginning
== 0 && range_end
== 0)
14433 /* Found the end of list entry. */
14436 /* Each base address selection entry is a pair of 2 values.
14437 The first is the largest possible address, the second is
14438 the base address. Check for a base address here. */
14439 if ((range_beginning
& mask
) == mask
)
14441 /* If we found the largest possible address, then we already
14442 have the base address in range_end. */
14450 /* We have no valid base address for the ranges
14452 complaint (&symfile_complaints
,
14453 _("Invalid .debug_ranges data (no base address)"));
14457 if (range_beginning
> range_end
)
14459 /* Inverted range entries are invalid. */
14460 complaint (&symfile_complaints
,
14461 _("Invalid .debug_ranges data (inverted range)"));
14465 /* Empty range entries have no effect. */
14466 if (range_beginning
== range_end
)
14469 range_beginning
+= base
;
14472 /* A not-uncommon case of bad debug info.
14473 Don't pollute the addrmap with bad data. */
14474 if (range_beginning
+ baseaddr
== 0
14475 && !dwarf2_per_objfile
->has_section_at_zero
)
14477 complaint (&symfile_complaints
,
14478 _(".debug_ranges entry has start address of zero"
14479 " [in module %s]"), objfile_name (objfile
));
14483 callback (range_beginning
, range_end
);
14489 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14490 Return 1 if the attributes are present and valid, otherwise, return 0.
14491 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14494 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14495 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14496 struct partial_symtab
*ranges_pst
)
14498 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14499 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14500 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
14501 SECT_OFF_TEXT (objfile
));
14504 CORE_ADDR high
= 0;
14507 retval
= dwarf2_ranges_process (offset
, cu
,
14508 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14510 if (ranges_pst
!= NULL
)
14515 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
14516 range_beginning
+ baseaddr
);
14517 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
14518 range_end
+ baseaddr
);
14519 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
14523 /* FIXME: This is recording everything as a low-high
14524 segment of consecutive addresses. We should have a
14525 data structure for discontiguous block ranges
14529 low
= range_beginning
;
14535 if (range_beginning
< low
)
14536 low
= range_beginning
;
14537 if (range_end
> high
)
14545 /* If the first entry is an end-of-list marker, the range
14546 describes an empty scope, i.e. no instructions. */
14552 *high_return
= high
;
14556 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14557 definition for the return value. *LOWPC and *HIGHPC are set iff
14558 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14560 static enum pc_bounds_kind
14561 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14562 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14563 struct partial_symtab
*pst
)
14565 struct dwarf2_per_objfile
*dwarf2_per_objfile
14566 = cu
->per_cu
->dwarf2_per_objfile
;
14567 struct attribute
*attr
;
14568 struct attribute
*attr_high
;
14570 CORE_ADDR high
= 0;
14571 enum pc_bounds_kind ret
;
14573 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14576 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14579 low
= attr_value_as_address (attr
);
14580 high
= attr_value_as_address (attr_high
);
14581 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14585 /* Found high w/o low attribute. */
14586 return PC_BOUNDS_INVALID
;
14588 /* Found consecutive range of addresses. */
14589 ret
= PC_BOUNDS_HIGH_LOW
;
14593 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14596 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
14597 We take advantage of the fact that DW_AT_ranges does not appear
14598 in DW_TAG_compile_unit of DWO files. */
14599 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14600 unsigned int ranges_offset
= (DW_UNSND (attr
)
14601 + (need_ranges_base
14605 /* Value of the DW_AT_ranges attribute is the offset in the
14606 .debug_ranges section. */
14607 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14608 return PC_BOUNDS_INVALID
;
14609 /* Found discontinuous range of addresses. */
14610 ret
= PC_BOUNDS_RANGES
;
14613 return PC_BOUNDS_NOT_PRESENT
;
14616 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14618 return PC_BOUNDS_INVALID
;
14620 /* When using the GNU linker, .gnu.linkonce. sections are used to
14621 eliminate duplicate copies of functions and vtables and such.
14622 The linker will arbitrarily choose one and discard the others.
14623 The AT_*_pc values for such functions refer to local labels in
14624 these sections. If the section from that file was discarded, the
14625 labels are not in the output, so the relocs get a value of 0.
14626 If this is a discarded function, mark the pc bounds as invalid,
14627 so that GDB will ignore it. */
14628 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
14629 return PC_BOUNDS_INVALID
;
14637 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14638 its low and high PC addresses. Do nothing if these addresses could not
14639 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14640 and HIGHPC to the high address if greater than HIGHPC. */
14643 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14644 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14645 struct dwarf2_cu
*cu
)
14647 CORE_ADDR low
, high
;
14648 struct die_info
*child
= die
->child
;
14650 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14652 *lowpc
= std::min (*lowpc
, low
);
14653 *highpc
= std::max (*highpc
, high
);
14656 /* If the language does not allow nested subprograms (either inside
14657 subprograms or lexical blocks), we're done. */
14658 if (cu
->language
!= language_ada
)
14661 /* Check all the children of the given DIE. If it contains nested
14662 subprograms, then check their pc bounds. Likewise, we need to
14663 check lexical blocks as well, as they may also contain subprogram
14665 while (child
&& child
->tag
)
14667 if (child
->tag
== DW_TAG_subprogram
14668 || child
->tag
== DW_TAG_lexical_block
)
14669 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14670 child
= sibling_die (child
);
14674 /* Get the low and high pc's represented by the scope DIE, and store
14675 them in *LOWPC and *HIGHPC. If the correct values can't be
14676 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14679 get_scope_pc_bounds (struct die_info
*die
,
14680 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14681 struct dwarf2_cu
*cu
)
14683 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14684 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14685 CORE_ADDR current_low
, current_high
;
14687 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14688 >= PC_BOUNDS_RANGES
)
14690 best_low
= current_low
;
14691 best_high
= current_high
;
14695 struct die_info
*child
= die
->child
;
14697 while (child
&& child
->tag
)
14699 switch (child
->tag
) {
14700 case DW_TAG_subprogram
:
14701 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14703 case DW_TAG_namespace
:
14704 case DW_TAG_module
:
14705 /* FIXME: carlton/2004-01-16: Should we do this for
14706 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14707 that current GCC's always emit the DIEs corresponding
14708 to definitions of methods of classes as children of a
14709 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14710 the DIEs giving the declarations, which could be
14711 anywhere). But I don't see any reason why the
14712 standards says that they have to be there. */
14713 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14715 if (current_low
!= ((CORE_ADDR
) -1))
14717 best_low
= std::min (best_low
, current_low
);
14718 best_high
= std::max (best_high
, current_high
);
14726 child
= sibling_die (child
);
14731 *highpc
= best_high
;
14734 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14738 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14739 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14741 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14742 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14743 struct attribute
*attr
;
14744 struct attribute
*attr_high
;
14746 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14749 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14752 CORE_ADDR low
= attr_value_as_address (attr
);
14753 CORE_ADDR high
= attr_value_as_address (attr_high
);
14755 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14758 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14759 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14760 record_block_range (block
, low
, high
- 1);
14764 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14767 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
14768 We take advantage of the fact that DW_AT_ranges does not appear
14769 in DW_TAG_compile_unit of DWO files. */
14770 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14772 /* The value of the DW_AT_ranges attribute is the offset of the
14773 address range list in the .debug_ranges section. */
14774 unsigned long offset
= (DW_UNSND (attr
)
14775 + (need_ranges_base
? cu
->ranges_base
: 0));
14777 dwarf2_ranges_process (offset
, cu
,
14778 [&] (CORE_ADDR start
, CORE_ADDR end
)
14782 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14783 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14784 record_block_range (block
, start
, end
- 1);
14789 /* Check whether the producer field indicates either of GCC < 4.6, or the
14790 Intel C/C++ compiler, and cache the result in CU. */
14793 check_producer (struct dwarf2_cu
*cu
)
14797 if (cu
->producer
== NULL
)
14799 /* For unknown compilers expect their behavior is DWARF version
14802 GCC started to support .debug_types sections by -gdwarf-4 since
14803 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14804 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14805 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14806 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14808 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14810 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14811 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14813 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14814 cu
->producer_is_icc_lt_14
= major
< 14;
14817 /* For other non-GCC compilers, expect their behavior is DWARF version
14821 cu
->checked_producer
= 1;
14824 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14825 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14826 during 4.6.0 experimental. */
14829 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14831 if (!cu
->checked_producer
)
14832 check_producer (cu
);
14834 return cu
->producer_is_gxx_lt_4_6
;
14837 /* Return the default accessibility type if it is not overriden by
14838 DW_AT_accessibility. */
14840 static enum dwarf_access_attribute
14841 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14843 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14845 /* The default DWARF 2 accessibility for members is public, the default
14846 accessibility for inheritance is private. */
14848 if (die
->tag
!= DW_TAG_inheritance
)
14849 return DW_ACCESS_public
;
14851 return DW_ACCESS_private
;
14855 /* DWARF 3+ defines the default accessibility a different way. The same
14856 rules apply now for DW_TAG_inheritance as for the members and it only
14857 depends on the container kind. */
14859 if (die
->parent
->tag
== DW_TAG_class_type
)
14860 return DW_ACCESS_private
;
14862 return DW_ACCESS_public
;
14866 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14867 offset. If the attribute was not found return 0, otherwise return
14868 1. If it was found but could not properly be handled, set *OFFSET
14872 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14875 struct attribute
*attr
;
14877 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14882 /* Note that we do not check for a section offset first here.
14883 This is because DW_AT_data_member_location is new in DWARF 4,
14884 so if we see it, we can assume that a constant form is really
14885 a constant and not a section offset. */
14886 if (attr_form_is_constant (attr
))
14887 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
14888 else if (attr_form_is_section_offset (attr
))
14889 dwarf2_complex_location_expr_complaint ();
14890 else if (attr_form_is_block (attr
))
14891 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14893 dwarf2_complex_location_expr_complaint ();
14901 /* Add an aggregate field to the field list. */
14904 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14905 struct dwarf2_cu
*cu
)
14907 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14908 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14909 struct nextfield
*new_field
;
14910 struct attribute
*attr
;
14912 const char *fieldname
= "";
14914 if (die
->tag
== DW_TAG_inheritance
)
14916 fip
->baseclasses
.emplace_back ();
14917 new_field
= &fip
->baseclasses
.back ();
14921 fip
->fields
.emplace_back ();
14922 new_field
= &fip
->fields
.back ();
14927 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14929 new_field
->accessibility
= DW_UNSND (attr
);
14931 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14932 if (new_field
->accessibility
!= DW_ACCESS_public
)
14933 fip
->non_public_fields
= 1;
14935 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14937 new_field
->virtuality
= DW_UNSND (attr
);
14939 new_field
->virtuality
= DW_VIRTUALITY_none
;
14941 fp
= &new_field
->field
;
14943 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14947 /* Data member other than a C++ static data member. */
14949 /* Get type of field. */
14950 fp
->type
= die_type (die
, cu
);
14952 SET_FIELD_BITPOS (*fp
, 0);
14954 /* Get bit size of field (zero if none). */
14955 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14958 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14962 FIELD_BITSIZE (*fp
) = 0;
14965 /* Get bit offset of field. */
14966 if (handle_data_member_location (die
, cu
, &offset
))
14967 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14968 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14971 if (gdbarch_bits_big_endian (gdbarch
))
14973 /* For big endian bits, the DW_AT_bit_offset gives the
14974 additional bit offset from the MSB of the containing
14975 anonymous object to the MSB of the field. We don't
14976 have to do anything special since we don't need to
14977 know the size of the anonymous object. */
14978 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14982 /* For little endian bits, compute the bit offset to the
14983 MSB of the anonymous object, subtract off the number of
14984 bits from the MSB of the field to the MSB of the
14985 object, and then subtract off the number of bits of
14986 the field itself. The result is the bit offset of
14987 the LSB of the field. */
14988 int anonymous_size
;
14989 int bit_offset
= DW_UNSND (attr
);
14991 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14994 /* The size of the anonymous object containing
14995 the bit field is explicit, so use the
14996 indicated size (in bytes). */
14997 anonymous_size
= DW_UNSND (attr
);
15001 /* The size of the anonymous object containing
15002 the bit field must be inferred from the type
15003 attribute of the data member containing the
15005 anonymous_size
= TYPE_LENGTH (fp
->type
);
15007 SET_FIELD_BITPOS (*fp
,
15008 (FIELD_BITPOS (*fp
)
15009 + anonymous_size
* bits_per_byte
15010 - bit_offset
- FIELD_BITSIZE (*fp
)));
15013 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15015 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15016 + dwarf2_get_attr_constant_value (attr
, 0)));
15018 /* Get name of field. */
15019 fieldname
= dwarf2_name (die
, cu
);
15020 if (fieldname
== NULL
)
15023 /* The name is already allocated along with this objfile, so we don't
15024 need to duplicate it for the type. */
15025 fp
->name
= fieldname
;
15027 /* Change accessibility for artificial fields (e.g. virtual table
15028 pointer or virtual base class pointer) to private. */
15029 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
15031 FIELD_ARTIFICIAL (*fp
) = 1;
15032 new_field
->accessibility
= DW_ACCESS_private
;
15033 fip
->non_public_fields
= 1;
15036 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
15038 /* C++ static member. */
15040 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
15041 is a declaration, but all versions of G++ as of this writing
15042 (so through at least 3.2.1) incorrectly generate
15043 DW_TAG_variable tags. */
15045 const char *physname
;
15047 /* Get name of field. */
15048 fieldname
= dwarf2_name (die
, cu
);
15049 if (fieldname
== NULL
)
15052 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15054 /* Only create a symbol if this is an external value.
15055 new_symbol checks this and puts the value in the global symbol
15056 table, which we want. If it is not external, new_symbol
15057 will try to put the value in cu->list_in_scope which is wrong. */
15058 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
15060 /* A static const member, not much different than an enum as far as
15061 we're concerned, except that we can support more types. */
15062 new_symbol (die
, NULL
, cu
);
15065 /* Get physical name. */
15066 physname
= dwarf2_physname (fieldname
, die
, cu
);
15068 /* The name is already allocated along with this objfile, so we don't
15069 need to duplicate it for the type. */
15070 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
15071 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15072 FIELD_NAME (*fp
) = fieldname
;
15074 else if (die
->tag
== DW_TAG_inheritance
)
15078 /* C++ base class field. */
15079 if (handle_data_member_location (die
, cu
, &offset
))
15080 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15081 FIELD_BITSIZE (*fp
) = 0;
15082 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15083 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
15085 else if (die
->tag
== DW_TAG_variant_part
)
15087 /* process_structure_scope will treat this DIE as a union. */
15088 process_structure_scope (die
, cu
);
15090 /* The variant part is relative to the start of the enclosing
15092 SET_FIELD_BITPOS (*fp
, 0);
15093 fp
->type
= get_die_type (die
, cu
);
15094 fp
->artificial
= 1;
15095 fp
->name
= "<<variant>>";
15098 gdb_assert_not_reached ("missing case in dwarf2_add_field");
15101 /* Can the type given by DIE define another type? */
15104 type_can_define_types (const struct die_info
*die
)
15108 case DW_TAG_typedef
:
15109 case DW_TAG_class_type
:
15110 case DW_TAG_structure_type
:
15111 case DW_TAG_union_type
:
15112 case DW_TAG_enumeration_type
:
15120 /* Add a type definition defined in the scope of the FIP's class. */
15123 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
15124 struct dwarf2_cu
*cu
)
15126 struct decl_field fp
;
15127 memset (&fp
, 0, sizeof (fp
));
15129 gdb_assert (type_can_define_types (die
));
15131 /* Get name of field. NULL is okay here, meaning an anonymous type. */
15132 fp
.name
= dwarf2_name (die
, cu
);
15133 fp
.type
= read_type_die (die
, cu
);
15135 /* Save accessibility. */
15136 enum dwarf_access_attribute accessibility
;
15137 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15139 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15141 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15142 switch (accessibility
)
15144 case DW_ACCESS_public
:
15145 /* The assumed value if neither private nor protected. */
15147 case DW_ACCESS_private
:
15150 case DW_ACCESS_protected
:
15151 fp
.is_protected
= 1;
15154 complaint (&symfile_complaints
,
15155 _("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
15158 if (die
->tag
== DW_TAG_typedef
)
15159 fip
->typedef_field_list
.push_back (fp
);
15161 fip
->nested_types_list
.push_back (fp
);
15164 /* Create the vector of fields, and attach it to the type. */
15167 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15168 struct dwarf2_cu
*cu
)
15170 int nfields
= fip
->nfields
;
15172 /* Record the field count, allocate space for the array of fields,
15173 and create blank accessibility bitfields if necessary. */
15174 TYPE_NFIELDS (type
) = nfields
;
15175 TYPE_FIELDS (type
) = (struct field
*)
15176 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
15178 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15180 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15182 TYPE_FIELD_PRIVATE_BITS (type
) =
15183 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15184 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15186 TYPE_FIELD_PROTECTED_BITS (type
) =
15187 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15188 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15190 TYPE_FIELD_IGNORE_BITS (type
) =
15191 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15192 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15195 /* If the type has baseclasses, allocate and clear a bit vector for
15196 TYPE_FIELD_VIRTUAL_BITS. */
15197 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15199 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15200 unsigned char *pointer
;
15202 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15203 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15204 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15205 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15206 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15209 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
15211 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
15213 for (int index
= 0; index
< nfields
; ++index
)
15215 struct nextfield
&field
= fip
->fields
[index
];
15217 if (field
.variant
.is_discriminant
)
15218 di
->discriminant_index
= index
;
15219 else if (field
.variant
.default_branch
)
15220 di
->default_index
= index
;
15222 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
15226 /* Copy the saved-up fields into the field vector. */
15227 for (int i
= 0; i
< nfields
; ++i
)
15229 struct nextfield
&field
15230 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15231 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15233 TYPE_FIELD (type
, i
) = field
.field
;
15234 switch (field
.accessibility
)
15236 case DW_ACCESS_private
:
15237 if (cu
->language
!= language_ada
)
15238 SET_TYPE_FIELD_PRIVATE (type
, i
);
15241 case DW_ACCESS_protected
:
15242 if (cu
->language
!= language_ada
)
15243 SET_TYPE_FIELD_PROTECTED (type
, i
);
15246 case DW_ACCESS_public
:
15250 /* Unknown accessibility. Complain and treat it as public. */
15252 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
15253 field
.accessibility
);
15257 if (i
< fip
->baseclasses
.size ())
15259 switch (field
.virtuality
)
15261 case DW_VIRTUALITY_virtual
:
15262 case DW_VIRTUALITY_pure_virtual
:
15263 if (cu
->language
== language_ada
)
15264 error (_("unexpected virtuality in component of Ada type"));
15265 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15272 /* Return true if this member function is a constructor, false
15276 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15278 const char *fieldname
;
15279 const char *type_name
;
15282 if (die
->parent
== NULL
)
15285 if (die
->parent
->tag
!= DW_TAG_structure_type
15286 && die
->parent
->tag
!= DW_TAG_union_type
15287 && die
->parent
->tag
!= DW_TAG_class_type
)
15290 fieldname
= dwarf2_name (die
, cu
);
15291 type_name
= dwarf2_name (die
->parent
, cu
);
15292 if (fieldname
== NULL
|| type_name
== NULL
)
15295 len
= strlen (fieldname
);
15296 return (strncmp (fieldname
, type_name
, len
) == 0
15297 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15300 /* Add a member function to the proper fieldlist. */
15303 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15304 struct type
*type
, struct dwarf2_cu
*cu
)
15306 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15307 struct attribute
*attr
;
15309 struct fnfieldlist
*flp
= nullptr;
15310 struct fn_field
*fnp
;
15311 const char *fieldname
;
15312 struct type
*this_type
;
15313 enum dwarf_access_attribute accessibility
;
15315 if (cu
->language
== language_ada
)
15316 error (_("unexpected member function in Ada type"));
15318 /* Get name of member function. */
15319 fieldname
= dwarf2_name (die
, cu
);
15320 if (fieldname
== NULL
)
15323 /* Look up member function name in fieldlist. */
15324 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15326 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15328 flp
= &fip
->fnfieldlists
[i
];
15333 /* Create a new fnfieldlist if necessary. */
15334 if (flp
== nullptr)
15336 fip
->fnfieldlists
.emplace_back ();
15337 flp
= &fip
->fnfieldlists
.back ();
15338 flp
->name
= fieldname
;
15339 i
= fip
->fnfieldlists
.size () - 1;
15342 /* Create a new member function field and add it to the vector of
15344 flp
->fnfields
.emplace_back ();
15345 fnp
= &flp
->fnfields
.back ();
15347 /* Delay processing of the physname until later. */
15348 if (cu
->language
== language_cplus
)
15349 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15353 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15354 fnp
->physname
= physname
? physname
: "";
15357 fnp
->type
= alloc_type (objfile
);
15358 this_type
= read_type_die (die
, cu
);
15359 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
15361 int nparams
= TYPE_NFIELDS (this_type
);
15363 /* TYPE is the domain of this method, and THIS_TYPE is the type
15364 of the method itself (TYPE_CODE_METHOD). */
15365 smash_to_method_type (fnp
->type
, type
,
15366 TYPE_TARGET_TYPE (this_type
),
15367 TYPE_FIELDS (this_type
),
15368 TYPE_NFIELDS (this_type
),
15369 TYPE_VARARGS (this_type
));
15371 /* Handle static member functions.
15372 Dwarf2 has no clean way to discern C++ static and non-static
15373 member functions. G++ helps GDB by marking the first
15374 parameter for non-static member functions (which is the this
15375 pointer) as artificial. We obtain this information from
15376 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15377 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15378 fnp
->voffset
= VOFFSET_STATIC
;
15381 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
15382 dwarf2_full_name (fieldname
, die
, cu
));
15384 /* Get fcontext from DW_AT_containing_type if present. */
15385 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15386 fnp
->fcontext
= die_containing_type (die
, cu
);
15388 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15389 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15391 /* Get accessibility. */
15392 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15394 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15396 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15397 switch (accessibility
)
15399 case DW_ACCESS_private
:
15400 fnp
->is_private
= 1;
15402 case DW_ACCESS_protected
:
15403 fnp
->is_protected
= 1;
15407 /* Check for artificial methods. */
15408 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15409 if (attr
&& DW_UNSND (attr
) != 0)
15410 fnp
->is_artificial
= 1;
15412 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15414 /* Get index in virtual function table if it is a virtual member
15415 function. For older versions of GCC, this is an offset in the
15416 appropriate virtual table, as specified by DW_AT_containing_type.
15417 For everyone else, it is an expression to be evaluated relative
15418 to the object address. */
15420 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15423 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
15425 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15427 /* Old-style GCC. */
15428 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15430 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15431 || (DW_BLOCK (attr
)->size
> 1
15432 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15433 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15435 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15436 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15437 dwarf2_complex_location_expr_complaint ();
15439 fnp
->voffset
/= cu
->header
.addr_size
;
15443 dwarf2_complex_location_expr_complaint ();
15445 if (!fnp
->fcontext
)
15447 /* If there is no `this' field and no DW_AT_containing_type,
15448 we cannot actually find a base class context for the
15450 if (TYPE_NFIELDS (this_type
) == 0
15451 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15453 complaint (&symfile_complaints
,
15454 _("cannot determine context for virtual member "
15455 "function \"%s\" (offset %s)"),
15456 fieldname
, sect_offset_str (die
->sect_off
));
15461 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15465 else if (attr_form_is_section_offset (attr
))
15467 dwarf2_complex_location_expr_complaint ();
15471 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15477 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15478 if (attr
&& DW_UNSND (attr
))
15480 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15481 complaint (&symfile_complaints
,
15482 _("Member function \"%s\" (offset %s) is virtual "
15483 "but the vtable offset is not specified"),
15484 fieldname
, sect_offset_str (die
->sect_off
));
15485 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15486 TYPE_CPLUS_DYNAMIC (type
) = 1;
15491 /* Create the vector of member function fields, and attach it to the type. */
15494 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15495 struct dwarf2_cu
*cu
)
15497 if (cu
->language
== language_ada
)
15498 error (_("unexpected member functions in Ada type"));
15500 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15501 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15503 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15505 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15507 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15508 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15510 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15511 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15512 fn_flp
->fn_fields
= (struct fn_field
*)
15513 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15515 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15516 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15519 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15522 /* Returns non-zero if NAME is the name of a vtable member in CU's
15523 language, zero otherwise. */
15525 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15527 static const char vptr
[] = "_vptr";
15529 /* Look for the C++ form of the vtable. */
15530 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15536 /* GCC outputs unnamed structures that are really pointers to member
15537 functions, with the ABI-specified layout. If TYPE describes
15538 such a structure, smash it into a member function type.
15540 GCC shouldn't do this; it should just output pointer to member DIEs.
15541 This is GCC PR debug/28767. */
15544 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15546 struct type
*pfn_type
, *self_type
, *new_type
;
15548 /* Check for a structure with no name and two children. */
15549 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
15552 /* Check for __pfn and __delta members. */
15553 if (TYPE_FIELD_NAME (type
, 0) == NULL
15554 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15555 || TYPE_FIELD_NAME (type
, 1) == NULL
15556 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15559 /* Find the type of the method. */
15560 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15561 if (pfn_type
== NULL
15562 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
15563 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
15566 /* Look for the "this" argument. */
15567 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15568 if (TYPE_NFIELDS (pfn_type
) == 0
15569 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15570 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
15573 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15574 new_type
= alloc_type (objfile
);
15575 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15576 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
15577 TYPE_VARARGS (pfn_type
));
15578 smash_to_methodptr_type (type
, new_type
);
15582 /* Called when we find the DIE that starts a structure or union scope
15583 (definition) to create a type for the structure or union. Fill in
15584 the type's name and general properties; the members will not be
15585 processed until process_structure_scope. A symbol table entry for
15586 the type will also not be done until process_structure_scope (assuming
15587 the type has a name).
15589 NOTE: we need to call these functions regardless of whether or not the
15590 DIE has a DW_AT_name attribute, since it might be an anonymous
15591 structure or union. This gets the type entered into our set of
15592 user defined types. */
15594 static struct type
*
15595 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15597 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15599 struct attribute
*attr
;
15602 /* If the definition of this type lives in .debug_types, read that type.
15603 Don't follow DW_AT_specification though, that will take us back up
15604 the chain and we want to go down. */
15605 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15608 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15610 /* The type's CU may not be the same as CU.
15611 Ensure TYPE is recorded with CU in die_type_hash. */
15612 return set_die_type (die
, type
, cu
);
15615 type
= alloc_type (objfile
);
15616 INIT_CPLUS_SPECIFIC (type
);
15618 name
= dwarf2_name (die
, cu
);
15621 if (cu
->language
== language_cplus
15622 || cu
->language
== language_d
15623 || cu
->language
== language_rust
)
15625 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15627 /* dwarf2_full_name might have already finished building the DIE's
15628 type. If so, there is no need to continue. */
15629 if (get_die_type (die
, cu
) != NULL
)
15630 return get_die_type (die
, cu
);
15632 TYPE_TAG_NAME (type
) = full_name
;
15633 if (die
->tag
== DW_TAG_structure_type
15634 || die
->tag
== DW_TAG_class_type
)
15635 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
15639 /* The name is already allocated along with this objfile, so
15640 we don't need to duplicate it for the type. */
15641 TYPE_TAG_NAME (type
) = name
;
15642 if (die
->tag
== DW_TAG_class_type
)
15643 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
15647 if (die
->tag
== DW_TAG_structure_type
)
15649 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15651 else if (die
->tag
== DW_TAG_union_type
)
15653 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15655 else if (die
->tag
== DW_TAG_variant_part
)
15657 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15658 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15662 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15665 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15666 TYPE_DECLARED_CLASS (type
) = 1;
15668 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15671 if (attr_form_is_constant (attr
))
15672 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15675 /* For the moment, dynamic type sizes are not supported
15676 by GDB's struct type. The actual size is determined
15677 on-demand when resolving the type of a given object,
15678 so set the type's length to zero for now. Otherwise,
15679 we record an expression as the length, and that expression
15680 could lead to a very large value, which could eventually
15681 lead to us trying to allocate that much memory when creating
15682 a value of that type. */
15683 TYPE_LENGTH (type
) = 0;
15688 TYPE_LENGTH (type
) = 0;
15691 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15693 /* ICC<14 does not output the required DW_AT_declaration on
15694 incomplete types, but gives them a size of zero. */
15695 TYPE_STUB (type
) = 1;
15698 TYPE_STUB_SUPPORTED (type
) = 1;
15700 if (die_is_declaration (die
, cu
))
15701 TYPE_STUB (type
) = 1;
15702 else if (attr
== NULL
&& die
->child
== NULL
15703 && producer_is_realview (cu
->producer
))
15704 /* RealView does not output the required DW_AT_declaration
15705 on incomplete types. */
15706 TYPE_STUB (type
) = 1;
15708 /* We need to add the type field to the die immediately so we don't
15709 infinitely recurse when dealing with pointers to the structure
15710 type within the structure itself. */
15711 set_die_type (die
, type
, cu
);
15713 /* set_die_type should be already done. */
15714 set_descriptive_type (type
, die
, cu
);
15719 /* A helper for process_structure_scope that handles a single member
15723 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15724 struct field_info
*fi
,
15725 std::vector
<struct symbol
*> *template_args
,
15726 struct dwarf2_cu
*cu
)
15728 if (child_die
->tag
== DW_TAG_member
15729 || child_die
->tag
== DW_TAG_variable
15730 || child_die
->tag
== DW_TAG_variant_part
)
15732 /* NOTE: carlton/2002-11-05: A C++ static data member
15733 should be a DW_TAG_member that is a declaration, but
15734 all versions of G++ as of this writing (so through at
15735 least 3.2.1) incorrectly generate DW_TAG_variable
15736 tags for them instead. */
15737 dwarf2_add_field (fi
, child_die
, cu
);
15739 else if (child_die
->tag
== DW_TAG_subprogram
)
15741 /* Rust doesn't have member functions in the C++ sense.
15742 However, it does emit ordinary functions as children
15743 of a struct DIE. */
15744 if (cu
->language
== language_rust
)
15745 read_func_scope (child_die
, cu
);
15748 /* C++ member function. */
15749 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15752 else if (child_die
->tag
== DW_TAG_inheritance
)
15754 /* C++ base class field. */
15755 dwarf2_add_field (fi
, child_die
, cu
);
15757 else if (type_can_define_types (child_die
))
15758 dwarf2_add_type_defn (fi
, child_die
, cu
);
15759 else if (child_die
->tag
== DW_TAG_template_type_param
15760 || child_die
->tag
== DW_TAG_template_value_param
)
15762 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15765 template_args
->push_back (arg
);
15767 else if (child_die
->tag
== DW_TAG_variant
)
15769 /* In a variant we want to get the discriminant and also add a
15770 field for our sole member child. */
15771 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
15773 for (struct die_info
*variant_child
= child_die
->child
;
15774 variant_child
!= NULL
;
15775 variant_child
= sibling_die (variant_child
))
15777 if (variant_child
->tag
== DW_TAG_member
)
15779 handle_struct_member_die (variant_child
, type
, fi
,
15780 template_args
, cu
);
15781 /* Only handle the one. */
15786 /* We don't handle this but we might as well report it if we see
15788 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
15789 complaint (&symfile_complaints
,
15790 _("DW_AT_discr_list is not supported yet"
15791 " - DIE at %s [in module %s]"),
15792 sect_offset_str (child_die
->sect_off
),
15793 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15795 /* The first field was just added, so we can stash the
15796 discriminant there. */
15797 gdb_assert (!fi
->fields
.empty ());
15799 fi
->fields
.back ().variant
.default_branch
= true;
15801 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
15805 /* Finish creating a structure or union type, including filling in
15806 its members and creating a symbol for it. */
15809 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15811 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15812 struct die_info
*child_die
;
15815 type
= get_die_type (die
, cu
);
15817 type
= read_structure_type (die
, cu
);
15819 /* When reading a DW_TAG_variant_part, we need to notice when we
15820 read the discriminant member, so we can record it later in the
15821 discriminant_info. */
15822 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
15823 sect_offset discr_offset
;
15825 if (is_variant_part
)
15827 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15830 /* Maybe it's a univariant form, an extension we support.
15831 In this case arrange not to check the offset. */
15832 is_variant_part
= false;
15834 else if (attr_form_is_ref (discr
))
15836 struct dwarf2_cu
*target_cu
= cu
;
15837 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15839 discr_offset
= target_die
->sect_off
;
15843 complaint (&symfile_complaints
,
15844 _("DW_AT_discr does not have DIE reference form"
15845 " - DIE at %s [in module %s]"),
15846 sect_offset_str (die
->sect_off
),
15847 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15848 is_variant_part
= false;
15852 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15854 struct field_info fi
;
15855 std::vector
<struct symbol
*> template_args
;
15857 child_die
= die
->child
;
15859 while (child_die
&& child_die
->tag
)
15861 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15863 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
15864 fi
.fields
.back ().variant
.is_discriminant
= true;
15866 child_die
= sibling_die (child_die
);
15869 /* Attach template arguments to type. */
15870 if (!template_args
.empty ())
15872 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15873 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15874 TYPE_TEMPLATE_ARGUMENTS (type
)
15875 = XOBNEWVEC (&objfile
->objfile_obstack
,
15877 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15878 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15879 template_args
.data (),
15880 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15881 * sizeof (struct symbol
*)));
15884 /* Attach fields and member functions to the type. */
15886 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15887 if (!fi
.fnfieldlists
.empty ())
15889 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15891 /* Get the type which refers to the base class (possibly this
15892 class itself) which contains the vtable pointer for the current
15893 class from the DW_AT_containing_type attribute. This use of
15894 DW_AT_containing_type is a GNU extension. */
15896 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15898 struct type
*t
= die_containing_type (die
, cu
);
15900 set_type_vptr_basetype (type
, t
);
15905 /* Our own class provides vtbl ptr. */
15906 for (i
= TYPE_NFIELDS (t
) - 1;
15907 i
>= TYPE_N_BASECLASSES (t
);
15910 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15912 if (is_vtable_name (fieldname
, cu
))
15914 set_type_vptr_fieldno (type
, i
);
15919 /* Complain if virtual function table field not found. */
15920 if (i
< TYPE_N_BASECLASSES (t
))
15921 complaint (&symfile_complaints
,
15922 _("virtual function table pointer "
15923 "not found when defining class '%s'"),
15924 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
15929 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15932 else if (cu
->producer
15933 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15935 /* The IBM XLC compiler does not provide direct indication
15936 of the containing type, but the vtable pointer is
15937 always named __vfp. */
15941 for (i
= TYPE_NFIELDS (type
) - 1;
15942 i
>= TYPE_N_BASECLASSES (type
);
15945 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15947 set_type_vptr_fieldno (type
, i
);
15948 set_type_vptr_basetype (type
, type
);
15955 /* Copy fi.typedef_field_list linked list elements content into the
15956 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15957 if (!fi
.typedef_field_list
.empty ())
15959 int count
= fi
.typedef_field_list
.size ();
15961 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15962 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15963 = ((struct decl_field
*)
15965 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15966 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15968 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15969 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15972 /* Copy fi.nested_types_list linked list elements content into the
15973 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15974 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15976 int count
= fi
.nested_types_list
.size ();
15978 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15979 TYPE_NESTED_TYPES_ARRAY (type
)
15980 = ((struct decl_field
*)
15981 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15982 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15984 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15985 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15989 quirk_gcc_member_function_pointer (type
, objfile
);
15990 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15991 cu
->rust_unions
.push_back (type
);
15993 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15994 snapshots) has been known to create a die giving a declaration
15995 for a class that has, as a child, a die giving a definition for a
15996 nested class. So we have to process our children even if the
15997 current die is a declaration. Normally, of course, a declaration
15998 won't have any children at all. */
16000 child_die
= die
->child
;
16002 while (child_die
!= NULL
&& child_die
->tag
)
16004 if (child_die
->tag
== DW_TAG_member
16005 || child_die
->tag
== DW_TAG_variable
16006 || child_die
->tag
== DW_TAG_inheritance
16007 || child_die
->tag
== DW_TAG_template_value_param
16008 || child_die
->tag
== DW_TAG_template_type_param
)
16013 process_die (child_die
, cu
);
16015 child_die
= sibling_die (child_die
);
16018 /* Do not consider external references. According to the DWARF standard,
16019 these DIEs are identified by the fact that they have no byte_size
16020 attribute, and a declaration attribute. */
16021 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16022 || !die_is_declaration (die
, cu
))
16023 new_symbol (die
, type
, cu
);
16026 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
16027 update TYPE using some information only available in DIE's children. */
16030 update_enumeration_type_from_children (struct die_info
*die
,
16032 struct dwarf2_cu
*cu
)
16034 struct die_info
*child_die
;
16035 int unsigned_enum
= 1;
16039 auto_obstack obstack
;
16041 for (child_die
= die
->child
;
16042 child_die
!= NULL
&& child_die
->tag
;
16043 child_die
= sibling_die (child_die
))
16045 struct attribute
*attr
;
16047 const gdb_byte
*bytes
;
16048 struct dwarf2_locexpr_baton
*baton
;
16051 if (child_die
->tag
!= DW_TAG_enumerator
)
16054 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16058 name
= dwarf2_name (child_die
, cu
);
16060 name
= "<anonymous enumerator>";
16062 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16063 &value
, &bytes
, &baton
);
16069 else if ((mask
& value
) != 0)
16074 /* If we already know that the enum type is neither unsigned, nor
16075 a flag type, no need to look at the rest of the enumerates. */
16076 if (!unsigned_enum
&& !flag_enum
)
16081 TYPE_UNSIGNED (type
) = 1;
16083 TYPE_FLAG_ENUM (type
) = 1;
16086 /* Given a DW_AT_enumeration_type die, set its type. We do not
16087 complete the type's fields yet, or create any symbols. */
16089 static struct type
*
16090 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16092 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16094 struct attribute
*attr
;
16097 /* If the definition of this type lives in .debug_types, read that type.
16098 Don't follow DW_AT_specification though, that will take us back up
16099 the chain and we want to go down. */
16100 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
16103 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16105 /* The type's CU may not be the same as CU.
16106 Ensure TYPE is recorded with CU in die_type_hash. */
16107 return set_die_type (die
, type
, cu
);
16110 type
= alloc_type (objfile
);
16112 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
16113 name
= dwarf2_full_name (NULL
, die
, cu
);
16115 TYPE_TAG_NAME (type
) = name
;
16117 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16120 struct type
*underlying_type
= die_type (die
, cu
);
16122 TYPE_TARGET_TYPE (type
) = underlying_type
;
16125 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16128 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16132 TYPE_LENGTH (type
) = 0;
16135 /* The enumeration DIE can be incomplete. In Ada, any type can be
16136 declared as private in the package spec, and then defined only
16137 inside the package body. Such types are known as Taft Amendment
16138 Types. When another package uses such a type, an incomplete DIE
16139 may be generated by the compiler. */
16140 if (die_is_declaration (die
, cu
))
16141 TYPE_STUB (type
) = 1;
16143 /* Finish the creation of this type by using the enum's children.
16144 We must call this even when the underlying type has been provided
16145 so that we can determine if we're looking at a "flag" enum. */
16146 update_enumeration_type_from_children (die
, type
, cu
);
16148 /* If this type has an underlying type that is not a stub, then we
16149 may use its attributes. We always use the "unsigned" attribute
16150 in this situation, because ordinarily we guess whether the type
16151 is unsigned -- but the guess can be wrong and the underlying type
16152 can tell us the reality. However, we defer to a local size
16153 attribute if one exists, because this lets the compiler override
16154 the underlying type if needed. */
16155 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16157 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
16158 if (TYPE_LENGTH (type
) == 0)
16159 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
16162 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16164 return set_die_type (die
, type
, cu
);
16167 /* Given a pointer to a die which begins an enumeration, process all
16168 the dies that define the members of the enumeration, and create the
16169 symbol for the enumeration type.
16171 NOTE: We reverse the order of the element list. */
16174 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16176 struct type
*this_type
;
16178 this_type
= get_die_type (die
, cu
);
16179 if (this_type
== NULL
)
16180 this_type
= read_enumeration_type (die
, cu
);
16182 if (die
->child
!= NULL
)
16184 struct die_info
*child_die
;
16185 struct symbol
*sym
;
16186 struct field
*fields
= NULL
;
16187 int num_fields
= 0;
16190 child_die
= die
->child
;
16191 while (child_die
&& child_die
->tag
)
16193 if (child_die
->tag
!= DW_TAG_enumerator
)
16195 process_die (child_die
, cu
);
16199 name
= dwarf2_name (child_die
, cu
);
16202 sym
= new_symbol (child_die
, this_type
, cu
);
16204 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
16206 fields
= (struct field
*)
16208 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
16209 * sizeof (struct field
));
16212 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
16213 FIELD_TYPE (fields
[num_fields
]) = NULL
;
16214 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
16215 FIELD_BITSIZE (fields
[num_fields
]) = 0;
16221 child_die
= sibling_die (child_die
);
16226 TYPE_NFIELDS (this_type
) = num_fields
;
16227 TYPE_FIELDS (this_type
) = (struct field
*)
16228 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
16229 memcpy (TYPE_FIELDS (this_type
), fields
,
16230 sizeof (struct field
) * num_fields
);
16235 /* If we are reading an enum from a .debug_types unit, and the enum
16236 is a declaration, and the enum is not the signatured type in the
16237 unit, then we do not want to add a symbol for it. Adding a
16238 symbol would in some cases obscure the true definition of the
16239 enum, giving users an incomplete type when the definition is
16240 actually available. Note that we do not want to do this for all
16241 enums which are just declarations, because C++0x allows forward
16242 enum declarations. */
16243 if (cu
->per_cu
->is_debug_types
16244 && die_is_declaration (die
, cu
))
16246 struct signatured_type
*sig_type
;
16248 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16249 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16250 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16254 new_symbol (die
, this_type
, cu
);
16257 /* Extract all information from a DW_TAG_array_type DIE and put it in
16258 the DIE's type field. For now, this only handles one dimensional
16261 static struct type
*
16262 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16264 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16265 struct die_info
*child_die
;
16267 struct type
*element_type
, *range_type
, *index_type
;
16268 struct attribute
*attr
;
16270 struct dynamic_prop
*byte_stride_prop
= NULL
;
16271 unsigned int bit_stride
= 0;
16273 element_type
= die_type (die
, cu
);
16275 /* The die_type call above may have already set the type for this DIE. */
16276 type
= get_die_type (die
, cu
);
16280 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16286 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16287 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
);
16290 complaint (&symfile_complaints
,
16291 _("unable to read array DW_AT_byte_stride "
16292 " - DIE at %s [in module %s]"),
16293 sect_offset_str (die
->sect_off
),
16294 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16295 /* Ignore this attribute. We will likely not be able to print
16296 arrays of this type correctly, but there is little we can do
16297 to help if we cannot read the attribute's value. */
16298 byte_stride_prop
= NULL
;
16302 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16304 bit_stride
= DW_UNSND (attr
);
16306 /* Irix 6.2 native cc creates array types without children for
16307 arrays with unspecified length. */
16308 if (die
->child
== NULL
)
16310 index_type
= objfile_type (objfile
)->builtin_int
;
16311 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16312 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16313 byte_stride_prop
, bit_stride
);
16314 return set_die_type (die
, type
, cu
);
16317 std::vector
<struct type
*> range_types
;
16318 child_die
= die
->child
;
16319 while (child_die
&& child_die
->tag
)
16321 if (child_die
->tag
== DW_TAG_subrange_type
)
16323 struct type
*child_type
= read_type_die (child_die
, cu
);
16325 if (child_type
!= NULL
)
16327 /* The range type was succesfully read. Save it for the
16328 array type creation. */
16329 range_types
.push_back (child_type
);
16332 child_die
= sibling_die (child_die
);
16335 /* Dwarf2 dimensions are output from left to right, create the
16336 necessary array types in backwards order. */
16338 type
= element_type
;
16340 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16344 while (i
< range_types
.size ())
16345 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16346 byte_stride_prop
, bit_stride
);
16350 size_t ndim
= range_types
.size ();
16352 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16353 byte_stride_prop
, bit_stride
);
16356 /* Understand Dwarf2 support for vector types (like they occur on
16357 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16358 array type. This is not part of the Dwarf2/3 standard yet, but a
16359 custom vendor extension. The main difference between a regular
16360 array and the vector variant is that vectors are passed by value
16362 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16364 make_vector_type (type
);
16366 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16367 implementation may choose to implement triple vectors using this
16369 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16372 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16373 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16375 complaint (&symfile_complaints
,
16376 _("DW_AT_byte_size for array type smaller "
16377 "than the total size of elements"));
16380 name
= dwarf2_name (die
, cu
);
16382 TYPE_NAME (type
) = name
;
16384 /* Install the type in the die. */
16385 set_die_type (die
, type
, cu
);
16387 /* set_die_type should be already done. */
16388 set_descriptive_type (type
, die
, cu
);
16393 static enum dwarf_array_dim_ordering
16394 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16396 struct attribute
*attr
;
16398 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16401 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16403 /* GNU F77 is a special case, as at 08/2004 array type info is the
16404 opposite order to the dwarf2 specification, but data is still
16405 laid out as per normal fortran.
16407 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16408 version checking. */
16410 if (cu
->language
== language_fortran
16411 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16413 return DW_ORD_row_major
;
16416 switch (cu
->language_defn
->la_array_ordering
)
16418 case array_column_major
:
16419 return DW_ORD_col_major
;
16420 case array_row_major
:
16422 return DW_ORD_row_major
;
16426 /* Extract all information from a DW_TAG_set_type DIE and put it in
16427 the DIE's type field. */
16429 static struct type
*
16430 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16432 struct type
*domain_type
, *set_type
;
16433 struct attribute
*attr
;
16435 domain_type
= die_type (die
, cu
);
16437 /* The die_type call above may have already set the type for this DIE. */
16438 set_type
= get_die_type (die
, cu
);
16442 set_type
= create_set_type (NULL
, domain_type
);
16444 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16446 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16448 return set_die_type (die
, set_type
, cu
);
16451 /* A helper for read_common_block that creates a locexpr baton.
16452 SYM is the symbol which we are marking as computed.
16453 COMMON_DIE is the DIE for the common block.
16454 COMMON_LOC is the location expression attribute for the common
16456 MEMBER_LOC is the location expression attribute for the particular
16457 member of the common block that we are processing.
16458 CU is the CU from which the above come. */
16461 mark_common_block_symbol_computed (struct symbol
*sym
,
16462 struct die_info
*common_die
,
16463 struct attribute
*common_loc
,
16464 struct attribute
*member_loc
,
16465 struct dwarf2_cu
*cu
)
16467 struct dwarf2_per_objfile
*dwarf2_per_objfile
16468 = cu
->per_cu
->dwarf2_per_objfile
;
16469 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16470 struct dwarf2_locexpr_baton
*baton
;
16472 unsigned int cu_off
;
16473 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
16474 LONGEST offset
= 0;
16476 gdb_assert (common_loc
&& member_loc
);
16477 gdb_assert (attr_form_is_block (common_loc
));
16478 gdb_assert (attr_form_is_block (member_loc
)
16479 || attr_form_is_constant (member_loc
));
16481 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16482 baton
->per_cu
= cu
->per_cu
;
16483 gdb_assert (baton
->per_cu
);
16485 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16487 if (attr_form_is_constant (member_loc
))
16489 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
16490 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16493 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16495 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16498 *ptr
++ = DW_OP_call4
;
16499 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16500 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16503 if (attr_form_is_constant (member_loc
))
16505 *ptr
++ = DW_OP_addr
;
16506 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16507 ptr
+= cu
->header
.addr_size
;
16511 /* We have to copy the data here, because DW_OP_call4 will only
16512 use a DW_AT_location attribute. */
16513 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16514 ptr
+= DW_BLOCK (member_loc
)->size
;
16517 *ptr
++ = DW_OP_plus
;
16518 gdb_assert (ptr
- baton
->data
== baton
->size
);
16520 SYMBOL_LOCATION_BATON (sym
) = baton
;
16521 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16524 /* Create appropriate locally-scoped variables for all the
16525 DW_TAG_common_block entries. Also create a struct common_block
16526 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16527 is used to sepate the common blocks name namespace from regular
16531 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16533 struct attribute
*attr
;
16535 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16538 /* Support the .debug_loc offsets. */
16539 if (attr_form_is_block (attr
))
16543 else if (attr_form_is_section_offset (attr
))
16545 dwarf2_complex_location_expr_complaint ();
16550 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16551 "common block member");
16556 if (die
->child
!= NULL
)
16558 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16559 struct die_info
*child_die
;
16560 size_t n_entries
= 0, size
;
16561 struct common_block
*common_block
;
16562 struct symbol
*sym
;
16564 for (child_die
= die
->child
;
16565 child_die
&& child_die
->tag
;
16566 child_die
= sibling_die (child_die
))
16569 size
= (sizeof (struct common_block
)
16570 + (n_entries
- 1) * sizeof (struct symbol
*));
16572 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16574 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16575 common_block
->n_entries
= 0;
16577 for (child_die
= die
->child
;
16578 child_die
&& child_die
->tag
;
16579 child_die
= sibling_die (child_die
))
16581 /* Create the symbol in the DW_TAG_common_block block in the current
16583 sym
= new_symbol (child_die
, NULL
, cu
);
16586 struct attribute
*member_loc
;
16588 common_block
->contents
[common_block
->n_entries
++] = sym
;
16590 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16594 /* GDB has handled this for a long time, but it is
16595 not specified by DWARF. It seems to have been
16596 emitted by gfortran at least as recently as:
16597 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16598 complaint (&symfile_complaints
,
16599 _("Variable in common block has "
16600 "DW_AT_data_member_location "
16601 "- DIE at %s [in module %s]"),
16602 sect_offset_str (child_die
->sect_off
),
16603 objfile_name (objfile
));
16605 if (attr_form_is_section_offset (member_loc
))
16606 dwarf2_complex_location_expr_complaint ();
16607 else if (attr_form_is_constant (member_loc
)
16608 || attr_form_is_block (member_loc
))
16611 mark_common_block_symbol_computed (sym
, die
, attr
,
16615 dwarf2_complex_location_expr_complaint ();
16620 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16621 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16625 /* Create a type for a C++ namespace. */
16627 static struct type
*
16628 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16630 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16631 const char *previous_prefix
, *name
;
16635 /* For extensions, reuse the type of the original namespace. */
16636 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16638 struct die_info
*ext_die
;
16639 struct dwarf2_cu
*ext_cu
= cu
;
16641 ext_die
= dwarf2_extension (die
, &ext_cu
);
16642 type
= read_type_die (ext_die
, ext_cu
);
16644 /* EXT_CU may not be the same as CU.
16645 Ensure TYPE is recorded with CU in die_type_hash. */
16646 return set_die_type (die
, type
, cu
);
16649 name
= namespace_name (die
, &is_anonymous
, cu
);
16651 /* Now build the name of the current namespace. */
16653 previous_prefix
= determine_prefix (die
, cu
);
16654 if (previous_prefix
[0] != '\0')
16655 name
= typename_concat (&objfile
->objfile_obstack
,
16656 previous_prefix
, name
, 0, cu
);
16658 /* Create the type. */
16659 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16660 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
16662 return set_die_type (die
, type
, cu
);
16665 /* Read a namespace scope. */
16668 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16670 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16673 /* Add a symbol associated to this if we haven't seen the namespace
16674 before. Also, add a using directive if it's an anonymous
16677 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16681 type
= read_type_die (die
, cu
);
16682 new_symbol (die
, type
, cu
);
16684 namespace_name (die
, &is_anonymous
, cu
);
16687 const char *previous_prefix
= determine_prefix (die
, cu
);
16689 std::vector
<const char *> excludes
;
16690 add_using_directive (using_directives (cu
->language
),
16691 previous_prefix
, TYPE_NAME (type
), NULL
,
16692 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16696 if (die
->child
!= NULL
)
16698 struct die_info
*child_die
= die
->child
;
16700 while (child_die
&& child_die
->tag
)
16702 process_die (child_die
, cu
);
16703 child_die
= sibling_die (child_die
);
16708 /* Read a Fortran module as type. This DIE can be only a declaration used for
16709 imported module. Still we need that type as local Fortran "use ... only"
16710 declaration imports depend on the created type in determine_prefix. */
16712 static struct type
*
16713 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16715 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16716 const char *module_name
;
16719 module_name
= dwarf2_name (die
, cu
);
16721 complaint (&symfile_complaints
,
16722 _("DW_TAG_module has no name, offset %s"),
16723 sect_offset_str (die
->sect_off
));
16724 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16726 /* determine_prefix uses TYPE_TAG_NAME. */
16727 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
16729 return set_die_type (die
, type
, cu
);
16732 /* Read a Fortran module. */
16735 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16737 struct die_info
*child_die
= die
->child
;
16740 type
= read_type_die (die
, cu
);
16741 new_symbol (die
, type
, cu
);
16743 while (child_die
&& child_die
->tag
)
16745 process_die (child_die
, cu
);
16746 child_die
= sibling_die (child_die
);
16750 /* Return the name of the namespace represented by DIE. Set
16751 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16754 static const char *
16755 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16757 struct die_info
*current_die
;
16758 const char *name
= NULL
;
16760 /* Loop through the extensions until we find a name. */
16762 for (current_die
= die
;
16763 current_die
!= NULL
;
16764 current_die
= dwarf2_extension (die
, &cu
))
16766 /* We don't use dwarf2_name here so that we can detect the absence
16767 of a name -> anonymous namespace. */
16768 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16774 /* Is it an anonymous namespace? */
16776 *is_anonymous
= (name
== NULL
);
16778 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16783 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16784 the user defined type vector. */
16786 static struct type
*
16787 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16789 struct gdbarch
*gdbarch
16790 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16791 struct comp_unit_head
*cu_header
= &cu
->header
;
16793 struct attribute
*attr_byte_size
;
16794 struct attribute
*attr_address_class
;
16795 int byte_size
, addr_class
;
16796 struct type
*target_type
;
16798 target_type
= die_type (die
, cu
);
16800 /* The die_type call above may have already set the type for this DIE. */
16801 type
= get_die_type (die
, cu
);
16805 type
= lookup_pointer_type (target_type
);
16807 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16808 if (attr_byte_size
)
16809 byte_size
= DW_UNSND (attr_byte_size
);
16811 byte_size
= cu_header
->addr_size
;
16813 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16814 if (attr_address_class
)
16815 addr_class
= DW_UNSND (attr_address_class
);
16817 addr_class
= DW_ADDR_none
;
16819 /* If the pointer size or address class is different than the
16820 default, create a type variant marked as such and set the
16821 length accordingly. */
16822 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
16824 if (gdbarch_address_class_type_flags_p (gdbarch
))
16828 type_flags
= gdbarch_address_class_type_flags
16829 (gdbarch
, byte_size
, addr_class
);
16830 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16832 type
= make_type_with_address_space (type
, type_flags
);
16834 else if (TYPE_LENGTH (type
) != byte_size
)
16836 complaint (&symfile_complaints
,
16837 _("invalid pointer size %d"), byte_size
);
16841 /* Should we also complain about unhandled address classes? */
16845 TYPE_LENGTH (type
) = byte_size
;
16846 return set_die_type (die
, type
, cu
);
16849 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16850 the user defined type vector. */
16852 static struct type
*
16853 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16856 struct type
*to_type
;
16857 struct type
*domain
;
16859 to_type
= die_type (die
, cu
);
16860 domain
= die_containing_type (die
, cu
);
16862 /* The calls above may have already set the type for this DIE. */
16863 type
= get_die_type (die
, cu
);
16867 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
16868 type
= lookup_methodptr_type (to_type
);
16869 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
16871 struct type
*new_type
16872 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16874 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16875 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
16876 TYPE_VARARGS (to_type
));
16877 type
= lookup_methodptr_type (new_type
);
16880 type
= lookup_memberptr_type (to_type
, domain
);
16882 return set_die_type (die
, type
, cu
);
16885 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16886 the user defined type vector. */
16888 static struct type
*
16889 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16890 enum type_code refcode
)
16892 struct comp_unit_head
*cu_header
= &cu
->header
;
16893 struct type
*type
, *target_type
;
16894 struct attribute
*attr
;
16896 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16898 target_type
= die_type (die
, cu
);
16900 /* The die_type call above may have already set the type for this DIE. */
16901 type
= get_die_type (die
, cu
);
16905 type
= lookup_reference_type (target_type
, refcode
);
16906 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16909 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16913 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16915 return set_die_type (die
, type
, cu
);
16918 /* Add the given cv-qualifiers to the element type of the array. GCC
16919 outputs DWARF type qualifiers that apply to an array, not the
16920 element type. But GDB relies on the array element type to carry
16921 the cv-qualifiers. This mimics section 6.7.3 of the C99
16924 static struct type
*
16925 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16926 struct type
*base_type
, int cnst
, int voltl
)
16928 struct type
*el_type
, *inner_array
;
16930 base_type
= copy_type (base_type
);
16931 inner_array
= base_type
;
16933 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
16935 TYPE_TARGET_TYPE (inner_array
) =
16936 copy_type (TYPE_TARGET_TYPE (inner_array
));
16937 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16940 el_type
= TYPE_TARGET_TYPE (inner_array
);
16941 cnst
|= TYPE_CONST (el_type
);
16942 voltl
|= TYPE_VOLATILE (el_type
);
16943 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16945 return set_die_type (die
, base_type
, cu
);
16948 static struct type
*
16949 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16951 struct type
*base_type
, *cv_type
;
16953 base_type
= die_type (die
, cu
);
16955 /* The die_type call above may have already set the type for this DIE. */
16956 cv_type
= get_die_type (die
, cu
);
16960 /* In case the const qualifier is applied to an array type, the element type
16961 is so qualified, not the array type (section 6.7.3 of C99). */
16962 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16963 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16965 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16966 return set_die_type (die
, cv_type
, cu
);
16969 static struct type
*
16970 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16972 struct type
*base_type
, *cv_type
;
16974 base_type
= die_type (die
, cu
);
16976 /* The die_type call above may have already set the type for this DIE. */
16977 cv_type
= get_die_type (die
, cu
);
16981 /* In case the volatile qualifier is applied to an array type, the
16982 element type is so qualified, not the array type (section 6.7.3
16984 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16985 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
16987 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
16988 return set_die_type (die
, cv_type
, cu
);
16991 /* Handle DW_TAG_restrict_type. */
16993 static struct type
*
16994 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16996 struct type
*base_type
, *cv_type
;
16998 base_type
= die_type (die
, cu
);
17000 /* The die_type call above may have already set the type for this DIE. */
17001 cv_type
= get_die_type (die
, cu
);
17005 cv_type
= make_restrict_type (base_type
);
17006 return set_die_type (die
, cv_type
, cu
);
17009 /* Handle DW_TAG_atomic_type. */
17011 static struct type
*
17012 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17014 struct type
*base_type
, *cv_type
;
17016 base_type
= die_type (die
, cu
);
17018 /* The die_type call above may have already set the type for this DIE. */
17019 cv_type
= get_die_type (die
, cu
);
17023 cv_type
= make_atomic_type (base_type
);
17024 return set_die_type (die
, cv_type
, cu
);
17027 /* Extract all information from a DW_TAG_string_type DIE and add to
17028 the user defined type vector. It isn't really a user defined type,
17029 but it behaves like one, with other DIE's using an AT_user_def_type
17030 attribute to reference it. */
17032 static struct type
*
17033 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17035 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17036 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17037 struct type
*type
, *range_type
, *index_type
, *char_type
;
17038 struct attribute
*attr
;
17039 unsigned int length
;
17041 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17044 length
= DW_UNSND (attr
);
17048 /* Check for the DW_AT_byte_size attribute. */
17049 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17052 length
= DW_UNSND (attr
);
17060 index_type
= objfile_type (objfile
)->builtin_int
;
17061 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17062 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17063 type
= create_string_type (NULL
, char_type
, range_type
);
17065 return set_die_type (die
, type
, cu
);
17068 /* Assuming that DIE corresponds to a function, returns nonzero
17069 if the function is prototyped. */
17072 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17074 struct attribute
*attr
;
17076 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17077 if (attr
&& (DW_UNSND (attr
) != 0))
17080 /* The DWARF standard implies that the DW_AT_prototyped attribute
17081 is only meaninful for C, but the concept also extends to other
17082 languages that allow unprototyped functions (Eg: Objective C).
17083 For all other languages, assume that functions are always
17085 if (cu
->language
!= language_c
17086 && cu
->language
!= language_objc
17087 && cu
->language
!= language_opencl
)
17090 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17091 prototyped and unprototyped functions; default to prototyped,
17092 since that is more common in modern code (and RealView warns
17093 about unprototyped functions). */
17094 if (producer_is_realview (cu
->producer
))
17100 /* Handle DIES due to C code like:
17104 int (*funcp)(int a, long l);
17108 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17110 static struct type
*
17111 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17113 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17114 struct type
*type
; /* Type that this function returns. */
17115 struct type
*ftype
; /* Function that returns above type. */
17116 struct attribute
*attr
;
17118 type
= die_type (die
, cu
);
17120 /* The die_type call above may have already set the type for this DIE. */
17121 ftype
= get_die_type (die
, cu
);
17125 ftype
= lookup_function_type (type
);
17127 if (prototyped_function_p (die
, cu
))
17128 TYPE_PROTOTYPED (ftype
) = 1;
17130 /* Store the calling convention in the type if it's available in
17131 the subroutine die. Otherwise set the calling convention to
17132 the default value DW_CC_normal. */
17133 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17135 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
17136 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17137 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17139 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17141 /* Record whether the function returns normally to its caller or not
17142 if the DWARF producer set that information. */
17143 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17144 if (attr
&& (DW_UNSND (attr
) != 0))
17145 TYPE_NO_RETURN (ftype
) = 1;
17147 /* We need to add the subroutine type to the die immediately so
17148 we don't infinitely recurse when dealing with parameters
17149 declared as the same subroutine type. */
17150 set_die_type (die
, ftype
, cu
);
17152 if (die
->child
!= NULL
)
17154 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17155 struct die_info
*child_die
;
17156 int nparams
, iparams
;
17158 /* Count the number of parameters.
17159 FIXME: GDB currently ignores vararg functions, but knows about
17160 vararg member functions. */
17162 child_die
= die
->child
;
17163 while (child_die
&& child_die
->tag
)
17165 if (child_die
->tag
== DW_TAG_formal_parameter
)
17167 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17168 TYPE_VARARGS (ftype
) = 1;
17169 child_die
= sibling_die (child_die
);
17172 /* Allocate storage for parameters and fill them in. */
17173 TYPE_NFIELDS (ftype
) = nparams
;
17174 TYPE_FIELDS (ftype
) = (struct field
*)
17175 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
17177 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17178 even if we error out during the parameters reading below. */
17179 for (iparams
= 0; iparams
< nparams
; iparams
++)
17180 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17183 child_die
= die
->child
;
17184 while (child_die
&& child_die
->tag
)
17186 if (child_die
->tag
== DW_TAG_formal_parameter
)
17188 struct type
*arg_type
;
17190 /* DWARF version 2 has no clean way to discern C++
17191 static and non-static member functions. G++ helps
17192 GDB by marking the first parameter for non-static
17193 member functions (which is the this pointer) as
17194 artificial. We pass this information to
17195 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17197 DWARF version 3 added DW_AT_object_pointer, which GCC
17198 4.5 does not yet generate. */
17199 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17201 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17203 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17204 arg_type
= die_type (child_die
, cu
);
17206 /* RealView does not mark THIS as const, which the testsuite
17207 expects. GCC marks THIS as const in method definitions,
17208 but not in the class specifications (GCC PR 43053). */
17209 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17210 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17213 struct dwarf2_cu
*arg_cu
= cu
;
17214 const char *name
= dwarf2_name (child_die
, cu
);
17216 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17219 /* If the compiler emits this, use it. */
17220 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17223 else if (name
&& strcmp (name
, "this") == 0)
17224 /* Function definitions will have the argument names. */
17226 else if (name
== NULL
&& iparams
== 0)
17227 /* Declarations may not have the names, so like
17228 elsewhere in GDB, assume an artificial first
17229 argument is "this". */
17233 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17237 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17240 child_die
= sibling_die (child_die
);
17247 static struct type
*
17248 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17250 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17251 const char *name
= NULL
;
17252 struct type
*this_type
, *target_type
;
17254 name
= dwarf2_full_name (NULL
, die
, cu
);
17255 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17256 TYPE_TARGET_STUB (this_type
) = 1;
17257 set_die_type (die
, this_type
, cu
);
17258 target_type
= die_type (die
, cu
);
17259 if (target_type
!= this_type
)
17260 TYPE_TARGET_TYPE (this_type
) = target_type
;
17263 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17264 spec and cause infinite loops in GDB. */
17265 complaint (&symfile_complaints
,
17266 _("Self-referential DW_TAG_typedef "
17267 "- DIE at %s [in module %s]"),
17268 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17269 TYPE_TARGET_TYPE (this_type
) = NULL
;
17274 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17275 (which may be different from NAME) to the architecture back-end to allow
17276 it to guess the correct format if necessary. */
17278 static struct type
*
17279 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17280 const char *name_hint
)
17282 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17283 const struct floatformat
**format
;
17286 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17288 type
= init_float_type (objfile
, bits
, name
, format
);
17290 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17295 /* Find a representation of a given base type and install
17296 it in the TYPE field of the die. */
17298 static struct type
*
17299 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17301 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17303 struct attribute
*attr
;
17304 int encoding
= 0, bits
= 0;
17307 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17310 encoding
= DW_UNSND (attr
);
17312 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17315 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17317 name
= dwarf2_name (die
, cu
);
17320 complaint (&symfile_complaints
,
17321 _("DW_AT_name missing from DW_TAG_base_type"));
17326 case DW_ATE_address
:
17327 /* Turn DW_ATE_address into a void * pointer. */
17328 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17329 type
= init_pointer_type (objfile
, bits
, name
, type
);
17331 case DW_ATE_boolean
:
17332 type
= init_boolean_type (objfile
, bits
, 1, name
);
17334 case DW_ATE_complex_float
:
17335 type
= dwarf2_init_float_type (objfile
, bits
/ 2, NULL
, name
);
17336 type
= init_complex_type (objfile
, name
, type
);
17338 case DW_ATE_decimal_float
:
17339 type
= init_decfloat_type (objfile
, bits
, name
);
17342 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
);
17344 case DW_ATE_signed
:
17345 type
= init_integer_type (objfile
, bits
, 0, name
);
17347 case DW_ATE_unsigned
:
17348 if (cu
->language
== language_fortran
17350 && startswith (name
, "character("))
17351 type
= init_character_type (objfile
, bits
, 1, name
);
17353 type
= init_integer_type (objfile
, bits
, 1, name
);
17355 case DW_ATE_signed_char
:
17356 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17357 || cu
->language
== language_pascal
17358 || cu
->language
== language_fortran
)
17359 type
= init_character_type (objfile
, bits
, 0, name
);
17361 type
= init_integer_type (objfile
, bits
, 0, name
);
17363 case DW_ATE_unsigned_char
:
17364 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17365 || cu
->language
== language_pascal
17366 || cu
->language
== language_fortran
17367 || cu
->language
== language_rust
)
17368 type
= init_character_type (objfile
, bits
, 1, name
);
17370 type
= init_integer_type (objfile
, bits
, 1, name
);
17374 gdbarch
*arch
= get_objfile_arch (objfile
);
17377 type
= builtin_type (arch
)->builtin_char16
;
17378 else if (bits
== 32)
17379 type
= builtin_type (arch
)->builtin_char32
;
17382 complaint (&symfile_complaints
,
17383 _("unsupported DW_ATE_UTF bit size: '%d'"),
17385 type
= init_integer_type (objfile
, bits
, 1, name
);
17387 return set_die_type (die
, type
, cu
);
17392 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
17393 dwarf_type_encoding_name (encoding
));
17394 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17398 if (name
&& strcmp (name
, "char") == 0)
17399 TYPE_NOSIGN (type
) = 1;
17401 return set_die_type (die
, type
, cu
);
17404 /* Parse dwarf attribute if it's a block, reference or constant and put the
17405 resulting value of the attribute into struct bound_prop.
17406 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17409 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17410 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
)
17412 struct dwarf2_property_baton
*baton
;
17413 struct obstack
*obstack
17414 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17416 if (attr
== NULL
|| prop
== NULL
)
17419 if (attr_form_is_block (attr
))
17421 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17422 baton
->referenced_type
= NULL
;
17423 baton
->locexpr
.per_cu
= cu
->per_cu
;
17424 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17425 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17426 prop
->data
.baton
= baton
;
17427 prop
->kind
= PROP_LOCEXPR
;
17428 gdb_assert (prop
->data
.baton
!= NULL
);
17430 else if (attr_form_is_ref (attr
))
17432 struct dwarf2_cu
*target_cu
= cu
;
17433 struct die_info
*target_die
;
17434 struct attribute
*target_attr
;
17436 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17437 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17438 if (target_attr
== NULL
)
17439 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17441 if (target_attr
== NULL
)
17444 switch (target_attr
->name
)
17446 case DW_AT_location
:
17447 if (attr_form_is_section_offset (target_attr
))
17449 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17450 baton
->referenced_type
= die_type (target_die
, target_cu
);
17451 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17452 prop
->data
.baton
= baton
;
17453 prop
->kind
= PROP_LOCLIST
;
17454 gdb_assert (prop
->data
.baton
!= NULL
);
17456 else if (attr_form_is_block (target_attr
))
17458 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17459 baton
->referenced_type
= die_type (target_die
, target_cu
);
17460 baton
->locexpr
.per_cu
= cu
->per_cu
;
17461 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17462 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17463 prop
->data
.baton
= baton
;
17464 prop
->kind
= PROP_LOCEXPR
;
17465 gdb_assert (prop
->data
.baton
!= NULL
);
17469 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17470 "dynamic property");
17474 case DW_AT_data_member_location
:
17478 if (!handle_data_member_location (target_die
, target_cu
,
17482 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17483 baton
->referenced_type
= read_type_die (target_die
->parent
,
17485 baton
->offset_info
.offset
= offset
;
17486 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17487 prop
->data
.baton
= baton
;
17488 prop
->kind
= PROP_ADDR_OFFSET
;
17493 else if (attr_form_is_constant (attr
))
17495 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
17496 prop
->kind
= PROP_CONST
;
17500 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17501 dwarf2_name (die
, cu
));
17508 /* Read the given DW_AT_subrange DIE. */
17510 static struct type
*
17511 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17513 struct type
*base_type
, *orig_base_type
;
17514 struct type
*range_type
;
17515 struct attribute
*attr
;
17516 struct dynamic_prop low
, high
;
17517 int low_default_is_valid
;
17518 int high_bound_is_count
= 0;
17520 LONGEST negative_mask
;
17522 orig_base_type
= die_type (die
, cu
);
17523 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17524 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17525 creating the range type, but we use the result of check_typedef
17526 when examining properties of the type. */
17527 base_type
= check_typedef (orig_base_type
);
17529 /* The die_type call above may have already set the type for this DIE. */
17530 range_type
= get_die_type (die
, cu
);
17534 low
.kind
= PROP_CONST
;
17535 high
.kind
= PROP_CONST
;
17536 high
.data
.const_val
= 0;
17538 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17539 omitting DW_AT_lower_bound. */
17540 switch (cu
->language
)
17543 case language_cplus
:
17544 low
.data
.const_val
= 0;
17545 low_default_is_valid
= 1;
17547 case language_fortran
:
17548 low
.data
.const_val
= 1;
17549 low_default_is_valid
= 1;
17552 case language_objc
:
17553 case language_rust
:
17554 low
.data
.const_val
= 0;
17555 low_default_is_valid
= (cu
->header
.version
>= 4);
17559 case language_pascal
:
17560 low
.data
.const_val
= 1;
17561 low_default_is_valid
= (cu
->header
.version
>= 4);
17564 low
.data
.const_val
= 0;
17565 low_default_is_valid
= 0;
17569 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17571 attr_to_dynamic_prop (attr
, die
, cu
, &low
);
17572 else if (!low_default_is_valid
)
17573 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
17574 "- DIE at %s [in module %s]"),
17575 sect_offset_str (die
->sect_off
),
17576 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17578 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17579 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
))
17581 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
17582 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
))
17584 /* If bounds are constant do the final calculation here. */
17585 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17586 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17588 high_bound_is_count
= 1;
17592 /* Dwarf-2 specifications explicitly allows to create subrange types
17593 without specifying a base type.
17594 In that case, the base type must be set to the type of
17595 the lower bound, upper bound or count, in that order, if any of these
17596 three attributes references an object that has a type.
17597 If no base type is found, the Dwarf-2 specifications say that
17598 a signed integer type of size equal to the size of an address should
17600 For the following C code: `extern char gdb_int [];'
17601 GCC produces an empty range DIE.
17602 FIXME: muller/2010-05-28: Possible references to object for low bound,
17603 high bound or count are not yet handled by this code. */
17604 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
17606 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17607 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17608 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
17609 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
17611 /* Test "int", "long int", and "long long int" objfile types,
17612 and select the first one having a size above or equal to the
17613 architecture address size. */
17614 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
17615 base_type
= int_type
;
17618 int_type
= objfile_type (objfile
)->builtin_long
;
17619 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
17620 base_type
= int_type
;
17623 int_type
= objfile_type (objfile
)->builtin_long_long
;
17624 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
17625 base_type
= int_type
;
17630 /* Normally, the DWARF producers are expected to use a signed
17631 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17632 But this is unfortunately not always the case, as witnessed
17633 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17634 is used instead. To work around that ambiguity, we treat
17635 the bounds as signed, and thus sign-extend their values, when
17636 the base type is signed. */
17638 -((LONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17639 if (low
.kind
== PROP_CONST
17640 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17641 low
.data
.const_val
|= negative_mask
;
17642 if (high
.kind
== PROP_CONST
17643 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17644 high
.data
.const_val
|= negative_mask
;
17646 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
);
17648 if (high_bound_is_count
)
17649 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17651 /* Ada expects an empty array on no boundary attributes. */
17652 if (attr
== NULL
&& cu
->language
!= language_ada
)
17653 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17655 name
= dwarf2_name (die
, cu
);
17657 TYPE_NAME (range_type
) = name
;
17659 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17661 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17663 set_die_type (die
, range_type
, cu
);
17665 /* set_die_type should be already done. */
17666 set_descriptive_type (range_type
, die
, cu
);
17671 static struct type
*
17672 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17676 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
17678 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
17680 /* In Ada, an unspecified type is typically used when the description
17681 of the type is defered to a different unit. When encountering
17682 such a type, we treat it as a stub, and try to resolve it later on,
17684 if (cu
->language
== language_ada
)
17685 TYPE_STUB (type
) = 1;
17687 return set_die_type (die
, type
, cu
);
17690 /* Read a single die and all its descendents. Set the die's sibling
17691 field to NULL; set other fields in the die correctly, and set all
17692 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17693 location of the info_ptr after reading all of those dies. PARENT
17694 is the parent of the die in question. */
17696 static struct die_info
*
17697 read_die_and_children (const struct die_reader_specs
*reader
,
17698 const gdb_byte
*info_ptr
,
17699 const gdb_byte
**new_info_ptr
,
17700 struct die_info
*parent
)
17702 struct die_info
*die
;
17703 const gdb_byte
*cur_ptr
;
17706 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
17709 *new_info_ptr
= cur_ptr
;
17712 store_in_ref_table (die
, reader
->cu
);
17715 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17719 *new_info_ptr
= cur_ptr
;
17722 die
->sibling
= NULL
;
17723 die
->parent
= parent
;
17727 /* Read a die, all of its descendents, and all of its siblings; set
17728 all of the fields of all of the dies correctly. Arguments are as
17729 in read_die_and_children. */
17731 static struct die_info
*
17732 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17733 const gdb_byte
*info_ptr
,
17734 const gdb_byte
**new_info_ptr
,
17735 struct die_info
*parent
)
17737 struct die_info
*first_die
, *last_sibling
;
17738 const gdb_byte
*cur_ptr
;
17740 cur_ptr
= info_ptr
;
17741 first_die
= last_sibling
= NULL
;
17745 struct die_info
*die
17746 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17750 *new_info_ptr
= cur_ptr
;
17757 last_sibling
->sibling
= die
;
17759 last_sibling
= die
;
17763 /* Read a die, all of its descendents, and all of its siblings; set
17764 all of the fields of all of the dies correctly. Arguments are as
17765 in read_die_and_children.
17766 This the main entry point for reading a DIE and all its children. */
17768 static struct die_info
*
17769 read_die_and_siblings (const struct die_reader_specs
*reader
,
17770 const gdb_byte
*info_ptr
,
17771 const gdb_byte
**new_info_ptr
,
17772 struct die_info
*parent
)
17774 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17775 new_info_ptr
, parent
);
17777 if (dwarf_die_debug
)
17779 fprintf_unfiltered (gdb_stdlog
,
17780 "Read die from %s@0x%x of %s:\n",
17781 get_section_name (reader
->die_section
),
17782 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17783 bfd_get_filename (reader
->abfd
));
17784 dump_die (die
, dwarf_die_debug
);
17790 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
17792 The caller is responsible for filling in the extra attributes
17793 and updating (*DIEP)->num_attrs.
17794 Set DIEP to point to a newly allocated die with its information,
17795 except for its child, sibling, and parent fields.
17796 Set HAS_CHILDREN to tell whether the die has children or not. */
17798 static const gdb_byte
*
17799 read_full_die_1 (const struct die_reader_specs
*reader
,
17800 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17801 int *has_children
, int num_extra_attrs
)
17803 unsigned int abbrev_number
, bytes_read
, i
;
17804 struct abbrev_info
*abbrev
;
17805 struct die_info
*die
;
17806 struct dwarf2_cu
*cu
= reader
->cu
;
17807 bfd
*abfd
= reader
->abfd
;
17809 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
17810 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17811 info_ptr
+= bytes_read
;
17812 if (!abbrev_number
)
17819 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
17821 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
17823 bfd_get_filename (abfd
));
17825 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
17826 die
->sect_off
= sect_off
;
17827 die
->tag
= abbrev
->tag
;
17828 die
->abbrev
= abbrev_number
;
17830 /* Make the result usable.
17831 The caller needs to update num_attrs after adding the extra
17833 die
->num_attrs
= abbrev
->num_attrs
;
17835 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
17836 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
17840 *has_children
= abbrev
->has_children
;
17844 /* Read a die and all its attributes.
17845 Set DIEP to point to a newly allocated die with its information,
17846 except for its child, sibling, and parent fields.
17847 Set HAS_CHILDREN to tell whether the die has children or not. */
17849 static const gdb_byte
*
17850 read_full_die (const struct die_reader_specs
*reader
,
17851 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17854 const gdb_byte
*result
;
17856 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
17858 if (dwarf_die_debug
)
17860 fprintf_unfiltered (gdb_stdlog
,
17861 "Read die from %s@0x%x of %s:\n",
17862 get_section_name (reader
->die_section
),
17863 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17864 bfd_get_filename (reader
->abfd
));
17865 dump_die (*diep
, dwarf_die_debug
);
17871 /* Abbreviation tables.
17873 In DWARF version 2, the description of the debugging information is
17874 stored in a separate .debug_abbrev section. Before we read any
17875 dies from a section we read in all abbreviations and install them
17876 in a hash table. */
17878 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
17880 struct abbrev_info
*
17881 abbrev_table::alloc_abbrev ()
17883 struct abbrev_info
*abbrev
;
17885 abbrev
= XOBNEW (&abbrev_obstack
, struct abbrev_info
);
17886 memset (abbrev
, 0, sizeof (struct abbrev_info
));
17891 /* Add an abbreviation to the table. */
17894 abbrev_table::add_abbrev (unsigned int abbrev_number
,
17895 struct abbrev_info
*abbrev
)
17897 unsigned int hash_number
;
17899 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
17900 abbrev
->next
= m_abbrevs
[hash_number
];
17901 m_abbrevs
[hash_number
] = abbrev
;
17904 /* Look up an abbrev in the table.
17905 Returns NULL if the abbrev is not found. */
17907 struct abbrev_info
*
17908 abbrev_table::lookup_abbrev (unsigned int abbrev_number
)
17910 unsigned int hash_number
;
17911 struct abbrev_info
*abbrev
;
17913 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
17914 abbrev
= m_abbrevs
[hash_number
];
17918 if (abbrev
->number
== abbrev_number
)
17920 abbrev
= abbrev
->next
;
17925 /* Read in an abbrev table. */
17927 static abbrev_table_up
17928 abbrev_table_read_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
17929 struct dwarf2_section_info
*section
,
17930 sect_offset sect_off
)
17932 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17933 bfd
*abfd
= get_section_bfd_owner (section
);
17934 const gdb_byte
*abbrev_ptr
;
17935 struct abbrev_info
*cur_abbrev
;
17936 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
17937 unsigned int abbrev_form
;
17938 struct attr_abbrev
*cur_attrs
;
17939 unsigned int allocated_attrs
;
17941 abbrev_table_up
abbrev_table (new struct abbrev_table (sect_off
));
17943 dwarf2_read_section (objfile
, section
);
17944 abbrev_ptr
= section
->buffer
+ to_underlying (sect_off
);
17945 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
17946 abbrev_ptr
+= bytes_read
;
17948 allocated_attrs
= ATTR_ALLOC_CHUNK
;
17949 cur_attrs
= XNEWVEC (struct attr_abbrev
, allocated_attrs
);
17951 /* Loop until we reach an abbrev number of 0. */
17952 while (abbrev_number
)
17954 cur_abbrev
= abbrev_table
->alloc_abbrev ();
17956 /* read in abbrev header */
17957 cur_abbrev
->number
= abbrev_number
;
17959 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
17960 abbrev_ptr
+= bytes_read
;
17961 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
17964 /* now read in declarations */
17967 LONGEST implicit_const
;
17969 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
17970 abbrev_ptr
+= bytes_read
;
17971 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
17972 abbrev_ptr
+= bytes_read
;
17973 if (abbrev_form
== DW_FORM_implicit_const
)
17975 implicit_const
= read_signed_leb128 (abfd
, abbrev_ptr
,
17977 abbrev_ptr
+= bytes_read
;
17981 /* Initialize it due to a false compiler warning. */
17982 implicit_const
= -1;
17985 if (abbrev_name
== 0)
17988 if (cur_abbrev
->num_attrs
== allocated_attrs
)
17990 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
17992 = XRESIZEVEC (struct attr_abbrev
, cur_attrs
, allocated_attrs
);
17995 cur_attrs
[cur_abbrev
->num_attrs
].name
17996 = (enum dwarf_attribute
) abbrev_name
;
17997 cur_attrs
[cur_abbrev
->num_attrs
].form
17998 = (enum dwarf_form
) abbrev_form
;
17999 cur_attrs
[cur_abbrev
->num_attrs
].implicit_const
= implicit_const
;
18000 ++cur_abbrev
->num_attrs
;
18003 cur_abbrev
->attrs
=
18004 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
18005 cur_abbrev
->num_attrs
);
18006 memcpy (cur_abbrev
->attrs
, cur_attrs
,
18007 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
18009 abbrev_table
->add_abbrev (abbrev_number
, cur_abbrev
);
18011 /* Get next abbreviation.
18012 Under Irix6 the abbreviations for a compilation unit are not
18013 always properly terminated with an abbrev number of 0.
18014 Exit loop if we encounter an abbreviation which we have
18015 already read (which means we are about to read the abbreviations
18016 for the next compile unit) or if the end of the abbreviation
18017 table is reached. */
18018 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
18020 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18021 abbrev_ptr
+= bytes_read
;
18022 if (abbrev_table
->lookup_abbrev (abbrev_number
) != NULL
)
18027 return abbrev_table
;
18030 /* Returns nonzero if TAG represents a type that we might generate a partial
18034 is_type_tag_for_partial (int tag
)
18039 /* Some types that would be reasonable to generate partial symbols for,
18040 that we don't at present. */
18041 case DW_TAG_array_type
:
18042 case DW_TAG_file_type
:
18043 case DW_TAG_ptr_to_member_type
:
18044 case DW_TAG_set_type
:
18045 case DW_TAG_string_type
:
18046 case DW_TAG_subroutine_type
:
18048 case DW_TAG_base_type
:
18049 case DW_TAG_class_type
:
18050 case DW_TAG_interface_type
:
18051 case DW_TAG_enumeration_type
:
18052 case DW_TAG_structure_type
:
18053 case DW_TAG_subrange_type
:
18054 case DW_TAG_typedef
:
18055 case DW_TAG_union_type
:
18062 /* Load all DIEs that are interesting for partial symbols into memory. */
18064 static struct partial_die_info
*
18065 load_partial_dies (const struct die_reader_specs
*reader
,
18066 const gdb_byte
*info_ptr
, int building_psymtab
)
18068 struct dwarf2_cu
*cu
= reader
->cu
;
18069 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18070 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18071 unsigned int bytes_read
;
18072 unsigned int load_all
= 0;
18073 int nesting_level
= 1;
18078 gdb_assert (cu
->per_cu
!= NULL
);
18079 if (cu
->per_cu
->load_all_dies
)
18083 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18087 &cu
->comp_unit_obstack
,
18088 hashtab_obstack_allocate
,
18089 dummy_obstack_deallocate
);
18093 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18095 /* A NULL abbrev means the end of a series of children. */
18096 if (abbrev
== NULL
)
18098 if (--nesting_level
== 0)
18101 info_ptr
+= bytes_read
;
18102 last_die
= parent_die
;
18103 parent_die
= parent_die
->die_parent
;
18107 /* Check for template arguments. We never save these; if
18108 they're seen, we just mark the parent, and go on our way. */
18109 if (parent_die
!= NULL
18110 && cu
->language
== language_cplus
18111 && (abbrev
->tag
== DW_TAG_template_type_param
18112 || abbrev
->tag
== DW_TAG_template_value_param
))
18114 parent_die
->has_template_arguments
= 1;
18118 /* We don't need a partial DIE for the template argument. */
18119 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18124 /* We only recurse into c++ subprograms looking for template arguments.
18125 Skip their other children. */
18127 && cu
->language
== language_cplus
18128 && parent_die
!= NULL
18129 && parent_die
->tag
== DW_TAG_subprogram
)
18131 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18135 /* Check whether this DIE is interesting enough to save. Normally
18136 we would not be interested in members here, but there may be
18137 later variables referencing them via DW_AT_specification (for
18138 static members). */
18140 && !is_type_tag_for_partial (abbrev
->tag
)
18141 && abbrev
->tag
!= DW_TAG_constant
18142 && abbrev
->tag
!= DW_TAG_enumerator
18143 && abbrev
->tag
!= DW_TAG_subprogram
18144 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18145 && abbrev
->tag
!= DW_TAG_lexical_block
18146 && abbrev
->tag
!= DW_TAG_variable
18147 && abbrev
->tag
!= DW_TAG_namespace
18148 && abbrev
->tag
!= DW_TAG_module
18149 && abbrev
->tag
!= DW_TAG_member
18150 && abbrev
->tag
!= DW_TAG_imported_unit
18151 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18153 /* Otherwise we skip to the next sibling, if any. */
18154 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18158 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18161 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18163 /* This two-pass algorithm for processing partial symbols has a
18164 high cost in cache pressure. Thus, handle some simple cases
18165 here which cover the majority of C partial symbols. DIEs
18166 which neither have specification tags in them, nor could have
18167 specification tags elsewhere pointing at them, can simply be
18168 processed and discarded.
18170 This segment is also optional; scan_partial_symbols and
18171 add_partial_symbol will handle these DIEs if we chain
18172 them in normally. When compilers which do not emit large
18173 quantities of duplicate debug information are more common,
18174 this code can probably be removed. */
18176 /* Any complete simple types at the top level (pretty much all
18177 of them, for a language without namespaces), can be processed
18179 if (parent_die
== NULL
18180 && pdi
.has_specification
== 0
18181 && pdi
.is_declaration
== 0
18182 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18183 || pdi
.tag
== DW_TAG_base_type
18184 || pdi
.tag
== DW_TAG_subrange_type
))
18186 if (building_psymtab
&& pdi
.name
!= NULL
)
18187 add_psymbol_to_list (pdi
.name
, strlen (pdi
.name
), 0,
18188 VAR_DOMAIN
, LOC_TYPEDEF
,
18189 &objfile
->static_psymbols
,
18190 0, cu
->language
, objfile
);
18191 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18195 /* The exception for DW_TAG_typedef with has_children above is
18196 a workaround of GCC PR debug/47510. In the case of this complaint
18197 type_name_no_tag_or_error will error on such types later.
18199 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18200 it could not find the child DIEs referenced later, this is checked
18201 above. In correct DWARF DW_TAG_typedef should have no children. */
18203 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18204 complaint (&symfile_complaints
,
18205 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18206 "- DIE at %s [in module %s]"),
18207 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18209 /* If we're at the second level, and we're an enumerator, and
18210 our parent has no specification (meaning possibly lives in a
18211 namespace elsewhere), then we can add the partial symbol now
18212 instead of queueing it. */
18213 if (pdi
.tag
== DW_TAG_enumerator
18214 && parent_die
!= NULL
18215 && parent_die
->die_parent
== NULL
18216 && parent_die
->tag
== DW_TAG_enumeration_type
18217 && parent_die
->has_specification
== 0)
18219 if (pdi
.name
== NULL
)
18220 complaint (&symfile_complaints
,
18221 _("malformed enumerator DIE ignored"));
18222 else if (building_psymtab
)
18223 add_psymbol_to_list (pdi
.name
, strlen (pdi
.name
), 0,
18224 VAR_DOMAIN
, LOC_CONST
,
18225 cu
->language
== language_cplus
18226 ? &objfile
->global_psymbols
18227 : &objfile
->static_psymbols
,
18228 0, cu
->language
, objfile
);
18230 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18234 struct partial_die_info
*part_die
18235 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18237 /* We'll save this DIE so link it in. */
18238 part_die
->die_parent
= parent_die
;
18239 part_die
->die_sibling
= NULL
;
18240 part_die
->die_child
= NULL
;
18242 if (last_die
&& last_die
== parent_die
)
18243 last_die
->die_child
= part_die
;
18245 last_die
->die_sibling
= part_die
;
18247 last_die
= part_die
;
18249 if (first_die
== NULL
)
18250 first_die
= part_die
;
18252 /* Maybe add the DIE to the hash table. Not all DIEs that we
18253 find interesting need to be in the hash table, because we
18254 also have the parent/sibling/child chains; only those that we
18255 might refer to by offset later during partial symbol reading.
18257 For now this means things that might have be the target of a
18258 DW_AT_specification, DW_AT_abstract_origin, or
18259 DW_AT_extension. DW_AT_extension will refer only to
18260 namespaces; DW_AT_abstract_origin refers to functions (and
18261 many things under the function DIE, but we do not recurse
18262 into function DIEs during partial symbol reading) and
18263 possibly variables as well; DW_AT_specification refers to
18264 declarations. Declarations ought to have the DW_AT_declaration
18265 flag. It happens that GCC forgets to put it in sometimes, but
18266 only for functions, not for types.
18268 Adding more things than necessary to the hash table is harmless
18269 except for the performance cost. Adding too few will result in
18270 wasted time in find_partial_die, when we reread the compilation
18271 unit with load_all_dies set. */
18274 || abbrev
->tag
== DW_TAG_constant
18275 || abbrev
->tag
== DW_TAG_subprogram
18276 || abbrev
->tag
== DW_TAG_variable
18277 || abbrev
->tag
== DW_TAG_namespace
18278 || part_die
->is_declaration
)
18282 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18283 to_underlying (part_die
->sect_off
),
18288 /* For some DIEs we want to follow their children (if any). For C
18289 we have no reason to follow the children of structures; for other
18290 languages we have to, so that we can get at method physnames
18291 to infer fully qualified class names, for DW_AT_specification,
18292 and for C++ template arguments. For C++, we also look one level
18293 inside functions to find template arguments (if the name of the
18294 function does not already contain the template arguments).
18296 For Ada, we need to scan the children of subprograms and lexical
18297 blocks as well because Ada allows the definition of nested
18298 entities that could be interesting for the debugger, such as
18299 nested subprograms for instance. */
18300 if (last_die
->has_children
18302 || last_die
->tag
== DW_TAG_namespace
18303 || last_die
->tag
== DW_TAG_module
18304 || last_die
->tag
== DW_TAG_enumeration_type
18305 || (cu
->language
== language_cplus
18306 && last_die
->tag
== DW_TAG_subprogram
18307 && (last_die
->name
== NULL
18308 || strchr (last_die
->name
, '<') == NULL
))
18309 || (cu
->language
!= language_c
18310 && (last_die
->tag
== DW_TAG_class_type
18311 || last_die
->tag
== DW_TAG_interface_type
18312 || last_die
->tag
== DW_TAG_structure_type
18313 || last_die
->tag
== DW_TAG_union_type
))
18314 || (cu
->language
== language_ada
18315 && (last_die
->tag
== DW_TAG_subprogram
18316 || last_die
->tag
== DW_TAG_lexical_block
))))
18319 parent_die
= last_die
;
18323 /* Otherwise we skip to the next sibling, if any. */
18324 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18326 /* Back to the top, do it again. */
18330 partial_die_info::partial_die_info (sect_offset sect_off_
,
18331 struct abbrev_info
*abbrev
)
18332 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18336 /* Read a minimal amount of information into the minimal die structure.
18337 INFO_PTR should point just after the initial uleb128 of a DIE. */
18340 partial_die_info::read (const struct die_reader_specs
*reader
,
18341 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18343 struct dwarf2_cu
*cu
= reader
->cu
;
18344 struct dwarf2_per_objfile
*dwarf2_per_objfile
18345 = cu
->per_cu
->dwarf2_per_objfile
;
18347 int has_low_pc_attr
= 0;
18348 int has_high_pc_attr
= 0;
18349 int high_pc_relative
= 0;
18351 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18353 struct attribute attr
;
18355 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
18357 /* Store the data if it is of an attribute we want to keep in a
18358 partial symbol table. */
18364 case DW_TAG_compile_unit
:
18365 case DW_TAG_partial_unit
:
18366 case DW_TAG_type_unit
:
18367 /* Compilation units have a DW_AT_name that is a filename, not
18368 a source language identifier. */
18369 case DW_TAG_enumeration_type
:
18370 case DW_TAG_enumerator
:
18371 /* These tags always have simple identifiers already; no need
18372 to canonicalize them. */
18373 name
= DW_STRING (&attr
);
18377 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18380 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
18381 &objfile
->per_bfd
->storage_obstack
);
18386 case DW_AT_linkage_name
:
18387 case DW_AT_MIPS_linkage_name
:
18388 /* Note that both forms of linkage name might appear. We
18389 assume they will be the same, and we only store the last
18391 if (cu
->language
== language_ada
)
18392 name
= DW_STRING (&attr
);
18393 linkage_name
= DW_STRING (&attr
);
18396 has_low_pc_attr
= 1;
18397 lowpc
= attr_value_as_address (&attr
);
18399 case DW_AT_high_pc
:
18400 has_high_pc_attr
= 1;
18401 highpc
= attr_value_as_address (&attr
);
18402 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
18403 high_pc_relative
= 1;
18405 case DW_AT_location
:
18406 /* Support the .debug_loc offsets. */
18407 if (attr_form_is_block (&attr
))
18409 d
.locdesc
= DW_BLOCK (&attr
);
18411 else if (attr_form_is_section_offset (&attr
))
18413 dwarf2_complex_location_expr_complaint ();
18417 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18418 "partial symbol information");
18421 case DW_AT_external
:
18422 is_external
= DW_UNSND (&attr
);
18424 case DW_AT_declaration
:
18425 is_declaration
= DW_UNSND (&attr
);
18430 case DW_AT_abstract_origin
:
18431 case DW_AT_specification
:
18432 case DW_AT_extension
:
18433 has_specification
= 1;
18434 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
18435 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18436 || cu
->per_cu
->is_dwz
);
18438 case DW_AT_sibling
:
18439 /* Ignore absolute siblings, they might point outside of
18440 the current compile unit. */
18441 if (attr
.form
== DW_FORM_ref_addr
)
18442 complaint (&symfile_complaints
,
18443 _("ignoring absolute DW_AT_sibling"));
18446 const gdb_byte
*buffer
= reader
->buffer
;
18447 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
18448 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18450 if (sibling_ptr
< info_ptr
)
18451 complaint (&symfile_complaints
,
18452 _("DW_AT_sibling points backwards"));
18453 else if (sibling_ptr
> reader
->buffer_end
)
18454 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
18456 sibling
= sibling_ptr
;
18459 case DW_AT_byte_size
:
18462 case DW_AT_const_value
:
18463 has_const_value
= 1;
18465 case DW_AT_calling_convention
:
18466 /* DWARF doesn't provide a way to identify a program's source-level
18467 entry point. DW_AT_calling_convention attributes are only meant
18468 to describe functions' calling conventions.
18470 However, because it's a necessary piece of information in
18471 Fortran, and before DWARF 4 DW_CC_program was the only
18472 piece of debugging information whose definition refers to
18473 a 'main program' at all, several compilers marked Fortran
18474 main programs with DW_CC_program --- even when those
18475 functions use the standard calling conventions.
18477 Although DWARF now specifies a way to provide this
18478 information, we support this practice for backward
18480 if (DW_UNSND (&attr
) == DW_CC_program
18481 && cu
->language
== language_fortran
)
18482 main_subprogram
= 1;
18485 if (DW_UNSND (&attr
) == DW_INL_inlined
18486 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18487 may_be_inlined
= 1;
18491 if (tag
== DW_TAG_imported_unit
)
18493 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
18494 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18495 || cu
->per_cu
->is_dwz
);
18499 case DW_AT_main_subprogram
:
18500 main_subprogram
= DW_UNSND (&attr
);
18508 if (high_pc_relative
)
18511 if (has_low_pc_attr
&& has_high_pc_attr
)
18513 /* When using the GNU linker, .gnu.linkonce. sections are used to
18514 eliminate duplicate copies of functions and vtables and such.
18515 The linker will arbitrarily choose one and discard the others.
18516 The AT_*_pc values for such functions refer to local labels in
18517 these sections. If the section from that file was discarded, the
18518 labels are not in the output, so the relocs get a value of 0.
18519 If this is a discarded function, mark the pc bounds as invalid,
18520 so that GDB will ignore it. */
18521 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18523 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18524 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18526 complaint (&symfile_complaints
,
18527 _("DW_AT_low_pc %s is zero "
18528 "for DIE at %s [in module %s]"),
18529 paddress (gdbarch
, lowpc
),
18530 sect_offset_str (sect_off
),
18531 objfile_name (objfile
));
18533 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18534 else if (lowpc
>= highpc
)
18536 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18537 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18539 complaint (&symfile_complaints
,
18540 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18541 "for DIE at %s [in module %s]"),
18542 paddress (gdbarch
, lowpc
),
18543 paddress (gdbarch
, highpc
),
18544 sect_offset_str (sect_off
),
18545 objfile_name (objfile
));
18554 /* Find a cached partial DIE at OFFSET in CU. */
18556 struct partial_die_info
*
18557 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18559 struct partial_die_info
*lookup_die
= NULL
;
18560 struct partial_die_info
part_die (sect_off
);
18562 lookup_die
= ((struct partial_die_info
*)
18563 htab_find_with_hash (partial_dies
, &part_die
,
18564 to_underlying (sect_off
)));
18569 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18570 except in the case of .debug_types DIEs which do not reference
18571 outside their CU (they do however referencing other types via
18572 DW_FORM_ref_sig8). */
18574 static struct partial_die_info
*
18575 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18577 struct dwarf2_per_objfile
*dwarf2_per_objfile
18578 = cu
->per_cu
->dwarf2_per_objfile
;
18579 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18580 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18581 struct partial_die_info
*pd
= NULL
;
18583 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18584 && offset_in_cu_p (&cu
->header
, sect_off
))
18586 pd
= cu
->find_partial_die (sect_off
);
18589 /* We missed recording what we needed.
18590 Load all dies and try again. */
18591 per_cu
= cu
->per_cu
;
18595 /* TUs don't reference other CUs/TUs (except via type signatures). */
18596 if (cu
->per_cu
->is_debug_types
)
18598 error (_("Dwarf Error: Type Unit at offset %s contains"
18599 " external reference to offset %s [in module %s].\n"),
18600 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18601 bfd_get_filename (objfile
->obfd
));
18603 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18604 dwarf2_per_objfile
);
18606 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18607 load_partial_comp_unit (per_cu
);
18609 per_cu
->cu
->last_used
= 0;
18610 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18613 /* If we didn't find it, and not all dies have been loaded,
18614 load them all and try again. */
18616 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18618 per_cu
->load_all_dies
= 1;
18620 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18621 THIS_CU->cu may already be in use. So we can't just free it and
18622 replace its DIEs with the ones we read in. Instead, we leave those
18623 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18624 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18626 load_partial_comp_unit (per_cu
);
18628 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18632 internal_error (__FILE__
, __LINE__
,
18633 _("could not find partial DIE %s "
18634 "in cache [from module %s]\n"),
18635 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18639 /* See if we can figure out if the class lives in a namespace. We do
18640 this by looking for a member function; its demangled name will
18641 contain namespace info, if there is any. */
18644 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18645 struct dwarf2_cu
*cu
)
18647 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18648 what template types look like, because the demangler
18649 frequently doesn't give the same name as the debug info. We
18650 could fix this by only using the demangled name to get the
18651 prefix (but see comment in read_structure_type). */
18653 struct partial_die_info
*real_pdi
;
18654 struct partial_die_info
*child_pdi
;
18656 /* If this DIE (this DIE's specification, if any) has a parent, then
18657 we should not do this. We'll prepend the parent's fully qualified
18658 name when we create the partial symbol. */
18660 real_pdi
= struct_pdi
;
18661 while (real_pdi
->has_specification
)
18662 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
18663 real_pdi
->spec_is_dwz
, cu
);
18665 if (real_pdi
->die_parent
!= NULL
)
18668 for (child_pdi
= struct_pdi
->die_child
;
18670 child_pdi
= child_pdi
->die_sibling
)
18672 if (child_pdi
->tag
== DW_TAG_subprogram
18673 && child_pdi
->linkage_name
!= NULL
)
18675 char *actual_class_name
18676 = language_class_name_from_physname (cu
->language_defn
,
18677 child_pdi
->linkage_name
);
18678 if (actual_class_name
!= NULL
)
18680 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18683 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
18685 strlen (actual_class_name
)));
18686 xfree (actual_class_name
);
18694 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18696 /* Once we've fixed up a die, there's no point in doing so again.
18697 This also avoids a memory leak if we were to call
18698 guess_partial_die_structure_name multiple times. */
18702 /* If we found a reference attribute and the DIE has no name, try
18703 to find a name in the referred to DIE. */
18705 if (name
== NULL
&& has_specification
)
18707 struct partial_die_info
*spec_die
;
18709 spec_die
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18711 spec_die
->fixup (cu
);
18713 if (spec_die
->name
)
18715 name
= spec_die
->name
;
18717 /* Copy DW_AT_external attribute if it is set. */
18718 if (spec_die
->is_external
)
18719 is_external
= spec_die
->is_external
;
18723 /* Set default names for some unnamed DIEs. */
18725 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18726 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18728 /* If there is no parent die to provide a namespace, and there are
18729 children, see if we can determine the namespace from their linkage
18731 if (cu
->language
== language_cplus
18732 && !VEC_empty (dwarf2_section_info_def
,
18733 cu
->per_cu
->dwarf2_per_objfile
->types
)
18734 && die_parent
== NULL
18736 && (tag
== DW_TAG_class_type
18737 || tag
== DW_TAG_structure_type
18738 || tag
== DW_TAG_union_type
))
18739 guess_partial_die_structure_name (this, cu
);
18741 /* GCC might emit a nameless struct or union that has a linkage
18742 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18744 && (tag
== DW_TAG_class_type
18745 || tag
== DW_TAG_interface_type
18746 || tag
== DW_TAG_structure_type
18747 || tag
== DW_TAG_union_type
)
18748 && linkage_name
!= NULL
)
18752 demangled
= gdb_demangle (linkage_name
, DMGL_TYPES
);
18757 /* Strip any leading namespaces/classes, keep only the base name.
18758 DW_AT_name for named DIEs does not contain the prefixes. */
18759 base
= strrchr (demangled
, ':');
18760 if (base
&& base
> demangled
&& base
[-1] == ':')
18765 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18768 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
18769 base
, strlen (base
)));
18777 /* Read an attribute value described by an attribute form. */
18779 static const gdb_byte
*
18780 read_attribute_value (const struct die_reader_specs
*reader
,
18781 struct attribute
*attr
, unsigned form
,
18782 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
18784 struct dwarf2_cu
*cu
= reader
->cu
;
18785 struct dwarf2_per_objfile
*dwarf2_per_objfile
18786 = cu
->per_cu
->dwarf2_per_objfile
;
18787 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18788 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18789 bfd
*abfd
= reader
->abfd
;
18790 struct comp_unit_head
*cu_header
= &cu
->header
;
18791 unsigned int bytes_read
;
18792 struct dwarf_block
*blk
;
18794 attr
->form
= (enum dwarf_form
) form
;
18797 case DW_FORM_ref_addr
:
18798 if (cu
->header
.version
== 2)
18799 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
18801 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
18802 &cu
->header
, &bytes_read
);
18803 info_ptr
+= bytes_read
;
18805 case DW_FORM_GNU_ref_alt
:
18806 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
18807 info_ptr
+= bytes_read
;
18810 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
18811 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
18812 info_ptr
+= bytes_read
;
18814 case DW_FORM_block2
:
18815 blk
= dwarf_alloc_block (cu
);
18816 blk
->size
= read_2_bytes (abfd
, info_ptr
);
18818 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18819 info_ptr
+= blk
->size
;
18820 DW_BLOCK (attr
) = blk
;
18822 case DW_FORM_block4
:
18823 blk
= dwarf_alloc_block (cu
);
18824 blk
->size
= read_4_bytes (abfd
, info_ptr
);
18826 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18827 info_ptr
+= blk
->size
;
18828 DW_BLOCK (attr
) = blk
;
18830 case DW_FORM_data2
:
18831 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
18834 case DW_FORM_data4
:
18835 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
18838 case DW_FORM_data8
:
18839 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
18842 case DW_FORM_data16
:
18843 blk
= dwarf_alloc_block (cu
);
18845 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
18847 DW_BLOCK (attr
) = blk
;
18849 case DW_FORM_sec_offset
:
18850 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
18851 info_ptr
+= bytes_read
;
18853 case DW_FORM_string
:
18854 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
18855 DW_STRING_IS_CANONICAL (attr
) = 0;
18856 info_ptr
+= bytes_read
;
18859 if (!cu
->per_cu
->is_dwz
)
18861 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
18862 abfd
, info_ptr
, cu_header
,
18864 DW_STRING_IS_CANONICAL (attr
) = 0;
18865 info_ptr
+= bytes_read
;
18869 case DW_FORM_line_strp
:
18870 if (!cu
->per_cu
->is_dwz
)
18872 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
18874 cu_header
, &bytes_read
);
18875 DW_STRING_IS_CANONICAL (attr
) = 0;
18876 info_ptr
+= bytes_read
;
18880 case DW_FORM_GNU_strp_alt
:
18882 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
18883 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
18886 DW_STRING (attr
) = read_indirect_string_from_dwz (objfile
,
18888 DW_STRING_IS_CANONICAL (attr
) = 0;
18889 info_ptr
+= bytes_read
;
18892 case DW_FORM_exprloc
:
18893 case DW_FORM_block
:
18894 blk
= dwarf_alloc_block (cu
);
18895 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18896 info_ptr
+= bytes_read
;
18897 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18898 info_ptr
+= blk
->size
;
18899 DW_BLOCK (attr
) = blk
;
18901 case DW_FORM_block1
:
18902 blk
= dwarf_alloc_block (cu
);
18903 blk
->size
= read_1_byte (abfd
, info_ptr
);
18905 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18906 info_ptr
+= blk
->size
;
18907 DW_BLOCK (attr
) = blk
;
18909 case DW_FORM_data1
:
18910 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18914 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18917 case DW_FORM_flag_present
:
18918 DW_UNSND (attr
) = 1;
18920 case DW_FORM_sdata
:
18921 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18922 info_ptr
+= bytes_read
;
18924 case DW_FORM_udata
:
18925 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18926 info_ptr
+= bytes_read
;
18929 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18930 + read_1_byte (abfd
, info_ptr
));
18934 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18935 + read_2_bytes (abfd
, info_ptr
));
18939 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18940 + read_4_bytes (abfd
, info_ptr
));
18944 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18945 + read_8_bytes (abfd
, info_ptr
));
18948 case DW_FORM_ref_sig8
:
18949 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
18952 case DW_FORM_ref_udata
:
18953 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18954 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
18955 info_ptr
+= bytes_read
;
18957 case DW_FORM_indirect
:
18958 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18959 info_ptr
+= bytes_read
;
18960 if (form
== DW_FORM_implicit_const
)
18962 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18963 info_ptr
+= bytes_read
;
18965 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
18968 case DW_FORM_implicit_const
:
18969 DW_SND (attr
) = implicit_const
;
18971 case DW_FORM_GNU_addr_index
:
18972 if (reader
->dwo_file
== NULL
)
18974 /* For now flag a hard error.
18975 Later we can turn this into a complaint. */
18976 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
18977 dwarf_form_name (form
),
18978 bfd_get_filename (abfd
));
18980 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
18981 info_ptr
+= bytes_read
;
18983 case DW_FORM_GNU_str_index
:
18984 if (reader
->dwo_file
== NULL
)
18986 /* For now flag a hard error.
18987 Later we can turn this into a complaint if warranted. */
18988 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
18989 dwarf_form_name (form
),
18990 bfd_get_filename (abfd
));
18993 ULONGEST str_index
=
18994 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18996 DW_STRING (attr
) = read_str_index (reader
, str_index
);
18997 DW_STRING_IS_CANONICAL (attr
) = 0;
18998 info_ptr
+= bytes_read
;
19002 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19003 dwarf_form_name (form
),
19004 bfd_get_filename (abfd
));
19008 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
19009 attr
->form
= DW_FORM_GNU_ref_alt
;
19011 /* We have seen instances where the compiler tried to emit a byte
19012 size attribute of -1 which ended up being encoded as an unsigned
19013 0xffffffff. Although 0xffffffff is technically a valid size value,
19014 an object of this size seems pretty unlikely so we can relatively
19015 safely treat these cases as if the size attribute was invalid and
19016 treat them as zero by default. */
19017 if (attr
->name
== DW_AT_byte_size
19018 && form
== DW_FORM_data4
19019 && DW_UNSND (attr
) >= 0xffffffff)
19022 (&symfile_complaints
,
19023 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19024 hex_string (DW_UNSND (attr
)));
19025 DW_UNSND (attr
) = 0;
19031 /* Read an attribute described by an abbreviated attribute. */
19033 static const gdb_byte
*
19034 read_attribute (const struct die_reader_specs
*reader
,
19035 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19036 const gdb_byte
*info_ptr
)
19038 attr
->name
= abbrev
->name
;
19039 return read_attribute_value (reader
, attr
, abbrev
->form
,
19040 abbrev
->implicit_const
, info_ptr
);
19043 /* Read dwarf information from a buffer. */
19045 static unsigned int
19046 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
19048 return bfd_get_8 (abfd
, buf
);
19052 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
19054 return bfd_get_signed_8 (abfd
, buf
);
19057 static unsigned int
19058 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19060 return bfd_get_16 (abfd
, buf
);
19064 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19066 return bfd_get_signed_16 (abfd
, buf
);
19069 static unsigned int
19070 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19072 return bfd_get_32 (abfd
, buf
);
19076 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19078 return bfd_get_signed_32 (abfd
, buf
);
19082 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19084 return bfd_get_64 (abfd
, buf
);
19088 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
19089 unsigned int *bytes_read
)
19091 struct comp_unit_head
*cu_header
= &cu
->header
;
19092 CORE_ADDR retval
= 0;
19094 if (cu_header
->signed_addr_p
)
19096 switch (cu_header
->addr_size
)
19099 retval
= bfd_get_signed_16 (abfd
, buf
);
19102 retval
= bfd_get_signed_32 (abfd
, buf
);
19105 retval
= bfd_get_signed_64 (abfd
, buf
);
19108 internal_error (__FILE__
, __LINE__
,
19109 _("read_address: bad switch, signed [in module %s]"),
19110 bfd_get_filename (abfd
));
19115 switch (cu_header
->addr_size
)
19118 retval
= bfd_get_16 (abfd
, buf
);
19121 retval
= bfd_get_32 (abfd
, buf
);
19124 retval
= bfd_get_64 (abfd
, buf
);
19127 internal_error (__FILE__
, __LINE__
,
19128 _("read_address: bad switch, "
19129 "unsigned [in module %s]"),
19130 bfd_get_filename (abfd
));
19134 *bytes_read
= cu_header
->addr_size
;
19138 /* Read the initial length from a section. The (draft) DWARF 3
19139 specification allows the initial length to take up either 4 bytes
19140 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
19141 bytes describe the length and all offsets will be 8 bytes in length
19144 An older, non-standard 64-bit format is also handled by this
19145 function. The older format in question stores the initial length
19146 as an 8-byte quantity without an escape value. Lengths greater
19147 than 2^32 aren't very common which means that the initial 4 bytes
19148 is almost always zero. Since a length value of zero doesn't make
19149 sense for the 32-bit format, this initial zero can be considered to
19150 be an escape value which indicates the presence of the older 64-bit
19151 format. As written, the code can't detect (old format) lengths
19152 greater than 4GB. If it becomes necessary to handle lengths
19153 somewhat larger than 4GB, we could allow other small values (such
19154 as the non-sensical values of 1, 2, and 3) to also be used as
19155 escape values indicating the presence of the old format.
19157 The value returned via bytes_read should be used to increment the
19158 relevant pointer after calling read_initial_length().
19160 [ Note: read_initial_length() and read_offset() are based on the
19161 document entitled "DWARF Debugging Information Format", revision
19162 3, draft 8, dated November 19, 2001. This document was obtained
19165 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
19167 This document is only a draft and is subject to change. (So beware.)
19169 Details regarding the older, non-standard 64-bit format were
19170 determined empirically by examining 64-bit ELF files produced by
19171 the SGI toolchain on an IRIX 6.5 machine.
19173 - Kevin, July 16, 2002
19177 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
19179 LONGEST length
= bfd_get_32 (abfd
, buf
);
19181 if (length
== 0xffffffff)
19183 length
= bfd_get_64 (abfd
, buf
+ 4);
19186 else if (length
== 0)
19188 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
19189 length
= bfd_get_64 (abfd
, buf
);
19200 /* Cover function for read_initial_length.
19201 Returns the length of the object at BUF, and stores the size of the
19202 initial length in *BYTES_READ and stores the size that offsets will be in
19204 If the initial length size is not equivalent to that specified in
19205 CU_HEADER then issue a complaint.
19206 This is useful when reading non-comp-unit headers. */
19209 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
19210 const struct comp_unit_head
*cu_header
,
19211 unsigned int *bytes_read
,
19212 unsigned int *offset_size
)
19214 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
19216 gdb_assert (cu_header
->initial_length_size
== 4
19217 || cu_header
->initial_length_size
== 8
19218 || cu_header
->initial_length_size
== 12);
19220 if (cu_header
->initial_length_size
!= *bytes_read
)
19221 complaint (&symfile_complaints
,
19222 _("intermixed 32-bit and 64-bit DWARF sections"));
19224 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
19228 /* Read an offset from the data stream. The size of the offset is
19229 given by cu_header->offset_size. */
19232 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
19233 const struct comp_unit_head
*cu_header
,
19234 unsigned int *bytes_read
)
19236 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
19238 *bytes_read
= cu_header
->offset_size
;
19242 /* Read an offset from the data stream. */
19245 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
19247 LONGEST retval
= 0;
19249 switch (offset_size
)
19252 retval
= bfd_get_32 (abfd
, buf
);
19255 retval
= bfd_get_64 (abfd
, buf
);
19258 internal_error (__FILE__
, __LINE__
,
19259 _("read_offset_1: bad switch [in module %s]"),
19260 bfd_get_filename (abfd
));
19266 static const gdb_byte
*
19267 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
19269 /* If the size of a host char is 8 bits, we can return a pointer
19270 to the buffer, otherwise we have to copy the data to a buffer
19271 allocated on the temporary obstack. */
19272 gdb_assert (HOST_CHAR_BIT
== 8);
19276 static const char *
19277 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
19278 unsigned int *bytes_read_ptr
)
19280 /* If the size of a host char is 8 bits, we can return a pointer
19281 to the string, otherwise we have to copy the string to a buffer
19282 allocated on the temporary obstack. */
19283 gdb_assert (HOST_CHAR_BIT
== 8);
19286 *bytes_read_ptr
= 1;
19289 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
19290 return (const char *) buf
;
19293 /* Return pointer to string at section SECT offset STR_OFFSET with error
19294 reporting strings FORM_NAME and SECT_NAME. */
19296 static const char *
19297 read_indirect_string_at_offset_from (struct objfile
*objfile
,
19298 bfd
*abfd
, LONGEST str_offset
,
19299 struct dwarf2_section_info
*sect
,
19300 const char *form_name
,
19301 const char *sect_name
)
19303 dwarf2_read_section (objfile
, sect
);
19304 if (sect
->buffer
== NULL
)
19305 error (_("%s used without %s section [in module %s]"),
19306 form_name
, sect_name
, bfd_get_filename (abfd
));
19307 if (str_offset
>= sect
->size
)
19308 error (_("%s pointing outside of %s section [in module %s]"),
19309 form_name
, sect_name
, bfd_get_filename (abfd
));
19310 gdb_assert (HOST_CHAR_BIT
== 8);
19311 if (sect
->buffer
[str_offset
] == '\0')
19313 return (const char *) (sect
->buffer
+ str_offset
);
19316 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19318 static const char *
19319 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19320 bfd
*abfd
, LONGEST str_offset
)
19322 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19324 &dwarf2_per_objfile
->str
,
19325 "DW_FORM_strp", ".debug_str");
19328 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
19330 static const char *
19331 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19332 bfd
*abfd
, LONGEST str_offset
)
19334 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19336 &dwarf2_per_objfile
->line_str
,
19337 "DW_FORM_line_strp",
19338 ".debug_line_str");
19341 /* Read a string at offset STR_OFFSET in the .debug_str section from
19342 the .dwz file DWZ. Throw an error if the offset is too large. If
19343 the string consists of a single NUL byte, return NULL; otherwise
19344 return a pointer to the string. */
19346 static const char *
19347 read_indirect_string_from_dwz (struct objfile
*objfile
, struct dwz_file
*dwz
,
19348 LONGEST str_offset
)
19350 dwarf2_read_section (objfile
, &dwz
->str
);
19352 if (dwz
->str
.buffer
== NULL
)
19353 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
19354 "section [in module %s]"),
19355 bfd_get_filename (dwz
->dwz_bfd
));
19356 if (str_offset
>= dwz
->str
.size
)
19357 error (_("DW_FORM_GNU_strp_alt pointing outside of "
19358 ".debug_str section [in module %s]"),
19359 bfd_get_filename (dwz
->dwz_bfd
));
19360 gdb_assert (HOST_CHAR_BIT
== 8);
19361 if (dwz
->str
.buffer
[str_offset
] == '\0')
19363 return (const char *) (dwz
->str
.buffer
+ str_offset
);
19366 /* Return pointer to string at .debug_str offset as read from BUF.
19367 BUF is assumed to be in a compilation unit described by CU_HEADER.
19368 Return *BYTES_READ_PTR count of bytes read from BUF. */
19370 static const char *
19371 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
19372 const gdb_byte
*buf
,
19373 const struct comp_unit_head
*cu_header
,
19374 unsigned int *bytes_read_ptr
)
19376 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19378 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
19381 /* Return pointer to string at .debug_line_str offset as read from BUF.
19382 BUF is assumed to be in a compilation unit described by CU_HEADER.
19383 Return *BYTES_READ_PTR count of bytes read from BUF. */
19385 static const char *
19386 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19387 bfd
*abfd
, const gdb_byte
*buf
,
19388 const struct comp_unit_head
*cu_header
,
19389 unsigned int *bytes_read_ptr
)
19391 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19393 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
19398 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
19399 unsigned int *bytes_read_ptr
)
19402 unsigned int num_read
;
19404 unsigned char byte
;
19411 byte
= bfd_get_8 (abfd
, buf
);
19414 result
|= ((ULONGEST
) (byte
& 127) << shift
);
19415 if ((byte
& 128) == 0)
19421 *bytes_read_ptr
= num_read
;
19426 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
19427 unsigned int *bytes_read_ptr
)
19430 int shift
, num_read
;
19431 unsigned char byte
;
19438 byte
= bfd_get_8 (abfd
, buf
);
19441 result
|= ((LONGEST
) (byte
& 127) << shift
);
19443 if ((byte
& 128) == 0)
19448 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
19449 result
|= -(((LONGEST
) 1) << shift
);
19450 *bytes_read_ptr
= num_read
;
19454 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
19455 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
19456 ADDR_SIZE is the size of addresses from the CU header. */
19459 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19460 unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
19462 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19463 bfd
*abfd
= objfile
->obfd
;
19464 const gdb_byte
*info_ptr
;
19466 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
19467 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
19468 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
19469 objfile_name (objfile
));
19470 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
19471 error (_("DW_FORM_addr_index pointing outside of "
19472 ".debug_addr section [in module %s]"),
19473 objfile_name (objfile
));
19474 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
19475 + addr_base
+ addr_index
* addr_size
);
19476 if (addr_size
== 4)
19477 return bfd_get_32 (abfd
, info_ptr
);
19479 return bfd_get_64 (abfd
, info_ptr
);
19482 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
19485 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
19487 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
19488 cu
->addr_base
, cu
->header
.addr_size
);
19491 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
19494 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
19495 unsigned int *bytes_read
)
19497 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
19498 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
19500 return read_addr_index (cu
, addr_index
);
19503 /* Data structure to pass results from dwarf2_read_addr_index_reader
19504 back to dwarf2_read_addr_index. */
19506 struct dwarf2_read_addr_index_data
19508 ULONGEST addr_base
;
19512 /* die_reader_func for dwarf2_read_addr_index. */
19515 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
19516 const gdb_byte
*info_ptr
,
19517 struct die_info
*comp_unit_die
,
19521 struct dwarf2_cu
*cu
= reader
->cu
;
19522 struct dwarf2_read_addr_index_data
*aidata
=
19523 (struct dwarf2_read_addr_index_data
*) data
;
19525 aidata
->addr_base
= cu
->addr_base
;
19526 aidata
->addr_size
= cu
->header
.addr_size
;
19529 /* Given an index in .debug_addr, fetch the value.
19530 NOTE: This can be called during dwarf expression evaluation,
19531 long after the debug information has been read, and thus per_cu->cu
19532 may no longer exist. */
19535 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
19536 unsigned int addr_index
)
19538 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
19539 struct dwarf2_cu
*cu
= per_cu
->cu
;
19540 ULONGEST addr_base
;
19543 /* We need addr_base and addr_size.
19544 If we don't have PER_CU->cu, we have to get it.
19545 Nasty, but the alternative is storing the needed info in PER_CU,
19546 which at this point doesn't seem justified: it's not clear how frequently
19547 it would get used and it would increase the size of every PER_CU.
19548 Entry points like dwarf2_per_cu_addr_size do a similar thing
19549 so we're not in uncharted territory here.
19550 Alas we need to be a bit more complicated as addr_base is contained
19553 We don't need to read the entire CU(/TU).
19554 We just need the header and top level die.
19556 IWBN to use the aging mechanism to let us lazily later discard the CU.
19557 For now we skip this optimization. */
19561 addr_base
= cu
->addr_base
;
19562 addr_size
= cu
->header
.addr_size
;
19566 struct dwarf2_read_addr_index_data aidata
;
19568 /* Note: We can't use init_cutu_and_read_dies_simple here,
19569 we need addr_base. */
19570 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
19571 dwarf2_read_addr_index_reader
, &aidata
);
19572 addr_base
= aidata
.addr_base
;
19573 addr_size
= aidata
.addr_size
;
19576 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
19580 /* Given a DW_FORM_GNU_str_index, fetch the string.
19581 This is only used by the Fission support. */
19583 static const char *
19584 read_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
19586 struct dwarf2_cu
*cu
= reader
->cu
;
19587 struct dwarf2_per_objfile
*dwarf2_per_objfile
19588 = cu
->per_cu
->dwarf2_per_objfile
;
19589 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19590 const char *objf_name
= objfile_name (objfile
);
19591 bfd
*abfd
= objfile
->obfd
;
19592 struct dwarf2_section_info
*str_section
= &reader
->dwo_file
->sections
.str
;
19593 struct dwarf2_section_info
*str_offsets_section
=
19594 &reader
->dwo_file
->sections
.str_offsets
;
19595 const gdb_byte
*info_ptr
;
19596 ULONGEST str_offset
;
19597 static const char form_name
[] = "DW_FORM_GNU_str_index";
19599 dwarf2_read_section (objfile
, str_section
);
19600 dwarf2_read_section (objfile
, str_offsets_section
);
19601 if (str_section
->buffer
== NULL
)
19602 error (_("%s used without .debug_str.dwo section"
19603 " in CU at offset %s [in module %s]"),
19604 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19605 if (str_offsets_section
->buffer
== NULL
)
19606 error (_("%s used without .debug_str_offsets.dwo section"
19607 " in CU at offset %s [in module %s]"),
19608 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19609 if (str_index
* cu
->header
.offset_size
>= str_offsets_section
->size
)
19610 error (_("%s pointing outside of .debug_str_offsets.dwo"
19611 " section in CU at offset %s [in module %s]"),
19612 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19613 info_ptr
= (str_offsets_section
->buffer
19614 + str_index
* cu
->header
.offset_size
);
19615 if (cu
->header
.offset_size
== 4)
19616 str_offset
= bfd_get_32 (abfd
, info_ptr
);
19618 str_offset
= bfd_get_64 (abfd
, info_ptr
);
19619 if (str_offset
>= str_section
->size
)
19620 error (_("Offset from %s pointing outside of"
19621 " .debug_str.dwo section in CU at offset %s [in module %s]"),
19622 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19623 return (const char *) (str_section
->buffer
+ str_offset
);
19626 /* Return the length of an LEB128 number in BUF. */
19629 leb128_size (const gdb_byte
*buf
)
19631 const gdb_byte
*begin
= buf
;
19637 if ((byte
& 128) == 0)
19638 return buf
- begin
;
19643 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19652 cu
->language
= language_c
;
19655 case DW_LANG_C_plus_plus
:
19656 case DW_LANG_C_plus_plus_11
:
19657 case DW_LANG_C_plus_plus_14
:
19658 cu
->language
= language_cplus
;
19661 cu
->language
= language_d
;
19663 case DW_LANG_Fortran77
:
19664 case DW_LANG_Fortran90
:
19665 case DW_LANG_Fortran95
:
19666 case DW_LANG_Fortran03
:
19667 case DW_LANG_Fortran08
:
19668 cu
->language
= language_fortran
;
19671 cu
->language
= language_go
;
19673 case DW_LANG_Mips_Assembler
:
19674 cu
->language
= language_asm
;
19676 case DW_LANG_Ada83
:
19677 case DW_LANG_Ada95
:
19678 cu
->language
= language_ada
;
19680 case DW_LANG_Modula2
:
19681 cu
->language
= language_m2
;
19683 case DW_LANG_Pascal83
:
19684 cu
->language
= language_pascal
;
19687 cu
->language
= language_objc
;
19690 case DW_LANG_Rust_old
:
19691 cu
->language
= language_rust
;
19693 case DW_LANG_Cobol74
:
19694 case DW_LANG_Cobol85
:
19696 cu
->language
= language_minimal
;
19699 cu
->language_defn
= language_def (cu
->language
);
19702 /* Return the named attribute or NULL if not there. */
19704 static struct attribute
*
19705 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19710 struct attribute
*spec
= NULL
;
19712 for (i
= 0; i
< die
->num_attrs
; ++i
)
19714 if (die
->attrs
[i
].name
== name
)
19715 return &die
->attrs
[i
];
19716 if (die
->attrs
[i
].name
== DW_AT_specification
19717 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19718 spec
= &die
->attrs
[i
];
19724 die
= follow_die_ref (die
, spec
, &cu
);
19730 /* Return the named attribute or NULL if not there,
19731 but do not follow DW_AT_specification, etc.
19732 This is for use in contexts where we're reading .debug_types dies.
19733 Following DW_AT_specification, DW_AT_abstract_origin will take us
19734 back up the chain, and we want to go down. */
19736 static struct attribute
*
19737 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
19741 for (i
= 0; i
< die
->num_attrs
; ++i
)
19742 if (die
->attrs
[i
].name
== name
)
19743 return &die
->attrs
[i
];
19748 /* Return the string associated with a string-typed attribute, or NULL if it
19749 is either not found or is of an incorrect type. */
19751 static const char *
19752 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19754 struct attribute
*attr
;
19755 const char *str
= NULL
;
19757 attr
= dwarf2_attr (die
, name
, cu
);
19761 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
19762 || attr
->form
== DW_FORM_string
19763 || attr
->form
== DW_FORM_GNU_str_index
19764 || attr
->form
== DW_FORM_GNU_strp_alt
)
19765 str
= DW_STRING (attr
);
19767 complaint (&symfile_complaints
,
19768 _("string type expected for attribute %s for "
19769 "DIE at %s in module %s"),
19770 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19771 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
19777 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19778 and holds a non-zero value. This function should only be used for
19779 DW_FORM_flag or DW_FORM_flag_present attributes. */
19782 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19784 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19786 return (attr
&& DW_UNSND (attr
));
19790 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19792 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19793 which value is non-zero. However, we have to be careful with
19794 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19795 (via dwarf2_flag_true_p) follows this attribute. So we may
19796 end up accidently finding a declaration attribute that belongs
19797 to a different DIE referenced by the specification attribute,
19798 even though the given DIE does not have a declaration attribute. */
19799 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19800 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19803 /* Return the die giving the specification for DIE, if there is
19804 one. *SPEC_CU is the CU containing DIE on input, and the CU
19805 containing the return value on output. If there is no
19806 specification, but there is an abstract origin, that is
19809 static struct die_info
*
19810 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19812 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19815 if (spec_attr
== NULL
)
19816 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19818 if (spec_attr
== NULL
)
19821 return follow_die_ref (die
, spec_attr
, spec_cu
);
19824 /* Stub for free_line_header to match void * callback types. */
19827 free_line_header_voidp (void *arg
)
19829 struct line_header
*lh
= (struct line_header
*) arg
;
19835 line_header::add_include_dir (const char *include_dir
)
19837 if (dwarf_line_debug
>= 2)
19838 fprintf_unfiltered (gdb_stdlog
, "Adding dir %zu: %s\n",
19839 include_dirs
.size () + 1, include_dir
);
19841 include_dirs
.push_back (include_dir
);
19845 line_header::add_file_name (const char *name
,
19847 unsigned int mod_time
,
19848 unsigned int length
)
19850 if (dwarf_line_debug
>= 2)
19851 fprintf_unfiltered (gdb_stdlog
, "Adding file %u: %s\n",
19852 (unsigned) file_names
.size () + 1, name
);
19854 file_names
.emplace_back (name
, d_index
, mod_time
, length
);
19857 /* A convenience function to find the proper .debug_line section for a CU. */
19859 static struct dwarf2_section_info
*
19860 get_debug_line_section (struct dwarf2_cu
*cu
)
19862 struct dwarf2_section_info
*section
;
19863 struct dwarf2_per_objfile
*dwarf2_per_objfile
19864 = cu
->per_cu
->dwarf2_per_objfile
;
19866 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19868 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19869 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19870 else if (cu
->per_cu
->is_dwz
)
19872 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19874 section
= &dwz
->line
;
19877 section
= &dwarf2_per_objfile
->line
;
19882 /* Read directory or file name entry format, starting with byte of
19883 format count entries, ULEB128 pairs of entry formats, ULEB128 of
19884 entries count and the entries themselves in the described entry
19888 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19889 bfd
*abfd
, const gdb_byte
**bufp
,
19890 struct line_header
*lh
,
19891 const struct comp_unit_head
*cu_header
,
19892 void (*callback
) (struct line_header
*lh
,
19895 unsigned int mod_time
,
19896 unsigned int length
))
19898 gdb_byte format_count
, formati
;
19899 ULONGEST data_count
, datai
;
19900 const gdb_byte
*buf
= *bufp
;
19901 const gdb_byte
*format_header_data
;
19902 unsigned int bytes_read
;
19904 format_count
= read_1_byte (abfd
, buf
);
19906 format_header_data
= buf
;
19907 for (formati
= 0; formati
< format_count
; formati
++)
19909 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19911 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19915 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19917 for (datai
= 0; datai
< data_count
; datai
++)
19919 const gdb_byte
*format
= format_header_data
;
19920 struct file_entry fe
;
19922 for (formati
= 0; formati
< format_count
; formati
++)
19924 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
19925 format
+= bytes_read
;
19927 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
19928 format
+= bytes_read
;
19930 gdb::optional
<const char *> string
;
19931 gdb::optional
<unsigned int> uint
;
19935 case DW_FORM_string
:
19936 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
19940 case DW_FORM_line_strp
:
19941 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
19948 case DW_FORM_data1
:
19949 uint
.emplace (read_1_byte (abfd
, buf
));
19953 case DW_FORM_data2
:
19954 uint
.emplace (read_2_bytes (abfd
, buf
));
19958 case DW_FORM_data4
:
19959 uint
.emplace (read_4_bytes (abfd
, buf
));
19963 case DW_FORM_data8
:
19964 uint
.emplace (read_8_bytes (abfd
, buf
));
19968 case DW_FORM_udata
:
19969 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
19973 case DW_FORM_block
:
19974 /* It is valid only for DW_LNCT_timestamp which is ignored by
19979 switch (content_type
)
19982 if (string
.has_value ())
19985 case DW_LNCT_directory_index
:
19986 if (uint
.has_value ())
19987 fe
.d_index
= (dir_index
) *uint
;
19989 case DW_LNCT_timestamp
:
19990 if (uint
.has_value ())
19991 fe
.mod_time
= *uint
;
19994 if (uint
.has_value ())
20000 complaint (&symfile_complaints
,
20001 _("Unknown format content type %s"),
20002 pulongest (content_type
));
20006 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
20012 /* Read the statement program header starting at OFFSET in
20013 .debug_line, or .debug_line.dwo. Return a pointer
20014 to a struct line_header, allocated using xmalloc.
20015 Returns NULL if there is a problem reading the header, e.g., if it
20016 has a version we don't understand.
20018 NOTE: the strings in the include directory and file name tables of
20019 the returned object point into the dwarf line section buffer,
20020 and must not be freed. */
20022 static line_header_up
20023 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20025 const gdb_byte
*line_ptr
;
20026 unsigned int bytes_read
, offset_size
;
20028 const char *cur_dir
, *cur_file
;
20029 struct dwarf2_section_info
*section
;
20031 struct dwarf2_per_objfile
*dwarf2_per_objfile
20032 = cu
->per_cu
->dwarf2_per_objfile
;
20034 section
= get_debug_line_section (cu
);
20035 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
20036 if (section
->buffer
== NULL
)
20038 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20039 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
20041 complaint (&symfile_complaints
, _("missing .debug_line section"));
20045 /* We can't do this until we know the section is non-empty.
20046 Only then do we know we have such a section. */
20047 abfd
= get_section_bfd_owner (section
);
20049 /* Make sure that at least there's room for the total_length field.
20050 That could be 12 bytes long, but we're just going to fudge that. */
20051 if (to_underlying (sect_off
) + 4 >= section
->size
)
20053 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20057 line_header_up
lh (new line_header ());
20059 lh
->sect_off
= sect_off
;
20060 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
20062 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
20064 /* Read in the header. */
20066 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
20067 &bytes_read
, &offset_size
);
20068 line_ptr
+= bytes_read
;
20069 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
20071 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20074 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
20075 lh
->version
= read_2_bytes (abfd
, line_ptr
);
20077 if (lh
->version
> 5)
20079 /* This is a version we don't understand. The format could have
20080 changed in ways we don't handle properly so just punt. */
20081 complaint (&symfile_complaints
,
20082 _("unsupported version in .debug_line section"));
20085 if (lh
->version
>= 5)
20087 gdb_byte segment_selector_size
;
20089 /* Skip address size. */
20090 read_1_byte (abfd
, line_ptr
);
20093 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
20095 if (segment_selector_size
!= 0)
20097 complaint (&symfile_complaints
,
20098 _("unsupported segment selector size %u "
20099 "in .debug_line section"),
20100 segment_selector_size
);
20104 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
20105 line_ptr
+= offset_size
;
20106 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
20108 if (lh
->version
>= 4)
20110 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
20114 lh
->maximum_ops_per_instruction
= 1;
20116 if (lh
->maximum_ops_per_instruction
== 0)
20118 lh
->maximum_ops_per_instruction
= 1;
20119 complaint (&symfile_complaints
,
20120 _("invalid maximum_ops_per_instruction "
20121 "in `.debug_line' section"));
20124 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
20126 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
20128 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
20130 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
20132 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
20134 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
20135 for (i
= 1; i
< lh
->opcode_base
; ++i
)
20137 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
20141 if (lh
->version
>= 5)
20143 /* Read directory table. */
20144 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20146 [] (struct line_header
*lh
, const char *name
,
20147 dir_index d_index
, unsigned int mod_time
,
20148 unsigned int length
)
20150 lh
->add_include_dir (name
);
20153 /* Read file name table. */
20154 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20156 [] (struct line_header
*lh
, const char *name
,
20157 dir_index d_index
, unsigned int mod_time
,
20158 unsigned int length
)
20160 lh
->add_file_name (name
, d_index
, mod_time
, length
);
20165 /* Read directory table. */
20166 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20168 line_ptr
+= bytes_read
;
20169 lh
->add_include_dir (cur_dir
);
20171 line_ptr
+= bytes_read
;
20173 /* Read file name table. */
20174 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20176 unsigned int mod_time
, length
;
20179 line_ptr
+= bytes_read
;
20180 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20181 line_ptr
+= bytes_read
;
20182 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20183 line_ptr
+= bytes_read
;
20184 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20185 line_ptr
+= bytes_read
;
20187 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
20189 line_ptr
+= bytes_read
;
20191 lh
->statement_program_start
= line_ptr
;
20193 if (line_ptr
> (section
->buffer
+ section
->size
))
20194 complaint (&symfile_complaints
,
20195 _("line number info header doesn't "
20196 "fit in `.debug_line' section"));
20201 /* Subroutine of dwarf_decode_lines to simplify it.
20202 Return the file name of the psymtab for included file FILE_INDEX
20203 in line header LH of PST.
20204 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20205 If space for the result is malloc'd, *NAME_HOLDER will be set.
20206 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20208 static const char *
20209 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
20210 const struct partial_symtab
*pst
,
20211 const char *comp_dir
,
20212 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20214 const file_entry
&fe
= lh
->file_names
[file_index
];
20215 const char *include_name
= fe
.name
;
20216 const char *include_name_to_compare
= include_name
;
20217 const char *pst_filename
;
20220 const char *dir_name
= fe
.include_dir (lh
);
20222 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20223 if (!IS_ABSOLUTE_PATH (include_name
)
20224 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20226 /* Avoid creating a duplicate psymtab for PST.
20227 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20228 Before we do the comparison, however, we need to account
20229 for DIR_NAME and COMP_DIR.
20230 First prepend dir_name (if non-NULL). If we still don't
20231 have an absolute path prepend comp_dir (if non-NULL).
20232 However, the directory we record in the include-file's
20233 psymtab does not contain COMP_DIR (to match the
20234 corresponding symtab(s)).
20239 bash$ gcc -g ./hello.c
20240 include_name = "hello.c"
20242 DW_AT_comp_dir = comp_dir = "/tmp"
20243 DW_AT_name = "./hello.c"
20247 if (dir_name
!= NULL
)
20249 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20250 include_name
, (char *) NULL
));
20251 include_name
= name_holder
->get ();
20252 include_name_to_compare
= include_name
;
20254 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20256 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20257 include_name
, (char *) NULL
));
20258 include_name_to_compare
= hold_compare
.get ();
20262 pst_filename
= pst
->filename
;
20263 gdb::unique_xmalloc_ptr
<char> copied_name
;
20264 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20266 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20267 pst_filename
, (char *) NULL
));
20268 pst_filename
= copied_name
.get ();
20271 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20275 return include_name
;
20278 /* State machine to track the state of the line number program. */
20280 class lnp_state_machine
20283 /* Initialize a machine state for the start of a line number
20285 lnp_state_machine (gdbarch
*arch
, line_header
*lh
, bool record_lines_p
);
20287 file_entry
*current_file ()
20289 /* lh->file_names is 0-based, but the file name numbers in the
20290 statement program are 1-based. */
20291 return m_line_header
->file_name_at (m_file
);
20294 /* Record the line in the state machine. END_SEQUENCE is true if
20295 we're processing the end of a sequence. */
20296 void record_line (bool end_sequence
);
20298 /* Check address and if invalid nop-out the rest of the lines in this
20300 void check_line_address (struct dwarf2_cu
*cu
,
20301 const gdb_byte
*line_ptr
,
20302 CORE_ADDR lowpc
, CORE_ADDR address
);
20304 void handle_set_discriminator (unsigned int discriminator
)
20306 m_discriminator
= discriminator
;
20307 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20310 /* Handle DW_LNE_set_address. */
20311 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20314 address
+= baseaddr
;
20315 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20318 /* Handle DW_LNS_advance_pc. */
20319 void handle_advance_pc (CORE_ADDR adjust
);
20321 /* Handle a special opcode. */
20322 void handle_special_opcode (unsigned char op_code
);
20324 /* Handle DW_LNS_advance_line. */
20325 void handle_advance_line (int line_delta
)
20327 advance_line (line_delta
);
20330 /* Handle DW_LNS_set_file. */
20331 void handle_set_file (file_name_index file
);
20333 /* Handle DW_LNS_negate_stmt. */
20334 void handle_negate_stmt ()
20336 m_is_stmt
= !m_is_stmt
;
20339 /* Handle DW_LNS_const_add_pc. */
20340 void handle_const_add_pc ();
20342 /* Handle DW_LNS_fixed_advance_pc. */
20343 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20345 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20349 /* Handle DW_LNS_copy. */
20350 void handle_copy ()
20352 record_line (false);
20353 m_discriminator
= 0;
20356 /* Handle DW_LNE_end_sequence. */
20357 void handle_end_sequence ()
20359 m_record_line_callback
= ::record_line
;
20363 /* Advance the line by LINE_DELTA. */
20364 void advance_line (int line_delta
)
20366 m_line
+= line_delta
;
20368 if (line_delta
!= 0)
20369 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20372 gdbarch
*m_gdbarch
;
20374 /* True if we're recording lines.
20375 Otherwise we're building partial symtabs and are just interested in
20376 finding include files mentioned by the line number program. */
20377 bool m_record_lines_p
;
20379 /* The line number header. */
20380 line_header
*m_line_header
;
20382 /* These are part of the standard DWARF line number state machine,
20383 and initialized according to the DWARF spec. */
20385 unsigned char m_op_index
= 0;
20386 /* The line table index (1-based) of the current file. */
20387 file_name_index m_file
= (file_name_index
) 1;
20388 unsigned int m_line
= 1;
20390 /* These are initialized in the constructor. */
20392 CORE_ADDR m_address
;
20394 unsigned int m_discriminator
;
20396 /* Additional bits of state we need to track. */
20398 /* The last file that we called dwarf2_start_subfile for.
20399 This is only used for TLLs. */
20400 unsigned int m_last_file
= 0;
20401 /* The last file a line number was recorded for. */
20402 struct subfile
*m_last_subfile
= NULL
;
20404 /* The function to call to record a line. */
20405 record_line_ftype
*m_record_line_callback
= NULL
;
20407 /* The last line number that was recorded, used to coalesce
20408 consecutive entries for the same line. This can happen, for
20409 example, when discriminators are present. PR 17276. */
20410 unsigned int m_last_line
= 0;
20411 bool m_line_has_non_zero_discriminator
= false;
20415 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20417 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20418 / m_line_header
->maximum_ops_per_instruction
)
20419 * m_line_header
->minimum_instruction_length
);
20420 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20421 m_op_index
= ((m_op_index
+ adjust
)
20422 % m_line_header
->maximum_ops_per_instruction
);
20426 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20428 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20429 CORE_ADDR addr_adj
= (((m_op_index
20430 + (adj_opcode
/ m_line_header
->line_range
))
20431 / m_line_header
->maximum_ops_per_instruction
)
20432 * m_line_header
->minimum_instruction_length
);
20433 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20434 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
20435 % m_line_header
->maximum_ops_per_instruction
);
20437 int line_delta
= (m_line_header
->line_base
20438 + (adj_opcode
% m_line_header
->line_range
));
20439 advance_line (line_delta
);
20440 record_line (false);
20441 m_discriminator
= 0;
20445 lnp_state_machine::handle_set_file (file_name_index file
)
20449 const file_entry
*fe
= current_file ();
20451 dwarf2_debug_line_missing_file_complaint ();
20452 else if (m_record_lines_p
)
20454 const char *dir
= fe
->include_dir (m_line_header
);
20456 m_last_subfile
= current_subfile
;
20457 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20458 dwarf2_start_subfile (fe
->name
, dir
);
20463 lnp_state_machine::handle_const_add_pc ()
20466 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20469 = (((m_op_index
+ adjust
)
20470 / m_line_header
->maximum_ops_per_instruction
)
20471 * m_line_header
->minimum_instruction_length
);
20473 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20474 m_op_index
= ((m_op_index
+ adjust
)
20475 % m_line_header
->maximum_ops_per_instruction
);
20478 /* Ignore this record_line request. */
20481 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
20486 /* Return non-zero if we should add LINE to the line number table.
20487 LINE is the line to add, LAST_LINE is the last line that was added,
20488 LAST_SUBFILE is the subfile for LAST_LINE.
20489 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20490 had a non-zero discriminator.
20492 We have to be careful in the presence of discriminators.
20493 E.g., for this line:
20495 for (i = 0; i < 100000; i++);
20497 clang can emit four line number entries for that one line,
20498 each with a different discriminator.
20499 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20501 However, we want gdb to coalesce all four entries into one.
20502 Otherwise the user could stepi into the middle of the line and
20503 gdb would get confused about whether the pc really was in the
20504 middle of the line.
20506 Things are further complicated by the fact that two consecutive
20507 line number entries for the same line is a heuristic used by gcc
20508 to denote the end of the prologue. So we can't just discard duplicate
20509 entries, we have to be selective about it. The heuristic we use is
20510 that we only collapse consecutive entries for the same line if at least
20511 one of those entries has a non-zero discriminator. PR 17276.
20513 Note: Addresses in the line number state machine can never go backwards
20514 within one sequence, thus this coalescing is ok. */
20517 dwarf_record_line_p (unsigned int line
, unsigned int last_line
,
20518 int line_has_non_zero_discriminator
,
20519 struct subfile
*last_subfile
)
20521 if (current_subfile
!= last_subfile
)
20523 if (line
!= last_line
)
20525 /* Same line for the same file that we've seen already.
20526 As a last check, for pr 17276, only record the line if the line
20527 has never had a non-zero discriminator. */
20528 if (!line_has_non_zero_discriminator
)
20533 /* Use P_RECORD_LINE to record line number LINE beginning at address ADDRESS
20534 in the line table of subfile SUBFILE. */
20537 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20538 unsigned int line
, CORE_ADDR address
,
20539 record_line_ftype p_record_line
)
20541 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20543 if (dwarf_line_debug
)
20545 fprintf_unfiltered (gdb_stdlog
,
20546 "Recording line %u, file %s, address %s\n",
20547 line
, lbasename (subfile
->name
),
20548 paddress (gdbarch
, address
));
20551 (*p_record_line
) (subfile
, line
, addr
);
20554 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20555 Mark the end of a set of line number records.
20556 The arguments are the same as for dwarf_record_line_1.
20557 If SUBFILE is NULL the request is ignored. */
20560 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20561 CORE_ADDR address
, record_line_ftype p_record_line
)
20563 if (subfile
== NULL
)
20566 if (dwarf_line_debug
)
20568 fprintf_unfiltered (gdb_stdlog
,
20569 "Finishing current line, file %s, address %s\n",
20570 lbasename (subfile
->name
),
20571 paddress (gdbarch
, address
));
20574 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, p_record_line
);
20578 lnp_state_machine::record_line (bool end_sequence
)
20580 if (dwarf_line_debug
)
20582 fprintf_unfiltered (gdb_stdlog
,
20583 "Processing actual line %u: file %u,"
20584 " address %s, is_stmt %u, discrim %u\n",
20585 m_line
, to_underlying (m_file
),
20586 paddress (m_gdbarch
, m_address
),
20587 m_is_stmt
, m_discriminator
);
20590 file_entry
*fe
= current_file ();
20593 dwarf2_debug_line_missing_file_complaint ();
20594 /* For now we ignore lines not starting on an instruction boundary.
20595 But not when processing end_sequence for compatibility with the
20596 previous version of the code. */
20597 else if (m_op_index
== 0 || end_sequence
)
20599 fe
->included_p
= 1;
20600 if (m_record_lines_p
&& m_is_stmt
)
20602 if (m_last_subfile
!= current_subfile
|| end_sequence
)
20604 dwarf_finish_line (m_gdbarch
, m_last_subfile
,
20605 m_address
, m_record_line_callback
);
20610 if (dwarf_record_line_p (m_line
, m_last_line
,
20611 m_line_has_non_zero_discriminator
,
20614 dwarf_record_line_1 (m_gdbarch
, current_subfile
,
20616 m_record_line_callback
);
20618 m_last_subfile
= current_subfile
;
20619 m_last_line
= m_line
;
20625 lnp_state_machine::lnp_state_machine (gdbarch
*arch
, line_header
*lh
,
20626 bool record_lines_p
)
20629 m_record_lines_p
= record_lines_p
;
20630 m_line_header
= lh
;
20632 m_record_line_callback
= ::record_line
;
20634 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20635 was a line entry for it so that the backend has a chance to adjust it
20636 and also record it in case it needs it. This is currently used by MIPS
20637 code, cf. `mips_adjust_dwarf2_line'. */
20638 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20639 m_is_stmt
= lh
->default_is_stmt
;
20640 m_discriminator
= 0;
20644 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20645 const gdb_byte
*line_ptr
,
20646 CORE_ADDR lowpc
, CORE_ADDR address
)
20648 /* If address < lowpc then it's not a usable value, it's outside the
20649 pc range of the CU. However, we restrict the test to only address
20650 values of zero to preserve GDB's previous behaviour which is to
20651 handle the specific case of a function being GC'd by the linker. */
20653 if (address
== 0 && address
< lowpc
)
20655 /* This line table is for a function which has been
20656 GCd by the linker. Ignore it. PR gdb/12528 */
20658 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20659 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20661 complaint (&symfile_complaints
,
20662 _(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20663 line_offset
, objfile_name (objfile
));
20664 m_record_line_callback
= noop_record_line
;
20665 /* Note: record_line_callback is left as noop_record_line until
20666 we see DW_LNE_end_sequence. */
20670 /* Subroutine of dwarf_decode_lines to simplify it.
20671 Process the line number information in LH.
20672 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20673 program in order to set included_p for every referenced header. */
20676 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20677 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20679 const gdb_byte
*line_ptr
, *extended_end
;
20680 const gdb_byte
*line_end
;
20681 unsigned int bytes_read
, extended_len
;
20682 unsigned char op_code
, extended_op
;
20683 CORE_ADDR baseaddr
;
20684 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20685 bfd
*abfd
= objfile
->obfd
;
20686 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20687 /* True if we're recording line info (as opposed to building partial
20688 symtabs and just interested in finding include files mentioned by
20689 the line number program). */
20690 bool record_lines_p
= !decode_for_pst_p
;
20692 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
20694 line_ptr
= lh
->statement_program_start
;
20695 line_end
= lh
->statement_program_end
;
20697 /* Read the statement sequences until there's nothing left. */
20698 while (line_ptr
< line_end
)
20700 /* The DWARF line number program state machine. Reset the state
20701 machine at the start of each sequence. */
20702 lnp_state_machine
state_machine (gdbarch
, lh
, record_lines_p
);
20703 bool end_sequence
= false;
20705 if (record_lines_p
)
20707 /* Start a subfile for the current file of the state
20709 const file_entry
*fe
= state_machine
.current_file ();
20712 dwarf2_start_subfile (fe
->name
, fe
->include_dir (lh
));
20715 /* Decode the table. */
20716 while (line_ptr
< line_end
&& !end_sequence
)
20718 op_code
= read_1_byte (abfd
, line_ptr
);
20721 if (op_code
>= lh
->opcode_base
)
20723 /* Special opcode. */
20724 state_machine
.handle_special_opcode (op_code
);
20726 else switch (op_code
)
20728 case DW_LNS_extended_op
:
20729 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20731 line_ptr
+= bytes_read
;
20732 extended_end
= line_ptr
+ extended_len
;
20733 extended_op
= read_1_byte (abfd
, line_ptr
);
20735 switch (extended_op
)
20737 case DW_LNE_end_sequence
:
20738 state_machine
.handle_end_sequence ();
20739 end_sequence
= true;
20741 case DW_LNE_set_address
:
20744 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
20745 line_ptr
+= bytes_read
;
20747 state_machine
.check_line_address (cu
, line_ptr
,
20749 state_machine
.handle_set_address (baseaddr
, address
);
20752 case DW_LNE_define_file
:
20754 const char *cur_file
;
20755 unsigned int mod_time
, length
;
20758 cur_file
= read_direct_string (abfd
, line_ptr
,
20760 line_ptr
+= bytes_read
;
20761 dindex
= (dir_index
)
20762 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20763 line_ptr
+= bytes_read
;
20765 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20766 line_ptr
+= bytes_read
;
20768 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20769 line_ptr
+= bytes_read
;
20770 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20773 case DW_LNE_set_discriminator
:
20775 /* The discriminator is not interesting to the
20776 debugger; just ignore it. We still need to
20777 check its value though:
20778 if there are consecutive entries for the same
20779 (non-prologue) line we want to coalesce them.
20782 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20783 line_ptr
+= bytes_read
;
20785 state_machine
.handle_set_discriminator (discr
);
20789 complaint (&symfile_complaints
,
20790 _("mangled .debug_line section"));
20793 /* Make sure that we parsed the extended op correctly. If e.g.
20794 we expected a different address size than the producer used,
20795 we may have read the wrong number of bytes. */
20796 if (line_ptr
!= extended_end
)
20798 complaint (&symfile_complaints
,
20799 _("mangled .debug_line section"));
20804 state_machine
.handle_copy ();
20806 case DW_LNS_advance_pc
:
20809 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20810 line_ptr
+= bytes_read
;
20812 state_machine
.handle_advance_pc (adjust
);
20815 case DW_LNS_advance_line
:
20818 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20819 line_ptr
+= bytes_read
;
20821 state_machine
.handle_advance_line (line_delta
);
20824 case DW_LNS_set_file
:
20826 file_name_index file
20827 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20829 line_ptr
+= bytes_read
;
20831 state_machine
.handle_set_file (file
);
20834 case DW_LNS_set_column
:
20835 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20836 line_ptr
+= bytes_read
;
20838 case DW_LNS_negate_stmt
:
20839 state_machine
.handle_negate_stmt ();
20841 case DW_LNS_set_basic_block
:
20843 /* Add to the address register of the state machine the
20844 address increment value corresponding to special opcode
20845 255. I.e., this value is scaled by the minimum
20846 instruction length since special opcode 255 would have
20847 scaled the increment. */
20848 case DW_LNS_const_add_pc
:
20849 state_machine
.handle_const_add_pc ();
20851 case DW_LNS_fixed_advance_pc
:
20853 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20856 state_machine
.handle_fixed_advance_pc (addr_adj
);
20861 /* Unknown standard opcode, ignore it. */
20864 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
20866 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20867 line_ptr
+= bytes_read
;
20874 dwarf2_debug_line_missing_end_sequence_complaint ();
20876 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
20877 in which case we still finish recording the last line). */
20878 state_machine
.record_line (true);
20882 /* Decode the Line Number Program (LNP) for the given line_header
20883 structure and CU. The actual information extracted and the type
20884 of structures created from the LNP depends on the value of PST.
20886 1. If PST is NULL, then this procedure uses the data from the program
20887 to create all necessary symbol tables, and their linetables.
20889 2. If PST is not NULL, this procedure reads the program to determine
20890 the list of files included by the unit represented by PST, and
20891 builds all the associated partial symbol tables.
20893 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20894 It is used for relative paths in the line table.
20895 NOTE: When processing partial symtabs (pst != NULL),
20896 comp_dir == pst->dirname.
20898 NOTE: It is important that psymtabs have the same file name (via strcmp)
20899 as the corresponding symtab. Since COMP_DIR is not used in the name of the
20900 symtab we don't use it in the name of the psymtabs we create.
20901 E.g. expand_line_sal requires this when finding psymtabs to expand.
20902 A good testcase for this is mb-inline.exp.
20904 LOWPC is the lowest address in CU (or 0 if not known).
20906 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
20907 for its PC<->lines mapping information. Otherwise only the filename
20908 table is read in. */
20911 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
20912 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
20913 CORE_ADDR lowpc
, int decode_mapping
)
20915 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20916 const int decode_for_pst_p
= (pst
!= NULL
);
20918 if (decode_mapping
)
20919 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
20921 if (decode_for_pst_p
)
20925 /* Now that we're done scanning the Line Header Program, we can
20926 create the psymtab of each included file. */
20927 for (file_index
= 0; file_index
< lh
->file_names
.size (); file_index
++)
20928 if (lh
->file_names
[file_index
].included_p
== 1)
20930 gdb::unique_xmalloc_ptr
<char> name_holder
;
20931 const char *include_name
=
20932 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
,
20934 if (include_name
!= NULL
)
20935 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
20940 /* Make sure a symtab is created for every file, even files
20941 which contain only variables (i.e. no code with associated
20943 struct compunit_symtab
*cust
= buildsym_compunit_symtab ();
20946 for (i
= 0; i
< lh
->file_names
.size (); i
++)
20948 file_entry
&fe
= lh
->file_names
[i
];
20950 dwarf2_start_subfile (fe
.name
, fe
.include_dir (lh
));
20952 if (current_subfile
->symtab
== NULL
)
20954 current_subfile
->symtab
20955 = allocate_symtab (cust
, current_subfile
->name
);
20957 fe
.symtab
= current_subfile
->symtab
;
20962 /* Start a subfile for DWARF. FILENAME is the name of the file and
20963 DIRNAME the name of the source directory which contains FILENAME
20964 or NULL if not known.
20965 This routine tries to keep line numbers from identical absolute and
20966 relative file names in a common subfile.
20968 Using the `list' example from the GDB testsuite, which resides in
20969 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
20970 of /srcdir/list0.c yields the following debugging information for list0.c:
20972 DW_AT_name: /srcdir/list0.c
20973 DW_AT_comp_dir: /compdir
20974 files.files[0].name: list0.h
20975 files.files[0].dir: /srcdir
20976 files.files[1].name: list0.c
20977 files.files[1].dir: /srcdir
20979 The line number information for list0.c has to end up in a single
20980 subfile, so that `break /srcdir/list0.c:1' works as expected.
20981 start_subfile will ensure that this happens provided that we pass the
20982 concatenation of files.files[1].dir and files.files[1].name as the
20986 dwarf2_start_subfile (const char *filename
, const char *dirname
)
20990 /* In order not to lose the line information directory,
20991 we concatenate it to the filename when it makes sense.
20992 Note that the Dwarf3 standard says (speaking of filenames in line
20993 information): ``The directory index is ignored for file names
20994 that represent full path names''. Thus ignoring dirname in the
20995 `else' branch below isn't an issue. */
20997 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
20999 copy
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
21003 start_subfile (filename
);
21009 /* Start a symtab for DWARF.
21010 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
21012 static struct compunit_symtab
*
21013 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
21014 const char *name
, const char *comp_dir
, CORE_ADDR low_pc
)
21016 struct compunit_symtab
*cust
21017 = start_symtab (cu
->per_cu
->dwarf2_per_objfile
->objfile
, name
, comp_dir
,
21018 low_pc
, cu
->language
);
21020 record_debugformat ("DWARF 2");
21021 record_producer (cu
->producer
);
21023 /* We assume that we're processing GCC output. */
21024 processing_gcc_compilation
= 2;
21026 cu
->processing_has_namespace_info
= 0;
21032 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21033 struct dwarf2_cu
*cu
)
21035 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21036 struct comp_unit_head
*cu_header
= &cu
->header
;
21038 /* NOTE drow/2003-01-30: There used to be a comment and some special
21039 code here to turn a symbol with DW_AT_external and a
21040 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21041 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21042 with some versions of binutils) where shared libraries could have
21043 relocations against symbols in their debug information - the
21044 minimal symbol would have the right address, but the debug info
21045 would not. It's no longer necessary, because we will explicitly
21046 apply relocations when we read in the debug information now. */
21048 /* A DW_AT_location attribute with no contents indicates that a
21049 variable has been optimized away. */
21050 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
21052 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21056 /* Handle one degenerate form of location expression specially, to
21057 preserve GDB's previous behavior when section offsets are
21058 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
21059 then mark this symbol as LOC_STATIC. */
21061 if (attr_form_is_block (attr
)
21062 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
21063 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
21064 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
21065 && (DW_BLOCK (attr
)->size
21066 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
21068 unsigned int dummy
;
21070 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
21071 SYMBOL_VALUE_ADDRESS (sym
) =
21072 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
21074 SYMBOL_VALUE_ADDRESS (sym
) =
21075 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
21076 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21077 fixup_symbol_section (sym
, objfile
);
21078 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
21079 SYMBOL_SECTION (sym
));
21083 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21084 expression evaluator, and use LOC_COMPUTED only when necessary
21085 (i.e. when the value of a register or memory location is
21086 referenced, or a thread-local block, etc.). Then again, it might
21087 not be worthwhile. I'm assuming that it isn't unless performance
21088 or memory numbers show me otherwise. */
21090 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21092 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21093 cu
->has_loclist
= 1;
21096 /* Given a pointer to a DWARF information entry, figure out if we need
21097 to make a symbol table entry for it, and if so, create a new entry
21098 and return a pointer to it.
21099 If TYPE is NULL, determine symbol type from the die, otherwise
21100 used the passed type.
21101 If SPACE is not NULL, use it to hold the new symbol. If it is
21102 NULL, allocate a new symbol on the objfile's obstack. */
21104 static struct symbol
*
21105 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21106 struct symbol
*space
)
21108 struct dwarf2_per_objfile
*dwarf2_per_objfile
21109 = cu
->per_cu
->dwarf2_per_objfile
;
21110 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21111 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21112 struct symbol
*sym
= NULL
;
21114 struct attribute
*attr
= NULL
;
21115 struct attribute
*attr2
= NULL
;
21116 CORE_ADDR baseaddr
;
21117 struct pending
**list_to_add
= NULL
;
21119 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21121 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
21123 name
= dwarf2_name (die
, cu
);
21126 const char *linkagename
;
21127 int suppress_add
= 0;
21132 sym
= allocate_symbol (objfile
);
21133 OBJSTAT (objfile
, n_syms
++);
21135 /* Cache this symbol's name and the name's demangled form (if any). */
21136 SYMBOL_SET_LANGUAGE (sym
, cu
->language
, &objfile
->objfile_obstack
);
21137 linkagename
= dwarf2_physname (name
, die
, cu
);
21138 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
21140 /* Fortran does not have mangling standard and the mangling does differ
21141 between gfortran, iFort etc. */
21142 if (cu
->language
== language_fortran
21143 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
21144 symbol_set_demangled_name (&(sym
->ginfo
),
21145 dwarf2_full_name (name
, die
, cu
),
21148 /* Default assumptions.
21149 Use the passed type or decode it from the die. */
21150 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21151 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21153 SYMBOL_TYPE (sym
) = type
;
21155 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21156 attr
= dwarf2_attr (die
,
21157 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21161 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
21164 attr
= dwarf2_attr (die
,
21165 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21169 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
21170 struct file_entry
*fe
;
21172 if (cu
->line_header
!= NULL
)
21173 fe
= cu
->line_header
->file_name_at (file_index
);
21178 complaint (&symfile_complaints
,
21179 _("file index out of range"));
21181 symbol_set_symtab (sym
, fe
->symtab
);
21187 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21192 addr
= attr_value_as_address (attr
);
21193 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21194 SYMBOL_VALUE_ADDRESS (sym
) = addr
;
21196 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21197 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21198 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21199 add_symbol_to_list (sym
, cu
->list_in_scope
);
21201 case DW_TAG_subprogram
:
21202 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21204 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21205 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21206 if ((attr2
&& (DW_UNSND (attr2
) != 0))
21207 || cu
->language
== language_ada
)
21209 /* Subprograms marked external are stored as a global symbol.
21210 Ada subprograms, whether marked external or not, are always
21211 stored as a global symbol, because we want to be able to
21212 access them globally. For instance, we want to be able
21213 to break on a nested subprogram without having to
21214 specify the context. */
21215 list_to_add
= &global_symbols
;
21219 list_to_add
= cu
->list_in_scope
;
21222 case DW_TAG_inlined_subroutine
:
21223 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21225 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21226 SYMBOL_INLINED (sym
) = 1;
21227 list_to_add
= cu
->list_in_scope
;
21229 case DW_TAG_template_value_param
:
21231 /* Fall through. */
21232 case DW_TAG_constant
:
21233 case DW_TAG_variable
:
21234 case DW_TAG_member
:
21235 /* Compilation with minimal debug info may result in
21236 variables with missing type entries. Change the
21237 misleading `void' type to something sensible. */
21238 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
21239 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21241 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21242 /* In the case of DW_TAG_member, we should only be called for
21243 static const members. */
21244 if (die
->tag
== DW_TAG_member
)
21246 /* dwarf2_add_field uses die_is_declaration,
21247 so we do the same. */
21248 gdb_assert (die_is_declaration (die
, cu
));
21253 dwarf2_const_value (attr
, sym
, cu
);
21254 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21257 if (attr2
&& (DW_UNSND (attr2
) != 0))
21258 list_to_add
= &global_symbols
;
21260 list_to_add
= cu
->list_in_scope
;
21264 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21267 var_decode_location (attr
, sym
, cu
);
21268 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21270 /* Fortran explicitly imports any global symbols to the local
21271 scope by DW_TAG_common_block. */
21272 if (cu
->language
== language_fortran
&& die
->parent
21273 && die
->parent
->tag
== DW_TAG_common_block
)
21276 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21277 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21278 && !dwarf2_per_objfile
->has_section_at_zero
)
21280 /* When a static variable is eliminated by the linker,
21281 the corresponding debug information is not stripped
21282 out, but the variable address is set to null;
21283 do not add such variables into symbol table. */
21285 else if (attr2
&& (DW_UNSND (attr2
) != 0))
21287 /* Workaround gfortran PR debug/40040 - it uses
21288 DW_AT_location for variables in -fPIC libraries which may
21289 get overriden by other libraries/executable and get
21290 a different address. Resolve it by the minimal symbol
21291 which may come from inferior's executable using copy
21292 relocation. Make this workaround only for gfortran as for
21293 other compilers GDB cannot guess the minimal symbol
21294 Fortran mangling kind. */
21295 if (cu
->language
== language_fortran
&& die
->parent
21296 && die
->parent
->tag
== DW_TAG_module
21298 && startswith (cu
->producer
, "GNU Fortran"))
21299 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21301 /* A variable with DW_AT_external is never static,
21302 but it may be block-scoped. */
21303 list_to_add
= (cu
->list_in_scope
== &file_symbols
21304 ? &global_symbols
: cu
->list_in_scope
);
21307 list_to_add
= cu
->list_in_scope
;
21311 /* We do not know the address of this symbol.
21312 If it is an external symbol and we have type information
21313 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21314 The address of the variable will then be determined from
21315 the minimal symbol table whenever the variable is
21317 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21319 /* Fortran explicitly imports any global symbols to the local
21320 scope by DW_TAG_common_block. */
21321 if (cu
->language
== language_fortran
&& die
->parent
21322 && die
->parent
->tag
== DW_TAG_common_block
)
21324 /* SYMBOL_CLASS doesn't matter here because
21325 read_common_block is going to reset it. */
21327 list_to_add
= cu
->list_in_scope
;
21329 else if (attr2
&& (DW_UNSND (attr2
) != 0)
21330 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21332 /* A variable with DW_AT_external is never static, but it
21333 may be block-scoped. */
21334 list_to_add
= (cu
->list_in_scope
== &file_symbols
21335 ? &global_symbols
: cu
->list_in_scope
);
21337 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21339 else if (!die_is_declaration (die
, cu
))
21341 /* Use the default LOC_OPTIMIZED_OUT class. */
21342 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21344 list_to_add
= cu
->list_in_scope
;
21348 case DW_TAG_formal_parameter
:
21349 /* If we are inside a function, mark this as an argument. If
21350 not, we might be looking at an argument to an inlined function
21351 when we do not have enough information to show inlined frames;
21352 pretend it's a local variable in that case so that the user can
21354 if (context_stack_depth
> 0
21355 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
21356 SYMBOL_IS_ARGUMENT (sym
) = 1;
21357 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21360 var_decode_location (attr
, sym
, cu
);
21362 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21365 dwarf2_const_value (attr
, sym
, cu
);
21368 list_to_add
= cu
->list_in_scope
;
21370 case DW_TAG_unspecified_parameters
:
21371 /* From varargs functions; gdb doesn't seem to have any
21372 interest in this information, so just ignore it for now.
21375 case DW_TAG_template_type_param
:
21377 /* Fall through. */
21378 case DW_TAG_class_type
:
21379 case DW_TAG_interface_type
:
21380 case DW_TAG_structure_type
:
21381 case DW_TAG_union_type
:
21382 case DW_TAG_set_type
:
21383 case DW_TAG_enumeration_type
:
21384 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21385 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21388 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21389 really ever be static objects: otherwise, if you try
21390 to, say, break of a class's method and you're in a file
21391 which doesn't mention that class, it won't work unless
21392 the check for all static symbols in lookup_symbol_aux
21393 saves you. See the OtherFileClass tests in
21394 gdb.c++/namespace.exp. */
21398 list_to_add
= (cu
->list_in_scope
== &file_symbols
21399 && cu
->language
== language_cplus
21400 ? &global_symbols
: cu
->list_in_scope
);
21402 /* The semantics of C++ state that "struct foo {
21403 ... }" also defines a typedef for "foo". */
21404 if (cu
->language
== language_cplus
21405 || cu
->language
== language_ada
21406 || cu
->language
== language_d
21407 || cu
->language
== language_rust
)
21409 /* The symbol's name is already allocated along
21410 with this objfile, so we don't need to
21411 duplicate it for the type. */
21412 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
21413 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
21418 case DW_TAG_typedef
:
21419 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21420 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21421 list_to_add
= cu
->list_in_scope
;
21423 case DW_TAG_base_type
:
21424 case DW_TAG_subrange_type
:
21425 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21426 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21427 list_to_add
= cu
->list_in_scope
;
21429 case DW_TAG_enumerator
:
21430 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21433 dwarf2_const_value (attr
, sym
, cu
);
21436 /* NOTE: carlton/2003-11-10: See comment above in the
21437 DW_TAG_class_type, etc. block. */
21439 list_to_add
= (cu
->list_in_scope
== &file_symbols
21440 && cu
->language
== language_cplus
21441 ? &global_symbols
: cu
->list_in_scope
);
21444 case DW_TAG_imported_declaration
:
21445 case DW_TAG_namespace
:
21446 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21447 list_to_add
= &global_symbols
;
21449 case DW_TAG_module
:
21450 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21451 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21452 list_to_add
= &global_symbols
;
21454 case DW_TAG_common_block
:
21455 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21456 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21457 add_symbol_to_list (sym
, cu
->list_in_scope
);
21460 /* Not a tag we recognize. Hopefully we aren't processing
21461 trash data, but since we must specifically ignore things
21462 we don't recognize, there is nothing else we should do at
21464 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
21465 dwarf_tag_name (die
->tag
));
21471 sym
->hash_next
= objfile
->template_symbols
;
21472 objfile
->template_symbols
= sym
;
21473 list_to_add
= NULL
;
21476 if (list_to_add
!= NULL
)
21477 add_symbol_to_list (sym
, list_to_add
);
21479 /* For the benefit of old versions of GCC, check for anonymous
21480 namespaces based on the demangled name. */
21481 if (!cu
->processing_has_namespace_info
21482 && cu
->language
== language_cplus
)
21483 cp_scan_for_anonymous_namespaces (sym
, objfile
);
21488 /* Given an attr with a DW_FORM_dataN value in host byte order,
21489 zero-extend it as appropriate for the symbol's type. The DWARF
21490 standard (v4) is not entirely clear about the meaning of using
21491 DW_FORM_dataN for a constant with a signed type, where the type is
21492 wider than the data. The conclusion of a discussion on the DWARF
21493 list was that this is unspecified. We choose to always zero-extend
21494 because that is the interpretation long in use by GCC. */
21497 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21498 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21500 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21501 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21502 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21503 LONGEST l
= DW_UNSND (attr
);
21505 if (bits
< sizeof (*value
) * 8)
21507 l
&= ((LONGEST
) 1 << bits
) - 1;
21510 else if (bits
== sizeof (*value
) * 8)
21514 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21515 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21522 /* Read a constant value from an attribute. Either set *VALUE, or if
21523 the value does not fit in *VALUE, set *BYTES - either already
21524 allocated on the objfile obstack, or newly allocated on OBSTACK,
21525 or, set *BATON, if we translated the constant to a location
21529 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21530 const char *name
, struct obstack
*obstack
,
21531 struct dwarf2_cu
*cu
,
21532 LONGEST
*value
, const gdb_byte
**bytes
,
21533 struct dwarf2_locexpr_baton
**baton
)
21535 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21536 struct comp_unit_head
*cu_header
= &cu
->header
;
21537 struct dwarf_block
*blk
;
21538 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21539 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21545 switch (attr
->form
)
21548 case DW_FORM_GNU_addr_index
:
21552 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21553 dwarf2_const_value_length_mismatch_complaint (name
,
21554 cu_header
->addr_size
,
21555 TYPE_LENGTH (type
));
21556 /* Symbols of this form are reasonably rare, so we just
21557 piggyback on the existing location code rather than writing
21558 a new implementation of symbol_computed_ops. */
21559 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21560 (*baton
)->per_cu
= cu
->per_cu
;
21561 gdb_assert ((*baton
)->per_cu
);
21563 (*baton
)->size
= 2 + cu_header
->addr_size
;
21564 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
21565 (*baton
)->data
= data
;
21567 data
[0] = DW_OP_addr
;
21568 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
21569 byte_order
, DW_ADDR (attr
));
21570 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
21573 case DW_FORM_string
:
21575 case DW_FORM_GNU_str_index
:
21576 case DW_FORM_GNU_strp_alt
:
21577 /* DW_STRING is already allocated on the objfile obstack, point
21579 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
21581 case DW_FORM_block1
:
21582 case DW_FORM_block2
:
21583 case DW_FORM_block4
:
21584 case DW_FORM_block
:
21585 case DW_FORM_exprloc
:
21586 case DW_FORM_data16
:
21587 blk
= DW_BLOCK (attr
);
21588 if (TYPE_LENGTH (type
) != blk
->size
)
21589 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
21590 TYPE_LENGTH (type
));
21591 *bytes
= blk
->data
;
21594 /* The DW_AT_const_value attributes are supposed to carry the
21595 symbol's value "represented as it would be on the target
21596 architecture." By the time we get here, it's already been
21597 converted to host endianness, so we just need to sign- or
21598 zero-extend it as appropriate. */
21599 case DW_FORM_data1
:
21600 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21602 case DW_FORM_data2
:
21603 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21605 case DW_FORM_data4
:
21606 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21608 case DW_FORM_data8
:
21609 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21612 case DW_FORM_sdata
:
21613 case DW_FORM_implicit_const
:
21614 *value
= DW_SND (attr
);
21617 case DW_FORM_udata
:
21618 *value
= DW_UNSND (attr
);
21622 complaint (&symfile_complaints
,
21623 _("unsupported const value attribute form: '%s'"),
21624 dwarf_form_name (attr
->form
));
21631 /* Copy constant value from an attribute to a symbol. */
21634 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21635 struct dwarf2_cu
*cu
)
21637 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21639 const gdb_byte
*bytes
;
21640 struct dwarf2_locexpr_baton
*baton
;
21642 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21643 SYMBOL_PRINT_NAME (sym
),
21644 &objfile
->objfile_obstack
, cu
,
21645 &value
, &bytes
, &baton
);
21649 SYMBOL_LOCATION_BATON (sym
) = baton
;
21650 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21652 else if (bytes
!= NULL
)
21654 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21655 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21659 SYMBOL_VALUE (sym
) = value
;
21660 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21664 /* Return the type of the die in question using its DW_AT_type attribute. */
21666 static struct type
*
21667 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21669 struct attribute
*type_attr
;
21671 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21674 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21675 /* A missing DW_AT_type represents a void type. */
21676 return objfile_type (objfile
)->builtin_void
;
21679 return lookup_die_type (die
, type_attr
, cu
);
21682 /* True iff CU's producer generates GNAT Ada auxiliary information
21683 that allows to find parallel types through that information instead
21684 of having to do expensive parallel lookups by type name. */
21687 need_gnat_info (struct dwarf2_cu
*cu
)
21689 /* Assume that the Ada compiler was GNAT, which always produces
21690 the auxiliary information. */
21691 return (cu
->language
== language_ada
);
21694 /* Return the auxiliary type of the die in question using its
21695 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21696 attribute is not present. */
21698 static struct type
*
21699 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21701 struct attribute
*type_attr
;
21703 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21707 return lookup_die_type (die
, type_attr
, cu
);
21710 /* If DIE has a descriptive_type attribute, then set the TYPE's
21711 descriptive type accordingly. */
21714 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21715 struct dwarf2_cu
*cu
)
21717 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21719 if (descriptive_type
)
21721 ALLOCATE_GNAT_AUX_TYPE (type
);
21722 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21726 /* Return the containing type of the die in question using its
21727 DW_AT_containing_type attribute. */
21729 static struct type
*
21730 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21732 struct attribute
*type_attr
;
21733 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21735 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21737 error (_("Dwarf Error: Problem turning containing type into gdb type "
21738 "[in module %s]"), objfile_name (objfile
));
21740 return lookup_die_type (die
, type_attr
, cu
);
21743 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21745 static struct type
*
21746 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21748 struct dwarf2_per_objfile
*dwarf2_per_objfile
21749 = cu
->per_cu
->dwarf2_per_objfile
;
21750 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21751 char *message
, *saved
;
21753 message
= xstrprintf (_("<unknown type in %s, CU %s, DIE %s>"),
21754 objfile_name (objfile
),
21755 sect_offset_str (cu
->header
.sect_off
),
21756 sect_offset_str (die
->sect_off
));
21757 saved
= (char *) obstack_copy0 (&objfile
->objfile_obstack
,
21758 message
, strlen (message
));
21761 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21764 /* Look up the type of DIE in CU using its type attribute ATTR.
21765 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21766 DW_AT_containing_type.
21767 If there is no type substitute an error marker. */
21769 static struct type
*
21770 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21771 struct dwarf2_cu
*cu
)
21773 struct dwarf2_per_objfile
*dwarf2_per_objfile
21774 = cu
->per_cu
->dwarf2_per_objfile
;
21775 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21776 struct type
*this_type
;
21778 gdb_assert (attr
->name
== DW_AT_type
21779 || attr
->name
== DW_AT_GNAT_descriptive_type
21780 || attr
->name
== DW_AT_containing_type
);
21782 /* First see if we have it cached. */
21784 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21786 struct dwarf2_per_cu_data
*per_cu
;
21787 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21789 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
21790 dwarf2_per_objfile
);
21791 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
21793 else if (attr_form_is_ref (attr
))
21795 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21797 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
21799 else if (attr
->form
== DW_FORM_ref_sig8
)
21801 ULONGEST signature
= DW_SIGNATURE (attr
);
21803 return get_signatured_type (die
, signature
, cu
);
21807 complaint (&symfile_complaints
,
21808 _("Dwarf Error: Bad type attribute %s in DIE"
21809 " at %s [in module %s]"),
21810 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
21811 objfile_name (objfile
));
21812 return build_error_marker_type (cu
, die
);
21815 /* If not cached we need to read it in. */
21817 if (this_type
== NULL
)
21819 struct die_info
*type_die
= NULL
;
21820 struct dwarf2_cu
*type_cu
= cu
;
21822 if (attr_form_is_ref (attr
))
21823 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21824 if (type_die
== NULL
)
21825 return build_error_marker_type (cu
, die
);
21826 /* If we find the type now, it's probably because the type came
21827 from an inter-CU reference and the type's CU got expanded before
21829 this_type
= read_type_die (type_die
, type_cu
);
21832 /* If we still don't have a type use an error marker. */
21834 if (this_type
== NULL
)
21835 return build_error_marker_type (cu
, die
);
21840 /* Return the type in DIE, CU.
21841 Returns NULL for invalid types.
21843 This first does a lookup in die_type_hash,
21844 and only reads the die in if necessary.
21846 NOTE: This can be called when reading in partial or full symbols. */
21848 static struct type
*
21849 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21851 struct type
*this_type
;
21853 this_type
= get_die_type (die
, cu
);
21857 return read_type_die_1 (die
, cu
);
21860 /* Read the type in DIE, CU.
21861 Returns NULL for invalid types. */
21863 static struct type
*
21864 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
21866 struct type
*this_type
= NULL
;
21870 case DW_TAG_class_type
:
21871 case DW_TAG_interface_type
:
21872 case DW_TAG_structure_type
:
21873 case DW_TAG_union_type
:
21874 this_type
= read_structure_type (die
, cu
);
21876 case DW_TAG_enumeration_type
:
21877 this_type
= read_enumeration_type (die
, cu
);
21879 case DW_TAG_subprogram
:
21880 case DW_TAG_subroutine_type
:
21881 case DW_TAG_inlined_subroutine
:
21882 this_type
= read_subroutine_type (die
, cu
);
21884 case DW_TAG_array_type
:
21885 this_type
= read_array_type (die
, cu
);
21887 case DW_TAG_set_type
:
21888 this_type
= read_set_type (die
, cu
);
21890 case DW_TAG_pointer_type
:
21891 this_type
= read_tag_pointer_type (die
, cu
);
21893 case DW_TAG_ptr_to_member_type
:
21894 this_type
= read_tag_ptr_to_member_type (die
, cu
);
21896 case DW_TAG_reference_type
:
21897 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
21899 case DW_TAG_rvalue_reference_type
:
21900 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
21902 case DW_TAG_const_type
:
21903 this_type
= read_tag_const_type (die
, cu
);
21905 case DW_TAG_volatile_type
:
21906 this_type
= read_tag_volatile_type (die
, cu
);
21908 case DW_TAG_restrict_type
:
21909 this_type
= read_tag_restrict_type (die
, cu
);
21911 case DW_TAG_string_type
:
21912 this_type
= read_tag_string_type (die
, cu
);
21914 case DW_TAG_typedef
:
21915 this_type
= read_typedef (die
, cu
);
21917 case DW_TAG_subrange_type
:
21918 this_type
= read_subrange_type (die
, cu
);
21920 case DW_TAG_base_type
:
21921 this_type
= read_base_type (die
, cu
);
21923 case DW_TAG_unspecified_type
:
21924 this_type
= read_unspecified_type (die
, cu
);
21926 case DW_TAG_namespace
:
21927 this_type
= read_namespace_type (die
, cu
);
21929 case DW_TAG_module
:
21930 this_type
= read_module_type (die
, cu
);
21932 case DW_TAG_atomic_type
:
21933 this_type
= read_tag_atomic_type (die
, cu
);
21936 complaint (&symfile_complaints
,
21937 _("unexpected tag in read_type_die: '%s'"),
21938 dwarf_tag_name (die
->tag
));
21945 /* See if we can figure out if the class lives in a namespace. We do
21946 this by looking for a member function; its demangled name will
21947 contain namespace info, if there is any.
21948 Return the computed name or NULL.
21949 Space for the result is allocated on the objfile's obstack.
21950 This is the full-die version of guess_partial_die_structure_name.
21951 In this case we know DIE has no useful parent. */
21954 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21956 struct die_info
*spec_die
;
21957 struct dwarf2_cu
*spec_cu
;
21958 struct die_info
*child
;
21959 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21962 spec_die
= die_specification (die
, &spec_cu
);
21963 if (spec_die
!= NULL
)
21969 for (child
= die
->child
;
21971 child
= child
->sibling
)
21973 if (child
->tag
== DW_TAG_subprogram
)
21975 const char *linkage_name
= dw2_linkage_name (child
, cu
);
21977 if (linkage_name
!= NULL
)
21980 = language_class_name_from_physname (cu
->language_defn
,
21984 if (actual_name
!= NULL
)
21986 const char *die_name
= dwarf2_name (die
, cu
);
21988 if (die_name
!= NULL
21989 && strcmp (die_name
, actual_name
) != 0)
21991 /* Strip off the class name from the full name.
21992 We want the prefix. */
21993 int die_name_len
= strlen (die_name
);
21994 int actual_name_len
= strlen (actual_name
);
21996 /* Test for '::' as a sanity check. */
21997 if (actual_name_len
> die_name_len
+ 2
21998 && actual_name
[actual_name_len
21999 - die_name_len
- 1] == ':')
22000 name
= (char *) obstack_copy0 (
22001 &objfile
->per_bfd
->storage_obstack
,
22002 actual_name
, actual_name_len
- die_name_len
- 2);
22005 xfree (actual_name
);
22014 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22015 prefix part in such case. See
22016 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22018 static const char *
22019 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22021 struct attribute
*attr
;
22024 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22025 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22028 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22031 attr
= dw2_linkage_name_attr (die
, cu
);
22032 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22035 /* dwarf2_name had to be already called. */
22036 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
22038 /* Strip the base name, keep any leading namespaces/classes. */
22039 base
= strrchr (DW_STRING (attr
), ':');
22040 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
22043 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22044 return (char *) obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
22046 &base
[-1] - DW_STRING (attr
));
22049 /* Return the name of the namespace/class that DIE is defined within,
22050 or "" if we can't tell. The caller should not xfree the result.
22052 For example, if we're within the method foo() in the following
22062 then determine_prefix on foo's die will return "N::C". */
22064 static const char *
22065 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22067 struct dwarf2_per_objfile
*dwarf2_per_objfile
22068 = cu
->per_cu
->dwarf2_per_objfile
;
22069 struct die_info
*parent
, *spec_die
;
22070 struct dwarf2_cu
*spec_cu
;
22071 struct type
*parent_type
;
22072 const char *retval
;
22074 if (cu
->language
!= language_cplus
22075 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22076 && cu
->language
!= language_rust
)
22079 retval
= anonymous_struct_prefix (die
, cu
);
22083 /* We have to be careful in the presence of DW_AT_specification.
22084 For example, with GCC 3.4, given the code
22088 // Definition of N::foo.
22092 then we'll have a tree of DIEs like this:
22094 1: DW_TAG_compile_unit
22095 2: DW_TAG_namespace // N
22096 3: DW_TAG_subprogram // declaration of N::foo
22097 4: DW_TAG_subprogram // definition of N::foo
22098 DW_AT_specification // refers to die #3
22100 Thus, when processing die #4, we have to pretend that we're in
22101 the context of its DW_AT_specification, namely the contex of die
22104 spec_die
= die_specification (die
, &spec_cu
);
22105 if (spec_die
== NULL
)
22106 parent
= die
->parent
;
22109 parent
= spec_die
->parent
;
22113 if (parent
== NULL
)
22115 else if (parent
->building_fullname
)
22118 const char *parent_name
;
22120 /* It has been seen on RealView 2.2 built binaries,
22121 DW_TAG_template_type_param types actually _defined_ as
22122 children of the parent class:
22125 template class <class Enum> Class{};
22126 Class<enum E> class_e;
22128 1: DW_TAG_class_type (Class)
22129 2: DW_TAG_enumeration_type (E)
22130 3: DW_TAG_enumerator (enum1:0)
22131 3: DW_TAG_enumerator (enum2:1)
22133 2: DW_TAG_template_type_param
22134 DW_AT_type DW_FORM_ref_udata (E)
22136 Besides being broken debug info, it can put GDB into an
22137 infinite loop. Consider:
22139 When we're building the full name for Class<E>, we'll start
22140 at Class, and go look over its template type parameters,
22141 finding E. We'll then try to build the full name of E, and
22142 reach here. We're now trying to build the full name of E,
22143 and look over the parent DIE for containing scope. In the
22144 broken case, if we followed the parent DIE of E, we'd again
22145 find Class, and once again go look at its template type
22146 arguments, etc., etc. Simply don't consider such parent die
22147 as source-level parent of this die (it can't be, the language
22148 doesn't allow it), and break the loop here. */
22149 name
= dwarf2_name (die
, cu
);
22150 parent_name
= dwarf2_name (parent
, cu
);
22151 complaint (&symfile_complaints
,
22152 _("template param type '%s' defined within parent '%s'"),
22153 name
? name
: "<unknown>",
22154 parent_name
? parent_name
: "<unknown>");
22158 switch (parent
->tag
)
22160 case DW_TAG_namespace
:
22161 parent_type
= read_type_die (parent
, cu
);
22162 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22163 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22164 Work around this problem here. */
22165 if (cu
->language
== language_cplus
22166 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
22168 /* We give a name to even anonymous namespaces. */
22169 return TYPE_TAG_NAME (parent_type
);
22170 case DW_TAG_class_type
:
22171 case DW_TAG_interface_type
:
22172 case DW_TAG_structure_type
:
22173 case DW_TAG_union_type
:
22174 case DW_TAG_module
:
22175 parent_type
= read_type_die (parent
, cu
);
22176 if (TYPE_TAG_NAME (parent_type
) != NULL
)
22177 return TYPE_TAG_NAME (parent_type
);
22179 /* An anonymous structure is only allowed non-static data
22180 members; no typedefs, no member functions, et cetera.
22181 So it does not need a prefix. */
22183 case DW_TAG_compile_unit
:
22184 case DW_TAG_partial_unit
:
22185 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22186 if (cu
->language
== language_cplus
22187 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
22188 && die
->child
!= NULL
22189 && (die
->tag
== DW_TAG_class_type
22190 || die
->tag
== DW_TAG_structure_type
22191 || die
->tag
== DW_TAG_union_type
))
22193 char *name
= guess_full_die_structure_name (die
, cu
);
22198 case DW_TAG_enumeration_type
:
22199 parent_type
= read_type_die (parent
, cu
);
22200 if (TYPE_DECLARED_CLASS (parent_type
))
22202 if (TYPE_TAG_NAME (parent_type
) != NULL
)
22203 return TYPE_TAG_NAME (parent_type
);
22206 /* Fall through. */
22208 return determine_prefix (parent
, cu
);
22212 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22213 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22214 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22215 an obconcat, otherwise allocate storage for the result. The CU argument is
22216 used to determine the language and hence, the appropriate separator. */
22218 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22221 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22222 int physname
, struct dwarf2_cu
*cu
)
22224 const char *lead
= "";
22227 if (suffix
== NULL
|| suffix
[0] == '\0'
22228 || prefix
== NULL
|| prefix
[0] == '\0')
22230 else if (cu
->language
== language_d
)
22232 /* For D, the 'main' function could be defined in any module, but it
22233 should never be prefixed. */
22234 if (strcmp (suffix
, "D main") == 0)
22242 else if (cu
->language
== language_fortran
&& physname
)
22244 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22245 DW_AT_MIPS_linkage_name is preferred and used instead. */
22253 if (prefix
== NULL
)
22255 if (suffix
== NULL
)
22262 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22264 strcpy (retval
, lead
);
22265 strcat (retval
, prefix
);
22266 strcat (retval
, sep
);
22267 strcat (retval
, suffix
);
22272 /* We have an obstack. */
22273 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22277 /* Return sibling of die, NULL if no sibling. */
22279 static struct die_info
*
22280 sibling_die (struct die_info
*die
)
22282 return die
->sibling
;
22285 /* Get name of a die, return NULL if not found. */
22287 static const char *
22288 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22289 struct obstack
*obstack
)
22291 if (name
&& cu
->language
== language_cplus
)
22293 std::string canon_name
= cp_canonicalize_string (name
);
22295 if (!canon_name
.empty ())
22297 if (canon_name
!= name
)
22298 name
= (const char *) obstack_copy0 (obstack
,
22299 canon_name
.c_str (),
22300 canon_name
.length ());
22307 /* Get name of a die, return NULL if not found.
22308 Anonymous namespaces are converted to their magic string. */
22310 static const char *
22311 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22313 struct attribute
*attr
;
22314 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22316 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22317 if ((!attr
|| !DW_STRING (attr
))
22318 && die
->tag
!= DW_TAG_namespace
22319 && die
->tag
!= DW_TAG_class_type
22320 && die
->tag
!= DW_TAG_interface_type
22321 && die
->tag
!= DW_TAG_structure_type
22322 && die
->tag
!= DW_TAG_union_type
)
22327 case DW_TAG_compile_unit
:
22328 case DW_TAG_partial_unit
:
22329 /* Compilation units have a DW_AT_name that is a filename, not
22330 a source language identifier. */
22331 case DW_TAG_enumeration_type
:
22332 case DW_TAG_enumerator
:
22333 /* These tags always have simple identifiers already; no need
22334 to canonicalize them. */
22335 return DW_STRING (attr
);
22337 case DW_TAG_namespace
:
22338 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
22339 return DW_STRING (attr
);
22340 return CP_ANONYMOUS_NAMESPACE_STR
;
22342 case DW_TAG_class_type
:
22343 case DW_TAG_interface_type
:
22344 case DW_TAG_structure_type
:
22345 case DW_TAG_union_type
:
22346 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22347 structures or unions. These were of the form "._%d" in GCC 4.1,
22348 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22349 and GCC 4.4. We work around this problem by ignoring these. */
22350 if (attr
&& DW_STRING (attr
)
22351 && (startswith (DW_STRING (attr
), "._")
22352 || startswith (DW_STRING (attr
), "<anonymous")))
22355 /* GCC might emit a nameless typedef that has a linkage name. See
22356 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22357 if (!attr
|| DW_STRING (attr
) == NULL
)
22359 char *demangled
= NULL
;
22361 attr
= dw2_linkage_name_attr (die
, cu
);
22362 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22365 /* Avoid demangling DW_STRING (attr) the second time on a second
22366 call for the same DIE. */
22367 if (!DW_STRING_IS_CANONICAL (attr
))
22368 demangled
= gdb_demangle (DW_STRING (attr
), DMGL_TYPES
);
22374 /* FIXME: we already did this for the partial symbol... */
22377 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
22378 demangled
, strlen (demangled
)));
22379 DW_STRING_IS_CANONICAL (attr
) = 1;
22382 /* Strip any leading namespaces/classes, keep only the base name.
22383 DW_AT_name for named DIEs does not contain the prefixes. */
22384 base
= strrchr (DW_STRING (attr
), ':');
22385 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
22388 return DW_STRING (attr
);
22397 if (!DW_STRING_IS_CANONICAL (attr
))
22400 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
22401 &objfile
->per_bfd
->storage_obstack
);
22402 DW_STRING_IS_CANONICAL (attr
) = 1;
22404 return DW_STRING (attr
);
22407 /* Return the die that this die in an extension of, or NULL if there
22408 is none. *EXT_CU is the CU containing DIE on input, and the CU
22409 containing the return value on output. */
22411 static struct die_info
*
22412 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22414 struct attribute
*attr
;
22416 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22420 return follow_die_ref (die
, attr
, ext_cu
);
22423 /* Convert a DIE tag into its string name. */
22425 static const char *
22426 dwarf_tag_name (unsigned tag
)
22428 const char *name
= get_DW_TAG_name (tag
);
22431 return "DW_TAG_<unknown>";
22436 /* Convert a DWARF attribute code into its string name. */
22438 static const char *
22439 dwarf_attr_name (unsigned attr
)
22443 #ifdef MIPS /* collides with DW_AT_HP_block_index */
22444 if (attr
== DW_AT_MIPS_fde
)
22445 return "DW_AT_MIPS_fde";
22447 if (attr
== DW_AT_HP_block_index
)
22448 return "DW_AT_HP_block_index";
22451 name
= get_DW_AT_name (attr
);
22454 return "DW_AT_<unknown>";
22459 /* Convert a DWARF value form code into its string name. */
22461 static const char *
22462 dwarf_form_name (unsigned form
)
22464 const char *name
= get_DW_FORM_name (form
);
22467 return "DW_FORM_<unknown>";
22472 static const char *
22473 dwarf_bool_name (unsigned mybool
)
22481 /* Convert a DWARF type code into its string name. */
22483 static const char *
22484 dwarf_type_encoding_name (unsigned enc
)
22486 const char *name
= get_DW_ATE_name (enc
);
22489 return "DW_ATE_<unknown>";
22495 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22499 print_spaces (indent
, f
);
22500 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
22501 dwarf_tag_name (die
->tag
), die
->abbrev
,
22502 sect_offset_str (die
->sect_off
));
22504 if (die
->parent
!= NULL
)
22506 print_spaces (indent
, f
);
22507 fprintf_unfiltered (f
, " parent at offset: %s\n",
22508 sect_offset_str (die
->parent
->sect_off
));
22511 print_spaces (indent
, f
);
22512 fprintf_unfiltered (f
, " has children: %s\n",
22513 dwarf_bool_name (die
->child
!= NULL
));
22515 print_spaces (indent
, f
);
22516 fprintf_unfiltered (f
, " attributes:\n");
22518 for (i
= 0; i
< die
->num_attrs
; ++i
)
22520 print_spaces (indent
, f
);
22521 fprintf_unfiltered (f
, " %s (%s) ",
22522 dwarf_attr_name (die
->attrs
[i
].name
),
22523 dwarf_form_name (die
->attrs
[i
].form
));
22525 switch (die
->attrs
[i
].form
)
22528 case DW_FORM_GNU_addr_index
:
22529 fprintf_unfiltered (f
, "address: ");
22530 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
22532 case DW_FORM_block2
:
22533 case DW_FORM_block4
:
22534 case DW_FORM_block
:
22535 case DW_FORM_block1
:
22536 fprintf_unfiltered (f
, "block: size %s",
22537 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22539 case DW_FORM_exprloc
:
22540 fprintf_unfiltered (f
, "expression: size %s",
22541 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22543 case DW_FORM_data16
:
22544 fprintf_unfiltered (f
, "constant of 16 bytes");
22546 case DW_FORM_ref_addr
:
22547 fprintf_unfiltered (f
, "ref address: ");
22548 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22550 case DW_FORM_GNU_ref_alt
:
22551 fprintf_unfiltered (f
, "alt ref address: ");
22552 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22558 case DW_FORM_ref_udata
:
22559 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
22560 (long) (DW_UNSND (&die
->attrs
[i
])));
22562 case DW_FORM_data1
:
22563 case DW_FORM_data2
:
22564 case DW_FORM_data4
:
22565 case DW_FORM_data8
:
22566 case DW_FORM_udata
:
22567 case DW_FORM_sdata
:
22568 fprintf_unfiltered (f
, "constant: %s",
22569 pulongest (DW_UNSND (&die
->attrs
[i
])));
22571 case DW_FORM_sec_offset
:
22572 fprintf_unfiltered (f
, "section offset: %s",
22573 pulongest (DW_UNSND (&die
->attrs
[i
])));
22575 case DW_FORM_ref_sig8
:
22576 fprintf_unfiltered (f
, "signature: %s",
22577 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
22579 case DW_FORM_string
:
22581 case DW_FORM_line_strp
:
22582 case DW_FORM_GNU_str_index
:
22583 case DW_FORM_GNU_strp_alt
:
22584 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22585 DW_STRING (&die
->attrs
[i
])
22586 ? DW_STRING (&die
->attrs
[i
]) : "",
22587 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
22590 if (DW_UNSND (&die
->attrs
[i
]))
22591 fprintf_unfiltered (f
, "flag: TRUE");
22593 fprintf_unfiltered (f
, "flag: FALSE");
22595 case DW_FORM_flag_present
:
22596 fprintf_unfiltered (f
, "flag: TRUE");
22598 case DW_FORM_indirect
:
22599 /* The reader will have reduced the indirect form to
22600 the "base form" so this form should not occur. */
22601 fprintf_unfiltered (f
,
22602 "unexpected attribute form: DW_FORM_indirect");
22604 case DW_FORM_implicit_const
:
22605 fprintf_unfiltered (f
, "constant: %s",
22606 plongest (DW_SND (&die
->attrs
[i
])));
22609 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22610 die
->attrs
[i
].form
);
22613 fprintf_unfiltered (f
, "\n");
22618 dump_die_for_error (struct die_info
*die
)
22620 dump_die_shallow (gdb_stderr
, 0, die
);
22624 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22626 int indent
= level
* 4;
22628 gdb_assert (die
!= NULL
);
22630 if (level
>= max_level
)
22633 dump_die_shallow (f
, indent
, die
);
22635 if (die
->child
!= NULL
)
22637 print_spaces (indent
, f
);
22638 fprintf_unfiltered (f
, " Children:");
22639 if (level
+ 1 < max_level
)
22641 fprintf_unfiltered (f
, "\n");
22642 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22646 fprintf_unfiltered (f
,
22647 " [not printed, max nesting level reached]\n");
22651 if (die
->sibling
!= NULL
&& level
> 0)
22653 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22657 /* This is called from the pdie macro in gdbinit.in.
22658 It's not static so gcc will keep a copy callable from gdb. */
22661 dump_die (struct die_info
*die
, int max_level
)
22663 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22667 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22671 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22672 to_underlying (die
->sect_off
),
22678 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
22682 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
22684 if (attr_form_is_ref (attr
))
22685 return (sect_offset
) DW_UNSND (attr
);
22687 complaint (&symfile_complaints
,
22688 _("unsupported die ref attribute form: '%s'"),
22689 dwarf_form_name (attr
->form
));
22693 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
22694 * the value held by the attribute is not constant. */
22697 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
22699 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
22700 return DW_SND (attr
);
22701 else if (attr
->form
== DW_FORM_udata
22702 || attr
->form
== DW_FORM_data1
22703 || attr
->form
== DW_FORM_data2
22704 || attr
->form
== DW_FORM_data4
22705 || attr
->form
== DW_FORM_data8
)
22706 return DW_UNSND (attr
);
22709 /* For DW_FORM_data16 see attr_form_is_constant. */
22710 complaint (&symfile_complaints
,
22711 _("Attribute value is not a constant (%s)"),
22712 dwarf_form_name (attr
->form
));
22713 return default_value
;
22717 /* Follow reference or signature attribute ATTR of SRC_DIE.
22718 On entry *REF_CU is the CU of SRC_DIE.
22719 On exit *REF_CU is the CU of the result. */
22721 static struct die_info
*
22722 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22723 struct dwarf2_cu
**ref_cu
)
22725 struct die_info
*die
;
22727 if (attr_form_is_ref (attr
))
22728 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22729 else if (attr
->form
== DW_FORM_ref_sig8
)
22730 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22733 dump_die_for_error (src_die
);
22734 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22735 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22741 /* Follow reference OFFSET.
22742 On entry *REF_CU is the CU of the source die referencing OFFSET.
22743 On exit *REF_CU is the CU of the result.
22744 Returns NULL if OFFSET is invalid. */
22746 static struct die_info
*
22747 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22748 struct dwarf2_cu
**ref_cu
)
22750 struct die_info temp_die
;
22751 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22752 struct dwarf2_per_objfile
*dwarf2_per_objfile
22753 = cu
->per_cu
->dwarf2_per_objfile
;
22755 gdb_assert (cu
->per_cu
!= NULL
);
22759 if (cu
->per_cu
->is_debug_types
)
22761 /* .debug_types CUs cannot reference anything outside their CU.
22762 If they need to, they have to reference a signatured type via
22763 DW_FORM_ref_sig8. */
22764 if (!offset_in_cu_p (&cu
->header
, sect_off
))
22767 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22768 || !offset_in_cu_p (&cu
->header
, sect_off
))
22770 struct dwarf2_per_cu_data
*per_cu
;
22772 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22773 dwarf2_per_objfile
);
22775 /* If necessary, add it to the queue and load its DIEs. */
22776 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
22777 load_full_comp_unit (per_cu
, cu
->language
);
22779 target_cu
= per_cu
->cu
;
22781 else if (cu
->dies
== NULL
)
22783 /* We're loading full DIEs during partial symbol reading. */
22784 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
22785 load_full_comp_unit (cu
->per_cu
, language_minimal
);
22788 *ref_cu
= target_cu
;
22789 temp_die
.sect_off
= sect_off
;
22790 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22792 to_underlying (sect_off
));
22795 /* Follow reference attribute ATTR of SRC_DIE.
22796 On entry *REF_CU is the CU of SRC_DIE.
22797 On exit *REF_CU is the CU of the result. */
22799 static struct die_info
*
22800 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22801 struct dwarf2_cu
**ref_cu
)
22803 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22804 struct dwarf2_cu
*cu
= *ref_cu
;
22805 struct die_info
*die
;
22807 die
= follow_die_offset (sect_off
,
22808 (attr
->form
== DW_FORM_GNU_ref_alt
22809 || cu
->per_cu
->is_dwz
),
22812 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22813 "at %s [in module %s]"),
22814 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22815 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
22820 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
22821 Returned value is intended for DW_OP_call*. Returned
22822 dwarf2_locexpr_baton->data has lifetime of
22823 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
22825 struct dwarf2_locexpr_baton
22826 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22827 struct dwarf2_per_cu_data
*per_cu
,
22828 CORE_ADDR (*get_frame_pc
) (void *baton
),
22831 struct dwarf2_cu
*cu
;
22832 struct die_info
*die
;
22833 struct attribute
*attr
;
22834 struct dwarf2_locexpr_baton retval
;
22835 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
22836 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22838 if (per_cu
->cu
== NULL
)
22843 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22844 Instead just throw an error, not much else we can do. */
22845 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22846 sect_offset_str (sect_off
), objfile_name (objfile
));
22849 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22851 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22852 sect_offset_str (sect_off
), objfile_name (objfile
));
22854 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22857 /* DWARF: "If there is no such attribute, then there is no effect.".
22858 DATA is ignored if SIZE is 0. */
22860 retval
.data
= NULL
;
22863 else if (attr_form_is_section_offset (attr
))
22865 struct dwarf2_loclist_baton loclist_baton
;
22866 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22869 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
22871 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
22873 retval
.size
= size
;
22877 if (!attr_form_is_block (attr
))
22878 error (_("Dwarf Error: DIE at %s referenced in module %s "
22879 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
22880 sect_offset_str (sect_off
), objfile_name (objfile
));
22882 retval
.data
= DW_BLOCK (attr
)->data
;
22883 retval
.size
= DW_BLOCK (attr
)->size
;
22885 retval
.per_cu
= cu
->per_cu
;
22887 age_cached_comp_units (dwarf2_per_objfile
);
22892 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
22895 struct dwarf2_locexpr_baton
22896 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
22897 struct dwarf2_per_cu_data
*per_cu
,
22898 CORE_ADDR (*get_frame_pc
) (void *baton
),
22901 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
22903 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
22906 /* Write a constant of a given type as target-ordered bytes into
22909 static const gdb_byte
*
22910 write_constant_as_bytes (struct obstack
*obstack
,
22911 enum bfd_endian byte_order
,
22918 *len
= TYPE_LENGTH (type
);
22919 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22920 store_unsigned_integer (result
, *len
, byte_order
, value
);
22925 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
22926 pointer to the constant bytes and set LEN to the length of the
22927 data. If memory is needed, allocate it on OBSTACK. If the DIE
22928 does not have a DW_AT_const_value, return NULL. */
22931 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
22932 struct dwarf2_per_cu_data
*per_cu
,
22933 struct obstack
*obstack
,
22936 struct dwarf2_cu
*cu
;
22937 struct die_info
*die
;
22938 struct attribute
*attr
;
22939 const gdb_byte
*result
= NULL
;
22942 enum bfd_endian byte_order
;
22943 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
22945 if (per_cu
->cu
== NULL
)
22950 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22951 Instead just throw an error, not much else we can do. */
22952 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22953 sect_offset_str (sect_off
), objfile_name (objfile
));
22956 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22958 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22959 sect_offset_str (sect_off
), objfile_name (objfile
));
22961 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22965 byte_order
= (bfd_big_endian (objfile
->obfd
)
22966 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22968 switch (attr
->form
)
22971 case DW_FORM_GNU_addr_index
:
22975 *len
= cu
->header
.addr_size
;
22976 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22977 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
22981 case DW_FORM_string
:
22983 case DW_FORM_GNU_str_index
:
22984 case DW_FORM_GNU_strp_alt
:
22985 /* DW_STRING is already allocated on the objfile obstack, point
22987 result
= (const gdb_byte
*) DW_STRING (attr
);
22988 *len
= strlen (DW_STRING (attr
));
22990 case DW_FORM_block1
:
22991 case DW_FORM_block2
:
22992 case DW_FORM_block4
:
22993 case DW_FORM_block
:
22994 case DW_FORM_exprloc
:
22995 case DW_FORM_data16
:
22996 result
= DW_BLOCK (attr
)->data
;
22997 *len
= DW_BLOCK (attr
)->size
;
23000 /* The DW_AT_const_value attributes are supposed to carry the
23001 symbol's value "represented as it would be on the target
23002 architecture." By the time we get here, it's already been
23003 converted to host endianness, so we just need to sign- or
23004 zero-extend it as appropriate. */
23005 case DW_FORM_data1
:
23006 type
= die_type (die
, cu
);
23007 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23008 if (result
== NULL
)
23009 result
= write_constant_as_bytes (obstack
, byte_order
,
23012 case DW_FORM_data2
:
23013 type
= die_type (die
, cu
);
23014 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23015 if (result
== NULL
)
23016 result
= write_constant_as_bytes (obstack
, byte_order
,
23019 case DW_FORM_data4
:
23020 type
= die_type (die
, cu
);
23021 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23022 if (result
== NULL
)
23023 result
= write_constant_as_bytes (obstack
, byte_order
,
23026 case DW_FORM_data8
:
23027 type
= die_type (die
, cu
);
23028 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23029 if (result
== NULL
)
23030 result
= write_constant_as_bytes (obstack
, byte_order
,
23034 case DW_FORM_sdata
:
23035 case DW_FORM_implicit_const
:
23036 type
= die_type (die
, cu
);
23037 result
= write_constant_as_bytes (obstack
, byte_order
,
23038 type
, DW_SND (attr
), len
);
23041 case DW_FORM_udata
:
23042 type
= die_type (die
, cu
);
23043 result
= write_constant_as_bytes (obstack
, byte_order
,
23044 type
, DW_UNSND (attr
), len
);
23048 complaint (&symfile_complaints
,
23049 _("unsupported const value attribute form: '%s'"),
23050 dwarf_form_name (attr
->form
));
23057 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
23058 valid type for this die is found. */
23061 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23062 struct dwarf2_per_cu_data
*per_cu
)
23064 struct dwarf2_cu
*cu
;
23065 struct die_info
*die
;
23067 if (per_cu
->cu
== NULL
)
23073 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23077 return die_type (die
, cu
);
23080 /* Return the type of the DIE at DIE_OFFSET in the CU named by
23084 dwarf2_get_die_type (cu_offset die_offset
,
23085 struct dwarf2_per_cu_data
*per_cu
)
23087 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23088 return get_die_type_at_offset (die_offset_sect
, per_cu
);
23091 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23092 On entry *REF_CU is the CU of SRC_DIE.
23093 On exit *REF_CU is the CU of the result.
23094 Returns NULL if the referenced DIE isn't found. */
23096 static struct die_info
*
23097 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23098 struct dwarf2_cu
**ref_cu
)
23100 struct die_info temp_die
;
23101 struct dwarf2_cu
*sig_cu
;
23102 struct die_info
*die
;
23104 /* While it might be nice to assert sig_type->type == NULL here,
23105 we can get here for DW_AT_imported_declaration where we need
23106 the DIE not the type. */
23108 /* If necessary, add it to the queue and load its DIEs. */
23110 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
23111 read_signatured_type (sig_type
);
23113 sig_cu
= sig_type
->per_cu
.cu
;
23114 gdb_assert (sig_cu
!= NULL
);
23115 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23116 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23117 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23118 to_underlying (temp_die
.sect_off
));
23121 struct dwarf2_per_objfile
*dwarf2_per_objfile
23122 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
23124 /* For .gdb_index version 7 keep track of included TUs.
23125 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23126 if (dwarf2_per_objfile
->index_table
!= NULL
23127 && dwarf2_per_objfile
->index_table
->version
<= 7)
23129 VEC_safe_push (dwarf2_per_cu_ptr
,
23130 (*ref_cu
)->per_cu
->imported_symtabs
,
23141 /* Follow signatured type referenced by ATTR in SRC_DIE.
23142 On entry *REF_CU is the CU of SRC_DIE.
23143 On exit *REF_CU is the CU of the result.
23144 The result is the DIE of the type.
23145 If the referenced type cannot be found an error is thrown. */
23147 static struct die_info
*
23148 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23149 struct dwarf2_cu
**ref_cu
)
23151 ULONGEST signature
= DW_SIGNATURE (attr
);
23152 struct signatured_type
*sig_type
;
23153 struct die_info
*die
;
23155 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23157 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23158 /* sig_type will be NULL if the signatured type is missing from
23160 if (sig_type
== NULL
)
23162 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23163 " from DIE at %s [in module %s]"),
23164 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23165 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23168 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23171 dump_die_for_error (src_die
);
23172 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23173 " from DIE at %s [in module %s]"),
23174 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23175 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23181 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23182 reading in and processing the type unit if necessary. */
23184 static struct type
*
23185 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23186 struct dwarf2_cu
*cu
)
23188 struct dwarf2_per_objfile
*dwarf2_per_objfile
23189 = cu
->per_cu
->dwarf2_per_objfile
;
23190 struct signatured_type
*sig_type
;
23191 struct dwarf2_cu
*type_cu
;
23192 struct die_info
*type_die
;
23195 sig_type
= lookup_signatured_type (cu
, signature
);
23196 /* sig_type will be NULL if the signatured type is missing from
23198 if (sig_type
== NULL
)
23200 complaint (&symfile_complaints
,
23201 _("Dwarf Error: Cannot find signatured DIE %s referenced"
23202 " from DIE at %s [in module %s]"),
23203 hex_string (signature
), sect_offset_str (die
->sect_off
),
23204 objfile_name (dwarf2_per_objfile
->objfile
));
23205 return build_error_marker_type (cu
, die
);
23208 /* If we already know the type we're done. */
23209 if (sig_type
->type
!= NULL
)
23210 return sig_type
->type
;
23213 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23214 if (type_die
!= NULL
)
23216 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23217 is created. This is important, for example, because for c++ classes
23218 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23219 type
= read_type_die (type_die
, type_cu
);
23222 complaint (&symfile_complaints
,
23223 _("Dwarf Error: Cannot build signatured type %s"
23224 " referenced from DIE at %s [in module %s]"),
23225 hex_string (signature
), sect_offset_str (die
->sect_off
),
23226 objfile_name (dwarf2_per_objfile
->objfile
));
23227 type
= build_error_marker_type (cu
, die
);
23232 complaint (&symfile_complaints
,
23233 _("Dwarf Error: Problem reading signatured DIE %s referenced"
23234 " from DIE at %s [in module %s]"),
23235 hex_string (signature
), sect_offset_str (die
->sect_off
),
23236 objfile_name (dwarf2_per_objfile
->objfile
));
23237 type
= build_error_marker_type (cu
, die
);
23239 sig_type
->type
= type
;
23244 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23245 reading in and processing the type unit if necessary. */
23247 static struct type
*
23248 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23249 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23251 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23252 if (attr_form_is_ref (attr
))
23254 struct dwarf2_cu
*type_cu
= cu
;
23255 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23257 return read_type_die (type_die
, type_cu
);
23259 else if (attr
->form
== DW_FORM_ref_sig8
)
23261 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
23265 struct dwarf2_per_objfile
*dwarf2_per_objfile
23266 = cu
->per_cu
->dwarf2_per_objfile
;
23268 complaint (&symfile_complaints
,
23269 _("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23270 " at %s [in module %s]"),
23271 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
23272 objfile_name (dwarf2_per_objfile
->objfile
));
23273 return build_error_marker_type (cu
, die
);
23277 /* Load the DIEs associated with type unit PER_CU into memory. */
23280 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
23282 struct signatured_type
*sig_type
;
23284 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23285 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
23287 /* We have the per_cu, but we need the signatured_type.
23288 Fortunately this is an easy translation. */
23289 gdb_assert (per_cu
->is_debug_types
);
23290 sig_type
= (struct signatured_type
*) per_cu
;
23292 gdb_assert (per_cu
->cu
== NULL
);
23294 read_signatured_type (sig_type
);
23296 gdb_assert (per_cu
->cu
!= NULL
);
23299 /* die_reader_func for read_signatured_type.
23300 This is identical to load_full_comp_unit_reader,
23301 but is kept separate for now. */
23304 read_signatured_type_reader (const struct die_reader_specs
*reader
,
23305 const gdb_byte
*info_ptr
,
23306 struct die_info
*comp_unit_die
,
23310 struct dwarf2_cu
*cu
= reader
->cu
;
23312 gdb_assert (cu
->die_hash
== NULL
);
23314 htab_create_alloc_ex (cu
->header
.length
/ 12,
23318 &cu
->comp_unit_obstack
,
23319 hashtab_obstack_allocate
,
23320 dummy_obstack_deallocate
);
23323 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
23324 &info_ptr
, comp_unit_die
);
23325 cu
->dies
= comp_unit_die
;
23326 /* comp_unit_die is not stored in die_hash, no need. */
23328 /* We try not to read any attributes in this function, because not
23329 all CUs needed for references have been loaded yet, and symbol
23330 table processing isn't initialized. But we have to set the CU language,
23331 or we won't be able to build types correctly.
23332 Similarly, if we do not read the producer, we can not apply
23333 producer-specific interpretation. */
23334 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23337 /* Read in a signatured type and build its CU and DIEs.
23338 If the type is a stub for the real type in a DWO file,
23339 read in the real type from the DWO file as well. */
23342 read_signatured_type (struct signatured_type
*sig_type
)
23344 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
23346 gdb_assert (per_cu
->is_debug_types
);
23347 gdb_assert (per_cu
->cu
== NULL
);
23349 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1,
23350 read_signatured_type_reader
, NULL
);
23351 sig_type
->per_cu
.tu_read
= 1;
23354 /* Decode simple location descriptions.
23355 Given a pointer to a dwarf block that defines a location, compute
23356 the location and return the value.
23358 NOTE drow/2003-11-18: This function is called in two situations
23359 now: for the address of static or global variables (partial symbols
23360 only) and for offsets into structures which are expected to be
23361 (more or less) constant. The partial symbol case should go away,
23362 and only the constant case should remain. That will let this
23363 function complain more accurately. A few special modes are allowed
23364 without complaint for global variables (for instance, global
23365 register values and thread-local values).
23367 A location description containing no operations indicates that the
23368 object is optimized out. The return value is 0 for that case.
23369 FIXME drow/2003-11-16: No callers check for this case any more; soon all
23370 callers will only want a very basic result and this can become a
23373 Note that stack[0] is unused except as a default error return. */
23376 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
23378 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
23380 size_t size
= blk
->size
;
23381 const gdb_byte
*data
= blk
->data
;
23382 CORE_ADDR stack
[64];
23384 unsigned int bytes_read
, unsnd
;
23390 stack
[++stacki
] = 0;
23429 stack
[++stacki
] = op
- DW_OP_lit0
;
23464 stack
[++stacki
] = op
- DW_OP_reg0
;
23466 dwarf2_complex_location_expr_complaint ();
23470 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
23472 stack
[++stacki
] = unsnd
;
23474 dwarf2_complex_location_expr_complaint ();
23478 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
23483 case DW_OP_const1u
:
23484 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
23488 case DW_OP_const1s
:
23489 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
23493 case DW_OP_const2u
:
23494 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
23498 case DW_OP_const2s
:
23499 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
23503 case DW_OP_const4u
:
23504 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
23508 case DW_OP_const4s
:
23509 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
23513 case DW_OP_const8u
:
23514 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
23519 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
23525 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
23530 stack
[stacki
+ 1] = stack
[stacki
];
23535 stack
[stacki
- 1] += stack
[stacki
];
23539 case DW_OP_plus_uconst
:
23540 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
23546 stack
[stacki
- 1] -= stack
[stacki
];
23551 /* If we're not the last op, then we definitely can't encode
23552 this using GDB's address_class enum. This is valid for partial
23553 global symbols, although the variable's address will be bogus
23556 dwarf2_complex_location_expr_complaint ();
23559 case DW_OP_GNU_push_tls_address
:
23560 case DW_OP_form_tls_address
:
23561 /* The top of the stack has the offset from the beginning
23562 of the thread control block at which the variable is located. */
23563 /* Nothing should follow this operator, so the top of stack would
23565 /* This is valid for partial global symbols, but the variable's
23566 address will be bogus in the psymtab. Make it always at least
23567 non-zero to not look as a variable garbage collected by linker
23568 which have DW_OP_addr 0. */
23570 dwarf2_complex_location_expr_complaint ();
23574 case DW_OP_GNU_uninit
:
23577 case DW_OP_GNU_addr_index
:
23578 case DW_OP_GNU_const_index
:
23579 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23586 const char *name
= get_DW_OP_name (op
);
23589 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
23592 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
23596 return (stack
[stacki
]);
23599 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23600 outside of the allocated space. Also enforce minimum>0. */
23601 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23603 complaint (&symfile_complaints
,
23604 _("location description stack overflow"));
23610 complaint (&symfile_complaints
,
23611 _("location description stack underflow"));
23615 return (stack
[stacki
]);
23618 /* memory allocation interface */
23620 static struct dwarf_block
*
23621 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23623 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23626 static struct die_info
*
23627 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23629 struct die_info
*die
;
23630 size_t size
= sizeof (struct die_info
);
23633 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23635 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23636 memset (die
, 0, sizeof (struct die_info
));
23641 /* Macro support. */
23643 /* Return file name relative to the compilation directory of file number I in
23644 *LH's file name table. The result is allocated using xmalloc; the caller is
23645 responsible for freeing it. */
23648 file_file_name (int file
, struct line_header
*lh
)
23650 /* Is the file number a valid index into the line header's file name
23651 table? Remember that file numbers start with one, not zero. */
23652 if (1 <= file
&& file
<= lh
->file_names
.size ())
23654 const file_entry
&fe
= lh
->file_names
[file
- 1];
23656 if (!IS_ABSOLUTE_PATH (fe
.name
))
23658 const char *dir
= fe
.include_dir (lh
);
23660 return concat (dir
, SLASH_STRING
, fe
.name
, (char *) NULL
);
23662 return xstrdup (fe
.name
);
23666 /* The compiler produced a bogus file number. We can at least
23667 record the macro definitions made in the file, even if we
23668 won't be able to find the file by name. */
23669 char fake_name
[80];
23671 xsnprintf (fake_name
, sizeof (fake_name
),
23672 "<bad macro file number %d>", file
);
23674 complaint (&symfile_complaints
,
23675 _("bad file number in macro information (%d)"),
23678 return xstrdup (fake_name
);
23682 /* Return the full name of file number I in *LH's file name table.
23683 Use COMP_DIR as the name of the current directory of the
23684 compilation. The result is allocated using xmalloc; the caller is
23685 responsible for freeing it. */
23687 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
23689 /* Is the file number a valid index into the line header's file name
23690 table? Remember that file numbers start with one, not zero. */
23691 if (1 <= file
&& file
<= lh
->file_names
.size ())
23693 char *relative
= file_file_name (file
, lh
);
23695 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
23697 return reconcat (relative
, comp_dir
, SLASH_STRING
,
23698 relative
, (char *) NULL
);
23701 return file_file_name (file
, lh
);
23705 static struct macro_source_file
*
23706 macro_start_file (int file
, int line
,
23707 struct macro_source_file
*current_file
,
23708 struct line_header
*lh
)
23710 /* File name relative to the compilation directory of this source file. */
23711 char *file_name
= file_file_name (file
, lh
);
23713 if (! current_file
)
23715 /* Note: We don't create a macro table for this compilation unit
23716 at all until we actually get a filename. */
23717 struct macro_table
*macro_table
= get_macro_table ();
23719 /* If we have no current file, then this must be the start_file
23720 directive for the compilation unit's main source file. */
23721 current_file
= macro_set_main (macro_table
, file_name
);
23722 macro_define_special (macro_table
);
23725 current_file
= macro_include (current_file
, line
, file_name
);
23729 return current_file
;
23732 static const char *
23733 consume_improper_spaces (const char *p
, const char *body
)
23737 complaint (&symfile_complaints
,
23738 _("macro definition contains spaces "
23739 "in formal argument list:\n`%s'"),
23751 parse_macro_definition (struct macro_source_file
*file
, int line
,
23756 /* The body string takes one of two forms. For object-like macro
23757 definitions, it should be:
23759 <macro name> " " <definition>
23761 For function-like macro definitions, it should be:
23763 <macro name> "() " <definition>
23765 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
23767 Spaces may appear only where explicitly indicated, and in the
23770 The Dwarf 2 spec says that an object-like macro's name is always
23771 followed by a space, but versions of GCC around March 2002 omit
23772 the space when the macro's definition is the empty string.
23774 The Dwarf 2 spec says that there should be no spaces between the
23775 formal arguments in a function-like macro's formal argument list,
23776 but versions of GCC around March 2002 include spaces after the
23780 /* Find the extent of the macro name. The macro name is terminated
23781 by either a space or null character (for an object-like macro) or
23782 an opening paren (for a function-like macro). */
23783 for (p
= body
; *p
; p
++)
23784 if (*p
== ' ' || *p
== '(')
23787 if (*p
== ' ' || *p
== '\0')
23789 /* It's an object-like macro. */
23790 int name_len
= p
- body
;
23791 char *name
= savestring (body
, name_len
);
23792 const char *replacement
;
23795 replacement
= body
+ name_len
+ 1;
23798 dwarf2_macro_malformed_definition_complaint (body
);
23799 replacement
= body
+ name_len
;
23802 macro_define_object (file
, line
, name
, replacement
);
23806 else if (*p
== '(')
23808 /* It's a function-like macro. */
23809 char *name
= savestring (body
, p
- body
);
23812 char **argv
= XNEWVEC (char *, argv_size
);
23816 p
= consume_improper_spaces (p
, body
);
23818 /* Parse the formal argument list. */
23819 while (*p
&& *p
!= ')')
23821 /* Find the extent of the current argument name. */
23822 const char *arg_start
= p
;
23824 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
23827 if (! *p
|| p
== arg_start
)
23828 dwarf2_macro_malformed_definition_complaint (body
);
23831 /* Make sure argv has room for the new argument. */
23832 if (argc
>= argv_size
)
23835 argv
= XRESIZEVEC (char *, argv
, argv_size
);
23838 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
23841 p
= consume_improper_spaces (p
, body
);
23843 /* Consume the comma, if present. */
23848 p
= consume_improper_spaces (p
, body
);
23857 /* Perfectly formed definition, no complaints. */
23858 macro_define_function (file
, line
, name
,
23859 argc
, (const char **) argv
,
23861 else if (*p
== '\0')
23863 /* Complain, but do define it. */
23864 dwarf2_macro_malformed_definition_complaint (body
);
23865 macro_define_function (file
, line
, name
,
23866 argc
, (const char **) argv
,
23870 /* Just complain. */
23871 dwarf2_macro_malformed_definition_complaint (body
);
23874 /* Just complain. */
23875 dwarf2_macro_malformed_definition_complaint (body
);
23881 for (i
= 0; i
< argc
; i
++)
23887 dwarf2_macro_malformed_definition_complaint (body
);
23890 /* Skip some bytes from BYTES according to the form given in FORM.
23891 Returns the new pointer. */
23893 static const gdb_byte
*
23894 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
23895 enum dwarf_form form
,
23896 unsigned int offset_size
,
23897 struct dwarf2_section_info
*section
)
23899 unsigned int bytes_read
;
23903 case DW_FORM_data1
:
23908 case DW_FORM_data2
:
23912 case DW_FORM_data4
:
23916 case DW_FORM_data8
:
23920 case DW_FORM_data16
:
23924 case DW_FORM_string
:
23925 read_direct_string (abfd
, bytes
, &bytes_read
);
23926 bytes
+= bytes_read
;
23929 case DW_FORM_sec_offset
:
23931 case DW_FORM_GNU_strp_alt
:
23932 bytes
+= offset_size
;
23935 case DW_FORM_block
:
23936 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
23937 bytes
+= bytes_read
;
23940 case DW_FORM_block1
:
23941 bytes
+= 1 + read_1_byte (abfd
, bytes
);
23943 case DW_FORM_block2
:
23944 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
23946 case DW_FORM_block4
:
23947 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
23950 case DW_FORM_sdata
:
23951 case DW_FORM_udata
:
23952 case DW_FORM_GNU_addr_index
:
23953 case DW_FORM_GNU_str_index
:
23954 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
23957 dwarf2_section_buffer_overflow_complaint (section
);
23962 case DW_FORM_implicit_const
:
23967 complaint (&symfile_complaints
,
23968 _("invalid form 0x%x in `%s'"),
23969 form
, get_section_name (section
));
23977 /* A helper for dwarf_decode_macros that handles skipping an unknown
23978 opcode. Returns an updated pointer to the macro data buffer; or,
23979 on error, issues a complaint and returns NULL. */
23981 static const gdb_byte
*
23982 skip_unknown_opcode (unsigned int opcode
,
23983 const gdb_byte
**opcode_definitions
,
23984 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
23986 unsigned int offset_size
,
23987 struct dwarf2_section_info
*section
)
23989 unsigned int bytes_read
, i
;
23991 const gdb_byte
*defn
;
23993 if (opcode_definitions
[opcode
] == NULL
)
23995 complaint (&symfile_complaints
,
23996 _("unrecognized DW_MACFINO opcode 0x%x"),
24001 defn
= opcode_definitions
[opcode
];
24002 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
24003 defn
+= bytes_read
;
24005 for (i
= 0; i
< arg
; ++i
)
24007 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
24008 (enum dwarf_form
) defn
[i
], offset_size
,
24010 if (mac_ptr
== NULL
)
24012 /* skip_form_bytes already issued the complaint. */
24020 /* A helper function which parses the header of a macro section.
24021 If the macro section is the extended (for now called "GNU") type,
24022 then this updates *OFFSET_SIZE. Returns a pointer to just after
24023 the header, or issues a complaint and returns NULL on error. */
24025 static const gdb_byte
*
24026 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
24028 const gdb_byte
*mac_ptr
,
24029 unsigned int *offset_size
,
24030 int section_is_gnu
)
24032 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
24034 if (section_is_gnu
)
24036 unsigned int version
, flags
;
24038 version
= read_2_bytes (abfd
, mac_ptr
);
24039 if (version
!= 4 && version
!= 5)
24041 complaint (&symfile_complaints
,
24042 _("unrecognized version `%d' in .debug_macro section"),
24048 flags
= read_1_byte (abfd
, mac_ptr
);
24050 *offset_size
= (flags
& 1) ? 8 : 4;
24052 if ((flags
& 2) != 0)
24053 /* We don't need the line table offset. */
24054 mac_ptr
+= *offset_size
;
24056 /* Vendor opcode descriptions. */
24057 if ((flags
& 4) != 0)
24059 unsigned int i
, count
;
24061 count
= read_1_byte (abfd
, mac_ptr
);
24063 for (i
= 0; i
< count
; ++i
)
24065 unsigned int opcode
, bytes_read
;
24068 opcode
= read_1_byte (abfd
, mac_ptr
);
24070 opcode_definitions
[opcode
] = mac_ptr
;
24071 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24072 mac_ptr
+= bytes_read
;
24081 /* A helper for dwarf_decode_macros that handles the GNU extensions,
24082 including DW_MACRO_import. */
24085 dwarf_decode_macro_bytes (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
24087 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24088 struct macro_source_file
*current_file
,
24089 struct line_header
*lh
,
24090 struct dwarf2_section_info
*section
,
24091 int section_is_gnu
, int section_is_dwz
,
24092 unsigned int offset_size
,
24093 htab_t include_hash
)
24095 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24096 enum dwarf_macro_record_type macinfo_type
;
24097 int at_commandline
;
24098 const gdb_byte
*opcode_definitions
[256];
24100 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24101 &offset_size
, section_is_gnu
);
24102 if (mac_ptr
== NULL
)
24104 /* We already issued a complaint. */
24108 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
24109 GDB is still reading the definitions from command line. First
24110 DW_MACINFO_start_file will need to be ignored as it was already executed
24111 to create CURRENT_FILE for the main source holding also the command line
24112 definitions. On first met DW_MACINFO_start_file this flag is reset to
24113 normally execute all the remaining DW_MACINFO_start_file macinfos. */
24115 at_commandline
= 1;
24119 /* Do we at least have room for a macinfo type byte? */
24120 if (mac_ptr
>= mac_end
)
24122 dwarf2_section_buffer_overflow_complaint (section
);
24126 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24129 /* Note that we rely on the fact that the corresponding GNU and
24130 DWARF constants are the same. */
24132 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24133 switch (macinfo_type
)
24135 /* A zero macinfo type indicates the end of the macro
24140 case DW_MACRO_define
:
24141 case DW_MACRO_undef
:
24142 case DW_MACRO_define_strp
:
24143 case DW_MACRO_undef_strp
:
24144 case DW_MACRO_define_sup
:
24145 case DW_MACRO_undef_sup
:
24147 unsigned int bytes_read
;
24152 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24153 mac_ptr
+= bytes_read
;
24155 if (macinfo_type
== DW_MACRO_define
24156 || macinfo_type
== DW_MACRO_undef
)
24158 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24159 mac_ptr
+= bytes_read
;
24163 LONGEST str_offset
;
24165 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24166 mac_ptr
+= offset_size
;
24168 if (macinfo_type
== DW_MACRO_define_sup
24169 || macinfo_type
== DW_MACRO_undef_sup
24172 struct dwz_file
*dwz
24173 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
24175 body
= read_indirect_string_from_dwz (objfile
,
24179 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
24183 is_define
= (macinfo_type
== DW_MACRO_define
24184 || macinfo_type
== DW_MACRO_define_strp
24185 || macinfo_type
== DW_MACRO_define_sup
);
24186 if (! current_file
)
24188 /* DWARF violation as no main source is present. */
24189 complaint (&symfile_complaints
,
24190 _("debug info with no main source gives macro %s "
24192 is_define
? _("definition") : _("undefinition"),
24196 if ((line
== 0 && !at_commandline
)
24197 || (line
!= 0 && at_commandline
))
24198 complaint (&symfile_complaints
,
24199 _("debug info gives %s macro %s with %s line %d: %s"),
24200 at_commandline
? _("command-line") : _("in-file"),
24201 is_define
? _("definition") : _("undefinition"),
24202 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
24205 parse_macro_definition (current_file
, line
, body
);
24208 gdb_assert (macinfo_type
== DW_MACRO_undef
24209 || macinfo_type
== DW_MACRO_undef_strp
24210 || macinfo_type
== DW_MACRO_undef_sup
);
24211 macro_undef (current_file
, line
, body
);
24216 case DW_MACRO_start_file
:
24218 unsigned int bytes_read
;
24221 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24222 mac_ptr
+= bytes_read
;
24223 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24224 mac_ptr
+= bytes_read
;
24226 if ((line
== 0 && !at_commandline
)
24227 || (line
!= 0 && at_commandline
))
24228 complaint (&symfile_complaints
,
24229 _("debug info gives source %d included "
24230 "from %s at %s line %d"),
24231 file
, at_commandline
? _("command-line") : _("file"),
24232 line
== 0 ? _("zero") : _("non-zero"), line
);
24234 if (at_commandline
)
24236 /* This DW_MACRO_start_file was executed in the
24238 at_commandline
= 0;
24241 current_file
= macro_start_file (file
, line
, current_file
, lh
);
24245 case DW_MACRO_end_file
:
24246 if (! current_file
)
24247 complaint (&symfile_complaints
,
24248 _("macro debug info has an unmatched "
24249 "`close_file' directive"));
24252 current_file
= current_file
->included_by
;
24253 if (! current_file
)
24255 enum dwarf_macro_record_type next_type
;
24257 /* GCC circa March 2002 doesn't produce the zero
24258 type byte marking the end of the compilation
24259 unit. Complain if it's not there, but exit no
24262 /* Do we at least have room for a macinfo type byte? */
24263 if (mac_ptr
>= mac_end
)
24265 dwarf2_section_buffer_overflow_complaint (section
);
24269 /* We don't increment mac_ptr here, so this is just
24272 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
24274 if (next_type
!= 0)
24275 complaint (&symfile_complaints
,
24276 _("no terminating 0-type entry for "
24277 "macros in `.debug_macinfo' section"));
24284 case DW_MACRO_import
:
24285 case DW_MACRO_import_sup
:
24289 bfd
*include_bfd
= abfd
;
24290 struct dwarf2_section_info
*include_section
= section
;
24291 const gdb_byte
*include_mac_end
= mac_end
;
24292 int is_dwz
= section_is_dwz
;
24293 const gdb_byte
*new_mac_ptr
;
24295 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24296 mac_ptr
+= offset_size
;
24298 if (macinfo_type
== DW_MACRO_import_sup
)
24300 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
24302 dwarf2_read_section (objfile
, &dwz
->macro
);
24304 include_section
= &dwz
->macro
;
24305 include_bfd
= get_section_bfd_owner (include_section
);
24306 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
24310 new_mac_ptr
= include_section
->buffer
+ offset
;
24311 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
24315 /* This has actually happened; see
24316 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
24317 complaint (&symfile_complaints
,
24318 _("recursive DW_MACRO_import in "
24319 ".debug_macro section"));
24323 *slot
= (void *) new_mac_ptr
;
24325 dwarf_decode_macro_bytes (dwarf2_per_objfile
,
24326 include_bfd
, new_mac_ptr
,
24327 include_mac_end
, current_file
, lh
,
24328 section
, section_is_gnu
, is_dwz
,
24329 offset_size
, include_hash
);
24331 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
24336 case DW_MACINFO_vendor_ext
:
24337 if (!section_is_gnu
)
24339 unsigned int bytes_read
;
24341 /* This reads the constant, but since we don't recognize
24342 any vendor extensions, we ignore it. */
24343 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24344 mac_ptr
+= bytes_read
;
24345 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24346 mac_ptr
+= bytes_read
;
24348 /* We don't recognize any vendor extensions. */
24354 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
24355 mac_ptr
, mac_end
, abfd
, offset_size
,
24357 if (mac_ptr
== NULL
)
24362 } while (macinfo_type
!= 0);
24366 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24367 int section_is_gnu
)
24369 struct dwarf2_per_objfile
*dwarf2_per_objfile
24370 = cu
->per_cu
->dwarf2_per_objfile
;
24371 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24372 struct line_header
*lh
= cu
->line_header
;
24374 const gdb_byte
*mac_ptr
, *mac_end
;
24375 struct macro_source_file
*current_file
= 0;
24376 enum dwarf_macro_record_type macinfo_type
;
24377 unsigned int offset_size
= cu
->header
.offset_size
;
24378 const gdb_byte
*opcode_definitions
[256];
24380 struct dwarf2_section_info
*section
;
24381 const char *section_name
;
24383 if (cu
->dwo_unit
!= NULL
)
24385 if (section_is_gnu
)
24387 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24388 section_name
= ".debug_macro.dwo";
24392 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24393 section_name
= ".debug_macinfo.dwo";
24398 if (section_is_gnu
)
24400 section
= &dwarf2_per_objfile
->macro
;
24401 section_name
= ".debug_macro";
24405 section
= &dwarf2_per_objfile
->macinfo
;
24406 section_name
= ".debug_macinfo";
24410 dwarf2_read_section (objfile
, section
);
24411 if (section
->buffer
== NULL
)
24413 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
24416 abfd
= get_section_bfd_owner (section
);
24418 /* First pass: Find the name of the base filename.
24419 This filename is needed in order to process all macros whose definition
24420 (or undefinition) comes from the command line. These macros are defined
24421 before the first DW_MACINFO_start_file entry, and yet still need to be
24422 associated to the base file.
24424 To determine the base file name, we scan the macro definitions until we
24425 reach the first DW_MACINFO_start_file entry. We then initialize
24426 CURRENT_FILE accordingly so that any macro definition found before the
24427 first DW_MACINFO_start_file can still be associated to the base file. */
24429 mac_ptr
= section
->buffer
+ offset
;
24430 mac_end
= section
->buffer
+ section
->size
;
24432 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24433 &offset_size
, section_is_gnu
);
24434 if (mac_ptr
== NULL
)
24436 /* We already issued a complaint. */
24442 /* Do we at least have room for a macinfo type byte? */
24443 if (mac_ptr
>= mac_end
)
24445 /* Complaint is printed during the second pass as GDB will probably
24446 stop the first pass earlier upon finding
24447 DW_MACINFO_start_file. */
24451 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24454 /* Note that we rely on the fact that the corresponding GNU and
24455 DWARF constants are the same. */
24457 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24458 switch (macinfo_type
)
24460 /* A zero macinfo type indicates the end of the macro
24465 case DW_MACRO_define
:
24466 case DW_MACRO_undef
:
24467 /* Only skip the data by MAC_PTR. */
24469 unsigned int bytes_read
;
24471 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24472 mac_ptr
+= bytes_read
;
24473 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24474 mac_ptr
+= bytes_read
;
24478 case DW_MACRO_start_file
:
24480 unsigned int bytes_read
;
24483 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24484 mac_ptr
+= bytes_read
;
24485 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24486 mac_ptr
+= bytes_read
;
24488 current_file
= macro_start_file (file
, line
, current_file
, lh
);
24492 case DW_MACRO_end_file
:
24493 /* No data to skip by MAC_PTR. */
24496 case DW_MACRO_define_strp
:
24497 case DW_MACRO_undef_strp
:
24498 case DW_MACRO_define_sup
:
24499 case DW_MACRO_undef_sup
:
24501 unsigned int bytes_read
;
24503 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24504 mac_ptr
+= bytes_read
;
24505 mac_ptr
+= offset_size
;
24509 case DW_MACRO_import
:
24510 case DW_MACRO_import_sup
:
24511 /* Note that, according to the spec, a transparent include
24512 chain cannot call DW_MACRO_start_file. So, we can just
24513 skip this opcode. */
24514 mac_ptr
+= offset_size
;
24517 case DW_MACINFO_vendor_ext
:
24518 /* Only skip the data by MAC_PTR. */
24519 if (!section_is_gnu
)
24521 unsigned int bytes_read
;
24523 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24524 mac_ptr
+= bytes_read
;
24525 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24526 mac_ptr
+= bytes_read
;
24531 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
24532 mac_ptr
, mac_end
, abfd
, offset_size
,
24534 if (mac_ptr
== NULL
)
24539 } while (macinfo_type
!= 0 && current_file
== NULL
);
24541 /* Second pass: Process all entries.
24543 Use the AT_COMMAND_LINE flag to determine whether we are still processing
24544 command-line macro definitions/undefinitions. This flag is unset when we
24545 reach the first DW_MACINFO_start_file entry. */
24547 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
24549 NULL
, xcalloc
, xfree
));
24550 mac_ptr
= section
->buffer
+ offset
;
24551 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
24552 *slot
= (void *) mac_ptr
;
24553 dwarf_decode_macro_bytes (dwarf2_per_objfile
,
24554 abfd
, mac_ptr
, mac_end
,
24555 current_file
, lh
, section
,
24556 section_is_gnu
, 0, offset_size
,
24557 include_hash
.get ());
24560 /* Check if the attribute's form is a DW_FORM_block*
24561 if so return true else false. */
24564 attr_form_is_block (const struct attribute
*attr
)
24566 return (attr
== NULL
? 0 :
24567 attr
->form
== DW_FORM_block1
24568 || attr
->form
== DW_FORM_block2
24569 || attr
->form
== DW_FORM_block4
24570 || attr
->form
== DW_FORM_block
24571 || attr
->form
== DW_FORM_exprloc
);
24574 /* Return non-zero if ATTR's value is a section offset --- classes
24575 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
24576 You may use DW_UNSND (attr) to retrieve such offsets.
24578 Section 7.5.4, "Attribute Encodings", explains that no attribute
24579 may have a value that belongs to more than one of these classes; it
24580 would be ambiguous if we did, because we use the same forms for all
24584 attr_form_is_section_offset (const struct attribute
*attr
)
24586 return (attr
->form
== DW_FORM_data4
24587 || attr
->form
== DW_FORM_data8
24588 || attr
->form
== DW_FORM_sec_offset
);
24591 /* Return non-zero if ATTR's value falls in the 'constant' class, or
24592 zero otherwise. When this function returns true, you can apply
24593 dwarf2_get_attr_constant_value to it.
24595 However, note that for some attributes you must check
24596 attr_form_is_section_offset before using this test. DW_FORM_data4
24597 and DW_FORM_data8 are members of both the constant class, and of
24598 the classes that contain offsets into other debug sections
24599 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
24600 that, if an attribute's can be either a constant or one of the
24601 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
24602 taken as section offsets, not constants.
24604 DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
24605 cannot handle that. */
24608 attr_form_is_constant (const struct attribute
*attr
)
24610 switch (attr
->form
)
24612 case DW_FORM_sdata
:
24613 case DW_FORM_udata
:
24614 case DW_FORM_data1
:
24615 case DW_FORM_data2
:
24616 case DW_FORM_data4
:
24617 case DW_FORM_data8
:
24618 case DW_FORM_implicit_const
:
24626 /* DW_ADDR is always stored already as sect_offset; despite for the forms
24627 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
24630 attr_form_is_ref (const struct attribute
*attr
)
24632 switch (attr
->form
)
24634 case DW_FORM_ref_addr
:
24639 case DW_FORM_ref_udata
:
24640 case DW_FORM_GNU_ref_alt
:
24647 /* Return the .debug_loc section to use for CU.
24648 For DWO files use .debug_loc.dwo. */
24650 static struct dwarf2_section_info
*
24651 cu_debug_loc_section (struct dwarf2_cu
*cu
)
24653 struct dwarf2_per_objfile
*dwarf2_per_objfile
24654 = cu
->per_cu
->dwarf2_per_objfile
;
24658 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24660 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
24662 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
24663 : &dwarf2_per_objfile
->loc
);
24666 /* A helper function that fills in a dwarf2_loclist_baton. */
24669 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
24670 struct dwarf2_loclist_baton
*baton
,
24671 const struct attribute
*attr
)
24673 struct dwarf2_per_objfile
*dwarf2_per_objfile
24674 = cu
->per_cu
->dwarf2_per_objfile
;
24675 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24677 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
24679 baton
->per_cu
= cu
->per_cu
;
24680 gdb_assert (baton
->per_cu
);
24681 /* We don't know how long the location list is, but make sure we
24682 don't run off the edge of the section. */
24683 baton
->size
= section
->size
- DW_UNSND (attr
);
24684 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
24685 baton
->base_address
= cu
->base_address
;
24686 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
24690 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
24691 struct dwarf2_cu
*cu
, int is_block
)
24693 struct dwarf2_per_objfile
*dwarf2_per_objfile
24694 = cu
->per_cu
->dwarf2_per_objfile
;
24695 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24696 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24698 if (attr_form_is_section_offset (attr
)
24699 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24700 the section. If so, fall through to the complaint in the
24702 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
24704 struct dwarf2_loclist_baton
*baton
;
24706 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24708 fill_in_loclist_baton (cu
, baton
, attr
);
24710 if (cu
->base_known
== 0)
24711 complaint (&symfile_complaints
,
24712 _("Location list used without "
24713 "specifying the CU base address."));
24715 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24716 ? dwarf2_loclist_block_index
24717 : dwarf2_loclist_index
);
24718 SYMBOL_LOCATION_BATON (sym
) = baton
;
24722 struct dwarf2_locexpr_baton
*baton
;
24724 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24725 baton
->per_cu
= cu
->per_cu
;
24726 gdb_assert (baton
->per_cu
);
24728 if (attr_form_is_block (attr
))
24730 /* Note that we're just copying the block's data pointer
24731 here, not the actual data. We're still pointing into the
24732 info_buffer for SYM's objfile; right now we never release
24733 that buffer, but when we do clean up properly this may
24735 baton
->size
= DW_BLOCK (attr
)->size
;
24736 baton
->data
= DW_BLOCK (attr
)->data
;
24740 dwarf2_invalid_attrib_class_complaint ("location description",
24741 SYMBOL_NATURAL_NAME (sym
));
24745 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24746 ? dwarf2_locexpr_block_index
24747 : dwarf2_locexpr_index
);
24748 SYMBOL_LOCATION_BATON (sym
) = baton
;
24752 /* Return the OBJFILE associated with the compilation unit CU. If CU
24753 came from a separate debuginfo file, then the master objfile is
24757 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
24759 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
24761 /* Return the master objfile, so that we can report and look up the
24762 correct file containing this variable. */
24763 if (objfile
->separate_debug_objfile_backlink
)
24764 objfile
= objfile
->separate_debug_objfile_backlink
;
24769 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
24770 (CU_HEADERP is unused in such case) or prepare a temporary copy at
24771 CU_HEADERP first. */
24773 static const struct comp_unit_head
*
24774 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
24775 struct dwarf2_per_cu_data
*per_cu
)
24777 const gdb_byte
*info_ptr
;
24780 return &per_cu
->cu
->header
;
24782 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
24784 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
24785 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
24786 rcuh_kind::COMPILE
);
24791 /* Return the address size given in the compilation unit header for CU. */
24794 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
24796 struct comp_unit_head cu_header_local
;
24797 const struct comp_unit_head
*cu_headerp
;
24799 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
24801 return cu_headerp
->addr_size
;
24804 /* Return the offset size given in the compilation unit header for CU. */
24807 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
24809 struct comp_unit_head cu_header_local
;
24810 const struct comp_unit_head
*cu_headerp
;
24812 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
24814 return cu_headerp
->offset_size
;
24817 /* See its dwarf2loc.h declaration. */
24820 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
24822 struct comp_unit_head cu_header_local
;
24823 const struct comp_unit_head
*cu_headerp
;
24825 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
24827 if (cu_headerp
->version
== 2)
24828 return cu_headerp
->addr_size
;
24830 return cu_headerp
->offset_size
;
24833 /* Return the text offset of the CU. The returned offset comes from
24834 this CU's objfile. If this objfile came from a separate debuginfo
24835 file, then the offset may be different from the corresponding
24836 offset in the parent objfile. */
24839 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
24841 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
24843 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
24846 /* Return DWARF version number of PER_CU. */
24849 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
24851 return per_cu
->dwarf_version
;
24854 /* Locate the .debug_info compilation unit from CU's objfile which contains
24855 the DIE at OFFSET. Raises an error on failure. */
24857 static struct dwarf2_per_cu_data
*
24858 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24859 unsigned int offset_in_dwz
,
24860 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
24862 struct dwarf2_per_cu_data
*this_cu
;
24864 const sect_offset
*cu_off
;
24867 high
= dwarf2_per_objfile
->all_comp_units
.size () - 1;
24870 struct dwarf2_per_cu_data
*mid_cu
;
24871 int mid
= low
+ (high
- low
) / 2;
24873 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
24874 cu_off
= &mid_cu
->sect_off
;
24875 if (mid_cu
->is_dwz
> offset_in_dwz
24876 || (mid_cu
->is_dwz
== offset_in_dwz
&& *cu_off
>= sect_off
))
24881 gdb_assert (low
== high
);
24882 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
24883 cu_off
= &this_cu
->sect_off
;
24884 if (this_cu
->is_dwz
!= offset_in_dwz
|| *cu_off
> sect_off
)
24886 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
24887 error (_("Dwarf Error: could not find partial DIE containing "
24888 "offset %s [in module %s]"),
24889 sect_offset_str (sect_off
),
24890 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
24892 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
24894 return dwarf2_per_objfile
->all_comp_units
[low
-1];
24898 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
24899 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
24900 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
24901 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
24902 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
24907 /* Initialize dwarf2_cu CU, owned by PER_CU. */
24909 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
24910 : per_cu (per_cu_
),
24913 checked_producer (0),
24914 producer_is_gxx_lt_4_6 (0),
24915 producer_is_gcc_lt_4_3 (0),
24916 producer_is_icc_lt_14 (0),
24917 processing_has_namespace_info (0)
24922 /* Destroy a dwarf2_cu. */
24924 dwarf2_cu::~dwarf2_cu ()
24929 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
24932 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
24933 enum language pretend_language
)
24935 struct attribute
*attr
;
24937 /* Set the language we're debugging. */
24938 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
24940 set_cu_language (DW_UNSND (attr
), cu
);
24943 cu
->language
= pretend_language
;
24944 cu
->language_defn
= language_def (cu
->language
);
24947 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
24950 /* Increase the age counter on each cached compilation unit, and free
24951 any that are too old. */
24954 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
24956 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
24958 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
24959 per_cu
= dwarf2_per_objfile
->read_in_chain
;
24960 while (per_cu
!= NULL
)
24962 per_cu
->cu
->last_used
++;
24963 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
24964 dwarf2_mark (per_cu
->cu
);
24965 per_cu
= per_cu
->cu
->read_in_chain
;
24968 per_cu
= dwarf2_per_objfile
->read_in_chain
;
24969 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
24970 while (per_cu
!= NULL
)
24972 struct dwarf2_per_cu_data
*next_cu
;
24974 next_cu
= per_cu
->cu
->read_in_chain
;
24976 if (!per_cu
->cu
->mark
)
24979 *last_chain
= next_cu
;
24982 last_chain
= &per_cu
->cu
->read_in_chain
;
24988 /* Remove a single compilation unit from the cache. */
24991 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
24993 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
24994 struct dwarf2_per_objfile
*dwarf2_per_objfile
24995 = target_per_cu
->dwarf2_per_objfile
;
24997 per_cu
= dwarf2_per_objfile
->read_in_chain
;
24998 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
24999 while (per_cu
!= NULL
)
25001 struct dwarf2_per_cu_data
*next_cu
;
25003 next_cu
= per_cu
->cu
->read_in_chain
;
25005 if (per_cu
== target_per_cu
)
25009 *last_chain
= next_cu
;
25013 last_chain
= &per_cu
->cu
->read_in_chain
;
25019 /* Release all extra memory associated with OBJFILE. */
25022 dwarf2_free_objfile (struct objfile
*objfile
)
25024 struct dwarf2_per_objfile
*dwarf2_per_objfile
25025 = get_dwarf2_per_objfile (objfile
);
25027 delete dwarf2_per_objfile
;
25030 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
25031 We store these in a hash table separate from the DIEs, and preserve them
25032 when the DIEs are flushed out of cache.
25034 The CU "per_cu" pointer is needed because offset alone is not enough to
25035 uniquely identify the type. A file may have multiple .debug_types sections,
25036 or the type may come from a DWO file. Furthermore, while it's more logical
25037 to use per_cu->section+offset, with Fission the section with the data is in
25038 the DWO file but we don't know that section at the point we need it.
25039 We have to use something in dwarf2_per_cu_data (or the pointer to it)
25040 because we can enter the lookup routine, get_die_type_at_offset, from
25041 outside this file, and thus won't necessarily have PER_CU->cu.
25042 Fortunately, PER_CU is stable for the life of the objfile. */
25044 struct dwarf2_per_cu_offset_and_type
25046 const struct dwarf2_per_cu_data
*per_cu
;
25047 sect_offset sect_off
;
25051 /* Hash function for a dwarf2_per_cu_offset_and_type. */
25054 per_cu_offset_and_type_hash (const void *item
)
25056 const struct dwarf2_per_cu_offset_and_type
*ofs
25057 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
25059 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
25062 /* Equality function for a dwarf2_per_cu_offset_and_type. */
25065 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
25067 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
25068 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
25069 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25070 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25072 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25073 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25076 /* Set the type associated with DIE to TYPE. Save it in CU's hash
25077 table if necessary. For convenience, return TYPE.
25079 The DIEs reading must have careful ordering to:
25080 * Not cause infite loops trying to read in DIEs as a prerequisite for
25081 reading current DIE.
25082 * Not trying to dereference contents of still incompletely read in types
25083 while reading in other DIEs.
25084 * Enable referencing still incompletely read in types just by a pointer to
25085 the type without accessing its fields.
25087 Therefore caller should follow these rules:
25088 * Try to fetch any prerequisite types we may need to build this DIE type
25089 before building the type and calling set_die_type.
25090 * After building type call set_die_type for current DIE as soon as
25091 possible before fetching more types to complete the current type.
25092 * Make the type as complete as possible before fetching more types. */
25094 static struct type
*
25095 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
25097 struct dwarf2_per_objfile
*dwarf2_per_objfile
25098 = cu
->per_cu
->dwarf2_per_objfile
;
25099 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
25100 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25101 struct attribute
*attr
;
25102 struct dynamic_prop prop
;
25104 /* For Ada types, make sure that the gnat-specific data is always
25105 initialized (if not already set). There are a few types where
25106 we should not be doing so, because the type-specific area is
25107 already used to hold some other piece of info (eg: TYPE_CODE_FLT
25108 where the type-specific area is used to store the floatformat).
25109 But this is not a problem, because the gnat-specific information
25110 is actually not needed for these types. */
25111 if (need_gnat_info (cu
)
25112 && TYPE_CODE (type
) != TYPE_CODE_FUNC
25113 && TYPE_CODE (type
) != TYPE_CODE_FLT
25114 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
25115 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
25116 && TYPE_CODE (type
) != TYPE_CODE_METHOD
25117 && !HAVE_GNAT_AUX_INFO (type
))
25118 INIT_GNAT_SPECIFIC (type
);
25120 /* Read DW_AT_allocated and set in type. */
25121 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
25122 if (attr_form_is_block (attr
))
25124 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25125 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
25127 else if (attr
!= NULL
)
25129 complaint (&symfile_complaints
,
25130 _("DW_AT_allocated has the wrong form (%s) at DIE %s"),
25131 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25132 sect_offset_str (die
->sect_off
));
25135 /* Read DW_AT_associated and set in type. */
25136 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
25137 if (attr_form_is_block (attr
))
25139 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25140 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
25142 else if (attr
!= NULL
)
25144 complaint (&symfile_complaints
,
25145 _("DW_AT_associated has the wrong form (%s) at DIE %s"),
25146 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25147 sect_offset_str (die
->sect_off
));
25150 /* Read DW_AT_data_location and set in type. */
25151 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
25152 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25153 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
25155 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25157 dwarf2_per_objfile
->die_type_hash
=
25158 htab_create_alloc_ex (127,
25159 per_cu_offset_and_type_hash
,
25160 per_cu_offset_and_type_eq
,
25162 &objfile
->objfile_obstack
,
25163 hashtab_obstack_allocate
,
25164 dummy_obstack_deallocate
);
25167 ofs
.per_cu
= cu
->per_cu
;
25168 ofs
.sect_off
= die
->sect_off
;
25170 slot
= (struct dwarf2_per_cu_offset_and_type
**)
25171 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
25173 complaint (&symfile_complaints
,
25174 _("A problem internal to GDB: DIE %s has type already set"),
25175 sect_offset_str (die
->sect_off
));
25176 *slot
= XOBNEW (&objfile
->objfile_obstack
,
25177 struct dwarf2_per_cu_offset_and_type
);
25182 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
25183 or return NULL if the die does not have a saved type. */
25185 static struct type
*
25186 get_die_type_at_offset (sect_offset sect_off
,
25187 struct dwarf2_per_cu_data
*per_cu
)
25189 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
25190 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
25192 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25195 ofs
.per_cu
= per_cu
;
25196 ofs
.sect_off
= sect_off
;
25197 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
25198 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
25205 /* Look up the type for DIE in CU in die_type_hash,
25206 or return NULL if DIE does not have a saved type. */
25208 static struct type
*
25209 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
25211 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
25214 /* Add a dependence relationship from CU to REF_PER_CU. */
25217 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
25218 struct dwarf2_per_cu_data
*ref_per_cu
)
25222 if (cu
->dependencies
== NULL
)
25224 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
25225 NULL
, &cu
->comp_unit_obstack
,
25226 hashtab_obstack_allocate
,
25227 dummy_obstack_deallocate
);
25229 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
25231 *slot
= ref_per_cu
;
25234 /* Subroutine of dwarf2_mark to pass to htab_traverse.
25235 Set the mark field in every compilation unit in the
25236 cache that we must keep because we are keeping CU. */
25239 dwarf2_mark_helper (void **slot
, void *data
)
25241 struct dwarf2_per_cu_data
*per_cu
;
25243 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
25245 /* cu->dependencies references may not yet have been ever read if QUIT aborts
25246 reading of the chain. As such dependencies remain valid it is not much
25247 useful to track and undo them during QUIT cleanups. */
25248 if (per_cu
->cu
== NULL
)
25251 if (per_cu
->cu
->mark
)
25253 per_cu
->cu
->mark
= 1;
25255 if (per_cu
->cu
->dependencies
!= NULL
)
25256 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25261 /* Set the mark field in CU and in every other compilation unit in the
25262 cache that we must keep because we are keeping CU. */
25265 dwarf2_mark (struct dwarf2_cu
*cu
)
25270 if (cu
->dependencies
!= NULL
)
25271 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25275 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
25279 per_cu
->cu
->mark
= 0;
25280 per_cu
= per_cu
->cu
->read_in_chain
;
25284 /* Trivial hash function for partial_die_info: the hash value of a DIE
25285 is its offset in .debug_info for this objfile. */
25288 partial_die_hash (const void *item
)
25290 const struct partial_die_info
*part_die
25291 = (const struct partial_die_info
*) item
;
25293 return to_underlying (part_die
->sect_off
);
25296 /* Trivial comparison function for partial_die_info structures: two DIEs
25297 are equal if they have the same offset. */
25300 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
25302 const struct partial_die_info
*part_die_lhs
25303 = (const struct partial_die_info
*) item_lhs
;
25304 const struct partial_die_info
*part_die_rhs
25305 = (const struct partial_die_info
*) item_rhs
;
25307 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
25310 static struct cmd_list_element
*set_dwarf_cmdlist
;
25311 static struct cmd_list_element
*show_dwarf_cmdlist
;
25314 set_dwarf_cmd (const char *args
, int from_tty
)
25316 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
25321 show_dwarf_cmd (const char *args
, int from_tty
)
25323 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
25326 int dwarf_always_disassemble
;
25329 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
25330 struct cmd_list_element
*c
, const char *value
)
25332 fprintf_filtered (file
,
25333 _("Whether to always disassemble "
25334 "DWARF expressions is %s.\n"),
25339 show_check_physname (struct ui_file
*file
, int from_tty
,
25340 struct cmd_list_element
*c
, const char *value
)
25342 fprintf_filtered (file
,
25343 _("Whether to check \"physname\" is %s.\n"),
25348 _initialize_dwarf2_read (void)
25351 dwarf2_objfile_data_key
= register_objfile_data ();
25353 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
25354 Set DWARF specific variables.\n\
25355 Configure DWARF variables such as the cache size"),
25356 &set_dwarf_cmdlist
, "maintenance set dwarf ",
25357 0/*allow-unknown*/, &maintenance_set_cmdlist
);
25359 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
25360 Show DWARF specific variables\n\
25361 Show DWARF variables such as the cache size"),
25362 &show_dwarf_cmdlist
, "maintenance show dwarf ",
25363 0/*allow-unknown*/, &maintenance_show_cmdlist
);
25365 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
25366 &dwarf_max_cache_age
, _("\
25367 Set the upper bound on the age of cached DWARF compilation units."), _("\
25368 Show the upper bound on the age of cached DWARF compilation units."), _("\
25369 A higher limit means that cached compilation units will be stored\n\
25370 in memory longer, and more total memory will be used. Zero disables\n\
25371 caching, which can slow down startup."),
25373 show_dwarf_max_cache_age
,
25374 &set_dwarf_cmdlist
,
25375 &show_dwarf_cmdlist
);
25377 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
25378 &dwarf_always_disassemble
, _("\
25379 Set whether `info address' always disassembles DWARF expressions."), _("\
25380 Show whether `info address' always disassembles DWARF expressions."), _("\
25381 When enabled, DWARF expressions are always printed in an assembly-like\n\
25382 syntax. When disabled, expressions will be printed in a more\n\
25383 conversational style, when possible."),
25385 show_dwarf_always_disassemble
,
25386 &set_dwarf_cmdlist
,
25387 &show_dwarf_cmdlist
);
25389 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
25390 Set debugging of the DWARF reader."), _("\
25391 Show debugging of the DWARF reader."), _("\
25392 When enabled (non-zero), debugging messages are printed during DWARF\n\
25393 reading and symtab expansion. A value of 1 (one) provides basic\n\
25394 information. A value greater than 1 provides more verbose information."),
25397 &setdebuglist
, &showdebuglist
);
25399 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
25400 Set debugging of the DWARF DIE reader."), _("\
25401 Show debugging of the DWARF DIE reader."), _("\
25402 When enabled (non-zero), DIEs are dumped after they are read in.\n\
25403 The value is the maximum depth to print."),
25406 &setdebuglist
, &showdebuglist
);
25408 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
25409 Set debugging of the dwarf line reader."), _("\
25410 Show debugging of the dwarf line reader."), _("\
25411 When enabled (non-zero), line number entries are dumped as they are read in.\n\
25412 A value of 1 (one) provides basic information.\n\
25413 A value greater than 1 provides more verbose information."),
25416 &setdebuglist
, &showdebuglist
);
25418 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
25419 Set cross-checking of \"physname\" code against demangler."), _("\
25420 Show cross-checking of \"physname\" code against demangler."), _("\
25421 When enabled, GDB's internal \"physname\" code is checked against\n\
25423 NULL
, show_check_physname
,
25424 &setdebuglist
, &showdebuglist
);
25426 add_setshow_boolean_cmd ("use-deprecated-index-sections",
25427 no_class
, &use_deprecated_index_sections
, _("\
25428 Set whether to use deprecated gdb_index sections."), _("\
25429 Show whether to use deprecated gdb_index sections."), _("\
25430 When enabled, deprecated .gdb_index sections are used anyway.\n\
25431 Normally they are ignored either because of a missing feature or\n\
25432 performance issue.\n\
25433 Warning: This option must be enabled before gdb reads the file."),
25436 &setlist
, &showlist
);
25438 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25439 &dwarf2_locexpr_funcs
);
25440 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25441 &dwarf2_loclist_funcs
);
25443 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25444 &dwarf2_block_frame_base_locexpr_funcs
);
25445 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25446 &dwarf2_block_frame_base_loclist_funcs
);
25449 selftests::register_test ("dw2_expand_symtabs_matching",
25450 selftests::dw2_expand_symtabs_matching::run_test
);