1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2012 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. */
39 #include "gdb-demangle.h"
40 #include "expression.h"
41 #include "filenames.h" /* for DOSish file names */
44 #include "complaints.h"
46 #include "dwarf2expr.h"
47 #include "dwarf2loc.h"
48 #include "cp-support.h"
54 #include "typeprint.h"
57 #include "exceptions.h"
59 #include "completer.h"
64 #include "gdbcore.h" /* for gnutarget */
68 #include "gdb_string.h"
69 #include "gdb_assert.h"
70 #include <sys/types.h>
77 #define MAP_FAILED ((void *) -1)
81 typedef struct symbol
*symbolp
;
84 /* When non-zero, dump DIEs after they are read in. */
85 static int dwarf2_die_debug
= 0;
87 /* When non-zero, cross-check physname against demangler. */
88 static int check_physname
= 0;
90 /* When non-zero, do not reject deprecated .gdb_index sections. */
91 int use_deprecated_index_sections
= 0;
95 /* When set, the file that we're processing is known to have debugging
96 info for C++ namespaces. GCC 3.3.x did not produce this information,
97 but later versions do. */
99 static int processing_has_namespace_info
;
101 static const struct objfile_data
*dwarf2_objfile_data_key
;
103 struct dwarf2_section_info
108 /* Not NULL if the section was actually mmapped. */
110 /* Page aligned size of mmapped area. */
111 bfd_size_type map_len
;
112 /* True if we have tried to read this section. */
116 typedef struct dwarf2_section_info dwarf2_section_info_def
;
117 DEF_VEC_O (dwarf2_section_info_def
);
119 /* All offsets in the index are of this type. It must be
120 architecture-independent. */
121 typedef uint32_t offset_type
;
123 DEF_VEC_I (offset_type
);
125 /* A description of the mapped index. The file format is described in
126 a comment by the code that writes the index. */
129 /* Index data format version. */
132 /* The total length of the buffer. */
135 /* A pointer to the address table data. */
136 const gdb_byte
*address_table
;
138 /* Size of the address table data in bytes. */
139 offset_type address_table_size
;
141 /* The symbol table, implemented as a hash table. */
142 const offset_type
*symbol_table
;
144 /* Size in slots, each slot is 2 offset_types. */
145 offset_type symbol_table_slots
;
147 /* A pointer to the constant pool. */
148 const char *constant_pool
;
151 typedef struct dwarf2_per_cu_data
*dwarf2_per_cu_ptr
;
152 DEF_VEC_P (dwarf2_per_cu_ptr
);
154 /* Collection of data recorded per objfile.
155 This hangs off of dwarf2_objfile_data_key. */
157 struct dwarf2_per_objfile
159 struct dwarf2_section_info info
;
160 struct dwarf2_section_info abbrev
;
161 struct dwarf2_section_info line
;
162 struct dwarf2_section_info loc
;
163 struct dwarf2_section_info macinfo
;
164 struct dwarf2_section_info macro
;
165 struct dwarf2_section_info str
;
166 struct dwarf2_section_info ranges
;
167 struct dwarf2_section_info addr
;
168 struct dwarf2_section_info frame
;
169 struct dwarf2_section_info eh_frame
;
170 struct dwarf2_section_info gdb_index
;
172 VEC (dwarf2_section_info_def
) *types
;
175 struct objfile
*objfile
;
177 /* Table of all the compilation units. This is used to locate
178 the target compilation unit of a particular reference. */
179 struct dwarf2_per_cu_data
**all_comp_units
;
181 /* The number of compilation units in ALL_COMP_UNITS. */
184 /* The number of .debug_types-related CUs. */
187 /* The .debug_types-related CUs (TUs). */
188 struct dwarf2_per_cu_data
**all_type_units
;
190 /* A chain of compilation units that are currently read in, so that
191 they can be freed later. */
192 struct dwarf2_per_cu_data
*read_in_chain
;
194 /* A table mapping .debug_types signatures to its signatured_type entry.
195 This is NULL if the .debug_types section hasn't been read in yet. */
196 htab_t signatured_types
;
198 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
199 This is NULL if the table hasn't been allocated yet. */
202 /* A flag indicating wether this objfile has a section loaded at a
204 int has_section_at_zero
;
206 /* True if we are using the mapped index,
207 or we are faking it for OBJF_READNOW's sake. */
208 unsigned char using_index
;
210 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
211 struct mapped_index
*index_table
;
213 /* When using index_table, this keeps track of all quick_file_names entries.
214 TUs can share line table entries with CUs or other TUs, and there can be
215 a lot more TUs than unique line tables, so we maintain a separate table
216 of all line table entries to support the sharing. */
217 htab_t quick_file_names_table
;
219 /* Set during partial symbol reading, to prevent queueing of full
221 int reading_partial_symbols
;
223 /* Table mapping type DIEs to their struct type *.
224 This is NULL if not allocated yet.
225 The mapping is done via (CU/TU signature + DIE offset) -> type. */
226 htab_t die_type_hash
;
228 /* The CUs we recently read. */
229 VEC (dwarf2_per_cu_ptr
) *just_read_cus
;
232 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
234 /* Default names of the debugging sections. */
236 /* Note that if the debugging section has been compressed, it might
237 have a name like .zdebug_info. */
239 static const struct dwarf2_debug_sections dwarf2_elf_names
=
241 { ".debug_info", ".zdebug_info" },
242 { ".debug_abbrev", ".zdebug_abbrev" },
243 { ".debug_line", ".zdebug_line" },
244 { ".debug_loc", ".zdebug_loc" },
245 { ".debug_macinfo", ".zdebug_macinfo" },
246 { ".debug_macro", ".zdebug_macro" },
247 { ".debug_str", ".zdebug_str" },
248 { ".debug_ranges", ".zdebug_ranges" },
249 { ".debug_types", ".zdebug_types" },
250 { ".debug_addr", ".zdebug_addr" },
251 { ".debug_frame", ".zdebug_frame" },
252 { ".eh_frame", NULL
},
253 { ".gdb_index", ".zgdb_index" },
257 /* List of DWO sections. */
259 static const struct dwo_section_names
261 struct dwarf2_section_names abbrev_dwo
;
262 struct dwarf2_section_names info_dwo
;
263 struct dwarf2_section_names line_dwo
;
264 struct dwarf2_section_names loc_dwo
;
265 struct dwarf2_section_names str_dwo
;
266 struct dwarf2_section_names str_offsets_dwo
;
267 struct dwarf2_section_names types_dwo
;
271 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
272 { ".debug_info.dwo", ".zdebug_info.dwo" },
273 { ".debug_line.dwo", ".zdebug_line.dwo" },
274 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
275 { ".debug_str.dwo", ".zdebug_str.dwo" },
276 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
277 { ".debug_types.dwo", ".zdebug_types.dwo" },
280 /* local data types */
282 /* We hold several abbreviation tables in memory at the same time. */
283 #ifndef ABBREV_HASH_SIZE
284 #define ABBREV_HASH_SIZE 121
287 /* The data in a compilation unit header, after target2host
288 translation, looks like this. */
289 struct comp_unit_head
293 unsigned char addr_size
;
294 unsigned char signed_addr_p
;
295 sect_offset abbrev_offset
;
297 /* Size of file offsets; either 4 or 8. */
298 unsigned int offset_size
;
300 /* Size of the length field; either 4 or 12. */
301 unsigned int initial_length_size
;
303 /* Offset to the first byte of this compilation unit header in the
304 .debug_info section, for resolving relative reference dies. */
307 /* Offset to first die in this cu from the start of the cu.
308 This will be the first byte following the compilation unit header. */
309 cu_offset first_die_offset
;
312 /* Type used for delaying computation of method physnames.
313 See comments for compute_delayed_physnames. */
314 struct delayed_method_info
316 /* The type to which the method is attached, i.e., its parent class. */
319 /* The index of the method in the type's function fieldlists. */
322 /* The index of the method in the fieldlist. */
325 /* The name of the DIE. */
328 /* The DIE associated with this method. */
329 struct die_info
*die
;
332 typedef struct delayed_method_info delayed_method_info
;
333 DEF_VEC_O (delayed_method_info
);
335 /* Internal state when decoding a particular compilation unit. */
338 /* The objfile containing this compilation unit. */
339 struct objfile
*objfile
;
341 /* The header of the compilation unit. */
342 struct comp_unit_head header
;
344 /* Base address of this compilation unit. */
345 CORE_ADDR base_address
;
347 /* Non-zero if base_address has been set. */
350 /* The language we are debugging. */
351 enum language language
;
352 const struct language_defn
*language_defn
;
354 const char *producer
;
356 /* The generic symbol table building routines have separate lists for
357 file scope symbols and all all other scopes (local scopes). So
358 we need to select the right one to pass to add_symbol_to_list().
359 We do it by keeping a pointer to the correct list in list_in_scope.
361 FIXME: The original dwarf code just treated the file scope as the
362 first local scope, and all other local scopes as nested local
363 scopes, and worked fine. Check to see if we really need to
364 distinguish these in buildsym.c. */
365 struct pending
**list_in_scope
;
367 /* DWARF abbreviation table associated with this compilation unit. */
368 struct abbrev_info
**dwarf2_abbrevs
;
370 /* Storage for the abbrev table. */
371 struct obstack abbrev_obstack
;
373 /* Hash table holding all the loaded partial DIEs
374 with partial_die->offset.SECT_OFF as hash. */
377 /* Storage for things with the same lifetime as this read-in compilation
378 unit, including partial DIEs. */
379 struct obstack comp_unit_obstack
;
381 /* When multiple dwarf2_cu structures are living in memory, this field
382 chains them all together, so that they can be released efficiently.
383 We will probably also want a generation counter so that most-recently-used
384 compilation units are cached... */
385 struct dwarf2_per_cu_data
*read_in_chain
;
387 /* Backchain to our per_cu entry if the tree has been built. */
388 struct dwarf2_per_cu_data
*per_cu
;
390 /* How many compilation units ago was this CU last referenced? */
393 /* A hash table of DIE cu_offset for following references with
394 die_info->offset.sect_off as hash. */
397 /* Full DIEs if read in. */
398 struct die_info
*dies
;
400 /* A set of pointers to dwarf2_per_cu_data objects for compilation
401 units referenced by this one. Only set during full symbol processing;
402 partial symbol tables do not have dependencies. */
405 /* Header data from the line table, during full symbol processing. */
406 struct line_header
*line_header
;
408 /* A list of methods which need to have physnames computed
409 after all type information has been read. */
410 VEC (delayed_method_info
) *method_list
;
412 /* To be copied to symtab->call_site_htab. */
413 htab_t call_site_htab
;
415 /* Non-NULL if this CU came from a DWO file. */
416 struct dwo_unit
*dwo_unit
;
418 /* The DW_AT_addr_base attribute if present, zero otherwise
419 (zero is a valid value though).
420 Note this value comes from the stub CU/TU's DIE. */
423 /* Mark used when releasing cached dies. */
424 unsigned int mark
: 1;
426 /* This CU references .debug_loc. See the symtab->locations_valid field.
427 This test is imperfect as there may exist optimized debug code not using
428 any location list and still facing inlining issues if handled as
429 unoptimized code. For a future better test see GCC PR other/32998. */
430 unsigned int has_loclist
: 1;
432 /* These cache the results of producer_is_gxx_lt_4_6.
433 CHECKED_PRODUCER is set if PRODUCER_IS_GXX_LT_4_6 is valid. This
434 information is cached because profiling CU expansion showed
435 excessive time spent in producer_is_gxx_lt_4_6. */
436 unsigned int checked_producer
: 1;
437 unsigned int producer_is_gxx_lt_4_6
: 1;
439 /* Non-zero if DW_AT_addr_base was found.
440 Used when processing DWO files. */
441 unsigned int have_addr_base
: 1;
444 /* Persistent data held for a compilation unit, even when not
445 processing it. We put a pointer to this structure in the
446 read_symtab_private field of the psymtab. */
448 struct dwarf2_per_cu_data
450 /* The start offset and length of this compilation unit. 2**29-1
451 bytes should suffice to store the length of any compilation unit
452 - if it doesn't, GDB will fall over anyway.
453 NOTE: Unlike comp_unit_head.length, this length includes
455 If the DIE refers to a DWO file, this is always of the original die,
458 unsigned int length
: 29;
460 /* Flag indicating this compilation unit will be read in before
461 any of the current compilation units are processed. */
462 unsigned int queued
: 1;
464 /* This flag will be set when reading partial DIEs if we need to load
465 absolutely all DIEs for this compilation unit, instead of just the ones
466 we think are interesting. It gets set if we look for a DIE in the
467 hash table and don't find it. */
468 unsigned int load_all_dies
: 1;
470 /* Non-zero if this CU is from .debug_types. */
471 unsigned int is_debug_types
: 1;
473 /* The section this CU/TU lives in.
474 If the DIE refers to a DWO file, this is always the original die,
476 struct dwarf2_section_info
*info_or_types_section
;
478 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
479 of the CU cache it gets reset to NULL again. */
480 struct dwarf2_cu
*cu
;
482 /* The corresponding objfile.
483 Normally we can get the objfile from dwarf2_per_objfile.
484 However we can enter this file with just a "per_cu" handle. */
485 struct objfile
*objfile
;
487 /* When using partial symbol tables, the 'psymtab' field is active.
488 Otherwise the 'quick' field is active. */
491 /* The partial symbol table associated with this compilation unit,
492 or NULL for unread partial units. */
493 struct partial_symtab
*psymtab
;
495 /* Data needed by the "quick" functions. */
496 struct dwarf2_per_cu_quick_data
*quick
;
499 /* The CUs we import using DW_TAG_imported_unit. This is filled in
500 while reading psymtabs, used to compute the psymtab dependencies,
501 and then cleared. Then it is filled in again while reading full
502 symbols, and only deleted when the objfile is destroyed. */
503 VEC (dwarf2_per_cu_ptr
) *imported_symtabs
;
506 /* Entry in the signatured_types hash table. */
508 struct signatured_type
510 /* The type's signature. */
513 /* Offset in the TU of the type's DIE, as read from the TU header.
514 If the definition lives in a DWO file, this value is unusable. */
515 cu_offset type_offset_in_tu
;
517 /* Offset in the section of the type's DIE.
518 If the definition lives in a DWO file, this is the offset in the
519 .debug_types.dwo section.
520 The value is zero until the actual value is known.
521 Zero is otherwise not a valid section offset. */
522 sect_offset type_offset_in_section
;
524 /* The CU(/TU) of this type. */
525 struct dwarf2_per_cu_data per_cu
;
528 /* These sections are what may appear in a "dwo" file. */
532 struct dwarf2_section_info abbrev
;
533 struct dwarf2_section_info info
;
534 struct dwarf2_section_info line
;
535 struct dwarf2_section_info loc
;
536 struct dwarf2_section_info str
;
537 struct dwarf2_section_info str_offsets
;
538 VEC (dwarf2_section_info_def
) *types
;
541 /* Common bits of DWO CUs/TUs. */
545 /* Backlink to the containing struct dwo_file. */
546 struct dwo_file
*dwo_file
;
548 /* The "id" that distinguishes this CU/TU.
549 .debug_info calls this "dwo_id", .debug_types calls this "signature".
550 Since signatures came first, we stick with it for consistency. */
553 /* The section this CU/TU lives in, in the DWO file. */
554 struct dwarf2_section_info
*info_or_types_section
;
556 /* Same as dwarf2_per_cu_data:{offset,length} but for the DWO section. */
560 /* For types, offset in the type's DIE of the type defined by this TU. */
561 cu_offset type_offset_in_tu
;
564 /* Data for one DWO file. */
568 /* The DW_AT_GNU_dwo_name attribute.
569 We don't manage space for this, it's an attribute. */
570 const char *dwo_name
;
572 /* The bfd, when the file is open. Otherwise this is NULL. */
575 /* Section info for this file. */
576 struct dwo_sections sections
;
578 /* Table of CUs in the file.
579 Each element is a struct dwo_unit. */
582 /* Table of TUs in the file.
583 Each element is a struct dwo_unit. */
587 /* Struct used to pass misc. parameters to read_die_and_children, et
588 al. which are used for both .debug_info and .debug_types dies.
589 All parameters here are unchanging for the life of the call. This
590 struct exists to abstract away the constant parameters of die reading. */
592 struct die_reader_specs
594 /* die_section->asection->owner. */
597 /* The CU of the DIE we are parsing. */
598 struct dwarf2_cu
*cu
;
600 /* Non-NULL if reading a DWO file. */
601 struct dwo_file
*dwo_file
;
603 /* The section the die comes from.
604 This is either .debug_info or .debug_types, or the .dwo variants. */
605 struct dwarf2_section_info
*die_section
;
607 /* die_section->buffer. */
611 /* Type of function passed to init_cutu_and_read_dies, et.al. */
612 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
614 struct die_info
*comp_unit_die
,
618 /* The line number information for a compilation unit (found in the
619 .debug_line section) begins with a "statement program header",
620 which contains the following information. */
623 unsigned int total_length
;
624 unsigned short version
;
625 unsigned int header_length
;
626 unsigned char minimum_instruction_length
;
627 unsigned char maximum_ops_per_instruction
;
628 unsigned char default_is_stmt
;
630 unsigned char line_range
;
631 unsigned char opcode_base
;
633 /* standard_opcode_lengths[i] is the number of operands for the
634 standard opcode whose value is i. This means that
635 standard_opcode_lengths[0] is unused, and the last meaningful
636 element is standard_opcode_lengths[opcode_base - 1]. */
637 unsigned char *standard_opcode_lengths
;
639 /* The include_directories table. NOTE! These strings are not
640 allocated with xmalloc; instead, they are pointers into
641 debug_line_buffer. If you try to free them, `free' will get
643 unsigned int num_include_dirs
, include_dirs_size
;
646 /* The file_names table. NOTE! These strings are not allocated
647 with xmalloc; instead, they are pointers into debug_line_buffer.
648 Don't try to free them directly. */
649 unsigned int num_file_names
, file_names_size
;
653 unsigned int dir_index
;
654 unsigned int mod_time
;
656 int included_p
; /* Non-zero if referenced by the Line Number Program. */
657 struct symtab
*symtab
; /* The associated symbol table, if any. */
660 /* The start and end of the statement program following this
661 header. These point into dwarf2_per_objfile->line_buffer. */
662 gdb_byte
*statement_program_start
, *statement_program_end
;
665 /* When we construct a partial symbol table entry we only
666 need this much information. */
667 struct partial_die_info
669 /* Offset of this DIE. */
672 /* DWARF-2 tag for this DIE. */
673 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
675 /* Assorted flags describing the data found in this DIE. */
676 unsigned int has_children
: 1;
677 unsigned int is_external
: 1;
678 unsigned int is_declaration
: 1;
679 unsigned int has_type
: 1;
680 unsigned int has_specification
: 1;
681 unsigned int has_pc_info
: 1;
682 unsigned int may_be_inlined
: 1;
684 /* Flag set if the SCOPE field of this structure has been
686 unsigned int scope_set
: 1;
688 /* Flag set if the DIE has a byte_size attribute. */
689 unsigned int has_byte_size
: 1;
691 /* Flag set if any of the DIE's children are template arguments. */
692 unsigned int has_template_arguments
: 1;
694 /* Flag set if fixup_partial_die has been called on this die. */
695 unsigned int fixup_called
: 1;
697 /* The name of this DIE. Normally the value of DW_AT_name, but
698 sometimes a default name for unnamed DIEs. */
701 /* The linkage name, if present. */
702 const char *linkage_name
;
704 /* The scope to prepend to our children. This is generally
705 allocated on the comp_unit_obstack, so will disappear
706 when this compilation unit leaves the cache. */
709 /* Some data associated with the partial DIE. The tag determines
710 which field is live. */
713 /* The location description associated with this DIE, if any. */
714 struct dwarf_block
*locdesc
;
715 /* The offset of an import, for DW_TAG_imported_unit. */
719 /* If HAS_PC_INFO, the PC range associated with this DIE. */
723 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
724 DW_AT_sibling, if any. */
725 /* NOTE: This member isn't strictly necessary, read_partial_die could
726 return DW_AT_sibling values to its caller load_partial_dies. */
729 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
730 DW_AT_specification (or DW_AT_abstract_origin or
732 sect_offset spec_offset
;
734 /* Pointers to this DIE's parent, first child, and next sibling,
736 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
739 /* This data structure holds the information of an abbrev. */
742 unsigned int number
; /* number identifying abbrev */
743 enum dwarf_tag tag
; /* dwarf tag */
744 unsigned short has_children
; /* boolean */
745 unsigned short num_attrs
; /* number of attributes */
746 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
747 struct abbrev_info
*next
; /* next in chain */
752 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
753 ENUM_BITFIELD(dwarf_form
) form
: 16;
756 /* Attributes have a name and a value. */
759 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
760 ENUM_BITFIELD(dwarf_form
) form
: 15;
762 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
763 field should be in u.str (existing only for DW_STRING) but it is kept
764 here for better struct attribute alignment. */
765 unsigned int string_is_canonical
: 1;
770 struct dwarf_block
*blk
;
774 struct signatured_type
*signatured_type
;
779 /* This data structure holds a complete die structure. */
782 /* DWARF-2 tag for this DIE. */
783 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
785 /* Number of attributes */
786 unsigned char num_attrs
;
788 /* True if we're presently building the full type name for the
789 type derived from this DIE. */
790 unsigned char building_fullname
: 1;
795 /* Offset in .debug_info or .debug_types section. */
798 /* The dies in a compilation unit form an n-ary tree. PARENT
799 points to this die's parent; CHILD points to the first child of
800 this node; and all the children of a given node are chained
801 together via their SIBLING fields. */
802 struct die_info
*child
; /* Its first child, if any. */
803 struct die_info
*sibling
; /* Its next sibling, if any. */
804 struct die_info
*parent
; /* Its parent, if any. */
806 /* An array of attributes, with NUM_ATTRS elements. There may be
807 zero, but it's not common and zero-sized arrays are not
808 sufficiently portable C. */
809 struct attribute attrs
[1];
812 /* Get at parts of an attribute structure. */
814 #define DW_STRING(attr) ((attr)->u.str)
815 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
816 #define DW_UNSND(attr) ((attr)->u.unsnd)
817 #define DW_BLOCK(attr) ((attr)->u.blk)
818 #define DW_SND(attr) ((attr)->u.snd)
819 #define DW_ADDR(attr) ((attr)->u.addr)
820 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
822 /* Blocks are a bunch of untyped bytes. */
827 /* Valid only if SIZE is not zero. */
831 #ifndef ATTR_ALLOC_CHUNK
832 #define ATTR_ALLOC_CHUNK 4
835 /* Allocate fields for structs, unions and enums in this size. */
836 #ifndef DW_FIELD_ALLOC_CHUNK
837 #define DW_FIELD_ALLOC_CHUNK 4
840 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
841 but this would require a corresponding change in unpack_field_as_long
843 static int bits_per_byte
= 8;
845 /* The routines that read and process dies for a C struct or C++ class
846 pass lists of data member fields and lists of member function fields
847 in an instance of a field_info structure, as defined below. */
850 /* List of data member and baseclasses fields. */
853 struct nextfield
*next
;
858 *fields
, *baseclasses
;
860 /* Number of fields (including baseclasses). */
863 /* Number of baseclasses. */
866 /* Set if the accesibility of one of the fields is not public. */
867 int non_public_fields
;
869 /* Member function fields array, entries are allocated in the order they
870 are encountered in the object file. */
873 struct nextfnfield
*next
;
874 struct fn_field fnfield
;
878 /* Member function fieldlist array, contains name of possibly overloaded
879 member function, number of overloaded member functions and a pointer
880 to the head of the member function field chain. */
885 struct nextfnfield
*head
;
889 /* Number of entries in the fnfieldlists array. */
892 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
893 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
894 struct typedef_field_list
896 struct typedef_field field
;
897 struct typedef_field_list
*next
;
900 unsigned typedef_field_list_count
;
903 /* One item on the queue of compilation units to read in full symbols
905 struct dwarf2_queue_item
907 struct dwarf2_per_cu_data
*per_cu
;
908 enum language pretend_language
;
909 struct dwarf2_queue_item
*next
;
912 /* The current queue. */
913 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
915 /* Loaded secondary compilation units are kept in memory until they
916 have not been referenced for the processing of this many
917 compilation units. Set this to zero to disable caching. Cache
918 sizes of up to at least twenty will improve startup time for
919 typical inter-CU-reference binaries, at an obvious memory cost. */
920 static int dwarf2_max_cache_age
= 5;
922 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
923 struct cmd_list_element
*c
, const char *value
)
925 fprintf_filtered (file
, _("The upper bound on the age of cached "
926 "dwarf2 compilation units is %s.\n"),
931 /* Various complaints about symbol reading that don't abort the process. */
934 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
936 complaint (&symfile_complaints
,
937 _("statement list doesn't fit in .debug_line section"));
941 dwarf2_debug_line_missing_file_complaint (void)
943 complaint (&symfile_complaints
,
944 _(".debug_line section has line data without a file"));
948 dwarf2_debug_line_missing_end_sequence_complaint (void)
950 complaint (&symfile_complaints
,
951 _(".debug_line section has line "
952 "program sequence without an end"));
956 dwarf2_complex_location_expr_complaint (void)
958 complaint (&symfile_complaints
, _("location expression too complex"));
962 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
965 complaint (&symfile_complaints
,
966 _("const value length mismatch for '%s', got %d, expected %d"),
971 dwarf2_macros_too_long_complaint (struct dwarf2_section_info
*section
)
973 complaint (&symfile_complaints
,
974 _("macro info runs off end of `%s' section"),
975 section
->asection
->name
);
979 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
981 complaint (&symfile_complaints
,
982 _("macro debug info contains a "
983 "malformed macro definition:\n`%s'"),
988 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
990 complaint (&symfile_complaints
,
991 _("invalid attribute class or form for '%s' in '%s'"),
995 /* local function prototypes */
997 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
999 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
1002 static void dwarf2_find_base_address (struct die_info
*die
,
1003 struct dwarf2_cu
*cu
);
1005 static void dwarf2_build_psymtabs_hard (struct objfile
*);
1007 static void scan_partial_symbols (struct partial_die_info
*,
1008 CORE_ADDR
*, CORE_ADDR
*,
1009 int, struct dwarf2_cu
*);
1011 static void add_partial_symbol (struct partial_die_info
*,
1012 struct dwarf2_cu
*);
1014 static void add_partial_namespace (struct partial_die_info
*pdi
,
1015 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1016 int need_pc
, struct dwarf2_cu
*cu
);
1018 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1019 CORE_ADDR
*highpc
, int need_pc
,
1020 struct dwarf2_cu
*cu
);
1022 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1023 struct dwarf2_cu
*cu
);
1025 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1026 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1027 int need_pc
, struct dwarf2_cu
*cu
);
1029 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
1031 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1033 static void dwarf2_read_abbrevs (struct dwarf2_cu
*,
1034 struct dwarf2_section_info
*);
1036 static void dwarf2_free_abbrev_table (void *);
1038 static unsigned int peek_abbrev_code (bfd
*, gdb_byte
*);
1040 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
1041 struct dwarf2_cu
*);
1043 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
1044 struct dwarf2_cu
*);
1046 static struct partial_die_info
*load_partial_dies
1047 (const struct die_reader_specs
*, gdb_byte
*, int);
1049 static gdb_byte
*read_partial_die (const struct die_reader_specs
*,
1050 struct partial_die_info
*,
1051 struct abbrev_info
*,
1055 static struct partial_die_info
*find_partial_die (sect_offset
,
1056 struct dwarf2_cu
*);
1058 static void fixup_partial_die (struct partial_die_info
*,
1059 struct dwarf2_cu
*);
1061 static gdb_byte
*read_attribute (const struct die_reader_specs
*,
1062 struct attribute
*, struct attr_abbrev
*,
1065 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
1067 static int read_1_signed_byte (bfd
*, gdb_byte
*);
1069 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
1071 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
1073 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
1075 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
1078 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
1080 static LONGEST read_checked_initial_length_and_offset
1081 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1082 unsigned int *, unsigned int *);
1084 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1087 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
1089 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
1091 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
1093 static char *read_indirect_string (bfd
*, gdb_byte
*,
1094 const struct comp_unit_head
*,
1097 static ULONGEST
read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1099 static LONGEST
read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1101 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*, gdb_byte
*,
1104 static char *read_str_index (const struct die_reader_specs
*reader
,
1105 struct dwarf2_cu
*cu
, ULONGEST str_index
);
1107 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
1109 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1111 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1112 struct dwarf2_cu
*);
1114 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1116 struct dwarf2_cu
*);
1118 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1119 struct dwarf2_cu
*cu
);
1121 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1123 static struct die_info
*die_specification (struct die_info
*die
,
1124 struct dwarf2_cu
**);
1126 static void free_line_header (struct line_header
*lh
);
1128 static void add_file_name (struct line_header
*, char *, unsigned int,
1129 unsigned int, unsigned int);
1131 static struct line_header
*dwarf_decode_line_header (unsigned int offset
,
1132 struct dwarf2_cu
*cu
);
1134 static void dwarf_decode_lines (struct line_header
*, const char *,
1135 struct dwarf2_cu
*, struct partial_symtab
*,
1138 static void dwarf2_start_subfile (char *, const char *, const char *);
1140 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1141 struct dwarf2_cu
*);
1143 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1144 struct dwarf2_cu
*, struct symbol
*);
1146 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1147 struct dwarf2_cu
*);
1149 static void dwarf2_const_value_attr (struct attribute
*attr
,
1152 struct obstack
*obstack
,
1153 struct dwarf2_cu
*cu
, LONGEST
*value
,
1155 struct dwarf2_locexpr_baton
**baton
);
1157 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1159 static int need_gnat_info (struct dwarf2_cu
*);
1161 static struct type
*die_descriptive_type (struct die_info
*,
1162 struct dwarf2_cu
*);
1164 static void set_descriptive_type (struct type
*, struct die_info
*,
1165 struct dwarf2_cu
*);
1167 static struct type
*die_containing_type (struct die_info
*,
1168 struct dwarf2_cu
*);
1170 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1171 struct dwarf2_cu
*);
1173 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1175 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1177 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1179 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1180 const char *suffix
, int physname
,
1181 struct dwarf2_cu
*cu
);
1183 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1185 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1187 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1189 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1191 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1193 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1194 struct dwarf2_cu
*, struct partial_symtab
*);
1196 static int dwarf2_get_pc_bounds (struct die_info
*,
1197 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1198 struct partial_symtab
*);
1200 static void get_scope_pc_bounds (struct die_info
*,
1201 CORE_ADDR
*, CORE_ADDR
*,
1202 struct dwarf2_cu
*);
1204 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1205 CORE_ADDR
, struct dwarf2_cu
*);
1207 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1208 struct dwarf2_cu
*);
1210 static void dwarf2_attach_fields_to_type (struct field_info
*,
1211 struct type
*, struct dwarf2_cu
*);
1213 static void dwarf2_add_member_fn (struct field_info
*,
1214 struct die_info
*, struct type
*,
1215 struct dwarf2_cu
*);
1217 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1219 struct dwarf2_cu
*);
1221 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1223 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1225 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1227 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1229 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1231 static struct type
*read_module_type (struct die_info
*die
,
1232 struct dwarf2_cu
*cu
);
1234 static const char *namespace_name (struct die_info
*die
,
1235 int *is_anonymous
, struct dwarf2_cu
*);
1237 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1239 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1241 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1242 struct dwarf2_cu
*);
1244 static struct die_info
*read_die_and_children (const struct die_reader_specs
*,
1246 gdb_byte
**new_info_ptr
,
1247 struct die_info
*parent
);
1249 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1251 gdb_byte
**new_info_ptr
,
1252 struct die_info
*parent
);
1254 static gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1255 struct die_info
**, gdb_byte
*, int *, int);
1257 static gdb_byte
*read_full_die (const struct die_reader_specs
*,
1258 struct die_info
**, gdb_byte
*, int *);
1260 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1262 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1265 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1267 static const char *dwarf2_full_name (char *name
,
1268 struct die_info
*die
,
1269 struct dwarf2_cu
*cu
);
1271 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1272 struct dwarf2_cu
**);
1274 static const char *dwarf_tag_name (unsigned int);
1276 static const char *dwarf_attr_name (unsigned int);
1278 static const char *dwarf_form_name (unsigned int);
1280 static char *dwarf_bool_name (unsigned int);
1282 static const char *dwarf_type_encoding_name (unsigned int);
1284 static struct die_info
*sibling_die (struct die_info
*);
1286 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1288 static void dump_die_for_error (struct die_info
*);
1290 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1293 /*static*/ void dump_die (struct die_info
*, int max_level
);
1295 static void store_in_ref_table (struct die_info
*,
1296 struct dwarf2_cu
*);
1298 static int is_ref_attr (struct attribute
*);
1300 static sect_offset
dwarf2_get_ref_die_offset (struct attribute
*);
1302 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1304 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1306 struct dwarf2_cu
**);
1308 static struct die_info
*follow_die_ref (struct die_info
*,
1310 struct dwarf2_cu
**);
1312 static struct die_info
*follow_die_sig (struct die_info
*,
1314 struct dwarf2_cu
**);
1316 static struct signatured_type
*lookup_signatured_type_at_offset
1317 (struct objfile
*objfile
,
1318 struct dwarf2_section_info
*section
, sect_offset offset
);
1320 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1322 static void read_signatured_type (struct signatured_type
*);
1324 /* memory allocation interface */
1326 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1328 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1330 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1332 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1333 char *, bfd
*, struct dwarf2_cu
*,
1334 struct dwarf2_section_info
*,
1337 static int attr_form_is_block (struct attribute
*);
1339 static int attr_form_is_section_offset (struct attribute
*);
1341 static int attr_form_is_constant (struct attribute
*);
1343 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1344 struct dwarf2_loclist_baton
*baton
,
1345 struct attribute
*attr
);
1347 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1349 struct dwarf2_cu
*cu
);
1351 static gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1353 struct abbrev_info
*abbrev
);
1355 static void free_stack_comp_unit (void *);
1357 static hashval_t
partial_die_hash (const void *item
);
1359 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1361 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1362 (sect_offset offset
, struct objfile
*objfile
);
1364 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1365 struct dwarf2_per_cu_data
*per_cu
);
1367 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1368 struct die_info
*comp_unit_die
,
1369 enum language pretend_language
);
1371 static void free_heap_comp_unit (void *);
1373 static void free_cached_comp_units (void *);
1375 static void age_cached_comp_units (void);
1377 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1379 static struct type
*set_die_type (struct die_info
*, struct type
*,
1380 struct dwarf2_cu
*);
1382 static void create_all_comp_units (struct objfile
*);
1384 static int create_all_type_units (struct objfile
*);
1386 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1389 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1392 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1393 struct dwarf2_per_cu_data
*);
1395 static void dwarf2_mark (struct dwarf2_cu
*);
1397 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1399 static struct type
*get_die_type_at_offset (sect_offset
,
1400 struct dwarf2_per_cu_data
*per_cu
);
1402 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1404 static void dwarf2_release_queue (void *dummy
);
1406 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1407 enum language pretend_language
);
1409 static int maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
1410 struct dwarf2_per_cu_data
*per_cu
,
1411 enum language pretend_language
);
1413 static void process_queue (void);
1415 static void find_file_and_directory (struct die_info
*die
,
1416 struct dwarf2_cu
*cu
,
1417 char **name
, char **comp_dir
);
1419 static char *file_full_name (int file
, struct line_header
*lh
,
1420 const char *comp_dir
);
1422 static gdb_byte
*read_and_check_comp_unit_head
1423 (struct comp_unit_head
*header
,
1424 struct dwarf2_section_info
*section
, gdb_byte
*info_ptr
,
1425 int is_debug_types_section
);
1427 static void init_cutu_and_read_dies
1428 (struct dwarf2_per_cu_data
*this_cu
, int use_existing_cu
, int keep
,
1429 die_reader_func_ftype
*die_reader_func
, void *data
);
1431 static void init_cutu_and_read_dies_simple
1432 (struct dwarf2_per_cu_data
*this_cu
,
1433 die_reader_func_ftype
*die_reader_func
, void *data
);
1435 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1437 static void process_psymtab_comp_unit (struct dwarf2_per_cu_data
*, int);
1439 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1441 static struct dwo_unit
*lookup_dwo_comp_unit
1442 (struct dwarf2_per_cu_data
*, char *, const char *, ULONGEST
);
1444 static struct dwo_unit
*lookup_dwo_type_unit
1445 (struct signatured_type
*, char *, const char *);
1447 static void free_dwo_file_cleanup (void *);
1449 static void munmap_section_buffer (struct dwarf2_section_info
*);
1451 static void process_cu_includes (void);
1455 /* Convert VALUE between big- and little-endian. */
1457 byte_swap (offset_type value
)
1461 result
= (value
& 0xff) << 24;
1462 result
|= (value
& 0xff00) << 8;
1463 result
|= (value
& 0xff0000) >> 8;
1464 result
|= (value
& 0xff000000) >> 24;
1468 #define MAYBE_SWAP(V) byte_swap (V)
1471 #define MAYBE_SWAP(V) (V)
1472 #endif /* WORDS_BIGENDIAN */
1474 /* The suffix for an index file. */
1475 #define INDEX_SUFFIX ".gdb-index"
1477 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1478 struct dwarf2_cu
*cu
);
1480 /* Try to locate the sections we need for DWARF 2 debugging
1481 information and return true if we have enough to do something.
1482 NAMES points to the dwarf2 section names, or is NULL if the standard
1483 ELF names are used. */
1486 dwarf2_has_info (struct objfile
*objfile
,
1487 const struct dwarf2_debug_sections
*names
)
1489 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1490 if (!dwarf2_per_objfile
)
1492 /* Initialize per-objfile state. */
1493 struct dwarf2_per_objfile
*data
1494 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1496 memset (data
, 0, sizeof (*data
));
1497 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1498 dwarf2_per_objfile
= data
;
1500 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1502 dwarf2_per_objfile
->objfile
= objfile
;
1504 return (dwarf2_per_objfile
->info
.asection
!= NULL
1505 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1508 /* When loading sections, we look either for uncompressed section or for
1509 compressed section names. */
1512 section_is_p (const char *section_name
,
1513 const struct dwarf2_section_names
*names
)
1515 if (names
->normal
!= NULL
1516 && strcmp (section_name
, names
->normal
) == 0)
1518 if (names
->compressed
!= NULL
1519 && strcmp (section_name
, names
->compressed
) == 0)
1524 /* This function is mapped across the sections and remembers the
1525 offset and size of each of the debugging sections we are interested
1529 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1531 const struct dwarf2_debug_sections
*names
;
1534 names
= &dwarf2_elf_names
;
1536 names
= (const struct dwarf2_debug_sections
*) vnames
;
1538 if (section_is_p (sectp
->name
, &names
->info
))
1540 dwarf2_per_objfile
->info
.asection
= sectp
;
1541 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1543 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1545 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1546 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1548 else if (section_is_p (sectp
->name
, &names
->line
))
1550 dwarf2_per_objfile
->line
.asection
= sectp
;
1551 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1553 else if (section_is_p (sectp
->name
, &names
->loc
))
1555 dwarf2_per_objfile
->loc
.asection
= sectp
;
1556 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1558 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1560 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1561 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1563 else if (section_is_p (sectp
->name
, &names
->macro
))
1565 dwarf2_per_objfile
->macro
.asection
= sectp
;
1566 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
1568 else if (section_is_p (sectp
->name
, &names
->str
))
1570 dwarf2_per_objfile
->str
.asection
= sectp
;
1571 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1573 else if (section_is_p (sectp
->name
, &names
->addr
))
1575 dwarf2_per_objfile
->addr
.asection
= sectp
;
1576 dwarf2_per_objfile
->addr
.size
= bfd_get_section_size (sectp
);
1578 else if (section_is_p (sectp
->name
, &names
->frame
))
1580 dwarf2_per_objfile
->frame
.asection
= sectp
;
1581 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1583 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1585 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
1587 if (aflag
& SEC_HAS_CONTENTS
)
1589 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1590 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1593 else if (section_is_p (sectp
->name
, &names
->ranges
))
1595 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1596 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1598 else if (section_is_p (sectp
->name
, &names
->types
))
1600 struct dwarf2_section_info type_section
;
1602 memset (&type_section
, 0, sizeof (type_section
));
1603 type_section
.asection
= sectp
;
1604 type_section
.size
= bfd_get_section_size (sectp
);
1606 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
1609 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1611 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1612 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1615 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1616 && bfd_section_vma (abfd
, sectp
) == 0)
1617 dwarf2_per_objfile
->has_section_at_zero
= 1;
1620 /* Decompress a section that was compressed using zlib. Store the
1621 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1624 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1625 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1627 bfd
*abfd
= sectp
->owner
;
1629 error (_("Support for zlib-compressed DWARF data (from '%s') "
1630 "is disabled in this copy of GDB"),
1631 bfd_get_filename (abfd
));
1633 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1634 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1635 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1636 bfd_size_type uncompressed_size
;
1637 gdb_byte
*uncompressed_buffer
;
1640 int header_size
= 12;
1642 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1643 || bfd_bread (compressed_buffer
,
1644 compressed_size
, abfd
) != compressed_size
)
1645 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1646 bfd_get_filename (abfd
));
1648 /* Read the zlib header. In this case, it should be "ZLIB" followed
1649 by the uncompressed section size, 8 bytes in big-endian order. */
1650 if (compressed_size
< header_size
1651 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1652 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1653 bfd_get_filename (abfd
));
1654 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1655 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1656 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1657 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1658 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1659 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1660 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1661 uncompressed_size
+= compressed_buffer
[11];
1663 /* It is possible the section consists of several compressed
1664 buffers concatenated together, so we uncompress in a loop. */
1668 strm
.avail_in
= compressed_size
- header_size
;
1669 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1670 strm
.avail_out
= uncompressed_size
;
1671 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1673 rc
= inflateInit (&strm
);
1674 while (strm
.avail_in
> 0)
1677 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1678 bfd_get_filename (abfd
), rc
);
1679 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1680 + (uncompressed_size
- strm
.avail_out
));
1681 rc
= inflate (&strm
, Z_FINISH
);
1682 if (rc
!= Z_STREAM_END
)
1683 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1684 bfd_get_filename (abfd
), rc
);
1685 rc
= inflateReset (&strm
);
1687 rc
= inflateEnd (&strm
);
1689 || strm
.avail_out
!= 0)
1690 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1691 bfd_get_filename (abfd
), rc
);
1693 do_cleanups (cleanup
);
1694 *outbuf
= uncompressed_buffer
;
1695 *outsize
= uncompressed_size
;
1699 /* A helper function that decides whether a section is empty,
1703 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1705 return info
->asection
== NULL
|| info
->size
== 0;
1708 /* Read the contents of the section INFO.
1709 OBJFILE is the main object file, but not necessarily the file where
1710 the section comes from. E.g., for DWO files INFO->asection->owner
1711 is the bfd of the DWO file.
1712 If the section is compressed, uncompress it before returning. */
1715 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1717 asection
*sectp
= info
->asection
;
1719 gdb_byte
*buf
, *retbuf
;
1720 unsigned char header
[4];
1724 info
->buffer
= NULL
;
1725 info
->map_addr
= NULL
;
1728 if (dwarf2_section_empty_p (info
))
1731 /* Note that ABFD may not be from OBJFILE, e.g. a DWO section. */
1732 abfd
= sectp
->owner
;
1734 /* Check if the file has a 4-byte header indicating compression. */
1735 if (info
->size
> sizeof (header
)
1736 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1737 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1739 /* Upon decompression, update the buffer and its size. */
1740 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1742 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1750 pagesize
= getpagesize ();
1752 /* Only try to mmap sections which are large enough: we don't want to
1753 waste space due to fragmentation. Also, only try mmap for sections
1754 without relocations. */
1756 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1758 info
->buffer
= bfd_mmap (abfd
, 0, info
->size
, PROT_READ
,
1759 MAP_PRIVATE
, sectp
->filepos
,
1760 &info
->map_addr
, &info
->map_len
);
1762 if ((caddr_t
)info
->buffer
!= MAP_FAILED
)
1764 #if HAVE_POSIX_MADVISE
1765 posix_madvise (info
->map_addr
, info
->map_len
, POSIX_MADV_WILLNEED
);
1772 /* If we get here, we are a normal, not-compressed section. */
1774 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1776 /* When debugging .o files, we may need to apply relocations; see
1777 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1778 We never compress sections in .o files, so we only need to
1779 try this when the section is not compressed. */
1780 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1783 info
->buffer
= retbuf
;
1787 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1788 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1789 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1790 bfd_get_filename (abfd
));
1793 /* A helper function that returns the size of a section in a safe way.
1794 If you are positive that the section has been read before using the
1795 size, then it is safe to refer to the dwarf2_section_info object's
1796 "size" field directly. In other cases, you must call this
1797 function, because for compressed sections the size field is not set
1798 correctly until the section has been read. */
1800 static bfd_size_type
1801 dwarf2_section_size (struct objfile
*objfile
,
1802 struct dwarf2_section_info
*info
)
1805 dwarf2_read_section (objfile
, info
);
1809 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1813 dwarf2_get_section_info (struct objfile
*objfile
,
1814 enum dwarf2_section_enum sect
,
1815 asection
**sectp
, gdb_byte
**bufp
,
1816 bfd_size_type
*sizep
)
1818 struct dwarf2_per_objfile
*data
1819 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1820 struct dwarf2_section_info
*info
;
1822 /* We may see an objfile without any DWARF, in which case we just
1833 case DWARF2_DEBUG_FRAME
:
1834 info
= &data
->frame
;
1836 case DWARF2_EH_FRAME
:
1837 info
= &data
->eh_frame
;
1840 gdb_assert_not_reached ("unexpected section");
1843 dwarf2_read_section (objfile
, info
);
1845 *sectp
= info
->asection
;
1846 *bufp
= info
->buffer
;
1847 *sizep
= info
->size
;
1851 /* DWARF quick_symbols_functions support. */
1853 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1854 unique line tables, so we maintain a separate table of all .debug_line
1855 derived entries to support the sharing.
1856 All the quick functions need is the list of file names. We discard the
1857 line_header when we're done and don't need to record it here. */
1858 struct quick_file_names
1860 /* The offset in .debug_line of the line table. We hash on this. */
1861 unsigned int offset
;
1863 /* The number of entries in file_names, real_names. */
1864 unsigned int num_file_names
;
1866 /* The file names from the line table, after being run through
1868 const char **file_names
;
1870 /* The file names from the line table after being run through
1871 gdb_realpath. These are computed lazily. */
1872 const char **real_names
;
1875 /* When using the index (and thus not using psymtabs), each CU has an
1876 object of this type. This is used to hold information needed by
1877 the various "quick" methods. */
1878 struct dwarf2_per_cu_quick_data
1880 /* The file table. This can be NULL if there was no file table
1881 or it's currently not read in.
1882 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1883 struct quick_file_names
*file_names
;
1885 /* The corresponding symbol table. This is NULL if symbols for this
1886 CU have not yet been read. */
1887 struct symtab
*symtab
;
1889 /* A temporary mark bit used when iterating over all CUs in
1890 expand_symtabs_matching. */
1891 unsigned int mark
: 1;
1893 /* True if we've tried to read the file table and found there isn't one.
1894 There will be no point in trying to read it again next time. */
1895 unsigned int no_file_data
: 1;
1898 /* Hash function for a quick_file_names. */
1901 hash_file_name_entry (const void *e
)
1903 const struct quick_file_names
*file_data
= e
;
1905 return file_data
->offset
;
1908 /* Equality function for a quick_file_names. */
1911 eq_file_name_entry (const void *a
, const void *b
)
1913 const struct quick_file_names
*ea
= a
;
1914 const struct quick_file_names
*eb
= b
;
1916 return ea
->offset
== eb
->offset
;
1919 /* Delete function for a quick_file_names. */
1922 delete_file_name_entry (void *e
)
1924 struct quick_file_names
*file_data
= e
;
1927 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
1929 xfree ((void*) file_data
->file_names
[i
]);
1930 if (file_data
->real_names
)
1931 xfree ((void*) file_data
->real_names
[i
]);
1934 /* The space for the struct itself lives on objfile_obstack,
1935 so we don't free it here. */
1938 /* Create a quick_file_names hash table. */
1941 create_quick_file_names_table (unsigned int nr_initial_entries
)
1943 return htab_create_alloc (nr_initial_entries
,
1944 hash_file_name_entry
, eq_file_name_entry
,
1945 delete_file_name_entry
, xcalloc
, xfree
);
1948 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
1949 have to be created afterwards. You should call age_cached_comp_units after
1950 processing PER_CU->CU. dw2_setup must have been already called. */
1953 load_cu (struct dwarf2_per_cu_data
*per_cu
)
1955 if (per_cu
->is_debug_types
)
1956 load_full_type_unit (per_cu
);
1958 load_full_comp_unit (per_cu
, language_minimal
);
1960 gdb_assert (per_cu
->cu
!= NULL
);
1962 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
1965 /* Read in the symbols for PER_CU. */
1968 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
1970 struct cleanup
*back_to
;
1972 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
1974 if (dwarf2_per_objfile
->using_index
1975 ? per_cu
->v
.quick
->symtab
== NULL
1976 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
1978 queue_comp_unit (per_cu
, language_minimal
);
1984 /* Age the cache, releasing compilation units that have not
1985 been used recently. */
1986 age_cached_comp_units ();
1988 do_cleanups (back_to
);
1991 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1992 the objfile from which this CU came. Returns the resulting symbol
1995 static struct symtab
*
1996 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
1998 gdb_assert (dwarf2_per_objfile
->using_index
);
1999 if (!per_cu
->v
.quick
->symtab
)
2001 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2002 increment_reading_symtab ();
2003 dw2_do_instantiate_symtab (per_cu
);
2004 process_cu_includes ();
2005 do_cleanups (back_to
);
2007 return per_cu
->v
.quick
->symtab
;
2010 /* Return the CU given its index. */
2012 static struct dwarf2_per_cu_data
*
2013 dw2_get_cu (int index
)
2015 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2017 index
-= dwarf2_per_objfile
->n_comp_units
;
2018 return dwarf2_per_objfile
->all_type_units
[index
];
2020 return dwarf2_per_objfile
->all_comp_units
[index
];
2023 /* A helper function that knows how to read a 64-bit value in a way
2024 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
2028 extract_cu_value (const char *bytes
, ULONGEST
*result
)
2030 if (sizeof (ULONGEST
) < 8)
2034 /* Ignore the upper 4 bytes if they are all zero. */
2035 for (i
= 0; i
< 4; ++i
)
2036 if (bytes
[i
+ 4] != 0)
2039 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
2042 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2046 /* Read the CU list from the mapped index, and use it to create all
2047 the CU objects for this objfile. Return 0 if something went wrong,
2048 1 if everything went ok. */
2051 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
2052 offset_type cu_list_elements
)
2056 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
2057 dwarf2_per_objfile
->all_comp_units
2058 = obstack_alloc (&objfile
->objfile_obstack
,
2059 dwarf2_per_objfile
->n_comp_units
2060 * sizeof (struct dwarf2_per_cu_data
*));
2062 for (i
= 0; i
< cu_list_elements
; i
+= 2)
2064 struct dwarf2_per_cu_data
*the_cu
;
2065 ULONGEST offset
, length
;
2067 if (!extract_cu_value (cu_list
, &offset
)
2068 || !extract_cu_value (cu_list
+ 8, &length
))
2072 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2073 struct dwarf2_per_cu_data
);
2074 the_cu
->offset
.sect_off
= offset
;
2075 the_cu
->length
= length
;
2076 the_cu
->objfile
= objfile
;
2077 the_cu
->info_or_types_section
= &dwarf2_per_objfile
->info
;
2078 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2079 struct dwarf2_per_cu_quick_data
);
2080 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
2086 /* Create the signatured type hash table from the index. */
2089 create_signatured_type_table_from_index (struct objfile
*objfile
,
2090 struct dwarf2_section_info
*section
,
2091 const gdb_byte
*bytes
,
2092 offset_type elements
)
2095 htab_t sig_types_hash
;
2097 dwarf2_per_objfile
->n_type_units
= elements
/ 3;
2098 dwarf2_per_objfile
->all_type_units
2099 = obstack_alloc (&objfile
->objfile_obstack
,
2100 dwarf2_per_objfile
->n_type_units
2101 * sizeof (struct dwarf2_per_cu_data
*));
2103 sig_types_hash
= allocate_signatured_type_table (objfile
);
2105 for (i
= 0; i
< elements
; i
+= 3)
2107 struct signatured_type
*sig_type
;
2108 ULONGEST offset
, type_offset_in_tu
, signature
;
2111 if (!extract_cu_value (bytes
, &offset
)
2112 || !extract_cu_value (bytes
+ 8, &type_offset_in_tu
))
2114 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2117 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2118 struct signatured_type
);
2119 sig_type
->signature
= signature
;
2120 sig_type
->type_offset_in_tu
.cu_off
= type_offset_in_tu
;
2121 sig_type
->per_cu
.is_debug_types
= 1;
2122 sig_type
->per_cu
.info_or_types_section
= section
;
2123 sig_type
->per_cu
.offset
.sect_off
= offset
;
2124 sig_type
->per_cu
.objfile
= objfile
;
2125 sig_type
->per_cu
.v
.quick
2126 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2127 struct dwarf2_per_cu_quick_data
);
2129 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
2132 dwarf2_per_objfile
->all_type_units
[i
/ 3] = &sig_type
->per_cu
;
2135 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2140 /* Read the address map data from the mapped index, and use it to
2141 populate the objfile's psymtabs_addrmap. */
2144 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
2146 const gdb_byte
*iter
, *end
;
2147 struct obstack temp_obstack
;
2148 struct addrmap
*mutable_map
;
2149 struct cleanup
*cleanup
;
2152 obstack_init (&temp_obstack
);
2153 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2154 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2156 iter
= index
->address_table
;
2157 end
= iter
+ index
->address_table_size
;
2159 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2163 ULONGEST hi
, lo
, cu_index
;
2164 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2166 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2168 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2171 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
2172 dw2_get_cu (cu_index
));
2175 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
2176 &objfile
->objfile_obstack
);
2177 do_cleanups (cleanup
);
2180 /* The hash function for strings in the mapped index. This is the same as
2181 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2182 implementation. This is necessary because the hash function is tied to the
2183 format of the mapped index file. The hash values do not have to match with
2186 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2189 mapped_index_string_hash (int index_version
, const void *p
)
2191 const unsigned char *str
= (const unsigned char *) p
;
2195 while ((c
= *str
++) != 0)
2197 if (index_version
>= 5)
2199 r
= r
* 67 + c
- 113;
2205 /* Find a slot in the mapped index INDEX for the object named NAME.
2206 If NAME is found, set *VEC_OUT to point to the CU vector in the
2207 constant pool and return 1. If NAME cannot be found, return 0. */
2210 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2211 offset_type
**vec_out
)
2213 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2215 offset_type slot
, step
;
2216 int (*cmp
) (const char *, const char *);
2218 if (current_language
->la_language
== language_cplus
2219 || current_language
->la_language
== language_java
2220 || current_language
->la_language
== language_fortran
)
2222 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2224 const char *paren
= strchr (name
, '(');
2230 dup
= xmalloc (paren
- name
+ 1);
2231 memcpy (dup
, name
, paren
- name
);
2232 dup
[paren
- name
] = 0;
2234 make_cleanup (xfree
, dup
);
2239 /* Index version 4 did not support case insensitive searches. But the
2240 indices for case insensitive languages are built in lowercase, therefore
2241 simulate our NAME being searched is also lowercased. */
2242 hash
= mapped_index_string_hash ((index
->version
== 4
2243 && case_sensitivity
== case_sensitive_off
2244 ? 5 : index
->version
),
2247 slot
= hash
& (index
->symbol_table_slots
- 1);
2248 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2249 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2253 /* Convert a slot number to an offset into the table. */
2254 offset_type i
= 2 * slot
;
2256 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2258 do_cleanups (back_to
);
2262 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2263 if (!cmp (name
, str
))
2265 *vec_out
= (offset_type
*) (index
->constant_pool
2266 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2267 do_cleanups (back_to
);
2271 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2275 /* Read the index file. If everything went ok, initialize the "quick"
2276 elements of all the CUs and return 1. Otherwise, return 0. */
2279 dwarf2_read_index (struct objfile
*objfile
)
2282 struct mapped_index
*map
;
2283 offset_type
*metadata
;
2284 const gdb_byte
*cu_list
;
2285 const gdb_byte
*types_list
= NULL
;
2286 offset_type version
, cu_list_elements
;
2287 offset_type types_list_elements
= 0;
2290 if (dwarf2_section_empty_p (&dwarf2_per_objfile
->gdb_index
))
2293 /* Older elfutils strip versions could keep the section in the main
2294 executable while splitting it for the separate debug info file. */
2295 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
2296 & SEC_HAS_CONTENTS
) == 0)
2299 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
2301 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
2302 /* Version check. */
2303 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2304 /* Versions earlier than 3 emitted every copy of a psymbol. This
2305 causes the index to behave very poorly for certain requests. Version 3
2306 contained incomplete addrmap. So, it seems better to just ignore such
2310 static int warning_printed
= 0;
2311 if (!warning_printed
)
2313 warning (_("Skipping obsolete .gdb_index section in %s."),
2315 warning_printed
= 1;
2319 /* Index version 4 uses a different hash function than index version
2322 Versions earlier than 6 did not emit psymbols for inlined
2323 functions. Using these files will cause GDB not to be able to
2324 set breakpoints on inlined functions by name, so we ignore these
2325 indices unless the --use-deprecated-index-sections command line
2326 option was supplied. */
2327 if (version
< 6 && !use_deprecated_index_sections
)
2329 static int warning_printed
= 0;
2330 if (!warning_printed
)
2332 warning (_("Skipping deprecated .gdb_index section in %s, pass "
2333 "--use-deprecated-index-sections to use them anyway"),
2335 warning_printed
= 1;
2339 /* Indexes with higher version than the one supported by GDB may be no
2340 longer backward compatible. */
2344 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
2345 map
->version
= version
;
2346 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
2348 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2351 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2352 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2356 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2357 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2358 - MAYBE_SWAP (metadata
[i
]))
2362 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2363 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2364 - MAYBE_SWAP (metadata
[i
]));
2367 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2368 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2369 - MAYBE_SWAP (metadata
[i
]))
2370 / (2 * sizeof (offset_type
)));
2373 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2375 /* Don't use the index if it's empty. */
2376 if (map
->symbol_table_slots
== 0)
2379 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
2382 if (types_list_elements
)
2384 struct dwarf2_section_info
*section
;
2386 /* We can only handle a single .debug_types when we have an
2388 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2391 section
= VEC_index (dwarf2_section_info_def
,
2392 dwarf2_per_objfile
->types
, 0);
2394 if (!create_signatured_type_table_from_index (objfile
, section
,
2396 types_list_elements
))
2400 create_addrmap_from_index (objfile
, map
);
2402 dwarf2_per_objfile
->index_table
= map
;
2403 dwarf2_per_objfile
->using_index
= 1;
2404 dwarf2_per_objfile
->quick_file_names_table
=
2405 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2410 /* A helper for the "quick" functions which sets the global
2411 dwarf2_per_objfile according to OBJFILE. */
2414 dw2_setup (struct objfile
*objfile
)
2416 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2417 gdb_assert (dwarf2_per_objfile
);
2420 /* die_reader_func for dw2_get_file_names. */
2423 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
2425 struct die_info
*comp_unit_die
,
2429 struct dwarf2_cu
*cu
= reader
->cu
;
2430 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
2431 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2432 struct line_header
*lh
;
2433 struct attribute
*attr
;
2435 char *name
, *comp_dir
;
2437 struct quick_file_names
*qfn
;
2438 unsigned int line_offset
;
2444 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
2447 struct quick_file_names find_entry
;
2449 line_offset
= DW_UNSND (attr
);
2451 /* We may have already read in this line header (TU line header sharing).
2452 If we have we're done. */
2453 find_entry
.offset
= line_offset
;
2454 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2455 &find_entry
, INSERT
);
2458 this_cu
->v
.quick
->file_names
= *slot
;
2462 lh
= dwarf_decode_line_header (line_offset
, cu
);
2466 this_cu
->v
.quick
->no_file_data
= 1;
2470 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2471 qfn
->offset
= line_offset
;
2472 gdb_assert (slot
!= NULL
);
2475 find_file_and_directory (comp_unit_die
, cu
, &name
, &comp_dir
);
2477 qfn
->num_file_names
= lh
->num_file_names
;
2478 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2479 lh
->num_file_names
* sizeof (char *));
2480 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2481 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2482 qfn
->real_names
= NULL
;
2484 free_line_header (lh
);
2486 this_cu
->v
.quick
->file_names
= qfn
;
2489 /* A helper for the "quick" functions which attempts to read the line
2490 table for THIS_CU. */
2492 static struct quick_file_names
*
2493 dw2_get_file_names (struct objfile
*objfile
,
2494 struct dwarf2_per_cu_data
*this_cu
)
2496 if (this_cu
->v
.quick
->file_names
!= NULL
)
2497 return this_cu
->v
.quick
->file_names
;
2498 /* If we know there is no line data, no point in looking again. */
2499 if (this_cu
->v
.quick
->no_file_data
)
2502 /* If DWO files are in use, we can still find the DW_AT_stmt_list attribute
2503 in the stub for CUs, there's is no need to lookup the DWO file.
2504 However, that's not the case for TUs where DW_AT_stmt_list lives in the
2506 if (this_cu
->is_debug_types
)
2507 init_cutu_and_read_dies (this_cu
, 0, 0, dw2_get_file_names_reader
, NULL
);
2509 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
2511 if (this_cu
->v
.quick
->no_file_data
)
2513 return this_cu
->v
.quick
->file_names
;
2516 /* A helper for the "quick" functions which computes and caches the
2517 real path for a given file name from the line table. */
2520 dw2_get_real_path (struct objfile
*objfile
,
2521 struct quick_file_names
*qfn
, int index
)
2523 if (qfn
->real_names
== NULL
)
2524 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2525 qfn
->num_file_names
, sizeof (char *));
2527 if (qfn
->real_names
[index
] == NULL
)
2528 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2530 return qfn
->real_names
[index
];
2533 static struct symtab
*
2534 dw2_find_last_source_symtab (struct objfile
*objfile
)
2538 dw2_setup (objfile
);
2539 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2540 return dw2_instantiate_symtab (dw2_get_cu (index
));
2543 /* Traversal function for dw2_forget_cached_source_info. */
2546 dw2_free_cached_file_names (void **slot
, void *info
)
2548 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2550 if (file_data
->real_names
)
2554 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2556 xfree ((void*) file_data
->real_names
[i
]);
2557 file_data
->real_names
[i
] = NULL
;
2565 dw2_forget_cached_source_info (struct objfile
*objfile
)
2567 dw2_setup (objfile
);
2569 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2570 dw2_free_cached_file_names
, NULL
);
2573 /* Helper function for dw2_map_symtabs_matching_filename that expands
2574 the symtabs and calls the iterator. */
2577 dw2_map_expand_apply (struct objfile
*objfile
,
2578 struct dwarf2_per_cu_data
*per_cu
,
2580 const char *full_path
, const char *real_path
,
2581 int (*callback
) (struct symtab
*, void *),
2584 struct symtab
*last_made
= objfile
->symtabs
;
2586 /* Don't visit already-expanded CUs. */
2587 if (per_cu
->v
.quick
->symtab
)
2590 /* This may expand more than one symtab, and we want to iterate over
2592 dw2_instantiate_symtab (per_cu
);
2594 return iterate_over_some_symtabs (name
, full_path
, real_path
, callback
, data
,
2595 objfile
->symtabs
, last_made
);
2598 /* Implementation of the map_symtabs_matching_filename method. */
2601 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
2602 const char *full_path
, const char *real_path
,
2603 int (*callback
) (struct symtab
*, void *),
2607 const char *name_basename
= lbasename (name
);
2608 int name_len
= strlen (name
);
2609 int is_abs
= IS_ABSOLUTE_PATH (name
);
2611 dw2_setup (objfile
);
2613 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2614 + dwarf2_per_objfile
->n_type_units
); ++i
)
2617 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2618 struct quick_file_names
*file_data
;
2620 /* We only need to look at symtabs not already expanded. */
2621 if (per_cu
->v
.quick
->symtab
)
2624 file_data
= dw2_get_file_names (objfile
, per_cu
);
2625 if (file_data
== NULL
)
2628 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2630 const char *this_name
= file_data
->file_names
[j
];
2632 if (FILENAME_CMP (name
, this_name
) == 0
2633 || (!is_abs
&& compare_filenames_for_search (this_name
,
2636 if (dw2_map_expand_apply (objfile
, per_cu
,
2637 name
, full_path
, real_path
,
2642 /* Before we invoke realpath, which can get expensive when many
2643 files are involved, do a quick comparison of the basenames. */
2644 if (! basenames_may_differ
2645 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
2648 if (full_path
!= NULL
)
2650 const char *this_real_name
= dw2_get_real_path (objfile
,
2653 if (this_real_name
!= NULL
2654 && (FILENAME_CMP (full_path
, this_real_name
) == 0
2656 && compare_filenames_for_search (this_real_name
,
2659 if (dw2_map_expand_apply (objfile
, per_cu
,
2660 name
, full_path
, real_path
,
2666 if (real_path
!= NULL
)
2668 const char *this_real_name
= dw2_get_real_path (objfile
,
2671 if (this_real_name
!= NULL
2672 && (FILENAME_CMP (real_path
, this_real_name
) == 0
2674 && compare_filenames_for_search (this_real_name
,
2677 if (dw2_map_expand_apply (objfile
, per_cu
,
2678 name
, full_path
, real_path
,
2689 static struct symtab
*
2690 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2691 const char *name
, domain_enum domain
)
2693 /* We do all the work in the pre_expand_symtabs_matching hook
2698 /* A helper function that expands all symtabs that hold an object
2702 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2704 dw2_setup (objfile
);
2706 /* index_table is NULL if OBJF_READNOW. */
2707 if (dwarf2_per_objfile
->index_table
)
2711 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2714 offset_type i
, len
= MAYBE_SWAP (*vec
);
2715 for (i
= 0; i
< len
; ++i
)
2717 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2718 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2720 dw2_instantiate_symtab (per_cu
);
2727 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2728 enum block_enum block_kind
, const char *name
,
2731 dw2_do_expand_symtabs_matching (objfile
, name
);
2735 dw2_print_stats (struct objfile
*objfile
)
2739 dw2_setup (objfile
);
2741 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2742 + dwarf2_per_objfile
->n_type_units
); ++i
)
2744 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2746 if (!per_cu
->v
.quick
->symtab
)
2749 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2753 dw2_dump (struct objfile
*objfile
)
2755 /* Nothing worth printing. */
2759 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2760 struct section_offsets
*delta
)
2762 /* There's nothing to relocate here. */
2766 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2767 const char *func_name
)
2769 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2773 dw2_expand_all_symtabs (struct objfile
*objfile
)
2777 dw2_setup (objfile
);
2779 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2780 + dwarf2_per_objfile
->n_type_units
); ++i
)
2782 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2784 dw2_instantiate_symtab (per_cu
);
2789 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2790 const char *filename
)
2794 dw2_setup (objfile
);
2796 /* We don't need to consider type units here.
2797 This is only called for examining code, e.g. expand_line_sal.
2798 There can be an order of magnitude (or more) more type units
2799 than comp units, and we avoid them if we can. */
2801 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2804 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2805 struct quick_file_names
*file_data
;
2807 /* We only need to look at symtabs not already expanded. */
2808 if (per_cu
->v
.quick
->symtab
)
2811 file_data
= dw2_get_file_names (objfile
, per_cu
);
2812 if (file_data
== NULL
)
2815 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2817 const char *this_name
= file_data
->file_names
[j
];
2818 if (FILENAME_CMP (this_name
, filename
) == 0)
2820 dw2_instantiate_symtab (per_cu
);
2828 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2830 struct dwarf2_per_cu_data
*per_cu
;
2832 struct quick_file_names
*file_data
;
2834 dw2_setup (objfile
);
2836 /* index_table is NULL if OBJF_READNOW. */
2837 if (!dwarf2_per_objfile
->index_table
)
2841 ALL_OBJFILE_SYMTABS (objfile
, s
)
2844 struct blockvector
*bv
= BLOCKVECTOR (s
);
2845 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2846 struct symbol
*sym
= lookup_block_symbol (block
, name
, VAR_DOMAIN
);
2849 return sym
->symtab
->filename
;
2854 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2858 /* Note that this just looks at the very first one named NAME -- but
2859 actually we are looking for a function. find_main_filename
2860 should be rewritten so that it doesn't require a custom hook. It
2861 could just use the ordinary symbol tables. */
2862 /* vec[0] is the length, which must always be >0. */
2863 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[1]));
2865 file_data
= dw2_get_file_names (objfile
, per_cu
);
2866 if (file_data
== NULL
2867 || file_data
->num_file_names
== 0)
2870 return file_data
->file_names
[file_data
->num_file_names
- 1];
2874 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
2875 struct objfile
*objfile
, int global
,
2876 int (*callback
) (struct block
*,
2877 struct symbol
*, void *),
2878 void *data
, symbol_compare_ftype
*match
,
2879 symbol_compare_ftype
*ordered_compare
)
2881 /* Currently unimplemented; used for Ada. The function can be called if the
2882 current language is Ada for a non-Ada objfile using GNU index. As Ada
2883 does not look for non-Ada symbols this function should just return. */
2887 dw2_expand_symtabs_matching
2888 (struct objfile
*objfile
,
2889 int (*file_matcher
) (const char *, void *),
2890 int (*name_matcher
) (const char *, void *),
2891 enum search_domain kind
,
2896 struct mapped_index
*index
;
2898 dw2_setup (objfile
);
2900 /* index_table is NULL if OBJF_READNOW. */
2901 if (!dwarf2_per_objfile
->index_table
)
2903 index
= dwarf2_per_objfile
->index_table
;
2905 if (file_matcher
!= NULL
)
2907 struct cleanup
*cleanup
;
2908 htab_t visited_found
, visited_not_found
;
2910 visited_found
= htab_create_alloc (10,
2911 htab_hash_pointer
, htab_eq_pointer
,
2912 NULL
, xcalloc
, xfree
);
2913 cleanup
= make_cleanup_htab_delete (visited_found
);
2914 visited_not_found
= htab_create_alloc (10,
2915 htab_hash_pointer
, htab_eq_pointer
,
2916 NULL
, xcalloc
, xfree
);
2917 make_cleanup_htab_delete (visited_not_found
);
2919 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2920 + dwarf2_per_objfile
->n_type_units
); ++i
)
2923 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2924 struct quick_file_names
*file_data
;
2927 per_cu
->v
.quick
->mark
= 0;
2929 /* We only need to look at symtabs not already expanded. */
2930 if (per_cu
->v
.quick
->symtab
)
2933 file_data
= dw2_get_file_names (objfile
, per_cu
);
2934 if (file_data
== NULL
)
2937 if (htab_find (visited_not_found
, file_data
) != NULL
)
2939 else if (htab_find (visited_found
, file_data
) != NULL
)
2941 per_cu
->v
.quick
->mark
= 1;
2945 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2947 if (file_matcher (file_data
->file_names
[j
], data
))
2949 per_cu
->v
.quick
->mark
= 1;
2954 slot
= htab_find_slot (per_cu
->v
.quick
->mark
2956 : visited_not_found
,
2961 do_cleanups (cleanup
);
2964 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2966 offset_type idx
= 2 * iter
;
2968 offset_type
*vec
, vec_len
, vec_idx
;
2970 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2973 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
2975 if (! (*name_matcher
) (name
, data
))
2978 /* The name was matched, now expand corresponding CUs that were
2980 vec
= (offset_type
*) (index
->constant_pool
2981 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
2982 vec_len
= MAYBE_SWAP (vec
[0]);
2983 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2985 struct dwarf2_per_cu_data
*per_cu
;
2987 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[vec_idx
+ 1]));
2988 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
2989 dw2_instantiate_symtab (per_cu
);
2994 /* A helper for dw2_find_pc_sect_symtab which finds the most specific
2997 static struct symtab
*
2998 recursively_find_pc_sect_symtab (struct symtab
*symtab
, CORE_ADDR pc
)
3002 if (BLOCKVECTOR (symtab
) != NULL
3003 && blockvector_contains_pc (BLOCKVECTOR (symtab
), pc
))
3006 for (i
= 0; symtab
->includes
[i
]; ++i
)
3010 s
= recursively_find_pc_sect_symtab (s
, pc
);
3018 static struct symtab
*
3019 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
3020 struct minimal_symbol
*msymbol
,
3022 struct obj_section
*section
,
3025 struct dwarf2_per_cu_data
*data
;
3026 struct symtab
*result
;
3028 dw2_setup (objfile
);
3030 if (!objfile
->psymtabs_addrmap
)
3033 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
3037 if (warn_if_readin
&& data
->v
.quick
->symtab
)
3038 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
3039 paddress (get_objfile_arch (objfile
), pc
));
3041 result
= recursively_find_pc_sect_symtab (dw2_instantiate_symtab (data
), pc
);
3042 gdb_assert (result
!= NULL
);
3047 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
3048 void *data
, int need_fullname
)
3051 struct cleanup
*cleanup
;
3052 htab_t visited
= htab_create_alloc (10, htab_hash_pointer
, htab_eq_pointer
,
3053 NULL
, xcalloc
, xfree
);
3055 cleanup
= make_cleanup_htab_delete (visited
);
3056 dw2_setup (objfile
);
3058 /* We can ignore file names coming from already-expanded CUs. */
3059 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3060 + dwarf2_per_objfile
->n_type_units
); ++i
)
3062 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3064 if (per_cu
->v
.quick
->symtab
)
3066 void **slot
= htab_find_slot (visited
, per_cu
->v
.quick
->file_names
,
3069 *slot
= per_cu
->v
.quick
->file_names
;
3073 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3074 + dwarf2_per_objfile
->n_type_units
); ++i
)
3077 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3078 struct quick_file_names
*file_data
;
3081 /* We only need to look at symtabs not already expanded. */
3082 if (per_cu
->v
.quick
->symtab
)
3085 file_data
= dw2_get_file_names (objfile
, per_cu
);
3086 if (file_data
== NULL
)
3089 slot
= htab_find_slot (visited
, file_data
, INSERT
);
3092 /* Already visited. */
3097 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3099 const char *this_real_name
;
3102 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3104 this_real_name
= NULL
;
3105 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
3109 do_cleanups (cleanup
);
3113 dw2_has_symbols (struct objfile
*objfile
)
3118 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
3121 dw2_find_last_source_symtab
,
3122 dw2_forget_cached_source_info
,
3123 dw2_map_symtabs_matching_filename
,
3125 dw2_pre_expand_symtabs_matching
,
3129 dw2_expand_symtabs_for_function
,
3130 dw2_expand_all_symtabs
,
3131 dw2_expand_symtabs_with_filename
,
3132 dw2_find_symbol_file
,
3133 dw2_map_matching_symbols
,
3134 dw2_expand_symtabs_matching
,
3135 dw2_find_pc_sect_symtab
,
3136 dw2_map_symbol_filenames
3139 /* Initialize for reading DWARF for this objfile. Return 0 if this
3140 file will use psymtabs, or 1 if using the GNU index. */
3143 dwarf2_initialize_objfile (struct objfile
*objfile
)
3145 /* If we're about to read full symbols, don't bother with the
3146 indices. In this case we also don't care if some other debug
3147 format is making psymtabs, because they are all about to be
3149 if ((objfile
->flags
& OBJF_READNOW
))
3153 dwarf2_per_objfile
->using_index
= 1;
3154 create_all_comp_units (objfile
);
3155 create_all_type_units (objfile
);
3156 dwarf2_per_objfile
->quick_file_names_table
=
3157 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3159 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3160 + dwarf2_per_objfile
->n_type_units
); ++i
)
3162 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3164 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3165 struct dwarf2_per_cu_quick_data
);
3168 /* Return 1 so that gdb sees the "quick" functions. However,
3169 these functions will be no-ops because we will have expanded
3174 if (dwarf2_read_index (objfile
))
3182 /* Build a partial symbol table. */
3185 dwarf2_build_psymtabs (struct objfile
*objfile
)
3187 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
3189 init_psymbol_list (objfile
, 1024);
3192 dwarf2_build_psymtabs_hard (objfile
);
3195 /* Return TRUE if OFFSET is within CU_HEADER. */
3198 offset_in_cu_p (const struct comp_unit_head
*cu_header
, sect_offset offset
)
3200 sect_offset bottom
= { cu_header
->offset
.sect_off
};
3201 sect_offset top
= { (cu_header
->offset
.sect_off
+ cu_header
->length
3202 + cu_header
->initial_length_size
) };
3204 return (offset
.sect_off
>= bottom
.sect_off
&& offset
.sect_off
< top
.sect_off
);
3207 /* Read in the comp unit header information from the debug_info at info_ptr.
3208 NOTE: This leaves members offset, first_die_offset to be filled in
3212 read_comp_unit_head (struct comp_unit_head
*cu_header
,
3213 gdb_byte
*info_ptr
, bfd
*abfd
)
3216 unsigned int bytes_read
;
3218 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
3219 cu_header
->initial_length_size
= bytes_read
;
3220 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
3221 info_ptr
+= bytes_read
;
3222 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
3224 cu_header
->abbrev_offset
.sect_off
= read_offset (abfd
, info_ptr
, cu_header
,
3226 info_ptr
+= bytes_read
;
3227 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
3229 signed_addr
= bfd_get_sign_extend_vma (abfd
);
3230 if (signed_addr
< 0)
3231 internal_error (__FILE__
, __LINE__
,
3232 _("read_comp_unit_head: dwarf from non elf file"));
3233 cu_header
->signed_addr_p
= signed_addr
;
3238 /* Subroutine of read_and_check_comp_unit_head and
3239 read_and_check_type_unit_head to simplify them.
3240 Perform various error checking on the header. */
3243 error_check_comp_unit_head (struct comp_unit_head
*header
,
3244 struct dwarf2_section_info
*section
)
3246 bfd
*abfd
= section
->asection
->owner
;
3247 const char *filename
= bfd_get_filename (abfd
);
3249 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
3250 error (_("Dwarf Error: wrong version in compilation unit header "
3251 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
3254 if (header
->abbrev_offset
.sect_off
3255 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
3256 &dwarf2_per_objfile
->abbrev
))
3257 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3258 "(offset 0x%lx + 6) [in module %s]"),
3259 (long) header
->abbrev_offset
.sect_off
, (long) header
->offset
.sect_off
,
3262 /* Cast to unsigned long to use 64-bit arithmetic when possible to
3263 avoid potential 32-bit overflow. */
3264 if (((unsigned long) header
->offset
.sect_off
3265 + header
->length
+ header
->initial_length_size
)
3267 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3268 "(offset 0x%lx + 0) [in module %s]"),
3269 (long) header
->length
, (long) header
->offset
.sect_off
,
3273 /* Read in a CU/TU header and perform some basic error checking.
3274 The contents of the header are stored in HEADER.
3275 The result is a pointer to the start of the first DIE. */
3278 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
3279 struct dwarf2_section_info
*section
,
3281 int is_debug_types_section
)
3283 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3284 bfd
*abfd
= section
->asection
->owner
;
3286 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3288 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3290 /* If we're reading a type unit, skip over the signature and
3291 type_offset fields. */
3292 if (is_debug_types_section
)
3293 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
3295 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3297 error_check_comp_unit_head (header
, section
);
3302 /* Read in the types comp unit header information from .debug_types entry at
3303 types_ptr. The result is a pointer to one past the end of the header. */
3306 read_and_check_type_unit_head (struct comp_unit_head
*header
,
3307 struct dwarf2_section_info
*section
,
3309 ULONGEST
*signature
,
3310 cu_offset
*type_offset_in_tu
)
3312 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3313 bfd
*abfd
= section
->asection
->owner
;
3315 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3317 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3319 /* If we're reading a type unit, skip over the signature and
3320 type_offset fields. */
3321 if (signature
!= NULL
)
3322 *signature
= read_8_bytes (abfd
, info_ptr
);
3324 if (type_offset_in_tu
!= NULL
)
3325 type_offset_in_tu
->cu_off
= read_offset_1 (abfd
, info_ptr
,
3326 header
->offset_size
);
3327 info_ptr
+= header
->offset_size
;
3329 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3331 error_check_comp_unit_head (header
, section
);
3336 /* Allocate a new partial symtab for file named NAME and mark this new
3337 partial symtab as being an include of PST. */
3340 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
3341 struct objfile
*objfile
)
3343 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
3345 subpst
->section_offsets
= pst
->section_offsets
;
3346 subpst
->textlow
= 0;
3347 subpst
->texthigh
= 0;
3349 subpst
->dependencies
= (struct partial_symtab
**)
3350 obstack_alloc (&objfile
->objfile_obstack
,
3351 sizeof (struct partial_symtab
*));
3352 subpst
->dependencies
[0] = pst
;
3353 subpst
->number_of_dependencies
= 1;
3355 subpst
->globals_offset
= 0;
3356 subpst
->n_global_syms
= 0;
3357 subpst
->statics_offset
= 0;
3358 subpst
->n_static_syms
= 0;
3359 subpst
->symtab
= NULL
;
3360 subpst
->read_symtab
= pst
->read_symtab
;
3363 /* No private part is necessary for include psymtabs. This property
3364 can be used to differentiate between such include psymtabs and
3365 the regular ones. */
3366 subpst
->read_symtab_private
= NULL
;
3369 /* Read the Line Number Program data and extract the list of files
3370 included by the source file represented by PST. Build an include
3371 partial symtab for each of these included files. */
3374 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
3375 struct die_info
*die
,
3376 struct partial_symtab
*pst
)
3378 struct line_header
*lh
= NULL
;
3379 struct attribute
*attr
;
3381 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3383 lh
= dwarf_decode_line_header (DW_UNSND (attr
), cu
);
3385 return; /* No linetable, so no includes. */
3387 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3388 dwarf_decode_lines (lh
, pst
->dirname
, cu
, pst
, 1);
3390 free_line_header (lh
);
3394 hash_signatured_type (const void *item
)
3396 const struct signatured_type
*sig_type
= item
;
3398 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3399 return sig_type
->signature
;
3403 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
3405 const struct signatured_type
*lhs
= item_lhs
;
3406 const struct signatured_type
*rhs
= item_rhs
;
3408 return lhs
->signature
== rhs
->signature
;
3411 /* Allocate a hash table for signatured types. */
3414 allocate_signatured_type_table (struct objfile
*objfile
)
3416 return htab_create_alloc_ex (41,
3417 hash_signatured_type
,
3420 &objfile
->objfile_obstack
,
3421 hashtab_obstack_allocate
,
3422 dummy_obstack_deallocate
);
3425 /* A helper function to add a signatured type CU to a table. */
3428 add_signatured_type_cu_to_table (void **slot
, void *datum
)
3430 struct signatured_type
*sigt
= *slot
;
3431 struct dwarf2_per_cu_data
***datap
= datum
;
3433 **datap
= &sigt
->per_cu
;
3439 /* Create the hash table of all entries in the .debug_types section.
3440 DWO_FILE is a pointer to the DWO file for .debug_types.dwo, NULL otherwise.
3441 The result is a pointer to the hash table or NULL if there are
3445 create_debug_types_hash_table (struct dwo_file
*dwo_file
,
3446 VEC (dwarf2_section_info_def
) *types
)
3448 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3449 htab_t types_htab
= NULL
;
3451 struct dwarf2_section_info
*section
;
3453 if (VEC_empty (dwarf2_section_info_def
, types
))
3457 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
3461 gdb_byte
*info_ptr
, *end_ptr
;
3463 dwarf2_read_section (objfile
, section
);
3464 info_ptr
= section
->buffer
;
3466 if (info_ptr
== NULL
)
3469 /* We can't set abfd until now because the section may be empty or
3470 not present, in which case section->asection will be NULL. */
3471 abfd
= section
->asection
->owner
;
3473 if (types_htab
== NULL
)
3476 types_htab
= allocate_dwo_unit_table (objfile
);
3478 types_htab
= allocate_signatured_type_table (objfile
);
3481 if (dwarf2_die_debug
)
3482 fprintf_unfiltered (gdb_stdlog
, "Reading signatured types for %s:\n",
3483 bfd_get_filename (abfd
));
3485 /* We don't use init_cutu_and_read_dies_simple, or some such, here
3486 because we don't need to read any dies: the signature is in the
3489 end_ptr
= info_ptr
+ section
->size
;
3490 while (info_ptr
< end_ptr
)
3493 cu_offset type_offset_in_tu
;
3495 struct signatured_type
*sig_type
;
3496 struct dwo_unit
*dwo_tu
;
3498 gdb_byte
*ptr
= info_ptr
;
3499 struct comp_unit_head header
;
3500 unsigned int length
;
3502 offset
.sect_off
= ptr
- section
->buffer
;
3504 /* We need to read the type's signature in order to build the hash
3505 table, but we don't need anything else just yet. */
3507 ptr
= read_and_check_type_unit_head (&header
, section
, ptr
,
3508 &signature
, &type_offset_in_tu
);
3510 length
= header
.initial_length_size
+ header
.length
;
3512 /* Skip dummy type units. */
3513 if (ptr
>= info_ptr
+ length
3514 || peek_abbrev_code (abfd
, ptr
) == 0)
3516 info_ptr
+= header
.initial_length_size
+ header
.length
;
3523 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3525 dwo_tu
->dwo_file
= dwo_file
;
3526 dwo_tu
->signature
= signature
;
3527 dwo_tu
->type_offset_in_tu
= type_offset_in_tu
;
3528 dwo_tu
->info_or_types_section
= section
;
3529 dwo_tu
->offset
= offset
;
3530 dwo_tu
->length
= length
;
3534 /* N.B.: type_offset is not usable if this type uses a DWO file.
3535 The real type_offset is in the DWO file. */
3537 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3538 struct signatured_type
);
3539 sig_type
->signature
= signature
;
3540 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3541 sig_type
->per_cu
.objfile
= objfile
;
3542 sig_type
->per_cu
.is_debug_types
= 1;
3543 sig_type
->per_cu
.info_or_types_section
= section
;
3544 sig_type
->per_cu
.offset
= offset
;
3545 sig_type
->per_cu
.length
= length
;
3548 slot
= htab_find_slot (types_htab
,
3549 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
3551 gdb_assert (slot
!= NULL
);
3554 sect_offset dup_offset
;
3558 const struct dwo_unit
*dup_tu
= *slot
;
3560 dup_offset
= dup_tu
->offset
;
3564 const struct signatured_type
*dup_tu
= *slot
;
3566 dup_offset
= dup_tu
->per_cu
.offset
;
3569 complaint (&symfile_complaints
,
3570 _("debug type entry at offset 0x%x is duplicate to the "
3571 "entry at offset 0x%x, signature 0x%s"),
3572 offset
.sect_off
, dup_offset
.sect_off
,
3573 phex (signature
, sizeof (signature
)));
3575 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
3577 if (dwarf2_die_debug
)
3578 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3580 phex (signature
, sizeof (signature
)));
3589 /* Create the hash table of all entries in the .debug_types section,
3590 and initialize all_type_units.
3591 The result is zero if there is an error (e.g. missing .debug_types section),
3592 otherwise non-zero. */
3595 create_all_type_units (struct objfile
*objfile
)
3598 struct dwarf2_per_cu_data
**iter
;
3600 types_htab
= create_debug_types_hash_table (NULL
, dwarf2_per_objfile
->types
);
3601 if (types_htab
== NULL
)
3603 dwarf2_per_objfile
->signatured_types
= NULL
;
3607 dwarf2_per_objfile
->signatured_types
= types_htab
;
3609 dwarf2_per_objfile
->n_type_units
= htab_elements (types_htab
);
3610 dwarf2_per_objfile
->all_type_units
3611 = obstack_alloc (&objfile
->objfile_obstack
,
3612 dwarf2_per_objfile
->n_type_units
3613 * sizeof (struct dwarf2_per_cu_data
*));
3614 iter
= &dwarf2_per_objfile
->all_type_units
[0];
3615 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
3616 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
3617 == dwarf2_per_objfile
->n_type_units
);
3622 /* Lookup a signature based type for DW_FORM_ref_sig8.
3623 Returns NULL if signature SIG is not present in the table. */
3625 static struct signatured_type
*
3626 lookup_signatured_type (ULONGEST sig
)
3628 struct signatured_type find_entry
, *entry
;
3630 if (dwarf2_per_objfile
->signatured_types
== NULL
)
3632 complaint (&symfile_complaints
,
3633 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3637 find_entry
.signature
= sig
;
3638 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
3642 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3645 init_cu_die_reader (struct die_reader_specs
*reader
,
3646 struct dwarf2_cu
*cu
,
3647 struct dwarf2_section_info
*section
,
3648 struct dwo_file
*dwo_file
)
3650 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
3651 reader
->abfd
= section
->asection
->owner
;
3653 reader
->dwo_file
= dwo_file
;
3654 reader
->die_section
= section
;
3655 reader
->buffer
= section
->buffer
;
3658 /* Find the base address of the compilation unit for range lists and
3659 location lists. It will normally be specified by DW_AT_low_pc.
3660 In DWARF-3 draft 4, the base address could be overridden by
3661 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3662 compilation units with discontinuous ranges. */
3665 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3667 struct attribute
*attr
;
3670 cu
->base_address
= 0;
3672 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3675 cu
->base_address
= DW_ADDR (attr
);
3680 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3683 cu
->base_address
= DW_ADDR (attr
);
3689 /* Initialize a CU (or TU) and read its DIEs.
3690 If the CU defers to a DWO file, read the DWO file as well.
3692 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
3693 Otherwise, a new CU is allocated with xmalloc.
3695 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
3696 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
3698 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
3699 linker) then DIE_READER_FUNC will not get called. */
3702 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
3703 int use_existing_cu
, int keep
,
3704 die_reader_func_ftype
*die_reader_func
,
3707 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3708 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
3709 bfd
*abfd
= section
->asection
->owner
;
3710 struct dwarf2_cu
*cu
;
3711 gdb_byte
*begin_info_ptr
, *info_ptr
;
3712 struct die_reader_specs reader
;
3713 struct die_info
*comp_unit_die
;
3715 struct attribute
*attr
;
3716 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
3717 struct signatured_type
*sig_type
= NULL
;
3719 if (use_existing_cu
)
3722 cleanups
= make_cleanup (null_cleanup
, NULL
);
3724 /* This is cheap if the section is already read in. */
3725 dwarf2_read_section (objfile
, section
);
3727 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
3729 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
3732 info_ptr
+= cu
->header
.first_die_offset
.cu_off
;
3736 /* If !use_existing_cu, this_cu->cu must be NULL. */
3737 gdb_assert (this_cu
->cu
== NULL
);
3739 cu
= xmalloc (sizeof (*cu
));
3740 init_one_comp_unit (cu
, this_cu
);
3742 /* If an error occurs while loading, release our storage. */
3743 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
3745 if (this_cu
->is_debug_types
)
3749 info_ptr
= read_and_check_type_unit_head (&cu
->header
,
3753 /* There's no way to get from PER_CU to its containing
3754 struct signatured_type.
3755 But we have the signature so we can use that. */
3756 sig_type
= lookup_signatured_type (signature
);
3757 /* We've already scanned all the signatured types,
3758 this must succeed. */
3759 gdb_assert (sig_type
!= NULL
);
3760 gdb_assert (&sig_type
->per_cu
== this_cu
);
3761 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
3763 /* LENGTH has not been set yet for type units. */
3764 this_cu
->length
= cu
->header
.length
+ cu
->header
.initial_length_size
;
3766 /* Establish the type offset that can be used to lookup the type. */
3767 sig_type
->type_offset_in_section
.sect_off
=
3768 this_cu
->offset
.sect_off
+ sig_type
->type_offset_in_tu
.cu_off
;
3772 info_ptr
= read_and_check_comp_unit_head (&cu
->header
,
3773 section
, info_ptr
, 0);
3775 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
3776 gdb_assert (this_cu
->length
3777 == cu
->header
.length
+ cu
->header
.initial_length_size
);
3781 /* Skip dummy compilation units. */
3782 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
3783 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3785 do_cleanups (cleanups
);
3789 /* Read the abbrevs for this compilation unit into a table. */
3790 if (cu
->dwarf2_abbrevs
== NULL
)
3792 dwarf2_read_abbrevs (cu
, &dwarf2_per_objfile
->abbrev
);
3793 make_cleanup (dwarf2_free_abbrev_table
, cu
);
3796 /* Read the top level CU/TU die. */
3797 init_cu_die_reader (&reader
, cu
, section
, NULL
);
3798 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
3800 /* If we have a DWO stub, process it and then read in the DWO file.
3801 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains
3802 a DWO CU, that this test will fail. */
3803 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
3806 char *dwo_name
= DW_STRING (attr
);
3807 const char *comp_dir
;
3808 struct dwo_unit
*dwo_unit
;
3809 ULONGEST signature
; /* Or dwo_id. */
3810 struct attribute
*stmt_list
, *low_pc
, *high_pc
, *ranges
;
3811 int i
,num_extra_attrs
;
3814 error (_("Dwarf Error: compilation unit with DW_AT_GNU_dwo_name"
3815 " has children (offset 0x%x) [in module %s]"),
3816 this_cu
->offset
.sect_off
, bfd_get_filename (abfd
));
3818 /* These attributes aren't processed until later:
3819 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
3820 However, the attribute is found in the stub which we won't have later.
3821 In order to not impose this complication on the rest of the code,
3822 we read them here and copy them to the DWO CU/TU die. */
3823 stmt_list
= low_pc
= high_pc
= ranges
= NULL
;
3825 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
3827 if (! this_cu
->is_debug_types
)
3828 stmt_list
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3829 low_pc
= dwarf2_attr (comp_unit_die
, DW_AT_low_pc
, cu
);
3830 high_pc
= dwarf2_attr (comp_unit_die
, DW_AT_high_pc
, cu
);
3831 ranges
= dwarf2_attr (comp_unit_die
, DW_AT_ranges
, cu
);
3833 /* There should be a DW_AT_addr_base attribute here (if needed).
3834 We need the value before we can process DW_FORM_GNU_addr_index. */
3836 cu
->have_addr_base
= 0;
3837 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
3840 cu
->addr_base
= DW_UNSND (attr
);
3841 cu
->have_addr_base
= 1;
3844 if (this_cu
->is_debug_types
)
3846 gdb_assert (sig_type
!= NULL
);
3847 signature
= sig_type
->signature
;
3851 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
3853 error (_("Dwarf Error: missing dwo_id [in module %s]"),
3855 signature
= DW_UNSND (attr
);
3858 /* We may need the comp_dir in order to find the DWO file. */
3860 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
3862 comp_dir
= DW_STRING (attr
);
3864 if (this_cu
->is_debug_types
)
3865 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
3867 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
3870 if (dwo_unit
== NULL
)
3872 error (_("Dwarf Error: CU at offset 0x%x references unknown DWO"
3873 " with ID %s [in module %s]"),
3874 this_cu
->offset
.sect_off
,
3875 phex (signature
, sizeof (signature
)),
3879 /* Set up for reading the DWO CU/TU. */
3880 cu
->dwo_unit
= dwo_unit
;
3881 section
= dwo_unit
->info_or_types_section
;
3882 begin_info_ptr
= info_ptr
= section
->buffer
+ dwo_unit
->offset
.sect_off
;
3883 init_cu_die_reader (&reader
, cu
, section
, dwo_unit
->dwo_file
);
3885 if (this_cu
->is_debug_types
)
3889 info_ptr
= read_and_check_type_unit_head (&cu
->header
,
3892 gdb_assert (sig_type
->signature
== signature
);
3893 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
3894 gdb_assert (dwo_unit
->length
3895 == cu
->header
.length
+ cu
->header
.initial_length_size
);
3897 /* Establish the type offset that can be used to lookup the type.
3898 For DWO files, we don't know it until now. */
3899 sig_type
->type_offset_in_section
.sect_off
=
3900 dwo_unit
->offset
.sect_off
+ dwo_unit
->type_offset_in_tu
.cu_off
;
3904 info_ptr
= read_and_check_comp_unit_head (&cu
->header
,
3905 section
, info_ptr
, 0);
3906 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
3907 gdb_assert (dwo_unit
->length
3908 == cu
->header
.length
+ cu
->header
.initial_length_size
);
3911 /* Discard the original CU's abbrev table, and read the DWO's. */
3912 dwarf2_free_abbrev_table (cu
);
3913 dwarf2_read_abbrevs (cu
, &dwo_unit
->dwo_file
->sections
.abbrev
);
3915 /* Read in the die, but leave space to copy over the attributes
3916 from the stub. This has the benefit of simplifying the rest of
3917 the code - all the real work is done here. */
3918 num_extra_attrs
= ((stmt_list
!= NULL
)
3921 + (ranges
!= NULL
));
3922 info_ptr
= read_full_die_1 (&reader
, &comp_unit_die
, info_ptr
,
3923 &has_children
, num_extra_attrs
);
3925 /* Copy over the attributes from the stub to the DWO die. */
3926 i
= comp_unit_die
->num_attrs
;
3927 if (stmt_list
!= NULL
)
3928 comp_unit_die
->attrs
[i
++] = *stmt_list
;
3930 comp_unit_die
->attrs
[i
++] = *low_pc
;
3931 if (high_pc
!= NULL
)
3932 comp_unit_die
->attrs
[i
++] = *high_pc
;
3934 comp_unit_die
->attrs
[i
++] = *ranges
;
3935 comp_unit_die
->num_attrs
+= num_extra_attrs
;
3937 /* Skip dummy compilation units. */
3938 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
3939 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3941 do_cleanups (cleanups
);
3946 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
3948 if (free_cu_cleanup
!= NULL
)
3952 /* We've successfully allocated this compilation unit. Let our
3953 caller clean it up when finished with it. */
3954 discard_cleanups (free_cu_cleanup
);
3956 /* We can only discard free_cu_cleanup and all subsequent cleanups.
3957 So we have to manually free the abbrev table. */
3958 dwarf2_free_abbrev_table (cu
);
3960 /* Link this CU into read_in_chain. */
3961 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3962 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3965 do_cleanups (free_cu_cleanup
);
3968 do_cleanups (cleanups
);
3971 /* Read CU/TU THIS_CU in section SECTION,
3972 but do not follow DW_AT_GNU_dwo_name if present.
3973 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed to
3974 have already done the lookup to find the DWO file).
3976 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
3977 THIS_CU->is_debug_types, but nothing else.
3979 We fill in THIS_CU->length.
3981 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
3982 linker) then DIE_READER_FUNC will not get called.
3984 THIS_CU->cu is always freed when done.
3985 This is done in order to not leave THIS_CU->cu in a state where we have
3986 to care whether it refers to the "main" CU or the DWO CU. */
3989 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
3990 struct dwarf2_section_info
*abbrev_section
,
3991 struct dwo_file
*dwo_file
,
3992 die_reader_func_ftype
*die_reader_func
,
3995 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3996 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
3997 bfd
*abfd
= section
->asection
->owner
;
3998 struct dwarf2_cu cu
;
3999 gdb_byte
*begin_info_ptr
, *info_ptr
;
4000 struct die_reader_specs reader
;
4001 struct cleanup
*cleanups
;
4002 struct die_info
*comp_unit_die
;
4005 gdb_assert (this_cu
->cu
== NULL
);
4007 /* This is cheap if the section is already read in. */
4008 dwarf2_read_section (objfile
, section
);
4010 init_one_comp_unit (&cu
, this_cu
);
4012 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
4014 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
4015 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
, info_ptr
,
4016 this_cu
->is_debug_types
);
4018 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
4020 /* Skip dummy compilation units. */
4021 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
4022 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4024 do_cleanups (cleanups
);
4028 dwarf2_read_abbrevs (&cu
, abbrev_section
);
4029 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
4031 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
);
4032 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
4034 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4036 do_cleanups (cleanups
);
4039 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
4040 does not lookup the specified DWO file.
4041 This cannot be used to read DWO files.
4043 THIS_CU->cu is always freed when done.
4044 This is done in order to not leave THIS_CU->cu in a state where we have
4045 to care whether it refers to the "main" CU or the DWO CU.
4046 We can revisit this if the data shows there's a performance issue. */
4049 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
4050 die_reader_func_ftype
*die_reader_func
,
4053 init_cutu_and_read_dies_no_follow (this_cu
,
4054 &dwarf2_per_objfile
->abbrev
,
4056 die_reader_func
, data
);
4059 /* die_reader_func for process_psymtab_comp_unit. */
4062 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
4064 struct die_info
*comp_unit_die
,
4068 struct dwarf2_cu
*cu
= reader
->cu
;
4069 struct objfile
*objfile
= cu
->objfile
;
4070 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
4071 struct attribute
*attr
;
4073 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
4074 struct partial_symtab
*pst
;
4076 const char *filename
;
4077 int *want_partial_unit_ptr
= data
;
4079 if (comp_unit_die
->tag
== DW_TAG_partial_unit
4080 && (want_partial_unit_ptr
== NULL
4081 || !*want_partial_unit_ptr
))
4084 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
4086 cu
->list_in_scope
= &file_symbols
;
4088 /* Allocate a new partial symbol table structure. */
4089 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
4090 if (attr
== NULL
|| !DW_STRING (attr
))
4093 filename
= DW_STRING (attr
);
4094 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
4096 /* TEXTLOW and TEXTHIGH are set below. */
4098 objfile
->global_psymbols
.next
,
4099 objfile
->static_psymbols
.next
);
4100 pst
->psymtabs_addrmap_supported
= 1;
4102 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4104 pst
->dirname
= DW_STRING (attr
);
4106 pst
->read_symtab_private
= per_cu
;
4108 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4110 /* Store the function that reads in the rest of the symbol table. */
4111 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
4113 per_cu
->v
.psymtab
= pst
;
4115 dwarf2_find_base_address (comp_unit_die
, cu
);
4117 /* Possibly set the default values of LOWPC and HIGHPC from
4119 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
4120 &best_highpc
, cu
, pst
);
4121 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
4122 /* Store the contiguous range if it is not empty; it can be empty for
4123 CUs with no code. */
4124 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4125 best_lowpc
+ baseaddr
,
4126 best_highpc
+ baseaddr
- 1, pst
);
4128 /* Check if comp unit has_children.
4129 If so, read the rest of the partial symbols from this comp unit.
4130 If not, there's no more debug_info for this comp unit. */
4133 struct partial_die_info
*first_die
;
4134 CORE_ADDR lowpc
, highpc
;
4136 lowpc
= ((CORE_ADDR
) -1);
4137 highpc
= ((CORE_ADDR
) 0);
4139 first_die
= load_partial_dies (reader
, info_ptr
, 1);
4141 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
4144 /* If we didn't find a lowpc, set it to highpc to avoid
4145 complaints from `maint check'. */
4146 if (lowpc
== ((CORE_ADDR
) -1))
4149 /* If the compilation unit didn't have an explicit address range,
4150 then use the information extracted from its child dies. */
4154 best_highpc
= highpc
;
4157 pst
->textlow
= best_lowpc
+ baseaddr
;
4158 pst
->texthigh
= best_highpc
+ baseaddr
;
4160 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
4161 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
4162 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
4163 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
4164 sort_pst_symbols (pst
);
4166 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
))
4169 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
4170 struct dwarf2_per_cu_data
*iter
;
4172 /* Fill in 'dependencies' here; we fill in 'users' in a
4174 pst
->number_of_dependencies
= len
;
4175 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
4176 len
* sizeof (struct symtab
*));
4178 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
4181 pst
->dependencies
[i
] = iter
->v
.psymtab
;
4183 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
4186 if (per_cu
->is_debug_types
)
4188 /* It's not clear we want to do anything with stmt lists here.
4189 Waiting to see what gcc ultimately does. */
4193 /* Get the list of files included in the current compilation unit,
4194 and build a psymtab for each of them. */
4195 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
4199 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
4200 Process compilation unit THIS_CU for a psymtab. */
4203 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
4204 int want_partial_unit
)
4206 /* If this compilation unit was already read in, free the
4207 cached copy in order to read it in again. This is
4208 necessary because we skipped some symbols when we first
4209 read in the compilation unit (see load_partial_dies).
4210 This problem could be avoided, but the benefit is unclear. */
4211 if (this_cu
->cu
!= NULL
)
4212 free_one_cached_comp_unit (this_cu
);
4214 gdb_assert (! this_cu
->is_debug_types
);
4215 init_cutu_and_read_dies (this_cu
, 0, 0, process_psymtab_comp_unit_reader
,
4216 &want_partial_unit
);
4218 /* Age out any secondary CUs. */
4219 age_cached_comp_units ();
4222 /* Traversal function for htab_traverse_noresize.
4223 Process one .debug_types comp-unit. */
4226 process_psymtab_type_unit (void **slot
, void *info
)
4228 struct signatured_type
*sig_type
= (struct signatured_type
*) *slot
;
4229 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
4231 gdb_assert (per_cu
->is_debug_types
);
4232 gdb_assert (info
== NULL
);
4234 /* If this compilation unit was already read in, free the
4235 cached copy in order to read it in again. This is
4236 necessary because we skipped some symbols when we first
4237 read in the compilation unit (see load_partial_dies).
4238 This problem could be avoided, but the benefit is unclear. */
4239 if (per_cu
->cu
!= NULL
)
4240 free_one_cached_comp_unit (per_cu
);
4242 init_cutu_and_read_dies (per_cu
, 0, 0, process_psymtab_comp_unit_reader
,
4245 /* Age out any secondary CUs. */
4246 age_cached_comp_units ();
4251 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
4252 Build partial symbol tables for the .debug_types comp-units. */
4255 build_type_psymtabs (struct objfile
*objfile
)
4257 if (! create_all_type_units (objfile
))
4260 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
4261 process_psymtab_type_unit
, NULL
);
4264 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
4267 psymtabs_addrmap_cleanup (void *o
)
4269 struct objfile
*objfile
= o
;
4271 objfile
->psymtabs_addrmap
= NULL
;
4274 /* Compute the 'user' field for each psymtab in OBJFILE. */
4277 set_partial_user (struct objfile
*objfile
)
4281 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4283 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
4284 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4287 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
4289 /* Set the 'user' field only if it is not already set. */
4290 if (pst
->dependencies
[j
]->user
== NULL
)
4291 pst
->dependencies
[j
]->user
= pst
;
4296 /* Build the partial symbol table by doing a quick pass through the
4297 .debug_info and .debug_abbrev sections. */
4300 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
4302 struct cleanup
*back_to
, *addrmap_cleanup
;
4303 struct obstack temp_obstack
;
4306 dwarf2_per_objfile
->reading_partial_symbols
= 1;
4308 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4310 /* Any cached compilation units will be linked by the per-objfile
4311 read_in_chain. Make sure to free them when we're done. */
4312 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
4314 build_type_psymtabs (objfile
);
4316 create_all_comp_units (objfile
);
4318 /* Create a temporary address map on a temporary obstack. We later
4319 copy this to the final obstack. */
4320 obstack_init (&temp_obstack
);
4321 make_cleanup_obstack_free (&temp_obstack
);
4322 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
4323 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
4325 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4327 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
4329 process_psymtab_comp_unit (per_cu
, 0);
4332 set_partial_user (objfile
);
4334 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
4335 &objfile
->objfile_obstack
);
4336 discard_cleanups (addrmap_cleanup
);
4338 do_cleanups (back_to
);
4341 /* die_reader_func for load_partial_comp_unit. */
4344 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
4346 struct die_info
*comp_unit_die
,
4350 struct dwarf2_cu
*cu
= reader
->cu
;
4352 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
4354 /* Check if comp unit has_children.
4355 If so, read the rest of the partial symbols from this comp unit.
4356 If not, there's no more debug_info for this comp unit. */
4358 load_partial_dies (reader
, info_ptr
, 0);
4361 /* Load the partial DIEs for a secondary CU into memory.
4362 This is also used when rereading a primary CU with load_all_dies. */
4365 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
4367 init_cutu_and_read_dies (this_cu
, 1, 1, load_partial_comp_unit_reader
, NULL
);
4370 /* Create a list of all compilation units in OBJFILE.
4371 This is only done for -readnow and building partial symtabs. */
4374 create_all_comp_units (struct objfile
*objfile
)
4378 struct dwarf2_per_cu_data
**all_comp_units
;
4381 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4382 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
4386 all_comp_units
= xmalloc (n_allocated
4387 * sizeof (struct dwarf2_per_cu_data
*));
4389 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
4390 + dwarf2_per_objfile
->info
.size
)
4392 unsigned int length
, initial_length_size
;
4393 struct dwarf2_per_cu_data
*this_cu
;
4396 offset
.sect_off
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
4398 /* Read just enough information to find out where the next
4399 compilation unit is. */
4400 length
= read_initial_length (objfile
->obfd
, info_ptr
,
4401 &initial_length_size
);
4403 /* Save the compilation unit for later lookup. */
4404 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
4405 sizeof (struct dwarf2_per_cu_data
));
4406 memset (this_cu
, 0, sizeof (*this_cu
));
4407 this_cu
->offset
= offset
;
4408 this_cu
->length
= length
+ initial_length_size
;
4409 this_cu
->objfile
= objfile
;
4410 this_cu
->info_or_types_section
= &dwarf2_per_objfile
->info
;
4412 if (n_comp_units
== n_allocated
)
4415 all_comp_units
= xrealloc (all_comp_units
,
4417 * sizeof (struct dwarf2_per_cu_data
*));
4419 all_comp_units
[n_comp_units
++] = this_cu
;
4421 info_ptr
= info_ptr
+ this_cu
->length
;
4424 dwarf2_per_objfile
->all_comp_units
4425 = obstack_alloc (&objfile
->objfile_obstack
,
4426 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
4427 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
4428 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
4429 xfree (all_comp_units
);
4430 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
4433 /* Process all loaded DIEs for compilation unit CU, starting at
4434 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
4435 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
4436 DW_AT_ranges). If NEED_PC is set, then this function will set
4437 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
4438 and record the covered ranges in the addrmap. */
4441 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
4442 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4444 struct partial_die_info
*pdi
;
4446 /* Now, march along the PDI's, descending into ones which have
4447 interesting children but skipping the children of the other ones,
4448 until we reach the end of the compilation unit. */
4454 fixup_partial_die (pdi
, cu
);
4456 /* Anonymous namespaces or modules have no name but have interesting
4457 children, so we need to look at them. Ditto for anonymous
4460 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
4461 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
4462 || pdi
->tag
== DW_TAG_imported_unit
)
4466 case DW_TAG_subprogram
:
4467 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4469 case DW_TAG_constant
:
4470 case DW_TAG_variable
:
4471 case DW_TAG_typedef
:
4472 case DW_TAG_union_type
:
4473 if (!pdi
->is_declaration
)
4475 add_partial_symbol (pdi
, cu
);
4478 case DW_TAG_class_type
:
4479 case DW_TAG_interface_type
:
4480 case DW_TAG_structure_type
:
4481 if (!pdi
->is_declaration
)
4483 add_partial_symbol (pdi
, cu
);
4486 case DW_TAG_enumeration_type
:
4487 if (!pdi
->is_declaration
)
4488 add_partial_enumeration (pdi
, cu
);
4490 case DW_TAG_base_type
:
4491 case DW_TAG_subrange_type
:
4492 /* File scope base type definitions are added to the partial
4494 add_partial_symbol (pdi
, cu
);
4496 case DW_TAG_namespace
:
4497 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
4500 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
4502 case DW_TAG_imported_unit
:
4504 struct dwarf2_per_cu_data
*per_cu
;
4506 per_cu
= dwarf2_find_containing_comp_unit (pdi
->d
.offset
,
4509 /* Go read the partial unit, if needed. */
4510 if (per_cu
->v
.psymtab
== NULL
)
4511 process_psymtab_comp_unit (per_cu
, 1);
4513 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
4522 /* If the die has a sibling, skip to the sibling. */
4524 pdi
= pdi
->die_sibling
;
4528 /* Functions used to compute the fully scoped name of a partial DIE.
4530 Normally, this is simple. For C++, the parent DIE's fully scoped
4531 name is concatenated with "::" and the partial DIE's name. For
4532 Java, the same thing occurs except that "." is used instead of "::".
4533 Enumerators are an exception; they use the scope of their parent
4534 enumeration type, i.e. the name of the enumeration type is not
4535 prepended to the enumerator.
4537 There are two complexities. One is DW_AT_specification; in this
4538 case "parent" means the parent of the target of the specification,
4539 instead of the direct parent of the DIE. The other is compilers
4540 which do not emit DW_TAG_namespace; in this case we try to guess
4541 the fully qualified name of structure types from their members'
4542 linkage names. This must be done using the DIE's children rather
4543 than the children of any DW_AT_specification target. We only need
4544 to do this for structures at the top level, i.e. if the target of
4545 any DW_AT_specification (if any; otherwise the DIE itself) does not
4548 /* Compute the scope prefix associated with PDI's parent, in
4549 compilation unit CU. The result will be allocated on CU's
4550 comp_unit_obstack, or a copy of the already allocated PDI->NAME
4551 field. NULL is returned if no prefix is necessary. */
4553 partial_die_parent_scope (struct partial_die_info
*pdi
,
4554 struct dwarf2_cu
*cu
)
4556 char *grandparent_scope
;
4557 struct partial_die_info
*parent
, *real_pdi
;
4559 /* We need to look at our parent DIE; if we have a DW_AT_specification,
4560 then this means the parent of the specification DIE. */
4563 while (real_pdi
->has_specification
)
4564 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
4566 parent
= real_pdi
->die_parent
;
4570 if (parent
->scope_set
)
4571 return parent
->scope
;
4573 fixup_partial_die (parent
, cu
);
4575 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
4577 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
4578 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
4579 Work around this problem here. */
4580 if (cu
->language
== language_cplus
4581 && parent
->tag
== DW_TAG_namespace
4582 && strcmp (parent
->name
, "::") == 0
4583 && grandparent_scope
== NULL
)
4585 parent
->scope
= NULL
;
4586 parent
->scope_set
= 1;
4590 if (pdi
->tag
== DW_TAG_enumerator
)
4591 /* Enumerators should not get the name of the enumeration as a prefix. */
4592 parent
->scope
= grandparent_scope
;
4593 else if (parent
->tag
== DW_TAG_namespace
4594 || parent
->tag
== DW_TAG_module
4595 || parent
->tag
== DW_TAG_structure_type
4596 || parent
->tag
== DW_TAG_class_type
4597 || parent
->tag
== DW_TAG_interface_type
4598 || parent
->tag
== DW_TAG_union_type
4599 || parent
->tag
== DW_TAG_enumeration_type
)
4601 if (grandparent_scope
== NULL
)
4602 parent
->scope
= parent
->name
;
4604 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
4606 parent
->name
, 0, cu
);
4610 /* FIXME drow/2004-04-01: What should we be doing with
4611 function-local names? For partial symbols, we should probably be
4613 complaint (&symfile_complaints
,
4614 _("unhandled containing DIE tag %d for DIE at %d"),
4615 parent
->tag
, pdi
->offset
.sect_off
);
4616 parent
->scope
= grandparent_scope
;
4619 parent
->scope_set
= 1;
4620 return parent
->scope
;
4623 /* Return the fully scoped name associated with PDI, from compilation unit
4624 CU. The result will be allocated with malloc. */
4627 partial_die_full_name (struct partial_die_info
*pdi
,
4628 struct dwarf2_cu
*cu
)
4632 /* If this is a template instantiation, we can not work out the
4633 template arguments from partial DIEs. So, unfortunately, we have
4634 to go through the full DIEs. At least any work we do building
4635 types here will be reused if full symbols are loaded later. */
4636 if (pdi
->has_template_arguments
)
4638 fixup_partial_die (pdi
, cu
);
4640 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
4642 struct die_info
*die
;
4643 struct attribute attr
;
4644 struct dwarf2_cu
*ref_cu
= cu
;
4646 /* DW_FORM_ref_addr is using section offset. */
4648 attr
.form
= DW_FORM_ref_addr
;
4649 attr
.u
.unsnd
= pdi
->offset
.sect_off
;
4650 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
4652 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
4656 parent_scope
= partial_die_parent_scope (pdi
, cu
);
4657 if (parent_scope
== NULL
)
4660 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
4664 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
4666 struct objfile
*objfile
= cu
->objfile
;
4668 char *actual_name
= NULL
;
4670 int built_actual_name
= 0;
4672 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4674 actual_name
= partial_die_full_name (pdi
, cu
);
4676 built_actual_name
= 1;
4678 if (actual_name
== NULL
)
4679 actual_name
= pdi
->name
;
4683 case DW_TAG_subprogram
:
4684 if (pdi
->is_external
|| cu
->language
== language_ada
)
4686 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
4687 of the global scope. But in Ada, we want to be able to access
4688 nested procedures globally. So all Ada subprograms are stored
4689 in the global scope. */
4690 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4691 mst_text, objfile); */
4692 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4694 VAR_DOMAIN
, LOC_BLOCK
,
4695 &objfile
->global_psymbols
,
4696 0, pdi
->lowpc
+ baseaddr
,
4697 cu
->language
, objfile
);
4701 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4702 mst_file_text, objfile); */
4703 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4705 VAR_DOMAIN
, LOC_BLOCK
,
4706 &objfile
->static_psymbols
,
4707 0, pdi
->lowpc
+ baseaddr
,
4708 cu
->language
, objfile
);
4711 case DW_TAG_constant
:
4713 struct psymbol_allocation_list
*list
;
4715 if (pdi
->is_external
)
4716 list
= &objfile
->global_psymbols
;
4718 list
= &objfile
->static_psymbols
;
4719 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4720 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
4721 list
, 0, 0, cu
->language
, objfile
);
4724 case DW_TAG_variable
:
4726 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
4730 && !dwarf2_per_objfile
->has_section_at_zero
)
4732 /* A global or static variable may also have been stripped
4733 out by the linker if unused, in which case its address
4734 will be nullified; do not add such variables into partial
4735 symbol table then. */
4737 else if (pdi
->is_external
)
4740 Don't enter into the minimal symbol tables as there is
4741 a minimal symbol table entry from the ELF symbols already.
4742 Enter into partial symbol table if it has a location
4743 descriptor or a type.
4744 If the location descriptor is missing, new_symbol will create
4745 a LOC_UNRESOLVED symbol, the address of the variable will then
4746 be determined from the minimal symbol table whenever the variable
4748 The address for the partial symbol table entry is not
4749 used by GDB, but it comes in handy for debugging partial symbol
4752 if (pdi
->d
.locdesc
|| pdi
->has_type
)
4753 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4755 VAR_DOMAIN
, LOC_STATIC
,
4756 &objfile
->global_psymbols
,
4758 cu
->language
, objfile
);
4762 /* Static Variable. Skip symbols without location descriptors. */
4763 if (pdi
->d
.locdesc
== NULL
)
4765 if (built_actual_name
)
4766 xfree (actual_name
);
4769 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
4770 mst_file_data, objfile); */
4771 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4773 VAR_DOMAIN
, LOC_STATIC
,
4774 &objfile
->static_psymbols
,
4776 cu
->language
, objfile
);
4779 case DW_TAG_typedef
:
4780 case DW_TAG_base_type
:
4781 case DW_TAG_subrange_type
:
4782 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4784 VAR_DOMAIN
, LOC_TYPEDEF
,
4785 &objfile
->static_psymbols
,
4786 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4788 case DW_TAG_namespace
:
4789 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4791 VAR_DOMAIN
, LOC_TYPEDEF
,
4792 &objfile
->global_psymbols
,
4793 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4795 case DW_TAG_class_type
:
4796 case DW_TAG_interface_type
:
4797 case DW_TAG_structure_type
:
4798 case DW_TAG_union_type
:
4799 case DW_TAG_enumeration_type
:
4800 /* Skip external references. The DWARF standard says in the section
4801 about "Structure, Union, and Class Type Entries": "An incomplete
4802 structure, union or class type is represented by a structure,
4803 union or class entry that does not have a byte size attribute
4804 and that has a DW_AT_declaration attribute." */
4805 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
4807 if (built_actual_name
)
4808 xfree (actual_name
);
4812 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
4813 static vs. global. */
4814 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4816 STRUCT_DOMAIN
, LOC_TYPEDEF
,
4817 (cu
->language
== language_cplus
4818 || cu
->language
== language_java
)
4819 ? &objfile
->global_psymbols
4820 : &objfile
->static_psymbols
,
4821 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4824 case DW_TAG_enumerator
:
4825 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4827 VAR_DOMAIN
, LOC_CONST
,
4828 (cu
->language
== language_cplus
4829 || cu
->language
== language_java
)
4830 ? &objfile
->global_psymbols
4831 : &objfile
->static_psymbols
,
4832 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4838 if (built_actual_name
)
4839 xfree (actual_name
);
4842 /* Read a partial die corresponding to a namespace; also, add a symbol
4843 corresponding to that namespace to the symbol table. NAMESPACE is
4844 the name of the enclosing namespace. */
4847 add_partial_namespace (struct partial_die_info
*pdi
,
4848 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4849 int need_pc
, struct dwarf2_cu
*cu
)
4851 /* Add a symbol for the namespace. */
4853 add_partial_symbol (pdi
, cu
);
4855 /* Now scan partial symbols in that namespace. */
4857 if (pdi
->has_children
)
4858 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4861 /* Read a partial die corresponding to a Fortran module. */
4864 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
4865 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4867 /* Now scan partial symbols in that module. */
4869 if (pdi
->has_children
)
4870 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4873 /* Read a partial die corresponding to a subprogram and create a partial
4874 symbol for that subprogram. When the CU language allows it, this
4875 routine also defines a partial symbol for each nested subprogram
4876 that this subprogram contains.
4878 DIE my also be a lexical block, in which case we simply search
4879 recursively for suprograms defined inside that lexical block.
4880 Again, this is only performed when the CU language allows this
4881 type of definitions. */
4884 add_partial_subprogram (struct partial_die_info
*pdi
,
4885 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4886 int need_pc
, struct dwarf2_cu
*cu
)
4888 if (pdi
->tag
== DW_TAG_subprogram
)
4890 if (pdi
->has_pc_info
)
4892 if (pdi
->lowpc
< *lowpc
)
4893 *lowpc
= pdi
->lowpc
;
4894 if (pdi
->highpc
> *highpc
)
4895 *highpc
= pdi
->highpc
;
4899 struct objfile
*objfile
= cu
->objfile
;
4901 baseaddr
= ANOFFSET (objfile
->section_offsets
,
4902 SECT_OFF_TEXT (objfile
));
4903 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4904 pdi
->lowpc
+ baseaddr
,
4905 pdi
->highpc
- 1 + baseaddr
,
4906 cu
->per_cu
->v
.psymtab
);
4910 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
4912 if (!pdi
->is_declaration
)
4913 /* Ignore subprogram DIEs that do not have a name, they are
4914 illegal. Do not emit a complaint at this point, we will
4915 do so when we convert this psymtab into a symtab. */
4917 add_partial_symbol (pdi
, cu
);
4921 if (! pdi
->has_children
)
4924 if (cu
->language
== language_ada
)
4926 pdi
= pdi
->die_child
;
4929 fixup_partial_die (pdi
, cu
);
4930 if (pdi
->tag
== DW_TAG_subprogram
4931 || pdi
->tag
== DW_TAG_lexical_block
)
4932 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4933 pdi
= pdi
->die_sibling
;
4938 /* Read a partial die corresponding to an enumeration type. */
4941 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
4942 struct dwarf2_cu
*cu
)
4944 struct partial_die_info
*pdi
;
4946 if (enum_pdi
->name
!= NULL
)
4947 add_partial_symbol (enum_pdi
, cu
);
4949 pdi
= enum_pdi
->die_child
;
4952 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
4953 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
4955 add_partial_symbol (pdi
, cu
);
4956 pdi
= pdi
->die_sibling
;
4960 /* Return the initial uleb128 in the die at INFO_PTR. */
4963 peek_abbrev_code (bfd
*abfd
, gdb_byte
*info_ptr
)
4965 unsigned int bytes_read
;
4967 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4970 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4971 Return the corresponding abbrev, or NULL if the number is zero (indicating
4972 an empty DIE). In either case *BYTES_READ will be set to the length of
4973 the initial number. */
4975 static struct abbrev_info
*
4976 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
4977 struct dwarf2_cu
*cu
)
4979 bfd
*abfd
= cu
->objfile
->obfd
;
4980 unsigned int abbrev_number
;
4981 struct abbrev_info
*abbrev
;
4983 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
4985 if (abbrev_number
== 0)
4988 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4991 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4992 abbrev_number
, bfd_get_filename (abfd
));
4998 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4999 Returns a pointer to the end of a series of DIEs, terminated by an empty
5000 DIE. Any children of the skipped DIEs will also be skipped. */
5003 skip_children (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
)
5005 struct dwarf2_cu
*cu
= reader
->cu
;
5006 struct abbrev_info
*abbrev
;
5007 unsigned int bytes_read
;
5011 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
5013 return info_ptr
+ bytes_read
;
5015 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
5019 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
5020 INFO_PTR should point just after the initial uleb128 of a DIE, and the
5021 abbrev corresponding to that skipped uleb128 should be passed in
5022 ABBREV. Returns a pointer to this DIE's sibling, skipping any
5026 skip_one_die (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
,
5027 struct abbrev_info
*abbrev
)
5029 unsigned int bytes_read
;
5030 struct attribute attr
;
5031 bfd
*abfd
= reader
->abfd
;
5032 struct dwarf2_cu
*cu
= reader
->cu
;
5033 gdb_byte
*buffer
= reader
->buffer
;
5034 unsigned int form
, i
;
5036 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
5038 /* The only abbrev we care about is DW_AT_sibling. */
5039 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
5041 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
5042 if (attr
.form
== DW_FORM_ref_addr
)
5043 complaint (&symfile_complaints
,
5044 _("ignoring absolute DW_AT_sibling"));
5046 return buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
5049 /* If it isn't DW_AT_sibling, skip this attribute. */
5050 form
= abbrev
->attrs
[i
].form
;
5054 case DW_FORM_ref_addr
:
5055 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
5056 and later it is offset sized. */
5057 if (cu
->header
.version
== 2)
5058 info_ptr
+= cu
->header
.addr_size
;
5060 info_ptr
+= cu
->header
.offset_size
;
5063 info_ptr
+= cu
->header
.addr_size
;
5070 case DW_FORM_flag_present
:
5082 case DW_FORM_ref_sig8
:
5085 case DW_FORM_string
:
5086 read_direct_string (abfd
, info_ptr
, &bytes_read
);
5087 info_ptr
+= bytes_read
;
5089 case DW_FORM_sec_offset
:
5091 info_ptr
+= cu
->header
.offset_size
;
5093 case DW_FORM_exprloc
:
5095 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5096 info_ptr
+= bytes_read
;
5098 case DW_FORM_block1
:
5099 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
5101 case DW_FORM_block2
:
5102 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
5104 case DW_FORM_block4
:
5105 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
5109 case DW_FORM_ref_udata
:
5110 case DW_FORM_GNU_addr_index
:
5111 case DW_FORM_GNU_str_index
:
5112 info_ptr
= skip_leb128 (abfd
, info_ptr
);
5114 case DW_FORM_indirect
:
5115 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5116 info_ptr
+= bytes_read
;
5117 /* We need to continue parsing from here, so just go back to
5119 goto skip_attribute
;
5122 error (_("Dwarf Error: Cannot handle %s "
5123 "in DWARF reader [in module %s]"),
5124 dwarf_form_name (form
),
5125 bfd_get_filename (abfd
));
5129 if (abbrev
->has_children
)
5130 return skip_children (reader
, info_ptr
);
5135 /* Locate ORIG_PDI's sibling.
5136 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
5139 locate_pdi_sibling (const struct die_reader_specs
*reader
,
5140 struct partial_die_info
*orig_pdi
,
5143 /* Do we know the sibling already? */
5145 if (orig_pdi
->sibling
)
5146 return orig_pdi
->sibling
;
5148 /* Are there any children to deal with? */
5150 if (!orig_pdi
->has_children
)
5153 /* Skip the children the long way. */
5155 return skip_children (reader
, info_ptr
);
5158 /* Expand this partial symbol table into a full symbol table. */
5161 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
5167 warning (_("bug: psymtab for %s is already read in."),
5174 printf_filtered (_("Reading in symbols for %s..."),
5176 gdb_flush (gdb_stdout
);
5179 /* Restore our global data. */
5180 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
5181 dwarf2_objfile_data_key
);
5183 /* If this psymtab is constructed from a debug-only objfile, the
5184 has_section_at_zero flag will not necessarily be correct. We
5185 can get the correct value for this flag by looking at the data
5186 associated with the (presumably stripped) associated objfile. */
5187 if (pst
->objfile
->separate_debug_objfile_backlink
)
5189 struct dwarf2_per_objfile
*dpo_backlink
5190 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
5191 dwarf2_objfile_data_key
);
5193 dwarf2_per_objfile
->has_section_at_zero
5194 = dpo_backlink
->has_section_at_zero
;
5197 dwarf2_per_objfile
->reading_partial_symbols
= 0;
5199 psymtab_to_symtab_1 (pst
);
5201 /* Finish up the debug error message. */
5203 printf_filtered (_("done.\n"));
5207 process_cu_includes ();
5210 /* Reading in full CUs. */
5212 /* Add PER_CU to the queue. */
5215 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
5216 enum language pretend_language
)
5218 struct dwarf2_queue_item
*item
;
5221 item
= xmalloc (sizeof (*item
));
5222 item
->per_cu
= per_cu
;
5223 item
->pretend_language
= pretend_language
;
5226 if (dwarf2_queue
== NULL
)
5227 dwarf2_queue
= item
;
5229 dwarf2_queue_tail
->next
= item
;
5231 dwarf2_queue_tail
= item
;
5234 /* Process the queue. */
5237 process_queue (void)
5239 struct dwarf2_queue_item
*item
, *next_item
;
5241 /* The queue starts out with one item, but following a DIE reference
5242 may load a new CU, adding it to the end of the queue. */
5243 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
5245 if (dwarf2_per_objfile
->using_index
5246 ? !item
->per_cu
->v
.quick
->symtab
5247 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
5248 process_full_comp_unit (item
->per_cu
, item
->pretend_language
);
5250 item
->per_cu
->queued
= 0;
5251 next_item
= item
->next
;
5255 dwarf2_queue_tail
= NULL
;
5258 /* Free all allocated queue entries. This function only releases anything if
5259 an error was thrown; if the queue was processed then it would have been
5260 freed as we went along. */
5263 dwarf2_release_queue (void *dummy
)
5265 struct dwarf2_queue_item
*item
, *last
;
5267 item
= dwarf2_queue
;
5270 /* Anything still marked queued is likely to be in an
5271 inconsistent state, so discard it. */
5272 if (item
->per_cu
->queued
)
5274 if (item
->per_cu
->cu
!= NULL
)
5275 free_one_cached_comp_unit (item
->per_cu
);
5276 item
->per_cu
->queued
= 0;
5284 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
5287 /* Read in full symbols for PST, and anything it depends on. */
5290 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
5292 struct dwarf2_per_cu_data
*per_cu
;
5298 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
5299 if (!pst
->dependencies
[i
]->readin
5300 && pst
->dependencies
[i
]->user
== NULL
)
5302 /* Inform about additional files that need to be read in. */
5305 /* FIXME: i18n: Need to make this a single string. */
5306 fputs_filtered (" ", gdb_stdout
);
5308 fputs_filtered ("and ", gdb_stdout
);
5310 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
5311 wrap_here (""); /* Flush output. */
5312 gdb_flush (gdb_stdout
);
5314 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
5317 per_cu
= pst
->read_symtab_private
;
5321 /* It's an include file, no symbols to read for it.
5322 Everything is in the parent symtab. */
5327 dw2_do_instantiate_symtab (per_cu
);
5330 /* Trivial hash function for die_info: the hash value of a DIE
5331 is its offset in .debug_info for this objfile. */
5334 die_hash (const void *item
)
5336 const struct die_info
*die
= item
;
5338 return die
->offset
.sect_off
;
5341 /* Trivial comparison function for die_info structures: two DIEs
5342 are equal if they have the same offset. */
5345 die_eq (const void *item_lhs
, const void *item_rhs
)
5347 const struct die_info
*die_lhs
= item_lhs
;
5348 const struct die_info
*die_rhs
= item_rhs
;
5350 return die_lhs
->offset
.sect_off
== die_rhs
->offset
.sect_off
;
5353 /* die_reader_func for load_full_comp_unit.
5354 This is identical to read_signatured_type_reader,
5355 but is kept separate for now. */
5358 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
5360 struct die_info
*comp_unit_die
,
5364 struct dwarf2_cu
*cu
= reader
->cu
;
5365 enum language
*language_ptr
= data
;
5367 gdb_assert (cu
->die_hash
== NULL
);
5369 htab_create_alloc_ex (cu
->header
.length
/ 12,
5373 &cu
->comp_unit_obstack
,
5374 hashtab_obstack_allocate
,
5375 dummy_obstack_deallocate
);
5378 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
5379 &info_ptr
, comp_unit_die
);
5380 cu
->dies
= comp_unit_die
;
5381 /* comp_unit_die is not stored in die_hash, no need. */
5383 /* We try not to read any attributes in this function, because not
5384 all CUs needed for references have been loaded yet, and symbol
5385 table processing isn't initialized. But we have to set the CU language,
5386 or we won't be able to build types correctly.
5387 Similarly, if we do not read the producer, we can not apply
5388 producer-specific interpretation. */
5389 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
5392 /* Load the DIEs associated with PER_CU into memory. */
5395 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
5396 enum language pretend_language
)
5398 gdb_assert (! this_cu
->is_debug_types
);
5400 init_cutu_and_read_dies (this_cu
, 1, 1, load_full_comp_unit_reader
,
5404 /* Add a DIE to the delayed physname list. */
5407 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
5408 const char *name
, struct die_info
*die
,
5409 struct dwarf2_cu
*cu
)
5411 struct delayed_method_info mi
;
5413 mi
.fnfield_index
= fnfield_index
;
5417 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
5420 /* A cleanup for freeing the delayed method list. */
5423 free_delayed_list (void *ptr
)
5425 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
5426 if (cu
->method_list
!= NULL
)
5428 VEC_free (delayed_method_info
, cu
->method_list
);
5429 cu
->method_list
= NULL
;
5433 /* Compute the physnames of any methods on the CU's method list.
5435 The computation of method physnames is delayed in order to avoid the
5436 (bad) condition that one of the method's formal parameters is of an as yet
5440 compute_delayed_physnames (struct dwarf2_cu
*cu
)
5443 struct delayed_method_info
*mi
;
5444 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
5446 const char *physname
;
5447 struct fn_fieldlist
*fn_flp
5448 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
5449 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
5450 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
5454 /* Go objects should be embedded in a DW_TAG_module DIE,
5455 and it's not clear if/how imported objects will appear.
5456 To keep Go support simple until that's worked out,
5457 go back through what we've read and create something usable.
5458 We could do this while processing each DIE, and feels kinda cleaner,
5459 but that way is more invasive.
5460 This is to, for example, allow the user to type "p var" or "b main"
5461 without having to specify the package name, and allow lookups
5462 of module.object to work in contexts that use the expression
5466 fixup_go_packaging (struct dwarf2_cu
*cu
)
5468 char *package_name
= NULL
;
5469 struct pending
*list
;
5472 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
5474 for (i
= 0; i
< list
->nsyms
; ++i
)
5476 struct symbol
*sym
= list
->symbol
[i
];
5478 if (SYMBOL_LANGUAGE (sym
) == language_go
5479 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
5481 char *this_package_name
= go_symbol_package_name (sym
);
5483 if (this_package_name
== NULL
)
5485 if (package_name
== NULL
)
5486 package_name
= this_package_name
;
5489 if (strcmp (package_name
, this_package_name
) != 0)
5490 complaint (&symfile_complaints
,
5491 _("Symtab %s has objects from two different Go packages: %s and %s"),
5492 (sym
->symtab
&& sym
->symtab
->filename
5493 ? sym
->symtab
->filename
5494 : cu
->objfile
->name
),
5495 this_package_name
, package_name
);
5496 xfree (this_package_name
);
5502 if (package_name
!= NULL
)
5504 struct objfile
*objfile
= cu
->objfile
;
5505 struct type
*type
= init_type (TYPE_CODE_MODULE
, 0, 0,
5506 package_name
, objfile
);
5509 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
5511 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
5512 SYMBOL_SET_LANGUAGE (sym
, language_go
);
5513 SYMBOL_SET_NAMES (sym
, package_name
, strlen (package_name
), 1, objfile
);
5514 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
5515 e.g., "main" finds the "main" module and not C's main(). */
5516 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
5517 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5518 SYMBOL_TYPE (sym
) = type
;
5520 add_symbol_to_list (sym
, &global_symbols
);
5522 xfree (package_name
);
5526 static void compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
);
5528 /* Return the symtab for PER_CU. This works properly regardless of
5529 whether we're using the index or psymtabs. */
5531 static struct symtab
*
5532 get_symtab (struct dwarf2_per_cu_data
*per_cu
)
5534 return (dwarf2_per_objfile
->using_index
5535 ? per_cu
->v
.quick
->symtab
5536 : per_cu
->v
.psymtab
->symtab
);
5539 /* A helper function for computing the list of all symbol tables
5540 included by PER_CU. */
5543 recursively_compute_inclusions (VEC (dwarf2_per_cu_ptr
) **result
,
5544 htab_t all_children
,
5545 struct dwarf2_per_cu_data
*per_cu
)
5549 struct dwarf2_per_cu_data
*iter
;
5551 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
5554 /* This inclusion and its children have been processed. */
5559 /* Only add a CU if it has a symbol table. */
5560 if (get_symtab (per_cu
) != NULL
)
5561 VEC_safe_push (dwarf2_per_cu_ptr
, *result
, per_cu
);
5564 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, ix
, iter
);
5566 recursively_compute_inclusions (result
, all_children
, iter
);
5569 /* Compute the symtab 'includes' fields for the symtab related to
5573 compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
5575 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
))
5578 struct dwarf2_per_cu_data
*iter
;
5579 VEC (dwarf2_per_cu_ptr
) *result_children
= NULL
;
5580 htab_t all_children
;
5581 struct symtab
*symtab
= get_symtab (per_cu
);
5583 /* If we don't have a symtab, we can just skip this case. */
5587 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
5588 NULL
, xcalloc
, xfree
);
5591 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
,
5594 recursively_compute_inclusions (&result_children
, all_children
, iter
);
5596 /* Now we have a transitive closure of all the included CUs, so
5597 we can convert it to a list of symtabs. */
5598 len
= VEC_length (dwarf2_per_cu_ptr
, result_children
);
5600 = obstack_alloc (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
5601 (len
+ 1) * sizeof (struct symtab
*));
5603 VEC_iterate (dwarf2_per_cu_ptr
, result_children
, ix
, iter
);
5605 symtab
->includes
[ix
] = get_symtab (iter
);
5606 symtab
->includes
[len
] = NULL
;
5608 VEC_free (dwarf2_per_cu_ptr
, result_children
);
5609 htab_delete (all_children
);
5613 /* Compute the 'includes' field for the symtabs of all the CUs we just
5617 process_cu_includes (void)
5620 struct dwarf2_per_cu_data
*iter
;
5623 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
5626 compute_symtab_includes (iter
);
5628 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
5631 /* Generate full symbol information for PER_CU, whose DIEs have
5632 already been loaded into memory. */
5635 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
5636 enum language pretend_language
)
5638 struct dwarf2_cu
*cu
= per_cu
->cu
;
5639 struct objfile
*objfile
= per_cu
->objfile
;
5640 CORE_ADDR lowpc
, highpc
;
5641 struct symtab
*symtab
;
5642 struct cleanup
*back_to
, *delayed_list_cleanup
;
5645 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5648 back_to
= make_cleanup (really_free_pendings
, NULL
);
5649 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
5651 cu
->list_in_scope
= &file_symbols
;
5653 cu
->language
= pretend_language
;
5654 cu
->language_defn
= language_def (cu
->language
);
5656 /* Do line number decoding in read_file_scope () */
5657 process_die (cu
->dies
, cu
);
5659 /* For now fudge the Go package. */
5660 if (cu
->language
== language_go
)
5661 fixup_go_packaging (cu
);
5663 /* Now that we have processed all the DIEs in the CU, all the types
5664 should be complete, and it should now be safe to compute all of the
5666 compute_delayed_physnames (cu
);
5667 do_cleanups (delayed_list_cleanup
);
5669 /* Some compilers don't define a DW_AT_high_pc attribute for the
5670 compilation unit. If the DW_AT_high_pc is missing, synthesize
5671 it, by scanning the DIE's below the compilation unit. */
5672 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
5674 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
5678 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
5680 /* Set symtab language to language from DW_AT_language. If the
5681 compilation is from a C file generated by language preprocessors, do
5682 not set the language if it was already deduced by start_subfile. */
5683 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
5684 symtab
->language
= cu
->language
;
5686 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
5687 produce DW_AT_location with location lists but it can be possibly
5688 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
5689 there were bugs in prologue debug info, fixed later in GCC-4.5
5690 by "unwind info for epilogues" patch (which is not directly related).
5692 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
5693 needed, it would be wrong due to missing DW_AT_producer there.
5695 Still one can confuse GDB by using non-standard GCC compilation
5696 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
5698 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
5699 symtab
->locations_valid
= 1;
5701 if (gcc_4_minor
>= 5)
5702 symtab
->epilogue_unwind_valid
= 1;
5704 symtab
->call_site_htab
= cu
->call_site_htab
;
5707 if (dwarf2_per_objfile
->using_index
)
5708 per_cu
->v
.quick
->symtab
= symtab
;
5711 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
5712 pst
->symtab
= symtab
;
5716 /* Push it for inclusion processing later. */
5717 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
5719 do_cleanups (back_to
);
5722 /* Process an imported unit DIE. */
5725 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
5727 struct attribute
*attr
;
5729 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
5732 struct dwarf2_per_cu_data
*per_cu
;
5733 struct symtab
*imported_symtab
;
5736 offset
= dwarf2_get_ref_die_offset (attr
);
5737 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
5739 /* Queue the unit, if needed. */
5740 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
5741 load_full_comp_unit (per_cu
, cu
->language
);
5743 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
5748 /* Process a die and its children. */
5751 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
5755 case DW_TAG_padding
:
5757 case DW_TAG_compile_unit
:
5758 case DW_TAG_partial_unit
:
5759 read_file_scope (die
, cu
);
5761 case DW_TAG_type_unit
:
5762 read_type_unit_scope (die
, cu
);
5764 case DW_TAG_subprogram
:
5765 case DW_TAG_inlined_subroutine
:
5766 read_func_scope (die
, cu
);
5768 case DW_TAG_lexical_block
:
5769 case DW_TAG_try_block
:
5770 case DW_TAG_catch_block
:
5771 read_lexical_block_scope (die
, cu
);
5773 case DW_TAG_GNU_call_site
:
5774 read_call_site_scope (die
, cu
);
5776 case DW_TAG_class_type
:
5777 case DW_TAG_interface_type
:
5778 case DW_TAG_structure_type
:
5779 case DW_TAG_union_type
:
5780 process_structure_scope (die
, cu
);
5782 case DW_TAG_enumeration_type
:
5783 process_enumeration_scope (die
, cu
);
5786 /* These dies have a type, but processing them does not create
5787 a symbol or recurse to process the children. Therefore we can
5788 read them on-demand through read_type_die. */
5789 case DW_TAG_subroutine_type
:
5790 case DW_TAG_set_type
:
5791 case DW_TAG_array_type
:
5792 case DW_TAG_pointer_type
:
5793 case DW_TAG_ptr_to_member_type
:
5794 case DW_TAG_reference_type
:
5795 case DW_TAG_string_type
:
5798 case DW_TAG_base_type
:
5799 case DW_TAG_subrange_type
:
5800 case DW_TAG_typedef
:
5801 /* Add a typedef symbol for the type definition, if it has a
5803 new_symbol (die
, read_type_die (die
, cu
), cu
);
5805 case DW_TAG_common_block
:
5806 read_common_block (die
, cu
);
5808 case DW_TAG_common_inclusion
:
5810 case DW_TAG_namespace
:
5811 processing_has_namespace_info
= 1;
5812 read_namespace (die
, cu
);
5815 processing_has_namespace_info
= 1;
5816 read_module (die
, cu
);
5818 case DW_TAG_imported_declaration
:
5819 case DW_TAG_imported_module
:
5820 processing_has_namespace_info
= 1;
5821 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
5822 || cu
->language
!= language_fortran
))
5823 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
5824 dwarf_tag_name (die
->tag
));
5825 read_import_statement (die
, cu
);
5828 case DW_TAG_imported_unit
:
5829 process_imported_unit_die (die
, cu
);
5833 new_symbol (die
, NULL
, cu
);
5838 /* A helper function for dwarf2_compute_name which determines whether DIE
5839 needs to have the name of the scope prepended to the name listed in the
5843 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
5845 struct attribute
*attr
;
5849 case DW_TAG_namespace
:
5850 case DW_TAG_typedef
:
5851 case DW_TAG_class_type
:
5852 case DW_TAG_interface_type
:
5853 case DW_TAG_structure_type
:
5854 case DW_TAG_union_type
:
5855 case DW_TAG_enumeration_type
:
5856 case DW_TAG_enumerator
:
5857 case DW_TAG_subprogram
:
5861 case DW_TAG_variable
:
5862 case DW_TAG_constant
:
5863 /* We only need to prefix "globally" visible variables. These include
5864 any variable marked with DW_AT_external or any variable that
5865 lives in a namespace. [Variables in anonymous namespaces
5866 require prefixing, but they are not DW_AT_external.] */
5868 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
5870 struct dwarf2_cu
*spec_cu
= cu
;
5872 return die_needs_namespace (die_specification (die
, &spec_cu
),
5876 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5877 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
5878 && die
->parent
->tag
!= DW_TAG_module
)
5880 /* A variable in a lexical block of some kind does not need a
5881 namespace, even though in C++ such variables may be external
5882 and have a mangled name. */
5883 if (die
->parent
->tag
== DW_TAG_lexical_block
5884 || die
->parent
->tag
== DW_TAG_try_block
5885 || die
->parent
->tag
== DW_TAG_catch_block
5886 || die
->parent
->tag
== DW_TAG_subprogram
)
5895 /* Retrieve the last character from a mem_file. */
5898 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
5900 char *last_char_p
= (char *) object
;
5903 *last_char_p
= buffer
[length
- 1];
5906 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
5907 compute the physname for the object, which include a method's:
5908 - formal parameters (C++/Java),
5909 - receiver type (Go),
5910 - return type (Java).
5912 The term "physname" is a bit confusing.
5913 For C++, for example, it is the demangled name.
5914 For Go, for example, it's the mangled name.
5916 For Ada, return the DIE's linkage name rather than the fully qualified
5917 name. PHYSNAME is ignored..
5919 The result is allocated on the objfile_obstack and canonicalized. */
5922 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
5925 struct objfile
*objfile
= cu
->objfile
;
5928 name
= dwarf2_name (die
, cu
);
5930 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
5931 compute it by typename_concat inside GDB. */
5932 if (cu
->language
== language_ada
5933 || (cu
->language
== language_fortran
&& physname
))
5935 /* For Ada unit, we prefer the linkage name over the name, as
5936 the former contains the exported name, which the user expects
5937 to be able to reference. Ideally, we want the user to be able
5938 to reference this entity using either natural or linkage name,
5939 but we haven't started looking at this enhancement yet. */
5940 struct attribute
*attr
;
5942 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5944 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5945 if (attr
&& DW_STRING (attr
))
5946 return DW_STRING (attr
);
5949 /* These are the only languages we know how to qualify names in. */
5951 && (cu
->language
== language_cplus
|| cu
->language
== language_java
5952 || cu
->language
== language_fortran
))
5954 if (die_needs_namespace (die
, cu
))
5958 struct ui_file
*buf
;
5960 prefix
= determine_prefix (die
, cu
);
5961 buf
= mem_fileopen ();
5962 if (*prefix
!= '\0')
5964 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
5967 fputs_unfiltered (prefixed_name
, buf
);
5968 xfree (prefixed_name
);
5971 fputs_unfiltered (name
, buf
);
5973 /* Template parameters may be specified in the DIE's DW_AT_name, or
5974 as children with DW_TAG_template_type_param or
5975 DW_TAG_value_type_param. If the latter, add them to the name
5976 here. If the name already has template parameters, then
5977 skip this step; some versions of GCC emit both, and
5978 it is more efficient to use the pre-computed name.
5980 Something to keep in mind about this process: it is very
5981 unlikely, or in some cases downright impossible, to produce
5982 something that will match the mangled name of a function.
5983 If the definition of the function has the same debug info,
5984 we should be able to match up with it anyway. But fallbacks
5985 using the minimal symbol, for instance to find a method
5986 implemented in a stripped copy of libstdc++, will not work.
5987 If we do not have debug info for the definition, we will have to
5988 match them up some other way.
5990 When we do name matching there is a related problem with function
5991 templates; two instantiated function templates are allowed to
5992 differ only by their return types, which we do not add here. */
5994 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
5996 struct attribute
*attr
;
5997 struct die_info
*child
;
6000 die
->building_fullname
= 1;
6002 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
6007 struct dwarf2_locexpr_baton
*baton
;
6010 if (child
->tag
!= DW_TAG_template_type_param
6011 && child
->tag
!= DW_TAG_template_value_param
)
6016 fputs_unfiltered ("<", buf
);
6020 fputs_unfiltered (", ", buf
);
6022 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
6025 complaint (&symfile_complaints
,
6026 _("template parameter missing DW_AT_type"));
6027 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
6030 type
= die_type (child
, cu
);
6032 if (child
->tag
== DW_TAG_template_type_param
)
6034 c_print_type (type
, "", buf
, -1, 0);
6038 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
6041 complaint (&symfile_complaints
,
6042 _("template parameter missing "
6043 "DW_AT_const_value"));
6044 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
6048 dwarf2_const_value_attr (attr
, type
, name
,
6049 &cu
->comp_unit_obstack
, cu
,
6050 &value
, &bytes
, &baton
);
6052 if (TYPE_NOSIGN (type
))
6053 /* GDB prints characters as NUMBER 'CHAR'. If that's
6054 changed, this can use value_print instead. */
6055 c_printchar (value
, type
, buf
);
6058 struct value_print_options opts
;
6061 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
6065 else if (bytes
!= NULL
)
6067 v
= allocate_value (type
);
6068 memcpy (value_contents_writeable (v
), bytes
,
6069 TYPE_LENGTH (type
));
6072 v
= value_from_longest (type
, value
);
6074 /* Specify decimal so that we do not depend on
6076 get_formatted_print_options (&opts
, 'd');
6078 value_print (v
, buf
, &opts
);
6084 die
->building_fullname
= 0;
6088 /* Close the argument list, with a space if necessary
6089 (nested templates). */
6090 char last_char
= '\0';
6091 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
6092 if (last_char
== '>')
6093 fputs_unfiltered (" >", buf
);
6095 fputs_unfiltered (">", buf
);
6099 /* For Java and C++ methods, append formal parameter type
6100 information, if PHYSNAME. */
6102 if (physname
&& die
->tag
== DW_TAG_subprogram
6103 && (cu
->language
== language_cplus
6104 || cu
->language
== language_java
))
6106 struct type
*type
= read_type_die (die
, cu
);
6108 c_type_print_args (type
, buf
, 1, cu
->language
);
6110 if (cu
->language
== language_java
)
6112 /* For java, we must append the return type to method
6114 if (die
->tag
== DW_TAG_subprogram
)
6115 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
6118 else if (cu
->language
== language_cplus
)
6120 /* Assume that an artificial first parameter is
6121 "this", but do not crash if it is not. RealView
6122 marks unnamed (and thus unused) parameters as
6123 artificial; there is no way to differentiate
6125 if (TYPE_NFIELDS (type
) > 0
6126 && TYPE_FIELD_ARTIFICIAL (type
, 0)
6127 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
6128 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
6130 fputs_unfiltered (" const", buf
);
6134 name
= ui_file_obsavestring (buf
, &objfile
->objfile_obstack
,
6136 ui_file_delete (buf
);
6138 if (cu
->language
== language_cplus
)
6141 = dwarf2_canonicalize_name (name
, cu
,
6142 &objfile
->objfile_obstack
);
6153 /* Return the fully qualified name of DIE, based on its DW_AT_name.
6154 If scope qualifiers are appropriate they will be added. The result
6155 will be allocated on the objfile_obstack, or NULL if the DIE does
6156 not have a name. NAME may either be from a previous call to
6157 dwarf2_name or NULL.
6159 The output string will be canonicalized (if C++/Java). */
6162 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
6164 return dwarf2_compute_name (name
, die
, cu
, 0);
6167 /* Construct a physname for the given DIE in CU. NAME may either be
6168 from a previous call to dwarf2_name or NULL. The result will be
6169 allocated on the objfile_objstack or NULL if the DIE does not have a
6172 The output string will be canonicalized (if C++/Java). */
6175 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
6177 struct objfile
*objfile
= cu
->objfile
;
6178 struct attribute
*attr
;
6179 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
6180 struct cleanup
*back_to
;
6183 /* In this case dwarf2_compute_name is just a shortcut not building anything
6185 if (!die_needs_namespace (die
, cu
))
6186 return dwarf2_compute_name (name
, die
, cu
, 1);
6188 back_to
= make_cleanup (null_cleanup
, NULL
);
6190 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
6192 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
6194 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
6196 if (attr
&& DW_STRING (attr
))
6200 mangled
= DW_STRING (attr
);
6202 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
6203 type. It is easier for GDB users to search for such functions as
6204 `name(params)' than `long name(params)'. In such case the minimal
6205 symbol names do not match the full symbol names but for template
6206 functions there is never a need to look up their definition from their
6207 declaration so the only disadvantage remains the minimal symbol
6208 variant `long name(params)' does not have the proper inferior type.
6211 if (cu
->language
== language_go
)
6213 /* This is a lie, but we already lie to the caller new_symbol_full.
6214 new_symbol_full assumes we return the mangled name.
6215 This just undoes that lie until things are cleaned up. */
6220 demangled
= cplus_demangle (mangled
,
6221 (DMGL_PARAMS
| DMGL_ANSI
6222 | (cu
->language
== language_java
6223 ? DMGL_JAVA
| DMGL_RET_POSTFIX
6228 make_cleanup (xfree
, demangled
);
6238 if (canon
== NULL
|| check_physname
)
6240 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
6242 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
6244 /* It may not mean a bug in GDB. The compiler could also
6245 compute DW_AT_linkage_name incorrectly. But in such case
6246 GDB would need to be bug-to-bug compatible. */
6248 complaint (&symfile_complaints
,
6249 _("Computed physname <%s> does not match demangled <%s> "
6250 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
6251 physname
, canon
, mangled
, die
->offset
.sect_off
, objfile
->name
);
6253 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
6254 is available here - over computed PHYSNAME. It is safer
6255 against both buggy GDB and buggy compilers. */
6269 retval
= obsavestring (retval
, strlen (retval
),
6270 &objfile
->objfile_obstack
);
6272 do_cleanups (back_to
);
6276 /* Read the import statement specified by the given die and record it. */
6279 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
6281 struct objfile
*objfile
= cu
->objfile
;
6282 struct attribute
*import_attr
;
6283 struct die_info
*imported_die
, *child_die
;
6284 struct dwarf2_cu
*imported_cu
;
6285 const char *imported_name
;
6286 const char *imported_name_prefix
;
6287 const char *canonical_name
;
6288 const char *import_alias
;
6289 const char *imported_declaration
= NULL
;
6290 const char *import_prefix
;
6291 VEC (const_char_ptr
) *excludes
= NULL
;
6292 struct cleanup
*cleanups
;
6296 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
6297 if (import_attr
== NULL
)
6299 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
6300 dwarf_tag_name (die
->tag
));
6305 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
6306 imported_name
= dwarf2_name (imported_die
, imported_cu
);
6307 if (imported_name
== NULL
)
6309 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
6311 The import in the following code:
6325 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
6326 <52> DW_AT_decl_file : 1
6327 <53> DW_AT_decl_line : 6
6328 <54> DW_AT_import : <0x75>
6329 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
6331 <5b> DW_AT_decl_file : 1
6332 <5c> DW_AT_decl_line : 2
6333 <5d> DW_AT_type : <0x6e>
6335 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
6336 <76> DW_AT_byte_size : 4
6337 <77> DW_AT_encoding : 5 (signed)
6339 imports the wrong die ( 0x75 instead of 0x58 ).
6340 This case will be ignored until the gcc bug is fixed. */
6344 /* Figure out the local name after import. */
6345 import_alias
= dwarf2_name (die
, cu
);
6347 /* Figure out where the statement is being imported to. */
6348 import_prefix
= determine_prefix (die
, cu
);
6350 /* Figure out what the scope of the imported die is and prepend it
6351 to the name of the imported die. */
6352 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
6354 if (imported_die
->tag
!= DW_TAG_namespace
6355 && imported_die
->tag
!= DW_TAG_module
)
6357 imported_declaration
= imported_name
;
6358 canonical_name
= imported_name_prefix
;
6360 else if (strlen (imported_name_prefix
) > 0)
6362 temp
= alloca (strlen (imported_name_prefix
)
6363 + 2 + strlen (imported_name
) + 1);
6364 strcpy (temp
, imported_name_prefix
);
6365 strcat (temp
, "::");
6366 strcat (temp
, imported_name
);
6367 canonical_name
= temp
;
6370 canonical_name
= imported_name
;
6372 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
6374 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
6375 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
6376 child_die
= sibling_die (child_die
))
6378 /* DWARF-4: A Fortran use statement with a “rename list” may be
6379 represented by an imported module entry with an import attribute
6380 referring to the module and owned entries corresponding to those
6381 entities that are renamed as part of being imported. */
6383 if (child_die
->tag
!= DW_TAG_imported_declaration
)
6385 complaint (&symfile_complaints
,
6386 _("child DW_TAG_imported_declaration expected "
6387 "- DIE at 0x%x [in module %s]"),
6388 child_die
->offset
.sect_off
, objfile
->name
);
6392 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
6393 if (import_attr
== NULL
)
6395 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
6396 dwarf_tag_name (child_die
->tag
));
6401 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
6403 imported_name
= dwarf2_name (imported_die
, imported_cu
);
6404 if (imported_name
== NULL
)
6406 complaint (&symfile_complaints
,
6407 _("child DW_TAG_imported_declaration has unknown "
6408 "imported name - DIE at 0x%x [in module %s]"),
6409 child_die
->offset
.sect_off
, objfile
->name
);
6413 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
6415 process_die (child_die
, cu
);
6418 cp_add_using_directive (import_prefix
,
6421 imported_declaration
,
6423 &objfile
->objfile_obstack
);
6425 do_cleanups (cleanups
);
6428 /* Cleanup function for read_file_scope. */
6431 free_cu_line_header (void *arg
)
6433 struct dwarf2_cu
*cu
= arg
;
6435 free_line_header (cu
->line_header
);
6436 cu
->line_header
= NULL
;
6440 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
6441 char **name
, char **comp_dir
)
6443 struct attribute
*attr
;
6448 /* Find the filename. Do not use dwarf2_name here, since the filename
6449 is not a source language identifier. */
6450 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6453 *name
= DW_STRING (attr
);
6456 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
6458 *comp_dir
= DW_STRING (attr
);
6459 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
6461 *comp_dir
= ldirname (*name
);
6462 if (*comp_dir
!= NULL
)
6463 make_cleanup (xfree
, *comp_dir
);
6465 if (*comp_dir
!= NULL
)
6467 /* Irix 6.2 native cc prepends <machine>.: to the compilation
6468 directory, get rid of it. */
6469 char *cp
= strchr (*comp_dir
, ':');
6471 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
6476 *name
= "<unknown>";
6479 /* Handle DW_AT_stmt_list for a compilation unit or type unit.
6480 DIE is the DW_TAG_compile_unit or DW_TAG_type_unit die for CU.
6481 COMP_DIR is the compilation directory.
6482 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
6485 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
6486 const char *comp_dir
, int want_line_info
)
6488 struct attribute
*attr
;
6490 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6493 unsigned int line_offset
= DW_UNSND (attr
);
6494 struct line_header
*line_header
6495 = dwarf_decode_line_header (line_offset
, cu
);
6499 cu
->line_header
= line_header
;
6500 make_cleanup (free_cu_line_header
, cu
);
6501 dwarf_decode_lines (line_header
, comp_dir
, cu
, NULL
, want_line_info
);
6506 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
6509 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6511 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6512 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
6513 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
6514 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
6515 struct attribute
*attr
;
6517 char *comp_dir
= NULL
;
6518 struct die_info
*child_die
;
6519 bfd
*abfd
= objfile
->obfd
;
6522 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6524 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
6526 /* If we didn't find a lowpc, set it to highpc to avoid complaints
6527 from finish_block. */
6528 if (lowpc
== ((CORE_ADDR
) -1))
6533 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
6535 prepare_one_comp_unit (cu
, die
, cu
->language
);
6537 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
6538 standardised yet. As a workaround for the language detection we fall
6539 back to the DW_AT_producer string. */
6540 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
6541 cu
->language
= language_opencl
;
6543 /* Similar hack for Go. */
6544 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
6545 set_cu_language (DW_LANG_Go
, cu
);
6547 /* We assume that we're processing GCC output. */
6548 processing_gcc_compilation
= 2;
6550 processing_has_namespace_info
= 0;
6552 start_symtab (name
, comp_dir
, lowpc
);
6553 record_debugformat ("DWARF 2");
6554 record_producer (cu
->producer
);
6556 /* Decode line number information if present. We do this before
6557 processing child DIEs, so that the line header table is available
6558 for DW_AT_decl_file. */
6559 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, 1);
6561 /* Process all dies in compilation unit. */
6562 if (die
->child
!= NULL
)
6564 child_die
= die
->child
;
6565 while (child_die
&& child_die
->tag
)
6567 process_die (child_die
, cu
);
6568 child_die
= sibling_die (child_die
);
6572 /* Decode macro information, if present. Dwarf 2 macro information
6573 refers to information in the line number info statement program
6574 header, so we can only read it if we've read the header
6576 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
6577 if (attr
&& cu
->line_header
)
6579 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
6580 complaint (&symfile_complaints
,
6581 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
6583 dwarf_decode_macros (cu
->line_header
, DW_UNSND (attr
),
6585 &dwarf2_per_objfile
->macro
, 1,
6590 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
6591 if (attr
&& cu
->line_header
)
6593 unsigned int macro_offset
= DW_UNSND (attr
);
6595 dwarf_decode_macros (cu
->line_header
, macro_offset
,
6597 &dwarf2_per_objfile
->macinfo
, 0,
6602 do_cleanups (back_to
);
6605 /* Process DW_TAG_type_unit.
6606 For TUs we want to skip the first top level sibling if it's not the
6607 actual type being defined by this TU. In this case the first top
6608 level sibling is there to provide context only. */
6611 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6613 struct objfile
*objfile
= cu
->objfile
;
6614 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
6616 struct attribute
*attr
;
6618 char *comp_dir
= NULL
;
6619 struct die_info
*child_die
;
6620 bfd
*abfd
= objfile
->obfd
;
6622 /* start_symtab needs a low pc, but we don't really have one.
6623 Do what read_file_scope would do in the absence of such info. */
6624 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6626 /* Find the filename. Do not use dwarf2_name here, since the filename
6627 is not a source language identifier. */
6628 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6630 name
= DW_STRING (attr
);
6632 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
6634 comp_dir
= DW_STRING (attr
);
6635 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
6637 comp_dir
= ldirname (name
);
6638 if (comp_dir
!= NULL
)
6639 make_cleanup (xfree
, comp_dir
);
6645 prepare_one_comp_unit (cu
, die
, language_minimal
);
6647 /* We assume that we're processing GCC output. */
6648 processing_gcc_compilation
= 2;
6650 processing_has_namespace_info
= 0;
6652 start_symtab (name
, comp_dir
, lowpc
);
6653 record_debugformat ("DWARF 2");
6654 record_producer (cu
->producer
);
6656 /* Decode line number information if present. We do this before
6657 processing child DIEs, so that the line header table is available
6658 for DW_AT_decl_file.
6659 We don't need the pc/line-number mapping for type units. */
6660 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, 0);
6662 /* Process the dies in the type unit. */
6663 if (die
->child
== NULL
)
6665 dump_die_for_error (die
);
6666 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
6667 bfd_get_filename (abfd
));
6670 child_die
= die
->child
;
6672 while (child_die
&& child_die
->tag
)
6674 process_die (child_die
, cu
);
6676 child_die
= sibling_die (child_die
);
6679 do_cleanups (back_to
);
6685 hash_dwo_file (const void *item
)
6687 const struct dwo_file
*dwo_file
= item
;
6689 return htab_hash_string (dwo_file
->dwo_name
);
6693 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
6695 const struct dwo_file
*lhs
= item_lhs
;
6696 const struct dwo_file
*rhs
= item_rhs
;
6698 return strcmp (lhs
->dwo_name
, rhs
->dwo_name
) == 0;
6701 /* Allocate a hash table for DWO files. */
6704 allocate_dwo_file_hash_table (void)
6706 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6708 return htab_create_alloc_ex (41,
6712 &objfile
->objfile_obstack
,
6713 hashtab_obstack_allocate
,
6714 dummy_obstack_deallocate
);
6718 hash_dwo_unit (const void *item
)
6720 const struct dwo_unit
*dwo_unit
= item
;
6722 /* This drops the top 32 bits of the id, but is ok for a hash. */
6723 return dwo_unit
->signature
;
6727 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
6729 const struct dwo_unit
*lhs
= item_lhs
;
6730 const struct dwo_unit
*rhs
= item_rhs
;
6732 /* The signature is assumed to be unique within the DWO file.
6733 So while object file CU dwo_id's always have the value zero,
6734 that's OK, assuming each object file DWO file has only one CU,
6735 and that's the rule for now. */
6736 return lhs
->signature
== rhs
->signature
;
6739 /* Allocate a hash table for DWO CUs,TUs.
6740 There is one of these tables for each of CUs,TUs for each DWO file. */
6743 allocate_dwo_unit_table (struct objfile
*objfile
)
6745 /* Start out with a pretty small number.
6746 Generally DWO files contain only one CU and maybe some TUs. */
6747 return htab_create_alloc_ex (3,
6751 &objfile
->objfile_obstack
,
6752 hashtab_obstack_allocate
,
6753 dummy_obstack_deallocate
);
6756 /* This function is mapped across the sections and remembers the offset and
6757 size of each of the DWO debugging sections we are interested in. */
6760 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_file_ptr
)
6762 struct dwo_file
*dwo_file
= dwo_file_ptr
;
6763 const struct dwo_section_names
*names
= &dwo_section_names
;
6765 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
6767 dwo_file
->sections
.abbrev
.asection
= sectp
;
6768 dwo_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
6770 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
6772 dwo_file
->sections
.info
.asection
= sectp
;
6773 dwo_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
6775 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
6777 dwo_file
->sections
.line
.asection
= sectp
;
6778 dwo_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
6780 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
6782 dwo_file
->sections
.loc
.asection
= sectp
;
6783 dwo_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
6785 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
6787 dwo_file
->sections
.str
.asection
= sectp
;
6788 dwo_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
6790 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
6792 dwo_file
->sections
.str_offsets
.asection
= sectp
;
6793 dwo_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
6795 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
6797 struct dwarf2_section_info type_section
;
6799 memset (&type_section
, 0, sizeof (type_section
));
6800 type_section
.asection
= sectp
;
6801 type_section
.size
= bfd_get_section_size (sectp
);
6802 VEC_safe_push (dwarf2_section_info_def
, dwo_file
->sections
.types
,
6807 /* Structure used to pass data to create_debug_info_hash_table_reader. */
6809 struct create_dwo_info_table_data
6811 struct dwo_file
*dwo_file
;
6815 /* die_reader_func for create_debug_info_hash_table. */
6818 create_debug_info_hash_table_reader (const struct die_reader_specs
*reader
,
6820 struct die_info
*comp_unit_die
,
6824 struct dwarf2_cu
*cu
= reader
->cu
;
6825 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6826 sect_offset offset
= cu
->per_cu
->offset
;
6827 struct dwarf2_section_info
*section
= cu
->per_cu
->info_or_types_section
;
6828 struct create_dwo_info_table_data
*data
= datap
;
6829 struct dwo_file
*dwo_file
= data
->dwo_file
;
6830 htab_t cu_htab
= data
->cu_htab
;
6832 struct attribute
*attr
;
6833 struct dwo_unit
*dwo_unit
;
6835 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6838 error (_("Dwarf Error: debug entry at offset 0x%x is missing"
6839 " its dwo_id [in module %s]"),
6840 offset
.sect_off
, dwo_file
->dwo_name
);
6844 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
6845 dwo_unit
->dwo_file
= dwo_file
;
6846 dwo_unit
->signature
= DW_UNSND (attr
);
6847 dwo_unit
->info_or_types_section
= section
;
6848 dwo_unit
->offset
= offset
;
6849 dwo_unit
->length
= cu
->per_cu
->length
;
6851 slot
= htab_find_slot (cu_htab
, dwo_unit
, INSERT
);
6852 gdb_assert (slot
!= NULL
);
6855 const struct dwo_unit
*dup_dwo_unit
= *slot
;
6857 complaint (&symfile_complaints
,
6858 _("debug entry at offset 0x%x is duplicate to the entry at"
6859 " offset 0x%x, dwo_id 0x%s [in module %s]"),
6860 offset
.sect_off
, dup_dwo_unit
->offset
.sect_off
,
6861 phex (dwo_unit
->signature
, sizeof (dwo_unit
->signature
)),
6862 dwo_file
->dwo_name
);
6867 if (dwarf2_die_debug
)
6868 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, dwo_id 0x%s\n",
6870 phex (dwo_unit
->signature
,
6871 sizeof (dwo_unit
->signature
)));
6874 /* Create a hash table to map DWO IDs to their CU entry in .debug_info.dwo. */
6877 create_debug_info_hash_table (struct dwo_file
*dwo_file
)
6879 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6880 struct dwarf2_section_info
*section
= &dwo_file
->sections
.info
;
6883 gdb_byte
*info_ptr
, *end_ptr
;
6884 struct create_dwo_info_table_data create_dwo_info_table_data
;
6886 dwarf2_read_section (objfile
, section
);
6887 info_ptr
= section
->buffer
;
6889 if (info_ptr
== NULL
)
6892 /* We can't set abfd until now because the section may be empty or
6893 not present, in which case section->asection will be NULL. */
6894 abfd
= section
->asection
->owner
;
6896 if (dwarf2_die_debug
)
6897 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_info.dwo for %s:\n",
6898 bfd_get_filename (abfd
));
6900 cu_htab
= allocate_dwo_unit_table (objfile
);
6902 create_dwo_info_table_data
.dwo_file
= dwo_file
;
6903 create_dwo_info_table_data
.cu_htab
= cu_htab
;
6905 end_ptr
= info_ptr
+ section
->size
;
6906 while (info_ptr
< end_ptr
)
6908 struct dwarf2_per_cu_data per_cu
;
6910 memset (&per_cu
, 0, sizeof (per_cu
));
6911 per_cu
.objfile
= objfile
;
6912 per_cu
.is_debug_types
= 0;
6913 per_cu
.offset
.sect_off
= info_ptr
- section
->buffer
;
6914 per_cu
.info_or_types_section
= section
;
6916 init_cutu_and_read_dies_no_follow (&per_cu
,
6917 &dwo_file
->sections
.abbrev
,
6919 create_debug_info_hash_table_reader
,
6920 &create_dwo_info_table_data
);
6922 info_ptr
+= per_cu
.length
;
6928 /* Subroutine of open_dwo_file to simplify it.
6929 Open the file specified by FILE_NAME and hand it off to BFD for
6930 preliminary analysis. Return a newly initialized bfd *, which
6931 includes a canonicalized copy of FILE_NAME.
6932 In case of trouble, return NULL.
6933 NOTE: This function is derived from symfile_bfd_open. */
6936 try_open_dwo_file (const char *file_name
)
6940 char *absolute_name
;
6942 desc
= openp (debug_file_directory
, OPF_TRY_CWD_FIRST
, file_name
,
6943 O_RDONLY
| O_BINARY
, &absolute_name
);
6947 sym_bfd
= bfd_fopen (absolute_name
, gnutarget
, FOPEN_RB
, desc
);
6951 xfree (absolute_name
);
6954 bfd_set_cacheable (sym_bfd
, 1);
6956 if (!bfd_check_format (sym_bfd
, bfd_object
))
6958 bfd_close (sym_bfd
); /* This also closes desc. */
6959 xfree (absolute_name
);
6963 /* bfd_usrdata exists for applications and libbfd must not touch it. */
6964 gdb_assert (bfd_usrdata (sym_bfd
) == NULL
);
6969 /* Try to open DWO file DWO_NAME.
6970 COMP_DIR is the DW_AT_comp_dir attribute.
6971 The result is the bfd handle of the file.
6972 If there is a problem finding or opening the file, return NULL.
6973 Upon success, the canonicalized path of the file is stored in the bfd,
6974 same as symfile_bfd_open. */
6977 open_dwo_file (const char *dwo_name
, const char *comp_dir
)
6981 if (IS_ABSOLUTE_PATH (dwo_name
))
6982 return try_open_dwo_file (dwo_name
);
6984 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
6986 if (comp_dir
!= NULL
)
6988 char *path_to_try
= concat (comp_dir
, SLASH_STRING
, dwo_name
, NULL
);
6990 /* NOTE: If comp_dir is a relative path, this will also try the
6991 search path, which seems useful. */
6992 abfd
= try_open_dwo_file (path_to_try
);
6993 xfree (path_to_try
);
6998 /* That didn't work, try debug-file-directory, which, despite its name,
6999 is a list of paths. */
7001 if (*debug_file_directory
== '\0')
7004 return try_open_dwo_file (dwo_name
);
7007 /* Initialize the use of the DWO file specified by DWO_NAME. */
7009 static struct dwo_file
*
7010 init_dwo_file (const char *dwo_name
, const char *comp_dir
)
7012 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7013 struct dwo_file
*dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7016 struct cleanup
*cleanups
;
7018 if (dwarf2_die_debug
)
7019 fprintf_unfiltered (gdb_stdlog
, "Reading DWO file %s:\n", dwo_name
);
7021 abfd
= open_dwo_file (dwo_name
, comp_dir
);
7024 dwo_file
->dwo_name
= dwo_name
;
7025 dwo_file
->dwo_bfd
= abfd
;
7027 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwo_file
);
7029 bfd_map_over_sections (abfd
, dwarf2_locate_dwo_sections
, dwo_file
);
7031 dwo_file
->cus
= create_debug_info_hash_table (dwo_file
);
7033 dwo_file
->tus
= create_debug_types_hash_table (dwo_file
,
7034 dwo_file
->sections
.types
);
7036 discard_cleanups (cleanups
);
7041 /* Lookup DWO file DWO_NAME. */
7043 static struct dwo_file
*
7044 lookup_dwo_file (char *dwo_name
, const char *comp_dir
)
7046 struct dwo_file
*dwo_file
;
7047 struct dwo_file find_entry
;
7050 if (dwarf2_per_objfile
->dwo_files
== NULL
)
7051 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
7053 /* Have we already seen this DWO file? */
7054 find_entry
.dwo_name
= dwo_name
;
7055 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
7057 /* If not, read it in and build a table of the DWOs it contains. */
7059 *slot
= init_dwo_file (dwo_name
, comp_dir
);
7061 /* NOTE: This will be NULL if unable to open the file. */
7067 /* Lookup the DWO CU referenced from THIS_CU in DWO file DWO_NAME.
7068 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
7069 SIGNATURE is the "dwo_id" of the CU (for consistency we use the same
7070 nomenclature as TUs).
7071 The result is the DWO CU or NULL if we didn't find it
7072 (dwo_id mismatch or couldn't find the DWO file). */
7074 static struct dwo_unit
*
7075 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7076 char *dwo_name
, const char *comp_dir
,
7079 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7080 struct dwo_file
*dwo_file
;
7082 dwo_file
= lookup_dwo_file (dwo_name
, comp_dir
);
7083 if (dwo_file
== NULL
)
7086 /* Look up the DWO using its signature(dwo_id). */
7088 if (dwo_file
->cus
!= NULL
)
7090 struct dwo_unit find_dwo_cu
, *dwo_cu
;
7092 find_dwo_cu
.signature
= signature
;
7093 dwo_cu
= htab_find (dwo_file
->cus
, &find_dwo_cu
);
7099 /* We didn't find it. This must mean a dwo_id mismatch. */
7101 complaint (&symfile_complaints
,
7102 _("Could not find DWO CU referenced by CU at offset 0x%x"
7104 this_cu
->offset
.sect_off
, objfile
->name
);
7108 /* Lookup the DWO TU referenced from THIS_TU in DWO file DWO_NAME.
7109 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
7110 The result is the DWO CU or NULL if we didn't find it
7111 (dwo_id mismatch or couldn't find the DWO file). */
7113 static struct dwo_unit
*
7114 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
7115 char *dwo_name
, const char *comp_dir
)
7117 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7118 struct dwo_file
*dwo_file
;
7120 dwo_file
= lookup_dwo_file (dwo_name
, comp_dir
);
7121 if (dwo_file
== NULL
)
7124 /* Look up the DWO using its signature(dwo_id). */
7126 if (dwo_file
->tus
!= NULL
)
7128 struct dwo_unit find_dwo_tu
, *dwo_tu
;
7130 find_dwo_tu
.signature
= this_tu
->signature
;
7131 dwo_tu
= htab_find (dwo_file
->tus
, &find_dwo_tu
);
7137 /* We didn't find it. This must mean a dwo_id mismatch. */
7139 complaint (&symfile_complaints
,
7140 _("Could not find DWO TU referenced by TU at offset 0x%x"
7142 this_tu
->per_cu
.offset
.sect_off
, objfile
->name
);
7146 /* Free all resources associated with DWO_FILE.
7147 Close the DWO file and munmap the sections.
7148 All memory should be on the objfile obstack. */
7151 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
7154 struct dwarf2_section_info
*section
;
7156 gdb_assert (dwo_file
->dwo_bfd
!= objfile
->obfd
);
7157 bfd_close (dwo_file
->dwo_bfd
);
7159 munmap_section_buffer (&dwo_file
->sections
.abbrev
);
7160 munmap_section_buffer (&dwo_file
->sections
.info
);
7161 munmap_section_buffer (&dwo_file
->sections
.line
);
7162 munmap_section_buffer (&dwo_file
->sections
.loc
);
7163 munmap_section_buffer (&dwo_file
->sections
.str
);
7164 munmap_section_buffer (&dwo_file
->sections
.str_offsets
);
7167 VEC_iterate (dwarf2_section_info_def
, dwo_file
->sections
.types
,
7170 munmap_section_buffer (section
);
7172 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
7175 /* Wrapper for free_dwo_file for use in cleanups. */
7178 free_dwo_file_cleanup (void *arg
)
7180 struct dwo_file
*dwo_file
= (struct dwo_file
*) arg
;
7181 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7183 free_dwo_file (dwo_file
, objfile
);
7186 /* Traversal function for free_dwo_files. */
7189 free_dwo_file_from_slot (void **slot
, void *info
)
7191 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7192 struct objfile
*objfile
= (struct objfile
*) info
;
7194 free_dwo_file (dwo_file
, objfile
);
7199 /* Free all resources associated with DWO_FILES. */
7202 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
7204 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
7207 /* Read in various DIEs. */
7209 /* qsort helper for inherit_abstract_dies. */
7212 unsigned_int_compar (const void *ap
, const void *bp
)
7214 unsigned int a
= *(unsigned int *) ap
;
7215 unsigned int b
= *(unsigned int *) bp
;
7217 return (a
> b
) - (b
> a
);
7220 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
7221 Inherit only the children of the DW_AT_abstract_origin DIE not being
7222 already referenced by DW_AT_abstract_origin from the children of the
7226 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
7228 struct die_info
*child_die
;
7229 unsigned die_children_count
;
7230 /* CU offsets which were referenced by children of the current DIE. */
7231 sect_offset
*offsets
;
7232 sect_offset
*offsets_end
, *offsetp
;
7233 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
7234 struct die_info
*origin_die
;
7235 /* Iterator of the ORIGIN_DIE children. */
7236 struct die_info
*origin_child_die
;
7237 struct cleanup
*cleanups
;
7238 struct attribute
*attr
;
7239 struct dwarf2_cu
*origin_cu
;
7240 struct pending
**origin_previous_list_in_scope
;
7242 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
7246 /* Note that following die references may follow to a die in a
7250 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
7252 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
7254 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
7255 origin_cu
->list_in_scope
= cu
->list_in_scope
;
7257 if (die
->tag
!= origin_die
->tag
7258 && !(die
->tag
== DW_TAG_inlined_subroutine
7259 && origin_die
->tag
== DW_TAG_subprogram
))
7260 complaint (&symfile_complaints
,
7261 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
7262 die
->offset
.sect_off
, origin_die
->offset
.sect_off
);
7264 child_die
= die
->child
;
7265 die_children_count
= 0;
7266 while (child_die
&& child_die
->tag
)
7268 child_die
= sibling_die (child_die
);
7269 die_children_count
++;
7271 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
7272 cleanups
= make_cleanup (xfree
, offsets
);
7274 offsets_end
= offsets
;
7275 child_die
= die
->child
;
7276 while (child_die
&& child_die
->tag
)
7278 /* For each CHILD_DIE, find the corresponding child of
7279 ORIGIN_DIE. If there is more than one layer of
7280 DW_AT_abstract_origin, follow them all; there shouldn't be,
7281 but GCC versions at least through 4.4 generate this (GCC PR
7283 struct die_info
*child_origin_die
= child_die
;
7284 struct dwarf2_cu
*child_origin_cu
= cu
;
7288 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
7292 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
7296 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
7297 counterpart may exist. */
7298 if (child_origin_die
!= child_die
)
7300 if (child_die
->tag
!= child_origin_die
->tag
7301 && !(child_die
->tag
== DW_TAG_inlined_subroutine
7302 && child_origin_die
->tag
== DW_TAG_subprogram
))
7303 complaint (&symfile_complaints
,
7304 _("Child DIE 0x%x and its abstract origin 0x%x have "
7305 "different tags"), child_die
->offset
.sect_off
,
7306 child_origin_die
->offset
.sect_off
);
7307 if (child_origin_die
->parent
!= origin_die
)
7308 complaint (&symfile_complaints
,
7309 _("Child DIE 0x%x and its abstract origin 0x%x have "
7310 "different parents"), child_die
->offset
.sect_off
,
7311 child_origin_die
->offset
.sect_off
);
7313 *offsets_end
++ = child_origin_die
->offset
;
7315 child_die
= sibling_die (child_die
);
7317 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
7318 unsigned_int_compar
);
7319 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
7320 if (offsetp
[-1].sect_off
== offsetp
->sect_off
)
7321 complaint (&symfile_complaints
,
7322 _("Multiple children of DIE 0x%x refer "
7323 "to DIE 0x%x as their abstract origin"),
7324 die
->offset
.sect_off
, offsetp
->sect_off
);
7327 origin_child_die
= origin_die
->child
;
7328 while (origin_child_die
&& origin_child_die
->tag
)
7330 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
7331 while (offsetp
< offsets_end
7332 && offsetp
->sect_off
< origin_child_die
->offset
.sect_off
)
7334 if (offsetp
>= offsets_end
7335 || offsetp
->sect_off
> origin_child_die
->offset
.sect_off
)
7337 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
7338 process_die (origin_child_die
, origin_cu
);
7340 origin_child_die
= sibling_die (origin_child_die
);
7342 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
7344 do_cleanups (cleanups
);
7348 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7350 struct objfile
*objfile
= cu
->objfile
;
7351 struct context_stack
*new;
7354 struct die_info
*child_die
;
7355 struct attribute
*attr
, *call_line
, *call_file
;
7358 struct block
*block
;
7359 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
7360 VEC (symbolp
) *template_args
= NULL
;
7361 struct template_symbol
*templ_func
= NULL
;
7365 /* If we do not have call site information, we can't show the
7366 caller of this inlined function. That's too confusing, so
7367 only use the scope for local variables. */
7368 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
7369 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
7370 if (call_line
== NULL
|| call_file
== NULL
)
7372 read_lexical_block_scope (die
, cu
);
7377 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7379 name
= dwarf2_name (die
, cu
);
7381 /* Ignore functions with missing or empty names. These are actually
7382 illegal according to the DWARF standard. */
7385 complaint (&symfile_complaints
,
7386 _("missing name for subprogram DIE at %d"),
7387 die
->offset
.sect_off
);
7391 /* Ignore functions with missing or invalid low and high pc attributes. */
7392 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
7394 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
7395 if (!attr
|| !DW_UNSND (attr
))
7396 complaint (&symfile_complaints
,
7397 _("cannot get low and high bounds "
7398 "for subprogram DIE at %d"),
7399 die
->offset
.sect_off
);
7406 /* If we have any template arguments, then we must allocate a
7407 different sort of symbol. */
7408 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
7410 if (child_die
->tag
== DW_TAG_template_type_param
7411 || child_die
->tag
== DW_TAG_template_value_param
)
7413 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7414 struct template_symbol
);
7415 templ_func
->base
.is_cplus_template_function
= 1;
7420 new = push_context (0, lowpc
);
7421 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
7422 (struct symbol
*) templ_func
);
7424 /* If there is a location expression for DW_AT_frame_base, record
7426 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
7428 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
7429 expression is being recorded directly in the function's symbol
7430 and not in a separate frame-base object. I guess this hack is
7431 to avoid adding some sort of frame-base adjunct/annex to the
7432 function's symbol :-(. The problem with doing this is that it
7433 results in a function symbol with a location expression that
7434 has nothing to do with the location of the function, ouch! The
7435 relationship should be: a function's symbol has-a frame base; a
7436 frame-base has-a location expression. */
7437 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
7439 cu
->list_in_scope
= &local_symbols
;
7441 if (die
->child
!= NULL
)
7443 child_die
= die
->child
;
7444 while (child_die
&& child_die
->tag
)
7446 if (child_die
->tag
== DW_TAG_template_type_param
7447 || child_die
->tag
== DW_TAG_template_value_param
)
7449 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
7452 VEC_safe_push (symbolp
, template_args
, arg
);
7455 process_die (child_die
, cu
);
7456 child_die
= sibling_die (child_die
);
7460 inherit_abstract_dies (die
, cu
);
7462 /* If we have a DW_AT_specification, we might need to import using
7463 directives from the context of the specification DIE. See the
7464 comment in determine_prefix. */
7465 if (cu
->language
== language_cplus
7466 && dwarf2_attr (die
, DW_AT_specification
, cu
))
7468 struct dwarf2_cu
*spec_cu
= cu
;
7469 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
7473 child_die
= spec_die
->child
;
7474 while (child_die
&& child_die
->tag
)
7476 if (child_die
->tag
== DW_TAG_imported_module
)
7477 process_die (child_die
, spec_cu
);
7478 child_die
= sibling_die (child_die
);
7481 /* In some cases, GCC generates specification DIEs that
7482 themselves contain DW_AT_specification attributes. */
7483 spec_die
= die_specification (spec_die
, &spec_cu
);
7487 new = pop_context ();
7488 /* Make a block for the local symbols within. */
7489 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
7490 lowpc
, highpc
, objfile
);
7492 /* For C++, set the block's scope. */
7493 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
7494 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
7495 determine_prefix (die
, cu
),
7496 processing_has_namespace_info
);
7498 /* If we have address ranges, record them. */
7499 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
7501 /* Attach template arguments to function. */
7502 if (! VEC_empty (symbolp
, template_args
))
7504 gdb_assert (templ_func
!= NULL
);
7506 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
7507 templ_func
->template_arguments
7508 = obstack_alloc (&objfile
->objfile_obstack
,
7509 (templ_func
->n_template_arguments
7510 * sizeof (struct symbol
*)));
7511 memcpy (templ_func
->template_arguments
,
7512 VEC_address (symbolp
, template_args
),
7513 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
7514 VEC_free (symbolp
, template_args
);
7517 /* In C++, we can have functions nested inside functions (e.g., when
7518 a function declares a class that has methods). This means that
7519 when we finish processing a function scope, we may need to go
7520 back to building a containing block's symbol lists. */
7521 local_symbols
= new->locals
;
7522 param_symbols
= new->params
;
7523 using_directives
= new->using_directives
;
7525 /* If we've finished processing a top-level function, subsequent
7526 symbols go in the file symbol list. */
7527 if (outermost_context_p ())
7528 cu
->list_in_scope
= &file_symbols
;
7531 /* Process all the DIES contained within a lexical block scope. Start
7532 a new scope, process the dies, and then close the scope. */
7535 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7537 struct objfile
*objfile
= cu
->objfile
;
7538 struct context_stack
*new;
7539 CORE_ADDR lowpc
, highpc
;
7540 struct die_info
*child_die
;
7543 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7545 /* Ignore blocks with missing or invalid low and high pc attributes. */
7546 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
7547 as multiple lexical blocks? Handling children in a sane way would
7548 be nasty. Might be easier to properly extend generic blocks to
7550 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
7555 push_context (0, lowpc
);
7556 if (die
->child
!= NULL
)
7558 child_die
= die
->child
;
7559 while (child_die
&& child_die
->tag
)
7561 process_die (child_die
, cu
);
7562 child_die
= sibling_die (child_die
);
7565 new = pop_context ();
7567 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
7570 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
7573 /* Note that recording ranges after traversing children, as we
7574 do here, means that recording a parent's ranges entails
7575 walking across all its children's ranges as they appear in
7576 the address map, which is quadratic behavior.
7578 It would be nicer to record the parent's ranges before
7579 traversing its children, simply overriding whatever you find
7580 there. But since we don't even decide whether to create a
7581 block until after we've traversed its children, that's hard
7583 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
7585 local_symbols
= new->locals
;
7586 using_directives
= new->using_directives
;
7589 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
7592 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7594 struct objfile
*objfile
= cu
->objfile
;
7595 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7596 CORE_ADDR pc
, baseaddr
;
7597 struct attribute
*attr
;
7598 struct call_site
*call_site
, call_site_local
;
7601 struct die_info
*child_die
;
7603 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7605 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7608 complaint (&symfile_complaints
,
7609 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
7610 "DIE 0x%x [in module %s]"),
7611 die
->offset
.sect_off
, objfile
->name
);
7614 pc
= DW_ADDR (attr
) + baseaddr
;
7616 if (cu
->call_site_htab
== NULL
)
7617 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
7618 NULL
, &objfile
->objfile_obstack
,
7619 hashtab_obstack_allocate
, NULL
);
7620 call_site_local
.pc
= pc
;
7621 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
7624 complaint (&symfile_complaints
,
7625 _("Duplicate PC %s for DW_TAG_GNU_call_site "
7626 "DIE 0x%x [in module %s]"),
7627 paddress (gdbarch
, pc
), die
->offset
.sect_off
, objfile
->name
);
7631 /* Count parameters at the caller. */
7634 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
7635 child_die
= sibling_die (child_die
))
7637 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
7639 complaint (&symfile_complaints
,
7640 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
7641 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
7642 child_die
->tag
, child_die
->offset
.sect_off
, objfile
->name
);
7649 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
7650 (sizeof (*call_site
)
7651 + (sizeof (*call_site
->parameter
)
7654 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
7657 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
7659 struct die_info
*func_die
;
7661 /* Skip also over DW_TAG_inlined_subroutine. */
7662 for (func_die
= die
->parent
;
7663 func_die
&& func_die
->tag
!= DW_TAG_subprogram
7664 && func_die
->tag
!= DW_TAG_subroutine_type
;
7665 func_die
= func_die
->parent
);
7667 /* DW_AT_GNU_all_call_sites is a superset
7668 of DW_AT_GNU_all_tail_call_sites. */
7670 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
7671 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
7673 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
7674 not complete. But keep CALL_SITE for look ups via call_site_htab,
7675 both the initial caller containing the real return address PC and
7676 the final callee containing the current PC of a chain of tail
7677 calls do not need to have the tail call list complete. But any
7678 function candidate for a virtual tail call frame searched via
7679 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
7680 determined unambiguously. */
7684 struct type
*func_type
= NULL
;
7687 func_type
= get_die_type (func_die
, cu
);
7688 if (func_type
!= NULL
)
7690 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
7692 /* Enlist this call site to the function. */
7693 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
7694 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
7697 complaint (&symfile_complaints
,
7698 _("Cannot find function owning DW_TAG_GNU_call_site "
7699 "DIE 0x%x [in module %s]"),
7700 die
->offset
.sect_off
, objfile
->name
);
7704 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
7706 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
7707 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
7708 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
7709 /* Keep NULL DWARF_BLOCK. */;
7710 else if (attr_form_is_block (attr
))
7712 struct dwarf2_locexpr_baton
*dlbaton
;
7714 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
7715 dlbaton
->data
= DW_BLOCK (attr
)->data
;
7716 dlbaton
->size
= DW_BLOCK (attr
)->size
;
7717 dlbaton
->per_cu
= cu
->per_cu
;
7719 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
7721 else if (is_ref_attr (attr
))
7723 struct dwarf2_cu
*target_cu
= cu
;
7724 struct die_info
*target_die
;
7726 target_die
= follow_die_ref_or_sig (die
, attr
, &target_cu
);
7727 gdb_assert (target_cu
->objfile
== objfile
);
7728 if (die_is_declaration (target_die
, target_cu
))
7730 const char *target_physname
;
7732 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
7733 if (target_physname
== NULL
)
7734 complaint (&symfile_complaints
,
7735 _("DW_AT_GNU_call_site_target target DIE has invalid "
7736 "physname, for referencing DIE 0x%x [in module %s]"),
7737 die
->offset
.sect_off
, objfile
->name
);
7739 SET_FIELD_PHYSNAME (call_site
->target
, (char *) target_physname
);
7745 /* DW_AT_entry_pc should be preferred. */
7746 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
7747 complaint (&symfile_complaints
,
7748 _("DW_AT_GNU_call_site_target target DIE has invalid "
7749 "low pc, for referencing DIE 0x%x [in module %s]"),
7750 die
->offset
.sect_off
, objfile
->name
);
7752 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
7756 complaint (&symfile_complaints
,
7757 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
7758 "block nor reference, for DIE 0x%x [in module %s]"),
7759 die
->offset
.sect_off
, objfile
->name
);
7761 call_site
->per_cu
= cu
->per_cu
;
7763 for (child_die
= die
->child
;
7764 child_die
&& child_die
->tag
;
7765 child_die
= sibling_die (child_die
))
7767 struct call_site_parameter
*parameter
;
7769 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
7771 /* Already printed the complaint above. */
7775 gdb_assert (call_site
->parameter_count
< nparams
);
7776 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
7778 /* DW_AT_location specifies the register number. Value of the data
7779 assumed for the register is contained in DW_AT_GNU_call_site_value. */
7781 attr
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
7782 if (!attr
|| !attr_form_is_block (attr
))
7784 complaint (&symfile_complaints
,
7785 _("No DW_FORM_block* DW_AT_location for "
7786 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
7787 child_die
->offset
.sect_off
, objfile
->name
);
7790 parameter
->dwarf_reg
= dwarf_block_to_dwarf_reg (DW_BLOCK (attr
)->data
,
7791 &DW_BLOCK (attr
)->data
[DW_BLOCK (attr
)->size
]);
7792 if (parameter
->dwarf_reg
== -1
7793 && !dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (attr
)->data
,
7794 &DW_BLOCK (attr
)->data
[DW_BLOCK (attr
)->size
],
7795 ¶meter
->fb_offset
))
7797 complaint (&symfile_complaints
,
7798 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
7799 "for DW_FORM_block* DW_AT_location for "
7800 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
7801 child_die
->offset
.sect_off
, objfile
->name
);
7805 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
7806 if (!attr_form_is_block (attr
))
7808 complaint (&symfile_complaints
,
7809 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
7810 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
7811 child_die
->offset
.sect_off
, objfile
->name
);
7814 parameter
->value
= DW_BLOCK (attr
)->data
;
7815 parameter
->value_size
= DW_BLOCK (attr
)->size
;
7817 /* Parameters are not pre-cleared by memset above. */
7818 parameter
->data_value
= NULL
;
7819 parameter
->data_value_size
= 0;
7820 call_site
->parameter_count
++;
7822 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
7825 if (!attr_form_is_block (attr
))
7826 complaint (&symfile_complaints
,
7827 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
7828 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
7829 child_die
->offset
.sect_off
, objfile
->name
);
7832 parameter
->data_value
= DW_BLOCK (attr
)->data
;
7833 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
7839 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
7840 Return 1 if the attributes are present and valid, otherwise, return 0.
7841 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
7844 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
7845 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
7846 struct partial_symtab
*ranges_pst
)
7848 struct objfile
*objfile
= cu
->objfile
;
7849 struct comp_unit_head
*cu_header
= &cu
->header
;
7850 bfd
*obfd
= objfile
->obfd
;
7851 unsigned int addr_size
= cu_header
->addr_size
;
7852 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
7853 /* Base address selection entry. */
7864 found_base
= cu
->base_known
;
7865 base
= cu
->base_address
;
7867 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
7868 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
7870 complaint (&symfile_complaints
,
7871 _("Offset %d out of bounds for DW_AT_ranges attribute"),
7875 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
7877 /* Read in the largest possible address. */
7878 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
7879 if ((marker
& mask
) == mask
)
7881 /* If we found the largest possible address, then
7882 read the base address. */
7883 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
7884 buffer
+= 2 * addr_size
;
7885 offset
+= 2 * addr_size
;
7891 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7895 CORE_ADDR range_beginning
, range_end
;
7897 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
7898 buffer
+= addr_size
;
7899 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
7900 buffer
+= addr_size
;
7901 offset
+= 2 * addr_size
;
7903 /* An end of list marker is a pair of zero addresses. */
7904 if (range_beginning
== 0 && range_end
== 0)
7905 /* Found the end of list entry. */
7908 /* Each base address selection entry is a pair of 2 values.
7909 The first is the largest possible address, the second is
7910 the base address. Check for a base address here. */
7911 if ((range_beginning
& mask
) == mask
)
7913 /* If we found the largest possible address, then
7914 read the base address. */
7915 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
7922 /* We have no valid base address for the ranges
7924 complaint (&symfile_complaints
,
7925 _("Invalid .debug_ranges data (no base address)"));
7929 if (range_beginning
> range_end
)
7931 /* Inverted range entries are invalid. */
7932 complaint (&symfile_complaints
,
7933 _("Invalid .debug_ranges data (inverted range)"));
7937 /* Empty range entries have no effect. */
7938 if (range_beginning
== range_end
)
7941 range_beginning
+= base
;
7944 if (ranges_pst
!= NULL
)
7945 addrmap_set_empty (objfile
->psymtabs_addrmap
,
7946 range_beginning
+ baseaddr
,
7947 range_end
- 1 + baseaddr
,
7950 /* FIXME: This is recording everything as a low-high
7951 segment of consecutive addresses. We should have a
7952 data structure for discontiguous block ranges
7956 low
= range_beginning
;
7962 if (range_beginning
< low
)
7963 low
= range_beginning
;
7964 if (range_end
> high
)
7970 /* If the first entry is an end-of-list marker, the range
7971 describes an empty scope, i.e. no instructions. */
7977 *high_return
= high
;
7981 /* Get low and high pc attributes from a die. Return 1 if the attributes
7982 are present and valid, otherwise, return 0. Return -1 if the range is
7983 discontinuous, i.e. derived from DW_AT_ranges information. */
7986 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
7987 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
7988 struct partial_symtab
*pst
)
7990 struct attribute
*attr
;
7991 struct attribute
*attr_high
;
7996 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
7999 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
8002 low
= DW_ADDR (attr
);
8003 if (attr_high
->form
== DW_FORM_addr
8004 || attr_high
->form
== DW_FORM_GNU_addr_index
)
8005 high
= DW_ADDR (attr_high
);
8007 high
= low
+ DW_UNSND (attr_high
);
8010 /* Found high w/o low attribute. */
8013 /* Found consecutive range of addresses. */
8018 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
8021 /* Value of the DW_AT_ranges attribute is the offset in the
8022 .debug_ranges section. */
8023 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
8025 /* Found discontinuous range of addresses. */
8030 /* read_partial_die has also the strict LOW < HIGH requirement. */
8034 /* When using the GNU linker, .gnu.linkonce. sections are used to
8035 eliminate duplicate copies of functions and vtables and such.
8036 The linker will arbitrarily choose one and discard the others.
8037 The AT_*_pc values for such functions refer to local labels in
8038 these sections. If the section from that file was discarded, the
8039 labels are not in the output, so the relocs get a value of 0.
8040 If this is a discarded function, mark the pc bounds as invalid,
8041 so that GDB will ignore it. */
8042 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
8051 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
8052 its low and high PC addresses. Do nothing if these addresses could not
8053 be determined. Otherwise, set LOWPC to the low address if it is smaller,
8054 and HIGHPC to the high address if greater than HIGHPC. */
8057 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
8058 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8059 struct dwarf2_cu
*cu
)
8061 CORE_ADDR low
, high
;
8062 struct die_info
*child
= die
->child
;
8064 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
8066 *lowpc
= min (*lowpc
, low
);
8067 *highpc
= max (*highpc
, high
);
8070 /* If the language does not allow nested subprograms (either inside
8071 subprograms or lexical blocks), we're done. */
8072 if (cu
->language
!= language_ada
)
8075 /* Check all the children of the given DIE. If it contains nested
8076 subprograms, then check their pc bounds. Likewise, we need to
8077 check lexical blocks as well, as they may also contain subprogram
8079 while (child
&& child
->tag
)
8081 if (child
->tag
== DW_TAG_subprogram
8082 || child
->tag
== DW_TAG_lexical_block
)
8083 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
8084 child
= sibling_die (child
);
8088 /* Get the low and high pc's represented by the scope DIE, and store
8089 them in *LOWPC and *HIGHPC. If the correct values can't be
8090 determined, set *LOWPC to -1 and *HIGHPC to 0. */
8093 get_scope_pc_bounds (struct die_info
*die
,
8094 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8095 struct dwarf2_cu
*cu
)
8097 CORE_ADDR best_low
= (CORE_ADDR
) -1;
8098 CORE_ADDR best_high
= (CORE_ADDR
) 0;
8099 CORE_ADDR current_low
, current_high
;
8101 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
8103 best_low
= current_low
;
8104 best_high
= current_high
;
8108 struct die_info
*child
= die
->child
;
8110 while (child
&& child
->tag
)
8112 switch (child
->tag
) {
8113 case DW_TAG_subprogram
:
8114 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
8116 case DW_TAG_namespace
:
8118 /* FIXME: carlton/2004-01-16: Should we do this for
8119 DW_TAG_class_type/DW_TAG_structure_type, too? I think
8120 that current GCC's always emit the DIEs corresponding
8121 to definitions of methods of classes as children of a
8122 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
8123 the DIEs giving the declarations, which could be
8124 anywhere). But I don't see any reason why the
8125 standards says that they have to be there. */
8126 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
8128 if (current_low
!= ((CORE_ADDR
) -1))
8130 best_low
= min (best_low
, current_low
);
8131 best_high
= max (best_high
, current_high
);
8139 child
= sibling_die (child
);
8144 *highpc
= best_high
;
8147 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
8151 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
8152 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
8154 struct objfile
*objfile
= cu
->objfile
;
8155 struct attribute
*attr
;
8156 struct attribute
*attr_high
;
8158 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
8161 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
8164 CORE_ADDR low
= DW_ADDR (attr
);
8166 if (attr_high
->form
== DW_FORM_addr
8167 || attr_high
->form
== DW_FORM_GNU_addr_index
)
8168 high
= DW_ADDR (attr_high
);
8170 high
= low
+ DW_UNSND (attr_high
);
8172 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
8176 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
8179 bfd
*obfd
= objfile
->obfd
;
8181 /* The value of the DW_AT_ranges attribute is the offset of the
8182 address range list in the .debug_ranges section. */
8183 unsigned long offset
= DW_UNSND (attr
);
8184 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
8186 /* For some target architectures, but not others, the
8187 read_address function sign-extends the addresses it returns.
8188 To recognize base address selection entries, we need a
8190 unsigned int addr_size
= cu
->header
.addr_size
;
8191 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
8193 /* The base address, to which the next pair is relative. Note
8194 that this 'base' is a DWARF concept: most entries in a range
8195 list are relative, to reduce the number of relocs against the
8196 debugging information. This is separate from this function's
8197 'baseaddr' argument, which GDB uses to relocate debugging
8198 information from a shared library based on the address at
8199 which the library was loaded. */
8200 CORE_ADDR base
= cu
->base_address
;
8201 int base_known
= cu
->base_known
;
8203 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
8204 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
8206 complaint (&symfile_complaints
,
8207 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
8214 unsigned int bytes_read
;
8215 CORE_ADDR start
, end
;
8217 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
8218 buffer
+= bytes_read
;
8219 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
8220 buffer
+= bytes_read
;
8222 /* Did we find the end of the range list? */
8223 if (start
== 0 && end
== 0)
8226 /* Did we find a base address selection entry? */
8227 else if ((start
& base_select_mask
) == base_select_mask
)
8233 /* We found an ordinary address range. */
8238 complaint (&symfile_complaints
,
8239 _("Invalid .debug_ranges data "
8240 "(no base address)"));
8246 /* Inverted range entries are invalid. */
8247 complaint (&symfile_complaints
,
8248 _("Invalid .debug_ranges data "
8249 "(inverted range)"));
8253 /* Empty range entries have no effect. */
8257 record_block_range (block
,
8258 baseaddr
+ base
+ start
,
8259 baseaddr
+ base
+ end
- 1);
8265 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
8266 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
8267 during 4.6.0 experimental. */
8270 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
8273 int major
, minor
, release
;
8276 if (cu
->producer
== NULL
)
8278 /* For unknown compilers expect their behavior is DWARF version
8281 GCC started to support .debug_types sections by -gdwarf-4 since
8282 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
8283 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
8284 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
8285 interpreted incorrectly by GDB now - GCC PR debug/48229. */
8290 if (cu
->checked_producer
)
8291 return cu
->producer_is_gxx_lt_4_6
;
8293 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
8295 if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) != 0)
8297 /* For non-GCC compilers expect their behavior is DWARF version
8302 cs
= &cu
->producer
[strlen ("GNU ")];
8303 while (*cs
&& !isdigit (*cs
))
8305 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
8307 /* Not recognized as GCC. */
8310 result
= major
< 4 || (major
== 4 && minor
< 6);
8313 cu
->checked_producer
= 1;
8314 cu
->producer_is_gxx_lt_4_6
= result
;
8319 /* Return the default accessibility type if it is not overriden by
8320 DW_AT_accessibility. */
8322 static enum dwarf_access_attribute
8323 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
8325 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
8327 /* The default DWARF 2 accessibility for members is public, the default
8328 accessibility for inheritance is private. */
8330 if (die
->tag
!= DW_TAG_inheritance
)
8331 return DW_ACCESS_public
;
8333 return DW_ACCESS_private
;
8337 /* DWARF 3+ defines the default accessibility a different way. The same
8338 rules apply now for DW_TAG_inheritance as for the members and it only
8339 depends on the container kind. */
8341 if (die
->parent
->tag
== DW_TAG_class_type
)
8342 return DW_ACCESS_private
;
8344 return DW_ACCESS_public
;
8348 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
8349 offset. If the attribute was not found return 0, otherwise return
8350 1. If it was found but could not properly be handled, set *OFFSET
8354 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
8357 struct attribute
*attr
;
8359 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
8364 /* Note that we do not check for a section offset first here.
8365 This is because DW_AT_data_member_location is new in DWARF 4,
8366 so if we see it, we can assume that a constant form is really
8367 a constant and not a section offset. */
8368 if (attr_form_is_constant (attr
))
8369 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
8370 else if (attr_form_is_section_offset (attr
))
8371 dwarf2_complex_location_expr_complaint ();
8372 else if (attr_form_is_block (attr
))
8373 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
8375 dwarf2_complex_location_expr_complaint ();
8383 /* Add an aggregate field to the field list. */
8386 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
8387 struct dwarf2_cu
*cu
)
8389 struct objfile
*objfile
= cu
->objfile
;
8390 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8391 struct nextfield
*new_field
;
8392 struct attribute
*attr
;
8394 char *fieldname
= "";
8396 /* Allocate a new field list entry and link it in. */
8397 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
8398 make_cleanup (xfree
, new_field
);
8399 memset (new_field
, 0, sizeof (struct nextfield
));
8401 if (die
->tag
== DW_TAG_inheritance
)
8403 new_field
->next
= fip
->baseclasses
;
8404 fip
->baseclasses
= new_field
;
8408 new_field
->next
= fip
->fields
;
8409 fip
->fields
= new_field
;
8413 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
8415 new_field
->accessibility
= DW_UNSND (attr
);
8417 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
8418 if (new_field
->accessibility
!= DW_ACCESS_public
)
8419 fip
->non_public_fields
= 1;
8421 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
8423 new_field
->virtuality
= DW_UNSND (attr
);
8425 new_field
->virtuality
= DW_VIRTUALITY_none
;
8427 fp
= &new_field
->field
;
8429 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
8433 /* Data member other than a C++ static data member. */
8435 /* Get type of field. */
8436 fp
->type
= die_type (die
, cu
);
8438 SET_FIELD_BITPOS (*fp
, 0);
8440 /* Get bit size of field (zero if none). */
8441 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
8444 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
8448 FIELD_BITSIZE (*fp
) = 0;
8451 /* Get bit offset of field. */
8452 if (handle_data_member_location (die
, cu
, &offset
))
8453 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
8454 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
8457 if (gdbarch_bits_big_endian (gdbarch
))
8459 /* For big endian bits, the DW_AT_bit_offset gives the
8460 additional bit offset from the MSB of the containing
8461 anonymous object to the MSB of the field. We don't
8462 have to do anything special since we don't need to
8463 know the size of the anonymous object. */
8464 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
8468 /* For little endian bits, compute the bit offset to the
8469 MSB of the anonymous object, subtract off the number of
8470 bits from the MSB of the field to the MSB of the
8471 object, and then subtract off the number of bits of
8472 the field itself. The result is the bit offset of
8473 the LSB of the field. */
8475 int bit_offset
= DW_UNSND (attr
);
8477 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8480 /* The size of the anonymous object containing
8481 the bit field is explicit, so use the
8482 indicated size (in bytes). */
8483 anonymous_size
= DW_UNSND (attr
);
8487 /* The size of the anonymous object containing
8488 the bit field must be inferred from the type
8489 attribute of the data member containing the
8491 anonymous_size
= TYPE_LENGTH (fp
->type
);
8493 SET_FIELD_BITPOS (*fp
,
8495 + anonymous_size
* bits_per_byte
8496 - bit_offset
- FIELD_BITSIZE (*fp
)));
8500 /* Get name of field. */
8501 fieldname
= dwarf2_name (die
, cu
);
8502 if (fieldname
== NULL
)
8505 /* The name is already allocated along with this objfile, so we don't
8506 need to duplicate it for the type. */
8507 fp
->name
= fieldname
;
8509 /* Change accessibility for artificial fields (e.g. virtual table
8510 pointer or virtual base class pointer) to private. */
8511 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
8513 FIELD_ARTIFICIAL (*fp
) = 1;
8514 new_field
->accessibility
= DW_ACCESS_private
;
8515 fip
->non_public_fields
= 1;
8518 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
8520 /* C++ static member. */
8522 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
8523 is a declaration, but all versions of G++ as of this writing
8524 (so through at least 3.2.1) incorrectly generate
8525 DW_TAG_variable tags. */
8527 const char *physname
;
8529 /* Get name of field. */
8530 fieldname
= dwarf2_name (die
, cu
);
8531 if (fieldname
== NULL
)
8534 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
8536 /* Only create a symbol if this is an external value.
8537 new_symbol checks this and puts the value in the global symbol
8538 table, which we want. If it is not external, new_symbol
8539 will try to put the value in cu->list_in_scope which is wrong. */
8540 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
8542 /* A static const member, not much different than an enum as far as
8543 we're concerned, except that we can support more types. */
8544 new_symbol (die
, NULL
, cu
);
8547 /* Get physical name. */
8548 physname
= dwarf2_physname (fieldname
, die
, cu
);
8550 /* The name is already allocated along with this objfile, so we don't
8551 need to duplicate it for the type. */
8552 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
8553 FIELD_TYPE (*fp
) = die_type (die
, cu
);
8554 FIELD_NAME (*fp
) = fieldname
;
8556 else if (die
->tag
== DW_TAG_inheritance
)
8560 /* C++ base class field. */
8561 if (handle_data_member_location (die
, cu
, &offset
))
8562 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
8563 FIELD_BITSIZE (*fp
) = 0;
8564 FIELD_TYPE (*fp
) = die_type (die
, cu
);
8565 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
8566 fip
->nbaseclasses
++;
8570 /* Add a typedef defined in the scope of the FIP's class. */
8573 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
8574 struct dwarf2_cu
*cu
)
8576 struct objfile
*objfile
= cu
->objfile
;
8577 struct typedef_field_list
*new_field
;
8578 struct attribute
*attr
;
8579 struct typedef_field
*fp
;
8580 char *fieldname
= "";
8582 /* Allocate a new field list entry and link it in. */
8583 new_field
= xzalloc (sizeof (*new_field
));
8584 make_cleanup (xfree
, new_field
);
8586 gdb_assert (die
->tag
== DW_TAG_typedef
);
8588 fp
= &new_field
->field
;
8590 /* Get name of field. */
8591 fp
->name
= dwarf2_name (die
, cu
);
8592 if (fp
->name
== NULL
)
8595 fp
->type
= read_type_die (die
, cu
);
8597 new_field
->next
= fip
->typedef_field_list
;
8598 fip
->typedef_field_list
= new_field
;
8599 fip
->typedef_field_list_count
++;
8602 /* Create the vector of fields, and attach it to the type. */
8605 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
8606 struct dwarf2_cu
*cu
)
8608 int nfields
= fip
->nfields
;
8610 /* Record the field count, allocate space for the array of fields,
8611 and create blank accessibility bitfields if necessary. */
8612 TYPE_NFIELDS (type
) = nfields
;
8613 TYPE_FIELDS (type
) = (struct field
*)
8614 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
8615 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
8617 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
8619 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
8621 TYPE_FIELD_PRIVATE_BITS (type
) =
8622 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
8623 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
8625 TYPE_FIELD_PROTECTED_BITS (type
) =
8626 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
8627 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
8629 TYPE_FIELD_IGNORE_BITS (type
) =
8630 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
8631 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
8634 /* If the type has baseclasses, allocate and clear a bit vector for
8635 TYPE_FIELD_VIRTUAL_BITS. */
8636 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
8638 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
8639 unsigned char *pointer
;
8641 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
8642 pointer
= TYPE_ALLOC (type
, num_bytes
);
8643 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
8644 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
8645 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
8648 /* Copy the saved-up fields into the field vector. Start from the head of
8649 the list, adding to the tail of the field array, so that they end up in
8650 the same order in the array in which they were added to the list. */
8651 while (nfields
-- > 0)
8653 struct nextfield
*fieldp
;
8657 fieldp
= fip
->fields
;
8658 fip
->fields
= fieldp
->next
;
8662 fieldp
= fip
->baseclasses
;
8663 fip
->baseclasses
= fieldp
->next
;
8666 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
8667 switch (fieldp
->accessibility
)
8669 case DW_ACCESS_private
:
8670 if (cu
->language
!= language_ada
)
8671 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
8674 case DW_ACCESS_protected
:
8675 if (cu
->language
!= language_ada
)
8676 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
8679 case DW_ACCESS_public
:
8683 /* Unknown accessibility. Complain and treat it as public. */
8685 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
8686 fieldp
->accessibility
);
8690 if (nfields
< fip
->nbaseclasses
)
8692 switch (fieldp
->virtuality
)
8694 case DW_VIRTUALITY_virtual
:
8695 case DW_VIRTUALITY_pure_virtual
:
8696 if (cu
->language
== language_ada
)
8697 error (_("unexpected virtuality in component of Ada type"));
8698 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
8705 /* Add a member function to the proper fieldlist. */
8708 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
8709 struct type
*type
, struct dwarf2_cu
*cu
)
8711 struct objfile
*objfile
= cu
->objfile
;
8712 struct attribute
*attr
;
8713 struct fnfieldlist
*flp
;
8715 struct fn_field
*fnp
;
8717 struct nextfnfield
*new_fnfield
;
8718 struct type
*this_type
;
8719 enum dwarf_access_attribute accessibility
;
8721 if (cu
->language
== language_ada
)
8722 error (_("unexpected member function in Ada type"));
8724 /* Get name of member function. */
8725 fieldname
= dwarf2_name (die
, cu
);
8726 if (fieldname
== NULL
)
8729 /* Look up member function name in fieldlist. */
8730 for (i
= 0; i
< fip
->nfnfields
; i
++)
8732 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
8736 /* Create new list element if necessary. */
8737 if (i
< fip
->nfnfields
)
8738 flp
= &fip
->fnfieldlists
[i
];
8741 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
8743 fip
->fnfieldlists
= (struct fnfieldlist
*)
8744 xrealloc (fip
->fnfieldlists
,
8745 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
8746 * sizeof (struct fnfieldlist
));
8747 if (fip
->nfnfields
== 0)
8748 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
8750 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
8751 flp
->name
= fieldname
;
8754 i
= fip
->nfnfields
++;
8757 /* Create a new member function field and chain it to the field list
8759 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
8760 make_cleanup (xfree
, new_fnfield
);
8761 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
8762 new_fnfield
->next
= flp
->head
;
8763 flp
->head
= new_fnfield
;
8766 /* Fill in the member function field info. */
8767 fnp
= &new_fnfield
->fnfield
;
8769 /* Delay processing of the physname until later. */
8770 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
8772 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
8777 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
8778 fnp
->physname
= physname
? physname
: "";
8781 fnp
->type
= alloc_type (objfile
);
8782 this_type
= read_type_die (die
, cu
);
8783 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
8785 int nparams
= TYPE_NFIELDS (this_type
);
8787 /* TYPE is the domain of this method, and THIS_TYPE is the type
8788 of the method itself (TYPE_CODE_METHOD). */
8789 smash_to_method_type (fnp
->type
, type
,
8790 TYPE_TARGET_TYPE (this_type
),
8791 TYPE_FIELDS (this_type
),
8792 TYPE_NFIELDS (this_type
),
8793 TYPE_VARARGS (this_type
));
8795 /* Handle static member functions.
8796 Dwarf2 has no clean way to discern C++ static and non-static
8797 member functions. G++ helps GDB by marking the first
8798 parameter for non-static member functions (which is the this
8799 pointer) as artificial. We obtain this information from
8800 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
8801 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
8802 fnp
->voffset
= VOFFSET_STATIC
;
8805 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
8806 dwarf2_full_name (fieldname
, die
, cu
));
8808 /* Get fcontext from DW_AT_containing_type if present. */
8809 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
8810 fnp
->fcontext
= die_containing_type (die
, cu
);
8812 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
8813 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
8815 /* Get accessibility. */
8816 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
8818 accessibility
= DW_UNSND (attr
);
8820 accessibility
= dwarf2_default_access_attribute (die
, cu
);
8821 switch (accessibility
)
8823 case DW_ACCESS_private
:
8824 fnp
->is_private
= 1;
8826 case DW_ACCESS_protected
:
8827 fnp
->is_protected
= 1;
8831 /* Check for artificial methods. */
8832 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
8833 if (attr
&& DW_UNSND (attr
) != 0)
8834 fnp
->is_artificial
= 1;
8836 /* Get index in virtual function table if it is a virtual member
8837 function. For older versions of GCC, this is an offset in the
8838 appropriate virtual table, as specified by DW_AT_containing_type.
8839 For everyone else, it is an expression to be evaluated relative
8840 to the object address. */
8842 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
8845 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
8847 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
8849 /* Old-style GCC. */
8850 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
8852 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
8853 || (DW_BLOCK (attr
)->size
> 1
8854 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
8855 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
8857 struct dwarf_block blk
;
8860 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
8862 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
8863 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
8864 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
8865 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
8866 dwarf2_complex_location_expr_complaint ();
8868 fnp
->voffset
/= cu
->header
.addr_size
;
8872 dwarf2_complex_location_expr_complaint ();
8875 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
8877 else if (attr_form_is_section_offset (attr
))
8879 dwarf2_complex_location_expr_complaint ();
8883 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
8889 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
8890 if (attr
&& DW_UNSND (attr
))
8892 /* GCC does this, as of 2008-08-25; PR debug/37237. */
8893 complaint (&symfile_complaints
,
8894 _("Member function \"%s\" (offset %d) is virtual "
8895 "but the vtable offset is not specified"),
8896 fieldname
, die
->offset
.sect_off
);
8897 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
8898 TYPE_CPLUS_DYNAMIC (type
) = 1;
8903 /* Create the vector of member function fields, and attach it to the type. */
8906 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
8907 struct dwarf2_cu
*cu
)
8909 struct fnfieldlist
*flp
;
8912 if (cu
->language
== language_ada
)
8913 error (_("unexpected member functions in Ada type"));
8915 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
8916 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
8917 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
8919 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
8921 struct nextfnfield
*nfp
= flp
->head
;
8922 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
8925 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
8926 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
8927 fn_flp
->fn_fields
= (struct fn_field
*)
8928 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
8929 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
8930 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
8933 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
8936 /* Returns non-zero if NAME is the name of a vtable member in CU's
8937 language, zero otherwise. */
8939 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
8941 static const char vptr
[] = "_vptr";
8942 static const char vtable
[] = "vtable";
8944 /* Look for the C++ and Java forms of the vtable. */
8945 if ((cu
->language
== language_java
8946 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
8947 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
8948 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
8954 /* GCC outputs unnamed structures that are really pointers to member
8955 functions, with the ABI-specified layout. If TYPE describes
8956 such a structure, smash it into a member function type.
8958 GCC shouldn't do this; it should just output pointer to member DIEs.
8959 This is GCC PR debug/28767. */
8962 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
8964 struct type
*pfn_type
, *domain_type
, *new_type
;
8966 /* Check for a structure with no name and two children. */
8967 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
8970 /* Check for __pfn and __delta members. */
8971 if (TYPE_FIELD_NAME (type
, 0) == NULL
8972 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
8973 || TYPE_FIELD_NAME (type
, 1) == NULL
8974 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
8977 /* Find the type of the method. */
8978 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
8979 if (pfn_type
== NULL
8980 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
8981 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
8984 /* Look for the "this" argument. */
8985 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
8986 if (TYPE_NFIELDS (pfn_type
) == 0
8987 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
8988 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
8991 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
8992 new_type
= alloc_type (objfile
);
8993 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
8994 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
8995 TYPE_VARARGS (pfn_type
));
8996 smash_to_methodptr_type (type
, new_type
);
8999 /* Called when we find the DIE that starts a structure or union scope
9000 (definition) to create a type for the structure or union. Fill in
9001 the type's name and general properties; the members will not be
9002 processed until process_structure_type.
9004 NOTE: we need to call these functions regardless of whether or not the
9005 DIE has a DW_AT_name attribute, since it might be an anonymous
9006 structure or union. This gets the type entered into our set of
9009 However, if the structure is incomplete (an opaque struct/union)
9010 then suppress creating a symbol table entry for it since gdb only
9011 wants to find the one with the complete definition. Note that if
9012 it is complete, we just call new_symbol, which does it's own
9013 checking about whether the struct/union is anonymous or not (and
9014 suppresses creating a symbol table entry itself). */
9016 static struct type
*
9017 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9019 struct objfile
*objfile
= cu
->objfile
;
9021 struct attribute
*attr
;
9024 /* If the definition of this type lives in .debug_types, read that type.
9025 Don't follow DW_AT_specification though, that will take us back up
9026 the chain and we want to go down. */
9027 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
9030 struct dwarf2_cu
*type_cu
= cu
;
9031 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
9033 /* We could just recurse on read_structure_type, but we need to call
9034 get_die_type to ensure only one type for this DIE is created.
9035 This is important, for example, because for c++ classes we need
9036 TYPE_NAME set which is only done by new_symbol. Blech. */
9037 type
= read_type_die (type_die
, type_cu
);
9039 /* TYPE_CU may not be the same as CU.
9040 Ensure TYPE is recorded in CU's type_hash table. */
9041 return set_die_type (die
, type
, cu
);
9044 type
= alloc_type (objfile
);
9045 INIT_CPLUS_SPECIFIC (type
);
9047 name
= dwarf2_name (die
, cu
);
9050 if (cu
->language
== language_cplus
9051 || cu
->language
== language_java
)
9053 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
9055 /* dwarf2_full_name might have already finished building the DIE's
9056 type. If so, there is no need to continue. */
9057 if (get_die_type (die
, cu
) != NULL
)
9058 return get_die_type (die
, cu
);
9060 TYPE_TAG_NAME (type
) = full_name
;
9061 if (die
->tag
== DW_TAG_structure_type
9062 || die
->tag
== DW_TAG_class_type
)
9063 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
9067 /* The name is already allocated along with this objfile, so
9068 we don't need to duplicate it for the type. */
9069 TYPE_TAG_NAME (type
) = (char *) name
;
9070 if (die
->tag
== DW_TAG_class_type
)
9071 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
9075 if (die
->tag
== DW_TAG_structure_type
)
9077 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9079 else if (die
->tag
== DW_TAG_union_type
)
9081 TYPE_CODE (type
) = TYPE_CODE_UNION
;
9085 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
9088 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
9089 TYPE_DECLARED_CLASS (type
) = 1;
9091 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9094 TYPE_LENGTH (type
) = DW_UNSND (attr
);
9098 TYPE_LENGTH (type
) = 0;
9101 TYPE_STUB_SUPPORTED (type
) = 1;
9102 if (die_is_declaration (die
, cu
))
9103 TYPE_STUB (type
) = 1;
9104 else if (attr
== NULL
&& die
->child
== NULL
9105 && producer_is_realview (cu
->producer
))
9106 /* RealView does not output the required DW_AT_declaration
9107 on incomplete types. */
9108 TYPE_STUB (type
) = 1;
9110 /* We need to add the type field to the die immediately so we don't
9111 infinitely recurse when dealing with pointers to the structure
9112 type within the structure itself. */
9113 set_die_type (die
, type
, cu
);
9115 /* set_die_type should be already done. */
9116 set_descriptive_type (type
, die
, cu
);
9121 /* Finish creating a structure or union type, including filling in
9122 its members and creating a symbol for it. */
9125 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9127 struct objfile
*objfile
= cu
->objfile
;
9128 struct die_info
*child_die
= die
->child
;
9131 type
= get_die_type (die
, cu
);
9133 type
= read_structure_type (die
, cu
);
9135 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
9137 struct field_info fi
;
9138 struct die_info
*child_die
;
9139 VEC (symbolp
) *template_args
= NULL
;
9140 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
9142 memset (&fi
, 0, sizeof (struct field_info
));
9144 child_die
= die
->child
;
9146 while (child_die
&& child_die
->tag
)
9148 if (child_die
->tag
== DW_TAG_member
9149 || child_die
->tag
== DW_TAG_variable
)
9151 /* NOTE: carlton/2002-11-05: A C++ static data member
9152 should be a DW_TAG_member that is a declaration, but
9153 all versions of G++ as of this writing (so through at
9154 least 3.2.1) incorrectly generate DW_TAG_variable
9155 tags for them instead. */
9156 dwarf2_add_field (&fi
, child_die
, cu
);
9158 else if (child_die
->tag
== DW_TAG_subprogram
)
9160 /* C++ member function. */
9161 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
9163 else if (child_die
->tag
== DW_TAG_inheritance
)
9165 /* C++ base class field. */
9166 dwarf2_add_field (&fi
, child_die
, cu
);
9168 else if (child_die
->tag
== DW_TAG_typedef
)
9169 dwarf2_add_typedef (&fi
, child_die
, cu
);
9170 else if (child_die
->tag
== DW_TAG_template_type_param
9171 || child_die
->tag
== DW_TAG_template_value_param
)
9173 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
9176 VEC_safe_push (symbolp
, template_args
, arg
);
9179 child_die
= sibling_die (child_die
);
9182 /* Attach template arguments to type. */
9183 if (! VEC_empty (symbolp
, template_args
))
9185 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9186 TYPE_N_TEMPLATE_ARGUMENTS (type
)
9187 = VEC_length (symbolp
, template_args
);
9188 TYPE_TEMPLATE_ARGUMENTS (type
)
9189 = obstack_alloc (&objfile
->objfile_obstack
,
9190 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
9191 * sizeof (struct symbol
*)));
9192 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
9193 VEC_address (symbolp
, template_args
),
9194 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
9195 * sizeof (struct symbol
*)));
9196 VEC_free (symbolp
, template_args
);
9199 /* Attach fields and member functions to the type. */
9201 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
9204 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
9206 /* Get the type which refers to the base class (possibly this
9207 class itself) which contains the vtable pointer for the current
9208 class from the DW_AT_containing_type attribute. This use of
9209 DW_AT_containing_type is a GNU extension. */
9211 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
9213 struct type
*t
= die_containing_type (die
, cu
);
9215 TYPE_VPTR_BASETYPE (type
) = t
;
9220 /* Our own class provides vtbl ptr. */
9221 for (i
= TYPE_NFIELDS (t
) - 1;
9222 i
>= TYPE_N_BASECLASSES (t
);
9225 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
9227 if (is_vtable_name (fieldname
, cu
))
9229 TYPE_VPTR_FIELDNO (type
) = i
;
9234 /* Complain if virtual function table field not found. */
9235 if (i
< TYPE_N_BASECLASSES (t
))
9236 complaint (&symfile_complaints
,
9237 _("virtual function table pointer "
9238 "not found when defining class '%s'"),
9239 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
9244 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
9247 else if (cu
->producer
9248 && strncmp (cu
->producer
,
9249 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
9251 /* The IBM XLC compiler does not provide direct indication
9252 of the containing type, but the vtable pointer is
9253 always named __vfp. */
9257 for (i
= TYPE_NFIELDS (type
) - 1;
9258 i
>= TYPE_N_BASECLASSES (type
);
9261 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
9263 TYPE_VPTR_FIELDNO (type
) = i
;
9264 TYPE_VPTR_BASETYPE (type
) = type
;
9271 /* Copy fi.typedef_field_list linked list elements content into the
9272 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
9273 if (fi
.typedef_field_list
)
9275 int i
= fi
.typedef_field_list_count
;
9277 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9278 TYPE_TYPEDEF_FIELD_ARRAY (type
)
9279 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
9280 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
9282 /* Reverse the list order to keep the debug info elements order. */
9285 struct typedef_field
*dest
, *src
;
9287 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
9288 src
= &fi
.typedef_field_list
->field
;
9289 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
9294 do_cleanups (back_to
);
9296 if (HAVE_CPLUS_STRUCT (type
))
9297 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
9300 quirk_gcc_member_function_pointer (type
, objfile
);
9302 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
9303 snapshots) has been known to create a die giving a declaration
9304 for a class that has, as a child, a die giving a definition for a
9305 nested class. So we have to process our children even if the
9306 current die is a declaration. Normally, of course, a declaration
9307 won't have any children at all. */
9309 while (child_die
!= NULL
&& child_die
->tag
)
9311 if (child_die
->tag
== DW_TAG_member
9312 || child_die
->tag
== DW_TAG_variable
9313 || child_die
->tag
== DW_TAG_inheritance
9314 || child_die
->tag
== DW_TAG_template_value_param
9315 || child_die
->tag
== DW_TAG_template_type_param
)
9320 process_die (child_die
, cu
);
9322 child_die
= sibling_die (child_die
);
9325 /* Do not consider external references. According to the DWARF standard,
9326 these DIEs are identified by the fact that they have no byte_size
9327 attribute, and a declaration attribute. */
9328 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
9329 || !die_is_declaration (die
, cu
))
9330 new_symbol (die
, type
, cu
);
9333 /* Given a DW_AT_enumeration_type die, set its type. We do not
9334 complete the type's fields yet, or create any symbols. */
9336 static struct type
*
9337 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9339 struct objfile
*objfile
= cu
->objfile
;
9341 struct attribute
*attr
;
9344 /* If the definition of this type lives in .debug_types, read that type.
9345 Don't follow DW_AT_specification though, that will take us back up
9346 the chain and we want to go down. */
9347 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
9350 struct dwarf2_cu
*type_cu
= cu
;
9351 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
9353 type
= read_type_die (type_die
, type_cu
);
9355 /* TYPE_CU may not be the same as CU.
9356 Ensure TYPE is recorded in CU's type_hash table. */
9357 return set_die_type (die
, type
, cu
);
9360 type
= alloc_type (objfile
);
9362 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
9363 name
= dwarf2_full_name (NULL
, die
, cu
);
9365 TYPE_TAG_NAME (type
) = (char *) name
;
9367 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9370 TYPE_LENGTH (type
) = DW_UNSND (attr
);
9374 TYPE_LENGTH (type
) = 0;
9377 /* The enumeration DIE can be incomplete. In Ada, any type can be
9378 declared as private in the package spec, and then defined only
9379 inside the package body. Such types are known as Taft Amendment
9380 Types. When another package uses such a type, an incomplete DIE
9381 may be generated by the compiler. */
9382 if (die_is_declaration (die
, cu
))
9383 TYPE_STUB (type
) = 1;
9385 return set_die_type (die
, type
, cu
);
9388 /* Given a pointer to a die which begins an enumeration, process all
9389 the dies that define the members of the enumeration, and create the
9390 symbol for the enumeration type.
9392 NOTE: We reverse the order of the element list. */
9395 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9397 struct type
*this_type
;
9399 this_type
= get_die_type (die
, cu
);
9400 if (this_type
== NULL
)
9401 this_type
= read_enumeration_type (die
, cu
);
9403 if (die
->child
!= NULL
)
9405 struct die_info
*child_die
;
9407 struct field
*fields
= NULL
;
9409 int unsigned_enum
= 1;
9414 child_die
= die
->child
;
9415 while (child_die
&& child_die
->tag
)
9417 if (child_die
->tag
!= DW_TAG_enumerator
)
9419 process_die (child_die
, cu
);
9423 name
= dwarf2_name (child_die
, cu
);
9426 sym
= new_symbol (child_die
, this_type
, cu
);
9427 if (SYMBOL_VALUE (sym
) < 0)
9432 else if ((mask
& SYMBOL_VALUE (sym
)) != 0)
9435 mask
|= SYMBOL_VALUE (sym
);
9437 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
9439 fields
= (struct field
*)
9441 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
9442 * sizeof (struct field
));
9445 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
9446 FIELD_TYPE (fields
[num_fields
]) = NULL
;
9447 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
9448 FIELD_BITSIZE (fields
[num_fields
]) = 0;
9454 child_die
= sibling_die (child_die
);
9459 TYPE_NFIELDS (this_type
) = num_fields
;
9460 TYPE_FIELDS (this_type
) = (struct field
*)
9461 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
9462 memcpy (TYPE_FIELDS (this_type
), fields
,
9463 sizeof (struct field
) * num_fields
);
9467 TYPE_UNSIGNED (this_type
) = 1;
9469 TYPE_FLAG_ENUM (this_type
) = 1;
9472 /* If we are reading an enum from a .debug_types unit, and the enum
9473 is a declaration, and the enum is not the signatured type in the
9474 unit, then we do not want to add a symbol for it. Adding a
9475 symbol would in some cases obscure the true definition of the
9476 enum, giving users an incomplete type when the definition is
9477 actually available. Note that we do not want to do this for all
9478 enums which are just declarations, because C++0x allows forward
9479 enum declarations. */
9480 if (cu
->per_cu
->is_debug_types
9481 && die_is_declaration (die
, cu
))
9483 struct signatured_type
*sig_type
;
9486 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
9487 cu
->per_cu
->info_or_types_section
,
9488 cu
->per_cu
->offset
);
9489 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
9490 if (sig_type
->type_offset_in_section
.sect_off
!= die
->offset
.sect_off
)
9494 new_symbol (die
, this_type
, cu
);
9497 /* Extract all information from a DW_TAG_array_type DIE and put it in
9498 the DIE's type field. For now, this only handles one dimensional
9501 static struct type
*
9502 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9504 struct objfile
*objfile
= cu
->objfile
;
9505 struct die_info
*child_die
;
9507 struct type
*element_type
, *range_type
, *index_type
;
9508 struct type
**range_types
= NULL
;
9509 struct attribute
*attr
;
9511 struct cleanup
*back_to
;
9514 element_type
= die_type (die
, cu
);
9516 /* The die_type call above may have already set the type for this DIE. */
9517 type
= get_die_type (die
, cu
);
9521 /* Irix 6.2 native cc creates array types without children for
9522 arrays with unspecified length. */
9523 if (die
->child
== NULL
)
9525 index_type
= objfile_type (objfile
)->builtin_int
;
9526 range_type
= create_range_type (NULL
, index_type
, 0, -1);
9527 type
= create_array_type (NULL
, element_type
, range_type
);
9528 return set_die_type (die
, type
, cu
);
9531 back_to
= make_cleanup (null_cleanup
, NULL
);
9532 child_die
= die
->child
;
9533 while (child_die
&& child_die
->tag
)
9535 if (child_die
->tag
== DW_TAG_subrange_type
)
9537 struct type
*child_type
= read_type_die (child_die
, cu
);
9539 if (child_type
!= NULL
)
9541 /* The range type was succesfully read. Save it for the
9542 array type creation. */
9543 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
9545 range_types
= (struct type
**)
9546 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
9547 * sizeof (struct type
*));
9549 make_cleanup (free_current_contents
, &range_types
);
9551 range_types
[ndim
++] = child_type
;
9554 child_die
= sibling_die (child_die
);
9557 /* Dwarf2 dimensions are output from left to right, create the
9558 necessary array types in backwards order. */
9560 type
= element_type
;
9562 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
9567 type
= create_array_type (NULL
, type
, range_types
[i
++]);
9572 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
9575 /* Understand Dwarf2 support for vector types (like they occur on
9576 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
9577 array type. This is not part of the Dwarf2/3 standard yet, but a
9578 custom vendor extension. The main difference between a regular
9579 array and the vector variant is that vectors are passed by value
9581 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
9583 make_vector_type (type
);
9585 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
9586 implementation may choose to implement triple vectors using this
9588 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9591 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
9592 TYPE_LENGTH (type
) = DW_UNSND (attr
);
9594 complaint (&symfile_complaints
,
9595 _("DW_AT_byte_size for array type smaller "
9596 "than the total size of elements"));
9599 name
= dwarf2_name (die
, cu
);
9601 TYPE_NAME (type
) = name
;
9603 /* Install the type in the die. */
9604 set_die_type (die
, type
, cu
);
9606 /* set_die_type should be already done. */
9607 set_descriptive_type (type
, die
, cu
);
9609 do_cleanups (back_to
);
9614 static enum dwarf_array_dim_ordering
9615 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
9617 struct attribute
*attr
;
9619 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
9621 if (attr
) return DW_SND (attr
);
9623 /* GNU F77 is a special case, as at 08/2004 array type info is the
9624 opposite order to the dwarf2 specification, but data is still
9625 laid out as per normal fortran.
9627 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
9628 version checking. */
9630 if (cu
->language
== language_fortran
9631 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
9633 return DW_ORD_row_major
;
9636 switch (cu
->language_defn
->la_array_ordering
)
9638 case array_column_major
:
9639 return DW_ORD_col_major
;
9640 case array_row_major
:
9642 return DW_ORD_row_major
;
9646 /* Extract all information from a DW_TAG_set_type DIE and put it in
9647 the DIE's type field. */
9649 static struct type
*
9650 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9652 struct type
*domain_type
, *set_type
;
9653 struct attribute
*attr
;
9655 domain_type
= die_type (die
, cu
);
9657 /* The die_type call above may have already set the type for this DIE. */
9658 set_type
= get_die_type (die
, cu
);
9662 set_type
= create_set_type (NULL
, domain_type
);
9664 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9666 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
9668 return set_die_type (die
, set_type
, cu
);
9671 /* First cut: install each common block member as a global variable. */
9674 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
9676 struct die_info
*child_die
;
9677 struct attribute
*attr
;
9679 CORE_ADDR base
= (CORE_ADDR
) 0;
9681 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
9684 /* Support the .debug_loc offsets. */
9685 if (attr_form_is_block (attr
))
9687 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
9689 else if (attr_form_is_section_offset (attr
))
9691 dwarf2_complex_location_expr_complaint ();
9695 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9696 "common block member");
9699 if (die
->child
!= NULL
)
9701 child_die
= die
->child
;
9702 while (child_die
&& child_die
->tag
)
9706 sym
= new_symbol (child_die
, NULL
, cu
);
9708 && handle_data_member_location (child_die
, cu
, &offset
))
9710 SYMBOL_VALUE_ADDRESS (sym
) = base
+ offset
;
9711 add_symbol_to_list (sym
, &global_symbols
);
9713 child_die
= sibling_die (child_die
);
9718 /* Create a type for a C++ namespace. */
9720 static struct type
*
9721 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9723 struct objfile
*objfile
= cu
->objfile
;
9724 const char *previous_prefix
, *name
;
9728 /* For extensions, reuse the type of the original namespace. */
9729 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
9731 struct die_info
*ext_die
;
9732 struct dwarf2_cu
*ext_cu
= cu
;
9734 ext_die
= dwarf2_extension (die
, &ext_cu
);
9735 type
= read_type_die (ext_die
, ext_cu
);
9737 /* EXT_CU may not be the same as CU.
9738 Ensure TYPE is recorded in CU's type_hash table. */
9739 return set_die_type (die
, type
, cu
);
9742 name
= namespace_name (die
, &is_anonymous
, cu
);
9744 /* Now build the name of the current namespace. */
9746 previous_prefix
= determine_prefix (die
, cu
);
9747 if (previous_prefix
[0] != '\0')
9748 name
= typename_concat (&objfile
->objfile_obstack
,
9749 previous_prefix
, name
, 0, cu
);
9751 /* Create the type. */
9752 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
9754 TYPE_NAME (type
) = (char *) name
;
9755 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
9757 return set_die_type (die
, type
, cu
);
9760 /* Read a C++ namespace. */
9763 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9765 struct objfile
*objfile
= cu
->objfile
;
9768 /* Add a symbol associated to this if we haven't seen the namespace
9769 before. Also, add a using directive if it's an anonymous
9772 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
9776 type
= read_type_die (die
, cu
);
9777 new_symbol (die
, type
, cu
);
9779 namespace_name (die
, &is_anonymous
, cu
);
9782 const char *previous_prefix
= determine_prefix (die
, cu
);
9784 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
9785 NULL
, NULL
, &objfile
->objfile_obstack
);
9789 if (die
->child
!= NULL
)
9791 struct die_info
*child_die
= die
->child
;
9793 while (child_die
&& child_die
->tag
)
9795 process_die (child_die
, cu
);
9796 child_die
= sibling_die (child_die
);
9801 /* Read a Fortran module as type. This DIE can be only a declaration used for
9802 imported module. Still we need that type as local Fortran "use ... only"
9803 declaration imports depend on the created type in determine_prefix. */
9805 static struct type
*
9806 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9808 struct objfile
*objfile
= cu
->objfile
;
9812 module_name
= dwarf2_name (die
, cu
);
9814 complaint (&symfile_complaints
,
9815 _("DW_TAG_module has no name, offset 0x%x"),
9816 die
->offset
.sect_off
);
9817 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
9819 /* determine_prefix uses TYPE_TAG_NAME. */
9820 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
9822 return set_die_type (die
, type
, cu
);
9825 /* Read a Fortran module. */
9828 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
9830 struct die_info
*child_die
= die
->child
;
9832 while (child_die
&& child_die
->tag
)
9834 process_die (child_die
, cu
);
9835 child_die
= sibling_die (child_die
);
9839 /* Return the name of the namespace represented by DIE. Set
9840 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
9844 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
9846 struct die_info
*current_die
;
9847 const char *name
= NULL
;
9849 /* Loop through the extensions until we find a name. */
9851 for (current_die
= die
;
9852 current_die
!= NULL
;
9853 current_die
= dwarf2_extension (die
, &cu
))
9855 name
= dwarf2_name (current_die
, cu
);
9860 /* Is it an anonymous namespace? */
9862 *is_anonymous
= (name
== NULL
);
9864 name
= CP_ANONYMOUS_NAMESPACE_STR
;
9869 /* Extract all information from a DW_TAG_pointer_type DIE and add to
9870 the user defined type vector. */
9872 static struct type
*
9873 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9875 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
9876 struct comp_unit_head
*cu_header
= &cu
->header
;
9878 struct attribute
*attr_byte_size
;
9879 struct attribute
*attr_address_class
;
9880 int byte_size
, addr_class
;
9881 struct type
*target_type
;
9883 target_type
= die_type (die
, cu
);
9885 /* The die_type call above may have already set the type for this DIE. */
9886 type
= get_die_type (die
, cu
);
9890 type
= lookup_pointer_type (target_type
);
9892 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9894 byte_size
= DW_UNSND (attr_byte_size
);
9896 byte_size
= cu_header
->addr_size
;
9898 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
9899 if (attr_address_class
)
9900 addr_class
= DW_UNSND (attr_address_class
);
9902 addr_class
= DW_ADDR_none
;
9904 /* If the pointer size or address class is different than the
9905 default, create a type variant marked as such and set the
9906 length accordingly. */
9907 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
9909 if (gdbarch_address_class_type_flags_p (gdbarch
))
9913 type_flags
= gdbarch_address_class_type_flags
9914 (gdbarch
, byte_size
, addr_class
);
9915 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
9917 type
= make_type_with_address_space (type
, type_flags
);
9919 else if (TYPE_LENGTH (type
) != byte_size
)
9921 complaint (&symfile_complaints
,
9922 _("invalid pointer size %d"), byte_size
);
9926 /* Should we also complain about unhandled address classes? */
9930 TYPE_LENGTH (type
) = byte_size
;
9931 return set_die_type (die
, type
, cu
);
9934 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
9935 the user defined type vector. */
9937 static struct type
*
9938 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9941 struct type
*to_type
;
9942 struct type
*domain
;
9944 to_type
= die_type (die
, cu
);
9945 domain
= die_containing_type (die
, cu
);
9947 /* The calls above may have already set the type for this DIE. */
9948 type
= get_die_type (die
, cu
);
9952 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
9953 type
= lookup_methodptr_type (to_type
);
9955 type
= lookup_memberptr_type (to_type
, domain
);
9957 return set_die_type (die
, type
, cu
);
9960 /* Extract all information from a DW_TAG_reference_type DIE and add to
9961 the user defined type vector. */
9963 static struct type
*
9964 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9966 struct comp_unit_head
*cu_header
= &cu
->header
;
9967 struct type
*type
, *target_type
;
9968 struct attribute
*attr
;
9970 target_type
= die_type (die
, cu
);
9972 /* The die_type call above may have already set the type for this DIE. */
9973 type
= get_die_type (die
, cu
);
9977 type
= lookup_reference_type (target_type
);
9978 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9981 TYPE_LENGTH (type
) = DW_UNSND (attr
);
9985 TYPE_LENGTH (type
) = cu_header
->addr_size
;
9987 return set_die_type (die
, type
, cu
);
9990 static struct type
*
9991 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9993 struct type
*base_type
, *cv_type
;
9995 base_type
= die_type (die
, cu
);
9997 /* The die_type call above may have already set the type for this DIE. */
9998 cv_type
= get_die_type (die
, cu
);
10002 /* In case the const qualifier is applied to an array type, the element type
10003 is so qualified, not the array type (section 6.7.3 of C99). */
10004 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
10006 struct type
*el_type
, *inner_array
;
10008 base_type
= copy_type (base_type
);
10009 inner_array
= base_type
;
10011 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
10013 TYPE_TARGET_TYPE (inner_array
) =
10014 copy_type (TYPE_TARGET_TYPE (inner_array
));
10015 inner_array
= TYPE_TARGET_TYPE (inner_array
);
10018 el_type
= TYPE_TARGET_TYPE (inner_array
);
10019 TYPE_TARGET_TYPE (inner_array
) =
10020 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
10022 return set_die_type (die
, base_type
, cu
);
10025 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
10026 return set_die_type (die
, cv_type
, cu
);
10029 static struct type
*
10030 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10032 struct type
*base_type
, *cv_type
;
10034 base_type
= die_type (die
, cu
);
10036 /* The die_type call above may have already set the type for this DIE. */
10037 cv_type
= get_die_type (die
, cu
);
10041 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
10042 return set_die_type (die
, cv_type
, cu
);
10045 /* Extract all information from a DW_TAG_string_type DIE and add to
10046 the user defined type vector. It isn't really a user defined type,
10047 but it behaves like one, with other DIE's using an AT_user_def_type
10048 attribute to reference it. */
10050 static struct type
*
10051 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10053 struct objfile
*objfile
= cu
->objfile
;
10054 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10055 struct type
*type
, *range_type
, *index_type
, *char_type
;
10056 struct attribute
*attr
;
10057 unsigned int length
;
10059 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
10062 length
= DW_UNSND (attr
);
10066 /* Check for the DW_AT_byte_size attribute. */
10067 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10070 length
= DW_UNSND (attr
);
10078 index_type
= objfile_type (objfile
)->builtin_int
;
10079 range_type
= create_range_type (NULL
, index_type
, 1, length
);
10080 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
10081 type
= create_string_type (NULL
, char_type
, range_type
);
10083 return set_die_type (die
, type
, cu
);
10086 /* Handle DIES due to C code like:
10090 int (*funcp)(int a, long l);
10094 ('funcp' generates a DW_TAG_subroutine_type DIE). */
10096 static struct type
*
10097 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10099 struct objfile
*objfile
= cu
->objfile
;
10100 struct type
*type
; /* Type that this function returns. */
10101 struct type
*ftype
; /* Function that returns above type. */
10102 struct attribute
*attr
;
10104 type
= die_type (die
, cu
);
10106 /* The die_type call above may have already set the type for this DIE. */
10107 ftype
= get_die_type (die
, cu
);
10111 ftype
= lookup_function_type (type
);
10113 /* All functions in C++, Pascal and Java have prototypes. */
10114 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
10115 if ((attr
&& (DW_UNSND (attr
) != 0))
10116 || cu
->language
== language_cplus
10117 || cu
->language
== language_java
10118 || cu
->language
== language_pascal
)
10119 TYPE_PROTOTYPED (ftype
) = 1;
10120 else if (producer_is_realview (cu
->producer
))
10121 /* RealView does not emit DW_AT_prototyped. We can not
10122 distinguish prototyped and unprototyped functions; default to
10123 prototyped, since that is more common in modern code (and
10124 RealView warns about unprototyped functions). */
10125 TYPE_PROTOTYPED (ftype
) = 1;
10127 /* Store the calling convention in the type if it's available in
10128 the subroutine die. Otherwise set the calling convention to
10129 the default value DW_CC_normal. */
10130 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
10132 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
10133 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
10134 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
10136 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
10138 /* We need to add the subroutine type to the die immediately so
10139 we don't infinitely recurse when dealing with parameters
10140 declared as the same subroutine type. */
10141 set_die_type (die
, ftype
, cu
);
10143 if (die
->child
!= NULL
)
10145 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
10146 struct die_info
*child_die
;
10147 int nparams
, iparams
;
10149 /* Count the number of parameters.
10150 FIXME: GDB currently ignores vararg functions, but knows about
10151 vararg member functions. */
10153 child_die
= die
->child
;
10154 while (child_die
&& child_die
->tag
)
10156 if (child_die
->tag
== DW_TAG_formal_parameter
)
10158 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
10159 TYPE_VARARGS (ftype
) = 1;
10160 child_die
= sibling_die (child_die
);
10163 /* Allocate storage for parameters and fill them in. */
10164 TYPE_NFIELDS (ftype
) = nparams
;
10165 TYPE_FIELDS (ftype
) = (struct field
*)
10166 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
10168 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
10169 even if we error out during the parameters reading below. */
10170 for (iparams
= 0; iparams
< nparams
; iparams
++)
10171 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
10174 child_die
= die
->child
;
10175 while (child_die
&& child_die
->tag
)
10177 if (child_die
->tag
== DW_TAG_formal_parameter
)
10179 struct type
*arg_type
;
10181 /* DWARF version 2 has no clean way to discern C++
10182 static and non-static member functions. G++ helps
10183 GDB by marking the first parameter for non-static
10184 member functions (which is the this pointer) as
10185 artificial. We pass this information to
10186 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
10188 DWARF version 3 added DW_AT_object_pointer, which GCC
10189 4.5 does not yet generate. */
10190 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
10192 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
10195 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
10197 /* GCC/43521: In java, the formal parameter
10198 "this" is sometimes not marked with DW_AT_artificial. */
10199 if (cu
->language
== language_java
)
10201 const char *name
= dwarf2_name (child_die
, cu
);
10203 if (name
&& !strcmp (name
, "this"))
10204 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
10207 arg_type
= die_type (child_die
, cu
);
10209 /* RealView does not mark THIS as const, which the testsuite
10210 expects. GCC marks THIS as const in method definitions,
10211 but not in the class specifications (GCC PR 43053). */
10212 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
10213 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
10216 struct dwarf2_cu
*arg_cu
= cu
;
10217 const char *name
= dwarf2_name (child_die
, cu
);
10219 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
10222 /* If the compiler emits this, use it. */
10223 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
10226 else if (name
&& strcmp (name
, "this") == 0)
10227 /* Function definitions will have the argument names. */
10229 else if (name
== NULL
&& iparams
== 0)
10230 /* Declarations may not have the names, so like
10231 elsewhere in GDB, assume an artificial first
10232 argument is "this". */
10236 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
10240 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
10243 child_die
= sibling_die (child_die
);
10250 static struct type
*
10251 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
10253 struct objfile
*objfile
= cu
->objfile
;
10254 const char *name
= NULL
;
10255 struct type
*this_type
, *target_type
;
10257 name
= dwarf2_full_name (NULL
, die
, cu
);
10258 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
10259 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
10260 TYPE_NAME (this_type
) = (char *) name
;
10261 set_die_type (die
, this_type
, cu
);
10262 target_type
= die_type (die
, cu
);
10263 if (target_type
!= this_type
)
10264 TYPE_TARGET_TYPE (this_type
) = target_type
;
10267 /* Self-referential typedefs are, it seems, not allowed by the DWARF
10268 spec and cause infinite loops in GDB. */
10269 complaint (&symfile_complaints
,
10270 _("Self-referential DW_TAG_typedef "
10271 "- DIE at 0x%x [in module %s]"),
10272 die
->offset
.sect_off
, objfile
->name
);
10273 TYPE_TARGET_TYPE (this_type
) = NULL
;
10278 /* Find a representation of a given base type and install
10279 it in the TYPE field of the die. */
10281 static struct type
*
10282 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10284 struct objfile
*objfile
= cu
->objfile
;
10286 struct attribute
*attr
;
10287 int encoding
= 0, size
= 0;
10289 enum type_code code
= TYPE_CODE_INT
;
10290 int type_flags
= 0;
10291 struct type
*target_type
= NULL
;
10293 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
10296 encoding
= DW_UNSND (attr
);
10298 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10301 size
= DW_UNSND (attr
);
10303 name
= dwarf2_name (die
, cu
);
10306 complaint (&symfile_complaints
,
10307 _("DW_AT_name missing from DW_TAG_base_type"));
10312 case DW_ATE_address
:
10313 /* Turn DW_ATE_address into a void * pointer. */
10314 code
= TYPE_CODE_PTR
;
10315 type_flags
|= TYPE_FLAG_UNSIGNED
;
10316 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
10318 case DW_ATE_boolean
:
10319 code
= TYPE_CODE_BOOL
;
10320 type_flags
|= TYPE_FLAG_UNSIGNED
;
10322 case DW_ATE_complex_float
:
10323 code
= TYPE_CODE_COMPLEX
;
10324 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
10326 case DW_ATE_decimal_float
:
10327 code
= TYPE_CODE_DECFLOAT
;
10330 code
= TYPE_CODE_FLT
;
10332 case DW_ATE_signed
:
10334 case DW_ATE_unsigned
:
10335 type_flags
|= TYPE_FLAG_UNSIGNED
;
10336 if (cu
->language
== language_fortran
10338 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
10339 code
= TYPE_CODE_CHAR
;
10341 case DW_ATE_signed_char
:
10342 if (cu
->language
== language_ada
|| cu
->language
== language_m2
10343 || cu
->language
== language_pascal
10344 || cu
->language
== language_fortran
)
10345 code
= TYPE_CODE_CHAR
;
10347 case DW_ATE_unsigned_char
:
10348 if (cu
->language
== language_ada
|| cu
->language
== language_m2
10349 || cu
->language
== language_pascal
10350 || cu
->language
== language_fortran
)
10351 code
= TYPE_CODE_CHAR
;
10352 type_flags
|= TYPE_FLAG_UNSIGNED
;
10355 /* We just treat this as an integer and then recognize the
10356 type by name elsewhere. */
10360 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
10361 dwarf_type_encoding_name (encoding
));
10365 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
10366 TYPE_NAME (type
) = name
;
10367 TYPE_TARGET_TYPE (type
) = target_type
;
10369 if (name
&& strcmp (name
, "char") == 0)
10370 TYPE_NOSIGN (type
) = 1;
10372 return set_die_type (die
, type
, cu
);
10375 /* Read the given DW_AT_subrange DIE. */
10377 static struct type
*
10378 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10380 struct type
*base_type
;
10381 struct type
*range_type
;
10382 struct attribute
*attr
;
10384 int low_default_is_valid
;
10386 LONGEST negative_mask
;
10388 base_type
= die_type (die
, cu
);
10389 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
10390 check_typedef (base_type
);
10392 /* The die_type call above may have already set the type for this DIE. */
10393 range_type
= get_die_type (die
, cu
);
10397 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
10398 omitting DW_AT_lower_bound. */
10399 switch (cu
->language
)
10402 case language_cplus
:
10404 low_default_is_valid
= 1;
10406 case language_fortran
:
10408 low_default_is_valid
= 1;
10411 case language_java
:
10412 case language_objc
:
10414 low_default_is_valid
= (cu
->header
.version
>= 4);
10418 case language_pascal
:
10420 low_default_is_valid
= (cu
->header
.version
>= 4);
10424 low_default_is_valid
= 0;
10428 /* FIXME: For variable sized arrays either of these could be
10429 a variable rather than a constant value. We'll allow it,
10430 but we don't know how to handle it. */
10431 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
10433 low
= dwarf2_get_attr_constant_value (attr
, low
);
10434 else if (!low_default_is_valid
)
10435 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
10436 "- DIE at 0x%x [in module %s]"),
10437 die
->offset
.sect_off
, cu
->objfile
->name
);
10439 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
10442 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
10444 /* GCC encodes arrays with unspecified or dynamic length
10445 with a DW_FORM_block1 attribute or a reference attribute.
10446 FIXME: GDB does not yet know how to handle dynamic
10447 arrays properly, treat them as arrays with unspecified
10450 FIXME: jimb/2003-09-22: GDB does not really know
10451 how to handle arrays of unspecified length
10452 either; we just represent them as zero-length
10453 arrays. Choose an appropriate upper bound given
10454 the lower bound we've computed above. */
10458 high
= dwarf2_get_attr_constant_value (attr
, 1);
10462 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
10465 int count
= dwarf2_get_attr_constant_value (attr
, 1);
10466 high
= low
+ count
- 1;
10470 /* Unspecified array length. */
10475 /* Dwarf-2 specifications explicitly allows to create subrange types
10476 without specifying a base type.
10477 In that case, the base type must be set to the type of
10478 the lower bound, upper bound or count, in that order, if any of these
10479 three attributes references an object that has a type.
10480 If no base type is found, the Dwarf-2 specifications say that
10481 a signed integer type of size equal to the size of an address should
10483 For the following C code: `extern char gdb_int [];'
10484 GCC produces an empty range DIE.
10485 FIXME: muller/2010-05-28: Possible references to object for low bound,
10486 high bound or count are not yet handled by this code. */
10487 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
10489 struct objfile
*objfile
= cu
->objfile
;
10490 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10491 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
10492 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
10494 /* Test "int", "long int", and "long long int" objfile types,
10495 and select the first one having a size above or equal to the
10496 architecture address size. */
10497 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
10498 base_type
= int_type
;
10501 int_type
= objfile_type (objfile
)->builtin_long
;
10502 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
10503 base_type
= int_type
;
10506 int_type
= objfile_type (objfile
)->builtin_long_long
;
10507 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
10508 base_type
= int_type
;
10514 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
10515 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
10516 low
|= negative_mask
;
10517 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
10518 high
|= negative_mask
;
10520 range_type
= create_range_type (NULL
, base_type
, low
, high
);
10522 /* Mark arrays with dynamic length at least as an array of unspecified
10523 length. GDB could check the boundary but before it gets implemented at
10524 least allow accessing the array elements. */
10525 if (attr
&& attr_form_is_block (attr
))
10526 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
10528 /* Ada expects an empty array on no boundary attributes. */
10529 if (attr
== NULL
&& cu
->language
!= language_ada
)
10530 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
10532 name
= dwarf2_name (die
, cu
);
10534 TYPE_NAME (range_type
) = name
;
10536 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10538 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
10540 set_die_type (die
, range_type
, cu
);
10542 /* set_die_type should be already done. */
10543 set_descriptive_type (range_type
, die
, cu
);
10548 static struct type
*
10549 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10553 /* For now, we only support the C meaning of an unspecified type: void. */
10555 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
10556 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
10558 return set_die_type (die
, type
, cu
);
10561 /* Read a single die and all its descendents. Set the die's sibling
10562 field to NULL; set other fields in the die correctly, and set all
10563 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
10564 location of the info_ptr after reading all of those dies. PARENT
10565 is the parent of the die in question. */
10567 static struct die_info
*
10568 read_die_and_children (const struct die_reader_specs
*reader
,
10569 gdb_byte
*info_ptr
,
10570 gdb_byte
**new_info_ptr
,
10571 struct die_info
*parent
)
10573 struct die_info
*die
;
10577 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
10580 *new_info_ptr
= cur_ptr
;
10583 store_in_ref_table (die
, reader
->cu
);
10586 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
10590 *new_info_ptr
= cur_ptr
;
10593 die
->sibling
= NULL
;
10594 die
->parent
= parent
;
10598 /* Read a die, all of its descendents, and all of its siblings; set
10599 all of the fields of all of the dies correctly. Arguments are as
10600 in read_die_and_children. */
10602 static struct die_info
*
10603 read_die_and_siblings (const struct die_reader_specs
*reader
,
10604 gdb_byte
*info_ptr
,
10605 gdb_byte
**new_info_ptr
,
10606 struct die_info
*parent
)
10608 struct die_info
*first_die
, *last_sibling
;
10611 cur_ptr
= info_ptr
;
10612 first_die
= last_sibling
= NULL
;
10616 struct die_info
*die
10617 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
10621 *new_info_ptr
= cur_ptr
;
10628 last_sibling
->sibling
= die
;
10630 last_sibling
= die
;
10634 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
10636 The caller is responsible for filling in the extra attributes
10637 and updating (*DIEP)->num_attrs.
10638 Set DIEP to point to a newly allocated die with its information,
10639 except for its child, sibling, and parent fields.
10640 Set HAS_CHILDREN to tell whether the die has children or not. */
10643 read_full_die_1 (const struct die_reader_specs
*reader
,
10644 struct die_info
**diep
, gdb_byte
*info_ptr
,
10645 int *has_children
, int num_extra_attrs
)
10647 unsigned int abbrev_number
, bytes_read
, i
;
10648 sect_offset offset
;
10649 struct abbrev_info
*abbrev
;
10650 struct die_info
*die
;
10651 struct dwarf2_cu
*cu
= reader
->cu
;
10652 bfd
*abfd
= reader
->abfd
;
10654 offset
.sect_off
= info_ptr
- reader
->buffer
;
10655 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10656 info_ptr
+= bytes_read
;
10657 if (!abbrev_number
)
10664 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
10666 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
10668 bfd_get_filename (abfd
));
10670 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
10671 die
->offset
= offset
;
10672 die
->tag
= abbrev
->tag
;
10673 die
->abbrev
= abbrev_number
;
10675 /* Make the result usable.
10676 The caller needs to update num_attrs after adding the extra
10678 die
->num_attrs
= abbrev
->num_attrs
;
10680 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
10681 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
10685 *has_children
= abbrev
->has_children
;
10689 /* Read a die and all its attributes.
10690 Set DIEP to point to a newly allocated die with its information,
10691 except for its child, sibling, and parent fields.
10692 Set HAS_CHILDREN to tell whether the die has children or not. */
10695 read_full_die (const struct die_reader_specs
*reader
,
10696 struct die_info
**diep
, gdb_byte
*info_ptr
,
10699 return read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
10702 /* In DWARF version 2, the description of the debugging information is
10703 stored in a separate .debug_abbrev section. Before we read any
10704 dies from a section we read in all abbreviations and install them
10705 in a hash table. This function also sets flags in CU describing
10706 the data found in the abbrev table. */
10709 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
10710 struct dwarf2_section_info
*abbrev_section
)
10713 bfd
*abfd
= abbrev_section
->asection
->owner
;
10714 struct comp_unit_head
*cu_header
= &cu
->header
;
10715 gdb_byte
*abbrev_ptr
;
10716 struct abbrev_info
*cur_abbrev
;
10717 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
10718 unsigned int abbrev_form
, hash_number
;
10719 struct attr_abbrev
*cur_attrs
;
10720 unsigned int allocated_attrs
;
10722 /* Initialize dwarf2 abbrevs. */
10723 obstack_init (&cu
->abbrev_obstack
);
10724 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
10726 * sizeof (struct abbrev_info
*)));
10727 memset (cu
->dwarf2_abbrevs
, 0,
10728 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
10730 dwarf2_read_section (cu
->objfile
, abbrev_section
);
10731 abbrev_ptr
= abbrev_section
->buffer
+ cu_header
->abbrev_offset
.sect_off
;
10732 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10733 abbrev_ptr
+= bytes_read
;
10735 allocated_attrs
= ATTR_ALLOC_CHUNK
;
10736 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
10738 /* Loop until we reach an abbrev number of 0. */
10739 while (abbrev_number
)
10741 cur_abbrev
= dwarf_alloc_abbrev (cu
);
10743 /* read in abbrev header */
10744 cur_abbrev
->number
= abbrev_number
;
10745 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10746 abbrev_ptr
+= bytes_read
;
10747 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
10750 /* now read in declarations */
10751 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10752 abbrev_ptr
+= bytes_read
;
10753 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10754 abbrev_ptr
+= bytes_read
;
10755 while (abbrev_name
)
10757 if (cur_abbrev
->num_attrs
== allocated_attrs
)
10759 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
10761 = xrealloc (cur_attrs
, (allocated_attrs
10762 * sizeof (struct attr_abbrev
)));
10765 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
10766 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
10767 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10768 abbrev_ptr
+= bytes_read
;
10769 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10770 abbrev_ptr
+= bytes_read
;
10773 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
10774 (cur_abbrev
->num_attrs
10775 * sizeof (struct attr_abbrev
)));
10776 memcpy (cur_abbrev
->attrs
, cur_attrs
,
10777 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
10779 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
10780 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
10781 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
10783 /* Get next abbreviation.
10784 Under Irix6 the abbreviations for a compilation unit are not
10785 always properly terminated with an abbrev number of 0.
10786 Exit loop if we encounter an abbreviation which we have
10787 already read (which means we are about to read the abbreviations
10788 for the next compile unit) or if the end of the abbreviation
10789 table is reached. */
10790 if ((unsigned int) (abbrev_ptr
- abbrev_section
->buffer
)
10791 >= abbrev_section
->size
)
10793 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10794 abbrev_ptr
+= bytes_read
;
10795 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
10802 /* Release the memory used by the abbrev table for a compilation unit. */
10805 dwarf2_free_abbrev_table (void *ptr_to_cu
)
10807 struct dwarf2_cu
*cu
= ptr_to_cu
;
10809 obstack_free (&cu
->abbrev_obstack
, NULL
);
10810 cu
->dwarf2_abbrevs
= NULL
;
10813 /* Lookup an abbrev_info structure in the abbrev hash table. */
10815 static struct abbrev_info
*
10816 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
10818 unsigned int hash_number
;
10819 struct abbrev_info
*abbrev
;
10821 hash_number
= number
% ABBREV_HASH_SIZE
;
10822 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
10826 if (abbrev
->number
== number
)
10829 abbrev
= abbrev
->next
;
10834 /* Returns nonzero if TAG represents a type that we might generate a partial
10838 is_type_tag_for_partial (int tag
)
10843 /* Some types that would be reasonable to generate partial symbols for,
10844 that we don't at present. */
10845 case DW_TAG_array_type
:
10846 case DW_TAG_file_type
:
10847 case DW_TAG_ptr_to_member_type
:
10848 case DW_TAG_set_type
:
10849 case DW_TAG_string_type
:
10850 case DW_TAG_subroutine_type
:
10852 case DW_TAG_base_type
:
10853 case DW_TAG_class_type
:
10854 case DW_TAG_interface_type
:
10855 case DW_TAG_enumeration_type
:
10856 case DW_TAG_structure_type
:
10857 case DW_TAG_subrange_type
:
10858 case DW_TAG_typedef
:
10859 case DW_TAG_union_type
:
10866 /* Load all DIEs that are interesting for partial symbols into memory. */
10868 static struct partial_die_info
*
10869 load_partial_dies (const struct die_reader_specs
*reader
,
10870 gdb_byte
*info_ptr
, int building_psymtab
)
10872 struct dwarf2_cu
*cu
= reader
->cu
;
10873 struct objfile
*objfile
= cu
->objfile
;
10874 struct partial_die_info
*part_die
;
10875 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
10876 struct abbrev_info
*abbrev
;
10877 unsigned int bytes_read
;
10878 unsigned int load_all
= 0;
10879 int nesting_level
= 1;
10884 gdb_assert (cu
->per_cu
!= NULL
);
10885 if (cu
->per_cu
->load_all_dies
)
10889 = htab_create_alloc_ex (cu
->header
.length
/ 12,
10893 &cu
->comp_unit_obstack
,
10894 hashtab_obstack_allocate
,
10895 dummy_obstack_deallocate
);
10897 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
10898 sizeof (struct partial_die_info
));
10902 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
10904 /* A NULL abbrev means the end of a series of children. */
10905 if (abbrev
== NULL
)
10907 if (--nesting_level
== 0)
10909 /* PART_DIE was probably the last thing allocated on the
10910 comp_unit_obstack, so we could call obstack_free
10911 here. We don't do that because the waste is small,
10912 and will be cleaned up when we're done with this
10913 compilation unit. This way, we're also more robust
10914 against other users of the comp_unit_obstack. */
10917 info_ptr
+= bytes_read
;
10918 last_die
= parent_die
;
10919 parent_die
= parent_die
->die_parent
;
10923 /* Check for template arguments. We never save these; if
10924 they're seen, we just mark the parent, and go on our way. */
10925 if (parent_die
!= NULL
10926 && cu
->language
== language_cplus
10927 && (abbrev
->tag
== DW_TAG_template_type_param
10928 || abbrev
->tag
== DW_TAG_template_value_param
))
10930 parent_die
->has_template_arguments
= 1;
10934 /* We don't need a partial DIE for the template argument. */
10935 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
10940 /* We only recurse into c++ subprograms looking for template arguments.
10941 Skip their other children. */
10943 && cu
->language
== language_cplus
10944 && parent_die
!= NULL
10945 && parent_die
->tag
== DW_TAG_subprogram
)
10947 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
10951 /* Check whether this DIE is interesting enough to save. Normally
10952 we would not be interested in members here, but there may be
10953 later variables referencing them via DW_AT_specification (for
10954 static members). */
10956 && !is_type_tag_for_partial (abbrev
->tag
)
10957 && abbrev
->tag
!= DW_TAG_constant
10958 && abbrev
->tag
!= DW_TAG_enumerator
10959 && abbrev
->tag
!= DW_TAG_subprogram
10960 && abbrev
->tag
!= DW_TAG_lexical_block
10961 && abbrev
->tag
!= DW_TAG_variable
10962 && abbrev
->tag
!= DW_TAG_namespace
10963 && abbrev
->tag
!= DW_TAG_module
10964 && abbrev
->tag
!= DW_TAG_member
10965 && abbrev
->tag
!= DW_TAG_imported_unit
)
10967 /* Otherwise we skip to the next sibling, if any. */
10968 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
10972 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
10975 /* This two-pass algorithm for processing partial symbols has a
10976 high cost in cache pressure. Thus, handle some simple cases
10977 here which cover the majority of C partial symbols. DIEs
10978 which neither have specification tags in them, nor could have
10979 specification tags elsewhere pointing at them, can simply be
10980 processed and discarded.
10982 This segment is also optional; scan_partial_symbols and
10983 add_partial_symbol will handle these DIEs if we chain
10984 them in normally. When compilers which do not emit large
10985 quantities of duplicate debug information are more common,
10986 this code can probably be removed. */
10988 /* Any complete simple types at the top level (pretty much all
10989 of them, for a language without namespaces), can be processed
10991 if (parent_die
== NULL
10992 && part_die
->has_specification
== 0
10993 && part_die
->is_declaration
== 0
10994 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
10995 || part_die
->tag
== DW_TAG_base_type
10996 || part_die
->tag
== DW_TAG_subrange_type
))
10998 if (building_psymtab
&& part_die
->name
!= NULL
)
10999 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
11000 VAR_DOMAIN
, LOC_TYPEDEF
,
11001 &objfile
->static_psymbols
,
11002 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
11003 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
11007 /* The exception for DW_TAG_typedef with has_children above is
11008 a workaround of GCC PR debug/47510. In the case of this complaint
11009 type_name_no_tag_or_error will error on such types later.
11011 GDB skipped children of DW_TAG_typedef by the shortcut above and then
11012 it could not find the child DIEs referenced later, this is checked
11013 above. In correct DWARF DW_TAG_typedef should have no children. */
11015 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
11016 complaint (&symfile_complaints
,
11017 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
11018 "- DIE at 0x%x [in module %s]"),
11019 part_die
->offset
.sect_off
, objfile
->name
);
11021 /* If we're at the second level, and we're an enumerator, and
11022 our parent has no specification (meaning possibly lives in a
11023 namespace elsewhere), then we can add the partial symbol now
11024 instead of queueing it. */
11025 if (part_die
->tag
== DW_TAG_enumerator
11026 && parent_die
!= NULL
11027 && parent_die
->die_parent
== NULL
11028 && parent_die
->tag
== DW_TAG_enumeration_type
11029 && parent_die
->has_specification
== 0)
11031 if (part_die
->name
== NULL
)
11032 complaint (&symfile_complaints
,
11033 _("malformed enumerator DIE ignored"));
11034 else if (building_psymtab
)
11035 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
11036 VAR_DOMAIN
, LOC_CONST
,
11037 (cu
->language
== language_cplus
11038 || cu
->language
== language_java
)
11039 ? &objfile
->global_psymbols
11040 : &objfile
->static_psymbols
,
11041 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
11043 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
11047 /* We'll save this DIE so link it in. */
11048 part_die
->die_parent
= parent_die
;
11049 part_die
->die_sibling
= NULL
;
11050 part_die
->die_child
= NULL
;
11052 if (last_die
&& last_die
== parent_die
)
11053 last_die
->die_child
= part_die
;
11055 last_die
->die_sibling
= part_die
;
11057 last_die
= part_die
;
11059 if (first_die
== NULL
)
11060 first_die
= part_die
;
11062 /* Maybe add the DIE to the hash table. Not all DIEs that we
11063 find interesting need to be in the hash table, because we
11064 also have the parent/sibling/child chains; only those that we
11065 might refer to by offset later during partial symbol reading.
11067 For now this means things that might have be the target of a
11068 DW_AT_specification, DW_AT_abstract_origin, or
11069 DW_AT_extension. DW_AT_extension will refer only to
11070 namespaces; DW_AT_abstract_origin refers to functions (and
11071 many things under the function DIE, but we do not recurse
11072 into function DIEs during partial symbol reading) and
11073 possibly variables as well; DW_AT_specification refers to
11074 declarations. Declarations ought to have the DW_AT_declaration
11075 flag. It happens that GCC forgets to put it in sometimes, but
11076 only for functions, not for types.
11078 Adding more things than necessary to the hash table is harmless
11079 except for the performance cost. Adding too few will result in
11080 wasted time in find_partial_die, when we reread the compilation
11081 unit with load_all_dies set. */
11084 || abbrev
->tag
== DW_TAG_constant
11085 || abbrev
->tag
== DW_TAG_subprogram
11086 || abbrev
->tag
== DW_TAG_variable
11087 || abbrev
->tag
== DW_TAG_namespace
11088 || part_die
->is_declaration
)
11092 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
11093 part_die
->offset
.sect_off
, INSERT
);
11097 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
11098 sizeof (struct partial_die_info
));
11100 /* For some DIEs we want to follow their children (if any). For C
11101 we have no reason to follow the children of structures; for other
11102 languages we have to, so that we can get at method physnames
11103 to infer fully qualified class names, for DW_AT_specification,
11104 and for C++ template arguments. For C++, we also look one level
11105 inside functions to find template arguments (if the name of the
11106 function does not already contain the template arguments).
11108 For Ada, we need to scan the children of subprograms and lexical
11109 blocks as well because Ada allows the definition of nested
11110 entities that could be interesting for the debugger, such as
11111 nested subprograms for instance. */
11112 if (last_die
->has_children
11114 || last_die
->tag
== DW_TAG_namespace
11115 || last_die
->tag
== DW_TAG_module
11116 || last_die
->tag
== DW_TAG_enumeration_type
11117 || (cu
->language
== language_cplus
11118 && last_die
->tag
== DW_TAG_subprogram
11119 && (last_die
->name
== NULL
11120 || strchr (last_die
->name
, '<') == NULL
))
11121 || (cu
->language
!= language_c
11122 && (last_die
->tag
== DW_TAG_class_type
11123 || last_die
->tag
== DW_TAG_interface_type
11124 || last_die
->tag
== DW_TAG_structure_type
11125 || last_die
->tag
== DW_TAG_union_type
))
11126 || (cu
->language
== language_ada
11127 && (last_die
->tag
== DW_TAG_subprogram
11128 || last_die
->tag
== DW_TAG_lexical_block
))))
11131 parent_die
= last_die
;
11135 /* Otherwise we skip to the next sibling, if any. */
11136 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
11138 /* Back to the top, do it again. */
11142 /* Read a minimal amount of information into the minimal die structure. */
11145 read_partial_die (const struct die_reader_specs
*reader
,
11146 struct partial_die_info
*part_die
,
11147 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
11148 gdb_byte
*info_ptr
)
11150 struct dwarf2_cu
*cu
= reader
->cu
;
11151 struct objfile
*objfile
= cu
->objfile
;
11152 gdb_byte
*buffer
= reader
->buffer
;
11154 struct attribute attr
;
11155 int has_low_pc_attr
= 0;
11156 int has_high_pc_attr
= 0;
11157 int high_pc_relative
= 0;
11159 memset (part_die
, 0, sizeof (struct partial_die_info
));
11161 part_die
->offset
.sect_off
= info_ptr
- buffer
;
11163 info_ptr
+= abbrev_len
;
11165 if (abbrev
== NULL
)
11168 part_die
->tag
= abbrev
->tag
;
11169 part_die
->has_children
= abbrev
->has_children
;
11171 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
11173 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
11175 /* Store the data if it is of an attribute we want to keep in a
11176 partial symbol table. */
11180 switch (part_die
->tag
)
11182 case DW_TAG_compile_unit
:
11183 case DW_TAG_partial_unit
:
11184 case DW_TAG_type_unit
:
11185 /* Compilation units have a DW_AT_name that is a filename, not
11186 a source language identifier. */
11187 case DW_TAG_enumeration_type
:
11188 case DW_TAG_enumerator
:
11189 /* These tags always have simple identifiers already; no need
11190 to canonicalize them. */
11191 part_die
->name
= DW_STRING (&attr
);
11195 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
11196 &objfile
->objfile_obstack
);
11200 case DW_AT_linkage_name
:
11201 case DW_AT_MIPS_linkage_name
:
11202 /* Note that both forms of linkage name might appear. We
11203 assume they will be the same, and we only store the last
11205 if (cu
->language
== language_ada
)
11206 part_die
->name
= DW_STRING (&attr
);
11207 part_die
->linkage_name
= DW_STRING (&attr
);
11210 has_low_pc_attr
= 1;
11211 part_die
->lowpc
= DW_ADDR (&attr
);
11213 case DW_AT_high_pc
:
11214 has_high_pc_attr
= 1;
11215 if (attr
.form
== DW_FORM_addr
11216 || attr
.form
== DW_FORM_GNU_addr_index
)
11217 part_die
->highpc
= DW_ADDR (&attr
);
11220 high_pc_relative
= 1;
11221 part_die
->highpc
= DW_UNSND (&attr
);
11224 case DW_AT_location
:
11225 /* Support the .debug_loc offsets. */
11226 if (attr_form_is_block (&attr
))
11228 part_die
->d
.locdesc
= DW_BLOCK (&attr
);
11230 else if (attr_form_is_section_offset (&attr
))
11232 dwarf2_complex_location_expr_complaint ();
11236 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
11237 "partial symbol information");
11240 case DW_AT_external
:
11241 part_die
->is_external
= DW_UNSND (&attr
);
11243 case DW_AT_declaration
:
11244 part_die
->is_declaration
= DW_UNSND (&attr
);
11247 part_die
->has_type
= 1;
11249 case DW_AT_abstract_origin
:
11250 case DW_AT_specification
:
11251 case DW_AT_extension
:
11252 part_die
->has_specification
= 1;
11253 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
11255 case DW_AT_sibling
:
11256 /* Ignore absolute siblings, they might point outside of
11257 the current compile unit. */
11258 if (attr
.form
== DW_FORM_ref_addr
)
11259 complaint (&symfile_complaints
,
11260 _("ignoring absolute DW_AT_sibling"));
11262 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
11264 case DW_AT_byte_size
:
11265 part_die
->has_byte_size
= 1;
11267 case DW_AT_calling_convention
:
11268 /* DWARF doesn't provide a way to identify a program's source-level
11269 entry point. DW_AT_calling_convention attributes are only meant
11270 to describe functions' calling conventions.
11272 However, because it's a necessary piece of information in
11273 Fortran, and because DW_CC_program is the only piece of debugging
11274 information whose definition refers to a 'main program' at all,
11275 several compilers have begun marking Fortran main programs with
11276 DW_CC_program --- even when those functions use the standard
11277 calling conventions.
11279 So until DWARF specifies a way to provide this information and
11280 compilers pick up the new representation, we'll support this
11282 if (DW_UNSND (&attr
) == DW_CC_program
11283 && cu
->language
== language_fortran
)
11285 set_main_name (part_die
->name
);
11287 /* As this DIE has a static linkage the name would be difficult
11288 to look up later. */
11289 language_of_main
= language_fortran
;
11293 if (DW_UNSND (&attr
) == DW_INL_inlined
11294 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
11295 part_die
->may_be_inlined
= 1;
11299 if (part_die
->tag
== DW_TAG_imported_unit
)
11300 part_die
->d
.offset
= dwarf2_get_ref_die_offset (&attr
);
11308 if (high_pc_relative
)
11309 part_die
->highpc
+= part_die
->lowpc
;
11311 if (has_low_pc_attr
&& has_high_pc_attr
)
11313 /* When using the GNU linker, .gnu.linkonce. sections are used to
11314 eliminate duplicate copies of functions and vtables and such.
11315 The linker will arbitrarily choose one and discard the others.
11316 The AT_*_pc values for such functions refer to local labels in
11317 these sections. If the section from that file was discarded, the
11318 labels are not in the output, so the relocs get a value of 0.
11319 If this is a discarded function, mark the pc bounds as invalid,
11320 so that GDB will ignore it. */
11321 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
11323 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11325 complaint (&symfile_complaints
,
11326 _("DW_AT_low_pc %s is zero "
11327 "for DIE at 0x%x [in module %s]"),
11328 paddress (gdbarch
, part_die
->lowpc
),
11329 part_die
->offset
.sect_off
, objfile
->name
);
11331 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
11332 else if (part_die
->lowpc
>= part_die
->highpc
)
11334 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11336 complaint (&symfile_complaints
,
11337 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
11338 "for DIE at 0x%x [in module %s]"),
11339 paddress (gdbarch
, part_die
->lowpc
),
11340 paddress (gdbarch
, part_die
->highpc
),
11341 part_die
->offset
.sect_off
, objfile
->name
);
11344 part_die
->has_pc_info
= 1;
11350 /* Find a cached partial DIE at OFFSET in CU. */
11352 static struct partial_die_info
*
11353 find_partial_die_in_comp_unit (sect_offset offset
, struct dwarf2_cu
*cu
)
11355 struct partial_die_info
*lookup_die
= NULL
;
11356 struct partial_die_info part_die
;
11358 part_die
.offset
= offset
;
11359 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
,
11365 /* Find a partial DIE at OFFSET, which may or may not be in CU,
11366 except in the case of .debug_types DIEs which do not reference
11367 outside their CU (they do however referencing other types via
11368 DW_FORM_ref_sig8). */
11370 static struct partial_die_info
*
11371 find_partial_die (sect_offset offset
, struct dwarf2_cu
*cu
)
11373 struct objfile
*objfile
= cu
->objfile
;
11374 struct dwarf2_per_cu_data
*per_cu
= NULL
;
11375 struct partial_die_info
*pd
= NULL
;
11377 if (offset_in_cu_p (&cu
->header
, offset
))
11379 pd
= find_partial_die_in_comp_unit (offset
, cu
);
11382 /* We missed recording what we needed.
11383 Load all dies and try again. */
11384 per_cu
= cu
->per_cu
;
11388 /* TUs don't reference other CUs/TUs (except via type signatures). */
11389 if (cu
->per_cu
->is_debug_types
)
11391 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
11392 " external reference to offset 0x%lx [in module %s].\n"),
11393 (long) cu
->header
.offset
.sect_off
, (long) offset
.sect_off
,
11394 bfd_get_filename (objfile
->obfd
));
11396 per_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
11398 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
11399 load_partial_comp_unit (per_cu
);
11401 per_cu
->cu
->last_used
= 0;
11402 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
11405 /* If we didn't find it, and not all dies have been loaded,
11406 load them all and try again. */
11408 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
11410 per_cu
->load_all_dies
= 1;
11412 /* This is nasty. When we reread the DIEs, somewhere up the call chain
11413 THIS_CU->cu may already be in use. So we can't just free it and
11414 replace its DIEs with the ones we read in. Instead, we leave those
11415 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
11416 and clobber THIS_CU->cu->partial_dies with the hash table for the new
11418 load_partial_comp_unit (per_cu
);
11420 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
11424 internal_error (__FILE__
, __LINE__
,
11425 _("could not find partial DIE 0x%x "
11426 "in cache [from module %s]\n"),
11427 offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
11431 /* See if we can figure out if the class lives in a namespace. We do
11432 this by looking for a member function; its demangled name will
11433 contain namespace info, if there is any. */
11436 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
11437 struct dwarf2_cu
*cu
)
11439 /* NOTE: carlton/2003-10-07: Getting the info this way changes
11440 what template types look like, because the demangler
11441 frequently doesn't give the same name as the debug info. We
11442 could fix this by only using the demangled name to get the
11443 prefix (but see comment in read_structure_type). */
11445 struct partial_die_info
*real_pdi
;
11446 struct partial_die_info
*child_pdi
;
11448 /* If this DIE (this DIE's specification, if any) has a parent, then
11449 we should not do this. We'll prepend the parent's fully qualified
11450 name when we create the partial symbol. */
11452 real_pdi
= struct_pdi
;
11453 while (real_pdi
->has_specification
)
11454 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
11456 if (real_pdi
->die_parent
!= NULL
)
11459 for (child_pdi
= struct_pdi
->die_child
;
11461 child_pdi
= child_pdi
->die_sibling
)
11463 if (child_pdi
->tag
== DW_TAG_subprogram
11464 && child_pdi
->linkage_name
!= NULL
)
11466 char *actual_class_name
11467 = language_class_name_from_physname (cu
->language_defn
,
11468 child_pdi
->linkage_name
);
11469 if (actual_class_name
!= NULL
)
11472 = obsavestring (actual_class_name
,
11473 strlen (actual_class_name
),
11474 &cu
->objfile
->objfile_obstack
);
11475 xfree (actual_class_name
);
11482 /* Adjust PART_DIE before generating a symbol for it. This function
11483 may set the is_external flag or change the DIE's name. */
11486 fixup_partial_die (struct partial_die_info
*part_die
,
11487 struct dwarf2_cu
*cu
)
11489 /* Once we've fixed up a die, there's no point in doing so again.
11490 This also avoids a memory leak if we were to call
11491 guess_partial_die_structure_name multiple times. */
11492 if (part_die
->fixup_called
)
11495 /* If we found a reference attribute and the DIE has no name, try
11496 to find a name in the referred to DIE. */
11498 if (part_die
->name
== NULL
&& part_die
->has_specification
)
11500 struct partial_die_info
*spec_die
;
11502 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
11504 fixup_partial_die (spec_die
, cu
);
11506 if (spec_die
->name
)
11508 part_die
->name
= spec_die
->name
;
11510 /* Copy DW_AT_external attribute if it is set. */
11511 if (spec_die
->is_external
)
11512 part_die
->is_external
= spec_die
->is_external
;
11516 /* Set default names for some unnamed DIEs. */
11518 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
11519 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
11521 /* If there is no parent die to provide a namespace, and there are
11522 children, see if we can determine the namespace from their linkage
11524 if (cu
->language
== language_cplus
11525 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
11526 && part_die
->die_parent
== NULL
11527 && part_die
->has_children
11528 && (part_die
->tag
== DW_TAG_class_type
11529 || part_die
->tag
== DW_TAG_structure_type
11530 || part_die
->tag
== DW_TAG_union_type
))
11531 guess_partial_die_structure_name (part_die
, cu
);
11533 /* GCC might emit a nameless struct or union that has a linkage
11534 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
11535 if (part_die
->name
== NULL
11536 && (part_die
->tag
== DW_TAG_class_type
11537 || part_die
->tag
== DW_TAG_interface_type
11538 || part_die
->tag
== DW_TAG_structure_type
11539 || part_die
->tag
== DW_TAG_union_type
)
11540 && part_die
->linkage_name
!= NULL
)
11544 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
11549 /* Strip any leading namespaces/classes, keep only the base name.
11550 DW_AT_name for named DIEs does not contain the prefixes. */
11551 base
= strrchr (demangled
, ':');
11552 if (base
&& base
> demangled
&& base
[-1] == ':')
11557 part_die
->name
= obsavestring (base
, strlen (base
),
11558 &cu
->objfile
->objfile_obstack
);
11563 part_die
->fixup_called
= 1;
11566 /* Read an attribute value described by an attribute form. */
11569 read_attribute_value (const struct die_reader_specs
*reader
,
11570 struct attribute
*attr
, unsigned form
,
11571 gdb_byte
*info_ptr
)
11573 struct dwarf2_cu
*cu
= reader
->cu
;
11574 bfd
*abfd
= reader
->abfd
;
11575 struct comp_unit_head
*cu_header
= &cu
->header
;
11576 unsigned int bytes_read
;
11577 struct dwarf_block
*blk
;
11582 case DW_FORM_ref_addr
:
11583 if (cu
->header
.version
== 2)
11584 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
11586 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
11587 &cu
->header
, &bytes_read
);
11588 info_ptr
+= bytes_read
;
11591 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
11592 info_ptr
+= bytes_read
;
11594 case DW_FORM_block2
:
11595 blk
= dwarf_alloc_block (cu
);
11596 blk
->size
= read_2_bytes (abfd
, info_ptr
);
11598 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11599 info_ptr
+= blk
->size
;
11600 DW_BLOCK (attr
) = blk
;
11602 case DW_FORM_block4
:
11603 blk
= dwarf_alloc_block (cu
);
11604 blk
->size
= read_4_bytes (abfd
, info_ptr
);
11606 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11607 info_ptr
+= blk
->size
;
11608 DW_BLOCK (attr
) = blk
;
11610 case DW_FORM_data2
:
11611 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
11614 case DW_FORM_data4
:
11615 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
11618 case DW_FORM_data8
:
11619 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
11622 case DW_FORM_sec_offset
:
11623 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
11624 info_ptr
+= bytes_read
;
11626 case DW_FORM_string
:
11627 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
11628 DW_STRING_IS_CANONICAL (attr
) = 0;
11629 info_ptr
+= bytes_read
;
11632 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
11634 DW_STRING_IS_CANONICAL (attr
) = 0;
11635 info_ptr
+= bytes_read
;
11637 case DW_FORM_exprloc
:
11638 case DW_FORM_block
:
11639 blk
= dwarf_alloc_block (cu
);
11640 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11641 info_ptr
+= bytes_read
;
11642 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11643 info_ptr
+= blk
->size
;
11644 DW_BLOCK (attr
) = blk
;
11646 case DW_FORM_block1
:
11647 blk
= dwarf_alloc_block (cu
);
11648 blk
->size
= read_1_byte (abfd
, info_ptr
);
11650 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11651 info_ptr
+= blk
->size
;
11652 DW_BLOCK (attr
) = blk
;
11654 case DW_FORM_data1
:
11655 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
11659 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
11662 case DW_FORM_flag_present
:
11663 DW_UNSND (attr
) = 1;
11665 case DW_FORM_sdata
:
11666 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
11667 info_ptr
+= bytes_read
;
11669 case DW_FORM_udata
:
11670 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11671 info_ptr
+= bytes_read
;
11674 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11675 + read_1_byte (abfd
, info_ptr
));
11679 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11680 + read_2_bytes (abfd
, info_ptr
));
11684 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11685 + read_4_bytes (abfd
, info_ptr
));
11689 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11690 + read_8_bytes (abfd
, info_ptr
));
11693 case DW_FORM_ref_sig8
:
11694 /* Convert the signature to something we can record in DW_UNSND
11696 NOTE: This is NULL if the type wasn't found. */
11697 DW_SIGNATURED_TYPE (attr
) =
11698 lookup_signatured_type (read_8_bytes (abfd
, info_ptr
));
11701 case DW_FORM_ref_udata
:
11702 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11703 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
11704 info_ptr
+= bytes_read
;
11706 case DW_FORM_indirect
:
11707 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11708 info_ptr
+= bytes_read
;
11709 info_ptr
= read_attribute_value (reader
, attr
, form
, info_ptr
);
11711 case DW_FORM_GNU_addr_index
:
11712 if (reader
->dwo_file
== NULL
)
11714 /* For now flag a hard error.
11715 Later we can turn this into a complaint. */
11716 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
11717 dwarf_form_name (form
),
11718 bfd_get_filename (abfd
));
11720 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
11721 info_ptr
+= bytes_read
;
11723 case DW_FORM_GNU_str_index
:
11724 if (reader
->dwo_file
== NULL
)
11726 /* For now flag a hard error.
11727 Later we can turn this into a complaint if warranted. */
11728 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
11729 dwarf_form_name (form
),
11730 bfd_get_filename (abfd
));
11733 ULONGEST str_index
=
11734 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11736 DW_STRING (attr
) = read_str_index (reader
, cu
, str_index
);
11737 DW_STRING_IS_CANONICAL (attr
) = 0;
11738 info_ptr
+= bytes_read
;
11742 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
11743 dwarf_form_name (form
),
11744 bfd_get_filename (abfd
));
11747 /* We have seen instances where the compiler tried to emit a byte
11748 size attribute of -1 which ended up being encoded as an unsigned
11749 0xffffffff. Although 0xffffffff is technically a valid size value,
11750 an object of this size seems pretty unlikely so we can relatively
11751 safely treat these cases as if the size attribute was invalid and
11752 treat them as zero by default. */
11753 if (attr
->name
== DW_AT_byte_size
11754 && form
== DW_FORM_data4
11755 && DW_UNSND (attr
) >= 0xffffffff)
11758 (&symfile_complaints
,
11759 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
11760 hex_string (DW_UNSND (attr
)));
11761 DW_UNSND (attr
) = 0;
11767 /* Read an attribute described by an abbreviated attribute. */
11770 read_attribute (const struct die_reader_specs
*reader
,
11771 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
11772 gdb_byte
*info_ptr
)
11774 attr
->name
= abbrev
->name
;
11775 return read_attribute_value (reader
, attr
, abbrev
->form
, info_ptr
);
11778 /* Read dwarf information from a buffer. */
11780 static unsigned int
11781 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
11783 return bfd_get_8 (abfd
, buf
);
11787 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
11789 return bfd_get_signed_8 (abfd
, buf
);
11792 static unsigned int
11793 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
11795 return bfd_get_16 (abfd
, buf
);
11799 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
11801 return bfd_get_signed_16 (abfd
, buf
);
11804 static unsigned int
11805 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
11807 return bfd_get_32 (abfd
, buf
);
11811 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
11813 return bfd_get_signed_32 (abfd
, buf
);
11817 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
11819 return bfd_get_64 (abfd
, buf
);
11823 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
11824 unsigned int *bytes_read
)
11826 struct comp_unit_head
*cu_header
= &cu
->header
;
11827 CORE_ADDR retval
= 0;
11829 if (cu_header
->signed_addr_p
)
11831 switch (cu_header
->addr_size
)
11834 retval
= bfd_get_signed_16 (abfd
, buf
);
11837 retval
= bfd_get_signed_32 (abfd
, buf
);
11840 retval
= bfd_get_signed_64 (abfd
, buf
);
11843 internal_error (__FILE__
, __LINE__
,
11844 _("read_address: bad switch, signed [in module %s]"),
11845 bfd_get_filename (abfd
));
11850 switch (cu_header
->addr_size
)
11853 retval
= bfd_get_16 (abfd
, buf
);
11856 retval
= bfd_get_32 (abfd
, buf
);
11859 retval
= bfd_get_64 (abfd
, buf
);
11862 internal_error (__FILE__
, __LINE__
,
11863 _("read_address: bad switch, "
11864 "unsigned [in module %s]"),
11865 bfd_get_filename (abfd
));
11869 *bytes_read
= cu_header
->addr_size
;
11873 /* Read the initial length from a section. The (draft) DWARF 3
11874 specification allows the initial length to take up either 4 bytes
11875 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
11876 bytes describe the length and all offsets will be 8 bytes in length
11879 An older, non-standard 64-bit format is also handled by this
11880 function. The older format in question stores the initial length
11881 as an 8-byte quantity without an escape value. Lengths greater
11882 than 2^32 aren't very common which means that the initial 4 bytes
11883 is almost always zero. Since a length value of zero doesn't make
11884 sense for the 32-bit format, this initial zero can be considered to
11885 be an escape value which indicates the presence of the older 64-bit
11886 format. As written, the code can't detect (old format) lengths
11887 greater than 4GB. If it becomes necessary to handle lengths
11888 somewhat larger than 4GB, we could allow other small values (such
11889 as the non-sensical values of 1, 2, and 3) to also be used as
11890 escape values indicating the presence of the old format.
11892 The value returned via bytes_read should be used to increment the
11893 relevant pointer after calling read_initial_length().
11895 [ Note: read_initial_length() and read_offset() are based on the
11896 document entitled "DWARF Debugging Information Format", revision
11897 3, draft 8, dated November 19, 2001. This document was obtained
11900 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
11902 This document is only a draft and is subject to change. (So beware.)
11904 Details regarding the older, non-standard 64-bit format were
11905 determined empirically by examining 64-bit ELF files produced by
11906 the SGI toolchain on an IRIX 6.5 machine.
11908 - Kevin, July 16, 2002
11912 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
11914 LONGEST length
= bfd_get_32 (abfd
, buf
);
11916 if (length
== 0xffffffff)
11918 length
= bfd_get_64 (abfd
, buf
+ 4);
11921 else if (length
== 0)
11923 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
11924 length
= bfd_get_64 (abfd
, buf
);
11935 /* Cover function for read_initial_length.
11936 Returns the length of the object at BUF, and stores the size of the
11937 initial length in *BYTES_READ and stores the size that offsets will be in
11939 If the initial length size is not equivalent to that specified in
11940 CU_HEADER then issue a complaint.
11941 This is useful when reading non-comp-unit headers. */
11944 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
11945 const struct comp_unit_head
*cu_header
,
11946 unsigned int *bytes_read
,
11947 unsigned int *offset_size
)
11949 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
11951 gdb_assert (cu_header
->initial_length_size
== 4
11952 || cu_header
->initial_length_size
== 8
11953 || cu_header
->initial_length_size
== 12);
11955 if (cu_header
->initial_length_size
!= *bytes_read
)
11956 complaint (&symfile_complaints
,
11957 _("intermixed 32-bit and 64-bit DWARF sections"));
11959 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
11963 /* Read an offset from the data stream. The size of the offset is
11964 given by cu_header->offset_size. */
11967 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
11968 unsigned int *bytes_read
)
11970 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
11972 *bytes_read
= cu_header
->offset_size
;
11976 /* Read an offset from the data stream. */
11979 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
11981 LONGEST retval
= 0;
11983 switch (offset_size
)
11986 retval
= bfd_get_32 (abfd
, buf
);
11989 retval
= bfd_get_64 (abfd
, buf
);
11992 internal_error (__FILE__
, __LINE__
,
11993 _("read_offset_1: bad switch [in module %s]"),
11994 bfd_get_filename (abfd
));
12001 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
12003 /* If the size of a host char is 8 bits, we can return a pointer
12004 to the buffer, otherwise we have to copy the data to a buffer
12005 allocated on the temporary obstack. */
12006 gdb_assert (HOST_CHAR_BIT
== 8);
12011 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
12013 /* If the size of a host char is 8 bits, we can return a pointer
12014 to the string, otherwise we have to copy the string to a buffer
12015 allocated on the temporary obstack. */
12016 gdb_assert (HOST_CHAR_BIT
== 8);
12019 *bytes_read_ptr
= 1;
12022 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
12023 return (char *) buf
;
12027 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
12029 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
12030 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
12031 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
12032 bfd_get_filename (abfd
));
12033 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
12034 error (_("DW_FORM_strp pointing outside of "
12035 ".debug_str section [in module %s]"),
12036 bfd_get_filename (abfd
));
12037 gdb_assert (HOST_CHAR_BIT
== 8);
12038 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
12040 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
12044 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
12045 const struct comp_unit_head
*cu_header
,
12046 unsigned int *bytes_read_ptr
)
12048 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
12050 return read_indirect_string_at_offset (abfd
, str_offset
);
12054 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
12057 unsigned int num_read
;
12059 unsigned char byte
;
12067 byte
= bfd_get_8 (abfd
, buf
);
12070 result
|= ((ULONGEST
) (byte
& 127) << shift
);
12071 if ((byte
& 128) == 0)
12077 *bytes_read_ptr
= num_read
;
12082 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
12085 int i
, shift
, num_read
;
12086 unsigned char byte
;
12094 byte
= bfd_get_8 (abfd
, buf
);
12097 result
|= ((LONGEST
) (byte
& 127) << shift
);
12099 if ((byte
& 128) == 0)
12104 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
12105 result
|= -(((LONGEST
) 1) << shift
);
12106 *bytes_read_ptr
= num_read
;
12110 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
12111 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
12112 ADDR_SIZE is the size of addresses from the CU header. */
12115 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
12117 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12118 bfd
*abfd
= objfile
->obfd
;
12119 const gdb_byte
*info_ptr
;
12121 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
12122 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
12123 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
12125 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
12126 error (_("DW_FORM_addr_index pointing outside of "
12127 ".debug_addr section [in module %s]"),
12129 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
12130 + addr_base
+ addr_index
* addr_size
);
12131 if (addr_size
== 4)
12132 return bfd_get_32 (abfd
, info_ptr
);
12134 return bfd_get_64 (abfd
, info_ptr
);
12137 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
12140 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
12142 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
12145 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
12148 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, gdb_byte
*info_ptr
,
12149 unsigned int *bytes_read
)
12151 bfd
*abfd
= cu
->objfile
->obfd
;
12152 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
12154 return read_addr_index (cu
, addr_index
);
12157 /* Data structure to pass results from dwarf2_read_addr_index_reader
12158 back to dwarf2_read_addr_index. */
12160 struct dwarf2_read_addr_index_data
12162 ULONGEST addr_base
;
12166 /* die_reader_func for dwarf2_read_addr_index. */
12169 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
12170 gdb_byte
*info_ptr
,
12171 struct die_info
*comp_unit_die
,
12175 struct dwarf2_cu
*cu
= reader
->cu
;
12176 struct dwarf2_read_addr_index_data
*aidata
=
12177 (struct dwarf2_read_addr_index_data
*) data
;
12179 aidata
->addr_base
= cu
->addr_base
;
12180 aidata
->addr_size
= cu
->header
.addr_size
;
12183 /* Given an index in .debug_addr, fetch the value.
12184 NOTE: This can be called during dwarf expression evaluation,
12185 long after the debug information has been read, and thus per_cu->cu
12186 may no longer exist. */
12189 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
12190 unsigned int addr_index
)
12192 struct objfile
*objfile
= per_cu
->objfile
;
12193 struct dwarf2_cu
*cu
= per_cu
->cu
;
12194 ULONGEST addr_base
;
12197 /* This is intended to be called from outside this file. */
12198 dw2_setup (objfile
);
12200 /* We need addr_base and addr_size.
12201 If we don't have PER_CU->cu, we have to get it.
12202 Nasty, but the alternative is storing the needed info in PER_CU,
12203 which at this point doesn't seem justified: it's not clear how frequently
12204 it would get used and it would increase the size of every PER_CU.
12205 Entry points like dwarf2_per_cu_addr_size do a similar thing
12206 so we're not in uncharted territory here.
12207 Alas we need to be a bit more complicated as addr_base is contained
12210 We don't need to read the entire CU(/TU).
12211 We just need the header and top level die.
12212 IWBN to use the aging mechanism to let us lazily later discard the CU.
12213 See however init_cutu_and_read_dies_simple. */
12217 addr_base
= cu
->addr_base
;
12218 addr_size
= cu
->header
.addr_size
;
12222 struct dwarf2_read_addr_index_data aidata
;
12224 init_cutu_and_read_dies_simple (per_cu
, dwarf2_read_addr_index_reader
,
12226 addr_base
= aidata
.addr_base
;
12227 addr_size
= aidata
.addr_size
;
12230 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
12233 /* Given a DW_AT_str_index, fetch the string. */
12236 read_str_index (const struct die_reader_specs
*reader
,
12237 struct dwarf2_cu
*cu
, ULONGEST str_index
)
12239 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12240 const char *dwo_name
= objfile
->name
;
12241 bfd
*abfd
= objfile
->obfd
;
12242 struct dwo_sections
*sections
= &reader
->dwo_file
->sections
;
12243 gdb_byte
*info_ptr
;
12244 ULONGEST str_offset
;
12246 dwarf2_read_section (objfile
, §ions
->str
);
12247 dwarf2_read_section (objfile
, §ions
->str_offsets
);
12248 if (sections
->str
.buffer
== NULL
)
12249 error (_("DW_FORM_str_index used without .debug_str.dwo section"
12250 " in CU at offset 0x%lx [in module %s]"),
12251 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12252 if (sections
->str_offsets
.buffer
== NULL
)
12253 error (_("DW_FORM_str_index used without .debug_str_offsets.dwo section"
12254 " in CU at offset 0x%lx [in module %s]"),
12255 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12256 if (str_index
* cu
->header
.offset_size
>= sections
->str_offsets
.size
)
12257 error (_("DW_FORM_str_index pointing outside of .debug_str_offsets.dwo"
12258 " section in CU at offset 0x%lx [in module %s]"),
12259 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12260 info_ptr
= (sections
->str_offsets
.buffer
12261 + str_index
* cu
->header
.offset_size
);
12262 if (cu
->header
.offset_size
== 4)
12263 str_offset
= bfd_get_32 (abfd
, info_ptr
);
12265 str_offset
= bfd_get_64 (abfd
, info_ptr
);
12266 if (str_offset
>= sections
->str
.size
)
12267 error (_("Offset from DW_FORM_str_index pointing outside of"
12268 " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"),
12269 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12270 return (char *) (sections
->str
.buffer
+ str_offset
);
12273 /* Return a pointer to just past the end of an LEB128 number in BUF. */
12276 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
12282 byte
= bfd_get_8 (abfd
, buf
);
12284 if ((byte
& 128) == 0)
12289 /* Return the length of an LEB128 number in BUF. */
12292 leb128_size (const gdb_byte
*buf
)
12294 const gdb_byte
*begin
= buf
;
12300 if ((byte
& 128) == 0)
12301 return buf
- begin
;
12306 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
12313 cu
->language
= language_c
;
12315 case DW_LANG_C_plus_plus
:
12316 cu
->language
= language_cplus
;
12319 cu
->language
= language_d
;
12321 case DW_LANG_Fortran77
:
12322 case DW_LANG_Fortran90
:
12323 case DW_LANG_Fortran95
:
12324 cu
->language
= language_fortran
;
12327 cu
->language
= language_go
;
12329 case DW_LANG_Mips_Assembler
:
12330 cu
->language
= language_asm
;
12333 cu
->language
= language_java
;
12335 case DW_LANG_Ada83
:
12336 case DW_LANG_Ada95
:
12337 cu
->language
= language_ada
;
12339 case DW_LANG_Modula2
:
12340 cu
->language
= language_m2
;
12342 case DW_LANG_Pascal83
:
12343 cu
->language
= language_pascal
;
12346 cu
->language
= language_objc
;
12348 case DW_LANG_Cobol74
:
12349 case DW_LANG_Cobol85
:
12351 cu
->language
= language_minimal
;
12354 cu
->language_defn
= language_def (cu
->language
);
12357 /* Return the named attribute or NULL if not there. */
12359 static struct attribute
*
12360 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
12365 struct attribute
*spec
= NULL
;
12367 for (i
= 0; i
< die
->num_attrs
; ++i
)
12369 if (die
->attrs
[i
].name
== name
)
12370 return &die
->attrs
[i
];
12371 if (die
->attrs
[i
].name
== DW_AT_specification
12372 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
12373 spec
= &die
->attrs
[i
];
12379 die
= follow_die_ref (die
, spec
, &cu
);
12385 /* Return the named attribute or NULL if not there,
12386 but do not follow DW_AT_specification, etc.
12387 This is for use in contexts where we're reading .debug_types dies.
12388 Following DW_AT_specification, DW_AT_abstract_origin will take us
12389 back up the chain, and we want to go down. */
12391 static struct attribute
*
12392 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
12393 struct dwarf2_cu
*cu
)
12397 for (i
= 0; i
< die
->num_attrs
; ++i
)
12398 if (die
->attrs
[i
].name
== name
)
12399 return &die
->attrs
[i
];
12404 /* Return non-zero iff the attribute NAME is defined for the given DIE,
12405 and holds a non-zero value. This function should only be used for
12406 DW_FORM_flag or DW_FORM_flag_present attributes. */
12409 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
12411 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
12413 return (attr
&& DW_UNSND (attr
));
12417 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
12419 /* A DIE is a declaration if it has a DW_AT_declaration attribute
12420 which value is non-zero. However, we have to be careful with
12421 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
12422 (via dwarf2_flag_true_p) follows this attribute. So we may
12423 end up accidently finding a declaration attribute that belongs
12424 to a different DIE referenced by the specification attribute,
12425 even though the given DIE does not have a declaration attribute. */
12426 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
12427 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
12430 /* Return the die giving the specification for DIE, if there is
12431 one. *SPEC_CU is the CU containing DIE on input, and the CU
12432 containing the return value on output. If there is no
12433 specification, but there is an abstract origin, that is
12436 static struct die_info
*
12437 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
12439 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
12442 if (spec_attr
== NULL
)
12443 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
12445 if (spec_attr
== NULL
)
12448 return follow_die_ref (die
, spec_attr
, spec_cu
);
12451 /* Free the line_header structure *LH, and any arrays and strings it
12453 NOTE: This is also used as a "cleanup" function. */
12456 free_line_header (struct line_header
*lh
)
12458 if (lh
->standard_opcode_lengths
)
12459 xfree (lh
->standard_opcode_lengths
);
12461 /* Remember that all the lh->file_names[i].name pointers are
12462 pointers into debug_line_buffer, and don't need to be freed. */
12463 if (lh
->file_names
)
12464 xfree (lh
->file_names
);
12466 /* Similarly for the include directory names. */
12467 if (lh
->include_dirs
)
12468 xfree (lh
->include_dirs
);
12473 /* Add an entry to LH's include directory table. */
12476 add_include_dir (struct line_header
*lh
, char *include_dir
)
12478 /* Grow the array if necessary. */
12479 if (lh
->include_dirs_size
== 0)
12481 lh
->include_dirs_size
= 1; /* for testing */
12482 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
12483 * sizeof (*lh
->include_dirs
));
12485 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
12487 lh
->include_dirs_size
*= 2;
12488 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
12489 (lh
->include_dirs_size
12490 * sizeof (*lh
->include_dirs
)));
12493 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
12496 /* Add an entry to LH's file name table. */
12499 add_file_name (struct line_header
*lh
,
12501 unsigned int dir_index
,
12502 unsigned int mod_time
,
12503 unsigned int length
)
12505 struct file_entry
*fe
;
12507 /* Grow the array if necessary. */
12508 if (lh
->file_names_size
== 0)
12510 lh
->file_names_size
= 1; /* for testing */
12511 lh
->file_names
= xmalloc (lh
->file_names_size
12512 * sizeof (*lh
->file_names
));
12514 else if (lh
->num_file_names
>= lh
->file_names_size
)
12516 lh
->file_names_size
*= 2;
12517 lh
->file_names
= xrealloc (lh
->file_names
,
12518 (lh
->file_names_size
12519 * sizeof (*lh
->file_names
)));
12522 fe
= &lh
->file_names
[lh
->num_file_names
++];
12524 fe
->dir_index
= dir_index
;
12525 fe
->mod_time
= mod_time
;
12526 fe
->length
= length
;
12527 fe
->included_p
= 0;
12531 /* Read the statement program header starting at OFFSET in
12532 .debug_line, or .debug_line.dwo. Return a pointer
12533 to a struct line_header, allocated using xmalloc.
12535 NOTE: the strings in the include directory and file name tables of
12536 the returned object point into the dwarf line section buffer,
12537 and must not be freed. */
12539 static struct line_header
*
12540 dwarf_decode_line_header (unsigned int offset
, struct dwarf2_cu
*cu
)
12542 struct cleanup
*back_to
;
12543 struct line_header
*lh
;
12544 gdb_byte
*line_ptr
;
12545 unsigned int bytes_read
, offset_size
;
12547 char *cur_dir
, *cur_file
;
12548 struct dwarf2_section_info
*section
;
12551 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
12553 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
12554 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
12556 section
= &dwarf2_per_objfile
->line
;
12558 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
12559 if (section
->buffer
== NULL
)
12561 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
12562 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
12564 complaint (&symfile_complaints
, _("missing .debug_line section"));
12568 /* We can't do this until we know the section is non-empty.
12569 Only then do we know we have such a section. */
12570 abfd
= section
->asection
->owner
;
12572 /* Make sure that at least there's room for the total_length field.
12573 That could be 12 bytes long, but we're just going to fudge that. */
12574 if (offset
+ 4 >= section
->size
)
12576 dwarf2_statement_list_fits_in_line_number_section_complaint ();
12580 lh
= xmalloc (sizeof (*lh
));
12581 memset (lh
, 0, sizeof (*lh
));
12582 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
12585 line_ptr
= section
->buffer
+ offset
;
12587 /* Read in the header. */
12589 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
12590 &bytes_read
, &offset_size
);
12591 line_ptr
+= bytes_read
;
12592 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
12594 dwarf2_statement_list_fits_in_line_number_section_complaint ();
12597 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
12598 lh
->version
= read_2_bytes (abfd
, line_ptr
);
12600 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
12601 line_ptr
+= offset_size
;
12602 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
12604 if (lh
->version
>= 4)
12606 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
12610 lh
->maximum_ops_per_instruction
= 1;
12612 if (lh
->maximum_ops_per_instruction
== 0)
12614 lh
->maximum_ops_per_instruction
= 1;
12615 complaint (&symfile_complaints
,
12616 _("invalid maximum_ops_per_instruction "
12617 "in `.debug_line' section"));
12620 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
12622 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
12624 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
12626 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
12628 lh
->standard_opcode_lengths
12629 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
12631 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
12632 for (i
= 1; i
< lh
->opcode_base
; ++i
)
12634 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
12638 /* Read directory table. */
12639 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
12641 line_ptr
+= bytes_read
;
12642 add_include_dir (lh
, cur_dir
);
12644 line_ptr
+= bytes_read
;
12646 /* Read file name table. */
12647 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
12649 unsigned int dir_index
, mod_time
, length
;
12651 line_ptr
+= bytes_read
;
12652 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12653 line_ptr
+= bytes_read
;
12654 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12655 line_ptr
+= bytes_read
;
12656 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12657 line_ptr
+= bytes_read
;
12659 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
12661 line_ptr
+= bytes_read
;
12662 lh
->statement_program_start
= line_ptr
;
12664 if (line_ptr
> (section
->buffer
+ section
->size
))
12665 complaint (&symfile_complaints
,
12666 _("line number info header doesn't "
12667 "fit in `.debug_line' section"));
12669 discard_cleanups (back_to
);
12673 /* Subroutine of dwarf_decode_lines to simplify it.
12674 Return the file name of the psymtab for included file FILE_INDEX
12675 in line header LH of PST.
12676 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
12677 If space for the result is malloc'd, it will be freed by a cleanup.
12678 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
12681 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
12682 const struct partial_symtab
*pst
,
12683 const char *comp_dir
)
12685 const struct file_entry fe
= lh
->file_names
[file_index
];
12686 char *include_name
= fe
.name
;
12687 char *include_name_to_compare
= include_name
;
12688 char *dir_name
= NULL
;
12689 const char *pst_filename
;
12690 char *copied_name
= NULL
;
12694 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
12696 if (!IS_ABSOLUTE_PATH (include_name
)
12697 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
12699 /* Avoid creating a duplicate psymtab for PST.
12700 We do this by comparing INCLUDE_NAME and PST_FILENAME.
12701 Before we do the comparison, however, we need to account
12702 for DIR_NAME and COMP_DIR.
12703 First prepend dir_name (if non-NULL). If we still don't
12704 have an absolute path prepend comp_dir (if non-NULL).
12705 However, the directory we record in the include-file's
12706 psymtab does not contain COMP_DIR (to match the
12707 corresponding symtab(s)).
12712 bash$ gcc -g ./hello.c
12713 include_name = "hello.c"
12715 DW_AT_comp_dir = comp_dir = "/tmp"
12716 DW_AT_name = "./hello.c" */
12718 if (dir_name
!= NULL
)
12720 include_name
= concat (dir_name
, SLASH_STRING
,
12721 include_name
, (char *)NULL
);
12722 include_name_to_compare
= include_name
;
12723 make_cleanup (xfree
, include_name
);
12725 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
12727 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
12728 include_name
, (char *)NULL
);
12732 pst_filename
= pst
->filename
;
12733 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
12735 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
12736 pst_filename
, (char *)NULL
);
12737 pst_filename
= copied_name
;
12740 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
12742 if (include_name_to_compare
!= include_name
)
12743 xfree (include_name_to_compare
);
12744 if (copied_name
!= NULL
)
12745 xfree (copied_name
);
12749 return include_name
;
12752 /* Ignore this record_line request. */
12755 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
12760 /* Subroutine of dwarf_decode_lines to simplify it.
12761 Process the line number information in LH. */
12764 dwarf_decode_lines_1 (struct line_header
*lh
, const char *comp_dir
,
12765 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
12767 gdb_byte
*line_ptr
, *extended_end
;
12768 gdb_byte
*line_end
;
12769 unsigned int bytes_read
, extended_len
;
12770 unsigned char op_code
, extended_op
, adj_opcode
;
12771 CORE_ADDR baseaddr
;
12772 struct objfile
*objfile
= cu
->objfile
;
12773 bfd
*abfd
= objfile
->obfd
;
12774 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12775 const int decode_for_pst_p
= (pst
!= NULL
);
12776 struct subfile
*last_subfile
= NULL
;
12777 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
12780 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
12782 line_ptr
= lh
->statement_program_start
;
12783 line_end
= lh
->statement_program_end
;
12785 /* Read the statement sequences until there's nothing left. */
12786 while (line_ptr
< line_end
)
12788 /* state machine registers */
12789 CORE_ADDR address
= 0;
12790 unsigned int file
= 1;
12791 unsigned int line
= 1;
12792 unsigned int column
= 0;
12793 int is_stmt
= lh
->default_is_stmt
;
12794 int basic_block
= 0;
12795 int end_sequence
= 0;
12797 unsigned char op_index
= 0;
12799 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
12801 /* Start a subfile for the current file of the state machine. */
12802 /* lh->include_dirs and lh->file_names are 0-based, but the
12803 directory and file name numbers in the statement program
12805 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
12809 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
12811 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
12814 /* Decode the table. */
12815 while (!end_sequence
)
12817 op_code
= read_1_byte (abfd
, line_ptr
);
12819 if (line_ptr
> line_end
)
12821 dwarf2_debug_line_missing_end_sequence_complaint ();
12825 if (op_code
>= lh
->opcode_base
)
12827 /* Special operand. */
12828 adj_opcode
= op_code
- lh
->opcode_base
;
12829 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
12830 / lh
->maximum_ops_per_instruction
)
12831 * lh
->minimum_instruction_length
);
12832 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
12833 % lh
->maximum_ops_per_instruction
);
12834 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
12835 if (lh
->num_file_names
< file
|| file
== 0)
12836 dwarf2_debug_line_missing_file_complaint ();
12837 /* For now we ignore lines not starting on an
12838 instruction boundary. */
12839 else if (op_index
== 0)
12841 lh
->file_names
[file
- 1].included_p
= 1;
12842 if (!decode_for_pst_p
&& is_stmt
)
12844 if (last_subfile
!= current_subfile
)
12846 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
12848 (*p_record_line
) (last_subfile
, 0, addr
);
12849 last_subfile
= current_subfile
;
12851 /* Append row to matrix using current values. */
12852 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
12853 (*p_record_line
) (current_subfile
, line
, addr
);
12858 else switch (op_code
)
12860 case DW_LNS_extended_op
:
12861 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
12863 line_ptr
+= bytes_read
;
12864 extended_end
= line_ptr
+ extended_len
;
12865 extended_op
= read_1_byte (abfd
, line_ptr
);
12867 switch (extended_op
)
12869 case DW_LNE_end_sequence
:
12870 p_record_line
= record_line
;
12873 case DW_LNE_set_address
:
12874 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
12876 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
12878 /* This line table is for a function which has been
12879 GCd by the linker. Ignore it. PR gdb/12528 */
12882 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
12884 complaint (&symfile_complaints
,
12885 _(".debug_line address at offset 0x%lx is 0 "
12887 line_offset
, objfile
->name
);
12888 p_record_line
= noop_record_line
;
12892 line_ptr
+= bytes_read
;
12893 address
+= baseaddr
;
12895 case DW_LNE_define_file
:
12898 unsigned int dir_index
, mod_time
, length
;
12900 cur_file
= read_direct_string (abfd
, line_ptr
,
12902 line_ptr
+= bytes_read
;
12904 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12905 line_ptr
+= bytes_read
;
12907 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12908 line_ptr
+= bytes_read
;
12910 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12911 line_ptr
+= bytes_read
;
12912 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
12915 case DW_LNE_set_discriminator
:
12916 /* The discriminator is not interesting to the debugger;
12918 line_ptr
= extended_end
;
12921 complaint (&symfile_complaints
,
12922 _("mangled .debug_line section"));
12925 /* Make sure that we parsed the extended op correctly. If e.g.
12926 we expected a different address size than the producer used,
12927 we may have read the wrong number of bytes. */
12928 if (line_ptr
!= extended_end
)
12930 complaint (&symfile_complaints
,
12931 _("mangled .debug_line section"));
12936 if (lh
->num_file_names
< file
|| file
== 0)
12937 dwarf2_debug_line_missing_file_complaint ();
12940 lh
->file_names
[file
- 1].included_p
= 1;
12941 if (!decode_for_pst_p
&& is_stmt
)
12943 if (last_subfile
!= current_subfile
)
12945 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
12947 (*p_record_line
) (last_subfile
, 0, addr
);
12948 last_subfile
= current_subfile
;
12950 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
12951 (*p_record_line
) (current_subfile
, line
, addr
);
12956 case DW_LNS_advance_pc
:
12959 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12961 address
+= (((op_index
+ adjust
)
12962 / lh
->maximum_ops_per_instruction
)
12963 * lh
->minimum_instruction_length
);
12964 op_index
= ((op_index
+ adjust
)
12965 % lh
->maximum_ops_per_instruction
);
12966 line_ptr
+= bytes_read
;
12969 case DW_LNS_advance_line
:
12970 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
12971 line_ptr
+= bytes_read
;
12973 case DW_LNS_set_file
:
12975 /* The arrays lh->include_dirs and lh->file_names are
12976 0-based, but the directory and file name numbers in
12977 the statement program are 1-based. */
12978 struct file_entry
*fe
;
12981 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12982 line_ptr
+= bytes_read
;
12983 if (lh
->num_file_names
< file
|| file
== 0)
12984 dwarf2_debug_line_missing_file_complaint ();
12987 fe
= &lh
->file_names
[file
- 1];
12989 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
12990 if (!decode_for_pst_p
)
12992 last_subfile
= current_subfile
;
12993 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
12998 case DW_LNS_set_column
:
12999 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13000 line_ptr
+= bytes_read
;
13002 case DW_LNS_negate_stmt
:
13003 is_stmt
= (!is_stmt
);
13005 case DW_LNS_set_basic_block
:
13008 /* Add to the address register of the state machine the
13009 address increment value corresponding to special opcode
13010 255. I.e., this value is scaled by the minimum
13011 instruction length since special opcode 255 would have
13012 scaled the increment. */
13013 case DW_LNS_const_add_pc
:
13015 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
13017 address
+= (((op_index
+ adjust
)
13018 / lh
->maximum_ops_per_instruction
)
13019 * lh
->minimum_instruction_length
);
13020 op_index
= ((op_index
+ adjust
)
13021 % lh
->maximum_ops_per_instruction
);
13024 case DW_LNS_fixed_advance_pc
:
13025 address
+= read_2_bytes (abfd
, line_ptr
);
13031 /* Unknown standard opcode, ignore it. */
13034 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
13036 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13037 line_ptr
+= bytes_read
;
13042 if (lh
->num_file_names
< file
|| file
== 0)
13043 dwarf2_debug_line_missing_file_complaint ();
13046 lh
->file_names
[file
- 1].included_p
= 1;
13047 if (!decode_for_pst_p
)
13049 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
13050 (*p_record_line
) (current_subfile
, 0, addr
);
13056 /* Decode the Line Number Program (LNP) for the given line_header
13057 structure and CU. The actual information extracted and the type
13058 of structures created from the LNP depends on the value of PST.
13060 1. If PST is NULL, then this procedure uses the data from the program
13061 to create all necessary symbol tables, and their linetables.
13063 2. If PST is not NULL, this procedure reads the program to determine
13064 the list of files included by the unit represented by PST, and
13065 builds all the associated partial symbol tables.
13067 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
13068 It is used for relative paths in the line table.
13069 NOTE: When processing partial symtabs (pst != NULL),
13070 comp_dir == pst->dirname.
13072 NOTE: It is important that psymtabs have the same file name (via strcmp)
13073 as the corresponding symtab. Since COMP_DIR is not used in the name of the
13074 symtab we don't use it in the name of the psymtabs we create.
13075 E.g. expand_line_sal requires this when finding psymtabs to expand.
13076 A good testcase for this is mb-inline.exp. */
13079 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
13080 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
13081 int want_line_info
)
13083 struct objfile
*objfile
= cu
->objfile
;
13084 const int decode_for_pst_p
= (pst
!= NULL
);
13085 struct subfile
*first_subfile
= current_subfile
;
13087 if (want_line_info
)
13088 dwarf_decode_lines_1 (lh
, comp_dir
, cu
, pst
);
13090 if (decode_for_pst_p
)
13094 /* Now that we're done scanning the Line Header Program, we can
13095 create the psymtab of each included file. */
13096 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
13097 if (lh
->file_names
[file_index
].included_p
== 1)
13099 char *include_name
=
13100 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
13101 if (include_name
!= NULL
)
13102 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
13107 /* Make sure a symtab is created for every file, even files
13108 which contain only variables (i.e. no code with associated
13112 for (i
= 0; i
< lh
->num_file_names
; i
++)
13115 struct file_entry
*fe
;
13117 fe
= &lh
->file_names
[i
];
13119 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
13120 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
13122 /* Skip the main file; we don't need it, and it must be
13123 allocated last, so that it will show up before the
13124 non-primary symtabs in the objfile's symtab list. */
13125 if (current_subfile
== first_subfile
)
13128 if (current_subfile
->symtab
== NULL
)
13129 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
13131 fe
->symtab
= current_subfile
->symtab
;
13136 /* Start a subfile for DWARF. FILENAME is the name of the file and
13137 DIRNAME the name of the source directory which contains FILENAME
13138 or NULL if not known. COMP_DIR is the compilation directory for the
13139 linetable's compilation unit or NULL if not known.
13140 This routine tries to keep line numbers from identical absolute and
13141 relative file names in a common subfile.
13143 Using the `list' example from the GDB testsuite, which resides in
13144 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
13145 of /srcdir/list0.c yields the following debugging information for list0.c:
13147 DW_AT_name: /srcdir/list0.c
13148 DW_AT_comp_dir: /compdir
13149 files.files[0].name: list0.h
13150 files.files[0].dir: /srcdir
13151 files.files[1].name: list0.c
13152 files.files[1].dir: /srcdir
13154 The line number information for list0.c has to end up in a single
13155 subfile, so that `break /srcdir/list0.c:1' works as expected.
13156 start_subfile will ensure that this happens provided that we pass the
13157 concatenation of files.files[1].dir and files.files[1].name as the
13161 dwarf2_start_subfile (char *filename
, const char *dirname
,
13162 const char *comp_dir
)
13166 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
13167 `start_symtab' will always pass the contents of DW_AT_comp_dir as
13168 second argument to start_subfile. To be consistent, we do the
13169 same here. In order not to lose the line information directory,
13170 we concatenate it to the filename when it makes sense.
13171 Note that the Dwarf3 standard says (speaking of filenames in line
13172 information): ``The directory index is ignored for file names
13173 that represent full path names''. Thus ignoring dirname in the
13174 `else' branch below isn't an issue. */
13176 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
13177 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
13179 fullname
= filename
;
13181 start_subfile (fullname
, comp_dir
);
13183 if (fullname
!= filename
)
13188 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
13189 struct dwarf2_cu
*cu
)
13191 struct objfile
*objfile
= cu
->objfile
;
13192 struct comp_unit_head
*cu_header
= &cu
->header
;
13194 /* NOTE drow/2003-01-30: There used to be a comment and some special
13195 code here to turn a symbol with DW_AT_external and a
13196 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
13197 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
13198 with some versions of binutils) where shared libraries could have
13199 relocations against symbols in their debug information - the
13200 minimal symbol would have the right address, but the debug info
13201 would not. It's no longer necessary, because we will explicitly
13202 apply relocations when we read in the debug information now. */
13204 /* A DW_AT_location attribute with no contents indicates that a
13205 variable has been optimized away. */
13206 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
13208 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
13212 /* Handle one degenerate form of location expression specially, to
13213 preserve GDB's previous behavior when section offsets are
13214 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
13215 then mark this symbol as LOC_STATIC. */
13217 if (attr_form_is_block (attr
)
13218 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
13219 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
13220 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
13221 && (DW_BLOCK (attr
)->size
13222 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
13224 unsigned int dummy
;
13226 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
13227 SYMBOL_VALUE_ADDRESS (sym
) =
13228 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
13230 SYMBOL_VALUE_ADDRESS (sym
) =
13231 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
13232 SYMBOL_CLASS (sym
) = LOC_STATIC
;
13233 fixup_symbol_section (sym
, objfile
);
13234 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
13235 SYMBOL_SECTION (sym
));
13239 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
13240 expression evaluator, and use LOC_COMPUTED only when necessary
13241 (i.e. when the value of a register or memory location is
13242 referenced, or a thread-local block, etc.). Then again, it might
13243 not be worthwhile. I'm assuming that it isn't unless performance
13244 or memory numbers show me otherwise. */
13246 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
13247 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
13249 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
13250 cu
->has_loclist
= 1;
13253 /* Given a pointer to a DWARF information entry, figure out if we need
13254 to make a symbol table entry for it, and if so, create a new entry
13255 and return a pointer to it.
13256 If TYPE is NULL, determine symbol type from the die, otherwise
13257 used the passed type.
13258 If SPACE is not NULL, use it to hold the new symbol. If it is
13259 NULL, allocate a new symbol on the objfile's obstack. */
13261 static struct symbol
*
13262 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
13263 struct symbol
*space
)
13265 struct objfile
*objfile
= cu
->objfile
;
13266 struct symbol
*sym
= NULL
;
13268 struct attribute
*attr
= NULL
;
13269 struct attribute
*attr2
= NULL
;
13270 CORE_ADDR baseaddr
;
13271 struct pending
**list_to_add
= NULL
;
13273 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13275 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13277 name
= dwarf2_name (die
, cu
);
13280 const char *linkagename
;
13281 int suppress_add
= 0;
13286 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
13287 OBJSTAT (objfile
, n_syms
++);
13289 /* Cache this symbol's name and the name's demangled form (if any). */
13290 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
13291 linkagename
= dwarf2_physname (name
, die
, cu
);
13292 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
13294 /* Fortran does not have mangling standard and the mangling does differ
13295 between gfortran, iFort etc. */
13296 if (cu
->language
== language_fortran
13297 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
13298 symbol_set_demangled_name (&(sym
->ginfo
),
13299 (char *) dwarf2_full_name (name
, die
, cu
),
13302 /* Default assumptions.
13303 Use the passed type or decode it from the die. */
13304 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
13305 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
13307 SYMBOL_TYPE (sym
) = type
;
13309 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
13310 attr
= dwarf2_attr (die
,
13311 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
13315 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
13318 attr
= dwarf2_attr (die
,
13319 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
13323 int file_index
= DW_UNSND (attr
);
13325 if (cu
->line_header
== NULL
13326 || file_index
> cu
->line_header
->num_file_names
)
13327 complaint (&symfile_complaints
,
13328 _("file index out of range"));
13329 else if (file_index
> 0)
13331 struct file_entry
*fe
;
13333 fe
= &cu
->line_header
->file_names
[file_index
- 1];
13334 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
13341 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13344 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
13346 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
13347 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
13348 SYMBOL_CLASS (sym
) = LOC_LABEL
;
13349 add_symbol_to_list (sym
, cu
->list_in_scope
);
13351 case DW_TAG_subprogram
:
13352 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
13354 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
13355 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13356 if ((attr2
&& (DW_UNSND (attr2
) != 0))
13357 || cu
->language
== language_ada
)
13359 /* Subprograms marked external are stored as a global symbol.
13360 Ada subprograms, whether marked external or not, are always
13361 stored as a global symbol, because we want to be able to
13362 access them globally. For instance, we want to be able
13363 to break on a nested subprogram without having to
13364 specify the context. */
13365 list_to_add
= &global_symbols
;
13369 list_to_add
= cu
->list_in_scope
;
13372 case DW_TAG_inlined_subroutine
:
13373 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
13375 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
13376 SYMBOL_INLINED (sym
) = 1;
13377 list_to_add
= cu
->list_in_scope
;
13379 case DW_TAG_template_value_param
:
13381 /* Fall through. */
13382 case DW_TAG_constant
:
13383 case DW_TAG_variable
:
13384 case DW_TAG_member
:
13385 /* Compilation with minimal debug info may result in
13386 variables with missing type entries. Change the
13387 misleading `void' type to something sensible. */
13388 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
13390 = objfile_type (objfile
)->nodebug_data_symbol
;
13392 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13393 /* In the case of DW_TAG_member, we should only be called for
13394 static const members. */
13395 if (die
->tag
== DW_TAG_member
)
13397 /* dwarf2_add_field uses die_is_declaration,
13398 so we do the same. */
13399 gdb_assert (die_is_declaration (die
, cu
));
13404 dwarf2_const_value (attr
, sym
, cu
);
13405 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13408 if (attr2
&& (DW_UNSND (attr2
) != 0))
13409 list_to_add
= &global_symbols
;
13411 list_to_add
= cu
->list_in_scope
;
13415 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13418 var_decode_location (attr
, sym
, cu
);
13419 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13420 if (SYMBOL_CLASS (sym
) == LOC_STATIC
13421 && SYMBOL_VALUE_ADDRESS (sym
) == 0
13422 && !dwarf2_per_objfile
->has_section_at_zero
)
13424 /* When a static variable is eliminated by the linker,
13425 the corresponding debug information is not stripped
13426 out, but the variable address is set to null;
13427 do not add such variables into symbol table. */
13429 else if (attr2
&& (DW_UNSND (attr2
) != 0))
13431 /* Workaround gfortran PR debug/40040 - it uses
13432 DW_AT_location for variables in -fPIC libraries which may
13433 get overriden by other libraries/executable and get
13434 a different address. Resolve it by the minimal symbol
13435 which may come from inferior's executable using copy
13436 relocation. Make this workaround only for gfortran as for
13437 other compilers GDB cannot guess the minimal symbol
13438 Fortran mangling kind. */
13439 if (cu
->language
== language_fortran
&& die
->parent
13440 && die
->parent
->tag
== DW_TAG_module
13442 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
13443 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
13445 /* A variable with DW_AT_external is never static,
13446 but it may be block-scoped. */
13447 list_to_add
= (cu
->list_in_scope
== &file_symbols
13448 ? &global_symbols
: cu
->list_in_scope
);
13451 list_to_add
= cu
->list_in_scope
;
13455 /* We do not know the address of this symbol.
13456 If it is an external symbol and we have type information
13457 for it, enter the symbol as a LOC_UNRESOLVED symbol.
13458 The address of the variable will then be determined from
13459 the minimal symbol table whenever the variable is
13461 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13462 if (attr2
&& (DW_UNSND (attr2
) != 0)
13463 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
13465 /* A variable with DW_AT_external is never static, but it
13466 may be block-scoped. */
13467 list_to_add
= (cu
->list_in_scope
== &file_symbols
13468 ? &global_symbols
: cu
->list_in_scope
);
13470 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
13472 else if (!die_is_declaration (die
, cu
))
13474 /* Use the default LOC_OPTIMIZED_OUT class. */
13475 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
13477 list_to_add
= cu
->list_in_scope
;
13481 case DW_TAG_formal_parameter
:
13482 /* If we are inside a function, mark this as an argument. If
13483 not, we might be looking at an argument to an inlined function
13484 when we do not have enough information to show inlined frames;
13485 pretend it's a local variable in that case so that the user can
13487 if (context_stack_depth
> 0
13488 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
13489 SYMBOL_IS_ARGUMENT (sym
) = 1;
13490 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13493 var_decode_location (attr
, sym
, cu
);
13495 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13498 dwarf2_const_value (attr
, sym
, cu
);
13501 list_to_add
= cu
->list_in_scope
;
13503 case DW_TAG_unspecified_parameters
:
13504 /* From varargs functions; gdb doesn't seem to have any
13505 interest in this information, so just ignore it for now.
13508 case DW_TAG_template_type_param
:
13510 /* Fall through. */
13511 case DW_TAG_class_type
:
13512 case DW_TAG_interface_type
:
13513 case DW_TAG_structure_type
:
13514 case DW_TAG_union_type
:
13515 case DW_TAG_set_type
:
13516 case DW_TAG_enumeration_type
:
13517 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13518 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
13521 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
13522 really ever be static objects: otherwise, if you try
13523 to, say, break of a class's method and you're in a file
13524 which doesn't mention that class, it won't work unless
13525 the check for all static symbols in lookup_symbol_aux
13526 saves you. See the OtherFileClass tests in
13527 gdb.c++/namespace.exp. */
13531 list_to_add
= (cu
->list_in_scope
== &file_symbols
13532 && (cu
->language
== language_cplus
13533 || cu
->language
== language_java
)
13534 ? &global_symbols
: cu
->list_in_scope
);
13536 /* The semantics of C++ state that "struct foo {
13537 ... }" also defines a typedef for "foo". A Java
13538 class declaration also defines a typedef for the
13540 if (cu
->language
== language_cplus
13541 || cu
->language
== language_java
13542 || cu
->language
== language_ada
)
13544 /* The symbol's name is already allocated along
13545 with this objfile, so we don't need to
13546 duplicate it for the type. */
13547 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
13548 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
13553 case DW_TAG_typedef
:
13554 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13555 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
13556 list_to_add
= cu
->list_in_scope
;
13558 case DW_TAG_base_type
:
13559 case DW_TAG_subrange_type
:
13560 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13561 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
13562 list_to_add
= cu
->list_in_scope
;
13564 case DW_TAG_enumerator
:
13565 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13568 dwarf2_const_value (attr
, sym
, cu
);
13571 /* NOTE: carlton/2003-11-10: See comment above in the
13572 DW_TAG_class_type, etc. block. */
13574 list_to_add
= (cu
->list_in_scope
== &file_symbols
13575 && (cu
->language
== language_cplus
13576 || cu
->language
== language_java
)
13577 ? &global_symbols
: cu
->list_in_scope
);
13580 case DW_TAG_namespace
:
13581 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13582 list_to_add
= &global_symbols
;
13585 /* Not a tag we recognize. Hopefully we aren't processing
13586 trash data, but since we must specifically ignore things
13587 we don't recognize, there is nothing else we should do at
13589 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
13590 dwarf_tag_name (die
->tag
));
13596 sym
->hash_next
= objfile
->template_symbols
;
13597 objfile
->template_symbols
= sym
;
13598 list_to_add
= NULL
;
13601 if (list_to_add
!= NULL
)
13602 add_symbol_to_list (sym
, list_to_add
);
13604 /* For the benefit of old versions of GCC, check for anonymous
13605 namespaces based on the demangled name. */
13606 if (!processing_has_namespace_info
13607 && cu
->language
== language_cplus
)
13608 cp_scan_for_anonymous_namespaces (sym
, objfile
);
13613 /* A wrapper for new_symbol_full that always allocates a new symbol. */
13615 static struct symbol
*
13616 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
13618 return new_symbol_full (die
, type
, cu
, NULL
);
13621 /* Given an attr with a DW_FORM_dataN value in host byte order,
13622 zero-extend it as appropriate for the symbol's type. The DWARF
13623 standard (v4) is not entirely clear about the meaning of using
13624 DW_FORM_dataN for a constant with a signed type, where the type is
13625 wider than the data. The conclusion of a discussion on the DWARF
13626 list was that this is unspecified. We choose to always zero-extend
13627 because that is the interpretation long in use by GCC. */
13630 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
13631 const char *name
, struct obstack
*obstack
,
13632 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
13634 struct objfile
*objfile
= cu
->objfile
;
13635 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
13636 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
13637 LONGEST l
= DW_UNSND (attr
);
13639 if (bits
< sizeof (*value
) * 8)
13641 l
&= ((LONGEST
) 1 << bits
) - 1;
13644 else if (bits
== sizeof (*value
) * 8)
13648 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
13649 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
13656 /* Read a constant value from an attribute. Either set *VALUE, or if
13657 the value does not fit in *VALUE, set *BYTES - either already
13658 allocated on the objfile obstack, or newly allocated on OBSTACK,
13659 or, set *BATON, if we translated the constant to a location
13663 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
13664 const char *name
, struct obstack
*obstack
,
13665 struct dwarf2_cu
*cu
,
13666 LONGEST
*value
, gdb_byte
**bytes
,
13667 struct dwarf2_locexpr_baton
**baton
)
13669 struct objfile
*objfile
= cu
->objfile
;
13670 struct comp_unit_head
*cu_header
= &cu
->header
;
13671 struct dwarf_block
*blk
;
13672 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
13673 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
13679 switch (attr
->form
)
13682 case DW_FORM_GNU_addr_index
:
13686 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
13687 dwarf2_const_value_length_mismatch_complaint (name
,
13688 cu_header
->addr_size
,
13689 TYPE_LENGTH (type
));
13690 /* Symbols of this form are reasonably rare, so we just
13691 piggyback on the existing location code rather than writing
13692 a new implementation of symbol_computed_ops. */
13693 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
13694 sizeof (struct dwarf2_locexpr_baton
));
13695 (*baton
)->per_cu
= cu
->per_cu
;
13696 gdb_assert ((*baton
)->per_cu
);
13698 (*baton
)->size
= 2 + cu_header
->addr_size
;
13699 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
13700 (*baton
)->data
= data
;
13702 data
[0] = DW_OP_addr
;
13703 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
13704 byte_order
, DW_ADDR (attr
));
13705 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
13708 case DW_FORM_string
:
13710 case DW_FORM_GNU_str_index
:
13711 /* DW_STRING is already allocated on the objfile obstack, point
13713 *bytes
= (gdb_byte
*) DW_STRING (attr
);
13715 case DW_FORM_block1
:
13716 case DW_FORM_block2
:
13717 case DW_FORM_block4
:
13718 case DW_FORM_block
:
13719 case DW_FORM_exprloc
:
13720 blk
= DW_BLOCK (attr
);
13721 if (TYPE_LENGTH (type
) != blk
->size
)
13722 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
13723 TYPE_LENGTH (type
));
13724 *bytes
= blk
->data
;
13727 /* The DW_AT_const_value attributes are supposed to carry the
13728 symbol's value "represented as it would be on the target
13729 architecture." By the time we get here, it's already been
13730 converted to host endianness, so we just need to sign- or
13731 zero-extend it as appropriate. */
13732 case DW_FORM_data1
:
13733 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
13734 obstack
, cu
, value
, 8);
13736 case DW_FORM_data2
:
13737 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
13738 obstack
, cu
, value
, 16);
13740 case DW_FORM_data4
:
13741 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
13742 obstack
, cu
, value
, 32);
13744 case DW_FORM_data8
:
13745 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
13746 obstack
, cu
, value
, 64);
13749 case DW_FORM_sdata
:
13750 *value
= DW_SND (attr
);
13753 case DW_FORM_udata
:
13754 *value
= DW_UNSND (attr
);
13758 complaint (&symfile_complaints
,
13759 _("unsupported const value attribute form: '%s'"),
13760 dwarf_form_name (attr
->form
));
13767 /* Copy constant value from an attribute to a symbol. */
13770 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
13771 struct dwarf2_cu
*cu
)
13773 struct objfile
*objfile
= cu
->objfile
;
13774 struct comp_unit_head
*cu_header
= &cu
->header
;
13777 struct dwarf2_locexpr_baton
*baton
;
13779 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
13780 SYMBOL_PRINT_NAME (sym
),
13781 &objfile
->objfile_obstack
, cu
,
13782 &value
, &bytes
, &baton
);
13786 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
13787 SYMBOL_LOCATION_BATON (sym
) = baton
;
13788 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
13790 else if (bytes
!= NULL
)
13792 SYMBOL_VALUE_BYTES (sym
) = bytes
;
13793 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
13797 SYMBOL_VALUE (sym
) = value
;
13798 SYMBOL_CLASS (sym
) = LOC_CONST
;
13802 /* Return the type of the die in question using its DW_AT_type attribute. */
13804 static struct type
*
13805 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13807 struct attribute
*type_attr
;
13809 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13812 /* A missing DW_AT_type represents a void type. */
13813 return objfile_type (cu
->objfile
)->builtin_void
;
13816 return lookup_die_type (die
, type_attr
, cu
);
13819 /* True iff CU's producer generates GNAT Ada auxiliary information
13820 that allows to find parallel types through that information instead
13821 of having to do expensive parallel lookups by type name. */
13824 need_gnat_info (struct dwarf2_cu
*cu
)
13826 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
13827 of GNAT produces this auxiliary information, without any indication
13828 that it is produced. Part of enhancing the FSF version of GNAT
13829 to produce that information will be to put in place an indicator
13830 that we can use in order to determine whether the descriptive type
13831 info is available or not. One suggestion that has been made is
13832 to use a new attribute, attached to the CU die. For now, assume
13833 that the descriptive type info is not available. */
13837 /* Return the auxiliary type of the die in question using its
13838 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
13839 attribute is not present. */
13841 static struct type
*
13842 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13844 struct attribute
*type_attr
;
13846 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
13850 return lookup_die_type (die
, type_attr
, cu
);
13853 /* If DIE has a descriptive_type attribute, then set the TYPE's
13854 descriptive type accordingly. */
13857 set_descriptive_type (struct type
*type
, struct die_info
*die
,
13858 struct dwarf2_cu
*cu
)
13860 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
13862 if (descriptive_type
)
13864 ALLOCATE_GNAT_AUX_TYPE (type
);
13865 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
13869 /* Return the containing type of the die in question using its
13870 DW_AT_containing_type attribute. */
13872 static struct type
*
13873 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13875 struct attribute
*type_attr
;
13877 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
13879 error (_("Dwarf Error: Problem turning containing type into gdb type "
13880 "[in module %s]"), cu
->objfile
->name
);
13882 return lookup_die_type (die
, type_attr
, cu
);
13885 /* Look up the type of DIE in CU using its type attribute ATTR.
13886 If there is no type substitute an error marker. */
13888 static struct type
*
13889 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
13890 struct dwarf2_cu
*cu
)
13892 struct objfile
*objfile
= cu
->objfile
;
13893 struct type
*this_type
;
13895 /* First see if we have it cached. */
13897 if (is_ref_attr (attr
))
13899 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
13901 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
13903 else if (attr
->form
== DW_FORM_ref_sig8
)
13905 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
13907 /* sig_type will be NULL if the signatured type is missing from
13909 if (sig_type
== NULL
)
13910 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
13911 "at 0x%x [in module %s]"),
13912 die
->offset
.sect_off
, objfile
->name
);
13914 gdb_assert (sig_type
->per_cu
.is_debug_types
);
13915 /* If we haven't filled in type_offset_in_section yet, then we
13916 haven't read the type in yet. */
13918 if (sig_type
->type_offset_in_section
.sect_off
!= 0)
13921 get_die_type_at_offset (sig_type
->type_offset_in_section
,
13922 &sig_type
->per_cu
);
13927 dump_die_for_error (die
);
13928 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
13929 dwarf_attr_name (attr
->name
), objfile
->name
);
13932 /* If not cached we need to read it in. */
13934 if (this_type
== NULL
)
13936 struct die_info
*type_die
;
13937 struct dwarf2_cu
*type_cu
= cu
;
13939 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
13940 /* If we found the type now, it's probably because the type came
13941 from an inter-CU reference and the type's CU got expanded before
13943 this_type
= get_die_type (type_die
, type_cu
);
13944 if (this_type
== NULL
)
13945 this_type
= read_type_die_1 (type_die
, type_cu
);
13948 /* If we still don't have a type use an error marker. */
13950 if (this_type
== NULL
)
13952 char *message
, *saved
;
13954 /* read_type_die already issued a complaint. */
13955 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
13957 cu
->header
.offset
.sect_off
,
13958 die
->offset
.sect_off
);
13959 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
13960 message
, strlen (message
));
13963 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
13969 /* Return the type in DIE, CU.
13970 Returns NULL for invalid types.
13972 This first does a lookup in the appropriate type_hash table,
13973 and only reads the die in if necessary.
13975 NOTE: This can be called when reading in partial or full symbols. */
13977 static struct type
*
13978 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
13980 struct type
*this_type
;
13982 this_type
= get_die_type (die
, cu
);
13986 return read_type_die_1 (die
, cu
);
13989 /* Read the type in DIE, CU.
13990 Returns NULL for invalid types. */
13992 static struct type
*
13993 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
13995 struct type
*this_type
= NULL
;
13999 case DW_TAG_class_type
:
14000 case DW_TAG_interface_type
:
14001 case DW_TAG_structure_type
:
14002 case DW_TAG_union_type
:
14003 this_type
= read_structure_type (die
, cu
);
14005 case DW_TAG_enumeration_type
:
14006 this_type
= read_enumeration_type (die
, cu
);
14008 case DW_TAG_subprogram
:
14009 case DW_TAG_subroutine_type
:
14010 case DW_TAG_inlined_subroutine
:
14011 this_type
= read_subroutine_type (die
, cu
);
14013 case DW_TAG_array_type
:
14014 this_type
= read_array_type (die
, cu
);
14016 case DW_TAG_set_type
:
14017 this_type
= read_set_type (die
, cu
);
14019 case DW_TAG_pointer_type
:
14020 this_type
= read_tag_pointer_type (die
, cu
);
14022 case DW_TAG_ptr_to_member_type
:
14023 this_type
= read_tag_ptr_to_member_type (die
, cu
);
14025 case DW_TAG_reference_type
:
14026 this_type
= read_tag_reference_type (die
, cu
);
14028 case DW_TAG_const_type
:
14029 this_type
= read_tag_const_type (die
, cu
);
14031 case DW_TAG_volatile_type
:
14032 this_type
= read_tag_volatile_type (die
, cu
);
14034 case DW_TAG_string_type
:
14035 this_type
= read_tag_string_type (die
, cu
);
14037 case DW_TAG_typedef
:
14038 this_type
= read_typedef (die
, cu
);
14040 case DW_TAG_subrange_type
:
14041 this_type
= read_subrange_type (die
, cu
);
14043 case DW_TAG_base_type
:
14044 this_type
= read_base_type (die
, cu
);
14046 case DW_TAG_unspecified_type
:
14047 this_type
= read_unspecified_type (die
, cu
);
14049 case DW_TAG_namespace
:
14050 this_type
= read_namespace_type (die
, cu
);
14052 case DW_TAG_module
:
14053 this_type
= read_module_type (die
, cu
);
14056 complaint (&symfile_complaints
,
14057 _("unexpected tag in read_type_die: '%s'"),
14058 dwarf_tag_name (die
->tag
));
14065 /* See if we can figure out if the class lives in a namespace. We do
14066 this by looking for a member function; its demangled name will
14067 contain namespace info, if there is any.
14068 Return the computed name or NULL.
14069 Space for the result is allocated on the objfile's obstack.
14070 This is the full-die version of guess_partial_die_structure_name.
14071 In this case we know DIE has no useful parent. */
14074 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
14076 struct die_info
*spec_die
;
14077 struct dwarf2_cu
*spec_cu
;
14078 struct die_info
*child
;
14081 spec_die
= die_specification (die
, &spec_cu
);
14082 if (spec_die
!= NULL
)
14088 for (child
= die
->child
;
14090 child
= child
->sibling
)
14092 if (child
->tag
== DW_TAG_subprogram
)
14094 struct attribute
*attr
;
14096 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
14098 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
14102 = language_class_name_from_physname (cu
->language_defn
,
14106 if (actual_name
!= NULL
)
14108 char *die_name
= dwarf2_name (die
, cu
);
14110 if (die_name
!= NULL
14111 && strcmp (die_name
, actual_name
) != 0)
14113 /* Strip off the class name from the full name.
14114 We want the prefix. */
14115 int die_name_len
= strlen (die_name
);
14116 int actual_name_len
= strlen (actual_name
);
14118 /* Test for '::' as a sanity check. */
14119 if (actual_name_len
> die_name_len
+ 2
14120 && actual_name
[actual_name_len
14121 - die_name_len
- 1] == ':')
14123 obsavestring (actual_name
,
14124 actual_name_len
- die_name_len
- 2,
14125 &cu
->objfile
->objfile_obstack
);
14128 xfree (actual_name
);
14137 /* GCC might emit a nameless typedef that has a linkage name. Determine the
14138 prefix part in such case. See
14139 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
14142 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
14144 struct attribute
*attr
;
14147 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
14148 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
14151 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
14152 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
14155 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
14157 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
14158 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
14161 /* dwarf2_name had to be already called. */
14162 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
14164 /* Strip the base name, keep any leading namespaces/classes. */
14165 base
= strrchr (DW_STRING (attr
), ':');
14166 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
14169 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
14170 &cu
->objfile
->objfile_obstack
);
14173 /* Return the name of the namespace/class that DIE is defined within,
14174 or "" if we can't tell. The caller should not xfree the result.
14176 For example, if we're within the method foo() in the following
14186 then determine_prefix on foo's die will return "N::C". */
14188 static const char *
14189 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
14191 struct die_info
*parent
, *spec_die
;
14192 struct dwarf2_cu
*spec_cu
;
14193 struct type
*parent_type
;
14196 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
14197 && cu
->language
!= language_fortran
)
14200 retval
= anonymous_struct_prefix (die
, cu
);
14204 /* We have to be careful in the presence of DW_AT_specification.
14205 For example, with GCC 3.4, given the code
14209 // Definition of N::foo.
14213 then we'll have a tree of DIEs like this:
14215 1: DW_TAG_compile_unit
14216 2: DW_TAG_namespace // N
14217 3: DW_TAG_subprogram // declaration of N::foo
14218 4: DW_TAG_subprogram // definition of N::foo
14219 DW_AT_specification // refers to die #3
14221 Thus, when processing die #4, we have to pretend that we're in
14222 the context of its DW_AT_specification, namely the contex of die
14225 spec_die
= die_specification (die
, &spec_cu
);
14226 if (spec_die
== NULL
)
14227 parent
= die
->parent
;
14230 parent
= spec_die
->parent
;
14234 if (parent
== NULL
)
14236 else if (parent
->building_fullname
)
14239 const char *parent_name
;
14241 /* It has been seen on RealView 2.2 built binaries,
14242 DW_TAG_template_type_param types actually _defined_ as
14243 children of the parent class:
14246 template class <class Enum> Class{};
14247 Class<enum E> class_e;
14249 1: DW_TAG_class_type (Class)
14250 2: DW_TAG_enumeration_type (E)
14251 3: DW_TAG_enumerator (enum1:0)
14252 3: DW_TAG_enumerator (enum2:1)
14254 2: DW_TAG_template_type_param
14255 DW_AT_type DW_FORM_ref_udata (E)
14257 Besides being broken debug info, it can put GDB into an
14258 infinite loop. Consider:
14260 When we're building the full name for Class<E>, we'll start
14261 at Class, and go look over its template type parameters,
14262 finding E. We'll then try to build the full name of E, and
14263 reach here. We're now trying to build the full name of E,
14264 and look over the parent DIE for containing scope. In the
14265 broken case, if we followed the parent DIE of E, we'd again
14266 find Class, and once again go look at its template type
14267 arguments, etc., etc. Simply don't consider such parent die
14268 as source-level parent of this die (it can't be, the language
14269 doesn't allow it), and break the loop here. */
14270 name
= dwarf2_name (die
, cu
);
14271 parent_name
= dwarf2_name (parent
, cu
);
14272 complaint (&symfile_complaints
,
14273 _("template param type '%s' defined within parent '%s'"),
14274 name
? name
: "<unknown>",
14275 parent_name
? parent_name
: "<unknown>");
14279 switch (parent
->tag
)
14281 case DW_TAG_namespace
:
14282 parent_type
= read_type_die (parent
, cu
);
14283 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
14284 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
14285 Work around this problem here. */
14286 if (cu
->language
== language_cplus
14287 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
14289 /* We give a name to even anonymous namespaces. */
14290 return TYPE_TAG_NAME (parent_type
);
14291 case DW_TAG_class_type
:
14292 case DW_TAG_interface_type
:
14293 case DW_TAG_structure_type
:
14294 case DW_TAG_union_type
:
14295 case DW_TAG_module
:
14296 parent_type
= read_type_die (parent
, cu
);
14297 if (TYPE_TAG_NAME (parent_type
) != NULL
)
14298 return TYPE_TAG_NAME (parent_type
);
14300 /* An anonymous structure is only allowed non-static data
14301 members; no typedefs, no member functions, et cetera.
14302 So it does not need a prefix. */
14304 case DW_TAG_compile_unit
:
14305 case DW_TAG_partial_unit
:
14306 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
14307 if (cu
->language
== language_cplus
14308 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
14309 && die
->child
!= NULL
14310 && (die
->tag
== DW_TAG_class_type
14311 || die
->tag
== DW_TAG_structure_type
14312 || die
->tag
== DW_TAG_union_type
))
14314 char *name
= guess_full_die_structure_name (die
, cu
);
14320 return determine_prefix (parent
, cu
);
14324 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
14325 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
14326 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
14327 an obconcat, otherwise allocate storage for the result. The CU argument is
14328 used to determine the language and hence, the appropriate separator. */
14330 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
14333 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
14334 int physname
, struct dwarf2_cu
*cu
)
14336 const char *lead
= "";
14339 if (suffix
== NULL
|| suffix
[0] == '\0'
14340 || prefix
== NULL
|| prefix
[0] == '\0')
14342 else if (cu
->language
== language_java
)
14344 else if (cu
->language
== language_fortran
&& physname
)
14346 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
14347 DW_AT_MIPS_linkage_name is preferred and used instead. */
14355 if (prefix
== NULL
)
14357 if (suffix
== NULL
)
14363 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
14365 strcpy (retval
, lead
);
14366 strcat (retval
, prefix
);
14367 strcat (retval
, sep
);
14368 strcat (retval
, suffix
);
14373 /* We have an obstack. */
14374 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
14378 /* Return sibling of die, NULL if no sibling. */
14380 static struct die_info
*
14381 sibling_die (struct die_info
*die
)
14383 return die
->sibling
;
14386 /* Get name of a die, return NULL if not found. */
14389 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
14390 struct obstack
*obstack
)
14392 if (name
&& cu
->language
== language_cplus
)
14394 char *canon_name
= cp_canonicalize_string (name
);
14396 if (canon_name
!= NULL
)
14398 if (strcmp (canon_name
, name
) != 0)
14399 name
= obsavestring (canon_name
, strlen (canon_name
),
14401 xfree (canon_name
);
14408 /* Get name of a die, return NULL if not found. */
14411 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
14413 struct attribute
*attr
;
14415 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
14416 if ((!attr
|| !DW_STRING (attr
))
14417 && die
->tag
!= DW_TAG_class_type
14418 && die
->tag
!= DW_TAG_interface_type
14419 && die
->tag
!= DW_TAG_structure_type
14420 && die
->tag
!= DW_TAG_union_type
)
14425 case DW_TAG_compile_unit
:
14426 case DW_TAG_partial_unit
:
14427 /* Compilation units have a DW_AT_name that is a filename, not
14428 a source language identifier. */
14429 case DW_TAG_enumeration_type
:
14430 case DW_TAG_enumerator
:
14431 /* These tags always have simple identifiers already; no need
14432 to canonicalize them. */
14433 return DW_STRING (attr
);
14435 case DW_TAG_subprogram
:
14436 /* Java constructors will all be named "<init>", so return
14437 the class name when we see this special case. */
14438 if (cu
->language
== language_java
14439 && DW_STRING (attr
) != NULL
14440 && strcmp (DW_STRING (attr
), "<init>") == 0)
14442 struct dwarf2_cu
*spec_cu
= cu
;
14443 struct die_info
*spec_die
;
14445 /* GCJ will output '<init>' for Java constructor names.
14446 For this special case, return the name of the parent class. */
14448 /* GCJ may output suprogram DIEs with AT_specification set.
14449 If so, use the name of the specified DIE. */
14450 spec_die
= die_specification (die
, &spec_cu
);
14451 if (spec_die
!= NULL
)
14452 return dwarf2_name (spec_die
, spec_cu
);
14457 if (die
->tag
== DW_TAG_class_type
)
14458 return dwarf2_name (die
, cu
);
14460 while (die
->tag
!= DW_TAG_compile_unit
14461 && die
->tag
!= DW_TAG_partial_unit
);
14465 case DW_TAG_class_type
:
14466 case DW_TAG_interface_type
:
14467 case DW_TAG_structure_type
:
14468 case DW_TAG_union_type
:
14469 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
14470 structures or unions. These were of the form "._%d" in GCC 4.1,
14471 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
14472 and GCC 4.4. We work around this problem by ignoring these. */
14473 if (attr
&& DW_STRING (attr
)
14474 && (strncmp (DW_STRING (attr
), "._", 2) == 0
14475 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
14478 /* GCC might emit a nameless typedef that has a linkage name. See
14479 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
14480 if (!attr
|| DW_STRING (attr
) == NULL
)
14482 char *demangled
= NULL
;
14484 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
14486 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
14488 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
14491 /* Avoid demangling DW_STRING (attr) the second time on a second
14492 call for the same DIE. */
14493 if (!DW_STRING_IS_CANONICAL (attr
))
14494 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
14500 /* FIXME: we already did this for the partial symbol... */
14501 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
14502 &cu
->objfile
->objfile_obstack
);
14503 DW_STRING_IS_CANONICAL (attr
) = 1;
14506 /* Strip any leading namespaces/classes, keep only the base name.
14507 DW_AT_name for named DIEs does not contain the prefixes. */
14508 base
= strrchr (DW_STRING (attr
), ':');
14509 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
14512 return DW_STRING (attr
);
14521 if (!DW_STRING_IS_CANONICAL (attr
))
14524 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
14525 &cu
->objfile
->objfile_obstack
);
14526 DW_STRING_IS_CANONICAL (attr
) = 1;
14528 return DW_STRING (attr
);
14531 /* Return the die that this die in an extension of, or NULL if there
14532 is none. *EXT_CU is the CU containing DIE on input, and the CU
14533 containing the return value on output. */
14535 static struct die_info
*
14536 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
14538 struct attribute
*attr
;
14540 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
14544 return follow_die_ref (die
, attr
, ext_cu
);
14547 /* Convert a DIE tag into its string name. */
14549 static const char *
14550 dwarf_tag_name (unsigned tag
)
14552 const char *name
= get_DW_TAG_name (tag
);
14555 return "DW_TAG_<unknown>";
14560 /* Convert a DWARF attribute code into its string name. */
14562 static const char *
14563 dwarf_attr_name (unsigned attr
)
14567 #ifdef MIPS /* collides with DW_AT_HP_block_index */
14568 if (attr
== DW_AT_MIPS_fde
)
14569 return "DW_AT_MIPS_fde";
14571 if (attr
== DW_AT_HP_block_index
)
14572 return "DW_AT_HP_block_index";
14575 name
= get_DW_AT_name (attr
);
14578 return "DW_AT_<unknown>";
14583 /* Convert a DWARF value form code into its string name. */
14585 static const char *
14586 dwarf_form_name (unsigned form
)
14588 const char *name
= get_DW_FORM_name (form
);
14591 return "DW_FORM_<unknown>";
14597 dwarf_bool_name (unsigned mybool
)
14605 /* Convert a DWARF type code into its string name. */
14607 static const char *
14608 dwarf_type_encoding_name (unsigned enc
)
14610 const char *name
= get_DW_ATE_name (enc
);
14613 return "DW_ATE_<unknown>";
14619 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
14623 print_spaces (indent
, f
);
14624 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
14625 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
.sect_off
);
14627 if (die
->parent
!= NULL
)
14629 print_spaces (indent
, f
);
14630 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
14631 die
->parent
->offset
.sect_off
);
14634 print_spaces (indent
, f
);
14635 fprintf_unfiltered (f
, " has children: %s\n",
14636 dwarf_bool_name (die
->child
!= NULL
));
14638 print_spaces (indent
, f
);
14639 fprintf_unfiltered (f
, " attributes:\n");
14641 for (i
= 0; i
< die
->num_attrs
; ++i
)
14643 print_spaces (indent
, f
);
14644 fprintf_unfiltered (f
, " %s (%s) ",
14645 dwarf_attr_name (die
->attrs
[i
].name
),
14646 dwarf_form_name (die
->attrs
[i
].form
));
14648 switch (die
->attrs
[i
].form
)
14651 case DW_FORM_GNU_addr_index
:
14652 fprintf_unfiltered (f
, "address: ");
14653 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
14655 case DW_FORM_block2
:
14656 case DW_FORM_block4
:
14657 case DW_FORM_block
:
14658 case DW_FORM_block1
:
14659 fprintf_unfiltered (f
, "block: size %d",
14660 DW_BLOCK (&die
->attrs
[i
])->size
);
14662 case DW_FORM_exprloc
:
14663 fprintf_unfiltered (f
, "expression: size %u",
14664 DW_BLOCK (&die
->attrs
[i
])->size
);
14666 case DW_FORM_ref_addr
:
14667 fprintf_unfiltered (f
, "ref address: ");
14668 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
14674 case DW_FORM_ref_udata
:
14675 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
14676 (long) (DW_UNSND (&die
->attrs
[i
])));
14678 case DW_FORM_data1
:
14679 case DW_FORM_data2
:
14680 case DW_FORM_data4
:
14681 case DW_FORM_data8
:
14682 case DW_FORM_udata
:
14683 case DW_FORM_sdata
:
14684 fprintf_unfiltered (f
, "constant: %s",
14685 pulongest (DW_UNSND (&die
->attrs
[i
])));
14687 case DW_FORM_sec_offset
:
14688 fprintf_unfiltered (f
, "section offset: %s",
14689 pulongest (DW_UNSND (&die
->attrs
[i
])));
14691 case DW_FORM_ref_sig8
:
14692 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
14693 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
14694 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
.sect_off
);
14696 fprintf_unfiltered (f
, "signatured type, offset: unknown");
14698 case DW_FORM_string
:
14700 case DW_FORM_GNU_str_index
:
14701 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
14702 DW_STRING (&die
->attrs
[i
])
14703 ? DW_STRING (&die
->attrs
[i
]) : "",
14704 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
14707 if (DW_UNSND (&die
->attrs
[i
]))
14708 fprintf_unfiltered (f
, "flag: TRUE");
14710 fprintf_unfiltered (f
, "flag: FALSE");
14712 case DW_FORM_flag_present
:
14713 fprintf_unfiltered (f
, "flag: TRUE");
14715 case DW_FORM_indirect
:
14716 /* The reader will have reduced the indirect form to
14717 the "base form" so this form should not occur. */
14718 fprintf_unfiltered (f
,
14719 "unexpected attribute form: DW_FORM_indirect");
14722 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
14723 die
->attrs
[i
].form
);
14726 fprintf_unfiltered (f
, "\n");
14731 dump_die_for_error (struct die_info
*die
)
14733 dump_die_shallow (gdb_stderr
, 0, die
);
14737 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
14739 int indent
= level
* 4;
14741 gdb_assert (die
!= NULL
);
14743 if (level
>= max_level
)
14746 dump_die_shallow (f
, indent
, die
);
14748 if (die
->child
!= NULL
)
14750 print_spaces (indent
, f
);
14751 fprintf_unfiltered (f
, " Children:");
14752 if (level
+ 1 < max_level
)
14754 fprintf_unfiltered (f
, "\n");
14755 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
14759 fprintf_unfiltered (f
,
14760 " [not printed, max nesting level reached]\n");
14764 if (die
->sibling
!= NULL
&& level
> 0)
14766 dump_die_1 (f
, level
, max_level
, die
->sibling
);
14770 /* This is called from the pdie macro in gdbinit.in.
14771 It's not static so gcc will keep a copy callable from gdb. */
14774 dump_die (struct die_info
*die
, int max_level
)
14776 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
14780 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
14784 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
.sect_off
,
14790 /* DW_ADDR is always stored already as sect_offset; despite for the forms
14791 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
14794 is_ref_attr (struct attribute
*attr
)
14796 switch (attr
->form
)
14798 case DW_FORM_ref_addr
:
14803 case DW_FORM_ref_udata
:
14810 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
14814 dwarf2_get_ref_die_offset (struct attribute
*attr
)
14816 sect_offset retval
= { DW_UNSND (attr
) };
14818 if (is_ref_attr (attr
))
14821 retval
.sect_off
= 0;
14822 complaint (&symfile_complaints
,
14823 _("unsupported die ref attribute form: '%s'"),
14824 dwarf_form_name (attr
->form
));
14828 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
14829 * the value held by the attribute is not constant. */
14832 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
14834 if (attr
->form
== DW_FORM_sdata
)
14835 return DW_SND (attr
);
14836 else if (attr
->form
== DW_FORM_udata
14837 || attr
->form
== DW_FORM_data1
14838 || attr
->form
== DW_FORM_data2
14839 || attr
->form
== DW_FORM_data4
14840 || attr
->form
== DW_FORM_data8
)
14841 return DW_UNSND (attr
);
14844 complaint (&symfile_complaints
,
14845 _("Attribute value is not a constant (%s)"),
14846 dwarf_form_name (attr
->form
));
14847 return default_value
;
14851 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
14852 unit and add it to our queue.
14853 The result is non-zero if PER_CU was queued, otherwise the result is zero
14854 meaning either PER_CU is already queued or it is already loaded. */
14857 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
14858 struct dwarf2_per_cu_data
*per_cu
,
14859 enum language pretend_language
)
14861 /* We may arrive here during partial symbol reading, if we need full
14862 DIEs to process an unusual case (e.g. template arguments). Do
14863 not queue PER_CU, just tell our caller to load its DIEs. */
14864 if (dwarf2_per_objfile
->reading_partial_symbols
)
14866 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
14871 /* Mark the dependence relation so that we don't flush PER_CU
14873 dwarf2_add_dependence (this_cu
, per_cu
);
14875 /* If it's already on the queue, we have nothing to do. */
14876 if (per_cu
->queued
)
14879 /* If the compilation unit is already loaded, just mark it as
14881 if (per_cu
->cu
!= NULL
)
14883 per_cu
->cu
->last_used
= 0;
14887 /* Add it to the queue. */
14888 queue_comp_unit (per_cu
, pretend_language
);
14893 /* Follow reference or signature attribute ATTR of SRC_DIE.
14894 On entry *REF_CU is the CU of SRC_DIE.
14895 On exit *REF_CU is the CU of the result. */
14897 static struct die_info
*
14898 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
14899 struct dwarf2_cu
**ref_cu
)
14901 struct die_info
*die
;
14903 if (is_ref_attr (attr
))
14904 die
= follow_die_ref (src_die
, attr
, ref_cu
);
14905 else if (attr
->form
== DW_FORM_ref_sig8
)
14906 die
= follow_die_sig (src_die
, attr
, ref_cu
);
14909 dump_die_for_error (src_die
);
14910 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
14911 (*ref_cu
)->objfile
->name
);
14917 /* Follow reference OFFSET.
14918 On entry *REF_CU is the CU of the source die referencing OFFSET.
14919 On exit *REF_CU is the CU of the result.
14920 Returns NULL if OFFSET is invalid. */
14922 static struct die_info
*
14923 follow_die_offset (sect_offset offset
, struct dwarf2_cu
**ref_cu
)
14925 struct die_info temp_die
;
14926 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
14928 gdb_assert (cu
->per_cu
!= NULL
);
14932 if (cu
->per_cu
->is_debug_types
)
14934 /* .debug_types CUs cannot reference anything outside their CU.
14935 If they need to, they have to reference a signatured type via
14936 DW_FORM_ref_sig8. */
14937 if (! offset_in_cu_p (&cu
->header
, offset
))
14940 else if (! offset_in_cu_p (&cu
->header
, offset
))
14942 struct dwarf2_per_cu_data
*per_cu
;
14944 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
14946 /* If necessary, add it to the queue and load its DIEs. */
14947 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
14948 load_full_comp_unit (per_cu
, cu
->language
);
14950 target_cu
= per_cu
->cu
;
14952 else if (cu
->dies
== NULL
)
14954 /* We're loading full DIEs during partial symbol reading. */
14955 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
14956 load_full_comp_unit (cu
->per_cu
, language_minimal
);
14959 *ref_cu
= target_cu
;
14960 temp_die
.offset
= offset
;
14961 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
.sect_off
);
14964 /* Follow reference attribute ATTR of SRC_DIE.
14965 On entry *REF_CU is the CU of SRC_DIE.
14966 On exit *REF_CU is the CU of the result. */
14968 static struct die_info
*
14969 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
14970 struct dwarf2_cu
**ref_cu
)
14972 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
14973 struct dwarf2_cu
*cu
= *ref_cu
;
14974 struct die_info
*die
;
14976 die
= follow_die_offset (offset
, ref_cu
);
14978 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
14979 "at 0x%x [in module %s]"),
14980 offset
.sect_off
, src_die
->offset
.sect_off
, cu
->objfile
->name
);
14985 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
14986 Returned value is intended for DW_OP_call*. Returned
14987 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
14989 struct dwarf2_locexpr_baton
14990 dwarf2_fetch_die_location_block (cu_offset offset_in_cu
,
14991 struct dwarf2_per_cu_data
*per_cu
,
14992 CORE_ADDR (*get_frame_pc
) (void *baton
),
14995 sect_offset offset
= { per_cu
->offset
.sect_off
+ offset_in_cu
.cu_off
};
14996 struct dwarf2_cu
*cu
;
14997 struct die_info
*die
;
14998 struct attribute
*attr
;
14999 struct dwarf2_locexpr_baton retval
;
15001 dw2_setup (per_cu
->objfile
);
15003 if (per_cu
->cu
== NULL
)
15007 die
= follow_die_offset (offset
, &cu
);
15009 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
15010 offset
.sect_off
, per_cu
->objfile
->name
);
15012 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15015 /* DWARF: "If there is no such attribute, then there is no effect.".
15016 DATA is ignored if SIZE is 0. */
15018 retval
.data
= NULL
;
15021 else if (attr_form_is_section_offset (attr
))
15023 struct dwarf2_loclist_baton loclist_baton
;
15024 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
15027 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
15029 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
15031 retval
.size
= size
;
15035 if (!attr_form_is_block (attr
))
15036 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
15037 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
15038 offset
.sect_off
, per_cu
->objfile
->name
);
15040 retval
.data
= DW_BLOCK (attr
)->data
;
15041 retval
.size
= DW_BLOCK (attr
)->size
;
15043 retval
.per_cu
= cu
->per_cu
;
15045 age_cached_comp_units ();
15050 /* Return the type of the DIE at DIE_OFFSET in the CU named by
15054 dwarf2_get_die_type (cu_offset die_offset
,
15055 struct dwarf2_per_cu_data
*per_cu
)
15057 sect_offset die_offset_sect
;
15059 dw2_setup (per_cu
->objfile
);
15061 die_offset_sect
.sect_off
= per_cu
->offset
.sect_off
+ die_offset
.cu_off
;
15062 return get_die_type_at_offset (die_offset_sect
, per_cu
);
15065 /* Follow the signature attribute ATTR in SRC_DIE.
15066 On entry *REF_CU is the CU of SRC_DIE.
15067 On exit *REF_CU is the CU of the result. */
15069 static struct die_info
*
15070 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
15071 struct dwarf2_cu
**ref_cu
)
15073 struct objfile
*objfile
= (*ref_cu
)->objfile
;
15074 struct die_info temp_die
;
15075 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
15076 struct dwarf2_cu
*sig_cu
;
15077 struct die_info
*die
;
15079 /* sig_type will be NULL if the signatured type is missing from
15081 if (sig_type
== NULL
)
15082 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
15083 "at 0x%x [in module %s]"),
15084 src_die
->offset
.sect_off
, objfile
->name
);
15086 /* If necessary, add it to the queue and load its DIEs. */
15088 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
15089 read_signatured_type (sig_type
);
15091 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
15093 sig_cu
= sig_type
->per_cu
.cu
;
15094 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
15095 temp_die
.offset
= sig_type
->type_offset_in_section
;
15096 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
15097 temp_die
.offset
.sect_off
);
15104 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
15105 "from DIE at 0x%x [in module %s]"),
15106 temp_die
.offset
.sect_off
, src_die
->offset
.sect_off
, objfile
->name
);
15109 /* Given an offset of a signatured type, return its signatured_type. */
15111 static struct signatured_type
*
15112 lookup_signatured_type_at_offset (struct objfile
*objfile
,
15113 struct dwarf2_section_info
*section
,
15114 sect_offset offset
)
15116 gdb_byte
*info_ptr
= section
->buffer
+ offset
.sect_off
;
15117 unsigned int length
, initial_length_size
;
15118 unsigned int sig_offset
;
15119 struct signatured_type find_entry
, *sig_type
;
15121 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
15122 sig_offset
= (initial_length_size
15124 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
15125 + 1 /*address_size*/);
15126 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
15127 sig_type
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
15129 /* This is only used to lookup previously recorded types.
15130 If we didn't find it, it's our bug. */
15131 gdb_assert (sig_type
!= NULL
);
15132 gdb_assert (offset
.sect_off
== sig_type
->per_cu
.offset
.sect_off
);
15137 /* Load the DIEs associated with type unit PER_CU into memory. */
15140 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
15142 struct objfile
*objfile
= per_cu
->objfile
;
15143 struct dwarf2_section_info
*sect
= per_cu
->info_or_types_section
;
15144 sect_offset offset
= per_cu
->offset
;
15145 struct signatured_type
*sig_type
;
15147 dwarf2_read_section (objfile
, sect
);
15149 /* We have the section offset, but we need the signature to do the
15150 hash table lookup. */
15151 /* FIXME: This is sorta unnecessary, read_signatured_type only uses
15152 the signature to assert we found the right one.
15153 Ok, but it's a lot of work. We should simplify things so any needed
15154 assert doesn't require all this clumsiness. */
15155 sig_type
= lookup_signatured_type_at_offset (objfile
, sect
, offset
);
15157 gdb_assert (&sig_type
->per_cu
== per_cu
);
15158 gdb_assert (sig_type
->per_cu
.cu
== NULL
);
15160 read_signatured_type (sig_type
);
15162 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
15165 /* die_reader_func for read_signatured_type.
15166 This is identical to load_full_comp_unit_reader,
15167 but is kept separate for now. */
15170 read_signatured_type_reader (const struct die_reader_specs
*reader
,
15171 gdb_byte
*info_ptr
,
15172 struct die_info
*comp_unit_die
,
15176 struct dwarf2_cu
*cu
= reader
->cu
;
15178 gdb_assert (cu
->die_hash
== NULL
);
15180 htab_create_alloc_ex (cu
->header
.length
/ 12,
15184 &cu
->comp_unit_obstack
,
15185 hashtab_obstack_allocate
,
15186 dummy_obstack_deallocate
);
15189 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
15190 &info_ptr
, comp_unit_die
);
15191 cu
->dies
= comp_unit_die
;
15192 /* comp_unit_die is not stored in die_hash, no need. */
15194 /* We try not to read any attributes in this function, because not
15195 all CUs needed for references have been loaded yet, and symbol
15196 table processing isn't initialized. But we have to set the CU language,
15197 or we won't be able to build types correctly.
15198 Similarly, if we do not read the producer, we can not apply
15199 producer-specific interpretation. */
15200 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
15203 /* Read in a signatured type and build its CU and DIEs.
15204 If the type is a stub for the real type in a DWO file,
15205 read in the real type from the DWO file as well. */
15208 read_signatured_type (struct signatured_type
*sig_type
)
15210 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
15212 gdb_assert (per_cu
->is_debug_types
);
15213 gdb_assert (per_cu
->cu
== NULL
);
15215 init_cutu_and_read_dies (per_cu
, 0, 1, read_signatured_type_reader
, NULL
);
15218 /* Decode simple location descriptions.
15219 Given a pointer to a dwarf block that defines a location, compute
15220 the location and return the value.
15222 NOTE drow/2003-11-18: This function is called in two situations
15223 now: for the address of static or global variables (partial symbols
15224 only) and for offsets into structures which are expected to be
15225 (more or less) constant. The partial symbol case should go away,
15226 and only the constant case should remain. That will let this
15227 function complain more accurately. A few special modes are allowed
15228 without complaint for global variables (for instance, global
15229 register values and thread-local values).
15231 A location description containing no operations indicates that the
15232 object is optimized out. The return value is 0 for that case.
15233 FIXME drow/2003-11-16: No callers check for this case any more; soon all
15234 callers will only want a very basic result and this can become a
15237 Note that stack[0] is unused except as a default error return. */
15240 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
15242 struct objfile
*objfile
= cu
->objfile
;
15244 int size
= blk
->size
;
15245 gdb_byte
*data
= blk
->data
;
15246 CORE_ADDR stack
[64];
15248 unsigned int bytes_read
, unsnd
;
15254 stack
[++stacki
] = 0;
15293 stack
[++stacki
] = op
- DW_OP_lit0
;
15328 stack
[++stacki
] = op
- DW_OP_reg0
;
15330 dwarf2_complex_location_expr_complaint ();
15334 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
15336 stack
[++stacki
] = unsnd
;
15338 dwarf2_complex_location_expr_complaint ();
15342 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
15347 case DW_OP_const1u
:
15348 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
15352 case DW_OP_const1s
:
15353 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
15357 case DW_OP_const2u
:
15358 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
15362 case DW_OP_const2s
:
15363 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
15367 case DW_OP_const4u
:
15368 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
15372 case DW_OP_const4s
:
15373 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
15377 case DW_OP_const8u
:
15378 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
15383 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
15389 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
15394 stack
[stacki
+ 1] = stack
[stacki
];
15399 stack
[stacki
- 1] += stack
[stacki
];
15403 case DW_OP_plus_uconst
:
15404 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
15410 stack
[stacki
- 1] -= stack
[stacki
];
15415 /* If we're not the last op, then we definitely can't encode
15416 this using GDB's address_class enum. This is valid for partial
15417 global symbols, although the variable's address will be bogus
15420 dwarf2_complex_location_expr_complaint ();
15423 case DW_OP_GNU_push_tls_address
:
15424 /* The top of the stack has the offset from the beginning
15425 of the thread control block at which the variable is located. */
15426 /* Nothing should follow this operator, so the top of stack would
15428 /* This is valid for partial global symbols, but the variable's
15429 address will be bogus in the psymtab. Make it always at least
15430 non-zero to not look as a variable garbage collected by linker
15431 which have DW_OP_addr 0. */
15433 dwarf2_complex_location_expr_complaint ();
15437 case DW_OP_GNU_uninit
:
15440 case DW_OP_GNU_addr_index
:
15441 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
15448 const char *name
= get_DW_OP_name (op
);
15451 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
15454 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
15458 return (stack
[stacki
]);
15461 /* Enforce maximum stack depth of SIZE-1 to avoid writing
15462 outside of the allocated space. Also enforce minimum>0. */
15463 if (stacki
>= ARRAY_SIZE (stack
) - 1)
15465 complaint (&symfile_complaints
,
15466 _("location description stack overflow"));
15472 complaint (&symfile_complaints
,
15473 _("location description stack underflow"));
15477 return (stack
[stacki
]);
15480 /* memory allocation interface */
15482 static struct dwarf_block
*
15483 dwarf_alloc_block (struct dwarf2_cu
*cu
)
15485 struct dwarf_block
*blk
;
15487 blk
= (struct dwarf_block
*)
15488 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
15492 static struct abbrev_info
*
15493 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
15495 struct abbrev_info
*abbrev
;
15497 abbrev
= (struct abbrev_info
*)
15498 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
15499 memset (abbrev
, 0, sizeof (struct abbrev_info
));
15503 static struct die_info
*
15504 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
15506 struct die_info
*die
;
15507 size_t size
= sizeof (struct die_info
);
15510 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
15512 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
15513 memset (die
, 0, sizeof (struct die_info
));
15518 /* Macro support. */
15520 /* Return the full name of file number I in *LH's file name table.
15521 Use COMP_DIR as the name of the current directory of the
15522 compilation. The result is allocated using xmalloc; the caller is
15523 responsible for freeing it. */
15525 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
15527 /* Is the file number a valid index into the line header's file name
15528 table? Remember that file numbers start with one, not zero. */
15529 if (1 <= file
&& file
<= lh
->num_file_names
)
15531 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
15533 if (IS_ABSOLUTE_PATH (fe
->name
))
15534 return xstrdup (fe
->name
);
15542 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
15548 dir_len
= strlen (dir
);
15549 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
15550 strcpy (full_name
, dir
);
15551 full_name
[dir_len
] = '/';
15552 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
15556 return xstrdup (fe
->name
);
15561 /* The compiler produced a bogus file number. We can at least
15562 record the macro definitions made in the file, even if we
15563 won't be able to find the file by name. */
15564 char fake_name
[80];
15566 sprintf (fake_name
, "<bad macro file number %d>", file
);
15568 complaint (&symfile_complaints
,
15569 _("bad file number in macro information (%d)"),
15572 return xstrdup (fake_name
);
15577 static struct macro_source_file
*
15578 macro_start_file (int file
, int line
,
15579 struct macro_source_file
*current_file
,
15580 const char *comp_dir
,
15581 struct line_header
*lh
, struct objfile
*objfile
)
15583 /* The full name of this source file. */
15584 char *full_name
= file_full_name (file
, lh
, comp_dir
);
15586 /* We don't create a macro table for this compilation unit
15587 at all until we actually get a filename. */
15588 if (! pending_macros
)
15589 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
15590 objfile
->macro_cache
);
15592 if (! current_file
)
15594 /* If we have no current file, then this must be the start_file
15595 directive for the compilation unit's main source file. */
15596 current_file
= macro_set_main (pending_macros
, full_name
);
15597 macro_define_special (pending_macros
);
15600 current_file
= macro_include (current_file
, line
, full_name
);
15604 return current_file
;
15608 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
15609 followed by a null byte. */
15611 copy_string (const char *buf
, int len
)
15613 char *s
= xmalloc (len
+ 1);
15615 memcpy (s
, buf
, len
);
15621 static const char *
15622 consume_improper_spaces (const char *p
, const char *body
)
15626 complaint (&symfile_complaints
,
15627 _("macro definition contains spaces "
15628 "in formal argument list:\n`%s'"),
15640 parse_macro_definition (struct macro_source_file
*file
, int line
,
15645 /* The body string takes one of two forms. For object-like macro
15646 definitions, it should be:
15648 <macro name> " " <definition>
15650 For function-like macro definitions, it should be:
15652 <macro name> "() " <definition>
15654 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
15656 Spaces may appear only where explicitly indicated, and in the
15659 The Dwarf 2 spec says that an object-like macro's name is always
15660 followed by a space, but versions of GCC around March 2002 omit
15661 the space when the macro's definition is the empty string.
15663 The Dwarf 2 spec says that there should be no spaces between the
15664 formal arguments in a function-like macro's formal argument list,
15665 but versions of GCC around March 2002 include spaces after the
15669 /* Find the extent of the macro name. The macro name is terminated
15670 by either a space or null character (for an object-like macro) or
15671 an opening paren (for a function-like macro). */
15672 for (p
= body
; *p
; p
++)
15673 if (*p
== ' ' || *p
== '(')
15676 if (*p
== ' ' || *p
== '\0')
15678 /* It's an object-like macro. */
15679 int name_len
= p
- body
;
15680 char *name
= copy_string (body
, name_len
);
15681 const char *replacement
;
15684 replacement
= body
+ name_len
+ 1;
15687 dwarf2_macro_malformed_definition_complaint (body
);
15688 replacement
= body
+ name_len
;
15691 macro_define_object (file
, line
, name
, replacement
);
15695 else if (*p
== '(')
15697 /* It's a function-like macro. */
15698 char *name
= copy_string (body
, p
- body
);
15701 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
15705 p
= consume_improper_spaces (p
, body
);
15707 /* Parse the formal argument list. */
15708 while (*p
&& *p
!= ')')
15710 /* Find the extent of the current argument name. */
15711 const char *arg_start
= p
;
15713 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
15716 if (! *p
|| p
== arg_start
)
15717 dwarf2_macro_malformed_definition_complaint (body
);
15720 /* Make sure argv has room for the new argument. */
15721 if (argc
>= argv_size
)
15724 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
15727 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
15730 p
= consume_improper_spaces (p
, body
);
15732 /* Consume the comma, if present. */
15737 p
= consume_improper_spaces (p
, body
);
15746 /* Perfectly formed definition, no complaints. */
15747 macro_define_function (file
, line
, name
,
15748 argc
, (const char **) argv
,
15750 else if (*p
== '\0')
15752 /* Complain, but do define it. */
15753 dwarf2_macro_malformed_definition_complaint (body
);
15754 macro_define_function (file
, line
, name
,
15755 argc
, (const char **) argv
,
15759 /* Just complain. */
15760 dwarf2_macro_malformed_definition_complaint (body
);
15763 /* Just complain. */
15764 dwarf2_macro_malformed_definition_complaint (body
);
15770 for (i
= 0; i
< argc
; i
++)
15776 dwarf2_macro_malformed_definition_complaint (body
);
15779 /* Skip some bytes from BYTES according to the form given in FORM.
15780 Returns the new pointer. */
15783 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
,
15784 enum dwarf_form form
,
15785 unsigned int offset_size
,
15786 struct dwarf2_section_info
*section
)
15788 unsigned int bytes_read
;
15792 case DW_FORM_data1
:
15797 case DW_FORM_data2
:
15801 case DW_FORM_data4
:
15805 case DW_FORM_data8
:
15809 case DW_FORM_string
:
15810 read_direct_string (abfd
, bytes
, &bytes_read
);
15811 bytes
+= bytes_read
;
15814 case DW_FORM_sec_offset
:
15816 bytes
+= offset_size
;
15819 case DW_FORM_block
:
15820 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
15821 bytes
+= bytes_read
;
15824 case DW_FORM_block1
:
15825 bytes
+= 1 + read_1_byte (abfd
, bytes
);
15827 case DW_FORM_block2
:
15828 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
15830 case DW_FORM_block4
:
15831 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
15834 case DW_FORM_sdata
:
15835 case DW_FORM_udata
:
15836 case DW_FORM_GNU_addr_index
:
15837 case DW_FORM_GNU_str_index
:
15838 bytes
= skip_leb128 (abfd
, bytes
);
15844 complaint (&symfile_complaints
,
15845 _("invalid form 0x%x in `%s'"),
15847 section
->asection
->name
);
15855 /* A helper for dwarf_decode_macros that handles skipping an unknown
15856 opcode. Returns an updated pointer to the macro data buffer; or,
15857 on error, issues a complaint and returns NULL. */
15860 skip_unknown_opcode (unsigned int opcode
,
15861 gdb_byte
**opcode_definitions
,
15864 unsigned int offset_size
,
15865 struct dwarf2_section_info
*section
)
15867 unsigned int bytes_read
, i
;
15871 if (opcode_definitions
[opcode
] == NULL
)
15873 complaint (&symfile_complaints
,
15874 _("unrecognized DW_MACFINO opcode 0x%x"),
15879 defn
= opcode_definitions
[opcode
];
15880 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
15881 defn
+= bytes_read
;
15883 for (i
= 0; i
< arg
; ++i
)
15885 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, defn
[i
], offset_size
, section
);
15886 if (mac_ptr
== NULL
)
15888 /* skip_form_bytes already issued the complaint. */
15896 /* A helper function which parses the header of a macro section.
15897 If the macro section is the extended (for now called "GNU") type,
15898 then this updates *OFFSET_SIZE. Returns a pointer to just after
15899 the header, or issues a complaint and returns NULL on error. */
15902 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
15905 unsigned int *offset_size
,
15906 int section_is_gnu
)
15908 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
15910 if (section_is_gnu
)
15912 unsigned int version
, flags
;
15914 version
= read_2_bytes (abfd
, mac_ptr
);
15917 complaint (&symfile_complaints
,
15918 _("unrecognized version `%d' in .debug_macro section"),
15924 flags
= read_1_byte (abfd
, mac_ptr
);
15926 *offset_size
= (flags
& 1) ? 8 : 4;
15928 if ((flags
& 2) != 0)
15929 /* We don't need the line table offset. */
15930 mac_ptr
+= *offset_size
;
15932 /* Vendor opcode descriptions. */
15933 if ((flags
& 4) != 0)
15935 unsigned int i
, count
;
15937 count
= read_1_byte (abfd
, mac_ptr
);
15939 for (i
= 0; i
< count
; ++i
)
15941 unsigned int opcode
, bytes_read
;
15944 opcode
= read_1_byte (abfd
, mac_ptr
);
15946 opcode_definitions
[opcode
] = mac_ptr
;
15947 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15948 mac_ptr
+= bytes_read
;
15957 /* A helper for dwarf_decode_macros that handles the GNU extensions,
15958 including DW_MACRO_GNU_transparent_include. */
15961 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
15962 struct macro_source_file
*current_file
,
15963 struct line_header
*lh
, char *comp_dir
,
15964 struct dwarf2_section_info
*section
,
15965 int section_is_gnu
,
15966 unsigned int offset_size
,
15967 struct objfile
*objfile
,
15968 htab_t include_hash
)
15970 enum dwarf_macro_record_type macinfo_type
;
15971 int at_commandline
;
15972 gdb_byte
*opcode_definitions
[256];
15974 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
15975 &offset_size
, section_is_gnu
);
15976 if (mac_ptr
== NULL
)
15978 /* We already issued a complaint. */
15982 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
15983 GDB is still reading the definitions from command line. First
15984 DW_MACINFO_start_file will need to be ignored as it was already executed
15985 to create CURRENT_FILE for the main source holding also the command line
15986 definitions. On first met DW_MACINFO_start_file this flag is reset to
15987 normally execute all the remaining DW_MACINFO_start_file macinfos. */
15989 at_commandline
= 1;
15993 /* Do we at least have room for a macinfo type byte? */
15994 if (mac_ptr
>= mac_end
)
15996 dwarf2_macros_too_long_complaint (section
);
16000 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
16003 /* Note that we rely on the fact that the corresponding GNU and
16004 DWARF constants are the same. */
16005 switch (macinfo_type
)
16007 /* A zero macinfo type indicates the end of the macro
16012 case DW_MACRO_GNU_define
:
16013 case DW_MACRO_GNU_undef
:
16014 case DW_MACRO_GNU_define_indirect
:
16015 case DW_MACRO_GNU_undef_indirect
:
16017 unsigned int bytes_read
;
16022 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16023 mac_ptr
+= bytes_read
;
16025 if (macinfo_type
== DW_MACRO_GNU_define
16026 || macinfo_type
== DW_MACRO_GNU_undef
)
16028 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16029 mac_ptr
+= bytes_read
;
16033 LONGEST str_offset
;
16035 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
16036 mac_ptr
+= offset_size
;
16038 body
= read_indirect_string_at_offset (abfd
, str_offset
);
16041 is_define
= (macinfo_type
== DW_MACRO_GNU_define
16042 || macinfo_type
== DW_MACRO_GNU_define_indirect
);
16043 if (! current_file
)
16045 /* DWARF violation as no main source is present. */
16046 complaint (&symfile_complaints
,
16047 _("debug info with no main source gives macro %s "
16049 is_define
? _("definition") : _("undefinition"),
16053 if ((line
== 0 && !at_commandline
)
16054 || (line
!= 0 && at_commandline
))
16055 complaint (&symfile_complaints
,
16056 _("debug info gives %s macro %s with %s line %d: %s"),
16057 at_commandline
? _("command-line") : _("in-file"),
16058 is_define
? _("definition") : _("undefinition"),
16059 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
16062 parse_macro_definition (current_file
, line
, body
);
16065 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
16066 || macinfo_type
== DW_MACRO_GNU_undef_indirect
);
16067 macro_undef (current_file
, line
, body
);
16072 case DW_MACRO_GNU_start_file
:
16074 unsigned int bytes_read
;
16077 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16078 mac_ptr
+= bytes_read
;
16079 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16080 mac_ptr
+= bytes_read
;
16082 if ((line
== 0 && !at_commandline
)
16083 || (line
!= 0 && at_commandline
))
16084 complaint (&symfile_complaints
,
16085 _("debug info gives source %d included "
16086 "from %s at %s line %d"),
16087 file
, at_commandline
? _("command-line") : _("file"),
16088 line
== 0 ? _("zero") : _("non-zero"), line
);
16090 if (at_commandline
)
16092 /* This DW_MACRO_GNU_start_file was executed in the
16094 at_commandline
= 0;
16097 current_file
= macro_start_file (file
, line
,
16098 current_file
, comp_dir
,
16103 case DW_MACRO_GNU_end_file
:
16104 if (! current_file
)
16105 complaint (&symfile_complaints
,
16106 _("macro debug info has an unmatched "
16107 "`close_file' directive"));
16110 current_file
= current_file
->included_by
;
16111 if (! current_file
)
16113 enum dwarf_macro_record_type next_type
;
16115 /* GCC circa March 2002 doesn't produce the zero
16116 type byte marking the end of the compilation
16117 unit. Complain if it's not there, but exit no
16120 /* Do we at least have room for a macinfo type byte? */
16121 if (mac_ptr
>= mac_end
)
16123 dwarf2_macros_too_long_complaint (section
);
16127 /* We don't increment mac_ptr here, so this is just
16129 next_type
= read_1_byte (abfd
, mac_ptr
);
16130 if (next_type
!= 0)
16131 complaint (&symfile_complaints
,
16132 _("no terminating 0-type entry for "
16133 "macros in `.debug_macinfo' section"));
16140 case DW_MACRO_GNU_transparent_include
:
16145 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
16146 mac_ptr
+= offset_size
;
16148 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
16151 /* This has actually happened; see
16152 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
16153 complaint (&symfile_complaints
,
16154 _("recursive DW_MACRO_GNU_transparent_include in "
16155 ".debug_macro section"));
16161 dwarf_decode_macro_bytes (abfd
,
16162 section
->buffer
+ offset
,
16163 mac_end
, current_file
,
16165 section
, section_is_gnu
,
16166 offset_size
, objfile
, include_hash
);
16168 htab_remove_elt (include_hash
, mac_ptr
);
16173 case DW_MACINFO_vendor_ext
:
16174 if (!section_is_gnu
)
16176 unsigned int bytes_read
;
16179 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16180 mac_ptr
+= bytes_read
;
16181 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16182 mac_ptr
+= bytes_read
;
16184 /* We don't recognize any vendor extensions. */
16190 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
16191 mac_ptr
, abfd
, offset_size
,
16193 if (mac_ptr
== NULL
)
16197 } while (macinfo_type
!= 0);
16201 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
16202 char *comp_dir
, bfd
*abfd
,
16203 struct dwarf2_cu
*cu
,
16204 struct dwarf2_section_info
*section
,
16205 int section_is_gnu
, const char *section_name
)
16207 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16208 gdb_byte
*mac_ptr
, *mac_end
;
16209 struct macro_source_file
*current_file
= 0;
16210 enum dwarf_macro_record_type macinfo_type
;
16211 unsigned int offset_size
= cu
->header
.offset_size
;
16212 gdb_byte
*opcode_definitions
[256];
16213 struct cleanup
*cleanup
;
16214 htab_t include_hash
;
16217 dwarf2_read_section (objfile
, section
);
16218 if (section
->buffer
== NULL
)
16220 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
16224 /* First pass: Find the name of the base filename.
16225 This filename is needed in order to process all macros whose definition
16226 (or undefinition) comes from the command line. These macros are defined
16227 before the first DW_MACINFO_start_file entry, and yet still need to be
16228 associated to the base file.
16230 To determine the base file name, we scan the macro definitions until we
16231 reach the first DW_MACINFO_start_file entry. We then initialize
16232 CURRENT_FILE accordingly so that any macro definition found before the
16233 first DW_MACINFO_start_file can still be associated to the base file. */
16235 mac_ptr
= section
->buffer
+ offset
;
16236 mac_end
= section
->buffer
+ section
->size
;
16238 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
16239 &offset_size
, section_is_gnu
);
16240 if (mac_ptr
== NULL
)
16242 /* We already issued a complaint. */
16248 /* Do we at least have room for a macinfo type byte? */
16249 if (mac_ptr
>= mac_end
)
16251 /* Complaint is printed during the second pass as GDB will probably
16252 stop the first pass earlier upon finding
16253 DW_MACINFO_start_file. */
16257 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
16260 /* Note that we rely on the fact that the corresponding GNU and
16261 DWARF constants are the same. */
16262 switch (macinfo_type
)
16264 /* A zero macinfo type indicates the end of the macro
16269 case DW_MACRO_GNU_define
:
16270 case DW_MACRO_GNU_undef
:
16271 /* Only skip the data by MAC_PTR. */
16273 unsigned int bytes_read
;
16275 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16276 mac_ptr
+= bytes_read
;
16277 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16278 mac_ptr
+= bytes_read
;
16282 case DW_MACRO_GNU_start_file
:
16284 unsigned int bytes_read
;
16287 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16288 mac_ptr
+= bytes_read
;
16289 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16290 mac_ptr
+= bytes_read
;
16292 current_file
= macro_start_file (file
, line
, current_file
,
16293 comp_dir
, lh
, objfile
);
16297 case DW_MACRO_GNU_end_file
:
16298 /* No data to skip by MAC_PTR. */
16301 case DW_MACRO_GNU_define_indirect
:
16302 case DW_MACRO_GNU_undef_indirect
:
16304 unsigned int bytes_read
;
16306 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16307 mac_ptr
+= bytes_read
;
16308 mac_ptr
+= offset_size
;
16312 case DW_MACRO_GNU_transparent_include
:
16313 /* Note that, according to the spec, a transparent include
16314 chain cannot call DW_MACRO_GNU_start_file. So, we can just
16315 skip this opcode. */
16316 mac_ptr
+= offset_size
;
16319 case DW_MACINFO_vendor_ext
:
16320 /* Only skip the data by MAC_PTR. */
16321 if (!section_is_gnu
)
16323 unsigned int bytes_read
;
16325 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16326 mac_ptr
+= bytes_read
;
16327 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16328 mac_ptr
+= bytes_read
;
16333 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
16334 mac_ptr
, abfd
, offset_size
,
16336 if (mac_ptr
== NULL
)
16340 } while (macinfo_type
!= 0 && current_file
== NULL
);
16342 /* Second pass: Process all entries.
16344 Use the AT_COMMAND_LINE flag to determine whether we are still processing
16345 command-line macro definitions/undefinitions. This flag is unset when we
16346 reach the first DW_MACINFO_start_file entry. */
16348 include_hash
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
16349 NULL
, xcalloc
, xfree
);
16350 cleanup
= make_cleanup_htab_delete (include_hash
);
16351 mac_ptr
= section
->buffer
+ offset
;
16352 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
16354 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
16355 current_file
, lh
, comp_dir
, section
, section_is_gnu
,
16356 offset_size
, objfile
, include_hash
);
16357 do_cleanups (cleanup
);
16360 /* Check if the attribute's form is a DW_FORM_block*
16361 if so return true else false. */
16364 attr_form_is_block (struct attribute
*attr
)
16366 return (attr
== NULL
? 0 :
16367 attr
->form
== DW_FORM_block1
16368 || attr
->form
== DW_FORM_block2
16369 || attr
->form
== DW_FORM_block4
16370 || attr
->form
== DW_FORM_block
16371 || attr
->form
== DW_FORM_exprloc
);
16374 /* Return non-zero if ATTR's value is a section offset --- classes
16375 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
16376 You may use DW_UNSND (attr) to retrieve such offsets.
16378 Section 7.5.4, "Attribute Encodings", explains that no attribute
16379 may have a value that belongs to more than one of these classes; it
16380 would be ambiguous if we did, because we use the same forms for all
16384 attr_form_is_section_offset (struct attribute
*attr
)
16386 return (attr
->form
== DW_FORM_data4
16387 || attr
->form
== DW_FORM_data8
16388 || attr
->form
== DW_FORM_sec_offset
);
16391 /* Return non-zero if ATTR's value falls in the 'constant' class, or
16392 zero otherwise. When this function returns true, you can apply
16393 dwarf2_get_attr_constant_value to it.
16395 However, note that for some attributes you must check
16396 attr_form_is_section_offset before using this test. DW_FORM_data4
16397 and DW_FORM_data8 are members of both the constant class, and of
16398 the classes that contain offsets into other debug sections
16399 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
16400 that, if an attribute's can be either a constant or one of the
16401 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
16402 taken as section offsets, not constants. */
16405 attr_form_is_constant (struct attribute
*attr
)
16407 switch (attr
->form
)
16409 case DW_FORM_sdata
:
16410 case DW_FORM_udata
:
16411 case DW_FORM_data1
:
16412 case DW_FORM_data2
:
16413 case DW_FORM_data4
:
16414 case DW_FORM_data8
:
16421 /* Return the .debug_loc section to use for CU.
16422 For DWO files use .debug_loc.dwo. */
16424 static struct dwarf2_section_info
*
16425 cu_debug_loc_section (struct dwarf2_cu
*cu
)
16428 return &cu
->dwo_unit
->dwo_file
->sections
.loc
;
16429 return &dwarf2_per_objfile
->loc
;
16432 /* A helper function that fills in a dwarf2_loclist_baton. */
16435 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
16436 struct dwarf2_loclist_baton
*baton
,
16437 struct attribute
*attr
)
16439 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
16441 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
16443 baton
->per_cu
= cu
->per_cu
;
16444 gdb_assert (baton
->per_cu
);
16445 /* We don't know how long the location list is, but make sure we
16446 don't run off the edge of the section. */
16447 baton
->size
= section
->size
- DW_UNSND (attr
);
16448 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
16449 baton
->base_address
= cu
->base_address
;
16453 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
16454 struct dwarf2_cu
*cu
)
16456 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16457 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
16459 if (attr_form_is_section_offset (attr
)
16460 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
16461 the section. If so, fall through to the complaint in the
16463 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
16465 struct dwarf2_loclist_baton
*baton
;
16467 baton
= obstack_alloc (&objfile
->objfile_obstack
,
16468 sizeof (struct dwarf2_loclist_baton
));
16470 fill_in_loclist_baton (cu
, baton
, attr
);
16472 if (cu
->base_known
== 0)
16473 complaint (&symfile_complaints
,
16474 _("Location list used without "
16475 "specifying the CU base address."));
16477 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
16478 SYMBOL_LOCATION_BATON (sym
) = baton
;
16482 struct dwarf2_locexpr_baton
*baton
;
16484 baton
= obstack_alloc (&objfile
->objfile_obstack
,
16485 sizeof (struct dwarf2_locexpr_baton
));
16486 baton
->per_cu
= cu
->per_cu
;
16487 gdb_assert (baton
->per_cu
);
16489 if (attr_form_is_block (attr
))
16491 /* Note that we're just copying the block's data pointer
16492 here, not the actual data. We're still pointing into the
16493 info_buffer for SYM's objfile; right now we never release
16494 that buffer, but when we do clean up properly this may
16496 baton
->size
= DW_BLOCK (attr
)->size
;
16497 baton
->data
= DW_BLOCK (attr
)->data
;
16501 dwarf2_invalid_attrib_class_complaint ("location description",
16502 SYMBOL_NATURAL_NAME (sym
));
16506 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
16507 SYMBOL_LOCATION_BATON (sym
) = baton
;
16511 /* Return the OBJFILE associated with the compilation unit CU. If CU
16512 came from a separate debuginfo file, then the master objfile is
16516 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
16518 struct objfile
*objfile
= per_cu
->objfile
;
16520 /* Return the master objfile, so that we can report and look up the
16521 correct file containing this variable. */
16522 if (objfile
->separate_debug_objfile_backlink
)
16523 objfile
= objfile
->separate_debug_objfile_backlink
;
16528 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
16529 (CU_HEADERP is unused in such case) or prepare a temporary copy at
16530 CU_HEADERP first. */
16532 static const struct comp_unit_head
*
16533 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
16534 struct dwarf2_per_cu_data
*per_cu
)
16536 struct objfile
*objfile
;
16537 struct dwarf2_per_objfile
*per_objfile
;
16538 gdb_byte
*info_ptr
;
16541 return &per_cu
->cu
->header
;
16543 objfile
= per_cu
->objfile
;
16544 per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
16545 info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
.sect_off
;
16547 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
16548 read_comp_unit_head (cu_headerp
, info_ptr
, objfile
->obfd
);
16553 /* Return the address size given in the compilation unit header for CU. */
16556 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
16558 struct comp_unit_head cu_header_local
;
16559 const struct comp_unit_head
*cu_headerp
;
16561 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
16563 return cu_headerp
->addr_size
;
16566 /* Return the offset size given in the compilation unit header for CU. */
16569 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
16571 struct comp_unit_head cu_header_local
;
16572 const struct comp_unit_head
*cu_headerp
;
16574 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
16576 return cu_headerp
->offset_size
;
16579 /* See its dwarf2loc.h declaration. */
16582 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
16584 struct comp_unit_head cu_header_local
;
16585 const struct comp_unit_head
*cu_headerp
;
16587 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
16589 if (cu_headerp
->version
== 2)
16590 return cu_headerp
->addr_size
;
16592 return cu_headerp
->offset_size
;
16595 /* Return the text offset of the CU. The returned offset comes from
16596 this CU's objfile. If this objfile came from a separate debuginfo
16597 file, then the offset may be different from the corresponding
16598 offset in the parent objfile. */
16601 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
16603 struct objfile
*objfile
= per_cu
->objfile
;
16605 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
16608 /* Locate the .debug_info compilation unit from CU's objfile which contains
16609 the DIE at OFFSET. Raises an error on failure. */
16611 static struct dwarf2_per_cu_data
*
16612 dwarf2_find_containing_comp_unit (sect_offset offset
,
16613 struct objfile
*objfile
)
16615 struct dwarf2_per_cu_data
*this_cu
;
16619 high
= dwarf2_per_objfile
->n_comp_units
- 1;
16622 int mid
= low
+ (high
- low
) / 2;
16624 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
.sect_off
16625 >= offset
.sect_off
)
16630 gdb_assert (low
== high
);
16631 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
.sect_off
16635 error (_("Dwarf Error: could not find partial DIE containing "
16636 "offset 0x%lx [in module %s]"),
16637 (long) offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
16639 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
.sect_off
16640 <= offset
.sect_off
);
16641 return dwarf2_per_objfile
->all_comp_units
[low
-1];
16645 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
16646 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
16647 && offset
.sect_off
>= this_cu
->offset
.sect_off
+ this_cu
->length
)
16648 error (_("invalid dwarf2 offset %u"), offset
.sect_off
);
16649 gdb_assert (offset
.sect_off
< this_cu
->offset
.sect_off
+ this_cu
->length
);
16654 /* Initialize dwarf2_cu CU, owned by PER_CU. */
16657 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
16659 memset (cu
, 0, sizeof (*cu
));
16661 cu
->per_cu
= per_cu
;
16662 cu
->objfile
= per_cu
->objfile
;
16663 obstack_init (&cu
->comp_unit_obstack
);
16666 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
16669 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
16670 enum language pretend_language
)
16672 struct attribute
*attr
;
16674 /* Set the language we're debugging. */
16675 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
16677 set_cu_language (DW_UNSND (attr
), cu
);
16680 cu
->language
= pretend_language
;
16681 cu
->language_defn
= language_def (cu
->language
);
16684 attr
= dwarf2_attr (comp_unit_die
, DW_AT_producer
, cu
);
16686 cu
->producer
= DW_STRING (attr
);
16689 /* Release one cached compilation unit, CU. We unlink it from the tree
16690 of compilation units, but we don't remove it from the read_in_chain;
16691 the caller is responsible for that.
16692 NOTE: DATA is a void * because this function is also used as a
16693 cleanup routine. */
16696 free_heap_comp_unit (void *data
)
16698 struct dwarf2_cu
*cu
= data
;
16700 gdb_assert (cu
->per_cu
!= NULL
);
16701 cu
->per_cu
->cu
= NULL
;
16704 obstack_free (&cu
->comp_unit_obstack
, NULL
);
16709 /* This cleanup function is passed the address of a dwarf2_cu on the stack
16710 when we're finished with it. We can't free the pointer itself, but be
16711 sure to unlink it from the cache. Also release any associated storage. */
16714 free_stack_comp_unit (void *data
)
16716 struct dwarf2_cu
*cu
= data
;
16718 gdb_assert (cu
->per_cu
!= NULL
);
16719 cu
->per_cu
->cu
= NULL
;
16722 obstack_free (&cu
->comp_unit_obstack
, NULL
);
16723 cu
->partial_dies
= NULL
;
16726 /* Free all cached compilation units. */
16729 free_cached_comp_units (void *data
)
16731 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
16733 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16734 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
16735 while (per_cu
!= NULL
)
16737 struct dwarf2_per_cu_data
*next_cu
;
16739 next_cu
= per_cu
->cu
->read_in_chain
;
16741 free_heap_comp_unit (per_cu
->cu
);
16742 *last_chain
= next_cu
;
16748 /* Increase the age counter on each cached compilation unit, and free
16749 any that are too old. */
16752 age_cached_comp_units (void)
16754 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
16756 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
16757 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16758 while (per_cu
!= NULL
)
16760 per_cu
->cu
->last_used
++;
16761 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
16762 dwarf2_mark (per_cu
->cu
);
16763 per_cu
= per_cu
->cu
->read_in_chain
;
16766 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16767 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
16768 while (per_cu
!= NULL
)
16770 struct dwarf2_per_cu_data
*next_cu
;
16772 next_cu
= per_cu
->cu
->read_in_chain
;
16774 if (!per_cu
->cu
->mark
)
16776 free_heap_comp_unit (per_cu
->cu
);
16777 *last_chain
= next_cu
;
16780 last_chain
= &per_cu
->cu
->read_in_chain
;
16786 /* Remove a single compilation unit from the cache. */
16789 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
16791 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
16793 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16794 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
16795 while (per_cu
!= NULL
)
16797 struct dwarf2_per_cu_data
*next_cu
;
16799 next_cu
= per_cu
->cu
->read_in_chain
;
16801 if (per_cu
== target_per_cu
)
16803 free_heap_comp_unit (per_cu
->cu
);
16805 *last_chain
= next_cu
;
16809 last_chain
= &per_cu
->cu
->read_in_chain
;
16815 /* Release all extra memory associated with OBJFILE. */
16818 dwarf2_free_objfile (struct objfile
*objfile
)
16820 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
16822 if (dwarf2_per_objfile
== NULL
)
16825 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
16826 free_cached_comp_units (NULL
);
16828 if (dwarf2_per_objfile
->quick_file_names_table
)
16829 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
16831 /* Everything else should be on the objfile obstack. */
16834 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
16835 We store these in a hash table separate from the DIEs, and preserve them
16836 when the DIEs are flushed out of cache.
16838 The CU "per_cu" pointer is needed because offset alone is not enough to
16839 uniquely identify the type. A file may have multiple .debug_types sections,
16840 or the type may come from a DWO file. We have to use something in
16841 dwarf2_per_cu_data (or the pointer to it) because we can enter the lookup
16842 routine, get_die_type_at_offset, from outside this file, and thus won't
16843 necessarily have PER_CU->cu. Fortunately, PER_CU is stable for the life
16846 struct dwarf2_per_cu_offset_and_type
16848 const struct dwarf2_per_cu_data
*per_cu
;
16849 sect_offset offset
;
16853 /* Hash function for a dwarf2_per_cu_offset_and_type. */
16856 per_cu_offset_and_type_hash (const void *item
)
16858 const struct dwarf2_per_cu_offset_and_type
*ofs
= item
;
16860 return (uintptr_t) ofs
->per_cu
+ ofs
->offset
.sect_off
;
16863 /* Equality function for a dwarf2_per_cu_offset_and_type. */
16866 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
16868 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
= item_lhs
;
16869 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
= item_rhs
;
16871 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
16872 && ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
);
16875 /* Set the type associated with DIE to TYPE. Save it in CU's hash
16876 table if necessary. For convenience, return TYPE.
16878 The DIEs reading must have careful ordering to:
16879 * Not cause infite loops trying to read in DIEs as a prerequisite for
16880 reading current DIE.
16881 * Not trying to dereference contents of still incompletely read in types
16882 while reading in other DIEs.
16883 * Enable referencing still incompletely read in types just by a pointer to
16884 the type without accessing its fields.
16886 Therefore caller should follow these rules:
16887 * Try to fetch any prerequisite types we may need to build this DIE type
16888 before building the type and calling set_die_type.
16889 * After building type call set_die_type for current DIE as soon as
16890 possible before fetching more types to complete the current type.
16891 * Make the type as complete as possible before fetching more types. */
16893 static struct type
*
16894 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
16896 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
16897 struct objfile
*objfile
= cu
->objfile
;
16899 /* For Ada types, make sure that the gnat-specific data is always
16900 initialized (if not already set). There are a few types where
16901 we should not be doing so, because the type-specific area is
16902 already used to hold some other piece of info (eg: TYPE_CODE_FLT
16903 where the type-specific area is used to store the floatformat).
16904 But this is not a problem, because the gnat-specific information
16905 is actually not needed for these types. */
16906 if (need_gnat_info (cu
)
16907 && TYPE_CODE (type
) != TYPE_CODE_FUNC
16908 && TYPE_CODE (type
) != TYPE_CODE_FLT
16909 && !HAVE_GNAT_AUX_INFO (type
))
16910 INIT_GNAT_SPECIFIC (type
);
16912 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
16914 dwarf2_per_objfile
->die_type_hash
=
16915 htab_create_alloc_ex (127,
16916 per_cu_offset_and_type_hash
,
16917 per_cu_offset_and_type_eq
,
16919 &objfile
->objfile_obstack
,
16920 hashtab_obstack_allocate
,
16921 dummy_obstack_deallocate
);
16924 ofs
.per_cu
= cu
->per_cu
;
16925 ofs
.offset
= die
->offset
;
16927 slot
= (struct dwarf2_per_cu_offset_and_type
**)
16928 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
16930 complaint (&symfile_complaints
,
16931 _("A problem internal to GDB: DIE 0x%x has type already set"),
16932 die
->offset
.sect_off
);
16933 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
16938 /* Look up the type for the die at OFFSET in the appropriate type_hash
16939 table, or return NULL if the die does not have a saved type. */
16941 static struct type
*
16942 get_die_type_at_offset (sect_offset offset
,
16943 struct dwarf2_per_cu_data
*per_cu
)
16945 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
16947 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
16950 ofs
.per_cu
= per_cu
;
16951 ofs
.offset
= offset
;
16952 slot
= htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
);
16959 /* Look up the type for DIE in the appropriate type_hash table,
16960 or return NULL if DIE does not have a saved type. */
16962 static struct type
*
16963 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16965 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
16968 /* Add a dependence relationship from CU to REF_PER_CU. */
16971 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
16972 struct dwarf2_per_cu_data
*ref_per_cu
)
16976 if (cu
->dependencies
== NULL
)
16978 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
16979 NULL
, &cu
->comp_unit_obstack
,
16980 hashtab_obstack_allocate
,
16981 dummy_obstack_deallocate
);
16983 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
16985 *slot
= ref_per_cu
;
16988 /* Subroutine of dwarf2_mark to pass to htab_traverse.
16989 Set the mark field in every compilation unit in the
16990 cache that we must keep because we are keeping CU. */
16993 dwarf2_mark_helper (void **slot
, void *data
)
16995 struct dwarf2_per_cu_data
*per_cu
;
16997 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
16999 /* cu->dependencies references may not yet have been ever read if QUIT aborts
17000 reading of the chain. As such dependencies remain valid it is not much
17001 useful to track and undo them during QUIT cleanups. */
17002 if (per_cu
->cu
== NULL
)
17005 if (per_cu
->cu
->mark
)
17007 per_cu
->cu
->mark
= 1;
17009 if (per_cu
->cu
->dependencies
!= NULL
)
17010 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
17015 /* Set the mark field in CU and in every other compilation unit in the
17016 cache that we must keep because we are keeping CU. */
17019 dwarf2_mark (struct dwarf2_cu
*cu
)
17024 if (cu
->dependencies
!= NULL
)
17025 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
17029 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
17033 per_cu
->cu
->mark
= 0;
17034 per_cu
= per_cu
->cu
->read_in_chain
;
17038 /* Trivial hash function for partial_die_info: the hash value of a DIE
17039 is its offset in .debug_info for this objfile. */
17042 partial_die_hash (const void *item
)
17044 const struct partial_die_info
*part_die
= item
;
17046 return part_die
->offset
.sect_off
;
17049 /* Trivial comparison function for partial_die_info structures: two DIEs
17050 are equal if they have the same offset. */
17053 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
17055 const struct partial_die_info
*part_die_lhs
= item_lhs
;
17056 const struct partial_die_info
*part_die_rhs
= item_rhs
;
17058 return part_die_lhs
->offset
.sect_off
== part_die_rhs
->offset
.sect_off
;
17061 static struct cmd_list_element
*set_dwarf2_cmdlist
;
17062 static struct cmd_list_element
*show_dwarf2_cmdlist
;
17065 set_dwarf2_cmd (char *args
, int from_tty
)
17067 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
17071 show_dwarf2_cmd (char *args
, int from_tty
)
17073 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
17076 /* If section described by INFO was mmapped, munmap it now. */
17079 munmap_section_buffer (struct dwarf2_section_info
*info
)
17081 if (info
->map_addr
!= NULL
)
17086 res
= munmap (info
->map_addr
, info
->map_len
);
17087 gdb_assert (res
== 0);
17089 /* Without HAVE_MMAP, we should never be here to begin with. */
17090 gdb_assert_not_reached ("no mmap support");
17095 /* munmap debug sections for OBJFILE, if necessary. */
17098 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
17100 struct dwarf2_per_objfile
*data
= d
;
17102 struct dwarf2_section_info
*section
;
17104 /* This is sorted according to the order they're defined in to make it easier
17105 to keep in sync. */
17106 munmap_section_buffer (&data
->info
);
17107 munmap_section_buffer (&data
->abbrev
);
17108 munmap_section_buffer (&data
->line
);
17109 munmap_section_buffer (&data
->loc
);
17110 munmap_section_buffer (&data
->macinfo
);
17111 munmap_section_buffer (&data
->macro
);
17112 munmap_section_buffer (&data
->str
);
17113 munmap_section_buffer (&data
->ranges
);
17114 munmap_section_buffer (&data
->addr
);
17115 munmap_section_buffer (&data
->frame
);
17116 munmap_section_buffer (&data
->eh_frame
);
17117 munmap_section_buffer (&data
->gdb_index
);
17120 VEC_iterate (dwarf2_section_info_def
, data
->types
, ix
, section
);
17122 munmap_section_buffer (section
);
17124 for (ix
= 0; ix
< dwarf2_per_objfile
->n_comp_units
; ++ix
)
17125 VEC_free (dwarf2_per_cu_ptr
,
17126 dwarf2_per_objfile
->all_comp_units
[ix
]->imported_symtabs
);
17128 VEC_free (dwarf2_section_info_def
, data
->types
);
17130 if (data
->dwo_files
)
17131 free_dwo_files (data
->dwo_files
, objfile
);
17135 /* The "save gdb-index" command. */
17137 /* The contents of the hash table we create when building the string
17139 struct strtab_entry
17141 offset_type offset
;
17145 /* Hash function for a strtab_entry.
17147 Function is used only during write_hash_table so no index format backward
17148 compatibility is needed. */
17151 hash_strtab_entry (const void *e
)
17153 const struct strtab_entry
*entry
= e
;
17154 return mapped_index_string_hash (INT_MAX
, entry
->str
);
17157 /* Equality function for a strtab_entry. */
17160 eq_strtab_entry (const void *a
, const void *b
)
17162 const struct strtab_entry
*ea
= a
;
17163 const struct strtab_entry
*eb
= b
;
17164 return !strcmp (ea
->str
, eb
->str
);
17167 /* Create a strtab_entry hash table. */
17170 create_strtab (void)
17172 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
17173 xfree
, xcalloc
, xfree
);
17176 /* Add a string to the constant pool. Return the string's offset in
17180 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
17183 struct strtab_entry entry
;
17184 struct strtab_entry
*result
;
17187 slot
= htab_find_slot (table
, &entry
, INSERT
);
17192 result
= XNEW (struct strtab_entry
);
17193 result
->offset
= obstack_object_size (cpool
);
17195 obstack_grow_str0 (cpool
, str
);
17198 return result
->offset
;
17201 /* An entry in the symbol table. */
17202 struct symtab_index_entry
17204 /* The name of the symbol. */
17206 /* The offset of the name in the constant pool. */
17207 offset_type index_offset
;
17208 /* A sorted vector of the indices of all the CUs that hold an object
17210 VEC (offset_type
) *cu_indices
;
17213 /* The symbol table. This is a power-of-2-sized hash table. */
17214 struct mapped_symtab
17216 offset_type n_elements
;
17218 struct symtab_index_entry
**data
;
17221 /* Hash function for a symtab_index_entry. */
17224 hash_symtab_entry (const void *e
)
17226 const struct symtab_index_entry
*entry
= e
;
17227 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
17228 sizeof (offset_type
) * VEC_length (offset_type
,
17229 entry
->cu_indices
),
17233 /* Equality function for a symtab_index_entry. */
17236 eq_symtab_entry (const void *a
, const void *b
)
17238 const struct symtab_index_entry
*ea
= a
;
17239 const struct symtab_index_entry
*eb
= b
;
17240 int len
= VEC_length (offset_type
, ea
->cu_indices
);
17241 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
17243 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
17244 VEC_address (offset_type
, eb
->cu_indices
),
17245 sizeof (offset_type
) * len
);
17248 /* Destroy a symtab_index_entry. */
17251 delete_symtab_entry (void *p
)
17253 struct symtab_index_entry
*entry
= p
;
17254 VEC_free (offset_type
, entry
->cu_indices
);
17258 /* Create a hash table holding symtab_index_entry objects. */
17261 create_symbol_hash_table (void)
17263 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
17264 delete_symtab_entry
, xcalloc
, xfree
);
17267 /* Create a new mapped symtab object. */
17269 static struct mapped_symtab
*
17270 create_mapped_symtab (void)
17272 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
17273 symtab
->n_elements
= 0;
17274 symtab
->size
= 1024;
17275 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
17279 /* Destroy a mapped_symtab. */
17282 cleanup_mapped_symtab (void *p
)
17284 struct mapped_symtab
*symtab
= p
;
17285 /* The contents of the array are freed when the other hash table is
17287 xfree (symtab
->data
);
17291 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
17294 Function is used only during write_hash_table so no index format backward
17295 compatibility is needed. */
17297 static struct symtab_index_entry
**
17298 find_slot (struct mapped_symtab
*symtab
, const char *name
)
17300 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
17302 index
= hash
& (symtab
->size
- 1);
17303 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
17307 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
17308 return &symtab
->data
[index
];
17309 index
= (index
+ step
) & (symtab
->size
- 1);
17313 /* Expand SYMTAB's hash table. */
17316 hash_expand (struct mapped_symtab
*symtab
)
17318 offset_type old_size
= symtab
->size
;
17320 struct symtab_index_entry
**old_entries
= symtab
->data
;
17323 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
17325 for (i
= 0; i
< old_size
; ++i
)
17327 if (old_entries
[i
])
17329 struct symtab_index_entry
**slot
= find_slot (symtab
,
17330 old_entries
[i
]->name
);
17331 *slot
= old_entries
[i
];
17335 xfree (old_entries
);
17338 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
17339 is the index of the CU in which the symbol appears. */
17342 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
17343 offset_type cu_index
)
17345 struct symtab_index_entry
**slot
;
17347 ++symtab
->n_elements
;
17348 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
17349 hash_expand (symtab
);
17351 slot
= find_slot (symtab
, name
);
17354 *slot
= XNEW (struct symtab_index_entry
);
17355 (*slot
)->name
= name
;
17356 (*slot
)->cu_indices
= NULL
;
17358 /* Don't push an index twice. Due to how we add entries we only
17359 have to check the last one. */
17360 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
17361 || VEC_last (offset_type
, (*slot
)->cu_indices
) != cu_index
)
17362 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
17365 /* Add a vector of indices to the constant pool. */
17368 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
17369 struct symtab_index_entry
*entry
)
17373 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
17376 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
17377 offset_type val
= MAYBE_SWAP (len
);
17382 entry
->index_offset
= obstack_object_size (cpool
);
17384 obstack_grow (cpool
, &val
, sizeof (val
));
17386 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
17389 val
= MAYBE_SWAP (iter
);
17390 obstack_grow (cpool
, &val
, sizeof (val
));
17395 struct symtab_index_entry
*old_entry
= *slot
;
17396 entry
->index_offset
= old_entry
->index_offset
;
17399 return entry
->index_offset
;
17402 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
17403 constant pool entries going into the obstack CPOOL. */
17406 write_hash_table (struct mapped_symtab
*symtab
,
17407 struct obstack
*output
, struct obstack
*cpool
)
17410 htab_t symbol_hash_table
;
17413 symbol_hash_table
= create_symbol_hash_table ();
17414 str_table
= create_strtab ();
17416 /* We add all the index vectors to the constant pool first, to
17417 ensure alignment is ok. */
17418 for (i
= 0; i
< symtab
->size
; ++i
)
17420 if (symtab
->data
[i
])
17421 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
17424 /* Now write out the hash table. */
17425 for (i
= 0; i
< symtab
->size
; ++i
)
17427 offset_type str_off
, vec_off
;
17429 if (symtab
->data
[i
])
17431 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
17432 vec_off
= symtab
->data
[i
]->index_offset
;
17436 /* While 0 is a valid constant pool index, it is not valid
17437 to have 0 for both offsets. */
17442 str_off
= MAYBE_SWAP (str_off
);
17443 vec_off
= MAYBE_SWAP (vec_off
);
17445 obstack_grow (output
, &str_off
, sizeof (str_off
));
17446 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
17449 htab_delete (str_table
);
17450 htab_delete (symbol_hash_table
);
17453 /* Struct to map psymtab to CU index in the index file. */
17454 struct psymtab_cu_index_map
17456 struct partial_symtab
*psymtab
;
17457 unsigned int cu_index
;
17461 hash_psymtab_cu_index (const void *item
)
17463 const struct psymtab_cu_index_map
*map
= item
;
17465 return htab_hash_pointer (map
->psymtab
);
17469 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
17471 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
17472 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
17474 return lhs
->psymtab
== rhs
->psymtab
;
17477 /* Helper struct for building the address table. */
17478 struct addrmap_index_data
17480 struct objfile
*objfile
;
17481 struct obstack
*addr_obstack
;
17482 htab_t cu_index_htab
;
17484 /* Non-zero if the previous_* fields are valid.
17485 We can't write an entry until we see the next entry (since it is only then
17486 that we know the end of the entry). */
17487 int previous_valid
;
17488 /* Index of the CU in the table of all CUs in the index file. */
17489 unsigned int previous_cu_index
;
17490 /* Start address of the CU. */
17491 CORE_ADDR previous_cu_start
;
17494 /* Write an address entry to OBSTACK. */
17497 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
17498 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
17500 offset_type cu_index_to_write
;
17502 CORE_ADDR baseaddr
;
17504 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
17506 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
17507 obstack_grow (obstack
, addr
, 8);
17508 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
17509 obstack_grow (obstack
, addr
, 8);
17510 cu_index_to_write
= MAYBE_SWAP (cu_index
);
17511 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
17514 /* Worker function for traversing an addrmap to build the address table. */
17517 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
17519 struct addrmap_index_data
*data
= datap
;
17520 struct partial_symtab
*pst
= obj
;
17522 if (data
->previous_valid
)
17523 add_address_entry (data
->objfile
, data
->addr_obstack
,
17524 data
->previous_cu_start
, start_addr
,
17525 data
->previous_cu_index
);
17527 data
->previous_cu_start
= start_addr
;
17530 struct psymtab_cu_index_map find_map
, *map
;
17531 find_map
.psymtab
= pst
;
17532 map
= htab_find (data
->cu_index_htab
, &find_map
);
17533 gdb_assert (map
!= NULL
);
17534 data
->previous_cu_index
= map
->cu_index
;
17535 data
->previous_valid
= 1;
17538 data
->previous_valid
= 0;
17543 /* Write OBJFILE's address map to OBSTACK.
17544 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
17545 in the index file. */
17548 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
17549 htab_t cu_index_htab
)
17551 struct addrmap_index_data addrmap_index_data
;
17553 /* When writing the address table, we have to cope with the fact that
17554 the addrmap iterator only provides the start of a region; we have to
17555 wait until the next invocation to get the start of the next region. */
17557 addrmap_index_data
.objfile
= objfile
;
17558 addrmap_index_data
.addr_obstack
= obstack
;
17559 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
17560 addrmap_index_data
.previous_valid
= 0;
17562 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
17563 &addrmap_index_data
);
17565 /* It's highly unlikely the last entry (end address = 0xff...ff)
17566 is valid, but we should still handle it.
17567 The end address is recorded as the start of the next region, but that
17568 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
17570 if (addrmap_index_data
.previous_valid
)
17571 add_address_entry (objfile
, obstack
,
17572 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
17573 addrmap_index_data
.previous_cu_index
);
17576 /* Add a list of partial symbols to SYMTAB. */
17579 write_psymbols (struct mapped_symtab
*symtab
,
17581 struct partial_symbol
**psymp
,
17583 offset_type cu_index
,
17586 for (; count
-- > 0; ++psymp
)
17588 void **slot
, *lookup
;
17590 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
17591 error (_("Ada is not currently supported by the index"));
17593 /* We only want to add a given psymbol once. However, we also
17594 want to account for whether it is global or static. So, we
17595 may add it twice, using slightly different values. */
17598 uintptr_t val
= 1 | (uintptr_t) *psymp
;
17600 lookup
= (void *) val
;
17605 /* Only add a given psymbol once. */
17606 slot
= htab_find_slot (psyms_seen
, lookup
, INSERT
);
17610 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (*psymp
), cu_index
);
17615 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
17616 exception if there is an error. */
17619 write_obstack (FILE *file
, struct obstack
*obstack
)
17621 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
17623 != obstack_object_size (obstack
))
17624 error (_("couldn't data write to file"));
17627 /* Unlink a file if the argument is not NULL. */
17630 unlink_if_set (void *p
)
17632 char **filename
= p
;
17634 unlink (*filename
);
17637 /* A helper struct used when iterating over debug_types. */
17638 struct signatured_type_index_data
17640 struct objfile
*objfile
;
17641 struct mapped_symtab
*symtab
;
17642 struct obstack
*types_list
;
17647 /* A helper function that writes a single signatured_type to an
17651 write_one_signatured_type (void **slot
, void *d
)
17653 struct signatured_type_index_data
*info
= d
;
17654 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
17655 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
17656 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
17659 write_psymbols (info
->symtab
,
17661 info
->objfile
->global_psymbols
.list
17662 + psymtab
->globals_offset
,
17663 psymtab
->n_global_syms
, info
->cu_index
,
17665 write_psymbols (info
->symtab
,
17667 info
->objfile
->static_psymbols
.list
17668 + psymtab
->statics_offset
,
17669 psymtab
->n_static_syms
, info
->cu_index
,
17672 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
17673 entry
->per_cu
.offset
.sect_off
);
17674 obstack_grow (info
->types_list
, val
, 8);
17675 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
17676 entry
->type_offset_in_tu
.cu_off
);
17677 obstack_grow (info
->types_list
, val
, 8);
17678 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
17679 obstack_grow (info
->types_list
, val
, 8);
17686 /* Recurse into all "included" dependencies and write their symbols as
17687 if they appeared in this psymtab. */
17690 recursively_write_psymbols (struct objfile
*objfile
,
17691 struct partial_symtab
*psymtab
,
17692 struct mapped_symtab
*symtab
,
17694 offset_type cu_index
)
17698 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
17699 if (psymtab
->dependencies
[i
]->user
!= NULL
)
17700 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
17701 symtab
, psyms_seen
, cu_index
);
17703 write_psymbols (symtab
,
17705 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
17706 psymtab
->n_global_syms
, cu_index
,
17708 write_psymbols (symtab
,
17710 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
17711 psymtab
->n_static_syms
, cu_index
,
17715 /* Create an index file for OBJFILE in the directory DIR. */
17718 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
17720 struct cleanup
*cleanup
;
17721 char *filename
, *cleanup_filename
;
17722 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
17723 struct obstack cu_list
, types_cu_list
;
17726 struct mapped_symtab
*symtab
;
17727 offset_type val
, size_of_contents
, total_len
;
17730 htab_t cu_index_htab
;
17731 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
17733 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
17736 if (dwarf2_per_objfile
->using_index
)
17737 error (_("Cannot use an index to create the index"));
17739 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
17740 error (_("Cannot make an index when the file has multiple .debug_types sections"));
17742 if (stat (objfile
->name
, &st
) < 0)
17743 perror_with_name (objfile
->name
);
17745 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
17746 INDEX_SUFFIX
, (char *) NULL
);
17747 cleanup
= make_cleanup (xfree
, filename
);
17749 out_file
= fopen (filename
, "wb");
17751 error (_("Can't open `%s' for writing"), filename
);
17753 cleanup_filename
= filename
;
17754 make_cleanup (unlink_if_set
, &cleanup_filename
);
17756 symtab
= create_mapped_symtab ();
17757 make_cleanup (cleanup_mapped_symtab
, symtab
);
17759 obstack_init (&addr_obstack
);
17760 make_cleanup_obstack_free (&addr_obstack
);
17762 obstack_init (&cu_list
);
17763 make_cleanup_obstack_free (&cu_list
);
17765 obstack_init (&types_cu_list
);
17766 make_cleanup_obstack_free (&types_cu_list
);
17768 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
17769 NULL
, xcalloc
, xfree
);
17770 make_cleanup_htab_delete (psyms_seen
);
17772 /* While we're scanning CU's create a table that maps a psymtab pointer
17773 (which is what addrmap records) to its index (which is what is recorded
17774 in the index file). This will later be needed to write the address
17776 cu_index_htab
= htab_create_alloc (100,
17777 hash_psymtab_cu_index
,
17778 eq_psymtab_cu_index
,
17779 NULL
, xcalloc
, xfree
);
17780 make_cleanup_htab_delete (cu_index_htab
);
17781 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
17782 xmalloc (sizeof (struct psymtab_cu_index_map
)
17783 * dwarf2_per_objfile
->n_comp_units
);
17784 make_cleanup (xfree
, psymtab_cu_index_map
);
17786 /* The CU list is already sorted, so we don't need to do additional
17787 work here. Also, the debug_types entries do not appear in
17788 all_comp_units, but only in their own hash table. */
17789 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
17791 struct dwarf2_per_cu_data
*per_cu
17792 = dwarf2_per_objfile
->all_comp_units
[i
];
17793 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
17795 struct psymtab_cu_index_map
*map
;
17798 if (psymtab
->user
== NULL
)
17799 recursively_write_psymbols (objfile
, psymtab
, symtab
, psyms_seen
, i
);
17801 map
= &psymtab_cu_index_map
[i
];
17802 map
->psymtab
= psymtab
;
17804 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
17805 gdb_assert (slot
!= NULL
);
17806 gdb_assert (*slot
== NULL
);
17809 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
17810 per_cu
->offset
.sect_off
);
17811 obstack_grow (&cu_list
, val
, 8);
17812 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
17813 obstack_grow (&cu_list
, val
, 8);
17816 /* Dump the address map. */
17817 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
17819 /* Write out the .debug_type entries, if any. */
17820 if (dwarf2_per_objfile
->signatured_types
)
17822 struct signatured_type_index_data sig_data
;
17824 sig_data
.objfile
= objfile
;
17825 sig_data
.symtab
= symtab
;
17826 sig_data
.types_list
= &types_cu_list
;
17827 sig_data
.psyms_seen
= psyms_seen
;
17828 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
17829 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
17830 write_one_signatured_type
, &sig_data
);
17833 obstack_init (&constant_pool
);
17834 make_cleanup_obstack_free (&constant_pool
);
17835 obstack_init (&symtab_obstack
);
17836 make_cleanup_obstack_free (&symtab_obstack
);
17837 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
17839 obstack_init (&contents
);
17840 make_cleanup_obstack_free (&contents
);
17841 size_of_contents
= 6 * sizeof (offset_type
);
17842 total_len
= size_of_contents
;
17844 /* The version number. */
17845 val
= MAYBE_SWAP (6);
17846 obstack_grow (&contents
, &val
, sizeof (val
));
17848 /* The offset of the CU list from the start of the file. */
17849 val
= MAYBE_SWAP (total_len
);
17850 obstack_grow (&contents
, &val
, sizeof (val
));
17851 total_len
+= obstack_object_size (&cu_list
);
17853 /* The offset of the types CU list from the start of the file. */
17854 val
= MAYBE_SWAP (total_len
);
17855 obstack_grow (&contents
, &val
, sizeof (val
));
17856 total_len
+= obstack_object_size (&types_cu_list
);
17858 /* The offset of the address table from the start of the file. */
17859 val
= MAYBE_SWAP (total_len
);
17860 obstack_grow (&contents
, &val
, sizeof (val
));
17861 total_len
+= obstack_object_size (&addr_obstack
);
17863 /* The offset of the symbol table from the start of the file. */
17864 val
= MAYBE_SWAP (total_len
);
17865 obstack_grow (&contents
, &val
, sizeof (val
));
17866 total_len
+= obstack_object_size (&symtab_obstack
);
17868 /* The offset of the constant pool from the start of the file. */
17869 val
= MAYBE_SWAP (total_len
);
17870 obstack_grow (&contents
, &val
, sizeof (val
));
17871 total_len
+= obstack_object_size (&constant_pool
);
17873 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
17875 write_obstack (out_file
, &contents
);
17876 write_obstack (out_file
, &cu_list
);
17877 write_obstack (out_file
, &types_cu_list
);
17878 write_obstack (out_file
, &addr_obstack
);
17879 write_obstack (out_file
, &symtab_obstack
);
17880 write_obstack (out_file
, &constant_pool
);
17884 /* We want to keep the file, so we set cleanup_filename to NULL
17885 here. See unlink_if_set. */
17886 cleanup_filename
= NULL
;
17888 do_cleanups (cleanup
);
17891 /* Implementation of the `save gdb-index' command.
17893 Note that the file format used by this command is documented in the
17894 GDB manual. Any changes here must be documented there. */
17897 save_gdb_index_command (char *arg
, int from_tty
)
17899 struct objfile
*objfile
;
17902 error (_("usage: save gdb-index DIRECTORY"));
17904 ALL_OBJFILES (objfile
)
17908 /* If the objfile does not correspond to an actual file, skip it. */
17909 if (stat (objfile
->name
, &st
) < 0)
17912 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
17913 if (dwarf2_per_objfile
)
17915 volatile struct gdb_exception except
;
17917 TRY_CATCH (except
, RETURN_MASK_ERROR
)
17919 write_psymtabs_to_index (objfile
, arg
);
17921 if (except
.reason
< 0)
17922 exception_fprintf (gdb_stderr
, except
,
17923 _("Error while writing index for `%s': "),
17931 int dwarf2_always_disassemble
;
17934 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
17935 struct cmd_list_element
*c
, const char *value
)
17937 fprintf_filtered (file
,
17938 _("Whether to always disassemble "
17939 "DWARF expressions is %s.\n"),
17944 show_check_physname (struct ui_file
*file
, int from_tty
,
17945 struct cmd_list_element
*c
, const char *value
)
17947 fprintf_filtered (file
,
17948 _("Whether to check \"physname\" is %s.\n"),
17952 void _initialize_dwarf2_read (void);
17955 _initialize_dwarf2_read (void)
17957 struct cmd_list_element
*c
;
17959 dwarf2_objfile_data_key
17960 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
17962 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
17963 Set DWARF 2 specific variables.\n\
17964 Configure DWARF 2 variables such as the cache size"),
17965 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
17966 0/*allow-unknown*/, &maintenance_set_cmdlist
);
17968 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
17969 Show DWARF 2 specific variables\n\
17970 Show DWARF 2 variables such as the cache size"),
17971 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
17972 0/*allow-unknown*/, &maintenance_show_cmdlist
);
17974 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
17975 &dwarf2_max_cache_age
, _("\
17976 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
17977 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
17978 A higher limit means that cached compilation units will be stored\n\
17979 in memory longer, and more total memory will be used. Zero disables\n\
17980 caching, which can slow down startup."),
17982 show_dwarf2_max_cache_age
,
17983 &set_dwarf2_cmdlist
,
17984 &show_dwarf2_cmdlist
);
17986 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
17987 &dwarf2_always_disassemble
, _("\
17988 Set whether `info address' always disassembles DWARF expressions."), _("\
17989 Show whether `info address' always disassembles DWARF expressions."), _("\
17990 When enabled, DWARF expressions are always printed in an assembly-like\n\
17991 syntax. When disabled, expressions will be printed in a more\n\
17992 conversational style, when possible."),
17994 show_dwarf2_always_disassemble
,
17995 &set_dwarf2_cmdlist
,
17996 &show_dwarf2_cmdlist
);
17998 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
17999 Set debugging of the dwarf2 DIE reader."), _("\
18000 Show debugging of the dwarf2 DIE reader."), _("\
18001 When enabled (non-zero), DIEs are dumped after they are read in.\n\
18002 The value is the maximum depth to print."),
18005 &setdebuglist
, &showdebuglist
);
18007 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
18008 Set cross-checking of \"physname\" code against demangler."), _("\
18009 Show cross-checking of \"physname\" code against demangler."), _("\
18010 When enabled, GDB's internal \"physname\" code is checked against\n\
18012 NULL
, show_check_physname
,
18013 &setdebuglist
, &showdebuglist
);
18015 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
18017 Save a gdb-index file.\n\
18018 Usage: save gdb-index DIRECTORY"),
18020 set_cmd_completer (c
, filename_completer
);