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"
78 #include <sys/types.h>
81 typedef struct symbol
*symbolp
;
84 /* When == 1, print basic high level tracing messages.
85 When > 1, be more verbose.
86 This is in contrast to the low level DIE reading of dwarf_die_debug. */
87 static unsigned int dwarf_read_debug
= 0;
89 /* When non-zero, dump DIEs after they are read in. */
90 static unsigned int dwarf_die_debug
= 0;
92 /* When non-zero, dump line number entries as they are read in. */
93 static unsigned int dwarf_line_debug
= 0;
95 /* When non-zero, cross-check physname against demangler. */
96 static int check_physname
= 0;
98 /* When non-zero, do not reject deprecated .gdb_index sections. */
99 static int use_deprecated_index_sections
= 0;
101 static const struct objfile_data
*dwarf2_objfile_data_key
;
103 /* The "aclass" indices for various kinds of computed DWARF symbols. */
105 static int dwarf2_locexpr_index
;
106 static int dwarf2_loclist_index
;
107 static int dwarf2_locexpr_block_index
;
108 static int dwarf2_loclist_block_index
;
110 /* A descriptor for dwarf sections.
112 S.ASECTION, SIZE are typically initialized when the objfile is first
113 scanned. BUFFER, READIN are filled in later when the section is read.
114 If the section contained compressed data then SIZE is updated to record
115 the uncompressed size of the section.
117 DWP file format V2 introduces a wrinkle that is easiest to handle by
118 creating the concept of virtual sections contained within a real section.
119 In DWP V2 the sections of the input DWO files are concatenated together
120 into one section, but section offsets are kept relative to the original
122 If this is a virtual dwp-v2 section, S.CONTAINING_SECTION is a backlink to
123 the real section this "virtual" section is contained in, and BUFFER,SIZE
124 describe the virtual section. */
126 struct dwarf2_section_info
130 /* If this is a real section, the bfd section. */
132 /* If this is a virtual section, pointer to the containing ("real")
134 struct dwarf2_section_info
*containing_section
;
136 /* Pointer to section data, only valid if readin. */
137 const gdb_byte
*buffer
;
138 /* The size of the section, real or virtual. */
140 /* If this is a virtual section, the offset in the real section.
141 Only valid if is_virtual. */
142 bfd_size_type virtual_offset
;
143 /* True if we have tried to read this section. */
145 /* True if this is a virtual section, False otherwise.
146 This specifies which of s.section and s.containing_section to use. */
150 typedef struct dwarf2_section_info dwarf2_section_info_def
;
151 DEF_VEC_O (dwarf2_section_info_def
);
153 /* All offsets in the index are of this type. It must be
154 architecture-independent. */
155 typedef uint32_t offset_type
;
157 DEF_VEC_I (offset_type
);
159 /* Ensure only legit values are used. */
160 #define DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \
162 gdb_assert ((unsigned int) (value) <= 1); \
163 GDB_INDEX_SYMBOL_STATIC_SET_VALUE((cu_index), (value)); \
166 /* Ensure only legit values are used. */
167 #define DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \
169 gdb_assert ((value) >= GDB_INDEX_SYMBOL_KIND_TYPE \
170 && (value) <= GDB_INDEX_SYMBOL_KIND_OTHER); \
171 GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \
174 /* Ensure we don't use more than the alloted nuber of bits for the CU. */
175 #define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \
177 gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \
178 GDB_INDEX_CU_SET_VALUE((cu_index), (value)); \
181 /* A description of the mapped index. The file format is described in
182 a comment by the code that writes the index. */
185 /* Index data format version. */
188 /* The total length of the buffer. */
191 /* A pointer to the address table data. */
192 const gdb_byte
*address_table
;
194 /* Size of the address table data in bytes. */
195 offset_type address_table_size
;
197 /* The symbol table, implemented as a hash table. */
198 const offset_type
*symbol_table
;
200 /* Size in slots, each slot is 2 offset_types. */
201 offset_type symbol_table_slots
;
203 /* A pointer to the constant pool. */
204 const char *constant_pool
;
207 typedef struct dwarf2_per_cu_data
*dwarf2_per_cu_ptr
;
208 DEF_VEC_P (dwarf2_per_cu_ptr
);
212 int nr_uniq_abbrev_tables
;
214 int nr_symtab_sharers
;
215 int nr_stmt_less_type_units
;
216 int nr_all_type_units_reallocs
;
219 /* Collection of data recorded per objfile.
220 This hangs off of dwarf2_objfile_data_key. */
222 struct dwarf2_per_objfile
224 struct dwarf2_section_info info
;
225 struct dwarf2_section_info abbrev
;
226 struct dwarf2_section_info line
;
227 struct dwarf2_section_info loc
;
228 struct dwarf2_section_info loclists
;
229 struct dwarf2_section_info macinfo
;
230 struct dwarf2_section_info macro
;
231 struct dwarf2_section_info str
;
232 struct dwarf2_section_info line_str
;
233 struct dwarf2_section_info ranges
;
234 struct dwarf2_section_info rnglists
;
235 struct dwarf2_section_info addr
;
236 struct dwarf2_section_info frame
;
237 struct dwarf2_section_info eh_frame
;
238 struct dwarf2_section_info gdb_index
;
240 VEC (dwarf2_section_info_def
) *types
;
243 struct objfile
*objfile
;
245 /* Table of all the compilation units. This is used to locate
246 the target compilation unit of a particular reference. */
247 struct dwarf2_per_cu_data
**all_comp_units
;
249 /* The number of compilation units in ALL_COMP_UNITS. */
252 /* The number of .debug_types-related CUs. */
255 /* The number of elements allocated in all_type_units.
256 If there are skeleton-less TUs, we add them to all_type_units lazily. */
257 int n_allocated_type_units
;
259 /* The .debug_types-related CUs (TUs).
260 This is stored in malloc space because we may realloc it. */
261 struct signatured_type
**all_type_units
;
263 /* Table of struct type_unit_group objects.
264 The hash key is the DW_AT_stmt_list value. */
265 htab_t type_unit_groups
;
267 /* A table mapping .debug_types signatures to its signatured_type entry.
268 This is NULL if the .debug_types section hasn't been read in yet. */
269 htab_t signatured_types
;
271 /* Type unit statistics, to see how well the scaling improvements
273 struct tu_stats tu_stats
;
275 /* A chain of compilation units that are currently read in, so that
276 they can be freed later. */
277 struct dwarf2_per_cu_data
*read_in_chain
;
279 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
280 This is NULL if the table hasn't been allocated yet. */
283 /* Non-zero if we've check for whether there is a DWP file. */
286 /* The DWP file if there is one, or NULL. */
287 struct dwp_file
*dwp_file
;
289 /* The shared '.dwz' file, if one exists. This is used when the
290 original data was compressed using 'dwz -m'. */
291 struct dwz_file
*dwz_file
;
293 /* A flag indicating wether this objfile has a section loaded at a
295 int has_section_at_zero
;
297 /* True if we are using the mapped index,
298 or we are faking it for OBJF_READNOW's sake. */
299 unsigned char using_index
;
301 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
302 struct mapped_index
*index_table
;
304 /* When using index_table, this keeps track of all quick_file_names entries.
305 TUs typically share line table entries with a CU, so we maintain a
306 separate table of all line table entries to support the sharing.
307 Note that while there can be way more TUs than CUs, we've already
308 sorted all the TUs into "type unit groups", grouped by their
309 DW_AT_stmt_list value. Therefore the only sharing done here is with a
310 CU and its associated TU group if there is one. */
311 htab_t quick_file_names_table
;
313 /* Set during partial symbol reading, to prevent queueing of full
315 int reading_partial_symbols
;
317 /* Table mapping type DIEs to their struct type *.
318 This is NULL if not allocated yet.
319 The mapping is done via (CU/TU + DIE offset) -> type. */
320 htab_t die_type_hash
;
322 /* The CUs we recently read. */
323 VEC (dwarf2_per_cu_ptr
) *just_read_cus
;
325 /* Table containing line_header indexed by offset and offset_in_dwz. */
326 htab_t line_header_hash
;
329 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
331 /* Default names of the debugging sections. */
333 /* Note that if the debugging section has been compressed, it might
334 have a name like .zdebug_info. */
336 static const struct dwarf2_debug_sections dwarf2_elf_names
=
338 { ".debug_info", ".zdebug_info" },
339 { ".debug_abbrev", ".zdebug_abbrev" },
340 { ".debug_line", ".zdebug_line" },
341 { ".debug_loc", ".zdebug_loc" },
342 { ".debug_loclists", ".zdebug_loclists" },
343 { ".debug_macinfo", ".zdebug_macinfo" },
344 { ".debug_macro", ".zdebug_macro" },
345 { ".debug_str", ".zdebug_str" },
346 { ".debug_line_str", ".zdebug_line_str" },
347 { ".debug_ranges", ".zdebug_ranges" },
348 { ".debug_rnglists", ".zdebug_rnglists" },
349 { ".debug_types", ".zdebug_types" },
350 { ".debug_addr", ".zdebug_addr" },
351 { ".debug_frame", ".zdebug_frame" },
352 { ".eh_frame", NULL
},
353 { ".gdb_index", ".zgdb_index" },
357 /* List of DWO/DWP sections. */
359 static const struct dwop_section_names
361 struct dwarf2_section_names abbrev_dwo
;
362 struct dwarf2_section_names info_dwo
;
363 struct dwarf2_section_names line_dwo
;
364 struct dwarf2_section_names loc_dwo
;
365 struct dwarf2_section_names loclists_dwo
;
366 struct dwarf2_section_names macinfo_dwo
;
367 struct dwarf2_section_names macro_dwo
;
368 struct dwarf2_section_names str_dwo
;
369 struct dwarf2_section_names str_offsets_dwo
;
370 struct dwarf2_section_names types_dwo
;
371 struct dwarf2_section_names cu_index
;
372 struct dwarf2_section_names tu_index
;
376 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
377 { ".debug_info.dwo", ".zdebug_info.dwo" },
378 { ".debug_line.dwo", ".zdebug_line.dwo" },
379 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
380 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
381 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
382 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
383 { ".debug_str.dwo", ".zdebug_str.dwo" },
384 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
385 { ".debug_types.dwo", ".zdebug_types.dwo" },
386 { ".debug_cu_index", ".zdebug_cu_index" },
387 { ".debug_tu_index", ".zdebug_tu_index" },
390 /* local data types */
392 /* The data in a compilation unit header, after target2host
393 translation, looks like this. */
394 struct comp_unit_head
398 unsigned char addr_size
;
399 unsigned char signed_addr_p
;
400 sect_offset abbrev_sect_off
;
402 /* Size of file offsets; either 4 or 8. */
403 unsigned int offset_size
;
405 /* Size of the length field; either 4 or 12. */
406 unsigned int initial_length_size
;
408 enum dwarf_unit_type unit_type
;
410 /* Offset to the first byte of this compilation unit header in the
411 .debug_info section, for resolving relative reference dies. */
412 sect_offset sect_off
;
414 /* Offset to first die in this cu from the start of the cu.
415 This will be the first byte following the compilation unit header. */
416 cu_offset first_die_cu_offset
;
418 /* 64-bit signature of this type unit - it is valid only for
419 UNIT_TYPE DW_UT_type. */
422 /* For types, offset in the type's DIE of the type defined by this TU. */
423 cu_offset type_cu_offset_in_tu
;
426 /* Type used for delaying computation of method physnames.
427 See comments for compute_delayed_physnames. */
428 struct delayed_method_info
430 /* The type to which the method is attached, i.e., its parent class. */
433 /* The index of the method in the type's function fieldlists. */
436 /* The index of the method in the fieldlist. */
439 /* The name of the DIE. */
442 /* The DIE associated with this method. */
443 struct die_info
*die
;
446 typedef struct delayed_method_info delayed_method_info
;
447 DEF_VEC_O (delayed_method_info
);
449 /* Internal state when decoding a particular compilation unit. */
452 /* The objfile containing this compilation unit. */
453 struct objfile
*objfile
;
455 /* The header of the compilation unit. */
456 struct comp_unit_head header
;
458 /* Base address of this compilation unit. */
459 CORE_ADDR base_address
;
461 /* Non-zero if base_address has been set. */
464 /* The language we are debugging. */
465 enum language language
;
466 const struct language_defn
*language_defn
;
468 const char *producer
;
470 /* The generic symbol table building routines have separate lists for
471 file scope symbols and all all other scopes (local scopes). So
472 we need to select the right one to pass to add_symbol_to_list().
473 We do it by keeping a pointer to the correct list in list_in_scope.
475 FIXME: The original dwarf code just treated the file scope as the
476 first local scope, and all other local scopes as nested local
477 scopes, and worked fine. Check to see if we really need to
478 distinguish these in buildsym.c. */
479 struct pending
**list_in_scope
;
481 /* The abbrev table for this CU.
482 Normally this points to the abbrev table in the objfile.
483 But if DWO_UNIT is non-NULL this is the abbrev table in the DWO file. */
484 struct abbrev_table
*abbrev_table
;
486 /* Hash table holding all the loaded partial DIEs
487 with partial_die->offset.SECT_OFF as hash. */
490 /* Storage for things with the same lifetime as this read-in compilation
491 unit, including partial DIEs. */
492 struct obstack comp_unit_obstack
;
494 /* When multiple dwarf2_cu structures are living in memory, this field
495 chains them all together, so that they can be released efficiently.
496 We will probably also want a generation counter so that most-recently-used
497 compilation units are cached... */
498 struct dwarf2_per_cu_data
*read_in_chain
;
500 /* Backlink to our per_cu entry. */
501 struct dwarf2_per_cu_data
*per_cu
;
503 /* How many compilation units ago was this CU last referenced? */
506 /* A hash table of DIE cu_offset for following references with
507 die_info->offset.sect_off as hash. */
510 /* Full DIEs if read in. */
511 struct die_info
*dies
;
513 /* A set of pointers to dwarf2_per_cu_data objects for compilation
514 units referenced by this one. Only set during full symbol processing;
515 partial symbol tables do not have dependencies. */
518 /* Header data from the line table, during full symbol processing. */
519 struct line_header
*line_header
;
521 /* A list of methods which need to have physnames computed
522 after all type information has been read. */
523 VEC (delayed_method_info
) *method_list
;
525 /* To be copied to symtab->call_site_htab. */
526 htab_t call_site_htab
;
528 /* Non-NULL if this CU came from a DWO file.
529 There is an invariant here that is important to remember:
530 Except for attributes copied from the top level DIE in the "main"
531 (or "stub") file in preparation for reading the DWO file
532 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
533 Either there isn't a DWO file (in which case this is NULL and the point
534 is moot), or there is and either we're not going to read it (in which
535 case this is NULL) or there is and we are reading it (in which case this
537 struct dwo_unit
*dwo_unit
;
539 /* The DW_AT_addr_base attribute if present, zero otherwise
540 (zero is a valid value though).
541 Note this value comes from the Fission stub CU/TU's DIE. */
544 /* The DW_AT_ranges_base attribute if present, zero otherwise
545 (zero is a valid value though).
546 Note this value comes from the Fission stub CU/TU's DIE.
547 Also note that the value is zero in the non-DWO case so this value can
548 be used without needing to know whether DWO files are in use or not.
549 N.B. This does not apply to DW_AT_ranges appearing in
550 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
551 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
552 DW_AT_ranges_base *would* have to be applied, and we'd have to care
553 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
554 ULONGEST ranges_base
;
556 /* Mark used when releasing cached dies. */
557 unsigned int mark
: 1;
559 /* This CU references .debug_loc. See the symtab->locations_valid field.
560 This test is imperfect as there may exist optimized debug code not using
561 any location list and still facing inlining issues if handled as
562 unoptimized code. For a future better test see GCC PR other/32998. */
563 unsigned int has_loclist
: 1;
565 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is set
566 if all the producer_is_* fields are valid. This information is cached
567 because profiling CU expansion showed excessive time spent in
568 producer_is_gxx_lt_4_6. */
569 unsigned int checked_producer
: 1;
570 unsigned int producer_is_gxx_lt_4_6
: 1;
571 unsigned int producer_is_gcc_lt_4_3
: 1;
572 unsigned int producer_is_icc
: 1;
574 /* When set, the file that we're processing is known to have
575 debugging info for C++ namespaces. GCC 3.3.x did not produce
576 this information, but later versions do. */
578 unsigned int processing_has_namespace_info
: 1;
581 /* Persistent data held for a compilation unit, even when not
582 processing it. We put a pointer to this structure in the
583 read_symtab_private field of the psymtab. */
585 struct dwarf2_per_cu_data
587 /* The start offset and length of this compilation unit.
588 NOTE: Unlike comp_unit_head.length, this length includes
590 If the DIE refers to a DWO file, this is always of the original die,
592 sect_offset sect_off
;
595 /* DWARF standard version this data has been read from (such as 4 or 5). */
598 /* Flag indicating this compilation unit will be read in before
599 any of the current compilation units are processed. */
600 unsigned int queued
: 1;
602 /* This flag will be set when reading partial DIEs if we need to load
603 absolutely all DIEs for this compilation unit, instead of just the ones
604 we think are interesting. It gets set if we look for a DIE in the
605 hash table and don't find it. */
606 unsigned int load_all_dies
: 1;
608 /* Non-zero if this CU is from .debug_types.
609 Struct dwarf2_per_cu_data is contained in struct signatured_type iff
611 unsigned int is_debug_types
: 1;
613 /* Non-zero if this CU is from the .dwz file. */
614 unsigned int is_dwz
: 1;
616 /* Non-zero if reading a TU directly from a DWO file, bypassing the stub.
617 This flag is only valid if is_debug_types is true.
618 We can't read a CU directly from a DWO file: There are required
619 attributes in the stub. */
620 unsigned int reading_dwo_directly
: 1;
622 /* Non-zero if the TU has been read.
623 This is used to assist the "Stay in DWO Optimization" for Fission:
624 When reading a DWO, it's faster to read TUs from the DWO instead of
625 fetching them from random other DWOs (due to comdat folding).
626 If the TU has already been read, the optimization is unnecessary
627 (and unwise - we don't want to change where gdb thinks the TU lives
629 This flag is only valid if is_debug_types is true. */
630 unsigned int tu_read
: 1;
632 /* The section this CU/TU lives in.
633 If the DIE refers to a DWO file, this is always the original die,
635 struct dwarf2_section_info
*section
;
637 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
638 of the CU cache it gets reset to NULL again. This is left as NULL for
639 dummy CUs (a CU header, but nothing else). */
640 struct dwarf2_cu
*cu
;
642 /* The corresponding objfile.
643 Normally we can get the objfile from dwarf2_per_objfile.
644 However we can enter this file with just a "per_cu" handle. */
645 struct objfile
*objfile
;
647 /* When dwarf2_per_objfile->using_index is true, the 'quick' field
648 is active. Otherwise, the 'psymtab' field is active. */
651 /* The partial symbol table associated with this compilation unit,
652 or NULL for unread partial units. */
653 struct partial_symtab
*psymtab
;
655 /* Data needed by the "quick" functions. */
656 struct dwarf2_per_cu_quick_data
*quick
;
659 /* The CUs we import using DW_TAG_imported_unit. This is filled in
660 while reading psymtabs, used to compute the psymtab dependencies,
661 and then cleared. Then it is filled in again while reading full
662 symbols, and only deleted when the objfile is destroyed.
664 This is also used to work around a difference between the way gold
665 generates .gdb_index version <=7 and the way gdb does. Arguably this
666 is a gold bug. For symbols coming from TUs, gold records in the index
667 the CU that includes the TU instead of the TU itself. This breaks
668 dw2_lookup_symbol: It assumes that if the index says symbol X lives
669 in CU/TU Y, then one need only expand Y and a subsequent lookup in Y
670 will find X. Alas TUs live in their own symtab, so after expanding CU Y
671 we need to look in TU Z to find X. Fortunately, this is akin to
672 DW_TAG_imported_unit, so we just use the same mechanism: For
673 .gdb_index version <=7 this also records the TUs that the CU referred
674 to. Concurrently with this change gdb was modified to emit version 8
675 indices so we only pay a price for gold generated indices.
676 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
677 VEC (dwarf2_per_cu_ptr
) *imported_symtabs
;
680 /* Entry in the signatured_types hash table. */
682 struct signatured_type
684 /* The "per_cu" object of this type.
685 This struct is used iff per_cu.is_debug_types.
686 N.B.: This is the first member so that it's easy to convert pointers
688 struct dwarf2_per_cu_data per_cu
;
690 /* The type's signature. */
693 /* Offset in the TU of the type's DIE, as read from the TU header.
694 If this TU is a DWO stub and the definition lives in a DWO file
695 (specified by DW_AT_GNU_dwo_name), this value is unusable. */
696 cu_offset type_offset_in_tu
;
698 /* Offset in the section of the type's DIE.
699 If the definition lives in a DWO file, this is the offset in the
700 .debug_types.dwo section.
701 The value is zero until the actual value is known.
702 Zero is otherwise not a valid section offset. */
703 sect_offset type_offset_in_section
;
705 /* Type units are grouped by their DW_AT_stmt_list entry so that they
706 can share them. This points to the containing symtab. */
707 struct type_unit_group
*type_unit_group
;
710 The first time we encounter this type we fully read it in and install it
711 in the symbol tables. Subsequent times we only need the type. */
714 /* Containing DWO unit.
715 This field is valid iff per_cu.reading_dwo_directly. */
716 struct dwo_unit
*dwo_unit
;
719 typedef struct signatured_type
*sig_type_ptr
;
720 DEF_VEC_P (sig_type_ptr
);
722 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
723 This includes type_unit_group and quick_file_names. */
725 struct stmt_list_hash
727 /* The DWO unit this table is from or NULL if there is none. */
728 struct dwo_unit
*dwo_unit
;
730 /* Offset in .debug_line or .debug_line.dwo. */
731 sect_offset line_sect_off
;
734 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
735 an object of this type. */
737 struct type_unit_group
739 /* dwarf2read.c's main "handle" on a TU symtab.
740 To simplify things we create an artificial CU that "includes" all the
741 type units using this stmt_list so that the rest of the code still has
742 a "per_cu" handle on the symtab.
743 This PER_CU is recognized by having no section. */
744 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->section == NULL)
745 struct dwarf2_per_cu_data per_cu
;
747 /* The TUs that share this DW_AT_stmt_list entry.
748 This is added to while parsing type units to build partial symtabs,
749 and is deleted afterwards and not used again. */
750 VEC (sig_type_ptr
) *tus
;
752 /* The compunit symtab.
753 Type units in a group needn't all be defined in the same source file,
754 so we create an essentially anonymous symtab as the compunit symtab. */
755 struct compunit_symtab
*compunit_symtab
;
757 /* The data used to construct the hash key. */
758 struct stmt_list_hash hash
;
760 /* The number of symtabs from the line header.
761 The value here must match line_header.num_file_names. */
762 unsigned int num_symtabs
;
764 /* The symbol tables for this TU (obtained from the files listed in
766 WARNING: The order of entries here must match the order of entries
767 in the line header. After the first TU using this type_unit_group, the
768 line header for the subsequent TUs is recreated from this. This is done
769 because we need to use the same symtabs for each TU using the same
770 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
771 there's no guarantee the line header doesn't have duplicate entries. */
772 struct symtab
**symtabs
;
775 /* These sections are what may appear in a (real or virtual) DWO file. */
779 struct dwarf2_section_info abbrev
;
780 struct dwarf2_section_info line
;
781 struct dwarf2_section_info loc
;
782 struct dwarf2_section_info loclists
;
783 struct dwarf2_section_info macinfo
;
784 struct dwarf2_section_info macro
;
785 struct dwarf2_section_info str
;
786 struct dwarf2_section_info str_offsets
;
787 /* In the case of a virtual DWO file, these two are unused. */
788 struct dwarf2_section_info info
;
789 VEC (dwarf2_section_info_def
) *types
;
792 /* CUs/TUs in DWP/DWO files. */
796 /* Backlink to the containing struct dwo_file. */
797 struct dwo_file
*dwo_file
;
799 /* The "id" that distinguishes this CU/TU.
800 .debug_info calls this "dwo_id", .debug_types calls this "signature".
801 Since signatures came first, we stick with it for consistency. */
804 /* The section this CU/TU lives in, in the DWO file. */
805 struct dwarf2_section_info
*section
;
807 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
808 sect_offset sect_off
;
811 /* For types, offset in the type's DIE of the type defined by this TU. */
812 cu_offset type_offset_in_tu
;
815 /* include/dwarf2.h defines the DWP section codes.
816 It defines a max value but it doesn't define a min value, which we
817 use for error checking, so provide one. */
819 enum dwp_v2_section_ids
824 /* Data for one DWO file.
826 This includes virtual DWO files (a virtual DWO file is a DWO file as it
827 appears in a DWP file). DWP files don't really have DWO files per se -
828 comdat folding of types "loses" the DWO file they came from, and from
829 a high level view DWP files appear to contain a mass of random types.
830 However, to maintain consistency with the non-DWP case we pretend DWP
831 files contain virtual DWO files, and we assign each TU with one virtual
832 DWO file (generally based on the line and abbrev section offsets -
833 a heuristic that seems to work in practice). */
837 /* The DW_AT_GNU_dwo_name attribute.
838 For virtual DWO files the name is constructed from the section offsets
839 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
840 from related CU+TUs. */
841 const char *dwo_name
;
843 /* The DW_AT_comp_dir attribute. */
844 const char *comp_dir
;
846 /* The bfd, when the file is open. Otherwise this is NULL.
847 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
850 /* The sections that make up this DWO file.
851 Remember that for virtual DWO files in DWP V2, these are virtual
852 sections (for lack of a better name). */
853 struct dwo_sections sections
;
855 /* The CU in the file.
856 We only support one because having more than one requires hacking the
857 dwo_name of each to match, which is highly unlikely to happen.
858 Doing this means all TUs can share comp_dir: We also assume that
859 DW_AT_comp_dir across all TUs in a DWO file will be identical. */
862 /* Table of TUs in the file.
863 Each element is a struct dwo_unit. */
867 /* These sections are what may appear in a DWP file. */
871 /* These are used by both DWP version 1 and 2. */
872 struct dwarf2_section_info str
;
873 struct dwarf2_section_info cu_index
;
874 struct dwarf2_section_info tu_index
;
876 /* These are only used by DWP version 2 files.
877 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
878 sections are referenced by section number, and are not recorded here.
879 In DWP version 2 there is at most one copy of all these sections, each
880 section being (effectively) comprised of the concatenation of all of the
881 individual sections that exist in the version 1 format.
882 To keep the code simple we treat each of these concatenated pieces as a
883 section itself (a virtual section?). */
884 struct dwarf2_section_info abbrev
;
885 struct dwarf2_section_info info
;
886 struct dwarf2_section_info line
;
887 struct dwarf2_section_info loc
;
888 struct dwarf2_section_info macinfo
;
889 struct dwarf2_section_info macro
;
890 struct dwarf2_section_info str_offsets
;
891 struct dwarf2_section_info types
;
894 /* These sections are what may appear in a virtual DWO file in DWP version 1.
895 A virtual DWO file is a DWO file as it appears in a DWP file. */
897 struct virtual_v1_dwo_sections
899 struct dwarf2_section_info abbrev
;
900 struct dwarf2_section_info line
;
901 struct dwarf2_section_info loc
;
902 struct dwarf2_section_info macinfo
;
903 struct dwarf2_section_info macro
;
904 struct dwarf2_section_info str_offsets
;
905 /* Each DWP hash table entry records one CU or one TU.
906 That is recorded here, and copied to dwo_unit.section. */
907 struct dwarf2_section_info info_or_types
;
910 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
911 In version 2, the sections of the DWO files are concatenated together
912 and stored in one section of that name. Thus each ELF section contains
913 several "virtual" sections. */
915 struct virtual_v2_dwo_sections
917 bfd_size_type abbrev_offset
;
918 bfd_size_type abbrev_size
;
920 bfd_size_type line_offset
;
921 bfd_size_type line_size
;
923 bfd_size_type loc_offset
;
924 bfd_size_type loc_size
;
926 bfd_size_type macinfo_offset
;
927 bfd_size_type macinfo_size
;
929 bfd_size_type macro_offset
;
930 bfd_size_type macro_size
;
932 bfd_size_type str_offsets_offset
;
933 bfd_size_type str_offsets_size
;
935 /* Each DWP hash table entry records one CU or one TU.
936 That is recorded here, and copied to dwo_unit.section. */
937 bfd_size_type info_or_types_offset
;
938 bfd_size_type info_or_types_size
;
941 /* Contents of DWP hash tables. */
943 struct dwp_hash_table
945 uint32_t version
, nr_columns
;
946 uint32_t nr_units
, nr_slots
;
947 const gdb_byte
*hash_table
, *unit_table
;
952 const gdb_byte
*indices
;
956 /* This is indexed by column number and gives the id of the section
958 #define MAX_NR_V2_DWO_SECTIONS \
959 (1 /* .debug_info or .debug_types */ \
960 + 1 /* .debug_abbrev */ \
961 + 1 /* .debug_line */ \
962 + 1 /* .debug_loc */ \
963 + 1 /* .debug_str_offsets */ \
964 + 1 /* .debug_macro or .debug_macinfo */)
965 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
966 const gdb_byte
*offsets
;
967 const gdb_byte
*sizes
;
972 /* Data for one DWP file. */
976 /* Name of the file. */
979 /* File format version. */
985 /* Section info for this file. */
986 struct dwp_sections sections
;
988 /* Table of CUs in the file. */
989 const struct dwp_hash_table
*cus
;
991 /* Table of TUs in the file. */
992 const struct dwp_hash_table
*tus
;
994 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
998 /* Table to map ELF section numbers to their sections.
999 This is only needed for the DWP V1 file format. */
1000 unsigned int num_sections
;
1001 asection
**elf_sections
;
1004 /* This represents a '.dwz' file. */
1008 /* A dwz file can only contain a few sections. */
1009 struct dwarf2_section_info abbrev
;
1010 struct dwarf2_section_info info
;
1011 struct dwarf2_section_info str
;
1012 struct dwarf2_section_info line
;
1013 struct dwarf2_section_info macro
;
1014 struct dwarf2_section_info gdb_index
;
1016 /* The dwz's BFD. */
1020 /* Struct used to pass misc. parameters to read_die_and_children, et
1021 al. which are used for both .debug_info and .debug_types dies.
1022 All parameters here are unchanging for the life of the call. This
1023 struct exists to abstract away the constant parameters of die reading. */
1025 struct die_reader_specs
1027 /* The bfd of die_section. */
1030 /* The CU of the DIE we are parsing. */
1031 struct dwarf2_cu
*cu
;
1033 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
1034 struct dwo_file
*dwo_file
;
1036 /* The section the die comes from.
1037 This is either .debug_info or .debug_types, or the .dwo variants. */
1038 struct dwarf2_section_info
*die_section
;
1040 /* die_section->buffer. */
1041 const gdb_byte
*buffer
;
1043 /* The end of the buffer. */
1044 const gdb_byte
*buffer_end
;
1046 /* The value of the DW_AT_comp_dir attribute. */
1047 const char *comp_dir
;
1050 /* Type of function passed to init_cutu_and_read_dies, et.al. */
1051 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
1052 const gdb_byte
*info_ptr
,
1053 struct die_info
*comp_unit_die
,
1057 /* A 1-based directory index. This is a strong typedef to prevent
1058 accidentally using a directory index as a 0-based index into an
1060 enum class dir_index
: unsigned int {};
1062 /* Likewise, a 1-based file name index. */
1063 enum class file_name_index
: unsigned int {};
1067 file_entry () = default;
1069 file_entry (const char *name_
, dir_index d_index_
,
1070 unsigned int mod_time_
, unsigned int length_
)
1073 mod_time (mod_time_
),
1077 /* Return the include directory at D_INDEX stored in LH. Returns
1078 NULL if D_INDEX is out of bounds. */
1079 const char *include_dir (const line_header
*lh
) const;
1081 /* The file name. Note this is an observing pointer. The memory is
1082 owned by debug_line_buffer. */
1083 const char *name
{};
1085 /* The directory index (1-based). */
1086 dir_index d_index
{};
1088 unsigned int mod_time
{};
1090 unsigned int length
{};
1092 /* True if referenced by the Line Number Program. */
1095 /* The associated symbol table, if any. */
1096 struct symtab
*symtab
{};
1099 /* The line number information for a compilation unit (found in the
1100 .debug_line section) begins with a "statement program header",
1101 which contains the following information. */
1108 /* Add an entry to the include directory table. */
1109 void add_include_dir (const char *include_dir
);
1111 /* Add an entry to the file name table. */
1112 void add_file_name (const char *name
, dir_index d_index
,
1113 unsigned int mod_time
, unsigned int length
);
1115 /* Return the include dir at INDEX (1-based). Returns NULL if INDEX
1116 is out of bounds. */
1117 const char *include_dir_at (dir_index index
) const
1119 /* Convert directory index number (1-based) to vector index
1121 size_t vec_index
= to_underlying (index
) - 1;
1123 if (vec_index
>= include_dirs
.size ())
1125 return include_dirs
[vec_index
];
1128 /* Return the file name at INDEX (1-based). Returns NULL if INDEX
1129 is out of bounds. */
1130 file_entry
*file_name_at (file_name_index index
)
1132 /* Convert file name index number (1-based) to vector index
1134 size_t vec_index
= to_underlying (index
) - 1;
1136 if (vec_index
>= file_names
.size ())
1138 return &file_names
[vec_index
];
1141 /* Const version of the above. */
1142 const file_entry
*file_name_at (unsigned int index
) const
1144 if (index
>= file_names
.size ())
1146 return &file_names
[index
];
1149 /* Offset of line number information in .debug_line section. */
1150 sect_offset sect_off
{};
1152 /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile. */
1153 unsigned offset_in_dwz
: 1; /* Can't initialize bitfields in-class. */
1155 unsigned int total_length
{};
1156 unsigned short version
{};
1157 unsigned int header_length
{};
1158 unsigned char minimum_instruction_length
{};
1159 unsigned char maximum_ops_per_instruction
{};
1160 unsigned char default_is_stmt
{};
1162 unsigned char line_range
{};
1163 unsigned char opcode_base
{};
1165 /* standard_opcode_lengths[i] is the number of operands for the
1166 standard opcode whose value is i. This means that
1167 standard_opcode_lengths[0] is unused, and the last meaningful
1168 element is standard_opcode_lengths[opcode_base - 1]. */
1169 std::unique_ptr
<unsigned char[]> standard_opcode_lengths
;
1171 /* The include_directories table. Note these are observing
1172 pointers. The memory is owned by debug_line_buffer. */
1173 std::vector
<const char *> include_dirs
;
1175 /* The file_names table. */
1176 std::vector
<file_entry
> file_names
;
1178 /* The start and end of the statement program following this
1179 header. These point into dwarf2_per_objfile->line_buffer. */
1180 const gdb_byte
*statement_program_start
{}, *statement_program_end
{};
1183 typedef std::unique_ptr
<line_header
> line_header_up
;
1186 file_entry::include_dir (const line_header
*lh
) const
1188 return lh
->include_dir_at (d_index
);
1191 /* When we construct a partial symbol table entry we only
1192 need this much information. */
1193 struct partial_die_info
1195 /* Offset of this DIE. */
1196 sect_offset sect_off
;
1198 /* DWARF-2 tag for this DIE. */
1199 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1201 /* Assorted flags describing the data found in this DIE. */
1202 unsigned int has_children
: 1;
1203 unsigned int is_external
: 1;
1204 unsigned int is_declaration
: 1;
1205 unsigned int has_type
: 1;
1206 unsigned int has_specification
: 1;
1207 unsigned int has_pc_info
: 1;
1208 unsigned int may_be_inlined
: 1;
1210 /* This DIE has been marked DW_AT_main_subprogram. */
1211 unsigned int main_subprogram
: 1;
1213 /* Flag set if the SCOPE field of this structure has been
1215 unsigned int scope_set
: 1;
1217 /* Flag set if the DIE has a byte_size attribute. */
1218 unsigned int has_byte_size
: 1;
1220 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1221 unsigned int has_const_value
: 1;
1223 /* Flag set if any of the DIE's children are template arguments. */
1224 unsigned int has_template_arguments
: 1;
1226 /* Flag set if fixup_partial_die has been called on this die. */
1227 unsigned int fixup_called
: 1;
1229 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1230 unsigned int is_dwz
: 1;
1232 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1233 unsigned int spec_is_dwz
: 1;
1235 /* The name of this DIE. Normally the value of DW_AT_name, but
1236 sometimes a default name for unnamed DIEs. */
1239 /* The linkage name, if present. */
1240 const char *linkage_name
;
1242 /* The scope to prepend to our children. This is generally
1243 allocated on the comp_unit_obstack, so will disappear
1244 when this compilation unit leaves the cache. */
1247 /* Some data associated with the partial DIE. The tag determines
1248 which field is live. */
1251 /* The location description associated with this DIE, if any. */
1252 struct dwarf_block
*locdesc
;
1253 /* The offset of an import, for DW_TAG_imported_unit. */
1254 sect_offset sect_off
;
1257 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1261 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1262 DW_AT_sibling, if any. */
1263 /* NOTE: This member isn't strictly necessary, read_partial_die could
1264 return DW_AT_sibling values to its caller load_partial_dies. */
1265 const gdb_byte
*sibling
;
1267 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1268 DW_AT_specification (or DW_AT_abstract_origin or
1269 DW_AT_extension). */
1270 sect_offset spec_offset
;
1272 /* Pointers to this DIE's parent, first child, and next sibling,
1274 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
1277 /* This data structure holds the information of an abbrev. */
1280 unsigned int number
; /* number identifying abbrev */
1281 enum dwarf_tag tag
; /* dwarf tag */
1282 unsigned short has_children
; /* boolean */
1283 unsigned short num_attrs
; /* number of attributes */
1284 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
1285 struct abbrev_info
*next
; /* next in chain */
1290 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1291 ENUM_BITFIELD(dwarf_form
) form
: 16;
1293 /* It is valid only if FORM is DW_FORM_implicit_const. */
1294 LONGEST implicit_const
;
1297 /* Size of abbrev_table.abbrev_hash_table. */
1298 #define ABBREV_HASH_SIZE 121
1300 /* Top level data structure to contain an abbreviation table. */
1304 /* Where the abbrev table came from.
1305 This is used as a sanity check when the table is used. */
1306 sect_offset sect_off
;
1308 /* Storage for the abbrev table. */
1309 struct obstack abbrev_obstack
;
1311 /* Hash table of abbrevs.
1312 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1313 It could be statically allocated, but the previous code didn't so we
1315 struct abbrev_info
**abbrevs
;
1318 /* Attributes have a name and a value. */
1321 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1322 ENUM_BITFIELD(dwarf_form
) form
: 15;
1324 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1325 field should be in u.str (existing only for DW_STRING) but it is kept
1326 here for better struct attribute alignment. */
1327 unsigned int string_is_canonical
: 1;
1332 struct dwarf_block
*blk
;
1341 /* This data structure holds a complete die structure. */
1344 /* DWARF-2 tag for this DIE. */
1345 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1347 /* Number of attributes */
1348 unsigned char num_attrs
;
1350 /* True if we're presently building the full type name for the
1351 type derived from this DIE. */
1352 unsigned char building_fullname
: 1;
1354 /* True if this die is in process. PR 16581. */
1355 unsigned char in_process
: 1;
1358 unsigned int abbrev
;
1360 /* Offset in .debug_info or .debug_types section. */
1361 sect_offset sect_off
;
1363 /* The dies in a compilation unit form an n-ary tree. PARENT
1364 points to this die's parent; CHILD points to the first child of
1365 this node; and all the children of a given node are chained
1366 together via their SIBLING fields. */
1367 struct die_info
*child
; /* Its first child, if any. */
1368 struct die_info
*sibling
; /* Its next sibling, if any. */
1369 struct die_info
*parent
; /* Its parent, if any. */
1371 /* An array of attributes, with NUM_ATTRS elements. There may be
1372 zero, but it's not common and zero-sized arrays are not
1373 sufficiently portable C. */
1374 struct attribute attrs
[1];
1377 /* Get at parts of an attribute structure. */
1379 #define DW_STRING(attr) ((attr)->u.str)
1380 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1381 #define DW_UNSND(attr) ((attr)->u.unsnd)
1382 #define DW_BLOCK(attr) ((attr)->u.blk)
1383 #define DW_SND(attr) ((attr)->u.snd)
1384 #define DW_ADDR(attr) ((attr)->u.addr)
1385 #define DW_SIGNATURE(attr) ((attr)->u.signature)
1387 /* Blocks are a bunch of untyped bytes. */
1392 /* Valid only if SIZE is not zero. */
1393 const gdb_byte
*data
;
1396 #ifndef ATTR_ALLOC_CHUNK
1397 #define ATTR_ALLOC_CHUNK 4
1400 /* Allocate fields for structs, unions and enums in this size. */
1401 #ifndef DW_FIELD_ALLOC_CHUNK
1402 #define DW_FIELD_ALLOC_CHUNK 4
1405 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1406 but this would require a corresponding change in unpack_field_as_long
1408 static int bits_per_byte
= 8;
1412 struct nextfield
*next
;
1420 struct nextfnfield
*next
;
1421 struct fn_field fnfield
;
1428 struct nextfnfield
*head
;
1431 struct typedef_field_list
1433 struct typedef_field field
;
1434 struct typedef_field_list
*next
;
1437 /* The routines that read and process dies for a C struct or C++ class
1438 pass lists of data member fields and lists of member function fields
1439 in an instance of a field_info structure, as defined below. */
1442 /* List of data member and baseclasses fields. */
1443 struct nextfield
*fields
, *baseclasses
;
1445 /* Number of fields (including baseclasses). */
1448 /* Number of baseclasses. */
1451 /* Set if the accesibility of one of the fields is not public. */
1452 int non_public_fields
;
1454 /* Member function fields array, entries are allocated in the order they
1455 are encountered in the object file. */
1456 struct nextfnfield
*fnfields
;
1458 /* Member function fieldlist array, contains name of possibly overloaded
1459 member function, number of overloaded member functions and a pointer
1460 to the head of the member function field chain. */
1461 struct fnfieldlist
*fnfieldlists
;
1463 /* Number of entries in the fnfieldlists array. */
1466 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1467 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1468 struct typedef_field_list
*typedef_field_list
;
1469 unsigned typedef_field_list_count
;
1472 /* One item on the queue of compilation units to read in full symbols
1474 struct dwarf2_queue_item
1476 struct dwarf2_per_cu_data
*per_cu
;
1477 enum language pretend_language
;
1478 struct dwarf2_queue_item
*next
;
1481 /* The current queue. */
1482 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1484 /* Loaded secondary compilation units are kept in memory until they
1485 have not been referenced for the processing of this many
1486 compilation units. Set this to zero to disable caching. Cache
1487 sizes of up to at least twenty will improve startup time for
1488 typical inter-CU-reference binaries, at an obvious memory cost. */
1489 static int dwarf_max_cache_age
= 5;
1491 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1492 struct cmd_list_element
*c
, const char *value
)
1494 fprintf_filtered (file
, _("The upper bound on the age of cached "
1495 "DWARF compilation units is %s.\n"),
1499 /* local function prototypes */
1501 static const char *get_section_name (const struct dwarf2_section_info
*);
1503 static const char *get_section_file_name (const struct dwarf2_section_info
*);
1505 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
1507 static void dwarf2_find_base_address (struct die_info
*die
,
1508 struct dwarf2_cu
*cu
);
1510 static struct partial_symtab
*create_partial_symtab
1511 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1513 static void dwarf2_build_psymtabs_hard (struct objfile
*);
1515 static void scan_partial_symbols (struct partial_die_info
*,
1516 CORE_ADDR
*, CORE_ADDR
*,
1517 int, struct dwarf2_cu
*);
1519 static void add_partial_symbol (struct partial_die_info
*,
1520 struct dwarf2_cu
*);
1522 static void add_partial_namespace (struct partial_die_info
*pdi
,
1523 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1524 int set_addrmap
, struct dwarf2_cu
*cu
);
1526 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1527 CORE_ADDR
*highpc
, int set_addrmap
,
1528 struct dwarf2_cu
*cu
);
1530 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1531 struct dwarf2_cu
*cu
);
1533 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1534 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1535 int need_pc
, struct dwarf2_cu
*cu
);
1537 static void dwarf2_read_symtab (struct partial_symtab
*,
1540 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1542 static struct abbrev_info
*abbrev_table_lookup_abbrev
1543 (const struct abbrev_table
*, unsigned int);
1545 static struct abbrev_table
*abbrev_table_read_table
1546 (struct dwarf2_section_info
*, sect_offset
);
1548 static void abbrev_table_free (struct abbrev_table
*);
1550 static void abbrev_table_free_cleanup (void *);
1552 static void dwarf2_read_abbrevs (struct dwarf2_cu
*,
1553 struct dwarf2_section_info
*);
1555 static void dwarf2_free_abbrev_table (void *);
1557 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1559 static struct partial_die_info
*load_partial_dies
1560 (const struct die_reader_specs
*, const gdb_byte
*, int);
1562 static const gdb_byte
*read_partial_die (const struct die_reader_specs
*,
1563 struct partial_die_info
*,
1564 struct abbrev_info
*,
1568 static struct partial_die_info
*find_partial_die (sect_offset
, int,
1569 struct dwarf2_cu
*);
1571 static void fixup_partial_die (struct partial_die_info
*,
1572 struct dwarf2_cu
*);
1574 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1575 struct attribute
*, struct attr_abbrev
*,
1578 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1580 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1582 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1584 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1586 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1588 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1591 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1593 static LONGEST read_checked_initial_length_and_offset
1594 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1595 unsigned int *, unsigned int *);
1597 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1598 const struct comp_unit_head
*,
1601 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1603 static sect_offset
read_abbrev_offset (struct dwarf2_section_info
*,
1606 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1608 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1610 static const char *read_indirect_string (bfd
*, const gdb_byte
*,
1611 const struct comp_unit_head
*,
1614 static const char *read_indirect_line_string (bfd
*, const gdb_byte
*,
1615 const struct comp_unit_head
*,
1618 static const char *read_indirect_string_from_dwz (struct dwz_file
*, LONGEST
);
1620 static LONGEST
read_signed_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1622 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1626 static const char *read_str_index (const struct die_reader_specs
*reader
,
1627 ULONGEST str_index
);
1629 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1631 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1632 struct dwarf2_cu
*);
1634 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1637 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1638 struct dwarf2_cu
*cu
);
1640 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1641 struct dwarf2_cu
*cu
);
1643 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1645 static struct die_info
*die_specification (struct die_info
*die
,
1646 struct dwarf2_cu
**);
1648 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1649 struct dwarf2_cu
*cu
);
1651 static void dwarf_decode_lines (struct line_header
*, const char *,
1652 struct dwarf2_cu
*, struct partial_symtab
*,
1653 CORE_ADDR
, int decode_mapping
);
1655 static void dwarf2_start_subfile (const char *, const char *);
1657 static struct compunit_symtab
*dwarf2_start_symtab (struct dwarf2_cu
*,
1658 const char *, const char *,
1661 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1662 struct dwarf2_cu
*);
1664 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1665 struct dwarf2_cu
*, struct symbol
*);
1667 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1668 struct dwarf2_cu
*);
1670 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1673 struct obstack
*obstack
,
1674 struct dwarf2_cu
*cu
, LONGEST
*value
,
1675 const gdb_byte
**bytes
,
1676 struct dwarf2_locexpr_baton
**baton
);
1678 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1680 static int need_gnat_info (struct dwarf2_cu
*);
1682 static struct type
*die_descriptive_type (struct die_info
*,
1683 struct dwarf2_cu
*);
1685 static void set_descriptive_type (struct type
*, struct die_info
*,
1686 struct dwarf2_cu
*);
1688 static struct type
*die_containing_type (struct die_info
*,
1689 struct dwarf2_cu
*);
1691 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1692 struct dwarf2_cu
*);
1694 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1696 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1698 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1700 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1701 const char *suffix
, int physname
,
1702 struct dwarf2_cu
*cu
);
1704 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1706 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1708 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1710 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1712 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1714 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1715 struct dwarf2_cu
*, struct partial_symtab
*);
1717 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1718 values. Keep the items ordered with increasing constraints compliance. */
1721 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1722 PC_BOUNDS_NOT_PRESENT
,
1724 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1725 were present but they do not form a valid range of PC addresses. */
1728 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1731 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1735 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1736 CORE_ADDR
*, CORE_ADDR
*,
1738 struct partial_symtab
*);
1740 static void get_scope_pc_bounds (struct die_info
*,
1741 CORE_ADDR
*, CORE_ADDR
*,
1742 struct dwarf2_cu
*);
1744 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1745 CORE_ADDR
, struct dwarf2_cu
*);
1747 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1748 struct dwarf2_cu
*);
1750 static void dwarf2_attach_fields_to_type (struct field_info
*,
1751 struct type
*, struct dwarf2_cu
*);
1753 static void dwarf2_add_member_fn (struct field_info
*,
1754 struct die_info
*, struct type
*,
1755 struct dwarf2_cu
*);
1757 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1759 struct dwarf2_cu
*);
1761 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1763 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1765 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1767 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1769 static struct using_direct
**using_directives (enum language
);
1771 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1773 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1775 static struct type
*read_module_type (struct die_info
*die
,
1776 struct dwarf2_cu
*cu
);
1778 static const char *namespace_name (struct die_info
*die
,
1779 int *is_anonymous
, struct dwarf2_cu
*);
1781 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1783 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1785 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1786 struct dwarf2_cu
*);
1788 static struct die_info
*read_die_and_siblings_1
1789 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1792 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1793 const gdb_byte
*info_ptr
,
1794 const gdb_byte
**new_info_ptr
,
1795 struct die_info
*parent
);
1797 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1798 struct die_info
**, const gdb_byte
*,
1801 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1802 struct die_info
**, const gdb_byte
*,
1805 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1807 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1810 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1812 static const char *dwarf2_full_name (const char *name
,
1813 struct die_info
*die
,
1814 struct dwarf2_cu
*cu
);
1816 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1817 struct dwarf2_cu
*cu
);
1819 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1820 struct dwarf2_cu
**);
1822 static const char *dwarf_tag_name (unsigned int);
1824 static const char *dwarf_attr_name (unsigned int);
1826 static const char *dwarf_form_name (unsigned int);
1828 static char *dwarf_bool_name (unsigned int);
1830 static const char *dwarf_type_encoding_name (unsigned int);
1832 static struct die_info
*sibling_die (struct die_info
*);
1834 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1836 static void dump_die_for_error (struct die_info
*);
1838 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1841 /*static*/ void dump_die (struct die_info
*, int max_level
);
1843 static void store_in_ref_table (struct die_info
*,
1844 struct dwarf2_cu
*);
1846 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1848 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1850 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1851 const struct attribute
*,
1852 struct dwarf2_cu
**);
1854 static struct die_info
*follow_die_ref (struct die_info
*,
1855 const struct attribute
*,
1856 struct dwarf2_cu
**);
1858 static struct die_info
*follow_die_sig (struct die_info
*,
1859 const struct attribute
*,
1860 struct dwarf2_cu
**);
1862 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1863 struct dwarf2_cu
*);
1865 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1866 const struct attribute
*,
1867 struct dwarf2_cu
*);
1869 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1871 static void read_signatured_type (struct signatured_type
*);
1873 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1874 struct die_info
*die
, struct dwarf2_cu
*cu
,
1875 struct dynamic_prop
*prop
);
1877 /* memory allocation interface */
1879 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1881 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1883 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1885 static int attr_form_is_block (const struct attribute
*);
1887 static int attr_form_is_section_offset (const struct attribute
*);
1889 static int attr_form_is_constant (const struct attribute
*);
1891 static int attr_form_is_ref (const struct attribute
*);
1893 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1894 struct dwarf2_loclist_baton
*baton
,
1895 const struct attribute
*attr
);
1897 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1899 struct dwarf2_cu
*cu
,
1902 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1903 const gdb_byte
*info_ptr
,
1904 struct abbrev_info
*abbrev
);
1906 static void free_stack_comp_unit (void *);
1908 static hashval_t
partial_die_hash (const void *item
);
1910 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1912 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1913 (sect_offset sect_off
, unsigned int offset_in_dwz
, struct objfile
*objfile
);
1915 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1916 struct dwarf2_per_cu_data
*per_cu
);
1918 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1919 struct die_info
*comp_unit_die
,
1920 enum language pretend_language
);
1922 static void free_heap_comp_unit (void *);
1924 static void free_cached_comp_units (void *);
1926 static void age_cached_comp_units (void);
1928 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1930 static struct type
*set_die_type (struct die_info
*, struct type
*,
1931 struct dwarf2_cu
*);
1933 static void create_all_comp_units (struct objfile
*);
1935 static int create_all_type_units (struct objfile
*);
1937 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1940 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1943 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1946 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1947 struct dwarf2_per_cu_data
*);
1949 static void dwarf2_mark (struct dwarf2_cu
*);
1951 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1953 static struct type
*get_die_type_at_offset (sect_offset
,
1954 struct dwarf2_per_cu_data
*);
1956 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1958 static void dwarf2_release_queue (void *dummy
);
1960 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1961 enum language pretend_language
);
1963 static void process_queue (void);
1965 /* The return type of find_file_and_directory. Note, the enclosed
1966 string pointers are only valid while this object is valid. */
1968 struct file_and_directory
1970 /* The filename. This is never NULL. */
1973 /* The compilation directory. NULL if not known. If we needed to
1974 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1975 points directly to the DW_AT_comp_dir string attribute owned by
1976 the obstack that owns the DIE. */
1977 const char *comp_dir
;
1979 /* If we needed to build a new string for comp_dir, this is what
1980 owns the storage. */
1981 std::string comp_dir_storage
;
1984 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1985 struct dwarf2_cu
*cu
);
1987 static char *file_full_name (int file
, struct line_header
*lh
,
1988 const char *comp_dir
);
1990 /* Expected enum dwarf_unit_type for read_comp_unit_head. */
1991 enum class rcuh_kind
{ COMPILE
, TYPE
};
1993 static const gdb_byte
*read_and_check_comp_unit_head
1994 (struct comp_unit_head
*header
,
1995 struct dwarf2_section_info
*section
,
1996 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
1997 rcuh_kind section_kind
);
1999 static void init_cutu_and_read_dies
2000 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
2001 int use_existing_cu
, int keep
,
2002 die_reader_func_ftype
*die_reader_func
, void *data
);
2004 static void init_cutu_and_read_dies_simple
2005 (struct dwarf2_per_cu_data
*this_cu
,
2006 die_reader_func_ftype
*die_reader_func
, void *data
);
2008 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
2010 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
2012 static struct dwo_unit
*lookup_dwo_unit_in_dwp
2013 (struct dwp_file
*dwp_file
, const char *comp_dir
,
2014 ULONGEST signature
, int is_debug_types
);
2016 static struct dwp_file
*get_dwp_file (void);
2018 static struct dwo_unit
*lookup_dwo_comp_unit
2019 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
2021 static struct dwo_unit
*lookup_dwo_type_unit
2022 (struct signatured_type
*, const char *, const char *);
2024 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
2026 static void free_dwo_file_cleanup (void *);
2028 static void process_cu_includes (void);
2030 static void check_producer (struct dwarf2_cu
*cu
);
2032 static void free_line_header_voidp (void *arg
);
2034 /* Various complaints about symbol reading that don't abort the process. */
2037 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
2039 complaint (&symfile_complaints
,
2040 _("statement list doesn't fit in .debug_line section"));
2044 dwarf2_debug_line_missing_file_complaint (void)
2046 complaint (&symfile_complaints
,
2047 _(".debug_line section has line data without a file"));
2051 dwarf2_debug_line_missing_end_sequence_complaint (void)
2053 complaint (&symfile_complaints
,
2054 _(".debug_line section has line "
2055 "program sequence without an end"));
2059 dwarf2_complex_location_expr_complaint (void)
2061 complaint (&symfile_complaints
, _("location expression too complex"));
2065 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
2068 complaint (&symfile_complaints
,
2069 _("const value length mismatch for '%s', got %d, expected %d"),
2074 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
2076 complaint (&symfile_complaints
,
2077 _("debug info runs off end of %s section"
2079 get_section_name (section
),
2080 get_section_file_name (section
));
2084 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
2086 complaint (&symfile_complaints
,
2087 _("macro debug info contains a "
2088 "malformed macro definition:\n`%s'"),
2093 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
2095 complaint (&symfile_complaints
,
2096 _("invalid attribute class or form for '%s' in '%s'"),
2100 /* Hash function for line_header_hash. */
2103 line_header_hash (const struct line_header
*ofs
)
2105 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
2108 /* Hash function for htab_create_alloc_ex for line_header_hash. */
2111 line_header_hash_voidp (const void *item
)
2113 const struct line_header
*ofs
= (const struct line_header
*) item
;
2115 return line_header_hash (ofs
);
2118 /* Equality function for line_header_hash. */
2121 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
2123 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
2124 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
2126 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
2127 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
2133 /* Convert VALUE between big- and little-endian. */
2135 byte_swap (offset_type value
)
2139 result
= (value
& 0xff) << 24;
2140 result
|= (value
& 0xff00) << 8;
2141 result
|= (value
& 0xff0000) >> 8;
2142 result
|= (value
& 0xff000000) >> 24;
2146 #define MAYBE_SWAP(V) byte_swap (V)
2149 #define MAYBE_SWAP(V) (V)
2150 #endif /* WORDS_BIGENDIAN */
2152 /* Read the given attribute value as an address, taking the attribute's
2153 form into account. */
2156 attr_value_as_address (struct attribute
*attr
)
2160 if (attr
->form
!= DW_FORM_addr
&& attr
->form
!= DW_FORM_GNU_addr_index
)
2162 /* Aside from a few clearly defined exceptions, attributes that
2163 contain an address must always be in DW_FORM_addr form.
2164 Unfortunately, some compilers happen to be violating this
2165 requirement by encoding addresses using other forms, such
2166 as DW_FORM_data4 for example. For those broken compilers,
2167 we try to do our best, without any guarantee of success,
2168 to interpret the address correctly. It would also be nice
2169 to generate a complaint, but that would require us to maintain
2170 a list of legitimate cases where a non-address form is allowed,
2171 as well as update callers to pass in at least the CU's DWARF
2172 version. This is more overhead than what we're willing to
2173 expand for a pretty rare case. */
2174 addr
= DW_UNSND (attr
);
2177 addr
= DW_ADDR (attr
);
2182 /* The suffix for an index file. */
2183 #define INDEX_SUFFIX ".gdb-index"
2185 /* Try to locate the sections we need for DWARF 2 debugging
2186 information and return true if we have enough to do something.
2187 NAMES points to the dwarf2 section names, or is NULL if the standard
2188 ELF names are used. */
2191 dwarf2_has_info (struct objfile
*objfile
,
2192 const struct dwarf2_debug_sections
*names
)
2194 dwarf2_per_objfile
= ((struct dwarf2_per_objfile
*)
2195 objfile_data (objfile
, dwarf2_objfile_data_key
));
2196 if (!dwarf2_per_objfile
)
2198 /* Initialize per-objfile state. */
2199 struct dwarf2_per_objfile
*data
2200 = XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_per_objfile
);
2202 memset (data
, 0, sizeof (*data
));
2203 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
2204 dwarf2_per_objfile
= data
;
2206 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
2208 dwarf2_per_objfile
->objfile
= objfile
;
2210 return (!dwarf2_per_objfile
->info
.is_virtual
2211 && dwarf2_per_objfile
->info
.s
.section
!= NULL
2212 && !dwarf2_per_objfile
->abbrev
.is_virtual
2213 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
2216 /* Return the containing section of virtual section SECTION. */
2218 static struct dwarf2_section_info
*
2219 get_containing_section (const struct dwarf2_section_info
*section
)
2221 gdb_assert (section
->is_virtual
);
2222 return section
->s
.containing_section
;
2225 /* Return the bfd owner of SECTION. */
2228 get_section_bfd_owner (const struct dwarf2_section_info
*section
)
2230 if (section
->is_virtual
)
2232 section
= get_containing_section (section
);
2233 gdb_assert (!section
->is_virtual
);
2235 return section
->s
.section
->owner
;
2238 /* Return the bfd section of SECTION.
2239 Returns NULL if the section is not present. */
2242 get_section_bfd_section (const struct dwarf2_section_info
*section
)
2244 if (section
->is_virtual
)
2246 section
= get_containing_section (section
);
2247 gdb_assert (!section
->is_virtual
);
2249 return section
->s
.section
;
2252 /* Return the name of SECTION. */
2255 get_section_name (const struct dwarf2_section_info
*section
)
2257 asection
*sectp
= get_section_bfd_section (section
);
2259 gdb_assert (sectp
!= NULL
);
2260 return bfd_section_name (get_section_bfd_owner (section
), sectp
);
2263 /* Return the name of the file SECTION is in. */
2266 get_section_file_name (const struct dwarf2_section_info
*section
)
2268 bfd
*abfd
= get_section_bfd_owner (section
);
2270 return bfd_get_filename (abfd
);
2273 /* Return the id of SECTION.
2274 Returns 0 if SECTION doesn't exist. */
2277 get_section_id (const struct dwarf2_section_info
*section
)
2279 asection
*sectp
= get_section_bfd_section (section
);
2286 /* Return the flags of SECTION.
2287 SECTION (or containing section if this is a virtual section) must exist. */
2290 get_section_flags (const struct dwarf2_section_info
*section
)
2292 asection
*sectp
= get_section_bfd_section (section
);
2294 gdb_assert (sectp
!= NULL
);
2295 return bfd_get_section_flags (sectp
->owner
, sectp
);
2298 /* When loading sections, we look either for uncompressed section or for
2299 compressed section names. */
2302 section_is_p (const char *section_name
,
2303 const struct dwarf2_section_names
*names
)
2305 if (names
->normal
!= NULL
2306 && strcmp (section_name
, names
->normal
) == 0)
2308 if (names
->compressed
!= NULL
2309 && strcmp (section_name
, names
->compressed
) == 0)
2314 /* This function is mapped across the sections and remembers the
2315 offset and size of each of the debugging sections we are interested
2319 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
2321 const struct dwarf2_debug_sections
*names
;
2322 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
2325 names
= &dwarf2_elf_names
;
2327 names
= (const struct dwarf2_debug_sections
*) vnames
;
2329 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2332 else if (section_is_p (sectp
->name
, &names
->info
))
2334 dwarf2_per_objfile
->info
.s
.section
= sectp
;
2335 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
2337 else if (section_is_p (sectp
->name
, &names
->abbrev
))
2339 dwarf2_per_objfile
->abbrev
.s
.section
= sectp
;
2340 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
2342 else if (section_is_p (sectp
->name
, &names
->line
))
2344 dwarf2_per_objfile
->line
.s
.section
= sectp
;
2345 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
2347 else if (section_is_p (sectp
->name
, &names
->loc
))
2349 dwarf2_per_objfile
->loc
.s
.section
= sectp
;
2350 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
2352 else if (section_is_p (sectp
->name
, &names
->loclists
))
2354 dwarf2_per_objfile
->loclists
.s
.section
= sectp
;
2355 dwarf2_per_objfile
->loclists
.size
= bfd_get_section_size (sectp
);
2357 else if (section_is_p (sectp
->name
, &names
->macinfo
))
2359 dwarf2_per_objfile
->macinfo
.s
.section
= sectp
;
2360 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
2362 else if (section_is_p (sectp
->name
, &names
->macro
))
2364 dwarf2_per_objfile
->macro
.s
.section
= sectp
;
2365 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
2367 else if (section_is_p (sectp
->name
, &names
->str
))
2369 dwarf2_per_objfile
->str
.s
.section
= sectp
;
2370 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
2372 else if (section_is_p (sectp
->name
, &names
->line_str
))
2374 dwarf2_per_objfile
->line_str
.s
.section
= sectp
;
2375 dwarf2_per_objfile
->line_str
.size
= bfd_get_section_size (sectp
);
2377 else if (section_is_p (sectp
->name
, &names
->addr
))
2379 dwarf2_per_objfile
->addr
.s
.section
= sectp
;
2380 dwarf2_per_objfile
->addr
.size
= bfd_get_section_size (sectp
);
2382 else if (section_is_p (sectp
->name
, &names
->frame
))
2384 dwarf2_per_objfile
->frame
.s
.section
= sectp
;
2385 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
2387 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
2389 dwarf2_per_objfile
->eh_frame
.s
.section
= sectp
;
2390 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
2392 else if (section_is_p (sectp
->name
, &names
->ranges
))
2394 dwarf2_per_objfile
->ranges
.s
.section
= sectp
;
2395 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
2397 else if (section_is_p (sectp
->name
, &names
->rnglists
))
2399 dwarf2_per_objfile
->rnglists
.s
.section
= sectp
;
2400 dwarf2_per_objfile
->rnglists
.size
= bfd_get_section_size (sectp
);
2402 else if (section_is_p (sectp
->name
, &names
->types
))
2404 struct dwarf2_section_info type_section
;
2406 memset (&type_section
, 0, sizeof (type_section
));
2407 type_section
.s
.section
= sectp
;
2408 type_section
.size
= bfd_get_section_size (sectp
);
2410 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
2413 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
2415 dwarf2_per_objfile
->gdb_index
.s
.section
= sectp
;
2416 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
2419 if ((bfd_get_section_flags (abfd
, sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2420 && bfd_section_vma (abfd
, sectp
) == 0)
2421 dwarf2_per_objfile
->has_section_at_zero
= 1;
2424 /* A helper function that decides whether a section is empty,
2428 dwarf2_section_empty_p (const struct dwarf2_section_info
*section
)
2430 if (section
->is_virtual
)
2431 return section
->size
== 0;
2432 return section
->s
.section
== NULL
|| section
->size
== 0;
2435 /* Read the contents of the section INFO.
2436 OBJFILE is the main object file, but not necessarily the file where
2437 the section comes from. E.g., for DWO files the bfd of INFO is the bfd
2439 If the section is compressed, uncompress it before returning. */
2442 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
2446 gdb_byte
*buf
, *retbuf
;
2450 info
->buffer
= NULL
;
2453 if (dwarf2_section_empty_p (info
))
2456 sectp
= get_section_bfd_section (info
);
2458 /* If this is a virtual section we need to read in the real one first. */
2459 if (info
->is_virtual
)
2461 struct dwarf2_section_info
*containing_section
=
2462 get_containing_section (info
);
2464 gdb_assert (sectp
!= NULL
);
2465 if ((sectp
->flags
& SEC_RELOC
) != 0)
2467 error (_("Dwarf Error: DWP format V2 with relocations is not"
2468 " supported in section %s [in module %s]"),
2469 get_section_name (info
), get_section_file_name (info
));
2471 dwarf2_read_section (objfile
, containing_section
);
2472 /* Other code should have already caught virtual sections that don't
2474 gdb_assert (info
->virtual_offset
+ info
->size
2475 <= containing_section
->size
);
2476 /* If the real section is empty or there was a problem reading the
2477 section we shouldn't get here. */
2478 gdb_assert (containing_section
->buffer
!= NULL
);
2479 info
->buffer
= containing_section
->buffer
+ info
->virtual_offset
;
2483 /* If the section has relocations, we must read it ourselves.
2484 Otherwise we attach it to the BFD. */
2485 if ((sectp
->flags
& SEC_RELOC
) == 0)
2487 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
2491 buf
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
2494 /* When debugging .o files, we may need to apply relocations; see
2495 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2496 We never compress sections in .o files, so we only need to
2497 try this when the section is not compressed. */
2498 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
2501 info
->buffer
= retbuf
;
2505 abfd
= get_section_bfd_owner (info
);
2506 gdb_assert (abfd
!= NULL
);
2508 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
2509 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
2511 error (_("Dwarf Error: Can't read DWARF data"
2512 " in section %s [in module %s]"),
2513 bfd_section_name (abfd
, sectp
), bfd_get_filename (abfd
));
2517 /* A helper function that returns the size of a section in a safe way.
2518 If you are positive that the section has been read before using the
2519 size, then it is safe to refer to the dwarf2_section_info object's
2520 "size" field directly. In other cases, you must call this
2521 function, because for compressed sections the size field is not set
2522 correctly until the section has been read. */
2524 static bfd_size_type
2525 dwarf2_section_size (struct objfile
*objfile
,
2526 struct dwarf2_section_info
*info
)
2529 dwarf2_read_section (objfile
, info
);
2533 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2537 dwarf2_get_section_info (struct objfile
*objfile
,
2538 enum dwarf2_section_enum sect
,
2539 asection
**sectp
, const gdb_byte
**bufp
,
2540 bfd_size_type
*sizep
)
2542 struct dwarf2_per_objfile
*data
2543 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
2544 dwarf2_objfile_data_key
);
2545 struct dwarf2_section_info
*info
;
2547 /* We may see an objfile without any DWARF, in which case we just
2558 case DWARF2_DEBUG_FRAME
:
2559 info
= &data
->frame
;
2561 case DWARF2_EH_FRAME
:
2562 info
= &data
->eh_frame
;
2565 gdb_assert_not_reached ("unexpected section");
2568 dwarf2_read_section (objfile
, info
);
2570 *sectp
= get_section_bfd_section (info
);
2571 *bufp
= info
->buffer
;
2572 *sizep
= info
->size
;
2575 /* A helper function to find the sections for a .dwz file. */
2578 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2580 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2582 /* Note that we only support the standard ELF names, because .dwz
2583 is ELF-only (at the time of writing). */
2584 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2586 dwz_file
->abbrev
.s
.section
= sectp
;
2587 dwz_file
->abbrev
.size
= bfd_get_section_size (sectp
);
2589 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2591 dwz_file
->info
.s
.section
= sectp
;
2592 dwz_file
->info
.size
= bfd_get_section_size (sectp
);
2594 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2596 dwz_file
->str
.s
.section
= sectp
;
2597 dwz_file
->str
.size
= bfd_get_section_size (sectp
);
2599 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2601 dwz_file
->line
.s
.section
= sectp
;
2602 dwz_file
->line
.size
= bfd_get_section_size (sectp
);
2604 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2606 dwz_file
->macro
.s
.section
= sectp
;
2607 dwz_file
->macro
.size
= bfd_get_section_size (sectp
);
2609 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2611 dwz_file
->gdb_index
.s
.section
= sectp
;
2612 dwz_file
->gdb_index
.size
= bfd_get_section_size (sectp
);
2616 /* Open the separate '.dwz' debug file, if needed. Return NULL if
2617 there is no .gnu_debugaltlink section in the file. Error if there
2618 is such a section but the file cannot be found. */
2620 static struct dwz_file
*
2621 dwarf2_get_dwz_file (void)
2624 struct cleanup
*cleanup
;
2625 const char *filename
;
2626 struct dwz_file
*result
;
2627 bfd_size_type buildid_len_arg
;
2631 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2632 return dwarf2_per_objfile
->dwz_file
;
2634 bfd_set_error (bfd_error_no_error
);
2635 data
= bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2636 &buildid_len_arg
, &buildid
);
2639 if (bfd_get_error () == bfd_error_no_error
)
2641 error (_("could not read '.gnu_debugaltlink' section: %s"),
2642 bfd_errmsg (bfd_get_error ()));
2644 cleanup
= make_cleanup (xfree
, data
);
2645 make_cleanup (xfree
, buildid
);
2647 buildid_len
= (size_t) buildid_len_arg
;
2649 filename
= (const char *) data
;
2651 std::string abs_storage
;
2652 if (!IS_ABSOLUTE_PATH (filename
))
2654 char *abs
= gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2656 make_cleanup (xfree
, abs
);
2657 abs_storage
= ldirname (abs
) + SLASH_STRING
+ filename
;
2658 filename
= abs_storage
.c_str ();
2661 /* First try the file name given in the section. If that doesn't
2662 work, try to use the build-id instead. */
2663 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2664 if (dwz_bfd
!= NULL
)
2666 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2670 if (dwz_bfd
== NULL
)
2671 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2673 if (dwz_bfd
== NULL
)
2674 error (_("could not find '.gnu_debugaltlink' file for %s"),
2675 objfile_name (dwarf2_per_objfile
->objfile
));
2677 result
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
2679 result
->dwz_bfd
= dwz_bfd
.release ();
2681 bfd_map_over_sections (result
->dwz_bfd
, locate_dwz_sections
, result
);
2683 do_cleanups (cleanup
);
2685 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, result
->dwz_bfd
);
2686 dwarf2_per_objfile
->dwz_file
= result
;
2690 /* DWARF quick_symbols_functions support. */
2692 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2693 unique line tables, so we maintain a separate table of all .debug_line
2694 derived entries to support the sharing.
2695 All the quick functions need is the list of file names. We discard the
2696 line_header when we're done and don't need to record it here. */
2697 struct quick_file_names
2699 /* The data used to construct the hash key. */
2700 struct stmt_list_hash hash
;
2702 /* The number of entries in file_names, real_names. */
2703 unsigned int num_file_names
;
2705 /* The file names from the line table, after being run through
2707 const char **file_names
;
2709 /* The file names from the line table after being run through
2710 gdb_realpath. These are computed lazily. */
2711 const char **real_names
;
2714 /* When using the index (and thus not using psymtabs), each CU has an
2715 object of this type. This is used to hold information needed by
2716 the various "quick" methods. */
2717 struct dwarf2_per_cu_quick_data
2719 /* The file table. This can be NULL if there was no file table
2720 or it's currently not read in.
2721 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2722 struct quick_file_names
*file_names
;
2724 /* The corresponding symbol table. This is NULL if symbols for this
2725 CU have not yet been read. */
2726 struct compunit_symtab
*compunit_symtab
;
2728 /* A temporary mark bit used when iterating over all CUs in
2729 expand_symtabs_matching. */
2730 unsigned int mark
: 1;
2732 /* True if we've tried to read the file table and found there isn't one.
2733 There will be no point in trying to read it again next time. */
2734 unsigned int no_file_data
: 1;
2737 /* Utility hash function for a stmt_list_hash. */
2740 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2744 if (stmt_list_hash
->dwo_unit
!= NULL
)
2745 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2746 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2750 /* Utility equality function for a stmt_list_hash. */
2753 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2754 const struct stmt_list_hash
*rhs
)
2756 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2758 if (lhs
->dwo_unit
!= NULL
2759 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2762 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2765 /* Hash function for a quick_file_names. */
2768 hash_file_name_entry (const void *e
)
2770 const struct quick_file_names
*file_data
2771 = (const struct quick_file_names
*) e
;
2773 return hash_stmt_list_entry (&file_data
->hash
);
2776 /* Equality function for a quick_file_names. */
2779 eq_file_name_entry (const void *a
, const void *b
)
2781 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2782 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2784 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2787 /* Delete function for a quick_file_names. */
2790 delete_file_name_entry (void *e
)
2792 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2795 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2797 xfree ((void*) file_data
->file_names
[i
]);
2798 if (file_data
->real_names
)
2799 xfree ((void*) file_data
->real_names
[i
]);
2802 /* The space for the struct itself lives on objfile_obstack,
2803 so we don't free it here. */
2806 /* Create a quick_file_names hash table. */
2809 create_quick_file_names_table (unsigned int nr_initial_entries
)
2811 return htab_create_alloc (nr_initial_entries
,
2812 hash_file_name_entry
, eq_file_name_entry
,
2813 delete_file_name_entry
, xcalloc
, xfree
);
2816 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2817 have to be created afterwards. You should call age_cached_comp_units after
2818 processing PER_CU->CU. dw2_setup must have been already called. */
2821 load_cu (struct dwarf2_per_cu_data
*per_cu
)
2823 if (per_cu
->is_debug_types
)
2824 load_full_type_unit (per_cu
);
2826 load_full_comp_unit (per_cu
, language_minimal
);
2828 if (per_cu
->cu
== NULL
)
2829 return; /* Dummy CU. */
2831 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2834 /* Read in the symbols for PER_CU. */
2837 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2839 struct cleanup
*back_to
;
2841 /* Skip type_unit_groups, reading the type units they contain
2842 is handled elsewhere. */
2843 if (IS_TYPE_UNIT_GROUP (per_cu
))
2846 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2848 if (dwarf2_per_objfile
->using_index
2849 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2850 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2852 queue_comp_unit (per_cu
, language_minimal
);
2855 /* If we just loaded a CU from a DWO, and we're working with an index
2856 that may badly handle TUs, load all the TUs in that DWO as well.
2857 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2858 if (!per_cu
->is_debug_types
2859 && per_cu
->cu
!= NULL
2860 && per_cu
->cu
->dwo_unit
!= NULL
2861 && dwarf2_per_objfile
->index_table
!= NULL
2862 && dwarf2_per_objfile
->index_table
->version
<= 7
2863 /* DWP files aren't supported yet. */
2864 && get_dwp_file () == NULL
)
2865 queue_and_load_all_dwo_tus (per_cu
);
2870 /* Age the cache, releasing compilation units that have not
2871 been used recently. */
2872 age_cached_comp_units ();
2874 do_cleanups (back_to
);
2877 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2878 the objfile from which this CU came. Returns the resulting symbol
2881 static struct compunit_symtab
*
2882 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2884 gdb_assert (dwarf2_per_objfile
->using_index
);
2885 if (!per_cu
->v
.quick
->compunit_symtab
)
2887 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2888 increment_reading_symtab ();
2889 dw2_do_instantiate_symtab (per_cu
);
2890 process_cu_includes ();
2891 do_cleanups (back_to
);
2894 return per_cu
->v
.quick
->compunit_symtab
;
2897 /* Return the CU/TU given its index.
2899 This is intended for loops like:
2901 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2902 + dwarf2_per_objfile->n_type_units); ++i)
2904 struct dwarf2_per_cu_data *per_cu = dw2_get_cutu (i);
2910 static struct dwarf2_per_cu_data
*
2911 dw2_get_cutu (int index
)
2913 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2915 index
-= dwarf2_per_objfile
->n_comp_units
;
2916 gdb_assert (index
< dwarf2_per_objfile
->n_type_units
);
2917 return &dwarf2_per_objfile
->all_type_units
[index
]->per_cu
;
2920 return dwarf2_per_objfile
->all_comp_units
[index
];
2923 /* Return the CU given its index.
2924 This differs from dw2_get_cutu in that it's for when you know INDEX
2927 static struct dwarf2_per_cu_data
*
2928 dw2_get_cu (int index
)
2930 gdb_assert (index
>= 0 && index
< dwarf2_per_objfile
->n_comp_units
);
2932 return dwarf2_per_objfile
->all_comp_units
[index
];
2935 /* A helper for create_cus_from_index that handles a given list of
2939 create_cus_from_index_list (struct objfile
*objfile
,
2940 const gdb_byte
*cu_list
, offset_type n_elements
,
2941 struct dwarf2_section_info
*section
,
2947 for (i
= 0; i
< n_elements
; i
+= 2)
2949 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2951 sect_offset sect_off
2952 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2953 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2956 dwarf2_per_cu_data
*the_cu
2957 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2958 struct dwarf2_per_cu_data
);
2959 the_cu
->sect_off
= sect_off
;
2960 the_cu
->length
= length
;
2961 the_cu
->objfile
= objfile
;
2962 the_cu
->section
= section
;
2963 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2964 struct dwarf2_per_cu_quick_data
);
2965 the_cu
->is_dwz
= is_dwz
;
2966 dwarf2_per_objfile
->all_comp_units
[base_offset
+ i
/ 2] = the_cu
;
2970 /* Read the CU list from the mapped index, and use it to create all
2971 the CU objects for this objfile. */
2974 create_cus_from_index (struct objfile
*objfile
,
2975 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2976 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2978 struct dwz_file
*dwz
;
2980 dwarf2_per_objfile
->n_comp_units
= (cu_list_elements
+ dwz_elements
) / 2;
2981 dwarf2_per_objfile
->all_comp_units
=
2982 XOBNEWVEC (&objfile
->objfile_obstack
, struct dwarf2_per_cu_data
*,
2983 dwarf2_per_objfile
->n_comp_units
);
2985 create_cus_from_index_list (objfile
, cu_list
, cu_list_elements
,
2986 &dwarf2_per_objfile
->info
, 0, 0);
2988 if (dwz_elements
== 0)
2991 dwz
= dwarf2_get_dwz_file ();
2992 create_cus_from_index_list (objfile
, dwz_list
, dwz_elements
, &dwz
->info
, 1,
2993 cu_list_elements
/ 2);
2996 /* Create the signatured type hash table from the index. */
2999 create_signatured_type_table_from_index (struct objfile
*objfile
,
3000 struct dwarf2_section_info
*section
,
3001 const gdb_byte
*bytes
,
3002 offset_type elements
)
3005 htab_t sig_types_hash
;
3007 dwarf2_per_objfile
->n_type_units
3008 = dwarf2_per_objfile
->n_allocated_type_units
3010 dwarf2_per_objfile
->all_type_units
=
3011 XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
3013 sig_types_hash
= allocate_signatured_type_table (objfile
);
3015 for (i
= 0; i
< elements
; i
+= 3)
3017 struct signatured_type
*sig_type
;
3020 cu_offset type_offset_in_tu
;
3022 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3023 sect_offset sect_off
3024 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
3026 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
3028 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
3031 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3032 struct signatured_type
);
3033 sig_type
->signature
= signature
;
3034 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3035 sig_type
->per_cu
.is_debug_types
= 1;
3036 sig_type
->per_cu
.section
= section
;
3037 sig_type
->per_cu
.sect_off
= sect_off
;
3038 sig_type
->per_cu
.objfile
= objfile
;
3039 sig_type
->per_cu
.v
.quick
3040 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3041 struct dwarf2_per_cu_quick_data
);
3043 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3046 dwarf2_per_objfile
->all_type_units
[i
/ 3] = sig_type
;
3049 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3052 /* Read the address map data from the mapped index, and use it to
3053 populate the objfile's psymtabs_addrmap. */
3056 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
3058 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3059 const gdb_byte
*iter
, *end
;
3060 struct obstack temp_obstack
;
3061 struct addrmap
*mutable_map
;
3062 struct cleanup
*cleanup
;
3065 obstack_init (&temp_obstack
);
3066 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
3067 mutable_map
= addrmap_create_mutable (&temp_obstack
);
3069 iter
= index
->address_table
;
3070 end
= iter
+ index
->address_table_size
;
3072 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3076 ULONGEST hi
, lo
, cu_index
;
3077 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3079 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3081 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
3086 complaint (&symfile_complaints
,
3087 _(".gdb_index address table has invalid range (%s - %s)"),
3088 hex_string (lo
), hex_string (hi
));
3092 if (cu_index
>= dwarf2_per_objfile
->n_comp_units
)
3094 complaint (&symfile_complaints
,
3095 _(".gdb_index address table has invalid CU number %u"),
3096 (unsigned) cu_index
);
3100 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
);
3101 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
);
3102 addrmap_set_empty (mutable_map
, lo
, hi
- 1, dw2_get_cutu (cu_index
));
3105 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
3106 &objfile
->objfile_obstack
);
3107 do_cleanups (cleanup
);
3110 /* The hash function for strings in the mapped index. This is the same as
3111 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
3112 implementation. This is necessary because the hash function is tied to the
3113 format of the mapped index file. The hash values do not have to match with
3116 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
3119 mapped_index_string_hash (int index_version
, const void *p
)
3121 const unsigned char *str
= (const unsigned char *) p
;
3125 while ((c
= *str
++) != 0)
3127 if (index_version
>= 5)
3129 r
= r
* 67 + c
- 113;
3135 /* Find a slot in the mapped index INDEX for the object named NAME.
3136 If NAME is found, set *VEC_OUT to point to the CU vector in the
3137 constant pool and return 1. If NAME cannot be found, return 0. */
3140 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3141 offset_type
**vec_out
)
3143 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
3145 offset_type slot
, step
;
3146 int (*cmp
) (const char *, const char *);
3148 if (current_language
->la_language
== language_cplus
3149 || current_language
->la_language
== language_fortran
3150 || current_language
->la_language
== language_d
)
3152 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3155 if (strchr (name
, '(') != NULL
)
3157 char *without_params
= cp_remove_params (name
);
3159 if (without_params
!= NULL
)
3161 make_cleanup (xfree
, without_params
);
3162 name
= without_params
;
3167 /* Index version 4 did not support case insensitive searches. But the
3168 indices for case insensitive languages are built in lowercase, therefore
3169 simulate our NAME being searched is also lowercased. */
3170 hash
= mapped_index_string_hash ((index
->version
== 4
3171 && case_sensitivity
== case_sensitive_off
3172 ? 5 : index
->version
),
3175 slot
= hash
& (index
->symbol_table_slots
- 1);
3176 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
3177 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3181 /* Convert a slot number to an offset into the table. */
3182 offset_type i
= 2 * slot
;
3184 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
3186 do_cleanups (back_to
);
3190 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
3191 if (!cmp (name
, str
))
3193 *vec_out
= (offset_type
*) (index
->constant_pool
3194 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
3195 do_cleanups (back_to
);
3199 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
3203 /* A helper function that reads the .gdb_index from SECTION and fills
3204 in MAP. FILENAME is the name of the file containing the section;
3205 it is used for error reporting. DEPRECATED_OK is nonzero if it is
3206 ok to use deprecated sections.
3208 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3209 out parameters that are filled in with information about the CU and
3210 TU lists in the section.
3212 Returns 1 if all went well, 0 otherwise. */
3215 read_index_from_section (struct objfile
*objfile
,
3216 const char *filename
,
3218 struct dwarf2_section_info
*section
,
3219 struct mapped_index
*map
,
3220 const gdb_byte
**cu_list
,
3221 offset_type
*cu_list_elements
,
3222 const gdb_byte
**types_list
,
3223 offset_type
*types_list_elements
)
3225 const gdb_byte
*addr
;
3226 offset_type version
;
3227 offset_type
*metadata
;
3230 if (dwarf2_section_empty_p (section
))
3233 /* Older elfutils strip versions could keep the section in the main
3234 executable while splitting it for the separate debug info file. */
3235 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
3238 dwarf2_read_section (objfile
, section
);
3240 addr
= section
->buffer
;
3241 /* Version check. */
3242 version
= MAYBE_SWAP (*(offset_type
*) addr
);
3243 /* Versions earlier than 3 emitted every copy of a psymbol. This
3244 causes the index to behave very poorly for certain requests. Version 3
3245 contained incomplete addrmap. So, it seems better to just ignore such
3249 static int warning_printed
= 0;
3250 if (!warning_printed
)
3252 warning (_("Skipping obsolete .gdb_index section in %s."),
3254 warning_printed
= 1;
3258 /* Index version 4 uses a different hash function than index version
3261 Versions earlier than 6 did not emit psymbols for inlined
3262 functions. Using these files will cause GDB not to be able to
3263 set breakpoints on inlined functions by name, so we ignore these
3264 indices unless the user has done
3265 "set use-deprecated-index-sections on". */
3266 if (version
< 6 && !deprecated_ok
)
3268 static int warning_printed
= 0;
3269 if (!warning_printed
)
3272 Skipping deprecated .gdb_index section in %s.\n\
3273 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3274 to use the section anyway."),
3276 warning_printed
= 1;
3280 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3281 of the TU (for symbols coming from TUs),
3282 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3283 Plus gold-generated indices can have duplicate entries for global symbols,
3284 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3285 These are just performance bugs, and we can't distinguish gdb-generated
3286 indices from gold-generated ones, so issue no warning here. */
3288 /* Indexes with higher version than the one supported by GDB may be no
3289 longer backward compatible. */
3293 map
->version
= version
;
3294 map
->total_size
= section
->size
;
3296 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3299 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3300 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3304 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3305 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3306 - MAYBE_SWAP (metadata
[i
]))
3310 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3311 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
3312 - MAYBE_SWAP (metadata
[i
]));
3315 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
3316 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
3317 - MAYBE_SWAP (metadata
[i
]))
3318 / (2 * sizeof (offset_type
)));
3321 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3327 /* Read the index file. If everything went ok, initialize the "quick"
3328 elements of all the CUs and return 1. Otherwise, return 0. */
3331 dwarf2_read_index (struct objfile
*objfile
)
3333 struct mapped_index local_map
, *map
;
3334 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3335 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3336 struct dwz_file
*dwz
;
3338 if (!read_index_from_section (objfile
, objfile_name (objfile
),
3339 use_deprecated_index_sections
,
3340 &dwarf2_per_objfile
->gdb_index
, &local_map
,
3341 &cu_list
, &cu_list_elements
,
3342 &types_list
, &types_list_elements
))
3345 /* Don't use the index if it's empty. */
3346 if (local_map
.symbol_table_slots
== 0)
3349 /* If there is a .dwz file, read it so we can get its CU list as
3351 dwz
= dwarf2_get_dwz_file ();
3354 struct mapped_index dwz_map
;
3355 const gdb_byte
*dwz_types_ignore
;
3356 offset_type dwz_types_elements_ignore
;
3358 if (!read_index_from_section (objfile
, bfd_get_filename (dwz
->dwz_bfd
),
3360 &dwz
->gdb_index
, &dwz_map
,
3361 &dwz_list
, &dwz_list_elements
,
3363 &dwz_types_elements_ignore
))
3365 warning (_("could not read '.gdb_index' section from %s; skipping"),
3366 bfd_get_filename (dwz
->dwz_bfd
));
3371 create_cus_from_index (objfile
, cu_list
, cu_list_elements
, dwz_list
,
3374 if (types_list_elements
)
3376 struct dwarf2_section_info
*section
;
3378 /* We can only handle a single .debug_types when we have an
3380 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
3383 section
= VEC_index (dwarf2_section_info_def
,
3384 dwarf2_per_objfile
->types
, 0);
3386 create_signatured_type_table_from_index (objfile
, section
, types_list
,
3387 types_list_elements
);
3390 create_addrmap_from_index (objfile
, &local_map
);
3392 map
= XOBNEW (&objfile
->objfile_obstack
, struct mapped_index
);
3395 dwarf2_per_objfile
->index_table
= map
;
3396 dwarf2_per_objfile
->using_index
= 1;
3397 dwarf2_per_objfile
->quick_file_names_table
=
3398 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3403 /* A helper for the "quick" functions which sets the global
3404 dwarf2_per_objfile according to OBJFILE. */
3407 dw2_setup (struct objfile
*objfile
)
3409 dwarf2_per_objfile
= ((struct dwarf2_per_objfile
*)
3410 objfile_data (objfile
, dwarf2_objfile_data_key
));
3411 gdb_assert (dwarf2_per_objfile
);
3414 /* die_reader_func for dw2_get_file_names. */
3417 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3418 const gdb_byte
*info_ptr
,
3419 struct die_info
*comp_unit_die
,
3423 struct dwarf2_cu
*cu
= reader
->cu
;
3424 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3425 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3426 struct dwarf2_per_cu_data
*lh_cu
;
3427 struct attribute
*attr
;
3430 struct quick_file_names
*qfn
;
3432 gdb_assert (! this_cu
->is_debug_types
);
3434 /* Our callers never want to match partial units -- instead they
3435 will match the enclosing full CU. */
3436 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3438 this_cu
->v
.quick
->no_file_data
= 1;
3446 sect_offset line_offset
{};
3448 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3451 struct quick_file_names find_entry
;
3453 line_offset
= (sect_offset
) DW_UNSND (attr
);
3455 /* We may have already read in this line header (TU line header sharing).
3456 If we have we're done. */
3457 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3458 find_entry
.hash
.line_sect_off
= line_offset
;
3459 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
3460 &find_entry
, INSERT
);
3463 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3467 lh
= dwarf_decode_line_header (line_offset
, cu
);
3471 lh_cu
->v
.quick
->no_file_data
= 1;
3475 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3476 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3477 qfn
->hash
.line_sect_off
= line_offset
;
3478 gdb_assert (slot
!= NULL
);
3481 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3483 qfn
->num_file_names
= lh
->file_names
.size ();
3485 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, lh
->file_names
.size ());
3486 for (i
= 0; i
< lh
->file_names
.size (); ++i
)
3487 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
.get (), fnd
.comp_dir
);
3488 qfn
->real_names
= NULL
;
3490 lh_cu
->v
.quick
->file_names
= qfn
;
3493 /* A helper for the "quick" functions which attempts to read the line
3494 table for THIS_CU. */
3496 static struct quick_file_names
*
3497 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3499 /* This should never be called for TUs. */
3500 gdb_assert (! this_cu
->is_debug_types
);
3501 /* Nor type unit groups. */
3502 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3504 if (this_cu
->v
.quick
->file_names
!= NULL
)
3505 return this_cu
->v
.quick
->file_names
;
3506 /* If we know there is no line data, no point in looking again. */
3507 if (this_cu
->v
.quick
->no_file_data
)
3510 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
3512 if (this_cu
->v
.quick
->no_file_data
)
3514 return this_cu
->v
.quick
->file_names
;
3517 /* A helper for the "quick" functions which computes and caches the
3518 real path for a given file name from the line table. */
3521 dw2_get_real_path (struct objfile
*objfile
,
3522 struct quick_file_names
*qfn
, int index
)
3524 if (qfn
->real_names
== NULL
)
3525 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3526 qfn
->num_file_names
, const char *);
3528 if (qfn
->real_names
[index
] == NULL
)
3529 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
3531 return qfn
->real_names
[index
];
3534 static struct symtab
*
3535 dw2_find_last_source_symtab (struct objfile
*objfile
)
3537 struct compunit_symtab
*cust
;
3540 dw2_setup (objfile
);
3541 index
= dwarf2_per_objfile
->n_comp_units
- 1;
3542 cust
= dw2_instantiate_symtab (dw2_get_cutu (index
));
3545 return compunit_primary_filetab (cust
);
3548 /* Traversal function for dw2_forget_cached_source_info. */
3551 dw2_free_cached_file_names (void **slot
, void *info
)
3553 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3555 if (file_data
->real_names
)
3559 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3561 xfree ((void*) file_data
->real_names
[i
]);
3562 file_data
->real_names
[i
] = NULL
;
3570 dw2_forget_cached_source_info (struct objfile
*objfile
)
3572 dw2_setup (objfile
);
3574 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3575 dw2_free_cached_file_names
, NULL
);
3578 /* Helper function for dw2_map_symtabs_matching_filename that expands
3579 the symtabs and calls the iterator. */
3582 dw2_map_expand_apply (struct objfile
*objfile
,
3583 struct dwarf2_per_cu_data
*per_cu
,
3584 const char *name
, const char *real_path
,
3585 gdb::function_view
<bool (symtab
*)> callback
)
3587 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3589 /* Don't visit already-expanded CUs. */
3590 if (per_cu
->v
.quick
->compunit_symtab
)
3593 /* This may expand more than one symtab, and we want to iterate over
3595 dw2_instantiate_symtab (per_cu
);
3597 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3598 last_made
, callback
);
3601 /* Implementation of the map_symtabs_matching_filename method. */
3604 dw2_map_symtabs_matching_filename
3605 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3606 gdb::function_view
<bool (symtab
*)> callback
)
3609 const char *name_basename
= lbasename (name
);
3611 dw2_setup (objfile
);
3613 /* The rule is CUs specify all the files, including those used by
3614 any TU, so there's no need to scan TUs here. */
3616 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3619 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3620 struct quick_file_names
*file_data
;
3622 /* We only need to look at symtabs not already expanded. */
3623 if (per_cu
->v
.quick
->compunit_symtab
)
3626 file_data
= dw2_get_file_names (per_cu
);
3627 if (file_data
== NULL
)
3630 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3632 const char *this_name
= file_data
->file_names
[j
];
3633 const char *this_real_name
;
3635 if (compare_filenames_for_search (this_name
, name
))
3637 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3643 /* Before we invoke realpath, which can get expensive when many
3644 files are involved, do a quick comparison of the basenames. */
3645 if (! basenames_may_differ
3646 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3649 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3650 if (compare_filenames_for_search (this_real_name
, name
))
3652 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3658 if (real_path
!= NULL
)
3660 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3661 gdb_assert (IS_ABSOLUTE_PATH (name
));
3662 if (this_real_name
!= NULL
3663 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3665 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3677 /* Struct used to manage iterating over all CUs looking for a symbol. */
3679 struct dw2_symtab_iterator
3681 /* The internalized form of .gdb_index. */
3682 struct mapped_index
*index
;
3683 /* If non-zero, only look for symbols that match BLOCK_INDEX. */
3684 int want_specific_block
;
3685 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
3686 Unused if !WANT_SPECIFIC_BLOCK. */
3688 /* The kind of symbol we're looking for. */
3690 /* The list of CUs from the index entry of the symbol,
3691 or NULL if not found. */
3693 /* The next element in VEC to look at. */
3695 /* The number of elements in VEC, or zero if there is no match. */
3697 /* Have we seen a global version of the symbol?
3698 If so we can ignore all further global instances.
3699 This is to work around gold/15646, inefficient gold-generated
3704 /* Initialize the index symtab iterator ITER.
3705 If WANT_SPECIFIC_BLOCK is non-zero, only look for symbols
3706 in block BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
3709 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3710 struct mapped_index
*index
,
3711 int want_specific_block
,
3716 iter
->index
= index
;
3717 iter
->want_specific_block
= want_specific_block
;
3718 iter
->block_index
= block_index
;
3719 iter
->domain
= domain
;
3721 iter
->global_seen
= 0;
3723 if (find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3724 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3732 /* Return the next matching CU or NULL if there are no more. */
3734 static struct dwarf2_per_cu_data
*
3735 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3737 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3739 offset_type cu_index_and_attrs
=
3740 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3741 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3742 struct dwarf2_per_cu_data
*per_cu
;
3743 int want_static
= iter
->block_index
!= GLOBAL_BLOCK
;
3744 /* This value is only valid for index versions >= 7. */
3745 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3746 gdb_index_symbol_kind symbol_kind
=
3747 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3748 /* Only check the symbol attributes if they're present.
3749 Indices prior to version 7 don't record them,
3750 and indices >= 7 may elide them for certain symbols
3751 (gold does this). */
3753 (iter
->index
->version
>= 7
3754 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3756 /* Don't crash on bad data. */
3757 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
3758 + dwarf2_per_objfile
->n_type_units
))
3760 complaint (&symfile_complaints
,
3761 _(".gdb_index entry has bad CU index"
3763 objfile_name (dwarf2_per_objfile
->objfile
));
3767 per_cu
= dw2_get_cutu (cu_index
);
3769 /* Skip if already read in. */
3770 if (per_cu
->v
.quick
->compunit_symtab
)
3773 /* Check static vs global. */
3776 if (iter
->want_specific_block
3777 && want_static
!= is_static
)
3779 /* Work around gold/15646. */
3780 if (!is_static
&& iter
->global_seen
)
3783 iter
->global_seen
= 1;
3786 /* Only check the symbol's kind if it has one. */
3789 switch (iter
->domain
)
3792 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3793 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3794 /* Some types are also in VAR_DOMAIN. */
3795 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3799 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3803 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3818 static struct compunit_symtab
*
3819 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
3820 const char *name
, domain_enum domain
)
3822 struct compunit_symtab
*stab_best
= NULL
;
3823 struct mapped_index
*index
;
3825 dw2_setup (objfile
);
3827 index
= dwarf2_per_objfile
->index_table
;
3829 /* index is NULL if OBJF_READNOW. */
3832 struct dw2_symtab_iterator iter
;
3833 struct dwarf2_per_cu_data
*per_cu
;
3835 dw2_symtab_iter_init (&iter
, index
, 1, block_index
, domain
, name
);
3837 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3839 struct symbol
*sym
, *with_opaque
= NULL
;
3840 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
);
3841 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3842 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3844 sym
= block_find_symbol (block
, name
, domain
,
3845 block_find_non_opaque_type_preferred
,
3848 /* Some caution must be observed with overloaded functions
3849 and methods, since the index will not contain any overload
3850 information (but NAME might contain it). */
3853 && strcmp_iw (SYMBOL_SEARCH_NAME (sym
), name
) == 0)
3855 if (with_opaque
!= NULL
3856 && strcmp_iw (SYMBOL_SEARCH_NAME (with_opaque
), name
) == 0)
3859 /* Keep looking through other CUs. */
3867 dw2_print_stats (struct objfile
*objfile
)
3869 int i
, total
, count
;
3871 dw2_setup (objfile
);
3872 total
= dwarf2_per_objfile
->n_comp_units
+ dwarf2_per_objfile
->n_type_units
;
3874 for (i
= 0; i
< total
; ++i
)
3876 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
3878 if (!per_cu
->v
.quick
->compunit_symtab
)
3881 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3882 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3885 /* This dumps minimal information about the index.
3886 It is called via "mt print objfiles".
3887 One use is to verify .gdb_index has been loaded by the
3888 gdb.dwarf2/gdb-index.exp testcase. */
3891 dw2_dump (struct objfile
*objfile
)
3893 dw2_setup (objfile
);
3894 gdb_assert (dwarf2_per_objfile
->using_index
);
3895 printf_filtered (".gdb_index:");
3896 if (dwarf2_per_objfile
->index_table
!= NULL
)
3898 printf_filtered (" version %d\n",
3899 dwarf2_per_objfile
->index_table
->version
);
3902 printf_filtered (" faked for \"readnow\"\n");
3903 printf_filtered ("\n");
3907 dw2_relocate (struct objfile
*objfile
,
3908 const struct section_offsets
*new_offsets
,
3909 const struct section_offsets
*delta
)
3911 /* There's nothing to relocate here. */
3915 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3916 const char *func_name
)
3918 struct mapped_index
*index
;
3920 dw2_setup (objfile
);
3922 index
= dwarf2_per_objfile
->index_table
;
3924 /* index is NULL if OBJF_READNOW. */
3927 struct dw2_symtab_iterator iter
;
3928 struct dwarf2_per_cu_data
*per_cu
;
3930 /* Note: It doesn't matter what we pass for block_index here. */
3931 dw2_symtab_iter_init (&iter
, index
, 0, GLOBAL_BLOCK
, VAR_DOMAIN
,
3934 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3935 dw2_instantiate_symtab (per_cu
);
3940 dw2_expand_all_symtabs (struct objfile
*objfile
)
3944 dw2_setup (objfile
);
3946 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3947 + dwarf2_per_objfile
->n_type_units
); ++i
)
3949 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
3951 dw2_instantiate_symtab (per_cu
);
3956 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3957 const char *fullname
)
3961 dw2_setup (objfile
);
3963 /* We don't need to consider type units here.
3964 This is only called for examining code, e.g. expand_line_sal.
3965 There can be an order of magnitude (or more) more type units
3966 than comp units, and we avoid them if we can. */
3968 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3971 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
3972 struct quick_file_names
*file_data
;
3974 /* We only need to look at symtabs not already expanded. */
3975 if (per_cu
->v
.quick
->compunit_symtab
)
3978 file_data
= dw2_get_file_names (per_cu
);
3979 if (file_data
== NULL
)
3982 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3984 const char *this_fullname
= file_data
->file_names
[j
];
3986 if (filename_cmp (this_fullname
, fullname
) == 0)
3988 dw2_instantiate_symtab (per_cu
);
3996 dw2_map_matching_symbols (struct objfile
*objfile
,
3997 const char * name
, domain_enum domain
,
3999 int (*callback
) (struct block
*,
4000 struct symbol
*, void *),
4001 void *data
, symbol_compare_ftype
*match
,
4002 symbol_compare_ftype
*ordered_compare
)
4004 /* Currently unimplemented; used for Ada. The function can be called if the
4005 current language is Ada for a non-Ada objfile using GNU index. As Ada
4006 does not look for non-Ada symbols this function should just return. */
4010 dw2_expand_symtabs_matching
4011 (struct objfile
*objfile
,
4012 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4013 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4014 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4015 enum search_domain kind
)
4019 struct mapped_index
*index
;
4021 dw2_setup (objfile
);
4023 /* index_table is NULL if OBJF_READNOW. */
4024 if (!dwarf2_per_objfile
->index_table
)
4026 index
= dwarf2_per_objfile
->index_table
;
4028 if (file_matcher
!= NULL
)
4030 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4032 NULL
, xcalloc
, xfree
));
4033 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4035 NULL
, xcalloc
, xfree
));
4037 /* The rule is CUs specify all the files, including those used by
4038 any TU, so there's no need to scan TUs here. */
4040 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4043 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
4044 struct quick_file_names
*file_data
;
4049 per_cu
->v
.quick
->mark
= 0;
4051 /* We only need to look at symtabs not already expanded. */
4052 if (per_cu
->v
.quick
->compunit_symtab
)
4055 file_data
= dw2_get_file_names (per_cu
);
4056 if (file_data
== NULL
)
4059 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4061 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4063 per_cu
->v
.quick
->mark
= 1;
4067 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
4069 const char *this_real_name
;
4071 if (file_matcher (file_data
->file_names
[j
], false))
4073 per_cu
->v
.quick
->mark
= 1;
4077 /* Before we invoke realpath, which can get expensive when many
4078 files are involved, do a quick comparison of the basenames. */
4079 if (!basenames_may_differ
4080 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4084 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4085 if (file_matcher (this_real_name
, false))
4087 per_cu
->v
.quick
->mark
= 1;
4092 slot
= htab_find_slot (per_cu
->v
.quick
->mark
4093 ? visited_found
.get ()
4094 : visited_not_found
.get (),
4100 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
4102 offset_type idx
= 2 * iter
;
4104 offset_type
*vec
, vec_len
, vec_idx
;
4105 int global_seen
= 0;
4109 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
4112 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
4114 if (!symbol_matcher (name
))
4117 /* The name was matched, now expand corresponding CUs that were
4119 vec
= (offset_type
*) (index
->constant_pool
4120 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
4121 vec_len
= MAYBE_SWAP (vec
[0]);
4122 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4124 struct dwarf2_per_cu_data
*per_cu
;
4125 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4126 /* This value is only valid for index versions >= 7. */
4127 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4128 gdb_index_symbol_kind symbol_kind
=
4129 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4130 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4131 /* Only check the symbol attributes if they're present.
4132 Indices prior to version 7 don't record them,
4133 and indices >= 7 may elide them for certain symbols
4134 (gold does this). */
4136 (index
->version
>= 7
4137 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4139 /* Work around gold/15646. */
4142 if (!is_static
&& global_seen
)
4148 /* Only check the symbol's kind if it has one. */
4153 case VARIABLES_DOMAIN
:
4154 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4157 case FUNCTIONS_DOMAIN
:
4158 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4162 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4170 /* Don't crash on bad data. */
4171 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
4172 + dwarf2_per_objfile
->n_type_units
))
4174 complaint (&symfile_complaints
,
4175 _(".gdb_index entry has bad CU index"
4176 " [in module %s]"), objfile_name (objfile
));
4180 per_cu
= dw2_get_cutu (cu_index
);
4181 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4183 int symtab_was_null
=
4184 (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4186 dw2_instantiate_symtab (per_cu
);
4188 if (expansion_notify
!= NULL
4190 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
4192 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
4199 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4202 static struct compunit_symtab
*
4203 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4208 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4209 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4212 if (cust
->includes
== NULL
)
4215 for (i
= 0; cust
->includes
[i
]; ++i
)
4217 struct compunit_symtab
*s
= cust
->includes
[i
];
4219 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4227 static struct compunit_symtab
*
4228 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4229 struct bound_minimal_symbol msymbol
,
4231 struct obj_section
*section
,
4234 struct dwarf2_per_cu_data
*data
;
4235 struct compunit_symtab
*result
;
4237 dw2_setup (objfile
);
4239 if (!objfile
->psymtabs_addrmap
)
4242 data
= (struct dwarf2_per_cu_data
*) addrmap_find (objfile
->psymtabs_addrmap
,
4247 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
4248 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4249 paddress (get_objfile_arch (objfile
), pc
));
4252 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
),
4254 gdb_assert (result
!= NULL
);
4259 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4260 void *data
, int need_fullname
)
4263 htab_up
visited (htab_create_alloc (10, htab_hash_pointer
, htab_eq_pointer
,
4264 NULL
, xcalloc
, xfree
));
4266 dw2_setup (objfile
);
4268 /* The rule is CUs specify all the files, including those used by
4269 any TU, so there's no need to scan TUs here.
4270 We can ignore file names coming from already-expanded CUs. */
4272 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4274 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
4276 if (per_cu
->v
.quick
->compunit_symtab
)
4278 void **slot
= htab_find_slot (visited
.get (),
4279 per_cu
->v
.quick
->file_names
,
4282 *slot
= per_cu
->v
.quick
->file_names
;
4286 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4289 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
4290 struct quick_file_names
*file_data
;
4293 /* We only need to look at symtabs not already expanded. */
4294 if (per_cu
->v
.quick
->compunit_symtab
)
4297 file_data
= dw2_get_file_names (per_cu
);
4298 if (file_data
== NULL
)
4301 slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4304 /* Already visited. */
4309 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
4311 const char *this_real_name
;
4314 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4316 this_real_name
= NULL
;
4317 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
4323 dw2_has_symbols (struct objfile
*objfile
)
4328 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4331 dw2_find_last_source_symtab
,
4332 dw2_forget_cached_source_info
,
4333 dw2_map_symtabs_matching_filename
,
4338 dw2_expand_symtabs_for_function
,
4339 dw2_expand_all_symtabs
,
4340 dw2_expand_symtabs_with_fullname
,
4341 dw2_map_matching_symbols
,
4342 dw2_expand_symtabs_matching
,
4343 dw2_find_pc_sect_compunit_symtab
,
4344 dw2_map_symbol_filenames
4347 /* Initialize for reading DWARF for this objfile. Return 0 if this
4348 file will use psymtabs, or 1 if using the GNU index. */
4351 dwarf2_initialize_objfile (struct objfile
*objfile
)
4353 /* If we're about to read full symbols, don't bother with the
4354 indices. In this case we also don't care if some other debug
4355 format is making psymtabs, because they are all about to be
4357 if ((objfile
->flags
& OBJF_READNOW
))
4361 dwarf2_per_objfile
->using_index
= 1;
4362 create_all_comp_units (objfile
);
4363 create_all_type_units (objfile
);
4364 dwarf2_per_objfile
->quick_file_names_table
=
4365 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
4367 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
4368 + dwarf2_per_objfile
->n_type_units
); ++i
)
4370 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
4372 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4373 struct dwarf2_per_cu_quick_data
);
4376 /* Return 1 so that gdb sees the "quick" functions. However,
4377 these functions will be no-ops because we will have expanded
4382 if (dwarf2_read_index (objfile
))
4390 /* Build a partial symbol table. */
4393 dwarf2_build_psymtabs (struct objfile
*objfile
)
4396 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
4398 init_psymbol_list (objfile
, 1024);
4403 /* This isn't really ideal: all the data we allocate on the
4404 objfile's obstack is still uselessly kept around. However,
4405 freeing it seems unsafe. */
4406 psymtab_discarder
psymtabs (objfile
);
4407 dwarf2_build_psymtabs_hard (objfile
);
4410 CATCH (except
, RETURN_MASK_ERROR
)
4412 exception_print (gdb_stderr
, except
);
4417 /* Return the total length of the CU described by HEADER. */
4420 get_cu_length (const struct comp_unit_head
*header
)
4422 return header
->initial_length_size
+ header
->length
;
4425 /* Return TRUE if SECT_OFF is within CU_HEADER. */
4428 offset_in_cu_p (const comp_unit_head
*cu_header
, sect_offset sect_off
)
4430 sect_offset bottom
= cu_header
->sect_off
;
4431 sect_offset top
= cu_header
->sect_off
+ get_cu_length (cu_header
);
4433 return sect_off
>= bottom
&& sect_off
< top
;
4436 /* Find the base address of the compilation unit for range lists and
4437 location lists. It will normally be specified by DW_AT_low_pc.
4438 In DWARF-3 draft 4, the base address could be overridden by
4439 DW_AT_entry_pc. It's been removed, but GCC still uses this for
4440 compilation units with discontinuous ranges. */
4443 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
4445 struct attribute
*attr
;
4448 cu
->base_address
= 0;
4450 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
4453 cu
->base_address
= attr_value_as_address (attr
);
4458 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
4461 cu
->base_address
= attr_value_as_address (attr
);
4467 /* Read in the comp unit header information from the debug_info at info_ptr.
4468 Use rcuh_kind::COMPILE as the default type if not known by the caller.
4469 NOTE: This leaves members offset, first_die_offset to be filled in
4472 static const gdb_byte
*
4473 read_comp_unit_head (struct comp_unit_head
*cu_header
,
4474 const gdb_byte
*info_ptr
,
4475 struct dwarf2_section_info
*section
,
4476 rcuh_kind section_kind
)
4479 unsigned int bytes_read
;
4480 const char *filename
= get_section_file_name (section
);
4481 bfd
*abfd
= get_section_bfd_owner (section
);
4483 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
4484 cu_header
->initial_length_size
= bytes_read
;
4485 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
4486 info_ptr
+= bytes_read
;
4487 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
4489 if (cu_header
->version
< 5)
4490 switch (section_kind
)
4492 case rcuh_kind::COMPILE
:
4493 cu_header
->unit_type
= DW_UT_compile
;
4495 case rcuh_kind::TYPE
:
4496 cu_header
->unit_type
= DW_UT_type
;
4499 internal_error (__FILE__
, __LINE__
,
4500 _("read_comp_unit_head: invalid section_kind"));
4504 cu_header
->unit_type
= static_cast<enum dwarf_unit_type
>
4505 (read_1_byte (abfd
, info_ptr
));
4507 switch (cu_header
->unit_type
)
4510 if (section_kind
!= rcuh_kind::COMPILE
)
4511 error (_("Dwarf Error: wrong unit_type in compilation unit header "
4512 "(is DW_UT_compile, should be DW_UT_type) [in module %s]"),
4516 section_kind
= rcuh_kind::TYPE
;
4519 error (_("Dwarf Error: wrong unit_type in compilation unit header "
4520 "(is %d, should be %d or %d) [in module %s]"),
4521 cu_header
->unit_type
, DW_UT_compile
, DW_UT_type
, filename
);
4524 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
4527 cu_header
->abbrev_sect_off
= (sect_offset
) read_offset (abfd
, info_ptr
,
4530 info_ptr
+= bytes_read
;
4531 if (cu_header
->version
< 5)
4533 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
4536 signed_addr
= bfd_get_sign_extend_vma (abfd
);
4537 if (signed_addr
< 0)
4538 internal_error (__FILE__
, __LINE__
,
4539 _("read_comp_unit_head: dwarf from non elf file"));
4540 cu_header
->signed_addr_p
= signed_addr
;
4542 if (section_kind
== rcuh_kind::TYPE
)
4544 LONGEST type_offset
;
4546 cu_header
->signature
= read_8_bytes (abfd
, info_ptr
);
4549 type_offset
= read_offset (abfd
, info_ptr
, cu_header
, &bytes_read
);
4550 info_ptr
+= bytes_read
;
4551 cu_header
->type_cu_offset_in_tu
= (cu_offset
) type_offset
;
4552 if (to_underlying (cu_header
->type_cu_offset_in_tu
) != type_offset
)
4553 error (_("Dwarf Error: Too big type_offset in compilation unit "
4554 "header (is %s) [in module %s]"), plongest (type_offset
),
4561 /* Helper function that returns the proper abbrev section for
4564 static struct dwarf2_section_info
*
4565 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
4567 struct dwarf2_section_info
*abbrev
;
4569 if (this_cu
->is_dwz
)
4570 abbrev
= &dwarf2_get_dwz_file ()->abbrev
;
4572 abbrev
= &dwarf2_per_objfile
->abbrev
;
4577 /* Subroutine of read_and_check_comp_unit_head and
4578 read_and_check_type_unit_head to simplify them.
4579 Perform various error checking on the header. */
4582 error_check_comp_unit_head (struct comp_unit_head
*header
,
4583 struct dwarf2_section_info
*section
,
4584 struct dwarf2_section_info
*abbrev_section
)
4586 const char *filename
= get_section_file_name (section
);
4588 if (header
->version
< 2 || header
->version
> 5)
4589 error (_("Dwarf Error: wrong version in compilation unit header "
4590 "(is %d, should be 2, 3, 4 or 5) [in module %s]"), header
->version
,
4593 if (to_underlying (header
->abbrev_sect_off
)
4594 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
4595 error (_("Dwarf Error: bad offset (0x%x) in compilation unit header "
4596 "(offset 0x%x + 6) [in module %s]"),
4597 to_underlying (header
->abbrev_sect_off
),
4598 to_underlying (header
->sect_off
),
4601 /* Cast to ULONGEST to use 64-bit arithmetic when possible to
4602 avoid potential 32-bit overflow. */
4603 if (((ULONGEST
) header
->sect_off
+ get_cu_length (header
))
4605 error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
4606 "(offset 0x%x + 0) [in module %s]"),
4607 header
->length
, to_underlying (header
->sect_off
),
4611 /* Read in a CU/TU header and perform some basic error checking.
4612 The contents of the header are stored in HEADER.
4613 The result is a pointer to the start of the first DIE. */
4615 static const gdb_byte
*
4616 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
4617 struct dwarf2_section_info
*section
,
4618 struct dwarf2_section_info
*abbrev_section
,
4619 const gdb_byte
*info_ptr
,
4620 rcuh_kind section_kind
)
4622 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
4623 bfd
*abfd
= get_section_bfd_owner (section
);
4625 header
->sect_off
= (sect_offset
) (beg_of_comp_unit
- section
->buffer
);
4627 info_ptr
= read_comp_unit_head (header
, info_ptr
, section
, section_kind
);
4629 header
->first_die_cu_offset
= (cu_offset
) (info_ptr
- beg_of_comp_unit
);
4631 error_check_comp_unit_head (header
, section
, abbrev_section
);
4636 /* Fetch the abbreviation table offset from a comp or type unit header. */
4639 read_abbrev_offset (struct dwarf2_section_info
*section
,
4640 sect_offset sect_off
)
4642 bfd
*abfd
= get_section_bfd_owner (section
);
4643 const gdb_byte
*info_ptr
;
4644 unsigned int initial_length_size
, offset_size
;
4647 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
4648 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
4649 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
4650 offset_size
= initial_length_size
== 4 ? 4 : 8;
4651 info_ptr
+= initial_length_size
;
4653 version
= read_2_bytes (abfd
, info_ptr
);
4657 /* Skip unit type and address size. */
4661 return (sect_offset
) read_offset_1 (abfd
, info_ptr
, offset_size
);
4664 /* Allocate a new partial symtab for file named NAME and mark this new
4665 partial symtab as being an include of PST. */
4668 dwarf2_create_include_psymtab (const char *name
, struct partial_symtab
*pst
,
4669 struct objfile
*objfile
)
4671 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
4673 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
4675 /* It shares objfile->objfile_obstack. */
4676 subpst
->dirname
= pst
->dirname
;
4679 subpst
->textlow
= 0;
4680 subpst
->texthigh
= 0;
4682 subpst
->dependencies
4683 = XOBNEW (&objfile
->objfile_obstack
, struct partial_symtab
*);
4684 subpst
->dependencies
[0] = pst
;
4685 subpst
->number_of_dependencies
= 1;
4687 subpst
->globals_offset
= 0;
4688 subpst
->n_global_syms
= 0;
4689 subpst
->statics_offset
= 0;
4690 subpst
->n_static_syms
= 0;
4691 subpst
->compunit_symtab
= NULL
;
4692 subpst
->read_symtab
= pst
->read_symtab
;
4695 /* No private part is necessary for include psymtabs. This property
4696 can be used to differentiate between such include psymtabs and
4697 the regular ones. */
4698 subpst
->read_symtab_private
= NULL
;
4701 /* Read the Line Number Program data and extract the list of files
4702 included by the source file represented by PST. Build an include
4703 partial symtab for each of these included files. */
4706 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
4707 struct die_info
*die
,
4708 struct partial_symtab
*pst
)
4711 struct attribute
*attr
;
4713 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
4715 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
4717 return; /* No linetable, so no includes. */
4719 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
4720 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
, pst
->textlow
, 1);
4724 hash_signatured_type (const void *item
)
4726 const struct signatured_type
*sig_type
4727 = (const struct signatured_type
*) item
;
4729 /* This drops the top 32 bits of the signature, but is ok for a hash. */
4730 return sig_type
->signature
;
4734 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
4736 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
4737 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
4739 return lhs
->signature
== rhs
->signature
;
4742 /* Allocate a hash table for signatured types. */
4745 allocate_signatured_type_table (struct objfile
*objfile
)
4747 return htab_create_alloc_ex (41,
4748 hash_signatured_type
,
4751 &objfile
->objfile_obstack
,
4752 hashtab_obstack_allocate
,
4753 dummy_obstack_deallocate
);
4756 /* A helper function to add a signatured type CU to a table. */
4759 add_signatured_type_cu_to_table (void **slot
, void *datum
)
4761 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
4762 struct signatured_type
***datap
= (struct signatured_type
***) datum
;
4770 /* A helper for create_debug_types_hash_table. Read types from SECTION
4771 and fill them into TYPES_HTAB. It will process only type units,
4772 therefore DW_UT_type. */
4775 create_debug_type_hash_table (struct dwo_file
*dwo_file
,
4776 dwarf2_section_info
*section
, htab_t
&types_htab
,
4777 rcuh_kind section_kind
)
4779 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4780 struct dwarf2_section_info
*abbrev_section
;
4782 const gdb_byte
*info_ptr
, *end_ptr
;
4784 abbrev_section
= (dwo_file
!= NULL
4785 ? &dwo_file
->sections
.abbrev
4786 : &dwarf2_per_objfile
->abbrev
);
4788 if (dwarf_read_debug
)
4789 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
4790 get_section_name (section
),
4791 get_section_file_name (abbrev_section
));
4793 dwarf2_read_section (objfile
, section
);
4794 info_ptr
= section
->buffer
;
4796 if (info_ptr
== NULL
)
4799 /* We can't set abfd until now because the section may be empty or
4800 not present, in which case the bfd is unknown. */
4801 abfd
= get_section_bfd_owner (section
);
4803 /* We don't use init_cutu_and_read_dies_simple, or some such, here
4804 because we don't need to read any dies: the signature is in the
4807 end_ptr
= info_ptr
+ section
->size
;
4808 while (info_ptr
< end_ptr
)
4810 struct signatured_type
*sig_type
;
4811 struct dwo_unit
*dwo_tu
;
4813 const gdb_byte
*ptr
= info_ptr
;
4814 struct comp_unit_head header
;
4815 unsigned int length
;
4817 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
4819 /* Initialize it due to a false compiler warning. */
4820 header
.signature
= -1;
4821 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
4823 /* We need to read the type's signature in order to build the hash
4824 table, but we don't need anything else just yet. */
4826 ptr
= read_and_check_comp_unit_head (&header
, section
,
4827 abbrev_section
, ptr
, section_kind
);
4829 length
= get_cu_length (&header
);
4831 /* Skip dummy type units. */
4832 if (ptr
>= info_ptr
+ length
4833 || peek_abbrev_code (abfd
, ptr
) == 0
4834 || header
.unit_type
!= DW_UT_type
)
4840 if (types_htab
== NULL
)
4843 types_htab
= allocate_dwo_unit_table (objfile
);
4845 types_htab
= allocate_signatured_type_table (objfile
);
4851 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4853 dwo_tu
->dwo_file
= dwo_file
;
4854 dwo_tu
->signature
= header
.signature
;
4855 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
4856 dwo_tu
->section
= section
;
4857 dwo_tu
->sect_off
= sect_off
;
4858 dwo_tu
->length
= length
;
4862 /* N.B.: type_offset is not usable if this type uses a DWO file.
4863 The real type_offset is in the DWO file. */
4865 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4866 struct signatured_type
);
4867 sig_type
->signature
= header
.signature
;
4868 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
4869 sig_type
->per_cu
.objfile
= objfile
;
4870 sig_type
->per_cu
.is_debug_types
= 1;
4871 sig_type
->per_cu
.section
= section
;
4872 sig_type
->per_cu
.sect_off
= sect_off
;
4873 sig_type
->per_cu
.length
= length
;
4876 slot
= htab_find_slot (types_htab
,
4877 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
4879 gdb_assert (slot
!= NULL
);
4882 sect_offset dup_sect_off
;
4886 const struct dwo_unit
*dup_tu
4887 = (const struct dwo_unit
*) *slot
;
4889 dup_sect_off
= dup_tu
->sect_off
;
4893 const struct signatured_type
*dup_tu
4894 = (const struct signatured_type
*) *slot
;
4896 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
4899 complaint (&symfile_complaints
,
4900 _("debug type entry at offset 0x%x is duplicate to"
4901 " the entry at offset 0x%x, signature %s"),
4902 to_underlying (sect_off
), to_underlying (dup_sect_off
),
4903 hex_string (header
.signature
));
4905 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
4907 if (dwarf_read_debug
> 1)
4908 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature %s\n",
4909 to_underlying (sect_off
),
4910 hex_string (header
.signature
));
4916 /* Create the hash table of all entries in the .debug_types
4917 (or .debug_types.dwo) section(s).
4918 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
4919 otherwise it is NULL.
4921 The result is a pointer to the hash table or NULL if there are no types.
4923 Note: This function processes DWO files only, not DWP files. */
4926 create_debug_types_hash_table (struct dwo_file
*dwo_file
,
4927 VEC (dwarf2_section_info_def
) *types
,
4931 struct dwarf2_section_info
*section
;
4933 if (VEC_empty (dwarf2_section_info_def
, types
))
4937 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
4939 create_debug_type_hash_table (dwo_file
, section
, types_htab
,
4943 /* Create the hash table of all entries in the .debug_types section,
4944 and initialize all_type_units.
4945 The result is zero if there is an error (e.g. missing .debug_types section),
4946 otherwise non-zero. */
4949 create_all_type_units (struct objfile
*objfile
)
4951 htab_t types_htab
= NULL
;
4952 struct signatured_type
**iter
;
4954 create_debug_type_hash_table (NULL
, &dwarf2_per_objfile
->info
, types_htab
,
4955 rcuh_kind::COMPILE
);
4956 create_debug_types_hash_table (NULL
, dwarf2_per_objfile
->types
, types_htab
);
4957 if (types_htab
== NULL
)
4959 dwarf2_per_objfile
->signatured_types
= NULL
;
4963 dwarf2_per_objfile
->signatured_types
= types_htab
;
4965 dwarf2_per_objfile
->n_type_units
4966 = dwarf2_per_objfile
->n_allocated_type_units
4967 = htab_elements (types_htab
);
4968 dwarf2_per_objfile
->all_type_units
=
4969 XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
4970 iter
= &dwarf2_per_objfile
->all_type_units
[0];
4971 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
4972 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
4973 == dwarf2_per_objfile
->n_type_units
);
4978 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
4979 If SLOT is non-NULL, it is the entry to use in the hash table.
4980 Otherwise we find one. */
4982 static struct signatured_type
*
4983 add_type_unit (ULONGEST sig
, void **slot
)
4985 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4986 int n_type_units
= dwarf2_per_objfile
->n_type_units
;
4987 struct signatured_type
*sig_type
;
4989 gdb_assert (n_type_units
<= dwarf2_per_objfile
->n_allocated_type_units
);
4991 if (n_type_units
> dwarf2_per_objfile
->n_allocated_type_units
)
4993 if (dwarf2_per_objfile
->n_allocated_type_units
== 0)
4994 dwarf2_per_objfile
->n_allocated_type_units
= 1;
4995 dwarf2_per_objfile
->n_allocated_type_units
*= 2;
4996 dwarf2_per_objfile
->all_type_units
4997 = XRESIZEVEC (struct signatured_type
*,
4998 dwarf2_per_objfile
->all_type_units
,
4999 dwarf2_per_objfile
->n_allocated_type_units
);
5000 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
5002 dwarf2_per_objfile
->n_type_units
= n_type_units
;
5004 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5005 struct signatured_type
);
5006 dwarf2_per_objfile
->all_type_units
[n_type_units
- 1] = sig_type
;
5007 sig_type
->signature
= sig
;
5008 sig_type
->per_cu
.is_debug_types
= 1;
5009 if (dwarf2_per_objfile
->using_index
)
5011 sig_type
->per_cu
.v
.quick
=
5012 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5013 struct dwarf2_per_cu_quick_data
);
5018 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
5021 gdb_assert (*slot
== NULL
);
5023 /* The rest of sig_type must be filled in by the caller. */
5027 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
5028 Fill in SIG_ENTRY with DWO_ENTRY. */
5031 fill_in_sig_entry_from_dwo_entry (struct objfile
*objfile
,
5032 struct signatured_type
*sig_entry
,
5033 struct dwo_unit
*dwo_entry
)
5035 /* Make sure we're not clobbering something we don't expect to. */
5036 gdb_assert (! sig_entry
->per_cu
.queued
);
5037 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
5038 if (dwarf2_per_objfile
->using_index
)
5040 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
5041 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
5044 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
5045 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
5046 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
5047 gdb_assert (sig_entry
->type_unit_group
== NULL
);
5048 gdb_assert (sig_entry
->dwo_unit
== NULL
);
5050 sig_entry
->per_cu
.section
= dwo_entry
->section
;
5051 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
5052 sig_entry
->per_cu
.length
= dwo_entry
->length
;
5053 sig_entry
->per_cu
.reading_dwo_directly
= 1;
5054 sig_entry
->per_cu
.objfile
= objfile
;
5055 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
5056 sig_entry
->dwo_unit
= dwo_entry
;
5059 /* Subroutine of lookup_signatured_type.
5060 If we haven't read the TU yet, create the signatured_type data structure
5061 for a TU to be read in directly from a DWO file, bypassing the stub.
5062 This is the "Stay in DWO Optimization": When there is no DWP file and we're
5063 using .gdb_index, then when reading a CU we want to stay in the DWO file
5064 containing that CU. Otherwise we could end up reading several other DWO
5065 files (due to comdat folding) to process the transitive closure of all the
5066 mentioned TUs, and that can be slow. The current DWO file will have every
5067 type signature that it needs.
5068 We only do this for .gdb_index because in the psymtab case we already have
5069 to read all the DWOs to build the type unit groups. */
5071 static struct signatured_type
*
5072 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
5074 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5075 struct dwo_file
*dwo_file
;
5076 struct dwo_unit find_dwo_entry
, *dwo_entry
;
5077 struct signatured_type find_sig_entry
, *sig_entry
;
5080 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
5082 /* If TU skeletons have been removed then we may not have read in any
5084 if (dwarf2_per_objfile
->signatured_types
== NULL
)
5086 dwarf2_per_objfile
->signatured_types
5087 = allocate_signatured_type_table (objfile
);
5090 /* We only ever need to read in one copy of a signatured type.
5091 Use the global signatured_types array to do our own comdat-folding
5092 of types. If this is the first time we're reading this TU, and
5093 the TU has an entry in .gdb_index, replace the recorded data from
5094 .gdb_index with this TU. */
5096 find_sig_entry
.signature
= sig
;
5097 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
5098 &find_sig_entry
, INSERT
);
5099 sig_entry
= (struct signatured_type
*) *slot
;
5101 /* We can get here with the TU already read, *or* in the process of being
5102 read. Don't reassign the global entry to point to this DWO if that's
5103 the case. Also note that if the TU is already being read, it may not
5104 have come from a DWO, the program may be a mix of Fission-compiled
5105 code and non-Fission-compiled code. */
5107 /* Have we already tried to read this TU?
5108 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
5109 needn't exist in the global table yet). */
5110 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
5113 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
5114 dwo_unit of the TU itself. */
5115 dwo_file
= cu
->dwo_unit
->dwo_file
;
5117 /* Ok, this is the first time we're reading this TU. */
5118 if (dwo_file
->tus
== NULL
)
5120 find_dwo_entry
.signature
= sig
;
5121 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_entry
);
5122 if (dwo_entry
== NULL
)
5125 /* If the global table doesn't have an entry for this TU, add one. */
5126 if (sig_entry
== NULL
)
5127 sig_entry
= add_type_unit (sig
, slot
);
5129 fill_in_sig_entry_from_dwo_entry (objfile
, sig_entry
, dwo_entry
);
5130 sig_entry
->per_cu
.tu_read
= 1;
5134 /* Subroutine of lookup_signatured_type.
5135 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
5136 then try the DWP file. If the TU stub (skeleton) has been removed then
5137 it won't be in .gdb_index. */
5139 static struct signatured_type
*
5140 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
5142 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5143 struct dwp_file
*dwp_file
= get_dwp_file ();
5144 struct dwo_unit
*dwo_entry
;
5145 struct signatured_type find_sig_entry
, *sig_entry
;
5148 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
5149 gdb_assert (dwp_file
!= NULL
);
5151 /* If TU skeletons have been removed then we may not have read in any
5153 if (dwarf2_per_objfile
->signatured_types
== NULL
)
5155 dwarf2_per_objfile
->signatured_types
5156 = allocate_signatured_type_table (objfile
);
5159 find_sig_entry
.signature
= sig
;
5160 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
5161 &find_sig_entry
, INSERT
);
5162 sig_entry
= (struct signatured_type
*) *slot
;
5164 /* Have we already tried to read this TU?
5165 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
5166 needn't exist in the global table yet). */
5167 if (sig_entry
!= NULL
)
5170 if (dwp_file
->tus
== NULL
)
5172 dwo_entry
= lookup_dwo_unit_in_dwp (dwp_file
, NULL
,
5173 sig
, 1 /* is_debug_types */);
5174 if (dwo_entry
== NULL
)
5177 sig_entry
= add_type_unit (sig
, slot
);
5178 fill_in_sig_entry_from_dwo_entry (objfile
, sig_entry
, dwo_entry
);
5183 /* Lookup a signature based type for DW_FORM_ref_sig8.
5184 Returns NULL if signature SIG is not present in the table.
5185 It is up to the caller to complain about this. */
5187 static struct signatured_type
*
5188 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
5191 && dwarf2_per_objfile
->using_index
)
5193 /* We're in a DWO/DWP file, and we're using .gdb_index.
5194 These cases require special processing. */
5195 if (get_dwp_file () == NULL
)
5196 return lookup_dwo_signatured_type (cu
, sig
);
5198 return lookup_dwp_signatured_type (cu
, sig
);
5202 struct signatured_type find_entry
, *entry
;
5204 if (dwarf2_per_objfile
->signatured_types
== NULL
)
5206 find_entry
.signature
= sig
;
5207 entry
= ((struct signatured_type
*)
5208 htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
));
5213 /* Low level DIE reading support. */
5215 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
5218 init_cu_die_reader (struct die_reader_specs
*reader
,
5219 struct dwarf2_cu
*cu
,
5220 struct dwarf2_section_info
*section
,
5221 struct dwo_file
*dwo_file
)
5223 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
5224 reader
->abfd
= get_section_bfd_owner (section
);
5226 reader
->dwo_file
= dwo_file
;
5227 reader
->die_section
= section
;
5228 reader
->buffer
= section
->buffer
;
5229 reader
->buffer_end
= section
->buffer
+ section
->size
;
5230 reader
->comp_dir
= NULL
;
5233 /* Subroutine of init_cutu_and_read_dies to simplify it.
5234 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
5235 There's just a lot of work to do, and init_cutu_and_read_dies is big enough
5238 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
5239 from it to the DIE in the DWO. If NULL we are skipping the stub.
5240 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
5241 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
5242 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
5243 STUB_COMP_DIR may be non-NULL.
5244 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
5245 are filled in with the info of the DIE from the DWO file.
5246 ABBREV_TABLE_PROVIDED is non-zero if the caller of init_cutu_and_read_dies
5247 provided an abbrev table to use.
5248 The result is non-zero if a valid (non-dummy) DIE was found. */
5251 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
5252 struct dwo_unit
*dwo_unit
,
5253 int abbrev_table_provided
,
5254 struct die_info
*stub_comp_unit_die
,
5255 const char *stub_comp_dir
,
5256 struct die_reader_specs
*result_reader
,
5257 const gdb_byte
**result_info_ptr
,
5258 struct die_info
**result_comp_unit_die
,
5259 int *result_has_children
)
5261 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5262 struct dwarf2_cu
*cu
= this_cu
->cu
;
5263 struct dwarf2_section_info
*section
;
5265 const gdb_byte
*begin_info_ptr
, *info_ptr
;
5266 ULONGEST signature
; /* Or dwo_id. */
5267 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
5268 int i
,num_extra_attrs
;
5269 struct dwarf2_section_info
*dwo_abbrev_section
;
5270 struct attribute
*attr
;
5271 struct die_info
*comp_unit_die
;
5273 /* At most one of these may be provided. */
5274 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
5276 /* These attributes aren't processed until later:
5277 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
5278 DW_AT_comp_dir is used now, to find the DWO file, but it is also
5279 referenced later. However, these attributes are found in the stub
5280 which we won't have later. In order to not impose this complication
5281 on the rest of the code, we read them here and copy them to the
5290 if (stub_comp_unit_die
!= NULL
)
5292 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
5294 if (! this_cu
->is_debug_types
)
5295 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
5296 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
5297 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
5298 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
5299 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
5301 /* There should be a DW_AT_addr_base attribute here (if needed).
5302 We need the value before we can process DW_FORM_GNU_addr_index. */
5304 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
5306 cu
->addr_base
= DW_UNSND (attr
);
5308 /* There should be a DW_AT_ranges_base attribute here (if needed).
5309 We need the value before we can process DW_AT_ranges. */
5310 cu
->ranges_base
= 0;
5311 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
5313 cu
->ranges_base
= DW_UNSND (attr
);
5315 else if (stub_comp_dir
!= NULL
)
5317 /* Reconstruct the comp_dir attribute to simplify the code below. */
5318 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
5319 comp_dir
->name
= DW_AT_comp_dir
;
5320 comp_dir
->form
= DW_FORM_string
;
5321 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
5322 DW_STRING (comp_dir
) = stub_comp_dir
;
5325 /* Set up for reading the DWO CU/TU. */
5326 cu
->dwo_unit
= dwo_unit
;
5327 section
= dwo_unit
->section
;
5328 dwarf2_read_section (objfile
, section
);
5329 abfd
= get_section_bfd_owner (section
);
5330 begin_info_ptr
= info_ptr
= (section
->buffer
5331 + to_underlying (dwo_unit
->sect_off
));
5332 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
5333 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
);
5335 if (this_cu
->is_debug_types
)
5337 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
5339 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
5341 info_ptr
, rcuh_kind::TYPE
);
5342 /* This is not an assert because it can be caused by bad debug info. */
5343 if (sig_type
->signature
!= cu
->header
.signature
)
5345 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
5346 " TU at offset 0x%x [in module %s]"),
5347 hex_string (sig_type
->signature
),
5348 hex_string (cu
->header
.signature
),
5349 to_underlying (dwo_unit
->sect_off
),
5350 bfd_get_filename (abfd
));
5352 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
5353 /* For DWOs coming from DWP files, we don't know the CU length
5354 nor the type's offset in the TU until now. */
5355 dwo_unit
->length
= get_cu_length (&cu
->header
);
5356 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
5358 /* Establish the type offset that can be used to lookup the type.
5359 For DWO files, we don't know it until now. */
5360 sig_type
->type_offset_in_section
5361 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
5365 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
5367 info_ptr
, rcuh_kind::COMPILE
);
5368 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
5369 /* For DWOs coming from DWP files, we don't know the CU length
5371 dwo_unit
->length
= get_cu_length (&cu
->header
);
5374 /* Replace the CU's original abbrev table with the DWO's.
5375 Reminder: We can't read the abbrev table until we've read the header. */
5376 if (abbrev_table_provided
)
5378 /* Don't free the provided abbrev table, the caller of
5379 init_cutu_and_read_dies owns it. */
5380 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
5381 /* Ensure the DWO abbrev table gets freed. */
5382 make_cleanup (dwarf2_free_abbrev_table
, cu
);
5386 dwarf2_free_abbrev_table (cu
);
5387 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
5388 /* Leave any existing abbrev table cleanup as is. */
5391 /* Read in the die, but leave space to copy over the attributes
5392 from the stub. This has the benefit of simplifying the rest of
5393 the code - all the work to maintain the illusion of a single
5394 DW_TAG_{compile,type}_unit DIE is done here. */
5395 num_extra_attrs
= ((stmt_list
!= NULL
)
5399 + (comp_dir
!= NULL
));
5400 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
5401 result_has_children
, num_extra_attrs
);
5403 /* Copy over the attributes from the stub to the DIE we just read in. */
5404 comp_unit_die
= *result_comp_unit_die
;
5405 i
= comp_unit_die
->num_attrs
;
5406 if (stmt_list
!= NULL
)
5407 comp_unit_die
->attrs
[i
++] = *stmt_list
;
5409 comp_unit_die
->attrs
[i
++] = *low_pc
;
5410 if (high_pc
!= NULL
)
5411 comp_unit_die
->attrs
[i
++] = *high_pc
;
5413 comp_unit_die
->attrs
[i
++] = *ranges
;
5414 if (comp_dir
!= NULL
)
5415 comp_unit_die
->attrs
[i
++] = *comp_dir
;
5416 comp_unit_die
->num_attrs
+= num_extra_attrs
;
5418 if (dwarf_die_debug
)
5420 fprintf_unfiltered (gdb_stdlog
,
5421 "Read die from %s@0x%x of %s:\n",
5422 get_section_name (section
),
5423 (unsigned) (begin_info_ptr
- section
->buffer
),
5424 bfd_get_filename (abfd
));
5425 dump_die (comp_unit_die
, dwarf_die_debug
);
5428 /* Save the comp_dir attribute. If there is no DWP file then we'll read
5429 TUs by skipping the stub and going directly to the entry in the DWO file.
5430 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
5431 to get it via circuitous means. Blech. */
5432 if (comp_dir
!= NULL
)
5433 result_reader
->comp_dir
= DW_STRING (comp_dir
);
5435 /* Skip dummy compilation units. */
5436 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
5437 || peek_abbrev_code (abfd
, info_ptr
) == 0)
5440 *result_info_ptr
= info_ptr
;
5444 /* Subroutine of init_cutu_and_read_dies to simplify it.
5445 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
5446 Returns NULL if the specified DWO unit cannot be found. */
5448 static struct dwo_unit
*
5449 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
5450 struct die_info
*comp_unit_die
)
5452 struct dwarf2_cu
*cu
= this_cu
->cu
;
5453 struct attribute
*attr
;
5455 struct dwo_unit
*dwo_unit
;
5456 const char *comp_dir
, *dwo_name
;
5458 gdb_assert (cu
!= NULL
);
5460 /* Yeah, we look dwo_name up again, but it simplifies the code. */
5461 dwo_name
= dwarf2_string_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
5462 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
5464 if (this_cu
->is_debug_types
)
5466 struct signatured_type
*sig_type
;
5468 /* Since this_cu is the first member of struct signatured_type,
5469 we can go from a pointer to one to a pointer to the other. */
5470 sig_type
= (struct signatured_type
*) this_cu
;
5471 signature
= sig_type
->signature
;
5472 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
5476 struct attribute
*attr
;
5478 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
5480 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
5482 dwo_name
, objfile_name (this_cu
->objfile
));
5483 signature
= DW_UNSND (attr
);
5484 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
5491 /* Subroutine of init_cutu_and_read_dies to simplify it.
5492 See it for a description of the parameters.
5493 Read a TU directly from a DWO file, bypassing the stub.
5495 Note: This function could be a little bit simpler if we shared cleanups
5496 with our caller, init_cutu_and_read_dies. That's generally a fragile thing
5497 to do, so we keep this function self-contained. Or we could move this
5498 into our caller, but it's complex enough already. */
5501 init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
5502 int use_existing_cu
, int keep
,
5503 die_reader_func_ftype
*die_reader_func
,
5506 struct dwarf2_cu
*cu
;
5507 struct signatured_type
*sig_type
;
5508 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
5509 struct die_reader_specs reader
;
5510 const gdb_byte
*info_ptr
;
5511 struct die_info
*comp_unit_die
;
5514 /* Verify we can do the following downcast, and that we have the
5516 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
5517 sig_type
= (struct signatured_type
*) this_cu
;
5518 gdb_assert (sig_type
->dwo_unit
!= NULL
);
5520 cleanups
= make_cleanup (null_cleanup
, NULL
);
5522 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
5524 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
5526 /* There's no need to do the rereading_dwo_cu handling that
5527 init_cutu_and_read_dies does since we don't read the stub. */
5531 /* If !use_existing_cu, this_cu->cu must be NULL. */
5532 gdb_assert (this_cu
->cu
== NULL
);
5533 cu
= XNEW (struct dwarf2_cu
);
5534 init_one_comp_unit (cu
, this_cu
);
5535 /* If an error occurs while loading, release our storage. */
5536 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
5539 /* A future optimization, if needed, would be to use an existing
5540 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
5541 could share abbrev tables. */
5543 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
5544 0 /* abbrev_table_provided */,
5545 NULL
/* stub_comp_unit_die */,
5546 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
5548 &comp_unit_die
, &has_children
) == 0)
5551 do_cleanups (cleanups
);
5555 /* All the "real" work is done here. */
5556 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
5558 /* This duplicates the code in init_cutu_and_read_dies,
5559 but the alternative is making the latter more complex.
5560 This function is only for the special case of using DWO files directly:
5561 no point in overly complicating the general case just to handle this. */
5562 if (free_cu_cleanup
!= NULL
)
5566 /* We've successfully allocated this compilation unit. Let our
5567 caller clean it up when finished with it. */
5568 discard_cleanups (free_cu_cleanup
);
5570 /* We can only discard free_cu_cleanup and all subsequent cleanups.
5571 So we have to manually free the abbrev table. */
5572 dwarf2_free_abbrev_table (cu
);
5574 /* Link this CU into read_in_chain. */
5575 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
5576 dwarf2_per_objfile
->read_in_chain
= this_cu
;
5579 do_cleanups (free_cu_cleanup
);
5582 do_cleanups (cleanups
);
5585 /* Initialize a CU (or TU) and read its DIEs.
5586 If the CU defers to a DWO file, read the DWO file as well.
5588 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
5589 Otherwise the table specified in the comp unit header is read in and used.
5590 This is an optimization for when we already have the abbrev table.
5592 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
5593 Otherwise, a new CU is allocated with xmalloc.
5595 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
5596 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
5598 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
5599 linker) then DIE_READER_FUNC will not get called. */
5602 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
5603 struct abbrev_table
*abbrev_table
,
5604 int use_existing_cu
, int keep
,
5605 die_reader_func_ftype
*die_reader_func
,
5608 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5609 struct dwarf2_section_info
*section
= this_cu
->section
;
5610 bfd
*abfd
= get_section_bfd_owner (section
);
5611 struct dwarf2_cu
*cu
;
5612 const gdb_byte
*begin_info_ptr
, *info_ptr
;
5613 struct die_reader_specs reader
;
5614 struct die_info
*comp_unit_die
;
5616 struct attribute
*attr
;
5617 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
5618 struct signatured_type
*sig_type
= NULL
;
5619 struct dwarf2_section_info
*abbrev_section
;
5620 /* Non-zero if CU currently points to a DWO file and we need to
5621 reread it. When this happens we need to reread the skeleton die
5622 before we can reread the DWO file (this only applies to CUs, not TUs). */
5623 int rereading_dwo_cu
= 0;
5625 if (dwarf_die_debug
)
5626 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
5627 this_cu
->is_debug_types
? "type" : "comp",
5628 to_underlying (this_cu
->sect_off
));
5630 if (use_existing_cu
)
5633 /* If we're reading a TU directly from a DWO file, including a virtual DWO
5634 file (instead of going through the stub), short-circuit all of this. */
5635 if (this_cu
->reading_dwo_directly
)
5637 /* Narrow down the scope of possibilities to have to understand. */
5638 gdb_assert (this_cu
->is_debug_types
);
5639 gdb_assert (abbrev_table
== NULL
);
5640 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
,
5641 die_reader_func
, data
);
5645 cleanups
= make_cleanup (null_cleanup
, NULL
);
5647 /* This is cheap if the section is already read in. */
5648 dwarf2_read_section (objfile
, section
);
5650 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
5652 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
5654 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
5657 /* If this CU is from a DWO file we need to start over, we need to
5658 refetch the attributes from the skeleton CU.
5659 This could be optimized by retrieving those attributes from when we
5660 were here the first time: the previous comp_unit_die was stored in
5661 comp_unit_obstack. But there's no data yet that we need this
5663 if (cu
->dwo_unit
!= NULL
)
5664 rereading_dwo_cu
= 1;
5668 /* If !use_existing_cu, this_cu->cu must be NULL. */
5669 gdb_assert (this_cu
->cu
== NULL
);
5670 cu
= XNEW (struct dwarf2_cu
);
5671 init_one_comp_unit (cu
, this_cu
);
5672 /* If an error occurs while loading, release our storage. */
5673 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
5676 /* Get the header. */
5677 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
5679 /* We already have the header, there's no need to read it in again. */
5680 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
5684 if (this_cu
->is_debug_types
)
5686 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
5687 abbrev_section
, info_ptr
,
5690 /* Since per_cu is the first member of struct signatured_type,
5691 we can go from a pointer to one to a pointer to the other. */
5692 sig_type
= (struct signatured_type
*) this_cu
;
5693 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
5694 gdb_assert (sig_type
->type_offset_in_tu
5695 == cu
->header
.type_cu_offset_in_tu
);
5696 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
5698 /* LENGTH has not been set yet for type units if we're
5699 using .gdb_index. */
5700 this_cu
->length
= get_cu_length (&cu
->header
);
5702 /* Establish the type offset that can be used to lookup the type. */
5703 sig_type
->type_offset_in_section
=
5704 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
5706 this_cu
->dwarf_version
= cu
->header
.version
;
5710 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
5713 rcuh_kind::COMPILE
);
5715 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
5716 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
5717 this_cu
->dwarf_version
= cu
->header
.version
;
5721 /* Skip dummy compilation units. */
5722 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
5723 || peek_abbrev_code (abfd
, info_ptr
) == 0)
5725 do_cleanups (cleanups
);
5729 /* If we don't have them yet, read the abbrevs for this compilation unit.
5730 And if we need to read them now, make sure they're freed when we're
5731 done. Note that it's important that if the CU had an abbrev table
5732 on entry we don't free it when we're done: Somewhere up the call stack
5733 it may be in use. */
5734 if (abbrev_table
!= NULL
)
5736 gdb_assert (cu
->abbrev_table
== NULL
);
5737 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
5738 cu
->abbrev_table
= abbrev_table
;
5740 else if (cu
->abbrev_table
== NULL
)
5742 dwarf2_read_abbrevs (cu
, abbrev_section
);
5743 make_cleanup (dwarf2_free_abbrev_table
, cu
);
5745 else if (rereading_dwo_cu
)
5747 dwarf2_free_abbrev_table (cu
);
5748 dwarf2_read_abbrevs (cu
, abbrev_section
);
5751 /* Read the top level CU/TU die. */
5752 init_cu_die_reader (&reader
, cu
, section
, NULL
);
5753 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
5755 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
5757 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
5758 DWO CU, that this test will fail (the attribute will not be present). */
5759 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
5762 struct dwo_unit
*dwo_unit
;
5763 struct die_info
*dwo_comp_unit_die
;
5767 complaint (&symfile_complaints
,
5768 _("compilation unit with DW_AT_GNU_dwo_name"
5769 " has children (offset 0x%x) [in module %s]"),
5770 to_underlying (this_cu
->sect_off
), bfd_get_filename (abfd
));
5772 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
);
5773 if (dwo_unit
!= NULL
)
5775 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
5776 abbrev_table
!= NULL
,
5777 comp_unit_die
, NULL
,
5779 &dwo_comp_unit_die
, &has_children
) == 0)
5782 do_cleanups (cleanups
);
5785 comp_unit_die
= dwo_comp_unit_die
;
5789 /* Yikes, we couldn't find the rest of the DIE, we only have
5790 the stub. A complaint has already been logged. There's
5791 not much more we can do except pass on the stub DIE to
5792 die_reader_func. We don't want to throw an error on bad
5797 /* All of the above is setup for this call. Yikes. */
5798 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
5800 /* Done, clean up. */
5801 if (free_cu_cleanup
!= NULL
)
5805 /* We've successfully allocated this compilation unit. Let our
5806 caller clean it up when finished with it. */
5807 discard_cleanups (free_cu_cleanup
);
5809 /* We can only discard free_cu_cleanup and all subsequent cleanups.
5810 So we have to manually free the abbrev table. */
5811 dwarf2_free_abbrev_table (cu
);
5813 /* Link this CU into read_in_chain. */
5814 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
5815 dwarf2_per_objfile
->read_in_chain
= this_cu
;
5818 do_cleanups (free_cu_cleanup
);
5821 do_cleanups (cleanups
);
5824 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name if present.
5825 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed
5826 to have already done the lookup to find the DWO file).
5828 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
5829 THIS_CU->is_debug_types, but nothing else.
5831 We fill in THIS_CU->length.
5833 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
5834 linker) then DIE_READER_FUNC will not get called.
5836 THIS_CU->cu is always freed when done.
5837 This is done in order to not leave THIS_CU->cu in a state where we have
5838 to care whether it refers to the "main" CU or the DWO CU. */
5841 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
5842 struct dwo_file
*dwo_file
,
5843 die_reader_func_ftype
*die_reader_func
,
5846 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5847 struct dwarf2_section_info
*section
= this_cu
->section
;
5848 bfd
*abfd
= get_section_bfd_owner (section
);
5849 struct dwarf2_section_info
*abbrev_section
;
5850 struct dwarf2_cu cu
;
5851 const gdb_byte
*begin_info_ptr
, *info_ptr
;
5852 struct die_reader_specs reader
;
5853 struct cleanup
*cleanups
;
5854 struct die_info
*comp_unit_die
;
5857 if (dwarf_die_debug
)
5858 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
5859 this_cu
->is_debug_types
? "type" : "comp",
5860 to_underlying (this_cu
->sect_off
));
5862 gdb_assert (this_cu
->cu
== NULL
);
5864 abbrev_section
= (dwo_file
!= NULL
5865 ? &dwo_file
->sections
.abbrev
5866 : get_abbrev_section_for_cu (this_cu
));
5868 /* This is cheap if the section is already read in. */
5869 dwarf2_read_section (objfile
, section
);
5871 init_one_comp_unit (&cu
, this_cu
);
5873 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
5875 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
5876 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
,
5877 abbrev_section
, info_ptr
,
5878 (this_cu
->is_debug_types
5880 : rcuh_kind::COMPILE
));
5882 this_cu
->length
= get_cu_length (&cu
.header
);
5884 /* Skip dummy compilation units. */
5885 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
5886 || peek_abbrev_code (abfd
, info_ptr
) == 0)
5888 do_cleanups (cleanups
);
5892 dwarf2_read_abbrevs (&cu
, abbrev_section
);
5893 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
5895 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
);
5896 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
5898 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
5900 do_cleanups (cleanups
);
5903 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
5904 does not lookup the specified DWO file.
5905 This cannot be used to read DWO files.
5907 THIS_CU->cu is always freed when done.
5908 This is done in order to not leave THIS_CU->cu in a state where we have
5909 to care whether it refers to the "main" CU or the DWO CU.
5910 We can revisit this if the data shows there's a performance issue. */
5913 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
5914 die_reader_func_ftype
*die_reader_func
,
5917 init_cutu_and_read_dies_no_follow (this_cu
, NULL
, die_reader_func
, data
);
5920 /* Type Unit Groups.
5922 Type Unit Groups are a way to collapse the set of all TUs (type units) into
5923 a more manageable set. The grouping is done by DW_AT_stmt_list entry
5924 so that all types coming from the same compilation (.o file) are grouped
5925 together. A future step could be to put the types in the same symtab as
5926 the CU the types ultimately came from. */
5929 hash_type_unit_group (const void *item
)
5931 const struct type_unit_group
*tu_group
5932 = (const struct type_unit_group
*) item
;
5934 return hash_stmt_list_entry (&tu_group
->hash
);
5938 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
5940 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
5941 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
5943 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
5946 /* Allocate a hash table for type unit groups. */
5949 allocate_type_unit_groups_table (void)
5951 return htab_create_alloc_ex (3,
5952 hash_type_unit_group
,
5955 &dwarf2_per_objfile
->objfile
->objfile_obstack
,
5956 hashtab_obstack_allocate
,
5957 dummy_obstack_deallocate
);
5960 /* Type units that don't have DW_AT_stmt_list are grouped into their own
5961 partial symtabs. We combine several TUs per psymtab to not let the size
5962 of any one psymtab grow too big. */
5963 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
5964 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
5966 /* Helper routine for get_type_unit_group.
5967 Create the type_unit_group object used to hold one or more TUs. */
5969 static struct type_unit_group
*
5970 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
5972 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5973 struct dwarf2_per_cu_data
*per_cu
;
5974 struct type_unit_group
*tu_group
;
5976 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5977 struct type_unit_group
);
5978 per_cu
= &tu_group
->per_cu
;
5979 per_cu
->objfile
= objfile
;
5981 if (dwarf2_per_objfile
->using_index
)
5983 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5984 struct dwarf2_per_cu_quick_data
);
5988 unsigned int line_offset
= to_underlying (line_offset_struct
);
5989 struct partial_symtab
*pst
;
5992 /* Give the symtab a useful name for debug purposes. */
5993 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
5994 name
= xstrprintf ("<type_units_%d>",
5995 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
5997 name
= xstrprintf ("<type_units_at_0x%x>", line_offset
);
5999 pst
= create_partial_symtab (per_cu
, name
);
6005 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
6006 tu_group
->hash
.line_sect_off
= line_offset_struct
;
6011 /* Look up the type_unit_group for type unit CU, and create it if necessary.
6012 STMT_LIST is a DW_AT_stmt_list attribute. */
6014 static struct type_unit_group
*
6015 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
6017 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
6018 struct type_unit_group
*tu_group
;
6020 unsigned int line_offset
;
6021 struct type_unit_group type_unit_group_for_lookup
;
6023 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
6025 dwarf2_per_objfile
->type_unit_groups
=
6026 allocate_type_unit_groups_table ();
6029 /* Do we need to create a new group, or can we use an existing one? */
6033 line_offset
= DW_UNSND (stmt_list
);
6034 ++tu_stats
->nr_symtab_sharers
;
6038 /* Ugh, no stmt_list. Rare, but we have to handle it.
6039 We can do various things here like create one group per TU or
6040 spread them over multiple groups to split up the expansion work.
6041 To avoid worst case scenarios (too many groups or too large groups)
6042 we, umm, group them in bunches. */
6043 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
6044 | (tu_stats
->nr_stmt_less_type_units
6045 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
6046 ++tu_stats
->nr_stmt_less_type_units
;
6049 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
6050 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
6051 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
6052 &type_unit_group_for_lookup
, INSERT
);
6055 tu_group
= (struct type_unit_group
*) *slot
;
6056 gdb_assert (tu_group
!= NULL
);
6060 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
6061 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
6063 ++tu_stats
->nr_symtabs
;
6069 /* Partial symbol tables. */
6071 /* Create a psymtab named NAME and assign it to PER_CU.
6073 The caller must fill in the following details:
6074 dirname, textlow, texthigh. */
6076 static struct partial_symtab
*
6077 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
6079 struct objfile
*objfile
= per_cu
->objfile
;
6080 struct partial_symtab
*pst
;
6082 pst
= start_psymtab_common (objfile
, name
, 0,
6083 objfile
->global_psymbols
.next
,
6084 objfile
->static_psymbols
.next
);
6086 pst
->psymtabs_addrmap_supported
= 1;
6088 /* This is the glue that links PST into GDB's symbol API. */
6089 pst
->read_symtab_private
= per_cu
;
6090 pst
->read_symtab
= dwarf2_read_symtab
;
6091 per_cu
->v
.psymtab
= pst
;
6096 /* The DATA object passed to process_psymtab_comp_unit_reader has this
6099 struct process_psymtab_comp_unit_data
6101 /* True if we are reading a DW_TAG_partial_unit. */
6103 int want_partial_unit
;
6105 /* The "pretend" language that is used if the CU doesn't declare a
6108 enum language pretend_language
;
6111 /* die_reader_func for process_psymtab_comp_unit. */
6114 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
6115 const gdb_byte
*info_ptr
,
6116 struct die_info
*comp_unit_die
,
6120 struct dwarf2_cu
*cu
= reader
->cu
;
6121 struct objfile
*objfile
= cu
->objfile
;
6122 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6123 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6125 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
6126 struct partial_symtab
*pst
;
6127 enum pc_bounds_kind cu_bounds_kind
;
6128 const char *filename
;
6129 struct process_psymtab_comp_unit_data
*info
6130 = (struct process_psymtab_comp_unit_data
*) data
;
6132 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !info
->want_partial_unit
)
6135 gdb_assert (! per_cu
->is_debug_types
);
6137 prepare_one_comp_unit (cu
, comp_unit_die
, info
->pretend_language
);
6139 cu
->list_in_scope
= &file_symbols
;
6141 /* Allocate a new partial symbol table structure. */
6142 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
6143 if (filename
== NULL
)
6146 pst
= create_partial_symtab (per_cu
, filename
);
6148 /* This must be done before calling dwarf2_build_include_psymtabs. */
6149 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6151 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6153 dwarf2_find_base_address (comp_unit_die
, cu
);
6155 /* Possibly set the default values of LOWPC and HIGHPC from
6157 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
6158 &best_highpc
, cu
, pst
);
6159 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
6160 /* Store the contiguous range if it is not empty; it can be empty for
6161 CUs with no code. */
6162 addrmap_set_empty (objfile
->psymtabs_addrmap
,
6163 gdbarch_adjust_dwarf2_addr (gdbarch
,
6164 best_lowpc
+ baseaddr
),
6165 gdbarch_adjust_dwarf2_addr (gdbarch
,
6166 best_highpc
+ baseaddr
) - 1,
6169 /* Check if comp unit has_children.
6170 If so, read the rest of the partial symbols from this comp unit.
6171 If not, there's no more debug_info for this comp unit. */
6174 struct partial_die_info
*first_die
;
6175 CORE_ADDR lowpc
, highpc
;
6177 lowpc
= ((CORE_ADDR
) -1);
6178 highpc
= ((CORE_ADDR
) 0);
6180 first_die
= load_partial_dies (reader
, info_ptr
, 1);
6182 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
6183 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
6185 /* If we didn't find a lowpc, set it to highpc to avoid
6186 complaints from `maint check'. */
6187 if (lowpc
== ((CORE_ADDR
) -1))
6190 /* If the compilation unit didn't have an explicit address range,
6191 then use the information extracted from its child dies. */
6192 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
6195 best_highpc
= highpc
;
6198 pst
->textlow
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
);
6199 pst
->texthigh
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
);
6201 end_psymtab_common (objfile
, pst
);
6203 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
))
6206 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
6207 struct dwarf2_per_cu_data
*iter
;
6209 /* Fill in 'dependencies' here; we fill in 'users' in a
6211 pst
->number_of_dependencies
= len
;
6213 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
6215 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
6218 pst
->dependencies
[i
] = iter
->v
.psymtab
;
6220 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
6223 /* Get the list of files included in the current compilation unit,
6224 and build a psymtab for each of them. */
6225 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
6227 if (dwarf_read_debug
)
6229 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6231 fprintf_unfiltered (gdb_stdlog
,
6232 "Psymtab for %s unit @0x%x: %s - %s"
6233 ", %d global, %d static syms\n",
6234 per_cu
->is_debug_types
? "type" : "comp",
6235 to_underlying (per_cu
->sect_off
),
6236 paddress (gdbarch
, pst
->textlow
),
6237 paddress (gdbarch
, pst
->texthigh
),
6238 pst
->n_global_syms
, pst
->n_static_syms
);
6242 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
6243 Process compilation unit THIS_CU for a psymtab. */
6246 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
6247 int want_partial_unit
,
6248 enum language pretend_language
)
6250 struct process_psymtab_comp_unit_data info
;
6252 /* If this compilation unit was already read in, free the
6253 cached copy in order to read it in again. This is
6254 necessary because we skipped some symbols when we first
6255 read in the compilation unit (see load_partial_dies).
6256 This problem could be avoided, but the benefit is unclear. */
6257 if (this_cu
->cu
!= NULL
)
6258 free_one_cached_comp_unit (this_cu
);
6260 gdb_assert (! this_cu
->is_debug_types
);
6261 info
.want_partial_unit
= want_partial_unit
;
6262 info
.pretend_language
= pretend_language
;
6263 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0,
6264 process_psymtab_comp_unit_reader
,
6267 /* Age out any secondary CUs. */
6268 age_cached_comp_units ();
6271 /* Reader function for build_type_psymtabs. */
6274 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
6275 const gdb_byte
*info_ptr
,
6276 struct die_info
*type_unit_die
,
6280 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6281 struct dwarf2_cu
*cu
= reader
->cu
;
6282 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6283 struct signatured_type
*sig_type
;
6284 struct type_unit_group
*tu_group
;
6285 struct attribute
*attr
;
6286 struct partial_die_info
*first_die
;
6287 CORE_ADDR lowpc
, highpc
;
6288 struct partial_symtab
*pst
;
6290 gdb_assert (data
== NULL
);
6291 gdb_assert (per_cu
->is_debug_types
);
6292 sig_type
= (struct signatured_type
*) per_cu
;
6297 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
6298 tu_group
= get_type_unit_group (cu
, attr
);
6300 VEC_safe_push (sig_type_ptr
, tu_group
->tus
, sig_type
);
6302 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
6303 cu
->list_in_scope
= &file_symbols
;
6304 pst
= create_partial_symtab (per_cu
, "");
6307 first_die
= load_partial_dies (reader
, info_ptr
, 1);
6309 lowpc
= (CORE_ADDR
) -1;
6310 highpc
= (CORE_ADDR
) 0;
6311 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
6313 end_psymtab_common (objfile
, pst
);
6316 /* Struct used to sort TUs by their abbreviation table offset. */
6318 struct tu_abbrev_offset
6320 struct signatured_type
*sig_type
;
6321 sect_offset abbrev_offset
;
6324 /* Helper routine for build_type_psymtabs_1, passed to qsort. */
6327 sort_tu_by_abbrev_offset (const void *ap
, const void *bp
)
6329 const struct tu_abbrev_offset
* const *a
6330 = (const struct tu_abbrev_offset
* const*) ap
;
6331 const struct tu_abbrev_offset
* const *b
6332 = (const struct tu_abbrev_offset
* const*) bp
;
6333 sect_offset aoff
= (*a
)->abbrev_offset
;
6334 sect_offset boff
= (*b
)->abbrev_offset
;
6336 return (aoff
> boff
) - (aoff
< boff
);
6339 /* Efficiently read all the type units.
6340 This does the bulk of the work for build_type_psymtabs.
6342 The efficiency is because we sort TUs by the abbrev table they use and
6343 only read each abbrev table once. In one program there are 200K TUs
6344 sharing 8K abbrev tables.
6346 The main purpose of this function is to support building the
6347 dwarf2_per_objfile->type_unit_groups table.
6348 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
6349 can collapse the search space by grouping them by stmt_list.
6350 The savings can be significant, in the same program from above the 200K TUs
6351 share 8K stmt_list tables.
6353 FUNC is expected to call get_type_unit_group, which will create the
6354 struct type_unit_group if necessary and add it to
6355 dwarf2_per_objfile->type_unit_groups. */
6358 build_type_psymtabs_1 (void)
6360 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
6361 struct cleanup
*cleanups
;
6362 struct abbrev_table
*abbrev_table
;
6363 sect_offset abbrev_offset
;
6364 struct tu_abbrev_offset
*sorted_by_abbrev
;
6367 /* It's up to the caller to not call us multiple times. */
6368 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
6370 if (dwarf2_per_objfile
->n_type_units
== 0)
6373 /* TUs typically share abbrev tables, and there can be way more TUs than
6374 abbrev tables. Sort by abbrev table to reduce the number of times we
6375 read each abbrev table in.
6376 Alternatives are to punt or to maintain a cache of abbrev tables.
6377 This is simpler and efficient enough for now.
6379 Later we group TUs by their DW_AT_stmt_list value (as this defines the
6380 symtab to use). Typically TUs with the same abbrev offset have the same
6381 stmt_list value too so in practice this should work well.
6383 The basic algorithm here is:
6385 sort TUs by abbrev table
6386 for each TU with same abbrev table:
6387 read abbrev table if first user
6388 read TU top level DIE
6389 [IWBN if DWO skeletons had DW_AT_stmt_list]
6392 if (dwarf_read_debug
)
6393 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
6395 /* Sort in a separate table to maintain the order of all_type_units
6396 for .gdb_index: TU indices directly index all_type_units. */
6397 sorted_by_abbrev
= XNEWVEC (struct tu_abbrev_offset
,
6398 dwarf2_per_objfile
->n_type_units
);
6399 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
6401 struct signatured_type
*sig_type
= dwarf2_per_objfile
->all_type_units
[i
];
6403 sorted_by_abbrev
[i
].sig_type
= sig_type
;
6404 sorted_by_abbrev
[i
].abbrev_offset
=
6405 read_abbrev_offset (sig_type
->per_cu
.section
,
6406 sig_type
->per_cu
.sect_off
);
6408 cleanups
= make_cleanup (xfree
, sorted_by_abbrev
);
6409 qsort (sorted_by_abbrev
, dwarf2_per_objfile
->n_type_units
,
6410 sizeof (struct tu_abbrev_offset
), sort_tu_by_abbrev_offset
);
6412 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
6413 abbrev_table
= NULL
;
6414 make_cleanup (abbrev_table_free_cleanup
, &abbrev_table
);
6416 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
6418 const struct tu_abbrev_offset
*tu
= &sorted_by_abbrev
[i
];
6420 /* Switch to the next abbrev table if necessary. */
6421 if (abbrev_table
== NULL
6422 || tu
->abbrev_offset
!= abbrev_offset
)
6424 if (abbrev_table
!= NULL
)
6426 abbrev_table_free (abbrev_table
);
6427 /* Reset to NULL in case abbrev_table_read_table throws
6428 an error: abbrev_table_free_cleanup will get called. */
6429 abbrev_table
= NULL
;
6431 abbrev_offset
= tu
->abbrev_offset
;
6433 abbrev_table_read_table (&dwarf2_per_objfile
->abbrev
,
6435 ++tu_stats
->nr_uniq_abbrev_tables
;
6438 init_cutu_and_read_dies (&tu
->sig_type
->per_cu
, abbrev_table
, 0, 0,
6439 build_type_psymtabs_reader
, NULL
);
6442 do_cleanups (cleanups
);
6445 /* Print collected type unit statistics. */
6448 print_tu_stats (void)
6450 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
6452 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
6453 fprintf_unfiltered (gdb_stdlog
, " %d TUs\n",
6454 dwarf2_per_objfile
->n_type_units
);
6455 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
6456 tu_stats
->nr_uniq_abbrev_tables
);
6457 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
6458 tu_stats
->nr_symtabs
);
6459 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
6460 tu_stats
->nr_symtab_sharers
);
6461 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
6462 tu_stats
->nr_stmt_less_type_units
);
6463 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
6464 tu_stats
->nr_all_type_units_reallocs
);
6467 /* Traversal function for build_type_psymtabs. */
6470 build_type_psymtab_dependencies (void **slot
, void *info
)
6472 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6473 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
6474 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
6475 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
6476 int len
= VEC_length (sig_type_ptr
, tu_group
->tus
);
6477 struct signatured_type
*iter
;
6480 gdb_assert (len
> 0);
6481 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
6483 pst
->number_of_dependencies
= len
;
6485 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
6487 VEC_iterate (sig_type_ptr
, tu_group
->tus
, i
, iter
);
6490 gdb_assert (iter
->per_cu
.is_debug_types
);
6491 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
6492 iter
->type_unit_group
= tu_group
;
6495 VEC_free (sig_type_ptr
, tu_group
->tus
);
6500 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
6501 Build partial symbol tables for the .debug_types comp-units. */
6504 build_type_psymtabs (struct objfile
*objfile
)
6506 if (! create_all_type_units (objfile
))
6509 build_type_psymtabs_1 ();
6512 /* Traversal function for process_skeletonless_type_unit.
6513 Read a TU in a DWO file and build partial symbols for it. */
6516 process_skeletonless_type_unit (void **slot
, void *info
)
6518 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
6519 struct objfile
*objfile
= (struct objfile
*) info
;
6520 struct signatured_type find_entry
, *entry
;
6522 /* If this TU doesn't exist in the global table, add it and read it in. */
6524 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6526 dwarf2_per_objfile
->signatured_types
6527 = allocate_signatured_type_table (objfile
);
6530 find_entry
.signature
= dwo_unit
->signature
;
6531 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
6533 /* If we've already seen this type there's nothing to do. What's happening
6534 is we're doing our own version of comdat-folding here. */
6538 /* This does the job that create_all_type_units would have done for
6540 entry
= add_type_unit (dwo_unit
->signature
, slot
);
6541 fill_in_sig_entry_from_dwo_entry (objfile
, entry
, dwo_unit
);
6544 /* This does the job that build_type_psymtabs_1 would have done. */
6545 init_cutu_and_read_dies (&entry
->per_cu
, NULL
, 0, 0,
6546 build_type_psymtabs_reader
, NULL
);
6551 /* Traversal function for process_skeletonless_type_units. */
6554 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
6556 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
6558 if (dwo_file
->tus
!= NULL
)
6560 htab_traverse_noresize (dwo_file
->tus
,
6561 process_skeletonless_type_unit
, info
);
6567 /* Scan all TUs of DWO files, verifying we've processed them.
6568 This is needed in case a TU was emitted without its skeleton.
6569 Note: This can't be done until we know what all the DWO files are. */
6572 process_skeletonless_type_units (struct objfile
*objfile
)
6574 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
6575 if (get_dwp_file () == NULL
6576 && dwarf2_per_objfile
->dwo_files
!= NULL
)
6578 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
,
6579 process_dwo_file_for_skeletonless_type_units
,
6584 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
6587 psymtabs_addrmap_cleanup (void *o
)
6589 struct objfile
*objfile
= (struct objfile
*) o
;
6591 objfile
->psymtabs_addrmap
= NULL
;
6594 /* Compute the 'user' field for each psymtab in OBJFILE. */
6597 set_partial_user (struct objfile
*objfile
)
6601 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
6603 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
6604 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
6610 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
6612 /* Set the 'user' field only if it is not already set. */
6613 if (pst
->dependencies
[j
]->user
== NULL
)
6614 pst
->dependencies
[j
]->user
= pst
;
6619 /* Build the partial symbol table by doing a quick pass through the
6620 .debug_info and .debug_abbrev sections. */
6623 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
6625 struct cleanup
*back_to
, *addrmap_cleanup
;
6626 struct obstack temp_obstack
;
6629 if (dwarf_read_debug
)
6631 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
6632 objfile_name (objfile
));
6635 dwarf2_per_objfile
->reading_partial_symbols
= 1;
6637 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
6639 /* Any cached compilation units will be linked by the per-objfile
6640 read_in_chain. Make sure to free them when we're done. */
6641 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
6643 build_type_psymtabs (objfile
);
6645 create_all_comp_units (objfile
);
6647 /* Create a temporary address map on a temporary obstack. We later
6648 copy this to the final obstack. */
6649 obstack_init (&temp_obstack
);
6650 make_cleanup_obstack_free (&temp_obstack
);
6651 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
6652 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
6654 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
6656 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
6658 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
6661 /* This has to wait until we read the CUs, we need the list of DWOs. */
6662 process_skeletonless_type_units (objfile
);
6664 /* Now that all TUs have been processed we can fill in the dependencies. */
6665 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
6667 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
6668 build_type_psymtab_dependencies
, NULL
);
6671 if (dwarf_read_debug
)
6674 set_partial_user (objfile
);
6676 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
6677 &objfile
->objfile_obstack
);
6678 discard_cleanups (addrmap_cleanup
);
6680 do_cleanups (back_to
);
6682 if (dwarf_read_debug
)
6683 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
6684 objfile_name (objfile
));
6687 /* die_reader_func for load_partial_comp_unit. */
6690 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
6691 const gdb_byte
*info_ptr
,
6692 struct die_info
*comp_unit_die
,
6696 struct dwarf2_cu
*cu
= reader
->cu
;
6698 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
6700 /* Check if comp unit has_children.
6701 If so, read the rest of the partial symbols from this comp unit.
6702 If not, there's no more debug_info for this comp unit. */
6704 load_partial_dies (reader
, info_ptr
, 0);
6707 /* Load the partial DIEs for a secondary CU into memory.
6708 This is also used when rereading a primary CU with load_all_dies. */
6711 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
6713 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
6714 load_partial_comp_unit_reader
, NULL
);
6718 read_comp_units_from_section (struct objfile
*objfile
,
6719 struct dwarf2_section_info
*section
,
6720 unsigned int is_dwz
,
6723 struct dwarf2_per_cu_data
***all_comp_units
)
6725 const gdb_byte
*info_ptr
;
6726 bfd
*abfd
= get_section_bfd_owner (section
);
6728 if (dwarf_read_debug
)
6729 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
6730 get_section_name (section
),
6731 get_section_file_name (section
));
6733 dwarf2_read_section (objfile
, section
);
6735 info_ptr
= section
->buffer
;
6737 while (info_ptr
< section
->buffer
+ section
->size
)
6739 unsigned int length
, initial_length_size
;
6740 struct dwarf2_per_cu_data
*this_cu
;
6742 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
6744 /* Read just enough information to find out where the next
6745 compilation unit is. */
6746 length
= read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6748 /* Save the compilation unit for later lookup. */
6749 this_cu
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_per_cu_data
);
6750 memset (this_cu
, 0, sizeof (*this_cu
));
6751 this_cu
->sect_off
= sect_off
;
6752 this_cu
->length
= length
+ initial_length_size
;
6753 this_cu
->is_dwz
= is_dwz
;
6754 this_cu
->objfile
= objfile
;
6755 this_cu
->section
= section
;
6757 if (*n_comp_units
== *n_allocated
)
6760 *all_comp_units
= XRESIZEVEC (struct dwarf2_per_cu_data
*,
6761 *all_comp_units
, *n_allocated
);
6763 (*all_comp_units
)[*n_comp_units
] = this_cu
;
6766 info_ptr
= info_ptr
+ this_cu
->length
;
6770 /* Create a list of all compilation units in OBJFILE.
6771 This is only done for -readnow and building partial symtabs. */
6774 create_all_comp_units (struct objfile
*objfile
)
6778 struct dwarf2_per_cu_data
**all_comp_units
;
6779 struct dwz_file
*dwz
;
6783 all_comp_units
= XNEWVEC (struct dwarf2_per_cu_data
*, n_allocated
);
6785 read_comp_units_from_section (objfile
, &dwarf2_per_objfile
->info
, 0,
6786 &n_allocated
, &n_comp_units
, &all_comp_units
);
6788 dwz
= dwarf2_get_dwz_file ();
6790 read_comp_units_from_section (objfile
, &dwz
->info
, 1,
6791 &n_allocated
, &n_comp_units
,
6794 dwarf2_per_objfile
->all_comp_units
= XOBNEWVEC (&objfile
->objfile_obstack
,
6795 struct dwarf2_per_cu_data
*,
6797 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
6798 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
6799 xfree (all_comp_units
);
6800 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
6803 /* Process all loaded DIEs for compilation unit CU, starting at
6804 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
6805 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
6806 DW_AT_ranges). See the comments of add_partial_subprogram on how
6807 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
6810 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
6811 CORE_ADDR
*highpc
, int set_addrmap
,
6812 struct dwarf2_cu
*cu
)
6814 struct partial_die_info
*pdi
;
6816 /* Now, march along the PDI's, descending into ones which have
6817 interesting children but skipping the children of the other ones,
6818 until we reach the end of the compilation unit. */
6824 fixup_partial_die (pdi
, cu
);
6826 /* Anonymous namespaces or modules have no name but have interesting
6827 children, so we need to look at them. Ditto for anonymous
6830 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
6831 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
6832 || pdi
->tag
== DW_TAG_imported_unit
)
6836 case DW_TAG_subprogram
:
6837 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
6839 case DW_TAG_constant
:
6840 case DW_TAG_variable
:
6841 case DW_TAG_typedef
:
6842 case DW_TAG_union_type
:
6843 if (!pdi
->is_declaration
)
6845 add_partial_symbol (pdi
, cu
);
6848 case DW_TAG_class_type
:
6849 case DW_TAG_interface_type
:
6850 case DW_TAG_structure_type
:
6851 if (!pdi
->is_declaration
)
6853 add_partial_symbol (pdi
, cu
);
6855 if (cu
->language
== language_rust
&& pdi
->has_children
)
6856 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
6859 case DW_TAG_enumeration_type
:
6860 if (!pdi
->is_declaration
)
6861 add_partial_enumeration (pdi
, cu
);
6863 case DW_TAG_base_type
:
6864 case DW_TAG_subrange_type
:
6865 /* File scope base type definitions are added to the partial
6867 add_partial_symbol (pdi
, cu
);
6869 case DW_TAG_namespace
:
6870 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
6873 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
6875 case DW_TAG_imported_unit
:
6877 struct dwarf2_per_cu_data
*per_cu
;
6879 /* For now we don't handle imported units in type units. */
6880 if (cu
->per_cu
->is_debug_types
)
6882 error (_("Dwarf Error: DW_TAG_imported_unit is not"
6883 " supported in type units [in module %s]"),
6884 objfile_name (cu
->objfile
));
6887 per_cu
= dwarf2_find_containing_comp_unit (pdi
->d
.sect_off
,
6891 /* Go read the partial unit, if needed. */
6892 if (per_cu
->v
.psymtab
== NULL
)
6893 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
6895 VEC_safe_push (dwarf2_per_cu_ptr
,
6896 cu
->per_cu
->imported_symtabs
, per_cu
);
6899 case DW_TAG_imported_declaration
:
6900 add_partial_symbol (pdi
, cu
);
6907 /* If the die has a sibling, skip to the sibling. */
6909 pdi
= pdi
->die_sibling
;
6913 /* Functions used to compute the fully scoped name of a partial DIE.
6915 Normally, this is simple. For C++, the parent DIE's fully scoped
6916 name is concatenated with "::" and the partial DIE's name.
6917 Enumerators are an exception; they use the scope of their parent
6918 enumeration type, i.e. the name of the enumeration type is not
6919 prepended to the enumerator.
6921 There are two complexities. One is DW_AT_specification; in this
6922 case "parent" means the parent of the target of the specification,
6923 instead of the direct parent of the DIE. The other is compilers
6924 which do not emit DW_TAG_namespace; in this case we try to guess
6925 the fully qualified name of structure types from their members'
6926 linkage names. This must be done using the DIE's children rather
6927 than the children of any DW_AT_specification target. We only need
6928 to do this for structures at the top level, i.e. if the target of
6929 any DW_AT_specification (if any; otherwise the DIE itself) does not
6932 /* Compute the scope prefix associated with PDI's parent, in
6933 compilation unit CU. The result will be allocated on CU's
6934 comp_unit_obstack, or a copy of the already allocated PDI->NAME
6935 field. NULL is returned if no prefix is necessary. */
6937 partial_die_parent_scope (struct partial_die_info
*pdi
,
6938 struct dwarf2_cu
*cu
)
6940 const char *grandparent_scope
;
6941 struct partial_die_info
*parent
, *real_pdi
;
6943 /* We need to look at our parent DIE; if we have a DW_AT_specification,
6944 then this means the parent of the specification DIE. */
6947 while (real_pdi
->has_specification
)
6948 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
6949 real_pdi
->spec_is_dwz
, cu
);
6951 parent
= real_pdi
->die_parent
;
6955 if (parent
->scope_set
)
6956 return parent
->scope
;
6958 fixup_partial_die (parent
, cu
);
6960 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
6962 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
6963 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
6964 Work around this problem here. */
6965 if (cu
->language
== language_cplus
6966 && parent
->tag
== DW_TAG_namespace
6967 && strcmp (parent
->name
, "::") == 0
6968 && grandparent_scope
== NULL
)
6970 parent
->scope
= NULL
;
6971 parent
->scope_set
= 1;
6975 if (pdi
->tag
== DW_TAG_enumerator
)
6976 /* Enumerators should not get the name of the enumeration as a prefix. */
6977 parent
->scope
= grandparent_scope
;
6978 else if (parent
->tag
== DW_TAG_namespace
6979 || parent
->tag
== DW_TAG_module
6980 || parent
->tag
== DW_TAG_structure_type
6981 || parent
->tag
== DW_TAG_class_type
6982 || parent
->tag
== DW_TAG_interface_type
6983 || parent
->tag
== DW_TAG_union_type
6984 || parent
->tag
== DW_TAG_enumeration_type
)
6986 if (grandparent_scope
== NULL
)
6987 parent
->scope
= parent
->name
;
6989 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
6991 parent
->name
, 0, cu
);
6995 /* FIXME drow/2004-04-01: What should we be doing with
6996 function-local names? For partial symbols, we should probably be
6998 complaint (&symfile_complaints
,
6999 _("unhandled containing DIE tag %d for DIE at %d"),
7000 parent
->tag
, to_underlying (pdi
->sect_off
));
7001 parent
->scope
= grandparent_scope
;
7004 parent
->scope_set
= 1;
7005 return parent
->scope
;
7008 /* Return the fully scoped name associated with PDI, from compilation unit
7009 CU. The result will be allocated with malloc. */
7012 partial_die_full_name (struct partial_die_info
*pdi
,
7013 struct dwarf2_cu
*cu
)
7015 const char *parent_scope
;
7017 /* If this is a template instantiation, we can not work out the
7018 template arguments from partial DIEs. So, unfortunately, we have
7019 to go through the full DIEs. At least any work we do building
7020 types here will be reused if full symbols are loaded later. */
7021 if (pdi
->has_template_arguments
)
7023 fixup_partial_die (pdi
, cu
);
7025 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
7027 struct die_info
*die
;
7028 struct attribute attr
;
7029 struct dwarf2_cu
*ref_cu
= cu
;
7031 /* DW_FORM_ref_addr is using section offset. */
7032 attr
.name
= (enum dwarf_attribute
) 0;
7033 attr
.form
= DW_FORM_ref_addr
;
7034 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
7035 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
7037 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
7041 parent_scope
= partial_die_parent_scope (pdi
, cu
);
7042 if (parent_scope
== NULL
)
7045 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
7049 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
7051 struct objfile
*objfile
= cu
->objfile
;
7052 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7054 const char *actual_name
= NULL
;
7056 char *built_actual_name
;
7058 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7060 built_actual_name
= partial_die_full_name (pdi
, cu
);
7061 if (built_actual_name
!= NULL
)
7062 actual_name
= built_actual_name
;
7064 if (actual_name
== NULL
)
7065 actual_name
= pdi
->name
;
7069 case DW_TAG_subprogram
:
7070 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
);
7071 if (pdi
->is_external
|| cu
->language
== language_ada
)
7073 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
7074 of the global scope. But in Ada, we want to be able to access
7075 nested procedures globally. So all Ada subprograms are stored
7076 in the global scope. */
7077 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7078 built_actual_name
!= NULL
,
7079 VAR_DOMAIN
, LOC_BLOCK
,
7080 &objfile
->global_psymbols
,
7081 addr
, cu
->language
, objfile
);
7085 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7086 built_actual_name
!= NULL
,
7087 VAR_DOMAIN
, LOC_BLOCK
,
7088 &objfile
->static_psymbols
,
7089 addr
, cu
->language
, objfile
);
7092 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
7093 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
7095 case DW_TAG_constant
:
7097 struct psymbol_allocation_list
*list
;
7099 if (pdi
->is_external
)
7100 list
= &objfile
->global_psymbols
;
7102 list
= &objfile
->static_psymbols
;
7103 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7104 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
7105 list
, 0, cu
->language
, objfile
);
7108 case DW_TAG_variable
:
7110 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
7114 && !dwarf2_per_objfile
->has_section_at_zero
)
7116 /* A global or static variable may also have been stripped
7117 out by the linker if unused, in which case its address
7118 will be nullified; do not add such variables into partial
7119 symbol table then. */
7121 else if (pdi
->is_external
)
7124 Don't enter into the minimal symbol tables as there is
7125 a minimal symbol table entry from the ELF symbols already.
7126 Enter into partial symbol table if it has a location
7127 descriptor or a type.
7128 If the location descriptor is missing, new_symbol will create
7129 a LOC_UNRESOLVED symbol, the address of the variable will then
7130 be determined from the minimal symbol table whenever the variable
7132 The address for the partial symbol table entry is not
7133 used by GDB, but it comes in handy for debugging partial symbol
7136 if (pdi
->d
.locdesc
|| pdi
->has_type
)
7137 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7138 built_actual_name
!= NULL
,
7139 VAR_DOMAIN
, LOC_STATIC
,
7140 &objfile
->global_psymbols
,
7142 cu
->language
, objfile
);
7146 int has_loc
= pdi
->d
.locdesc
!= NULL
;
7148 /* Static Variable. Skip symbols whose value we cannot know (those
7149 without location descriptors or constant values). */
7150 if (!has_loc
&& !pdi
->has_const_value
)
7152 xfree (built_actual_name
);
7156 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7157 built_actual_name
!= NULL
,
7158 VAR_DOMAIN
, LOC_STATIC
,
7159 &objfile
->static_psymbols
,
7160 has_loc
? addr
+ baseaddr
: (CORE_ADDR
) 0,
7161 cu
->language
, objfile
);
7164 case DW_TAG_typedef
:
7165 case DW_TAG_base_type
:
7166 case DW_TAG_subrange_type
:
7167 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7168 built_actual_name
!= NULL
,
7169 VAR_DOMAIN
, LOC_TYPEDEF
,
7170 &objfile
->static_psymbols
,
7171 0, cu
->language
, objfile
);
7173 case DW_TAG_imported_declaration
:
7174 case DW_TAG_namespace
:
7175 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7176 built_actual_name
!= NULL
,
7177 VAR_DOMAIN
, LOC_TYPEDEF
,
7178 &objfile
->global_psymbols
,
7179 0, cu
->language
, objfile
);
7182 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7183 built_actual_name
!= NULL
,
7184 MODULE_DOMAIN
, LOC_TYPEDEF
,
7185 &objfile
->global_psymbols
,
7186 0, cu
->language
, objfile
);
7188 case DW_TAG_class_type
:
7189 case DW_TAG_interface_type
:
7190 case DW_TAG_structure_type
:
7191 case DW_TAG_union_type
:
7192 case DW_TAG_enumeration_type
:
7193 /* Skip external references. The DWARF standard says in the section
7194 about "Structure, Union, and Class Type Entries": "An incomplete
7195 structure, union or class type is represented by a structure,
7196 union or class entry that does not have a byte size attribute
7197 and that has a DW_AT_declaration attribute." */
7198 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
7200 xfree (built_actual_name
);
7204 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
7205 static vs. global. */
7206 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7207 built_actual_name
!= NULL
,
7208 STRUCT_DOMAIN
, LOC_TYPEDEF
,
7209 cu
->language
== language_cplus
7210 ? &objfile
->global_psymbols
7211 : &objfile
->static_psymbols
,
7212 0, cu
->language
, objfile
);
7215 case DW_TAG_enumerator
:
7216 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7217 built_actual_name
!= NULL
,
7218 VAR_DOMAIN
, LOC_CONST
,
7219 cu
->language
== language_cplus
7220 ? &objfile
->global_psymbols
7221 : &objfile
->static_psymbols
,
7222 0, cu
->language
, objfile
);
7228 xfree (built_actual_name
);
7231 /* Read a partial die corresponding to a namespace; also, add a symbol
7232 corresponding to that namespace to the symbol table. NAMESPACE is
7233 the name of the enclosing namespace. */
7236 add_partial_namespace (struct partial_die_info
*pdi
,
7237 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
7238 int set_addrmap
, struct dwarf2_cu
*cu
)
7240 /* Add a symbol for the namespace. */
7242 add_partial_symbol (pdi
, cu
);
7244 /* Now scan partial symbols in that namespace. */
7246 if (pdi
->has_children
)
7247 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
7250 /* Read a partial die corresponding to a Fortran module. */
7253 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
7254 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
7256 /* Add a symbol for the namespace. */
7258 add_partial_symbol (pdi
, cu
);
7260 /* Now scan partial symbols in that module. */
7262 if (pdi
->has_children
)
7263 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
7266 /* Read a partial die corresponding to a subprogram and create a partial
7267 symbol for that subprogram. When the CU language allows it, this
7268 routine also defines a partial symbol for each nested subprogram
7269 that this subprogram contains. If SET_ADDRMAP is true, record the
7270 covered ranges in the addrmap. Set *LOWPC and *HIGHPC to the lowest
7271 and highest PC values found in PDI.
7273 PDI may also be a lexical block, in which case we simply search
7274 recursively for subprograms defined inside that lexical block.
7275 Again, this is only performed when the CU language allows this
7276 type of definitions. */
7279 add_partial_subprogram (struct partial_die_info
*pdi
,
7280 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
7281 int set_addrmap
, struct dwarf2_cu
*cu
)
7283 if (pdi
->tag
== DW_TAG_subprogram
)
7285 if (pdi
->has_pc_info
)
7287 if (pdi
->lowpc
< *lowpc
)
7288 *lowpc
= pdi
->lowpc
;
7289 if (pdi
->highpc
> *highpc
)
7290 *highpc
= pdi
->highpc
;
7293 struct objfile
*objfile
= cu
->objfile
;
7294 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7299 baseaddr
= ANOFFSET (objfile
->section_offsets
,
7300 SECT_OFF_TEXT (objfile
));
7301 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
7302 pdi
->lowpc
+ baseaddr
);
7303 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
7304 pdi
->highpc
+ baseaddr
);
7305 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
7306 cu
->per_cu
->v
.psymtab
);
7310 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
7312 if (!pdi
->is_declaration
)
7313 /* Ignore subprogram DIEs that do not have a name, they are
7314 illegal. Do not emit a complaint at this point, we will
7315 do so when we convert this psymtab into a symtab. */
7317 add_partial_symbol (pdi
, cu
);
7321 if (! pdi
->has_children
)
7324 if (cu
->language
== language_ada
)
7326 pdi
= pdi
->die_child
;
7329 fixup_partial_die (pdi
, cu
);
7330 if (pdi
->tag
== DW_TAG_subprogram
7331 || pdi
->tag
== DW_TAG_lexical_block
)
7332 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7333 pdi
= pdi
->die_sibling
;
7338 /* Read a partial die corresponding to an enumeration type. */
7341 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
7342 struct dwarf2_cu
*cu
)
7344 struct partial_die_info
*pdi
;
7346 if (enum_pdi
->name
!= NULL
)
7347 add_partial_symbol (enum_pdi
, cu
);
7349 pdi
= enum_pdi
->die_child
;
7352 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
7353 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
7355 add_partial_symbol (pdi
, cu
);
7356 pdi
= pdi
->die_sibling
;
7360 /* Return the initial uleb128 in the die at INFO_PTR. */
7363 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
7365 unsigned int bytes_read
;
7367 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7370 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
7371 Return the corresponding abbrev, or NULL if the number is zero (indicating
7372 an empty DIE). In either case *BYTES_READ will be set to the length of
7373 the initial number. */
7375 static struct abbrev_info
*
7376 peek_die_abbrev (const gdb_byte
*info_ptr
, unsigned int *bytes_read
,
7377 struct dwarf2_cu
*cu
)
7379 bfd
*abfd
= cu
->objfile
->obfd
;
7380 unsigned int abbrev_number
;
7381 struct abbrev_info
*abbrev
;
7383 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
7385 if (abbrev_number
== 0)
7388 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
7391 error (_("Dwarf Error: Could not find abbrev number %d in %s"
7392 " at offset 0x%x [in module %s]"),
7393 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
7394 to_underlying (cu
->header
.sect_off
), bfd_get_filename (abfd
));
7400 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
7401 Returns a pointer to the end of a series of DIEs, terminated by an empty
7402 DIE. Any children of the skipped DIEs will also be skipped. */
7404 static const gdb_byte
*
7405 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
7407 struct dwarf2_cu
*cu
= reader
->cu
;
7408 struct abbrev_info
*abbrev
;
7409 unsigned int bytes_read
;
7413 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
7415 return info_ptr
+ bytes_read
;
7417 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
7421 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
7422 INFO_PTR should point just after the initial uleb128 of a DIE, and the
7423 abbrev corresponding to that skipped uleb128 should be passed in
7424 ABBREV. Returns a pointer to this DIE's sibling, skipping any
7427 static const gdb_byte
*
7428 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
7429 struct abbrev_info
*abbrev
)
7431 unsigned int bytes_read
;
7432 struct attribute attr
;
7433 bfd
*abfd
= reader
->abfd
;
7434 struct dwarf2_cu
*cu
= reader
->cu
;
7435 const gdb_byte
*buffer
= reader
->buffer
;
7436 const gdb_byte
*buffer_end
= reader
->buffer_end
;
7437 unsigned int form
, i
;
7439 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
7441 /* The only abbrev we care about is DW_AT_sibling. */
7442 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
7444 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
7445 if (attr
.form
== DW_FORM_ref_addr
)
7446 complaint (&symfile_complaints
,
7447 _("ignoring absolute DW_AT_sibling"));
7450 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
7451 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
7453 if (sibling_ptr
< info_ptr
)
7454 complaint (&symfile_complaints
,
7455 _("DW_AT_sibling points backwards"));
7456 else if (sibling_ptr
> reader
->buffer_end
)
7457 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
7463 /* If it isn't DW_AT_sibling, skip this attribute. */
7464 form
= abbrev
->attrs
[i
].form
;
7468 case DW_FORM_ref_addr
:
7469 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
7470 and later it is offset sized. */
7471 if (cu
->header
.version
== 2)
7472 info_ptr
+= cu
->header
.addr_size
;
7474 info_ptr
+= cu
->header
.offset_size
;
7476 case DW_FORM_GNU_ref_alt
:
7477 info_ptr
+= cu
->header
.offset_size
;
7480 info_ptr
+= cu
->header
.addr_size
;
7487 case DW_FORM_flag_present
:
7488 case DW_FORM_implicit_const
:
7500 case DW_FORM_ref_sig8
:
7503 case DW_FORM_data16
:
7506 case DW_FORM_string
:
7507 read_direct_string (abfd
, info_ptr
, &bytes_read
);
7508 info_ptr
+= bytes_read
;
7510 case DW_FORM_sec_offset
:
7512 case DW_FORM_GNU_strp_alt
:
7513 info_ptr
+= cu
->header
.offset_size
;
7515 case DW_FORM_exprloc
:
7517 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7518 info_ptr
+= bytes_read
;
7520 case DW_FORM_block1
:
7521 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
7523 case DW_FORM_block2
:
7524 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
7526 case DW_FORM_block4
:
7527 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
7531 case DW_FORM_ref_udata
:
7532 case DW_FORM_GNU_addr_index
:
7533 case DW_FORM_GNU_str_index
:
7534 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
7536 case DW_FORM_indirect
:
7537 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7538 info_ptr
+= bytes_read
;
7539 /* We need to continue parsing from here, so just go back to
7541 goto skip_attribute
;
7544 error (_("Dwarf Error: Cannot handle %s "
7545 "in DWARF reader [in module %s]"),
7546 dwarf_form_name (form
),
7547 bfd_get_filename (abfd
));
7551 if (abbrev
->has_children
)
7552 return skip_children (reader
, info_ptr
);
7557 /* Locate ORIG_PDI's sibling.
7558 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
7560 static const gdb_byte
*
7561 locate_pdi_sibling (const struct die_reader_specs
*reader
,
7562 struct partial_die_info
*orig_pdi
,
7563 const gdb_byte
*info_ptr
)
7565 /* Do we know the sibling already? */
7567 if (orig_pdi
->sibling
)
7568 return orig_pdi
->sibling
;
7570 /* Are there any children to deal with? */
7572 if (!orig_pdi
->has_children
)
7575 /* Skip the children the long way. */
7577 return skip_children (reader
, info_ptr
);
7580 /* Expand this partial symbol table into a full symbol table. SELF is
7584 dwarf2_read_symtab (struct partial_symtab
*self
,
7585 struct objfile
*objfile
)
7589 warning (_("bug: psymtab for %s is already read in."),
7596 printf_filtered (_("Reading in symbols for %s..."),
7598 gdb_flush (gdb_stdout
);
7601 /* Restore our global data. */
7603 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
7604 dwarf2_objfile_data_key
);
7606 /* If this psymtab is constructed from a debug-only objfile, the
7607 has_section_at_zero flag will not necessarily be correct. We
7608 can get the correct value for this flag by looking at the data
7609 associated with the (presumably stripped) associated objfile. */
7610 if (objfile
->separate_debug_objfile_backlink
)
7612 struct dwarf2_per_objfile
*dpo_backlink
7613 = ((struct dwarf2_per_objfile
*)
7614 objfile_data (objfile
->separate_debug_objfile_backlink
,
7615 dwarf2_objfile_data_key
));
7617 dwarf2_per_objfile
->has_section_at_zero
7618 = dpo_backlink
->has_section_at_zero
;
7621 dwarf2_per_objfile
->reading_partial_symbols
= 0;
7623 psymtab_to_symtab_1 (self
);
7625 /* Finish up the debug error message. */
7627 printf_filtered (_("done.\n"));
7630 process_cu_includes ();
7633 /* Reading in full CUs. */
7635 /* Add PER_CU to the queue. */
7638 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
7639 enum language pretend_language
)
7641 struct dwarf2_queue_item
*item
;
7644 item
= XNEW (struct dwarf2_queue_item
);
7645 item
->per_cu
= per_cu
;
7646 item
->pretend_language
= pretend_language
;
7649 if (dwarf2_queue
== NULL
)
7650 dwarf2_queue
= item
;
7652 dwarf2_queue_tail
->next
= item
;
7654 dwarf2_queue_tail
= item
;
7657 /* If PER_CU is not yet queued, add it to the queue.
7658 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
7660 The result is non-zero if PER_CU was queued, otherwise the result is zero
7661 meaning either PER_CU is already queued or it is already loaded.
7663 N.B. There is an invariant here that if a CU is queued then it is loaded.
7664 The caller is required to load PER_CU if we return non-zero. */
7667 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
7668 struct dwarf2_per_cu_data
*per_cu
,
7669 enum language pretend_language
)
7671 /* We may arrive here during partial symbol reading, if we need full
7672 DIEs to process an unusual case (e.g. template arguments). Do
7673 not queue PER_CU, just tell our caller to load its DIEs. */
7674 if (dwarf2_per_objfile
->reading_partial_symbols
)
7676 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
7681 /* Mark the dependence relation so that we don't flush PER_CU
7683 if (dependent_cu
!= NULL
)
7684 dwarf2_add_dependence (dependent_cu
, per_cu
);
7686 /* If it's already on the queue, we have nothing to do. */
7690 /* If the compilation unit is already loaded, just mark it as
7692 if (per_cu
->cu
!= NULL
)
7694 per_cu
->cu
->last_used
= 0;
7698 /* Add it to the queue. */
7699 queue_comp_unit (per_cu
, pretend_language
);
7704 /* Process the queue. */
7707 process_queue (void)
7709 struct dwarf2_queue_item
*item
, *next_item
;
7711 if (dwarf_read_debug
)
7713 fprintf_unfiltered (gdb_stdlog
,
7714 "Expanding one or more symtabs of objfile %s ...\n",
7715 objfile_name (dwarf2_per_objfile
->objfile
));
7718 /* The queue starts out with one item, but following a DIE reference
7719 may load a new CU, adding it to the end of the queue. */
7720 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
7722 if ((dwarf2_per_objfile
->using_index
7723 ? !item
->per_cu
->v
.quick
->compunit_symtab
7724 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
7725 /* Skip dummy CUs. */
7726 && item
->per_cu
->cu
!= NULL
)
7728 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
7729 unsigned int debug_print_threshold
;
7732 if (per_cu
->is_debug_types
)
7734 struct signatured_type
*sig_type
=
7735 (struct signatured_type
*) per_cu
;
7737 sprintf (buf
, "TU %s at offset 0x%x",
7738 hex_string (sig_type
->signature
),
7739 to_underlying (per_cu
->sect_off
));
7740 /* There can be 100s of TUs.
7741 Only print them in verbose mode. */
7742 debug_print_threshold
= 2;
7746 sprintf (buf
, "CU at offset 0x%x",
7747 to_underlying (per_cu
->sect_off
));
7748 debug_print_threshold
= 1;
7751 if (dwarf_read_debug
>= debug_print_threshold
)
7752 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
7754 if (per_cu
->is_debug_types
)
7755 process_full_type_unit (per_cu
, item
->pretend_language
);
7757 process_full_comp_unit (per_cu
, item
->pretend_language
);
7759 if (dwarf_read_debug
>= debug_print_threshold
)
7760 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
7763 item
->per_cu
->queued
= 0;
7764 next_item
= item
->next
;
7768 dwarf2_queue_tail
= NULL
;
7770 if (dwarf_read_debug
)
7772 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
7773 objfile_name (dwarf2_per_objfile
->objfile
));
7777 /* Free all allocated queue entries. This function only releases anything if
7778 an error was thrown; if the queue was processed then it would have been
7779 freed as we went along. */
7782 dwarf2_release_queue (void *dummy
)
7784 struct dwarf2_queue_item
*item
, *last
;
7786 item
= dwarf2_queue
;
7789 /* Anything still marked queued is likely to be in an
7790 inconsistent state, so discard it. */
7791 if (item
->per_cu
->queued
)
7793 if (item
->per_cu
->cu
!= NULL
)
7794 free_one_cached_comp_unit (item
->per_cu
);
7795 item
->per_cu
->queued
= 0;
7803 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
7806 /* Read in full symbols for PST, and anything it depends on. */
7809 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
7811 struct dwarf2_per_cu_data
*per_cu
;
7817 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
7818 if (!pst
->dependencies
[i
]->readin
7819 && pst
->dependencies
[i
]->user
== NULL
)
7821 /* Inform about additional files that need to be read in. */
7824 /* FIXME: i18n: Need to make this a single string. */
7825 fputs_filtered (" ", gdb_stdout
);
7827 fputs_filtered ("and ", gdb_stdout
);
7829 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
7830 wrap_here (""); /* Flush output. */
7831 gdb_flush (gdb_stdout
);
7833 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
7836 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
7840 /* It's an include file, no symbols to read for it.
7841 Everything is in the parent symtab. */
7846 dw2_do_instantiate_symtab (per_cu
);
7849 /* Trivial hash function for die_info: the hash value of a DIE
7850 is its offset in .debug_info for this objfile. */
7853 die_hash (const void *item
)
7855 const struct die_info
*die
= (const struct die_info
*) item
;
7857 return to_underlying (die
->sect_off
);
7860 /* Trivial comparison function for die_info structures: two DIEs
7861 are equal if they have the same offset. */
7864 die_eq (const void *item_lhs
, const void *item_rhs
)
7866 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
7867 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
7869 return die_lhs
->sect_off
== die_rhs
->sect_off
;
7872 /* die_reader_func for load_full_comp_unit.
7873 This is identical to read_signatured_type_reader,
7874 but is kept separate for now. */
7877 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
7878 const gdb_byte
*info_ptr
,
7879 struct die_info
*comp_unit_die
,
7883 struct dwarf2_cu
*cu
= reader
->cu
;
7884 enum language
*language_ptr
= (enum language
*) data
;
7886 gdb_assert (cu
->die_hash
== NULL
);
7888 htab_create_alloc_ex (cu
->header
.length
/ 12,
7892 &cu
->comp_unit_obstack
,
7893 hashtab_obstack_allocate
,
7894 dummy_obstack_deallocate
);
7897 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
7898 &info_ptr
, comp_unit_die
);
7899 cu
->dies
= comp_unit_die
;
7900 /* comp_unit_die is not stored in die_hash, no need. */
7902 /* We try not to read any attributes in this function, because not
7903 all CUs needed for references have been loaded yet, and symbol
7904 table processing isn't initialized. But we have to set the CU language,
7905 or we won't be able to build types correctly.
7906 Similarly, if we do not read the producer, we can not apply
7907 producer-specific interpretation. */
7908 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
7911 /* Load the DIEs associated with PER_CU into memory. */
7914 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7915 enum language pretend_language
)
7917 gdb_assert (! this_cu
->is_debug_types
);
7919 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
7920 load_full_comp_unit_reader
, &pretend_language
);
7923 /* Add a DIE to the delayed physname list. */
7926 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
7927 const char *name
, struct die_info
*die
,
7928 struct dwarf2_cu
*cu
)
7930 struct delayed_method_info mi
;
7932 mi
.fnfield_index
= fnfield_index
;
7936 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
7939 /* A cleanup for freeing the delayed method list. */
7942 free_delayed_list (void *ptr
)
7944 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
7945 if (cu
->method_list
!= NULL
)
7947 VEC_free (delayed_method_info
, cu
->method_list
);
7948 cu
->method_list
= NULL
;
7952 /* Compute the physnames of any methods on the CU's method list.
7954 The computation of method physnames is delayed in order to avoid the
7955 (bad) condition that one of the method's formal parameters is of an as yet
7959 compute_delayed_physnames (struct dwarf2_cu
*cu
)
7962 struct delayed_method_info
*mi
;
7963 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
7965 const char *physname
;
7966 struct fn_fieldlist
*fn_flp
7967 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
7968 physname
= dwarf2_physname (mi
->name
, mi
->die
, cu
);
7969 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
->index
)
7970 = physname
? physname
: "";
7974 /* Go objects should be embedded in a DW_TAG_module DIE,
7975 and it's not clear if/how imported objects will appear.
7976 To keep Go support simple until that's worked out,
7977 go back through what we've read and create something usable.
7978 We could do this while processing each DIE, and feels kinda cleaner,
7979 but that way is more invasive.
7980 This is to, for example, allow the user to type "p var" or "b main"
7981 without having to specify the package name, and allow lookups
7982 of module.object to work in contexts that use the expression
7986 fixup_go_packaging (struct dwarf2_cu
*cu
)
7988 char *package_name
= NULL
;
7989 struct pending
*list
;
7992 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
7994 for (i
= 0; i
< list
->nsyms
; ++i
)
7996 struct symbol
*sym
= list
->symbol
[i
];
7998 if (SYMBOL_LANGUAGE (sym
) == language_go
7999 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
8001 char *this_package_name
= go_symbol_package_name (sym
);
8003 if (this_package_name
== NULL
)
8005 if (package_name
== NULL
)
8006 package_name
= this_package_name
;
8009 if (strcmp (package_name
, this_package_name
) != 0)
8010 complaint (&symfile_complaints
,
8011 _("Symtab %s has objects from two different Go packages: %s and %s"),
8012 (symbol_symtab (sym
) != NULL
8013 ? symtab_to_filename_for_display
8014 (symbol_symtab (sym
))
8015 : objfile_name (cu
->objfile
)),
8016 this_package_name
, package_name
);
8017 xfree (this_package_name
);
8023 if (package_name
!= NULL
)
8025 struct objfile
*objfile
= cu
->objfile
;
8026 const char *saved_package_name
8027 = (const char *) obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
8029 strlen (package_name
));
8030 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
8031 saved_package_name
);
8034 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8036 sym
= allocate_symbol (objfile
);
8037 SYMBOL_SET_LANGUAGE (sym
, language_go
, &objfile
->objfile_obstack
);
8038 SYMBOL_SET_NAMES (sym
, saved_package_name
,
8039 strlen (saved_package_name
), 0, objfile
);
8040 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
8041 e.g., "main" finds the "main" module and not C's main(). */
8042 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
8043 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
8044 SYMBOL_TYPE (sym
) = type
;
8046 add_symbol_to_list (sym
, &global_symbols
);
8048 xfree (package_name
);
8052 /* Return the symtab for PER_CU. This works properly regardless of
8053 whether we're using the index or psymtabs. */
8055 static struct compunit_symtab
*
8056 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
8058 return (dwarf2_per_objfile
->using_index
8059 ? per_cu
->v
.quick
->compunit_symtab
8060 : per_cu
->v
.psymtab
->compunit_symtab
);
8063 /* A helper function for computing the list of all symbol tables
8064 included by PER_CU. */
8067 recursively_compute_inclusions (VEC (compunit_symtab_ptr
) **result
,
8068 htab_t all_children
, htab_t all_type_symtabs
,
8069 struct dwarf2_per_cu_data
*per_cu
,
8070 struct compunit_symtab
*immediate_parent
)
8074 struct compunit_symtab
*cust
;
8075 struct dwarf2_per_cu_data
*iter
;
8077 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
8080 /* This inclusion and its children have been processed. */
8085 /* Only add a CU if it has a symbol table. */
8086 cust
= get_compunit_symtab (per_cu
);
8089 /* If this is a type unit only add its symbol table if we haven't
8090 seen it yet (type unit per_cu's can share symtabs). */
8091 if (per_cu
->is_debug_types
)
8093 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
8097 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
8098 if (cust
->user
== NULL
)
8099 cust
->user
= immediate_parent
;
8104 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
8105 if (cust
->user
== NULL
)
8106 cust
->user
= immediate_parent
;
8111 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, ix
, iter
);
8114 recursively_compute_inclusions (result
, all_children
,
8115 all_type_symtabs
, iter
, cust
);
8119 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
8123 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
8125 gdb_assert (! per_cu
->is_debug_types
);
8127 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
))
8130 struct dwarf2_per_cu_data
*per_cu_iter
;
8131 struct compunit_symtab
*compunit_symtab_iter
;
8132 VEC (compunit_symtab_ptr
) *result_symtabs
= NULL
;
8133 htab_t all_children
, all_type_symtabs
;
8134 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
8136 /* If we don't have a symtab, we can just skip this case. */
8140 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
8141 NULL
, xcalloc
, xfree
);
8142 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
8143 NULL
, xcalloc
, xfree
);
8146 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
,
8150 recursively_compute_inclusions (&result_symtabs
, all_children
,
8151 all_type_symtabs
, per_cu_iter
,
8155 /* Now we have a transitive closure of all the included symtabs. */
8156 len
= VEC_length (compunit_symtab_ptr
, result_symtabs
);
8158 = XOBNEWVEC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
8159 struct compunit_symtab
*, len
+ 1);
8161 VEC_iterate (compunit_symtab_ptr
, result_symtabs
, ix
,
8162 compunit_symtab_iter
);
8164 cust
->includes
[ix
] = compunit_symtab_iter
;
8165 cust
->includes
[len
] = NULL
;
8167 VEC_free (compunit_symtab_ptr
, result_symtabs
);
8168 htab_delete (all_children
);
8169 htab_delete (all_type_symtabs
);
8173 /* Compute the 'includes' field for the symtabs of all the CUs we just
8177 process_cu_includes (void)
8180 struct dwarf2_per_cu_data
*iter
;
8183 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
8187 if (! iter
->is_debug_types
)
8188 compute_compunit_symtab_includes (iter
);
8191 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
8194 /* Generate full symbol information for PER_CU, whose DIEs have
8195 already been loaded into memory. */
8198 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8199 enum language pretend_language
)
8201 struct dwarf2_cu
*cu
= per_cu
->cu
;
8202 struct objfile
*objfile
= per_cu
->objfile
;
8203 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8204 CORE_ADDR lowpc
, highpc
;
8205 struct compunit_symtab
*cust
;
8206 struct cleanup
*back_to
, *delayed_list_cleanup
;
8208 struct block
*static_block
;
8211 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8214 back_to
= make_cleanup (really_free_pendings
, NULL
);
8215 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
8217 cu
->list_in_scope
= &file_symbols
;
8219 cu
->language
= pretend_language
;
8220 cu
->language_defn
= language_def (cu
->language
);
8222 /* Do line number decoding in read_file_scope () */
8223 process_die (cu
->dies
, cu
);
8225 /* For now fudge the Go package. */
8226 if (cu
->language
== language_go
)
8227 fixup_go_packaging (cu
);
8229 /* Now that we have processed all the DIEs in the CU, all the types
8230 should be complete, and it should now be safe to compute all of the
8232 compute_delayed_physnames (cu
);
8233 do_cleanups (delayed_list_cleanup
);
8235 /* Some compilers don't define a DW_AT_high_pc attribute for the
8236 compilation unit. If the DW_AT_high_pc is missing, synthesize
8237 it, by scanning the DIE's below the compilation unit. */
8238 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
8240 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
8241 static_block
= end_symtab_get_static_block (addr
, 0, 1);
8243 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
8244 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
8245 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
8246 addrmap to help ensure it has an accurate map of pc values belonging to
8248 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
8250 cust
= end_symtab_from_static_block (static_block
,
8251 SECT_OFF_TEXT (objfile
), 0);
8255 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
8257 /* Set symtab language to language from DW_AT_language. If the
8258 compilation is from a C file generated by language preprocessors, do
8259 not set the language if it was already deduced by start_subfile. */
8260 if (!(cu
->language
== language_c
8261 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
8262 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
8264 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
8265 produce DW_AT_location with location lists but it can be possibly
8266 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
8267 there were bugs in prologue debug info, fixed later in GCC-4.5
8268 by "unwind info for epilogues" patch (which is not directly related).
8270 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
8271 needed, it would be wrong due to missing DW_AT_producer there.
8273 Still one can confuse GDB by using non-standard GCC compilation
8274 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
8276 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
8277 cust
->locations_valid
= 1;
8279 if (gcc_4_minor
>= 5)
8280 cust
->epilogue_unwind_valid
= 1;
8282 cust
->call_site_htab
= cu
->call_site_htab
;
8285 if (dwarf2_per_objfile
->using_index
)
8286 per_cu
->v
.quick
->compunit_symtab
= cust
;
8289 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8290 pst
->compunit_symtab
= cust
;
8294 /* Push it for inclusion processing later. */
8295 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
8297 do_cleanups (back_to
);
8300 /* Generate full symbol information for type unit PER_CU, whose DIEs have
8301 already been loaded into memory. */
8304 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
8305 enum language pretend_language
)
8307 struct dwarf2_cu
*cu
= per_cu
->cu
;
8308 struct objfile
*objfile
= per_cu
->objfile
;
8309 struct compunit_symtab
*cust
;
8310 struct cleanup
*back_to
, *delayed_list_cleanup
;
8311 struct signatured_type
*sig_type
;
8313 gdb_assert (per_cu
->is_debug_types
);
8314 sig_type
= (struct signatured_type
*) per_cu
;
8317 back_to
= make_cleanup (really_free_pendings
, NULL
);
8318 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
8320 cu
->list_in_scope
= &file_symbols
;
8322 cu
->language
= pretend_language
;
8323 cu
->language_defn
= language_def (cu
->language
);
8325 /* The symbol tables are set up in read_type_unit_scope. */
8326 process_die (cu
->dies
, cu
);
8328 /* For now fudge the Go package. */
8329 if (cu
->language
== language_go
)
8330 fixup_go_packaging (cu
);
8332 /* Now that we have processed all the DIEs in the CU, all the types
8333 should be complete, and it should now be safe to compute all of the
8335 compute_delayed_physnames (cu
);
8336 do_cleanups (delayed_list_cleanup
);
8338 /* TUs share symbol tables.
8339 If this is the first TU to use this symtab, complete the construction
8340 of it with end_expandable_symtab. Otherwise, complete the addition of
8341 this TU's symbols to the existing symtab. */
8342 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
8344 cust
= end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
8345 sig_type
->type_unit_group
->compunit_symtab
= cust
;
8349 /* Set symtab language to language from DW_AT_language. If the
8350 compilation is from a C file generated by language preprocessors,
8351 do not set the language if it was already deduced by
8353 if (!(cu
->language
== language_c
8354 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
8355 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
8360 augment_type_symtab ();
8361 cust
= sig_type
->type_unit_group
->compunit_symtab
;
8364 if (dwarf2_per_objfile
->using_index
)
8365 per_cu
->v
.quick
->compunit_symtab
= cust
;
8368 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8369 pst
->compunit_symtab
= cust
;
8373 do_cleanups (back_to
);
8376 /* Process an imported unit DIE. */
8379 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
8381 struct attribute
*attr
;
8383 /* For now we don't handle imported units in type units. */
8384 if (cu
->per_cu
->is_debug_types
)
8386 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8387 " supported in type units [in module %s]"),
8388 objfile_name (cu
->objfile
));
8391 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
8394 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
8395 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
8396 dwarf2_per_cu_data
*per_cu
8397 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, cu
->objfile
);
8399 /* If necessary, add it to the queue and load its DIEs. */
8400 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
8401 load_full_comp_unit (per_cu
, cu
->language
);
8403 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
8408 /* Reset the in_process bit of a die. */
8411 reset_die_in_process (void *arg
)
8413 struct die_info
*die
= (struct die_info
*) arg
;
8415 die
->in_process
= 0;
8418 /* Process a die and its children. */
8421 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
8423 struct cleanup
*in_process
;
8425 /* We should only be processing those not already in process. */
8426 gdb_assert (!die
->in_process
);
8428 die
->in_process
= 1;
8429 in_process
= make_cleanup (reset_die_in_process
,die
);
8433 case DW_TAG_padding
:
8435 case DW_TAG_compile_unit
:
8436 case DW_TAG_partial_unit
:
8437 read_file_scope (die
, cu
);
8439 case DW_TAG_type_unit
:
8440 read_type_unit_scope (die
, cu
);
8442 case DW_TAG_subprogram
:
8443 case DW_TAG_inlined_subroutine
:
8444 read_func_scope (die
, cu
);
8446 case DW_TAG_lexical_block
:
8447 case DW_TAG_try_block
:
8448 case DW_TAG_catch_block
:
8449 read_lexical_block_scope (die
, cu
);
8451 case DW_TAG_call_site
:
8452 case DW_TAG_GNU_call_site
:
8453 read_call_site_scope (die
, cu
);
8455 case DW_TAG_class_type
:
8456 case DW_TAG_interface_type
:
8457 case DW_TAG_structure_type
:
8458 case DW_TAG_union_type
:
8459 process_structure_scope (die
, cu
);
8461 case DW_TAG_enumeration_type
:
8462 process_enumeration_scope (die
, cu
);
8465 /* These dies have a type, but processing them does not create
8466 a symbol or recurse to process the children. Therefore we can
8467 read them on-demand through read_type_die. */
8468 case DW_TAG_subroutine_type
:
8469 case DW_TAG_set_type
:
8470 case DW_TAG_array_type
:
8471 case DW_TAG_pointer_type
:
8472 case DW_TAG_ptr_to_member_type
:
8473 case DW_TAG_reference_type
:
8474 case DW_TAG_rvalue_reference_type
:
8475 case DW_TAG_string_type
:
8478 case DW_TAG_base_type
:
8479 case DW_TAG_subrange_type
:
8480 case DW_TAG_typedef
:
8481 /* Add a typedef symbol for the type definition, if it has a
8483 new_symbol (die
, read_type_die (die
, cu
), cu
);
8485 case DW_TAG_common_block
:
8486 read_common_block (die
, cu
);
8488 case DW_TAG_common_inclusion
:
8490 case DW_TAG_namespace
:
8491 cu
->processing_has_namespace_info
= 1;
8492 read_namespace (die
, cu
);
8495 cu
->processing_has_namespace_info
= 1;
8496 read_module (die
, cu
);
8498 case DW_TAG_imported_declaration
:
8499 cu
->processing_has_namespace_info
= 1;
8500 if (read_namespace_alias (die
, cu
))
8502 /* The declaration is not a global namespace alias: fall through. */
8503 case DW_TAG_imported_module
:
8504 cu
->processing_has_namespace_info
= 1;
8505 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
8506 || cu
->language
!= language_fortran
))
8507 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
8508 dwarf_tag_name (die
->tag
));
8509 read_import_statement (die
, cu
);
8512 case DW_TAG_imported_unit
:
8513 process_imported_unit_die (die
, cu
);
8517 new_symbol (die
, NULL
, cu
);
8521 do_cleanups (in_process
);
8524 /* DWARF name computation. */
8526 /* A helper function for dwarf2_compute_name which determines whether DIE
8527 needs to have the name of the scope prepended to the name listed in the
8531 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
8533 struct attribute
*attr
;
8537 case DW_TAG_namespace
:
8538 case DW_TAG_typedef
:
8539 case DW_TAG_class_type
:
8540 case DW_TAG_interface_type
:
8541 case DW_TAG_structure_type
:
8542 case DW_TAG_union_type
:
8543 case DW_TAG_enumeration_type
:
8544 case DW_TAG_enumerator
:
8545 case DW_TAG_subprogram
:
8546 case DW_TAG_inlined_subroutine
:
8548 case DW_TAG_imported_declaration
:
8551 case DW_TAG_variable
:
8552 case DW_TAG_constant
:
8553 /* We only need to prefix "globally" visible variables. These include
8554 any variable marked with DW_AT_external or any variable that
8555 lives in a namespace. [Variables in anonymous namespaces
8556 require prefixing, but they are not DW_AT_external.] */
8558 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
8560 struct dwarf2_cu
*spec_cu
= cu
;
8562 return die_needs_namespace (die_specification (die
, &spec_cu
),
8566 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
8567 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
8568 && die
->parent
->tag
!= DW_TAG_module
)
8570 /* A variable in a lexical block of some kind does not need a
8571 namespace, even though in C++ such variables may be external
8572 and have a mangled name. */
8573 if (die
->parent
->tag
== DW_TAG_lexical_block
8574 || die
->parent
->tag
== DW_TAG_try_block
8575 || die
->parent
->tag
== DW_TAG_catch_block
8576 || die
->parent
->tag
== DW_TAG_subprogram
)
8585 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
8586 compute the physname for the object, which include a method's:
8587 - formal parameters (C++),
8588 - receiver type (Go),
8590 The term "physname" is a bit confusing.
8591 For C++, for example, it is the demangled name.
8592 For Go, for example, it's the mangled name.
8594 For Ada, return the DIE's linkage name rather than the fully qualified
8595 name. PHYSNAME is ignored..
8597 The result is allocated on the objfile_obstack and canonicalized. */
8600 dwarf2_compute_name (const char *name
,
8601 struct die_info
*die
, struct dwarf2_cu
*cu
,
8604 struct objfile
*objfile
= cu
->objfile
;
8607 name
= dwarf2_name (die
, cu
);
8609 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
8610 but otherwise compute it by typename_concat inside GDB.
8611 FIXME: Actually this is not really true, or at least not always true.
8612 It's all very confusing. SYMBOL_SET_NAMES doesn't try to demangle
8613 Fortran names because there is no mangling standard. So new_symbol_full
8614 will set the demangled name to the result of dwarf2_full_name, and it is
8615 the demangled name that GDB uses if it exists. */
8616 if (cu
->language
== language_ada
8617 || (cu
->language
== language_fortran
&& physname
))
8619 /* For Ada unit, we prefer the linkage name over the name, as
8620 the former contains the exported name, which the user expects
8621 to be able to reference. Ideally, we want the user to be able
8622 to reference this entity using either natural or linkage name,
8623 but we haven't started looking at this enhancement yet. */
8624 const char *linkage_name
;
8626 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
8627 if (linkage_name
== NULL
)
8628 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8629 if (linkage_name
!= NULL
)
8630 return linkage_name
;
8633 /* These are the only languages we know how to qualify names in. */
8635 && (cu
->language
== language_cplus
8636 || cu
->language
== language_fortran
|| cu
->language
== language_d
8637 || cu
->language
== language_rust
))
8639 if (die_needs_namespace (die
, cu
))
8643 const char *canonical_name
= NULL
;
8647 prefix
= determine_prefix (die
, cu
);
8648 if (*prefix
!= '\0')
8650 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
8653 buf
.puts (prefixed_name
);
8654 xfree (prefixed_name
);
8659 /* Template parameters may be specified in the DIE's DW_AT_name, or
8660 as children with DW_TAG_template_type_param or
8661 DW_TAG_value_type_param. If the latter, add them to the name
8662 here. If the name already has template parameters, then
8663 skip this step; some versions of GCC emit both, and
8664 it is more efficient to use the pre-computed name.
8666 Something to keep in mind about this process: it is very
8667 unlikely, or in some cases downright impossible, to produce
8668 something that will match the mangled name of a function.
8669 If the definition of the function has the same debug info,
8670 we should be able to match up with it anyway. But fallbacks
8671 using the minimal symbol, for instance to find a method
8672 implemented in a stripped copy of libstdc++, will not work.
8673 If we do not have debug info for the definition, we will have to
8674 match them up some other way.
8676 When we do name matching there is a related problem with function
8677 templates; two instantiated function templates are allowed to
8678 differ only by their return types, which we do not add here. */
8680 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
8682 struct attribute
*attr
;
8683 struct die_info
*child
;
8686 die
->building_fullname
= 1;
8688 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
8692 const gdb_byte
*bytes
;
8693 struct dwarf2_locexpr_baton
*baton
;
8696 if (child
->tag
!= DW_TAG_template_type_param
8697 && child
->tag
!= DW_TAG_template_value_param
)
8708 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
8711 complaint (&symfile_complaints
,
8712 _("template parameter missing DW_AT_type"));
8713 buf
.puts ("UNKNOWN_TYPE");
8716 type
= die_type (child
, cu
);
8718 if (child
->tag
== DW_TAG_template_type_param
)
8720 c_print_type (type
, "", &buf
, -1, 0, &type_print_raw_options
);
8724 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
8727 complaint (&symfile_complaints
,
8728 _("template parameter missing "
8729 "DW_AT_const_value"));
8730 buf
.puts ("UNKNOWN_VALUE");
8734 dwarf2_const_value_attr (attr
, type
, name
,
8735 &cu
->comp_unit_obstack
, cu
,
8736 &value
, &bytes
, &baton
);
8738 if (TYPE_NOSIGN (type
))
8739 /* GDB prints characters as NUMBER 'CHAR'. If that's
8740 changed, this can use value_print instead. */
8741 c_printchar (value
, type
, &buf
);
8744 struct value_print_options opts
;
8747 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
8751 else if (bytes
!= NULL
)
8753 v
= allocate_value (type
);
8754 memcpy (value_contents_writeable (v
), bytes
,
8755 TYPE_LENGTH (type
));
8758 v
= value_from_longest (type
, value
);
8760 /* Specify decimal so that we do not depend on
8762 get_formatted_print_options (&opts
, 'd');
8764 value_print (v
, &buf
, &opts
);
8770 die
->building_fullname
= 0;
8774 /* Close the argument list, with a space if necessary
8775 (nested templates). */
8776 if (!buf
.empty () && buf
.string ().back () == '>')
8783 /* For C++ methods, append formal parameter type
8784 information, if PHYSNAME. */
8786 if (physname
&& die
->tag
== DW_TAG_subprogram
8787 && cu
->language
== language_cplus
)
8789 struct type
*type
= read_type_die (die
, cu
);
8791 c_type_print_args (type
, &buf
, 1, cu
->language
,
8792 &type_print_raw_options
);
8794 if (cu
->language
== language_cplus
)
8796 /* Assume that an artificial first parameter is
8797 "this", but do not crash if it is not. RealView
8798 marks unnamed (and thus unused) parameters as
8799 artificial; there is no way to differentiate
8801 if (TYPE_NFIELDS (type
) > 0
8802 && TYPE_FIELD_ARTIFICIAL (type
, 0)
8803 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
8804 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
8806 buf
.puts (" const");
8810 const std::string
&intermediate_name
= buf
.string ();
8812 if (cu
->language
== language_cplus
)
8814 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
8815 &objfile
->per_bfd
->storage_obstack
);
8817 /* If we only computed INTERMEDIATE_NAME, or if
8818 INTERMEDIATE_NAME is already canonical, then we need to
8819 copy it to the appropriate obstack. */
8820 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
8821 name
= ((const char *)
8822 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
8823 intermediate_name
.c_str (),
8824 intermediate_name
.length ()));
8826 name
= canonical_name
;
8833 /* Return the fully qualified name of DIE, based on its DW_AT_name.
8834 If scope qualifiers are appropriate they will be added. The result
8835 will be allocated on the storage_obstack, or NULL if the DIE does
8836 not have a name. NAME may either be from a previous call to
8837 dwarf2_name or NULL.
8839 The output string will be canonicalized (if C++). */
8842 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
8844 return dwarf2_compute_name (name
, die
, cu
, 0);
8847 /* Construct a physname for the given DIE in CU. NAME may either be
8848 from a previous call to dwarf2_name or NULL. The result will be
8849 allocated on the objfile_objstack or NULL if the DIE does not have a
8852 The output string will be canonicalized (if C++). */
8855 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
8857 struct objfile
*objfile
= cu
->objfile
;
8858 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
8859 struct cleanup
*back_to
;
8862 /* In this case dwarf2_compute_name is just a shortcut not building anything
8864 if (!die_needs_namespace (die
, cu
))
8865 return dwarf2_compute_name (name
, die
, cu
, 1);
8867 back_to
= make_cleanup (null_cleanup
, NULL
);
8869 mangled
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
8870 if (mangled
== NULL
)
8871 mangled
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8873 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
8874 See https://github.com/rust-lang/rust/issues/32925. */
8875 if (cu
->language
== language_rust
&& mangled
!= NULL
8876 && strchr (mangled
, '{') != NULL
)
8879 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
8881 if (mangled
!= NULL
)
8885 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
8886 type. It is easier for GDB users to search for such functions as
8887 `name(params)' than `long name(params)'. In such case the minimal
8888 symbol names do not match the full symbol names but for template
8889 functions there is never a need to look up their definition from their
8890 declaration so the only disadvantage remains the minimal symbol
8891 variant `long name(params)' does not have the proper inferior type.
8894 if (cu
->language
== language_go
)
8896 /* This is a lie, but we already lie to the caller new_symbol_full.
8897 new_symbol_full assumes we return the mangled name.
8898 This just undoes that lie until things are cleaned up. */
8903 demangled
= gdb_demangle (mangled
,
8904 (DMGL_PARAMS
| DMGL_ANSI
| DMGL_RET_DROP
));
8908 make_cleanup (xfree
, demangled
);
8918 if (canon
== NULL
|| check_physname
)
8920 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
8922 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
8924 /* It may not mean a bug in GDB. The compiler could also
8925 compute DW_AT_linkage_name incorrectly. But in such case
8926 GDB would need to be bug-to-bug compatible. */
8928 complaint (&symfile_complaints
,
8929 _("Computed physname <%s> does not match demangled <%s> "
8930 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
8931 physname
, canon
, mangled
, to_underlying (die
->sect_off
),
8932 objfile_name (objfile
));
8934 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
8935 is available here - over computed PHYSNAME. It is safer
8936 against both buggy GDB and buggy compilers. */
8950 retval
= ((const char *)
8951 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
8952 retval
, strlen (retval
)));
8954 do_cleanups (back_to
);
8958 /* Inspect DIE in CU for a namespace alias. If one exists, record
8959 a new symbol for it.
8961 Returns 1 if a namespace alias was recorded, 0 otherwise. */
8964 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
8966 struct attribute
*attr
;
8968 /* If the die does not have a name, this is not a namespace
8970 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8974 struct die_info
*d
= die
;
8975 struct dwarf2_cu
*imported_cu
= cu
;
8977 /* If the compiler has nested DW_AT_imported_declaration DIEs,
8978 keep inspecting DIEs until we hit the underlying import. */
8979 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
8980 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
8982 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
8986 d
= follow_die_ref (d
, attr
, &imported_cu
);
8987 if (d
->tag
!= DW_TAG_imported_declaration
)
8991 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
8993 complaint (&symfile_complaints
,
8994 _("DIE at 0x%x has too many recursively imported "
8995 "declarations"), to_underlying (d
->sect_off
));
9002 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
9004 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
9005 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
9007 /* This declaration is a global namespace alias. Add
9008 a symbol for it whose type is the aliased namespace. */
9009 new_symbol (die
, type
, cu
);
9018 /* Return the using directives repository (global or local?) to use in the
9019 current context for LANGUAGE.
9021 For Ada, imported declarations can materialize renamings, which *may* be
9022 global. However it is impossible (for now?) in DWARF to distinguish
9023 "external" imported declarations and "static" ones. As all imported
9024 declarations seem to be static in all other languages, make them all CU-wide
9025 global only in Ada. */
9027 static struct using_direct
**
9028 using_directives (enum language language
)
9030 if (language
== language_ada
&& context_stack_depth
== 0)
9031 return &global_using_directives
;
9033 return &local_using_directives
;
9036 /* Read the import statement specified by the given die and record it. */
9039 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
9041 struct objfile
*objfile
= cu
->objfile
;
9042 struct attribute
*import_attr
;
9043 struct die_info
*imported_die
, *child_die
;
9044 struct dwarf2_cu
*imported_cu
;
9045 const char *imported_name
;
9046 const char *imported_name_prefix
;
9047 const char *canonical_name
;
9048 const char *import_alias
;
9049 const char *imported_declaration
= NULL
;
9050 const char *import_prefix
;
9051 VEC (const_char_ptr
) *excludes
= NULL
;
9052 struct cleanup
*cleanups
;
9054 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9055 if (import_attr
== NULL
)
9057 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
9058 dwarf_tag_name (die
->tag
));
9063 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
9064 imported_name
= dwarf2_name (imported_die
, imported_cu
);
9065 if (imported_name
== NULL
)
9067 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
9069 The import in the following code:
9083 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
9084 <52> DW_AT_decl_file : 1
9085 <53> DW_AT_decl_line : 6
9086 <54> DW_AT_import : <0x75>
9087 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
9089 <5b> DW_AT_decl_file : 1
9090 <5c> DW_AT_decl_line : 2
9091 <5d> DW_AT_type : <0x6e>
9093 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
9094 <76> DW_AT_byte_size : 4
9095 <77> DW_AT_encoding : 5 (signed)
9097 imports the wrong die ( 0x75 instead of 0x58 ).
9098 This case will be ignored until the gcc bug is fixed. */
9102 /* Figure out the local name after import. */
9103 import_alias
= dwarf2_name (die
, cu
);
9105 /* Figure out where the statement is being imported to. */
9106 import_prefix
= determine_prefix (die
, cu
);
9108 /* Figure out what the scope of the imported die is and prepend it
9109 to the name of the imported die. */
9110 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
9112 if (imported_die
->tag
!= DW_TAG_namespace
9113 && imported_die
->tag
!= DW_TAG_module
)
9115 imported_declaration
= imported_name
;
9116 canonical_name
= imported_name_prefix
;
9118 else if (strlen (imported_name_prefix
) > 0)
9119 canonical_name
= obconcat (&objfile
->objfile_obstack
,
9120 imported_name_prefix
,
9121 (cu
->language
== language_d
? "." : "::"),
9122 imported_name
, (char *) NULL
);
9124 canonical_name
= imported_name
;
9126 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
9128 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
9129 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
9130 child_die
= sibling_die (child_die
))
9132 /* DWARF-4: A Fortran use statement with a “rename list” may be
9133 represented by an imported module entry with an import attribute
9134 referring to the module and owned entries corresponding to those
9135 entities that are renamed as part of being imported. */
9137 if (child_die
->tag
!= DW_TAG_imported_declaration
)
9139 complaint (&symfile_complaints
,
9140 _("child DW_TAG_imported_declaration expected "
9141 "- DIE at 0x%x [in module %s]"),
9142 to_underlying (child_die
->sect_off
), objfile_name (objfile
));
9146 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
9147 if (import_attr
== NULL
)
9149 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
9150 dwarf_tag_name (child_die
->tag
));
9155 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
9157 imported_name
= dwarf2_name (imported_die
, imported_cu
);
9158 if (imported_name
== NULL
)
9160 complaint (&symfile_complaints
,
9161 _("child DW_TAG_imported_declaration has unknown "
9162 "imported name - DIE at 0x%x [in module %s]"),
9163 to_underlying (child_die
->sect_off
), objfile_name (objfile
));
9167 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
9169 process_die (child_die
, cu
);
9172 add_using_directive (using_directives (cu
->language
),
9176 imported_declaration
,
9179 &objfile
->objfile_obstack
);
9181 do_cleanups (cleanups
);
9184 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
9185 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
9186 this, it was first present in GCC release 4.3.0. */
9189 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
9191 if (!cu
->checked_producer
)
9192 check_producer (cu
);
9194 return cu
->producer_is_gcc_lt_4_3
;
9197 static file_and_directory
9198 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
9200 file_and_directory res
;
9202 /* Find the filename. Do not use dwarf2_name here, since the filename
9203 is not a source language identifier. */
9204 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
9205 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
9207 if (res
.comp_dir
== NULL
9208 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
9209 && IS_ABSOLUTE_PATH (res
.name
))
9211 res
.comp_dir_storage
= ldirname (res
.name
);
9212 if (!res
.comp_dir_storage
.empty ())
9213 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
9215 if (res
.comp_dir
!= NULL
)
9217 /* Irix 6.2 native cc prepends <machine>.: to the compilation
9218 directory, get rid of it. */
9219 const char *cp
= strchr (res
.comp_dir
, ':');
9221 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
9222 res
.comp_dir
= cp
+ 1;
9225 if (res
.name
== NULL
)
9226 res
.name
= "<unknown>";
9231 /* Handle DW_AT_stmt_list for a compilation unit.
9232 DIE is the DW_TAG_compile_unit die for CU.
9233 COMP_DIR is the compilation directory. LOWPC is passed to
9234 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
9237 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
9238 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
9240 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9241 struct attribute
*attr
;
9242 struct line_header line_header_local
;
9243 hashval_t line_header_local_hash
;
9248 gdb_assert (! cu
->per_cu
->is_debug_types
);
9250 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
9254 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
9256 /* The line header hash table is only created if needed (it exists to
9257 prevent redundant reading of the line table for partial_units).
9258 If we're given a partial_unit, we'll need it. If we're given a
9259 compile_unit, then use the line header hash table if it's already
9260 created, but don't create one just yet. */
9262 if (dwarf2_per_objfile
->line_header_hash
== NULL
9263 && die
->tag
== DW_TAG_partial_unit
)
9265 dwarf2_per_objfile
->line_header_hash
9266 = htab_create_alloc_ex (127, line_header_hash_voidp
,
9267 line_header_eq_voidp
,
9268 free_line_header_voidp
,
9269 &objfile
->objfile_obstack
,
9270 hashtab_obstack_allocate
,
9271 dummy_obstack_deallocate
);
9274 line_header_local
.sect_off
= line_offset
;
9275 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
9276 line_header_local_hash
= line_header_hash (&line_header_local
);
9277 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
9279 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
9281 line_header_local_hash
, NO_INSERT
);
9283 /* For DW_TAG_compile_unit we need info like symtab::linetable which
9284 is not present in *SLOT (since if there is something in *SLOT then
9285 it will be for a partial_unit). */
9286 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
9288 gdb_assert (*slot
!= NULL
);
9289 cu
->line_header
= (struct line_header
*) *slot
;
9294 /* dwarf_decode_line_header does not yet provide sufficient information.
9295 We always have to call also dwarf_decode_lines for it. */
9296 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
9299 cu
->line_header
= lh
.get ();
9301 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
9305 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
9307 line_header_local_hash
, INSERT
);
9308 gdb_assert (slot
!= NULL
);
9310 if (slot
!= NULL
&& *slot
== NULL
)
9312 /* This newly decoded line number information unit will be owned
9313 by line_header_hash hash table. */
9314 *slot
= cu
->line_header
;
9318 /* We cannot free any current entry in (*slot) as that struct line_header
9319 may be already used by multiple CUs. Create only temporary decoded
9320 line_header for this CU - it may happen at most once for each line
9321 number information unit. And if we're not using line_header_hash
9322 then this is what we want as well. */
9323 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
9325 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
9326 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
9332 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
9335 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9337 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9338 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9339 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
9340 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
9341 struct attribute
*attr
;
9342 struct die_info
*child_die
;
9345 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9347 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
9349 /* If we didn't find a lowpc, set it to highpc to avoid complaints
9350 from finish_block. */
9351 if (lowpc
== ((CORE_ADDR
) -1))
9353 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
9355 file_and_directory fnd
= find_file_and_directory (die
, cu
);
9357 prepare_one_comp_unit (cu
, die
, cu
->language
);
9359 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
9360 standardised yet. As a workaround for the language detection we fall
9361 back to the DW_AT_producer string. */
9362 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
9363 cu
->language
= language_opencl
;
9365 /* Similar hack for Go. */
9366 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
9367 set_cu_language (DW_LANG_Go
, cu
);
9369 dwarf2_start_symtab (cu
, fnd
.name
, fnd
.comp_dir
, lowpc
);
9371 /* Decode line number information if present. We do this before
9372 processing child DIEs, so that the line header table is available
9373 for DW_AT_decl_file. */
9374 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
9376 /* Process all dies in compilation unit. */
9377 if (die
->child
!= NULL
)
9379 child_die
= die
->child
;
9380 while (child_die
&& child_die
->tag
)
9382 process_die (child_die
, cu
);
9383 child_die
= sibling_die (child_die
);
9387 /* Decode macro information, if present. Dwarf 2 macro information
9388 refers to information in the line number info statement program
9389 header, so we can only read it if we've read the header
9391 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
9393 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
9394 if (attr
&& cu
->line_header
)
9396 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
9397 complaint (&symfile_complaints
,
9398 _("CU refers to both DW_AT_macros and DW_AT_macro_info"));
9400 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
9404 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
9405 if (attr
&& cu
->line_header
)
9407 unsigned int macro_offset
= DW_UNSND (attr
);
9409 dwarf_decode_macros (cu
, macro_offset
, 0);
9414 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
9415 Create the set of symtabs used by this TU, or if this TU is sharing
9416 symtabs with another TU and the symtabs have already been created
9417 then restore those symtabs in the line header.
9418 We don't need the pc/line-number mapping for type units. */
9421 setup_type_unit_groups (struct die_info
*die
, struct dwarf2_cu
*cu
)
9423 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
9424 struct type_unit_group
*tu_group
;
9426 struct attribute
*attr
;
9428 struct signatured_type
*sig_type
;
9430 gdb_assert (per_cu
->is_debug_types
);
9431 sig_type
= (struct signatured_type
*) per_cu
;
9433 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
9435 /* If we're using .gdb_index (includes -readnow) then
9436 per_cu->type_unit_group may not have been set up yet. */
9437 if (sig_type
->type_unit_group
== NULL
)
9438 sig_type
->type_unit_group
= get_type_unit_group (cu
, attr
);
9439 tu_group
= sig_type
->type_unit_group
;
9441 /* If we've already processed this stmt_list there's no real need to
9442 do it again, we could fake it and just recreate the part we need
9443 (file name,index -> symtab mapping). If data shows this optimization
9444 is useful we can do it then. */
9445 first_time
= tu_group
->compunit_symtab
== NULL
;
9447 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
9452 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
9453 lh
= dwarf_decode_line_header (line_offset
, cu
);
9458 dwarf2_start_symtab (cu
, "", NULL
, 0);
9461 gdb_assert (tu_group
->symtabs
== NULL
);
9462 restart_symtab (tu_group
->compunit_symtab
, "", 0);
9467 cu
->line_header
= lh
.get ();
9471 struct compunit_symtab
*cust
= dwarf2_start_symtab (cu
, "", NULL
, 0);
9473 /* Note: We don't assign tu_group->compunit_symtab yet because we're
9474 still initializing it, and our caller (a few levels up)
9475 process_full_type_unit still needs to know if this is the first
9478 tu_group
->num_symtabs
= lh
->file_names
.size ();
9479 tu_group
->symtabs
= XNEWVEC (struct symtab
*, lh
->file_names
.size ());
9481 for (i
= 0; i
< lh
->file_names
.size (); ++i
)
9483 file_entry
&fe
= lh
->file_names
[i
];
9485 dwarf2_start_subfile (fe
.name
, fe
.include_dir (lh
.get ()));
9487 if (current_subfile
->symtab
== NULL
)
9489 /* NOTE: start_subfile will recognize when it's been passed
9490 a file it has already seen. So we can't assume there's a
9491 simple mapping from lh->file_names to subfiles, plus
9492 lh->file_names may contain dups. */
9493 current_subfile
->symtab
9494 = allocate_symtab (cust
, current_subfile
->name
);
9497 fe
.symtab
= current_subfile
->symtab
;
9498 tu_group
->symtabs
[i
] = fe
.symtab
;
9503 restart_symtab (tu_group
->compunit_symtab
, "", 0);
9505 for (i
= 0; i
< lh
->file_names
.size (); ++i
)
9507 struct file_entry
*fe
= &lh
->file_names
[i
];
9509 fe
->symtab
= tu_group
->symtabs
[i
];
9515 /* The main symtab is allocated last. Type units don't have DW_AT_name
9516 so they don't have a "real" (so to speak) symtab anyway.
9517 There is later code that will assign the main symtab to all symbols
9518 that don't have one. We need to handle the case of a symbol with a
9519 missing symtab (DW_AT_decl_file) anyway. */
9522 /* Process DW_TAG_type_unit.
9523 For TUs we want to skip the first top level sibling if it's not the
9524 actual type being defined by this TU. In this case the first top
9525 level sibling is there to provide context only. */
9528 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9530 struct die_info
*child_die
;
9532 prepare_one_comp_unit (cu
, die
, language_minimal
);
9534 /* Initialize (or reinitialize) the machinery for building symtabs.
9535 We do this before processing child DIEs, so that the line header table
9536 is available for DW_AT_decl_file. */
9537 setup_type_unit_groups (die
, cu
);
9539 if (die
->child
!= NULL
)
9541 child_die
= die
->child
;
9542 while (child_die
&& child_die
->tag
)
9544 process_die (child_die
, cu
);
9545 child_die
= sibling_die (child_die
);
9552 http://gcc.gnu.org/wiki/DebugFission
9553 http://gcc.gnu.org/wiki/DebugFissionDWP
9555 To simplify handling of both DWO files ("object" files with the DWARF info)
9556 and DWP files (a file with the DWOs packaged up into one file), we treat
9557 DWP files as having a collection of virtual DWO files. */
9560 hash_dwo_file (const void *item
)
9562 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
9565 hash
= htab_hash_string (dwo_file
->dwo_name
);
9566 if (dwo_file
->comp_dir
!= NULL
)
9567 hash
+= htab_hash_string (dwo_file
->comp_dir
);
9572 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
9574 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
9575 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
9577 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
9579 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
9580 return lhs
->comp_dir
== rhs
->comp_dir
;
9581 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
9584 /* Allocate a hash table for DWO files. */
9587 allocate_dwo_file_hash_table (void)
9589 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9591 return htab_create_alloc_ex (41,
9595 &objfile
->objfile_obstack
,
9596 hashtab_obstack_allocate
,
9597 dummy_obstack_deallocate
);
9600 /* Lookup DWO file DWO_NAME. */
9603 lookup_dwo_file_slot (const char *dwo_name
, const char *comp_dir
)
9605 struct dwo_file find_entry
;
9608 if (dwarf2_per_objfile
->dwo_files
== NULL
)
9609 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
9611 memset (&find_entry
, 0, sizeof (find_entry
));
9612 find_entry
.dwo_name
= dwo_name
;
9613 find_entry
.comp_dir
= comp_dir
;
9614 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
9620 hash_dwo_unit (const void *item
)
9622 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
9624 /* This drops the top 32 bits of the id, but is ok for a hash. */
9625 return dwo_unit
->signature
;
9629 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
9631 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
9632 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
9634 /* The signature is assumed to be unique within the DWO file.
9635 So while object file CU dwo_id's always have the value zero,
9636 that's OK, assuming each object file DWO file has only one CU,
9637 and that's the rule for now. */
9638 return lhs
->signature
== rhs
->signature
;
9641 /* Allocate a hash table for DWO CUs,TUs.
9642 There is one of these tables for each of CUs,TUs for each DWO file. */
9645 allocate_dwo_unit_table (struct objfile
*objfile
)
9647 /* Start out with a pretty small number.
9648 Generally DWO files contain only one CU and maybe some TUs. */
9649 return htab_create_alloc_ex (3,
9653 &objfile
->objfile_obstack
,
9654 hashtab_obstack_allocate
,
9655 dummy_obstack_deallocate
);
9658 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
9660 struct create_dwo_cu_data
9662 struct dwo_file
*dwo_file
;
9663 struct dwo_unit dwo_unit
;
9666 /* die_reader_func for create_dwo_cu. */
9669 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
9670 const gdb_byte
*info_ptr
,
9671 struct die_info
*comp_unit_die
,
9675 struct dwarf2_cu
*cu
= reader
->cu
;
9676 sect_offset sect_off
= cu
->per_cu
->sect_off
;
9677 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
9678 struct create_dwo_cu_data
*data
= (struct create_dwo_cu_data
*) datap
;
9679 struct dwo_file
*dwo_file
= data
->dwo_file
;
9680 struct dwo_unit
*dwo_unit
= &data
->dwo_unit
;
9681 struct attribute
*attr
;
9683 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
9686 complaint (&symfile_complaints
,
9687 _("Dwarf Error: debug entry at offset 0x%x is missing"
9688 " its dwo_id [in module %s]"),
9689 to_underlying (sect_off
), dwo_file
->dwo_name
);
9693 dwo_unit
->dwo_file
= dwo_file
;
9694 dwo_unit
->signature
= DW_UNSND (attr
);
9695 dwo_unit
->section
= section
;
9696 dwo_unit
->sect_off
= sect_off
;
9697 dwo_unit
->length
= cu
->per_cu
->length
;
9699 if (dwarf_read_debug
)
9700 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, dwo_id %s\n",
9701 to_underlying (sect_off
),
9702 hex_string (dwo_unit
->signature
));
9705 /* Create the dwo_unit for the lone CU in DWO_FILE.
9706 Note: This function processes DWO files only, not DWP files. */
9708 static struct dwo_unit
*
9709 create_dwo_cu (struct dwo_file
*dwo_file
)
9711 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9712 struct dwarf2_section_info
*section
= &dwo_file
->sections
.info
;
9713 const gdb_byte
*info_ptr
, *end_ptr
;
9714 struct create_dwo_cu_data create_dwo_cu_data
;
9715 struct dwo_unit
*dwo_unit
;
9717 dwarf2_read_section (objfile
, section
);
9718 info_ptr
= section
->buffer
;
9720 if (info_ptr
== NULL
)
9723 if (dwarf_read_debug
)
9725 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
9726 get_section_name (section
),
9727 get_section_file_name (section
));
9730 create_dwo_cu_data
.dwo_file
= dwo_file
;
9733 end_ptr
= info_ptr
+ section
->size
;
9734 while (info_ptr
< end_ptr
)
9736 struct dwarf2_per_cu_data per_cu
;
9738 memset (&create_dwo_cu_data
.dwo_unit
, 0,
9739 sizeof (create_dwo_cu_data
.dwo_unit
));
9740 memset (&per_cu
, 0, sizeof (per_cu
));
9741 per_cu
.objfile
= objfile
;
9742 per_cu
.is_debug_types
= 0;
9743 per_cu
.sect_off
= sect_offset (info_ptr
- section
->buffer
);
9744 per_cu
.section
= section
;
9746 init_cutu_and_read_dies_no_follow (&per_cu
, dwo_file
,
9747 create_dwo_cu_reader
,
9748 &create_dwo_cu_data
);
9750 if (create_dwo_cu_data
.dwo_unit
.dwo_file
!= NULL
)
9752 /* If we've already found one, complain. We only support one
9753 because having more than one requires hacking the dwo_name of
9754 each to match, which is highly unlikely to happen. */
9755 if (dwo_unit
!= NULL
)
9757 complaint (&symfile_complaints
,
9758 _("Multiple CUs in DWO file %s [in module %s]"),
9759 dwo_file
->dwo_name
, objfile_name (objfile
));
9763 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
9764 *dwo_unit
= create_dwo_cu_data
.dwo_unit
;
9767 info_ptr
+= per_cu
.length
;
9773 /* DWP file .debug_{cu,tu}_index section format:
9774 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
9778 Both index sections have the same format, and serve to map a 64-bit
9779 signature to a set of section numbers. Each section begins with a header,
9780 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
9781 indexes, and a pool of 32-bit section numbers. The index sections will be
9782 aligned at 8-byte boundaries in the file.
9784 The index section header consists of:
9786 V, 32 bit version number
9788 N, 32 bit number of compilation units or type units in the index
9789 M, 32 bit number of slots in the hash table
9791 Numbers are recorded using the byte order of the application binary.
9793 The hash table begins at offset 16 in the section, and consists of an array
9794 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
9795 order of the application binary). Unused slots in the hash table are 0.
9796 (We rely on the extreme unlikeliness of a signature being exactly 0.)
9798 The parallel table begins immediately after the hash table
9799 (at offset 16 + 8 * M from the beginning of the section), and consists of an
9800 array of 32-bit indexes (using the byte order of the application binary),
9801 corresponding 1-1 with slots in the hash table. Each entry in the parallel
9802 table contains a 32-bit index into the pool of section numbers. For unused
9803 hash table slots, the corresponding entry in the parallel table will be 0.
9805 The pool of section numbers begins immediately following the hash table
9806 (at offset 16 + 12 * M from the beginning of the section). The pool of
9807 section numbers consists of an array of 32-bit words (using the byte order
9808 of the application binary). Each item in the array is indexed starting
9809 from 0. The hash table entry provides the index of the first section
9810 number in the set. Additional section numbers in the set follow, and the
9811 set is terminated by a 0 entry (section number 0 is not used in ELF).
9813 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
9814 section must be the first entry in the set, and the .debug_abbrev.dwo must
9815 be the second entry. Other members of the set may follow in any order.
9821 DWP Version 2 combines all the .debug_info, etc. sections into one,
9822 and the entries in the index tables are now offsets into these sections.
9823 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
9826 Index Section Contents:
9828 Hash Table of Signatures dwp_hash_table.hash_table
9829 Parallel Table of Indices dwp_hash_table.unit_table
9830 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
9831 Table of Section Sizes dwp_hash_table.v2.sizes
9833 The index section header consists of:
9835 V, 32 bit version number
9836 L, 32 bit number of columns in the table of section offsets
9837 N, 32 bit number of compilation units or type units in the index
9838 M, 32 bit number of slots in the hash table
9840 Numbers are recorded using the byte order of the application binary.
9842 The hash table has the same format as version 1.
9843 The parallel table of indices has the same format as version 1,
9844 except that the entries are origin-1 indices into the table of sections
9845 offsets and the table of section sizes.
9847 The table of offsets begins immediately following the parallel table
9848 (at offset 16 + 12 * M from the beginning of the section). The table is
9849 a two-dimensional array of 32-bit words (using the byte order of the
9850 application binary), with L columns and N+1 rows, in row-major order.
9851 Each row in the array is indexed starting from 0. The first row provides
9852 a key to the remaining rows: each column in this row provides an identifier
9853 for a debug section, and the offsets in the same column of subsequent rows
9854 refer to that section. The section identifiers are:
9856 DW_SECT_INFO 1 .debug_info.dwo
9857 DW_SECT_TYPES 2 .debug_types.dwo
9858 DW_SECT_ABBREV 3 .debug_abbrev.dwo
9859 DW_SECT_LINE 4 .debug_line.dwo
9860 DW_SECT_LOC 5 .debug_loc.dwo
9861 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
9862 DW_SECT_MACINFO 7 .debug_macinfo.dwo
9863 DW_SECT_MACRO 8 .debug_macro.dwo
9865 The offsets provided by the CU and TU index sections are the base offsets
9866 for the contributions made by each CU or TU to the corresponding section
9867 in the package file. Each CU and TU header contains an abbrev_offset
9868 field, used to find the abbreviations table for that CU or TU within the
9869 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
9870 be interpreted as relative to the base offset given in the index section.
9871 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
9872 should be interpreted as relative to the base offset for .debug_line.dwo,
9873 and offsets into other debug sections obtained from DWARF attributes should
9874 also be interpreted as relative to the corresponding base offset.
9876 The table of sizes begins immediately following the table of offsets.
9877 Like the table of offsets, it is a two-dimensional array of 32-bit words,
9878 with L columns and N rows, in row-major order. Each row in the array is
9879 indexed starting from 1 (row 0 is shared by the two tables).
9883 Hash table lookup is handled the same in version 1 and 2:
9885 We assume that N and M will not exceed 2^32 - 1.
9886 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
9888 Given a 64-bit compilation unit signature or a type signature S, an entry
9889 in the hash table is located as follows:
9891 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
9892 the low-order k bits all set to 1.
9894 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
9896 3) If the hash table entry at index H matches the signature, use that
9897 entry. If the hash table entry at index H is unused (all zeroes),
9898 terminate the search: the signature is not present in the table.
9900 4) Let H = (H + H') modulo M. Repeat at Step 3.
9902 Because M > N and H' and M are relatively prime, the search is guaranteed
9903 to stop at an unused slot or find the match. */
9905 /* Create a hash table to map DWO IDs to their CU/TU entry in
9906 .debug_{info,types}.dwo in DWP_FILE.
9907 Returns NULL if there isn't one.
9908 Note: This function processes DWP files only, not DWO files. */
9910 static struct dwp_hash_table
*
9911 create_dwp_hash_table (struct dwp_file
*dwp_file
, int is_debug_types
)
9913 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9914 bfd
*dbfd
= dwp_file
->dbfd
;
9915 const gdb_byte
*index_ptr
, *index_end
;
9916 struct dwarf2_section_info
*index
;
9917 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
9918 struct dwp_hash_table
*htab
;
9921 index
= &dwp_file
->sections
.tu_index
;
9923 index
= &dwp_file
->sections
.cu_index
;
9925 if (dwarf2_section_empty_p (index
))
9927 dwarf2_read_section (objfile
, index
);
9929 index_ptr
= index
->buffer
;
9930 index_end
= index_ptr
+ index
->size
;
9932 version
= read_4_bytes (dbfd
, index_ptr
);
9935 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
9939 nr_units
= read_4_bytes (dbfd
, index_ptr
);
9941 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
9944 if (version
!= 1 && version
!= 2)
9946 error (_("Dwarf Error: unsupported DWP file version (%s)"
9948 pulongest (version
), dwp_file
->name
);
9950 if (nr_slots
!= (nr_slots
& -nr_slots
))
9952 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
9953 " is not power of 2 [in module %s]"),
9954 pulongest (nr_slots
), dwp_file
->name
);
9957 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
9958 htab
->version
= version
;
9959 htab
->nr_columns
= nr_columns
;
9960 htab
->nr_units
= nr_units
;
9961 htab
->nr_slots
= nr_slots
;
9962 htab
->hash_table
= index_ptr
;
9963 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
9965 /* Exit early if the table is empty. */
9966 if (nr_slots
== 0 || nr_units
== 0
9967 || (version
== 2 && nr_columns
== 0))
9969 /* All must be zero. */
9970 if (nr_slots
!= 0 || nr_units
!= 0
9971 || (version
== 2 && nr_columns
!= 0))
9973 complaint (&symfile_complaints
,
9974 _("Empty DWP but nr_slots,nr_units,nr_columns not"
9975 " all zero [in modules %s]"),
9983 htab
->section_pool
.v1
.indices
=
9984 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
9985 /* It's harder to decide whether the section is too small in v1.
9986 V1 is deprecated anyway so we punt. */
9990 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
9991 int *ids
= htab
->section_pool
.v2
.section_ids
;
9992 /* Reverse map for error checking. */
9993 int ids_seen
[DW_SECT_MAX
+ 1];
9998 error (_("Dwarf Error: bad DWP hash table, too few columns"
9999 " in section table [in module %s]"),
10002 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
10004 error (_("Dwarf Error: bad DWP hash table, too many columns"
10005 " in section table [in module %s]"),
10008 memset (ids
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
10009 memset (ids_seen
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
10010 for (i
= 0; i
< nr_columns
; ++i
)
10012 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
10014 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
10016 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
10017 " in section table [in module %s]"),
10018 id
, dwp_file
->name
);
10020 if (ids_seen
[id
] != -1)
10022 error (_("Dwarf Error: bad DWP hash table, duplicate section"
10023 " id %d in section table [in module %s]"),
10024 id
, dwp_file
->name
);
10029 /* Must have exactly one info or types section. */
10030 if (((ids_seen
[DW_SECT_INFO
] != -1)
10031 + (ids_seen
[DW_SECT_TYPES
] != -1))
10034 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
10035 " DWO info/types section [in module %s]"),
10038 /* Must have an abbrev section. */
10039 if (ids_seen
[DW_SECT_ABBREV
] == -1)
10041 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
10042 " section [in module %s]"),
10045 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
10046 htab
->section_pool
.v2
.sizes
=
10047 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
10048 * nr_units
* nr_columns
);
10049 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
10050 * nr_units
* nr_columns
))
10053 error (_("Dwarf Error: DWP index section is corrupt (too small)"
10054 " [in module %s]"),
10062 /* Update SECTIONS with the data from SECTP.
10064 This function is like the other "locate" section routines that are
10065 passed to bfd_map_over_sections, but in this context the sections to
10066 read comes from the DWP V1 hash table, not the full ELF section table.
10068 The result is non-zero for success, or zero if an error was found. */
10071 locate_v1_virtual_dwo_sections (asection
*sectp
,
10072 struct virtual_v1_dwo_sections
*sections
)
10074 const struct dwop_section_names
*names
= &dwop_section_names
;
10076 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
10078 /* There can be only one. */
10079 if (sections
->abbrev
.s
.section
!= NULL
)
10081 sections
->abbrev
.s
.section
= sectp
;
10082 sections
->abbrev
.size
= bfd_get_section_size (sectp
);
10084 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
10085 || section_is_p (sectp
->name
, &names
->types_dwo
))
10087 /* There can be only one. */
10088 if (sections
->info_or_types
.s
.section
!= NULL
)
10090 sections
->info_or_types
.s
.section
= sectp
;
10091 sections
->info_or_types
.size
= bfd_get_section_size (sectp
);
10093 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
10095 /* There can be only one. */
10096 if (sections
->line
.s
.section
!= NULL
)
10098 sections
->line
.s
.section
= sectp
;
10099 sections
->line
.size
= bfd_get_section_size (sectp
);
10101 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
10103 /* There can be only one. */
10104 if (sections
->loc
.s
.section
!= NULL
)
10106 sections
->loc
.s
.section
= sectp
;
10107 sections
->loc
.size
= bfd_get_section_size (sectp
);
10109 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
10111 /* There can be only one. */
10112 if (sections
->macinfo
.s
.section
!= NULL
)
10114 sections
->macinfo
.s
.section
= sectp
;
10115 sections
->macinfo
.size
= bfd_get_section_size (sectp
);
10117 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
10119 /* There can be only one. */
10120 if (sections
->macro
.s
.section
!= NULL
)
10122 sections
->macro
.s
.section
= sectp
;
10123 sections
->macro
.size
= bfd_get_section_size (sectp
);
10125 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
10127 /* There can be only one. */
10128 if (sections
->str_offsets
.s
.section
!= NULL
)
10130 sections
->str_offsets
.s
.section
= sectp
;
10131 sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
10135 /* No other kind of section is valid. */
10142 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
10143 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
10144 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
10145 This is for DWP version 1 files. */
10147 static struct dwo_unit
*
10148 create_dwo_unit_in_dwp_v1 (struct dwp_file
*dwp_file
,
10149 uint32_t unit_index
,
10150 const char *comp_dir
,
10151 ULONGEST signature
, int is_debug_types
)
10153 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10154 const struct dwp_hash_table
*dwp_htab
=
10155 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
10156 bfd
*dbfd
= dwp_file
->dbfd
;
10157 const char *kind
= is_debug_types
? "TU" : "CU";
10158 struct dwo_file
*dwo_file
;
10159 struct dwo_unit
*dwo_unit
;
10160 struct virtual_v1_dwo_sections sections
;
10161 void **dwo_file_slot
;
10162 char *virtual_dwo_name
;
10163 struct cleanup
*cleanups
;
10166 gdb_assert (dwp_file
->version
== 1);
10168 if (dwarf_read_debug
)
10170 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
10172 pulongest (unit_index
), hex_string (signature
),
10176 /* Fetch the sections of this DWO unit.
10177 Put a limit on the number of sections we look for so that bad data
10178 doesn't cause us to loop forever. */
10180 #define MAX_NR_V1_DWO_SECTIONS \
10181 (1 /* .debug_info or .debug_types */ \
10182 + 1 /* .debug_abbrev */ \
10183 + 1 /* .debug_line */ \
10184 + 1 /* .debug_loc */ \
10185 + 1 /* .debug_str_offsets */ \
10186 + 1 /* .debug_macro or .debug_macinfo */ \
10187 + 1 /* trailing zero */)
10189 memset (§ions
, 0, sizeof (sections
));
10190 cleanups
= make_cleanup (null_cleanup
, 0);
10192 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
10195 uint32_t section_nr
=
10196 read_4_bytes (dbfd
,
10197 dwp_htab
->section_pool
.v1
.indices
10198 + (unit_index
+ i
) * sizeof (uint32_t));
10200 if (section_nr
== 0)
10202 if (section_nr
>= dwp_file
->num_sections
)
10204 error (_("Dwarf Error: bad DWP hash table, section number too large"
10205 " [in module %s]"),
10209 sectp
= dwp_file
->elf_sections
[section_nr
];
10210 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
10212 error (_("Dwarf Error: bad DWP hash table, invalid section found"
10213 " [in module %s]"),
10219 || dwarf2_section_empty_p (§ions
.info_or_types
)
10220 || dwarf2_section_empty_p (§ions
.abbrev
))
10222 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
10223 " [in module %s]"),
10226 if (i
== MAX_NR_V1_DWO_SECTIONS
)
10228 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
10229 " [in module %s]"),
10233 /* It's easier for the rest of the code if we fake a struct dwo_file and
10234 have dwo_unit "live" in that. At least for now.
10236 The DWP file can be made up of a random collection of CUs and TUs.
10237 However, for each CU + set of TUs that came from the same original DWO
10238 file, we can combine them back into a virtual DWO file to save space
10239 (fewer struct dwo_file objects to allocate). Remember that for really
10240 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
10243 xstrprintf ("virtual-dwo/%d-%d-%d-%d",
10244 get_section_id (§ions
.abbrev
),
10245 get_section_id (§ions
.line
),
10246 get_section_id (§ions
.loc
),
10247 get_section_id (§ions
.str_offsets
));
10248 make_cleanup (xfree
, virtual_dwo_name
);
10249 /* Can we use an existing virtual DWO file? */
10250 dwo_file_slot
= lookup_dwo_file_slot (virtual_dwo_name
, comp_dir
);
10251 /* Create one if necessary. */
10252 if (*dwo_file_slot
== NULL
)
10254 if (dwarf_read_debug
)
10256 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
10259 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
10261 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
10263 strlen (virtual_dwo_name
));
10264 dwo_file
->comp_dir
= comp_dir
;
10265 dwo_file
->sections
.abbrev
= sections
.abbrev
;
10266 dwo_file
->sections
.line
= sections
.line
;
10267 dwo_file
->sections
.loc
= sections
.loc
;
10268 dwo_file
->sections
.macinfo
= sections
.macinfo
;
10269 dwo_file
->sections
.macro
= sections
.macro
;
10270 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
10271 /* The "str" section is global to the entire DWP file. */
10272 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
10273 /* The info or types section is assigned below to dwo_unit,
10274 there's no need to record it in dwo_file.
10275 Also, we can't simply record type sections in dwo_file because
10276 we record a pointer into the vector in dwo_unit. As we collect more
10277 types we'll grow the vector and eventually have to reallocate space
10278 for it, invalidating all copies of pointers into the previous
10280 *dwo_file_slot
= dwo_file
;
10284 if (dwarf_read_debug
)
10286 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
10289 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
10291 do_cleanups (cleanups
);
10293 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
10294 dwo_unit
->dwo_file
= dwo_file
;
10295 dwo_unit
->signature
= signature
;
10296 dwo_unit
->section
=
10297 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
10298 *dwo_unit
->section
= sections
.info_or_types
;
10299 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
10304 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
10305 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
10306 piece within that section used by a TU/CU, return a virtual section
10307 of just that piece. */
10309 static struct dwarf2_section_info
10310 create_dwp_v2_section (struct dwarf2_section_info
*section
,
10311 bfd_size_type offset
, bfd_size_type size
)
10313 struct dwarf2_section_info result
;
10316 gdb_assert (section
!= NULL
);
10317 gdb_assert (!section
->is_virtual
);
10319 memset (&result
, 0, sizeof (result
));
10320 result
.s
.containing_section
= section
;
10321 result
.is_virtual
= 1;
10326 sectp
= get_section_bfd_section (section
);
10328 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
10329 bounds of the real section. This is a pretty-rare event, so just
10330 flag an error (easier) instead of a warning and trying to cope. */
10332 || offset
+ size
> bfd_get_section_size (sectp
))
10334 bfd
*abfd
= sectp
->owner
;
10336 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
10337 " in section %s [in module %s]"),
10338 sectp
? bfd_section_name (abfd
, sectp
) : "<unknown>",
10339 objfile_name (dwarf2_per_objfile
->objfile
));
10342 result
.virtual_offset
= offset
;
10343 result
.size
= size
;
10347 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
10348 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
10349 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
10350 This is for DWP version 2 files. */
10352 static struct dwo_unit
*
10353 create_dwo_unit_in_dwp_v2 (struct dwp_file
*dwp_file
,
10354 uint32_t unit_index
,
10355 const char *comp_dir
,
10356 ULONGEST signature
, int is_debug_types
)
10358 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10359 const struct dwp_hash_table
*dwp_htab
=
10360 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
10361 bfd
*dbfd
= dwp_file
->dbfd
;
10362 const char *kind
= is_debug_types
? "TU" : "CU";
10363 struct dwo_file
*dwo_file
;
10364 struct dwo_unit
*dwo_unit
;
10365 struct virtual_v2_dwo_sections sections
;
10366 void **dwo_file_slot
;
10367 char *virtual_dwo_name
;
10368 struct cleanup
*cleanups
;
10371 gdb_assert (dwp_file
->version
== 2);
10373 if (dwarf_read_debug
)
10375 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
10377 pulongest (unit_index
), hex_string (signature
),
10381 /* Fetch the section offsets of this DWO unit. */
10383 memset (§ions
, 0, sizeof (sections
));
10384 cleanups
= make_cleanup (null_cleanup
, 0);
10386 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
10388 uint32_t offset
= read_4_bytes (dbfd
,
10389 dwp_htab
->section_pool
.v2
.offsets
10390 + (((unit_index
- 1) * dwp_htab
->nr_columns
10392 * sizeof (uint32_t)));
10393 uint32_t size
= read_4_bytes (dbfd
,
10394 dwp_htab
->section_pool
.v2
.sizes
10395 + (((unit_index
- 1) * dwp_htab
->nr_columns
10397 * sizeof (uint32_t)));
10399 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
10402 case DW_SECT_TYPES
:
10403 sections
.info_or_types_offset
= offset
;
10404 sections
.info_or_types_size
= size
;
10406 case DW_SECT_ABBREV
:
10407 sections
.abbrev_offset
= offset
;
10408 sections
.abbrev_size
= size
;
10411 sections
.line_offset
= offset
;
10412 sections
.line_size
= size
;
10415 sections
.loc_offset
= offset
;
10416 sections
.loc_size
= size
;
10418 case DW_SECT_STR_OFFSETS
:
10419 sections
.str_offsets_offset
= offset
;
10420 sections
.str_offsets_size
= size
;
10422 case DW_SECT_MACINFO
:
10423 sections
.macinfo_offset
= offset
;
10424 sections
.macinfo_size
= size
;
10426 case DW_SECT_MACRO
:
10427 sections
.macro_offset
= offset
;
10428 sections
.macro_size
= size
;
10433 /* It's easier for the rest of the code if we fake a struct dwo_file and
10434 have dwo_unit "live" in that. At least for now.
10436 The DWP file can be made up of a random collection of CUs and TUs.
10437 However, for each CU + set of TUs that came from the same original DWO
10438 file, we can combine them back into a virtual DWO file to save space
10439 (fewer struct dwo_file objects to allocate). Remember that for really
10440 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
10443 xstrprintf ("virtual-dwo/%ld-%ld-%ld-%ld",
10444 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
10445 (long) (sections
.line_size
? sections
.line_offset
: 0),
10446 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
10447 (long) (sections
.str_offsets_size
10448 ? sections
.str_offsets_offset
: 0));
10449 make_cleanup (xfree
, virtual_dwo_name
);
10450 /* Can we use an existing virtual DWO file? */
10451 dwo_file_slot
= lookup_dwo_file_slot (virtual_dwo_name
, comp_dir
);
10452 /* Create one if necessary. */
10453 if (*dwo_file_slot
== NULL
)
10455 if (dwarf_read_debug
)
10457 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
10460 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
10462 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
10464 strlen (virtual_dwo_name
));
10465 dwo_file
->comp_dir
= comp_dir
;
10466 dwo_file
->sections
.abbrev
=
10467 create_dwp_v2_section (&dwp_file
->sections
.abbrev
,
10468 sections
.abbrev_offset
, sections
.abbrev_size
);
10469 dwo_file
->sections
.line
=
10470 create_dwp_v2_section (&dwp_file
->sections
.line
,
10471 sections
.line_offset
, sections
.line_size
);
10472 dwo_file
->sections
.loc
=
10473 create_dwp_v2_section (&dwp_file
->sections
.loc
,
10474 sections
.loc_offset
, sections
.loc_size
);
10475 dwo_file
->sections
.macinfo
=
10476 create_dwp_v2_section (&dwp_file
->sections
.macinfo
,
10477 sections
.macinfo_offset
, sections
.macinfo_size
);
10478 dwo_file
->sections
.macro
=
10479 create_dwp_v2_section (&dwp_file
->sections
.macro
,
10480 sections
.macro_offset
, sections
.macro_size
);
10481 dwo_file
->sections
.str_offsets
=
10482 create_dwp_v2_section (&dwp_file
->sections
.str_offsets
,
10483 sections
.str_offsets_offset
,
10484 sections
.str_offsets_size
);
10485 /* The "str" section is global to the entire DWP file. */
10486 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
10487 /* The info or types section is assigned below to dwo_unit,
10488 there's no need to record it in dwo_file.
10489 Also, we can't simply record type sections in dwo_file because
10490 we record a pointer into the vector in dwo_unit. As we collect more
10491 types we'll grow the vector and eventually have to reallocate space
10492 for it, invalidating all copies of pointers into the previous
10494 *dwo_file_slot
= dwo_file
;
10498 if (dwarf_read_debug
)
10500 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
10503 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
10505 do_cleanups (cleanups
);
10507 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
10508 dwo_unit
->dwo_file
= dwo_file
;
10509 dwo_unit
->signature
= signature
;
10510 dwo_unit
->section
=
10511 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
10512 *dwo_unit
->section
= create_dwp_v2_section (is_debug_types
10513 ? &dwp_file
->sections
.types
10514 : &dwp_file
->sections
.info
,
10515 sections
.info_or_types_offset
,
10516 sections
.info_or_types_size
);
10517 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
10522 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
10523 Returns NULL if the signature isn't found. */
10525 static struct dwo_unit
*
10526 lookup_dwo_unit_in_dwp (struct dwp_file
*dwp_file
, const char *comp_dir
,
10527 ULONGEST signature
, int is_debug_types
)
10529 const struct dwp_hash_table
*dwp_htab
=
10530 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
10531 bfd
*dbfd
= dwp_file
->dbfd
;
10532 uint32_t mask
= dwp_htab
->nr_slots
- 1;
10533 uint32_t hash
= signature
& mask
;
10534 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
10537 struct dwo_unit find_dwo_cu
;
10539 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
10540 find_dwo_cu
.signature
= signature
;
10541 slot
= htab_find_slot (is_debug_types
10542 ? dwp_file
->loaded_tus
10543 : dwp_file
->loaded_cus
,
10544 &find_dwo_cu
, INSERT
);
10547 return (struct dwo_unit
*) *slot
;
10549 /* Use a for loop so that we don't loop forever on bad debug info. */
10550 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
10552 ULONGEST signature_in_table
;
10554 signature_in_table
=
10555 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
10556 if (signature_in_table
== signature
)
10558 uint32_t unit_index
=
10559 read_4_bytes (dbfd
,
10560 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
10562 if (dwp_file
->version
== 1)
10564 *slot
= create_dwo_unit_in_dwp_v1 (dwp_file
, unit_index
,
10565 comp_dir
, signature
,
10570 *slot
= create_dwo_unit_in_dwp_v2 (dwp_file
, unit_index
,
10571 comp_dir
, signature
,
10574 return (struct dwo_unit
*) *slot
;
10576 if (signature_in_table
== 0)
10578 hash
= (hash
+ hash2
) & mask
;
10581 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
10582 " [in module %s]"),
10586 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
10587 Open the file specified by FILE_NAME and hand it off to BFD for
10588 preliminary analysis. Return a newly initialized bfd *, which
10589 includes a canonicalized copy of FILE_NAME.
10590 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
10591 SEARCH_CWD is true if the current directory is to be searched.
10592 It will be searched before debug-file-directory.
10593 If successful, the file is added to the bfd include table of the
10594 objfile's bfd (see gdb_bfd_record_inclusion).
10595 If unable to find/open the file, return NULL.
10596 NOTE: This function is derived from symfile_bfd_open. */
10598 static gdb_bfd_ref_ptr
10599 try_open_dwop_file (const char *file_name
, int is_dwp
, int search_cwd
)
10602 char *absolute_name
;
10603 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
10604 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
10605 to debug_file_directory. */
10607 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
10611 if (*debug_file_directory
!= '\0')
10612 search_path
= concat (".", dirname_separator_string
,
10613 debug_file_directory
, (char *) NULL
);
10615 search_path
= xstrdup (".");
10618 search_path
= xstrdup (debug_file_directory
);
10620 flags
= OPF_RETURN_REALPATH
;
10622 flags
|= OPF_SEARCH_IN_PATH
;
10623 desc
= openp (search_path
, flags
, file_name
,
10624 O_RDONLY
| O_BINARY
, &absolute_name
);
10625 xfree (search_path
);
10629 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
, gnutarget
, desc
));
10630 xfree (absolute_name
);
10631 if (sym_bfd
== NULL
)
10633 bfd_set_cacheable (sym_bfd
.get (), 1);
10635 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
10638 /* Success. Record the bfd as having been included by the objfile's bfd.
10639 This is important because things like demangled_names_hash lives in the
10640 objfile's per_bfd space and may have references to things like symbol
10641 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
10642 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
10647 /* Try to open DWO file FILE_NAME.
10648 COMP_DIR is the DW_AT_comp_dir attribute.
10649 The result is the bfd handle of the file.
10650 If there is a problem finding or opening the file, return NULL.
10651 Upon success, the canonicalized path of the file is stored in the bfd,
10652 same as symfile_bfd_open. */
10654 static gdb_bfd_ref_ptr
10655 open_dwo_file (const char *file_name
, const char *comp_dir
)
10657 if (IS_ABSOLUTE_PATH (file_name
))
10658 return try_open_dwop_file (file_name
, 0 /*is_dwp*/, 0 /*search_cwd*/);
10660 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
10662 if (comp_dir
!= NULL
)
10664 char *path_to_try
= concat (comp_dir
, SLASH_STRING
,
10665 file_name
, (char *) NULL
);
10667 /* NOTE: If comp_dir is a relative path, this will also try the
10668 search path, which seems useful. */
10669 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (path_to_try
, 0 /*is_dwp*/,
10670 1 /*search_cwd*/));
10671 xfree (path_to_try
);
10676 /* That didn't work, try debug-file-directory, which, despite its name,
10677 is a list of paths. */
10679 if (*debug_file_directory
== '\0')
10682 return try_open_dwop_file (file_name
, 0 /*is_dwp*/, 1 /*search_cwd*/);
10685 /* This function is mapped across the sections and remembers the offset and
10686 size of each of the DWO debugging sections we are interested in. */
10689 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
10691 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
10692 const struct dwop_section_names
*names
= &dwop_section_names
;
10694 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
10696 dwo_sections
->abbrev
.s
.section
= sectp
;
10697 dwo_sections
->abbrev
.size
= bfd_get_section_size (sectp
);
10699 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
10701 dwo_sections
->info
.s
.section
= sectp
;
10702 dwo_sections
->info
.size
= bfd_get_section_size (sectp
);
10704 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
10706 dwo_sections
->line
.s
.section
= sectp
;
10707 dwo_sections
->line
.size
= bfd_get_section_size (sectp
);
10709 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
10711 dwo_sections
->loc
.s
.section
= sectp
;
10712 dwo_sections
->loc
.size
= bfd_get_section_size (sectp
);
10714 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
10716 dwo_sections
->macinfo
.s
.section
= sectp
;
10717 dwo_sections
->macinfo
.size
= bfd_get_section_size (sectp
);
10719 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
10721 dwo_sections
->macro
.s
.section
= sectp
;
10722 dwo_sections
->macro
.size
= bfd_get_section_size (sectp
);
10724 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
10726 dwo_sections
->str
.s
.section
= sectp
;
10727 dwo_sections
->str
.size
= bfd_get_section_size (sectp
);
10729 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
10731 dwo_sections
->str_offsets
.s
.section
= sectp
;
10732 dwo_sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
10734 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
10736 struct dwarf2_section_info type_section
;
10738 memset (&type_section
, 0, sizeof (type_section
));
10739 type_section
.s
.section
= sectp
;
10740 type_section
.size
= bfd_get_section_size (sectp
);
10741 VEC_safe_push (dwarf2_section_info_def
, dwo_sections
->types
,
10746 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
10747 by PER_CU. This is for the non-DWP case.
10748 The result is NULL if DWO_NAME can't be found. */
10750 static struct dwo_file
*
10751 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
10752 const char *dwo_name
, const char *comp_dir
)
10754 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10755 struct dwo_file
*dwo_file
;
10756 struct cleanup
*cleanups
;
10758 gdb_bfd_ref_ptr
dbfd (open_dwo_file (dwo_name
, comp_dir
));
10761 if (dwarf_read_debug
)
10762 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
10765 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
10766 dwo_file
->dwo_name
= dwo_name
;
10767 dwo_file
->comp_dir
= comp_dir
;
10768 dwo_file
->dbfd
= dbfd
.release ();
10770 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwo_file
);
10772 bfd_map_over_sections (dwo_file
->dbfd
, dwarf2_locate_dwo_sections
,
10773 &dwo_file
->sections
);
10775 dwo_file
->cu
= create_dwo_cu (dwo_file
);
10777 create_debug_types_hash_table (dwo_file
, dwo_file
->sections
.types
,
10780 discard_cleanups (cleanups
);
10782 if (dwarf_read_debug
)
10783 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
10788 /* This function is mapped across the sections and remembers the offset and
10789 size of each of the DWP debugging sections common to version 1 and 2 that
10790 we are interested in. */
10793 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
10794 void *dwp_file_ptr
)
10796 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
10797 const struct dwop_section_names
*names
= &dwop_section_names
;
10798 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
10800 /* Record the ELF section number for later lookup: this is what the
10801 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
10802 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
10803 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
10805 /* Look for specific sections that we need. */
10806 if (section_is_p (sectp
->name
, &names
->str_dwo
))
10808 dwp_file
->sections
.str
.s
.section
= sectp
;
10809 dwp_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
10811 else if (section_is_p (sectp
->name
, &names
->cu_index
))
10813 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
10814 dwp_file
->sections
.cu_index
.size
= bfd_get_section_size (sectp
);
10816 else if (section_is_p (sectp
->name
, &names
->tu_index
))
10818 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
10819 dwp_file
->sections
.tu_index
.size
= bfd_get_section_size (sectp
);
10823 /* This function is mapped across the sections and remembers the offset and
10824 size of each of the DWP version 2 debugging sections that we are interested
10825 in. This is split into a separate function because we don't know if we
10826 have version 1 or 2 until we parse the cu_index/tu_index sections. */
10829 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
10831 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
10832 const struct dwop_section_names
*names
= &dwop_section_names
;
10833 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
10835 /* Record the ELF section number for later lookup: this is what the
10836 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
10837 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
10838 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
10840 /* Look for specific sections that we need. */
10841 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
10843 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
10844 dwp_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
10846 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
10848 dwp_file
->sections
.info
.s
.section
= sectp
;
10849 dwp_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
10851 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
10853 dwp_file
->sections
.line
.s
.section
= sectp
;
10854 dwp_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
10856 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
10858 dwp_file
->sections
.loc
.s
.section
= sectp
;
10859 dwp_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
10861 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
10863 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
10864 dwp_file
->sections
.macinfo
.size
= bfd_get_section_size (sectp
);
10866 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
10868 dwp_file
->sections
.macro
.s
.section
= sectp
;
10869 dwp_file
->sections
.macro
.size
= bfd_get_section_size (sectp
);
10871 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
10873 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
10874 dwp_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
10876 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
10878 dwp_file
->sections
.types
.s
.section
= sectp
;
10879 dwp_file
->sections
.types
.size
= bfd_get_section_size (sectp
);
10883 /* Hash function for dwp_file loaded CUs/TUs. */
10886 hash_dwp_loaded_cutus (const void *item
)
10888 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
10890 /* This drops the top 32 bits of the signature, but is ok for a hash. */
10891 return dwo_unit
->signature
;
10894 /* Equality function for dwp_file loaded CUs/TUs. */
10897 eq_dwp_loaded_cutus (const void *a
, const void *b
)
10899 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
10900 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
10902 return dua
->signature
== dub
->signature
;
10905 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
10908 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
10910 return htab_create_alloc_ex (3,
10911 hash_dwp_loaded_cutus
,
10912 eq_dwp_loaded_cutus
,
10914 &objfile
->objfile_obstack
,
10915 hashtab_obstack_allocate
,
10916 dummy_obstack_deallocate
);
10919 /* Try to open DWP file FILE_NAME.
10920 The result is the bfd handle of the file.
10921 If there is a problem finding or opening the file, return NULL.
10922 Upon success, the canonicalized path of the file is stored in the bfd,
10923 same as symfile_bfd_open. */
10925 static gdb_bfd_ref_ptr
10926 open_dwp_file (const char *file_name
)
10928 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (file_name
, 1 /*is_dwp*/,
10929 1 /*search_cwd*/));
10933 /* Work around upstream bug 15652.
10934 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
10935 [Whether that's a "bug" is debatable, but it is getting in our way.]
10936 We have no real idea where the dwp file is, because gdb's realpath-ing
10937 of the executable's path may have discarded the needed info.
10938 [IWBN if the dwp file name was recorded in the executable, akin to
10939 .gnu_debuglink, but that doesn't exist yet.]
10940 Strip the directory from FILE_NAME and search again. */
10941 if (*debug_file_directory
!= '\0')
10943 /* Don't implicitly search the current directory here.
10944 If the user wants to search "." to handle this case,
10945 it must be added to debug-file-directory. */
10946 return try_open_dwop_file (lbasename (file_name
), 1 /*is_dwp*/,
10953 /* Initialize the use of the DWP file for the current objfile.
10954 By convention the name of the DWP file is ${objfile}.dwp.
10955 The result is NULL if it can't be found. */
10957 static struct dwp_file
*
10958 open_and_init_dwp_file (void)
10960 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10961 struct dwp_file
*dwp_file
;
10963 /* Try to find first .dwp for the binary file before any symbolic links
10966 /* If the objfile is a debug file, find the name of the real binary
10967 file and get the name of dwp file from there. */
10968 std::string dwp_name
;
10969 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
10971 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
10972 const char *backlink_basename
= lbasename (backlink
->original_name
);
10974 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
10977 dwp_name
= objfile
->original_name
;
10979 dwp_name
+= ".dwp";
10981 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwp_name
.c_str ()));
10983 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
10985 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
10986 dwp_name
= objfile_name (objfile
);
10987 dwp_name
+= ".dwp";
10988 dbfd
= open_dwp_file (dwp_name
.c_str ());
10993 if (dwarf_read_debug
)
10994 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
10997 dwp_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_file
);
10998 dwp_file
->name
= bfd_get_filename (dbfd
.get ());
10999 dwp_file
->dbfd
= dbfd
.release ();
11001 /* +1: section 0 is unused */
11002 dwp_file
->num_sections
= bfd_count_sections (dwp_file
->dbfd
) + 1;
11003 dwp_file
->elf_sections
=
11004 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
11005 dwp_file
->num_sections
, asection
*);
11007 bfd_map_over_sections (dwp_file
->dbfd
, dwarf2_locate_common_dwp_sections
,
11010 dwp_file
->cus
= create_dwp_hash_table (dwp_file
, 0);
11012 dwp_file
->tus
= create_dwp_hash_table (dwp_file
, 1);
11014 /* The DWP file version is stored in the hash table. Oh well. */
11015 if (dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
11017 /* Technically speaking, we should try to limp along, but this is
11018 pretty bizarre. We use pulongest here because that's the established
11019 portability solution (e.g, we cannot use %u for uint32_t). */
11020 error (_("Dwarf Error: DWP file CU version %s doesn't match"
11021 " TU version %s [in DWP file %s]"),
11022 pulongest (dwp_file
->cus
->version
),
11023 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
11025 dwp_file
->version
= dwp_file
->cus
->version
;
11027 if (dwp_file
->version
== 2)
11028 bfd_map_over_sections (dwp_file
->dbfd
, dwarf2_locate_v2_dwp_sections
,
11031 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
11032 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
11034 if (dwarf_read_debug
)
11036 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
11037 fprintf_unfiltered (gdb_stdlog
,
11038 " %s CUs, %s TUs\n",
11039 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
11040 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
11046 /* Wrapper around open_and_init_dwp_file, only open it once. */
11048 static struct dwp_file
*
11049 get_dwp_file (void)
11051 if (! dwarf2_per_objfile
->dwp_checked
)
11053 dwarf2_per_objfile
->dwp_file
= open_and_init_dwp_file ();
11054 dwarf2_per_objfile
->dwp_checked
= 1;
11056 return dwarf2_per_objfile
->dwp_file
;
11059 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
11060 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
11061 or in the DWP file for the objfile, referenced by THIS_UNIT.
11062 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
11063 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
11065 This is called, for example, when wanting to read a variable with a
11066 complex location. Therefore we don't want to do file i/o for every call.
11067 Therefore we don't want to look for a DWO file on every call.
11068 Therefore we first see if we've already seen SIGNATURE in a DWP file,
11069 then we check if we've already seen DWO_NAME, and only THEN do we check
11072 The result is a pointer to the dwo_unit object or NULL if we didn't find it
11073 (dwo_id mismatch or couldn't find the DWO/DWP file). */
11075 static struct dwo_unit
*
11076 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
11077 const char *dwo_name
, const char *comp_dir
,
11078 ULONGEST signature
, int is_debug_types
)
11080 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11081 const char *kind
= is_debug_types
? "TU" : "CU";
11082 void **dwo_file_slot
;
11083 struct dwo_file
*dwo_file
;
11084 struct dwp_file
*dwp_file
;
11086 /* First see if there's a DWP file.
11087 If we have a DWP file but didn't find the DWO inside it, don't
11088 look for the original DWO file. It makes gdb behave differently
11089 depending on whether one is debugging in the build tree. */
11091 dwp_file
= get_dwp_file ();
11092 if (dwp_file
!= NULL
)
11094 const struct dwp_hash_table
*dwp_htab
=
11095 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11097 if (dwp_htab
!= NULL
)
11099 struct dwo_unit
*dwo_cutu
=
11100 lookup_dwo_unit_in_dwp (dwp_file
, comp_dir
,
11101 signature
, is_debug_types
);
11103 if (dwo_cutu
!= NULL
)
11105 if (dwarf_read_debug
)
11107 fprintf_unfiltered (gdb_stdlog
,
11108 "Virtual DWO %s %s found: @%s\n",
11109 kind
, hex_string (signature
),
11110 host_address_to_string (dwo_cutu
));
11118 /* No DWP file, look for the DWO file. */
11120 dwo_file_slot
= lookup_dwo_file_slot (dwo_name
, comp_dir
);
11121 if (*dwo_file_slot
== NULL
)
11123 /* Read in the file and build a table of the CUs/TUs it contains. */
11124 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
11126 /* NOTE: This will be NULL if unable to open the file. */
11127 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11129 if (dwo_file
!= NULL
)
11131 struct dwo_unit
*dwo_cutu
= NULL
;
11133 if (is_debug_types
&& dwo_file
->tus
)
11135 struct dwo_unit find_dwo_cutu
;
11137 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
11138 find_dwo_cutu
.signature
= signature
;
11140 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
11142 else if (!is_debug_types
&& dwo_file
->cu
)
11144 if (signature
== dwo_file
->cu
->signature
)
11145 dwo_cutu
= dwo_file
->cu
;
11148 if (dwo_cutu
!= NULL
)
11150 if (dwarf_read_debug
)
11152 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
11153 kind
, dwo_name
, hex_string (signature
),
11154 host_address_to_string (dwo_cutu
));
11161 /* We didn't find it. This could mean a dwo_id mismatch, or
11162 someone deleted the DWO/DWP file, or the search path isn't set up
11163 correctly to find the file. */
11165 if (dwarf_read_debug
)
11167 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
11168 kind
, dwo_name
, hex_string (signature
));
11171 /* This is a warning and not a complaint because it can be caused by
11172 pilot error (e.g., user accidentally deleting the DWO). */
11174 /* Print the name of the DWP file if we looked there, helps the user
11175 better diagnose the problem. */
11176 char *dwp_text
= NULL
;
11177 struct cleanup
*cleanups
;
11179 if (dwp_file
!= NULL
)
11180 dwp_text
= xstrprintf (" [in DWP file %s]", lbasename (dwp_file
->name
));
11181 cleanups
= make_cleanup (xfree
, dwp_text
);
11183 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset 0x%x"
11184 " [in module %s]"),
11185 kind
, dwo_name
, hex_string (signature
),
11186 dwp_text
!= NULL
? dwp_text
: "",
11187 this_unit
->is_debug_types
? "TU" : "CU",
11188 to_underlying (this_unit
->sect_off
), objfile_name (objfile
));
11190 do_cleanups (cleanups
);
11195 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
11196 See lookup_dwo_cutu_unit for details. */
11198 static struct dwo_unit
*
11199 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
11200 const char *dwo_name
, const char *comp_dir
,
11201 ULONGEST signature
)
11203 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
11206 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
11207 See lookup_dwo_cutu_unit for details. */
11209 static struct dwo_unit
*
11210 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
11211 const char *dwo_name
, const char *comp_dir
)
11213 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
11216 /* Traversal function for queue_and_load_all_dwo_tus. */
11219 queue_and_load_dwo_tu (void **slot
, void *info
)
11221 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
11222 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
11223 ULONGEST signature
= dwo_unit
->signature
;
11224 struct signatured_type
*sig_type
=
11225 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
11227 if (sig_type
!= NULL
)
11229 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
11231 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
11232 a real dependency of PER_CU on SIG_TYPE. That is detected later
11233 while processing PER_CU. */
11234 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
11235 load_full_type_unit (sig_cu
);
11236 VEC_safe_push (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, sig_cu
);
11242 /* Queue all TUs contained in the DWO of PER_CU to be read in.
11243 The DWO may have the only definition of the type, though it may not be
11244 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
11245 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
11248 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
11250 struct dwo_unit
*dwo_unit
;
11251 struct dwo_file
*dwo_file
;
11253 gdb_assert (!per_cu
->is_debug_types
);
11254 gdb_assert (get_dwp_file () == NULL
);
11255 gdb_assert (per_cu
->cu
!= NULL
);
11257 dwo_unit
= per_cu
->cu
->dwo_unit
;
11258 gdb_assert (dwo_unit
!= NULL
);
11260 dwo_file
= dwo_unit
->dwo_file
;
11261 if (dwo_file
->tus
!= NULL
)
11262 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
11265 /* Free all resources associated with DWO_FILE.
11266 Close the DWO file and munmap the sections.
11267 All memory should be on the objfile obstack. */
11270 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
11273 /* Note: dbfd is NULL for virtual DWO files. */
11274 gdb_bfd_unref (dwo_file
->dbfd
);
11276 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
11279 /* Wrapper for free_dwo_file for use in cleanups. */
11282 free_dwo_file_cleanup (void *arg
)
11284 struct dwo_file
*dwo_file
= (struct dwo_file
*) arg
;
11285 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11287 free_dwo_file (dwo_file
, objfile
);
11290 /* Traversal function for free_dwo_files. */
11293 free_dwo_file_from_slot (void **slot
, void *info
)
11295 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
11296 struct objfile
*objfile
= (struct objfile
*) info
;
11298 free_dwo_file (dwo_file
, objfile
);
11303 /* Free all resources associated with DWO_FILES. */
11306 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
11308 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
11311 /* Read in various DIEs. */
11313 /* qsort helper for inherit_abstract_dies. */
11316 unsigned_int_compar (const void *ap
, const void *bp
)
11318 unsigned int a
= *(unsigned int *) ap
;
11319 unsigned int b
= *(unsigned int *) bp
;
11321 return (a
> b
) - (b
> a
);
11324 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
11325 Inherit only the children of the DW_AT_abstract_origin DIE not being
11326 already referenced by DW_AT_abstract_origin from the children of the
11330 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
11332 struct die_info
*child_die
;
11333 unsigned die_children_count
;
11334 /* CU offsets which were referenced by children of the current DIE. */
11335 sect_offset
*offsets
;
11336 sect_offset
*offsets_end
, *offsetp
;
11337 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
11338 struct die_info
*origin_die
;
11339 /* Iterator of the ORIGIN_DIE children. */
11340 struct die_info
*origin_child_die
;
11341 struct cleanup
*cleanups
;
11342 struct attribute
*attr
;
11343 struct dwarf2_cu
*origin_cu
;
11344 struct pending
**origin_previous_list_in_scope
;
11346 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
11350 /* Note that following die references may follow to a die in a
11354 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
11356 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
11358 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
11359 origin_cu
->list_in_scope
= cu
->list_in_scope
;
11361 if (die
->tag
!= origin_die
->tag
11362 && !(die
->tag
== DW_TAG_inlined_subroutine
11363 && origin_die
->tag
== DW_TAG_subprogram
))
11364 complaint (&symfile_complaints
,
11365 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
11366 to_underlying (die
->sect_off
),
11367 to_underlying (origin_die
->sect_off
));
11369 child_die
= die
->child
;
11370 die_children_count
= 0;
11371 while (child_die
&& child_die
->tag
)
11373 child_die
= sibling_die (child_die
);
11374 die_children_count
++;
11376 offsets
= XNEWVEC (sect_offset
, die_children_count
);
11377 cleanups
= make_cleanup (xfree
, offsets
);
11379 offsets_end
= offsets
;
11380 for (child_die
= die
->child
;
11381 child_die
&& child_die
->tag
;
11382 child_die
= sibling_die (child_die
))
11384 struct die_info
*child_origin_die
;
11385 struct dwarf2_cu
*child_origin_cu
;
11387 /* We are trying to process concrete instance entries:
11388 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
11389 it's not relevant to our analysis here. i.e. detecting DIEs that are
11390 present in the abstract instance but not referenced in the concrete
11392 if (child_die
->tag
== DW_TAG_call_site
11393 || child_die
->tag
== DW_TAG_GNU_call_site
)
11396 /* For each CHILD_DIE, find the corresponding child of
11397 ORIGIN_DIE. If there is more than one layer of
11398 DW_AT_abstract_origin, follow them all; there shouldn't be,
11399 but GCC versions at least through 4.4 generate this (GCC PR
11401 child_origin_die
= child_die
;
11402 child_origin_cu
= cu
;
11405 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
11409 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
11413 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
11414 counterpart may exist. */
11415 if (child_origin_die
!= child_die
)
11417 if (child_die
->tag
!= child_origin_die
->tag
11418 && !(child_die
->tag
== DW_TAG_inlined_subroutine
11419 && child_origin_die
->tag
== DW_TAG_subprogram
))
11420 complaint (&symfile_complaints
,
11421 _("Child DIE 0x%x and its abstract origin 0x%x have "
11423 to_underlying (child_die
->sect_off
),
11424 to_underlying (child_origin_die
->sect_off
));
11425 if (child_origin_die
->parent
!= origin_die
)
11426 complaint (&symfile_complaints
,
11427 _("Child DIE 0x%x and its abstract origin 0x%x have "
11428 "different parents"),
11429 to_underlying (child_die
->sect_off
),
11430 to_underlying (child_origin_die
->sect_off
));
11432 *offsets_end
++ = child_origin_die
->sect_off
;
11435 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
11436 unsigned_int_compar
);
11437 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
11438 if (offsetp
[-1] == *offsetp
)
11439 complaint (&symfile_complaints
,
11440 _("Multiple children of DIE 0x%x refer "
11441 "to DIE 0x%x as their abstract origin"),
11442 to_underlying (die
->sect_off
), to_underlying (*offsetp
));
11445 origin_child_die
= origin_die
->child
;
11446 while (origin_child_die
&& origin_child_die
->tag
)
11448 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
11449 while (offsetp
< offsets_end
11450 && *offsetp
< origin_child_die
->sect_off
)
11452 if (offsetp
>= offsets_end
11453 || *offsetp
> origin_child_die
->sect_off
)
11455 /* Found that ORIGIN_CHILD_DIE is really not referenced.
11456 Check whether we're already processing ORIGIN_CHILD_DIE.
11457 This can happen with mutually referenced abstract_origins.
11459 if (!origin_child_die
->in_process
)
11460 process_die (origin_child_die
, origin_cu
);
11462 origin_child_die
= sibling_die (origin_child_die
);
11464 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
11466 do_cleanups (cleanups
);
11470 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11472 struct objfile
*objfile
= cu
->objfile
;
11473 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11474 struct context_stack
*newobj
;
11477 struct die_info
*child_die
;
11478 struct attribute
*attr
, *call_line
, *call_file
;
11480 CORE_ADDR baseaddr
;
11481 struct block
*block
;
11482 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
11483 VEC (symbolp
) *template_args
= NULL
;
11484 struct template_symbol
*templ_func
= NULL
;
11488 /* If we do not have call site information, we can't show the
11489 caller of this inlined function. That's too confusing, so
11490 only use the scope for local variables. */
11491 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
11492 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
11493 if (call_line
== NULL
|| call_file
== NULL
)
11495 read_lexical_block_scope (die
, cu
);
11500 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11502 name
= dwarf2_name (die
, cu
);
11504 /* Ignore functions with missing or empty names. These are actually
11505 illegal according to the DWARF standard. */
11508 complaint (&symfile_complaints
,
11509 _("missing name for subprogram DIE at %d"),
11510 to_underlying (die
->sect_off
));
11514 /* Ignore functions with missing or invalid low and high pc attributes. */
11515 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
11516 <= PC_BOUNDS_INVALID
)
11518 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
11519 if (!attr
|| !DW_UNSND (attr
))
11520 complaint (&symfile_complaints
,
11521 _("cannot get low and high bounds "
11522 "for subprogram DIE at %d"),
11523 to_underlying (die
->sect_off
));
11527 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11528 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
11530 /* If we have any template arguments, then we must allocate a
11531 different sort of symbol. */
11532 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
11534 if (child_die
->tag
== DW_TAG_template_type_param
11535 || child_die
->tag
== DW_TAG_template_value_param
)
11537 templ_func
= allocate_template_symbol (objfile
);
11538 templ_func
->base
.is_cplus_template_function
= 1;
11543 newobj
= push_context (0, lowpc
);
11544 newobj
->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
11545 (struct symbol
*) templ_func
);
11547 /* If there is a location expression for DW_AT_frame_base, record
11549 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
11551 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
11553 /* If there is a location for the static link, record it. */
11554 newobj
->static_link
= NULL
;
11555 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
11558 newobj
->static_link
11559 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
11560 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
);
11563 cu
->list_in_scope
= &local_symbols
;
11565 if (die
->child
!= NULL
)
11567 child_die
= die
->child
;
11568 while (child_die
&& child_die
->tag
)
11570 if (child_die
->tag
== DW_TAG_template_type_param
11571 || child_die
->tag
== DW_TAG_template_value_param
)
11573 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
11576 VEC_safe_push (symbolp
, template_args
, arg
);
11579 process_die (child_die
, cu
);
11580 child_die
= sibling_die (child_die
);
11584 inherit_abstract_dies (die
, cu
);
11586 /* If we have a DW_AT_specification, we might need to import using
11587 directives from the context of the specification DIE. See the
11588 comment in determine_prefix. */
11589 if (cu
->language
== language_cplus
11590 && dwarf2_attr (die
, DW_AT_specification
, cu
))
11592 struct dwarf2_cu
*spec_cu
= cu
;
11593 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
11597 child_die
= spec_die
->child
;
11598 while (child_die
&& child_die
->tag
)
11600 if (child_die
->tag
== DW_TAG_imported_module
)
11601 process_die (child_die
, spec_cu
);
11602 child_die
= sibling_die (child_die
);
11605 /* In some cases, GCC generates specification DIEs that
11606 themselves contain DW_AT_specification attributes. */
11607 spec_die
= die_specification (spec_die
, &spec_cu
);
11611 newobj
= pop_context ();
11612 /* Make a block for the local symbols within. */
11613 block
= finish_block (newobj
->name
, &local_symbols
, newobj
->old_blocks
,
11614 newobj
->static_link
, lowpc
, highpc
);
11616 /* For C++, set the block's scope. */
11617 if ((cu
->language
== language_cplus
11618 || cu
->language
== language_fortran
11619 || cu
->language
== language_d
11620 || cu
->language
== language_rust
)
11621 && cu
->processing_has_namespace_info
)
11622 block_set_scope (block
, determine_prefix (die
, cu
),
11623 &objfile
->objfile_obstack
);
11625 /* If we have address ranges, record them. */
11626 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
11628 gdbarch_make_symbol_special (gdbarch
, newobj
->name
, objfile
);
11630 /* Attach template arguments to function. */
11631 if (! VEC_empty (symbolp
, template_args
))
11633 gdb_assert (templ_func
!= NULL
);
11635 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
11636 templ_func
->template_arguments
11637 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
11638 templ_func
->n_template_arguments
);
11639 memcpy (templ_func
->template_arguments
,
11640 VEC_address (symbolp
, template_args
),
11641 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
11642 VEC_free (symbolp
, template_args
);
11645 /* In C++, we can have functions nested inside functions (e.g., when
11646 a function declares a class that has methods). This means that
11647 when we finish processing a function scope, we may need to go
11648 back to building a containing block's symbol lists. */
11649 local_symbols
= newobj
->locals
;
11650 local_using_directives
= newobj
->local_using_directives
;
11652 /* If we've finished processing a top-level function, subsequent
11653 symbols go in the file symbol list. */
11654 if (outermost_context_p ())
11655 cu
->list_in_scope
= &file_symbols
;
11658 /* Process all the DIES contained within a lexical block scope. Start
11659 a new scope, process the dies, and then close the scope. */
11662 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11664 struct objfile
*objfile
= cu
->objfile
;
11665 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11666 struct context_stack
*newobj
;
11667 CORE_ADDR lowpc
, highpc
;
11668 struct die_info
*child_die
;
11669 CORE_ADDR baseaddr
;
11671 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11673 /* Ignore blocks with missing or invalid low and high pc attributes. */
11674 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
11675 as multiple lexical blocks? Handling children in a sane way would
11676 be nasty. Might be easier to properly extend generic blocks to
11677 describe ranges. */
11678 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
11680 case PC_BOUNDS_NOT_PRESENT
:
11681 /* DW_TAG_lexical_block has no attributes, process its children as if
11682 there was no wrapping by that DW_TAG_lexical_block.
11683 GCC does no longer produces such DWARF since GCC r224161. */
11684 for (child_die
= die
->child
;
11685 child_die
!= NULL
&& child_die
->tag
;
11686 child_die
= sibling_die (child_die
))
11687 process_die (child_die
, cu
);
11689 case PC_BOUNDS_INVALID
:
11692 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11693 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
11695 push_context (0, lowpc
);
11696 if (die
->child
!= NULL
)
11698 child_die
= die
->child
;
11699 while (child_die
&& child_die
->tag
)
11701 process_die (child_die
, cu
);
11702 child_die
= sibling_die (child_die
);
11705 inherit_abstract_dies (die
, cu
);
11706 newobj
= pop_context ();
11708 if (local_symbols
!= NULL
|| local_using_directives
!= NULL
)
11710 struct block
*block
11711 = finish_block (0, &local_symbols
, newobj
->old_blocks
, NULL
,
11712 newobj
->start_addr
, highpc
);
11714 /* Note that recording ranges after traversing children, as we
11715 do here, means that recording a parent's ranges entails
11716 walking across all its children's ranges as they appear in
11717 the address map, which is quadratic behavior.
11719 It would be nicer to record the parent's ranges before
11720 traversing its children, simply overriding whatever you find
11721 there. But since we don't even decide whether to create a
11722 block until after we've traversed its children, that's hard
11724 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
11726 local_symbols
= newobj
->locals
;
11727 local_using_directives
= newobj
->local_using_directives
;
11730 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
11733 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11735 struct objfile
*objfile
= cu
->objfile
;
11736 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11737 CORE_ADDR pc
, baseaddr
;
11738 struct attribute
*attr
;
11739 struct call_site
*call_site
, call_site_local
;
11742 struct die_info
*child_die
;
11744 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11746 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
11749 /* This was a pre-DWARF-5 GNU extension alias
11750 for DW_AT_call_return_pc. */
11751 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11755 complaint (&symfile_complaints
,
11756 _("missing DW_AT_call_return_pc for DW_TAG_call_site "
11757 "DIE 0x%x [in module %s]"),
11758 to_underlying (die
->sect_off
), objfile_name (objfile
));
11761 pc
= attr_value_as_address (attr
) + baseaddr
;
11762 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
11764 if (cu
->call_site_htab
== NULL
)
11765 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
11766 NULL
, &objfile
->objfile_obstack
,
11767 hashtab_obstack_allocate
, NULL
);
11768 call_site_local
.pc
= pc
;
11769 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
11772 complaint (&symfile_complaints
,
11773 _("Duplicate PC %s for DW_TAG_call_site "
11774 "DIE 0x%x [in module %s]"),
11775 paddress (gdbarch
, pc
), to_underlying (die
->sect_off
),
11776 objfile_name (objfile
));
11780 /* Count parameters at the caller. */
11783 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11784 child_die
= sibling_die (child_die
))
11786 if (child_die
->tag
!= DW_TAG_call_site_parameter
11787 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
11789 complaint (&symfile_complaints
,
11790 _("Tag %d is not DW_TAG_call_site_parameter in "
11791 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
11792 child_die
->tag
, to_underlying (child_die
->sect_off
),
11793 objfile_name (objfile
));
11801 = ((struct call_site
*)
11802 obstack_alloc (&objfile
->objfile_obstack
,
11803 sizeof (*call_site
)
11804 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
11806 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
11807 call_site
->pc
= pc
;
11809 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
11810 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
11812 struct die_info
*func_die
;
11814 /* Skip also over DW_TAG_inlined_subroutine. */
11815 for (func_die
= die
->parent
;
11816 func_die
&& func_die
->tag
!= DW_TAG_subprogram
11817 && func_die
->tag
!= DW_TAG_subroutine_type
;
11818 func_die
= func_die
->parent
);
11820 /* DW_AT_call_all_calls is a superset
11821 of DW_AT_call_all_tail_calls. */
11823 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
11824 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
11825 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
11826 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
11828 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
11829 not complete. But keep CALL_SITE for look ups via call_site_htab,
11830 both the initial caller containing the real return address PC and
11831 the final callee containing the current PC of a chain of tail
11832 calls do not need to have the tail call list complete. But any
11833 function candidate for a virtual tail call frame searched via
11834 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
11835 determined unambiguously. */
11839 struct type
*func_type
= NULL
;
11842 func_type
= get_die_type (func_die
, cu
);
11843 if (func_type
!= NULL
)
11845 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
11847 /* Enlist this call site to the function. */
11848 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
11849 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
11852 complaint (&symfile_complaints
,
11853 _("Cannot find function owning DW_TAG_call_site "
11854 "DIE 0x%x [in module %s]"),
11855 to_underlying (die
->sect_off
), objfile_name (objfile
));
11859 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
11861 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
11863 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
11866 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
11867 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
11869 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
11870 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
11871 /* Keep NULL DWARF_BLOCK. */;
11872 else if (attr_form_is_block (attr
))
11874 struct dwarf2_locexpr_baton
*dlbaton
;
11876 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
11877 dlbaton
->data
= DW_BLOCK (attr
)->data
;
11878 dlbaton
->size
= DW_BLOCK (attr
)->size
;
11879 dlbaton
->per_cu
= cu
->per_cu
;
11881 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
11883 else if (attr_form_is_ref (attr
))
11885 struct dwarf2_cu
*target_cu
= cu
;
11886 struct die_info
*target_die
;
11888 target_die
= follow_die_ref (die
, attr
, &target_cu
);
11889 gdb_assert (target_cu
->objfile
== objfile
);
11890 if (die_is_declaration (target_die
, target_cu
))
11892 const char *target_physname
;
11894 /* Prefer the mangled name; otherwise compute the demangled one. */
11895 target_physname
= dwarf2_string_attr (target_die
,
11896 DW_AT_linkage_name
,
11898 if (target_physname
== NULL
)
11899 target_physname
= dwarf2_string_attr (target_die
,
11900 DW_AT_MIPS_linkage_name
,
11902 if (target_physname
== NULL
)
11903 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
11904 if (target_physname
== NULL
)
11905 complaint (&symfile_complaints
,
11906 _("DW_AT_call_target target DIE has invalid "
11907 "physname, for referencing DIE 0x%x [in module %s]"),
11908 to_underlying (die
->sect_off
), objfile_name (objfile
));
11910 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
11916 /* DW_AT_entry_pc should be preferred. */
11917 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
11918 <= PC_BOUNDS_INVALID
)
11919 complaint (&symfile_complaints
,
11920 _("DW_AT_call_target target DIE has invalid "
11921 "low pc, for referencing DIE 0x%x [in module %s]"),
11922 to_underlying (die
->sect_off
), objfile_name (objfile
));
11925 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11926 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
11931 complaint (&symfile_complaints
,
11932 _("DW_TAG_call_site DW_AT_call_target is neither "
11933 "block nor reference, for DIE 0x%x [in module %s]"),
11934 to_underlying (die
->sect_off
), objfile_name (objfile
));
11936 call_site
->per_cu
= cu
->per_cu
;
11938 for (child_die
= die
->child
;
11939 child_die
&& child_die
->tag
;
11940 child_die
= sibling_die (child_die
))
11942 struct call_site_parameter
*parameter
;
11943 struct attribute
*loc
, *origin
;
11945 if (child_die
->tag
!= DW_TAG_call_site_parameter
11946 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
11948 /* Already printed the complaint above. */
11952 gdb_assert (call_site
->parameter_count
< nparams
);
11953 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
11955 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
11956 specifies DW_TAG_formal_parameter. Value of the data assumed for the
11957 register is contained in DW_AT_call_value. */
11959 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
11960 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
11961 if (origin
== NULL
)
11963 /* This was a pre-DWARF-5 GNU extension alias
11964 for DW_AT_call_parameter. */
11965 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
11967 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
11969 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
11971 sect_offset sect_off
11972 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
11973 if (!offset_in_cu_p (&cu
->header
, sect_off
))
11975 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
11976 binding can be done only inside one CU. Such referenced DIE
11977 therefore cannot be even moved to DW_TAG_partial_unit. */
11978 complaint (&symfile_complaints
,
11979 _("DW_AT_call_parameter offset is not in CU for "
11980 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
11981 to_underlying (child_die
->sect_off
),
11982 objfile_name (objfile
));
11985 parameter
->u
.param_cu_off
11986 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
11988 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
11990 complaint (&symfile_complaints
,
11991 _("No DW_FORM_block* DW_AT_location for "
11992 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
11993 to_underlying (child_die
->sect_off
), objfile_name (objfile
));
11998 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
11999 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
12000 if (parameter
->u
.dwarf_reg
!= -1)
12001 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
12002 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
12003 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
12004 ¶meter
->u
.fb_offset
))
12005 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
12008 complaint (&symfile_complaints
,
12009 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
12010 "for DW_FORM_block* DW_AT_location is supported for "
12011 "DW_TAG_call_site child DIE 0x%x "
12013 to_underlying (child_die
->sect_off
),
12014 objfile_name (objfile
));
12019 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
12021 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
12022 if (!attr_form_is_block (attr
))
12024 complaint (&symfile_complaints
,
12025 _("No DW_FORM_block* DW_AT_call_value for "
12026 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
12027 to_underlying (child_die
->sect_off
),
12028 objfile_name (objfile
));
12031 parameter
->value
= DW_BLOCK (attr
)->data
;
12032 parameter
->value_size
= DW_BLOCK (attr
)->size
;
12034 /* Parameters are not pre-cleared by memset above. */
12035 parameter
->data_value
= NULL
;
12036 parameter
->data_value_size
= 0;
12037 call_site
->parameter_count
++;
12039 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
12041 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
12044 if (!attr_form_is_block (attr
))
12045 complaint (&symfile_complaints
,
12046 _("No DW_FORM_block* DW_AT_call_data_value for "
12047 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
12048 to_underlying (child_die
->sect_off
),
12049 objfile_name (objfile
));
12052 parameter
->data_value
= DW_BLOCK (attr
)->data
;
12053 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
12059 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
12060 reading .debug_rnglists.
12061 Callback's type should be:
12062 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
12063 Return true if the attributes are present and valid, otherwise,
12066 template <typename Callback
>
12068 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
12069 Callback
&&callback
)
12071 struct objfile
*objfile
= cu
->objfile
;
12072 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12073 struct comp_unit_head
*cu_header
= &cu
->header
;
12074 bfd
*obfd
= objfile
->obfd
;
12075 unsigned int addr_size
= cu_header
->addr_size
;
12076 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
12077 /* Base address selection entry. */
12080 unsigned int dummy
;
12081 const gdb_byte
*buffer
;
12083 CORE_ADDR high
= 0;
12084 CORE_ADDR baseaddr
;
12085 bool overflow
= false;
12087 found_base
= cu
->base_known
;
12088 base
= cu
->base_address
;
12090 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->rnglists
);
12091 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
12093 complaint (&symfile_complaints
,
12094 _("Offset %d out of bounds for DW_AT_ranges attribute"),
12098 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
12100 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
12104 /* Initialize it due to a false compiler warning. */
12105 CORE_ADDR range_beginning
= 0, range_end
= 0;
12106 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
12107 + dwarf2_per_objfile
->rnglists
.size
);
12108 unsigned int bytes_read
;
12110 if (buffer
== buf_end
)
12115 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
12118 case DW_RLE_end_of_list
:
12120 case DW_RLE_base_address
:
12121 if (buffer
+ cu
->header
.addr_size
> buf_end
)
12126 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
12128 buffer
+= bytes_read
;
12130 case DW_RLE_start_length
:
12131 if (buffer
+ cu
->header
.addr_size
> buf_end
)
12136 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
12137 buffer
+= bytes_read
;
12138 range_end
= (range_beginning
12139 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
12140 buffer
+= bytes_read
;
12141 if (buffer
> buf_end
)
12147 case DW_RLE_offset_pair
:
12148 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
12149 buffer
+= bytes_read
;
12150 if (buffer
> buf_end
)
12155 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
12156 buffer
+= bytes_read
;
12157 if (buffer
> buf_end
)
12163 case DW_RLE_start_end
:
12164 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
12169 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
12170 buffer
+= bytes_read
;
12171 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
12172 buffer
+= bytes_read
;
12175 complaint (&symfile_complaints
,
12176 _("Invalid .debug_rnglists data (no base address)"));
12179 if (rlet
== DW_RLE_end_of_list
|| overflow
)
12181 if (rlet
== DW_RLE_base_address
)
12186 /* We have no valid base address for the ranges
12188 complaint (&symfile_complaints
,
12189 _("Invalid .debug_rnglists data (no base address)"));
12193 if (range_beginning
> range_end
)
12195 /* Inverted range entries are invalid. */
12196 complaint (&symfile_complaints
,
12197 _("Invalid .debug_rnglists data (inverted range)"));
12201 /* Empty range entries have no effect. */
12202 if (range_beginning
== range_end
)
12205 range_beginning
+= base
;
12208 /* A not-uncommon case of bad debug info.
12209 Don't pollute the addrmap with bad data. */
12210 if (range_beginning
+ baseaddr
== 0
12211 && !dwarf2_per_objfile
->has_section_at_zero
)
12213 complaint (&symfile_complaints
,
12214 _(".debug_rnglists entry has start address of zero"
12215 " [in module %s]"), objfile_name (objfile
));
12219 callback (range_beginning
, range_end
);
12224 complaint (&symfile_complaints
,
12225 _("Offset %d is not terminated "
12226 "for DW_AT_ranges attribute"),
12234 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
12235 Callback's type should be:
12236 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
12237 Return 1 if the attributes are present and valid, otherwise, return 0. */
12239 template <typename Callback
>
12241 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
12242 Callback
&&callback
)
12244 struct objfile
*objfile
= cu
->objfile
;
12245 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12246 struct comp_unit_head
*cu_header
= &cu
->header
;
12247 bfd
*obfd
= objfile
->obfd
;
12248 unsigned int addr_size
= cu_header
->addr_size
;
12249 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
12250 /* Base address selection entry. */
12253 unsigned int dummy
;
12254 const gdb_byte
*buffer
;
12255 CORE_ADDR baseaddr
;
12257 if (cu_header
->version
>= 5)
12258 return dwarf2_rnglists_process (offset
, cu
, callback
);
12260 found_base
= cu
->base_known
;
12261 base
= cu
->base_address
;
12263 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
12264 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
12266 complaint (&symfile_complaints
,
12267 _("Offset %d out of bounds for DW_AT_ranges attribute"),
12271 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
12273 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
12277 CORE_ADDR range_beginning
, range_end
;
12279 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
12280 buffer
+= addr_size
;
12281 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
12282 buffer
+= addr_size
;
12283 offset
+= 2 * addr_size
;
12285 /* An end of list marker is a pair of zero addresses. */
12286 if (range_beginning
== 0 && range_end
== 0)
12287 /* Found the end of list entry. */
12290 /* Each base address selection entry is a pair of 2 values.
12291 The first is the largest possible address, the second is
12292 the base address. Check for a base address here. */
12293 if ((range_beginning
& mask
) == mask
)
12295 /* If we found the largest possible address, then we already
12296 have the base address in range_end. */
12304 /* We have no valid base address for the ranges
12306 complaint (&symfile_complaints
,
12307 _("Invalid .debug_ranges data (no base address)"));
12311 if (range_beginning
> range_end
)
12313 /* Inverted range entries are invalid. */
12314 complaint (&symfile_complaints
,
12315 _("Invalid .debug_ranges data (inverted range)"));
12319 /* Empty range entries have no effect. */
12320 if (range_beginning
== range_end
)
12323 range_beginning
+= base
;
12326 /* A not-uncommon case of bad debug info.
12327 Don't pollute the addrmap with bad data. */
12328 if (range_beginning
+ baseaddr
== 0
12329 && !dwarf2_per_objfile
->has_section_at_zero
)
12331 complaint (&symfile_complaints
,
12332 _(".debug_ranges entry has start address of zero"
12333 " [in module %s]"), objfile_name (objfile
));
12337 callback (range_beginning
, range_end
);
12343 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
12344 Return 1 if the attributes are present and valid, otherwise, return 0.
12345 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
12348 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
12349 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
12350 struct partial_symtab
*ranges_pst
)
12352 struct objfile
*objfile
= cu
->objfile
;
12353 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12354 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
12355 SECT_OFF_TEXT (objfile
));
12358 CORE_ADDR high
= 0;
12361 retval
= dwarf2_ranges_process (offset
, cu
,
12362 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
12364 if (ranges_pst
!= NULL
)
12369 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
12370 range_beginning
+ baseaddr
);
12371 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
12372 range_end
+ baseaddr
);
12373 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
12377 /* FIXME: This is recording everything as a low-high
12378 segment of consecutive addresses. We should have a
12379 data structure for discontiguous block ranges
12383 low
= range_beginning
;
12389 if (range_beginning
< low
)
12390 low
= range_beginning
;
12391 if (range_end
> high
)
12399 /* If the first entry is an end-of-list marker, the range
12400 describes an empty scope, i.e. no instructions. */
12406 *high_return
= high
;
12410 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
12411 definition for the return value. *LOWPC and *HIGHPC are set iff
12412 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
12414 static enum pc_bounds_kind
12415 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
12416 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
12417 struct partial_symtab
*pst
)
12419 struct attribute
*attr
;
12420 struct attribute
*attr_high
;
12422 CORE_ADDR high
= 0;
12423 enum pc_bounds_kind ret
;
12425 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
12428 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
12431 low
= attr_value_as_address (attr
);
12432 high
= attr_value_as_address (attr_high
);
12433 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
12437 /* Found high w/o low attribute. */
12438 return PC_BOUNDS_INVALID
;
12440 /* Found consecutive range of addresses. */
12441 ret
= PC_BOUNDS_HIGH_LOW
;
12445 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
12448 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
12449 We take advantage of the fact that DW_AT_ranges does not appear
12450 in DW_TAG_compile_unit of DWO files. */
12451 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
12452 unsigned int ranges_offset
= (DW_UNSND (attr
)
12453 + (need_ranges_base
12457 /* Value of the DW_AT_ranges attribute is the offset in the
12458 .debug_ranges section. */
12459 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
12460 return PC_BOUNDS_INVALID
;
12461 /* Found discontinuous range of addresses. */
12462 ret
= PC_BOUNDS_RANGES
;
12465 return PC_BOUNDS_NOT_PRESENT
;
12468 /* read_partial_die has also the strict LOW < HIGH requirement. */
12470 return PC_BOUNDS_INVALID
;
12472 /* When using the GNU linker, .gnu.linkonce. sections are used to
12473 eliminate duplicate copies of functions and vtables and such.
12474 The linker will arbitrarily choose one and discard the others.
12475 The AT_*_pc values for such functions refer to local labels in
12476 these sections. If the section from that file was discarded, the
12477 labels are not in the output, so the relocs get a value of 0.
12478 If this is a discarded function, mark the pc bounds as invalid,
12479 so that GDB will ignore it. */
12480 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
12481 return PC_BOUNDS_INVALID
;
12489 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
12490 its low and high PC addresses. Do nothing if these addresses could not
12491 be determined. Otherwise, set LOWPC to the low address if it is smaller,
12492 and HIGHPC to the high address if greater than HIGHPC. */
12495 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
12496 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
12497 struct dwarf2_cu
*cu
)
12499 CORE_ADDR low
, high
;
12500 struct die_info
*child
= die
->child
;
12502 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
12504 *lowpc
= std::min (*lowpc
, low
);
12505 *highpc
= std::max (*highpc
, high
);
12508 /* If the language does not allow nested subprograms (either inside
12509 subprograms or lexical blocks), we're done. */
12510 if (cu
->language
!= language_ada
)
12513 /* Check all the children of the given DIE. If it contains nested
12514 subprograms, then check their pc bounds. Likewise, we need to
12515 check lexical blocks as well, as they may also contain subprogram
12517 while (child
&& child
->tag
)
12519 if (child
->tag
== DW_TAG_subprogram
12520 || child
->tag
== DW_TAG_lexical_block
)
12521 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
12522 child
= sibling_die (child
);
12526 /* Get the low and high pc's represented by the scope DIE, and store
12527 them in *LOWPC and *HIGHPC. If the correct values can't be
12528 determined, set *LOWPC to -1 and *HIGHPC to 0. */
12531 get_scope_pc_bounds (struct die_info
*die
,
12532 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
12533 struct dwarf2_cu
*cu
)
12535 CORE_ADDR best_low
= (CORE_ADDR
) -1;
12536 CORE_ADDR best_high
= (CORE_ADDR
) 0;
12537 CORE_ADDR current_low
, current_high
;
12539 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
12540 >= PC_BOUNDS_RANGES
)
12542 best_low
= current_low
;
12543 best_high
= current_high
;
12547 struct die_info
*child
= die
->child
;
12549 while (child
&& child
->tag
)
12551 switch (child
->tag
) {
12552 case DW_TAG_subprogram
:
12553 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
12555 case DW_TAG_namespace
:
12556 case DW_TAG_module
:
12557 /* FIXME: carlton/2004-01-16: Should we do this for
12558 DW_TAG_class_type/DW_TAG_structure_type, too? I think
12559 that current GCC's always emit the DIEs corresponding
12560 to definitions of methods of classes as children of a
12561 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
12562 the DIEs giving the declarations, which could be
12563 anywhere). But I don't see any reason why the
12564 standards says that they have to be there. */
12565 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
12567 if (current_low
!= ((CORE_ADDR
) -1))
12569 best_low
= std::min (best_low
, current_low
);
12570 best_high
= std::max (best_high
, current_high
);
12578 child
= sibling_die (child
);
12583 *highpc
= best_high
;
12586 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
12590 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
12591 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
12593 struct objfile
*objfile
= cu
->objfile
;
12594 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12595 struct attribute
*attr
;
12596 struct attribute
*attr_high
;
12598 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
12601 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
12604 CORE_ADDR low
= attr_value_as_address (attr
);
12605 CORE_ADDR high
= attr_value_as_address (attr_high
);
12607 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
12610 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
12611 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
12612 record_block_range (block
, low
, high
- 1);
12616 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
12619 bfd
*obfd
= objfile
->obfd
;
12620 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
12621 We take advantage of the fact that DW_AT_ranges does not appear
12622 in DW_TAG_compile_unit of DWO files. */
12623 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
12625 /* The value of the DW_AT_ranges attribute is the offset of the
12626 address range list in the .debug_ranges section. */
12627 unsigned long offset
= (DW_UNSND (attr
)
12628 + (need_ranges_base
? cu
->ranges_base
: 0));
12629 const gdb_byte
*buffer
;
12631 /* For some target architectures, but not others, the
12632 read_address function sign-extends the addresses it returns.
12633 To recognize base address selection entries, we need a
12635 unsigned int addr_size
= cu
->header
.addr_size
;
12636 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
12638 /* The base address, to which the next pair is relative. Note
12639 that this 'base' is a DWARF concept: most entries in a range
12640 list are relative, to reduce the number of relocs against the
12641 debugging information. This is separate from this function's
12642 'baseaddr' argument, which GDB uses to relocate debugging
12643 information from a shared library based on the address at
12644 which the library was loaded. */
12645 CORE_ADDR base
= cu
->base_address
;
12646 int base_known
= cu
->base_known
;
12648 dwarf2_ranges_process (offset
, cu
,
12649 [&] (CORE_ADDR start
, CORE_ADDR end
)
12653 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
12654 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
12655 record_block_range (block
, start
, end
- 1);
12660 /* Check whether the producer field indicates either of GCC < 4.6, or the
12661 Intel C/C++ compiler, and cache the result in CU. */
12664 check_producer (struct dwarf2_cu
*cu
)
12668 if (cu
->producer
== NULL
)
12670 /* For unknown compilers expect their behavior is DWARF version
12673 GCC started to support .debug_types sections by -gdwarf-4 since
12674 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
12675 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
12676 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
12677 interpreted incorrectly by GDB now - GCC PR debug/48229. */
12679 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
12681 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
12682 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
12684 else if (startswith (cu
->producer
, "Intel(R) C"))
12685 cu
->producer_is_icc
= 1;
12688 /* For other non-GCC compilers, expect their behavior is DWARF version
12692 cu
->checked_producer
= 1;
12695 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
12696 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
12697 during 4.6.0 experimental. */
12700 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
12702 if (!cu
->checked_producer
)
12703 check_producer (cu
);
12705 return cu
->producer_is_gxx_lt_4_6
;
12708 /* Return the default accessibility type if it is not overriden by
12709 DW_AT_accessibility. */
12711 static enum dwarf_access_attribute
12712 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
12714 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
12716 /* The default DWARF 2 accessibility for members is public, the default
12717 accessibility for inheritance is private. */
12719 if (die
->tag
!= DW_TAG_inheritance
)
12720 return DW_ACCESS_public
;
12722 return DW_ACCESS_private
;
12726 /* DWARF 3+ defines the default accessibility a different way. The same
12727 rules apply now for DW_TAG_inheritance as for the members and it only
12728 depends on the container kind. */
12730 if (die
->parent
->tag
== DW_TAG_class_type
)
12731 return DW_ACCESS_private
;
12733 return DW_ACCESS_public
;
12737 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
12738 offset. If the attribute was not found return 0, otherwise return
12739 1. If it was found but could not properly be handled, set *OFFSET
12743 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
12746 struct attribute
*attr
;
12748 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
12753 /* Note that we do not check for a section offset first here.
12754 This is because DW_AT_data_member_location is new in DWARF 4,
12755 so if we see it, we can assume that a constant form is really
12756 a constant and not a section offset. */
12757 if (attr_form_is_constant (attr
))
12758 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
12759 else if (attr_form_is_section_offset (attr
))
12760 dwarf2_complex_location_expr_complaint ();
12761 else if (attr_form_is_block (attr
))
12762 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
12764 dwarf2_complex_location_expr_complaint ();
12772 /* Add an aggregate field to the field list. */
12775 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
12776 struct dwarf2_cu
*cu
)
12778 struct objfile
*objfile
= cu
->objfile
;
12779 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12780 struct nextfield
*new_field
;
12781 struct attribute
*attr
;
12783 const char *fieldname
= "";
12785 /* Allocate a new field list entry and link it in. */
12786 new_field
= XNEW (struct nextfield
);
12787 make_cleanup (xfree
, new_field
);
12788 memset (new_field
, 0, sizeof (struct nextfield
));
12790 if (die
->tag
== DW_TAG_inheritance
)
12792 new_field
->next
= fip
->baseclasses
;
12793 fip
->baseclasses
= new_field
;
12797 new_field
->next
= fip
->fields
;
12798 fip
->fields
= new_field
;
12802 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
12804 new_field
->accessibility
= DW_UNSND (attr
);
12806 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
12807 if (new_field
->accessibility
!= DW_ACCESS_public
)
12808 fip
->non_public_fields
= 1;
12810 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
12812 new_field
->virtuality
= DW_UNSND (attr
);
12814 new_field
->virtuality
= DW_VIRTUALITY_none
;
12816 fp
= &new_field
->field
;
12818 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
12822 /* Data member other than a C++ static data member. */
12824 /* Get type of field. */
12825 fp
->type
= die_type (die
, cu
);
12827 SET_FIELD_BITPOS (*fp
, 0);
12829 /* Get bit size of field (zero if none). */
12830 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
12833 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
12837 FIELD_BITSIZE (*fp
) = 0;
12840 /* Get bit offset of field. */
12841 if (handle_data_member_location (die
, cu
, &offset
))
12842 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
12843 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
12846 if (gdbarch_bits_big_endian (gdbarch
))
12848 /* For big endian bits, the DW_AT_bit_offset gives the
12849 additional bit offset from the MSB of the containing
12850 anonymous object to the MSB of the field. We don't
12851 have to do anything special since we don't need to
12852 know the size of the anonymous object. */
12853 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
12857 /* For little endian bits, compute the bit offset to the
12858 MSB of the anonymous object, subtract off the number of
12859 bits from the MSB of the field to the MSB of the
12860 object, and then subtract off the number of bits of
12861 the field itself. The result is the bit offset of
12862 the LSB of the field. */
12863 int anonymous_size
;
12864 int bit_offset
= DW_UNSND (attr
);
12866 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12869 /* The size of the anonymous object containing
12870 the bit field is explicit, so use the
12871 indicated size (in bytes). */
12872 anonymous_size
= DW_UNSND (attr
);
12876 /* The size of the anonymous object containing
12877 the bit field must be inferred from the type
12878 attribute of the data member containing the
12880 anonymous_size
= TYPE_LENGTH (fp
->type
);
12882 SET_FIELD_BITPOS (*fp
,
12883 (FIELD_BITPOS (*fp
)
12884 + anonymous_size
* bits_per_byte
12885 - bit_offset
- FIELD_BITSIZE (*fp
)));
12888 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
12890 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
12891 + dwarf2_get_attr_constant_value (attr
, 0)));
12893 /* Get name of field. */
12894 fieldname
= dwarf2_name (die
, cu
);
12895 if (fieldname
== NULL
)
12898 /* The name is already allocated along with this objfile, so we don't
12899 need to duplicate it for the type. */
12900 fp
->name
= fieldname
;
12902 /* Change accessibility for artificial fields (e.g. virtual table
12903 pointer or virtual base class pointer) to private. */
12904 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
12906 FIELD_ARTIFICIAL (*fp
) = 1;
12907 new_field
->accessibility
= DW_ACCESS_private
;
12908 fip
->non_public_fields
= 1;
12911 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
12913 /* C++ static member. */
12915 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
12916 is a declaration, but all versions of G++ as of this writing
12917 (so through at least 3.2.1) incorrectly generate
12918 DW_TAG_variable tags. */
12920 const char *physname
;
12922 /* Get name of field. */
12923 fieldname
= dwarf2_name (die
, cu
);
12924 if (fieldname
== NULL
)
12927 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
12929 /* Only create a symbol if this is an external value.
12930 new_symbol checks this and puts the value in the global symbol
12931 table, which we want. If it is not external, new_symbol
12932 will try to put the value in cu->list_in_scope which is wrong. */
12933 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
12935 /* A static const member, not much different than an enum as far as
12936 we're concerned, except that we can support more types. */
12937 new_symbol (die
, NULL
, cu
);
12940 /* Get physical name. */
12941 physname
= dwarf2_physname (fieldname
, die
, cu
);
12943 /* The name is already allocated along with this objfile, so we don't
12944 need to duplicate it for the type. */
12945 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
12946 FIELD_TYPE (*fp
) = die_type (die
, cu
);
12947 FIELD_NAME (*fp
) = fieldname
;
12949 else if (die
->tag
== DW_TAG_inheritance
)
12953 /* C++ base class field. */
12954 if (handle_data_member_location (die
, cu
, &offset
))
12955 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
12956 FIELD_BITSIZE (*fp
) = 0;
12957 FIELD_TYPE (*fp
) = die_type (die
, cu
);
12958 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
12959 fip
->nbaseclasses
++;
12963 /* Add a typedef defined in the scope of the FIP's class. */
12966 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
12967 struct dwarf2_cu
*cu
)
12969 struct typedef_field_list
*new_field
;
12970 struct typedef_field
*fp
;
12972 /* Allocate a new field list entry and link it in. */
12973 new_field
= XCNEW (struct typedef_field_list
);
12974 make_cleanup (xfree
, new_field
);
12976 gdb_assert (die
->tag
== DW_TAG_typedef
);
12978 fp
= &new_field
->field
;
12980 /* Get name of field. */
12981 fp
->name
= dwarf2_name (die
, cu
);
12982 if (fp
->name
== NULL
)
12985 fp
->type
= read_type_die (die
, cu
);
12987 new_field
->next
= fip
->typedef_field_list
;
12988 fip
->typedef_field_list
= new_field
;
12989 fip
->typedef_field_list_count
++;
12992 /* Create the vector of fields, and attach it to the type. */
12995 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
12996 struct dwarf2_cu
*cu
)
12998 int nfields
= fip
->nfields
;
13000 /* Record the field count, allocate space for the array of fields,
13001 and create blank accessibility bitfields if necessary. */
13002 TYPE_NFIELDS (type
) = nfields
;
13003 TYPE_FIELDS (type
) = (struct field
*)
13004 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
13005 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
13007 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
13009 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13011 TYPE_FIELD_PRIVATE_BITS (type
) =
13012 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
13013 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
13015 TYPE_FIELD_PROTECTED_BITS (type
) =
13016 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
13017 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
13019 TYPE_FIELD_IGNORE_BITS (type
) =
13020 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
13021 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
13024 /* If the type has baseclasses, allocate and clear a bit vector for
13025 TYPE_FIELD_VIRTUAL_BITS. */
13026 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
13028 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
13029 unsigned char *pointer
;
13031 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13032 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
13033 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
13034 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
13035 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
13038 /* Copy the saved-up fields into the field vector. Start from the head of
13039 the list, adding to the tail of the field array, so that they end up in
13040 the same order in the array in which they were added to the list. */
13041 while (nfields
-- > 0)
13043 struct nextfield
*fieldp
;
13047 fieldp
= fip
->fields
;
13048 fip
->fields
= fieldp
->next
;
13052 fieldp
= fip
->baseclasses
;
13053 fip
->baseclasses
= fieldp
->next
;
13056 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
13057 switch (fieldp
->accessibility
)
13059 case DW_ACCESS_private
:
13060 if (cu
->language
!= language_ada
)
13061 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
13064 case DW_ACCESS_protected
:
13065 if (cu
->language
!= language_ada
)
13066 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
13069 case DW_ACCESS_public
:
13073 /* Unknown accessibility. Complain and treat it as public. */
13075 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
13076 fieldp
->accessibility
);
13080 if (nfields
< fip
->nbaseclasses
)
13082 switch (fieldp
->virtuality
)
13084 case DW_VIRTUALITY_virtual
:
13085 case DW_VIRTUALITY_pure_virtual
:
13086 if (cu
->language
== language_ada
)
13087 error (_("unexpected virtuality in component of Ada type"));
13088 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
13095 /* Return true if this member function is a constructor, false
13099 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
13101 const char *fieldname
;
13102 const char *type_name
;
13105 if (die
->parent
== NULL
)
13108 if (die
->parent
->tag
!= DW_TAG_structure_type
13109 && die
->parent
->tag
!= DW_TAG_union_type
13110 && die
->parent
->tag
!= DW_TAG_class_type
)
13113 fieldname
= dwarf2_name (die
, cu
);
13114 type_name
= dwarf2_name (die
->parent
, cu
);
13115 if (fieldname
== NULL
|| type_name
== NULL
)
13118 len
= strlen (fieldname
);
13119 return (strncmp (fieldname
, type_name
, len
) == 0
13120 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
13123 /* Add a member function to the proper fieldlist. */
13126 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
13127 struct type
*type
, struct dwarf2_cu
*cu
)
13129 struct objfile
*objfile
= cu
->objfile
;
13130 struct attribute
*attr
;
13131 struct fnfieldlist
*flp
;
13133 struct fn_field
*fnp
;
13134 const char *fieldname
;
13135 struct nextfnfield
*new_fnfield
;
13136 struct type
*this_type
;
13137 enum dwarf_access_attribute accessibility
;
13139 if (cu
->language
== language_ada
)
13140 error (_("unexpected member function in Ada type"));
13142 /* Get name of member function. */
13143 fieldname
= dwarf2_name (die
, cu
);
13144 if (fieldname
== NULL
)
13147 /* Look up member function name in fieldlist. */
13148 for (i
= 0; i
< fip
->nfnfields
; i
++)
13150 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
13154 /* Create new list element if necessary. */
13155 if (i
< fip
->nfnfields
)
13156 flp
= &fip
->fnfieldlists
[i
];
13159 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
13161 fip
->fnfieldlists
= (struct fnfieldlist
*)
13162 xrealloc (fip
->fnfieldlists
,
13163 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
13164 * sizeof (struct fnfieldlist
));
13165 if (fip
->nfnfields
== 0)
13166 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
13168 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
13169 flp
->name
= fieldname
;
13172 i
= fip
->nfnfields
++;
13175 /* Create a new member function field and chain it to the field list
13177 new_fnfield
= XNEW (struct nextfnfield
);
13178 make_cleanup (xfree
, new_fnfield
);
13179 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
13180 new_fnfield
->next
= flp
->head
;
13181 flp
->head
= new_fnfield
;
13184 /* Fill in the member function field info. */
13185 fnp
= &new_fnfield
->fnfield
;
13187 /* Delay processing of the physname until later. */
13188 if (cu
->language
== language_cplus
)
13190 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
13195 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
13196 fnp
->physname
= physname
? physname
: "";
13199 fnp
->type
= alloc_type (objfile
);
13200 this_type
= read_type_die (die
, cu
);
13201 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
13203 int nparams
= TYPE_NFIELDS (this_type
);
13205 /* TYPE is the domain of this method, and THIS_TYPE is the type
13206 of the method itself (TYPE_CODE_METHOD). */
13207 smash_to_method_type (fnp
->type
, type
,
13208 TYPE_TARGET_TYPE (this_type
),
13209 TYPE_FIELDS (this_type
),
13210 TYPE_NFIELDS (this_type
),
13211 TYPE_VARARGS (this_type
));
13213 /* Handle static member functions.
13214 Dwarf2 has no clean way to discern C++ static and non-static
13215 member functions. G++ helps GDB by marking the first
13216 parameter for non-static member functions (which is the this
13217 pointer) as artificial. We obtain this information from
13218 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
13219 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
13220 fnp
->voffset
= VOFFSET_STATIC
;
13223 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
13224 dwarf2_full_name (fieldname
, die
, cu
));
13226 /* Get fcontext from DW_AT_containing_type if present. */
13227 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
13228 fnp
->fcontext
= die_containing_type (die
, cu
);
13230 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
13231 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
13233 /* Get accessibility. */
13234 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
13236 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
13238 accessibility
= dwarf2_default_access_attribute (die
, cu
);
13239 switch (accessibility
)
13241 case DW_ACCESS_private
:
13242 fnp
->is_private
= 1;
13244 case DW_ACCESS_protected
:
13245 fnp
->is_protected
= 1;
13249 /* Check for artificial methods. */
13250 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
13251 if (attr
&& DW_UNSND (attr
) != 0)
13252 fnp
->is_artificial
= 1;
13254 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
13256 /* Get index in virtual function table if it is a virtual member
13257 function. For older versions of GCC, this is an offset in the
13258 appropriate virtual table, as specified by DW_AT_containing_type.
13259 For everyone else, it is an expression to be evaluated relative
13260 to the object address. */
13262 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
13265 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
13267 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
13269 /* Old-style GCC. */
13270 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
13272 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
13273 || (DW_BLOCK (attr
)->size
> 1
13274 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
13275 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
13277 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
13278 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
13279 dwarf2_complex_location_expr_complaint ();
13281 fnp
->voffset
/= cu
->header
.addr_size
;
13285 dwarf2_complex_location_expr_complaint ();
13287 if (!fnp
->fcontext
)
13289 /* If there is no `this' field and no DW_AT_containing_type,
13290 we cannot actually find a base class context for the
13292 if (TYPE_NFIELDS (this_type
) == 0
13293 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
13295 complaint (&symfile_complaints
,
13296 _("cannot determine context for virtual member "
13297 "function \"%s\" (offset %d)"),
13298 fieldname
, to_underlying (die
->sect_off
));
13303 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
13307 else if (attr_form_is_section_offset (attr
))
13309 dwarf2_complex_location_expr_complaint ();
13313 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
13319 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
13320 if (attr
&& DW_UNSND (attr
))
13322 /* GCC does this, as of 2008-08-25; PR debug/37237. */
13323 complaint (&symfile_complaints
,
13324 _("Member function \"%s\" (offset %d) is virtual "
13325 "but the vtable offset is not specified"),
13326 fieldname
, to_underlying (die
->sect_off
));
13327 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13328 TYPE_CPLUS_DYNAMIC (type
) = 1;
13333 /* Create the vector of member function fields, and attach it to the type. */
13336 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
13337 struct dwarf2_cu
*cu
)
13339 struct fnfieldlist
*flp
;
13342 if (cu
->language
== language_ada
)
13343 error (_("unexpected member functions in Ada type"));
13345 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13346 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
13347 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
13349 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
13351 struct nextfnfield
*nfp
= flp
->head
;
13352 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
13355 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
13356 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
13357 fn_flp
->fn_fields
= (struct fn_field
*)
13358 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
13359 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
13360 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
13363 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
13366 /* Returns non-zero if NAME is the name of a vtable member in CU's
13367 language, zero otherwise. */
13369 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
13371 static const char vptr
[] = "_vptr";
13372 static const char vtable
[] = "vtable";
13374 /* Look for the C++ form of the vtable. */
13375 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
13381 /* GCC outputs unnamed structures that are really pointers to member
13382 functions, with the ABI-specified layout. If TYPE describes
13383 such a structure, smash it into a member function type.
13385 GCC shouldn't do this; it should just output pointer to member DIEs.
13386 This is GCC PR debug/28767. */
13389 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
13391 struct type
*pfn_type
, *self_type
, *new_type
;
13393 /* Check for a structure with no name and two children. */
13394 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
13397 /* Check for __pfn and __delta members. */
13398 if (TYPE_FIELD_NAME (type
, 0) == NULL
13399 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
13400 || TYPE_FIELD_NAME (type
, 1) == NULL
13401 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
13404 /* Find the type of the method. */
13405 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
13406 if (pfn_type
== NULL
13407 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
13408 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
13411 /* Look for the "this" argument. */
13412 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
13413 if (TYPE_NFIELDS (pfn_type
) == 0
13414 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
13415 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
13418 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
13419 new_type
= alloc_type (objfile
);
13420 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
13421 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
13422 TYPE_VARARGS (pfn_type
));
13423 smash_to_methodptr_type (type
, new_type
);
13426 /* Return non-zero if the CU's PRODUCER string matches the Intel C/C++ compiler
13430 producer_is_icc (struct dwarf2_cu
*cu
)
13432 if (!cu
->checked_producer
)
13433 check_producer (cu
);
13435 return cu
->producer_is_icc
;
13438 /* Called when we find the DIE that starts a structure or union scope
13439 (definition) to create a type for the structure or union. Fill in
13440 the type's name and general properties; the members will not be
13441 processed until process_structure_scope. A symbol table entry for
13442 the type will also not be done until process_structure_scope (assuming
13443 the type has a name).
13445 NOTE: we need to call these functions regardless of whether or not the
13446 DIE has a DW_AT_name attribute, since it might be an anonymous
13447 structure or union. This gets the type entered into our set of
13448 user defined types. */
13450 static struct type
*
13451 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13453 struct objfile
*objfile
= cu
->objfile
;
13455 struct attribute
*attr
;
13458 /* If the definition of this type lives in .debug_types, read that type.
13459 Don't follow DW_AT_specification though, that will take us back up
13460 the chain and we want to go down. */
13461 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
13464 type
= get_DW_AT_signature_type (die
, attr
, cu
);
13466 /* The type's CU may not be the same as CU.
13467 Ensure TYPE is recorded with CU in die_type_hash. */
13468 return set_die_type (die
, type
, cu
);
13471 type
= alloc_type (objfile
);
13472 INIT_CPLUS_SPECIFIC (type
);
13474 name
= dwarf2_name (die
, cu
);
13477 if (cu
->language
== language_cplus
13478 || cu
->language
== language_d
13479 || cu
->language
== language_rust
)
13481 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
13483 /* dwarf2_full_name might have already finished building the DIE's
13484 type. If so, there is no need to continue. */
13485 if (get_die_type (die
, cu
) != NULL
)
13486 return get_die_type (die
, cu
);
13488 TYPE_TAG_NAME (type
) = full_name
;
13489 if (die
->tag
== DW_TAG_structure_type
13490 || die
->tag
== DW_TAG_class_type
)
13491 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
13495 /* The name is already allocated along with this objfile, so
13496 we don't need to duplicate it for the type. */
13497 TYPE_TAG_NAME (type
) = name
;
13498 if (die
->tag
== DW_TAG_class_type
)
13499 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
13503 if (die
->tag
== DW_TAG_structure_type
)
13505 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
13507 else if (die
->tag
== DW_TAG_union_type
)
13509 TYPE_CODE (type
) = TYPE_CODE_UNION
;
13513 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
13516 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
13517 TYPE_DECLARED_CLASS (type
) = 1;
13519 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13522 if (attr_form_is_constant (attr
))
13523 TYPE_LENGTH (type
) = DW_UNSND (attr
);
13526 /* For the moment, dynamic type sizes are not supported
13527 by GDB's struct type. The actual size is determined
13528 on-demand when resolving the type of a given object,
13529 so set the type's length to zero for now. Otherwise,
13530 we record an expression as the length, and that expression
13531 could lead to a very large value, which could eventually
13532 lead to us trying to allocate that much memory when creating
13533 a value of that type. */
13534 TYPE_LENGTH (type
) = 0;
13539 TYPE_LENGTH (type
) = 0;
13542 if (producer_is_icc (cu
) && (TYPE_LENGTH (type
) == 0))
13544 /* ICC does not output the required DW_AT_declaration
13545 on incomplete types, but gives them a size of zero. */
13546 TYPE_STUB (type
) = 1;
13549 TYPE_STUB_SUPPORTED (type
) = 1;
13551 if (die_is_declaration (die
, cu
))
13552 TYPE_STUB (type
) = 1;
13553 else if (attr
== NULL
&& die
->child
== NULL
13554 && producer_is_realview (cu
->producer
))
13555 /* RealView does not output the required DW_AT_declaration
13556 on incomplete types. */
13557 TYPE_STUB (type
) = 1;
13559 /* We need to add the type field to the die immediately so we don't
13560 infinitely recurse when dealing with pointers to the structure
13561 type within the structure itself. */
13562 set_die_type (die
, type
, cu
);
13564 /* set_die_type should be already done. */
13565 set_descriptive_type (type
, die
, cu
);
13570 /* Finish creating a structure or union type, including filling in
13571 its members and creating a symbol for it. */
13574 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13576 struct objfile
*objfile
= cu
->objfile
;
13577 struct die_info
*child_die
;
13580 type
= get_die_type (die
, cu
);
13582 type
= read_structure_type (die
, cu
);
13584 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
13586 struct field_info fi
;
13587 VEC (symbolp
) *template_args
= NULL
;
13588 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
13590 memset (&fi
, 0, sizeof (struct field_info
));
13592 child_die
= die
->child
;
13594 while (child_die
&& child_die
->tag
)
13596 if (child_die
->tag
== DW_TAG_member
13597 || child_die
->tag
== DW_TAG_variable
)
13599 /* NOTE: carlton/2002-11-05: A C++ static data member
13600 should be a DW_TAG_member that is a declaration, but
13601 all versions of G++ as of this writing (so through at
13602 least 3.2.1) incorrectly generate DW_TAG_variable
13603 tags for them instead. */
13604 dwarf2_add_field (&fi
, child_die
, cu
);
13606 else if (child_die
->tag
== DW_TAG_subprogram
)
13608 /* Rust doesn't have member functions in the C++ sense.
13609 However, it does emit ordinary functions as children
13610 of a struct DIE. */
13611 if (cu
->language
== language_rust
)
13612 read_func_scope (child_die
, cu
);
13615 /* C++ member function. */
13616 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
13619 else if (child_die
->tag
== DW_TAG_inheritance
)
13621 /* C++ base class field. */
13622 dwarf2_add_field (&fi
, child_die
, cu
);
13624 else if (child_die
->tag
== DW_TAG_typedef
)
13625 dwarf2_add_typedef (&fi
, child_die
, cu
);
13626 else if (child_die
->tag
== DW_TAG_template_type_param
13627 || child_die
->tag
== DW_TAG_template_value_param
)
13629 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13632 VEC_safe_push (symbolp
, template_args
, arg
);
13635 child_die
= sibling_die (child_die
);
13638 /* Attach template arguments to type. */
13639 if (! VEC_empty (symbolp
, template_args
))
13641 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13642 TYPE_N_TEMPLATE_ARGUMENTS (type
)
13643 = VEC_length (symbolp
, template_args
);
13644 TYPE_TEMPLATE_ARGUMENTS (type
)
13645 = XOBNEWVEC (&objfile
->objfile_obstack
,
13647 TYPE_N_TEMPLATE_ARGUMENTS (type
));
13648 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
13649 VEC_address (symbolp
, template_args
),
13650 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
13651 * sizeof (struct symbol
*)));
13652 VEC_free (symbolp
, template_args
);
13655 /* Attach fields and member functions to the type. */
13657 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
13660 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
13662 /* Get the type which refers to the base class (possibly this
13663 class itself) which contains the vtable pointer for the current
13664 class from the DW_AT_containing_type attribute. This use of
13665 DW_AT_containing_type is a GNU extension. */
13667 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
13669 struct type
*t
= die_containing_type (die
, cu
);
13671 set_type_vptr_basetype (type
, t
);
13676 /* Our own class provides vtbl ptr. */
13677 for (i
= TYPE_NFIELDS (t
) - 1;
13678 i
>= TYPE_N_BASECLASSES (t
);
13681 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
13683 if (is_vtable_name (fieldname
, cu
))
13685 set_type_vptr_fieldno (type
, i
);
13690 /* Complain if virtual function table field not found. */
13691 if (i
< TYPE_N_BASECLASSES (t
))
13692 complaint (&symfile_complaints
,
13693 _("virtual function table pointer "
13694 "not found when defining class '%s'"),
13695 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
13700 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
13703 else if (cu
->producer
13704 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
13706 /* The IBM XLC compiler does not provide direct indication
13707 of the containing type, but the vtable pointer is
13708 always named __vfp. */
13712 for (i
= TYPE_NFIELDS (type
) - 1;
13713 i
>= TYPE_N_BASECLASSES (type
);
13716 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
13718 set_type_vptr_fieldno (type
, i
);
13719 set_type_vptr_basetype (type
, type
);
13726 /* Copy fi.typedef_field_list linked list elements content into the
13727 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
13728 if (fi
.typedef_field_list
)
13730 int i
= fi
.typedef_field_list_count
;
13732 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13733 TYPE_TYPEDEF_FIELD_ARRAY (type
)
13734 = ((struct typedef_field
*)
13735 TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
));
13736 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
13738 /* Reverse the list order to keep the debug info elements order. */
13741 struct typedef_field
*dest
, *src
;
13743 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
13744 src
= &fi
.typedef_field_list
->field
;
13745 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
13750 do_cleanups (back_to
);
13753 quirk_gcc_member_function_pointer (type
, objfile
);
13755 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
13756 snapshots) has been known to create a die giving a declaration
13757 for a class that has, as a child, a die giving a definition for a
13758 nested class. So we have to process our children even if the
13759 current die is a declaration. Normally, of course, a declaration
13760 won't have any children at all. */
13762 child_die
= die
->child
;
13764 while (child_die
!= NULL
&& child_die
->tag
)
13766 if (child_die
->tag
== DW_TAG_member
13767 || child_die
->tag
== DW_TAG_variable
13768 || child_die
->tag
== DW_TAG_inheritance
13769 || child_die
->tag
== DW_TAG_template_value_param
13770 || child_die
->tag
== DW_TAG_template_type_param
)
13775 process_die (child_die
, cu
);
13777 child_die
= sibling_die (child_die
);
13780 /* Do not consider external references. According to the DWARF standard,
13781 these DIEs are identified by the fact that they have no byte_size
13782 attribute, and a declaration attribute. */
13783 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
13784 || !die_is_declaration (die
, cu
))
13785 new_symbol (die
, type
, cu
);
13788 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
13789 update TYPE using some information only available in DIE's children. */
13792 update_enumeration_type_from_children (struct die_info
*die
,
13794 struct dwarf2_cu
*cu
)
13796 struct obstack obstack
;
13797 struct die_info
*child_die
;
13798 int unsigned_enum
= 1;
13801 struct cleanup
*old_chain
;
13803 obstack_init (&obstack
);
13804 old_chain
= make_cleanup_obstack_free (&obstack
);
13806 for (child_die
= die
->child
;
13807 child_die
!= NULL
&& child_die
->tag
;
13808 child_die
= sibling_die (child_die
))
13810 struct attribute
*attr
;
13812 const gdb_byte
*bytes
;
13813 struct dwarf2_locexpr_baton
*baton
;
13816 if (child_die
->tag
!= DW_TAG_enumerator
)
13819 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
13823 name
= dwarf2_name (child_die
, cu
);
13825 name
= "<anonymous enumerator>";
13827 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
13828 &value
, &bytes
, &baton
);
13834 else if ((mask
& value
) != 0)
13839 /* If we already know that the enum type is neither unsigned, nor
13840 a flag type, no need to look at the rest of the enumerates. */
13841 if (!unsigned_enum
&& !flag_enum
)
13846 TYPE_UNSIGNED (type
) = 1;
13848 TYPE_FLAG_ENUM (type
) = 1;
13850 do_cleanups (old_chain
);
13853 /* Given a DW_AT_enumeration_type die, set its type. We do not
13854 complete the type's fields yet, or create any symbols. */
13856 static struct type
*
13857 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13859 struct objfile
*objfile
= cu
->objfile
;
13861 struct attribute
*attr
;
13864 /* If the definition of this type lives in .debug_types, read that type.
13865 Don't follow DW_AT_specification though, that will take us back up
13866 the chain and we want to go down. */
13867 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
13870 type
= get_DW_AT_signature_type (die
, attr
, cu
);
13872 /* The type's CU may not be the same as CU.
13873 Ensure TYPE is recorded with CU in die_type_hash. */
13874 return set_die_type (die
, type
, cu
);
13877 type
= alloc_type (objfile
);
13879 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
13880 name
= dwarf2_full_name (NULL
, die
, cu
);
13882 TYPE_TAG_NAME (type
) = name
;
13884 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13887 struct type
*underlying_type
= die_type (die
, cu
);
13889 TYPE_TARGET_TYPE (type
) = underlying_type
;
13892 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13895 TYPE_LENGTH (type
) = DW_UNSND (attr
);
13899 TYPE_LENGTH (type
) = 0;
13902 /* The enumeration DIE can be incomplete. In Ada, any type can be
13903 declared as private in the package spec, and then defined only
13904 inside the package body. Such types are known as Taft Amendment
13905 Types. When another package uses such a type, an incomplete DIE
13906 may be generated by the compiler. */
13907 if (die_is_declaration (die
, cu
))
13908 TYPE_STUB (type
) = 1;
13910 /* Finish the creation of this type by using the enum's children.
13911 We must call this even when the underlying type has been provided
13912 so that we can determine if we're looking at a "flag" enum. */
13913 update_enumeration_type_from_children (die
, type
, cu
);
13915 /* If this type has an underlying type that is not a stub, then we
13916 may use its attributes. We always use the "unsigned" attribute
13917 in this situation, because ordinarily we guess whether the type
13918 is unsigned -- but the guess can be wrong and the underlying type
13919 can tell us the reality. However, we defer to a local size
13920 attribute if one exists, because this lets the compiler override
13921 the underlying type if needed. */
13922 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
13924 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
13925 if (TYPE_LENGTH (type
) == 0)
13926 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
13929 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
13931 return set_die_type (die
, type
, cu
);
13934 /* Given a pointer to a die which begins an enumeration, process all
13935 the dies that define the members of the enumeration, and create the
13936 symbol for the enumeration type.
13938 NOTE: We reverse the order of the element list. */
13941 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13943 struct type
*this_type
;
13945 this_type
= get_die_type (die
, cu
);
13946 if (this_type
== NULL
)
13947 this_type
= read_enumeration_type (die
, cu
);
13949 if (die
->child
!= NULL
)
13951 struct die_info
*child_die
;
13952 struct symbol
*sym
;
13953 struct field
*fields
= NULL
;
13954 int num_fields
= 0;
13957 child_die
= die
->child
;
13958 while (child_die
&& child_die
->tag
)
13960 if (child_die
->tag
!= DW_TAG_enumerator
)
13962 process_die (child_die
, cu
);
13966 name
= dwarf2_name (child_die
, cu
);
13969 sym
= new_symbol (child_die
, this_type
, cu
);
13971 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
13973 fields
= (struct field
*)
13975 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
13976 * sizeof (struct field
));
13979 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
13980 FIELD_TYPE (fields
[num_fields
]) = NULL
;
13981 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
13982 FIELD_BITSIZE (fields
[num_fields
]) = 0;
13988 child_die
= sibling_die (child_die
);
13993 TYPE_NFIELDS (this_type
) = num_fields
;
13994 TYPE_FIELDS (this_type
) = (struct field
*)
13995 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
13996 memcpy (TYPE_FIELDS (this_type
), fields
,
13997 sizeof (struct field
) * num_fields
);
14002 /* If we are reading an enum from a .debug_types unit, and the enum
14003 is a declaration, and the enum is not the signatured type in the
14004 unit, then we do not want to add a symbol for it. Adding a
14005 symbol would in some cases obscure the true definition of the
14006 enum, giving users an incomplete type when the definition is
14007 actually available. Note that we do not want to do this for all
14008 enums which are just declarations, because C++0x allows forward
14009 enum declarations. */
14010 if (cu
->per_cu
->is_debug_types
14011 && die_is_declaration (die
, cu
))
14013 struct signatured_type
*sig_type
;
14015 sig_type
= (struct signatured_type
*) cu
->per_cu
;
14016 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
14017 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
14021 new_symbol (die
, this_type
, cu
);
14024 /* Extract all information from a DW_TAG_array_type DIE and put it in
14025 the DIE's type field. For now, this only handles one dimensional
14028 static struct type
*
14029 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14031 struct objfile
*objfile
= cu
->objfile
;
14032 struct die_info
*child_die
;
14034 struct type
*element_type
, *range_type
, *index_type
;
14035 struct type
**range_types
= NULL
;
14036 struct attribute
*attr
;
14038 struct cleanup
*back_to
;
14040 unsigned int bit_stride
= 0;
14042 element_type
= die_type (die
, cu
);
14044 /* The die_type call above may have already set the type for this DIE. */
14045 type
= get_die_type (die
, cu
);
14049 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
14051 bit_stride
= DW_UNSND (attr
) * 8;
14053 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
14055 bit_stride
= DW_UNSND (attr
);
14057 /* Irix 6.2 native cc creates array types without children for
14058 arrays with unspecified length. */
14059 if (die
->child
== NULL
)
14061 index_type
= objfile_type (objfile
)->builtin_int
;
14062 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
14063 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
14065 return set_die_type (die
, type
, cu
);
14068 back_to
= make_cleanup (null_cleanup
, NULL
);
14069 child_die
= die
->child
;
14070 while (child_die
&& child_die
->tag
)
14072 if (child_die
->tag
== DW_TAG_subrange_type
)
14074 struct type
*child_type
= read_type_die (child_die
, cu
);
14076 if (child_type
!= NULL
)
14078 /* The range type was succesfully read. Save it for the
14079 array type creation. */
14080 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
14082 range_types
= (struct type
**)
14083 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
14084 * sizeof (struct type
*));
14086 make_cleanup (free_current_contents
, &range_types
);
14088 range_types
[ndim
++] = child_type
;
14091 child_die
= sibling_die (child_die
);
14094 /* Dwarf2 dimensions are output from left to right, create the
14095 necessary array types in backwards order. */
14097 type
= element_type
;
14099 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
14104 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
14110 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
14114 /* Understand Dwarf2 support for vector types (like they occur on
14115 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
14116 array type. This is not part of the Dwarf2/3 standard yet, but a
14117 custom vendor extension. The main difference between a regular
14118 array and the vector variant is that vectors are passed by value
14120 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
14122 make_vector_type (type
);
14124 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
14125 implementation may choose to implement triple vectors using this
14127 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14130 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
14131 TYPE_LENGTH (type
) = DW_UNSND (attr
);
14133 complaint (&symfile_complaints
,
14134 _("DW_AT_byte_size for array type smaller "
14135 "than the total size of elements"));
14138 name
= dwarf2_name (die
, cu
);
14140 TYPE_NAME (type
) = name
;
14142 /* Install the type in the die. */
14143 set_die_type (die
, type
, cu
);
14145 /* set_die_type should be already done. */
14146 set_descriptive_type (type
, die
, cu
);
14148 do_cleanups (back_to
);
14153 static enum dwarf_array_dim_ordering
14154 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
14156 struct attribute
*attr
;
14158 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
14161 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
14163 /* GNU F77 is a special case, as at 08/2004 array type info is the
14164 opposite order to the dwarf2 specification, but data is still
14165 laid out as per normal fortran.
14167 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
14168 version checking. */
14170 if (cu
->language
== language_fortran
14171 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
14173 return DW_ORD_row_major
;
14176 switch (cu
->language_defn
->la_array_ordering
)
14178 case array_column_major
:
14179 return DW_ORD_col_major
;
14180 case array_row_major
:
14182 return DW_ORD_row_major
;
14186 /* Extract all information from a DW_TAG_set_type DIE and put it in
14187 the DIE's type field. */
14189 static struct type
*
14190 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14192 struct type
*domain_type
, *set_type
;
14193 struct attribute
*attr
;
14195 domain_type
= die_type (die
, cu
);
14197 /* The die_type call above may have already set the type for this DIE. */
14198 set_type
= get_die_type (die
, cu
);
14202 set_type
= create_set_type (NULL
, domain_type
);
14204 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14206 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
14208 return set_die_type (die
, set_type
, cu
);
14211 /* A helper for read_common_block that creates a locexpr baton.
14212 SYM is the symbol which we are marking as computed.
14213 COMMON_DIE is the DIE for the common block.
14214 COMMON_LOC is the location expression attribute for the common
14216 MEMBER_LOC is the location expression attribute for the particular
14217 member of the common block that we are processing.
14218 CU is the CU from which the above come. */
14221 mark_common_block_symbol_computed (struct symbol
*sym
,
14222 struct die_info
*common_die
,
14223 struct attribute
*common_loc
,
14224 struct attribute
*member_loc
,
14225 struct dwarf2_cu
*cu
)
14227 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14228 struct dwarf2_locexpr_baton
*baton
;
14230 unsigned int cu_off
;
14231 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
14232 LONGEST offset
= 0;
14234 gdb_assert (common_loc
&& member_loc
);
14235 gdb_assert (attr_form_is_block (common_loc
));
14236 gdb_assert (attr_form_is_block (member_loc
)
14237 || attr_form_is_constant (member_loc
));
14239 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
14240 baton
->per_cu
= cu
->per_cu
;
14241 gdb_assert (baton
->per_cu
);
14243 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
14245 if (attr_form_is_constant (member_loc
))
14247 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
14248 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
14251 baton
->size
+= DW_BLOCK (member_loc
)->size
;
14253 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
14256 *ptr
++ = DW_OP_call4
;
14257 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
14258 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
14261 if (attr_form_is_constant (member_loc
))
14263 *ptr
++ = DW_OP_addr
;
14264 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
14265 ptr
+= cu
->header
.addr_size
;
14269 /* We have to copy the data here, because DW_OP_call4 will only
14270 use a DW_AT_location attribute. */
14271 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
14272 ptr
+= DW_BLOCK (member_loc
)->size
;
14275 *ptr
++ = DW_OP_plus
;
14276 gdb_assert (ptr
- baton
->data
== baton
->size
);
14278 SYMBOL_LOCATION_BATON (sym
) = baton
;
14279 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
14282 /* Create appropriate locally-scoped variables for all the
14283 DW_TAG_common_block entries. Also create a struct common_block
14284 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
14285 is used to sepate the common blocks name namespace from regular
14289 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
14291 struct attribute
*attr
;
14293 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
14296 /* Support the .debug_loc offsets. */
14297 if (attr_form_is_block (attr
))
14301 else if (attr_form_is_section_offset (attr
))
14303 dwarf2_complex_location_expr_complaint ();
14308 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
14309 "common block member");
14314 if (die
->child
!= NULL
)
14316 struct objfile
*objfile
= cu
->objfile
;
14317 struct die_info
*child_die
;
14318 size_t n_entries
= 0, size
;
14319 struct common_block
*common_block
;
14320 struct symbol
*sym
;
14322 for (child_die
= die
->child
;
14323 child_die
&& child_die
->tag
;
14324 child_die
= sibling_die (child_die
))
14327 size
= (sizeof (struct common_block
)
14328 + (n_entries
- 1) * sizeof (struct symbol
*));
14330 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
14332 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
14333 common_block
->n_entries
= 0;
14335 for (child_die
= die
->child
;
14336 child_die
&& child_die
->tag
;
14337 child_die
= sibling_die (child_die
))
14339 /* Create the symbol in the DW_TAG_common_block block in the current
14341 sym
= new_symbol (child_die
, NULL
, cu
);
14344 struct attribute
*member_loc
;
14346 common_block
->contents
[common_block
->n_entries
++] = sym
;
14348 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
14352 /* GDB has handled this for a long time, but it is
14353 not specified by DWARF. It seems to have been
14354 emitted by gfortran at least as recently as:
14355 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
14356 complaint (&symfile_complaints
,
14357 _("Variable in common block has "
14358 "DW_AT_data_member_location "
14359 "- DIE at 0x%x [in module %s]"),
14360 to_underlying (child_die
->sect_off
),
14361 objfile_name (cu
->objfile
));
14363 if (attr_form_is_section_offset (member_loc
))
14364 dwarf2_complex_location_expr_complaint ();
14365 else if (attr_form_is_constant (member_loc
)
14366 || attr_form_is_block (member_loc
))
14369 mark_common_block_symbol_computed (sym
, die
, attr
,
14373 dwarf2_complex_location_expr_complaint ();
14378 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
14379 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
14383 /* Create a type for a C++ namespace. */
14385 static struct type
*
14386 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14388 struct objfile
*objfile
= cu
->objfile
;
14389 const char *previous_prefix
, *name
;
14393 /* For extensions, reuse the type of the original namespace. */
14394 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
14396 struct die_info
*ext_die
;
14397 struct dwarf2_cu
*ext_cu
= cu
;
14399 ext_die
= dwarf2_extension (die
, &ext_cu
);
14400 type
= read_type_die (ext_die
, ext_cu
);
14402 /* EXT_CU may not be the same as CU.
14403 Ensure TYPE is recorded with CU in die_type_hash. */
14404 return set_die_type (die
, type
, cu
);
14407 name
= namespace_name (die
, &is_anonymous
, cu
);
14409 /* Now build the name of the current namespace. */
14411 previous_prefix
= determine_prefix (die
, cu
);
14412 if (previous_prefix
[0] != '\0')
14413 name
= typename_concat (&objfile
->objfile_obstack
,
14414 previous_prefix
, name
, 0, cu
);
14416 /* Create the type. */
14417 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
14418 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
14420 return set_die_type (die
, type
, cu
);
14423 /* Read a namespace scope. */
14426 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
14428 struct objfile
*objfile
= cu
->objfile
;
14431 /* Add a symbol associated to this if we haven't seen the namespace
14432 before. Also, add a using directive if it's an anonymous
14435 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
14439 type
= read_type_die (die
, cu
);
14440 new_symbol (die
, type
, cu
);
14442 namespace_name (die
, &is_anonymous
, cu
);
14445 const char *previous_prefix
= determine_prefix (die
, cu
);
14447 add_using_directive (using_directives (cu
->language
),
14448 previous_prefix
, TYPE_NAME (type
), NULL
,
14449 NULL
, NULL
, 0, &objfile
->objfile_obstack
);
14453 if (die
->child
!= NULL
)
14455 struct die_info
*child_die
= die
->child
;
14457 while (child_die
&& child_die
->tag
)
14459 process_die (child_die
, cu
);
14460 child_die
= sibling_die (child_die
);
14465 /* Read a Fortran module as type. This DIE can be only a declaration used for
14466 imported module. Still we need that type as local Fortran "use ... only"
14467 declaration imports depend on the created type in determine_prefix. */
14469 static struct type
*
14470 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14472 struct objfile
*objfile
= cu
->objfile
;
14473 const char *module_name
;
14476 module_name
= dwarf2_name (die
, cu
);
14478 complaint (&symfile_complaints
,
14479 _("DW_TAG_module has no name, offset 0x%x"),
14480 to_underlying (die
->sect_off
));
14481 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
14483 /* determine_prefix uses TYPE_TAG_NAME. */
14484 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
14486 return set_die_type (die
, type
, cu
);
14489 /* Read a Fortran module. */
14492 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
14494 struct die_info
*child_die
= die
->child
;
14497 type
= read_type_die (die
, cu
);
14498 new_symbol (die
, type
, cu
);
14500 while (child_die
&& child_die
->tag
)
14502 process_die (child_die
, cu
);
14503 child_die
= sibling_die (child_die
);
14507 /* Return the name of the namespace represented by DIE. Set
14508 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
14511 static const char *
14512 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
14514 struct die_info
*current_die
;
14515 const char *name
= NULL
;
14517 /* Loop through the extensions until we find a name. */
14519 for (current_die
= die
;
14520 current_die
!= NULL
;
14521 current_die
= dwarf2_extension (die
, &cu
))
14523 /* We don't use dwarf2_name here so that we can detect the absence
14524 of a name -> anonymous namespace. */
14525 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
14531 /* Is it an anonymous namespace? */
14533 *is_anonymous
= (name
== NULL
);
14535 name
= CP_ANONYMOUS_NAMESPACE_STR
;
14540 /* Extract all information from a DW_TAG_pointer_type DIE and add to
14541 the user defined type vector. */
14543 static struct type
*
14544 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14546 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
14547 struct comp_unit_head
*cu_header
= &cu
->header
;
14549 struct attribute
*attr_byte_size
;
14550 struct attribute
*attr_address_class
;
14551 int byte_size
, addr_class
;
14552 struct type
*target_type
;
14554 target_type
= die_type (die
, cu
);
14556 /* The die_type call above may have already set the type for this DIE. */
14557 type
= get_die_type (die
, cu
);
14561 type
= lookup_pointer_type (target_type
);
14563 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14564 if (attr_byte_size
)
14565 byte_size
= DW_UNSND (attr_byte_size
);
14567 byte_size
= cu_header
->addr_size
;
14569 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
14570 if (attr_address_class
)
14571 addr_class
= DW_UNSND (attr_address_class
);
14573 addr_class
= DW_ADDR_none
;
14575 /* If the pointer size or address class is different than the
14576 default, create a type variant marked as such and set the
14577 length accordingly. */
14578 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
14580 if (gdbarch_address_class_type_flags_p (gdbarch
))
14584 type_flags
= gdbarch_address_class_type_flags
14585 (gdbarch
, byte_size
, addr_class
);
14586 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
14588 type
= make_type_with_address_space (type
, type_flags
);
14590 else if (TYPE_LENGTH (type
) != byte_size
)
14592 complaint (&symfile_complaints
,
14593 _("invalid pointer size %d"), byte_size
);
14597 /* Should we also complain about unhandled address classes? */
14601 TYPE_LENGTH (type
) = byte_size
;
14602 return set_die_type (die
, type
, cu
);
14605 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
14606 the user defined type vector. */
14608 static struct type
*
14609 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14612 struct type
*to_type
;
14613 struct type
*domain
;
14615 to_type
= die_type (die
, cu
);
14616 domain
= die_containing_type (die
, cu
);
14618 /* The calls above may have already set the type for this DIE. */
14619 type
= get_die_type (die
, cu
);
14623 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
14624 type
= lookup_methodptr_type (to_type
);
14625 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
14627 struct type
*new_type
= alloc_type (cu
->objfile
);
14629 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
14630 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
14631 TYPE_VARARGS (to_type
));
14632 type
= lookup_methodptr_type (new_type
);
14635 type
= lookup_memberptr_type (to_type
, domain
);
14637 return set_die_type (die
, type
, cu
);
14640 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
14641 the user defined type vector. */
14643 static struct type
*
14644 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
14645 enum type_code refcode
)
14647 struct comp_unit_head
*cu_header
= &cu
->header
;
14648 struct type
*type
, *target_type
;
14649 struct attribute
*attr
;
14651 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
14653 target_type
= die_type (die
, cu
);
14655 /* The die_type call above may have already set the type for this DIE. */
14656 type
= get_die_type (die
, cu
);
14660 type
= lookup_reference_type (target_type
, refcode
);
14661 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14664 TYPE_LENGTH (type
) = DW_UNSND (attr
);
14668 TYPE_LENGTH (type
) = cu_header
->addr_size
;
14670 return set_die_type (die
, type
, cu
);
14673 /* Add the given cv-qualifiers to the element type of the array. GCC
14674 outputs DWARF type qualifiers that apply to an array, not the
14675 element type. But GDB relies on the array element type to carry
14676 the cv-qualifiers. This mimics section 6.7.3 of the C99
14679 static struct type
*
14680 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
14681 struct type
*base_type
, int cnst
, int voltl
)
14683 struct type
*el_type
, *inner_array
;
14685 base_type
= copy_type (base_type
);
14686 inner_array
= base_type
;
14688 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
14690 TYPE_TARGET_TYPE (inner_array
) =
14691 copy_type (TYPE_TARGET_TYPE (inner_array
));
14692 inner_array
= TYPE_TARGET_TYPE (inner_array
);
14695 el_type
= TYPE_TARGET_TYPE (inner_array
);
14696 cnst
|= TYPE_CONST (el_type
);
14697 voltl
|= TYPE_VOLATILE (el_type
);
14698 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
14700 return set_die_type (die
, base_type
, cu
);
14703 static struct type
*
14704 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14706 struct type
*base_type
, *cv_type
;
14708 base_type
= die_type (die
, cu
);
14710 /* The die_type call above may have already set the type for this DIE. */
14711 cv_type
= get_die_type (die
, cu
);
14715 /* In case the const qualifier is applied to an array type, the element type
14716 is so qualified, not the array type (section 6.7.3 of C99). */
14717 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
14718 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
14720 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
14721 return set_die_type (die
, cv_type
, cu
);
14724 static struct type
*
14725 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14727 struct type
*base_type
, *cv_type
;
14729 base_type
= die_type (die
, cu
);
14731 /* The die_type call above may have already set the type for this DIE. */
14732 cv_type
= get_die_type (die
, cu
);
14736 /* In case the volatile qualifier is applied to an array type, the
14737 element type is so qualified, not the array type (section 6.7.3
14739 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
14740 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
14742 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
14743 return set_die_type (die
, cv_type
, cu
);
14746 /* Handle DW_TAG_restrict_type. */
14748 static struct type
*
14749 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14751 struct type
*base_type
, *cv_type
;
14753 base_type
= die_type (die
, cu
);
14755 /* The die_type call above may have already set the type for this DIE. */
14756 cv_type
= get_die_type (die
, cu
);
14760 cv_type
= make_restrict_type (base_type
);
14761 return set_die_type (die
, cv_type
, cu
);
14764 /* Handle DW_TAG_atomic_type. */
14766 static struct type
*
14767 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14769 struct type
*base_type
, *cv_type
;
14771 base_type
= die_type (die
, cu
);
14773 /* The die_type call above may have already set the type for this DIE. */
14774 cv_type
= get_die_type (die
, cu
);
14778 cv_type
= make_atomic_type (base_type
);
14779 return set_die_type (die
, cv_type
, cu
);
14782 /* Extract all information from a DW_TAG_string_type DIE and add to
14783 the user defined type vector. It isn't really a user defined type,
14784 but it behaves like one, with other DIE's using an AT_user_def_type
14785 attribute to reference it. */
14787 static struct type
*
14788 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14790 struct objfile
*objfile
= cu
->objfile
;
14791 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14792 struct type
*type
, *range_type
, *index_type
, *char_type
;
14793 struct attribute
*attr
;
14794 unsigned int length
;
14796 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
14799 length
= DW_UNSND (attr
);
14803 /* Check for the DW_AT_byte_size attribute. */
14804 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14807 length
= DW_UNSND (attr
);
14815 index_type
= objfile_type (objfile
)->builtin_int
;
14816 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
14817 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
14818 type
= create_string_type (NULL
, char_type
, range_type
);
14820 return set_die_type (die
, type
, cu
);
14823 /* Assuming that DIE corresponds to a function, returns nonzero
14824 if the function is prototyped. */
14827 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
14829 struct attribute
*attr
;
14831 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
14832 if (attr
&& (DW_UNSND (attr
) != 0))
14835 /* The DWARF standard implies that the DW_AT_prototyped attribute
14836 is only meaninful for C, but the concept also extends to other
14837 languages that allow unprototyped functions (Eg: Objective C).
14838 For all other languages, assume that functions are always
14840 if (cu
->language
!= language_c
14841 && cu
->language
!= language_objc
14842 && cu
->language
!= language_opencl
)
14845 /* RealView does not emit DW_AT_prototyped. We can not distinguish
14846 prototyped and unprototyped functions; default to prototyped,
14847 since that is more common in modern code (and RealView warns
14848 about unprototyped functions). */
14849 if (producer_is_realview (cu
->producer
))
14855 /* Handle DIES due to C code like:
14859 int (*funcp)(int a, long l);
14863 ('funcp' generates a DW_TAG_subroutine_type DIE). */
14865 static struct type
*
14866 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14868 struct objfile
*objfile
= cu
->objfile
;
14869 struct type
*type
; /* Type that this function returns. */
14870 struct type
*ftype
; /* Function that returns above type. */
14871 struct attribute
*attr
;
14873 type
= die_type (die
, cu
);
14875 /* The die_type call above may have already set the type for this DIE. */
14876 ftype
= get_die_type (die
, cu
);
14880 ftype
= lookup_function_type (type
);
14882 if (prototyped_function_p (die
, cu
))
14883 TYPE_PROTOTYPED (ftype
) = 1;
14885 /* Store the calling convention in the type if it's available in
14886 the subroutine die. Otherwise set the calling convention to
14887 the default value DW_CC_normal. */
14888 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
14890 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
14891 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
14892 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
14894 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
14896 /* Record whether the function returns normally to its caller or not
14897 if the DWARF producer set that information. */
14898 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
14899 if (attr
&& (DW_UNSND (attr
) != 0))
14900 TYPE_NO_RETURN (ftype
) = 1;
14902 /* We need to add the subroutine type to the die immediately so
14903 we don't infinitely recurse when dealing with parameters
14904 declared as the same subroutine type. */
14905 set_die_type (die
, ftype
, cu
);
14907 if (die
->child
!= NULL
)
14909 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
14910 struct die_info
*child_die
;
14911 int nparams
, iparams
;
14913 /* Count the number of parameters.
14914 FIXME: GDB currently ignores vararg functions, but knows about
14915 vararg member functions. */
14917 child_die
= die
->child
;
14918 while (child_die
&& child_die
->tag
)
14920 if (child_die
->tag
== DW_TAG_formal_parameter
)
14922 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
14923 TYPE_VARARGS (ftype
) = 1;
14924 child_die
= sibling_die (child_die
);
14927 /* Allocate storage for parameters and fill them in. */
14928 TYPE_NFIELDS (ftype
) = nparams
;
14929 TYPE_FIELDS (ftype
) = (struct field
*)
14930 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
14932 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
14933 even if we error out during the parameters reading below. */
14934 for (iparams
= 0; iparams
< nparams
; iparams
++)
14935 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
14938 child_die
= die
->child
;
14939 while (child_die
&& child_die
->tag
)
14941 if (child_die
->tag
== DW_TAG_formal_parameter
)
14943 struct type
*arg_type
;
14945 /* DWARF version 2 has no clean way to discern C++
14946 static and non-static member functions. G++ helps
14947 GDB by marking the first parameter for non-static
14948 member functions (which is the this pointer) as
14949 artificial. We pass this information to
14950 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
14952 DWARF version 3 added DW_AT_object_pointer, which GCC
14953 4.5 does not yet generate. */
14954 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
14956 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
14958 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
14959 arg_type
= die_type (child_die
, cu
);
14961 /* RealView does not mark THIS as const, which the testsuite
14962 expects. GCC marks THIS as const in method definitions,
14963 but not in the class specifications (GCC PR 43053). */
14964 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
14965 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
14968 struct dwarf2_cu
*arg_cu
= cu
;
14969 const char *name
= dwarf2_name (child_die
, cu
);
14971 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
14974 /* If the compiler emits this, use it. */
14975 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
14978 else if (name
&& strcmp (name
, "this") == 0)
14979 /* Function definitions will have the argument names. */
14981 else if (name
== NULL
&& iparams
== 0)
14982 /* Declarations may not have the names, so like
14983 elsewhere in GDB, assume an artificial first
14984 argument is "this". */
14988 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
14992 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
14995 child_die
= sibling_die (child_die
);
15002 static struct type
*
15003 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
15005 struct objfile
*objfile
= cu
->objfile
;
15006 const char *name
= NULL
;
15007 struct type
*this_type
, *target_type
;
15009 name
= dwarf2_full_name (NULL
, die
, cu
);
15010 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
15011 TYPE_TARGET_STUB (this_type
) = 1;
15012 set_die_type (die
, this_type
, cu
);
15013 target_type
= die_type (die
, cu
);
15014 if (target_type
!= this_type
)
15015 TYPE_TARGET_TYPE (this_type
) = target_type
;
15018 /* Self-referential typedefs are, it seems, not allowed by the DWARF
15019 spec and cause infinite loops in GDB. */
15020 complaint (&symfile_complaints
,
15021 _("Self-referential DW_TAG_typedef "
15022 "- DIE at 0x%x [in module %s]"),
15023 to_underlying (die
->sect_off
), objfile_name (objfile
));
15024 TYPE_TARGET_TYPE (this_type
) = NULL
;
15029 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
15030 (which may be different from NAME) to the architecture back-end to allow
15031 it to guess the correct format if necessary. */
15033 static struct type
*
15034 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
15035 const char *name_hint
)
15037 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15038 const struct floatformat
**format
;
15041 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
15043 type
= init_float_type (objfile
, bits
, name
, format
);
15045 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
/ TARGET_CHAR_BIT
, name
);
15050 /* Find a representation of a given base type and install
15051 it in the TYPE field of the die. */
15053 static struct type
*
15054 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15056 struct objfile
*objfile
= cu
->objfile
;
15058 struct attribute
*attr
;
15059 int encoding
= 0, bits
= 0;
15062 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
15065 encoding
= DW_UNSND (attr
);
15067 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15070 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
15072 name
= dwarf2_name (die
, cu
);
15075 complaint (&symfile_complaints
,
15076 _("DW_AT_name missing from DW_TAG_base_type"));
15081 case DW_ATE_address
:
15082 /* Turn DW_ATE_address into a void * pointer. */
15083 type
= init_type (objfile
, TYPE_CODE_VOID
, 1, NULL
);
15084 type
= init_pointer_type (objfile
, bits
, name
, type
);
15086 case DW_ATE_boolean
:
15087 type
= init_boolean_type (objfile
, bits
, 1, name
);
15089 case DW_ATE_complex_float
:
15090 type
= dwarf2_init_float_type (objfile
, bits
/ 2, NULL
, name
);
15091 type
= init_complex_type (objfile
, name
, type
);
15093 case DW_ATE_decimal_float
:
15094 type
= init_decfloat_type (objfile
, bits
, name
);
15097 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
);
15099 case DW_ATE_signed
:
15100 type
= init_integer_type (objfile
, bits
, 0, name
);
15102 case DW_ATE_unsigned
:
15103 if (cu
->language
== language_fortran
15105 && startswith (name
, "character("))
15106 type
= init_character_type (objfile
, bits
, 1, name
);
15108 type
= init_integer_type (objfile
, bits
, 1, name
);
15110 case DW_ATE_signed_char
:
15111 if (cu
->language
== language_ada
|| cu
->language
== language_m2
15112 || cu
->language
== language_pascal
15113 || cu
->language
== language_fortran
)
15114 type
= init_character_type (objfile
, bits
, 0, name
);
15116 type
= init_integer_type (objfile
, bits
, 0, name
);
15118 case DW_ATE_unsigned_char
:
15119 if (cu
->language
== language_ada
|| cu
->language
== language_m2
15120 || cu
->language
== language_pascal
15121 || cu
->language
== language_fortran
15122 || cu
->language
== language_rust
)
15123 type
= init_character_type (objfile
, bits
, 1, name
);
15125 type
= init_integer_type (objfile
, bits
, 1, name
);
15128 /* We just treat this as an integer and then recognize the
15129 type by name elsewhere. */
15130 type
= init_integer_type (objfile
, bits
, 0, name
);
15134 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
15135 dwarf_type_encoding_name (encoding
));
15136 type
= init_type (objfile
, TYPE_CODE_ERROR
,
15137 bits
/ TARGET_CHAR_BIT
, name
);
15141 if (name
&& strcmp (name
, "char") == 0)
15142 TYPE_NOSIGN (type
) = 1;
15144 return set_die_type (die
, type
, cu
);
15147 /* Parse dwarf attribute if it's a block, reference or constant and put the
15148 resulting value of the attribute into struct bound_prop.
15149 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
15152 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
15153 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
)
15155 struct dwarf2_property_baton
*baton
;
15156 struct obstack
*obstack
= &cu
->objfile
->objfile_obstack
;
15158 if (attr
== NULL
|| prop
== NULL
)
15161 if (attr_form_is_block (attr
))
15163 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
15164 baton
->referenced_type
= NULL
;
15165 baton
->locexpr
.per_cu
= cu
->per_cu
;
15166 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
15167 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
15168 prop
->data
.baton
= baton
;
15169 prop
->kind
= PROP_LOCEXPR
;
15170 gdb_assert (prop
->data
.baton
!= NULL
);
15172 else if (attr_form_is_ref (attr
))
15174 struct dwarf2_cu
*target_cu
= cu
;
15175 struct die_info
*target_die
;
15176 struct attribute
*target_attr
;
15178 target_die
= follow_die_ref (die
, attr
, &target_cu
);
15179 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
15180 if (target_attr
== NULL
)
15181 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
15183 if (target_attr
== NULL
)
15186 switch (target_attr
->name
)
15188 case DW_AT_location
:
15189 if (attr_form_is_section_offset (target_attr
))
15191 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
15192 baton
->referenced_type
= die_type (target_die
, target_cu
);
15193 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
15194 prop
->data
.baton
= baton
;
15195 prop
->kind
= PROP_LOCLIST
;
15196 gdb_assert (prop
->data
.baton
!= NULL
);
15198 else if (attr_form_is_block (target_attr
))
15200 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
15201 baton
->referenced_type
= die_type (target_die
, target_cu
);
15202 baton
->locexpr
.per_cu
= cu
->per_cu
;
15203 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
15204 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
15205 prop
->data
.baton
= baton
;
15206 prop
->kind
= PROP_LOCEXPR
;
15207 gdb_assert (prop
->data
.baton
!= NULL
);
15211 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
15212 "dynamic property");
15216 case DW_AT_data_member_location
:
15220 if (!handle_data_member_location (target_die
, target_cu
,
15224 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
15225 baton
->referenced_type
= read_type_die (target_die
->parent
,
15227 baton
->offset_info
.offset
= offset
;
15228 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
15229 prop
->data
.baton
= baton
;
15230 prop
->kind
= PROP_ADDR_OFFSET
;
15235 else if (attr_form_is_constant (attr
))
15237 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
15238 prop
->kind
= PROP_CONST
;
15242 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
15243 dwarf2_name (die
, cu
));
15250 /* Read the given DW_AT_subrange DIE. */
15252 static struct type
*
15253 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15255 struct type
*base_type
, *orig_base_type
;
15256 struct type
*range_type
;
15257 struct attribute
*attr
;
15258 struct dynamic_prop low
, high
;
15259 int low_default_is_valid
;
15260 int high_bound_is_count
= 0;
15262 LONGEST negative_mask
;
15264 orig_base_type
= die_type (die
, cu
);
15265 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
15266 whereas the real type might be. So, we use ORIG_BASE_TYPE when
15267 creating the range type, but we use the result of check_typedef
15268 when examining properties of the type. */
15269 base_type
= check_typedef (orig_base_type
);
15271 /* The die_type call above may have already set the type for this DIE. */
15272 range_type
= get_die_type (die
, cu
);
15276 low
.kind
= PROP_CONST
;
15277 high
.kind
= PROP_CONST
;
15278 high
.data
.const_val
= 0;
15280 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
15281 omitting DW_AT_lower_bound. */
15282 switch (cu
->language
)
15285 case language_cplus
:
15286 low
.data
.const_val
= 0;
15287 low_default_is_valid
= 1;
15289 case language_fortran
:
15290 low
.data
.const_val
= 1;
15291 low_default_is_valid
= 1;
15294 case language_objc
:
15295 case language_rust
:
15296 low
.data
.const_val
= 0;
15297 low_default_is_valid
= (cu
->header
.version
>= 4);
15301 case language_pascal
:
15302 low
.data
.const_val
= 1;
15303 low_default_is_valid
= (cu
->header
.version
>= 4);
15306 low
.data
.const_val
= 0;
15307 low_default_is_valid
= 0;
15311 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
15313 attr_to_dynamic_prop (attr
, die
, cu
, &low
);
15314 else if (!low_default_is_valid
)
15315 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
15316 "- DIE at 0x%x [in module %s]"),
15317 to_underlying (die
->sect_off
), objfile_name (cu
->objfile
));
15319 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
15320 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
))
15322 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
15323 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
))
15325 /* If bounds are constant do the final calculation here. */
15326 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
15327 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
15329 high_bound_is_count
= 1;
15333 /* Dwarf-2 specifications explicitly allows to create subrange types
15334 without specifying a base type.
15335 In that case, the base type must be set to the type of
15336 the lower bound, upper bound or count, in that order, if any of these
15337 three attributes references an object that has a type.
15338 If no base type is found, the Dwarf-2 specifications say that
15339 a signed integer type of size equal to the size of an address should
15341 For the following C code: `extern char gdb_int [];'
15342 GCC produces an empty range DIE.
15343 FIXME: muller/2010-05-28: Possible references to object for low bound,
15344 high bound or count are not yet handled by this code. */
15345 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
15347 struct objfile
*objfile
= cu
->objfile
;
15348 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15349 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
15350 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
15352 /* Test "int", "long int", and "long long int" objfile types,
15353 and select the first one having a size above or equal to the
15354 architecture address size. */
15355 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
15356 base_type
= int_type
;
15359 int_type
= objfile_type (objfile
)->builtin_long
;
15360 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
15361 base_type
= int_type
;
15364 int_type
= objfile_type (objfile
)->builtin_long_long
;
15365 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
15366 base_type
= int_type
;
15371 /* Normally, the DWARF producers are expected to use a signed
15372 constant form (Eg. DW_FORM_sdata) to express negative bounds.
15373 But this is unfortunately not always the case, as witnessed
15374 with GCC, for instance, where the ambiguous DW_FORM_dataN form
15375 is used instead. To work around that ambiguity, we treat
15376 the bounds as signed, and thus sign-extend their values, when
15377 the base type is signed. */
15379 -((LONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
15380 if (low
.kind
== PROP_CONST
15381 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
15382 low
.data
.const_val
|= negative_mask
;
15383 if (high
.kind
== PROP_CONST
15384 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
15385 high
.data
.const_val
|= negative_mask
;
15387 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
);
15389 if (high_bound_is_count
)
15390 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
15392 /* Ada expects an empty array on no boundary attributes. */
15393 if (attr
== NULL
&& cu
->language
!= language_ada
)
15394 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
15396 name
= dwarf2_name (die
, cu
);
15398 TYPE_NAME (range_type
) = name
;
15400 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15402 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
15404 set_die_type (die
, range_type
, cu
);
15406 /* set_die_type should be already done. */
15407 set_descriptive_type (range_type
, die
, cu
);
15412 static struct type
*
15413 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15417 /* For now, we only support the C meaning of an unspecified type: void. */
15419 type
= init_type (cu
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
15420 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
15422 return set_die_type (die
, type
, cu
);
15425 /* Read a single die and all its descendents. Set the die's sibling
15426 field to NULL; set other fields in the die correctly, and set all
15427 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
15428 location of the info_ptr after reading all of those dies. PARENT
15429 is the parent of the die in question. */
15431 static struct die_info
*
15432 read_die_and_children (const struct die_reader_specs
*reader
,
15433 const gdb_byte
*info_ptr
,
15434 const gdb_byte
**new_info_ptr
,
15435 struct die_info
*parent
)
15437 struct die_info
*die
;
15438 const gdb_byte
*cur_ptr
;
15441 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
15444 *new_info_ptr
= cur_ptr
;
15447 store_in_ref_table (die
, reader
->cu
);
15450 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
15454 *new_info_ptr
= cur_ptr
;
15457 die
->sibling
= NULL
;
15458 die
->parent
= parent
;
15462 /* Read a die, all of its descendents, and all of its siblings; set
15463 all of the fields of all of the dies correctly. Arguments are as
15464 in read_die_and_children. */
15466 static struct die_info
*
15467 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
15468 const gdb_byte
*info_ptr
,
15469 const gdb_byte
**new_info_ptr
,
15470 struct die_info
*parent
)
15472 struct die_info
*first_die
, *last_sibling
;
15473 const gdb_byte
*cur_ptr
;
15475 cur_ptr
= info_ptr
;
15476 first_die
= last_sibling
= NULL
;
15480 struct die_info
*die
15481 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
15485 *new_info_ptr
= cur_ptr
;
15492 last_sibling
->sibling
= die
;
15494 last_sibling
= die
;
15498 /* Read a die, all of its descendents, and all of its siblings; set
15499 all of the fields of all of the dies correctly. Arguments are as
15500 in read_die_and_children.
15501 This the main entry point for reading a DIE and all its children. */
15503 static struct die_info
*
15504 read_die_and_siblings (const struct die_reader_specs
*reader
,
15505 const gdb_byte
*info_ptr
,
15506 const gdb_byte
**new_info_ptr
,
15507 struct die_info
*parent
)
15509 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
15510 new_info_ptr
, parent
);
15512 if (dwarf_die_debug
)
15514 fprintf_unfiltered (gdb_stdlog
,
15515 "Read die from %s@0x%x of %s:\n",
15516 get_section_name (reader
->die_section
),
15517 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
15518 bfd_get_filename (reader
->abfd
));
15519 dump_die (die
, dwarf_die_debug
);
15525 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
15527 The caller is responsible for filling in the extra attributes
15528 and updating (*DIEP)->num_attrs.
15529 Set DIEP to point to a newly allocated die with its information,
15530 except for its child, sibling, and parent fields.
15531 Set HAS_CHILDREN to tell whether the die has children or not. */
15533 static const gdb_byte
*
15534 read_full_die_1 (const struct die_reader_specs
*reader
,
15535 struct die_info
**diep
, const gdb_byte
*info_ptr
,
15536 int *has_children
, int num_extra_attrs
)
15538 unsigned int abbrev_number
, bytes_read
, i
;
15539 struct abbrev_info
*abbrev
;
15540 struct die_info
*die
;
15541 struct dwarf2_cu
*cu
= reader
->cu
;
15542 bfd
*abfd
= reader
->abfd
;
15544 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
15545 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
15546 info_ptr
+= bytes_read
;
15547 if (!abbrev_number
)
15554 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
15556 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
15558 bfd_get_filename (abfd
));
15560 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
15561 die
->sect_off
= sect_off
;
15562 die
->tag
= abbrev
->tag
;
15563 die
->abbrev
= abbrev_number
;
15565 /* Make the result usable.
15566 The caller needs to update num_attrs after adding the extra
15568 die
->num_attrs
= abbrev
->num_attrs
;
15570 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
15571 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
15575 *has_children
= abbrev
->has_children
;
15579 /* Read a die and all its attributes.
15580 Set DIEP to point to a newly allocated die with its information,
15581 except for its child, sibling, and parent fields.
15582 Set HAS_CHILDREN to tell whether the die has children or not. */
15584 static const gdb_byte
*
15585 read_full_die (const struct die_reader_specs
*reader
,
15586 struct die_info
**diep
, const gdb_byte
*info_ptr
,
15589 const gdb_byte
*result
;
15591 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
15593 if (dwarf_die_debug
)
15595 fprintf_unfiltered (gdb_stdlog
,
15596 "Read die from %s@0x%x of %s:\n",
15597 get_section_name (reader
->die_section
),
15598 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
15599 bfd_get_filename (reader
->abfd
));
15600 dump_die (*diep
, dwarf_die_debug
);
15606 /* Abbreviation tables.
15608 In DWARF version 2, the description of the debugging information is
15609 stored in a separate .debug_abbrev section. Before we read any
15610 dies from a section we read in all abbreviations and install them
15611 in a hash table. */
15613 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
15615 static struct abbrev_info
*
15616 abbrev_table_alloc_abbrev (struct abbrev_table
*abbrev_table
)
15618 struct abbrev_info
*abbrev
;
15620 abbrev
= XOBNEW (&abbrev_table
->abbrev_obstack
, struct abbrev_info
);
15621 memset (abbrev
, 0, sizeof (struct abbrev_info
));
15626 /* Add an abbreviation to the table. */
15629 abbrev_table_add_abbrev (struct abbrev_table
*abbrev_table
,
15630 unsigned int abbrev_number
,
15631 struct abbrev_info
*abbrev
)
15633 unsigned int hash_number
;
15635 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
15636 abbrev
->next
= abbrev_table
->abbrevs
[hash_number
];
15637 abbrev_table
->abbrevs
[hash_number
] = abbrev
;
15640 /* Look up an abbrev in the table.
15641 Returns NULL if the abbrev is not found. */
15643 static struct abbrev_info
*
15644 abbrev_table_lookup_abbrev (const struct abbrev_table
*abbrev_table
,
15645 unsigned int abbrev_number
)
15647 unsigned int hash_number
;
15648 struct abbrev_info
*abbrev
;
15650 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
15651 abbrev
= abbrev_table
->abbrevs
[hash_number
];
15655 if (abbrev
->number
== abbrev_number
)
15657 abbrev
= abbrev
->next
;
15662 /* Read in an abbrev table. */
15664 static struct abbrev_table
*
15665 abbrev_table_read_table (struct dwarf2_section_info
*section
,
15666 sect_offset sect_off
)
15668 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15669 bfd
*abfd
= get_section_bfd_owner (section
);
15670 struct abbrev_table
*abbrev_table
;
15671 const gdb_byte
*abbrev_ptr
;
15672 struct abbrev_info
*cur_abbrev
;
15673 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
15674 unsigned int abbrev_form
;
15675 struct attr_abbrev
*cur_attrs
;
15676 unsigned int allocated_attrs
;
15678 abbrev_table
= XNEW (struct abbrev_table
);
15679 abbrev_table
->sect_off
= sect_off
;
15680 obstack_init (&abbrev_table
->abbrev_obstack
);
15681 abbrev_table
->abbrevs
=
15682 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct abbrev_info
*,
15684 memset (abbrev_table
->abbrevs
, 0,
15685 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
15687 dwarf2_read_section (objfile
, section
);
15688 abbrev_ptr
= section
->buffer
+ to_underlying (sect_off
);
15689 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15690 abbrev_ptr
+= bytes_read
;
15692 allocated_attrs
= ATTR_ALLOC_CHUNK
;
15693 cur_attrs
= XNEWVEC (struct attr_abbrev
, allocated_attrs
);
15695 /* Loop until we reach an abbrev number of 0. */
15696 while (abbrev_number
)
15698 cur_abbrev
= abbrev_table_alloc_abbrev (abbrev_table
);
15700 /* read in abbrev header */
15701 cur_abbrev
->number
= abbrev_number
;
15703 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15704 abbrev_ptr
+= bytes_read
;
15705 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
15708 /* now read in declarations */
15711 LONGEST implicit_const
;
15713 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15714 abbrev_ptr
+= bytes_read
;
15715 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15716 abbrev_ptr
+= bytes_read
;
15717 if (abbrev_form
== DW_FORM_implicit_const
)
15719 implicit_const
= read_signed_leb128 (abfd
, abbrev_ptr
,
15721 abbrev_ptr
+= bytes_read
;
15725 /* Initialize it due to a false compiler warning. */
15726 implicit_const
= -1;
15729 if (abbrev_name
== 0)
15732 if (cur_abbrev
->num_attrs
== allocated_attrs
)
15734 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
15736 = XRESIZEVEC (struct attr_abbrev
, cur_attrs
, allocated_attrs
);
15739 cur_attrs
[cur_abbrev
->num_attrs
].name
15740 = (enum dwarf_attribute
) abbrev_name
;
15741 cur_attrs
[cur_abbrev
->num_attrs
].form
15742 = (enum dwarf_form
) abbrev_form
;
15743 cur_attrs
[cur_abbrev
->num_attrs
].implicit_const
= implicit_const
;
15744 ++cur_abbrev
->num_attrs
;
15747 cur_abbrev
->attrs
=
15748 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
15749 cur_abbrev
->num_attrs
);
15750 memcpy (cur_abbrev
->attrs
, cur_attrs
,
15751 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
15753 abbrev_table_add_abbrev (abbrev_table
, abbrev_number
, cur_abbrev
);
15755 /* Get next abbreviation.
15756 Under Irix6 the abbreviations for a compilation unit are not
15757 always properly terminated with an abbrev number of 0.
15758 Exit loop if we encounter an abbreviation which we have
15759 already read (which means we are about to read the abbreviations
15760 for the next compile unit) or if the end of the abbreviation
15761 table is reached. */
15762 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
15764 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15765 abbrev_ptr
+= bytes_read
;
15766 if (abbrev_table_lookup_abbrev (abbrev_table
, abbrev_number
) != NULL
)
15771 return abbrev_table
;
15774 /* Free the resources held by ABBREV_TABLE. */
15777 abbrev_table_free (struct abbrev_table
*abbrev_table
)
15779 obstack_free (&abbrev_table
->abbrev_obstack
, NULL
);
15780 xfree (abbrev_table
);
15783 /* Same as abbrev_table_free but as a cleanup.
15784 We pass in a pointer to the pointer to the table so that we can
15785 set the pointer to NULL when we're done. It also simplifies
15786 build_type_psymtabs_1. */
15789 abbrev_table_free_cleanup (void *table_ptr
)
15791 struct abbrev_table
**abbrev_table_ptr
= (struct abbrev_table
**) table_ptr
;
15793 if (*abbrev_table_ptr
!= NULL
)
15794 abbrev_table_free (*abbrev_table_ptr
);
15795 *abbrev_table_ptr
= NULL
;
15798 /* Read the abbrev table for CU from ABBREV_SECTION. */
15801 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
15802 struct dwarf2_section_info
*abbrev_section
)
15805 abbrev_table_read_table (abbrev_section
, cu
->header
.abbrev_sect_off
);
15808 /* Release the memory used by the abbrev table for a compilation unit. */
15811 dwarf2_free_abbrev_table (void *ptr_to_cu
)
15813 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr_to_cu
;
15815 if (cu
->abbrev_table
!= NULL
)
15816 abbrev_table_free (cu
->abbrev_table
);
15817 /* Set this to NULL so that we SEGV if we try to read it later,
15818 and also because free_comp_unit verifies this is NULL. */
15819 cu
->abbrev_table
= NULL
;
15822 /* Returns nonzero if TAG represents a type that we might generate a partial
15826 is_type_tag_for_partial (int tag
)
15831 /* Some types that would be reasonable to generate partial symbols for,
15832 that we don't at present. */
15833 case DW_TAG_array_type
:
15834 case DW_TAG_file_type
:
15835 case DW_TAG_ptr_to_member_type
:
15836 case DW_TAG_set_type
:
15837 case DW_TAG_string_type
:
15838 case DW_TAG_subroutine_type
:
15840 case DW_TAG_base_type
:
15841 case DW_TAG_class_type
:
15842 case DW_TAG_interface_type
:
15843 case DW_TAG_enumeration_type
:
15844 case DW_TAG_structure_type
:
15845 case DW_TAG_subrange_type
:
15846 case DW_TAG_typedef
:
15847 case DW_TAG_union_type
:
15854 /* Load all DIEs that are interesting for partial symbols into memory. */
15856 static struct partial_die_info
*
15857 load_partial_dies (const struct die_reader_specs
*reader
,
15858 const gdb_byte
*info_ptr
, int building_psymtab
)
15860 struct dwarf2_cu
*cu
= reader
->cu
;
15861 struct objfile
*objfile
= cu
->objfile
;
15862 struct partial_die_info
*part_die
;
15863 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
15864 struct abbrev_info
*abbrev
;
15865 unsigned int bytes_read
;
15866 unsigned int load_all
= 0;
15867 int nesting_level
= 1;
15872 gdb_assert (cu
->per_cu
!= NULL
);
15873 if (cu
->per_cu
->load_all_dies
)
15877 = htab_create_alloc_ex (cu
->header
.length
/ 12,
15881 &cu
->comp_unit_obstack
,
15882 hashtab_obstack_allocate
,
15883 dummy_obstack_deallocate
);
15885 part_die
= XOBNEW (&cu
->comp_unit_obstack
, struct partial_die_info
);
15889 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
15891 /* A NULL abbrev means the end of a series of children. */
15892 if (abbrev
== NULL
)
15894 if (--nesting_level
== 0)
15896 /* PART_DIE was probably the last thing allocated on the
15897 comp_unit_obstack, so we could call obstack_free
15898 here. We don't do that because the waste is small,
15899 and will be cleaned up when we're done with this
15900 compilation unit. This way, we're also more robust
15901 against other users of the comp_unit_obstack. */
15904 info_ptr
+= bytes_read
;
15905 last_die
= parent_die
;
15906 parent_die
= parent_die
->die_parent
;
15910 /* Check for template arguments. We never save these; if
15911 they're seen, we just mark the parent, and go on our way. */
15912 if (parent_die
!= NULL
15913 && cu
->language
== language_cplus
15914 && (abbrev
->tag
== DW_TAG_template_type_param
15915 || abbrev
->tag
== DW_TAG_template_value_param
))
15917 parent_die
->has_template_arguments
= 1;
15921 /* We don't need a partial DIE for the template argument. */
15922 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
15927 /* We only recurse into c++ subprograms looking for template arguments.
15928 Skip their other children. */
15930 && cu
->language
== language_cplus
15931 && parent_die
!= NULL
15932 && parent_die
->tag
== DW_TAG_subprogram
)
15934 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
15938 /* Check whether this DIE is interesting enough to save. Normally
15939 we would not be interested in members here, but there may be
15940 later variables referencing them via DW_AT_specification (for
15941 static members). */
15943 && !is_type_tag_for_partial (abbrev
->tag
)
15944 && abbrev
->tag
!= DW_TAG_constant
15945 && abbrev
->tag
!= DW_TAG_enumerator
15946 && abbrev
->tag
!= DW_TAG_subprogram
15947 && abbrev
->tag
!= DW_TAG_lexical_block
15948 && abbrev
->tag
!= DW_TAG_variable
15949 && abbrev
->tag
!= DW_TAG_namespace
15950 && abbrev
->tag
!= DW_TAG_module
15951 && abbrev
->tag
!= DW_TAG_member
15952 && abbrev
->tag
!= DW_TAG_imported_unit
15953 && abbrev
->tag
!= DW_TAG_imported_declaration
)
15955 /* Otherwise we skip to the next sibling, if any. */
15956 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
15960 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
15963 /* This two-pass algorithm for processing partial symbols has a
15964 high cost in cache pressure. Thus, handle some simple cases
15965 here which cover the majority of C partial symbols. DIEs
15966 which neither have specification tags in them, nor could have
15967 specification tags elsewhere pointing at them, can simply be
15968 processed and discarded.
15970 This segment is also optional; scan_partial_symbols and
15971 add_partial_symbol will handle these DIEs if we chain
15972 them in normally. When compilers which do not emit large
15973 quantities of duplicate debug information are more common,
15974 this code can probably be removed. */
15976 /* Any complete simple types at the top level (pretty much all
15977 of them, for a language without namespaces), can be processed
15979 if (parent_die
== NULL
15980 && part_die
->has_specification
== 0
15981 && part_die
->is_declaration
== 0
15982 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
15983 || part_die
->tag
== DW_TAG_base_type
15984 || part_die
->tag
== DW_TAG_subrange_type
))
15986 if (building_psymtab
&& part_die
->name
!= NULL
)
15987 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
15988 VAR_DOMAIN
, LOC_TYPEDEF
,
15989 &objfile
->static_psymbols
,
15990 0, cu
->language
, objfile
);
15991 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
15995 /* The exception for DW_TAG_typedef with has_children above is
15996 a workaround of GCC PR debug/47510. In the case of this complaint
15997 type_name_no_tag_or_error will error on such types later.
15999 GDB skipped children of DW_TAG_typedef by the shortcut above and then
16000 it could not find the child DIEs referenced later, this is checked
16001 above. In correct DWARF DW_TAG_typedef should have no children. */
16003 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
16004 complaint (&symfile_complaints
,
16005 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
16006 "- DIE at 0x%x [in module %s]"),
16007 to_underlying (part_die
->sect_off
), objfile_name (objfile
));
16009 /* If we're at the second level, and we're an enumerator, and
16010 our parent has no specification (meaning possibly lives in a
16011 namespace elsewhere), then we can add the partial symbol now
16012 instead of queueing it. */
16013 if (part_die
->tag
== DW_TAG_enumerator
16014 && parent_die
!= NULL
16015 && parent_die
->die_parent
== NULL
16016 && parent_die
->tag
== DW_TAG_enumeration_type
16017 && parent_die
->has_specification
== 0)
16019 if (part_die
->name
== NULL
)
16020 complaint (&symfile_complaints
,
16021 _("malformed enumerator DIE ignored"));
16022 else if (building_psymtab
)
16023 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
16024 VAR_DOMAIN
, LOC_CONST
,
16025 cu
->language
== language_cplus
16026 ? &objfile
->global_psymbols
16027 : &objfile
->static_psymbols
,
16028 0, cu
->language
, objfile
);
16030 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
16034 /* We'll save this DIE so link it in. */
16035 part_die
->die_parent
= parent_die
;
16036 part_die
->die_sibling
= NULL
;
16037 part_die
->die_child
= NULL
;
16039 if (last_die
&& last_die
== parent_die
)
16040 last_die
->die_child
= part_die
;
16042 last_die
->die_sibling
= part_die
;
16044 last_die
= part_die
;
16046 if (first_die
== NULL
)
16047 first_die
= part_die
;
16049 /* Maybe add the DIE to the hash table. Not all DIEs that we
16050 find interesting need to be in the hash table, because we
16051 also have the parent/sibling/child chains; only those that we
16052 might refer to by offset later during partial symbol reading.
16054 For now this means things that might have be the target of a
16055 DW_AT_specification, DW_AT_abstract_origin, or
16056 DW_AT_extension. DW_AT_extension will refer only to
16057 namespaces; DW_AT_abstract_origin refers to functions (and
16058 many things under the function DIE, but we do not recurse
16059 into function DIEs during partial symbol reading) and
16060 possibly variables as well; DW_AT_specification refers to
16061 declarations. Declarations ought to have the DW_AT_declaration
16062 flag. It happens that GCC forgets to put it in sometimes, but
16063 only for functions, not for types.
16065 Adding more things than necessary to the hash table is harmless
16066 except for the performance cost. Adding too few will result in
16067 wasted time in find_partial_die, when we reread the compilation
16068 unit with load_all_dies set. */
16071 || abbrev
->tag
== DW_TAG_constant
16072 || abbrev
->tag
== DW_TAG_subprogram
16073 || abbrev
->tag
== DW_TAG_variable
16074 || abbrev
->tag
== DW_TAG_namespace
16075 || part_die
->is_declaration
)
16079 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
16080 to_underlying (part_die
->sect_off
),
16085 part_die
= XOBNEW (&cu
->comp_unit_obstack
, struct partial_die_info
);
16087 /* For some DIEs we want to follow their children (if any). For C
16088 we have no reason to follow the children of structures; for other
16089 languages we have to, so that we can get at method physnames
16090 to infer fully qualified class names, for DW_AT_specification,
16091 and for C++ template arguments. For C++, we also look one level
16092 inside functions to find template arguments (if the name of the
16093 function does not already contain the template arguments).
16095 For Ada, we need to scan the children of subprograms and lexical
16096 blocks as well because Ada allows the definition of nested
16097 entities that could be interesting for the debugger, such as
16098 nested subprograms for instance. */
16099 if (last_die
->has_children
16101 || last_die
->tag
== DW_TAG_namespace
16102 || last_die
->tag
== DW_TAG_module
16103 || last_die
->tag
== DW_TAG_enumeration_type
16104 || (cu
->language
== language_cplus
16105 && last_die
->tag
== DW_TAG_subprogram
16106 && (last_die
->name
== NULL
16107 || strchr (last_die
->name
, '<') == NULL
))
16108 || (cu
->language
!= language_c
16109 && (last_die
->tag
== DW_TAG_class_type
16110 || last_die
->tag
== DW_TAG_interface_type
16111 || last_die
->tag
== DW_TAG_structure_type
16112 || last_die
->tag
== DW_TAG_union_type
))
16113 || (cu
->language
== language_ada
16114 && (last_die
->tag
== DW_TAG_subprogram
16115 || last_die
->tag
== DW_TAG_lexical_block
))))
16118 parent_die
= last_die
;
16122 /* Otherwise we skip to the next sibling, if any. */
16123 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
16125 /* Back to the top, do it again. */
16129 /* Read a minimal amount of information into the minimal die structure. */
16131 static const gdb_byte
*
16132 read_partial_die (const struct die_reader_specs
*reader
,
16133 struct partial_die_info
*part_die
,
16134 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
16135 const gdb_byte
*info_ptr
)
16137 struct dwarf2_cu
*cu
= reader
->cu
;
16138 struct objfile
*objfile
= cu
->objfile
;
16139 const gdb_byte
*buffer
= reader
->buffer
;
16141 struct attribute attr
;
16142 int has_low_pc_attr
= 0;
16143 int has_high_pc_attr
= 0;
16144 int high_pc_relative
= 0;
16146 memset (part_die
, 0, sizeof (struct partial_die_info
));
16148 part_die
->sect_off
= (sect_offset
) (info_ptr
- buffer
);
16150 info_ptr
+= abbrev_len
;
16152 if (abbrev
== NULL
)
16155 part_die
->tag
= abbrev
->tag
;
16156 part_die
->has_children
= abbrev
->has_children
;
16158 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
16160 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
16162 /* Store the data if it is of an attribute we want to keep in a
16163 partial symbol table. */
16167 switch (part_die
->tag
)
16169 case DW_TAG_compile_unit
:
16170 case DW_TAG_partial_unit
:
16171 case DW_TAG_type_unit
:
16172 /* Compilation units have a DW_AT_name that is a filename, not
16173 a source language identifier. */
16174 case DW_TAG_enumeration_type
:
16175 case DW_TAG_enumerator
:
16176 /* These tags always have simple identifiers already; no need
16177 to canonicalize them. */
16178 part_die
->name
= DW_STRING (&attr
);
16182 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
16183 &objfile
->per_bfd
->storage_obstack
);
16187 case DW_AT_linkage_name
:
16188 case DW_AT_MIPS_linkage_name
:
16189 /* Note that both forms of linkage name might appear. We
16190 assume they will be the same, and we only store the last
16192 if (cu
->language
== language_ada
)
16193 part_die
->name
= DW_STRING (&attr
);
16194 part_die
->linkage_name
= DW_STRING (&attr
);
16197 has_low_pc_attr
= 1;
16198 part_die
->lowpc
= attr_value_as_address (&attr
);
16200 case DW_AT_high_pc
:
16201 has_high_pc_attr
= 1;
16202 part_die
->highpc
= attr_value_as_address (&attr
);
16203 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
16204 high_pc_relative
= 1;
16206 case DW_AT_location
:
16207 /* Support the .debug_loc offsets. */
16208 if (attr_form_is_block (&attr
))
16210 part_die
->d
.locdesc
= DW_BLOCK (&attr
);
16212 else if (attr_form_is_section_offset (&attr
))
16214 dwarf2_complex_location_expr_complaint ();
16218 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16219 "partial symbol information");
16222 case DW_AT_external
:
16223 part_die
->is_external
= DW_UNSND (&attr
);
16225 case DW_AT_declaration
:
16226 part_die
->is_declaration
= DW_UNSND (&attr
);
16229 part_die
->has_type
= 1;
16231 case DW_AT_abstract_origin
:
16232 case DW_AT_specification
:
16233 case DW_AT_extension
:
16234 part_die
->has_specification
= 1;
16235 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
16236 part_die
->spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
16237 || cu
->per_cu
->is_dwz
);
16239 case DW_AT_sibling
:
16240 /* Ignore absolute siblings, they might point outside of
16241 the current compile unit. */
16242 if (attr
.form
== DW_FORM_ref_addr
)
16243 complaint (&symfile_complaints
,
16244 _("ignoring absolute DW_AT_sibling"));
16247 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
16248 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
16250 if (sibling_ptr
< info_ptr
)
16251 complaint (&symfile_complaints
,
16252 _("DW_AT_sibling points backwards"));
16253 else if (sibling_ptr
> reader
->buffer_end
)
16254 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
16256 part_die
->sibling
= sibling_ptr
;
16259 case DW_AT_byte_size
:
16260 part_die
->has_byte_size
= 1;
16262 case DW_AT_const_value
:
16263 part_die
->has_const_value
= 1;
16265 case DW_AT_calling_convention
:
16266 /* DWARF doesn't provide a way to identify a program's source-level
16267 entry point. DW_AT_calling_convention attributes are only meant
16268 to describe functions' calling conventions.
16270 However, because it's a necessary piece of information in
16271 Fortran, and before DWARF 4 DW_CC_program was the only
16272 piece of debugging information whose definition refers to
16273 a 'main program' at all, several compilers marked Fortran
16274 main programs with DW_CC_program --- even when those
16275 functions use the standard calling conventions.
16277 Although DWARF now specifies a way to provide this
16278 information, we support this practice for backward
16280 if (DW_UNSND (&attr
) == DW_CC_program
16281 && cu
->language
== language_fortran
)
16282 part_die
->main_subprogram
= 1;
16285 if (DW_UNSND (&attr
) == DW_INL_inlined
16286 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
16287 part_die
->may_be_inlined
= 1;
16291 if (part_die
->tag
== DW_TAG_imported_unit
)
16293 part_die
->d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
16294 part_die
->is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
16295 || cu
->per_cu
->is_dwz
);
16299 case DW_AT_main_subprogram
:
16300 part_die
->main_subprogram
= DW_UNSND (&attr
);
16308 if (high_pc_relative
)
16309 part_die
->highpc
+= part_die
->lowpc
;
16311 if (has_low_pc_attr
&& has_high_pc_attr
)
16313 /* When using the GNU linker, .gnu.linkonce. sections are used to
16314 eliminate duplicate copies of functions and vtables and such.
16315 The linker will arbitrarily choose one and discard the others.
16316 The AT_*_pc values for such functions refer to local labels in
16317 these sections. If the section from that file was discarded, the
16318 labels are not in the output, so the relocs get a value of 0.
16319 If this is a discarded function, mark the pc bounds as invalid,
16320 so that GDB will ignore it. */
16321 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
16323 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16325 complaint (&symfile_complaints
,
16326 _("DW_AT_low_pc %s is zero "
16327 "for DIE at 0x%x [in module %s]"),
16328 paddress (gdbarch
, part_die
->lowpc
),
16329 to_underlying (part_die
->sect_off
), objfile_name (objfile
));
16331 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
16332 else if (part_die
->lowpc
>= part_die
->highpc
)
16334 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16336 complaint (&symfile_complaints
,
16337 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
16338 "for DIE at 0x%x [in module %s]"),
16339 paddress (gdbarch
, part_die
->lowpc
),
16340 paddress (gdbarch
, part_die
->highpc
),
16341 to_underlying (part_die
->sect_off
),
16342 objfile_name (objfile
));
16345 part_die
->has_pc_info
= 1;
16351 /* Find a cached partial DIE at OFFSET in CU. */
16353 static struct partial_die_info
*
16354 find_partial_die_in_comp_unit (sect_offset sect_off
, struct dwarf2_cu
*cu
)
16356 struct partial_die_info
*lookup_die
= NULL
;
16357 struct partial_die_info part_die
;
16359 part_die
.sect_off
= sect_off
;
16360 lookup_die
= ((struct partial_die_info
*)
16361 htab_find_with_hash (cu
->partial_dies
, &part_die
,
16362 to_underlying (sect_off
)));
16367 /* Find a partial DIE at OFFSET, which may or may not be in CU,
16368 except in the case of .debug_types DIEs which do not reference
16369 outside their CU (they do however referencing other types via
16370 DW_FORM_ref_sig8). */
16372 static struct partial_die_info
*
16373 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
16375 struct objfile
*objfile
= cu
->objfile
;
16376 struct dwarf2_per_cu_data
*per_cu
= NULL
;
16377 struct partial_die_info
*pd
= NULL
;
16379 if (offset_in_dwz
== cu
->per_cu
->is_dwz
16380 && offset_in_cu_p (&cu
->header
, sect_off
))
16382 pd
= find_partial_die_in_comp_unit (sect_off
, cu
);
16385 /* We missed recording what we needed.
16386 Load all dies and try again. */
16387 per_cu
= cu
->per_cu
;
16391 /* TUs don't reference other CUs/TUs (except via type signatures). */
16392 if (cu
->per_cu
->is_debug_types
)
16394 error (_("Dwarf Error: Type Unit at offset 0x%x contains"
16395 " external reference to offset 0x%x [in module %s].\n"),
16396 to_underlying (cu
->header
.sect_off
), to_underlying (sect_off
),
16397 bfd_get_filename (objfile
->obfd
));
16399 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
16402 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
16403 load_partial_comp_unit (per_cu
);
16405 per_cu
->cu
->last_used
= 0;
16406 pd
= find_partial_die_in_comp_unit (sect_off
, per_cu
->cu
);
16409 /* If we didn't find it, and not all dies have been loaded,
16410 load them all and try again. */
16412 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
16414 per_cu
->load_all_dies
= 1;
16416 /* This is nasty. When we reread the DIEs, somewhere up the call chain
16417 THIS_CU->cu may already be in use. So we can't just free it and
16418 replace its DIEs with the ones we read in. Instead, we leave those
16419 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
16420 and clobber THIS_CU->cu->partial_dies with the hash table for the new
16422 load_partial_comp_unit (per_cu
);
16424 pd
= find_partial_die_in_comp_unit (sect_off
, per_cu
->cu
);
16428 internal_error (__FILE__
, __LINE__
,
16429 _("could not find partial DIE 0x%x "
16430 "in cache [from module %s]\n"),
16431 to_underlying (sect_off
), bfd_get_filename (objfile
->obfd
));
16435 /* See if we can figure out if the class lives in a namespace. We do
16436 this by looking for a member function; its demangled name will
16437 contain namespace info, if there is any. */
16440 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
16441 struct dwarf2_cu
*cu
)
16443 /* NOTE: carlton/2003-10-07: Getting the info this way changes
16444 what template types look like, because the demangler
16445 frequently doesn't give the same name as the debug info. We
16446 could fix this by only using the demangled name to get the
16447 prefix (but see comment in read_structure_type). */
16449 struct partial_die_info
*real_pdi
;
16450 struct partial_die_info
*child_pdi
;
16452 /* If this DIE (this DIE's specification, if any) has a parent, then
16453 we should not do this. We'll prepend the parent's fully qualified
16454 name when we create the partial symbol. */
16456 real_pdi
= struct_pdi
;
16457 while (real_pdi
->has_specification
)
16458 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
16459 real_pdi
->spec_is_dwz
, cu
);
16461 if (real_pdi
->die_parent
!= NULL
)
16464 for (child_pdi
= struct_pdi
->die_child
;
16466 child_pdi
= child_pdi
->die_sibling
)
16468 if (child_pdi
->tag
== DW_TAG_subprogram
16469 && child_pdi
->linkage_name
!= NULL
)
16471 char *actual_class_name
16472 = language_class_name_from_physname (cu
->language_defn
,
16473 child_pdi
->linkage_name
);
16474 if (actual_class_name
!= NULL
)
16478 obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
16480 strlen (actual_class_name
)));
16481 xfree (actual_class_name
);
16488 /* Adjust PART_DIE before generating a symbol for it. This function
16489 may set the is_external flag or change the DIE's name. */
16492 fixup_partial_die (struct partial_die_info
*part_die
,
16493 struct dwarf2_cu
*cu
)
16495 /* Once we've fixed up a die, there's no point in doing so again.
16496 This also avoids a memory leak if we were to call
16497 guess_partial_die_structure_name multiple times. */
16498 if (part_die
->fixup_called
)
16501 /* If we found a reference attribute and the DIE has no name, try
16502 to find a name in the referred to DIE. */
16504 if (part_die
->name
== NULL
&& part_die
->has_specification
)
16506 struct partial_die_info
*spec_die
;
16508 spec_die
= find_partial_die (part_die
->spec_offset
,
16509 part_die
->spec_is_dwz
, cu
);
16511 fixup_partial_die (spec_die
, cu
);
16513 if (spec_die
->name
)
16515 part_die
->name
= spec_die
->name
;
16517 /* Copy DW_AT_external attribute if it is set. */
16518 if (spec_die
->is_external
)
16519 part_die
->is_external
= spec_die
->is_external
;
16523 /* Set default names for some unnamed DIEs. */
16525 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
16526 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
16528 /* If there is no parent die to provide a namespace, and there are
16529 children, see if we can determine the namespace from their linkage
16531 if (cu
->language
== language_cplus
16532 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
16533 && part_die
->die_parent
== NULL
16534 && part_die
->has_children
16535 && (part_die
->tag
== DW_TAG_class_type
16536 || part_die
->tag
== DW_TAG_structure_type
16537 || part_die
->tag
== DW_TAG_union_type
))
16538 guess_partial_die_structure_name (part_die
, cu
);
16540 /* GCC might emit a nameless struct or union that has a linkage
16541 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
16542 if (part_die
->name
== NULL
16543 && (part_die
->tag
== DW_TAG_class_type
16544 || part_die
->tag
== DW_TAG_interface_type
16545 || part_die
->tag
== DW_TAG_structure_type
16546 || part_die
->tag
== DW_TAG_union_type
)
16547 && part_die
->linkage_name
!= NULL
)
16551 demangled
= gdb_demangle (part_die
->linkage_name
, DMGL_TYPES
);
16556 /* Strip any leading namespaces/classes, keep only the base name.
16557 DW_AT_name for named DIEs does not contain the prefixes. */
16558 base
= strrchr (demangled
, ':');
16559 if (base
&& base
> demangled
&& base
[-1] == ':')
16566 obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
16567 base
, strlen (base
)));
16572 part_die
->fixup_called
= 1;
16575 /* Read an attribute value described by an attribute form. */
16577 static const gdb_byte
*
16578 read_attribute_value (const struct die_reader_specs
*reader
,
16579 struct attribute
*attr
, unsigned form
,
16580 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
16582 struct dwarf2_cu
*cu
= reader
->cu
;
16583 struct objfile
*objfile
= cu
->objfile
;
16584 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16585 bfd
*abfd
= reader
->abfd
;
16586 struct comp_unit_head
*cu_header
= &cu
->header
;
16587 unsigned int bytes_read
;
16588 struct dwarf_block
*blk
;
16590 attr
->form
= (enum dwarf_form
) form
;
16593 case DW_FORM_ref_addr
:
16594 if (cu
->header
.version
== 2)
16595 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
16597 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
16598 &cu
->header
, &bytes_read
);
16599 info_ptr
+= bytes_read
;
16601 case DW_FORM_GNU_ref_alt
:
16602 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
16603 info_ptr
+= bytes_read
;
16606 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
16607 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
16608 info_ptr
+= bytes_read
;
16610 case DW_FORM_block2
:
16611 blk
= dwarf_alloc_block (cu
);
16612 blk
->size
= read_2_bytes (abfd
, info_ptr
);
16614 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
16615 info_ptr
+= blk
->size
;
16616 DW_BLOCK (attr
) = blk
;
16618 case DW_FORM_block4
:
16619 blk
= dwarf_alloc_block (cu
);
16620 blk
->size
= read_4_bytes (abfd
, info_ptr
);
16622 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
16623 info_ptr
+= blk
->size
;
16624 DW_BLOCK (attr
) = blk
;
16626 case DW_FORM_data2
:
16627 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
16630 case DW_FORM_data4
:
16631 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
16634 case DW_FORM_data8
:
16635 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
16638 case DW_FORM_data16
:
16639 blk
= dwarf_alloc_block (cu
);
16641 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
16643 DW_BLOCK (attr
) = blk
;
16645 case DW_FORM_sec_offset
:
16646 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
16647 info_ptr
+= bytes_read
;
16649 case DW_FORM_string
:
16650 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
16651 DW_STRING_IS_CANONICAL (attr
) = 0;
16652 info_ptr
+= bytes_read
;
16655 if (!cu
->per_cu
->is_dwz
)
16657 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
16659 DW_STRING_IS_CANONICAL (attr
) = 0;
16660 info_ptr
+= bytes_read
;
16664 case DW_FORM_line_strp
:
16665 if (!cu
->per_cu
->is_dwz
)
16667 DW_STRING (attr
) = read_indirect_line_string (abfd
, info_ptr
,
16668 cu_header
, &bytes_read
);
16669 DW_STRING_IS_CANONICAL (attr
) = 0;
16670 info_ptr
+= bytes_read
;
16674 case DW_FORM_GNU_strp_alt
:
16676 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
16677 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
16680 DW_STRING (attr
) = read_indirect_string_from_dwz (dwz
, str_offset
);
16681 DW_STRING_IS_CANONICAL (attr
) = 0;
16682 info_ptr
+= bytes_read
;
16685 case DW_FORM_exprloc
:
16686 case DW_FORM_block
:
16687 blk
= dwarf_alloc_block (cu
);
16688 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
16689 info_ptr
+= bytes_read
;
16690 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
16691 info_ptr
+= blk
->size
;
16692 DW_BLOCK (attr
) = blk
;
16694 case DW_FORM_block1
:
16695 blk
= dwarf_alloc_block (cu
);
16696 blk
->size
= read_1_byte (abfd
, info_ptr
);
16698 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
16699 info_ptr
+= blk
->size
;
16700 DW_BLOCK (attr
) = blk
;
16702 case DW_FORM_data1
:
16703 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
16707 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
16710 case DW_FORM_flag_present
:
16711 DW_UNSND (attr
) = 1;
16713 case DW_FORM_sdata
:
16714 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
16715 info_ptr
+= bytes_read
;
16717 case DW_FORM_udata
:
16718 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
16719 info_ptr
+= bytes_read
;
16722 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
16723 + read_1_byte (abfd
, info_ptr
));
16727 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
16728 + read_2_bytes (abfd
, info_ptr
));
16732 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
16733 + read_4_bytes (abfd
, info_ptr
));
16737 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
16738 + read_8_bytes (abfd
, info_ptr
));
16741 case DW_FORM_ref_sig8
:
16742 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
16745 case DW_FORM_ref_udata
:
16746 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
16747 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
16748 info_ptr
+= bytes_read
;
16750 case DW_FORM_indirect
:
16751 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
16752 info_ptr
+= bytes_read
;
16753 if (form
== DW_FORM_implicit_const
)
16755 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
16756 info_ptr
+= bytes_read
;
16758 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
16761 case DW_FORM_implicit_const
:
16762 DW_SND (attr
) = implicit_const
;
16764 case DW_FORM_GNU_addr_index
:
16765 if (reader
->dwo_file
== NULL
)
16767 /* For now flag a hard error.
16768 Later we can turn this into a complaint. */
16769 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
16770 dwarf_form_name (form
),
16771 bfd_get_filename (abfd
));
16773 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
16774 info_ptr
+= bytes_read
;
16776 case DW_FORM_GNU_str_index
:
16777 if (reader
->dwo_file
== NULL
)
16779 /* For now flag a hard error.
16780 Later we can turn this into a complaint if warranted. */
16781 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
16782 dwarf_form_name (form
),
16783 bfd_get_filename (abfd
));
16786 ULONGEST str_index
=
16787 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
16789 DW_STRING (attr
) = read_str_index (reader
, str_index
);
16790 DW_STRING_IS_CANONICAL (attr
) = 0;
16791 info_ptr
+= bytes_read
;
16795 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
16796 dwarf_form_name (form
),
16797 bfd_get_filename (abfd
));
16801 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
16802 attr
->form
= DW_FORM_GNU_ref_alt
;
16804 /* We have seen instances where the compiler tried to emit a byte
16805 size attribute of -1 which ended up being encoded as an unsigned
16806 0xffffffff. Although 0xffffffff is technically a valid size value,
16807 an object of this size seems pretty unlikely so we can relatively
16808 safely treat these cases as if the size attribute was invalid and
16809 treat them as zero by default. */
16810 if (attr
->name
== DW_AT_byte_size
16811 && form
== DW_FORM_data4
16812 && DW_UNSND (attr
) >= 0xffffffff)
16815 (&symfile_complaints
,
16816 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
16817 hex_string (DW_UNSND (attr
)));
16818 DW_UNSND (attr
) = 0;
16824 /* Read an attribute described by an abbreviated attribute. */
16826 static const gdb_byte
*
16827 read_attribute (const struct die_reader_specs
*reader
,
16828 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
16829 const gdb_byte
*info_ptr
)
16831 attr
->name
= abbrev
->name
;
16832 return read_attribute_value (reader
, attr
, abbrev
->form
,
16833 abbrev
->implicit_const
, info_ptr
);
16836 /* Read dwarf information from a buffer. */
16838 static unsigned int
16839 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
16841 return bfd_get_8 (abfd
, buf
);
16845 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
16847 return bfd_get_signed_8 (abfd
, buf
);
16850 static unsigned int
16851 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
16853 return bfd_get_16 (abfd
, buf
);
16857 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
16859 return bfd_get_signed_16 (abfd
, buf
);
16862 static unsigned int
16863 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
16865 return bfd_get_32 (abfd
, buf
);
16869 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
16871 return bfd_get_signed_32 (abfd
, buf
);
16875 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
16877 return bfd_get_64 (abfd
, buf
);
16881 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
16882 unsigned int *bytes_read
)
16884 struct comp_unit_head
*cu_header
= &cu
->header
;
16885 CORE_ADDR retval
= 0;
16887 if (cu_header
->signed_addr_p
)
16889 switch (cu_header
->addr_size
)
16892 retval
= bfd_get_signed_16 (abfd
, buf
);
16895 retval
= bfd_get_signed_32 (abfd
, buf
);
16898 retval
= bfd_get_signed_64 (abfd
, buf
);
16901 internal_error (__FILE__
, __LINE__
,
16902 _("read_address: bad switch, signed [in module %s]"),
16903 bfd_get_filename (abfd
));
16908 switch (cu_header
->addr_size
)
16911 retval
= bfd_get_16 (abfd
, buf
);
16914 retval
= bfd_get_32 (abfd
, buf
);
16917 retval
= bfd_get_64 (abfd
, buf
);
16920 internal_error (__FILE__
, __LINE__
,
16921 _("read_address: bad switch, "
16922 "unsigned [in module %s]"),
16923 bfd_get_filename (abfd
));
16927 *bytes_read
= cu_header
->addr_size
;
16931 /* Read the initial length from a section. The (draft) DWARF 3
16932 specification allows the initial length to take up either 4 bytes
16933 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
16934 bytes describe the length and all offsets will be 8 bytes in length
16937 An older, non-standard 64-bit format is also handled by this
16938 function. The older format in question stores the initial length
16939 as an 8-byte quantity without an escape value. Lengths greater
16940 than 2^32 aren't very common which means that the initial 4 bytes
16941 is almost always zero. Since a length value of zero doesn't make
16942 sense for the 32-bit format, this initial zero can be considered to
16943 be an escape value which indicates the presence of the older 64-bit
16944 format. As written, the code can't detect (old format) lengths
16945 greater than 4GB. If it becomes necessary to handle lengths
16946 somewhat larger than 4GB, we could allow other small values (such
16947 as the non-sensical values of 1, 2, and 3) to also be used as
16948 escape values indicating the presence of the old format.
16950 The value returned via bytes_read should be used to increment the
16951 relevant pointer after calling read_initial_length().
16953 [ Note: read_initial_length() and read_offset() are based on the
16954 document entitled "DWARF Debugging Information Format", revision
16955 3, draft 8, dated November 19, 2001. This document was obtained
16958 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
16960 This document is only a draft and is subject to change. (So beware.)
16962 Details regarding the older, non-standard 64-bit format were
16963 determined empirically by examining 64-bit ELF files produced by
16964 the SGI toolchain on an IRIX 6.5 machine.
16966 - Kevin, July 16, 2002
16970 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
16972 LONGEST length
= bfd_get_32 (abfd
, buf
);
16974 if (length
== 0xffffffff)
16976 length
= bfd_get_64 (abfd
, buf
+ 4);
16979 else if (length
== 0)
16981 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
16982 length
= bfd_get_64 (abfd
, buf
);
16993 /* Cover function for read_initial_length.
16994 Returns the length of the object at BUF, and stores the size of the
16995 initial length in *BYTES_READ and stores the size that offsets will be in
16997 If the initial length size is not equivalent to that specified in
16998 CU_HEADER then issue a complaint.
16999 This is useful when reading non-comp-unit headers. */
17002 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
17003 const struct comp_unit_head
*cu_header
,
17004 unsigned int *bytes_read
,
17005 unsigned int *offset_size
)
17007 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
17009 gdb_assert (cu_header
->initial_length_size
== 4
17010 || cu_header
->initial_length_size
== 8
17011 || cu_header
->initial_length_size
== 12);
17013 if (cu_header
->initial_length_size
!= *bytes_read
)
17014 complaint (&symfile_complaints
,
17015 _("intermixed 32-bit and 64-bit DWARF sections"));
17017 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
17021 /* Read an offset from the data stream. The size of the offset is
17022 given by cu_header->offset_size. */
17025 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
17026 const struct comp_unit_head
*cu_header
,
17027 unsigned int *bytes_read
)
17029 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
17031 *bytes_read
= cu_header
->offset_size
;
17035 /* Read an offset from the data stream. */
17038 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
17040 LONGEST retval
= 0;
17042 switch (offset_size
)
17045 retval
= bfd_get_32 (abfd
, buf
);
17048 retval
= bfd_get_64 (abfd
, buf
);
17051 internal_error (__FILE__
, __LINE__
,
17052 _("read_offset_1: bad switch [in module %s]"),
17053 bfd_get_filename (abfd
));
17059 static const gdb_byte
*
17060 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
17062 /* If the size of a host char is 8 bits, we can return a pointer
17063 to the buffer, otherwise we have to copy the data to a buffer
17064 allocated on the temporary obstack. */
17065 gdb_assert (HOST_CHAR_BIT
== 8);
17069 static const char *
17070 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
17071 unsigned int *bytes_read_ptr
)
17073 /* If the size of a host char is 8 bits, we can return a pointer
17074 to the string, otherwise we have to copy the string to a buffer
17075 allocated on the temporary obstack. */
17076 gdb_assert (HOST_CHAR_BIT
== 8);
17079 *bytes_read_ptr
= 1;
17082 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
17083 return (const char *) buf
;
17086 /* Return pointer to string at section SECT offset STR_OFFSET with error
17087 reporting strings FORM_NAME and SECT_NAME. */
17089 static const char *
17090 read_indirect_string_at_offset_from (bfd
*abfd
, LONGEST str_offset
,
17091 struct dwarf2_section_info
*sect
,
17092 const char *form_name
,
17093 const char *sect_name
)
17095 dwarf2_read_section (dwarf2_per_objfile
->objfile
, sect
);
17096 if (sect
->buffer
== NULL
)
17097 error (_("%s used without %s section [in module %s]"),
17098 form_name
, sect_name
, bfd_get_filename (abfd
));
17099 if (str_offset
>= sect
->size
)
17100 error (_("%s pointing outside of %s section [in module %s]"),
17101 form_name
, sect_name
, bfd_get_filename (abfd
));
17102 gdb_assert (HOST_CHAR_BIT
== 8);
17103 if (sect
->buffer
[str_offset
] == '\0')
17105 return (const char *) (sect
->buffer
+ str_offset
);
17108 /* Return pointer to string at .debug_str offset STR_OFFSET. */
17110 static const char *
17111 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
17113 return read_indirect_string_at_offset_from (abfd
, str_offset
,
17114 &dwarf2_per_objfile
->str
,
17115 "DW_FORM_strp", ".debug_str");
17118 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
17120 static const char *
17121 read_indirect_line_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
17123 return read_indirect_string_at_offset_from (abfd
, str_offset
,
17124 &dwarf2_per_objfile
->line_str
,
17125 "DW_FORM_line_strp",
17126 ".debug_line_str");
17129 /* Read a string at offset STR_OFFSET in the .debug_str section from
17130 the .dwz file DWZ. Throw an error if the offset is too large. If
17131 the string consists of a single NUL byte, return NULL; otherwise
17132 return a pointer to the string. */
17134 static const char *
17135 read_indirect_string_from_dwz (struct dwz_file
*dwz
, LONGEST str_offset
)
17137 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwz
->str
);
17139 if (dwz
->str
.buffer
== NULL
)
17140 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
17141 "section [in module %s]"),
17142 bfd_get_filename (dwz
->dwz_bfd
));
17143 if (str_offset
>= dwz
->str
.size
)
17144 error (_("DW_FORM_GNU_strp_alt pointing outside of "
17145 ".debug_str section [in module %s]"),
17146 bfd_get_filename (dwz
->dwz_bfd
));
17147 gdb_assert (HOST_CHAR_BIT
== 8);
17148 if (dwz
->str
.buffer
[str_offset
] == '\0')
17150 return (const char *) (dwz
->str
.buffer
+ str_offset
);
17153 /* Return pointer to string at .debug_str offset as read from BUF.
17154 BUF is assumed to be in a compilation unit described by CU_HEADER.
17155 Return *BYTES_READ_PTR count of bytes read from BUF. */
17157 static const char *
17158 read_indirect_string (bfd
*abfd
, const gdb_byte
*buf
,
17159 const struct comp_unit_head
*cu_header
,
17160 unsigned int *bytes_read_ptr
)
17162 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
17164 return read_indirect_string_at_offset (abfd
, str_offset
);
17167 /* Return pointer to string at .debug_line_str offset as read from BUF.
17168 BUF is assumed to be in a compilation unit described by CU_HEADER.
17169 Return *BYTES_READ_PTR count of bytes read from BUF. */
17171 static const char *
17172 read_indirect_line_string (bfd
*abfd
, const gdb_byte
*buf
,
17173 const struct comp_unit_head
*cu_header
,
17174 unsigned int *bytes_read_ptr
)
17176 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
17178 return read_indirect_line_string_at_offset (abfd
, str_offset
);
17182 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
17183 unsigned int *bytes_read_ptr
)
17186 unsigned int num_read
;
17188 unsigned char byte
;
17195 byte
= bfd_get_8 (abfd
, buf
);
17198 result
|= ((ULONGEST
) (byte
& 127) << shift
);
17199 if ((byte
& 128) == 0)
17205 *bytes_read_ptr
= num_read
;
17210 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
17211 unsigned int *bytes_read_ptr
)
17214 int shift
, num_read
;
17215 unsigned char byte
;
17222 byte
= bfd_get_8 (abfd
, buf
);
17225 result
|= ((LONGEST
) (byte
& 127) << shift
);
17227 if ((byte
& 128) == 0)
17232 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
17233 result
|= -(((LONGEST
) 1) << shift
);
17234 *bytes_read_ptr
= num_read
;
17238 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
17239 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
17240 ADDR_SIZE is the size of addresses from the CU header. */
17243 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
17245 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17246 bfd
*abfd
= objfile
->obfd
;
17247 const gdb_byte
*info_ptr
;
17249 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
17250 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
17251 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
17252 objfile_name (objfile
));
17253 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
17254 error (_("DW_FORM_addr_index pointing outside of "
17255 ".debug_addr section [in module %s]"),
17256 objfile_name (objfile
));
17257 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
17258 + addr_base
+ addr_index
* addr_size
);
17259 if (addr_size
== 4)
17260 return bfd_get_32 (abfd
, info_ptr
);
17262 return bfd_get_64 (abfd
, info_ptr
);
17265 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
17268 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
17270 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
17273 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
17276 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
17277 unsigned int *bytes_read
)
17279 bfd
*abfd
= cu
->objfile
->obfd
;
17280 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
17282 return read_addr_index (cu
, addr_index
);
17285 /* Data structure to pass results from dwarf2_read_addr_index_reader
17286 back to dwarf2_read_addr_index. */
17288 struct dwarf2_read_addr_index_data
17290 ULONGEST addr_base
;
17294 /* die_reader_func for dwarf2_read_addr_index. */
17297 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
17298 const gdb_byte
*info_ptr
,
17299 struct die_info
*comp_unit_die
,
17303 struct dwarf2_cu
*cu
= reader
->cu
;
17304 struct dwarf2_read_addr_index_data
*aidata
=
17305 (struct dwarf2_read_addr_index_data
*) data
;
17307 aidata
->addr_base
= cu
->addr_base
;
17308 aidata
->addr_size
= cu
->header
.addr_size
;
17311 /* Given an index in .debug_addr, fetch the value.
17312 NOTE: This can be called during dwarf expression evaluation,
17313 long after the debug information has been read, and thus per_cu->cu
17314 may no longer exist. */
17317 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
17318 unsigned int addr_index
)
17320 struct objfile
*objfile
= per_cu
->objfile
;
17321 struct dwarf2_cu
*cu
= per_cu
->cu
;
17322 ULONGEST addr_base
;
17325 /* This is intended to be called from outside this file. */
17326 dw2_setup (objfile
);
17328 /* We need addr_base and addr_size.
17329 If we don't have PER_CU->cu, we have to get it.
17330 Nasty, but the alternative is storing the needed info in PER_CU,
17331 which at this point doesn't seem justified: it's not clear how frequently
17332 it would get used and it would increase the size of every PER_CU.
17333 Entry points like dwarf2_per_cu_addr_size do a similar thing
17334 so we're not in uncharted territory here.
17335 Alas we need to be a bit more complicated as addr_base is contained
17338 We don't need to read the entire CU(/TU).
17339 We just need the header and top level die.
17341 IWBN to use the aging mechanism to let us lazily later discard the CU.
17342 For now we skip this optimization. */
17346 addr_base
= cu
->addr_base
;
17347 addr_size
= cu
->header
.addr_size
;
17351 struct dwarf2_read_addr_index_data aidata
;
17353 /* Note: We can't use init_cutu_and_read_dies_simple here,
17354 we need addr_base. */
17355 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
17356 dwarf2_read_addr_index_reader
, &aidata
);
17357 addr_base
= aidata
.addr_base
;
17358 addr_size
= aidata
.addr_size
;
17361 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
17364 /* Given a DW_FORM_GNU_str_index, fetch the string.
17365 This is only used by the Fission support. */
17367 static const char *
17368 read_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
17370 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17371 const char *objf_name
= objfile_name (objfile
);
17372 bfd
*abfd
= objfile
->obfd
;
17373 struct dwarf2_cu
*cu
= reader
->cu
;
17374 struct dwarf2_section_info
*str_section
= &reader
->dwo_file
->sections
.str
;
17375 struct dwarf2_section_info
*str_offsets_section
=
17376 &reader
->dwo_file
->sections
.str_offsets
;
17377 const gdb_byte
*info_ptr
;
17378 ULONGEST str_offset
;
17379 static const char form_name
[] = "DW_FORM_GNU_str_index";
17381 dwarf2_read_section (objfile
, str_section
);
17382 dwarf2_read_section (objfile
, str_offsets_section
);
17383 if (str_section
->buffer
== NULL
)
17384 error (_("%s used without .debug_str.dwo section"
17385 " in CU at offset 0x%x [in module %s]"),
17386 form_name
, to_underlying (cu
->header
.sect_off
), objf_name
);
17387 if (str_offsets_section
->buffer
== NULL
)
17388 error (_("%s used without .debug_str_offsets.dwo section"
17389 " in CU at offset 0x%x [in module %s]"),
17390 form_name
, to_underlying (cu
->header
.sect_off
), objf_name
);
17391 if (str_index
* cu
->header
.offset_size
>= str_offsets_section
->size
)
17392 error (_("%s pointing outside of .debug_str_offsets.dwo"
17393 " section in CU at offset 0x%x [in module %s]"),
17394 form_name
, to_underlying (cu
->header
.sect_off
), objf_name
);
17395 info_ptr
= (str_offsets_section
->buffer
17396 + str_index
* cu
->header
.offset_size
);
17397 if (cu
->header
.offset_size
== 4)
17398 str_offset
= bfd_get_32 (abfd
, info_ptr
);
17400 str_offset
= bfd_get_64 (abfd
, info_ptr
);
17401 if (str_offset
>= str_section
->size
)
17402 error (_("Offset from %s pointing outside of"
17403 " .debug_str.dwo section in CU at offset 0x%x [in module %s]"),
17404 form_name
, to_underlying (cu
->header
.sect_off
), objf_name
);
17405 return (const char *) (str_section
->buffer
+ str_offset
);
17408 /* Return the length of an LEB128 number in BUF. */
17411 leb128_size (const gdb_byte
*buf
)
17413 const gdb_byte
*begin
= buf
;
17419 if ((byte
& 128) == 0)
17420 return buf
- begin
;
17425 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
17434 cu
->language
= language_c
;
17437 case DW_LANG_C_plus_plus
:
17438 case DW_LANG_C_plus_plus_11
:
17439 case DW_LANG_C_plus_plus_14
:
17440 cu
->language
= language_cplus
;
17443 cu
->language
= language_d
;
17445 case DW_LANG_Fortran77
:
17446 case DW_LANG_Fortran90
:
17447 case DW_LANG_Fortran95
:
17448 case DW_LANG_Fortran03
:
17449 case DW_LANG_Fortran08
:
17450 cu
->language
= language_fortran
;
17453 cu
->language
= language_go
;
17455 case DW_LANG_Mips_Assembler
:
17456 cu
->language
= language_asm
;
17458 case DW_LANG_Ada83
:
17459 case DW_LANG_Ada95
:
17460 cu
->language
= language_ada
;
17462 case DW_LANG_Modula2
:
17463 cu
->language
= language_m2
;
17465 case DW_LANG_Pascal83
:
17466 cu
->language
= language_pascal
;
17469 cu
->language
= language_objc
;
17472 case DW_LANG_Rust_old
:
17473 cu
->language
= language_rust
;
17475 case DW_LANG_Cobol74
:
17476 case DW_LANG_Cobol85
:
17478 cu
->language
= language_minimal
;
17481 cu
->language_defn
= language_def (cu
->language
);
17484 /* Return the named attribute or NULL if not there. */
17486 static struct attribute
*
17487 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
17492 struct attribute
*spec
= NULL
;
17494 for (i
= 0; i
< die
->num_attrs
; ++i
)
17496 if (die
->attrs
[i
].name
== name
)
17497 return &die
->attrs
[i
];
17498 if (die
->attrs
[i
].name
== DW_AT_specification
17499 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
17500 spec
= &die
->attrs
[i
];
17506 die
= follow_die_ref (die
, spec
, &cu
);
17512 /* Return the named attribute or NULL if not there,
17513 but do not follow DW_AT_specification, etc.
17514 This is for use in contexts where we're reading .debug_types dies.
17515 Following DW_AT_specification, DW_AT_abstract_origin will take us
17516 back up the chain, and we want to go down. */
17518 static struct attribute
*
17519 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
17523 for (i
= 0; i
< die
->num_attrs
; ++i
)
17524 if (die
->attrs
[i
].name
== name
)
17525 return &die
->attrs
[i
];
17530 /* Return the string associated with a string-typed attribute, or NULL if it
17531 is either not found or is of an incorrect type. */
17533 static const char *
17534 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
17536 struct attribute
*attr
;
17537 const char *str
= NULL
;
17539 attr
= dwarf2_attr (die
, name
, cu
);
17543 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
17544 || attr
->form
== DW_FORM_string
|| attr
->form
== DW_FORM_GNU_strp_alt
)
17545 str
= DW_STRING (attr
);
17547 complaint (&symfile_complaints
,
17548 _("string type expected for attribute %s for "
17549 "DIE at 0x%x in module %s"),
17550 dwarf_attr_name (name
), to_underlying (die
->sect_off
),
17551 objfile_name (cu
->objfile
));
17557 /* Return non-zero iff the attribute NAME is defined for the given DIE,
17558 and holds a non-zero value. This function should only be used for
17559 DW_FORM_flag or DW_FORM_flag_present attributes. */
17562 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
17564 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
17566 return (attr
&& DW_UNSND (attr
));
17570 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
17572 /* A DIE is a declaration if it has a DW_AT_declaration attribute
17573 which value is non-zero. However, we have to be careful with
17574 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
17575 (via dwarf2_flag_true_p) follows this attribute. So we may
17576 end up accidently finding a declaration attribute that belongs
17577 to a different DIE referenced by the specification attribute,
17578 even though the given DIE does not have a declaration attribute. */
17579 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
17580 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
17583 /* Return the die giving the specification for DIE, if there is
17584 one. *SPEC_CU is the CU containing DIE on input, and the CU
17585 containing the return value on output. If there is no
17586 specification, but there is an abstract origin, that is
17589 static struct die_info
*
17590 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
17592 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
17595 if (spec_attr
== NULL
)
17596 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
17598 if (spec_attr
== NULL
)
17601 return follow_die_ref (die
, spec_attr
, spec_cu
);
17604 /* Stub for free_line_header to match void * callback types. */
17607 free_line_header_voidp (void *arg
)
17609 struct line_header
*lh
= (struct line_header
*) arg
;
17615 line_header::add_include_dir (const char *include_dir
)
17617 if (dwarf_line_debug
>= 2)
17618 fprintf_unfiltered (gdb_stdlog
, "Adding dir %zu: %s\n",
17619 include_dirs
.size () + 1, include_dir
);
17621 include_dirs
.push_back (include_dir
);
17625 line_header::add_file_name (const char *name
,
17627 unsigned int mod_time
,
17628 unsigned int length
)
17630 if (dwarf_line_debug
>= 2)
17631 fprintf_unfiltered (gdb_stdlog
, "Adding file %u: %s\n",
17632 (unsigned) file_names
.size () + 1, name
);
17634 file_names
.emplace_back (name
, d_index
, mod_time
, length
);
17637 /* A convenience function to find the proper .debug_line section for a CU. */
17639 static struct dwarf2_section_info
*
17640 get_debug_line_section (struct dwarf2_cu
*cu
)
17642 struct dwarf2_section_info
*section
;
17644 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
17646 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
17647 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
17648 else if (cu
->per_cu
->is_dwz
)
17650 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
17652 section
= &dwz
->line
;
17655 section
= &dwarf2_per_objfile
->line
;
17660 /* Read directory or file name entry format, starting with byte of
17661 format count entries, ULEB128 pairs of entry formats, ULEB128 of
17662 entries count and the entries themselves in the described entry
17666 read_formatted_entries (bfd
*abfd
, const gdb_byte
**bufp
,
17667 struct line_header
*lh
,
17668 const struct comp_unit_head
*cu_header
,
17669 void (*callback
) (struct line_header
*lh
,
17672 unsigned int mod_time
,
17673 unsigned int length
))
17675 gdb_byte format_count
, formati
;
17676 ULONGEST data_count
, datai
;
17677 const gdb_byte
*buf
= *bufp
;
17678 const gdb_byte
*format_header_data
;
17680 unsigned int bytes_read
;
17682 format_count
= read_1_byte (abfd
, buf
);
17684 format_header_data
= buf
;
17685 for (formati
= 0; formati
< format_count
; formati
++)
17687 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
17689 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
17693 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
17695 for (datai
= 0; datai
< data_count
; datai
++)
17697 const gdb_byte
*format
= format_header_data
;
17698 struct file_entry fe
;
17700 for (formati
= 0; formati
< format_count
; formati
++)
17702 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
17703 format
+= bytes_read
;
17705 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
17706 format
+= bytes_read
;
17708 gdb::optional
<const char *> string
;
17709 gdb::optional
<unsigned int> uint
;
17713 case DW_FORM_string
:
17714 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
17718 case DW_FORM_line_strp
:
17719 string
.emplace (read_indirect_line_string (abfd
, buf
,
17725 case DW_FORM_data1
:
17726 uint
.emplace (read_1_byte (abfd
, buf
));
17730 case DW_FORM_data2
:
17731 uint
.emplace (read_2_bytes (abfd
, buf
));
17735 case DW_FORM_data4
:
17736 uint
.emplace (read_4_bytes (abfd
, buf
));
17740 case DW_FORM_data8
:
17741 uint
.emplace (read_8_bytes (abfd
, buf
));
17745 case DW_FORM_udata
:
17746 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
17750 case DW_FORM_block
:
17751 /* It is valid only for DW_LNCT_timestamp which is ignored by
17756 switch (content_type
)
17759 if (string
.has_value ())
17762 case DW_LNCT_directory_index
:
17763 if (uint
.has_value ())
17764 fe
.d_index
= (dir_index
) *uint
;
17766 case DW_LNCT_timestamp
:
17767 if (uint
.has_value ())
17768 fe
.mod_time
= *uint
;
17771 if (uint
.has_value ())
17777 complaint (&symfile_complaints
,
17778 _("Unknown format content type %s"),
17779 pulongest (content_type
));
17783 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
17789 /* Read the statement program header starting at OFFSET in
17790 .debug_line, or .debug_line.dwo. Return a pointer
17791 to a struct line_header, allocated using xmalloc.
17792 Returns NULL if there is a problem reading the header, e.g., if it
17793 has a version we don't understand.
17795 NOTE: the strings in the include directory and file name tables of
17796 the returned object point into the dwarf line section buffer,
17797 and must not be freed. */
17799 static line_header_up
17800 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
17802 const gdb_byte
*line_ptr
;
17803 unsigned int bytes_read
, offset_size
;
17805 const char *cur_dir
, *cur_file
;
17806 struct dwarf2_section_info
*section
;
17809 section
= get_debug_line_section (cu
);
17810 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
17811 if (section
->buffer
== NULL
)
17813 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
17814 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
17816 complaint (&symfile_complaints
, _("missing .debug_line section"));
17820 /* We can't do this until we know the section is non-empty.
17821 Only then do we know we have such a section. */
17822 abfd
= get_section_bfd_owner (section
);
17824 /* Make sure that at least there's room for the total_length field.
17825 That could be 12 bytes long, but we're just going to fudge that. */
17826 if (to_underlying (sect_off
) + 4 >= section
->size
)
17828 dwarf2_statement_list_fits_in_line_number_section_complaint ();
17832 line_header_up
lh (new line_header ());
17834 lh
->sect_off
= sect_off
;
17835 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
17837 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
17839 /* Read in the header. */
17841 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
17842 &bytes_read
, &offset_size
);
17843 line_ptr
+= bytes_read
;
17844 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
17846 dwarf2_statement_list_fits_in_line_number_section_complaint ();
17849 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
17850 lh
->version
= read_2_bytes (abfd
, line_ptr
);
17852 if (lh
->version
> 5)
17854 /* This is a version we don't understand. The format could have
17855 changed in ways we don't handle properly so just punt. */
17856 complaint (&symfile_complaints
,
17857 _("unsupported version in .debug_line section"));
17860 if (lh
->version
>= 5)
17862 gdb_byte segment_selector_size
;
17864 /* Skip address size. */
17865 read_1_byte (abfd
, line_ptr
);
17868 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
17870 if (segment_selector_size
!= 0)
17872 complaint (&symfile_complaints
,
17873 _("unsupported segment selector size %u "
17874 "in .debug_line section"),
17875 segment_selector_size
);
17879 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
17880 line_ptr
+= offset_size
;
17881 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
17883 if (lh
->version
>= 4)
17885 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
17889 lh
->maximum_ops_per_instruction
= 1;
17891 if (lh
->maximum_ops_per_instruction
== 0)
17893 lh
->maximum_ops_per_instruction
= 1;
17894 complaint (&symfile_complaints
,
17895 _("invalid maximum_ops_per_instruction "
17896 "in `.debug_line' section"));
17899 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
17901 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
17903 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
17905 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
17907 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
17909 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
17910 for (i
= 1; i
< lh
->opcode_base
; ++i
)
17912 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
17916 if (lh
->version
>= 5)
17918 /* Read directory table. */
17919 read_formatted_entries (abfd
, &line_ptr
, lh
.get (), &cu
->header
,
17920 [] (struct line_header
*lh
, const char *name
,
17921 dir_index d_index
, unsigned int mod_time
,
17922 unsigned int length
)
17924 lh
->add_include_dir (name
);
17927 /* Read file name table. */
17928 read_formatted_entries (abfd
, &line_ptr
, lh
.get (), &cu
->header
,
17929 [] (struct line_header
*lh
, const char *name
,
17930 dir_index d_index
, unsigned int mod_time
,
17931 unsigned int length
)
17933 lh
->add_file_name (name
, d_index
, mod_time
, length
);
17938 /* Read directory table. */
17939 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
17941 line_ptr
+= bytes_read
;
17942 lh
->add_include_dir (cur_dir
);
17944 line_ptr
+= bytes_read
;
17946 /* Read file name table. */
17947 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
17949 unsigned int mod_time
, length
;
17952 line_ptr
+= bytes_read
;
17953 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
17954 line_ptr
+= bytes_read
;
17955 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
17956 line_ptr
+= bytes_read
;
17957 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
17958 line_ptr
+= bytes_read
;
17960 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
17962 line_ptr
+= bytes_read
;
17964 lh
->statement_program_start
= line_ptr
;
17966 if (line_ptr
> (section
->buffer
+ section
->size
))
17967 complaint (&symfile_complaints
,
17968 _("line number info header doesn't "
17969 "fit in `.debug_line' section"));
17974 /* Subroutine of dwarf_decode_lines to simplify it.
17975 Return the file name of the psymtab for included file FILE_INDEX
17976 in line header LH of PST.
17977 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
17978 If space for the result is malloc'd, it will be freed by a cleanup.
17979 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename.
17981 The function creates dangling cleanup registration. */
17983 static const char *
17984 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
17985 const struct partial_symtab
*pst
,
17986 const char *comp_dir
)
17988 const file_entry
&fe
= lh
->file_names
[file_index
];
17989 const char *include_name
= fe
.name
;
17990 const char *include_name_to_compare
= include_name
;
17991 const char *pst_filename
;
17992 char *copied_name
= NULL
;
17995 const char *dir_name
= fe
.include_dir (lh
);
17997 if (!IS_ABSOLUTE_PATH (include_name
)
17998 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
18000 /* Avoid creating a duplicate psymtab for PST.
18001 We do this by comparing INCLUDE_NAME and PST_FILENAME.
18002 Before we do the comparison, however, we need to account
18003 for DIR_NAME and COMP_DIR.
18004 First prepend dir_name (if non-NULL). If we still don't
18005 have an absolute path prepend comp_dir (if non-NULL).
18006 However, the directory we record in the include-file's
18007 psymtab does not contain COMP_DIR (to match the
18008 corresponding symtab(s)).
18013 bash$ gcc -g ./hello.c
18014 include_name = "hello.c"
18016 DW_AT_comp_dir = comp_dir = "/tmp"
18017 DW_AT_name = "./hello.c"
18021 if (dir_name
!= NULL
)
18023 char *tem
= concat (dir_name
, SLASH_STRING
,
18024 include_name
, (char *)NULL
);
18026 make_cleanup (xfree
, tem
);
18027 include_name
= tem
;
18028 include_name_to_compare
= include_name
;
18030 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
18032 char *tem
= concat (comp_dir
, SLASH_STRING
,
18033 include_name
, (char *)NULL
);
18035 make_cleanup (xfree
, tem
);
18036 include_name_to_compare
= tem
;
18040 pst_filename
= pst
->filename
;
18041 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
18043 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
18044 pst_filename
, (char *)NULL
);
18045 pst_filename
= copied_name
;
18048 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
18050 if (copied_name
!= NULL
)
18051 xfree (copied_name
);
18055 return include_name
;
18058 /* State machine to track the state of the line number program. */
18060 class lnp_state_machine
18063 /* Initialize a machine state for the start of a line number
18065 lnp_state_machine (gdbarch
*arch
, line_header
*lh
, bool record_lines_p
);
18067 file_entry
*current_file ()
18069 /* lh->file_names is 0-based, but the file name numbers in the
18070 statement program are 1-based. */
18071 return m_line_header
->file_name_at (m_file
);
18074 /* Record the line in the state machine. END_SEQUENCE is true if
18075 we're processing the end of a sequence. */
18076 void record_line (bool end_sequence
);
18078 /* Check address and if invalid nop-out the rest of the lines in this
18080 void check_line_address (struct dwarf2_cu
*cu
,
18081 const gdb_byte
*line_ptr
,
18082 CORE_ADDR lowpc
, CORE_ADDR address
);
18084 void handle_set_discriminator (unsigned int discriminator
)
18086 m_discriminator
= discriminator
;
18087 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
18090 /* Handle DW_LNE_set_address. */
18091 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
18094 address
+= baseaddr
;
18095 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
18098 /* Handle DW_LNS_advance_pc. */
18099 void handle_advance_pc (CORE_ADDR adjust
);
18101 /* Handle a special opcode. */
18102 void handle_special_opcode (unsigned char op_code
);
18104 /* Handle DW_LNS_advance_line. */
18105 void handle_advance_line (int line_delta
)
18107 advance_line (line_delta
);
18110 /* Handle DW_LNS_set_file. */
18111 void handle_set_file (file_name_index file
);
18113 /* Handle DW_LNS_negate_stmt. */
18114 void handle_negate_stmt ()
18116 m_is_stmt
= !m_is_stmt
;
18119 /* Handle DW_LNS_const_add_pc. */
18120 void handle_const_add_pc ();
18122 /* Handle DW_LNS_fixed_advance_pc. */
18123 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
18125 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
18129 /* Handle DW_LNS_copy. */
18130 void handle_copy ()
18132 record_line (false);
18133 m_discriminator
= 0;
18136 /* Handle DW_LNE_end_sequence. */
18137 void handle_end_sequence ()
18139 m_record_line_callback
= ::record_line
;
18143 /* Advance the line by LINE_DELTA. */
18144 void advance_line (int line_delta
)
18146 m_line
+= line_delta
;
18148 if (line_delta
!= 0)
18149 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
18152 gdbarch
*m_gdbarch
;
18154 /* True if we're recording lines.
18155 Otherwise we're building partial symtabs and are just interested in
18156 finding include files mentioned by the line number program. */
18157 bool m_record_lines_p
;
18159 /* The line number header. */
18160 line_header
*m_line_header
;
18162 /* These are part of the standard DWARF line number state machine,
18163 and initialized according to the DWARF spec. */
18165 unsigned char m_op_index
= 0;
18166 /* The line table index (1-based) of the current file. */
18167 file_name_index m_file
= (file_name_index
) 1;
18168 unsigned int m_line
= 1;
18170 /* These are initialized in the constructor. */
18172 CORE_ADDR m_address
;
18174 unsigned int m_discriminator
;
18176 /* Additional bits of state we need to track. */
18178 /* The last file that we called dwarf2_start_subfile for.
18179 This is only used for TLLs. */
18180 unsigned int m_last_file
= 0;
18181 /* The last file a line number was recorded for. */
18182 struct subfile
*m_last_subfile
= NULL
;
18184 /* The function to call to record a line. */
18185 record_line_ftype
*m_record_line_callback
= NULL
;
18187 /* The last line number that was recorded, used to coalesce
18188 consecutive entries for the same line. This can happen, for
18189 example, when discriminators are present. PR 17276. */
18190 unsigned int m_last_line
= 0;
18191 bool m_line_has_non_zero_discriminator
= false;
18195 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
18197 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
18198 / m_line_header
->maximum_ops_per_instruction
)
18199 * m_line_header
->minimum_instruction_length
);
18200 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
18201 m_op_index
= ((m_op_index
+ adjust
)
18202 % m_line_header
->maximum_ops_per_instruction
);
18206 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
18208 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
18209 CORE_ADDR addr_adj
= (((m_op_index
18210 + (adj_opcode
/ m_line_header
->line_range
))
18211 / m_line_header
->maximum_ops_per_instruction
)
18212 * m_line_header
->minimum_instruction_length
);
18213 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
18214 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
18215 % m_line_header
->maximum_ops_per_instruction
);
18217 int line_delta
= (m_line_header
->line_base
18218 + (adj_opcode
% m_line_header
->line_range
));
18219 advance_line (line_delta
);
18220 record_line (false);
18221 m_discriminator
= 0;
18225 lnp_state_machine::handle_set_file (file_name_index file
)
18229 const file_entry
*fe
= current_file ();
18231 dwarf2_debug_line_missing_file_complaint ();
18232 else if (m_record_lines_p
)
18234 const char *dir
= fe
->include_dir (m_line_header
);
18236 m_last_subfile
= current_subfile
;
18237 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
18238 dwarf2_start_subfile (fe
->name
, dir
);
18243 lnp_state_machine::handle_const_add_pc ()
18246 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
18249 = (((m_op_index
+ adjust
)
18250 / m_line_header
->maximum_ops_per_instruction
)
18251 * m_line_header
->minimum_instruction_length
);
18253 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
18254 m_op_index
= ((m_op_index
+ adjust
)
18255 % m_line_header
->maximum_ops_per_instruction
);
18258 /* Ignore this record_line request. */
18261 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
18266 /* Return non-zero if we should add LINE to the line number table.
18267 LINE is the line to add, LAST_LINE is the last line that was added,
18268 LAST_SUBFILE is the subfile for LAST_LINE.
18269 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
18270 had a non-zero discriminator.
18272 We have to be careful in the presence of discriminators.
18273 E.g., for this line:
18275 for (i = 0; i < 100000; i++);
18277 clang can emit four line number entries for that one line,
18278 each with a different discriminator.
18279 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
18281 However, we want gdb to coalesce all four entries into one.
18282 Otherwise the user could stepi into the middle of the line and
18283 gdb would get confused about whether the pc really was in the
18284 middle of the line.
18286 Things are further complicated by the fact that two consecutive
18287 line number entries for the same line is a heuristic used by gcc
18288 to denote the end of the prologue. So we can't just discard duplicate
18289 entries, we have to be selective about it. The heuristic we use is
18290 that we only collapse consecutive entries for the same line if at least
18291 one of those entries has a non-zero discriminator. PR 17276.
18293 Note: Addresses in the line number state machine can never go backwards
18294 within one sequence, thus this coalescing is ok. */
18297 dwarf_record_line_p (unsigned int line
, unsigned int last_line
,
18298 int line_has_non_zero_discriminator
,
18299 struct subfile
*last_subfile
)
18301 if (current_subfile
!= last_subfile
)
18303 if (line
!= last_line
)
18305 /* Same line for the same file that we've seen already.
18306 As a last check, for pr 17276, only record the line if the line
18307 has never had a non-zero discriminator. */
18308 if (!line_has_non_zero_discriminator
)
18313 /* Use P_RECORD_LINE to record line number LINE beginning at address ADDRESS
18314 in the line table of subfile SUBFILE. */
18317 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
18318 unsigned int line
, CORE_ADDR address
,
18319 record_line_ftype p_record_line
)
18321 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
18323 if (dwarf_line_debug
)
18325 fprintf_unfiltered (gdb_stdlog
,
18326 "Recording line %u, file %s, address %s\n",
18327 line
, lbasename (subfile
->name
),
18328 paddress (gdbarch
, address
));
18331 (*p_record_line
) (subfile
, line
, addr
);
18334 /* Subroutine of dwarf_decode_lines_1 to simplify it.
18335 Mark the end of a set of line number records.
18336 The arguments are the same as for dwarf_record_line_1.
18337 If SUBFILE is NULL the request is ignored. */
18340 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
18341 CORE_ADDR address
, record_line_ftype p_record_line
)
18343 if (subfile
== NULL
)
18346 if (dwarf_line_debug
)
18348 fprintf_unfiltered (gdb_stdlog
,
18349 "Finishing current line, file %s, address %s\n",
18350 lbasename (subfile
->name
),
18351 paddress (gdbarch
, address
));
18354 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, p_record_line
);
18358 lnp_state_machine::record_line (bool end_sequence
)
18360 if (dwarf_line_debug
)
18362 fprintf_unfiltered (gdb_stdlog
,
18363 "Processing actual line %u: file %u,"
18364 " address %s, is_stmt %u, discrim %u\n",
18365 m_line
, to_underlying (m_file
),
18366 paddress (m_gdbarch
, m_address
),
18367 m_is_stmt
, m_discriminator
);
18370 file_entry
*fe
= current_file ();
18373 dwarf2_debug_line_missing_file_complaint ();
18374 /* For now we ignore lines not starting on an instruction boundary.
18375 But not when processing end_sequence for compatibility with the
18376 previous version of the code. */
18377 else if (m_op_index
== 0 || end_sequence
)
18379 fe
->included_p
= 1;
18380 if (m_record_lines_p
&& m_is_stmt
)
18382 if (m_last_subfile
!= current_subfile
|| end_sequence
)
18384 dwarf_finish_line (m_gdbarch
, m_last_subfile
,
18385 m_address
, m_record_line_callback
);
18390 if (dwarf_record_line_p (m_line
, m_last_line
,
18391 m_line_has_non_zero_discriminator
,
18394 dwarf_record_line_1 (m_gdbarch
, current_subfile
,
18396 m_record_line_callback
);
18398 m_last_subfile
= current_subfile
;
18399 m_last_line
= m_line
;
18405 lnp_state_machine::lnp_state_machine (gdbarch
*arch
, line_header
*lh
,
18406 bool record_lines_p
)
18409 m_record_lines_p
= record_lines_p
;
18410 m_line_header
= lh
;
18412 m_record_line_callback
= ::record_line
;
18414 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
18415 was a line entry for it so that the backend has a chance to adjust it
18416 and also record it in case it needs it. This is currently used by MIPS
18417 code, cf. `mips_adjust_dwarf2_line'. */
18418 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
18419 m_is_stmt
= lh
->default_is_stmt
;
18420 m_discriminator
= 0;
18424 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
18425 const gdb_byte
*line_ptr
,
18426 CORE_ADDR lowpc
, CORE_ADDR address
)
18428 /* If address < lowpc then it's not a usable value, it's outside the
18429 pc range of the CU. However, we restrict the test to only address
18430 values of zero to preserve GDB's previous behaviour which is to
18431 handle the specific case of a function being GC'd by the linker. */
18433 if (address
== 0 && address
< lowpc
)
18435 /* This line table is for a function which has been
18436 GCd by the linker. Ignore it. PR gdb/12528 */
18438 struct objfile
*objfile
= cu
->objfile
;
18439 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
18441 complaint (&symfile_complaints
,
18442 _(".debug_line address at offset 0x%lx is 0 [in module %s]"),
18443 line_offset
, objfile_name (objfile
));
18444 m_record_line_callback
= noop_record_line
;
18445 /* Note: record_line_callback is left as noop_record_line until
18446 we see DW_LNE_end_sequence. */
18450 /* Subroutine of dwarf_decode_lines to simplify it.
18451 Process the line number information in LH.
18452 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
18453 program in order to set included_p for every referenced header. */
18456 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
18457 const int decode_for_pst_p
, CORE_ADDR lowpc
)
18459 const gdb_byte
*line_ptr
, *extended_end
;
18460 const gdb_byte
*line_end
;
18461 unsigned int bytes_read
, extended_len
;
18462 unsigned char op_code
, extended_op
;
18463 CORE_ADDR baseaddr
;
18464 struct objfile
*objfile
= cu
->objfile
;
18465 bfd
*abfd
= objfile
->obfd
;
18466 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18467 /* True if we're recording line info (as opposed to building partial
18468 symtabs and just interested in finding include files mentioned by
18469 the line number program). */
18470 bool record_lines_p
= !decode_for_pst_p
;
18472 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
18474 line_ptr
= lh
->statement_program_start
;
18475 line_end
= lh
->statement_program_end
;
18477 /* Read the statement sequences until there's nothing left. */
18478 while (line_ptr
< line_end
)
18480 /* The DWARF line number program state machine. Reset the state
18481 machine at the start of each sequence. */
18482 lnp_state_machine
state_machine (gdbarch
, lh
, record_lines_p
);
18483 bool end_sequence
= false;
18485 if (record_lines_p
)
18487 /* Start a subfile for the current file of the state
18489 const file_entry
*fe
= state_machine
.current_file ();
18492 dwarf2_start_subfile (fe
->name
, fe
->include_dir (lh
));
18495 /* Decode the table. */
18496 while (line_ptr
< line_end
&& !end_sequence
)
18498 op_code
= read_1_byte (abfd
, line_ptr
);
18501 if (op_code
>= lh
->opcode_base
)
18503 /* Special opcode. */
18504 state_machine
.handle_special_opcode (op_code
);
18506 else switch (op_code
)
18508 case DW_LNS_extended_op
:
18509 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
18511 line_ptr
+= bytes_read
;
18512 extended_end
= line_ptr
+ extended_len
;
18513 extended_op
= read_1_byte (abfd
, line_ptr
);
18515 switch (extended_op
)
18517 case DW_LNE_end_sequence
:
18518 state_machine
.handle_end_sequence ();
18519 end_sequence
= true;
18521 case DW_LNE_set_address
:
18524 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
18525 line_ptr
+= bytes_read
;
18527 state_machine
.check_line_address (cu
, line_ptr
,
18529 state_machine
.handle_set_address (baseaddr
, address
);
18532 case DW_LNE_define_file
:
18534 const char *cur_file
;
18535 unsigned int mod_time
, length
;
18538 cur_file
= read_direct_string (abfd
, line_ptr
,
18540 line_ptr
+= bytes_read
;
18541 dindex
= (dir_index
)
18542 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18543 line_ptr
+= bytes_read
;
18545 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18546 line_ptr
+= bytes_read
;
18548 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18549 line_ptr
+= bytes_read
;
18550 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
18553 case DW_LNE_set_discriminator
:
18555 /* The discriminator is not interesting to the
18556 debugger; just ignore it. We still need to
18557 check its value though:
18558 if there are consecutive entries for the same
18559 (non-prologue) line we want to coalesce them.
18562 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18563 line_ptr
+= bytes_read
;
18565 state_machine
.handle_set_discriminator (discr
);
18569 complaint (&symfile_complaints
,
18570 _("mangled .debug_line section"));
18573 /* Make sure that we parsed the extended op correctly. If e.g.
18574 we expected a different address size than the producer used,
18575 we may have read the wrong number of bytes. */
18576 if (line_ptr
!= extended_end
)
18578 complaint (&symfile_complaints
,
18579 _("mangled .debug_line section"));
18584 state_machine
.handle_copy ();
18586 case DW_LNS_advance_pc
:
18589 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18590 line_ptr
+= bytes_read
;
18592 state_machine
.handle_advance_pc (adjust
);
18595 case DW_LNS_advance_line
:
18598 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
18599 line_ptr
+= bytes_read
;
18601 state_machine
.handle_advance_line (line_delta
);
18604 case DW_LNS_set_file
:
18606 file_name_index file
18607 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
18609 line_ptr
+= bytes_read
;
18611 state_machine
.handle_set_file (file
);
18614 case DW_LNS_set_column
:
18615 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18616 line_ptr
+= bytes_read
;
18618 case DW_LNS_negate_stmt
:
18619 state_machine
.handle_negate_stmt ();
18621 case DW_LNS_set_basic_block
:
18623 /* Add to the address register of the state machine the
18624 address increment value corresponding to special opcode
18625 255. I.e., this value is scaled by the minimum
18626 instruction length since special opcode 255 would have
18627 scaled the increment. */
18628 case DW_LNS_const_add_pc
:
18629 state_machine
.handle_const_add_pc ();
18631 case DW_LNS_fixed_advance_pc
:
18633 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
18636 state_machine
.handle_fixed_advance_pc (addr_adj
);
18641 /* Unknown standard opcode, ignore it. */
18644 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
18646 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18647 line_ptr
+= bytes_read
;
18654 dwarf2_debug_line_missing_end_sequence_complaint ();
18656 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
18657 in which case we still finish recording the last line). */
18658 state_machine
.record_line (true);
18662 /* Decode the Line Number Program (LNP) for the given line_header
18663 structure and CU. The actual information extracted and the type
18664 of structures created from the LNP depends on the value of PST.
18666 1. If PST is NULL, then this procedure uses the data from the program
18667 to create all necessary symbol tables, and their linetables.
18669 2. If PST is not NULL, this procedure reads the program to determine
18670 the list of files included by the unit represented by PST, and
18671 builds all the associated partial symbol tables.
18673 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
18674 It is used for relative paths in the line table.
18675 NOTE: When processing partial symtabs (pst != NULL),
18676 comp_dir == pst->dirname.
18678 NOTE: It is important that psymtabs have the same file name (via strcmp)
18679 as the corresponding symtab. Since COMP_DIR is not used in the name of the
18680 symtab we don't use it in the name of the psymtabs we create.
18681 E.g. expand_line_sal requires this when finding psymtabs to expand.
18682 A good testcase for this is mb-inline.exp.
18684 LOWPC is the lowest address in CU (or 0 if not known).
18686 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
18687 for its PC<->lines mapping information. Otherwise only the filename
18688 table is read in. */
18691 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
18692 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
18693 CORE_ADDR lowpc
, int decode_mapping
)
18695 struct objfile
*objfile
= cu
->objfile
;
18696 const int decode_for_pst_p
= (pst
!= NULL
);
18698 if (decode_mapping
)
18699 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
18701 if (decode_for_pst_p
)
18705 /* Now that we're done scanning the Line Header Program, we can
18706 create the psymtab of each included file. */
18707 for (file_index
= 0; file_index
< lh
->file_names
.size (); file_index
++)
18708 if (lh
->file_names
[file_index
].included_p
== 1)
18710 const char *include_name
=
18711 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
18712 if (include_name
!= NULL
)
18713 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
18718 /* Make sure a symtab is created for every file, even files
18719 which contain only variables (i.e. no code with associated
18721 struct compunit_symtab
*cust
= buildsym_compunit_symtab ();
18724 for (i
= 0; i
< lh
->file_names
.size (); i
++)
18726 file_entry
&fe
= lh
->file_names
[i
];
18728 dwarf2_start_subfile (fe
.name
, fe
.include_dir (lh
));
18730 if (current_subfile
->symtab
== NULL
)
18732 current_subfile
->symtab
18733 = allocate_symtab (cust
, current_subfile
->name
);
18735 fe
.symtab
= current_subfile
->symtab
;
18740 /* Start a subfile for DWARF. FILENAME is the name of the file and
18741 DIRNAME the name of the source directory which contains FILENAME
18742 or NULL if not known.
18743 This routine tries to keep line numbers from identical absolute and
18744 relative file names in a common subfile.
18746 Using the `list' example from the GDB testsuite, which resides in
18747 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
18748 of /srcdir/list0.c yields the following debugging information for list0.c:
18750 DW_AT_name: /srcdir/list0.c
18751 DW_AT_comp_dir: /compdir
18752 files.files[0].name: list0.h
18753 files.files[0].dir: /srcdir
18754 files.files[1].name: list0.c
18755 files.files[1].dir: /srcdir
18757 The line number information for list0.c has to end up in a single
18758 subfile, so that `break /srcdir/list0.c:1' works as expected.
18759 start_subfile will ensure that this happens provided that we pass the
18760 concatenation of files.files[1].dir and files.files[1].name as the
18764 dwarf2_start_subfile (const char *filename
, const char *dirname
)
18768 /* In order not to lose the line information directory,
18769 we concatenate it to the filename when it makes sense.
18770 Note that the Dwarf3 standard says (speaking of filenames in line
18771 information): ``The directory index is ignored for file names
18772 that represent full path names''. Thus ignoring dirname in the
18773 `else' branch below isn't an issue. */
18775 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
18777 copy
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
18781 start_subfile (filename
);
18787 /* Start a symtab for DWARF.
18788 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
18790 static struct compunit_symtab
*
18791 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
18792 const char *name
, const char *comp_dir
, CORE_ADDR low_pc
)
18794 struct compunit_symtab
*cust
18795 = start_symtab (cu
->objfile
, name
, comp_dir
, low_pc
);
18797 record_debugformat ("DWARF 2");
18798 record_producer (cu
->producer
);
18800 /* We assume that we're processing GCC output. */
18801 processing_gcc_compilation
= 2;
18803 cu
->processing_has_namespace_info
= 0;
18809 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
18810 struct dwarf2_cu
*cu
)
18812 struct objfile
*objfile
= cu
->objfile
;
18813 struct comp_unit_head
*cu_header
= &cu
->header
;
18815 /* NOTE drow/2003-01-30: There used to be a comment and some special
18816 code here to turn a symbol with DW_AT_external and a
18817 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
18818 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
18819 with some versions of binutils) where shared libraries could have
18820 relocations against symbols in their debug information - the
18821 minimal symbol would have the right address, but the debug info
18822 would not. It's no longer necessary, because we will explicitly
18823 apply relocations when we read in the debug information now. */
18825 /* A DW_AT_location attribute with no contents indicates that a
18826 variable has been optimized away. */
18827 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
18829 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
18833 /* Handle one degenerate form of location expression specially, to
18834 preserve GDB's previous behavior when section offsets are
18835 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
18836 then mark this symbol as LOC_STATIC. */
18838 if (attr_form_is_block (attr
)
18839 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
18840 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
18841 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
18842 && (DW_BLOCK (attr
)->size
18843 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
18845 unsigned int dummy
;
18847 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
18848 SYMBOL_VALUE_ADDRESS (sym
) =
18849 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
18851 SYMBOL_VALUE_ADDRESS (sym
) =
18852 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
18853 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
18854 fixup_symbol_section (sym
, objfile
);
18855 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
18856 SYMBOL_SECTION (sym
));
18860 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
18861 expression evaluator, and use LOC_COMPUTED only when necessary
18862 (i.e. when the value of a register or memory location is
18863 referenced, or a thread-local block, etc.). Then again, it might
18864 not be worthwhile. I'm assuming that it isn't unless performance
18865 or memory numbers show me otherwise. */
18867 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
18869 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
18870 cu
->has_loclist
= 1;
18873 /* Given a pointer to a DWARF information entry, figure out if we need
18874 to make a symbol table entry for it, and if so, create a new entry
18875 and return a pointer to it.
18876 If TYPE is NULL, determine symbol type from the die, otherwise
18877 used the passed type.
18878 If SPACE is not NULL, use it to hold the new symbol. If it is
18879 NULL, allocate a new symbol on the objfile's obstack. */
18881 static struct symbol
*
18882 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
18883 struct symbol
*space
)
18885 struct objfile
*objfile
= cu
->objfile
;
18886 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18887 struct symbol
*sym
= NULL
;
18889 struct attribute
*attr
= NULL
;
18890 struct attribute
*attr2
= NULL
;
18891 CORE_ADDR baseaddr
;
18892 struct pending
**list_to_add
= NULL
;
18894 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
18896 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
18898 name
= dwarf2_name (die
, cu
);
18901 const char *linkagename
;
18902 int suppress_add
= 0;
18907 sym
= allocate_symbol (objfile
);
18908 OBJSTAT (objfile
, n_syms
++);
18910 /* Cache this symbol's name and the name's demangled form (if any). */
18911 SYMBOL_SET_LANGUAGE (sym
, cu
->language
, &objfile
->objfile_obstack
);
18912 linkagename
= dwarf2_physname (name
, die
, cu
);
18913 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
18915 /* Fortran does not have mangling standard and the mangling does differ
18916 between gfortran, iFort etc. */
18917 if (cu
->language
== language_fortran
18918 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
18919 symbol_set_demangled_name (&(sym
->ginfo
),
18920 dwarf2_full_name (name
, die
, cu
),
18923 /* Default assumptions.
18924 Use the passed type or decode it from the die. */
18925 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
18926 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
18928 SYMBOL_TYPE (sym
) = type
;
18930 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
18931 attr
= dwarf2_attr (die
,
18932 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
18936 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
18939 attr
= dwarf2_attr (die
,
18940 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
18944 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
18945 struct file_entry
*fe
;
18947 if (cu
->line_header
!= NULL
)
18948 fe
= cu
->line_header
->file_name_at (file_index
);
18953 complaint (&symfile_complaints
,
18954 _("file index out of range"));
18956 symbol_set_symtab (sym
, fe
->symtab
);
18962 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
18967 addr
= attr_value_as_address (attr
);
18968 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
18969 SYMBOL_VALUE_ADDRESS (sym
) = addr
;
18971 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
18972 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
18973 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
18974 add_symbol_to_list (sym
, cu
->list_in_scope
);
18976 case DW_TAG_subprogram
:
18977 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
18979 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
18980 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
18981 if ((attr2
&& (DW_UNSND (attr2
) != 0))
18982 || cu
->language
== language_ada
)
18984 /* Subprograms marked external are stored as a global symbol.
18985 Ada subprograms, whether marked external or not, are always
18986 stored as a global symbol, because we want to be able to
18987 access them globally. For instance, we want to be able
18988 to break on a nested subprogram without having to
18989 specify the context. */
18990 list_to_add
= &global_symbols
;
18994 list_to_add
= cu
->list_in_scope
;
18997 case DW_TAG_inlined_subroutine
:
18998 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
19000 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
19001 SYMBOL_INLINED (sym
) = 1;
19002 list_to_add
= cu
->list_in_scope
;
19004 case DW_TAG_template_value_param
:
19006 /* Fall through. */
19007 case DW_TAG_constant
:
19008 case DW_TAG_variable
:
19009 case DW_TAG_member
:
19010 /* Compilation with minimal debug info may result in
19011 variables with missing type entries. Change the
19012 misleading `void' type to something sensible. */
19013 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
19015 = objfile_type (objfile
)->nodebug_data_symbol
;
19017 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
19018 /* In the case of DW_TAG_member, we should only be called for
19019 static const members. */
19020 if (die
->tag
== DW_TAG_member
)
19022 /* dwarf2_add_field uses die_is_declaration,
19023 so we do the same. */
19024 gdb_assert (die_is_declaration (die
, cu
));
19029 dwarf2_const_value (attr
, sym
, cu
);
19030 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
19033 if (attr2
&& (DW_UNSND (attr2
) != 0))
19034 list_to_add
= &global_symbols
;
19036 list_to_add
= cu
->list_in_scope
;
19040 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
19043 var_decode_location (attr
, sym
, cu
);
19044 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
19046 /* Fortran explicitly imports any global symbols to the local
19047 scope by DW_TAG_common_block. */
19048 if (cu
->language
== language_fortran
&& die
->parent
19049 && die
->parent
->tag
== DW_TAG_common_block
)
19052 if (SYMBOL_CLASS (sym
) == LOC_STATIC
19053 && SYMBOL_VALUE_ADDRESS (sym
) == 0
19054 && !dwarf2_per_objfile
->has_section_at_zero
)
19056 /* When a static variable is eliminated by the linker,
19057 the corresponding debug information is not stripped
19058 out, but the variable address is set to null;
19059 do not add such variables into symbol table. */
19061 else if (attr2
&& (DW_UNSND (attr2
) != 0))
19063 /* Workaround gfortran PR debug/40040 - it uses
19064 DW_AT_location for variables in -fPIC libraries which may
19065 get overriden by other libraries/executable and get
19066 a different address. Resolve it by the minimal symbol
19067 which may come from inferior's executable using copy
19068 relocation. Make this workaround only for gfortran as for
19069 other compilers GDB cannot guess the minimal symbol
19070 Fortran mangling kind. */
19071 if (cu
->language
== language_fortran
&& die
->parent
19072 && die
->parent
->tag
== DW_TAG_module
19074 && startswith (cu
->producer
, "GNU Fortran"))
19075 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
19077 /* A variable with DW_AT_external is never static,
19078 but it may be block-scoped. */
19079 list_to_add
= (cu
->list_in_scope
== &file_symbols
19080 ? &global_symbols
: cu
->list_in_scope
);
19083 list_to_add
= cu
->list_in_scope
;
19087 /* We do not know the address of this symbol.
19088 If it is an external symbol and we have type information
19089 for it, enter the symbol as a LOC_UNRESOLVED symbol.
19090 The address of the variable will then be determined from
19091 the minimal symbol table whenever the variable is
19093 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
19095 /* Fortran explicitly imports any global symbols to the local
19096 scope by DW_TAG_common_block. */
19097 if (cu
->language
== language_fortran
&& die
->parent
19098 && die
->parent
->tag
== DW_TAG_common_block
)
19100 /* SYMBOL_CLASS doesn't matter here because
19101 read_common_block is going to reset it. */
19103 list_to_add
= cu
->list_in_scope
;
19105 else if (attr2
&& (DW_UNSND (attr2
) != 0)
19106 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
19108 /* A variable with DW_AT_external is never static, but it
19109 may be block-scoped. */
19110 list_to_add
= (cu
->list_in_scope
== &file_symbols
19111 ? &global_symbols
: cu
->list_in_scope
);
19113 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
19115 else if (!die_is_declaration (die
, cu
))
19117 /* Use the default LOC_OPTIMIZED_OUT class. */
19118 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
19120 list_to_add
= cu
->list_in_scope
;
19124 case DW_TAG_formal_parameter
:
19125 /* If we are inside a function, mark this as an argument. If
19126 not, we might be looking at an argument to an inlined function
19127 when we do not have enough information to show inlined frames;
19128 pretend it's a local variable in that case so that the user can
19130 if (context_stack_depth
> 0
19131 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
19132 SYMBOL_IS_ARGUMENT (sym
) = 1;
19133 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
19136 var_decode_location (attr
, sym
, cu
);
19138 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
19141 dwarf2_const_value (attr
, sym
, cu
);
19144 list_to_add
= cu
->list_in_scope
;
19146 case DW_TAG_unspecified_parameters
:
19147 /* From varargs functions; gdb doesn't seem to have any
19148 interest in this information, so just ignore it for now.
19151 case DW_TAG_template_type_param
:
19153 /* Fall through. */
19154 case DW_TAG_class_type
:
19155 case DW_TAG_interface_type
:
19156 case DW_TAG_structure_type
:
19157 case DW_TAG_union_type
:
19158 case DW_TAG_set_type
:
19159 case DW_TAG_enumeration_type
:
19160 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
19161 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
19164 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
19165 really ever be static objects: otherwise, if you try
19166 to, say, break of a class's method and you're in a file
19167 which doesn't mention that class, it won't work unless
19168 the check for all static symbols in lookup_symbol_aux
19169 saves you. See the OtherFileClass tests in
19170 gdb.c++/namespace.exp. */
19174 list_to_add
= (cu
->list_in_scope
== &file_symbols
19175 && cu
->language
== language_cplus
19176 ? &global_symbols
: cu
->list_in_scope
);
19178 /* The semantics of C++ state that "struct foo {
19179 ... }" also defines a typedef for "foo". */
19180 if (cu
->language
== language_cplus
19181 || cu
->language
== language_ada
19182 || cu
->language
== language_d
19183 || cu
->language
== language_rust
)
19185 /* The symbol's name is already allocated along
19186 with this objfile, so we don't need to
19187 duplicate it for the type. */
19188 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
19189 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
19194 case DW_TAG_typedef
:
19195 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
19196 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
19197 list_to_add
= cu
->list_in_scope
;
19199 case DW_TAG_base_type
:
19200 case DW_TAG_subrange_type
:
19201 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
19202 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
19203 list_to_add
= cu
->list_in_scope
;
19205 case DW_TAG_enumerator
:
19206 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
19209 dwarf2_const_value (attr
, sym
, cu
);
19212 /* NOTE: carlton/2003-11-10: See comment above in the
19213 DW_TAG_class_type, etc. block. */
19215 list_to_add
= (cu
->list_in_scope
== &file_symbols
19216 && cu
->language
== language_cplus
19217 ? &global_symbols
: cu
->list_in_scope
);
19220 case DW_TAG_imported_declaration
:
19221 case DW_TAG_namespace
:
19222 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
19223 list_to_add
= &global_symbols
;
19225 case DW_TAG_module
:
19226 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
19227 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
19228 list_to_add
= &global_symbols
;
19230 case DW_TAG_common_block
:
19231 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
19232 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
19233 add_symbol_to_list (sym
, cu
->list_in_scope
);
19236 /* Not a tag we recognize. Hopefully we aren't processing
19237 trash data, but since we must specifically ignore things
19238 we don't recognize, there is nothing else we should do at
19240 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
19241 dwarf_tag_name (die
->tag
));
19247 sym
->hash_next
= objfile
->template_symbols
;
19248 objfile
->template_symbols
= sym
;
19249 list_to_add
= NULL
;
19252 if (list_to_add
!= NULL
)
19253 add_symbol_to_list (sym
, list_to_add
);
19255 /* For the benefit of old versions of GCC, check for anonymous
19256 namespaces based on the demangled name. */
19257 if (!cu
->processing_has_namespace_info
19258 && cu
->language
== language_cplus
)
19259 cp_scan_for_anonymous_namespaces (sym
, objfile
);
19264 /* A wrapper for new_symbol_full that always allocates a new symbol. */
19266 static struct symbol
*
19267 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
19269 return new_symbol_full (die
, type
, cu
, NULL
);
19272 /* Given an attr with a DW_FORM_dataN value in host byte order,
19273 zero-extend it as appropriate for the symbol's type. The DWARF
19274 standard (v4) is not entirely clear about the meaning of using
19275 DW_FORM_dataN for a constant with a signed type, where the type is
19276 wider than the data. The conclusion of a discussion on the DWARF
19277 list was that this is unspecified. We choose to always zero-extend
19278 because that is the interpretation long in use by GCC. */
19281 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
19282 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
19284 struct objfile
*objfile
= cu
->objfile
;
19285 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
19286 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
19287 LONGEST l
= DW_UNSND (attr
);
19289 if (bits
< sizeof (*value
) * 8)
19291 l
&= ((LONGEST
) 1 << bits
) - 1;
19294 else if (bits
== sizeof (*value
) * 8)
19298 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
19299 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
19306 /* Read a constant value from an attribute. Either set *VALUE, or if
19307 the value does not fit in *VALUE, set *BYTES - either already
19308 allocated on the objfile obstack, or newly allocated on OBSTACK,
19309 or, set *BATON, if we translated the constant to a location
19313 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
19314 const char *name
, struct obstack
*obstack
,
19315 struct dwarf2_cu
*cu
,
19316 LONGEST
*value
, const gdb_byte
**bytes
,
19317 struct dwarf2_locexpr_baton
**baton
)
19319 struct objfile
*objfile
= cu
->objfile
;
19320 struct comp_unit_head
*cu_header
= &cu
->header
;
19321 struct dwarf_block
*blk
;
19322 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
19323 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
19329 switch (attr
->form
)
19332 case DW_FORM_GNU_addr_index
:
19336 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
19337 dwarf2_const_value_length_mismatch_complaint (name
,
19338 cu_header
->addr_size
,
19339 TYPE_LENGTH (type
));
19340 /* Symbols of this form are reasonably rare, so we just
19341 piggyback on the existing location code rather than writing
19342 a new implementation of symbol_computed_ops. */
19343 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
19344 (*baton
)->per_cu
= cu
->per_cu
;
19345 gdb_assert ((*baton
)->per_cu
);
19347 (*baton
)->size
= 2 + cu_header
->addr_size
;
19348 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
19349 (*baton
)->data
= data
;
19351 data
[0] = DW_OP_addr
;
19352 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
19353 byte_order
, DW_ADDR (attr
));
19354 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
19357 case DW_FORM_string
:
19359 case DW_FORM_GNU_str_index
:
19360 case DW_FORM_GNU_strp_alt
:
19361 /* DW_STRING is already allocated on the objfile obstack, point
19363 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
19365 case DW_FORM_block1
:
19366 case DW_FORM_block2
:
19367 case DW_FORM_block4
:
19368 case DW_FORM_block
:
19369 case DW_FORM_exprloc
:
19370 case DW_FORM_data16
:
19371 blk
= DW_BLOCK (attr
);
19372 if (TYPE_LENGTH (type
) != blk
->size
)
19373 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
19374 TYPE_LENGTH (type
));
19375 *bytes
= blk
->data
;
19378 /* The DW_AT_const_value attributes are supposed to carry the
19379 symbol's value "represented as it would be on the target
19380 architecture." By the time we get here, it's already been
19381 converted to host endianness, so we just need to sign- or
19382 zero-extend it as appropriate. */
19383 case DW_FORM_data1
:
19384 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
19386 case DW_FORM_data2
:
19387 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
19389 case DW_FORM_data4
:
19390 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
19392 case DW_FORM_data8
:
19393 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
19396 case DW_FORM_sdata
:
19397 *value
= DW_SND (attr
);
19400 case DW_FORM_udata
:
19401 *value
= DW_UNSND (attr
);
19405 complaint (&symfile_complaints
,
19406 _("unsupported const value attribute form: '%s'"),
19407 dwarf_form_name (attr
->form
));
19414 /* Copy constant value from an attribute to a symbol. */
19417 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
19418 struct dwarf2_cu
*cu
)
19420 struct objfile
*objfile
= cu
->objfile
;
19422 const gdb_byte
*bytes
;
19423 struct dwarf2_locexpr_baton
*baton
;
19425 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
19426 SYMBOL_PRINT_NAME (sym
),
19427 &objfile
->objfile_obstack
, cu
,
19428 &value
, &bytes
, &baton
);
19432 SYMBOL_LOCATION_BATON (sym
) = baton
;
19433 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
19435 else if (bytes
!= NULL
)
19437 SYMBOL_VALUE_BYTES (sym
) = bytes
;
19438 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
19442 SYMBOL_VALUE (sym
) = value
;
19443 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
19447 /* Return the type of the die in question using its DW_AT_type attribute. */
19449 static struct type
*
19450 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19452 struct attribute
*type_attr
;
19454 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
19457 /* A missing DW_AT_type represents a void type. */
19458 return objfile_type (cu
->objfile
)->builtin_void
;
19461 return lookup_die_type (die
, type_attr
, cu
);
19464 /* True iff CU's producer generates GNAT Ada auxiliary information
19465 that allows to find parallel types through that information instead
19466 of having to do expensive parallel lookups by type name. */
19469 need_gnat_info (struct dwarf2_cu
*cu
)
19471 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
19472 of GNAT produces this auxiliary information, without any indication
19473 that it is produced. Part of enhancing the FSF version of GNAT
19474 to produce that information will be to put in place an indicator
19475 that we can use in order to determine whether the descriptive type
19476 info is available or not. One suggestion that has been made is
19477 to use a new attribute, attached to the CU die. For now, assume
19478 that the descriptive type info is not available. */
19482 /* Return the auxiliary type of the die in question using its
19483 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
19484 attribute is not present. */
19486 static struct type
*
19487 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19489 struct attribute
*type_attr
;
19491 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
19495 return lookup_die_type (die
, type_attr
, cu
);
19498 /* If DIE has a descriptive_type attribute, then set the TYPE's
19499 descriptive type accordingly. */
19502 set_descriptive_type (struct type
*type
, struct die_info
*die
,
19503 struct dwarf2_cu
*cu
)
19505 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
19507 if (descriptive_type
)
19509 ALLOCATE_GNAT_AUX_TYPE (type
);
19510 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
19514 /* Return the containing type of the die in question using its
19515 DW_AT_containing_type attribute. */
19517 static struct type
*
19518 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19520 struct attribute
*type_attr
;
19522 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
19524 error (_("Dwarf Error: Problem turning containing type into gdb type "
19525 "[in module %s]"), objfile_name (cu
->objfile
));
19527 return lookup_die_type (die
, type_attr
, cu
);
19530 /* Return an error marker type to use for the ill formed type in DIE/CU. */
19532 static struct type
*
19533 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
19535 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19536 char *message
, *saved
;
19538 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
19539 objfile_name (objfile
),
19540 to_underlying (cu
->header
.sect_off
),
19541 to_underlying (die
->sect_off
));
19542 saved
= (char *) obstack_copy0 (&objfile
->objfile_obstack
,
19543 message
, strlen (message
));
19546 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
19549 /* Look up the type of DIE in CU using its type attribute ATTR.
19550 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
19551 DW_AT_containing_type.
19552 If there is no type substitute an error marker. */
19554 static struct type
*
19555 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
19556 struct dwarf2_cu
*cu
)
19558 struct objfile
*objfile
= cu
->objfile
;
19559 struct type
*this_type
;
19561 gdb_assert (attr
->name
== DW_AT_type
19562 || attr
->name
== DW_AT_GNAT_descriptive_type
19563 || attr
->name
== DW_AT_containing_type
);
19565 /* First see if we have it cached. */
19567 if (attr
->form
== DW_FORM_GNU_ref_alt
)
19569 struct dwarf2_per_cu_data
*per_cu
;
19570 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
19572 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1, cu
->objfile
);
19573 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
19575 else if (attr_form_is_ref (attr
))
19577 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
19579 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
19581 else if (attr
->form
== DW_FORM_ref_sig8
)
19583 ULONGEST signature
= DW_SIGNATURE (attr
);
19585 return get_signatured_type (die
, signature
, cu
);
19589 complaint (&symfile_complaints
,
19590 _("Dwarf Error: Bad type attribute %s in DIE"
19591 " at 0x%x [in module %s]"),
19592 dwarf_attr_name (attr
->name
), to_underlying (die
->sect_off
),
19593 objfile_name (objfile
));
19594 return build_error_marker_type (cu
, die
);
19597 /* If not cached we need to read it in. */
19599 if (this_type
== NULL
)
19601 struct die_info
*type_die
= NULL
;
19602 struct dwarf2_cu
*type_cu
= cu
;
19604 if (attr_form_is_ref (attr
))
19605 type_die
= follow_die_ref (die
, attr
, &type_cu
);
19606 if (type_die
== NULL
)
19607 return build_error_marker_type (cu
, die
);
19608 /* If we find the type now, it's probably because the type came
19609 from an inter-CU reference and the type's CU got expanded before
19611 this_type
= read_type_die (type_die
, type_cu
);
19614 /* If we still don't have a type use an error marker. */
19616 if (this_type
== NULL
)
19617 return build_error_marker_type (cu
, die
);
19622 /* Return the type in DIE, CU.
19623 Returns NULL for invalid types.
19625 This first does a lookup in die_type_hash,
19626 and only reads the die in if necessary.
19628 NOTE: This can be called when reading in partial or full symbols. */
19630 static struct type
*
19631 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
19633 struct type
*this_type
;
19635 this_type
= get_die_type (die
, cu
);
19639 return read_type_die_1 (die
, cu
);
19642 /* Read the type in DIE, CU.
19643 Returns NULL for invalid types. */
19645 static struct type
*
19646 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
19648 struct type
*this_type
= NULL
;
19652 case DW_TAG_class_type
:
19653 case DW_TAG_interface_type
:
19654 case DW_TAG_structure_type
:
19655 case DW_TAG_union_type
:
19656 this_type
= read_structure_type (die
, cu
);
19658 case DW_TAG_enumeration_type
:
19659 this_type
= read_enumeration_type (die
, cu
);
19661 case DW_TAG_subprogram
:
19662 case DW_TAG_subroutine_type
:
19663 case DW_TAG_inlined_subroutine
:
19664 this_type
= read_subroutine_type (die
, cu
);
19666 case DW_TAG_array_type
:
19667 this_type
= read_array_type (die
, cu
);
19669 case DW_TAG_set_type
:
19670 this_type
= read_set_type (die
, cu
);
19672 case DW_TAG_pointer_type
:
19673 this_type
= read_tag_pointer_type (die
, cu
);
19675 case DW_TAG_ptr_to_member_type
:
19676 this_type
= read_tag_ptr_to_member_type (die
, cu
);
19678 case DW_TAG_reference_type
:
19679 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
19681 case DW_TAG_rvalue_reference_type
:
19682 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
19684 case DW_TAG_const_type
:
19685 this_type
= read_tag_const_type (die
, cu
);
19687 case DW_TAG_volatile_type
:
19688 this_type
= read_tag_volatile_type (die
, cu
);
19690 case DW_TAG_restrict_type
:
19691 this_type
= read_tag_restrict_type (die
, cu
);
19693 case DW_TAG_string_type
:
19694 this_type
= read_tag_string_type (die
, cu
);
19696 case DW_TAG_typedef
:
19697 this_type
= read_typedef (die
, cu
);
19699 case DW_TAG_subrange_type
:
19700 this_type
= read_subrange_type (die
, cu
);
19702 case DW_TAG_base_type
:
19703 this_type
= read_base_type (die
, cu
);
19705 case DW_TAG_unspecified_type
:
19706 this_type
= read_unspecified_type (die
, cu
);
19708 case DW_TAG_namespace
:
19709 this_type
= read_namespace_type (die
, cu
);
19711 case DW_TAG_module
:
19712 this_type
= read_module_type (die
, cu
);
19714 case DW_TAG_atomic_type
:
19715 this_type
= read_tag_atomic_type (die
, cu
);
19718 complaint (&symfile_complaints
,
19719 _("unexpected tag in read_type_die: '%s'"),
19720 dwarf_tag_name (die
->tag
));
19727 /* See if we can figure out if the class lives in a namespace. We do
19728 this by looking for a member function; its demangled name will
19729 contain namespace info, if there is any.
19730 Return the computed name or NULL.
19731 Space for the result is allocated on the objfile's obstack.
19732 This is the full-die version of guess_partial_die_structure_name.
19733 In this case we know DIE has no useful parent. */
19736 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19738 struct die_info
*spec_die
;
19739 struct dwarf2_cu
*spec_cu
;
19740 struct die_info
*child
;
19743 spec_die
= die_specification (die
, &spec_cu
);
19744 if (spec_die
!= NULL
)
19750 for (child
= die
->child
;
19752 child
= child
->sibling
)
19754 if (child
->tag
== DW_TAG_subprogram
)
19756 const char *linkage_name
;
19758 linkage_name
= dwarf2_string_attr (child
, DW_AT_linkage_name
, cu
);
19759 if (linkage_name
== NULL
)
19760 linkage_name
= dwarf2_string_attr (child
, DW_AT_MIPS_linkage_name
,
19762 if (linkage_name
!= NULL
)
19765 = language_class_name_from_physname (cu
->language_defn
,
19769 if (actual_name
!= NULL
)
19771 const char *die_name
= dwarf2_name (die
, cu
);
19773 if (die_name
!= NULL
19774 && strcmp (die_name
, actual_name
) != 0)
19776 /* Strip off the class name from the full name.
19777 We want the prefix. */
19778 int die_name_len
= strlen (die_name
);
19779 int actual_name_len
= strlen (actual_name
);
19781 /* Test for '::' as a sanity check. */
19782 if (actual_name_len
> die_name_len
+ 2
19783 && actual_name
[actual_name_len
19784 - die_name_len
- 1] == ':')
19785 name
= (char *) obstack_copy0 (
19786 &cu
->objfile
->per_bfd
->storage_obstack
,
19787 actual_name
, actual_name_len
- die_name_len
- 2);
19790 xfree (actual_name
);
19799 /* GCC might emit a nameless typedef that has a linkage name. Determine the
19800 prefix part in such case. See
19801 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19804 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
19806 struct attribute
*attr
;
19809 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
19810 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
19813 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
19816 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
19818 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
19819 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
19822 /* dwarf2_name had to be already called. */
19823 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
19825 /* Strip the base name, keep any leading namespaces/classes. */
19826 base
= strrchr (DW_STRING (attr
), ':');
19827 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
19830 return (char *) obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
19832 &base
[-1] - DW_STRING (attr
));
19835 /* Return the name of the namespace/class that DIE is defined within,
19836 or "" if we can't tell. The caller should not xfree the result.
19838 For example, if we're within the method foo() in the following
19848 then determine_prefix on foo's die will return "N::C". */
19850 static const char *
19851 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
19853 struct die_info
*parent
, *spec_die
;
19854 struct dwarf2_cu
*spec_cu
;
19855 struct type
*parent_type
;
19858 if (cu
->language
!= language_cplus
19859 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
19860 && cu
->language
!= language_rust
)
19863 retval
= anonymous_struct_prefix (die
, cu
);
19867 /* We have to be careful in the presence of DW_AT_specification.
19868 For example, with GCC 3.4, given the code
19872 // Definition of N::foo.
19876 then we'll have a tree of DIEs like this:
19878 1: DW_TAG_compile_unit
19879 2: DW_TAG_namespace // N
19880 3: DW_TAG_subprogram // declaration of N::foo
19881 4: DW_TAG_subprogram // definition of N::foo
19882 DW_AT_specification // refers to die #3
19884 Thus, when processing die #4, we have to pretend that we're in
19885 the context of its DW_AT_specification, namely the contex of die
19888 spec_die
= die_specification (die
, &spec_cu
);
19889 if (spec_die
== NULL
)
19890 parent
= die
->parent
;
19893 parent
= spec_die
->parent
;
19897 if (parent
== NULL
)
19899 else if (parent
->building_fullname
)
19902 const char *parent_name
;
19904 /* It has been seen on RealView 2.2 built binaries,
19905 DW_TAG_template_type_param types actually _defined_ as
19906 children of the parent class:
19909 template class <class Enum> Class{};
19910 Class<enum E> class_e;
19912 1: DW_TAG_class_type (Class)
19913 2: DW_TAG_enumeration_type (E)
19914 3: DW_TAG_enumerator (enum1:0)
19915 3: DW_TAG_enumerator (enum2:1)
19917 2: DW_TAG_template_type_param
19918 DW_AT_type DW_FORM_ref_udata (E)
19920 Besides being broken debug info, it can put GDB into an
19921 infinite loop. Consider:
19923 When we're building the full name for Class<E>, we'll start
19924 at Class, and go look over its template type parameters,
19925 finding E. We'll then try to build the full name of E, and
19926 reach here. We're now trying to build the full name of E,
19927 and look over the parent DIE for containing scope. In the
19928 broken case, if we followed the parent DIE of E, we'd again
19929 find Class, and once again go look at its template type
19930 arguments, etc., etc. Simply don't consider such parent die
19931 as source-level parent of this die (it can't be, the language
19932 doesn't allow it), and break the loop here. */
19933 name
= dwarf2_name (die
, cu
);
19934 parent_name
= dwarf2_name (parent
, cu
);
19935 complaint (&symfile_complaints
,
19936 _("template param type '%s' defined within parent '%s'"),
19937 name
? name
: "<unknown>",
19938 parent_name
? parent_name
: "<unknown>");
19942 switch (parent
->tag
)
19944 case DW_TAG_namespace
:
19945 parent_type
= read_type_die (parent
, cu
);
19946 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
19947 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
19948 Work around this problem here. */
19949 if (cu
->language
== language_cplus
19950 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
19952 /* We give a name to even anonymous namespaces. */
19953 return TYPE_TAG_NAME (parent_type
);
19954 case DW_TAG_class_type
:
19955 case DW_TAG_interface_type
:
19956 case DW_TAG_structure_type
:
19957 case DW_TAG_union_type
:
19958 case DW_TAG_module
:
19959 parent_type
= read_type_die (parent
, cu
);
19960 if (TYPE_TAG_NAME (parent_type
) != NULL
)
19961 return TYPE_TAG_NAME (parent_type
);
19963 /* An anonymous structure is only allowed non-static data
19964 members; no typedefs, no member functions, et cetera.
19965 So it does not need a prefix. */
19967 case DW_TAG_compile_unit
:
19968 case DW_TAG_partial_unit
:
19969 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
19970 if (cu
->language
== language_cplus
19971 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
19972 && die
->child
!= NULL
19973 && (die
->tag
== DW_TAG_class_type
19974 || die
->tag
== DW_TAG_structure_type
19975 || die
->tag
== DW_TAG_union_type
))
19977 char *name
= guess_full_die_structure_name (die
, cu
);
19982 case DW_TAG_enumeration_type
:
19983 parent_type
= read_type_die (parent
, cu
);
19984 if (TYPE_DECLARED_CLASS (parent_type
))
19986 if (TYPE_TAG_NAME (parent_type
) != NULL
)
19987 return TYPE_TAG_NAME (parent_type
);
19990 /* Fall through. */
19992 return determine_prefix (parent
, cu
);
19996 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
19997 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
19998 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
19999 an obconcat, otherwise allocate storage for the result. The CU argument is
20000 used to determine the language and hence, the appropriate separator. */
20002 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
20005 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
20006 int physname
, struct dwarf2_cu
*cu
)
20008 const char *lead
= "";
20011 if (suffix
== NULL
|| suffix
[0] == '\0'
20012 || prefix
== NULL
|| prefix
[0] == '\0')
20014 else if (cu
->language
== language_d
)
20016 /* For D, the 'main' function could be defined in any module, but it
20017 should never be prefixed. */
20018 if (strcmp (suffix
, "D main") == 0)
20026 else if (cu
->language
== language_fortran
&& physname
)
20028 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
20029 DW_AT_MIPS_linkage_name is preferred and used instead. */
20037 if (prefix
== NULL
)
20039 if (suffix
== NULL
)
20046 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
20048 strcpy (retval
, lead
);
20049 strcat (retval
, prefix
);
20050 strcat (retval
, sep
);
20051 strcat (retval
, suffix
);
20056 /* We have an obstack. */
20057 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
20061 /* Return sibling of die, NULL if no sibling. */
20063 static struct die_info
*
20064 sibling_die (struct die_info
*die
)
20066 return die
->sibling
;
20069 /* Get name of a die, return NULL if not found. */
20071 static const char *
20072 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
20073 struct obstack
*obstack
)
20075 if (name
&& cu
->language
== language_cplus
)
20077 std::string canon_name
= cp_canonicalize_string (name
);
20079 if (!canon_name
.empty ())
20081 if (canon_name
!= name
)
20082 name
= (const char *) obstack_copy0 (obstack
,
20083 canon_name
.c_str (),
20084 canon_name
.length ());
20091 /* Get name of a die, return NULL if not found.
20092 Anonymous namespaces are converted to their magic string. */
20094 static const char *
20095 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20097 struct attribute
*attr
;
20099 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
20100 if ((!attr
|| !DW_STRING (attr
))
20101 && die
->tag
!= DW_TAG_namespace
20102 && die
->tag
!= DW_TAG_class_type
20103 && die
->tag
!= DW_TAG_interface_type
20104 && die
->tag
!= DW_TAG_structure_type
20105 && die
->tag
!= DW_TAG_union_type
)
20110 case DW_TAG_compile_unit
:
20111 case DW_TAG_partial_unit
:
20112 /* Compilation units have a DW_AT_name that is a filename, not
20113 a source language identifier. */
20114 case DW_TAG_enumeration_type
:
20115 case DW_TAG_enumerator
:
20116 /* These tags always have simple identifiers already; no need
20117 to canonicalize them. */
20118 return DW_STRING (attr
);
20120 case DW_TAG_namespace
:
20121 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
20122 return DW_STRING (attr
);
20123 return CP_ANONYMOUS_NAMESPACE_STR
;
20125 case DW_TAG_class_type
:
20126 case DW_TAG_interface_type
:
20127 case DW_TAG_structure_type
:
20128 case DW_TAG_union_type
:
20129 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
20130 structures or unions. These were of the form "._%d" in GCC 4.1,
20131 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
20132 and GCC 4.4. We work around this problem by ignoring these. */
20133 if (attr
&& DW_STRING (attr
)
20134 && (startswith (DW_STRING (attr
), "._")
20135 || startswith (DW_STRING (attr
), "<anonymous")))
20138 /* GCC might emit a nameless typedef that has a linkage name. See
20139 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
20140 if (!attr
|| DW_STRING (attr
) == NULL
)
20142 char *demangled
= NULL
;
20144 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
20146 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
20148 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
20151 /* Avoid demangling DW_STRING (attr) the second time on a second
20152 call for the same DIE. */
20153 if (!DW_STRING_IS_CANONICAL (attr
))
20154 demangled
= gdb_demangle (DW_STRING (attr
), DMGL_TYPES
);
20160 /* FIXME: we already did this for the partial symbol... */
20163 obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
20164 demangled
, strlen (demangled
)));
20165 DW_STRING_IS_CANONICAL (attr
) = 1;
20168 /* Strip any leading namespaces/classes, keep only the base name.
20169 DW_AT_name for named DIEs does not contain the prefixes. */
20170 base
= strrchr (DW_STRING (attr
), ':');
20171 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
20174 return DW_STRING (attr
);
20183 if (!DW_STRING_IS_CANONICAL (attr
))
20186 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
20187 &cu
->objfile
->per_bfd
->storage_obstack
);
20188 DW_STRING_IS_CANONICAL (attr
) = 1;
20190 return DW_STRING (attr
);
20193 /* Return the die that this die in an extension of, or NULL if there
20194 is none. *EXT_CU is the CU containing DIE on input, and the CU
20195 containing the return value on output. */
20197 static struct die_info
*
20198 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
20200 struct attribute
*attr
;
20202 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
20206 return follow_die_ref (die
, attr
, ext_cu
);
20209 /* Convert a DIE tag into its string name. */
20211 static const char *
20212 dwarf_tag_name (unsigned tag
)
20214 const char *name
= get_DW_TAG_name (tag
);
20217 return "DW_TAG_<unknown>";
20222 /* Convert a DWARF attribute code into its string name. */
20224 static const char *
20225 dwarf_attr_name (unsigned attr
)
20229 #ifdef MIPS /* collides with DW_AT_HP_block_index */
20230 if (attr
== DW_AT_MIPS_fde
)
20231 return "DW_AT_MIPS_fde";
20233 if (attr
== DW_AT_HP_block_index
)
20234 return "DW_AT_HP_block_index";
20237 name
= get_DW_AT_name (attr
);
20240 return "DW_AT_<unknown>";
20245 /* Convert a DWARF value form code into its string name. */
20247 static const char *
20248 dwarf_form_name (unsigned form
)
20250 const char *name
= get_DW_FORM_name (form
);
20253 return "DW_FORM_<unknown>";
20259 dwarf_bool_name (unsigned mybool
)
20267 /* Convert a DWARF type code into its string name. */
20269 static const char *
20270 dwarf_type_encoding_name (unsigned enc
)
20272 const char *name
= get_DW_ATE_name (enc
);
20275 return "DW_ATE_<unknown>";
20281 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
20285 print_spaces (indent
, f
);
20286 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
20287 dwarf_tag_name (die
->tag
), die
->abbrev
,
20288 to_underlying (die
->sect_off
));
20290 if (die
->parent
!= NULL
)
20292 print_spaces (indent
, f
);
20293 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
20294 to_underlying (die
->parent
->sect_off
));
20297 print_spaces (indent
, f
);
20298 fprintf_unfiltered (f
, " has children: %s\n",
20299 dwarf_bool_name (die
->child
!= NULL
));
20301 print_spaces (indent
, f
);
20302 fprintf_unfiltered (f
, " attributes:\n");
20304 for (i
= 0; i
< die
->num_attrs
; ++i
)
20306 print_spaces (indent
, f
);
20307 fprintf_unfiltered (f
, " %s (%s) ",
20308 dwarf_attr_name (die
->attrs
[i
].name
),
20309 dwarf_form_name (die
->attrs
[i
].form
));
20311 switch (die
->attrs
[i
].form
)
20314 case DW_FORM_GNU_addr_index
:
20315 fprintf_unfiltered (f
, "address: ");
20316 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
20318 case DW_FORM_block2
:
20319 case DW_FORM_block4
:
20320 case DW_FORM_block
:
20321 case DW_FORM_block1
:
20322 fprintf_unfiltered (f
, "block: size %s",
20323 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
20325 case DW_FORM_exprloc
:
20326 fprintf_unfiltered (f
, "expression: size %s",
20327 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
20329 case DW_FORM_data16
:
20330 fprintf_unfiltered (f
, "constant of 16 bytes");
20332 case DW_FORM_ref_addr
:
20333 fprintf_unfiltered (f
, "ref address: ");
20334 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
20336 case DW_FORM_GNU_ref_alt
:
20337 fprintf_unfiltered (f
, "alt ref address: ");
20338 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
20344 case DW_FORM_ref_udata
:
20345 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
20346 (long) (DW_UNSND (&die
->attrs
[i
])));
20348 case DW_FORM_data1
:
20349 case DW_FORM_data2
:
20350 case DW_FORM_data4
:
20351 case DW_FORM_data8
:
20352 case DW_FORM_udata
:
20353 case DW_FORM_sdata
:
20354 fprintf_unfiltered (f
, "constant: %s",
20355 pulongest (DW_UNSND (&die
->attrs
[i
])));
20357 case DW_FORM_sec_offset
:
20358 fprintf_unfiltered (f
, "section offset: %s",
20359 pulongest (DW_UNSND (&die
->attrs
[i
])));
20361 case DW_FORM_ref_sig8
:
20362 fprintf_unfiltered (f
, "signature: %s",
20363 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
20365 case DW_FORM_string
:
20367 case DW_FORM_line_strp
:
20368 case DW_FORM_GNU_str_index
:
20369 case DW_FORM_GNU_strp_alt
:
20370 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
20371 DW_STRING (&die
->attrs
[i
])
20372 ? DW_STRING (&die
->attrs
[i
]) : "",
20373 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
20376 if (DW_UNSND (&die
->attrs
[i
]))
20377 fprintf_unfiltered (f
, "flag: TRUE");
20379 fprintf_unfiltered (f
, "flag: FALSE");
20381 case DW_FORM_flag_present
:
20382 fprintf_unfiltered (f
, "flag: TRUE");
20384 case DW_FORM_indirect
:
20385 /* The reader will have reduced the indirect form to
20386 the "base form" so this form should not occur. */
20387 fprintf_unfiltered (f
,
20388 "unexpected attribute form: DW_FORM_indirect");
20391 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
20392 die
->attrs
[i
].form
);
20395 fprintf_unfiltered (f
, "\n");
20400 dump_die_for_error (struct die_info
*die
)
20402 dump_die_shallow (gdb_stderr
, 0, die
);
20406 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
20408 int indent
= level
* 4;
20410 gdb_assert (die
!= NULL
);
20412 if (level
>= max_level
)
20415 dump_die_shallow (f
, indent
, die
);
20417 if (die
->child
!= NULL
)
20419 print_spaces (indent
, f
);
20420 fprintf_unfiltered (f
, " Children:");
20421 if (level
+ 1 < max_level
)
20423 fprintf_unfiltered (f
, "\n");
20424 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
20428 fprintf_unfiltered (f
,
20429 " [not printed, max nesting level reached]\n");
20433 if (die
->sibling
!= NULL
&& level
> 0)
20435 dump_die_1 (f
, level
, max_level
, die
->sibling
);
20439 /* This is called from the pdie macro in gdbinit.in.
20440 It's not static so gcc will keep a copy callable from gdb. */
20443 dump_die (struct die_info
*die
, int max_level
)
20445 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
20449 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
20453 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
20454 to_underlying (die
->sect_off
),
20460 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
20464 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
20466 if (attr_form_is_ref (attr
))
20467 return (sect_offset
) DW_UNSND (attr
);
20469 complaint (&symfile_complaints
,
20470 _("unsupported die ref attribute form: '%s'"),
20471 dwarf_form_name (attr
->form
));
20475 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
20476 * the value held by the attribute is not constant. */
20479 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
20481 if (attr
->form
== DW_FORM_sdata
)
20482 return DW_SND (attr
);
20483 else if (attr
->form
== DW_FORM_udata
20484 || attr
->form
== DW_FORM_data1
20485 || attr
->form
== DW_FORM_data2
20486 || attr
->form
== DW_FORM_data4
20487 || attr
->form
== DW_FORM_data8
)
20488 return DW_UNSND (attr
);
20491 /* For DW_FORM_data16 see attr_form_is_constant. */
20492 complaint (&symfile_complaints
,
20493 _("Attribute value is not a constant (%s)"),
20494 dwarf_form_name (attr
->form
));
20495 return default_value
;
20499 /* Follow reference or signature attribute ATTR of SRC_DIE.
20500 On entry *REF_CU is the CU of SRC_DIE.
20501 On exit *REF_CU is the CU of the result. */
20503 static struct die_info
*
20504 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
20505 struct dwarf2_cu
**ref_cu
)
20507 struct die_info
*die
;
20509 if (attr_form_is_ref (attr
))
20510 die
= follow_die_ref (src_die
, attr
, ref_cu
);
20511 else if (attr
->form
== DW_FORM_ref_sig8
)
20512 die
= follow_die_sig (src_die
, attr
, ref_cu
);
20515 dump_die_for_error (src_die
);
20516 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
20517 objfile_name ((*ref_cu
)->objfile
));
20523 /* Follow reference OFFSET.
20524 On entry *REF_CU is the CU of the source die referencing OFFSET.
20525 On exit *REF_CU is the CU of the result.
20526 Returns NULL if OFFSET is invalid. */
20528 static struct die_info
*
20529 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
20530 struct dwarf2_cu
**ref_cu
)
20532 struct die_info temp_die
;
20533 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
20535 gdb_assert (cu
->per_cu
!= NULL
);
20539 if (cu
->per_cu
->is_debug_types
)
20541 /* .debug_types CUs cannot reference anything outside their CU.
20542 If they need to, they have to reference a signatured type via
20543 DW_FORM_ref_sig8. */
20544 if (!offset_in_cu_p (&cu
->header
, sect_off
))
20547 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
20548 || !offset_in_cu_p (&cu
->header
, sect_off
))
20550 struct dwarf2_per_cu_data
*per_cu
;
20552 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
20555 /* If necessary, add it to the queue and load its DIEs. */
20556 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
20557 load_full_comp_unit (per_cu
, cu
->language
);
20559 target_cu
= per_cu
->cu
;
20561 else if (cu
->dies
== NULL
)
20563 /* We're loading full DIEs during partial symbol reading. */
20564 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
20565 load_full_comp_unit (cu
->per_cu
, language_minimal
);
20568 *ref_cu
= target_cu
;
20569 temp_die
.sect_off
= sect_off
;
20570 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
20572 to_underlying (sect_off
));
20575 /* Follow reference attribute ATTR of SRC_DIE.
20576 On entry *REF_CU is the CU of SRC_DIE.
20577 On exit *REF_CU is the CU of the result. */
20579 static struct die_info
*
20580 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
20581 struct dwarf2_cu
**ref_cu
)
20583 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
20584 struct dwarf2_cu
*cu
= *ref_cu
;
20585 struct die_info
*die
;
20587 die
= follow_die_offset (sect_off
,
20588 (attr
->form
== DW_FORM_GNU_ref_alt
20589 || cu
->per_cu
->is_dwz
),
20592 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
20593 "at 0x%x [in module %s]"),
20594 to_underlying (sect_off
), to_underlying (src_die
->sect_off
),
20595 objfile_name (cu
->objfile
));
20600 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
20601 Returned value is intended for DW_OP_call*. Returned
20602 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
20604 struct dwarf2_locexpr_baton
20605 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
20606 struct dwarf2_per_cu_data
*per_cu
,
20607 CORE_ADDR (*get_frame_pc
) (void *baton
),
20610 struct dwarf2_cu
*cu
;
20611 struct die_info
*die
;
20612 struct attribute
*attr
;
20613 struct dwarf2_locexpr_baton retval
;
20615 dw2_setup (per_cu
->objfile
);
20617 if (per_cu
->cu
== NULL
)
20622 /* We shouldn't get here for a dummy CU, but don't crash on the user.
20623 Instead just throw an error, not much else we can do. */
20624 error (_("Dwarf Error: Dummy CU at 0x%x referenced in module %s"),
20625 to_underlying (sect_off
), objfile_name (per_cu
->objfile
));
20628 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
20630 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
20631 to_underlying (sect_off
), objfile_name (per_cu
->objfile
));
20633 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20636 /* DWARF: "If there is no such attribute, then there is no effect.".
20637 DATA is ignored if SIZE is 0. */
20639 retval
.data
= NULL
;
20642 else if (attr_form_is_section_offset (attr
))
20644 struct dwarf2_loclist_baton loclist_baton
;
20645 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
20648 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
20650 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
20652 retval
.size
= size
;
20656 if (!attr_form_is_block (attr
))
20657 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
20658 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
20659 to_underlying (sect_off
), objfile_name (per_cu
->objfile
));
20661 retval
.data
= DW_BLOCK (attr
)->data
;
20662 retval
.size
= DW_BLOCK (attr
)->size
;
20664 retval
.per_cu
= cu
->per_cu
;
20666 age_cached_comp_units ();
20671 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
20674 struct dwarf2_locexpr_baton
20675 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
20676 struct dwarf2_per_cu_data
*per_cu
,
20677 CORE_ADDR (*get_frame_pc
) (void *baton
),
20680 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
20682 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
20685 /* Write a constant of a given type as target-ordered bytes into
20688 static const gdb_byte
*
20689 write_constant_as_bytes (struct obstack
*obstack
,
20690 enum bfd_endian byte_order
,
20697 *len
= TYPE_LENGTH (type
);
20698 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
20699 store_unsigned_integer (result
, *len
, byte_order
, value
);
20704 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
20705 pointer to the constant bytes and set LEN to the length of the
20706 data. If memory is needed, allocate it on OBSTACK. If the DIE
20707 does not have a DW_AT_const_value, return NULL. */
20710 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
20711 struct dwarf2_per_cu_data
*per_cu
,
20712 struct obstack
*obstack
,
20715 struct dwarf2_cu
*cu
;
20716 struct die_info
*die
;
20717 struct attribute
*attr
;
20718 const gdb_byte
*result
= NULL
;
20721 enum bfd_endian byte_order
;
20723 dw2_setup (per_cu
->objfile
);
20725 if (per_cu
->cu
== NULL
)
20730 /* We shouldn't get here for a dummy CU, but don't crash on the user.
20731 Instead just throw an error, not much else we can do. */
20732 error (_("Dwarf Error: Dummy CU at 0x%x referenced in module %s"),
20733 to_underlying (sect_off
), objfile_name (per_cu
->objfile
));
20736 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
20738 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
20739 to_underlying (sect_off
), objfile_name (per_cu
->objfile
));
20742 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20746 byte_order
= (bfd_big_endian (per_cu
->objfile
->obfd
)
20747 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
20749 switch (attr
->form
)
20752 case DW_FORM_GNU_addr_index
:
20756 *len
= cu
->header
.addr_size
;
20757 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
20758 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
20762 case DW_FORM_string
:
20764 case DW_FORM_GNU_str_index
:
20765 case DW_FORM_GNU_strp_alt
:
20766 /* DW_STRING is already allocated on the objfile obstack, point
20768 result
= (const gdb_byte
*) DW_STRING (attr
);
20769 *len
= strlen (DW_STRING (attr
));
20771 case DW_FORM_block1
:
20772 case DW_FORM_block2
:
20773 case DW_FORM_block4
:
20774 case DW_FORM_block
:
20775 case DW_FORM_exprloc
:
20776 case DW_FORM_data16
:
20777 result
= DW_BLOCK (attr
)->data
;
20778 *len
= DW_BLOCK (attr
)->size
;
20781 /* The DW_AT_const_value attributes are supposed to carry the
20782 symbol's value "represented as it would be on the target
20783 architecture." By the time we get here, it's already been
20784 converted to host endianness, so we just need to sign- or
20785 zero-extend it as appropriate. */
20786 case DW_FORM_data1
:
20787 type
= die_type (die
, cu
);
20788 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
20789 if (result
== NULL
)
20790 result
= write_constant_as_bytes (obstack
, byte_order
,
20793 case DW_FORM_data2
:
20794 type
= die_type (die
, cu
);
20795 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
20796 if (result
== NULL
)
20797 result
= write_constant_as_bytes (obstack
, byte_order
,
20800 case DW_FORM_data4
:
20801 type
= die_type (die
, cu
);
20802 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
20803 if (result
== NULL
)
20804 result
= write_constant_as_bytes (obstack
, byte_order
,
20807 case DW_FORM_data8
:
20808 type
= die_type (die
, cu
);
20809 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
20810 if (result
== NULL
)
20811 result
= write_constant_as_bytes (obstack
, byte_order
,
20815 case DW_FORM_sdata
:
20816 type
= die_type (die
, cu
);
20817 result
= write_constant_as_bytes (obstack
, byte_order
,
20818 type
, DW_SND (attr
), len
);
20821 case DW_FORM_udata
:
20822 type
= die_type (die
, cu
);
20823 result
= write_constant_as_bytes (obstack
, byte_order
,
20824 type
, DW_UNSND (attr
), len
);
20828 complaint (&symfile_complaints
,
20829 _("unsupported const value attribute form: '%s'"),
20830 dwarf_form_name (attr
->form
));
20837 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
20838 valid type for this die is found. */
20841 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
20842 struct dwarf2_per_cu_data
*per_cu
)
20844 struct dwarf2_cu
*cu
;
20845 struct die_info
*die
;
20847 dw2_setup (per_cu
->objfile
);
20849 if (per_cu
->cu
== NULL
)
20855 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
20859 return die_type (die
, cu
);
20862 /* Return the type of the DIE at DIE_OFFSET in the CU named by
20866 dwarf2_get_die_type (cu_offset die_offset
,
20867 struct dwarf2_per_cu_data
*per_cu
)
20869 dw2_setup (per_cu
->objfile
);
20871 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
20872 return get_die_type_at_offset (die_offset_sect
, per_cu
);
20875 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
20876 On entry *REF_CU is the CU of SRC_DIE.
20877 On exit *REF_CU is the CU of the result.
20878 Returns NULL if the referenced DIE isn't found. */
20880 static struct die_info
*
20881 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
20882 struct dwarf2_cu
**ref_cu
)
20884 struct die_info temp_die
;
20885 struct dwarf2_cu
*sig_cu
;
20886 struct die_info
*die
;
20888 /* While it might be nice to assert sig_type->type == NULL here,
20889 we can get here for DW_AT_imported_declaration where we need
20890 the DIE not the type. */
20892 /* If necessary, add it to the queue and load its DIEs. */
20894 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
20895 read_signatured_type (sig_type
);
20897 sig_cu
= sig_type
->per_cu
.cu
;
20898 gdb_assert (sig_cu
!= NULL
);
20899 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
20900 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
20901 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
20902 to_underlying (temp_die
.sect_off
));
20905 /* For .gdb_index version 7 keep track of included TUs.
20906 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
20907 if (dwarf2_per_objfile
->index_table
!= NULL
20908 && dwarf2_per_objfile
->index_table
->version
<= 7)
20910 VEC_safe_push (dwarf2_per_cu_ptr
,
20911 (*ref_cu
)->per_cu
->imported_symtabs
,
20922 /* Follow signatured type referenced by ATTR in SRC_DIE.
20923 On entry *REF_CU is the CU of SRC_DIE.
20924 On exit *REF_CU is the CU of the result.
20925 The result is the DIE of the type.
20926 If the referenced type cannot be found an error is thrown. */
20928 static struct die_info
*
20929 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
20930 struct dwarf2_cu
**ref_cu
)
20932 ULONGEST signature
= DW_SIGNATURE (attr
);
20933 struct signatured_type
*sig_type
;
20934 struct die_info
*die
;
20936 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
20938 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
20939 /* sig_type will be NULL if the signatured type is missing from
20941 if (sig_type
== NULL
)
20943 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
20944 " from DIE at 0x%x [in module %s]"),
20945 hex_string (signature
), to_underlying (src_die
->sect_off
),
20946 objfile_name ((*ref_cu
)->objfile
));
20949 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
20952 dump_die_for_error (src_die
);
20953 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
20954 " from DIE at 0x%x [in module %s]"),
20955 hex_string (signature
), to_underlying (src_die
->sect_off
),
20956 objfile_name ((*ref_cu
)->objfile
));
20962 /* Get the type specified by SIGNATURE referenced in DIE/CU,
20963 reading in and processing the type unit if necessary. */
20965 static struct type
*
20966 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
20967 struct dwarf2_cu
*cu
)
20969 struct signatured_type
*sig_type
;
20970 struct dwarf2_cu
*type_cu
;
20971 struct die_info
*type_die
;
20974 sig_type
= lookup_signatured_type (cu
, signature
);
20975 /* sig_type will be NULL if the signatured type is missing from
20977 if (sig_type
== NULL
)
20979 complaint (&symfile_complaints
,
20980 _("Dwarf Error: Cannot find signatured DIE %s referenced"
20981 " from DIE at 0x%x [in module %s]"),
20982 hex_string (signature
), to_underlying (die
->sect_off
),
20983 objfile_name (dwarf2_per_objfile
->objfile
));
20984 return build_error_marker_type (cu
, die
);
20987 /* If we already know the type we're done. */
20988 if (sig_type
->type
!= NULL
)
20989 return sig_type
->type
;
20992 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
20993 if (type_die
!= NULL
)
20995 /* N.B. We need to call get_die_type to ensure only one type for this DIE
20996 is created. This is important, for example, because for c++ classes
20997 we need TYPE_NAME set which is only done by new_symbol. Blech. */
20998 type
= read_type_die (type_die
, type_cu
);
21001 complaint (&symfile_complaints
,
21002 _("Dwarf Error: Cannot build signatured type %s"
21003 " referenced from DIE at 0x%x [in module %s]"),
21004 hex_string (signature
), to_underlying (die
->sect_off
),
21005 objfile_name (dwarf2_per_objfile
->objfile
));
21006 type
= build_error_marker_type (cu
, die
);
21011 complaint (&symfile_complaints
,
21012 _("Dwarf Error: Problem reading signatured DIE %s referenced"
21013 " from DIE at 0x%x [in module %s]"),
21014 hex_string (signature
), to_underlying (die
->sect_off
),
21015 objfile_name (dwarf2_per_objfile
->objfile
));
21016 type
= build_error_marker_type (cu
, die
);
21018 sig_type
->type
= type
;
21023 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
21024 reading in and processing the type unit if necessary. */
21026 static struct type
*
21027 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
21028 struct dwarf2_cu
*cu
) /* ARI: editCase function */
21030 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
21031 if (attr_form_is_ref (attr
))
21033 struct dwarf2_cu
*type_cu
= cu
;
21034 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
21036 return read_type_die (type_die
, type_cu
);
21038 else if (attr
->form
== DW_FORM_ref_sig8
)
21040 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
21044 complaint (&symfile_complaints
,
21045 _("Dwarf Error: DW_AT_signature has bad form %s in DIE"
21046 " at 0x%x [in module %s]"),
21047 dwarf_form_name (attr
->form
), to_underlying (die
->sect_off
),
21048 objfile_name (dwarf2_per_objfile
->objfile
));
21049 return build_error_marker_type (cu
, die
);
21053 /* Load the DIEs associated with type unit PER_CU into memory. */
21056 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
21058 struct signatured_type
*sig_type
;
21060 /* Caller is responsible for ensuring type_unit_groups don't get here. */
21061 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
21063 /* We have the per_cu, but we need the signatured_type.
21064 Fortunately this is an easy translation. */
21065 gdb_assert (per_cu
->is_debug_types
);
21066 sig_type
= (struct signatured_type
*) per_cu
;
21068 gdb_assert (per_cu
->cu
== NULL
);
21070 read_signatured_type (sig_type
);
21072 gdb_assert (per_cu
->cu
!= NULL
);
21075 /* die_reader_func for read_signatured_type.
21076 This is identical to load_full_comp_unit_reader,
21077 but is kept separate for now. */
21080 read_signatured_type_reader (const struct die_reader_specs
*reader
,
21081 const gdb_byte
*info_ptr
,
21082 struct die_info
*comp_unit_die
,
21086 struct dwarf2_cu
*cu
= reader
->cu
;
21088 gdb_assert (cu
->die_hash
== NULL
);
21090 htab_create_alloc_ex (cu
->header
.length
/ 12,
21094 &cu
->comp_unit_obstack
,
21095 hashtab_obstack_allocate
,
21096 dummy_obstack_deallocate
);
21099 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
21100 &info_ptr
, comp_unit_die
);
21101 cu
->dies
= comp_unit_die
;
21102 /* comp_unit_die is not stored in die_hash, no need. */
21104 /* We try not to read any attributes in this function, because not
21105 all CUs needed for references have been loaded yet, and symbol
21106 table processing isn't initialized. But we have to set the CU language,
21107 or we won't be able to build types correctly.
21108 Similarly, if we do not read the producer, we can not apply
21109 producer-specific interpretation. */
21110 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
21113 /* Read in a signatured type and build its CU and DIEs.
21114 If the type is a stub for the real type in a DWO file,
21115 read in the real type from the DWO file as well. */
21118 read_signatured_type (struct signatured_type
*sig_type
)
21120 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
21122 gdb_assert (per_cu
->is_debug_types
);
21123 gdb_assert (per_cu
->cu
== NULL
);
21125 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1,
21126 read_signatured_type_reader
, NULL
);
21127 sig_type
->per_cu
.tu_read
= 1;
21130 /* Decode simple location descriptions.
21131 Given a pointer to a dwarf block that defines a location, compute
21132 the location and return the value.
21134 NOTE drow/2003-11-18: This function is called in two situations
21135 now: for the address of static or global variables (partial symbols
21136 only) and for offsets into structures which are expected to be
21137 (more or less) constant. The partial symbol case should go away,
21138 and only the constant case should remain. That will let this
21139 function complain more accurately. A few special modes are allowed
21140 without complaint for global variables (for instance, global
21141 register values and thread-local values).
21143 A location description containing no operations indicates that the
21144 object is optimized out. The return value is 0 for that case.
21145 FIXME drow/2003-11-16: No callers check for this case any more; soon all
21146 callers will only want a very basic result and this can become a
21149 Note that stack[0] is unused except as a default error return. */
21152 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
21154 struct objfile
*objfile
= cu
->objfile
;
21156 size_t size
= blk
->size
;
21157 const gdb_byte
*data
= blk
->data
;
21158 CORE_ADDR stack
[64];
21160 unsigned int bytes_read
, unsnd
;
21166 stack
[++stacki
] = 0;
21205 stack
[++stacki
] = op
- DW_OP_lit0
;
21240 stack
[++stacki
] = op
- DW_OP_reg0
;
21242 dwarf2_complex_location_expr_complaint ();
21246 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
21248 stack
[++stacki
] = unsnd
;
21250 dwarf2_complex_location_expr_complaint ();
21254 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
21259 case DW_OP_const1u
:
21260 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
21264 case DW_OP_const1s
:
21265 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
21269 case DW_OP_const2u
:
21270 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
21274 case DW_OP_const2s
:
21275 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
21279 case DW_OP_const4u
:
21280 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
21284 case DW_OP_const4s
:
21285 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
21289 case DW_OP_const8u
:
21290 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
21295 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
21301 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
21306 stack
[stacki
+ 1] = stack
[stacki
];
21311 stack
[stacki
- 1] += stack
[stacki
];
21315 case DW_OP_plus_uconst
:
21316 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
21322 stack
[stacki
- 1] -= stack
[stacki
];
21327 /* If we're not the last op, then we definitely can't encode
21328 this using GDB's address_class enum. This is valid for partial
21329 global symbols, although the variable's address will be bogus
21332 dwarf2_complex_location_expr_complaint ();
21335 case DW_OP_GNU_push_tls_address
:
21336 case DW_OP_form_tls_address
:
21337 /* The top of the stack has the offset from the beginning
21338 of the thread control block at which the variable is located. */
21339 /* Nothing should follow this operator, so the top of stack would
21341 /* This is valid for partial global symbols, but the variable's
21342 address will be bogus in the psymtab. Make it always at least
21343 non-zero to not look as a variable garbage collected by linker
21344 which have DW_OP_addr 0. */
21346 dwarf2_complex_location_expr_complaint ();
21350 case DW_OP_GNU_uninit
:
21353 case DW_OP_GNU_addr_index
:
21354 case DW_OP_GNU_const_index
:
21355 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
21362 const char *name
= get_DW_OP_name (op
);
21365 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
21368 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
21372 return (stack
[stacki
]);
21375 /* Enforce maximum stack depth of SIZE-1 to avoid writing
21376 outside of the allocated space. Also enforce minimum>0. */
21377 if (stacki
>= ARRAY_SIZE (stack
) - 1)
21379 complaint (&symfile_complaints
,
21380 _("location description stack overflow"));
21386 complaint (&symfile_complaints
,
21387 _("location description stack underflow"));
21391 return (stack
[stacki
]);
21394 /* memory allocation interface */
21396 static struct dwarf_block
*
21397 dwarf_alloc_block (struct dwarf2_cu
*cu
)
21399 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
21402 static struct die_info
*
21403 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
21405 struct die_info
*die
;
21406 size_t size
= sizeof (struct die_info
);
21409 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
21411 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
21412 memset (die
, 0, sizeof (struct die_info
));
21417 /* Macro support. */
21419 /* Return file name relative to the compilation directory of file number I in
21420 *LH's file name table. The result is allocated using xmalloc; the caller is
21421 responsible for freeing it. */
21424 file_file_name (int file
, struct line_header
*lh
)
21426 /* Is the file number a valid index into the line header's file name
21427 table? Remember that file numbers start with one, not zero. */
21428 if (1 <= file
&& file
<= lh
->file_names
.size ())
21430 const file_entry
&fe
= lh
->file_names
[file
- 1];
21432 if (!IS_ABSOLUTE_PATH (fe
.name
))
21434 const char *dir
= fe
.include_dir (lh
);
21436 return concat (dir
, SLASH_STRING
, fe
.name
, (char *) NULL
);
21438 return xstrdup (fe
.name
);
21442 /* The compiler produced a bogus file number. We can at least
21443 record the macro definitions made in the file, even if we
21444 won't be able to find the file by name. */
21445 char fake_name
[80];
21447 xsnprintf (fake_name
, sizeof (fake_name
),
21448 "<bad macro file number %d>", file
);
21450 complaint (&symfile_complaints
,
21451 _("bad file number in macro information (%d)"),
21454 return xstrdup (fake_name
);
21458 /* Return the full name of file number I in *LH's file name table.
21459 Use COMP_DIR as the name of the current directory of the
21460 compilation. The result is allocated using xmalloc; the caller is
21461 responsible for freeing it. */
21463 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
21465 /* Is the file number a valid index into the line header's file name
21466 table? Remember that file numbers start with one, not zero. */
21467 if (1 <= file
&& file
<= lh
->file_names
.size ())
21469 char *relative
= file_file_name (file
, lh
);
21471 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
21473 return reconcat (relative
, comp_dir
, SLASH_STRING
,
21474 relative
, (char *) NULL
);
21477 return file_file_name (file
, lh
);
21481 static struct macro_source_file
*
21482 macro_start_file (int file
, int line
,
21483 struct macro_source_file
*current_file
,
21484 struct line_header
*lh
)
21486 /* File name relative to the compilation directory of this source file. */
21487 char *file_name
= file_file_name (file
, lh
);
21489 if (! current_file
)
21491 /* Note: We don't create a macro table for this compilation unit
21492 at all until we actually get a filename. */
21493 struct macro_table
*macro_table
= get_macro_table ();
21495 /* If we have no current file, then this must be the start_file
21496 directive for the compilation unit's main source file. */
21497 current_file
= macro_set_main (macro_table
, file_name
);
21498 macro_define_special (macro_table
);
21501 current_file
= macro_include (current_file
, line
, file_name
);
21505 return current_file
;
21509 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
21510 followed by a null byte. */
21512 copy_string (const char *buf
, int len
)
21514 char *s
= (char *) xmalloc (len
+ 1);
21516 memcpy (s
, buf
, len
);
21522 static const char *
21523 consume_improper_spaces (const char *p
, const char *body
)
21527 complaint (&symfile_complaints
,
21528 _("macro definition contains spaces "
21529 "in formal argument list:\n`%s'"),
21541 parse_macro_definition (struct macro_source_file
*file
, int line
,
21546 /* The body string takes one of two forms. For object-like macro
21547 definitions, it should be:
21549 <macro name> " " <definition>
21551 For function-like macro definitions, it should be:
21553 <macro name> "() " <definition>
21555 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
21557 Spaces may appear only where explicitly indicated, and in the
21560 The Dwarf 2 spec says that an object-like macro's name is always
21561 followed by a space, but versions of GCC around March 2002 omit
21562 the space when the macro's definition is the empty string.
21564 The Dwarf 2 spec says that there should be no spaces between the
21565 formal arguments in a function-like macro's formal argument list,
21566 but versions of GCC around March 2002 include spaces after the
21570 /* Find the extent of the macro name. The macro name is terminated
21571 by either a space or null character (for an object-like macro) or
21572 an opening paren (for a function-like macro). */
21573 for (p
= body
; *p
; p
++)
21574 if (*p
== ' ' || *p
== '(')
21577 if (*p
== ' ' || *p
== '\0')
21579 /* It's an object-like macro. */
21580 int name_len
= p
- body
;
21581 char *name
= copy_string (body
, name_len
);
21582 const char *replacement
;
21585 replacement
= body
+ name_len
+ 1;
21588 dwarf2_macro_malformed_definition_complaint (body
);
21589 replacement
= body
+ name_len
;
21592 macro_define_object (file
, line
, name
, replacement
);
21596 else if (*p
== '(')
21598 /* It's a function-like macro. */
21599 char *name
= copy_string (body
, p
- body
);
21602 char **argv
= XNEWVEC (char *, argv_size
);
21606 p
= consume_improper_spaces (p
, body
);
21608 /* Parse the formal argument list. */
21609 while (*p
&& *p
!= ')')
21611 /* Find the extent of the current argument name. */
21612 const char *arg_start
= p
;
21614 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
21617 if (! *p
|| p
== arg_start
)
21618 dwarf2_macro_malformed_definition_complaint (body
);
21621 /* Make sure argv has room for the new argument. */
21622 if (argc
>= argv_size
)
21625 argv
= XRESIZEVEC (char *, argv
, argv_size
);
21628 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
21631 p
= consume_improper_spaces (p
, body
);
21633 /* Consume the comma, if present. */
21638 p
= consume_improper_spaces (p
, body
);
21647 /* Perfectly formed definition, no complaints. */
21648 macro_define_function (file
, line
, name
,
21649 argc
, (const char **) argv
,
21651 else if (*p
== '\0')
21653 /* Complain, but do define it. */
21654 dwarf2_macro_malformed_definition_complaint (body
);
21655 macro_define_function (file
, line
, name
,
21656 argc
, (const char **) argv
,
21660 /* Just complain. */
21661 dwarf2_macro_malformed_definition_complaint (body
);
21664 /* Just complain. */
21665 dwarf2_macro_malformed_definition_complaint (body
);
21671 for (i
= 0; i
< argc
; i
++)
21677 dwarf2_macro_malformed_definition_complaint (body
);
21680 /* Skip some bytes from BYTES according to the form given in FORM.
21681 Returns the new pointer. */
21683 static const gdb_byte
*
21684 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
21685 enum dwarf_form form
,
21686 unsigned int offset_size
,
21687 struct dwarf2_section_info
*section
)
21689 unsigned int bytes_read
;
21693 case DW_FORM_data1
:
21698 case DW_FORM_data2
:
21702 case DW_FORM_data4
:
21706 case DW_FORM_data8
:
21710 case DW_FORM_data16
:
21714 case DW_FORM_string
:
21715 read_direct_string (abfd
, bytes
, &bytes_read
);
21716 bytes
+= bytes_read
;
21719 case DW_FORM_sec_offset
:
21721 case DW_FORM_GNU_strp_alt
:
21722 bytes
+= offset_size
;
21725 case DW_FORM_block
:
21726 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
21727 bytes
+= bytes_read
;
21730 case DW_FORM_block1
:
21731 bytes
+= 1 + read_1_byte (abfd
, bytes
);
21733 case DW_FORM_block2
:
21734 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
21736 case DW_FORM_block4
:
21737 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
21740 case DW_FORM_sdata
:
21741 case DW_FORM_udata
:
21742 case DW_FORM_GNU_addr_index
:
21743 case DW_FORM_GNU_str_index
:
21744 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
21747 dwarf2_section_buffer_overflow_complaint (section
);
21755 complaint (&symfile_complaints
,
21756 _("invalid form 0x%x in `%s'"),
21757 form
, get_section_name (section
));
21765 /* A helper for dwarf_decode_macros that handles skipping an unknown
21766 opcode. Returns an updated pointer to the macro data buffer; or,
21767 on error, issues a complaint and returns NULL. */
21769 static const gdb_byte
*
21770 skip_unknown_opcode (unsigned int opcode
,
21771 const gdb_byte
**opcode_definitions
,
21772 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
21774 unsigned int offset_size
,
21775 struct dwarf2_section_info
*section
)
21777 unsigned int bytes_read
, i
;
21779 const gdb_byte
*defn
;
21781 if (opcode_definitions
[opcode
] == NULL
)
21783 complaint (&symfile_complaints
,
21784 _("unrecognized DW_MACFINO opcode 0x%x"),
21789 defn
= opcode_definitions
[opcode
];
21790 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
21791 defn
+= bytes_read
;
21793 for (i
= 0; i
< arg
; ++i
)
21795 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
21796 (enum dwarf_form
) defn
[i
], offset_size
,
21798 if (mac_ptr
== NULL
)
21800 /* skip_form_bytes already issued the complaint. */
21808 /* A helper function which parses the header of a macro section.
21809 If the macro section is the extended (for now called "GNU") type,
21810 then this updates *OFFSET_SIZE. Returns a pointer to just after
21811 the header, or issues a complaint and returns NULL on error. */
21813 static const gdb_byte
*
21814 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
21816 const gdb_byte
*mac_ptr
,
21817 unsigned int *offset_size
,
21818 int section_is_gnu
)
21820 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
21822 if (section_is_gnu
)
21824 unsigned int version
, flags
;
21826 version
= read_2_bytes (abfd
, mac_ptr
);
21827 if (version
!= 4 && version
!= 5)
21829 complaint (&symfile_complaints
,
21830 _("unrecognized version `%d' in .debug_macro section"),
21836 flags
= read_1_byte (abfd
, mac_ptr
);
21838 *offset_size
= (flags
& 1) ? 8 : 4;
21840 if ((flags
& 2) != 0)
21841 /* We don't need the line table offset. */
21842 mac_ptr
+= *offset_size
;
21844 /* Vendor opcode descriptions. */
21845 if ((flags
& 4) != 0)
21847 unsigned int i
, count
;
21849 count
= read_1_byte (abfd
, mac_ptr
);
21851 for (i
= 0; i
< count
; ++i
)
21853 unsigned int opcode
, bytes_read
;
21856 opcode
= read_1_byte (abfd
, mac_ptr
);
21858 opcode_definitions
[opcode
] = mac_ptr
;
21859 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21860 mac_ptr
+= bytes_read
;
21869 /* A helper for dwarf_decode_macros that handles the GNU extensions,
21870 including DW_MACRO_import. */
21873 dwarf_decode_macro_bytes (bfd
*abfd
,
21874 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
21875 struct macro_source_file
*current_file
,
21876 struct line_header
*lh
,
21877 struct dwarf2_section_info
*section
,
21878 int section_is_gnu
, int section_is_dwz
,
21879 unsigned int offset_size
,
21880 htab_t include_hash
)
21882 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21883 enum dwarf_macro_record_type macinfo_type
;
21884 int at_commandline
;
21885 const gdb_byte
*opcode_definitions
[256];
21887 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
21888 &offset_size
, section_is_gnu
);
21889 if (mac_ptr
== NULL
)
21891 /* We already issued a complaint. */
21895 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
21896 GDB is still reading the definitions from command line. First
21897 DW_MACINFO_start_file will need to be ignored as it was already executed
21898 to create CURRENT_FILE for the main source holding also the command line
21899 definitions. On first met DW_MACINFO_start_file this flag is reset to
21900 normally execute all the remaining DW_MACINFO_start_file macinfos. */
21902 at_commandline
= 1;
21906 /* Do we at least have room for a macinfo type byte? */
21907 if (mac_ptr
>= mac_end
)
21909 dwarf2_section_buffer_overflow_complaint (section
);
21913 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
21916 /* Note that we rely on the fact that the corresponding GNU and
21917 DWARF constants are the same. */
21918 switch (macinfo_type
)
21920 /* A zero macinfo type indicates the end of the macro
21925 case DW_MACRO_define
:
21926 case DW_MACRO_undef
:
21927 case DW_MACRO_define_strp
:
21928 case DW_MACRO_undef_strp
:
21929 case DW_MACRO_define_sup
:
21930 case DW_MACRO_undef_sup
:
21932 unsigned int bytes_read
;
21937 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21938 mac_ptr
+= bytes_read
;
21940 if (macinfo_type
== DW_MACRO_define
21941 || macinfo_type
== DW_MACRO_undef
)
21943 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
21944 mac_ptr
+= bytes_read
;
21948 LONGEST str_offset
;
21950 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
21951 mac_ptr
+= offset_size
;
21953 if (macinfo_type
== DW_MACRO_define_sup
21954 || macinfo_type
== DW_MACRO_undef_sup
21957 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
21959 body
= read_indirect_string_from_dwz (dwz
, str_offset
);
21962 body
= read_indirect_string_at_offset (abfd
, str_offset
);
21965 is_define
= (macinfo_type
== DW_MACRO_define
21966 || macinfo_type
== DW_MACRO_define_strp
21967 || macinfo_type
== DW_MACRO_define_sup
);
21968 if (! current_file
)
21970 /* DWARF violation as no main source is present. */
21971 complaint (&symfile_complaints
,
21972 _("debug info with no main source gives macro %s "
21974 is_define
? _("definition") : _("undefinition"),
21978 if ((line
== 0 && !at_commandline
)
21979 || (line
!= 0 && at_commandline
))
21980 complaint (&symfile_complaints
,
21981 _("debug info gives %s macro %s with %s line %d: %s"),
21982 at_commandline
? _("command-line") : _("in-file"),
21983 is_define
? _("definition") : _("undefinition"),
21984 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
21987 parse_macro_definition (current_file
, line
, body
);
21990 gdb_assert (macinfo_type
== DW_MACRO_undef
21991 || macinfo_type
== DW_MACRO_undef_strp
21992 || macinfo_type
== DW_MACRO_undef_sup
);
21993 macro_undef (current_file
, line
, body
);
21998 case DW_MACRO_start_file
:
22000 unsigned int bytes_read
;
22003 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22004 mac_ptr
+= bytes_read
;
22005 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22006 mac_ptr
+= bytes_read
;
22008 if ((line
== 0 && !at_commandline
)
22009 || (line
!= 0 && at_commandline
))
22010 complaint (&symfile_complaints
,
22011 _("debug info gives source %d included "
22012 "from %s at %s line %d"),
22013 file
, at_commandline
? _("command-line") : _("file"),
22014 line
== 0 ? _("zero") : _("non-zero"), line
);
22016 if (at_commandline
)
22018 /* This DW_MACRO_start_file was executed in the
22020 at_commandline
= 0;
22023 current_file
= macro_start_file (file
, line
, current_file
, lh
);
22027 case DW_MACRO_end_file
:
22028 if (! current_file
)
22029 complaint (&symfile_complaints
,
22030 _("macro debug info has an unmatched "
22031 "`close_file' directive"));
22034 current_file
= current_file
->included_by
;
22035 if (! current_file
)
22037 enum dwarf_macro_record_type next_type
;
22039 /* GCC circa March 2002 doesn't produce the zero
22040 type byte marking the end of the compilation
22041 unit. Complain if it's not there, but exit no
22044 /* Do we at least have room for a macinfo type byte? */
22045 if (mac_ptr
>= mac_end
)
22047 dwarf2_section_buffer_overflow_complaint (section
);
22051 /* We don't increment mac_ptr here, so this is just
22054 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
22056 if (next_type
!= 0)
22057 complaint (&symfile_complaints
,
22058 _("no terminating 0-type entry for "
22059 "macros in `.debug_macinfo' section"));
22066 case DW_MACRO_import
:
22067 case DW_MACRO_import_sup
:
22071 bfd
*include_bfd
= abfd
;
22072 struct dwarf2_section_info
*include_section
= section
;
22073 const gdb_byte
*include_mac_end
= mac_end
;
22074 int is_dwz
= section_is_dwz
;
22075 const gdb_byte
*new_mac_ptr
;
22077 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
22078 mac_ptr
+= offset_size
;
22080 if (macinfo_type
== DW_MACRO_import_sup
)
22082 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
22084 dwarf2_read_section (objfile
, &dwz
->macro
);
22086 include_section
= &dwz
->macro
;
22087 include_bfd
= get_section_bfd_owner (include_section
);
22088 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
22092 new_mac_ptr
= include_section
->buffer
+ offset
;
22093 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
22097 /* This has actually happened; see
22098 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
22099 complaint (&symfile_complaints
,
22100 _("recursive DW_MACRO_import in "
22101 ".debug_macro section"));
22105 *slot
= (void *) new_mac_ptr
;
22107 dwarf_decode_macro_bytes (include_bfd
, new_mac_ptr
,
22108 include_mac_end
, current_file
, lh
,
22109 section
, section_is_gnu
, is_dwz
,
22110 offset_size
, include_hash
);
22112 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
22117 case DW_MACINFO_vendor_ext
:
22118 if (!section_is_gnu
)
22120 unsigned int bytes_read
;
22122 /* This reads the constant, but since we don't recognize
22123 any vendor extensions, we ignore it. */
22124 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22125 mac_ptr
+= bytes_read
;
22126 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
22127 mac_ptr
+= bytes_read
;
22129 /* We don't recognize any vendor extensions. */
22135 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
22136 mac_ptr
, mac_end
, abfd
, offset_size
,
22138 if (mac_ptr
== NULL
)
22142 } while (macinfo_type
!= 0);
22146 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
22147 int section_is_gnu
)
22149 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22150 struct line_header
*lh
= cu
->line_header
;
22152 const gdb_byte
*mac_ptr
, *mac_end
;
22153 struct macro_source_file
*current_file
= 0;
22154 enum dwarf_macro_record_type macinfo_type
;
22155 unsigned int offset_size
= cu
->header
.offset_size
;
22156 const gdb_byte
*opcode_definitions
[256];
22157 struct cleanup
*cleanup
;
22159 struct dwarf2_section_info
*section
;
22160 const char *section_name
;
22162 if (cu
->dwo_unit
!= NULL
)
22164 if (section_is_gnu
)
22166 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
22167 section_name
= ".debug_macro.dwo";
22171 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
22172 section_name
= ".debug_macinfo.dwo";
22177 if (section_is_gnu
)
22179 section
= &dwarf2_per_objfile
->macro
;
22180 section_name
= ".debug_macro";
22184 section
= &dwarf2_per_objfile
->macinfo
;
22185 section_name
= ".debug_macinfo";
22189 dwarf2_read_section (objfile
, section
);
22190 if (section
->buffer
== NULL
)
22192 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
22195 abfd
= get_section_bfd_owner (section
);
22197 /* First pass: Find the name of the base filename.
22198 This filename is needed in order to process all macros whose definition
22199 (or undefinition) comes from the command line. These macros are defined
22200 before the first DW_MACINFO_start_file entry, and yet still need to be
22201 associated to the base file.
22203 To determine the base file name, we scan the macro definitions until we
22204 reach the first DW_MACINFO_start_file entry. We then initialize
22205 CURRENT_FILE accordingly so that any macro definition found before the
22206 first DW_MACINFO_start_file can still be associated to the base file. */
22208 mac_ptr
= section
->buffer
+ offset
;
22209 mac_end
= section
->buffer
+ section
->size
;
22211 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
22212 &offset_size
, section_is_gnu
);
22213 if (mac_ptr
== NULL
)
22215 /* We already issued a complaint. */
22221 /* Do we at least have room for a macinfo type byte? */
22222 if (mac_ptr
>= mac_end
)
22224 /* Complaint is printed during the second pass as GDB will probably
22225 stop the first pass earlier upon finding
22226 DW_MACINFO_start_file. */
22230 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
22233 /* Note that we rely on the fact that the corresponding GNU and
22234 DWARF constants are the same. */
22235 switch (macinfo_type
)
22237 /* A zero macinfo type indicates the end of the macro
22242 case DW_MACRO_define
:
22243 case DW_MACRO_undef
:
22244 /* Only skip the data by MAC_PTR. */
22246 unsigned int bytes_read
;
22248 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22249 mac_ptr
+= bytes_read
;
22250 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
22251 mac_ptr
+= bytes_read
;
22255 case DW_MACRO_start_file
:
22257 unsigned int bytes_read
;
22260 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22261 mac_ptr
+= bytes_read
;
22262 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22263 mac_ptr
+= bytes_read
;
22265 current_file
= macro_start_file (file
, line
, current_file
, lh
);
22269 case DW_MACRO_end_file
:
22270 /* No data to skip by MAC_PTR. */
22273 case DW_MACRO_define_strp
:
22274 case DW_MACRO_undef_strp
:
22275 case DW_MACRO_define_sup
:
22276 case DW_MACRO_undef_sup
:
22278 unsigned int bytes_read
;
22280 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22281 mac_ptr
+= bytes_read
;
22282 mac_ptr
+= offset_size
;
22286 case DW_MACRO_import
:
22287 case DW_MACRO_import_sup
:
22288 /* Note that, according to the spec, a transparent include
22289 chain cannot call DW_MACRO_start_file. So, we can just
22290 skip this opcode. */
22291 mac_ptr
+= offset_size
;
22294 case DW_MACINFO_vendor_ext
:
22295 /* Only skip the data by MAC_PTR. */
22296 if (!section_is_gnu
)
22298 unsigned int bytes_read
;
22300 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
22301 mac_ptr
+= bytes_read
;
22302 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
22303 mac_ptr
+= bytes_read
;
22308 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
22309 mac_ptr
, mac_end
, abfd
, offset_size
,
22311 if (mac_ptr
== NULL
)
22315 } while (macinfo_type
!= 0 && current_file
== NULL
);
22317 /* Second pass: Process all entries.
22319 Use the AT_COMMAND_LINE flag to determine whether we are still processing
22320 command-line macro definitions/undefinitions. This flag is unset when we
22321 reach the first DW_MACINFO_start_file entry. */
22323 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
22325 NULL
, xcalloc
, xfree
));
22326 mac_ptr
= section
->buffer
+ offset
;
22327 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
22328 *slot
= (void *) mac_ptr
;
22329 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
22330 current_file
, lh
, section
,
22331 section_is_gnu
, 0, offset_size
,
22332 include_hash
.get ());
22335 /* Check if the attribute's form is a DW_FORM_block*
22336 if so return true else false. */
22339 attr_form_is_block (const struct attribute
*attr
)
22341 return (attr
== NULL
? 0 :
22342 attr
->form
== DW_FORM_block1
22343 || attr
->form
== DW_FORM_block2
22344 || attr
->form
== DW_FORM_block4
22345 || attr
->form
== DW_FORM_block
22346 || attr
->form
== DW_FORM_exprloc
);
22349 /* Return non-zero if ATTR's value is a section offset --- classes
22350 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
22351 You may use DW_UNSND (attr) to retrieve such offsets.
22353 Section 7.5.4, "Attribute Encodings", explains that no attribute
22354 may have a value that belongs to more than one of these classes; it
22355 would be ambiguous if we did, because we use the same forms for all
22359 attr_form_is_section_offset (const struct attribute
*attr
)
22361 return (attr
->form
== DW_FORM_data4
22362 || attr
->form
== DW_FORM_data8
22363 || attr
->form
== DW_FORM_sec_offset
);
22366 /* Return non-zero if ATTR's value falls in the 'constant' class, or
22367 zero otherwise. When this function returns true, you can apply
22368 dwarf2_get_attr_constant_value to it.
22370 However, note that for some attributes you must check
22371 attr_form_is_section_offset before using this test. DW_FORM_data4
22372 and DW_FORM_data8 are members of both the constant class, and of
22373 the classes that contain offsets into other debug sections
22374 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
22375 that, if an attribute's can be either a constant or one of the
22376 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
22377 taken as section offsets, not constants.
22379 DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
22380 cannot handle that. */
22383 attr_form_is_constant (const struct attribute
*attr
)
22385 switch (attr
->form
)
22387 case DW_FORM_sdata
:
22388 case DW_FORM_udata
:
22389 case DW_FORM_data1
:
22390 case DW_FORM_data2
:
22391 case DW_FORM_data4
:
22392 case DW_FORM_data8
:
22400 /* DW_ADDR is always stored already as sect_offset; despite for the forms
22401 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
22404 attr_form_is_ref (const struct attribute
*attr
)
22406 switch (attr
->form
)
22408 case DW_FORM_ref_addr
:
22413 case DW_FORM_ref_udata
:
22414 case DW_FORM_GNU_ref_alt
:
22421 /* Return the .debug_loc section to use for CU.
22422 For DWO files use .debug_loc.dwo. */
22424 static struct dwarf2_section_info
*
22425 cu_debug_loc_section (struct dwarf2_cu
*cu
)
22429 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
22431 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
22433 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
22434 : &dwarf2_per_objfile
->loc
);
22437 /* A helper function that fills in a dwarf2_loclist_baton. */
22440 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
22441 struct dwarf2_loclist_baton
*baton
,
22442 const struct attribute
*attr
)
22444 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
22446 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
22448 baton
->per_cu
= cu
->per_cu
;
22449 gdb_assert (baton
->per_cu
);
22450 /* We don't know how long the location list is, but make sure we
22451 don't run off the edge of the section. */
22452 baton
->size
= section
->size
- DW_UNSND (attr
);
22453 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
22454 baton
->base_address
= cu
->base_address
;
22455 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
22459 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
22460 struct dwarf2_cu
*cu
, int is_block
)
22462 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22463 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
22465 if (attr_form_is_section_offset (attr
)
22466 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
22467 the section. If so, fall through to the complaint in the
22469 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
22471 struct dwarf2_loclist_baton
*baton
;
22473 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
22475 fill_in_loclist_baton (cu
, baton
, attr
);
22477 if (cu
->base_known
== 0)
22478 complaint (&symfile_complaints
,
22479 _("Location list used without "
22480 "specifying the CU base address."));
22482 SYMBOL_ACLASS_INDEX (sym
) = (is_block
22483 ? dwarf2_loclist_block_index
22484 : dwarf2_loclist_index
);
22485 SYMBOL_LOCATION_BATON (sym
) = baton
;
22489 struct dwarf2_locexpr_baton
*baton
;
22491 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
22492 baton
->per_cu
= cu
->per_cu
;
22493 gdb_assert (baton
->per_cu
);
22495 if (attr_form_is_block (attr
))
22497 /* Note that we're just copying the block's data pointer
22498 here, not the actual data. We're still pointing into the
22499 info_buffer for SYM's objfile; right now we never release
22500 that buffer, but when we do clean up properly this may
22502 baton
->size
= DW_BLOCK (attr
)->size
;
22503 baton
->data
= DW_BLOCK (attr
)->data
;
22507 dwarf2_invalid_attrib_class_complaint ("location description",
22508 SYMBOL_NATURAL_NAME (sym
));
22512 SYMBOL_ACLASS_INDEX (sym
) = (is_block
22513 ? dwarf2_locexpr_block_index
22514 : dwarf2_locexpr_index
);
22515 SYMBOL_LOCATION_BATON (sym
) = baton
;
22519 /* Return the OBJFILE associated with the compilation unit CU. If CU
22520 came from a separate debuginfo file, then the master objfile is
22524 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
22526 struct objfile
*objfile
= per_cu
->objfile
;
22528 /* Return the master objfile, so that we can report and look up the
22529 correct file containing this variable. */
22530 if (objfile
->separate_debug_objfile_backlink
)
22531 objfile
= objfile
->separate_debug_objfile_backlink
;
22536 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
22537 (CU_HEADERP is unused in such case) or prepare a temporary copy at
22538 CU_HEADERP first. */
22540 static const struct comp_unit_head
*
22541 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
22542 struct dwarf2_per_cu_data
*per_cu
)
22544 const gdb_byte
*info_ptr
;
22547 return &per_cu
->cu
->header
;
22549 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
22551 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
22552 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
22553 rcuh_kind::COMPILE
);
22558 /* Return the address size given in the compilation unit header for CU. */
22561 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
22563 struct comp_unit_head cu_header_local
;
22564 const struct comp_unit_head
*cu_headerp
;
22566 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
22568 return cu_headerp
->addr_size
;
22571 /* Return the offset size given in the compilation unit header for CU. */
22574 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
22576 struct comp_unit_head cu_header_local
;
22577 const struct comp_unit_head
*cu_headerp
;
22579 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
22581 return cu_headerp
->offset_size
;
22584 /* See its dwarf2loc.h declaration. */
22587 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
22589 struct comp_unit_head cu_header_local
;
22590 const struct comp_unit_head
*cu_headerp
;
22592 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
22594 if (cu_headerp
->version
== 2)
22595 return cu_headerp
->addr_size
;
22597 return cu_headerp
->offset_size
;
22600 /* Return the text offset of the CU. The returned offset comes from
22601 this CU's objfile. If this objfile came from a separate debuginfo
22602 file, then the offset may be different from the corresponding
22603 offset in the parent objfile. */
22606 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
22608 struct objfile
*objfile
= per_cu
->objfile
;
22610 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
22613 /* Return DWARF version number of PER_CU. */
22616 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
22618 return per_cu
->dwarf_version
;
22621 /* Locate the .debug_info compilation unit from CU's objfile which contains
22622 the DIE at OFFSET. Raises an error on failure. */
22624 static struct dwarf2_per_cu_data
*
22625 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
22626 unsigned int offset_in_dwz
,
22627 struct objfile
*objfile
)
22629 struct dwarf2_per_cu_data
*this_cu
;
22631 const sect_offset
*cu_off
;
22634 high
= dwarf2_per_objfile
->n_comp_units
- 1;
22637 struct dwarf2_per_cu_data
*mid_cu
;
22638 int mid
= low
+ (high
- low
) / 2;
22640 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
22641 cu_off
= &mid_cu
->sect_off
;
22642 if (mid_cu
->is_dwz
> offset_in_dwz
22643 || (mid_cu
->is_dwz
== offset_in_dwz
&& *cu_off
>= sect_off
))
22648 gdb_assert (low
== high
);
22649 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
22650 cu_off
= &this_cu
->sect_off
;
22651 if (this_cu
->is_dwz
!= offset_in_dwz
|| *cu_off
> sect_off
)
22653 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
22654 error (_("Dwarf Error: could not find partial DIE containing "
22655 "offset 0x%x [in module %s]"),
22656 to_underlying (sect_off
), bfd_get_filename (objfile
->obfd
));
22658 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
22660 return dwarf2_per_objfile
->all_comp_units
[low
-1];
22664 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
22665 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
22666 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
22667 error (_("invalid dwarf2 offset %u"), to_underlying (sect_off
));
22668 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
22673 /* Initialize dwarf2_cu CU, owned by PER_CU. */
22676 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
22678 memset (cu
, 0, sizeof (*cu
));
22680 cu
->per_cu
= per_cu
;
22681 cu
->objfile
= per_cu
->objfile
;
22682 obstack_init (&cu
->comp_unit_obstack
);
22685 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
22688 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
22689 enum language pretend_language
)
22691 struct attribute
*attr
;
22693 /* Set the language we're debugging. */
22694 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
22696 set_cu_language (DW_UNSND (attr
), cu
);
22699 cu
->language
= pretend_language
;
22700 cu
->language_defn
= language_def (cu
->language
);
22703 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
22706 /* Release one cached compilation unit, CU. We unlink it from the tree
22707 of compilation units, but we don't remove it from the read_in_chain;
22708 the caller is responsible for that.
22709 NOTE: DATA is a void * because this function is also used as a
22710 cleanup routine. */
22713 free_heap_comp_unit (void *data
)
22715 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) data
;
22717 gdb_assert (cu
->per_cu
!= NULL
);
22718 cu
->per_cu
->cu
= NULL
;
22721 obstack_free (&cu
->comp_unit_obstack
, NULL
);
22726 /* This cleanup function is passed the address of a dwarf2_cu on the stack
22727 when we're finished with it. We can't free the pointer itself, but be
22728 sure to unlink it from the cache. Also release any associated storage. */
22731 free_stack_comp_unit (void *data
)
22733 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) data
;
22735 gdb_assert (cu
->per_cu
!= NULL
);
22736 cu
->per_cu
->cu
= NULL
;
22739 obstack_free (&cu
->comp_unit_obstack
, NULL
);
22740 cu
->partial_dies
= NULL
;
22743 /* Free all cached compilation units. */
22746 free_cached_comp_units (void *data
)
22748 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
22750 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22751 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
22752 while (per_cu
!= NULL
)
22754 struct dwarf2_per_cu_data
*next_cu
;
22756 next_cu
= per_cu
->cu
->read_in_chain
;
22758 free_heap_comp_unit (per_cu
->cu
);
22759 *last_chain
= next_cu
;
22765 /* Increase the age counter on each cached compilation unit, and free
22766 any that are too old. */
22769 age_cached_comp_units (void)
22771 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
22773 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
22774 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22775 while (per_cu
!= NULL
)
22777 per_cu
->cu
->last_used
++;
22778 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
22779 dwarf2_mark (per_cu
->cu
);
22780 per_cu
= per_cu
->cu
->read_in_chain
;
22783 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22784 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
22785 while (per_cu
!= NULL
)
22787 struct dwarf2_per_cu_data
*next_cu
;
22789 next_cu
= per_cu
->cu
->read_in_chain
;
22791 if (!per_cu
->cu
->mark
)
22793 free_heap_comp_unit (per_cu
->cu
);
22794 *last_chain
= next_cu
;
22797 last_chain
= &per_cu
->cu
->read_in_chain
;
22803 /* Remove a single compilation unit from the cache. */
22806 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
22808 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
22810 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22811 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
22812 while (per_cu
!= NULL
)
22814 struct dwarf2_per_cu_data
*next_cu
;
22816 next_cu
= per_cu
->cu
->read_in_chain
;
22818 if (per_cu
== target_per_cu
)
22820 free_heap_comp_unit (per_cu
->cu
);
22822 *last_chain
= next_cu
;
22826 last_chain
= &per_cu
->cu
->read_in_chain
;
22832 /* Release all extra memory associated with OBJFILE. */
22835 dwarf2_free_objfile (struct objfile
*objfile
)
22838 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
22839 dwarf2_objfile_data_key
);
22841 if (dwarf2_per_objfile
== NULL
)
22844 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
22845 free_cached_comp_units (NULL
);
22847 if (dwarf2_per_objfile
->quick_file_names_table
)
22848 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
22850 if (dwarf2_per_objfile
->line_header_hash
)
22851 htab_delete (dwarf2_per_objfile
->line_header_hash
);
22853 /* Everything else should be on the objfile obstack. */
22856 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
22857 We store these in a hash table separate from the DIEs, and preserve them
22858 when the DIEs are flushed out of cache.
22860 The CU "per_cu" pointer is needed because offset alone is not enough to
22861 uniquely identify the type. A file may have multiple .debug_types sections,
22862 or the type may come from a DWO file. Furthermore, while it's more logical
22863 to use per_cu->section+offset, with Fission the section with the data is in
22864 the DWO file but we don't know that section at the point we need it.
22865 We have to use something in dwarf2_per_cu_data (or the pointer to it)
22866 because we can enter the lookup routine, get_die_type_at_offset, from
22867 outside this file, and thus won't necessarily have PER_CU->cu.
22868 Fortunately, PER_CU is stable for the life of the objfile. */
22870 struct dwarf2_per_cu_offset_and_type
22872 const struct dwarf2_per_cu_data
*per_cu
;
22873 sect_offset sect_off
;
22877 /* Hash function for a dwarf2_per_cu_offset_and_type. */
22880 per_cu_offset_and_type_hash (const void *item
)
22882 const struct dwarf2_per_cu_offset_and_type
*ofs
22883 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
22885 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
22888 /* Equality function for a dwarf2_per_cu_offset_and_type. */
22891 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
22893 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
22894 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
22895 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
22896 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
22898 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
22899 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
22902 /* Set the type associated with DIE to TYPE. Save it in CU's hash
22903 table if necessary. For convenience, return TYPE.
22905 The DIEs reading must have careful ordering to:
22906 * Not cause infite loops trying to read in DIEs as a prerequisite for
22907 reading current DIE.
22908 * Not trying to dereference contents of still incompletely read in types
22909 while reading in other DIEs.
22910 * Enable referencing still incompletely read in types just by a pointer to
22911 the type without accessing its fields.
22913 Therefore caller should follow these rules:
22914 * Try to fetch any prerequisite types we may need to build this DIE type
22915 before building the type and calling set_die_type.
22916 * After building type call set_die_type for current DIE as soon as
22917 possible before fetching more types to complete the current type.
22918 * Make the type as complete as possible before fetching more types. */
22920 static struct type
*
22921 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
22923 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
22924 struct objfile
*objfile
= cu
->objfile
;
22925 struct attribute
*attr
;
22926 struct dynamic_prop prop
;
22928 /* For Ada types, make sure that the gnat-specific data is always
22929 initialized (if not already set). There are a few types where
22930 we should not be doing so, because the type-specific area is
22931 already used to hold some other piece of info (eg: TYPE_CODE_FLT
22932 where the type-specific area is used to store the floatformat).
22933 But this is not a problem, because the gnat-specific information
22934 is actually not needed for these types. */
22935 if (need_gnat_info (cu
)
22936 && TYPE_CODE (type
) != TYPE_CODE_FUNC
22937 && TYPE_CODE (type
) != TYPE_CODE_FLT
22938 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
22939 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
22940 && TYPE_CODE (type
) != TYPE_CODE_METHOD
22941 && !HAVE_GNAT_AUX_INFO (type
))
22942 INIT_GNAT_SPECIFIC (type
);
22944 /* Read DW_AT_allocated and set in type. */
22945 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
22946 if (attr_form_is_block (attr
))
22948 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
22949 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
, objfile
);
22951 else if (attr
!= NULL
)
22953 complaint (&symfile_complaints
,
22954 _("DW_AT_allocated has the wrong form (%s) at DIE 0x%x"),
22955 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
22956 to_underlying (die
->sect_off
));
22959 /* Read DW_AT_associated and set in type. */
22960 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
22961 if (attr_form_is_block (attr
))
22963 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
22964 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
, objfile
);
22966 else if (attr
!= NULL
)
22968 complaint (&symfile_complaints
,
22969 _("DW_AT_associated has the wrong form (%s) at DIE 0x%x"),
22970 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
22971 to_underlying (die
->sect_off
));
22974 /* Read DW_AT_data_location and set in type. */
22975 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
22976 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
22977 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
, objfile
);
22979 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
22981 dwarf2_per_objfile
->die_type_hash
=
22982 htab_create_alloc_ex (127,
22983 per_cu_offset_and_type_hash
,
22984 per_cu_offset_and_type_eq
,
22986 &objfile
->objfile_obstack
,
22987 hashtab_obstack_allocate
,
22988 dummy_obstack_deallocate
);
22991 ofs
.per_cu
= cu
->per_cu
;
22992 ofs
.sect_off
= die
->sect_off
;
22994 slot
= (struct dwarf2_per_cu_offset_and_type
**)
22995 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
22997 complaint (&symfile_complaints
,
22998 _("A problem internal to GDB: DIE 0x%x has type already set"),
22999 to_underlying (die
->sect_off
));
23000 *slot
= XOBNEW (&objfile
->objfile_obstack
,
23001 struct dwarf2_per_cu_offset_and_type
);
23006 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
23007 or return NULL if the die does not have a saved type. */
23009 static struct type
*
23010 get_die_type_at_offset (sect_offset sect_off
,
23011 struct dwarf2_per_cu_data
*per_cu
)
23013 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
23015 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23018 ofs
.per_cu
= per_cu
;
23019 ofs
.sect_off
= sect_off
;
23020 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
23021 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
23028 /* Look up the type for DIE in CU in die_type_hash,
23029 or return NULL if DIE does not have a saved type. */
23031 static struct type
*
23032 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
23034 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
23037 /* Add a dependence relationship from CU to REF_PER_CU. */
23040 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
23041 struct dwarf2_per_cu_data
*ref_per_cu
)
23045 if (cu
->dependencies
== NULL
)
23047 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
23048 NULL
, &cu
->comp_unit_obstack
,
23049 hashtab_obstack_allocate
,
23050 dummy_obstack_deallocate
);
23052 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
23054 *slot
= ref_per_cu
;
23057 /* Subroutine of dwarf2_mark to pass to htab_traverse.
23058 Set the mark field in every compilation unit in the
23059 cache that we must keep because we are keeping CU. */
23062 dwarf2_mark_helper (void **slot
, void *data
)
23064 struct dwarf2_per_cu_data
*per_cu
;
23066 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
23068 /* cu->dependencies references may not yet have been ever read if QUIT aborts
23069 reading of the chain. As such dependencies remain valid it is not much
23070 useful to track and undo them during QUIT cleanups. */
23071 if (per_cu
->cu
== NULL
)
23074 if (per_cu
->cu
->mark
)
23076 per_cu
->cu
->mark
= 1;
23078 if (per_cu
->cu
->dependencies
!= NULL
)
23079 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23084 /* Set the mark field in CU and in every other compilation unit in the
23085 cache that we must keep because we are keeping CU. */
23088 dwarf2_mark (struct dwarf2_cu
*cu
)
23093 if (cu
->dependencies
!= NULL
)
23094 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23098 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
23102 per_cu
->cu
->mark
= 0;
23103 per_cu
= per_cu
->cu
->read_in_chain
;
23107 /* Trivial hash function for partial_die_info: the hash value of a DIE
23108 is its offset in .debug_info for this objfile. */
23111 partial_die_hash (const void *item
)
23113 const struct partial_die_info
*part_die
23114 = (const struct partial_die_info
*) item
;
23116 return to_underlying (part_die
->sect_off
);
23119 /* Trivial comparison function for partial_die_info structures: two DIEs
23120 are equal if they have the same offset. */
23123 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
23125 const struct partial_die_info
*part_die_lhs
23126 = (const struct partial_die_info
*) item_lhs
;
23127 const struct partial_die_info
*part_die_rhs
23128 = (const struct partial_die_info
*) item_rhs
;
23130 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
23133 static struct cmd_list_element
*set_dwarf_cmdlist
;
23134 static struct cmd_list_element
*show_dwarf_cmdlist
;
23137 set_dwarf_cmd (char *args
, int from_tty
)
23139 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
23144 show_dwarf_cmd (char *args
, int from_tty
)
23146 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
23149 /* Free data associated with OBJFILE, if necessary. */
23152 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
23154 struct dwarf2_per_objfile
*data
= (struct dwarf2_per_objfile
*) d
;
23157 /* Make sure we don't accidentally use dwarf2_per_objfile while
23159 dwarf2_per_objfile
= NULL
;
23161 for (ix
= 0; ix
< data
->n_comp_units
; ++ix
)
23162 VEC_free (dwarf2_per_cu_ptr
, data
->all_comp_units
[ix
]->imported_symtabs
);
23164 for (ix
= 0; ix
< data
->n_type_units
; ++ix
)
23165 VEC_free (dwarf2_per_cu_ptr
,
23166 data
->all_type_units
[ix
]->per_cu
.imported_symtabs
);
23167 xfree (data
->all_type_units
);
23169 VEC_free (dwarf2_section_info_def
, data
->types
);
23171 if (data
->dwo_files
)
23172 free_dwo_files (data
->dwo_files
, objfile
);
23173 if (data
->dwp_file
)
23174 gdb_bfd_unref (data
->dwp_file
->dbfd
);
23176 if (data
->dwz_file
&& data
->dwz_file
->dwz_bfd
)
23177 gdb_bfd_unref (data
->dwz_file
->dwz_bfd
);
23181 /* The "save gdb-index" command. */
23183 /* The contents of the hash table we create when building the string
23185 struct strtab_entry
23187 offset_type offset
;
23191 /* Hash function for a strtab_entry.
23193 Function is used only during write_hash_table so no index format backward
23194 compatibility is needed. */
23197 hash_strtab_entry (const void *e
)
23199 const struct strtab_entry
*entry
= (const struct strtab_entry
*) e
;
23200 return mapped_index_string_hash (INT_MAX
, entry
->str
);
23203 /* Equality function for a strtab_entry. */
23206 eq_strtab_entry (const void *a
, const void *b
)
23208 const struct strtab_entry
*ea
= (const struct strtab_entry
*) a
;
23209 const struct strtab_entry
*eb
= (const struct strtab_entry
*) b
;
23210 return !strcmp (ea
->str
, eb
->str
);
23213 /* Create a strtab_entry hash table. */
23216 create_strtab (void)
23218 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
23219 xfree
, xcalloc
, xfree
);
23222 /* Add a string to the constant pool. Return the string's offset in
23226 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
23229 struct strtab_entry entry
;
23230 struct strtab_entry
*result
;
23233 slot
= htab_find_slot (table
, &entry
, INSERT
);
23235 result
= (struct strtab_entry
*) *slot
;
23238 result
= XNEW (struct strtab_entry
);
23239 result
->offset
= obstack_object_size (cpool
);
23241 obstack_grow_str0 (cpool
, str
);
23244 return result
->offset
;
23247 /* An entry in the symbol table. */
23248 struct symtab_index_entry
23250 /* The name of the symbol. */
23252 /* The offset of the name in the constant pool. */
23253 offset_type index_offset
;
23254 /* A sorted vector of the indices of all the CUs that hold an object
23256 VEC (offset_type
) *cu_indices
;
23259 /* The symbol table. This is a power-of-2-sized hash table. */
23260 struct mapped_symtab
23262 offset_type n_elements
;
23264 struct symtab_index_entry
**data
;
23267 /* Hash function for a symtab_index_entry. */
23270 hash_symtab_entry (const void *e
)
23272 const struct symtab_index_entry
*entry
23273 = (const struct symtab_index_entry
*) e
;
23274 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
23275 sizeof (offset_type
) * VEC_length (offset_type
,
23276 entry
->cu_indices
),
23280 /* Equality function for a symtab_index_entry. */
23283 eq_symtab_entry (const void *a
, const void *b
)
23285 const struct symtab_index_entry
*ea
= (const struct symtab_index_entry
*) a
;
23286 const struct symtab_index_entry
*eb
= (const struct symtab_index_entry
*) b
;
23287 int len
= VEC_length (offset_type
, ea
->cu_indices
);
23288 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
23290 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
23291 VEC_address (offset_type
, eb
->cu_indices
),
23292 sizeof (offset_type
) * len
);
23295 /* Destroy a symtab_index_entry. */
23298 delete_symtab_entry (void *p
)
23300 struct symtab_index_entry
*entry
= (struct symtab_index_entry
*) p
;
23301 VEC_free (offset_type
, entry
->cu_indices
);
23305 /* Create a hash table holding symtab_index_entry objects. */
23308 create_symbol_hash_table (void)
23310 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
23311 delete_symtab_entry
, xcalloc
, xfree
);
23314 /* Create a new mapped symtab object. */
23316 static struct mapped_symtab
*
23317 create_mapped_symtab (void)
23319 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
23320 symtab
->n_elements
= 0;
23321 symtab
->size
= 1024;
23322 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
23326 /* Destroy a mapped_symtab. */
23329 cleanup_mapped_symtab (void *p
)
23331 struct mapped_symtab
*symtab
= (struct mapped_symtab
*) p
;
23332 /* The contents of the array are freed when the other hash table is
23334 xfree (symtab
->data
);
23338 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
23341 Function is used only during write_hash_table so no index format backward
23342 compatibility is needed. */
23344 static struct symtab_index_entry
**
23345 find_slot (struct mapped_symtab
*symtab
, const char *name
)
23347 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
23349 index
= hash
& (symtab
->size
- 1);
23350 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
23354 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
23355 return &symtab
->data
[index
];
23356 index
= (index
+ step
) & (symtab
->size
- 1);
23360 /* Expand SYMTAB's hash table. */
23363 hash_expand (struct mapped_symtab
*symtab
)
23365 offset_type old_size
= symtab
->size
;
23367 struct symtab_index_entry
**old_entries
= symtab
->data
;
23370 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
23372 for (i
= 0; i
< old_size
; ++i
)
23374 if (old_entries
[i
])
23376 struct symtab_index_entry
**slot
= find_slot (symtab
,
23377 old_entries
[i
]->name
);
23378 *slot
= old_entries
[i
];
23382 xfree (old_entries
);
23385 /* Add an entry to SYMTAB. NAME is the name of the symbol.
23386 CU_INDEX is the index of the CU in which the symbol appears.
23387 IS_STATIC is one if the symbol is static, otherwise zero (global). */
23390 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
23391 int is_static
, gdb_index_symbol_kind kind
,
23392 offset_type cu_index
)
23394 struct symtab_index_entry
**slot
;
23395 offset_type cu_index_and_attrs
;
23397 ++symtab
->n_elements
;
23398 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
23399 hash_expand (symtab
);
23401 slot
= find_slot (symtab
, name
);
23404 *slot
= XNEW (struct symtab_index_entry
);
23405 (*slot
)->name
= name
;
23406 /* index_offset is set later. */
23407 (*slot
)->cu_indices
= NULL
;
23410 cu_index_and_attrs
= 0;
23411 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
23412 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
23413 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
23415 /* We don't want to record an index value twice as we want to avoid the
23417 We process all global symbols and then all static symbols
23418 (which would allow us to avoid the duplication by only having to check
23419 the last entry pushed), but a symbol could have multiple kinds in one CU.
23420 To keep things simple we don't worry about the duplication here and
23421 sort and uniqufy the list after we've processed all symbols. */
23422 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index_and_attrs
);
23425 /* qsort helper routine for uniquify_cu_indices. */
23428 offset_type_compare (const void *ap
, const void *bp
)
23430 offset_type a
= *(offset_type
*) ap
;
23431 offset_type b
= *(offset_type
*) bp
;
23433 return (a
> b
) - (b
> a
);
23436 /* Sort and remove duplicates of all symbols' cu_indices lists. */
23439 uniquify_cu_indices (struct mapped_symtab
*symtab
)
23443 for (i
= 0; i
< symtab
->size
; ++i
)
23445 struct symtab_index_entry
*entry
= symtab
->data
[i
];
23448 && entry
->cu_indices
!= NULL
)
23450 unsigned int next_to_insert
, next_to_check
;
23451 offset_type last_value
;
23453 qsort (VEC_address (offset_type
, entry
->cu_indices
),
23454 VEC_length (offset_type
, entry
->cu_indices
),
23455 sizeof (offset_type
), offset_type_compare
);
23457 last_value
= VEC_index (offset_type
, entry
->cu_indices
, 0);
23458 next_to_insert
= 1;
23459 for (next_to_check
= 1;
23460 next_to_check
< VEC_length (offset_type
, entry
->cu_indices
);
23463 if (VEC_index (offset_type
, entry
->cu_indices
, next_to_check
)
23466 last_value
= VEC_index (offset_type
, entry
->cu_indices
,
23468 VEC_replace (offset_type
, entry
->cu_indices
, next_to_insert
,
23473 VEC_truncate (offset_type
, entry
->cu_indices
, next_to_insert
);
23478 /* Add a vector of indices to the constant pool. */
23481 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
23482 struct symtab_index_entry
*entry
)
23486 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
23489 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
23490 offset_type val
= MAYBE_SWAP (len
);
23495 entry
->index_offset
= obstack_object_size (cpool
);
23497 obstack_grow (cpool
, &val
, sizeof (val
));
23499 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
23502 val
= MAYBE_SWAP (iter
);
23503 obstack_grow (cpool
, &val
, sizeof (val
));
23508 struct symtab_index_entry
*old_entry
23509 = (struct symtab_index_entry
*) *slot
;
23510 entry
->index_offset
= old_entry
->index_offset
;
23513 return entry
->index_offset
;
23516 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
23517 constant pool entries going into the obstack CPOOL. */
23520 write_hash_table (struct mapped_symtab
*symtab
,
23521 struct obstack
*output
, struct obstack
*cpool
)
23524 htab_t symbol_hash_table
;
23527 symbol_hash_table
= create_symbol_hash_table ();
23528 str_table
= create_strtab ();
23530 /* We add all the index vectors to the constant pool first, to
23531 ensure alignment is ok. */
23532 for (i
= 0; i
< symtab
->size
; ++i
)
23534 if (symtab
->data
[i
])
23535 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
23538 /* Now write out the hash table. */
23539 for (i
= 0; i
< symtab
->size
; ++i
)
23541 offset_type str_off
, vec_off
;
23543 if (symtab
->data
[i
])
23545 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
23546 vec_off
= symtab
->data
[i
]->index_offset
;
23550 /* While 0 is a valid constant pool index, it is not valid
23551 to have 0 for both offsets. */
23556 str_off
= MAYBE_SWAP (str_off
);
23557 vec_off
= MAYBE_SWAP (vec_off
);
23559 obstack_grow (output
, &str_off
, sizeof (str_off
));
23560 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
23563 htab_delete (str_table
);
23564 htab_delete (symbol_hash_table
);
23567 /* Struct to map psymtab to CU index in the index file. */
23568 struct psymtab_cu_index_map
23570 struct partial_symtab
*psymtab
;
23571 unsigned int cu_index
;
23575 hash_psymtab_cu_index (const void *item
)
23577 const struct psymtab_cu_index_map
*map
23578 = (const struct psymtab_cu_index_map
*) item
;
23580 return htab_hash_pointer (map
->psymtab
);
23584 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
23586 const struct psymtab_cu_index_map
*lhs
23587 = (const struct psymtab_cu_index_map
*) item_lhs
;
23588 const struct psymtab_cu_index_map
*rhs
23589 = (const struct psymtab_cu_index_map
*) item_rhs
;
23591 return lhs
->psymtab
== rhs
->psymtab
;
23594 /* Helper struct for building the address table. */
23595 struct addrmap_index_data
23597 struct objfile
*objfile
;
23598 struct obstack
*addr_obstack
;
23599 htab_t cu_index_htab
;
23601 /* Non-zero if the previous_* fields are valid.
23602 We can't write an entry until we see the next entry (since it is only then
23603 that we know the end of the entry). */
23604 int previous_valid
;
23605 /* Index of the CU in the table of all CUs in the index file. */
23606 unsigned int previous_cu_index
;
23607 /* Start address of the CU. */
23608 CORE_ADDR previous_cu_start
;
23611 /* Write an address entry to OBSTACK. */
23614 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
23615 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
23617 offset_type cu_index_to_write
;
23619 CORE_ADDR baseaddr
;
23621 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
23623 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
23624 obstack_grow (obstack
, addr
, 8);
23625 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
23626 obstack_grow (obstack
, addr
, 8);
23627 cu_index_to_write
= MAYBE_SWAP (cu_index
);
23628 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
23631 /* Worker function for traversing an addrmap to build the address table. */
23634 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
23636 struct addrmap_index_data
*data
= (struct addrmap_index_data
*) datap
;
23637 struct partial_symtab
*pst
= (struct partial_symtab
*) obj
;
23639 if (data
->previous_valid
)
23640 add_address_entry (data
->objfile
, data
->addr_obstack
,
23641 data
->previous_cu_start
, start_addr
,
23642 data
->previous_cu_index
);
23644 data
->previous_cu_start
= start_addr
;
23647 struct psymtab_cu_index_map find_map
, *map
;
23648 find_map
.psymtab
= pst
;
23649 map
= ((struct psymtab_cu_index_map
*)
23650 htab_find (data
->cu_index_htab
, &find_map
));
23651 gdb_assert (map
!= NULL
);
23652 data
->previous_cu_index
= map
->cu_index
;
23653 data
->previous_valid
= 1;
23656 data
->previous_valid
= 0;
23661 /* Write OBJFILE's address map to OBSTACK.
23662 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
23663 in the index file. */
23666 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
23667 htab_t cu_index_htab
)
23669 struct addrmap_index_data addrmap_index_data
;
23671 /* When writing the address table, we have to cope with the fact that
23672 the addrmap iterator only provides the start of a region; we have to
23673 wait until the next invocation to get the start of the next region. */
23675 addrmap_index_data
.objfile
= objfile
;
23676 addrmap_index_data
.addr_obstack
= obstack
;
23677 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
23678 addrmap_index_data
.previous_valid
= 0;
23680 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
23681 &addrmap_index_data
);
23683 /* It's highly unlikely the last entry (end address = 0xff...ff)
23684 is valid, but we should still handle it.
23685 The end address is recorded as the start of the next region, but that
23686 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
23688 if (addrmap_index_data
.previous_valid
)
23689 add_address_entry (objfile
, obstack
,
23690 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
23691 addrmap_index_data
.previous_cu_index
);
23694 /* Return the symbol kind of PSYM. */
23696 static gdb_index_symbol_kind
23697 symbol_kind (struct partial_symbol
*psym
)
23699 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
23700 enum address_class aclass
= PSYMBOL_CLASS (psym
);
23708 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
23710 return GDB_INDEX_SYMBOL_KIND_TYPE
;
23712 case LOC_CONST_BYTES
:
23713 case LOC_OPTIMIZED_OUT
:
23715 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
23717 /* Note: It's currently impossible to recognize psyms as enum values
23718 short of reading the type info. For now punt. */
23719 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
23721 /* There are other LOC_FOO values that one might want to classify
23722 as variables, but dwarf2read.c doesn't currently use them. */
23723 return GDB_INDEX_SYMBOL_KIND_OTHER
;
23725 case STRUCT_DOMAIN
:
23726 return GDB_INDEX_SYMBOL_KIND_TYPE
;
23728 return GDB_INDEX_SYMBOL_KIND_OTHER
;
23732 /* Add a list of partial symbols to SYMTAB. */
23735 write_psymbols (struct mapped_symtab
*symtab
,
23737 struct partial_symbol
**psymp
,
23739 offset_type cu_index
,
23742 for (; count
-- > 0; ++psymp
)
23744 struct partial_symbol
*psym
= *psymp
;
23747 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
23748 error (_("Ada is not currently supported by the index"));
23750 /* Only add a given psymbol once. */
23751 slot
= htab_find_slot (psyms_seen
, psym
, INSERT
);
23754 gdb_index_symbol_kind kind
= symbol_kind (psym
);
23757 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
23758 is_static
, kind
, cu_index
);
23763 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
23764 exception if there is an error. */
23767 write_obstack (FILE *file
, struct obstack
*obstack
)
23769 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
23771 != obstack_object_size (obstack
))
23772 error (_("couldn't data write to file"));
23775 /* A helper struct used when iterating over debug_types. */
23776 struct signatured_type_index_data
23778 struct objfile
*objfile
;
23779 struct mapped_symtab
*symtab
;
23780 struct obstack
*types_list
;
23785 /* A helper function that writes a single signatured_type to an
23789 write_one_signatured_type (void **slot
, void *d
)
23791 struct signatured_type_index_data
*info
23792 = (struct signatured_type_index_data
*) d
;
23793 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
23794 struct partial_symtab
*psymtab
= entry
->per_cu
.v
.psymtab
;
23797 write_psymbols (info
->symtab
,
23799 info
->objfile
->global_psymbols
.list
23800 + psymtab
->globals_offset
,
23801 psymtab
->n_global_syms
, info
->cu_index
,
23803 write_psymbols (info
->symtab
,
23805 info
->objfile
->static_psymbols
.list
23806 + psymtab
->statics_offset
,
23807 psymtab
->n_static_syms
, info
->cu_index
,
23810 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
23811 to_underlying (entry
->per_cu
.sect_off
));
23812 obstack_grow (info
->types_list
, val
, 8);
23813 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
23814 to_underlying (entry
->type_offset_in_tu
));
23815 obstack_grow (info
->types_list
, val
, 8);
23816 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
23817 obstack_grow (info
->types_list
, val
, 8);
23824 /* Recurse into all "included" dependencies and write their symbols as
23825 if they appeared in this psymtab. */
23828 recursively_write_psymbols (struct objfile
*objfile
,
23829 struct partial_symtab
*psymtab
,
23830 struct mapped_symtab
*symtab
,
23832 offset_type cu_index
)
23836 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
23837 if (psymtab
->dependencies
[i
]->user
!= NULL
)
23838 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
23839 symtab
, psyms_seen
, cu_index
);
23841 write_psymbols (symtab
,
23843 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
23844 psymtab
->n_global_syms
, cu_index
,
23846 write_psymbols (symtab
,
23848 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
23849 psymtab
->n_static_syms
, cu_index
,
23853 /* Create an index file for OBJFILE in the directory DIR. */
23856 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
23858 struct cleanup
*cleanup
;
23860 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
23861 struct obstack cu_list
, types_cu_list
;
23864 struct mapped_symtab
*symtab
;
23865 offset_type val
, size_of_contents
, total_len
;
23867 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
23869 if (dwarf2_per_objfile
->using_index
)
23870 error (_("Cannot use an index to create the index"));
23872 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
23873 error (_("Cannot make an index when the file has multiple .debug_types sections"));
23875 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
23878 if (stat (objfile_name (objfile
), &st
) < 0)
23879 perror_with_name (objfile_name (objfile
));
23881 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile_name (objfile
)),
23882 INDEX_SUFFIX
, (char *) NULL
);
23883 cleanup
= make_cleanup (xfree
, filename
);
23885 out_file
= gdb_fopen_cloexec (filename
, "wb");
23887 error (_("Can't open `%s' for writing"), filename
);
23889 gdb::unlinker
unlink_file (filename
);
23891 symtab
= create_mapped_symtab ();
23892 make_cleanup (cleanup_mapped_symtab
, symtab
);
23894 obstack_init (&addr_obstack
);
23895 make_cleanup_obstack_free (&addr_obstack
);
23897 obstack_init (&cu_list
);
23898 make_cleanup_obstack_free (&cu_list
);
23900 obstack_init (&types_cu_list
);
23901 make_cleanup_obstack_free (&types_cu_list
);
23903 htab_up
psyms_seen (htab_create_alloc (100, htab_hash_pointer
,
23905 NULL
, xcalloc
, xfree
));
23907 /* While we're scanning CU's create a table that maps a psymtab pointer
23908 (which is what addrmap records) to its index (which is what is recorded
23909 in the index file). This will later be needed to write the address
23911 htab_up
cu_index_htab (htab_create_alloc (100,
23912 hash_psymtab_cu_index
,
23913 eq_psymtab_cu_index
,
23914 NULL
, xcalloc
, xfree
));
23915 psymtab_cu_index_map
= XNEWVEC (struct psymtab_cu_index_map
,
23916 dwarf2_per_objfile
->n_comp_units
);
23917 make_cleanup (xfree
, psymtab_cu_index_map
);
23919 /* The CU list is already sorted, so we don't need to do additional
23920 work here. Also, the debug_types entries do not appear in
23921 all_comp_units, but only in their own hash table. */
23922 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
23924 struct dwarf2_per_cu_data
*per_cu
23925 = dwarf2_per_objfile
->all_comp_units
[i
];
23926 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
23928 struct psymtab_cu_index_map
*map
;
23931 /* CU of a shared file from 'dwz -m' may be unused by this main file.
23932 It may be referenced from a local scope but in such case it does not
23933 need to be present in .gdb_index. */
23934 if (psymtab
== NULL
)
23937 if (psymtab
->user
== NULL
)
23938 recursively_write_psymbols (objfile
, psymtab
, symtab
,
23939 psyms_seen
.get (), i
);
23941 map
= &psymtab_cu_index_map
[i
];
23942 map
->psymtab
= psymtab
;
23944 slot
= htab_find_slot (cu_index_htab
.get (), map
, INSERT
);
23945 gdb_assert (slot
!= NULL
);
23946 gdb_assert (*slot
== NULL
);
23949 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
23950 to_underlying (per_cu
->sect_off
));
23951 obstack_grow (&cu_list
, val
, 8);
23952 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
23953 obstack_grow (&cu_list
, val
, 8);
23956 /* Dump the address map. */
23957 write_address_map (objfile
, &addr_obstack
, cu_index_htab
.get ());
23959 /* Write out the .debug_type entries, if any. */
23960 if (dwarf2_per_objfile
->signatured_types
)
23962 struct signatured_type_index_data sig_data
;
23964 sig_data
.objfile
= objfile
;
23965 sig_data
.symtab
= symtab
;
23966 sig_data
.types_list
= &types_cu_list
;
23967 sig_data
.psyms_seen
= psyms_seen
.get ();
23968 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
23969 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
23970 write_one_signatured_type
, &sig_data
);
23973 /* Now that we've processed all symbols we can shrink their cu_indices
23975 uniquify_cu_indices (symtab
);
23977 obstack_init (&constant_pool
);
23978 make_cleanup_obstack_free (&constant_pool
);
23979 obstack_init (&symtab_obstack
);
23980 make_cleanup_obstack_free (&symtab_obstack
);
23981 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
23983 obstack_init (&contents
);
23984 make_cleanup_obstack_free (&contents
);
23985 size_of_contents
= 6 * sizeof (offset_type
);
23986 total_len
= size_of_contents
;
23988 /* The version number. */
23989 val
= MAYBE_SWAP (8);
23990 obstack_grow (&contents
, &val
, sizeof (val
));
23992 /* The offset of the CU list from the start of the file. */
23993 val
= MAYBE_SWAP (total_len
);
23994 obstack_grow (&contents
, &val
, sizeof (val
));
23995 total_len
+= obstack_object_size (&cu_list
);
23997 /* The offset of the types CU list from the start of the file. */
23998 val
= MAYBE_SWAP (total_len
);
23999 obstack_grow (&contents
, &val
, sizeof (val
));
24000 total_len
+= obstack_object_size (&types_cu_list
);
24002 /* The offset of the address table from the start of the file. */
24003 val
= MAYBE_SWAP (total_len
);
24004 obstack_grow (&contents
, &val
, sizeof (val
));
24005 total_len
+= obstack_object_size (&addr_obstack
);
24007 /* The offset of the symbol table from the start of the file. */
24008 val
= MAYBE_SWAP (total_len
);
24009 obstack_grow (&contents
, &val
, sizeof (val
));
24010 total_len
+= obstack_object_size (&symtab_obstack
);
24012 /* The offset of the constant pool from the start of the file. */
24013 val
= MAYBE_SWAP (total_len
);
24014 obstack_grow (&contents
, &val
, sizeof (val
));
24015 total_len
+= obstack_object_size (&constant_pool
);
24017 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
24019 write_obstack (out_file
, &contents
);
24020 write_obstack (out_file
, &cu_list
);
24021 write_obstack (out_file
, &types_cu_list
);
24022 write_obstack (out_file
, &addr_obstack
);
24023 write_obstack (out_file
, &symtab_obstack
);
24024 write_obstack (out_file
, &constant_pool
);
24028 /* We want to keep the file. */
24029 unlink_file
.keep ();
24031 do_cleanups (cleanup
);
24034 /* Implementation of the `save gdb-index' command.
24036 Note that the file format used by this command is documented in the
24037 GDB manual. Any changes here must be documented there. */
24040 save_gdb_index_command (char *arg
, int from_tty
)
24042 struct objfile
*objfile
;
24045 error (_("usage: save gdb-index DIRECTORY"));
24047 ALL_OBJFILES (objfile
)
24051 /* If the objfile does not correspond to an actual file, skip it. */
24052 if (stat (objfile_name (objfile
), &st
) < 0)
24056 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
24057 dwarf2_objfile_data_key
);
24058 if (dwarf2_per_objfile
)
24063 write_psymtabs_to_index (objfile
, arg
);
24065 CATCH (except
, RETURN_MASK_ERROR
)
24067 exception_fprintf (gdb_stderr
, except
,
24068 _("Error while writing index for `%s': "),
24069 objfile_name (objfile
));
24078 int dwarf_always_disassemble
;
24081 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
24082 struct cmd_list_element
*c
, const char *value
)
24084 fprintf_filtered (file
,
24085 _("Whether to always disassemble "
24086 "DWARF expressions is %s.\n"),
24091 show_check_physname (struct ui_file
*file
, int from_tty
,
24092 struct cmd_list_element
*c
, const char *value
)
24094 fprintf_filtered (file
,
24095 _("Whether to check \"physname\" is %s.\n"),
24099 void _initialize_dwarf2_read (void);
24102 _initialize_dwarf2_read (void)
24104 struct cmd_list_element
*c
;
24106 dwarf2_objfile_data_key
24107 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
24109 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
24110 Set DWARF specific variables.\n\
24111 Configure DWARF variables such as the cache size"),
24112 &set_dwarf_cmdlist
, "maintenance set dwarf ",
24113 0/*allow-unknown*/, &maintenance_set_cmdlist
);
24115 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
24116 Show DWARF specific variables\n\
24117 Show DWARF variables such as the cache size"),
24118 &show_dwarf_cmdlist
, "maintenance show dwarf ",
24119 0/*allow-unknown*/, &maintenance_show_cmdlist
);
24121 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
24122 &dwarf_max_cache_age
, _("\
24123 Set the upper bound on the age of cached DWARF compilation units."), _("\
24124 Show the upper bound on the age of cached DWARF compilation units."), _("\
24125 A higher limit means that cached compilation units will be stored\n\
24126 in memory longer, and more total memory will be used. Zero disables\n\
24127 caching, which can slow down startup."),
24129 show_dwarf_max_cache_age
,
24130 &set_dwarf_cmdlist
,
24131 &show_dwarf_cmdlist
);
24133 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
24134 &dwarf_always_disassemble
, _("\
24135 Set whether `info address' always disassembles DWARF expressions."), _("\
24136 Show whether `info address' always disassembles DWARF expressions."), _("\
24137 When enabled, DWARF expressions are always printed in an assembly-like\n\
24138 syntax. When disabled, expressions will be printed in a more\n\
24139 conversational style, when possible."),
24141 show_dwarf_always_disassemble
,
24142 &set_dwarf_cmdlist
,
24143 &show_dwarf_cmdlist
);
24145 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
24146 Set debugging of the DWARF reader."), _("\
24147 Show debugging of the DWARF reader."), _("\
24148 When enabled (non-zero), debugging messages are printed during DWARF\n\
24149 reading and symtab expansion. A value of 1 (one) provides basic\n\
24150 information. A value greater than 1 provides more verbose information."),
24153 &setdebuglist
, &showdebuglist
);
24155 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
24156 Set debugging of the DWARF DIE reader."), _("\
24157 Show debugging of the DWARF DIE reader."), _("\
24158 When enabled (non-zero), DIEs are dumped after they are read in.\n\
24159 The value is the maximum depth to print."),
24162 &setdebuglist
, &showdebuglist
);
24164 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
24165 Set debugging of the dwarf line reader."), _("\
24166 Show debugging of the dwarf line reader."), _("\
24167 When enabled (non-zero), line number entries are dumped as they are read in.\n\
24168 A value of 1 (one) provides basic information.\n\
24169 A value greater than 1 provides more verbose information."),
24172 &setdebuglist
, &showdebuglist
);
24174 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
24175 Set cross-checking of \"physname\" code against demangler."), _("\
24176 Show cross-checking of \"physname\" code against demangler."), _("\
24177 When enabled, GDB's internal \"physname\" code is checked against\n\
24179 NULL
, show_check_physname
,
24180 &setdebuglist
, &showdebuglist
);
24182 add_setshow_boolean_cmd ("use-deprecated-index-sections",
24183 no_class
, &use_deprecated_index_sections
, _("\
24184 Set whether to use deprecated gdb_index sections."), _("\
24185 Show whether to use deprecated gdb_index sections."), _("\
24186 When enabled, deprecated .gdb_index sections are used anyway.\n\
24187 Normally they are ignored either because of a missing feature or\n\
24188 performance issue.\n\
24189 Warning: This option must be enabled before gdb reads the file."),
24192 &setlist
, &showlist
);
24194 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
24196 Save a gdb-index file.\n\
24197 Usage: save gdb-index DIRECTORY"),
24199 set_cmd_completer (c
, filename_completer
);
24201 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24202 &dwarf2_locexpr_funcs
);
24203 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24204 &dwarf2_loclist_funcs
);
24206 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24207 &dwarf2_block_frame_base_locexpr_funcs
);
24208 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24209 &dwarf2_block_frame_base_loclist_funcs
);