1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2017 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. */
40 #include "gdb-demangle.h"
41 #include "expression.h"
42 #include "filenames.h" /* for DOSish file names */
45 #include "complaints.h"
47 #include "dwarf2expr.h"
48 #include "dwarf2loc.h"
49 #include "cp-support.h"
55 #include "typeprint.h"
58 #include "completer.h"
63 #include "gdbcore.h" /* for gnutarget */
64 #include "gdb/gdb-index.h"
69 #include "filestuff.h"
71 #include "namespace.h"
72 #include "common/gdb_unlinker.h"
73 #include "common/function-view.h"
74 #include "common/gdb_optional.h"
75 #include "common/underlying.h"
76 #include "common/byte-vector.h"
77 #include "filename-seen-cache.h"
80 #include <sys/types.h>
82 #include <unordered_set>
83 #include <unordered_map>
86 /* When == 1, print basic high level tracing messages.
87 When > 1, be more verbose.
88 This is in contrast to the low level DIE reading of dwarf_die_debug. */
89 static unsigned int dwarf_read_debug
= 0;
91 /* When non-zero, dump DIEs after they are read in. */
92 static unsigned int dwarf_die_debug
= 0;
94 /* When non-zero, dump line number entries as they are read in. */
95 static unsigned int dwarf_line_debug
= 0;
97 /* When non-zero, cross-check physname against demangler. */
98 static int check_physname
= 0;
100 /* When non-zero, do not reject deprecated .gdb_index sections. */
101 static int use_deprecated_index_sections
= 0;
103 static const struct objfile_data
*dwarf2_objfile_data_key
;
105 /* The "aclass" indices for various kinds of computed DWARF symbols. */
107 static int dwarf2_locexpr_index
;
108 static int dwarf2_loclist_index
;
109 static int dwarf2_locexpr_block_index
;
110 static int dwarf2_loclist_block_index
;
112 /* A descriptor for dwarf sections.
114 S.ASECTION, SIZE are typically initialized when the objfile is first
115 scanned. BUFFER, READIN are filled in later when the section is read.
116 If the section contained compressed data then SIZE is updated to record
117 the uncompressed size of the section.
119 DWP file format V2 introduces a wrinkle that is easiest to handle by
120 creating the concept of virtual sections contained within a real section.
121 In DWP V2 the sections of the input DWO files are concatenated together
122 into one section, but section offsets are kept relative to the original
124 If this is a virtual dwp-v2 section, S.CONTAINING_SECTION is a backlink to
125 the real section this "virtual" section is contained in, and BUFFER,SIZE
126 describe the virtual section. */
128 struct dwarf2_section_info
132 /* If this is a real section, the bfd section. */
134 /* If this is a virtual section, pointer to the containing ("real")
136 struct dwarf2_section_info
*containing_section
;
138 /* Pointer to section data, only valid if readin. */
139 const gdb_byte
*buffer
;
140 /* The size of the section, real or virtual. */
142 /* If this is a virtual section, the offset in the real section.
143 Only valid if is_virtual. */
144 bfd_size_type virtual_offset
;
145 /* True if we have tried to read this section. */
147 /* True if this is a virtual section, False otherwise.
148 This specifies which of s.section and s.containing_section to use. */
152 typedef struct dwarf2_section_info dwarf2_section_info_def
;
153 DEF_VEC_O (dwarf2_section_info_def
);
155 /* All offsets in the index are of this type. It must be
156 architecture-independent. */
157 typedef uint32_t offset_type
;
159 DEF_VEC_I (offset_type
);
161 /* Ensure only legit values are used. */
162 #define DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \
164 gdb_assert ((unsigned int) (value) <= 1); \
165 GDB_INDEX_SYMBOL_STATIC_SET_VALUE((cu_index), (value)); \
168 /* Ensure only legit values are used. */
169 #define DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \
171 gdb_assert ((value) >= GDB_INDEX_SYMBOL_KIND_TYPE \
172 && (value) <= GDB_INDEX_SYMBOL_KIND_OTHER); \
173 GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \
176 /* Ensure we don't use more than the alloted nuber of bits for the CU. */
177 #define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \
179 gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \
180 GDB_INDEX_CU_SET_VALUE((cu_index), (value)); \
185 /* Convert VALUE between big- and little-endian. */
188 byte_swap (offset_type value
)
192 result
= (value
& 0xff) << 24;
193 result
|= (value
& 0xff00) << 8;
194 result
|= (value
& 0xff0000) >> 8;
195 result
|= (value
& 0xff000000) >> 24;
199 #define MAYBE_SWAP(V) byte_swap (V)
202 #define MAYBE_SWAP(V) static_cast<offset_type> (V)
203 #endif /* WORDS_BIGENDIAN */
205 /* An index into a (C++) symbol name component in a symbol name as
206 recorded in the mapped_index's symbol table. For each C++ symbol
207 in the symbol table, we record one entry for the start of each
208 component in the symbol in a table of name components, and then
209 sort the table, in order to be able to binary search symbol names,
210 ignoring leading namespaces, both completion and regular look up.
211 For example, for symbol "A::B::C", we'll have an entry that points
212 to "A::B::C", another that points to "B::C", and another for "C".
213 Note that function symbols in GDB index have no parameter
214 information, just the function/method names. You can convert a
215 name_component to a "const char *" using the
216 'mapped_index::symbol_name_at(offset_type)' method. */
218 struct name_component
220 /* Offset in the symbol name where the component starts. Stored as
221 a (32-bit) offset instead of a pointer to save memory and improve
222 locality on 64-bit architectures. */
223 offset_type name_offset
;
225 /* The symbol's index in the symbol and constant pool tables of a
230 /* A description of the mapped index. The file format is described in
231 a comment by the code that writes the index. */
234 /* Index data format version. */
237 /* The total length of the buffer. */
240 /* A pointer to the address table data. */
241 const gdb_byte
*address_table
;
243 /* Size of the address table data in bytes. */
244 offset_type address_table_size
;
246 /* The symbol table, implemented as a hash table. */
247 const offset_type
*symbol_table
;
249 /* Size in slots, each slot is 2 offset_types. */
250 offset_type symbol_table_slots
;
252 /* A pointer to the constant pool. */
253 const char *constant_pool
;
255 /* The name_component table (a sorted vector). See name_component's
256 description above. */
257 std::vector
<name_component
> name_components
;
259 /* Convenience method to get at the name of the symbol at IDX in the
261 const char *symbol_name_at (offset_type idx
) const
262 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
]); }
265 typedef struct dwarf2_per_cu_data
*dwarf2_per_cu_ptr
;
266 DEF_VEC_P (dwarf2_per_cu_ptr
);
270 int nr_uniq_abbrev_tables
;
272 int nr_symtab_sharers
;
273 int nr_stmt_less_type_units
;
274 int nr_all_type_units_reallocs
;
277 /* Collection of data recorded per objfile.
278 This hangs off of dwarf2_objfile_data_key. */
280 struct dwarf2_per_objfile
282 /* Construct a dwarf2_per_objfile for OBJFILE. NAMES points to the
283 dwarf2 section names, or is NULL if the standard ELF names are
285 dwarf2_per_objfile (struct objfile
*objfile
,
286 const dwarf2_debug_sections
*names
);
288 ~dwarf2_per_objfile ();
290 DISABLE_COPY_AND_ASSIGN (dwarf2_per_objfile
);
292 /* Free all cached compilation units. */
293 void free_cached_comp_units ();
295 /* This function is mapped across the sections and remembers the
296 offset and size of each of the debugging sections we are
298 void locate_sections (bfd
*abfd
, asection
*sectp
,
299 const dwarf2_debug_sections
&names
);
302 dwarf2_section_info info
{};
303 dwarf2_section_info abbrev
{};
304 dwarf2_section_info line
{};
305 dwarf2_section_info loc
{};
306 dwarf2_section_info loclists
{};
307 dwarf2_section_info macinfo
{};
308 dwarf2_section_info macro
{};
309 dwarf2_section_info str
{};
310 dwarf2_section_info line_str
{};
311 dwarf2_section_info ranges
{};
312 dwarf2_section_info rnglists
{};
313 dwarf2_section_info addr
{};
314 dwarf2_section_info frame
{};
315 dwarf2_section_info eh_frame
{};
316 dwarf2_section_info gdb_index
{};
318 VEC (dwarf2_section_info_def
) *types
= NULL
;
321 struct objfile
*objfile
= NULL
;
323 /* Table of all the compilation units. This is used to locate
324 the target compilation unit of a particular reference. */
325 struct dwarf2_per_cu_data
**all_comp_units
= NULL
;
327 /* The number of compilation units in ALL_COMP_UNITS. */
328 int n_comp_units
= 0;
330 /* The number of .debug_types-related CUs. */
331 int n_type_units
= 0;
333 /* The number of elements allocated in all_type_units.
334 If there are skeleton-less TUs, we add them to all_type_units lazily. */
335 int n_allocated_type_units
= 0;
337 /* The .debug_types-related CUs (TUs).
338 This is stored in malloc space because we may realloc it. */
339 struct signatured_type
**all_type_units
= NULL
;
341 /* Table of struct type_unit_group objects.
342 The hash key is the DW_AT_stmt_list value. */
343 htab_t type_unit_groups
{};
345 /* A table mapping .debug_types signatures to its signatured_type entry.
346 This is NULL if the .debug_types section hasn't been read in yet. */
347 htab_t signatured_types
{};
349 /* Type unit statistics, to see how well the scaling improvements
351 struct tu_stats tu_stats
{};
353 /* A chain of compilation units that are currently read in, so that
354 they can be freed later. */
355 dwarf2_per_cu_data
*read_in_chain
= NULL
;
357 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
358 This is NULL if the table hasn't been allocated yet. */
361 /* True if we've checked for whether there is a DWP file. */
362 bool dwp_checked
= false;
364 /* The DWP file if there is one, or NULL. */
365 struct dwp_file
*dwp_file
= NULL
;
367 /* The shared '.dwz' file, if one exists. This is used when the
368 original data was compressed using 'dwz -m'. */
369 struct dwz_file
*dwz_file
= NULL
;
371 /* A flag indicating whether this objfile has a section loaded at a
373 bool has_section_at_zero
= false;
375 /* True if we are using the mapped index,
376 or we are faking it for OBJF_READNOW's sake. */
377 bool using_index
= false;
379 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
380 mapped_index
*index_table
= NULL
;
382 /* When using index_table, this keeps track of all quick_file_names entries.
383 TUs typically share line table entries with a CU, so we maintain a
384 separate table of all line table entries to support the sharing.
385 Note that while there can be way more TUs than CUs, we've already
386 sorted all the TUs into "type unit groups", grouped by their
387 DW_AT_stmt_list value. Therefore the only sharing done here is with a
388 CU and its associated TU group if there is one. */
389 htab_t quick_file_names_table
{};
391 /* Set during partial symbol reading, to prevent queueing of full
393 bool reading_partial_symbols
= false;
395 /* Table mapping type DIEs to their struct type *.
396 This is NULL if not allocated yet.
397 The mapping is done via (CU/TU + DIE offset) -> type. */
398 htab_t die_type_hash
{};
400 /* The CUs we recently read. */
401 VEC (dwarf2_per_cu_ptr
) *just_read_cus
= NULL
;
403 /* Table containing line_header indexed by offset and offset_in_dwz. */
404 htab_t line_header_hash
{};
406 /* Table containing all filenames. This is an optional because the
407 table is lazily constructed on first access. */
408 gdb::optional
<filename_seen_cache
> filenames_cache
;
411 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
413 /* Default names of the debugging sections. */
415 /* Note that if the debugging section has been compressed, it might
416 have a name like .zdebug_info. */
418 static const struct dwarf2_debug_sections dwarf2_elf_names
=
420 { ".debug_info", ".zdebug_info" },
421 { ".debug_abbrev", ".zdebug_abbrev" },
422 { ".debug_line", ".zdebug_line" },
423 { ".debug_loc", ".zdebug_loc" },
424 { ".debug_loclists", ".zdebug_loclists" },
425 { ".debug_macinfo", ".zdebug_macinfo" },
426 { ".debug_macro", ".zdebug_macro" },
427 { ".debug_str", ".zdebug_str" },
428 { ".debug_line_str", ".zdebug_line_str" },
429 { ".debug_ranges", ".zdebug_ranges" },
430 { ".debug_rnglists", ".zdebug_rnglists" },
431 { ".debug_types", ".zdebug_types" },
432 { ".debug_addr", ".zdebug_addr" },
433 { ".debug_frame", ".zdebug_frame" },
434 { ".eh_frame", NULL
},
435 { ".gdb_index", ".zgdb_index" },
439 /* List of DWO/DWP sections. */
441 static const struct dwop_section_names
443 struct dwarf2_section_names abbrev_dwo
;
444 struct dwarf2_section_names info_dwo
;
445 struct dwarf2_section_names line_dwo
;
446 struct dwarf2_section_names loc_dwo
;
447 struct dwarf2_section_names loclists_dwo
;
448 struct dwarf2_section_names macinfo_dwo
;
449 struct dwarf2_section_names macro_dwo
;
450 struct dwarf2_section_names str_dwo
;
451 struct dwarf2_section_names str_offsets_dwo
;
452 struct dwarf2_section_names types_dwo
;
453 struct dwarf2_section_names cu_index
;
454 struct dwarf2_section_names tu_index
;
458 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
459 { ".debug_info.dwo", ".zdebug_info.dwo" },
460 { ".debug_line.dwo", ".zdebug_line.dwo" },
461 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
462 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
463 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
464 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
465 { ".debug_str.dwo", ".zdebug_str.dwo" },
466 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
467 { ".debug_types.dwo", ".zdebug_types.dwo" },
468 { ".debug_cu_index", ".zdebug_cu_index" },
469 { ".debug_tu_index", ".zdebug_tu_index" },
472 /* local data types */
474 /* The data in a compilation unit header, after target2host
475 translation, looks like this. */
476 struct comp_unit_head
480 unsigned char addr_size
;
481 unsigned char signed_addr_p
;
482 sect_offset abbrev_sect_off
;
484 /* Size of file offsets; either 4 or 8. */
485 unsigned int offset_size
;
487 /* Size of the length field; either 4 or 12. */
488 unsigned int initial_length_size
;
490 enum dwarf_unit_type unit_type
;
492 /* Offset to the first byte of this compilation unit header in the
493 .debug_info section, for resolving relative reference dies. */
494 sect_offset sect_off
;
496 /* Offset to first die in this cu from the start of the cu.
497 This will be the first byte following the compilation unit header. */
498 cu_offset first_die_cu_offset
;
500 /* 64-bit signature of this type unit - it is valid only for
501 UNIT_TYPE DW_UT_type. */
504 /* For types, offset in the type's DIE of the type defined by this TU. */
505 cu_offset type_cu_offset_in_tu
;
508 /* Type used for delaying computation of method physnames.
509 See comments for compute_delayed_physnames. */
510 struct delayed_method_info
512 /* The type to which the method is attached, i.e., its parent class. */
515 /* The index of the method in the type's function fieldlists. */
518 /* The index of the method in the fieldlist. */
521 /* The name of the DIE. */
524 /* The DIE associated with this method. */
525 struct die_info
*die
;
528 typedef struct delayed_method_info delayed_method_info
;
529 DEF_VEC_O (delayed_method_info
);
531 /* Internal state when decoding a particular compilation unit. */
534 /* The objfile containing this compilation unit. */
535 struct objfile
*objfile
;
537 /* The header of the compilation unit. */
538 struct comp_unit_head header
;
540 /* Base address of this compilation unit. */
541 CORE_ADDR base_address
;
543 /* Non-zero if base_address has been set. */
546 /* The language we are debugging. */
547 enum language language
;
548 const struct language_defn
*language_defn
;
550 const char *producer
;
552 /* The generic symbol table building routines have separate lists for
553 file scope symbols and all all other scopes (local scopes). So
554 we need to select the right one to pass to add_symbol_to_list().
555 We do it by keeping a pointer to the correct list in list_in_scope.
557 FIXME: The original dwarf code just treated the file scope as the
558 first local scope, and all other local scopes as nested local
559 scopes, and worked fine. Check to see if we really need to
560 distinguish these in buildsym.c. */
561 struct pending
**list_in_scope
;
563 /* The abbrev table for this CU.
564 Normally this points to the abbrev table in the objfile.
565 But if DWO_UNIT is non-NULL this is the abbrev table in the DWO file. */
566 struct abbrev_table
*abbrev_table
;
568 /* Hash table holding all the loaded partial DIEs
569 with partial_die->offset.SECT_OFF as hash. */
572 /* Storage for things with the same lifetime as this read-in compilation
573 unit, including partial DIEs. */
574 struct obstack comp_unit_obstack
;
576 /* When multiple dwarf2_cu structures are living in memory, this field
577 chains them all together, so that they can be released efficiently.
578 We will probably also want a generation counter so that most-recently-used
579 compilation units are cached... */
580 struct dwarf2_per_cu_data
*read_in_chain
;
582 /* Backlink to our per_cu entry. */
583 struct dwarf2_per_cu_data
*per_cu
;
585 /* How many compilation units ago was this CU last referenced? */
588 /* A hash table of DIE cu_offset for following references with
589 die_info->offset.sect_off as hash. */
592 /* Full DIEs if read in. */
593 struct die_info
*dies
;
595 /* A set of pointers to dwarf2_per_cu_data objects for compilation
596 units referenced by this one. Only set during full symbol processing;
597 partial symbol tables do not have dependencies. */
600 /* Header data from the line table, during full symbol processing. */
601 struct line_header
*line_header
;
602 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
603 it's owned by dwarf2_per_objfile::line_header_hash. If non-NULL,
604 this is the DW_TAG_compile_unit die for this CU. We'll hold on
605 to the line header as long as this DIE is being processed. See
606 process_die_scope. */
607 die_info
*line_header_die_owner
;
609 /* A list of methods which need to have physnames computed
610 after all type information has been read. */
611 VEC (delayed_method_info
) *method_list
;
613 /* To be copied to symtab->call_site_htab. */
614 htab_t call_site_htab
;
616 /* Non-NULL if this CU came from a DWO file.
617 There is an invariant here that is important to remember:
618 Except for attributes copied from the top level DIE in the "main"
619 (or "stub") file in preparation for reading the DWO file
620 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
621 Either there isn't a DWO file (in which case this is NULL and the point
622 is moot), or there is and either we're not going to read it (in which
623 case this is NULL) or there is and we are reading it (in which case this
625 struct dwo_unit
*dwo_unit
;
627 /* The DW_AT_addr_base attribute if present, zero otherwise
628 (zero is a valid value though).
629 Note this value comes from the Fission stub CU/TU's DIE. */
632 /* The DW_AT_ranges_base attribute if present, zero otherwise
633 (zero is a valid value though).
634 Note this value comes from the Fission stub CU/TU's DIE.
635 Also note that the value is zero in the non-DWO case so this value can
636 be used without needing to know whether DWO files are in use or not.
637 N.B. This does not apply to DW_AT_ranges appearing in
638 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
639 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
640 DW_AT_ranges_base *would* have to be applied, and we'd have to care
641 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
642 ULONGEST ranges_base
;
644 /* Mark used when releasing cached dies. */
645 unsigned int mark
: 1;
647 /* This CU references .debug_loc. See the symtab->locations_valid field.
648 This test is imperfect as there may exist optimized debug code not using
649 any location list and still facing inlining issues if handled as
650 unoptimized code. For a future better test see GCC PR other/32998. */
651 unsigned int has_loclist
: 1;
653 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is set
654 if all the producer_is_* fields are valid. This information is cached
655 because profiling CU expansion showed excessive time spent in
656 producer_is_gxx_lt_4_6. */
657 unsigned int checked_producer
: 1;
658 unsigned int producer_is_gxx_lt_4_6
: 1;
659 unsigned int producer_is_gcc_lt_4_3
: 1;
660 unsigned int producer_is_icc_lt_14
: 1;
662 /* When set, the file that we're processing is known to have
663 debugging info for C++ namespaces. GCC 3.3.x did not produce
664 this information, but later versions do. */
666 unsigned int processing_has_namespace_info
: 1;
669 /* Persistent data held for a compilation unit, even when not
670 processing it. We put a pointer to this structure in the
671 read_symtab_private field of the psymtab. */
673 struct dwarf2_per_cu_data
675 /* The start offset and length of this compilation unit.
676 NOTE: Unlike comp_unit_head.length, this length includes
678 If the DIE refers to a DWO file, this is always of the original die,
680 sect_offset sect_off
;
683 /* DWARF standard version this data has been read from (such as 4 or 5). */
686 /* Flag indicating this compilation unit will be read in before
687 any of the current compilation units are processed. */
688 unsigned int queued
: 1;
690 /* This flag will be set when reading partial DIEs if we need to load
691 absolutely all DIEs for this compilation unit, instead of just the ones
692 we think are interesting. It gets set if we look for a DIE in the
693 hash table and don't find it. */
694 unsigned int load_all_dies
: 1;
696 /* Non-zero if this CU is from .debug_types.
697 Struct dwarf2_per_cu_data is contained in struct signatured_type iff
699 unsigned int is_debug_types
: 1;
701 /* Non-zero if this CU is from the .dwz file. */
702 unsigned int is_dwz
: 1;
704 /* Non-zero if reading a TU directly from a DWO file, bypassing the stub.
705 This flag is only valid if is_debug_types is true.
706 We can't read a CU directly from a DWO file: There are required
707 attributes in the stub. */
708 unsigned int reading_dwo_directly
: 1;
710 /* Non-zero if the TU has been read.
711 This is used to assist the "Stay in DWO Optimization" for Fission:
712 When reading a DWO, it's faster to read TUs from the DWO instead of
713 fetching them from random other DWOs (due to comdat folding).
714 If the TU has already been read, the optimization is unnecessary
715 (and unwise - we don't want to change where gdb thinks the TU lives
717 This flag is only valid if is_debug_types is true. */
718 unsigned int tu_read
: 1;
720 /* The section this CU/TU lives in.
721 If the DIE refers to a DWO file, this is always the original die,
723 struct dwarf2_section_info
*section
;
725 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
726 of the CU cache it gets reset to NULL again. This is left as NULL for
727 dummy CUs (a CU header, but nothing else). */
728 struct dwarf2_cu
*cu
;
730 /* The corresponding objfile.
731 Normally we can get the objfile from dwarf2_per_objfile.
732 However we can enter this file with just a "per_cu" handle. */
733 struct objfile
*objfile
;
735 /* When dwarf2_per_objfile->using_index is true, the 'quick' field
736 is active. Otherwise, the 'psymtab' field is active. */
739 /* The partial symbol table associated with this compilation unit,
740 or NULL for unread partial units. */
741 struct partial_symtab
*psymtab
;
743 /* Data needed by the "quick" functions. */
744 struct dwarf2_per_cu_quick_data
*quick
;
747 /* The CUs we import using DW_TAG_imported_unit. This is filled in
748 while reading psymtabs, used to compute the psymtab dependencies,
749 and then cleared. Then it is filled in again while reading full
750 symbols, and only deleted when the objfile is destroyed.
752 This is also used to work around a difference between the way gold
753 generates .gdb_index version <=7 and the way gdb does. Arguably this
754 is a gold bug. For symbols coming from TUs, gold records in the index
755 the CU that includes the TU instead of the TU itself. This breaks
756 dw2_lookup_symbol: It assumes that if the index says symbol X lives
757 in CU/TU Y, then one need only expand Y and a subsequent lookup in Y
758 will find X. Alas TUs live in their own symtab, so after expanding CU Y
759 we need to look in TU Z to find X. Fortunately, this is akin to
760 DW_TAG_imported_unit, so we just use the same mechanism: For
761 .gdb_index version <=7 this also records the TUs that the CU referred
762 to. Concurrently with this change gdb was modified to emit version 8
763 indices so we only pay a price for gold generated indices.
764 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
765 VEC (dwarf2_per_cu_ptr
) *imported_symtabs
;
768 /* Entry in the signatured_types hash table. */
770 struct signatured_type
772 /* The "per_cu" object of this type.
773 This struct is used iff per_cu.is_debug_types.
774 N.B.: This is the first member so that it's easy to convert pointers
776 struct dwarf2_per_cu_data per_cu
;
778 /* The type's signature. */
781 /* Offset in the TU of the type's DIE, as read from the TU header.
782 If this TU is a DWO stub and the definition lives in a DWO file
783 (specified by DW_AT_GNU_dwo_name), this value is unusable. */
784 cu_offset type_offset_in_tu
;
786 /* Offset in the section of the type's DIE.
787 If the definition lives in a DWO file, this is the offset in the
788 .debug_types.dwo section.
789 The value is zero until the actual value is known.
790 Zero is otherwise not a valid section offset. */
791 sect_offset type_offset_in_section
;
793 /* Type units are grouped by their DW_AT_stmt_list entry so that they
794 can share them. This points to the containing symtab. */
795 struct type_unit_group
*type_unit_group
;
798 The first time we encounter this type we fully read it in and install it
799 in the symbol tables. Subsequent times we only need the type. */
802 /* Containing DWO unit.
803 This field is valid iff per_cu.reading_dwo_directly. */
804 struct dwo_unit
*dwo_unit
;
807 typedef struct signatured_type
*sig_type_ptr
;
808 DEF_VEC_P (sig_type_ptr
);
810 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
811 This includes type_unit_group and quick_file_names. */
813 struct stmt_list_hash
815 /* The DWO unit this table is from or NULL if there is none. */
816 struct dwo_unit
*dwo_unit
;
818 /* Offset in .debug_line or .debug_line.dwo. */
819 sect_offset line_sect_off
;
822 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
823 an object of this type. */
825 struct type_unit_group
827 /* dwarf2read.c's main "handle" on a TU symtab.
828 To simplify things we create an artificial CU that "includes" all the
829 type units using this stmt_list so that the rest of the code still has
830 a "per_cu" handle on the symtab.
831 This PER_CU is recognized by having no section. */
832 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->section == NULL)
833 struct dwarf2_per_cu_data per_cu
;
835 /* The TUs that share this DW_AT_stmt_list entry.
836 This is added to while parsing type units to build partial symtabs,
837 and is deleted afterwards and not used again. */
838 VEC (sig_type_ptr
) *tus
;
840 /* The compunit symtab.
841 Type units in a group needn't all be defined in the same source file,
842 so we create an essentially anonymous symtab as the compunit symtab. */
843 struct compunit_symtab
*compunit_symtab
;
845 /* The data used to construct the hash key. */
846 struct stmt_list_hash hash
;
848 /* The number of symtabs from the line header.
849 The value here must match line_header.num_file_names. */
850 unsigned int num_symtabs
;
852 /* The symbol tables for this TU (obtained from the files listed in
854 WARNING: The order of entries here must match the order of entries
855 in the line header. After the first TU using this type_unit_group, the
856 line header for the subsequent TUs is recreated from this. This is done
857 because we need to use the same symtabs for each TU using the same
858 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
859 there's no guarantee the line header doesn't have duplicate entries. */
860 struct symtab
**symtabs
;
863 /* These sections are what may appear in a (real or virtual) DWO file. */
867 struct dwarf2_section_info abbrev
;
868 struct dwarf2_section_info line
;
869 struct dwarf2_section_info loc
;
870 struct dwarf2_section_info loclists
;
871 struct dwarf2_section_info macinfo
;
872 struct dwarf2_section_info macro
;
873 struct dwarf2_section_info str
;
874 struct dwarf2_section_info str_offsets
;
875 /* In the case of a virtual DWO file, these two are unused. */
876 struct dwarf2_section_info info
;
877 VEC (dwarf2_section_info_def
) *types
;
880 /* CUs/TUs in DWP/DWO files. */
884 /* Backlink to the containing struct dwo_file. */
885 struct dwo_file
*dwo_file
;
887 /* The "id" that distinguishes this CU/TU.
888 .debug_info calls this "dwo_id", .debug_types calls this "signature".
889 Since signatures came first, we stick with it for consistency. */
892 /* The section this CU/TU lives in, in the DWO file. */
893 struct dwarf2_section_info
*section
;
895 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
896 sect_offset sect_off
;
899 /* For types, offset in the type's DIE of the type defined by this TU. */
900 cu_offset type_offset_in_tu
;
903 /* include/dwarf2.h defines the DWP section codes.
904 It defines a max value but it doesn't define a min value, which we
905 use for error checking, so provide one. */
907 enum dwp_v2_section_ids
912 /* Data for one DWO file.
914 This includes virtual DWO files (a virtual DWO file is a DWO file as it
915 appears in a DWP file). DWP files don't really have DWO files per se -
916 comdat folding of types "loses" the DWO file they came from, and from
917 a high level view DWP files appear to contain a mass of random types.
918 However, to maintain consistency with the non-DWP case we pretend DWP
919 files contain virtual DWO files, and we assign each TU with one virtual
920 DWO file (generally based on the line and abbrev section offsets -
921 a heuristic that seems to work in practice). */
925 /* The DW_AT_GNU_dwo_name attribute.
926 For virtual DWO files the name is constructed from the section offsets
927 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
928 from related CU+TUs. */
929 const char *dwo_name
;
931 /* The DW_AT_comp_dir attribute. */
932 const char *comp_dir
;
934 /* The bfd, when the file is open. Otherwise this is NULL.
935 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
938 /* The sections that make up this DWO file.
939 Remember that for virtual DWO files in DWP V2, these are virtual
940 sections (for lack of a better name). */
941 struct dwo_sections sections
;
943 /* The CUs in the file.
944 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
945 an extension to handle LLVM's Link Time Optimization output (where
946 multiple source files may be compiled into a single object/dwo pair). */
949 /* Table of TUs in the file.
950 Each element is a struct dwo_unit. */
954 /* These sections are what may appear in a DWP file. */
958 /* These are used by both DWP version 1 and 2. */
959 struct dwarf2_section_info str
;
960 struct dwarf2_section_info cu_index
;
961 struct dwarf2_section_info tu_index
;
963 /* These are only used by DWP version 2 files.
964 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
965 sections are referenced by section number, and are not recorded here.
966 In DWP version 2 there is at most one copy of all these sections, each
967 section being (effectively) comprised of the concatenation of all of the
968 individual sections that exist in the version 1 format.
969 To keep the code simple we treat each of these concatenated pieces as a
970 section itself (a virtual section?). */
971 struct dwarf2_section_info abbrev
;
972 struct dwarf2_section_info info
;
973 struct dwarf2_section_info line
;
974 struct dwarf2_section_info loc
;
975 struct dwarf2_section_info macinfo
;
976 struct dwarf2_section_info macro
;
977 struct dwarf2_section_info str_offsets
;
978 struct dwarf2_section_info types
;
981 /* These sections are what may appear in a virtual DWO file in DWP version 1.
982 A virtual DWO file is a DWO file as it appears in a DWP file. */
984 struct virtual_v1_dwo_sections
986 struct dwarf2_section_info abbrev
;
987 struct dwarf2_section_info line
;
988 struct dwarf2_section_info loc
;
989 struct dwarf2_section_info macinfo
;
990 struct dwarf2_section_info macro
;
991 struct dwarf2_section_info str_offsets
;
992 /* Each DWP hash table entry records one CU or one TU.
993 That is recorded here, and copied to dwo_unit.section. */
994 struct dwarf2_section_info info_or_types
;
997 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
998 In version 2, the sections of the DWO files are concatenated together
999 and stored in one section of that name. Thus each ELF section contains
1000 several "virtual" sections. */
1002 struct virtual_v2_dwo_sections
1004 bfd_size_type abbrev_offset
;
1005 bfd_size_type abbrev_size
;
1007 bfd_size_type line_offset
;
1008 bfd_size_type line_size
;
1010 bfd_size_type loc_offset
;
1011 bfd_size_type loc_size
;
1013 bfd_size_type macinfo_offset
;
1014 bfd_size_type macinfo_size
;
1016 bfd_size_type macro_offset
;
1017 bfd_size_type macro_size
;
1019 bfd_size_type str_offsets_offset
;
1020 bfd_size_type str_offsets_size
;
1022 /* Each DWP hash table entry records one CU or one TU.
1023 That is recorded here, and copied to dwo_unit.section. */
1024 bfd_size_type info_or_types_offset
;
1025 bfd_size_type info_or_types_size
;
1028 /* Contents of DWP hash tables. */
1030 struct dwp_hash_table
1032 uint32_t version
, nr_columns
;
1033 uint32_t nr_units
, nr_slots
;
1034 const gdb_byte
*hash_table
, *unit_table
;
1039 const gdb_byte
*indices
;
1043 /* This is indexed by column number and gives the id of the section
1045 #define MAX_NR_V2_DWO_SECTIONS \
1046 (1 /* .debug_info or .debug_types */ \
1047 + 1 /* .debug_abbrev */ \
1048 + 1 /* .debug_line */ \
1049 + 1 /* .debug_loc */ \
1050 + 1 /* .debug_str_offsets */ \
1051 + 1 /* .debug_macro or .debug_macinfo */)
1052 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
1053 const gdb_byte
*offsets
;
1054 const gdb_byte
*sizes
;
1059 /* Data for one DWP file. */
1063 /* Name of the file. */
1066 /* File format version. */
1072 /* Section info for this file. */
1073 struct dwp_sections sections
;
1075 /* Table of CUs in the file. */
1076 const struct dwp_hash_table
*cus
;
1078 /* Table of TUs in the file. */
1079 const struct dwp_hash_table
*tus
;
1081 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
1085 /* Table to map ELF section numbers to their sections.
1086 This is only needed for the DWP V1 file format. */
1087 unsigned int num_sections
;
1088 asection
**elf_sections
;
1091 /* This represents a '.dwz' file. */
1095 /* A dwz file can only contain a few sections. */
1096 struct dwarf2_section_info abbrev
;
1097 struct dwarf2_section_info info
;
1098 struct dwarf2_section_info str
;
1099 struct dwarf2_section_info line
;
1100 struct dwarf2_section_info macro
;
1101 struct dwarf2_section_info gdb_index
;
1103 /* The dwz's BFD. */
1107 /* Struct used to pass misc. parameters to read_die_and_children, et
1108 al. which are used for both .debug_info and .debug_types dies.
1109 All parameters here are unchanging for the life of the call. This
1110 struct exists to abstract away the constant parameters of die reading. */
1112 struct die_reader_specs
1114 /* The bfd of die_section. */
1117 /* The CU of the DIE we are parsing. */
1118 struct dwarf2_cu
*cu
;
1120 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
1121 struct dwo_file
*dwo_file
;
1123 /* The section the die comes from.
1124 This is either .debug_info or .debug_types, or the .dwo variants. */
1125 struct dwarf2_section_info
*die_section
;
1127 /* die_section->buffer. */
1128 const gdb_byte
*buffer
;
1130 /* The end of the buffer. */
1131 const gdb_byte
*buffer_end
;
1133 /* The value of the DW_AT_comp_dir attribute. */
1134 const char *comp_dir
;
1137 /* Type of function passed to init_cutu_and_read_dies, et.al. */
1138 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
1139 const gdb_byte
*info_ptr
,
1140 struct die_info
*comp_unit_die
,
1144 /* A 1-based directory index. This is a strong typedef to prevent
1145 accidentally using a directory index as a 0-based index into an
1147 enum class dir_index
: unsigned int {};
1149 /* Likewise, a 1-based file name index. */
1150 enum class file_name_index
: unsigned int {};
1154 file_entry () = default;
1156 file_entry (const char *name_
, dir_index d_index_
,
1157 unsigned int mod_time_
, unsigned int length_
)
1160 mod_time (mod_time_
),
1164 /* Return the include directory at D_INDEX stored in LH. Returns
1165 NULL if D_INDEX is out of bounds. */
1166 const char *include_dir (const line_header
*lh
) const;
1168 /* The file name. Note this is an observing pointer. The memory is
1169 owned by debug_line_buffer. */
1170 const char *name
{};
1172 /* The directory index (1-based). */
1173 dir_index d_index
{};
1175 unsigned int mod_time
{};
1177 unsigned int length
{};
1179 /* True if referenced by the Line Number Program. */
1182 /* The associated symbol table, if any. */
1183 struct symtab
*symtab
{};
1186 /* The line number information for a compilation unit (found in the
1187 .debug_line section) begins with a "statement program header",
1188 which contains the following information. */
1195 /* Add an entry to the include directory table. */
1196 void add_include_dir (const char *include_dir
);
1198 /* Add an entry to the file name table. */
1199 void add_file_name (const char *name
, dir_index d_index
,
1200 unsigned int mod_time
, unsigned int length
);
1202 /* Return the include dir at INDEX (1-based). Returns NULL if INDEX
1203 is out of bounds. */
1204 const char *include_dir_at (dir_index index
) const
1206 /* Convert directory index number (1-based) to vector index
1208 size_t vec_index
= to_underlying (index
) - 1;
1210 if (vec_index
>= include_dirs
.size ())
1212 return include_dirs
[vec_index
];
1215 /* Return the file name at INDEX (1-based). Returns NULL if INDEX
1216 is out of bounds. */
1217 file_entry
*file_name_at (file_name_index index
)
1219 /* Convert file name index number (1-based) to vector index
1221 size_t vec_index
= to_underlying (index
) - 1;
1223 if (vec_index
>= file_names
.size ())
1225 return &file_names
[vec_index
];
1228 /* Const version of the above. */
1229 const file_entry
*file_name_at (unsigned int index
) const
1231 if (index
>= file_names
.size ())
1233 return &file_names
[index
];
1236 /* Offset of line number information in .debug_line section. */
1237 sect_offset sect_off
{};
1239 /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile. */
1240 unsigned offset_in_dwz
: 1; /* Can't initialize bitfields in-class. */
1242 unsigned int total_length
{};
1243 unsigned short version
{};
1244 unsigned int header_length
{};
1245 unsigned char minimum_instruction_length
{};
1246 unsigned char maximum_ops_per_instruction
{};
1247 unsigned char default_is_stmt
{};
1249 unsigned char line_range
{};
1250 unsigned char opcode_base
{};
1252 /* standard_opcode_lengths[i] is the number of operands for the
1253 standard opcode whose value is i. This means that
1254 standard_opcode_lengths[0] is unused, and the last meaningful
1255 element is standard_opcode_lengths[opcode_base - 1]. */
1256 std::unique_ptr
<unsigned char[]> standard_opcode_lengths
;
1258 /* The include_directories table. Note these are observing
1259 pointers. The memory is owned by debug_line_buffer. */
1260 std::vector
<const char *> include_dirs
;
1262 /* The file_names table. */
1263 std::vector
<file_entry
> file_names
;
1265 /* The start and end of the statement program following this
1266 header. These point into dwarf2_per_objfile->line_buffer. */
1267 const gdb_byte
*statement_program_start
{}, *statement_program_end
{};
1270 typedef std::unique_ptr
<line_header
> line_header_up
;
1273 file_entry::include_dir (const line_header
*lh
) const
1275 return lh
->include_dir_at (d_index
);
1278 /* When we construct a partial symbol table entry we only
1279 need this much information. */
1280 struct partial_die_info
1282 /* Offset of this DIE. */
1283 sect_offset sect_off
;
1285 /* DWARF-2 tag for this DIE. */
1286 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1288 /* Assorted flags describing the data found in this DIE. */
1289 unsigned int has_children
: 1;
1290 unsigned int is_external
: 1;
1291 unsigned int is_declaration
: 1;
1292 unsigned int has_type
: 1;
1293 unsigned int has_specification
: 1;
1294 unsigned int has_pc_info
: 1;
1295 unsigned int may_be_inlined
: 1;
1297 /* This DIE has been marked DW_AT_main_subprogram. */
1298 unsigned int main_subprogram
: 1;
1300 /* Flag set if the SCOPE field of this structure has been
1302 unsigned int scope_set
: 1;
1304 /* Flag set if the DIE has a byte_size attribute. */
1305 unsigned int has_byte_size
: 1;
1307 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1308 unsigned int has_const_value
: 1;
1310 /* Flag set if any of the DIE's children are template arguments. */
1311 unsigned int has_template_arguments
: 1;
1313 /* Flag set if fixup_partial_die has been called on this die. */
1314 unsigned int fixup_called
: 1;
1316 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1317 unsigned int is_dwz
: 1;
1319 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1320 unsigned int spec_is_dwz
: 1;
1322 /* The name of this DIE. Normally the value of DW_AT_name, but
1323 sometimes a default name for unnamed DIEs. */
1326 /* The linkage name, if present. */
1327 const char *linkage_name
;
1329 /* The scope to prepend to our children. This is generally
1330 allocated on the comp_unit_obstack, so will disappear
1331 when this compilation unit leaves the cache. */
1334 /* Some data associated with the partial DIE. The tag determines
1335 which field is live. */
1338 /* The location description associated with this DIE, if any. */
1339 struct dwarf_block
*locdesc
;
1340 /* The offset of an import, for DW_TAG_imported_unit. */
1341 sect_offset sect_off
;
1344 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1348 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1349 DW_AT_sibling, if any. */
1350 /* NOTE: This member isn't strictly necessary, read_partial_die could
1351 return DW_AT_sibling values to its caller load_partial_dies. */
1352 const gdb_byte
*sibling
;
1354 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1355 DW_AT_specification (or DW_AT_abstract_origin or
1356 DW_AT_extension). */
1357 sect_offset spec_offset
;
1359 /* Pointers to this DIE's parent, first child, and next sibling,
1361 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
1364 /* This data structure holds the information of an abbrev. */
1367 unsigned int number
; /* number identifying abbrev */
1368 enum dwarf_tag tag
; /* dwarf tag */
1369 unsigned short has_children
; /* boolean */
1370 unsigned short num_attrs
; /* number of attributes */
1371 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
1372 struct abbrev_info
*next
; /* next in chain */
1377 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1378 ENUM_BITFIELD(dwarf_form
) form
: 16;
1380 /* It is valid only if FORM is DW_FORM_implicit_const. */
1381 LONGEST implicit_const
;
1384 /* Size of abbrev_table.abbrev_hash_table. */
1385 #define ABBREV_HASH_SIZE 121
1387 /* Top level data structure to contain an abbreviation table. */
1391 /* Where the abbrev table came from.
1392 This is used as a sanity check when the table is used. */
1393 sect_offset sect_off
;
1395 /* Storage for the abbrev table. */
1396 struct obstack abbrev_obstack
;
1398 /* Hash table of abbrevs.
1399 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1400 It could be statically allocated, but the previous code didn't so we
1402 struct abbrev_info
**abbrevs
;
1405 /* Attributes have a name and a value. */
1408 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1409 ENUM_BITFIELD(dwarf_form
) form
: 15;
1411 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1412 field should be in u.str (existing only for DW_STRING) but it is kept
1413 here for better struct attribute alignment. */
1414 unsigned int string_is_canonical
: 1;
1419 struct dwarf_block
*blk
;
1428 /* This data structure holds a complete die structure. */
1431 /* DWARF-2 tag for this DIE. */
1432 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1434 /* Number of attributes */
1435 unsigned char num_attrs
;
1437 /* True if we're presently building the full type name for the
1438 type derived from this DIE. */
1439 unsigned char building_fullname
: 1;
1441 /* True if this die is in process. PR 16581. */
1442 unsigned char in_process
: 1;
1445 unsigned int abbrev
;
1447 /* Offset in .debug_info or .debug_types section. */
1448 sect_offset sect_off
;
1450 /* The dies in a compilation unit form an n-ary tree. PARENT
1451 points to this die's parent; CHILD points to the first child of
1452 this node; and all the children of a given node are chained
1453 together via their SIBLING fields. */
1454 struct die_info
*child
; /* Its first child, if any. */
1455 struct die_info
*sibling
; /* Its next sibling, if any. */
1456 struct die_info
*parent
; /* Its parent, if any. */
1458 /* An array of attributes, with NUM_ATTRS elements. There may be
1459 zero, but it's not common and zero-sized arrays are not
1460 sufficiently portable C. */
1461 struct attribute attrs
[1];
1464 /* Get at parts of an attribute structure. */
1466 #define DW_STRING(attr) ((attr)->u.str)
1467 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1468 #define DW_UNSND(attr) ((attr)->u.unsnd)
1469 #define DW_BLOCK(attr) ((attr)->u.blk)
1470 #define DW_SND(attr) ((attr)->u.snd)
1471 #define DW_ADDR(attr) ((attr)->u.addr)
1472 #define DW_SIGNATURE(attr) ((attr)->u.signature)
1474 /* Blocks are a bunch of untyped bytes. */
1479 /* Valid only if SIZE is not zero. */
1480 const gdb_byte
*data
;
1483 #ifndef ATTR_ALLOC_CHUNK
1484 #define ATTR_ALLOC_CHUNK 4
1487 /* Allocate fields for structs, unions and enums in this size. */
1488 #ifndef DW_FIELD_ALLOC_CHUNK
1489 #define DW_FIELD_ALLOC_CHUNK 4
1492 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1493 but this would require a corresponding change in unpack_field_as_long
1495 static int bits_per_byte
= 8;
1499 struct nextfield
*next
;
1507 struct nextfnfield
*next
;
1508 struct fn_field fnfield
;
1515 struct nextfnfield
*head
;
1518 struct typedef_field_list
1520 struct typedef_field field
;
1521 struct typedef_field_list
*next
;
1524 /* The routines that read and process dies for a C struct or C++ class
1525 pass lists of data member fields and lists of member function fields
1526 in an instance of a field_info structure, as defined below. */
1529 /* List of data member and baseclasses fields. */
1530 struct nextfield
*fields
, *baseclasses
;
1532 /* Number of fields (including baseclasses). */
1535 /* Number of baseclasses. */
1538 /* Set if the accesibility of one of the fields is not public. */
1539 int non_public_fields
;
1541 /* Member function fieldlist array, contains name of possibly overloaded
1542 member function, number of overloaded member functions and a pointer
1543 to the head of the member function field chain. */
1544 struct fnfieldlist
*fnfieldlists
;
1546 /* Number of entries in the fnfieldlists array. */
1549 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1550 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1551 struct typedef_field_list
*typedef_field_list
;
1552 unsigned typedef_field_list_count
;
1555 /* One item on the queue of compilation units to read in full symbols
1557 struct dwarf2_queue_item
1559 struct dwarf2_per_cu_data
*per_cu
;
1560 enum language pretend_language
;
1561 struct dwarf2_queue_item
*next
;
1564 /* The current queue. */
1565 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1567 /* Loaded secondary compilation units are kept in memory until they
1568 have not been referenced for the processing of this many
1569 compilation units. Set this to zero to disable caching. Cache
1570 sizes of up to at least twenty will improve startup time for
1571 typical inter-CU-reference binaries, at an obvious memory cost. */
1572 static int dwarf_max_cache_age
= 5;
1574 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1575 struct cmd_list_element
*c
, const char *value
)
1577 fprintf_filtered (file
, _("The upper bound on the age of cached "
1578 "DWARF compilation units is %s.\n"),
1582 /* local function prototypes */
1584 static const char *get_section_name (const struct dwarf2_section_info
*);
1586 static const char *get_section_file_name (const struct dwarf2_section_info
*);
1588 static void dwarf2_find_base_address (struct die_info
*die
,
1589 struct dwarf2_cu
*cu
);
1591 static struct partial_symtab
*create_partial_symtab
1592 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1594 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1595 const gdb_byte
*info_ptr
,
1596 struct die_info
*type_unit_die
,
1597 int has_children
, void *data
);
1599 static void dwarf2_build_psymtabs_hard (struct objfile
*);
1601 static void scan_partial_symbols (struct partial_die_info
*,
1602 CORE_ADDR
*, CORE_ADDR
*,
1603 int, struct dwarf2_cu
*);
1605 static void add_partial_symbol (struct partial_die_info
*,
1606 struct dwarf2_cu
*);
1608 static void add_partial_namespace (struct partial_die_info
*pdi
,
1609 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1610 int set_addrmap
, struct dwarf2_cu
*cu
);
1612 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1613 CORE_ADDR
*highpc
, int set_addrmap
,
1614 struct dwarf2_cu
*cu
);
1616 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1617 struct dwarf2_cu
*cu
);
1619 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1620 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1621 int need_pc
, struct dwarf2_cu
*cu
);
1623 static void dwarf2_read_symtab (struct partial_symtab
*,
1626 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1628 static struct abbrev_info
*abbrev_table_lookup_abbrev
1629 (const struct abbrev_table
*, unsigned int);
1631 static struct abbrev_table
*abbrev_table_read_table
1632 (struct dwarf2_section_info
*, sect_offset
);
1634 static void abbrev_table_free (struct abbrev_table
*);
1636 static void abbrev_table_free_cleanup (void *);
1638 static void dwarf2_read_abbrevs (struct dwarf2_cu
*,
1639 struct dwarf2_section_info
*);
1641 static void dwarf2_free_abbrev_table (void *);
1643 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1645 static struct partial_die_info
*load_partial_dies
1646 (const struct die_reader_specs
*, const gdb_byte
*, int);
1648 static const gdb_byte
*read_partial_die (const struct die_reader_specs
*,
1649 struct partial_die_info
*,
1650 struct abbrev_info
*,
1654 static struct partial_die_info
*find_partial_die (sect_offset
, int,
1655 struct dwarf2_cu
*);
1657 static void fixup_partial_die (struct partial_die_info
*,
1658 struct dwarf2_cu
*);
1660 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1661 struct attribute
*, struct attr_abbrev
*,
1664 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1666 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1668 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1670 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1672 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1674 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1677 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1679 static LONGEST read_checked_initial_length_and_offset
1680 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1681 unsigned int *, unsigned int *);
1683 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1684 const struct comp_unit_head
*,
1687 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1689 static sect_offset
read_abbrev_offset (struct dwarf2_section_info
*,
1692 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1694 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1696 static const char *read_indirect_string (bfd
*, const gdb_byte
*,
1697 const struct comp_unit_head
*,
1700 static const char *read_indirect_line_string (bfd
*, const gdb_byte
*,
1701 const struct comp_unit_head
*,
1704 static const char *read_indirect_string_from_dwz (struct dwz_file
*, LONGEST
);
1706 static LONGEST
read_signed_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1708 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1712 static const char *read_str_index (const struct die_reader_specs
*reader
,
1713 ULONGEST str_index
);
1715 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1717 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1718 struct dwarf2_cu
*);
1720 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1723 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1724 struct dwarf2_cu
*cu
);
1726 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1727 struct dwarf2_cu
*cu
);
1729 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1731 static struct die_info
*die_specification (struct die_info
*die
,
1732 struct dwarf2_cu
**);
1734 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1735 struct dwarf2_cu
*cu
);
1737 static void dwarf_decode_lines (struct line_header
*, const char *,
1738 struct dwarf2_cu
*, struct partial_symtab
*,
1739 CORE_ADDR
, int decode_mapping
);
1741 static void dwarf2_start_subfile (const char *, const char *);
1743 static struct compunit_symtab
*dwarf2_start_symtab (struct dwarf2_cu
*,
1744 const char *, const char *,
1747 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1748 struct dwarf2_cu
*);
1750 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1751 struct dwarf2_cu
*, struct symbol
*);
1753 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1754 struct dwarf2_cu
*);
1756 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1759 struct obstack
*obstack
,
1760 struct dwarf2_cu
*cu
, LONGEST
*value
,
1761 const gdb_byte
**bytes
,
1762 struct dwarf2_locexpr_baton
**baton
);
1764 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1766 static int need_gnat_info (struct dwarf2_cu
*);
1768 static struct type
*die_descriptive_type (struct die_info
*,
1769 struct dwarf2_cu
*);
1771 static void set_descriptive_type (struct type
*, struct die_info
*,
1772 struct dwarf2_cu
*);
1774 static struct type
*die_containing_type (struct die_info
*,
1775 struct dwarf2_cu
*);
1777 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1778 struct dwarf2_cu
*);
1780 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1782 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1784 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1786 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1787 const char *suffix
, int physname
,
1788 struct dwarf2_cu
*cu
);
1790 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1792 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1794 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1796 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1798 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1800 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1801 struct dwarf2_cu
*, struct partial_symtab
*);
1803 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1804 values. Keep the items ordered with increasing constraints compliance. */
1807 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1808 PC_BOUNDS_NOT_PRESENT
,
1810 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1811 were present but they do not form a valid range of PC addresses. */
1814 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1817 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1821 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1822 CORE_ADDR
*, CORE_ADDR
*,
1824 struct partial_symtab
*);
1826 static void get_scope_pc_bounds (struct die_info
*,
1827 CORE_ADDR
*, CORE_ADDR
*,
1828 struct dwarf2_cu
*);
1830 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1831 CORE_ADDR
, struct dwarf2_cu
*);
1833 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1834 struct dwarf2_cu
*);
1836 static void dwarf2_attach_fields_to_type (struct field_info
*,
1837 struct type
*, struct dwarf2_cu
*);
1839 static void dwarf2_add_member_fn (struct field_info
*,
1840 struct die_info
*, struct type
*,
1841 struct dwarf2_cu
*);
1843 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1845 struct dwarf2_cu
*);
1847 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1849 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1851 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1853 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1855 static struct using_direct
**using_directives (enum language
);
1857 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1859 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1861 static struct type
*read_module_type (struct die_info
*die
,
1862 struct dwarf2_cu
*cu
);
1864 static const char *namespace_name (struct die_info
*die
,
1865 int *is_anonymous
, struct dwarf2_cu
*);
1867 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1869 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1871 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1872 struct dwarf2_cu
*);
1874 static struct die_info
*read_die_and_siblings_1
1875 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1878 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1879 const gdb_byte
*info_ptr
,
1880 const gdb_byte
**new_info_ptr
,
1881 struct die_info
*parent
);
1883 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1884 struct die_info
**, const gdb_byte
*,
1887 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1888 struct die_info
**, const gdb_byte
*,
1891 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1893 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1896 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1898 static const char *dwarf2_full_name (const char *name
,
1899 struct die_info
*die
,
1900 struct dwarf2_cu
*cu
);
1902 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1903 struct dwarf2_cu
*cu
);
1905 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1906 struct dwarf2_cu
**);
1908 static const char *dwarf_tag_name (unsigned int);
1910 static const char *dwarf_attr_name (unsigned int);
1912 static const char *dwarf_form_name (unsigned int);
1914 static const char *dwarf_bool_name (unsigned int);
1916 static const char *dwarf_type_encoding_name (unsigned int);
1918 static struct die_info
*sibling_die (struct die_info
*);
1920 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1922 static void dump_die_for_error (struct die_info
*);
1924 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1927 /*static*/ void dump_die (struct die_info
*, int max_level
);
1929 static void store_in_ref_table (struct die_info
*,
1930 struct dwarf2_cu
*);
1932 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1934 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1936 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1937 const struct attribute
*,
1938 struct dwarf2_cu
**);
1940 static struct die_info
*follow_die_ref (struct die_info
*,
1941 const struct attribute
*,
1942 struct dwarf2_cu
**);
1944 static struct die_info
*follow_die_sig (struct die_info
*,
1945 const struct attribute
*,
1946 struct dwarf2_cu
**);
1948 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1949 struct dwarf2_cu
*);
1951 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1952 const struct attribute
*,
1953 struct dwarf2_cu
*);
1955 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1957 static void read_signatured_type (struct signatured_type
*);
1959 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1960 struct die_info
*die
, struct dwarf2_cu
*cu
,
1961 struct dynamic_prop
*prop
);
1963 /* memory allocation interface */
1965 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1967 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1969 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1971 static int attr_form_is_block (const struct attribute
*);
1973 static int attr_form_is_section_offset (const struct attribute
*);
1975 static int attr_form_is_constant (const struct attribute
*);
1977 static int attr_form_is_ref (const struct attribute
*);
1979 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1980 struct dwarf2_loclist_baton
*baton
,
1981 const struct attribute
*attr
);
1983 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1985 struct dwarf2_cu
*cu
,
1988 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1989 const gdb_byte
*info_ptr
,
1990 struct abbrev_info
*abbrev
);
1992 static void free_stack_comp_unit (void *);
1994 static hashval_t
partial_die_hash (const void *item
);
1996 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1998 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1999 (sect_offset sect_off
, unsigned int offset_in_dwz
, struct objfile
*objfile
);
2001 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
2002 struct dwarf2_per_cu_data
*per_cu
);
2004 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
2005 struct die_info
*comp_unit_die
,
2006 enum language pretend_language
);
2008 static void free_heap_comp_unit (void *);
2010 static void free_cached_comp_units (void *);
2012 static void age_cached_comp_units (void);
2014 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
2016 static struct type
*set_die_type (struct die_info
*, struct type
*,
2017 struct dwarf2_cu
*);
2019 static void create_all_comp_units (struct objfile
*);
2021 static int create_all_type_units (struct objfile
*);
2023 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
2026 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
2029 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
2032 static void dwarf2_add_dependence (struct dwarf2_cu
*,
2033 struct dwarf2_per_cu_data
*);
2035 static void dwarf2_mark (struct dwarf2_cu
*);
2037 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
2039 static struct type
*get_die_type_at_offset (sect_offset
,
2040 struct dwarf2_per_cu_data
*);
2042 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
2044 static void dwarf2_release_queue (void *dummy
);
2046 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
2047 enum language pretend_language
);
2049 static void process_queue (void);
2051 /* The return type of find_file_and_directory. Note, the enclosed
2052 string pointers are only valid while this object is valid. */
2054 struct file_and_directory
2056 /* The filename. This is never NULL. */
2059 /* The compilation directory. NULL if not known. If we needed to
2060 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
2061 points directly to the DW_AT_comp_dir string attribute owned by
2062 the obstack that owns the DIE. */
2063 const char *comp_dir
;
2065 /* If we needed to build a new string for comp_dir, this is what
2066 owns the storage. */
2067 std::string comp_dir_storage
;
2070 static file_and_directory
find_file_and_directory (struct die_info
*die
,
2071 struct dwarf2_cu
*cu
);
2073 static char *file_full_name (int file
, struct line_header
*lh
,
2074 const char *comp_dir
);
2076 /* Expected enum dwarf_unit_type for read_comp_unit_head. */
2077 enum class rcuh_kind
{ COMPILE
, TYPE
};
2079 static const gdb_byte
*read_and_check_comp_unit_head
2080 (struct comp_unit_head
*header
,
2081 struct dwarf2_section_info
*section
,
2082 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
2083 rcuh_kind section_kind
);
2085 static void init_cutu_and_read_dies
2086 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
2087 int use_existing_cu
, int keep
,
2088 die_reader_func_ftype
*die_reader_func
, void *data
);
2090 static void init_cutu_and_read_dies_simple
2091 (struct dwarf2_per_cu_data
*this_cu
,
2092 die_reader_func_ftype
*die_reader_func
, void *data
);
2094 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
2096 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
2098 static struct dwo_unit
*lookup_dwo_unit_in_dwp
2099 (struct dwp_file
*dwp_file
, const char *comp_dir
,
2100 ULONGEST signature
, int is_debug_types
);
2102 static struct dwp_file
*get_dwp_file (void);
2104 static struct dwo_unit
*lookup_dwo_comp_unit
2105 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
2107 static struct dwo_unit
*lookup_dwo_type_unit
2108 (struct signatured_type
*, const char *, const char *);
2110 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
2112 static void free_dwo_file_cleanup (void *);
2114 static void process_cu_includes (void);
2116 static void check_producer (struct dwarf2_cu
*cu
);
2118 static void free_line_header_voidp (void *arg
);
2120 /* Various complaints about symbol reading that don't abort the process. */
2123 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
2125 complaint (&symfile_complaints
,
2126 _("statement list doesn't fit in .debug_line section"));
2130 dwarf2_debug_line_missing_file_complaint (void)
2132 complaint (&symfile_complaints
,
2133 _(".debug_line section has line data without a file"));
2137 dwarf2_debug_line_missing_end_sequence_complaint (void)
2139 complaint (&symfile_complaints
,
2140 _(".debug_line section has line "
2141 "program sequence without an end"));
2145 dwarf2_complex_location_expr_complaint (void)
2147 complaint (&symfile_complaints
, _("location expression too complex"));
2151 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
2154 complaint (&symfile_complaints
,
2155 _("const value length mismatch for '%s', got %d, expected %d"),
2160 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
2162 complaint (&symfile_complaints
,
2163 _("debug info runs off end of %s section"
2165 get_section_name (section
),
2166 get_section_file_name (section
));
2170 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
2172 complaint (&symfile_complaints
,
2173 _("macro debug info contains a "
2174 "malformed macro definition:\n`%s'"),
2179 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
2181 complaint (&symfile_complaints
,
2182 _("invalid attribute class or form for '%s' in '%s'"),
2186 /* Hash function for line_header_hash. */
2189 line_header_hash (const struct line_header
*ofs
)
2191 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
2194 /* Hash function for htab_create_alloc_ex for line_header_hash. */
2197 line_header_hash_voidp (const void *item
)
2199 const struct line_header
*ofs
= (const struct line_header
*) item
;
2201 return line_header_hash (ofs
);
2204 /* Equality function for line_header_hash. */
2207 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
2209 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
2210 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
2212 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
2213 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
2218 /* Read the given attribute value as an address, taking the attribute's
2219 form into account. */
2222 attr_value_as_address (struct attribute
*attr
)
2226 if (attr
->form
!= DW_FORM_addr
&& attr
->form
!= DW_FORM_GNU_addr_index
)
2228 /* Aside from a few clearly defined exceptions, attributes that
2229 contain an address must always be in DW_FORM_addr form.
2230 Unfortunately, some compilers happen to be violating this
2231 requirement by encoding addresses using other forms, such
2232 as DW_FORM_data4 for example. For those broken compilers,
2233 we try to do our best, without any guarantee of success,
2234 to interpret the address correctly. It would also be nice
2235 to generate a complaint, but that would require us to maintain
2236 a list of legitimate cases where a non-address form is allowed,
2237 as well as update callers to pass in at least the CU's DWARF
2238 version. This is more overhead than what we're willing to
2239 expand for a pretty rare case. */
2240 addr
= DW_UNSND (attr
);
2243 addr
= DW_ADDR (attr
);
2248 /* The suffix for an index file. */
2249 #define INDEX_SUFFIX ".gdb-index"
2251 /* See declaration. */
2253 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
2254 const dwarf2_debug_sections
*names
)
2255 : objfile (objfile_
)
2258 names
= &dwarf2_elf_names
;
2260 bfd
*obfd
= objfile
->obfd
;
2262 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2263 locate_sections (obfd
, sec
, *names
);
2266 dwarf2_per_objfile::~dwarf2_per_objfile ()
2268 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
2269 free_cached_comp_units ();
2271 if (quick_file_names_table
)
2272 htab_delete (quick_file_names_table
);
2274 if (line_header_hash
)
2275 htab_delete (line_header_hash
);
2277 /* Everything else should be on the objfile obstack. */
2280 /* See declaration. */
2283 dwarf2_per_objfile::free_cached_comp_units ()
2285 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
2286 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
2287 while (per_cu
!= NULL
)
2289 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
2291 free_heap_comp_unit (per_cu
->cu
);
2292 *last_chain
= next_cu
;
2297 /* Try to locate the sections we need for DWARF 2 debugging
2298 information and return true if we have enough to do something.
2299 NAMES points to the dwarf2 section names, or is NULL if the standard
2300 ELF names are used. */
2303 dwarf2_has_info (struct objfile
*objfile
,
2304 const struct dwarf2_debug_sections
*names
)
2306 dwarf2_per_objfile
= ((struct dwarf2_per_objfile
*)
2307 objfile_data (objfile
, dwarf2_objfile_data_key
));
2308 if (!dwarf2_per_objfile
)
2310 /* Initialize per-objfile state. */
2311 struct dwarf2_per_objfile
*data
2312 = XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_per_objfile
);
2314 dwarf2_per_objfile
= new (data
) struct dwarf2_per_objfile (objfile
, names
);
2315 set_objfile_data (objfile
, dwarf2_objfile_data_key
, dwarf2_per_objfile
);
2317 return (!dwarf2_per_objfile
->info
.is_virtual
2318 && dwarf2_per_objfile
->info
.s
.section
!= NULL
2319 && !dwarf2_per_objfile
->abbrev
.is_virtual
2320 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
2323 /* Return the containing section of virtual section SECTION. */
2325 static struct dwarf2_section_info
*
2326 get_containing_section (const struct dwarf2_section_info
*section
)
2328 gdb_assert (section
->is_virtual
);
2329 return section
->s
.containing_section
;
2332 /* Return the bfd owner of SECTION. */
2335 get_section_bfd_owner (const struct dwarf2_section_info
*section
)
2337 if (section
->is_virtual
)
2339 section
= get_containing_section (section
);
2340 gdb_assert (!section
->is_virtual
);
2342 return section
->s
.section
->owner
;
2345 /* Return the bfd section of SECTION.
2346 Returns NULL if the section is not present. */
2349 get_section_bfd_section (const struct dwarf2_section_info
*section
)
2351 if (section
->is_virtual
)
2353 section
= get_containing_section (section
);
2354 gdb_assert (!section
->is_virtual
);
2356 return section
->s
.section
;
2359 /* Return the name of SECTION. */
2362 get_section_name (const struct dwarf2_section_info
*section
)
2364 asection
*sectp
= get_section_bfd_section (section
);
2366 gdb_assert (sectp
!= NULL
);
2367 return bfd_section_name (get_section_bfd_owner (section
), sectp
);
2370 /* Return the name of the file SECTION is in. */
2373 get_section_file_name (const struct dwarf2_section_info
*section
)
2375 bfd
*abfd
= get_section_bfd_owner (section
);
2377 return bfd_get_filename (abfd
);
2380 /* Return the id of SECTION.
2381 Returns 0 if SECTION doesn't exist. */
2384 get_section_id (const struct dwarf2_section_info
*section
)
2386 asection
*sectp
= get_section_bfd_section (section
);
2393 /* Return the flags of SECTION.
2394 SECTION (or containing section if this is a virtual section) must exist. */
2397 get_section_flags (const struct dwarf2_section_info
*section
)
2399 asection
*sectp
= get_section_bfd_section (section
);
2401 gdb_assert (sectp
!= NULL
);
2402 return bfd_get_section_flags (sectp
->owner
, sectp
);
2405 /* When loading sections, we look either for uncompressed section or for
2406 compressed section names. */
2409 section_is_p (const char *section_name
,
2410 const struct dwarf2_section_names
*names
)
2412 if (names
->normal
!= NULL
2413 && strcmp (section_name
, names
->normal
) == 0)
2415 if (names
->compressed
!= NULL
2416 && strcmp (section_name
, names
->compressed
) == 0)
2421 /* See declaration. */
2424 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
2425 const dwarf2_debug_sections
&names
)
2427 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
2429 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2432 else if (section_is_p (sectp
->name
, &names
.info
))
2434 this->info
.s
.section
= sectp
;
2435 this->info
.size
= bfd_get_section_size (sectp
);
2437 else if (section_is_p (sectp
->name
, &names
.abbrev
))
2439 this->abbrev
.s
.section
= sectp
;
2440 this->abbrev
.size
= bfd_get_section_size (sectp
);
2442 else if (section_is_p (sectp
->name
, &names
.line
))
2444 this->line
.s
.section
= sectp
;
2445 this->line
.size
= bfd_get_section_size (sectp
);
2447 else if (section_is_p (sectp
->name
, &names
.loc
))
2449 this->loc
.s
.section
= sectp
;
2450 this->loc
.size
= bfd_get_section_size (sectp
);
2452 else if (section_is_p (sectp
->name
, &names
.loclists
))
2454 this->loclists
.s
.section
= sectp
;
2455 this->loclists
.size
= bfd_get_section_size (sectp
);
2457 else if (section_is_p (sectp
->name
, &names
.macinfo
))
2459 this->macinfo
.s
.section
= sectp
;
2460 this->macinfo
.size
= bfd_get_section_size (sectp
);
2462 else if (section_is_p (sectp
->name
, &names
.macro
))
2464 this->macro
.s
.section
= sectp
;
2465 this->macro
.size
= bfd_get_section_size (sectp
);
2467 else if (section_is_p (sectp
->name
, &names
.str
))
2469 this->str
.s
.section
= sectp
;
2470 this->str
.size
= bfd_get_section_size (sectp
);
2472 else if (section_is_p (sectp
->name
, &names
.line_str
))
2474 this->line_str
.s
.section
= sectp
;
2475 this->line_str
.size
= bfd_get_section_size (sectp
);
2477 else if (section_is_p (sectp
->name
, &names
.addr
))
2479 this->addr
.s
.section
= sectp
;
2480 this->addr
.size
= bfd_get_section_size (sectp
);
2482 else if (section_is_p (sectp
->name
, &names
.frame
))
2484 this->frame
.s
.section
= sectp
;
2485 this->frame
.size
= bfd_get_section_size (sectp
);
2487 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2489 this->eh_frame
.s
.section
= sectp
;
2490 this->eh_frame
.size
= bfd_get_section_size (sectp
);
2492 else if (section_is_p (sectp
->name
, &names
.ranges
))
2494 this->ranges
.s
.section
= sectp
;
2495 this->ranges
.size
= bfd_get_section_size (sectp
);
2497 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2499 this->rnglists
.s
.section
= sectp
;
2500 this->rnglists
.size
= bfd_get_section_size (sectp
);
2502 else if (section_is_p (sectp
->name
, &names
.types
))
2504 struct dwarf2_section_info type_section
;
2506 memset (&type_section
, 0, sizeof (type_section
));
2507 type_section
.s
.section
= sectp
;
2508 type_section
.size
= bfd_get_section_size (sectp
);
2510 VEC_safe_push (dwarf2_section_info_def
, this->types
,
2513 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2515 this->gdb_index
.s
.section
= sectp
;
2516 this->gdb_index
.size
= bfd_get_section_size (sectp
);
2519 if ((bfd_get_section_flags (abfd
, sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2520 && bfd_section_vma (abfd
, sectp
) == 0)
2521 this->has_section_at_zero
= true;
2524 /* A helper function that decides whether a section is empty,
2528 dwarf2_section_empty_p (const struct dwarf2_section_info
*section
)
2530 if (section
->is_virtual
)
2531 return section
->size
== 0;
2532 return section
->s
.section
== NULL
|| section
->size
== 0;
2535 /* Read the contents of the section INFO.
2536 OBJFILE is the main object file, but not necessarily the file where
2537 the section comes from. E.g., for DWO files the bfd of INFO is the bfd
2539 If the section is compressed, uncompress it before returning. */
2542 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
2546 gdb_byte
*buf
, *retbuf
;
2550 info
->buffer
= NULL
;
2553 if (dwarf2_section_empty_p (info
))
2556 sectp
= get_section_bfd_section (info
);
2558 /* If this is a virtual section we need to read in the real one first. */
2559 if (info
->is_virtual
)
2561 struct dwarf2_section_info
*containing_section
=
2562 get_containing_section (info
);
2564 gdb_assert (sectp
!= NULL
);
2565 if ((sectp
->flags
& SEC_RELOC
) != 0)
2567 error (_("Dwarf Error: DWP format V2 with relocations is not"
2568 " supported in section %s [in module %s]"),
2569 get_section_name (info
), get_section_file_name (info
));
2571 dwarf2_read_section (objfile
, containing_section
);
2572 /* Other code should have already caught virtual sections that don't
2574 gdb_assert (info
->virtual_offset
+ info
->size
2575 <= containing_section
->size
);
2576 /* If the real section is empty or there was a problem reading the
2577 section we shouldn't get here. */
2578 gdb_assert (containing_section
->buffer
!= NULL
);
2579 info
->buffer
= containing_section
->buffer
+ info
->virtual_offset
;
2583 /* If the section has relocations, we must read it ourselves.
2584 Otherwise we attach it to the BFD. */
2585 if ((sectp
->flags
& SEC_RELOC
) == 0)
2587 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
2591 buf
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
2594 /* When debugging .o files, we may need to apply relocations; see
2595 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2596 We never compress sections in .o files, so we only need to
2597 try this when the section is not compressed. */
2598 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
2601 info
->buffer
= retbuf
;
2605 abfd
= get_section_bfd_owner (info
);
2606 gdb_assert (abfd
!= NULL
);
2608 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
2609 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
2611 error (_("Dwarf Error: Can't read DWARF data"
2612 " in section %s [in module %s]"),
2613 bfd_section_name (abfd
, sectp
), bfd_get_filename (abfd
));
2617 /* A helper function that returns the size of a section in a safe way.
2618 If you are positive that the section has been read before using the
2619 size, then it is safe to refer to the dwarf2_section_info object's
2620 "size" field directly. In other cases, you must call this
2621 function, because for compressed sections the size field is not set
2622 correctly until the section has been read. */
2624 static bfd_size_type
2625 dwarf2_section_size (struct objfile
*objfile
,
2626 struct dwarf2_section_info
*info
)
2629 dwarf2_read_section (objfile
, info
);
2633 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2637 dwarf2_get_section_info (struct objfile
*objfile
,
2638 enum dwarf2_section_enum sect
,
2639 asection
**sectp
, const gdb_byte
**bufp
,
2640 bfd_size_type
*sizep
)
2642 struct dwarf2_per_objfile
*data
2643 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
2644 dwarf2_objfile_data_key
);
2645 struct dwarf2_section_info
*info
;
2647 /* We may see an objfile without any DWARF, in which case we just
2658 case DWARF2_DEBUG_FRAME
:
2659 info
= &data
->frame
;
2661 case DWARF2_EH_FRAME
:
2662 info
= &data
->eh_frame
;
2665 gdb_assert_not_reached ("unexpected section");
2668 dwarf2_read_section (objfile
, info
);
2670 *sectp
= get_section_bfd_section (info
);
2671 *bufp
= info
->buffer
;
2672 *sizep
= info
->size
;
2675 /* A helper function to find the sections for a .dwz file. */
2678 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2680 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2682 /* Note that we only support the standard ELF names, because .dwz
2683 is ELF-only (at the time of writing). */
2684 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2686 dwz_file
->abbrev
.s
.section
= sectp
;
2687 dwz_file
->abbrev
.size
= bfd_get_section_size (sectp
);
2689 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2691 dwz_file
->info
.s
.section
= sectp
;
2692 dwz_file
->info
.size
= bfd_get_section_size (sectp
);
2694 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2696 dwz_file
->str
.s
.section
= sectp
;
2697 dwz_file
->str
.size
= bfd_get_section_size (sectp
);
2699 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2701 dwz_file
->line
.s
.section
= sectp
;
2702 dwz_file
->line
.size
= bfd_get_section_size (sectp
);
2704 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2706 dwz_file
->macro
.s
.section
= sectp
;
2707 dwz_file
->macro
.size
= bfd_get_section_size (sectp
);
2709 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2711 dwz_file
->gdb_index
.s
.section
= sectp
;
2712 dwz_file
->gdb_index
.size
= bfd_get_section_size (sectp
);
2716 /* Open the separate '.dwz' debug file, if needed. Return NULL if
2717 there is no .gnu_debugaltlink section in the file. Error if there
2718 is such a section but the file cannot be found. */
2720 static struct dwz_file
*
2721 dwarf2_get_dwz_file (void)
2723 const char *filename
;
2724 struct dwz_file
*result
;
2725 bfd_size_type buildid_len_arg
;
2729 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2730 return dwarf2_per_objfile
->dwz_file
;
2732 bfd_set_error (bfd_error_no_error
);
2733 gdb::unique_xmalloc_ptr
<char> data
2734 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2735 &buildid_len_arg
, &buildid
));
2738 if (bfd_get_error () == bfd_error_no_error
)
2740 error (_("could not read '.gnu_debugaltlink' section: %s"),
2741 bfd_errmsg (bfd_get_error ()));
2744 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2746 buildid_len
= (size_t) buildid_len_arg
;
2748 filename
= data
.get ();
2750 std::string abs_storage
;
2751 if (!IS_ABSOLUTE_PATH (filename
))
2753 gdb::unique_xmalloc_ptr
<char> abs
2754 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2756 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2757 filename
= abs_storage
.c_str ();
2760 /* First try the file name given in the section. If that doesn't
2761 work, try to use the build-id instead. */
2762 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2763 if (dwz_bfd
!= NULL
)
2765 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2769 if (dwz_bfd
== NULL
)
2770 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2772 if (dwz_bfd
== NULL
)
2773 error (_("could not find '.gnu_debugaltlink' file for %s"),
2774 objfile_name (dwarf2_per_objfile
->objfile
));
2776 result
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
2778 result
->dwz_bfd
= dwz_bfd
.release ();
2780 bfd_map_over_sections (result
->dwz_bfd
, locate_dwz_sections
, result
);
2782 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, result
->dwz_bfd
);
2783 dwarf2_per_objfile
->dwz_file
= result
;
2787 /* DWARF quick_symbols_functions support. */
2789 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2790 unique line tables, so we maintain a separate table of all .debug_line
2791 derived entries to support the sharing.
2792 All the quick functions need is the list of file names. We discard the
2793 line_header when we're done and don't need to record it here. */
2794 struct quick_file_names
2796 /* The data used to construct the hash key. */
2797 struct stmt_list_hash hash
;
2799 /* The number of entries in file_names, real_names. */
2800 unsigned int num_file_names
;
2802 /* The file names from the line table, after being run through
2804 const char **file_names
;
2806 /* The file names from the line table after being run through
2807 gdb_realpath. These are computed lazily. */
2808 const char **real_names
;
2811 /* When using the index (and thus not using psymtabs), each CU has an
2812 object of this type. This is used to hold information needed by
2813 the various "quick" methods. */
2814 struct dwarf2_per_cu_quick_data
2816 /* The file table. This can be NULL if there was no file table
2817 or it's currently not read in.
2818 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2819 struct quick_file_names
*file_names
;
2821 /* The corresponding symbol table. This is NULL if symbols for this
2822 CU have not yet been read. */
2823 struct compunit_symtab
*compunit_symtab
;
2825 /* A temporary mark bit used when iterating over all CUs in
2826 expand_symtabs_matching. */
2827 unsigned int mark
: 1;
2829 /* True if we've tried to read the file table and found there isn't one.
2830 There will be no point in trying to read it again next time. */
2831 unsigned int no_file_data
: 1;
2834 /* Utility hash function for a stmt_list_hash. */
2837 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2841 if (stmt_list_hash
->dwo_unit
!= NULL
)
2842 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2843 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2847 /* Utility equality function for a stmt_list_hash. */
2850 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2851 const struct stmt_list_hash
*rhs
)
2853 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2855 if (lhs
->dwo_unit
!= NULL
2856 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2859 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2862 /* Hash function for a quick_file_names. */
2865 hash_file_name_entry (const void *e
)
2867 const struct quick_file_names
*file_data
2868 = (const struct quick_file_names
*) e
;
2870 return hash_stmt_list_entry (&file_data
->hash
);
2873 /* Equality function for a quick_file_names. */
2876 eq_file_name_entry (const void *a
, const void *b
)
2878 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2879 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2881 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2884 /* Delete function for a quick_file_names. */
2887 delete_file_name_entry (void *e
)
2889 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2892 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2894 xfree ((void*) file_data
->file_names
[i
]);
2895 if (file_data
->real_names
)
2896 xfree ((void*) file_data
->real_names
[i
]);
2899 /* The space for the struct itself lives on objfile_obstack,
2900 so we don't free it here. */
2903 /* Create a quick_file_names hash table. */
2906 create_quick_file_names_table (unsigned int nr_initial_entries
)
2908 return htab_create_alloc (nr_initial_entries
,
2909 hash_file_name_entry
, eq_file_name_entry
,
2910 delete_file_name_entry
, xcalloc
, xfree
);
2913 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2914 have to be created afterwards. You should call age_cached_comp_units after
2915 processing PER_CU->CU. dw2_setup must have been already called. */
2918 load_cu (struct dwarf2_per_cu_data
*per_cu
)
2920 if (per_cu
->is_debug_types
)
2921 load_full_type_unit (per_cu
);
2923 load_full_comp_unit (per_cu
, language_minimal
);
2925 if (per_cu
->cu
== NULL
)
2926 return; /* Dummy CU. */
2928 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2931 /* Read in the symbols for PER_CU. */
2934 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2936 struct cleanup
*back_to
;
2938 /* Skip type_unit_groups, reading the type units they contain
2939 is handled elsewhere. */
2940 if (IS_TYPE_UNIT_GROUP (per_cu
))
2943 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2945 if (dwarf2_per_objfile
->using_index
2946 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2947 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2949 queue_comp_unit (per_cu
, language_minimal
);
2952 /* If we just loaded a CU from a DWO, and we're working with an index
2953 that may badly handle TUs, load all the TUs in that DWO as well.
2954 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2955 if (!per_cu
->is_debug_types
2956 && per_cu
->cu
!= NULL
2957 && per_cu
->cu
->dwo_unit
!= NULL
2958 && dwarf2_per_objfile
->index_table
!= NULL
2959 && dwarf2_per_objfile
->index_table
->version
<= 7
2960 /* DWP files aren't supported yet. */
2961 && get_dwp_file () == NULL
)
2962 queue_and_load_all_dwo_tus (per_cu
);
2967 /* Age the cache, releasing compilation units that have not
2968 been used recently. */
2969 age_cached_comp_units ();
2971 do_cleanups (back_to
);
2974 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2975 the objfile from which this CU came. Returns the resulting symbol
2978 static struct compunit_symtab
*
2979 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2981 gdb_assert (dwarf2_per_objfile
->using_index
);
2982 if (!per_cu
->v
.quick
->compunit_symtab
)
2984 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2985 scoped_restore decrementer
= increment_reading_symtab ();
2986 dw2_do_instantiate_symtab (per_cu
);
2987 process_cu_includes ();
2988 do_cleanups (back_to
);
2991 return per_cu
->v
.quick
->compunit_symtab
;
2994 /* Return the CU/TU given its index.
2996 This is intended for loops like:
2998 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2999 + dwarf2_per_objfile->n_type_units); ++i)
3001 struct dwarf2_per_cu_data *per_cu = dw2_get_cutu (i);
3007 static struct dwarf2_per_cu_data
*
3008 dw2_get_cutu (int index
)
3010 if (index
>= dwarf2_per_objfile
->n_comp_units
)
3012 index
-= dwarf2_per_objfile
->n_comp_units
;
3013 gdb_assert (index
< dwarf2_per_objfile
->n_type_units
);
3014 return &dwarf2_per_objfile
->all_type_units
[index
]->per_cu
;
3017 return dwarf2_per_objfile
->all_comp_units
[index
];
3020 /* Return the CU given its index.
3021 This differs from dw2_get_cutu in that it's for when you know INDEX
3024 static struct dwarf2_per_cu_data
*
3025 dw2_get_cu (int index
)
3027 gdb_assert (index
>= 0 && index
< dwarf2_per_objfile
->n_comp_units
);
3029 return dwarf2_per_objfile
->all_comp_units
[index
];
3032 /* A helper for create_cus_from_index that handles a given list of
3036 create_cus_from_index_list (struct objfile
*objfile
,
3037 const gdb_byte
*cu_list
, offset_type n_elements
,
3038 struct dwarf2_section_info
*section
,
3044 for (i
= 0; i
< n_elements
; i
+= 2)
3046 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3048 sect_offset sect_off
3049 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
3050 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
3053 dwarf2_per_cu_data
*the_cu
3054 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3055 struct dwarf2_per_cu_data
);
3056 the_cu
->sect_off
= sect_off
;
3057 the_cu
->length
= length
;
3058 the_cu
->objfile
= objfile
;
3059 the_cu
->section
= section
;
3060 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3061 struct dwarf2_per_cu_quick_data
);
3062 the_cu
->is_dwz
= is_dwz
;
3063 dwarf2_per_objfile
->all_comp_units
[base_offset
+ i
/ 2] = the_cu
;
3067 /* Read the CU list from the mapped index, and use it to create all
3068 the CU objects for this objfile. */
3071 create_cus_from_index (struct objfile
*objfile
,
3072 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
3073 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
3075 struct dwz_file
*dwz
;
3077 dwarf2_per_objfile
->n_comp_units
= (cu_list_elements
+ dwz_elements
) / 2;
3078 dwarf2_per_objfile
->all_comp_units
=
3079 XOBNEWVEC (&objfile
->objfile_obstack
, struct dwarf2_per_cu_data
*,
3080 dwarf2_per_objfile
->n_comp_units
);
3082 create_cus_from_index_list (objfile
, cu_list
, cu_list_elements
,
3083 &dwarf2_per_objfile
->info
, 0, 0);
3085 if (dwz_elements
== 0)
3088 dwz
= dwarf2_get_dwz_file ();
3089 create_cus_from_index_list (objfile
, dwz_list
, dwz_elements
, &dwz
->info
, 1,
3090 cu_list_elements
/ 2);
3093 /* Create the signatured type hash table from the index. */
3096 create_signatured_type_table_from_index (struct objfile
*objfile
,
3097 struct dwarf2_section_info
*section
,
3098 const gdb_byte
*bytes
,
3099 offset_type elements
)
3102 htab_t sig_types_hash
;
3104 dwarf2_per_objfile
->n_type_units
3105 = dwarf2_per_objfile
->n_allocated_type_units
3107 dwarf2_per_objfile
->all_type_units
=
3108 XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
3110 sig_types_hash
= allocate_signatured_type_table (objfile
);
3112 for (i
= 0; i
< elements
; i
+= 3)
3114 struct signatured_type
*sig_type
;
3117 cu_offset type_offset_in_tu
;
3119 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3120 sect_offset sect_off
3121 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
3123 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
3125 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
3128 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3129 struct signatured_type
);
3130 sig_type
->signature
= signature
;
3131 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3132 sig_type
->per_cu
.is_debug_types
= 1;
3133 sig_type
->per_cu
.section
= section
;
3134 sig_type
->per_cu
.sect_off
= sect_off
;
3135 sig_type
->per_cu
.objfile
= objfile
;
3136 sig_type
->per_cu
.v
.quick
3137 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3138 struct dwarf2_per_cu_quick_data
);
3140 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3143 dwarf2_per_objfile
->all_type_units
[i
/ 3] = sig_type
;
3146 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3149 /* Read the address map data from the mapped index, and use it to
3150 populate the objfile's psymtabs_addrmap. */
3153 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
3155 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3156 const gdb_byte
*iter
, *end
;
3157 struct addrmap
*mutable_map
;
3160 auto_obstack temp_obstack
;
3162 mutable_map
= addrmap_create_mutable (&temp_obstack
);
3164 iter
= index
->address_table
;
3165 end
= iter
+ index
->address_table_size
;
3167 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3171 ULONGEST hi
, lo
, cu_index
;
3172 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3174 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3176 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
3181 complaint (&symfile_complaints
,
3182 _(".gdb_index address table has invalid range (%s - %s)"),
3183 hex_string (lo
), hex_string (hi
));
3187 if (cu_index
>= dwarf2_per_objfile
->n_comp_units
)
3189 complaint (&symfile_complaints
,
3190 _(".gdb_index address table has invalid CU number %u"),
3191 (unsigned) cu_index
);
3195 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
);
3196 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
);
3197 addrmap_set_empty (mutable_map
, lo
, hi
- 1, dw2_get_cutu (cu_index
));
3200 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
3201 &objfile
->objfile_obstack
);
3204 /* The hash function for strings in the mapped index. This is the same as
3205 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
3206 implementation. This is necessary because the hash function is tied to the
3207 format of the mapped index file. The hash values do not have to match with
3210 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
3213 mapped_index_string_hash (int index_version
, const void *p
)
3215 const unsigned char *str
= (const unsigned char *) p
;
3219 while ((c
= *str
++) != 0)
3221 if (index_version
>= 5)
3223 r
= r
* 67 + c
- 113;
3229 /* Find a slot in the mapped index INDEX for the object named NAME.
3230 If NAME is found, set *VEC_OUT to point to the CU vector in the
3231 constant pool and return true. If NAME cannot be found, return
3235 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3236 offset_type
**vec_out
)
3239 offset_type slot
, step
;
3240 int (*cmp
) (const char *, const char *);
3242 gdb::unique_xmalloc_ptr
<char> without_params
;
3243 if (current_language
->la_language
== language_cplus
3244 || current_language
->la_language
== language_fortran
3245 || current_language
->la_language
== language_d
)
3247 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3250 if (strchr (name
, '(') != NULL
)
3252 without_params
= cp_remove_params (name
);
3254 if (without_params
!= NULL
)
3255 name
= without_params
.get ();
3259 /* Index version 4 did not support case insensitive searches. But the
3260 indices for case insensitive languages are built in lowercase, therefore
3261 simulate our NAME being searched is also lowercased. */
3262 hash
= mapped_index_string_hash ((index
->version
== 4
3263 && case_sensitivity
== case_sensitive_off
3264 ? 5 : index
->version
),
3267 slot
= hash
& (index
->symbol_table_slots
- 1);
3268 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
3269 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3273 /* Convert a slot number to an offset into the table. */
3274 offset_type i
= 2 * slot
;
3276 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
3279 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
3280 if (!cmp (name
, str
))
3282 *vec_out
= (offset_type
*) (index
->constant_pool
3283 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
3287 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
3291 /* A helper function that reads the .gdb_index from SECTION and fills
3292 in MAP. FILENAME is the name of the file containing the section;
3293 it is used for error reporting. DEPRECATED_OK is nonzero if it is
3294 ok to use deprecated sections.
3296 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3297 out parameters that are filled in with information about the CU and
3298 TU lists in the section.
3300 Returns 1 if all went well, 0 otherwise. */
3303 read_index_from_section (struct objfile
*objfile
,
3304 const char *filename
,
3306 struct dwarf2_section_info
*section
,
3307 struct mapped_index
*map
,
3308 const gdb_byte
**cu_list
,
3309 offset_type
*cu_list_elements
,
3310 const gdb_byte
**types_list
,
3311 offset_type
*types_list_elements
)
3313 const gdb_byte
*addr
;
3314 offset_type version
;
3315 offset_type
*metadata
;
3318 if (dwarf2_section_empty_p (section
))
3321 /* Older elfutils strip versions could keep the section in the main
3322 executable while splitting it for the separate debug info file. */
3323 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
3326 dwarf2_read_section (objfile
, section
);
3328 addr
= section
->buffer
;
3329 /* Version check. */
3330 version
= MAYBE_SWAP (*(offset_type
*) addr
);
3331 /* Versions earlier than 3 emitted every copy of a psymbol. This
3332 causes the index to behave very poorly for certain requests. Version 3
3333 contained incomplete addrmap. So, it seems better to just ignore such
3337 static int warning_printed
= 0;
3338 if (!warning_printed
)
3340 warning (_("Skipping obsolete .gdb_index section in %s."),
3342 warning_printed
= 1;
3346 /* Index version 4 uses a different hash function than index version
3349 Versions earlier than 6 did not emit psymbols for inlined
3350 functions. Using these files will cause GDB not to be able to
3351 set breakpoints on inlined functions by name, so we ignore these
3352 indices unless the user has done
3353 "set use-deprecated-index-sections on". */
3354 if (version
< 6 && !deprecated_ok
)
3356 static int warning_printed
= 0;
3357 if (!warning_printed
)
3360 Skipping deprecated .gdb_index section in %s.\n\
3361 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3362 to use the section anyway."),
3364 warning_printed
= 1;
3368 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3369 of the TU (for symbols coming from TUs),
3370 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3371 Plus gold-generated indices can have duplicate entries for global symbols,
3372 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3373 These are just performance bugs, and we can't distinguish gdb-generated
3374 indices from gold-generated ones, so issue no warning here. */
3376 /* Indexes with higher version than the one supported by GDB may be no
3377 longer backward compatible. */
3381 map
->version
= version
;
3382 map
->total_size
= section
->size
;
3384 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3387 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3388 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3392 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3393 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3394 - MAYBE_SWAP (metadata
[i
]))
3398 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3399 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
3400 - MAYBE_SWAP (metadata
[i
]));
3403 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
3404 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
3405 - MAYBE_SWAP (metadata
[i
]))
3406 / (2 * sizeof (offset_type
)));
3409 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3415 /* Read the index file. If everything went ok, initialize the "quick"
3416 elements of all the CUs and return 1. Otherwise, return 0. */
3419 dwarf2_read_index (struct objfile
*objfile
)
3421 struct mapped_index local_map
, *map
;
3422 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3423 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3424 struct dwz_file
*dwz
;
3426 if (!read_index_from_section (objfile
, objfile_name (objfile
),
3427 use_deprecated_index_sections
,
3428 &dwarf2_per_objfile
->gdb_index
, &local_map
,
3429 &cu_list
, &cu_list_elements
,
3430 &types_list
, &types_list_elements
))
3433 /* Don't use the index if it's empty. */
3434 if (local_map
.symbol_table_slots
== 0)
3437 /* If there is a .dwz file, read it so we can get its CU list as
3439 dwz
= dwarf2_get_dwz_file ();
3442 struct mapped_index dwz_map
;
3443 const gdb_byte
*dwz_types_ignore
;
3444 offset_type dwz_types_elements_ignore
;
3446 if (!read_index_from_section (objfile
, bfd_get_filename (dwz
->dwz_bfd
),
3448 &dwz
->gdb_index
, &dwz_map
,
3449 &dwz_list
, &dwz_list_elements
,
3451 &dwz_types_elements_ignore
))
3453 warning (_("could not read '.gdb_index' section from %s; skipping"),
3454 bfd_get_filename (dwz
->dwz_bfd
));
3459 create_cus_from_index (objfile
, cu_list
, cu_list_elements
, dwz_list
,
3462 if (types_list_elements
)
3464 struct dwarf2_section_info
*section
;
3466 /* We can only handle a single .debug_types when we have an
3468 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
3471 section
= VEC_index (dwarf2_section_info_def
,
3472 dwarf2_per_objfile
->types
, 0);
3474 create_signatured_type_table_from_index (objfile
, section
, types_list
,
3475 types_list_elements
);
3478 create_addrmap_from_index (objfile
, &local_map
);
3480 map
= XOBNEW (&objfile
->objfile_obstack
, struct mapped_index
);
3481 map
= new (map
) mapped_index ();
3484 dwarf2_per_objfile
->index_table
= map
;
3485 dwarf2_per_objfile
->using_index
= 1;
3486 dwarf2_per_objfile
->quick_file_names_table
=
3487 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3492 /* A helper for the "quick" functions which sets the global
3493 dwarf2_per_objfile according to OBJFILE. */
3496 dw2_setup (struct objfile
*objfile
)
3498 dwarf2_per_objfile
= ((struct dwarf2_per_objfile
*)
3499 objfile_data (objfile
, dwarf2_objfile_data_key
));
3500 gdb_assert (dwarf2_per_objfile
);
3503 /* die_reader_func for dw2_get_file_names. */
3506 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3507 const gdb_byte
*info_ptr
,
3508 struct die_info
*comp_unit_die
,
3512 struct dwarf2_cu
*cu
= reader
->cu
;
3513 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3514 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3515 struct dwarf2_per_cu_data
*lh_cu
;
3516 struct attribute
*attr
;
3519 struct quick_file_names
*qfn
;
3521 gdb_assert (! this_cu
->is_debug_types
);
3523 /* Our callers never want to match partial units -- instead they
3524 will match the enclosing full CU. */
3525 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3527 this_cu
->v
.quick
->no_file_data
= 1;
3535 sect_offset line_offset
{};
3537 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3540 struct quick_file_names find_entry
;
3542 line_offset
= (sect_offset
) DW_UNSND (attr
);
3544 /* We may have already read in this line header (TU line header sharing).
3545 If we have we're done. */
3546 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3547 find_entry
.hash
.line_sect_off
= line_offset
;
3548 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
3549 &find_entry
, INSERT
);
3552 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3556 lh
= dwarf_decode_line_header (line_offset
, cu
);
3560 lh_cu
->v
.quick
->no_file_data
= 1;
3564 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3565 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3566 qfn
->hash
.line_sect_off
= line_offset
;
3567 gdb_assert (slot
!= NULL
);
3570 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3572 qfn
->num_file_names
= lh
->file_names
.size ();
3574 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, lh
->file_names
.size ());
3575 for (i
= 0; i
< lh
->file_names
.size (); ++i
)
3576 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
.get (), fnd
.comp_dir
);
3577 qfn
->real_names
= NULL
;
3579 lh_cu
->v
.quick
->file_names
= qfn
;
3582 /* A helper for the "quick" functions which attempts to read the line
3583 table for THIS_CU. */
3585 static struct quick_file_names
*
3586 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3588 /* This should never be called for TUs. */
3589 gdb_assert (! this_cu
->is_debug_types
);
3590 /* Nor type unit groups. */
3591 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3593 if (this_cu
->v
.quick
->file_names
!= NULL
)
3594 return this_cu
->v
.quick
->file_names
;
3595 /* If we know there is no line data, no point in looking again. */
3596 if (this_cu
->v
.quick
->no_file_data
)
3599 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
3601 if (this_cu
->v
.quick
->no_file_data
)
3603 return this_cu
->v
.quick
->file_names
;
3606 /* A helper for the "quick" functions which computes and caches the
3607 real path for a given file name from the line table. */
3610 dw2_get_real_path (struct objfile
*objfile
,
3611 struct quick_file_names
*qfn
, int index
)
3613 if (qfn
->real_names
== NULL
)
3614 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3615 qfn
->num_file_names
, const char *);
3617 if (qfn
->real_names
[index
] == NULL
)
3618 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3620 return qfn
->real_names
[index
];
3623 static struct symtab
*
3624 dw2_find_last_source_symtab (struct objfile
*objfile
)
3626 struct compunit_symtab
*cust
;
3629 dw2_setup (objfile
);
3630 index
= dwarf2_per_objfile
->n_comp_units
- 1;
3631 cust
= dw2_instantiate_symtab (dw2_get_cutu (index
));
3634 return compunit_primary_filetab (cust
);
3637 /* Traversal function for dw2_forget_cached_source_info. */
3640 dw2_free_cached_file_names (void **slot
, void *info
)
3642 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3644 if (file_data
->real_names
)
3648 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3650 xfree ((void*) file_data
->real_names
[i
]);
3651 file_data
->real_names
[i
] = NULL
;
3659 dw2_forget_cached_source_info (struct objfile
*objfile
)
3661 dw2_setup (objfile
);
3663 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3664 dw2_free_cached_file_names
, NULL
);
3667 /* Helper function for dw2_map_symtabs_matching_filename that expands
3668 the symtabs and calls the iterator. */
3671 dw2_map_expand_apply (struct objfile
*objfile
,
3672 struct dwarf2_per_cu_data
*per_cu
,
3673 const char *name
, const char *real_path
,
3674 gdb::function_view
<bool (symtab
*)> callback
)
3676 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3678 /* Don't visit already-expanded CUs. */
3679 if (per_cu
->v
.quick
->compunit_symtab
)
3682 /* This may expand more than one symtab, and we want to iterate over
3684 dw2_instantiate_symtab (per_cu
);
3686 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3687 last_made
, callback
);
3690 /* Implementation of the map_symtabs_matching_filename method. */
3693 dw2_map_symtabs_matching_filename
3694 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3695 gdb::function_view
<bool (symtab
*)> callback
)
3698 const char *name_basename
= lbasename (name
);
3700 dw2_setup (objfile
);
3702 /* The rule is CUs specify all the files, including those used by
3703 any TU, so there's no need to scan TUs here. */
3705 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3708 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3709 struct quick_file_names
*file_data
;
3711 /* We only need to look at symtabs not already expanded. */
3712 if (per_cu
->v
.quick
->compunit_symtab
)
3715 file_data
= dw2_get_file_names (per_cu
);
3716 if (file_data
== NULL
)
3719 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3721 const char *this_name
= file_data
->file_names
[j
];
3722 const char *this_real_name
;
3724 if (compare_filenames_for_search (this_name
, name
))
3726 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3732 /* Before we invoke realpath, which can get expensive when many
3733 files are involved, do a quick comparison of the basenames. */
3734 if (! basenames_may_differ
3735 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3738 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3739 if (compare_filenames_for_search (this_real_name
, name
))
3741 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3747 if (real_path
!= NULL
)
3749 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3750 gdb_assert (IS_ABSOLUTE_PATH (name
));
3751 if (this_real_name
!= NULL
3752 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3754 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3766 /* Struct used to manage iterating over all CUs looking for a symbol. */
3768 struct dw2_symtab_iterator
3770 /* The internalized form of .gdb_index. */
3771 struct mapped_index
*index
;
3772 /* If non-zero, only look for symbols that match BLOCK_INDEX. */
3773 int want_specific_block
;
3774 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
3775 Unused if !WANT_SPECIFIC_BLOCK. */
3777 /* The kind of symbol we're looking for. */
3779 /* The list of CUs from the index entry of the symbol,
3780 or NULL if not found. */
3782 /* The next element in VEC to look at. */
3784 /* The number of elements in VEC, or zero if there is no match. */
3786 /* Have we seen a global version of the symbol?
3787 If so we can ignore all further global instances.
3788 This is to work around gold/15646, inefficient gold-generated
3793 /* Initialize the index symtab iterator ITER.
3794 If WANT_SPECIFIC_BLOCK is non-zero, only look for symbols
3795 in block BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
3798 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3799 struct mapped_index
*index
,
3800 int want_specific_block
,
3805 iter
->index
= index
;
3806 iter
->want_specific_block
= want_specific_block
;
3807 iter
->block_index
= block_index
;
3808 iter
->domain
= domain
;
3810 iter
->global_seen
= 0;
3812 if (find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3813 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3821 /* Return the next matching CU or NULL if there are no more. */
3823 static struct dwarf2_per_cu_data
*
3824 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3826 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3828 offset_type cu_index_and_attrs
=
3829 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3830 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3831 struct dwarf2_per_cu_data
*per_cu
;
3832 int want_static
= iter
->block_index
!= GLOBAL_BLOCK
;
3833 /* This value is only valid for index versions >= 7. */
3834 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3835 gdb_index_symbol_kind symbol_kind
=
3836 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3837 /* Only check the symbol attributes if they're present.
3838 Indices prior to version 7 don't record them,
3839 and indices >= 7 may elide them for certain symbols
3840 (gold does this). */
3842 (iter
->index
->version
>= 7
3843 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3845 /* Don't crash on bad data. */
3846 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
3847 + dwarf2_per_objfile
->n_type_units
))
3849 complaint (&symfile_complaints
,
3850 _(".gdb_index entry has bad CU index"
3852 objfile_name (dwarf2_per_objfile
->objfile
));
3856 per_cu
= dw2_get_cutu (cu_index
);
3858 /* Skip if already read in. */
3859 if (per_cu
->v
.quick
->compunit_symtab
)
3862 /* Check static vs global. */
3865 if (iter
->want_specific_block
3866 && want_static
!= is_static
)
3868 /* Work around gold/15646. */
3869 if (!is_static
&& iter
->global_seen
)
3872 iter
->global_seen
= 1;
3875 /* Only check the symbol's kind if it has one. */
3878 switch (iter
->domain
)
3881 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3882 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3883 /* Some types are also in VAR_DOMAIN. */
3884 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3888 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3892 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3907 static struct compunit_symtab
*
3908 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
3909 const char *name
, domain_enum domain
)
3911 struct compunit_symtab
*stab_best
= NULL
;
3912 struct mapped_index
*index
;
3914 dw2_setup (objfile
);
3916 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3918 index
= dwarf2_per_objfile
->index_table
;
3920 /* index is NULL if OBJF_READNOW. */
3923 struct dw2_symtab_iterator iter
;
3924 struct dwarf2_per_cu_data
*per_cu
;
3926 dw2_symtab_iter_init (&iter
, index
, 1, block_index
, domain
, name
);
3928 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3930 struct symbol
*sym
, *with_opaque
= NULL
;
3931 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
);
3932 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3933 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3935 sym
= block_find_symbol (block
, name
, domain
,
3936 block_find_non_opaque_type_preferred
,
3939 /* Some caution must be observed with overloaded functions
3940 and methods, since the index will not contain any overload
3941 information (but NAME might contain it). */
3944 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3946 if (with_opaque
!= NULL
3947 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3950 /* Keep looking through other CUs. */
3958 dw2_print_stats (struct objfile
*objfile
)
3960 int i
, total
, count
;
3962 dw2_setup (objfile
);
3963 total
= dwarf2_per_objfile
->n_comp_units
+ dwarf2_per_objfile
->n_type_units
;
3965 for (i
= 0; i
< total
; ++i
)
3967 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
3969 if (!per_cu
->v
.quick
->compunit_symtab
)
3972 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3973 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3976 /* This dumps minimal information about the index.
3977 It is called via "mt print objfiles".
3978 One use is to verify .gdb_index has been loaded by the
3979 gdb.dwarf2/gdb-index.exp testcase. */
3982 dw2_dump (struct objfile
*objfile
)
3984 dw2_setup (objfile
);
3985 gdb_assert (dwarf2_per_objfile
->using_index
);
3986 printf_filtered (".gdb_index:");
3987 if (dwarf2_per_objfile
->index_table
!= NULL
)
3989 printf_filtered (" version %d\n",
3990 dwarf2_per_objfile
->index_table
->version
);
3993 printf_filtered (" faked for \"readnow\"\n");
3994 printf_filtered ("\n");
3998 dw2_relocate (struct objfile
*objfile
,
3999 const struct section_offsets
*new_offsets
,
4000 const struct section_offsets
*delta
)
4002 /* There's nothing to relocate here. */
4006 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
4007 const char *func_name
)
4009 struct mapped_index
*index
;
4011 dw2_setup (objfile
);
4013 index
= dwarf2_per_objfile
->index_table
;
4015 /* index is NULL if OBJF_READNOW. */
4018 struct dw2_symtab_iterator iter
;
4019 struct dwarf2_per_cu_data
*per_cu
;
4021 /* Note: It doesn't matter what we pass for block_index here. */
4022 dw2_symtab_iter_init (&iter
, index
, 0, GLOBAL_BLOCK
, VAR_DOMAIN
,
4025 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4026 dw2_instantiate_symtab (per_cu
);
4031 dw2_expand_all_symtabs (struct objfile
*objfile
)
4035 dw2_setup (objfile
);
4037 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
4038 + dwarf2_per_objfile
->n_type_units
); ++i
)
4040 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
4042 dw2_instantiate_symtab (per_cu
);
4047 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
4048 const char *fullname
)
4052 dw2_setup (objfile
);
4054 /* We don't need to consider type units here.
4055 This is only called for examining code, e.g. expand_line_sal.
4056 There can be an order of magnitude (or more) more type units
4057 than comp units, and we avoid them if we can. */
4059 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4062 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
4063 struct quick_file_names
*file_data
;
4065 /* We only need to look at symtabs not already expanded. */
4066 if (per_cu
->v
.quick
->compunit_symtab
)
4069 file_data
= dw2_get_file_names (per_cu
);
4070 if (file_data
== NULL
)
4073 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
4075 const char *this_fullname
= file_data
->file_names
[j
];
4077 if (filename_cmp (this_fullname
, fullname
) == 0)
4079 dw2_instantiate_symtab (per_cu
);
4087 dw2_map_matching_symbols (struct objfile
*objfile
,
4088 const char * name
, domain_enum domain
,
4090 int (*callback
) (struct block
*,
4091 struct symbol
*, void *),
4092 void *data
, symbol_name_match_type match
,
4093 symbol_compare_ftype
*ordered_compare
)
4095 /* Currently unimplemented; used for Ada. The function can be called if the
4096 current language is Ada for a non-Ada objfile using GNU index. As Ada
4097 does not look for non-Ada symbols this function should just return. */
4100 /* Symbol name matcher for .gdb_index names.
4102 Symbol names in .gdb_index have a few particularities:
4104 - There's no indication of which is the language of each symbol.
4106 Since each language has its own symbol name matching algorithm,
4107 and we don't know which language is the right one, we must match
4108 each symbol against all languages. This would be a potential
4109 performance problem if it were not mitigated by the
4110 mapped_index::name_components lookup table, which significantly
4111 reduces the number of times we need to call into this matcher,
4112 making it a non-issue.
4114 - Symbol names in the index have no overload (parameter)
4115 information. I.e., in C++, "foo(int)" and "foo(long)" both
4116 appear as "foo" in the index, for example.
4118 This means that the lookup names passed to the symbol name
4119 matcher functions must have no parameter information either
4120 because (e.g.) symbol search name "foo" does not match
4121 lookup-name "foo(int)" [while swapping search name for lookup
4124 class gdb_index_symbol_name_matcher
4127 /* Prepares the vector of comparison functions for LOOKUP_NAME. */
4128 gdb_index_symbol_name_matcher (const lookup_name_info
&lookup_name
);
4130 /* Walk all the matcher routines and match SYMBOL_NAME against them.
4131 Returns true if any matcher matches. */
4132 bool matches (const char *symbol_name
);
4135 /* A reference to the lookup name we're matching against. */
4136 const lookup_name_info
&m_lookup_name
;
4138 /* A vector holding all the different symbol name matchers, for all
4140 std::vector
<symbol_name_matcher_ftype
*> m_symbol_name_matcher_funcs
;
4143 gdb_index_symbol_name_matcher::gdb_index_symbol_name_matcher
4144 (const lookup_name_info
&lookup_name
)
4145 : m_lookup_name (lookup_name
)
4147 /* Prepare the vector of comparison functions upfront, to avoid
4148 doing the same work for each symbol. Care is taken to avoid
4149 matching with the same matcher more than once if/when multiple
4150 languages use the same matcher function. */
4151 auto &matchers
= m_symbol_name_matcher_funcs
;
4152 matchers
.reserve (nr_languages
);
4154 matchers
.push_back (default_symbol_name_matcher
);
4156 for (int i
= 0; i
< nr_languages
; i
++)
4158 const language_defn
*lang
= language_def ((enum language
) i
);
4159 if (lang
->la_get_symbol_name_matcher
!= NULL
)
4161 symbol_name_matcher_ftype
*name_matcher
4162 = lang
->la_get_symbol_name_matcher (m_lookup_name
);
4164 /* Don't insert the same comparison routine more than once.
4165 Note that we do this linear walk instead of a cheaper
4166 sorted insert, or use a std::set or something like that,
4167 because relative order of function addresses is not
4168 stable. This is not a problem in practice because the
4169 number of supported languages is low, and the cost here
4170 is tiny compared to the number of searches we'll do
4171 afterwards using this object. */
4172 if (std::find (matchers
.begin (), matchers
.end (), name_matcher
)
4174 matchers
.push_back (name_matcher
);
4180 gdb_index_symbol_name_matcher::matches (const char *symbol_name
)
4182 for (auto matches_name
: m_symbol_name_matcher_funcs
)
4183 if (matches_name (symbol_name
, m_lookup_name
, NULL
))
4189 /* Helper for dw2_expand_symtabs_matching that works with a
4190 mapped_index instead of the containing objfile. This is split to a
4191 separate function in order to be able to unit test the
4192 name_components matching using a mock mapped_index. For each
4193 symbol name that matches, calls MATCH_CALLBACK, passing it the
4194 symbol's index in the mapped_index symbol table. */
4197 dw2_expand_symtabs_matching_symbol
4198 (mapped_index
&index
,
4199 const lookup_name_info
&lookup_name_in
,
4200 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4201 enum search_domain kind
,
4202 gdb::function_view
<void (offset_type
)> match_callback
)
4204 lookup_name_info lookup_name_without_params
4205 = lookup_name_in
.make_ignore_params ();
4206 gdb_index_symbol_name_matcher lookup_name_matcher
4207 (lookup_name_without_params
);
4209 auto *name_cmp
= case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
;
4211 /* Build the symbol name component sorted vector, if we haven't yet.
4212 The code below only knows how to break apart components of C++
4213 symbol names (and other languages that use '::' as
4214 namespace/module separator). If we add support for wild matching
4215 to some language that uses some other operator (E.g., Ada, Go and
4216 D use '.'), then we'll need to try splitting the symbol name
4217 according to that language too. Note that Ada does support wild
4218 matching, but doesn't currently support .gdb_index. */
4219 if (index
.name_components
.empty ())
4221 for (size_t iter
= 0; iter
< index
.symbol_table_slots
; ++iter
)
4223 offset_type idx
= 2 * iter
;
4225 if (index
.symbol_table
[idx
] == 0
4226 && index
.symbol_table
[idx
+ 1] == 0)
4229 const char *name
= index
.symbol_name_at (idx
);
4231 /* Add each name component to the name component table. */
4232 unsigned int previous_len
= 0;
4233 for (unsigned int current_len
= cp_find_first_component (name
);
4234 name
[current_len
] != '\0';
4235 current_len
+= cp_find_first_component (name
+ current_len
))
4237 gdb_assert (name
[current_len
] == ':');
4238 index
.name_components
.push_back ({previous_len
, idx
});
4239 /* Skip the '::'. */
4241 previous_len
= current_len
;
4243 index
.name_components
.push_back ({previous_len
, idx
});
4246 /* Sort name_components elements by name. */
4247 auto name_comp_compare
= [&] (const name_component
&left
,
4248 const name_component
&right
)
4250 const char *left_qualified
= index
.symbol_name_at (left
.idx
);
4251 const char *right_qualified
= index
.symbol_name_at (right
.idx
);
4253 const char *left_name
= left_qualified
+ left
.name_offset
;
4254 const char *right_name
= right_qualified
+ right
.name_offset
;
4256 return name_cmp (left_name
, right_name
) < 0;
4259 std::sort (index
.name_components
.begin (),
4260 index
.name_components
.end (),
4265 = lookup_name_without_params
.cplus ().lookup_name ().c_str ();
4267 /* Comparison function object for lower_bound that matches against a
4268 given symbol name. */
4269 auto lookup_compare_lower
= [&] (const name_component
&elem
,
4272 const char *elem_qualified
= index
.symbol_name_at (elem
.idx
);
4273 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4274 return name_cmp (elem_name
, name
) < 0;
4277 /* Comparison function object for upper_bound that matches against a
4278 given symbol name. */
4279 auto lookup_compare_upper
= [&] (const char *name
,
4280 const name_component
&elem
)
4282 const char *elem_qualified
= index
.symbol_name_at (elem
.idx
);
4283 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4284 return name_cmp (name
, elem_name
) < 0;
4287 auto begin
= index
.name_components
.begin ();
4288 auto end
= index
.name_components
.end ();
4290 /* Find the lower bound. */
4293 if (lookup_name_in
.completion_mode () && cplus
[0] == '\0')
4296 return std::lower_bound (begin
, end
, cplus
, lookup_compare_lower
);
4299 /* Find the upper bound. */
4302 if (lookup_name_in
.completion_mode ())
4304 /* The string frobbing below won't work if the string is
4305 empty. We don't need it then, anyway -- if we're
4306 completing an empty string, then we want to iterate over
4308 if (cplus
[0] == '\0')
4311 /* In completion mode, increment the last character because
4312 we want UPPER to point past all symbols names that have
4314 std::string after
= cplus
;
4316 gdb_assert (after
.back () != 0xff);
4319 return std::upper_bound (lower
, end
, after
.c_str (),
4320 lookup_compare_upper
);
4323 return std::upper_bound (lower
, end
, cplus
, lookup_compare_upper
);
4326 /* Now for each symbol name in range, check to see if we have a name
4327 match, and if so, call the MATCH_CALLBACK callback. */
4329 /* The same symbol may appear more than once in the range though.
4330 E.g., if we're looking for symbols that complete "w", and we have
4331 a symbol named "w1::w2", we'll find the two name components for
4332 that same symbol in the range. To be sure we only call the
4333 callback once per symbol, we first collect the symbol name
4334 indexes that matched in a temporary vector and ignore
4336 std::vector
<offset_type
> matches
;
4337 matches
.reserve (std::distance (lower
, upper
));
4339 for (;lower
!= upper
; ++lower
)
4341 const char *qualified
= index
.symbol_name_at (lower
->idx
);
4343 if (!lookup_name_matcher
.matches (qualified
)
4344 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4347 matches
.push_back (lower
->idx
);
4350 std::sort (matches
.begin (), matches
.end ());
4352 /* Finally call the callback, once per match. */
4354 for (offset_type idx
: matches
)
4358 match_callback (idx
);
4363 /* Above we use a type wider than idx's for 'prev', since 0 and
4364 (offset_type)-1 are both possible values. */
4365 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4370 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4372 /* A wrapper around mapped_index that builds a mock mapped_index, from
4373 the symbol list passed as parameter to the constructor. */
4374 class mock_mapped_index
4378 mock_mapped_index (const char *(&symbols
)[N
])
4379 : mock_mapped_index (symbols
, N
)
4382 /* Access the built index. */
4383 mapped_index
&index ()
4387 mock_mapped_index(const mock_mapped_index
&) = delete;
4388 void operator= (const mock_mapped_index
&) = delete;
4391 mock_mapped_index (const char **symbols
, size_t symbols_size
)
4393 /* No string can live at offset zero. Add a dummy entry. */
4394 obstack_grow_str0 (&m_constant_pool
, "");
4396 for (size_t i
= 0; i
< symbols_size
; i
++)
4398 const char *sym
= symbols
[i
];
4399 size_t offset
= obstack_object_size (&m_constant_pool
);
4400 obstack_grow_str0 (&m_constant_pool
, sym
);
4401 m_symbol_table
.push_back (offset
);
4402 m_symbol_table
.push_back (0);
4405 m_index
.constant_pool
= (const char *) obstack_base (&m_constant_pool
);
4406 m_index
.symbol_table
= m_symbol_table
.data ();
4407 m_index
.symbol_table_slots
= m_symbol_table
.size () / 2;
4411 /* The built mapped_index. */
4412 mapped_index m_index
{};
4414 /* The storage that the built mapped_index uses for symbol and
4415 constant pool tables. */
4416 std::vector
<offset_type
> m_symbol_table
;
4417 auto_obstack m_constant_pool
;
4420 /* Convenience function that converts a NULL pointer to a "<null>"
4421 string, to pass to print routines. */
4424 string_or_null (const char *str
)
4426 return str
!= NULL
? str
: "<null>";
4429 /* Check if a lookup_name_info built from
4430 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4431 index. EXPECTED_LIST is the list of expected matches, in expected
4432 matching order. If no match expected, then an empty list is
4433 specified. Returns true on success. On failure prints a warning
4434 indicating the file:line that failed, and returns false. */
4437 check_match (const char *file
, int line
,
4438 mock_mapped_index
&mock_index
,
4439 const char *name
, symbol_name_match_type match_type
,
4440 bool completion_mode
,
4441 std::initializer_list
<const char *> expected_list
)
4443 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4445 bool matched
= true;
4447 auto mismatch
= [&] (const char *expected_str
,
4450 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4451 "expected=\"%s\", got=\"%s\"\n"),
4453 (match_type
== symbol_name_match_type::FULL
4455 name
, string_or_null (expected_str
), string_or_null (got
));
4459 auto expected_it
= expected_list
.begin ();
4460 auto expected_end
= expected_list
.end ();
4462 dw2_expand_symtabs_matching_symbol (mock_index
.index (), lookup_name
,
4464 [&] (offset_type idx
)
4466 const char *matched_name
= mock_index
.index ().symbol_name_at (idx
);
4467 const char *expected_str
4468 = expected_it
== expected_end
? NULL
: *expected_it
++;
4470 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4471 mismatch (expected_str
, matched_name
);
4474 const char *expected_str
4475 = expected_it
== expected_end
? NULL
: *expected_it
++;
4476 if (expected_str
!= NULL
)
4477 mismatch (expected_str
, NULL
);
4482 /* The symbols added to the mock mapped_index for testing (in
4484 static const char *test_symbols
[] = {
4494 /* A name with all sorts of complications. Starts with "z" to make
4495 it easier for the completion tests below. */
4496 #define Z_SYM_NAME \
4497 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4498 "::tuple<(anonymous namespace)::ui*, " \
4499 "std::default_delete<(anonymous namespace)::ui>, void>"
4507 mock_mapped_index
mock_index (test_symbols
);
4509 /* We let all tests run until the end even if some fails, for debug
4511 bool any_mismatch
= false;
4513 /* Create the expected symbols list (an initializer_list). Needed
4514 because lists have commas, and we need to pass them to CHECK,
4515 which is a macro. */
4516 #define EXPECT(...) { __VA_ARGS__ }
4518 /* Wrapper for check_match that passes down the current
4519 __FILE__/__LINE__. */
4520 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4521 any_mismatch |= !check_match (__FILE__, __LINE__, \
4523 NAME, MATCH_TYPE, COMPLETION_MODE, \
4526 /* Identity checks. */
4527 for (const char *sym
: test_symbols
)
4529 /* Should be able to match all existing symbols. */
4530 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4533 /* Should be able to match all existing symbols with
4535 std::string with_params
= std::string (sym
) + "(int)";
4536 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4539 /* Should be able to match all existing symbols with
4540 parameters and qualifiers. */
4541 with_params
= std::string (sym
) + " ( int ) const";
4542 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4545 /* This should really find sym, but cp-name-parser.y doesn't
4546 know about lvalue/rvalue qualifiers yet. */
4547 with_params
= std::string (sym
) + " ( int ) &&";
4548 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4552 /* Check that completion mode works at each prefix of the expected
4555 static const char str
[] = "function(int)";
4556 size_t len
= strlen (str
);
4559 for (size_t i
= 1; i
< len
; i
++)
4561 lookup
.assign (str
, i
);
4562 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4563 EXPECT ("function"));
4567 /* While "w" is a prefix of both components, the match function
4568 should still only be called once. */
4570 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4574 /* Same, with a "complicated" symbol. */
4576 static const char str
[] = Z_SYM_NAME
;
4577 size_t len
= strlen (str
);
4580 for (size_t i
= 1; i
< len
; i
++)
4582 lookup
.assign (str
, i
);
4583 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4584 EXPECT (Z_SYM_NAME
));
4588 /* In FULL mode, an incomplete symbol doesn't match. */
4590 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4594 /* A complete symbol with parameters matches any overload, since the
4595 index has no overload info. */
4597 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4598 EXPECT ("std::zfunction", "std::zfunction2"));
4601 /* Check that whitespace is ignored appropriately. A symbol with a
4602 template argument list. */
4604 static const char expected
[] = "ns::foo<int>";
4605 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4609 /* Check that whitespace is ignored appropriately. A symbol with a
4610 template argument list that includes a pointer. */
4612 static const char expected
[] = "ns::foo<char*>";
4613 /* Try both completion and non-completion modes. */
4614 static const bool completion_mode
[2] = {false, true};
4615 for (size_t i
= 0; i
< 2; i
++)
4617 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4618 completion_mode
[i
], EXPECT (expected
));
4620 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4621 completion_mode
[i
], EXPECT (expected
));
4626 /* Check method qualifiers are ignored. */
4627 static const char expected
[] = "ns::foo<char*>";
4628 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4629 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4630 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4631 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4634 /* Test lookup names that don't match anything. */
4636 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4640 SELF_CHECK (!any_mismatch
);
4646 }} // namespace selftests::dw2_expand_symtabs_matching
4648 #endif /* GDB_SELF_TEST */
4650 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4651 matched, to expand corresponding CUs that were marked. IDX is the
4652 index of the symbol name that matched. */
4655 dw2_expand_marked_cus
4656 (mapped_index
&index
, offset_type idx
,
4657 struct objfile
*objfile
,
4658 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4659 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4663 offset_type
*vec
, vec_len
, vec_idx
;
4664 bool global_seen
= false;
4666 vec
= (offset_type
*) (index
.constant_pool
4667 + MAYBE_SWAP (index
.symbol_table
[idx
+ 1]));
4668 vec_len
= MAYBE_SWAP (vec
[0]);
4669 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4671 struct dwarf2_per_cu_data
*per_cu
;
4672 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4673 /* This value is only valid for index versions >= 7. */
4674 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4675 gdb_index_symbol_kind symbol_kind
=
4676 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4677 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4678 /* Only check the symbol attributes if they're present.
4679 Indices prior to version 7 don't record them,
4680 and indices >= 7 may elide them for certain symbols
4681 (gold does this). */
4684 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4686 /* Work around gold/15646. */
4689 if (!is_static
&& global_seen
)
4695 /* Only check the symbol's kind if it has one. */
4700 case VARIABLES_DOMAIN
:
4701 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4704 case FUNCTIONS_DOMAIN
:
4705 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4709 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4717 /* Don't crash on bad data. */
4718 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
4719 + dwarf2_per_objfile
->n_type_units
))
4721 complaint (&symfile_complaints
,
4722 _(".gdb_index entry has bad CU index"
4723 " [in module %s]"), objfile_name (objfile
));
4727 per_cu
= dw2_get_cutu (cu_index
);
4728 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4730 int symtab_was_null
=
4731 (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4733 dw2_instantiate_symtab (per_cu
);
4735 if (expansion_notify
!= NULL
4737 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
4738 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
4744 dw2_expand_symtabs_matching
4745 (struct objfile
*objfile
,
4746 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4747 const lookup_name_info
&lookup_name
,
4748 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4749 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4750 enum search_domain kind
)
4755 dw2_setup (objfile
);
4757 /* index_table is NULL if OBJF_READNOW. */
4758 if (!dwarf2_per_objfile
->index_table
)
4761 if (file_matcher
!= NULL
)
4763 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4765 NULL
, xcalloc
, xfree
));
4766 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4768 NULL
, xcalloc
, xfree
));
4770 /* The rule is CUs specify all the files, including those used by
4771 any TU, so there's no need to scan TUs here. */
4773 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4776 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
4777 struct quick_file_names
*file_data
;
4782 per_cu
->v
.quick
->mark
= 0;
4784 /* We only need to look at symtabs not already expanded. */
4785 if (per_cu
->v
.quick
->compunit_symtab
)
4788 file_data
= dw2_get_file_names (per_cu
);
4789 if (file_data
== NULL
)
4792 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4794 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4796 per_cu
->v
.quick
->mark
= 1;
4800 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
4802 const char *this_real_name
;
4804 if (file_matcher (file_data
->file_names
[j
], false))
4806 per_cu
->v
.quick
->mark
= 1;
4810 /* Before we invoke realpath, which can get expensive when many
4811 files are involved, do a quick comparison of the basenames. */
4812 if (!basenames_may_differ
4813 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4817 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4818 if (file_matcher (this_real_name
, false))
4820 per_cu
->v
.quick
->mark
= 1;
4825 slot
= htab_find_slot (per_cu
->v
.quick
->mark
4826 ? visited_found
.get ()
4827 : visited_not_found
.get (),
4833 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4835 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
4837 kind
, [&] (offset_type idx
)
4839 dw2_expand_marked_cus (index
, idx
, objfile
, file_matcher
,
4840 expansion_notify
, kind
);
4844 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4847 static struct compunit_symtab
*
4848 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4853 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4854 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4857 if (cust
->includes
== NULL
)
4860 for (i
= 0; cust
->includes
[i
]; ++i
)
4862 struct compunit_symtab
*s
= cust
->includes
[i
];
4864 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4872 static struct compunit_symtab
*
4873 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4874 struct bound_minimal_symbol msymbol
,
4876 struct obj_section
*section
,
4879 struct dwarf2_per_cu_data
*data
;
4880 struct compunit_symtab
*result
;
4882 dw2_setup (objfile
);
4884 if (!objfile
->psymtabs_addrmap
)
4887 data
= (struct dwarf2_per_cu_data
*) addrmap_find (objfile
->psymtabs_addrmap
,
4892 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
4893 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4894 paddress (get_objfile_arch (objfile
), pc
));
4897 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
),
4899 gdb_assert (result
!= NULL
);
4904 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4905 void *data
, int need_fullname
)
4907 dw2_setup (objfile
);
4909 if (!dwarf2_per_objfile
->filenames_cache
)
4911 dwarf2_per_objfile
->filenames_cache
.emplace ();
4913 htab_up
visited (htab_create_alloc (10,
4914 htab_hash_pointer
, htab_eq_pointer
,
4915 NULL
, xcalloc
, xfree
));
4917 /* The rule is CUs specify all the files, including those used
4918 by any TU, so there's no need to scan TUs here. We can
4919 ignore file names coming from already-expanded CUs. */
4921 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4923 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
4925 if (per_cu
->v
.quick
->compunit_symtab
)
4927 void **slot
= htab_find_slot (visited
.get (),
4928 per_cu
->v
.quick
->file_names
,
4931 *slot
= per_cu
->v
.quick
->file_names
;
4935 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4938 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
4939 struct quick_file_names
*file_data
;
4942 /* We only need to look at symtabs not already expanded. */
4943 if (per_cu
->v
.quick
->compunit_symtab
)
4946 file_data
= dw2_get_file_names (per_cu
);
4947 if (file_data
== NULL
)
4950 slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4953 /* Already visited. */
4958 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4960 const char *filename
= file_data
->file_names
[j
];
4961 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
4966 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
4968 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4971 this_real_name
= gdb_realpath (filename
);
4972 (*fun
) (filename
, this_real_name
.get (), data
);
4977 dw2_has_symbols (struct objfile
*objfile
)
4982 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4985 dw2_find_last_source_symtab
,
4986 dw2_forget_cached_source_info
,
4987 dw2_map_symtabs_matching_filename
,
4992 dw2_expand_symtabs_for_function
,
4993 dw2_expand_all_symtabs
,
4994 dw2_expand_symtabs_with_fullname
,
4995 dw2_map_matching_symbols
,
4996 dw2_expand_symtabs_matching
,
4997 dw2_find_pc_sect_compunit_symtab
,
4998 dw2_map_symbol_filenames
5001 /* Initialize for reading DWARF for this objfile. Return 0 if this
5002 file will use psymtabs, or 1 if using the GNU index. */
5005 dwarf2_initialize_objfile (struct objfile
*objfile
)
5007 /* If we're about to read full symbols, don't bother with the
5008 indices. In this case we also don't care if some other debug
5009 format is making psymtabs, because they are all about to be
5011 if ((objfile
->flags
& OBJF_READNOW
))
5015 dwarf2_per_objfile
->using_index
= 1;
5016 create_all_comp_units (objfile
);
5017 create_all_type_units (objfile
);
5018 dwarf2_per_objfile
->quick_file_names_table
=
5019 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
5021 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
5022 + dwarf2_per_objfile
->n_type_units
); ++i
)
5024 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
5026 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5027 struct dwarf2_per_cu_quick_data
);
5030 /* Return 1 so that gdb sees the "quick" functions. However,
5031 these functions will be no-ops because we will have expanded
5036 if (dwarf2_read_index (objfile
))
5044 /* Build a partial symbol table. */
5047 dwarf2_build_psymtabs (struct objfile
*objfile
)
5050 if (objfile
->global_psymbols
.capacity () == 0
5051 && objfile
->static_psymbols
.capacity () == 0)
5052 init_psymbol_list (objfile
, 1024);
5056 /* This isn't really ideal: all the data we allocate on the
5057 objfile's obstack is still uselessly kept around. However,
5058 freeing it seems unsafe. */
5059 psymtab_discarder
psymtabs (objfile
);
5060 dwarf2_build_psymtabs_hard (objfile
);
5063 CATCH (except
, RETURN_MASK_ERROR
)
5065 exception_print (gdb_stderr
, except
);
5070 /* Return the total length of the CU described by HEADER. */
5073 get_cu_length (const struct comp_unit_head
*header
)
5075 return header
->initial_length_size
+ header
->length
;
5078 /* Return TRUE if SECT_OFF is within CU_HEADER. */
5081 offset_in_cu_p (const comp_unit_head
*cu_header
, sect_offset sect_off
)
5083 sect_offset bottom
= cu_header
->sect_off
;
5084 sect_offset top
= cu_header
->sect_off
+ get_cu_length (cu_header
);
5086 return sect_off
>= bottom
&& sect_off
< top
;
5089 /* Find the base address of the compilation unit for range lists and
5090 location lists. It will normally be specified by DW_AT_low_pc.
5091 In DWARF-3 draft 4, the base address could be overridden by
5092 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5093 compilation units with discontinuous ranges. */
5096 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5098 struct attribute
*attr
;
5101 cu
->base_address
= 0;
5103 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
5106 cu
->base_address
= attr_value_as_address (attr
);
5111 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5114 cu
->base_address
= attr_value_as_address (attr
);
5120 /* Read in the comp unit header information from the debug_info at info_ptr.
5121 Use rcuh_kind::COMPILE as the default type if not known by the caller.
5122 NOTE: This leaves members offset, first_die_offset to be filled in
5125 static const gdb_byte
*
5126 read_comp_unit_head (struct comp_unit_head
*cu_header
,
5127 const gdb_byte
*info_ptr
,
5128 struct dwarf2_section_info
*section
,
5129 rcuh_kind section_kind
)
5132 unsigned int bytes_read
;
5133 const char *filename
= get_section_file_name (section
);
5134 bfd
*abfd
= get_section_bfd_owner (section
);
5136 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
5137 cu_header
->initial_length_size
= bytes_read
;
5138 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
5139 info_ptr
+= bytes_read
;
5140 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
5142 if (cu_header
->version
< 5)
5143 switch (section_kind
)
5145 case rcuh_kind::COMPILE
:
5146 cu_header
->unit_type
= DW_UT_compile
;
5148 case rcuh_kind::TYPE
:
5149 cu_header
->unit_type
= DW_UT_type
;
5152 internal_error (__FILE__
, __LINE__
,
5153 _("read_comp_unit_head: invalid section_kind"));
5157 cu_header
->unit_type
= static_cast<enum dwarf_unit_type
>
5158 (read_1_byte (abfd
, info_ptr
));
5160 switch (cu_header
->unit_type
)
5163 if (section_kind
!= rcuh_kind::COMPILE
)
5164 error (_("Dwarf Error: wrong unit_type in compilation unit header "
5165 "(is DW_UT_compile, should be DW_UT_type) [in module %s]"),
5169 section_kind
= rcuh_kind::TYPE
;
5172 error (_("Dwarf Error: wrong unit_type in compilation unit header "
5173 "(is %d, should be %d or %d) [in module %s]"),
5174 cu_header
->unit_type
, DW_UT_compile
, DW_UT_type
, filename
);
5177 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
5180 cu_header
->abbrev_sect_off
= (sect_offset
) read_offset (abfd
, info_ptr
,
5183 info_ptr
+= bytes_read
;
5184 if (cu_header
->version
< 5)
5186 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
5189 signed_addr
= bfd_get_sign_extend_vma (abfd
);
5190 if (signed_addr
< 0)
5191 internal_error (__FILE__
, __LINE__
,
5192 _("read_comp_unit_head: dwarf from non elf file"));
5193 cu_header
->signed_addr_p
= signed_addr
;
5195 if (section_kind
== rcuh_kind::TYPE
)
5197 LONGEST type_offset
;
5199 cu_header
->signature
= read_8_bytes (abfd
, info_ptr
);
5202 type_offset
= read_offset (abfd
, info_ptr
, cu_header
, &bytes_read
);
5203 info_ptr
+= bytes_read
;
5204 cu_header
->type_cu_offset_in_tu
= (cu_offset
) type_offset
;
5205 if (to_underlying (cu_header
->type_cu_offset_in_tu
) != type_offset
)
5206 error (_("Dwarf Error: Too big type_offset in compilation unit "
5207 "header (is %s) [in module %s]"), plongest (type_offset
),
5214 /* Helper function that returns the proper abbrev section for
5217 static struct dwarf2_section_info
*
5218 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
5220 struct dwarf2_section_info
*abbrev
;
5222 if (this_cu
->is_dwz
)
5223 abbrev
= &dwarf2_get_dwz_file ()->abbrev
;
5225 abbrev
= &dwarf2_per_objfile
->abbrev
;
5230 /* Subroutine of read_and_check_comp_unit_head and
5231 read_and_check_type_unit_head to simplify them.
5232 Perform various error checking on the header. */
5235 error_check_comp_unit_head (struct comp_unit_head
*header
,
5236 struct dwarf2_section_info
*section
,
5237 struct dwarf2_section_info
*abbrev_section
)
5239 const char *filename
= get_section_file_name (section
);
5241 if (header
->version
< 2 || header
->version
> 5)
5242 error (_("Dwarf Error: wrong version in compilation unit header "
5243 "(is %d, should be 2, 3, 4 or 5) [in module %s]"), header
->version
,
5246 if (to_underlying (header
->abbrev_sect_off
)
5247 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
5248 error (_("Dwarf Error: bad offset (0x%x) in compilation unit header "
5249 "(offset 0x%x + 6) [in module %s]"),
5250 to_underlying (header
->abbrev_sect_off
),
5251 to_underlying (header
->sect_off
),
5254 /* Cast to ULONGEST to use 64-bit arithmetic when possible to
5255 avoid potential 32-bit overflow. */
5256 if (((ULONGEST
) header
->sect_off
+ get_cu_length (header
))
5258 error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
5259 "(offset 0x%x + 0) [in module %s]"),
5260 header
->length
, to_underlying (header
->sect_off
),
5264 /* Read in a CU/TU header and perform some basic error checking.
5265 The contents of the header are stored in HEADER.
5266 The result is a pointer to the start of the first DIE. */
5268 static const gdb_byte
*
5269 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
5270 struct dwarf2_section_info
*section
,
5271 struct dwarf2_section_info
*abbrev_section
,
5272 const gdb_byte
*info_ptr
,
5273 rcuh_kind section_kind
)
5275 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
5276 bfd
*abfd
= get_section_bfd_owner (section
);
5278 header
->sect_off
= (sect_offset
) (beg_of_comp_unit
- section
->buffer
);
5280 info_ptr
= read_comp_unit_head (header
, info_ptr
, section
, section_kind
);
5282 header
->first_die_cu_offset
= (cu_offset
) (info_ptr
- beg_of_comp_unit
);
5284 error_check_comp_unit_head (header
, section
, abbrev_section
);
5289 /* Fetch the abbreviation table offset from a comp or type unit header. */
5292 read_abbrev_offset (struct dwarf2_section_info
*section
,
5293 sect_offset sect_off
)
5295 bfd
*abfd
= get_section_bfd_owner (section
);
5296 const gdb_byte
*info_ptr
;
5297 unsigned int initial_length_size
, offset_size
;
5300 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
5301 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
5302 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5303 offset_size
= initial_length_size
== 4 ? 4 : 8;
5304 info_ptr
+= initial_length_size
;
5306 version
= read_2_bytes (abfd
, info_ptr
);
5310 /* Skip unit type and address size. */
5314 return (sect_offset
) read_offset_1 (abfd
, info_ptr
, offset_size
);
5317 /* Allocate a new partial symtab for file named NAME and mark this new
5318 partial symtab as being an include of PST. */
5321 dwarf2_create_include_psymtab (const char *name
, struct partial_symtab
*pst
,
5322 struct objfile
*objfile
)
5324 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
5326 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
5328 /* It shares objfile->objfile_obstack. */
5329 subpst
->dirname
= pst
->dirname
;
5332 subpst
->textlow
= 0;
5333 subpst
->texthigh
= 0;
5335 subpst
->dependencies
5336 = XOBNEW (&objfile
->objfile_obstack
, struct partial_symtab
*);
5337 subpst
->dependencies
[0] = pst
;
5338 subpst
->number_of_dependencies
= 1;
5340 subpst
->globals_offset
= 0;
5341 subpst
->n_global_syms
= 0;
5342 subpst
->statics_offset
= 0;
5343 subpst
->n_static_syms
= 0;
5344 subpst
->compunit_symtab
= NULL
;
5345 subpst
->read_symtab
= pst
->read_symtab
;
5348 /* No private part is necessary for include psymtabs. This property
5349 can be used to differentiate between such include psymtabs and
5350 the regular ones. */
5351 subpst
->read_symtab_private
= NULL
;
5354 /* Read the Line Number Program data and extract the list of files
5355 included by the source file represented by PST. Build an include
5356 partial symtab for each of these included files. */
5359 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
5360 struct die_info
*die
,
5361 struct partial_symtab
*pst
)
5364 struct attribute
*attr
;
5366 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5368 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
5370 return; /* No linetable, so no includes. */
5372 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
5373 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
, pst
->textlow
, 1);
5377 hash_signatured_type (const void *item
)
5379 const struct signatured_type
*sig_type
5380 = (const struct signatured_type
*) item
;
5382 /* This drops the top 32 bits of the signature, but is ok for a hash. */
5383 return sig_type
->signature
;
5387 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
5389 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
5390 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
5392 return lhs
->signature
== rhs
->signature
;
5395 /* Allocate a hash table for signatured types. */
5398 allocate_signatured_type_table (struct objfile
*objfile
)
5400 return htab_create_alloc_ex (41,
5401 hash_signatured_type
,
5404 &objfile
->objfile_obstack
,
5405 hashtab_obstack_allocate
,
5406 dummy_obstack_deallocate
);
5409 /* A helper function to add a signatured type CU to a table. */
5412 add_signatured_type_cu_to_table (void **slot
, void *datum
)
5414 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
5415 struct signatured_type
***datap
= (struct signatured_type
***) datum
;
5423 /* A helper for create_debug_types_hash_table. Read types from SECTION
5424 and fill them into TYPES_HTAB. It will process only type units,
5425 therefore DW_UT_type. */
5428 create_debug_type_hash_table (struct dwo_file
*dwo_file
,
5429 dwarf2_section_info
*section
, htab_t
&types_htab
,
5430 rcuh_kind section_kind
)
5432 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5433 struct dwarf2_section_info
*abbrev_section
;
5435 const gdb_byte
*info_ptr
, *end_ptr
;
5437 abbrev_section
= (dwo_file
!= NULL
5438 ? &dwo_file
->sections
.abbrev
5439 : &dwarf2_per_objfile
->abbrev
);
5441 if (dwarf_read_debug
)
5442 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
5443 get_section_name (section
),
5444 get_section_file_name (abbrev_section
));
5446 dwarf2_read_section (objfile
, section
);
5447 info_ptr
= section
->buffer
;
5449 if (info_ptr
== NULL
)
5452 /* We can't set abfd until now because the section may be empty or
5453 not present, in which case the bfd is unknown. */
5454 abfd
= get_section_bfd_owner (section
);
5456 /* We don't use init_cutu_and_read_dies_simple, or some such, here
5457 because we don't need to read any dies: the signature is in the
5460 end_ptr
= info_ptr
+ section
->size
;
5461 while (info_ptr
< end_ptr
)
5463 struct signatured_type
*sig_type
;
5464 struct dwo_unit
*dwo_tu
;
5466 const gdb_byte
*ptr
= info_ptr
;
5467 struct comp_unit_head header
;
5468 unsigned int length
;
5470 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
5472 /* Initialize it due to a false compiler warning. */
5473 header
.signature
= -1;
5474 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
5476 /* We need to read the type's signature in order to build the hash
5477 table, but we don't need anything else just yet. */
5479 ptr
= read_and_check_comp_unit_head (&header
, section
,
5480 abbrev_section
, ptr
, section_kind
);
5482 length
= get_cu_length (&header
);
5484 /* Skip dummy type units. */
5485 if (ptr
>= info_ptr
+ length
5486 || peek_abbrev_code (abfd
, ptr
) == 0
5487 || header
.unit_type
!= DW_UT_type
)
5493 if (types_htab
== NULL
)
5496 types_htab
= allocate_dwo_unit_table (objfile
);
5498 types_htab
= allocate_signatured_type_table (objfile
);
5504 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5506 dwo_tu
->dwo_file
= dwo_file
;
5507 dwo_tu
->signature
= header
.signature
;
5508 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
5509 dwo_tu
->section
= section
;
5510 dwo_tu
->sect_off
= sect_off
;
5511 dwo_tu
->length
= length
;
5515 /* N.B.: type_offset is not usable if this type uses a DWO file.
5516 The real type_offset is in the DWO file. */
5518 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5519 struct signatured_type
);
5520 sig_type
->signature
= header
.signature
;
5521 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
5522 sig_type
->per_cu
.objfile
= objfile
;
5523 sig_type
->per_cu
.is_debug_types
= 1;
5524 sig_type
->per_cu
.section
= section
;
5525 sig_type
->per_cu
.sect_off
= sect_off
;
5526 sig_type
->per_cu
.length
= length
;
5529 slot
= htab_find_slot (types_htab
,
5530 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
5532 gdb_assert (slot
!= NULL
);
5535 sect_offset dup_sect_off
;
5539 const struct dwo_unit
*dup_tu
5540 = (const struct dwo_unit
*) *slot
;
5542 dup_sect_off
= dup_tu
->sect_off
;
5546 const struct signatured_type
*dup_tu
5547 = (const struct signatured_type
*) *slot
;
5549 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
5552 complaint (&symfile_complaints
,
5553 _("debug type entry at offset 0x%x is duplicate to"
5554 " the entry at offset 0x%x, signature %s"),
5555 to_underlying (sect_off
), to_underlying (dup_sect_off
),
5556 hex_string (header
.signature
));
5558 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
5560 if (dwarf_read_debug
> 1)
5561 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature %s\n",
5562 to_underlying (sect_off
),
5563 hex_string (header
.signature
));
5569 /* Create the hash table of all entries in the .debug_types
5570 (or .debug_types.dwo) section(s).
5571 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
5572 otherwise it is NULL.
5574 The result is a pointer to the hash table or NULL if there are no types.
5576 Note: This function processes DWO files only, not DWP files. */
5579 create_debug_types_hash_table (struct dwo_file
*dwo_file
,
5580 VEC (dwarf2_section_info_def
) *types
,
5584 struct dwarf2_section_info
*section
;
5586 if (VEC_empty (dwarf2_section_info_def
, types
))
5590 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
5592 create_debug_type_hash_table (dwo_file
, section
, types_htab
,
5596 /* Create the hash table of all entries in the .debug_types section,
5597 and initialize all_type_units.
5598 The result is zero if there is an error (e.g. missing .debug_types section),
5599 otherwise non-zero. */
5602 create_all_type_units (struct objfile
*objfile
)
5604 htab_t types_htab
= NULL
;
5605 struct signatured_type
**iter
;
5607 create_debug_type_hash_table (NULL
, &dwarf2_per_objfile
->info
, types_htab
,
5608 rcuh_kind::COMPILE
);
5609 create_debug_types_hash_table (NULL
, dwarf2_per_objfile
->types
, types_htab
);
5610 if (types_htab
== NULL
)
5612 dwarf2_per_objfile
->signatured_types
= NULL
;
5616 dwarf2_per_objfile
->signatured_types
= types_htab
;
5618 dwarf2_per_objfile
->n_type_units
5619 = dwarf2_per_objfile
->n_allocated_type_units
5620 = htab_elements (types_htab
);
5621 dwarf2_per_objfile
->all_type_units
=
5622 XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
5623 iter
= &dwarf2_per_objfile
->all_type_units
[0];
5624 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
5625 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
5626 == dwarf2_per_objfile
->n_type_units
);
5631 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
5632 If SLOT is non-NULL, it is the entry to use in the hash table.
5633 Otherwise we find one. */
5635 static struct signatured_type
*
5636 add_type_unit (ULONGEST sig
, void **slot
)
5638 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5639 int n_type_units
= dwarf2_per_objfile
->n_type_units
;
5640 struct signatured_type
*sig_type
;
5642 gdb_assert (n_type_units
<= dwarf2_per_objfile
->n_allocated_type_units
);
5644 if (n_type_units
> dwarf2_per_objfile
->n_allocated_type_units
)
5646 if (dwarf2_per_objfile
->n_allocated_type_units
== 0)
5647 dwarf2_per_objfile
->n_allocated_type_units
= 1;
5648 dwarf2_per_objfile
->n_allocated_type_units
*= 2;
5649 dwarf2_per_objfile
->all_type_units
5650 = XRESIZEVEC (struct signatured_type
*,
5651 dwarf2_per_objfile
->all_type_units
,
5652 dwarf2_per_objfile
->n_allocated_type_units
);
5653 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
5655 dwarf2_per_objfile
->n_type_units
= n_type_units
;
5657 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5658 struct signatured_type
);
5659 dwarf2_per_objfile
->all_type_units
[n_type_units
- 1] = sig_type
;
5660 sig_type
->signature
= sig
;
5661 sig_type
->per_cu
.is_debug_types
= 1;
5662 if (dwarf2_per_objfile
->using_index
)
5664 sig_type
->per_cu
.v
.quick
=
5665 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5666 struct dwarf2_per_cu_quick_data
);
5671 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
5674 gdb_assert (*slot
== NULL
);
5676 /* The rest of sig_type must be filled in by the caller. */
5680 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
5681 Fill in SIG_ENTRY with DWO_ENTRY. */
5684 fill_in_sig_entry_from_dwo_entry (struct objfile
*objfile
,
5685 struct signatured_type
*sig_entry
,
5686 struct dwo_unit
*dwo_entry
)
5688 /* Make sure we're not clobbering something we don't expect to. */
5689 gdb_assert (! sig_entry
->per_cu
.queued
);
5690 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
5691 if (dwarf2_per_objfile
->using_index
)
5693 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
5694 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
5697 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
5698 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
5699 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
5700 gdb_assert (sig_entry
->type_unit_group
== NULL
);
5701 gdb_assert (sig_entry
->dwo_unit
== NULL
);
5703 sig_entry
->per_cu
.section
= dwo_entry
->section
;
5704 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
5705 sig_entry
->per_cu
.length
= dwo_entry
->length
;
5706 sig_entry
->per_cu
.reading_dwo_directly
= 1;
5707 sig_entry
->per_cu
.objfile
= objfile
;
5708 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
5709 sig_entry
->dwo_unit
= dwo_entry
;
5712 /* Subroutine of lookup_signatured_type.
5713 If we haven't read the TU yet, create the signatured_type data structure
5714 for a TU to be read in directly from a DWO file, bypassing the stub.
5715 This is the "Stay in DWO Optimization": When there is no DWP file and we're
5716 using .gdb_index, then when reading a CU we want to stay in the DWO file
5717 containing that CU. Otherwise we could end up reading several other DWO
5718 files (due to comdat folding) to process the transitive closure of all the
5719 mentioned TUs, and that can be slow. The current DWO file will have every
5720 type signature that it needs.
5721 We only do this for .gdb_index because in the psymtab case we already have
5722 to read all the DWOs to build the type unit groups. */
5724 static struct signatured_type
*
5725 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
5727 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5728 struct dwo_file
*dwo_file
;
5729 struct dwo_unit find_dwo_entry
, *dwo_entry
;
5730 struct signatured_type find_sig_entry
, *sig_entry
;
5733 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
5735 /* If TU skeletons have been removed then we may not have read in any
5737 if (dwarf2_per_objfile
->signatured_types
== NULL
)
5739 dwarf2_per_objfile
->signatured_types
5740 = allocate_signatured_type_table (objfile
);
5743 /* We only ever need to read in one copy of a signatured type.
5744 Use the global signatured_types array to do our own comdat-folding
5745 of types. If this is the first time we're reading this TU, and
5746 the TU has an entry in .gdb_index, replace the recorded data from
5747 .gdb_index with this TU. */
5749 find_sig_entry
.signature
= sig
;
5750 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
5751 &find_sig_entry
, INSERT
);
5752 sig_entry
= (struct signatured_type
*) *slot
;
5754 /* We can get here with the TU already read, *or* in the process of being
5755 read. Don't reassign the global entry to point to this DWO if that's
5756 the case. Also note that if the TU is already being read, it may not
5757 have come from a DWO, the program may be a mix of Fission-compiled
5758 code and non-Fission-compiled code. */
5760 /* Have we already tried to read this TU?
5761 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
5762 needn't exist in the global table yet). */
5763 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
5766 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
5767 dwo_unit of the TU itself. */
5768 dwo_file
= cu
->dwo_unit
->dwo_file
;
5770 /* Ok, this is the first time we're reading this TU. */
5771 if (dwo_file
->tus
== NULL
)
5773 find_dwo_entry
.signature
= sig
;
5774 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_entry
);
5775 if (dwo_entry
== NULL
)
5778 /* If the global table doesn't have an entry for this TU, add one. */
5779 if (sig_entry
== NULL
)
5780 sig_entry
= add_type_unit (sig
, slot
);
5782 fill_in_sig_entry_from_dwo_entry (objfile
, sig_entry
, dwo_entry
);
5783 sig_entry
->per_cu
.tu_read
= 1;
5787 /* Subroutine of lookup_signatured_type.
5788 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
5789 then try the DWP file. If the TU stub (skeleton) has been removed then
5790 it won't be in .gdb_index. */
5792 static struct signatured_type
*
5793 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
5795 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5796 struct dwp_file
*dwp_file
= get_dwp_file ();
5797 struct dwo_unit
*dwo_entry
;
5798 struct signatured_type find_sig_entry
, *sig_entry
;
5801 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
5802 gdb_assert (dwp_file
!= NULL
);
5804 /* If TU skeletons have been removed then we may not have read in any
5806 if (dwarf2_per_objfile
->signatured_types
== NULL
)
5808 dwarf2_per_objfile
->signatured_types
5809 = allocate_signatured_type_table (objfile
);
5812 find_sig_entry
.signature
= sig
;
5813 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
5814 &find_sig_entry
, INSERT
);
5815 sig_entry
= (struct signatured_type
*) *slot
;
5817 /* Have we already tried to read this TU?
5818 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
5819 needn't exist in the global table yet). */
5820 if (sig_entry
!= NULL
)
5823 if (dwp_file
->tus
== NULL
)
5825 dwo_entry
= lookup_dwo_unit_in_dwp (dwp_file
, NULL
,
5826 sig
, 1 /* is_debug_types */);
5827 if (dwo_entry
== NULL
)
5830 sig_entry
= add_type_unit (sig
, slot
);
5831 fill_in_sig_entry_from_dwo_entry (objfile
, sig_entry
, dwo_entry
);
5836 /* Lookup a signature based type for DW_FORM_ref_sig8.
5837 Returns NULL if signature SIG is not present in the table.
5838 It is up to the caller to complain about this. */
5840 static struct signatured_type
*
5841 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
5844 && dwarf2_per_objfile
->using_index
)
5846 /* We're in a DWO/DWP file, and we're using .gdb_index.
5847 These cases require special processing. */
5848 if (get_dwp_file () == NULL
)
5849 return lookup_dwo_signatured_type (cu
, sig
);
5851 return lookup_dwp_signatured_type (cu
, sig
);
5855 struct signatured_type find_entry
, *entry
;
5857 if (dwarf2_per_objfile
->signatured_types
== NULL
)
5859 find_entry
.signature
= sig
;
5860 entry
= ((struct signatured_type
*)
5861 htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
));
5866 /* Low level DIE reading support. */
5868 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
5871 init_cu_die_reader (struct die_reader_specs
*reader
,
5872 struct dwarf2_cu
*cu
,
5873 struct dwarf2_section_info
*section
,
5874 struct dwo_file
*dwo_file
)
5876 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
5877 reader
->abfd
= get_section_bfd_owner (section
);
5879 reader
->dwo_file
= dwo_file
;
5880 reader
->die_section
= section
;
5881 reader
->buffer
= section
->buffer
;
5882 reader
->buffer_end
= section
->buffer
+ section
->size
;
5883 reader
->comp_dir
= NULL
;
5886 /* Subroutine of init_cutu_and_read_dies to simplify it.
5887 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
5888 There's just a lot of work to do, and init_cutu_and_read_dies is big enough
5891 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
5892 from it to the DIE in the DWO. If NULL we are skipping the stub.
5893 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
5894 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
5895 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
5896 STUB_COMP_DIR may be non-NULL.
5897 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
5898 are filled in with the info of the DIE from the DWO file.
5899 ABBREV_TABLE_PROVIDED is non-zero if the caller of init_cutu_and_read_dies
5900 provided an abbrev table to use.
5901 The result is non-zero if a valid (non-dummy) DIE was found. */
5904 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
5905 struct dwo_unit
*dwo_unit
,
5906 int abbrev_table_provided
,
5907 struct die_info
*stub_comp_unit_die
,
5908 const char *stub_comp_dir
,
5909 struct die_reader_specs
*result_reader
,
5910 const gdb_byte
**result_info_ptr
,
5911 struct die_info
**result_comp_unit_die
,
5912 int *result_has_children
)
5914 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5915 struct dwarf2_cu
*cu
= this_cu
->cu
;
5916 struct dwarf2_section_info
*section
;
5918 const gdb_byte
*begin_info_ptr
, *info_ptr
;
5919 ULONGEST signature
; /* Or dwo_id. */
5920 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
5921 int i
,num_extra_attrs
;
5922 struct dwarf2_section_info
*dwo_abbrev_section
;
5923 struct attribute
*attr
;
5924 struct die_info
*comp_unit_die
;
5926 /* At most one of these may be provided. */
5927 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
5929 /* These attributes aren't processed until later:
5930 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
5931 DW_AT_comp_dir is used now, to find the DWO file, but it is also
5932 referenced later. However, these attributes are found in the stub
5933 which we won't have later. In order to not impose this complication
5934 on the rest of the code, we read them here and copy them to the
5943 if (stub_comp_unit_die
!= NULL
)
5945 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
5947 if (! this_cu
->is_debug_types
)
5948 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
5949 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
5950 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
5951 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
5952 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
5954 /* There should be a DW_AT_addr_base attribute here (if needed).
5955 We need the value before we can process DW_FORM_GNU_addr_index. */
5957 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
5959 cu
->addr_base
= DW_UNSND (attr
);
5961 /* There should be a DW_AT_ranges_base attribute here (if needed).
5962 We need the value before we can process DW_AT_ranges. */
5963 cu
->ranges_base
= 0;
5964 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
5966 cu
->ranges_base
= DW_UNSND (attr
);
5968 else if (stub_comp_dir
!= NULL
)
5970 /* Reconstruct the comp_dir attribute to simplify the code below. */
5971 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
5972 comp_dir
->name
= DW_AT_comp_dir
;
5973 comp_dir
->form
= DW_FORM_string
;
5974 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
5975 DW_STRING (comp_dir
) = stub_comp_dir
;
5978 /* Set up for reading the DWO CU/TU. */
5979 cu
->dwo_unit
= dwo_unit
;
5980 section
= dwo_unit
->section
;
5981 dwarf2_read_section (objfile
, section
);
5982 abfd
= get_section_bfd_owner (section
);
5983 begin_info_ptr
= info_ptr
= (section
->buffer
5984 + to_underlying (dwo_unit
->sect_off
));
5985 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
5986 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
);
5988 if (this_cu
->is_debug_types
)
5990 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
5992 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
5994 info_ptr
, rcuh_kind::TYPE
);
5995 /* This is not an assert because it can be caused by bad debug info. */
5996 if (sig_type
->signature
!= cu
->header
.signature
)
5998 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
5999 " TU at offset 0x%x [in module %s]"),
6000 hex_string (sig_type
->signature
),
6001 hex_string (cu
->header
.signature
),
6002 to_underlying (dwo_unit
->sect_off
),
6003 bfd_get_filename (abfd
));
6005 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6006 /* For DWOs coming from DWP files, we don't know the CU length
6007 nor the type's offset in the TU until now. */
6008 dwo_unit
->length
= get_cu_length (&cu
->header
);
6009 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6011 /* Establish the type offset that can be used to lookup the type.
6012 For DWO files, we don't know it until now. */
6013 sig_type
->type_offset_in_section
6014 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6018 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
6020 info_ptr
, rcuh_kind::COMPILE
);
6021 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6022 /* For DWOs coming from DWP files, we don't know the CU length
6024 dwo_unit
->length
= get_cu_length (&cu
->header
);
6027 /* Replace the CU's original abbrev table with the DWO's.
6028 Reminder: We can't read the abbrev table until we've read the header. */
6029 if (abbrev_table_provided
)
6031 /* Don't free the provided abbrev table, the caller of
6032 init_cutu_and_read_dies owns it. */
6033 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
6034 /* Ensure the DWO abbrev table gets freed. */
6035 make_cleanup (dwarf2_free_abbrev_table
, cu
);
6039 dwarf2_free_abbrev_table (cu
);
6040 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
6041 /* Leave any existing abbrev table cleanup as is. */
6044 /* Read in the die, but leave space to copy over the attributes
6045 from the stub. This has the benefit of simplifying the rest of
6046 the code - all the work to maintain the illusion of a single
6047 DW_TAG_{compile,type}_unit DIE is done here. */
6048 num_extra_attrs
= ((stmt_list
!= NULL
)
6052 + (comp_dir
!= NULL
));
6053 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6054 result_has_children
, num_extra_attrs
);
6056 /* Copy over the attributes from the stub to the DIE we just read in. */
6057 comp_unit_die
= *result_comp_unit_die
;
6058 i
= comp_unit_die
->num_attrs
;
6059 if (stmt_list
!= NULL
)
6060 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6062 comp_unit_die
->attrs
[i
++] = *low_pc
;
6063 if (high_pc
!= NULL
)
6064 comp_unit_die
->attrs
[i
++] = *high_pc
;
6066 comp_unit_die
->attrs
[i
++] = *ranges
;
6067 if (comp_dir
!= NULL
)
6068 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6069 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6071 if (dwarf_die_debug
)
6073 fprintf_unfiltered (gdb_stdlog
,
6074 "Read die from %s@0x%x of %s:\n",
6075 get_section_name (section
),
6076 (unsigned) (begin_info_ptr
- section
->buffer
),
6077 bfd_get_filename (abfd
));
6078 dump_die (comp_unit_die
, dwarf_die_debug
);
6081 /* Save the comp_dir attribute. If there is no DWP file then we'll read
6082 TUs by skipping the stub and going directly to the entry in the DWO file.
6083 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
6084 to get it via circuitous means. Blech. */
6085 if (comp_dir
!= NULL
)
6086 result_reader
->comp_dir
= DW_STRING (comp_dir
);
6088 /* Skip dummy compilation units. */
6089 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6090 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6093 *result_info_ptr
= info_ptr
;
6097 /* Subroutine of init_cutu_and_read_dies to simplify it.
6098 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6099 Returns NULL if the specified DWO unit cannot be found. */
6101 static struct dwo_unit
*
6102 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
6103 struct die_info
*comp_unit_die
)
6105 struct dwarf2_cu
*cu
= this_cu
->cu
;
6106 struct attribute
*attr
;
6108 struct dwo_unit
*dwo_unit
;
6109 const char *comp_dir
, *dwo_name
;
6111 gdb_assert (cu
!= NULL
);
6113 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6114 dwo_name
= dwarf2_string_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
6115 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6117 if (this_cu
->is_debug_types
)
6119 struct signatured_type
*sig_type
;
6121 /* Since this_cu is the first member of struct signatured_type,
6122 we can go from a pointer to one to a pointer to the other. */
6123 sig_type
= (struct signatured_type
*) this_cu
;
6124 signature
= sig_type
->signature
;
6125 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
6129 struct attribute
*attr
;
6131 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6133 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6135 dwo_name
, objfile_name (this_cu
->objfile
));
6136 signature
= DW_UNSND (attr
);
6137 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
6144 /* Subroutine of init_cutu_and_read_dies to simplify it.
6145 See it for a description of the parameters.
6146 Read a TU directly from a DWO file, bypassing the stub.
6148 Note: This function could be a little bit simpler if we shared cleanups
6149 with our caller, init_cutu_and_read_dies. That's generally a fragile thing
6150 to do, so we keep this function self-contained. Or we could move this
6151 into our caller, but it's complex enough already. */
6154 init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
6155 int use_existing_cu
, int keep
,
6156 die_reader_func_ftype
*die_reader_func
,
6159 struct dwarf2_cu
*cu
;
6160 struct signatured_type
*sig_type
;
6161 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
6162 struct die_reader_specs reader
;
6163 const gdb_byte
*info_ptr
;
6164 struct die_info
*comp_unit_die
;
6167 /* Verify we can do the following downcast, and that we have the
6169 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6170 sig_type
= (struct signatured_type
*) this_cu
;
6171 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6173 cleanups
= make_cleanup (null_cleanup
, NULL
);
6175 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6177 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
6179 /* There's no need to do the rereading_dwo_cu handling that
6180 init_cutu_and_read_dies does since we don't read the stub. */
6184 /* If !use_existing_cu, this_cu->cu must be NULL. */
6185 gdb_assert (this_cu
->cu
== NULL
);
6186 cu
= XNEW (struct dwarf2_cu
);
6187 init_one_comp_unit (cu
, this_cu
);
6188 /* If an error occurs while loading, release our storage. */
6189 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
6192 /* A future optimization, if needed, would be to use an existing
6193 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6194 could share abbrev tables. */
6196 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
6197 0 /* abbrev_table_provided */,
6198 NULL
/* stub_comp_unit_die */,
6199 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6201 &comp_unit_die
, &has_children
) == 0)
6204 do_cleanups (cleanups
);
6208 /* All the "real" work is done here. */
6209 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
6211 /* This duplicates the code in init_cutu_and_read_dies,
6212 but the alternative is making the latter more complex.
6213 This function is only for the special case of using DWO files directly:
6214 no point in overly complicating the general case just to handle this. */
6215 if (free_cu_cleanup
!= NULL
)
6219 /* We've successfully allocated this compilation unit. Let our
6220 caller clean it up when finished with it. */
6221 discard_cleanups (free_cu_cleanup
);
6223 /* We can only discard free_cu_cleanup and all subsequent cleanups.
6224 So we have to manually free the abbrev table. */
6225 dwarf2_free_abbrev_table (cu
);
6227 /* Link this CU into read_in_chain. */
6228 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6229 dwarf2_per_objfile
->read_in_chain
= this_cu
;
6232 do_cleanups (free_cu_cleanup
);
6235 do_cleanups (cleanups
);
6238 /* Initialize a CU (or TU) and read its DIEs.
6239 If the CU defers to a DWO file, read the DWO file as well.
6241 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6242 Otherwise the table specified in the comp unit header is read in and used.
6243 This is an optimization for when we already have the abbrev table.
6245 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
6246 Otherwise, a new CU is allocated with xmalloc.
6248 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
6249 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
6251 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
6252 linker) then DIE_READER_FUNC will not get called. */
6255 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
6256 struct abbrev_table
*abbrev_table
,
6257 int use_existing_cu
, int keep
,
6258 die_reader_func_ftype
*die_reader_func
,
6261 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6262 struct dwarf2_section_info
*section
= this_cu
->section
;
6263 bfd
*abfd
= get_section_bfd_owner (section
);
6264 struct dwarf2_cu
*cu
;
6265 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6266 struct die_reader_specs reader
;
6267 struct die_info
*comp_unit_die
;
6269 struct attribute
*attr
;
6270 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
6271 struct signatured_type
*sig_type
= NULL
;
6272 struct dwarf2_section_info
*abbrev_section
;
6273 /* Non-zero if CU currently points to a DWO file and we need to
6274 reread it. When this happens we need to reread the skeleton die
6275 before we can reread the DWO file (this only applies to CUs, not TUs). */
6276 int rereading_dwo_cu
= 0;
6278 if (dwarf_die_debug
)
6279 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
6280 this_cu
->is_debug_types
? "type" : "comp",
6281 to_underlying (this_cu
->sect_off
));
6283 if (use_existing_cu
)
6286 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6287 file (instead of going through the stub), short-circuit all of this. */
6288 if (this_cu
->reading_dwo_directly
)
6290 /* Narrow down the scope of possibilities to have to understand. */
6291 gdb_assert (this_cu
->is_debug_types
);
6292 gdb_assert (abbrev_table
== NULL
);
6293 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
,
6294 die_reader_func
, data
);
6298 cleanups
= make_cleanup (null_cleanup
, NULL
);
6300 /* This is cheap if the section is already read in. */
6301 dwarf2_read_section (objfile
, section
);
6303 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6305 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6307 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6310 /* If this CU is from a DWO file we need to start over, we need to
6311 refetch the attributes from the skeleton CU.
6312 This could be optimized by retrieving those attributes from when we
6313 were here the first time: the previous comp_unit_die was stored in
6314 comp_unit_obstack. But there's no data yet that we need this
6316 if (cu
->dwo_unit
!= NULL
)
6317 rereading_dwo_cu
= 1;
6321 /* If !use_existing_cu, this_cu->cu must be NULL. */
6322 gdb_assert (this_cu
->cu
== NULL
);
6323 cu
= XNEW (struct dwarf2_cu
);
6324 init_one_comp_unit (cu
, this_cu
);
6325 /* If an error occurs while loading, release our storage. */
6326 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
6329 /* Get the header. */
6330 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6332 /* We already have the header, there's no need to read it in again. */
6333 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6337 if (this_cu
->is_debug_types
)
6339 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
6340 abbrev_section
, info_ptr
,
6343 /* Since per_cu is the first member of struct signatured_type,
6344 we can go from a pointer to one to a pointer to the other. */
6345 sig_type
= (struct signatured_type
*) this_cu
;
6346 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6347 gdb_assert (sig_type
->type_offset_in_tu
6348 == cu
->header
.type_cu_offset_in_tu
);
6349 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6351 /* LENGTH has not been set yet for type units if we're
6352 using .gdb_index. */
6353 this_cu
->length
= get_cu_length (&cu
->header
);
6355 /* Establish the type offset that can be used to lookup the type. */
6356 sig_type
->type_offset_in_section
=
6357 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6359 this_cu
->dwarf_version
= cu
->header
.version
;
6363 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
6366 rcuh_kind::COMPILE
);
6368 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6369 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
6370 this_cu
->dwarf_version
= cu
->header
.version
;
6374 /* Skip dummy compilation units. */
6375 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6376 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6378 do_cleanups (cleanups
);
6382 /* If we don't have them yet, read the abbrevs for this compilation unit.
6383 And if we need to read them now, make sure they're freed when we're
6384 done. Note that it's important that if the CU had an abbrev table
6385 on entry we don't free it when we're done: Somewhere up the call stack
6386 it may be in use. */
6387 if (abbrev_table
!= NULL
)
6389 gdb_assert (cu
->abbrev_table
== NULL
);
6390 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6391 cu
->abbrev_table
= abbrev_table
;
6393 else if (cu
->abbrev_table
== NULL
)
6395 dwarf2_read_abbrevs (cu
, abbrev_section
);
6396 make_cleanup (dwarf2_free_abbrev_table
, cu
);
6398 else if (rereading_dwo_cu
)
6400 dwarf2_free_abbrev_table (cu
);
6401 dwarf2_read_abbrevs (cu
, abbrev_section
);
6404 /* Read the top level CU/TU die. */
6405 init_cu_die_reader (&reader
, cu
, section
, NULL
);
6406 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
6408 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6410 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6411 DWO CU, that this test will fail (the attribute will not be present). */
6412 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
6415 struct dwo_unit
*dwo_unit
;
6416 struct die_info
*dwo_comp_unit_die
;
6420 complaint (&symfile_complaints
,
6421 _("compilation unit with DW_AT_GNU_dwo_name"
6422 " has children (offset 0x%x) [in module %s]"),
6423 to_underlying (this_cu
->sect_off
), bfd_get_filename (abfd
));
6425 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
);
6426 if (dwo_unit
!= NULL
)
6428 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
6429 abbrev_table
!= NULL
,
6430 comp_unit_die
, NULL
,
6432 &dwo_comp_unit_die
, &has_children
) == 0)
6435 do_cleanups (cleanups
);
6438 comp_unit_die
= dwo_comp_unit_die
;
6442 /* Yikes, we couldn't find the rest of the DIE, we only have
6443 the stub. A complaint has already been logged. There's
6444 not much more we can do except pass on the stub DIE to
6445 die_reader_func. We don't want to throw an error on bad
6450 /* All of the above is setup for this call. Yikes. */
6451 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
6453 /* Done, clean up. */
6454 if (free_cu_cleanup
!= NULL
)
6458 /* We've successfully allocated this compilation unit. Let our
6459 caller clean it up when finished with it. */
6460 discard_cleanups (free_cu_cleanup
);
6462 /* We can only discard free_cu_cleanup and all subsequent cleanups.
6463 So we have to manually free the abbrev table. */
6464 dwarf2_free_abbrev_table (cu
);
6466 /* Link this CU into read_in_chain. */
6467 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6468 dwarf2_per_objfile
->read_in_chain
= this_cu
;
6471 do_cleanups (free_cu_cleanup
);
6474 do_cleanups (cleanups
);
6477 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name if present.
6478 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed
6479 to have already done the lookup to find the DWO file).
6481 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
6482 THIS_CU->is_debug_types, but nothing else.
6484 We fill in THIS_CU->length.
6486 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
6487 linker) then DIE_READER_FUNC will not get called.
6489 THIS_CU->cu is always freed when done.
6490 This is done in order to not leave THIS_CU->cu in a state where we have
6491 to care whether it refers to the "main" CU or the DWO CU. */
6494 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
6495 struct dwo_file
*dwo_file
,
6496 die_reader_func_ftype
*die_reader_func
,
6499 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6500 struct dwarf2_section_info
*section
= this_cu
->section
;
6501 bfd
*abfd
= get_section_bfd_owner (section
);
6502 struct dwarf2_section_info
*abbrev_section
;
6503 struct dwarf2_cu cu
;
6504 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6505 struct die_reader_specs reader
;
6506 struct cleanup
*cleanups
;
6507 struct die_info
*comp_unit_die
;
6510 if (dwarf_die_debug
)
6511 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
6512 this_cu
->is_debug_types
? "type" : "comp",
6513 to_underlying (this_cu
->sect_off
));
6515 gdb_assert (this_cu
->cu
== NULL
);
6517 abbrev_section
= (dwo_file
!= NULL
6518 ? &dwo_file
->sections
.abbrev
6519 : get_abbrev_section_for_cu (this_cu
));
6521 /* This is cheap if the section is already read in. */
6522 dwarf2_read_section (objfile
, section
);
6524 init_one_comp_unit (&cu
, this_cu
);
6526 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
6528 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6529 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
,
6530 abbrev_section
, info_ptr
,
6531 (this_cu
->is_debug_types
6533 : rcuh_kind::COMPILE
));
6535 this_cu
->length
= get_cu_length (&cu
.header
);
6537 /* Skip dummy compilation units. */
6538 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6539 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6541 do_cleanups (cleanups
);
6545 dwarf2_read_abbrevs (&cu
, abbrev_section
);
6546 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
6548 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
);
6549 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
6551 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
6553 do_cleanups (cleanups
);
6556 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
6557 does not lookup the specified DWO file.
6558 This cannot be used to read DWO files.
6560 THIS_CU->cu is always freed when done.
6561 This is done in order to not leave THIS_CU->cu in a state where we have
6562 to care whether it refers to the "main" CU or the DWO CU.
6563 We can revisit this if the data shows there's a performance issue. */
6566 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
6567 die_reader_func_ftype
*die_reader_func
,
6570 init_cutu_and_read_dies_no_follow (this_cu
, NULL
, die_reader_func
, data
);
6573 /* Type Unit Groups.
6575 Type Unit Groups are a way to collapse the set of all TUs (type units) into
6576 a more manageable set. The grouping is done by DW_AT_stmt_list entry
6577 so that all types coming from the same compilation (.o file) are grouped
6578 together. A future step could be to put the types in the same symtab as
6579 the CU the types ultimately came from. */
6582 hash_type_unit_group (const void *item
)
6584 const struct type_unit_group
*tu_group
6585 = (const struct type_unit_group
*) item
;
6587 return hash_stmt_list_entry (&tu_group
->hash
);
6591 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
6593 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
6594 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
6596 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
6599 /* Allocate a hash table for type unit groups. */
6602 allocate_type_unit_groups_table (void)
6604 return htab_create_alloc_ex (3,
6605 hash_type_unit_group
,
6608 &dwarf2_per_objfile
->objfile
->objfile_obstack
,
6609 hashtab_obstack_allocate
,
6610 dummy_obstack_deallocate
);
6613 /* Type units that don't have DW_AT_stmt_list are grouped into their own
6614 partial symtabs. We combine several TUs per psymtab to not let the size
6615 of any one psymtab grow too big. */
6616 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
6617 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
6619 /* Helper routine for get_type_unit_group.
6620 Create the type_unit_group object used to hold one or more TUs. */
6622 static struct type_unit_group
*
6623 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
6625 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6626 struct dwarf2_per_cu_data
*per_cu
;
6627 struct type_unit_group
*tu_group
;
6629 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6630 struct type_unit_group
);
6631 per_cu
= &tu_group
->per_cu
;
6632 per_cu
->objfile
= objfile
;
6634 if (dwarf2_per_objfile
->using_index
)
6636 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6637 struct dwarf2_per_cu_quick_data
);
6641 unsigned int line_offset
= to_underlying (line_offset_struct
);
6642 struct partial_symtab
*pst
;
6645 /* Give the symtab a useful name for debug purposes. */
6646 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
6647 name
= xstrprintf ("<type_units_%d>",
6648 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
6650 name
= xstrprintf ("<type_units_at_0x%x>", line_offset
);
6652 pst
= create_partial_symtab (per_cu
, name
);
6658 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
6659 tu_group
->hash
.line_sect_off
= line_offset_struct
;
6664 /* Look up the type_unit_group for type unit CU, and create it if necessary.
6665 STMT_LIST is a DW_AT_stmt_list attribute. */
6667 static struct type_unit_group
*
6668 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
6670 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
6671 struct type_unit_group
*tu_group
;
6673 unsigned int line_offset
;
6674 struct type_unit_group type_unit_group_for_lookup
;
6676 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
6678 dwarf2_per_objfile
->type_unit_groups
=
6679 allocate_type_unit_groups_table ();
6682 /* Do we need to create a new group, or can we use an existing one? */
6686 line_offset
= DW_UNSND (stmt_list
);
6687 ++tu_stats
->nr_symtab_sharers
;
6691 /* Ugh, no stmt_list. Rare, but we have to handle it.
6692 We can do various things here like create one group per TU or
6693 spread them over multiple groups to split up the expansion work.
6694 To avoid worst case scenarios (too many groups or too large groups)
6695 we, umm, group them in bunches. */
6696 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
6697 | (tu_stats
->nr_stmt_less_type_units
6698 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
6699 ++tu_stats
->nr_stmt_less_type_units
;
6702 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
6703 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
6704 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
6705 &type_unit_group_for_lookup
, INSERT
);
6708 tu_group
= (struct type_unit_group
*) *slot
;
6709 gdb_assert (tu_group
!= NULL
);
6713 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
6714 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
6716 ++tu_stats
->nr_symtabs
;
6722 /* Partial symbol tables. */
6724 /* Create a psymtab named NAME and assign it to PER_CU.
6726 The caller must fill in the following details:
6727 dirname, textlow, texthigh. */
6729 static struct partial_symtab
*
6730 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
6732 struct objfile
*objfile
= per_cu
->objfile
;
6733 struct partial_symtab
*pst
;
6735 pst
= start_psymtab_common (objfile
, name
, 0,
6736 objfile
->global_psymbols
,
6737 objfile
->static_psymbols
);
6739 pst
->psymtabs_addrmap_supported
= 1;
6741 /* This is the glue that links PST into GDB's symbol API. */
6742 pst
->read_symtab_private
= per_cu
;
6743 pst
->read_symtab
= dwarf2_read_symtab
;
6744 per_cu
->v
.psymtab
= pst
;
6749 /* The DATA object passed to process_psymtab_comp_unit_reader has this
6752 struct process_psymtab_comp_unit_data
6754 /* True if we are reading a DW_TAG_partial_unit. */
6756 int want_partial_unit
;
6758 /* The "pretend" language that is used if the CU doesn't declare a
6761 enum language pretend_language
;
6764 /* die_reader_func for process_psymtab_comp_unit. */
6767 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
6768 const gdb_byte
*info_ptr
,
6769 struct die_info
*comp_unit_die
,
6773 struct dwarf2_cu
*cu
= reader
->cu
;
6774 struct objfile
*objfile
= cu
->objfile
;
6775 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6776 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6778 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
6779 struct partial_symtab
*pst
;
6780 enum pc_bounds_kind cu_bounds_kind
;
6781 const char *filename
;
6782 struct process_psymtab_comp_unit_data
*info
6783 = (struct process_psymtab_comp_unit_data
*) data
;
6785 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !info
->want_partial_unit
)
6788 gdb_assert (! per_cu
->is_debug_types
);
6790 prepare_one_comp_unit (cu
, comp_unit_die
, info
->pretend_language
);
6792 cu
->list_in_scope
= &file_symbols
;
6794 /* Allocate a new partial symbol table structure. */
6795 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
6796 if (filename
== NULL
)
6799 pst
= create_partial_symtab (per_cu
, filename
);
6801 /* This must be done before calling dwarf2_build_include_psymtabs. */
6802 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6804 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6806 dwarf2_find_base_address (comp_unit_die
, cu
);
6808 /* Possibly set the default values of LOWPC and HIGHPC from
6810 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
6811 &best_highpc
, cu
, pst
);
6812 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
6813 /* Store the contiguous range if it is not empty; it can be empty for
6814 CUs with no code. */
6815 addrmap_set_empty (objfile
->psymtabs_addrmap
,
6816 gdbarch_adjust_dwarf2_addr (gdbarch
,
6817 best_lowpc
+ baseaddr
),
6818 gdbarch_adjust_dwarf2_addr (gdbarch
,
6819 best_highpc
+ baseaddr
) - 1,
6822 /* Check if comp unit has_children.
6823 If so, read the rest of the partial symbols from this comp unit.
6824 If not, there's no more debug_info for this comp unit. */
6827 struct partial_die_info
*first_die
;
6828 CORE_ADDR lowpc
, highpc
;
6830 lowpc
= ((CORE_ADDR
) -1);
6831 highpc
= ((CORE_ADDR
) 0);
6833 first_die
= load_partial_dies (reader
, info_ptr
, 1);
6835 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
6836 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
6838 /* If we didn't find a lowpc, set it to highpc to avoid
6839 complaints from `maint check'. */
6840 if (lowpc
== ((CORE_ADDR
) -1))
6843 /* If the compilation unit didn't have an explicit address range,
6844 then use the information extracted from its child dies. */
6845 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
6848 best_highpc
= highpc
;
6851 pst
->textlow
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
);
6852 pst
->texthigh
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
);
6854 end_psymtab_common (objfile
, pst
);
6856 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
))
6859 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
6860 struct dwarf2_per_cu_data
*iter
;
6862 /* Fill in 'dependencies' here; we fill in 'users' in a
6864 pst
->number_of_dependencies
= len
;
6866 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
6868 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
6871 pst
->dependencies
[i
] = iter
->v
.psymtab
;
6873 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
6876 /* Get the list of files included in the current compilation unit,
6877 and build a psymtab for each of them. */
6878 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
6880 if (dwarf_read_debug
)
6882 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6884 fprintf_unfiltered (gdb_stdlog
,
6885 "Psymtab for %s unit @0x%x: %s - %s"
6886 ", %d global, %d static syms\n",
6887 per_cu
->is_debug_types
? "type" : "comp",
6888 to_underlying (per_cu
->sect_off
),
6889 paddress (gdbarch
, pst
->textlow
),
6890 paddress (gdbarch
, pst
->texthigh
),
6891 pst
->n_global_syms
, pst
->n_static_syms
);
6895 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
6896 Process compilation unit THIS_CU for a psymtab. */
6899 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
6900 int want_partial_unit
,
6901 enum language pretend_language
)
6903 /* If this compilation unit was already read in, free the
6904 cached copy in order to read it in again. This is
6905 necessary because we skipped some symbols when we first
6906 read in the compilation unit (see load_partial_dies).
6907 This problem could be avoided, but the benefit is unclear. */
6908 if (this_cu
->cu
!= NULL
)
6909 free_one_cached_comp_unit (this_cu
);
6911 if (this_cu
->is_debug_types
)
6912 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0, build_type_psymtabs_reader
,
6916 process_psymtab_comp_unit_data info
;
6917 info
.want_partial_unit
= want_partial_unit
;
6918 info
.pretend_language
= pretend_language
;
6919 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0,
6920 process_psymtab_comp_unit_reader
, &info
);
6923 /* Age out any secondary CUs. */
6924 age_cached_comp_units ();
6927 /* Reader function for build_type_psymtabs. */
6930 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
6931 const gdb_byte
*info_ptr
,
6932 struct die_info
*type_unit_die
,
6936 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6937 struct dwarf2_cu
*cu
= reader
->cu
;
6938 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6939 struct signatured_type
*sig_type
;
6940 struct type_unit_group
*tu_group
;
6941 struct attribute
*attr
;
6942 struct partial_die_info
*first_die
;
6943 CORE_ADDR lowpc
, highpc
;
6944 struct partial_symtab
*pst
;
6946 gdb_assert (data
== NULL
);
6947 gdb_assert (per_cu
->is_debug_types
);
6948 sig_type
= (struct signatured_type
*) per_cu
;
6953 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
6954 tu_group
= get_type_unit_group (cu
, attr
);
6956 VEC_safe_push (sig_type_ptr
, tu_group
->tus
, sig_type
);
6958 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
6959 cu
->list_in_scope
= &file_symbols
;
6960 pst
= create_partial_symtab (per_cu
, "");
6963 first_die
= load_partial_dies (reader
, info_ptr
, 1);
6965 lowpc
= (CORE_ADDR
) -1;
6966 highpc
= (CORE_ADDR
) 0;
6967 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
6969 end_psymtab_common (objfile
, pst
);
6972 /* Struct used to sort TUs by their abbreviation table offset. */
6974 struct tu_abbrev_offset
6976 struct signatured_type
*sig_type
;
6977 sect_offset abbrev_offset
;
6980 /* Helper routine for build_type_psymtabs_1, passed to qsort. */
6983 sort_tu_by_abbrev_offset (const void *ap
, const void *bp
)
6985 const struct tu_abbrev_offset
* const *a
6986 = (const struct tu_abbrev_offset
* const*) ap
;
6987 const struct tu_abbrev_offset
* const *b
6988 = (const struct tu_abbrev_offset
* const*) bp
;
6989 sect_offset aoff
= (*a
)->abbrev_offset
;
6990 sect_offset boff
= (*b
)->abbrev_offset
;
6992 return (aoff
> boff
) - (aoff
< boff
);
6995 /* Efficiently read all the type units.
6996 This does the bulk of the work for build_type_psymtabs.
6998 The efficiency is because we sort TUs by the abbrev table they use and
6999 only read each abbrev table once. In one program there are 200K TUs
7000 sharing 8K abbrev tables.
7002 The main purpose of this function is to support building the
7003 dwarf2_per_objfile->type_unit_groups table.
7004 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7005 can collapse the search space by grouping them by stmt_list.
7006 The savings can be significant, in the same program from above the 200K TUs
7007 share 8K stmt_list tables.
7009 FUNC is expected to call get_type_unit_group, which will create the
7010 struct type_unit_group if necessary and add it to
7011 dwarf2_per_objfile->type_unit_groups. */
7014 build_type_psymtabs_1 (void)
7016 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7017 struct cleanup
*cleanups
;
7018 struct abbrev_table
*abbrev_table
;
7019 sect_offset abbrev_offset
;
7020 struct tu_abbrev_offset
*sorted_by_abbrev
;
7023 /* It's up to the caller to not call us multiple times. */
7024 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
7026 if (dwarf2_per_objfile
->n_type_units
== 0)
7029 /* TUs typically share abbrev tables, and there can be way more TUs than
7030 abbrev tables. Sort by abbrev table to reduce the number of times we
7031 read each abbrev table in.
7032 Alternatives are to punt or to maintain a cache of abbrev tables.
7033 This is simpler and efficient enough for now.
7035 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7036 symtab to use). Typically TUs with the same abbrev offset have the same
7037 stmt_list value too so in practice this should work well.
7039 The basic algorithm here is:
7041 sort TUs by abbrev table
7042 for each TU with same abbrev table:
7043 read abbrev table if first user
7044 read TU top level DIE
7045 [IWBN if DWO skeletons had DW_AT_stmt_list]
7048 if (dwarf_read_debug
)
7049 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7051 /* Sort in a separate table to maintain the order of all_type_units
7052 for .gdb_index: TU indices directly index all_type_units. */
7053 sorted_by_abbrev
= XNEWVEC (struct tu_abbrev_offset
,
7054 dwarf2_per_objfile
->n_type_units
);
7055 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
7057 struct signatured_type
*sig_type
= dwarf2_per_objfile
->all_type_units
[i
];
7059 sorted_by_abbrev
[i
].sig_type
= sig_type
;
7060 sorted_by_abbrev
[i
].abbrev_offset
=
7061 read_abbrev_offset (sig_type
->per_cu
.section
,
7062 sig_type
->per_cu
.sect_off
);
7064 cleanups
= make_cleanup (xfree
, sorted_by_abbrev
);
7065 qsort (sorted_by_abbrev
, dwarf2_per_objfile
->n_type_units
,
7066 sizeof (struct tu_abbrev_offset
), sort_tu_by_abbrev_offset
);
7068 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7069 abbrev_table
= NULL
;
7070 make_cleanup (abbrev_table_free_cleanup
, &abbrev_table
);
7072 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
7074 const struct tu_abbrev_offset
*tu
= &sorted_by_abbrev
[i
];
7076 /* Switch to the next abbrev table if necessary. */
7077 if (abbrev_table
== NULL
7078 || tu
->abbrev_offset
!= abbrev_offset
)
7080 if (abbrev_table
!= NULL
)
7082 abbrev_table_free (abbrev_table
);
7083 /* Reset to NULL in case abbrev_table_read_table throws
7084 an error: abbrev_table_free_cleanup will get called. */
7085 abbrev_table
= NULL
;
7087 abbrev_offset
= tu
->abbrev_offset
;
7089 abbrev_table_read_table (&dwarf2_per_objfile
->abbrev
,
7091 ++tu_stats
->nr_uniq_abbrev_tables
;
7094 init_cutu_and_read_dies (&tu
->sig_type
->per_cu
, abbrev_table
, 0, 0,
7095 build_type_psymtabs_reader
, NULL
);
7098 do_cleanups (cleanups
);
7101 /* Print collected type unit statistics. */
7104 print_tu_stats (void)
7106 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7108 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7109 fprintf_unfiltered (gdb_stdlog
, " %d TUs\n",
7110 dwarf2_per_objfile
->n_type_units
);
7111 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7112 tu_stats
->nr_uniq_abbrev_tables
);
7113 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7114 tu_stats
->nr_symtabs
);
7115 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7116 tu_stats
->nr_symtab_sharers
);
7117 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7118 tu_stats
->nr_stmt_less_type_units
);
7119 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7120 tu_stats
->nr_all_type_units_reallocs
);
7123 /* Traversal function for build_type_psymtabs. */
7126 build_type_psymtab_dependencies (void **slot
, void *info
)
7128 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7129 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7130 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7131 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
7132 int len
= VEC_length (sig_type_ptr
, tu_group
->tus
);
7133 struct signatured_type
*iter
;
7136 gdb_assert (len
> 0);
7137 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
7139 pst
->number_of_dependencies
= len
;
7141 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
7143 VEC_iterate (sig_type_ptr
, tu_group
->tus
, i
, iter
);
7146 gdb_assert (iter
->per_cu
.is_debug_types
);
7147 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7148 iter
->type_unit_group
= tu_group
;
7151 VEC_free (sig_type_ptr
, tu_group
->tus
);
7156 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7157 Build partial symbol tables for the .debug_types comp-units. */
7160 build_type_psymtabs (struct objfile
*objfile
)
7162 if (! create_all_type_units (objfile
))
7165 build_type_psymtabs_1 ();
7168 /* Traversal function for process_skeletonless_type_unit.
7169 Read a TU in a DWO file and build partial symbols for it. */
7172 process_skeletonless_type_unit (void **slot
, void *info
)
7174 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7175 struct objfile
*objfile
= (struct objfile
*) info
;
7176 struct signatured_type find_entry
, *entry
;
7178 /* If this TU doesn't exist in the global table, add it and read it in. */
7180 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7182 dwarf2_per_objfile
->signatured_types
7183 = allocate_signatured_type_table (objfile
);
7186 find_entry
.signature
= dwo_unit
->signature
;
7187 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
7189 /* If we've already seen this type there's nothing to do. What's happening
7190 is we're doing our own version of comdat-folding here. */
7194 /* This does the job that create_all_type_units would have done for
7196 entry
= add_type_unit (dwo_unit
->signature
, slot
);
7197 fill_in_sig_entry_from_dwo_entry (objfile
, entry
, dwo_unit
);
7200 /* This does the job that build_type_psymtabs_1 would have done. */
7201 init_cutu_and_read_dies (&entry
->per_cu
, NULL
, 0, 0,
7202 build_type_psymtabs_reader
, NULL
);
7207 /* Traversal function for process_skeletonless_type_units. */
7210 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7212 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7214 if (dwo_file
->tus
!= NULL
)
7216 htab_traverse_noresize (dwo_file
->tus
,
7217 process_skeletonless_type_unit
, info
);
7223 /* Scan all TUs of DWO files, verifying we've processed them.
7224 This is needed in case a TU was emitted without its skeleton.
7225 Note: This can't be done until we know what all the DWO files are. */
7228 process_skeletonless_type_units (struct objfile
*objfile
)
7230 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7231 if (get_dwp_file () == NULL
7232 && dwarf2_per_objfile
->dwo_files
!= NULL
)
7234 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
,
7235 process_dwo_file_for_skeletonless_type_units
,
7240 /* Compute the 'user' field for each psymtab in OBJFILE. */
7243 set_partial_user (struct objfile
*objfile
)
7247 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
7249 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
7250 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
7256 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7258 /* Set the 'user' field only if it is not already set. */
7259 if (pst
->dependencies
[j
]->user
== NULL
)
7260 pst
->dependencies
[j
]->user
= pst
;
7265 /* Build the partial symbol table by doing a quick pass through the
7266 .debug_info and .debug_abbrev sections. */
7269 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
7271 struct cleanup
*back_to
;
7274 if (dwarf_read_debug
)
7276 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
7277 objfile_name (objfile
));
7280 dwarf2_per_objfile
->reading_partial_symbols
= 1;
7282 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
7284 /* Any cached compilation units will be linked by the per-objfile
7285 read_in_chain. Make sure to free them when we're done. */
7286 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
7288 build_type_psymtabs (objfile
);
7290 create_all_comp_units (objfile
);
7292 /* Create a temporary address map on a temporary obstack. We later
7293 copy this to the final obstack. */
7294 auto_obstack temp_obstack
;
7296 scoped_restore save_psymtabs_addrmap
7297 = make_scoped_restore (&objfile
->psymtabs_addrmap
,
7298 addrmap_create_mutable (&temp_obstack
));
7300 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
7302 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
7304 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
7307 /* This has to wait until we read the CUs, we need the list of DWOs. */
7308 process_skeletonless_type_units (objfile
);
7310 /* Now that all TUs have been processed we can fill in the dependencies. */
7311 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
7313 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
7314 build_type_psymtab_dependencies
, NULL
);
7317 if (dwarf_read_debug
)
7320 set_partial_user (objfile
);
7322 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
7323 &objfile
->objfile_obstack
);
7324 /* At this point we want to keep the address map. */
7325 save_psymtabs_addrmap
.release ();
7327 do_cleanups (back_to
);
7329 if (dwarf_read_debug
)
7330 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
7331 objfile_name (objfile
));
7334 /* die_reader_func for load_partial_comp_unit. */
7337 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
7338 const gdb_byte
*info_ptr
,
7339 struct die_info
*comp_unit_die
,
7343 struct dwarf2_cu
*cu
= reader
->cu
;
7345 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
7347 /* Check if comp unit has_children.
7348 If so, read the rest of the partial symbols from this comp unit.
7349 If not, there's no more debug_info for this comp unit. */
7351 load_partial_dies (reader
, info_ptr
, 0);
7354 /* Load the partial DIEs for a secondary CU into memory.
7355 This is also used when rereading a primary CU with load_all_dies. */
7358 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
7360 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
7361 load_partial_comp_unit_reader
, NULL
);
7365 read_comp_units_from_section (struct objfile
*objfile
,
7366 struct dwarf2_section_info
*section
,
7367 struct dwarf2_section_info
*abbrev_section
,
7368 unsigned int is_dwz
,
7371 struct dwarf2_per_cu_data
***all_comp_units
)
7373 const gdb_byte
*info_ptr
;
7374 bfd
*abfd
= get_section_bfd_owner (section
);
7376 if (dwarf_read_debug
)
7377 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
7378 get_section_name (section
),
7379 get_section_file_name (section
));
7381 dwarf2_read_section (objfile
, section
);
7383 info_ptr
= section
->buffer
;
7385 while (info_ptr
< section
->buffer
+ section
->size
)
7387 struct dwarf2_per_cu_data
*this_cu
;
7389 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7391 comp_unit_head cu_header
;
7392 read_and_check_comp_unit_head (&cu_header
, section
, abbrev_section
,
7393 info_ptr
, rcuh_kind::COMPILE
);
7395 /* Save the compilation unit for later lookup. */
7396 if (cu_header
.unit_type
!= DW_UT_type
)
7398 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
7399 struct dwarf2_per_cu_data
);
7400 memset (this_cu
, 0, sizeof (*this_cu
));
7404 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
7405 struct signatured_type
);
7406 memset (sig_type
, 0, sizeof (*sig_type
));
7407 sig_type
->signature
= cu_header
.signature
;
7408 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7409 this_cu
= &sig_type
->per_cu
;
7411 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
7412 this_cu
->sect_off
= sect_off
;
7413 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7414 this_cu
->is_dwz
= is_dwz
;
7415 this_cu
->objfile
= objfile
;
7416 this_cu
->section
= section
;
7418 if (*n_comp_units
== *n_allocated
)
7421 *all_comp_units
= XRESIZEVEC (struct dwarf2_per_cu_data
*,
7422 *all_comp_units
, *n_allocated
);
7424 (*all_comp_units
)[*n_comp_units
] = this_cu
;
7427 info_ptr
= info_ptr
+ this_cu
->length
;
7431 /* Create a list of all compilation units in OBJFILE.
7432 This is only done for -readnow and building partial symtabs. */
7435 create_all_comp_units (struct objfile
*objfile
)
7439 struct dwarf2_per_cu_data
**all_comp_units
;
7440 struct dwz_file
*dwz
;
7444 all_comp_units
= XNEWVEC (struct dwarf2_per_cu_data
*, n_allocated
);
7446 read_comp_units_from_section (objfile
, &dwarf2_per_objfile
->info
,
7447 &dwarf2_per_objfile
->abbrev
, 0,
7448 &n_allocated
, &n_comp_units
, &all_comp_units
);
7450 dwz
= dwarf2_get_dwz_file ();
7452 read_comp_units_from_section (objfile
, &dwz
->info
, &dwz
->abbrev
, 1,
7453 &n_allocated
, &n_comp_units
,
7456 dwarf2_per_objfile
->all_comp_units
= XOBNEWVEC (&objfile
->objfile_obstack
,
7457 struct dwarf2_per_cu_data
*,
7459 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
7460 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
7461 xfree (all_comp_units
);
7462 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
7465 /* Process all loaded DIEs for compilation unit CU, starting at
7466 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
7467 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
7468 DW_AT_ranges). See the comments of add_partial_subprogram on how
7469 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
7472 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
7473 CORE_ADDR
*highpc
, int set_addrmap
,
7474 struct dwarf2_cu
*cu
)
7476 struct partial_die_info
*pdi
;
7478 /* Now, march along the PDI's, descending into ones which have
7479 interesting children but skipping the children of the other ones,
7480 until we reach the end of the compilation unit. */
7486 fixup_partial_die (pdi
, cu
);
7488 /* Anonymous namespaces or modules have no name but have interesting
7489 children, so we need to look at them. Ditto for anonymous
7492 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
7493 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
7494 || pdi
->tag
== DW_TAG_imported_unit
)
7498 case DW_TAG_subprogram
:
7499 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7501 case DW_TAG_constant
:
7502 case DW_TAG_variable
:
7503 case DW_TAG_typedef
:
7504 case DW_TAG_union_type
:
7505 if (!pdi
->is_declaration
)
7507 add_partial_symbol (pdi
, cu
);
7510 case DW_TAG_class_type
:
7511 case DW_TAG_interface_type
:
7512 case DW_TAG_structure_type
:
7513 if (!pdi
->is_declaration
)
7515 add_partial_symbol (pdi
, cu
);
7517 if (cu
->language
== language_rust
&& pdi
->has_children
)
7518 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7521 case DW_TAG_enumeration_type
:
7522 if (!pdi
->is_declaration
)
7523 add_partial_enumeration (pdi
, cu
);
7525 case DW_TAG_base_type
:
7526 case DW_TAG_subrange_type
:
7527 /* File scope base type definitions are added to the partial
7529 add_partial_symbol (pdi
, cu
);
7531 case DW_TAG_namespace
:
7532 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7535 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7537 case DW_TAG_imported_unit
:
7539 struct dwarf2_per_cu_data
*per_cu
;
7541 /* For now we don't handle imported units in type units. */
7542 if (cu
->per_cu
->is_debug_types
)
7544 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7545 " supported in type units [in module %s]"),
7546 objfile_name (cu
->objfile
));
7549 per_cu
= dwarf2_find_containing_comp_unit (pdi
->d
.sect_off
,
7553 /* Go read the partial unit, if needed. */
7554 if (per_cu
->v
.psymtab
== NULL
)
7555 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
7557 VEC_safe_push (dwarf2_per_cu_ptr
,
7558 cu
->per_cu
->imported_symtabs
, per_cu
);
7561 case DW_TAG_imported_declaration
:
7562 add_partial_symbol (pdi
, cu
);
7569 /* If the die has a sibling, skip to the sibling. */
7571 pdi
= pdi
->die_sibling
;
7575 /* Functions used to compute the fully scoped name of a partial DIE.
7577 Normally, this is simple. For C++, the parent DIE's fully scoped
7578 name is concatenated with "::" and the partial DIE's name.
7579 Enumerators are an exception; they use the scope of their parent
7580 enumeration type, i.e. the name of the enumeration type is not
7581 prepended to the enumerator.
7583 There are two complexities. One is DW_AT_specification; in this
7584 case "parent" means the parent of the target of the specification,
7585 instead of the direct parent of the DIE. The other is compilers
7586 which do not emit DW_TAG_namespace; in this case we try to guess
7587 the fully qualified name of structure types from their members'
7588 linkage names. This must be done using the DIE's children rather
7589 than the children of any DW_AT_specification target. We only need
7590 to do this for structures at the top level, i.e. if the target of
7591 any DW_AT_specification (if any; otherwise the DIE itself) does not
7594 /* Compute the scope prefix associated with PDI's parent, in
7595 compilation unit CU. The result will be allocated on CU's
7596 comp_unit_obstack, or a copy of the already allocated PDI->NAME
7597 field. NULL is returned if no prefix is necessary. */
7599 partial_die_parent_scope (struct partial_die_info
*pdi
,
7600 struct dwarf2_cu
*cu
)
7602 const char *grandparent_scope
;
7603 struct partial_die_info
*parent
, *real_pdi
;
7605 /* We need to look at our parent DIE; if we have a DW_AT_specification,
7606 then this means the parent of the specification DIE. */
7609 while (real_pdi
->has_specification
)
7610 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
7611 real_pdi
->spec_is_dwz
, cu
);
7613 parent
= real_pdi
->die_parent
;
7617 if (parent
->scope_set
)
7618 return parent
->scope
;
7620 fixup_partial_die (parent
, cu
);
7622 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
7624 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
7625 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
7626 Work around this problem here. */
7627 if (cu
->language
== language_cplus
7628 && parent
->tag
== DW_TAG_namespace
7629 && strcmp (parent
->name
, "::") == 0
7630 && grandparent_scope
== NULL
)
7632 parent
->scope
= NULL
;
7633 parent
->scope_set
= 1;
7637 if (pdi
->tag
== DW_TAG_enumerator
)
7638 /* Enumerators should not get the name of the enumeration as a prefix. */
7639 parent
->scope
= grandparent_scope
;
7640 else if (parent
->tag
== DW_TAG_namespace
7641 || parent
->tag
== DW_TAG_module
7642 || parent
->tag
== DW_TAG_structure_type
7643 || parent
->tag
== DW_TAG_class_type
7644 || parent
->tag
== DW_TAG_interface_type
7645 || parent
->tag
== DW_TAG_union_type
7646 || parent
->tag
== DW_TAG_enumeration_type
)
7648 if (grandparent_scope
== NULL
)
7649 parent
->scope
= parent
->name
;
7651 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
7653 parent
->name
, 0, cu
);
7657 /* FIXME drow/2004-04-01: What should we be doing with
7658 function-local names? For partial symbols, we should probably be
7660 complaint (&symfile_complaints
,
7661 _("unhandled containing DIE tag %d for DIE at %d"),
7662 parent
->tag
, to_underlying (pdi
->sect_off
));
7663 parent
->scope
= grandparent_scope
;
7666 parent
->scope_set
= 1;
7667 return parent
->scope
;
7670 /* Return the fully scoped name associated with PDI, from compilation unit
7671 CU. The result will be allocated with malloc. */
7674 partial_die_full_name (struct partial_die_info
*pdi
,
7675 struct dwarf2_cu
*cu
)
7677 const char *parent_scope
;
7679 /* If this is a template instantiation, we can not work out the
7680 template arguments from partial DIEs. So, unfortunately, we have
7681 to go through the full DIEs. At least any work we do building
7682 types here will be reused if full symbols are loaded later. */
7683 if (pdi
->has_template_arguments
)
7685 fixup_partial_die (pdi
, cu
);
7687 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
7689 struct die_info
*die
;
7690 struct attribute attr
;
7691 struct dwarf2_cu
*ref_cu
= cu
;
7693 /* DW_FORM_ref_addr is using section offset. */
7694 attr
.name
= (enum dwarf_attribute
) 0;
7695 attr
.form
= DW_FORM_ref_addr
;
7696 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
7697 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
7699 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
7703 parent_scope
= partial_die_parent_scope (pdi
, cu
);
7704 if (parent_scope
== NULL
)
7707 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
7711 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
7713 struct objfile
*objfile
= cu
->objfile
;
7714 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7716 const char *actual_name
= NULL
;
7718 char *built_actual_name
;
7720 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7722 built_actual_name
= partial_die_full_name (pdi
, cu
);
7723 if (built_actual_name
!= NULL
)
7724 actual_name
= built_actual_name
;
7726 if (actual_name
== NULL
)
7727 actual_name
= pdi
->name
;
7731 case DW_TAG_subprogram
:
7732 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
);
7733 if (pdi
->is_external
|| cu
->language
== language_ada
)
7735 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
7736 of the global scope. But in Ada, we want to be able to access
7737 nested procedures globally. So all Ada subprograms are stored
7738 in the global scope. */
7739 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7740 built_actual_name
!= NULL
,
7741 VAR_DOMAIN
, LOC_BLOCK
,
7742 &objfile
->global_psymbols
,
7743 addr
, cu
->language
, objfile
);
7747 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7748 built_actual_name
!= NULL
,
7749 VAR_DOMAIN
, LOC_BLOCK
,
7750 &objfile
->static_psymbols
,
7751 addr
, cu
->language
, objfile
);
7754 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
7755 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
7757 case DW_TAG_constant
:
7759 std::vector
<partial_symbol
*> *list
;
7761 if (pdi
->is_external
)
7762 list
= &objfile
->global_psymbols
;
7764 list
= &objfile
->static_psymbols
;
7765 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7766 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
7767 list
, 0, cu
->language
, objfile
);
7770 case DW_TAG_variable
:
7772 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
7776 && !dwarf2_per_objfile
->has_section_at_zero
)
7778 /* A global or static variable may also have been stripped
7779 out by the linker if unused, in which case its address
7780 will be nullified; do not add such variables into partial
7781 symbol table then. */
7783 else if (pdi
->is_external
)
7786 Don't enter into the minimal symbol tables as there is
7787 a minimal symbol table entry from the ELF symbols already.
7788 Enter into partial symbol table if it has a location
7789 descriptor or a type.
7790 If the location descriptor is missing, new_symbol will create
7791 a LOC_UNRESOLVED symbol, the address of the variable will then
7792 be determined from the minimal symbol table whenever the variable
7794 The address for the partial symbol table entry is not
7795 used by GDB, but it comes in handy for debugging partial symbol
7798 if (pdi
->d
.locdesc
|| pdi
->has_type
)
7799 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7800 built_actual_name
!= NULL
,
7801 VAR_DOMAIN
, LOC_STATIC
,
7802 &objfile
->global_psymbols
,
7804 cu
->language
, objfile
);
7808 int has_loc
= pdi
->d
.locdesc
!= NULL
;
7810 /* Static Variable. Skip symbols whose value we cannot know (those
7811 without location descriptors or constant values). */
7812 if (!has_loc
&& !pdi
->has_const_value
)
7814 xfree (built_actual_name
);
7818 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7819 built_actual_name
!= NULL
,
7820 VAR_DOMAIN
, LOC_STATIC
,
7821 &objfile
->static_psymbols
,
7822 has_loc
? addr
+ baseaddr
: (CORE_ADDR
) 0,
7823 cu
->language
, objfile
);
7826 case DW_TAG_typedef
:
7827 case DW_TAG_base_type
:
7828 case DW_TAG_subrange_type
:
7829 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7830 built_actual_name
!= NULL
,
7831 VAR_DOMAIN
, LOC_TYPEDEF
,
7832 &objfile
->static_psymbols
,
7833 0, cu
->language
, objfile
);
7835 case DW_TAG_imported_declaration
:
7836 case DW_TAG_namespace
:
7837 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7838 built_actual_name
!= NULL
,
7839 VAR_DOMAIN
, LOC_TYPEDEF
,
7840 &objfile
->global_psymbols
,
7841 0, cu
->language
, objfile
);
7844 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7845 built_actual_name
!= NULL
,
7846 MODULE_DOMAIN
, LOC_TYPEDEF
,
7847 &objfile
->global_psymbols
,
7848 0, cu
->language
, objfile
);
7850 case DW_TAG_class_type
:
7851 case DW_TAG_interface_type
:
7852 case DW_TAG_structure_type
:
7853 case DW_TAG_union_type
:
7854 case DW_TAG_enumeration_type
:
7855 /* Skip external references. The DWARF standard says in the section
7856 about "Structure, Union, and Class Type Entries": "An incomplete
7857 structure, union or class type is represented by a structure,
7858 union or class entry that does not have a byte size attribute
7859 and that has a DW_AT_declaration attribute." */
7860 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
7862 xfree (built_actual_name
);
7866 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
7867 static vs. global. */
7868 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7869 built_actual_name
!= NULL
,
7870 STRUCT_DOMAIN
, LOC_TYPEDEF
,
7871 cu
->language
== language_cplus
7872 ? &objfile
->global_psymbols
7873 : &objfile
->static_psymbols
,
7874 0, cu
->language
, objfile
);
7877 case DW_TAG_enumerator
:
7878 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7879 built_actual_name
!= NULL
,
7880 VAR_DOMAIN
, LOC_CONST
,
7881 cu
->language
== language_cplus
7882 ? &objfile
->global_psymbols
7883 : &objfile
->static_psymbols
,
7884 0, cu
->language
, objfile
);
7890 xfree (built_actual_name
);
7893 /* Read a partial die corresponding to a namespace; also, add a symbol
7894 corresponding to that namespace to the symbol table. NAMESPACE is
7895 the name of the enclosing namespace. */
7898 add_partial_namespace (struct partial_die_info
*pdi
,
7899 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
7900 int set_addrmap
, struct dwarf2_cu
*cu
)
7902 /* Add a symbol for the namespace. */
7904 add_partial_symbol (pdi
, cu
);
7906 /* Now scan partial symbols in that namespace. */
7908 if (pdi
->has_children
)
7909 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
7912 /* Read a partial die corresponding to a Fortran module. */
7915 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
7916 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
7918 /* Add a symbol for the namespace. */
7920 add_partial_symbol (pdi
, cu
);
7922 /* Now scan partial symbols in that module. */
7924 if (pdi
->has_children
)
7925 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
7928 /* Read a partial die corresponding to a subprogram and create a partial
7929 symbol for that subprogram. When the CU language allows it, this
7930 routine also defines a partial symbol for each nested subprogram
7931 that this subprogram contains. If SET_ADDRMAP is true, record the
7932 covered ranges in the addrmap. Set *LOWPC and *HIGHPC to the lowest
7933 and highest PC values found in PDI.
7935 PDI may also be a lexical block, in which case we simply search
7936 recursively for subprograms defined inside that lexical block.
7937 Again, this is only performed when the CU language allows this
7938 type of definitions. */
7941 add_partial_subprogram (struct partial_die_info
*pdi
,
7942 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
7943 int set_addrmap
, struct dwarf2_cu
*cu
)
7945 if (pdi
->tag
== DW_TAG_subprogram
)
7947 if (pdi
->has_pc_info
)
7949 if (pdi
->lowpc
< *lowpc
)
7950 *lowpc
= pdi
->lowpc
;
7951 if (pdi
->highpc
> *highpc
)
7952 *highpc
= pdi
->highpc
;
7955 struct objfile
*objfile
= cu
->objfile
;
7956 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7961 baseaddr
= ANOFFSET (objfile
->section_offsets
,
7962 SECT_OFF_TEXT (objfile
));
7963 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
7964 pdi
->lowpc
+ baseaddr
);
7965 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
7966 pdi
->highpc
+ baseaddr
);
7967 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
7968 cu
->per_cu
->v
.psymtab
);
7972 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
7974 if (!pdi
->is_declaration
)
7975 /* Ignore subprogram DIEs that do not have a name, they are
7976 illegal. Do not emit a complaint at this point, we will
7977 do so when we convert this psymtab into a symtab. */
7979 add_partial_symbol (pdi
, cu
);
7983 if (! pdi
->has_children
)
7986 if (cu
->language
== language_ada
)
7988 pdi
= pdi
->die_child
;
7991 fixup_partial_die (pdi
, cu
);
7992 if (pdi
->tag
== DW_TAG_subprogram
7993 || pdi
->tag
== DW_TAG_lexical_block
)
7994 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7995 pdi
= pdi
->die_sibling
;
8000 /* Read a partial die corresponding to an enumeration type. */
8003 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8004 struct dwarf2_cu
*cu
)
8006 struct partial_die_info
*pdi
;
8008 if (enum_pdi
->name
!= NULL
)
8009 add_partial_symbol (enum_pdi
, cu
);
8011 pdi
= enum_pdi
->die_child
;
8014 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
8015 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
8017 add_partial_symbol (pdi
, cu
);
8018 pdi
= pdi
->die_sibling
;
8022 /* Return the initial uleb128 in the die at INFO_PTR. */
8025 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8027 unsigned int bytes_read
;
8029 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8032 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
8033 Return the corresponding abbrev, or NULL if the number is zero (indicating
8034 an empty DIE). In either case *BYTES_READ will be set to the length of
8035 the initial number. */
8037 static struct abbrev_info
*
8038 peek_die_abbrev (const gdb_byte
*info_ptr
, unsigned int *bytes_read
,
8039 struct dwarf2_cu
*cu
)
8041 bfd
*abfd
= cu
->objfile
->obfd
;
8042 unsigned int abbrev_number
;
8043 struct abbrev_info
*abbrev
;
8045 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8047 if (abbrev_number
== 0)
8050 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
8053 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8054 " at offset 0x%x [in module %s]"),
8055 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8056 to_underlying (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8062 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8063 Returns a pointer to the end of a series of DIEs, terminated by an empty
8064 DIE. Any children of the skipped DIEs will also be skipped. */
8066 static const gdb_byte
*
8067 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8069 struct dwarf2_cu
*cu
= reader
->cu
;
8070 struct abbrev_info
*abbrev
;
8071 unsigned int bytes_read
;
8075 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
8077 return info_ptr
+ bytes_read
;
8079 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8083 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8084 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8085 abbrev corresponding to that skipped uleb128 should be passed in
8086 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8089 static const gdb_byte
*
8090 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8091 struct abbrev_info
*abbrev
)
8093 unsigned int bytes_read
;
8094 struct attribute attr
;
8095 bfd
*abfd
= reader
->abfd
;
8096 struct dwarf2_cu
*cu
= reader
->cu
;
8097 const gdb_byte
*buffer
= reader
->buffer
;
8098 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8099 unsigned int form
, i
;
8101 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8103 /* The only abbrev we care about is DW_AT_sibling. */
8104 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8106 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
8107 if (attr
.form
== DW_FORM_ref_addr
)
8108 complaint (&symfile_complaints
,
8109 _("ignoring absolute DW_AT_sibling"));
8112 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
8113 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8115 if (sibling_ptr
< info_ptr
)
8116 complaint (&symfile_complaints
,
8117 _("DW_AT_sibling points backwards"));
8118 else if (sibling_ptr
> reader
->buffer_end
)
8119 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
8125 /* If it isn't DW_AT_sibling, skip this attribute. */
8126 form
= abbrev
->attrs
[i
].form
;
8130 case DW_FORM_ref_addr
:
8131 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8132 and later it is offset sized. */
8133 if (cu
->header
.version
== 2)
8134 info_ptr
+= cu
->header
.addr_size
;
8136 info_ptr
+= cu
->header
.offset_size
;
8138 case DW_FORM_GNU_ref_alt
:
8139 info_ptr
+= cu
->header
.offset_size
;
8142 info_ptr
+= cu
->header
.addr_size
;
8149 case DW_FORM_flag_present
:
8150 case DW_FORM_implicit_const
:
8162 case DW_FORM_ref_sig8
:
8165 case DW_FORM_data16
:
8168 case DW_FORM_string
:
8169 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8170 info_ptr
+= bytes_read
;
8172 case DW_FORM_sec_offset
:
8174 case DW_FORM_GNU_strp_alt
:
8175 info_ptr
+= cu
->header
.offset_size
;
8177 case DW_FORM_exprloc
:
8179 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8180 info_ptr
+= bytes_read
;
8182 case DW_FORM_block1
:
8183 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8185 case DW_FORM_block2
:
8186 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8188 case DW_FORM_block4
:
8189 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8193 case DW_FORM_ref_udata
:
8194 case DW_FORM_GNU_addr_index
:
8195 case DW_FORM_GNU_str_index
:
8196 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8198 case DW_FORM_indirect
:
8199 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8200 info_ptr
+= bytes_read
;
8201 /* We need to continue parsing from here, so just go back to
8203 goto skip_attribute
;
8206 error (_("Dwarf Error: Cannot handle %s "
8207 "in DWARF reader [in module %s]"),
8208 dwarf_form_name (form
),
8209 bfd_get_filename (abfd
));
8213 if (abbrev
->has_children
)
8214 return skip_children (reader
, info_ptr
);
8219 /* Locate ORIG_PDI's sibling.
8220 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8222 static const gdb_byte
*
8223 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8224 struct partial_die_info
*orig_pdi
,
8225 const gdb_byte
*info_ptr
)
8227 /* Do we know the sibling already? */
8229 if (orig_pdi
->sibling
)
8230 return orig_pdi
->sibling
;
8232 /* Are there any children to deal with? */
8234 if (!orig_pdi
->has_children
)
8237 /* Skip the children the long way. */
8239 return skip_children (reader
, info_ptr
);
8242 /* Expand this partial symbol table into a full symbol table. SELF is
8246 dwarf2_read_symtab (struct partial_symtab
*self
,
8247 struct objfile
*objfile
)
8251 warning (_("bug: psymtab for %s is already read in."),
8258 printf_filtered (_("Reading in symbols for %s..."),
8260 gdb_flush (gdb_stdout
);
8263 /* Restore our global data. */
8265 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
8266 dwarf2_objfile_data_key
);
8268 /* If this psymtab is constructed from a debug-only objfile, the
8269 has_section_at_zero flag will not necessarily be correct. We
8270 can get the correct value for this flag by looking at the data
8271 associated with the (presumably stripped) associated objfile. */
8272 if (objfile
->separate_debug_objfile_backlink
)
8274 struct dwarf2_per_objfile
*dpo_backlink
8275 = ((struct dwarf2_per_objfile
*)
8276 objfile_data (objfile
->separate_debug_objfile_backlink
,
8277 dwarf2_objfile_data_key
));
8279 dwarf2_per_objfile
->has_section_at_zero
8280 = dpo_backlink
->has_section_at_zero
;
8283 dwarf2_per_objfile
->reading_partial_symbols
= 0;
8285 psymtab_to_symtab_1 (self
);
8287 /* Finish up the debug error message. */
8289 printf_filtered (_("done.\n"));
8292 process_cu_includes ();
8295 /* Reading in full CUs. */
8297 /* Add PER_CU to the queue. */
8300 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8301 enum language pretend_language
)
8303 struct dwarf2_queue_item
*item
;
8306 item
= XNEW (struct dwarf2_queue_item
);
8307 item
->per_cu
= per_cu
;
8308 item
->pretend_language
= pretend_language
;
8311 if (dwarf2_queue
== NULL
)
8312 dwarf2_queue
= item
;
8314 dwarf2_queue_tail
->next
= item
;
8316 dwarf2_queue_tail
= item
;
8319 /* If PER_CU is not yet queued, add it to the queue.
8320 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8322 The result is non-zero if PER_CU was queued, otherwise the result is zero
8323 meaning either PER_CU is already queued or it is already loaded.
8325 N.B. There is an invariant here that if a CU is queued then it is loaded.
8326 The caller is required to load PER_CU if we return non-zero. */
8329 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8330 struct dwarf2_per_cu_data
*per_cu
,
8331 enum language pretend_language
)
8333 /* We may arrive here during partial symbol reading, if we need full
8334 DIEs to process an unusual case (e.g. template arguments). Do
8335 not queue PER_CU, just tell our caller to load its DIEs. */
8336 if (dwarf2_per_objfile
->reading_partial_symbols
)
8338 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
8343 /* Mark the dependence relation so that we don't flush PER_CU
8345 if (dependent_cu
!= NULL
)
8346 dwarf2_add_dependence (dependent_cu
, per_cu
);
8348 /* If it's already on the queue, we have nothing to do. */
8352 /* If the compilation unit is already loaded, just mark it as
8354 if (per_cu
->cu
!= NULL
)
8356 per_cu
->cu
->last_used
= 0;
8360 /* Add it to the queue. */
8361 queue_comp_unit (per_cu
, pretend_language
);
8366 /* Process the queue. */
8369 process_queue (void)
8371 struct dwarf2_queue_item
*item
, *next_item
;
8373 if (dwarf_read_debug
)
8375 fprintf_unfiltered (gdb_stdlog
,
8376 "Expanding one or more symtabs of objfile %s ...\n",
8377 objfile_name (dwarf2_per_objfile
->objfile
));
8380 /* The queue starts out with one item, but following a DIE reference
8381 may load a new CU, adding it to the end of the queue. */
8382 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
8384 if ((dwarf2_per_objfile
->using_index
8385 ? !item
->per_cu
->v
.quick
->compunit_symtab
8386 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
8387 /* Skip dummy CUs. */
8388 && item
->per_cu
->cu
!= NULL
)
8390 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
8391 unsigned int debug_print_threshold
;
8394 if (per_cu
->is_debug_types
)
8396 struct signatured_type
*sig_type
=
8397 (struct signatured_type
*) per_cu
;
8399 sprintf (buf
, "TU %s at offset 0x%x",
8400 hex_string (sig_type
->signature
),
8401 to_underlying (per_cu
->sect_off
));
8402 /* There can be 100s of TUs.
8403 Only print them in verbose mode. */
8404 debug_print_threshold
= 2;
8408 sprintf (buf
, "CU at offset 0x%x",
8409 to_underlying (per_cu
->sect_off
));
8410 debug_print_threshold
= 1;
8413 if (dwarf_read_debug
>= debug_print_threshold
)
8414 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
8416 if (per_cu
->is_debug_types
)
8417 process_full_type_unit (per_cu
, item
->pretend_language
);
8419 process_full_comp_unit (per_cu
, item
->pretend_language
);
8421 if (dwarf_read_debug
>= debug_print_threshold
)
8422 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
8425 item
->per_cu
->queued
= 0;
8426 next_item
= item
->next
;
8430 dwarf2_queue_tail
= NULL
;
8432 if (dwarf_read_debug
)
8434 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
8435 objfile_name (dwarf2_per_objfile
->objfile
));
8439 /* Free all allocated queue entries. This function only releases anything if
8440 an error was thrown; if the queue was processed then it would have been
8441 freed as we went along. */
8444 dwarf2_release_queue (void *dummy
)
8446 struct dwarf2_queue_item
*item
, *last
;
8448 item
= dwarf2_queue
;
8451 /* Anything still marked queued is likely to be in an
8452 inconsistent state, so discard it. */
8453 if (item
->per_cu
->queued
)
8455 if (item
->per_cu
->cu
!= NULL
)
8456 free_one_cached_comp_unit (item
->per_cu
);
8457 item
->per_cu
->queued
= 0;
8465 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
8468 /* Read in full symbols for PST, and anything it depends on. */
8471 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
8473 struct dwarf2_per_cu_data
*per_cu
;
8479 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
8480 if (!pst
->dependencies
[i
]->readin
8481 && pst
->dependencies
[i
]->user
== NULL
)
8483 /* Inform about additional files that need to be read in. */
8486 /* FIXME: i18n: Need to make this a single string. */
8487 fputs_filtered (" ", gdb_stdout
);
8489 fputs_filtered ("and ", gdb_stdout
);
8491 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
8492 wrap_here (""); /* Flush output. */
8493 gdb_flush (gdb_stdout
);
8495 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
8498 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
8502 /* It's an include file, no symbols to read for it.
8503 Everything is in the parent symtab. */
8508 dw2_do_instantiate_symtab (per_cu
);
8511 /* Trivial hash function for die_info: the hash value of a DIE
8512 is its offset in .debug_info for this objfile. */
8515 die_hash (const void *item
)
8517 const struct die_info
*die
= (const struct die_info
*) item
;
8519 return to_underlying (die
->sect_off
);
8522 /* Trivial comparison function for die_info structures: two DIEs
8523 are equal if they have the same offset. */
8526 die_eq (const void *item_lhs
, const void *item_rhs
)
8528 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8529 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8531 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8534 /* die_reader_func for load_full_comp_unit.
8535 This is identical to read_signatured_type_reader,
8536 but is kept separate for now. */
8539 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
8540 const gdb_byte
*info_ptr
,
8541 struct die_info
*comp_unit_die
,
8545 struct dwarf2_cu
*cu
= reader
->cu
;
8546 enum language
*language_ptr
= (enum language
*) data
;
8548 gdb_assert (cu
->die_hash
== NULL
);
8550 htab_create_alloc_ex (cu
->header
.length
/ 12,
8554 &cu
->comp_unit_obstack
,
8555 hashtab_obstack_allocate
,
8556 dummy_obstack_deallocate
);
8559 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
8560 &info_ptr
, comp_unit_die
);
8561 cu
->dies
= comp_unit_die
;
8562 /* comp_unit_die is not stored in die_hash, no need. */
8564 /* We try not to read any attributes in this function, because not
8565 all CUs needed for references have been loaded yet, and symbol
8566 table processing isn't initialized. But we have to set the CU language,
8567 or we won't be able to build types correctly.
8568 Similarly, if we do not read the producer, we can not apply
8569 producer-specific interpretation. */
8570 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
8573 /* Load the DIEs associated with PER_CU into memory. */
8576 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8577 enum language pretend_language
)
8579 gdb_assert (! this_cu
->is_debug_types
);
8581 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
8582 load_full_comp_unit_reader
, &pretend_language
);
8585 /* Add a DIE to the delayed physname list. */
8588 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
8589 const char *name
, struct die_info
*die
,
8590 struct dwarf2_cu
*cu
)
8592 struct delayed_method_info mi
;
8594 mi
.fnfield_index
= fnfield_index
;
8598 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
8601 /* A cleanup for freeing the delayed method list. */
8604 free_delayed_list (void *ptr
)
8606 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
8607 if (cu
->method_list
!= NULL
)
8609 VEC_free (delayed_method_info
, cu
->method_list
);
8610 cu
->method_list
= NULL
;
8614 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
8615 "const" / "volatile". If so, decrements LEN by the length of the
8616 modifier and return true. Otherwise return false. */
8620 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
8622 size_t mod_len
= sizeof (mod
) - 1;
8623 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
8631 /* Compute the physnames of any methods on the CU's method list.
8633 The computation of method physnames is delayed in order to avoid the
8634 (bad) condition that one of the method's formal parameters is of an as yet
8638 compute_delayed_physnames (struct dwarf2_cu
*cu
)
8641 struct delayed_method_info
*mi
;
8643 /* Only C++ delays computing physnames. */
8644 if (VEC_empty (delayed_method_info
, cu
->method_list
))
8646 gdb_assert (cu
->language
== language_cplus
);
8648 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
8650 const char *physname
;
8651 struct fn_fieldlist
*fn_flp
8652 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
8653 physname
= dwarf2_physname (mi
->name
, mi
->die
, cu
);
8654 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
->index
)
8655 = physname
? physname
: "";
8657 /* Since there's no tag to indicate whether a method is a
8658 const/volatile overload, extract that information out of the
8660 if (physname
!= NULL
)
8662 size_t len
= strlen (physname
);
8666 if (physname
[len
] == ')') /* shortcut */
8668 else if (check_modifier (physname
, len
, " const"))
8669 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
->index
) = 1;
8670 else if (check_modifier (physname
, len
, " volatile"))
8671 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
->index
) = 1;
8679 /* Go objects should be embedded in a DW_TAG_module DIE,
8680 and it's not clear if/how imported objects will appear.
8681 To keep Go support simple until that's worked out,
8682 go back through what we've read and create something usable.
8683 We could do this while processing each DIE, and feels kinda cleaner,
8684 but that way is more invasive.
8685 This is to, for example, allow the user to type "p var" or "b main"
8686 without having to specify the package name, and allow lookups
8687 of module.object to work in contexts that use the expression
8691 fixup_go_packaging (struct dwarf2_cu
*cu
)
8693 char *package_name
= NULL
;
8694 struct pending
*list
;
8697 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
8699 for (i
= 0; i
< list
->nsyms
; ++i
)
8701 struct symbol
*sym
= list
->symbol
[i
];
8703 if (SYMBOL_LANGUAGE (sym
) == language_go
8704 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
8706 char *this_package_name
= go_symbol_package_name (sym
);
8708 if (this_package_name
== NULL
)
8710 if (package_name
== NULL
)
8711 package_name
= this_package_name
;
8714 if (strcmp (package_name
, this_package_name
) != 0)
8715 complaint (&symfile_complaints
,
8716 _("Symtab %s has objects from two different Go packages: %s and %s"),
8717 (symbol_symtab (sym
) != NULL
8718 ? symtab_to_filename_for_display
8719 (symbol_symtab (sym
))
8720 : objfile_name (cu
->objfile
)),
8721 this_package_name
, package_name
);
8722 xfree (this_package_name
);
8728 if (package_name
!= NULL
)
8730 struct objfile
*objfile
= cu
->objfile
;
8731 const char *saved_package_name
8732 = (const char *) obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
8734 strlen (package_name
));
8735 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
8736 saved_package_name
);
8739 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8741 sym
= allocate_symbol (objfile
);
8742 SYMBOL_SET_LANGUAGE (sym
, language_go
, &objfile
->objfile_obstack
);
8743 SYMBOL_SET_NAMES (sym
, saved_package_name
,
8744 strlen (saved_package_name
), 0, objfile
);
8745 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
8746 e.g., "main" finds the "main" module and not C's main(). */
8747 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
8748 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
8749 SYMBOL_TYPE (sym
) = type
;
8751 add_symbol_to_list (sym
, &global_symbols
);
8753 xfree (package_name
);
8757 /* Return the symtab for PER_CU. This works properly regardless of
8758 whether we're using the index or psymtabs. */
8760 static struct compunit_symtab
*
8761 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
8763 return (dwarf2_per_objfile
->using_index
8764 ? per_cu
->v
.quick
->compunit_symtab
8765 : per_cu
->v
.psymtab
->compunit_symtab
);
8768 /* A helper function for computing the list of all symbol tables
8769 included by PER_CU. */
8772 recursively_compute_inclusions (VEC (compunit_symtab_ptr
) **result
,
8773 htab_t all_children
, htab_t all_type_symtabs
,
8774 struct dwarf2_per_cu_data
*per_cu
,
8775 struct compunit_symtab
*immediate_parent
)
8779 struct compunit_symtab
*cust
;
8780 struct dwarf2_per_cu_data
*iter
;
8782 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
8785 /* This inclusion and its children have been processed. */
8790 /* Only add a CU if it has a symbol table. */
8791 cust
= get_compunit_symtab (per_cu
);
8794 /* If this is a type unit only add its symbol table if we haven't
8795 seen it yet (type unit per_cu's can share symtabs). */
8796 if (per_cu
->is_debug_types
)
8798 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
8802 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
8803 if (cust
->user
== NULL
)
8804 cust
->user
= immediate_parent
;
8809 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
8810 if (cust
->user
== NULL
)
8811 cust
->user
= immediate_parent
;
8816 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, ix
, iter
);
8819 recursively_compute_inclusions (result
, all_children
,
8820 all_type_symtabs
, iter
, cust
);
8824 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
8828 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
8830 gdb_assert (! per_cu
->is_debug_types
);
8832 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
))
8835 struct dwarf2_per_cu_data
*per_cu_iter
;
8836 struct compunit_symtab
*compunit_symtab_iter
;
8837 VEC (compunit_symtab_ptr
) *result_symtabs
= NULL
;
8838 htab_t all_children
, all_type_symtabs
;
8839 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
8841 /* If we don't have a symtab, we can just skip this case. */
8845 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
8846 NULL
, xcalloc
, xfree
);
8847 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
8848 NULL
, xcalloc
, xfree
);
8851 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
,
8855 recursively_compute_inclusions (&result_symtabs
, all_children
,
8856 all_type_symtabs
, per_cu_iter
,
8860 /* Now we have a transitive closure of all the included symtabs. */
8861 len
= VEC_length (compunit_symtab_ptr
, result_symtabs
);
8863 = XOBNEWVEC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
8864 struct compunit_symtab
*, len
+ 1);
8866 VEC_iterate (compunit_symtab_ptr
, result_symtabs
, ix
,
8867 compunit_symtab_iter
);
8869 cust
->includes
[ix
] = compunit_symtab_iter
;
8870 cust
->includes
[len
] = NULL
;
8872 VEC_free (compunit_symtab_ptr
, result_symtabs
);
8873 htab_delete (all_children
);
8874 htab_delete (all_type_symtabs
);
8878 /* Compute the 'includes' field for the symtabs of all the CUs we just
8882 process_cu_includes (void)
8885 struct dwarf2_per_cu_data
*iter
;
8888 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
8892 if (! iter
->is_debug_types
)
8893 compute_compunit_symtab_includes (iter
);
8896 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
8899 /* Generate full symbol information for PER_CU, whose DIEs have
8900 already been loaded into memory. */
8903 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8904 enum language pretend_language
)
8906 struct dwarf2_cu
*cu
= per_cu
->cu
;
8907 struct objfile
*objfile
= per_cu
->objfile
;
8908 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8909 CORE_ADDR lowpc
, highpc
;
8910 struct compunit_symtab
*cust
;
8911 struct cleanup
*delayed_list_cleanup
;
8913 struct block
*static_block
;
8916 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8919 scoped_free_pendings free_pending
;
8920 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
8922 cu
->list_in_scope
= &file_symbols
;
8924 cu
->language
= pretend_language
;
8925 cu
->language_defn
= language_def (cu
->language
);
8927 /* Do line number decoding in read_file_scope () */
8928 process_die (cu
->dies
, cu
);
8930 /* For now fudge the Go package. */
8931 if (cu
->language
== language_go
)
8932 fixup_go_packaging (cu
);
8934 /* Now that we have processed all the DIEs in the CU, all the types
8935 should be complete, and it should now be safe to compute all of the
8937 compute_delayed_physnames (cu
);
8938 do_cleanups (delayed_list_cleanup
);
8940 /* Some compilers don't define a DW_AT_high_pc attribute for the
8941 compilation unit. If the DW_AT_high_pc is missing, synthesize
8942 it, by scanning the DIE's below the compilation unit. */
8943 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
8945 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
8946 static_block
= end_symtab_get_static_block (addr
, 0, 1);
8948 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
8949 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
8950 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
8951 addrmap to help ensure it has an accurate map of pc values belonging to
8953 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
8955 cust
= end_symtab_from_static_block (static_block
,
8956 SECT_OFF_TEXT (objfile
), 0);
8960 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
8962 /* Set symtab language to language from DW_AT_language. If the
8963 compilation is from a C file generated by language preprocessors, do
8964 not set the language if it was already deduced by start_subfile. */
8965 if (!(cu
->language
== language_c
8966 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
8967 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
8969 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
8970 produce DW_AT_location with location lists but it can be possibly
8971 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
8972 there were bugs in prologue debug info, fixed later in GCC-4.5
8973 by "unwind info for epilogues" patch (which is not directly related).
8975 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
8976 needed, it would be wrong due to missing DW_AT_producer there.
8978 Still one can confuse GDB by using non-standard GCC compilation
8979 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
8981 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
8982 cust
->locations_valid
= 1;
8984 if (gcc_4_minor
>= 5)
8985 cust
->epilogue_unwind_valid
= 1;
8987 cust
->call_site_htab
= cu
->call_site_htab
;
8990 if (dwarf2_per_objfile
->using_index
)
8991 per_cu
->v
.quick
->compunit_symtab
= cust
;
8994 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8995 pst
->compunit_symtab
= cust
;
8999 /* Push it for inclusion processing later. */
9000 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
9003 /* Generate full symbol information for type unit PER_CU, whose DIEs have
9004 already been loaded into memory. */
9007 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
9008 enum language pretend_language
)
9010 struct dwarf2_cu
*cu
= per_cu
->cu
;
9011 struct objfile
*objfile
= per_cu
->objfile
;
9012 struct compunit_symtab
*cust
;
9013 struct cleanup
*delayed_list_cleanup
;
9014 struct signatured_type
*sig_type
;
9016 gdb_assert (per_cu
->is_debug_types
);
9017 sig_type
= (struct signatured_type
*) per_cu
;
9020 scoped_free_pendings free_pending
;
9021 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
9023 cu
->list_in_scope
= &file_symbols
;
9025 cu
->language
= pretend_language
;
9026 cu
->language_defn
= language_def (cu
->language
);
9028 /* The symbol tables are set up in read_type_unit_scope. */
9029 process_die (cu
->dies
, cu
);
9031 /* For now fudge the Go package. */
9032 if (cu
->language
== language_go
)
9033 fixup_go_packaging (cu
);
9035 /* Now that we have processed all the DIEs in the CU, all the types
9036 should be complete, and it should now be safe to compute all of the
9038 compute_delayed_physnames (cu
);
9039 do_cleanups (delayed_list_cleanup
);
9041 /* TUs share symbol tables.
9042 If this is the first TU to use this symtab, complete the construction
9043 of it with end_expandable_symtab. Otherwise, complete the addition of
9044 this TU's symbols to the existing symtab. */
9045 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
9047 cust
= end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9048 sig_type
->type_unit_group
->compunit_symtab
= cust
;
9052 /* Set symtab language to language from DW_AT_language. If the
9053 compilation is from a C file generated by language preprocessors,
9054 do not set the language if it was already deduced by
9056 if (!(cu
->language
== language_c
9057 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9058 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9063 augment_type_symtab ();
9064 cust
= sig_type
->type_unit_group
->compunit_symtab
;
9067 if (dwarf2_per_objfile
->using_index
)
9068 per_cu
->v
.quick
->compunit_symtab
= cust
;
9071 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
9072 pst
->compunit_symtab
= cust
;
9077 /* Process an imported unit DIE. */
9080 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9082 struct attribute
*attr
;
9084 /* For now we don't handle imported units in type units. */
9085 if (cu
->per_cu
->is_debug_types
)
9087 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9088 " supported in type units [in module %s]"),
9089 objfile_name (cu
->objfile
));
9092 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9095 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
9096 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9097 dwarf2_per_cu_data
*per_cu
9098 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, cu
->objfile
);
9100 /* If necessary, add it to the queue and load its DIEs. */
9101 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
9102 load_full_comp_unit (per_cu
, cu
->language
);
9104 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
9109 /* RAII object that represents a process_die scope: i.e.,
9110 starts/finishes processing a DIE. */
9111 class process_die_scope
9114 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9115 : m_die (die
), m_cu (cu
)
9117 /* We should only be processing DIEs not already in process. */
9118 gdb_assert (!m_die
->in_process
);
9119 m_die
->in_process
= true;
9122 ~process_die_scope ()
9124 m_die
->in_process
= false;
9126 /* If we're done processing the DIE for the CU that owns the line
9127 header, we don't need the line header anymore. */
9128 if (m_cu
->line_header_die_owner
== m_die
)
9130 delete m_cu
->line_header
;
9131 m_cu
->line_header
= NULL
;
9132 m_cu
->line_header_die_owner
= NULL
;
9141 /* Process a die and its children. */
9144 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9146 process_die_scope
scope (die
, cu
);
9150 case DW_TAG_padding
:
9152 case DW_TAG_compile_unit
:
9153 case DW_TAG_partial_unit
:
9154 read_file_scope (die
, cu
);
9156 case DW_TAG_type_unit
:
9157 read_type_unit_scope (die
, cu
);
9159 case DW_TAG_subprogram
:
9160 case DW_TAG_inlined_subroutine
:
9161 read_func_scope (die
, cu
);
9163 case DW_TAG_lexical_block
:
9164 case DW_TAG_try_block
:
9165 case DW_TAG_catch_block
:
9166 read_lexical_block_scope (die
, cu
);
9168 case DW_TAG_call_site
:
9169 case DW_TAG_GNU_call_site
:
9170 read_call_site_scope (die
, cu
);
9172 case DW_TAG_class_type
:
9173 case DW_TAG_interface_type
:
9174 case DW_TAG_structure_type
:
9175 case DW_TAG_union_type
:
9176 process_structure_scope (die
, cu
);
9178 case DW_TAG_enumeration_type
:
9179 process_enumeration_scope (die
, cu
);
9182 /* These dies have a type, but processing them does not create
9183 a symbol or recurse to process the children. Therefore we can
9184 read them on-demand through read_type_die. */
9185 case DW_TAG_subroutine_type
:
9186 case DW_TAG_set_type
:
9187 case DW_TAG_array_type
:
9188 case DW_TAG_pointer_type
:
9189 case DW_TAG_ptr_to_member_type
:
9190 case DW_TAG_reference_type
:
9191 case DW_TAG_rvalue_reference_type
:
9192 case DW_TAG_string_type
:
9195 case DW_TAG_base_type
:
9196 case DW_TAG_subrange_type
:
9197 case DW_TAG_typedef
:
9198 /* Add a typedef symbol for the type definition, if it has a
9200 new_symbol (die
, read_type_die (die
, cu
), cu
);
9202 case DW_TAG_common_block
:
9203 read_common_block (die
, cu
);
9205 case DW_TAG_common_inclusion
:
9207 case DW_TAG_namespace
:
9208 cu
->processing_has_namespace_info
= 1;
9209 read_namespace (die
, cu
);
9212 cu
->processing_has_namespace_info
= 1;
9213 read_module (die
, cu
);
9215 case DW_TAG_imported_declaration
:
9216 cu
->processing_has_namespace_info
= 1;
9217 if (read_namespace_alias (die
, cu
))
9219 /* The declaration is not a global namespace alias: fall through. */
9220 case DW_TAG_imported_module
:
9221 cu
->processing_has_namespace_info
= 1;
9222 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
9223 || cu
->language
!= language_fortran
))
9224 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
9225 dwarf_tag_name (die
->tag
));
9226 read_import_statement (die
, cu
);
9229 case DW_TAG_imported_unit
:
9230 process_imported_unit_die (die
, cu
);
9234 new_symbol (die
, NULL
, cu
);
9239 /* DWARF name computation. */
9241 /* A helper function for dwarf2_compute_name which determines whether DIE
9242 needs to have the name of the scope prepended to the name listed in the
9246 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9248 struct attribute
*attr
;
9252 case DW_TAG_namespace
:
9253 case DW_TAG_typedef
:
9254 case DW_TAG_class_type
:
9255 case DW_TAG_interface_type
:
9256 case DW_TAG_structure_type
:
9257 case DW_TAG_union_type
:
9258 case DW_TAG_enumeration_type
:
9259 case DW_TAG_enumerator
:
9260 case DW_TAG_subprogram
:
9261 case DW_TAG_inlined_subroutine
:
9263 case DW_TAG_imported_declaration
:
9266 case DW_TAG_variable
:
9267 case DW_TAG_constant
:
9268 /* We only need to prefix "globally" visible variables. These include
9269 any variable marked with DW_AT_external or any variable that
9270 lives in a namespace. [Variables in anonymous namespaces
9271 require prefixing, but they are not DW_AT_external.] */
9273 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
9275 struct dwarf2_cu
*spec_cu
= cu
;
9277 return die_needs_namespace (die_specification (die
, &spec_cu
),
9281 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9282 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
9283 && die
->parent
->tag
!= DW_TAG_module
)
9285 /* A variable in a lexical block of some kind does not need a
9286 namespace, even though in C++ such variables may be external
9287 and have a mangled name. */
9288 if (die
->parent
->tag
== DW_TAG_lexical_block
9289 || die
->parent
->tag
== DW_TAG_try_block
9290 || die
->parent
->tag
== DW_TAG_catch_block
9291 || die
->parent
->tag
== DW_TAG_subprogram
)
9300 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
9301 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9302 defined for the given DIE. */
9304 static struct attribute
*
9305 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
9307 struct attribute
*attr
;
9309 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
9311 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9316 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
9317 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9318 defined for the given DIE. */
9321 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9323 const char *linkage_name
;
9325 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
9326 if (linkage_name
== NULL
)
9327 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9329 return linkage_name
;
9332 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
9333 compute the physname for the object, which include a method's:
9334 - formal parameters (C++),
9335 - receiver type (Go),
9337 The term "physname" is a bit confusing.
9338 For C++, for example, it is the demangled name.
9339 For Go, for example, it's the mangled name.
9341 For Ada, return the DIE's linkage name rather than the fully qualified
9342 name. PHYSNAME is ignored..
9344 The result is allocated on the objfile_obstack and canonicalized. */
9347 dwarf2_compute_name (const char *name
,
9348 struct die_info
*die
, struct dwarf2_cu
*cu
,
9351 struct objfile
*objfile
= cu
->objfile
;
9354 name
= dwarf2_name (die
, cu
);
9356 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
9357 but otherwise compute it by typename_concat inside GDB.
9358 FIXME: Actually this is not really true, or at least not always true.
9359 It's all very confusing. SYMBOL_SET_NAMES doesn't try to demangle
9360 Fortran names because there is no mangling standard. So new_symbol_full
9361 will set the demangled name to the result of dwarf2_full_name, and it is
9362 the demangled name that GDB uses if it exists. */
9363 if (cu
->language
== language_ada
9364 || (cu
->language
== language_fortran
&& physname
))
9366 /* For Ada unit, we prefer the linkage name over the name, as
9367 the former contains the exported name, which the user expects
9368 to be able to reference. Ideally, we want the user to be able
9369 to reference this entity using either natural or linkage name,
9370 but we haven't started looking at this enhancement yet. */
9371 const char *linkage_name
= dw2_linkage_name (die
, cu
);
9373 if (linkage_name
!= NULL
)
9374 return linkage_name
;
9377 /* These are the only languages we know how to qualify names in. */
9379 && (cu
->language
== language_cplus
9380 || cu
->language
== language_fortran
|| cu
->language
== language_d
9381 || cu
->language
== language_rust
))
9383 if (die_needs_namespace (die
, cu
))
9387 const char *canonical_name
= NULL
;
9391 prefix
= determine_prefix (die
, cu
);
9392 if (*prefix
!= '\0')
9394 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
9397 buf
.puts (prefixed_name
);
9398 xfree (prefixed_name
);
9403 /* Template parameters may be specified in the DIE's DW_AT_name, or
9404 as children with DW_TAG_template_type_param or
9405 DW_TAG_value_type_param. If the latter, add them to the name
9406 here. If the name already has template parameters, then
9407 skip this step; some versions of GCC emit both, and
9408 it is more efficient to use the pre-computed name.
9410 Something to keep in mind about this process: it is very
9411 unlikely, or in some cases downright impossible, to produce
9412 something that will match the mangled name of a function.
9413 If the definition of the function has the same debug info,
9414 we should be able to match up with it anyway. But fallbacks
9415 using the minimal symbol, for instance to find a method
9416 implemented in a stripped copy of libstdc++, will not work.
9417 If we do not have debug info for the definition, we will have to
9418 match them up some other way.
9420 When we do name matching there is a related problem with function
9421 templates; two instantiated function templates are allowed to
9422 differ only by their return types, which we do not add here. */
9424 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
9426 struct attribute
*attr
;
9427 struct die_info
*child
;
9430 die
->building_fullname
= 1;
9432 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
9436 const gdb_byte
*bytes
;
9437 struct dwarf2_locexpr_baton
*baton
;
9440 if (child
->tag
!= DW_TAG_template_type_param
9441 && child
->tag
!= DW_TAG_template_value_param
)
9452 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
9455 complaint (&symfile_complaints
,
9456 _("template parameter missing DW_AT_type"));
9457 buf
.puts ("UNKNOWN_TYPE");
9460 type
= die_type (child
, cu
);
9462 if (child
->tag
== DW_TAG_template_type_param
)
9464 c_print_type (type
, "", &buf
, -1, 0, &type_print_raw_options
);
9468 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
9471 complaint (&symfile_complaints
,
9472 _("template parameter missing "
9473 "DW_AT_const_value"));
9474 buf
.puts ("UNKNOWN_VALUE");
9478 dwarf2_const_value_attr (attr
, type
, name
,
9479 &cu
->comp_unit_obstack
, cu
,
9480 &value
, &bytes
, &baton
);
9482 if (TYPE_NOSIGN (type
))
9483 /* GDB prints characters as NUMBER 'CHAR'. If that's
9484 changed, this can use value_print instead. */
9485 c_printchar (value
, type
, &buf
);
9488 struct value_print_options opts
;
9491 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
9495 else if (bytes
!= NULL
)
9497 v
= allocate_value (type
);
9498 memcpy (value_contents_writeable (v
), bytes
,
9499 TYPE_LENGTH (type
));
9502 v
= value_from_longest (type
, value
);
9504 /* Specify decimal so that we do not depend on
9506 get_formatted_print_options (&opts
, 'd');
9508 value_print (v
, &buf
, &opts
);
9514 die
->building_fullname
= 0;
9518 /* Close the argument list, with a space if necessary
9519 (nested templates). */
9520 if (!buf
.empty () && buf
.string ().back () == '>')
9527 /* For C++ methods, append formal parameter type
9528 information, if PHYSNAME. */
9530 if (physname
&& die
->tag
== DW_TAG_subprogram
9531 && cu
->language
== language_cplus
)
9533 struct type
*type
= read_type_die (die
, cu
);
9535 c_type_print_args (type
, &buf
, 1, cu
->language
,
9536 &type_print_raw_options
);
9538 if (cu
->language
== language_cplus
)
9540 /* Assume that an artificial first parameter is
9541 "this", but do not crash if it is not. RealView
9542 marks unnamed (and thus unused) parameters as
9543 artificial; there is no way to differentiate
9545 if (TYPE_NFIELDS (type
) > 0
9546 && TYPE_FIELD_ARTIFICIAL (type
, 0)
9547 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
9548 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
9550 buf
.puts (" const");
9554 const std::string
&intermediate_name
= buf
.string ();
9556 if (cu
->language
== language_cplus
)
9558 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
9559 &objfile
->per_bfd
->storage_obstack
);
9561 /* If we only computed INTERMEDIATE_NAME, or if
9562 INTERMEDIATE_NAME is already canonical, then we need to
9563 copy it to the appropriate obstack. */
9564 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
9565 name
= ((const char *)
9566 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
9567 intermediate_name
.c_str (),
9568 intermediate_name
.length ()));
9570 name
= canonical_name
;
9577 /* Return the fully qualified name of DIE, based on its DW_AT_name.
9578 If scope qualifiers are appropriate they will be added. The result
9579 will be allocated on the storage_obstack, or NULL if the DIE does
9580 not have a name. NAME may either be from a previous call to
9581 dwarf2_name or NULL.
9583 The output string will be canonicalized (if C++). */
9586 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
9588 return dwarf2_compute_name (name
, die
, cu
, 0);
9591 /* Construct a physname for the given DIE in CU. NAME may either be
9592 from a previous call to dwarf2_name or NULL. The result will be
9593 allocated on the objfile_objstack or NULL if the DIE does not have a
9596 The output string will be canonicalized (if C++). */
9599 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
9601 struct objfile
*objfile
= cu
->objfile
;
9602 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
9605 /* In this case dwarf2_compute_name is just a shortcut not building anything
9607 if (!die_needs_namespace (die
, cu
))
9608 return dwarf2_compute_name (name
, die
, cu
, 1);
9610 mangled
= dw2_linkage_name (die
, cu
);
9612 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
9613 See https://github.com/rust-lang/rust/issues/32925. */
9614 if (cu
->language
== language_rust
&& mangled
!= NULL
9615 && strchr (mangled
, '{') != NULL
)
9618 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
9620 gdb::unique_xmalloc_ptr
<char> demangled
;
9621 if (mangled
!= NULL
)
9623 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
9624 type. It is easier for GDB users to search for such functions as
9625 `name(params)' than `long name(params)'. In such case the minimal
9626 symbol names do not match the full symbol names but for template
9627 functions there is never a need to look up their definition from their
9628 declaration so the only disadvantage remains the minimal symbol
9629 variant `long name(params)' does not have the proper inferior type.
9632 if (cu
->language
== language_go
)
9634 /* This is a lie, but we already lie to the caller new_symbol_full.
9635 new_symbol_full assumes we return the mangled name.
9636 This just undoes that lie until things are cleaned up. */
9640 demangled
.reset (gdb_demangle (mangled
,
9641 (DMGL_PARAMS
| DMGL_ANSI
9645 canon
= demangled
.get ();
9653 if (canon
== NULL
|| check_physname
)
9655 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
9657 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
9659 /* It may not mean a bug in GDB. The compiler could also
9660 compute DW_AT_linkage_name incorrectly. But in such case
9661 GDB would need to be bug-to-bug compatible. */
9663 complaint (&symfile_complaints
,
9664 _("Computed physname <%s> does not match demangled <%s> "
9665 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
9666 physname
, canon
, mangled
, to_underlying (die
->sect_off
),
9667 objfile_name (objfile
));
9669 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
9670 is available here - over computed PHYSNAME. It is safer
9671 against both buggy GDB and buggy compilers. */
9685 retval
= ((const char *)
9686 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
9687 retval
, strlen (retval
)));
9692 /* Inspect DIE in CU for a namespace alias. If one exists, record
9693 a new symbol for it.
9695 Returns 1 if a namespace alias was recorded, 0 otherwise. */
9698 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
9700 struct attribute
*attr
;
9702 /* If the die does not have a name, this is not a namespace
9704 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
9708 struct die_info
*d
= die
;
9709 struct dwarf2_cu
*imported_cu
= cu
;
9711 /* If the compiler has nested DW_AT_imported_declaration DIEs,
9712 keep inspecting DIEs until we hit the underlying import. */
9713 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
9714 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
9716 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
9720 d
= follow_die_ref (d
, attr
, &imported_cu
);
9721 if (d
->tag
!= DW_TAG_imported_declaration
)
9725 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
9727 complaint (&symfile_complaints
,
9728 _("DIE at 0x%x has too many recursively imported "
9729 "declarations"), to_underlying (d
->sect_off
));
9736 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
9738 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
9739 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
9741 /* This declaration is a global namespace alias. Add
9742 a symbol for it whose type is the aliased namespace. */
9743 new_symbol (die
, type
, cu
);
9752 /* Return the using directives repository (global or local?) to use in the
9753 current context for LANGUAGE.
9755 For Ada, imported declarations can materialize renamings, which *may* be
9756 global. However it is impossible (for now?) in DWARF to distinguish
9757 "external" imported declarations and "static" ones. As all imported
9758 declarations seem to be static in all other languages, make them all CU-wide
9759 global only in Ada. */
9761 static struct using_direct
**
9762 using_directives (enum language language
)
9764 if (language
== language_ada
&& context_stack_depth
== 0)
9765 return &global_using_directives
;
9767 return &local_using_directives
;
9770 /* Read the import statement specified by the given die and record it. */
9773 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
9775 struct objfile
*objfile
= cu
->objfile
;
9776 struct attribute
*import_attr
;
9777 struct die_info
*imported_die
, *child_die
;
9778 struct dwarf2_cu
*imported_cu
;
9779 const char *imported_name
;
9780 const char *imported_name_prefix
;
9781 const char *canonical_name
;
9782 const char *import_alias
;
9783 const char *imported_declaration
= NULL
;
9784 const char *import_prefix
;
9785 std::vector
<const char *> excludes
;
9787 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9788 if (import_attr
== NULL
)
9790 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
9791 dwarf_tag_name (die
->tag
));
9796 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
9797 imported_name
= dwarf2_name (imported_die
, imported_cu
);
9798 if (imported_name
== NULL
)
9800 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
9802 The import in the following code:
9816 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
9817 <52> DW_AT_decl_file : 1
9818 <53> DW_AT_decl_line : 6
9819 <54> DW_AT_import : <0x75>
9820 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
9822 <5b> DW_AT_decl_file : 1
9823 <5c> DW_AT_decl_line : 2
9824 <5d> DW_AT_type : <0x6e>
9826 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
9827 <76> DW_AT_byte_size : 4
9828 <77> DW_AT_encoding : 5 (signed)
9830 imports the wrong die ( 0x75 instead of 0x58 ).
9831 This case will be ignored until the gcc bug is fixed. */
9835 /* Figure out the local name after import. */
9836 import_alias
= dwarf2_name (die
, cu
);
9838 /* Figure out where the statement is being imported to. */
9839 import_prefix
= determine_prefix (die
, cu
);
9841 /* Figure out what the scope of the imported die is and prepend it
9842 to the name of the imported die. */
9843 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
9845 if (imported_die
->tag
!= DW_TAG_namespace
9846 && imported_die
->tag
!= DW_TAG_module
)
9848 imported_declaration
= imported_name
;
9849 canonical_name
= imported_name_prefix
;
9851 else if (strlen (imported_name_prefix
) > 0)
9852 canonical_name
= obconcat (&objfile
->objfile_obstack
,
9853 imported_name_prefix
,
9854 (cu
->language
== language_d
? "." : "::"),
9855 imported_name
, (char *) NULL
);
9857 canonical_name
= imported_name
;
9859 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
9860 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
9861 child_die
= sibling_die (child_die
))
9863 /* DWARF-4: A Fortran use statement with a “rename list” may be
9864 represented by an imported module entry with an import attribute
9865 referring to the module and owned entries corresponding to those
9866 entities that are renamed as part of being imported. */
9868 if (child_die
->tag
!= DW_TAG_imported_declaration
)
9870 complaint (&symfile_complaints
,
9871 _("child DW_TAG_imported_declaration expected "
9872 "- DIE at 0x%x [in module %s]"),
9873 to_underlying (child_die
->sect_off
), objfile_name (objfile
));
9877 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
9878 if (import_attr
== NULL
)
9880 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
9881 dwarf_tag_name (child_die
->tag
));
9886 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
9888 imported_name
= dwarf2_name (imported_die
, imported_cu
);
9889 if (imported_name
== NULL
)
9891 complaint (&symfile_complaints
,
9892 _("child DW_TAG_imported_declaration has unknown "
9893 "imported name - DIE at 0x%x [in module %s]"),
9894 to_underlying (child_die
->sect_off
), objfile_name (objfile
));
9898 excludes
.push_back (imported_name
);
9900 process_die (child_die
, cu
);
9903 add_using_directive (using_directives (cu
->language
),
9907 imported_declaration
,
9910 &objfile
->objfile_obstack
);
9913 /* ICC<14 does not output the required DW_AT_declaration on incomplete
9914 types, but gives them a size of zero. Starting with version 14,
9915 ICC is compatible with GCC. */
9918 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
9920 if (!cu
->checked_producer
)
9921 check_producer (cu
);
9923 return cu
->producer_is_icc_lt_14
;
9926 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
9927 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
9928 this, it was first present in GCC release 4.3.0. */
9931 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
9933 if (!cu
->checked_producer
)
9934 check_producer (cu
);
9936 return cu
->producer_is_gcc_lt_4_3
;
9939 static file_and_directory
9940 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
9942 file_and_directory res
;
9944 /* Find the filename. Do not use dwarf2_name here, since the filename
9945 is not a source language identifier. */
9946 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
9947 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
9949 if (res
.comp_dir
== NULL
9950 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
9951 && IS_ABSOLUTE_PATH (res
.name
))
9953 res
.comp_dir_storage
= ldirname (res
.name
);
9954 if (!res
.comp_dir_storage
.empty ())
9955 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
9957 if (res
.comp_dir
!= NULL
)
9959 /* Irix 6.2 native cc prepends <machine>.: to the compilation
9960 directory, get rid of it. */
9961 const char *cp
= strchr (res
.comp_dir
, ':');
9963 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
9964 res
.comp_dir
= cp
+ 1;
9967 if (res
.name
== NULL
)
9968 res
.name
= "<unknown>";
9973 /* Handle DW_AT_stmt_list for a compilation unit.
9974 DIE is the DW_TAG_compile_unit die for CU.
9975 COMP_DIR is the compilation directory. LOWPC is passed to
9976 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
9979 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
9980 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
9982 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9983 struct attribute
*attr
;
9984 struct line_header line_header_local
;
9985 hashval_t line_header_local_hash
;
9990 gdb_assert (! cu
->per_cu
->is_debug_types
);
9992 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
9996 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
9998 /* The line header hash table is only created if needed (it exists to
9999 prevent redundant reading of the line table for partial_units).
10000 If we're given a partial_unit, we'll need it. If we're given a
10001 compile_unit, then use the line header hash table if it's already
10002 created, but don't create one just yet. */
10004 if (dwarf2_per_objfile
->line_header_hash
== NULL
10005 && die
->tag
== DW_TAG_partial_unit
)
10007 dwarf2_per_objfile
->line_header_hash
10008 = htab_create_alloc_ex (127, line_header_hash_voidp
,
10009 line_header_eq_voidp
,
10010 free_line_header_voidp
,
10011 &objfile
->objfile_obstack
,
10012 hashtab_obstack_allocate
,
10013 dummy_obstack_deallocate
);
10016 line_header_local
.sect_off
= line_offset
;
10017 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10018 line_header_local_hash
= line_header_hash (&line_header_local
);
10019 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
10021 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
10022 &line_header_local
,
10023 line_header_local_hash
, NO_INSERT
);
10025 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10026 is not present in *SLOT (since if there is something in *SLOT then
10027 it will be for a partial_unit). */
10028 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10030 gdb_assert (*slot
!= NULL
);
10031 cu
->line_header
= (struct line_header
*) *slot
;
10036 /* dwarf_decode_line_header does not yet provide sufficient information.
10037 We always have to call also dwarf_decode_lines for it. */
10038 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10042 cu
->line_header
= lh
.release ();
10043 cu
->line_header_die_owner
= die
;
10045 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
10049 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
10050 &line_header_local
,
10051 line_header_local_hash
, INSERT
);
10052 gdb_assert (slot
!= NULL
);
10054 if (slot
!= NULL
&& *slot
== NULL
)
10056 /* This newly decoded line number information unit will be owned
10057 by line_header_hash hash table. */
10058 *slot
= cu
->line_header
;
10059 cu
->line_header_die_owner
= NULL
;
10063 /* We cannot free any current entry in (*slot) as that struct line_header
10064 may be already used by multiple CUs. Create only temporary decoded
10065 line_header for this CU - it may happen at most once for each line
10066 number information unit. And if we're not using line_header_hash
10067 then this is what we want as well. */
10068 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10070 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10071 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10076 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10079 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10081 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10082 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10083 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10084 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10085 struct attribute
*attr
;
10086 struct die_info
*child_die
;
10087 CORE_ADDR baseaddr
;
10089 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10091 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10093 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10094 from finish_block. */
10095 if (lowpc
== ((CORE_ADDR
) -1))
10097 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10099 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10101 prepare_one_comp_unit (cu
, die
, cu
->language
);
10103 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
10104 standardised yet. As a workaround for the language detection we fall
10105 back to the DW_AT_producer string. */
10106 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
10107 cu
->language
= language_opencl
;
10109 /* Similar hack for Go. */
10110 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
10111 set_cu_language (DW_LANG_Go
, cu
);
10113 dwarf2_start_symtab (cu
, fnd
.name
, fnd
.comp_dir
, lowpc
);
10115 /* Decode line number information if present. We do this before
10116 processing child DIEs, so that the line header table is available
10117 for DW_AT_decl_file. */
10118 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10120 /* Process all dies in compilation unit. */
10121 if (die
->child
!= NULL
)
10123 child_die
= die
->child
;
10124 while (child_die
&& child_die
->tag
)
10126 process_die (child_die
, cu
);
10127 child_die
= sibling_die (child_die
);
10131 /* Decode macro information, if present. Dwarf 2 macro information
10132 refers to information in the line number info statement program
10133 header, so we can only read it if we've read the header
10135 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10137 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10138 if (attr
&& cu
->line_header
)
10140 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10141 complaint (&symfile_complaints
,
10142 _("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10144 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
10148 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10149 if (attr
&& cu
->line_header
)
10151 unsigned int macro_offset
= DW_UNSND (attr
);
10153 dwarf_decode_macros (cu
, macro_offset
, 0);
10158 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
10159 Create the set of symtabs used by this TU, or if this TU is sharing
10160 symtabs with another TU and the symtabs have already been created
10161 then restore those symtabs in the line header.
10162 We don't need the pc/line-number mapping for type units. */
10165 setup_type_unit_groups (struct die_info
*die
, struct dwarf2_cu
*cu
)
10167 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
10168 struct type_unit_group
*tu_group
;
10170 struct attribute
*attr
;
10172 struct signatured_type
*sig_type
;
10174 gdb_assert (per_cu
->is_debug_types
);
10175 sig_type
= (struct signatured_type
*) per_cu
;
10177 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10179 /* If we're using .gdb_index (includes -readnow) then
10180 per_cu->type_unit_group may not have been set up yet. */
10181 if (sig_type
->type_unit_group
== NULL
)
10182 sig_type
->type_unit_group
= get_type_unit_group (cu
, attr
);
10183 tu_group
= sig_type
->type_unit_group
;
10185 /* If we've already processed this stmt_list there's no real need to
10186 do it again, we could fake it and just recreate the part we need
10187 (file name,index -> symtab mapping). If data shows this optimization
10188 is useful we can do it then. */
10189 first_time
= tu_group
->compunit_symtab
== NULL
;
10191 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10196 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10197 lh
= dwarf_decode_line_header (line_offset
, cu
);
10202 dwarf2_start_symtab (cu
, "", NULL
, 0);
10205 gdb_assert (tu_group
->symtabs
== NULL
);
10206 restart_symtab (tu_group
->compunit_symtab
, "", 0);
10211 cu
->line_header
= lh
.release ();
10212 cu
->line_header_die_owner
= die
;
10216 struct compunit_symtab
*cust
= dwarf2_start_symtab (cu
, "", NULL
, 0);
10218 /* Note: We don't assign tu_group->compunit_symtab yet because we're
10219 still initializing it, and our caller (a few levels up)
10220 process_full_type_unit still needs to know if this is the first
10223 tu_group
->num_symtabs
= cu
->line_header
->file_names
.size ();
10224 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
10225 cu
->line_header
->file_names
.size ());
10227 for (i
= 0; i
< cu
->line_header
->file_names
.size (); ++i
)
10229 file_entry
&fe
= cu
->line_header
->file_names
[i
];
10231 dwarf2_start_subfile (fe
.name
, fe
.include_dir (cu
->line_header
));
10233 if (current_subfile
->symtab
== NULL
)
10235 /* NOTE: start_subfile will recognize when it's been
10236 passed a file it has already seen. So we can't
10237 assume there's a simple mapping from
10238 cu->line_header->file_names to subfiles, plus
10239 cu->line_header->file_names may contain dups. */
10240 current_subfile
->symtab
10241 = allocate_symtab (cust
, current_subfile
->name
);
10244 fe
.symtab
= current_subfile
->symtab
;
10245 tu_group
->symtabs
[i
] = fe
.symtab
;
10250 restart_symtab (tu_group
->compunit_symtab
, "", 0);
10252 for (i
= 0; i
< cu
->line_header
->file_names
.size (); ++i
)
10254 file_entry
&fe
= cu
->line_header
->file_names
[i
];
10256 fe
.symtab
= tu_group
->symtabs
[i
];
10260 /* The main symtab is allocated last. Type units don't have DW_AT_name
10261 so they don't have a "real" (so to speak) symtab anyway.
10262 There is later code that will assign the main symtab to all symbols
10263 that don't have one. We need to handle the case of a symbol with a
10264 missing symtab (DW_AT_decl_file) anyway. */
10267 /* Process DW_TAG_type_unit.
10268 For TUs we want to skip the first top level sibling if it's not the
10269 actual type being defined by this TU. In this case the first top
10270 level sibling is there to provide context only. */
10273 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10275 struct die_info
*child_die
;
10277 prepare_one_comp_unit (cu
, die
, language_minimal
);
10279 /* Initialize (or reinitialize) the machinery for building symtabs.
10280 We do this before processing child DIEs, so that the line header table
10281 is available for DW_AT_decl_file. */
10282 setup_type_unit_groups (die
, cu
);
10284 if (die
->child
!= NULL
)
10286 child_die
= die
->child
;
10287 while (child_die
&& child_die
->tag
)
10289 process_die (child_die
, cu
);
10290 child_die
= sibling_die (child_die
);
10297 http://gcc.gnu.org/wiki/DebugFission
10298 http://gcc.gnu.org/wiki/DebugFissionDWP
10300 To simplify handling of both DWO files ("object" files with the DWARF info)
10301 and DWP files (a file with the DWOs packaged up into one file), we treat
10302 DWP files as having a collection of virtual DWO files. */
10305 hash_dwo_file (const void *item
)
10307 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
10310 hash
= htab_hash_string (dwo_file
->dwo_name
);
10311 if (dwo_file
->comp_dir
!= NULL
)
10312 hash
+= htab_hash_string (dwo_file
->comp_dir
);
10317 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
10319 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
10320 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
10322 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
10324 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
10325 return lhs
->comp_dir
== rhs
->comp_dir
;
10326 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
10329 /* Allocate a hash table for DWO files. */
10332 allocate_dwo_file_hash_table (void)
10334 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10336 return htab_create_alloc_ex (41,
10340 &objfile
->objfile_obstack
,
10341 hashtab_obstack_allocate
,
10342 dummy_obstack_deallocate
);
10345 /* Lookup DWO file DWO_NAME. */
10348 lookup_dwo_file_slot (const char *dwo_name
, const char *comp_dir
)
10350 struct dwo_file find_entry
;
10353 if (dwarf2_per_objfile
->dwo_files
== NULL
)
10354 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
10356 memset (&find_entry
, 0, sizeof (find_entry
));
10357 find_entry
.dwo_name
= dwo_name
;
10358 find_entry
.comp_dir
= comp_dir
;
10359 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
10365 hash_dwo_unit (const void *item
)
10367 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
10369 /* This drops the top 32 bits of the id, but is ok for a hash. */
10370 return dwo_unit
->signature
;
10374 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
10376 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
10377 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
10379 /* The signature is assumed to be unique within the DWO file.
10380 So while object file CU dwo_id's always have the value zero,
10381 that's OK, assuming each object file DWO file has only one CU,
10382 and that's the rule for now. */
10383 return lhs
->signature
== rhs
->signature
;
10386 /* Allocate a hash table for DWO CUs,TUs.
10387 There is one of these tables for each of CUs,TUs for each DWO file. */
10390 allocate_dwo_unit_table (struct objfile
*objfile
)
10392 /* Start out with a pretty small number.
10393 Generally DWO files contain only one CU and maybe some TUs. */
10394 return htab_create_alloc_ex (3,
10398 &objfile
->objfile_obstack
,
10399 hashtab_obstack_allocate
,
10400 dummy_obstack_deallocate
);
10403 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
10405 struct create_dwo_cu_data
10407 struct dwo_file
*dwo_file
;
10408 struct dwo_unit dwo_unit
;
10411 /* die_reader_func for create_dwo_cu. */
10414 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
10415 const gdb_byte
*info_ptr
,
10416 struct die_info
*comp_unit_die
,
10420 struct dwarf2_cu
*cu
= reader
->cu
;
10421 sect_offset sect_off
= cu
->per_cu
->sect_off
;
10422 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
10423 struct create_dwo_cu_data
*data
= (struct create_dwo_cu_data
*) datap
;
10424 struct dwo_file
*dwo_file
= data
->dwo_file
;
10425 struct dwo_unit
*dwo_unit
= &data
->dwo_unit
;
10426 struct attribute
*attr
;
10428 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
10431 complaint (&symfile_complaints
,
10432 _("Dwarf Error: debug entry at offset 0x%x is missing"
10433 " its dwo_id [in module %s]"),
10434 to_underlying (sect_off
), dwo_file
->dwo_name
);
10438 dwo_unit
->dwo_file
= dwo_file
;
10439 dwo_unit
->signature
= DW_UNSND (attr
);
10440 dwo_unit
->section
= section
;
10441 dwo_unit
->sect_off
= sect_off
;
10442 dwo_unit
->length
= cu
->per_cu
->length
;
10444 if (dwarf_read_debug
)
10445 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, dwo_id %s\n",
10446 to_underlying (sect_off
),
10447 hex_string (dwo_unit
->signature
));
10450 /* Create the dwo_units for the CUs in a DWO_FILE.
10451 Note: This function processes DWO files only, not DWP files. */
10454 create_cus_hash_table (struct dwo_file
&dwo_file
, dwarf2_section_info
§ion
,
10457 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10458 const struct dwarf2_section_info
*abbrev_section
= &dwo_file
.sections
.abbrev
;
10459 const gdb_byte
*info_ptr
, *end_ptr
;
10461 dwarf2_read_section (objfile
, §ion
);
10462 info_ptr
= section
.buffer
;
10464 if (info_ptr
== NULL
)
10467 if (dwarf_read_debug
)
10469 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
10470 get_section_name (§ion
),
10471 get_section_file_name (§ion
));
10474 end_ptr
= info_ptr
+ section
.size
;
10475 while (info_ptr
< end_ptr
)
10477 struct dwarf2_per_cu_data per_cu
;
10478 struct create_dwo_cu_data create_dwo_cu_data
;
10479 struct dwo_unit
*dwo_unit
;
10481 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
10483 memset (&create_dwo_cu_data
.dwo_unit
, 0,
10484 sizeof (create_dwo_cu_data
.dwo_unit
));
10485 memset (&per_cu
, 0, sizeof (per_cu
));
10486 per_cu
.objfile
= objfile
;
10487 per_cu
.is_debug_types
= 0;
10488 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
10489 per_cu
.section
= §ion
;
10490 create_dwo_cu_data
.dwo_file
= &dwo_file
;
10492 init_cutu_and_read_dies_no_follow (
10493 &per_cu
, &dwo_file
, create_dwo_cu_reader
, &create_dwo_cu_data
);
10494 info_ptr
+= per_cu
.length
;
10496 // If the unit could not be parsed, skip it.
10497 if (create_dwo_cu_data
.dwo_unit
.dwo_file
== NULL
)
10500 if (cus_htab
== NULL
)
10501 cus_htab
= allocate_dwo_unit_table (objfile
);
10503 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
10504 *dwo_unit
= create_dwo_cu_data
.dwo_unit
;
10505 slot
= htab_find_slot (cus_htab
, dwo_unit
, INSERT
);
10506 gdb_assert (slot
!= NULL
);
10509 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
10510 sect_offset dup_sect_off
= dup_cu
->sect_off
;
10512 complaint (&symfile_complaints
,
10513 _("debug cu entry at offset 0x%x is duplicate to"
10514 " the entry at offset 0x%x, signature %s"),
10515 to_underlying (sect_off
), to_underlying (dup_sect_off
),
10516 hex_string (dwo_unit
->signature
));
10518 *slot
= (void *)dwo_unit
;
10522 /* DWP file .debug_{cu,tu}_index section format:
10523 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
10527 Both index sections have the same format, and serve to map a 64-bit
10528 signature to a set of section numbers. Each section begins with a header,
10529 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
10530 indexes, and a pool of 32-bit section numbers. The index sections will be
10531 aligned at 8-byte boundaries in the file.
10533 The index section header consists of:
10535 V, 32 bit version number
10537 N, 32 bit number of compilation units or type units in the index
10538 M, 32 bit number of slots in the hash table
10540 Numbers are recorded using the byte order of the application binary.
10542 The hash table begins at offset 16 in the section, and consists of an array
10543 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
10544 order of the application binary). Unused slots in the hash table are 0.
10545 (We rely on the extreme unlikeliness of a signature being exactly 0.)
10547 The parallel table begins immediately after the hash table
10548 (at offset 16 + 8 * M from the beginning of the section), and consists of an
10549 array of 32-bit indexes (using the byte order of the application binary),
10550 corresponding 1-1 with slots in the hash table. Each entry in the parallel
10551 table contains a 32-bit index into the pool of section numbers. For unused
10552 hash table slots, the corresponding entry in the parallel table will be 0.
10554 The pool of section numbers begins immediately following the hash table
10555 (at offset 16 + 12 * M from the beginning of the section). The pool of
10556 section numbers consists of an array of 32-bit words (using the byte order
10557 of the application binary). Each item in the array is indexed starting
10558 from 0. The hash table entry provides the index of the first section
10559 number in the set. Additional section numbers in the set follow, and the
10560 set is terminated by a 0 entry (section number 0 is not used in ELF).
10562 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
10563 section must be the first entry in the set, and the .debug_abbrev.dwo must
10564 be the second entry. Other members of the set may follow in any order.
10570 DWP Version 2 combines all the .debug_info, etc. sections into one,
10571 and the entries in the index tables are now offsets into these sections.
10572 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
10575 Index Section Contents:
10577 Hash Table of Signatures dwp_hash_table.hash_table
10578 Parallel Table of Indices dwp_hash_table.unit_table
10579 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
10580 Table of Section Sizes dwp_hash_table.v2.sizes
10582 The index section header consists of:
10584 V, 32 bit version number
10585 L, 32 bit number of columns in the table of section offsets
10586 N, 32 bit number of compilation units or type units in the index
10587 M, 32 bit number of slots in the hash table
10589 Numbers are recorded using the byte order of the application binary.
10591 The hash table has the same format as version 1.
10592 The parallel table of indices has the same format as version 1,
10593 except that the entries are origin-1 indices into the table of sections
10594 offsets and the table of section sizes.
10596 The table of offsets begins immediately following the parallel table
10597 (at offset 16 + 12 * M from the beginning of the section). The table is
10598 a two-dimensional array of 32-bit words (using the byte order of the
10599 application binary), with L columns and N+1 rows, in row-major order.
10600 Each row in the array is indexed starting from 0. The first row provides
10601 a key to the remaining rows: each column in this row provides an identifier
10602 for a debug section, and the offsets in the same column of subsequent rows
10603 refer to that section. The section identifiers are:
10605 DW_SECT_INFO 1 .debug_info.dwo
10606 DW_SECT_TYPES 2 .debug_types.dwo
10607 DW_SECT_ABBREV 3 .debug_abbrev.dwo
10608 DW_SECT_LINE 4 .debug_line.dwo
10609 DW_SECT_LOC 5 .debug_loc.dwo
10610 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
10611 DW_SECT_MACINFO 7 .debug_macinfo.dwo
10612 DW_SECT_MACRO 8 .debug_macro.dwo
10614 The offsets provided by the CU and TU index sections are the base offsets
10615 for the contributions made by each CU or TU to the corresponding section
10616 in the package file. Each CU and TU header contains an abbrev_offset
10617 field, used to find the abbreviations table for that CU or TU within the
10618 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
10619 be interpreted as relative to the base offset given in the index section.
10620 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
10621 should be interpreted as relative to the base offset for .debug_line.dwo,
10622 and offsets into other debug sections obtained from DWARF attributes should
10623 also be interpreted as relative to the corresponding base offset.
10625 The table of sizes begins immediately following the table of offsets.
10626 Like the table of offsets, it is a two-dimensional array of 32-bit words,
10627 with L columns and N rows, in row-major order. Each row in the array is
10628 indexed starting from 1 (row 0 is shared by the two tables).
10632 Hash table lookup is handled the same in version 1 and 2:
10634 We assume that N and M will not exceed 2^32 - 1.
10635 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
10637 Given a 64-bit compilation unit signature or a type signature S, an entry
10638 in the hash table is located as follows:
10640 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
10641 the low-order k bits all set to 1.
10643 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
10645 3) If the hash table entry at index H matches the signature, use that
10646 entry. If the hash table entry at index H is unused (all zeroes),
10647 terminate the search: the signature is not present in the table.
10649 4) Let H = (H + H') modulo M. Repeat at Step 3.
10651 Because M > N and H' and M are relatively prime, the search is guaranteed
10652 to stop at an unused slot or find the match. */
10654 /* Create a hash table to map DWO IDs to their CU/TU entry in
10655 .debug_{info,types}.dwo in DWP_FILE.
10656 Returns NULL if there isn't one.
10657 Note: This function processes DWP files only, not DWO files. */
10659 static struct dwp_hash_table
*
10660 create_dwp_hash_table (struct dwp_file
*dwp_file
, int is_debug_types
)
10662 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10663 bfd
*dbfd
= dwp_file
->dbfd
;
10664 const gdb_byte
*index_ptr
, *index_end
;
10665 struct dwarf2_section_info
*index
;
10666 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
10667 struct dwp_hash_table
*htab
;
10669 if (is_debug_types
)
10670 index
= &dwp_file
->sections
.tu_index
;
10672 index
= &dwp_file
->sections
.cu_index
;
10674 if (dwarf2_section_empty_p (index
))
10676 dwarf2_read_section (objfile
, index
);
10678 index_ptr
= index
->buffer
;
10679 index_end
= index_ptr
+ index
->size
;
10681 version
= read_4_bytes (dbfd
, index_ptr
);
10684 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
10688 nr_units
= read_4_bytes (dbfd
, index_ptr
);
10690 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
10693 if (version
!= 1 && version
!= 2)
10695 error (_("Dwarf Error: unsupported DWP file version (%s)"
10696 " [in module %s]"),
10697 pulongest (version
), dwp_file
->name
);
10699 if (nr_slots
!= (nr_slots
& -nr_slots
))
10701 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
10702 " is not power of 2 [in module %s]"),
10703 pulongest (nr_slots
), dwp_file
->name
);
10706 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
10707 htab
->version
= version
;
10708 htab
->nr_columns
= nr_columns
;
10709 htab
->nr_units
= nr_units
;
10710 htab
->nr_slots
= nr_slots
;
10711 htab
->hash_table
= index_ptr
;
10712 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
10714 /* Exit early if the table is empty. */
10715 if (nr_slots
== 0 || nr_units
== 0
10716 || (version
== 2 && nr_columns
== 0))
10718 /* All must be zero. */
10719 if (nr_slots
!= 0 || nr_units
!= 0
10720 || (version
== 2 && nr_columns
!= 0))
10722 complaint (&symfile_complaints
,
10723 _("Empty DWP but nr_slots,nr_units,nr_columns not"
10724 " all zero [in modules %s]"),
10732 htab
->section_pool
.v1
.indices
=
10733 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
10734 /* It's harder to decide whether the section is too small in v1.
10735 V1 is deprecated anyway so we punt. */
10739 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
10740 int *ids
= htab
->section_pool
.v2
.section_ids
;
10741 /* Reverse map for error checking. */
10742 int ids_seen
[DW_SECT_MAX
+ 1];
10745 if (nr_columns
< 2)
10747 error (_("Dwarf Error: bad DWP hash table, too few columns"
10748 " in section table [in module %s]"),
10751 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
10753 error (_("Dwarf Error: bad DWP hash table, too many columns"
10754 " in section table [in module %s]"),
10757 memset (ids
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
10758 memset (ids_seen
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
10759 for (i
= 0; i
< nr_columns
; ++i
)
10761 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
10763 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
10765 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
10766 " in section table [in module %s]"),
10767 id
, dwp_file
->name
);
10769 if (ids_seen
[id
] != -1)
10771 error (_("Dwarf Error: bad DWP hash table, duplicate section"
10772 " id %d in section table [in module %s]"),
10773 id
, dwp_file
->name
);
10778 /* Must have exactly one info or types section. */
10779 if (((ids_seen
[DW_SECT_INFO
] != -1)
10780 + (ids_seen
[DW_SECT_TYPES
] != -1))
10783 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
10784 " DWO info/types section [in module %s]"),
10787 /* Must have an abbrev section. */
10788 if (ids_seen
[DW_SECT_ABBREV
] == -1)
10790 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
10791 " section [in module %s]"),
10794 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
10795 htab
->section_pool
.v2
.sizes
=
10796 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
10797 * nr_units
* nr_columns
);
10798 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
10799 * nr_units
* nr_columns
))
10802 error (_("Dwarf Error: DWP index section is corrupt (too small)"
10803 " [in module %s]"),
10811 /* Update SECTIONS with the data from SECTP.
10813 This function is like the other "locate" section routines that are
10814 passed to bfd_map_over_sections, but in this context the sections to
10815 read comes from the DWP V1 hash table, not the full ELF section table.
10817 The result is non-zero for success, or zero if an error was found. */
10820 locate_v1_virtual_dwo_sections (asection
*sectp
,
10821 struct virtual_v1_dwo_sections
*sections
)
10823 const struct dwop_section_names
*names
= &dwop_section_names
;
10825 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
10827 /* There can be only one. */
10828 if (sections
->abbrev
.s
.section
!= NULL
)
10830 sections
->abbrev
.s
.section
= sectp
;
10831 sections
->abbrev
.size
= bfd_get_section_size (sectp
);
10833 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
10834 || section_is_p (sectp
->name
, &names
->types_dwo
))
10836 /* There can be only one. */
10837 if (sections
->info_or_types
.s
.section
!= NULL
)
10839 sections
->info_or_types
.s
.section
= sectp
;
10840 sections
->info_or_types
.size
= bfd_get_section_size (sectp
);
10842 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
10844 /* There can be only one. */
10845 if (sections
->line
.s
.section
!= NULL
)
10847 sections
->line
.s
.section
= sectp
;
10848 sections
->line
.size
= bfd_get_section_size (sectp
);
10850 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
10852 /* There can be only one. */
10853 if (sections
->loc
.s
.section
!= NULL
)
10855 sections
->loc
.s
.section
= sectp
;
10856 sections
->loc
.size
= bfd_get_section_size (sectp
);
10858 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
10860 /* There can be only one. */
10861 if (sections
->macinfo
.s
.section
!= NULL
)
10863 sections
->macinfo
.s
.section
= sectp
;
10864 sections
->macinfo
.size
= bfd_get_section_size (sectp
);
10866 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
10868 /* There can be only one. */
10869 if (sections
->macro
.s
.section
!= NULL
)
10871 sections
->macro
.s
.section
= sectp
;
10872 sections
->macro
.size
= bfd_get_section_size (sectp
);
10874 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
10876 /* There can be only one. */
10877 if (sections
->str_offsets
.s
.section
!= NULL
)
10879 sections
->str_offsets
.s
.section
= sectp
;
10880 sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
10884 /* No other kind of section is valid. */
10891 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
10892 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
10893 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
10894 This is for DWP version 1 files. */
10896 static struct dwo_unit
*
10897 create_dwo_unit_in_dwp_v1 (struct dwp_file
*dwp_file
,
10898 uint32_t unit_index
,
10899 const char *comp_dir
,
10900 ULONGEST signature
, int is_debug_types
)
10902 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10903 const struct dwp_hash_table
*dwp_htab
=
10904 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
10905 bfd
*dbfd
= dwp_file
->dbfd
;
10906 const char *kind
= is_debug_types
? "TU" : "CU";
10907 struct dwo_file
*dwo_file
;
10908 struct dwo_unit
*dwo_unit
;
10909 struct virtual_v1_dwo_sections sections
;
10910 void **dwo_file_slot
;
10913 gdb_assert (dwp_file
->version
== 1);
10915 if (dwarf_read_debug
)
10917 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
10919 pulongest (unit_index
), hex_string (signature
),
10923 /* Fetch the sections of this DWO unit.
10924 Put a limit on the number of sections we look for so that bad data
10925 doesn't cause us to loop forever. */
10927 #define MAX_NR_V1_DWO_SECTIONS \
10928 (1 /* .debug_info or .debug_types */ \
10929 + 1 /* .debug_abbrev */ \
10930 + 1 /* .debug_line */ \
10931 + 1 /* .debug_loc */ \
10932 + 1 /* .debug_str_offsets */ \
10933 + 1 /* .debug_macro or .debug_macinfo */ \
10934 + 1 /* trailing zero */)
10936 memset (§ions
, 0, sizeof (sections
));
10938 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
10941 uint32_t section_nr
=
10942 read_4_bytes (dbfd
,
10943 dwp_htab
->section_pool
.v1
.indices
10944 + (unit_index
+ i
) * sizeof (uint32_t));
10946 if (section_nr
== 0)
10948 if (section_nr
>= dwp_file
->num_sections
)
10950 error (_("Dwarf Error: bad DWP hash table, section number too large"
10951 " [in module %s]"),
10955 sectp
= dwp_file
->elf_sections
[section_nr
];
10956 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
10958 error (_("Dwarf Error: bad DWP hash table, invalid section found"
10959 " [in module %s]"),
10965 || dwarf2_section_empty_p (§ions
.info_or_types
)
10966 || dwarf2_section_empty_p (§ions
.abbrev
))
10968 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
10969 " [in module %s]"),
10972 if (i
== MAX_NR_V1_DWO_SECTIONS
)
10974 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
10975 " [in module %s]"),
10979 /* It's easier for the rest of the code if we fake a struct dwo_file and
10980 have dwo_unit "live" in that. At least for now.
10982 The DWP file can be made up of a random collection of CUs and TUs.
10983 However, for each CU + set of TUs that came from the same original DWO
10984 file, we can combine them back into a virtual DWO file to save space
10985 (fewer struct dwo_file objects to allocate). Remember that for really
10986 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
10988 std::string virtual_dwo_name
=
10989 string_printf ("virtual-dwo/%d-%d-%d-%d",
10990 get_section_id (§ions
.abbrev
),
10991 get_section_id (§ions
.line
),
10992 get_section_id (§ions
.loc
),
10993 get_section_id (§ions
.str_offsets
));
10994 /* Can we use an existing virtual DWO file? */
10995 dwo_file_slot
= lookup_dwo_file_slot (virtual_dwo_name
.c_str (), comp_dir
);
10996 /* Create one if necessary. */
10997 if (*dwo_file_slot
== NULL
)
10999 if (dwarf_read_debug
)
11001 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11002 virtual_dwo_name
.c_str ());
11004 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
11006 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
11007 virtual_dwo_name
.c_str (),
11008 virtual_dwo_name
.size ());
11009 dwo_file
->comp_dir
= comp_dir
;
11010 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11011 dwo_file
->sections
.line
= sections
.line
;
11012 dwo_file
->sections
.loc
= sections
.loc
;
11013 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11014 dwo_file
->sections
.macro
= sections
.macro
;
11015 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11016 /* The "str" section is global to the entire DWP file. */
11017 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11018 /* The info or types section is assigned below to dwo_unit,
11019 there's no need to record it in dwo_file.
11020 Also, we can't simply record type sections in dwo_file because
11021 we record a pointer into the vector in dwo_unit. As we collect more
11022 types we'll grow the vector and eventually have to reallocate space
11023 for it, invalidating all copies of pointers into the previous
11025 *dwo_file_slot
= dwo_file
;
11029 if (dwarf_read_debug
)
11031 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11032 virtual_dwo_name
.c_str ());
11034 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11037 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11038 dwo_unit
->dwo_file
= dwo_file
;
11039 dwo_unit
->signature
= signature
;
11040 dwo_unit
->section
=
11041 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11042 *dwo_unit
->section
= sections
.info_or_types
;
11043 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11048 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
11049 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
11050 piece within that section used by a TU/CU, return a virtual section
11051 of just that piece. */
11053 static struct dwarf2_section_info
11054 create_dwp_v2_section (struct dwarf2_section_info
*section
,
11055 bfd_size_type offset
, bfd_size_type size
)
11057 struct dwarf2_section_info result
;
11060 gdb_assert (section
!= NULL
);
11061 gdb_assert (!section
->is_virtual
);
11063 memset (&result
, 0, sizeof (result
));
11064 result
.s
.containing_section
= section
;
11065 result
.is_virtual
= 1;
11070 sectp
= get_section_bfd_section (section
);
11072 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11073 bounds of the real section. This is a pretty-rare event, so just
11074 flag an error (easier) instead of a warning and trying to cope. */
11076 || offset
+ size
> bfd_get_section_size (sectp
))
11078 bfd
*abfd
= sectp
->owner
;
11080 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
11081 " in section %s [in module %s]"),
11082 sectp
? bfd_section_name (abfd
, sectp
) : "<unknown>",
11083 objfile_name (dwarf2_per_objfile
->objfile
));
11086 result
.virtual_offset
= offset
;
11087 result
.size
= size
;
11091 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11092 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11093 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11094 This is for DWP version 2 files. */
11096 static struct dwo_unit
*
11097 create_dwo_unit_in_dwp_v2 (struct dwp_file
*dwp_file
,
11098 uint32_t unit_index
,
11099 const char *comp_dir
,
11100 ULONGEST signature
, int is_debug_types
)
11102 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11103 const struct dwp_hash_table
*dwp_htab
=
11104 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11105 bfd
*dbfd
= dwp_file
->dbfd
;
11106 const char *kind
= is_debug_types
? "TU" : "CU";
11107 struct dwo_file
*dwo_file
;
11108 struct dwo_unit
*dwo_unit
;
11109 struct virtual_v2_dwo_sections sections
;
11110 void **dwo_file_slot
;
11113 gdb_assert (dwp_file
->version
== 2);
11115 if (dwarf_read_debug
)
11117 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
11119 pulongest (unit_index
), hex_string (signature
),
11123 /* Fetch the section offsets of this DWO unit. */
11125 memset (§ions
, 0, sizeof (sections
));
11127 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11129 uint32_t offset
= read_4_bytes (dbfd
,
11130 dwp_htab
->section_pool
.v2
.offsets
11131 + (((unit_index
- 1) * dwp_htab
->nr_columns
11133 * sizeof (uint32_t)));
11134 uint32_t size
= read_4_bytes (dbfd
,
11135 dwp_htab
->section_pool
.v2
.sizes
11136 + (((unit_index
- 1) * dwp_htab
->nr_columns
11138 * sizeof (uint32_t)));
11140 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11143 case DW_SECT_TYPES
:
11144 sections
.info_or_types_offset
= offset
;
11145 sections
.info_or_types_size
= size
;
11147 case DW_SECT_ABBREV
:
11148 sections
.abbrev_offset
= offset
;
11149 sections
.abbrev_size
= size
;
11152 sections
.line_offset
= offset
;
11153 sections
.line_size
= size
;
11156 sections
.loc_offset
= offset
;
11157 sections
.loc_size
= size
;
11159 case DW_SECT_STR_OFFSETS
:
11160 sections
.str_offsets_offset
= offset
;
11161 sections
.str_offsets_size
= size
;
11163 case DW_SECT_MACINFO
:
11164 sections
.macinfo_offset
= offset
;
11165 sections
.macinfo_size
= size
;
11167 case DW_SECT_MACRO
:
11168 sections
.macro_offset
= offset
;
11169 sections
.macro_size
= size
;
11174 /* It's easier for the rest of the code if we fake a struct dwo_file and
11175 have dwo_unit "live" in that. At least for now.
11177 The DWP file can be made up of a random collection of CUs and TUs.
11178 However, for each CU + set of TUs that came from the same original DWO
11179 file, we can combine them back into a virtual DWO file to save space
11180 (fewer struct dwo_file objects to allocate). Remember that for really
11181 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11183 std::string virtual_dwo_name
=
11184 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
11185 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11186 (long) (sections
.line_size
? sections
.line_offset
: 0),
11187 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
11188 (long) (sections
.str_offsets_size
11189 ? sections
.str_offsets_offset
: 0));
11190 /* Can we use an existing virtual DWO file? */
11191 dwo_file_slot
= lookup_dwo_file_slot (virtual_dwo_name
.c_str (), comp_dir
);
11192 /* Create one if necessary. */
11193 if (*dwo_file_slot
== NULL
)
11195 if (dwarf_read_debug
)
11197 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11198 virtual_dwo_name
.c_str ());
11200 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
11202 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
11203 virtual_dwo_name
.c_str (),
11204 virtual_dwo_name
.size ());
11205 dwo_file
->comp_dir
= comp_dir
;
11206 dwo_file
->sections
.abbrev
=
11207 create_dwp_v2_section (&dwp_file
->sections
.abbrev
,
11208 sections
.abbrev_offset
, sections
.abbrev_size
);
11209 dwo_file
->sections
.line
=
11210 create_dwp_v2_section (&dwp_file
->sections
.line
,
11211 sections
.line_offset
, sections
.line_size
);
11212 dwo_file
->sections
.loc
=
11213 create_dwp_v2_section (&dwp_file
->sections
.loc
,
11214 sections
.loc_offset
, sections
.loc_size
);
11215 dwo_file
->sections
.macinfo
=
11216 create_dwp_v2_section (&dwp_file
->sections
.macinfo
,
11217 sections
.macinfo_offset
, sections
.macinfo_size
);
11218 dwo_file
->sections
.macro
=
11219 create_dwp_v2_section (&dwp_file
->sections
.macro
,
11220 sections
.macro_offset
, sections
.macro_size
);
11221 dwo_file
->sections
.str_offsets
=
11222 create_dwp_v2_section (&dwp_file
->sections
.str_offsets
,
11223 sections
.str_offsets_offset
,
11224 sections
.str_offsets_size
);
11225 /* The "str" section is global to the entire DWP file. */
11226 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11227 /* The info or types section is assigned below to dwo_unit,
11228 there's no need to record it in dwo_file.
11229 Also, we can't simply record type sections in dwo_file because
11230 we record a pointer into the vector in dwo_unit. As we collect more
11231 types we'll grow the vector and eventually have to reallocate space
11232 for it, invalidating all copies of pointers into the previous
11234 *dwo_file_slot
= dwo_file
;
11238 if (dwarf_read_debug
)
11240 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11241 virtual_dwo_name
.c_str ());
11243 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11246 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11247 dwo_unit
->dwo_file
= dwo_file
;
11248 dwo_unit
->signature
= signature
;
11249 dwo_unit
->section
=
11250 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11251 *dwo_unit
->section
= create_dwp_v2_section (is_debug_types
11252 ? &dwp_file
->sections
.types
11253 : &dwp_file
->sections
.info
,
11254 sections
.info_or_types_offset
,
11255 sections
.info_or_types_size
);
11256 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11261 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
11262 Returns NULL if the signature isn't found. */
11264 static struct dwo_unit
*
11265 lookup_dwo_unit_in_dwp (struct dwp_file
*dwp_file
, const char *comp_dir
,
11266 ULONGEST signature
, int is_debug_types
)
11268 const struct dwp_hash_table
*dwp_htab
=
11269 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11270 bfd
*dbfd
= dwp_file
->dbfd
;
11271 uint32_t mask
= dwp_htab
->nr_slots
- 1;
11272 uint32_t hash
= signature
& mask
;
11273 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
11276 struct dwo_unit find_dwo_cu
;
11278 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
11279 find_dwo_cu
.signature
= signature
;
11280 slot
= htab_find_slot (is_debug_types
11281 ? dwp_file
->loaded_tus
11282 : dwp_file
->loaded_cus
,
11283 &find_dwo_cu
, INSERT
);
11286 return (struct dwo_unit
*) *slot
;
11288 /* Use a for loop so that we don't loop forever on bad debug info. */
11289 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
11291 ULONGEST signature_in_table
;
11293 signature_in_table
=
11294 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
11295 if (signature_in_table
== signature
)
11297 uint32_t unit_index
=
11298 read_4_bytes (dbfd
,
11299 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
11301 if (dwp_file
->version
== 1)
11303 *slot
= create_dwo_unit_in_dwp_v1 (dwp_file
, unit_index
,
11304 comp_dir
, signature
,
11309 *slot
= create_dwo_unit_in_dwp_v2 (dwp_file
, unit_index
,
11310 comp_dir
, signature
,
11313 return (struct dwo_unit
*) *slot
;
11315 if (signature_in_table
== 0)
11317 hash
= (hash
+ hash2
) & mask
;
11320 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
11321 " [in module %s]"),
11325 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
11326 Open the file specified by FILE_NAME and hand it off to BFD for
11327 preliminary analysis. Return a newly initialized bfd *, which
11328 includes a canonicalized copy of FILE_NAME.
11329 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
11330 SEARCH_CWD is true if the current directory is to be searched.
11331 It will be searched before debug-file-directory.
11332 If successful, the file is added to the bfd include table of the
11333 objfile's bfd (see gdb_bfd_record_inclusion).
11334 If unable to find/open the file, return NULL.
11335 NOTE: This function is derived from symfile_bfd_open. */
11337 static gdb_bfd_ref_ptr
11338 try_open_dwop_file (const char *file_name
, int is_dwp
, int search_cwd
)
11341 char *absolute_name
;
11342 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
11343 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
11344 to debug_file_directory. */
11346 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
11350 if (*debug_file_directory
!= '\0')
11351 search_path
= concat (".", dirname_separator_string
,
11352 debug_file_directory
, (char *) NULL
);
11354 search_path
= xstrdup (".");
11357 search_path
= xstrdup (debug_file_directory
);
11359 flags
= OPF_RETURN_REALPATH
;
11361 flags
|= OPF_SEARCH_IN_PATH
;
11362 desc
= openp (search_path
, flags
, file_name
,
11363 O_RDONLY
| O_BINARY
, &absolute_name
);
11364 xfree (search_path
);
11368 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
, gnutarget
, desc
));
11369 xfree (absolute_name
);
11370 if (sym_bfd
== NULL
)
11372 bfd_set_cacheable (sym_bfd
.get (), 1);
11374 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
11377 /* Success. Record the bfd as having been included by the objfile's bfd.
11378 This is important because things like demangled_names_hash lives in the
11379 objfile's per_bfd space and may have references to things like symbol
11380 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
11381 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
11386 /* Try to open DWO file FILE_NAME.
11387 COMP_DIR is the DW_AT_comp_dir attribute.
11388 The result is the bfd handle of the file.
11389 If there is a problem finding or opening the file, return NULL.
11390 Upon success, the canonicalized path of the file is stored in the bfd,
11391 same as symfile_bfd_open. */
11393 static gdb_bfd_ref_ptr
11394 open_dwo_file (const char *file_name
, const char *comp_dir
)
11396 if (IS_ABSOLUTE_PATH (file_name
))
11397 return try_open_dwop_file (file_name
, 0 /*is_dwp*/, 0 /*search_cwd*/);
11399 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
11401 if (comp_dir
!= NULL
)
11403 char *path_to_try
= concat (comp_dir
, SLASH_STRING
,
11404 file_name
, (char *) NULL
);
11406 /* NOTE: If comp_dir is a relative path, this will also try the
11407 search path, which seems useful. */
11408 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (path_to_try
, 0 /*is_dwp*/,
11409 1 /*search_cwd*/));
11410 xfree (path_to_try
);
11415 /* That didn't work, try debug-file-directory, which, despite its name,
11416 is a list of paths. */
11418 if (*debug_file_directory
== '\0')
11421 return try_open_dwop_file (file_name
, 0 /*is_dwp*/, 1 /*search_cwd*/);
11424 /* This function is mapped across the sections and remembers the offset and
11425 size of each of the DWO debugging sections we are interested in. */
11428 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
11430 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
11431 const struct dwop_section_names
*names
= &dwop_section_names
;
11433 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11435 dwo_sections
->abbrev
.s
.section
= sectp
;
11436 dwo_sections
->abbrev
.size
= bfd_get_section_size (sectp
);
11438 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
11440 dwo_sections
->info
.s
.section
= sectp
;
11441 dwo_sections
->info
.size
= bfd_get_section_size (sectp
);
11443 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11445 dwo_sections
->line
.s
.section
= sectp
;
11446 dwo_sections
->line
.size
= bfd_get_section_size (sectp
);
11448 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11450 dwo_sections
->loc
.s
.section
= sectp
;
11451 dwo_sections
->loc
.size
= bfd_get_section_size (sectp
);
11453 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11455 dwo_sections
->macinfo
.s
.section
= sectp
;
11456 dwo_sections
->macinfo
.size
= bfd_get_section_size (sectp
);
11458 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11460 dwo_sections
->macro
.s
.section
= sectp
;
11461 dwo_sections
->macro
.size
= bfd_get_section_size (sectp
);
11463 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
11465 dwo_sections
->str
.s
.section
= sectp
;
11466 dwo_sections
->str
.size
= bfd_get_section_size (sectp
);
11468 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11470 dwo_sections
->str_offsets
.s
.section
= sectp
;
11471 dwo_sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
11473 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
11475 struct dwarf2_section_info type_section
;
11477 memset (&type_section
, 0, sizeof (type_section
));
11478 type_section
.s
.section
= sectp
;
11479 type_section
.size
= bfd_get_section_size (sectp
);
11480 VEC_safe_push (dwarf2_section_info_def
, dwo_sections
->types
,
11485 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
11486 by PER_CU. This is for the non-DWP case.
11487 The result is NULL if DWO_NAME can't be found. */
11489 static struct dwo_file
*
11490 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
11491 const char *dwo_name
, const char *comp_dir
)
11493 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11494 struct dwo_file
*dwo_file
;
11495 struct cleanup
*cleanups
;
11497 gdb_bfd_ref_ptr
dbfd (open_dwo_file (dwo_name
, comp_dir
));
11500 if (dwarf_read_debug
)
11501 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
11504 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
11505 dwo_file
->dwo_name
= dwo_name
;
11506 dwo_file
->comp_dir
= comp_dir
;
11507 dwo_file
->dbfd
= dbfd
.release ();
11509 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwo_file
);
11511 bfd_map_over_sections (dwo_file
->dbfd
, dwarf2_locate_dwo_sections
,
11512 &dwo_file
->sections
);
11514 create_cus_hash_table (*dwo_file
, dwo_file
->sections
.info
, dwo_file
->cus
);
11516 create_debug_types_hash_table (dwo_file
, dwo_file
->sections
.types
,
11519 discard_cleanups (cleanups
);
11521 if (dwarf_read_debug
)
11522 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
11527 /* This function is mapped across the sections and remembers the offset and
11528 size of each of the DWP debugging sections common to version 1 and 2 that
11529 we are interested in. */
11532 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
11533 void *dwp_file_ptr
)
11535 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
11536 const struct dwop_section_names
*names
= &dwop_section_names
;
11537 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
11539 /* Record the ELF section number for later lookup: this is what the
11540 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
11541 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
11542 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
11544 /* Look for specific sections that we need. */
11545 if (section_is_p (sectp
->name
, &names
->str_dwo
))
11547 dwp_file
->sections
.str
.s
.section
= sectp
;
11548 dwp_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
11550 else if (section_is_p (sectp
->name
, &names
->cu_index
))
11552 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
11553 dwp_file
->sections
.cu_index
.size
= bfd_get_section_size (sectp
);
11555 else if (section_is_p (sectp
->name
, &names
->tu_index
))
11557 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
11558 dwp_file
->sections
.tu_index
.size
= bfd_get_section_size (sectp
);
11562 /* This function is mapped across the sections and remembers the offset and
11563 size of each of the DWP version 2 debugging sections that we are interested
11564 in. This is split into a separate function because we don't know if we
11565 have version 1 or 2 until we parse the cu_index/tu_index sections. */
11568 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
11570 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
11571 const struct dwop_section_names
*names
= &dwop_section_names
;
11572 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
11574 /* Record the ELF section number for later lookup: this is what the
11575 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
11576 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
11577 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
11579 /* Look for specific sections that we need. */
11580 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11582 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
11583 dwp_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
11585 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
11587 dwp_file
->sections
.info
.s
.section
= sectp
;
11588 dwp_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
11590 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11592 dwp_file
->sections
.line
.s
.section
= sectp
;
11593 dwp_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
11595 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11597 dwp_file
->sections
.loc
.s
.section
= sectp
;
11598 dwp_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
11600 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11602 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
11603 dwp_file
->sections
.macinfo
.size
= bfd_get_section_size (sectp
);
11605 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11607 dwp_file
->sections
.macro
.s
.section
= sectp
;
11608 dwp_file
->sections
.macro
.size
= bfd_get_section_size (sectp
);
11610 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11612 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
11613 dwp_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
11615 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
11617 dwp_file
->sections
.types
.s
.section
= sectp
;
11618 dwp_file
->sections
.types
.size
= bfd_get_section_size (sectp
);
11622 /* Hash function for dwp_file loaded CUs/TUs. */
11625 hash_dwp_loaded_cutus (const void *item
)
11627 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11629 /* This drops the top 32 bits of the signature, but is ok for a hash. */
11630 return dwo_unit
->signature
;
11633 /* Equality function for dwp_file loaded CUs/TUs. */
11636 eq_dwp_loaded_cutus (const void *a
, const void *b
)
11638 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
11639 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
11641 return dua
->signature
== dub
->signature
;
11644 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
11647 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
11649 return htab_create_alloc_ex (3,
11650 hash_dwp_loaded_cutus
,
11651 eq_dwp_loaded_cutus
,
11653 &objfile
->objfile_obstack
,
11654 hashtab_obstack_allocate
,
11655 dummy_obstack_deallocate
);
11658 /* Try to open DWP file FILE_NAME.
11659 The result is the bfd handle of the file.
11660 If there is a problem finding or opening the file, return NULL.
11661 Upon success, the canonicalized path of the file is stored in the bfd,
11662 same as symfile_bfd_open. */
11664 static gdb_bfd_ref_ptr
11665 open_dwp_file (const char *file_name
)
11667 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (file_name
, 1 /*is_dwp*/,
11668 1 /*search_cwd*/));
11672 /* Work around upstream bug 15652.
11673 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
11674 [Whether that's a "bug" is debatable, but it is getting in our way.]
11675 We have no real idea where the dwp file is, because gdb's realpath-ing
11676 of the executable's path may have discarded the needed info.
11677 [IWBN if the dwp file name was recorded in the executable, akin to
11678 .gnu_debuglink, but that doesn't exist yet.]
11679 Strip the directory from FILE_NAME and search again. */
11680 if (*debug_file_directory
!= '\0')
11682 /* Don't implicitly search the current directory here.
11683 If the user wants to search "." to handle this case,
11684 it must be added to debug-file-directory. */
11685 return try_open_dwop_file (lbasename (file_name
), 1 /*is_dwp*/,
11692 /* Initialize the use of the DWP file for the current objfile.
11693 By convention the name of the DWP file is ${objfile}.dwp.
11694 The result is NULL if it can't be found. */
11696 static struct dwp_file
*
11697 open_and_init_dwp_file (void)
11699 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11700 struct dwp_file
*dwp_file
;
11702 /* Try to find first .dwp for the binary file before any symbolic links
11705 /* If the objfile is a debug file, find the name of the real binary
11706 file and get the name of dwp file from there. */
11707 std::string dwp_name
;
11708 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
11710 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
11711 const char *backlink_basename
= lbasename (backlink
->original_name
);
11713 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
11716 dwp_name
= objfile
->original_name
;
11718 dwp_name
+= ".dwp";
11720 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwp_name
.c_str ()));
11722 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
11724 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
11725 dwp_name
= objfile_name (objfile
);
11726 dwp_name
+= ".dwp";
11727 dbfd
= open_dwp_file (dwp_name
.c_str ());
11732 if (dwarf_read_debug
)
11733 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
11736 dwp_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_file
);
11737 dwp_file
->name
= bfd_get_filename (dbfd
.get ());
11738 dwp_file
->dbfd
= dbfd
.release ();
11740 /* +1: section 0 is unused */
11741 dwp_file
->num_sections
= bfd_count_sections (dwp_file
->dbfd
) + 1;
11742 dwp_file
->elf_sections
=
11743 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
11744 dwp_file
->num_sections
, asection
*);
11746 bfd_map_over_sections (dwp_file
->dbfd
, dwarf2_locate_common_dwp_sections
,
11749 dwp_file
->cus
= create_dwp_hash_table (dwp_file
, 0);
11751 dwp_file
->tus
= create_dwp_hash_table (dwp_file
, 1);
11753 /* The DWP file version is stored in the hash table. Oh well. */
11754 if (dwp_file
->cus
&& dwp_file
->tus
11755 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
11757 /* Technically speaking, we should try to limp along, but this is
11758 pretty bizarre. We use pulongest here because that's the established
11759 portability solution (e.g, we cannot use %u for uint32_t). */
11760 error (_("Dwarf Error: DWP file CU version %s doesn't match"
11761 " TU version %s [in DWP file %s]"),
11762 pulongest (dwp_file
->cus
->version
),
11763 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
11767 dwp_file
->version
= dwp_file
->cus
->version
;
11768 else if (dwp_file
->tus
)
11769 dwp_file
->version
= dwp_file
->tus
->version
;
11771 dwp_file
->version
= 2;
11773 if (dwp_file
->version
== 2)
11774 bfd_map_over_sections (dwp_file
->dbfd
, dwarf2_locate_v2_dwp_sections
,
11777 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
11778 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
11780 if (dwarf_read_debug
)
11782 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
11783 fprintf_unfiltered (gdb_stdlog
,
11784 " %s CUs, %s TUs\n",
11785 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
11786 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
11792 /* Wrapper around open_and_init_dwp_file, only open it once. */
11794 static struct dwp_file
*
11795 get_dwp_file (void)
11797 if (! dwarf2_per_objfile
->dwp_checked
)
11799 dwarf2_per_objfile
->dwp_file
= open_and_init_dwp_file ();
11800 dwarf2_per_objfile
->dwp_checked
= 1;
11802 return dwarf2_per_objfile
->dwp_file
;
11805 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
11806 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
11807 or in the DWP file for the objfile, referenced by THIS_UNIT.
11808 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
11809 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
11811 This is called, for example, when wanting to read a variable with a
11812 complex location. Therefore we don't want to do file i/o for every call.
11813 Therefore we don't want to look for a DWO file on every call.
11814 Therefore we first see if we've already seen SIGNATURE in a DWP file,
11815 then we check if we've already seen DWO_NAME, and only THEN do we check
11818 The result is a pointer to the dwo_unit object or NULL if we didn't find it
11819 (dwo_id mismatch or couldn't find the DWO/DWP file). */
11821 static struct dwo_unit
*
11822 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
11823 const char *dwo_name
, const char *comp_dir
,
11824 ULONGEST signature
, int is_debug_types
)
11826 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11827 const char *kind
= is_debug_types
? "TU" : "CU";
11828 void **dwo_file_slot
;
11829 struct dwo_file
*dwo_file
;
11830 struct dwp_file
*dwp_file
;
11832 /* First see if there's a DWP file.
11833 If we have a DWP file but didn't find the DWO inside it, don't
11834 look for the original DWO file. It makes gdb behave differently
11835 depending on whether one is debugging in the build tree. */
11837 dwp_file
= get_dwp_file ();
11838 if (dwp_file
!= NULL
)
11840 const struct dwp_hash_table
*dwp_htab
=
11841 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11843 if (dwp_htab
!= NULL
)
11845 struct dwo_unit
*dwo_cutu
=
11846 lookup_dwo_unit_in_dwp (dwp_file
, comp_dir
,
11847 signature
, is_debug_types
);
11849 if (dwo_cutu
!= NULL
)
11851 if (dwarf_read_debug
)
11853 fprintf_unfiltered (gdb_stdlog
,
11854 "Virtual DWO %s %s found: @%s\n",
11855 kind
, hex_string (signature
),
11856 host_address_to_string (dwo_cutu
));
11864 /* No DWP file, look for the DWO file. */
11866 dwo_file_slot
= lookup_dwo_file_slot (dwo_name
, comp_dir
);
11867 if (*dwo_file_slot
== NULL
)
11869 /* Read in the file and build a table of the CUs/TUs it contains. */
11870 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
11872 /* NOTE: This will be NULL if unable to open the file. */
11873 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11875 if (dwo_file
!= NULL
)
11877 struct dwo_unit
*dwo_cutu
= NULL
;
11879 if (is_debug_types
&& dwo_file
->tus
)
11881 struct dwo_unit find_dwo_cutu
;
11883 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
11884 find_dwo_cutu
.signature
= signature
;
11886 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
11888 else if (!is_debug_types
&& dwo_file
->cus
)
11890 struct dwo_unit find_dwo_cutu
;
11892 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
11893 find_dwo_cutu
.signature
= signature
;
11894 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
,
11898 if (dwo_cutu
!= NULL
)
11900 if (dwarf_read_debug
)
11902 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
11903 kind
, dwo_name
, hex_string (signature
),
11904 host_address_to_string (dwo_cutu
));
11911 /* We didn't find it. This could mean a dwo_id mismatch, or
11912 someone deleted the DWO/DWP file, or the search path isn't set up
11913 correctly to find the file. */
11915 if (dwarf_read_debug
)
11917 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
11918 kind
, dwo_name
, hex_string (signature
));
11921 /* This is a warning and not a complaint because it can be caused by
11922 pilot error (e.g., user accidentally deleting the DWO). */
11924 /* Print the name of the DWP file if we looked there, helps the user
11925 better diagnose the problem. */
11926 std::string dwp_text
;
11928 if (dwp_file
!= NULL
)
11929 dwp_text
= string_printf (" [in DWP file %s]",
11930 lbasename (dwp_file
->name
));
11932 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset 0x%x"
11933 " [in module %s]"),
11934 kind
, dwo_name
, hex_string (signature
),
11936 this_unit
->is_debug_types
? "TU" : "CU",
11937 to_underlying (this_unit
->sect_off
), objfile_name (objfile
));
11942 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
11943 See lookup_dwo_cutu_unit for details. */
11945 static struct dwo_unit
*
11946 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
11947 const char *dwo_name
, const char *comp_dir
,
11948 ULONGEST signature
)
11950 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
11953 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
11954 See lookup_dwo_cutu_unit for details. */
11956 static struct dwo_unit
*
11957 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
11958 const char *dwo_name
, const char *comp_dir
)
11960 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
11963 /* Traversal function for queue_and_load_all_dwo_tus. */
11966 queue_and_load_dwo_tu (void **slot
, void *info
)
11968 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
11969 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
11970 ULONGEST signature
= dwo_unit
->signature
;
11971 struct signatured_type
*sig_type
=
11972 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
11974 if (sig_type
!= NULL
)
11976 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
11978 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
11979 a real dependency of PER_CU on SIG_TYPE. That is detected later
11980 while processing PER_CU. */
11981 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
11982 load_full_type_unit (sig_cu
);
11983 VEC_safe_push (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, sig_cu
);
11989 /* Queue all TUs contained in the DWO of PER_CU to be read in.
11990 The DWO may have the only definition of the type, though it may not be
11991 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
11992 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
11995 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
11997 struct dwo_unit
*dwo_unit
;
11998 struct dwo_file
*dwo_file
;
12000 gdb_assert (!per_cu
->is_debug_types
);
12001 gdb_assert (get_dwp_file () == NULL
);
12002 gdb_assert (per_cu
->cu
!= NULL
);
12004 dwo_unit
= per_cu
->cu
->dwo_unit
;
12005 gdb_assert (dwo_unit
!= NULL
);
12007 dwo_file
= dwo_unit
->dwo_file
;
12008 if (dwo_file
->tus
!= NULL
)
12009 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
12012 /* Free all resources associated with DWO_FILE.
12013 Close the DWO file and munmap the sections.
12014 All memory should be on the objfile obstack. */
12017 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
12020 /* Note: dbfd is NULL for virtual DWO files. */
12021 gdb_bfd_unref (dwo_file
->dbfd
);
12023 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
12026 /* Wrapper for free_dwo_file for use in cleanups. */
12029 free_dwo_file_cleanup (void *arg
)
12031 struct dwo_file
*dwo_file
= (struct dwo_file
*) arg
;
12032 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12034 free_dwo_file (dwo_file
, objfile
);
12037 /* Traversal function for free_dwo_files. */
12040 free_dwo_file_from_slot (void **slot
, void *info
)
12042 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
12043 struct objfile
*objfile
= (struct objfile
*) info
;
12045 free_dwo_file (dwo_file
, objfile
);
12050 /* Free all resources associated with DWO_FILES. */
12053 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
12055 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
12058 /* Read in various DIEs. */
12060 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12061 Inherit only the children of the DW_AT_abstract_origin DIE not being
12062 already referenced by DW_AT_abstract_origin from the children of the
12066 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12068 struct die_info
*child_die
;
12069 sect_offset
*offsetp
;
12070 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12071 struct die_info
*origin_die
;
12072 /* Iterator of the ORIGIN_DIE children. */
12073 struct die_info
*origin_child_die
;
12074 struct attribute
*attr
;
12075 struct dwarf2_cu
*origin_cu
;
12076 struct pending
**origin_previous_list_in_scope
;
12078 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12082 /* Note that following die references may follow to a die in a
12086 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12088 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12090 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12091 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12093 if (die
->tag
!= origin_die
->tag
12094 && !(die
->tag
== DW_TAG_inlined_subroutine
12095 && origin_die
->tag
== DW_TAG_subprogram
))
12096 complaint (&symfile_complaints
,
12097 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
12098 to_underlying (die
->sect_off
),
12099 to_underlying (origin_die
->sect_off
));
12101 std::vector
<sect_offset
> offsets
;
12103 for (child_die
= die
->child
;
12104 child_die
&& child_die
->tag
;
12105 child_die
= sibling_die (child_die
))
12107 struct die_info
*child_origin_die
;
12108 struct dwarf2_cu
*child_origin_cu
;
12110 /* We are trying to process concrete instance entries:
12111 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12112 it's not relevant to our analysis here. i.e. detecting DIEs that are
12113 present in the abstract instance but not referenced in the concrete
12115 if (child_die
->tag
== DW_TAG_call_site
12116 || child_die
->tag
== DW_TAG_GNU_call_site
)
12119 /* For each CHILD_DIE, find the corresponding child of
12120 ORIGIN_DIE. If there is more than one layer of
12121 DW_AT_abstract_origin, follow them all; there shouldn't be,
12122 but GCC versions at least through 4.4 generate this (GCC PR
12124 child_origin_die
= child_die
;
12125 child_origin_cu
= cu
;
12128 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12132 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12136 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12137 counterpart may exist. */
12138 if (child_origin_die
!= child_die
)
12140 if (child_die
->tag
!= child_origin_die
->tag
12141 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12142 && child_origin_die
->tag
== DW_TAG_subprogram
))
12143 complaint (&symfile_complaints
,
12144 _("Child DIE 0x%x and its abstract origin 0x%x have "
12146 to_underlying (child_die
->sect_off
),
12147 to_underlying (child_origin_die
->sect_off
));
12148 if (child_origin_die
->parent
!= origin_die
)
12149 complaint (&symfile_complaints
,
12150 _("Child DIE 0x%x and its abstract origin 0x%x have "
12151 "different parents"),
12152 to_underlying (child_die
->sect_off
),
12153 to_underlying (child_origin_die
->sect_off
));
12155 offsets
.push_back (child_origin_die
->sect_off
);
12158 std::sort (offsets
.begin (), offsets
.end ());
12159 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
12160 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
12161 if (offsetp
[-1] == *offsetp
)
12162 complaint (&symfile_complaints
,
12163 _("Multiple children of DIE 0x%x refer "
12164 "to DIE 0x%x as their abstract origin"),
12165 to_underlying (die
->sect_off
), to_underlying (*offsetp
));
12167 offsetp
= offsets
.data ();
12168 origin_child_die
= origin_die
->child
;
12169 while (origin_child_die
&& origin_child_die
->tag
)
12171 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
12172 while (offsetp
< offsets_end
12173 && *offsetp
< origin_child_die
->sect_off
)
12175 if (offsetp
>= offsets_end
12176 || *offsetp
> origin_child_die
->sect_off
)
12178 /* Found that ORIGIN_CHILD_DIE is really not referenced.
12179 Check whether we're already processing ORIGIN_CHILD_DIE.
12180 This can happen with mutually referenced abstract_origins.
12182 if (!origin_child_die
->in_process
)
12183 process_die (origin_child_die
, origin_cu
);
12185 origin_child_die
= sibling_die (origin_child_die
);
12187 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
12191 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12193 struct objfile
*objfile
= cu
->objfile
;
12194 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12195 struct context_stack
*newobj
;
12198 struct die_info
*child_die
;
12199 struct attribute
*attr
, *call_line
, *call_file
;
12201 CORE_ADDR baseaddr
;
12202 struct block
*block
;
12203 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
12204 std::vector
<struct symbol
*> template_args
;
12205 struct template_symbol
*templ_func
= NULL
;
12209 /* If we do not have call site information, we can't show the
12210 caller of this inlined function. That's too confusing, so
12211 only use the scope for local variables. */
12212 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
12213 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
12214 if (call_line
== NULL
|| call_file
== NULL
)
12216 read_lexical_block_scope (die
, cu
);
12221 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
12223 name
= dwarf2_name (die
, cu
);
12225 /* Ignore functions with missing or empty names. These are actually
12226 illegal according to the DWARF standard. */
12229 complaint (&symfile_complaints
,
12230 _("missing name for subprogram DIE at %d"),
12231 to_underlying (die
->sect_off
));
12235 /* Ignore functions with missing or invalid low and high pc attributes. */
12236 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
12237 <= PC_BOUNDS_INVALID
)
12239 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
12240 if (!attr
|| !DW_UNSND (attr
))
12241 complaint (&symfile_complaints
,
12242 _("cannot get low and high bounds "
12243 "for subprogram DIE at %d"),
12244 to_underlying (die
->sect_off
));
12248 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12249 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
12251 /* If we have any template arguments, then we must allocate a
12252 different sort of symbol. */
12253 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
12255 if (child_die
->tag
== DW_TAG_template_type_param
12256 || child_die
->tag
== DW_TAG_template_value_param
)
12258 templ_func
= allocate_template_symbol (objfile
);
12259 templ_func
->base
.is_cplus_template_function
= 1;
12264 newobj
= push_context (0, lowpc
);
12265 newobj
->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
12266 (struct symbol
*) templ_func
);
12268 /* If there is a location expression for DW_AT_frame_base, record
12270 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
12272 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
12274 /* If there is a location for the static link, record it. */
12275 newobj
->static_link
= NULL
;
12276 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
12279 newobj
->static_link
12280 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
12281 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
);
12284 cu
->list_in_scope
= &local_symbols
;
12286 if (die
->child
!= NULL
)
12288 child_die
= die
->child
;
12289 while (child_die
&& child_die
->tag
)
12291 if (child_die
->tag
== DW_TAG_template_type_param
12292 || child_die
->tag
== DW_TAG_template_value_param
)
12294 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
12297 template_args
.push_back (arg
);
12300 process_die (child_die
, cu
);
12301 child_die
= sibling_die (child_die
);
12305 inherit_abstract_dies (die
, cu
);
12307 /* If we have a DW_AT_specification, we might need to import using
12308 directives from the context of the specification DIE. See the
12309 comment in determine_prefix. */
12310 if (cu
->language
== language_cplus
12311 && dwarf2_attr (die
, DW_AT_specification
, cu
))
12313 struct dwarf2_cu
*spec_cu
= cu
;
12314 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
12318 child_die
= spec_die
->child
;
12319 while (child_die
&& child_die
->tag
)
12321 if (child_die
->tag
== DW_TAG_imported_module
)
12322 process_die (child_die
, spec_cu
);
12323 child_die
= sibling_die (child_die
);
12326 /* In some cases, GCC generates specification DIEs that
12327 themselves contain DW_AT_specification attributes. */
12328 spec_die
= die_specification (spec_die
, &spec_cu
);
12332 newobj
= pop_context ();
12333 /* Make a block for the local symbols within. */
12334 block
= finish_block (newobj
->name
, &local_symbols
, newobj
->old_blocks
,
12335 newobj
->static_link
, lowpc
, highpc
);
12337 /* For C++, set the block's scope. */
12338 if ((cu
->language
== language_cplus
12339 || cu
->language
== language_fortran
12340 || cu
->language
== language_d
12341 || cu
->language
== language_rust
)
12342 && cu
->processing_has_namespace_info
)
12343 block_set_scope (block
, determine_prefix (die
, cu
),
12344 &objfile
->objfile_obstack
);
12346 /* If we have address ranges, record them. */
12347 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
12349 gdbarch_make_symbol_special (gdbarch
, newobj
->name
, objfile
);
12351 /* Attach template arguments to function. */
12352 if (!template_args
.empty ())
12354 gdb_assert (templ_func
!= NULL
);
12356 templ_func
->n_template_arguments
= template_args
.size ();
12357 templ_func
->template_arguments
12358 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
12359 templ_func
->n_template_arguments
);
12360 memcpy (templ_func
->template_arguments
,
12361 template_args
.data (),
12362 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
12365 /* In C++, we can have functions nested inside functions (e.g., when
12366 a function declares a class that has methods). This means that
12367 when we finish processing a function scope, we may need to go
12368 back to building a containing block's symbol lists. */
12369 local_symbols
= newobj
->locals
;
12370 local_using_directives
= newobj
->local_using_directives
;
12372 /* If we've finished processing a top-level function, subsequent
12373 symbols go in the file symbol list. */
12374 if (outermost_context_p ())
12375 cu
->list_in_scope
= &file_symbols
;
12378 /* Process all the DIES contained within a lexical block scope. Start
12379 a new scope, process the dies, and then close the scope. */
12382 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12384 struct objfile
*objfile
= cu
->objfile
;
12385 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12386 struct context_stack
*newobj
;
12387 CORE_ADDR lowpc
, highpc
;
12388 struct die_info
*child_die
;
12389 CORE_ADDR baseaddr
;
12391 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
12393 /* Ignore blocks with missing or invalid low and high pc attributes. */
12394 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
12395 as multiple lexical blocks? Handling children in a sane way would
12396 be nasty. Might be easier to properly extend generic blocks to
12397 describe ranges. */
12398 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
12400 case PC_BOUNDS_NOT_PRESENT
:
12401 /* DW_TAG_lexical_block has no attributes, process its children as if
12402 there was no wrapping by that DW_TAG_lexical_block.
12403 GCC does no longer produces such DWARF since GCC r224161. */
12404 for (child_die
= die
->child
;
12405 child_die
!= NULL
&& child_die
->tag
;
12406 child_die
= sibling_die (child_die
))
12407 process_die (child_die
, cu
);
12409 case PC_BOUNDS_INVALID
:
12412 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12413 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
12415 push_context (0, lowpc
);
12416 if (die
->child
!= NULL
)
12418 child_die
= die
->child
;
12419 while (child_die
&& child_die
->tag
)
12421 process_die (child_die
, cu
);
12422 child_die
= sibling_die (child_die
);
12425 inherit_abstract_dies (die
, cu
);
12426 newobj
= pop_context ();
12428 if (local_symbols
!= NULL
|| local_using_directives
!= NULL
)
12430 struct block
*block
12431 = finish_block (0, &local_symbols
, newobj
->old_blocks
, NULL
,
12432 newobj
->start_addr
, highpc
);
12434 /* Note that recording ranges after traversing children, as we
12435 do here, means that recording a parent's ranges entails
12436 walking across all its children's ranges as they appear in
12437 the address map, which is quadratic behavior.
12439 It would be nicer to record the parent's ranges before
12440 traversing its children, simply overriding whatever you find
12441 there. But since we don't even decide whether to create a
12442 block until after we've traversed its children, that's hard
12444 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
12446 local_symbols
= newobj
->locals
;
12447 local_using_directives
= newobj
->local_using_directives
;
12450 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
12453 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12455 struct objfile
*objfile
= cu
->objfile
;
12456 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12457 CORE_ADDR pc
, baseaddr
;
12458 struct attribute
*attr
;
12459 struct call_site
*call_site
, call_site_local
;
12462 struct die_info
*child_die
;
12464 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
12466 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
12469 /* This was a pre-DWARF-5 GNU extension alias
12470 for DW_AT_call_return_pc. */
12471 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
12475 complaint (&symfile_complaints
,
12476 _("missing DW_AT_call_return_pc for DW_TAG_call_site "
12477 "DIE 0x%x [in module %s]"),
12478 to_underlying (die
->sect_off
), objfile_name (objfile
));
12481 pc
= attr_value_as_address (attr
) + baseaddr
;
12482 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
12484 if (cu
->call_site_htab
== NULL
)
12485 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
12486 NULL
, &objfile
->objfile_obstack
,
12487 hashtab_obstack_allocate
, NULL
);
12488 call_site_local
.pc
= pc
;
12489 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
12492 complaint (&symfile_complaints
,
12493 _("Duplicate PC %s for DW_TAG_call_site "
12494 "DIE 0x%x [in module %s]"),
12495 paddress (gdbarch
, pc
), to_underlying (die
->sect_off
),
12496 objfile_name (objfile
));
12500 /* Count parameters at the caller. */
12503 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
12504 child_die
= sibling_die (child_die
))
12506 if (child_die
->tag
!= DW_TAG_call_site_parameter
12507 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
12509 complaint (&symfile_complaints
,
12510 _("Tag %d is not DW_TAG_call_site_parameter in "
12511 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
12512 child_die
->tag
, to_underlying (child_die
->sect_off
),
12513 objfile_name (objfile
));
12521 = ((struct call_site
*)
12522 obstack_alloc (&objfile
->objfile_obstack
,
12523 sizeof (*call_site
)
12524 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
12526 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
12527 call_site
->pc
= pc
;
12529 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
12530 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
12532 struct die_info
*func_die
;
12534 /* Skip also over DW_TAG_inlined_subroutine. */
12535 for (func_die
= die
->parent
;
12536 func_die
&& func_die
->tag
!= DW_TAG_subprogram
12537 && func_die
->tag
!= DW_TAG_subroutine_type
;
12538 func_die
= func_die
->parent
);
12540 /* DW_AT_call_all_calls is a superset
12541 of DW_AT_call_all_tail_calls. */
12543 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
12544 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
12545 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
12546 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
12548 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
12549 not complete. But keep CALL_SITE for look ups via call_site_htab,
12550 both the initial caller containing the real return address PC and
12551 the final callee containing the current PC of a chain of tail
12552 calls do not need to have the tail call list complete. But any
12553 function candidate for a virtual tail call frame searched via
12554 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
12555 determined unambiguously. */
12559 struct type
*func_type
= NULL
;
12562 func_type
= get_die_type (func_die
, cu
);
12563 if (func_type
!= NULL
)
12565 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
12567 /* Enlist this call site to the function. */
12568 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
12569 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
12572 complaint (&symfile_complaints
,
12573 _("Cannot find function owning DW_TAG_call_site "
12574 "DIE 0x%x [in module %s]"),
12575 to_underlying (die
->sect_off
), objfile_name (objfile
));
12579 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
12581 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
12583 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
12586 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
12587 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12589 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
12590 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
12591 /* Keep NULL DWARF_BLOCK. */;
12592 else if (attr_form_is_block (attr
))
12594 struct dwarf2_locexpr_baton
*dlbaton
;
12596 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
12597 dlbaton
->data
= DW_BLOCK (attr
)->data
;
12598 dlbaton
->size
= DW_BLOCK (attr
)->size
;
12599 dlbaton
->per_cu
= cu
->per_cu
;
12601 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
12603 else if (attr_form_is_ref (attr
))
12605 struct dwarf2_cu
*target_cu
= cu
;
12606 struct die_info
*target_die
;
12608 target_die
= follow_die_ref (die
, attr
, &target_cu
);
12609 gdb_assert (target_cu
->objfile
== objfile
);
12610 if (die_is_declaration (target_die
, target_cu
))
12612 const char *target_physname
;
12614 /* Prefer the mangled name; otherwise compute the demangled one. */
12615 target_physname
= dw2_linkage_name (target_die
, target_cu
);
12616 if (target_physname
== NULL
)
12617 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
12618 if (target_physname
== NULL
)
12619 complaint (&symfile_complaints
,
12620 _("DW_AT_call_target target DIE has invalid "
12621 "physname, for referencing DIE 0x%x [in module %s]"),
12622 to_underlying (die
->sect_off
), objfile_name (objfile
));
12624 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
12630 /* DW_AT_entry_pc should be preferred. */
12631 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
12632 <= PC_BOUNDS_INVALID
)
12633 complaint (&symfile_complaints
,
12634 _("DW_AT_call_target target DIE has invalid "
12635 "low pc, for referencing DIE 0x%x [in module %s]"),
12636 to_underlying (die
->sect_off
), objfile_name (objfile
));
12639 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12640 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
12645 complaint (&symfile_complaints
,
12646 _("DW_TAG_call_site DW_AT_call_target is neither "
12647 "block nor reference, for DIE 0x%x [in module %s]"),
12648 to_underlying (die
->sect_off
), objfile_name (objfile
));
12650 call_site
->per_cu
= cu
->per_cu
;
12652 for (child_die
= die
->child
;
12653 child_die
&& child_die
->tag
;
12654 child_die
= sibling_die (child_die
))
12656 struct call_site_parameter
*parameter
;
12657 struct attribute
*loc
, *origin
;
12659 if (child_die
->tag
!= DW_TAG_call_site_parameter
12660 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
12662 /* Already printed the complaint above. */
12666 gdb_assert (call_site
->parameter_count
< nparams
);
12667 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
12669 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
12670 specifies DW_TAG_formal_parameter. Value of the data assumed for the
12671 register is contained in DW_AT_call_value. */
12673 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
12674 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
12675 if (origin
== NULL
)
12677 /* This was a pre-DWARF-5 GNU extension alias
12678 for DW_AT_call_parameter. */
12679 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
12681 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
12683 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
12685 sect_offset sect_off
12686 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
12687 if (!offset_in_cu_p (&cu
->header
, sect_off
))
12689 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
12690 binding can be done only inside one CU. Such referenced DIE
12691 therefore cannot be even moved to DW_TAG_partial_unit. */
12692 complaint (&symfile_complaints
,
12693 _("DW_AT_call_parameter offset is not in CU for "
12694 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
12695 to_underlying (child_die
->sect_off
),
12696 objfile_name (objfile
));
12699 parameter
->u
.param_cu_off
12700 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
12702 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
12704 complaint (&symfile_complaints
,
12705 _("No DW_FORM_block* DW_AT_location for "
12706 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
12707 to_underlying (child_die
->sect_off
), objfile_name (objfile
));
12712 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
12713 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
12714 if (parameter
->u
.dwarf_reg
!= -1)
12715 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
12716 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
12717 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
12718 ¶meter
->u
.fb_offset
))
12719 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
12722 complaint (&symfile_complaints
,
12723 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
12724 "for DW_FORM_block* DW_AT_location is supported for "
12725 "DW_TAG_call_site child DIE 0x%x "
12727 to_underlying (child_die
->sect_off
),
12728 objfile_name (objfile
));
12733 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
12735 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
12736 if (!attr_form_is_block (attr
))
12738 complaint (&symfile_complaints
,
12739 _("No DW_FORM_block* DW_AT_call_value for "
12740 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
12741 to_underlying (child_die
->sect_off
),
12742 objfile_name (objfile
));
12745 parameter
->value
= DW_BLOCK (attr
)->data
;
12746 parameter
->value_size
= DW_BLOCK (attr
)->size
;
12748 /* Parameters are not pre-cleared by memset above. */
12749 parameter
->data_value
= NULL
;
12750 parameter
->data_value_size
= 0;
12751 call_site
->parameter_count
++;
12753 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
12755 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
12758 if (!attr_form_is_block (attr
))
12759 complaint (&symfile_complaints
,
12760 _("No DW_FORM_block* DW_AT_call_data_value for "
12761 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
12762 to_underlying (child_die
->sect_off
),
12763 objfile_name (objfile
));
12766 parameter
->data_value
= DW_BLOCK (attr
)->data
;
12767 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
12773 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
12774 reading .debug_rnglists.
12775 Callback's type should be:
12776 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
12777 Return true if the attributes are present and valid, otherwise,
12780 template <typename Callback
>
12782 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
12783 Callback
&&callback
)
12785 struct objfile
*objfile
= cu
->objfile
;
12786 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12787 struct comp_unit_head
*cu_header
= &cu
->header
;
12788 bfd
*obfd
= objfile
->obfd
;
12789 unsigned int addr_size
= cu_header
->addr_size
;
12790 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
12791 /* Base address selection entry. */
12794 unsigned int dummy
;
12795 const gdb_byte
*buffer
;
12797 CORE_ADDR high
= 0;
12798 CORE_ADDR baseaddr
;
12799 bool overflow
= false;
12801 found_base
= cu
->base_known
;
12802 base
= cu
->base_address
;
12804 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->rnglists
);
12805 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
12807 complaint (&symfile_complaints
,
12808 _("Offset %d out of bounds for DW_AT_ranges attribute"),
12812 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
12814 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
12818 /* Initialize it due to a false compiler warning. */
12819 CORE_ADDR range_beginning
= 0, range_end
= 0;
12820 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
12821 + dwarf2_per_objfile
->rnglists
.size
);
12822 unsigned int bytes_read
;
12824 if (buffer
== buf_end
)
12829 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
12832 case DW_RLE_end_of_list
:
12834 case DW_RLE_base_address
:
12835 if (buffer
+ cu
->header
.addr_size
> buf_end
)
12840 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
12842 buffer
+= bytes_read
;
12844 case DW_RLE_start_length
:
12845 if (buffer
+ cu
->header
.addr_size
> buf_end
)
12850 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
12851 buffer
+= bytes_read
;
12852 range_end
= (range_beginning
12853 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
12854 buffer
+= bytes_read
;
12855 if (buffer
> buf_end
)
12861 case DW_RLE_offset_pair
:
12862 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
12863 buffer
+= bytes_read
;
12864 if (buffer
> buf_end
)
12869 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
12870 buffer
+= bytes_read
;
12871 if (buffer
> buf_end
)
12877 case DW_RLE_start_end
:
12878 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
12883 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
12884 buffer
+= bytes_read
;
12885 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
12886 buffer
+= bytes_read
;
12889 complaint (&symfile_complaints
,
12890 _("Invalid .debug_rnglists data (no base address)"));
12893 if (rlet
== DW_RLE_end_of_list
|| overflow
)
12895 if (rlet
== DW_RLE_base_address
)
12900 /* We have no valid base address for the ranges
12902 complaint (&symfile_complaints
,
12903 _("Invalid .debug_rnglists data (no base address)"));
12907 if (range_beginning
> range_end
)
12909 /* Inverted range entries are invalid. */
12910 complaint (&symfile_complaints
,
12911 _("Invalid .debug_rnglists data (inverted range)"));
12915 /* Empty range entries have no effect. */
12916 if (range_beginning
== range_end
)
12919 range_beginning
+= base
;
12922 /* A not-uncommon case of bad debug info.
12923 Don't pollute the addrmap with bad data. */
12924 if (range_beginning
+ baseaddr
== 0
12925 && !dwarf2_per_objfile
->has_section_at_zero
)
12927 complaint (&symfile_complaints
,
12928 _(".debug_rnglists entry has start address of zero"
12929 " [in module %s]"), objfile_name (objfile
));
12933 callback (range_beginning
, range_end
);
12938 complaint (&symfile_complaints
,
12939 _("Offset %d is not terminated "
12940 "for DW_AT_ranges attribute"),
12948 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
12949 Callback's type should be:
12950 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
12951 Return 1 if the attributes are present and valid, otherwise, return 0. */
12953 template <typename Callback
>
12955 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
12956 Callback
&&callback
)
12958 struct objfile
*objfile
= cu
->objfile
;
12959 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12960 struct comp_unit_head
*cu_header
= &cu
->header
;
12961 bfd
*obfd
= objfile
->obfd
;
12962 unsigned int addr_size
= cu_header
->addr_size
;
12963 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
12964 /* Base address selection entry. */
12967 unsigned int dummy
;
12968 const gdb_byte
*buffer
;
12969 CORE_ADDR baseaddr
;
12971 if (cu_header
->version
>= 5)
12972 return dwarf2_rnglists_process (offset
, cu
, callback
);
12974 found_base
= cu
->base_known
;
12975 base
= cu
->base_address
;
12977 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
12978 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
12980 complaint (&symfile_complaints
,
12981 _("Offset %d out of bounds for DW_AT_ranges attribute"),
12985 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
12987 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
12991 CORE_ADDR range_beginning
, range_end
;
12993 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
12994 buffer
+= addr_size
;
12995 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
12996 buffer
+= addr_size
;
12997 offset
+= 2 * addr_size
;
12999 /* An end of list marker is a pair of zero addresses. */
13000 if (range_beginning
== 0 && range_end
== 0)
13001 /* Found the end of list entry. */
13004 /* Each base address selection entry is a pair of 2 values.
13005 The first is the largest possible address, the second is
13006 the base address. Check for a base address here. */
13007 if ((range_beginning
& mask
) == mask
)
13009 /* If we found the largest possible address, then we already
13010 have the base address in range_end. */
13018 /* We have no valid base address for the ranges
13020 complaint (&symfile_complaints
,
13021 _("Invalid .debug_ranges data (no base address)"));
13025 if (range_beginning
> range_end
)
13027 /* Inverted range entries are invalid. */
13028 complaint (&symfile_complaints
,
13029 _("Invalid .debug_ranges data (inverted range)"));
13033 /* Empty range entries have no effect. */
13034 if (range_beginning
== range_end
)
13037 range_beginning
+= base
;
13040 /* A not-uncommon case of bad debug info.
13041 Don't pollute the addrmap with bad data. */
13042 if (range_beginning
+ baseaddr
== 0
13043 && !dwarf2_per_objfile
->has_section_at_zero
)
13045 complaint (&symfile_complaints
,
13046 _(".debug_ranges entry has start address of zero"
13047 " [in module %s]"), objfile_name (objfile
));
13051 callback (range_beginning
, range_end
);
13057 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13058 Return 1 if the attributes are present and valid, otherwise, return 0.
13059 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
13062 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13063 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13064 struct partial_symtab
*ranges_pst
)
13066 struct objfile
*objfile
= cu
->objfile
;
13067 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13068 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
13069 SECT_OFF_TEXT (objfile
));
13072 CORE_ADDR high
= 0;
13075 retval
= dwarf2_ranges_process (offset
, cu
,
13076 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
13078 if (ranges_pst
!= NULL
)
13083 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
13084 range_beginning
+ baseaddr
);
13085 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
13086 range_end
+ baseaddr
);
13087 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
13091 /* FIXME: This is recording everything as a low-high
13092 segment of consecutive addresses. We should have a
13093 data structure for discontiguous block ranges
13097 low
= range_beginning
;
13103 if (range_beginning
< low
)
13104 low
= range_beginning
;
13105 if (range_end
> high
)
13113 /* If the first entry is an end-of-list marker, the range
13114 describes an empty scope, i.e. no instructions. */
13120 *high_return
= high
;
13124 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
13125 definition for the return value. *LOWPC and *HIGHPC are set iff
13126 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
13128 static enum pc_bounds_kind
13129 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
13130 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
13131 struct partial_symtab
*pst
)
13133 struct attribute
*attr
;
13134 struct attribute
*attr_high
;
13136 CORE_ADDR high
= 0;
13137 enum pc_bounds_kind ret
;
13139 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13142 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13145 low
= attr_value_as_address (attr
);
13146 high
= attr_value_as_address (attr_high
);
13147 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
13151 /* Found high w/o low attribute. */
13152 return PC_BOUNDS_INVALID
;
13154 /* Found consecutive range of addresses. */
13155 ret
= PC_BOUNDS_HIGH_LOW
;
13159 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13162 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
13163 We take advantage of the fact that DW_AT_ranges does not appear
13164 in DW_TAG_compile_unit of DWO files. */
13165 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
13166 unsigned int ranges_offset
= (DW_UNSND (attr
)
13167 + (need_ranges_base
13171 /* Value of the DW_AT_ranges attribute is the offset in the
13172 .debug_ranges section. */
13173 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
13174 return PC_BOUNDS_INVALID
;
13175 /* Found discontinuous range of addresses. */
13176 ret
= PC_BOUNDS_RANGES
;
13179 return PC_BOUNDS_NOT_PRESENT
;
13182 /* read_partial_die has also the strict LOW < HIGH requirement. */
13184 return PC_BOUNDS_INVALID
;
13186 /* When using the GNU linker, .gnu.linkonce. sections are used to
13187 eliminate duplicate copies of functions and vtables and such.
13188 The linker will arbitrarily choose one and discard the others.
13189 The AT_*_pc values for such functions refer to local labels in
13190 these sections. If the section from that file was discarded, the
13191 labels are not in the output, so the relocs get a value of 0.
13192 If this is a discarded function, mark the pc bounds as invalid,
13193 so that GDB will ignore it. */
13194 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
13195 return PC_BOUNDS_INVALID
;
13203 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
13204 its low and high PC addresses. Do nothing if these addresses could not
13205 be determined. Otherwise, set LOWPC to the low address if it is smaller,
13206 and HIGHPC to the high address if greater than HIGHPC. */
13209 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
13210 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13211 struct dwarf2_cu
*cu
)
13213 CORE_ADDR low
, high
;
13214 struct die_info
*child
= die
->child
;
13216 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
13218 *lowpc
= std::min (*lowpc
, low
);
13219 *highpc
= std::max (*highpc
, high
);
13222 /* If the language does not allow nested subprograms (either inside
13223 subprograms or lexical blocks), we're done. */
13224 if (cu
->language
!= language_ada
)
13227 /* Check all the children of the given DIE. If it contains nested
13228 subprograms, then check their pc bounds. Likewise, we need to
13229 check lexical blocks as well, as they may also contain subprogram
13231 while (child
&& child
->tag
)
13233 if (child
->tag
== DW_TAG_subprogram
13234 || child
->tag
== DW_TAG_lexical_block
)
13235 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
13236 child
= sibling_die (child
);
13240 /* Get the low and high pc's represented by the scope DIE, and store
13241 them in *LOWPC and *HIGHPC. If the correct values can't be
13242 determined, set *LOWPC to -1 and *HIGHPC to 0. */
13245 get_scope_pc_bounds (struct die_info
*die
,
13246 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13247 struct dwarf2_cu
*cu
)
13249 CORE_ADDR best_low
= (CORE_ADDR
) -1;
13250 CORE_ADDR best_high
= (CORE_ADDR
) 0;
13251 CORE_ADDR current_low
, current_high
;
13253 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
13254 >= PC_BOUNDS_RANGES
)
13256 best_low
= current_low
;
13257 best_high
= current_high
;
13261 struct die_info
*child
= die
->child
;
13263 while (child
&& child
->tag
)
13265 switch (child
->tag
) {
13266 case DW_TAG_subprogram
:
13267 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
13269 case DW_TAG_namespace
:
13270 case DW_TAG_module
:
13271 /* FIXME: carlton/2004-01-16: Should we do this for
13272 DW_TAG_class_type/DW_TAG_structure_type, too? I think
13273 that current GCC's always emit the DIEs corresponding
13274 to definitions of methods of classes as children of a
13275 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
13276 the DIEs giving the declarations, which could be
13277 anywhere). But I don't see any reason why the
13278 standards says that they have to be there. */
13279 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
13281 if (current_low
!= ((CORE_ADDR
) -1))
13283 best_low
= std::min (best_low
, current_low
);
13284 best_high
= std::max (best_high
, current_high
);
13292 child
= sibling_die (child
);
13297 *highpc
= best_high
;
13300 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
13304 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
13305 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
13307 struct objfile
*objfile
= cu
->objfile
;
13308 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13309 struct attribute
*attr
;
13310 struct attribute
*attr_high
;
13312 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13315 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13318 CORE_ADDR low
= attr_value_as_address (attr
);
13319 CORE_ADDR high
= attr_value_as_address (attr_high
);
13321 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
13324 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
13325 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
13326 record_block_range (block
, low
, high
- 1);
13330 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13333 bfd
*obfd
= objfile
->obfd
;
13334 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
13335 We take advantage of the fact that DW_AT_ranges does not appear
13336 in DW_TAG_compile_unit of DWO files. */
13337 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
13339 /* The value of the DW_AT_ranges attribute is the offset of the
13340 address range list in the .debug_ranges section. */
13341 unsigned long offset
= (DW_UNSND (attr
)
13342 + (need_ranges_base
? cu
->ranges_base
: 0));
13343 const gdb_byte
*buffer
;
13345 /* For some target architectures, but not others, the
13346 read_address function sign-extends the addresses it returns.
13347 To recognize base address selection entries, we need a
13349 unsigned int addr_size
= cu
->header
.addr_size
;
13350 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13352 /* The base address, to which the next pair is relative. Note
13353 that this 'base' is a DWARF concept: most entries in a range
13354 list are relative, to reduce the number of relocs against the
13355 debugging information. This is separate from this function's
13356 'baseaddr' argument, which GDB uses to relocate debugging
13357 information from a shared library based on the address at
13358 which the library was loaded. */
13359 CORE_ADDR base
= cu
->base_address
;
13360 int base_known
= cu
->base_known
;
13362 dwarf2_ranges_process (offset
, cu
,
13363 [&] (CORE_ADDR start
, CORE_ADDR end
)
13367 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
13368 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
13369 record_block_range (block
, start
, end
- 1);
13374 /* Check whether the producer field indicates either of GCC < 4.6, or the
13375 Intel C/C++ compiler, and cache the result in CU. */
13378 check_producer (struct dwarf2_cu
*cu
)
13382 if (cu
->producer
== NULL
)
13384 /* For unknown compilers expect their behavior is DWARF version
13387 GCC started to support .debug_types sections by -gdwarf-4 since
13388 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
13389 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
13390 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
13391 interpreted incorrectly by GDB now - GCC PR debug/48229. */
13393 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
13395 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
13396 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
13398 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
13399 cu
->producer_is_icc_lt_14
= major
< 14;
13402 /* For other non-GCC compilers, expect their behavior is DWARF version
13406 cu
->checked_producer
= 1;
13409 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
13410 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
13411 during 4.6.0 experimental. */
13414 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
13416 if (!cu
->checked_producer
)
13417 check_producer (cu
);
13419 return cu
->producer_is_gxx_lt_4_6
;
13422 /* Return the default accessibility type if it is not overriden by
13423 DW_AT_accessibility. */
13425 static enum dwarf_access_attribute
13426 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
13428 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
13430 /* The default DWARF 2 accessibility for members is public, the default
13431 accessibility for inheritance is private. */
13433 if (die
->tag
!= DW_TAG_inheritance
)
13434 return DW_ACCESS_public
;
13436 return DW_ACCESS_private
;
13440 /* DWARF 3+ defines the default accessibility a different way. The same
13441 rules apply now for DW_TAG_inheritance as for the members and it only
13442 depends on the container kind. */
13444 if (die
->parent
->tag
== DW_TAG_class_type
)
13445 return DW_ACCESS_private
;
13447 return DW_ACCESS_public
;
13451 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
13452 offset. If the attribute was not found return 0, otherwise return
13453 1. If it was found but could not properly be handled, set *OFFSET
13457 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
13460 struct attribute
*attr
;
13462 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
13467 /* Note that we do not check for a section offset first here.
13468 This is because DW_AT_data_member_location is new in DWARF 4,
13469 so if we see it, we can assume that a constant form is really
13470 a constant and not a section offset. */
13471 if (attr_form_is_constant (attr
))
13472 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
13473 else if (attr_form_is_section_offset (attr
))
13474 dwarf2_complex_location_expr_complaint ();
13475 else if (attr_form_is_block (attr
))
13476 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
13478 dwarf2_complex_location_expr_complaint ();
13486 /* Add an aggregate field to the field list. */
13489 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
13490 struct dwarf2_cu
*cu
)
13492 struct objfile
*objfile
= cu
->objfile
;
13493 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13494 struct nextfield
*new_field
;
13495 struct attribute
*attr
;
13497 const char *fieldname
= "";
13499 /* Allocate a new field list entry and link it in. */
13500 new_field
= XNEW (struct nextfield
);
13501 make_cleanup (xfree
, new_field
);
13502 memset (new_field
, 0, sizeof (struct nextfield
));
13504 if (die
->tag
== DW_TAG_inheritance
)
13506 new_field
->next
= fip
->baseclasses
;
13507 fip
->baseclasses
= new_field
;
13511 new_field
->next
= fip
->fields
;
13512 fip
->fields
= new_field
;
13516 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
13518 new_field
->accessibility
= DW_UNSND (attr
);
13520 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
13521 if (new_field
->accessibility
!= DW_ACCESS_public
)
13522 fip
->non_public_fields
= 1;
13524 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
13526 new_field
->virtuality
= DW_UNSND (attr
);
13528 new_field
->virtuality
= DW_VIRTUALITY_none
;
13530 fp
= &new_field
->field
;
13532 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
13536 /* Data member other than a C++ static data member. */
13538 /* Get type of field. */
13539 fp
->type
= die_type (die
, cu
);
13541 SET_FIELD_BITPOS (*fp
, 0);
13543 /* Get bit size of field (zero if none). */
13544 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
13547 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
13551 FIELD_BITSIZE (*fp
) = 0;
13554 /* Get bit offset of field. */
13555 if (handle_data_member_location (die
, cu
, &offset
))
13556 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
13557 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
13560 if (gdbarch_bits_big_endian (gdbarch
))
13562 /* For big endian bits, the DW_AT_bit_offset gives the
13563 additional bit offset from the MSB of the containing
13564 anonymous object to the MSB of the field. We don't
13565 have to do anything special since we don't need to
13566 know the size of the anonymous object. */
13567 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
13571 /* For little endian bits, compute the bit offset to the
13572 MSB of the anonymous object, subtract off the number of
13573 bits from the MSB of the field to the MSB of the
13574 object, and then subtract off the number of bits of
13575 the field itself. The result is the bit offset of
13576 the LSB of the field. */
13577 int anonymous_size
;
13578 int bit_offset
= DW_UNSND (attr
);
13580 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13583 /* The size of the anonymous object containing
13584 the bit field is explicit, so use the
13585 indicated size (in bytes). */
13586 anonymous_size
= DW_UNSND (attr
);
13590 /* The size of the anonymous object containing
13591 the bit field must be inferred from the type
13592 attribute of the data member containing the
13594 anonymous_size
= TYPE_LENGTH (fp
->type
);
13596 SET_FIELD_BITPOS (*fp
,
13597 (FIELD_BITPOS (*fp
)
13598 + anonymous_size
* bits_per_byte
13599 - bit_offset
- FIELD_BITSIZE (*fp
)));
13602 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
13604 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
13605 + dwarf2_get_attr_constant_value (attr
, 0)));
13607 /* Get name of field. */
13608 fieldname
= dwarf2_name (die
, cu
);
13609 if (fieldname
== NULL
)
13612 /* The name is already allocated along with this objfile, so we don't
13613 need to duplicate it for the type. */
13614 fp
->name
= fieldname
;
13616 /* Change accessibility for artificial fields (e.g. virtual table
13617 pointer or virtual base class pointer) to private. */
13618 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
13620 FIELD_ARTIFICIAL (*fp
) = 1;
13621 new_field
->accessibility
= DW_ACCESS_private
;
13622 fip
->non_public_fields
= 1;
13625 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
13627 /* C++ static member. */
13629 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
13630 is a declaration, but all versions of G++ as of this writing
13631 (so through at least 3.2.1) incorrectly generate
13632 DW_TAG_variable tags. */
13634 const char *physname
;
13636 /* Get name of field. */
13637 fieldname
= dwarf2_name (die
, cu
);
13638 if (fieldname
== NULL
)
13641 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13643 /* Only create a symbol if this is an external value.
13644 new_symbol checks this and puts the value in the global symbol
13645 table, which we want. If it is not external, new_symbol
13646 will try to put the value in cu->list_in_scope which is wrong. */
13647 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
13649 /* A static const member, not much different than an enum as far as
13650 we're concerned, except that we can support more types. */
13651 new_symbol (die
, NULL
, cu
);
13654 /* Get physical name. */
13655 physname
= dwarf2_physname (fieldname
, die
, cu
);
13657 /* The name is already allocated along with this objfile, so we don't
13658 need to duplicate it for the type. */
13659 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
13660 FIELD_TYPE (*fp
) = die_type (die
, cu
);
13661 FIELD_NAME (*fp
) = fieldname
;
13663 else if (die
->tag
== DW_TAG_inheritance
)
13667 /* C++ base class field. */
13668 if (handle_data_member_location (die
, cu
, &offset
))
13669 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
13670 FIELD_BITSIZE (*fp
) = 0;
13671 FIELD_TYPE (*fp
) = die_type (die
, cu
);
13672 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
13673 fip
->nbaseclasses
++;
13677 /* Add a typedef defined in the scope of the FIP's class. */
13680 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
13681 struct dwarf2_cu
*cu
)
13683 struct typedef_field_list
*new_field
;
13684 struct typedef_field
*fp
;
13686 /* Allocate a new field list entry and link it in. */
13687 new_field
= XCNEW (struct typedef_field_list
);
13688 make_cleanup (xfree
, new_field
);
13690 gdb_assert (die
->tag
== DW_TAG_typedef
);
13692 fp
= &new_field
->field
;
13694 /* Get name of field. */
13695 fp
->name
= dwarf2_name (die
, cu
);
13696 if (fp
->name
== NULL
)
13699 fp
->type
= read_type_die (die
, cu
);
13701 /* Save accessibility. */
13702 enum dwarf_access_attribute accessibility
;
13703 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
13705 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
13707 accessibility
= dwarf2_default_access_attribute (die
, cu
);
13708 switch (accessibility
)
13710 case DW_ACCESS_public
:
13711 /* The assumed value if neither private nor protected. */
13713 case DW_ACCESS_private
:
13714 fp
->is_private
= 1;
13716 case DW_ACCESS_protected
:
13717 fp
->is_protected
= 1;
13720 complaint (&symfile_complaints
,
13721 _("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
13724 new_field
->next
= fip
->typedef_field_list
;
13725 fip
->typedef_field_list
= new_field
;
13726 fip
->typedef_field_list_count
++;
13729 /* Create the vector of fields, and attach it to the type. */
13732 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
13733 struct dwarf2_cu
*cu
)
13735 int nfields
= fip
->nfields
;
13737 /* Record the field count, allocate space for the array of fields,
13738 and create blank accessibility bitfields if necessary. */
13739 TYPE_NFIELDS (type
) = nfields
;
13740 TYPE_FIELDS (type
) = (struct field
*)
13741 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
13742 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
13744 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
13746 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13748 TYPE_FIELD_PRIVATE_BITS (type
) =
13749 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
13750 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
13752 TYPE_FIELD_PROTECTED_BITS (type
) =
13753 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
13754 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
13756 TYPE_FIELD_IGNORE_BITS (type
) =
13757 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
13758 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
13761 /* If the type has baseclasses, allocate and clear a bit vector for
13762 TYPE_FIELD_VIRTUAL_BITS. */
13763 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
13765 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
13766 unsigned char *pointer
;
13768 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13769 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
13770 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
13771 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
13772 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
13775 /* Copy the saved-up fields into the field vector. Start from the head of
13776 the list, adding to the tail of the field array, so that they end up in
13777 the same order in the array in which they were added to the list. */
13778 while (nfields
-- > 0)
13780 struct nextfield
*fieldp
;
13784 fieldp
= fip
->fields
;
13785 fip
->fields
= fieldp
->next
;
13789 fieldp
= fip
->baseclasses
;
13790 fip
->baseclasses
= fieldp
->next
;
13793 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
13794 switch (fieldp
->accessibility
)
13796 case DW_ACCESS_private
:
13797 if (cu
->language
!= language_ada
)
13798 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
13801 case DW_ACCESS_protected
:
13802 if (cu
->language
!= language_ada
)
13803 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
13806 case DW_ACCESS_public
:
13810 /* Unknown accessibility. Complain and treat it as public. */
13812 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
13813 fieldp
->accessibility
);
13817 if (nfields
< fip
->nbaseclasses
)
13819 switch (fieldp
->virtuality
)
13821 case DW_VIRTUALITY_virtual
:
13822 case DW_VIRTUALITY_pure_virtual
:
13823 if (cu
->language
== language_ada
)
13824 error (_("unexpected virtuality in component of Ada type"));
13825 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
13832 /* Return true if this member function is a constructor, false
13836 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
13838 const char *fieldname
;
13839 const char *type_name
;
13842 if (die
->parent
== NULL
)
13845 if (die
->parent
->tag
!= DW_TAG_structure_type
13846 && die
->parent
->tag
!= DW_TAG_union_type
13847 && die
->parent
->tag
!= DW_TAG_class_type
)
13850 fieldname
= dwarf2_name (die
, cu
);
13851 type_name
= dwarf2_name (die
->parent
, cu
);
13852 if (fieldname
== NULL
|| type_name
== NULL
)
13855 len
= strlen (fieldname
);
13856 return (strncmp (fieldname
, type_name
, len
) == 0
13857 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
13860 /* Add a member function to the proper fieldlist. */
13863 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
13864 struct type
*type
, struct dwarf2_cu
*cu
)
13866 struct objfile
*objfile
= cu
->objfile
;
13867 struct attribute
*attr
;
13868 struct fnfieldlist
*flp
;
13870 struct fn_field
*fnp
;
13871 const char *fieldname
;
13872 struct nextfnfield
*new_fnfield
;
13873 struct type
*this_type
;
13874 enum dwarf_access_attribute accessibility
;
13876 if (cu
->language
== language_ada
)
13877 error (_("unexpected member function in Ada type"));
13879 /* Get name of member function. */
13880 fieldname
= dwarf2_name (die
, cu
);
13881 if (fieldname
== NULL
)
13884 /* Look up member function name in fieldlist. */
13885 for (i
= 0; i
< fip
->nfnfields
; i
++)
13887 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
13891 /* Create new list element if necessary. */
13892 if (i
< fip
->nfnfields
)
13893 flp
= &fip
->fnfieldlists
[i
];
13896 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
13898 fip
->fnfieldlists
= (struct fnfieldlist
*)
13899 xrealloc (fip
->fnfieldlists
,
13900 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
13901 * sizeof (struct fnfieldlist
));
13902 if (fip
->nfnfields
== 0)
13903 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
13905 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
13906 flp
->name
= fieldname
;
13909 i
= fip
->nfnfields
++;
13912 /* Create a new member function field and chain it to the field list
13914 new_fnfield
= XNEW (struct nextfnfield
);
13915 make_cleanup (xfree
, new_fnfield
);
13916 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
13917 new_fnfield
->next
= flp
->head
;
13918 flp
->head
= new_fnfield
;
13921 /* Fill in the member function field info. */
13922 fnp
= &new_fnfield
->fnfield
;
13924 /* Delay processing of the physname until later. */
13925 if (cu
->language
== language_cplus
)
13927 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
13932 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
13933 fnp
->physname
= physname
? physname
: "";
13936 fnp
->type
= alloc_type (objfile
);
13937 this_type
= read_type_die (die
, cu
);
13938 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
13940 int nparams
= TYPE_NFIELDS (this_type
);
13942 /* TYPE is the domain of this method, and THIS_TYPE is the type
13943 of the method itself (TYPE_CODE_METHOD). */
13944 smash_to_method_type (fnp
->type
, type
,
13945 TYPE_TARGET_TYPE (this_type
),
13946 TYPE_FIELDS (this_type
),
13947 TYPE_NFIELDS (this_type
),
13948 TYPE_VARARGS (this_type
));
13950 /* Handle static member functions.
13951 Dwarf2 has no clean way to discern C++ static and non-static
13952 member functions. G++ helps GDB by marking the first
13953 parameter for non-static member functions (which is the this
13954 pointer) as artificial. We obtain this information from
13955 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
13956 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
13957 fnp
->voffset
= VOFFSET_STATIC
;
13960 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
13961 dwarf2_full_name (fieldname
, die
, cu
));
13963 /* Get fcontext from DW_AT_containing_type if present. */
13964 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
13965 fnp
->fcontext
= die_containing_type (die
, cu
);
13967 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
13968 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
13970 /* Get accessibility. */
13971 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
13973 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
13975 accessibility
= dwarf2_default_access_attribute (die
, cu
);
13976 switch (accessibility
)
13978 case DW_ACCESS_private
:
13979 fnp
->is_private
= 1;
13981 case DW_ACCESS_protected
:
13982 fnp
->is_protected
= 1;
13986 /* Check for artificial methods. */
13987 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
13988 if (attr
&& DW_UNSND (attr
) != 0)
13989 fnp
->is_artificial
= 1;
13991 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
13993 /* Get index in virtual function table if it is a virtual member
13994 function. For older versions of GCC, this is an offset in the
13995 appropriate virtual table, as specified by DW_AT_containing_type.
13996 For everyone else, it is an expression to be evaluated relative
13997 to the object address. */
13999 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
14002 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
14004 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
14006 /* Old-style GCC. */
14007 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
14009 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
14010 || (DW_BLOCK (attr
)->size
> 1
14011 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
14012 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
14014 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14015 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
14016 dwarf2_complex_location_expr_complaint ();
14018 fnp
->voffset
/= cu
->header
.addr_size
;
14022 dwarf2_complex_location_expr_complaint ();
14024 if (!fnp
->fcontext
)
14026 /* If there is no `this' field and no DW_AT_containing_type,
14027 we cannot actually find a base class context for the
14029 if (TYPE_NFIELDS (this_type
) == 0
14030 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
14032 complaint (&symfile_complaints
,
14033 _("cannot determine context for virtual member "
14034 "function \"%s\" (offset %d)"),
14035 fieldname
, to_underlying (die
->sect_off
));
14040 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
14044 else if (attr_form_is_section_offset (attr
))
14046 dwarf2_complex_location_expr_complaint ();
14050 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
14056 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14057 if (attr
&& DW_UNSND (attr
))
14059 /* GCC does this, as of 2008-08-25; PR debug/37237. */
14060 complaint (&symfile_complaints
,
14061 _("Member function \"%s\" (offset %d) is virtual "
14062 "but the vtable offset is not specified"),
14063 fieldname
, to_underlying (die
->sect_off
));
14064 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14065 TYPE_CPLUS_DYNAMIC (type
) = 1;
14070 /* Create the vector of member function fields, and attach it to the type. */
14073 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
14074 struct dwarf2_cu
*cu
)
14076 struct fnfieldlist
*flp
;
14079 if (cu
->language
== language_ada
)
14080 error (_("unexpected member functions in Ada type"));
14082 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14083 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
14084 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
14086 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
14088 struct nextfnfield
*nfp
= flp
->head
;
14089 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
14092 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
14093 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
14094 fn_flp
->fn_fields
= (struct fn_field
*)
14095 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
14096 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
14097 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
14100 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
14103 /* Returns non-zero if NAME is the name of a vtable member in CU's
14104 language, zero otherwise. */
14106 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
14108 static const char vptr
[] = "_vptr";
14109 static const char vtable
[] = "vtable";
14111 /* Look for the C++ form of the vtable. */
14112 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
14118 /* GCC outputs unnamed structures that are really pointers to member
14119 functions, with the ABI-specified layout. If TYPE describes
14120 such a structure, smash it into a member function type.
14122 GCC shouldn't do this; it should just output pointer to member DIEs.
14123 This is GCC PR debug/28767. */
14126 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
14128 struct type
*pfn_type
, *self_type
, *new_type
;
14130 /* Check for a structure with no name and two children. */
14131 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
14134 /* Check for __pfn and __delta members. */
14135 if (TYPE_FIELD_NAME (type
, 0) == NULL
14136 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
14137 || TYPE_FIELD_NAME (type
, 1) == NULL
14138 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
14141 /* Find the type of the method. */
14142 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
14143 if (pfn_type
== NULL
14144 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
14145 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
14148 /* Look for the "this" argument. */
14149 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
14150 if (TYPE_NFIELDS (pfn_type
) == 0
14151 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
14152 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
14155 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
14156 new_type
= alloc_type (objfile
);
14157 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
14158 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
14159 TYPE_VARARGS (pfn_type
));
14160 smash_to_methodptr_type (type
, new_type
);
14164 /* Called when we find the DIE that starts a structure or union scope
14165 (definition) to create a type for the structure or union. Fill in
14166 the type's name and general properties; the members will not be
14167 processed until process_structure_scope. A symbol table entry for
14168 the type will also not be done until process_structure_scope (assuming
14169 the type has a name).
14171 NOTE: we need to call these functions regardless of whether or not the
14172 DIE has a DW_AT_name attribute, since it might be an anonymous
14173 structure or union. This gets the type entered into our set of
14174 user defined types. */
14176 static struct type
*
14177 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14179 struct objfile
*objfile
= cu
->objfile
;
14181 struct attribute
*attr
;
14184 /* If the definition of this type lives in .debug_types, read that type.
14185 Don't follow DW_AT_specification though, that will take us back up
14186 the chain and we want to go down. */
14187 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
14190 type
= get_DW_AT_signature_type (die
, attr
, cu
);
14192 /* The type's CU may not be the same as CU.
14193 Ensure TYPE is recorded with CU in die_type_hash. */
14194 return set_die_type (die
, type
, cu
);
14197 type
= alloc_type (objfile
);
14198 INIT_CPLUS_SPECIFIC (type
);
14200 name
= dwarf2_name (die
, cu
);
14203 if (cu
->language
== language_cplus
14204 || cu
->language
== language_d
14205 || cu
->language
== language_rust
)
14207 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
14209 /* dwarf2_full_name might have already finished building the DIE's
14210 type. If so, there is no need to continue. */
14211 if (get_die_type (die
, cu
) != NULL
)
14212 return get_die_type (die
, cu
);
14214 TYPE_TAG_NAME (type
) = full_name
;
14215 if (die
->tag
== DW_TAG_structure_type
14216 || die
->tag
== DW_TAG_class_type
)
14217 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
14221 /* The name is already allocated along with this objfile, so
14222 we don't need to duplicate it for the type. */
14223 TYPE_TAG_NAME (type
) = name
;
14224 if (die
->tag
== DW_TAG_class_type
)
14225 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
14229 if (die
->tag
== DW_TAG_structure_type
)
14231 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
14233 else if (die
->tag
== DW_TAG_union_type
)
14235 TYPE_CODE (type
) = TYPE_CODE_UNION
;
14239 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
14242 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
14243 TYPE_DECLARED_CLASS (type
) = 1;
14245 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14248 if (attr_form_is_constant (attr
))
14249 TYPE_LENGTH (type
) = DW_UNSND (attr
);
14252 /* For the moment, dynamic type sizes are not supported
14253 by GDB's struct type. The actual size is determined
14254 on-demand when resolving the type of a given object,
14255 so set the type's length to zero for now. Otherwise,
14256 we record an expression as the length, and that expression
14257 could lead to a very large value, which could eventually
14258 lead to us trying to allocate that much memory when creating
14259 a value of that type. */
14260 TYPE_LENGTH (type
) = 0;
14265 TYPE_LENGTH (type
) = 0;
14268 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
14270 /* ICC<14 does not output the required DW_AT_declaration on
14271 incomplete types, but gives them a size of zero. */
14272 TYPE_STUB (type
) = 1;
14275 TYPE_STUB_SUPPORTED (type
) = 1;
14277 if (die_is_declaration (die
, cu
))
14278 TYPE_STUB (type
) = 1;
14279 else if (attr
== NULL
&& die
->child
== NULL
14280 && producer_is_realview (cu
->producer
))
14281 /* RealView does not output the required DW_AT_declaration
14282 on incomplete types. */
14283 TYPE_STUB (type
) = 1;
14285 /* We need to add the type field to the die immediately so we don't
14286 infinitely recurse when dealing with pointers to the structure
14287 type within the structure itself. */
14288 set_die_type (die
, type
, cu
);
14290 /* set_die_type should be already done. */
14291 set_descriptive_type (type
, die
, cu
);
14296 /* Finish creating a structure or union type, including filling in
14297 its members and creating a symbol for it. */
14300 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
14302 struct objfile
*objfile
= cu
->objfile
;
14303 struct die_info
*child_die
;
14306 type
= get_die_type (die
, cu
);
14308 type
= read_structure_type (die
, cu
);
14310 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
14312 struct field_info fi
;
14313 std::vector
<struct symbol
*> template_args
;
14314 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
14316 memset (&fi
, 0, sizeof (struct field_info
));
14318 child_die
= die
->child
;
14320 while (child_die
&& child_die
->tag
)
14322 if (child_die
->tag
== DW_TAG_member
14323 || child_die
->tag
== DW_TAG_variable
)
14325 /* NOTE: carlton/2002-11-05: A C++ static data member
14326 should be a DW_TAG_member that is a declaration, but
14327 all versions of G++ as of this writing (so through at
14328 least 3.2.1) incorrectly generate DW_TAG_variable
14329 tags for them instead. */
14330 dwarf2_add_field (&fi
, child_die
, cu
);
14332 else if (child_die
->tag
== DW_TAG_subprogram
)
14334 /* Rust doesn't have member functions in the C++ sense.
14335 However, it does emit ordinary functions as children
14336 of a struct DIE. */
14337 if (cu
->language
== language_rust
)
14338 read_func_scope (child_die
, cu
);
14341 /* C++ member function. */
14342 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
14345 else if (child_die
->tag
== DW_TAG_inheritance
)
14347 /* C++ base class field. */
14348 dwarf2_add_field (&fi
, child_die
, cu
);
14350 else if (child_die
->tag
== DW_TAG_typedef
)
14351 dwarf2_add_typedef (&fi
, child_die
, cu
);
14352 else if (child_die
->tag
== DW_TAG_template_type_param
14353 || child_die
->tag
== DW_TAG_template_value_param
)
14355 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
14358 template_args
.push_back (arg
);
14361 child_die
= sibling_die (child_die
);
14364 /* Attach template arguments to type. */
14365 if (!template_args
.empty ())
14367 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14368 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
14369 TYPE_TEMPLATE_ARGUMENTS (type
)
14370 = XOBNEWVEC (&objfile
->objfile_obstack
,
14372 TYPE_N_TEMPLATE_ARGUMENTS (type
));
14373 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
14374 template_args
.data (),
14375 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
14376 * sizeof (struct symbol
*)));
14379 /* Attach fields and member functions to the type. */
14381 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
14384 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
14386 /* Get the type which refers to the base class (possibly this
14387 class itself) which contains the vtable pointer for the current
14388 class from the DW_AT_containing_type attribute. This use of
14389 DW_AT_containing_type is a GNU extension. */
14391 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
14393 struct type
*t
= die_containing_type (die
, cu
);
14395 set_type_vptr_basetype (type
, t
);
14400 /* Our own class provides vtbl ptr. */
14401 for (i
= TYPE_NFIELDS (t
) - 1;
14402 i
>= TYPE_N_BASECLASSES (t
);
14405 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
14407 if (is_vtable_name (fieldname
, cu
))
14409 set_type_vptr_fieldno (type
, i
);
14414 /* Complain if virtual function table field not found. */
14415 if (i
< TYPE_N_BASECLASSES (t
))
14416 complaint (&symfile_complaints
,
14417 _("virtual function table pointer "
14418 "not found when defining class '%s'"),
14419 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
14424 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
14427 else if (cu
->producer
14428 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
14430 /* The IBM XLC compiler does not provide direct indication
14431 of the containing type, but the vtable pointer is
14432 always named __vfp. */
14436 for (i
= TYPE_NFIELDS (type
) - 1;
14437 i
>= TYPE_N_BASECLASSES (type
);
14440 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
14442 set_type_vptr_fieldno (type
, i
);
14443 set_type_vptr_basetype (type
, type
);
14450 /* Copy fi.typedef_field_list linked list elements content into the
14451 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
14452 if (fi
.typedef_field_list
)
14454 int i
= fi
.typedef_field_list_count
;
14456 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14457 TYPE_TYPEDEF_FIELD_ARRAY (type
)
14458 = ((struct typedef_field
*)
14459 TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
));
14460 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
14462 /* Reverse the list order to keep the debug info elements order. */
14465 struct typedef_field
*dest
, *src
;
14467 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
14468 src
= &fi
.typedef_field_list
->field
;
14469 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
14474 do_cleanups (back_to
);
14477 quirk_gcc_member_function_pointer (type
, objfile
);
14479 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
14480 snapshots) has been known to create a die giving a declaration
14481 for a class that has, as a child, a die giving a definition for a
14482 nested class. So we have to process our children even if the
14483 current die is a declaration. Normally, of course, a declaration
14484 won't have any children at all. */
14486 child_die
= die
->child
;
14488 while (child_die
!= NULL
&& child_die
->tag
)
14490 if (child_die
->tag
== DW_TAG_member
14491 || child_die
->tag
== DW_TAG_variable
14492 || child_die
->tag
== DW_TAG_inheritance
14493 || child_die
->tag
== DW_TAG_template_value_param
14494 || child_die
->tag
== DW_TAG_template_type_param
)
14499 process_die (child_die
, cu
);
14501 child_die
= sibling_die (child_die
);
14504 /* Do not consider external references. According to the DWARF standard,
14505 these DIEs are identified by the fact that they have no byte_size
14506 attribute, and a declaration attribute. */
14507 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
14508 || !die_is_declaration (die
, cu
))
14509 new_symbol (die
, type
, cu
);
14512 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
14513 update TYPE using some information only available in DIE's children. */
14516 update_enumeration_type_from_children (struct die_info
*die
,
14518 struct dwarf2_cu
*cu
)
14520 struct die_info
*child_die
;
14521 int unsigned_enum
= 1;
14525 auto_obstack obstack
;
14527 for (child_die
= die
->child
;
14528 child_die
!= NULL
&& child_die
->tag
;
14529 child_die
= sibling_die (child_die
))
14531 struct attribute
*attr
;
14533 const gdb_byte
*bytes
;
14534 struct dwarf2_locexpr_baton
*baton
;
14537 if (child_die
->tag
!= DW_TAG_enumerator
)
14540 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
14544 name
= dwarf2_name (child_die
, cu
);
14546 name
= "<anonymous enumerator>";
14548 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
14549 &value
, &bytes
, &baton
);
14555 else if ((mask
& value
) != 0)
14560 /* If we already know that the enum type is neither unsigned, nor
14561 a flag type, no need to look at the rest of the enumerates. */
14562 if (!unsigned_enum
&& !flag_enum
)
14567 TYPE_UNSIGNED (type
) = 1;
14569 TYPE_FLAG_ENUM (type
) = 1;
14572 /* Given a DW_AT_enumeration_type die, set its type. We do not
14573 complete the type's fields yet, or create any symbols. */
14575 static struct type
*
14576 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14578 struct objfile
*objfile
= cu
->objfile
;
14580 struct attribute
*attr
;
14583 /* If the definition of this type lives in .debug_types, read that type.
14584 Don't follow DW_AT_specification though, that will take us back up
14585 the chain and we want to go down. */
14586 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
14589 type
= get_DW_AT_signature_type (die
, attr
, cu
);
14591 /* The type's CU may not be the same as CU.
14592 Ensure TYPE is recorded with CU in die_type_hash. */
14593 return set_die_type (die
, type
, cu
);
14596 type
= alloc_type (objfile
);
14598 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
14599 name
= dwarf2_full_name (NULL
, die
, cu
);
14601 TYPE_TAG_NAME (type
) = name
;
14603 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14606 struct type
*underlying_type
= die_type (die
, cu
);
14608 TYPE_TARGET_TYPE (type
) = underlying_type
;
14611 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14614 TYPE_LENGTH (type
) = DW_UNSND (attr
);
14618 TYPE_LENGTH (type
) = 0;
14621 /* The enumeration DIE can be incomplete. In Ada, any type can be
14622 declared as private in the package spec, and then defined only
14623 inside the package body. Such types are known as Taft Amendment
14624 Types. When another package uses such a type, an incomplete DIE
14625 may be generated by the compiler. */
14626 if (die_is_declaration (die
, cu
))
14627 TYPE_STUB (type
) = 1;
14629 /* Finish the creation of this type by using the enum's children.
14630 We must call this even when the underlying type has been provided
14631 so that we can determine if we're looking at a "flag" enum. */
14632 update_enumeration_type_from_children (die
, type
, cu
);
14634 /* If this type has an underlying type that is not a stub, then we
14635 may use its attributes. We always use the "unsigned" attribute
14636 in this situation, because ordinarily we guess whether the type
14637 is unsigned -- but the guess can be wrong and the underlying type
14638 can tell us the reality. However, we defer to a local size
14639 attribute if one exists, because this lets the compiler override
14640 the underlying type if needed. */
14641 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
14643 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
14644 if (TYPE_LENGTH (type
) == 0)
14645 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
14648 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
14650 return set_die_type (die
, type
, cu
);
14653 /* Given a pointer to a die which begins an enumeration, process all
14654 the dies that define the members of the enumeration, and create the
14655 symbol for the enumeration type.
14657 NOTE: We reverse the order of the element list. */
14660 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
14662 struct type
*this_type
;
14664 this_type
= get_die_type (die
, cu
);
14665 if (this_type
== NULL
)
14666 this_type
= read_enumeration_type (die
, cu
);
14668 if (die
->child
!= NULL
)
14670 struct die_info
*child_die
;
14671 struct symbol
*sym
;
14672 struct field
*fields
= NULL
;
14673 int num_fields
= 0;
14676 child_die
= die
->child
;
14677 while (child_die
&& child_die
->tag
)
14679 if (child_die
->tag
!= DW_TAG_enumerator
)
14681 process_die (child_die
, cu
);
14685 name
= dwarf2_name (child_die
, cu
);
14688 sym
= new_symbol (child_die
, this_type
, cu
);
14690 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
14692 fields
= (struct field
*)
14694 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
14695 * sizeof (struct field
));
14698 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
14699 FIELD_TYPE (fields
[num_fields
]) = NULL
;
14700 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
14701 FIELD_BITSIZE (fields
[num_fields
]) = 0;
14707 child_die
= sibling_die (child_die
);
14712 TYPE_NFIELDS (this_type
) = num_fields
;
14713 TYPE_FIELDS (this_type
) = (struct field
*)
14714 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
14715 memcpy (TYPE_FIELDS (this_type
), fields
,
14716 sizeof (struct field
) * num_fields
);
14721 /* If we are reading an enum from a .debug_types unit, and the enum
14722 is a declaration, and the enum is not the signatured type in the
14723 unit, then we do not want to add a symbol for it. Adding a
14724 symbol would in some cases obscure the true definition of the
14725 enum, giving users an incomplete type when the definition is
14726 actually available. Note that we do not want to do this for all
14727 enums which are just declarations, because C++0x allows forward
14728 enum declarations. */
14729 if (cu
->per_cu
->is_debug_types
14730 && die_is_declaration (die
, cu
))
14732 struct signatured_type
*sig_type
;
14734 sig_type
= (struct signatured_type
*) cu
->per_cu
;
14735 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
14736 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
14740 new_symbol (die
, this_type
, cu
);
14743 /* Extract all information from a DW_TAG_array_type DIE and put it in
14744 the DIE's type field. For now, this only handles one dimensional
14747 static struct type
*
14748 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14750 struct objfile
*objfile
= cu
->objfile
;
14751 struct die_info
*child_die
;
14753 struct type
*element_type
, *range_type
, *index_type
;
14754 struct attribute
*attr
;
14756 unsigned int bit_stride
= 0;
14758 element_type
= die_type (die
, cu
);
14760 /* The die_type call above may have already set the type for this DIE. */
14761 type
= get_die_type (die
, cu
);
14765 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
14767 bit_stride
= DW_UNSND (attr
) * 8;
14769 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
14771 bit_stride
= DW_UNSND (attr
);
14773 /* Irix 6.2 native cc creates array types without children for
14774 arrays with unspecified length. */
14775 if (die
->child
== NULL
)
14777 index_type
= objfile_type (objfile
)->builtin_int
;
14778 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
14779 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
14781 return set_die_type (die
, type
, cu
);
14784 std::vector
<struct type
*> range_types
;
14785 child_die
= die
->child
;
14786 while (child_die
&& child_die
->tag
)
14788 if (child_die
->tag
== DW_TAG_subrange_type
)
14790 struct type
*child_type
= read_type_die (child_die
, cu
);
14792 if (child_type
!= NULL
)
14794 /* The range type was succesfully read. Save it for the
14795 array type creation. */
14796 range_types
.push_back (child_type
);
14799 child_die
= sibling_die (child_die
);
14802 /* Dwarf2 dimensions are output from left to right, create the
14803 necessary array types in backwards order. */
14805 type
= element_type
;
14807 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
14811 while (i
< range_types
.size ())
14812 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
14817 size_t ndim
= range_types
.size ();
14819 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
14823 /* Understand Dwarf2 support for vector types (like they occur on
14824 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
14825 array type. This is not part of the Dwarf2/3 standard yet, but a
14826 custom vendor extension. The main difference between a regular
14827 array and the vector variant is that vectors are passed by value
14829 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
14831 make_vector_type (type
);
14833 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
14834 implementation may choose to implement triple vectors using this
14836 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14839 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
14840 TYPE_LENGTH (type
) = DW_UNSND (attr
);
14842 complaint (&symfile_complaints
,
14843 _("DW_AT_byte_size for array type smaller "
14844 "than the total size of elements"));
14847 name
= dwarf2_name (die
, cu
);
14849 TYPE_NAME (type
) = name
;
14851 /* Install the type in the die. */
14852 set_die_type (die
, type
, cu
);
14854 /* set_die_type should be already done. */
14855 set_descriptive_type (type
, die
, cu
);
14860 static enum dwarf_array_dim_ordering
14861 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
14863 struct attribute
*attr
;
14865 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
14868 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
14870 /* GNU F77 is a special case, as at 08/2004 array type info is the
14871 opposite order to the dwarf2 specification, but data is still
14872 laid out as per normal fortran.
14874 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
14875 version checking. */
14877 if (cu
->language
== language_fortran
14878 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
14880 return DW_ORD_row_major
;
14883 switch (cu
->language_defn
->la_array_ordering
)
14885 case array_column_major
:
14886 return DW_ORD_col_major
;
14887 case array_row_major
:
14889 return DW_ORD_row_major
;
14893 /* Extract all information from a DW_TAG_set_type DIE and put it in
14894 the DIE's type field. */
14896 static struct type
*
14897 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14899 struct type
*domain_type
, *set_type
;
14900 struct attribute
*attr
;
14902 domain_type
= die_type (die
, cu
);
14904 /* The die_type call above may have already set the type for this DIE. */
14905 set_type
= get_die_type (die
, cu
);
14909 set_type
= create_set_type (NULL
, domain_type
);
14911 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14913 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
14915 return set_die_type (die
, set_type
, cu
);
14918 /* A helper for read_common_block that creates a locexpr baton.
14919 SYM is the symbol which we are marking as computed.
14920 COMMON_DIE is the DIE for the common block.
14921 COMMON_LOC is the location expression attribute for the common
14923 MEMBER_LOC is the location expression attribute for the particular
14924 member of the common block that we are processing.
14925 CU is the CU from which the above come. */
14928 mark_common_block_symbol_computed (struct symbol
*sym
,
14929 struct die_info
*common_die
,
14930 struct attribute
*common_loc
,
14931 struct attribute
*member_loc
,
14932 struct dwarf2_cu
*cu
)
14934 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14935 struct dwarf2_locexpr_baton
*baton
;
14937 unsigned int cu_off
;
14938 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
14939 LONGEST offset
= 0;
14941 gdb_assert (common_loc
&& member_loc
);
14942 gdb_assert (attr_form_is_block (common_loc
));
14943 gdb_assert (attr_form_is_block (member_loc
)
14944 || attr_form_is_constant (member_loc
));
14946 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
14947 baton
->per_cu
= cu
->per_cu
;
14948 gdb_assert (baton
->per_cu
);
14950 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
14952 if (attr_form_is_constant (member_loc
))
14954 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
14955 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
14958 baton
->size
+= DW_BLOCK (member_loc
)->size
;
14960 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
14963 *ptr
++ = DW_OP_call4
;
14964 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
14965 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
14968 if (attr_form_is_constant (member_loc
))
14970 *ptr
++ = DW_OP_addr
;
14971 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
14972 ptr
+= cu
->header
.addr_size
;
14976 /* We have to copy the data here, because DW_OP_call4 will only
14977 use a DW_AT_location attribute. */
14978 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
14979 ptr
+= DW_BLOCK (member_loc
)->size
;
14982 *ptr
++ = DW_OP_plus
;
14983 gdb_assert (ptr
- baton
->data
== baton
->size
);
14985 SYMBOL_LOCATION_BATON (sym
) = baton
;
14986 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
14989 /* Create appropriate locally-scoped variables for all the
14990 DW_TAG_common_block entries. Also create a struct common_block
14991 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
14992 is used to sepate the common blocks name namespace from regular
14996 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
14998 struct attribute
*attr
;
15000 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15003 /* Support the .debug_loc offsets. */
15004 if (attr_form_is_block (attr
))
15008 else if (attr_form_is_section_offset (attr
))
15010 dwarf2_complex_location_expr_complaint ();
15015 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
15016 "common block member");
15021 if (die
->child
!= NULL
)
15023 struct objfile
*objfile
= cu
->objfile
;
15024 struct die_info
*child_die
;
15025 size_t n_entries
= 0, size
;
15026 struct common_block
*common_block
;
15027 struct symbol
*sym
;
15029 for (child_die
= die
->child
;
15030 child_die
&& child_die
->tag
;
15031 child_die
= sibling_die (child_die
))
15034 size
= (sizeof (struct common_block
)
15035 + (n_entries
- 1) * sizeof (struct symbol
*));
15037 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
15039 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
15040 common_block
->n_entries
= 0;
15042 for (child_die
= die
->child
;
15043 child_die
&& child_die
->tag
;
15044 child_die
= sibling_die (child_die
))
15046 /* Create the symbol in the DW_TAG_common_block block in the current
15048 sym
= new_symbol (child_die
, NULL
, cu
);
15051 struct attribute
*member_loc
;
15053 common_block
->contents
[common_block
->n_entries
++] = sym
;
15055 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
15059 /* GDB has handled this for a long time, but it is
15060 not specified by DWARF. It seems to have been
15061 emitted by gfortran at least as recently as:
15062 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
15063 complaint (&symfile_complaints
,
15064 _("Variable in common block has "
15065 "DW_AT_data_member_location "
15066 "- DIE at 0x%x [in module %s]"),
15067 to_underlying (child_die
->sect_off
),
15068 objfile_name (cu
->objfile
));
15070 if (attr_form_is_section_offset (member_loc
))
15071 dwarf2_complex_location_expr_complaint ();
15072 else if (attr_form_is_constant (member_loc
)
15073 || attr_form_is_block (member_loc
))
15076 mark_common_block_symbol_computed (sym
, die
, attr
,
15080 dwarf2_complex_location_expr_complaint ();
15085 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
15086 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
15090 /* Create a type for a C++ namespace. */
15092 static struct type
*
15093 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15095 struct objfile
*objfile
= cu
->objfile
;
15096 const char *previous_prefix
, *name
;
15100 /* For extensions, reuse the type of the original namespace. */
15101 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
15103 struct die_info
*ext_die
;
15104 struct dwarf2_cu
*ext_cu
= cu
;
15106 ext_die
= dwarf2_extension (die
, &ext_cu
);
15107 type
= read_type_die (ext_die
, ext_cu
);
15109 /* EXT_CU may not be the same as CU.
15110 Ensure TYPE is recorded with CU in die_type_hash. */
15111 return set_die_type (die
, type
, cu
);
15114 name
= namespace_name (die
, &is_anonymous
, cu
);
15116 /* Now build the name of the current namespace. */
15118 previous_prefix
= determine_prefix (die
, cu
);
15119 if (previous_prefix
[0] != '\0')
15120 name
= typename_concat (&objfile
->objfile_obstack
,
15121 previous_prefix
, name
, 0, cu
);
15123 /* Create the type. */
15124 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
15125 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
15127 return set_die_type (die
, type
, cu
);
15130 /* Read a namespace scope. */
15133 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
15135 struct objfile
*objfile
= cu
->objfile
;
15138 /* Add a symbol associated to this if we haven't seen the namespace
15139 before. Also, add a using directive if it's an anonymous
15142 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
15146 type
= read_type_die (die
, cu
);
15147 new_symbol (die
, type
, cu
);
15149 namespace_name (die
, &is_anonymous
, cu
);
15152 const char *previous_prefix
= determine_prefix (die
, cu
);
15154 std::vector
<const char *> excludes
;
15155 add_using_directive (using_directives (cu
->language
),
15156 previous_prefix
, TYPE_NAME (type
), NULL
,
15157 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
15161 if (die
->child
!= NULL
)
15163 struct die_info
*child_die
= die
->child
;
15165 while (child_die
&& child_die
->tag
)
15167 process_die (child_die
, cu
);
15168 child_die
= sibling_die (child_die
);
15173 /* Read a Fortran module as type. This DIE can be only a declaration used for
15174 imported module. Still we need that type as local Fortran "use ... only"
15175 declaration imports depend on the created type in determine_prefix. */
15177 static struct type
*
15178 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15180 struct objfile
*objfile
= cu
->objfile
;
15181 const char *module_name
;
15184 module_name
= dwarf2_name (die
, cu
);
15186 complaint (&symfile_complaints
,
15187 _("DW_TAG_module has no name, offset 0x%x"),
15188 to_underlying (die
->sect_off
));
15189 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
15191 /* determine_prefix uses TYPE_TAG_NAME. */
15192 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
15194 return set_die_type (die
, type
, cu
);
15197 /* Read a Fortran module. */
15200 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
15202 struct die_info
*child_die
= die
->child
;
15205 type
= read_type_die (die
, cu
);
15206 new_symbol (die
, type
, cu
);
15208 while (child_die
&& child_die
->tag
)
15210 process_die (child_die
, cu
);
15211 child_die
= sibling_die (child_die
);
15215 /* Return the name of the namespace represented by DIE. Set
15216 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
15219 static const char *
15220 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
15222 struct die_info
*current_die
;
15223 const char *name
= NULL
;
15225 /* Loop through the extensions until we find a name. */
15227 for (current_die
= die
;
15228 current_die
!= NULL
;
15229 current_die
= dwarf2_extension (die
, &cu
))
15231 /* We don't use dwarf2_name here so that we can detect the absence
15232 of a name -> anonymous namespace. */
15233 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
15239 /* Is it an anonymous namespace? */
15241 *is_anonymous
= (name
== NULL
);
15243 name
= CP_ANONYMOUS_NAMESPACE_STR
;
15248 /* Extract all information from a DW_TAG_pointer_type DIE and add to
15249 the user defined type vector. */
15251 static struct type
*
15252 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15254 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
15255 struct comp_unit_head
*cu_header
= &cu
->header
;
15257 struct attribute
*attr_byte_size
;
15258 struct attribute
*attr_address_class
;
15259 int byte_size
, addr_class
;
15260 struct type
*target_type
;
15262 target_type
= die_type (die
, cu
);
15264 /* The die_type call above may have already set the type for this DIE. */
15265 type
= get_die_type (die
, cu
);
15269 type
= lookup_pointer_type (target_type
);
15271 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15272 if (attr_byte_size
)
15273 byte_size
= DW_UNSND (attr_byte_size
);
15275 byte_size
= cu_header
->addr_size
;
15277 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
15278 if (attr_address_class
)
15279 addr_class
= DW_UNSND (attr_address_class
);
15281 addr_class
= DW_ADDR_none
;
15283 /* If the pointer size or address class is different than the
15284 default, create a type variant marked as such and set the
15285 length accordingly. */
15286 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
15288 if (gdbarch_address_class_type_flags_p (gdbarch
))
15292 type_flags
= gdbarch_address_class_type_flags
15293 (gdbarch
, byte_size
, addr_class
);
15294 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
15296 type
= make_type_with_address_space (type
, type_flags
);
15298 else if (TYPE_LENGTH (type
) != byte_size
)
15300 complaint (&symfile_complaints
,
15301 _("invalid pointer size %d"), byte_size
);
15305 /* Should we also complain about unhandled address classes? */
15309 TYPE_LENGTH (type
) = byte_size
;
15310 return set_die_type (die
, type
, cu
);
15313 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
15314 the user defined type vector. */
15316 static struct type
*
15317 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15320 struct type
*to_type
;
15321 struct type
*domain
;
15323 to_type
= die_type (die
, cu
);
15324 domain
= die_containing_type (die
, cu
);
15326 /* The calls above may have already set the type for this DIE. */
15327 type
= get_die_type (die
, cu
);
15331 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
15332 type
= lookup_methodptr_type (to_type
);
15333 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
15335 struct type
*new_type
= alloc_type (cu
->objfile
);
15337 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
15338 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
15339 TYPE_VARARGS (to_type
));
15340 type
= lookup_methodptr_type (new_type
);
15343 type
= lookup_memberptr_type (to_type
, domain
);
15345 return set_die_type (die
, type
, cu
);
15348 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
15349 the user defined type vector. */
15351 static struct type
*
15352 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
15353 enum type_code refcode
)
15355 struct comp_unit_head
*cu_header
= &cu
->header
;
15356 struct type
*type
, *target_type
;
15357 struct attribute
*attr
;
15359 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
15361 target_type
= die_type (die
, cu
);
15363 /* The die_type call above may have already set the type for this DIE. */
15364 type
= get_die_type (die
, cu
);
15368 type
= lookup_reference_type (target_type
, refcode
);
15369 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15372 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15376 TYPE_LENGTH (type
) = cu_header
->addr_size
;
15378 return set_die_type (die
, type
, cu
);
15381 /* Add the given cv-qualifiers to the element type of the array. GCC
15382 outputs DWARF type qualifiers that apply to an array, not the
15383 element type. But GDB relies on the array element type to carry
15384 the cv-qualifiers. This mimics section 6.7.3 of the C99
15387 static struct type
*
15388 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
15389 struct type
*base_type
, int cnst
, int voltl
)
15391 struct type
*el_type
, *inner_array
;
15393 base_type
= copy_type (base_type
);
15394 inner_array
= base_type
;
15396 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
15398 TYPE_TARGET_TYPE (inner_array
) =
15399 copy_type (TYPE_TARGET_TYPE (inner_array
));
15400 inner_array
= TYPE_TARGET_TYPE (inner_array
);
15403 el_type
= TYPE_TARGET_TYPE (inner_array
);
15404 cnst
|= TYPE_CONST (el_type
);
15405 voltl
|= TYPE_VOLATILE (el_type
);
15406 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
15408 return set_die_type (die
, base_type
, cu
);
15411 static struct type
*
15412 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15414 struct type
*base_type
, *cv_type
;
15416 base_type
= die_type (die
, cu
);
15418 /* The die_type call above may have already set the type for this DIE. */
15419 cv_type
= get_die_type (die
, cu
);
15423 /* In case the const qualifier is applied to an array type, the element type
15424 is so qualified, not the array type (section 6.7.3 of C99). */
15425 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
15426 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
15428 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
15429 return set_die_type (die
, cv_type
, cu
);
15432 static struct type
*
15433 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15435 struct type
*base_type
, *cv_type
;
15437 base_type
= die_type (die
, cu
);
15439 /* The die_type call above may have already set the type for this DIE. */
15440 cv_type
= get_die_type (die
, cu
);
15444 /* In case the volatile qualifier is applied to an array type, the
15445 element type is so qualified, not the array type (section 6.7.3
15447 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
15448 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
15450 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
15451 return set_die_type (die
, cv_type
, cu
);
15454 /* Handle DW_TAG_restrict_type. */
15456 static struct type
*
15457 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15459 struct type
*base_type
, *cv_type
;
15461 base_type
= die_type (die
, cu
);
15463 /* The die_type call above may have already set the type for this DIE. */
15464 cv_type
= get_die_type (die
, cu
);
15468 cv_type
= make_restrict_type (base_type
);
15469 return set_die_type (die
, cv_type
, cu
);
15472 /* Handle DW_TAG_atomic_type. */
15474 static struct type
*
15475 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15477 struct type
*base_type
, *cv_type
;
15479 base_type
= die_type (die
, cu
);
15481 /* The die_type call above may have already set the type for this DIE. */
15482 cv_type
= get_die_type (die
, cu
);
15486 cv_type
= make_atomic_type (base_type
);
15487 return set_die_type (die
, cv_type
, cu
);
15490 /* Extract all information from a DW_TAG_string_type DIE and add to
15491 the user defined type vector. It isn't really a user defined type,
15492 but it behaves like one, with other DIE's using an AT_user_def_type
15493 attribute to reference it. */
15495 static struct type
*
15496 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15498 struct objfile
*objfile
= cu
->objfile
;
15499 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15500 struct type
*type
, *range_type
, *index_type
, *char_type
;
15501 struct attribute
*attr
;
15502 unsigned int length
;
15504 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
15507 length
= DW_UNSND (attr
);
15511 /* Check for the DW_AT_byte_size attribute. */
15512 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15515 length
= DW_UNSND (attr
);
15523 index_type
= objfile_type (objfile
)->builtin_int
;
15524 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
15525 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
15526 type
= create_string_type (NULL
, char_type
, range_type
);
15528 return set_die_type (die
, type
, cu
);
15531 /* Assuming that DIE corresponds to a function, returns nonzero
15532 if the function is prototyped. */
15535 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
15537 struct attribute
*attr
;
15539 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
15540 if (attr
&& (DW_UNSND (attr
) != 0))
15543 /* The DWARF standard implies that the DW_AT_prototyped attribute
15544 is only meaninful for C, but the concept also extends to other
15545 languages that allow unprototyped functions (Eg: Objective C).
15546 For all other languages, assume that functions are always
15548 if (cu
->language
!= language_c
15549 && cu
->language
!= language_objc
15550 && cu
->language
!= language_opencl
)
15553 /* RealView does not emit DW_AT_prototyped. We can not distinguish
15554 prototyped and unprototyped functions; default to prototyped,
15555 since that is more common in modern code (and RealView warns
15556 about unprototyped functions). */
15557 if (producer_is_realview (cu
->producer
))
15563 /* Handle DIES due to C code like:
15567 int (*funcp)(int a, long l);
15571 ('funcp' generates a DW_TAG_subroutine_type DIE). */
15573 static struct type
*
15574 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15576 struct objfile
*objfile
= cu
->objfile
;
15577 struct type
*type
; /* Type that this function returns. */
15578 struct type
*ftype
; /* Function that returns above type. */
15579 struct attribute
*attr
;
15581 type
= die_type (die
, cu
);
15583 /* The die_type call above may have already set the type for this DIE. */
15584 ftype
= get_die_type (die
, cu
);
15588 ftype
= lookup_function_type (type
);
15590 if (prototyped_function_p (die
, cu
))
15591 TYPE_PROTOTYPED (ftype
) = 1;
15593 /* Store the calling convention in the type if it's available in
15594 the subroutine die. Otherwise set the calling convention to
15595 the default value DW_CC_normal. */
15596 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15598 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
15599 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
15600 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
15602 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
15604 /* Record whether the function returns normally to its caller or not
15605 if the DWARF producer set that information. */
15606 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
15607 if (attr
&& (DW_UNSND (attr
) != 0))
15608 TYPE_NO_RETURN (ftype
) = 1;
15610 /* We need to add the subroutine type to the die immediately so
15611 we don't infinitely recurse when dealing with parameters
15612 declared as the same subroutine type. */
15613 set_die_type (die
, ftype
, cu
);
15615 if (die
->child
!= NULL
)
15617 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
15618 struct die_info
*child_die
;
15619 int nparams
, iparams
;
15621 /* Count the number of parameters.
15622 FIXME: GDB currently ignores vararg functions, but knows about
15623 vararg member functions. */
15625 child_die
= die
->child
;
15626 while (child_die
&& child_die
->tag
)
15628 if (child_die
->tag
== DW_TAG_formal_parameter
)
15630 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
15631 TYPE_VARARGS (ftype
) = 1;
15632 child_die
= sibling_die (child_die
);
15635 /* Allocate storage for parameters and fill them in. */
15636 TYPE_NFIELDS (ftype
) = nparams
;
15637 TYPE_FIELDS (ftype
) = (struct field
*)
15638 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
15640 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
15641 even if we error out during the parameters reading below. */
15642 for (iparams
= 0; iparams
< nparams
; iparams
++)
15643 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
15646 child_die
= die
->child
;
15647 while (child_die
&& child_die
->tag
)
15649 if (child_die
->tag
== DW_TAG_formal_parameter
)
15651 struct type
*arg_type
;
15653 /* DWARF version 2 has no clean way to discern C++
15654 static and non-static member functions. G++ helps
15655 GDB by marking the first parameter for non-static
15656 member functions (which is the this pointer) as
15657 artificial. We pass this information to
15658 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
15660 DWARF version 3 added DW_AT_object_pointer, which GCC
15661 4.5 does not yet generate. */
15662 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
15664 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
15666 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
15667 arg_type
= die_type (child_die
, cu
);
15669 /* RealView does not mark THIS as const, which the testsuite
15670 expects. GCC marks THIS as const in method definitions,
15671 but not in the class specifications (GCC PR 43053). */
15672 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
15673 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
15676 struct dwarf2_cu
*arg_cu
= cu
;
15677 const char *name
= dwarf2_name (child_die
, cu
);
15679 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
15682 /* If the compiler emits this, use it. */
15683 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
15686 else if (name
&& strcmp (name
, "this") == 0)
15687 /* Function definitions will have the argument names. */
15689 else if (name
== NULL
&& iparams
== 0)
15690 /* Declarations may not have the names, so like
15691 elsewhere in GDB, assume an artificial first
15692 argument is "this". */
15696 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
15700 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
15703 child_die
= sibling_die (child_die
);
15710 static struct type
*
15711 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
15713 struct objfile
*objfile
= cu
->objfile
;
15714 const char *name
= NULL
;
15715 struct type
*this_type
, *target_type
;
15717 name
= dwarf2_full_name (NULL
, die
, cu
);
15718 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
15719 TYPE_TARGET_STUB (this_type
) = 1;
15720 set_die_type (die
, this_type
, cu
);
15721 target_type
= die_type (die
, cu
);
15722 if (target_type
!= this_type
)
15723 TYPE_TARGET_TYPE (this_type
) = target_type
;
15726 /* Self-referential typedefs are, it seems, not allowed by the DWARF
15727 spec and cause infinite loops in GDB. */
15728 complaint (&symfile_complaints
,
15729 _("Self-referential DW_TAG_typedef "
15730 "- DIE at 0x%x [in module %s]"),
15731 to_underlying (die
->sect_off
), objfile_name (objfile
));
15732 TYPE_TARGET_TYPE (this_type
) = NULL
;
15737 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
15738 (which may be different from NAME) to the architecture back-end to allow
15739 it to guess the correct format if necessary. */
15741 static struct type
*
15742 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
15743 const char *name_hint
)
15745 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15746 const struct floatformat
**format
;
15749 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
15751 type
= init_float_type (objfile
, bits
, name
, format
);
15753 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
15758 /* Find a representation of a given base type and install
15759 it in the TYPE field of the die. */
15761 static struct type
*
15762 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15764 struct objfile
*objfile
= cu
->objfile
;
15766 struct attribute
*attr
;
15767 int encoding
= 0, bits
= 0;
15770 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
15773 encoding
= DW_UNSND (attr
);
15775 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15778 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
15780 name
= dwarf2_name (die
, cu
);
15783 complaint (&symfile_complaints
,
15784 _("DW_AT_name missing from DW_TAG_base_type"));
15789 case DW_ATE_address
:
15790 /* Turn DW_ATE_address into a void * pointer. */
15791 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
15792 type
= init_pointer_type (objfile
, bits
, name
, type
);
15794 case DW_ATE_boolean
:
15795 type
= init_boolean_type (objfile
, bits
, 1, name
);
15797 case DW_ATE_complex_float
:
15798 type
= dwarf2_init_float_type (objfile
, bits
/ 2, NULL
, name
);
15799 type
= init_complex_type (objfile
, name
, type
);
15801 case DW_ATE_decimal_float
:
15802 type
= init_decfloat_type (objfile
, bits
, name
);
15805 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
);
15807 case DW_ATE_signed
:
15808 type
= init_integer_type (objfile
, bits
, 0, name
);
15810 case DW_ATE_unsigned
:
15811 if (cu
->language
== language_fortran
15813 && startswith (name
, "character("))
15814 type
= init_character_type (objfile
, bits
, 1, name
);
15816 type
= init_integer_type (objfile
, bits
, 1, name
);
15818 case DW_ATE_signed_char
:
15819 if (cu
->language
== language_ada
|| cu
->language
== language_m2
15820 || cu
->language
== language_pascal
15821 || cu
->language
== language_fortran
)
15822 type
= init_character_type (objfile
, bits
, 0, name
);
15824 type
= init_integer_type (objfile
, bits
, 0, name
);
15826 case DW_ATE_unsigned_char
:
15827 if (cu
->language
== language_ada
|| cu
->language
== language_m2
15828 || cu
->language
== language_pascal
15829 || cu
->language
== language_fortran
15830 || cu
->language
== language_rust
)
15831 type
= init_character_type (objfile
, bits
, 1, name
);
15833 type
= init_integer_type (objfile
, bits
, 1, name
);
15837 gdbarch
*arch
= get_objfile_arch (objfile
);
15840 type
= builtin_type (arch
)->builtin_char16
;
15841 else if (bits
== 32)
15842 type
= builtin_type (arch
)->builtin_char32
;
15845 complaint (&symfile_complaints
,
15846 _("unsupported DW_ATE_UTF bit size: '%d'"),
15848 type
= init_integer_type (objfile
, bits
, 1, name
);
15850 return set_die_type (die
, type
, cu
);
15855 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
15856 dwarf_type_encoding_name (encoding
));
15857 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
15861 if (name
&& strcmp (name
, "char") == 0)
15862 TYPE_NOSIGN (type
) = 1;
15864 return set_die_type (die
, type
, cu
);
15867 /* Parse dwarf attribute if it's a block, reference or constant and put the
15868 resulting value of the attribute into struct bound_prop.
15869 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
15872 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
15873 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
)
15875 struct dwarf2_property_baton
*baton
;
15876 struct obstack
*obstack
= &cu
->objfile
->objfile_obstack
;
15878 if (attr
== NULL
|| prop
== NULL
)
15881 if (attr_form_is_block (attr
))
15883 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
15884 baton
->referenced_type
= NULL
;
15885 baton
->locexpr
.per_cu
= cu
->per_cu
;
15886 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
15887 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
15888 prop
->data
.baton
= baton
;
15889 prop
->kind
= PROP_LOCEXPR
;
15890 gdb_assert (prop
->data
.baton
!= NULL
);
15892 else if (attr_form_is_ref (attr
))
15894 struct dwarf2_cu
*target_cu
= cu
;
15895 struct die_info
*target_die
;
15896 struct attribute
*target_attr
;
15898 target_die
= follow_die_ref (die
, attr
, &target_cu
);
15899 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
15900 if (target_attr
== NULL
)
15901 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
15903 if (target_attr
== NULL
)
15906 switch (target_attr
->name
)
15908 case DW_AT_location
:
15909 if (attr_form_is_section_offset (target_attr
))
15911 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
15912 baton
->referenced_type
= die_type (target_die
, target_cu
);
15913 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
15914 prop
->data
.baton
= baton
;
15915 prop
->kind
= PROP_LOCLIST
;
15916 gdb_assert (prop
->data
.baton
!= NULL
);
15918 else if (attr_form_is_block (target_attr
))
15920 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
15921 baton
->referenced_type
= die_type (target_die
, target_cu
);
15922 baton
->locexpr
.per_cu
= cu
->per_cu
;
15923 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
15924 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
15925 prop
->data
.baton
= baton
;
15926 prop
->kind
= PROP_LOCEXPR
;
15927 gdb_assert (prop
->data
.baton
!= NULL
);
15931 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
15932 "dynamic property");
15936 case DW_AT_data_member_location
:
15940 if (!handle_data_member_location (target_die
, target_cu
,
15944 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
15945 baton
->referenced_type
= read_type_die (target_die
->parent
,
15947 baton
->offset_info
.offset
= offset
;
15948 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
15949 prop
->data
.baton
= baton
;
15950 prop
->kind
= PROP_ADDR_OFFSET
;
15955 else if (attr_form_is_constant (attr
))
15957 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
15958 prop
->kind
= PROP_CONST
;
15962 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
15963 dwarf2_name (die
, cu
));
15970 /* Read the given DW_AT_subrange DIE. */
15972 static struct type
*
15973 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15975 struct type
*base_type
, *orig_base_type
;
15976 struct type
*range_type
;
15977 struct attribute
*attr
;
15978 struct dynamic_prop low
, high
;
15979 int low_default_is_valid
;
15980 int high_bound_is_count
= 0;
15982 LONGEST negative_mask
;
15984 orig_base_type
= die_type (die
, cu
);
15985 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
15986 whereas the real type might be. So, we use ORIG_BASE_TYPE when
15987 creating the range type, but we use the result of check_typedef
15988 when examining properties of the type. */
15989 base_type
= check_typedef (orig_base_type
);
15991 /* The die_type call above may have already set the type for this DIE. */
15992 range_type
= get_die_type (die
, cu
);
15996 low
.kind
= PROP_CONST
;
15997 high
.kind
= PROP_CONST
;
15998 high
.data
.const_val
= 0;
16000 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
16001 omitting DW_AT_lower_bound. */
16002 switch (cu
->language
)
16005 case language_cplus
:
16006 low
.data
.const_val
= 0;
16007 low_default_is_valid
= 1;
16009 case language_fortran
:
16010 low
.data
.const_val
= 1;
16011 low_default_is_valid
= 1;
16014 case language_objc
:
16015 case language_rust
:
16016 low
.data
.const_val
= 0;
16017 low_default_is_valid
= (cu
->header
.version
>= 4);
16021 case language_pascal
:
16022 low
.data
.const_val
= 1;
16023 low_default_is_valid
= (cu
->header
.version
>= 4);
16026 low
.data
.const_val
= 0;
16027 low_default_is_valid
= 0;
16031 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
16033 attr_to_dynamic_prop (attr
, die
, cu
, &low
);
16034 else if (!low_default_is_valid
)
16035 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
16036 "- DIE at 0x%x [in module %s]"),
16037 to_underlying (die
->sect_off
), objfile_name (cu
->objfile
));
16039 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
16040 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
))
16042 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
16043 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
))
16045 /* If bounds are constant do the final calculation here. */
16046 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
16047 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
16049 high_bound_is_count
= 1;
16053 /* Dwarf-2 specifications explicitly allows to create subrange types
16054 without specifying a base type.
16055 In that case, the base type must be set to the type of
16056 the lower bound, upper bound or count, in that order, if any of these
16057 three attributes references an object that has a type.
16058 If no base type is found, the Dwarf-2 specifications say that
16059 a signed integer type of size equal to the size of an address should
16061 For the following C code: `extern char gdb_int [];'
16062 GCC produces an empty range DIE.
16063 FIXME: muller/2010-05-28: Possible references to object for low bound,
16064 high bound or count are not yet handled by this code. */
16065 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
16067 struct objfile
*objfile
= cu
->objfile
;
16068 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16069 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
16070 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
16072 /* Test "int", "long int", and "long long int" objfile types,
16073 and select the first one having a size above or equal to the
16074 architecture address size. */
16075 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
16076 base_type
= int_type
;
16079 int_type
= objfile_type (objfile
)->builtin_long
;
16080 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
16081 base_type
= int_type
;
16084 int_type
= objfile_type (objfile
)->builtin_long_long
;
16085 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
16086 base_type
= int_type
;
16091 /* Normally, the DWARF producers are expected to use a signed
16092 constant form (Eg. DW_FORM_sdata) to express negative bounds.
16093 But this is unfortunately not always the case, as witnessed
16094 with GCC, for instance, where the ambiguous DW_FORM_dataN form
16095 is used instead. To work around that ambiguity, we treat
16096 the bounds as signed, and thus sign-extend their values, when
16097 the base type is signed. */
16099 -((LONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
16100 if (low
.kind
== PROP_CONST
16101 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
16102 low
.data
.const_val
|= negative_mask
;
16103 if (high
.kind
== PROP_CONST
16104 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
16105 high
.data
.const_val
|= negative_mask
;
16107 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
);
16109 if (high_bound_is_count
)
16110 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
16112 /* Ada expects an empty array on no boundary attributes. */
16113 if (attr
== NULL
&& cu
->language
!= language_ada
)
16114 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
16116 name
= dwarf2_name (die
, cu
);
16118 TYPE_NAME (range_type
) = name
;
16120 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16122 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
16124 set_die_type (die
, range_type
, cu
);
16126 /* set_die_type should be already done. */
16127 set_descriptive_type (range_type
, die
, cu
);
16132 static struct type
*
16133 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16137 /* For now, we only support the C meaning of an unspecified type: void. */
16139 type
= init_type (cu
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
16140 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
16142 return set_die_type (die
, type
, cu
);
16145 /* Read a single die and all its descendents. Set the die's sibling
16146 field to NULL; set other fields in the die correctly, and set all
16147 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
16148 location of the info_ptr after reading all of those dies. PARENT
16149 is the parent of the die in question. */
16151 static struct die_info
*
16152 read_die_and_children (const struct die_reader_specs
*reader
,
16153 const gdb_byte
*info_ptr
,
16154 const gdb_byte
**new_info_ptr
,
16155 struct die_info
*parent
)
16157 struct die_info
*die
;
16158 const gdb_byte
*cur_ptr
;
16161 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
16164 *new_info_ptr
= cur_ptr
;
16167 store_in_ref_table (die
, reader
->cu
);
16170 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
16174 *new_info_ptr
= cur_ptr
;
16177 die
->sibling
= NULL
;
16178 die
->parent
= parent
;
16182 /* Read a die, all of its descendents, and all of its siblings; set
16183 all of the fields of all of the dies correctly. Arguments are as
16184 in read_die_and_children. */
16186 static struct die_info
*
16187 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
16188 const gdb_byte
*info_ptr
,
16189 const gdb_byte
**new_info_ptr
,
16190 struct die_info
*parent
)
16192 struct die_info
*first_die
, *last_sibling
;
16193 const gdb_byte
*cur_ptr
;
16195 cur_ptr
= info_ptr
;
16196 first_die
= last_sibling
= NULL
;
16200 struct die_info
*die
16201 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
16205 *new_info_ptr
= cur_ptr
;
16212 last_sibling
->sibling
= die
;
16214 last_sibling
= die
;
16218 /* Read a die, all of its descendents, and all of its siblings; set
16219 all of the fields of all of the dies correctly. Arguments are as
16220 in read_die_and_children.
16221 This the main entry point for reading a DIE and all its children. */
16223 static struct die_info
*
16224 read_die_and_siblings (const struct die_reader_specs
*reader
,
16225 const gdb_byte
*info_ptr
,
16226 const gdb_byte
**new_info_ptr
,
16227 struct die_info
*parent
)
16229 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
16230 new_info_ptr
, parent
);
16232 if (dwarf_die_debug
)
16234 fprintf_unfiltered (gdb_stdlog
,
16235 "Read die from %s@0x%x of %s:\n",
16236 get_section_name (reader
->die_section
),
16237 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
16238 bfd_get_filename (reader
->abfd
));
16239 dump_die (die
, dwarf_die_debug
);
16245 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
16247 The caller is responsible for filling in the extra attributes
16248 and updating (*DIEP)->num_attrs.
16249 Set DIEP to point to a newly allocated die with its information,
16250 except for its child, sibling, and parent fields.
16251 Set HAS_CHILDREN to tell whether the die has children or not. */
16253 static const gdb_byte
*
16254 read_full_die_1 (const struct die_reader_specs
*reader
,
16255 struct die_info
**diep
, const gdb_byte
*info_ptr
,
16256 int *has_children
, int num_extra_attrs
)
16258 unsigned int abbrev_number
, bytes_read
, i
;
16259 struct abbrev_info
*abbrev
;
16260 struct die_info
*die
;
16261 struct dwarf2_cu
*cu
= reader
->cu
;
16262 bfd
*abfd
= reader
->abfd
;
16264 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
16265 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
16266 info_ptr
+= bytes_read
;
16267 if (!abbrev_number
)
16274 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
16276 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
16278 bfd_get_filename (abfd
));
16280 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
16281 die
->sect_off
= sect_off
;
16282 die
->tag
= abbrev
->tag
;
16283 die
->abbrev
= abbrev_number
;
16285 /* Make the result usable.
16286 The caller needs to update num_attrs after adding the extra
16288 die
->num_attrs
= abbrev
->num_attrs
;
16290 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
16291 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
16295 *has_children
= abbrev
->has_children
;
16299 /* Read a die and all its attributes.
16300 Set DIEP to point to a newly allocated die with its information,
16301 except for its child, sibling, and parent fields.
16302 Set HAS_CHILDREN to tell whether the die has children or not. */
16304 static const gdb_byte
*
16305 read_full_die (const struct die_reader_specs
*reader
,
16306 struct die_info
**diep
, const gdb_byte
*info_ptr
,
16309 const gdb_byte
*result
;
16311 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
16313 if (dwarf_die_debug
)
16315 fprintf_unfiltered (gdb_stdlog
,
16316 "Read die from %s@0x%x of %s:\n",
16317 get_section_name (reader
->die_section
),
16318 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
16319 bfd_get_filename (reader
->abfd
));
16320 dump_die (*diep
, dwarf_die_debug
);
16326 /* Abbreviation tables.
16328 In DWARF version 2, the description of the debugging information is
16329 stored in a separate .debug_abbrev section. Before we read any
16330 dies from a section we read in all abbreviations and install them
16331 in a hash table. */
16333 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
16335 static struct abbrev_info
*
16336 abbrev_table_alloc_abbrev (struct abbrev_table
*abbrev_table
)
16338 struct abbrev_info
*abbrev
;
16340 abbrev
= XOBNEW (&abbrev_table
->abbrev_obstack
, struct abbrev_info
);
16341 memset (abbrev
, 0, sizeof (struct abbrev_info
));
16346 /* Add an abbreviation to the table. */
16349 abbrev_table_add_abbrev (struct abbrev_table
*abbrev_table
,
16350 unsigned int abbrev_number
,
16351 struct abbrev_info
*abbrev
)
16353 unsigned int hash_number
;
16355 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
16356 abbrev
->next
= abbrev_table
->abbrevs
[hash_number
];
16357 abbrev_table
->abbrevs
[hash_number
] = abbrev
;
16360 /* Look up an abbrev in the table.
16361 Returns NULL if the abbrev is not found. */
16363 static struct abbrev_info
*
16364 abbrev_table_lookup_abbrev (const struct abbrev_table
*abbrev_table
,
16365 unsigned int abbrev_number
)
16367 unsigned int hash_number
;
16368 struct abbrev_info
*abbrev
;
16370 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
16371 abbrev
= abbrev_table
->abbrevs
[hash_number
];
16375 if (abbrev
->number
== abbrev_number
)
16377 abbrev
= abbrev
->next
;
16382 /* Read in an abbrev table. */
16384 static struct abbrev_table
*
16385 abbrev_table_read_table (struct dwarf2_section_info
*section
,
16386 sect_offset sect_off
)
16388 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16389 bfd
*abfd
= get_section_bfd_owner (section
);
16390 struct abbrev_table
*abbrev_table
;
16391 const gdb_byte
*abbrev_ptr
;
16392 struct abbrev_info
*cur_abbrev
;
16393 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
16394 unsigned int abbrev_form
;
16395 struct attr_abbrev
*cur_attrs
;
16396 unsigned int allocated_attrs
;
16398 abbrev_table
= XNEW (struct abbrev_table
);
16399 abbrev_table
->sect_off
= sect_off
;
16400 obstack_init (&abbrev_table
->abbrev_obstack
);
16401 abbrev_table
->abbrevs
=
16402 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct abbrev_info
*,
16404 memset (abbrev_table
->abbrevs
, 0,
16405 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
16407 dwarf2_read_section (objfile
, section
);
16408 abbrev_ptr
= section
->buffer
+ to_underlying (sect_off
);
16409 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
16410 abbrev_ptr
+= bytes_read
;
16412 allocated_attrs
= ATTR_ALLOC_CHUNK
;
16413 cur_attrs
= XNEWVEC (struct attr_abbrev
, allocated_attrs
);
16415 /* Loop until we reach an abbrev number of 0. */
16416 while (abbrev_number
)
16418 cur_abbrev
= abbrev_table_alloc_abbrev (abbrev_table
);
16420 /* read in abbrev header */
16421 cur_abbrev
->number
= abbrev_number
;
16423 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
16424 abbrev_ptr
+= bytes_read
;
16425 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
16428 /* now read in declarations */
16431 LONGEST implicit_const
;
16433 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
16434 abbrev_ptr
+= bytes_read
;
16435 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
16436 abbrev_ptr
+= bytes_read
;
16437 if (abbrev_form
== DW_FORM_implicit_const
)
16439 implicit_const
= read_signed_leb128 (abfd
, abbrev_ptr
,
16441 abbrev_ptr
+= bytes_read
;
16445 /* Initialize it due to a false compiler warning. */
16446 implicit_const
= -1;
16449 if (abbrev_name
== 0)
16452 if (cur_abbrev
->num_attrs
== allocated_attrs
)
16454 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
16456 = XRESIZEVEC (struct attr_abbrev
, cur_attrs
, allocated_attrs
);
16459 cur_attrs
[cur_abbrev
->num_attrs
].name
16460 = (enum dwarf_attribute
) abbrev_name
;
16461 cur_attrs
[cur_abbrev
->num_attrs
].form
16462 = (enum dwarf_form
) abbrev_form
;
16463 cur_attrs
[cur_abbrev
->num_attrs
].implicit_const
= implicit_const
;
16464 ++cur_abbrev
->num_attrs
;
16467 cur_abbrev
->attrs
=
16468 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
16469 cur_abbrev
->num_attrs
);
16470 memcpy (cur_abbrev
->attrs
, cur_attrs
,
16471 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
16473 abbrev_table_add_abbrev (abbrev_table
, abbrev_number
, cur_abbrev
);
16475 /* Get next abbreviation.
16476 Under Irix6 the abbreviations for a compilation unit are not
16477 always properly terminated with an abbrev number of 0.
16478 Exit loop if we encounter an abbreviation which we have
16479 already read (which means we are about to read the abbreviations
16480 for the next compile unit) or if the end of the abbreviation
16481 table is reached. */
16482 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
16484 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
16485 abbrev_ptr
+= bytes_read
;
16486 if (abbrev_table_lookup_abbrev (abbrev_table
, abbrev_number
) != NULL
)
16491 return abbrev_table
;
16494 /* Free the resources held by ABBREV_TABLE. */
16497 abbrev_table_free (struct abbrev_table
*abbrev_table
)
16499 obstack_free (&abbrev_table
->abbrev_obstack
, NULL
);
16500 xfree (abbrev_table
);
16503 /* Same as abbrev_table_free but as a cleanup.
16504 We pass in a pointer to the pointer to the table so that we can
16505 set the pointer to NULL when we're done. It also simplifies
16506 build_type_psymtabs_1. */
16509 abbrev_table_free_cleanup (void *table_ptr
)
16511 struct abbrev_table
**abbrev_table_ptr
= (struct abbrev_table
**) table_ptr
;
16513 if (*abbrev_table_ptr
!= NULL
)
16514 abbrev_table_free (*abbrev_table_ptr
);
16515 *abbrev_table_ptr
= NULL
;
16518 /* Read the abbrev table for CU from ABBREV_SECTION. */
16521 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
16522 struct dwarf2_section_info
*abbrev_section
)
16525 abbrev_table_read_table (abbrev_section
, cu
->header
.abbrev_sect_off
);
16528 /* Release the memory used by the abbrev table for a compilation unit. */
16531 dwarf2_free_abbrev_table (void *ptr_to_cu
)
16533 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr_to_cu
;
16535 if (cu
->abbrev_table
!= NULL
)
16536 abbrev_table_free (cu
->abbrev_table
);
16537 /* Set this to NULL so that we SEGV if we try to read it later,
16538 and also because free_comp_unit verifies this is NULL. */
16539 cu
->abbrev_table
= NULL
;
16542 /* Returns nonzero if TAG represents a type that we might generate a partial
16546 is_type_tag_for_partial (int tag
)
16551 /* Some types that would be reasonable to generate partial symbols for,
16552 that we don't at present. */
16553 case DW_TAG_array_type
:
16554 case DW_TAG_file_type
:
16555 case DW_TAG_ptr_to_member_type
:
16556 case DW_TAG_set_type
:
16557 case DW_TAG_string_type
:
16558 case DW_TAG_subroutine_type
:
16560 case DW_TAG_base_type
:
16561 case DW_TAG_class_type
:
16562 case DW_TAG_interface_type
:
16563 case DW_TAG_enumeration_type
:
16564 case DW_TAG_structure_type
:
16565 case DW_TAG_subrange_type
:
16566 case DW_TAG_typedef
:
16567 case DW_TAG_union_type
:
16574 /* Load all DIEs that are interesting for partial symbols into memory. */
16576 static struct partial_die_info
*
16577 load_partial_dies (const struct die_reader_specs
*reader
,
16578 const gdb_byte
*info_ptr
, int building_psymtab
)
16580 struct dwarf2_cu
*cu
= reader
->cu
;
16581 struct objfile
*objfile
= cu
->objfile
;
16582 struct partial_die_info
*part_die
;
16583 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
16584 struct abbrev_info
*abbrev
;
16585 unsigned int bytes_read
;
16586 unsigned int load_all
= 0;
16587 int nesting_level
= 1;
16592 gdb_assert (cu
->per_cu
!= NULL
);
16593 if (cu
->per_cu
->load_all_dies
)
16597 = htab_create_alloc_ex (cu
->header
.length
/ 12,
16601 &cu
->comp_unit_obstack
,
16602 hashtab_obstack_allocate
,
16603 dummy_obstack_deallocate
);
16605 part_die
= XOBNEW (&cu
->comp_unit_obstack
, struct partial_die_info
);
16609 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
16611 /* A NULL abbrev means the end of a series of children. */
16612 if (abbrev
== NULL
)
16614 if (--nesting_level
== 0)
16616 /* PART_DIE was probably the last thing allocated on the
16617 comp_unit_obstack, so we could call obstack_free
16618 here. We don't do that because the waste is small,
16619 and will be cleaned up when we're done with this
16620 compilation unit. This way, we're also more robust
16621 against other users of the comp_unit_obstack. */
16624 info_ptr
+= bytes_read
;
16625 last_die
= parent_die
;
16626 parent_die
= parent_die
->die_parent
;
16630 /* Check for template arguments. We never save these; if
16631 they're seen, we just mark the parent, and go on our way. */
16632 if (parent_die
!= NULL
16633 && cu
->language
== language_cplus
16634 && (abbrev
->tag
== DW_TAG_template_type_param
16635 || abbrev
->tag
== DW_TAG_template_value_param
))
16637 parent_die
->has_template_arguments
= 1;
16641 /* We don't need a partial DIE for the template argument. */
16642 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
16647 /* We only recurse into c++ subprograms looking for template arguments.
16648 Skip their other children. */
16650 && cu
->language
== language_cplus
16651 && parent_die
!= NULL
16652 && parent_die
->tag
== DW_TAG_subprogram
)
16654 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
16658 /* Check whether this DIE is interesting enough to save. Normally
16659 we would not be interested in members here, but there may be
16660 later variables referencing them via DW_AT_specification (for
16661 static members). */
16663 && !is_type_tag_for_partial (abbrev
->tag
)
16664 && abbrev
->tag
!= DW_TAG_constant
16665 && abbrev
->tag
!= DW_TAG_enumerator
16666 && abbrev
->tag
!= DW_TAG_subprogram
16667 && abbrev
->tag
!= DW_TAG_lexical_block
16668 && abbrev
->tag
!= DW_TAG_variable
16669 && abbrev
->tag
!= DW_TAG_namespace
16670 && abbrev
->tag
!= DW_TAG_module
16671 && abbrev
->tag
!= DW_TAG_member
16672 && abbrev
->tag
!= DW_TAG_imported_unit
16673 && abbrev
->tag
!= DW_TAG_imported_declaration
)
16675 /* Otherwise we skip to the next sibling, if any. */
16676 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
16680 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
16683 /* This two-pass algorithm for processing partial symbols has a
16684 high cost in cache pressure. Thus, handle some simple cases
16685 here which cover the majority of C partial symbols. DIEs
16686 which neither have specification tags in them, nor could have
16687 specification tags elsewhere pointing at them, can simply be
16688 processed and discarded.
16690 This segment is also optional; scan_partial_symbols and
16691 add_partial_symbol will handle these DIEs if we chain
16692 them in normally. When compilers which do not emit large
16693 quantities of duplicate debug information are more common,
16694 this code can probably be removed. */
16696 /* Any complete simple types at the top level (pretty much all
16697 of them, for a language without namespaces), can be processed
16699 if (parent_die
== NULL
16700 && part_die
->has_specification
== 0
16701 && part_die
->is_declaration
== 0
16702 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
16703 || part_die
->tag
== DW_TAG_base_type
16704 || part_die
->tag
== DW_TAG_subrange_type
))
16706 if (building_psymtab
&& part_die
->name
!= NULL
)
16707 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
16708 VAR_DOMAIN
, LOC_TYPEDEF
,
16709 &objfile
->static_psymbols
,
16710 0, cu
->language
, objfile
);
16711 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
16715 /* The exception for DW_TAG_typedef with has_children above is
16716 a workaround of GCC PR debug/47510. In the case of this complaint
16717 type_name_no_tag_or_error will error on such types later.
16719 GDB skipped children of DW_TAG_typedef by the shortcut above and then
16720 it could not find the child DIEs referenced later, this is checked
16721 above. In correct DWARF DW_TAG_typedef should have no children. */
16723 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
16724 complaint (&symfile_complaints
,
16725 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
16726 "- DIE at 0x%x [in module %s]"),
16727 to_underlying (part_die
->sect_off
), objfile_name (objfile
));
16729 /* If we're at the second level, and we're an enumerator, and
16730 our parent has no specification (meaning possibly lives in a
16731 namespace elsewhere), then we can add the partial symbol now
16732 instead of queueing it. */
16733 if (part_die
->tag
== DW_TAG_enumerator
16734 && parent_die
!= NULL
16735 && parent_die
->die_parent
== NULL
16736 && parent_die
->tag
== DW_TAG_enumeration_type
16737 && parent_die
->has_specification
== 0)
16739 if (part_die
->name
== NULL
)
16740 complaint (&symfile_complaints
,
16741 _("malformed enumerator DIE ignored"));
16742 else if (building_psymtab
)
16743 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
16744 VAR_DOMAIN
, LOC_CONST
,
16745 cu
->language
== language_cplus
16746 ? &objfile
->global_psymbols
16747 : &objfile
->static_psymbols
,
16748 0, cu
->language
, objfile
);
16750 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
16754 /* We'll save this DIE so link it in. */
16755 part_die
->die_parent
= parent_die
;
16756 part_die
->die_sibling
= NULL
;
16757 part_die
->die_child
= NULL
;
16759 if (last_die
&& last_die
== parent_die
)
16760 last_die
->die_child
= part_die
;
16762 last_die
->die_sibling
= part_die
;
16764 last_die
= part_die
;
16766 if (first_die
== NULL
)
16767 first_die
= part_die
;
16769 /* Maybe add the DIE to the hash table. Not all DIEs that we
16770 find interesting need to be in the hash table, because we
16771 also have the parent/sibling/child chains; only those that we
16772 might refer to by offset later during partial symbol reading.
16774 For now this means things that might have be the target of a
16775 DW_AT_specification, DW_AT_abstract_origin, or
16776 DW_AT_extension. DW_AT_extension will refer only to
16777 namespaces; DW_AT_abstract_origin refers to functions (and
16778 many things under the function DIE, but we do not recurse
16779 into function DIEs during partial symbol reading) and
16780 possibly variables as well; DW_AT_specification refers to
16781 declarations. Declarations ought to have the DW_AT_declaration
16782 flag. It happens that GCC forgets to put it in sometimes, but
16783 only for functions, not for types.
16785 Adding more things than necessary to the hash table is harmless
16786 except for the performance cost. Adding too few will result in
16787 wasted time in find_partial_die, when we reread the compilation
16788 unit with load_all_dies set. */
16791 || abbrev
->tag
== DW_TAG_constant
16792 || abbrev
->tag
== DW_TAG_subprogram
16793 || abbrev
->tag
== DW_TAG_variable
16794 || abbrev
->tag
== DW_TAG_namespace
16795 || part_die
->is_declaration
)
16799 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
16800 to_underlying (part_die
->sect_off
),
16805 part_die
= XOBNEW (&cu
->comp_unit_obstack
, struct partial_die_info
);
16807 /* For some DIEs we want to follow their children (if any). For C
16808 we have no reason to follow the children of structures; for other
16809 languages we have to, so that we can get at method physnames
16810 to infer fully qualified class names, for DW_AT_specification,
16811 and for C++ template arguments. For C++, we also look one level
16812 inside functions to find template arguments (if the name of the
16813 function does not already contain the template arguments).
16815 For Ada, we need to scan the children of subprograms and lexical
16816 blocks as well because Ada allows the definition of nested
16817 entities that could be interesting for the debugger, such as
16818 nested subprograms for instance. */
16819 if (last_die
->has_children
16821 || last_die
->tag
== DW_TAG_namespace
16822 || last_die
->tag
== DW_TAG_module
16823 || last_die
->tag
== DW_TAG_enumeration_type
16824 || (cu
->language
== language_cplus
16825 && last_die
->tag
== DW_TAG_subprogram
16826 && (last_die
->name
== NULL
16827 || strchr (last_die
->name
, '<') == NULL
))
16828 || (cu
->language
!= language_c
16829 && (last_die
->tag
== DW_TAG_class_type
16830 || last_die
->tag
== DW_TAG_interface_type
16831 || last_die
->tag
== DW_TAG_structure_type
16832 || last_die
->tag
== DW_TAG_union_type
))
16833 || (cu
->language
== language_ada
16834 && (last_die
->tag
== DW_TAG_subprogram
16835 || last_die
->tag
== DW_TAG_lexical_block
))))
16838 parent_die
= last_die
;
16842 /* Otherwise we skip to the next sibling, if any. */
16843 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
16845 /* Back to the top, do it again. */
16849 /* Read a minimal amount of information into the minimal die structure. */
16851 static const gdb_byte
*
16852 read_partial_die (const struct die_reader_specs
*reader
,
16853 struct partial_die_info
*part_die
,
16854 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
16855 const gdb_byte
*info_ptr
)
16857 struct dwarf2_cu
*cu
= reader
->cu
;
16858 struct objfile
*objfile
= cu
->objfile
;
16859 const gdb_byte
*buffer
= reader
->buffer
;
16861 struct attribute attr
;
16862 int has_low_pc_attr
= 0;
16863 int has_high_pc_attr
= 0;
16864 int high_pc_relative
= 0;
16866 memset (part_die
, 0, sizeof (struct partial_die_info
));
16868 part_die
->sect_off
= (sect_offset
) (info_ptr
- buffer
);
16870 info_ptr
+= abbrev_len
;
16872 if (abbrev
== NULL
)
16875 part_die
->tag
= abbrev
->tag
;
16876 part_die
->has_children
= abbrev
->has_children
;
16878 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
16880 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
16882 /* Store the data if it is of an attribute we want to keep in a
16883 partial symbol table. */
16887 switch (part_die
->tag
)
16889 case DW_TAG_compile_unit
:
16890 case DW_TAG_partial_unit
:
16891 case DW_TAG_type_unit
:
16892 /* Compilation units have a DW_AT_name that is a filename, not
16893 a source language identifier. */
16894 case DW_TAG_enumeration_type
:
16895 case DW_TAG_enumerator
:
16896 /* These tags always have simple identifiers already; no need
16897 to canonicalize them. */
16898 part_die
->name
= DW_STRING (&attr
);
16902 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
16903 &objfile
->per_bfd
->storage_obstack
);
16907 case DW_AT_linkage_name
:
16908 case DW_AT_MIPS_linkage_name
:
16909 /* Note that both forms of linkage name might appear. We
16910 assume they will be the same, and we only store the last
16912 if (cu
->language
== language_ada
)
16913 part_die
->name
= DW_STRING (&attr
);
16914 part_die
->linkage_name
= DW_STRING (&attr
);
16917 has_low_pc_attr
= 1;
16918 part_die
->lowpc
= attr_value_as_address (&attr
);
16920 case DW_AT_high_pc
:
16921 has_high_pc_attr
= 1;
16922 part_die
->highpc
= attr_value_as_address (&attr
);
16923 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
16924 high_pc_relative
= 1;
16926 case DW_AT_location
:
16927 /* Support the .debug_loc offsets. */
16928 if (attr_form_is_block (&attr
))
16930 part_die
->d
.locdesc
= DW_BLOCK (&attr
);
16932 else if (attr_form_is_section_offset (&attr
))
16934 dwarf2_complex_location_expr_complaint ();
16938 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16939 "partial symbol information");
16942 case DW_AT_external
:
16943 part_die
->is_external
= DW_UNSND (&attr
);
16945 case DW_AT_declaration
:
16946 part_die
->is_declaration
= DW_UNSND (&attr
);
16949 part_die
->has_type
= 1;
16951 case DW_AT_abstract_origin
:
16952 case DW_AT_specification
:
16953 case DW_AT_extension
:
16954 part_die
->has_specification
= 1;
16955 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
16956 part_die
->spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
16957 || cu
->per_cu
->is_dwz
);
16959 case DW_AT_sibling
:
16960 /* Ignore absolute siblings, they might point outside of
16961 the current compile unit. */
16962 if (attr
.form
== DW_FORM_ref_addr
)
16963 complaint (&symfile_complaints
,
16964 _("ignoring absolute DW_AT_sibling"));
16967 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
16968 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
16970 if (sibling_ptr
< info_ptr
)
16971 complaint (&symfile_complaints
,
16972 _("DW_AT_sibling points backwards"));
16973 else if (sibling_ptr
> reader
->buffer_end
)
16974 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
16976 part_die
->sibling
= sibling_ptr
;
16979 case DW_AT_byte_size
:
16980 part_die
->has_byte_size
= 1;
16982 case DW_AT_const_value
:
16983 part_die
->has_const_value
= 1;
16985 case DW_AT_calling_convention
:
16986 /* DWARF doesn't provide a way to identify a program's source-level
16987 entry point. DW_AT_calling_convention attributes are only meant
16988 to describe functions' calling conventions.
16990 However, because it's a necessary piece of information in
16991 Fortran, and before DWARF 4 DW_CC_program was the only
16992 piece of debugging information whose definition refers to
16993 a 'main program' at all, several compilers marked Fortran
16994 main programs with DW_CC_program --- even when those
16995 functions use the standard calling conventions.
16997 Although DWARF now specifies a way to provide this
16998 information, we support this practice for backward
17000 if (DW_UNSND (&attr
) == DW_CC_program
17001 && cu
->language
== language_fortran
)
17002 part_die
->main_subprogram
= 1;
17005 if (DW_UNSND (&attr
) == DW_INL_inlined
17006 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
17007 part_die
->may_be_inlined
= 1;
17011 if (part_die
->tag
== DW_TAG_imported_unit
)
17013 part_die
->d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
17014 part_die
->is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
17015 || cu
->per_cu
->is_dwz
);
17019 case DW_AT_main_subprogram
:
17020 part_die
->main_subprogram
= DW_UNSND (&attr
);
17028 if (high_pc_relative
)
17029 part_die
->highpc
+= part_die
->lowpc
;
17031 if (has_low_pc_attr
&& has_high_pc_attr
)
17033 /* When using the GNU linker, .gnu.linkonce. sections are used to
17034 eliminate duplicate copies of functions and vtables and such.
17035 The linker will arbitrarily choose one and discard the others.
17036 The AT_*_pc values for such functions refer to local labels in
17037 these sections. If the section from that file was discarded, the
17038 labels are not in the output, so the relocs get a value of 0.
17039 If this is a discarded function, mark the pc bounds as invalid,
17040 so that GDB will ignore it. */
17041 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
17043 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17045 complaint (&symfile_complaints
,
17046 _("DW_AT_low_pc %s is zero "
17047 "for DIE at 0x%x [in module %s]"),
17048 paddress (gdbarch
, part_die
->lowpc
),
17049 to_underlying (part_die
->sect_off
), objfile_name (objfile
));
17051 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
17052 else if (part_die
->lowpc
>= part_die
->highpc
)
17054 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17056 complaint (&symfile_complaints
,
17057 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
17058 "for DIE at 0x%x [in module %s]"),
17059 paddress (gdbarch
, part_die
->lowpc
),
17060 paddress (gdbarch
, part_die
->highpc
),
17061 to_underlying (part_die
->sect_off
),
17062 objfile_name (objfile
));
17065 part_die
->has_pc_info
= 1;
17071 /* Find a cached partial DIE at OFFSET in CU. */
17073 static struct partial_die_info
*
17074 find_partial_die_in_comp_unit (sect_offset sect_off
, struct dwarf2_cu
*cu
)
17076 struct partial_die_info
*lookup_die
= NULL
;
17077 struct partial_die_info part_die
;
17079 part_die
.sect_off
= sect_off
;
17080 lookup_die
= ((struct partial_die_info
*)
17081 htab_find_with_hash (cu
->partial_dies
, &part_die
,
17082 to_underlying (sect_off
)));
17087 /* Find a partial DIE at OFFSET, which may or may not be in CU,
17088 except in the case of .debug_types DIEs which do not reference
17089 outside their CU (they do however referencing other types via
17090 DW_FORM_ref_sig8). */
17092 static struct partial_die_info
*
17093 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
17095 struct objfile
*objfile
= cu
->objfile
;
17096 struct dwarf2_per_cu_data
*per_cu
= NULL
;
17097 struct partial_die_info
*pd
= NULL
;
17099 if (offset_in_dwz
== cu
->per_cu
->is_dwz
17100 && offset_in_cu_p (&cu
->header
, sect_off
))
17102 pd
= find_partial_die_in_comp_unit (sect_off
, cu
);
17105 /* We missed recording what we needed.
17106 Load all dies and try again. */
17107 per_cu
= cu
->per_cu
;
17111 /* TUs don't reference other CUs/TUs (except via type signatures). */
17112 if (cu
->per_cu
->is_debug_types
)
17114 error (_("Dwarf Error: Type Unit at offset 0x%x contains"
17115 " external reference to offset 0x%x [in module %s].\n"),
17116 to_underlying (cu
->header
.sect_off
), to_underlying (sect_off
),
17117 bfd_get_filename (objfile
->obfd
));
17119 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
17122 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
17123 load_partial_comp_unit (per_cu
);
17125 per_cu
->cu
->last_used
= 0;
17126 pd
= find_partial_die_in_comp_unit (sect_off
, per_cu
->cu
);
17129 /* If we didn't find it, and not all dies have been loaded,
17130 load them all and try again. */
17132 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
17134 per_cu
->load_all_dies
= 1;
17136 /* This is nasty. When we reread the DIEs, somewhere up the call chain
17137 THIS_CU->cu may already be in use. So we can't just free it and
17138 replace its DIEs with the ones we read in. Instead, we leave those
17139 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
17140 and clobber THIS_CU->cu->partial_dies with the hash table for the new
17142 load_partial_comp_unit (per_cu
);
17144 pd
= find_partial_die_in_comp_unit (sect_off
, per_cu
->cu
);
17148 internal_error (__FILE__
, __LINE__
,
17149 _("could not find partial DIE 0x%x "
17150 "in cache [from module %s]\n"),
17151 to_underlying (sect_off
), bfd_get_filename (objfile
->obfd
));
17155 /* See if we can figure out if the class lives in a namespace. We do
17156 this by looking for a member function; its demangled name will
17157 contain namespace info, if there is any. */
17160 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
17161 struct dwarf2_cu
*cu
)
17163 /* NOTE: carlton/2003-10-07: Getting the info this way changes
17164 what template types look like, because the demangler
17165 frequently doesn't give the same name as the debug info. We
17166 could fix this by only using the demangled name to get the
17167 prefix (but see comment in read_structure_type). */
17169 struct partial_die_info
*real_pdi
;
17170 struct partial_die_info
*child_pdi
;
17172 /* If this DIE (this DIE's specification, if any) has a parent, then
17173 we should not do this. We'll prepend the parent's fully qualified
17174 name when we create the partial symbol. */
17176 real_pdi
= struct_pdi
;
17177 while (real_pdi
->has_specification
)
17178 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
17179 real_pdi
->spec_is_dwz
, cu
);
17181 if (real_pdi
->die_parent
!= NULL
)
17184 for (child_pdi
= struct_pdi
->die_child
;
17186 child_pdi
= child_pdi
->die_sibling
)
17188 if (child_pdi
->tag
== DW_TAG_subprogram
17189 && child_pdi
->linkage_name
!= NULL
)
17191 char *actual_class_name
17192 = language_class_name_from_physname (cu
->language_defn
,
17193 child_pdi
->linkage_name
);
17194 if (actual_class_name
!= NULL
)
17198 obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
17200 strlen (actual_class_name
)));
17201 xfree (actual_class_name
);
17208 /* Adjust PART_DIE before generating a symbol for it. This function
17209 may set the is_external flag or change the DIE's name. */
17212 fixup_partial_die (struct partial_die_info
*part_die
,
17213 struct dwarf2_cu
*cu
)
17215 /* Once we've fixed up a die, there's no point in doing so again.
17216 This also avoids a memory leak if we were to call
17217 guess_partial_die_structure_name multiple times. */
17218 if (part_die
->fixup_called
)
17221 /* If we found a reference attribute and the DIE has no name, try
17222 to find a name in the referred to DIE. */
17224 if (part_die
->name
== NULL
&& part_die
->has_specification
)
17226 struct partial_die_info
*spec_die
;
17228 spec_die
= find_partial_die (part_die
->spec_offset
,
17229 part_die
->spec_is_dwz
, cu
);
17231 fixup_partial_die (spec_die
, cu
);
17233 if (spec_die
->name
)
17235 part_die
->name
= spec_die
->name
;
17237 /* Copy DW_AT_external attribute if it is set. */
17238 if (spec_die
->is_external
)
17239 part_die
->is_external
= spec_die
->is_external
;
17243 /* Set default names for some unnamed DIEs. */
17245 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
17246 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
17248 /* If there is no parent die to provide a namespace, and there are
17249 children, see if we can determine the namespace from their linkage
17251 if (cu
->language
== language_cplus
17252 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
17253 && part_die
->die_parent
== NULL
17254 && part_die
->has_children
17255 && (part_die
->tag
== DW_TAG_class_type
17256 || part_die
->tag
== DW_TAG_structure_type
17257 || part_die
->tag
== DW_TAG_union_type
))
17258 guess_partial_die_structure_name (part_die
, cu
);
17260 /* GCC might emit a nameless struct or union that has a linkage
17261 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
17262 if (part_die
->name
== NULL
17263 && (part_die
->tag
== DW_TAG_class_type
17264 || part_die
->tag
== DW_TAG_interface_type
17265 || part_die
->tag
== DW_TAG_structure_type
17266 || part_die
->tag
== DW_TAG_union_type
)
17267 && part_die
->linkage_name
!= NULL
)
17271 demangled
= gdb_demangle (part_die
->linkage_name
, DMGL_TYPES
);
17276 /* Strip any leading namespaces/classes, keep only the base name.
17277 DW_AT_name for named DIEs does not contain the prefixes. */
17278 base
= strrchr (demangled
, ':');
17279 if (base
&& base
> demangled
&& base
[-1] == ':')
17286 obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
17287 base
, strlen (base
)));
17292 part_die
->fixup_called
= 1;
17295 /* Read an attribute value described by an attribute form. */
17297 static const gdb_byte
*
17298 read_attribute_value (const struct die_reader_specs
*reader
,
17299 struct attribute
*attr
, unsigned form
,
17300 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
17302 struct dwarf2_cu
*cu
= reader
->cu
;
17303 struct objfile
*objfile
= cu
->objfile
;
17304 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17305 bfd
*abfd
= reader
->abfd
;
17306 struct comp_unit_head
*cu_header
= &cu
->header
;
17307 unsigned int bytes_read
;
17308 struct dwarf_block
*blk
;
17310 attr
->form
= (enum dwarf_form
) form
;
17313 case DW_FORM_ref_addr
:
17314 if (cu
->header
.version
== 2)
17315 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
17317 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
17318 &cu
->header
, &bytes_read
);
17319 info_ptr
+= bytes_read
;
17321 case DW_FORM_GNU_ref_alt
:
17322 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
17323 info_ptr
+= bytes_read
;
17326 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
17327 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
17328 info_ptr
+= bytes_read
;
17330 case DW_FORM_block2
:
17331 blk
= dwarf_alloc_block (cu
);
17332 blk
->size
= read_2_bytes (abfd
, info_ptr
);
17334 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
17335 info_ptr
+= blk
->size
;
17336 DW_BLOCK (attr
) = blk
;
17338 case DW_FORM_block4
:
17339 blk
= dwarf_alloc_block (cu
);
17340 blk
->size
= read_4_bytes (abfd
, info_ptr
);
17342 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
17343 info_ptr
+= blk
->size
;
17344 DW_BLOCK (attr
) = blk
;
17346 case DW_FORM_data2
:
17347 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
17350 case DW_FORM_data4
:
17351 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
17354 case DW_FORM_data8
:
17355 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
17358 case DW_FORM_data16
:
17359 blk
= dwarf_alloc_block (cu
);
17361 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
17363 DW_BLOCK (attr
) = blk
;
17365 case DW_FORM_sec_offset
:
17366 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
17367 info_ptr
+= bytes_read
;
17369 case DW_FORM_string
:
17370 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
17371 DW_STRING_IS_CANONICAL (attr
) = 0;
17372 info_ptr
+= bytes_read
;
17375 if (!cu
->per_cu
->is_dwz
)
17377 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
17379 DW_STRING_IS_CANONICAL (attr
) = 0;
17380 info_ptr
+= bytes_read
;
17384 case DW_FORM_line_strp
:
17385 if (!cu
->per_cu
->is_dwz
)
17387 DW_STRING (attr
) = read_indirect_line_string (abfd
, info_ptr
,
17388 cu_header
, &bytes_read
);
17389 DW_STRING_IS_CANONICAL (attr
) = 0;
17390 info_ptr
+= bytes_read
;
17394 case DW_FORM_GNU_strp_alt
:
17396 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
17397 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
17400 DW_STRING (attr
) = read_indirect_string_from_dwz (dwz
, str_offset
);
17401 DW_STRING_IS_CANONICAL (attr
) = 0;
17402 info_ptr
+= bytes_read
;
17405 case DW_FORM_exprloc
:
17406 case DW_FORM_block
:
17407 blk
= dwarf_alloc_block (cu
);
17408 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17409 info_ptr
+= bytes_read
;
17410 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
17411 info_ptr
+= blk
->size
;
17412 DW_BLOCK (attr
) = blk
;
17414 case DW_FORM_block1
:
17415 blk
= dwarf_alloc_block (cu
);
17416 blk
->size
= read_1_byte (abfd
, info_ptr
);
17418 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
17419 info_ptr
+= blk
->size
;
17420 DW_BLOCK (attr
) = blk
;
17422 case DW_FORM_data1
:
17423 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
17427 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
17430 case DW_FORM_flag_present
:
17431 DW_UNSND (attr
) = 1;
17433 case DW_FORM_sdata
:
17434 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
17435 info_ptr
+= bytes_read
;
17437 case DW_FORM_udata
:
17438 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17439 info_ptr
+= bytes_read
;
17442 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
17443 + read_1_byte (abfd
, info_ptr
));
17447 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
17448 + read_2_bytes (abfd
, info_ptr
));
17452 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
17453 + read_4_bytes (abfd
, info_ptr
));
17457 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
17458 + read_8_bytes (abfd
, info_ptr
));
17461 case DW_FORM_ref_sig8
:
17462 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
17465 case DW_FORM_ref_udata
:
17466 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
17467 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
17468 info_ptr
+= bytes_read
;
17470 case DW_FORM_indirect
:
17471 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17472 info_ptr
+= bytes_read
;
17473 if (form
== DW_FORM_implicit_const
)
17475 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
17476 info_ptr
+= bytes_read
;
17478 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
17481 case DW_FORM_implicit_const
:
17482 DW_SND (attr
) = implicit_const
;
17484 case DW_FORM_GNU_addr_index
:
17485 if (reader
->dwo_file
== NULL
)
17487 /* For now flag a hard error.
17488 Later we can turn this into a complaint. */
17489 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
17490 dwarf_form_name (form
),
17491 bfd_get_filename (abfd
));
17493 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
17494 info_ptr
+= bytes_read
;
17496 case DW_FORM_GNU_str_index
:
17497 if (reader
->dwo_file
== NULL
)
17499 /* For now flag a hard error.
17500 Later we can turn this into a complaint if warranted. */
17501 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
17502 dwarf_form_name (form
),
17503 bfd_get_filename (abfd
));
17506 ULONGEST str_index
=
17507 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17509 DW_STRING (attr
) = read_str_index (reader
, str_index
);
17510 DW_STRING_IS_CANONICAL (attr
) = 0;
17511 info_ptr
+= bytes_read
;
17515 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
17516 dwarf_form_name (form
),
17517 bfd_get_filename (abfd
));
17521 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
17522 attr
->form
= DW_FORM_GNU_ref_alt
;
17524 /* We have seen instances where the compiler tried to emit a byte
17525 size attribute of -1 which ended up being encoded as an unsigned
17526 0xffffffff. Although 0xffffffff is technically a valid size value,
17527 an object of this size seems pretty unlikely so we can relatively
17528 safely treat these cases as if the size attribute was invalid and
17529 treat them as zero by default. */
17530 if (attr
->name
== DW_AT_byte_size
17531 && form
== DW_FORM_data4
17532 && DW_UNSND (attr
) >= 0xffffffff)
17535 (&symfile_complaints
,
17536 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
17537 hex_string (DW_UNSND (attr
)));
17538 DW_UNSND (attr
) = 0;
17544 /* Read an attribute described by an abbreviated attribute. */
17546 static const gdb_byte
*
17547 read_attribute (const struct die_reader_specs
*reader
,
17548 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
17549 const gdb_byte
*info_ptr
)
17551 attr
->name
= abbrev
->name
;
17552 return read_attribute_value (reader
, attr
, abbrev
->form
,
17553 abbrev
->implicit_const
, info_ptr
);
17556 /* Read dwarf information from a buffer. */
17558 static unsigned int
17559 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
17561 return bfd_get_8 (abfd
, buf
);
17565 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
17567 return bfd_get_signed_8 (abfd
, buf
);
17570 static unsigned int
17571 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
17573 return bfd_get_16 (abfd
, buf
);
17577 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
17579 return bfd_get_signed_16 (abfd
, buf
);
17582 static unsigned int
17583 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
17585 return bfd_get_32 (abfd
, buf
);
17589 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
17591 return bfd_get_signed_32 (abfd
, buf
);
17595 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
17597 return bfd_get_64 (abfd
, buf
);
17601 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
17602 unsigned int *bytes_read
)
17604 struct comp_unit_head
*cu_header
= &cu
->header
;
17605 CORE_ADDR retval
= 0;
17607 if (cu_header
->signed_addr_p
)
17609 switch (cu_header
->addr_size
)
17612 retval
= bfd_get_signed_16 (abfd
, buf
);
17615 retval
= bfd_get_signed_32 (abfd
, buf
);
17618 retval
= bfd_get_signed_64 (abfd
, buf
);
17621 internal_error (__FILE__
, __LINE__
,
17622 _("read_address: bad switch, signed [in module %s]"),
17623 bfd_get_filename (abfd
));
17628 switch (cu_header
->addr_size
)
17631 retval
= bfd_get_16 (abfd
, buf
);
17634 retval
= bfd_get_32 (abfd
, buf
);
17637 retval
= bfd_get_64 (abfd
, buf
);
17640 internal_error (__FILE__
, __LINE__
,
17641 _("read_address: bad switch, "
17642 "unsigned [in module %s]"),
17643 bfd_get_filename (abfd
));
17647 *bytes_read
= cu_header
->addr_size
;
17651 /* Read the initial length from a section. The (draft) DWARF 3
17652 specification allows the initial length to take up either 4 bytes
17653 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
17654 bytes describe the length and all offsets will be 8 bytes in length
17657 An older, non-standard 64-bit format is also handled by this
17658 function. The older format in question stores the initial length
17659 as an 8-byte quantity without an escape value. Lengths greater
17660 than 2^32 aren't very common which means that the initial 4 bytes
17661 is almost always zero. Since a length value of zero doesn't make
17662 sense for the 32-bit format, this initial zero can be considered to
17663 be an escape value which indicates the presence of the older 64-bit
17664 format. As written, the code can't detect (old format) lengths
17665 greater than 4GB. If it becomes necessary to handle lengths
17666 somewhat larger than 4GB, we could allow other small values (such
17667 as the non-sensical values of 1, 2, and 3) to also be used as
17668 escape values indicating the presence of the old format.
17670 The value returned via bytes_read should be used to increment the
17671 relevant pointer after calling read_initial_length().
17673 [ Note: read_initial_length() and read_offset() are based on the
17674 document entitled "DWARF Debugging Information Format", revision
17675 3, draft 8, dated November 19, 2001. This document was obtained
17678 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
17680 This document is only a draft and is subject to change. (So beware.)
17682 Details regarding the older, non-standard 64-bit format were
17683 determined empirically by examining 64-bit ELF files produced by
17684 the SGI toolchain on an IRIX 6.5 machine.
17686 - Kevin, July 16, 2002
17690 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
17692 LONGEST length
= bfd_get_32 (abfd
, buf
);
17694 if (length
== 0xffffffff)
17696 length
= bfd_get_64 (abfd
, buf
+ 4);
17699 else if (length
== 0)
17701 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
17702 length
= bfd_get_64 (abfd
, buf
);
17713 /* Cover function for read_initial_length.
17714 Returns the length of the object at BUF, and stores the size of the
17715 initial length in *BYTES_READ and stores the size that offsets will be in
17717 If the initial length size is not equivalent to that specified in
17718 CU_HEADER then issue a complaint.
17719 This is useful when reading non-comp-unit headers. */
17722 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
17723 const struct comp_unit_head
*cu_header
,
17724 unsigned int *bytes_read
,
17725 unsigned int *offset_size
)
17727 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
17729 gdb_assert (cu_header
->initial_length_size
== 4
17730 || cu_header
->initial_length_size
== 8
17731 || cu_header
->initial_length_size
== 12);
17733 if (cu_header
->initial_length_size
!= *bytes_read
)
17734 complaint (&symfile_complaints
,
17735 _("intermixed 32-bit and 64-bit DWARF sections"));
17737 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
17741 /* Read an offset from the data stream. The size of the offset is
17742 given by cu_header->offset_size. */
17745 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
17746 const struct comp_unit_head
*cu_header
,
17747 unsigned int *bytes_read
)
17749 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
17751 *bytes_read
= cu_header
->offset_size
;
17755 /* Read an offset from the data stream. */
17758 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
17760 LONGEST retval
= 0;
17762 switch (offset_size
)
17765 retval
= bfd_get_32 (abfd
, buf
);
17768 retval
= bfd_get_64 (abfd
, buf
);
17771 internal_error (__FILE__
, __LINE__
,
17772 _("read_offset_1: bad switch [in module %s]"),
17773 bfd_get_filename (abfd
));
17779 static const gdb_byte
*
17780 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
17782 /* If the size of a host char is 8 bits, we can return a pointer
17783 to the buffer, otherwise we have to copy the data to a buffer
17784 allocated on the temporary obstack. */
17785 gdb_assert (HOST_CHAR_BIT
== 8);
17789 static const char *
17790 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
17791 unsigned int *bytes_read_ptr
)
17793 /* If the size of a host char is 8 bits, we can return a pointer
17794 to the string, otherwise we have to copy the string to a buffer
17795 allocated on the temporary obstack. */
17796 gdb_assert (HOST_CHAR_BIT
== 8);
17799 *bytes_read_ptr
= 1;
17802 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
17803 return (const char *) buf
;
17806 /* Return pointer to string at section SECT offset STR_OFFSET with error
17807 reporting strings FORM_NAME and SECT_NAME. */
17809 static const char *
17810 read_indirect_string_at_offset_from (bfd
*abfd
, LONGEST str_offset
,
17811 struct dwarf2_section_info
*sect
,
17812 const char *form_name
,
17813 const char *sect_name
)
17815 dwarf2_read_section (dwarf2_per_objfile
->objfile
, sect
);
17816 if (sect
->buffer
== NULL
)
17817 error (_("%s used without %s section [in module %s]"),
17818 form_name
, sect_name
, bfd_get_filename (abfd
));
17819 if (str_offset
>= sect
->size
)
17820 error (_("%s pointing outside of %s section [in module %s]"),
17821 form_name
, sect_name
, bfd_get_filename (abfd
));
17822 gdb_assert (HOST_CHAR_BIT
== 8);
17823 if (sect
->buffer
[str_offset
] == '\0')
17825 return (const char *) (sect
->buffer
+ str_offset
);
17828 /* Return pointer to string at .debug_str offset STR_OFFSET. */
17830 static const char *
17831 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
17833 return read_indirect_string_at_offset_from (abfd
, str_offset
,
17834 &dwarf2_per_objfile
->str
,
17835 "DW_FORM_strp", ".debug_str");
17838 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
17840 static const char *
17841 read_indirect_line_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
17843 return read_indirect_string_at_offset_from (abfd
, str_offset
,
17844 &dwarf2_per_objfile
->line_str
,
17845 "DW_FORM_line_strp",
17846 ".debug_line_str");
17849 /* Read a string at offset STR_OFFSET in the .debug_str section from
17850 the .dwz file DWZ. Throw an error if the offset is too large. If
17851 the string consists of a single NUL byte, return NULL; otherwise
17852 return a pointer to the string. */
17854 static const char *
17855 read_indirect_string_from_dwz (struct dwz_file
*dwz
, LONGEST str_offset
)
17857 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwz
->str
);
17859 if (dwz
->str
.buffer
== NULL
)
17860 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
17861 "section [in module %s]"),
17862 bfd_get_filename (dwz
->dwz_bfd
));
17863 if (str_offset
>= dwz
->str
.size
)
17864 error (_("DW_FORM_GNU_strp_alt pointing outside of "
17865 ".debug_str section [in module %s]"),
17866 bfd_get_filename (dwz
->dwz_bfd
));
17867 gdb_assert (HOST_CHAR_BIT
== 8);
17868 if (dwz
->str
.buffer
[str_offset
] == '\0')
17870 return (const char *) (dwz
->str
.buffer
+ str_offset
);
17873 /* Return pointer to string at .debug_str offset as read from BUF.
17874 BUF is assumed to be in a compilation unit described by CU_HEADER.
17875 Return *BYTES_READ_PTR count of bytes read from BUF. */
17877 static const char *
17878 read_indirect_string (bfd
*abfd
, const gdb_byte
*buf
,
17879 const struct comp_unit_head
*cu_header
,
17880 unsigned int *bytes_read_ptr
)
17882 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
17884 return read_indirect_string_at_offset (abfd
, str_offset
);
17887 /* Return pointer to string at .debug_line_str offset as read from BUF.
17888 BUF is assumed to be in a compilation unit described by CU_HEADER.
17889 Return *BYTES_READ_PTR count of bytes read from BUF. */
17891 static const char *
17892 read_indirect_line_string (bfd
*abfd
, const gdb_byte
*buf
,
17893 const struct comp_unit_head
*cu_header
,
17894 unsigned int *bytes_read_ptr
)
17896 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
17898 return read_indirect_line_string_at_offset (abfd
, str_offset
);
17902 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
17903 unsigned int *bytes_read_ptr
)
17906 unsigned int num_read
;
17908 unsigned char byte
;
17915 byte
= bfd_get_8 (abfd
, buf
);
17918 result
|= ((ULONGEST
) (byte
& 127) << shift
);
17919 if ((byte
& 128) == 0)
17925 *bytes_read_ptr
= num_read
;
17930 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
17931 unsigned int *bytes_read_ptr
)
17934 int shift
, num_read
;
17935 unsigned char byte
;
17942 byte
= bfd_get_8 (abfd
, buf
);
17945 result
|= ((LONGEST
) (byte
& 127) << shift
);
17947 if ((byte
& 128) == 0)
17952 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
17953 result
|= -(((LONGEST
) 1) << shift
);
17954 *bytes_read_ptr
= num_read
;
17958 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
17959 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
17960 ADDR_SIZE is the size of addresses from the CU header. */
17963 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
17965 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17966 bfd
*abfd
= objfile
->obfd
;
17967 const gdb_byte
*info_ptr
;
17969 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
17970 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
17971 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
17972 objfile_name (objfile
));
17973 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
17974 error (_("DW_FORM_addr_index pointing outside of "
17975 ".debug_addr section [in module %s]"),
17976 objfile_name (objfile
));
17977 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
17978 + addr_base
+ addr_index
* addr_size
);
17979 if (addr_size
== 4)
17980 return bfd_get_32 (abfd
, info_ptr
);
17982 return bfd_get_64 (abfd
, info_ptr
);
17985 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
17988 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
17990 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
17993 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
17996 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
17997 unsigned int *bytes_read
)
17999 bfd
*abfd
= cu
->objfile
->obfd
;
18000 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
18002 return read_addr_index (cu
, addr_index
);
18005 /* Data structure to pass results from dwarf2_read_addr_index_reader
18006 back to dwarf2_read_addr_index. */
18008 struct dwarf2_read_addr_index_data
18010 ULONGEST addr_base
;
18014 /* die_reader_func for dwarf2_read_addr_index. */
18017 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
18018 const gdb_byte
*info_ptr
,
18019 struct die_info
*comp_unit_die
,
18023 struct dwarf2_cu
*cu
= reader
->cu
;
18024 struct dwarf2_read_addr_index_data
*aidata
=
18025 (struct dwarf2_read_addr_index_data
*) data
;
18027 aidata
->addr_base
= cu
->addr_base
;
18028 aidata
->addr_size
= cu
->header
.addr_size
;
18031 /* Given an index in .debug_addr, fetch the value.
18032 NOTE: This can be called during dwarf expression evaluation,
18033 long after the debug information has been read, and thus per_cu->cu
18034 may no longer exist. */
18037 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
18038 unsigned int addr_index
)
18040 struct objfile
*objfile
= per_cu
->objfile
;
18041 struct dwarf2_cu
*cu
= per_cu
->cu
;
18042 ULONGEST addr_base
;
18045 /* This is intended to be called from outside this file. */
18046 dw2_setup (objfile
);
18048 /* We need addr_base and addr_size.
18049 If we don't have PER_CU->cu, we have to get it.
18050 Nasty, but the alternative is storing the needed info in PER_CU,
18051 which at this point doesn't seem justified: it's not clear how frequently
18052 it would get used and it would increase the size of every PER_CU.
18053 Entry points like dwarf2_per_cu_addr_size do a similar thing
18054 so we're not in uncharted territory here.
18055 Alas we need to be a bit more complicated as addr_base is contained
18058 We don't need to read the entire CU(/TU).
18059 We just need the header and top level die.
18061 IWBN to use the aging mechanism to let us lazily later discard the CU.
18062 For now we skip this optimization. */
18066 addr_base
= cu
->addr_base
;
18067 addr_size
= cu
->header
.addr_size
;
18071 struct dwarf2_read_addr_index_data aidata
;
18073 /* Note: We can't use init_cutu_and_read_dies_simple here,
18074 we need addr_base. */
18075 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
18076 dwarf2_read_addr_index_reader
, &aidata
);
18077 addr_base
= aidata
.addr_base
;
18078 addr_size
= aidata
.addr_size
;
18081 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
18084 /* Given a DW_FORM_GNU_str_index, fetch the string.
18085 This is only used by the Fission support. */
18087 static const char *
18088 read_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
18090 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18091 const char *objf_name
= objfile_name (objfile
);
18092 bfd
*abfd
= objfile
->obfd
;
18093 struct dwarf2_cu
*cu
= reader
->cu
;
18094 struct dwarf2_section_info
*str_section
= &reader
->dwo_file
->sections
.str
;
18095 struct dwarf2_section_info
*str_offsets_section
=
18096 &reader
->dwo_file
->sections
.str_offsets
;
18097 const gdb_byte
*info_ptr
;
18098 ULONGEST str_offset
;
18099 static const char form_name
[] = "DW_FORM_GNU_str_index";
18101 dwarf2_read_section (objfile
, str_section
);
18102 dwarf2_read_section (objfile
, str_offsets_section
);
18103 if (str_section
->buffer
== NULL
)
18104 error (_("%s used without .debug_str.dwo section"
18105 " in CU at offset 0x%x [in module %s]"),
18106 form_name
, to_underlying (cu
->header
.sect_off
), objf_name
);
18107 if (str_offsets_section
->buffer
== NULL
)
18108 error (_("%s used without .debug_str_offsets.dwo section"
18109 " in CU at offset 0x%x [in module %s]"),
18110 form_name
, to_underlying (cu
->header
.sect_off
), objf_name
);
18111 if (str_index
* cu
->header
.offset_size
>= str_offsets_section
->size
)
18112 error (_("%s pointing outside of .debug_str_offsets.dwo"
18113 " section in CU at offset 0x%x [in module %s]"),
18114 form_name
, to_underlying (cu
->header
.sect_off
), objf_name
);
18115 info_ptr
= (str_offsets_section
->buffer
18116 + str_index
* cu
->header
.offset_size
);
18117 if (cu
->header
.offset_size
== 4)
18118 str_offset
= bfd_get_32 (abfd
, info_ptr
);
18120 str_offset
= bfd_get_64 (abfd
, info_ptr
);
18121 if (str_offset
>= str_section
->size
)
18122 error (_("Offset from %s pointing outside of"
18123 " .debug_str.dwo section in CU at offset 0x%x [in module %s]"),
18124 form_name
, to_underlying (cu
->header
.sect_off
), objf_name
);
18125 return (const char *) (str_section
->buffer
+ str_offset
);
18128 /* Return the length of an LEB128 number in BUF. */
18131 leb128_size (const gdb_byte
*buf
)
18133 const gdb_byte
*begin
= buf
;
18139 if ((byte
& 128) == 0)
18140 return buf
- begin
;
18145 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
18154 cu
->language
= language_c
;
18157 case DW_LANG_C_plus_plus
:
18158 case DW_LANG_C_plus_plus_11
:
18159 case DW_LANG_C_plus_plus_14
:
18160 cu
->language
= language_cplus
;
18163 cu
->language
= language_d
;
18165 case DW_LANG_Fortran77
:
18166 case DW_LANG_Fortran90
:
18167 case DW_LANG_Fortran95
:
18168 case DW_LANG_Fortran03
:
18169 case DW_LANG_Fortran08
:
18170 cu
->language
= language_fortran
;
18173 cu
->language
= language_go
;
18175 case DW_LANG_Mips_Assembler
:
18176 cu
->language
= language_asm
;
18178 case DW_LANG_Ada83
:
18179 case DW_LANG_Ada95
:
18180 cu
->language
= language_ada
;
18182 case DW_LANG_Modula2
:
18183 cu
->language
= language_m2
;
18185 case DW_LANG_Pascal83
:
18186 cu
->language
= language_pascal
;
18189 cu
->language
= language_objc
;
18192 case DW_LANG_Rust_old
:
18193 cu
->language
= language_rust
;
18195 case DW_LANG_Cobol74
:
18196 case DW_LANG_Cobol85
:
18198 cu
->language
= language_minimal
;
18201 cu
->language_defn
= language_def (cu
->language
);
18204 /* Return the named attribute or NULL if not there. */
18206 static struct attribute
*
18207 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
18212 struct attribute
*spec
= NULL
;
18214 for (i
= 0; i
< die
->num_attrs
; ++i
)
18216 if (die
->attrs
[i
].name
== name
)
18217 return &die
->attrs
[i
];
18218 if (die
->attrs
[i
].name
== DW_AT_specification
18219 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
18220 spec
= &die
->attrs
[i
];
18226 die
= follow_die_ref (die
, spec
, &cu
);
18232 /* Return the named attribute or NULL if not there,
18233 but do not follow DW_AT_specification, etc.
18234 This is for use in contexts where we're reading .debug_types dies.
18235 Following DW_AT_specification, DW_AT_abstract_origin will take us
18236 back up the chain, and we want to go down. */
18238 static struct attribute
*
18239 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
18243 for (i
= 0; i
< die
->num_attrs
; ++i
)
18244 if (die
->attrs
[i
].name
== name
)
18245 return &die
->attrs
[i
];
18250 /* Return the string associated with a string-typed attribute, or NULL if it
18251 is either not found or is of an incorrect type. */
18253 static const char *
18254 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
18256 struct attribute
*attr
;
18257 const char *str
= NULL
;
18259 attr
= dwarf2_attr (die
, name
, cu
);
18263 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
18264 || attr
->form
== DW_FORM_string
18265 || attr
->form
== DW_FORM_GNU_str_index
18266 || attr
->form
== DW_FORM_GNU_strp_alt
)
18267 str
= DW_STRING (attr
);
18269 complaint (&symfile_complaints
,
18270 _("string type expected for attribute %s for "
18271 "DIE at 0x%x in module %s"),
18272 dwarf_attr_name (name
), to_underlying (die
->sect_off
),
18273 objfile_name (cu
->objfile
));
18279 /* Return non-zero iff the attribute NAME is defined for the given DIE,
18280 and holds a non-zero value. This function should only be used for
18281 DW_FORM_flag or DW_FORM_flag_present attributes. */
18284 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
18286 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
18288 return (attr
&& DW_UNSND (attr
));
18292 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
18294 /* A DIE is a declaration if it has a DW_AT_declaration attribute
18295 which value is non-zero. However, we have to be careful with
18296 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
18297 (via dwarf2_flag_true_p) follows this attribute. So we may
18298 end up accidently finding a declaration attribute that belongs
18299 to a different DIE referenced by the specification attribute,
18300 even though the given DIE does not have a declaration attribute. */
18301 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
18302 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
18305 /* Return the die giving the specification for DIE, if there is
18306 one. *SPEC_CU is the CU containing DIE on input, and the CU
18307 containing the return value on output. If there is no
18308 specification, but there is an abstract origin, that is
18311 static struct die_info
*
18312 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
18314 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
18317 if (spec_attr
== NULL
)
18318 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
18320 if (spec_attr
== NULL
)
18323 return follow_die_ref (die
, spec_attr
, spec_cu
);
18326 /* Stub for free_line_header to match void * callback types. */
18329 free_line_header_voidp (void *arg
)
18331 struct line_header
*lh
= (struct line_header
*) arg
;
18337 line_header::add_include_dir (const char *include_dir
)
18339 if (dwarf_line_debug
>= 2)
18340 fprintf_unfiltered (gdb_stdlog
, "Adding dir %zu: %s\n",
18341 include_dirs
.size () + 1, include_dir
);
18343 include_dirs
.push_back (include_dir
);
18347 line_header::add_file_name (const char *name
,
18349 unsigned int mod_time
,
18350 unsigned int length
)
18352 if (dwarf_line_debug
>= 2)
18353 fprintf_unfiltered (gdb_stdlog
, "Adding file %u: %s\n",
18354 (unsigned) file_names
.size () + 1, name
);
18356 file_names
.emplace_back (name
, d_index
, mod_time
, length
);
18359 /* A convenience function to find the proper .debug_line section for a CU. */
18361 static struct dwarf2_section_info
*
18362 get_debug_line_section (struct dwarf2_cu
*cu
)
18364 struct dwarf2_section_info
*section
;
18366 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
18368 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
18369 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
18370 else if (cu
->per_cu
->is_dwz
)
18372 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
18374 section
= &dwz
->line
;
18377 section
= &dwarf2_per_objfile
->line
;
18382 /* Read directory or file name entry format, starting with byte of
18383 format count entries, ULEB128 pairs of entry formats, ULEB128 of
18384 entries count and the entries themselves in the described entry
18388 read_formatted_entries (bfd
*abfd
, const gdb_byte
**bufp
,
18389 struct line_header
*lh
,
18390 const struct comp_unit_head
*cu_header
,
18391 void (*callback
) (struct line_header
*lh
,
18394 unsigned int mod_time
,
18395 unsigned int length
))
18397 gdb_byte format_count
, formati
;
18398 ULONGEST data_count
, datai
;
18399 const gdb_byte
*buf
= *bufp
;
18400 const gdb_byte
*format_header_data
;
18402 unsigned int bytes_read
;
18404 format_count
= read_1_byte (abfd
, buf
);
18406 format_header_data
= buf
;
18407 for (formati
= 0; formati
< format_count
; formati
++)
18409 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
18411 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
18415 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
18417 for (datai
= 0; datai
< data_count
; datai
++)
18419 const gdb_byte
*format
= format_header_data
;
18420 struct file_entry fe
;
18422 for (formati
= 0; formati
< format_count
; formati
++)
18424 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
18425 format
+= bytes_read
;
18427 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
18428 format
+= bytes_read
;
18430 gdb::optional
<const char *> string
;
18431 gdb::optional
<unsigned int> uint
;
18435 case DW_FORM_string
:
18436 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
18440 case DW_FORM_line_strp
:
18441 string
.emplace (read_indirect_line_string (abfd
, buf
,
18447 case DW_FORM_data1
:
18448 uint
.emplace (read_1_byte (abfd
, buf
));
18452 case DW_FORM_data2
:
18453 uint
.emplace (read_2_bytes (abfd
, buf
));
18457 case DW_FORM_data4
:
18458 uint
.emplace (read_4_bytes (abfd
, buf
));
18462 case DW_FORM_data8
:
18463 uint
.emplace (read_8_bytes (abfd
, buf
));
18467 case DW_FORM_udata
:
18468 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
18472 case DW_FORM_block
:
18473 /* It is valid only for DW_LNCT_timestamp which is ignored by
18478 switch (content_type
)
18481 if (string
.has_value ())
18484 case DW_LNCT_directory_index
:
18485 if (uint
.has_value ())
18486 fe
.d_index
= (dir_index
) *uint
;
18488 case DW_LNCT_timestamp
:
18489 if (uint
.has_value ())
18490 fe
.mod_time
= *uint
;
18493 if (uint
.has_value ())
18499 complaint (&symfile_complaints
,
18500 _("Unknown format content type %s"),
18501 pulongest (content_type
));
18505 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
18511 /* Read the statement program header starting at OFFSET in
18512 .debug_line, or .debug_line.dwo. Return a pointer
18513 to a struct line_header, allocated using xmalloc.
18514 Returns NULL if there is a problem reading the header, e.g., if it
18515 has a version we don't understand.
18517 NOTE: the strings in the include directory and file name tables of
18518 the returned object point into the dwarf line section buffer,
18519 and must not be freed. */
18521 static line_header_up
18522 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
18524 const gdb_byte
*line_ptr
;
18525 unsigned int bytes_read
, offset_size
;
18527 const char *cur_dir
, *cur_file
;
18528 struct dwarf2_section_info
*section
;
18531 section
= get_debug_line_section (cu
);
18532 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
18533 if (section
->buffer
== NULL
)
18535 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
18536 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
18538 complaint (&symfile_complaints
, _("missing .debug_line section"));
18542 /* We can't do this until we know the section is non-empty.
18543 Only then do we know we have such a section. */
18544 abfd
= get_section_bfd_owner (section
);
18546 /* Make sure that at least there's room for the total_length field.
18547 That could be 12 bytes long, but we're just going to fudge that. */
18548 if (to_underlying (sect_off
) + 4 >= section
->size
)
18550 dwarf2_statement_list_fits_in_line_number_section_complaint ();
18554 line_header_up
lh (new line_header ());
18556 lh
->sect_off
= sect_off
;
18557 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
18559 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
18561 /* Read in the header. */
18563 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
18564 &bytes_read
, &offset_size
);
18565 line_ptr
+= bytes_read
;
18566 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
18568 dwarf2_statement_list_fits_in_line_number_section_complaint ();
18571 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
18572 lh
->version
= read_2_bytes (abfd
, line_ptr
);
18574 if (lh
->version
> 5)
18576 /* This is a version we don't understand. The format could have
18577 changed in ways we don't handle properly so just punt. */
18578 complaint (&symfile_complaints
,
18579 _("unsupported version in .debug_line section"));
18582 if (lh
->version
>= 5)
18584 gdb_byte segment_selector_size
;
18586 /* Skip address size. */
18587 read_1_byte (abfd
, line_ptr
);
18590 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
18592 if (segment_selector_size
!= 0)
18594 complaint (&symfile_complaints
,
18595 _("unsupported segment selector size %u "
18596 "in .debug_line section"),
18597 segment_selector_size
);
18601 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
18602 line_ptr
+= offset_size
;
18603 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
18605 if (lh
->version
>= 4)
18607 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
18611 lh
->maximum_ops_per_instruction
= 1;
18613 if (lh
->maximum_ops_per_instruction
== 0)
18615 lh
->maximum_ops_per_instruction
= 1;
18616 complaint (&symfile_complaints
,
18617 _("invalid maximum_ops_per_instruction "
18618 "in `.debug_line' section"));
18621 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
18623 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
18625 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
18627 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
18629 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
18631 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
18632 for (i
= 1; i
< lh
->opcode_base
; ++i
)
18634 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
18638 if (lh
->version
>= 5)
18640 /* Read directory table. */
18641 read_formatted_entries (abfd
, &line_ptr
, lh
.get (), &cu
->header
,
18642 [] (struct line_header
*lh
, const char *name
,
18643 dir_index d_index
, unsigned int mod_time
,
18644 unsigned int length
)
18646 lh
->add_include_dir (name
);
18649 /* Read file name table. */
18650 read_formatted_entries (abfd
, &line_ptr
, lh
.get (), &cu
->header
,
18651 [] (struct line_header
*lh
, const char *name
,
18652 dir_index d_index
, unsigned int mod_time
,
18653 unsigned int length
)
18655 lh
->add_file_name (name
, d_index
, mod_time
, length
);
18660 /* Read directory table. */
18661 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
18663 line_ptr
+= bytes_read
;
18664 lh
->add_include_dir (cur_dir
);
18666 line_ptr
+= bytes_read
;
18668 /* Read file name table. */
18669 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
18671 unsigned int mod_time
, length
;
18674 line_ptr
+= bytes_read
;
18675 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18676 line_ptr
+= bytes_read
;
18677 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18678 line_ptr
+= bytes_read
;
18679 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18680 line_ptr
+= bytes_read
;
18682 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
18684 line_ptr
+= bytes_read
;
18686 lh
->statement_program_start
= line_ptr
;
18688 if (line_ptr
> (section
->buffer
+ section
->size
))
18689 complaint (&symfile_complaints
,
18690 _("line number info header doesn't "
18691 "fit in `.debug_line' section"));
18696 /* Subroutine of dwarf_decode_lines to simplify it.
18697 Return the file name of the psymtab for included file FILE_INDEX
18698 in line header LH of PST.
18699 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
18700 If space for the result is malloc'd, it will be freed by a cleanup.
18701 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename.
18703 The function creates dangling cleanup registration. */
18705 static const char *
18706 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
18707 const struct partial_symtab
*pst
,
18708 const char *comp_dir
)
18710 const file_entry
&fe
= lh
->file_names
[file_index
];
18711 const char *include_name
= fe
.name
;
18712 const char *include_name_to_compare
= include_name
;
18713 const char *pst_filename
;
18714 char *copied_name
= NULL
;
18717 const char *dir_name
= fe
.include_dir (lh
);
18719 if (!IS_ABSOLUTE_PATH (include_name
)
18720 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
18722 /* Avoid creating a duplicate psymtab for PST.
18723 We do this by comparing INCLUDE_NAME and PST_FILENAME.
18724 Before we do the comparison, however, we need to account
18725 for DIR_NAME and COMP_DIR.
18726 First prepend dir_name (if non-NULL). If we still don't
18727 have an absolute path prepend comp_dir (if non-NULL).
18728 However, the directory we record in the include-file's
18729 psymtab does not contain COMP_DIR (to match the
18730 corresponding symtab(s)).
18735 bash$ gcc -g ./hello.c
18736 include_name = "hello.c"
18738 DW_AT_comp_dir = comp_dir = "/tmp"
18739 DW_AT_name = "./hello.c"
18743 if (dir_name
!= NULL
)
18745 char *tem
= concat (dir_name
, SLASH_STRING
,
18746 include_name
, (char *)NULL
);
18748 make_cleanup (xfree
, tem
);
18749 include_name
= tem
;
18750 include_name_to_compare
= include_name
;
18752 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
18754 char *tem
= concat (comp_dir
, SLASH_STRING
,
18755 include_name
, (char *)NULL
);
18757 make_cleanup (xfree
, tem
);
18758 include_name_to_compare
= tem
;
18762 pst_filename
= pst
->filename
;
18763 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
18765 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
18766 pst_filename
, (char *)NULL
);
18767 pst_filename
= copied_name
;
18770 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
18772 if (copied_name
!= NULL
)
18773 xfree (copied_name
);
18777 return include_name
;
18780 /* State machine to track the state of the line number program. */
18782 class lnp_state_machine
18785 /* Initialize a machine state for the start of a line number
18787 lnp_state_machine (gdbarch
*arch
, line_header
*lh
, bool record_lines_p
);
18789 file_entry
*current_file ()
18791 /* lh->file_names is 0-based, but the file name numbers in the
18792 statement program are 1-based. */
18793 return m_line_header
->file_name_at (m_file
);
18796 /* Record the line in the state machine. END_SEQUENCE is true if
18797 we're processing the end of a sequence. */
18798 void record_line (bool end_sequence
);
18800 /* Check address and if invalid nop-out the rest of the lines in this
18802 void check_line_address (struct dwarf2_cu
*cu
,
18803 const gdb_byte
*line_ptr
,
18804 CORE_ADDR lowpc
, CORE_ADDR address
);
18806 void handle_set_discriminator (unsigned int discriminator
)
18808 m_discriminator
= discriminator
;
18809 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
18812 /* Handle DW_LNE_set_address. */
18813 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
18816 address
+= baseaddr
;
18817 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
18820 /* Handle DW_LNS_advance_pc. */
18821 void handle_advance_pc (CORE_ADDR adjust
);
18823 /* Handle a special opcode. */
18824 void handle_special_opcode (unsigned char op_code
);
18826 /* Handle DW_LNS_advance_line. */
18827 void handle_advance_line (int line_delta
)
18829 advance_line (line_delta
);
18832 /* Handle DW_LNS_set_file. */
18833 void handle_set_file (file_name_index file
);
18835 /* Handle DW_LNS_negate_stmt. */
18836 void handle_negate_stmt ()
18838 m_is_stmt
= !m_is_stmt
;
18841 /* Handle DW_LNS_const_add_pc. */
18842 void handle_const_add_pc ();
18844 /* Handle DW_LNS_fixed_advance_pc. */
18845 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
18847 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
18851 /* Handle DW_LNS_copy. */
18852 void handle_copy ()
18854 record_line (false);
18855 m_discriminator
= 0;
18858 /* Handle DW_LNE_end_sequence. */
18859 void handle_end_sequence ()
18861 m_record_line_callback
= ::record_line
;
18865 /* Advance the line by LINE_DELTA. */
18866 void advance_line (int line_delta
)
18868 m_line
+= line_delta
;
18870 if (line_delta
!= 0)
18871 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
18874 gdbarch
*m_gdbarch
;
18876 /* True if we're recording lines.
18877 Otherwise we're building partial symtabs and are just interested in
18878 finding include files mentioned by the line number program. */
18879 bool m_record_lines_p
;
18881 /* The line number header. */
18882 line_header
*m_line_header
;
18884 /* These are part of the standard DWARF line number state machine,
18885 and initialized according to the DWARF spec. */
18887 unsigned char m_op_index
= 0;
18888 /* The line table index (1-based) of the current file. */
18889 file_name_index m_file
= (file_name_index
) 1;
18890 unsigned int m_line
= 1;
18892 /* These are initialized in the constructor. */
18894 CORE_ADDR m_address
;
18896 unsigned int m_discriminator
;
18898 /* Additional bits of state we need to track. */
18900 /* The last file that we called dwarf2_start_subfile for.
18901 This is only used for TLLs. */
18902 unsigned int m_last_file
= 0;
18903 /* The last file a line number was recorded for. */
18904 struct subfile
*m_last_subfile
= NULL
;
18906 /* The function to call to record a line. */
18907 record_line_ftype
*m_record_line_callback
= NULL
;
18909 /* The last line number that was recorded, used to coalesce
18910 consecutive entries for the same line. This can happen, for
18911 example, when discriminators are present. PR 17276. */
18912 unsigned int m_last_line
= 0;
18913 bool m_line_has_non_zero_discriminator
= false;
18917 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
18919 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
18920 / m_line_header
->maximum_ops_per_instruction
)
18921 * m_line_header
->minimum_instruction_length
);
18922 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
18923 m_op_index
= ((m_op_index
+ adjust
)
18924 % m_line_header
->maximum_ops_per_instruction
);
18928 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
18930 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
18931 CORE_ADDR addr_adj
= (((m_op_index
18932 + (adj_opcode
/ m_line_header
->line_range
))
18933 / m_line_header
->maximum_ops_per_instruction
)
18934 * m_line_header
->minimum_instruction_length
);
18935 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
18936 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
18937 % m_line_header
->maximum_ops_per_instruction
);
18939 int line_delta
= (m_line_header
->line_base
18940 + (adj_opcode
% m_line_header
->line_range
));
18941 advance_line (line_delta
);
18942 record_line (false);
18943 m_discriminator
= 0;
18947 lnp_state_machine::handle_set_file (file_name_index file
)
18951 const file_entry
*fe
= current_file ();
18953 dwarf2_debug_line_missing_file_complaint ();
18954 else if (m_record_lines_p
)
18956 const char *dir
= fe
->include_dir (m_line_header
);
18958 m_last_subfile
= current_subfile
;
18959 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
18960 dwarf2_start_subfile (fe
->name
, dir
);
18965 lnp_state_machine::handle_const_add_pc ()
18968 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
18971 = (((m_op_index
+ adjust
)
18972 / m_line_header
->maximum_ops_per_instruction
)
18973 * m_line_header
->minimum_instruction_length
);
18975 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
18976 m_op_index
= ((m_op_index
+ adjust
)
18977 % m_line_header
->maximum_ops_per_instruction
);
18980 /* Ignore this record_line request. */
18983 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
18988 /* Return non-zero if we should add LINE to the line number table.
18989 LINE is the line to add, LAST_LINE is the last line that was added,
18990 LAST_SUBFILE is the subfile for LAST_LINE.
18991 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
18992 had a non-zero discriminator.
18994 We have to be careful in the presence of discriminators.
18995 E.g., for this line:
18997 for (i = 0; i < 100000; i++);
18999 clang can emit four line number entries for that one line,
19000 each with a different discriminator.
19001 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
19003 However, we want gdb to coalesce all four entries into one.
19004 Otherwise the user could stepi into the middle of the line and
19005 gdb would get confused about whether the pc really was in the
19006 middle of the line.
19008 Things are further complicated by the fact that two consecutive
19009 line number entries for the same line is a heuristic used by gcc
19010 to denote the end of the prologue. So we can't just discard duplicate
19011 entries, we have to be selective about it. The heuristic we use is
19012 that we only collapse consecutive entries for the same line if at least
19013 one of those entries has a non-zero discriminator. PR 17276.
19015 Note: Addresses in the line number state machine can never go backwards
19016 within one sequence, thus this coalescing is ok. */
19019 dwarf_record_line_p (unsigned int line
, unsigned int last_line
,
19020 int line_has_non_zero_discriminator
,
19021 struct subfile
*last_subfile
)
19023 if (current_subfile
!= last_subfile
)
19025 if (line
!= last_line
)
19027 /* Same line for the same file that we've seen already.
19028 As a last check, for pr 17276, only record the line if the line
19029 has never had a non-zero discriminator. */
19030 if (!line_has_non_zero_discriminator
)
19035 /* Use P_RECORD_LINE to record line number LINE beginning at address ADDRESS
19036 in the line table of subfile SUBFILE. */
19039 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19040 unsigned int line
, CORE_ADDR address
,
19041 record_line_ftype p_record_line
)
19043 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
19045 if (dwarf_line_debug
)
19047 fprintf_unfiltered (gdb_stdlog
,
19048 "Recording line %u, file %s, address %s\n",
19049 line
, lbasename (subfile
->name
),
19050 paddress (gdbarch
, address
));
19053 (*p_record_line
) (subfile
, line
, addr
);
19056 /* Subroutine of dwarf_decode_lines_1 to simplify it.
19057 Mark the end of a set of line number records.
19058 The arguments are the same as for dwarf_record_line_1.
19059 If SUBFILE is NULL the request is ignored. */
19062 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19063 CORE_ADDR address
, record_line_ftype p_record_line
)
19065 if (subfile
== NULL
)
19068 if (dwarf_line_debug
)
19070 fprintf_unfiltered (gdb_stdlog
,
19071 "Finishing current line, file %s, address %s\n",
19072 lbasename (subfile
->name
),
19073 paddress (gdbarch
, address
));
19076 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, p_record_line
);
19080 lnp_state_machine::record_line (bool end_sequence
)
19082 if (dwarf_line_debug
)
19084 fprintf_unfiltered (gdb_stdlog
,
19085 "Processing actual line %u: file %u,"
19086 " address %s, is_stmt %u, discrim %u\n",
19087 m_line
, to_underlying (m_file
),
19088 paddress (m_gdbarch
, m_address
),
19089 m_is_stmt
, m_discriminator
);
19092 file_entry
*fe
= current_file ();
19095 dwarf2_debug_line_missing_file_complaint ();
19096 /* For now we ignore lines not starting on an instruction boundary.
19097 But not when processing end_sequence for compatibility with the
19098 previous version of the code. */
19099 else if (m_op_index
== 0 || end_sequence
)
19101 fe
->included_p
= 1;
19102 if (m_record_lines_p
&& m_is_stmt
)
19104 if (m_last_subfile
!= current_subfile
|| end_sequence
)
19106 dwarf_finish_line (m_gdbarch
, m_last_subfile
,
19107 m_address
, m_record_line_callback
);
19112 if (dwarf_record_line_p (m_line
, m_last_line
,
19113 m_line_has_non_zero_discriminator
,
19116 dwarf_record_line_1 (m_gdbarch
, current_subfile
,
19118 m_record_line_callback
);
19120 m_last_subfile
= current_subfile
;
19121 m_last_line
= m_line
;
19127 lnp_state_machine::lnp_state_machine (gdbarch
*arch
, line_header
*lh
,
19128 bool record_lines_p
)
19131 m_record_lines_p
= record_lines_p
;
19132 m_line_header
= lh
;
19134 m_record_line_callback
= ::record_line
;
19136 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
19137 was a line entry for it so that the backend has a chance to adjust it
19138 and also record it in case it needs it. This is currently used by MIPS
19139 code, cf. `mips_adjust_dwarf2_line'. */
19140 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
19141 m_is_stmt
= lh
->default_is_stmt
;
19142 m_discriminator
= 0;
19146 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
19147 const gdb_byte
*line_ptr
,
19148 CORE_ADDR lowpc
, CORE_ADDR address
)
19150 /* If address < lowpc then it's not a usable value, it's outside the
19151 pc range of the CU. However, we restrict the test to only address
19152 values of zero to preserve GDB's previous behaviour which is to
19153 handle the specific case of a function being GC'd by the linker. */
19155 if (address
== 0 && address
< lowpc
)
19157 /* This line table is for a function which has been
19158 GCd by the linker. Ignore it. PR gdb/12528 */
19160 struct objfile
*objfile
= cu
->objfile
;
19161 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
19163 complaint (&symfile_complaints
,
19164 _(".debug_line address at offset 0x%lx is 0 [in module %s]"),
19165 line_offset
, objfile_name (objfile
));
19166 m_record_line_callback
= noop_record_line
;
19167 /* Note: record_line_callback is left as noop_record_line until
19168 we see DW_LNE_end_sequence. */
19172 /* Subroutine of dwarf_decode_lines to simplify it.
19173 Process the line number information in LH.
19174 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
19175 program in order to set included_p for every referenced header. */
19178 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
19179 const int decode_for_pst_p
, CORE_ADDR lowpc
)
19181 const gdb_byte
*line_ptr
, *extended_end
;
19182 const gdb_byte
*line_end
;
19183 unsigned int bytes_read
, extended_len
;
19184 unsigned char op_code
, extended_op
;
19185 CORE_ADDR baseaddr
;
19186 struct objfile
*objfile
= cu
->objfile
;
19187 bfd
*abfd
= objfile
->obfd
;
19188 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19189 /* True if we're recording line info (as opposed to building partial
19190 symtabs and just interested in finding include files mentioned by
19191 the line number program). */
19192 bool record_lines_p
= !decode_for_pst_p
;
19194 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
19196 line_ptr
= lh
->statement_program_start
;
19197 line_end
= lh
->statement_program_end
;
19199 /* Read the statement sequences until there's nothing left. */
19200 while (line_ptr
< line_end
)
19202 /* The DWARF line number program state machine. Reset the state
19203 machine at the start of each sequence. */
19204 lnp_state_machine
state_machine (gdbarch
, lh
, record_lines_p
);
19205 bool end_sequence
= false;
19207 if (record_lines_p
)
19209 /* Start a subfile for the current file of the state
19211 const file_entry
*fe
= state_machine
.current_file ();
19214 dwarf2_start_subfile (fe
->name
, fe
->include_dir (lh
));
19217 /* Decode the table. */
19218 while (line_ptr
< line_end
&& !end_sequence
)
19220 op_code
= read_1_byte (abfd
, line_ptr
);
19223 if (op_code
>= lh
->opcode_base
)
19225 /* Special opcode. */
19226 state_machine
.handle_special_opcode (op_code
);
19228 else switch (op_code
)
19230 case DW_LNS_extended_op
:
19231 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
19233 line_ptr
+= bytes_read
;
19234 extended_end
= line_ptr
+ extended_len
;
19235 extended_op
= read_1_byte (abfd
, line_ptr
);
19237 switch (extended_op
)
19239 case DW_LNE_end_sequence
:
19240 state_machine
.handle_end_sequence ();
19241 end_sequence
= true;
19243 case DW_LNE_set_address
:
19246 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
19247 line_ptr
+= bytes_read
;
19249 state_machine
.check_line_address (cu
, line_ptr
,
19251 state_machine
.handle_set_address (baseaddr
, address
);
19254 case DW_LNE_define_file
:
19256 const char *cur_file
;
19257 unsigned int mod_time
, length
;
19260 cur_file
= read_direct_string (abfd
, line_ptr
,
19262 line_ptr
+= bytes_read
;
19263 dindex
= (dir_index
)
19264 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19265 line_ptr
+= bytes_read
;
19267 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19268 line_ptr
+= bytes_read
;
19270 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19271 line_ptr
+= bytes_read
;
19272 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
19275 case DW_LNE_set_discriminator
:
19277 /* The discriminator is not interesting to the
19278 debugger; just ignore it. We still need to
19279 check its value though:
19280 if there are consecutive entries for the same
19281 (non-prologue) line we want to coalesce them.
19284 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19285 line_ptr
+= bytes_read
;
19287 state_machine
.handle_set_discriminator (discr
);
19291 complaint (&symfile_complaints
,
19292 _("mangled .debug_line section"));
19295 /* Make sure that we parsed the extended op correctly. If e.g.
19296 we expected a different address size than the producer used,
19297 we may have read the wrong number of bytes. */
19298 if (line_ptr
!= extended_end
)
19300 complaint (&symfile_complaints
,
19301 _("mangled .debug_line section"));
19306 state_machine
.handle_copy ();
19308 case DW_LNS_advance_pc
:
19311 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19312 line_ptr
+= bytes_read
;
19314 state_machine
.handle_advance_pc (adjust
);
19317 case DW_LNS_advance_line
:
19320 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
19321 line_ptr
+= bytes_read
;
19323 state_machine
.handle_advance_line (line_delta
);
19326 case DW_LNS_set_file
:
19328 file_name_index file
19329 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
19331 line_ptr
+= bytes_read
;
19333 state_machine
.handle_set_file (file
);
19336 case DW_LNS_set_column
:
19337 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19338 line_ptr
+= bytes_read
;
19340 case DW_LNS_negate_stmt
:
19341 state_machine
.handle_negate_stmt ();
19343 case DW_LNS_set_basic_block
:
19345 /* Add to the address register of the state machine the
19346 address increment value corresponding to special opcode
19347 255. I.e., this value is scaled by the minimum
19348 instruction length since special opcode 255 would have
19349 scaled the increment. */
19350 case DW_LNS_const_add_pc
:
19351 state_machine
.handle_const_add_pc ();
19353 case DW_LNS_fixed_advance_pc
:
19355 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
19358 state_machine
.handle_fixed_advance_pc (addr_adj
);
19363 /* Unknown standard opcode, ignore it. */
19366 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
19368 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19369 line_ptr
+= bytes_read
;
19376 dwarf2_debug_line_missing_end_sequence_complaint ();
19378 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
19379 in which case we still finish recording the last line). */
19380 state_machine
.record_line (true);
19384 /* Decode the Line Number Program (LNP) for the given line_header
19385 structure and CU. The actual information extracted and the type
19386 of structures created from the LNP depends on the value of PST.
19388 1. If PST is NULL, then this procedure uses the data from the program
19389 to create all necessary symbol tables, and their linetables.
19391 2. If PST is not NULL, this procedure reads the program to determine
19392 the list of files included by the unit represented by PST, and
19393 builds all the associated partial symbol tables.
19395 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19396 It is used for relative paths in the line table.
19397 NOTE: When processing partial symtabs (pst != NULL),
19398 comp_dir == pst->dirname.
19400 NOTE: It is important that psymtabs have the same file name (via strcmp)
19401 as the corresponding symtab. Since COMP_DIR is not used in the name of the
19402 symtab we don't use it in the name of the psymtabs we create.
19403 E.g. expand_line_sal requires this when finding psymtabs to expand.
19404 A good testcase for this is mb-inline.exp.
19406 LOWPC is the lowest address in CU (or 0 if not known).
19408 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
19409 for its PC<->lines mapping information. Otherwise only the filename
19410 table is read in. */
19413 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
19414 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
19415 CORE_ADDR lowpc
, int decode_mapping
)
19417 struct objfile
*objfile
= cu
->objfile
;
19418 const int decode_for_pst_p
= (pst
!= NULL
);
19420 if (decode_mapping
)
19421 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
19423 if (decode_for_pst_p
)
19427 /* Now that we're done scanning the Line Header Program, we can
19428 create the psymtab of each included file. */
19429 for (file_index
= 0; file_index
< lh
->file_names
.size (); file_index
++)
19430 if (lh
->file_names
[file_index
].included_p
== 1)
19432 const char *include_name
=
19433 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
19434 if (include_name
!= NULL
)
19435 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
19440 /* Make sure a symtab is created for every file, even files
19441 which contain only variables (i.e. no code with associated
19443 struct compunit_symtab
*cust
= buildsym_compunit_symtab ();
19446 for (i
= 0; i
< lh
->file_names
.size (); i
++)
19448 file_entry
&fe
= lh
->file_names
[i
];
19450 dwarf2_start_subfile (fe
.name
, fe
.include_dir (lh
));
19452 if (current_subfile
->symtab
== NULL
)
19454 current_subfile
->symtab
19455 = allocate_symtab (cust
, current_subfile
->name
);
19457 fe
.symtab
= current_subfile
->symtab
;
19462 /* Start a subfile for DWARF. FILENAME is the name of the file and
19463 DIRNAME the name of the source directory which contains FILENAME
19464 or NULL if not known.
19465 This routine tries to keep line numbers from identical absolute and
19466 relative file names in a common subfile.
19468 Using the `list' example from the GDB testsuite, which resides in
19469 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
19470 of /srcdir/list0.c yields the following debugging information for list0.c:
19472 DW_AT_name: /srcdir/list0.c
19473 DW_AT_comp_dir: /compdir
19474 files.files[0].name: list0.h
19475 files.files[0].dir: /srcdir
19476 files.files[1].name: list0.c
19477 files.files[1].dir: /srcdir
19479 The line number information for list0.c has to end up in a single
19480 subfile, so that `break /srcdir/list0.c:1' works as expected.
19481 start_subfile will ensure that this happens provided that we pass the
19482 concatenation of files.files[1].dir and files.files[1].name as the
19486 dwarf2_start_subfile (const char *filename
, const char *dirname
)
19490 /* In order not to lose the line information directory,
19491 we concatenate it to the filename when it makes sense.
19492 Note that the Dwarf3 standard says (speaking of filenames in line
19493 information): ``The directory index is ignored for file names
19494 that represent full path names''. Thus ignoring dirname in the
19495 `else' branch below isn't an issue. */
19497 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
19499 copy
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
19503 start_subfile (filename
);
19509 /* Start a symtab for DWARF.
19510 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
19512 static struct compunit_symtab
*
19513 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
19514 const char *name
, const char *comp_dir
, CORE_ADDR low_pc
)
19516 struct compunit_symtab
*cust
19517 = start_symtab (cu
->objfile
, name
, comp_dir
, low_pc
, cu
->language
);
19519 record_debugformat ("DWARF 2");
19520 record_producer (cu
->producer
);
19522 /* We assume that we're processing GCC output. */
19523 processing_gcc_compilation
= 2;
19525 cu
->processing_has_namespace_info
= 0;
19531 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
19532 struct dwarf2_cu
*cu
)
19534 struct objfile
*objfile
= cu
->objfile
;
19535 struct comp_unit_head
*cu_header
= &cu
->header
;
19537 /* NOTE drow/2003-01-30: There used to be a comment and some special
19538 code here to turn a symbol with DW_AT_external and a
19539 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
19540 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
19541 with some versions of binutils) where shared libraries could have
19542 relocations against symbols in their debug information - the
19543 minimal symbol would have the right address, but the debug info
19544 would not. It's no longer necessary, because we will explicitly
19545 apply relocations when we read in the debug information now. */
19547 /* A DW_AT_location attribute with no contents indicates that a
19548 variable has been optimized away. */
19549 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
19551 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
19555 /* Handle one degenerate form of location expression specially, to
19556 preserve GDB's previous behavior when section offsets are
19557 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
19558 then mark this symbol as LOC_STATIC. */
19560 if (attr_form_is_block (attr
)
19561 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
19562 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
19563 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
19564 && (DW_BLOCK (attr
)->size
19565 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
19567 unsigned int dummy
;
19569 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
19570 SYMBOL_VALUE_ADDRESS (sym
) =
19571 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
19573 SYMBOL_VALUE_ADDRESS (sym
) =
19574 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
19575 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
19576 fixup_symbol_section (sym
, objfile
);
19577 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
19578 SYMBOL_SECTION (sym
));
19582 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
19583 expression evaluator, and use LOC_COMPUTED only when necessary
19584 (i.e. when the value of a register or memory location is
19585 referenced, or a thread-local block, etc.). Then again, it might
19586 not be worthwhile. I'm assuming that it isn't unless performance
19587 or memory numbers show me otherwise. */
19589 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
19591 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
19592 cu
->has_loclist
= 1;
19595 /* Given a pointer to a DWARF information entry, figure out if we need
19596 to make a symbol table entry for it, and if so, create a new entry
19597 and return a pointer to it.
19598 If TYPE is NULL, determine symbol type from the die, otherwise
19599 used the passed type.
19600 If SPACE is not NULL, use it to hold the new symbol. If it is
19601 NULL, allocate a new symbol on the objfile's obstack. */
19603 static struct symbol
*
19604 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
19605 struct symbol
*space
)
19607 struct objfile
*objfile
= cu
->objfile
;
19608 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19609 struct symbol
*sym
= NULL
;
19611 struct attribute
*attr
= NULL
;
19612 struct attribute
*attr2
= NULL
;
19613 CORE_ADDR baseaddr
;
19614 struct pending
**list_to_add
= NULL
;
19616 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
19618 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
19620 name
= dwarf2_name (die
, cu
);
19623 const char *linkagename
;
19624 int suppress_add
= 0;
19629 sym
= allocate_symbol (objfile
);
19630 OBJSTAT (objfile
, n_syms
++);
19632 /* Cache this symbol's name and the name's demangled form (if any). */
19633 SYMBOL_SET_LANGUAGE (sym
, cu
->language
, &objfile
->objfile_obstack
);
19634 linkagename
= dwarf2_physname (name
, die
, cu
);
19635 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
19637 /* Fortran does not have mangling standard and the mangling does differ
19638 between gfortran, iFort etc. */
19639 if (cu
->language
== language_fortran
19640 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
19641 symbol_set_demangled_name (&(sym
->ginfo
),
19642 dwarf2_full_name (name
, die
, cu
),
19645 /* Default assumptions.
19646 Use the passed type or decode it from the die. */
19647 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
19648 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
19650 SYMBOL_TYPE (sym
) = type
;
19652 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
19653 attr
= dwarf2_attr (die
,
19654 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
19658 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
19661 attr
= dwarf2_attr (die
,
19662 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
19666 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
19667 struct file_entry
*fe
;
19669 if (cu
->line_header
!= NULL
)
19670 fe
= cu
->line_header
->file_name_at (file_index
);
19675 complaint (&symfile_complaints
,
19676 _("file index out of range"));
19678 symbol_set_symtab (sym
, fe
->symtab
);
19684 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
19689 addr
= attr_value_as_address (attr
);
19690 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
19691 SYMBOL_VALUE_ADDRESS (sym
) = addr
;
19693 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
19694 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
19695 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
19696 add_symbol_to_list (sym
, cu
->list_in_scope
);
19698 case DW_TAG_subprogram
:
19699 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
19701 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
19702 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
19703 if ((attr2
&& (DW_UNSND (attr2
) != 0))
19704 || cu
->language
== language_ada
)
19706 /* Subprograms marked external are stored as a global symbol.
19707 Ada subprograms, whether marked external or not, are always
19708 stored as a global symbol, because we want to be able to
19709 access them globally. For instance, we want to be able
19710 to break on a nested subprogram without having to
19711 specify the context. */
19712 list_to_add
= &global_symbols
;
19716 list_to_add
= cu
->list_in_scope
;
19719 case DW_TAG_inlined_subroutine
:
19720 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
19722 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
19723 SYMBOL_INLINED (sym
) = 1;
19724 list_to_add
= cu
->list_in_scope
;
19726 case DW_TAG_template_value_param
:
19728 /* Fall through. */
19729 case DW_TAG_constant
:
19730 case DW_TAG_variable
:
19731 case DW_TAG_member
:
19732 /* Compilation with minimal debug info may result in
19733 variables with missing type entries. Change the
19734 misleading `void' type to something sensible. */
19735 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
19736 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
19738 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
19739 /* In the case of DW_TAG_member, we should only be called for
19740 static const members. */
19741 if (die
->tag
== DW_TAG_member
)
19743 /* dwarf2_add_field uses die_is_declaration,
19744 so we do the same. */
19745 gdb_assert (die_is_declaration (die
, cu
));
19750 dwarf2_const_value (attr
, sym
, cu
);
19751 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
19754 if (attr2
&& (DW_UNSND (attr2
) != 0))
19755 list_to_add
= &global_symbols
;
19757 list_to_add
= cu
->list_in_scope
;
19761 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
19764 var_decode_location (attr
, sym
, cu
);
19765 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
19767 /* Fortran explicitly imports any global symbols to the local
19768 scope by DW_TAG_common_block. */
19769 if (cu
->language
== language_fortran
&& die
->parent
19770 && die
->parent
->tag
== DW_TAG_common_block
)
19773 if (SYMBOL_CLASS (sym
) == LOC_STATIC
19774 && SYMBOL_VALUE_ADDRESS (sym
) == 0
19775 && !dwarf2_per_objfile
->has_section_at_zero
)
19777 /* When a static variable is eliminated by the linker,
19778 the corresponding debug information is not stripped
19779 out, but the variable address is set to null;
19780 do not add such variables into symbol table. */
19782 else if (attr2
&& (DW_UNSND (attr2
) != 0))
19784 /* Workaround gfortran PR debug/40040 - it uses
19785 DW_AT_location for variables in -fPIC libraries which may
19786 get overriden by other libraries/executable and get
19787 a different address. Resolve it by the minimal symbol
19788 which may come from inferior's executable using copy
19789 relocation. Make this workaround only for gfortran as for
19790 other compilers GDB cannot guess the minimal symbol
19791 Fortran mangling kind. */
19792 if (cu
->language
== language_fortran
&& die
->parent
19793 && die
->parent
->tag
== DW_TAG_module
19795 && startswith (cu
->producer
, "GNU Fortran"))
19796 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
19798 /* A variable with DW_AT_external is never static,
19799 but it may be block-scoped. */
19800 list_to_add
= (cu
->list_in_scope
== &file_symbols
19801 ? &global_symbols
: cu
->list_in_scope
);
19804 list_to_add
= cu
->list_in_scope
;
19808 /* We do not know the address of this symbol.
19809 If it is an external symbol and we have type information
19810 for it, enter the symbol as a LOC_UNRESOLVED symbol.
19811 The address of the variable will then be determined from
19812 the minimal symbol table whenever the variable is
19814 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
19816 /* Fortran explicitly imports any global symbols to the local
19817 scope by DW_TAG_common_block. */
19818 if (cu
->language
== language_fortran
&& die
->parent
19819 && die
->parent
->tag
== DW_TAG_common_block
)
19821 /* SYMBOL_CLASS doesn't matter here because
19822 read_common_block is going to reset it. */
19824 list_to_add
= cu
->list_in_scope
;
19826 else if (attr2
&& (DW_UNSND (attr2
) != 0)
19827 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
19829 /* A variable with DW_AT_external is never static, but it
19830 may be block-scoped. */
19831 list_to_add
= (cu
->list_in_scope
== &file_symbols
19832 ? &global_symbols
: cu
->list_in_scope
);
19834 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
19836 else if (!die_is_declaration (die
, cu
))
19838 /* Use the default LOC_OPTIMIZED_OUT class. */
19839 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
19841 list_to_add
= cu
->list_in_scope
;
19845 case DW_TAG_formal_parameter
:
19846 /* If we are inside a function, mark this as an argument. If
19847 not, we might be looking at an argument to an inlined function
19848 when we do not have enough information to show inlined frames;
19849 pretend it's a local variable in that case so that the user can
19851 if (context_stack_depth
> 0
19852 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
19853 SYMBOL_IS_ARGUMENT (sym
) = 1;
19854 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
19857 var_decode_location (attr
, sym
, cu
);
19859 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
19862 dwarf2_const_value (attr
, sym
, cu
);
19865 list_to_add
= cu
->list_in_scope
;
19867 case DW_TAG_unspecified_parameters
:
19868 /* From varargs functions; gdb doesn't seem to have any
19869 interest in this information, so just ignore it for now.
19872 case DW_TAG_template_type_param
:
19874 /* Fall through. */
19875 case DW_TAG_class_type
:
19876 case DW_TAG_interface_type
:
19877 case DW_TAG_structure_type
:
19878 case DW_TAG_union_type
:
19879 case DW_TAG_set_type
:
19880 case DW_TAG_enumeration_type
:
19881 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
19882 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
19885 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
19886 really ever be static objects: otherwise, if you try
19887 to, say, break of a class's method and you're in a file
19888 which doesn't mention that class, it won't work unless
19889 the check for all static symbols in lookup_symbol_aux
19890 saves you. See the OtherFileClass tests in
19891 gdb.c++/namespace.exp. */
19895 list_to_add
= (cu
->list_in_scope
== &file_symbols
19896 && cu
->language
== language_cplus
19897 ? &global_symbols
: cu
->list_in_scope
);
19899 /* The semantics of C++ state that "struct foo {
19900 ... }" also defines a typedef for "foo". */
19901 if (cu
->language
== language_cplus
19902 || cu
->language
== language_ada
19903 || cu
->language
== language_d
19904 || cu
->language
== language_rust
)
19906 /* The symbol's name is already allocated along
19907 with this objfile, so we don't need to
19908 duplicate it for the type. */
19909 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
19910 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
19915 case DW_TAG_typedef
:
19916 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
19917 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
19918 list_to_add
= cu
->list_in_scope
;
19920 case DW_TAG_base_type
:
19921 case DW_TAG_subrange_type
:
19922 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
19923 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
19924 list_to_add
= cu
->list_in_scope
;
19926 case DW_TAG_enumerator
:
19927 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
19930 dwarf2_const_value (attr
, sym
, cu
);
19933 /* NOTE: carlton/2003-11-10: See comment above in the
19934 DW_TAG_class_type, etc. block. */
19936 list_to_add
= (cu
->list_in_scope
== &file_symbols
19937 && cu
->language
== language_cplus
19938 ? &global_symbols
: cu
->list_in_scope
);
19941 case DW_TAG_imported_declaration
:
19942 case DW_TAG_namespace
:
19943 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
19944 list_to_add
= &global_symbols
;
19946 case DW_TAG_module
:
19947 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
19948 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
19949 list_to_add
= &global_symbols
;
19951 case DW_TAG_common_block
:
19952 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
19953 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
19954 add_symbol_to_list (sym
, cu
->list_in_scope
);
19957 /* Not a tag we recognize. Hopefully we aren't processing
19958 trash data, but since we must specifically ignore things
19959 we don't recognize, there is nothing else we should do at
19961 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
19962 dwarf_tag_name (die
->tag
));
19968 sym
->hash_next
= objfile
->template_symbols
;
19969 objfile
->template_symbols
= sym
;
19970 list_to_add
= NULL
;
19973 if (list_to_add
!= NULL
)
19974 add_symbol_to_list (sym
, list_to_add
);
19976 /* For the benefit of old versions of GCC, check for anonymous
19977 namespaces based on the demangled name. */
19978 if (!cu
->processing_has_namespace_info
19979 && cu
->language
== language_cplus
)
19980 cp_scan_for_anonymous_namespaces (sym
, objfile
);
19985 /* A wrapper for new_symbol_full that always allocates a new symbol. */
19987 static struct symbol
*
19988 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
19990 return new_symbol_full (die
, type
, cu
, NULL
);
19993 /* Given an attr with a DW_FORM_dataN value in host byte order,
19994 zero-extend it as appropriate for the symbol's type. The DWARF
19995 standard (v4) is not entirely clear about the meaning of using
19996 DW_FORM_dataN for a constant with a signed type, where the type is
19997 wider than the data. The conclusion of a discussion on the DWARF
19998 list was that this is unspecified. We choose to always zero-extend
19999 because that is the interpretation long in use by GCC. */
20002 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
20003 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
20005 struct objfile
*objfile
= cu
->objfile
;
20006 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
20007 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
20008 LONGEST l
= DW_UNSND (attr
);
20010 if (bits
< sizeof (*value
) * 8)
20012 l
&= ((LONGEST
) 1 << bits
) - 1;
20015 else if (bits
== sizeof (*value
) * 8)
20019 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
20020 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
20027 /* Read a constant value from an attribute. Either set *VALUE, or if
20028 the value does not fit in *VALUE, set *BYTES - either already
20029 allocated on the objfile obstack, or newly allocated on OBSTACK,
20030 or, set *BATON, if we translated the constant to a location
20034 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
20035 const char *name
, struct obstack
*obstack
,
20036 struct dwarf2_cu
*cu
,
20037 LONGEST
*value
, const gdb_byte
**bytes
,
20038 struct dwarf2_locexpr_baton
**baton
)
20040 struct objfile
*objfile
= cu
->objfile
;
20041 struct comp_unit_head
*cu_header
= &cu
->header
;
20042 struct dwarf_block
*blk
;
20043 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
20044 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
20050 switch (attr
->form
)
20053 case DW_FORM_GNU_addr_index
:
20057 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
20058 dwarf2_const_value_length_mismatch_complaint (name
,
20059 cu_header
->addr_size
,
20060 TYPE_LENGTH (type
));
20061 /* Symbols of this form are reasonably rare, so we just
20062 piggyback on the existing location code rather than writing
20063 a new implementation of symbol_computed_ops. */
20064 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
20065 (*baton
)->per_cu
= cu
->per_cu
;
20066 gdb_assert ((*baton
)->per_cu
);
20068 (*baton
)->size
= 2 + cu_header
->addr_size
;
20069 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
20070 (*baton
)->data
= data
;
20072 data
[0] = DW_OP_addr
;
20073 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
20074 byte_order
, DW_ADDR (attr
));
20075 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
20078 case DW_FORM_string
:
20080 case DW_FORM_GNU_str_index
:
20081 case DW_FORM_GNU_strp_alt
:
20082 /* DW_STRING is already allocated on the objfile obstack, point
20084 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
20086 case DW_FORM_block1
:
20087 case DW_FORM_block2
:
20088 case DW_FORM_block4
:
20089 case DW_FORM_block
:
20090 case DW_FORM_exprloc
:
20091 case DW_FORM_data16
:
20092 blk
= DW_BLOCK (attr
);
20093 if (TYPE_LENGTH (type
) != blk
->size
)
20094 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
20095 TYPE_LENGTH (type
));
20096 *bytes
= blk
->data
;
20099 /* The DW_AT_const_value attributes are supposed to carry the
20100 symbol's value "represented as it would be on the target
20101 architecture." By the time we get here, it's already been
20102 converted to host endianness, so we just need to sign- or
20103 zero-extend it as appropriate. */
20104 case DW_FORM_data1
:
20105 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
20107 case DW_FORM_data2
:
20108 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
20110 case DW_FORM_data4
:
20111 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
20113 case DW_FORM_data8
:
20114 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
20117 case DW_FORM_sdata
:
20118 case DW_FORM_implicit_const
:
20119 *value
= DW_SND (attr
);
20122 case DW_FORM_udata
:
20123 *value
= DW_UNSND (attr
);
20127 complaint (&symfile_complaints
,
20128 _("unsupported const value attribute form: '%s'"),
20129 dwarf_form_name (attr
->form
));
20136 /* Copy constant value from an attribute to a symbol. */
20139 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
20140 struct dwarf2_cu
*cu
)
20142 struct objfile
*objfile
= cu
->objfile
;
20144 const gdb_byte
*bytes
;
20145 struct dwarf2_locexpr_baton
*baton
;
20147 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
20148 SYMBOL_PRINT_NAME (sym
),
20149 &objfile
->objfile_obstack
, cu
,
20150 &value
, &bytes
, &baton
);
20154 SYMBOL_LOCATION_BATON (sym
) = baton
;
20155 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
20157 else if (bytes
!= NULL
)
20159 SYMBOL_VALUE_BYTES (sym
) = bytes
;
20160 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
20164 SYMBOL_VALUE (sym
) = value
;
20165 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
20169 /* Return the type of the die in question using its DW_AT_type attribute. */
20171 static struct type
*
20172 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
20174 struct attribute
*type_attr
;
20176 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
20179 /* A missing DW_AT_type represents a void type. */
20180 return objfile_type (cu
->objfile
)->builtin_void
;
20183 return lookup_die_type (die
, type_attr
, cu
);
20186 /* True iff CU's producer generates GNAT Ada auxiliary information
20187 that allows to find parallel types through that information instead
20188 of having to do expensive parallel lookups by type name. */
20191 need_gnat_info (struct dwarf2_cu
*cu
)
20193 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
20194 of GNAT produces this auxiliary information, without any indication
20195 that it is produced. Part of enhancing the FSF version of GNAT
20196 to produce that information will be to put in place an indicator
20197 that we can use in order to determine whether the descriptive type
20198 info is available or not. One suggestion that has been made is
20199 to use a new attribute, attached to the CU die. For now, assume
20200 that the descriptive type info is not available. */
20204 /* Return the auxiliary type of the die in question using its
20205 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
20206 attribute is not present. */
20208 static struct type
*
20209 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
20211 struct attribute
*type_attr
;
20213 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
20217 return lookup_die_type (die
, type_attr
, cu
);
20220 /* If DIE has a descriptive_type attribute, then set the TYPE's
20221 descriptive type accordingly. */
20224 set_descriptive_type (struct type
*type
, struct die_info
*die
,
20225 struct dwarf2_cu
*cu
)
20227 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
20229 if (descriptive_type
)
20231 ALLOCATE_GNAT_AUX_TYPE (type
);
20232 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
20236 /* Return the containing type of the die in question using its
20237 DW_AT_containing_type attribute. */
20239 static struct type
*
20240 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
20242 struct attribute
*type_attr
;
20244 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
20246 error (_("Dwarf Error: Problem turning containing type into gdb type "
20247 "[in module %s]"), objfile_name (cu
->objfile
));
20249 return lookup_die_type (die
, type_attr
, cu
);
20252 /* Return an error marker type to use for the ill formed type in DIE/CU. */
20254 static struct type
*
20255 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
20257 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20258 char *message
, *saved
;
20260 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
20261 objfile_name (objfile
),
20262 to_underlying (cu
->header
.sect_off
),
20263 to_underlying (die
->sect_off
));
20264 saved
= (char *) obstack_copy0 (&objfile
->objfile_obstack
,
20265 message
, strlen (message
));
20268 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
20271 /* Look up the type of DIE in CU using its type attribute ATTR.
20272 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
20273 DW_AT_containing_type.
20274 If there is no type substitute an error marker. */
20276 static struct type
*
20277 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
20278 struct dwarf2_cu
*cu
)
20280 struct objfile
*objfile
= cu
->objfile
;
20281 struct type
*this_type
;
20283 gdb_assert (attr
->name
== DW_AT_type
20284 || attr
->name
== DW_AT_GNAT_descriptive_type
20285 || attr
->name
== DW_AT_containing_type
);
20287 /* First see if we have it cached. */
20289 if (attr
->form
== DW_FORM_GNU_ref_alt
)
20291 struct dwarf2_per_cu_data
*per_cu
;
20292 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
20294 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1, cu
->objfile
);
20295 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
20297 else if (attr_form_is_ref (attr
))
20299 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
20301 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
20303 else if (attr
->form
== DW_FORM_ref_sig8
)
20305 ULONGEST signature
= DW_SIGNATURE (attr
);
20307 return get_signatured_type (die
, signature
, cu
);
20311 complaint (&symfile_complaints
,
20312 _("Dwarf Error: Bad type attribute %s in DIE"
20313 " at 0x%x [in module %s]"),
20314 dwarf_attr_name (attr
->name
), to_underlying (die
->sect_off
),
20315 objfile_name (objfile
));
20316 return build_error_marker_type (cu
, die
);
20319 /* If not cached we need to read it in. */
20321 if (this_type
== NULL
)
20323 struct die_info
*type_die
= NULL
;
20324 struct dwarf2_cu
*type_cu
= cu
;
20326 if (attr_form_is_ref (attr
))
20327 type_die
= follow_die_ref (die
, attr
, &type_cu
);
20328 if (type_die
== NULL
)
20329 return build_error_marker_type (cu
, die
);
20330 /* If we find the type now, it's probably because the type came
20331 from an inter-CU reference and the type's CU got expanded before
20333 this_type
= read_type_die (type_die
, type_cu
);
20336 /* If we still don't have a type use an error marker. */
20338 if (this_type
== NULL
)
20339 return build_error_marker_type (cu
, die
);
20344 /* Return the type in DIE, CU.
20345 Returns NULL for invalid types.
20347 This first does a lookup in die_type_hash,
20348 and only reads the die in if necessary.
20350 NOTE: This can be called when reading in partial or full symbols. */
20352 static struct type
*
20353 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
20355 struct type
*this_type
;
20357 this_type
= get_die_type (die
, cu
);
20361 return read_type_die_1 (die
, cu
);
20364 /* Read the type in DIE, CU.
20365 Returns NULL for invalid types. */
20367 static struct type
*
20368 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
20370 struct type
*this_type
= NULL
;
20374 case DW_TAG_class_type
:
20375 case DW_TAG_interface_type
:
20376 case DW_TAG_structure_type
:
20377 case DW_TAG_union_type
:
20378 this_type
= read_structure_type (die
, cu
);
20380 case DW_TAG_enumeration_type
:
20381 this_type
= read_enumeration_type (die
, cu
);
20383 case DW_TAG_subprogram
:
20384 case DW_TAG_subroutine_type
:
20385 case DW_TAG_inlined_subroutine
:
20386 this_type
= read_subroutine_type (die
, cu
);
20388 case DW_TAG_array_type
:
20389 this_type
= read_array_type (die
, cu
);
20391 case DW_TAG_set_type
:
20392 this_type
= read_set_type (die
, cu
);
20394 case DW_TAG_pointer_type
:
20395 this_type
= read_tag_pointer_type (die
, cu
);
20397 case DW_TAG_ptr_to_member_type
:
20398 this_type
= read_tag_ptr_to_member_type (die
, cu
);
20400 case DW_TAG_reference_type
:
20401 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
20403 case DW_TAG_rvalue_reference_type
:
20404 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
20406 case DW_TAG_const_type
:
20407 this_type
= read_tag_const_type (die
, cu
);
20409 case DW_TAG_volatile_type
:
20410 this_type
= read_tag_volatile_type (die
, cu
);
20412 case DW_TAG_restrict_type
:
20413 this_type
= read_tag_restrict_type (die
, cu
);
20415 case DW_TAG_string_type
:
20416 this_type
= read_tag_string_type (die
, cu
);
20418 case DW_TAG_typedef
:
20419 this_type
= read_typedef (die
, cu
);
20421 case DW_TAG_subrange_type
:
20422 this_type
= read_subrange_type (die
, cu
);
20424 case DW_TAG_base_type
:
20425 this_type
= read_base_type (die
, cu
);
20427 case DW_TAG_unspecified_type
:
20428 this_type
= read_unspecified_type (die
, cu
);
20430 case DW_TAG_namespace
:
20431 this_type
= read_namespace_type (die
, cu
);
20433 case DW_TAG_module
:
20434 this_type
= read_module_type (die
, cu
);
20436 case DW_TAG_atomic_type
:
20437 this_type
= read_tag_atomic_type (die
, cu
);
20440 complaint (&symfile_complaints
,
20441 _("unexpected tag in read_type_die: '%s'"),
20442 dwarf_tag_name (die
->tag
));
20449 /* See if we can figure out if the class lives in a namespace. We do
20450 this by looking for a member function; its demangled name will
20451 contain namespace info, if there is any.
20452 Return the computed name or NULL.
20453 Space for the result is allocated on the objfile's obstack.
20454 This is the full-die version of guess_partial_die_structure_name.
20455 In this case we know DIE has no useful parent. */
20458 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20460 struct die_info
*spec_die
;
20461 struct dwarf2_cu
*spec_cu
;
20462 struct die_info
*child
;
20465 spec_die
= die_specification (die
, &spec_cu
);
20466 if (spec_die
!= NULL
)
20472 for (child
= die
->child
;
20474 child
= child
->sibling
)
20476 if (child
->tag
== DW_TAG_subprogram
)
20478 const char *linkage_name
= dw2_linkage_name (child
, cu
);
20480 if (linkage_name
!= NULL
)
20483 = language_class_name_from_physname (cu
->language_defn
,
20487 if (actual_name
!= NULL
)
20489 const char *die_name
= dwarf2_name (die
, cu
);
20491 if (die_name
!= NULL
20492 && strcmp (die_name
, actual_name
) != 0)
20494 /* Strip off the class name from the full name.
20495 We want the prefix. */
20496 int die_name_len
= strlen (die_name
);
20497 int actual_name_len
= strlen (actual_name
);
20499 /* Test for '::' as a sanity check. */
20500 if (actual_name_len
> die_name_len
+ 2
20501 && actual_name
[actual_name_len
20502 - die_name_len
- 1] == ':')
20503 name
= (char *) obstack_copy0 (
20504 &cu
->objfile
->per_bfd
->storage_obstack
,
20505 actual_name
, actual_name_len
- die_name_len
- 2);
20508 xfree (actual_name
);
20517 /* GCC might emit a nameless typedef that has a linkage name. Determine the
20518 prefix part in such case. See
20519 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
20521 static const char *
20522 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
20524 struct attribute
*attr
;
20527 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
20528 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
20531 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
20534 attr
= dw2_linkage_name_attr (die
, cu
);
20535 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
20538 /* dwarf2_name had to be already called. */
20539 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
20541 /* Strip the base name, keep any leading namespaces/classes. */
20542 base
= strrchr (DW_STRING (attr
), ':');
20543 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
20546 return (char *) obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
20548 &base
[-1] - DW_STRING (attr
));
20551 /* Return the name of the namespace/class that DIE is defined within,
20552 or "" if we can't tell. The caller should not xfree the result.
20554 For example, if we're within the method foo() in the following
20564 then determine_prefix on foo's die will return "N::C". */
20566 static const char *
20567 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
20569 struct die_info
*parent
, *spec_die
;
20570 struct dwarf2_cu
*spec_cu
;
20571 struct type
*parent_type
;
20572 const char *retval
;
20574 if (cu
->language
!= language_cplus
20575 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
20576 && cu
->language
!= language_rust
)
20579 retval
= anonymous_struct_prefix (die
, cu
);
20583 /* We have to be careful in the presence of DW_AT_specification.
20584 For example, with GCC 3.4, given the code
20588 // Definition of N::foo.
20592 then we'll have a tree of DIEs like this:
20594 1: DW_TAG_compile_unit
20595 2: DW_TAG_namespace // N
20596 3: DW_TAG_subprogram // declaration of N::foo
20597 4: DW_TAG_subprogram // definition of N::foo
20598 DW_AT_specification // refers to die #3
20600 Thus, when processing die #4, we have to pretend that we're in
20601 the context of its DW_AT_specification, namely the contex of die
20604 spec_die
= die_specification (die
, &spec_cu
);
20605 if (spec_die
== NULL
)
20606 parent
= die
->parent
;
20609 parent
= spec_die
->parent
;
20613 if (parent
== NULL
)
20615 else if (parent
->building_fullname
)
20618 const char *parent_name
;
20620 /* It has been seen on RealView 2.2 built binaries,
20621 DW_TAG_template_type_param types actually _defined_ as
20622 children of the parent class:
20625 template class <class Enum> Class{};
20626 Class<enum E> class_e;
20628 1: DW_TAG_class_type (Class)
20629 2: DW_TAG_enumeration_type (E)
20630 3: DW_TAG_enumerator (enum1:0)
20631 3: DW_TAG_enumerator (enum2:1)
20633 2: DW_TAG_template_type_param
20634 DW_AT_type DW_FORM_ref_udata (E)
20636 Besides being broken debug info, it can put GDB into an
20637 infinite loop. Consider:
20639 When we're building the full name for Class<E>, we'll start
20640 at Class, and go look over its template type parameters,
20641 finding E. We'll then try to build the full name of E, and
20642 reach here. We're now trying to build the full name of E,
20643 and look over the parent DIE for containing scope. In the
20644 broken case, if we followed the parent DIE of E, we'd again
20645 find Class, and once again go look at its template type
20646 arguments, etc., etc. Simply don't consider such parent die
20647 as source-level parent of this die (it can't be, the language
20648 doesn't allow it), and break the loop here. */
20649 name
= dwarf2_name (die
, cu
);
20650 parent_name
= dwarf2_name (parent
, cu
);
20651 complaint (&symfile_complaints
,
20652 _("template param type '%s' defined within parent '%s'"),
20653 name
? name
: "<unknown>",
20654 parent_name
? parent_name
: "<unknown>");
20658 switch (parent
->tag
)
20660 case DW_TAG_namespace
:
20661 parent_type
= read_type_die (parent
, cu
);
20662 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
20663 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
20664 Work around this problem here. */
20665 if (cu
->language
== language_cplus
20666 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
20668 /* We give a name to even anonymous namespaces. */
20669 return TYPE_TAG_NAME (parent_type
);
20670 case DW_TAG_class_type
:
20671 case DW_TAG_interface_type
:
20672 case DW_TAG_structure_type
:
20673 case DW_TAG_union_type
:
20674 case DW_TAG_module
:
20675 parent_type
= read_type_die (parent
, cu
);
20676 if (TYPE_TAG_NAME (parent_type
) != NULL
)
20677 return TYPE_TAG_NAME (parent_type
);
20679 /* An anonymous structure is only allowed non-static data
20680 members; no typedefs, no member functions, et cetera.
20681 So it does not need a prefix. */
20683 case DW_TAG_compile_unit
:
20684 case DW_TAG_partial_unit
:
20685 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
20686 if (cu
->language
== language_cplus
20687 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
20688 && die
->child
!= NULL
20689 && (die
->tag
== DW_TAG_class_type
20690 || die
->tag
== DW_TAG_structure_type
20691 || die
->tag
== DW_TAG_union_type
))
20693 char *name
= guess_full_die_structure_name (die
, cu
);
20698 case DW_TAG_enumeration_type
:
20699 parent_type
= read_type_die (parent
, cu
);
20700 if (TYPE_DECLARED_CLASS (parent_type
))
20702 if (TYPE_TAG_NAME (parent_type
) != NULL
)
20703 return TYPE_TAG_NAME (parent_type
);
20706 /* Fall through. */
20708 return determine_prefix (parent
, cu
);
20712 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
20713 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
20714 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
20715 an obconcat, otherwise allocate storage for the result. The CU argument is
20716 used to determine the language and hence, the appropriate separator. */
20718 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
20721 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
20722 int physname
, struct dwarf2_cu
*cu
)
20724 const char *lead
= "";
20727 if (suffix
== NULL
|| suffix
[0] == '\0'
20728 || prefix
== NULL
|| prefix
[0] == '\0')
20730 else if (cu
->language
== language_d
)
20732 /* For D, the 'main' function could be defined in any module, but it
20733 should never be prefixed. */
20734 if (strcmp (suffix
, "D main") == 0)
20742 else if (cu
->language
== language_fortran
&& physname
)
20744 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
20745 DW_AT_MIPS_linkage_name is preferred and used instead. */
20753 if (prefix
== NULL
)
20755 if (suffix
== NULL
)
20762 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
20764 strcpy (retval
, lead
);
20765 strcat (retval
, prefix
);
20766 strcat (retval
, sep
);
20767 strcat (retval
, suffix
);
20772 /* We have an obstack. */
20773 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
20777 /* Return sibling of die, NULL if no sibling. */
20779 static struct die_info
*
20780 sibling_die (struct die_info
*die
)
20782 return die
->sibling
;
20785 /* Get name of a die, return NULL if not found. */
20787 static const char *
20788 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
20789 struct obstack
*obstack
)
20791 if (name
&& cu
->language
== language_cplus
)
20793 std::string canon_name
= cp_canonicalize_string (name
);
20795 if (!canon_name
.empty ())
20797 if (canon_name
!= name
)
20798 name
= (const char *) obstack_copy0 (obstack
,
20799 canon_name
.c_str (),
20800 canon_name
.length ());
20807 /* Get name of a die, return NULL if not found.
20808 Anonymous namespaces are converted to their magic string. */
20810 static const char *
20811 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20813 struct attribute
*attr
;
20815 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
20816 if ((!attr
|| !DW_STRING (attr
))
20817 && die
->tag
!= DW_TAG_namespace
20818 && die
->tag
!= DW_TAG_class_type
20819 && die
->tag
!= DW_TAG_interface_type
20820 && die
->tag
!= DW_TAG_structure_type
20821 && die
->tag
!= DW_TAG_union_type
)
20826 case DW_TAG_compile_unit
:
20827 case DW_TAG_partial_unit
:
20828 /* Compilation units have a DW_AT_name that is a filename, not
20829 a source language identifier. */
20830 case DW_TAG_enumeration_type
:
20831 case DW_TAG_enumerator
:
20832 /* These tags always have simple identifiers already; no need
20833 to canonicalize them. */
20834 return DW_STRING (attr
);
20836 case DW_TAG_namespace
:
20837 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
20838 return DW_STRING (attr
);
20839 return CP_ANONYMOUS_NAMESPACE_STR
;
20841 case DW_TAG_class_type
:
20842 case DW_TAG_interface_type
:
20843 case DW_TAG_structure_type
:
20844 case DW_TAG_union_type
:
20845 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
20846 structures or unions. These were of the form "._%d" in GCC 4.1,
20847 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
20848 and GCC 4.4. We work around this problem by ignoring these. */
20849 if (attr
&& DW_STRING (attr
)
20850 && (startswith (DW_STRING (attr
), "._")
20851 || startswith (DW_STRING (attr
), "<anonymous")))
20854 /* GCC might emit a nameless typedef that has a linkage name. See
20855 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
20856 if (!attr
|| DW_STRING (attr
) == NULL
)
20858 char *demangled
= NULL
;
20860 attr
= dw2_linkage_name_attr (die
, cu
);
20861 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
20864 /* Avoid demangling DW_STRING (attr) the second time on a second
20865 call for the same DIE. */
20866 if (!DW_STRING_IS_CANONICAL (attr
))
20867 demangled
= gdb_demangle (DW_STRING (attr
), DMGL_TYPES
);
20873 /* FIXME: we already did this for the partial symbol... */
20876 obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
20877 demangled
, strlen (demangled
)));
20878 DW_STRING_IS_CANONICAL (attr
) = 1;
20881 /* Strip any leading namespaces/classes, keep only the base name.
20882 DW_AT_name for named DIEs does not contain the prefixes. */
20883 base
= strrchr (DW_STRING (attr
), ':');
20884 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
20887 return DW_STRING (attr
);
20896 if (!DW_STRING_IS_CANONICAL (attr
))
20899 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
20900 &cu
->objfile
->per_bfd
->storage_obstack
);
20901 DW_STRING_IS_CANONICAL (attr
) = 1;
20903 return DW_STRING (attr
);
20906 /* Return the die that this die in an extension of, or NULL if there
20907 is none. *EXT_CU is the CU containing DIE on input, and the CU
20908 containing the return value on output. */
20910 static struct die_info
*
20911 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
20913 struct attribute
*attr
;
20915 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
20919 return follow_die_ref (die
, attr
, ext_cu
);
20922 /* Convert a DIE tag into its string name. */
20924 static const char *
20925 dwarf_tag_name (unsigned tag
)
20927 const char *name
= get_DW_TAG_name (tag
);
20930 return "DW_TAG_<unknown>";
20935 /* Convert a DWARF attribute code into its string name. */
20937 static const char *
20938 dwarf_attr_name (unsigned attr
)
20942 #ifdef MIPS /* collides with DW_AT_HP_block_index */
20943 if (attr
== DW_AT_MIPS_fde
)
20944 return "DW_AT_MIPS_fde";
20946 if (attr
== DW_AT_HP_block_index
)
20947 return "DW_AT_HP_block_index";
20950 name
= get_DW_AT_name (attr
);
20953 return "DW_AT_<unknown>";
20958 /* Convert a DWARF value form code into its string name. */
20960 static const char *
20961 dwarf_form_name (unsigned form
)
20963 const char *name
= get_DW_FORM_name (form
);
20966 return "DW_FORM_<unknown>";
20971 static const char *
20972 dwarf_bool_name (unsigned mybool
)
20980 /* Convert a DWARF type code into its string name. */
20982 static const char *
20983 dwarf_type_encoding_name (unsigned enc
)
20985 const char *name
= get_DW_ATE_name (enc
);
20988 return "DW_ATE_<unknown>";
20994 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
20998 print_spaces (indent
, f
);
20999 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
21000 dwarf_tag_name (die
->tag
), die
->abbrev
,
21001 to_underlying (die
->sect_off
));
21003 if (die
->parent
!= NULL
)
21005 print_spaces (indent
, f
);
21006 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
21007 to_underlying (die
->parent
->sect_off
));
21010 print_spaces (indent
, f
);
21011 fprintf_unfiltered (f
, " has children: %s\n",
21012 dwarf_bool_name (die
->child
!= NULL
));
21014 print_spaces (indent
, f
);
21015 fprintf_unfiltered (f
, " attributes:\n");
21017 for (i
= 0; i
< die
->num_attrs
; ++i
)
21019 print_spaces (indent
, f
);
21020 fprintf_unfiltered (f
, " %s (%s) ",
21021 dwarf_attr_name (die
->attrs
[i
].name
),
21022 dwarf_form_name (die
->attrs
[i
].form
));
21024 switch (die
->attrs
[i
].form
)
21027 case DW_FORM_GNU_addr_index
:
21028 fprintf_unfiltered (f
, "address: ");
21029 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
21031 case DW_FORM_block2
:
21032 case DW_FORM_block4
:
21033 case DW_FORM_block
:
21034 case DW_FORM_block1
:
21035 fprintf_unfiltered (f
, "block: size %s",
21036 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21038 case DW_FORM_exprloc
:
21039 fprintf_unfiltered (f
, "expression: size %s",
21040 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21042 case DW_FORM_data16
:
21043 fprintf_unfiltered (f
, "constant of 16 bytes");
21045 case DW_FORM_ref_addr
:
21046 fprintf_unfiltered (f
, "ref address: ");
21047 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21049 case DW_FORM_GNU_ref_alt
:
21050 fprintf_unfiltered (f
, "alt ref address: ");
21051 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21057 case DW_FORM_ref_udata
:
21058 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
21059 (long) (DW_UNSND (&die
->attrs
[i
])));
21061 case DW_FORM_data1
:
21062 case DW_FORM_data2
:
21063 case DW_FORM_data4
:
21064 case DW_FORM_data8
:
21065 case DW_FORM_udata
:
21066 case DW_FORM_sdata
:
21067 fprintf_unfiltered (f
, "constant: %s",
21068 pulongest (DW_UNSND (&die
->attrs
[i
])));
21070 case DW_FORM_sec_offset
:
21071 fprintf_unfiltered (f
, "section offset: %s",
21072 pulongest (DW_UNSND (&die
->attrs
[i
])));
21074 case DW_FORM_ref_sig8
:
21075 fprintf_unfiltered (f
, "signature: %s",
21076 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
21078 case DW_FORM_string
:
21080 case DW_FORM_line_strp
:
21081 case DW_FORM_GNU_str_index
:
21082 case DW_FORM_GNU_strp_alt
:
21083 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
21084 DW_STRING (&die
->attrs
[i
])
21085 ? DW_STRING (&die
->attrs
[i
]) : "",
21086 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
21089 if (DW_UNSND (&die
->attrs
[i
]))
21090 fprintf_unfiltered (f
, "flag: TRUE");
21092 fprintf_unfiltered (f
, "flag: FALSE");
21094 case DW_FORM_flag_present
:
21095 fprintf_unfiltered (f
, "flag: TRUE");
21097 case DW_FORM_indirect
:
21098 /* The reader will have reduced the indirect form to
21099 the "base form" so this form should not occur. */
21100 fprintf_unfiltered (f
,
21101 "unexpected attribute form: DW_FORM_indirect");
21103 case DW_FORM_implicit_const
:
21104 fprintf_unfiltered (f
, "constant: %s",
21105 plongest (DW_SND (&die
->attrs
[i
])));
21108 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
21109 die
->attrs
[i
].form
);
21112 fprintf_unfiltered (f
, "\n");
21117 dump_die_for_error (struct die_info
*die
)
21119 dump_die_shallow (gdb_stderr
, 0, die
);
21123 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
21125 int indent
= level
* 4;
21127 gdb_assert (die
!= NULL
);
21129 if (level
>= max_level
)
21132 dump_die_shallow (f
, indent
, die
);
21134 if (die
->child
!= NULL
)
21136 print_spaces (indent
, f
);
21137 fprintf_unfiltered (f
, " Children:");
21138 if (level
+ 1 < max_level
)
21140 fprintf_unfiltered (f
, "\n");
21141 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
21145 fprintf_unfiltered (f
,
21146 " [not printed, max nesting level reached]\n");
21150 if (die
->sibling
!= NULL
&& level
> 0)
21152 dump_die_1 (f
, level
, max_level
, die
->sibling
);
21156 /* This is called from the pdie macro in gdbinit.in.
21157 It's not static so gcc will keep a copy callable from gdb. */
21160 dump_die (struct die_info
*die
, int max_level
)
21162 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
21166 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
21170 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
21171 to_underlying (die
->sect_off
),
21177 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
21181 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
21183 if (attr_form_is_ref (attr
))
21184 return (sect_offset
) DW_UNSND (attr
);
21186 complaint (&symfile_complaints
,
21187 _("unsupported die ref attribute form: '%s'"),
21188 dwarf_form_name (attr
->form
));
21192 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
21193 * the value held by the attribute is not constant. */
21196 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
21198 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
21199 return DW_SND (attr
);
21200 else if (attr
->form
== DW_FORM_udata
21201 || attr
->form
== DW_FORM_data1
21202 || attr
->form
== DW_FORM_data2
21203 || attr
->form
== DW_FORM_data4
21204 || attr
->form
== DW_FORM_data8
)
21205 return DW_UNSND (attr
);
21208 /* For DW_FORM_data16 see attr_form_is_constant. */
21209 complaint (&symfile_complaints
,
21210 _("Attribute value is not a constant (%s)"),
21211 dwarf_form_name (attr
->form
));
21212 return default_value
;
21216 /* Follow reference or signature attribute ATTR of SRC_DIE.
21217 On entry *REF_CU is the CU of SRC_DIE.
21218 On exit *REF_CU is the CU of the result. */
21220 static struct die_info
*
21221 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
21222 struct dwarf2_cu
**ref_cu
)
21224 struct die_info
*die
;
21226 if (attr_form_is_ref (attr
))
21227 die
= follow_die_ref (src_die
, attr
, ref_cu
);
21228 else if (attr
->form
== DW_FORM_ref_sig8
)
21229 die
= follow_die_sig (src_die
, attr
, ref_cu
);
21232 dump_die_for_error (src_die
);
21233 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
21234 objfile_name ((*ref_cu
)->objfile
));
21240 /* Follow reference OFFSET.
21241 On entry *REF_CU is the CU of the source die referencing OFFSET.
21242 On exit *REF_CU is the CU of the result.
21243 Returns NULL if OFFSET is invalid. */
21245 static struct die_info
*
21246 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
21247 struct dwarf2_cu
**ref_cu
)
21249 struct die_info temp_die
;
21250 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
21252 gdb_assert (cu
->per_cu
!= NULL
);
21256 if (cu
->per_cu
->is_debug_types
)
21258 /* .debug_types CUs cannot reference anything outside their CU.
21259 If they need to, they have to reference a signatured type via
21260 DW_FORM_ref_sig8. */
21261 if (!offset_in_cu_p (&cu
->header
, sect_off
))
21264 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
21265 || !offset_in_cu_p (&cu
->header
, sect_off
))
21267 struct dwarf2_per_cu_data
*per_cu
;
21269 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
21272 /* If necessary, add it to the queue and load its DIEs. */
21273 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
21274 load_full_comp_unit (per_cu
, cu
->language
);
21276 target_cu
= per_cu
->cu
;
21278 else if (cu
->dies
== NULL
)
21280 /* We're loading full DIEs during partial symbol reading. */
21281 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
21282 load_full_comp_unit (cu
->per_cu
, language_minimal
);
21285 *ref_cu
= target_cu
;
21286 temp_die
.sect_off
= sect_off
;
21287 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
21289 to_underlying (sect_off
));
21292 /* Follow reference attribute ATTR of SRC_DIE.
21293 On entry *REF_CU is the CU of SRC_DIE.
21294 On exit *REF_CU is the CU of the result. */
21296 static struct die_info
*
21297 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
21298 struct dwarf2_cu
**ref_cu
)
21300 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21301 struct dwarf2_cu
*cu
= *ref_cu
;
21302 struct die_info
*die
;
21304 die
= follow_die_offset (sect_off
,
21305 (attr
->form
== DW_FORM_GNU_ref_alt
21306 || cu
->per_cu
->is_dwz
),
21309 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
21310 "at 0x%x [in module %s]"),
21311 to_underlying (sect_off
), to_underlying (src_die
->sect_off
),
21312 objfile_name (cu
->objfile
));
21317 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
21318 Returned value is intended for DW_OP_call*. Returned
21319 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
21321 struct dwarf2_locexpr_baton
21322 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
21323 struct dwarf2_per_cu_data
*per_cu
,
21324 CORE_ADDR (*get_frame_pc
) (void *baton
),
21327 struct dwarf2_cu
*cu
;
21328 struct die_info
*die
;
21329 struct attribute
*attr
;
21330 struct dwarf2_locexpr_baton retval
;
21332 dw2_setup (per_cu
->objfile
);
21334 if (per_cu
->cu
== NULL
)
21339 /* We shouldn't get here for a dummy CU, but don't crash on the user.
21340 Instead just throw an error, not much else we can do. */
21341 error (_("Dwarf Error: Dummy CU at 0x%x referenced in module %s"),
21342 to_underlying (sect_off
), objfile_name (per_cu
->objfile
));
21345 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
21347 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
21348 to_underlying (sect_off
), objfile_name (per_cu
->objfile
));
21350 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21353 /* DWARF: "If there is no such attribute, then there is no effect.".
21354 DATA is ignored if SIZE is 0. */
21356 retval
.data
= NULL
;
21359 else if (attr_form_is_section_offset (attr
))
21361 struct dwarf2_loclist_baton loclist_baton
;
21362 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
21365 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
21367 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
21369 retval
.size
= size
;
21373 if (!attr_form_is_block (attr
))
21374 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
21375 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
21376 to_underlying (sect_off
), objfile_name (per_cu
->objfile
));
21378 retval
.data
= DW_BLOCK (attr
)->data
;
21379 retval
.size
= DW_BLOCK (attr
)->size
;
21381 retval
.per_cu
= cu
->per_cu
;
21383 age_cached_comp_units ();
21388 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
21391 struct dwarf2_locexpr_baton
21392 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
21393 struct dwarf2_per_cu_data
*per_cu
,
21394 CORE_ADDR (*get_frame_pc
) (void *baton
),
21397 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
21399 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
21402 /* Write a constant of a given type as target-ordered bytes into
21405 static const gdb_byte
*
21406 write_constant_as_bytes (struct obstack
*obstack
,
21407 enum bfd_endian byte_order
,
21414 *len
= TYPE_LENGTH (type
);
21415 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
21416 store_unsigned_integer (result
, *len
, byte_order
, value
);
21421 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
21422 pointer to the constant bytes and set LEN to the length of the
21423 data. If memory is needed, allocate it on OBSTACK. If the DIE
21424 does not have a DW_AT_const_value, return NULL. */
21427 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
21428 struct dwarf2_per_cu_data
*per_cu
,
21429 struct obstack
*obstack
,
21432 struct dwarf2_cu
*cu
;
21433 struct die_info
*die
;
21434 struct attribute
*attr
;
21435 const gdb_byte
*result
= NULL
;
21438 enum bfd_endian byte_order
;
21440 dw2_setup (per_cu
->objfile
);
21442 if (per_cu
->cu
== NULL
)
21447 /* We shouldn't get here for a dummy CU, but don't crash on the user.
21448 Instead just throw an error, not much else we can do. */
21449 error (_("Dwarf Error: Dummy CU at 0x%x referenced in module %s"),
21450 to_underlying (sect_off
), objfile_name (per_cu
->objfile
));
21453 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
21455 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
21456 to_underlying (sect_off
), objfile_name (per_cu
->objfile
));
21459 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21463 byte_order
= (bfd_big_endian (per_cu
->objfile
->obfd
)
21464 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21466 switch (attr
->form
)
21469 case DW_FORM_GNU_addr_index
:
21473 *len
= cu
->header
.addr_size
;
21474 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
21475 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
21479 case DW_FORM_string
:
21481 case DW_FORM_GNU_str_index
:
21482 case DW_FORM_GNU_strp_alt
:
21483 /* DW_STRING is already allocated on the objfile obstack, point
21485 result
= (const gdb_byte
*) DW_STRING (attr
);
21486 *len
= strlen (DW_STRING (attr
));
21488 case DW_FORM_block1
:
21489 case DW_FORM_block2
:
21490 case DW_FORM_block4
:
21491 case DW_FORM_block
:
21492 case DW_FORM_exprloc
:
21493 case DW_FORM_data16
:
21494 result
= DW_BLOCK (attr
)->data
;
21495 *len
= DW_BLOCK (attr
)->size
;
21498 /* The DW_AT_const_value attributes are supposed to carry the
21499 symbol's value "represented as it would be on the target
21500 architecture." By the time we get here, it's already been
21501 converted to host endianness, so we just need to sign- or
21502 zero-extend it as appropriate. */
21503 case DW_FORM_data1
:
21504 type
= die_type (die
, cu
);
21505 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
21506 if (result
== NULL
)
21507 result
= write_constant_as_bytes (obstack
, byte_order
,
21510 case DW_FORM_data2
:
21511 type
= die_type (die
, cu
);
21512 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
21513 if (result
== NULL
)
21514 result
= write_constant_as_bytes (obstack
, byte_order
,
21517 case DW_FORM_data4
:
21518 type
= die_type (die
, cu
);
21519 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
21520 if (result
== NULL
)
21521 result
= write_constant_as_bytes (obstack
, byte_order
,
21524 case DW_FORM_data8
:
21525 type
= die_type (die
, cu
);
21526 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
21527 if (result
== NULL
)
21528 result
= write_constant_as_bytes (obstack
, byte_order
,
21532 case DW_FORM_sdata
:
21533 case DW_FORM_implicit_const
:
21534 type
= die_type (die
, cu
);
21535 result
= write_constant_as_bytes (obstack
, byte_order
,
21536 type
, DW_SND (attr
), len
);
21539 case DW_FORM_udata
:
21540 type
= die_type (die
, cu
);
21541 result
= write_constant_as_bytes (obstack
, byte_order
,
21542 type
, DW_UNSND (attr
), len
);
21546 complaint (&symfile_complaints
,
21547 _("unsupported const value attribute form: '%s'"),
21548 dwarf_form_name (attr
->form
));
21555 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
21556 valid type for this die is found. */
21559 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
21560 struct dwarf2_per_cu_data
*per_cu
)
21562 struct dwarf2_cu
*cu
;
21563 struct die_info
*die
;
21565 dw2_setup (per_cu
->objfile
);
21567 if (per_cu
->cu
== NULL
)
21573 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
21577 return die_type (die
, cu
);
21580 /* Return the type of the DIE at DIE_OFFSET in the CU named by
21584 dwarf2_get_die_type (cu_offset die_offset
,
21585 struct dwarf2_per_cu_data
*per_cu
)
21587 dw2_setup (per_cu
->objfile
);
21589 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
21590 return get_die_type_at_offset (die_offset_sect
, per_cu
);
21593 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
21594 On entry *REF_CU is the CU of SRC_DIE.
21595 On exit *REF_CU is the CU of the result.
21596 Returns NULL if the referenced DIE isn't found. */
21598 static struct die_info
*
21599 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
21600 struct dwarf2_cu
**ref_cu
)
21602 struct die_info temp_die
;
21603 struct dwarf2_cu
*sig_cu
;
21604 struct die_info
*die
;
21606 /* While it might be nice to assert sig_type->type == NULL here,
21607 we can get here for DW_AT_imported_declaration where we need
21608 the DIE not the type. */
21610 /* If necessary, add it to the queue and load its DIEs. */
21612 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
21613 read_signatured_type (sig_type
);
21615 sig_cu
= sig_type
->per_cu
.cu
;
21616 gdb_assert (sig_cu
!= NULL
);
21617 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
21618 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
21619 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
21620 to_underlying (temp_die
.sect_off
));
21623 /* For .gdb_index version 7 keep track of included TUs.
21624 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
21625 if (dwarf2_per_objfile
->index_table
!= NULL
21626 && dwarf2_per_objfile
->index_table
->version
<= 7)
21628 VEC_safe_push (dwarf2_per_cu_ptr
,
21629 (*ref_cu
)->per_cu
->imported_symtabs
,
21640 /* Follow signatured type referenced by ATTR in SRC_DIE.
21641 On entry *REF_CU is the CU of SRC_DIE.
21642 On exit *REF_CU is the CU of the result.
21643 The result is the DIE of the type.
21644 If the referenced type cannot be found an error is thrown. */
21646 static struct die_info
*
21647 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
21648 struct dwarf2_cu
**ref_cu
)
21650 ULONGEST signature
= DW_SIGNATURE (attr
);
21651 struct signatured_type
*sig_type
;
21652 struct die_info
*die
;
21654 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
21656 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
21657 /* sig_type will be NULL if the signatured type is missing from
21659 if (sig_type
== NULL
)
21661 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
21662 " from DIE at 0x%x [in module %s]"),
21663 hex_string (signature
), to_underlying (src_die
->sect_off
),
21664 objfile_name ((*ref_cu
)->objfile
));
21667 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
21670 dump_die_for_error (src_die
);
21671 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
21672 " from DIE at 0x%x [in module %s]"),
21673 hex_string (signature
), to_underlying (src_die
->sect_off
),
21674 objfile_name ((*ref_cu
)->objfile
));
21680 /* Get the type specified by SIGNATURE referenced in DIE/CU,
21681 reading in and processing the type unit if necessary. */
21683 static struct type
*
21684 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
21685 struct dwarf2_cu
*cu
)
21687 struct signatured_type
*sig_type
;
21688 struct dwarf2_cu
*type_cu
;
21689 struct die_info
*type_die
;
21692 sig_type
= lookup_signatured_type (cu
, signature
);
21693 /* sig_type will be NULL if the signatured type is missing from
21695 if (sig_type
== NULL
)
21697 complaint (&symfile_complaints
,
21698 _("Dwarf Error: Cannot find signatured DIE %s referenced"
21699 " from DIE at 0x%x [in module %s]"),
21700 hex_string (signature
), to_underlying (die
->sect_off
),
21701 objfile_name (dwarf2_per_objfile
->objfile
));
21702 return build_error_marker_type (cu
, die
);
21705 /* If we already know the type we're done. */
21706 if (sig_type
->type
!= NULL
)
21707 return sig_type
->type
;
21710 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
21711 if (type_die
!= NULL
)
21713 /* N.B. We need to call get_die_type to ensure only one type for this DIE
21714 is created. This is important, for example, because for c++ classes
21715 we need TYPE_NAME set which is only done by new_symbol. Blech. */
21716 type
= read_type_die (type_die
, type_cu
);
21719 complaint (&symfile_complaints
,
21720 _("Dwarf Error: Cannot build signatured type %s"
21721 " referenced from DIE at 0x%x [in module %s]"),
21722 hex_string (signature
), to_underlying (die
->sect_off
),
21723 objfile_name (dwarf2_per_objfile
->objfile
));
21724 type
= build_error_marker_type (cu
, die
);
21729 complaint (&symfile_complaints
,
21730 _("Dwarf Error: Problem reading signatured DIE %s referenced"
21731 " from DIE at 0x%x [in module %s]"),
21732 hex_string (signature
), to_underlying (die
->sect_off
),
21733 objfile_name (dwarf2_per_objfile
->objfile
));
21734 type
= build_error_marker_type (cu
, die
);
21736 sig_type
->type
= type
;
21741 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
21742 reading in and processing the type unit if necessary. */
21744 static struct type
*
21745 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
21746 struct dwarf2_cu
*cu
) /* ARI: editCase function */
21748 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
21749 if (attr_form_is_ref (attr
))
21751 struct dwarf2_cu
*type_cu
= cu
;
21752 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
21754 return read_type_die (type_die
, type_cu
);
21756 else if (attr
->form
== DW_FORM_ref_sig8
)
21758 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
21762 complaint (&symfile_complaints
,
21763 _("Dwarf Error: DW_AT_signature has bad form %s in DIE"
21764 " at 0x%x [in module %s]"),
21765 dwarf_form_name (attr
->form
), to_underlying (die
->sect_off
),
21766 objfile_name (dwarf2_per_objfile
->objfile
));
21767 return build_error_marker_type (cu
, die
);
21771 /* Load the DIEs associated with type unit PER_CU into memory. */
21774 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
21776 struct signatured_type
*sig_type
;
21778 /* Caller is responsible for ensuring type_unit_groups don't get here. */
21779 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
21781 /* We have the per_cu, but we need the signatured_type.
21782 Fortunately this is an easy translation. */
21783 gdb_assert (per_cu
->is_debug_types
);
21784 sig_type
= (struct signatured_type
*) per_cu
;
21786 gdb_assert (per_cu
->cu
== NULL
);
21788 read_signatured_type (sig_type
);
21790 gdb_assert (per_cu
->cu
!= NULL
);
21793 /* die_reader_func for read_signatured_type.
21794 This is identical to load_full_comp_unit_reader,
21795 but is kept separate for now. */
21798 read_signatured_type_reader (const struct die_reader_specs
*reader
,
21799 const gdb_byte
*info_ptr
,
21800 struct die_info
*comp_unit_die
,
21804 struct dwarf2_cu
*cu
= reader
->cu
;
21806 gdb_assert (cu
->die_hash
== NULL
);
21808 htab_create_alloc_ex (cu
->header
.length
/ 12,
21812 &cu
->comp_unit_obstack
,
21813 hashtab_obstack_allocate
,
21814 dummy_obstack_deallocate
);
21817 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
21818 &info_ptr
, comp_unit_die
);
21819 cu
->dies
= comp_unit_die
;
21820 /* comp_unit_die is not stored in die_hash, no need. */
21822 /* We try not to read any attributes in this function, because not
21823 all CUs needed for references have been loaded yet, and symbol
21824 table processing isn't initialized. But we have to set the CU language,
21825 or we won't be able to build types correctly.
21826 Similarly, if we do not read the producer, we can not apply
21827 producer-specific interpretation. */
21828 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
21831 /* Read in a signatured type and build its CU and DIEs.
21832 If the type is a stub for the real type in a DWO file,
21833 read in the real type from the DWO file as well. */
21836 read_signatured_type (struct signatured_type
*sig_type
)
21838 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
21840 gdb_assert (per_cu
->is_debug_types
);
21841 gdb_assert (per_cu
->cu
== NULL
);
21843 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1,
21844 read_signatured_type_reader
, NULL
);
21845 sig_type
->per_cu
.tu_read
= 1;
21848 /* Decode simple location descriptions.
21849 Given a pointer to a dwarf block that defines a location, compute
21850 the location and return the value.
21852 NOTE drow/2003-11-18: This function is called in two situations
21853 now: for the address of static or global variables (partial symbols
21854 only) and for offsets into structures which are expected to be
21855 (more or less) constant. The partial symbol case should go away,
21856 and only the constant case should remain. That will let this
21857 function complain more accurately. A few special modes are allowed
21858 without complaint for global variables (for instance, global
21859 register values and thread-local values).
21861 A location description containing no operations indicates that the
21862 object is optimized out. The return value is 0 for that case.
21863 FIXME drow/2003-11-16: No callers check for this case any more; soon all
21864 callers will only want a very basic result and this can become a
21867 Note that stack[0] is unused except as a default error return. */
21870 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
21872 struct objfile
*objfile
= cu
->objfile
;
21874 size_t size
= blk
->size
;
21875 const gdb_byte
*data
= blk
->data
;
21876 CORE_ADDR stack
[64];
21878 unsigned int bytes_read
, unsnd
;
21884 stack
[++stacki
] = 0;
21923 stack
[++stacki
] = op
- DW_OP_lit0
;
21958 stack
[++stacki
] = op
- DW_OP_reg0
;
21960 dwarf2_complex_location_expr_complaint ();
21964 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
21966 stack
[++stacki
] = unsnd
;
21968 dwarf2_complex_location_expr_complaint ();
21972 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
21977 case DW_OP_const1u
:
21978 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
21982 case DW_OP_const1s
:
21983 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
21987 case DW_OP_const2u
:
21988 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
21992 case DW_OP_const2s
:
21993 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
21997 case DW_OP_const4u
:
21998 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
22002 case DW_OP_const4s
:
22003 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
22007 case DW_OP_const8u
:
22008 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
22013 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
22019 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
22024 stack
[stacki
+ 1] = stack
[stacki
];
22029 stack
[stacki
- 1] += stack
[stacki
];
22033 case DW_OP_plus_uconst
:
22034 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
22040 stack
[stacki
- 1] -= stack
[stacki
];
22045 /* If we're not the last op, then we definitely can't encode
22046 this using GDB's address_class enum. This is valid for partial
22047 global symbols, although the variable's address will be bogus
22050 dwarf2_complex_location_expr_complaint ();
22053 case DW_OP_GNU_push_tls_address
:
22054 case DW_OP_form_tls_address
:
22055 /* The top of the stack has the offset from the beginning
22056 of the thread control block at which the variable is located. */
22057 /* Nothing should follow this operator, so the top of stack would
22059 /* This is valid for partial global symbols, but the variable's
22060 address will be bogus in the psymtab. Make it always at least
22061 non-zero to not look as a variable garbage collected by linker
22062 which have DW_OP_addr 0. */
22064 dwarf2_complex_location_expr_complaint ();
22068 case DW_OP_GNU_uninit
:
22071 case DW_OP_GNU_addr_index
:
22072 case DW_OP_GNU_const_index
:
22073 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
22080 const char *name
= get_DW_OP_name (op
);
22083 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
22086 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
22090 return (stack
[stacki
]);
22093 /* Enforce maximum stack depth of SIZE-1 to avoid writing
22094 outside of the allocated space. Also enforce minimum>0. */
22095 if (stacki
>= ARRAY_SIZE (stack
) - 1)
22097 complaint (&symfile_complaints
,
22098 _("location description stack overflow"));
22104 complaint (&symfile_complaints
,
22105 _("location description stack underflow"));
22109 return (stack
[stacki
]);
22112 /* memory allocation interface */
22114 static struct dwarf_block
*
22115 dwarf_alloc_block (struct dwarf2_cu
*cu
)
22117 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
22120 static struct die_info
*
22121 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
22123 struct die_info
*die
;
22124 size_t size
= sizeof (struct die_info
);
22127 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
22129 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
22130 memset (die
, 0, sizeof (struct die_info
));
22135 /* Macro support. */
22137 /* Return file name relative to the compilation directory of file number I in
22138 *LH's file name table. The result is allocated using xmalloc; the caller is
22139 responsible for freeing it. */
22142 file_file_name (int file
, struct line_header
*lh
)
22144 /* Is the file number a valid index into the line header's file name
22145 table? Remember that file numbers start with one, not zero. */
22146 if (1 <= file
&& file
<= lh
->file_names
.size ())
22148 const file_entry
&fe
= lh
->file_names
[file
- 1];
22150 if (!IS_ABSOLUTE_PATH (fe
.name
))
22152 const char *dir
= fe
.include_dir (lh
);
22154 return concat (dir
, SLASH_STRING
, fe
.name
, (char *) NULL
);
22156 return xstrdup (fe
.name
);
22160 /* The compiler produced a bogus file number. We can at least
22161 record the macro definitions made in the file, even if we
22162 won't be able to find the file by name. */
22163 char fake_name
[80];
22165 xsnprintf (fake_name
, sizeof (fake_name
),
22166 "<bad macro file number %d>", file
);
22168 complaint (&symfile_complaints
,
22169 _("bad file number in macro information (%d)"),
22172 return xstrdup (fake_name
);
22176 /* Return the full name of file number I in *LH's file name table.
22177 Use COMP_DIR as the name of the current directory of the
22178 compilation. The result is allocated using xmalloc; the caller is
22179 responsible for freeing it. */
22181 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
22183 /* Is the file number a valid index into the line header's file name
22184 table? Remember that file numbers start with one, not zero. */
22185 if (1 <= file
&& file
<= lh
->file_names
.size ())
22187 char *relative
= file_file_name (file
, lh
);
22189 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
22191 return reconcat (relative
, comp_dir
, SLASH_STRING
,
22192 relative
, (char *) NULL
);
22195 return file_file_name (file
, lh
);
22199 static struct macro_source_file
*
22200 macro_start_file (int file
, int line
,
22201 struct macro_source_file
*current_file
,
22202 struct line_header
*lh
)
22204 /* File name relative to the compilation directory of this source file. */
22205 char *file_name
= file_file_name (file
, lh
);
22207 if (! current_file
)
22209 /* Note: We don't create a macro table for this compilation unit
22210 at all until we actually get a filename. */
22211 struct macro_table
*macro_table
= get_macro_table ();
22213 /* If we have no current file, then this must be the start_file
22214 directive for the compilation unit's main source file. */
22215 current_file
= macro_set_main (macro_table
, file_name
);
22216 macro_define_special (macro_table
);
22219 current_file
= macro_include (current_file
, line
, file_name
);
22223 return current_file
;
22226 static const char *
22227 consume_improper_spaces (const char *p
, const char *body
)
22231 complaint (&symfile_complaints
,
22232 _("macro definition contains spaces "
22233 "in formal argument list:\n`%s'"),
22245 parse_macro_definition (struct macro_source_file
*file
, int line
,
22250 /* The body string takes one of two forms. For object-like macro
22251 definitions, it should be:
22253 <macro name> " " <definition>
22255 For function-like macro definitions, it should be:
22257 <macro name> "() " <definition>
22259 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
22261 Spaces may appear only where explicitly indicated, and in the
22264 The Dwarf 2 spec says that an object-like macro's name is always
22265 followed by a space, but versions of GCC around March 2002 omit
22266 the space when the macro's definition is the empty string.
22268 The Dwarf 2 spec says that there should be no spaces between the
22269 formal arguments in a function-like macro's formal argument list,
22270 but versions of GCC around March 2002 include spaces after the
22274 /* Find the extent of the macro name. The macro name is terminated
22275 by either a space or null character (for an object-like macro) or
22276 an opening paren (for a function-like macro). */
22277 for (p
= body
; *p
; p
++)
22278 if (*p
== ' ' || *p
== '(')
22281 if (*p
== ' ' || *p
== '\0')
22283 /* It's an object-like macro. */
22284 int name_len
= p
- body
;
22285 char *name
= savestring (body
, name_len
);
22286 const char *replacement
;
22289 replacement
= body
+ name_len
+ 1;
22292 dwarf2_macro_malformed_definition_complaint (body
);
22293 replacement
= body
+ name_len
;
22296 macro_define_object (file
, line
, name
, replacement
);
22300 else if (*p
== '(')
22302 /* It's a function-like macro. */
22303 char *name
= savestring (body
, p
- body
);
22306 char **argv
= XNEWVEC (char *, argv_size
);
22310 p
= consume_improper_spaces (p
, body
);
22312 /* Parse the formal argument list. */
22313 while (*p
&& *p
!= ')')
22315 /* Find the extent of the current argument name. */
22316 const char *arg_start
= p
;
22318 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
22321 if (! *p
|| p
== arg_start
)
22322 dwarf2_macro_malformed_definition_complaint (body
);
22325 /* Make sure argv has room for the new argument. */
22326 if (argc
>= argv_size
)
22329 argv
= XRESIZEVEC (char *, argv
, argv_size
);
22332 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
22335 p
= consume_improper_spaces (p
, body
);
22337 /* Consume the comma, if present. */
22342 p
= consume_improper_spaces (p
, body
);
22351 /* Perfectly formed definition, no complaints. */
22352 macro_define_function (file
, line
, name
,
22353 argc
, (const char **) argv
,
22355 else if (*p
== '\0')
22357 /* Complain, but do define it. */
22358 dwarf2_macro_malformed_definition_complaint (body
);
22359 macro_define_function (file
, line
, name
,
22360 argc
, (const char **) argv
,
22364 /* Just complain. */
22365 dwarf2_macro_malformed_definition_complaint (body
);
22368 /* Just complain. */
22369 dwarf2_macro_malformed_definition_complaint (body
);
22375 for (i
= 0; i
< argc
; i
++)
22381 dwarf2_macro_malformed_definition_complaint (body
);
22384 /* Skip some bytes from BYTES according to the form given in FORM.
22385 Returns the new pointer. */
22387 static const gdb_byte
*
22388 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
22389 enum dwarf_form form
,
22390 unsigned int offset_size
,
22391 struct dwarf2_section_info
*section
)
22393 unsigned int bytes_read
;
22397 case DW_FORM_data1
:
22402 case DW_FORM_data2
:
22406 case DW_FORM_data4
:
22410 case DW_FORM_data8
:
22414 case DW_FORM_data16
:
22418 case DW_FORM_string
:
22419 read_direct_string (abfd
, bytes
, &bytes_read
);
22420 bytes
+= bytes_read
;
22423 case DW_FORM_sec_offset
:
22425 case DW_FORM_GNU_strp_alt
:
22426 bytes
+= offset_size
;
22429 case DW_FORM_block
:
22430 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
22431 bytes
+= bytes_read
;
22434 case DW_FORM_block1
:
22435 bytes
+= 1 + read_1_byte (abfd
, bytes
);
22437 case DW_FORM_block2
:
22438 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
22440 case DW_FORM_block4
:
22441 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
22444 case DW_FORM_sdata
:
22445 case DW_FORM_udata
:
22446 case DW_FORM_GNU_addr_index
:
22447 case DW_FORM_GNU_str_index
:
22448 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
22451 dwarf2_section_buffer_overflow_complaint (section
);
22456 case DW_FORM_implicit_const
:
22462 complaint (&symfile_complaints
,
22463 _("invalid form 0x%x in `%s'"),
22464 form
, get_section_name (section
));
22472 /* A helper for dwarf_decode_macros that handles skipping an unknown
22473 opcode. Returns an updated pointer to the macro data buffer; or,
22474 on error, issues a complaint and returns NULL. */
22476 static const gdb_byte
*
22477 skip_unknown_opcode (unsigned int opcode
,
22478 const gdb_byte
**opcode_definitions
,
22479 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
22481 unsigned int offset_size
,
22482 struct dwarf2_section_info
*section
)
22484 unsigned int bytes_read
, i
;
22486 const gdb_byte
*defn
;
22488 if (opcode_definitions
[opcode
] == NULL
)
22490 complaint (&symfile_complaints
,
22491 _("unrecognized DW_MACFINO opcode 0x%x"),
22496 defn
= opcode_definitions
[opcode
];
22497 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
22498 defn
+= bytes_read
;
22500 for (i
= 0; i
< arg
; ++i
)
22502 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
22503 (enum dwarf_form
) defn
[i
], offset_size
,
22505 if (mac_ptr
== NULL
)
22507 /* skip_form_bytes already issued the complaint. */
22515 /* A helper function which parses the header of a macro section.
22516 If the macro section is the extended (for now called "GNU") type,
22517 then this updates *OFFSET_SIZE. Returns a pointer to just after
22518 the header, or issues a complaint and returns NULL on error. */
22520 static const gdb_byte
*
22521 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
22523 const gdb_byte
*mac_ptr
,
22524 unsigned int *offset_size
,
22525 int section_is_gnu
)
22527 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
22529 if (section_is_gnu
)
22531 unsigned int version
, flags
;
22533 version
= read_2_bytes (abfd
, mac_ptr
);
22534 if (version
!= 4 && version
!= 5)
22536 complaint (&symfile_complaints
,
22537 _("unrecognized version `%d' in .debug_macro section"),
22543 flags
= read_1_byte (abfd
, mac_ptr
);
22545 *offset_size
= (flags
& 1) ? 8 : 4;
22547 if ((flags
& 2) != 0)
22548 /* We don't need the line table offset. */
22549 mac_ptr
+= *offset_size
;
22551 /* Vendor opcode descriptions. */
22552 if ((flags
& 4) != 0)
22554 unsigned int i
, count
;
22556 count
= read_1_byte (abfd
, mac_ptr
);
22558 for (i
= 0; i
< count
; ++i
)
22560 unsigned int opcode
, bytes_read
;
22563 opcode
= read_1_byte (abfd
, mac_ptr
);
22565 opcode_definitions
[opcode
] = mac_ptr
;
22566 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22567 mac_ptr
+= bytes_read
;
22576 /* A helper for dwarf_decode_macros that handles the GNU extensions,
22577 including DW_MACRO_import. */
22580 dwarf_decode_macro_bytes (bfd
*abfd
,
22581 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
22582 struct macro_source_file
*current_file
,
22583 struct line_header
*lh
,
22584 struct dwarf2_section_info
*section
,
22585 int section_is_gnu
, int section_is_dwz
,
22586 unsigned int offset_size
,
22587 htab_t include_hash
)
22589 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22590 enum dwarf_macro_record_type macinfo_type
;
22591 int at_commandline
;
22592 const gdb_byte
*opcode_definitions
[256];
22594 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
22595 &offset_size
, section_is_gnu
);
22596 if (mac_ptr
== NULL
)
22598 /* We already issued a complaint. */
22602 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
22603 GDB is still reading the definitions from command line. First
22604 DW_MACINFO_start_file will need to be ignored as it was already executed
22605 to create CURRENT_FILE for the main source holding also the command line
22606 definitions. On first met DW_MACINFO_start_file this flag is reset to
22607 normally execute all the remaining DW_MACINFO_start_file macinfos. */
22609 at_commandline
= 1;
22613 /* Do we at least have room for a macinfo type byte? */
22614 if (mac_ptr
>= mac_end
)
22616 dwarf2_section_buffer_overflow_complaint (section
);
22620 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
22623 /* Note that we rely on the fact that the corresponding GNU and
22624 DWARF constants are the same. */
22625 switch (macinfo_type
)
22627 /* A zero macinfo type indicates the end of the macro
22632 case DW_MACRO_define
:
22633 case DW_MACRO_undef
:
22634 case DW_MACRO_define_strp
:
22635 case DW_MACRO_undef_strp
:
22636 case DW_MACRO_define_sup
:
22637 case DW_MACRO_undef_sup
:
22639 unsigned int bytes_read
;
22644 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22645 mac_ptr
+= bytes_read
;
22647 if (macinfo_type
== DW_MACRO_define
22648 || macinfo_type
== DW_MACRO_undef
)
22650 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
22651 mac_ptr
+= bytes_read
;
22655 LONGEST str_offset
;
22657 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
22658 mac_ptr
+= offset_size
;
22660 if (macinfo_type
== DW_MACRO_define_sup
22661 || macinfo_type
== DW_MACRO_undef_sup
22664 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
22666 body
= read_indirect_string_from_dwz (dwz
, str_offset
);
22669 body
= read_indirect_string_at_offset (abfd
, str_offset
);
22672 is_define
= (macinfo_type
== DW_MACRO_define
22673 || macinfo_type
== DW_MACRO_define_strp
22674 || macinfo_type
== DW_MACRO_define_sup
);
22675 if (! current_file
)
22677 /* DWARF violation as no main source is present. */
22678 complaint (&symfile_complaints
,
22679 _("debug info with no main source gives macro %s "
22681 is_define
? _("definition") : _("undefinition"),
22685 if ((line
== 0 && !at_commandline
)
22686 || (line
!= 0 && at_commandline
))
22687 complaint (&symfile_complaints
,
22688 _("debug info gives %s macro %s with %s line %d: %s"),
22689 at_commandline
? _("command-line") : _("in-file"),
22690 is_define
? _("definition") : _("undefinition"),
22691 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
22694 parse_macro_definition (current_file
, line
, body
);
22697 gdb_assert (macinfo_type
== DW_MACRO_undef
22698 || macinfo_type
== DW_MACRO_undef_strp
22699 || macinfo_type
== DW_MACRO_undef_sup
);
22700 macro_undef (current_file
, line
, body
);
22705 case DW_MACRO_start_file
:
22707 unsigned int bytes_read
;
22710 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22711 mac_ptr
+= bytes_read
;
22712 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22713 mac_ptr
+= bytes_read
;
22715 if ((line
== 0 && !at_commandline
)
22716 || (line
!= 0 && at_commandline
))
22717 complaint (&symfile_complaints
,
22718 _("debug info gives source %d included "
22719 "from %s at %s line %d"),
22720 file
, at_commandline
? _("command-line") : _("file"),
22721 line
== 0 ? _("zero") : _("non-zero"), line
);
22723 if (at_commandline
)
22725 /* This DW_MACRO_start_file was executed in the
22727 at_commandline
= 0;
22730 current_file
= macro_start_file (file
, line
, current_file
, lh
);
22734 case DW_MACRO_end_file
:
22735 if (! current_file
)
22736 complaint (&symfile_complaints
,
22737 _("macro debug info has an unmatched "
22738 "`close_file' directive"));
22741 current_file
= current_file
->included_by
;
22742 if (! current_file
)
22744 enum dwarf_macro_record_type next_type
;
22746 /* GCC circa March 2002 doesn't produce the zero
22747 type byte marking the end of the compilation
22748 unit. Complain if it's not there, but exit no
22751 /* Do we at least have room for a macinfo type byte? */
22752 if (mac_ptr
>= mac_end
)
22754 dwarf2_section_buffer_overflow_complaint (section
);
22758 /* We don't increment mac_ptr here, so this is just
22761 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
22763 if (next_type
!= 0)
22764 complaint (&symfile_complaints
,
22765 _("no terminating 0-type entry for "
22766 "macros in `.debug_macinfo' section"));
22773 case DW_MACRO_import
:
22774 case DW_MACRO_import_sup
:
22778 bfd
*include_bfd
= abfd
;
22779 struct dwarf2_section_info
*include_section
= section
;
22780 const gdb_byte
*include_mac_end
= mac_end
;
22781 int is_dwz
= section_is_dwz
;
22782 const gdb_byte
*new_mac_ptr
;
22784 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
22785 mac_ptr
+= offset_size
;
22787 if (macinfo_type
== DW_MACRO_import_sup
)
22789 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
22791 dwarf2_read_section (objfile
, &dwz
->macro
);
22793 include_section
= &dwz
->macro
;
22794 include_bfd
= get_section_bfd_owner (include_section
);
22795 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
22799 new_mac_ptr
= include_section
->buffer
+ offset
;
22800 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
22804 /* This has actually happened; see
22805 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
22806 complaint (&symfile_complaints
,
22807 _("recursive DW_MACRO_import in "
22808 ".debug_macro section"));
22812 *slot
= (void *) new_mac_ptr
;
22814 dwarf_decode_macro_bytes (include_bfd
, new_mac_ptr
,
22815 include_mac_end
, current_file
, lh
,
22816 section
, section_is_gnu
, is_dwz
,
22817 offset_size
, include_hash
);
22819 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
22824 case DW_MACINFO_vendor_ext
:
22825 if (!section_is_gnu
)
22827 unsigned int bytes_read
;
22829 /* This reads the constant, but since we don't recognize
22830 any vendor extensions, we ignore it. */
22831 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22832 mac_ptr
+= bytes_read
;
22833 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
22834 mac_ptr
+= bytes_read
;
22836 /* We don't recognize any vendor extensions. */
22842 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
22843 mac_ptr
, mac_end
, abfd
, offset_size
,
22845 if (mac_ptr
== NULL
)
22849 } while (macinfo_type
!= 0);
22853 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
22854 int section_is_gnu
)
22856 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22857 struct line_header
*lh
= cu
->line_header
;
22859 const gdb_byte
*mac_ptr
, *mac_end
;
22860 struct macro_source_file
*current_file
= 0;
22861 enum dwarf_macro_record_type macinfo_type
;
22862 unsigned int offset_size
= cu
->header
.offset_size
;
22863 const gdb_byte
*opcode_definitions
[256];
22865 struct dwarf2_section_info
*section
;
22866 const char *section_name
;
22868 if (cu
->dwo_unit
!= NULL
)
22870 if (section_is_gnu
)
22872 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
22873 section_name
= ".debug_macro.dwo";
22877 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
22878 section_name
= ".debug_macinfo.dwo";
22883 if (section_is_gnu
)
22885 section
= &dwarf2_per_objfile
->macro
;
22886 section_name
= ".debug_macro";
22890 section
= &dwarf2_per_objfile
->macinfo
;
22891 section_name
= ".debug_macinfo";
22895 dwarf2_read_section (objfile
, section
);
22896 if (section
->buffer
== NULL
)
22898 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
22901 abfd
= get_section_bfd_owner (section
);
22903 /* First pass: Find the name of the base filename.
22904 This filename is needed in order to process all macros whose definition
22905 (or undefinition) comes from the command line. These macros are defined
22906 before the first DW_MACINFO_start_file entry, and yet still need to be
22907 associated to the base file.
22909 To determine the base file name, we scan the macro definitions until we
22910 reach the first DW_MACINFO_start_file entry. We then initialize
22911 CURRENT_FILE accordingly so that any macro definition found before the
22912 first DW_MACINFO_start_file can still be associated to the base file. */
22914 mac_ptr
= section
->buffer
+ offset
;
22915 mac_end
= section
->buffer
+ section
->size
;
22917 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
22918 &offset_size
, section_is_gnu
);
22919 if (mac_ptr
== NULL
)
22921 /* We already issued a complaint. */
22927 /* Do we at least have room for a macinfo type byte? */
22928 if (mac_ptr
>= mac_end
)
22930 /* Complaint is printed during the second pass as GDB will probably
22931 stop the first pass earlier upon finding
22932 DW_MACINFO_start_file. */
22936 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
22939 /* Note that we rely on the fact that the corresponding GNU and
22940 DWARF constants are the same. */
22941 switch (macinfo_type
)
22943 /* A zero macinfo type indicates the end of the macro
22948 case DW_MACRO_define
:
22949 case DW_MACRO_undef
:
22950 /* Only skip the data by MAC_PTR. */
22952 unsigned int bytes_read
;
22954 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22955 mac_ptr
+= bytes_read
;
22956 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
22957 mac_ptr
+= bytes_read
;
22961 case DW_MACRO_start_file
:
22963 unsigned int bytes_read
;
22966 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22967 mac_ptr
+= bytes_read
;
22968 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22969 mac_ptr
+= bytes_read
;
22971 current_file
= macro_start_file (file
, line
, current_file
, lh
);
22975 case DW_MACRO_end_file
:
22976 /* No data to skip by MAC_PTR. */
22979 case DW_MACRO_define_strp
:
22980 case DW_MACRO_undef_strp
:
22981 case DW_MACRO_define_sup
:
22982 case DW_MACRO_undef_sup
:
22984 unsigned int bytes_read
;
22986 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22987 mac_ptr
+= bytes_read
;
22988 mac_ptr
+= offset_size
;
22992 case DW_MACRO_import
:
22993 case DW_MACRO_import_sup
:
22994 /* Note that, according to the spec, a transparent include
22995 chain cannot call DW_MACRO_start_file. So, we can just
22996 skip this opcode. */
22997 mac_ptr
+= offset_size
;
23000 case DW_MACINFO_vendor_ext
:
23001 /* Only skip the data by MAC_PTR. */
23002 if (!section_is_gnu
)
23004 unsigned int bytes_read
;
23006 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23007 mac_ptr
+= bytes_read
;
23008 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
23009 mac_ptr
+= bytes_read
;
23014 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
23015 mac_ptr
, mac_end
, abfd
, offset_size
,
23017 if (mac_ptr
== NULL
)
23021 } while (macinfo_type
!= 0 && current_file
== NULL
);
23023 /* Second pass: Process all entries.
23025 Use the AT_COMMAND_LINE flag to determine whether we are still processing
23026 command-line macro definitions/undefinitions. This flag is unset when we
23027 reach the first DW_MACINFO_start_file entry. */
23029 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
23031 NULL
, xcalloc
, xfree
));
23032 mac_ptr
= section
->buffer
+ offset
;
23033 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
23034 *slot
= (void *) mac_ptr
;
23035 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
23036 current_file
, lh
, section
,
23037 section_is_gnu
, 0, offset_size
,
23038 include_hash
.get ());
23041 /* Check if the attribute's form is a DW_FORM_block*
23042 if so return true else false. */
23045 attr_form_is_block (const struct attribute
*attr
)
23047 return (attr
== NULL
? 0 :
23048 attr
->form
== DW_FORM_block1
23049 || attr
->form
== DW_FORM_block2
23050 || attr
->form
== DW_FORM_block4
23051 || attr
->form
== DW_FORM_block
23052 || attr
->form
== DW_FORM_exprloc
);
23055 /* Return non-zero if ATTR's value is a section offset --- classes
23056 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
23057 You may use DW_UNSND (attr) to retrieve such offsets.
23059 Section 7.5.4, "Attribute Encodings", explains that no attribute
23060 may have a value that belongs to more than one of these classes; it
23061 would be ambiguous if we did, because we use the same forms for all
23065 attr_form_is_section_offset (const struct attribute
*attr
)
23067 return (attr
->form
== DW_FORM_data4
23068 || attr
->form
== DW_FORM_data8
23069 || attr
->form
== DW_FORM_sec_offset
);
23072 /* Return non-zero if ATTR's value falls in the 'constant' class, or
23073 zero otherwise. When this function returns true, you can apply
23074 dwarf2_get_attr_constant_value to it.
23076 However, note that for some attributes you must check
23077 attr_form_is_section_offset before using this test. DW_FORM_data4
23078 and DW_FORM_data8 are members of both the constant class, and of
23079 the classes that contain offsets into other debug sections
23080 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
23081 that, if an attribute's can be either a constant or one of the
23082 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
23083 taken as section offsets, not constants.
23085 DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
23086 cannot handle that. */
23089 attr_form_is_constant (const struct attribute
*attr
)
23091 switch (attr
->form
)
23093 case DW_FORM_sdata
:
23094 case DW_FORM_udata
:
23095 case DW_FORM_data1
:
23096 case DW_FORM_data2
:
23097 case DW_FORM_data4
:
23098 case DW_FORM_data8
:
23099 case DW_FORM_implicit_const
:
23107 /* DW_ADDR is always stored already as sect_offset; despite for the forms
23108 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
23111 attr_form_is_ref (const struct attribute
*attr
)
23113 switch (attr
->form
)
23115 case DW_FORM_ref_addr
:
23120 case DW_FORM_ref_udata
:
23121 case DW_FORM_GNU_ref_alt
:
23128 /* Return the .debug_loc section to use for CU.
23129 For DWO files use .debug_loc.dwo. */
23131 static struct dwarf2_section_info
*
23132 cu_debug_loc_section (struct dwarf2_cu
*cu
)
23136 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
23138 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
23140 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
23141 : &dwarf2_per_objfile
->loc
);
23144 /* A helper function that fills in a dwarf2_loclist_baton. */
23147 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
23148 struct dwarf2_loclist_baton
*baton
,
23149 const struct attribute
*attr
)
23151 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23153 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
23155 baton
->per_cu
= cu
->per_cu
;
23156 gdb_assert (baton
->per_cu
);
23157 /* We don't know how long the location list is, but make sure we
23158 don't run off the edge of the section. */
23159 baton
->size
= section
->size
- DW_UNSND (attr
);
23160 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
23161 baton
->base_address
= cu
->base_address
;
23162 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
23166 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
23167 struct dwarf2_cu
*cu
, int is_block
)
23169 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23170 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23172 if (attr_form_is_section_offset (attr
)
23173 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
23174 the section. If so, fall through to the complaint in the
23176 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
23178 struct dwarf2_loclist_baton
*baton
;
23180 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
23182 fill_in_loclist_baton (cu
, baton
, attr
);
23184 if (cu
->base_known
== 0)
23185 complaint (&symfile_complaints
,
23186 _("Location list used without "
23187 "specifying the CU base address."));
23189 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23190 ? dwarf2_loclist_block_index
23191 : dwarf2_loclist_index
);
23192 SYMBOL_LOCATION_BATON (sym
) = baton
;
23196 struct dwarf2_locexpr_baton
*baton
;
23198 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
23199 baton
->per_cu
= cu
->per_cu
;
23200 gdb_assert (baton
->per_cu
);
23202 if (attr_form_is_block (attr
))
23204 /* Note that we're just copying the block's data pointer
23205 here, not the actual data. We're still pointing into the
23206 info_buffer for SYM's objfile; right now we never release
23207 that buffer, but when we do clean up properly this may
23209 baton
->size
= DW_BLOCK (attr
)->size
;
23210 baton
->data
= DW_BLOCK (attr
)->data
;
23214 dwarf2_invalid_attrib_class_complaint ("location description",
23215 SYMBOL_NATURAL_NAME (sym
));
23219 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23220 ? dwarf2_locexpr_block_index
23221 : dwarf2_locexpr_index
);
23222 SYMBOL_LOCATION_BATON (sym
) = baton
;
23226 /* Return the OBJFILE associated with the compilation unit CU. If CU
23227 came from a separate debuginfo file, then the master objfile is
23231 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
23233 struct objfile
*objfile
= per_cu
->objfile
;
23235 /* Return the master objfile, so that we can report and look up the
23236 correct file containing this variable. */
23237 if (objfile
->separate_debug_objfile_backlink
)
23238 objfile
= objfile
->separate_debug_objfile_backlink
;
23243 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
23244 (CU_HEADERP is unused in such case) or prepare a temporary copy at
23245 CU_HEADERP first. */
23247 static const struct comp_unit_head
*
23248 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
23249 struct dwarf2_per_cu_data
*per_cu
)
23251 const gdb_byte
*info_ptr
;
23254 return &per_cu
->cu
->header
;
23256 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
23258 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
23259 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
23260 rcuh_kind::COMPILE
);
23265 /* Return the address size given in the compilation unit header for CU. */
23268 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
23270 struct comp_unit_head cu_header_local
;
23271 const struct comp_unit_head
*cu_headerp
;
23273 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
23275 return cu_headerp
->addr_size
;
23278 /* Return the offset size given in the compilation unit header for CU. */
23281 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
23283 struct comp_unit_head cu_header_local
;
23284 const struct comp_unit_head
*cu_headerp
;
23286 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
23288 return cu_headerp
->offset_size
;
23291 /* See its dwarf2loc.h declaration. */
23294 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
23296 struct comp_unit_head cu_header_local
;
23297 const struct comp_unit_head
*cu_headerp
;
23299 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
23301 if (cu_headerp
->version
== 2)
23302 return cu_headerp
->addr_size
;
23304 return cu_headerp
->offset_size
;
23307 /* Return the text offset of the CU. The returned offset comes from
23308 this CU's objfile. If this objfile came from a separate debuginfo
23309 file, then the offset may be different from the corresponding
23310 offset in the parent objfile. */
23313 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
23315 struct objfile
*objfile
= per_cu
->objfile
;
23317 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
23320 /* Return DWARF version number of PER_CU. */
23323 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
23325 return per_cu
->dwarf_version
;
23328 /* Locate the .debug_info compilation unit from CU's objfile which contains
23329 the DIE at OFFSET. Raises an error on failure. */
23331 static struct dwarf2_per_cu_data
*
23332 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
23333 unsigned int offset_in_dwz
,
23334 struct objfile
*objfile
)
23336 struct dwarf2_per_cu_data
*this_cu
;
23338 const sect_offset
*cu_off
;
23341 high
= dwarf2_per_objfile
->n_comp_units
- 1;
23344 struct dwarf2_per_cu_data
*mid_cu
;
23345 int mid
= low
+ (high
- low
) / 2;
23347 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
23348 cu_off
= &mid_cu
->sect_off
;
23349 if (mid_cu
->is_dwz
> offset_in_dwz
23350 || (mid_cu
->is_dwz
== offset_in_dwz
&& *cu_off
>= sect_off
))
23355 gdb_assert (low
== high
);
23356 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
23357 cu_off
= &this_cu
->sect_off
;
23358 if (this_cu
->is_dwz
!= offset_in_dwz
|| *cu_off
> sect_off
)
23360 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
23361 error (_("Dwarf Error: could not find partial DIE containing "
23362 "offset 0x%x [in module %s]"),
23363 to_underlying (sect_off
), bfd_get_filename (objfile
->obfd
));
23365 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
23367 return dwarf2_per_objfile
->all_comp_units
[low
-1];
23371 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
23372 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
23373 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
23374 error (_("invalid dwarf2 offset %u"), to_underlying (sect_off
));
23375 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
23380 /* Initialize dwarf2_cu CU, owned by PER_CU. */
23383 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
23385 memset (cu
, 0, sizeof (*cu
));
23387 cu
->per_cu
= per_cu
;
23388 cu
->objfile
= per_cu
->objfile
;
23389 obstack_init (&cu
->comp_unit_obstack
);
23392 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
23395 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
23396 enum language pretend_language
)
23398 struct attribute
*attr
;
23400 /* Set the language we're debugging. */
23401 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
23403 set_cu_language (DW_UNSND (attr
), cu
);
23406 cu
->language
= pretend_language
;
23407 cu
->language_defn
= language_def (cu
->language
);
23410 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
23413 /* Release one cached compilation unit, CU. We unlink it from the tree
23414 of compilation units, but we don't remove it from the read_in_chain;
23415 the caller is responsible for that.
23416 NOTE: DATA is a void * because this function is also used as a
23417 cleanup routine. */
23420 free_heap_comp_unit (void *data
)
23422 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) data
;
23424 gdb_assert (cu
->per_cu
!= NULL
);
23425 cu
->per_cu
->cu
= NULL
;
23428 obstack_free (&cu
->comp_unit_obstack
, NULL
);
23433 /* This cleanup function is passed the address of a dwarf2_cu on the stack
23434 when we're finished with it. We can't free the pointer itself, but be
23435 sure to unlink it from the cache. Also release any associated storage. */
23438 free_stack_comp_unit (void *data
)
23440 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) data
;
23442 gdb_assert (cu
->per_cu
!= NULL
);
23443 cu
->per_cu
->cu
= NULL
;
23446 obstack_free (&cu
->comp_unit_obstack
, NULL
);
23447 cu
->partial_dies
= NULL
;
23450 /* Free all cached compilation units. */
23453 free_cached_comp_units (void *data
)
23455 dwarf2_per_objfile
->free_cached_comp_units ();
23458 /* Increase the age counter on each cached compilation unit, and free
23459 any that are too old. */
23462 age_cached_comp_units (void)
23464 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23466 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
23467 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23468 while (per_cu
!= NULL
)
23470 per_cu
->cu
->last_used
++;
23471 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
23472 dwarf2_mark (per_cu
->cu
);
23473 per_cu
= per_cu
->cu
->read_in_chain
;
23476 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23477 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
23478 while (per_cu
!= NULL
)
23480 struct dwarf2_per_cu_data
*next_cu
;
23482 next_cu
= per_cu
->cu
->read_in_chain
;
23484 if (!per_cu
->cu
->mark
)
23486 free_heap_comp_unit (per_cu
->cu
);
23487 *last_chain
= next_cu
;
23490 last_chain
= &per_cu
->cu
->read_in_chain
;
23496 /* Remove a single compilation unit from the cache. */
23499 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
23501 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23503 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23504 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
23505 while (per_cu
!= NULL
)
23507 struct dwarf2_per_cu_data
*next_cu
;
23509 next_cu
= per_cu
->cu
->read_in_chain
;
23511 if (per_cu
== target_per_cu
)
23513 free_heap_comp_unit (per_cu
->cu
);
23515 *last_chain
= next_cu
;
23519 last_chain
= &per_cu
->cu
->read_in_chain
;
23525 /* Release all extra memory associated with OBJFILE. */
23528 dwarf2_free_objfile (struct objfile
*objfile
)
23531 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
23532 dwarf2_objfile_data_key
);
23534 if (dwarf2_per_objfile
== NULL
)
23537 dwarf2_per_objfile
->~dwarf2_per_objfile ();
23540 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
23541 We store these in a hash table separate from the DIEs, and preserve them
23542 when the DIEs are flushed out of cache.
23544 The CU "per_cu" pointer is needed because offset alone is not enough to
23545 uniquely identify the type. A file may have multiple .debug_types sections,
23546 or the type may come from a DWO file. Furthermore, while it's more logical
23547 to use per_cu->section+offset, with Fission the section with the data is in
23548 the DWO file but we don't know that section at the point we need it.
23549 We have to use something in dwarf2_per_cu_data (or the pointer to it)
23550 because we can enter the lookup routine, get_die_type_at_offset, from
23551 outside this file, and thus won't necessarily have PER_CU->cu.
23552 Fortunately, PER_CU is stable for the life of the objfile. */
23554 struct dwarf2_per_cu_offset_and_type
23556 const struct dwarf2_per_cu_data
*per_cu
;
23557 sect_offset sect_off
;
23561 /* Hash function for a dwarf2_per_cu_offset_and_type. */
23564 per_cu_offset_and_type_hash (const void *item
)
23566 const struct dwarf2_per_cu_offset_and_type
*ofs
23567 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
23569 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
23572 /* Equality function for a dwarf2_per_cu_offset_and_type. */
23575 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
23577 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
23578 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
23579 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
23580 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
23582 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
23583 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
23586 /* Set the type associated with DIE to TYPE. Save it in CU's hash
23587 table if necessary. For convenience, return TYPE.
23589 The DIEs reading must have careful ordering to:
23590 * Not cause infite loops trying to read in DIEs as a prerequisite for
23591 reading current DIE.
23592 * Not trying to dereference contents of still incompletely read in types
23593 while reading in other DIEs.
23594 * Enable referencing still incompletely read in types just by a pointer to
23595 the type without accessing its fields.
23597 Therefore caller should follow these rules:
23598 * Try to fetch any prerequisite types we may need to build this DIE type
23599 before building the type and calling set_die_type.
23600 * After building type call set_die_type for current DIE as soon as
23601 possible before fetching more types to complete the current type.
23602 * Make the type as complete as possible before fetching more types. */
23604 static struct type
*
23605 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
23607 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
23608 struct objfile
*objfile
= cu
->objfile
;
23609 struct attribute
*attr
;
23610 struct dynamic_prop prop
;
23612 /* For Ada types, make sure that the gnat-specific data is always
23613 initialized (if not already set). There are a few types where
23614 we should not be doing so, because the type-specific area is
23615 already used to hold some other piece of info (eg: TYPE_CODE_FLT
23616 where the type-specific area is used to store the floatformat).
23617 But this is not a problem, because the gnat-specific information
23618 is actually not needed for these types. */
23619 if (need_gnat_info (cu
)
23620 && TYPE_CODE (type
) != TYPE_CODE_FUNC
23621 && TYPE_CODE (type
) != TYPE_CODE_FLT
23622 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
23623 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
23624 && TYPE_CODE (type
) != TYPE_CODE_METHOD
23625 && !HAVE_GNAT_AUX_INFO (type
))
23626 INIT_GNAT_SPECIFIC (type
);
23628 /* Read DW_AT_allocated and set in type. */
23629 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
23630 if (attr_form_is_block (attr
))
23632 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
23633 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
, objfile
);
23635 else if (attr
!= NULL
)
23637 complaint (&symfile_complaints
,
23638 _("DW_AT_allocated has the wrong form (%s) at DIE 0x%x"),
23639 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23640 to_underlying (die
->sect_off
));
23643 /* Read DW_AT_associated and set in type. */
23644 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
23645 if (attr_form_is_block (attr
))
23647 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
23648 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
, objfile
);
23650 else if (attr
!= NULL
)
23652 complaint (&symfile_complaints
,
23653 _("DW_AT_associated has the wrong form (%s) at DIE 0x%x"),
23654 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23655 to_underlying (die
->sect_off
));
23658 /* Read DW_AT_data_location and set in type. */
23659 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
23660 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
23661 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
, objfile
);
23663 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23665 dwarf2_per_objfile
->die_type_hash
=
23666 htab_create_alloc_ex (127,
23667 per_cu_offset_and_type_hash
,
23668 per_cu_offset_and_type_eq
,
23670 &objfile
->objfile_obstack
,
23671 hashtab_obstack_allocate
,
23672 dummy_obstack_deallocate
);
23675 ofs
.per_cu
= cu
->per_cu
;
23676 ofs
.sect_off
= die
->sect_off
;
23678 slot
= (struct dwarf2_per_cu_offset_and_type
**)
23679 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
23681 complaint (&symfile_complaints
,
23682 _("A problem internal to GDB: DIE 0x%x has type already set"),
23683 to_underlying (die
->sect_off
));
23684 *slot
= XOBNEW (&objfile
->objfile_obstack
,
23685 struct dwarf2_per_cu_offset_and_type
);
23690 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
23691 or return NULL if the die does not have a saved type. */
23693 static struct type
*
23694 get_die_type_at_offset (sect_offset sect_off
,
23695 struct dwarf2_per_cu_data
*per_cu
)
23697 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
23699 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23702 ofs
.per_cu
= per_cu
;
23703 ofs
.sect_off
= sect_off
;
23704 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
23705 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
23712 /* Look up the type for DIE in CU in die_type_hash,
23713 or return NULL if DIE does not have a saved type. */
23715 static struct type
*
23716 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
23718 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
23721 /* Add a dependence relationship from CU to REF_PER_CU. */
23724 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
23725 struct dwarf2_per_cu_data
*ref_per_cu
)
23729 if (cu
->dependencies
== NULL
)
23731 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
23732 NULL
, &cu
->comp_unit_obstack
,
23733 hashtab_obstack_allocate
,
23734 dummy_obstack_deallocate
);
23736 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
23738 *slot
= ref_per_cu
;
23741 /* Subroutine of dwarf2_mark to pass to htab_traverse.
23742 Set the mark field in every compilation unit in the
23743 cache that we must keep because we are keeping CU. */
23746 dwarf2_mark_helper (void **slot
, void *data
)
23748 struct dwarf2_per_cu_data
*per_cu
;
23750 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
23752 /* cu->dependencies references may not yet have been ever read if QUIT aborts
23753 reading of the chain. As such dependencies remain valid it is not much
23754 useful to track and undo them during QUIT cleanups. */
23755 if (per_cu
->cu
== NULL
)
23758 if (per_cu
->cu
->mark
)
23760 per_cu
->cu
->mark
= 1;
23762 if (per_cu
->cu
->dependencies
!= NULL
)
23763 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23768 /* Set the mark field in CU and in every other compilation unit in the
23769 cache that we must keep because we are keeping CU. */
23772 dwarf2_mark (struct dwarf2_cu
*cu
)
23777 if (cu
->dependencies
!= NULL
)
23778 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23782 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
23786 per_cu
->cu
->mark
= 0;
23787 per_cu
= per_cu
->cu
->read_in_chain
;
23791 /* Trivial hash function for partial_die_info: the hash value of a DIE
23792 is its offset in .debug_info for this objfile. */
23795 partial_die_hash (const void *item
)
23797 const struct partial_die_info
*part_die
23798 = (const struct partial_die_info
*) item
;
23800 return to_underlying (part_die
->sect_off
);
23803 /* Trivial comparison function for partial_die_info structures: two DIEs
23804 are equal if they have the same offset. */
23807 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
23809 const struct partial_die_info
*part_die_lhs
23810 = (const struct partial_die_info
*) item_lhs
;
23811 const struct partial_die_info
*part_die_rhs
23812 = (const struct partial_die_info
*) item_rhs
;
23814 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
23817 static struct cmd_list_element
*set_dwarf_cmdlist
;
23818 static struct cmd_list_element
*show_dwarf_cmdlist
;
23821 set_dwarf_cmd (const char *args
, int from_tty
)
23823 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
23828 show_dwarf_cmd (const char *args
, int from_tty
)
23830 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
23833 /* Free data associated with OBJFILE, if necessary. */
23836 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
23838 struct dwarf2_per_objfile
*data
= (struct dwarf2_per_objfile
*) d
;
23841 /* Make sure we don't accidentally use dwarf2_per_objfile while
23843 dwarf2_per_objfile
= NULL
;
23845 for (ix
= 0; ix
< data
->n_comp_units
; ++ix
)
23846 VEC_free (dwarf2_per_cu_ptr
, data
->all_comp_units
[ix
]->imported_symtabs
);
23848 for (ix
= 0; ix
< data
->n_type_units
; ++ix
)
23849 VEC_free (dwarf2_per_cu_ptr
,
23850 data
->all_type_units
[ix
]->per_cu
.imported_symtabs
);
23851 xfree (data
->all_type_units
);
23853 VEC_free (dwarf2_section_info_def
, data
->types
);
23855 if (data
->dwo_files
)
23856 free_dwo_files (data
->dwo_files
, objfile
);
23857 if (data
->dwp_file
)
23858 gdb_bfd_unref (data
->dwp_file
->dbfd
);
23860 if (data
->dwz_file
&& data
->dwz_file
->dwz_bfd
)
23861 gdb_bfd_unref (data
->dwz_file
->dwz_bfd
);
23863 if (data
->index_table
!= NULL
)
23864 data
->index_table
->~mapped_index ();
23868 /* The "save gdb-index" command. */
23870 /* In-memory buffer to prepare data to be written later to a file. */
23874 /* Copy DATA to the end of the buffer. */
23875 template<typename T
>
23876 void append_data (const T
&data
)
23878 std::copy (reinterpret_cast<const gdb_byte
*> (&data
),
23879 reinterpret_cast<const gdb_byte
*> (&data
+ 1),
23880 grow (sizeof (data
)));
23883 /* Copy CSTR (a zero-terminated string) to the end of buffer. The
23884 terminating zero is appended too. */
23885 void append_cstr0 (const char *cstr
)
23887 const size_t size
= strlen (cstr
) + 1;
23888 std::copy (cstr
, cstr
+ size
, grow (size
));
23891 /* Accept a host-format integer in VAL and append it to the buffer
23892 as a target-format integer which is LEN bytes long. */
23893 void append_uint (size_t len
, bfd_endian byte_order
, ULONGEST val
)
23895 ::store_unsigned_integer (grow (len
), len
, byte_order
, val
);
23898 /* Return the size of the buffer. */
23899 size_t size () const
23901 return m_vec
.size ();
23904 /* Write the buffer to FILE. */
23905 void file_write (FILE *file
) const
23907 if (::fwrite (m_vec
.data (), 1, m_vec
.size (), file
) != m_vec
.size ())
23908 error (_("couldn't write data to file"));
23912 /* Grow SIZE bytes at the end of the buffer. Returns a pointer to
23913 the start of the new block. */
23914 gdb_byte
*grow (size_t size
)
23916 m_vec
.resize (m_vec
.size () + size
);
23917 return &*m_vec
.end () - size
;
23920 gdb::byte_vector m_vec
;
23923 /* An entry in the symbol table. */
23924 struct symtab_index_entry
23926 /* The name of the symbol. */
23928 /* The offset of the name in the constant pool. */
23929 offset_type index_offset
;
23930 /* A sorted vector of the indices of all the CUs that hold an object
23932 std::vector
<offset_type
> cu_indices
;
23935 /* The symbol table. This is a power-of-2-sized hash table. */
23936 struct mapped_symtab
23940 data
.resize (1024);
23943 offset_type n_elements
= 0;
23944 std::vector
<symtab_index_entry
> data
;
23947 /* Find a slot in SYMTAB for the symbol NAME. Returns a reference to
23950 Function is used only during write_hash_table so no index format backward
23951 compatibility is needed. */
23953 static symtab_index_entry
&
23954 find_slot (struct mapped_symtab
*symtab
, const char *name
)
23956 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
23958 index
= hash
& (symtab
->data
.size () - 1);
23959 step
= ((hash
* 17) & (symtab
->data
.size () - 1)) | 1;
23963 if (symtab
->data
[index
].name
== NULL
23964 || strcmp (name
, symtab
->data
[index
].name
) == 0)
23965 return symtab
->data
[index
];
23966 index
= (index
+ step
) & (symtab
->data
.size () - 1);
23970 /* Expand SYMTAB's hash table. */
23973 hash_expand (struct mapped_symtab
*symtab
)
23975 auto old_entries
= std::move (symtab
->data
);
23977 symtab
->data
.clear ();
23978 symtab
->data
.resize (old_entries
.size () * 2);
23980 for (auto &it
: old_entries
)
23981 if (it
.name
!= NULL
)
23983 auto &ref
= find_slot (symtab
, it
.name
);
23984 ref
= std::move (it
);
23988 /* Add an entry to SYMTAB. NAME is the name of the symbol.
23989 CU_INDEX is the index of the CU in which the symbol appears.
23990 IS_STATIC is one if the symbol is static, otherwise zero (global). */
23993 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
23994 int is_static
, gdb_index_symbol_kind kind
,
23995 offset_type cu_index
)
23997 offset_type cu_index_and_attrs
;
23999 ++symtab
->n_elements
;
24000 if (4 * symtab
->n_elements
/ 3 >= symtab
->data
.size ())
24001 hash_expand (symtab
);
24003 symtab_index_entry
&slot
= find_slot (symtab
, name
);
24004 if (slot
.name
== NULL
)
24007 /* index_offset is set later. */
24010 cu_index_and_attrs
= 0;
24011 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
24012 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
24013 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
24015 /* We don't want to record an index value twice as we want to avoid the
24017 We process all global symbols and then all static symbols
24018 (which would allow us to avoid the duplication by only having to check
24019 the last entry pushed), but a symbol could have multiple kinds in one CU.
24020 To keep things simple we don't worry about the duplication here and
24021 sort and uniqufy the list after we've processed all symbols. */
24022 slot
.cu_indices
.push_back (cu_index_and_attrs
);
24025 /* Sort and remove duplicates of all symbols' cu_indices lists. */
24028 uniquify_cu_indices (struct mapped_symtab
*symtab
)
24030 for (auto &entry
: symtab
->data
)
24032 if (entry
.name
!= NULL
&& !entry
.cu_indices
.empty ())
24034 auto &cu_indices
= entry
.cu_indices
;
24035 std::sort (cu_indices
.begin (), cu_indices
.end ());
24036 auto from
= std::unique (cu_indices
.begin (), cu_indices
.end ());
24037 cu_indices
.erase (from
, cu_indices
.end ());
24042 /* A form of 'const char *' suitable for container keys. Only the
24043 pointer is stored. The strings themselves are compared, not the
24048 c_str_view (const char *cstr
)
24052 bool operator== (const c_str_view
&other
) const
24054 return strcmp (m_cstr
, other
.m_cstr
) == 0;
24058 friend class c_str_view_hasher
;
24059 const char *const m_cstr
;
24062 /* A std::unordered_map::hasher for c_str_view that uses the right
24063 hash function for strings in a mapped index. */
24064 class c_str_view_hasher
24067 size_t operator () (const c_str_view
&x
) const
24069 return mapped_index_string_hash (INT_MAX
, x
.m_cstr
);
24073 /* A std::unordered_map::hasher for std::vector<>. */
24074 template<typename T
>
24075 class vector_hasher
24078 size_t operator () (const std::vector
<T
> &key
) const
24080 return iterative_hash (key
.data (),
24081 sizeof (key
.front ()) * key
.size (), 0);
24085 /* Write the mapped hash table SYMTAB to the data buffer OUTPUT, with
24086 constant pool entries going into the data buffer CPOOL. */
24089 write_hash_table (mapped_symtab
*symtab
, data_buf
&output
, data_buf
&cpool
)
24092 /* Elements are sorted vectors of the indices of all the CUs that
24093 hold an object of this name. */
24094 std::unordered_map
<std::vector
<offset_type
>, offset_type
,
24095 vector_hasher
<offset_type
>>
24098 /* We add all the index vectors to the constant pool first, to
24099 ensure alignment is ok. */
24100 for (symtab_index_entry
&entry
: symtab
->data
)
24102 if (entry
.name
== NULL
)
24104 gdb_assert (entry
.index_offset
== 0);
24106 /* Finding before inserting is faster than always trying to
24107 insert, because inserting always allocates a node, does the
24108 lookup, and then destroys the new node if another node
24109 already had the same key. C++17 try_emplace will avoid
24112 = symbol_hash_table
.find (entry
.cu_indices
);
24113 if (found
!= symbol_hash_table
.end ())
24115 entry
.index_offset
= found
->second
;
24119 symbol_hash_table
.emplace (entry
.cu_indices
, cpool
.size ());
24120 entry
.index_offset
= cpool
.size ();
24121 cpool
.append_data (MAYBE_SWAP (entry
.cu_indices
.size ()));
24122 for (const auto index
: entry
.cu_indices
)
24123 cpool
.append_data (MAYBE_SWAP (index
));
24127 /* Now write out the hash table. */
24128 std::unordered_map
<c_str_view
, offset_type
, c_str_view_hasher
> str_table
;
24129 for (const auto &entry
: symtab
->data
)
24131 offset_type str_off
, vec_off
;
24133 if (entry
.name
!= NULL
)
24135 const auto insertpair
= str_table
.emplace (entry
.name
, cpool
.size ());
24136 if (insertpair
.second
)
24137 cpool
.append_cstr0 (entry
.name
);
24138 str_off
= insertpair
.first
->second
;
24139 vec_off
= entry
.index_offset
;
24143 /* While 0 is a valid constant pool index, it is not valid
24144 to have 0 for both offsets. */
24149 output
.append_data (MAYBE_SWAP (str_off
));
24150 output
.append_data (MAYBE_SWAP (vec_off
));
24154 typedef std::unordered_map
<partial_symtab
*, unsigned int> psym_index_map
;
24156 /* Helper struct for building the address table. */
24157 struct addrmap_index_data
24159 addrmap_index_data (data_buf
&addr_vec_
, psym_index_map
&cu_index_htab_
)
24160 : addr_vec (addr_vec_
), cu_index_htab (cu_index_htab_
)
24163 struct objfile
*objfile
;
24164 data_buf
&addr_vec
;
24165 psym_index_map
&cu_index_htab
;
24167 /* Non-zero if the previous_* fields are valid.
24168 We can't write an entry until we see the next entry (since it is only then
24169 that we know the end of the entry). */
24170 int previous_valid
;
24171 /* Index of the CU in the table of all CUs in the index file. */
24172 unsigned int previous_cu_index
;
24173 /* Start address of the CU. */
24174 CORE_ADDR previous_cu_start
;
24177 /* Write an address entry to ADDR_VEC. */
24180 add_address_entry (struct objfile
*objfile
, data_buf
&addr_vec
,
24181 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
24183 CORE_ADDR baseaddr
;
24185 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
24187 addr_vec
.append_uint (8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
24188 addr_vec
.append_uint (8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
24189 addr_vec
.append_data (MAYBE_SWAP (cu_index
));
24192 /* Worker function for traversing an addrmap to build the address table. */
24195 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
24197 struct addrmap_index_data
*data
= (struct addrmap_index_data
*) datap
;
24198 struct partial_symtab
*pst
= (struct partial_symtab
*) obj
;
24200 if (data
->previous_valid
)
24201 add_address_entry (data
->objfile
, data
->addr_vec
,
24202 data
->previous_cu_start
, start_addr
,
24203 data
->previous_cu_index
);
24205 data
->previous_cu_start
= start_addr
;
24208 const auto it
= data
->cu_index_htab
.find (pst
);
24209 gdb_assert (it
!= data
->cu_index_htab
.cend ());
24210 data
->previous_cu_index
= it
->second
;
24211 data
->previous_valid
= 1;
24214 data
->previous_valid
= 0;
24219 /* Write OBJFILE's address map to ADDR_VEC.
24220 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
24221 in the index file. */
24224 write_address_map (struct objfile
*objfile
, data_buf
&addr_vec
,
24225 psym_index_map
&cu_index_htab
)
24227 struct addrmap_index_data
addrmap_index_data (addr_vec
, cu_index_htab
);
24229 /* When writing the address table, we have to cope with the fact that
24230 the addrmap iterator only provides the start of a region; we have to
24231 wait until the next invocation to get the start of the next region. */
24233 addrmap_index_data
.objfile
= objfile
;
24234 addrmap_index_data
.previous_valid
= 0;
24236 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
24237 &addrmap_index_data
);
24239 /* It's highly unlikely the last entry (end address = 0xff...ff)
24240 is valid, but we should still handle it.
24241 The end address is recorded as the start of the next region, but that
24242 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
24244 if (addrmap_index_data
.previous_valid
)
24245 add_address_entry (objfile
, addr_vec
,
24246 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
24247 addrmap_index_data
.previous_cu_index
);
24250 /* Return the symbol kind of PSYM. */
24252 static gdb_index_symbol_kind
24253 symbol_kind (struct partial_symbol
*psym
)
24255 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
24256 enum address_class aclass
= PSYMBOL_CLASS (psym
);
24264 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
24266 return GDB_INDEX_SYMBOL_KIND_TYPE
;
24268 case LOC_CONST_BYTES
:
24269 case LOC_OPTIMIZED_OUT
:
24271 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
24273 /* Note: It's currently impossible to recognize psyms as enum values
24274 short of reading the type info. For now punt. */
24275 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
24277 /* There are other LOC_FOO values that one might want to classify
24278 as variables, but dwarf2read.c doesn't currently use them. */
24279 return GDB_INDEX_SYMBOL_KIND_OTHER
;
24281 case STRUCT_DOMAIN
:
24282 return GDB_INDEX_SYMBOL_KIND_TYPE
;
24284 return GDB_INDEX_SYMBOL_KIND_OTHER
;
24288 /* Add a list of partial symbols to SYMTAB. */
24291 write_psymbols (struct mapped_symtab
*symtab
,
24292 std::unordered_set
<partial_symbol
*> &psyms_seen
,
24293 struct partial_symbol
**psymp
,
24295 offset_type cu_index
,
24298 for (; count
-- > 0; ++psymp
)
24300 struct partial_symbol
*psym
= *psymp
;
24302 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
24303 error (_("Ada is not currently supported by the index"));
24305 /* Only add a given psymbol once. */
24306 if (psyms_seen
.insert (psym
).second
)
24308 gdb_index_symbol_kind kind
= symbol_kind (psym
);
24310 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
24311 is_static
, kind
, cu_index
);
24316 /* A helper struct used when iterating over debug_types. */
24317 struct signatured_type_index_data
24319 signatured_type_index_data (data_buf
&types_list_
,
24320 std::unordered_set
<partial_symbol
*> &psyms_seen_
)
24321 : types_list (types_list_
), psyms_seen (psyms_seen_
)
24324 struct objfile
*objfile
;
24325 struct mapped_symtab
*symtab
;
24326 data_buf
&types_list
;
24327 std::unordered_set
<partial_symbol
*> &psyms_seen
;
24331 /* A helper function that writes a single signatured_type to an
24335 write_one_signatured_type (void **slot
, void *d
)
24337 struct signatured_type_index_data
*info
24338 = (struct signatured_type_index_data
*) d
;
24339 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
24340 struct partial_symtab
*psymtab
= entry
->per_cu
.v
.psymtab
;
24342 write_psymbols (info
->symtab
,
24344 &info
->objfile
->global_psymbols
[psymtab
->globals_offset
],
24345 psymtab
->n_global_syms
, info
->cu_index
,
24347 write_psymbols (info
->symtab
,
24349 &info
->objfile
->static_psymbols
[psymtab
->statics_offset
],
24350 psymtab
->n_static_syms
, info
->cu_index
,
24353 info
->types_list
.append_uint (8, BFD_ENDIAN_LITTLE
,
24354 to_underlying (entry
->per_cu
.sect_off
));
24355 info
->types_list
.append_uint (8, BFD_ENDIAN_LITTLE
,
24356 to_underlying (entry
->type_offset_in_tu
));
24357 info
->types_list
.append_uint (8, BFD_ENDIAN_LITTLE
, entry
->signature
);
24364 /* Recurse into all "included" dependencies and count their symbols as
24365 if they appeared in this psymtab. */
24368 recursively_count_psymbols (struct partial_symtab
*psymtab
,
24369 size_t &psyms_seen
)
24371 for (int i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
24372 if (psymtab
->dependencies
[i
]->user
!= NULL
)
24373 recursively_count_psymbols (psymtab
->dependencies
[i
],
24376 psyms_seen
+= psymtab
->n_global_syms
;
24377 psyms_seen
+= psymtab
->n_static_syms
;
24380 /* Recurse into all "included" dependencies and write their symbols as
24381 if they appeared in this psymtab. */
24384 recursively_write_psymbols (struct objfile
*objfile
,
24385 struct partial_symtab
*psymtab
,
24386 struct mapped_symtab
*symtab
,
24387 std::unordered_set
<partial_symbol
*> &psyms_seen
,
24388 offset_type cu_index
)
24392 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
24393 if (psymtab
->dependencies
[i
]->user
!= NULL
)
24394 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
24395 symtab
, psyms_seen
, cu_index
);
24397 write_psymbols (symtab
,
24399 &objfile
->global_psymbols
[psymtab
->globals_offset
],
24400 psymtab
->n_global_syms
, cu_index
,
24402 write_psymbols (symtab
,
24404 &objfile
->static_psymbols
[psymtab
->statics_offset
],
24405 psymtab
->n_static_syms
, cu_index
,
24409 /* Create an index file for OBJFILE in the directory DIR. */
24412 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
24414 if (dwarf2_per_objfile
->using_index
)
24415 error (_("Cannot use an index to create the index"));
24417 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
24418 error (_("Cannot make an index when the file has multiple .debug_types sections"));
24420 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
24424 if (stat (objfile_name (objfile
), &st
) < 0)
24425 perror_with_name (objfile_name (objfile
));
24427 std::string
filename (std::string (dir
) + SLASH_STRING
24428 + lbasename (objfile_name (objfile
)) + INDEX_SUFFIX
);
24430 FILE *out_file
= gdb_fopen_cloexec (filename
.c_str (), "wb").release ();
24432 error (_("Can't open `%s' for writing"), filename
.c_str ());
24434 /* Order matters here; we want FILE to be closed before FILENAME is
24435 unlinked, because on MS-Windows one cannot delete a file that is
24436 still open. (Don't call anything here that might throw until
24437 file_closer is created.) */
24438 gdb::unlinker
unlink_file (filename
.c_str ());
24439 gdb_file_up
close_out_file (out_file
);
24441 mapped_symtab symtab
;
24444 /* While we're scanning CU's create a table that maps a psymtab pointer
24445 (which is what addrmap records) to its index (which is what is recorded
24446 in the index file). This will later be needed to write the address
24448 psym_index_map cu_index_htab
;
24449 cu_index_htab
.reserve (dwarf2_per_objfile
->n_comp_units
);
24451 /* The CU list is already sorted, so we don't need to do additional
24452 work here. Also, the debug_types entries do not appear in
24453 all_comp_units, but only in their own hash table. */
24455 /* The psyms_seen set is potentially going to be largish (~40k
24456 elements when indexing a -g3 build of GDB itself). Estimate the
24457 number of elements in order to avoid too many rehashes, which
24458 require rebuilding buckets and thus many trips to
24460 size_t psyms_count
= 0;
24461 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
24463 struct dwarf2_per_cu_data
*per_cu
24464 = dwarf2_per_objfile
->all_comp_units
[i
];
24465 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
24467 if (psymtab
!= NULL
&& psymtab
->user
== NULL
)
24468 recursively_count_psymbols (psymtab
, psyms_count
);
24470 /* Generating an index for gdb itself shows a ratio of
24471 TOTAL_SEEN_SYMS/UNIQUE_SYMS or ~5. 4 seems like a good bet. */
24472 std::unordered_set
<partial_symbol
*> psyms_seen (psyms_count
/ 4);
24473 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
24475 struct dwarf2_per_cu_data
*per_cu
24476 = dwarf2_per_objfile
->all_comp_units
[i
];
24477 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
24479 /* CU of a shared file from 'dwz -m' may be unused by this main file.
24480 It may be referenced from a local scope but in such case it does not
24481 need to be present in .gdb_index. */
24482 if (psymtab
== NULL
)
24485 if (psymtab
->user
== NULL
)
24486 recursively_write_psymbols (objfile
, psymtab
, &symtab
,
24489 const auto insertpair
= cu_index_htab
.emplace (psymtab
, i
);
24490 gdb_assert (insertpair
.second
);
24492 cu_list
.append_uint (8, BFD_ENDIAN_LITTLE
,
24493 to_underlying (per_cu
->sect_off
));
24494 cu_list
.append_uint (8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
24497 /* Dump the address map. */
24499 write_address_map (objfile
, addr_vec
, cu_index_htab
);
24501 /* Write out the .debug_type entries, if any. */
24502 data_buf types_cu_list
;
24503 if (dwarf2_per_objfile
->signatured_types
)
24505 signatured_type_index_data
sig_data (types_cu_list
,
24508 sig_data
.objfile
= objfile
;
24509 sig_data
.symtab
= &symtab
;
24510 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
24511 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
24512 write_one_signatured_type
, &sig_data
);
24515 /* Now that we've processed all symbols we can shrink their cu_indices
24517 uniquify_cu_indices (&symtab
);
24519 data_buf symtab_vec
, constant_pool
;
24520 write_hash_table (&symtab
, symtab_vec
, constant_pool
);
24523 const offset_type size_of_contents
= 6 * sizeof (offset_type
);
24524 offset_type total_len
= size_of_contents
;
24526 /* The version number. */
24527 contents
.append_data (MAYBE_SWAP (8));
24529 /* The offset of the CU list from the start of the file. */
24530 contents
.append_data (MAYBE_SWAP (total_len
));
24531 total_len
+= cu_list
.size ();
24533 /* The offset of the types CU list from the start of the file. */
24534 contents
.append_data (MAYBE_SWAP (total_len
));
24535 total_len
+= types_cu_list
.size ();
24537 /* The offset of the address table from the start of the file. */
24538 contents
.append_data (MAYBE_SWAP (total_len
));
24539 total_len
+= addr_vec
.size ();
24541 /* The offset of the symbol table from the start of the file. */
24542 contents
.append_data (MAYBE_SWAP (total_len
));
24543 total_len
+= symtab_vec
.size ();
24545 /* The offset of the constant pool from the start of the file. */
24546 contents
.append_data (MAYBE_SWAP (total_len
));
24547 total_len
+= constant_pool
.size ();
24549 gdb_assert (contents
.size () == size_of_contents
);
24551 contents
.file_write (out_file
);
24552 cu_list
.file_write (out_file
);
24553 types_cu_list
.file_write (out_file
);
24554 addr_vec
.file_write (out_file
);
24555 symtab_vec
.file_write (out_file
);
24556 constant_pool
.file_write (out_file
);
24558 /* We want to keep the file. */
24559 unlink_file
.keep ();
24562 /* Implementation of the `save gdb-index' command.
24564 Note that the file format used by this command is documented in the
24565 GDB manual. Any changes here must be documented there. */
24568 save_gdb_index_command (const char *arg
, int from_tty
)
24570 struct objfile
*objfile
;
24573 error (_("usage: save gdb-index DIRECTORY"));
24575 ALL_OBJFILES (objfile
)
24579 /* If the objfile does not correspond to an actual file, skip it. */
24580 if (stat (objfile_name (objfile
), &st
) < 0)
24584 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
24585 dwarf2_objfile_data_key
);
24586 if (dwarf2_per_objfile
)
24591 write_psymtabs_to_index (objfile
, arg
);
24593 CATCH (except
, RETURN_MASK_ERROR
)
24595 exception_fprintf (gdb_stderr
, except
,
24596 _("Error while writing index for `%s': "),
24597 objfile_name (objfile
));
24606 int dwarf_always_disassemble
;
24609 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
24610 struct cmd_list_element
*c
, const char *value
)
24612 fprintf_filtered (file
,
24613 _("Whether to always disassemble "
24614 "DWARF expressions is %s.\n"),
24619 show_check_physname (struct ui_file
*file
, int from_tty
,
24620 struct cmd_list_element
*c
, const char *value
)
24622 fprintf_filtered (file
,
24623 _("Whether to check \"physname\" is %s.\n"),
24628 _initialize_dwarf2_read (void)
24630 struct cmd_list_element
*c
;
24632 dwarf2_objfile_data_key
24633 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
24635 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
24636 Set DWARF specific variables.\n\
24637 Configure DWARF variables such as the cache size"),
24638 &set_dwarf_cmdlist
, "maintenance set dwarf ",
24639 0/*allow-unknown*/, &maintenance_set_cmdlist
);
24641 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
24642 Show DWARF specific variables\n\
24643 Show DWARF variables such as the cache size"),
24644 &show_dwarf_cmdlist
, "maintenance show dwarf ",
24645 0/*allow-unknown*/, &maintenance_show_cmdlist
);
24647 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
24648 &dwarf_max_cache_age
, _("\
24649 Set the upper bound on the age of cached DWARF compilation units."), _("\
24650 Show the upper bound on the age of cached DWARF compilation units."), _("\
24651 A higher limit means that cached compilation units will be stored\n\
24652 in memory longer, and more total memory will be used. Zero disables\n\
24653 caching, which can slow down startup."),
24655 show_dwarf_max_cache_age
,
24656 &set_dwarf_cmdlist
,
24657 &show_dwarf_cmdlist
);
24659 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
24660 &dwarf_always_disassemble
, _("\
24661 Set whether `info address' always disassembles DWARF expressions."), _("\
24662 Show whether `info address' always disassembles DWARF expressions."), _("\
24663 When enabled, DWARF expressions are always printed in an assembly-like\n\
24664 syntax. When disabled, expressions will be printed in a more\n\
24665 conversational style, when possible."),
24667 show_dwarf_always_disassemble
,
24668 &set_dwarf_cmdlist
,
24669 &show_dwarf_cmdlist
);
24671 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
24672 Set debugging of the DWARF reader."), _("\
24673 Show debugging of the DWARF reader."), _("\
24674 When enabled (non-zero), debugging messages are printed during DWARF\n\
24675 reading and symtab expansion. A value of 1 (one) provides basic\n\
24676 information. A value greater than 1 provides more verbose information."),
24679 &setdebuglist
, &showdebuglist
);
24681 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
24682 Set debugging of the DWARF DIE reader."), _("\
24683 Show debugging of the DWARF DIE reader."), _("\
24684 When enabled (non-zero), DIEs are dumped after they are read in.\n\
24685 The value is the maximum depth to print."),
24688 &setdebuglist
, &showdebuglist
);
24690 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
24691 Set debugging of the dwarf line reader."), _("\
24692 Show debugging of the dwarf line reader."), _("\
24693 When enabled (non-zero), line number entries are dumped as they are read in.\n\
24694 A value of 1 (one) provides basic information.\n\
24695 A value greater than 1 provides more verbose information."),
24698 &setdebuglist
, &showdebuglist
);
24700 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
24701 Set cross-checking of \"physname\" code against demangler."), _("\
24702 Show cross-checking of \"physname\" code against demangler."), _("\
24703 When enabled, GDB's internal \"physname\" code is checked against\n\
24705 NULL
, show_check_physname
,
24706 &setdebuglist
, &showdebuglist
);
24708 add_setshow_boolean_cmd ("use-deprecated-index-sections",
24709 no_class
, &use_deprecated_index_sections
, _("\
24710 Set whether to use deprecated gdb_index sections."), _("\
24711 Show whether to use deprecated gdb_index sections."), _("\
24712 When enabled, deprecated .gdb_index sections are used anyway.\n\
24713 Normally they are ignored either because of a missing feature or\n\
24714 performance issue.\n\
24715 Warning: This option must be enabled before gdb reads the file."),
24718 &setlist
, &showlist
);
24720 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
24722 Save a gdb-index file.\n\
24723 Usage: save gdb-index DIRECTORY"),
24725 set_cmd_completer (c
, filename_completer
);
24727 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24728 &dwarf2_locexpr_funcs
);
24729 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24730 &dwarf2_loclist_funcs
);
24732 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24733 &dwarf2_block_frame_base_locexpr_funcs
);
24734 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24735 &dwarf2_block_frame_base_loclist_funcs
);
24738 selftests::register_test ("dw2_expand_symtabs_matching",
24739 selftests::dw2_expand_symtabs_matching::run_test
);