1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2015 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"
59 #include "completer.h"
64 #include "gdbcore.h" /* for gnutarget */
65 #include "gdb/gdb-index.h"
70 #include "filestuff.h"
72 #include "namespace.h"
75 #include <sys/types.h>
77 typedef struct symbol
*symbolp
;
80 /* When == 1, print basic high level tracing messages.
81 When > 1, be more verbose.
82 This is in contrast to the low level DIE reading of dwarf_die_debug. */
83 static unsigned int dwarf_read_debug
= 0;
85 /* When non-zero, dump DIEs after they are read in. */
86 static unsigned int dwarf_die_debug
= 0;
88 /* When non-zero, dump line number entries as they are read in. */
89 static unsigned int dwarf_line_debug
= 0;
91 /* When non-zero, cross-check physname against demangler. */
92 static int check_physname
= 0;
94 /* When non-zero, do not reject deprecated .gdb_index sections. */
95 static int use_deprecated_index_sections
= 0;
97 static const struct objfile_data
*dwarf2_objfile_data_key
;
99 /* The "aclass" indices for various kinds of computed DWARF symbols. */
101 static int dwarf2_locexpr_index
;
102 static int dwarf2_loclist_index
;
103 static int dwarf2_locexpr_block_index
;
104 static int dwarf2_loclist_block_index
;
106 /* A descriptor for dwarf sections.
108 S.ASECTION, SIZE are typically initialized when the objfile is first
109 scanned. BUFFER, READIN are filled in later when the section is read.
110 If the section contained compressed data then SIZE is updated to record
111 the uncompressed size of the section.
113 DWP file format V2 introduces a wrinkle that is easiest to handle by
114 creating the concept of virtual sections contained within a real section.
115 In DWP V2 the sections of the input DWO files are concatenated together
116 into one section, but section offsets are kept relative to the original
118 If this is a virtual dwp-v2 section, S.CONTAINING_SECTION is a backlink to
119 the real section this "virtual" section is contained in, and BUFFER,SIZE
120 describe the virtual section. */
122 struct dwarf2_section_info
126 /* If this is a real section, the bfd section. */
128 /* If this is a virtual section, pointer to the containing ("real")
130 struct dwarf2_section_info
*containing_section
;
132 /* Pointer to section data, only valid if readin. */
133 const gdb_byte
*buffer
;
134 /* The size of the section, real or virtual. */
136 /* If this is a virtual section, the offset in the real section.
137 Only valid if is_virtual. */
138 bfd_size_type virtual_offset
;
139 /* True if we have tried to read this section. */
141 /* True if this is a virtual section, False otherwise.
142 This specifies which of s.asection and s.containing_section to use. */
146 typedef struct dwarf2_section_info dwarf2_section_info_def
;
147 DEF_VEC_O (dwarf2_section_info_def
);
149 /* All offsets in the index are of this type. It must be
150 architecture-independent. */
151 typedef uint32_t offset_type
;
153 DEF_VEC_I (offset_type
);
155 /* Ensure only legit values are used. */
156 #define DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \
158 gdb_assert ((unsigned int) (value) <= 1); \
159 GDB_INDEX_SYMBOL_STATIC_SET_VALUE((cu_index), (value)); \
162 /* Ensure only legit values are used. */
163 #define DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \
165 gdb_assert ((value) >= GDB_INDEX_SYMBOL_KIND_TYPE \
166 && (value) <= GDB_INDEX_SYMBOL_KIND_OTHER); \
167 GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \
170 /* Ensure we don't use more than the alloted nuber of bits for the CU. */
171 #define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \
173 gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \
174 GDB_INDEX_CU_SET_VALUE((cu_index), (value)); \
177 /* A description of the mapped index. The file format is described in
178 a comment by the code that writes the index. */
181 /* Index data format version. */
184 /* The total length of the buffer. */
187 /* A pointer to the address table data. */
188 const gdb_byte
*address_table
;
190 /* Size of the address table data in bytes. */
191 offset_type address_table_size
;
193 /* The symbol table, implemented as a hash table. */
194 const offset_type
*symbol_table
;
196 /* Size in slots, each slot is 2 offset_types. */
197 offset_type symbol_table_slots
;
199 /* A pointer to the constant pool. */
200 const char *constant_pool
;
203 typedef struct dwarf2_per_cu_data
*dwarf2_per_cu_ptr
;
204 DEF_VEC_P (dwarf2_per_cu_ptr
);
208 int nr_uniq_abbrev_tables
;
210 int nr_symtab_sharers
;
211 int nr_stmt_less_type_units
;
212 int nr_all_type_units_reallocs
;
215 /* Collection of data recorded per objfile.
216 This hangs off of dwarf2_objfile_data_key. */
218 struct dwarf2_per_objfile
220 struct dwarf2_section_info info
;
221 struct dwarf2_section_info abbrev
;
222 struct dwarf2_section_info line
;
223 struct dwarf2_section_info loc
;
224 struct dwarf2_section_info macinfo
;
225 struct dwarf2_section_info macro
;
226 struct dwarf2_section_info str
;
227 struct dwarf2_section_info ranges
;
228 struct dwarf2_section_info addr
;
229 struct dwarf2_section_info frame
;
230 struct dwarf2_section_info eh_frame
;
231 struct dwarf2_section_info gdb_index
;
233 VEC (dwarf2_section_info_def
) *types
;
236 struct objfile
*objfile
;
238 /* Table of all the compilation units. This is used to locate
239 the target compilation unit of a particular reference. */
240 struct dwarf2_per_cu_data
**all_comp_units
;
242 /* The number of compilation units in ALL_COMP_UNITS. */
245 /* The number of .debug_types-related CUs. */
248 /* The number of elements allocated in all_type_units.
249 If there are skeleton-less TUs, we add them to all_type_units lazily. */
250 int n_allocated_type_units
;
252 /* The .debug_types-related CUs (TUs).
253 This is stored in malloc space because we may realloc it. */
254 struct signatured_type
**all_type_units
;
256 /* Table of struct type_unit_group objects.
257 The hash key is the DW_AT_stmt_list value. */
258 htab_t type_unit_groups
;
260 /* A table mapping .debug_types signatures to its signatured_type entry.
261 This is NULL if the .debug_types section hasn't been read in yet. */
262 htab_t signatured_types
;
264 /* Type unit statistics, to see how well the scaling improvements
266 struct tu_stats tu_stats
;
268 /* A chain of compilation units that are currently read in, so that
269 they can be freed later. */
270 struct dwarf2_per_cu_data
*read_in_chain
;
272 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
273 This is NULL if the table hasn't been allocated yet. */
276 /* Non-zero if we've check for whether there is a DWP file. */
279 /* The DWP file if there is one, or NULL. */
280 struct dwp_file
*dwp_file
;
282 /* The shared '.dwz' file, if one exists. This is used when the
283 original data was compressed using 'dwz -m'. */
284 struct dwz_file
*dwz_file
;
286 /* A flag indicating wether this objfile has a section loaded at a
288 int has_section_at_zero
;
290 /* True if we are using the mapped index,
291 or we are faking it for OBJF_READNOW's sake. */
292 unsigned char using_index
;
294 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
295 struct mapped_index
*index_table
;
297 /* When using index_table, this keeps track of all quick_file_names entries.
298 TUs typically share line table entries with a CU, so we maintain a
299 separate table of all line table entries to support the sharing.
300 Note that while there can be way more TUs than CUs, we've already
301 sorted all the TUs into "type unit groups", grouped by their
302 DW_AT_stmt_list value. Therefore the only sharing done here is with a
303 CU and its associated TU group if there is one. */
304 htab_t quick_file_names_table
;
306 /* Set during partial symbol reading, to prevent queueing of full
308 int reading_partial_symbols
;
310 /* Table mapping type DIEs to their struct type *.
311 This is NULL if not allocated yet.
312 The mapping is done via (CU/TU + DIE offset) -> type. */
313 htab_t die_type_hash
;
315 /* The CUs we recently read. */
316 VEC (dwarf2_per_cu_ptr
) *just_read_cus
;
318 /* Table containing line_header indexed by offset and offset_in_dwz. */
319 htab_t line_header_hash
;
322 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
324 /* Default names of the debugging sections. */
326 /* Note that if the debugging section has been compressed, it might
327 have a name like .zdebug_info. */
329 static const struct dwarf2_debug_sections dwarf2_elf_names
=
331 { ".debug_info", ".zdebug_info" },
332 { ".debug_abbrev", ".zdebug_abbrev" },
333 { ".debug_line", ".zdebug_line" },
334 { ".debug_loc", ".zdebug_loc" },
335 { ".debug_macinfo", ".zdebug_macinfo" },
336 { ".debug_macro", ".zdebug_macro" },
337 { ".debug_str", ".zdebug_str" },
338 { ".debug_ranges", ".zdebug_ranges" },
339 { ".debug_types", ".zdebug_types" },
340 { ".debug_addr", ".zdebug_addr" },
341 { ".debug_frame", ".zdebug_frame" },
342 { ".eh_frame", NULL
},
343 { ".gdb_index", ".zgdb_index" },
347 /* List of DWO/DWP sections. */
349 static const struct dwop_section_names
351 struct dwarf2_section_names abbrev_dwo
;
352 struct dwarf2_section_names info_dwo
;
353 struct dwarf2_section_names line_dwo
;
354 struct dwarf2_section_names loc_dwo
;
355 struct dwarf2_section_names macinfo_dwo
;
356 struct dwarf2_section_names macro_dwo
;
357 struct dwarf2_section_names str_dwo
;
358 struct dwarf2_section_names str_offsets_dwo
;
359 struct dwarf2_section_names types_dwo
;
360 struct dwarf2_section_names cu_index
;
361 struct dwarf2_section_names tu_index
;
365 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
366 { ".debug_info.dwo", ".zdebug_info.dwo" },
367 { ".debug_line.dwo", ".zdebug_line.dwo" },
368 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
369 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
370 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
371 { ".debug_str.dwo", ".zdebug_str.dwo" },
372 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
373 { ".debug_types.dwo", ".zdebug_types.dwo" },
374 { ".debug_cu_index", ".zdebug_cu_index" },
375 { ".debug_tu_index", ".zdebug_tu_index" },
378 /* local data types */
380 /* The data in a compilation unit header, after target2host
381 translation, looks like this. */
382 struct comp_unit_head
386 unsigned char addr_size
;
387 unsigned char signed_addr_p
;
388 sect_offset abbrev_offset
;
390 /* Size of file offsets; either 4 or 8. */
391 unsigned int offset_size
;
393 /* Size of the length field; either 4 or 12. */
394 unsigned int initial_length_size
;
396 /* Offset to the first byte of this compilation unit header in the
397 .debug_info section, for resolving relative reference dies. */
400 /* Offset to first die in this cu from the start of the cu.
401 This will be the first byte following the compilation unit header. */
402 cu_offset first_die_offset
;
405 /* Type used for delaying computation of method physnames.
406 See comments for compute_delayed_physnames. */
407 struct delayed_method_info
409 /* The type to which the method is attached, i.e., its parent class. */
412 /* The index of the method in the type's function fieldlists. */
415 /* The index of the method in the fieldlist. */
418 /* The name of the DIE. */
421 /* The DIE associated with this method. */
422 struct die_info
*die
;
425 typedef struct delayed_method_info delayed_method_info
;
426 DEF_VEC_O (delayed_method_info
);
428 /* Internal state when decoding a particular compilation unit. */
431 /* The objfile containing this compilation unit. */
432 struct objfile
*objfile
;
434 /* The header of the compilation unit. */
435 struct comp_unit_head header
;
437 /* Base address of this compilation unit. */
438 CORE_ADDR base_address
;
440 /* Non-zero if base_address has been set. */
443 /* The language we are debugging. */
444 enum language language
;
445 const struct language_defn
*language_defn
;
447 const char *producer
;
449 /* The generic symbol table building routines have separate lists for
450 file scope symbols and all all other scopes (local scopes). So
451 we need to select the right one to pass to add_symbol_to_list().
452 We do it by keeping a pointer to the correct list in list_in_scope.
454 FIXME: The original dwarf code just treated the file scope as the
455 first local scope, and all other local scopes as nested local
456 scopes, and worked fine. Check to see if we really need to
457 distinguish these in buildsym.c. */
458 struct pending
**list_in_scope
;
460 /* The abbrev table for this CU.
461 Normally this points to the abbrev table in the objfile.
462 But if DWO_UNIT is non-NULL this is the abbrev table in the DWO file. */
463 struct abbrev_table
*abbrev_table
;
465 /* Hash table holding all the loaded partial DIEs
466 with partial_die->offset.SECT_OFF as hash. */
469 /* Storage for things with the same lifetime as this read-in compilation
470 unit, including partial DIEs. */
471 struct obstack comp_unit_obstack
;
473 /* When multiple dwarf2_cu structures are living in memory, this field
474 chains them all together, so that they can be released efficiently.
475 We will probably also want a generation counter so that most-recently-used
476 compilation units are cached... */
477 struct dwarf2_per_cu_data
*read_in_chain
;
479 /* Backlink to our per_cu entry. */
480 struct dwarf2_per_cu_data
*per_cu
;
482 /* How many compilation units ago was this CU last referenced? */
485 /* A hash table of DIE cu_offset for following references with
486 die_info->offset.sect_off as hash. */
489 /* Full DIEs if read in. */
490 struct die_info
*dies
;
492 /* A set of pointers to dwarf2_per_cu_data objects for compilation
493 units referenced by this one. Only set during full symbol processing;
494 partial symbol tables do not have dependencies. */
497 /* Header data from the line table, during full symbol processing. */
498 struct line_header
*line_header
;
500 /* A list of methods which need to have physnames computed
501 after all type information has been read. */
502 VEC (delayed_method_info
) *method_list
;
504 /* To be copied to symtab->call_site_htab. */
505 htab_t call_site_htab
;
507 /* Non-NULL if this CU came from a DWO file.
508 There is an invariant here that is important to remember:
509 Except for attributes copied from the top level DIE in the "main"
510 (or "stub") file in preparation for reading the DWO file
511 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
512 Either there isn't a DWO file (in which case this is NULL and the point
513 is moot), or there is and either we're not going to read it (in which
514 case this is NULL) or there is and we are reading it (in which case this
516 struct dwo_unit
*dwo_unit
;
518 /* The DW_AT_addr_base attribute if present, zero otherwise
519 (zero is a valid value though).
520 Note this value comes from the Fission stub CU/TU's DIE. */
523 /* The DW_AT_ranges_base attribute if present, zero otherwise
524 (zero is a valid value though).
525 Note this value comes from the Fission stub CU/TU's DIE.
526 Also note that the value is zero in the non-DWO case so this value can
527 be used without needing to know whether DWO files are in use or not.
528 N.B. This does not apply to DW_AT_ranges appearing in
529 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
530 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
531 DW_AT_ranges_base *would* have to be applied, and we'd have to care
532 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
533 ULONGEST ranges_base
;
535 /* Mark used when releasing cached dies. */
536 unsigned int mark
: 1;
538 /* This CU references .debug_loc. See the symtab->locations_valid field.
539 This test is imperfect as there may exist optimized debug code not using
540 any location list and still facing inlining issues if handled as
541 unoptimized code. For a future better test see GCC PR other/32998. */
542 unsigned int has_loclist
: 1;
544 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is set
545 if all the producer_is_* fields are valid. This information is cached
546 because profiling CU expansion showed excessive time spent in
547 producer_is_gxx_lt_4_6. */
548 unsigned int checked_producer
: 1;
549 unsigned int producer_is_gxx_lt_4_6
: 1;
550 unsigned int producer_is_gcc_lt_4_3
: 1;
551 unsigned int producer_is_icc
: 1;
553 /* When set, the file that we're processing is known to have
554 debugging info for C++ namespaces. GCC 3.3.x did not produce
555 this information, but later versions do. */
557 unsigned int processing_has_namespace_info
: 1;
560 /* Persistent data held for a compilation unit, even when not
561 processing it. We put a pointer to this structure in the
562 read_symtab_private field of the psymtab. */
564 struct dwarf2_per_cu_data
566 /* The start offset and length of this compilation unit.
567 NOTE: Unlike comp_unit_head.length, this length includes
569 If the DIE refers to a DWO file, this is always of the original die,
574 /* Flag indicating this compilation unit will be read in before
575 any of the current compilation units are processed. */
576 unsigned int queued
: 1;
578 /* This flag will be set when reading partial DIEs if we need to load
579 absolutely all DIEs for this compilation unit, instead of just the ones
580 we think are interesting. It gets set if we look for a DIE in the
581 hash table and don't find it. */
582 unsigned int load_all_dies
: 1;
584 /* Non-zero if this CU is from .debug_types.
585 Struct dwarf2_per_cu_data is contained in struct signatured_type iff
587 unsigned int is_debug_types
: 1;
589 /* Non-zero if this CU is from the .dwz file. */
590 unsigned int is_dwz
: 1;
592 /* Non-zero if reading a TU directly from a DWO file, bypassing the stub.
593 This flag is only valid if is_debug_types is true.
594 We can't read a CU directly from a DWO file: There are required
595 attributes in the stub. */
596 unsigned int reading_dwo_directly
: 1;
598 /* Non-zero if the TU has been read.
599 This is used to assist the "Stay in DWO Optimization" for Fission:
600 When reading a DWO, it's faster to read TUs from the DWO instead of
601 fetching them from random other DWOs (due to comdat folding).
602 If the TU has already been read, the optimization is unnecessary
603 (and unwise - we don't want to change where gdb thinks the TU lives
605 This flag is only valid if is_debug_types is true. */
606 unsigned int tu_read
: 1;
608 /* The section this CU/TU lives in.
609 If the DIE refers to a DWO file, this is always the original die,
611 struct dwarf2_section_info
*section
;
613 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
614 of the CU cache it gets reset to NULL again. This is left as NULL for
615 dummy CUs (a CU header, but nothing else). */
616 struct dwarf2_cu
*cu
;
618 /* The corresponding objfile.
619 Normally we can get the objfile from dwarf2_per_objfile.
620 However we can enter this file with just a "per_cu" handle. */
621 struct objfile
*objfile
;
623 /* When dwarf2_per_objfile->using_index is true, the 'quick' field
624 is active. Otherwise, the 'psymtab' field is active. */
627 /* The partial symbol table associated with this compilation unit,
628 or NULL for unread partial units. */
629 struct partial_symtab
*psymtab
;
631 /* Data needed by the "quick" functions. */
632 struct dwarf2_per_cu_quick_data
*quick
;
635 /* The CUs we import using DW_TAG_imported_unit. This is filled in
636 while reading psymtabs, used to compute the psymtab dependencies,
637 and then cleared. Then it is filled in again while reading full
638 symbols, and only deleted when the objfile is destroyed.
640 This is also used to work around a difference between the way gold
641 generates .gdb_index version <=7 and the way gdb does. Arguably this
642 is a gold bug. For symbols coming from TUs, gold records in the index
643 the CU that includes the TU instead of the TU itself. This breaks
644 dw2_lookup_symbol: It assumes that if the index says symbol X lives
645 in CU/TU Y, then one need only expand Y and a subsequent lookup in Y
646 will find X. Alas TUs live in their own symtab, so after expanding CU Y
647 we need to look in TU Z to find X. Fortunately, this is akin to
648 DW_TAG_imported_unit, so we just use the same mechanism: For
649 .gdb_index version <=7 this also records the TUs that the CU referred
650 to. Concurrently with this change gdb was modified to emit version 8
651 indices so we only pay a price for gold generated indices.
652 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
653 VEC (dwarf2_per_cu_ptr
) *imported_symtabs
;
656 /* Entry in the signatured_types hash table. */
658 struct signatured_type
660 /* The "per_cu" object of this type.
661 This struct is used iff per_cu.is_debug_types.
662 N.B.: This is the first member so that it's easy to convert pointers
664 struct dwarf2_per_cu_data per_cu
;
666 /* The type's signature. */
669 /* Offset in the TU of the type's DIE, as read from the TU header.
670 If this TU is a DWO stub and the definition lives in a DWO file
671 (specified by DW_AT_GNU_dwo_name), this value is unusable. */
672 cu_offset type_offset_in_tu
;
674 /* Offset in the section of the type's DIE.
675 If the definition lives in a DWO file, this is the offset in the
676 .debug_types.dwo section.
677 The value is zero until the actual value is known.
678 Zero is otherwise not a valid section offset. */
679 sect_offset type_offset_in_section
;
681 /* Type units are grouped by their DW_AT_stmt_list entry so that they
682 can share them. This points to the containing symtab. */
683 struct type_unit_group
*type_unit_group
;
686 The first time we encounter this type we fully read it in and install it
687 in the symbol tables. Subsequent times we only need the type. */
690 /* Containing DWO unit.
691 This field is valid iff per_cu.reading_dwo_directly. */
692 struct dwo_unit
*dwo_unit
;
695 typedef struct signatured_type
*sig_type_ptr
;
696 DEF_VEC_P (sig_type_ptr
);
698 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
699 This includes type_unit_group and quick_file_names. */
701 struct stmt_list_hash
703 /* The DWO unit this table is from or NULL if there is none. */
704 struct dwo_unit
*dwo_unit
;
706 /* Offset in .debug_line or .debug_line.dwo. */
707 sect_offset line_offset
;
710 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
711 an object of this type. */
713 struct type_unit_group
715 /* dwarf2read.c's main "handle" on a TU symtab.
716 To simplify things we create an artificial CU that "includes" all the
717 type units using this stmt_list so that the rest of the code still has
718 a "per_cu" handle on the symtab.
719 This PER_CU is recognized by having no section. */
720 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->section == NULL)
721 struct dwarf2_per_cu_data per_cu
;
723 /* The TUs that share this DW_AT_stmt_list entry.
724 This is added to while parsing type units to build partial symtabs,
725 and is deleted afterwards and not used again. */
726 VEC (sig_type_ptr
) *tus
;
728 /* The compunit symtab.
729 Type units in a group needn't all be defined in the same source file,
730 so we create an essentially anonymous symtab as the compunit symtab. */
731 struct compunit_symtab
*compunit_symtab
;
733 /* The data used to construct the hash key. */
734 struct stmt_list_hash hash
;
736 /* The number of symtabs from the line header.
737 The value here must match line_header.num_file_names. */
738 unsigned int num_symtabs
;
740 /* The symbol tables for this TU (obtained from the files listed in
742 WARNING: The order of entries here must match the order of entries
743 in the line header. After the first TU using this type_unit_group, the
744 line header for the subsequent TUs is recreated from this. This is done
745 because we need to use the same symtabs for each TU using the same
746 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
747 there's no guarantee the line header doesn't have duplicate entries. */
748 struct symtab
**symtabs
;
751 /* These sections are what may appear in a (real or virtual) DWO file. */
755 struct dwarf2_section_info abbrev
;
756 struct dwarf2_section_info line
;
757 struct dwarf2_section_info loc
;
758 struct dwarf2_section_info macinfo
;
759 struct dwarf2_section_info macro
;
760 struct dwarf2_section_info str
;
761 struct dwarf2_section_info str_offsets
;
762 /* In the case of a virtual DWO file, these two are unused. */
763 struct dwarf2_section_info info
;
764 VEC (dwarf2_section_info_def
) *types
;
767 /* CUs/TUs in DWP/DWO files. */
771 /* Backlink to the containing struct dwo_file. */
772 struct dwo_file
*dwo_file
;
774 /* The "id" that distinguishes this CU/TU.
775 .debug_info calls this "dwo_id", .debug_types calls this "signature".
776 Since signatures came first, we stick with it for consistency. */
779 /* The section this CU/TU lives in, in the DWO file. */
780 struct dwarf2_section_info
*section
;
782 /* Same as dwarf2_per_cu_data:{offset,length} but in the DWO section. */
786 /* For types, offset in the type's DIE of the type defined by this TU. */
787 cu_offset type_offset_in_tu
;
790 /* include/dwarf2.h defines the DWP section codes.
791 It defines a max value but it doesn't define a min value, which we
792 use for error checking, so provide one. */
794 enum dwp_v2_section_ids
799 /* Data for one DWO file.
801 This includes virtual DWO files (a virtual DWO file is a DWO file as it
802 appears in a DWP file). DWP files don't really have DWO files per se -
803 comdat folding of types "loses" the DWO file they came from, and from
804 a high level view DWP files appear to contain a mass of random types.
805 However, to maintain consistency with the non-DWP case we pretend DWP
806 files contain virtual DWO files, and we assign each TU with one virtual
807 DWO file (generally based on the line and abbrev section offsets -
808 a heuristic that seems to work in practice). */
812 /* The DW_AT_GNU_dwo_name attribute.
813 For virtual DWO files the name is constructed from the section offsets
814 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
815 from related CU+TUs. */
816 const char *dwo_name
;
818 /* The DW_AT_comp_dir attribute. */
819 const char *comp_dir
;
821 /* The bfd, when the file is open. Otherwise this is NULL.
822 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
825 /* The sections that make up this DWO file.
826 Remember that for virtual DWO files in DWP V2, these are virtual
827 sections (for lack of a better name). */
828 struct dwo_sections sections
;
830 /* The CU in the file.
831 We only support one because having more than one requires hacking the
832 dwo_name of each to match, which is highly unlikely to happen.
833 Doing this means all TUs can share comp_dir: We also assume that
834 DW_AT_comp_dir across all TUs in a DWO file will be identical. */
837 /* Table of TUs in the file.
838 Each element is a struct dwo_unit. */
842 /* These sections are what may appear in a DWP file. */
846 /* These are used by both DWP version 1 and 2. */
847 struct dwarf2_section_info str
;
848 struct dwarf2_section_info cu_index
;
849 struct dwarf2_section_info tu_index
;
851 /* These are only used by DWP version 2 files.
852 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
853 sections are referenced by section number, and are not recorded here.
854 In DWP version 2 there is at most one copy of all these sections, each
855 section being (effectively) comprised of the concatenation of all of the
856 individual sections that exist in the version 1 format.
857 To keep the code simple we treat each of these concatenated pieces as a
858 section itself (a virtual section?). */
859 struct dwarf2_section_info abbrev
;
860 struct dwarf2_section_info info
;
861 struct dwarf2_section_info line
;
862 struct dwarf2_section_info loc
;
863 struct dwarf2_section_info macinfo
;
864 struct dwarf2_section_info macro
;
865 struct dwarf2_section_info str_offsets
;
866 struct dwarf2_section_info types
;
869 /* These sections are what may appear in a virtual DWO file in DWP version 1.
870 A virtual DWO file is a DWO file as it appears in a DWP file. */
872 struct virtual_v1_dwo_sections
874 struct dwarf2_section_info abbrev
;
875 struct dwarf2_section_info line
;
876 struct dwarf2_section_info loc
;
877 struct dwarf2_section_info macinfo
;
878 struct dwarf2_section_info macro
;
879 struct dwarf2_section_info str_offsets
;
880 /* Each DWP hash table entry records one CU or one TU.
881 That is recorded here, and copied to dwo_unit.section. */
882 struct dwarf2_section_info info_or_types
;
885 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
886 In version 2, the sections of the DWO files are concatenated together
887 and stored in one section of that name. Thus each ELF section contains
888 several "virtual" sections. */
890 struct virtual_v2_dwo_sections
892 bfd_size_type abbrev_offset
;
893 bfd_size_type abbrev_size
;
895 bfd_size_type line_offset
;
896 bfd_size_type line_size
;
898 bfd_size_type loc_offset
;
899 bfd_size_type loc_size
;
901 bfd_size_type macinfo_offset
;
902 bfd_size_type macinfo_size
;
904 bfd_size_type macro_offset
;
905 bfd_size_type macro_size
;
907 bfd_size_type str_offsets_offset
;
908 bfd_size_type str_offsets_size
;
910 /* Each DWP hash table entry records one CU or one TU.
911 That is recorded here, and copied to dwo_unit.section. */
912 bfd_size_type info_or_types_offset
;
913 bfd_size_type info_or_types_size
;
916 /* Contents of DWP hash tables. */
918 struct dwp_hash_table
920 uint32_t version
, nr_columns
;
921 uint32_t nr_units
, nr_slots
;
922 const gdb_byte
*hash_table
, *unit_table
;
927 const gdb_byte
*indices
;
931 /* This is indexed by column number and gives the id of the section
933 #define MAX_NR_V2_DWO_SECTIONS \
934 (1 /* .debug_info or .debug_types */ \
935 + 1 /* .debug_abbrev */ \
936 + 1 /* .debug_line */ \
937 + 1 /* .debug_loc */ \
938 + 1 /* .debug_str_offsets */ \
939 + 1 /* .debug_macro or .debug_macinfo */)
940 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
941 const gdb_byte
*offsets
;
942 const gdb_byte
*sizes
;
947 /* Data for one DWP file. */
951 /* Name of the file. */
954 /* File format version. */
960 /* Section info for this file. */
961 struct dwp_sections sections
;
963 /* Table of CUs in the file. */
964 const struct dwp_hash_table
*cus
;
966 /* Table of TUs in the file. */
967 const struct dwp_hash_table
*tus
;
969 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
973 /* Table to map ELF section numbers to their sections.
974 This is only needed for the DWP V1 file format. */
975 unsigned int num_sections
;
976 asection
**elf_sections
;
979 /* This represents a '.dwz' file. */
983 /* A dwz file can only contain a few sections. */
984 struct dwarf2_section_info abbrev
;
985 struct dwarf2_section_info info
;
986 struct dwarf2_section_info str
;
987 struct dwarf2_section_info line
;
988 struct dwarf2_section_info macro
;
989 struct dwarf2_section_info gdb_index
;
995 /* Struct used to pass misc. parameters to read_die_and_children, et
996 al. which are used for both .debug_info and .debug_types dies.
997 All parameters here are unchanging for the life of the call. This
998 struct exists to abstract away the constant parameters of die reading. */
1000 struct die_reader_specs
1002 /* The bfd of die_section. */
1005 /* The CU of the DIE we are parsing. */
1006 struct dwarf2_cu
*cu
;
1008 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
1009 struct dwo_file
*dwo_file
;
1011 /* The section the die comes from.
1012 This is either .debug_info or .debug_types, or the .dwo variants. */
1013 struct dwarf2_section_info
*die_section
;
1015 /* die_section->buffer. */
1016 const gdb_byte
*buffer
;
1018 /* The end of the buffer. */
1019 const gdb_byte
*buffer_end
;
1021 /* The value of the DW_AT_comp_dir attribute. */
1022 const char *comp_dir
;
1025 /* Type of function passed to init_cutu_and_read_dies, et.al. */
1026 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
1027 const gdb_byte
*info_ptr
,
1028 struct die_info
*comp_unit_die
,
1035 unsigned int dir_index
;
1036 unsigned int mod_time
;
1037 unsigned int length
;
1038 /* Non-zero if referenced by the Line Number Program. */
1040 /* The associated symbol table, if any. */
1041 struct symtab
*symtab
;
1044 /* The line number information for a compilation unit (found in the
1045 .debug_line section) begins with a "statement program header",
1046 which contains the following information. */
1049 /* Offset of line number information in .debug_line section. */
1052 /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile. */
1053 unsigned offset_in_dwz
: 1;
1055 unsigned int total_length
;
1056 unsigned short version
;
1057 unsigned int header_length
;
1058 unsigned char minimum_instruction_length
;
1059 unsigned char maximum_ops_per_instruction
;
1060 unsigned char default_is_stmt
;
1062 unsigned char line_range
;
1063 unsigned char opcode_base
;
1065 /* standard_opcode_lengths[i] is the number of operands for the
1066 standard opcode whose value is i. This means that
1067 standard_opcode_lengths[0] is unused, and the last meaningful
1068 element is standard_opcode_lengths[opcode_base - 1]. */
1069 unsigned char *standard_opcode_lengths
;
1071 /* The include_directories table. NOTE! These strings are not
1072 allocated with xmalloc; instead, they are pointers into
1073 debug_line_buffer. If you try to free them, `free' will get
1075 unsigned int num_include_dirs
, include_dirs_size
;
1076 const char **include_dirs
;
1078 /* The file_names table. NOTE! These strings are not allocated
1079 with xmalloc; instead, they are pointers into debug_line_buffer.
1080 Don't try to free them directly. */
1081 unsigned int num_file_names
, file_names_size
;
1082 struct file_entry
*file_names
;
1084 /* The start and end of the statement program following this
1085 header. These point into dwarf2_per_objfile->line_buffer. */
1086 const gdb_byte
*statement_program_start
, *statement_program_end
;
1089 /* When we construct a partial symbol table entry we only
1090 need this much information. */
1091 struct partial_die_info
1093 /* Offset of this DIE. */
1096 /* DWARF-2 tag for this DIE. */
1097 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1099 /* Assorted flags describing the data found in this DIE. */
1100 unsigned int has_children
: 1;
1101 unsigned int is_external
: 1;
1102 unsigned int is_declaration
: 1;
1103 unsigned int has_type
: 1;
1104 unsigned int has_specification
: 1;
1105 unsigned int has_pc_info
: 1;
1106 unsigned int may_be_inlined
: 1;
1108 /* Flag set if the SCOPE field of this structure has been
1110 unsigned int scope_set
: 1;
1112 /* Flag set if the DIE has a byte_size attribute. */
1113 unsigned int has_byte_size
: 1;
1115 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1116 unsigned int has_const_value
: 1;
1118 /* Flag set if any of the DIE's children are template arguments. */
1119 unsigned int has_template_arguments
: 1;
1121 /* Flag set if fixup_partial_die has been called on this die. */
1122 unsigned int fixup_called
: 1;
1124 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1125 unsigned int is_dwz
: 1;
1127 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1128 unsigned int spec_is_dwz
: 1;
1130 /* The name of this DIE. Normally the value of DW_AT_name, but
1131 sometimes a default name for unnamed DIEs. */
1134 /* The linkage name, if present. */
1135 const char *linkage_name
;
1137 /* The scope to prepend to our children. This is generally
1138 allocated on the comp_unit_obstack, so will disappear
1139 when this compilation unit leaves the cache. */
1142 /* Some data associated with the partial DIE. The tag determines
1143 which field is live. */
1146 /* The location description associated with this DIE, if any. */
1147 struct dwarf_block
*locdesc
;
1148 /* The offset of an import, for DW_TAG_imported_unit. */
1152 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1156 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1157 DW_AT_sibling, if any. */
1158 /* NOTE: This member isn't strictly necessary, read_partial_die could
1159 return DW_AT_sibling values to its caller load_partial_dies. */
1160 const gdb_byte
*sibling
;
1162 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1163 DW_AT_specification (or DW_AT_abstract_origin or
1164 DW_AT_extension). */
1165 sect_offset spec_offset
;
1167 /* Pointers to this DIE's parent, first child, and next sibling,
1169 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
1172 /* This data structure holds the information of an abbrev. */
1175 unsigned int number
; /* number identifying abbrev */
1176 enum dwarf_tag tag
; /* dwarf tag */
1177 unsigned short has_children
; /* boolean */
1178 unsigned short num_attrs
; /* number of attributes */
1179 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
1180 struct abbrev_info
*next
; /* next in chain */
1185 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1186 ENUM_BITFIELD(dwarf_form
) form
: 16;
1189 /* Size of abbrev_table.abbrev_hash_table. */
1190 #define ABBREV_HASH_SIZE 121
1192 /* Top level data structure to contain an abbreviation table. */
1196 /* Where the abbrev table came from.
1197 This is used as a sanity check when the table is used. */
1200 /* Storage for the abbrev table. */
1201 struct obstack abbrev_obstack
;
1203 /* Hash table of abbrevs.
1204 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1205 It could be statically allocated, but the previous code didn't so we
1207 struct abbrev_info
**abbrevs
;
1210 /* Attributes have a name and a value. */
1213 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1214 ENUM_BITFIELD(dwarf_form
) form
: 15;
1216 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1217 field should be in u.str (existing only for DW_STRING) but it is kept
1218 here for better struct attribute alignment. */
1219 unsigned int string_is_canonical
: 1;
1224 struct dwarf_block
*blk
;
1233 /* This data structure holds a complete die structure. */
1236 /* DWARF-2 tag for this DIE. */
1237 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1239 /* Number of attributes */
1240 unsigned char num_attrs
;
1242 /* True if we're presently building the full type name for the
1243 type derived from this DIE. */
1244 unsigned char building_fullname
: 1;
1246 /* True if this die is in process. PR 16581. */
1247 unsigned char in_process
: 1;
1250 unsigned int abbrev
;
1252 /* Offset in .debug_info or .debug_types section. */
1255 /* The dies in a compilation unit form an n-ary tree. PARENT
1256 points to this die's parent; CHILD points to the first child of
1257 this node; and all the children of a given node are chained
1258 together via their SIBLING fields. */
1259 struct die_info
*child
; /* Its first child, if any. */
1260 struct die_info
*sibling
; /* Its next sibling, if any. */
1261 struct die_info
*parent
; /* Its parent, if any. */
1263 /* An array of attributes, with NUM_ATTRS elements. There may be
1264 zero, but it's not common and zero-sized arrays are not
1265 sufficiently portable C. */
1266 struct attribute attrs
[1];
1269 /* Get at parts of an attribute structure. */
1271 #define DW_STRING(attr) ((attr)->u.str)
1272 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1273 #define DW_UNSND(attr) ((attr)->u.unsnd)
1274 #define DW_BLOCK(attr) ((attr)->u.blk)
1275 #define DW_SND(attr) ((attr)->u.snd)
1276 #define DW_ADDR(attr) ((attr)->u.addr)
1277 #define DW_SIGNATURE(attr) ((attr)->u.signature)
1279 /* Blocks are a bunch of untyped bytes. */
1284 /* Valid only if SIZE is not zero. */
1285 const gdb_byte
*data
;
1288 #ifndef ATTR_ALLOC_CHUNK
1289 #define ATTR_ALLOC_CHUNK 4
1292 /* Allocate fields for structs, unions and enums in this size. */
1293 #ifndef DW_FIELD_ALLOC_CHUNK
1294 #define DW_FIELD_ALLOC_CHUNK 4
1297 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1298 but this would require a corresponding change in unpack_field_as_long
1300 static int bits_per_byte
= 8;
1304 struct nextfield
*next
;
1312 struct nextfnfield
*next
;
1313 struct fn_field fnfield
;
1320 struct nextfnfield
*head
;
1323 struct typedef_field_list
1325 struct typedef_field field
;
1326 struct typedef_field_list
*next
;
1329 /* The routines that read and process dies for a C struct or C++ class
1330 pass lists of data member fields and lists of member function fields
1331 in an instance of a field_info structure, as defined below. */
1334 /* List of data member and baseclasses fields. */
1335 struct nextfield
*fields
, *baseclasses
;
1337 /* Number of fields (including baseclasses). */
1340 /* Number of baseclasses. */
1343 /* Set if the accesibility of one of the fields is not public. */
1344 int non_public_fields
;
1346 /* Member function fields array, entries are allocated in the order they
1347 are encountered in the object file. */
1348 struct nextfnfield
*fnfields
;
1350 /* Member function fieldlist array, contains name of possibly overloaded
1351 member function, number of overloaded member functions and a pointer
1352 to the head of the member function field chain. */
1353 struct fnfieldlist
*fnfieldlists
;
1355 /* Number of entries in the fnfieldlists array. */
1358 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1359 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1360 struct typedef_field_list
*typedef_field_list
;
1361 unsigned typedef_field_list_count
;
1364 /* One item on the queue of compilation units to read in full symbols
1366 struct dwarf2_queue_item
1368 struct dwarf2_per_cu_data
*per_cu
;
1369 enum language pretend_language
;
1370 struct dwarf2_queue_item
*next
;
1373 /* The current queue. */
1374 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1376 /* Loaded secondary compilation units are kept in memory until they
1377 have not been referenced for the processing of this many
1378 compilation units. Set this to zero to disable caching. Cache
1379 sizes of up to at least twenty will improve startup time for
1380 typical inter-CU-reference binaries, at an obvious memory cost. */
1381 static int dwarf_max_cache_age
= 5;
1383 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1384 struct cmd_list_element
*c
, const char *value
)
1386 fprintf_filtered (file
, _("The upper bound on the age of cached "
1387 "DWARF compilation units is %s.\n"),
1391 /* local function prototypes */
1393 static const char *get_section_name (const struct dwarf2_section_info
*);
1395 static const char *get_section_file_name (const struct dwarf2_section_info
*);
1397 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
1399 static void dwarf2_find_base_address (struct die_info
*die
,
1400 struct dwarf2_cu
*cu
);
1402 static struct partial_symtab
*create_partial_symtab
1403 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1405 static void dwarf2_build_psymtabs_hard (struct objfile
*);
1407 static void scan_partial_symbols (struct partial_die_info
*,
1408 CORE_ADDR
*, CORE_ADDR
*,
1409 int, struct dwarf2_cu
*);
1411 static void add_partial_symbol (struct partial_die_info
*,
1412 struct dwarf2_cu
*);
1414 static void add_partial_namespace (struct partial_die_info
*pdi
,
1415 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1416 int set_addrmap
, struct dwarf2_cu
*cu
);
1418 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1419 CORE_ADDR
*highpc
, int set_addrmap
,
1420 struct dwarf2_cu
*cu
);
1422 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1423 struct dwarf2_cu
*cu
);
1425 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1426 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1427 int need_pc
, struct dwarf2_cu
*cu
);
1429 static void dwarf2_read_symtab (struct partial_symtab
*,
1432 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1434 static struct abbrev_info
*abbrev_table_lookup_abbrev
1435 (const struct abbrev_table
*, unsigned int);
1437 static struct abbrev_table
*abbrev_table_read_table
1438 (struct dwarf2_section_info
*, sect_offset
);
1440 static void abbrev_table_free (struct abbrev_table
*);
1442 static void abbrev_table_free_cleanup (void *);
1444 static void dwarf2_read_abbrevs (struct dwarf2_cu
*,
1445 struct dwarf2_section_info
*);
1447 static void dwarf2_free_abbrev_table (void *);
1449 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1451 static struct partial_die_info
*load_partial_dies
1452 (const struct die_reader_specs
*, const gdb_byte
*, int);
1454 static const gdb_byte
*read_partial_die (const struct die_reader_specs
*,
1455 struct partial_die_info
*,
1456 struct abbrev_info
*,
1460 static struct partial_die_info
*find_partial_die (sect_offset
, int,
1461 struct dwarf2_cu
*);
1463 static void fixup_partial_die (struct partial_die_info
*,
1464 struct dwarf2_cu
*);
1466 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1467 struct attribute
*, struct attr_abbrev
*,
1470 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1472 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1474 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1476 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1478 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1480 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1483 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1485 static LONGEST read_checked_initial_length_and_offset
1486 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1487 unsigned int *, unsigned int *);
1489 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1490 const struct comp_unit_head
*,
1493 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1495 static sect_offset
read_abbrev_offset (struct dwarf2_section_info
*,
1498 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1500 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1502 static const char *read_indirect_string (bfd
*, const gdb_byte
*,
1503 const struct comp_unit_head
*,
1506 static const char *read_indirect_string_from_dwz (struct dwz_file
*, LONGEST
);
1508 static ULONGEST
read_unsigned_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1510 static LONGEST
read_signed_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1512 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1516 static const char *read_str_index (const struct die_reader_specs
*reader
,
1517 ULONGEST str_index
);
1519 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1521 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1522 struct dwarf2_cu
*);
1524 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1527 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1528 struct dwarf2_cu
*cu
);
1530 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1531 struct dwarf2_cu
*cu
);
1533 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1535 static struct die_info
*die_specification (struct die_info
*die
,
1536 struct dwarf2_cu
**);
1538 static void free_line_header (struct line_header
*lh
);
1540 static struct line_header
*dwarf_decode_line_header (unsigned int offset
,
1541 struct dwarf2_cu
*cu
);
1543 static void dwarf_decode_lines (struct line_header
*, const char *,
1544 struct dwarf2_cu
*, struct partial_symtab
*,
1545 CORE_ADDR
, int decode_mapping
);
1547 static void dwarf2_start_subfile (const char *, const char *);
1549 static struct compunit_symtab
*dwarf2_start_symtab (struct dwarf2_cu
*,
1550 const char *, const char *,
1553 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1554 struct dwarf2_cu
*);
1556 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1557 struct dwarf2_cu
*, struct symbol
*);
1559 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1560 struct dwarf2_cu
*);
1562 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1565 struct obstack
*obstack
,
1566 struct dwarf2_cu
*cu
, LONGEST
*value
,
1567 const gdb_byte
**bytes
,
1568 struct dwarf2_locexpr_baton
**baton
);
1570 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1572 static int need_gnat_info (struct dwarf2_cu
*);
1574 static struct type
*die_descriptive_type (struct die_info
*,
1575 struct dwarf2_cu
*);
1577 static void set_descriptive_type (struct type
*, struct die_info
*,
1578 struct dwarf2_cu
*);
1580 static struct type
*die_containing_type (struct die_info
*,
1581 struct dwarf2_cu
*);
1583 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1584 struct dwarf2_cu
*);
1586 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1588 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1590 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1592 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1593 const char *suffix
, int physname
,
1594 struct dwarf2_cu
*cu
);
1596 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1598 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1600 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1602 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1604 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1606 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1607 struct dwarf2_cu
*, struct partial_symtab
*);
1609 static int dwarf2_get_pc_bounds (struct die_info
*,
1610 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1611 struct partial_symtab
*);
1613 static void get_scope_pc_bounds (struct die_info
*,
1614 CORE_ADDR
*, CORE_ADDR
*,
1615 struct dwarf2_cu
*);
1617 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1618 CORE_ADDR
, struct dwarf2_cu
*);
1620 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1621 struct dwarf2_cu
*);
1623 static void dwarf2_attach_fields_to_type (struct field_info
*,
1624 struct type
*, struct dwarf2_cu
*);
1626 static void dwarf2_add_member_fn (struct field_info
*,
1627 struct die_info
*, struct type
*,
1628 struct dwarf2_cu
*);
1630 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1632 struct dwarf2_cu
*);
1634 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1636 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1638 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1640 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1642 static struct using_direct
**using_directives (enum language
);
1644 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1646 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1648 static struct type
*read_module_type (struct die_info
*die
,
1649 struct dwarf2_cu
*cu
);
1651 static const char *namespace_name (struct die_info
*die
,
1652 int *is_anonymous
, struct dwarf2_cu
*);
1654 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1656 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1658 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1659 struct dwarf2_cu
*);
1661 static struct die_info
*read_die_and_siblings_1
1662 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1665 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1666 const gdb_byte
*info_ptr
,
1667 const gdb_byte
**new_info_ptr
,
1668 struct die_info
*parent
);
1670 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1671 struct die_info
**, const gdb_byte
*,
1674 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1675 struct die_info
**, const gdb_byte
*,
1678 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1680 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1683 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1685 static const char *dwarf2_full_name (const char *name
,
1686 struct die_info
*die
,
1687 struct dwarf2_cu
*cu
);
1689 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1690 struct dwarf2_cu
*cu
);
1692 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1693 struct dwarf2_cu
**);
1695 static const char *dwarf_tag_name (unsigned int);
1697 static const char *dwarf_attr_name (unsigned int);
1699 static const char *dwarf_form_name (unsigned int);
1701 static char *dwarf_bool_name (unsigned int);
1703 static const char *dwarf_type_encoding_name (unsigned int);
1705 static struct die_info
*sibling_die (struct die_info
*);
1707 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1709 static void dump_die_for_error (struct die_info
*);
1711 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1714 /*static*/ void dump_die (struct die_info
*, int max_level
);
1716 static void store_in_ref_table (struct die_info
*,
1717 struct dwarf2_cu
*);
1719 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1721 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1723 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1724 const struct attribute
*,
1725 struct dwarf2_cu
**);
1727 static struct die_info
*follow_die_ref (struct die_info
*,
1728 const struct attribute
*,
1729 struct dwarf2_cu
**);
1731 static struct die_info
*follow_die_sig (struct die_info
*,
1732 const struct attribute
*,
1733 struct dwarf2_cu
**);
1735 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1736 struct dwarf2_cu
*);
1738 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1739 const struct attribute
*,
1740 struct dwarf2_cu
*);
1742 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1744 static void read_signatured_type (struct signatured_type
*);
1746 /* memory allocation interface */
1748 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1750 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1752 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1754 static int attr_form_is_block (const struct attribute
*);
1756 static int attr_form_is_section_offset (const struct attribute
*);
1758 static int attr_form_is_constant (const struct attribute
*);
1760 static int attr_form_is_ref (const struct attribute
*);
1762 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1763 struct dwarf2_loclist_baton
*baton
,
1764 const struct attribute
*attr
);
1766 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1768 struct dwarf2_cu
*cu
,
1771 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1772 const gdb_byte
*info_ptr
,
1773 struct abbrev_info
*abbrev
);
1775 static void free_stack_comp_unit (void *);
1777 static hashval_t
partial_die_hash (const void *item
);
1779 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1781 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1782 (sect_offset offset
, unsigned int offset_in_dwz
, struct objfile
*objfile
);
1784 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1785 struct dwarf2_per_cu_data
*per_cu
);
1787 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1788 struct die_info
*comp_unit_die
,
1789 enum language pretend_language
);
1791 static void free_heap_comp_unit (void *);
1793 static void free_cached_comp_units (void *);
1795 static void age_cached_comp_units (void);
1797 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1799 static struct type
*set_die_type (struct die_info
*, struct type
*,
1800 struct dwarf2_cu
*);
1802 static void create_all_comp_units (struct objfile
*);
1804 static int create_all_type_units (struct objfile
*);
1806 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1809 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1812 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1815 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1816 struct dwarf2_per_cu_data
*);
1818 static void dwarf2_mark (struct dwarf2_cu
*);
1820 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1822 static struct type
*get_die_type_at_offset (sect_offset
,
1823 struct dwarf2_per_cu_data
*);
1825 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1827 static void dwarf2_release_queue (void *dummy
);
1829 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1830 enum language pretend_language
);
1832 static void process_queue (void);
1834 static void find_file_and_directory (struct die_info
*die
,
1835 struct dwarf2_cu
*cu
,
1836 const char **name
, const char **comp_dir
);
1838 static char *file_full_name (int file
, struct line_header
*lh
,
1839 const char *comp_dir
);
1841 static const gdb_byte
*read_and_check_comp_unit_head
1842 (struct comp_unit_head
*header
,
1843 struct dwarf2_section_info
*section
,
1844 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
1845 int is_debug_types_section
);
1847 static void init_cutu_and_read_dies
1848 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
1849 int use_existing_cu
, int keep
,
1850 die_reader_func_ftype
*die_reader_func
, void *data
);
1852 static void init_cutu_and_read_dies_simple
1853 (struct dwarf2_per_cu_data
*this_cu
,
1854 die_reader_func_ftype
*die_reader_func
, void *data
);
1856 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1858 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1860 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1861 (struct dwp_file
*dwp_file
, const char *comp_dir
,
1862 ULONGEST signature
, int is_debug_types
);
1864 static struct dwp_file
*get_dwp_file (void);
1866 static struct dwo_unit
*lookup_dwo_comp_unit
1867 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1869 static struct dwo_unit
*lookup_dwo_type_unit
1870 (struct signatured_type
*, const char *, const char *);
1872 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1874 static void free_dwo_file_cleanup (void *);
1876 static void process_cu_includes (void);
1878 static void check_producer (struct dwarf2_cu
*cu
);
1880 static void free_line_header_voidp (void *arg
);
1882 /* Various complaints about symbol reading that don't abort the process. */
1885 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1887 complaint (&symfile_complaints
,
1888 _("statement list doesn't fit in .debug_line section"));
1892 dwarf2_debug_line_missing_file_complaint (void)
1894 complaint (&symfile_complaints
,
1895 _(".debug_line section has line data without a file"));
1899 dwarf2_debug_line_missing_end_sequence_complaint (void)
1901 complaint (&symfile_complaints
,
1902 _(".debug_line section has line "
1903 "program sequence without an end"));
1907 dwarf2_complex_location_expr_complaint (void)
1909 complaint (&symfile_complaints
, _("location expression too complex"));
1913 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1916 complaint (&symfile_complaints
,
1917 _("const value length mismatch for '%s', got %d, expected %d"),
1922 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
1924 complaint (&symfile_complaints
,
1925 _("debug info runs off end of %s section"
1927 get_section_name (section
),
1928 get_section_file_name (section
));
1932 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
1934 complaint (&symfile_complaints
,
1935 _("macro debug info contains a "
1936 "malformed macro definition:\n`%s'"),
1941 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1943 complaint (&symfile_complaints
,
1944 _("invalid attribute class or form for '%s' in '%s'"),
1948 /* Hash function for line_header_hash. */
1951 line_header_hash (const struct line_header
*ofs
)
1953 return ofs
->offset
.sect_off
^ ofs
->offset_in_dwz
;
1956 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1959 line_header_hash_voidp (const void *item
)
1961 const struct line_header
*ofs
= item
;
1963 return line_header_hash (ofs
);
1966 /* Equality function for line_header_hash. */
1969 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1971 const struct line_header
*ofs_lhs
= item_lhs
;
1972 const struct line_header
*ofs_rhs
= item_rhs
;
1974 return (ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
1975 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1981 /* Convert VALUE between big- and little-endian. */
1983 byte_swap (offset_type value
)
1987 result
= (value
& 0xff) << 24;
1988 result
|= (value
& 0xff00) << 8;
1989 result
|= (value
& 0xff0000) >> 8;
1990 result
|= (value
& 0xff000000) >> 24;
1994 #define MAYBE_SWAP(V) byte_swap (V)
1997 #define MAYBE_SWAP(V) (V)
1998 #endif /* WORDS_BIGENDIAN */
2000 /* Read the given attribute value as an address, taking the attribute's
2001 form into account. */
2004 attr_value_as_address (struct attribute
*attr
)
2008 if (attr
->form
!= DW_FORM_addr
&& attr
->form
!= DW_FORM_GNU_addr_index
)
2010 /* Aside from a few clearly defined exceptions, attributes that
2011 contain an address must always be in DW_FORM_addr form.
2012 Unfortunately, some compilers happen to be violating this
2013 requirement by encoding addresses using other forms, such
2014 as DW_FORM_data4 for example. For those broken compilers,
2015 we try to do our best, without any guarantee of success,
2016 to interpret the address correctly. It would also be nice
2017 to generate a complaint, but that would require us to maintain
2018 a list of legitimate cases where a non-address form is allowed,
2019 as well as update callers to pass in at least the CU's DWARF
2020 version. This is more overhead than what we're willing to
2021 expand for a pretty rare case. */
2022 addr
= DW_UNSND (attr
);
2025 addr
= DW_ADDR (attr
);
2030 /* The suffix for an index file. */
2031 #define INDEX_SUFFIX ".gdb-index"
2033 /* Try to locate the sections we need for DWARF 2 debugging
2034 information and return true if we have enough to do something.
2035 NAMES points to the dwarf2 section names, or is NULL if the standard
2036 ELF names are used. */
2039 dwarf2_has_info (struct objfile
*objfile
,
2040 const struct dwarf2_debug_sections
*names
)
2042 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2043 if (!dwarf2_per_objfile
)
2045 /* Initialize per-objfile state. */
2046 struct dwarf2_per_objfile
*data
2047 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
2049 memset (data
, 0, sizeof (*data
));
2050 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
2051 dwarf2_per_objfile
= data
;
2053 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
2055 dwarf2_per_objfile
->objfile
= objfile
;
2057 return (!dwarf2_per_objfile
->info
.is_virtual
2058 && dwarf2_per_objfile
->info
.s
.asection
!= NULL
2059 && !dwarf2_per_objfile
->abbrev
.is_virtual
2060 && dwarf2_per_objfile
->abbrev
.s
.asection
!= NULL
);
2063 /* Return the containing section of virtual section SECTION. */
2065 static struct dwarf2_section_info
*
2066 get_containing_section (const struct dwarf2_section_info
*section
)
2068 gdb_assert (section
->is_virtual
);
2069 return section
->s
.containing_section
;
2072 /* Return the bfd owner of SECTION. */
2075 get_section_bfd_owner (const struct dwarf2_section_info
*section
)
2077 if (section
->is_virtual
)
2079 section
= get_containing_section (section
);
2080 gdb_assert (!section
->is_virtual
);
2082 return section
->s
.asection
->owner
;
2085 /* Return the bfd section of SECTION.
2086 Returns NULL if the section is not present. */
2089 get_section_bfd_section (const struct dwarf2_section_info
*section
)
2091 if (section
->is_virtual
)
2093 section
= get_containing_section (section
);
2094 gdb_assert (!section
->is_virtual
);
2096 return section
->s
.asection
;
2099 /* Return the name of SECTION. */
2102 get_section_name (const struct dwarf2_section_info
*section
)
2104 asection
*sectp
= get_section_bfd_section (section
);
2106 gdb_assert (sectp
!= NULL
);
2107 return bfd_section_name (get_section_bfd_owner (section
), sectp
);
2110 /* Return the name of the file SECTION is in. */
2113 get_section_file_name (const struct dwarf2_section_info
*section
)
2115 bfd
*abfd
= get_section_bfd_owner (section
);
2117 return bfd_get_filename (abfd
);
2120 /* Return the id of SECTION.
2121 Returns 0 if SECTION doesn't exist. */
2124 get_section_id (const struct dwarf2_section_info
*section
)
2126 asection
*sectp
= get_section_bfd_section (section
);
2133 /* Return the flags of SECTION.
2134 SECTION (or containing section if this is a virtual section) must exist. */
2137 get_section_flags (const struct dwarf2_section_info
*section
)
2139 asection
*sectp
= get_section_bfd_section (section
);
2141 gdb_assert (sectp
!= NULL
);
2142 return bfd_get_section_flags (sectp
->owner
, sectp
);
2145 /* When loading sections, we look either for uncompressed section or for
2146 compressed section names. */
2149 section_is_p (const char *section_name
,
2150 const struct dwarf2_section_names
*names
)
2152 if (names
->normal
!= NULL
2153 && strcmp (section_name
, names
->normal
) == 0)
2155 if (names
->compressed
!= NULL
2156 && strcmp (section_name
, names
->compressed
) == 0)
2161 /* This function is mapped across the sections and remembers the
2162 offset and size of each of the debugging sections we are interested
2166 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
2168 const struct dwarf2_debug_sections
*names
;
2169 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
2172 names
= &dwarf2_elf_names
;
2174 names
= (const struct dwarf2_debug_sections
*) vnames
;
2176 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2179 else if (section_is_p (sectp
->name
, &names
->info
))
2181 dwarf2_per_objfile
->info
.s
.asection
= sectp
;
2182 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
2184 else if (section_is_p (sectp
->name
, &names
->abbrev
))
2186 dwarf2_per_objfile
->abbrev
.s
.asection
= sectp
;
2187 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
2189 else if (section_is_p (sectp
->name
, &names
->line
))
2191 dwarf2_per_objfile
->line
.s
.asection
= sectp
;
2192 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
2194 else if (section_is_p (sectp
->name
, &names
->loc
))
2196 dwarf2_per_objfile
->loc
.s
.asection
= sectp
;
2197 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
2199 else if (section_is_p (sectp
->name
, &names
->macinfo
))
2201 dwarf2_per_objfile
->macinfo
.s
.asection
= sectp
;
2202 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
2204 else if (section_is_p (sectp
->name
, &names
->macro
))
2206 dwarf2_per_objfile
->macro
.s
.asection
= sectp
;
2207 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
2209 else if (section_is_p (sectp
->name
, &names
->str
))
2211 dwarf2_per_objfile
->str
.s
.asection
= sectp
;
2212 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
2214 else if (section_is_p (sectp
->name
, &names
->addr
))
2216 dwarf2_per_objfile
->addr
.s
.asection
= sectp
;
2217 dwarf2_per_objfile
->addr
.size
= bfd_get_section_size (sectp
);
2219 else if (section_is_p (sectp
->name
, &names
->frame
))
2221 dwarf2_per_objfile
->frame
.s
.asection
= sectp
;
2222 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
2224 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
2226 dwarf2_per_objfile
->eh_frame
.s
.asection
= sectp
;
2227 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
2229 else if (section_is_p (sectp
->name
, &names
->ranges
))
2231 dwarf2_per_objfile
->ranges
.s
.asection
= sectp
;
2232 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
2234 else if (section_is_p (sectp
->name
, &names
->types
))
2236 struct dwarf2_section_info type_section
;
2238 memset (&type_section
, 0, sizeof (type_section
));
2239 type_section
.s
.asection
= sectp
;
2240 type_section
.size
= bfd_get_section_size (sectp
);
2242 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
2245 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
2247 dwarf2_per_objfile
->gdb_index
.s
.asection
= sectp
;
2248 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
2251 if ((bfd_get_section_flags (abfd
, sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2252 && bfd_section_vma (abfd
, sectp
) == 0)
2253 dwarf2_per_objfile
->has_section_at_zero
= 1;
2256 /* A helper function that decides whether a section is empty,
2260 dwarf2_section_empty_p (const struct dwarf2_section_info
*section
)
2262 if (section
->is_virtual
)
2263 return section
->size
== 0;
2264 return section
->s
.asection
== NULL
|| section
->size
== 0;
2267 /* Read the contents of the section INFO.
2268 OBJFILE is the main object file, but not necessarily the file where
2269 the section comes from. E.g., for DWO files the bfd of INFO is the bfd
2271 If the section is compressed, uncompress it before returning. */
2274 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
2278 gdb_byte
*buf
, *retbuf
;
2282 info
->buffer
= NULL
;
2285 if (dwarf2_section_empty_p (info
))
2288 sectp
= get_section_bfd_section (info
);
2290 /* If this is a virtual section we need to read in the real one first. */
2291 if (info
->is_virtual
)
2293 struct dwarf2_section_info
*containing_section
=
2294 get_containing_section (info
);
2296 gdb_assert (sectp
!= NULL
);
2297 if ((sectp
->flags
& SEC_RELOC
) != 0)
2299 error (_("Dwarf Error: DWP format V2 with relocations is not"
2300 " supported in section %s [in module %s]"),
2301 get_section_name (info
), get_section_file_name (info
));
2303 dwarf2_read_section (objfile
, containing_section
);
2304 /* Other code should have already caught virtual sections that don't
2306 gdb_assert (info
->virtual_offset
+ info
->size
2307 <= containing_section
->size
);
2308 /* If the real section is empty or there was a problem reading the
2309 section we shouldn't get here. */
2310 gdb_assert (containing_section
->buffer
!= NULL
);
2311 info
->buffer
= containing_section
->buffer
+ info
->virtual_offset
;
2315 /* If the section has relocations, we must read it ourselves.
2316 Otherwise we attach it to the BFD. */
2317 if ((sectp
->flags
& SEC_RELOC
) == 0)
2319 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
2323 buf
= obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
2326 /* When debugging .o files, we may need to apply relocations; see
2327 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2328 We never compress sections in .o files, so we only need to
2329 try this when the section is not compressed. */
2330 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
2333 info
->buffer
= retbuf
;
2337 abfd
= get_section_bfd_owner (info
);
2338 gdb_assert (abfd
!= NULL
);
2340 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
2341 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
2343 error (_("Dwarf Error: Can't read DWARF data"
2344 " in section %s [in module %s]"),
2345 bfd_section_name (abfd
, sectp
), bfd_get_filename (abfd
));
2349 /* A helper function that returns the size of a section in a safe way.
2350 If you are positive that the section has been read before using the
2351 size, then it is safe to refer to the dwarf2_section_info object's
2352 "size" field directly. In other cases, you must call this
2353 function, because for compressed sections the size field is not set
2354 correctly until the section has been read. */
2356 static bfd_size_type
2357 dwarf2_section_size (struct objfile
*objfile
,
2358 struct dwarf2_section_info
*info
)
2361 dwarf2_read_section (objfile
, info
);
2365 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2369 dwarf2_get_section_info (struct objfile
*objfile
,
2370 enum dwarf2_section_enum sect
,
2371 asection
**sectp
, const gdb_byte
**bufp
,
2372 bfd_size_type
*sizep
)
2374 struct dwarf2_per_objfile
*data
2375 = objfile_data (objfile
, dwarf2_objfile_data_key
);
2376 struct dwarf2_section_info
*info
;
2378 /* We may see an objfile without any DWARF, in which case we just
2389 case DWARF2_DEBUG_FRAME
:
2390 info
= &data
->frame
;
2392 case DWARF2_EH_FRAME
:
2393 info
= &data
->eh_frame
;
2396 gdb_assert_not_reached ("unexpected section");
2399 dwarf2_read_section (objfile
, info
);
2401 *sectp
= get_section_bfd_section (info
);
2402 *bufp
= info
->buffer
;
2403 *sizep
= info
->size
;
2406 /* A helper function to find the sections for a .dwz file. */
2409 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2411 struct dwz_file
*dwz_file
= arg
;
2413 /* Note that we only support the standard ELF names, because .dwz
2414 is ELF-only (at the time of writing). */
2415 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2417 dwz_file
->abbrev
.s
.asection
= sectp
;
2418 dwz_file
->abbrev
.size
= bfd_get_section_size (sectp
);
2420 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2422 dwz_file
->info
.s
.asection
= sectp
;
2423 dwz_file
->info
.size
= bfd_get_section_size (sectp
);
2425 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2427 dwz_file
->str
.s
.asection
= sectp
;
2428 dwz_file
->str
.size
= bfd_get_section_size (sectp
);
2430 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2432 dwz_file
->line
.s
.asection
= sectp
;
2433 dwz_file
->line
.size
= bfd_get_section_size (sectp
);
2435 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2437 dwz_file
->macro
.s
.asection
= sectp
;
2438 dwz_file
->macro
.size
= bfd_get_section_size (sectp
);
2440 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2442 dwz_file
->gdb_index
.s
.asection
= sectp
;
2443 dwz_file
->gdb_index
.size
= bfd_get_section_size (sectp
);
2447 /* Open the separate '.dwz' debug file, if needed. Return NULL if
2448 there is no .gnu_debugaltlink section in the file. Error if there
2449 is such a section but the file cannot be found. */
2451 static struct dwz_file
*
2452 dwarf2_get_dwz_file (void)
2456 struct cleanup
*cleanup
;
2457 const char *filename
;
2458 struct dwz_file
*result
;
2459 bfd_size_type buildid_len_arg
;
2463 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2464 return dwarf2_per_objfile
->dwz_file
;
2466 bfd_set_error (bfd_error_no_error
);
2467 data
= bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2468 &buildid_len_arg
, &buildid
);
2471 if (bfd_get_error () == bfd_error_no_error
)
2473 error (_("could not read '.gnu_debugaltlink' section: %s"),
2474 bfd_errmsg (bfd_get_error ()));
2476 cleanup
= make_cleanup (xfree
, data
);
2477 make_cleanup (xfree
, buildid
);
2479 buildid_len
= (size_t) buildid_len_arg
;
2481 filename
= (const char *) data
;
2482 if (!IS_ABSOLUTE_PATH (filename
))
2484 char *abs
= gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2487 make_cleanup (xfree
, abs
);
2488 abs
= ldirname (abs
);
2489 make_cleanup (xfree
, abs
);
2491 rel
= concat (abs
, SLASH_STRING
, filename
, (char *) NULL
);
2492 make_cleanup (xfree
, rel
);
2496 /* First try the file name given in the section. If that doesn't
2497 work, try to use the build-id instead. */
2498 dwz_bfd
= gdb_bfd_open (filename
, gnutarget
, -1);
2499 if (dwz_bfd
!= NULL
)
2501 if (!build_id_verify (dwz_bfd
, buildid_len
, buildid
))
2503 gdb_bfd_unref (dwz_bfd
);
2508 if (dwz_bfd
== NULL
)
2509 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2511 if (dwz_bfd
== NULL
)
2512 error (_("could not find '.gnu_debugaltlink' file for %s"),
2513 objfile_name (dwarf2_per_objfile
->objfile
));
2515 result
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
2517 result
->dwz_bfd
= dwz_bfd
;
2519 bfd_map_over_sections (dwz_bfd
, locate_dwz_sections
, result
);
2521 do_cleanups (cleanup
);
2523 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, dwz_bfd
);
2524 dwarf2_per_objfile
->dwz_file
= result
;
2528 /* DWARF quick_symbols_functions support. */
2530 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2531 unique line tables, so we maintain a separate table of all .debug_line
2532 derived entries to support the sharing.
2533 All the quick functions need is the list of file names. We discard the
2534 line_header when we're done and don't need to record it here. */
2535 struct quick_file_names
2537 /* The data used to construct the hash key. */
2538 struct stmt_list_hash hash
;
2540 /* The number of entries in file_names, real_names. */
2541 unsigned int num_file_names
;
2543 /* The file names from the line table, after being run through
2545 const char **file_names
;
2547 /* The file names from the line table after being run through
2548 gdb_realpath. These are computed lazily. */
2549 const char **real_names
;
2552 /* When using the index (and thus not using psymtabs), each CU has an
2553 object of this type. This is used to hold information needed by
2554 the various "quick" methods. */
2555 struct dwarf2_per_cu_quick_data
2557 /* The file table. This can be NULL if there was no file table
2558 or it's currently not read in.
2559 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2560 struct quick_file_names
*file_names
;
2562 /* The corresponding symbol table. This is NULL if symbols for this
2563 CU have not yet been read. */
2564 struct compunit_symtab
*compunit_symtab
;
2566 /* A temporary mark bit used when iterating over all CUs in
2567 expand_symtabs_matching. */
2568 unsigned int mark
: 1;
2570 /* True if we've tried to read the file table and found there isn't one.
2571 There will be no point in trying to read it again next time. */
2572 unsigned int no_file_data
: 1;
2575 /* Utility hash function for a stmt_list_hash. */
2578 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2582 if (stmt_list_hash
->dwo_unit
!= NULL
)
2583 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2584 v
+= stmt_list_hash
->line_offset
.sect_off
;
2588 /* Utility equality function for a stmt_list_hash. */
2591 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2592 const struct stmt_list_hash
*rhs
)
2594 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2596 if (lhs
->dwo_unit
!= NULL
2597 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2600 return lhs
->line_offset
.sect_off
== rhs
->line_offset
.sect_off
;
2603 /* Hash function for a quick_file_names. */
2606 hash_file_name_entry (const void *e
)
2608 const struct quick_file_names
*file_data
= e
;
2610 return hash_stmt_list_entry (&file_data
->hash
);
2613 /* Equality function for a quick_file_names. */
2616 eq_file_name_entry (const void *a
, const void *b
)
2618 const struct quick_file_names
*ea
= a
;
2619 const struct quick_file_names
*eb
= b
;
2621 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2624 /* Delete function for a quick_file_names. */
2627 delete_file_name_entry (void *e
)
2629 struct quick_file_names
*file_data
= e
;
2632 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2634 xfree ((void*) file_data
->file_names
[i
]);
2635 if (file_data
->real_names
)
2636 xfree ((void*) file_data
->real_names
[i
]);
2639 /* The space for the struct itself lives on objfile_obstack,
2640 so we don't free it here. */
2643 /* Create a quick_file_names hash table. */
2646 create_quick_file_names_table (unsigned int nr_initial_entries
)
2648 return htab_create_alloc (nr_initial_entries
,
2649 hash_file_name_entry
, eq_file_name_entry
,
2650 delete_file_name_entry
, xcalloc
, xfree
);
2653 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2654 have to be created afterwards. You should call age_cached_comp_units after
2655 processing PER_CU->CU. dw2_setup must have been already called. */
2658 load_cu (struct dwarf2_per_cu_data
*per_cu
)
2660 if (per_cu
->is_debug_types
)
2661 load_full_type_unit (per_cu
);
2663 load_full_comp_unit (per_cu
, language_minimal
);
2665 if (per_cu
->cu
== NULL
)
2666 return; /* Dummy CU. */
2668 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2671 /* Read in the symbols for PER_CU. */
2674 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2676 struct cleanup
*back_to
;
2678 /* Skip type_unit_groups, reading the type units they contain
2679 is handled elsewhere. */
2680 if (IS_TYPE_UNIT_GROUP (per_cu
))
2683 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2685 if (dwarf2_per_objfile
->using_index
2686 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2687 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2689 queue_comp_unit (per_cu
, language_minimal
);
2692 /* If we just loaded a CU from a DWO, and we're working with an index
2693 that may badly handle TUs, load all the TUs in that DWO as well.
2694 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2695 if (!per_cu
->is_debug_types
2696 && per_cu
->cu
!= NULL
2697 && per_cu
->cu
->dwo_unit
!= NULL
2698 && dwarf2_per_objfile
->index_table
!= NULL
2699 && dwarf2_per_objfile
->index_table
->version
<= 7
2700 /* DWP files aren't supported yet. */
2701 && get_dwp_file () == NULL
)
2702 queue_and_load_all_dwo_tus (per_cu
);
2707 /* Age the cache, releasing compilation units that have not
2708 been used recently. */
2709 age_cached_comp_units ();
2711 do_cleanups (back_to
);
2714 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2715 the objfile from which this CU came. Returns the resulting symbol
2718 static struct compunit_symtab
*
2719 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2721 gdb_assert (dwarf2_per_objfile
->using_index
);
2722 if (!per_cu
->v
.quick
->compunit_symtab
)
2724 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2725 increment_reading_symtab ();
2726 dw2_do_instantiate_symtab (per_cu
);
2727 process_cu_includes ();
2728 do_cleanups (back_to
);
2731 return per_cu
->v
.quick
->compunit_symtab
;
2734 /* Return the CU/TU given its index.
2736 This is intended for loops like:
2738 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2739 + dwarf2_per_objfile->n_type_units); ++i)
2741 struct dwarf2_per_cu_data *per_cu = dw2_get_cutu (i);
2747 static struct dwarf2_per_cu_data
*
2748 dw2_get_cutu (int index
)
2750 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2752 index
-= dwarf2_per_objfile
->n_comp_units
;
2753 gdb_assert (index
< dwarf2_per_objfile
->n_type_units
);
2754 return &dwarf2_per_objfile
->all_type_units
[index
]->per_cu
;
2757 return dwarf2_per_objfile
->all_comp_units
[index
];
2760 /* Return the CU given its index.
2761 This differs from dw2_get_cutu in that it's for when you know INDEX
2764 static struct dwarf2_per_cu_data
*
2765 dw2_get_cu (int index
)
2767 gdb_assert (index
>= 0 && index
< dwarf2_per_objfile
->n_comp_units
);
2769 return dwarf2_per_objfile
->all_comp_units
[index
];
2772 /* A helper for create_cus_from_index that handles a given list of
2776 create_cus_from_index_list (struct objfile
*objfile
,
2777 const gdb_byte
*cu_list
, offset_type n_elements
,
2778 struct dwarf2_section_info
*section
,
2784 for (i
= 0; i
< n_elements
; i
+= 2)
2786 struct dwarf2_per_cu_data
*the_cu
;
2787 ULONGEST offset
, length
;
2789 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2790 offset
= extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2791 length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2794 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2795 struct dwarf2_per_cu_data
);
2796 the_cu
->offset
.sect_off
= offset
;
2797 the_cu
->length
= length
;
2798 the_cu
->objfile
= objfile
;
2799 the_cu
->section
= section
;
2800 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2801 struct dwarf2_per_cu_quick_data
);
2802 the_cu
->is_dwz
= is_dwz
;
2803 dwarf2_per_objfile
->all_comp_units
[base_offset
+ i
/ 2] = the_cu
;
2807 /* Read the CU list from the mapped index, and use it to create all
2808 the CU objects for this objfile. */
2811 create_cus_from_index (struct objfile
*objfile
,
2812 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2813 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2815 struct dwz_file
*dwz
;
2817 dwarf2_per_objfile
->n_comp_units
= (cu_list_elements
+ dwz_elements
) / 2;
2818 dwarf2_per_objfile
->all_comp_units
2819 = obstack_alloc (&objfile
->objfile_obstack
,
2820 dwarf2_per_objfile
->n_comp_units
2821 * sizeof (struct dwarf2_per_cu_data
*));
2823 create_cus_from_index_list (objfile
, cu_list
, cu_list_elements
,
2824 &dwarf2_per_objfile
->info
, 0, 0);
2826 if (dwz_elements
== 0)
2829 dwz
= dwarf2_get_dwz_file ();
2830 create_cus_from_index_list (objfile
, dwz_list
, dwz_elements
, &dwz
->info
, 1,
2831 cu_list_elements
/ 2);
2834 /* Create the signatured type hash table from the index. */
2837 create_signatured_type_table_from_index (struct objfile
*objfile
,
2838 struct dwarf2_section_info
*section
,
2839 const gdb_byte
*bytes
,
2840 offset_type elements
)
2843 htab_t sig_types_hash
;
2845 dwarf2_per_objfile
->n_type_units
2846 = dwarf2_per_objfile
->n_allocated_type_units
2848 dwarf2_per_objfile
->all_type_units
2849 = xmalloc (dwarf2_per_objfile
->n_type_units
2850 * sizeof (struct signatured_type
*));
2852 sig_types_hash
= allocate_signatured_type_table (objfile
);
2854 for (i
= 0; i
< elements
; i
+= 3)
2856 struct signatured_type
*sig_type
;
2857 ULONGEST offset
, type_offset_in_tu
, signature
;
2860 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2861 offset
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2862 type_offset_in_tu
= extract_unsigned_integer (bytes
+ 8, 8,
2864 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2867 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2868 struct signatured_type
);
2869 sig_type
->signature
= signature
;
2870 sig_type
->type_offset_in_tu
.cu_off
= type_offset_in_tu
;
2871 sig_type
->per_cu
.is_debug_types
= 1;
2872 sig_type
->per_cu
.section
= section
;
2873 sig_type
->per_cu
.offset
.sect_off
= offset
;
2874 sig_type
->per_cu
.objfile
= objfile
;
2875 sig_type
->per_cu
.v
.quick
2876 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2877 struct dwarf2_per_cu_quick_data
);
2879 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
2882 dwarf2_per_objfile
->all_type_units
[i
/ 3] = sig_type
;
2885 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2888 /* Read the address map data from the mapped index, and use it to
2889 populate the objfile's psymtabs_addrmap. */
2892 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
2894 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2895 const gdb_byte
*iter
, *end
;
2896 struct obstack temp_obstack
;
2897 struct addrmap
*mutable_map
;
2898 struct cleanup
*cleanup
;
2901 obstack_init (&temp_obstack
);
2902 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2903 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2905 iter
= index
->address_table
;
2906 end
= iter
+ index
->address_table_size
;
2908 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2912 ULONGEST hi
, lo
, cu_index
;
2913 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2915 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2917 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2922 complaint (&symfile_complaints
,
2923 _(".gdb_index address table has invalid range (%s - %s)"),
2924 hex_string (lo
), hex_string (hi
));
2928 if (cu_index
>= dwarf2_per_objfile
->n_comp_units
)
2930 complaint (&symfile_complaints
,
2931 _(".gdb_index address table has invalid CU number %u"),
2932 (unsigned) cu_index
);
2936 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
);
2937 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
);
2938 addrmap_set_empty (mutable_map
, lo
, hi
- 1, dw2_get_cutu (cu_index
));
2941 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
2942 &objfile
->objfile_obstack
);
2943 do_cleanups (cleanup
);
2946 /* The hash function for strings in the mapped index. This is the same as
2947 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2948 implementation. This is necessary because the hash function is tied to the
2949 format of the mapped index file. The hash values do not have to match with
2952 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2955 mapped_index_string_hash (int index_version
, const void *p
)
2957 const unsigned char *str
= (const unsigned char *) p
;
2961 while ((c
= *str
++) != 0)
2963 if (index_version
>= 5)
2965 r
= r
* 67 + c
- 113;
2971 /* Find a slot in the mapped index INDEX for the object named NAME.
2972 If NAME is found, set *VEC_OUT to point to the CU vector in the
2973 constant pool and return 1. If NAME cannot be found, return 0. */
2976 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2977 offset_type
**vec_out
)
2979 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2981 offset_type slot
, step
;
2982 int (*cmp
) (const char *, const char *);
2984 if (current_language
->la_language
== language_cplus
2985 || current_language
->la_language
== language_java
2986 || current_language
->la_language
== language_fortran
2987 || current_language
->la_language
== language_d
)
2989 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2992 if (strchr (name
, '(') != NULL
)
2994 char *without_params
= cp_remove_params (name
);
2996 if (without_params
!= NULL
)
2998 make_cleanup (xfree
, without_params
);
2999 name
= without_params
;
3004 /* Index version 4 did not support case insensitive searches. But the
3005 indices for case insensitive languages are built in lowercase, therefore
3006 simulate our NAME being searched is also lowercased. */
3007 hash
= mapped_index_string_hash ((index
->version
== 4
3008 && case_sensitivity
== case_sensitive_off
3009 ? 5 : index
->version
),
3012 slot
= hash
& (index
->symbol_table_slots
- 1);
3013 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
3014 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3018 /* Convert a slot number to an offset into the table. */
3019 offset_type i
= 2 * slot
;
3021 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
3023 do_cleanups (back_to
);
3027 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
3028 if (!cmp (name
, str
))
3030 *vec_out
= (offset_type
*) (index
->constant_pool
3031 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
3032 do_cleanups (back_to
);
3036 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
3040 /* A helper function that reads the .gdb_index from SECTION and fills
3041 in MAP. FILENAME is the name of the file containing the section;
3042 it is used for error reporting. DEPRECATED_OK is nonzero if it is
3043 ok to use deprecated sections.
3045 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3046 out parameters that are filled in with information about the CU and
3047 TU lists in the section.
3049 Returns 1 if all went well, 0 otherwise. */
3052 read_index_from_section (struct objfile
*objfile
,
3053 const char *filename
,
3055 struct dwarf2_section_info
*section
,
3056 struct mapped_index
*map
,
3057 const gdb_byte
**cu_list
,
3058 offset_type
*cu_list_elements
,
3059 const gdb_byte
**types_list
,
3060 offset_type
*types_list_elements
)
3062 const gdb_byte
*addr
;
3063 offset_type version
;
3064 offset_type
*metadata
;
3067 if (dwarf2_section_empty_p (section
))
3070 /* Older elfutils strip versions could keep the section in the main
3071 executable while splitting it for the separate debug info file. */
3072 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
3075 dwarf2_read_section (objfile
, section
);
3077 addr
= section
->buffer
;
3078 /* Version check. */
3079 version
= MAYBE_SWAP (*(offset_type
*) addr
);
3080 /* Versions earlier than 3 emitted every copy of a psymbol. This
3081 causes the index to behave very poorly for certain requests. Version 3
3082 contained incomplete addrmap. So, it seems better to just ignore such
3086 static int warning_printed
= 0;
3087 if (!warning_printed
)
3089 warning (_("Skipping obsolete .gdb_index section in %s."),
3091 warning_printed
= 1;
3095 /* Index version 4 uses a different hash function than index version
3098 Versions earlier than 6 did not emit psymbols for inlined
3099 functions. Using these files will cause GDB not to be able to
3100 set breakpoints on inlined functions by name, so we ignore these
3101 indices unless the user has done
3102 "set use-deprecated-index-sections on". */
3103 if (version
< 6 && !deprecated_ok
)
3105 static int warning_printed
= 0;
3106 if (!warning_printed
)
3109 Skipping deprecated .gdb_index section in %s.\n\
3110 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3111 to use the section anyway."),
3113 warning_printed
= 1;
3117 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3118 of the TU (for symbols coming from TUs),
3119 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3120 Plus gold-generated indices can have duplicate entries for global symbols,
3121 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3122 These are just performance bugs, and we can't distinguish gdb-generated
3123 indices from gold-generated ones, so issue no warning here. */
3125 /* Indexes with higher version than the one supported by GDB may be no
3126 longer backward compatible. */
3130 map
->version
= version
;
3131 map
->total_size
= section
->size
;
3133 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3136 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3137 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3141 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3142 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3143 - MAYBE_SWAP (metadata
[i
]))
3147 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3148 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
3149 - MAYBE_SWAP (metadata
[i
]));
3152 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
3153 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
3154 - MAYBE_SWAP (metadata
[i
]))
3155 / (2 * sizeof (offset_type
)));
3158 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3164 /* Read the index file. If everything went ok, initialize the "quick"
3165 elements of all the CUs and return 1. Otherwise, return 0. */
3168 dwarf2_read_index (struct objfile
*objfile
)
3170 struct mapped_index local_map
, *map
;
3171 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3172 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3173 struct dwz_file
*dwz
;
3175 if (!read_index_from_section (objfile
, objfile_name (objfile
),
3176 use_deprecated_index_sections
,
3177 &dwarf2_per_objfile
->gdb_index
, &local_map
,
3178 &cu_list
, &cu_list_elements
,
3179 &types_list
, &types_list_elements
))
3182 /* Don't use the index if it's empty. */
3183 if (local_map
.symbol_table_slots
== 0)
3186 /* If there is a .dwz file, read it so we can get its CU list as
3188 dwz
= dwarf2_get_dwz_file ();
3191 struct mapped_index dwz_map
;
3192 const gdb_byte
*dwz_types_ignore
;
3193 offset_type dwz_types_elements_ignore
;
3195 if (!read_index_from_section (objfile
, bfd_get_filename (dwz
->dwz_bfd
),
3197 &dwz
->gdb_index
, &dwz_map
,
3198 &dwz_list
, &dwz_list_elements
,
3200 &dwz_types_elements_ignore
))
3202 warning (_("could not read '.gdb_index' section from %s; skipping"),
3203 bfd_get_filename (dwz
->dwz_bfd
));
3208 create_cus_from_index (objfile
, cu_list
, cu_list_elements
, dwz_list
,
3211 if (types_list_elements
)
3213 struct dwarf2_section_info
*section
;
3215 /* We can only handle a single .debug_types when we have an
3217 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
3220 section
= VEC_index (dwarf2_section_info_def
,
3221 dwarf2_per_objfile
->types
, 0);
3223 create_signatured_type_table_from_index (objfile
, section
, types_list
,
3224 types_list_elements
);
3227 create_addrmap_from_index (objfile
, &local_map
);
3229 map
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (struct mapped_index
));
3232 dwarf2_per_objfile
->index_table
= map
;
3233 dwarf2_per_objfile
->using_index
= 1;
3234 dwarf2_per_objfile
->quick_file_names_table
=
3235 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3240 /* A helper for the "quick" functions which sets the global
3241 dwarf2_per_objfile according to OBJFILE. */
3244 dw2_setup (struct objfile
*objfile
)
3246 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
3247 gdb_assert (dwarf2_per_objfile
);
3250 /* die_reader_func for dw2_get_file_names. */
3253 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3254 const gdb_byte
*info_ptr
,
3255 struct die_info
*comp_unit_die
,
3259 struct dwarf2_cu
*cu
= reader
->cu
;
3260 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3261 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3262 struct dwarf2_per_cu_data
*lh_cu
;
3263 struct line_header
*lh
;
3264 struct attribute
*attr
;
3266 const char *name
, *comp_dir
;
3268 struct quick_file_names
*qfn
;
3269 unsigned int line_offset
;
3271 gdb_assert (! this_cu
->is_debug_types
);
3273 /* Our callers never want to match partial units -- instead they
3274 will match the enclosing full CU. */
3275 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3277 this_cu
->v
.quick
->no_file_data
= 1;
3286 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3289 struct quick_file_names find_entry
;
3291 line_offset
= DW_UNSND (attr
);
3293 /* We may have already read in this line header (TU line header sharing).
3294 If we have we're done. */
3295 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3296 find_entry
.hash
.line_offset
.sect_off
= line_offset
;
3297 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
3298 &find_entry
, INSERT
);
3301 lh_cu
->v
.quick
->file_names
= *slot
;
3305 lh
= dwarf_decode_line_header (line_offset
, cu
);
3309 lh_cu
->v
.quick
->no_file_data
= 1;
3313 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
3314 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3315 qfn
->hash
.line_offset
.sect_off
= line_offset
;
3316 gdb_assert (slot
!= NULL
);
3319 find_file_and_directory (comp_unit_die
, cu
, &name
, &comp_dir
);
3321 qfn
->num_file_names
= lh
->num_file_names
;
3322 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
3323 lh
->num_file_names
* sizeof (char *));
3324 for (i
= 0; i
< lh
->num_file_names
; ++i
)
3325 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
3326 qfn
->real_names
= NULL
;
3328 free_line_header (lh
);
3330 lh_cu
->v
.quick
->file_names
= qfn
;
3333 /* A helper for the "quick" functions which attempts to read the line
3334 table for THIS_CU. */
3336 static struct quick_file_names
*
3337 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3339 /* This should never be called for TUs. */
3340 gdb_assert (! this_cu
->is_debug_types
);
3341 /* Nor type unit groups. */
3342 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3344 if (this_cu
->v
.quick
->file_names
!= NULL
)
3345 return this_cu
->v
.quick
->file_names
;
3346 /* If we know there is no line data, no point in looking again. */
3347 if (this_cu
->v
.quick
->no_file_data
)
3350 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
3352 if (this_cu
->v
.quick
->no_file_data
)
3354 return this_cu
->v
.quick
->file_names
;
3357 /* A helper for the "quick" functions which computes and caches the
3358 real path for a given file name from the line table. */
3361 dw2_get_real_path (struct objfile
*objfile
,
3362 struct quick_file_names
*qfn
, int index
)
3364 if (qfn
->real_names
== NULL
)
3365 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3366 qfn
->num_file_names
, const char *);
3368 if (qfn
->real_names
[index
] == NULL
)
3369 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
3371 return qfn
->real_names
[index
];
3374 static struct symtab
*
3375 dw2_find_last_source_symtab (struct objfile
*objfile
)
3377 struct compunit_symtab
*cust
;
3380 dw2_setup (objfile
);
3381 index
= dwarf2_per_objfile
->n_comp_units
- 1;
3382 cust
= dw2_instantiate_symtab (dw2_get_cutu (index
));
3385 return compunit_primary_filetab (cust
);
3388 /* Traversal function for dw2_forget_cached_source_info. */
3391 dw2_free_cached_file_names (void **slot
, void *info
)
3393 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3395 if (file_data
->real_names
)
3399 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3401 xfree ((void*) file_data
->real_names
[i
]);
3402 file_data
->real_names
[i
] = NULL
;
3410 dw2_forget_cached_source_info (struct objfile
*objfile
)
3412 dw2_setup (objfile
);
3414 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3415 dw2_free_cached_file_names
, NULL
);
3418 /* Helper function for dw2_map_symtabs_matching_filename that expands
3419 the symtabs and calls the iterator. */
3422 dw2_map_expand_apply (struct objfile
*objfile
,
3423 struct dwarf2_per_cu_data
*per_cu
,
3424 const char *name
, const char *real_path
,
3425 int (*callback
) (struct symtab
*, void *),
3428 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3430 /* Don't visit already-expanded CUs. */
3431 if (per_cu
->v
.quick
->compunit_symtab
)
3434 /* This may expand more than one symtab, and we want to iterate over
3436 dw2_instantiate_symtab (per_cu
);
3438 return iterate_over_some_symtabs (name
, real_path
, callback
, data
,
3439 objfile
->compunit_symtabs
, last_made
);
3442 /* Implementation of the map_symtabs_matching_filename method. */
3445 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
3446 const char *real_path
,
3447 int (*callback
) (struct symtab
*, void *),
3451 const char *name_basename
= lbasename (name
);
3453 dw2_setup (objfile
);
3455 /* The rule is CUs specify all the files, including those used by
3456 any TU, so there's no need to scan TUs here. */
3458 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3461 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3462 struct quick_file_names
*file_data
;
3464 /* We only need to look at symtabs not already expanded. */
3465 if (per_cu
->v
.quick
->compunit_symtab
)
3468 file_data
= dw2_get_file_names (per_cu
);
3469 if (file_data
== NULL
)
3472 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3474 const char *this_name
= file_data
->file_names
[j
];
3475 const char *this_real_name
;
3477 if (compare_filenames_for_search (this_name
, name
))
3479 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3485 /* Before we invoke realpath, which can get expensive when many
3486 files are involved, do a quick comparison of the basenames. */
3487 if (! basenames_may_differ
3488 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3491 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3492 if (compare_filenames_for_search (this_real_name
, name
))
3494 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3500 if (real_path
!= NULL
)
3502 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3503 gdb_assert (IS_ABSOLUTE_PATH (name
));
3504 if (this_real_name
!= NULL
3505 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3507 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3519 /* Struct used to manage iterating over all CUs looking for a symbol. */
3521 struct dw2_symtab_iterator
3523 /* The internalized form of .gdb_index. */
3524 struct mapped_index
*index
;
3525 /* If non-zero, only look for symbols that match BLOCK_INDEX. */
3526 int want_specific_block
;
3527 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
3528 Unused if !WANT_SPECIFIC_BLOCK. */
3530 /* The kind of symbol we're looking for. */
3532 /* The list of CUs from the index entry of the symbol,
3533 or NULL if not found. */
3535 /* The next element in VEC to look at. */
3537 /* The number of elements in VEC, or zero if there is no match. */
3539 /* Have we seen a global version of the symbol?
3540 If so we can ignore all further global instances.
3541 This is to work around gold/15646, inefficient gold-generated
3546 /* Initialize the index symtab iterator ITER.
3547 If WANT_SPECIFIC_BLOCK is non-zero, only look for symbols
3548 in block BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
3551 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3552 struct mapped_index
*index
,
3553 int want_specific_block
,
3558 iter
->index
= index
;
3559 iter
->want_specific_block
= want_specific_block
;
3560 iter
->block_index
= block_index
;
3561 iter
->domain
= domain
;
3563 iter
->global_seen
= 0;
3565 if (find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3566 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3574 /* Return the next matching CU or NULL if there are no more. */
3576 static struct dwarf2_per_cu_data
*
3577 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3579 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3581 offset_type cu_index_and_attrs
=
3582 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3583 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3584 struct dwarf2_per_cu_data
*per_cu
;
3585 int want_static
= iter
->block_index
!= GLOBAL_BLOCK
;
3586 /* This value is only valid for index versions >= 7. */
3587 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3588 gdb_index_symbol_kind symbol_kind
=
3589 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3590 /* Only check the symbol attributes if they're present.
3591 Indices prior to version 7 don't record them,
3592 and indices >= 7 may elide them for certain symbols
3593 (gold does this). */
3595 (iter
->index
->version
>= 7
3596 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3598 /* Don't crash on bad data. */
3599 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
3600 + dwarf2_per_objfile
->n_type_units
))
3602 complaint (&symfile_complaints
,
3603 _(".gdb_index entry has bad CU index"
3605 objfile_name (dwarf2_per_objfile
->objfile
));
3609 per_cu
= dw2_get_cutu (cu_index
);
3611 /* Skip if already read in. */
3612 if (per_cu
->v
.quick
->compunit_symtab
)
3615 /* Check static vs global. */
3618 if (iter
->want_specific_block
3619 && want_static
!= is_static
)
3621 /* Work around gold/15646. */
3622 if (!is_static
&& iter
->global_seen
)
3625 iter
->global_seen
= 1;
3628 /* Only check the symbol's kind if it has one. */
3631 switch (iter
->domain
)
3634 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3635 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3636 /* Some types are also in VAR_DOMAIN. */
3637 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3641 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3645 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3660 static struct compunit_symtab
*
3661 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
3662 const char *name
, domain_enum domain
)
3664 struct compunit_symtab
*stab_best
= NULL
;
3665 struct mapped_index
*index
;
3667 dw2_setup (objfile
);
3669 index
= dwarf2_per_objfile
->index_table
;
3671 /* index is NULL if OBJF_READNOW. */
3674 struct dw2_symtab_iterator iter
;
3675 struct dwarf2_per_cu_data
*per_cu
;
3677 dw2_symtab_iter_init (&iter
, index
, 1, block_index
, domain
, name
);
3679 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3681 struct symbol
*sym
, *with_opaque
= NULL
;
3682 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
);
3683 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3684 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3686 sym
= block_find_symbol (block
, name
, domain
,
3687 block_find_non_opaque_type_preferred
,
3690 /* Some caution must be observed with overloaded functions
3691 and methods, since the index will not contain any overload
3692 information (but NAME might contain it). */
3695 && strcmp_iw (SYMBOL_SEARCH_NAME (sym
), name
) == 0)
3697 if (with_opaque
!= NULL
3698 && strcmp_iw (SYMBOL_SEARCH_NAME (with_opaque
), name
) == 0)
3701 /* Keep looking through other CUs. */
3709 dw2_print_stats (struct objfile
*objfile
)
3711 int i
, total
, count
;
3713 dw2_setup (objfile
);
3714 total
= dwarf2_per_objfile
->n_comp_units
+ dwarf2_per_objfile
->n_type_units
;
3716 for (i
= 0; i
< total
; ++i
)
3718 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
3720 if (!per_cu
->v
.quick
->compunit_symtab
)
3723 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3724 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3727 /* This dumps minimal information about the index.
3728 It is called via "mt print objfiles".
3729 One use is to verify .gdb_index has been loaded by the
3730 gdb.dwarf2/gdb-index.exp testcase. */
3733 dw2_dump (struct objfile
*objfile
)
3735 dw2_setup (objfile
);
3736 gdb_assert (dwarf2_per_objfile
->using_index
);
3737 printf_filtered (".gdb_index:");
3738 if (dwarf2_per_objfile
->index_table
!= NULL
)
3740 printf_filtered (" version %d\n",
3741 dwarf2_per_objfile
->index_table
->version
);
3744 printf_filtered (" faked for \"readnow\"\n");
3745 printf_filtered ("\n");
3749 dw2_relocate (struct objfile
*objfile
,
3750 const struct section_offsets
*new_offsets
,
3751 const struct section_offsets
*delta
)
3753 /* There's nothing to relocate here. */
3757 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3758 const char *func_name
)
3760 struct mapped_index
*index
;
3762 dw2_setup (objfile
);
3764 index
= dwarf2_per_objfile
->index_table
;
3766 /* index is NULL if OBJF_READNOW. */
3769 struct dw2_symtab_iterator iter
;
3770 struct dwarf2_per_cu_data
*per_cu
;
3772 /* Note: It doesn't matter what we pass for block_index here. */
3773 dw2_symtab_iter_init (&iter
, index
, 0, GLOBAL_BLOCK
, VAR_DOMAIN
,
3776 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3777 dw2_instantiate_symtab (per_cu
);
3782 dw2_expand_all_symtabs (struct objfile
*objfile
)
3786 dw2_setup (objfile
);
3788 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3789 + dwarf2_per_objfile
->n_type_units
); ++i
)
3791 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
3793 dw2_instantiate_symtab (per_cu
);
3798 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3799 const char *fullname
)
3803 dw2_setup (objfile
);
3805 /* We don't need to consider type units here.
3806 This is only called for examining code, e.g. expand_line_sal.
3807 There can be an order of magnitude (or more) more type units
3808 than comp units, and we avoid them if we can. */
3810 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3813 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
3814 struct quick_file_names
*file_data
;
3816 /* We only need to look at symtabs not already expanded. */
3817 if (per_cu
->v
.quick
->compunit_symtab
)
3820 file_data
= dw2_get_file_names (per_cu
);
3821 if (file_data
== NULL
)
3824 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3826 const char *this_fullname
= file_data
->file_names
[j
];
3828 if (filename_cmp (this_fullname
, fullname
) == 0)
3830 dw2_instantiate_symtab (per_cu
);
3838 dw2_map_matching_symbols (struct objfile
*objfile
,
3839 const char * name
, domain_enum domain
,
3841 int (*callback
) (struct block
*,
3842 struct symbol
*, void *),
3843 void *data
, symbol_compare_ftype
*match
,
3844 symbol_compare_ftype
*ordered_compare
)
3846 /* Currently unimplemented; used for Ada. The function can be called if the
3847 current language is Ada for a non-Ada objfile using GNU index. As Ada
3848 does not look for non-Ada symbols this function should just return. */
3852 dw2_expand_symtabs_matching
3853 (struct objfile
*objfile
,
3854 expand_symtabs_file_matcher_ftype
*file_matcher
,
3855 expand_symtabs_symbol_matcher_ftype
*symbol_matcher
,
3856 expand_symtabs_exp_notify_ftype
*expansion_notify
,
3857 enum search_domain kind
,
3862 struct mapped_index
*index
;
3864 dw2_setup (objfile
);
3866 /* index_table is NULL if OBJF_READNOW. */
3867 if (!dwarf2_per_objfile
->index_table
)
3869 index
= dwarf2_per_objfile
->index_table
;
3871 if (file_matcher
!= NULL
)
3873 struct cleanup
*cleanup
;
3874 htab_t visited_found
, visited_not_found
;
3876 visited_found
= htab_create_alloc (10,
3877 htab_hash_pointer
, htab_eq_pointer
,
3878 NULL
, xcalloc
, xfree
);
3879 cleanup
= make_cleanup_htab_delete (visited_found
);
3880 visited_not_found
= htab_create_alloc (10,
3881 htab_hash_pointer
, htab_eq_pointer
,
3882 NULL
, xcalloc
, xfree
);
3883 make_cleanup_htab_delete (visited_not_found
);
3885 /* The rule is CUs specify all the files, including those used by
3886 any TU, so there's no need to scan TUs here. */
3888 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3891 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3892 struct quick_file_names
*file_data
;
3897 per_cu
->v
.quick
->mark
= 0;
3899 /* We only need to look at symtabs not already expanded. */
3900 if (per_cu
->v
.quick
->compunit_symtab
)
3903 file_data
= dw2_get_file_names (per_cu
);
3904 if (file_data
== NULL
)
3907 if (htab_find (visited_not_found
, file_data
) != NULL
)
3909 else if (htab_find (visited_found
, file_data
) != NULL
)
3911 per_cu
->v
.quick
->mark
= 1;
3915 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3917 const char *this_real_name
;
3919 if (file_matcher (file_data
->file_names
[j
], data
, 0))
3921 per_cu
->v
.quick
->mark
= 1;
3925 /* Before we invoke realpath, which can get expensive when many
3926 files are involved, do a quick comparison of the basenames. */
3927 if (!basenames_may_differ
3928 && !file_matcher (lbasename (file_data
->file_names
[j
]),
3932 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3933 if (file_matcher (this_real_name
, data
, 0))
3935 per_cu
->v
.quick
->mark
= 1;
3940 slot
= htab_find_slot (per_cu
->v
.quick
->mark
3942 : visited_not_found
,
3947 do_cleanups (cleanup
);
3950 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
3952 offset_type idx
= 2 * iter
;
3954 offset_type
*vec
, vec_len
, vec_idx
;
3955 int global_seen
= 0;
3959 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
3962 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
3964 if (! (*symbol_matcher
) (name
, data
))
3967 /* The name was matched, now expand corresponding CUs that were
3969 vec
= (offset_type
*) (index
->constant_pool
3970 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
3971 vec_len
= MAYBE_SWAP (vec
[0]);
3972 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
3974 struct dwarf2_per_cu_data
*per_cu
;
3975 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
3976 /* This value is only valid for index versions >= 7. */
3977 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3978 gdb_index_symbol_kind symbol_kind
=
3979 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3980 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3981 /* Only check the symbol attributes if they're present.
3982 Indices prior to version 7 don't record them,
3983 and indices >= 7 may elide them for certain symbols
3984 (gold does this). */
3986 (index
->version
>= 7
3987 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3989 /* Work around gold/15646. */
3992 if (!is_static
&& global_seen
)
3998 /* Only check the symbol's kind if it has one. */
4003 case VARIABLES_DOMAIN
:
4004 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4007 case FUNCTIONS_DOMAIN
:
4008 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4012 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4020 /* Don't crash on bad data. */
4021 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
4022 + dwarf2_per_objfile
->n_type_units
))
4024 complaint (&symfile_complaints
,
4025 _(".gdb_index entry has bad CU index"
4026 " [in module %s]"), objfile_name (objfile
));
4030 per_cu
= dw2_get_cutu (cu_index
);
4031 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4033 int symtab_was_null
=
4034 (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4036 dw2_instantiate_symtab (per_cu
);
4038 if (expansion_notify
!= NULL
4040 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
4042 expansion_notify (per_cu
->v
.quick
->compunit_symtab
,
4050 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4053 static struct compunit_symtab
*
4054 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4059 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4060 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4063 if (cust
->includes
== NULL
)
4066 for (i
= 0; cust
->includes
[i
]; ++i
)
4068 struct compunit_symtab
*s
= cust
->includes
[i
];
4070 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4078 static struct compunit_symtab
*
4079 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4080 struct bound_minimal_symbol msymbol
,
4082 struct obj_section
*section
,
4085 struct dwarf2_per_cu_data
*data
;
4086 struct compunit_symtab
*result
;
4088 dw2_setup (objfile
);
4090 if (!objfile
->psymtabs_addrmap
)
4093 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
4097 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
4098 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4099 paddress (get_objfile_arch (objfile
), pc
));
4102 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
),
4104 gdb_assert (result
!= NULL
);
4109 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4110 void *data
, int need_fullname
)
4113 struct cleanup
*cleanup
;
4114 htab_t visited
= htab_create_alloc (10, htab_hash_pointer
, htab_eq_pointer
,
4115 NULL
, xcalloc
, xfree
);
4117 cleanup
= make_cleanup_htab_delete (visited
);
4118 dw2_setup (objfile
);
4120 /* The rule is CUs specify all the files, including those used by
4121 any TU, so there's no need to scan TUs here.
4122 We can ignore file names coming from already-expanded CUs. */
4124 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4126 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
4128 if (per_cu
->v
.quick
->compunit_symtab
)
4130 void **slot
= htab_find_slot (visited
, per_cu
->v
.quick
->file_names
,
4133 *slot
= per_cu
->v
.quick
->file_names
;
4137 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4140 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
4141 struct quick_file_names
*file_data
;
4144 /* We only need to look at symtabs not already expanded. */
4145 if (per_cu
->v
.quick
->compunit_symtab
)
4148 file_data
= dw2_get_file_names (per_cu
);
4149 if (file_data
== NULL
)
4152 slot
= htab_find_slot (visited
, file_data
, INSERT
);
4155 /* Already visited. */
4160 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
4162 const char *this_real_name
;
4165 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4167 this_real_name
= NULL
;
4168 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
4172 do_cleanups (cleanup
);
4176 dw2_has_symbols (struct objfile
*objfile
)
4181 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4184 dw2_find_last_source_symtab
,
4185 dw2_forget_cached_source_info
,
4186 dw2_map_symtabs_matching_filename
,
4191 dw2_expand_symtabs_for_function
,
4192 dw2_expand_all_symtabs
,
4193 dw2_expand_symtabs_with_fullname
,
4194 dw2_map_matching_symbols
,
4195 dw2_expand_symtabs_matching
,
4196 dw2_find_pc_sect_compunit_symtab
,
4197 dw2_map_symbol_filenames
4200 /* Initialize for reading DWARF for this objfile. Return 0 if this
4201 file will use psymtabs, or 1 if using the GNU index. */
4204 dwarf2_initialize_objfile (struct objfile
*objfile
)
4206 /* If we're about to read full symbols, don't bother with the
4207 indices. In this case we also don't care if some other debug
4208 format is making psymtabs, because they are all about to be
4210 if ((objfile
->flags
& OBJF_READNOW
))
4214 dwarf2_per_objfile
->using_index
= 1;
4215 create_all_comp_units (objfile
);
4216 create_all_type_units (objfile
);
4217 dwarf2_per_objfile
->quick_file_names_table
=
4218 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
4220 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
4221 + dwarf2_per_objfile
->n_type_units
); ++i
)
4223 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
4225 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4226 struct dwarf2_per_cu_quick_data
);
4229 /* Return 1 so that gdb sees the "quick" functions. However,
4230 these functions will be no-ops because we will have expanded
4235 if (dwarf2_read_index (objfile
))
4243 /* Build a partial symbol table. */
4246 dwarf2_build_psymtabs (struct objfile
*objfile
)
4249 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
4251 init_psymbol_list (objfile
, 1024);
4256 /* This isn't really ideal: all the data we allocate on the
4257 objfile's obstack is still uselessly kept around. However,
4258 freeing it seems unsafe. */
4259 struct cleanup
*cleanups
= make_cleanup_discard_psymtabs (objfile
);
4261 dwarf2_build_psymtabs_hard (objfile
);
4262 discard_cleanups (cleanups
);
4264 CATCH (except
, RETURN_MASK_ERROR
)
4266 exception_print (gdb_stderr
, except
);
4271 /* Return the total length of the CU described by HEADER. */
4274 get_cu_length (const struct comp_unit_head
*header
)
4276 return header
->initial_length_size
+ header
->length
;
4279 /* Return TRUE if OFFSET is within CU_HEADER. */
4282 offset_in_cu_p (const struct comp_unit_head
*cu_header
, sect_offset offset
)
4284 sect_offset bottom
= { cu_header
->offset
.sect_off
};
4285 sect_offset top
= { cu_header
->offset
.sect_off
+ get_cu_length (cu_header
) };
4287 return (offset
.sect_off
>= bottom
.sect_off
&& offset
.sect_off
< top
.sect_off
);
4290 /* Find the base address of the compilation unit for range lists and
4291 location lists. It will normally be specified by DW_AT_low_pc.
4292 In DWARF-3 draft 4, the base address could be overridden by
4293 DW_AT_entry_pc. It's been removed, but GCC still uses this for
4294 compilation units with discontinuous ranges. */
4297 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
4299 struct attribute
*attr
;
4302 cu
->base_address
= 0;
4304 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
4307 cu
->base_address
= attr_value_as_address (attr
);
4312 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
4315 cu
->base_address
= attr_value_as_address (attr
);
4321 /* Read in the comp unit header information from the debug_info at info_ptr.
4322 NOTE: This leaves members offset, first_die_offset to be filled in
4325 static const gdb_byte
*
4326 read_comp_unit_head (struct comp_unit_head
*cu_header
,
4327 const gdb_byte
*info_ptr
, bfd
*abfd
)
4330 unsigned int bytes_read
;
4332 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
4333 cu_header
->initial_length_size
= bytes_read
;
4334 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
4335 info_ptr
+= bytes_read
;
4336 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
4338 cu_header
->abbrev_offset
.sect_off
= read_offset (abfd
, info_ptr
, cu_header
,
4340 info_ptr
+= bytes_read
;
4341 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
4343 signed_addr
= bfd_get_sign_extend_vma (abfd
);
4344 if (signed_addr
< 0)
4345 internal_error (__FILE__
, __LINE__
,
4346 _("read_comp_unit_head: dwarf from non elf file"));
4347 cu_header
->signed_addr_p
= signed_addr
;
4352 /* Helper function that returns the proper abbrev section for
4355 static struct dwarf2_section_info
*
4356 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
4358 struct dwarf2_section_info
*abbrev
;
4360 if (this_cu
->is_dwz
)
4361 abbrev
= &dwarf2_get_dwz_file ()->abbrev
;
4363 abbrev
= &dwarf2_per_objfile
->abbrev
;
4368 /* Subroutine of read_and_check_comp_unit_head and
4369 read_and_check_type_unit_head to simplify them.
4370 Perform various error checking on the header. */
4373 error_check_comp_unit_head (struct comp_unit_head
*header
,
4374 struct dwarf2_section_info
*section
,
4375 struct dwarf2_section_info
*abbrev_section
)
4377 bfd
*abfd
= get_section_bfd_owner (section
);
4378 const char *filename
= get_section_file_name (section
);
4380 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
4381 error (_("Dwarf Error: wrong version in compilation unit header "
4382 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
4385 if (header
->abbrev_offset
.sect_off
4386 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
4387 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
4388 "(offset 0x%lx + 6) [in module %s]"),
4389 (long) header
->abbrev_offset
.sect_off
, (long) header
->offset
.sect_off
,
4392 /* Cast to unsigned long to use 64-bit arithmetic when possible to
4393 avoid potential 32-bit overflow. */
4394 if (((unsigned long) header
->offset
.sect_off
+ get_cu_length (header
))
4396 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
4397 "(offset 0x%lx + 0) [in module %s]"),
4398 (long) header
->length
, (long) header
->offset
.sect_off
,
4402 /* Read in a CU/TU header and perform some basic error checking.
4403 The contents of the header are stored in HEADER.
4404 The result is a pointer to the start of the first DIE. */
4406 static const gdb_byte
*
4407 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
4408 struct dwarf2_section_info
*section
,
4409 struct dwarf2_section_info
*abbrev_section
,
4410 const gdb_byte
*info_ptr
,
4411 int is_debug_types_section
)
4413 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
4414 bfd
*abfd
= get_section_bfd_owner (section
);
4416 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
4418 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
4420 /* If we're reading a type unit, skip over the signature and
4421 type_offset fields. */
4422 if (is_debug_types_section
)
4423 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
4425 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
4427 error_check_comp_unit_head (header
, section
, abbrev_section
);
4432 /* Read in the types comp unit header information from .debug_types entry at
4433 types_ptr. The result is a pointer to one past the end of the header. */
4435 static const gdb_byte
*
4436 read_and_check_type_unit_head (struct comp_unit_head
*header
,
4437 struct dwarf2_section_info
*section
,
4438 struct dwarf2_section_info
*abbrev_section
,
4439 const gdb_byte
*info_ptr
,
4440 ULONGEST
*signature
,
4441 cu_offset
*type_offset_in_tu
)
4443 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
4444 bfd
*abfd
= get_section_bfd_owner (section
);
4446 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
4448 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
4450 /* If we're reading a type unit, skip over the signature and
4451 type_offset fields. */
4452 if (signature
!= NULL
)
4453 *signature
= read_8_bytes (abfd
, info_ptr
);
4455 if (type_offset_in_tu
!= NULL
)
4456 type_offset_in_tu
->cu_off
= read_offset_1 (abfd
, info_ptr
,
4457 header
->offset_size
);
4458 info_ptr
+= header
->offset_size
;
4460 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
4462 error_check_comp_unit_head (header
, section
, abbrev_section
);
4467 /* Fetch the abbreviation table offset from a comp or type unit header. */
4470 read_abbrev_offset (struct dwarf2_section_info
*section
,
4473 bfd
*abfd
= get_section_bfd_owner (section
);
4474 const gdb_byte
*info_ptr
;
4475 unsigned int length
, initial_length_size
, offset_size
;
4476 sect_offset abbrev_offset
;
4478 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
4479 info_ptr
= section
->buffer
+ offset
.sect_off
;
4480 length
= read_initial_length (abfd
, info_ptr
, &initial_length_size
);
4481 offset_size
= initial_length_size
== 4 ? 4 : 8;
4482 info_ptr
+= initial_length_size
+ 2 /*version*/;
4483 abbrev_offset
.sect_off
= read_offset_1 (abfd
, info_ptr
, offset_size
);
4484 return abbrev_offset
;
4487 /* Allocate a new partial symtab for file named NAME and mark this new
4488 partial symtab as being an include of PST. */
4491 dwarf2_create_include_psymtab (const char *name
, struct partial_symtab
*pst
,
4492 struct objfile
*objfile
)
4494 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
4496 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
4498 /* It shares objfile->objfile_obstack. */
4499 subpst
->dirname
= pst
->dirname
;
4502 subpst
->textlow
= 0;
4503 subpst
->texthigh
= 0;
4505 subpst
->dependencies
= (struct partial_symtab
**)
4506 obstack_alloc (&objfile
->objfile_obstack
,
4507 sizeof (struct partial_symtab
*));
4508 subpst
->dependencies
[0] = pst
;
4509 subpst
->number_of_dependencies
= 1;
4511 subpst
->globals_offset
= 0;
4512 subpst
->n_global_syms
= 0;
4513 subpst
->statics_offset
= 0;
4514 subpst
->n_static_syms
= 0;
4515 subpst
->compunit_symtab
= NULL
;
4516 subpst
->read_symtab
= pst
->read_symtab
;
4519 /* No private part is necessary for include psymtabs. This property
4520 can be used to differentiate between such include psymtabs and
4521 the regular ones. */
4522 subpst
->read_symtab_private
= NULL
;
4525 /* Read the Line Number Program data and extract the list of files
4526 included by the source file represented by PST. Build an include
4527 partial symtab for each of these included files. */
4530 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
4531 struct die_info
*die
,
4532 struct partial_symtab
*pst
)
4534 struct line_header
*lh
= NULL
;
4535 struct attribute
*attr
;
4537 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
4539 lh
= dwarf_decode_line_header (DW_UNSND (attr
), cu
);
4541 return; /* No linetable, so no includes. */
4543 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
4544 dwarf_decode_lines (lh
, pst
->dirname
, cu
, pst
, pst
->textlow
, 1);
4546 free_line_header (lh
);
4550 hash_signatured_type (const void *item
)
4552 const struct signatured_type
*sig_type
= item
;
4554 /* This drops the top 32 bits of the signature, but is ok for a hash. */
4555 return sig_type
->signature
;
4559 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
4561 const struct signatured_type
*lhs
= item_lhs
;
4562 const struct signatured_type
*rhs
= item_rhs
;
4564 return lhs
->signature
== rhs
->signature
;
4567 /* Allocate a hash table for signatured types. */
4570 allocate_signatured_type_table (struct objfile
*objfile
)
4572 return htab_create_alloc_ex (41,
4573 hash_signatured_type
,
4576 &objfile
->objfile_obstack
,
4577 hashtab_obstack_allocate
,
4578 dummy_obstack_deallocate
);
4581 /* A helper function to add a signatured type CU to a table. */
4584 add_signatured_type_cu_to_table (void **slot
, void *datum
)
4586 struct signatured_type
*sigt
= *slot
;
4587 struct signatured_type
***datap
= datum
;
4595 /* Create the hash table of all entries in the .debug_types
4596 (or .debug_types.dwo) section(s).
4597 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
4598 otherwise it is NULL.
4600 The result is a pointer to the hash table or NULL if there are no types.
4602 Note: This function processes DWO files only, not DWP files. */
4605 create_debug_types_hash_table (struct dwo_file
*dwo_file
,
4606 VEC (dwarf2_section_info_def
) *types
)
4608 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4609 htab_t types_htab
= NULL
;
4611 struct dwarf2_section_info
*section
;
4612 struct dwarf2_section_info
*abbrev_section
;
4614 if (VEC_empty (dwarf2_section_info_def
, types
))
4617 abbrev_section
= (dwo_file
!= NULL
4618 ? &dwo_file
->sections
.abbrev
4619 : &dwarf2_per_objfile
->abbrev
);
4621 if (dwarf_read_debug
)
4622 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_types%s for %s:\n",
4623 dwo_file
? ".dwo" : "",
4624 get_section_file_name (abbrev_section
));
4627 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
4631 const gdb_byte
*info_ptr
, *end_ptr
;
4633 dwarf2_read_section (objfile
, section
);
4634 info_ptr
= section
->buffer
;
4636 if (info_ptr
== NULL
)
4639 /* We can't set abfd until now because the section may be empty or
4640 not present, in which case the bfd is unknown. */
4641 abfd
= get_section_bfd_owner (section
);
4643 /* We don't use init_cutu_and_read_dies_simple, or some such, here
4644 because we don't need to read any dies: the signature is in the
4647 end_ptr
= info_ptr
+ section
->size
;
4648 while (info_ptr
< end_ptr
)
4651 cu_offset type_offset_in_tu
;
4653 struct signatured_type
*sig_type
;
4654 struct dwo_unit
*dwo_tu
;
4656 const gdb_byte
*ptr
= info_ptr
;
4657 struct comp_unit_head header
;
4658 unsigned int length
;
4660 offset
.sect_off
= ptr
- section
->buffer
;
4662 /* We need to read the type's signature in order to build the hash
4663 table, but we don't need anything else just yet. */
4665 ptr
= read_and_check_type_unit_head (&header
, section
,
4666 abbrev_section
, ptr
,
4667 &signature
, &type_offset_in_tu
);
4669 length
= get_cu_length (&header
);
4671 /* Skip dummy type units. */
4672 if (ptr
>= info_ptr
+ length
4673 || peek_abbrev_code (abfd
, ptr
) == 0)
4679 if (types_htab
== NULL
)
4682 types_htab
= allocate_dwo_unit_table (objfile
);
4684 types_htab
= allocate_signatured_type_table (objfile
);
4690 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4692 dwo_tu
->dwo_file
= dwo_file
;
4693 dwo_tu
->signature
= signature
;
4694 dwo_tu
->type_offset_in_tu
= type_offset_in_tu
;
4695 dwo_tu
->section
= section
;
4696 dwo_tu
->offset
= offset
;
4697 dwo_tu
->length
= length
;
4701 /* N.B.: type_offset is not usable if this type uses a DWO file.
4702 The real type_offset is in the DWO file. */
4704 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4705 struct signatured_type
);
4706 sig_type
->signature
= signature
;
4707 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
4708 sig_type
->per_cu
.objfile
= objfile
;
4709 sig_type
->per_cu
.is_debug_types
= 1;
4710 sig_type
->per_cu
.section
= section
;
4711 sig_type
->per_cu
.offset
= offset
;
4712 sig_type
->per_cu
.length
= length
;
4715 slot
= htab_find_slot (types_htab
,
4716 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
4718 gdb_assert (slot
!= NULL
);
4721 sect_offset dup_offset
;
4725 const struct dwo_unit
*dup_tu
= *slot
;
4727 dup_offset
= dup_tu
->offset
;
4731 const struct signatured_type
*dup_tu
= *slot
;
4733 dup_offset
= dup_tu
->per_cu
.offset
;
4736 complaint (&symfile_complaints
,
4737 _("debug type entry at offset 0x%x is duplicate to"
4738 " the entry at offset 0x%x, signature %s"),
4739 offset
.sect_off
, dup_offset
.sect_off
,
4740 hex_string (signature
));
4742 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
4744 if (dwarf_read_debug
> 1)
4745 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature %s\n",
4747 hex_string (signature
));
4756 /* Create the hash table of all entries in the .debug_types section,
4757 and initialize all_type_units.
4758 The result is zero if there is an error (e.g. missing .debug_types section),
4759 otherwise non-zero. */
4762 create_all_type_units (struct objfile
*objfile
)
4765 struct signatured_type
**iter
;
4767 types_htab
= create_debug_types_hash_table (NULL
, dwarf2_per_objfile
->types
);
4768 if (types_htab
== NULL
)
4770 dwarf2_per_objfile
->signatured_types
= NULL
;
4774 dwarf2_per_objfile
->signatured_types
= types_htab
;
4776 dwarf2_per_objfile
->n_type_units
4777 = dwarf2_per_objfile
->n_allocated_type_units
4778 = htab_elements (types_htab
);
4779 dwarf2_per_objfile
->all_type_units
4780 = xmalloc (dwarf2_per_objfile
->n_type_units
4781 * sizeof (struct signatured_type
*));
4782 iter
= &dwarf2_per_objfile
->all_type_units
[0];
4783 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
4784 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
4785 == dwarf2_per_objfile
->n_type_units
);
4790 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
4791 If SLOT is non-NULL, it is the entry to use in the hash table.
4792 Otherwise we find one. */
4794 static struct signatured_type
*
4795 add_type_unit (ULONGEST sig
, void **slot
)
4797 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4798 int n_type_units
= dwarf2_per_objfile
->n_type_units
;
4799 struct signatured_type
*sig_type
;
4801 gdb_assert (n_type_units
<= dwarf2_per_objfile
->n_allocated_type_units
);
4803 if (n_type_units
> dwarf2_per_objfile
->n_allocated_type_units
)
4805 if (dwarf2_per_objfile
->n_allocated_type_units
== 0)
4806 dwarf2_per_objfile
->n_allocated_type_units
= 1;
4807 dwarf2_per_objfile
->n_allocated_type_units
*= 2;
4808 dwarf2_per_objfile
->all_type_units
4809 = xrealloc (dwarf2_per_objfile
->all_type_units
,
4810 dwarf2_per_objfile
->n_allocated_type_units
4811 * sizeof (struct signatured_type
*));
4812 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
4814 dwarf2_per_objfile
->n_type_units
= n_type_units
;
4816 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4817 struct signatured_type
);
4818 dwarf2_per_objfile
->all_type_units
[n_type_units
- 1] = sig_type
;
4819 sig_type
->signature
= sig
;
4820 sig_type
->per_cu
.is_debug_types
= 1;
4821 if (dwarf2_per_objfile
->using_index
)
4823 sig_type
->per_cu
.v
.quick
=
4824 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4825 struct dwarf2_per_cu_quick_data
);
4830 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
4833 gdb_assert (*slot
== NULL
);
4835 /* The rest of sig_type must be filled in by the caller. */
4839 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
4840 Fill in SIG_ENTRY with DWO_ENTRY. */
4843 fill_in_sig_entry_from_dwo_entry (struct objfile
*objfile
,
4844 struct signatured_type
*sig_entry
,
4845 struct dwo_unit
*dwo_entry
)
4847 /* Make sure we're not clobbering something we don't expect to. */
4848 gdb_assert (! sig_entry
->per_cu
.queued
);
4849 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
4850 if (dwarf2_per_objfile
->using_index
)
4852 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
4853 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
4856 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
4857 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
4858 gdb_assert (sig_entry
->type_offset_in_section
.sect_off
== 0);
4859 gdb_assert (sig_entry
->type_unit_group
== NULL
);
4860 gdb_assert (sig_entry
->dwo_unit
== NULL
);
4862 sig_entry
->per_cu
.section
= dwo_entry
->section
;
4863 sig_entry
->per_cu
.offset
= dwo_entry
->offset
;
4864 sig_entry
->per_cu
.length
= dwo_entry
->length
;
4865 sig_entry
->per_cu
.reading_dwo_directly
= 1;
4866 sig_entry
->per_cu
.objfile
= objfile
;
4867 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
4868 sig_entry
->dwo_unit
= dwo_entry
;
4871 /* Subroutine of lookup_signatured_type.
4872 If we haven't read the TU yet, create the signatured_type data structure
4873 for a TU to be read in directly from a DWO file, bypassing the stub.
4874 This is the "Stay in DWO Optimization": When there is no DWP file and we're
4875 using .gdb_index, then when reading a CU we want to stay in the DWO file
4876 containing that CU. Otherwise we could end up reading several other DWO
4877 files (due to comdat folding) to process the transitive closure of all the
4878 mentioned TUs, and that can be slow. The current DWO file will have every
4879 type signature that it needs.
4880 We only do this for .gdb_index because in the psymtab case we already have
4881 to read all the DWOs to build the type unit groups. */
4883 static struct signatured_type
*
4884 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
4886 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4887 struct dwo_file
*dwo_file
;
4888 struct dwo_unit find_dwo_entry
, *dwo_entry
;
4889 struct signatured_type find_sig_entry
, *sig_entry
;
4892 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
4894 /* If TU skeletons have been removed then we may not have read in any
4896 if (dwarf2_per_objfile
->signatured_types
== NULL
)
4898 dwarf2_per_objfile
->signatured_types
4899 = allocate_signatured_type_table (objfile
);
4902 /* We only ever need to read in one copy of a signatured type.
4903 Use the global signatured_types array to do our own comdat-folding
4904 of types. If this is the first time we're reading this TU, and
4905 the TU has an entry in .gdb_index, replace the recorded data from
4906 .gdb_index with this TU. */
4908 find_sig_entry
.signature
= sig
;
4909 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
4910 &find_sig_entry
, INSERT
);
4913 /* We can get here with the TU already read, *or* in the process of being
4914 read. Don't reassign the global entry to point to this DWO if that's
4915 the case. Also note that if the TU is already being read, it may not
4916 have come from a DWO, the program may be a mix of Fission-compiled
4917 code and non-Fission-compiled code. */
4919 /* Have we already tried to read this TU?
4920 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
4921 needn't exist in the global table yet). */
4922 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
4925 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
4926 dwo_unit of the TU itself. */
4927 dwo_file
= cu
->dwo_unit
->dwo_file
;
4929 /* Ok, this is the first time we're reading this TU. */
4930 if (dwo_file
->tus
== NULL
)
4932 find_dwo_entry
.signature
= sig
;
4933 dwo_entry
= htab_find (dwo_file
->tus
, &find_dwo_entry
);
4934 if (dwo_entry
== NULL
)
4937 /* If the global table doesn't have an entry for this TU, add one. */
4938 if (sig_entry
== NULL
)
4939 sig_entry
= add_type_unit (sig
, slot
);
4941 fill_in_sig_entry_from_dwo_entry (objfile
, sig_entry
, dwo_entry
);
4942 sig_entry
->per_cu
.tu_read
= 1;
4946 /* Subroutine of lookup_signatured_type.
4947 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
4948 then try the DWP file. If the TU stub (skeleton) has been removed then
4949 it won't be in .gdb_index. */
4951 static struct signatured_type
*
4952 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
4954 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4955 struct dwp_file
*dwp_file
= get_dwp_file ();
4956 struct dwo_unit
*dwo_entry
;
4957 struct signatured_type find_sig_entry
, *sig_entry
;
4960 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
4961 gdb_assert (dwp_file
!= NULL
);
4963 /* If TU skeletons have been removed then we may not have read in any
4965 if (dwarf2_per_objfile
->signatured_types
== NULL
)
4967 dwarf2_per_objfile
->signatured_types
4968 = allocate_signatured_type_table (objfile
);
4971 find_sig_entry
.signature
= sig
;
4972 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
4973 &find_sig_entry
, INSERT
);
4976 /* Have we already tried to read this TU?
4977 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
4978 needn't exist in the global table yet). */
4979 if (sig_entry
!= NULL
)
4982 if (dwp_file
->tus
== NULL
)
4984 dwo_entry
= lookup_dwo_unit_in_dwp (dwp_file
, NULL
,
4985 sig
, 1 /* is_debug_types */);
4986 if (dwo_entry
== NULL
)
4989 sig_entry
= add_type_unit (sig
, slot
);
4990 fill_in_sig_entry_from_dwo_entry (objfile
, sig_entry
, dwo_entry
);
4995 /* Lookup a signature based type for DW_FORM_ref_sig8.
4996 Returns NULL if signature SIG is not present in the table.
4997 It is up to the caller to complain about this. */
4999 static struct signatured_type
*
5000 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
5003 && dwarf2_per_objfile
->using_index
)
5005 /* We're in a DWO/DWP file, and we're using .gdb_index.
5006 These cases require special processing. */
5007 if (get_dwp_file () == NULL
)
5008 return lookup_dwo_signatured_type (cu
, sig
);
5010 return lookup_dwp_signatured_type (cu
, sig
);
5014 struct signatured_type find_entry
, *entry
;
5016 if (dwarf2_per_objfile
->signatured_types
== NULL
)
5018 find_entry
.signature
= sig
;
5019 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
5024 /* Low level DIE reading support. */
5026 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
5029 init_cu_die_reader (struct die_reader_specs
*reader
,
5030 struct dwarf2_cu
*cu
,
5031 struct dwarf2_section_info
*section
,
5032 struct dwo_file
*dwo_file
)
5034 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
5035 reader
->abfd
= get_section_bfd_owner (section
);
5037 reader
->dwo_file
= dwo_file
;
5038 reader
->die_section
= section
;
5039 reader
->buffer
= section
->buffer
;
5040 reader
->buffer_end
= section
->buffer
+ section
->size
;
5041 reader
->comp_dir
= NULL
;
5044 /* Subroutine of init_cutu_and_read_dies to simplify it.
5045 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
5046 There's just a lot of work to do, and init_cutu_and_read_dies is big enough
5049 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
5050 from it to the DIE in the DWO. If NULL we are skipping the stub.
5051 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
5052 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
5053 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
5054 STUB_COMP_DIR may be non-NULL.
5055 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
5056 are filled in with the info of the DIE from the DWO file.
5057 ABBREV_TABLE_PROVIDED is non-zero if the caller of init_cutu_and_read_dies
5058 provided an abbrev table to use.
5059 The result is non-zero if a valid (non-dummy) DIE was found. */
5062 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
5063 struct dwo_unit
*dwo_unit
,
5064 int abbrev_table_provided
,
5065 struct die_info
*stub_comp_unit_die
,
5066 const char *stub_comp_dir
,
5067 struct die_reader_specs
*result_reader
,
5068 const gdb_byte
**result_info_ptr
,
5069 struct die_info
**result_comp_unit_die
,
5070 int *result_has_children
)
5072 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5073 struct dwarf2_cu
*cu
= this_cu
->cu
;
5074 struct dwarf2_section_info
*section
;
5076 const gdb_byte
*begin_info_ptr
, *info_ptr
;
5077 ULONGEST signature
; /* Or dwo_id. */
5078 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
5079 int i
,num_extra_attrs
;
5080 struct dwarf2_section_info
*dwo_abbrev_section
;
5081 struct attribute
*attr
;
5082 struct die_info
*comp_unit_die
;
5084 /* At most one of these may be provided. */
5085 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
5087 /* These attributes aren't processed until later:
5088 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
5089 DW_AT_comp_dir is used now, to find the DWO file, but it is also
5090 referenced later. However, these attributes are found in the stub
5091 which we won't have later. In order to not impose this complication
5092 on the rest of the code, we read them here and copy them to the
5101 if (stub_comp_unit_die
!= NULL
)
5103 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
5105 if (! this_cu
->is_debug_types
)
5106 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
5107 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
5108 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
5109 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
5110 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
5112 /* There should be a DW_AT_addr_base attribute here (if needed).
5113 We need the value before we can process DW_FORM_GNU_addr_index. */
5115 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
5117 cu
->addr_base
= DW_UNSND (attr
);
5119 /* There should be a DW_AT_ranges_base attribute here (if needed).
5120 We need the value before we can process DW_AT_ranges. */
5121 cu
->ranges_base
= 0;
5122 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
5124 cu
->ranges_base
= DW_UNSND (attr
);
5126 else if (stub_comp_dir
!= NULL
)
5128 /* Reconstruct the comp_dir attribute to simplify the code below. */
5129 comp_dir
= (struct attribute
*)
5130 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (*comp_dir
));
5131 comp_dir
->name
= DW_AT_comp_dir
;
5132 comp_dir
->form
= DW_FORM_string
;
5133 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
5134 DW_STRING (comp_dir
) = stub_comp_dir
;
5137 /* Set up for reading the DWO CU/TU. */
5138 cu
->dwo_unit
= dwo_unit
;
5139 section
= dwo_unit
->section
;
5140 dwarf2_read_section (objfile
, section
);
5141 abfd
= get_section_bfd_owner (section
);
5142 begin_info_ptr
= info_ptr
= section
->buffer
+ dwo_unit
->offset
.sect_off
;
5143 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
5144 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
);
5146 if (this_cu
->is_debug_types
)
5148 ULONGEST header_signature
;
5149 cu_offset type_offset_in_tu
;
5150 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
5152 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
5156 &type_offset_in_tu
);
5157 /* This is not an assert because it can be caused by bad debug info. */
5158 if (sig_type
->signature
!= header_signature
)
5160 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
5161 " TU at offset 0x%x [in module %s]"),
5162 hex_string (sig_type
->signature
),
5163 hex_string (header_signature
),
5164 dwo_unit
->offset
.sect_off
,
5165 bfd_get_filename (abfd
));
5167 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
5168 /* For DWOs coming from DWP files, we don't know the CU length
5169 nor the type's offset in the TU until now. */
5170 dwo_unit
->length
= get_cu_length (&cu
->header
);
5171 dwo_unit
->type_offset_in_tu
= type_offset_in_tu
;
5173 /* Establish the type offset that can be used to lookup the type.
5174 For DWO files, we don't know it until now. */
5175 sig_type
->type_offset_in_section
.sect_off
=
5176 dwo_unit
->offset
.sect_off
+ dwo_unit
->type_offset_in_tu
.cu_off
;
5180 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
5183 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
5184 /* For DWOs coming from DWP files, we don't know the CU length
5186 dwo_unit
->length
= get_cu_length (&cu
->header
);
5189 /* Replace the CU's original abbrev table with the DWO's.
5190 Reminder: We can't read the abbrev table until we've read the header. */
5191 if (abbrev_table_provided
)
5193 /* Don't free the provided abbrev table, the caller of
5194 init_cutu_and_read_dies owns it. */
5195 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
5196 /* Ensure the DWO abbrev table gets freed. */
5197 make_cleanup (dwarf2_free_abbrev_table
, cu
);
5201 dwarf2_free_abbrev_table (cu
);
5202 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
5203 /* Leave any existing abbrev table cleanup as is. */
5206 /* Read in the die, but leave space to copy over the attributes
5207 from the stub. This has the benefit of simplifying the rest of
5208 the code - all the work to maintain the illusion of a single
5209 DW_TAG_{compile,type}_unit DIE is done here. */
5210 num_extra_attrs
= ((stmt_list
!= NULL
)
5214 + (comp_dir
!= NULL
));
5215 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
5216 result_has_children
, num_extra_attrs
);
5218 /* Copy over the attributes from the stub to the DIE we just read in. */
5219 comp_unit_die
= *result_comp_unit_die
;
5220 i
= comp_unit_die
->num_attrs
;
5221 if (stmt_list
!= NULL
)
5222 comp_unit_die
->attrs
[i
++] = *stmt_list
;
5224 comp_unit_die
->attrs
[i
++] = *low_pc
;
5225 if (high_pc
!= NULL
)
5226 comp_unit_die
->attrs
[i
++] = *high_pc
;
5228 comp_unit_die
->attrs
[i
++] = *ranges
;
5229 if (comp_dir
!= NULL
)
5230 comp_unit_die
->attrs
[i
++] = *comp_dir
;
5231 comp_unit_die
->num_attrs
+= num_extra_attrs
;
5233 if (dwarf_die_debug
)
5235 fprintf_unfiltered (gdb_stdlog
,
5236 "Read die from %s@0x%x of %s:\n",
5237 get_section_name (section
),
5238 (unsigned) (begin_info_ptr
- section
->buffer
),
5239 bfd_get_filename (abfd
));
5240 dump_die (comp_unit_die
, dwarf_die_debug
);
5243 /* Save the comp_dir attribute. If there is no DWP file then we'll read
5244 TUs by skipping the stub and going directly to the entry in the DWO file.
5245 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
5246 to get it via circuitous means. Blech. */
5247 if (comp_dir
!= NULL
)
5248 result_reader
->comp_dir
= DW_STRING (comp_dir
);
5250 /* Skip dummy compilation units. */
5251 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
5252 || peek_abbrev_code (abfd
, info_ptr
) == 0)
5255 *result_info_ptr
= info_ptr
;
5259 /* Subroutine of init_cutu_and_read_dies to simplify it.
5260 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
5261 Returns NULL if the specified DWO unit cannot be found. */
5263 static struct dwo_unit
*
5264 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
5265 struct die_info
*comp_unit_die
)
5267 struct dwarf2_cu
*cu
= this_cu
->cu
;
5268 struct attribute
*attr
;
5270 struct dwo_unit
*dwo_unit
;
5271 const char *comp_dir
, *dwo_name
;
5273 gdb_assert (cu
!= NULL
);
5275 /* Yeah, we look dwo_name up again, but it simplifies the code. */
5276 dwo_name
= dwarf2_string_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
5277 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
5279 if (this_cu
->is_debug_types
)
5281 struct signatured_type
*sig_type
;
5283 /* Since this_cu is the first member of struct signatured_type,
5284 we can go from a pointer to one to a pointer to the other. */
5285 sig_type
= (struct signatured_type
*) this_cu
;
5286 signature
= sig_type
->signature
;
5287 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
5291 struct attribute
*attr
;
5293 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
5295 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
5297 dwo_name
, objfile_name (this_cu
->objfile
));
5298 signature
= DW_UNSND (attr
);
5299 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
5306 /* Subroutine of init_cutu_and_read_dies to simplify it.
5307 See it for a description of the parameters.
5308 Read a TU directly from a DWO file, bypassing the stub.
5310 Note: This function could be a little bit simpler if we shared cleanups
5311 with our caller, init_cutu_and_read_dies. That's generally a fragile thing
5312 to do, so we keep this function self-contained. Or we could move this
5313 into our caller, but it's complex enough already. */
5316 init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
5317 int use_existing_cu
, int keep
,
5318 die_reader_func_ftype
*die_reader_func
,
5321 struct dwarf2_cu
*cu
;
5322 struct signatured_type
*sig_type
;
5323 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
5324 struct die_reader_specs reader
;
5325 const gdb_byte
*info_ptr
;
5326 struct die_info
*comp_unit_die
;
5329 /* Verify we can do the following downcast, and that we have the
5331 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
5332 sig_type
= (struct signatured_type
*) this_cu
;
5333 gdb_assert (sig_type
->dwo_unit
!= NULL
);
5335 cleanups
= make_cleanup (null_cleanup
, NULL
);
5337 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
5339 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
5341 /* There's no need to do the rereading_dwo_cu handling that
5342 init_cutu_and_read_dies does since we don't read the stub. */
5346 /* If !use_existing_cu, this_cu->cu must be NULL. */
5347 gdb_assert (this_cu
->cu
== NULL
);
5348 cu
= xmalloc (sizeof (*cu
));
5349 init_one_comp_unit (cu
, this_cu
);
5350 /* If an error occurs while loading, release our storage. */
5351 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
5354 /* A future optimization, if needed, would be to use an existing
5355 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
5356 could share abbrev tables. */
5358 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
5359 0 /* abbrev_table_provided */,
5360 NULL
/* stub_comp_unit_die */,
5361 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
5363 &comp_unit_die
, &has_children
) == 0)
5366 do_cleanups (cleanups
);
5370 /* All the "real" work is done here. */
5371 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
5373 /* This duplicates the code in init_cutu_and_read_dies,
5374 but the alternative is making the latter more complex.
5375 This function is only for the special case of using DWO files directly:
5376 no point in overly complicating the general case just to handle this. */
5377 if (free_cu_cleanup
!= NULL
)
5381 /* We've successfully allocated this compilation unit. Let our
5382 caller clean it up when finished with it. */
5383 discard_cleanups (free_cu_cleanup
);
5385 /* We can only discard free_cu_cleanup and all subsequent cleanups.
5386 So we have to manually free the abbrev table. */
5387 dwarf2_free_abbrev_table (cu
);
5389 /* Link this CU into read_in_chain. */
5390 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
5391 dwarf2_per_objfile
->read_in_chain
= this_cu
;
5394 do_cleanups (free_cu_cleanup
);
5397 do_cleanups (cleanups
);
5400 /* Initialize a CU (or TU) and read its DIEs.
5401 If the CU defers to a DWO file, read the DWO file as well.
5403 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
5404 Otherwise the table specified in the comp unit header is read in and used.
5405 This is an optimization for when we already have the abbrev table.
5407 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
5408 Otherwise, a new CU is allocated with xmalloc.
5410 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
5411 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
5413 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
5414 linker) then DIE_READER_FUNC will not get called. */
5417 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
5418 struct abbrev_table
*abbrev_table
,
5419 int use_existing_cu
, int keep
,
5420 die_reader_func_ftype
*die_reader_func
,
5423 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5424 struct dwarf2_section_info
*section
= this_cu
->section
;
5425 bfd
*abfd
= get_section_bfd_owner (section
);
5426 struct dwarf2_cu
*cu
;
5427 const gdb_byte
*begin_info_ptr
, *info_ptr
;
5428 struct die_reader_specs reader
;
5429 struct die_info
*comp_unit_die
;
5431 struct attribute
*attr
;
5432 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
5433 struct signatured_type
*sig_type
= NULL
;
5434 struct dwarf2_section_info
*abbrev_section
;
5435 /* Non-zero if CU currently points to a DWO file and we need to
5436 reread it. When this happens we need to reread the skeleton die
5437 before we can reread the DWO file (this only applies to CUs, not TUs). */
5438 int rereading_dwo_cu
= 0;
5440 if (dwarf_die_debug
)
5441 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
5442 this_cu
->is_debug_types
? "type" : "comp",
5443 this_cu
->offset
.sect_off
);
5445 if (use_existing_cu
)
5448 /* If we're reading a TU directly from a DWO file, including a virtual DWO
5449 file (instead of going through the stub), short-circuit all of this. */
5450 if (this_cu
->reading_dwo_directly
)
5452 /* Narrow down the scope of possibilities to have to understand. */
5453 gdb_assert (this_cu
->is_debug_types
);
5454 gdb_assert (abbrev_table
== NULL
);
5455 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
,
5456 die_reader_func
, data
);
5460 cleanups
= make_cleanup (null_cleanup
, NULL
);
5462 /* This is cheap if the section is already read in. */
5463 dwarf2_read_section (objfile
, section
);
5465 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
5467 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
5469 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
5472 /* If this CU is from a DWO file we need to start over, we need to
5473 refetch the attributes from the skeleton CU.
5474 This could be optimized by retrieving those attributes from when we
5475 were here the first time: the previous comp_unit_die was stored in
5476 comp_unit_obstack. But there's no data yet that we need this
5478 if (cu
->dwo_unit
!= NULL
)
5479 rereading_dwo_cu
= 1;
5483 /* If !use_existing_cu, this_cu->cu must be NULL. */
5484 gdb_assert (this_cu
->cu
== NULL
);
5485 cu
= xmalloc (sizeof (*cu
));
5486 init_one_comp_unit (cu
, this_cu
);
5487 /* If an error occurs while loading, release our storage. */
5488 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
5491 /* Get the header. */
5492 if (cu
->header
.first_die_offset
.cu_off
!= 0 && ! rereading_dwo_cu
)
5494 /* We already have the header, there's no need to read it in again. */
5495 info_ptr
+= cu
->header
.first_die_offset
.cu_off
;
5499 if (this_cu
->is_debug_types
)
5502 cu_offset type_offset_in_tu
;
5504 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
5505 abbrev_section
, info_ptr
,
5507 &type_offset_in_tu
);
5509 /* Since per_cu is the first member of struct signatured_type,
5510 we can go from a pointer to one to a pointer to the other. */
5511 sig_type
= (struct signatured_type
*) this_cu
;
5512 gdb_assert (sig_type
->signature
== signature
);
5513 gdb_assert (sig_type
->type_offset_in_tu
.cu_off
5514 == type_offset_in_tu
.cu_off
);
5515 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
5517 /* LENGTH has not been set yet for type units if we're
5518 using .gdb_index. */
5519 this_cu
->length
= get_cu_length (&cu
->header
);
5521 /* Establish the type offset that can be used to lookup the type. */
5522 sig_type
->type_offset_in_section
.sect_off
=
5523 this_cu
->offset
.sect_off
+ sig_type
->type_offset_in_tu
.cu_off
;
5527 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
5531 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
5532 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
5536 /* Skip dummy compilation units. */
5537 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
5538 || peek_abbrev_code (abfd
, info_ptr
) == 0)
5540 do_cleanups (cleanups
);
5544 /* If we don't have them yet, read the abbrevs for this compilation unit.
5545 And if we need to read them now, make sure they're freed when we're
5546 done. Note that it's important that if the CU had an abbrev table
5547 on entry we don't free it when we're done: Somewhere up the call stack
5548 it may be in use. */
5549 if (abbrev_table
!= NULL
)
5551 gdb_assert (cu
->abbrev_table
== NULL
);
5552 gdb_assert (cu
->header
.abbrev_offset
.sect_off
5553 == abbrev_table
->offset
.sect_off
);
5554 cu
->abbrev_table
= abbrev_table
;
5556 else if (cu
->abbrev_table
== NULL
)
5558 dwarf2_read_abbrevs (cu
, abbrev_section
);
5559 make_cleanup (dwarf2_free_abbrev_table
, cu
);
5561 else if (rereading_dwo_cu
)
5563 dwarf2_free_abbrev_table (cu
);
5564 dwarf2_read_abbrevs (cu
, abbrev_section
);
5567 /* Read the top level CU/TU die. */
5568 init_cu_die_reader (&reader
, cu
, section
, NULL
);
5569 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
5571 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
5573 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
5574 DWO CU, that this test will fail (the attribute will not be present). */
5575 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
5578 struct dwo_unit
*dwo_unit
;
5579 struct die_info
*dwo_comp_unit_die
;
5583 complaint (&symfile_complaints
,
5584 _("compilation unit with DW_AT_GNU_dwo_name"
5585 " has children (offset 0x%x) [in module %s]"),
5586 this_cu
->offset
.sect_off
, bfd_get_filename (abfd
));
5588 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
);
5589 if (dwo_unit
!= NULL
)
5591 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
5592 abbrev_table
!= NULL
,
5593 comp_unit_die
, NULL
,
5595 &dwo_comp_unit_die
, &has_children
) == 0)
5598 do_cleanups (cleanups
);
5601 comp_unit_die
= dwo_comp_unit_die
;
5605 /* Yikes, we couldn't find the rest of the DIE, we only have
5606 the stub. A complaint has already been logged. There's
5607 not much more we can do except pass on the stub DIE to
5608 die_reader_func. We don't want to throw an error on bad
5613 /* All of the above is setup for this call. Yikes. */
5614 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
5616 /* Done, clean up. */
5617 if (free_cu_cleanup
!= NULL
)
5621 /* We've successfully allocated this compilation unit. Let our
5622 caller clean it up when finished with it. */
5623 discard_cleanups (free_cu_cleanup
);
5625 /* We can only discard free_cu_cleanup and all subsequent cleanups.
5626 So we have to manually free the abbrev table. */
5627 dwarf2_free_abbrev_table (cu
);
5629 /* Link this CU into read_in_chain. */
5630 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
5631 dwarf2_per_objfile
->read_in_chain
= this_cu
;
5634 do_cleanups (free_cu_cleanup
);
5637 do_cleanups (cleanups
);
5640 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name if present.
5641 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed
5642 to have already done the lookup to find the DWO file).
5644 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
5645 THIS_CU->is_debug_types, but nothing else.
5647 We fill in THIS_CU->length.
5649 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
5650 linker) then DIE_READER_FUNC will not get called.
5652 THIS_CU->cu is always freed when done.
5653 This is done in order to not leave THIS_CU->cu in a state where we have
5654 to care whether it refers to the "main" CU or the DWO CU. */
5657 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
5658 struct dwo_file
*dwo_file
,
5659 die_reader_func_ftype
*die_reader_func
,
5662 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5663 struct dwarf2_section_info
*section
= this_cu
->section
;
5664 bfd
*abfd
= get_section_bfd_owner (section
);
5665 struct dwarf2_section_info
*abbrev_section
;
5666 struct dwarf2_cu cu
;
5667 const gdb_byte
*begin_info_ptr
, *info_ptr
;
5668 struct die_reader_specs reader
;
5669 struct cleanup
*cleanups
;
5670 struct die_info
*comp_unit_die
;
5673 if (dwarf_die_debug
)
5674 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
5675 this_cu
->is_debug_types
? "type" : "comp",
5676 this_cu
->offset
.sect_off
);
5678 gdb_assert (this_cu
->cu
== NULL
);
5680 abbrev_section
= (dwo_file
!= NULL
5681 ? &dwo_file
->sections
.abbrev
5682 : get_abbrev_section_for_cu (this_cu
));
5684 /* This is cheap if the section is already read in. */
5685 dwarf2_read_section (objfile
, section
);
5687 init_one_comp_unit (&cu
, this_cu
);
5689 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
5691 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
5692 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
,
5693 abbrev_section
, info_ptr
,
5694 this_cu
->is_debug_types
);
5696 this_cu
->length
= get_cu_length (&cu
.header
);
5698 /* Skip dummy compilation units. */
5699 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
5700 || peek_abbrev_code (abfd
, info_ptr
) == 0)
5702 do_cleanups (cleanups
);
5706 dwarf2_read_abbrevs (&cu
, abbrev_section
);
5707 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
5709 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
);
5710 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
5712 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
5714 do_cleanups (cleanups
);
5717 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
5718 does not lookup the specified DWO file.
5719 This cannot be used to read DWO files.
5721 THIS_CU->cu is always freed when done.
5722 This is done in order to not leave THIS_CU->cu in a state where we have
5723 to care whether it refers to the "main" CU or the DWO CU.
5724 We can revisit this if the data shows there's a performance issue. */
5727 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
5728 die_reader_func_ftype
*die_reader_func
,
5731 init_cutu_and_read_dies_no_follow (this_cu
, NULL
, die_reader_func
, data
);
5734 /* Type Unit Groups.
5736 Type Unit Groups are a way to collapse the set of all TUs (type units) into
5737 a more manageable set. The grouping is done by DW_AT_stmt_list entry
5738 so that all types coming from the same compilation (.o file) are grouped
5739 together. A future step could be to put the types in the same symtab as
5740 the CU the types ultimately came from. */
5743 hash_type_unit_group (const void *item
)
5745 const struct type_unit_group
*tu_group
= item
;
5747 return hash_stmt_list_entry (&tu_group
->hash
);
5751 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
5753 const struct type_unit_group
*lhs
= item_lhs
;
5754 const struct type_unit_group
*rhs
= item_rhs
;
5756 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
5759 /* Allocate a hash table for type unit groups. */
5762 allocate_type_unit_groups_table (void)
5764 return htab_create_alloc_ex (3,
5765 hash_type_unit_group
,
5768 &dwarf2_per_objfile
->objfile
->objfile_obstack
,
5769 hashtab_obstack_allocate
,
5770 dummy_obstack_deallocate
);
5773 /* Type units that don't have DW_AT_stmt_list are grouped into their own
5774 partial symtabs. We combine several TUs per psymtab to not let the size
5775 of any one psymtab grow too big. */
5776 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
5777 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
5779 /* Helper routine for get_type_unit_group.
5780 Create the type_unit_group object used to hold one or more TUs. */
5782 static struct type_unit_group
*
5783 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
5785 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5786 struct dwarf2_per_cu_data
*per_cu
;
5787 struct type_unit_group
*tu_group
;
5789 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5790 struct type_unit_group
);
5791 per_cu
= &tu_group
->per_cu
;
5792 per_cu
->objfile
= objfile
;
5794 if (dwarf2_per_objfile
->using_index
)
5796 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5797 struct dwarf2_per_cu_quick_data
);
5801 unsigned int line_offset
= line_offset_struct
.sect_off
;
5802 struct partial_symtab
*pst
;
5805 /* Give the symtab a useful name for debug purposes. */
5806 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
5807 name
= xstrprintf ("<type_units_%d>",
5808 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
5810 name
= xstrprintf ("<type_units_at_0x%x>", line_offset
);
5812 pst
= create_partial_symtab (per_cu
, name
);
5818 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
5819 tu_group
->hash
.line_offset
= line_offset_struct
;
5824 /* Look up the type_unit_group for type unit CU, and create it if necessary.
5825 STMT_LIST is a DW_AT_stmt_list attribute. */
5827 static struct type_unit_group
*
5828 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
5830 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
5831 struct type_unit_group
*tu_group
;
5833 unsigned int line_offset
;
5834 struct type_unit_group type_unit_group_for_lookup
;
5836 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
5838 dwarf2_per_objfile
->type_unit_groups
=
5839 allocate_type_unit_groups_table ();
5842 /* Do we need to create a new group, or can we use an existing one? */
5846 line_offset
= DW_UNSND (stmt_list
);
5847 ++tu_stats
->nr_symtab_sharers
;
5851 /* Ugh, no stmt_list. Rare, but we have to handle it.
5852 We can do various things here like create one group per TU or
5853 spread them over multiple groups to split up the expansion work.
5854 To avoid worst case scenarios (too many groups or too large groups)
5855 we, umm, group them in bunches. */
5856 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
5857 | (tu_stats
->nr_stmt_less_type_units
5858 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
5859 ++tu_stats
->nr_stmt_less_type_units
;
5862 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
5863 type_unit_group_for_lookup
.hash
.line_offset
.sect_off
= line_offset
;
5864 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
5865 &type_unit_group_for_lookup
, INSERT
);
5869 gdb_assert (tu_group
!= NULL
);
5873 sect_offset line_offset_struct
;
5875 line_offset_struct
.sect_off
= line_offset
;
5876 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
5878 ++tu_stats
->nr_symtabs
;
5884 /* Partial symbol tables. */
5886 /* Create a psymtab named NAME and assign it to PER_CU.
5888 The caller must fill in the following details:
5889 dirname, textlow, texthigh. */
5891 static struct partial_symtab
*
5892 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
5894 struct objfile
*objfile
= per_cu
->objfile
;
5895 struct partial_symtab
*pst
;
5897 pst
= start_psymtab_common (objfile
, name
, 0,
5898 objfile
->global_psymbols
.next
,
5899 objfile
->static_psymbols
.next
);
5901 pst
->psymtabs_addrmap_supported
= 1;
5903 /* This is the glue that links PST into GDB's symbol API. */
5904 pst
->read_symtab_private
= per_cu
;
5905 pst
->read_symtab
= dwarf2_read_symtab
;
5906 per_cu
->v
.psymtab
= pst
;
5911 /* The DATA object passed to process_psymtab_comp_unit_reader has this
5914 struct process_psymtab_comp_unit_data
5916 /* True if we are reading a DW_TAG_partial_unit. */
5918 int want_partial_unit
;
5920 /* The "pretend" language that is used if the CU doesn't declare a
5923 enum language pretend_language
;
5926 /* die_reader_func for process_psymtab_comp_unit. */
5929 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
5930 const gdb_byte
*info_ptr
,
5931 struct die_info
*comp_unit_die
,
5935 struct dwarf2_cu
*cu
= reader
->cu
;
5936 struct objfile
*objfile
= cu
->objfile
;
5937 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
5938 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
5940 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
5941 struct partial_symtab
*pst
;
5943 const char *filename
;
5944 struct process_psymtab_comp_unit_data
*info
= data
;
5946 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !info
->want_partial_unit
)
5949 gdb_assert (! per_cu
->is_debug_types
);
5951 prepare_one_comp_unit (cu
, comp_unit_die
, info
->pretend_language
);
5953 cu
->list_in_scope
= &file_symbols
;
5955 /* Allocate a new partial symbol table structure. */
5956 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
5957 if (filename
== NULL
)
5960 pst
= create_partial_symtab (per_cu
, filename
);
5962 /* This must be done before calling dwarf2_build_include_psymtabs. */
5963 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
5965 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5967 dwarf2_find_base_address (comp_unit_die
, cu
);
5969 /* Possibly set the default values of LOWPC and HIGHPC from
5971 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
5972 &best_highpc
, cu
, pst
);
5973 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
5974 /* Store the contiguous range if it is not empty; it can be empty for
5975 CUs with no code. */
5976 addrmap_set_empty (objfile
->psymtabs_addrmap
,
5977 gdbarch_adjust_dwarf2_addr (gdbarch
,
5978 best_lowpc
+ baseaddr
),
5979 gdbarch_adjust_dwarf2_addr (gdbarch
,
5980 best_highpc
+ baseaddr
) - 1,
5983 /* Check if comp unit has_children.
5984 If so, read the rest of the partial symbols from this comp unit.
5985 If not, there's no more debug_info for this comp unit. */
5988 struct partial_die_info
*first_die
;
5989 CORE_ADDR lowpc
, highpc
;
5991 lowpc
= ((CORE_ADDR
) -1);
5992 highpc
= ((CORE_ADDR
) 0);
5994 first_die
= load_partial_dies (reader
, info_ptr
, 1);
5996 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
5999 /* If we didn't find a lowpc, set it to highpc to avoid
6000 complaints from `maint check'. */
6001 if (lowpc
== ((CORE_ADDR
) -1))
6004 /* If the compilation unit didn't have an explicit address range,
6005 then use the information extracted from its child dies. */
6009 best_highpc
= highpc
;
6012 pst
->textlow
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
);
6013 pst
->texthigh
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
);
6015 end_psymtab_common (objfile
, pst
);
6017 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
))
6020 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
6021 struct dwarf2_per_cu_data
*iter
;
6023 /* Fill in 'dependencies' here; we fill in 'users' in a
6025 pst
->number_of_dependencies
= len
;
6026 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
6027 len
* sizeof (struct symtab
*));
6029 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
6032 pst
->dependencies
[i
] = iter
->v
.psymtab
;
6034 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
6037 /* Get the list of files included in the current compilation unit,
6038 and build a psymtab for each of them. */
6039 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
6041 if (dwarf_read_debug
)
6043 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6045 fprintf_unfiltered (gdb_stdlog
,
6046 "Psymtab for %s unit @0x%x: %s - %s"
6047 ", %d global, %d static syms\n",
6048 per_cu
->is_debug_types
? "type" : "comp",
6049 per_cu
->offset
.sect_off
,
6050 paddress (gdbarch
, pst
->textlow
),
6051 paddress (gdbarch
, pst
->texthigh
),
6052 pst
->n_global_syms
, pst
->n_static_syms
);
6056 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
6057 Process compilation unit THIS_CU for a psymtab. */
6060 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
6061 int want_partial_unit
,
6062 enum language pretend_language
)
6064 struct process_psymtab_comp_unit_data info
;
6066 /* If this compilation unit was already read in, free the
6067 cached copy in order to read it in again. This is
6068 necessary because we skipped some symbols when we first
6069 read in the compilation unit (see load_partial_dies).
6070 This problem could be avoided, but the benefit is unclear. */
6071 if (this_cu
->cu
!= NULL
)
6072 free_one_cached_comp_unit (this_cu
);
6074 gdb_assert (! this_cu
->is_debug_types
);
6075 info
.want_partial_unit
= want_partial_unit
;
6076 info
.pretend_language
= pretend_language
;
6077 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0,
6078 process_psymtab_comp_unit_reader
,
6081 /* Age out any secondary CUs. */
6082 age_cached_comp_units ();
6085 /* Reader function for build_type_psymtabs. */
6088 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
6089 const gdb_byte
*info_ptr
,
6090 struct die_info
*type_unit_die
,
6094 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6095 struct dwarf2_cu
*cu
= reader
->cu
;
6096 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6097 struct signatured_type
*sig_type
;
6098 struct type_unit_group
*tu_group
;
6099 struct attribute
*attr
;
6100 struct partial_die_info
*first_die
;
6101 CORE_ADDR lowpc
, highpc
;
6102 struct partial_symtab
*pst
;
6104 gdb_assert (data
== NULL
);
6105 gdb_assert (per_cu
->is_debug_types
);
6106 sig_type
= (struct signatured_type
*) per_cu
;
6111 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
6112 tu_group
= get_type_unit_group (cu
, attr
);
6114 VEC_safe_push (sig_type_ptr
, tu_group
->tus
, sig_type
);
6116 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
6117 cu
->list_in_scope
= &file_symbols
;
6118 pst
= create_partial_symtab (per_cu
, "");
6121 first_die
= load_partial_dies (reader
, info_ptr
, 1);
6123 lowpc
= (CORE_ADDR
) -1;
6124 highpc
= (CORE_ADDR
) 0;
6125 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
6127 end_psymtab_common (objfile
, pst
);
6130 /* Struct used to sort TUs by their abbreviation table offset. */
6132 struct tu_abbrev_offset
6134 struct signatured_type
*sig_type
;
6135 sect_offset abbrev_offset
;
6138 /* Helper routine for build_type_psymtabs_1, passed to qsort. */
6141 sort_tu_by_abbrev_offset (const void *ap
, const void *bp
)
6143 const struct tu_abbrev_offset
* const *a
= ap
;
6144 const struct tu_abbrev_offset
* const *b
= bp
;
6145 unsigned int aoff
= (*a
)->abbrev_offset
.sect_off
;
6146 unsigned int boff
= (*b
)->abbrev_offset
.sect_off
;
6148 return (aoff
> boff
) - (aoff
< boff
);
6151 /* Efficiently read all the type units.
6152 This does the bulk of the work for build_type_psymtabs.
6154 The efficiency is because we sort TUs by the abbrev table they use and
6155 only read each abbrev table once. In one program there are 200K TUs
6156 sharing 8K abbrev tables.
6158 The main purpose of this function is to support building the
6159 dwarf2_per_objfile->type_unit_groups table.
6160 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
6161 can collapse the search space by grouping them by stmt_list.
6162 The savings can be significant, in the same program from above the 200K TUs
6163 share 8K stmt_list tables.
6165 FUNC is expected to call get_type_unit_group, which will create the
6166 struct type_unit_group if necessary and add it to
6167 dwarf2_per_objfile->type_unit_groups. */
6170 build_type_psymtabs_1 (void)
6172 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6173 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
6174 struct cleanup
*cleanups
;
6175 struct abbrev_table
*abbrev_table
;
6176 sect_offset abbrev_offset
;
6177 struct tu_abbrev_offset
*sorted_by_abbrev
;
6178 struct type_unit_group
**iter
;
6181 /* It's up to the caller to not call us multiple times. */
6182 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
6184 if (dwarf2_per_objfile
->n_type_units
== 0)
6187 /* TUs typically share abbrev tables, and there can be way more TUs than
6188 abbrev tables. Sort by abbrev table to reduce the number of times we
6189 read each abbrev table in.
6190 Alternatives are to punt or to maintain a cache of abbrev tables.
6191 This is simpler and efficient enough for now.
6193 Later we group TUs by their DW_AT_stmt_list value (as this defines the
6194 symtab to use). Typically TUs with the same abbrev offset have the same
6195 stmt_list value too so in practice this should work well.
6197 The basic algorithm here is:
6199 sort TUs by abbrev table
6200 for each TU with same abbrev table:
6201 read abbrev table if first user
6202 read TU top level DIE
6203 [IWBN if DWO skeletons had DW_AT_stmt_list]
6206 if (dwarf_read_debug
)
6207 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
6209 /* Sort in a separate table to maintain the order of all_type_units
6210 for .gdb_index: TU indices directly index all_type_units. */
6211 sorted_by_abbrev
= XNEWVEC (struct tu_abbrev_offset
,
6212 dwarf2_per_objfile
->n_type_units
);
6213 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
6215 struct signatured_type
*sig_type
= dwarf2_per_objfile
->all_type_units
[i
];
6217 sorted_by_abbrev
[i
].sig_type
= sig_type
;
6218 sorted_by_abbrev
[i
].abbrev_offset
=
6219 read_abbrev_offset (sig_type
->per_cu
.section
,
6220 sig_type
->per_cu
.offset
);
6222 cleanups
= make_cleanup (xfree
, sorted_by_abbrev
);
6223 qsort (sorted_by_abbrev
, dwarf2_per_objfile
->n_type_units
,
6224 sizeof (struct tu_abbrev_offset
), sort_tu_by_abbrev_offset
);
6226 abbrev_offset
.sect_off
= ~(unsigned) 0;
6227 abbrev_table
= NULL
;
6228 make_cleanup (abbrev_table_free_cleanup
, &abbrev_table
);
6230 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
6232 const struct tu_abbrev_offset
*tu
= &sorted_by_abbrev
[i
];
6234 /* Switch to the next abbrev table if necessary. */
6235 if (abbrev_table
== NULL
6236 || tu
->abbrev_offset
.sect_off
!= abbrev_offset
.sect_off
)
6238 if (abbrev_table
!= NULL
)
6240 abbrev_table_free (abbrev_table
);
6241 /* Reset to NULL in case abbrev_table_read_table throws
6242 an error: abbrev_table_free_cleanup will get called. */
6243 abbrev_table
= NULL
;
6245 abbrev_offset
= tu
->abbrev_offset
;
6247 abbrev_table_read_table (&dwarf2_per_objfile
->abbrev
,
6249 ++tu_stats
->nr_uniq_abbrev_tables
;
6252 init_cutu_and_read_dies (&tu
->sig_type
->per_cu
, abbrev_table
, 0, 0,
6253 build_type_psymtabs_reader
, NULL
);
6256 do_cleanups (cleanups
);
6259 /* Print collected type unit statistics. */
6262 print_tu_stats (void)
6264 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
6266 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
6267 fprintf_unfiltered (gdb_stdlog
, " %d TUs\n",
6268 dwarf2_per_objfile
->n_type_units
);
6269 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
6270 tu_stats
->nr_uniq_abbrev_tables
);
6271 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
6272 tu_stats
->nr_symtabs
);
6273 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
6274 tu_stats
->nr_symtab_sharers
);
6275 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
6276 tu_stats
->nr_stmt_less_type_units
);
6277 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
6278 tu_stats
->nr_all_type_units_reallocs
);
6281 /* Traversal function for build_type_psymtabs. */
6284 build_type_psymtab_dependencies (void **slot
, void *info
)
6286 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6287 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
6288 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
6289 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
6290 int len
= VEC_length (sig_type_ptr
, tu_group
->tus
);
6291 struct signatured_type
*iter
;
6294 gdb_assert (len
> 0);
6295 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
6297 pst
->number_of_dependencies
= len
;
6298 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
6299 len
* sizeof (struct psymtab
*));
6301 VEC_iterate (sig_type_ptr
, tu_group
->tus
, i
, iter
);
6304 gdb_assert (iter
->per_cu
.is_debug_types
);
6305 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
6306 iter
->type_unit_group
= tu_group
;
6309 VEC_free (sig_type_ptr
, tu_group
->tus
);
6314 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
6315 Build partial symbol tables for the .debug_types comp-units. */
6318 build_type_psymtabs (struct objfile
*objfile
)
6320 if (! create_all_type_units (objfile
))
6323 build_type_psymtabs_1 ();
6326 /* Traversal function for process_skeletonless_type_unit.
6327 Read a TU in a DWO file and build partial symbols for it. */
6330 process_skeletonless_type_unit (void **slot
, void *info
)
6332 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
6333 struct objfile
*objfile
= info
;
6334 struct signatured_type find_entry
, *entry
;
6336 /* If this TU doesn't exist in the global table, add it and read it in. */
6338 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6340 dwarf2_per_objfile
->signatured_types
6341 = allocate_signatured_type_table (objfile
);
6344 find_entry
.signature
= dwo_unit
->signature
;
6345 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
6347 /* If we've already seen this type there's nothing to do. What's happening
6348 is we're doing our own version of comdat-folding here. */
6352 /* This does the job that create_all_type_units would have done for
6354 entry
= add_type_unit (dwo_unit
->signature
, slot
);
6355 fill_in_sig_entry_from_dwo_entry (objfile
, entry
, dwo_unit
);
6358 /* This does the job that build_type_psymtabs_1 would have done. */
6359 init_cutu_and_read_dies (&entry
->per_cu
, NULL
, 0, 0,
6360 build_type_psymtabs_reader
, NULL
);
6365 /* Traversal function for process_skeletonless_type_units. */
6368 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
6370 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
6372 if (dwo_file
->tus
!= NULL
)
6374 htab_traverse_noresize (dwo_file
->tus
,
6375 process_skeletonless_type_unit
, info
);
6381 /* Scan all TUs of DWO files, verifying we've processed them.
6382 This is needed in case a TU was emitted without its skeleton.
6383 Note: This can't be done until we know what all the DWO files are. */
6386 process_skeletonless_type_units (struct objfile
*objfile
)
6388 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
6389 if (get_dwp_file () == NULL
6390 && dwarf2_per_objfile
->dwo_files
!= NULL
)
6392 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
,
6393 process_dwo_file_for_skeletonless_type_units
,
6398 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
6401 psymtabs_addrmap_cleanup (void *o
)
6403 struct objfile
*objfile
= o
;
6405 objfile
->psymtabs_addrmap
= NULL
;
6408 /* Compute the 'user' field for each psymtab in OBJFILE. */
6411 set_partial_user (struct objfile
*objfile
)
6415 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
6417 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
6418 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
6424 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
6426 /* Set the 'user' field only if it is not already set. */
6427 if (pst
->dependencies
[j
]->user
== NULL
)
6428 pst
->dependencies
[j
]->user
= pst
;
6433 /* Build the partial symbol table by doing a quick pass through the
6434 .debug_info and .debug_abbrev sections. */
6437 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
6439 struct cleanup
*back_to
, *addrmap_cleanup
;
6440 struct obstack temp_obstack
;
6443 if (dwarf_read_debug
)
6445 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
6446 objfile_name (objfile
));
6449 dwarf2_per_objfile
->reading_partial_symbols
= 1;
6451 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
6453 /* Any cached compilation units will be linked by the per-objfile
6454 read_in_chain. Make sure to free them when we're done. */
6455 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
6457 build_type_psymtabs (objfile
);
6459 create_all_comp_units (objfile
);
6461 /* Create a temporary address map on a temporary obstack. We later
6462 copy this to the final obstack. */
6463 obstack_init (&temp_obstack
);
6464 make_cleanup_obstack_free (&temp_obstack
);
6465 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
6466 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
6468 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
6470 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (i
);
6472 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
6475 /* This has to wait until we read the CUs, we need the list of DWOs. */
6476 process_skeletonless_type_units (objfile
);
6478 /* Now that all TUs have been processed we can fill in the dependencies. */
6479 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
6481 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
6482 build_type_psymtab_dependencies
, NULL
);
6485 if (dwarf_read_debug
)
6488 set_partial_user (objfile
);
6490 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
6491 &objfile
->objfile_obstack
);
6492 discard_cleanups (addrmap_cleanup
);
6494 do_cleanups (back_to
);
6496 if (dwarf_read_debug
)
6497 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
6498 objfile_name (objfile
));
6501 /* die_reader_func for load_partial_comp_unit. */
6504 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
6505 const gdb_byte
*info_ptr
,
6506 struct die_info
*comp_unit_die
,
6510 struct dwarf2_cu
*cu
= reader
->cu
;
6512 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
6514 /* Check if comp unit has_children.
6515 If so, read the rest of the partial symbols from this comp unit.
6516 If not, there's no more debug_info for this comp unit. */
6518 load_partial_dies (reader
, info_ptr
, 0);
6521 /* Load the partial DIEs for a secondary CU into memory.
6522 This is also used when rereading a primary CU with load_all_dies. */
6525 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
6527 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
6528 load_partial_comp_unit_reader
, NULL
);
6532 read_comp_units_from_section (struct objfile
*objfile
,
6533 struct dwarf2_section_info
*section
,
6534 unsigned int is_dwz
,
6537 struct dwarf2_per_cu_data
***all_comp_units
)
6539 const gdb_byte
*info_ptr
;
6540 bfd
*abfd
= get_section_bfd_owner (section
);
6542 if (dwarf_read_debug
)
6543 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
6544 get_section_name (section
),
6545 get_section_file_name (section
));
6547 dwarf2_read_section (objfile
, section
);
6549 info_ptr
= section
->buffer
;
6551 while (info_ptr
< section
->buffer
+ section
->size
)
6553 unsigned int length
, initial_length_size
;
6554 struct dwarf2_per_cu_data
*this_cu
;
6557 offset
.sect_off
= info_ptr
- section
->buffer
;
6559 /* Read just enough information to find out where the next
6560 compilation unit is. */
6561 length
= read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6563 /* Save the compilation unit for later lookup. */
6564 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
6565 sizeof (struct dwarf2_per_cu_data
));
6566 memset (this_cu
, 0, sizeof (*this_cu
));
6567 this_cu
->offset
= offset
;
6568 this_cu
->length
= length
+ initial_length_size
;
6569 this_cu
->is_dwz
= is_dwz
;
6570 this_cu
->objfile
= objfile
;
6571 this_cu
->section
= section
;
6573 if (*n_comp_units
== *n_allocated
)
6576 *all_comp_units
= xrealloc (*all_comp_units
,
6578 * sizeof (struct dwarf2_per_cu_data
*));
6580 (*all_comp_units
)[*n_comp_units
] = this_cu
;
6583 info_ptr
= info_ptr
+ this_cu
->length
;
6587 /* Create a list of all compilation units in OBJFILE.
6588 This is only done for -readnow and building partial symtabs. */
6591 create_all_comp_units (struct objfile
*objfile
)
6595 struct dwarf2_per_cu_data
**all_comp_units
;
6596 struct dwz_file
*dwz
;
6600 all_comp_units
= xmalloc (n_allocated
6601 * sizeof (struct dwarf2_per_cu_data
*));
6603 read_comp_units_from_section (objfile
, &dwarf2_per_objfile
->info
, 0,
6604 &n_allocated
, &n_comp_units
, &all_comp_units
);
6606 dwz
= dwarf2_get_dwz_file ();
6608 read_comp_units_from_section (objfile
, &dwz
->info
, 1,
6609 &n_allocated
, &n_comp_units
,
6612 dwarf2_per_objfile
->all_comp_units
6613 = obstack_alloc (&objfile
->objfile_obstack
,
6614 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
6615 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
6616 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
6617 xfree (all_comp_units
);
6618 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
6621 /* Process all loaded DIEs for compilation unit CU, starting at
6622 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
6623 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
6624 DW_AT_ranges). See the comments of add_partial_subprogram on how
6625 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
6628 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
6629 CORE_ADDR
*highpc
, int set_addrmap
,
6630 struct dwarf2_cu
*cu
)
6632 struct partial_die_info
*pdi
;
6634 /* Now, march along the PDI's, descending into ones which have
6635 interesting children but skipping the children of the other ones,
6636 until we reach the end of the compilation unit. */
6642 fixup_partial_die (pdi
, cu
);
6644 /* Anonymous namespaces or modules have no name but have interesting
6645 children, so we need to look at them. Ditto for anonymous
6648 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
6649 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
6650 || pdi
->tag
== DW_TAG_imported_unit
)
6654 case DW_TAG_subprogram
:
6655 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
6657 case DW_TAG_constant
:
6658 case DW_TAG_variable
:
6659 case DW_TAG_typedef
:
6660 case DW_TAG_union_type
:
6661 if (!pdi
->is_declaration
)
6663 add_partial_symbol (pdi
, cu
);
6666 case DW_TAG_class_type
:
6667 case DW_TAG_interface_type
:
6668 case DW_TAG_structure_type
:
6669 if (!pdi
->is_declaration
)
6671 add_partial_symbol (pdi
, cu
);
6674 case DW_TAG_enumeration_type
:
6675 if (!pdi
->is_declaration
)
6676 add_partial_enumeration (pdi
, cu
);
6678 case DW_TAG_base_type
:
6679 case DW_TAG_subrange_type
:
6680 /* File scope base type definitions are added to the partial
6682 add_partial_symbol (pdi
, cu
);
6684 case DW_TAG_namespace
:
6685 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
6688 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
6690 case DW_TAG_imported_unit
:
6692 struct dwarf2_per_cu_data
*per_cu
;
6694 /* For now we don't handle imported units in type units. */
6695 if (cu
->per_cu
->is_debug_types
)
6697 error (_("Dwarf Error: DW_TAG_imported_unit is not"
6698 " supported in type units [in module %s]"),
6699 objfile_name (cu
->objfile
));
6702 per_cu
= dwarf2_find_containing_comp_unit (pdi
->d
.offset
,
6706 /* Go read the partial unit, if needed. */
6707 if (per_cu
->v
.psymtab
== NULL
)
6708 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
6710 VEC_safe_push (dwarf2_per_cu_ptr
,
6711 cu
->per_cu
->imported_symtabs
, per_cu
);
6714 case DW_TAG_imported_declaration
:
6715 add_partial_symbol (pdi
, cu
);
6722 /* If the die has a sibling, skip to the sibling. */
6724 pdi
= pdi
->die_sibling
;
6728 /* Functions used to compute the fully scoped name of a partial DIE.
6730 Normally, this is simple. For C++, the parent DIE's fully scoped
6731 name is concatenated with "::" and the partial DIE's name. For
6732 Java, the same thing occurs except that "." is used instead of "::".
6733 Enumerators are an exception; they use the scope of their parent
6734 enumeration type, i.e. the name of the enumeration type is not
6735 prepended to the enumerator.
6737 There are two complexities. One is DW_AT_specification; in this
6738 case "parent" means the parent of the target of the specification,
6739 instead of the direct parent of the DIE. The other is compilers
6740 which do not emit DW_TAG_namespace; in this case we try to guess
6741 the fully qualified name of structure types from their members'
6742 linkage names. This must be done using the DIE's children rather
6743 than the children of any DW_AT_specification target. We only need
6744 to do this for structures at the top level, i.e. if the target of
6745 any DW_AT_specification (if any; otherwise the DIE itself) does not
6748 /* Compute the scope prefix associated with PDI's parent, in
6749 compilation unit CU. The result will be allocated on CU's
6750 comp_unit_obstack, or a copy of the already allocated PDI->NAME
6751 field. NULL is returned if no prefix is necessary. */
6753 partial_die_parent_scope (struct partial_die_info
*pdi
,
6754 struct dwarf2_cu
*cu
)
6756 const char *grandparent_scope
;
6757 struct partial_die_info
*parent
, *real_pdi
;
6759 /* We need to look at our parent DIE; if we have a DW_AT_specification,
6760 then this means the parent of the specification DIE. */
6763 while (real_pdi
->has_specification
)
6764 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
6765 real_pdi
->spec_is_dwz
, cu
);
6767 parent
= real_pdi
->die_parent
;
6771 if (parent
->scope_set
)
6772 return parent
->scope
;
6774 fixup_partial_die (parent
, cu
);
6776 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
6778 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
6779 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
6780 Work around this problem here. */
6781 if (cu
->language
== language_cplus
6782 && parent
->tag
== DW_TAG_namespace
6783 && strcmp (parent
->name
, "::") == 0
6784 && grandparent_scope
== NULL
)
6786 parent
->scope
= NULL
;
6787 parent
->scope_set
= 1;
6791 if (pdi
->tag
== DW_TAG_enumerator
)
6792 /* Enumerators should not get the name of the enumeration as a prefix. */
6793 parent
->scope
= grandparent_scope
;
6794 else if (parent
->tag
== DW_TAG_namespace
6795 || parent
->tag
== DW_TAG_module
6796 || parent
->tag
== DW_TAG_structure_type
6797 || parent
->tag
== DW_TAG_class_type
6798 || parent
->tag
== DW_TAG_interface_type
6799 || parent
->tag
== DW_TAG_union_type
6800 || parent
->tag
== DW_TAG_enumeration_type
)
6802 if (grandparent_scope
== NULL
)
6803 parent
->scope
= parent
->name
;
6805 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
6807 parent
->name
, 0, cu
);
6811 /* FIXME drow/2004-04-01: What should we be doing with
6812 function-local names? For partial symbols, we should probably be
6814 complaint (&symfile_complaints
,
6815 _("unhandled containing DIE tag %d for DIE at %d"),
6816 parent
->tag
, pdi
->offset
.sect_off
);
6817 parent
->scope
= grandparent_scope
;
6820 parent
->scope_set
= 1;
6821 return parent
->scope
;
6824 /* Return the fully scoped name associated with PDI, from compilation unit
6825 CU. The result will be allocated with malloc. */
6828 partial_die_full_name (struct partial_die_info
*pdi
,
6829 struct dwarf2_cu
*cu
)
6831 const char *parent_scope
;
6833 /* If this is a template instantiation, we can not work out the
6834 template arguments from partial DIEs. So, unfortunately, we have
6835 to go through the full DIEs. At least any work we do building
6836 types here will be reused if full symbols are loaded later. */
6837 if (pdi
->has_template_arguments
)
6839 fixup_partial_die (pdi
, cu
);
6841 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
6843 struct die_info
*die
;
6844 struct attribute attr
;
6845 struct dwarf2_cu
*ref_cu
= cu
;
6847 /* DW_FORM_ref_addr is using section offset. */
6849 attr
.form
= DW_FORM_ref_addr
;
6850 attr
.u
.unsnd
= pdi
->offset
.sect_off
;
6851 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
6853 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
6857 parent_scope
= partial_die_parent_scope (pdi
, cu
);
6858 if (parent_scope
== NULL
)
6861 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
6865 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
6867 struct objfile
*objfile
= cu
->objfile
;
6868 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6870 const char *actual_name
= NULL
;
6872 char *built_actual_name
;
6874 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6876 built_actual_name
= partial_die_full_name (pdi
, cu
);
6877 if (built_actual_name
!= NULL
)
6878 actual_name
= built_actual_name
;
6880 if (actual_name
== NULL
)
6881 actual_name
= pdi
->name
;
6885 case DW_TAG_subprogram
:
6886 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
);
6887 if (pdi
->is_external
|| cu
->language
== language_ada
)
6889 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
6890 of the global scope. But in Ada, we want to be able to access
6891 nested procedures globally. So all Ada subprograms are stored
6892 in the global scope. */
6893 /* prim_record_minimal_symbol (actual_name, addr, mst_text,
6895 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6896 built_actual_name
!= NULL
,
6897 VAR_DOMAIN
, LOC_BLOCK
,
6898 &objfile
->global_psymbols
,
6899 addr
, cu
->language
, objfile
);
6903 /* prim_record_minimal_symbol (actual_name, addr, mst_file_text,
6905 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6906 built_actual_name
!= NULL
,
6907 VAR_DOMAIN
, LOC_BLOCK
,
6908 &objfile
->static_psymbols
,
6909 addr
, cu
->language
, objfile
);
6912 case DW_TAG_constant
:
6914 struct psymbol_allocation_list
*list
;
6916 if (pdi
->is_external
)
6917 list
= &objfile
->global_psymbols
;
6919 list
= &objfile
->static_psymbols
;
6920 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6921 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
6922 list
, 0, cu
->language
, objfile
);
6925 case DW_TAG_variable
:
6927 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
6931 && !dwarf2_per_objfile
->has_section_at_zero
)
6933 /* A global or static variable may also have been stripped
6934 out by the linker if unused, in which case its address
6935 will be nullified; do not add such variables into partial
6936 symbol table then. */
6938 else if (pdi
->is_external
)
6941 Don't enter into the minimal symbol tables as there is
6942 a minimal symbol table entry from the ELF symbols already.
6943 Enter into partial symbol table if it has a location
6944 descriptor or a type.
6945 If the location descriptor is missing, new_symbol will create
6946 a LOC_UNRESOLVED symbol, the address of the variable will then
6947 be determined from the minimal symbol table whenever the variable
6949 The address for the partial symbol table entry is not
6950 used by GDB, but it comes in handy for debugging partial symbol
6953 if (pdi
->d
.locdesc
|| pdi
->has_type
)
6954 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6955 built_actual_name
!= NULL
,
6956 VAR_DOMAIN
, LOC_STATIC
,
6957 &objfile
->global_psymbols
,
6959 cu
->language
, objfile
);
6963 int has_loc
= pdi
->d
.locdesc
!= NULL
;
6965 /* Static Variable. Skip symbols whose value we cannot know (those
6966 without location descriptors or constant values). */
6967 if (!has_loc
&& !pdi
->has_const_value
)
6969 xfree (built_actual_name
);
6973 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
6974 mst_file_data, objfile); */
6975 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6976 built_actual_name
!= NULL
,
6977 VAR_DOMAIN
, LOC_STATIC
,
6978 &objfile
->static_psymbols
,
6979 has_loc
? addr
+ baseaddr
: (CORE_ADDR
) 0,
6980 cu
->language
, objfile
);
6983 case DW_TAG_typedef
:
6984 case DW_TAG_base_type
:
6985 case DW_TAG_subrange_type
:
6986 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6987 built_actual_name
!= NULL
,
6988 VAR_DOMAIN
, LOC_TYPEDEF
,
6989 &objfile
->static_psymbols
,
6990 0, cu
->language
, objfile
);
6992 case DW_TAG_imported_declaration
:
6993 case DW_TAG_namespace
:
6994 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6995 built_actual_name
!= NULL
,
6996 VAR_DOMAIN
, LOC_TYPEDEF
,
6997 &objfile
->global_psymbols
,
6998 0, cu
->language
, objfile
);
7001 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7002 built_actual_name
!= NULL
,
7003 MODULE_DOMAIN
, LOC_TYPEDEF
,
7004 &objfile
->global_psymbols
,
7005 0, cu
->language
, objfile
);
7007 case DW_TAG_class_type
:
7008 case DW_TAG_interface_type
:
7009 case DW_TAG_structure_type
:
7010 case DW_TAG_union_type
:
7011 case DW_TAG_enumeration_type
:
7012 /* Skip external references. The DWARF standard says in the section
7013 about "Structure, Union, and Class Type Entries": "An incomplete
7014 structure, union or class type is represented by a structure,
7015 union or class entry that does not have a byte size attribute
7016 and that has a DW_AT_declaration attribute." */
7017 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
7019 xfree (built_actual_name
);
7023 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
7024 static vs. global. */
7025 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7026 built_actual_name
!= NULL
,
7027 STRUCT_DOMAIN
, LOC_TYPEDEF
,
7028 (cu
->language
== language_cplus
7029 || cu
->language
== language_java
)
7030 ? &objfile
->global_psymbols
7031 : &objfile
->static_psymbols
,
7032 0, cu
->language
, objfile
);
7035 case DW_TAG_enumerator
:
7036 add_psymbol_to_list (actual_name
, strlen (actual_name
),
7037 built_actual_name
!= NULL
,
7038 VAR_DOMAIN
, LOC_CONST
,
7039 (cu
->language
== language_cplus
7040 || cu
->language
== language_java
)
7041 ? &objfile
->global_psymbols
7042 : &objfile
->static_psymbols
,
7043 0, cu
->language
, objfile
);
7049 xfree (built_actual_name
);
7052 /* Read a partial die corresponding to a namespace; also, add a symbol
7053 corresponding to that namespace to the symbol table. NAMESPACE is
7054 the name of the enclosing namespace. */
7057 add_partial_namespace (struct partial_die_info
*pdi
,
7058 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
7059 int set_addrmap
, struct dwarf2_cu
*cu
)
7061 /* Add a symbol for the namespace. */
7063 add_partial_symbol (pdi
, cu
);
7065 /* Now scan partial symbols in that namespace. */
7067 if (pdi
->has_children
)
7068 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
7071 /* Read a partial die corresponding to a Fortran module. */
7074 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
7075 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
7077 /* Add a symbol for the namespace. */
7079 add_partial_symbol (pdi
, cu
);
7081 /* Now scan partial symbols in that module. */
7083 if (pdi
->has_children
)
7084 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
7087 /* Read a partial die corresponding to a subprogram and create a partial
7088 symbol for that subprogram. When the CU language allows it, this
7089 routine also defines a partial symbol for each nested subprogram
7090 that this subprogram contains. If SET_ADDRMAP is true, record the
7091 covered ranges in the addrmap. Set *LOWPC and *HIGHPC to the lowest
7092 and highest PC values found in PDI.
7094 PDI may also be a lexical block, in which case we simply search
7095 recursively for subprograms defined inside that lexical block.
7096 Again, this is only performed when the CU language allows this
7097 type of definitions. */
7100 add_partial_subprogram (struct partial_die_info
*pdi
,
7101 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
7102 int set_addrmap
, struct dwarf2_cu
*cu
)
7104 if (pdi
->tag
== DW_TAG_subprogram
)
7106 if (pdi
->has_pc_info
)
7108 if (pdi
->lowpc
< *lowpc
)
7109 *lowpc
= pdi
->lowpc
;
7110 if (pdi
->highpc
> *highpc
)
7111 *highpc
= pdi
->highpc
;
7114 struct objfile
*objfile
= cu
->objfile
;
7115 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7120 baseaddr
= ANOFFSET (objfile
->section_offsets
,
7121 SECT_OFF_TEXT (objfile
));
7122 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
7123 pdi
->lowpc
+ baseaddr
);
7124 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
7125 pdi
->highpc
+ baseaddr
);
7126 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
7127 cu
->per_cu
->v
.psymtab
);
7131 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
7133 if (!pdi
->is_declaration
)
7134 /* Ignore subprogram DIEs that do not have a name, they are
7135 illegal. Do not emit a complaint at this point, we will
7136 do so when we convert this psymtab into a symtab. */
7138 add_partial_symbol (pdi
, cu
);
7142 if (! pdi
->has_children
)
7145 if (cu
->language
== language_ada
)
7147 pdi
= pdi
->die_child
;
7150 fixup_partial_die (pdi
, cu
);
7151 if (pdi
->tag
== DW_TAG_subprogram
7152 || pdi
->tag
== DW_TAG_lexical_block
)
7153 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7154 pdi
= pdi
->die_sibling
;
7159 /* Read a partial die corresponding to an enumeration type. */
7162 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
7163 struct dwarf2_cu
*cu
)
7165 struct partial_die_info
*pdi
;
7167 if (enum_pdi
->name
!= NULL
)
7168 add_partial_symbol (enum_pdi
, cu
);
7170 pdi
= enum_pdi
->die_child
;
7173 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
7174 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
7176 add_partial_symbol (pdi
, cu
);
7177 pdi
= pdi
->die_sibling
;
7181 /* Return the initial uleb128 in the die at INFO_PTR. */
7184 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
7186 unsigned int bytes_read
;
7188 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7191 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
7192 Return the corresponding abbrev, or NULL if the number is zero (indicating
7193 an empty DIE). In either case *BYTES_READ will be set to the length of
7194 the initial number. */
7196 static struct abbrev_info
*
7197 peek_die_abbrev (const gdb_byte
*info_ptr
, unsigned int *bytes_read
,
7198 struct dwarf2_cu
*cu
)
7200 bfd
*abfd
= cu
->objfile
->obfd
;
7201 unsigned int abbrev_number
;
7202 struct abbrev_info
*abbrev
;
7204 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
7206 if (abbrev_number
== 0)
7209 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
7212 error (_("Dwarf Error: Could not find abbrev number %d in %s"
7213 " at offset 0x%x [in module %s]"),
7214 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
7215 cu
->header
.offset
.sect_off
, bfd_get_filename (abfd
));
7221 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
7222 Returns a pointer to the end of a series of DIEs, terminated by an empty
7223 DIE. Any children of the skipped DIEs will also be skipped. */
7225 static const gdb_byte
*
7226 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
7228 struct dwarf2_cu
*cu
= reader
->cu
;
7229 struct abbrev_info
*abbrev
;
7230 unsigned int bytes_read
;
7234 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
7236 return info_ptr
+ bytes_read
;
7238 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
7242 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
7243 INFO_PTR should point just after the initial uleb128 of a DIE, and the
7244 abbrev corresponding to that skipped uleb128 should be passed in
7245 ABBREV. Returns a pointer to this DIE's sibling, skipping any
7248 static const gdb_byte
*
7249 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
7250 struct abbrev_info
*abbrev
)
7252 unsigned int bytes_read
;
7253 struct attribute attr
;
7254 bfd
*abfd
= reader
->abfd
;
7255 struct dwarf2_cu
*cu
= reader
->cu
;
7256 const gdb_byte
*buffer
= reader
->buffer
;
7257 const gdb_byte
*buffer_end
= reader
->buffer_end
;
7258 const gdb_byte
*start_info_ptr
= info_ptr
;
7259 unsigned int form
, i
;
7261 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
7263 /* The only abbrev we care about is DW_AT_sibling. */
7264 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
7266 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
7267 if (attr
.form
== DW_FORM_ref_addr
)
7268 complaint (&symfile_complaints
,
7269 _("ignoring absolute DW_AT_sibling"));
7272 unsigned int off
= dwarf2_get_ref_die_offset (&attr
).sect_off
;
7273 const gdb_byte
*sibling_ptr
= buffer
+ off
;
7275 if (sibling_ptr
< info_ptr
)
7276 complaint (&symfile_complaints
,
7277 _("DW_AT_sibling points backwards"));
7278 else if (sibling_ptr
> reader
->buffer_end
)
7279 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
7285 /* If it isn't DW_AT_sibling, skip this attribute. */
7286 form
= abbrev
->attrs
[i
].form
;
7290 case DW_FORM_ref_addr
:
7291 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
7292 and later it is offset sized. */
7293 if (cu
->header
.version
== 2)
7294 info_ptr
+= cu
->header
.addr_size
;
7296 info_ptr
+= cu
->header
.offset_size
;
7298 case DW_FORM_GNU_ref_alt
:
7299 info_ptr
+= cu
->header
.offset_size
;
7302 info_ptr
+= cu
->header
.addr_size
;
7309 case DW_FORM_flag_present
:
7321 case DW_FORM_ref_sig8
:
7324 case DW_FORM_string
:
7325 read_direct_string (abfd
, info_ptr
, &bytes_read
);
7326 info_ptr
+= bytes_read
;
7328 case DW_FORM_sec_offset
:
7330 case DW_FORM_GNU_strp_alt
:
7331 info_ptr
+= cu
->header
.offset_size
;
7333 case DW_FORM_exprloc
:
7335 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7336 info_ptr
+= bytes_read
;
7338 case DW_FORM_block1
:
7339 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
7341 case DW_FORM_block2
:
7342 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
7344 case DW_FORM_block4
:
7345 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
7349 case DW_FORM_ref_udata
:
7350 case DW_FORM_GNU_addr_index
:
7351 case DW_FORM_GNU_str_index
:
7352 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
7354 case DW_FORM_indirect
:
7355 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7356 info_ptr
+= bytes_read
;
7357 /* We need to continue parsing from here, so just go back to
7359 goto skip_attribute
;
7362 error (_("Dwarf Error: Cannot handle %s "
7363 "in DWARF reader [in module %s]"),
7364 dwarf_form_name (form
),
7365 bfd_get_filename (abfd
));
7369 if (abbrev
->has_children
)
7370 return skip_children (reader
, info_ptr
);
7375 /* Locate ORIG_PDI's sibling.
7376 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
7378 static const gdb_byte
*
7379 locate_pdi_sibling (const struct die_reader_specs
*reader
,
7380 struct partial_die_info
*orig_pdi
,
7381 const gdb_byte
*info_ptr
)
7383 /* Do we know the sibling already? */
7385 if (orig_pdi
->sibling
)
7386 return orig_pdi
->sibling
;
7388 /* Are there any children to deal with? */
7390 if (!orig_pdi
->has_children
)
7393 /* Skip the children the long way. */
7395 return skip_children (reader
, info_ptr
);
7398 /* Expand this partial symbol table into a full symbol table. SELF is
7402 dwarf2_read_symtab (struct partial_symtab
*self
,
7403 struct objfile
*objfile
)
7407 warning (_("bug: psymtab for %s is already read in."),
7414 printf_filtered (_("Reading in symbols for %s..."),
7416 gdb_flush (gdb_stdout
);
7419 /* Restore our global data. */
7420 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
7422 /* If this psymtab is constructed from a debug-only objfile, the
7423 has_section_at_zero flag will not necessarily be correct. We
7424 can get the correct value for this flag by looking at the data
7425 associated with the (presumably stripped) associated objfile. */
7426 if (objfile
->separate_debug_objfile_backlink
)
7428 struct dwarf2_per_objfile
*dpo_backlink
7429 = objfile_data (objfile
->separate_debug_objfile_backlink
,
7430 dwarf2_objfile_data_key
);
7432 dwarf2_per_objfile
->has_section_at_zero
7433 = dpo_backlink
->has_section_at_zero
;
7436 dwarf2_per_objfile
->reading_partial_symbols
= 0;
7438 psymtab_to_symtab_1 (self
);
7440 /* Finish up the debug error message. */
7442 printf_filtered (_("done.\n"));
7445 process_cu_includes ();
7448 /* Reading in full CUs. */
7450 /* Add PER_CU to the queue. */
7453 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
7454 enum language pretend_language
)
7456 struct dwarf2_queue_item
*item
;
7459 item
= xmalloc (sizeof (*item
));
7460 item
->per_cu
= per_cu
;
7461 item
->pretend_language
= pretend_language
;
7464 if (dwarf2_queue
== NULL
)
7465 dwarf2_queue
= item
;
7467 dwarf2_queue_tail
->next
= item
;
7469 dwarf2_queue_tail
= item
;
7472 /* If PER_CU is not yet queued, add it to the queue.
7473 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
7475 The result is non-zero if PER_CU was queued, otherwise the result is zero
7476 meaning either PER_CU is already queued or it is already loaded.
7478 N.B. There is an invariant here that if a CU is queued then it is loaded.
7479 The caller is required to load PER_CU if we return non-zero. */
7482 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
7483 struct dwarf2_per_cu_data
*per_cu
,
7484 enum language pretend_language
)
7486 /* We may arrive here during partial symbol reading, if we need full
7487 DIEs to process an unusual case (e.g. template arguments). Do
7488 not queue PER_CU, just tell our caller to load its DIEs. */
7489 if (dwarf2_per_objfile
->reading_partial_symbols
)
7491 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
7496 /* Mark the dependence relation so that we don't flush PER_CU
7498 if (dependent_cu
!= NULL
)
7499 dwarf2_add_dependence (dependent_cu
, per_cu
);
7501 /* If it's already on the queue, we have nothing to do. */
7505 /* If the compilation unit is already loaded, just mark it as
7507 if (per_cu
->cu
!= NULL
)
7509 per_cu
->cu
->last_used
= 0;
7513 /* Add it to the queue. */
7514 queue_comp_unit (per_cu
, pretend_language
);
7519 /* Process the queue. */
7522 process_queue (void)
7524 struct dwarf2_queue_item
*item
, *next_item
;
7526 if (dwarf_read_debug
)
7528 fprintf_unfiltered (gdb_stdlog
,
7529 "Expanding one or more symtabs of objfile %s ...\n",
7530 objfile_name (dwarf2_per_objfile
->objfile
));
7533 /* The queue starts out with one item, but following a DIE reference
7534 may load a new CU, adding it to the end of the queue. */
7535 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
7537 if ((dwarf2_per_objfile
->using_index
7538 ? !item
->per_cu
->v
.quick
->compunit_symtab
7539 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
7540 /* Skip dummy CUs. */
7541 && item
->per_cu
->cu
!= NULL
)
7543 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
7544 unsigned int debug_print_threshold
;
7547 if (per_cu
->is_debug_types
)
7549 struct signatured_type
*sig_type
=
7550 (struct signatured_type
*) per_cu
;
7552 sprintf (buf
, "TU %s at offset 0x%x",
7553 hex_string (sig_type
->signature
),
7554 per_cu
->offset
.sect_off
);
7555 /* There can be 100s of TUs.
7556 Only print them in verbose mode. */
7557 debug_print_threshold
= 2;
7561 sprintf (buf
, "CU at offset 0x%x", per_cu
->offset
.sect_off
);
7562 debug_print_threshold
= 1;
7565 if (dwarf_read_debug
>= debug_print_threshold
)
7566 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
7568 if (per_cu
->is_debug_types
)
7569 process_full_type_unit (per_cu
, item
->pretend_language
);
7571 process_full_comp_unit (per_cu
, item
->pretend_language
);
7573 if (dwarf_read_debug
>= debug_print_threshold
)
7574 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
7577 item
->per_cu
->queued
= 0;
7578 next_item
= item
->next
;
7582 dwarf2_queue_tail
= NULL
;
7584 if (dwarf_read_debug
)
7586 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
7587 objfile_name (dwarf2_per_objfile
->objfile
));
7591 /* Free all allocated queue entries. This function only releases anything if
7592 an error was thrown; if the queue was processed then it would have been
7593 freed as we went along. */
7596 dwarf2_release_queue (void *dummy
)
7598 struct dwarf2_queue_item
*item
, *last
;
7600 item
= dwarf2_queue
;
7603 /* Anything still marked queued is likely to be in an
7604 inconsistent state, so discard it. */
7605 if (item
->per_cu
->queued
)
7607 if (item
->per_cu
->cu
!= NULL
)
7608 free_one_cached_comp_unit (item
->per_cu
);
7609 item
->per_cu
->queued
= 0;
7617 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
7620 /* Read in full symbols for PST, and anything it depends on. */
7623 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
7625 struct dwarf2_per_cu_data
*per_cu
;
7631 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
7632 if (!pst
->dependencies
[i
]->readin
7633 && pst
->dependencies
[i
]->user
== NULL
)
7635 /* Inform about additional files that need to be read in. */
7638 /* FIXME: i18n: Need to make this a single string. */
7639 fputs_filtered (" ", gdb_stdout
);
7641 fputs_filtered ("and ", gdb_stdout
);
7643 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
7644 wrap_here (""); /* Flush output. */
7645 gdb_flush (gdb_stdout
);
7647 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
7650 per_cu
= pst
->read_symtab_private
;
7654 /* It's an include file, no symbols to read for it.
7655 Everything is in the parent symtab. */
7660 dw2_do_instantiate_symtab (per_cu
);
7663 /* Trivial hash function for die_info: the hash value of a DIE
7664 is its offset in .debug_info for this objfile. */
7667 die_hash (const void *item
)
7669 const struct die_info
*die
= item
;
7671 return die
->offset
.sect_off
;
7674 /* Trivial comparison function for die_info structures: two DIEs
7675 are equal if they have the same offset. */
7678 die_eq (const void *item_lhs
, const void *item_rhs
)
7680 const struct die_info
*die_lhs
= item_lhs
;
7681 const struct die_info
*die_rhs
= item_rhs
;
7683 return die_lhs
->offset
.sect_off
== die_rhs
->offset
.sect_off
;
7686 /* die_reader_func for load_full_comp_unit.
7687 This is identical to read_signatured_type_reader,
7688 but is kept separate for now. */
7691 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
7692 const gdb_byte
*info_ptr
,
7693 struct die_info
*comp_unit_die
,
7697 struct dwarf2_cu
*cu
= reader
->cu
;
7698 enum language
*language_ptr
= data
;
7700 gdb_assert (cu
->die_hash
== NULL
);
7702 htab_create_alloc_ex (cu
->header
.length
/ 12,
7706 &cu
->comp_unit_obstack
,
7707 hashtab_obstack_allocate
,
7708 dummy_obstack_deallocate
);
7711 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
7712 &info_ptr
, comp_unit_die
);
7713 cu
->dies
= comp_unit_die
;
7714 /* comp_unit_die is not stored in die_hash, no need. */
7716 /* We try not to read any attributes in this function, because not
7717 all CUs needed for references have been loaded yet, and symbol
7718 table processing isn't initialized. But we have to set the CU language,
7719 or we won't be able to build types correctly.
7720 Similarly, if we do not read the producer, we can not apply
7721 producer-specific interpretation. */
7722 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
7725 /* Load the DIEs associated with PER_CU into memory. */
7728 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7729 enum language pretend_language
)
7731 gdb_assert (! this_cu
->is_debug_types
);
7733 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
7734 load_full_comp_unit_reader
, &pretend_language
);
7737 /* Add a DIE to the delayed physname list. */
7740 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
7741 const char *name
, struct die_info
*die
,
7742 struct dwarf2_cu
*cu
)
7744 struct delayed_method_info mi
;
7746 mi
.fnfield_index
= fnfield_index
;
7750 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
7753 /* A cleanup for freeing the delayed method list. */
7756 free_delayed_list (void *ptr
)
7758 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
7759 if (cu
->method_list
!= NULL
)
7761 VEC_free (delayed_method_info
, cu
->method_list
);
7762 cu
->method_list
= NULL
;
7766 /* Compute the physnames of any methods on the CU's method list.
7768 The computation of method physnames is delayed in order to avoid the
7769 (bad) condition that one of the method's formal parameters is of an as yet
7773 compute_delayed_physnames (struct dwarf2_cu
*cu
)
7776 struct delayed_method_info
*mi
;
7777 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
7779 const char *physname
;
7780 struct fn_fieldlist
*fn_flp
7781 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
7782 physname
= dwarf2_physname (mi
->name
, mi
->die
, cu
);
7783 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
->index
)
7784 = physname
? physname
: "";
7788 /* Go objects should be embedded in a DW_TAG_module DIE,
7789 and it's not clear if/how imported objects will appear.
7790 To keep Go support simple until that's worked out,
7791 go back through what we've read and create something usable.
7792 We could do this while processing each DIE, and feels kinda cleaner,
7793 but that way is more invasive.
7794 This is to, for example, allow the user to type "p var" or "b main"
7795 without having to specify the package name, and allow lookups
7796 of module.object to work in contexts that use the expression
7800 fixup_go_packaging (struct dwarf2_cu
*cu
)
7802 char *package_name
= NULL
;
7803 struct pending
*list
;
7806 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
7808 for (i
= 0; i
< list
->nsyms
; ++i
)
7810 struct symbol
*sym
= list
->symbol
[i
];
7812 if (SYMBOL_LANGUAGE (sym
) == language_go
7813 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
7815 char *this_package_name
= go_symbol_package_name (sym
);
7817 if (this_package_name
== NULL
)
7819 if (package_name
== NULL
)
7820 package_name
= this_package_name
;
7823 if (strcmp (package_name
, this_package_name
) != 0)
7824 complaint (&symfile_complaints
,
7825 _("Symtab %s has objects from two different Go packages: %s and %s"),
7826 (symbol_symtab (sym
) != NULL
7827 ? symtab_to_filename_for_display
7828 (symbol_symtab (sym
))
7829 : objfile_name (cu
->objfile
)),
7830 this_package_name
, package_name
);
7831 xfree (this_package_name
);
7837 if (package_name
!= NULL
)
7839 struct objfile
*objfile
= cu
->objfile
;
7840 const char *saved_package_name
7841 = obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
7843 strlen (package_name
));
7844 struct type
*type
= init_type (TYPE_CODE_MODULE
, 0, 0,
7845 saved_package_name
, objfile
);
7848 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7850 sym
= allocate_symbol (objfile
);
7851 SYMBOL_SET_LANGUAGE (sym
, language_go
, &objfile
->objfile_obstack
);
7852 SYMBOL_SET_NAMES (sym
, saved_package_name
,
7853 strlen (saved_package_name
), 0, objfile
);
7854 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
7855 e.g., "main" finds the "main" module and not C's main(). */
7856 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
7857 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
7858 SYMBOL_TYPE (sym
) = type
;
7860 add_symbol_to_list (sym
, &global_symbols
);
7862 xfree (package_name
);
7866 /* Return the symtab for PER_CU. This works properly regardless of
7867 whether we're using the index or psymtabs. */
7869 static struct compunit_symtab
*
7870 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
7872 return (dwarf2_per_objfile
->using_index
7873 ? per_cu
->v
.quick
->compunit_symtab
7874 : per_cu
->v
.psymtab
->compunit_symtab
);
7877 /* A helper function for computing the list of all symbol tables
7878 included by PER_CU. */
7881 recursively_compute_inclusions (VEC (compunit_symtab_ptr
) **result
,
7882 htab_t all_children
, htab_t all_type_symtabs
,
7883 struct dwarf2_per_cu_data
*per_cu
,
7884 struct compunit_symtab
*immediate_parent
)
7888 struct compunit_symtab
*cust
;
7889 struct dwarf2_per_cu_data
*iter
;
7891 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
7894 /* This inclusion and its children have been processed. */
7899 /* Only add a CU if it has a symbol table. */
7900 cust
= get_compunit_symtab (per_cu
);
7903 /* If this is a type unit only add its symbol table if we haven't
7904 seen it yet (type unit per_cu's can share symtabs). */
7905 if (per_cu
->is_debug_types
)
7907 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
7911 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
7912 if (cust
->user
== NULL
)
7913 cust
->user
= immediate_parent
;
7918 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
7919 if (cust
->user
== NULL
)
7920 cust
->user
= immediate_parent
;
7925 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, ix
, iter
);
7928 recursively_compute_inclusions (result
, all_children
,
7929 all_type_symtabs
, iter
, cust
);
7933 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
7937 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
7939 gdb_assert (! per_cu
->is_debug_types
);
7941 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
))
7944 struct dwarf2_per_cu_data
*per_cu_iter
;
7945 struct compunit_symtab
*compunit_symtab_iter
;
7946 VEC (compunit_symtab_ptr
) *result_symtabs
= NULL
;
7947 htab_t all_children
, all_type_symtabs
;
7948 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
7950 /* If we don't have a symtab, we can just skip this case. */
7954 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
7955 NULL
, xcalloc
, xfree
);
7956 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
7957 NULL
, xcalloc
, xfree
);
7960 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
,
7964 recursively_compute_inclusions (&result_symtabs
, all_children
,
7965 all_type_symtabs
, per_cu_iter
,
7969 /* Now we have a transitive closure of all the included symtabs. */
7970 len
= VEC_length (compunit_symtab_ptr
, result_symtabs
);
7972 = obstack_alloc (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
7973 (len
+ 1) * sizeof (struct compunit_symtab
*));
7975 VEC_iterate (compunit_symtab_ptr
, result_symtabs
, ix
,
7976 compunit_symtab_iter
);
7978 cust
->includes
[ix
] = compunit_symtab_iter
;
7979 cust
->includes
[len
] = NULL
;
7981 VEC_free (compunit_symtab_ptr
, result_symtabs
);
7982 htab_delete (all_children
);
7983 htab_delete (all_type_symtabs
);
7987 /* Compute the 'includes' field for the symtabs of all the CUs we just
7991 process_cu_includes (void)
7994 struct dwarf2_per_cu_data
*iter
;
7997 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
8001 if (! iter
->is_debug_types
)
8002 compute_compunit_symtab_includes (iter
);
8005 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
8008 /* Generate full symbol information for PER_CU, whose DIEs have
8009 already been loaded into memory. */
8012 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8013 enum language pretend_language
)
8015 struct dwarf2_cu
*cu
= per_cu
->cu
;
8016 struct objfile
*objfile
= per_cu
->objfile
;
8017 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8018 CORE_ADDR lowpc
, highpc
;
8019 struct compunit_symtab
*cust
;
8020 struct cleanup
*back_to
, *delayed_list_cleanup
;
8022 struct block
*static_block
;
8025 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8028 back_to
= make_cleanup (really_free_pendings
, NULL
);
8029 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
8031 cu
->list_in_scope
= &file_symbols
;
8033 cu
->language
= pretend_language
;
8034 cu
->language_defn
= language_def (cu
->language
);
8036 /* Do line number decoding in read_file_scope () */
8037 process_die (cu
->dies
, cu
);
8039 /* For now fudge the Go package. */
8040 if (cu
->language
== language_go
)
8041 fixup_go_packaging (cu
);
8043 /* Now that we have processed all the DIEs in the CU, all the types
8044 should be complete, and it should now be safe to compute all of the
8046 compute_delayed_physnames (cu
);
8047 do_cleanups (delayed_list_cleanup
);
8049 /* Some compilers don't define a DW_AT_high_pc attribute for the
8050 compilation unit. If the DW_AT_high_pc is missing, synthesize
8051 it, by scanning the DIE's below the compilation unit. */
8052 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
8054 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
8055 static_block
= end_symtab_get_static_block (addr
, 0, 1);
8057 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
8058 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
8059 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
8060 addrmap to help ensure it has an accurate map of pc values belonging to
8062 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
8064 cust
= end_symtab_from_static_block (static_block
,
8065 SECT_OFF_TEXT (objfile
), 0);
8069 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
8071 /* Set symtab language to language from DW_AT_language. If the
8072 compilation is from a C file generated by language preprocessors, do
8073 not set the language if it was already deduced by start_subfile. */
8074 if (!(cu
->language
== language_c
8075 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
8076 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
8078 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
8079 produce DW_AT_location with location lists but it can be possibly
8080 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
8081 there were bugs in prologue debug info, fixed later in GCC-4.5
8082 by "unwind info for epilogues" patch (which is not directly related).
8084 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
8085 needed, it would be wrong due to missing DW_AT_producer there.
8087 Still one can confuse GDB by using non-standard GCC compilation
8088 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
8090 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
8091 cust
->locations_valid
= 1;
8093 if (gcc_4_minor
>= 5)
8094 cust
->epilogue_unwind_valid
= 1;
8096 cust
->call_site_htab
= cu
->call_site_htab
;
8099 if (dwarf2_per_objfile
->using_index
)
8100 per_cu
->v
.quick
->compunit_symtab
= cust
;
8103 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8104 pst
->compunit_symtab
= cust
;
8108 /* Push it for inclusion processing later. */
8109 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
8111 do_cleanups (back_to
);
8114 /* Generate full symbol information for type unit PER_CU, whose DIEs have
8115 already been loaded into memory. */
8118 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
8119 enum language pretend_language
)
8121 struct dwarf2_cu
*cu
= per_cu
->cu
;
8122 struct objfile
*objfile
= per_cu
->objfile
;
8123 struct compunit_symtab
*cust
;
8124 struct cleanup
*back_to
, *delayed_list_cleanup
;
8125 struct signatured_type
*sig_type
;
8127 gdb_assert (per_cu
->is_debug_types
);
8128 sig_type
= (struct signatured_type
*) per_cu
;
8131 back_to
= make_cleanup (really_free_pendings
, NULL
);
8132 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
8134 cu
->list_in_scope
= &file_symbols
;
8136 cu
->language
= pretend_language
;
8137 cu
->language_defn
= language_def (cu
->language
);
8139 /* The symbol tables are set up in read_type_unit_scope. */
8140 process_die (cu
->dies
, cu
);
8142 /* For now fudge the Go package. */
8143 if (cu
->language
== language_go
)
8144 fixup_go_packaging (cu
);
8146 /* Now that we have processed all the DIEs in the CU, all the types
8147 should be complete, and it should now be safe to compute all of the
8149 compute_delayed_physnames (cu
);
8150 do_cleanups (delayed_list_cleanup
);
8152 /* TUs share symbol tables.
8153 If this is the first TU to use this symtab, complete the construction
8154 of it with end_expandable_symtab. Otherwise, complete the addition of
8155 this TU's symbols to the existing symtab. */
8156 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
8158 cust
= end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
8159 sig_type
->type_unit_group
->compunit_symtab
= cust
;
8163 /* Set symtab language to language from DW_AT_language. If the
8164 compilation is from a C file generated by language preprocessors,
8165 do not set the language if it was already deduced by
8167 if (!(cu
->language
== language_c
8168 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
8169 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
8174 augment_type_symtab ();
8175 cust
= sig_type
->type_unit_group
->compunit_symtab
;
8178 if (dwarf2_per_objfile
->using_index
)
8179 per_cu
->v
.quick
->compunit_symtab
= cust
;
8182 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8183 pst
->compunit_symtab
= cust
;
8187 do_cleanups (back_to
);
8190 /* Process an imported unit DIE. */
8193 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
8195 struct attribute
*attr
;
8197 /* For now we don't handle imported units in type units. */
8198 if (cu
->per_cu
->is_debug_types
)
8200 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8201 " supported in type units [in module %s]"),
8202 objfile_name (cu
->objfile
));
8205 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
8208 struct dwarf2_per_cu_data
*per_cu
;
8209 struct symtab
*imported_symtab
;
8213 offset
= dwarf2_get_ref_die_offset (attr
);
8214 is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
8215 per_cu
= dwarf2_find_containing_comp_unit (offset
, is_dwz
, cu
->objfile
);
8217 /* If necessary, add it to the queue and load its DIEs. */
8218 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
8219 load_full_comp_unit (per_cu
, cu
->language
);
8221 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
8226 /* Reset the in_process bit of a die. */
8229 reset_die_in_process (void *arg
)
8231 struct die_info
*die
= arg
;
8233 die
->in_process
= 0;
8236 /* Process a die and its children. */
8239 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
8241 struct cleanup
*in_process
;
8243 /* We should only be processing those not already in process. */
8244 gdb_assert (!die
->in_process
);
8246 die
->in_process
= 1;
8247 in_process
= make_cleanup (reset_die_in_process
,die
);
8251 case DW_TAG_padding
:
8253 case DW_TAG_compile_unit
:
8254 case DW_TAG_partial_unit
:
8255 read_file_scope (die
, cu
);
8257 case DW_TAG_type_unit
:
8258 read_type_unit_scope (die
, cu
);
8260 case DW_TAG_subprogram
:
8261 case DW_TAG_inlined_subroutine
:
8262 read_func_scope (die
, cu
);
8264 case DW_TAG_lexical_block
:
8265 case DW_TAG_try_block
:
8266 case DW_TAG_catch_block
:
8267 read_lexical_block_scope (die
, cu
);
8269 case DW_TAG_GNU_call_site
:
8270 read_call_site_scope (die
, cu
);
8272 case DW_TAG_class_type
:
8273 case DW_TAG_interface_type
:
8274 case DW_TAG_structure_type
:
8275 case DW_TAG_union_type
:
8276 process_structure_scope (die
, cu
);
8278 case DW_TAG_enumeration_type
:
8279 process_enumeration_scope (die
, cu
);
8282 /* These dies have a type, but processing them does not create
8283 a symbol or recurse to process the children. Therefore we can
8284 read them on-demand through read_type_die. */
8285 case DW_TAG_subroutine_type
:
8286 case DW_TAG_set_type
:
8287 case DW_TAG_array_type
:
8288 case DW_TAG_pointer_type
:
8289 case DW_TAG_ptr_to_member_type
:
8290 case DW_TAG_reference_type
:
8291 case DW_TAG_string_type
:
8294 case DW_TAG_base_type
:
8295 case DW_TAG_subrange_type
:
8296 case DW_TAG_typedef
:
8297 /* Add a typedef symbol for the type definition, if it has a
8299 new_symbol (die
, read_type_die (die
, cu
), cu
);
8301 case DW_TAG_common_block
:
8302 read_common_block (die
, cu
);
8304 case DW_TAG_common_inclusion
:
8306 case DW_TAG_namespace
:
8307 cu
->processing_has_namespace_info
= 1;
8308 read_namespace (die
, cu
);
8311 cu
->processing_has_namespace_info
= 1;
8312 read_module (die
, cu
);
8314 case DW_TAG_imported_declaration
:
8315 cu
->processing_has_namespace_info
= 1;
8316 if (read_namespace_alias (die
, cu
))
8318 /* The declaration is not a global namespace alias: fall through. */
8319 case DW_TAG_imported_module
:
8320 cu
->processing_has_namespace_info
= 1;
8321 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
8322 || cu
->language
!= language_fortran
))
8323 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
8324 dwarf_tag_name (die
->tag
));
8325 read_import_statement (die
, cu
);
8328 case DW_TAG_imported_unit
:
8329 process_imported_unit_die (die
, cu
);
8333 new_symbol (die
, NULL
, cu
);
8337 do_cleanups (in_process
);
8340 /* DWARF name computation. */
8342 /* A helper function for dwarf2_compute_name which determines whether DIE
8343 needs to have the name of the scope prepended to the name listed in the
8347 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
8349 struct attribute
*attr
;
8353 case DW_TAG_namespace
:
8354 case DW_TAG_typedef
:
8355 case DW_TAG_class_type
:
8356 case DW_TAG_interface_type
:
8357 case DW_TAG_structure_type
:
8358 case DW_TAG_union_type
:
8359 case DW_TAG_enumeration_type
:
8360 case DW_TAG_enumerator
:
8361 case DW_TAG_subprogram
:
8362 case DW_TAG_inlined_subroutine
:
8364 case DW_TAG_imported_declaration
:
8367 case DW_TAG_variable
:
8368 case DW_TAG_constant
:
8369 /* We only need to prefix "globally" visible variables. These include
8370 any variable marked with DW_AT_external or any variable that
8371 lives in a namespace. [Variables in anonymous namespaces
8372 require prefixing, but they are not DW_AT_external.] */
8374 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
8376 struct dwarf2_cu
*spec_cu
= cu
;
8378 return die_needs_namespace (die_specification (die
, &spec_cu
),
8382 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
8383 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
8384 && die
->parent
->tag
!= DW_TAG_module
)
8386 /* A variable in a lexical block of some kind does not need a
8387 namespace, even though in C++ such variables may be external
8388 and have a mangled name. */
8389 if (die
->parent
->tag
== DW_TAG_lexical_block
8390 || die
->parent
->tag
== DW_TAG_try_block
8391 || die
->parent
->tag
== DW_TAG_catch_block
8392 || die
->parent
->tag
== DW_TAG_subprogram
)
8401 /* Retrieve the last character from a mem_file. */
8404 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
8406 char *last_char_p
= (char *) object
;
8409 *last_char_p
= buffer
[length
- 1];
8412 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
8413 compute the physname for the object, which include a method's:
8414 - formal parameters (C++/Java),
8415 - receiver type (Go),
8416 - return type (Java).
8418 The term "physname" is a bit confusing.
8419 For C++, for example, it is the demangled name.
8420 For Go, for example, it's the mangled name.
8422 For Ada, return the DIE's linkage name rather than the fully qualified
8423 name. PHYSNAME is ignored..
8425 The result is allocated on the objfile_obstack and canonicalized. */
8428 dwarf2_compute_name (const char *name
,
8429 struct die_info
*die
, struct dwarf2_cu
*cu
,
8432 struct objfile
*objfile
= cu
->objfile
;
8435 name
= dwarf2_name (die
, cu
);
8437 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
8438 compute it by typename_concat inside GDB. */
8439 if (cu
->language
== language_ada
8440 || (cu
->language
== language_fortran
&& physname
))
8442 /* For Ada unit, we prefer the linkage name over the name, as
8443 the former contains the exported name, which the user expects
8444 to be able to reference. Ideally, we want the user to be able
8445 to reference this entity using either natural or linkage name,
8446 but we haven't started looking at this enhancement yet. */
8449 name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
8451 name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8456 /* These are the only languages we know how to qualify names in. */
8458 && (cu
->language
== language_cplus
|| cu
->language
== language_java
8459 || cu
->language
== language_fortran
|| cu
->language
== language_d
))
8461 if (die_needs_namespace (die
, cu
))
8465 struct ui_file
*buf
;
8466 char *intermediate_name
;
8467 const char *canonical_name
= NULL
;
8469 prefix
= determine_prefix (die
, cu
);
8470 buf
= mem_fileopen ();
8471 if (*prefix
!= '\0')
8473 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
8476 fputs_unfiltered (prefixed_name
, buf
);
8477 xfree (prefixed_name
);
8480 fputs_unfiltered (name
, buf
);
8482 /* Template parameters may be specified in the DIE's DW_AT_name, or
8483 as children with DW_TAG_template_type_param or
8484 DW_TAG_value_type_param. If the latter, add them to the name
8485 here. If the name already has template parameters, then
8486 skip this step; some versions of GCC emit both, and
8487 it is more efficient to use the pre-computed name.
8489 Something to keep in mind about this process: it is very
8490 unlikely, or in some cases downright impossible, to produce
8491 something that will match the mangled name of a function.
8492 If the definition of the function has the same debug info,
8493 we should be able to match up with it anyway. But fallbacks
8494 using the minimal symbol, for instance to find a method
8495 implemented in a stripped copy of libstdc++, will not work.
8496 If we do not have debug info for the definition, we will have to
8497 match them up some other way.
8499 When we do name matching there is a related problem with function
8500 templates; two instantiated function templates are allowed to
8501 differ only by their return types, which we do not add here. */
8503 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
8505 struct attribute
*attr
;
8506 struct die_info
*child
;
8509 die
->building_fullname
= 1;
8511 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
8515 const gdb_byte
*bytes
;
8516 struct dwarf2_locexpr_baton
*baton
;
8519 if (child
->tag
!= DW_TAG_template_type_param
8520 && child
->tag
!= DW_TAG_template_value_param
)
8525 fputs_unfiltered ("<", buf
);
8529 fputs_unfiltered (", ", buf
);
8531 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
8534 complaint (&symfile_complaints
,
8535 _("template parameter missing DW_AT_type"));
8536 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
8539 type
= die_type (child
, cu
);
8541 if (child
->tag
== DW_TAG_template_type_param
)
8543 c_print_type (type
, "", buf
, -1, 0, &type_print_raw_options
);
8547 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
8550 complaint (&symfile_complaints
,
8551 _("template parameter missing "
8552 "DW_AT_const_value"));
8553 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
8557 dwarf2_const_value_attr (attr
, type
, name
,
8558 &cu
->comp_unit_obstack
, cu
,
8559 &value
, &bytes
, &baton
);
8561 if (TYPE_NOSIGN (type
))
8562 /* GDB prints characters as NUMBER 'CHAR'. If that's
8563 changed, this can use value_print instead. */
8564 c_printchar (value
, type
, buf
);
8567 struct value_print_options opts
;
8570 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
8574 else if (bytes
!= NULL
)
8576 v
= allocate_value (type
);
8577 memcpy (value_contents_writeable (v
), bytes
,
8578 TYPE_LENGTH (type
));
8581 v
= value_from_longest (type
, value
);
8583 /* Specify decimal so that we do not depend on
8585 get_formatted_print_options (&opts
, 'd');
8587 value_print (v
, buf
, &opts
);
8593 die
->building_fullname
= 0;
8597 /* Close the argument list, with a space if necessary
8598 (nested templates). */
8599 char last_char
= '\0';
8600 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
8601 if (last_char
== '>')
8602 fputs_unfiltered (" >", buf
);
8604 fputs_unfiltered (">", buf
);
8608 /* For Java and C++ methods, append formal parameter type
8609 information, if PHYSNAME. */
8611 if (physname
&& die
->tag
== DW_TAG_subprogram
8612 && (cu
->language
== language_cplus
8613 || cu
->language
== language_java
))
8615 struct type
*type
= read_type_die (die
, cu
);
8617 c_type_print_args (type
, buf
, 1, cu
->language
,
8618 &type_print_raw_options
);
8620 if (cu
->language
== language_java
)
8622 /* For java, we must append the return type to method
8624 if (die
->tag
== DW_TAG_subprogram
)
8625 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
8626 0, 0, &type_print_raw_options
);
8628 else if (cu
->language
== language_cplus
)
8630 /* Assume that an artificial first parameter is
8631 "this", but do not crash if it is not. RealView
8632 marks unnamed (and thus unused) parameters as
8633 artificial; there is no way to differentiate
8635 if (TYPE_NFIELDS (type
) > 0
8636 && TYPE_FIELD_ARTIFICIAL (type
, 0)
8637 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
8638 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
8640 fputs_unfiltered (" const", buf
);
8644 intermediate_name
= ui_file_xstrdup (buf
, &length
);
8645 ui_file_delete (buf
);
8647 if (cu
->language
== language_cplus
)
8649 = dwarf2_canonicalize_name (intermediate_name
, cu
,
8650 &objfile
->per_bfd
->storage_obstack
);
8652 /* If we only computed INTERMEDIATE_NAME, or if
8653 INTERMEDIATE_NAME is already canonical, then we need to
8654 copy it to the appropriate obstack. */
8655 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
)
8656 name
= obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
8658 strlen (intermediate_name
));
8660 name
= canonical_name
;
8662 xfree (intermediate_name
);
8669 /* Return the fully qualified name of DIE, based on its DW_AT_name.
8670 If scope qualifiers are appropriate they will be added. The result
8671 will be allocated on the storage_obstack, or NULL if the DIE does
8672 not have a name. NAME may either be from a previous call to
8673 dwarf2_name or NULL.
8675 The output string will be canonicalized (if C++/Java). */
8678 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
8680 return dwarf2_compute_name (name
, die
, cu
, 0);
8683 /* Construct a physname for the given DIE in CU. NAME may either be
8684 from a previous call to dwarf2_name or NULL. The result will be
8685 allocated on the objfile_objstack or NULL if the DIE does not have a
8688 The output string will be canonicalized (if C++/Java). */
8691 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
8693 struct objfile
*objfile
= cu
->objfile
;
8694 struct attribute
*attr
;
8695 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
8696 struct cleanup
*back_to
;
8699 /* In this case dwarf2_compute_name is just a shortcut not building anything
8701 if (!die_needs_namespace (die
, cu
))
8702 return dwarf2_compute_name (name
, die
, cu
, 1);
8704 back_to
= make_cleanup (null_cleanup
, NULL
);
8706 mangled
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
8707 if (mangled
== NULL
)
8708 mangled
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8710 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
8712 if (mangled
!= NULL
)
8716 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
8717 type. It is easier for GDB users to search for such functions as
8718 `name(params)' than `long name(params)'. In such case the minimal
8719 symbol names do not match the full symbol names but for template
8720 functions there is never a need to look up their definition from their
8721 declaration so the only disadvantage remains the minimal symbol
8722 variant `long name(params)' does not have the proper inferior type.
8725 if (cu
->language
== language_go
)
8727 /* This is a lie, but we already lie to the caller new_symbol_full.
8728 new_symbol_full assumes we return the mangled name.
8729 This just undoes that lie until things are cleaned up. */
8734 demangled
= gdb_demangle (mangled
,
8735 (DMGL_PARAMS
| DMGL_ANSI
8736 | (cu
->language
== language_java
8737 ? DMGL_JAVA
| DMGL_RET_POSTFIX
8742 make_cleanup (xfree
, demangled
);
8752 if (canon
== NULL
|| check_physname
)
8754 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
8756 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
8758 /* It may not mean a bug in GDB. The compiler could also
8759 compute DW_AT_linkage_name incorrectly. But in such case
8760 GDB would need to be bug-to-bug compatible. */
8762 complaint (&symfile_complaints
,
8763 _("Computed physname <%s> does not match demangled <%s> "
8764 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
8765 physname
, canon
, mangled
, die
->offset
.sect_off
,
8766 objfile_name (objfile
));
8768 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
8769 is available here - over computed PHYSNAME. It is safer
8770 against both buggy GDB and buggy compilers. */
8784 retval
= obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
8785 retval
, strlen (retval
));
8787 do_cleanups (back_to
);
8791 /* Inspect DIE in CU for a namespace alias. If one exists, record
8792 a new symbol for it.
8794 Returns 1 if a namespace alias was recorded, 0 otherwise. */
8797 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
8799 struct attribute
*attr
;
8801 /* If the die does not have a name, this is not a namespace
8803 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8807 struct die_info
*d
= die
;
8808 struct dwarf2_cu
*imported_cu
= cu
;
8810 /* If the compiler has nested DW_AT_imported_declaration DIEs,
8811 keep inspecting DIEs until we hit the underlying import. */
8812 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
8813 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
8815 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
8819 d
= follow_die_ref (d
, attr
, &imported_cu
);
8820 if (d
->tag
!= DW_TAG_imported_declaration
)
8824 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
8826 complaint (&symfile_complaints
,
8827 _("DIE at 0x%x has too many recursively imported "
8828 "declarations"), d
->offset
.sect_off
);
8835 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
8837 type
= get_die_type_at_offset (offset
, cu
->per_cu
);
8838 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
8840 /* This declaration is a global namespace alias. Add
8841 a symbol for it whose type is the aliased namespace. */
8842 new_symbol (die
, type
, cu
);
8851 /* Return the using directives repository (global or local?) to use in the
8852 current context for LANGUAGE.
8854 For Ada, imported declarations can materialize renamings, which *may* be
8855 global. However it is impossible (for now?) in DWARF to distinguish
8856 "external" imported declarations and "static" ones. As all imported
8857 declarations seem to be static in all other languages, make them all CU-wide
8858 global only in Ada. */
8860 static struct using_direct
**
8861 using_directives (enum language language
)
8863 if (language
== language_ada
&& context_stack_depth
== 0)
8864 return &global_using_directives
;
8866 return &local_using_directives
;
8869 /* Read the import statement specified by the given die and record it. */
8872 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
8874 struct objfile
*objfile
= cu
->objfile
;
8875 struct attribute
*import_attr
;
8876 struct die_info
*imported_die
, *child_die
;
8877 struct dwarf2_cu
*imported_cu
;
8878 const char *imported_name
;
8879 const char *imported_name_prefix
;
8880 const char *canonical_name
;
8881 const char *import_alias
;
8882 const char *imported_declaration
= NULL
;
8883 const char *import_prefix
;
8884 VEC (const_char_ptr
) *excludes
= NULL
;
8885 struct cleanup
*cleanups
;
8887 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
8888 if (import_attr
== NULL
)
8890 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
8891 dwarf_tag_name (die
->tag
));
8896 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
8897 imported_name
= dwarf2_name (imported_die
, imported_cu
);
8898 if (imported_name
== NULL
)
8900 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
8902 The import in the following code:
8916 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
8917 <52> DW_AT_decl_file : 1
8918 <53> DW_AT_decl_line : 6
8919 <54> DW_AT_import : <0x75>
8920 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
8922 <5b> DW_AT_decl_file : 1
8923 <5c> DW_AT_decl_line : 2
8924 <5d> DW_AT_type : <0x6e>
8926 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
8927 <76> DW_AT_byte_size : 4
8928 <77> DW_AT_encoding : 5 (signed)
8930 imports the wrong die ( 0x75 instead of 0x58 ).
8931 This case will be ignored until the gcc bug is fixed. */
8935 /* Figure out the local name after import. */
8936 import_alias
= dwarf2_name (die
, cu
);
8938 /* Figure out where the statement is being imported to. */
8939 import_prefix
= determine_prefix (die
, cu
);
8941 /* Figure out what the scope of the imported die is and prepend it
8942 to the name of the imported die. */
8943 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
8945 if (imported_die
->tag
!= DW_TAG_namespace
8946 && imported_die
->tag
!= DW_TAG_module
)
8948 imported_declaration
= imported_name
;
8949 canonical_name
= imported_name_prefix
;
8951 else if (strlen (imported_name_prefix
) > 0)
8952 canonical_name
= obconcat (&objfile
->objfile_obstack
,
8953 imported_name_prefix
,
8954 (cu
->language
== language_d
? "." : "::"),
8955 imported_name
, (char *) NULL
);
8957 canonical_name
= imported_name
;
8959 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
8961 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
8962 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
8963 child_die
= sibling_die (child_die
))
8965 /* DWARF-4: A Fortran use statement with a “rename list” may be
8966 represented by an imported module entry with an import attribute
8967 referring to the module and owned entries corresponding to those
8968 entities that are renamed as part of being imported. */
8970 if (child_die
->tag
!= DW_TAG_imported_declaration
)
8972 complaint (&symfile_complaints
,
8973 _("child DW_TAG_imported_declaration expected "
8974 "- DIE at 0x%x [in module %s]"),
8975 child_die
->offset
.sect_off
, objfile_name (objfile
));
8979 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
8980 if (import_attr
== NULL
)
8982 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
8983 dwarf_tag_name (child_die
->tag
));
8988 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
8990 imported_name
= dwarf2_name (imported_die
, imported_cu
);
8991 if (imported_name
== NULL
)
8993 complaint (&symfile_complaints
,
8994 _("child DW_TAG_imported_declaration has unknown "
8995 "imported name - DIE at 0x%x [in module %s]"),
8996 child_die
->offset
.sect_off
, objfile_name (objfile
));
9000 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
9002 process_die (child_die
, cu
);
9005 add_using_directive (using_directives (cu
->language
),
9009 imported_declaration
,
9012 &objfile
->objfile_obstack
);
9014 do_cleanups (cleanups
);
9017 /* Cleanup function for handle_DW_AT_stmt_list. */
9020 free_cu_line_header (void *arg
)
9022 struct dwarf2_cu
*cu
= arg
;
9024 free_line_header (cu
->line_header
);
9025 cu
->line_header
= NULL
;
9028 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
9029 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
9030 this, it was first present in GCC release 4.3.0. */
9033 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
9035 if (!cu
->checked_producer
)
9036 check_producer (cu
);
9038 return cu
->producer_is_gcc_lt_4_3
;
9042 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
9043 const char **name
, const char **comp_dir
)
9045 /* Find the filename. Do not use dwarf2_name here, since the filename
9046 is not a source language identifier. */
9047 *name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
9048 *comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
9050 if (*comp_dir
== NULL
9051 && producer_is_gcc_lt_4_3 (cu
) && *name
!= NULL
9052 && IS_ABSOLUTE_PATH (*name
))
9054 char *d
= ldirname (*name
);
9058 make_cleanup (xfree
, d
);
9060 if (*comp_dir
!= NULL
)
9062 /* Irix 6.2 native cc prepends <machine>.: to the compilation
9063 directory, get rid of it. */
9064 char *cp
= strchr (*comp_dir
, ':');
9066 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
9071 *name
= "<unknown>";
9074 /* Handle DW_AT_stmt_list for a compilation unit.
9075 DIE is the DW_TAG_compile_unit die for CU.
9076 COMP_DIR is the compilation directory. LOWPC is passed to
9077 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
9080 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
9081 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
9083 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9084 struct attribute
*attr
;
9085 unsigned int line_offset
;
9086 struct line_header line_header_local
;
9087 hashval_t line_header_local_hash
;
9092 gdb_assert (! cu
->per_cu
->is_debug_types
);
9094 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
9098 line_offset
= DW_UNSND (attr
);
9100 /* The line header hash table is only created if needed (it exists to
9101 prevent redundant reading of the line table for partial_units).
9102 If we're given a partial_unit, we'll need it. If we're given a
9103 compile_unit, then use the line header hash table if it's already
9104 created, but don't create one just yet. */
9106 if (dwarf2_per_objfile
->line_header_hash
== NULL
9107 && die
->tag
== DW_TAG_partial_unit
)
9109 dwarf2_per_objfile
->line_header_hash
9110 = htab_create_alloc_ex (127, line_header_hash_voidp
,
9111 line_header_eq_voidp
,
9112 free_line_header_voidp
,
9113 &objfile
->objfile_obstack
,
9114 hashtab_obstack_allocate
,
9115 dummy_obstack_deallocate
);
9118 line_header_local
.offset
.sect_off
= line_offset
;
9119 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
9120 line_header_local_hash
= line_header_hash (&line_header_local
);
9121 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
9123 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
9125 line_header_local_hash
, NO_INSERT
);
9127 /* For DW_TAG_compile_unit we need info like symtab::linetable which
9128 is not present in *SLOT (since if there is something in *SLOT then
9129 it will be for a partial_unit). */
9130 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
9132 gdb_assert (*slot
!= NULL
);
9133 cu
->line_header
= *slot
;
9138 /* dwarf_decode_line_header does not yet provide sufficient information.
9139 We always have to call also dwarf_decode_lines for it. */
9140 cu
->line_header
= dwarf_decode_line_header (line_offset
, cu
);
9141 if (cu
->line_header
== NULL
)
9144 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
9148 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
9150 line_header_local_hash
, INSERT
);
9151 gdb_assert (slot
!= NULL
);
9153 if (slot
!= NULL
&& *slot
== NULL
)
9155 /* This newly decoded line number information unit will be owned
9156 by line_header_hash hash table. */
9157 *slot
= cu
->line_header
;
9161 /* We cannot free any current entry in (*slot) as that struct line_header
9162 may be already used by multiple CUs. Create only temporary decoded
9163 line_header for this CU - it may happen at most once for each line
9164 number information unit. And if we're not using line_header_hash
9165 then this is what we want as well. */
9166 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
9167 make_cleanup (free_cu_line_header
, cu
);
9169 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
9170 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
9174 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
9177 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9179 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9180 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9181 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
9182 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
9183 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
9184 struct attribute
*attr
;
9185 const char *name
= NULL
;
9186 const char *comp_dir
= NULL
;
9187 struct die_info
*child_die
;
9188 bfd
*abfd
= objfile
->obfd
;
9191 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9193 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
9195 /* If we didn't find a lowpc, set it to highpc to avoid complaints
9196 from finish_block. */
9197 if (lowpc
== ((CORE_ADDR
) -1))
9199 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
9201 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
9203 prepare_one_comp_unit (cu
, die
, cu
->language
);
9205 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
9206 standardised yet. As a workaround for the language detection we fall
9207 back to the DW_AT_producer string. */
9208 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
9209 cu
->language
= language_opencl
;
9211 /* Similar hack for Go. */
9212 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
9213 set_cu_language (DW_LANG_Go
, cu
);
9215 dwarf2_start_symtab (cu
, name
, comp_dir
, lowpc
);
9217 /* Decode line number information if present. We do this before
9218 processing child DIEs, so that the line header table is available
9219 for DW_AT_decl_file. */
9220 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, lowpc
);
9222 /* Process all dies in compilation unit. */
9223 if (die
->child
!= NULL
)
9225 child_die
= die
->child
;
9226 while (child_die
&& child_die
->tag
)
9228 process_die (child_die
, cu
);
9229 child_die
= sibling_die (child_die
);
9233 /* Decode macro information, if present. Dwarf 2 macro information
9234 refers to information in the line number info statement program
9235 header, so we can only read it if we've read the header
9237 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
9238 if (attr
&& cu
->line_header
)
9240 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
9241 complaint (&symfile_complaints
,
9242 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
9244 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
9248 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
9249 if (attr
&& cu
->line_header
)
9251 unsigned int macro_offset
= DW_UNSND (attr
);
9253 dwarf_decode_macros (cu
, macro_offset
, 0);
9257 do_cleanups (back_to
);
9260 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
9261 Create the set of symtabs used by this TU, or if this TU is sharing
9262 symtabs with another TU and the symtabs have already been created
9263 then restore those symtabs in the line header.
9264 We don't need the pc/line-number mapping for type units. */
9267 setup_type_unit_groups (struct die_info
*die
, struct dwarf2_cu
*cu
)
9269 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9270 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
9271 struct type_unit_group
*tu_group
;
9273 struct line_header
*lh
;
9274 struct attribute
*attr
;
9275 unsigned int i
, line_offset
;
9276 struct signatured_type
*sig_type
;
9278 gdb_assert (per_cu
->is_debug_types
);
9279 sig_type
= (struct signatured_type
*) per_cu
;
9281 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
9283 /* If we're using .gdb_index (includes -readnow) then
9284 per_cu->type_unit_group may not have been set up yet. */
9285 if (sig_type
->type_unit_group
== NULL
)
9286 sig_type
->type_unit_group
= get_type_unit_group (cu
, attr
);
9287 tu_group
= sig_type
->type_unit_group
;
9289 /* If we've already processed this stmt_list there's no real need to
9290 do it again, we could fake it and just recreate the part we need
9291 (file name,index -> symtab mapping). If data shows this optimization
9292 is useful we can do it then. */
9293 first_time
= tu_group
->compunit_symtab
== NULL
;
9295 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
9300 line_offset
= DW_UNSND (attr
);
9301 lh
= dwarf_decode_line_header (line_offset
, cu
);
9306 dwarf2_start_symtab (cu
, "", NULL
, 0);
9309 gdb_assert (tu_group
->symtabs
== NULL
);
9310 restart_symtab (tu_group
->compunit_symtab
, "", 0);
9315 cu
->line_header
= lh
;
9316 make_cleanup (free_cu_line_header
, cu
);
9320 struct compunit_symtab
*cust
= dwarf2_start_symtab (cu
, "", NULL
, 0);
9322 tu_group
->num_symtabs
= lh
->num_file_names
;
9323 tu_group
->symtabs
= XNEWVEC (struct symtab
*, lh
->num_file_names
);
9325 for (i
= 0; i
< lh
->num_file_names
; ++i
)
9327 const char *dir
= NULL
;
9328 struct file_entry
*fe
= &lh
->file_names
[i
];
9330 if (fe
->dir_index
&& lh
->include_dirs
!= NULL
)
9331 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9332 dwarf2_start_subfile (fe
->name
, dir
);
9334 if (current_subfile
->symtab
== NULL
)
9336 /* NOTE: start_subfile will recognize when it's been passed
9337 a file it has already seen. So we can't assume there's a
9338 simple mapping from lh->file_names to subfiles, plus
9339 lh->file_names may contain dups. */
9340 current_subfile
->symtab
9341 = allocate_symtab (cust
, current_subfile
->name
);
9344 fe
->symtab
= current_subfile
->symtab
;
9345 tu_group
->symtabs
[i
] = fe
->symtab
;
9350 restart_symtab (tu_group
->compunit_symtab
, "", 0);
9352 for (i
= 0; i
< lh
->num_file_names
; ++i
)
9354 struct file_entry
*fe
= &lh
->file_names
[i
];
9356 fe
->symtab
= tu_group
->symtabs
[i
];
9360 /* The main symtab is allocated last. Type units don't have DW_AT_name
9361 so they don't have a "real" (so to speak) symtab anyway.
9362 There is later code that will assign the main symtab to all symbols
9363 that don't have one. We need to handle the case of a symbol with a
9364 missing symtab (DW_AT_decl_file) anyway. */
9367 /* Process DW_TAG_type_unit.
9368 For TUs we want to skip the first top level sibling if it's not the
9369 actual type being defined by this TU. In this case the first top
9370 level sibling is there to provide context only. */
9373 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9375 struct die_info
*child_die
;
9377 prepare_one_comp_unit (cu
, die
, language_minimal
);
9379 /* Initialize (or reinitialize) the machinery for building symtabs.
9380 We do this before processing child DIEs, so that the line header table
9381 is available for DW_AT_decl_file. */
9382 setup_type_unit_groups (die
, cu
);
9384 if (die
->child
!= NULL
)
9386 child_die
= die
->child
;
9387 while (child_die
&& child_die
->tag
)
9389 process_die (child_die
, cu
);
9390 child_die
= sibling_die (child_die
);
9397 http://gcc.gnu.org/wiki/DebugFission
9398 http://gcc.gnu.org/wiki/DebugFissionDWP
9400 To simplify handling of both DWO files ("object" files with the DWARF info)
9401 and DWP files (a file with the DWOs packaged up into one file), we treat
9402 DWP files as having a collection of virtual DWO files. */
9405 hash_dwo_file (const void *item
)
9407 const struct dwo_file
*dwo_file
= item
;
9410 hash
= htab_hash_string (dwo_file
->dwo_name
);
9411 if (dwo_file
->comp_dir
!= NULL
)
9412 hash
+= htab_hash_string (dwo_file
->comp_dir
);
9417 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
9419 const struct dwo_file
*lhs
= item_lhs
;
9420 const struct dwo_file
*rhs
= item_rhs
;
9422 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
9424 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
9425 return lhs
->comp_dir
== rhs
->comp_dir
;
9426 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
9429 /* Allocate a hash table for DWO files. */
9432 allocate_dwo_file_hash_table (void)
9434 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9436 return htab_create_alloc_ex (41,
9440 &objfile
->objfile_obstack
,
9441 hashtab_obstack_allocate
,
9442 dummy_obstack_deallocate
);
9445 /* Lookup DWO file DWO_NAME. */
9448 lookup_dwo_file_slot (const char *dwo_name
, const char *comp_dir
)
9450 struct dwo_file find_entry
;
9453 if (dwarf2_per_objfile
->dwo_files
== NULL
)
9454 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
9456 memset (&find_entry
, 0, sizeof (find_entry
));
9457 find_entry
.dwo_name
= dwo_name
;
9458 find_entry
.comp_dir
= comp_dir
;
9459 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
9465 hash_dwo_unit (const void *item
)
9467 const struct dwo_unit
*dwo_unit
= item
;
9469 /* This drops the top 32 bits of the id, but is ok for a hash. */
9470 return dwo_unit
->signature
;
9474 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
9476 const struct dwo_unit
*lhs
= item_lhs
;
9477 const struct dwo_unit
*rhs
= item_rhs
;
9479 /* The signature is assumed to be unique within the DWO file.
9480 So while object file CU dwo_id's always have the value zero,
9481 that's OK, assuming each object file DWO file has only one CU,
9482 and that's the rule for now. */
9483 return lhs
->signature
== rhs
->signature
;
9486 /* Allocate a hash table for DWO CUs,TUs.
9487 There is one of these tables for each of CUs,TUs for each DWO file. */
9490 allocate_dwo_unit_table (struct objfile
*objfile
)
9492 /* Start out with a pretty small number.
9493 Generally DWO files contain only one CU and maybe some TUs. */
9494 return htab_create_alloc_ex (3,
9498 &objfile
->objfile_obstack
,
9499 hashtab_obstack_allocate
,
9500 dummy_obstack_deallocate
);
9503 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
9505 struct create_dwo_cu_data
9507 struct dwo_file
*dwo_file
;
9508 struct dwo_unit dwo_unit
;
9511 /* die_reader_func for create_dwo_cu. */
9514 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
9515 const gdb_byte
*info_ptr
,
9516 struct die_info
*comp_unit_die
,
9520 struct dwarf2_cu
*cu
= reader
->cu
;
9521 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9522 sect_offset offset
= cu
->per_cu
->offset
;
9523 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
9524 struct create_dwo_cu_data
*data
= datap
;
9525 struct dwo_file
*dwo_file
= data
->dwo_file
;
9526 struct dwo_unit
*dwo_unit
= &data
->dwo_unit
;
9527 struct attribute
*attr
;
9529 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
9532 complaint (&symfile_complaints
,
9533 _("Dwarf Error: debug entry at offset 0x%x is missing"
9534 " its dwo_id [in module %s]"),
9535 offset
.sect_off
, dwo_file
->dwo_name
);
9539 dwo_unit
->dwo_file
= dwo_file
;
9540 dwo_unit
->signature
= DW_UNSND (attr
);
9541 dwo_unit
->section
= section
;
9542 dwo_unit
->offset
= offset
;
9543 dwo_unit
->length
= cu
->per_cu
->length
;
9545 if (dwarf_read_debug
)
9546 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, dwo_id %s\n",
9547 offset
.sect_off
, hex_string (dwo_unit
->signature
));
9550 /* Create the dwo_unit for the lone CU in DWO_FILE.
9551 Note: This function processes DWO files only, not DWP files. */
9553 static struct dwo_unit
*
9554 create_dwo_cu (struct dwo_file
*dwo_file
)
9556 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9557 struct dwarf2_section_info
*section
= &dwo_file
->sections
.info
;
9560 const gdb_byte
*info_ptr
, *end_ptr
;
9561 struct create_dwo_cu_data create_dwo_cu_data
;
9562 struct dwo_unit
*dwo_unit
;
9564 dwarf2_read_section (objfile
, section
);
9565 info_ptr
= section
->buffer
;
9567 if (info_ptr
== NULL
)
9570 /* We can't set abfd until now because the section may be empty or
9571 not present, in which case section->asection will be NULL. */
9572 abfd
= get_section_bfd_owner (section
);
9574 if (dwarf_read_debug
)
9576 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
9577 get_section_name (section
),
9578 get_section_file_name (section
));
9581 create_dwo_cu_data
.dwo_file
= dwo_file
;
9584 end_ptr
= info_ptr
+ section
->size
;
9585 while (info_ptr
< end_ptr
)
9587 struct dwarf2_per_cu_data per_cu
;
9589 memset (&create_dwo_cu_data
.dwo_unit
, 0,
9590 sizeof (create_dwo_cu_data
.dwo_unit
));
9591 memset (&per_cu
, 0, sizeof (per_cu
));
9592 per_cu
.objfile
= objfile
;
9593 per_cu
.is_debug_types
= 0;
9594 per_cu
.offset
.sect_off
= info_ptr
- section
->buffer
;
9595 per_cu
.section
= section
;
9597 init_cutu_and_read_dies_no_follow (&per_cu
, dwo_file
,
9598 create_dwo_cu_reader
,
9599 &create_dwo_cu_data
);
9601 if (create_dwo_cu_data
.dwo_unit
.dwo_file
!= NULL
)
9603 /* If we've already found one, complain. We only support one
9604 because having more than one requires hacking the dwo_name of
9605 each to match, which is highly unlikely to happen. */
9606 if (dwo_unit
!= NULL
)
9608 complaint (&symfile_complaints
,
9609 _("Multiple CUs in DWO file %s [in module %s]"),
9610 dwo_file
->dwo_name
, objfile_name (objfile
));
9614 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
9615 *dwo_unit
= create_dwo_cu_data
.dwo_unit
;
9618 info_ptr
+= per_cu
.length
;
9624 /* DWP file .debug_{cu,tu}_index section format:
9625 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
9629 Both index sections have the same format, and serve to map a 64-bit
9630 signature to a set of section numbers. Each section begins with a header,
9631 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
9632 indexes, and a pool of 32-bit section numbers. The index sections will be
9633 aligned at 8-byte boundaries in the file.
9635 The index section header consists of:
9637 V, 32 bit version number
9639 N, 32 bit number of compilation units or type units in the index
9640 M, 32 bit number of slots in the hash table
9642 Numbers are recorded using the byte order of the application binary.
9644 The hash table begins at offset 16 in the section, and consists of an array
9645 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
9646 order of the application binary). Unused slots in the hash table are 0.
9647 (We rely on the extreme unlikeliness of a signature being exactly 0.)
9649 The parallel table begins immediately after the hash table
9650 (at offset 16 + 8 * M from the beginning of the section), and consists of an
9651 array of 32-bit indexes (using the byte order of the application binary),
9652 corresponding 1-1 with slots in the hash table. Each entry in the parallel
9653 table contains a 32-bit index into the pool of section numbers. For unused
9654 hash table slots, the corresponding entry in the parallel table will be 0.
9656 The pool of section numbers begins immediately following the hash table
9657 (at offset 16 + 12 * M from the beginning of the section). The pool of
9658 section numbers consists of an array of 32-bit words (using the byte order
9659 of the application binary). Each item in the array is indexed starting
9660 from 0. The hash table entry provides the index of the first section
9661 number in the set. Additional section numbers in the set follow, and the
9662 set is terminated by a 0 entry (section number 0 is not used in ELF).
9664 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
9665 section must be the first entry in the set, and the .debug_abbrev.dwo must
9666 be the second entry. Other members of the set may follow in any order.
9672 DWP Version 2 combines all the .debug_info, etc. sections into one,
9673 and the entries in the index tables are now offsets into these sections.
9674 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
9677 Index Section Contents:
9679 Hash Table of Signatures dwp_hash_table.hash_table
9680 Parallel Table of Indices dwp_hash_table.unit_table
9681 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
9682 Table of Section Sizes dwp_hash_table.v2.sizes
9684 The index section header consists of:
9686 V, 32 bit version number
9687 L, 32 bit number of columns in the table of section offsets
9688 N, 32 bit number of compilation units or type units in the index
9689 M, 32 bit number of slots in the hash table
9691 Numbers are recorded using the byte order of the application binary.
9693 The hash table has the same format as version 1.
9694 The parallel table of indices has the same format as version 1,
9695 except that the entries are origin-1 indices into the table of sections
9696 offsets and the table of section sizes.
9698 The table of offsets begins immediately following the parallel table
9699 (at offset 16 + 12 * M from the beginning of the section). The table is
9700 a two-dimensional array of 32-bit words (using the byte order of the
9701 application binary), with L columns and N+1 rows, in row-major order.
9702 Each row in the array is indexed starting from 0. The first row provides
9703 a key to the remaining rows: each column in this row provides an identifier
9704 for a debug section, and the offsets in the same column of subsequent rows
9705 refer to that section. The section identifiers are:
9707 DW_SECT_INFO 1 .debug_info.dwo
9708 DW_SECT_TYPES 2 .debug_types.dwo
9709 DW_SECT_ABBREV 3 .debug_abbrev.dwo
9710 DW_SECT_LINE 4 .debug_line.dwo
9711 DW_SECT_LOC 5 .debug_loc.dwo
9712 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
9713 DW_SECT_MACINFO 7 .debug_macinfo.dwo
9714 DW_SECT_MACRO 8 .debug_macro.dwo
9716 The offsets provided by the CU and TU index sections are the base offsets
9717 for the contributions made by each CU or TU to the corresponding section
9718 in the package file. Each CU and TU header contains an abbrev_offset
9719 field, used to find the abbreviations table for that CU or TU within the
9720 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
9721 be interpreted as relative to the base offset given in the index section.
9722 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
9723 should be interpreted as relative to the base offset for .debug_line.dwo,
9724 and offsets into other debug sections obtained from DWARF attributes should
9725 also be interpreted as relative to the corresponding base offset.
9727 The table of sizes begins immediately following the table of offsets.
9728 Like the table of offsets, it is a two-dimensional array of 32-bit words,
9729 with L columns and N rows, in row-major order. Each row in the array is
9730 indexed starting from 1 (row 0 is shared by the two tables).
9734 Hash table lookup is handled the same in version 1 and 2:
9736 We assume that N and M will not exceed 2^32 - 1.
9737 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
9739 Given a 64-bit compilation unit signature or a type signature S, an entry
9740 in the hash table is located as follows:
9742 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
9743 the low-order k bits all set to 1.
9745 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
9747 3) If the hash table entry at index H matches the signature, use that
9748 entry. If the hash table entry at index H is unused (all zeroes),
9749 terminate the search: the signature is not present in the table.
9751 4) Let H = (H + H') modulo M. Repeat at Step 3.
9753 Because M > N and H' and M are relatively prime, the search is guaranteed
9754 to stop at an unused slot or find the match. */
9756 /* Create a hash table to map DWO IDs to their CU/TU entry in
9757 .debug_{info,types}.dwo in DWP_FILE.
9758 Returns NULL if there isn't one.
9759 Note: This function processes DWP files only, not DWO files. */
9761 static struct dwp_hash_table
*
9762 create_dwp_hash_table (struct dwp_file
*dwp_file
, int is_debug_types
)
9764 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9765 bfd
*dbfd
= dwp_file
->dbfd
;
9766 const gdb_byte
*index_ptr
, *index_end
;
9767 struct dwarf2_section_info
*index
;
9768 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
9769 struct dwp_hash_table
*htab
;
9772 index
= &dwp_file
->sections
.tu_index
;
9774 index
= &dwp_file
->sections
.cu_index
;
9776 if (dwarf2_section_empty_p (index
))
9778 dwarf2_read_section (objfile
, index
);
9780 index_ptr
= index
->buffer
;
9781 index_end
= index_ptr
+ index
->size
;
9783 version
= read_4_bytes (dbfd
, index_ptr
);
9786 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
9790 nr_units
= read_4_bytes (dbfd
, index_ptr
);
9792 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
9795 if (version
!= 1 && version
!= 2)
9797 error (_("Dwarf Error: unsupported DWP file version (%s)"
9799 pulongest (version
), dwp_file
->name
);
9801 if (nr_slots
!= (nr_slots
& -nr_slots
))
9803 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
9804 " is not power of 2 [in module %s]"),
9805 pulongest (nr_slots
), dwp_file
->name
);
9808 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
9809 htab
->version
= version
;
9810 htab
->nr_columns
= nr_columns
;
9811 htab
->nr_units
= nr_units
;
9812 htab
->nr_slots
= nr_slots
;
9813 htab
->hash_table
= index_ptr
;
9814 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
9816 /* Exit early if the table is empty. */
9817 if (nr_slots
== 0 || nr_units
== 0
9818 || (version
== 2 && nr_columns
== 0))
9820 /* All must be zero. */
9821 if (nr_slots
!= 0 || nr_units
!= 0
9822 || (version
== 2 && nr_columns
!= 0))
9824 complaint (&symfile_complaints
,
9825 _("Empty DWP but nr_slots,nr_units,nr_columns not"
9826 " all zero [in modules %s]"),
9834 htab
->section_pool
.v1
.indices
=
9835 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
9836 /* It's harder to decide whether the section is too small in v1.
9837 V1 is deprecated anyway so we punt. */
9841 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
9842 int *ids
= htab
->section_pool
.v2
.section_ids
;
9843 /* Reverse map for error checking. */
9844 int ids_seen
[DW_SECT_MAX
+ 1];
9849 error (_("Dwarf Error: bad DWP hash table, too few columns"
9850 " in section table [in module %s]"),
9853 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
9855 error (_("Dwarf Error: bad DWP hash table, too many columns"
9856 " in section table [in module %s]"),
9859 memset (ids
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
9860 memset (ids_seen
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
9861 for (i
= 0; i
< nr_columns
; ++i
)
9863 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
9865 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
9867 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
9868 " in section table [in module %s]"),
9869 id
, dwp_file
->name
);
9871 if (ids_seen
[id
] != -1)
9873 error (_("Dwarf Error: bad DWP hash table, duplicate section"
9874 " id %d in section table [in module %s]"),
9875 id
, dwp_file
->name
);
9880 /* Must have exactly one info or types section. */
9881 if (((ids_seen
[DW_SECT_INFO
] != -1)
9882 + (ids_seen
[DW_SECT_TYPES
] != -1))
9885 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
9886 " DWO info/types section [in module %s]"),
9889 /* Must have an abbrev section. */
9890 if (ids_seen
[DW_SECT_ABBREV
] == -1)
9892 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
9893 " section [in module %s]"),
9896 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
9897 htab
->section_pool
.v2
.sizes
=
9898 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
9899 * nr_units
* nr_columns
);
9900 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
9901 * nr_units
* nr_columns
))
9904 error (_("Dwarf Error: DWP index section is corrupt (too small)"
9913 /* Update SECTIONS with the data from SECTP.
9915 This function is like the other "locate" section routines that are
9916 passed to bfd_map_over_sections, but in this context the sections to
9917 read comes from the DWP V1 hash table, not the full ELF section table.
9919 The result is non-zero for success, or zero if an error was found. */
9922 locate_v1_virtual_dwo_sections (asection
*sectp
,
9923 struct virtual_v1_dwo_sections
*sections
)
9925 const struct dwop_section_names
*names
= &dwop_section_names
;
9927 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
9929 /* There can be only one. */
9930 if (sections
->abbrev
.s
.asection
!= NULL
)
9932 sections
->abbrev
.s
.asection
= sectp
;
9933 sections
->abbrev
.size
= bfd_get_section_size (sectp
);
9935 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
9936 || section_is_p (sectp
->name
, &names
->types_dwo
))
9938 /* There can be only one. */
9939 if (sections
->info_or_types
.s
.asection
!= NULL
)
9941 sections
->info_or_types
.s
.asection
= sectp
;
9942 sections
->info_or_types
.size
= bfd_get_section_size (sectp
);
9944 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
9946 /* There can be only one. */
9947 if (sections
->line
.s
.asection
!= NULL
)
9949 sections
->line
.s
.asection
= sectp
;
9950 sections
->line
.size
= bfd_get_section_size (sectp
);
9952 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
9954 /* There can be only one. */
9955 if (sections
->loc
.s
.asection
!= NULL
)
9957 sections
->loc
.s
.asection
= sectp
;
9958 sections
->loc
.size
= bfd_get_section_size (sectp
);
9960 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
9962 /* There can be only one. */
9963 if (sections
->macinfo
.s
.asection
!= NULL
)
9965 sections
->macinfo
.s
.asection
= sectp
;
9966 sections
->macinfo
.size
= bfd_get_section_size (sectp
);
9968 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
9970 /* There can be only one. */
9971 if (sections
->macro
.s
.asection
!= NULL
)
9973 sections
->macro
.s
.asection
= sectp
;
9974 sections
->macro
.size
= bfd_get_section_size (sectp
);
9976 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
9978 /* There can be only one. */
9979 if (sections
->str_offsets
.s
.asection
!= NULL
)
9981 sections
->str_offsets
.s
.asection
= sectp
;
9982 sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
9986 /* No other kind of section is valid. */
9993 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
9994 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
9995 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
9996 This is for DWP version 1 files. */
9998 static struct dwo_unit
*
9999 create_dwo_unit_in_dwp_v1 (struct dwp_file
*dwp_file
,
10000 uint32_t unit_index
,
10001 const char *comp_dir
,
10002 ULONGEST signature
, int is_debug_types
)
10004 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10005 const struct dwp_hash_table
*dwp_htab
=
10006 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
10007 bfd
*dbfd
= dwp_file
->dbfd
;
10008 const char *kind
= is_debug_types
? "TU" : "CU";
10009 struct dwo_file
*dwo_file
;
10010 struct dwo_unit
*dwo_unit
;
10011 struct virtual_v1_dwo_sections sections
;
10012 void **dwo_file_slot
;
10013 char *virtual_dwo_name
;
10014 struct dwarf2_section_info
*cutu
;
10015 struct cleanup
*cleanups
;
10018 gdb_assert (dwp_file
->version
== 1);
10020 if (dwarf_read_debug
)
10022 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
10024 pulongest (unit_index
), hex_string (signature
),
10028 /* Fetch the sections of this DWO unit.
10029 Put a limit on the number of sections we look for so that bad data
10030 doesn't cause us to loop forever. */
10032 #define MAX_NR_V1_DWO_SECTIONS \
10033 (1 /* .debug_info or .debug_types */ \
10034 + 1 /* .debug_abbrev */ \
10035 + 1 /* .debug_line */ \
10036 + 1 /* .debug_loc */ \
10037 + 1 /* .debug_str_offsets */ \
10038 + 1 /* .debug_macro or .debug_macinfo */ \
10039 + 1 /* trailing zero */)
10041 memset (§ions
, 0, sizeof (sections
));
10042 cleanups
= make_cleanup (null_cleanup
, 0);
10044 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
10047 uint32_t section_nr
=
10048 read_4_bytes (dbfd
,
10049 dwp_htab
->section_pool
.v1
.indices
10050 + (unit_index
+ i
) * sizeof (uint32_t));
10052 if (section_nr
== 0)
10054 if (section_nr
>= dwp_file
->num_sections
)
10056 error (_("Dwarf Error: bad DWP hash table, section number too large"
10057 " [in module %s]"),
10061 sectp
= dwp_file
->elf_sections
[section_nr
];
10062 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
10064 error (_("Dwarf Error: bad DWP hash table, invalid section found"
10065 " [in module %s]"),
10071 || dwarf2_section_empty_p (§ions
.info_or_types
)
10072 || dwarf2_section_empty_p (§ions
.abbrev
))
10074 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
10075 " [in module %s]"),
10078 if (i
== MAX_NR_V1_DWO_SECTIONS
)
10080 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
10081 " [in module %s]"),
10085 /* It's easier for the rest of the code if we fake a struct dwo_file and
10086 have dwo_unit "live" in that. At least for now.
10088 The DWP file can be made up of a random collection of CUs and TUs.
10089 However, for each CU + set of TUs that came from the same original DWO
10090 file, we can combine them back into a virtual DWO file to save space
10091 (fewer struct dwo_file objects to allocate). Remember that for really
10092 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
10095 xstrprintf ("virtual-dwo/%d-%d-%d-%d",
10096 get_section_id (§ions
.abbrev
),
10097 get_section_id (§ions
.line
),
10098 get_section_id (§ions
.loc
),
10099 get_section_id (§ions
.str_offsets
));
10100 make_cleanup (xfree
, virtual_dwo_name
);
10101 /* Can we use an existing virtual DWO file? */
10102 dwo_file_slot
= lookup_dwo_file_slot (virtual_dwo_name
, comp_dir
);
10103 /* Create one if necessary. */
10104 if (*dwo_file_slot
== NULL
)
10106 if (dwarf_read_debug
)
10108 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
10111 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
10112 dwo_file
->dwo_name
= obstack_copy0 (&objfile
->objfile_obstack
,
10114 strlen (virtual_dwo_name
));
10115 dwo_file
->comp_dir
= comp_dir
;
10116 dwo_file
->sections
.abbrev
= sections
.abbrev
;
10117 dwo_file
->sections
.line
= sections
.line
;
10118 dwo_file
->sections
.loc
= sections
.loc
;
10119 dwo_file
->sections
.macinfo
= sections
.macinfo
;
10120 dwo_file
->sections
.macro
= sections
.macro
;
10121 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
10122 /* The "str" section is global to the entire DWP file. */
10123 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
10124 /* The info or types section is assigned below to dwo_unit,
10125 there's no need to record it in dwo_file.
10126 Also, we can't simply record type sections in dwo_file because
10127 we record a pointer into the vector in dwo_unit. As we collect more
10128 types we'll grow the vector and eventually have to reallocate space
10129 for it, invalidating all copies of pointers into the previous
10131 *dwo_file_slot
= dwo_file
;
10135 if (dwarf_read_debug
)
10137 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
10140 dwo_file
= *dwo_file_slot
;
10142 do_cleanups (cleanups
);
10144 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
10145 dwo_unit
->dwo_file
= dwo_file
;
10146 dwo_unit
->signature
= signature
;
10147 dwo_unit
->section
= obstack_alloc (&objfile
->objfile_obstack
,
10148 sizeof (struct dwarf2_section_info
));
10149 *dwo_unit
->section
= sections
.info_or_types
;
10150 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
10155 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
10156 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
10157 piece within that section used by a TU/CU, return a virtual section
10158 of just that piece. */
10160 static struct dwarf2_section_info
10161 create_dwp_v2_section (struct dwarf2_section_info
*section
,
10162 bfd_size_type offset
, bfd_size_type size
)
10164 struct dwarf2_section_info result
;
10167 gdb_assert (section
!= NULL
);
10168 gdb_assert (!section
->is_virtual
);
10170 memset (&result
, 0, sizeof (result
));
10171 result
.s
.containing_section
= section
;
10172 result
.is_virtual
= 1;
10177 sectp
= get_section_bfd_section (section
);
10179 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
10180 bounds of the real section. This is a pretty-rare event, so just
10181 flag an error (easier) instead of a warning and trying to cope. */
10183 || offset
+ size
> bfd_get_section_size (sectp
))
10185 bfd
*abfd
= sectp
->owner
;
10187 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
10188 " in section %s [in module %s]"),
10189 sectp
? bfd_section_name (abfd
, sectp
) : "<unknown>",
10190 objfile_name (dwarf2_per_objfile
->objfile
));
10193 result
.virtual_offset
= offset
;
10194 result
.size
= size
;
10198 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
10199 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
10200 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
10201 This is for DWP version 2 files. */
10203 static struct dwo_unit
*
10204 create_dwo_unit_in_dwp_v2 (struct dwp_file
*dwp_file
,
10205 uint32_t unit_index
,
10206 const char *comp_dir
,
10207 ULONGEST signature
, int is_debug_types
)
10209 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10210 const struct dwp_hash_table
*dwp_htab
=
10211 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
10212 bfd
*dbfd
= dwp_file
->dbfd
;
10213 const char *kind
= is_debug_types
? "TU" : "CU";
10214 struct dwo_file
*dwo_file
;
10215 struct dwo_unit
*dwo_unit
;
10216 struct virtual_v2_dwo_sections sections
;
10217 void **dwo_file_slot
;
10218 char *virtual_dwo_name
;
10219 struct dwarf2_section_info
*cutu
;
10220 struct cleanup
*cleanups
;
10223 gdb_assert (dwp_file
->version
== 2);
10225 if (dwarf_read_debug
)
10227 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
10229 pulongest (unit_index
), hex_string (signature
),
10233 /* Fetch the section offsets of this DWO unit. */
10235 memset (§ions
, 0, sizeof (sections
));
10236 cleanups
= make_cleanup (null_cleanup
, 0);
10238 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
10240 uint32_t offset
= read_4_bytes (dbfd
,
10241 dwp_htab
->section_pool
.v2
.offsets
10242 + (((unit_index
- 1) * dwp_htab
->nr_columns
10244 * sizeof (uint32_t)));
10245 uint32_t size
= read_4_bytes (dbfd
,
10246 dwp_htab
->section_pool
.v2
.sizes
10247 + (((unit_index
- 1) * dwp_htab
->nr_columns
10249 * sizeof (uint32_t)));
10251 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
10254 case DW_SECT_TYPES
:
10255 sections
.info_or_types_offset
= offset
;
10256 sections
.info_or_types_size
= size
;
10258 case DW_SECT_ABBREV
:
10259 sections
.abbrev_offset
= offset
;
10260 sections
.abbrev_size
= size
;
10263 sections
.line_offset
= offset
;
10264 sections
.line_size
= size
;
10267 sections
.loc_offset
= offset
;
10268 sections
.loc_size
= size
;
10270 case DW_SECT_STR_OFFSETS
:
10271 sections
.str_offsets_offset
= offset
;
10272 sections
.str_offsets_size
= size
;
10274 case DW_SECT_MACINFO
:
10275 sections
.macinfo_offset
= offset
;
10276 sections
.macinfo_size
= size
;
10278 case DW_SECT_MACRO
:
10279 sections
.macro_offset
= offset
;
10280 sections
.macro_size
= size
;
10285 /* It's easier for the rest of the code if we fake a struct dwo_file and
10286 have dwo_unit "live" in that. At least for now.
10288 The DWP file can be made up of a random collection of CUs and TUs.
10289 However, for each CU + set of TUs that came from the same original DWO
10290 file, we can combine them back into a virtual DWO file to save space
10291 (fewer struct dwo_file objects to allocate). Remember that for really
10292 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
10295 xstrprintf ("virtual-dwo/%ld-%ld-%ld-%ld",
10296 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
10297 (long) (sections
.line_size
? sections
.line_offset
: 0),
10298 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
10299 (long) (sections
.str_offsets_size
10300 ? sections
.str_offsets_offset
: 0));
10301 make_cleanup (xfree
, virtual_dwo_name
);
10302 /* Can we use an existing virtual DWO file? */
10303 dwo_file_slot
= lookup_dwo_file_slot (virtual_dwo_name
, comp_dir
);
10304 /* Create one if necessary. */
10305 if (*dwo_file_slot
== NULL
)
10307 if (dwarf_read_debug
)
10309 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
10312 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
10313 dwo_file
->dwo_name
= obstack_copy0 (&objfile
->objfile_obstack
,
10315 strlen (virtual_dwo_name
));
10316 dwo_file
->comp_dir
= comp_dir
;
10317 dwo_file
->sections
.abbrev
=
10318 create_dwp_v2_section (&dwp_file
->sections
.abbrev
,
10319 sections
.abbrev_offset
, sections
.abbrev_size
);
10320 dwo_file
->sections
.line
=
10321 create_dwp_v2_section (&dwp_file
->sections
.line
,
10322 sections
.line_offset
, sections
.line_size
);
10323 dwo_file
->sections
.loc
=
10324 create_dwp_v2_section (&dwp_file
->sections
.loc
,
10325 sections
.loc_offset
, sections
.loc_size
);
10326 dwo_file
->sections
.macinfo
=
10327 create_dwp_v2_section (&dwp_file
->sections
.macinfo
,
10328 sections
.macinfo_offset
, sections
.macinfo_size
);
10329 dwo_file
->sections
.macro
=
10330 create_dwp_v2_section (&dwp_file
->sections
.macro
,
10331 sections
.macro_offset
, sections
.macro_size
);
10332 dwo_file
->sections
.str_offsets
=
10333 create_dwp_v2_section (&dwp_file
->sections
.str_offsets
,
10334 sections
.str_offsets_offset
,
10335 sections
.str_offsets_size
);
10336 /* The "str" section is global to the entire DWP file. */
10337 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
10338 /* The info or types section is assigned below to dwo_unit,
10339 there's no need to record it in dwo_file.
10340 Also, we can't simply record type sections in dwo_file because
10341 we record a pointer into the vector in dwo_unit. As we collect more
10342 types we'll grow the vector and eventually have to reallocate space
10343 for it, invalidating all copies of pointers into the previous
10345 *dwo_file_slot
= dwo_file
;
10349 if (dwarf_read_debug
)
10351 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
10354 dwo_file
= *dwo_file_slot
;
10356 do_cleanups (cleanups
);
10358 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
10359 dwo_unit
->dwo_file
= dwo_file
;
10360 dwo_unit
->signature
= signature
;
10361 dwo_unit
->section
= obstack_alloc (&objfile
->objfile_obstack
,
10362 sizeof (struct dwarf2_section_info
));
10363 *dwo_unit
->section
= create_dwp_v2_section (is_debug_types
10364 ? &dwp_file
->sections
.types
10365 : &dwp_file
->sections
.info
,
10366 sections
.info_or_types_offset
,
10367 sections
.info_or_types_size
);
10368 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
10373 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
10374 Returns NULL if the signature isn't found. */
10376 static struct dwo_unit
*
10377 lookup_dwo_unit_in_dwp (struct dwp_file
*dwp_file
, const char *comp_dir
,
10378 ULONGEST signature
, int is_debug_types
)
10380 const struct dwp_hash_table
*dwp_htab
=
10381 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
10382 bfd
*dbfd
= dwp_file
->dbfd
;
10383 uint32_t mask
= dwp_htab
->nr_slots
- 1;
10384 uint32_t hash
= signature
& mask
;
10385 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
10388 struct dwo_unit find_dwo_cu
, *dwo_cu
;
10390 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
10391 find_dwo_cu
.signature
= signature
;
10392 slot
= htab_find_slot (is_debug_types
10393 ? dwp_file
->loaded_tus
10394 : dwp_file
->loaded_cus
,
10395 &find_dwo_cu
, INSERT
);
10400 /* Use a for loop so that we don't loop forever on bad debug info. */
10401 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
10403 ULONGEST signature_in_table
;
10405 signature_in_table
=
10406 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
10407 if (signature_in_table
== signature
)
10409 uint32_t unit_index
=
10410 read_4_bytes (dbfd
,
10411 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
10413 if (dwp_file
->version
== 1)
10415 *slot
= create_dwo_unit_in_dwp_v1 (dwp_file
, unit_index
,
10416 comp_dir
, signature
,
10421 *slot
= create_dwo_unit_in_dwp_v2 (dwp_file
, unit_index
,
10422 comp_dir
, signature
,
10427 if (signature_in_table
== 0)
10429 hash
= (hash
+ hash2
) & mask
;
10432 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
10433 " [in module %s]"),
10437 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
10438 Open the file specified by FILE_NAME and hand it off to BFD for
10439 preliminary analysis. Return a newly initialized bfd *, which
10440 includes a canonicalized copy of FILE_NAME.
10441 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
10442 SEARCH_CWD is true if the current directory is to be searched.
10443 It will be searched before debug-file-directory.
10444 If successful, the file is added to the bfd include table of the
10445 objfile's bfd (see gdb_bfd_record_inclusion).
10446 If unable to find/open the file, return NULL.
10447 NOTE: This function is derived from symfile_bfd_open. */
10450 try_open_dwop_file (const char *file_name
, int is_dwp
, int search_cwd
)
10454 char *absolute_name
;
10455 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
10456 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
10457 to debug_file_directory. */
10459 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
10463 if (*debug_file_directory
!= '\0')
10464 search_path
= concat (".", dirname_separator_string
,
10465 debug_file_directory
, NULL
);
10467 search_path
= xstrdup (".");
10470 search_path
= xstrdup (debug_file_directory
);
10472 flags
= OPF_RETURN_REALPATH
;
10474 flags
|= OPF_SEARCH_IN_PATH
;
10475 desc
= openp (search_path
, flags
, file_name
,
10476 O_RDONLY
| O_BINARY
, &absolute_name
);
10477 xfree (search_path
);
10481 sym_bfd
= gdb_bfd_open (absolute_name
, gnutarget
, desc
);
10482 xfree (absolute_name
);
10483 if (sym_bfd
== NULL
)
10485 bfd_set_cacheable (sym_bfd
, 1);
10487 if (!bfd_check_format (sym_bfd
, bfd_object
))
10489 gdb_bfd_unref (sym_bfd
); /* This also closes desc. */
10493 /* Success. Record the bfd as having been included by the objfile's bfd.
10494 This is important because things like demangled_names_hash lives in the
10495 objfile's per_bfd space and may have references to things like symbol
10496 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
10497 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
);
10502 /* Try to open DWO file FILE_NAME.
10503 COMP_DIR is the DW_AT_comp_dir attribute.
10504 The result is the bfd handle of the file.
10505 If there is a problem finding or opening the file, return NULL.
10506 Upon success, the canonicalized path of the file is stored in the bfd,
10507 same as symfile_bfd_open. */
10510 open_dwo_file (const char *file_name
, const char *comp_dir
)
10514 if (IS_ABSOLUTE_PATH (file_name
))
10515 return try_open_dwop_file (file_name
, 0 /*is_dwp*/, 0 /*search_cwd*/);
10517 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
10519 if (comp_dir
!= NULL
)
10521 char *path_to_try
= concat (comp_dir
, SLASH_STRING
, file_name
, NULL
);
10523 /* NOTE: If comp_dir is a relative path, this will also try the
10524 search path, which seems useful. */
10525 abfd
= try_open_dwop_file (path_to_try
, 0 /*is_dwp*/, 1 /*search_cwd*/);
10526 xfree (path_to_try
);
10531 /* That didn't work, try debug-file-directory, which, despite its name,
10532 is a list of paths. */
10534 if (*debug_file_directory
== '\0')
10537 return try_open_dwop_file (file_name
, 0 /*is_dwp*/, 1 /*search_cwd*/);
10540 /* This function is mapped across the sections and remembers the offset and
10541 size of each of the DWO debugging sections we are interested in. */
10544 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
10546 struct dwo_sections
*dwo_sections
= dwo_sections_ptr
;
10547 const struct dwop_section_names
*names
= &dwop_section_names
;
10549 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
10551 dwo_sections
->abbrev
.s
.asection
= sectp
;
10552 dwo_sections
->abbrev
.size
= bfd_get_section_size (sectp
);
10554 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
10556 dwo_sections
->info
.s
.asection
= sectp
;
10557 dwo_sections
->info
.size
= bfd_get_section_size (sectp
);
10559 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
10561 dwo_sections
->line
.s
.asection
= sectp
;
10562 dwo_sections
->line
.size
= bfd_get_section_size (sectp
);
10564 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
10566 dwo_sections
->loc
.s
.asection
= sectp
;
10567 dwo_sections
->loc
.size
= bfd_get_section_size (sectp
);
10569 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
10571 dwo_sections
->macinfo
.s
.asection
= sectp
;
10572 dwo_sections
->macinfo
.size
= bfd_get_section_size (sectp
);
10574 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
10576 dwo_sections
->macro
.s
.asection
= sectp
;
10577 dwo_sections
->macro
.size
= bfd_get_section_size (sectp
);
10579 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
10581 dwo_sections
->str
.s
.asection
= sectp
;
10582 dwo_sections
->str
.size
= bfd_get_section_size (sectp
);
10584 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
10586 dwo_sections
->str_offsets
.s
.asection
= sectp
;
10587 dwo_sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
10589 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
10591 struct dwarf2_section_info type_section
;
10593 memset (&type_section
, 0, sizeof (type_section
));
10594 type_section
.s
.asection
= sectp
;
10595 type_section
.size
= bfd_get_section_size (sectp
);
10596 VEC_safe_push (dwarf2_section_info_def
, dwo_sections
->types
,
10601 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
10602 by PER_CU. This is for the non-DWP case.
10603 The result is NULL if DWO_NAME can't be found. */
10605 static struct dwo_file
*
10606 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
10607 const char *dwo_name
, const char *comp_dir
)
10609 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10610 struct dwo_file
*dwo_file
;
10612 struct cleanup
*cleanups
;
10614 dbfd
= open_dwo_file (dwo_name
, comp_dir
);
10617 if (dwarf_read_debug
)
10618 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
10621 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
10622 dwo_file
->dwo_name
= dwo_name
;
10623 dwo_file
->comp_dir
= comp_dir
;
10624 dwo_file
->dbfd
= dbfd
;
10626 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwo_file
);
10628 bfd_map_over_sections (dbfd
, dwarf2_locate_dwo_sections
, &dwo_file
->sections
);
10630 dwo_file
->cu
= create_dwo_cu (dwo_file
);
10632 dwo_file
->tus
= create_debug_types_hash_table (dwo_file
,
10633 dwo_file
->sections
.types
);
10635 discard_cleanups (cleanups
);
10637 if (dwarf_read_debug
)
10638 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
10643 /* This function is mapped across the sections and remembers the offset and
10644 size of each of the DWP debugging sections common to version 1 and 2 that
10645 we are interested in. */
10648 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
10649 void *dwp_file_ptr
)
10651 struct dwp_file
*dwp_file
= dwp_file_ptr
;
10652 const struct dwop_section_names
*names
= &dwop_section_names
;
10653 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
10655 /* Record the ELF section number for later lookup: this is what the
10656 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
10657 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
10658 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
10660 /* Look for specific sections that we need. */
10661 if (section_is_p (sectp
->name
, &names
->str_dwo
))
10663 dwp_file
->sections
.str
.s
.asection
= sectp
;
10664 dwp_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
10666 else if (section_is_p (sectp
->name
, &names
->cu_index
))
10668 dwp_file
->sections
.cu_index
.s
.asection
= sectp
;
10669 dwp_file
->sections
.cu_index
.size
= bfd_get_section_size (sectp
);
10671 else if (section_is_p (sectp
->name
, &names
->tu_index
))
10673 dwp_file
->sections
.tu_index
.s
.asection
= sectp
;
10674 dwp_file
->sections
.tu_index
.size
= bfd_get_section_size (sectp
);
10678 /* This function is mapped across the sections and remembers the offset and
10679 size of each of the DWP version 2 debugging sections that we are interested
10680 in. This is split into a separate function because we don't know if we
10681 have version 1 or 2 until we parse the cu_index/tu_index sections. */
10684 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
10686 struct dwp_file
*dwp_file
= dwp_file_ptr
;
10687 const struct dwop_section_names
*names
= &dwop_section_names
;
10688 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
10690 /* Record the ELF section number for later lookup: this is what the
10691 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
10692 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
10693 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
10695 /* Look for specific sections that we need. */
10696 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
10698 dwp_file
->sections
.abbrev
.s
.asection
= sectp
;
10699 dwp_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
10701 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
10703 dwp_file
->sections
.info
.s
.asection
= sectp
;
10704 dwp_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
10706 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
10708 dwp_file
->sections
.line
.s
.asection
= sectp
;
10709 dwp_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
10711 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
10713 dwp_file
->sections
.loc
.s
.asection
= sectp
;
10714 dwp_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
10716 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
10718 dwp_file
->sections
.macinfo
.s
.asection
= sectp
;
10719 dwp_file
->sections
.macinfo
.size
= bfd_get_section_size (sectp
);
10721 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
10723 dwp_file
->sections
.macro
.s
.asection
= sectp
;
10724 dwp_file
->sections
.macro
.size
= bfd_get_section_size (sectp
);
10726 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
10728 dwp_file
->sections
.str_offsets
.s
.asection
= sectp
;
10729 dwp_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
10731 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
10733 dwp_file
->sections
.types
.s
.asection
= sectp
;
10734 dwp_file
->sections
.types
.size
= bfd_get_section_size (sectp
);
10738 /* Hash function for dwp_file loaded CUs/TUs. */
10741 hash_dwp_loaded_cutus (const void *item
)
10743 const struct dwo_unit
*dwo_unit
= item
;
10745 /* This drops the top 32 bits of the signature, but is ok for a hash. */
10746 return dwo_unit
->signature
;
10749 /* Equality function for dwp_file loaded CUs/TUs. */
10752 eq_dwp_loaded_cutus (const void *a
, const void *b
)
10754 const struct dwo_unit
*dua
= a
;
10755 const struct dwo_unit
*dub
= b
;
10757 return dua
->signature
== dub
->signature
;
10760 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
10763 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
10765 return htab_create_alloc_ex (3,
10766 hash_dwp_loaded_cutus
,
10767 eq_dwp_loaded_cutus
,
10769 &objfile
->objfile_obstack
,
10770 hashtab_obstack_allocate
,
10771 dummy_obstack_deallocate
);
10774 /* Try to open DWP file FILE_NAME.
10775 The result is the bfd handle of the file.
10776 If there is a problem finding or opening the file, return NULL.
10777 Upon success, the canonicalized path of the file is stored in the bfd,
10778 same as symfile_bfd_open. */
10781 open_dwp_file (const char *file_name
)
10785 abfd
= try_open_dwop_file (file_name
, 1 /*is_dwp*/, 1 /*search_cwd*/);
10789 /* Work around upstream bug 15652.
10790 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
10791 [Whether that's a "bug" is debatable, but it is getting in our way.]
10792 We have no real idea where the dwp file is, because gdb's realpath-ing
10793 of the executable's path may have discarded the needed info.
10794 [IWBN if the dwp file name was recorded in the executable, akin to
10795 .gnu_debuglink, but that doesn't exist yet.]
10796 Strip the directory from FILE_NAME and search again. */
10797 if (*debug_file_directory
!= '\0')
10799 /* Don't implicitly search the current directory here.
10800 If the user wants to search "." to handle this case,
10801 it must be added to debug-file-directory. */
10802 return try_open_dwop_file (lbasename (file_name
), 1 /*is_dwp*/,
10809 /* Initialize the use of the DWP file for the current objfile.
10810 By convention the name of the DWP file is ${objfile}.dwp.
10811 The result is NULL if it can't be found. */
10813 static struct dwp_file
*
10814 open_and_init_dwp_file (void)
10816 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10817 struct dwp_file
*dwp_file
;
10820 struct cleanup
*cleanups
;
10822 /* Try to find first .dwp for the binary file before any symbolic links
10824 dwp_name
= xstrprintf ("%s.dwp", objfile
->original_name
);
10825 cleanups
= make_cleanup (xfree
, dwp_name
);
10827 dbfd
= open_dwp_file (dwp_name
);
10829 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
10831 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
10832 dwp_name
= xstrprintf ("%s.dwp", objfile_name (objfile
));
10833 make_cleanup (xfree
, dwp_name
);
10834 dbfd
= open_dwp_file (dwp_name
);
10839 if (dwarf_read_debug
)
10840 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
);
10841 do_cleanups (cleanups
);
10844 dwp_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_file
);
10845 dwp_file
->name
= bfd_get_filename (dbfd
);
10846 dwp_file
->dbfd
= dbfd
;
10847 do_cleanups (cleanups
);
10849 /* +1: section 0 is unused */
10850 dwp_file
->num_sections
= bfd_count_sections (dbfd
) + 1;
10851 dwp_file
->elf_sections
=
10852 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
10853 dwp_file
->num_sections
, asection
*);
10855 bfd_map_over_sections (dbfd
, dwarf2_locate_common_dwp_sections
, dwp_file
);
10857 dwp_file
->cus
= create_dwp_hash_table (dwp_file
, 0);
10859 dwp_file
->tus
= create_dwp_hash_table (dwp_file
, 1);
10861 /* The DWP file version is stored in the hash table. Oh well. */
10862 if (dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
10864 /* Technically speaking, we should try to limp along, but this is
10865 pretty bizarre. We use pulongest here because that's the established
10866 portability solution (e.g, we cannot use %u for uint32_t). */
10867 error (_("Dwarf Error: DWP file CU version %s doesn't match"
10868 " TU version %s [in DWP file %s]"),
10869 pulongest (dwp_file
->cus
->version
),
10870 pulongest (dwp_file
->tus
->version
), dwp_name
);
10872 dwp_file
->version
= dwp_file
->cus
->version
;
10874 if (dwp_file
->version
== 2)
10875 bfd_map_over_sections (dbfd
, dwarf2_locate_v2_dwp_sections
, dwp_file
);
10877 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
10878 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
10880 if (dwarf_read_debug
)
10882 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
10883 fprintf_unfiltered (gdb_stdlog
,
10884 " %s CUs, %s TUs\n",
10885 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
10886 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
10892 /* Wrapper around open_and_init_dwp_file, only open it once. */
10894 static struct dwp_file
*
10895 get_dwp_file (void)
10897 if (! dwarf2_per_objfile
->dwp_checked
)
10899 dwarf2_per_objfile
->dwp_file
= open_and_init_dwp_file ();
10900 dwarf2_per_objfile
->dwp_checked
= 1;
10902 return dwarf2_per_objfile
->dwp_file
;
10905 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
10906 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
10907 or in the DWP file for the objfile, referenced by THIS_UNIT.
10908 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
10909 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
10911 This is called, for example, when wanting to read a variable with a
10912 complex location. Therefore we don't want to do file i/o for every call.
10913 Therefore we don't want to look for a DWO file on every call.
10914 Therefore we first see if we've already seen SIGNATURE in a DWP file,
10915 then we check if we've already seen DWO_NAME, and only THEN do we check
10918 The result is a pointer to the dwo_unit object or NULL if we didn't find it
10919 (dwo_id mismatch or couldn't find the DWO/DWP file). */
10921 static struct dwo_unit
*
10922 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
10923 const char *dwo_name
, const char *comp_dir
,
10924 ULONGEST signature
, int is_debug_types
)
10926 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10927 const char *kind
= is_debug_types
? "TU" : "CU";
10928 void **dwo_file_slot
;
10929 struct dwo_file
*dwo_file
;
10930 struct dwp_file
*dwp_file
;
10932 /* First see if there's a DWP file.
10933 If we have a DWP file but didn't find the DWO inside it, don't
10934 look for the original DWO file. It makes gdb behave differently
10935 depending on whether one is debugging in the build tree. */
10937 dwp_file
= get_dwp_file ();
10938 if (dwp_file
!= NULL
)
10940 const struct dwp_hash_table
*dwp_htab
=
10941 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
10943 if (dwp_htab
!= NULL
)
10945 struct dwo_unit
*dwo_cutu
=
10946 lookup_dwo_unit_in_dwp (dwp_file
, comp_dir
,
10947 signature
, is_debug_types
);
10949 if (dwo_cutu
!= NULL
)
10951 if (dwarf_read_debug
)
10953 fprintf_unfiltered (gdb_stdlog
,
10954 "Virtual DWO %s %s found: @%s\n",
10955 kind
, hex_string (signature
),
10956 host_address_to_string (dwo_cutu
));
10964 /* No DWP file, look for the DWO file. */
10966 dwo_file_slot
= lookup_dwo_file_slot (dwo_name
, comp_dir
);
10967 if (*dwo_file_slot
== NULL
)
10969 /* Read in the file and build a table of the CUs/TUs it contains. */
10970 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
10972 /* NOTE: This will be NULL if unable to open the file. */
10973 dwo_file
= *dwo_file_slot
;
10975 if (dwo_file
!= NULL
)
10977 struct dwo_unit
*dwo_cutu
= NULL
;
10979 if (is_debug_types
&& dwo_file
->tus
)
10981 struct dwo_unit find_dwo_cutu
;
10983 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
10984 find_dwo_cutu
.signature
= signature
;
10985 dwo_cutu
= htab_find (dwo_file
->tus
, &find_dwo_cutu
);
10987 else if (!is_debug_types
&& dwo_file
->cu
)
10989 if (signature
== dwo_file
->cu
->signature
)
10990 dwo_cutu
= dwo_file
->cu
;
10993 if (dwo_cutu
!= NULL
)
10995 if (dwarf_read_debug
)
10997 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
10998 kind
, dwo_name
, hex_string (signature
),
10999 host_address_to_string (dwo_cutu
));
11006 /* We didn't find it. This could mean a dwo_id mismatch, or
11007 someone deleted the DWO/DWP file, or the search path isn't set up
11008 correctly to find the file. */
11010 if (dwarf_read_debug
)
11012 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
11013 kind
, dwo_name
, hex_string (signature
));
11016 /* This is a warning and not a complaint because it can be caused by
11017 pilot error (e.g., user accidentally deleting the DWO). */
11019 /* Print the name of the DWP file if we looked there, helps the user
11020 better diagnose the problem. */
11021 char *dwp_text
= NULL
;
11022 struct cleanup
*cleanups
;
11024 if (dwp_file
!= NULL
)
11025 dwp_text
= xstrprintf (" [in DWP file %s]", lbasename (dwp_file
->name
));
11026 cleanups
= make_cleanup (xfree
, dwp_text
);
11028 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset 0x%x"
11029 " [in module %s]"),
11030 kind
, dwo_name
, hex_string (signature
),
11031 dwp_text
!= NULL
? dwp_text
: "",
11032 this_unit
->is_debug_types
? "TU" : "CU",
11033 this_unit
->offset
.sect_off
, objfile_name (objfile
));
11035 do_cleanups (cleanups
);
11040 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
11041 See lookup_dwo_cutu_unit for details. */
11043 static struct dwo_unit
*
11044 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
11045 const char *dwo_name
, const char *comp_dir
,
11046 ULONGEST signature
)
11048 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
11051 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
11052 See lookup_dwo_cutu_unit for details. */
11054 static struct dwo_unit
*
11055 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
11056 const char *dwo_name
, const char *comp_dir
)
11058 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
11061 /* Traversal function for queue_and_load_all_dwo_tus. */
11064 queue_and_load_dwo_tu (void **slot
, void *info
)
11066 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
11067 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
11068 ULONGEST signature
= dwo_unit
->signature
;
11069 struct signatured_type
*sig_type
=
11070 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
11072 if (sig_type
!= NULL
)
11074 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
11076 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
11077 a real dependency of PER_CU on SIG_TYPE. That is detected later
11078 while processing PER_CU. */
11079 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
11080 load_full_type_unit (sig_cu
);
11081 VEC_safe_push (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, sig_cu
);
11087 /* Queue all TUs contained in the DWO of PER_CU to be read in.
11088 The DWO may have the only definition of the type, though it may not be
11089 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
11090 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
11093 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
11095 struct dwo_unit
*dwo_unit
;
11096 struct dwo_file
*dwo_file
;
11098 gdb_assert (!per_cu
->is_debug_types
);
11099 gdb_assert (get_dwp_file () == NULL
);
11100 gdb_assert (per_cu
->cu
!= NULL
);
11102 dwo_unit
= per_cu
->cu
->dwo_unit
;
11103 gdb_assert (dwo_unit
!= NULL
);
11105 dwo_file
= dwo_unit
->dwo_file
;
11106 if (dwo_file
->tus
!= NULL
)
11107 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
11110 /* Free all resources associated with DWO_FILE.
11111 Close the DWO file and munmap the sections.
11112 All memory should be on the objfile obstack. */
11115 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
11118 struct dwarf2_section_info
*section
;
11120 /* Note: dbfd is NULL for virtual DWO files. */
11121 gdb_bfd_unref (dwo_file
->dbfd
);
11123 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
11126 /* Wrapper for free_dwo_file for use in cleanups. */
11129 free_dwo_file_cleanup (void *arg
)
11131 struct dwo_file
*dwo_file
= (struct dwo_file
*) arg
;
11132 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11134 free_dwo_file (dwo_file
, objfile
);
11137 /* Traversal function for free_dwo_files. */
11140 free_dwo_file_from_slot (void **slot
, void *info
)
11142 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
11143 struct objfile
*objfile
= (struct objfile
*) info
;
11145 free_dwo_file (dwo_file
, objfile
);
11150 /* Free all resources associated with DWO_FILES. */
11153 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
11155 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
11158 /* Read in various DIEs. */
11160 /* qsort helper for inherit_abstract_dies. */
11163 unsigned_int_compar (const void *ap
, const void *bp
)
11165 unsigned int a
= *(unsigned int *) ap
;
11166 unsigned int b
= *(unsigned int *) bp
;
11168 return (a
> b
) - (b
> a
);
11171 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
11172 Inherit only the children of the DW_AT_abstract_origin DIE not being
11173 already referenced by DW_AT_abstract_origin from the children of the
11177 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
11179 struct die_info
*child_die
;
11180 unsigned die_children_count
;
11181 /* CU offsets which were referenced by children of the current DIE. */
11182 sect_offset
*offsets
;
11183 sect_offset
*offsets_end
, *offsetp
;
11184 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
11185 struct die_info
*origin_die
;
11186 /* Iterator of the ORIGIN_DIE children. */
11187 struct die_info
*origin_child_die
;
11188 struct cleanup
*cleanups
;
11189 struct attribute
*attr
;
11190 struct dwarf2_cu
*origin_cu
;
11191 struct pending
**origin_previous_list_in_scope
;
11193 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
11197 /* Note that following die references may follow to a die in a
11201 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
11203 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
11205 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
11206 origin_cu
->list_in_scope
= cu
->list_in_scope
;
11208 if (die
->tag
!= origin_die
->tag
11209 && !(die
->tag
== DW_TAG_inlined_subroutine
11210 && origin_die
->tag
== DW_TAG_subprogram
))
11211 complaint (&symfile_complaints
,
11212 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
11213 die
->offset
.sect_off
, origin_die
->offset
.sect_off
);
11215 child_die
= die
->child
;
11216 die_children_count
= 0;
11217 while (child_die
&& child_die
->tag
)
11219 child_die
= sibling_die (child_die
);
11220 die_children_count
++;
11222 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
11223 cleanups
= make_cleanup (xfree
, offsets
);
11225 offsets_end
= offsets
;
11226 for (child_die
= die
->child
;
11227 child_die
&& child_die
->tag
;
11228 child_die
= sibling_die (child_die
))
11230 struct die_info
*child_origin_die
;
11231 struct dwarf2_cu
*child_origin_cu
;
11233 /* We are trying to process concrete instance entries:
11234 DW_TAG_GNU_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
11235 it's not relevant to our analysis here. i.e. detecting DIEs that are
11236 present in the abstract instance but not referenced in the concrete
11238 if (child_die
->tag
== DW_TAG_GNU_call_site
)
11241 /* For each CHILD_DIE, find the corresponding child of
11242 ORIGIN_DIE. If there is more than one layer of
11243 DW_AT_abstract_origin, follow them all; there shouldn't be,
11244 but GCC versions at least through 4.4 generate this (GCC PR
11246 child_origin_die
= child_die
;
11247 child_origin_cu
= cu
;
11250 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
11254 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
11258 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
11259 counterpart may exist. */
11260 if (child_origin_die
!= child_die
)
11262 if (child_die
->tag
!= child_origin_die
->tag
11263 && !(child_die
->tag
== DW_TAG_inlined_subroutine
11264 && child_origin_die
->tag
== DW_TAG_subprogram
))
11265 complaint (&symfile_complaints
,
11266 _("Child DIE 0x%x and its abstract origin 0x%x have "
11267 "different tags"), child_die
->offset
.sect_off
,
11268 child_origin_die
->offset
.sect_off
);
11269 if (child_origin_die
->parent
!= origin_die
)
11270 complaint (&symfile_complaints
,
11271 _("Child DIE 0x%x and its abstract origin 0x%x have "
11272 "different parents"), child_die
->offset
.sect_off
,
11273 child_origin_die
->offset
.sect_off
);
11275 *offsets_end
++ = child_origin_die
->offset
;
11278 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
11279 unsigned_int_compar
);
11280 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
11281 if (offsetp
[-1].sect_off
== offsetp
->sect_off
)
11282 complaint (&symfile_complaints
,
11283 _("Multiple children of DIE 0x%x refer "
11284 "to DIE 0x%x as their abstract origin"),
11285 die
->offset
.sect_off
, offsetp
->sect_off
);
11288 origin_child_die
= origin_die
->child
;
11289 while (origin_child_die
&& origin_child_die
->tag
)
11291 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
11292 while (offsetp
< offsets_end
11293 && offsetp
->sect_off
< origin_child_die
->offset
.sect_off
)
11295 if (offsetp
>= offsets_end
11296 || offsetp
->sect_off
> origin_child_die
->offset
.sect_off
)
11298 /* Found that ORIGIN_CHILD_DIE is really not referenced.
11299 Check whether we're already processing ORIGIN_CHILD_DIE.
11300 This can happen with mutually referenced abstract_origins.
11302 if (!origin_child_die
->in_process
)
11303 process_die (origin_child_die
, origin_cu
);
11305 origin_child_die
= sibling_die (origin_child_die
);
11307 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
11309 do_cleanups (cleanups
);
11313 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11315 struct objfile
*objfile
= cu
->objfile
;
11316 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11317 struct context_stack
*newobj
;
11320 struct die_info
*child_die
;
11321 struct attribute
*attr
, *call_line
, *call_file
;
11323 CORE_ADDR baseaddr
;
11324 struct block
*block
;
11325 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
11326 VEC (symbolp
) *template_args
= NULL
;
11327 struct template_symbol
*templ_func
= NULL
;
11331 /* If we do not have call site information, we can't show the
11332 caller of this inlined function. That's too confusing, so
11333 only use the scope for local variables. */
11334 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
11335 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
11336 if (call_line
== NULL
|| call_file
== NULL
)
11338 read_lexical_block_scope (die
, cu
);
11343 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11345 name
= dwarf2_name (die
, cu
);
11347 /* Ignore functions with missing or empty names. These are actually
11348 illegal according to the DWARF standard. */
11351 complaint (&symfile_complaints
,
11352 _("missing name for subprogram DIE at %d"),
11353 die
->offset
.sect_off
);
11357 /* Ignore functions with missing or invalid low and high pc attributes. */
11358 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
11360 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
11361 if (!attr
|| !DW_UNSND (attr
))
11362 complaint (&symfile_complaints
,
11363 _("cannot get low and high bounds "
11364 "for subprogram DIE at %d"),
11365 die
->offset
.sect_off
);
11369 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11370 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
11372 /* If we have any template arguments, then we must allocate a
11373 different sort of symbol. */
11374 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
11376 if (child_die
->tag
== DW_TAG_template_type_param
11377 || child_die
->tag
== DW_TAG_template_value_param
)
11379 templ_func
= allocate_template_symbol (objfile
);
11380 templ_func
->base
.is_cplus_template_function
= 1;
11385 newobj
= push_context (0, lowpc
);
11386 newobj
->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
11387 (struct symbol
*) templ_func
);
11389 /* If there is a location expression for DW_AT_frame_base, record
11391 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
11393 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
11395 cu
->list_in_scope
= &local_symbols
;
11397 if (die
->child
!= NULL
)
11399 child_die
= die
->child
;
11400 while (child_die
&& child_die
->tag
)
11402 if (child_die
->tag
== DW_TAG_template_type_param
11403 || child_die
->tag
== DW_TAG_template_value_param
)
11405 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
11408 VEC_safe_push (symbolp
, template_args
, arg
);
11411 process_die (child_die
, cu
);
11412 child_die
= sibling_die (child_die
);
11416 inherit_abstract_dies (die
, cu
);
11418 /* If we have a DW_AT_specification, we might need to import using
11419 directives from the context of the specification DIE. See the
11420 comment in determine_prefix. */
11421 if (cu
->language
== language_cplus
11422 && dwarf2_attr (die
, DW_AT_specification
, cu
))
11424 struct dwarf2_cu
*spec_cu
= cu
;
11425 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
11429 child_die
= spec_die
->child
;
11430 while (child_die
&& child_die
->tag
)
11432 if (child_die
->tag
== DW_TAG_imported_module
)
11433 process_die (child_die
, spec_cu
);
11434 child_die
= sibling_die (child_die
);
11437 /* In some cases, GCC generates specification DIEs that
11438 themselves contain DW_AT_specification attributes. */
11439 spec_die
= die_specification (spec_die
, &spec_cu
);
11443 newobj
= pop_context ();
11444 /* Make a block for the local symbols within. */
11445 block
= finish_block (newobj
->name
, &local_symbols
, newobj
->old_blocks
,
11448 /* For C++, set the block's scope. */
11449 if ((cu
->language
== language_cplus
11450 || cu
->language
== language_fortran
11451 || cu
->language
== language_d
)
11452 && cu
->processing_has_namespace_info
)
11453 block_set_scope (block
, determine_prefix (die
, cu
),
11454 &objfile
->objfile_obstack
);
11456 /* If we have address ranges, record them. */
11457 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
11459 gdbarch_make_symbol_special (gdbarch
, newobj
->name
, objfile
);
11461 /* Attach template arguments to function. */
11462 if (! VEC_empty (symbolp
, template_args
))
11464 gdb_assert (templ_func
!= NULL
);
11466 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
11467 templ_func
->template_arguments
11468 = obstack_alloc (&objfile
->objfile_obstack
,
11469 (templ_func
->n_template_arguments
11470 * sizeof (struct symbol
*)));
11471 memcpy (templ_func
->template_arguments
,
11472 VEC_address (symbolp
, template_args
),
11473 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
11474 VEC_free (symbolp
, template_args
);
11477 /* In C++, we can have functions nested inside functions (e.g., when
11478 a function declares a class that has methods). This means that
11479 when we finish processing a function scope, we may need to go
11480 back to building a containing block's symbol lists. */
11481 local_symbols
= newobj
->locals
;
11482 local_using_directives
= newobj
->local_using_directives
;
11484 /* If we've finished processing a top-level function, subsequent
11485 symbols go in the file symbol list. */
11486 if (outermost_context_p ())
11487 cu
->list_in_scope
= &file_symbols
;
11490 /* Process all the DIES contained within a lexical block scope. Start
11491 a new scope, process the dies, and then close the scope. */
11494 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11496 struct objfile
*objfile
= cu
->objfile
;
11497 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11498 struct context_stack
*newobj
;
11499 CORE_ADDR lowpc
, highpc
;
11500 struct die_info
*child_die
;
11501 CORE_ADDR baseaddr
;
11503 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11505 /* Ignore blocks with missing or invalid low and high pc attributes. */
11506 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
11507 as multiple lexical blocks? Handling children in a sane way would
11508 be nasty. Might be easier to properly extend generic blocks to
11509 describe ranges. */
11510 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
11512 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11513 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
11515 push_context (0, lowpc
);
11516 if (die
->child
!= NULL
)
11518 child_die
= die
->child
;
11519 while (child_die
&& child_die
->tag
)
11521 process_die (child_die
, cu
);
11522 child_die
= sibling_die (child_die
);
11525 inherit_abstract_dies (die
, cu
);
11526 newobj
= pop_context ();
11528 if (local_symbols
!= NULL
|| local_using_directives
!= NULL
)
11530 struct block
*block
11531 = finish_block (0, &local_symbols
, newobj
->old_blocks
,
11532 newobj
->start_addr
, highpc
);
11534 /* Note that recording ranges after traversing children, as we
11535 do here, means that recording a parent's ranges entails
11536 walking across all its children's ranges as they appear in
11537 the address map, which is quadratic behavior.
11539 It would be nicer to record the parent's ranges before
11540 traversing its children, simply overriding whatever you find
11541 there. But since we don't even decide whether to create a
11542 block until after we've traversed its children, that's hard
11544 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
11546 local_symbols
= newobj
->locals
;
11547 local_using_directives
= newobj
->local_using_directives
;
11550 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
11553 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11555 struct objfile
*objfile
= cu
->objfile
;
11556 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11557 CORE_ADDR pc
, baseaddr
;
11558 struct attribute
*attr
;
11559 struct call_site
*call_site
, call_site_local
;
11562 struct die_info
*child_die
;
11564 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11566 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11569 complaint (&symfile_complaints
,
11570 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
11571 "DIE 0x%x [in module %s]"),
11572 die
->offset
.sect_off
, objfile_name (objfile
));
11575 pc
= attr_value_as_address (attr
) + baseaddr
;
11576 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
11578 if (cu
->call_site_htab
== NULL
)
11579 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
11580 NULL
, &objfile
->objfile_obstack
,
11581 hashtab_obstack_allocate
, NULL
);
11582 call_site_local
.pc
= pc
;
11583 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
11586 complaint (&symfile_complaints
,
11587 _("Duplicate PC %s for DW_TAG_GNU_call_site "
11588 "DIE 0x%x [in module %s]"),
11589 paddress (gdbarch
, pc
), die
->offset
.sect_off
,
11590 objfile_name (objfile
));
11594 /* Count parameters at the caller. */
11597 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11598 child_die
= sibling_die (child_die
))
11600 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
11602 complaint (&symfile_complaints
,
11603 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
11604 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
11605 child_die
->tag
, child_die
->offset
.sect_off
,
11606 objfile_name (objfile
));
11613 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
11614 (sizeof (*call_site
)
11615 + (sizeof (*call_site
->parameter
)
11616 * (nparams
- 1))));
11618 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
11619 call_site
->pc
= pc
;
11621 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
11623 struct die_info
*func_die
;
11625 /* Skip also over DW_TAG_inlined_subroutine. */
11626 for (func_die
= die
->parent
;
11627 func_die
&& func_die
->tag
!= DW_TAG_subprogram
11628 && func_die
->tag
!= DW_TAG_subroutine_type
;
11629 func_die
= func_die
->parent
);
11631 /* DW_AT_GNU_all_call_sites is a superset
11632 of DW_AT_GNU_all_tail_call_sites. */
11634 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
11635 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
11637 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
11638 not complete. But keep CALL_SITE for look ups via call_site_htab,
11639 both the initial caller containing the real return address PC and
11640 the final callee containing the current PC of a chain of tail
11641 calls do not need to have the tail call list complete. But any
11642 function candidate for a virtual tail call frame searched via
11643 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
11644 determined unambiguously. */
11648 struct type
*func_type
= NULL
;
11651 func_type
= get_die_type (func_die
, cu
);
11652 if (func_type
!= NULL
)
11654 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
11656 /* Enlist this call site to the function. */
11657 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
11658 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
11661 complaint (&symfile_complaints
,
11662 _("Cannot find function owning DW_TAG_GNU_call_site "
11663 "DIE 0x%x [in module %s]"),
11664 die
->offset
.sect_off
, objfile_name (objfile
));
11668 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
11670 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
11671 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
11672 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
11673 /* Keep NULL DWARF_BLOCK. */;
11674 else if (attr_form_is_block (attr
))
11676 struct dwarf2_locexpr_baton
*dlbaton
;
11678 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
11679 dlbaton
->data
= DW_BLOCK (attr
)->data
;
11680 dlbaton
->size
= DW_BLOCK (attr
)->size
;
11681 dlbaton
->per_cu
= cu
->per_cu
;
11683 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
11685 else if (attr_form_is_ref (attr
))
11687 struct dwarf2_cu
*target_cu
= cu
;
11688 struct die_info
*target_die
;
11690 target_die
= follow_die_ref (die
, attr
, &target_cu
);
11691 gdb_assert (target_cu
->objfile
== objfile
);
11692 if (die_is_declaration (target_die
, target_cu
))
11694 const char *target_physname
;
11696 /* Prefer the mangled name; otherwise compute the demangled one. */
11697 target_physname
= dwarf2_string_attr (target_die
,
11698 DW_AT_linkage_name
,
11700 if (target_physname
== NULL
)
11701 target_physname
= dwarf2_string_attr (target_die
,
11702 DW_AT_MIPS_linkage_name
,
11704 if (target_physname
== NULL
)
11705 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
11706 if (target_physname
== NULL
)
11707 complaint (&symfile_complaints
,
11708 _("DW_AT_GNU_call_site_target target DIE has invalid "
11709 "physname, for referencing DIE 0x%x [in module %s]"),
11710 die
->offset
.sect_off
, objfile_name (objfile
));
11712 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
11718 /* DW_AT_entry_pc should be preferred. */
11719 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
11720 complaint (&symfile_complaints
,
11721 _("DW_AT_GNU_call_site_target target DIE has invalid "
11722 "low pc, for referencing DIE 0x%x [in module %s]"),
11723 die
->offset
.sect_off
, objfile_name (objfile
));
11726 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11727 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
11732 complaint (&symfile_complaints
,
11733 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
11734 "block nor reference, for DIE 0x%x [in module %s]"),
11735 die
->offset
.sect_off
, objfile_name (objfile
));
11737 call_site
->per_cu
= cu
->per_cu
;
11739 for (child_die
= die
->child
;
11740 child_die
&& child_die
->tag
;
11741 child_die
= sibling_die (child_die
))
11743 struct call_site_parameter
*parameter
;
11744 struct attribute
*loc
, *origin
;
11746 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
11748 /* Already printed the complaint above. */
11752 gdb_assert (call_site
->parameter_count
< nparams
);
11753 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
11755 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
11756 specifies DW_TAG_formal_parameter. Value of the data assumed for the
11757 register is contained in DW_AT_GNU_call_site_value. */
11759 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
11760 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
11761 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
11763 sect_offset offset
;
11765 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
11766 offset
= dwarf2_get_ref_die_offset (origin
);
11767 if (!offset_in_cu_p (&cu
->header
, offset
))
11769 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
11770 binding can be done only inside one CU. Such referenced DIE
11771 therefore cannot be even moved to DW_TAG_partial_unit. */
11772 complaint (&symfile_complaints
,
11773 _("DW_AT_abstract_origin offset is not in CU for "
11774 "DW_TAG_GNU_call_site child DIE 0x%x "
11776 child_die
->offset
.sect_off
, objfile_name (objfile
));
11779 parameter
->u
.param_offset
.cu_off
= (offset
.sect_off
11780 - cu
->header
.offset
.sect_off
);
11782 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
11784 complaint (&symfile_complaints
,
11785 _("No DW_FORM_block* DW_AT_location for "
11786 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
11787 child_die
->offset
.sect_off
, objfile_name (objfile
));
11792 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
11793 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
11794 if (parameter
->u
.dwarf_reg
!= -1)
11795 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
11796 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
11797 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
11798 ¶meter
->u
.fb_offset
))
11799 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
11802 complaint (&symfile_complaints
,
11803 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
11804 "for DW_FORM_block* DW_AT_location is supported for "
11805 "DW_TAG_GNU_call_site child DIE 0x%x "
11807 child_die
->offset
.sect_off
, objfile_name (objfile
));
11812 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
11813 if (!attr_form_is_block (attr
))
11815 complaint (&symfile_complaints
,
11816 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
11817 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
11818 child_die
->offset
.sect_off
, objfile_name (objfile
));
11821 parameter
->value
= DW_BLOCK (attr
)->data
;
11822 parameter
->value_size
= DW_BLOCK (attr
)->size
;
11824 /* Parameters are not pre-cleared by memset above. */
11825 parameter
->data_value
= NULL
;
11826 parameter
->data_value_size
= 0;
11827 call_site
->parameter_count
++;
11829 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
11832 if (!attr_form_is_block (attr
))
11833 complaint (&symfile_complaints
,
11834 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
11835 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
11836 child_die
->offset
.sect_off
, objfile_name (objfile
));
11839 parameter
->data_value
= DW_BLOCK (attr
)->data
;
11840 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
11846 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
11847 Return 1 if the attributes are present and valid, otherwise, return 0.
11848 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
11851 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
11852 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
11853 struct partial_symtab
*ranges_pst
)
11855 struct objfile
*objfile
= cu
->objfile
;
11856 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11857 struct comp_unit_head
*cu_header
= &cu
->header
;
11858 bfd
*obfd
= objfile
->obfd
;
11859 unsigned int addr_size
= cu_header
->addr_size
;
11860 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
11861 /* Base address selection entry. */
11864 unsigned int dummy
;
11865 const gdb_byte
*buffer
;
11869 CORE_ADDR high
= 0;
11870 CORE_ADDR baseaddr
;
11872 found_base
= cu
->base_known
;
11873 base
= cu
->base_address
;
11875 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
11876 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
11878 complaint (&symfile_complaints
,
11879 _("Offset %d out of bounds for DW_AT_ranges attribute"),
11883 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
11885 /* Read in the largest possible address. */
11886 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
11887 if ((marker
& mask
) == mask
)
11889 /* If we found the largest possible address, then
11890 read the base address. */
11891 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
11892 buffer
+= 2 * addr_size
;
11893 offset
+= 2 * addr_size
;
11899 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11903 CORE_ADDR range_beginning
, range_end
;
11905 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
11906 buffer
+= addr_size
;
11907 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
11908 buffer
+= addr_size
;
11909 offset
+= 2 * addr_size
;
11911 /* An end of list marker is a pair of zero addresses. */
11912 if (range_beginning
== 0 && range_end
== 0)
11913 /* Found the end of list entry. */
11916 /* Each base address selection entry is a pair of 2 values.
11917 The first is the largest possible address, the second is
11918 the base address. Check for a base address here. */
11919 if ((range_beginning
& mask
) == mask
)
11921 /* If we found the largest possible address, then
11922 read the base address. */
11923 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
11930 /* We have no valid base address for the ranges
11932 complaint (&symfile_complaints
,
11933 _("Invalid .debug_ranges data (no base address)"));
11937 if (range_beginning
> range_end
)
11939 /* Inverted range entries are invalid. */
11940 complaint (&symfile_complaints
,
11941 _("Invalid .debug_ranges data (inverted range)"));
11945 /* Empty range entries have no effect. */
11946 if (range_beginning
== range_end
)
11949 range_beginning
+= base
;
11952 /* A not-uncommon case of bad debug info.
11953 Don't pollute the addrmap with bad data. */
11954 if (range_beginning
+ baseaddr
== 0
11955 && !dwarf2_per_objfile
->has_section_at_zero
)
11957 complaint (&symfile_complaints
,
11958 _(".debug_ranges entry has start address of zero"
11959 " [in module %s]"), objfile_name (objfile
));
11963 if (ranges_pst
!= NULL
)
11968 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
11969 range_beginning
+ baseaddr
);
11970 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
11971 range_end
+ baseaddr
);
11972 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
11976 /* FIXME: This is recording everything as a low-high
11977 segment of consecutive addresses. We should have a
11978 data structure for discontiguous block ranges
11982 low
= range_beginning
;
11988 if (range_beginning
< low
)
11989 low
= range_beginning
;
11990 if (range_end
> high
)
11996 /* If the first entry is an end-of-list marker, the range
11997 describes an empty scope, i.e. no instructions. */
12003 *high_return
= high
;
12007 /* Get low and high pc attributes from a die. Return 1 if the attributes
12008 are present and valid, otherwise, return 0. Return -1 if the range is
12009 discontinuous, i.e. derived from DW_AT_ranges information. */
12012 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
12013 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
12014 struct partial_symtab
*pst
)
12016 struct attribute
*attr
;
12017 struct attribute
*attr_high
;
12019 CORE_ADDR high
= 0;
12022 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
12025 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
12028 low
= attr_value_as_address (attr
);
12029 high
= attr_value_as_address (attr_high
);
12030 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
12034 /* Found high w/o low attribute. */
12037 /* Found consecutive range of addresses. */
12042 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
12045 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
12046 We take advantage of the fact that DW_AT_ranges does not appear
12047 in DW_TAG_compile_unit of DWO files. */
12048 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
12049 unsigned int ranges_offset
= (DW_UNSND (attr
)
12050 + (need_ranges_base
12054 /* Value of the DW_AT_ranges attribute is the offset in the
12055 .debug_ranges section. */
12056 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
12058 /* Found discontinuous range of addresses. */
12063 /* read_partial_die has also the strict LOW < HIGH requirement. */
12067 /* When using the GNU linker, .gnu.linkonce. sections are used to
12068 eliminate duplicate copies of functions and vtables and such.
12069 The linker will arbitrarily choose one and discard the others.
12070 The AT_*_pc values for such functions refer to local labels in
12071 these sections. If the section from that file was discarded, the
12072 labels are not in the output, so the relocs get a value of 0.
12073 If this is a discarded function, mark the pc bounds as invalid,
12074 so that GDB will ignore it. */
12075 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
12084 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
12085 its low and high PC addresses. Do nothing if these addresses could not
12086 be determined. Otherwise, set LOWPC to the low address if it is smaller,
12087 and HIGHPC to the high address if greater than HIGHPC. */
12090 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
12091 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
12092 struct dwarf2_cu
*cu
)
12094 CORE_ADDR low
, high
;
12095 struct die_info
*child
= die
->child
;
12097 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
12099 *lowpc
= min (*lowpc
, low
);
12100 *highpc
= max (*highpc
, high
);
12103 /* If the language does not allow nested subprograms (either inside
12104 subprograms or lexical blocks), we're done. */
12105 if (cu
->language
!= language_ada
)
12108 /* Check all the children of the given DIE. If it contains nested
12109 subprograms, then check their pc bounds. Likewise, we need to
12110 check lexical blocks as well, as they may also contain subprogram
12112 while (child
&& child
->tag
)
12114 if (child
->tag
== DW_TAG_subprogram
12115 || child
->tag
== DW_TAG_lexical_block
)
12116 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
12117 child
= sibling_die (child
);
12121 /* Get the low and high pc's represented by the scope DIE, and store
12122 them in *LOWPC and *HIGHPC. If the correct values can't be
12123 determined, set *LOWPC to -1 and *HIGHPC to 0. */
12126 get_scope_pc_bounds (struct die_info
*die
,
12127 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
12128 struct dwarf2_cu
*cu
)
12130 CORE_ADDR best_low
= (CORE_ADDR
) -1;
12131 CORE_ADDR best_high
= (CORE_ADDR
) 0;
12132 CORE_ADDR current_low
, current_high
;
12134 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
12136 best_low
= current_low
;
12137 best_high
= current_high
;
12141 struct die_info
*child
= die
->child
;
12143 while (child
&& child
->tag
)
12145 switch (child
->tag
) {
12146 case DW_TAG_subprogram
:
12147 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
12149 case DW_TAG_namespace
:
12150 case DW_TAG_module
:
12151 /* FIXME: carlton/2004-01-16: Should we do this for
12152 DW_TAG_class_type/DW_TAG_structure_type, too? I think
12153 that current GCC's always emit the DIEs corresponding
12154 to definitions of methods of classes as children of a
12155 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
12156 the DIEs giving the declarations, which could be
12157 anywhere). But I don't see any reason why the
12158 standards says that they have to be there. */
12159 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
12161 if (current_low
!= ((CORE_ADDR
) -1))
12163 best_low
= min (best_low
, current_low
);
12164 best_high
= max (best_high
, current_high
);
12172 child
= sibling_die (child
);
12177 *highpc
= best_high
;
12180 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
12184 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
12185 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
12187 struct objfile
*objfile
= cu
->objfile
;
12188 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12189 struct attribute
*attr
;
12190 struct attribute
*attr_high
;
12192 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
12195 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
12198 CORE_ADDR low
= attr_value_as_address (attr
);
12199 CORE_ADDR high
= attr_value_as_address (attr_high
);
12201 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
12204 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
12205 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
12206 record_block_range (block
, low
, high
- 1);
12210 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
12213 bfd
*obfd
= objfile
->obfd
;
12214 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
12215 We take advantage of the fact that DW_AT_ranges does not appear
12216 in DW_TAG_compile_unit of DWO files. */
12217 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
12219 /* The value of the DW_AT_ranges attribute is the offset of the
12220 address range list in the .debug_ranges section. */
12221 unsigned long offset
= (DW_UNSND (attr
)
12222 + (need_ranges_base
? cu
->ranges_base
: 0));
12223 const gdb_byte
*buffer
;
12225 /* For some target architectures, but not others, the
12226 read_address function sign-extends the addresses it returns.
12227 To recognize base address selection entries, we need a
12229 unsigned int addr_size
= cu
->header
.addr_size
;
12230 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
12232 /* The base address, to which the next pair is relative. Note
12233 that this 'base' is a DWARF concept: most entries in a range
12234 list are relative, to reduce the number of relocs against the
12235 debugging information. This is separate from this function's
12236 'baseaddr' argument, which GDB uses to relocate debugging
12237 information from a shared library based on the address at
12238 which the library was loaded. */
12239 CORE_ADDR base
= cu
->base_address
;
12240 int base_known
= cu
->base_known
;
12242 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
12243 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
12245 complaint (&symfile_complaints
,
12246 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
12250 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
12254 unsigned int bytes_read
;
12255 CORE_ADDR start
, end
;
12257 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
12258 buffer
+= bytes_read
;
12259 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
12260 buffer
+= bytes_read
;
12262 /* Did we find the end of the range list? */
12263 if (start
== 0 && end
== 0)
12266 /* Did we find a base address selection entry? */
12267 else if ((start
& base_select_mask
) == base_select_mask
)
12273 /* We found an ordinary address range. */
12278 complaint (&symfile_complaints
,
12279 _("Invalid .debug_ranges data "
12280 "(no base address)"));
12286 /* Inverted range entries are invalid. */
12287 complaint (&symfile_complaints
,
12288 _("Invalid .debug_ranges data "
12289 "(inverted range)"));
12293 /* Empty range entries have no effect. */
12297 start
+= base
+ baseaddr
;
12298 end
+= base
+ baseaddr
;
12300 /* A not-uncommon case of bad debug info.
12301 Don't pollute the addrmap with bad data. */
12302 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
12304 complaint (&symfile_complaints
,
12305 _(".debug_ranges entry has start address of zero"
12306 " [in module %s]"), objfile_name (objfile
));
12310 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
12311 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
12312 record_block_range (block
, start
, end
- 1);
12318 /* Check whether the producer field indicates either of GCC < 4.6, or the
12319 Intel C/C++ compiler, and cache the result in CU. */
12322 check_producer (struct dwarf2_cu
*cu
)
12327 if (cu
->producer
== NULL
)
12329 /* For unknown compilers expect their behavior is DWARF version
12332 GCC started to support .debug_types sections by -gdwarf-4 since
12333 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
12334 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
12335 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
12336 interpreted incorrectly by GDB now - GCC PR debug/48229. */
12338 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
12340 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
12341 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
12343 else if (startswith (cu
->producer
, "Intel(R) C"))
12344 cu
->producer_is_icc
= 1;
12347 /* For other non-GCC compilers, expect their behavior is DWARF version
12351 cu
->checked_producer
= 1;
12354 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
12355 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
12356 during 4.6.0 experimental. */
12359 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
12361 if (!cu
->checked_producer
)
12362 check_producer (cu
);
12364 return cu
->producer_is_gxx_lt_4_6
;
12367 /* Return the default accessibility type if it is not overriden by
12368 DW_AT_accessibility. */
12370 static enum dwarf_access_attribute
12371 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
12373 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
12375 /* The default DWARF 2 accessibility for members is public, the default
12376 accessibility for inheritance is private. */
12378 if (die
->tag
!= DW_TAG_inheritance
)
12379 return DW_ACCESS_public
;
12381 return DW_ACCESS_private
;
12385 /* DWARF 3+ defines the default accessibility a different way. The same
12386 rules apply now for DW_TAG_inheritance as for the members and it only
12387 depends on the container kind. */
12389 if (die
->parent
->tag
== DW_TAG_class_type
)
12390 return DW_ACCESS_private
;
12392 return DW_ACCESS_public
;
12396 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
12397 offset. If the attribute was not found return 0, otherwise return
12398 1. If it was found but could not properly be handled, set *OFFSET
12402 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
12405 struct attribute
*attr
;
12407 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
12412 /* Note that we do not check for a section offset first here.
12413 This is because DW_AT_data_member_location is new in DWARF 4,
12414 so if we see it, we can assume that a constant form is really
12415 a constant and not a section offset. */
12416 if (attr_form_is_constant (attr
))
12417 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
12418 else if (attr_form_is_section_offset (attr
))
12419 dwarf2_complex_location_expr_complaint ();
12420 else if (attr_form_is_block (attr
))
12421 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
12423 dwarf2_complex_location_expr_complaint ();
12431 /* Add an aggregate field to the field list. */
12434 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
12435 struct dwarf2_cu
*cu
)
12437 struct objfile
*objfile
= cu
->objfile
;
12438 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12439 struct nextfield
*new_field
;
12440 struct attribute
*attr
;
12442 const char *fieldname
= "";
12444 /* Allocate a new field list entry and link it in. */
12445 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
12446 make_cleanup (xfree
, new_field
);
12447 memset (new_field
, 0, sizeof (struct nextfield
));
12449 if (die
->tag
== DW_TAG_inheritance
)
12451 new_field
->next
= fip
->baseclasses
;
12452 fip
->baseclasses
= new_field
;
12456 new_field
->next
= fip
->fields
;
12457 fip
->fields
= new_field
;
12461 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
12463 new_field
->accessibility
= DW_UNSND (attr
);
12465 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
12466 if (new_field
->accessibility
!= DW_ACCESS_public
)
12467 fip
->non_public_fields
= 1;
12469 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
12471 new_field
->virtuality
= DW_UNSND (attr
);
12473 new_field
->virtuality
= DW_VIRTUALITY_none
;
12475 fp
= &new_field
->field
;
12477 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
12481 /* Data member other than a C++ static data member. */
12483 /* Get type of field. */
12484 fp
->type
= die_type (die
, cu
);
12486 SET_FIELD_BITPOS (*fp
, 0);
12488 /* Get bit size of field (zero if none). */
12489 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
12492 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
12496 FIELD_BITSIZE (*fp
) = 0;
12499 /* Get bit offset of field. */
12500 if (handle_data_member_location (die
, cu
, &offset
))
12501 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
12502 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
12505 if (gdbarch_bits_big_endian (gdbarch
))
12507 /* For big endian bits, the DW_AT_bit_offset gives the
12508 additional bit offset from the MSB of the containing
12509 anonymous object to the MSB of the field. We don't
12510 have to do anything special since we don't need to
12511 know the size of the anonymous object. */
12512 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
12516 /* For little endian bits, compute the bit offset to the
12517 MSB of the anonymous object, subtract off the number of
12518 bits from the MSB of the field to the MSB of the
12519 object, and then subtract off the number of bits of
12520 the field itself. The result is the bit offset of
12521 the LSB of the field. */
12522 int anonymous_size
;
12523 int bit_offset
= DW_UNSND (attr
);
12525 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12528 /* The size of the anonymous object containing
12529 the bit field is explicit, so use the
12530 indicated size (in bytes). */
12531 anonymous_size
= DW_UNSND (attr
);
12535 /* The size of the anonymous object containing
12536 the bit field must be inferred from the type
12537 attribute of the data member containing the
12539 anonymous_size
= TYPE_LENGTH (fp
->type
);
12541 SET_FIELD_BITPOS (*fp
,
12542 (FIELD_BITPOS (*fp
)
12543 + anonymous_size
* bits_per_byte
12544 - bit_offset
- FIELD_BITSIZE (*fp
)));
12548 /* Get name of field. */
12549 fieldname
= dwarf2_name (die
, cu
);
12550 if (fieldname
== NULL
)
12553 /* The name is already allocated along with this objfile, so we don't
12554 need to duplicate it for the type. */
12555 fp
->name
= fieldname
;
12557 /* Change accessibility for artificial fields (e.g. virtual table
12558 pointer or virtual base class pointer) to private. */
12559 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
12561 FIELD_ARTIFICIAL (*fp
) = 1;
12562 new_field
->accessibility
= DW_ACCESS_private
;
12563 fip
->non_public_fields
= 1;
12566 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
12568 /* C++ static member. */
12570 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
12571 is a declaration, but all versions of G++ as of this writing
12572 (so through at least 3.2.1) incorrectly generate
12573 DW_TAG_variable tags. */
12575 const char *physname
;
12577 /* Get name of field. */
12578 fieldname
= dwarf2_name (die
, cu
);
12579 if (fieldname
== NULL
)
12582 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
12584 /* Only create a symbol if this is an external value.
12585 new_symbol checks this and puts the value in the global symbol
12586 table, which we want. If it is not external, new_symbol
12587 will try to put the value in cu->list_in_scope which is wrong. */
12588 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
12590 /* A static const member, not much different than an enum as far as
12591 we're concerned, except that we can support more types. */
12592 new_symbol (die
, NULL
, cu
);
12595 /* Get physical name. */
12596 physname
= dwarf2_physname (fieldname
, die
, cu
);
12598 /* The name is already allocated along with this objfile, so we don't
12599 need to duplicate it for the type. */
12600 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
12601 FIELD_TYPE (*fp
) = die_type (die
, cu
);
12602 FIELD_NAME (*fp
) = fieldname
;
12604 else if (die
->tag
== DW_TAG_inheritance
)
12608 /* C++ base class field. */
12609 if (handle_data_member_location (die
, cu
, &offset
))
12610 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
12611 FIELD_BITSIZE (*fp
) = 0;
12612 FIELD_TYPE (*fp
) = die_type (die
, cu
);
12613 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
12614 fip
->nbaseclasses
++;
12618 /* Add a typedef defined in the scope of the FIP's class. */
12621 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
12622 struct dwarf2_cu
*cu
)
12624 struct objfile
*objfile
= cu
->objfile
;
12625 struct typedef_field_list
*new_field
;
12626 struct attribute
*attr
;
12627 struct typedef_field
*fp
;
12628 char *fieldname
= "";
12630 /* Allocate a new field list entry and link it in. */
12631 new_field
= xzalloc (sizeof (*new_field
));
12632 make_cleanup (xfree
, new_field
);
12634 gdb_assert (die
->tag
== DW_TAG_typedef
);
12636 fp
= &new_field
->field
;
12638 /* Get name of field. */
12639 fp
->name
= dwarf2_name (die
, cu
);
12640 if (fp
->name
== NULL
)
12643 fp
->type
= read_type_die (die
, cu
);
12645 new_field
->next
= fip
->typedef_field_list
;
12646 fip
->typedef_field_list
= new_field
;
12647 fip
->typedef_field_list_count
++;
12650 /* Create the vector of fields, and attach it to the type. */
12653 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
12654 struct dwarf2_cu
*cu
)
12656 int nfields
= fip
->nfields
;
12658 /* Record the field count, allocate space for the array of fields,
12659 and create blank accessibility bitfields if necessary. */
12660 TYPE_NFIELDS (type
) = nfields
;
12661 TYPE_FIELDS (type
) = (struct field
*)
12662 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
12663 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
12665 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
12667 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
12669 TYPE_FIELD_PRIVATE_BITS (type
) =
12670 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
12671 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
12673 TYPE_FIELD_PROTECTED_BITS (type
) =
12674 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
12675 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
12677 TYPE_FIELD_IGNORE_BITS (type
) =
12678 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
12679 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
12682 /* If the type has baseclasses, allocate and clear a bit vector for
12683 TYPE_FIELD_VIRTUAL_BITS. */
12684 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
12686 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
12687 unsigned char *pointer
;
12689 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
12690 pointer
= TYPE_ALLOC (type
, num_bytes
);
12691 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
12692 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
12693 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
12696 /* Copy the saved-up fields into the field vector. Start from the head of
12697 the list, adding to the tail of the field array, so that they end up in
12698 the same order in the array in which they were added to the list. */
12699 while (nfields
-- > 0)
12701 struct nextfield
*fieldp
;
12705 fieldp
= fip
->fields
;
12706 fip
->fields
= fieldp
->next
;
12710 fieldp
= fip
->baseclasses
;
12711 fip
->baseclasses
= fieldp
->next
;
12714 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
12715 switch (fieldp
->accessibility
)
12717 case DW_ACCESS_private
:
12718 if (cu
->language
!= language_ada
)
12719 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
12722 case DW_ACCESS_protected
:
12723 if (cu
->language
!= language_ada
)
12724 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
12727 case DW_ACCESS_public
:
12731 /* Unknown accessibility. Complain and treat it as public. */
12733 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
12734 fieldp
->accessibility
);
12738 if (nfields
< fip
->nbaseclasses
)
12740 switch (fieldp
->virtuality
)
12742 case DW_VIRTUALITY_virtual
:
12743 case DW_VIRTUALITY_pure_virtual
:
12744 if (cu
->language
== language_ada
)
12745 error (_("unexpected virtuality in component of Ada type"));
12746 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
12753 /* Return true if this member function is a constructor, false
12757 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
12759 const char *fieldname
;
12760 const char *type_name
;
12763 if (die
->parent
== NULL
)
12766 if (die
->parent
->tag
!= DW_TAG_structure_type
12767 && die
->parent
->tag
!= DW_TAG_union_type
12768 && die
->parent
->tag
!= DW_TAG_class_type
)
12771 fieldname
= dwarf2_name (die
, cu
);
12772 type_name
= dwarf2_name (die
->parent
, cu
);
12773 if (fieldname
== NULL
|| type_name
== NULL
)
12776 len
= strlen (fieldname
);
12777 return (strncmp (fieldname
, type_name
, len
) == 0
12778 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
12781 /* Add a member function to the proper fieldlist. */
12784 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
12785 struct type
*type
, struct dwarf2_cu
*cu
)
12787 struct objfile
*objfile
= cu
->objfile
;
12788 struct attribute
*attr
;
12789 struct fnfieldlist
*flp
;
12791 struct fn_field
*fnp
;
12792 const char *fieldname
;
12793 struct nextfnfield
*new_fnfield
;
12794 struct type
*this_type
;
12795 enum dwarf_access_attribute accessibility
;
12797 if (cu
->language
== language_ada
)
12798 error (_("unexpected member function in Ada type"));
12800 /* Get name of member function. */
12801 fieldname
= dwarf2_name (die
, cu
);
12802 if (fieldname
== NULL
)
12805 /* Look up member function name in fieldlist. */
12806 for (i
= 0; i
< fip
->nfnfields
; i
++)
12808 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
12812 /* Create new list element if necessary. */
12813 if (i
< fip
->nfnfields
)
12814 flp
= &fip
->fnfieldlists
[i
];
12817 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
12819 fip
->fnfieldlists
= (struct fnfieldlist
*)
12820 xrealloc (fip
->fnfieldlists
,
12821 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
12822 * sizeof (struct fnfieldlist
));
12823 if (fip
->nfnfields
== 0)
12824 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
12826 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
12827 flp
->name
= fieldname
;
12830 i
= fip
->nfnfields
++;
12833 /* Create a new member function field and chain it to the field list
12835 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
12836 make_cleanup (xfree
, new_fnfield
);
12837 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
12838 new_fnfield
->next
= flp
->head
;
12839 flp
->head
= new_fnfield
;
12842 /* Fill in the member function field info. */
12843 fnp
= &new_fnfield
->fnfield
;
12845 /* Delay processing of the physname until later. */
12846 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
12848 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
12853 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
12854 fnp
->physname
= physname
? physname
: "";
12857 fnp
->type
= alloc_type (objfile
);
12858 this_type
= read_type_die (die
, cu
);
12859 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
12861 int nparams
= TYPE_NFIELDS (this_type
);
12863 /* TYPE is the domain of this method, and THIS_TYPE is the type
12864 of the method itself (TYPE_CODE_METHOD). */
12865 smash_to_method_type (fnp
->type
, type
,
12866 TYPE_TARGET_TYPE (this_type
),
12867 TYPE_FIELDS (this_type
),
12868 TYPE_NFIELDS (this_type
),
12869 TYPE_VARARGS (this_type
));
12871 /* Handle static member functions.
12872 Dwarf2 has no clean way to discern C++ static and non-static
12873 member functions. G++ helps GDB by marking the first
12874 parameter for non-static member functions (which is the this
12875 pointer) as artificial. We obtain this information from
12876 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
12877 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
12878 fnp
->voffset
= VOFFSET_STATIC
;
12881 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
12882 dwarf2_full_name (fieldname
, die
, cu
));
12884 /* Get fcontext from DW_AT_containing_type if present. */
12885 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
12886 fnp
->fcontext
= die_containing_type (die
, cu
);
12888 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
12889 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
12891 /* Get accessibility. */
12892 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
12894 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
12896 accessibility
= dwarf2_default_access_attribute (die
, cu
);
12897 switch (accessibility
)
12899 case DW_ACCESS_private
:
12900 fnp
->is_private
= 1;
12902 case DW_ACCESS_protected
:
12903 fnp
->is_protected
= 1;
12907 /* Check for artificial methods. */
12908 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
12909 if (attr
&& DW_UNSND (attr
) != 0)
12910 fnp
->is_artificial
= 1;
12912 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
12914 /* Get index in virtual function table if it is a virtual member
12915 function. For older versions of GCC, this is an offset in the
12916 appropriate virtual table, as specified by DW_AT_containing_type.
12917 For everyone else, it is an expression to be evaluated relative
12918 to the object address. */
12920 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
12923 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
12925 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
12927 /* Old-style GCC. */
12928 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
12930 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
12931 || (DW_BLOCK (attr
)->size
> 1
12932 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
12933 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
12935 struct dwarf_block blk
;
12938 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
12940 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
12941 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
12942 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
12943 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
12944 dwarf2_complex_location_expr_complaint ();
12946 fnp
->voffset
/= cu
->header
.addr_size
;
12950 dwarf2_complex_location_expr_complaint ();
12952 if (!fnp
->fcontext
)
12954 /* If there is no `this' field and no DW_AT_containing_type,
12955 we cannot actually find a base class context for the
12957 if (TYPE_NFIELDS (this_type
) == 0
12958 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
12960 complaint (&symfile_complaints
,
12961 _("cannot determine context for virtual member "
12962 "function \"%s\" (offset %d)"),
12963 fieldname
, die
->offset
.sect_off
);
12968 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
12972 else if (attr_form_is_section_offset (attr
))
12974 dwarf2_complex_location_expr_complaint ();
12978 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
12984 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
12985 if (attr
&& DW_UNSND (attr
))
12987 /* GCC does this, as of 2008-08-25; PR debug/37237. */
12988 complaint (&symfile_complaints
,
12989 _("Member function \"%s\" (offset %d) is virtual "
12990 "but the vtable offset is not specified"),
12991 fieldname
, die
->offset
.sect_off
);
12992 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
12993 TYPE_CPLUS_DYNAMIC (type
) = 1;
12998 /* Create the vector of member function fields, and attach it to the type. */
13001 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
13002 struct dwarf2_cu
*cu
)
13004 struct fnfieldlist
*flp
;
13007 if (cu
->language
== language_ada
)
13008 error (_("unexpected member functions in Ada type"));
13010 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13011 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
13012 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
13014 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
13016 struct nextfnfield
*nfp
= flp
->head
;
13017 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
13020 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
13021 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
13022 fn_flp
->fn_fields
= (struct fn_field
*)
13023 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
13024 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
13025 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
13028 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
13031 /* Returns non-zero if NAME is the name of a vtable member in CU's
13032 language, zero otherwise. */
13034 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
13036 static const char vptr
[] = "_vptr";
13037 static const char vtable
[] = "vtable";
13039 /* Look for the C++ and Java forms of the vtable. */
13040 if ((cu
->language
== language_java
13041 && startswith (name
, vtable
))
13042 || (startswith (name
, vptr
)
13043 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
13049 /* GCC outputs unnamed structures that are really pointers to member
13050 functions, with the ABI-specified layout. If TYPE describes
13051 such a structure, smash it into a member function type.
13053 GCC shouldn't do this; it should just output pointer to member DIEs.
13054 This is GCC PR debug/28767. */
13057 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
13059 struct type
*pfn_type
, *self_type
, *new_type
;
13061 /* Check for a structure with no name and two children. */
13062 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
13065 /* Check for __pfn and __delta members. */
13066 if (TYPE_FIELD_NAME (type
, 0) == NULL
13067 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
13068 || TYPE_FIELD_NAME (type
, 1) == NULL
13069 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
13072 /* Find the type of the method. */
13073 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
13074 if (pfn_type
== NULL
13075 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
13076 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
13079 /* Look for the "this" argument. */
13080 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
13081 if (TYPE_NFIELDS (pfn_type
) == 0
13082 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
13083 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
13086 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
13087 new_type
= alloc_type (objfile
);
13088 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
13089 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
13090 TYPE_VARARGS (pfn_type
));
13091 smash_to_methodptr_type (type
, new_type
);
13094 /* Return non-zero if the CU's PRODUCER string matches the Intel C/C++ compiler
13098 producer_is_icc (struct dwarf2_cu
*cu
)
13100 if (!cu
->checked_producer
)
13101 check_producer (cu
);
13103 return cu
->producer_is_icc
;
13106 /* Called when we find the DIE that starts a structure or union scope
13107 (definition) to create a type for the structure or union. Fill in
13108 the type's name and general properties; the members will not be
13109 processed until process_structure_scope. A symbol table entry for
13110 the type will also not be done until process_structure_scope (assuming
13111 the type has a name).
13113 NOTE: we need to call these functions regardless of whether or not the
13114 DIE has a DW_AT_name attribute, since it might be an anonymous
13115 structure or union. This gets the type entered into our set of
13116 user defined types. */
13118 static struct type
*
13119 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13121 struct objfile
*objfile
= cu
->objfile
;
13123 struct attribute
*attr
;
13126 /* If the definition of this type lives in .debug_types, read that type.
13127 Don't follow DW_AT_specification though, that will take us back up
13128 the chain and we want to go down. */
13129 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
13132 type
= get_DW_AT_signature_type (die
, attr
, cu
);
13134 /* The type's CU may not be the same as CU.
13135 Ensure TYPE is recorded with CU in die_type_hash. */
13136 return set_die_type (die
, type
, cu
);
13139 type
= alloc_type (objfile
);
13140 INIT_CPLUS_SPECIFIC (type
);
13142 name
= dwarf2_name (die
, cu
);
13145 if (cu
->language
== language_cplus
13146 || cu
->language
== language_java
13147 || cu
->language
== language_d
)
13149 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
13151 /* dwarf2_full_name might have already finished building the DIE's
13152 type. If so, there is no need to continue. */
13153 if (get_die_type (die
, cu
) != NULL
)
13154 return get_die_type (die
, cu
);
13156 TYPE_TAG_NAME (type
) = full_name
;
13157 if (die
->tag
== DW_TAG_structure_type
13158 || die
->tag
== DW_TAG_class_type
)
13159 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
13163 /* The name is already allocated along with this objfile, so
13164 we don't need to duplicate it for the type. */
13165 TYPE_TAG_NAME (type
) = name
;
13166 if (die
->tag
== DW_TAG_class_type
)
13167 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
13171 if (die
->tag
== DW_TAG_structure_type
)
13173 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
13175 else if (die
->tag
== DW_TAG_union_type
)
13177 TYPE_CODE (type
) = TYPE_CODE_UNION
;
13181 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
13184 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
13185 TYPE_DECLARED_CLASS (type
) = 1;
13187 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13190 TYPE_LENGTH (type
) = DW_UNSND (attr
);
13194 TYPE_LENGTH (type
) = 0;
13197 if (producer_is_icc (cu
) && (TYPE_LENGTH (type
) == 0))
13199 /* ICC does not output the required DW_AT_declaration
13200 on incomplete types, but gives them a size of zero. */
13201 TYPE_STUB (type
) = 1;
13204 TYPE_STUB_SUPPORTED (type
) = 1;
13206 if (die_is_declaration (die
, cu
))
13207 TYPE_STUB (type
) = 1;
13208 else if (attr
== NULL
&& die
->child
== NULL
13209 && producer_is_realview (cu
->producer
))
13210 /* RealView does not output the required DW_AT_declaration
13211 on incomplete types. */
13212 TYPE_STUB (type
) = 1;
13214 /* We need to add the type field to the die immediately so we don't
13215 infinitely recurse when dealing with pointers to the structure
13216 type within the structure itself. */
13217 set_die_type (die
, type
, cu
);
13219 /* set_die_type should be already done. */
13220 set_descriptive_type (type
, die
, cu
);
13225 /* Finish creating a structure or union type, including filling in
13226 its members and creating a symbol for it. */
13229 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13231 struct objfile
*objfile
= cu
->objfile
;
13232 struct die_info
*child_die
;
13235 type
= get_die_type (die
, cu
);
13237 type
= read_structure_type (die
, cu
);
13239 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
13241 struct field_info fi
;
13242 VEC (symbolp
) *template_args
= NULL
;
13243 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
13245 memset (&fi
, 0, sizeof (struct field_info
));
13247 child_die
= die
->child
;
13249 while (child_die
&& child_die
->tag
)
13251 if (child_die
->tag
== DW_TAG_member
13252 || child_die
->tag
== DW_TAG_variable
)
13254 /* NOTE: carlton/2002-11-05: A C++ static data member
13255 should be a DW_TAG_member that is a declaration, but
13256 all versions of G++ as of this writing (so through at
13257 least 3.2.1) incorrectly generate DW_TAG_variable
13258 tags for them instead. */
13259 dwarf2_add_field (&fi
, child_die
, cu
);
13261 else if (child_die
->tag
== DW_TAG_subprogram
)
13263 /* C++ member function. */
13264 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
13266 else if (child_die
->tag
== DW_TAG_inheritance
)
13268 /* C++ base class field. */
13269 dwarf2_add_field (&fi
, child_die
, cu
);
13271 else if (child_die
->tag
== DW_TAG_typedef
)
13272 dwarf2_add_typedef (&fi
, child_die
, cu
);
13273 else if (child_die
->tag
== DW_TAG_template_type_param
13274 || child_die
->tag
== DW_TAG_template_value_param
)
13276 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13279 VEC_safe_push (symbolp
, template_args
, arg
);
13282 child_die
= sibling_die (child_die
);
13285 /* Attach template arguments to type. */
13286 if (! VEC_empty (symbolp
, template_args
))
13288 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13289 TYPE_N_TEMPLATE_ARGUMENTS (type
)
13290 = VEC_length (symbolp
, template_args
);
13291 TYPE_TEMPLATE_ARGUMENTS (type
)
13292 = obstack_alloc (&objfile
->objfile_obstack
,
13293 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
13294 * sizeof (struct symbol
*)));
13295 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
13296 VEC_address (symbolp
, template_args
),
13297 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
13298 * sizeof (struct symbol
*)));
13299 VEC_free (symbolp
, template_args
);
13302 /* Attach fields and member functions to the type. */
13304 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
13307 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
13309 /* Get the type which refers to the base class (possibly this
13310 class itself) which contains the vtable pointer for the current
13311 class from the DW_AT_containing_type attribute. This use of
13312 DW_AT_containing_type is a GNU extension. */
13314 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
13316 struct type
*t
= die_containing_type (die
, cu
);
13318 set_type_vptr_basetype (type
, t
);
13323 /* Our own class provides vtbl ptr. */
13324 for (i
= TYPE_NFIELDS (t
) - 1;
13325 i
>= TYPE_N_BASECLASSES (t
);
13328 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
13330 if (is_vtable_name (fieldname
, cu
))
13332 set_type_vptr_fieldno (type
, i
);
13337 /* Complain if virtual function table field not found. */
13338 if (i
< TYPE_N_BASECLASSES (t
))
13339 complaint (&symfile_complaints
,
13340 _("virtual function table pointer "
13341 "not found when defining class '%s'"),
13342 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
13347 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
13350 else if (cu
->producer
13351 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
13353 /* The IBM XLC compiler does not provide direct indication
13354 of the containing type, but the vtable pointer is
13355 always named __vfp. */
13359 for (i
= TYPE_NFIELDS (type
) - 1;
13360 i
>= TYPE_N_BASECLASSES (type
);
13363 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
13365 set_type_vptr_fieldno (type
, i
);
13366 set_type_vptr_basetype (type
, type
);
13373 /* Copy fi.typedef_field_list linked list elements content into the
13374 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
13375 if (fi
.typedef_field_list
)
13377 int i
= fi
.typedef_field_list_count
;
13379 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13380 TYPE_TYPEDEF_FIELD_ARRAY (type
)
13381 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
13382 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
13384 /* Reverse the list order to keep the debug info elements order. */
13387 struct typedef_field
*dest
, *src
;
13389 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
13390 src
= &fi
.typedef_field_list
->field
;
13391 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
13396 do_cleanups (back_to
);
13398 if (HAVE_CPLUS_STRUCT (type
))
13399 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
13402 quirk_gcc_member_function_pointer (type
, objfile
);
13404 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
13405 snapshots) has been known to create a die giving a declaration
13406 for a class that has, as a child, a die giving a definition for a
13407 nested class. So we have to process our children even if the
13408 current die is a declaration. Normally, of course, a declaration
13409 won't have any children at all. */
13411 child_die
= die
->child
;
13413 while (child_die
!= NULL
&& child_die
->tag
)
13415 if (child_die
->tag
== DW_TAG_member
13416 || child_die
->tag
== DW_TAG_variable
13417 || child_die
->tag
== DW_TAG_inheritance
13418 || child_die
->tag
== DW_TAG_template_value_param
13419 || child_die
->tag
== DW_TAG_template_type_param
)
13424 process_die (child_die
, cu
);
13426 child_die
= sibling_die (child_die
);
13429 /* Do not consider external references. According to the DWARF standard,
13430 these DIEs are identified by the fact that they have no byte_size
13431 attribute, and a declaration attribute. */
13432 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
13433 || !die_is_declaration (die
, cu
))
13434 new_symbol (die
, type
, cu
);
13437 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
13438 update TYPE using some information only available in DIE's children. */
13441 update_enumeration_type_from_children (struct die_info
*die
,
13443 struct dwarf2_cu
*cu
)
13445 struct obstack obstack
;
13446 struct die_info
*child_die
;
13447 int unsigned_enum
= 1;
13450 struct cleanup
*old_chain
;
13452 obstack_init (&obstack
);
13453 old_chain
= make_cleanup_obstack_free (&obstack
);
13455 for (child_die
= die
->child
;
13456 child_die
!= NULL
&& child_die
->tag
;
13457 child_die
= sibling_die (child_die
))
13459 struct attribute
*attr
;
13461 const gdb_byte
*bytes
;
13462 struct dwarf2_locexpr_baton
*baton
;
13465 if (child_die
->tag
!= DW_TAG_enumerator
)
13468 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
13472 name
= dwarf2_name (child_die
, cu
);
13474 name
= "<anonymous enumerator>";
13476 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
13477 &value
, &bytes
, &baton
);
13483 else if ((mask
& value
) != 0)
13488 /* If we already know that the enum type is neither unsigned, nor
13489 a flag type, no need to look at the rest of the enumerates. */
13490 if (!unsigned_enum
&& !flag_enum
)
13495 TYPE_UNSIGNED (type
) = 1;
13497 TYPE_FLAG_ENUM (type
) = 1;
13499 do_cleanups (old_chain
);
13502 /* Given a DW_AT_enumeration_type die, set its type. We do not
13503 complete the type's fields yet, or create any symbols. */
13505 static struct type
*
13506 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13508 struct objfile
*objfile
= cu
->objfile
;
13510 struct attribute
*attr
;
13513 /* If the definition of this type lives in .debug_types, read that type.
13514 Don't follow DW_AT_specification though, that will take us back up
13515 the chain and we want to go down. */
13516 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
13519 type
= get_DW_AT_signature_type (die
, attr
, cu
);
13521 /* The type's CU may not be the same as CU.
13522 Ensure TYPE is recorded with CU in die_type_hash. */
13523 return set_die_type (die
, type
, cu
);
13526 type
= alloc_type (objfile
);
13528 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
13529 name
= dwarf2_full_name (NULL
, die
, cu
);
13531 TYPE_TAG_NAME (type
) = name
;
13533 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13536 struct type
*underlying_type
= die_type (die
, cu
);
13538 TYPE_TARGET_TYPE (type
) = underlying_type
;
13541 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13544 TYPE_LENGTH (type
) = DW_UNSND (attr
);
13548 TYPE_LENGTH (type
) = 0;
13551 /* The enumeration DIE can be incomplete. In Ada, any type can be
13552 declared as private in the package spec, and then defined only
13553 inside the package body. Such types are known as Taft Amendment
13554 Types. When another package uses such a type, an incomplete DIE
13555 may be generated by the compiler. */
13556 if (die_is_declaration (die
, cu
))
13557 TYPE_STUB (type
) = 1;
13559 /* Finish the creation of this type by using the enum's children.
13560 We must call this even when the underlying type has been provided
13561 so that we can determine if we're looking at a "flag" enum. */
13562 update_enumeration_type_from_children (die
, type
, cu
);
13564 /* If this type has an underlying type that is not a stub, then we
13565 may use its attributes. We always use the "unsigned" attribute
13566 in this situation, because ordinarily we guess whether the type
13567 is unsigned -- but the guess can be wrong and the underlying type
13568 can tell us the reality. However, we defer to a local size
13569 attribute if one exists, because this lets the compiler override
13570 the underlying type if needed. */
13571 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
13573 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
13574 if (TYPE_LENGTH (type
) == 0)
13575 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
13578 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
13580 return set_die_type (die
, type
, cu
);
13583 /* Given a pointer to a die which begins an enumeration, process all
13584 the dies that define the members of the enumeration, and create the
13585 symbol for the enumeration type.
13587 NOTE: We reverse the order of the element list. */
13590 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13592 struct type
*this_type
;
13594 this_type
= get_die_type (die
, cu
);
13595 if (this_type
== NULL
)
13596 this_type
= read_enumeration_type (die
, cu
);
13598 if (die
->child
!= NULL
)
13600 struct die_info
*child_die
;
13601 struct symbol
*sym
;
13602 struct field
*fields
= NULL
;
13603 int num_fields
= 0;
13606 child_die
= die
->child
;
13607 while (child_die
&& child_die
->tag
)
13609 if (child_die
->tag
!= DW_TAG_enumerator
)
13611 process_die (child_die
, cu
);
13615 name
= dwarf2_name (child_die
, cu
);
13618 sym
= new_symbol (child_die
, this_type
, cu
);
13620 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
13622 fields
= (struct field
*)
13624 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
13625 * sizeof (struct field
));
13628 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
13629 FIELD_TYPE (fields
[num_fields
]) = NULL
;
13630 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
13631 FIELD_BITSIZE (fields
[num_fields
]) = 0;
13637 child_die
= sibling_die (child_die
);
13642 TYPE_NFIELDS (this_type
) = num_fields
;
13643 TYPE_FIELDS (this_type
) = (struct field
*)
13644 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
13645 memcpy (TYPE_FIELDS (this_type
), fields
,
13646 sizeof (struct field
) * num_fields
);
13651 /* If we are reading an enum from a .debug_types unit, and the enum
13652 is a declaration, and the enum is not the signatured type in the
13653 unit, then we do not want to add a symbol for it. Adding a
13654 symbol would in some cases obscure the true definition of the
13655 enum, giving users an incomplete type when the definition is
13656 actually available. Note that we do not want to do this for all
13657 enums which are just declarations, because C++0x allows forward
13658 enum declarations. */
13659 if (cu
->per_cu
->is_debug_types
13660 && die_is_declaration (die
, cu
))
13662 struct signatured_type
*sig_type
;
13664 sig_type
= (struct signatured_type
*) cu
->per_cu
;
13665 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
13666 if (sig_type
->type_offset_in_section
.sect_off
!= die
->offset
.sect_off
)
13670 new_symbol (die
, this_type
, cu
);
13673 /* Extract all information from a DW_TAG_array_type DIE and put it in
13674 the DIE's type field. For now, this only handles one dimensional
13677 static struct type
*
13678 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13680 struct objfile
*objfile
= cu
->objfile
;
13681 struct die_info
*child_die
;
13683 struct type
*element_type
, *range_type
, *index_type
;
13684 struct type
**range_types
= NULL
;
13685 struct attribute
*attr
;
13687 struct cleanup
*back_to
;
13689 unsigned int bit_stride
= 0;
13691 element_type
= die_type (die
, cu
);
13693 /* The die_type call above may have already set the type for this DIE. */
13694 type
= get_die_type (die
, cu
);
13698 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
13700 bit_stride
= DW_UNSND (attr
) * 8;
13702 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
13704 bit_stride
= DW_UNSND (attr
);
13706 /* Irix 6.2 native cc creates array types without children for
13707 arrays with unspecified length. */
13708 if (die
->child
== NULL
)
13710 index_type
= objfile_type (objfile
)->builtin_int
;
13711 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
13712 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
13714 return set_die_type (die
, type
, cu
);
13717 back_to
= make_cleanup (null_cleanup
, NULL
);
13718 child_die
= die
->child
;
13719 while (child_die
&& child_die
->tag
)
13721 if (child_die
->tag
== DW_TAG_subrange_type
)
13723 struct type
*child_type
= read_type_die (child_die
, cu
);
13725 if (child_type
!= NULL
)
13727 /* The range type was succesfully read. Save it for the
13728 array type creation. */
13729 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
13731 range_types
= (struct type
**)
13732 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
13733 * sizeof (struct type
*));
13735 make_cleanup (free_current_contents
, &range_types
);
13737 range_types
[ndim
++] = child_type
;
13740 child_die
= sibling_die (child_die
);
13743 /* Dwarf2 dimensions are output from left to right, create the
13744 necessary array types in backwards order. */
13746 type
= element_type
;
13748 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
13753 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
13759 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
13763 /* Understand Dwarf2 support for vector types (like they occur on
13764 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
13765 array type. This is not part of the Dwarf2/3 standard yet, but a
13766 custom vendor extension. The main difference between a regular
13767 array and the vector variant is that vectors are passed by value
13769 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
13771 make_vector_type (type
);
13773 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
13774 implementation may choose to implement triple vectors using this
13776 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13779 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
13780 TYPE_LENGTH (type
) = DW_UNSND (attr
);
13782 complaint (&symfile_complaints
,
13783 _("DW_AT_byte_size for array type smaller "
13784 "than the total size of elements"));
13787 name
= dwarf2_name (die
, cu
);
13789 TYPE_NAME (type
) = name
;
13791 /* Install the type in the die. */
13792 set_die_type (die
, type
, cu
);
13794 /* set_die_type should be already done. */
13795 set_descriptive_type (type
, die
, cu
);
13797 do_cleanups (back_to
);
13802 static enum dwarf_array_dim_ordering
13803 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
13805 struct attribute
*attr
;
13807 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
13810 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
13812 /* GNU F77 is a special case, as at 08/2004 array type info is the
13813 opposite order to the dwarf2 specification, but data is still
13814 laid out as per normal fortran.
13816 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
13817 version checking. */
13819 if (cu
->language
== language_fortran
13820 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
13822 return DW_ORD_row_major
;
13825 switch (cu
->language_defn
->la_array_ordering
)
13827 case array_column_major
:
13828 return DW_ORD_col_major
;
13829 case array_row_major
:
13831 return DW_ORD_row_major
;
13835 /* Extract all information from a DW_TAG_set_type DIE and put it in
13836 the DIE's type field. */
13838 static struct type
*
13839 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13841 struct type
*domain_type
, *set_type
;
13842 struct attribute
*attr
;
13844 domain_type
= die_type (die
, cu
);
13846 /* The die_type call above may have already set the type for this DIE. */
13847 set_type
= get_die_type (die
, cu
);
13851 set_type
= create_set_type (NULL
, domain_type
);
13853 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13855 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
13857 return set_die_type (die
, set_type
, cu
);
13860 /* A helper for read_common_block that creates a locexpr baton.
13861 SYM is the symbol which we are marking as computed.
13862 COMMON_DIE is the DIE for the common block.
13863 COMMON_LOC is the location expression attribute for the common
13865 MEMBER_LOC is the location expression attribute for the particular
13866 member of the common block that we are processing.
13867 CU is the CU from which the above come. */
13870 mark_common_block_symbol_computed (struct symbol
*sym
,
13871 struct die_info
*common_die
,
13872 struct attribute
*common_loc
,
13873 struct attribute
*member_loc
,
13874 struct dwarf2_cu
*cu
)
13876 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13877 struct dwarf2_locexpr_baton
*baton
;
13879 unsigned int cu_off
;
13880 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
13881 LONGEST offset
= 0;
13883 gdb_assert (common_loc
&& member_loc
);
13884 gdb_assert (attr_form_is_block (common_loc
));
13885 gdb_assert (attr_form_is_block (member_loc
)
13886 || attr_form_is_constant (member_loc
));
13888 baton
= obstack_alloc (&objfile
->objfile_obstack
,
13889 sizeof (struct dwarf2_locexpr_baton
));
13890 baton
->per_cu
= cu
->per_cu
;
13891 gdb_assert (baton
->per_cu
);
13893 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
13895 if (attr_form_is_constant (member_loc
))
13897 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
13898 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
13901 baton
->size
+= DW_BLOCK (member_loc
)->size
;
13903 ptr
= obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
13906 *ptr
++ = DW_OP_call4
;
13907 cu_off
= common_die
->offset
.sect_off
- cu
->per_cu
->offset
.sect_off
;
13908 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
13911 if (attr_form_is_constant (member_loc
))
13913 *ptr
++ = DW_OP_addr
;
13914 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
13915 ptr
+= cu
->header
.addr_size
;
13919 /* We have to copy the data here, because DW_OP_call4 will only
13920 use a DW_AT_location attribute. */
13921 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
13922 ptr
+= DW_BLOCK (member_loc
)->size
;
13925 *ptr
++ = DW_OP_plus
;
13926 gdb_assert (ptr
- baton
->data
== baton
->size
);
13928 SYMBOL_LOCATION_BATON (sym
) = baton
;
13929 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
13932 /* Create appropriate locally-scoped variables for all the
13933 DW_TAG_common_block entries. Also create a struct common_block
13934 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
13935 is used to sepate the common blocks name namespace from regular
13939 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
13941 struct attribute
*attr
;
13943 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13946 /* Support the .debug_loc offsets. */
13947 if (attr_form_is_block (attr
))
13951 else if (attr_form_is_section_offset (attr
))
13953 dwarf2_complex_location_expr_complaint ();
13958 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
13959 "common block member");
13964 if (die
->child
!= NULL
)
13966 struct objfile
*objfile
= cu
->objfile
;
13967 struct die_info
*child_die
;
13968 size_t n_entries
= 0, size
;
13969 struct common_block
*common_block
;
13970 struct symbol
*sym
;
13972 for (child_die
= die
->child
;
13973 child_die
&& child_die
->tag
;
13974 child_die
= sibling_die (child_die
))
13977 size
= (sizeof (struct common_block
)
13978 + (n_entries
- 1) * sizeof (struct symbol
*));
13979 common_block
= obstack_alloc (&objfile
->objfile_obstack
, size
);
13980 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
13981 common_block
->n_entries
= 0;
13983 for (child_die
= die
->child
;
13984 child_die
&& child_die
->tag
;
13985 child_die
= sibling_die (child_die
))
13987 /* Create the symbol in the DW_TAG_common_block block in the current
13989 sym
= new_symbol (child_die
, NULL
, cu
);
13992 struct attribute
*member_loc
;
13994 common_block
->contents
[common_block
->n_entries
++] = sym
;
13996 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
14000 /* GDB has handled this for a long time, but it is
14001 not specified by DWARF. It seems to have been
14002 emitted by gfortran at least as recently as:
14003 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
14004 complaint (&symfile_complaints
,
14005 _("Variable in common block has "
14006 "DW_AT_data_member_location "
14007 "- DIE at 0x%x [in module %s]"),
14008 child_die
->offset
.sect_off
,
14009 objfile_name (cu
->objfile
));
14011 if (attr_form_is_section_offset (member_loc
))
14012 dwarf2_complex_location_expr_complaint ();
14013 else if (attr_form_is_constant (member_loc
)
14014 || attr_form_is_block (member_loc
))
14017 mark_common_block_symbol_computed (sym
, die
, attr
,
14021 dwarf2_complex_location_expr_complaint ();
14026 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
14027 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
14031 /* Create a type for a C++ namespace. */
14033 static struct type
*
14034 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14036 struct objfile
*objfile
= cu
->objfile
;
14037 const char *previous_prefix
, *name
;
14041 /* For extensions, reuse the type of the original namespace. */
14042 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
14044 struct die_info
*ext_die
;
14045 struct dwarf2_cu
*ext_cu
= cu
;
14047 ext_die
= dwarf2_extension (die
, &ext_cu
);
14048 type
= read_type_die (ext_die
, ext_cu
);
14050 /* EXT_CU may not be the same as CU.
14051 Ensure TYPE is recorded with CU in die_type_hash. */
14052 return set_die_type (die
, type
, cu
);
14055 name
= namespace_name (die
, &is_anonymous
, cu
);
14057 /* Now build the name of the current namespace. */
14059 previous_prefix
= determine_prefix (die
, cu
);
14060 if (previous_prefix
[0] != '\0')
14061 name
= typename_concat (&objfile
->objfile_obstack
,
14062 previous_prefix
, name
, 0, cu
);
14064 /* Create the type. */
14065 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
14067 TYPE_NAME (type
) = name
;
14068 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
14070 return set_die_type (die
, type
, cu
);
14073 /* Read a namespace scope. */
14076 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
14078 struct objfile
*objfile
= cu
->objfile
;
14081 /* Add a symbol associated to this if we haven't seen the namespace
14082 before. Also, add a using directive if it's an anonymous
14085 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
14089 type
= read_type_die (die
, cu
);
14090 new_symbol (die
, type
, cu
);
14092 namespace_name (die
, &is_anonymous
, cu
);
14095 const char *previous_prefix
= determine_prefix (die
, cu
);
14097 add_using_directive (using_directives (cu
->language
),
14098 previous_prefix
, TYPE_NAME (type
), NULL
,
14099 NULL
, NULL
, 0, &objfile
->objfile_obstack
);
14103 if (die
->child
!= NULL
)
14105 struct die_info
*child_die
= die
->child
;
14107 while (child_die
&& child_die
->tag
)
14109 process_die (child_die
, cu
);
14110 child_die
= sibling_die (child_die
);
14115 /* Read a Fortran module as type. This DIE can be only a declaration used for
14116 imported module. Still we need that type as local Fortran "use ... only"
14117 declaration imports depend on the created type in determine_prefix. */
14119 static struct type
*
14120 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14122 struct objfile
*objfile
= cu
->objfile
;
14123 const char *module_name
;
14126 module_name
= dwarf2_name (die
, cu
);
14128 complaint (&symfile_complaints
,
14129 _("DW_TAG_module has no name, offset 0x%x"),
14130 die
->offset
.sect_off
);
14131 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
14133 /* determine_prefix uses TYPE_TAG_NAME. */
14134 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
14136 return set_die_type (die
, type
, cu
);
14139 /* Read a Fortran module. */
14142 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
14144 struct die_info
*child_die
= die
->child
;
14147 type
= read_type_die (die
, cu
);
14148 new_symbol (die
, type
, cu
);
14150 while (child_die
&& child_die
->tag
)
14152 process_die (child_die
, cu
);
14153 child_die
= sibling_die (child_die
);
14157 /* Return the name of the namespace represented by DIE. Set
14158 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
14161 static const char *
14162 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
14164 struct die_info
*current_die
;
14165 const char *name
= NULL
;
14167 /* Loop through the extensions until we find a name. */
14169 for (current_die
= die
;
14170 current_die
!= NULL
;
14171 current_die
= dwarf2_extension (die
, &cu
))
14173 /* We don't use dwarf2_name here so that we can detect the absence
14174 of a name -> anonymous namespace. */
14175 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
14181 /* Is it an anonymous namespace? */
14183 *is_anonymous
= (name
== NULL
);
14185 name
= CP_ANONYMOUS_NAMESPACE_STR
;
14190 /* Extract all information from a DW_TAG_pointer_type DIE and add to
14191 the user defined type vector. */
14193 static struct type
*
14194 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14196 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
14197 struct comp_unit_head
*cu_header
= &cu
->header
;
14199 struct attribute
*attr_byte_size
;
14200 struct attribute
*attr_address_class
;
14201 int byte_size
, addr_class
;
14202 struct type
*target_type
;
14204 target_type
= die_type (die
, cu
);
14206 /* The die_type call above may have already set the type for this DIE. */
14207 type
= get_die_type (die
, cu
);
14211 type
= lookup_pointer_type (target_type
);
14213 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14214 if (attr_byte_size
)
14215 byte_size
= DW_UNSND (attr_byte_size
);
14217 byte_size
= cu_header
->addr_size
;
14219 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
14220 if (attr_address_class
)
14221 addr_class
= DW_UNSND (attr_address_class
);
14223 addr_class
= DW_ADDR_none
;
14225 /* If the pointer size or address class is different than the
14226 default, create a type variant marked as such and set the
14227 length accordingly. */
14228 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
14230 if (gdbarch_address_class_type_flags_p (gdbarch
))
14234 type_flags
= gdbarch_address_class_type_flags
14235 (gdbarch
, byte_size
, addr_class
);
14236 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
14238 type
= make_type_with_address_space (type
, type_flags
);
14240 else if (TYPE_LENGTH (type
) != byte_size
)
14242 complaint (&symfile_complaints
,
14243 _("invalid pointer size %d"), byte_size
);
14247 /* Should we also complain about unhandled address classes? */
14251 TYPE_LENGTH (type
) = byte_size
;
14252 return set_die_type (die
, type
, cu
);
14255 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
14256 the user defined type vector. */
14258 static struct type
*
14259 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14262 struct type
*to_type
;
14263 struct type
*domain
;
14265 to_type
= die_type (die
, cu
);
14266 domain
= die_containing_type (die
, cu
);
14268 /* The calls above may have already set the type for this DIE. */
14269 type
= get_die_type (die
, cu
);
14273 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
14274 type
= lookup_methodptr_type (to_type
);
14275 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
14277 struct type
*new_type
= alloc_type (cu
->objfile
);
14279 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
14280 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
14281 TYPE_VARARGS (to_type
));
14282 type
= lookup_methodptr_type (new_type
);
14285 type
= lookup_memberptr_type (to_type
, domain
);
14287 return set_die_type (die
, type
, cu
);
14290 /* Extract all information from a DW_TAG_reference_type DIE and add to
14291 the user defined type vector. */
14293 static struct type
*
14294 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14296 struct comp_unit_head
*cu_header
= &cu
->header
;
14297 struct type
*type
, *target_type
;
14298 struct attribute
*attr
;
14300 target_type
= die_type (die
, cu
);
14302 /* The die_type call above may have already set the type for this DIE. */
14303 type
= get_die_type (die
, cu
);
14307 type
= lookup_reference_type (target_type
);
14308 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14311 TYPE_LENGTH (type
) = DW_UNSND (attr
);
14315 TYPE_LENGTH (type
) = cu_header
->addr_size
;
14317 return set_die_type (die
, type
, cu
);
14320 /* Add the given cv-qualifiers to the element type of the array. GCC
14321 outputs DWARF type qualifiers that apply to an array, not the
14322 element type. But GDB relies on the array element type to carry
14323 the cv-qualifiers. This mimics section 6.7.3 of the C99
14326 static struct type
*
14327 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
14328 struct type
*base_type
, int cnst
, int voltl
)
14330 struct type
*el_type
, *inner_array
;
14332 base_type
= copy_type (base_type
);
14333 inner_array
= base_type
;
14335 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
14337 TYPE_TARGET_TYPE (inner_array
) =
14338 copy_type (TYPE_TARGET_TYPE (inner_array
));
14339 inner_array
= TYPE_TARGET_TYPE (inner_array
);
14342 el_type
= TYPE_TARGET_TYPE (inner_array
);
14343 cnst
|= TYPE_CONST (el_type
);
14344 voltl
|= TYPE_VOLATILE (el_type
);
14345 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
14347 return set_die_type (die
, base_type
, cu
);
14350 static struct type
*
14351 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14353 struct type
*base_type
, *cv_type
;
14355 base_type
= die_type (die
, cu
);
14357 /* The die_type call above may have already set the type for this DIE. */
14358 cv_type
= get_die_type (die
, cu
);
14362 /* In case the const qualifier is applied to an array type, the element type
14363 is so qualified, not the array type (section 6.7.3 of C99). */
14364 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
14365 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
14367 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
14368 return set_die_type (die
, cv_type
, cu
);
14371 static struct type
*
14372 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14374 struct type
*base_type
, *cv_type
;
14376 base_type
= die_type (die
, cu
);
14378 /* The die_type call above may have already set the type for this DIE. */
14379 cv_type
= get_die_type (die
, cu
);
14383 /* In case the volatile qualifier is applied to an array type, the
14384 element type is so qualified, not the array type (section 6.7.3
14386 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
14387 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
14389 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
14390 return set_die_type (die
, cv_type
, cu
);
14393 /* Handle DW_TAG_restrict_type. */
14395 static struct type
*
14396 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14398 struct type
*base_type
, *cv_type
;
14400 base_type
= die_type (die
, cu
);
14402 /* The die_type call above may have already set the type for this DIE. */
14403 cv_type
= get_die_type (die
, cu
);
14407 cv_type
= make_restrict_type (base_type
);
14408 return set_die_type (die
, cv_type
, cu
);
14411 /* Handle DW_TAG_atomic_type. */
14413 static struct type
*
14414 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14416 struct type
*base_type
, *cv_type
;
14418 base_type
= die_type (die
, cu
);
14420 /* The die_type call above may have already set the type for this DIE. */
14421 cv_type
= get_die_type (die
, cu
);
14425 cv_type
= make_atomic_type (base_type
);
14426 return set_die_type (die
, cv_type
, cu
);
14429 /* Extract all information from a DW_TAG_string_type DIE and add to
14430 the user defined type vector. It isn't really a user defined type,
14431 but it behaves like one, with other DIE's using an AT_user_def_type
14432 attribute to reference it. */
14434 static struct type
*
14435 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14437 struct objfile
*objfile
= cu
->objfile
;
14438 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14439 struct type
*type
, *range_type
, *index_type
, *char_type
;
14440 struct attribute
*attr
;
14441 unsigned int length
;
14443 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
14446 length
= DW_UNSND (attr
);
14450 /* Check for the DW_AT_byte_size attribute. */
14451 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14454 length
= DW_UNSND (attr
);
14462 index_type
= objfile_type (objfile
)->builtin_int
;
14463 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
14464 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
14465 type
= create_string_type (NULL
, char_type
, range_type
);
14467 return set_die_type (die
, type
, cu
);
14470 /* Assuming that DIE corresponds to a function, returns nonzero
14471 if the function is prototyped. */
14474 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
14476 struct attribute
*attr
;
14478 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
14479 if (attr
&& (DW_UNSND (attr
) != 0))
14482 /* The DWARF standard implies that the DW_AT_prototyped attribute
14483 is only meaninful for C, but the concept also extends to other
14484 languages that allow unprototyped functions (Eg: Objective C).
14485 For all other languages, assume that functions are always
14487 if (cu
->language
!= language_c
14488 && cu
->language
!= language_objc
14489 && cu
->language
!= language_opencl
)
14492 /* RealView does not emit DW_AT_prototyped. We can not distinguish
14493 prototyped and unprototyped functions; default to prototyped,
14494 since that is more common in modern code (and RealView warns
14495 about unprototyped functions). */
14496 if (producer_is_realview (cu
->producer
))
14502 /* Handle DIES due to C code like:
14506 int (*funcp)(int a, long l);
14510 ('funcp' generates a DW_TAG_subroutine_type DIE). */
14512 static struct type
*
14513 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14515 struct objfile
*objfile
= cu
->objfile
;
14516 struct type
*type
; /* Type that this function returns. */
14517 struct type
*ftype
; /* Function that returns above type. */
14518 struct attribute
*attr
;
14520 type
= die_type (die
, cu
);
14522 /* The die_type call above may have already set the type for this DIE. */
14523 ftype
= get_die_type (die
, cu
);
14527 ftype
= lookup_function_type (type
);
14529 if (prototyped_function_p (die
, cu
))
14530 TYPE_PROTOTYPED (ftype
) = 1;
14532 /* Store the calling convention in the type if it's available in
14533 the subroutine die. Otherwise set the calling convention to
14534 the default value DW_CC_normal. */
14535 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
14537 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
14538 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
14539 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
14541 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
14543 /* Record whether the function returns normally to its caller or not
14544 if the DWARF producer set that information. */
14545 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
14546 if (attr
&& (DW_UNSND (attr
) != 0))
14547 TYPE_NO_RETURN (ftype
) = 1;
14549 /* We need to add the subroutine type to the die immediately so
14550 we don't infinitely recurse when dealing with parameters
14551 declared as the same subroutine type. */
14552 set_die_type (die
, ftype
, cu
);
14554 if (die
->child
!= NULL
)
14556 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
14557 struct die_info
*child_die
;
14558 int nparams
, iparams
;
14560 /* Count the number of parameters.
14561 FIXME: GDB currently ignores vararg functions, but knows about
14562 vararg member functions. */
14564 child_die
= die
->child
;
14565 while (child_die
&& child_die
->tag
)
14567 if (child_die
->tag
== DW_TAG_formal_parameter
)
14569 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
14570 TYPE_VARARGS (ftype
) = 1;
14571 child_die
= sibling_die (child_die
);
14574 /* Allocate storage for parameters and fill them in. */
14575 TYPE_NFIELDS (ftype
) = nparams
;
14576 TYPE_FIELDS (ftype
) = (struct field
*)
14577 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
14579 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
14580 even if we error out during the parameters reading below. */
14581 for (iparams
= 0; iparams
< nparams
; iparams
++)
14582 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
14585 child_die
= die
->child
;
14586 while (child_die
&& child_die
->tag
)
14588 if (child_die
->tag
== DW_TAG_formal_parameter
)
14590 struct type
*arg_type
;
14592 /* DWARF version 2 has no clean way to discern C++
14593 static and non-static member functions. G++ helps
14594 GDB by marking the first parameter for non-static
14595 member functions (which is the this pointer) as
14596 artificial. We pass this information to
14597 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
14599 DWARF version 3 added DW_AT_object_pointer, which GCC
14600 4.5 does not yet generate. */
14601 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
14603 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
14606 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
14608 /* GCC/43521: In java, the formal parameter
14609 "this" is sometimes not marked with DW_AT_artificial. */
14610 if (cu
->language
== language_java
)
14612 const char *name
= dwarf2_name (child_die
, cu
);
14614 if (name
&& !strcmp (name
, "this"))
14615 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
14618 arg_type
= die_type (child_die
, cu
);
14620 /* RealView does not mark THIS as const, which the testsuite
14621 expects. GCC marks THIS as const in method definitions,
14622 but not in the class specifications (GCC PR 43053). */
14623 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
14624 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
14627 struct dwarf2_cu
*arg_cu
= cu
;
14628 const char *name
= dwarf2_name (child_die
, cu
);
14630 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
14633 /* If the compiler emits this, use it. */
14634 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
14637 else if (name
&& strcmp (name
, "this") == 0)
14638 /* Function definitions will have the argument names. */
14640 else if (name
== NULL
&& iparams
== 0)
14641 /* Declarations may not have the names, so like
14642 elsewhere in GDB, assume an artificial first
14643 argument is "this". */
14647 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
14651 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
14654 child_die
= sibling_die (child_die
);
14661 static struct type
*
14662 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
14664 struct objfile
*objfile
= cu
->objfile
;
14665 const char *name
= NULL
;
14666 struct type
*this_type
, *target_type
;
14668 name
= dwarf2_full_name (NULL
, die
, cu
);
14669 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
14670 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
14671 TYPE_NAME (this_type
) = name
;
14672 set_die_type (die
, this_type
, cu
);
14673 target_type
= die_type (die
, cu
);
14674 if (target_type
!= this_type
)
14675 TYPE_TARGET_TYPE (this_type
) = target_type
;
14678 /* Self-referential typedefs are, it seems, not allowed by the DWARF
14679 spec and cause infinite loops in GDB. */
14680 complaint (&symfile_complaints
,
14681 _("Self-referential DW_TAG_typedef "
14682 "- DIE at 0x%x [in module %s]"),
14683 die
->offset
.sect_off
, objfile_name (objfile
));
14684 TYPE_TARGET_TYPE (this_type
) = NULL
;
14689 /* Find a representation of a given base type and install
14690 it in the TYPE field of the die. */
14692 static struct type
*
14693 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14695 struct objfile
*objfile
= cu
->objfile
;
14697 struct attribute
*attr
;
14698 int encoding
= 0, size
= 0;
14700 enum type_code code
= TYPE_CODE_INT
;
14701 int type_flags
= 0;
14702 struct type
*target_type
= NULL
;
14704 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
14707 encoding
= DW_UNSND (attr
);
14709 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14712 size
= DW_UNSND (attr
);
14714 name
= dwarf2_name (die
, cu
);
14717 complaint (&symfile_complaints
,
14718 _("DW_AT_name missing from DW_TAG_base_type"));
14723 case DW_ATE_address
:
14724 /* Turn DW_ATE_address into a void * pointer. */
14725 code
= TYPE_CODE_PTR
;
14726 type_flags
|= TYPE_FLAG_UNSIGNED
;
14727 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
14729 case DW_ATE_boolean
:
14730 code
= TYPE_CODE_BOOL
;
14731 type_flags
|= TYPE_FLAG_UNSIGNED
;
14733 case DW_ATE_complex_float
:
14734 code
= TYPE_CODE_COMPLEX
;
14735 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
14737 case DW_ATE_decimal_float
:
14738 code
= TYPE_CODE_DECFLOAT
;
14741 code
= TYPE_CODE_FLT
;
14743 case DW_ATE_signed
:
14745 case DW_ATE_unsigned
:
14746 type_flags
|= TYPE_FLAG_UNSIGNED
;
14747 if (cu
->language
== language_fortran
14749 && startswith (name
, "character("))
14750 code
= TYPE_CODE_CHAR
;
14752 case DW_ATE_signed_char
:
14753 if (cu
->language
== language_ada
|| cu
->language
== language_m2
14754 || cu
->language
== language_pascal
14755 || cu
->language
== language_fortran
)
14756 code
= TYPE_CODE_CHAR
;
14758 case DW_ATE_unsigned_char
:
14759 if (cu
->language
== language_ada
|| cu
->language
== language_m2
14760 || cu
->language
== language_pascal
14761 || cu
->language
== language_fortran
)
14762 code
= TYPE_CODE_CHAR
;
14763 type_flags
|= TYPE_FLAG_UNSIGNED
;
14766 /* We just treat this as an integer and then recognize the
14767 type by name elsewhere. */
14771 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
14772 dwarf_type_encoding_name (encoding
));
14776 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
14777 TYPE_NAME (type
) = name
;
14778 TYPE_TARGET_TYPE (type
) = target_type
;
14780 if (name
&& strcmp (name
, "char") == 0)
14781 TYPE_NOSIGN (type
) = 1;
14783 return set_die_type (die
, type
, cu
);
14786 /* Parse dwarf attribute if it's a block, reference or constant and put the
14787 resulting value of the attribute into struct bound_prop.
14788 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
14791 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
14792 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
)
14794 struct dwarf2_property_baton
*baton
;
14795 struct obstack
*obstack
= &cu
->objfile
->objfile_obstack
;
14797 if (attr
== NULL
|| prop
== NULL
)
14800 if (attr_form_is_block (attr
))
14802 baton
= obstack_alloc (obstack
, sizeof (*baton
));
14803 baton
->referenced_type
= NULL
;
14804 baton
->locexpr
.per_cu
= cu
->per_cu
;
14805 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
14806 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
14807 prop
->data
.baton
= baton
;
14808 prop
->kind
= PROP_LOCEXPR
;
14809 gdb_assert (prop
->data
.baton
!= NULL
);
14811 else if (attr_form_is_ref (attr
))
14813 struct dwarf2_cu
*target_cu
= cu
;
14814 struct die_info
*target_die
;
14815 struct attribute
*target_attr
;
14817 target_die
= follow_die_ref (die
, attr
, &target_cu
);
14818 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
14819 if (target_attr
== NULL
)
14820 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
14822 if (target_attr
== NULL
)
14825 switch (target_attr
->name
)
14827 case DW_AT_location
:
14828 if (attr_form_is_section_offset (target_attr
))
14830 baton
= obstack_alloc (obstack
, sizeof (*baton
));
14831 baton
->referenced_type
= die_type (target_die
, target_cu
);
14832 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
14833 prop
->data
.baton
= baton
;
14834 prop
->kind
= PROP_LOCLIST
;
14835 gdb_assert (prop
->data
.baton
!= NULL
);
14837 else if (attr_form_is_block (target_attr
))
14839 baton
= obstack_alloc (obstack
, sizeof (*baton
));
14840 baton
->referenced_type
= die_type (target_die
, target_cu
);
14841 baton
->locexpr
.per_cu
= cu
->per_cu
;
14842 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
14843 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
14844 prop
->data
.baton
= baton
;
14845 prop
->kind
= PROP_LOCEXPR
;
14846 gdb_assert (prop
->data
.baton
!= NULL
);
14850 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
14851 "dynamic property");
14855 case DW_AT_data_member_location
:
14859 if (!handle_data_member_location (target_die
, target_cu
,
14863 baton
= obstack_alloc (obstack
, sizeof (*baton
));
14864 baton
->referenced_type
= read_type_die (target_die
->parent
,
14866 baton
->offset_info
.offset
= offset
;
14867 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
14868 prop
->data
.baton
= baton
;
14869 prop
->kind
= PROP_ADDR_OFFSET
;
14874 else if (attr_form_is_constant (attr
))
14876 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
14877 prop
->kind
= PROP_CONST
;
14881 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
14882 dwarf2_name (die
, cu
));
14889 /* Read the given DW_AT_subrange DIE. */
14891 static struct type
*
14892 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14894 struct type
*base_type
, *orig_base_type
;
14895 struct type
*range_type
;
14896 struct attribute
*attr
;
14897 struct dynamic_prop low
, high
;
14898 int low_default_is_valid
;
14899 int high_bound_is_count
= 0;
14901 LONGEST negative_mask
;
14903 orig_base_type
= die_type (die
, cu
);
14904 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
14905 whereas the real type might be. So, we use ORIG_BASE_TYPE when
14906 creating the range type, but we use the result of check_typedef
14907 when examining properties of the type. */
14908 base_type
= check_typedef (orig_base_type
);
14910 /* The die_type call above may have already set the type for this DIE. */
14911 range_type
= get_die_type (die
, cu
);
14915 low
.kind
= PROP_CONST
;
14916 high
.kind
= PROP_CONST
;
14917 high
.data
.const_val
= 0;
14919 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
14920 omitting DW_AT_lower_bound. */
14921 switch (cu
->language
)
14924 case language_cplus
:
14925 low
.data
.const_val
= 0;
14926 low_default_is_valid
= 1;
14928 case language_fortran
:
14929 low
.data
.const_val
= 1;
14930 low_default_is_valid
= 1;
14933 case language_java
:
14934 case language_objc
:
14935 low
.data
.const_val
= 0;
14936 low_default_is_valid
= (cu
->header
.version
>= 4);
14940 case language_pascal
:
14941 low
.data
.const_val
= 1;
14942 low_default_is_valid
= (cu
->header
.version
>= 4);
14945 low
.data
.const_val
= 0;
14946 low_default_is_valid
= 0;
14950 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
14952 attr_to_dynamic_prop (attr
, die
, cu
, &low
);
14953 else if (!low_default_is_valid
)
14954 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
14955 "- DIE at 0x%x [in module %s]"),
14956 die
->offset
.sect_off
, objfile_name (cu
->objfile
));
14958 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
14959 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
))
14961 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
14962 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
))
14964 /* If bounds are constant do the final calculation here. */
14965 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
14966 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
14968 high_bound_is_count
= 1;
14972 /* Dwarf-2 specifications explicitly allows to create subrange types
14973 without specifying a base type.
14974 In that case, the base type must be set to the type of
14975 the lower bound, upper bound or count, in that order, if any of these
14976 three attributes references an object that has a type.
14977 If no base type is found, the Dwarf-2 specifications say that
14978 a signed integer type of size equal to the size of an address should
14980 For the following C code: `extern char gdb_int [];'
14981 GCC produces an empty range DIE.
14982 FIXME: muller/2010-05-28: Possible references to object for low bound,
14983 high bound or count are not yet handled by this code. */
14984 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
14986 struct objfile
*objfile
= cu
->objfile
;
14987 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14988 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
14989 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
14991 /* Test "int", "long int", and "long long int" objfile types,
14992 and select the first one having a size above or equal to the
14993 architecture address size. */
14994 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
14995 base_type
= int_type
;
14998 int_type
= objfile_type (objfile
)->builtin_long
;
14999 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
15000 base_type
= int_type
;
15003 int_type
= objfile_type (objfile
)->builtin_long_long
;
15004 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
15005 base_type
= int_type
;
15010 /* Normally, the DWARF producers are expected to use a signed
15011 constant form (Eg. DW_FORM_sdata) to express negative bounds.
15012 But this is unfortunately not always the case, as witnessed
15013 with GCC, for instance, where the ambiguous DW_FORM_dataN form
15014 is used instead. To work around that ambiguity, we treat
15015 the bounds as signed, and thus sign-extend their values, when
15016 the base type is signed. */
15018 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
15019 if (low
.kind
== PROP_CONST
15020 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
15021 low
.data
.const_val
|= negative_mask
;
15022 if (high
.kind
== PROP_CONST
15023 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
15024 high
.data
.const_val
|= negative_mask
;
15026 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
);
15028 if (high_bound_is_count
)
15029 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
15031 /* Ada expects an empty array on no boundary attributes. */
15032 if (attr
== NULL
&& cu
->language
!= language_ada
)
15033 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
15035 name
= dwarf2_name (die
, cu
);
15037 TYPE_NAME (range_type
) = name
;
15039 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15041 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
15043 set_die_type (die
, range_type
, cu
);
15045 /* set_die_type should be already done. */
15046 set_descriptive_type (range_type
, die
, cu
);
15051 static struct type
*
15052 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15056 /* For now, we only support the C meaning of an unspecified type: void. */
15058 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
15059 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
15061 return set_die_type (die
, type
, cu
);
15064 /* Read a single die and all its descendents. Set the die's sibling
15065 field to NULL; set other fields in the die correctly, and set all
15066 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
15067 location of the info_ptr after reading all of those dies. PARENT
15068 is the parent of the die in question. */
15070 static struct die_info
*
15071 read_die_and_children (const struct die_reader_specs
*reader
,
15072 const gdb_byte
*info_ptr
,
15073 const gdb_byte
**new_info_ptr
,
15074 struct die_info
*parent
)
15076 struct die_info
*die
;
15077 const gdb_byte
*cur_ptr
;
15080 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
15083 *new_info_ptr
= cur_ptr
;
15086 store_in_ref_table (die
, reader
->cu
);
15089 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
15093 *new_info_ptr
= cur_ptr
;
15096 die
->sibling
= NULL
;
15097 die
->parent
= parent
;
15101 /* Read a die, all of its descendents, and all of its siblings; set
15102 all of the fields of all of the dies correctly. Arguments are as
15103 in read_die_and_children. */
15105 static struct die_info
*
15106 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
15107 const gdb_byte
*info_ptr
,
15108 const gdb_byte
**new_info_ptr
,
15109 struct die_info
*parent
)
15111 struct die_info
*first_die
, *last_sibling
;
15112 const gdb_byte
*cur_ptr
;
15114 cur_ptr
= info_ptr
;
15115 first_die
= last_sibling
= NULL
;
15119 struct die_info
*die
15120 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
15124 *new_info_ptr
= cur_ptr
;
15131 last_sibling
->sibling
= die
;
15133 last_sibling
= die
;
15137 /* Read a die, all of its descendents, and all of its siblings; set
15138 all of the fields of all of the dies correctly. Arguments are as
15139 in read_die_and_children.
15140 This the main entry point for reading a DIE and all its children. */
15142 static struct die_info
*
15143 read_die_and_siblings (const struct die_reader_specs
*reader
,
15144 const gdb_byte
*info_ptr
,
15145 const gdb_byte
**new_info_ptr
,
15146 struct die_info
*parent
)
15148 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
15149 new_info_ptr
, parent
);
15151 if (dwarf_die_debug
)
15153 fprintf_unfiltered (gdb_stdlog
,
15154 "Read die from %s@0x%x of %s:\n",
15155 get_section_name (reader
->die_section
),
15156 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
15157 bfd_get_filename (reader
->abfd
));
15158 dump_die (die
, dwarf_die_debug
);
15164 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
15166 The caller is responsible for filling in the extra attributes
15167 and updating (*DIEP)->num_attrs.
15168 Set DIEP to point to a newly allocated die with its information,
15169 except for its child, sibling, and parent fields.
15170 Set HAS_CHILDREN to tell whether the die has children or not. */
15172 static const gdb_byte
*
15173 read_full_die_1 (const struct die_reader_specs
*reader
,
15174 struct die_info
**diep
, const gdb_byte
*info_ptr
,
15175 int *has_children
, int num_extra_attrs
)
15177 unsigned int abbrev_number
, bytes_read
, i
;
15178 sect_offset offset
;
15179 struct abbrev_info
*abbrev
;
15180 struct die_info
*die
;
15181 struct dwarf2_cu
*cu
= reader
->cu
;
15182 bfd
*abfd
= reader
->abfd
;
15184 offset
.sect_off
= info_ptr
- reader
->buffer
;
15185 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
15186 info_ptr
+= bytes_read
;
15187 if (!abbrev_number
)
15194 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
15196 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
15198 bfd_get_filename (abfd
));
15200 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
15201 die
->offset
= offset
;
15202 die
->tag
= abbrev
->tag
;
15203 die
->abbrev
= abbrev_number
;
15205 /* Make the result usable.
15206 The caller needs to update num_attrs after adding the extra
15208 die
->num_attrs
= abbrev
->num_attrs
;
15210 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
15211 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
15215 *has_children
= abbrev
->has_children
;
15219 /* Read a die and all its attributes.
15220 Set DIEP to point to a newly allocated die with its information,
15221 except for its child, sibling, and parent fields.
15222 Set HAS_CHILDREN to tell whether the die has children or not. */
15224 static const gdb_byte
*
15225 read_full_die (const struct die_reader_specs
*reader
,
15226 struct die_info
**diep
, const gdb_byte
*info_ptr
,
15229 const gdb_byte
*result
;
15231 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
15233 if (dwarf_die_debug
)
15235 fprintf_unfiltered (gdb_stdlog
,
15236 "Read die from %s@0x%x of %s:\n",
15237 get_section_name (reader
->die_section
),
15238 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
15239 bfd_get_filename (reader
->abfd
));
15240 dump_die (*diep
, dwarf_die_debug
);
15246 /* Abbreviation tables.
15248 In DWARF version 2, the description of the debugging information is
15249 stored in a separate .debug_abbrev section. Before we read any
15250 dies from a section we read in all abbreviations and install them
15251 in a hash table. */
15253 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
15255 static struct abbrev_info
*
15256 abbrev_table_alloc_abbrev (struct abbrev_table
*abbrev_table
)
15258 struct abbrev_info
*abbrev
;
15260 abbrev
= (struct abbrev_info
*)
15261 obstack_alloc (&abbrev_table
->abbrev_obstack
, sizeof (struct abbrev_info
));
15262 memset (abbrev
, 0, sizeof (struct abbrev_info
));
15266 /* Add an abbreviation to the table. */
15269 abbrev_table_add_abbrev (struct abbrev_table
*abbrev_table
,
15270 unsigned int abbrev_number
,
15271 struct abbrev_info
*abbrev
)
15273 unsigned int hash_number
;
15275 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
15276 abbrev
->next
= abbrev_table
->abbrevs
[hash_number
];
15277 abbrev_table
->abbrevs
[hash_number
] = abbrev
;
15280 /* Look up an abbrev in the table.
15281 Returns NULL if the abbrev is not found. */
15283 static struct abbrev_info
*
15284 abbrev_table_lookup_abbrev (const struct abbrev_table
*abbrev_table
,
15285 unsigned int abbrev_number
)
15287 unsigned int hash_number
;
15288 struct abbrev_info
*abbrev
;
15290 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
15291 abbrev
= abbrev_table
->abbrevs
[hash_number
];
15295 if (abbrev
->number
== abbrev_number
)
15297 abbrev
= abbrev
->next
;
15302 /* Read in an abbrev table. */
15304 static struct abbrev_table
*
15305 abbrev_table_read_table (struct dwarf2_section_info
*section
,
15306 sect_offset offset
)
15308 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15309 bfd
*abfd
= get_section_bfd_owner (section
);
15310 struct abbrev_table
*abbrev_table
;
15311 const gdb_byte
*abbrev_ptr
;
15312 struct abbrev_info
*cur_abbrev
;
15313 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
15314 unsigned int abbrev_form
;
15315 struct attr_abbrev
*cur_attrs
;
15316 unsigned int allocated_attrs
;
15318 abbrev_table
= XNEW (struct abbrev_table
);
15319 abbrev_table
->offset
= offset
;
15320 obstack_init (&abbrev_table
->abbrev_obstack
);
15321 abbrev_table
->abbrevs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
15323 * sizeof (struct abbrev_info
*)));
15324 memset (abbrev_table
->abbrevs
, 0,
15325 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
15327 dwarf2_read_section (objfile
, section
);
15328 abbrev_ptr
= section
->buffer
+ offset
.sect_off
;
15329 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15330 abbrev_ptr
+= bytes_read
;
15332 allocated_attrs
= ATTR_ALLOC_CHUNK
;
15333 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
15335 /* Loop until we reach an abbrev number of 0. */
15336 while (abbrev_number
)
15338 cur_abbrev
= abbrev_table_alloc_abbrev (abbrev_table
);
15340 /* read in abbrev header */
15341 cur_abbrev
->number
= abbrev_number
;
15343 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15344 abbrev_ptr
+= bytes_read
;
15345 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
15348 /* now read in declarations */
15349 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15350 abbrev_ptr
+= bytes_read
;
15351 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15352 abbrev_ptr
+= bytes_read
;
15353 while (abbrev_name
)
15355 if (cur_abbrev
->num_attrs
== allocated_attrs
)
15357 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
15359 = xrealloc (cur_attrs
, (allocated_attrs
15360 * sizeof (struct attr_abbrev
)));
15363 cur_attrs
[cur_abbrev
->num_attrs
].name
15364 = (enum dwarf_attribute
) abbrev_name
;
15365 cur_attrs
[cur_abbrev
->num_attrs
++].form
15366 = (enum dwarf_form
) abbrev_form
;
15367 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15368 abbrev_ptr
+= bytes_read
;
15369 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15370 abbrev_ptr
+= bytes_read
;
15373 cur_abbrev
->attrs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
15374 (cur_abbrev
->num_attrs
15375 * sizeof (struct attr_abbrev
)));
15376 memcpy (cur_abbrev
->attrs
, cur_attrs
,
15377 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
15379 abbrev_table_add_abbrev (abbrev_table
, abbrev_number
, cur_abbrev
);
15381 /* Get next abbreviation.
15382 Under Irix6 the abbreviations for a compilation unit are not
15383 always properly terminated with an abbrev number of 0.
15384 Exit loop if we encounter an abbreviation which we have
15385 already read (which means we are about to read the abbreviations
15386 for the next compile unit) or if the end of the abbreviation
15387 table is reached. */
15388 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
15390 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
15391 abbrev_ptr
+= bytes_read
;
15392 if (abbrev_table_lookup_abbrev (abbrev_table
, abbrev_number
) != NULL
)
15397 return abbrev_table
;
15400 /* Free the resources held by ABBREV_TABLE. */
15403 abbrev_table_free (struct abbrev_table
*abbrev_table
)
15405 obstack_free (&abbrev_table
->abbrev_obstack
, NULL
);
15406 xfree (abbrev_table
);
15409 /* Same as abbrev_table_free but as a cleanup.
15410 We pass in a pointer to the pointer to the table so that we can
15411 set the pointer to NULL when we're done. It also simplifies
15412 build_type_psymtabs_1. */
15415 abbrev_table_free_cleanup (void *table_ptr
)
15417 struct abbrev_table
**abbrev_table_ptr
= table_ptr
;
15419 if (*abbrev_table_ptr
!= NULL
)
15420 abbrev_table_free (*abbrev_table_ptr
);
15421 *abbrev_table_ptr
= NULL
;
15424 /* Read the abbrev table for CU from ABBREV_SECTION. */
15427 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
15428 struct dwarf2_section_info
*abbrev_section
)
15431 abbrev_table_read_table (abbrev_section
, cu
->header
.abbrev_offset
);
15434 /* Release the memory used by the abbrev table for a compilation unit. */
15437 dwarf2_free_abbrev_table (void *ptr_to_cu
)
15439 struct dwarf2_cu
*cu
= ptr_to_cu
;
15441 if (cu
->abbrev_table
!= NULL
)
15442 abbrev_table_free (cu
->abbrev_table
);
15443 /* Set this to NULL so that we SEGV if we try to read it later,
15444 and also because free_comp_unit verifies this is NULL. */
15445 cu
->abbrev_table
= NULL
;
15448 /* Returns nonzero if TAG represents a type that we might generate a partial
15452 is_type_tag_for_partial (int tag
)
15457 /* Some types that would be reasonable to generate partial symbols for,
15458 that we don't at present. */
15459 case DW_TAG_array_type
:
15460 case DW_TAG_file_type
:
15461 case DW_TAG_ptr_to_member_type
:
15462 case DW_TAG_set_type
:
15463 case DW_TAG_string_type
:
15464 case DW_TAG_subroutine_type
:
15466 case DW_TAG_base_type
:
15467 case DW_TAG_class_type
:
15468 case DW_TAG_interface_type
:
15469 case DW_TAG_enumeration_type
:
15470 case DW_TAG_structure_type
:
15471 case DW_TAG_subrange_type
:
15472 case DW_TAG_typedef
:
15473 case DW_TAG_union_type
:
15480 /* Load all DIEs that are interesting for partial symbols into memory. */
15482 static struct partial_die_info
*
15483 load_partial_dies (const struct die_reader_specs
*reader
,
15484 const gdb_byte
*info_ptr
, int building_psymtab
)
15486 struct dwarf2_cu
*cu
= reader
->cu
;
15487 struct objfile
*objfile
= cu
->objfile
;
15488 struct partial_die_info
*part_die
;
15489 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
15490 struct abbrev_info
*abbrev
;
15491 unsigned int bytes_read
;
15492 unsigned int load_all
= 0;
15493 int nesting_level
= 1;
15498 gdb_assert (cu
->per_cu
!= NULL
);
15499 if (cu
->per_cu
->load_all_dies
)
15503 = htab_create_alloc_ex (cu
->header
.length
/ 12,
15507 &cu
->comp_unit_obstack
,
15508 hashtab_obstack_allocate
,
15509 dummy_obstack_deallocate
);
15511 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
15512 sizeof (struct partial_die_info
));
15516 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
15518 /* A NULL abbrev means the end of a series of children. */
15519 if (abbrev
== NULL
)
15521 if (--nesting_level
== 0)
15523 /* PART_DIE was probably the last thing allocated on the
15524 comp_unit_obstack, so we could call obstack_free
15525 here. We don't do that because the waste is small,
15526 and will be cleaned up when we're done with this
15527 compilation unit. This way, we're also more robust
15528 against other users of the comp_unit_obstack. */
15531 info_ptr
+= bytes_read
;
15532 last_die
= parent_die
;
15533 parent_die
= parent_die
->die_parent
;
15537 /* Check for template arguments. We never save these; if
15538 they're seen, we just mark the parent, and go on our way. */
15539 if (parent_die
!= NULL
15540 && cu
->language
== language_cplus
15541 && (abbrev
->tag
== DW_TAG_template_type_param
15542 || abbrev
->tag
== DW_TAG_template_value_param
))
15544 parent_die
->has_template_arguments
= 1;
15548 /* We don't need a partial DIE for the template argument. */
15549 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
15554 /* We only recurse into c++ subprograms looking for template arguments.
15555 Skip their other children. */
15557 && cu
->language
== language_cplus
15558 && parent_die
!= NULL
15559 && parent_die
->tag
== DW_TAG_subprogram
)
15561 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
15565 /* Check whether this DIE is interesting enough to save. Normally
15566 we would not be interested in members here, but there may be
15567 later variables referencing them via DW_AT_specification (for
15568 static members). */
15570 && !is_type_tag_for_partial (abbrev
->tag
)
15571 && abbrev
->tag
!= DW_TAG_constant
15572 && abbrev
->tag
!= DW_TAG_enumerator
15573 && abbrev
->tag
!= DW_TAG_subprogram
15574 && abbrev
->tag
!= DW_TAG_lexical_block
15575 && abbrev
->tag
!= DW_TAG_variable
15576 && abbrev
->tag
!= DW_TAG_namespace
15577 && abbrev
->tag
!= DW_TAG_module
15578 && abbrev
->tag
!= DW_TAG_member
15579 && abbrev
->tag
!= DW_TAG_imported_unit
15580 && abbrev
->tag
!= DW_TAG_imported_declaration
)
15582 /* Otherwise we skip to the next sibling, if any. */
15583 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
15587 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
15590 /* This two-pass algorithm for processing partial symbols has a
15591 high cost in cache pressure. Thus, handle some simple cases
15592 here which cover the majority of C partial symbols. DIEs
15593 which neither have specification tags in them, nor could have
15594 specification tags elsewhere pointing at them, can simply be
15595 processed and discarded.
15597 This segment is also optional; scan_partial_symbols and
15598 add_partial_symbol will handle these DIEs if we chain
15599 them in normally. When compilers which do not emit large
15600 quantities of duplicate debug information are more common,
15601 this code can probably be removed. */
15603 /* Any complete simple types at the top level (pretty much all
15604 of them, for a language without namespaces), can be processed
15606 if (parent_die
== NULL
15607 && part_die
->has_specification
== 0
15608 && part_die
->is_declaration
== 0
15609 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
15610 || part_die
->tag
== DW_TAG_base_type
15611 || part_die
->tag
== DW_TAG_subrange_type
))
15613 if (building_psymtab
&& part_die
->name
!= NULL
)
15614 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
15615 VAR_DOMAIN
, LOC_TYPEDEF
,
15616 &objfile
->static_psymbols
,
15617 0, cu
->language
, objfile
);
15618 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
15622 /* The exception for DW_TAG_typedef with has_children above is
15623 a workaround of GCC PR debug/47510. In the case of this complaint
15624 type_name_no_tag_or_error will error on such types later.
15626 GDB skipped children of DW_TAG_typedef by the shortcut above and then
15627 it could not find the child DIEs referenced later, this is checked
15628 above. In correct DWARF DW_TAG_typedef should have no children. */
15630 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
15631 complaint (&symfile_complaints
,
15632 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
15633 "- DIE at 0x%x [in module %s]"),
15634 part_die
->offset
.sect_off
, objfile_name (objfile
));
15636 /* If we're at the second level, and we're an enumerator, and
15637 our parent has no specification (meaning possibly lives in a
15638 namespace elsewhere), then we can add the partial symbol now
15639 instead of queueing it. */
15640 if (part_die
->tag
== DW_TAG_enumerator
15641 && parent_die
!= NULL
15642 && parent_die
->die_parent
== NULL
15643 && parent_die
->tag
== DW_TAG_enumeration_type
15644 && parent_die
->has_specification
== 0)
15646 if (part_die
->name
== NULL
)
15647 complaint (&symfile_complaints
,
15648 _("malformed enumerator DIE ignored"));
15649 else if (building_psymtab
)
15650 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
15651 VAR_DOMAIN
, LOC_CONST
,
15652 (cu
->language
== language_cplus
15653 || cu
->language
== language_java
)
15654 ? &objfile
->global_psymbols
15655 : &objfile
->static_psymbols
,
15656 0, cu
->language
, objfile
);
15658 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
15662 /* We'll save this DIE so link it in. */
15663 part_die
->die_parent
= parent_die
;
15664 part_die
->die_sibling
= NULL
;
15665 part_die
->die_child
= NULL
;
15667 if (last_die
&& last_die
== parent_die
)
15668 last_die
->die_child
= part_die
;
15670 last_die
->die_sibling
= part_die
;
15672 last_die
= part_die
;
15674 if (first_die
== NULL
)
15675 first_die
= part_die
;
15677 /* Maybe add the DIE to the hash table. Not all DIEs that we
15678 find interesting need to be in the hash table, because we
15679 also have the parent/sibling/child chains; only those that we
15680 might refer to by offset later during partial symbol reading.
15682 For now this means things that might have be the target of a
15683 DW_AT_specification, DW_AT_abstract_origin, or
15684 DW_AT_extension. DW_AT_extension will refer only to
15685 namespaces; DW_AT_abstract_origin refers to functions (and
15686 many things under the function DIE, but we do not recurse
15687 into function DIEs during partial symbol reading) and
15688 possibly variables as well; DW_AT_specification refers to
15689 declarations. Declarations ought to have the DW_AT_declaration
15690 flag. It happens that GCC forgets to put it in sometimes, but
15691 only for functions, not for types.
15693 Adding more things than necessary to the hash table is harmless
15694 except for the performance cost. Adding too few will result in
15695 wasted time in find_partial_die, when we reread the compilation
15696 unit with load_all_dies set. */
15699 || abbrev
->tag
== DW_TAG_constant
15700 || abbrev
->tag
== DW_TAG_subprogram
15701 || abbrev
->tag
== DW_TAG_variable
15702 || abbrev
->tag
== DW_TAG_namespace
15703 || part_die
->is_declaration
)
15707 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
15708 part_die
->offset
.sect_off
, INSERT
);
15712 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
15713 sizeof (struct partial_die_info
));
15715 /* For some DIEs we want to follow their children (if any). For C
15716 we have no reason to follow the children of structures; for other
15717 languages we have to, so that we can get at method physnames
15718 to infer fully qualified class names, for DW_AT_specification,
15719 and for C++ template arguments. For C++, we also look one level
15720 inside functions to find template arguments (if the name of the
15721 function does not already contain the template arguments).
15723 For Ada, we need to scan the children of subprograms and lexical
15724 blocks as well because Ada allows the definition of nested
15725 entities that could be interesting for the debugger, such as
15726 nested subprograms for instance. */
15727 if (last_die
->has_children
15729 || last_die
->tag
== DW_TAG_namespace
15730 || last_die
->tag
== DW_TAG_module
15731 || last_die
->tag
== DW_TAG_enumeration_type
15732 || (cu
->language
== language_cplus
15733 && last_die
->tag
== DW_TAG_subprogram
15734 && (last_die
->name
== NULL
15735 || strchr (last_die
->name
, '<') == NULL
))
15736 || (cu
->language
!= language_c
15737 && (last_die
->tag
== DW_TAG_class_type
15738 || last_die
->tag
== DW_TAG_interface_type
15739 || last_die
->tag
== DW_TAG_structure_type
15740 || last_die
->tag
== DW_TAG_union_type
))
15741 || (cu
->language
== language_ada
15742 && (last_die
->tag
== DW_TAG_subprogram
15743 || last_die
->tag
== DW_TAG_lexical_block
))))
15746 parent_die
= last_die
;
15750 /* Otherwise we skip to the next sibling, if any. */
15751 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
15753 /* Back to the top, do it again. */
15757 /* Read a minimal amount of information into the minimal die structure. */
15759 static const gdb_byte
*
15760 read_partial_die (const struct die_reader_specs
*reader
,
15761 struct partial_die_info
*part_die
,
15762 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
15763 const gdb_byte
*info_ptr
)
15765 struct dwarf2_cu
*cu
= reader
->cu
;
15766 struct objfile
*objfile
= cu
->objfile
;
15767 const gdb_byte
*buffer
= reader
->buffer
;
15769 struct attribute attr
;
15770 int has_low_pc_attr
= 0;
15771 int has_high_pc_attr
= 0;
15772 int high_pc_relative
= 0;
15774 memset (part_die
, 0, sizeof (struct partial_die_info
));
15776 part_die
->offset
.sect_off
= info_ptr
- buffer
;
15778 info_ptr
+= abbrev_len
;
15780 if (abbrev
== NULL
)
15783 part_die
->tag
= abbrev
->tag
;
15784 part_die
->has_children
= abbrev
->has_children
;
15786 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
15788 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
15790 /* Store the data if it is of an attribute we want to keep in a
15791 partial symbol table. */
15795 switch (part_die
->tag
)
15797 case DW_TAG_compile_unit
:
15798 case DW_TAG_partial_unit
:
15799 case DW_TAG_type_unit
:
15800 /* Compilation units have a DW_AT_name that is a filename, not
15801 a source language identifier. */
15802 case DW_TAG_enumeration_type
:
15803 case DW_TAG_enumerator
:
15804 /* These tags always have simple identifiers already; no need
15805 to canonicalize them. */
15806 part_die
->name
= DW_STRING (&attr
);
15810 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
15811 &objfile
->per_bfd
->storage_obstack
);
15815 case DW_AT_linkage_name
:
15816 case DW_AT_MIPS_linkage_name
:
15817 /* Note that both forms of linkage name might appear. We
15818 assume they will be the same, and we only store the last
15820 if (cu
->language
== language_ada
)
15821 part_die
->name
= DW_STRING (&attr
);
15822 part_die
->linkage_name
= DW_STRING (&attr
);
15825 has_low_pc_attr
= 1;
15826 part_die
->lowpc
= attr_value_as_address (&attr
);
15828 case DW_AT_high_pc
:
15829 has_high_pc_attr
= 1;
15830 part_die
->highpc
= attr_value_as_address (&attr
);
15831 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
15832 high_pc_relative
= 1;
15834 case DW_AT_location
:
15835 /* Support the .debug_loc offsets. */
15836 if (attr_form_is_block (&attr
))
15838 part_die
->d
.locdesc
= DW_BLOCK (&attr
);
15840 else if (attr_form_is_section_offset (&attr
))
15842 dwarf2_complex_location_expr_complaint ();
15846 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
15847 "partial symbol information");
15850 case DW_AT_external
:
15851 part_die
->is_external
= DW_UNSND (&attr
);
15853 case DW_AT_declaration
:
15854 part_die
->is_declaration
= DW_UNSND (&attr
);
15857 part_die
->has_type
= 1;
15859 case DW_AT_abstract_origin
:
15860 case DW_AT_specification
:
15861 case DW_AT_extension
:
15862 part_die
->has_specification
= 1;
15863 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
15864 part_die
->spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
15865 || cu
->per_cu
->is_dwz
);
15867 case DW_AT_sibling
:
15868 /* Ignore absolute siblings, they might point outside of
15869 the current compile unit. */
15870 if (attr
.form
== DW_FORM_ref_addr
)
15871 complaint (&symfile_complaints
,
15872 _("ignoring absolute DW_AT_sibling"));
15875 unsigned int off
= dwarf2_get_ref_die_offset (&attr
).sect_off
;
15876 const gdb_byte
*sibling_ptr
= buffer
+ off
;
15878 if (sibling_ptr
< info_ptr
)
15879 complaint (&symfile_complaints
,
15880 _("DW_AT_sibling points backwards"));
15881 else if (sibling_ptr
> reader
->buffer_end
)
15882 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
15884 part_die
->sibling
= sibling_ptr
;
15887 case DW_AT_byte_size
:
15888 part_die
->has_byte_size
= 1;
15890 case DW_AT_const_value
:
15891 part_die
->has_const_value
= 1;
15893 case DW_AT_calling_convention
:
15894 /* DWARF doesn't provide a way to identify a program's source-level
15895 entry point. DW_AT_calling_convention attributes are only meant
15896 to describe functions' calling conventions.
15898 However, because it's a necessary piece of information in
15899 Fortran, and because DW_CC_program is the only piece of debugging
15900 information whose definition refers to a 'main program' at all,
15901 several compilers have begun marking Fortran main programs with
15902 DW_CC_program --- even when those functions use the standard
15903 calling conventions.
15905 So until DWARF specifies a way to provide this information and
15906 compilers pick up the new representation, we'll support this
15908 if (DW_UNSND (&attr
) == DW_CC_program
15909 && cu
->language
== language_fortran
)
15910 set_objfile_main_name (objfile
, part_die
->name
, language_fortran
);
15913 if (DW_UNSND (&attr
) == DW_INL_inlined
15914 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
15915 part_die
->may_be_inlined
= 1;
15919 if (part_die
->tag
== DW_TAG_imported_unit
)
15921 part_die
->d
.offset
= dwarf2_get_ref_die_offset (&attr
);
15922 part_die
->is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
15923 || cu
->per_cu
->is_dwz
);
15932 if (high_pc_relative
)
15933 part_die
->highpc
+= part_die
->lowpc
;
15935 if (has_low_pc_attr
&& has_high_pc_attr
)
15937 /* When using the GNU linker, .gnu.linkonce. sections are used to
15938 eliminate duplicate copies of functions and vtables and such.
15939 The linker will arbitrarily choose one and discard the others.
15940 The AT_*_pc values for such functions refer to local labels in
15941 these sections. If the section from that file was discarded, the
15942 labels are not in the output, so the relocs get a value of 0.
15943 If this is a discarded function, mark the pc bounds as invalid,
15944 so that GDB will ignore it. */
15945 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
15947 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15949 complaint (&symfile_complaints
,
15950 _("DW_AT_low_pc %s is zero "
15951 "for DIE at 0x%x [in module %s]"),
15952 paddress (gdbarch
, part_die
->lowpc
),
15953 part_die
->offset
.sect_off
, objfile_name (objfile
));
15955 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
15956 else if (part_die
->lowpc
>= part_die
->highpc
)
15958 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15960 complaint (&symfile_complaints
,
15961 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
15962 "for DIE at 0x%x [in module %s]"),
15963 paddress (gdbarch
, part_die
->lowpc
),
15964 paddress (gdbarch
, part_die
->highpc
),
15965 part_die
->offset
.sect_off
, objfile_name (objfile
));
15968 part_die
->has_pc_info
= 1;
15974 /* Find a cached partial DIE at OFFSET in CU. */
15976 static struct partial_die_info
*
15977 find_partial_die_in_comp_unit (sect_offset offset
, struct dwarf2_cu
*cu
)
15979 struct partial_die_info
*lookup_die
= NULL
;
15980 struct partial_die_info part_die
;
15982 part_die
.offset
= offset
;
15983 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
,
15989 /* Find a partial DIE at OFFSET, which may or may not be in CU,
15990 except in the case of .debug_types DIEs which do not reference
15991 outside their CU (they do however referencing other types via
15992 DW_FORM_ref_sig8). */
15994 static struct partial_die_info
*
15995 find_partial_die (sect_offset offset
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
15997 struct objfile
*objfile
= cu
->objfile
;
15998 struct dwarf2_per_cu_data
*per_cu
= NULL
;
15999 struct partial_die_info
*pd
= NULL
;
16001 if (offset_in_dwz
== cu
->per_cu
->is_dwz
16002 && offset_in_cu_p (&cu
->header
, offset
))
16004 pd
= find_partial_die_in_comp_unit (offset
, cu
);
16007 /* We missed recording what we needed.
16008 Load all dies and try again. */
16009 per_cu
= cu
->per_cu
;
16013 /* TUs don't reference other CUs/TUs (except via type signatures). */
16014 if (cu
->per_cu
->is_debug_types
)
16016 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
16017 " external reference to offset 0x%lx [in module %s].\n"),
16018 (long) cu
->header
.offset
.sect_off
, (long) offset
.sect_off
,
16019 bfd_get_filename (objfile
->obfd
));
16021 per_cu
= dwarf2_find_containing_comp_unit (offset
, offset_in_dwz
,
16024 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
16025 load_partial_comp_unit (per_cu
);
16027 per_cu
->cu
->last_used
= 0;
16028 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
16031 /* If we didn't find it, and not all dies have been loaded,
16032 load them all and try again. */
16034 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
16036 per_cu
->load_all_dies
= 1;
16038 /* This is nasty. When we reread the DIEs, somewhere up the call chain
16039 THIS_CU->cu may already be in use. So we can't just free it and
16040 replace its DIEs with the ones we read in. Instead, we leave those
16041 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
16042 and clobber THIS_CU->cu->partial_dies with the hash table for the new
16044 load_partial_comp_unit (per_cu
);
16046 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
16050 internal_error (__FILE__
, __LINE__
,
16051 _("could not find partial DIE 0x%x "
16052 "in cache [from module %s]\n"),
16053 offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
16057 /* See if we can figure out if the class lives in a namespace. We do
16058 this by looking for a member function; its demangled name will
16059 contain namespace info, if there is any. */
16062 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
16063 struct dwarf2_cu
*cu
)
16065 /* NOTE: carlton/2003-10-07: Getting the info this way changes
16066 what template types look like, because the demangler
16067 frequently doesn't give the same name as the debug info. We
16068 could fix this by only using the demangled name to get the
16069 prefix (but see comment in read_structure_type). */
16071 struct partial_die_info
*real_pdi
;
16072 struct partial_die_info
*child_pdi
;
16074 /* If this DIE (this DIE's specification, if any) has a parent, then
16075 we should not do this. We'll prepend the parent's fully qualified
16076 name when we create the partial symbol. */
16078 real_pdi
= struct_pdi
;
16079 while (real_pdi
->has_specification
)
16080 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
16081 real_pdi
->spec_is_dwz
, cu
);
16083 if (real_pdi
->die_parent
!= NULL
)
16086 for (child_pdi
= struct_pdi
->die_child
;
16088 child_pdi
= child_pdi
->die_sibling
)
16090 if (child_pdi
->tag
== DW_TAG_subprogram
16091 && child_pdi
->linkage_name
!= NULL
)
16093 char *actual_class_name
16094 = language_class_name_from_physname (cu
->language_defn
,
16095 child_pdi
->linkage_name
);
16096 if (actual_class_name
!= NULL
)
16099 = obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
16101 strlen (actual_class_name
));
16102 xfree (actual_class_name
);
16109 /* Adjust PART_DIE before generating a symbol for it. This function
16110 may set the is_external flag or change the DIE's name. */
16113 fixup_partial_die (struct partial_die_info
*part_die
,
16114 struct dwarf2_cu
*cu
)
16116 /* Once we've fixed up a die, there's no point in doing so again.
16117 This also avoids a memory leak if we were to call
16118 guess_partial_die_structure_name multiple times. */
16119 if (part_die
->fixup_called
)
16122 /* If we found a reference attribute and the DIE has no name, try
16123 to find a name in the referred to DIE. */
16125 if (part_die
->name
== NULL
&& part_die
->has_specification
)
16127 struct partial_die_info
*spec_die
;
16129 spec_die
= find_partial_die (part_die
->spec_offset
,
16130 part_die
->spec_is_dwz
, cu
);
16132 fixup_partial_die (spec_die
, cu
);
16134 if (spec_die
->name
)
16136 part_die
->name
= spec_die
->name
;
16138 /* Copy DW_AT_external attribute if it is set. */
16139 if (spec_die
->is_external
)
16140 part_die
->is_external
= spec_die
->is_external
;
16144 /* Set default names for some unnamed DIEs. */
16146 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
16147 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
16149 /* If there is no parent die to provide a namespace, and there are
16150 children, see if we can determine the namespace from their linkage
16152 if (cu
->language
== language_cplus
16153 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
16154 && part_die
->die_parent
== NULL
16155 && part_die
->has_children
16156 && (part_die
->tag
== DW_TAG_class_type
16157 || part_die
->tag
== DW_TAG_structure_type
16158 || part_die
->tag
== DW_TAG_union_type
))
16159 guess_partial_die_structure_name (part_die
, cu
);
16161 /* GCC might emit a nameless struct or union that has a linkage
16162 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
16163 if (part_die
->name
== NULL
16164 && (part_die
->tag
== DW_TAG_class_type
16165 || part_die
->tag
== DW_TAG_interface_type
16166 || part_die
->tag
== DW_TAG_structure_type
16167 || part_die
->tag
== DW_TAG_union_type
)
16168 && part_die
->linkage_name
!= NULL
)
16172 demangled
= gdb_demangle (part_die
->linkage_name
, DMGL_TYPES
);
16177 /* Strip any leading namespaces/classes, keep only the base name.
16178 DW_AT_name for named DIEs does not contain the prefixes. */
16179 base
= strrchr (demangled
, ':');
16180 if (base
&& base
> demangled
&& base
[-1] == ':')
16186 = obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
16187 base
, strlen (base
));
16192 part_die
->fixup_called
= 1;
16195 /* Read an attribute value described by an attribute form. */
16197 static const gdb_byte
*
16198 read_attribute_value (const struct die_reader_specs
*reader
,
16199 struct attribute
*attr
, unsigned form
,
16200 const gdb_byte
*info_ptr
)
16202 struct dwarf2_cu
*cu
= reader
->cu
;
16203 struct objfile
*objfile
= cu
->objfile
;
16204 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16205 bfd
*abfd
= reader
->abfd
;
16206 struct comp_unit_head
*cu_header
= &cu
->header
;
16207 unsigned int bytes_read
;
16208 struct dwarf_block
*blk
;
16210 attr
->form
= (enum dwarf_form
) form
;
16213 case DW_FORM_ref_addr
:
16214 if (cu
->header
.version
== 2)
16215 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
16217 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
16218 &cu
->header
, &bytes_read
);
16219 info_ptr
+= bytes_read
;
16221 case DW_FORM_GNU_ref_alt
:
16222 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
16223 info_ptr
+= bytes_read
;
16226 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
16227 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
16228 info_ptr
+= bytes_read
;
16230 case DW_FORM_block2
:
16231 blk
= dwarf_alloc_block (cu
);
16232 blk
->size
= read_2_bytes (abfd
, info_ptr
);
16234 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
16235 info_ptr
+= blk
->size
;
16236 DW_BLOCK (attr
) = blk
;
16238 case DW_FORM_block4
:
16239 blk
= dwarf_alloc_block (cu
);
16240 blk
->size
= read_4_bytes (abfd
, info_ptr
);
16242 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
16243 info_ptr
+= blk
->size
;
16244 DW_BLOCK (attr
) = blk
;
16246 case DW_FORM_data2
:
16247 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
16250 case DW_FORM_data4
:
16251 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
16254 case DW_FORM_data8
:
16255 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
16258 case DW_FORM_sec_offset
:
16259 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
16260 info_ptr
+= bytes_read
;
16262 case DW_FORM_string
:
16263 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
16264 DW_STRING_IS_CANONICAL (attr
) = 0;
16265 info_ptr
+= bytes_read
;
16268 if (!cu
->per_cu
->is_dwz
)
16270 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
16272 DW_STRING_IS_CANONICAL (attr
) = 0;
16273 info_ptr
+= bytes_read
;
16277 case DW_FORM_GNU_strp_alt
:
16279 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
16280 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
16283 DW_STRING (attr
) = read_indirect_string_from_dwz (dwz
, str_offset
);
16284 DW_STRING_IS_CANONICAL (attr
) = 0;
16285 info_ptr
+= bytes_read
;
16288 case DW_FORM_exprloc
:
16289 case DW_FORM_block
:
16290 blk
= dwarf_alloc_block (cu
);
16291 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
16292 info_ptr
+= bytes_read
;
16293 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
16294 info_ptr
+= blk
->size
;
16295 DW_BLOCK (attr
) = blk
;
16297 case DW_FORM_block1
:
16298 blk
= dwarf_alloc_block (cu
);
16299 blk
->size
= read_1_byte (abfd
, info_ptr
);
16301 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
16302 info_ptr
+= blk
->size
;
16303 DW_BLOCK (attr
) = blk
;
16305 case DW_FORM_data1
:
16306 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
16310 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
16313 case DW_FORM_flag_present
:
16314 DW_UNSND (attr
) = 1;
16316 case DW_FORM_sdata
:
16317 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
16318 info_ptr
+= bytes_read
;
16320 case DW_FORM_udata
:
16321 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
16322 info_ptr
+= bytes_read
;
16325 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
16326 + read_1_byte (abfd
, info_ptr
));
16330 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
16331 + read_2_bytes (abfd
, info_ptr
));
16335 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
16336 + read_4_bytes (abfd
, info_ptr
));
16340 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
16341 + read_8_bytes (abfd
, info_ptr
));
16344 case DW_FORM_ref_sig8
:
16345 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
16348 case DW_FORM_ref_udata
:
16349 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
16350 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
16351 info_ptr
+= bytes_read
;
16353 case DW_FORM_indirect
:
16354 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
16355 info_ptr
+= bytes_read
;
16356 info_ptr
= read_attribute_value (reader
, attr
, form
, info_ptr
);
16358 case DW_FORM_GNU_addr_index
:
16359 if (reader
->dwo_file
== NULL
)
16361 /* For now flag a hard error.
16362 Later we can turn this into a complaint. */
16363 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
16364 dwarf_form_name (form
),
16365 bfd_get_filename (abfd
));
16367 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
16368 info_ptr
+= bytes_read
;
16370 case DW_FORM_GNU_str_index
:
16371 if (reader
->dwo_file
== NULL
)
16373 /* For now flag a hard error.
16374 Later we can turn this into a complaint if warranted. */
16375 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
16376 dwarf_form_name (form
),
16377 bfd_get_filename (abfd
));
16380 ULONGEST str_index
=
16381 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
16383 DW_STRING (attr
) = read_str_index (reader
, str_index
);
16384 DW_STRING_IS_CANONICAL (attr
) = 0;
16385 info_ptr
+= bytes_read
;
16389 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
16390 dwarf_form_name (form
),
16391 bfd_get_filename (abfd
));
16395 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
16396 attr
->form
= DW_FORM_GNU_ref_alt
;
16398 /* We have seen instances where the compiler tried to emit a byte
16399 size attribute of -1 which ended up being encoded as an unsigned
16400 0xffffffff. Although 0xffffffff is technically a valid size value,
16401 an object of this size seems pretty unlikely so we can relatively
16402 safely treat these cases as if the size attribute was invalid and
16403 treat them as zero by default. */
16404 if (attr
->name
== DW_AT_byte_size
16405 && form
== DW_FORM_data4
16406 && DW_UNSND (attr
) >= 0xffffffff)
16409 (&symfile_complaints
,
16410 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
16411 hex_string (DW_UNSND (attr
)));
16412 DW_UNSND (attr
) = 0;
16418 /* Read an attribute described by an abbreviated attribute. */
16420 static const gdb_byte
*
16421 read_attribute (const struct die_reader_specs
*reader
,
16422 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
16423 const gdb_byte
*info_ptr
)
16425 attr
->name
= abbrev
->name
;
16426 return read_attribute_value (reader
, attr
, abbrev
->form
, info_ptr
);
16429 /* Read dwarf information from a buffer. */
16431 static unsigned int
16432 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
16434 return bfd_get_8 (abfd
, buf
);
16438 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
16440 return bfd_get_signed_8 (abfd
, buf
);
16443 static unsigned int
16444 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
16446 return bfd_get_16 (abfd
, buf
);
16450 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
16452 return bfd_get_signed_16 (abfd
, buf
);
16455 static unsigned int
16456 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
16458 return bfd_get_32 (abfd
, buf
);
16462 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
16464 return bfd_get_signed_32 (abfd
, buf
);
16468 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
16470 return bfd_get_64 (abfd
, buf
);
16474 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
16475 unsigned int *bytes_read
)
16477 struct comp_unit_head
*cu_header
= &cu
->header
;
16478 CORE_ADDR retval
= 0;
16480 if (cu_header
->signed_addr_p
)
16482 switch (cu_header
->addr_size
)
16485 retval
= bfd_get_signed_16 (abfd
, buf
);
16488 retval
= bfd_get_signed_32 (abfd
, buf
);
16491 retval
= bfd_get_signed_64 (abfd
, buf
);
16494 internal_error (__FILE__
, __LINE__
,
16495 _("read_address: bad switch, signed [in module %s]"),
16496 bfd_get_filename (abfd
));
16501 switch (cu_header
->addr_size
)
16504 retval
= bfd_get_16 (abfd
, buf
);
16507 retval
= bfd_get_32 (abfd
, buf
);
16510 retval
= bfd_get_64 (abfd
, buf
);
16513 internal_error (__FILE__
, __LINE__
,
16514 _("read_address: bad switch, "
16515 "unsigned [in module %s]"),
16516 bfd_get_filename (abfd
));
16520 *bytes_read
= cu_header
->addr_size
;
16524 /* Read the initial length from a section. The (draft) DWARF 3
16525 specification allows the initial length to take up either 4 bytes
16526 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
16527 bytes describe the length and all offsets will be 8 bytes in length
16530 An older, non-standard 64-bit format is also handled by this
16531 function. The older format in question stores the initial length
16532 as an 8-byte quantity without an escape value. Lengths greater
16533 than 2^32 aren't very common which means that the initial 4 bytes
16534 is almost always zero. Since a length value of zero doesn't make
16535 sense for the 32-bit format, this initial zero can be considered to
16536 be an escape value which indicates the presence of the older 64-bit
16537 format. As written, the code can't detect (old format) lengths
16538 greater than 4GB. If it becomes necessary to handle lengths
16539 somewhat larger than 4GB, we could allow other small values (such
16540 as the non-sensical values of 1, 2, and 3) to also be used as
16541 escape values indicating the presence of the old format.
16543 The value returned via bytes_read should be used to increment the
16544 relevant pointer after calling read_initial_length().
16546 [ Note: read_initial_length() and read_offset() are based on the
16547 document entitled "DWARF Debugging Information Format", revision
16548 3, draft 8, dated November 19, 2001. This document was obtained
16551 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
16553 This document is only a draft and is subject to change. (So beware.)
16555 Details regarding the older, non-standard 64-bit format were
16556 determined empirically by examining 64-bit ELF files produced by
16557 the SGI toolchain on an IRIX 6.5 machine.
16559 - Kevin, July 16, 2002
16563 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
16565 LONGEST length
= bfd_get_32 (abfd
, buf
);
16567 if (length
== 0xffffffff)
16569 length
= bfd_get_64 (abfd
, buf
+ 4);
16572 else if (length
== 0)
16574 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
16575 length
= bfd_get_64 (abfd
, buf
);
16586 /* Cover function for read_initial_length.
16587 Returns the length of the object at BUF, and stores the size of the
16588 initial length in *BYTES_READ and stores the size that offsets will be in
16590 If the initial length size is not equivalent to that specified in
16591 CU_HEADER then issue a complaint.
16592 This is useful when reading non-comp-unit headers. */
16595 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
16596 const struct comp_unit_head
*cu_header
,
16597 unsigned int *bytes_read
,
16598 unsigned int *offset_size
)
16600 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
16602 gdb_assert (cu_header
->initial_length_size
== 4
16603 || cu_header
->initial_length_size
== 8
16604 || cu_header
->initial_length_size
== 12);
16606 if (cu_header
->initial_length_size
!= *bytes_read
)
16607 complaint (&symfile_complaints
,
16608 _("intermixed 32-bit and 64-bit DWARF sections"));
16610 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
16614 /* Read an offset from the data stream. The size of the offset is
16615 given by cu_header->offset_size. */
16618 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
16619 const struct comp_unit_head
*cu_header
,
16620 unsigned int *bytes_read
)
16622 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
16624 *bytes_read
= cu_header
->offset_size
;
16628 /* Read an offset from the data stream. */
16631 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
16633 LONGEST retval
= 0;
16635 switch (offset_size
)
16638 retval
= bfd_get_32 (abfd
, buf
);
16641 retval
= bfd_get_64 (abfd
, buf
);
16644 internal_error (__FILE__
, __LINE__
,
16645 _("read_offset_1: bad switch [in module %s]"),
16646 bfd_get_filename (abfd
));
16652 static const gdb_byte
*
16653 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
16655 /* If the size of a host char is 8 bits, we can return a pointer
16656 to the buffer, otherwise we have to copy the data to a buffer
16657 allocated on the temporary obstack. */
16658 gdb_assert (HOST_CHAR_BIT
== 8);
16662 static const char *
16663 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
16664 unsigned int *bytes_read_ptr
)
16666 /* If the size of a host char is 8 bits, we can return a pointer
16667 to the string, otherwise we have to copy the string to a buffer
16668 allocated on the temporary obstack. */
16669 gdb_assert (HOST_CHAR_BIT
== 8);
16672 *bytes_read_ptr
= 1;
16675 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
16676 return (const char *) buf
;
16679 static const char *
16680 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
16682 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
16683 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
16684 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
16685 bfd_get_filename (abfd
));
16686 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
16687 error (_("DW_FORM_strp pointing outside of "
16688 ".debug_str section [in module %s]"),
16689 bfd_get_filename (abfd
));
16690 gdb_assert (HOST_CHAR_BIT
== 8);
16691 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
16693 return (const char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
16696 /* Read a string at offset STR_OFFSET in the .debug_str section from
16697 the .dwz file DWZ. Throw an error if the offset is too large. If
16698 the string consists of a single NUL byte, return NULL; otherwise
16699 return a pointer to the string. */
16701 static const char *
16702 read_indirect_string_from_dwz (struct dwz_file
*dwz
, LONGEST str_offset
)
16704 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwz
->str
);
16706 if (dwz
->str
.buffer
== NULL
)
16707 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
16708 "section [in module %s]"),
16709 bfd_get_filename (dwz
->dwz_bfd
));
16710 if (str_offset
>= dwz
->str
.size
)
16711 error (_("DW_FORM_GNU_strp_alt pointing outside of "
16712 ".debug_str section [in module %s]"),
16713 bfd_get_filename (dwz
->dwz_bfd
));
16714 gdb_assert (HOST_CHAR_BIT
== 8);
16715 if (dwz
->str
.buffer
[str_offset
] == '\0')
16717 return (const char *) (dwz
->str
.buffer
+ str_offset
);
16720 static const char *
16721 read_indirect_string (bfd
*abfd
, const gdb_byte
*buf
,
16722 const struct comp_unit_head
*cu_header
,
16723 unsigned int *bytes_read_ptr
)
16725 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
16727 return read_indirect_string_at_offset (abfd
, str_offset
);
16731 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
16732 unsigned int *bytes_read_ptr
)
16735 unsigned int num_read
;
16737 unsigned char byte
;
16745 byte
= bfd_get_8 (abfd
, buf
);
16748 result
|= ((ULONGEST
) (byte
& 127) << shift
);
16749 if ((byte
& 128) == 0)
16755 *bytes_read_ptr
= num_read
;
16760 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
16761 unsigned int *bytes_read_ptr
)
16764 int i
, shift
, num_read
;
16765 unsigned char byte
;
16773 byte
= bfd_get_8 (abfd
, buf
);
16776 result
|= ((LONGEST
) (byte
& 127) << shift
);
16778 if ((byte
& 128) == 0)
16783 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
16784 result
|= -(((LONGEST
) 1) << shift
);
16785 *bytes_read_ptr
= num_read
;
16789 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
16790 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
16791 ADDR_SIZE is the size of addresses from the CU header. */
16794 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
16796 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16797 bfd
*abfd
= objfile
->obfd
;
16798 const gdb_byte
*info_ptr
;
16800 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
16801 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
16802 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
16803 objfile_name (objfile
));
16804 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
16805 error (_("DW_FORM_addr_index pointing outside of "
16806 ".debug_addr section [in module %s]"),
16807 objfile_name (objfile
));
16808 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
16809 + addr_base
+ addr_index
* addr_size
);
16810 if (addr_size
== 4)
16811 return bfd_get_32 (abfd
, info_ptr
);
16813 return bfd_get_64 (abfd
, info_ptr
);
16816 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
16819 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
16821 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
16824 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
16827 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
16828 unsigned int *bytes_read
)
16830 bfd
*abfd
= cu
->objfile
->obfd
;
16831 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
16833 return read_addr_index (cu
, addr_index
);
16836 /* Data structure to pass results from dwarf2_read_addr_index_reader
16837 back to dwarf2_read_addr_index. */
16839 struct dwarf2_read_addr_index_data
16841 ULONGEST addr_base
;
16845 /* die_reader_func for dwarf2_read_addr_index. */
16848 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
16849 const gdb_byte
*info_ptr
,
16850 struct die_info
*comp_unit_die
,
16854 struct dwarf2_cu
*cu
= reader
->cu
;
16855 struct dwarf2_read_addr_index_data
*aidata
=
16856 (struct dwarf2_read_addr_index_data
*) data
;
16858 aidata
->addr_base
= cu
->addr_base
;
16859 aidata
->addr_size
= cu
->header
.addr_size
;
16862 /* Given an index in .debug_addr, fetch the value.
16863 NOTE: This can be called during dwarf expression evaluation,
16864 long after the debug information has been read, and thus per_cu->cu
16865 may no longer exist. */
16868 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
16869 unsigned int addr_index
)
16871 struct objfile
*objfile
= per_cu
->objfile
;
16872 struct dwarf2_cu
*cu
= per_cu
->cu
;
16873 ULONGEST addr_base
;
16876 /* This is intended to be called from outside this file. */
16877 dw2_setup (objfile
);
16879 /* We need addr_base and addr_size.
16880 If we don't have PER_CU->cu, we have to get it.
16881 Nasty, but the alternative is storing the needed info in PER_CU,
16882 which at this point doesn't seem justified: it's not clear how frequently
16883 it would get used and it would increase the size of every PER_CU.
16884 Entry points like dwarf2_per_cu_addr_size do a similar thing
16885 so we're not in uncharted territory here.
16886 Alas we need to be a bit more complicated as addr_base is contained
16889 We don't need to read the entire CU(/TU).
16890 We just need the header and top level die.
16892 IWBN to use the aging mechanism to let us lazily later discard the CU.
16893 For now we skip this optimization. */
16897 addr_base
= cu
->addr_base
;
16898 addr_size
= cu
->header
.addr_size
;
16902 struct dwarf2_read_addr_index_data aidata
;
16904 /* Note: We can't use init_cutu_and_read_dies_simple here,
16905 we need addr_base. */
16906 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
16907 dwarf2_read_addr_index_reader
, &aidata
);
16908 addr_base
= aidata
.addr_base
;
16909 addr_size
= aidata
.addr_size
;
16912 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
16915 /* Given a DW_FORM_GNU_str_index, fetch the string.
16916 This is only used by the Fission support. */
16918 static const char *
16919 read_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
16921 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16922 const char *objf_name
= objfile_name (objfile
);
16923 bfd
*abfd
= objfile
->obfd
;
16924 struct dwarf2_cu
*cu
= reader
->cu
;
16925 struct dwarf2_section_info
*str_section
= &reader
->dwo_file
->sections
.str
;
16926 struct dwarf2_section_info
*str_offsets_section
=
16927 &reader
->dwo_file
->sections
.str_offsets
;
16928 const gdb_byte
*info_ptr
;
16929 ULONGEST str_offset
;
16930 static const char form_name
[] = "DW_FORM_GNU_str_index";
16932 dwarf2_read_section (objfile
, str_section
);
16933 dwarf2_read_section (objfile
, str_offsets_section
);
16934 if (str_section
->buffer
== NULL
)
16935 error (_("%s used without .debug_str.dwo section"
16936 " in CU at offset 0x%lx [in module %s]"),
16937 form_name
, (long) cu
->header
.offset
.sect_off
, objf_name
);
16938 if (str_offsets_section
->buffer
== NULL
)
16939 error (_("%s used without .debug_str_offsets.dwo section"
16940 " in CU at offset 0x%lx [in module %s]"),
16941 form_name
, (long) cu
->header
.offset
.sect_off
, objf_name
);
16942 if (str_index
* cu
->header
.offset_size
>= str_offsets_section
->size
)
16943 error (_("%s pointing outside of .debug_str_offsets.dwo"
16944 " section in CU at offset 0x%lx [in module %s]"),
16945 form_name
, (long) cu
->header
.offset
.sect_off
, objf_name
);
16946 info_ptr
= (str_offsets_section
->buffer
16947 + str_index
* cu
->header
.offset_size
);
16948 if (cu
->header
.offset_size
== 4)
16949 str_offset
= bfd_get_32 (abfd
, info_ptr
);
16951 str_offset
= bfd_get_64 (abfd
, info_ptr
);
16952 if (str_offset
>= str_section
->size
)
16953 error (_("Offset from %s pointing outside of"
16954 " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"),
16955 form_name
, (long) cu
->header
.offset
.sect_off
, objf_name
);
16956 return (const char *) (str_section
->buffer
+ str_offset
);
16959 /* Return the length of an LEB128 number in BUF. */
16962 leb128_size (const gdb_byte
*buf
)
16964 const gdb_byte
*begin
= buf
;
16970 if ((byte
& 128) == 0)
16971 return buf
- begin
;
16976 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
16985 cu
->language
= language_c
;
16987 case DW_LANG_C_plus_plus
:
16988 case DW_LANG_C_plus_plus_11
:
16989 case DW_LANG_C_plus_plus_14
:
16990 cu
->language
= language_cplus
;
16993 cu
->language
= language_d
;
16995 case DW_LANG_Fortran77
:
16996 case DW_LANG_Fortran90
:
16997 case DW_LANG_Fortran95
:
16998 case DW_LANG_Fortran03
:
16999 case DW_LANG_Fortran08
:
17000 cu
->language
= language_fortran
;
17003 cu
->language
= language_go
;
17005 case DW_LANG_Mips_Assembler
:
17006 cu
->language
= language_asm
;
17009 cu
->language
= language_java
;
17011 case DW_LANG_Ada83
:
17012 case DW_LANG_Ada95
:
17013 cu
->language
= language_ada
;
17015 case DW_LANG_Modula2
:
17016 cu
->language
= language_m2
;
17018 case DW_LANG_Pascal83
:
17019 cu
->language
= language_pascal
;
17022 cu
->language
= language_objc
;
17024 case DW_LANG_Cobol74
:
17025 case DW_LANG_Cobol85
:
17027 cu
->language
= language_minimal
;
17030 cu
->language_defn
= language_def (cu
->language
);
17033 /* Return the named attribute or NULL if not there. */
17035 static struct attribute
*
17036 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
17041 struct attribute
*spec
= NULL
;
17043 for (i
= 0; i
< die
->num_attrs
; ++i
)
17045 if (die
->attrs
[i
].name
== name
)
17046 return &die
->attrs
[i
];
17047 if (die
->attrs
[i
].name
== DW_AT_specification
17048 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
17049 spec
= &die
->attrs
[i
];
17055 die
= follow_die_ref (die
, spec
, &cu
);
17061 /* Return the named attribute or NULL if not there,
17062 but do not follow DW_AT_specification, etc.
17063 This is for use in contexts where we're reading .debug_types dies.
17064 Following DW_AT_specification, DW_AT_abstract_origin will take us
17065 back up the chain, and we want to go down. */
17067 static struct attribute
*
17068 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
17072 for (i
= 0; i
< die
->num_attrs
; ++i
)
17073 if (die
->attrs
[i
].name
== name
)
17074 return &die
->attrs
[i
];
17079 /* Return the string associated with a string-typed attribute, or NULL if it
17080 is either not found or is of an incorrect type. */
17082 static const char *
17083 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
17085 struct attribute
*attr
;
17086 const char *str
= NULL
;
17088 attr
= dwarf2_attr (die
, name
, cu
);
17092 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_string
17093 || attr
->form
== DW_FORM_GNU_strp_alt
)
17094 str
= DW_STRING (attr
);
17096 complaint (&symfile_complaints
,
17097 _("string type expected for attribute %s for "
17098 "DIE at 0x%x in module %s"),
17099 dwarf_attr_name (name
), die
->offset
.sect_off
,
17100 objfile_name (cu
->objfile
));
17106 /* Return non-zero iff the attribute NAME is defined for the given DIE,
17107 and holds a non-zero value. This function should only be used for
17108 DW_FORM_flag or DW_FORM_flag_present attributes. */
17111 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
17113 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
17115 return (attr
&& DW_UNSND (attr
));
17119 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
17121 /* A DIE is a declaration if it has a DW_AT_declaration attribute
17122 which value is non-zero. However, we have to be careful with
17123 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
17124 (via dwarf2_flag_true_p) follows this attribute. So we may
17125 end up accidently finding a declaration attribute that belongs
17126 to a different DIE referenced by the specification attribute,
17127 even though the given DIE does not have a declaration attribute. */
17128 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
17129 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
17132 /* Return the die giving the specification for DIE, if there is
17133 one. *SPEC_CU is the CU containing DIE on input, and the CU
17134 containing the return value on output. If there is no
17135 specification, but there is an abstract origin, that is
17138 static struct die_info
*
17139 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
17141 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
17144 if (spec_attr
== NULL
)
17145 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
17147 if (spec_attr
== NULL
)
17150 return follow_die_ref (die
, spec_attr
, spec_cu
);
17153 /* Free the line_header structure *LH, and any arrays and strings it
17155 NOTE: This is also used as a "cleanup" function. */
17158 free_line_header (struct line_header
*lh
)
17160 if (lh
->standard_opcode_lengths
)
17161 xfree (lh
->standard_opcode_lengths
);
17163 /* Remember that all the lh->file_names[i].name pointers are
17164 pointers into debug_line_buffer, and don't need to be freed. */
17165 if (lh
->file_names
)
17166 xfree (lh
->file_names
);
17168 /* Similarly for the include directory names. */
17169 if (lh
->include_dirs
)
17170 xfree (lh
->include_dirs
);
17175 /* Stub for free_line_header to match void * callback types. */
17178 free_line_header_voidp (void *arg
)
17180 struct line_header
*lh
= arg
;
17182 free_line_header (lh
);
17185 /* Add an entry to LH's include directory table. */
17188 add_include_dir (struct line_header
*lh
, const char *include_dir
)
17190 if (dwarf_line_debug
>= 2)
17191 fprintf_unfiltered (gdb_stdlog
, "Adding dir %u: %s\n",
17192 lh
->num_include_dirs
+ 1, include_dir
);
17194 /* Grow the array if necessary. */
17195 if (lh
->include_dirs_size
== 0)
17197 lh
->include_dirs_size
= 1; /* for testing */
17198 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
17199 * sizeof (*lh
->include_dirs
));
17201 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
17203 lh
->include_dirs_size
*= 2;
17204 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
17205 (lh
->include_dirs_size
17206 * sizeof (*lh
->include_dirs
)));
17209 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
17212 /* Add an entry to LH's file name table. */
17215 add_file_name (struct line_header
*lh
,
17217 unsigned int dir_index
,
17218 unsigned int mod_time
,
17219 unsigned int length
)
17221 struct file_entry
*fe
;
17223 if (dwarf_line_debug
>= 2)
17224 fprintf_unfiltered (gdb_stdlog
, "Adding file %u: %s\n",
17225 lh
->num_file_names
+ 1, name
);
17227 /* Grow the array if necessary. */
17228 if (lh
->file_names_size
== 0)
17230 lh
->file_names_size
= 1; /* for testing */
17231 lh
->file_names
= xmalloc (lh
->file_names_size
17232 * sizeof (*lh
->file_names
));
17234 else if (lh
->num_file_names
>= lh
->file_names_size
)
17236 lh
->file_names_size
*= 2;
17237 lh
->file_names
= xrealloc (lh
->file_names
,
17238 (lh
->file_names_size
17239 * sizeof (*lh
->file_names
)));
17242 fe
= &lh
->file_names
[lh
->num_file_names
++];
17244 fe
->dir_index
= dir_index
;
17245 fe
->mod_time
= mod_time
;
17246 fe
->length
= length
;
17247 fe
->included_p
= 0;
17251 /* A convenience function to find the proper .debug_line section for a CU. */
17253 static struct dwarf2_section_info
*
17254 get_debug_line_section (struct dwarf2_cu
*cu
)
17256 struct dwarf2_section_info
*section
;
17258 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
17260 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
17261 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
17262 else if (cu
->per_cu
->is_dwz
)
17264 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
17266 section
= &dwz
->line
;
17269 section
= &dwarf2_per_objfile
->line
;
17274 /* Read the statement program header starting at OFFSET in
17275 .debug_line, or .debug_line.dwo. Return a pointer
17276 to a struct line_header, allocated using xmalloc.
17277 Returns NULL if there is a problem reading the header, e.g., if it
17278 has a version we don't understand.
17280 NOTE: the strings in the include directory and file name tables of
17281 the returned object point into the dwarf line section buffer,
17282 and must not be freed. */
17284 static struct line_header
*
17285 dwarf_decode_line_header (unsigned int offset
, struct dwarf2_cu
*cu
)
17287 struct cleanup
*back_to
;
17288 struct line_header
*lh
;
17289 const gdb_byte
*line_ptr
;
17290 unsigned int bytes_read
, offset_size
;
17292 const char *cur_dir
, *cur_file
;
17293 struct dwarf2_section_info
*section
;
17296 section
= get_debug_line_section (cu
);
17297 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
17298 if (section
->buffer
== NULL
)
17300 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
17301 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
17303 complaint (&symfile_complaints
, _("missing .debug_line section"));
17307 /* We can't do this until we know the section is non-empty.
17308 Only then do we know we have such a section. */
17309 abfd
= get_section_bfd_owner (section
);
17311 /* Make sure that at least there's room for the total_length field.
17312 That could be 12 bytes long, but we're just going to fudge that. */
17313 if (offset
+ 4 >= section
->size
)
17315 dwarf2_statement_list_fits_in_line_number_section_complaint ();
17319 lh
= xmalloc (sizeof (*lh
));
17320 memset (lh
, 0, sizeof (*lh
));
17321 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
17324 lh
->offset
.sect_off
= offset
;
17325 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
17327 line_ptr
= section
->buffer
+ offset
;
17329 /* Read in the header. */
17331 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
17332 &bytes_read
, &offset_size
);
17333 line_ptr
+= bytes_read
;
17334 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
17336 dwarf2_statement_list_fits_in_line_number_section_complaint ();
17337 do_cleanups (back_to
);
17340 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
17341 lh
->version
= read_2_bytes (abfd
, line_ptr
);
17343 if (lh
->version
> 4)
17345 /* This is a version we don't understand. The format could have
17346 changed in ways we don't handle properly so just punt. */
17347 complaint (&symfile_complaints
,
17348 _("unsupported version in .debug_line section"));
17351 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
17352 line_ptr
+= offset_size
;
17353 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
17355 if (lh
->version
>= 4)
17357 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
17361 lh
->maximum_ops_per_instruction
= 1;
17363 if (lh
->maximum_ops_per_instruction
== 0)
17365 lh
->maximum_ops_per_instruction
= 1;
17366 complaint (&symfile_complaints
,
17367 _("invalid maximum_ops_per_instruction "
17368 "in `.debug_line' section"));
17371 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
17373 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
17375 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
17377 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
17379 lh
->standard_opcode_lengths
17380 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
17382 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
17383 for (i
= 1; i
< lh
->opcode_base
; ++i
)
17385 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
17389 /* Read directory table. */
17390 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
17392 line_ptr
+= bytes_read
;
17393 add_include_dir (lh
, cur_dir
);
17395 line_ptr
+= bytes_read
;
17397 /* Read file name table. */
17398 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
17400 unsigned int dir_index
, mod_time
, length
;
17402 line_ptr
+= bytes_read
;
17403 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
17404 line_ptr
+= bytes_read
;
17405 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
17406 line_ptr
+= bytes_read
;
17407 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
17408 line_ptr
+= bytes_read
;
17410 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
17412 line_ptr
+= bytes_read
;
17413 lh
->statement_program_start
= line_ptr
;
17415 if (line_ptr
> (section
->buffer
+ section
->size
))
17416 complaint (&symfile_complaints
,
17417 _("line number info header doesn't "
17418 "fit in `.debug_line' section"));
17420 discard_cleanups (back_to
);
17424 /* Subroutine of dwarf_decode_lines to simplify it.
17425 Return the file name of the psymtab for included file FILE_INDEX
17426 in line header LH of PST.
17427 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
17428 If space for the result is malloc'd, it will be freed by a cleanup.
17429 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename.
17431 The function creates dangling cleanup registration. */
17433 static const char *
17434 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
17435 const struct partial_symtab
*pst
,
17436 const char *comp_dir
)
17438 const struct file_entry fe
= lh
->file_names
[file_index
];
17439 const char *include_name
= fe
.name
;
17440 const char *include_name_to_compare
= include_name
;
17441 const char *dir_name
= NULL
;
17442 const char *pst_filename
;
17443 char *copied_name
= NULL
;
17446 if (fe
.dir_index
&& lh
->include_dirs
!= NULL
)
17447 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
17449 if (!IS_ABSOLUTE_PATH (include_name
)
17450 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
17452 /* Avoid creating a duplicate psymtab for PST.
17453 We do this by comparing INCLUDE_NAME and PST_FILENAME.
17454 Before we do the comparison, however, we need to account
17455 for DIR_NAME and COMP_DIR.
17456 First prepend dir_name (if non-NULL). If we still don't
17457 have an absolute path prepend comp_dir (if non-NULL).
17458 However, the directory we record in the include-file's
17459 psymtab does not contain COMP_DIR (to match the
17460 corresponding symtab(s)).
17465 bash$ gcc -g ./hello.c
17466 include_name = "hello.c"
17468 DW_AT_comp_dir = comp_dir = "/tmp"
17469 DW_AT_name = "./hello.c"
17473 if (dir_name
!= NULL
)
17475 char *tem
= concat (dir_name
, SLASH_STRING
,
17476 include_name
, (char *)NULL
);
17478 make_cleanup (xfree
, tem
);
17479 include_name
= tem
;
17480 include_name_to_compare
= include_name
;
17482 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
17484 char *tem
= concat (comp_dir
, SLASH_STRING
,
17485 include_name
, (char *)NULL
);
17487 make_cleanup (xfree
, tem
);
17488 include_name_to_compare
= tem
;
17492 pst_filename
= pst
->filename
;
17493 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
17495 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
17496 pst_filename
, (char *)NULL
);
17497 pst_filename
= copied_name
;
17500 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
17502 if (copied_name
!= NULL
)
17503 xfree (copied_name
);
17507 return include_name
;
17510 /* State machine to track the state of the line number program. */
17514 /* These are part of the standard DWARF line number state machine. */
17516 unsigned char op_index
;
17521 unsigned int discriminator
;
17523 /* Additional bits of state we need to track. */
17525 /* The last file that we called dwarf2_start_subfile for.
17526 This is only used for TLLs. */
17527 unsigned int last_file
;
17528 /* The last file a line number was recorded for. */
17529 struct subfile
*last_subfile
;
17531 /* The function to call to record a line. */
17532 record_line_ftype
*record_line
;
17534 /* The last line number that was recorded, used to coalesce
17535 consecutive entries for the same line. This can happen, for
17536 example, when discriminators are present. PR 17276. */
17537 unsigned int last_line
;
17538 int line_has_non_zero_discriminator
;
17539 } lnp_state_machine
;
17541 /* There's a lot of static state to pass to dwarf_record_line.
17542 This keeps it all together. */
17547 struct gdbarch
*gdbarch
;
17549 /* The line number header. */
17550 struct line_header
*line_header
;
17552 /* Non-zero if we're recording lines.
17553 Otherwise we're building partial symtabs and are just interested in
17554 finding include files mentioned by the line number program. */
17555 int record_lines_p
;
17556 } lnp_reader_state
;
17558 /* Ignore this record_line request. */
17561 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
17566 /* Return non-zero if we should add LINE to the line number table.
17567 LINE is the line to add, LAST_LINE is the last line that was added,
17568 LAST_SUBFILE is the subfile for LAST_LINE.
17569 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
17570 had a non-zero discriminator.
17572 We have to be careful in the presence of discriminators.
17573 E.g., for this line:
17575 for (i = 0; i < 100000; i++);
17577 clang can emit four line number entries for that one line,
17578 each with a different discriminator.
17579 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
17581 However, we want gdb to coalesce all four entries into one.
17582 Otherwise the user could stepi into the middle of the line and
17583 gdb would get confused about whether the pc really was in the
17584 middle of the line.
17586 Things are further complicated by the fact that two consecutive
17587 line number entries for the same line is a heuristic used by gcc
17588 to denote the end of the prologue. So we can't just discard duplicate
17589 entries, we have to be selective about it. The heuristic we use is
17590 that we only collapse consecutive entries for the same line if at least
17591 one of those entries has a non-zero discriminator. PR 17276.
17593 Note: Addresses in the line number state machine can never go backwards
17594 within one sequence, thus this coalescing is ok. */
17597 dwarf_record_line_p (unsigned int line
, unsigned int last_line
,
17598 int line_has_non_zero_discriminator
,
17599 struct subfile
*last_subfile
)
17601 if (current_subfile
!= last_subfile
)
17603 if (line
!= last_line
)
17605 /* Same line for the same file that we've seen already.
17606 As a last check, for pr 17276, only record the line if the line
17607 has never had a non-zero discriminator. */
17608 if (!line_has_non_zero_discriminator
)
17613 /* Use P_RECORD_LINE to record line number LINE beginning at address ADDRESS
17614 in the line table of subfile SUBFILE. */
17617 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
17618 unsigned int line
, CORE_ADDR address
,
17619 record_line_ftype p_record_line
)
17621 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
17623 if (dwarf_line_debug
)
17625 fprintf_unfiltered (gdb_stdlog
,
17626 "Recording line %u, file %s, address %s\n",
17627 line
, lbasename (subfile
->name
),
17628 paddress (gdbarch
, address
));
17631 (*p_record_line
) (subfile
, line
, addr
);
17634 /* Subroutine of dwarf_decode_lines_1 to simplify it.
17635 Mark the end of a set of line number records.
17636 The arguments are the same as for dwarf_record_line_1.
17637 If SUBFILE is NULL the request is ignored. */
17640 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
17641 CORE_ADDR address
, record_line_ftype p_record_line
)
17643 if (subfile
== NULL
)
17646 if (dwarf_line_debug
)
17648 fprintf_unfiltered (gdb_stdlog
,
17649 "Finishing current line, file %s, address %s\n",
17650 lbasename (subfile
->name
),
17651 paddress (gdbarch
, address
));
17654 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, p_record_line
);
17657 /* Record the line in STATE.
17658 END_SEQUENCE is non-zero if we're processing the end of a sequence. */
17661 dwarf_record_line (lnp_reader_state
*reader
, lnp_state_machine
*state
,
17664 const struct line_header
*lh
= reader
->line_header
;
17665 unsigned int file
, line
, discriminator
;
17668 file
= state
->file
;
17669 line
= state
->line
;
17670 is_stmt
= state
->is_stmt
;
17671 discriminator
= state
->discriminator
;
17673 if (dwarf_line_debug
)
17675 fprintf_unfiltered (gdb_stdlog
,
17676 "Processing actual line %u: file %u,"
17677 " address %s, is_stmt %u, discrim %u\n",
17679 paddress (reader
->gdbarch
, state
->address
),
17680 is_stmt
, discriminator
);
17683 if (file
== 0 || file
- 1 >= lh
->num_file_names
)
17684 dwarf2_debug_line_missing_file_complaint ();
17685 /* For now we ignore lines not starting on an instruction boundary.
17686 But not when processing end_sequence for compatibility with the
17687 previous version of the code. */
17688 else if (state
->op_index
== 0 || end_sequence
)
17690 lh
->file_names
[file
- 1].included_p
= 1;
17691 if (reader
->record_lines_p
&& is_stmt
)
17693 if (state
->last_subfile
!= current_subfile
|| end_sequence
)
17695 dwarf_finish_line (reader
->gdbarch
, state
->last_subfile
,
17696 state
->address
, state
->record_line
);
17701 if (dwarf_record_line_p (line
, state
->last_line
,
17702 state
->line_has_non_zero_discriminator
,
17703 state
->last_subfile
))
17705 dwarf_record_line_1 (reader
->gdbarch
, current_subfile
,
17706 line
, state
->address
,
17707 state
->record_line
);
17709 state
->last_subfile
= current_subfile
;
17710 state
->last_line
= line
;
17716 /* Initialize STATE for the start of a line number program. */
17719 init_lnp_state_machine (lnp_state_machine
*state
,
17720 const lnp_reader_state
*reader
)
17722 memset (state
, 0, sizeof (*state
));
17724 /* Just starting, there is no "last file". */
17725 state
->last_file
= 0;
17726 state
->last_subfile
= NULL
;
17728 state
->record_line
= record_line
;
17730 state
->last_line
= 0;
17731 state
->line_has_non_zero_discriminator
= 0;
17733 /* Initialize these according to the DWARF spec. */
17734 state
->op_index
= 0;
17737 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
17738 was a line entry for it so that the backend has a chance to adjust it
17739 and also record it in case it needs it. This is currently used by MIPS
17740 code, cf. `mips_adjust_dwarf2_line'. */
17741 state
->address
= gdbarch_adjust_dwarf2_line (reader
->gdbarch
, 0, 0);
17742 state
->is_stmt
= reader
->line_header
->default_is_stmt
;
17743 state
->discriminator
= 0;
17746 /* Check address and if invalid nop-out the rest of the lines in this
17750 check_line_address (struct dwarf2_cu
*cu
, lnp_state_machine
*state
,
17751 const gdb_byte
*line_ptr
,
17752 CORE_ADDR lowpc
, CORE_ADDR address
)
17754 /* If address < lowpc then it's not a usable value, it's outside the
17755 pc range of the CU. However, we restrict the test to only address
17756 values of zero to preserve GDB's previous behaviour which is to
17757 handle the specific case of a function being GC'd by the linker. */
17759 if (address
== 0 && address
< lowpc
)
17761 /* This line table is for a function which has been
17762 GCd by the linker. Ignore it. PR gdb/12528 */
17764 struct objfile
*objfile
= cu
->objfile
;
17765 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
17767 complaint (&symfile_complaints
,
17768 _(".debug_line address at offset 0x%lx is 0 [in module %s]"),
17769 line_offset
, objfile_name (objfile
));
17770 state
->record_line
= noop_record_line
;
17771 /* Note: sm.record_line is left as noop_record_line
17772 until we see DW_LNE_end_sequence. */
17776 /* Subroutine of dwarf_decode_lines to simplify it.
17777 Process the line number information in LH.
17778 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
17779 program in order to set included_p for every referenced header. */
17782 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
17783 const int decode_for_pst_p
, CORE_ADDR lowpc
)
17785 const gdb_byte
*line_ptr
, *extended_end
;
17786 const gdb_byte
*line_end
;
17787 unsigned int bytes_read
, extended_len
;
17788 unsigned char op_code
, extended_op
;
17789 CORE_ADDR baseaddr
;
17790 struct objfile
*objfile
= cu
->objfile
;
17791 bfd
*abfd
= objfile
->obfd
;
17792 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17793 /* Non-zero if we're recording line info (as opposed to building partial
17795 int record_lines_p
= !decode_for_pst_p
;
17796 /* A collection of things we need to pass to dwarf_record_line. */
17797 lnp_reader_state reader_state
;
17799 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
17801 line_ptr
= lh
->statement_program_start
;
17802 line_end
= lh
->statement_program_end
;
17804 reader_state
.gdbarch
= gdbarch
;
17805 reader_state
.line_header
= lh
;
17806 reader_state
.record_lines_p
= record_lines_p
;
17808 /* Read the statement sequences until there's nothing left. */
17809 while (line_ptr
< line_end
)
17811 /* The DWARF line number program state machine. */
17812 lnp_state_machine state_machine
;
17813 int end_sequence
= 0;
17815 /* Reset the state machine at the start of each sequence. */
17816 init_lnp_state_machine (&state_machine
, &reader_state
);
17818 if (record_lines_p
&& lh
->num_file_names
>= state_machine
.file
)
17820 /* Start a subfile for the current file of the state machine. */
17821 /* lh->include_dirs and lh->file_names are 0-based, but the
17822 directory and file name numbers in the statement program
17824 struct file_entry
*fe
= &lh
->file_names
[state_machine
.file
- 1];
17825 const char *dir
= NULL
;
17827 if (fe
->dir_index
&& lh
->include_dirs
!= NULL
)
17828 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
17830 dwarf2_start_subfile (fe
->name
, dir
);
17833 /* Decode the table. */
17834 while (line_ptr
< line_end
&& !end_sequence
)
17836 op_code
= read_1_byte (abfd
, line_ptr
);
17839 if (op_code
>= lh
->opcode_base
)
17841 /* Special opcode. */
17842 unsigned char adj_opcode
;
17843 CORE_ADDR addr_adj
;
17846 adj_opcode
= op_code
- lh
->opcode_base
;
17847 addr_adj
= (((state_machine
.op_index
17848 + (adj_opcode
/ lh
->line_range
))
17849 / lh
->maximum_ops_per_instruction
)
17850 * lh
->minimum_instruction_length
);
17851 state_machine
.address
17852 += gdbarch_adjust_dwarf2_line (gdbarch
, addr_adj
, 1);
17853 state_machine
.op_index
= ((state_machine
.op_index
17854 + (adj_opcode
/ lh
->line_range
))
17855 % lh
->maximum_ops_per_instruction
);
17856 line_delta
= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
17857 state_machine
.line
+= line_delta
;
17858 if (line_delta
!= 0)
17859 state_machine
.line_has_non_zero_discriminator
17860 = state_machine
.discriminator
!= 0;
17862 dwarf_record_line (&reader_state
, &state_machine
, 0);
17863 state_machine
.discriminator
= 0;
17865 else switch (op_code
)
17867 case DW_LNS_extended_op
:
17868 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
17870 line_ptr
+= bytes_read
;
17871 extended_end
= line_ptr
+ extended_len
;
17872 extended_op
= read_1_byte (abfd
, line_ptr
);
17874 switch (extended_op
)
17876 case DW_LNE_end_sequence
:
17877 state_machine
.record_line
= record_line
;
17880 case DW_LNE_set_address
:
17883 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
17885 line_ptr
+= bytes_read
;
17886 check_line_address (cu
, &state_machine
, line_ptr
,
17888 state_machine
.op_index
= 0;
17889 address
+= baseaddr
;
17890 state_machine
.address
17891 = gdbarch_adjust_dwarf2_line (gdbarch
, address
, 0);
17894 case DW_LNE_define_file
:
17896 const char *cur_file
;
17897 unsigned int dir_index
, mod_time
, length
;
17899 cur_file
= read_direct_string (abfd
, line_ptr
,
17901 line_ptr
+= bytes_read
;
17903 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
17904 line_ptr
+= bytes_read
;
17906 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
17907 line_ptr
+= bytes_read
;
17909 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
17910 line_ptr
+= bytes_read
;
17911 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
17914 case DW_LNE_set_discriminator
:
17915 /* The discriminator is not interesting to the debugger;
17916 just ignore it. We still need to check its value though:
17917 if there are consecutive entries for the same
17918 (non-prologue) line we want to coalesce them.
17920 state_machine
.discriminator
17921 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
17922 state_machine
.line_has_non_zero_discriminator
17923 |= state_machine
.discriminator
!= 0;
17924 line_ptr
+= bytes_read
;
17927 complaint (&symfile_complaints
,
17928 _("mangled .debug_line section"));
17931 /* Make sure that we parsed the extended op correctly. If e.g.
17932 we expected a different address size than the producer used,
17933 we may have read the wrong number of bytes. */
17934 if (line_ptr
!= extended_end
)
17936 complaint (&symfile_complaints
,
17937 _("mangled .debug_line section"));
17942 dwarf_record_line (&reader_state
, &state_machine
, 0);
17943 state_machine
.discriminator
= 0;
17945 case DW_LNS_advance_pc
:
17948 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
17949 CORE_ADDR addr_adj
;
17951 addr_adj
= (((state_machine
.op_index
+ adjust
)
17952 / lh
->maximum_ops_per_instruction
)
17953 * lh
->minimum_instruction_length
);
17954 state_machine
.address
17955 += gdbarch_adjust_dwarf2_line (gdbarch
, addr_adj
, 1);
17956 state_machine
.op_index
= ((state_machine
.op_index
+ adjust
)
17957 % lh
->maximum_ops_per_instruction
);
17958 line_ptr
+= bytes_read
;
17961 case DW_LNS_advance_line
:
17964 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
17966 state_machine
.line
+= line_delta
;
17967 if (line_delta
!= 0)
17968 state_machine
.line_has_non_zero_discriminator
17969 = state_machine
.discriminator
!= 0;
17970 line_ptr
+= bytes_read
;
17973 case DW_LNS_set_file
:
17975 /* The arrays lh->include_dirs and lh->file_names are
17976 0-based, but the directory and file name numbers in
17977 the statement program are 1-based. */
17978 struct file_entry
*fe
;
17979 const char *dir
= NULL
;
17981 state_machine
.file
= read_unsigned_leb128 (abfd
, line_ptr
,
17983 line_ptr
+= bytes_read
;
17984 if (state_machine
.file
== 0
17985 || state_machine
.file
- 1 >= lh
->num_file_names
)
17986 dwarf2_debug_line_missing_file_complaint ();
17989 fe
= &lh
->file_names
[state_machine
.file
- 1];
17990 if (fe
->dir_index
&& lh
->include_dirs
!= NULL
)
17991 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
17992 if (record_lines_p
)
17994 state_machine
.last_subfile
= current_subfile
;
17995 state_machine
.line_has_non_zero_discriminator
17996 = state_machine
.discriminator
!= 0;
17997 dwarf2_start_subfile (fe
->name
, dir
);
18002 case DW_LNS_set_column
:
18003 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18004 line_ptr
+= bytes_read
;
18006 case DW_LNS_negate_stmt
:
18007 state_machine
.is_stmt
= (!state_machine
.is_stmt
);
18009 case DW_LNS_set_basic_block
:
18011 /* Add to the address register of the state machine the
18012 address increment value corresponding to special opcode
18013 255. I.e., this value is scaled by the minimum
18014 instruction length since special opcode 255 would have
18015 scaled the increment. */
18016 case DW_LNS_const_add_pc
:
18018 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
18019 CORE_ADDR addr_adj
;
18021 addr_adj
= (((state_machine
.op_index
+ adjust
)
18022 / lh
->maximum_ops_per_instruction
)
18023 * lh
->minimum_instruction_length
);
18024 state_machine
.address
18025 += gdbarch_adjust_dwarf2_line (gdbarch
, addr_adj
, 1);
18026 state_machine
.op_index
= ((state_machine
.op_index
+ adjust
)
18027 % lh
->maximum_ops_per_instruction
);
18030 case DW_LNS_fixed_advance_pc
:
18032 CORE_ADDR addr_adj
;
18034 addr_adj
= read_2_bytes (abfd
, line_ptr
);
18035 state_machine
.address
18036 += gdbarch_adjust_dwarf2_line (gdbarch
, addr_adj
, 1);
18037 state_machine
.op_index
= 0;
18043 /* Unknown standard opcode, ignore it. */
18046 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
18048 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18049 line_ptr
+= bytes_read
;
18056 dwarf2_debug_line_missing_end_sequence_complaint ();
18058 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
18059 in which case we still finish recording the last line). */
18060 dwarf_record_line (&reader_state
, &state_machine
, 1);
18064 /* Decode the Line Number Program (LNP) for the given line_header
18065 structure and CU. The actual information extracted and the type
18066 of structures created from the LNP depends on the value of PST.
18068 1. If PST is NULL, then this procedure uses the data from the program
18069 to create all necessary symbol tables, and their linetables.
18071 2. If PST is not NULL, this procedure reads the program to determine
18072 the list of files included by the unit represented by PST, and
18073 builds all the associated partial symbol tables.
18075 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
18076 It is used for relative paths in the line table.
18077 NOTE: When processing partial symtabs (pst != NULL),
18078 comp_dir == pst->dirname.
18080 NOTE: It is important that psymtabs have the same file name (via strcmp)
18081 as the corresponding symtab. Since COMP_DIR is not used in the name of the
18082 symtab we don't use it in the name of the psymtabs we create.
18083 E.g. expand_line_sal requires this when finding psymtabs to expand.
18084 A good testcase for this is mb-inline.exp.
18086 LOWPC is the lowest address in CU (or 0 if not known).
18088 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
18089 for its PC<->lines mapping information. Otherwise only the filename
18090 table is read in. */
18093 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
18094 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
18095 CORE_ADDR lowpc
, int decode_mapping
)
18097 struct objfile
*objfile
= cu
->objfile
;
18098 const int decode_for_pst_p
= (pst
!= NULL
);
18100 if (decode_mapping
)
18101 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
18103 if (decode_for_pst_p
)
18107 /* Now that we're done scanning the Line Header Program, we can
18108 create the psymtab of each included file. */
18109 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
18110 if (lh
->file_names
[file_index
].included_p
== 1)
18112 const char *include_name
=
18113 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
18114 if (include_name
!= NULL
)
18115 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
18120 /* Make sure a symtab is created for every file, even files
18121 which contain only variables (i.e. no code with associated
18123 struct compunit_symtab
*cust
= buildsym_compunit_symtab ();
18126 for (i
= 0; i
< lh
->num_file_names
; i
++)
18128 const char *dir
= NULL
;
18129 struct file_entry
*fe
;
18131 fe
= &lh
->file_names
[i
];
18132 if (fe
->dir_index
&& lh
->include_dirs
!= NULL
)
18133 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
18134 dwarf2_start_subfile (fe
->name
, dir
);
18136 if (current_subfile
->symtab
== NULL
)
18138 current_subfile
->symtab
18139 = allocate_symtab (cust
, current_subfile
->name
);
18141 fe
->symtab
= current_subfile
->symtab
;
18146 /* Start a subfile for DWARF. FILENAME is the name of the file and
18147 DIRNAME the name of the source directory which contains FILENAME
18148 or NULL if not known.
18149 This routine tries to keep line numbers from identical absolute and
18150 relative file names in a common subfile.
18152 Using the `list' example from the GDB testsuite, which resides in
18153 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
18154 of /srcdir/list0.c yields the following debugging information for list0.c:
18156 DW_AT_name: /srcdir/list0.c
18157 DW_AT_comp_dir: /compdir
18158 files.files[0].name: list0.h
18159 files.files[0].dir: /srcdir
18160 files.files[1].name: list0.c
18161 files.files[1].dir: /srcdir
18163 The line number information for list0.c has to end up in a single
18164 subfile, so that `break /srcdir/list0.c:1' works as expected.
18165 start_subfile will ensure that this happens provided that we pass the
18166 concatenation of files.files[1].dir and files.files[1].name as the
18170 dwarf2_start_subfile (const char *filename
, const char *dirname
)
18174 /* In order not to lose the line information directory,
18175 we concatenate it to the filename when it makes sense.
18176 Note that the Dwarf3 standard says (speaking of filenames in line
18177 information): ``The directory index is ignored for file names
18178 that represent full path names''. Thus ignoring dirname in the
18179 `else' branch below isn't an issue. */
18181 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
18183 copy
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
18187 start_subfile (filename
);
18193 /* Start a symtab for DWARF.
18194 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
18196 static struct compunit_symtab
*
18197 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
18198 const char *name
, const char *comp_dir
, CORE_ADDR low_pc
)
18200 struct compunit_symtab
*cust
18201 = start_symtab (cu
->objfile
, name
, comp_dir
, low_pc
);
18203 record_debugformat ("DWARF 2");
18204 record_producer (cu
->producer
);
18206 /* We assume that we're processing GCC output. */
18207 processing_gcc_compilation
= 2;
18209 cu
->processing_has_namespace_info
= 0;
18215 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
18216 struct dwarf2_cu
*cu
)
18218 struct objfile
*objfile
= cu
->objfile
;
18219 struct comp_unit_head
*cu_header
= &cu
->header
;
18221 /* NOTE drow/2003-01-30: There used to be a comment and some special
18222 code here to turn a symbol with DW_AT_external and a
18223 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
18224 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
18225 with some versions of binutils) where shared libraries could have
18226 relocations against symbols in their debug information - the
18227 minimal symbol would have the right address, but the debug info
18228 would not. It's no longer necessary, because we will explicitly
18229 apply relocations when we read in the debug information now. */
18231 /* A DW_AT_location attribute with no contents indicates that a
18232 variable has been optimized away. */
18233 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
18235 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
18239 /* Handle one degenerate form of location expression specially, to
18240 preserve GDB's previous behavior when section offsets are
18241 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
18242 then mark this symbol as LOC_STATIC. */
18244 if (attr_form_is_block (attr
)
18245 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
18246 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
18247 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
18248 && (DW_BLOCK (attr
)->size
18249 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
18251 unsigned int dummy
;
18253 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
18254 SYMBOL_VALUE_ADDRESS (sym
) =
18255 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
18257 SYMBOL_VALUE_ADDRESS (sym
) =
18258 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
18259 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
18260 fixup_symbol_section (sym
, objfile
);
18261 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
18262 SYMBOL_SECTION (sym
));
18266 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
18267 expression evaluator, and use LOC_COMPUTED only when necessary
18268 (i.e. when the value of a register or memory location is
18269 referenced, or a thread-local block, etc.). Then again, it might
18270 not be worthwhile. I'm assuming that it isn't unless performance
18271 or memory numbers show me otherwise. */
18273 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
18275 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
18276 cu
->has_loclist
= 1;
18279 /* Given a pointer to a DWARF information entry, figure out if we need
18280 to make a symbol table entry for it, and if so, create a new entry
18281 and return a pointer to it.
18282 If TYPE is NULL, determine symbol type from the die, otherwise
18283 used the passed type.
18284 If SPACE is not NULL, use it to hold the new symbol. If it is
18285 NULL, allocate a new symbol on the objfile's obstack. */
18287 static struct symbol
*
18288 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
18289 struct symbol
*space
)
18291 struct objfile
*objfile
= cu
->objfile
;
18292 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18293 struct symbol
*sym
= NULL
;
18295 struct attribute
*attr
= NULL
;
18296 struct attribute
*attr2
= NULL
;
18297 CORE_ADDR baseaddr
;
18298 struct pending
**list_to_add
= NULL
;
18300 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
18302 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
18304 name
= dwarf2_name (die
, cu
);
18307 const char *linkagename
;
18308 int suppress_add
= 0;
18313 sym
= allocate_symbol (objfile
);
18314 OBJSTAT (objfile
, n_syms
++);
18316 /* Cache this symbol's name and the name's demangled form (if any). */
18317 SYMBOL_SET_LANGUAGE (sym
, cu
->language
, &objfile
->objfile_obstack
);
18318 linkagename
= dwarf2_physname (name
, die
, cu
);
18319 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
18321 /* Fortran does not have mangling standard and the mangling does differ
18322 between gfortran, iFort etc. */
18323 if (cu
->language
== language_fortran
18324 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
18325 symbol_set_demangled_name (&(sym
->ginfo
),
18326 dwarf2_full_name (name
, die
, cu
),
18329 /* Default assumptions.
18330 Use the passed type or decode it from the die. */
18331 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
18332 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
18334 SYMBOL_TYPE (sym
) = type
;
18336 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
18337 attr
= dwarf2_attr (die
,
18338 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
18342 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
18345 attr
= dwarf2_attr (die
,
18346 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
18350 int file_index
= DW_UNSND (attr
);
18352 if (cu
->line_header
== NULL
18353 || file_index
> cu
->line_header
->num_file_names
)
18354 complaint (&symfile_complaints
,
18355 _("file index out of range"));
18356 else if (file_index
> 0)
18358 struct file_entry
*fe
;
18360 fe
= &cu
->line_header
->file_names
[file_index
- 1];
18361 symbol_set_symtab (sym
, fe
->symtab
);
18368 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
18373 addr
= attr_value_as_address (attr
);
18374 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
18375 SYMBOL_VALUE_ADDRESS (sym
) = addr
;
18377 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
18378 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
18379 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
18380 add_symbol_to_list (sym
, cu
->list_in_scope
);
18382 case DW_TAG_subprogram
:
18383 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
18385 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
18386 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
18387 if ((attr2
&& (DW_UNSND (attr2
) != 0))
18388 || cu
->language
== language_ada
)
18390 /* Subprograms marked external are stored as a global symbol.
18391 Ada subprograms, whether marked external or not, are always
18392 stored as a global symbol, because we want to be able to
18393 access them globally. For instance, we want to be able
18394 to break on a nested subprogram without having to
18395 specify the context. */
18396 list_to_add
= &global_symbols
;
18400 list_to_add
= cu
->list_in_scope
;
18403 case DW_TAG_inlined_subroutine
:
18404 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
18406 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
18407 SYMBOL_INLINED (sym
) = 1;
18408 list_to_add
= cu
->list_in_scope
;
18410 case DW_TAG_template_value_param
:
18412 /* Fall through. */
18413 case DW_TAG_constant
:
18414 case DW_TAG_variable
:
18415 case DW_TAG_member
:
18416 /* Compilation with minimal debug info may result in
18417 variables with missing type entries. Change the
18418 misleading `void' type to something sensible. */
18419 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
18421 = objfile_type (objfile
)->nodebug_data_symbol
;
18423 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
18424 /* In the case of DW_TAG_member, we should only be called for
18425 static const members. */
18426 if (die
->tag
== DW_TAG_member
)
18428 /* dwarf2_add_field uses die_is_declaration,
18429 so we do the same. */
18430 gdb_assert (die_is_declaration (die
, cu
));
18435 dwarf2_const_value (attr
, sym
, cu
);
18436 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
18439 if (attr2
&& (DW_UNSND (attr2
) != 0))
18440 list_to_add
= &global_symbols
;
18442 list_to_add
= cu
->list_in_scope
;
18446 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
18449 var_decode_location (attr
, sym
, cu
);
18450 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
18452 /* Fortran explicitly imports any global symbols to the local
18453 scope by DW_TAG_common_block. */
18454 if (cu
->language
== language_fortran
&& die
->parent
18455 && die
->parent
->tag
== DW_TAG_common_block
)
18458 if (SYMBOL_CLASS (sym
) == LOC_STATIC
18459 && SYMBOL_VALUE_ADDRESS (sym
) == 0
18460 && !dwarf2_per_objfile
->has_section_at_zero
)
18462 /* When a static variable is eliminated by the linker,
18463 the corresponding debug information is not stripped
18464 out, but the variable address is set to null;
18465 do not add such variables into symbol table. */
18467 else if (attr2
&& (DW_UNSND (attr2
) != 0))
18469 /* Workaround gfortran PR debug/40040 - it uses
18470 DW_AT_location for variables in -fPIC libraries which may
18471 get overriden by other libraries/executable and get
18472 a different address. Resolve it by the minimal symbol
18473 which may come from inferior's executable using copy
18474 relocation. Make this workaround only for gfortran as for
18475 other compilers GDB cannot guess the minimal symbol
18476 Fortran mangling kind. */
18477 if (cu
->language
== language_fortran
&& die
->parent
18478 && die
->parent
->tag
== DW_TAG_module
18480 && startswith (cu
->producer
, "GNU Fortran "))
18481 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
18483 /* A variable with DW_AT_external is never static,
18484 but it may be block-scoped. */
18485 list_to_add
= (cu
->list_in_scope
== &file_symbols
18486 ? &global_symbols
: cu
->list_in_scope
);
18489 list_to_add
= cu
->list_in_scope
;
18493 /* We do not know the address of this symbol.
18494 If it is an external symbol and we have type information
18495 for it, enter the symbol as a LOC_UNRESOLVED symbol.
18496 The address of the variable will then be determined from
18497 the minimal symbol table whenever the variable is
18499 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
18501 /* Fortran explicitly imports any global symbols to the local
18502 scope by DW_TAG_common_block. */
18503 if (cu
->language
== language_fortran
&& die
->parent
18504 && die
->parent
->tag
== DW_TAG_common_block
)
18506 /* SYMBOL_CLASS doesn't matter here because
18507 read_common_block is going to reset it. */
18509 list_to_add
= cu
->list_in_scope
;
18511 else if (attr2
&& (DW_UNSND (attr2
) != 0)
18512 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
18514 /* A variable with DW_AT_external is never static, but it
18515 may be block-scoped. */
18516 list_to_add
= (cu
->list_in_scope
== &file_symbols
18517 ? &global_symbols
: cu
->list_in_scope
);
18519 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
18521 else if (!die_is_declaration (die
, cu
))
18523 /* Use the default LOC_OPTIMIZED_OUT class. */
18524 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
18526 list_to_add
= cu
->list_in_scope
;
18530 case DW_TAG_formal_parameter
:
18531 /* If we are inside a function, mark this as an argument. If
18532 not, we might be looking at an argument to an inlined function
18533 when we do not have enough information to show inlined frames;
18534 pretend it's a local variable in that case so that the user can
18536 if (context_stack_depth
> 0
18537 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
18538 SYMBOL_IS_ARGUMENT (sym
) = 1;
18539 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
18542 var_decode_location (attr
, sym
, cu
);
18544 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
18547 dwarf2_const_value (attr
, sym
, cu
);
18550 list_to_add
= cu
->list_in_scope
;
18552 case DW_TAG_unspecified_parameters
:
18553 /* From varargs functions; gdb doesn't seem to have any
18554 interest in this information, so just ignore it for now.
18557 case DW_TAG_template_type_param
:
18559 /* Fall through. */
18560 case DW_TAG_class_type
:
18561 case DW_TAG_interface_type
:
18562 case DW_TAG_structure_type
:
18563 case DW_TAG_union_type
:
18564 case DW_TAG_set_type
:
18565 case DW_TAG_enumeration_type
:
18566 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
18567 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
18570 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
18571 really ever be static objects: otherwise, if you try
18572 to, say, break of a class's method and you're in a file
18573 which doesn't mention that class, it won't work unless
18574 the check for all static symbols in lookup_symbol_aux
18575 saves you. See the OtherFileClass tests in
18576 gdb.c++/namespace.exp. */
18580 list_to_add
= (cu
->list_in_scope
== &file_symbols
18581 && (cu
->language
== language_cplus
18582 || cu
->language
== language_java
)
18583 ? &global_symbols
: cu
->list_in_scope
);
18585 /* The semantics of C++ state that "struct foo {
18586 ... }" also defines a typedef for "foo". A Java
18587 class declaration also defines a typedef for the
18589 if (cu
->language
== language_cplus
18590 || cu
->language
== language_java
18591 || cu
->language
== language_ada
18592 || cu
->language
== language_d
)
18594 /* The symbol's name is already allocated along
18595 with this objfile, so we don't need to
18596 duplicate it for the type. */
18597 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
18598 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
18603 case DW_TAG_typedef
:
18604 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
18605 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
18606 list_to_add
= cu
->list_in_scope
;
18608 case DW_TAG_base_type
:
18609 case DW_TAG_subrange_type
:
18610 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
18611 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
18612 list_to_add
= cu
->list_in_scope
;
18614 case DW_TAG_enumerator
:
18615 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
18618 dwarf2_const_value (attr
, sym
, cu
);
18621 /* NOTE: carlton/2003-11-10: See comment above in the
18622 DW_TAG_class_type, etc. block. */
18624 list_to_add
= (cu
->list_in_scope
== &file_symbols
18625 && (cu
->language
== language_cplus
18626 || cu
->language
== language_java
)
18627 ? &global_symbols
: cu
->list_in_scope
);
18630 case DW_TAG_imported_declaration
:
18631 case DW_TAG_namespace
:
18632 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
18633 list_to_add
= &global_symbols
;
18635 case DW_TAG_module
:
18636 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
18637 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
18638 list_to_add
= &global_symbols
;
18640 case DW_TAG_common_block
:
18641 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
18642 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
18643 add_symbol_to_list (sym
, cu
->list_in_scope
);
18646 /* Not a tag we recognize. Hopefully we aren't processing
18647 trash data, but since we must specifically ignore things
18648 we don't recognize, there is nothing else we should do at
18650 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
18651 dwarf_tag_name (die
->tag
));
18657 sym
->hash_next
= objfile
->template_symbols
;
18658 objfile
->template_symbols
= sym
;
18659 list_to_add
= NULL
;
18662 if (list_to_add
!= NULL
)
18663 add_symbol_to_list (sym
, list_to_add
);
18665 /* For the benefit of old versions of GCC, check for anonymous
18666 namespaces based on the demangled name. */
18667 if (!cu
->processing_has_namespace_info
18668 && cu
->language
== language_cplus
)
18669 cp_scan_for_anonymous_namespaces (sym
, objfile
);
18674 /* A wrapper for new_symbol_full that always allocates a new symbol. */
18676 static struct symbol
*
18677 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
18679 return new_symbol_full (die
, type
, cu
, NULL
);
18682 /* Given an attr with a DW_FORM_dataN value in host byte order,
18683 zero-extend it as appropriate for the symbol's type. The DWARF
18684 standard (v4) is not entirely clear about the meaning of using
18685 DW_FORM_dataN for a constant with a signed type, where the type is
18686 wider than the data. The conclusion of a discussion on the DWARF
18687 list was that this is unspecified. We choose to always zero-extend
18688 because that is the interpretation long in use by GCC. */
18691 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
18692 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
18694 struct objfile
*objfile
= cu
->objfile
;
18695 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
18696 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
18697 LONGEST l
= DW_UNSND (attr
);
18699 if (bits
< sizeof (*value
) * 8)
18701 l
&= ((LONGEST
) 1 << bits
) - 1;
18704 else if (bits
== sizeof (*value
) * 8)
18708 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
18709 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
18716 /* Read a constant value from an attribute. Either set *VALUE, or if
18717 the value does not fit in *VALUE, set *BYTES - either already
18718 allocated on the objfile obstack, or newly allocated on OBSTACK,
18719 or, set *BATON, if we translated the constant to a location
18723 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
18724 const char *name
, struct obstack
*obstack
,
18725 struct dwarf2_cu
*cu
,
18726 LONGEST
*value
, const gdb_byte
**bytes
,
18727 struct dwarf2_locexpr_baton
**baton
)
18729 struct objfile
*objfile
= cu
->objfile
;
18730 struct comp_unit_head
*cu_header
= &cu
->header
;
18731 struct dwarf_block
*blk
;
18732 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
18733 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
18739 switch (attr
->form
)
18742 case DW_FORM_GNU_addr_index
:
18746 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
18747 dwarf2_const_value_length_mismatch_complaint (name
,
18748 cu_header
->addr_size
,
18749 TYPE_LENGTH (type
));
18750 /* Symbols of this form are reasonably rare, so we just
18751 piggyback on the existing location code rather than writing
18752 a new implementation of symbol_computed_ops. */
18753 *baton
= obstack_alloc (obstack
, sizeof (struct dwarf2_locexpr_baton
));
18754 (*baton
)->per_cu
= cu
->per_cu
;
18755 gdb_assert ((*baton
)->per_cu
);
18757 (*baton
)->size
= 2 + cu_header
->addr_size
;
18758 data
= obstack_alloc (obstack
, (*baton
)->size
);
18759 (*baton
)->data
= data
;
18761 data
[0] = DW_OP_addr
;
18762 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
18763 byte_order
, DW_ADDR (attr
));
18764 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
18767 case DW_FORM_string
:
18769 case DW_FORM_GNU_str_index
:
18770 case DW_FORM_GNU_strp_alt
:
18771 /* DW_STRING is already allocated on the objfile obstack, point
18773 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
18775 case DW_FORM_block1
:
18776 case DW_FORM_block2
:
18777 case DW_FORM_block4
:
18778 case DW_FORM_block
:
18779 case DW_FORM_exprloc
:
18780 blk
= DW_BLOCK (attr
);
18781 if (TYPE_LENGTH (type
) != blk
->size
)
18782 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
18783 TYPE_LENGTH (type
));
18784 *bytes
= blk
->data
;
18787 /* The DW_AT_const_value attributes are supposed to carry the
18788 symbol's value "represented as it would be on the target
18789 architecture." By the time we get here, it's already been
18790 converted to host endianness, so we just need to sign- or
18791 zero-extend it as appropriate. */
18792 case DW_FORM_data1
:
18793 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
18795 case DW_FORM_data2
:
18796 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
18798 case DW_FORM_data4
:
18799 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
18801 case DW_FORM_data8
:
18802 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
18805 case DW_FORM_sdata
:
18806 *value
= DW_SND (attr
);
18809 case DW_FORM_udata
:
18810 *value
= DW_UNSND (attr
);
18814 complaint (&symfile_complaints
,
18815 _("unsupported const value attribute form: '%s'"),
18816 dwarf_form_name (attr
->form
));
18823 /* Copy constant value from an attribute to a symbol. */
18826 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
18827 struct dwarf2_cu
*cu
)
18829 struct objfile
*objfile
= cu
->objfile
;
18830 struct comp_unit_head
*cu_header
= &cu
->header
;
18832 const gdb_byte
*bytes
;
18833 struct dwarf2_locexpr_baton
*baton
;
18835 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
18836 SYMBOL_PRINT_NAME (sym
),
18837 &objfile
->objfile_obstack
, cu
,
18838 &value
, &bytes
, &baton
);
18842 SYMBOL_LOCATION_BATON (sym
) = baton
;
18843 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
18845 else if (bytes
!= NULL
)
18847 SYMBOL_VALUE_BYTES (sym
) = bytes
;
18848 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
18852 SYMBOL_VALUE (sym
) = value
;
18853 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
18857 /* Return the type of the die in question using its DW_AT_type attribute. */
18859 static struct type
*
18860 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18862 struct attribute
*type_attr
;
18864 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
18867 /* A missing DW_AT_type represents a void type. */
18868 return objfile_type (cu
->objfile
)->builtin_void
;
18871 return lookup_die_type (die
, type_attr
, cu
);
18874 /* True iff CU's producer generates GNAT Ada auxiliary information
18875 that allows to find parallel types through that information instead
18876 of having to do expensive parallel lookups by type name. */
18879 need_gnat_info (struct dwarf2_cu
*cu
)
18881 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
18882 of GNAT produces this auxiliary information, without any indication
18883 that it is produced. Part of enhancing the FSF version of GNAT
18884 to produce that information will be to put in place an indicator
18885 that we can use in order to determine whether the descriptive type
18886 info is available or not. One suggestion that has been made is
18887 to use a new attribute, attached to the CU die. For now, assume
18888 that the descriptive type info is not available. */
18892 /* Return the auxiliary type of the die in question using its
18893 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
18894 attribute is not present. */
18896 static struct type
*
18897 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18899 struct attribute
*type_attr
;
18901 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
18905 return lookup_die_type (die
, type_attr
, cu
);
18908 /* If DIE has a descriptive_type attribute, then set the TYPE's
18909 descriptive type accordingly. */
18912 set_descriptive_type (struct type
*type
, struct die_info
*die
,
18913 struct dwarf2_cu
*cu
)
18915 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
18917 if (descriptive_type
)
18919 ALLOCATE_GNAT_AUX_TYPE (type
);
18920 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
18924 /* Return the containing type of the die in question using its
18925 DW_AT_containing_type attribute. */
18927 static struct type
*
18928 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18930 struct attribute
*type_attr
;
18932 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
18934 error (_("Dwarf Error: Problem turning containing type into gdb type "
18935 "[in module %s]"), objfile_name (cu
->objfile
));
18937 return lookup_die_type (die
, type_attr
, cu
);
18940 /* Return an error marker type to use for the ill formed type in DIE/CU. */
18942 static struct type
*
18943 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
18945 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18946 char *message
, *saved
;
18948 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
18949 objfile_name (objfile
),
18950 cu
->header
.offset
.sect_off
,
18951 die
->offset
.sect_off
);
18952 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
18953 message
, strlen (message
));
18956 return init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
18959 /* Look up the type of DIE in CU using its type attribute ATTR.
18960 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
18961 DW_AT_containing_type.
18962 If there is no type substitute an error marker. */
18964 static struct type
*
18965 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
18966 struct dwarf2_cu
*cu
)
18968 struct objfile
*objfile
= cu
->objfile
;
18969 struct type
*this_type
;
18971 gdb_assert (attr
->name
== DW_AT_type
18972 || attr
->name
== DW_AT_GNAT_descriptive_type
18973 || attr
->name
== DW_AT_containing_type
);
18975 /* First see if we have it cached. */
18977 if (attr
->form
== DW_FORM_GNU_ref_alt
)
18979 struct dwarf2_per_cu_data
*per_cu
;
18980 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
18982 per_cu
= dwarf2_find_containing_comp_unit (offset
, 1, cu
->objfile
);
18983 this_type
= get_die_type_at_offset (offset
, per_cu
);
18985 else if (attr_form_is_ref (attr
))
18987 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
18989 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
18991 else if (attr
->form
== DW_FORM_ref_sig8
)
18993 ULONGEST signature
= DW_SIGNATURE (attr
);
18995 return get_signatured_type (die
, signature
, cu
);
18999 complaint (&symfile_complaints
,
19000 _("Dwarf Error: Bad type attribute %s in DIE"
19001 " at 0x%x [in module %s]"),
19002 dwarf_attr_name (attr
->name
), die
->offset
.sect_off
,
19003 objfile_name (objfile
));
19004 return build_error_marker_type (cu
, die
);
19007 /* If not cached we need to read it in. */
19009 if (this_type
== NULL
)
19011 struct die_info
*type_die
= NULL
;
19012 struct dwarf2_cu
*type_cu
= cu
;
19014 if (attr_form_is_ref (attr
))
19015 type_die
= follow_die_ref (die
, attr
, &type_cu
);
19016 if (type_die
== NULL
)
19017 return build_error_marker_type (cu
, die
);
19018 /* If we find the type now, it's probably because the type came
19019 from an inter-CU reference and the type's CU got expanded before
19021 this_type
= read_type_die (type_die
, type_cu
);
19024 /* If we still don't have a type use an error marker. */
19026 if (this_type
== NULL
)
19027 return build_error_marker_type (cu
, die
);
19032 /* Return the type in DIE, CU.
19033 Returns NULL for invalid types.
19035 This first does a lookup in die_type_hash,
19036 and only reads the die in if necessary.
19038 NOTE: This can be called when reading in partial or full symbols. */
19040 static struct type
*
19041 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
19043 struct type
*this_type
;
19045 this_type
= get_die_type (die
, cu
);
19049 return read_type_die_1 (die
, cu
);
19052 /* Read the type in DIE, CU.
19053 Returns NULL for invalid types. */
19055 static struct type
*
19056 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
19058 struct type
*this_type
= NULL
;
19062 case DW_TAG_class_type
:
19063 case DW_TAG_interface_type
:
19064 case DW_TAG_structure_type
:
19065 case DW_TAG_union_type
:
19066 this_type
= read_structure_type (die
, cu
);
19068 case DW_TAG_enumeration_type
:
19069 this_type
= read_enumeration_type (die
, cu
);
19071 case DW_TAG_subprogram
:
19072 case DW_TAG_subroutine_type
:
19073 case DW_TAG_inlined_subroutine
:
19074 this_type
= read_subroutine_type (die
, cu
);
19076 case DW_TAG_array_type
:
19077 this_type
= read_array_type (die
, cu
);
19079 case DW_TAG_set_type
:
19080 this_type
= read_set_type (die
, cu
);
19082 case DW_TAG_pointer_type
:
19083 this_type
= read_tag_pointer_type (die
, cu
);
19085 case DW_TAG_ptr_to_member_type
:
19086 this_type
= read_tag_ptr_to_member_type (die
, cu
);
19088 case DW_TAG_reference_type
:
19089 this_type
= read_tag_reference_type (die
, cu
);
19091 case DW_TAG_const_type
:
19092 this_type
= read_tag_const_type (die
, cu
);
19094 case DW_TAG_volatile_type
:
19095 this_type
= read_tag_volatile_type (die
, cu
);
19097 case DW_TAG_restrict_type
:
19098 this_type
= read_tag_restrict_type (die
, cu
);
19100 case DW_TAG_string_type
:
19101 this_type
= read_tag_string_type (die
, cu
);
19103 case DW_TAG_typedef
:
19104 this_type
= read_typedef (die
, cu
);
19106 case DW_TAG_subrange_type
:
19107 this_type
= read_subrange_type (die
, cu
);
19109 case DW_TAG_base_type
:
19110 this_type
= read_base_type (die
, cu
);
19112 case DW_TAG_unspecified_type
:
19113 this_type
= read_unspecified_type (die
, cu
);
19115 case DW_TAG_namespace
:
19116 this_type
= read_namespace_type (die
, cu
);
19118 case DW_TAG_module
:
19119 this_type
= read_module_type (die
, cu
);
19121 case DW_TAG_atomic_type
:
19122 this_type
= read_tag_atomic_type (die
, cu
);
19125 complaint (&symfile_complaints
,
19126 _("unexpected tag in read_type_die: '%s'"),
19127 dwarf_tag_name (die
->tag
));
19134 /* See if we can figure out if the class lives in a namespace. We do
19135 this by looking for a member function; its demangled name will
19136 contain namespace info, if there is any.
19137 Return the computed name or NULL.
19138 Space for the result is allocated on the objfile's obstack.
19139 This is the full-die version of guess_partial_die_structure_name.
19140 In this case we know DIE has no useful parent. */
19143 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19145 struct die_info
*spec_die
;
19146 struct dwarf2_cu
*spec_cu
;
19147 struct die_info
*child
;
19150 spec_die
= die_specification (die
, &spec_cu
);
19151 if (spec_die
!= NULL
)
19157 for (child
= die
->child
;
19159 child
= child
->sibling
)
19161 if (child
->tag
== DW_TAG_subprogram
)
19163 const char *linkage_name
;
19165 linkage_name
= dwarf2_string_attr (child
, DW_AT_linkage_name
, cu
);
19166 if (linkage_name
== NULL
)
19167 linkage_name
= dwarf2_string_attr (child
, DW_AT_MIPS_linkage_name
,
19169 if (linkage_name
!= NULL
)
19172 = language_class_name_from_physname (cu
->language_defn
,
19176 if (actual_name
!= NULL
)
19178 const char *die_name
= dwarf2_name (die
, cu
);
19180 if (die_name
!= NULL
19181 && strcmp (die_name
, actual_name
) != 0)
19183 /* Strip off the class name from the full name.
19184 We want the prefix. */
19185 int die_name_len
= strlen (die_name
);
19186 int actual_name_len
= strlen (actual_name
);
19188 /* Test for '::' as a sanity check. */
19189 if (actual_name_len
> die_name_len
+ 2
19190 && actual_name
[actual_name_len
19191 - die_name_len
- 1] == ':')
19193 obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
19195 actual_name_len
- die_name_len
- 2);
19198 xfree (actual_name
);
19207 /* GCC might emit a nameless typedef that has a linkage name. Determine the
19208 prefix part in such case. See
19209 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19212 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
19214 struct attribute
*attr
;
19217 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
19218 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
19221 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
19224 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
19226 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
19227 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
19230 /* dwarf2_name had to be already called. */
19231 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
19233 /* Strip the base name, keep any leading namespaces/classes. */
19234 base
= strrchr (DW_STRING (attr
), ':');
19235 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
19238 return obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
19239 DW_STRING (attr
), &base
[-1] - DW_STRING (attr
));
19242 /* Return the name of the namespace/class that DIE is defined within,
19243 or "" if we can't tell. The caller should not xfree the result.
19245 For example, if we're within the method foo() in the following
19255 then determine_prefix on foo's die will return "N::C". */
19257 static const char *
19258 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
19260 struct die_info
*parent
, *spec_die
;
19261 struct dwarf2_cu
*spec_cu
;
19262 struct type
*parent_type
;
19265 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
19266 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
)
19269 retval
= anonymous_struct_prefix (die
, cu
);
19273 /* We have to be careful in the presence of DW_AT_specification.
19274 For example, with GCC 3.4, given the code
19278 // Definition of N::foo.
19282 then we'll have a tree of DIEs like this:
19284 1: DW_TAG_compile_unit
19285 2: DW_TAG_namespace // N
19286 3: DW_TAG_subprogram // declaration of N::foo
19287 4: DW_TAG_subprogram // definition of N::foo
19288 DW_AT_specification // refers to die #3
19290 Thus, when processing die #4, we have to pretend that we're in
19291 the context of its DW_AT_specification, namely the contex of die
19294 spec_die
= die_specification (die
, &spec_cu
);
19295 if (spec_die
== NULL
)
19296 parent
= die
->parent
;
19299 parent
= spec_die
->parent
;
19303 if (parent
== NULL
)
19305 else if (parent
->building_fullname
)
19308 const char *parent_name
;
19310 /* It has been seen on RealView 2.2 built binaries,
19311 DW_TAG_template_type_param types actually _defined_ as
19312 children of the parent class:
19315 template class <class Enum> Class{};
19316 Class<enum E> class_e;
19318 1: DW_TAG_class_type (Class)
19319 2: DW_TAG_enumeration_type (E)
19320 3: DW_TAG_enumerator (enum1:0)
19321 3: DW_TAG_enumerator (enum2:1)
19323 2: DW_TAG_template_type_param
19324 DW_AT_type DW_FORM_ref_udata (E)
19326 Besides being broken debug info, it can put GDB into an
19327 infinite loop. Consider:
19329 When we're building the full name for Class<E>, we'll start
19330 at Class, and go look over its template type parameters,
19331 finding E. We'll then try to build the full name of E, and
19332 reach here. We're now trying to build the full name of E,
19333 and look over the parent DIE for containing scope. In the
19334 broken case, if we followed the parent DIE of E, we'd again
19335 find Class, and once again go look at its template type
19336 arguments, etc., etc. Simply don't consider such parent die
19337 as source-level parent of this die (it can't be, the language
19338 doesn't allow it), and break the loop here. */
19339 name
= dwarf2_name (die
, cu
);
19340 parent_name
= dwarf2_name (parent
, cu
);
19341 complaint (&symfile_complaints
,
19342 _("template param type '%s' defined within parent '%s'"),
19343 name
? name
: "<unknown>",
19344 parent_name
? parent_name
: "<unknown>");
19348 switch (parent
->tag
)
19350 case DW_TAG_namespace
:
19351 parent_type
= read_type_die (parent
, cu
);
19352 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
19353 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
19354 Work around this problem here. */
19355 if (cu
->language
== language_cplus
19356 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
19358 /* We give a name to even anonymous namespaces. */
19359 return TYPE_TAG_NAME (parent_type
);
19360 case DW_TAG_class_type
:
19361 case DW_TAG_interface_type
:
19362 case DW_TAG_structure_type
:
19363 case DW_TAG_union_type
:
19364 case DW_TAG_module
:
19365 parent_type
= read_type_die (parent
, cu
);
19366 if (TYPE_TAG_NAME (parent_type
) != NULL
)
19367 return TYPE_TAG_NAME (parent_type
);
19369 /* An anonymous structure is only allowed non-static data
19370 members; no typedefs, no member functions, et cetera.
19371 So it does not need a prefix. */
19373 case DW_TAG_compile_unit
:
19374 case DW_TAG_partial_unit
:
19375 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
19376 if (cu
->language
== language_cplus
19377 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
19378 && die
->child
!= NULL
19379 && (die
->tag
== DW_TAG_class_type
19380 || die
->tag
== DW_TAG_structure_type
19381 || die
->tag
== DW_TAG_union_type
))
19383 char *name
= guess_full_die_structure_name (die
, cu
);
19388 case DW_TAG_enumeration_type
:
19389 parent_type
= read_type_die (parent
, cu
);
19390 if (TYPE_DECLARED_CLASS (parent_type
))
19392 if (TYPE_TAG_NAME (parent_type
) != NULL
)
19393 return TYPE_TAG_NAME (parent_type
);
19396 /* Fall through. */
19398 return determine_prefix (parent
, cu
);
19402 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
19403 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
19404 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
19405 an obconcat, otherwise allocate storage for the result. The CU argument is
19406 used to determine the language and hence, the appropriate separator. */
19408 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
19411 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
19412 int physname
, struct dwarf2_cu
*cu
)
19414 const char *lead
= "";
19417 if (suffix
== NULL
|| suffix
[0] == '\0'
19418 || prefix
== NULL
|| prefix
[0] == '\0')
19420 else if (cu
->language
== language_java
)
19422 else if (cu
->language
== language_d
)
19424 /* For D, the 'main' function could be defined in any module, but it
19425 should never be prefixed. */
19426 if (strcmp (suffix
, "D main") == 0)
19434 else if (cu
->language
== language_fortran
&& physname
)
19436 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
19437 DW_AT_MIPS_linkage_name is preferred and used instead. */
19445 if (prefix
== NULL
)
19447 if (suffix
== NULL
)
19453 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
19455 strcpy (retval
, lead
);
19456 strcat (retval
, prefix
);
19457 strcat (retval
, sep
);
19458 strcat (retval
, suffix
);
19463 /* We have an obstack. */
19464 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
19468 /* Return sibling of die, NULL if no sibling. */
19470 static struct die_info
*
19471 sibling_die (struct die_info
*die
)
19473 return die
->sibling
;
19476 /* Get name of a die, return NULL if not found. */
19478 static const char *
19479 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
19480 struct obstack
*obstack
)
19482 if (name
&& cu
->language
== language_cplus
)
19484 char *canon_name
= cp_canonicalize_string (name
);
19486 if (canon_name
!= NULL
)
19488 if (strcmp (canon_name
, name
) != 0)
19489 name
= obstack_copy0 (obstack
, canon_name
, strlen (canon_name
));
19490 xfree (canon_name
);
19497 /* Get name of a die, return NULL if not found.
19498 Anonymous namespaces are converted to their magic string. */
19500 static const char *
19501 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19503 struct attribute
*attr
;
19505 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
19506 if ((!attr
|| !DW_STRING (attr
))
19507 && die
->tag
!= DW_TAG_namespace
19508 && die
->tag
!= DW_TAG_class_type
19509 && die
->tag
!= DW_TAG_interface_type
19510 && die
->tag
!= DW_TAG_structure_type
19511 && die
->tag
!= DW_TAG_union_type
)
19516 case DW_TAG_compile_unit
:
19517 case DW_TAG_partial_unit
:
19518 /* Compilation units have a DW_AT_name that is a filename, not
19519 a source language identifier. */
19520 case DW_TAG_enumeration_type
:
19521 case DW_TAG_enumerator
:
19522 /* These tags always have simple identifiers already; no need
19523 to canonicalize them. */
19524 return DW_STRING (attr
);
19526 case DW_TAG_namespace
:
19527 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
19528 return DW_STRING (attr
);
19529 return CP_ANONYMOUS_NAMESPACE_STR
;
19531 case DW_TAG_subprogram
:
19532 /* Java constructors will all be named "<init>", so return
19533 the class name when we see this special case. */
19534 if (cu
->language
== language_java
19535 && DW_STRING (attr
) != NULL
19536 && strcmp (DW_STRING (attr
), "<init>") == 0)
19538 struct dwarf2_cu
*spec_cu
= cu
;
19539 struct die_info
*spec_die
;
19541 /* GCJ will output '<init>' for Java constructor names.
19542 For this special case, return the name of the parent class. */
19544 /* GCJ may output subprogram DIEs with AT_specification set.
19545 If so, use the name of the specified DIE. */
19546 spec_die
= die_specification (die
, &spec_cu
);
19547 if (spec_die
!= NULL
)
19548 return dwarf2_name (spec_die
, spec_cu
);
19553 if (die
->tag
== DW_TAG_class_type
)
19554 return dwarf2_name (die
, cu
);
19556 while (die
->tag
!= DW_TAG_compile_unit
19557 && die
->tag
!= DW_TAG_partial_unit
);
19561 case DW_TAG_class_type
:
19562 case DW_TAG_interface_type
:
19563 case DW_TAG_structure_type
:
19564 case DW_TAG_union_type
:
19565 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
19566 structures or unions. These were of the form "._%d" in GCC 4.1,
19567 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
19568 and GCC 4.4. We work around this problem by ignoring these. */
19569 if (attr
&& DW_STRING (attr
)
19570 && (startswith (DW_STRING (attr
), "._")
19571 || startswith (DW_STRING (attr
), "<anonymous")))
19574 /* GCC might emit a nameless typedef that has a linkage name. See
19575 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19576 if (!attr
|| DW_STRING (attr
) == NULL
)
19578 char *demangled
= NULL
;
19580 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
19582 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
19584 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
19587 /* Avoid demangling DW_STRING (attr) the second time on a second
19588 call for the same DIE. */
19589 if (!DW_STRING_IS_CANONICAL (attr
))
19590 demangled
= gdb_demangle (DW_STRING (attr
), DMGL_TYPES
);
19596 /* FIXME: we already did this for the partial symbol... */
19598 = obstack_copy0 (&cu
->objfile
->per_bfd
->storage_obstack
,
19599 demangled
, strlen (demangled
));
19600 DW_STRING_IS_CANONICAL (attr
) = 1;
19603 /* Strip any leading namespaces/classes, keep only the base name.
19604 DW_AT_name for named DIEs does not contain the prefixes. */
19605 base
= strrchr (DW_STRING (attr
), ':');
19606 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
19609 return DW_STRING (attr
);
19618 if (!DW_STRING_IS_CANONICAL (attr
))
19621 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
19622 &cu
->objfile
->per_bfd
->storage_obstack
);
19623 DW_STRING_IS_CANONICAL (attr
) = 1;
19625 return DW_STRING (attr
);
19628 /* Return the die that this die in an extension of, or NULL if there
19629 is none. *EXT_CU is the CU containing DIE on input, and the CU
19630 containing the return value on output. */
19632 static struct die_info
*
19633 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
19635 struct attribute
*attr
;
19637 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
19641 return follow_die_ref (die
, attr
, ext_cu
);
19644 /* Convert a DIE tag into its string name. */
19646 static const char *
19647 dwarf_tag_name (unsigned tag
)
19649 const char *name
= get_DW_TAG_name (tag
);
19652 return "DW_TAG_<unknown>";
19657 /* Convert a DWARF attribute code into its string name. */
19659 static const char *
19660 dwarf_attr_name (unsigned attr
)
19664 #ifdef MIPS /* collides with DW_AT_HP_block_index */
19665 if (attr
== DW_AT_MIPS_fde
)
19666 return "DW_AT_MIPS_fde";
19668 if (attr
== DW_AT_HP_block_index
)
19669 return "DW_AT_HP_block_index";
19672 name
= get_DW_AT_name (attr
);
19675 return "DW_AT_<unknown>";
19680 /* Convert a DWARF value form code into its string name. */
19682 static const char *
19683 dwarf_form_name (unsigned form
)
19685 const char *name
= get_DW_FORM_name (form
);
19688 return "DW_FORM_<unknown>";
19694 dwarf_bool_name (unsigned mybool
)
19702 /* Convert a DWARF type code into its string name. */
19704 static const char *
19705 dwarf_type_encoding_name (unsigned enc
)
19707 const char *name
= get_DW_ATE_name (enc
);
19710 return "DW_ATE_<unknown>";
19716 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
19720 print_spaces (indent
, f
);
19721 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
19722 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
.sect_off
);
19724 if (die
->parent
!= NULL
)
19726 print_spaces (indent
, f
);
19727 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
19728 die
->parent
->offset
.sect_off
);
19731 print_spaces (indent
, f
);
19732 fprintf_unfiltered (f
, " has children: %s\n",
19733 dwarf_bool_name (die
->child
!= NULL
));
19735 print_spaces (indent
, f
);
19736 fprintf_unfiltered (f
, " attributes:\n");
19738 for (i
= 0; i
< die
->num_attrs
; ++i
)
19740 print_spaces (indent
, f
);
19741 fprintf_unfiltered (f
, " %s (%s) ",
19742 dwarf_attr_name (die
->attrs
[i
].name
),
19743 dwarf_form_name (die
->attrs
[i
].form
));
19745 switch (die
->attrs
[i
].form
)
19748 case DW_FORM_GNU_addr_index
:
19749 fprintf_unfiltered (f
, "address: ");
19750 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
19752 case DW_FORM_block2
:
19753 case DW_FORM_block4
:
19754 case DW_FORM_block
:
19755 case DW_FORM_block1
:
19756 fprintf_unfiltered (f
, "block: size %s",
19757 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
19759 case DW_FORM_exprloc
:
19760 fprintf_unfiltered (f
, "expression: size %s",
19761 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
19763 case DW_FORM_ref_addr
:
19764 fprintf_unfiltered (f
, "ref address: ");
19765 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
19767 case DW_FORM_GNU_ref_alt
:
19768 fprintf_unfiltered (f
, "alt ref address: ");
19769 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
19775 case DW_FORM_ref_udata
:
19776 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
19777 (long) (DW_UNSND (&die
->attrs
[i
])));
19779 case DW_FORM_data1
:
19780 case DW_FORM_data2
:
19781 case DW_FORM_data4
:
19782 case DW_FORM_data8
:
19783 case DW_FORM_udata
:
19784 case DW_FORM_sdata
:
19785 fprintf_unfiltered (f
, "constant: %s",
19786 pulongest (DW_UNSND (&die
->attrs
[i
])));
19788 case DW_FORM_sec_offset
:
19789 fprintf_unfiltered (f
, "section offset: %s",
19790 pulongest (DW_UNSND (&die
->attrs
[i
])));
19792 case DW_FORM_ref_sig8
:
19793 fprintf_unfiltered (f
, "signature: %s",
19794 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
19796 case DW_FORM_string
:
19798 case DW_FORM_GNU_str_index
:
19799 case DW_FORM_GNU_strp_alt
:
19800 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
19801 DW_STRING (&die
->attrs
[i
])
19802 ? DW_STRING (&die
->attrs
[i
]) : "",
19803 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
19806 if (DW_UNSND (&die
->attrs
[i
]))
19807 fprintf_unfiltered (f
, "flag: TRUE");
19809 fprintf_unfiltered (f
, "flag: FALSE");
19811 case DW_FORM_flag_present
:
19812 fprintf_unfiltered (f
, "flag: TRUE");
19814 case DW_FORM_indirect
:
19815 /* The reader will have reduced the indirect form to
19816 the "base form" so this form should not occur. */
19817 fprintf_unfiltered (f
,
19818 "unexpected attribute form: DW_FORM_indirect");
19821 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
19822 die
->attrs
[i
].form
);
19825 fprintf_unfiltered (f
, "\n");
19830 dump_die_for_error (struct die_info
*die
)
19832 dump_die_shallow (gdb_stderr
, 0, die
);
19836 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
19838 int indent
= level
* 4;
19840 gdb_assert (die
!= NULL
);
19842 if (level
>= max_level
)
19845 dump_die_shallow (f
, indent
, die
);
19847 if (die
->child
!= NULL
)
19849 print_spaces (indent
, f
);
19850 fprintf_unfiltered (f
, " Children:");
19851 if (level
+ 1 < max_level
)
19853 fprintf_unfiltered (f
, "\n");
19854 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
19858 fprintf_unfiltered (f
,
19859 " [not printed, max nesting level reached]\n");
19863 if (die
->sibling
!= NULL
&& level
> 0)
19865 dump_die_1 (f
, level
, max_level
, die
->sibling
);
19869 /* This is called from the pdie macro in gdbinit.in.
19870 It's not static so gcc will keep a copy callable from gdb. */
19873 dump_die (struct die_info
*die
, int max_level
)
19875 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
19879 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
19883 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
.sect_off
,
19889 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
19893 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
19895 sect_offset retval
= { DW_UNSND (attr
) };
19897 if (attr_form_is_ref (attr
))
19900 retval
.sect_off
= 0;
19901 complaint (&symfile_complaints
,
19902 _("unsupported die ref attribute form: '%s'"),
19903 dwarf_form_name (attr
->form
));
19907 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
19908 * the value held by the attribute is not constant. */
19911 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
19913 if (attr
->form
== DW_FORM_sdata
)
19914 return DW_SND (attr
);
19915 else if (attr
->form
== DW_FORM_udata
19916 || attr
->form
== DW_FORM_data1
19917 || attr
->form
== DW_FORM_data2
19918 || attr
->form
== DW_FORM_data4
19919 || attr
->form
== DW_FORM_data8
)
19920 return DW_UNSND (attr
);
19923 complaint (&symfile_complaints
,
19924 _("Attribute value is not a constant (%s)"),
19925 dwarf_form_name (attr
->form
));
19926 return default_value
;
19930 /* Follow reference or signature attribute ATTR of SRC_DIE.
19931 On entry *REF_CU is the CU of SRC_DIE.
19932 On exit *REF_CU is the CU of the result. */
19934 static struct die_info
*
19935 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
19936 struct dwarf2_cu
**ref_cu
)
19938 struct die_info
*die
;
19940 if (attr_form_is_ref (attr
))
19941 die
= follow_die_ref (src_die
, attr
, ref_cu
);
19942 else if (attr
->form
== DW_FORM_ref_sig8
)
19943 die
= follow_die_sig (src_die
, attr
, ref_cu
);
19946 dump_die_for_error (src_die
);
19947 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
19948 objfile_name ((*ref_cu
)->objfile
));
19954 /* Follow reference OFFSET.
19955 On entry *REF_CU is the CU of the source die referencing OFFSET.
19956 On exit *REF_CU is the CU of the result.
19957 Returns NULL if OFFSET is invalid. */
19959 static struct die_info
*
19960 follow_die_offset (sect_offset offset
, int offset_in_dwz
,
19961 struct dwarf2_cu
**ref_cu
)
19963 struct die_info temp_die
;
19964 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
19966 gdb_assert (cu
->per_cu
!= NULL
);
19970 if (cu
->per_cu
->is_debug_types
)
19972 /* .debug_types CUs cannot reference anything outside their CU.
19973 If they need to, they have to reference a signatured type via
19974 DW_FORM_ref_sig8. */
19975 if (! offset_in_cu_p (&cu
->header
, offset
))
19978 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
19979 || ! offset_in_cu_p (&cu
->header
, offset
))
19981 struct dwarf2_per_cu_data
*per_cu
;
19983 per_cu
= dwarf2_find_containing_comp_unit (offset
, offset_in_dwz
,
19986 /* If necessary, add it to the queue and load its DIEs. */
19987 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
19988 load_full_comp_unit (per_cu
, cu
->language
);
19990 target_cu
= per_cu
->cu
;
19992 else if (cu
->dies
== NULL
)
19994 /* We're loading full DIEs during partial symbol reading. */
19995 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
19996 load_full_comp_unit (cu
->per_cu
, language_minimal
);
19999 *ref_cu
= target_cu
;
20000 temp_die
.offset
= offset
;
20001 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
.sect_off
);
20004 /* Follow reference attribute ATTR of SRC_DIE.
20005 On entry *REF_CU is the CU of SRC_DIE.
20006 On exit *REF_CU is the CU of the result. */
20008 static struct die_info
*
20009 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
20010 struct dwarf2_cu
**ref_cu
)
20012 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
20013 struct dwarf2_cu
*cu
= *ref_cu
;
20014 struct die_info
*die
;
20016 die
= follow_die_offset (offset
,
20017 (attr
->form
== DW_FORM_GNU_ref_alt
20018 || cu
->per_cu
->is_dwz
),
20021 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
20022 "at 0x%x [in module %s]"),
20023 offset
.sect_off
, src_die
->offset
.sect_off
,
20024 objfile_name (cu
->objfile
));
20029 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
20030 Returned value is intended for DW_OP_call*. Returned
20031 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
20033 struct dwarf2_locexpr_baton
20034 dwarf2_fetch_die_loc_sect_off (sect_offset offset
,
20035 struct dwarf2_per_cu_data
*per_cu
,
20036 CORE_ADDR (*get_frame_pc
) (void *baton
),
20039 struct dwarf2_cu
*cu
;
20040 struct die_info
*die
;
20041 struct attribute
*attr
;
20042 struct dwarf2_locexpr_baton retval
;
20044 dw2_setup (per_cu
->objfile
);
20046 if (per_cu
->cu
== NULL
)
20051 /* We shouldn't get here for a dummy CU, but don't crash on the user.
20052 Instead just throw an error, not much else we can do. */
20053 error (_("Dwarf Error: Dummy CU at 0x%x referenced in module %s"),
20054 offset
.sect_off
, objfile_name (per_cu
->objfile
));
20057 die
= follow_die_offset (offset
, per_cu
->is_dwz
, &cu
);
20059 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
20060 offset
.sect_off
, objfile_name (per_cu
->objfile
));
20062 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20065 /* DWARF: "If there is no such attribute, then there is no effect.".
20066 DATA is ignored if SIZE is 0. */
20068 retval
.data
= NULL
;
20071 else if (attr_form_is_section_offset (attr
))
20073 struct dwarf2_loclist_baton loclist_baton
;
20074 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
20077 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
20079 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
20081 retval
.size
= size
;
20085 if (!attr_form_is_block (attr
))
20086 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
20087 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
20088 offset
.sect_off
, objfile_name (per_cu
->objfile
));
20090 retval
.data
= DW_BLOCK (attr
)->data
;
20091 retval
.size
= DW_BLOCK (attr
)->size
;
20093 retval
.per_cu
= cu
->per_cu
;
20095 age_cached_comp_units ();
20100 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
20103 struct dwarf2_locexpr_baton
20104 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
20105 struct dwarf2_per_cu_data
*per_cu
,
20106 CORE_ADDR (*get_frame_pc
) (void *baton
),
20109 sect_offset offset
= { per_cu
->offset
.sect_off
+ offset_in_cu
.cu_off
};
20111 return dwarf2_fetch_die_loc_sect_off (offset
, per_cu
, get_frame_pc
, baton
);
20114 /* Write a constant of a given type as target-ordered bytes into
20117 static const gdb_byte
*
20118 write_constant_as_bytes (struct obstack
*obstack
,
20119 enum bfd_endian byte_order
,
20126 *len
= TYPE_LENGTH (type
);
20127 result
= obstack_alloc (obstack
, *len
);
20128 store_unsigned_integer (result
, *len
, byte_order
, value
);
20133 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
20134 pointer to the constant bytes and set LEN to the length of the
20135 data. If memory is needed, allocate it on OBSTACK. If the DIE
20136 does not have a DW_AT_const_value, return NULL. */
20139 dwarf2_fetch_constant_bytes (sect_offset offset
,
20140 struct dwarf2_per_cu_data
*per_cu
,
20141 struct obstack
*obstack
,
20144 struct dwarf2_cu
*cu
;
20145 struct die_info
*die
;
20146 struct attribute
*attr
;
20147 const gdb_byte
*result
= NULL
;
20150 enum bfd_endian byte_order
;
20152 dw2_setup (per_cu
->objfile
);
20154 if (per_cu
->cu
== NULL
)
20159 /* We shouldn't get here for a dummy CU, but don't crash on the user.
20160 Instead just throw an error, not much else we can do. */
20161 error (_("Dwarf Error: Dummy CU at 0x%x referenced in module %s"),
20162 offset
.sect_off
, objfile_name (per_cu
->objfile
));
20165 die
= follow_die_offset (offset
, per_cu
->is_dwz
, &cu
);
20167 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
20168 offset
.sect_off
, objfile_name (per_cu
->objfile
));
20171 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20175 byte_order
= (bfd_big_endian (per_cu
->objfile
->obfd
)
20176 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
20178 switch (attr
->form
)
20181 case DW_FORM_GNU_addr_index
:
20185 *len
= cu
->header
.addr_size
;
20186 tem
= obstack_alloc (obstack
, *len
);
20187 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
20191 case DW_FORM_string
:
20193 case DW_FORM_GNU_str_index
:
20194 case DW_FORM_GNU_strp_alt
:
20195 /* DW_STRING is already allocated on the objfile obstack, point
20197 result
= (const gdb_byte
*) DW_STRING (attr
);
20198 *len
= strlen (DW_STRING (attr
));
20200 case DW_FORM_block1
:
20201 case DW_FORM_block2
:
20202 case DW_FORM_block4
:
20203 case DW_FORM_block
:
20204 case DW_FORM_exprloc
:
20205 result
= DW_BLOCK (attr
)->data
;
20206 *len
= DW_BLOCK (attr
)->size
;
20209 /* The DW_AT_const_value attributes are supposed to carry the
20210 symbol's value "represented as it would be on the target
20211 architecture." By the time we get here, it's already been
20212 converted to host endianness, so we just need to sign- or
20213 zero-extend it as appropriate. */
20214 case DW_FORM_data1
:
20215 type
= die_type (die
, cu
);
20216 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
20217 if (result
== NULL
)
20218 result
= write_constant_as_bytes (obstack
, byte_order
,
20221 case DW_FORM_data2
:
20222 type
= die_type (die
, cu
);
20223 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
20224 if (result
== NULL
)
20225 result
= write_constant_as_bytes (obstack
, byte_order
,
20228 case DW_FORM_data4
:
20229 type
= die_type (die
, cu
);
20230 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
20231 if (result
== NULL
)
20232 result
= write_constant_as_bytes (obstack
, byte_order
,
20235 case DW_FORM_data8
:
20236 type
= die_type (die
, cu
);
20237 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
20238 if (result
== NULL
)
20239 result
= write_constant_as_bytes (obstack
, byte_order
,
20243 case DW_FORM_sdata
:
20244 type
= die_type (die
, cu
);
20245 result
= write_constant_as_bytes (obstack
, byte_order
,
20246 type
, DW_SND (attr
), len
);
20249 case DW_FORM_udata
:
20250 type
= die_type (die
, cu
);
20251 result
= write_constant_as_bytes (obstack
, byte_order
,
20252 type
, DW_UNSND (attr
), len
);
20256 complaint (&symfile_complaints
,
20257 _("unsupported const value attribute form: '%s'"),
20258 dwarf_form_name (attr
->form
));
20265 /* Return the type of the DIE at DIE_OFFSET in the CU named by
20269 dwarf2_get_die_type (cu_offset die_offset
,
20270 struct dwarf2_per_cu_data
*per_cu
)
20272 sect_offset die_offset_sect
;
20274 dw2_setup (per_cu
->objfile
);
20276 die_offset_sect
.sect_off
= per_cu
->offset
.sect_off
+ die_offset
.cu_off
;
20277 return get_die_type_at_offset (die_offset_sect
, per_cu
);
20280 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
20281 On entry *REF_CU is the CU of SRC_DIE.
20282 On exit *REF_CU is the CU of the result.
20283 Returns NULL if the referenced DIE isn't found. */
20285 static struct die_info
*
20286 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
20287 struct dwarf2_cu
**ref_cu
)
20289 struct objfile
*objfile
= (*ref_cu
)->objfile
;
20290 struct die_info temp_die
;
20291 struct dwarf2_cu
*sig_cu
;
20292 struct die_info
*die
;
20294 /* While it might be nice to assert sig_type->type == NULL here,
20295 we can get here for DW_AT_imported_declaration where we need
20296 the DIE not the type. */
20298 /* If necessary, add it to the queue and load its DIEs. */
20300 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
20301 read_signatured_type (sig_type
);
20303 sig_cu
= sig_type
->per_cu
.cu
;
20304 gdb_assert (sig_cu
!= NULL
);
20305 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
20306 temp_die
.offset
= sig_type
->type_offset_in_section
;
20307 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
20308 temp_die
.offset
.sect_off
);
20311 /* For .gdb_index version 7 keep track of included TUs.
20312 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
20313 if (dwarf2_per_objfile
->index_table
!= NULL
20314 && dwarf2_per_objfile
->index_table
->version
<= 7)
20316 VEC_safe_push (dwarf2_per_cu_ptr
,
20317 (*ref_cu
)->per_cu
->imported_symtabs
,
20328 /* Follow signatured type referenced by ATTR in SRC_DIE.
20329 On entry *REF_CU is the CU of SRC_DIE.
20330 On exit *REF_CU is the CU of the result.
20331 The result is the DIE of the type.
20332 If the referenced type cannot be found an error is thrown. */
20334 static struct die_info
*
20335 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
20336 struct dwarf2_cu
**ref_cu
)
20338 ULONGEST signature
= DW_SIGNATURE (attr
);
20339 struct signatured_type
*sig_type
;
20340 struct die_info
*die
;
20342 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
20344 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
20345 /* sig_type will be NULL if the signatured type is missing from
20347 if (sig_type
== NULL
)
20349 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
20350 " from DIE at 0x%x [in module %s]"),
20351 hex_string (signature
), src_die
->offset
.sect_off
,
20352 objfile_name ((*ref_cu
)->objfile
));
20355 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
20358 dump_die_for_error (src_die
);
20359 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
20360 " from DIE at 0x%x [in module %s]"),
20361 hex_string (signature
), src_die
->offset
.sect_off
,
20362 objfile_name ((*ref_cu
)->objfile
));
20368 /* Get the type specified by SIGNATURE referenced in DIE/CU,
20369 reading in and processing the type unit if necessary. */
20371 static struct type
*
20372 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
20373 struct dwarf2_cu
*cu
)
20375 struct signatured_type
*sig_type
;
20376 struct dwarf2_cu
*type_cu
;
20377 struct die_info
*type_die
;
20380 sig_type
= lookup_signatured_type (cu
, signature
);
20381 /* sig_type will be NULL if the signatured type is missing from
20383 if (sig_type
== NULL
)
20385 complaint (&symfile_complaints
,
20386 _("Dwarf Error: Cannot find signatured DIE %s referenced"
20387 " from DIE at 0x%x [in module %s]"),
20388 hex_string (signature
), die
->offset
.sect_off
,
20389 objfile_name (dwarf2_per_objfile
->objfile
));
20390 return build_error_marker_type (cu
, die
);
20393 /* If we already know the type we're done. */
20394 if (sig_type
->type
!= NULL
)
20395 return sig_type
->type
;
20398 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
20399 if (type_die
!= NULL
)
20401 /* N.B. We need to call get_die_type to ensure only one type for this DIE
20402 is created. This is important, for example, because for c++ classes
20403 we need TYPE_NAME set which is only done by new_symbol. Blech. */
20404 type
= read_type_die (type_die
, type_cu
);
20407 complaint (&symfile_complaints
,
20408 _("Dwarf Error: Cannot build signatured type %s"
20409 " referenced from DIE at 0x%x [in module %s]"),
20410 hex_string (signature
), die
->offset
.sect_off
,
20411 objfile_name (dwarf2_per_objfile
->objfile
));
20412 type
= build_error_marker_type (cu
, die
);
20417 complaint (&symfile_complaints
,
20418 _("Dwarf Error: Problem reading signatured DIE %s referenced"
20419 " from DIE at 0x%x [in module %s]"),
20420 hex_string (signature
), die
->offset
.sect_off
,
20421 objfile_name (dwarf2_per_objfile
->objfile
));
20422 type
= build_error_marker_type (cu
, die
);
20424 sig_type
->type
= type
;
20429 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
20430 reading in and processing the type unit if necessary. */
20432 static struct type
*
20433 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
20434 struct dwarf2_cu
*cu
) /* ARI: editCase function */
20436 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
20437 if (attr_form_is_ref (attr
))
20439 struct dwarf2_cu
*type_cu
= cu
;
20440 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
20442 return read_type_die (type_die
, type_cu
);
20444 else if (attr
->form
== DW_FORM_ref_sig8
)
20446 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
20450 complaint (&symfile_complaints
,
20451 _("Dwarf Error: DW_AT_signature has bad form %s in DIE"
20452 " at 0x%x [in module %s]"),
20453 dwarf_form_name (attr
->form
), die
->offset
.sect_off
,
20454 objfile_name (dwarf2_per_objfile
->objfile
));
20455 return build_error_marker_type (cu
, die
);
20459 /* Load the DIEs associated with type unit PER_CU into memory. */
20462 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
20464 struct signatured_type
*sig_type
;
20466 /* Caller is responsible for ensuring type_unit_groups don't get here. */
20467 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
20469 /* We have the per_cu, but we need the signatured_type.
20470 Fortunately this is an easy translation. */
20471 gdb_assert (per_cu
->is_debug_types
);
20472 sig_type
= (struct signatured_type
*) per_cu
;
20474 gdb_assert (per_cu
->cu
== NULL
);
20476 read_signatured_type (sig_type
);
20478 gdb_assert (per_cu
->cu
!= NULL
);
20481 /* die_reader_func for read_signatured_type.
20482 This is identical to load_full_comp_unit_reader,
20483 but is kept separate for now. */
20486 read_signatured_type_reader (const struct die_reader_specs
*reader
,
20487 const gdb_byte
*info_ptr
,
20488 struct die_info
*comp_unit_die
,
20492 struct dwarf2_cu
*cu
= reader
->cu
;
20494 gdb_assert (cu
->die_hash
== NULL
);
20496 htab_create_alloc_ex (cu
->header
.length
/ 12,
20500 &cu
->comp_unit_obstack
,
20501 hashtab_obstack_allocate
,
20502 dummy_obstack_deallocate
);
20505 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
20506 &info_ptr
, comp_unit_die
);
20507 cu
->dies
= comp_unit_die
;
20508 /* comp_unit_die is not stored in die_hash, no need. */
20510 /* We try not to read any attributes in this function, because not
20511 all CUs needed for references have been loaded yet, and symbol
20512 table processing isn't initialized. But we have to set the CU language,
20513 or we won't be able to build types correctly.
20514 Similarly, if we do not read the producer, we can not apply
20515 producer-specific interpretation. */
20516 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
20519 /* Read in a signatured type and build its CU and DIEs.
20520 If the type is a stub for the real type in a DWO file,
20521 read in the real type from the DWO file as well. */
20524 read_signatured_type (struct signatured_type
*sig_type
)
20526 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
20528 gdb_assert (per_cu
->is_debug_types
);
20529 gdb_assert (per_cu
->cu
== NULL
);
20531 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1,
20532 read_signatured_type_reader
, NULL
);
20533 sig_type
->per_cu
.tu_read
= 1;
20536 /* Decode simple location descriptions.
20537 Given a pointer to a dwarf block that defines a location, compute
20538 the location and return the value.
20540 NOTE drow/2003-11-18: This function is called in two situations
20541 now: for the address of static or global variables (partial symbols
20542 only) and for offsets into structures which are expected to be
20543 (more or less) constant. The partial symbol case should go away,
20544 and only the constant case should remain. That will let this
20545 function complain more accurately. A few special modes are allowed
20546 without complaint for global variables (for instance, global
20547 register values and thread-local values).
20549 A location description containing no operations indicates that the
20550 object is optimized out. The return value is 0 for that case.
20551 FIXME drow/2003-11-16: No callers check for this case any more; soon all
20552 callers will only want a very basic result and this can become a
20555 Note that stack[0] is unused except as a default error return. */
20558 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
20560 struct objfile
*objfile
= cu
->objfile
;
20562 size_t size
= blk
->size
;
20563 const gdb_byte
*data
= blk
->data
;
20564 CORE_ADDR stack
[64];
20566 unsigned int bytes_read
, unsnd
;
20572 stack
[++stacki
] = 0;
20611 stack
[++stacki
] = op
- DW_OP_lit0
;
20646 stack
[++stacki
] = op
- DW_OP_reg0
;
20648 dwarf2_complex_location_expr_complaint ();
20652 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
20654 stack
[++stacki
] = unsnd
;
20656 dwarf2_complex_location_expr_complaint ();
20660 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
20665 case DW_OP_const1u
:
20666 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
20670 case DW_OP_const1s
:
20671 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
20675 case DW_OP_const2u
:
20676 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
20680 case DW_OP_const2s
:
20681 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
20685 case DW_OP_const4u
:
20686 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
20690 case DW_OP_const4s
:
20691 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
20695 case DW_OP_const8u
:
20696 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
20701 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
20707 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
20712 stack
[stacki
+ 1] = stack
[stacki
];
20717 stack
[stacki
- 1] += stack
[stacki
];
20721 case DW_OP_plus_uconst
:
20722 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
20728 stack
[stacki
- 1] -= stack
[stacki
];
20733 /* If we're not the last op, then we definitely can't encode
20734 this using GDB's address_class enum. This is valid for partial
20735 global symbols, although the variable's address will be bogus
20738 dwarf2_complex_location_expr_complaint ();
20741 case DW_OP_GNU_push_tls_address
:
20742 /* The top of the stack has the offset from the beginning
20743 of the thread control block at which the variable is located. */
20744 /* Nothing should follow this operator, so the top of stack would
20746 /* This is valid for partial global symbols, but the variable's
20747 address will be bogus in the psymtab. Make it always at least
20748 non-zero to not look as a variable garbage collected by linker
20749 which have DW_OP_addr 0. */
20751 dwarf2_complex_location_expr_complaint ();
20755 case DW_OP_GNU_uninit
:
20758 case DW_OP_GNU_addr_index
:
20759 case DW_OP_GNU_const_index
:
20760 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
20767 const char *name
= get_DW_OP_name (op
);
20770 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
20773 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
20777 return (stack
[stacki
]);
20780 /* Enforce maximum stack depth of SIZE-1 to avoid writing
20781 outside of the allocated space. Also enforce minimum>0. */
20782 if (stacki
>= ARRAY_SIZE (stack
) - 1)
20784 complaint (&symfile_complaints
,
20785 _("location description stack overflow"));
20791 complaint (&symfile_complaints
,
20792 _("location description stack underflow"));
20796 return (stack
[stacki
]);
20799 /* memory allocation interface */
20801 static struct dwarf_block
*
20802 dwarf_alloc_block (struct dwarf2_cu
*cu
)
20804 struct dwarf_block
*blk
;
20806 blk
= (struct dwarf_block
*)
20807 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
20811 static struct die_info
*
20812 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
20814 struct die_info
*die
;
20815 size_t size
= sizeof (struct die_info
);
20818 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
20820 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
20821 memset (die
, 0, sizeof (struct die_info
));
20826 /* Macro support. */
20828 /* Return file name relative to the compilation directory of file number I in
20829 *LH's file name table. The result is allocated using xmalloc; the caller is
20830 responsible for freeing it. */
20833 file_file_name (int file
, struct line_header
*lh
)
20835 /* Is the file number a valid index into the line header's file name
20836 table? Remember that file numbers start with one, not zero. */
20837 if (1 <= file
&& file
<= lh
->num_file_names
)
20839 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
20841 if (IS_ABSOLUTE_PATH (fe
->name
) || fe
->dir_index
== 0
20842 || lh
->include_dirs
== NULL
)
20843 return xstrdup (fe
->name
);
20844 return concat (lh
->include_dirs
[fe
->dir_index
- 1], SLASH_STRING
,
20849 /* The compiler produced a bogus file number. We can at least
20850 record the macro definitions made in the file, even if we
20851 won't be able to find the file by name. */
20852 char fake_name
[80];
20854 xsnprintf (fake_name
, sizeof (fake_name
),
20855 "<bad macro file number %d>", file
);
20857 complaint (&symfile_complaints
,
20858 _("bad file number in macro information (%d)"),
20861 return xstrdup (fake_name
);
20865 /* Return the full name of file number I in *LH's file name table.
20866 Use COMP_DIR as the name of the current directory of the
20867 compilation. The result is allocated using xmalloc; the caller is
20868 responsible for freeing it. */
20870 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
20872 /* Is the file number a valid index into the line header's file name
20873 table? Remember that file numbers start with one, not zero. */
20874 if (1 <= file
&& file
<= lh
->num_file_names
)
20876 char *relative
= file_file_name (file
, lh
);
20878 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
20880 return reconcat (relative
, comp_dir
, SLASH_STRING
, relative
, NULL
);
20883 return file_file_name (file
, lh
);
20887 static struct macro_source_file
*
20888 macro_start_file (int file
, int line
,
20889 struct macro_source_file
*current_file
,
20890 struct line_header
*lh
)
20892 /* File name relative to the compilation directory of this source file. */
20893 char *file_name
= file_file_name (file
, lh
);
20895 if (! current_file
)
20897 /* Note: We don't create a macro table for this compilation unit
20898 at all until we actually get a filename. */
20899 struct macro_table
*macro_table
= get_macro_table ();
20901 /* If we have no current file, then this must be the start_file
20902 directive for the compilation unit's main source file. */
20903 current_file
= macro_set_main (macro_table
, file_name
);
20904 macro_define_special (macro_table
);
20907 current_file
= macro_include (current_file
, line
, file_name
);
20911 return current_file
;
20915 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
20916 followed by a null byte. */
20918 copy_string (const char *buf
, int len
)
20920 char *s
= xmalloc (len
+ 1);
20922 memcpy (s
, buf
, len
);
20928 static const char *
20929 consume_improper_spaces (const char *p
, const char *body
)
20933 complaint (&symfile_complaints
,
20934 _("macro definition contains spaces "
20935 "in formal argument list:\n`%s'"),
20947 parse_macro_definition (struct macro_source_file
*file
, int line
,
20952 /* The body string takes one of two forms. For object-like macro
20953 definitions, it should be:
20955 <macro name> " " <definition>
20957 For function-like macro definitions, it should be:
20959 <macro name> "() " <definition>
20961 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
20963 Spaces may appear only where explicitly indicated, and in the
20966 The Dwarf 2 spec says that an object-like macro's name is always
20967 followed by a space, but versions of GCC around March 2002 omit
20968 the space when the macro's definition is the empty string.
20970 The Dwarf 2 spec says that there should be no spaces between the
20971 formal arguments in a function-like macro's formal argument list,
20972 but versions of GCC around March 2002 include spaces after the
20976 /* Find the extent of the macro name. The macro name is terminated
20977 by either a space or null character (for an object-like macro) or
20978 an opening paren (for a function-like macro). */
20979 for (p
= body
; *p
; p
++)
20980 if (*p
== ' ' || *p
== '(')
20983 if (*p
== ' ' || *p
== '\0')
20985 /* It's an object-like macro. */
20986 int name_len
= p
- body
;
20987 char *name
= copy_string (body
, name_len
);
20988 const char *replacement
;
20991 replacement
= body
+ name_len
+ 1;
20994 dwarf2_macro_malformed_definition_complaint (body
);
20995 replacement
= body
+ name_len
;
20998 macro_define_object (file
, line
, name
, replacement
);
21002 else if (*p
== '(')
21004 /* It's a function-like macro. */
21005 char *name
= copy_string (body
, p
- body
);
21008 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
21012 p
= consume_improper_spaces (p
, body
);
21014 /* Parse the formal argument list. */
21015 while (*p
&& *p
!= ')')
21017 /* Find the extent of the current argument name. */
21018 const char *arg_start
= p
;
21020 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
21023 if (! *p
|| p
== arg_start
)
21024 dwarf2_macro_malformed_definition_complaint (body
);
21027 /* Make sure argv has room for the new argument. */
21028 if (argc
>= argv_size
)
21031 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
21034 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
21037 p
= consume_improper_spaces (p
, body
);
21039 /* Consume the comma, if present. */
21044 p
= consume_improper_spaces (p
, body
);
21053 /* Perfectly formed definition, no complaints. */
21054 macro_define_function (file
, line
, name
,
21055 argc
, (const char **) argv
,
21057 else if (*p
== '\0')
21059 /* Complain, but do define it. */
21060 dwarf2_macro_malformed_definition_complaint (body
);
21061 macro_define_function (file
, line
, name
,
21062 argc
, (const char **) argv
,
21066 /* Just complain. */
21067 dwarf2_macro_malformed_definition_complaint (body
);
21070 /* Just complain. */
21071 dwarf2_macro_malformed_definition_complaint (body
);
21077 for (i
= 0; i
< argc
; i
++)
21083 dwarf2_macro_malformed_definition_complaint (body
);
21086 /* Skip some bytes from BYTES according to the form given in FORM.
21087 Returns the new pointer. */
21089 static const gdb_byte
*
21090 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
21091 enum dwarf_form form
,
21092 unsigned int offset_size
,
21093 struct dwarf2_section_info
*section
)
21095 unsigned int bytes_read
;
21099 case DW_FORM_data1
:
21104 case DW_FORM_data2
:
21108 case DW_FORM_data4
:
21112 case DW_FORM_data8
:
21116 case DW_FORM_string
:
21117 read_direct_string (abfd
, bytes
, &bytes_read
);
21118 bytes
+= bytes_read
;
21121 case DW_FORM_sec_offset
:
21123 case DW_FORM_GNU_strp_alt
:
21124 bytes
+= offset_size
;
21127 case DW_FORM_block
:
21128 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
21129 bytes
+= bytes_read
;
21132 case DW_FORM_block1
:
21133 bytes
+= 1 + read_1_byte (abfd
, bytes
);
21135 case DW_FORM_block2
:
21136 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
21138 case DW_FORM_block4
:
21139 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
21142 case DW_FORM_sdata
:
21143 case DW_FORM_udata
:
21144 case DW_FORM_GNU_addr_index
:
21145 case DW_FORM_GNU_str_index
:
21146 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
21149 dwarf2_section_buffer_overflow_complaint (section
);
21157 complaint (&symfile_complaints
,
21158 _("invalid form 0x%x in `%s'"),
21159 form
, get_section_name (section
));
21167 /* A helper for dwarf_decode_macros that handles skipping an unknown
21168 opcode. Returns an updated pointer to the macro data buffer; or,
21169 on error, issues a complaint and returns NULL. */
21171 static const gdb_byte
*
21172 skip_unknown_opcode (unsigned int opcode
,
21173 const gdb_byte
**opcode_definitions
,
21174 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
21176 unsigned int offset_size
,
21177 struct dwarf2_section_info
*section
)
21179 unsigned int bytes_read
, i
;
21181 const gdb_byte
*defn
;
21183 if (opcode_definitions
[opcode
] == NULL
)
21185 complaint (&symfile_complaints
,
21186 _("unrecognized DW_MACFINO opcode 0x%x"),
21191 defn
= opcode_definitions
[opcode
];
21192 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
21193 defn
+= bytes_read
;
21195 for (i
= 0; i
< arg
; ++i
)
21197 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
21198 (enum dwarf_form
) defn
[i
], offset_size
,
21200 if (mac_ptr
== NULL
)
21202 /* skip_form_bytes already issued the complaint. */
21210 /* A helper function which parses the header of a macro section.
21211 If the macro section is the extended (for now called "GNU") type,
21212 then this updates *OFFSET_SIZE. Returns a pointer to just after
21213 the header, or issues a complaint and returns NULL on error. */
21215 static const gdb_byte
*
21216 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
21218 const gdb_byte
*mac_ptr
,
21219 unsigned int *offset_size
,
21220 int section_is_gnu
)
21222 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
21224 if (section_is_gnu
)
21226 unsigned int version
, flags
;
21228 version
= read_2_bytes (abfd
, mac_ptr
);
21231 complaint (&symfile_complaints
,
21232 _("unrecognized version `%d' in .debug_macro section"),
21238 flags
= read_1_byte (abfd
, mac_ptr
);
21240 *offset_size
= (flags
& 1) ? 8 : 4;
21242 if ((flags
& 2) != 0)
21243 /* We don't need the line table offset. */
21244 mac_ptr
+= *offset_size
;
21246 /* Vendor opcode descriptions. */
21247 if ((flags
& 4) != 0)
21249 unsigned int i
, count
;
21251 count
= read_1_byte (abfd
, mac_ptr
);
21253 for (i
= 0; i
< count
; ++i
)
21255 unsigned int opcode
, bytes_read
;
21258 opcode
= read_1_byte (abfd
, mac_ptr
);
21260 opcode_definitions
[opcode
] = mac_ptr
;
21261 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21262 mac_ptr
+= bytes_read
;
21271 /* A helper for dwarf_decode_macros that handles the GNU extensions,
21272 including DW_MACRO_GNU_transparent_include. */
21275 dwarf_decode_macro_bytes (bfd
*abfd
,
21276 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
21277 struct macro_source_file
*current_file
,
21278 struct line_header
*lh
,
21279 struct dwarf2_section_info
*section
,
21280 int section_is_gnu
, int section_is_dwz
,
21281 unsigned int offset_size
,
21282 htab_t include_hash
)
21284 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21285 enum dwarf_macro_record_type macinfo_type
;
21286 int at_commandline
;
21287 const gdb_byte
*opcode_definitions
[256];
21289 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
21290 &offset_size
, section_is_gnu
);
21291 if (mac_ptr
== NULL
)
21293 /* We already issued a complaint. */
21297 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
21298 GDB is still reading the definitions from command line. First
21299 DW_MACINFO_start_file will need to be ignored as it was already executed
21300 to create CURRENT_FILE for the main source holding also the command line
21301 definitions. On first met DW_MACINFO_start_file this flag is reset to
21302 normally execute all the remaining DW_MACINFO_start_file macinfos. */
21304 at_commandline
= 1;
21308 /* Do we at least have room for a macinfo type byte? */
21309 if (mac_ptr
>= mac_end
)
21311 dwarf2_section_buffer_overflow_complaint (section
);
21315 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
21318 /* Note that we rely on the fact that the corresponding GNU and
21319 DWARF constants are the same. */
21320 switch (macinfo_type
)
21322 /* A zero macinfo type indicates the end of the macro
21327 case DW_MACRO_GNU_define
:
21328 case DW_MACRO_GNU_undef
:
21329 case DW_MACRO_GNU_define_indirect
:
21330 case DW_MACRO_GNU_undef_indirect
:
21331 case DW_MACRO_GNU_define_indirect_alt
:
21332 case DW_MACRO_GNU_undef_indirect_alt
:
21334 unsigned int bytes_read
;
21339 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21340 mac_ptr
+= bytes_read
;
21342 if (macinfo_type
== DW_MACRO_GNU_define
21343 || macinfo_type
== DW_MACRO_GNU_undef
)
21345 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
21346 mac_ptr
+= bytes_read
;
21350 LONGEST str_offset
;
21352 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
21353 mac_ptr
+= offset_size
;
21355 if (macinfo_type
== DW_MACRO_GNU_define_indirect_alt
21356 || macinfo_type
== DW_MACRO_GNU_undef_indirect_alt
21359 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
21361 body
= read_indirect_string_from_dwz (dwz
, str_offset
);
21364 body
= read_indirect_string_at_offset (abfd
, str_offset
);
21367 is_define
= (macinfo_type
== DW_MACRO_GNU_define
21368 || macinfo_type
== DW_MACRO_GNU_define_indirect
21369 || macinfo_type
== DW_MACRO_GNU_define_indirect_alt
);
21370 if (! current_file
)
21372 /* DWARF violation as no main source is present. */
21373 complaint (&symfile_complaints
,
21374 _("debug info with no main source gives macro %s "
21376 is_define
? _("definition") : _("undefinition"),
21380 if ((line
== 0 && !at_commandline
)
21381 || (line
!= 0 && at_commandline
))
21382 complaint (&symfile_complaints
,
21383 _("debug info gives %s macro %s with %s line %d: %s"),
21384 at_commandline
? _("command-line") : _("in-file"),
21385 is_define
? _("definition") : _("undefinition"),
21386 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
21389 parse_macro_definition (current_file
, line
, body
);
21392 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
21393 || macinfo_type
== DW_MACRO_GNU_undef_indirect
21394 || macinfo_type
== DW_MACRO_GNU_undef_indirect_alt
);
21395 macro_undef (current_file
, line
, body
);
21400 case DW_MACRO_GNU_start_file
:
21402 unsigned int bytes_read
;
21405 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21406 mac_ptr
+= bytes_read
;
21407 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21408 mac_ptr
+= bytes_read
;
21410 if ((line
== 0 && !at_commandline
)
21411 || (line
!= 0 && at_commandline
))
21412 complaint (&symfile_complaints
,
21413 _("debug info gives source %d included "
21414 "from %s at %s line %d"),
21415 file
, at_commandline
? _("command-line") : _("file"),
21416 line
== 0 ? _("zero") : _("non-zero"), line
);
21418 if (at_commandline
)
21420 /* This DW_MACRO_GNU_start_file was executed in the
21422 at_commandline
= 0;
21425 current_file
= macro_start_file (file
, line
, current_file
, lh
);
21429 case DW_MACRO_GNU_end_file
:
21430 if (! current_file
)
21431 complaint (&symfile_complaints
,
21432 _("macro debug info has an unmatched "
21433 "`close_file' directive"));
21436 current_file
= current_file
->included_by
;
21437 if (! current_file
)
21439 enum dwarf_macro_record_type next_type
;
21441 /* GCC circa March 2002 doesn't produce the zero
21442 type byte marking the end of the compilation
21443 unit. Complain if it's not there, but exit no
21446 /* Do we at least have room for a macinfo type byte? */
21447 if (mac_ptr
>= mac_end
)
21449 dwarf2_section_buffer_overflow_complaint (section
);
21453 /* We don't increment mac_ptr here, so this is just
21456 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
21458 if (next_type
!= 0)
21459 complaint (&symfile_complaints
,
21460 _("no terminating 0-type entry for "
21461 "macros in `.debug_macinfo' section"));
21468 case DW_MACRO_GNU_transparent_include
:
21469 case DW_MACRO_GNU_transparent_include_alt
:
21473 bfd
*include_bfd
= abfd
;
21474 struct dwarf2_section_info
*include_section
= section
;
21475 struct dwarf2_section_info alt_section
;
21476 const gdb_byte
*include_mac_end
= mac_end
;
21477 int is_dwz
= section_is_dwz
;
21478 const gdb_byte
*new_mac_ptr
;
21480 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
21481 mac_ptr
+= offset_size
;
21483 if (macinfo_type
== DW_MACRO_GNU_transparent_include_alt
)
21485 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
21487 dwarf2_read_section (objfile
, &dwz
->macro
);
21489 include_section
= &dwz
->macro
;
21490 include_bfd
= get_section_bfd_owner (include_section
);
21491 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
21495 new_mac_ptr
= include_section
->buffer
+ offset
;
21496 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
21500 /* This has actually happened; see
21501 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
21502 complaint (&symfile_complaints
,
21503 _("recursive DW_MACRO_GNU_transparent_include in "
21504 ".debug_macro section"));
21508 *slot
= (void *) new_mac_ptr
;
21510 dwarf_decode_macro_bytes (include_bfd
, new_mac_ptr
,
21511 include_mac_end
, current_file
, lh
,
21512 section
, section_is_gnu
, is_dwz
,
21513 offset_size
, include_hash
);
21515 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
21520 case DW_MACINFO_vendor_ext
:
21521 if (!section_is_gnu
)
21523 unsigned int bytes_read
;
21526 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21527 mac_ptr
+= bytes_read
;
21528 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
21529 mac_ptr
+= bytes_read
;
21531 /* We don't recognize any vendor extensions. */
21537 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
21538 mac_ptr
, mac_end
, abfd
, offset_size
,
21540 if (mac_ptr
== NULL
)
21544 } while (macinfo_type
!= 0);
21548 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
21549 int section_is_gnu
)
21551 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21552 struct line_header
*lh
= cu
->line_header
;
21554 const gdb_byte
*mac_ptr
, *mac_end
;
21555 struct macro_source_file
*current_file
= 0;
21556 enum dwarf_macro_record_type macinfo_type
;
21557 unsigned int offset_size
= cu
->header
.offset_size
;
21558 const gdb_byte
*opcode_definitions
[256];
21559 struct cleanup
*cleanup
;
21560 htab_t include_hash
;
21562 struct dwarf2_section_info
*section
;
21563 const char *section_name
;
21565 if (cu
->dwo_unit
!= NULL
)
21567 if (section_is_gnu
)
21569 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
21570 section_name
= ".debug_macro.dwo";
21574 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
21575 section_name
= ".debug_macinfo.dwo";
21580 if (section_is_gnu
)
21582 section
= &dwarf2_per_objfile
->macro
;
21583 section_name
= ".debug_macro";
21587 section
= &dwarf2_per_objfile
->macinfo
;
21588 section_name
= ".debug_macinfo";
21592 dwarf2_read_section (objfile
, section
);
21593 if (section
->buffer
== NULL
)
21595 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
21598 abfd
= get_section_bfd_owner (section
);
21600 /* First pass: Find the name of the base filename.
21601 This filename is needed in order to process all macros whose definition
21602 (or undefinition) comes from the command line. These macros are defined
21603 before the first DW_MACINFO_start_file entry, and yet still need to be
21604 associated to the base file.
21606 To determine the base file name, we scan the macro definitions until we
21607 reach the first DW_MACINFO_start_file entry. We then initialize
21608 CURRENT_FILE accordingly so that any macro definition found before the
21609 first DW_MACINFO_start_file can still be associated to the base file. */
21611 mac_ptr
= section
->buffer
+ offset
;
21612 mac_end
= section
->buffer
+ section
->size
;
21614 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
21615 &offset_size
, section_is_gnu
);
21616 if (mac_ptr
== NULL
)
21618 /* We already issued a complaint. */
21624 /* Do we at least have room for a macinfo type byte? */
21625 if (mac_ptr
>= mac_end
)
21627 /* Complaint is printed during the second pass as GDB will probably
21628 stop the first pass earlier upon finding
21629 DW_MACINFO_start_file. */
21633 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
21636 /* Note that we rely on the fact that the corresponding GNU and
21637 DWARF constants are the same. */
21638 switch (macinfo_type
)
21640 /* A zero macinfo type indicates the end of the macro
21645 case DW_MACRO_GNU_define
:
21646 case DW_MACRO_GNU_undef
:
21647 /* Only skip the data by MAC_PTR. */
21649 unsigned int bytes_read
;
21651 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21652 mac_ptr
+= bytes_read
;
21653 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
21654 mac_ptr
+= bytes_read
;
21658 case DW_MACRO_GNU_start_file
:
21660 unsigned int bytes_read
;
21663 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21664 mac_ptr
+= bytes_read
;
21665 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21666 mac_ptr
+= bytes_read
;
21668 current_file
= macro_start_file (file
, line
, current_file
, lh
);
21672 case DW_MACRO_GNU_end_file
:
21673 /* No data to skip by MAC_PTR. */
21676 case DW_MACRO_GNU_define_indirect
:
21677 case DW_MACRO_GNU_undef_indirect
:
21678 case DW_MACRO_GNU_define_indirect_alt
:
21679 case DW_MACRO_GNU_undef_indirect_alt
:
21681 unsigned int bytes_read
;
21683 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21684 mac_ptr
+= bytes_read
;
21685 mac_ptr
+= offset_size
;
21689 case DW_MACRO_GNU_transparent_include
:
21690 case DW_MACRO_GNU_transparent_include_alt
:
21691 /* Note that, according to the spec, a transparent include
21692 chain cannot call DW_MACRO_GNU_start_file. So, we can just
21693 skip this opcode. */
21694 mac_ptr
+= offset_size
;
21697 case DW_MACINFO_vendor_ext
:
21698 /* Only skip the data by MAC_PTR. */
21699 if (!section_is_gnu
)
21701 unsigned int bytes_read
;
21703 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
21704 mac_ptr
+= bytes_read
;
21705 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
21706 mac_ptr
+= bytes_read
;
21711 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
21712 mac_ptr
, mac_end
, abfd
, offset_size
,
21714 if (mac_ptr
== NULL
)
21718 } while (macinfo_type
!= 0 && current_file
== NULL
);
21720 /* Second pass: Process all entries.
21722 Use the AT_COMMAND_LINE flag to determine whether we are still processing
21723 command-line macro definitions/undefinitions. This flag is unset when we
21724 reach the first DW_MACINFO_start_file entry. */
21726 include_hash
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
21727 NULL
, xcalloc
, xfree
);
21728 cleanup
= make_cleanup_htab_delete (include_hash
);
21729 mac_ptr
= section
->buffer
+ offset
;
21730 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
21731 *slot
= (void *) mac_ptr
;
21732 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
21733 current_file
, lh
, section
,
21734 section_is_gnu
, 0, offset_size
, include_hash
);
21735 do_cleanups (cleanup
);
21738 /* Check if the attribute's form is a DW_FORM_block*
21739 if so return true else false. */
21742 attr_form_is_block (const struct attribute
*attr
)
21744 return (attr
== NULL
? 0 :
21745 attr
->form
== DW_FORM_block1
21746 || attr
->form
== DW_FORM_block2
21747 || attr
->form
== DW_FORM_block4
21748 || attr
->form
== DW_FORM_block
21749 || attr
->form
== DW_FORM_exprloc
);
21752 /* Return non-zero if ATTR's value is a section offset --- classes
21753 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
21754 You may use DW_UNSND (attr) to retrieve such offsets.
21756 Section 7.5.4, "Attribute Encodings", explains that no attribute
21757 may have a value that belongs to more than one of these classes; it
21758 would be ambiguous if we did, because we use the same forms for all
21762 attr_form_is_section_offset (const struct attribute
*attr
)
21764 return (attr
->form
== DW_FORM_data4
21765 || attr
->form
== DW_FORM_data8
21766 || attr
->form
== DW_FORM_sec_offset
);
21769 /* Return non-zero if ATTR's value falls in the 'constant' class, or
21770 zero otherwise. When this function returns true, you can apply
21771 dwarf2_get_attr_constant_value to it.
21773 However, note that for some attributes you must check
21774 attr_form_is_section_offset before using this test. DW_FORM_data4
21775 and DW_FORM_data8 are members of both the constant class, and of
21776 the classes that contain offsets into other debug sections
21777 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
21778 that, if an attribute's can be either a constant or one of the
21779 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
21780 taken as section offsets, not constants. */
21783 attr_form_is_constant (const struct attribute
*attr
)
21785 switch (attr
->form
)
21787 case DW_FORM_sdata
:
21788 case DW_FORM_udata
:
21789 case DW_FORM_data1
:
21790 case DW_FORM_data2
:
21791 case DW_FORM_data4
:
21792 case DW_FORM_data8
:
21800 /* DW_ADDR is always stored already as sect_offset; despite for the forms
21801 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
21804 attr_form_is_ref (const struct attribute
*attr
)
21806 switch (attr
->form
)
21808 case DW_FORM_ref_addr
:
21813 case DW_FORM_ref_udata
:
21814 case DW_FORM_GNU_ref_alt
:
21821 /* Return the .debug_loc section to use for CU.
21822 For DWO files use .debug_loc.dwo. */
21824 static struct dwarf2_section_info
*
21825 cu_debug_loc_section (struct dwarf2_cu
*cu
)
21828 return &cu
->dwo_unit
->dwo_file
->sections
.loc
;
21829 return &dwarf2_per_objfile
->loc
;
21832 /* A helper function that fills in a dwarf2_loclist_baton. */
21835 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
21836 struct dwarf2_loclist_baton
*baton
,
21837 const struct attribute
*attr
)
21839 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
21841 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
21843 baton
->per_cu
= cu
->per_cu
;
21844 gdb_assert (baton
->per_cu
);
21845 /* We don't know how long the location list is, but make sure we
21846 don't run off the edge of the section. */
21847 baton
->size
= section
->size
- DW_UNSND (attr
);
21848 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
21849 baton
->base_address
= cu
->base_address
;
21850 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
21854 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
21855 struct dwarf2_cu
*cu
, int is_block
)
21857 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21858 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
21860 if (attr_form_is_section_offset (attr
)
21861 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
21862 the section. If so, fall through to the complaint in the
21864 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
21866 struct dwarf2_loclist_baton
*baton
;
21868 baton
= obstack_alloc (&objfile
->objfile_obstack
,
21869 sizeof (struct dwarf2_loclist_baton
));
21871 fill_in_loclist_baton (cu
, baton
, attr
);
21873 if (cu
->base_known
== 0)
21874 complaint (&symfile_complaints
,
21875 _("Location list used without "
21876 "specifying the CU base address."));
21878 SYMBOL_ACLASS_INDEX (sym
) = (is_block
21879 ? dwarf2_loclist_block_index
21880 : dwarf2_loclist_index
);
21881 SYMBOL_LOCATION_BATON (sym
) = baton
;
21885 struct dwarf2_locexpr_baton
*baton
;
21887 baton
= obstack_alloc (&objfile
->objfile_obstack
,
21888 sizeof (struct dwarf2_locexpr_baton
));
21889 baton
->per_cu
= cu
->per_cu
;
21890 gdb_assert (baton
->per_cu
);
21892 if (attr_form_is_block (attr
))
21894 /* Note that we're just copying the block's data pointer
21895 here, not the actual data. We're still pointing into the
21896 info_buffer for SYM's objfile; right now we never release
21897 that buffer, but when we do clean up properly this may
21899 baton
->size
= DW_BLOCK (attr
)->size
;
21900 baton
->data
= DW_BLOCK (attr
)->data
;
21904 dwarf2_invalid_attrib_class_complaint ("location description",
21905 SYMBOL_NATURAL_NAME (sym
));
21909 SYMBOL_ACLASS_INDEX (sym
) = (is_block
21910 ? dwarf2_locexpr_block_index
21911 : dwarf2_locexpr_index
);
21912 SYMBOL_LOCATION_BATON (sym
) = baton
;
21916 /* Return the OBJFILE associated with the compilation unit CU. If CU
21917 came from a separate debuginfo file, then the master objfile is
21921 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
21923 struct objfile
*objfile
= per_cu
->objfile
;
21925 /* Return the master objfile, so that we can report and look up the
21926 correct file containing this variable. */
21927 if (objfile
->separate_debug_objfile_backlink
)
21928 objfile
= objfile
->separate_debug_objfile_backlink
;
21933 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
21934 (CU_HEADERP is unused in such case) or prepare a temporary copy at
21935 CU_HEADERP first. */
21937 static const struct comp_unit_head
*
21938 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
21939 struct dwarf2_per_cu_data
*per_cu
)
21941 const gdb_byte
*info_ptr
;
21944 return &per_cu
->cu
->header
;
21946 info_ptr
= per_cu
->section
->buffer
+ per_cu
->offset
.sect_off
;
21948 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
21949 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->objfile
->obfd
);
21954 /* Return the address size given in the compilation unit header for CU. */
21957 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
21959 struct comp_unit_head cu_header_local
;
21960 const struct comp_unit_head
*cu_headerp
;
21962 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
21964 return cu_headerp
->addr_size
;
21967 /* Return the offset size given in the compilation unit header for CU. */
21970 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
21972 struct comp_unit_head cu_header_local
;
21973 const struct comp_unit_head
*cu_headerp
;
21975 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
21977 return cu_headerp
->offset_size
;
21980 /* See its dwarf2loc.h declaration. */
21983 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
21985 struct comp_unit_head cu_header_local
;
21986 const struct comp_unit_head
*cu_headerp
;
21988 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
21990 if (cu_headerp
->version
== 2)
21991 return cu_headerp
->addr_size
;
21993 return cu_headerp
->offset_size
;
21996 /* Return the text offset of the CU. The returned offset comes from
21997 this CU's objfile. If this objfile came from a separate debuginfo
21998 file, then the offset may be different from the corresponding
21999 offset in the parent objfile. */
22002 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
22004 struct objfile
*objfile
= per_cu
->objfile
;
22006 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
22009 /* Locate the .debug_info compilation unit from CU's objfile which contains
22010 the DIE at OFFSET. Raises an error on failure. */
22012 static struct dwarf2_per_cu_data
*
22013 dwarf2_find_containing_comp_unit (sect_offset offset
,
22014 unsigned int offset_in_dwz
,
22015 struct objfile
*objfile
)
22017 struct dwarf2_per_cu_data
*this_cu
;
22019 const sect_offset
*cu_off
;
22022 high
= dwarf2_per_objfile
->n_comp_units
- 1;
22025 struct dwarf2_per_cu_data
*mid_cu
;
22026 int mid
= low
+ (high
- low
) / 2;
22028 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
22029 cu_off
= &mid_cu
->offset
;
22030 if (mid_cu
->is_dwz
> offset_in_dwz
22031 || (mid_cu
->is_dwz
== offset_in_dwz
22032 && cu_off
->sect_off
>= offset
.sect_off
))
22037 gdb_assert (low
== high
);
22038 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
22039 cu_off
= &this_cu
->offset
;
22040 if (this_cu
->is_dwz
!= offset_in_dwz
|| cu_off
->sect_off
> offset
.sect_off
)
22042 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
22043 error (_("Dwarf Error: could not find partial DIE containing "
22044 "offset 0x%lx [in module %s]"),
22045 (long) offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
22047 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
.sect_off
22048 <= offset
.sect_off
);
22049 return dwarf2_per_objfile
->all_comp_units
[low
-1];
22053 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
22054 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
22055 && offset
.sect_off
>= this_cu
->offset
.sect_off
+ this_cu
->length
)
22056 error (_("invalid dwarf2 offset %u"), offset
.sect_off
);
22057 gdb_assert (offset
.sect_off
< this_cu
->offset
.sect_off
+ this_cu
->length
);
22062 /* Initialize dwarf2_cu CU, owned by PER_CU. */
22065 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
22067 memset (cu
, 0, sizeof (*cu
));
22069 cu
->per_cu
= per_cu
;
22070 cu
->objfile
= per_cu
->objfile
;
22071 obstack_init (&cu
->comp_unit_obstack
);
22074 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
22077 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
22078 enum language pretend_language
)
22080 struct attribute
*attr
;
22082 /* Set the language we're debugging. */
22083 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
22085 set_cu_language (DW_UNSND (attr
), cu
);
22088 cu
->language
= pretend_language
;
22089 cu
->language_defn
= language_def (cu
->language
);
22092 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
22095 /* Release one cached compilation unit, CU. We unlink it from the tree
22096 of compilation units, but we don't remove it from the read_in_chain;
22097 the caller is responsible for that.
22098 NOTE: DATA is a void * because this function is also used as a
22099 cleanup routine. */
22102 free_heap_comp_unit (void *data
)
22104 struct dwarf2_cu
*cu
= data
;
22106 gdb_assert (cu
->per_cu
!= NULL
);
22107 cu
->per_cu
->cu
= NULL
;
22110 obstack_free (&cu
->comp_unit_obstack
, NULL
);
22115 /* This cleanup function is passed the address of a dwarf2_cu on the stack
22116 when we're finished with it. We can't free the pointer itself, but be
22117 sure to unlink it from the cache. Also release any associated storage. */
22120 free_stack_comp_unit (void *data
)
22122 struct dwarf2_cu
*cu
= data
;
22124 gdb_assert (cu
->per_cu
!= NULL
);
22125 cu
->per_cu
->cu
= NULL
;
22128 obstack_free (&cu
->comp_unit_obstack
, NULL
);
22129 cu
->partial_dies
= NULL
;
22132 /* Free all cached compilation units. */
22135 free_cached_comp_units (void *data
)
22137 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
22139 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22140 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
22141 while (per_cu
!= NULL
)
22143 struct dwarf2_per_cu_data
*next_cu
;
22145 next_cu
= per_cu
->cu
->read_in_chain
;
22147 free_heap_comp_unit (per_cu
->cu
);
22148 *last_chain
= next_cu
;
22154 /* Increase the age counter on each cached compilation unit, and free
22155 any that are too old. */
22158 age_cached_comp_units (void)
22160 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
22162 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
22163 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22164 while (per_cu
!= NULL
)
22166 per_cu
->cu
->last_used
++;
22167 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
22168 dwarf2_mark (per_cu
->cu
);
22169 per_cu
= per_cu
->cu
->read_in_chain
;
22172 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22173 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
22174 while (per_cu
!= NULL
)
22176 struct dwarf2_per_cu_data
*next_cu
;
22178 next_cu
= per_cu
->cu
->read_in_chain
;
22180 if (!per_cu
->cu
->mark
)
22182 free_heap_comp_unit (per_cu
->cu
);
22183 *last_chain
= next_cu
;
22186 last_chain
= &per_cu
->cu
->read_in_chain
;
22192 /* Remove a single compilation unit from the cache. */
22195 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
22197 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
22199 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22200 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
22201 while (per_cu
!= NULL
)
22203 struct dwarf2_per_cu_data
*next_cu
;
22205 next_cu
= per_cu
->cu
->read_in_chain
;
22207 if (per_cu
== target_per_cu
)
22209 free_heap_comp_unit (per_cu
->cu
);
22211 *last_chain
= next_cu
;
22215 last_chain
= &per_cu
->cu
->read_in_chain
;
22221 /* Release all extra memory associated with OBJFILE. */
22224 dwarf2_free_objfile (struct objfile
*objfile
)
22226 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
22228 if (dwarf2_per_objfile
== NULL
)
22231 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
22232 free_cached_comp_units (NULL
);
22234 if (dwarf2_per_objfile
->quick_file_names_table
)
22235 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
22237 if (dwarf2_per_objfile
->line_header_hash
)
22238 htab_delete (dwarf2_per_objfile
->line_header_hash
);
22240 /* Everything else should be on the objfile obstack. */
22243 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
22244 We store these in a hash table separate from the DIEs, and preserve them
22245 when the DIEs are flushed out of cache.
22247 The CU "per_cu" pointer is needed because offset alone is not enough to
22248 uniquely identify the type. A file may have multiple .debug_types sections,
22249 or the type may come from a DWO file. Furthermore, while it's more logical
22250 to use per_cu->section+offset, with Fission the section with the data is in
22251 the DWO file but we don't know that section at the point we need it.
22252 We have to use something in dwarf2_per_cu_data (or the pointer to it)
22253 because we can enter the lookup routine, get_die_type_at_offset, from
22254 outside this file, and thus won't necessarily have PER_CU->cu.
22255 Fortunately, PER_CU is stable for the life of the objfile. */
22257 struct dwarf2_per_cu_offset_and_type
22259 const struct dwarf2_per_cu_data
*per_cu
;
22260 sect_offset offset
;
22264 /* Hash function for a dwarf2_per_cu_offset_and_type. */
22267 per_cu_offset_and_type_hash (const void *item
)
22269 const struct dwarf2_per_cu_offset_and_type
*ofs
= item
;
22271 return (uintptr_t) ofs
->per_cu
+ ofs
->offset
.sect_off
;
22274 /* Equality function for a dwarf2_per_cu_offset_and_type. */
22277 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
22279 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
= item_lhs
;
22280 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
= item_rhs
;
22282 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
22283 && ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
);
22286 /* Set the type associated with DIE to TYPE. Save it in CU's hash
22287 table if necessary. For convenience, return TYPE.
22289 The DIEs reading must have careful ordering to:
22290 * Not cause infite loops trying to read in DIEs as a prerequisite for
22291 reading current DIE.
22292 * Not trying to dereference contents of still incompletely read in types
22293 while reading in other DIEs.
22294 * Enable referencing still incompletely read in types just by a pointer to
22295 the type without accessing its fields.
22297 Therefore caller should follow these rules:
22298 * Try to fetch any prerequisite types we may need to build this DIE type
22299 before building the type and calling set_die_type.
22300 * After building type call set_die_type for current DIE as soon as
22301 possible before fetching more types to complete the current type.
22302 * Make the type as complete as possible before fetching more types. */
22304 static struct type
*
22305 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
22307 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
22308 struct objfile
*objfile
= cu
->objfile
;
22309 struct attribute
*attr
;
22310 struct dynamic_prop prop
;
22312 /* For Ada types, make sure that the gnat-specific data is always
22313 initialized (if not already set). There are a few types where
22314 we should not be doing so, because the type-specific area is
22315 already used to hold some other piece of info (eg: TYPE_CODE_FLT
22316 where the type-specific area is used to store the floatformat).
22317 But this is not a problem, because the gnat-specific information
22318 is actually not needed for these types. */
22319 if (need_gnat_info (cu
)
22320 && TYPE_CODE (type
) != TYPE_CODE_FUNC
22321 && TYPE_CODE (type
) != TYPE_CODE_FLT
22322 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
22323 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
22324 && TYPE_CODE (type
) != TYPE_CODE_METHOD
22325 && !HAVE_GNAT_AUX_INFO (type
))
22326 INIT_GNAT_SPECIFIC (type
);
22328 /* Read DW_AT_data_location and set in type. */
22329 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
22330 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
22331 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
, objfile
);
22333 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
22335 dwarf2_per_objfile
->die_type_hash
=
22336 htab_create_alloc_ex (127,
22337 per_cu_offset_and_type_hash
,
22338 per_cu_offset_and_type_eq
,
22340 &objfile
->objfile_obstack
,
22341 hashtab_obstack_allocate
,
22342 dummy_obstack_deallocate
);
22345 ofs
.per_cu
= cu
->per_cu
;
22346 ofs
.offset
= die
->offset
;
22348 slot
= (struct dwarf2_per_cu_offset_and_type
**)
22349 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
22351 complaint (&symfile_complaints
,
22352 _("A problem internal to GDB: DIE 0x%x has type already set"),
22353 die
->offset
.sect_off
);
22354 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
22359 /* Look up the type for the die at OFFSET in PER_CU in die_type_hash,
22360 or return NULL if the die does not have a saved type. */
22362 static struct type
*
22363 get_die_type_at_offset (sect_offset offset
,
22364 struct dwarf2_per_cu_data
*per_cu
)
22366 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
22368 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
22371 ofs
.per_cu
= per_cu
;
22372 ofs
.offset
= offset
;
22373 slot
= htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
);
22380 /* Look up the type for DIE in CU in die_type_hash,
22381 or return NULL if DIE does not have a saved type. */
22383 static struct type
*
22384 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22386 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
22389 /* Add a dependence relationship from CU to REF_PER_CU. */
22392 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
22393 struct dwarf2_per_cu_data
*ref_per_cu
)
22397 if (cu
->dependencies
== NULL
)
22399 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
22400 NULL
, &cu
->comp_unit_obstack
,
22401 hashtab_obstack_allocate
,
22402 dummy_obstack_deallocate
);
22404 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
22406 *slot
= ref_per_cu
;
22409 /* Subroutine of dwarf2_mark to pass to htab_traverse.
22410 Set the mark field in every compilation unit in the
22411 cache that we must keep because we are keeping CU. */
22414 dwarf2_mark_helper (void **slot
, void *data
)
22416 struct dwarf2_per_cu_data
*per_cu
;
22418 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
22420 /* cu->dependencies references may not yet have been ever read if QUIT aborts
22421 reading of the chain. As such dependencies remain valid it is not much
22422 useful to track and undo them during QUIT cleanups. */
22423 if (per_cu
->cu
== NULL
)
22426 if (per_cu
->cu
->mark
)
22428 per_cu
->cu
->mark
= 1;
22430 if (per_cu
->cu
->dependencies
!= NULL
)
22431 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
22436 /* Set the mark field in CU and in every other compilation unit in the
22437 cache that we must keep because we are keeping CU. */
22440 dwarf2_mark (struct dwarf2_cu
*cu
)
22445 if (cu
->dependencies
!= NULL
)
22446 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
22450 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
22454 per_cu
->cu
->mark
= 0;
22455 per_cu
= per_cu
->cu
->read_in_chain
;
22459 /* Trivial hash function for partial_die_info: the hash value of a DIE
22460 is its offset in .debug_info for this objfile. */
22463 partial_die_hash (const void *item
)
22465 const struct partial_die_info
*part_die
= item
;
22467 return part_die
->offset
.sect_off
;
22470 /* Trivial comparison function for partial_die_info structures: two DIEs
22471 are equal if they have the same offset. */
22474 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
22476 const struct partial_die_info
*part_die_lhs
= item_lhs
;
22477 const struct partial_die_info
*part_die_rhs
= item_rhs
;
22479 return part_die_lhs
->offset
.sect_off
== part_die_rhs
->offset
.sect_off
;
22482 static struct cmd_list_element
*set_dwarf_cmdlist
;
22483 static struct cmd_list_element
*show_dwarf_cmdlist
;
22486 set_dwarf_cmd (char *args
, int from_tty
)
22488 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
22493 show_dwarf_cmd (char *args
, int from_tty
)
22495 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
22498 /* Free data associated with OBJFILE, if necessary. */
22501 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
22503 struct dwarf2_per_objfile
*data
= d
;
22506 /* Make sure we don't accidentally use dwarf2_per_objfile while
22508 dwarf2_per_objfile
= NULL
;
22510 for (ix
= 0; ix
< data
->n_comp_units
; ++ix
)
22511 VEC_free (dwarf2_per_cu_ptr
, data
->all_comp_units
[ix
]->imported_symtabs
);
22513 for (ix
= 0; ix
< data
->n_type_units
; ++ix
)
22514 VEC_free (dwarf2_per_cu_ptr
,
22515 data
->all_type_units
[ix
]->per_cu
.imported_symtabs
);
22516 xfree (data
->all_type_units
);
22518 VEC_free (dwarf2_section_info_def
, data
->types
);
22520 if (data
->dwo_files
)
22521 free_dwo_files (data
->dwo_files
, objfile
);
22522 if (data
->dwp_file
)
22523 gdb_bfd_unref (data
->dwp_file
->dbfd
);
22525 if (data
->dwz_file
&& data
->dwz_file
->dwz_bfd
)
22526 gdb_bfd_unref (data
->dwz_file
->dwz_bfd
);
22530 /* The "save gdb-index" command. */
22532 /* The contents of the hash table we create when building the string
22534 struct strtab_entry
22536 offset_type offset
;
22540 /* Hash function for a strtab_entry.
22542 Function is used only during write_hash_table so no index format backward
22543 compatibility is needed. */
22546 hash_strtab_entry (const void *e
)
22548 const struct strtab_entry
*entry
= e
;
22549 return mapped_index_string_hash (INT_MAX
, entry
->str
);
22552 /* Equality function for a strtab_entry. */
22555 eq_strtab_entry (const void *a
, const void *b
)
22557 const struct strtab_entry
*ea
= a
;
22558 const struct strtab_entry
*eb
= b
;
22559 return !strcmp (ea
->str
, eb
->str
);
22562 /* Create a strtab_entry hash table. */
22565 create_strtab (void)
22567 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
22568 xfree
, xcalloc
, xfree
);
22571 /* Add a string to the constant pool. Return the string's offset in
22575 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
22578 struct strtab_entry entry
;
22579 struct strtab_entry
*result
;
22582 slot
= htab_find_slot (table
, &entry
, INSERT
);
22587 result
= XNEW (struct strtab_entry
);
22588 result
->offset
= obstack_object_size (cpool
);
22590 obstack_grow_str0 (cpool
, str
);
22593 return result
->offset
;
22596 /* An entry in the symbol table. */
22597 struct symtab_index_entry
22599 /* The name of the symbol. */
22601 /* The offset of the name in the constant pool. */
22602 offset_type index_offset
;
22603 /* A sorted vector of the indices of all the CUs that hold an object
22605 VEC (offset_type
) *cu_indices
;
22608 /* The symbol table. This is a power-of-2-sized hash table. */
22609 struct mapped_symtab
22611 offset_type n_elements
;
22613 struct symtab_index_entry
**data
;
22616 /* Hash function for a symtab_index_entry. */
22619 hash_symtab_entry (const void *e
)
22621 const struct symtab_index_entry
*entry
= e
;
22622 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
22623 sizeof (offset_type
) * VEC_length (offset_type
,
22624 entry
->cu_indices
),
22628 /* Equality function for a symtab_index_entry. */
22631 eq_symtab_entry (const void *a
, const void *b
)
22633 const struct symtab_index_entry
*ea
= a
;
22634 const struct symtab_index_entry
*eb
= b
;
22635 int len
= VEC_length (offset_type
, ea
->cu_indices
);
22636 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
22638 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
22639 VEC_address (offset_type
, eb
->cu_indices
),
22640 sizeof (offset_type
) * len
);
22643 /* Destroy a symtab_index_entry. */
22646 delete_symtab_entry (void *p
)
22648 struct symtab_index_entry
*entry
= p
;
22649 VEC_free (offset_type
, entry
->cu_indices
);
22653 /* Create a hash table holding symtab_index_entry objects. */
22656 create_symbol_hash_table (void)
22658 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
22659 delete_symtab_entry
, xcalloc
, xfree
);
22662 /* Create a new mapped symtab object. */
22664 static struct mapped_symtab
*
22665 create_mapped_symtab (void)
22667 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
22668 symtab
->n_elements
= 0;
22669 symtab
->size
= 1024;
22670 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
22674 /* Destroy a mapped_symtab. */
22677 cleanup_mapped_symtab (void *p
)
22679 struct mapped_symtab
*symtab
= p
;
22680 /* The contents of the array are freed when the other hash table is
22682 xfree (symtab
->data
);
22686 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
22689 Function is used only during write_hash_table so no index format backward
22690 compatibility is needed. */
22692 static struct symtab_index_entry
**
22693 find_slot (struct mapped_symtab
*symtab
, const char *name
)
22695 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
22697 index
= hash
& (symtab
->size
- 1);
22698 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
22702 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
22703 return &symtab
->data
[index
];
22704 index
= (index
+ step
) & (symtab
->size
- 1);
22708 /* Expand SYMTAB's hash table. */
22711 hash_expand (struct mapped_symtab
*symtab
)
22713 offset_type old_size
= symtab
->size
;
22715 struct symtab_index_entry
**old_entries
= symtab
->data
;
22718 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
22720 for (i
= 0; i
< old_size
; ++i
)
22722 if (old_entries
[i
])
22724 struct symtab_index_entry
**slot
= find_slot (symtab
,
22725 old_entries
[i
]->name
);
22726 *slot
= old_entries
[i
];
22730 xfree (old_entries
);
22733 /* Add an entry to SYMTAB. NAME is the name of the symbol.
22734 CU_INDEX is the index of the CU in which the symbol appears.
22735 IS_STATIC is one if the symbol is static, otherwise zero (global). */
22738 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
22739 int is_static
, gdb_index_symbol_kind kind
,
22740 offset_type cu_index
)
22742 struct symtab_index_entry
**slot
;
22743 offset_type cu_index_and_attrs
;
22745 ++symtab
->n_elements
;
22746 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
22747 hash_expand (symtab
);
22749 slot
= find_slot (symtab
, name
);
22752 *slot
= XNEW (struct symtab_index_entry
);
22753 (*slot
)->name
= name
;
22754 /* index_offset is set later. */
22755 (*slot
)->cu_indices
= NULL
;
22758 cu_index_and_attrs
= 0;
22759 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
22760 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
22761 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
22763 /* We don't want to record an index value twice as we want to avoid the
22765 We process all global symbols and then all static symbols
22766 (which would allow us to avoid the duplication by only having to check
22767 the last entry pushed), but a symbol could have multiple kinds in one CU.
22768 To keep things simple we don't worry about the duplication here and
22769 sort and uniqufy the list after we've processed all symbols. */
22770 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index_and_attrs
);
22773 /* qsort helper routine for uniquify_cu_indices. */
22776 offset_type_compare (const void *ap
, const void *bp
)
22778 offset_type a
= *(offset_type
*) ap
;
22779 offset_type b
= *(offset_type
*) bp
;
22781 return (a
> b
) - (b
> a
);
22784 /* Sort and remove duplicates of all symbols' cu_indices lists. */
22787 uniquify_cu_indices (struct mapped_symtab
*symtab
)
22791 for (i
= 0; i
< symtab
->size
; ++i
)
22793 struct symtab_index_entry
*entry
= symtab
->data
[i
];
22796 && entry
->cu_indices
!= NULL
)
22798 unsigned int next_to_insert
, next_to_check
;
22799 offset_type last_value
;
22801 qsort (VEC_address (offset_type
, entry
->cu_indices
),
22802 VEC_length (offset_type
, entry
->cu_indices
),
22803 sizeof (offset_type
), offset_type_compare
);
22805 last_value
= VEC_index (offset_type
, entry
->cu_indices
, 0);
22806 next_to_insert
= 1;
22807 for (next_to_check
= 1;
22808 next_to_check
< VEC_length (offset_type
, entry
->cu_indices
);
22811 if (VEC_index (offset_type
, entry
->cu_indices
, next_to_check
)
22814 last_value
= VEC_index (offset_type
, entry
->cu_indices
,
22816 VEC_replace (offset_type
, entry
->cu_indices
, next_to_insert
,
22821 VEC_truncate (offset_type
, entry
->cu_indices
, next_to_insert
);
22826 /* Add a vector of indices to the constant pool. */
22829 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
22830 struct symtab_index_entry
*entry
)
22834 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
22837 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
22838 offset_type val
= MAYBE_SWAP (len
);
22843 entry
->index_offset
= obstack_object_size (cpool
);
22845 obstack_grow (cpool
, &val
, sizeof (val
));
22847 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
22850 val
= MAYBE_SWAP (iter
);
22851 obstack_grow (cpool
, &val
, sizeof (val
));
22856 struct symtab_index_entry
*old_entry
= *slot
;
22857 entry
->index_offset
= old_entry
->index_offset
;
22860 return entry
->index_offset
;
22863 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
22864 constant pool entries going into the obstack CPOOL. */
22867 write_hash_table (struct mapped_symtab
*symtab
,
22868 struct obstack
*output
, struct obstack
*cpool
)
22871 htab_t symbol_hash_table
;
22874 symbol_hash_table
= create_symbol_hash_table ();
22875 str_table
= create_strtab ();
22877 /* We add all the index vectors to the constant pool first, to
22878 ensure alignment is ok. */
22879 for (i
= 0; i
< symtab
->size
; ++i
)
22881 if (symtab
->data
[i
])
22882 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
22885 /* Now write out the hash table. */
22886 for (i
= 0; i
< symtab
->size
; ++i
)
22888 offset_type str_off
, vec_off
;
22890 if (symtab
->data
[i
])
22892 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
22893 vec_off
= symtab
->data
[i
]->index_offset
;
22897 /* While 0 is a valid constant pool index, it is not valid
22898 to have 0 for both offsets. */
22903 str_off
= MAYBE_SWAP (str_off
);
22904 vec_off
= MAYBE_SWAP (vec_off
);
22906 obstack_grow (output
, &str_off
, sizeof (str_off
));
22907 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
22910 htab_delete (str_table
);
22911 htab_delete (symbol_hash_table
);
22914 /* Struct to map psymtab to CU index in the index file. */
22915 struct psymtab_cu_index_map
22917 struct partial_symtab
*psymtab
;
22918 unsigned int cu_index
;
22922 hash_psymtab_cu_index (const void *item
)
22924 const struct psymtab_cu_index_map
*map
= item
;
22926 return htab_hash_pointer (map
->psymtab
);
22930 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
22932 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
22933 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
22935 return lhs
->psymtab
== rhs
->psymtab
;
22938 /* Helper struct for building the address table. */
22939 struct addrmap_index_data
22941 struct objfile
*objfile
;
22942 struct obstack
*addr_obstack
;
22943 htab_t cu_index_htab
;
22945 /* Non-zero if the previous_* fields are valid.
22946 We can't write an entry until we see the next entry (since it is only then
22947 that we know the end of the entry). */
22948 int previous_valid
;
22949 /* Index of the CU in the table of all CUs in the index file. */
22950 unsigned int previous_cu_index
;
22951 /* Start address of the CU. */
22952 CORE_ADDR previous_cu_start
;
22955 /* Write an address entry to OBSTACK. */
22958 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
22959 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
22961 offset_type cu_index_to_write
;
22963 CORE_ADDR baseaddr
;
22965 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
22967 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
22968 obstack_grow (obstack
, addr
, 8);
22969 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
22970 obstack_grow (obstack
, addr
, 8);
22971 cu_index_to_write
= MAYBE_SWAP (cu_index
);
22972 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
22975 /* Worker function for traversing an addrmap to build the address table. */
22978 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
22980 struct addrmap_index_data
*data
= datap
;
22981 struct partial_symtab
*pst
= obj
;
22983 if (data
->previous_valid
)
22984 add_address_entry (data
->objfile
, data
->addr_obstack
,
22985 data
->previous_cu_start
, start_addr
,
22986 data
->previous_cu_index
);
22988 data
->previous_cu_start
= start_addr
;
22991 struct psymtab_cu_index_map find_map
, *map
;
22992 find_map
.psymtab
= pst
;
22993 map
= htab_find (data
->cu_index_htab
, &find_map
);
22994 gdb_assert (map
!= NULL
);
22995 data
->previous_cu_index
= map
->cu_index
;
22996 data
->previous_valid
= 1;
22999 data
->previous_valid
= 0;
23004 /* Write OBJFILE's address map to OBSTACK.
23005 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
23006 in the index file. */
23009 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
23010 htab_t cu_index_htab
)
23012 struct addrmap_index_data addrmap_index_data
;
23014 /* When writing the address table, we have to cope with the fact that
23015 the addrmap iterator only provides the start of a region; we have to
23016 wait until the next invocation to get the start of the next region. */
23018 addrmap_index_data
.objfile
= objfile
;
23019 addrmap_index_data
.addr_obstack
= obstack
;
23020 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
23021 addrmap_index_data
.previous_valid
= 0;
23023 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
23024 &addrmap_index_data
);
23026 /* It's highly unlikely the last entry (end address = 0xff...ff)
23027 is valid, but we should still handle it.
23028 The end address is recorded as the start of the next region, but that
23029 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
23031 if (addrmap_index_data
.previous_valid
)
23032 add_address_entry (objfile
, obstack
,
23033 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
23034 addrmap_index_data
.previous_cu_index
);
23037 /* Return the symbol kind of PSYM. */
23039 static gdb_index_symbol_kind
23040 symbol_kind (struct partial_symbol
*psym
)
23042 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
23043 enum address_class aclass
= PSYMBOL_CLASS (psym
);
23051 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
23053 return GDB_INDEX_SYMBOL_KIND_TYPE
;
23055 case LOC_CONST_BYTES
:
23056 case LOC_OPTIMIZED_OUT
:
23058 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
23060 /* Note: It's currently impossible to recognize psyms as enum values
23061 short of reading the type info. For now punt. */
23062 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
23064 /* There are other LOC_FOO values that one might want to classify
23065 as variables, but dwarf2read.c doesn't currently use them. */
23066 return GDB_INDEX_SYMBOL_KIND_OTHER
;
23068 case STRUCT_DOMAIN
:
23069 return GDB_INDEX_SYMBOL_KIND_TYPE
;
23071 return GDB_INDEX_SYMBOL_KIND_OTHER
;
23075 /* Add a list of partial symbols to SYMTAB. */
23078 write_psymbols (struct mapped_symtab
*symtab
,
23080 struct partial_symbol
**psymp
,
23082 offset_type cu_index
,
23085 for (; count
-- > 0; ++psymp
)
23087 struct partial_symbol
*psym
= *psymp
;
23090 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
23091 error (_("Ada is not currently supported by the index"));
23093 /* Only add a given psymbol once. */
23094 slot
= htab_find_slot (psyms_seen
, psym
, INSERT
);
23097 gdb_index_symbol_kind kind
= symbol_kind (psym
);
23100 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
23101 is_static
, kind
, cu_index
);
23106 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
23107 exception if there is an error. */
23110 write_obstack (FILE *file
, struct obstack
*obstack
)
23112 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
23114 != obstack_object_size (obstack
))
23115 error (_("couldn't data write to file"));
23118 /* Unlink a file if the argument is not NULL. */
23121 unlink_if_set (void *p
)
23123 char **filename
= p
;
23125 unlink (*filename
);
23128 /* A helper struct used when iterating over debug_types. */
23129 struct signatured_type_index_data
23131 struct objfile
*objfile
;
23132 struct mapped_symtab
*symtab
;
23133 struct obstack
*types_list
;
23138 /* A helper function that writes a single signatured_type to an
23142 write_one_signatured_type (void **slot
, void *d
)
23144 struct signatured_type_index_data
*info
= d
;
23145 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
23146 struct partial_symtab
*psymtab
= entry
->per_cu
.v
.psymtab
;
23149 write_psymbols (info
->symtab
,
23151 info
->objfile
->global_psymbols
.list
23152 + psymtab
->globals_offset
,
23153 psymtab
->n_global_syms
, info
->cu_index
,
23155 write_psymbols (info
->symtab
,
23157 info
->objfile
->static_psymbols
.list
23158 + psymtab
->statics_offset
,
23159 psymtab
->n_static_syms
, info
->cu_index
,
23162 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
23163 entry
->per_cu
.offset
.sect_off
);
23164 obstack_grow (info
->types_list
, val
, 8);
23165 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
23166 entry
->type_offset_in_tu
.cu_off
);
23167 obstack_grow (info
->types_list
, val
, 8);
23168 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
23169 obstack_grow (info
->types_list
, val
, 8);
23176 /* Recurse into all "included" dependencies and write their symbols as
23177 if they appeared in this psymtab. */
23180 recursively_write_psymbols (struct objfile
*objfile
,
23181 struct partial_symtab
*psymtab
,
23182 struct mapped_symtab
*symtab
,
23184 offset_type cu_index
)
23188 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
23189 if (psymtab
->dependencies
[i
]->user
!= NULL
)
23190 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
23191 symtab
, psyms_seen
, cu_index
);
23193 write_psymbols (symtab
,
23195 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
23196 psymtab
->n_global_syms
, cu_index
,
23198 write_psymbols (symtab
,
23200 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
23201 psymtab
->n_static_syms
, cu_index
,
23205 /* Create an index file for OBJFILE in the directory DIR. */
23208 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
23210 struct cleanup
*cleanup
;
23211 char *filename
, *cleanup_filename
;
23212 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
23213 struct obstack cu_list
, types_cu_list
;
23216 struct mapped_symtab
*symtab
;
23217 offset_type val
, size_of_contents
, total_len
;
23220 htab_t cu_index_htab
;
23221 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
23223 if (dwarf2_per_objfile
->using_index
)
23224 error (_("Cannot use an index to create the index"));
23226 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
23227 error (_("Cannot make an index when the file has multiple .debug_types sections"));
23229 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
23232 if (stat (objfile_name (objfile
), &st
) < 0)
23233 perror_with_name (objfile_name (objfile
));
23235 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile_name (objfile
)),
23236 INDEX_SUFFIX
, (char *) NULL
);
23237 cleanup
= make_cleanup (xfree
, filename
);
23239 out_file
= gdb_fopen_cloexec (filename
, "wb");
23241 error (_("Can't open `%s' for writing"), filename
);
23243 cleanup_filename
= filename
;
23244 make_cleanup (unlink_if_set
, &cleanup_filename
);
23246 symtab
= create_mapped_symtab ();
23247 make_cleanup (cleanup_mapped_symtab
, symtab
);
23249 obstack_init (&addr_obstack
);
23250 make_cleanup_obstack_free (&addr_obstack
);
23252 obstack_init (&cu_list
);
23253 make_cleanup_obstack_free (&cu_list
);
23255 obstack_init (&types_cu_list
);
23256 make_cleanup_obstack_free (&types_cu_list
);
23258 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
23259 NULL
, xcalloc
, xfree
);
23260 make_cleanup_htab_delete (psyms_seen
);
23262 /* While we're scanning CU's create a table that maps a psymtab pointer
23263 (which is what addrmap records) to its index (which is what is recorded
23264 in the index file). This will later be needed to write the address
23266 cu_index_htab
= htab_create_alloc (100,
23267 hash_psymtab_cu_index
,
23268 eq_psymtab_cu_index
,
23269 NULL
, xcalloc
, xfree
);
23270 make_cleanup_htab_delete (cu_index_htab
);
23271 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
23272 xmalloc (sizeof (struct psymtab_cu_index_map
)
23273 * dwarf2_per_objfile
->n_comp_units
);
23274 make_cleanup (xfree
, psymtab_cu_index_map
);
23276 /* The CU list is already sorted, so we don't need to do additional
23277 work here. Also, the debug_types entries do not appear in
23278 all_comp_units, but only in their own hash table. */
23279 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
23281 struct dwarf2_per_cu_data
*per_cu
23282 = dwarf2_per_objfile
->all_comp_units
[i
];
23283 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
23285 struct psymtab_cu_index_map
*map
;
23288 /* CU of a shared file from 'dwz -m' may be unused by this main file.
23289 It may be referenced from a local scope but in such case it does not
23290 need to be present in .gdb_index. */
23291 if (psymtab
== NULL
)
23294 if (psymtab
->user
== NULL
)
23295 recursively_write_psymbols (objfile
, psymtab
, symtab
, psyms_seen
, i
);
23297 map
= &psymtab_cu_index_map
[i
];
23298 map
->psymtab
= psymtab
;
23300 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
23301 gdb_assert (slot
!= NULL
);
23302 gdb_assert (*slot
== NULL
);
23305 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
23306 per_cu
->offset
.sect_off
);
23307 obstack_grow (&cu_list
, val
, 8);
23308 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
23309 obstack_grow (&cu_list
, val
, 8);
23312 /* Dump the address map. */
23313 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
23315 /* Write out the .debug_type entries, if any. */
23316 if (dwarf2_per_objfile
->signatured_types
)
23318 struct signatured_type_index_data sig_data
;
23320 sig_data
.objfile
= objfile
;
23321 sig_data
.symtab
= symtab
;
23322 sig_data
.types_list
= &types_cu_list
;
23323 sig_data
.psyms_seen
= psyms_seen
;
23324 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
23325 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
23326 write_one_signatured_type
, &sig_data
);
23329 /* Now that we've processed all symbols we can shrink their cu_indices
23331 uniquify_cu_indices (symtab
);
23333 obstack_init (&constant_pool
);
23334 make_cleanup_obstack_free (&constant_pool
);
23335 obstack_init (&symtab_obstack
);
23336 make_cleanup_obstack_free (&symtab_obstack
);
23337 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
23339 obstack_init (&contents
);
23340 make_cleanup_obstack_free (&contents
);
23341 size_of_contents
= 6 * sizeof (offset_type
);
23342 total_len
= size_of_contents
;
23344 /* The version number. */
23345 val
= MAYBE_SWAP (8);
23346 obstack_grow (&contents
, &val
, sizeof (val
));
23348 /* The offset of the CU list from the start of the file. */
23349 val
= MAYBE_SWAP (total_len
);
23350 obstack_grow (&contents
, &val
, sizeof (val
));
23351 total_len
+= obstack_object_size (&cu_list
);
23353 /* The offset of the types CU list from the start of the file. */
23354 val
= MAYBE_SWAP (total_len
);
23355 obstack_grow (&contents
, &val
, sizeof (val
));
23356 total_len
+= obstack_object_size (&types_cu_list
);
23358 /* The offset of the address table from the start of the file. */
23359 val
= MAYBE_SWAP (total_len
);
23360 obstack_grow (&contents
, &val
, sizeof (val
));
23361 total_len
+= obstack_object_size (&addr_obstack
);
23363 /* The offset of the symbol table from the start of the file. */
23364 val
= MAYBE_SWAP (total_len
);
23365 obstack_grow (&contents
, &val
, sizeof (val
));
23366 total_len
+= obstack_object_size (&symtab_obstack
);
23368 /* The offset of the constant pool from the start of the file. */
23369 val
= MAYBE_SWAP (total_len
);
23370 obstack_grow (&contents
, &val
, sizeof (val
));
23371 total_len
+= obstack_object_size (&constant_pool
);
23373 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
23375 write_obstack (out_file
, &contents
);
23376 write_obstack (out_file
, &cu_list
);
23377 write_obstack (out_file
, &types_cu_list
);
23378 write_obstack (out_file
, &addr_obstack
);
23379 write_obstack (out_file
, &symtab_obstack
);
23380 write_obstack (out_file
, &constant_pool
);
23384 /* We want to keep the file, so we set cleanup_filename to NULL
23385 here. See unlink_if_set. */
23386 cleanup_filename
= NULL
;
23388 do_cleanups (cleanup
);
23391 /* Implementation of the `save gdb-index' command.
23393 Note that the file format used by this command is documented in the
23394 GDB manual. Any changes here must be documented there. */
23397 save_gdb_index_command (char *arg
, int from_tty
)
23399 struct objfile
*objfile
;
23402 error (_("usage: save gdb-index DIRECTORY"));
23404 ALL_OBJFILES (objfile
)
23408 /* If the objfile does not correspond to an actual file, skip it. */
23409 if (stat (objfile_name (objfile
), &st
) < 0)
23412 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
23413 if (dwarf2_per_objfile
)
23418 write_psymtabs_to_index (objfile
, arg
);
23420 CATCH (except
, RETURN_MASK_ERROR
)
23422 exception_fprintf (gdb_stderr
, except
,
23423 _("Error while writing index for `%s': "),
23424 objfile_name (objfile
));
23433 int dwarf_always_disassemble
;
23436 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
23437 struct cmd_list_element
*c
, const char *value
)
23439 fprintf_filtered (file
,
23440 _("Whether to always disassemble "
23441 "DWARF expressions is %s.\n"),
23446 show_check_physname (struct ui_file
*file
, int from_tty
,
23447 struct cmd_list_element
*c
, const char *value
)
23449 fprintf_filtered (file
,
23450 _("Whether to check \"physname\" is %s.\n"),
23454 void _initialize_dwarf2_read (void);
23457 _initialize_dwarf2_read (void)
23459 struct cmd_list_element
*c
;
23461 dwarf2_objfile_data_key
23462 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
23464 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
23465 Set DWARF specific variables.\n\
23466 Configure DWARF variables such as the cache size"),
23467 &set_dwarf_cmdlist
, "maintenance set dwarf ",
23468 0/*allow-unknown*/, &maintenance_set_cmdlist
);
23470 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
23471 Show DWARF specific variables\n\
23472 Show DWARF variables such as the cache size"),
23473 &show_dwarf_cmdlist
, "maintenance show dwarf ",
23474 0/*allow-unknown*/, &maintenance_show_cmdlist
);
23476 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
23477 &dwarf_max_cache_age
, _("\
23478 Set the upper bound on the age of cached DWARF compilation units."), _("\
23479 Show the upper bound on the age of cached DWARF compilation units."), _("\
23480 A higher limit means that cached compilation units will be stored\n\
23481 in memory longer, and more total memory will be used. Zero disables\n\
23482 caching, which can slow down startup."),
23484 show_dwarf_max_cache_age
,
23485 &set_dwarf_cmdlist
,
23486 &show_dwarf_cmdlist
);
23488 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
23489 &dwarf_always_disassemble
, _("\
23490 Set whether `info address' always disassembles DWARF expressions."), _("\
23491 Show whether `info address' always disassembles DWARF expressions."), _("\
23492 When enabled, DWARF expressions are always printed in an assembly-like\n\
23493 syntax. When disabled, expressions will be printed in a more\n\
23494 conversational style, when possible."),
23496 show_dwarf_always_disassemble
,
23497 &set_dwarf_cmdlist
,
23498 &show_dwarf_cmdlist
);
23500 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
23501 Set debugging of the DWARF reader."), _("\
23502 Show debugging of the DWARF reader."), _("\
23503 When enabled (non-zero), debugging messages are printed during DWARF\n\
23504 reading and symtab expansion. A value of 1 (one) provides basic\n\
23505 information. A value greater than 1 provides more verbose information."),
23508 &setdebuglist
, &showdebuglist
);
23510 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
23511 Set debugging of the DWARF DIE reader."), _("\
23512 Show debugging of the DWARF DIE reader."), _("\
23513 When enabled (non-zero), DIEs are dumped after they are read in.\n\
23514 The value is the maximum depth to print."),
23517 &setdebuglist
, &showdebuglist
);
23519 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
23520 Set debugging of the dwarf line reader."), _("\
23521 Show debugging of the dwarf line reader."), _("\
23522 When enabled (non-zero), line number entries are dumped as they are read in.\n\
23523 A value of 1 (one) provides basic information.\n\
23524 A value greater than 1 provides more verbose information."),
23527 &setdebuglist
, &showdebuglist
);
23529 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
23530 Set cross-checking of \"physname\" code against demangler."), _("\
23531 Show cross-checking of \"physname\" code against demangler."), _("\
23532 When enabled, GDB's internal \"physname\" code is checked against\n\
23534 NULL
, show_check_physname
,
23535 &setdebuglist
, &showdebuglist
);
23537 add_setshow_boolean_cmd ("use-deprecated-index-sections",
23538 no_class
, &use_deprecated_index_sections
, _("\
23539 Set whether to use deprecated gdb_index sections."), _("\
23540 Show whether to use deprecated gdb_index sections."), _("\
23541 When enabled, deprecated .gdb_index sections are used anyway.\n\
23542 Normally they are ignored either because of a missing feature or\n\
23543 performance issue.\n\
23544 Warning: This option must be enabled before gdb reads the file."),
23547 &setlist
, &showlist
);
23549 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
23551 Save a gdb-index file.\n\
23552 Usage: save gdb-index DIRECTORY"),
23554 set_cmd_completer (c
, filename_completer
);
23556 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23557 &dwarf2_locexpr_funcs
);
23558 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23559 &dwarf2_loclist_funcs
);
23561 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23562 &dwarf2_block_frame_base_locexpr_funcs
);
23563 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23564 &dwarf2_block_frame_base_loclist_funcs
);