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"
66 #include "gdb_string.h"
67 #include "gdb_assert.h"
68 #include <sys/types.h>
75 #define MAP_FAILED ((void *) -1)
79 typedef struct symbol
*symbolp
;
82 /* When non-zero, dump DIEs after they are read in. */
83 static int dwarf2_die_debug
= 0;
85 /* When non-zero, cross-check physname against demangler. */
86 static int check_physname
= 0;
88 /* When non-zero, do not reject deprecated .gdb_index sections. */
89 int use_deprecated_index_sections
= 0;
93 /* When set, the file that we're processing is known to have debugging
94 info for C++ namespaces. GCC 3.3.x did not produce this information,
95 but later versions do. */
97 static int processing_has_namespace_info
;
99 static const struct objfile_data
*dwarf2_objfile_data_key
;
101 struct dwarf2_section_info
106 /* Not NULL if the section was actually mmapped. */
108 /* Page aligned size of mmapped area. */
109 bfd_size_type map_len
;
110 /* True if we have tried to read this section. */
114 typedef struct dwarf2_section_info dwarf2_section_info_def
;
115 DEF_VEC_O (dwarf2_section_info_def
);
117 /* All offsets in the index are of this type. It must be
118 architecture-independent. */
119 typedef uint32_t offset_type
;
121 DEF_VEC_I (offset_type
);
123 /* A description of the mapped index. The file format is described in
124 a comment by the code that writes the index. */
127 /* Index data format version. */
130 /* The total length of the buffer. */
133 /* A pointer to the address table data. */
134 const gdb_byte
*address_table
;
136 /* Size of the address table data in bytes. */
137 offset_type address_table_size
;
139 /* The symbol table, implemented as a hash table. */
140 const offset_type
*symbol_table
;
142 /* Size in slots, each slot is 2 offset_types. */
143 offset_type symbol_table_slots
;
145 /* A pointer to the constant pool. */
146 const char *constant_pool
;
149 /* Collection of data recorded per objfile.
150 This hangs off of dwarf2_objfile_data_key. */
152 struct dwarf2_per_objfile
154 struct dwarf2_section_info info
;
155 struct dwarf2_section_info abbrev
;
156 struct dwarf2_section_info line
;
157 struct dwarf2_section_info loc
;
158 struct dwarf2_section_info macinfo
;
159 struct dwarf2_section_info macro
;
160 struct dwarf2_section_info str
;
161 struct dwarf2_section_info ranges
;
162 struct dwarf2_section_info frame
;
163 struct dwarf2_section_info eh_frame
;
164 struct dwarf2_section_info gdb_index
;
166 VEC (dwarf2_section_info_def
) *types
;
169 struct objfile
*objfile
;
171 /* Table of all the compilation units. This is used to locate
172 the target compilation unit of a particular reference. */
173 struct dwarf2_per_cu_data
**all_comp_units
;
175 /* The number of compilation units in ALL_COMP_UNITS. */
178 /* The number of .debug_types-related CUs. */
181 /* The .debug_types-related CUs (TUs). */
182 struct dwarf2_per_cu_data
**all_type_units
;
184 /* A chain of compilation units that are currently read in, so that
185 they can be freed later. */
186 struct dwarf2_per_cu_data
*read_in_chain
;
188 /* A table mapping .debug_types signatures to its signatured_type entry.
189 This is NULL if the .debug_types section hasn't been read in yet. */
190 htab_t signatured_types
;
192 /* A flag indicating wether this objfile has a section loaded at a
194 int has_section_at_zero
;
196 /* True if we are using the mapped index,
197 or we are faking it for OBJF_READNOW's sake. */
198 unsigned char using_index
;
200 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
201 struct mapped_index
*index_table
;
203 /* When using index_table, this keeps track of all quick_file_names entries.
204 TUs can share line table entries with CUs or other TUs, and there can be
205 a lot more TUs than unique line tables, so we maintain a separate table
206 of all line table entries to support the sharing. */
207 htab_t quick_file_names_table
;
209 /* Set during partial symbol reading, to prevent queueing of full
211 int reading_partial_symbols
;
213 /* Table mapping type .debug_info DIE offsets to types.
214 This is NULL if not allocated yet.
215 It (currently) makes sense to allocate debug_types_type_hash lazily.
216 To keep things simple we allocate both lazily. */
217 htab_t debug_info_type_hash
;
219 /* Table mapping type .debug_types DIE sect_offset to types.
220 This is NULL if not allocated yet. */
221 htab_t debug_types_type_hash
;
224 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
226 /* Default names of the debugging sections. */
228 /* Note that if the debugging section has been compressed, it might
229 have a name like .zdebug_info. */
231 static const struct dwarf2_debug_sections dwarf2_elf_names
=
233 { ".debug_info", ".zdebug_info" },
234 { ".debug_abbrev", ".zdebug_abbrev" },
235 { ".debug_line", ".zdebug_line" },
236 { ".debug_loc", ".zdebug_loc" },
237 { ".debug_macinfo", ".zdebug_macinfo" },
238 { ".debug_macro", ".zdebug_macro" },
239 { ".debug_str", ".zdebug_str" },
240 { ".debug_ranges", ".zdebug_ranges" },
241 { ".debug_types", ".zdebug_types" },
242 { ".debug_frame", ".zdebug_frame" },
243 { ".eh_frame", NULL
},
244 { ".gdb_index", ".zgdb_index" },
248 /* local data types */
250 /* We hold several abbreviation tables in memory at the same time. */
251 #ifndef ABBREV_HASH_SIZE
252 #define ABBREV_HASH_SIZE 121
255 /* The data in a compilation unit header, after target2host
256 translation, looks like this. */
257 struct comp_unit_head
261 unsigned char addr_size
;
262 unsigned char signed_addr_p
;
263 sect_offset abbrev_offset
;
265 /* Size of file offsets; either 4 or 8. */
266 unsigned int offset_size
;
268 /* Size of the length field; either 4 or 12. */
269 unsigned int initial_length_size
;
271 /* Offset to the first byte of this compilation unit header in the
272 .debug_info section, for resolving relative reference dies. */
275 /* Offset to first die in this cu from the start of the cu.
276 This will be the first byte following the compilation unit header. */
277 cu_offset first_die_offset
;
280 /* Type used for delaying computation of method physnames.
281 See comments for compute_delayed_physnames. */
282 struct delayed_method_info
284 /* The type to which the method is attached, i.e., its parent class. */
287 /* The index of the method in the type's function fieldlists. */
290 /* The index of the method in the fieldlist. */
293 /* The name of the DIE. */
296 /* The DIE associated with this method. */
297 struct die_info
*die
;
300 typedef struct delayed_method_info delayed_method_info
;
301 DEF_VEC_O (delayed_method_info
);
303 /* Internal state when decoding a particular compilation unit. */
306 /* The objfile containing this compilation unit. */
307 struct objfile
*objfile
;
309 /* The header of the compilation unit. */
310 struct comp_unit_head header
;
312 /* Base address of this compilation unit. */
313 CORE_ADDR base_address
;
315 /* Non-zero if base_address has been set. */
318 /* The language we are debugging. */
319 enum language language
;
320 const struct language_defn
*language_defn
;
322 const char *producer
;
324 /* The generic symbol table building routines have separate lists for
325 file scope symbols and all all other scopes (local scopes). So
326 we need to select the right one to pass to add_symbol_to_list().
327 We do it by keeping a pointer to the correct list in list_in_scope.
329 FIXME: The original dwarf code just treated the file scope as the
330 first local scope, and all other local scopes as nested local
331 scopes, and worked fine. Check to see if we really need to
332 distinguish these in buildsym.c. */
333 struct pending
**list_in_scope
;
335 /* DWARF abbreviation table associated with this compilation unit. */
336 struct abbrev_info
**dwarf2_abbrevs
;
338 /* Storage for the abbrev table. */
339 struct obstack abbrev_obstack
;
341 /* Hash table holding all the loaded partial DIEs
342 with partial_die->offset.SECT_OFF as hash. */
345 /* Storage for things with the same lifetime as this read-in compilation
346 unit, including partial DIEs. */
347 struct obstack comp_unit_obstack
;
349 /* When multiple dwarf2_cu structures are living in memory, this field
350 chains them all together, so that they can be released efficiently.
351 We will probably also want a generation counter so that most-recently-used
352 compilation units are cached... */
353 struct dwarf2_per_cu_data
*read_in_chain
;
355 /* Backchain to our per_cu entry if the tree has been built. */
356 struct dwarf2_per_cu_data
*per_cu
;
358 /* How many compilation units ago was this CU last referenced? */
361 /* A hash table of DIE cu_offset for following references with
362 die_info->offset.sect_off as hash. */
365 /* Full DIEs if read in. */
366 struct die_info
*dies
;
368 /* A set of pointers to dwarf2_per_cu_data objects for compilation
369 units referenced by this one. Only set during full symbol processing;
370 partial symbol tables do not have dependencies. */
373 /* Header data from the line table, during full symbol processing. */
374 struct line_header
*line_header
;
376 /* A list of methods which need to have physnames computed
377 after all type information has been read. */
378 VEC (delayed_method_info
) *method_list
;
380 /* To be copied to symtab->call_site_htab. */
381 htab_t call_site_htab
;
383 /* Mark used when releasing cached dies. */
384 unsigned int mark
: 1;
386 /* This CU references .debug_loc. See the symtab->locations_valid field.
387 This test is imperfect as there may exist optimized debug code not using
388 any location list and still facing inlining issues if handled as
389 unoptimized code. For a future better test see GCC PR other/32998. */
390 unsigned int has_loclist
: 1;
392 /* These cache the results of producer_is_gxx_lt_4_6.
393 CHECKED_PRODUCER is set if PRODUCER_IS_GXX_LT_4_6 is valid. This
394 information is cached because profiling CU expansion showed
395 excessive time spent in producer_is_gxx_lt_4_6. */
396 unsigned int checked_producer
: 1;
397 unsigned int producer_is_gxx_lt_4_6
: 1;
400 /* Persistent data held for a compilation unit, even when not
401 processing it. We put a pointer to this structure in the
402 read_symtab_private field of the psymtab. */
404 struct dwarf2_per_cu_data
406 /* The start offset and length of this compilation unit. 2**29-1
407 bytes should suffice to store the length of any compilation unit
408 - if it doesn't, GDB will fall over anyway.
409 NOTE: Unlike comp_unit_head.length, this length includes
410 initial_length_size. */
412 unsigned int length
: 29;
414 /* Flag indicating this compilation unit will be read in before
415 any of the current compilation units are processed. */
416 unsigned int queued
: 1;
418 /* This flag will be set when reading partial DIEs if we need to load
419 absolutely all DIEs for this compilation unit, instead of just the ones
420 we think are interesting. It gets set if we look for a DIE in the
421 hash table and don't find it. */
422 unsigned int load_all_dies
: 1;
424 /* Non-null if this CU is from .debug_types; in which case it points
425 to the section. Otherwise it's from .debug_info. */
426 struct dwarf2_section_info
*debug_types_section
;
428 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
429 of the CU cache it gets reset to NULL again. */
430 struct dwarf2_cu
*cu
;
432 /* The corresponding objfile.
433 Normally we can get the objfile from dwarf2_per_objfile.
434 However we can enter this file with just a "per_cu" handle. */
435 struct objfile
*objfile
;
437 /* When using partial symbol tables, the 'psymtab' field is active.
438 Otherwise the 'quick' field is active. */
441 /* The partial symbol table associated with this compilation unit,
442 or NULL for partial units (which do not have an associated
444 struct partial_symtab
*psymtab
;
446 /* Data needed by the "quick" functions. */
447 struct dwarf2_per_cu_quick_data
*quick
;
451 /* Entry in the signatured_types hash table. */
453 struct signatured_type
457 /* Offset in this TU of the type defined by this TU. */
458 cu_offset type_offset
;
460 /* The CU(/TU) of this type. */
461 struct dwarf2_per_cu_data per_cu
;
464 /* Struct used to pass misc. parameters to read_die_and_children, et
465 al. which are used for both .debug_info and .debug_types dies.
466 All parameters here are unchanging for the life of the call. This
467 struct exists to abstract away the constant parameters of die
470 struct die_reader_specs
472 /* The bfd of this objfile. */
475 /* The CU of the DIE we are parsing. */
476 struct dwarf2_cu
*cu
;
478 /* Pointer to start of section buffer.
479 This is either the start of .debug_info or .debug_types. */
480 const gdb_byte
*buffer
;
483 /* The line number information for a compilation unit (found in the
484 .debug_line section) begins with a "statement program header",
485 which contains the following information. */
488 unsigned int total_length
;
489 unsigned short version
;
490 unsigned int header_length
;
491 unsigned char minimum_instruction_length
;
492 unsigned char maximum_ops_per_instruction
;
493 unsigned char default_is_stmt
;
495 unsigned char line_range
;
496 unsigned char opcode_base
;
498 /* standard_opcode_lengths[i] is the number of operands for the
499 standard opcode whose value is i. This means that
500 standard_opcode_lengths[0] is unused, and the last meaningful
501 element is standard_opcode_lengths[opcode_base - 1]. */
502 unsigned char *standard_opcode_lengths
;
504 /* The include_directories table. NOTE! These strings are not
505 allocated with xmalloc; instead, they are pointers into
506 debug_line_buffer. If you try to free them, `free' will get
508 unsigned int num_include_dirs
, include_dirs_size
;
511 /* The file_names table. NOTE! These strings are not allocated
512 with xmalloc; instead, they are pointers into debug_line_buffer.
513 Don't try to free them directly. */
514 unsigned int num_file_names
, file_names_size
;
518 unsigned int dir_index
;
519 unsigned int mod_time
;
521 int included_p
; /* Non-zero if referenced by the Line Number Program. */
522 struct symtab
*symtab
; /* The associated symbol table, if any. */
525 /* The start and end of the statement program following this
526 header. These point into dwarf2_per_objfile->line_buffer. */
527 gdb_byte
*statement_program_start
, *statement_program_end
;
530 /* When we construct a partial symbol table entry we only
531 need this much information. */
532 struct partial_die_info
534 /* Offset of this DIE. */
537 /* DWARF-2 tag for this DIE. */
538 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
540 /* Assorted flags describing the data found in this DIE. */
541 unsigned int has_children
: 1;
542 unsigned int is_external
: 1;
543 unsigned int is_declaration
: 1;
544 unsigned int has_type
: 1;
545 unsigned int has_specification
: 1;
546 unsigned int has_pc_info
: 1;
547 unsigned int may_be_inlined
: 1;
549 /* Flag set if the SCOPE field of this structure has been
551 unsigned int scope_set
: 1;
553 /* Flag set if the DIE has a byte_size attribute. */
554 unsigned int has_byte_size
: 1;
556 /* Flag set if any of the DIE's children are template arguments. */
557 unsigned int has_template_arguments
: 1;
559 /* Flag set if fixup_partial_die has been called on this die. */
560 unsigned int fixup_called
: 1;
562 /* The name of this DIE. Normally the value of DW_AT_name, but
563 sometimes a default name for unnamed DIEs. */
566 /* The linkage name, if present. */
567 const char *linkage_name
;
569 /* The scope to prepend to our children. This is generally
570 allocated on the comp_unit_obstack, so will disappear
571 when this compilation unit leaves the cache. */
574 /* The location description associated with this DIE, if any. */
575 struct dwarf_block
*locdesc
;
577 /* If HAS_PC_INFO, the PC range associated with this DIE. */
581 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
582 DW_AT_sibling, if any. */
583 /* NOTE: This member isn't strictly necessary, read_partial_die could
584 return DW_AT_sibling values to its caller load_partial_dies. */
587 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
588 DW_AT_specification (or DW_AT_abstract_origin or
590 sect_offset spec_offset
;
592 /* Pointers to this DIE's parent, first child, and next sibling,
594 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
597 /* This data structure holds the information of an abbrev. */
600 unsigned int number
; /* number identifying abbrev */
601 enum dwarf_tag tag
; /* dwarf tag */
602 unsigned short has_children
; /* boolean */
603 unsigned short num_attrs
; /* number of attributes */
604 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
605 struct abbrev_info
*next
; /* next in chain */
610 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
611 ENUM_BITFIELD(dwarf_form
) form
: 16;
614 /* Attributes have a name and a value. */
617 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
618 ENUM_BITFIELD(dwarf_form
) form
: 15;
620 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
621 field should be in u.str (existing only for DW_STRING) but it is kept
622 here for better struct attribute alignment. */
623 unsigned int string_is_canonical
: 1;
628 struct dwarf_block
*blk
;
632 struct signatured_type
*signatured_type
;
637 /* This data structure holds a complete die structure. */
640 /* DWARF-2 tag for this DIE. */
641 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
643 /* Number of attributes */
644 unsigned char num_attrs
;
646 /* True if we're presently building the full type name for the
647 type derived from this DIE. */
648 unsigned char building_fullname
: 1;
653 /* Offset in .debug_info or .debug_types section. */
656 /* The dies in a compilation unit form an n-ary tree. PARENT
657 points to this die's parent; CHILD points to the first child of
658 this node; and all the children of a given node are chained
659 together via their SIBLING fields. */
660 struct die_info
*child
; /* Its first child, if any. */
661 struct die_info
*sibling
; /* Its next sibling, if any. */
662 struct die_info
*parent
; /* Its parent, if any. */
664 /* An array of attributes, with NUM_ATTRS elements. There may be
665 zero, but it's not common and zero-sized arrays are not
666 sufficiently portable C. */
667 struct attribute attrs
[1];
670 /* Get at parts of an attribute structure. */
672 #define DW_STRING(attr) ((attr)->u.str)
673 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
674 #define DW_UNSND(attr) ((attr)->u.unsnd)
675 #define DW_BLOCK(attr) ((attr)->u.blk)
676 #define DW_SND(attr) ((attr)->u.snd)
677 #define DW_ADDR(attr) ((attr)->u.addr)
678 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
680 /* Blocks are a bunch of untyped bytes. */
685 /* Valid only if SIZE is not zero. */
689 #ifndef ATTR_ALLOC_CHUNK
690 #define ATTR_ALLOC_CHUNK 4
693 /* Allocate fields for structs, unions and enums in this size. */
694 #ifndef DW_FIELD_ALLOC_CHUNK
695 #define DW_FIELD_ALLOC_CHUNK 4
698 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
699 but this would require a corresponding change in unpack_field_as_long
701 static int bits_per_byte
= 8;
703 /* The routines that read and process dies for a C struct or C++ class
704 pass lists of data member fields and lists of member function fields
705 in an instance of a field_info structure, as defined below. */
708 /* List of data member and baseclasses fields. */
711 struct nextfield
*next
;
716 *fields
, *baseclasses
;
718 /* Number of fields (including baseclasses). */
721 /* Number of baseclasses. */
724 /* Set if the accesibility of one of the fields is not public. */
725 int non_public_fields
;
727 /* Member function fields array, entries are allocated in the order they
728 are encountered in the object file. */
731 struct nextfnfield
*next
;
732 struct fn_field fnfield
;
736 /* Member function fieldlist array, contains name of possibly overloaded
737 member function, number of overloaded member functions and a pointer
738 to the head of the member function field chain. */
743 struct nextfnfield
*head
;
747 /* Number of entries in the fnfieldlists array. */
750 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
751 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
752 struct typedef_field_list
754 struct typedef_field field
;
755 struct typedef_field_list
*next
;
758 unsigned typedef_field_list_count
;
761 /* One item on the queue of compilation units to read in full symbols
763 struct dwarf2_queue_item
765 struct dwarf2_per_cu_data
*per_cu
;
766 struct dwarf2_queue_item
*next
;
769 /* The current queue. */
770 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
772 /* Loaded secondary compilation units are kept in memory until they
773 have not been referenced for the processing of this many
774 compilation units. Set this to zero to disable caching. Cache
775 sizes of up to at least twenty will improve startup time for
776 typical inter-CU-reference binaries, at an obvious memory cost. */
777 static int dwarf2_max_cache_age
= 5;
779 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
780 struct cmd_list_element
*c
, const char *value
)
782 fprintf_filtered (file
, _("The upper bound on the age of cached "
783 "dwarf2 compilation units is %s.\n"),
788 /* Various complaints about symbol reading that don't abort the process. */
791 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
793 complaint (&symfile_complaints
,
794 _("statement list doesn't fit in .debug_line section"));
798 dwarf2_debug_line_missing_file_complaint (void)
800 complaint (&symfile_complaints
,
801 _(".debug_line section has line data without a file"));
805 dwarf2_debug_line_missing_end_sequence_complaint (void)
807 complaint (&symfile_complaints
,
808 _(".debug_line section has line "
809 "program sequence without an end"));
813 dwarf2_complex_location_expr_complaint (void)
815 complaint (&symfile_complaints
, _("location expression too complex"));
819 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
822 complaint (&symfile_complaints
,
823 _("const value length mismatch for '%s', got %d, expected %d"),
828 dwarf2_macros_too_long_complaint (struct dwarf2_section_info
*section
)
830 complaint (&symfile_complaints
,
831 _("macro info runs off end of `%s' section"),
832 section
->asection
->name
);
836 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
838 complaint (&symfile_complaints
,
839 _("macro debug info contains a "
840 "malformed macro definition:\n`%s'"),
845 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
847 complaint (&symfile_complaints
,
848 _("invalid attribute class or form for '%s' in '%s'"),
852 /* local function prototypes */
854 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
856 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
859 static void dwarf2_find_base_address (struct die_info
*die
,
860 struct dwarf2_cu
*cu
);
862 static void dwarf2_build_psymtabs_hard (struct objfile
*);
864 static void scan_partial_symbols (struct partial_die_info
*,
865 CORE_ADDR
*, CORE_ADDR
*,
866 int, struct dwarf2_cu
*);
868 static void add_partial_symbol (struct partial_die_info
*,
871 static void add_partial_namespace (struct partial_die_info
*pdi
,
872 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
873 int need_pc
, struct dwarf2_cu
*cu
);
875 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
876 CORE_ADDR
*highpc
, int need_pc
,
877 struct dwarf2_cu
*cu
);
879 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
880 struct dwarf2_cu
*cu
);
882 static void add_partial_subprogram (struct partial_die_info
*pdi
,
883 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
884 int need_pc
, struct dwarf2_cu
*cu
);
886 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
887 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
888 bfd
*abfd
, struct dwarf2_cu
*cu
);
890 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
892 static void psymtab_to_symtab_1 (struct partial_symtab
*);
894 static void dwarf2_read_abbrevs (struct dwarf2_cu
*cu
);
896 static void dwarf2_free_abbrev_table (void *);
898 static unsigned int peek_abbrev_code (bfd
*, gdb_byte
*);
900 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
903 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
906 static struct partial_die_info
*load_partial_dies (bfd
*,
907 gdb_byte
*, gdb_byte
*,
908 int, struct dwarf2_cu
*);
910 static gdb_byte
*read_partial_die (struct partial_die_info
*,
911 struct abbrev_info
*abbrev
,
913 gdb_byte
*, gdb_byte
*,
916 static struct partial_die_info
*find_partial_die (sect_offset
,
919 static void fixup_partial_die (struct partial_die_info
*,
922 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
923 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
925 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
926 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
928 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
930 static int read_1_signed_byte (bfd
*, gdb_byte
*);
932 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
934 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
936 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
938 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
941 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
943 static LONGEST read_checked_initial_length_and_offset
944 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
945 unsigned int *, unsigned int *);
947 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
950 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
952 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
954 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
956 static char *read_indirect_string (bfd
*, gdb_byte
*,
957 const struct comp_unit_head
*,
960 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
962 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
964 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
966 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
968 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
971 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
975 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
976 struct dwarf2_cu
*cu
);
978 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
980 static struct die_info
*die_specification (struct die_info
*die
,
981 struct dwarf2_cu
**);
983 static void free_line_header (struct line_header
*lh
);
985 static void add_file_name (struct line_header
*, char *, unsigned int,
986 unsigned int, unsigned int);
988 static struct line_header
*(dwarf_decode_line_header
989 (unsigned int offset
,
990 bfd
*abfd
, struct dwarf2_cu
*cu
));
992 static void dwarf_decode_lines (struct line_header
*, const char *,
993 struct dwarf2_cu
*, struct partial_symtab
*,
996 static void dwarf2_start_subfile (char *, const char *, const char *);
998 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1001 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1002 struct dwarf2_cu
*, struct symbol
*);
1004 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1005 struct dwarf2_cu
*);
1007 static void dwarf2_const_value_attr (struct attribute
*attr
,
1010 struct obstack
*obstack
,
1011 struct dwarf2_cu
*cu
, long *value
,
1013 struct dwarf2_locexpr_baton
**baton
);
1015 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1017 static int need_gnat_info (struct dwarf2_cu
*);
1019 static struct type
*die_descriptive_type (struct die_info
*,
1020 struct dwarf2_cu
*);
1022 static void set_descriptive_type (struct type
*, struct die_info
*,
1023 struct dwarf2_cu
*);
1025 static struct type
*die_containing_type (struct die_info
*,
1026 struct dwarf2_cu
*);
1028 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1029 struct dwarf2_cu
*);
1031 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1033 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1035 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1037 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1038 const char *suffix
, int physname
,
1039 struct dwarf2_cu
*cu
);
1041 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1043 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1045 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1047 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1049 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1051 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1052 struct dwarf2_cu
*, struct partial_symtab
*);
1054 static int dwarf2_get_pc_bounds (struct die_info
*,
1055 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1056 struct partial_symtab
*);
1058 static void get_scope_pc_bounds (struct die_info
*,
1059 CORE_ADDR
*, CORE_ADDR
*,
1060 struct dwarf2_cu
*);
1062 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1063 CORE_ADDR
, struct dwarf2_cu
*);
1065 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1066 struct dwarf2_cu
*);
1068 static void dwarf2_attach_fields_to_type (struct field_info
*,
1069 struct type
*, struct dwarf2_cu
*);
1071 static void dwarf2_add_member_fn (struct field_info
*,
1072 struct die_info
*, struct type
*,
1073 struct dwarf2_cu
*);
1075 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1077 struct dwarf2_cu
*);
1079 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1081 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1083 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1085 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1087 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1089 static struct type
*read_module_type (struct die_info
*die
,
1090 struct dwarf2_cu
*cu
);
1092 static const char *namespace_name (struct die_info
*die
,
1093 int *is_anonymous
, struct dwarf2_cu
*);
1095 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1097 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1099 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1100 struct dwarf2_cu
*);
1102 static struct die_info
*read_comp_unit (gdb_byte
*, struct dwarf2_cu
*);
1104 static struct die_info
*read_die_and_children_1 (const struct die_reader_specs
*reader
,
1106 gdb_byte
**new_info_ptr
,
1107 struct die_info
*parent
);
1109 static struct die_info
*read_die_and_children (const struct die_reader_specs
*reader
,
1111 gdb_byte
**new_info_ptr
,
1112 struct die_info
*parent
);
1114 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*reader
,
1116 gdb_byte
**new_info_ptr
,
1117 struct die_info
*parent
);
1119 static gdb_byte
*read_full_die (const struct die_reader_specs
*reader
,
1120 struct die_info
**, gdb_byte
*,
1123 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1125 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1128 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1130 static const char *dwarf2_full_name (char *name
,
1131 struct die_info
*die
,
1132 struct dwarf2_cu
*cu
);
1134 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1135 struct dwarf2_cu
**);
1137 static char *dwarf_tag_name (unsigned int);
1139 static char *dwarf_attr_name (unsigned int);
1141 static char *dwarf_form_name (unsigned int);
1143 static char *dwarf_bool_name (unsigned int);
1145 static char *dwarf_type_encoding_name (unsigned int);
1148 static char *dwarf_cfi_name (unsigned int);
1151 static struct die_info
*sibling_die (struct die_info
*);
1153 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1155 static void dump_die_for_error (struct die_info
*);
1157 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1160 /*static*/ void dump_die (struct die_info
*, int max_level
);
1162 static void store_in_ref_table (struct die_info
*,
1163 struct dwarf2_cu
*);
1165 static int is_ref_attr (struct attribute
*);
1167 static sect_offset
dwarf2_get_ref_die_offset (struct attribute
*);
1169 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1171 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1173 struct dwarf2_cu
**);
1175 static struct die_info
*follow_die_ref (struct die_info
*,
1177 struct dwarf2_cu
**);
1179 static struct die_info
*follow_die_sig (struct die_info
*,
1181 struct dwarf2_cu
**);
1183 static struct signatured_type
*lookup_signatured_type_at_offset
1184 (struct objfile
*objfile
,
1185 struct dwarf2_section_info
*section
, sect_offset offset
);
1187 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1189 static void read_signatured_type (struct signatured_type
*);
1191 /* memory allocation interface */
1193 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1195 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1197 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1199 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1200 char *, bfd
*, struct dwarf2_cu
*,
1201 struct dwarf2_section_info
*,
1204 static int attr_form_is_block (struct attribute
*);
1206 static int attr_form_is_section_offset (struct attribute
*);
1208 static int attr_form_is_constant (struct attribute
*);
1210 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1211 struct dwarf2_loclist_baton
*baton
,
1212 struct attribute
*attr
);
1214 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1216 struct dwarf2_cu
*cu
);
1218 static gdb_byte
*skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1219 struct abbrev_info
*abbrev
,
1220 struct dwarf2_cu
*cu
);
1222 static void free_stack_comp_unit (void *);
1224 static hashval_t
partial_die_hash (const void *item
);
1226 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1228 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1229 (sect_offset offset
, struct objfile
*objfile
);
1231 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1232 struct dwarf2_per_cu_data
*per_cu
);
1234 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1235 struct die_info
*comp_unit_die
);
1237 static void free_heap_comp_unit (void *);
1239 static void free_cached_comp_units (void *);
1241 static void age_cached_comp_units (void);
1243 static void free_one_cached_comp_unit (void *);
1245 static struct type
*set_die_type (struct die_info
*, struct type
*,
1246 struct dwarf2_cu
*);
1248 static void create_all_comp_units (struct objfile
*);
1250 static int create_all_type_units (struct objfile
*);
1252 static void load_full_comp_unit (struct dwarf2_per_cu_data
*);
1254 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1256 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1257 struct dwarf2_per_cu_data
*);
1259 static void dwarf2_mark (struct dwarf2_cu
*);
1261 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1263 static struct type
*get_die_type_at_offset (sect_offset
,
1264 struct dwarf2_per_cu_data
*per_cu
);
1266 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1268 static void dwarf2_release_queue (void *dummy
);
1270 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
);
1272 static void process_queue (void);
1274 static void find_file_and_directory (struct die_info
*die
,
1275 struct dwarf2_cu
*cu
,
1276 char **name
, char **comp_dir
);
1278 static char *file_full_name (int file
, struct line_header
*lh
,
1279 const char *comp_dir
);
1281 static gdb_byte
*read_and_check_comp_unit_head
1282 (struct comp_unit_head
*header
,
1283 struct dwarf2_section_info
*section
, gdb_byte
*info_ptr
,
1284 int is_debug_types_section
);
1286 static void init_cu_die_reader (struct die_reader_specs
*reader
,
1287 struct dwarf2_cu
*cu
);
1289 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1293 /* Convert VALUE between big- and little-endian. */
1295 byte_swap (offset_type value
)
1299 result
= (value
& 0xff) << 24;
1300 result
|= (value
& 0xff00) << 8;
1301 result
|= (value
& 0xff0000) >> 8;
1302 result
|= (value
& 0xff000000) >> 24;
1306 #define MAYBE_SWAP(V) byte_swap (V)
1309 #define MAYBE_SWAP(V) (V)
1310 #endif /* WORDS_BIGENDIAN */
1312 /* The suffix for an index file. */
1313 #define INDEX_SUFFIX ".gdb-index"
1315 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1316 struct dwarf2_cu
*cu
);
1318 /* Try to locate the sections we need for DWARF 2 debugging
1319 information and return true if we have enough to do something.
1320 NAMES points to the dwarf2 section names, or is NULL if the standard
1321 ELF names are used. */
1324 dwarf2_has_info (struct objfile
*objfile
,
1325 const struct dwarf2_debug_sections
*names
)
1327 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1328 if (!dwarf2_per_objfile
)
1330 /* Initialize per-objfile state. */
1331 struct dwarf2_per_objfile
*data
1332 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1334 memset (data
, 0, sizeof (*data
));
1335 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1336 dwarf2_per_objfile
= data
;
1338 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1340 dwarf2_per_objfile
->objfile
= objfile
;
1342 return (dwarf2_per_objfile
->info
.asection
!= NULL
1343 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1346 /* When loading sections, we look either for uncompressed section or for
1347 compressed section names. */
1350 section_is_p (const char *section_name
,
1351 const struct dwarf2_section_names
*names
)
1353 if (names
->normal
!= NULL
1354 && strcmp (section_name
, names
->normal
) == 0)
1356 if (names
->compressed
!= NULL
1357 && strcmp (section_name
, names
->compressed
) == 0)
1362 /* This function is mapped across the sections and remembers the
1363 offset and size of each of the debugging sections we are interested
1367 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1369 const struct dwarf2_debug_sections
*names
;
1372 names
= &dwarf2_elf_names
;
1374 names
= (const struct dwarf2_debug_sections
*) vnames
;
1376 if (section_is_p (sectp
->name
, &names
->info
))
1378 dwarf2_per_objfile
->info
.asection
= sectp
;
1379 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1381 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1383 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1384 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1386 else if (section_is_p (sectp
->name
, &names
->line
))
1388 dwarf2_per_objfile
->line
.asection
= sectp
;
1389 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1391 else if (section_is_p (sectp
->name
, &names
->loc
))
1393 dwarf2_per_objfile
->loc
.asection
= sectp
;
1394 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1396 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1398 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1399 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1401 else if (section_is_p (sectp
->name
, &names
->macro
))
1403 dwarf2_per_objfile
->macro
.asection
= sectp
;
1404 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
1406 else if (section_is_p (sectp
->name
, &names
->str
))
1408 dwarf2_per_objfile
->str
.asection
= sectp
;
1409 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1411 else if (section_is_p (sectp
->name
, &names
->frame
))
1413 dwarf2_per_objfile
->frame
.asection
= sectp
;
1414 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1416 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1418 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1420 if (aflag
& SEC_HAS_CONTENTS
)
1422 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1423 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1426 else if (section_is_p (sectp
->name
, &names
->ranges
))
1428 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1429 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1431 else if (section_is_p (sectp
->name
, &names
->types
))
1433 struct dwarf2_section_info type_section
;
1435 memset (&type_section
, 0, sizeof (type_section
));
1436 type_section
.asection
= sectp
;
1437 type_section
.size
= bfd_get_section_size (sectp
);
1439 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
1442 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1444 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1445 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1448 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1449 && bfd_section_vma (abfd
, sectp
) == 0)
1450 dwarf2_per_objfile
->has_section_at_zero
= 1;
1453 /* Decompress a section that was compressed using zlib. Store the
1454 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1457 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1458 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1460 bfd
*abfd
= objfile
->obfd
;
1462 error (_("Support for zlib-compressed DWARF data (from '%s') "
1463 "is disabled in this copy of GDB"),
1464 bfd_get_filename (abfd
));
1466 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1467 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1468 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1469 bfd_size_type uncompressed_size
;
1470 gdb_byte
*uncompressed_buffer
;
1473 int header_size
= 12;
1475 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1476 || bfd_bread (compressed_buffer
,
1477 compressed_size
, abfd
) != compressed_size
)
1478 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1479 bfd_get_filename (abfd
));
1481 /* Read the zlib header. In this case, it should be "ZLIB" followed
1482 by the uncompressed section size, 8 bytes in big-endian order. */
1483 if (compressed_size
< header_size
1484 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1485 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1486 bfd_get_filename (abfd
));
1487 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1488 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1489 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1490 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1491 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1492 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1493 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1494 uncompressed_size
+= compressed_buffer
[11];
1496 /* It is possible the section consists of several compressed
1497 buffers concatenated together, so we uncompress in a loop. */
1501 strm
.avail_in
= compressed_size
- header_size
;
1502 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1503 strm
.avail_out
= uncompressed_size
;
1504 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1506 rc
= inflateInit (&strm
);
1507 while (strm
.avail_in
> 0)
1510 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1511 bfd_get_filename (abfd
), rc
);
1512 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1513 + (uncompressed_size
- strm
.avail_out
));
1514 rc
= inflate (&strm
, Z_FINISH
);
1515 if (rc
!= Z_STREAM_END
)
1516 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1517 bfd_get_filename (abfd
), rc
);
1518 rc
= inflateReset (&strm
);
1520 rc
= inflateEnd (&strm
);
1522 || strm
.avail_out
!= 0)
1523 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1524 bfd_get_filename (abfd
), rc
);
1526 do_cleanups (cleanup
);
1527 *outbuf
= uncompressed_buffer
;
1528 *outsize
= uncompressed_size
;
1532 /* A helper function that decides whether a section is empty. */
1535 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1537 return info
->asection
== NULL
|| info
->size
== 0;
1540 /* Read the contents of the section INFO from object file specified by
1541 OBJFILE, store info about the section into INFO.
1542 If the section is compressed, uncompress it before returning. */
1545 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1547 bfd
*abfd
= objfile
->obfd
;
1548 asection
*sectp
= info
->asection
;
1549 gdb_byte
*buf
, *retbuf
;
1550 unsigned char header
[4];
1554 info
->buffer
= NULL
;
1555 info
->map_addr
= NULL
;
1558 if (dwarf2_section_empty_p (info
))
1561 /* Check if the file has a 4-byte header indicating compression. */
1562 if (info
->size
> sizeof (header
)
1563 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1564 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1566 /* Upon decompression, update the buffer and its size. */
1567 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1569 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1577 pagesize
= getpagesize ();
1579 /* Only try to mmap sections which are large enough: we don't want to
1580 waste space due to fragmentation. Also, only try mmap for sections
1581 without relocations. */
1583 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1585 info
->buffer
= bfd_mmap (abfd
, 0, info
->size
, PROT_READ
,
1586 MAP_PRIVATE
, sectp
->filepos
,
1587 &info
->map_addr
, &info
->map_len
);
1589 if ((caddr_t
)info
->buffer
!= MAP_FAILED
)
1591 #if HAVE_POSIX_MADVISE
1592 posix_madvise (info
->map_addr
, info
->map_len
, POSIX_MADV_WILLNEED
);
1599 /* If we get here, we are a normal, not-compressed section. */
1601 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1603 /* When debugging .o files, we may need to apply relocations; see
1604 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1605 We never compress sections in .o files, so we only need to
1606 try this when the section is not compressed. */
1607 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1610 info
->buffer
= retbuf
;
1614 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1615 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1616 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1617 bfd_get_filename (abfd
));
1620 /* A helper function that returns the size of a section in a safe way.
1621 If you are positive that the section has been read before using the
1622 size, then it is safe to refer to the dwarf2_section_info object's
1623 "size" field directly. In other cases, you must call this
1624 function, because for compressed sections the size field is not set
1625 correctly until the section has been read. */
1627 static bfd_size_type
1628 dwarf2_section_size (struct objfile
*objfile
,
1629 struct dwarf2_section_info
*info
)
1632 dwarf2_read_section (objfile
, info
);
1636 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1640 dwarf2_get_section_info (struct objfile
*objfile
,
1641 enum dwarf2_section_enum sect
,
1642 asection
**sectp
, gdb_byte
**bufp
,
1643 bfd_size_type
*sizep
)
1645 struct dwarf2_per_objfile
*data
1646 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1647 struct dwarf2_section_info
*info
;
1649 /* We may see an objfile without any DWARF, in which case we just
1660 case DWARF2_DEBUG_FRAME
:
1661 info
= &data
->frame
;
1663 case DWARF2_EH_FRAME
:
1664 info
= &data
->eh_frame
;
1667 gdb_assert_not_reached ("unexpected section");
1670 dwarf2_read_section (objfile
, info
);
1672 *sectp
= info
->asection
;
1673 *bufp
= info
->buffer
;
1674 *sizep
= info
->size
;
1678 /* DWARF quick_symbols_functions support. */
1680 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1681 unique line tables, so we maintain a separate table of all .debug_line
1682 derived entries to support the sharing.
1683 All the quick functions need is the list of file names. We discard the
1684 line_header when we're done and don't need to record it here. */
1685 struct quick_file_names
1687 /* The offset in .debug_line of the line table. We hash on this. */
1688 unsigned int offset
;
1690 /* The number of entries in file_names, real_names. */
1691 unsigned int num_file_names
;
1693 /* The file names from the line table, after being run through
1695 const char **file_names
;
1697 /* The file names from the line table after being run through
1698 gdb_realpath. These are computed lazily. */
1699 const char **real_names
;
1702 /* When using the index (and thus not using psymtabs), each CU has an
1703 object of this type. This is used to hold information needed by
1704 the various "quick" methods. */
1705 struct dwarf2_per_cu_quick_data
1707 /* The file table. This can be NULL if there was no file table
1708 or it's currently not read in.
1709 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1710 struct quick_file_names
*file_names
;
1712 /* The corresponding symbol table. This is NULL if symbols for this
1713 CU have not yet been read. */
1714 struct symtab
*symtab
;
1716 /* A temporary mark bit used when iterating over all CUs in
1717 expand_symtabs_matching. */
1718 unsigned int mark
: 1;
1720 /* True if we've tried to read the file table and found there isn't one.
1721 There will be no point in trying to read it again next time. */
1722 unsigned int no_file_data
: 1;
1725 /* Hash function for a quick_file_names. */
1728 hash_file_name_entry (const void *e
)
1730 const struct quick_file_names
*file_data
= e
;
1732 return file_data
->offset
;
1735 /* Equality function for a quick_file_names. */
1738 eq_file_name_entry (const void *a
, const void *b
)
1740 const struct quick_file_names
*ea
= a
;
1741 const struct quick_file_names
*eb
= b
;
1743 return ea
->offset
== eb
->offset
;
1746 /* Delete function for a quick_file_names. */
1749 delete_file_name_entry (void *e
)
1751 struct quick_file_names
*file_data
= e
;
1754 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
1756 xfree ((void*) file_data
->file_names
[i
]);
1757 if (file_data
->real_names
)
1758 xfree ((void*) file_data
->real_names
[i
]);
1761 /* The space for the struct itself lives on objfile_obstack,
1762 so we don't free it here. */
1765 /* Create a quick_file_names hash table. */
1768 create_quick_file_names_table (unsigned int nr_initial_entries
)
1770 return htab_create_alloc (nr_initial_entries
,
1771 hash_file_name_entry
, eq_file_name_entry
,
1772 delete_file_name_entry
, xcalloc
, xfree
);
1775 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
1776 have to be created afterwards. You should call age_cached_comp_units after
1777 processing PER_CU->CU. dw2_setup must have been already called. */
1780 load_cu (struct dwarf2_per_cu_data
*per_cu
)
1782 if (per_cu
->debug_types_section
)
1783 load_full_type_unit (per_cu
);
1785 load_full_comp_unit (per_cu
);
1787 gdb_assert (per_cu
->cu
!= NULL
);
1789 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
1792 /* Read in the symbols for PER_CU. */
1795 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
1797 struct cleanup
*back_to
;
1799 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
1801 queue_comp_unit (per_cu
);
1807 /* Age the cache, releasing compilation units that have not
1808 been used recently. */
1809 age_cached_comp_units ();
1811 do_cleanups (back_to
);
1814 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1815 the objfile from which this CU came. Returns the resulting symbol
1818 static struct symtab
*
1819 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
1821 if (!per_cu
->v
.quick
->symtab
)
1823 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1824 increment_reading_symtab ();
1825 dw2_do_instantiate_symtab (per_cu
);
1826 do_cleanups (back_to
);
1828 return per_cu
->v
.quick
->symtab
;
1831 /* Return the CU given its index. */
1833 static struct dwarf2_per_cu_data
*
1834 dw2_get_cu (int index
)
1836 if (index
>= dwarf2_per_objfile
->n_comp_units
)
1838 index
-= dwarf2_per_objfile
->n_comp_units
;
1839 return dwarf2_per_objfile
->all_type_units
[index
];
1841 return dwarf2_per_objfile
->all_comp_units
[index
];
1844 /* A helper function that knows how to read a 64-bit value in a way
1845 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1849 extract_cu_value (const char *bytes
, ULONGEST
*result
)
1851 if (sizeof (ULONGEST
) < 8)
1855 /* Ignore the upper 4 bytes if they are all zero. */
1856 for (i
= 0; i
< 4; ++i
)
1857 if (bytes
[i
+ 4] != 0)
1860 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
1863 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
1867 /* Read the CU list from the mapped index, and use it to create all
1868 the CU objects for this objfile. Return 0 if something went wrong,
1869 1 if everything went ok. */
1872 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
1873 offset_type cu_list_elements
)
1877 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
1878 dwarf2_per_objfile
->all_comp_units
1879 = obstack_alloc (&objfile
->objfile_obstack
,
1880 dwarf2_per_objfile
->n_comp_units
1881 * sizeof (struct dwarf2_per_cu_data
*));
1883 for (i
= 0; i
< cu_list_elements
; i
+= 2)
1885 struct dwarf2_per_cu_data
*the_cu
;
1886 ULONGEST offset
, length
;
1888 if (!extract_cu_value (cu_list
, &offset
)
1889 || !extract_cu_value (cu_list
+ 8, &length
))
1893 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1894 struct dwarf2_per_cu_data
);
1895 the_cu
->offset
.sect_off
= offset
;
1896 the_cu
->length
= length
;
1897 the_cu
->objfile
= objfile
;
1898 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1899 struct dwarf2_per_cu_quick_data
);
1900 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
1906 /* Create the signatured type hash table from the index. */
1909 create_signatured_type_table_from_index (struct objfile
*objfile
,
1910 struct dwarf2_section_info
*section
,
1911 const gdb_byte
*bytes
,
1912 offset_type elements
)
1915 htab_t sig_types_hash
;
1917 dwarf2_per_objfile
->n_type_units
= elements
/ 3;
1918 dwarf2_per_objfile
->all_type_units
1919 = obstack_alloc (&objfile
->objfile_obstack
,
1920 dwarf2_per_objfile
->n_type_units
1921 * sizeof (struct dwarf2_per_cu_data
*));
1923 sig_types_hash
= allocate_signatured_type_table (objfile
);
1925 for (i
= 0; i
< elements
; i
+= 3)
1927 struct signatured_type
*sig_type
;
1928 ULONGEST offset
, type_offset_in_tu
, signature
;
1931 if (!extract_cu_value (bytes
, &offset
)
1932 || !extract_cu_value (bytes
+ 8, &type_offset_in_tu
))
1934 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
1937 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1938 struct signatured_type
);
1939 sig_type
->signature
= signature
;
1940 sig_type
->type_offset
.cu_off
= type_offset_in_tu
;
1941 sig_type
->per_cu
.debug_types_section
= section
;
1942 sig_type
->per_cu
.offset
.sect_off
= offset
;
1943 sig_type
->per_cu
.objfile
= objfile
;
1944 sig_type
->per_cu
.v
.quick
1945 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1946 struct dwarf2_per_cu_quick_data
);
1948 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
1951 dwarf2_per_objfile
->all_type_units
[i
/ 3] = &sig_type
->per_cu
;
1954 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
1959 /* Read the address map data from the mapped index, and use it to
1960 populate the objfile's psymtabs_addrmap. */
1963 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
1965 const gdb_byte
*iter
, *end
;
1966 struct obstack temp_obstack
;
1967 struct addrmap
*mutable_map
;
1968 struct cleanup
*cleanup
;
1971 obstack_init (&temp_obstack
);
1972 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
1973 mutable_map
= addrmap_create_mutable (&temp_obstack
);
1975 iter
= index
->address_table
;
1976 end
= iter
+ index
->address_table_size
;
1978 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1982 ULONGEST hi
, lo
, cu_index
;
1983 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1985 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1987 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
1990 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
1991 dw2_get_cu (cu_index
));
1994 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
1995 &objfile
->objfile_obstack
);
1996 do_cleanups (cleanup
);
1999 /* The hash function for strings in the mapped index. This is the same as
2000 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2001 implementation. This is necessary because the hash function is tied to the
2002 format of the mapped index file. The hash values do not have to match with
2005 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2008 mapped_index_string_hash (int index_version
, const void *p
)
2010 const unsigned char *str
= (const unsigned char *) p
;
2014 while ((c
= *str
++) != 0)
2016 if (index_version
>= 5)
2018 r
= r
* 67 + c
- 113;
2024 /* Find a slot in the mapped index INDEX for the object named NAME.
2025 If NAME is found, set *VEC_OUT to point to the CU vector in the
2026 constant pool and return 1. If NAME cannot be found, return 0. */
2029 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2030 offset_type
**vec_out
)
2032 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2034 offset_type slot
, step
;
2035 int (*cmp
) (const char *, const char *);
2037 if (current_language
->la_language
== language_cplus
2038 || current_language
->la_language
== language_java
2039 || current_language
->la_language
== language_fortran
)
2041 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2043 const char *paren
= strchr (name
, '(');
2049 dup
= xmalloc (paren
- name
+ 1);
2050 memcpy (dup
, name
, paren
- name
);
2051 dup
[paren
- name
] = 0;
2053 make_cleanup (xfree
, dup
);
2058 /* Index version 4 did not support case insensitive searches. But the
2059 indices for case insensitive languages are built in lowercase, therefore
2060 simulate our NAME being searched is also lowercased. */
2061 hash
= mapped_index_string_hash ((index
->version
== 4
2062 && case_sensitivity
== case_sensitive_off
2063 ? 5 : index
->version
),
2066 slot
= hash
& (index
->symbol_table_slots
- 1);
2067 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2068 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2072 /* Convert a slot number to an offset into the table. */
2073 offset_type i
= 2 * slot
;
2075 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2077 do_cleanups (back_to
);
2081 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2082 if (!cmp (name
, str
))
2084 *vec_out
= (offset_type
*) (index
->constant_pool
2085 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2086 do_cleanups (back_to
);
2090 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2094 /* Read the index file. If everything went ok, initialize the "quick"
2095 elements of all the CUs and return 1. Otherwise, return 0. */
2098 dwarf2_read_index (struct objfile
*objfile
)
2101 struct mapped_index
*map
;
2102 offset_type
*metadata
;
2103 const gdb_byte
*cu_list
;
2104 const gdb_byte
*types_list
= NULL
;
2105 offset_type version
, cu_list_elements
;
2106 offset_type types_list_elements
= 0;
2109 if (dwarf2_section_empty_p (&dwarf2_per_objfile
->gdb_index
))
2112 /* Older elfutils strip versions could keep the section in the main
2113 executable while splitting it for the separate debug info file. */
2114 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
2115 & SEC_HAS_CONTENTS
) == 0)
2118 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
2120 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
2121 /* Version check. */
2122 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2123 /* Versions earlier than 3 emitted every copy of a psymbol. This
2124 causes the index to behave very poorly for certain requests. Version 3
2125 contained incomplete addrmap. So, it seems better to just ignore such
2129 static int warning_printed
= 0;
2130 if (!warning_printed
)
2132 warning (_("Skipping obsolete .gdb_index section in %s."),
2134 warning_printed
= 1;
2138 /* Index version 4 uses a different hash function than index version
2141 Versions earlier than 6 did not emit psymbols for inlined
2142 functions. Using these files will cause GDB not to be able to
2143 set breakpoints on inlined functions by name, so we ignore these
2144 indices unless the --use-deprecated-index-sections command line
2145 option was supplied. */
2146 if (version
< 6 && !use_deprecated_index_sections
)
2148 static int warning_printed
= 0;
2149 if (!warning_printed
)
2151 warning (_("Skipping deprecated .gdb_index section in %s, pass "
2152 "--use-deprecated-index-sections to use them anyway"),
2154 warning_printed
= 1;
2158 /* Indexes with higher version than the one supported by GDB may be no
2159 longer backward compatible. */
2163 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
2164 map
->version
= version
;
2165 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
2167 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2170 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2171 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2175 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2176 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2177 - MAYBE_SWAP (metadata
[i
]))
2181 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2182 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2183 - MAYBE_SWAP (metadata
[i
]));
2186 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2187 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2188 - MAYBE_SWAP (metadata
[i
]))
2189 / (2 * sizeof (offset_type
)));
2192 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2194 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
2197 if (types_list_elements
)
2199 struct dwarf2_section_info
*section
;
2201 /* We can only handle a single .debug_types when we have an
2203 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2206 section
= VEC_index (dwarf2_section_info_def
,
2207 dwarf2_per_objfile
->types
, 0);
2209 if (!create_signatured_type_table_from_index (objfile
, section
,
2211 types_list_elements
))
2215 create_addrmap_from_index (objfile
, map
);
2217 dwarf2_per_objfile
->index_table
= map
;
2218 dwarf2_per_objfile
->using_index
= 1;
2219 dwarf2_per_objfile
->quick_file_names_table
=
2220 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2225 /* A helper for the "quick" functions which sets the global
2226 dwarf2_per_objfile according to OBJFILE. */
2229 dw2_setup (struct objfile
*objfile
)
2231 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2232 gdb_assert (dwarf2_per_objfile
);
2235 /* A helper for the "quick" functions which attempts to read the line
2236 table for THIS_CU. */
2238 static struct quick_file_names
*
2239 dw2_get_file_names (struct objfile
*objfile
,
2240 struct dwarf2_per_cu_data
*this_cu
)
2242 bfd
*abfd
= objfile
->obfd
;
2243 struct line_header
*lh
;
2244 struct attribute
*attr
;
2245 struct cleanup
*cleanups
;
2246 struct die_info
*comp_unit_die
;
2247 struct dwarf2_section_info
* sec
;
2249 int has_children
, i
;
2250 struct dwarf2_cu cu
;
2251 unsigned int bytes_read
;
2252 struct die_reader_specs reader_specs
;
2253 char *name
, *comp_dir
;
2255 struct quick_file_names
*qfn
;
2256 unsigned int line_offset
;
2258 if (this_cu
->v
.quick
->file_names
!= NULL
)
2259 return this_cu
->v
.quick
->file_names
;
2260 /* If we know there is no line data, no point in looking again. */
2261 if (this_cu
->v
.quick
->no_file_data
)
2264 init_one_comp_unit (&cu
, this_cu
);
2265 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
2267 if (this_cu
->debug_types_section
)
2268 sec
= this_cu
->debug_types_section
;
2270 sec
= &dwarf2_per_objfile
->info
;
2271 dwarf2_read_section (objfile
, sec
);
2272 info_ptr
= sec
->buffer
+ this_cu
->offset
.sect_off
;
2274 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, sec
, info_ptr
,
2275 this_cu
->debug_types_section
!= NULL
);
2277 /* Skip dummy compilation units. */
2278 if (info_ptr
>= (sec
->buffer
+ sec
->size
)
2279 || peek_abbrev_code (abfd
, info_ptr
) == 0)
2281 do_cleanups (cleanups
);
2285 dwarf2_read_abbrevs (&cu
);
2286 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2288 init_cu_die_reader (&reader_specs
, &cu
);
2289 read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2295 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, &cu
);
2298 struct quick_file_names find_entry
;
2300 line_offset
= DW_UNSND (attr
);
2302 /* We may have already read in this line header (TU line header sharing).
2303 If we have we're done. */
2304 find_entry
.offset
= line_offset
;
2305 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2306 &find_entry
, INSERT
);
2309 do_cleanups (cleanups
);
2310 this_cu
->v
.quick
->file_names
= *slot
;
2314 lh
= dwarf_decode_line_header (line_offset
, abfd
, &cu
);
2318 do_cleanups (cleanups
);
2319 this_cu
->v
.quick
->no_file_data
= 1;
2323 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2324 qfn
->offset
= line_offset
;
2325 gdb_assert (slot
!= NULL
);
2328 find_file_and_directory (comp_unit_die
, &cu
, &name
, &comp_dir
);
2330 qfn
->num_file_names
= lh
->num_file_names
;
2331 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2332 lh
->num_file_names
* sizeof (char *));
2333 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2334 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2335 qfn
->real_names
= NULL
;
2337 free_line_header (lh
);
2338 do_cleanups (cleanups
);
2340 this_cu
->v
.quick
->file_names
= qfn
;
2344 /* A helper for the "quick" functions which computes and caches the
2345 real path for a given file name from the line table. */
2348 dw2_get_real_path (struct objfile
*objfile
,
2349 struct quick_file_names
*qfn
, int index
)
2351 if (qfn
->real_names
== NULL
)
2352 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2353 qfn
->num_file_names
, sizeof (char *));
2355 if (qfn
->real_names
[index
] == NULL
)
2356 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2358 return qfn
->real_names
[index
];
2361 static struct symtab
*
2362 dw2_find_last_source_symtab (struct objfile
*objfile
)
2366 dw2_setup (objfile
);
2367 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2368 return dw2_instantiate_symtab (dw2_get_cu (index
));
2371 /* Traversal function for dw2_forget_cached_source_info. */
2374 dw2_free_cached_file_names (void **slot
, void *info
)
2376 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2378 if (file_data
->real_names
)
2382 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2384 xfree ((void*) file_data
->real_names
[i
]);
2385 file_data
->real_names
[i
] = NULL
;
2393 dw2_forget_cached_source_info (struct objfile
*objfile
)
2395 dw2_setup (objfile
);
2397 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2398 dw2_free_cached_file_names
, NULL
);
2401 /* Helper function for dw2_map_symtabs_matching_filename that expands
2402 the symtabs and calls the iterator. */
2405 dw2_map_expand_apply (struct objfile
*objfile
,
2406 struct dwarf2_per_cu_data
*per_cu
,
2408 const char *full_path
, const char *real_path
,
2409 int (*callback
) (struct symtab
*, void *),
2412 struct symtab
*last_made
= objfile
->symtabs
;
2414 /* Don't visit already-expanded CUs. */
2415 if (per_cu
->v
.quick
->symtab
)
2418 /* This may expand more than one symtab, and we want to iterate over
2420 dw2_instantiate_symtab (per_cu
);
2422 return iterate_over_some_symtabs (name
, full_path
, real_path
, callback
, data
,
2423 objfile
->symtabs
, last_made
);
2426 /* Implementation of the map_symtabs_matching_filename method. */
2429 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
2430 const char *full_path
, const char *real_path
,
2431 int (*callback
) (struct symtab
*, void *),
2435 const char *name_basename
= lbasename (name
);
2436 int name_len
= strlen (name
);
2437 int is_abs
= IS_ABSOLUTE_PATH (name
);
2439 dw2_setup (objfile
);
2441 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2442 + dwarf2_per_objfile
->n_type_units
); ++i
)
2445 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2446 struct quick_file_names
*file_data
;
2448 /* We only need to look at symtabs not already expanded. */
2449 if (per_cu
->v
.quick
->symtab
)
2452 file_data
= dw2_get_file_names (objfile
, per_cu
);
2453 if (file_data
== NULL
)
2456 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2458 const char *this_name
= file_data
->file_names
[j
];
2460 if (FILENAME_CMP (name
, this_name
) == 0
2461 || (!is_abs
&& compare_filenames_for_search (this_name
,
2464 if (dw2_map_expand_apply (objfile
, per_cu
,
2465 name
, full_path
, real_path
,
2470 /* Before we invoke realpath, which can get expensive when many
2471 files are involved, do a quick comparison of the basenames. */
2472 if (! basenames_may_differ
2473 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
2476 if (full_path
!= NULL
)
2478 const char *this_real_name
= dw2_get_real_path (objfile
,
2481 if (this_real_name
!= NULL
2482 && (FILENAME_CMP (full_path
, this_real_name
) == 0
2484 && compare_filenames_for_search (this_real_name
,
2487 if (dw2_map_expand_apply (objfile
, per_cu
,
2488 name
, full_path
, real_path
,
2494 if (real_path
!= NULL
)
2496 const char *this_real_name
= dw2_get_real_path (objfile
,
2499 if (this_real_name
!= NULL
2500 && (FILENAME_CMP (real_path
, this_real_name
) == 0
2502 && compare_filenames_for_search (this_real_name
,
2505 if (dw2_map_expand_apply (objfile
, per_cu
,
2506 name
, full_path
, real_path
,
2517 static struct symtab
*
2518 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2519 const char *name
, domain_enum domain
)
2521 /* We do all the work in the pre_expand_symtabs_matching hook
2526 /* A helper function that expands all symtabs that hold an object
2530 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2532 dw2_setup (objfile
);
2534 /* index_table is NULL if OBJF_READNOW. */
2535 if (dwarf2_per_objfile
->index_table
)
2539 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2542 offset_type i
, len
= MAYBE_SWAP (*vec
);
2543 for (i
= 0; i
< len
; ++i
)
2545 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2546 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2548 dw2_instantiate_symtab (per_cu
);
2555 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2556 enum block_enum block_kind
, const char *name
,
2559 dw2_do_expand_symtabs_matching (objfile
, name
);
2563 dw2_print_stats (struct objfile
*objfile
)
2567 dw2_setup (objfile
);
2569 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2570 + dwarf2_per_objfile
->n_type_units
); ++i
)
2572 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2574 if (!per_cu
->v
.quick
->symtab
)
2577 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2581 dw2_dump (struct objfile
*objfile
)
2583 /* Nothing worth printing. */
2587 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2588 struct section_offsets
*delta
)
2590 /* There's nothing to relocate here. */
2594 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2595 const char *func_name
)
2597 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2601 dw2_expand_all_symtabs (struct objfile
*objfile
)
2605 dw2_setup (objfile
);
2607 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2608 + dwarf2_per_objfile
->n_type_units
); ++i
)
2610 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2612 dw2_instantiate_symtab (per_cu
);
2617 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2618 const char *filename
)
2622 dw2_setup (objfile
);
2624 /* We don't need to consider type units here.
2625 This is only called for examining code, e.g. expand_line_sal.
2626 There can be an order of magnitude (or more) more type units
2627 than comp units, and we avoid them if we can. */
2629 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2632 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2633 struct quick_file_names
*file_data
;
2635 /* We only need to look at symtabs not already expanded. */
2636 if (per_cu
->v
.quick
->symtab
)
2639 file_data
= dw2_get_file_names (objfile
, per_cu
);
2640 if (file_data
== NULL
)
2643 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2645 const char *this_name
= file_data
->file_names
[j
];
2646 if (FILENAME_CMP (this_name
, filename
) == 0)
2648 dw2_instantiate_symtab (per_cu
);
2656 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2658 struct dwarf2_per_cu_data
*per_cu
;
2660 struct quick_file_names
*file_data
;
2662 dw2_setup (objfile
);
2664 /* index_table is NULL if OBJF_READNOW. */
2665 if (!dwarf2_per_objfile
->index_table
)
2669 ALL_OBJFILE_SYMTABS (objfile
, s
)
2672 struct blockvector
*bv
= BLOCKVECTOR (s
);
2673 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2674 struct symbol
*sym
= lookup_block_symbol (block
, name
, VAR_DOMAIN
);
2677 return sym
->symtab
->filename
;
2682 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2686 /* Note that this just looks at the very first one named NAME -- but
2687 actually we are looking for a function. find_main_filename
2688 should be rewritten so that it doesn't require a custom hook. It
2689 could just use the ordinary symbol tables. */
2690 /* vec[0] is the length, which must always be >0. */
2691 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[1]));
2693 file_data
= dw2_get_file_names (objfile
, per_cu
);
2694 if (file_data
== NULL
)
2697 return file_data
->file_names
[file_data
->num_file_names
- 1];
2701 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
2702 struct objfile
*objfile
, int global
,
2703 int (*callback
) (struct block
*,
2704 struct symbol
*, void *),
2705 void *data
, symbol_compare_ftype
*match
,
2706 symbol_compare_ftype
*ordered_compare
)
2708 /* Currently unimplemented; used for Ada. The function can be called if the
2709 current language is Ada for a non-Ada objfile using GNU index. As Ada
2710 does not look for non-Ada symbols this function should just return. */
2714 dw2_expand_symtabs_matching
2715 (struct objfile
*objfile
,
2716 int (*file_matcher
) (const char *, void *),
2717 int (*name_matcher
) (const char *, void *),
2718 enum search_domain kind
,
2723 struct mapped_index
*index
;
2725 dw2_setup (objfile
);
2727 /* index_table is NULL if OBJF_READNOW. */
2728 if (!dwarf2_per_objfile
->index_table
)
2730 index
= dwarf2_per_objfile
->index_table
;
2732 if (file_matcher
!= NULL
)
2734 struct cleanup
*cleanup
;
2735 htab_t visited_found
, visited_not_found
;
2737 visited_found
= htab_create_alloc (10,
2738 htab_hash_pointer
, htab_eq_pointer
,
2739 NULL
, xcalloc
, xfree
);
2740 cleanup
= make_cleanup_htab_delete (visited_found
);
2741 visited_not_found
= htab_create_alloc (10,
2742 htab_hash_pointer
, htab_eq_pointer
,
2743 NULL
, xcalloc
, xfree
);
2744 make_cleanup_htab_delete (visited_not_found
);
2746 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2747 + dwarf2_per_objfile
->n_type_units
); ++i
)
2750 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2751 struct quick_file_names
*file_data
;
2754 per_cu
->v
.quick
->mark
= 0;
2756 /* We only need to look at symtabs not already expanded. */
2757 if (per_cu
->v
.quick
->symtab
)
2760 file_data
= dw2_get_file_names (objfile
, per_cu
);
2761 if (file_data
== NULL
)
2764 if (htab_find (visited_not_found
, file_data
) != NULL
)
2766 else if (htab_find (visited_found
, file_data
) != NULL
)
2768 per_cu
->v
.quick
->mark
= 1;
2772 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2774 if (file_matcher (file_data
->file_names
[j
], data
))
2776 per_cu
->v
.quick
->mark
= 1;
2781 slot
= htab_find_slot (per_cu
->v
.quick
->mark
2783 : visited_not_found
,
2788 do_cleanups (cleanup
);
2791 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2793 offset_type idx
= 2 * iter
;
2795 offset_type
*vec
, vec_len
, vec_idx
;
2797 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2800 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
2802 if (! (*name_matcher
) (name
, data
))
2805 /* The name was matched, now expand corresponding CUs that were
2807 vec
= (offset_type
*) (index
->constant_pool
2808 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
2809 vec_len
= MAYBE_SWAP (vec
[0]);
2810 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2812 struct dwarf2_per_cu_data
*per_cu
;
2814 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[vec_idx
+ 1]));
2815 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
2816 dw2_instantiate_symtab (per_cu
);
2821 static struct symtab
*
2822 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
2823 struct minimal_symbol
*msymbol
,
2825 struct obj_section
*section
,
2828 struct dwarf2_per_cu_data
*data
;
2830 dw2_setup (objfile
);
2832 if (!objfile
->psymtabs_addrmap
)
2835 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
2839 if (warn_if_readin
&& data
->v
.quick
->symtab
)
2840 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2841 paddress (get_objfile_arch (objfile
), pc
));
2843 return dw2_instantiate_symtab (data
);
2847 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
2848 void *data
, int need_fullname
)
2851 struct cleanup
*cleanup
;
2852 htab_t visited
= htab_create_alloc (10, htab_hash_pointer
, htab_eq_pointer
,
2853 NULL
, xcalloc
, xfree
);
2855 cleanup
= make_cleanup_htab_delete (visited
);
2856 dw2_setup (objfile
);
2858 /* We can ignore file names coming from already-expanded CUs. */
2859 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2860 + dwarf2_per_objfile
->n_type_units
); ++i
)
2862 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2864 if (per_cu
->v
.quick
->symtab
)
2866 void **slot
= htab_find_slot (visited
, per_cu
->v
.quick
->file_names
,
2869 *slot
= per_cu
->v
.quick
->file_names
;
2873 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2874 + dwarf2_per_objfile
->n_type_units
); ++i
)
2877 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2878 struct quick_file_names
*file_data
;
2881 /* We only need to look at symtabs not already expanded. */
2882 if (per_cu
->v
.quick
->symtab
)
2885 file_data
= dw2_get_file_names (objfile
, per_cu
);
2886 if (file_data
== NULL
)
2889 slot
= htab_find_slot (visited
, file_data
, INSERT
);
2892 /* Already visited. */
2897 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2899 const char *this_real_name
;
2902 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
2904 this_real_name
= NULL
;
2905 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
2909 do_cleanups (cleanup
);
2913 dw2_has_symbols (struct objfile
*objfile
)
2918 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
2921 dw2_find_last_source_symtab
,
2922 dw2_forget_cached_source_info
,
2923 dw2_map_symtabs_matching_filename
,
2925 dw2_pre_expand_symtabs_matching
,
2929 dw2_expand_symtabs_for_function
,
2930 dw2_expand_all_symtabs
,
2931 dw2_expand_symtabs_with_filename
,
2932 dw2_find_symbol_file
,
2933 dw2_map_matching_symbols
,
2934 dw2_expand_symtabs_matching
,
2935 dw2_find_pc_sect_symtab
,
2936 dw2_map_symbol_filenames
2939 /* Initialize for reading DWARF for this objfile. Return 0 if this
2940 file will use psymtabs, or 1 if using the GNU index. */
2943 dwarf2_initialize_objfile (struct objfile
*objfile
)
2945 /* If we're about to read full symbols, don't bother with the
2946 indices. In this case we also don't care if some other debug
2947 format is making psymtabs, because they are all about to be
2949 if ((objfile
->flags
& OBJF_READNOW
))
2953 dwarf2_per_objfile
->using_index
= 1;
2954 create_all_comp_units (objfile
);
2955 create_all_type_units (objfile
);
2956 dwarf2_per_objfile
->quick_file_names_table
=
2957 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2959 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2960 + dwarf2_per_objfile
->n_type_units
); ++i
)
2962 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2964 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2965 struct dwarf2_per_cu_quick_data
);
2968 /* Return 1 so that gdb sees the "quick" functions. However,
2969 these functions will be no-ops because we will have expanded
2974 if (dwarf2_read_index (objfile
))
2982 /* Build a partial symbol table. */
2985 dwarf2_build_psymtabs (struct objfile
*objfile
)
2987 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2989 init_psymbol_list (objfile
, 1024);
2992 dwarf2_build_psymtabs_hard (objfile
);
2995 /* Return TRUE if OFFSET is within CU_HEADER. */
2998 offset_in_cu_p (const struct comp_unit_head
*cu_header
, sect_offset offset
)
3000 sect_offset bottom
= { cu_header
->offset
.sect_off
};
3001 sect_offset top
= { (cu_header
->offset
.sect_off
+ cu_header
->length
3002 + cu_header
->initial_length_size
) };
3004 return (offset
.sect_off
>= bottom
.sect_off
&& offset
.sect_off
< top
.sect_off
);
3007 /* Read in the comp unit header information from the debug_info at info_ptr.
3008 NOTE: This leaves members offset, first_die_offset to be filled in
3012 read_comp_unit_head (struct comp_unit_head
*cu_header
,
3013 gdb_byte
*info_ptr
, bfd
*abfd
)
3016 unsigned int bytes_read
;
3018 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
3019 cu_header
->initial_length_size
= bytes_read
;
3020 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
3021 info_ptr
+= bytes_read
;
3022 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
3024 cu_header
->abbrev_offset
.sect_off
= read_offset (abfd
, info_ptr
, cu_header
,
3026 info_ptr
+= bytes_read
;
3027 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
3029 signed_addr
= bfd_get_sign_extend_vma (abfd
);
3030 if (signed_addr
< 0)
3031 internal_error (__FILE__
, __LINE__
,
3032 _("read_comp_unit_head: dwarf from non elf file"));
3033 cu_header
->signed_addr_p
= signed_addr
;
3038 /* Subroutine of read_and_check_comp_unit_head and
3039 read_and_check_type_unit_head to simplify them.
3040 Perform various error checking on the header. */
3043 error_check_comp_unit_head (struct comp_unit_head
*header
,
3044 struct dwarf2_section_info
*section
)
3046 bfd
*abfd
= section
->asection
->owner
;
3047 const char *filename
= bfd_get_filename (abfd
);
3049 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
3050 error (_("Dwarf Error: wrong version in compilation unit header "
3051 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
3054 if (header
->abbrev_offset
.sect_off
3055 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
3056 &dwarf2_per_objfile
->abbrev
))
3057 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3058 "(offset 0x%lx + 6) [in module %s]"),
3059 (long) header
->abbrev_offset
.sect_off
, (long) header
->offset
.sect_off
,
3062 /* Cast to unsigned long to use 64-bit arithmetic when possible to
3063 avoid potential 32-bit overflow. */
3064 if (((unsigned long) header
->offset
.sect_off
3065 + header
->length
+ header
->initial_length_size
)
3067 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3068 "(offset 0x%lx + 0) [in module %s]"),
3069 (long) header
->length
, (long) header
->offset
.sect_off
,
3073 /* Read in a CU/TU header and perform some basic error checking.
3074 The contents of the header are stored in HEADER.
3075 The result is a pointer to the start of the first DIE. */
3078 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
3079 struct dwarf2_section_info
*section
,
3081 int is_debug_types_section
)
3083 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3084 bfd
*abfd
= section
->asection
->owner
;
3086 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3088 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3090 /* If we're reading a type unit, skip over the signature and
3091 type_offset fields. */
3092 if (is_debug_types_section
)
3093 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
3095 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3097 error_check_comp_unit_head (header
, section
);
3102 /* Read in the types comp unit header information from .debug_types entry at
3103 types_ptr. The result is a pointer to one past the end of the header. */
3106 read_and_check_type_unit_head (struct comp_unit_head
*header
,
3107 struct dwarf2_section_info
*section
,
3109 ULONGEST
*signature
, cu_offset
*type_offset
)
3111 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3112 bfd
*abfd
= section
->asection
->owner
;
3114 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3116 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3118 /* If we're reading a type unit, skip over the signature and
3119 type_offset fields. */
3120 if (signature
!= NULL
)
3121 *signature
= read_8_bytes (abfd
, info_ptr
);
3123 if (type_offset
!= NULL
)
3124 type_offset
->cu_off
= read_offset_1 (abfd
, info_ptr
, header
->offset_size
);
3125 info_ptr
+= header
->offset_size
;
3127 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3129 error_check_comp_unit_head (header
, section
);
3134 /* Allocate a new partial symtab for file named NAME and mark this new
3135 partial symtab as being an include of PST. */
3138 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
3139 struct objfile
*objfile
)
3141 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
3143 subpst
->section_offsets
= pst
->section_offsets
;
3144 subpst
->textlow
= 0;
3145 subpst
->texthigh
= 0;
3147 subpst
->dependencies
= (struct partial_symtab
**)
3148 obstack_alloc (&objfile
->objfile_obstack
,
3149 sizeof (struct partial_symtab
*));
3150 subpst
->dependencies
[0] = pst
;
3151 subpst
->number_of_dependencies
= 1;
3153 subpst
->globals_offset
= 0;
3154 subpst
->n_global_syms
= 0;
3155 subpst
->statics_offset
= 0;
3156 subpst
->n_static_syms
= 0;
3157 subpst
->symtab
= NULL
;
3158 subpst
->read_symtab
= pst
->read_symtab
;
3161 /* No private part is necessary for include psymtabs. This property
3162 can be used to differentiate between such include psymtabs and
3163 the regular ones. */
3164 subpst
->read_symtab_private
= NULL
;
3167 /* Read the Line Number Program data and extract the list of files
3168 included by the source file represented by PST. Build an include
3169 partial symtab for each of these included files. */
3172 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
3173 struct die_info
*die
,
3174 struct partial_symtab
*pst
)
3176 struct objfile
*objfile
= cu
->objfile
;
3177 bfd
*abfd
= objfile
->obfd
;
3178 struct line_header
*lh
= NULL
;
3179 struct attribute
*attr
;
3181 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3184 unsigned int line_offset
= DW_UNSND (attr
);
3186 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
3189 return; /* No linetable, so no includes. */
3191 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3192 dwarf_decode_lines (lh
, pst
->dirname
, cu
, pst
, 1);
3194 free_line_header (lh
);
3198 hash_signatured_type (const void *item
)
3200 const struct signatured_type
*sig_type
= item
;
3202 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3203 return sig_type
->signature
;
3207 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
3209 const struct signatured_type
*lhs
= item_lhs
;
3210 const struct signatured_type
*rhs
= item_rhs
;
3212 return lhs
->signature
== rhs
->signature
;
3215 /* Allocate a hash table for signatured types. */
3218 allocate_signatured_type_table (struct objfile
*objfile
)
3220 return htab_create_alloc_ex (41,
3221 hash_signatured_type
,
3224 &objfile
->objfile_obstack
,
3225 hashtab_obstack_allocate
,
3226 dummy_obstack_deallocate
);
3229 /* A helper function to add a signatured type CU to a table. */
3232 add_signatured_type_cu_to_table (void **slot
, void *datum
)
3234 struct signatured_type
*sigt
= *slot
;
3235 struct dwarf2_per_cu_data
***datap
= datum
;
3237 **datap
= &sigt
->per_cu
;
3243 /* Create the hash table of all entries in the .debug_types section(s).
3244 The result is zero if there are no .debug_types sections,
3245 otherwise non-zero. */
3248 create_all_type_units (struct objfile
*objfile
)
3250 htab_t types_htab
= NULL
;
3251 struct dwarf2_per_cu_data
**iter
;
3253 struct dwarf2_section_info
*section
;
3255 if (VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
))
3257 dwarf2_per_objfile
->signatured_types
= NULL
;
3262 VEC_iterate (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
3266 gdb_byte
*info_ptr
, *end_ptr
;
3268 dwarf2_read_section (objfile
, section
);
3269 info_ptr
= section
->buffer
;
3271 if (info_ptr
== NULL
)
3274 if (types_htab
== NULL
)
3275 types_htab
= allocate_signatured_type_table (objfile
);
3277 if (dwarf2_die_debug
)
3278 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
3280 end_ptr
= info_ptr
+ section
->size
;
3281 while (info_ptr
< end_ptr
)
3284 cu_offset type_offset
;
3286 struct signatured_type
*sig_type
;
3288 gdb_byte
*ptr
= info_ptr
;
3289 struct comp_unit_head header
;
3291 offset
.sect_off
= ptr
- section
->buffer
;
3293 /* We need to read the type's signature in order to build the hash
3294 table, but we don't need anything else just yet. */
3296 ptr
= read_and_check_type_unit_head (&header
, section
, ptr
,
3297 &signature
, &type_offset
);
3299 /* Skip dummy type units. */
3300 if (ptr
>= end_ptr
|| peek_abbrev_code (objfile
->obfd
, ptr
) == 0)
3302 info_ptr
= info_ptr
+ header
.initial_length_size
+ header
.length
;
3306 sig_type
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*sig_type
));
3307 memset (sig_type
, 0, sizeof (*sig_type
));
3308 sig_type
->signature
= signature
;
3309 sig_type
->type_offset
= type_offset
;
3310 sig_type
->per_cu
.objfile
= objfile
;
3311 sig_type
->per_cu
.debug_types_section
= section
;
3312 sig_type
->per_cu
.offset
= offset
;
3314 slot
= htab_find_slot (types_htab
, sig_type
, INSERT
);
3315 gdb_assert (slot
!= NULL
);
3318 const struct signatured_type
*dup_sig
= *slot
;
3320 complaint (&symfile_complaints
,
3321 _("debug type entry at offset 0x%x is duplicate to the "
3322 "entry at offset 0x%x, signature 0x%s"),
3323 offset
.sect_off
, dup_sig
->per_cu
.offset
.sect_off
,
3324 phex (signature
, sizeof (signature
)));
3325 gdb_assert (signature
== dup_sig
->signature
);
3329 if (dwarf2_die_debug
)
3330 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3332 phex (signature
, sizeof (signature
)));
3334 info_ptr
= info_ptr
+ header
.initial_length_size
+ header
.length
;
3338 dwarf2_per_objfile
->signatured_types
= types_htab
;
3340 dwarf2_per_objfile
->n_type_units
= htab_elements (types_htab
);
3341 dwarf2_per_objfile
->all_type_units
3342 = obstack_alloc (&objfile
->objfile_obstack
,
3343 dwarf2_per_objfile
->n_type_units
3344 * sizeof (struct dwarf2_per_cu_data
*));
3345 iter
= &dwarf2_per_objfile
->all_type_units
[0];
3346 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
3347 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
3348 == dwarf2_per_objfile
->n_type_units
);
3353 /* Lookup a signature based type.
3354 Returns NULL if signature SIG is not present in the table. */
3356 static struct signatured_type
*
3357 lookup_signatured_type (ULONGEST sig
)
3359 struct signatured_type find_entry
, *entry
;
3361 if (dwarf2_per_objfile
->signatured_types
== NULL
)
3363 complaint (&symfile_complaints
,
3364 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3368 find_entry
.signature
= sig
;
3369 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
3373 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3376 init_cu_die_reader (struct die_reader_specs
*reader
,
3377 struct dwarf2_cu
*cu
)
3379 reader
->abfd
= cu
->objfile
->obfd
;
3381 if (cu
->per_cu
->debug_types_section
)
3383 gdb_assert (cu
->per_cu
->debug_types_section
->readin
);
3384 reader
->buffer
= cu
->per_cu
->debug_types_section
->buffer
;
3388 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3389 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
3393 /* Find the base address of the compilation unit for range lists and
3394 location lists. It will normally be specified by DW_AT_low_pc.
3395 In DWARF-3 draft 4, the base address could be overridden by
3396 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3397 compilation units with discontinuous ranges. */
3400 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3402 struct attribute
*attr
;
3405 cu
->base_address
= 0;
3407 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3410 cu
->base_address
= DW_ADDR (attr
);
3415 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3418 cu
->base_address
= DW_ADDR (attr
);
3424 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
3425 to combine the common parts.
3426 Process compilation unit THIS_CU for a psymtab.
3427 SECTION is the section the CU/TU comes from,
3428 either .debug_info or .debug_types. */
3431 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
3432 struct dwarf2_section_info
*section
,
3433 int is_debug_types_section
)
3435 struct objfile
*objfile
= this_cu
->objfile
;
3436 bfd
*abfd
= objfile
->obfd
;
3437 gdb_byte
*buffer
= section
->buffer
;
3438 gdb_byte
*info_ptr
= buffer
+ this_cu
->offset
.sect_off
;
3439 unsigned int buffer_size
= section
->size
;
3440 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3441 struct die_info
*comp_unit_die
;
3442 struct partial_symtab
*pst
;
3444 struct cleanup
*back_to_inner
;
3445 struct dwarf2_cu cu
;
3446 int has_children
, has_pc_info
;
3447 struct attribute
*attr
;
3448 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
3449 struct die_reader_specs reader_specs
;
3450 const char *filename
;
3452 /* If this compilation unit was already read in, free the
3453 cached copy in order to read it in again. This is
3454 necessary because we skipped some symbols when we first
3455 read in the compilation unit (see load_partial_dies).
3456 This problem could be avoided, but the benefit is
3458 if (this_cu
->cu
!= NULL
)
3459 free_one_cached_comp_unit (this_cu
->cu
);
3461 /* Note that this is a pointer to our stack frame, being
3462 added to a global data structure. It will be cleaned up
3463 in free_stack_comp_unit when we finish with this
3464 compilation unit. */
3465 init_one_comp_unit (&cu
, this_cu
);
3466 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
3468 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
, info_ptr
,
3469 is_debug_types_section
);
3471 /* Skip dummy compilation units. */
3472 if (info_ptr
>= buffer
+ buffer_size
3473 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3475 do_cleanups (back_to_inner
);
3479 cu
.list_in_scope
= &file_symbols
;
3481 /* Read the abbrevs for this compilation unit into a table. */
3482 dwarf2_read_abbrevs (&cu
);
3483 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
3485 /* Read the compilation unit die. */
3486 init_cu_die_reader (&reader_specs
, &cu
);
3487 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3490 if (is_debug_types_section
)
3492 /* LENGTH has not been set yet for type units. */
3493 gdb_assert (this_cu
->offset
.sect_off
== cu
.header
.offset
.sect_off
);
3494 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
3496 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3498 do_cleanups (back_to_inner
);
3502 prepare_one_comp_unit (&cu
, comp_unit_die
);
3504 /* Allocate a new partial symbol table structure. */
3505 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
3506 if (attr
== NULL
|| !DW_STRING (attr
))
3509 filename
= DW_STRING (attr
);
3510 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
3512 /* TEXTLOW and TEXTHIGH are set below. */
3514 objfile
->global_psymbols
.next
,
3515 objfile
->static_psymbols
.next
);
3516 pst
->psymtabs_addrmap_supported
= 1;
3518 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
3520 pst
->dirname
= DW_STRING (attr
);
3522 pst
->read_symtab_private
= this_cu
;
3524 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3526 /* Store the function that reads in the rest of the symbol table. */
3527 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
3529 this_cu
->v
.psymtab
= pst
;
3531 dwarf2_find_base_address (comp_unit_die
, &cu
);
3533 /* Possibly set the default values of LOWPC and HIGHPC from
3535 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
3536 &best_highpc
, &cu
, pst
);
3537 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
3538 /* Store the contiguous range if it is not empty; it can be empty for
3539 CUs with no code. */
3540 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3541 best_lowpc
+ baseaddr
,
3542 best_highpc
+ baseaddr
- 1, pst
);
3544 /* Check if comp unit has_children.
3545 If so, read the rest of the partial symbols from this comp unit.
3546 If not, there's no more debug_info for this comp unit. */
3549 struct partial_die_info
*first_die
;
3550 CORE_ADDR lowpc
, highpc
;
3552 lowpc
= ((CORE_ADDR
) -1);
3553 highpc
= ((CORE_ADDR
) 0);
3555 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
3557 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
3558 ! has_pc_info
, &cu
);
3560 /* If we didn't find a lowpc, set it to highpc to avoid
3561 complaints from `maint check'. */
3562 if (lowpc
== ((CORE_ADDR
) -1))
3565 /* If the compilation unit didn't have an explicit address range,
3566 then use the information extracted from its child dies. */
3570 best_highpc
= highpc
;
3573 pst
->textlow
= best_lowpc
+ baseaddr
;
3574 pst
->texthigh
= best_highpc
+ baseaddr
;
3576 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
3577 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
3578 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
3579 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
3580 sort_pst_symbols (pst
);
3582 if (is_debug_types_section
)
3584 /* It's not clear we want to do anything with stmt lists here.
3585 Waiting to see what gcc ultimately does. */
3589 /* Get the list of files included in the current compilation unit,
3590 and build a psymtab for each of them. */
3591 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
3594 do_cleanups (back_to_inner
);
3597 /* Traversal function for htab_traverse_noresize.
3598 Process one .debug_types comp-unit. */
3601 process_type_comp_unit (void **slot
, void *info
)
3603 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
3604 struct dwarf2_per_cu_data
*this_cu
;
3606 gdb_assert (info
== NULL
);
3607 this_cu
= &entry
->per_cu
;
3609 gdb_assert (this_cu
->debug_types_section
->readin
);
3610 process_psymtab_comp_unit (this_cu
, this_cu
->debug_types_section
, 1);
3615 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3616 Build partial symbol tables for the .debug_types comp-units. */
3619 build_type_psymtabs (struct objfile
*objfile
)
3621 if (! create_all_type_units (objfile
))
3624 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
3625 process_type_comp_unit
, NULL
);
3628 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3631 psymtabs_addrmap_cleanup (void *o
)
3633 struct objfile
*objfile
= o
;
3635 objfile
->psymtabs_addrmap
= NULL
;
3638 /* Build the partial symbol table by doing a quick pass through the
3639 .debug_info and .debug_abbrev sections. */
3642 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
3644 struct cleanup
*back_to
, *addrmap_cleanup
;
3645 struct obstack temp_obstack
;
3648 dwarf2_per_objfile
->reading_partial_symbols
= 1;
3650 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3652 /* Any cached compilation units will be linked by the per-objfile
3653 read_in_chain. Make sure to free them when we're done. */
3654 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
3656 build_type_psymtabs (objfile
);
3658 create_all_comp_units (objfile
);
3660 /* Create a temporary address map on a temporary obstack. We later
3661 copy this to the final obstack. */
3662 obstack_init (&temp_obstack
);
3663 make_cleanup_obstack_free (&temp_obstack
);
3664 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
3665 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
3667 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3669 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3671 process_psymtab_comp_unit (per_cu
, &dwarf2_per_objfile
->info
, 0);
3674 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
3675 &objfile
->objfile_obstack
);
3676 discard_cleanups (addrmap_cleanup
);
3678 do_cleanups (back_to
);
3681 /* Load the partial DIEs for a secondary CU into memory. */
3684 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
3686 struct objfile
*objfile
= this_cu
->objfile
;
3687 bfd
*abfd
= objfile
->obfd
;
3689 struct die_info
*comp_unit_die
;
3690 struct dwarf2_cu
*cu
;
3691 struct cleanup
*free_abbrevs_cleanup
, *free_cu_cleanup
= NULL
;
3693 struct die_reader_specs reader_specs
;
3695 struct dwarf2_section_info
*section
= &dwarf2_per_objfile
->info
;
3697 gdb_assert (! this_cu
->debug_types_section
);
3699 gdb_assert (section
->readin
);
3700 info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
3702 if (this_cu
->cu
== NULL
)
3704 cu
= xmalloc (sizeof (*cu
));
3705 init_one_comp_unit (cu
, this_cu
);
3709 /* If an error occurs while loading, release our storage. */
3710 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
3712 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
, info_ptr
,
3715 /* Skip dummy compilation units. */
3716 if (info_ptr
>= (section
->buffer
+ section
->size
)
3717 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3719 do_cleanups (free_cu_cleanup
);
3726 info_ptr
+= cu
->header
.first_die_offset
.cu_off
;
3729 /* Read the abbrevs for this compilation unit into a table. */
3730 gdb_assert (cu
->dwarf2_abbrevs
== NULL
);
3731 dwarf2_read_abbrevs (cu
);
3732 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3734 /* Read the compilation unit die. */
3735 init_cu_die_reader (&reader_specs
, cu
);
3736 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3739 prepare_one_comp_unit (cu
, comp_unit_die
);
3741 /* Check if comp unit has_children.
3742 If so, read the rest of the partial symbols from this comp unit.
3743 If not, there's no more debug_info for this comp unit. */
3745 load_partial_dies (abfd
, section
->buffer
, info_ptr
, 0, cu
);
3747 do_cleanups (free_abbrevs_cleanup
);
3751 /* We've successfully allocated this compilation unit. Let our
3752 caller clean it up when finished with it. */
3753 discard_cleanups (free_cu_cleanup
);
3755 /* Link this CU into read_in_chain. */
3756 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3757 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3761 /* Create a list of all compilation units in OBJFILE.
3762 This is only done for -readnow and building partial symtabs. */
3765 create_all_comp_units (struct objfile
*objfile
)
3769 struct dwarf2_per_cu_data
**all_comp_units
;
3772 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3773 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3777 all_comp_units
= xmalloc (n_allocated
3778 * sizeof (struct dwarf2_per_cu_data
*));
3780 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
3781 + dwarf2_per_objfile
->info
.size
)
3783 unsigned int length
, initial_length_size
;
3784 struct dwarf2_per_cu_data
*this_cu
;
3787 offset
.sect_off
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
3789 /* Read just enough information to find out where the next
3790 compilation unit is. */
3791 length
= read_initial_length (objfile
->obfd
, info_ptr
,
3792 &initial_length_size
);
3794 /* Save the compilation unit for later lookup. */
3795 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
3796 sizeof (struct dwarf2_per_cu_data
));
3797 memset (this_cu
, 0, sizeof (*this_cu
));
3798 this_cu
->offset
= offset
;
3799 this_cu
->length
= length
+ initial_length_size
;
3800 this_cu
->objfile
= objfile
;
3802 if (n_comp_units
== n_allocated
)
3805 all_comp_units
= xrealloc (all_comp_units
,
3807 * sizeof (struct dwarf2_per_cu_data
*));
3809 all_comp_units
[n_comp_units
++] = this_cu
;
3811 info_ptr
= info_ptr
+ this_cu
->length
;
3814 dwarf2_per_objfile
->all_comp_units
3815 = obstack_alloc (&objfile
->objfile_obstack
,
3816 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3817 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
3818 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3819 xfree (all_comp_units
);
3820 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
3823 /* Process all loaded DIEs for compilation unit CU, starting at
3824 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3825 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3826 DW_AT_ranges). If NEED_PC is set, then this function will set
3827 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3828 and record the covered ranges in the addrmap. */
3831 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
3832 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3834 struct partial_die_info
*pdi
;
3836 /* Now, march along the PDI's, descending into ones which have
3837 interesting children but skipping the children of the other ones,
3838 until we reach the end of the compilation unit. */
3844 fixup_partial_die (pdi
, cu
);
3846 /* Anonymous namespaces or modules have no name but have interesting
3847 children, so we need to look at them. Ditto for anonymous
3850 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
3851 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
3855 case DW_TAG_subprogram
:
3856 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3858 case DW_TAG_constant
:
3859 case DW_TAG_variable
:
3860 case DW_TAG_typedef
:
3861 case DW_TAG_union_type
:
3862 if (!pdi
->is_declaration
)
3864 add_partial_symbol (pdi
, cu
);
3867 case DW_TAG_class_type
:
3868 case DW_TAG_interface_type
:
3869 case DW_TAG_structure_type
:
3870 if (!pdi
->is_declaration
)
3872 add_partial_symbol (pdi
, cu
);
3875 case DW_TAG_enumeration_type
:
3876 if (!pdi
->is_declaration
)
3877 add_partial_enumeration (pdi
, cu
);
3879 case DW_TAG_base_type
:
3880 case DW_TAG_subrange_type
:
3881 /* File scope base type definitions are added to the partial
3883 add_partial_symbol (pdi
, cu
);
3885 case DW_TAG_namespace
:
3886 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
3889 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
3896 /* If the die has a sibling, skip to the sibling. */
3898 pdi
= pdi
->die_sibling
;
3902 /* Functions used to compute the fully scoped name of a partial DIE.
3904 Normally, this is simple. For C++, the parent DIE's fully scoped
3905 name is concatenated with "::" and the partial DIE's name. For
3906 Java, the same thing occurs except that "." is used instead of "::".
3907 Enumerators are an exception; they use the scope of their parent
3908 enumeration type, i.e. the name of the enumeration type is not
3909 prepended to the enumerator.
3911 There are two complexities. One is DW_AT_specification; in this
3912 case "parent" means the parent of the target of the specification,
3913 instead of the direct parent of the DIE. The other is compilers
3914 which do not emit DW_TAG_namespace; in this case we try to guess
3915 the fully qualified name of structure types from their members'
3916 linkage names. This must be done using the DIE's children rather
3917 than the children of any DW_AT_specification target. We only need
3918 to do this for structures at the top level, i.e. if the target of
3919 any DW_AT_specification (if any; otherwise the DIE itself) does not
3922 /* Compute the scope prefix associated with PDI's parent, in
3923 compilation unit CU. The result will be allocated on CU's
3924 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3925 field. NULL is returned if no prefix is necessary. */
3927 partial_die_parent_scope (struct partial_die_info
*pdi
,
3928 struct dwarf2_cu
*cu
)
3930 char *grandparent_scope
;
3931 struct partial_die_info
*parent
, *real_pdi
;
3933 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3934 then this means the parent of the specification DIE. */
3937 while (real_pdi
->has_specification
)
3938 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3940 parent
= real_pdi
->die_parent
;
3944 if (parent
->scope_set
)
3945 return parent
->scope
;
3947 fixup_partial_die (parent
, cu
);
3949 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
3951 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3952 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3953 Work around this problem here. */
3954 if (cu
->language
== language_cplus
3955 && parent
->tag
== DW_TAG_namespace
3956 && strcmp (parent
->name
, "::") == 0
3957 && grandparent_scope
== NULL
)
3959 parent
->scope
= NULL
;
3960 parent
->scope_set
= 1;
3964 if (pdi
->tag
== DW_TAG_enumerator
)
3965 /* Enumerators should not get the name of the enumeration as a prefix. */
3966 parent
->scope
= grandparent_scope
;
3967 else if (parent
->tag
== DW_TAG_namespace
3968 || parent
->tag
== DW_TAG_module
3969 || parent
->tag
== DW_TAG_structure_type
3970 || parent
->tag
== DW_TAG_class_type
3971 || parent
->tag
== DW_TAG_interface_type
3972 || parent
->tag
== DW_TAG_union_type
3973 || parent
->tag
== DW_TAG_enumeration_type
)
3975 if (grandparent_scope
== NULL
)
3976 parent
->scope
= parent
->name
;
3978 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
3980 parent
->name
, 0, cu
);
3984 /* FIXME drow/2004-04-01: What should we be doing with
3985 function-local names? For partial symbols, we should probably be
3987 complaint (&symfile_complaints
,
3988 _("unhandled containing DIE tag %d for DIE at %d"),
3989 parent
->tag
, pdi
->offset
.sect_off
);
3990 parent
->scope
= grandparent_scope
;
3993 parent
->scope_set
= 1;
3994 return parent
->scope
;
3997 /* Return the fully scoped name associated with PDI, from compilation unit
3998 CU. The result will be allocated with malloc. */
4000 partial_die_full_name (struct partial_die_info
*pdi
,
4001 struct dwarf2_cu
*cu
)
4005 /* If this is a template instantiation, we can not work out the
4006 template arguments from partial DIEs. So, unfortunately, we have
4007 to go through the full DIEs. At least any work we do building
4008 types here will be reused if full symbols are loaded later. */
4009 if (pdi
->has_template_arguments
)
4011 fixup_partial_die (pdi
, cu
);
4013 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
4015 struct die_info
*die
;
4016 struct attribute attr
;
4017 struct dwarf2_cu
*ref_cu
= cu
;
4019 /* DW_FORM_ref_addr is using section offset. */
4021 attr
.form
= DW_FORM_ref_addr
;
4022 attr
.u
.addr
= pdi
->offset
.sect_off
;
4023 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
4025 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
4029 parent_scope
= partial_die_parent_scope (pdi
, cu
);
4030 if (parent_scope
== NULL
)
4033 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
4037 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
4039 struct objfile
*objfile
= cu
->objfile
;
4041 char *actual_name
= NULL
;
4043 int built_actual_name
= 0;
4045 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4047 actual_name
= partial_die_full_name (pdi
, cu
);
4049 built_actual_name
= 1;
4051 if (actual_name
== NULL
)
4052 actual_name
= pdi
->name
;
4056 case DW_TAG_subprogram
:
4057 if (pdi
->is_external
|| cu
->language
== language_ada
)
4059 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
4060 of the global scope. But in Ada, we want to be able to access
4061 nested procedures globally. So all Ada subprograms are stored
4062 in the global scope. */
4063 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4064 mst_text, objfile); */
4065 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4067 VAR_DOMAIN
, LOC_BLOCK
,
4068 &objfile
->global_psymbols
,
4069 0, pdi
->lowpc
+ baseaddr
,
4070 cu
->language
, objfile
);
4074 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4075 mst_file_text, objfile); */
4076 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4078 VAR_DOMAIN
, LOC_BLOCK
,
4079 &objfile
->static_psymbols
,
4080 0, pdi
->lowpc
+ baseaddr
,
4081 cu
->language
, objfile
);
4084 case DW_TAG_constant
:
4086 struct psymbol_allocation_list
*list
;
4088 if (pdi
->is_external
)
4089 list
= &objfile
->global_psymbols
;
4091 list
= &objfile
->static_psymbols
;
4092 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4093 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
4094 list
, 0, 0, cu
->language
, objfile
);
4097 case DW_TAG_variable
:
4099 addr
= decode_locdesc (pdi
->locdesc
, cu
);
4103 && !dwarf2_per_objfile
->has_section_at_zero
)
4105 /* A global or static variable may also have been stripped
4106 out by the linker if unused, in which case its address
4107 will be nullified; do not add such variables into partial
4108 symbol table then. */
4110 else if (pdi
->is_external
)
4113 Don't enter into the minimal symbol tables as there is
4114 a minimal symbol table entry from the ELF symbols already.
4115 Enter into partial symbol table if it has a location
4116 descriptor or a type.
4117 If the location descriptor is missing, new_symbol will create
4118 a LOC_UNRESOLVED symbol, the address of the variable will then
4119 be determined from the minimal symbol table whenever the variable
4121 The address for the partial symbol table entry is not
4122 used by GDB, but it comes in handy for debugging partial symbol
4125 if (pdi
->locdesc
|| pdi
->has_type
)
4126 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4128 VAR_DOMAIN
, LOC_STATIC
,
4129 &objfile
->global_psymbols
,
4131 cu
->language
, objfile
);
4135 /* Static Variable. Skip symbols without location descriptors. */
4136 if (pdi
->locdesc
== NULL
)
4138 if (built_actual_name
)
4139 xfree (actual_name
);
4142 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
4143 mst_file_data, objfile); */
4144 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4146 VAR_DOMAIN
, LOC_STATIC
,
4147 &objfile
->static_psymbols
,
4149 cu
->language
, objfile
);
4152 case DW_TAG_typedef
:
4153 case DW_TAG_base_type
:
4154 case DW_TAG_subrange_type
:
4155 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4157 VAR_DOMAIN
, LOC_TYPEDEF
,
4158 &objfile
->static_psymbols
,
4159 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4161 case DW_TAG_namespace
:
4162 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4164 VAR_DOMAIN
, LOC_TYPEDEF
,
4165 &objfile
->global_psymbols
,
4166 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4168 case DW_TAG_class_type
:
4169 case DW_TAG_interface_type
:
4170 case DW_TAG_structure_type
:
4171 case DW_TAG_union_type
:
4172 case DW_TAG_enumeration_type
:
4173 /* Skip external references. The DWARF standard says in the section
4174 about "Structure, Union, and Class Type Entries": "An incomplete
4175 structure, union or class type is represented by a structure,
4176 union or class entry that does not have a byte size attribute
4177 and that has a DW_AT_declaration attribute." */
4178 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
4180 if (built_actual_name
)
4181 xfree (actual_name
);
4185 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
4186 static vs. global. */
4187 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4189 STRUCT_DOMAIN
, LOC_TYPEDEF
,
4190 (cu
->language
== language_cplus
4191 || cu
->language
== language_java
)
4192 ? &objfile
->global_psymbols
4193 : &objfile
->static_psymbols
,
4194 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4197 case DW_TAG_enumerator
:
4198 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4200 VAR_DOMAIN
, LOC_CONST
,
4201 (cu
->language
== language_cplus
4202 || cu
->language
== language_java
)
4203 ? &objfile
->global_psymbols
4204 : &objfile
->static_psymbols
,
4205 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4211 if (built_actual_name
)
4212 xfree (actual_name
);
4215 /* Read a partial die corresponding to a namespace; also, add a symbol
4216 corresponding to that namespace to the symbol table. NAMESPACE is
4217 the name of the enclosing namespace. */
4220 add_partial_namespace (struct partial_die_info
*pdi
,
4221 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4222 int need_pc
, struct dwarf2_cu
*cu
)
4224 /* Add a symbol for the namespace. */
4226 add_partial_symbol (pdi
, cu
);
4228 /* Now scan partial symbols in that namespace. */
4230 if (pdi
->has_children
)
4231 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4234 /* Read a partial die corresponding to a Fortran module. */
4237 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
4238 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4240 /* Now scan partial symbols in that module. */
4242 if (pdi
->has_children
)
4243 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4246 /* Read a partial die corresponding to a subprogram and create a partial
4247 symbol for that subprogram. When the CU language allows it, this
4248 routine also defines a partial symbol for each nested subprogram
4249 that this subprogram contains.
4251 DIE my also be a lexical block, in which case we simply search
4252 recursively for suprograms defined inside that lexical block.
4253 Again, this is only performed when the CU language allows this
4254 type of definitions. */
4257 add_partial_subprogram (struct partial_die_info
*pdi
,
4258 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4259 int need_pc
, struct dwarf2_cu
*cu
)
4261 if (pdi
->tag
== DW_TAG_subprogram
)
4263 if (pdi
->has_pc_info
)
4265 if (pdi
->lowpc
< *lowpc
)
4266 *lowpc
= pdi
->lowpc
;
4267 if (pdi
->highpc
> *highpc
)
4268 *highpc
= pdi
->highpc
;
4272 struct objfile
*objfile
= cu
->objfile
;
4274 baseaddr
= ANOFFSET (objfile
->section_offsets
,
4275 SECT_OFF_TEXT (objfile
));
4276 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4277 pdi
->lowpc
+ baseaddr
,
4278 pdi
->highpc
- 1 + baseaddr
,
4279 cu
->per_cu
->v
.psymtab
);
4283 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
4285 if (!pdi
->is_declaration
)
4286 /* Ignore subprogram DIEs that do not have a name, they are
4287 illegal. Do not emit a complaint at this point, we will
4288 do so when we convert this psymtab into a symtab. */
4290 add_partial_symbol (pdi
, cu
);
4294 if (! pdi
->has_children
)
4297 if (cu
->language
== language_ada
)
4299 pdi
= pdi
->die_child
;
4302 fixup_partial_die (pdi
, cu
);
4303 if (pdi
->tag
== DW_TAG_subprogram
4304 || pdi
->tag
== DW_TAG_lexical_block
)
4305 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4306 pdi
= pdi
->die_sibling
;
4311 /* Read a partial die corresponding to an enumeration type. */
4314 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
4315 struct dwarf2_cu
*cu
)
4317 struct partial_die_info
*pdi
;
4319 if (enum_pdi
->name
!= NULL
)
4320 add_partial_symbol (enum_pdi
, cu
);
4322 pdi
= enum_pdi
->die_child
;
4325 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
4326 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
4328 add_partial_symbol (pdi
, cu
);
4329 pdi
= pdi
->die_sibling
;
4333 /* Return the initial uleb128 in the die at INFO_PTR. */
4336 peek_abbrev_code (bfd
*abfd
, gdb_byte
*info_ptr
)
4338 unsigned int bytes_read
;
4340 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4343 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4344 Return the corresponding abbrev, or NULL if the number is zero (indicating
4345 an empty DIE). In either case *BYTES_READ will be set to the length of
4346 the initial number. */
4348 static struct abbrev_info
*
4349 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
4350 struct dwarf2_cu
*cu
)
4352 bfd
*abfd
= cu
->objfile
->obfd
;
4353 unsigned int abbrev_number
;
4354 struct abbrev_info
*abbrev
;
4356 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
4358 if (abbrev_number
== 0)
4361 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4364 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4365 abbrev_number
, bfd_get_filename (abfd
));
4371 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4372 Returns a pointer to the end of a series of DIEs, terminated by an empty
4373 DIE. Any children of the skipped DIEs will also be skipped. */
4376 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
4378 struct abbrev_info
*abbrev
;
4379 unsigned int bytes_read
;
4383 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
4385 return info_ptr
+ bytes_read
;
4387 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
4391 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4392 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4393 abbrev corresponding to that skipped uleb128 should be passed in
4394 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4398 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4399 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
4401 unsigned int bytes_read
;
4402 struct attribute attr
;
4403 bfd
*abfd
= cu
->objfile
->obfd
;
4404 unsigned int form
, i
;
4406 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
4408 /* The only abbrev we care about is DW_AT_sibling. */
4409 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
4411 read_attribute (&attr
, &abbrev
->attrs
[i
],
4412 abfd
, info_ptr
, cu
);
4413 if (attr
.form
== DW_FORM_ref_addr
)
4414 complaint (&symfile_complaints
,
4415 _("ignoring absolute DW_AT_sibling"));
4417 return buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
4420 /* If it isn't DW_AT_sibling, skip this attribute. */
4421 form
= abbrev
->attrs
[i
].form
;
4425 case DW_FORM_ref_addr
:
4426 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4427 and later it is offset sized. */
4428 if (cu
->header
.version
== 2)
4429 info_ptr
+= cu
->header
.addr_size
;
4431 info_ptr
+= cu
->header
.offset_size
;
4434 info_ptr
+= cu
->header
.addr_size
;
4441 case DW_FORM_flag_present
:
4453 case DW_FORM_ref_sig8
:
4456 case DW_FORM_string
:
4457 read_direct_string (abfd
, info_ptr
, &bytes_read
);
4458 info_ptr
+= bytes_read
;
4460 case DW_FORM_sec_offset
:
4462 info_ptr
+= cu
->header
.offset_size
;
4464 case DW_FORM_exprloc
:
4466 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4467 info_ptr
+= bytes_read
;
4469 case DW_FORM_block1
:
4470 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
4472 case DW_FORM_block2
:
4473 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
4475 case DW_FORM_block4
:
4476 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
4480 case DW_FORM_ref_udata
:
4481 info_ptr
= skip_leb128 (abfd
, info_ptr
);
4483 case DW_FORM_indirect
:
4484 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4485 info_ptr
+= bytes_read
;
4486 /* We need to continue parsing from here, so just go back to
4488 goto skip_attribute
;
4491 error (_("Dwarf Error: Cannot handle %s "
4492 "in DWARF reader [in module %s]"),
4493 dwarf_form_name (form
),
4494 bfd_get_filename (abfd
));
4498 if (abbrev
->has_children
)
4499 return skip_children (buffer
, info_ptr
, cu
);
4504 /* Locate ORIG_PDI's sibling.
4505 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4509 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
4510 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4511 bfd
*abfd
, struct dwarf2_cu
*cu
)
4513 /* Do we know the sibling already? */
4515 if (orig_pdi
->sibling
)
4516 return orig_pdi
->sibling
;
4518 /* Are there any children to deal with? */
4520 if (!orig_pdi
->has_children
)
4523 /* Skip the children the long way. */
4525 return skip_children (buffer
, info_ptr
, cu
);
4528 /* Expand this partial symbol table into a full symbol table. */
4531 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
4537 warning (_("bug: psymtab for %s is already read in."),
4544 printf_filtered (_("Reading in symbols for %s..."),
4546 gdb_flush (gdb_stdout
);
4549 /* Restore our global data. */
4550 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
4551 dwarf2_objfile_data_key
);
4553 /* If this psymtab is constructed from a debug-only objfile, the
4554 has_section_at_zero flag will not necessarily be correct. We
4555 can get the correct value for this flag by looking at the data
4556 associated with the (presumably stripped) associated objfile. */
4557 if (pst
->objfile
->separate_debug_objfile_backlink
)
4559 struct dwarf2_per_objfile
*dpo_backlink
4560 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
4561 dwarf2_objfile_data_key
);
4563 dwarf2_per_objfile
->has_section_at_zero
4564 = dpo_backlink
->has_section_at_zero
;
4567 dwarf2_per_objfile
->reading_partial_symbols
= 0;
4569 psymtab_to_symtab_1 (pst
);
4571 /* Finish up the debug error message. */
4573 printf_filtered (_("done.\n"));
4578 /* Reading in full CUs. */
4580 /* Add PER_CU to the queue. */
4583 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4585 struct dwarf2_queue_item
*item
;
4588 item
= xmalloc (sizeof (*item
));
4589 item
->per_cu
= per_cu
;
4592 if (dwarf2_queue
== NULL
)
4593 dwarf2_queue
= item
;
4595 dwarf2_queue_tail
->next
= item
;
4597 dwarf2_queue_tail
= item
;
4600 /* Process the queue. */
4603 process_queue (void)
4605 struct dwarf2_queue_item
*item
, *next_item
;
4607 /* The queue starts out with one item, but following a DIE reference
4608 may load a new CU, adding it to the end of the queue. */
4609 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
4611 if (dwarf2_per_objfile
->using_index
4612 ? !item
->per_cu
->v
.quick
->symtab
4613 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
4614 process_full_comp_unit (item
->per_cu
);
4616 item
->per_cu
->queued
= 0;
4617 next_item
= item
->next
;
4621 dwarf2_queue_tail
= NULL
;
4624 /* Free all allocated queue entries. This function only releases anything if
4625 an error was thrown; if the queue was processed then it would have been
4626 freed as we went along. */
4629 dwarf2_release_queue (void *dummy
)
4631 struct dwarf2_queue_item
*item
, *last
;
4633 item
= dwarf2_queue
;
4636 /* Anything still marked queued is likely to be in an
4637 inconsistent state, so discard it. */
4638 if (item
->per_cu
->queued
)
4640 if (item
->per_cu
->cu
!= NULL
)
4641 free_one_cached_comp_unit (item
->per_cu
->cu
);
4642 item
->per_cu
->queued
= 0;
4650 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
4653 /* Read in full symbols for PST, and anything it depends on. */
4656 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
4658 struct dwarf2_per_cu_data
*per_cu
;
4659 struct cleanup
*back_to
;
4662 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
4663 if (!pst
->dependencies
[i
]->readin
)
4665 /* Inform about additional files that need to be read in. */
4668 /* FIXME: i18n: Need to make this a single string. */
4669 fputs_filtered (" ", gdb_stdout
);
4671 fputs_filtered ("and ", gdb_stdout
);
4673 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
4674 wrap_here (""); /* Flush output. */
4675 gdb_flush (gdb_stdout
);
4677 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
4680 per_cu
= pst
->read_symtab_private
;
4684 /* It's an include file, no symbols to read for it.
4685 Everything is in the parent symtab. */
4690 dw2_do_instantiate_symtab (per_cu
);
4693 /* Load the DIEs associated with PER_CU into memory. */
4696 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4698 struct objfile
*objfile
= per_cu
->objfile
;
4699 bfd
*abfd
= objfile
->obfd
;
4700 struct dwarf2_cu
*cu
;
4702 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
4703 struct cleanup
*free_cu_cleanup
= NULL
;
4704 struct attribute
*attr
;
4707 gdb_assert (! per_cu
->debug_types_section
);
4709 /* Set local variables from the partial symbol table info. */
4710 offset
= per_cu
->offset
;
4712 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4713 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
.sect_off
;
4714 beg_of_comp_unit
= info_ptr
;
4716 if (per_cu
->cu
== NULL
)
4718 cu
= xmalloc (sizeof (*cu
));
4719 init_one_comp_unit (cu
, per_cu
);
4723 /* If an error occurs while loading, release our storage. */
4724 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
4726 /* Read in the comp_unit header. */
4727 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
4729 /* Skip dummy compilation units. */
4730 if (info_ptr
>= (dwarf2_per_objfile
->info
.buffer
4731 + dwarf2_per_objfile
->info
.size
)
4732 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4734 do_cleanups (free_cu_cleanup
);
4738 /* Complete the cu_header. */
4739 cu
->header
.offset
= offset
;
4740 cu
->header
.first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
4745 info_ptr
+= cu
->header
.first_die_offset
.cu_off
;
4748 cu
->dies
= read_comp_unit (info_ptr
, cu
);
4750 /* We try not to read any attributes in this function, because not
4751 all CUs needed for references have been loaded yet, and symbol
4752 table processing isn't initialized. But we have to set the CU language,
4753 or we won't be able to build types correctly. */
4754 prepare_one_comp_unit (cu
, cu
->dies
);
4756 /* Similarly, if we do not read the producer, we can not apply
4757 producer-specific interpretation. */
4758 attr
= dwarf2_attr (cu
->dies
, DW_AT_producer
, cu
);
4760 cu
->producer
= DW_STRING (attr
);
4764 /* We've successfully allocated this compilation unit. Let our
4765 caller clean it up when finished with it. */
4766 discard_cleanups (free_cu_cleanup
);
4768 /* Link this CU into read_in_chain. */
4769 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4770 dwarf2_per_objfile
->read_in_chain
= per_cu
;
4774 /* Add a DIE to the delayed physname list. */
4777 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
4778 const char *name
, struct die_info
*die
,
4779 struct dwarf2_cu
*cu
)
4781 struct delayed_method_info mi
;
4783 mi
.fnfield_index
= fnfield_index
;
4787 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
4790 /* A cleanup for freeing the delayed method list. */
4793 free_delayed_list (void *ptr
)
4795 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
4796 if (cu
->method_list
!= NULL
)
4798 VEC_free (delayed_method_info
, cu
->method_list
);
4799 cu
->method_list
= NULL
;
4803 /* Compute the physnames of any methods on the CU's method list.
4805 The computation of method physnames is delayed in order to avoid the
4806 (bad) condition that one of the method's formal parameters is of an as yet
4810 compute_delayed_physnames (struct dwarf2_cu
*cu
)
4813 struct delayed_method_info
*mi
;
4814 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
4816 const char *physname
;
4817 struct fn_fieldlist
*fn_flp
4818 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
4819 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
4820 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
4824 /* Generate full symbol information for PER_CU, whose DIEs have
4825 already been loaded into memory. */
4828 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4830 struct dwarf2_cu
*cu
= per_cu
->cu
;
4831 struct objfile
*objfile
= per_cu
->objfile
;
4832 CORE_ADDR lowpc
, highpc
;
4833 struct symtab
*symtab
;
4834 struct cleanup
*back_to
, *delayed_list_cleanup
;
4837 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4840 back_to
= make_cleanup (really_free_pendings
, NULL
);
4841 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
4843 cu
->list_in_scope
= &file_symbols
;
4845 /* Do line number decoding in read_file_scope () */
4846 process_die (cu
->dies
, cu
);
4848 /* Now that we have processed all the DIEs in the CU, all the types
4849 should be complete, and it should now be safe to compute all of the
4851 compute_delayed_physnames (cu
);
4852 do_cleanups (delayed_list_cleanup
);
4854 /* Some compilers don't define a DW_AT_high_pc attribute for the
4855 compilation unit. If the DW_AT_high_pc is missing, synthesize
4856 it, by scanning the DIE's below the compilation unit. */
4857 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
4859 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
4863 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
4865 /* Set symtab language to language from DW_AT_language. If the
4866 compilation is from a C file generated by language preprocessors, do
4867 not set the language if it was already deduced by start_subfile. */
4868 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
4869 symtab
->language
= cu
->language
;
4871 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
4872 produce DW_AT_location with location lists but it can be possibly
4873 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
4874 there were bugs in prologue debug info, fixed later in GCC-4.5
4875 by "unwind info for epilogues" patch (which is not directly related).
4877 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
4878 needed, it would be wrong due to missing DW_AT_producer there.
4880 Still one can confuse GDB by using non-standard GCC compilation
4881 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
4883 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
4884 symtab
->locations_valid
= 1;
4886 if (gcc_4_minor
>= 5)
4887 symtab
->epilogue_unwind_valid
= 1;
4889 symtab
->call_site_htab
= cu
->call_site_htab
;
4892 if (dwarf2_per_objfile
->using_index
)
4893 per_cu
->v
.quick
->symtab
= symtab
;
4896 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4897 pst
->symtab
= symtab
;
4901 do_cleanups (back_to
);
4904 /* Process a die and its children. */
4907 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
4911 case DW_TAG_padding
:
4913 case DW_TAG_compile_unit
:
4914 read_file_scope (die
, cu
);
4916 case DW_TAG_type_unit
:
4917 read_type_unit_scope (die
, cu
);
4919 case DW_TAG_subprogram
:
4920 case DW_TAG_inlined_subroutine
:
4921 read_func_scope (die
, cu
);
4923 case DW_TAG_lexical_block
:
4924 case DW_TAG_try_block
:
4925 case DW_TAG_catch_block
:
4926 read_lexical_block_scope (die
, cu
);
4928 case DW_TAG_GNU_call_site
:
4929 read_call_site_scope (die
, cu
);
4931 case DW_TAG_class_type
:
4932 case DW_TAG_interface_type
:
4933 case DW_TAG_structure_type
:
4934 case DW_TAG_union_type
:
4935 process_structure_scope (die
, cu
);
4937 case DW_TAG_enumeration_type
:
4938 process_enumeration_scope (die
, cu
);
4941 /* These dies have a type, but processing them does not create
4942 a symbol or recurse to process the children. Therefore we can
4943 read them on-demand through read_type_die. */
4944 case DW_TAG_subroutine_type
:
4945 case DW_TAG_set_type
:
4946 case DW_TAG_array_type
:
4947 case DW_TAG_pointer_type
:
4948 case DW_TAG_ptr_to_member_type
:
4949 case DW_TAG_reference_type
:
4950 case DW_TAG_string_type
:
4953 case DW_TAG_base_type
:
4954 case DW_TAG_subrange_type
:
4955 case DW_TAG_typedef
:
4956 /* Add a typedef symbol for the type definition, if it has a
4958 new_symbol (die
, read_type_die (die
, cu
), cu
);
4960 case DW_TAG_common_block
:
4961 read_common_block (die
, cu
);
4963 case DW_TAG_common_inclusion
:
4965 case DW_TAG_namespace
:
4966 processing_has_namespace_info
= 1;
4967 read_namespace (die
, cu
);
4970 processing_has_namespace_info
= 1;
4971 read_module (die
, cu
);
4973 case DW_TAG_imported_declaration
:
4974 case DW_TAG_imported_module
:
4975 processing_has_namespace_info
= 1;
4976 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
4977 || cu
->language
!= language_fortran
))
4978 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
4979 dwarf_tag_name (die
->tag
));
4980 read_import_statement (die
, cu
);
4983 new_symbol (die
, NULL
, cu
);
4988 /* A helper function for dwarf2_compute_name which determines whether DIE
4989 needs to have the name of the scope prepended to the name listed in the
4993 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4995 struct attribute
*attr
;
4999 case DW_TAG_namespace
:
5000 case DW_TAG_typedef
:
5001 case DW_TAG_class_type
:
5002 case DW_TAG_interface_type
:
5003 case DW_TAG_structure_type
:
5004 case DW_TAG_union_type
:
5005 case DW_TAG_enumeration_type
:
5006 case DW_TAG_enumerator
:
5007 case DW_TAG_subprogram
:
5011 case DW_TAG_variable
:
5012 case DW_TAG_constant
:
5013 /* We only need to prefix "globally" visible variables. These include
5014 any variable marked with DW_AT_external or any variable that
5015 lives in a namespace. [Variables in anonymous namespaces
5016 require prefixing, but they are not DW_AT_external.] */
5018 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
5020 struct dwarf2_cu
*spec_cu
= cu
;
5022 return die_needs_namespace (die_specification (die
, &spec_cu
),
5026 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5027 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
5028 && die
->parent
->tag
!= DW_TAG_module
)
5030 /* A variable in a lexical block of some kind does not need a
5031 namespace, even though in C++ such variables may be external
5032 and have a mangled name. */
5033 if (die
->parent
->tag
== DW_TAG_lexical_block
5034 || die
->parent
->tag
== DW_TAG_try_block
5035 || die
->parent
->tag
== DW_TAG_catch_block
5036 || die
->parent
->tag
== DW_TAG_subprogram
)
5045 /* Retrieve the last character from a mem_file. */
5048 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
5050 char *last_char_p
= (char *) object
;
5053 *last_char_p
= buffer
[length
- 1];
5056 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
5057 compute the physname for the object, which include a method's
5058 formal parameters (C++/Java) and return type (Java).
5060 For Ada, return the DIE's linkage name rather than the fully qualified
5061 name. PHYSNAME is ignored..
5063 The result is allocated on the objfile_obstack and canonicalized. */
5066 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
5069 struct objfile
*objfile
= cu
->objfile
;
5072 name
= dwarf2_name (die
, cu
);
5074 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
5075 compute it by typename_concat inside GDB. */
5076 if (cu
->language
== language_ada
5077 || (cu
->language
== language_fortran
&& physname
))
5079 /* For Ada unit, we prefer the linkage name over the name, as
5080 the former contains the exported name, which the user expects
5081 to be able to reference. Ideally, we want the user to be able
5082 to reference this entity using either natural or linkage name,
5083 but we haven't started looking at this enhancement yet. */
5084 struct attribute
*attr
;
5086 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5088 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5089 if (attr
&& DW_STRING (attr
))
5090 return DW_STRING (attr
);
5093 /* These are the only languages we know how to qualify names in. */
5095 && (cu
->language
== language_cplus
|| cu
->language
== language_java
5096 || cu
->language
== language_fortran
))
5098 if (die_needs_namespace (die
, cu
))
5102 struct ui_file
*buf
;
5104 prefix
= determine_prefix (die
, cu
);
5105 buf
= mem_fileopen ();
5106 if (*prefix
!= '\0')
5108 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
5111 fputs_unfiltered (prefixed_name
, buf
);
5112 xfree (prefixed_name
);
5115 fputs_unfiltered (name
, buf
);
5117 /* Template parameters may be specified in the DIE's DW_AT_name, or
5118 as children with DW_TAG_template_type_param or
5119 DW_TAG_value_type_param. If the latter, add them to the name
5120 here. If the name already has template parameters, then
5121 skip this step; some versions of GCC emit both, and
5122 it is more efficient to use the pre-computed name.
5124 Something to keep in mind about this process: it is very
5125 unlikely, or in some cases downright impossible, to produce
5126 something that will match the mangled name of a function.
5127 If the definition of the function has the same debug info,
5128 we should be able to match up with it anyway. But fallbacks
5129 using the minimal symbol, for instance to find a method
5130 implemented in a stripped copy of libstdc++, will not work.
5131 If we do not have debug info for the definition, we will have to
5132 match them up some other way.
5134 When we do name matching there is a related problem with function
5135 templates; two instantiated function templates are allowed to
5136 differ only by their return types, which we do not add here. */
5138 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
5140 struct attribute
*attr
;
5141 struct die_info
*child
;
5144 die
->building_fullname
= 1;
5146 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
5151 struct dwarf2_locexpr_baton
*baton
;
5154 if (child
->tag
!= DW_TAG_template_type_param
5155 && child
->tag
!= DW_TAG_template_value_param
)
5160 fputs_unfiltered ("<", buf
);
5164 fputs_unfiltered (", ", buf
);
5166 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
5169 complaint (&symfile_complaints
,
5170 _("template parameter missing DW_AT_type"));
5171 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
5174 type
= die_type (child
, cu
);
5176 if (child
->tag
== DW_TAG_template_type_param
)
5178 c_print_type (type
, "", buf
, -1, 0);
5182 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
5185 complaint (&symfile_complaints
,
5186 _("template parameter missing "
5187 "DW_AT_const_value"));
5188 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
5192 dwarf2_const_value_attr (attr
, type
, name
,
5193 &cu
->comp_unit_obstack
, cu
,
5194 &value
, &bytes
, &baton
);
5196 if (TYPE_NOSIGN (type
))
5197 /* GDB prints characters as NUMBER 'CHAR'. If that's
5198 changed, this can use value_print instead. */
5199 c_printchar (value
, type
, buf
);
5202 struct value_print_options opts
;
5205 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
5209 else if (bytes
!= NULL
)
5211 v
= allocate_value (type
);
5212 memcpy (value_contents_writeable (v
), bytes
,
5213 TYPE_LENGTH (type
));
5216 v
= value_from_longest (type
, value
);
5218 /* Specify decimal so that we do not depend on
5220 get_formatted_print_options (&opts
, 'd');
5222 value_print (v
, buf
, &opts
);
5228 die
->building_fullname
= 0;
5232 /* Close the argument list, with a space if necessary
5233 (nested templates). */
5234 char last_char
= '\0';
5235 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
5236 if (last_char
== '>')
5237 fputs_unfiltered (" >", buf
);
5239 fputs_unfiltered (">", buf
);
5243 /* For Java and C++ methods, append formal parameter type
5244 information, if PHYSNAME. */
5246 if (physname
&& die
->tag
== DW_TAG_subprogram
5247 && (cu
->language
== language_cplus
5248 || cu
->language
== language_java
))
5250 struct type
*type
= read_type_die (die
, cu
);
5252 c_type_print_args (type
, buf
, 1, cu
->language
);
5254 if (cu
->language
== language_java
)
5256 /* For java, we must append the return type to method
5258 if (die
->tag
== DW_TAG_subprogram
)
5259 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
5262 else if (cu
->language
== language_cplus
)
5264 /* Assume that an artificial first parameter is
5265 "this", but do not crash if it is not. RealView
5266 marks unnamed (and thus unused) parameters as
5267 artificial; there is no way to differentiate
5269 if (TYPE_NFIELDS (type
) > 0
5270 && TYPE_FIELD_ARTIFICIAL (type
, 0)
5271 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
5272 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
5274 fputs_unfiltered (" const", buf
);
5278 name
= ui_file_obsavestring (buf
, &objfile
->objfile_obstack
,
5280 ui_file_delete (buf
);
5282 if (cu
->language
== language_cplus
)
5285 = dwarf2_canonicalize_name (name
, cu
,
5286 &objfile
->objfile_obstack
);
5297 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5298 If scope qualifiers are appropriate they will be added. The result
5299 will be allocated on the objfile_obstack, or NULL if the DIE does
5300 not have a name. NAME may either be from a previous call to
5301 dwarf2_name or NULL.
5303 The output string will be canonicalized (if C++/Java). */
5306 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5308 return dwarf2_compute_name (name
, die
, cu
, 0);
5311 /* Construct a physname for the given DIE in CU. NAME may either be
5312 from a previous call to dwarf2_name or NULL. The result will be
5313 allocated on the objfile_objstack or NULL if the DIE does not have a
5316 The output string will be canonicalized (if C++/Java). */
5319 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5321 struct objfile
*objfile
= cu
->objfile
;
5322 struct attribute
*attr
;
5323 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
5324 struct cleanup
*back_to
;
5327 /* In this case dwarf2_compute_name is just a shortcut not building anything
5329 if (!die_needs_namespace (die
, cu
))
5330 return dwarf2_compute_name (name
, die
, cu
, 1);
5332 back_to
= make_cleanup (null_cleanup
, NULL
);
5334 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5336 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5338 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
5340 if (attr
&& DW_STRING (attr
))
5344 mangled
= DW_STRING (attr
);
5346 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
5347 type. It is easier for GDB users to search for such functions as
5348 `name(params)' than `long name(params)'. In such case the minimal
5349 symbol names do not match the full symbol names but for template
5350 functions there is never a need to look up their definition from their
5351 declaration so the only disadvantage remains the minimal symbol
5352 variant `long name(params)' does not have the proper inferior type.
5355 demangled
= cplus_demangle (mangled
, (DMGL_PARAMS
| DMGL_ANSI
5356 | (cu
->language
== language_java
5357 ? DMGL_JAVA
| DMGL_RET_POSTFIX
5361 make_cleanup (xfree
, demangled
);
5371 if (canon
== NULL
|| check_physname
)
5373 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
5375 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
5377 /* It may not mean a bug in GDB. The compiler could also
5378 compute DW_AT_linkage_name incorrectly. But in such case
5379 GDB would need to be bug-to-bug compatible. */
5381 complaint (&symfile_complaints
,
5382 _("Computed physname <%s> does not match demangled <%s> "
5383 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
5384 physname
, canon
, mangled
, die
->offset
.sect_off
, objfile
->name
);
5386 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
5387 is available here - over computed PHYSNAME. It is safer
5388 against both buggy GDB and buggy compilers. */
5402 retval
= obsavestring (retval
, strlen (retval
),
5403 &objfile
->objfile_obstack
);
5405 do_cleanups (back_to
);
5409 /* Read the import statement specified by the given die and record it. */
5412 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
5414 struct objfile
*objfile
= cu
->objfile
;
5415 struct attribute
*import_attr
;
5416 struct die_info
*imported_die
, *child_die
;
5417 struct dwarf2_cu
*imported_cu
;
5418 const char *imported_name
;
5419 const char *imported_name_prefix
;
5420 const char *canonical_name
;
5421 const char *import_alias
;
5422 const char *imported_declaration
= NULL
;
5423 const char *import_prefix
;
5424 VEC (const_char_ptr
) *excludes
= NULL
;
5425 struct cleanup
*cleanups
;
5429 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
5430 if (import_attr
== NULL
)
5432 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5433 dwarf_tag_name (die
->tag
));
5438 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
5439 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5440 if (imported_name
== NULL
)
5442 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
5444 The import in the following code:
5458 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
5459 <52> DW_AT_decl_file : 1
5460 <53> DW_AT_decl_line : 6
5461 <54> DW_AT_import : <0x75>
5462 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
5464 <5b> DW_AT_decl_file : 1
5465 <5c> DW_AT_decl_line : 2
5466 <5d> DW_AT_type : <0x6e>
5468 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
5469 <76> DW_AT_byte_size : 4
5470 <77> DW_AT_encoding : 5 (signed)
5472 imports the wrong die ( 0x75 instead of 0x58 ).
5473 This case will be ignored until the gcc bug is fixed. */
5477 /* Figure out the local name after import. */
5478 import_alias
= dwarf2_name (die
, cu
);
5480 /* Figure out where the statement is being imported to. */
5481 import_prefix
= determine_prefix (die
, cu
);
5483 /* Figure out what the scope of the imported die is and prepend it
5484 to the name of the imported die. */
5485 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
5487 if (imported_die
->tag
!= DW_TAG_namespace
5488 && imported_die
->tag
!= DW_TAG_module
)
5490 imported_declaration
= imported_name
;
5491 canonical_name
= imported_name_prefix
;
5493 else if (strlen (imported_name_prefix
) > 0)
5495 temp
= alloca (strlen (imported_name_prefix
)
5496 + 2 + strlen (imported_name
) + 1);
5497 strcpy (temp
, imported_name_prefix
);
5498 strcat (temp
, "::");
5499 strcat (temp
, imported_name
);
5500 canonical_name
= temp
;
5503 canonical_name
= imported_name
;
5505 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
5507 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
5508 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
5509 child_die
= sibling_die (child_die
))
5511 /* DWARF-4: A Fortran use statement with a “rename list” may be
5512 represented by an imported module entry with an import attribute
5513 referring to the module and owned entries corresponding to those
5514 entities that are renamed as part of being imported. */
5516 if (child_die
->tag
!= DW_TAG_imported_declaration
)
5518 complaint (&symfile_complaints
,
5519 _("child DW_TAG_imported_declaration expected "
5520 "- DIE at 0x%x [in module %s]"),
5521 child_die
->offset
.sect_off
, objfile
->name
);
5525 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
5526 if (import_attr
== NULL
)
5528 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5529 dwarf_tag_name (child_die
->tag
));
5534 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
5536 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5537 if (imported_name
== NULL
)
5539 complaint (&symfile_complaints
,
5540 _("child DW_TAG_imported_declaration has unknown "
5541 "imported name - DIE at 0x%x [in module %s]"),
5542 child_die
->offset
.sect_off
, objfile
->name
);
5546 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
5548 process_die (child_die
, cu
);
5551 cp_add_using_directive (import_prefix
,
5554 imported_declaration
,
5556 &objfile
->objfile_obstack
);
5558 do_cleanups (cleanups
);
5561 /* Cleanup function for read_file_scope. */
5564 free_cu_line_header (void *arg
)
5566 struct dwarf2_cu
*cu
= arg
;
5568 free_line_header (cu
->line_header
);
5569 cu
->line_header
= NULL
;
5573 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
5574 char **name
, char **comp_dir
)
5576 struct attribute
*attr
;
5581 /* Find the filename. Do not use dwarf2_name here, since the filename
5582 is not a source language identifier. */
5583 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5586 *name
= DW_STRING (attr
);
5589 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5591 *comp_dir
= DW_STRING (attr
);
5592 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
5594 *comp_dir
= ldirname (*name
);
5595 if (*comp_dir
!= NULL
)
5596 make_cleanup (xfree
, *comp_dir
);
5598 if (*comp_dir
!= NULL
)
5600 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5601 directory, get rid of it. */
5602 char *cp
= strchr (*comp_dir
, ':');
5604 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
5609 *name
= "<unknown>";
5612 /* Handle DW_AT_stmt_list for a compilation unit or type unit.
5613 DIE is the DW_TAG_compile_unit or DW_TAG_type_unit die for CU.
5614 COMP_DIR is the compilation directory.
5615 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
5618 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
5619 const char *comp_dir
, int want_line_info
)
5621 struct attribute
*attr
;
5622 struct objfile
*objfile
= cu
->objfile
;
5623 bfd
*abfd
= objfile
->obfd
;
5625 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5628 unsigned int line_offset
= DW_UNSND (attr
);
5629 struct line_header
*line_header
5630 = dwarf_decode_line_header (line_offset
, abfd
, cu
);
5634 cu
->line_header
= line_header
;
5635 make_cleanup (free_cu_line_header
, cu
);
5636 dwarf_decode_lines (line_header
, comp_dir
, cu
, NULL
, want_line_info
);
5641 /* Process DW_TAG_compile_unit. */
5644 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5646 struct objfile
*objfile
= cu
->objfile
;
5647 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5648 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
5649 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
5650 struct attribute
*attr
;
5652 char *comp_dir
= NULL
;
5653 struct die_info
*child_die
;
5654 bfd
*abfd
= objfile
->obfd
;
5657 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5659 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
5661 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5662 from finish_block. */
5663 if (lowpc
== ((CORE_ADDR
) -1))
5668 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
5670 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5673 set_cu_language (DW_UNSND (attr
), cu
);
5676 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5678 cu
->producer
= DW_STRING (attr
);
5680 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
5681 standardised yet. As a workaround for the language detection we fall
5682 back to the DW_AT_producer string. */
5683 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
5684 cu
->language
= language_opencl
;
5686 /* We assume that we're processing GCC output. */
5687 processing_gcc_compilation
= 2;
5689 processing_has_namespace_info
= 0;
5691 start_symtab (name
, comp_dir
, lowpc
);
5692 record_debugformat ("DWARF 2");
5693 record_producer (cu
->producer
);
5695 /* Decode line number information if present. We do this before
5696 processing child DIEs, so that the line header table is available
5697 for DW_AT_decl_file. */
5698 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, 1);
5700 /* Process all dies in compilation unit. */
5701 if (die
->child
!= NULL
)
5703 child_die
= die
->child
;
5704 while (child_die
&& child_die
->tag
)
5706 process_die (child_die
, cu
);
5707 child_die
= sibling_die (child_die
);
5711 /* Decode macro information, if present. Dwarf 2 macro information
5712 refers to information in the line number info statement program
5713 header, so we can only read it if we've read the header
5715 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
5716 if (attr
&& cu
->line_header
)
5718 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
5719 complaint (&symfile_complaints
,
5720 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
5722 dwarf_decode_macros (cu
->line_header
, DW_UNSND (attr
),
5724 &dwarf2_per_objfile
->macro
, 1);
5728 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
5729 if (attr
&& cu
->line_header
)
5731 unsigned int macro_offset
= DW_UNSND (attr
);
5733 dwarf_decode_macros (cu
->line_header
, macro_offset
,
5735 &dwarf2_per_objfile
->macinfo
, 0);
5739 do_cleanups (back_to
);
5742 /* Process DW_TAG_type_unit.
5743 For TUs we want to skip the first top level sibling if it's not the
5744 actual type being defined by this TU. In this case the first top
5745 level sibling is there to provide context only. */
5748 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5750 struct objfile
*objfile
= cu
->objfile
;
5751 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5753 struct attribute
*attr
;
5755 char *comp_dir
= NULL
;
5756 struct die_info
*child_die
;
5757 bfd
*abfd
= objfile
->obfd
;
5759 /* start_symtab needs a low pc, but we don't really have one.
5760 Do what read_file_scope would do in the absence of such info. */
5761 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5763 /* Find the filename. Do not use dwarf2_name here, since the filename
5764 is not a source language identifier. */
5765 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5767 name
= DW_STRING (attr
);
5769 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5771 comp_dir
= DW_STRING (attr
);
5772 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
5774 comp_dir
= ldirname (name
);
5775 if (comp_dir
!= NULL
)
5776 make_cleanup (xfree
, comp_dir
);
5782 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5784 set_cu_language (DW_UNSND (attr
), cu
);
5786 /* This isn't technically needed today. It is done for symmetry
5787 with read_file_scope. */
5788 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5790 cu
->producer
= DW_STRING (attr
);
5792 /* We assume that we're processing GCC output. */
5793 processing_gcc_compilation
= 2;
5795 processing_has_namespace_info
= 0;
5797 start_symtab (name
, comp_dir
, lowpc
);
5798 record_debugformat ("DWARF 2");
5799 record_producer (cu
->producer
);
5801 /* Decode line number information if present. We do this before
5802 processing child DIEs, so that the line header table is available
5803 for DW_AT_decl_file.
5804 We don't need the pc/line-number mapping for type units. */
5805 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, 0);
5807 /* Process the dies in the type unit. */
5808 if (die
->child
== NULL
)
5810 dump_die_for_error (die
);
5811 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5812 bfd_get_filename (abfd
));
5815 child_die
= die
->child
;
5817 while (child_die
&& child_die
->tag
)
5819 process_die (child_die
, cu
);
5821 child_die
= sibling_die (child_die
);
5824 do_cleanups (back_to
);
5827 /* qsort helper for inherit_abstract_dies. */
5830 unsigned_int_compar (const void *ap
, const void *bp
)
5832 unsigned int a
= *(unsigned int *) ap
;
5833 unsigned int b
= *(unsigned int *) bp
;
5835 return (a
> b
) - (b
> a
);
5838 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5839 Inherit only the children of the DW_AT_abstract_origin DIE not being
5840 already referenced by DW_AT_abstract_origin from the children of the
5844 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
5846 struct die_info
*child_die
;
5847 unsigned die_children_count
;
5848 /* CU offsets which were referenced by children of the current DIE. */
5849 sect_offset
*offsets
;
5850 sect_offset
*offsets_end
, *offsetp
;
5851 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5852 struct die_info
*origin_die
;
5853 /* Iterator of the ORIGIN_DIE children. */
5854 struct die_info
*origin_child_die
;
5855 struct cleanup
*cleanups
;
5856 struct attribute
*attr
;
5857 struct dwarf2_cu
*origin_cu
;
5858 struct pending
**origin_previous_list_in_scope
;
5860 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
5864 /* Note that following die references may follow to a die in a
5868 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
5870 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5872 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
5873 origin_cu
->list_in_scope
= cu
->list_in_scope
;
5875 if (die
->tag
!= origin_die
->tag
5876 && !(die
->tag
== DW_TAG_inlined_subroutine
5877 && origin_die
->tag
== DW_TAG_subprogram
))
5878 complaint (&symfile_complaints
,
5879 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5880 die
->offset
.sect_off
, origin_die
->offset
.sect_off
);
5882 child_die
= die
->child
;
5883 die_children_count
= 0;
5884 while (child_die
&& child_die
->tag
)
5886 child_die
= sibling_die (child_die
);
5887 die_children_count
++;
5889 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
5890 cleanups
= make_cleanup (xfree
, offsets
);
5892 offsets_end
= offsets
;
5893 child_die
= die
->child
;
5894 while (child_die
&& child_die
->tag
)
5896 /* For each CHILD_DIE, find the corresponding child of
5897 ORIGIN_DIE. If there is more than one layer of
5898 DW_AT_abstract_origin, follow them all; there shouldn't be,
5899 but GCC versions at least through 4.4 generate this (GCC PR
5901 struct die_info
*child_origin_die
= child_die
;
5902 struct dwarf2_cu
*child_origin_cu
= cu
;
5906 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
5910 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
5914 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5915 counterpart may exist. */
5916 if (child_origin_die
!= child_die
)
5918 if (child_die
->tag
!= child_origin_die
->tag
5919 && !(child_die
->tag
== DW_TAG_inlined_subroutine
5920 && child_origin_die
->tag
== DW_TAG_subprogram
))
5921 complaint (&symfile_complaints
,
5922 _("Child DIE 0x%x and its abstract origin 0x%x have "
5923 "different tags"), child_die
->offset
.sect_off
,
5924 child_origin_die
->offset
.sect_off
);
5925 if (child_origin_die
->parent
!= origin_die
)
5926 complaint (&symfile_complaints
,
5927 _("Child DIE 0x%x and its abstract origin 0x%x have "
5928 "different parents"), child_die
->offset
.sect_off
,
5929 child_origin_die
->offset
.sect_off
);
5931 *offsets_end
++ = child_origin_die
->offset
;
5933 child_die
= sibling_die (child_die
);
5935 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
5936 unsigned_int_compar
);
5937 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
5938 if (offsetp
[-1].sect_off
== offsetp
->sect_off
)
5939 complaint (&symfile_complaints
,
5940 _("Multiple children of DIE 0x%x refer "
5941 "to DIE 0x%x as their abstract origin"),
5942 die
->offset
.sect_off
, offsetp
->sect_off
);
5945 origin_child_die
= origin_die
->child
;
5946 while (origin_child_die
&& origin_child_die
->tag
)
5948 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5949 while (offsetp
< offsets_end
5950 && offsetp
->sect_off
< origin_child_die
->offset
.sect_off
)
5952 if (offsetp
>= offsets_end
5953 || offsetp
->sect_off
> origin_child_die
->offset
.sect_off
)
5955 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5956 process_die (origin_child_die
, origin_cu
);
5958 origin_child_die
= sibling_die (origin_child_die
);
5960 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
5962 do_cleanups (cleanups
);
5966 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5968 struct objfile
*objfile
= cu
->objfile
;
5969 struct context_stack
*new;
5972 struct die_info
*child_die
;
5973 struct attribute
*attr
, *call_line
, *call_file
;
5976 struct block
*block
;
5977 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
5978 VEC (symbolp
) *template_args
= NULL
;
5979 struct template_symbol
*templ_func
= NULL
;
5983 /* If we do not have call site information, we can't show the
5984 caller of this inlined function. That's too confusing, so
5985 only use the scope for local variables. */
5986 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
5987 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
5988 if (call_line
== NULL
|| call_file
== NULL
)
5990 read_lexical_block_scope (die
, cu
);
5995 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5997 name
= dwarf2_name (die
, cu
);
5999 /* Ignore functions with missing or empty names. These are actually
6000 illegal according to the DWARF standard. */
6003 complaint (&symfile_complaints
,
6004 _("missing name for subprogram DIE at %d"),
6005 die
->offset
.sect_off
);
6009 /* Ignore functions with missing or invalid low and high pc attributes. */
6010 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
6012 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
6013 if (!attr
|| !DW_UNSND (attr
))
6014 complaint (&symfile_complaints
,
6015 _("cannot get low and high bounds "
6016 "for subprogram DIE at %d"),
6017 die
->offset
.sect_off
);
6024 /* If we have any template arguments, then we must allocate a
6025 different sort of symbol. */
6026 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
6028 if (child_die
->tag
== DW_TAG_template_type_param
6029 || child_die
->tag
== DW_TAG_template_value_param
)
6031 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6032 struct template_symbol
);
6033 templ_func
->base
.is_cplus_template_function
= 1;
6038 new = push_context (0, lowpc
);
6039 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
6040 (struct symbol
*) templ_func
);
6042 /* If there is a location expression for DW_AT_frame_base, record
6044 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
6046 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
6047 expression is being recorded directly in the function's symbol
6048 and not in a separate frame-base object. I guess this hack is
6049 to avoid adding some sort of frame-base adjunct/annex to the
6050 function's symbol :-(. The problem with doing this is that it
6051 results in a function symbol with a location expression that
6052 has nothing to do with the location of the function, ouch! The
6053 relationship should be: a function's symbol has-a frame base; a
6054 frame-base has-a location expression. */
6055 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
6057 cu
->list_in_scope
= &local_symbols
;
6059 if (die
->child
!= NULL
)
6061 child_die
= die
->child
;
6062 while (child_die
&& child_die
->tag
)
6064 if (child_die
->tag
== DW_TAG_template_type_param
6065 || child_die
->tag
== DW_TAG_template_value_param
)
6067 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
6070 VEC_safe_push (symbolp
, template_args
, arg
);
6073 process_die (child_die
, cu
);
6074 child_die
= sibling_die (child_die
);
6078 inherit_abstract_dies (die
, cu
);
6080 /* If we have a DW_AT_specification, we might need to import using
6081 directives from the context of the specification DIE. See the
6082 comment in determine_prefix. */
6083 if (cu
->language
== language_cplus
6084 && dwarf2_attr (die
, DW_AT_specification
, cu
))
6086 struct dwarf2_cu
*spec_cu
= cu
;
6087 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
6091 child_die
= spec_die
->child
;
6092 while (child_die
&& child_die
->tag
)
6094 if (child_die
->tag
== DW_TAG_imported_module
)
6095 process_die (child_die
, spec_cu
);
6096 child_die
= sibling_die (child_die
);
6099 /* In some cases, GCC generates specification DIEs that
6100 themselves contain DW_AT_specification attributes. */
6101 spec_die
= die_specification (spec_die
, &spec_cu
);
6105 new = pop_context ();
6106 /* Make a block for the local symbols within. */
6107 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
6108 lowpc
, highpc
, objfile
);
6110 /* For C++, set the block's scope. */
6111 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
6112 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
6113 determine_prefix (die
, cu
),
6114 processing_has_namespace_info
);
6116 /* If we have address ranges, record them. */
6117 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
6119 /* Attach template arguments to function. */
6120 if (! VEC_empty (symbolp
, template_args
))
6122 gdb_assert (templ_func
!= NULL
);
6124 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
6125 templ_func
->template_arguments
6126 = obstack_alloc (&objfile
->objfile_obstack
,
6127 (templ_func
->n_template_arguments
6128 * sizeof (struct symbol
*)));
6129 memcpy (templ_func
->template_arguments
,
6130 VEC_address (symbolp
, template_args
),
6131 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
6132 VEC_free (symbolp
, template_args
);
6135 /* In C++, we can have functions nested inside functions (e.g., when
6136 a function declares a class that has methods). This means that
6137 when we finish processing a function scope, we may need to go
6138 back to building a containing block's symbol lists. */
6139 local_symbols
= new->locals
;
6140 param_symbols
= new->params
;
6141 using_directives
= new->using_directives
;
6143 /* If we've finished processing a top-level function, subsequent
6144 symbols go in the file symbol list. */
6145 if (outermost_context_p ())
6146 cu
->list_in_scope
= &file_symbols
;
6149 /* Process all the DIES contained within a lexical block scope. Start
6150 a new scope, process the dies, and then close the scope. */
6153 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6155 struct objfile
*objfile
= cu
->objfile
;
6156 struct context_stack
*new;
6157 CORE_ADDR lowpc
, highpc
;
6158 struct die_info
*child_die
;
6161 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6163 /* Ignore blocks with missing or invalid low and high pc attributes. */
6164 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
6165 as multiple lexical blocks? Handling children in a sane way would
6166 be nasty. Might be easier to properly extend generic blocks to
6168 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
6173 push_context (0, lowpc
);
6174 if (die
->child
!= NULL
)
6176 child_die
= die
->child
;
6177 while (child_die
&& child_die
->tag
)
6179 process_die (child_die
, cu
);
6180 child_die
= sibling_die (child_die
);
6183 new = pop_context ();
6185 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
6188 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
6191 /* Note that recording ranges after traversing children, as we
6192 do here, means that recording a parent's ranges entails
6193 walking across all its children's ranges as they appear in
6194 the address map, which is quadratic behavior.
6196 It would be nicer to record the parent's ranges before
6197 traversing its children, simply overriding whatever you find
6198 there. But since we don't even decide whether to create a
6199 block until after we've traversed its children, that's hard
6201 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
6203 local_symbols
= new->locals
;
6204 using_directives
= new->using_directives
;
6207 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
6210 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6212 struct objfile
*objfile
= cu
->objfile
;
6213 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6214 CORE_ADDR pc
, baseaddr
;
6215 struct attribute
*attr
;
6216 struct call_site
*call_site
, call_site_local
;
6219 struct die_info
*child_die
;
6221 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6223 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6226 complaint (&symfile_complaints
,
6227 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
6228 "DIE 0x%x [in module %s]"),
6229 die
->offset
.sect_off
, objfile
->name
);
6232 pc
= DW_ADDR (attr
) + baseaddr
;
6234 if (cu
->call_site_htab
== NULL
)
6235 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
6236 NULL
, &objfile
->objfile_obstack
,
6237 hashtab_obstack_allocate
, NULL
);
6238 call_site_local
.pc
= pc
;
6239 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
6242 complaint (&symfile_complaints
,
6243 _("Duplicate PC %s for DW_TAG_GNU_call_site "
6244 "DIE 0x%x [in module %s]"),
6245 paddress (gdbarch
, pc
), die
->offset
.sect_off
, objfile
->name
);
6249 /* Count parameters at the caller. */
6252 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
6253 child_die
= sibling_die (child_die
))
6255 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
6257 complaint (&symfile_complaints
,
6258 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
6259 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6260 child_die
->tag
, child_die
->offset
.sect_off
, objfile
->name
);
6267 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
6268 (sizeof (*call_site
)
6269 + (sizeof (*call_site
->parameter
)
6272 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
6275 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
6277 struct die_info
*func_die
;
6279 /* Skip also over DW_TAG_inlined_subroutine. */
6280 for (func_die
= die
->parent
;
6281 func_die
&& func_die
->tag
!= DW_TAG_subprogram
6282 && func_die
->tag
!= DW_TAG_subroutine_type
;
6283 func_die
= func_die
->parent
);
6285 /* DW_AT_GNU_all_call_sites is a superset
6286 of DW_AT_GNU_all_tail_call_sites. */
6288 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
6289 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
6291 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
6292 not complete. But keep CALL_SITE for look ups via call_site_htab,
6293 both the initial caller containing the real return address PC and
6294 the final callee containing the current PC of a chain of tail
6295 calls do not need to have the tail call list complete. But any
6296 function candidate for a virtual tail call frame searched via
6297 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
6298 determined unambiguously. */
6302 struct type
*func_type
= NULL
;
6305 func_type
= get_die_type (func_die
, cu
);
6306 if (func_type
!= NULL
)
6308 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
6310 /* Enlist this call site to the function. */
6311 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
6312 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
6315 complaint (&symfile_complaints
,
6316 _("Cannot find function owning DW_TAG_GNU_call_site "
6317 "DIE 0x%x [in module %s]"),
6318 die
->offset
.sect_off
, objfile
->name
);
6322 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
6324 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
6325 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
6326 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
6327 /* Keep NULL DWARF_BLOCK. */;
6328 else if (attr_form_is_block (attr
))
6330 struct dwarf2_locexpr_baton
*dlbaton
;
6332 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
6333 dlbaton
->data
= DW_BLOCK (attr
)->data
;
6334 dlbaton
->size
= DW_BLOCK (attr
)->size
;
6335 dlbaton
->per_cu
= cu
->per_cu
;
6337 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
6339 else if (is_ref_attr (attr
))
6341 struct dwarf2_cu
*target_cu
= cu
;
6342 struct die_info
*target_die
;
6344 target_die
= follow_die_ref_or_sig (die
, attr
, &target_cu
);
6345 gdb_assert (target_cu
->objfile
== objfile
);
6346 if (die_is_declaration (target_die
, target_cu
))
6348 const char *target_physname
;
6350 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
6351 if (target_physname
== NULL
)
6352 complaint (&symfile_complaints
,
6353 _("DW_AT_GNU_call_site_target target DIE has invalid "
6354 "physname, for referencing DIE 0x%x [in module %s]"),
6355 die
->offset
.sect_off
, objfile
->name
);
6357 SET_FIELD_PHYSNAME (call_site
->target
, (char *) target_physname
);
6363 /* DW_AT_entry_pc should be preferred. */
6364 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
6365 complaint (&symfile_complaints
,
6366 _("DW_AT_GNU_call_site_target target DIE has invalid "
6367 "low pc, for referencing DIE 0x%x [in module %s]"),
6368 die
->offset
.sect_off
, objfile
->name
);
6370 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
6374 complaint (&symfile_complaints
,
6375 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
6376 "block nor reference, for DIE 0x%x [in module %s]"),
6377 die
->offset
.sect_off
, objfile
->name
);
6379 call_site
->per_cu
= cu
->per_cu
;
6381 for (child_die
= die
->child
;
6382 child_die
&& child_die
->tag
;
6383 child_die
= sibling_die (child_die
))
6385 struct dwarf2_locexpr_baton
*dlbaton
;
6386 struct call_site_parameter
*parameter
;
6388 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
6390 /* Already printed the complaint above. */
6394 gdb_assert (call_site
->parameter_count
< nparams
);
6395 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
6397 /* DW_AT_location specifies the register number. Value of the data
6398 assumed for the register is contained in DW_AT_GNU_call_site_value. */
6400 attr
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
6401 if (!attr
|| !attr_form_is_block (attr
))
6403 complaint (&symfile_complaints
,
6404 _("No DW_FORM_block* DW_AT_location for "
6405 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6406 child_die
->offset
.sect_off
, objfile
->name
);
6409 parameter
->dwarf_reg
= dwarf_block_to_dwarf_reg (DW_BLOCK (attr
)->data
,
6410 &DW_BLOCK (attr
)->data
[DW_BLOCK (attr
)->size
]);
6411 if (parameter
->dwarf_reg
== -1
6412 && !dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (attr
)->data
,
6413 &DW_BLOCK (attr
)->data
[DW_BLOCK (attr
)->size
],
6414 ¶meter
->fb_offset
))
6416 complaint (&symfile_complaints
,
6417 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
6418 "for DW_FORM_block* DW_AT_location for "
6419 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6420 child_die
->offset
.sect_off
, objfile
->name
);
6424 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
6425 if (!attr_form_is_block (attr
))
6427 complaint (&symfile_complaints
,
6428 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
6429 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6430 child_die
->offset
.sect_off
, objfile
->name
);
6433 parameter
->value
= DW_BLOCK (attr
)->data
;
6434 parameter
->value_size
= DW_BLOCK (attr
)->size
;
6436 /* Parameters are not pre-cleared by memset above. */
6437 parameter
->data_value
= NULL
;
6438 parameter
->data_value_size
= 0;
6439 call_site
->parameter_count
++;
6441 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
6444 if (!attr_form_is_block (attr
))
6445 complaint (&symfile_complaints
,
6446 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
6447 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6448 child_die
->offset
.sect_off
, objfile
->name
);
6451 parameter
->data_value
= DW_BLOCK (attr
)->data
;
6452 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
6458 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
6459 Return 1 if the attributes are present and valid, otherwise, return 0.
6460 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
6463 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
6464 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
6465 struct partial_symtab
*ranges_pst
)
6467 struct objfile
*objfile
= cu
->objfile
;
6468 struct comp_unit_head
*cu_header
= &cu
->header
;
6469 bfd
*obfd
= objfile
->obfd
;
6470 unsigned int addr_size
= cu_header
->addr_size
;
6471 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6472 /* Base address selection entry. */
6483 found_base
= cu
->base_known
;
6484 base
= cu
->base_address
;
6486 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
6487 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6489 complaint (&symfile_complaints
,
6490 _("Offset %d out of bounds for DW_AT_ranges attribute"),
6494 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6496 /* Read in the largest possible address. */
6497 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
6498 if ((marker
& mask
) == mask
)
6500 /* If we found the largest possible address, then
6501 read the base address. */
6502 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
6503 buffer
+= 2 * addr_size
;
6504 offset
+= 2 * addr_size
;
6510 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6514 CORE_ADDR range_beginning
, range_end
;
6516 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
6517 buffer
+= addr_size
;
6518 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
6519 buffer
+= addr_size
;
6520 offset
+= 2 * addr_size
;
6522 /* An end of list marker is a pair of zero addresses. */
6523 if (range_beginning
== 0 && range_end
== 0)
6524 /* Found the end of list entry. */
6527 /* Each base address selection entry is a pair of 2 values.
6528 The first is the largest possible address, the second is
6529 the base address. Check for a base address here. */
6530 if ((range_beginning
& mask
) == mask
)
6532 /* If we found the largest possible address, then
6533 read the base address. */
6534 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
6541 /* We have no valid base address for the ranges
6543 complaint (&symfile_complaints
,
6544 _("Invalid .debug_ranges data (no base address)"));
6548 if (range_beginning
> range_end
)
6550 /* Inverted range entries are invalid. */
6551 complaint (&symfile_complaints
,
6552 _("Invalid .debug_ranges data (inverted range)"));
6556 /* Empty range entries have no effect. */
6557 if (range_beginning
== range_end
)
6560 range_beginning
+= base
;
6563 if (ranges_pst
!= NULL
)
6564 addrmap_set_empty (objfile
->psymtabs_addrmap
,
6565 range_beginning
+ baseaddr
,
6566 range_end
- 1 + baseaddr
,
6569 /* FIXME: This is recording everything as a low-high
6570 segment of consecutive addresses. We should have a
6571 data structure for discontiguous block ranges
6575 low
= range_beginning
;
6581 if (range_beginning
< low
)
6582 low
= range_beginning
;
6583 if (range_end
> high
)
6589 /* If the first entry is an end-of-list marker, the range
6590 describes an empty scope, i.e. no instructions. */
6596 *high_return
= high
;
6600 /* Get low and high pc attributes from a die. Return 1 if the attributes
6601 are present and valid, otherwise, return 0. Return -1 if the range is
6602 discontinuous, i.e. derived from DW_AT_ranges information. */
6604 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
6605 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
6606 struct partial_symtab
*pst
)
6608 struct attribute
*attr
;
6613 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6616 high
= DW_ADDR (attr
);
6617 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6619 low
= DW_ADDR (attr
);
6621 /* Found high w/o low attribute. */
6624 /* Found consecutive range of addresses. */
6629 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6632 /* Value of the DW_AT_ranges attribute is the offset in the
6633 .debug_ranges section. */
6634 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
6636 /* Found discontinuous range of addresses. */
6641 /* read_partial_die has also the strict LOW < HIGH requirement. */
6645 /* When using the GNU linker, .gnu.linkonce. sections are used to
6646 eliminate duplicate copies of functions and vtables and such.
6647 The linker will arbitrarily choose one and discard the others.
6648 The AT_*_pc values for such functions refer to local labels in
6649 these sections. If the section from that file was discarded, the
6650 labels are not in the output, so the relocs get a value of 0.
6651 If this is a discarded function, mark the pc bounds as invalid,
6652 so that GDB will ignore it. */
6653 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
6662 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
6663 its low and high PC addresses. Do nothing if these addresses could not
6664 be determined. Otherwise, set LOWPC to the low address if it is smaller,
6665 and HIGHPC to the high address if greater than HIGHPC. */
6668 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
6669 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6670 struct dwarf2_cu
*cu
)
6672 CORE_ADDR low
, high
;
6673 struct die_info
*child
= die
->child
;
6675 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
6677 *lowpc
= min (*lowpc
, low
);
6678 *highpc
= max (*highpc
, high
);
6681 /* If the language does not allow nested subprograms (either inside
6682 subprograms or lexical blocks), we're done. */
6683 if (cu
->language
!= language_ada
)
6686 /* Check all the children of the given DIE. If it contains nested
6687 subprograms, then check their pc bounds. Likewise, we need to
6688 check lexical blocks as well, as they may also contain subprogram
6690 while (child
&& child
->tag
)
6692 if (child
->tag
== DW_TAG_subprogram
6693 || child
->tag
== DW_TAG_lexical_block
)
6694 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
6695 child
= sibling_die (child
);
6699 /* Get the low and high pc's represented by the scope DIE, and store
6700 them in *LOWPC and *HIGHPC. If the correct values can't be
6701 determined, set *LOWPC to -1 and *HIGHPC to 0. */
6704 get_scope_pc_bounds (struct die_info
*die
,
6705 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6706 struct dwarf2_cu
*cu
)
6708 CORE_ADDR best_low
= (CORE_ADDR
) -1;
6709 CORE_ADDR best_high
= (CORE_ADDR
) 0;
6710 CORE_ADDR current_low
, current_high
;
6712 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
6714 best_low
= current_low
;
6715 best_high
= current_high
;
6719 struct die_info
*child
= die
->child
;
6721 while (child
&& child
->tag
)
6723 switch (child
->tag
) {
6724 case DW_TAG_subprogram
:
6725 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
6727 case DW_TAG_namespace
:
6729 /* FIXME: carlton/2004-01-16: Should we do this for
6730 DW_TAG_class_type/DW_TAG_structure_type, too? I think
6731 that current GCC's always emit the DIEs corresponding
6732 to definitions of methods of classes as children of a
6733 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
6734 the DIEs giving the declarations, which could be
6735 anywhere). But I don't see any reason why the
6736 standards says that they have to be there. */
6737 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
6739 if (current_low
!= ((CORE_ADDR
) -1))
6741 best_low
= min (best_low
, current_low
);
6742 best_high
= max (best_high
, current_high
);
6750 child
= sibling_die (child
);
6755 *highpc
= best_high
;
6758 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
6761 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
6762 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
6764 struct objfile
*objfile
= cu
->objfile
;
6765 struct attribute
*attr
;
6767 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6770 CORE_ADDR high
= DW_ADDR (attr
);
6772 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6775 CORE_ADDR low
= DW_ADDR (attr
);
6777 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
6781 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6784 bfd
*obfd
= objfile
->obfd
;
6786 /* The value of the DW_AT_ranges attribute is the offset of the
6787 address range list in the .debug_ranges section. */
6788 unsigned long offset
= DW_UNSND (attr
);
6789 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6791 /* For some target architectures, but not others, the
6792 read_address function sign-extends the addresses it returns.
6793 To recognize base address selection entries, we need a
6795 unsigned int addr_size
= cu
->header
.addr_size
;
6796 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6798 /* The base address, to which the next pair is relative. Note
6799 that this 'base' is a DWARF concept: most entries in a range
6800 list are relative, to reduce the number of relocs against the
6801 debugging information. This is separate from this function's
6802 'baseaddr' argument, which GDB uses to relocate debugging
6803 information from a shared library based on the address at
6804 which the library was loaded. */
6805 CORE_ADDR base
= cu
->base_address
;
6806 int base_known
= cu
->base_known
;
6808 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
6809 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6811 complaint (&symfile_complaints
,
6812 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
6819 unsigned int bytes_read
;
6820 CORE_ADDR start
, end
;
6822 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6823 buffer
+= bytes_read
;
6824 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6825 buffer
+= bytes_read
;
6827 /* Did we find the end of the range list? */
6828 if (start
== 0 && end
== 0)
6831 /* Did we find a base address selection entry? */
6832 else if ((start
& base_select_mask
) == base_select_mask
)
6838 /* We found an ordinary address range. */
6843 complaint (&symfile_complaints
,
6844 _("Invalid .debug_ranges data "
6845 "(no base address)"));
6851 /* Inverted range entries are invalid. */
6852 complaint (&symfile_complaints
,
6853 _("Invalid .debug_ranges data "
6854 "(inverted range)"));
6858 /* Empty range entries have no effect. */
6862 record_block_range (block
,
6863 baseaddr
+ base
+ start
,
6864 baseaddr
+ base
+ end
- 1);
6870 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
6871 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
6872 during 4.6.0 experimental. */
6875 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
6878 int major
, minor
, release
;
6881 if (cu
->producer
== NULL
)
6883 /* For unknown compilers expect their behavior is DWARF version
6886 GCC started to support .debug_types sections by -gdwarf-4 since
6887 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
6888 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
6889 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
6890 interpreted incorrectly by GDB now - GCC PR debug/48229. */
6895 if (cu
->checked_producer
)
6896 return cu
->producer_is_gxx_lt_4_6
;
6898 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
6900 if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) != 0)
6902 /* For non-GCC compilers expect their behavior is DWARF version
6907 cs
= &cu
->producer
[strlen ("GNU ")];
6908 while (*cs
&& !isdigit (*cs
))
6910 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
6912 /* Not recognized as GCC. */
6915 result
= major
< 4 || (major
== 4 && minor
< 6);
6918 cu
->checked_producer
= 1;
6919 cu
->producer_is_gxx_lt_4_6
= result
;
6924 /* Return the default accessibility type if it is not overriden by
6925 DW_AT_accessibility. */
6927 static enum dwarf_access_attribute
6928 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
6930 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
6932 /* The default DWARF 2 accessibility for members is public, the default
6933 accessibility for inheritance is private. */
6935 if (die
->tag
!= DW_TAG_inheritance
)
6936 return DW_ACCESS_public
;
6938 return DW_ACCESS_private
;
6942 /* DWARF 3+ defines the default accessibility a different way. The same
6943 rules apply now for DW_TAG_inheritance as for the members and it only
6944 depends on the container kind. */
6946 if (die
->parent
->tag
== DW_TAG_class_type
)
6947 return DW_ACCESS_private
;
6949 return DW_ACCESS_public
;
6953 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
6954 offset. If the attribute was not found return 0, otherwise return
6955 1. If it was found but could not properly be handled, set *OFFSET
6959 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
6962 struct attribute
*attr
;
6964 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6969 /* Note that we do not check for a section offset first here.
6970 This is because DW_AT_data_member_location is new in DWARF 4,
6971 so if we see it, we can assume that a constant form is really
6972 a constant and not a section offset. */
6973 if (attr_form_is_constant (attr
))
6974 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
6975 else if (attr_form_is_section_offset (attr
))
6976 dwarf2_complex_location_expr_complaint ();
6977 else if (attr_form_is_block (attr
))
6978 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6980 dwarf2_complex_location_expr_complaint ();
6988 /* Add an aggregate field to the field list. */
6991 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
6992 struct dwarf2_cu
*cu
)
6994 struct objfile
*objfile
= cu
->objfile
;
6995 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6996 struct nextfield
*new_field
;
6997 struct attribute
*attr
;
6999 char *fieldname
= "";
7001 /* Allocate a new field list entry and link it in. */
7002 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
7003 make_cleanup (xfree
, new_field
);
7004 memset (new_field
, 0, sizeof (struct nextfield
));
7006 if (die
->tag
== DW_TAG_inheritance
)
7008 new_field
->next
= fip
->baseclasses
;
7009 fip
->baseclasses
= new_field
;
7013 new_field
->next
= fip
->fields
;
7014 fip
->fields
= new_field
;
7018 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
7020 new_field
->accessibility
= DW_UNSND (attr
);
7022 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
7023 if (new_field
->accessibility
!= DW_ACCESS_public
)
7024 fip
->non_public_fields
= 1;
7026 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
7028 new_field
->virtuality
= DW_UNSND (attr
);
7030 new_field
->virtuality
= DW_VIRTUALITY_none
;
7032 fp
= &new_field
->field
;
7034 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
7038 /* Data member other than a C++ static data member. */
7040 /* Get type of field. */
7041 fp
->type
= die_type (die
, cu
);
7043 SET_FIELD_BITPOS (*fp
, 0);
7045 /* Get bit size of field (zero if none). */
7046 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
7049 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
7053 FIELD_BITSIZE (*fp
) = 0;
7056 /* Get bit offset of field. */
7057 if (handle_data_member_location (die
, cu
, &offset
))
7058 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
7059 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
7062 if (gdbarch_bits_big_endian (gdbarch
))
7064 /* For big endian bits, the DW_AT_bit_offset gives the
7065 additional bit offset from the MSB of the containing
7066 anonymous object to the MSB of the field. We don't
7067 have to do anything special since we don't need to
7068 know the size of the anonymous object. */
7069 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
7073 /* For little endian bits, compute the bit offset to the
7074 MSB of the anonymous object, subtract off the number of
7075 bits from the MSB of the field to the MSB of the
7076 object, and then subtract off the number of bits of
7077 the field itself. The result is the bit offset of
7078 the LSB of the field. */
7080 int bit_offset
= DW_UNSND (attr
);
7082 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7085 /* The size of the anonymous object containing
7086 the bit field is explicit, so use the
7087 indicated size (in bytes). */
7088 anonymous_size
= DW_UNSND (attr
);
7092 /* The size of the anonymous object containing
7093 the bit field must be inferred from the type
7094 attribute of the data member containing the
7096 anonymous_size
= TYPE_LENGTH (fp
->type
);
7098 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
7099 - bit_offset
- FIELD_BITSIZE (*fp
);
7103 /* Get name of field. */
7104 fieldname
= dwarf2_name (die
, cu
);
7105 if (fieldname
== NULL
)
7108 /* The name is already allocated along with this objfile, so we don't
7109 need to duplicate it for the type. */
7110 fp
->name
= fieldname
;
7112 /* Change accessibility for artificial fields (e.g. virtual table
7113 pointer or virtual base class pointer) to private. */
7114 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
7116 FIELD_ARTIFICIAL (*fp
) = 1;
7117 new_field
->accessibility
= DW_ACCESS_private
;
7118 fip
->non_public_fields
= 1;
7121 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
7123 /* C++ static member. */
7125 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
7126 is a declaration, but all versions of G++ as of this writing
7127 (so through at least 3.2.1) incorrectly generate
7128 DW_TAG_variable tags. */
7130 const char *physname
;
7132 /* Get name of field. */
7133 fieldname
= dwarf2_name (die
, cu
);
7134 if (fieldname
== NULL
)
7137 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7139 /* Only create a symbol if this is an external value.
7140 new_symbol checks this and puts the value in the global symbol
7141 table, which we want. If it is not external, new_symbol
7142 will try to put the value in cu->list_in_scope which is wrong. */
7143 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
7145 /* A static const member, not much different than an enum as far as
7146 we're concerned, except that we can support more types. */
7147 new_symbol (die
, NULL
, cu
);
7150 /* Get physical name. */
7151 physname
= dwarf2_physname (fieldname
, die
, cu
);
7153 /* The name is already allocated along with this objfile, so we don't
7154 need to duplicate it for the type. */
7155 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
7156 FIELD_TYPE (*fp
) = die_type (die
, cu
);
7157 FIELD_NAME (*fp
) = fieldname
;
7159 else if (die
->tag
== DW_TAG_inheritance
)
7163 /* C++ base class field. */
7164 if (handle_data_member_location (die
, cu
, &offset
))
7165 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
7166 FIELD_BITSIZE (*fp
) = 0;
7167 FIELD_TYPE (*fp
) = die_type (die
, cu
);
7168 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
7169 fip
->nbaseclasses
++;
7173 /* Add a typedef defined in the scope of the FIP's class. */
7176 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
7177 struct dwarf2_cu
*cu
)
7179 struct objfile
*objfile
= cu
->objfile
;
7180 struct typedef_field_list
*new_field
;
7181 struct attribute
*attr
;
7182 struct typedef_field
*fp
;
7183 char *fieldname
= "";
7185 /* Allocate a new field list entry and link it in. */
7186 new_field
= xzalloc (sizeof (*new_field
));
7187 make_cleanup (xfree
, new_field
);
7189 gdb_assert (die
->tag
== DW_TAG_typedef
);
7191 fp
= &new_field
->field
;
7193 /* Get name of field. */
7194 fp
->name
= dwarf2_name (die
, cu
);
7195 if (fp
->name
== NULL
)
7198 fp
->type
= read_type_die (die
, cu
);
7200 new_field
->next
= fip
->typedef_field_list
;
7201 fip
->typedef_field_list
= new_field
;
7202 fip
->typedef_field_list_count
++;
7205 /* Create the vector of fields, and attach it to the type. */
7208 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
7209 struct dwarf2_cu
*cu
)
7211 int nfields
= fip
->nfields
;
7213 /* Record the field count, allocate space for the array of fields,
7214 and create blank accessibility bitfields if necessary. */
7215 TYPE_NFIELDS (type
) = nfields
;
7216 TYPE_FIELDS (type
) = (struct field
*)
7217 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
7218 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
7220 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
7222 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7224 TYPE_FIELD_PRIVATE_BITS (type
) =
7225 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7226 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
7228 TYPE_FIELD_PROTECTED_BITS (type
) =
7229 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7230 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
7232 TYPE_FIELD_IGNORE_BITS (type
) =
7233 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7234 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
7237 /* If the type has baseclasses, allocate and clear a bit vector for
7238 TYPE_FIELD_VIRTUAL_BITS. */
7239 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
7241 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
7242 unsigned char *pointer
;
7244 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7245 pointer
= TYPE_ALLOC (type
, num_bytes
);
7246 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
7247 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
7248 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
7251 /* Copy the saved-up fields into the field vector. Start from the head of
7252 the list, adding to the tail of the field array, so that they end up in
7253 the same order in the array in which they were added to the list. */
7254 while (nfields
-- > 0)
7256 struct nextfield
*fieldp
;
7260 fieldp
= fip
->fields
;
7261 fip
->fields
= fieldp
->next
;
7265 fieldp
= fip
->baseclasses
;
7266 fip
->baseclasses
= fieldp
->next
;
7269 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
7270 switch (fieldp
->accessibility
)
7272 case DW_ACCESS_private
:
7273 if (cu
->language
!= language_ada
)
7274 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
7277 case DW_ACCESS_protected
:
7278 if (cu
->language
!= language_ada
)
7279 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
7282 case DW_ACCESS_public
:
7286 /* Unknown accessibility. Complain and treat it as public. */
7288 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
7289 fieldp
->accessibility
);
7293 if (nfields
< fip
->nbaseclasses
)
7295 switch (fieldp
->virtuality
)
7297 case DW_VIRTUALITY_virtual
:
7298 case DW_VIRTUALITY_pure_virtual
:
7299 if (cu
->language
== language_ada
)
7300 error (_("unexpected virtuality in component of Ada type"));
7301 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
7308 /* Add a member function to the proper fieldlist. */
7311 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
7312 struct type
*type
, struct dwarf2_cu
*cu
)
7314 struct objfile
*objfile
= cu
->objfile
;
7315 struct attribute
*attr
;
7316 struct fnfieldlist
*flp
;
7318 struct fn_field
*fnp
;
7320 struct nextfnfield
*new_fnfield
;
7321 struct type
*this_type
;
7322 enum dwarf_access_attribute accessibility
;
7324 if (cu
->language
== language_ada
)
7325 error (_("unexpected member function in Ada type"));
7327 /* Get name of member function. */
7328 fieldname
= dwarf2_name (die
, cu
);
7329 if (fieldname
== NULL
)
7332 /* Look up member function name in fieldlist. */
7333 for (i
= 0; i
< fip
->nfnfields
; i
++)
7335 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
7339 /* Create new list element if necessary. */
7340 if (i
< fip
->nfnfields
)
7341 flp
= &fip
->fnfieldlists
[i
];
7344 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7346 fip
->fnfieldlists
= (struct fnfieldlist
*)
7347 xrealloc (fip
->fnfieldlists
,
7348 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
7349 * sizeof (struct fnfieldlist
));
7350 if (fip
->nfnfields
== 0)
7351 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
7353 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
7354 flp
->name
= fieldname
;
7357 i
= fip
->nfnfields
++;
7360 /* Create a new member function field and chain it to the field list
7362 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
7363 make_cleanup (xfree
, new_fnfield
);
7364 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
7365 new_fnfield
->next
= flp
->head
;
7366 flp
->head
= new_fnfield
;
7369 /* Fill in the member function field info. */
7370 fnp
= &new_fnfield
->fnfield
;
7372 /* Delay processing of the physname until later. */
7373 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
7375 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
7380 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
7381 fnp
->physname
= physname
? physname
: "";
7384 fnp
->type
= alloc_type (objfile
);
7385 this_type
= read_type_die (die
, cu
);
7386 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
7388 int nparams
= TYPE_NFIELDS (this_type
);
7390 /* TYPE is the domain of this method, and THIS_TYPE is the type
7391 of the method itself (TYPE_CODE_METHOD). */
7392 smash_to_method_type (fnp
->type
, type
,
7393 TYPE_TARGET_TYPE (this_type
),
7394 TYPE_FIELDS (this_type
),
7395 TYPE_NFIELDS (this_type
),
7396 TYPE_VARARGS (this_type
));
7398 /* Handle static member functions.
7399 Dwarf2 has no clean way to discern C++ static and non-static
7400 member functions. G++ helps GDB by marking the first
7401 parameter for non-static member functions (which is the this
7402 pointer) as artificial. We obtain this information from
7403 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
7404 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
7405 fnp
->voffset
= VOFFSET_STATIC
;
7408 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
7409 dwarf2_full_name (fieldname
, die
, cu
));
7411 /* Get fcontext from DW_AT_containing_type if present. */
7412 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7413 fnp
->fcontext
= die_containing_type (die
, cu
);
7415 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
7416 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
7418 /* Get accessibility. */
7419 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
7421 accessibility
= DW_UNSND (attr
);
7423 accessibility
= dwarf2_default_access_attribute (die
, cu
);
7424 switch (accessibility
)
7426 case DW_ACCESS_private
:
7427 fnp
->is_private
= 1;
7429 case DW_ACCESS_protected
:
7430 fnp
->is_protected
= 1;
7434 /* Check for artificial methods. */
7435 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
7436 if (attr
&& DW_UNSND (attr
) != 0)
7437 fnp
->is_artificial
= 1;
7439 /* Get index in virtual function table if it is a virtual member
7440 function. For older versions of GCC, this is an offset in the
7441 appropriate virtual table, as specified by DW_AT_containing_type.
7442 For everyone else, it is an expression to be evaluated relative
7443 to the object address. */
7445 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
7448 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
7450 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
7452 /* Old-style GCC. */
7453 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
7455 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
7456 || (DW_BLOCK (attr
)->size
> 1
7457 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
7458 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
7460 struct dwarf_block blk
;
7463 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
7465 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
7466 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
7467 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
7468 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
7469 dwarf2_complex_location_expr_complaint ();
7471 fnp
->voffset
/= cu
->header
.addr_size
;
7475 dwarf2_complex_location_expr_complaint ();
7478 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
7480 else if (attr_form_is_section_offset (attr
))
7482 dwarf2_complex_location_expr_complaint ();
7486 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
7492 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
7493 if (attr
&& DW_UNSND (attr
))
7495 /* GCC does this, as of 2008-08-25; PR debug/37237. */
7496 complaint (&symfile_complaints
,
7497 _("Member function \"%s\" (offset %d) is virtual "
7498 "but the vtable offset is not specified"),
7499 fieldname
, die
->offset
.sect_off
);
7500 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7501 TYPE_CPLUS_DYNAMIC (type
) = 1;
7506 /* Create the vector of member function fields, and attach it to the type. */
7509 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
7510 struct dwarf2_cu
*cu
)
7512 struct fnfieldlist
*flp
;
7515 if (cu
->language
== language_ada
)
7516 error (_("unexpected member functions in Ada type"));
7518 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7519 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
7520 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
7522 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
7524 struct nextfnfield
*nfp
= flp
->head
;
7525 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
7528 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
7529 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
7530 fn_flp
->fn_fields
= (struct fn_field
*)
7531 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
7532 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
7533 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
7536 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
7539 /* Returns non-zero if NAME is the name of a vtable member in CU's
7540 language, zero otherwise. */
7542 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
7544 static const char vptr
[] = "_vptr";
7545 static const char vtable
[] = "vtable";
7547 /* Look for the C++ and Java forms of the vtable. */
7548 if ((cu
->language
== language_java
7549 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
7550 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
7551 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
7557 /* GCC outputs unnamed structures that are really pointers to member
7558 functions, with the ABI-specified layout. If TYPE describes
7559 such a structure, smash it into a member function type.
7561 GCC shouldn't do this; it should just output pointer to member DIEs.
7562 This is GCC PR debug/28767. */
7565 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
7567 struct type
*pfn_type
, *domain_type
, *new_type
;
7569 /* Check for a structure with no name and two children. */
7570 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
7573 /* Check for __pfn and __delta members. */
7574 if (TYPE_FIELD_NAME (type
, 0) == NULL
7575 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
7576 || TYPE_FIELD_NAME (type
, 1) == NULL
7577 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
7580 /* Find the type of the method. */
7581 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
7582 if (pfn_type
== NULL
7583 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
7584 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
7587 /* Look for the "this" argument. */
7588 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
7589 if (TYPE_NFIELDS (pfn_type
) == 0
7590 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
7591 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
7594 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
7595 new_type
= alloc_type (objfile
);
7596 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
7597 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
7598 TYPE_VARARGS (pfn_type
));
7599 smash_to_methodptr_type (type
, new_type
);
7602 /* Called when we find the DIE that starts a structure or union scope
7603 (definition) to create a type for the structure or union. Fill in
7604 the type's name and general properties; the members will not be
7605 processed until process_structure_type.
7607 NOTE: we need to call these functions regardless of whether or not the
7608 DIE has a DW_AT_name attribute, since it might be an anonymous
7609 structure or union. This gets the type entered into our set of
7612 However, if the structure is incomplete (an opaque struct/union)
7613 then suppress creating a symbol table entry for it since gdb only
7614 wants to find the one with the complete definition. Note that if
7615 it is complete, we just call new_symbol, which does it's own
7616 checking about whether the struct/union is anonymous or not (and
7617 suppresses creating a symbol table entry itself). */
7619 static struct type
*
7620 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7622 struct objfile
*objfile
= cu
->objfile
;
7624 struct attribute
*attr
;
7627 /* If the definition of this type lives in .debug_types, read that type.
7628 Don't follow DW_AT_specification though, that will take us back up
7629 the chain and we want to go down. */
7630 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7633 struct dwarf2_cu
*type_cu
= cu
;
7634 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7636 /* We could just recurse on read_structure_type, but we need to call
7637 get_die_type to ensure only one type for this DIE is created.
7638 This is important, for example, because for c++ classes we need
7639 TYPE_NAME set which is only done by new_symbol. Blech. */
7640 type
= read_type_die (type_die
, type_cu
);
7642 /* TYPE_CU may not be the same as CU.
7643 Ensure TYPE is recorded in CU's type_hash table. */
7644 return set_die_type (die
, type
, cu
);
7647 type
= alloc_type (objfile
);
7648 INIT_CPLUS_SPECIFIC (type
);
7650 name
= dwarf2_name (die
, cu
);
7653 if (cu
->language
== language_cplus
7654 || cu
->language
== language_java
)
7656 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
7658 /* dwarf2_full_name might have already finished building the DIE's
7659 type. If so, there is no need to continue. */
7660 if (get_die_type (die
, cu
) != NULL
)
7661 return get_die_type (die
, cu
);
7663 TYPE_TAG_NAME (type
) = full_name
;
7664 if (die
->tag
== DW_TAG_structure_type
7665 || die
->tag
== DW_TAG_class_type
)
7666 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7670 /* The name is already allocated along with this objfile, so
7671 we don't need to duplicate it for the type. */
7672 TYPE_TAG_NAME (type
) = (char *) name
;
7673 if (die
->tag
== DW_TAG_class_type
)
7674 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7678 if (die
->tag
== DW_TAG_structure_type
)
7680 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
7682 else if (die
->tag
== DW_TAG_union_type
)
7684 TYPE_CODE (type
) = TYPE_CODE_UNION
;
7688 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
7691 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
7692 TYPE_DECLARED_CLASS (type
) = 1;
7694 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7697 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7701 TYPE_LENGTH (type
) = 0;
7704 TYPE_STUB_SUPPORTED (type
) = 1;
7705 if (die_is_declaration (die
, cu
))
7706 TYPE_STUB (type
) = 1;
7707 else if (attr
== NULL
&& die
->child
== NULL
7708 && producer_is_realview (cu
->producer
))
7709 /* RealView does not output the required DW_AT_declaration
7710 on incomplete types. */
7711 TYPE_STUB (type
) = 1;
7713 /* We need to add the type field to the die immediately so we don't
7714 infinitely recurse when dealing with pointers to the structure
7715 type within the structure itself. */
7716 set_die_type (die
, type
, cu
);
7718 /* set_die_type should be already done. */
7719 set_descriptive_type (type
, die
, cu
);
7724 /* Finish creating a structure or union type, including filling in
7725 its members and creating a symbol for it. */
7728 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7730 struct objfile
*objfile
= cu
->objfile
;
7731 struct die_info
*child_die
= die
->child
;
7734 type
= get_die_type (die
, cu
);
7736 type
= read_structure_type (die
, cu
);
7738 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
7740 struct field_info fi
;
7741 struct die_info
*child_die
;
7742 VEC (symbolp
) *template_args
= NULL
;
7743 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
7745 memset (&fi
, 0, sizeof (struct field_info
));
7747 child_die
= die
->child
;
7749 while (child_die
&& child_die
->tag
)
7751 if (child_die
->tag
== DW_TAG_member
7752 || child_die
->tag
== DW_TAG_variable
)
7754 /* NOTE: carlton/2002-11-05: A C++ static data member
7755 should be a DW_TAG_member that is a declaration, but
7756 all versions of G++ as of this writing (so through at
7757 least 3.2.1) incorrectly generate DW_TAG_variable
7758 tags for them instead. */
7759 dwarf2_add_field (&fi
, child_die
, cu
);
7761 else if (child_die
->tag
== DW_TAG_subprogram
)
7763 /* C++ member function. */
7764 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
7766 else if (child_die
->tag
== DW_TAG_inheritance
)
7768 /* C++ base class field. */
7769 dwarf2_add_field (&fi
, child_die
, cu
);
7771 else if (child_die
->tag
== DW_TAG_typedef
)
7772 dwarf2_add_typedef (&fi
, child_die
, cu
);
7773 else if (child_die
->tag
== DW_TAG_template_type_param
7774 || child_die
->tag
== DW_TAG_template_value_param
)
7776 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
7779 VEC_safe_push (symbolp
, template_args
, arg
);
7782 child_die
= sibling_die (child_die
);
7785 /* Attach template arguments to type. */
7786 if (! VEC_empty (symbolp
, template_args
))
7788 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7789 TYPE_N_TEMPLATE_ARGUMENTS (type
)
7790 = VEC_length (symbolp
, template_args
);
7791 TYPE_TEMPLATE_ARGUMENTS (type
)
7792 = obstack_alloc (&objfile
->objfile_obstack
,
7793 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7794 * sizeof (struct symbol
*)));
7795 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
7796 VEC_address (symbolp
, template_args
),
7797 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7798 * sizeof (struct symbol
*)));
7799 VEC_free (symbolp
, template_args
);
7802 /* Attach fields and member functions to the type. */
7804 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
7807 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
7809 /* Get the type which refers to the base class (possibly this
7810 class itself) which contains the vtable pointer for the current
7811 class from the DW_AT_containing_type attribute. This use of
7812 DW_AT_containing_type is a GNU extension. */
7814 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7816 struct type
*t
= die_containing_type (die
, cu
);
7818 TYPE_VPTR_BASETYPE (type
) = t
;
7823 /* Our own class provides vtbl ptr. */
7824 for (i
= TYPE_NFIELDS (t
) - 1;
7825 i
>= TYPE_N_BASECLASSES (t
);
7828 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
7830 if (is_vtable_name (fieldname
, cu
))
7832 TYPE_VPTR_FIELDNO (type
) = i
;
7837 /* Complain if virtual function table field not found. */
7838 if (i
< TYPE_N_BASECLASSES (t
))
7839 complaint (&symfile_complaints
,
7840 _("virtual function table pointer "
7841 "not found when defining class '%s'"),
7842 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
7847 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
7850 else if (cu
->producer
7851 && strncmp (cu
->producer
,
7852 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
7854 /* The IBM XLC compiler does not provide direct indication
7855 of the containing type, but the vtable pointer is
7856 always named __vfp. */
7860 for (i
= TYPE_NFIELDS (type
) - 1;
7861 i
>= TYPE_N_BASECLASSES (type
);
7864 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
7866 TYPE_VPTR_FIELDNO (type
) = i
;
7867 TYPE_VPTR_BASETYPE (type
) = type
;
7874 /* Copy fi.typedef_field_list linked list elements content into the
7875 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
7876 if (fi
.typedef_field_list
)
7878 int i
= fi
.typedef_field_list_count
;
7880 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7881 TYPE_TYPEDEF_FIELD_ARRAY (type
)
7882 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
7883 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
7885 /* Reverse the list order to keep the debug info elements order. */
7888 struct typedef_field
*dest
, *src
;
7890 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
7891 src
= &fi
.typedef_field_list
->field
;
7892 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
7897 do_cleanups (back_to
);
7899 if (HAVE_CPLUS_STRUCT (type
))
7900 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
7903 quirk_gcc_member_function_pointer (type
, objfile
);
7905 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
7906 snapshots) has been known to create a die giving a declaration
7907 for a class that has, as a child, a die giving a definition for a
7908 nested class. So we have to process our children even if the
7909 current die is a declaration. Normally, of course, a declaration
7910 won't have any children at all. */
7912 while (child_die
!= NULL
&& child_die
->tag
)
7914 if (child_die
->tag
== DW_TAG_member
7915 || child_die
->tag
== DW_TAG_variable
7916 || child_die
->tag
== DW_TAG_inheritance
7917 || child_die
->tag
== DW_TAG_template_value_param
7918 || child_die
->tag
== DW_TAG_template_type_param
)
7923 process_die (child_die
, cu
);
7925 child_die
= sibling_die (child_die
);
7928 /* Do not consider external references. According to the DWARF standard,
7929 these DIEs are identified by the fact that they have no byte_size
7930 attribute, and a declaration attribute. */
7931 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
7932 || !die_is_declaration (die
, cu
))
7933 new_symbol (die
, type
, cu
);
7936 /* Given a DW_AT_enumeration_type die, set its type. We do not
7937 complete the type's fields yet, or create any symbols. */
7939 static struct type
*
7940 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7942 struct objfile
*objfile
= cu
->objfile
;
7944 struct attribute
*attr
;
7947 /* If the definition of this type lives in .debug_types, read that type.
7948 Don't follow DW_AT_specification though, that will take us back up
7949 the chain and we want to go down. */
7950 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7953 struct dwarf2_cu
*type_cu
= cu
;
7954 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7956 type
= read_type_die (type_die
, type_cu
);
7958 /* TYPE_CU may not be the same as CU.
7959 Ensure TYPE is recorded in CU's type_hash table. */
7960 return set_die_type (die
, type
, cu
);
7963 type
= alloc_type (objfile
);
7965 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
7966 name
= dwarf2_full_name (NULL
, die
, cu
);
7968 TYPE_TAG_NAME (type
) = (char *) name
;
7970 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7973 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7977 TYPE_LENGTH (type
) = 0;
7980 /* The enumeration DIE can be incomplete. In Ada, any type can be
7981 declared as private in the package spec, and then defined only
7982 inside the package body. Such types are known as Taft Amendment
7983 Types. When another package uses such a type, an incomplete DIE
7984 may be generated by the compiler. */
7985 if (die_is_declaration (die
, cu
))
7986 TYPE_STUB (type
) = 1;
7988 return set_die_type (die
, type
, cu
);
7991 /* Given a pointer to a die which begins an enumeration, process all
7992 the dies that define the members of the enumeration, and create the
7993 symbol for the enumeration type.
7995 NOTE: We reverse the order of the element list. */
7998 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8000 struct type
*this_type
;
8002 this_type
= get_die_type (die
, cu
);
8003 if (this_type
== NULL
)
8004 this_type
= read_enumeration_type (die
, cu
);
8006 if (die
->child
!= NULL
)
8008 struct die_info
*child_die
;
8010 struct field
*fields
= NULL
;
8012 int unsigned_enum
= 1;
8017 child_die
= die
->child
;
8018 while (child_die
&& child_die
->tag
)
8020 if (child_die
->tag
!= DW_TAG_enumerator
)
8022 process_die (child_die
, cu
);
8026 name
= dwarf2_name (child_die
, cu
);
8029 sym
= new_symbol (child_die
, this_type
, cu
);
8030 if (SYMBOL_VALUE (sym
) < 0)
8035 else if ((mask
& SYMBOL_VALUE (sym
)) != 0)
8038 mask
|= SYMBOL_VALUE (sym
);
8040 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
8042 fields
= (struct field
*)
8044 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
8045 * sizeof (struct field
));
8048 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
8049 FIELD_TYPE (fields
[num_fields
]) = NULL
;
8050 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
8051 FIELD_BITSIZE (fields
[num_fields
]) = 0;
8057 child_die
= sibling_die (child_die
);
8062 TYPE_NFIELDS (this_type
) = num_fields
;
8063 TYPE_FIELDS (this_type
) = (struct field
*)
8064 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
8065 memcpy (TYPE_FIELDS (this_type
), fields
,
8066 sizeof (struct field
) * num_fields
);
8070 TYPE_UNSIGNED (this_type
) = 1;
8072 TYPE_FLAG_ENUM (this_type
) = 1;
8075 /* If we are reading an enum from a .debug_types unit, and the enum
8076 is a declaration, and the enum is not the signatured type in the
8077 unit, then we do not want to add a symbol for it. Adding a
8078 symbol would in some cases obscure the true definition of the
8079 enum, giving users an incomplete type when the definition is
8080 actually available. Note that we do not want to do this for all
8081 enums which are just declarations, because C++0x allows forward
8082 enum declarations. */
8083 if (cu
->per_cu
->debug_types_section
8084 && die_is_declaration (die
, cu
))
8086 struct signatured_type
*sig_type
;
8089 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
8090 cu
->per_cu
->debug_types_section
,
8091 cu
->per_cu
->offset
);
8092 if (sig_type
->per_cu
.offset
.sect_off
+ sig_type
->type_offset
.cu_off
8093 != die
->offset
.sect_off
)
8097 new_symbol (die
, this_type
, cu
);
8100 /* Extract all information from a DW_TAG_array_type DIE and put it in
8101 the DIE's type field. For now, this only handles one dimensional
8104 static struct type
*
8105 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8107 struct objfile
*objfile
= cu
->objfile
;
8108 struct die_info
*child_die
;
8110 struct type
*element_type
, *range_type
, *index_type
;
8111 struct type
**range_types
= NULL
;
8112 struct attribute
*attr
;
8114 struct cleanup
*back_to
;
8117 element_type
= die_type (die
, cu
);
8119 /* The die_type call above may have already set the type for this DIE. */
8120 type
= get_die_type (die
, cu
);
8124 /* Irix 6.2 native cc creates array types without children for
8125 arrays with unspecified length. */
8126 if (die
->child
== NULL
)
8128 index_type
= objfile_type (objfile
)->builtin_int
;
8129 range_type
= create_range_type (NULL
, index_type
, 0, -1);
8130 type
= create_array_type (NULL
, element_type
, range_type
);
8131 return set_die_type (die
, type
, cu
);
8134 back_to
= make_cleanup (null_cleanup
, NULL
);
8135 child_die
= die
->child
;
8136 while (child_die
&& child_die
->tag
)
8138 if (child_die
->tag
== DW_TAG_subrange_type
)
8140 struct type
*child_type
= read_type_die (child_die
, cu
);
8142 if (child_type
!= NULL
)
8144 /* The range type was succesfully read. Save it for the
8145 array type creation. */
8146 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
8148 range_types
= (struct type
**)
8149 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
8150 * sizeof (struct type
*));
8152 make_cleanup (free_current_contents
, &range_types
);
8154 range_types
[ndim
++] = child_type
;
8157 child_die
= sibling_die (child_die
);
8160 /* Dwarf2 dimensions are output from left to right, create the
8161 necessary array types in backwards order. */
8163 type
= element_type
;
8165 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
8170 type
= create_array_type (NULL
, type
, range_types
[i
++]);
8175 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
8178 /* Understand Dwarf2 support for vector types (like they occur on
8179 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
8180 array type. This is not part of the Dwarf2/3 standard yet, but a
8181 custom vendor extension. The main difference between a regular
8182 array and the vector variant is that vectors are passed by value
8184 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
8186 make_vector_type (type
);
8188 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
8189 implementation may choose to implement triple vectors using this
8191 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8194 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
8195 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8197 complaint (&symfile_complaints
,
8198 _("DW_AT_byte_size for array type smaller "
8199 "than the total size of elements"));
8202 name
= dwarf2_name (die
, cu
);
8204 TYPE_NAME (type
) = name
;
8206 /* Install the type in the die. */
8207 set_die_type (die
, type
, cu
);
8209 /* set_die_type should be already done. */
8210 set_descriptive_type (type
, die
, cu
);
8212 do_cleanups (back_to
);
8217 static enum dwarf_array_dim_ordering
8218 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
8220 struct attribute
*attr
;
8222 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
8224 if (attr
) return DW_SND (attr
);
8226 /* GNU F77 is a special case, as at 08/2004 array type info is the
8227 opposite order to the dwarf2 specification, but data is still
8228 laid out as per normal fortran.
8230 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
8231 version checking. */
8233 if (cu
->language
== language_fortran
8234 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
8236 return DW_ORD_row_major
;
8239 switch (cu
->language_defn
->la_array_ordering
)
8241 case array_column_major
:
8242 return DW_ORD_col_major
;
8243 case array_row_major
:
8245 return DW_ORD_row_major
;
8249 /* Extract all information from a DW_TAG_set_type DIE and put it in
8250 the DIE's type field. */
8252 static struct type
*
8253 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8255 struct type
*domain_type
, *set_type
;
8256 struct attribute
*attr
;
8258 domain_type
= die_type (die
, cu
);
8260 /* The die_type call above may have already set the type for this DIE. */
8261 set_type
= get_die_type (die
, cu
);
8265 set_type
= create_set_type (NULL
, domain_type
);
8267 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8269 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
8271 return set_die_type (die
, set_type
, cu
);
8274 /* First cut: install each common block member as a global variable. */
8277 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
8279 struct die_info
*child_die
;
8280 struct attribute
*attr
;
8282 CORE_ADDR base
= (CORE_ADDR
) 0;
8284 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
8287 /* Support the .debug_loc offsets. */
8288 if (attr_form_is_block (attr
))
8290 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
8292 else if (attr_form_is_section_offset (attr
))
8294 dwarf2_complex_location_expr_complaint ();
8298 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
8299 "common block member");
8302 if (die
->child
!= NULL
)
8304 child_die
= die
->child
;
8305 while (child_die
&& child_die
->tag
)
8309 sym
= new_symbol (child_die
, NULL
, cu
);
8311 && handle_data_member_location (child_die
, cu
, &offset
))
8313 SYMBOL_VALUE_ADDRESS (sym
) = base
+ offset
;
8314 add_symbol_to_list (sym
, &global_symbols
);
8316 child_die
= sibling_die (child_die
);
8321 /* Create a type for a C++ namespace. */
8323 static struct type
*
8324 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8326 struct objfile
*objfile
= cu
->objfile
;
8327 const char *previous_prefix
, *name
;
8331 /* For extensions, reuse the type of the original namespace. */
8332 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
8334 struct die_info
*ext_die
;
8335 struct dwarf2_cu
*ext_cu
= cu
;
8337 ext_die
= dwarf2_extension (die
, &ext_cu
);
8338 type
= read_type_die (ext_die
, ext_cu
);
8340 /* EXT_CU may not be the same as CU.
8341 Ensure TYPE is recorded in CU's type_hash table. */
8342 return set_die_type (die
, type
, cu
);
8345 name
= namespace_name (die
, &is_anonymous
, cu
);
8347 /* Now build the name of the current namespace. */
8349 previous_prefix
= determine_prefix (die
, cu
);
8350 if (previous_prefix
[0] != '\0')
8351 name
= typename_concat (&objfile
->objfile_obstack
,
8352 previous_prefix
, name
, 0, cu
);
8354 /* Create the type. */
8355 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
8357 TYPE_NAME (type
) = (char *) name
;
8358 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8360 return set_die_type (die
, type
, cu
);
8363 /* Read a C++ namespace. */
8366 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
8368 struct objfile
*objfile
= cu
->objfile
;
8371 /* Add a symbol associated to this if we haven't seen the namespace
8372 before. Also, add a using directive if it's an anonymous
8375 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
8379 type
= read_type_die (die
, cu
);
8380 new_symbol (die
, type
, cu
);
8382 namespace_name (die
, &is_anonymous
, cu
);
8385 const char *previous_prefix
= determine_prefix (die
, cu
);
8387 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
8388 NULL
, NULL
, &objfile
->objfile_obstack
);
8392 if (die
->child
!= NULL
)
8394 struct die_info
*child_die
= die
->child
;
8396 while (child_die
&& child_die
->tag
)
8398 process_die (child_die
, cu
);
8399 child_die
= sibling_die (child_die
);
8404 /* Read a Fortran module as type. This DIE can be only a declaration used for
8405 imported module. Still we need that type as local Fortran "use ... only"
8406 declaration imports depend on the created type in determine_prefix. */
8408 static struct type
*
8409 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8411 struct objfile
*objfile
= cu
->objfile
;
8415 module_name
= dwarf2_name (die
, cu
);
8417 complaint (&symfile_complaints
,
8418 _("DW_TAG_module has no name, offset 0x%x"),
8419 die
->offset
.sect_off
);
8420 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
8422 /* determine_prefix uses TYPE_TAG_NAME. */
8423 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8425 return set_die_type (die
, type
, cu
);
8428 /* Read a Fortran module. */
8431 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
8433 struct die_info
*child_die
= die
->child
;
8435 while (child_die
&& child_die
->tag
)
8437 process_die (child_die
, cu
);
8438 child_die
= sibling_die (child_die
);
8442 /* Return the name of the namespace represented by DIE. Set
8443 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
8447 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
8449 struct die_info
*current_die
;
8450 const char *name
= NULL
;
8452 /* Loop through the extensions until we find a name. */
8454 for (current_die
= die
;
8455 current_die
!= NULL
;
8456 current_die
= dwarf2_extension (die
, &cu
))
8458 name
= dwarf2_name (current_die
, cu
);
8463 /* Is it an anonymous namespace? */
8465 *is_anonymous
= (name
== NULL
);
8467 name
= CP_ANONYMOUS_NAMESPACE_STR
;
8472 /* Extract all information from a DW_TAG_pointer_type DIE and add to
8473 the user defined type vector. */
8475 static struct type
*
8476 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8478 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
8479 struct comp_unit_head
*cu_header
= &cu
->header
;
8481 struct attribute
*attr_byte_size
;
8482 struct attribute
*attr_address_class
;
8483 int byte_size
, addr_class
;
8484 struct type
*target_type
;
8486 target_type
= die_type (die
, cu
);
8488 /* The die_type call above may have already set the type for this DIE. */
8489 type
= get_die_type (die
, cu
);
8493 type
= lookup_pointer_type (target_type
);
8495 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8497 byte_size
= DW_UNSND (attr_byte_size
);
8499 byte_size
= cu_header
->addr_size
;
8501 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
8502 if (attr_address_class
)
8503 addr_class
= DW_UNSND (attr_address_class
);
8505 addr_class
= DW_ADDR_none
;
8507 /* If the pointer size or address class is different than the
8508 default, create a type variant marked as such and set the
8509 length accordingly. */
8510 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
8512 if (gdbarch_address_class_type_flags_p (gdbarch
))
8516 type_flags
= gdbarch_address_class_type_flags
8517 (gdbarch
, byte_size
, addr_class
);
8518 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
8520 type
= make_type_with_address_space (type
, type_flags
);
8522 else if (TYPE_LENGTH (type
) != byte_size
)
8524 complaint (&symfile_complaints
,
8525 _("invalid pointer size %d"), byte_size
);
8529 /* Should we also complain about unhandled address classes? */
8533 TYPE_LENGTH (type
) = byte_size
;
8534 return set_die_type (die
, type
, cu
);
8537 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
8538 the user defined type vector. */
8540 static struct type
*
8541 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8544 struct type
*to_type
;
8545 struct type
*domain
;
8547 to_type
= die_type (die
, cu
);
8548 domain
= die_containing_type (die
, cu
);
8550 /* The calls above may have already set the type for this DIE. */
8551 type
= get_die_type (die
, cu
);
8555 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
8556 type
= lookup_methodptr_type (to_type
);
8558 type
= lookup_memberptr_type (to_type
, domain
);
8560 return set_die_type (die
, type
, cu
);
8563 /* Extract all information from a DW_TAG_reference_type DIE and add to
8564 the user defined type vector. */
8566 static struct type
*
8567 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8569 struct comp_unit_head
*cu_header
= &cu
->header
;
8570 struct type
*type
, *target_type
;
8571 struct attribute
*attr
;
8573 target_type
= die_type (die
, cu
);
8575 /* The die_type call above may have already set the type for this DIE. */
8576 type
= get_die_type (die
, cu
);
8580 type
= lookup_reference_type (target_type
);
8581 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8584 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8588 TYPE_LENGTH (type
) = cu_header
->addr_size
;
8590 return set_die_type (die
, type
, cu
);
8593 static struct type
*
8594 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8596 struct type
*base_type
, *cv_type
;
8598 base_type
= die_type (die
, cu
);
8600 /* The die_type call above may have already set the type for this DIE. */
8601 cv_type
= get_die_type (die
, cu
);
8605 /* In case the const qualifier is applied to an array type, the element type
8606 is so qualified, not the array type (section 6.7.3 of C99). */
8607 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
8609 struct type
*el_type
, *inner_array
;
8611 base_type
= copy_type (base_type
);
8612 inner_array
= base_type
;
8614 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
8616 TYPE_TARGET_TYPE (inner_array
) =
8617 copy_type (TYPE_TARGET_TYPE (inner_array
));
8618 inner_array
= TYPE_TARGET_TYPE (inner_array
);
8621 el_type
= TYPE_TARGET_TYPE (inner_array
);
8622 TYPE_TARGET_TYPE (inner_array
) =
8623 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
8625 return set_die_type (die
, base_type
, cu
);
8628 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
8629 return set_die_type (die
, cv_type
, cu
);
8632 static struct type
*
8633 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8635 struct type
*base_type
, *cv_type
;
8637 base_type
= die_type (die
, cu
);
8639 /* The die_type call above may have already set the type for this DIE. */
8640 cv_type
= get_die_type (die
, cu
);
8644 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
8645 return set_die_type (die
, cv_type
, cu
);
8648 /* Extract all information from a DW_TAG_string_type DIE and add to
8649 the user defined type vector. It isn't really a user defined type,
8650 but it behaves like one, with other DIE's using an AT_user_def_type
8651 attribute to reference it. */
8653 static struct type
*
8654 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8656 struct objfile
*objfile
= cu
->objfile
;
8657 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8658 struct type
*type
, *range_type
, *index_type
, *char_type
;
8659 struct attribute
*attr
;
8660 unsigned int length
;
8662 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
8665 length
= DW_UNSND (attr
);
8669 /* Check for the DW_AT_byte_size attribute. */
8670 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8673 length
= DW_UNSND (attr
);
8681 index_type
= objfile_type (objfile
)->builtin_int
;
8682 range_type
= create_range_type (NULL
, index_type
, 1, length
);
8683 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
8684 type
= create_string_type (NULL
, char_type
, range_type
);
8686 return set_die_type (die
, type
, cu
);
8689 /* Handle DIES due to C code like:
8693 int (*funcp)(int a, long l);
8697 ('funcp' generates a DW_TAG_subroutine_type DIE). */
8699 static struct type
*
8700 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8702 struct objfile
*objfile
= cu
->objfile
;
8703 struct type
*type
; /* Type that this function returns. */
8704 struct type
*ftype
; /* Function that returns above type. */
8705 struct attribute
*attr
;
8707 type
= die_type (die
, cu
);
8709 /* The die_type call above may have already set the type for this DIE. */
8710 ftype
= get_die_type (die
, cu
);
8714 ftype
= lookup_function_type (type
);
8716 /* All functions in C++, Pascal and Java have prototypes. */
8717 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
8718 if ((attr
&& (DW_UNSND (attr
) != 0))
8719 || cu
->language
== language_cplus
8720 || cu
->language
== language_java
8721 || cu
->language
== language_pascal
)
8722 TYPE_PROTOTYPED (ftype
) = 1;
8723 else if (producer_is_realview (cu
->producer
))
8724 /* RealView does not emit DW_AT_prototyped. We can not
8725 distinguish prototyped and unprototyped functions; default to
8726 prototyped, since that is more common in modern code (and
8727 RealView warns about unprototyped functions). */
8728 TYPE_PROTOTYPED (ftype
) = 1;
8730 /* Store the calling convention in the type if it's available in
8731 the subroutine die. Otherwise set the calling convention to
8732 the default value DW_CC_normal. */
8733 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
8735 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
8736 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
8737 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
8739 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
8741 /* We need to add the subroutine type to the die immediately so
8742 we don't infinitely recurse when dealing with parameters
8743 declared as the same subroutine type. */
8744 set_die_type (die
, ftype
, cu
);
8746 if (die
->child
!= NULL
)
8748 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
8749 struct die_info
*child_die
;
8750 int nparams
, iparams
;
8752 /* Count the number of parameters.
8753 FIXME: GDB currently ignores vararg functions, but knows about
8754 vararg member functions. */
8756 child_die
= die
->child
;
8757 while (child_die
&& child_die
->tag
)
8759 if (child_die
->tag
== DW_TAG_formal_parameter
)
8761 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
8762 TYPE_VARARGS (ftype
) = 1;
8763 child_die
= sibling_die (child_die
);
8766 /* Allocate storage for parameters and fill them in. */
8767 TYPE_NFIELDS (ftype
) = nparams
;
8768 TYPE_FIELDS (ftype
) = (struct field
*)
8769 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
8771 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
8772 even if we error out during the parameters reading below. */
8773 for (iparams
= 0; iparams
< nparams
; iparams
++)
8774 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
8777 child_die
= die
->child
;
8778 while (child_die
&& child_die
->tag
)
8780 if (child_die
->tag
== DW_TAG_formal_parameter
)
8782 struct type
*arg_type
;
8784 /* DWARF version 2 has no clean way to discern C++
8785 static and non-static member functions. G++ helps
8786 GDB by marking the first parameter for non-static
8787 member functions (which is the this pointer) as
8788 artificial. We pass this information to
8789 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
8791 DWARF version 3 added DW_AT_object_pointer, which GCC
8792 4.5 does not yet generate. */
8793 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
8795 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
8798 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
8800 /* GCC/43521: In java, the formal parameter
8801 "this" is sometimes not marked with DW_AT_artificial. */
8802 if (cu
->language
== language_java
)
8804 const char *name
= dwarf2_name (child_die
, cu
);
8806 if (name
&& !strcmp (name
, "this"))
8807 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
8810 arg_type
= die_type (child_die
, cu
);
8812 /* RealView does not mark THIS as const, which the testsuite
8813 expects. GCC marks THIS as const in method definitions,
8814 but not in the class specifications (GCC PR 43053). */
8815 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
8816 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
8819 struct dwarf2_cu
*arg_cu
= cu
;
8820 const char *name
= dwarf2_name (child_die
, cu
);
8822 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
8825 /* If the compiler emits this, use it. */
8826 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
8829 else if (name
&& strcmp (name
, "this") == 0)
8830 /* Function definitions will have the argument names. */
8832 else if (name
== NULL
&& iparams
== 0)
8833 /* Declarations may not have the names, so like
8834 elsewhere in GDB, assume an artificial first
8835 argument is "this". */
8839 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
8843 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
8846 child_die
= sibling_die (child_die
);
8853 static struct type
*
8854 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
8856 struct objfile
*objfile
= cu
->objfile
;
8857 const char *name
= NULL
;
8858 struct type
*this_type
, *target_type
;
8860 name
= dwarf2_full_name (NULL
, die
, cu
);
8861 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
8862 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
8863 TYPE_NAME (this_type
) = (char *) name
;
8864 set_die_type (die
, this_type
, cu
);
8865 target_type
= die_type (die
, cu
);
8866 if (target_type
!= this_type
)
8867 TYPE_TARGET_TYPE (this_type
) = target_type
;
8870 /* Self-referential typedefs are, it seems, not allowed by the DWARF
8871 spec and cause infinite loops in GDB. */
8872 complaint (&symfile_complaints
,
8873 _("Self-referential DW_TAG_typedef "
8874 "- DIE at 0x%x [in module %s]"),
8875 die
->offset
.sect_off
, objfile
->name
);
8876 TYPE_TARGET_TYPE (this_type
) = NULL
;
8881 /* Find a representation of a given base type and install
8882 it in the TYPE field of the die. */
8884 static struct type
*
8885 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8887 struct objfile
*objfile
= cu
->objfile
;
8889 struct attribute
*attr
;
8890 int encoding
= 0, size
= 0;
8892 enum type_code code
= TYPE_CODE_INT
;
8894 struct type
*target_type
= NULL
;
8896 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
8899 encoding
= DW_UNSND (attr
);
8901 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8904 size
= DW_UNSND (attr
);
8906 name
= dwarf2_name (die
, cu
);
8909 complaint (&symfile_complaints
,
8910 _("DW_AT_name missing from DW_TAG_base_type"));
8915 case DW_ATE_address
:
8916 /* Turn DW_ATE_address into a void * pointer. */
8917 code
= TYPE_CODE_PTR
;
8918 type_flags
|= TYPE_FLAG_UNSIGNED
;
8919 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
8921 case DW_ATE_boolean
:
8922 code
= TYPE_CODE_BOOL
;
8923 type_flags
|= TYPE_FLAG_UNSIGNED
;
8925 case DW_ATE_complex_float
:
8926 code
= TYPE_CODE_COMPLEX
;
8927 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
8929 case DW_ATE_decimal_float
:
8930 code
= TYPE_CODE_DECFLOAT
;
8933 code
= TYPE_CODE_FLT
;
8937 case DW_ATE_unsigned
:
8938 type_flags
|= TYPE_FLAG_UNSIGNED
;
8939 if (cu
->language
== language_fortran
8941 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
8942 code
= TYPE_CODE_CHAR
;
8944 case DW_ATE_signed_char
:
8945 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8946 || cu
->language
== language_pascal
8947 || cu
->language
== language_fortran
)
8948 code
= TYPE_CODE_CHAR
;
8950 case DW_ATE_unsigned_char
:
8951 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8952 || cu
->language
== language_pascal
8953 || cu
->language
== language_fortran
)
8954 code
= TYPE_CODE_CHAR
;
8955 type_flags
|= TYPE_FLAG_UNSIGNED
;
8958 /* We just treat this as an integer and then recognize the
8959 type by name elsewhere. */
8963 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
8964 dwarf_type_encoding_name (encoding
));
8968 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
8969 TYPE_NAME (type
) = name
;
8970 TYPE_TARGET_TYPE (type
) = target_type
;
8972 if (name
&& strcmp (name
, "char") == 0)
8973 TYPE_NOSIGN (type
) = 1;
8975 return set_die_type (die
, type
, cu
);
8978 /* Read the given DW_AT_subrange DIE. */
8980 static struct type
*
8981 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8983 struct type
*base_type
;
8984 struct type
*range_type
;
8985 struct attribute
*attr
;
8989 LONGEST negative_mask
;
8991 base_type
= die_type (die
, cu
);
8992 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
8993 check_typedef (base_type
);
8995 /* The die_type call above may have already set the type for this DIE. */
8996 range_type
= get_die_type (die
, cu
);
9000 if (cu
->language
== language_fortran
)
9002 /* FORTRAN implies a lower bound of 1, if not given. */
9006 /* FIXME: For variable sized arrays either of these could be
9007 a variable rather than a constant value. We'll allow it,
9008 but we don't know how to handle it. */
9009 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
9011 low
= dwarf2_get_attr_constant_value (attr
, 0);
9013 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
9016 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
9018 /* GCC encodes arrays with unspecified or dynamic length
9019 with a DW_FORM_block1 attribute or a reference attribute.
9020 FIXME: GDB does not yet know how to handle dynamic
9021 arrays properly, treat them as arrays with unspecified
9024 FIXME: jimb/2003-09-22: GDB does not really know
9025 how to handle arrays of unspecified length
9026 either; we just represent them as zero-length
9027 arrays. Choose an appropriate upper bound given
9028 the lower bound we've computed above. */
9032 high
= dwarf2_get_attr_constant_value (attr
, 1);
9036 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
9039 int count
= dwarf2_get_attr_constant_value (attr
, 1);
9040 high
= low
+ count
- 1;
9044 /* Unspecified array length. */
9049 /* Dwarf-2 specifications explicitly allows to create subrange types
9050 without specifying a base type.
9051 In that case, the base type must be set to the type of
9052 the lower bound, upper bound or count, in that order, if any of these
9053 three attributes references an object that has a type.
9054 If no base type is found, the Dwarf-2 specifications say that
9055 a signed integer type of size equal to the size of an address should
9057 For the following C code: `extern char gdb_int [];'
9058 GCC produces an empty range DIE.
9059 FIXME: muller/2010-05-28: Possible references to object for low bound,
9060 high bound or count are not yet handled by this code. */
9061 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
9063 struct objfile
*objfile
= cu
->objfile
;
9064 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9065 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
9066 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
9068 /* Test "int", "long int", and "long long int" objfile types,
9069 and select the first one having a size above or equal to the
9070 architecture address size. */
9071 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
9072 base_type
= int_type
;
9075 int_type
= objfile_type (objfile
)->builtin_long
;
9076 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
9077 base_type
= int_type
;
9080 int_type
= objfile_type (objfile
)->builtin_long_long
;
9081 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
9082 base_type
= int_type
;
9088 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
9089 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
9090 low
|= negative_mask
;
9091 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
9092 high
|= negative_mask
;
9094 range_type
= create_range_type (NULL
, base_type
, low
, high
);
9096 /* Mark arrays with dynamic length at least as an array of unspecified
9097 length. GDB could check the boundary but before it gets implemented at
9098 least allow accessing the array elements. */
9099 if (attr
&& attr_form_is_block (attr
))
9100 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
9102 /* Ada expects an empty array on no boundary attributes. */
9103 if (attr
== NULL
&& cu
->language
!= language_ada
)
9104 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
9106 name
= dwarf2_name (die
, cu
);
9108 TYPE_NAME (range_type
) = name
;
9110 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9112 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
9114 set_die_type (die
, range_type
, cu
);
9116 /* set_die_type should be already done. */
9117 set_descriptive_type (range_type
, die
, cu
);
9122 static struct type
*
9123 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9127 /* For now, we only support the C meaning of an unspecified type: void. */
9129 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
9130 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
9132 return set_die_type (die
, type
, cu
);
9135 /* Trivial hash function for die_info: the hash value of a DIE
9136 is its offset in .debug_info for this objfile. */
9139 die_hash (const void *item
)
9141 const struct die_info
*die
= item
;
9143 return die
->offset
.sect_off
;
9146 /* Trivial comparison function for die_info structures: two DIEs
9147 are equal if they have the same offset. */
9150 die_eq (const void *item_lhs
, const void *item_rhs
)
9152 const struct die_info
*die_lhs
= item_lhs
;
9153 const struct die_info
*die_rhs
= item_rhs
;
9155 return die_lhs
->offset
.sect_off
== die_rhs
->offset
.sect_off
;
9158 /* Read a whole compilation unit into a linked list of dies. */
9160 static struct die_info
*
9161 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
9163 struct die_reader_specs reader_specs
;
9164 int read_abbrevs
= 0;
9165 struct cleanup
*back_to
= NULL
;
9166 struct die_info
*die
;
9168 if (cu
->dwarf2_abbrevs
== NULL
)
9170 dwarf2_read_abbrevs (cu
);
9171 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
9175 gdb_assert (cu
->die_hash
== NULL
);
9177 = htab_create_alloc_ex (cu
->header
.length
/ 12,
9181 &cu
->comp_unit_obstack
,
9182 hashtab_obstack_allocate
,
9183 dummy_obstack_deallocate
);
9185 init_cu_die_reader (&reader_specs
, cu
);
9187 die
= read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
9190 do_cleanups (back_to
);
9195 /* Main entry point for reading a DIE and all children.
9196 Read the DIE and dump it if requested. */
9198 static struct die_info
*
9199 read_die_and_children (const struct die_reader_specs
*reader
,
9201 gdb_byte
**new_info_ptr
,
9202 struct die_info
*parent
)
9204 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
9205 new_info_ptr
, parent
);
9207 if (dwarf2_die_debug
)
9209 fprintf_unfiltered (gdb_stdlog
,
9210 "\nRead die from %s of %s:\n",
9211 (reader
->cu
->per_cu
->debug_types_section
9214 reader
->abfd
->filename
);
9215 dump_die (result
, dwarf2_die_debug
);
9221 /* Read a single die and all its descendents. Set the die's sibling
9222 field to NULL; set other fields in the die correctly, and set all
9223 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
9224 location of the info_ptr after reading all of those dies. PARENT
9225 is the parent of the die in question. */
9227 static struct die_info
*
9228 read_die_and_children_1 (const struct die_reader_specs
*reader
,
9230 gdb_byte
**new_info_ptr
,
9231 struct die_info
*parent
)
9233 struct die_info
*die
;
9237 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
9240 *new_info_ptr
= cur_ptr
;
9243 store_in_ref_table (die
, reader
->cu
);
9246 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
9250 *new_info_ptr
= cur_ptr
;
9253 die
->sibling
= NULL
;
9254 die
->parent
= parent
;
9258 /* Read a die, all of its descendents, and all of its siblings; set
9259 all of the fields of all of the dies correctly. Arguments are as
9260 in read_die_and_children. */
9262 static struct die_info
*
9263 read_die_and_siblings (const struct die_reader_specs
*reader
,
9265 gdb_byte
**new_info_ptr
,
9266 struct die_info
*parent
)
9268 struct die_info
*first_die
, *last_sibling
;
9272 first_die
= last_sibling
= NULL
;
9276 struct die_info
*die
9277 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
9281 *new_info_ptr
= cur_ptr
;
9288 last_sibling
->sibling
= die
;
9294 /* Read the die from the .debug_info section buffer. Set DIEP to
9295 point to a newly allocated die with its information, except for its
9296 child, sibling, and parent fields. Set HAS_CHILDREN to tell
9297 whether the die has children or not. */
9300 read_full_die (const struct die_reader_specs
*reader
,
9301 struct die_info
**diep
, gdb_byte
*info_ptr
,
9304 unsigned int abbrev_number
, bytes_read
, i
;
9306 struct abbrev_info
*abbrev
;
9307 struct die_info
*die
;
9308 struct dwarf2_cu
*cu
= reader
->cu
;
9309 bfd
*abfd
= reader
->abfd
;
9311 offset
.sect_off
= info_ptr
- reader
->buffer
;
9312 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9313 info_ptr
+= bytes_read
;
9321 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
9323 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
9325 bfd_get_filename (abfd
));
9327 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
9328 die
->offset
= offset
;
9329 die
->tag
= abbrev
->tag
;
9330 die
->abbrev
= abbrev_number
;
9332 die
->num_attrs
= abbrev
->num_attrs
;
9334 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9335 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
9336 abfd
, info_ptr
, cu
);
9339 *has_children
= abbrev
->has_children
;
9343 /* In DWARF version 2, the description of the debugging information is
9344 stored in a separate .debug_abbrev section. Before we read any
9345 dies from a section we read in all abbreviations and install them
9346 in a hash table. This function also sets flags in CU describing
9347 the data found in the abbrev table. */
9350 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
)
9352 bfd
*abfd
= cu
->objfile
->obfd
;
9353 struct comp_unit_head
*cu_header
= &cu
->header
;
9354 gdb_byte
*abbrev_ptr
;
9355 struct abbrev_info
*cur_abbrev
;
9356 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
9357 unsigned int abbrev_form
, hash_number
;
9358 struct attr_abbrev
*cur_attrs
;
9359 unsigned int allocated_attrs
;
9361 /* Initialize dwarf2 abbrevs. */
9362 obstack_init (&cu
->abbrev_obstack
);
9363 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
9365 * sizeof (struct abbrev_info
*)));
9366 memset (cu
->dwarf2_abbrevs
, 0,
9367 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
9369 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
9370 &dwarf2_per_objfile
->abbrev
);
9371 abbrev_ptr
= (dwarf2_per_objfile
->abbrev
.buffer
9372 + cu_header
->abbrev_offset
.sect_off
);
9373 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9374 abbrev_ptr
+= bytes_read
;
9376 allocated_attrs
= ATTR_ALLOC_CHUNK
;
9377 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
9379 /* Loop until we reach an abbrev number of 0. */
9380 while (abbrev_number
)
9382 cur_abbrev
= dwarf_alloc_abbrev (cu
);
9384 /* read in abbrev header */
9385 cur_abbrev
->number
= abbrev_number
;
9386 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9387 abbrev_ptr
+= bytes_read
;
9388 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
9391 /* now read in declarations */
9392 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9393 abbrev_ptr
+= bytes_read
;
9394 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9395 abbrev_ptr
+= bytes_read
;
9398 if (cur_abbrev
->num_attrs
== allocated_attrs
)
9400 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
9402 = xrealloc (cur_attrs
, (allocated_attrs
9403 * sizeof (struct attr_abbrev
)));
9406 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
9407 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
9408 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9409 abbrev_ptr
+= bytes_read
;
9410 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9411 abbrev_ptr
+= bytes_read
;
9414 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
9415 (cur_abbrev
->num_attrs
9416 * sizeof (struct attr_abbrev
)));
9417 memcpy (cur_abbrev
->attrs
, cur_attrs
,
9418 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
9420 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
9421 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
9422 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
9424 /* Get next abbreviation.
9425 Under Irix6 the abbreviations for a compilation unit are not
9426 always properly terminated with an abbrev number of 0.
9427 Exit loop if we encounter an abbreviation which we have
9428 already read (which means we are about to read the abbreviations
9429 for the next compile unit) or if the end of the abbreviation
9430 table is reached. */
9431 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
9432 >= dwarf2_per_objfile
->abbrev
.size
)
9434 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9435 abbrev_ptr
+= bytes_read
;
9436 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
9443 /* Release the memory used by the abbrev table for a compilation unit. */
9446 dwarf2_free_abbrev_table (void *ptr_to_cu
)
9448 struct dwarf2_cu
*cu
= ptr_to_cu
;
9450 obstack_free (&cu
->abbrev_obstack
, NULL
);
9451 cu
->dwarf2_abbrevs
= NULL
;
9454 /* Lookup an abbrev_info structure in the abbrev hash table. */
9456 static struct abbrev_info
*
9457 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
9459 unsigned int hash_number
;
9460 struct abbrev_info
*abbrev
;
9462 hash_number
= number
% ABBREV_HASH_SIZE
;
9463 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
9467 if (abbrev
->number
== number
)
9470 abbrev
= abbrev
->next
;
9475 /* Returns nonzero if TAG represents a type that we might generate a partial
9479 is_type_tag_for_partial (int tag
)
9484 /* Some types that would be reasonable to generate partial symbols for,
9485 that we don't at present. */
9486 case DW_TAG_array_type
:
9487 case DW_TAG_file_type
:
9488 case DW_TAG_ptr_to_member_type
:
9489 case DW_TAG_set_type
:
9490 case DW_TAG_string_type
:
9491 case DW_TAG_subroutine_type
:
9493 case DW_TAG_base_type
:
9494 case DW_TAG_class_type
:
9495 case DW_TAG_interface_type
:
9496 case DW_TAG_enumeration_type
:
9497 case DW_TAG_structure_type
:
9498 case DW_TAG_subrange_type
:
9499 case DW_TAG_typedef
:
9500 case DW_TAG_union_type
:
9507 /* Load all DIEs that are interesting for partial symbols into memory. */
9509 static struct partial_die_info
*
9510 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9511 int building_psymtab
, struct dwarf2_cu
*cu
)
9513 struct objfile
*objfile
= cu
->objfile
;
9514 struct partial_die_info
*part_die
;
9515 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
9516 struct abbrev_info
*abbrev
;
9517 unsigned int bytes_read
;
9518 unsigned int load_all
= 0;
9519 int nesting_level
= 1;
9524 gdb_assert (cu
->per_cu
!= NULL
);
9525 if (cu
->per_cu
->load_all_dies
)
9529 = htab_create_alloc_ex (cu
->header
.length
/ 12,
9533 &cu
->comp_unit_obstack
,
9534 hashtab_obstack_allocate
,
9535 dummy_obstack_deallocate
);
9537 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9538 sizeof (struct partial_die_info
));
9542 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
9544 /* A NULL abbrev means the end of a series of children. */
9547 if (--nesting_level
== 0)
9549 /* PART_DIE was probably the last thing allocated on the
9550 comp_unit_obstack, so we could call obstack_free
9551 here. We don't do that because the waste is small,
9552 and will be cleaned up when we're done with this
9553 compilation unit. This way, we're also more robust
9554 against other users of the comp_unit_obstack. */
9557 info_ptr
+= bytes_read
;
9558 last_die
= parent_die
;
9559 parent_die
= parent_die
->die_parent
;
9563 /* Check for template arguments. We never save these; if
9564 they're seen, we just mark the parent, and go on our way. */
9565 if (parent_die
!= NULL
9566 && cu
->language
== language_cplus
9567 && (abbrev
->tag
== DW_TAG_template_type_param
9568 || abbrev
->tag
== DW_TAG_template_value_param
))
9570 parent_die
->has_template_arguments
= 1;
9574 /* We don't need a partial DIE for the template argument. */
9575 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
,
9581 /* We only recurse into c++ subprograms looking for template arguments.
9582 Skip their other children. */
9584 && cu
->language
== language_cplus
9585 && parent_die
!= NULL
9586 && parent_die
->tag
== DW_TAG_subprogram
)
9588 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
9592 /* Check whether this DIE is interesting enough to save. Normally
9593 we would not be interested in members here, but there may be
9594 later variables referencing them via DW_AT_specification (for
9597 && !is_type_tag_for_partial (abbrev
->tag
)
9598 && abbrev
->tag
!= DW_TAG_constant
9599 && abbrev
->tag
!= DW_TAG_enumerator
9600 && abbrev
->tag
!= DW_TAG_subprogram
9601 && abbrev
->tag
!= DW_TAG_lexical_block
9602 && abbrev
->tag
!= DW_TAG_variable
9603 && abbrev
->tag
!= DW_TAG_namespace
9604 && abbrev
->tag
!= DW_TAG_module
9605 && abbrev
->tag
!= DW_TAG_member
)
9607 /* Otherwise we skip to the next sibling, if any. */
9608 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
9612 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
9613 buffer
, info_ptr
, cu
);
9615 /* This two-pass algorithm for processing partial symbols has a
9616 high cost in cache pressure. Thus, handle some simple cases
9617 here which cover the majority of C partial symbols. DIEs
9618 which neither have specification tags in them, nor could have
9619 specification tags elsewhere pointing at them, can simply be
9620 processed and discarded.
9622 This segment is also optional; scan_partial_symbols and
9623 add_partial_symbol will handle these DIEs if we chain
9624 them in normally. When compilers which do not emit large
9625 quantities of duplicate debug information are more common,
9626 this code can probably be removed. */
9628 /* Any complete simple types at the top level (pretty much all
9629 of them, for a language without namespaces), can be processed
9631 if (parent_die
== NULL
9632 && part_die
->has_specification
== 0
9633 && part_die
->is_declaration
== 0
9634 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
9635 || part_die
->tag
== DW_TAG_base_type
9636 || part_die
->tag
== DW_TAG_subrange_type
))
9638 if (building_psymtab
&& part_die
->name
!= NULL
)
9639 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9640 VAR_DOMAIN
, LOC_TYPEDEF
,
9641 &objfile
->static_psymbols
,
9642 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
9643 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9647 /* The exception for DW_TAG_typedef with has_children above is
9648 a workaround of GCC PR debug/47510. In the case of this complaint
9649 type_name_no_tag_or_error will error on such types later.
9651 GDB skipped children of DW_TAG_typedef by the shortcut above and then
9652 it could not find the child DIEs referenced later, this is checked
9653 above. In correct DWARF DW_TAG_typedef should have no children. */
9655 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
9656 complaint (&symfile_complaints
,
9657 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
9658 "- DIE at 0x%x [in module %s]"),
9659 part_die
->offset
.sect_off
, objfile
->name
);
9661 /* If we're at the second level, and we're an enumerator, and
9662 our parent has no specification (meaning possibly lives in a
9663 namespace elsewhere), then we can add the partial symbol now
9664 instead of queueing it. */
9665 if (part_die
->tag
== DW_TAG_enumerator
9666 && parent_die
!= NULL
9667 && parent_die
->die_parent
== NULL
9668 && parent_die
->tag
== DW_TAG_enumeration_type
9669 && parent_die
->has_specification
== 0)
9671 if (part_die
->name
== NULL
)
9672 complaint (&symfile_complaints
,
9673 _("malformed enumerator DIE ignored"));
9674 else if (building_psymtab
)
9675 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9676 VAR_DOMAIN
, LOC_CONST
,
9677 (cu
->language
== language_cplus
9678 || cu
->language
== language_java
)
9679 ? &objfile
->global_psymbols
9680 : &objfile
->static_psymbols
,
9681 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
9683 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9687 /* We'll save this DIE so link it in. */
9688 part_die
->die_parent
= parent_die
;
9689 part_die
->die_sibling
= NULL
;
9690 part_die
->die_child
= NULL
;
9692 if (last_die
&& last_die
== parent_die
)
9693 last_die
->die_child
= part_die
;
9695 last_die
->die_sibling
= part_die
;
9697 last_die
= part_die
;
9699 if (first_die
== NULL
)
9700 first_die
= part_die
;
9702 /* Maybe add the DIE to the hash table. Not all DIEs that we
9703 find interesting need to be in the hash table, because we
9704 also have the parent/sibling/child chains; only those that we
9705 might refer to by offset later during partial symbol reading.
9707 For now this means things that might have be the target of a
9708 DW_AT_specification, DW_AT_abstract_origin, or
9709 DW_AT_extension. DW_AT_extension will refer only to
9710 namespaces; DW_AT_abstract_origin refers to functions (and
9711 many things under the function DIE, but we do not recurse
9712 into function DIEs during partial symbol reading) and
9713 possibly variables as well; DW_AT_specification refers to
9714 declarations. Declarations ought to have the DW_AT_declaration
9715 flag. It happens that GCC forgets to put it in sometimes, but
9716 only for functions, not for types.
9718 Adding more things than necessary to the hash table is harmless
9719 except for the performance cost. Adding too few will result in
9720 wasted time in find_partial_die, when we reread the compilation
9721 unit with load_all_dies set. */
9724 || abbrev
->tag
== DW_TAG_constant
9725 || abbrev
->tag
== DW_TAG_subprogram
9726 || abbrev
->tag
== DW_TAG_variable
9727 || abbrev
->tag
== DW_TAG_namespace
9728 || part_die
->is_declaration
)
9732 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
9733 part_die
->offset
.sect_off
, INSERT
);
9737 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9738 sizeof (struct partial_die_info
));
9740 /* For some DIEs we want to follow their children (if any). For C
9741 we have no reason to follow the children of structures; for other
9742 languages we have to, so that we can get at method physnames
9743 to infer fully qualified class names, for DW_AT_specification,
9744 and for C++ template arguments. For C++, we also look one level
9745 inside functions to find template arguments (if the name of the
9746 function does not already contain the template arguments).
9748 For Ada, we need to scan the children of subprograms and lexical
9749 blocks as well because Ada allows the definition of nested
9750 entities that could be interesting for the debugger, such as
9751 nested subprograms for instance. */
9752 if (last_die
->has_children
9754 || last_die
->tag
== DW_TAG_namespace
9755 || last_die
->tag
== DW_TAG_module
9756 || last_die
->tag
== DW_TAG_enumeration_type
9757 || (cu
->language
== language_cplus
9758 && last_die
->tag
== DW_TAG_subprogram
9759 && (last_die
->name
== NULL
9760 || strchr (last_die
->name
, '<') == NULL
))
9761 || (cu
->language
!= language_c
9762 && (last_die
->tag
== DW_TAG_class_type
9763 || last_die
->tag
== DW_TAG_interface_type
9764 || last_die
->tag
== DW_TAG_structure_type
9765 || last_die
->tag
== DW_TAG_union_type
))
9766 || (cu
->language
== language_ada
9767 && (last_die
->tag
== DW_TAG_subprogram
9768 || last_die
->tag
== DW_TAG_lexical_block
))))
9771 parent_die
= last_die
;
9775 /* Otherwise we skip to the next sibling, if any. */
9776 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
9778 /* Back to the top, do it again. */
9782 /* Read a minimal amount of information into the minimal die structure. */
9785 read_partial_die (struct partial_die_info
*part_die
,
9786 struct abbrev_info
*abbrev
,
9787 unsigned int abbrev_len
, bfd
*abfd
,
9788 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9789 struct dwarf2_cu
*cu
)
9791 struct objfile
*objfile
= cu
->objfile
;
9793 struct attribute attr
;
9794 int has_low_pc_attr
= 0;
9795 int has_high_pc_attr
= 0;
9797 memset (part_die
, 0, sizeof (struct partial_die_info
));
9799 part_die
->offset
.sect_off
= info_ptr
- buffer
;
9801 info_ptr
+= abbrev_len
;
9806 part_die
->tag
= abbrev
->tag
;
9807 part_die
->has_children
= abbrev
->has_children
;
9809 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9811 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
9813 /* Store the data if it is of an attribute we want to keep in a
9814 partial symbol table. */
9818 switch (part_die
->tag
)
9820 case DW_TAG_compile_unit
:
9821 case DW_TAG_type_unit
:
9822 /* Compilation units have a DW_AT_name that is a filename, not
9823 a source language identifier. */
9824 case DW_TAG_enumeration_type
:
9825 case DW_TAG_enumerator
:
9826 /* These tags always have simple identifiers already; no need
9827 to canonicalize them. */
9828 part_die
->name
= DW_STRING (&attr
);
9832 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
9833 &objfile
->objfile_obstack
);
9837 case DW_AT_linkage_name
:
9838 case DW_AT_MIPS_linkage_name
:
9839 /* Note that both forms of linkage name might appear. We
9840 assume they will be the same, and we only store the last
9842 if (cu
->language
== language_ada
)
9843 part_die
->name
= DW_STRING (&attr
);
9844 part_die
->linkage_name
= DW_STRING (&attr
);
9847 has_low_pc_attr
= 1;
9848 part_die
->lowpc
= DW_ADDR (&attr
);
9851 has_high_pc_attr
= 1;
9852 part_die
->highpc
= DW_ADDR (&attr
);
9854 case DW_AT_location
:
9855 /* Support the .debug_loc offsets. */
9856 if (attr_form_is_block (&attr
))
9858 part_die
->locdesc
= DW_BLOCK (&attr
);
9860 else if (attr_form_is_section_offset (&attr
))
9862 dwarf2_complex_location_expr_complaint ();
9866 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9867 "partial symbol information");
9870 case DW_AT_external
:
9871 part_die
->is_external
= DW_UNSND (&attr
);
9873 case DW_AT_declaration
:
9874 part_die
->is_declaration
= DW_UNSND (&attr
);
9877 part_die
->has_type
= 1;
9879 case DW_AT_abstract_origin
:
9880 case DW_AT_specification
:
9881 case DW_AT_extension
:
9882 part_die
->has_specification
= 1;
9883 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
9886 /* Ignore absolute siblings, they might point outside of
9887 the current compile unit. */
9888 if (attr
.form
== DW_FORM_ref_addr
)
9889 complaint (&symfile_complaints
,
9890 _("ignoring absolute DW_AT_sibling"));
9892 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
9894 case DW_AT_byte_size
:
9895 part_die
->has_byte_size
= 1;
9897 case DW_AT_calling_convention
:
9898 /* DWARF doesn't provide a way to identify a program's source-level
9899 entry point. DW_AT_calling_convention attributes are only meant
9900 to describe functions' calling conventions.
9902 However, because it's a necessary piece of information in
9903 Fortran, and because DW_CC_program is the only piece of debugging
9904 information whose definition refers to a 'main program' at all,
9905 several compilers have begun marking Fortran main programs with
9906 DW_CC_program --- even when those functions use the standard
9907 calling conventions.
9909 So until DWARF specifies a way to provide this information and
9910 compilers pick up the new representation, we'll support this
9912 if (DW_UNSND (&attr
) == DW_CC_program
9913 && cu
->language
== language_fortran
)
9915 set_main_name (part_die
->name
);
9917 /* As this DIE has a static linkage the name would be difficult
9918 to look up later. */
9919 language_of_main
= language_fortran
;
9923 if (DW_UNSND (&attr
) == DW_INL_inlined
9924 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
9925 part_die
->may_be_inlined
= 1;
9932 if (has_low_pc_attr
&& has_high_pc_attr
)
9934 /* When using the GNU linker, .gnu.linkonce. sections are used to
9935 eliminate duplicate copies of functions and vtables and such.
9936 The linker will arbitrarily choose one and discard the others.
9937 The AT_*_pc values for such functions refer to local labels in
9938 these sections. If the section from that file was discarded, the
9939 labels are not in the output, so the relocs get a value of 0.
9940 If this is a discarded function, mark the pc bounds as invalid,
9941 so that GDB will ignore it. */
9942 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
9944 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9946 complaint (&symfile_complaints
,
9947 _("DW_AT_low_pc %s is zero "
9948 "for DIE at 0x%x [in module %s]"),
9949 paddress (gdbarch
, part_die
->lowpc
),
9950 part_die
->offset
.sect_off
, objfile
->name
);
9952 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
9953 else if (part_die
->lowpc
>= part_die
->highpc
)
9955 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9957 complaint (&symfile_complaints
,
9958 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
9959 "for DIE at 0x%x [in module %s]"),
9960 paddress (gdbarch
, part_die
->lowpc
),
9961 paddress (gdbarch
, part_die
->highpc
),
9962 part_die
->offset
.sect_off
, objfile
->name
);
9965 part_die
->has_pc_info
= 1;
9971 /* Find a cached partial DIE at OFFSET in CU. */
9973 static struct partial_die_info
*
9974 find_partial_die_in_comp_unit (sect_offset offset
, struct dwarf2_cu
*cu
)
9976 struct partial_die_info
*lookup_die
= NULL
;
9977 struct partial_die_info part_die
;
9979 part_die
.offset
= offset
;
9980 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
,
9986 /* Find a partial DIE at OFFSET, which may or may not be in CU,
9987 except in the case of .debug_types DIEs which do not reference
9988 outside their CU (they do however referencing other types via
9989 DW_FORM_ref_sig8). */
9991 static struct partial_die_info
*
9992 find_partial_die (sect_offset offset
, struct dwarf2_cu
*cu
)
9994 struct objfile
*objfile
= cu
->objfile
;
9995 struct dwarf2_per_cu_data
*per_cu
= NULL
;
9996 struct partial_die_info
*pd
= NULL
;
9998 if (offset_in_cu_p (&cu
->header
, offset
))
10000 pd
= find_partial_die_in_comp_unit (offset
, cu
);
10003 /* We missed recording what we needed.
10004 Load all dies and try again. */
10005 per_cu
= cu
->per_cu
;
10009 /* TUs don't reference other CUs/TUs (except via type signatures). */
10010 if (cu
->per_cu
->debug_types_section
)
10012 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
10013 " external reference to offset 0x%lx [in module %s].\n"),
10014 (long) cu
->header
.offset
.sect_off
, (long) offset
.sect_off
,
10015 bfd_get_filename (objfile
->obfd
));
10017 per_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
10019 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
10020 load_partial_comp_unit (per_cu
);
10022 per_cu
->cu
->last_used
= 0;
10023 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
10026 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
10028 struct cleanup
*back_to
;
10029 struct partial_die_info comp_unit_die
;
10030 struct abbrev_info
*abbrev
;
10031 unsigned int bytes_read
;
10033 struct dwarf2_section_info
*sec
;
10035 per_cu
->load_all_dies
= 1;
10037 if (per_cu
->debug_types_section
)
10038 sec
= per_cu
->debug_types_section
;
10040 sec
= &dwarf2_per_objfile
->info
;
10042 /* Re-read the DIEs, this time reading all of them.
10043 NOTE: We don't discard the previous set of DIEs.
10044 This doesn't happen very often so it's (hopefully) not a problem. */
10045 back_to
= make_cleanup (null_cleanup
, 0);
10046 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
10048 dwarf2_read_abbrevs (per_cu
->cu
);
10049 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
10051 info_ptr
= (sec
->buffer
10052 + per_cu
->cu
->header
.offset
.sect_off
10053 + per_cu
->cu
->header
.first_die_offset
.cu_off
);
10054 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
10055 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
10056 objfile
->obfd
, sec
->buffer
, info_ptr
,
10058 if (comp_unit_die
.has_children
)
10059 load_partial_dies (objfile
->obfd
, sec
->buffer
, info_ptr
, 0,
10061 do_cleanups (back_to
);
10063 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
10067 internal_error (__FILE__
, __LINE__
,
10068 _("could not find partial DIE 0x%x "
10069 "in cache [from module %s]\n"),
10070 offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
10074 /* See if we can figure out if the class lives in a namespace. We do
10075 this by looking for a member function; its demangled name will
10076 contain namespace info, if there is any. */
10079 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
10080 struct dwarf2_cu
*cu
)
10082 /* NOTE: carlton/2003-10-07: Getting the info this way changes
10083 what template types look like, because the demangler
10084 frequently doesn't give the same name as the debug info. We
10085 could fix this by only using the demangled name to get the
10086 prefix (but see comment in read_structure_type). */
10088 struct partial_die_info
*real_pdi
;
10089 struct partial_die_info
*child_pdi
;
10091 /* If this DIE (this DIE's specification, if any) has a parent, then
10092 we should not do this. We'll prepend the parent's fully qualified
10093 name when we create the partial symbol. */
10095 real_pdi
= struct_pdi
;
10096 while (real_pdi
->has_specification
)
10097 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
10099 if (real_pdi
->die_parent
!= NULL
)
10102 for (child_pdi
= struct_pdi
->die_child
;
10104 child_pdi
= child_pdi
->die_sibling
)
10106 if (child_pdi
->tag
== DW_TAG_subprogram
10107 && child_pdi
->linkage_name
!= NULL
)
10109 char *actual_class_name
10110 = language_class_name_from_physname (cu
->language_defn
,
10111 child_pdi
->linkage_name
);
10112 if (actual_class_name
!= NULL
)
10115 = obsavestring (actual_class_name
,
10116 strlen (actual_class_name
),
10117 &cu
->objfile
->objfile_obstack
);
10118 xfree (actual_class_name
);
10125 /* Adjust PART_DIE before generating a symbol for it. This function
10126 may set the is_external flag or change the DIE's name. */
10129 fixup_partial_die (struct partial_die_info
*part_die
,
10130 struct dwarf2_cu
*cu
)
10132 /* Once we've fixed up a die, there's no point in doing so again.
10133 This also avoids a memory leak if we were to call
10134 guess_partial_die_structure_name multiple times. */
10135 if (part_die
->fixup_called
)
10138 /* If we found a reference attribute and the DIE has no name, try
10139 to find a name in the referred to DIE. */
10141 if (part_die
->name
== NULL
&& part_die
->has_specification
)
10143 struct partial_die_info
*spec_die
;
10145 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
10147 fixup_partial_die (spec_die
, cu
);
10149 if (spec_die
->name
)
10151 part_die
->name
= spec_die
->name
;
10153 /* Copy DW_AT_external attribute if it is set. */
10154 if (spec_die
->is_external
)
10155 part_die
->is_external
= spec_die
->is_external
;
10159 /* Set default names for some unnamed DIEs. */
10161 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
10162 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
10164 /* If there is no parent die to provide a namespace, and there are
10165 children, see if we can determine the namespace from their linkage
10167 if (cu
->language
== language_cplus
10168 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
10169 && part_die
->die_parent
== NULL
10170 && part_die
->has_children
10171 && (part_die
->tag
== DW_TAG_class_type
10172 || part_die
->tag
== DW_TAG_structure_type
10173 || part_die
->tag
== DW_TAG_union_type
))
10174 guess_partial_die_structure_name (part_die
, cu
);
10176 /* GCC might emit a nameless struct or union that has a linkage
10177 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
10178 if (part_die
->name
== NULL
10179 && (part_die
->tag
== DW_TAG_class_type
10180 || part_die
->tag
== DW_TAG_interface_type
10181 || part_die
->tag
== DW_TAG_structure_type
10182 || part_die
->tag
== DW_TAG_union_type
)
10183 && part_die
->linkage_name
!= NULL
)
10187 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
10192 /* Strip any leading namespaces/classes, keep only the base name.
10193 DW_AT_name for named DIEs does not contain the prefixes. */
10194 base
= strrchr (demangled
, ':');
10195 if (base
&& base
> demangled
&& base
[-1] == ':')
10200 part_die
->name
= obsavestring (base
, strlen (base
),
10201 &cu
->objfile
->objfile_obstack
);
10206 part_die
->fixup_called
= 1;
10209 /* Read an attribute value described by an attribute form. */
10212 read_attribute_value (struct attribute
*attr
, unsigned form
,
10213 bfd
*abfd
, gdb_byte
*info_ptr
,
10214 struct dwarf2_cu
*cu
)
10216 struct comp_unit_head
*cu_header
= &cu
->header
;
10217 unsigned int bytes_read
;
10218 struct dwarf_block
*blk
;
10223 case DW_FORM_ref_addr
:
10224 if (cu
->header
.version
== 2)
10225 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
10227 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
,
10228 &cu
->header
, &bytes_read
);
10229 info_ptr
+= bytes_read
;
10232 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
10233 info_ptr
+= bytes_read
;
10235 case DW_FORM_block2
:
10236 blk
= dwarf_alloc_block (cu
);
10237 blk
->size
= read_2_bytes (abfd
, info_ptr
);
10239 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10240 info_ptr
+= blk
->size
;
10241 DW_BLOCK (attr
) = blk
;
10243 case DW_FORM_block4
:
10244 blk
= dwarf_alloc_block (cu
);
10245 blk
->size
= read_4_bytes (abfd
, info_ptr
);
10247 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10248 info_ptr
+= blk
->size
;
10249 DW_BLOCK (attr
) = blk
;
10251 case DW_FORM_data2
:
10252 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
10255 case DW_FORM_data4
:
10256 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
10259 case DW_FORM_data8
:
10260 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
10263 case DW_FORM_sec_offset
:
10264 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
10265 info_ptr
+= bytes_read
;
10267 case DW_FORM_string
:
10268 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
10269 DW_STRING_IS_CANONICAL (attr
) = 0;
10270 info_ptr
+= bytes_read
;
10273 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
10275 DW_STRING_IS_CANONICAL (attr
) = 0;
10276 info_ptr
+= bytes_read
;
10278 case DW_FORM_exprloc
:
10279 case DW_FORM_block
:
10280 blk
= dwarf_alloc_block (cu
);
10281 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10282 info_ptr
+= bytes_read
;
10283 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10284 info_ptr
+= blk
->size
;
10285 DW_BLOCK (attr
) = blk
;
10287 case DW_FORM_block1
:
10288 blk
= dwarf_alloc_block (cu
);
10289 blk
->size
= read_1_byte (abfd
, info_ptr
);
10291 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10292 info_ptr
+= blk
->size
;
10293 DW_BLOCK (attr
) = blk
;
10295 case DW_FORM_data1
:
10296 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
10300 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
10303 case DW_FORM_flag_present
:
10304 DW_UNSND (attr
) = 1;
10306 case DW_FORM_sdata
:
10307 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
10308 info_ptr
+= bytes_read
;
10310 case DW_FORM_udata
:
10311 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10312 info_ptr
+= bytes_read
;
10315 DW_ADDR (attr
) = (cu
->header
.offset
.sect_off
10316 + read_1_byte (abfd
, info_ptr
));
10320 DW_ADDR (attr
) = (cu
->header
.offset
.sect_off
10321 + read_2_bytes (abfd
, info_ptr
));
10325 DW_ADDR (attr
) = (cu
->header
.offset
.sect_off
10326 + read_4_bytes (abfd
, info_ptr
));
10330 DW_ADDR (attr
) = (cu
->header
.offset
.sect_off
10331 + read_8_bytes (abfd
, info_ptr
));
10334 case DW_FORM_ref_sig8
:
10335 /* Convert the signature to something we can record in DW_UNSND
10337 NOTE: This is NULL if the type wasn't found. */
10338 DW_SIGNATURED_TYPE (attr
) =
10339 lookup_signatured_type (read_8_bytes (abfd
, info_ptr
));
10342 case DW_FORM_ref_udata
:
10343 DW_ADDR (attr
) = (cu
->header
.offset
.sect_off
10344 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
10345 info_ptr
+= bytes_read
;
10347 case DW_FORM_indirect
:
10348 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10349 info_ptr
+= bytes_read
;
10350 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
10353 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
10354 dwarf_form_name (form
),
10355 bfd_get_filename (abfd
));
10358 /* We have seen instances where the compiler tried to emit a byte
10359 size attribute of -1 which ended up being encoded as an unsigned
10360 0xffffffff. Although 0xffffffff is technically a valid size value,
10361 an object of this size seems pretty unlikely so we can relatively
10362 safely treat these cases as if the size attribute was invalid and
10363 treat them as zero by default. */
10364 if (attr
->name
== DW_AT_byte_size
10365 && form
== DW_FORM_data4
10366 && DW_UNSND (attr
) >= 0xffffffff)
10369 (&symfile_complaints
,
10370 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
10371 hex_string (DW_UNSND (attr
)));
10372 DW_UNSND (attr
) = 0;
10378 /* Read an attribute described by an abbreviated attribute. */
10381 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
10382 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
10384 attr
->name
= abbrev
->name
;
10385 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
10388 /* Read dwarf information from a buffer. */
10390 static unsigned int
10391 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
10393 return bfd_get_8 (abfd
, buf
);
10397 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
10399 return bfd_get_signed_8 (abfd
, buf
);
10402 static unsigned int
10403 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
10405 return bfd_get_16 (abfd
, buf
);
10409 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
10411 return bfd_get_signed_16 (abfd
, buf
);
10414 static unsigned int
10415 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
10417 return bfd_get_32 (abfd
, buf
);
10421 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
10423 return bfd_get_signed_32 (abfd
, buf
);
10427 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
10429 return bfd_get_64 (abfd
, buf
);
10433 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
10434 unsigned int *bytes_read
)
10436 struct comp_unit_head
*cu_header
= &cu
->header
;
10437 CORE_ADDR retval
= 0;
10439 if (cu_header
->signed_addr_p
)
10441 switch (cu_header
->addr_size
)
10444 retval
= bfd_get_signed_16 (abfd
, buf
);
10447 retval
= bfd_get_signed_32 (abfd
, buf
);
10450 retval
= bfd_get_signed_64 (abfd
, buf
);
10453 internal_error (__FILE__
, __LINE__
,
10454 _("read_address: bad switch, signed [in module %s]"),
10455 bfd_get_filename (abfd
));
10460 switch (cu_header
->addr_size
)
10463 retval
= bfd_get_16 (abfd
, buf
);
10466 retval
= bfd_get_32 (abfd
, buf
);
10469 retval
= bfd_get_64 (abfd
, buf
);
10472 internal_error (__FILE__
, __LINE__
,
10473 _("read_address: bad switch, "
10474 "unsigned [in module %s]"),
10475 bfd_get_filename (abfd
));
10479 *bytes_read
= cu_header
->addr_size
;
10483 /* Read the initial length from a section. The (draft) DWARF 3
10484 specification allows the initial length to take up either 4 bytes
10485 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
10486 bytes describe the length and all offsets will be 8 bytes in length
10489 An older, non-standard 64-bit format is also handled by this
10490 function. The older format in question stores the initial length
10491 as an 8-byte quantity without an escape value. Lengths greater
10492 than 2^32 aren't very common which means that the initial 4 bytes
10493 is almost always zero. Since a length value of zero doesn't make
10494 sense for the 32-bit format, this initial zero can be considered to
10495 be an escape value which indicates the presence of the older 64-bit
10496 format. As written, the code can't detect (old format) lengths
10497 greater than 4GB. If it becomes necessary to handle lengths
10498 somewhat larger than 4GB, we could allow other small values (such
10499 as the non-sensical values of 1, 2, and 3) to also be used as
10500 escape values indicating the presence of the old format.
10502 The value returned via bytes_read should be used to increment the
10503 relevant pointer after calling read_initial_length().
10505 [ Note: read_initial_length() and read_offset() are based on the
10506 document entitled "DWARF Debugging Information Format", revision
10507 3, draft 8, dated November 19, 2001. This document was obtained
10510 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
10512 This document is only a draft and is subject to change. (So beware.)
10514 Details regarding the older, non-standard 64-bit format were
10515 determined empirically by examining 64-bit ELF files produced by
10516 the SGI toolchain on an IRIX 6.5 machine.
10518 - Kevin, July 16, 2002
10522 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
10524 LONGEST length
= bfd_get_32 (abfd
, buf
);
10526 if (length
== 0xffffffff)
10528 length
= bfd_get_64 (abfd
, buf
+ 4);
10531 else if (length
== 0)
10533 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
10534 length
= bfd_get_64 (abfd
, buf
);
10545 /* Cover function for read_initial_length.
10546 Returns the length of the object at BUF, and stores the size of the
10547 initial length in *BYTES_READ and stores the size that offsets will be in
10549 If the initial length size is not equivalent to that specified in
10550 CU_HEADER then issue a complaint.
10551 This is useful when reading non-comp-unit headers. */
10554 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
10555 const struct comp_unit_head
*cu_header
,
10556 unsigned int *bytes_read
,
10557 unsigned int *offset_size
)
10559 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
10561 gdb_assert (cu_header
->initial_length_size
== 4
10562 || cu_header
->initial_length_size
== 8
10563 || cu_header
->initial_length_size
== 12);
10565 if (cu_header
->initial_length_size
!= *bytes_read
)
10566 complaint (&symfile_complaints
,
10567 _("intermixed 32-bit and 64-bit DWARF sections"));
10569 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
10573 /* Read an offset from the data stream. The size of the offset is
10574 given by cu_header->offset_size. */
10577 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
10578 unsigned int *bytes_read
)
10580 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
10582 *bytes_read
= cu_header
->offset_size
;
10586 /* Read an offset from the data stream. */
10589 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
10591 LONGEST retval
= 0;
10593 switch (offset_size
)
10596 retval
= bfd_get_32 (abfd
, buf
);
10599 retval
= bfd_get_64 (abfd
, buf
);
10602 internal_error (__FILE__
, __LINE__
,
10603 _("read_offset_1: bad switch [in module %s]"),
10604 bfd_get_filename (abfd
));
10611 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
10613 /* If the size of a host char is 8 bits, we can return a pointer
10614 to the buffer, otherwise we have to copy the data to a buffer
10615 allocated on the temporary obstack. */
10616 gdb_assert (HOST_CHAR_BIT
== 8);
10621 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10623 /* If the size of a host char is 8 bits, we can return a pointer
10624 to the string, otherwise we have to copy the string to a buffer
10625 allocated on the temporary obstack. */
10626 gdb_assert (HOST_CHAR_BIT
== 8);
10629 *bytes_read_ptr
= 1;
10632 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
10633 return (char *) buf
;
10637 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
10639 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
10640 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
10641 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
10642 bfd_get_filename (abfd
));
10643 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
10644 error (_("DW_FORM_strp pointing outside of "
10645 ".debug_str section [in module %s]"),
10646 bfd_get_filename (abfd
));
10647 gdb_assert (HOST_CHAR_BIT
== 8);
10648 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
10650 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
10654 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
10655 const struct comp_unit_head
*cu_header
,
10656 unsigned int *bytes_read_ptr
)
10658 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
10660 return read_indirect_string_at_offset (abfd
, str_offset
);
10663 static unsigned long
10664 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10666 unsigned long result
;
10667 unsigned int num_read
;
10669 unsigned char byte
;
10677 byte
= bfd_get_8 (abfd
, buf
);
10680 result
|= ((unsigned long)(byte
& 127) << shift
);
10681 if ((byte
& 128) == 0)
10687 *bytes_read_ptr
= num_read
;
10692 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10695 int i
, shift
, num_read
;
10696 unsigned char byte
;
10704 byte
= bfd_get_8 (abfd
, buf
);
10707 result
|= ((long)(byte
& 127) << shift
);
10709 if ((byte
& 128) == 0)
10714 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
10715 result
|= -(((long)1) << shift
);
10716 *bytes_read_ptr
= num_read
;
10720 /* Return a pointer to just past the end of an LEB128 number in BUF. */
10723 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
10729 byte
= bfd_get_8 (abfd
, buf
);
10731 if ((byte
& 128) == 0)
10737 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
10744 cu
->language
= language_c
;
10746 case DW_LANG_C_plus_plus
:
10747 cu
->language
= language_cplus
;
10750 cu
->language
= language_d
;
10752 case DW_LANG_Fortran77
:
10753 case DW_LANG_Fortran90
:
10754 case DW_LANG_Fortran95
:
10755 cu
->language
= language_fortran
;
10757 case DW_LANG_Mips_Assembler
:
10758 cu
->language
= language_asm
;
10761 cu
->language
= language_java
;
10763 case DW_LANG_Ada83
:
10764 case DW_LANG_Ada95
:
10765 cu
->language
= language_ada
;
10767 case DW_LANG_Modula2
:
10768 cu
->language
= language_m2
;
10770 case DW_LANG_Pascal83
:
10771 cu
->language
= language_pascal
;
10774 cu
->language
= language_objc
;
10776 case DW_LANG_Cobol74
:
10777 case DW_LANG_Cobol85
:
10779 cu
->language
= language_minimal
;
10782 cu
->language_defn
= language_def (cu
->language
);
10785 /* Return the named attribute or NULL if not there. */
10787 static struct attribute
*
10788 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
10793 struct attribute
*spec
= NULL
;
10795 for (i
= 0; i
< die
->num_attrs
; ++i
)
10797 if (die
->attrs
[i
].name
== name
)
10798 return &die
->attrs
[i
];
10799 if (die
->attrs
[i
].name
== DW_AT_specification
10800 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
10801 spec
= &die
->attrs
[i
];
10807 die
= follow_die_ref (die
, spec
, &cu
);
10813 /* Return the named attribute or NULL if not there,
10814 but do not follow DW_AT_specification, etc.
10815 This is for use in contexts where we're reading .debug_types dies.
10816 Following DW_AT_specification, DW_AT_abstract_origin will take us
10817 back up the chain, and we want to go down. */
10819 static struct attribute
*
10820 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
10821 struct dwarf2_cu
*cu
)
10825 for (i
= 0; i
< die
->num_attrs
; ++i
)
10826 if (die
->attrs
[i
].name
== name
)
10827 return &die
->attrs
[i
];
10832 /* Return non-zero iff the attribute NAME is defined for the given DIE,
10833 and holds a non-zero value. This function should only be used for
10834 DW_FORM_flag or DW_FORM_flag_present attributes. */
10837 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
10839 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
10841 return (attr
&& DW_UNSND (attr
));
10845 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
10847 /* A DIE is a declaration if it has a DW_AT_declaration attribute
10848 which value is non-zero. However, we have to be careful with
10849 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
10850 (via dwarf2_flag_true_p) follows this attribute. So we may
10851 end up accidently finding a declaration attribute that belongs
10852 to a different DIE referenced by the specification attribute,
10853 even though the given DIE does not have a declaration attribute. */
10854 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
10855 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
10858 /* Return the die giving the specification for DIE, if there is
10859 one. *SPEC_CU is the CU containing DIE on input, and the CU
10860 containing the return value on output. If there is no
10861 specification, but there is an abstract origin, that is
10864 static struct die_info
*
10865 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
10867 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
10870 if (spec_attr
== NULL
)
10871 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
10873 if (spec_attr
== NULL
)
10876 return follow_die_ref (die
, spec_attr
, spec_cu
);
10879 /* Free the line_header structure *LH, and any arrays and strings it
10881 NOTE: This is also used as a "cleanup" function. */
10884 free_line_header (struct line_header
*lh
)
10886 if (lh
->standard_opcode_lengths
)
10887 xfree (lh
->standard_opcode_lengths
);
10889 /* Remember that all the lh->file_names[i].name pointers are
10890 pointers into debug_line_buffer, and don't need to be freed. */
10891 if (lh
->file_names
)
10892 xfree (lh
->file_names
);
10894 /* Similarly for the include directory names. */
10895 if (lh
->include_dirs
)
10896 xfree (lh
->include_dirs
);
10901 /* Add an entry to LH's include directory table. */
10904 add_include_dir (struct line_header
*lh
, char *include_dir
)
10906 /* Grow the array if necessary. */
10907 if (lh
->include_dirs_size
== 0)
10909 lh
->include_dirs_size
= 1; /* for testing */
10910 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
10911 * sizeof (*lh
->include_dirs
));
10913 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
10915 lh
->include_dirs_size
*= 2;
10916 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
10917 (lh
->include_dirs_size
10918 * sizeof (*lh
->include_dirs
)));
10921 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
10924 /* Add an entry to LH's file name table. */
10927 add_file_name (struct line_header
*lh
,
10929 unsigned int dir_index
,
10930 unsigned int mod_time
,
10931 unsigned int length
)
10933 struct file_entry
*fe
;
10935 /* Grow the array if necessary. */
10936 if (lh
->file_names_size
== 0)
10938 lh
->file_names_size
= 1; /* for testing */
10939 lh
->file_names
= xmalloc (lh
->file_names_size
10940 * sizeof (*lh
->file_names
));
10942 else if (lh
->num_file_names
>= lh
->file_names_size
)
10944 lh
->file_names_size
*= 2;
10945 lh
->file_names
= xrealloc (lh
->file_names
,
10946 (lh
->file_names_size
10947 * sizeof (*lh
->file_names
)));
10950 fe
= &lh
->file_names
[lh
->num_file_names
++];
10952 fe
->dir_index
= dir_index
;
10953 fe
->mod_time
= mod_time
;
10954 fe
->length
= length
;
10955 fe
->included_p
= 0;
10959 /* Read the statement program header starting at OFFSET in
10960 .debug_line, according to the endianness of ABFD. Return a pointer
10961 to a struct line_header, allocated using xmalloc.
10963 NOTE: the strings in the include directory and file name tables of
10964 the returned object point into debug_line_buffer, and must not be
10967 static struct line_header
*
10968 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
10969 struct dwarf2_cu
*cu
)
10971 struct cleanup
*back_to
;
10972 struct line_header
*lh
;
10973 gdb_byte
*line_ptr
;
10974 unsigned int bytes_read
, offset_size
;
10976 char *cur_dir
, *cur_file
;
10978 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
10979 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
10981 complaint (&symfile_complaints
, _("missing .debug_line section"));
10985 /* Make sure that at least there's room for the total_length field.
10986 That could be 12 bytes long, but we're just going to fudge that. */
10987 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
10989 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10993 lh
= xmalloc (sizeof (*lh
));
10994 memset (lh
, 0, sizeof (*lh
));
10995 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
10998 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
11000 /* Read in the header. */
11002 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
11003 &bytes_read
, &offset_size
);
11004 line_ptr
+= bytes_read
;
11005 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
11006 + dwarf2_per_objfile
->line
.size
))
11008 dwarf2_statement_list_fits_in_line_number_section_complaint ();
11011 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
11012 lh
->version
= read_2_bytes (abfd
, line_ptr
);
11014 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
11015 line_ptr
+= offset_size
;
11016 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
11018 if (lh
->version
>= 4)
11020 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
11024 lh
->maximum_ops_per_instruction
= 1;
11026 if (lh
->maximum_ops_per_instruction
== 0)
11028 lh
->maximum_ops_per_instruction
= 1;
11029 complaint (&symfile_complaints
,
11030 _("invalid maximum_ops_per_instruction "
11031 "in `.debug_line' section"));
11034 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
11036 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
11038 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
11040 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
11042 lh
->standard_opcode_lengths
11043 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
11045 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
11046 for (i
= 1; i
< lh
->opcode_base
; ++i
)
11048 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
11052 /* Read directory table. */
11053 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
11055 line_ptr
+= bytes_read
;
11056 add_include_dir (lh
, cur_dir
);
11058 line_ptr
+= bytes_read
;
11060 /* Read file name table. */
11061 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
11063 unsigned int dir_index
, mod_time
, length
;
11065 line_ptr
+= bytes_read
;
11066 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11067 line_ptr
+= bytes_read
;
11068 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11069 line_ptr
+= bytes_read
;
11070 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11071 line_ptr
+= bytes_read
;
11073 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
11075 line_ptr
+= bytes_read
;
11076 lh
->statement_program_start
= line_ptr
;
11078 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
11079 + dwarf2_per_objfile
->line
.size
))
11080 complaint (&symfile_complaints
,
11081 _("line number info header doesn't "
11082 "fit in `.debug_line' section"));
11084 discard_cleanups (back_to
);
11088 /* Subroutine of dwarf_decode_lines to simplify it.
11089 Return the file name of the psymtab for included file FILE_INDEX
11090 in line header LH of PST.
11091 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
11092 If space for the result is malloc'd, it will be freed by a cleanup.
11093 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
11096 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
11097 const struct partial_symtab
*pst
,
11098 const char *comp_dir
)
11100 const struct file_entry fe
= lh
->file_names
[file_index
];
11101 char *include_name
= fe
.name
;
11102 char *include_name_to_compare
= include_name
;
11103 char *dir_name
= NULL
;
11104 const char *pst_filename
;
11105 char *copied_name
= NULL
;
11109 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
11111 if (!IS_ABSOLUTE_PATH (include_name
)
11112 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
11114 /* Avoid creating a duplicate psymtab for PST.
11115 We do this by comparing INCLUDE_NAME and PST_FILENAME.
11116 Before we do the comparison, however, we need to account
11117 for DIR_NAME and COMP_DIR.
11118 First prepend dir_name (if non-NULL). If we still don't
11119 have an absolute path prepend comp_dir (if non-NULL).
11120 However, the directory we record in the include-file's
11121 psymtab does not contain COMP_DIR (to match the
11122 corresponding symtab(s)).
11127 bash$ gcc -g ./hello.c
11128 include_name = "hello.c"
11130 DW_AT_comp_dir = comp_dir = "/tmp"
11131 DW_AT_name = "./hello.c" */
11133 if (dir_name
!= NULL
)
11135 include_name
= concat (dir_name
, SLASH_STRING
,
11136 include_name
, (char *)NULL
);
11137 include_name_to_compare
= include_name
;
11138 make_cleanup (xfree
, include_name
);
11140 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
11142 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
11143 include_name
, (char *)NULL
);
11147 pst_filename
= pst
->filename
;
11148 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
11150 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
11151 pst_filename
, (char *)NULL
);
11152 pst_filename
= copied_name
;
11155 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
11157 if (include_name_to_compare
!= include_name
)
11158 xfree (include_name_to_compare
);
11159 if (copied_name
!= NULL
)
11160 xfree (copied_name
);
11164 return include_name
;
11167 /* Ignore this record_line request. */
11170 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
11175 /* Subroutine of dwarf_decode_lines to simplify it.
11176 Process the line number information in LH. */
11179 dwarf_decode_lines_1 (struct line_header
*lh
, const char *comp_dir
,
11180 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
11182 gdb_byte
*line_ptr
, *extended_end
;
11183 gdb_byte
*line_end
;
11184 unsigned int bytes_read
, extended_len
;
11185 unsigned char op_code
, extended_op
, adj_opcode
;
11186 CORE_ADDR baseaddr
;
11187 struct objfile
*objfile
= cu
->objfile
;
11188 bfd
*abfd
= objfile
->obfd
;
11189 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11190 const int decode_for_pst_p
= (pst
!= NULL
);
11191 struct subfile
*last_subfile
= NULL
;
11192 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
11195 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11197 line_ptr
= lh
->statement_program_start
;
11198 line_end
= lh
->statement_program_end
;
11200 /* Read the statement sequences until there's nothing left. */
11201 while (line_ptr
< line_end
)
11203 /* state machine registers */
11204 CORE_ADDR address
= 0;
11205 unsigned int file
= 1;
11206 unsigned int line
= 1;
11207 unsigned int column
= 0;
11208 int is_stmt
= lh
->default_is_stmt
;
11209 int basic_block
= 0;
11210 int end_sequence
= 0;
11212 unsigned char op_index
= 0;
11214 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
11216 /* Start a subfile for the current file of the state machine. */
11217 /* lh->include_dirs and lh->file_names are 0-based, but the
11218 directory and file name numbers in the statement program
11220 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
11224 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11226 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11229 /* Decode the table. */
11230 while (!end_sequence
)
11232 op_code
= read_1_byte (abfd
, line_ptr
);
11234 if (line_ptr
> line_end
)
11236 dwarf2_debug_line_missing_end_sequence_complaint ();
11240 if (op_code
>= lh
->opcode_base
)
11242 /* Special operand. */
11243 adj_opcode
= op_code
- lh
->opcode_base
;
11244 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
11245 / lh
->maximum_ops_per_instruction
)
11246 * lh
->minimum_instruction_length
);
11247 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
11248 % lh
->maximum_ops_per_instruction
);
11249 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
11250 if (lh
->num_file_names
< file
|| file
== 0)
11251 dwarf2_debug_line_missing_file_complaint ();
11252 /* For now we ignore lines not starting on an
11253 instruction boundary. */
11254 else if (op_index
== 0)
11256 lh
->file_names
[file
- 1].included_p
= 1;
11257 if (!decode_for_pst_p
&& is_stmt
)
11259 if (last_subfile
!= current_subfile
)
11261 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11263 (*p_record_line
) (last_subfile
, 0, addr
);
11264 last_subfile
= current_subfile
;
11266 /* Append row to matrix using current values. */
11267 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11268 (*p_record_line
) (current_subfile
, line
, addr
);
11273 else switch (op_code
)
11275 case DW_LNS_extended_op
:
11276 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
11278 line_ptr
+= bytes_read
;
11279 extended_end
= line_ptr
+ extended_len
;
11280 extended_op
= read_1_byte (abfd
, line_ptr
);
11282 switch (extended_op
)
11284 case DW_LNE_end_sequence
:
11285 p_record_line
= record_line
;
11288 case DW_LNE_set_address
:
11289 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
11291 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
11293 /* This line table is for a function which has been
11294 GCd by the linker. Ignore it. PR gdb/12528 */
11297 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
11299 complaint (&symfile_complaints
,
11300 _(".debug_line address at offset 0x%lx is 0 "
11302 line_offset
, objfile
->name
);
11303 p_record_line
= noop_record_line
;
11307 line_ptr
+= bytes_read
;
11308 address
+= baseaddr
;
11310 case DW_LNE_define_file
:
11313 unsigned int dir_index
, mod_time
, length
;
11315 cur_file
= read_direct_string (abfd
, line_ptr
,
11317 line_ptr
+= bytes_read
;
11319 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11320 line_ptr
+= bytes_read
;
11322 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11323 line_ptr
+= bytes_read
;
11325 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11326 line_ptr
+= bytes_read
;
11327 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
11330 case DW_LNE_set_discriminator
:
11331 /* The discriminator is not interesting to the debugger;
11333 line_ptr
= extended_end
;
11336 complaint (&symfile_complaints
,
11337 _("mangled .debug_line section"));
11340 /* Make sure that we parsed the extended op correctly. If e.g.
11341 we expected a different address size than the producer used,
11342 we may have read the wrong number of bytes. */
11343 if (line_ptr
!= extended_end
)
11345 complaint (&symfile_complaints
,
11346 _("mangled .debug_line section"));
11351 if (lh
->num_file_names
< file
|| file
== 0)
11352 dwarf2_debug_line_missing_file_complaint ();
11355 lh
->file_names
[file
- 1].included_p
= 1;
11356 if (!decode_for_pst_p
&& is_stmt
)
11358 if (last_subfile
!= current_subfile
)
11360 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11362 (*p_record_line
) (last_subfile
, 0, addr
);
11363 last_subfile
= current_subfile
;
11365 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11366 (*p_record_line
) (current_subfile
, line
, addr
);
11371 case DW_LNS_advance_pc
:
11374 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11376 address
+= (((op_index
+ adjust
)
11377 / lh
->maximum_ops_per_instruction
)
11378 * lh
->minimum_instruction_length
);
11379 op_index
= ((op_index
+ adjust
)
11380 % lh
->maximum_ops_per_instruction
);
11381 line_ptr
+= bytes_read
;
11384 case DW_LNS_advance_line
:
11385 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
11386 line_ptr
+= bytes_read
;
11388 case DW_LNS_set_file
:
11390 /* The arrays lh->include_dirs and lh->file_names are
11391 0-based, but the directory and file name numbers in
11392 the statement program are 1-based. */
11393 struct file_entry
*fe
;
11396 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11397 line_ptr
+= bytes_read
;
11398 if (lh
->num_file_names
< file
|| file
== 0)
11399 dwarf2_debug_line_missing_file_complaint ();
11402 fe
= &lh
->file_names
[file
- 1];
11404 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11405 if (!decode_for_pst_p
)
11407 last_subfile
= current_subfile
;
11408 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11413 case DW_LNS_set_column
:
11414 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11415 line_ptr
+= bytes_read
;
11417 case DW_LNS_negate_stmt
:
11418 is_stmt
= (!is_stmt
);
11420 case DW_LNS_set_basic_block
:
11423 /* Add to the address register of the state machine the
11424 address increment value corresponding to special opcode
11425 255. I.e., this value is scaled by the minimum
11426 instruction length since special opcode 255 would have
11427 scaled the increment. */
11428 case DW_LNS_const_add_pc
:
11430 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
11432 address
+= (((op_index
+ adjust
)
11433 / lh
->maximum_ops_per_instruction
)
11434 * lh
->minimum_instruction_length
);
11435 op_index
= ((op_index
+ adjust
)
11436 % lh
->maximum_ops_per_instruction
);
11439 case DW_LNS_fixed_advance_pc
:
11440 address
+= read_2_bytes (abfd
, line_ptr
);
11446 /* Unknown standard opcode, ignore it. */
11449 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
11451 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11452 line_ptr
+= bytes_read
;
11457 if (lh
->num_file_names
< file
|| file
== 0)
11458 dwarf2_debug_line_missing_file_complaint ();
11461 lh
->file_names
[file
- 1].included_p
= 1;
11462 if (!decode_for_pst_p
)
11464 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11465 (*p_record_line
) (current_subfile
, 0, addr
);
11471 /* Decode the Line Number Program (LNP) for the given line_header
11472 structure and CU. The actual information extracted and the type
11473 of structures created from the LNP depends on the value of PST.
11475 1. If PST is NULL, then this procedure uses the data from the program
11476 to create all necessary symbol tables, and their linetables.
11478 2. If PST is not NULL, this procedure reads the program to determine
11479 the list of files included by the unit represented by PST, and
11480 builds all the associated partial symbol tables.
11482 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
11483 It is used for relative paths in the line table.
11484 NOTE: When processing partial symtabs (pst != NULL),
11485 comp_dir == pst->dirname.
11487 NOTE: It is important that psymtabs have the same file name (via strcmp)
11488 as the corresponding symtab. Since COMP_DIR is not used in the name of the
11489 symtab we don't use it in the name of the psymtabs we create.
11490 E.g. expand_line_sal requires this when finding psymtabs to expand.
11491 A good testcase for this is mb-inline.exp. */
11494 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
11495 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
11496 int want_line_info
)
11498 struct objfile
*objfile
= cu
->objfile
;
11499 const int decode_for_pst_p
= (pst
!= NULL
);
11500 struct subfile
*first_subfile
= current_subfile
;
11502 if (want_line_info
)
11503 dwarf_decode_lines_1 (lh
, comp_dir
, cu
, pst
);
11505 if (decode_for_pst_p
)
11509 /* Now that we're done scanning the Line Header Program, we can
11510 create the psymtab of each included file. */
11511 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
11512 if (lh
->file_names
[file_index
].included_p
== 1)
11514 char *include_name
=
11515 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
11516 if (include_name
!= NULL
)
11517 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
11522 /* Make sure a symtab is created for every file, even files
11523 which contain only variables (i.e. no code with associated
11527 for (i
= 0; i
< lh
->num_file_names
; i
++)
11530 struct file_entry
*fe
;
11532 fe
= &lh
->file_names
[i
];
11534 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11535 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11537 /* Skip the main file; we don't need it, and it must be
11538 allocated last, so that it will show up before the
11539 non-primary symtabs in the objfile's symtab list. */
11540 if (current_subfile
== first_subfile
)
11543 if (current_subfile
->symtab
== NULL
)
11544 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
11546 fe
->symtab
= current_subfile
->symtab
;
11551 /* Start a subfile for DWARF. FILENAME is the name of the file and
11552 DIRNAME the name of the source directory which contains FILENAME
11553 or NULL if not known. COMP_DIR is the compilation directory for the
11554 linetable's compilation unit or NULL if not known.
11555 This routine tries to keep line numbers from identical absolute and
11556 relative file names in a common subfile.
11558 Using the `list' example from the GDB testsuite, which resides in
11559 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
11560 of /srcdir/list0.c yields the following debugging information for list0.c:
11562 DW_AT_name: /srcdir/list0.c
11563 DW_AT_comp_dir: /compdir
11564 files.files[0].name: list0.h
11565 files.files[0].dir: /srcdir
11566 files.files[1].name: list0.c
11567 files.files[1].dir: /srcdir
11569 The line number information for list0.c has to end up in a single
11570 subfile, so that `break /srcdir/list0.c:1' works as expected.
11571 start_subfile will ensure that this happens provided that we pass the
11572 concatenation of files.files[1].dir and files.files[1].name as the
11576 dwarf2_start_subfile (char *filename
, const char *dirname
,
11577 const char *comp_dir
)
11581 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
11582 `start_symtab' will always pass the contents of DW_AT_comp_dir as
11583 second argument to start_subfile. To be consistent, we do the
11584 same here. In order not to lose the line information directory,
11585 we concatenate it to the filename when it makes sense.
11586 Note that the Dwarf3 standard says (speaking of filenames in line
11587 information): ``The directory index is ignored for file names
11588 that represent full path names''. Thus ignoring dirname in the
11589 `else' branch below isn't an issue. */
11591 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
11592 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
11594 fullname
= filename
;
11596 start_subfile (fullname
, comp_dir
);
11598 if (fullname
!= filename
)
11603 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
11604 struct dwarf2_cu
*cu
)
11606 struct objfile
*objfile
= cu
->objfile
;
11607 struct comp_unit_head
*cu_header
= &cu
->header
;
11609 /* NOTE drow/2003-01-30: There used to be a comment and some special
11610 code here to turn a symbol with DW_AT_external and a
11611 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
11612 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
11613 with some versions of binutils) where shared libraries could have
11614 relocations against symbols in their debug information - the
11615 minimal symbol would have the right address, but the debug info
11616 would not. It's no longer necessary, because we will explicitly
11617 apply relocations when we read in the debug information now. */
11619 /* A DW_AT_location attribute with no contents indicates that a
11620 variable has been optimized away. */
11621 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
11623 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11627 /* Handle one degenerate form of location expression specially, to
11628 preserve GDB's previous behavior when section offsets are
11629 specified. If this is just a DW_OP_addr then mark this symbol
11632 if (attr_form_is_block (attr
)
11633 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
11634 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
11636 unsigned int dummy
;
11638 SYMBOL_VALUE_ADDRESS (sym
) =
11639 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
11640 SYMBOL_CLASS (sym
) = LOC_STATIC
;
11641 fixup_symbol_section (sym
, objfile
);
11642 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
11643 SYMBOL_SECTION (sym
));
11647 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
11648 expression evaluator, and use LOC_COMPUTED only when necessary
11649 (i.e. when the value of a register or memory location is
11650 referenced, or a thread-local block, etc.). Then again, it might
11651 not be worthwhile. I'm assuming that it isn't unless performance
11652 or memory numbers show me otherwise. */
11654 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
11655 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11657 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
11658 cu
->has_loclist
= 1;
11661 /* Given a pointer to a DWARF information entry, figure out if we need
11662 to make a symbol table entry for it, and if so, create a new entry
11663 and return a pointer to it.
11664 If TYPE is NULL, determine symbol type from the die, otherwise
11665 used the passed type.
11666 If SPACE is not NULL, use it to hold the new symbol. If it is
11667 NULL, allocate a new symbol on the objfile's obstack. */
11669 static struct symbol
*
11670 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
11671 struct symbol
*space
)
11673 struct objfile
*objfile
= cu
->objfile
;
11674 struct symbol
*sym
= NULL
;
11676 struct attribute
*attr
= NULL
;
11677 struct attribute
*attr2
= NULL
;
11678 CORE_ADDR baseaddr
;
11679 struct pending
**list_to_add
= NULL
;
11681 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
11683 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11685 name
= dwarf2_name (die
, cu
);
11688 const char *linkagename
;
11689 int suppress_add
= 0;
11694 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
11695 OBJSTAT (objfile
, n_syms
++);
11697 /* Cache this symbol's name and the name's demangled form (if any). */
11698 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
11699 linkagename
= dwarf2_physname (name
, die
, cu
);
11700 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
11702 /* Fortran does not have mangling standard and the mangling does differ
11703 between gfortran, iFort etc. */
11704 if (cu
->language
== language_fortran
11705 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
11706 symbol_set_demangled_name (&(sym
->ginfo
),
11707 (char *) dwarf2_full_name (name
, die
, cu
),
11710 /* Default assumptions.
11711 Use the passed type or decode it from the die. */
11712 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11713 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11715 SYMBOL_TYPE (sym
) = type
;
11717 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
11718 attr
= dwarf2_attr (die
,
11719 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
11723 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
11726 attr
= dwarf2_attr (die
,
11727 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
11731 int file_index
= DW_UNSND (attr
);
11733 if (cu
->line_header
== NULL
11734 || file_index
> cu
->line_header
->num_file_names
)
11735 complaint (&symfile_complaints
,
11736 _("file index out of range"));
11737 else if (file_index
> 0)
11739 struct file_entry
*fe
;
11741 fe
= &cu
->line_header
->file_names
[file_index
- 1];
11742 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
11749 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11752 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
11754 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
11755 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
11756 SYMBOL_CLASS (sym
) = LOC_LABEL
;
11757 add_symbol_to_list (sym
, cu
->list_in_scope
);
11759 case DW_TAG_subprogram
:
11760 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11762 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11763 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11764 if ((attr2
&& (DW_UNSND (attr2
) != 0))
11765 || cu
->language
== language_ada
)
11767 /* Subprograms marked external are stored as a global symbol.
11768 Ada subprograms, whether marked external or not, are always
11769 stored as a global symbol, because we want to be able to
11770 access them globally. For instance, we want to be able
11771 to break on a nested subprogram without having to
11772 specify the context. */
11773 list_to_add
= &global_symbols
;
11777 list_to_add
= cu
->list_in_scope
;
11780 case DW_TAG_inlined_subroutine
:
11781 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11783 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11784 SYMBOL_INLINED (sym
) = 1;
11785 list_to_add
= cu
->list_in_scope
;
11787 case DW_TAG_template_value_param
:
11789 /* Fall through. */
11790 case DW_TAG_constant
:
11791 case DW_TAG_variable
:
11792 case DW_TAG_member
:
11793 /* Compilation with minimal debug info may result in
11794 variables with missing type entries. Change the
11795 misleading `void' type to something sensible. */
11796 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
11798 = objfile_type (objfile
)->nodebug_data_symbol
;
11800 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11801 /* In the case of DW_TAG_member, we should only be called for
11802 static const members. */
11803 if (die
->tag
== DW_TAG_member
)
11805 /* dwarf2_add_field uses die_is_declaration,
11806 so we do the same. */
11807 gdb_assert (die_is_declaration (die
, cu
));
11812 dwarf2_const_value (attr
, sym
, cu
);
11813 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11816 if (attr2
&& (DW_UNSND (attr2
) != 0))
11817 list_to_add
= &global_symbols
;
11819 list_to_add
= cu
->list_in_scope
;
11823 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11826 var_decode_location (attr
, sym
, cu
);
11827 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11828 if (SYMBOL_CLASS (sym
) == LOC_STATIC
11829 && SYMBOL_VALUE_ADDRESS (sym
) == 0
11830 && !dwarf2_per_objfile
->has_section_at_zero
)
11832 /* When a static variable is eliminated by the linker,
11833 the corresponding debug information is not stripped
11834 out, but the variable address is set to null;
11835 do not add such variables into symbol table. */
11837 else if (attr2
&& (DW_UNSND (attr2
) != 0))
11839 /* Workaround gfortran PR debug/40040 - it uses
11840 DW_AT_location for variables in -fPIC libraries which may
11841 get overriden by other libraries/executable and get
11842 a different address. Resolve it by the minimal symbol
11843 which may come from inferior's executable using copy
11844 relocation. Make this workaround only for gfortran as for
11845 other compilers GDB cannot guess the minimal symbol
11846 Fortran mangling kind. */
11847 if (cu
->language
== language_fortran
&& die
->parent
11848 && die
->parent
->tag
== DW_TAG_module
11850 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
11851 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11853 /* A variable with DW_AT_external is never static,
11854 but it may be block-scoped. */
11855 list_to_add
= (cu
->list_in_scope
== &file_symbols
11856 ? &global_symbols
: cu
->list_in_scope
);
11859 list_to_add
= cu
->list_in_scope
;
11863 /* We do not know the address of this symbol.
11864 If it is an external symbol and we have type information
11865 for it, enter the symbol as a LOC_UNRESOLVED symbol.
11866 The address of the variable will then be determined from
11867 the minimal symbol table whenever the variable is
11869 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11870 if (attr2
&& (DW_UNSND (attr2
) != 0)
11871 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
11873 /* A variable with DW_AT_external is never static, but it
11874 may be block-scoped. */
11875 list_to_add
= (cu
->list_in_scope
== &file_symbols
11876 ? &global_symbols
: cu
->list_in_scope
);
11878 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11880 else if (!die_is_declaration (die
, cu
))
11882 /* Use the default LOC_OPTIMIZED_OUT class. */
11883 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
11885 list_to_add
= cu
->list_in_scope
;
11889 case DW_TAG_formal_parameter
:
11890 /* If we are inside a function, mark this as an argument. If
11891 not, we might be looking at an argument to an inlined function
11892 when we do not have enough information to show inlined frames;
11893 pretend it's a local variable in that case so that the user can
11895 if (context_stack_depth
> 0
11896 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
11897 SYMBOL_IS_ARGUMENT (sym
) = 1;
11898 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11901 var_decode_location (attr
, sym
, cu
);
11903 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11906 dwarf2_const_value (attr
, sym
, cu
);
11909 list_to_add
= cu
->list_in_scope
;
11911 case DW_TAG_unspecified_parameters
:
11912 /* From varargs functions; gdb doesn't seem to have any
11913 interest in this information, so just ignore it for now.
11916 case DW_TAG_template_type_param
:
11918 /* Fall through. */
11919 case DW_TAG_class_type
:
11920 case DW_TAG_interface_type
:
11921 case DW_TAG_structure_type
:
11922 case DW_TAG_union_type
:
11923 case DW_TAG_set_type
:
11924 case DW_TAG_enumeration_type
:
11925 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11926 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
11929 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
11930 really ever be static objects: otherwise, if you try
11931 to, say, break of a class's method and you're in a file
11932 which doesn't mention that class, it won't work unless
11933 the check for all static symbols in lookup_symbol_aux
11934 saves you. See the OtherFileClass tests in
11935 gdb.c++/namespace.exp. */
11939 list_to_add
= (cu
->list_in_scope
== &file_symbols
11940 && (cu
->language
== language_cplus
11941 || cu
->language
== language_java
)
11942 ? &global_symbols
: cu
->list_in_scope
);
11944 /* The semantics of C++ state that "struct foo {
11945 ... }" also defines a typedef for "foo". A Java
11946 class declaration also defines a typedef for the
11948 if (cu
->language
== language_cplus
11949 || cu
->language
== language_java
11950 || cu
->language
== language_ada
)
11952 /* The symbol's name is already allocated along
11953 with this objfile, so we don't need to
11954 duplicate it for the type. */
11955 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
11956 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
11961 case DW_TAG_typedef
:
11962 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11963 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11964 list_to_add
= cu
->list_in_scope
;
11966 case DW_TAG_base_type
:
11967 case DW_TAG_subrange_type
:
11968 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11969 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11970 list_to_add
= cu
->list_in_scope
;
11972 case DW_TAG_enumerator
:
11973 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11976 dwarf2_const_value (attr
, sym
, cu
);
11979 /* NOTE: carlton/2003-11-10: See comment above in the
11980 DW_TAG_class_type, etc. block. */
11982 list_to_add
= (cu
->list_in_scope
== &file_symbols
11983 && (cu
->language
== language_cplus
11984 || cu
->language
== language_java
)
11985 ? &global_symbols
: cu
->list_in_scope
);
11988 case DW_TAG_namespace
:
11989 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11990 list_to_add
= &global_symbols
;
11993 /* Not a tag we recognize. Hopefully we aren't processing
11994 trash data, but since we must specifically ignore things
11995 we don't recognize, there is nothing else we should do at
11997 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
11998 dwarf_tag_name (die
->tag
));
12004 sym
->hash_next
= objfile
->template_symbols
;
12005 objfile
->template_symbols
= sym
;
12006 list_to_add
= NULL
;
12009 if (list_to_add
!= NULL
)
12010 add_symbol_to_list (sym
, list_to_add
);
12012 /* For the benefit of old versions of GCC, check for anonymous
12013 namespaces based on the demangled name. */
12014 if (!processing_has_namespace_info
12015 && cu
->language
== language_cplus
)
12016 cp_scan_for_anonymous_namespaces (sym
, objfile
);
12021 /* A wrapper for new_symbol_full that always allocates a new symbol. */
12023 static struct symbol
*
12024 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
12026 return new_symbol_full (die
, type
, cu
, NULL
);
12029 /* Given an attr with a DW_FORM_dataN value in host byte order,
12030 zero-extend it as appropriate for the symbol's type. The DWARF
12031 standard (v4) is not entirely clear about the meaning of using
12032 DW_FORM_dataN for a constant with a signed type, where the type is
12033 wider than the data. The conclusion of a discussion on the DWARF
12034 list was that this is unspecified. We choose to always zero-extend
12035 because that is the interpretation long in use by GCC. */
12038 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
12039 const char *name
, struct obstack
*obstack
,
12040 struct dwarf2_cu
*cu
, long *value
, int bits
)
12042 struct objfile
*objfile
= cu
->objfile
;
12043 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
12044 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
12045 LONGEST l
= DW_UNSND (attr
);
12047 if (bits
< sizeof (*value
) * 8)
12049 l
&= ((LONGEST
) 1 << bits
) - 1;
12052 else if (bits
== sizeof (*value
) * 8)
12056 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
12057 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
12064 /* Read a constant value from an attribute. Either set *VALUE, or if
12065 the value does not fit in *VALUE, set *BYTES - either already
12066 allocated on the objfile obstack, or newly allocated on OBSTACK,
12067 or, set *BATON, if we translated the constant to a location
12071 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
12072 const char *name
, struct obstack
*obstack
,
12073 struct dwarf2_cu
*cu
,
12074 long *value
, gdb_byte
**bytes
,
12075 struct dwarf2_locexpr_baton
**baton
)
12077 struct objfile
*objfile
= cu
->objfile
;
12078 struct comp_unit_head
*cu_header
= &cu
->header
;
12079 struct dwarf_block
*blk
;
12080 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
12081 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
12087 switch (attr
->form
)
12093 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
12094 dwarf2_const_value_length_mismatch_complaint (name
,
12095 cu_header
->addr_size
,
12096 TYPE_LENGTH (type
));
12097 /* Symbols of this form are reasonably rare, so we just
12098 piggyback on the existing location code rather than writing
12099 a new implementation of symbol_computed_ops. */
12100 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
12101 sizeof (struct dwarf2_locexpr_baton
));
12102 (*baton
)->per_cu
= cu
->per_cu
;
12103 gdb_assert ((*baton
)->per_cu
);
12105 (*baton
)->size
= 2 + cu_header
->addr_size
;
12106 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
12107 (*baton
)->data
= data
;
12109 data
[0] = DW_OP_addr
;
12110 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
12111 byte_order
, DW_ADDR (attr
));
12112 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
12115 case DW_FORM_string
:
12117 /* DW_STRING is already allocated on the objfile obstack, point
12119 *bytes
= (gdb_byte
*) DW_STRING (attr
);
12121 case DW_FORM_block1
:
12122 case DW_FORM_block2
:
12123 case DW_FORM_block4
:
12124 case DW_FORM_block
:
12125 case DW_FORM_exprloc
:
12126 blk
= DW_BLOCK (attr
);
12127 if (TYPE_LENGTH (type
) != blk
->size
)
12128 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
12129 TYPE_LENGTH (type
));
12130 *bytes
= blk
->data
;
12133 /* The DW_AT_const_value attributes are supposed to carry the
12134 symbol's value "represented as it would be on the target
12135 architecture." By the time we get here, it's already been
12136 converted to host endianness, so we just need to sign- or
12137 zero-extend it as appropriate. */
12138 case DW_FORM_data1
:
12139 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12140 obstack
, cu
, value
, 8);
12142 case DW_FORM_data2
:
12143 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12144 obstack
, cu
, value
, 16);
12146 case DW_FORM_data4
:
12147 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12148 obstack
, cu
, value
, 32);
12150 case DW_FORM_data8
:
12151 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12152 obstack
, cu
, value
, 64);
12155 case DW_FORM_sdata
:
12156 *value
= DW_SND (attr
);
12159 case DW_FORM_udata
:
12160 *value
= DW_UNSND (attr
);
12164 complaint (&symfile_complaints
,
12165 _("unsupported const value attribute form: '%s'"),
12166 dwarf_form_name (attr
->form
));
12173 /* Copy constant value from an attribute to a symbol. */
12176 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
12177 struct dwarf2_cu
*cu
)
12179 struct objfile
*objfile
= cu
->objfile
;
12180 struct comp_unit_head
*cu_header
= &cu
->header
;
12183 struct dwarf2_locexpr_baton
*baton
;
12185 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
12186 SYMBOL_PRINT_NAME (sym
),
12187 &objfile
->objfile_obstack
, cu
,
12188 &value
, &bytes
, &baton
);
12192 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
12193 SYMBOL_LOCATION_BATON (sym
) = baton
;
12194 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
12196 else if (bytes
!= NULL
)
12198 SYMBOL_VALUE_BYTES (sym
) = bytes
;
12199 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
12203 SYMBOL_VALUE (sym
) = value
;
12204 SYMBOL_CLASS (sym
) = LOC_CONST
;
12208 /* Return the type of the die in question using its DW_AT_type attribute. */
12210 static struct type
*
12211 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12213 struct attribute
*type_attr
;
12215 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
12218 /* A missing DW_AT_type represents a void type. */
12219 return objfile_type (cu
->objfile
)->builtin_void
;
12222 return lookup_die_type (die
, type_attr
, cu
);
12225 /* True iff CU's producer generates GNAT Ada auxiliary information
12226 that allows to find parallel types through that information instead
12227 of having to do expensive parallel lookups by type name. */
12230 need_gnat_info (struct dwarf2_cu
*cu
)
12232 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
12233 of GNAT produces this auxiliary information, without any indication
12234 that it is produced. Part of enhancing the FSF version of GNAT
12235 to produce that information will be to put in place an indicator
12236 that we can use in order to determine whether the descriptive type
12237 info is available or not. One suggestion that has been made is
12238 to use a new attribute, attached to the CU die. For now, assume
12239 that the descriptive type info is not available. */
12243 /* Return the auxiliary type of the die in question using its
12244 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
12245 attribute is not present. */
12247 static struct type
*
12248 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12250 struct attribute
*type_attr
;
12252 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
12256 return lookup_die_type (die
, type_attr
, cu
);
12259 /* If DIE has a descriptive_type attribute, then set the TYPE's
12260 descriptive type accordingly. */
12263 set_descriptive_type (struct type
*type
, struct die_info
*die
,
12264 struct dwarf2_cu
*cu
)
12266 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
12268 if (descriptive_type
)
12270 ALLOCATE_GNAT_AUX_TYPE (type
);
12271 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
12275 /* Return the containing type of the die in question using its
12276 DW_AT_containing_type attribute. */
12278 static struct type
*
12279 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12281 struct attribute
*type_attr
;
12283 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
12285 error (_("Dwarf Error: Problem turning containing type into gdb type "
12286 "[in module %s]"), cu
->objfile
->name
);
12288 return lookup_die_type (die
, type_attr
, cu
);
12291 /* Look up the type of DIE in CU using its type attribute ATTR.
12292 If there is no type substitute an error marker. */
12294 static struct type
*
12295 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
12296 struct dwarf2_cu
*cu
)
12298 struct objfile
*objfile
= cu
->objfile
;
12299 struct type
*this_type
;
12301 /* First see if we have it cached. */
12303 if (is_ref_attr (attr
))
12305 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
12307 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
12309 else if (attr
->form
== DW_FORM_ref_sig8
)
12311 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
12312 struct dwarf2_cu
*sig_cu
;
12313 sect_offset offset
;
12315 /* sig_type will be NULL if the signatured type is missing from
12317 if (sig_type
== NULL
)
12318 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
12319 "at 0x%x [in module %s]"),
12320 die
->offset
.sect_off
, objfile
->name
);
12322 gdb_assert (sig_type
->per_cu
.debug_types_section
);
12323 offset
.sect_off
= (sig_type
->per_cu
.offset
.sect_off
12324 + sig_type
->type_offset
.cu_off
);
12325 this_type
= get_die_type_at_offset (offset
, &sig_type
->per_cu
);
12329 dump_die_for_error (die
);
12330 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
12331 dwarf_attr_name (attr
->name
), objfile
->name
);
12334 /* If not cached we need to read it in. */
12336 if (this_type
== NULL
)
12338 struct die_info
*type_die
;
12339 struct dwarf2_cu
*type_cu
= cu
;
12341 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
12342 /* If the type is cached, we should have found it above. */
12343 gdb_assert (get_die_type (type_die
, type_cu
) == NULL
);
12344 this_type
= read_type_die_1 (type_die
, type_cu
);
12347 /* If we still don't have a type use an error marker. */
12349 if (this_type
== NULL
)
12351 char *message
, *saved
;
12353 /* read_type_die already issued a complaint. */
12354 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
12356 cu
->header
.offset
.sect_off
,
12357 die
->offset
.sect_off
);
12358 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
12359 message
, strlen (message
));
12362 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
12368 /* Return the type in DIE, CU.
12369 Returns NULL for invalid types.
12371 This first does a lookup in the appropriate type_hash table,
12372 and only reads the die in if necessary.
12374 NOTE: This can be called when reading in partial or full symbols. */
12376 static struct type
*
12377 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
12379 struct type
*this_type
;
12381 this_type
= get_die_type (die
, cu
);
12385 return read_type_die_1 (die
, cu
);
12388 /* Read the type in DIE, CU.
12389 Returns NULL for invalid types. */
12391 static struct type
*
12392 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
12394 struct type
*this_type
= NULL
;
12398 case DW_TAG_class_type
:
12399 case DW_TAG_interface_type
:
12400 case DW_TAG_structure_type
:
12401 case DW_TAG_union_type
:
12402 this_type
= read_structure_type (die
, cu
);
12404 case DW_TAG_enumeration_type
:
12405 this_type
= read_enumeration_type (die
, cu
);
12407 case DW_TAG_subprogram
:
12408 case DW_TAG_subroutine_type
:
12409 case DW_TAG_inlined_subroutine
:
12410 this_type
= read_subroutine_type (die
, cu
);
12412 case DW_TAG_array_type
:
12413 this_type
= read_array_type (die
, cu
);
12415 case DW_TAG_set_type
:
12416 this_type
= read_set_type (die
, cu
);
12418 case DW_TAG_pointer_type
:
12419 this_type
= read_tag_pointer_type (die
, cu
);
12421 case DW_TAG_ptr_to_member_type
:
12422 this_type
= read_tag_ptr_to_member_type (die
, cu
);
12424 case DW_TAG_reference_type
:
12425 this_type
= read_tag_reference_type (die
, cu
);
12427 case DW_TAG_const_type
:
12428 this_type
= read_tag_const_type (die
, cu
);
12430 case DW_TAG_volatile_type
:
12431 this_type
= read_tag_volatile_type (die
, cu
);
12433 case DW_TAG_string_type
:
12434 this_type
= read_tag_string_type (die
, cu
);
12436 case DW_TAG_typedef
:
12437 this_type
= read_typedef (die
, cu
);
12439 case DW_TAG_subrange_type
:
12440 this_type
= read_subrange_type (die
, cu
);
12442 case DW_TAG_base_type
:
12443 this_type
= read_base_type (die
, cu
);
12445 case DW_TAG_unspecified_type
:
12446 this_type
= read_unspecified_type (die
, cu
);
12448 case DW_TAG_namespace
:
12449 this_type
= read_namespace_type (die
, cu
);
12451 case DW_TAG_module
:
12452 this_type
= read_module_type (die
, cu
);
12455 complaint (&symfile_complaints
,
12456 _("unexpected tag in read_type_die: '%s'"),
12457 dwarf_tag_name (die
->tag
));
12464 /* See if we can figure out if the class lives in a namespace. We do
12465 this by looking for a member function; its demangled name will
12466 contain namespace info, if there is any.
12467 Return the computed name or NULL.
12468 Space for the result is allocated on the objfile's obstack.
12469 This is the full-die version of guess_partial_die_structure_name.
12470 In this case we know DIE has no useful parent. */
12473 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12475 struct die_info
*spec_die
;
12476 struct dwarf2_cu
*spec_cu
;
12477 struct die_info
*child
;
12480 spec_die
= die_specification (die
, &spec_cu
);
12481 if (spec_die
!= NULL
)
12487 for (child
= die
->child
;
12489 child
= child
->sibling
)
12491 if (child
->tag
== DW_TAG_subprogram
)
12493 struct attribute
*attr
;
12495 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
12497 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
12501 = language_class_name_from_physname (cu
->language_defn
,
12505 if (actual_name
!= NULL
)
12507 char *die_name
= dwarf2_name (die
, cu
);
12509 if (die_name
!= NULL
12510 && strcmp (die_name
, actual_name
) != 0)
12512 /* Strip off the class name from the full name.
12513 We want the prefix. */
12514 int die_name_len
= strlen (die_name
);
12515 int actual_name_len
= strlen (actual_name
);
12517 /* Test for '::' as a sanity check. */
12518 if (actual_name_len
> die_name_len
+ 2
12519 && actual_name
[actual_name_len
12520 - die_name_len
- 1] == ':')
12522 obsavestring (actual_name
,
12523 actual_name_len
- die_name_len
- 2,
12524 &cu
->objfile
->objfile_obstack
);
12527 xfree (actual_name
);
12536 /* GCC might emit a nameless typedef that has a linkage name. Determine the
12537 prefix part in such case. See
12538 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12541 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
12543 struct attribute
*attr
;
12546 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
12547 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
12550 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
12551 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
12554 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
12556 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
12557 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
12560 /* dwarf2_name had to be already called. */
12561 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
12563 /* Strip the base name, keep any leading namespaces/classes. */
12564 base
= strrchr (DW_STRING (attr
), ':');
12565 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
12568 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
12569 &cu
->objfile
->objfile_obstack
);
12572 /* Return the name of the namespace/class that DIE is defined within,
12573 or "" if we can't tell. The caller should not xfree the result.
12575 For example, if we're within the method foo() in the following
12585 then determine_prefix on foo's die will return "N::C". */
12587 static const char *
12588 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
12590 struct die_info
*parent
, *spec_die
;
12591 struct dwarf2_cu
*spec_cu
;
12592 struct type
*parent_type
;
12595 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
12596 && cu
->language
!= language_fortran
)
12599 retval
= anonymous_struct_prefix (die
, cu
);
12603 /* We have to be careful in the presence of DW_AT_specification.
12604 For example, with GCC 3.4, given the code
12608 // Definition of N::foo.
12612 then we'll have a tree of DIEs like this:
12614 1: DW_TAG_compile_unit
12615 2: DW_TAG_namespace // N
12616 3: DW_TAG_subprogram // declaration of N::foo
12617 4: DW_TAG_subprogram // definition of N::foo
12618 DW_AT_specification // refers to die #3
12620 Thus, when processing die #4, we have to pretend that we're in
12621 the context of its DW_AT_specification, namely the contex of die
12624 spec_die
= die_specification (die
, &spec_cu
);
12625 if (spec_die
== NULL
)
12626 parent
= die
->parent
;
12629 parent
= spec_die
->parent
;
12633 if (parent
== NULL
)
12635 else if (parent
->building_fullname
)
12638 const char *parent_name
;
12640 /* It has been seen on RealView 2.2 built binaries,
12641 DW_TAG_template_type_param types actually _defined_ as
12642 children of the parent class:
12645 template class <class Enum> Class{};
12646 Class<enum E> class_e;
12648 1: DW_TAG_class_type (Class)
12649 2: DW_TAG_enumeration_type (E)
12650 3: DW_TAG_enumerator (enum1:0)
12651 3: DW_TAG_enumerator (enum2:1)
12653 2: DW_TAG_template_type_param
12654 DW_AT_type DW_FORM_ref_udata (E)
12656 Besides being broken debug info, it can put GDB into an
12657 infinite loop. Consider:
12659 When we're building the full name for Class<E>, we'll start
12660 at Class, and go look over its template type parameters,
12661 finding E. We'll then try to build the full name of E, and
12662 reach here. We're now trying to build the full name of E,
12663 and look over the parent DIE for containing scope. In the
12664 broken case, if we followed the parent DIE of E, we'd again
12665 find Class, and once again go look at its template type
12666 arguments, etc., etc. Simply don't consider such parent die
12667 as source-level parent of this die (it can't be, the language
12668 doesn't allow it), and break the loop here. */
12669 name
= dwarf2_name (die
, cu
);
12670 parent_name
= dwarf2_name (parent
, cu
);
12671 complaint (&symfile_complaints
,
12672 _("template param type '%s' defined within parent '%s'"),
12673 name
? name
: "<unknown>",
12674 parent_name
? parent_name
: "<unknown>");
12678 switch (parent
->tag
)
12680 case DW_TAG_namespace
:
12681 parent_type
= read_type_die (parent
, cu
);
12682 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
12683 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
12684 Work around this problem here. */
12685 if (cu
->language
== language_cplus
12686 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
12688 /* We give a name to even anonymous namespaces. */
12689 return TYPE_TAG_NAME (parent_type
);
12690 case DW_TAG_class_type
:
12691 case DW_TAG_interface_type
:
12692 case DW_TAG_structure_type
:
12693 case DW_TAG_union_type
:
12694 case DW_TAG_module
:
12695 parent_type
= read_type_die (parent
, cu
);
12696 if (TYPE_TAG_NAME (parent_type
) != NULL
)
12697 return TYPE_TAG_NAME (parent_type
);
12699 /* An anonymous structure is only allowed non-static data
12700 members; no typedefs, no member functions, et cetera.
12701 So it does not need a prefix. */
12703 case DW_TAG_compile_unit
:
12704 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
12705 if (cu
->language
== language_cplus
12706 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
12707 && die
->child
!= NULL
12708 && (die
->tag
== DW_TAG_class_type
12709 || die
->tag
== DW_TAG_structure_type
12710 || die
->tag
== DW_TAG_union_type
))
12712 char *name
= guess_full_die_structure_name (die
, cu
);
12718 return determine_prefix (parent
, cu
);
12722 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
12723 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
12724 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
12725 an obconcat, otherwise allocate storage for the result. The CU argument is
12726 used to determine the language and hence, the appropriate separator. */
12728 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
12731 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
12732 int physname
, struct dwarf2_cu
*cu
)
12734 const char *lead
= "";
12737 if (suffix
== NULL
|| suffix
[0] == '\0'
12738 || prefix
== NULL
|| prefix
[0] == '\0')
12740 else if (cu
->language
== language_java
)
12742 else if (cu
->language
== language_fortran
&& physname
)
12744 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
12745 DW_AT_MIPS_linkage_name is preferred and used instead. */
12753 if (prefix
== NULL
)
12755 if (suffix
== NULL
)
12761 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
12763 strcpy (retval
, lead
);
12764 strcat (retval
, prefix
);
12765 strcat (retval
, sep
);
12766 strcat (retval
, suffix
);
12771 /* We have an obstack. */
12772 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
12776 /* Return sibling of die, NULL if no sibling. */
12778 static struct die_info
*
12779 sibling_die (struct die_info
*die
)
12781 return die
->sibling
;
12784 /* Get name of a die, return NULL if not found. */
12787 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
12788 struct obstack
*obstack
)
12790 if (name
&& cu
->language
== language_cplus
)
12792 char *canon_name
= cp_canonicalize_string (name
);
12794 if (canon_name
!= NULL
)
12796 if (strcmp (canon_name
, name
) != 0)
12797 name
= obsavestring (canon_name
, strlen (canon_name
),
12799 xfree (canon_name
);
12806 /* Get name of a die, return NULL if not found. */
12809 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12811 struct attribute
*attr
;
12813 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
12814 if ((!attr
|| !DW_STRING (attr
))
12815 && die
->tag
!= DW_TAG_class_type
12816 && die
->tag
!= DW_TAG_interface_type
12817 && die
->tag
!= DW_TAG_structure_type
12818 && die
->tag
!= DW_TAG_union_type
)
12823 case DW_TAG_compile_unit
:
12824 /* Compilation units have a DW_AT_name that is a filename, not
12825 a source language identifier. */
12826 case DW_TAG_enumeration_type
:
12827 case DW_TAG_enumerator
:
12828 /* These tags always have simple identifiers already; no need
12829 to canonicalize them. */
12830 return DW_STRING (attr
);
12832 case DW_TAG_subprogram
:
12833 /* Java constructors will all be named "<init>", so return
12834 the class name when we see this special case. */
12835 if (cu
->language
== language_java
12836 && DW_STRING (attr
) != NULL
12837 && strcmp (DW_STRING (attr
), "<init>") == 0)
12839 struct dwarf2_cu
*spec_cu
= cu
;
12840 struct die_info
*spec_die
;
12842 /* GCJ will output '<init>' for Java constructor names.
12843 For this special case, return the name of the parent class. */
12845 /* GCJ may output suprogram DIEs with AT_specification set.
12846 If so, use the name of the specified DIE. */
12847 spec_die
= die_specification (die
, &spec_cu
);
12848 if (spec_die
!= NULL
)
12849 return dwarf2_name (spec_die
, spec_cu
);
12854 if (die
->tag
== DW_TAG_class_type
)
12855 return dwarf2_name (die
, cu
);
12857 while (die
->tag
!= DW_TAG_compile_unit
);
12861 case DW_TAG_class_type
:
12862 case DW_TAG_interface_type
:
12863 case DW_TAG_structure_type
:
12864 case DW_TAG_union_type
:
12865 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
12866 structures or unions. These were of the form "._%d" in GCC 4.1,
12867 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
12868 and GCC 4.4. We work around this problem by ignoring these. */
12869 if (attr
&& DW_STRING (attr
)
12870 && (strncmp (DW_STRING (attr
), "._", 2) == 0
12871 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
12874 /* GCC might emit a nameless typedef that has a linkage name. See
12875 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12876 if (!attr
|| DW_STRING (attr
) == NULL
)
12878 char *demangled
= NULL
;
12880 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
12882 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
12884 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
12887 /* Avoid demangling DW_STRING (attr) the second time on a second
12888 call for the same DIE. */
12889 if (!DW_STRING_IS_CANONICAL (attr
))
12890 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
12896 /* FIXME: we already did this for the partial symbol... */
12897 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
12898 &cu
->objfile
->objfile_obstack
);
12899 DW_STRING_IS_CANONICAL (attr
) = 1;
12902 /* Strip any leading namespaces/classes, keep only the base name.
12903 DW_AT_name for named DIEs does not contain the prefixes. */
12904 base
= strrchr (DW_STRING (attr
), ':');
12905 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
12908 return DW_STRING (attr
);
12917 if (!DW_STRING_IS_CANONICAL (attr
))
12920 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
12921 &cu
->objfile
->objfile_obstack
);
12922 DW_STRING_IS_CANONICAL (attr
) = 1;
12924 return DW_STRING (attr
);
12927 /* Return the die that this die in an extension of, or NULL if there
12928 is none. *EXT_CU is the CU containing DIE on input, and the CU
12929 containing the return value on output. */
12931 static struct die_info
*
12932 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
12934 struct attribute
*attr
;
12936 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
12940 return follow_die_ref (die
, attr
, ext_cu
);
12943 /* Convert a DIE tag into its string name. */
12946 dwarf_tag_name (unsigned tag
)
12950 case DW_TAG_padding
:
12951 return "DW_TAG_padding";
12952 case DW_TAG_array_type
:
12953 return "DW_TAG_array_type";
12954 case DW_TAG_class_type
:
12955 return "DW_TAG_class_type";
12956 case DW_TAG_entry_point
:
12957 return "DW_TAG_entry_point";
12958 case DW_TAG_enumeration_type
:
12959 return "DW_TAG_enumeration_type";
12960 case DW_TAG_formal_parameter
:
12961 return "DW_TAG_formal_parameter";
12962 case DW_TAG_imported_declaration
:
12963 return "DW_TAG_imported_declaration";
12965 return "DW_TAG_label";
12966 case DW_TAG_lexical_block
:
12967 return "DW_TAG_lexical_block";
12968 case DW_TAG_member
:
12969 return "DW_TAG_member";
12970 case DW_TAG_pointer_type
:
12971 return "DW_TAG_pointer_type";
12972 case DW_TAG_reference_type
:
12973 return "DW_TAG_reference_type";
12974 case DW_TAG_compile_unit
:
12975 return "DW_TAG_compile_unit";
12976 case DW_TAG_string_type
:
12977 return "DW_TAG_string_type";
12978 case DW_TAG_structure_type
:
12979 return "DW_TAG_structure_type";
12980 case DW_TAG_subroutine_type
:
12981 return "DW_TAG_subroutine_type";
12982 case DW_TAG_typedef
:
12983 return "DW_TAG_typedef";
12984 case DW_TAG_union_type
:
12985 return "DW_TAG_union_type";
12986 case DW_TAG_unspecified_parameters
:
12987 return "DW_TAG_unspecified_parameters";
12988 case DW_TAG_variant
:
12989 return "DW_TAG_variant";
12990 case DW_TAG_common_block
:
12991 return "DW_TAG_common_block";
12992 case DW_TAG_common_inclusion
:
12993 return "DW_TAG_common_inclusion";
12994 case DW_TAG_inheritance
:
12995 return "DW_TAG_inheritance";
12996 case DW_TAG_inlined_subroutine
:
12997 return "DW_TAG_inlined_subroutine";
12998 case DW_TAG_module
:
12999 return "DW_TAG_module";
13000 case DW_TAG_ptr_to_member_type
:
13001 return "DW_TAG_ptr_to_member_type";
13002 case DW_TAG_set_type
:
13003 return "DW_TAG_set_type";
13004 case DW_TAG_subrange_type
:
13005 return "DW_TAG_subrange_type";
13006 case DW_TAG_with_stmt
:
13007 return "DW_TAG_with_stmt";
13008 case DW_TAG_access_declaration
:
13009 return "DW_TAG_access_declaration";
13010 case DW_TAG_base_type
:
13011 return "DW_TAG_base_type";
13012 case DW_TAG_catch_block
:
13013 return "DW_TAG_catch_block";
13014 case DW_TAG_const_type
:
13015 return "DW_TAG_const_type";
13016 case DW_TAG_constant
:
13017 return "DW_TAG_constant";
13018 case DW_TAG_enumerator
:
13019 return "DW_TAG_enumerator";
13020 case DW_TAG_file_type
:
13021 return "DW_TAG_file_type";
13022 case DW_TAG_friend
:
13023 return "DW_TAG_friend";
13024 case DW_TAG_namelist
:
13025 return "DW_TAG_namelist";
13026 case DW_TAG_namelist_item
:
13027 return "DW_TAG_namelist_item";
13028 case DW_TAG_packed_type
:
13029 return "DW_TAG_packed_type";
13030 case DW_TAG_subprogram
:
13031 return "DW_TAG_subprogram";
13032 case DW_TAG_template_type_param
:
13033 return "DW_TAG_template_type_param";
13034 case DW_TAG_template_value_param
:
13035 return "DW_TAG_template_value_param";
13036 case DW_TAG_thrown_type
:
13037 return "DW_TAG_thrown_type";
13038 case DW_TAG_try_block
:
13039 return "DW_TAG_try_block";
13040 case DW_TAG_variant_part
:
13041 return "DW_TAG_variant_part";
13042 case DW_TAG_variable
:
13043 return "DW_TAG_variable";
13044 case DW_TAG_volatile_type
:
13045 return "DW_TAG_volatile_type";
13046 case DW_TAG_dwarf_procedure
:
13047 return "DW_TAG_dwarf_procedure";
13048 case DW_TAG_restrict_type
:
13049 return "DW_TAG_restrict_type";
13050 case DW_TAG_interface_type
:
13051 return "DW_TAG_interface_type";
13052 case DW_TAG_namespace
:
13053 return "DW_TAG_namespace";
13054 case DW_TAG_imported_module
:
13055 return "DW_TAG_imported_module";
13056 case DW_TAG_unspecified_type
:
13057 return "DW_TAG_unspecified_type";
13058 case DW_TAG_partial_unit
:
13059 return "DW_TAG_partial_unit";
13060 case DW_TAG_imported_unit
:
13061 return "DW_TAG_imported_unit";
13062 case DW_TAG_condition
:
13063 return "DW_TAG_condition";
13064 case DW_TAG_shared_type
:
13065 return "DW_TAG_shared_type";
13066 case DW_TAG_type_unit
:
13067 return "DW_TAG_type_unit";
13068 case DW_TAG_MIPS_loop
:
13069 return "DW_TAG_MIPS_loop";
13070 case DW_TAG_HP_array_descriptor
:
13071 return "DW_TAG_HP_array_descriptor";
13072 case DW_TAG_format_label
:
13073 return "DW_TAG_format_label";
13074 case DW_TAG_function_template
:
13075 return "DW_TAG_function_template";
13076 case DW_TAG_class_template
:
13077 return "DW_TAG_class_template";
13078 case DW_TAG_GNU_BINCL
:
13079 return "DW_TAG_GNU_BINCL";
13080 case DW_TAG_GNU_EINCL
:
13081 return "DW_TAG_GNU_EINCL";
13082 case DW_TAG_upc_shared_type
:
13083 return "DW_TAG_upc_shared_type";
13084 case DW_TAG_upc_strict_type
:
13085 return "DW_TAG_upc_strict_type";
13086 case DW_TAG_upc_relaxed_type
:
13087 return "DW_TAG_upc_relaxed_type";
13088 case DW_TAG_PGI_kanji_type
:
13089 return "DW_TAG_PGI_kanji_type";
13090 case DW_TAG_PGI_interface_block
:
13091 return "DW_TAG_PGI_interface_block";
13092 case DW_TAG_GNU_call_site
:
13093 return "DW_TAG_GNU_call_site";
13095 return "DW_TAG_<unknown>";
13099 /* Convert a DWARF attribute code into its string name. */
13102 dwarf_attr_name (unsigned attr
)
13106 case DW_AT_sibling
:
13107 return "DW_AT_sibling";
13108 case DW_AT_location
:
13109 return "DW_AT_location";
13111 return "DW_AT_name";
13112 case DW_AT_ordering
:
13113 return "DW_AT_ordering";
13114 case DW_AT_subscr_data
:
13115 return "DW_AT_subscr_data";
13116 case DW_AT_byte_size
:
13117 return "DW_AT_byte_size";
13118 case DW_AT_bit_offset
:
13119 return "DW_AT_bit_offset";
13120 case DW_AT_bit_size
:
13121 return "DW_AT_bit_size";
13122 case DW_AT_element_list
:
13123 return "DW_AT_element_list";
13124 case DW_AT_stmt_list
:
13125 return "DW_AT_stmt_list";
13127 return "DW_AT_low_pc";
13128 case DW_AT_high_pc
:
13129 return "DW_AT_high_pc";
13130 case DW_AT_language
:
13131 return "DW_AT_language";
13133 return "DW_AT_member";
13135 return "DW_AT_discr";
13136 case DW_AT_discr_value
:
13137 return "DW_AT_discr_value";
13138 case DW_AT_visibility
:
13139 return "DW_AT_visibility";
13141 return "DW_AT_import";
13142 case DW_AT_string_length
:
13143 return "DW_AT_string_length";
13144 case DW_AT_common_reference
:
13145 return "DW_AT_common_reference";
13146 case DW_AT_comp_dir
:
13147 return "DW_AT_comp_dir";
13148 case DW_AT_const_value
:
13149 return "DW_AT_const_value";
13150 case DW_AT_containing_type
:
13151 return "DW_AT_containing_type";
13152 case DW_AT_default_value
:
13153 return "DW_AT_default_value";
13155 return "DW_AT_inline";
13156 case DW_AT_is_optional
:
13157 return "DW_AT_is_optional";
13158 case DW_AT_lower_bound
:
13159 return "DW_AT_lower_bound";
13160 case DW_AT_producer
:
13161 return "DW_AT_producer";
13162 case DW_AT_prototyped
:
13163 return "DW_AT_prototyped";
13164 case DW_AT_return_addr
:
13165 return "DW_AT_return_addr";
13166 case DW_AT_start_scope
:
13167 return "DW_AT_start_scope";
13168 case DW_AT_bit_stride
:
13169 return "DW_AT_bit_stride";
13170 case DW_AT_upper_bound
:
13171 return "DW_AT_upper_bound";
13172 case DW_AT_abstract_origin
:
13173 return "DW_AT_abstract_origin";
13174 case DW_AT_accessibility
:
13175 return "DW_AT_accessibility";
13176 case DW_AT_address_class
:
13177 return "DW_AT_address_class";
13178 case DW_AT_artificial
:
13179 return "DW_AT_artificial";
13180 case DW_AT_base_types
:
13181 return "DW_AT_base_types";
13182 case DW_AT_calling_convention
:
13183 return "DW_AT_calling_convention";
13185 return "DW_AT_count";
13186 case DW_AT_data_member_location
:
13187 return "DW_AT_data_member_location";
13188 case DW_AT_decl_column
:
13189 return "DW_AT_decl_column";
13190 case DW_AT_decl_file
:
13191 return "DW_AT_decl_file";
13192 case DW_AT_decl_line
:
13193 return "DW_AT_decl_line";
13194 case DW_AT_declaration
:
13195 return "DW_AT_declaration";
13196 case DW_AT_discr_list
:
13197 return "DW_AT_discr_list";
13198 case DW_AT_encoding
:
13199 return "DW_AT_encoding";
13200 case DW_AT_external
:
13201 return "DW_AT_external";
13202 case DW_AT_frame_base
:
13203 return "DW_AT_frame_base";
13205 return "DW_AT_friend";
13206 case DW_AT_identifier_case
:
13207 return "DW_AT_identifier_case";
13208 case DW_AT_macro_info
:
13209 return "DW_AT_macro_info";
13210 case DW_AT_namelist_items
:
13211 return "DW_AT_namelist_items";
13212 case DW_AT_priority
:
13213 return "DW_AT_priority";
13214 case DW_AT_segment
:
13215 return "DW_AT_segment";
13216 case DW_AT_specification
:
13217 return "DW_AT_specification";
13218 case DW_AT_static_link
:
13219 return "DW_AT_static_link";
13221 return "DW_AT_type";
13222 case DW_AT_use_location
:
13223 return "DW_AT_use_location";
13224 case DW_AT_variable_parameter
:
13225 return "DW_AT_variable_parameter";
13226 case DW_AT_virtuality
:
13227 return "DW_AT_virtuality";
13228 case DW_AT_vtable_elem_location
:
13229 return "DW_AT_vtable_elem_location";
13230 /* DWARF 3 values. */
13231 case DW_AT_allocated
:
13232 return "DW_AT_allocated";
13233 case DW_AT_associated
:
13234 return "DW_AT_associated";
13235 case DW_AT_data_location
:
13236 return "DW_AT_data_location";
13237 case DW_AT_byte_stride
:
13238 return "DW_AT_byte_stride";
13239 case DW_AT_entry_pc
:
13240 return "DW_AT_entry_pc";
13241 case DW_AT_use_UTF8
:
13242 return "DW_AT_use_UTF8";
13243 case DW_AT_extension
:
13244 return "DW_AT_extension";
13246 return "DW_AT_ranges";
13247 case DW_AT_trampoline
:
13248 return "DW_AT_trampoline";
13249 case DW_AT_call_column
:
13250 return "DW_AT_call_column";
13251 case DW_AT_call_file
:
13252 return "DW_AT_call_file";
13253 case DW_AT_call_line
:
13254 return "DW_AT_call_line";
13255 case DW_AT_description
:
13256 return "DW_AT_description";
13257 case DW_AT_binary_scale
:
13258 return "DW_AT_binary_scale";
13259 case DW_AT_decimal_scale
:
13260 return "DW_AT_decimal_scale";
13262 return "DW_AT_small";
13263 case DW_AT_decimal_sign
:
13264 return "DW_AT_decimal_sign";
13265 case DW_AT_digit_count
:
13266 return "DW_AT_digit_count";
13267 case DW_AT_picture_string
:
13268 return "DW_AT_picture_string";
13269 case DW_AT_mutable
:
13270 return "DW_AT_mutable";
13271 case DW_AT_threads_scaled
:
13272 return "DW_AT_threads_scaled";
13273 case DW_AT_explicit
:
13274 return "DW_AT_explicit";
13275 case DW_AT_object_pointer
:
13276 return "DW_AT_object_pointer";
13277 case DW_AT_endianity
:
13278 return "DW_AT_endianity";
13279 case DW_AT_elemental
:
13280 return "DW_AT_elemental";
13282 return "DW_AT_pure";
13283 case DW_AT_recursive
:
13284 return "DW_AT_recursive";
13285 /* DWARF 4 values. */
13286 case DW_AT_signature
:
13287 return "DW_AT_signature";
13288 case DW_AT_linkage_name
:
13289 return "DW_AT_linkage_name";
13290 /* SGI/MIPS extensions. */
13291 #ifdef MIPS /* collides with DW_AT_HP_block_index */
13292 case DW_AT_MIPS_fde
:
13293 return "DW_AT_MIPS_fde";
13295 case DW_AT_MIPS_loop_begin
:
13296 return "DW_AT_MIPS_loop_begin";
13297 case DW_AT_MIPS_tail_loop_begin
:
13298 return "DW_AT_MIPS_tail_loop_begin";
13299 case DW_AT_MIPS_epilog_begin
:
13300 return "DW_AT_MIPS_epilog_begin";
13301 case DW_AT_MIPS_loop_unroll_factor
:
13302 return "DW_AT_MIPS_loop_unroll_factor";
13303 case DW_AT_MIPS_software_pipeline_depth
:
13304 return "DW_AT_MIPS_software_pipeline_depth";
13305 case DW_AT_MIPS_linkage_name
:
13306 return "DW_AT_MIPS_linkage_name";
13307 case DW_AT_MIPS_stride
:
13308 return "DW_AT_MIPS_stride";
13309 case DW_AT_MIPS_abstract_name
:
13310 return "DW_AT_MIPS_abstract_name";
13311 case DW_AT_MIPS_clone_origin
:
13312 return "DW_AT_MIPS_clone_origin";
13313 case DW_AT_MIPS_has_inlines
:
13314 return "DW_AT_MIPS_has_inlines";
13315 /* HP extensions. */
13316 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
13317 case DW_AT_HP_block_index
:
13318 return "DW_AT_HP_block_index";
13320 case DW_AT_HP_unmodifiable
:
13321 return "DW_AT_HP_unmodifiable";
13322 case DW_AT_HP_actuals_stmt_list
:
13323 return "DW_AT_HP_actuals_stmt_list";
13324 case DW_AT_HP_proc_per_section
:
13325 return "DW_AT_HP_proc_per_section";
13326 case DW_AT_HP_raw_data_ptr
:
13327 return "DW_AT_HP_raw_data_ptr";
13328 case DW_AT_HP_pass_by_reference
:
13329 return "DW_AT_HP_pass_by_reference";
13330 case DW_AT_HP_opt_level
:
13331 return "DW_AT_HP_opt_level";
13332 case DW_AT_HP_prof_version_id
:
13333 return "DW_AT_HP_prof_version_id";
13334 case DW_AT_HP_opt_flags
:
13335 return "DW_AT_HP_opt_flags";
13336 case DW_AT_HP_cold_region_low_pc
:
13337 return "DW_AT_HP_cold_region_low_pc";
13338 case DW_AT_HP_cold_region_high_pc
:
13339 return "DW_AT_HP_cold_region_high_pc";
13340 case DW_AT_HP_all_variables_modifiable
:
13341 return "DW_AT_HP_all_variables_modifiable";
13342 case DW_AT_HP_linkage_name
:
13343 return "DW_AT_HP_linkage_name";
13344 case DW_AT_HP_prof_flags
:
13345 return "DW_AT_HP_prof_flags";
13346 /* GNU extensions. */
13347 case DW_AT_sf_names
:
13348 return "DW_AT_sf_names";
13349 case DW_AT_src_info
:
13350 return "DW_AT_src_info";
13351 case DW_AT_mac_info
:
13352 return "DW_AT_mac_info";
13353 case DW_AT_src_coords
:
13354 return "DW_AT_src_coords";
13355 case DW_AT_body_begin
:
13356 return "DW_AT_body_begin";
13357 case DW_AT_body_end
:
13358 return "DW_AT_body_end";
13359 case DW_AT_GNU_vector
:
13360 return "DW_AT_GNU_vector";
13361 case DW_AT_GNU_odr_signature
:
13362 return "DW_AT_GNU_odr_signature";
13363 /* VMS extensions. */
13364 case DW_AT_VMS_rtnbeg_pd_address
:
13365 return "DW_AT_VMS_rtnbeg_pd_address";
13366 /* UPC extension. */
13367 case DW_AT_upc_threads_scaled
:
13368 return "DW_AT_upc_threads_scaled";
13369 /* PGI (STMicroelectronics) extensions. */
13370 case DW_AT_PGI_lbase
:
13371 return "DW_AT_PGI_lbase";
13372 case DW_AT_PGI_soffset
:
13373 return "DW_AT_PGI_soffset";
13374 case DW_AT_PGI_lstride
:
13375 return "DW_AT_PGI_lstride";
13377 return "DW_AT_<unknown>";
13381 /* Convert a DWARF value form code into its string name. */
13384 dwarf_form_name (unsigned form
)
13389 return "DW_FORM_addr";
13390 case DW_FORM_block2
:
13391 return "DW_FORM_block2";
13392 case DW_FORM_block4
:
13393 return "DW_FORM_block4";
13394 case DW_FORM_data2
:
13395 return "DW_FORM_data2";
13396 case DW_FORM_data4
:
13397 return "DW_FORM_data4";
13398 case DW_FORM_data8
:
13399 return "DW_FORM_data8";
13400 case DW_FORM_string
:
13401 return "DW_FORM_string";
13402 case DW_FORM_block
:
13403 return "DW_FORM_block";
13404 case DW_FORM_block1
:
13405 return "DW_FORM_block1";
13406 case DW_FORM_data1
:
13407 return "DW_FORM_data1";
13409 return "DW_FORM_flag";
13410 case DW_FORM_sdata
:
13411 return "DW_FORM_sdata";
13413 return "DW_FORM_strp";
13414 case DW_FORM_udata
:
13415 return "DW_FORM_udata";
13416 case DW_FORM_ref_addr
:
13417 return "DW_FORM_ref_addr";
13419 return "DW_FORM_ref1";
13421 return "DW_FORM_ref2";
13423 return "DW_FORM_ref4";
13425 return "DW_FORM_ref8";
13426 case DW_FORM_ref_udata
:
13427 return "DW_FORM_ref_udata";
13428 case DW_FORM_indirect
:
13429 return "DW_FORM_indirect";
13430 case DW_FORM_sec_offset
:
13431 return "DW_FORM_sec_offset";
13432 case DW_FORM_exprloc
:
13433 return "DW_FORM_exprloc";
13434 case DW_FORM_flag_present
:
13435 return "DW_FORM_flag_present";
13436 case DW_FORM_ref_sig8
:
13437 return "DW_FORM_ref_sig8";
13439 return "DW_FORM_<unknown>";
13443 /* Convert a DWARF stack opcode into its string name. */
13446 dwarf_stack_op_name (unsigned op
)
13451 return "DW_OP_addr";
13453 return "DW_OP_deref";
13454 case DW_OP_const1u
:
13455 return "DW_OP_const1u";
13456 case DW_OP_const1s
:
13457 return "DW_OP_const1s";
13458 case DW_OP_const2u
:
13459 return "DW_OP_const2u";
13460 case DW_OP_const2s
:
13461 return "DW_OP_const2s";
13462 case DW_OP_const4u
:
13463 return "DW_OP_const4u";
13464 case DW_OP_const4s
:
13465 return "DW_OP_const4s";
13466 case DW_OP_const8u
:
13467 return "DW_OP_const8u";
13468 case DW_OP_const8s
:
13469 return "DW_OP_const8s";
13471 return "DW_OP_constu";
13473 return "DW_OP_consts";
13475 return "DW_OP_dup";
13477 return "DW_OP_drop";
13479 return "DW_OP_over";
13481 return "DW_OP_pick";
13483 return "DW_OP_swap";
13485 return "DW_OP_rot";
13487 return "DW_OP_xderef";
13489 return "DW_OP_abs";
13491 return "DW_OP_and";
13493 return "DW_OP_div";
13495 return "DW_OP_minus";
13497 return "DW_OP_mod";
13499 return "DW_OP_mul";
13501 return "DW_OP_neg";
13503 return "DW_OP_not";
13507 return "DW_OP_plus";
13508 case DW_OP_plus_uconst
:
13509 return "DW_OP_plus_uconst";
13511 return "DW_OP_shl";
13513 return "DW_OP_shr";
13515 return "DW_OP_shra";
13517 return "DW_OP_xor";
13519 return "DW_OP_bra";
13533 return "DW_OP_skip";
13535 return "DW_OP_lit0";
13537 return "DW_OP_lit1";
13539 return "DW_OP_lit2";
13541 return "DW_OP_lit3";
13543 return "DW_OP_lit4";
13545 return "DW_OP_lit5";
13547 return "DW_OP_lit6";
13549 return "DW_OP_lit7";
13551 return "DW_OP_lit8";
13553 return "DW_OP_lit9";
13555 return "DW_OP_lit10";
13557 return "DW_OP_lit11";
13559 return "DW_OP_lit12";
13561 return "DW_OP_lit13";
13563 return "DW_OP_lit14";
13565 return "DW_OP_lit15";
13567 return "DW_OP_lit16";
13569 return "DW_OP_lit17";
13571 return "DW_OP_lit18";
13573 return "DW_OP_lit19";
13575 return "DW_OP_lit20";
13577 return "DW_OP_lit21";
13579 return "DW_OP_lit22";
13581 return "DW_OP_lit23";
13583 return "DW_OP_lit24";
13585 return "DW_OP_lit25";
13587 return "DW_OP_lit26";
13589 return "DW_OP_lit27";
13591 return "DW_OP_lit28";
13593 return "DW_OP_lit29";
13595 return "DW_OP_lit30";
13597 return "DW_OP_lit31";
13599 return "DW_OP_reg0";
13601 return "DW_OP_reg1";
13603 return "DW_OP_reg2";
13605 return "DW_OP_reg3";
13607 return "DW_OP_reg4";
13609 return "DW_OP_reg5";
13611 return "DW_OP_reg6";
13613 return "DW_OP_reg7";
13615 return "DW_OP_reg8";
13617 return "DW_OP_reg9";
13619 return "DW_OP_reg10";
13621 return "DW_OP_reg11";
13623 return "DW_OP_reg12";
13625 return "DW_OP_reg13";
13627 return "DW_OP_reg14";
13629 return "DW_OP_reg15";
13631 return "DW_OP_reg16";
13633 return "DW_OP_reg17";
13635 return "DW_OP_reg18";
13637 return "DW_OP_reg19";
13639 return "DW_OP_reg20";
13641 return "DW_OP_reg21";
13643 return "DW_OP_reg22";
13645 return "DW_OP_reg23";
13647 return "DW_OP_reg24";
13649 return "DW_OP_reg25";
13651 return "DW_OP_reg26";
13653 return "DW_OP_reg27";
13655 return "DW_OP_reg28";
13657 return "DW_OP_reg29";
13659 return "DW_OP_reg30";
13661 return "DW_OP_reg31";
13663 return "DW_OP_breg0";
13665 return "DW_OP_breg1";
13667 return "DW_OP_breg2";
13669 return "DW_OP_breg3";
13671 return "DW_OP_breg4";
13673 return "DW_OP_breg5";
13675 return "DW_OP_breg6";
13677 return "DW_OP_breg7";
13679 return "DW_OP_breg8";
13681 return "DW_OP_breg9";
13683 return "DW_OP_breg10";
13685 return "DW_OP_breg11";
13687 return "DW_OP_breg12";
13689 return "DW_OP_breg13";
13691 return "DW_OP_breg14";
13693 return "DW_OP_breg15";
13695 return "DW_OP_breg16";
13697 return "DW_OP_breg17";
13699 return "DW_OP_breg18";
13701 return "DW_OP_breg19";
13703 return "DW_OP_breg20";
13705 return "DW_OP_breg21";
13707 return "DW_OP_breg22";
13709 return "DW_OP_breg23";
13711 return "DW_OP_breg24";
13713 return "DW_OP_breg25";
13715 return "DW_OP_breg26";
13717 return "DW_OP_breg27";
13719 return "DW_OP_breg28";
13721 return "DW_OP_breg29";
13723 return "DW_OP_breg30";
13725 return "DW_OP_breg31";
13727 return "DW_OP_regx";
13729 return "DW_OP_fbreg";
13731 return "DW_OP_bregx";
13733 return "DW_OP_piece";
13734 case DW_OP_deref_size
:
13735 return "DW_OP_deref_size";
13736 case DW_OP_xderef_size
:
13737 return "DW_OP_xderef_size";
13739 return "DW_OP_nop";
13740 /* DWARF 3 extensions. */
13741 case DW_OP_push_object_address
:
13742 return "DW_OP_push_object_address";
13744 return "DW_OP_call2";
13746 return "DW_OP_call4";
13747 case DW_OP_call_ref
:
13748 return "DW_OP_call_ref";
13749 case DW_OP_form_tls_address
:
13750 return "DW_OP_form_tls_address";
13751 case DW_OP_call_frame_cfa
:
13752 return "DW_OP_call_frame_cfa";
13753 case DW_OP_bit_piece
:
13754 return "DW_OP_bit_piece";
13755 /* DWARF 4 extensions. */
13756 case DW_OP_implicit_value
:
13757 return "DW_OP_implicit_value";
13758 case DW_OP_stack_value
:
13759 return "DW_OP_stack_value";
13760 /* GNU extensions. */
13761 case DW_OP_GNU_push_tls_address
:
13762 return "DW_OP_GNU_push_tls_address";
13763 case DW_OP_GNU_uninit
:
13764 return "DW_OP_GNU_uninit";
13765 case DW_OP_GNU_encoded_addr
:
13766 return "DW_OP_GNU_encoded_addr";
13767 case DW_OP_GNU_implicit_pointer
:
13768 return "DW_OP_GNU_implicit_pointer";
13769 case DW_OP_GNU_entry_value
:
13770 return "DW_OP_GNU_entry_value";
13771 case DW_OP_GNU_const_type
:
13772 return "DW_OP_GNU_const_type";
13773 case DW_OP_GNU_regval_type
:
13774 return "DW_OP_GNU_regval_type";
13775 case DW_OP_GNU_deref_type
:
13776 return "DW_OP_GNU_deref_type";
13777 case DW_OP_GNU_convert
:
13778 return "DW_OP_GNU_convert";
13779 case DW_OP_GNU_reinterpret
:
13780 return "DW_OP_GNU_reinterpret";
13781 case DW_OP_GNU_parameter_ref
:
13782 return "DW_OP_GNU_parameter_ref";
13789 dwarf_bool_name (unsigned mybool
)
13797 /* Convert a DWARF type code into its string name. */
13800 dwarf_type_encoding_name (unsigned enc
)
13805 return "DW_ATE_void";
13806 case DW_ATE_address
:
13807 return "DW_ATE_address";
13808 case DW_ATE_boolean
:
13809 return "DW_ATE_boolean";
13810 case DW_ATE_complex_float
:
13811 return "DW_ATE_complex_float";
13813 return "DW_ATE_float";
13814 case DW_ATE_signed
:
13815 return "DW_ATE_signed";
13816 case DW_ATE_signed_char
:
13817 return "DW_ATE_signed_char";
13818 case DW_ATE_unsigned
:
13819 return "DW_ATE_unsigned";
13820 case DW_ATE_unsigned_char
:
13821 return "DW_ATE_unsigned_char";
13823 case DW_ATE_imaginary_float
:
13824 return "DW_ATE_imaginary_float";
13825 case DW_ATE_packed_decimal
:
13826 return "DW_ATE_packed_decimal";
13827 case DW_ATE_numeric_string
:
13828 return "DW_ATE_numeric_string";
13829 case DW_ATE_edited
:
13830 return "DW_ATE_edited";
13831 case DW_ATE_signed_fixed
:
13832 return "DW_ATE_signed_fixed";
13833 case DW_ATE_unsigned_fixed
:
13834 return "DW_ATE_unsigned_fixed";
13835 case DW_ATE_decimal_float
:
13836 return "DW_ATE_decimal_float";
13839 return "DW_ATE_UTF";
13840 /* HP extensions. */
13841 case DW_ATE_HP_float80
:
13842 return "DW_ATE_HP_float80";
13843 case DW_ATE_HP_complex_float80
:
13844 return "DW_ATE_HP_complex_float80";
13845 case DW_ATE_HP_float128
:
13846 return "DW_ATE_HP_float128";
13847 case DW_ATE_HP_complex_float128
:
13848 return "DW_ATE_HP_complex_float128";
13849 case DW_ATE_HP_floathpintel
:
13850 return "DW_ATE_HP_floathpintel";
13851 case DW_ATE_HP_imaginary_float80
:
13852 return "DW_ATE_HP_imaginary_float80";
13853 case DW_ATE_HP_imaginary_float128
:
13854 return "DW_ATE_HP_imaginary_float128";
13856 return "DW_ATE_<unknown>";
13860 /* Convert a DWARF call frame info operation to its string name. */
13864 dwarf_cfi_name (unsigned cfi_opc
)
13868 case DW_CFA_advance_loc
:
13869 return "DW_CFA_advance_loc";
13870 case DW_CFA_offset
:
13871 return "DW_CFA_offset";
13872 case DW_CFA_restore
:
13873 return "DW_CFA_restore";
13875 return "DW_CFA_nop";
13876 case DW_CFA_set_loc
:
13877 return "DW_CFA_set_loc";
13878 case DW_CFA_advance_loc1
:
13879 return "DW_CFA_advance_loc1";
13880 case DW_CFA_advance_loc2
:
13881 return "DW_CFA_advance_loc2";
13882 case DW_CFA_advance_loc4
:
13883 return "DW_CFA_advance_loc4";
13884 case DW_CFA_offset_extended
:
13885 return "DW_CFA_offset_extended";
13886 case DW_CFA_restore_extended
:
13887 return "DW_CFA_restore_extended";
13888 case DW_CFA_undefined
:
13889 return "DW_CFA_undefined";
13890 case DW_CFA_same_value
:
13891 return "DW_CFA_same_value";
13892 case DW_CFA_register
:
13893 return "DW_CFA_register";
13894 case DW_CFA_remember_state
:
13895 return "DW_CFA_remember_state";
13896 case DW_CFA_restore_state
:
13897 return "DW_CFA_restore_state";
13898 case DW_CFA_def_cfa
:
13899 return "DW_CFA_def_cfa";
13900 case DW_CFA_def_cfa_register
:
13901 return "DW_CFA_def_cfa_register";
13902 case DW_CFA_def_cfa_offset
:
13903 return "DW_CFA_def_cfa_offset";
13905 case DW_CFA_def_cfa_expression
:
13906 return "DW_CFA_def_cfa_expression";
13907 case DW_CFA_expression
:
13908 return "DW_CFA_expression";
13909 case DW_CFA_offset_extended_sf
:
13910 return "DW_CFA_offset_extended_sf";
13911 case DW_CFA_def_cfa_sf
:
13912 return "DW_CFA_def_cfa_sf";
13913 case DW_CFA_def_cfa_offset_sf
:
13914 return "DW_CFA_def_cfa_offset_sf";
13915 case DW_CFA_val_offset
:
13916 return "DW_CFA_val_offset";
13917 case DW_CFA_val_offset_sf
:
13918 return "DW_CFA_val_offset_sf";
13919 case DW_CFA_val_expression
:
13920 return "DW_CFA_val_expression";
13921 /* SGI/MIPS specific. */
13922 case DW_CFA_MIPS_advance_loc8
:
13923 return "DW_CFA_MIPS_advance_loc8";
13924 /* GNU extensions. */
13925 case DW_CFA_GNU_window_save
:
13926 return "DW_CFA_GNU_window_save";
13927 case DW_CFA_GNU_args_size
:
13928 return "DW_CFA_GNU_args_size";
13929 case DW_CFA_GNU_negative_offset_extended
:
13930 return "DW_CFA_GNU_negative_offset_extended";
13932 return "DW_CFA_<unknown>";
13938 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
13942 print_spaces (indent
, f
);
13943 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
13944 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
.sect_off
);
13946 if (die
->parent
!= NULL
)
13948 print_spaces (indent
, f
);
13949 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
13950 die
->parent
->offset
.sect_off
);
13953 print_spaces (indent
, f
);
13954 fprintf_unfiltered (f
, " has children: %s\n",
13955 dwarf_bool_name (die
->child
!= NULL
));
13957 print_spaces (indent
, f
);
13958 fprintf_unfiltered (f
, " attributes:\n");
13960 for (i
= 0; i
< die
->num_attrs
; ++i
)
13962 print_spaces (indent
, f
);
13963 fprintf_unfiltered (f
, " %s (%s) ",
13964 dwarf_attr_name (die
->attrs
[i
].name
),
13965 dwarf_form_name (die
->attrs
[i
].form
));
13967 switch (die
->attrs
[i
].form
)
13969 case DW_FORM_ref_addr
:
13971 fprintf_unfiltered (f
, "address: ");
13972 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
13974 case DW_FORM_block2
:
13975 case DW_FORM_block4
:
13976 case DW_FORM_block
:
13977 case DW_FORM_block1
:
13978 fprintf_unfiltered (f
, "block: size %d",
13979 DW_BLOCK (&die
->attrs
[i
])->size
);
13981 case DW_FORM_exprloc
:
13982 fprintf_unfiltered (f
, "expression: size %u",
13983 DW_BLOCK (&die
->attrs
[i
])->size
);
13988 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
13989 (long) (DW_ADDR (&die
->attrs
[i
])));
13991 case DW_FORM_data1
:
13992 case DW_FORM_data2
:
13993 case DW_FORM_data4
:
13994 case DW_FORM_data8
:
13995 case DW_FORM_udata
:
13996 case DW_FORM_sdata
:
13997 fprintf_unfiltered (f
, "constant: %s",
13998 pulongest (DW_UNSND (&die
->attrs
[i
])));
14000 case DW_FORM_sec_offset
:
14001 fprintf_unfiltered (f
, "section offset: %s",
14002 pulongest (DW_UNSND (&die
->attrs
[i
])));
14004 case DW_FORM_ref_sig8
:
14005 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
14006 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
14007 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
.sect_off
);
14009 fprintf_unfiltered (f
, "signatured type, offset: unknown");
14011 case DW_FORM_string
:
14013 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
14014 DW_STRING (&die
->attrs
[i
])
14015 ? DW_STRING (&die
->attrs
[i
]) : "",
14016 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
14019 if (DW_UNSND (&die
->attrs
[i
]))
14020 fprintf_unfiltered (f
, "flag: TRUE");
14022 fprintf_unfiltered (f
, "flag: FALSE");
14024 case DW_FORM_flag_present
:
14025 fprintf_unfiltered (f
, "flag: TRUE");
14027 case DW_FORM_indirect
:
14028 /* The reader will have reduced the indirect form to
14029 the "base form" so this form should not occur. */
14030 fprintf_unfiltered (f
,
14031 "unexpected attribute form: DW_FORM_indirect");
14034 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
14035 die
->attrs
[i
].form
);
14038 fprintf_unfiltered (f
, "\n");
14043 dump_die_for_error (struct die_info
*die
)
14045 dump_die_shallow (gdb_stderr
, 0, die
);
14049 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
14051 int indent
= level
* 4;
14053 gdb_assert (die
!= NULL
);
14055 if (level
>= max_level
)
14058 dump_die_shallow (f
, indent
, die
);
14060 if (die
->child
!= NULL
)
14062 print_spaces (indent
, f
);
14063 fprintf_unfiltered (f
, " Children:");
14064 if (level
+ 1 < max_level
)
14066 fprintf_unfiltered (f
, "\n");
14067 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
14071 fprintf_unfiltered (f
,
14072 " [not printed, max nesting level reached]\n");
14076 if (die
->sibling
!= NULL
&& level
> 0)
14078 dump_die_1 (f
, level
, max_level
, die
->sibling
);
14082 /* This is called from the pdie macro in gdbinit.in.
14083 It's not static so gcc will keep a copy callable from gdb. */
14086 dump_die (struct die_info
*die
, int max_level
)
14088 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
14092 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
14096 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
.sect_off
,
14102 /* DW_ADDR is always stored already as sect_offset; despite for the forms
14103 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
14106 is_ref_attr (struct attribute
*attr
)
14108 switch (attr
->form
)
14110 case DW_FORM_ref_addr
:
14115 case DW_FORM_ref_udata
:
14122 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
14126 dwarf2_get_ref_die_offset (struct attribute
*attr
)
14128 sect_offset retval
= { DW_ADDR (attr
) };
14130 if (is_ref_attr (attr
))
14133 retval
.sect_off
= 0;
14134 complaint (&symfile_complaints
,
14135 _("unsupported die ref attribute form: '%s'"),
14136 dwarf_form_name (attr
->form
));
14140 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
14141 * the value held by the attribute is not constant. */
14144 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
14146 if (attr
->form
== DW_FORM_sdata
)
14147 return DW_SND (attr
);
14148 else if (attr
->form
== DW_FORM_udata
14149 || attr
->form
== DW_FORM_data1
14150 || attr
->form
== DW_FORM_data2
14151 || attr
->form
== DW_FORM_data4
14152 || attr
->form
== DW_FORM_data8
)
14153 return DW_UNSND (attr
);
14156 complaint (&symfile_complaints
,
14157 _("Attribute value is not a constant (%s)"),
14158 dwarf_form_name (attr
->form
));
14159 return default_value
;
14163 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
14164 unit and add it to our queue.
14165 The result is non-zero if PER_CU was queued, otherwise the result is zero
14166 meaning either PER_CU is already queued or it is already loaded. */
14169 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
14170 struct dwarf2_per_cu_data
*per_cu
)
14172 /* We may arrive here during partial symbol reading, if we need full
14173 DIEs to process an unusual case (e.g. template arguments). Do
14174 not queue PER_CU, just tell our caller to load its DIEs. */
14175 if (dwarf2_per_objfile
->reading_partial_symbols
)
14177 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
14182 /* Mark the dependence relation so that we don't flush PER_CU
14184 dwarf2_add_dependence (this_cu
, per_cu
);
14186 /* If it's already on the queue, we have nothing to do. */
14187 if (per_cu
->queued
)
14190 /* If the compilation unit is already loaded, just mark it as
14192 if (per_cu
->cu
!= NULL
)
14194 per_cu
->cu
->last_used
= 0;
14198 /* Add it to the queue. */
14199 queue_comp_unit (per_cu
);
14204 /* Follow reference or signature attribute ATTR of SRC_DIE.
14205 On entry *REF_CU is the CU of SRC_DIE.
14206 On exit *REF_CU is the CU of the result. */
14208 static struct die_info
*
14209 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
14210 struct dwarf2_cu
**ref_cu
)
14212 struct die_info
*die
;
14214 if (is_ref_attr (attr
))
14215 die
= follow_die_ref (src_die
, attr
, ref_cu
);
14216 else if (attr
->form
== DW_FORM_ref_sig8
)
14217 die
= follow_die_sig (src_die
, attr
, ref_cu
);
14220 dump_die_for_error (src_die
);
14221 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
14222 (*ref_cu
)->objfile
->name
);
14228 /* Follow reference OFFSET.
14229 On entry *REF_CU is the CU of the source die referencing OFFSET.
14230 On exit *REF_CU is the CU of the result.
14231 Returns NULL if OFFSET is invalid. */
14233 static struct die_info
*
14234 follow_die_offset (sect_offset offset
, struct dwarf2_cu
**ref_cu
)
14236 struct die_info temp_die
;
14237 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
14239 gdb_assert (cu
->per_cu
!= NULL
);
14243 if (cu
->per_cu
->debug_types_section
)
14245 /* .debug_types CUs cannot reference anything outside their CU.
14246 If they need to, they have to reference a signatured type via
14247 DW_FORM_ref_sig8. */
14248 if (! offset_in_cu_p (&cu
->header
, offset
))
14251 else if (! offset_in_cu_p (&cu
->header
, offset
))
14253 struct dwarf2_per_cu_data
*per_cu
;
14255 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
14257 /* If necessary, add it to the queue and load its DIEs. */
14258 if (maybe_queue_comp_unit (cu
, per_cu
))
14259 load_full_comp_unit (per_cu
);
14261 target_cu
= per_cu
->cu
;
14263 else if (cu
->dies
== NULL
)
14265 /* We're loading full DIEs during partial symbol reading. */
14266 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
14267 load_full_comp_unit (cu
->per_cu
);
14270 *ref_cu
= target_cu
;
14271 temp_die
.offset
= offset
;
14272 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
.sect_off
);
14275 /* Follow reference attribute ATTR of SRC_DIE.
14276 On entry *REF_CU is the CU of SRC_DIE.
14277 On exit *REF_CU is the CU of the result. */
14279 static struct die_info
*
14280 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
14281 struct dwarf2_cu
**ref_cu
)
14283 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
14284 struct dwarf2_cu
*cu
= *ref_cu
;
14285 struct die_info
*die
;
14287 die
= follow_die_offset (offset
, ref_cu
);
14289 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
14290 "at 0x%x [in module %s]"),
14291 offset
.sect_off
, src_die
->offset
.sect_off
, cu
->objfile
->name
);
14296 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
14297 Returned value is intended for DW_OP_call*. Returned
14298 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
14300 struct dwarf2_locexpr_baton
14301 dwarf2_fetch_die_location_block (cu_offset offset_in_cu
,
14302 struct dwarf2_per_cu_data
*per_cu
,
14303 CORE_ADDR (*get_frame_pc
) (void *baton
),
14306 sect_offset offset
= { per_cu
->offset
.sect_off
+ offset_in_cu
.cu_off
};
14307 struct dwarf2_cu
*cu
;
14308 struct die_info
*die
;
14309 struct attribute
*attr
;
14310 struct dwarf2_locexpr_baton retval
;
14312 dw2_setup (per_cu
->objfile
);
14314 if (per_cu
->cu
== NULL
)
14318 die
= follow_die_offset (offset
, &cu
);
14320 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
14321 offset
.sect_off
, per_cu
->objfile
->name
);
14323 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
14326 /* DWARF: "If there is no such attribute, then there is no effect.".
14327 DATA is ignored if SIZE is 0. */
14329 retval
.data
= NULL
;
14332 else if (attr_form_is_section_offset (attr
))
14334 struct dwarf2_loclist_baton loclist_baton
;
14335 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
14338 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
14340 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
14342 retval
.size
= size
;
14346 if (!attr_form_is_block (attr
))
14347 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
14348 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
14349 offset
.sect_off
, per_cu
->objfile
->name
);
14351 retval
.data
= DW_BLOCK (attr
)->data
;
14352 retval
.size
= DW_BLOCK (attr
)->size
;
14354 retval
.per_cu
= cu
->per_cu
;
14356 age_cached_comp_units ();
14361 /* Return the type of the DIE at DIE_OFFSET in the CU named by
14365 dwarf2_get_die_type (cu_offset die_offset
,
14366 struct dwarf2_per_cu_data
*per_cu
)
14368 sect_offset die_offset_sect
;
14370 dw2_setup (per_cu
->objfile
);
14372 die_offset_sect
.sect_off
= per_cu
->offset
.sect_off
+ die_offset
.cu_off
;
14373 return get_die_type_at_offset (die_offset_sect
, per_cu
);
14376 /* Follow the signature attribute ATTR in SRC_DIE.
14377 On entry *REF_CU is the CU of SRC_DIE.
14378 On exit *REF_CU is the CU of the result. */
14380 static struct die_info
*
14381 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
14382 struct dwarf2_cu
**ref_cu
)
14384 struct objfile
*objfile
= (*ref_cu
)->objfile
;
14385 struct die_info temp_die
;
14386 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
14387 struct dwarf2_cu
*sig_cu
;
14388 struct die_info
*die
;
14390 /* sig_type will be NULL if the signatured type is missing from
14392 if (sig_type
== NULL
)
14393 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
14394 "at 0x%x [in module %s]"),
14395 src_die
->offset
.sect_off
, objfile
->name
);
14397 /* If necessary, add it to the queue and load its DIEs. */
14399 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
14400 read_signatured_type (sig_type
);
14402 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
14404 sig_cu
= sig_type
->per_cu
.cu
;
14405 temp_die
.offset
.sect_off
= (sig_type
->per_cu
.offset
.sect_off
14406 + sig_type
->type_offset
.cu_off
);
14407 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
14408 temp_die
.offset
.sect_off
);
14415 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
14416 "from DIE at 0x%x [in module %s]"),
14417 temp_die
.offset
.sect_off
, src_die
->offset
.sect_off
, objfile
->name
);
14420 /* Given an offset of a signatured type, return its signatured_type. */
14422 static struct signatured_type
*
14423 lookup_signatured_type_at_offset (struct objfile
*objfile
,
14424 struct dwarf2_section_info
*section
,
14425 sect_offset offset
)
14427 gdb_byte
*info_ptr
= section
->buffer
+ offset
.sect_off
;
14428 unsigned int length
, initial_length_size
;
14429 unsigned int sig_offset
;
14430 struct signatured_type find_entry
, *sig_type
;
14432 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
14433 sig_offset
= (initial_length_size
14435 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
14436 + 1 /*address_size*/);
14437 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
14438 sig_type
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
14440 /* This is only used to lookup previously recorded types.
14441 If we didn't find it, it's our bug. */
14442 gdb_assert (sig_type
!= NULL
);
14443 gdb_assert (offset
.sect_off
== sig_type
->per_cu
.offset
.sect_off
);
14448 /* Load the DIEs associated with type unit PER_CU into memory. */
14451 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
14453 struct objfile
*objfile
= per_cu
->objfile
;
14454 struct dwarf2_section_info
*sect
= per_cu
->debug_types_section
;
14455 sect_offset offset
= per_cu
->offset
;
14456 struct signatured_type
*sig_type
;
14458 dwarf2_read_section (objfile
, sect
);
14460 /* We have the section offset, but we need the signature to do the
14461 hash table lookup. */
14462 /* FIXME: This is sorta unnecessary, read_signatured_type only uses
14463 the signature to assert we found the right one.
14464 Ok, but it's a lot of work. We should simplify things so any needed
14465 assert doesn't require all this clumsiness. */
14466 sig_type
= lookup_signatured_type_at_offset (objfile
, sect
, offset
);
14468 gdb_assert (sig_type
->per_cu
.cu
== NULL
);
14470 read_signatured_type (sig_type
);
14472 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
14475 /* Read in a signatured type and build its CU and DIEs. */
14478 read_signatured_type (struct signatured_type
*sig_type
)
14480 struct objfile
*objfile
= sig_type
->per_cu
.objfile
;
14481 gdb_byte
*types_ptr
;
14482 struct die_reader_specs reader_specs
;
14483 struct dwarf2_cu
*cu
;
14484 ULONGEST signature
;
14485 struct cleanup
*back_to
, *free_cu_cleanup
;
14486 struct dwarf2_section_info
*section
= sig_type
->per_cu
.debug_types_section
;
14488 dwarf2_read_section (objfile
, section
);
14489 types_ptr
= section
->buffer
+ sig_type
->per_cu
.offset
.sect_off
;
14491 gdb_assert (sig_type
->per_cu
.cu
== NULL
);
14493 cu
= xmalloc (sizeof (*cu
));
14494 init_one_comp_unit (cu
, &sig_type
->per_cu
);
14496 /* If an error occurs while loading, release our storage. */
14497 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
14499 types_ptr
= read_and_check_type_unit_head (&cu
->header
, section
, types_ptr
,
14501 gdb_assert (signature
== sig_type
->signature
);
14504 = htab_create_alloc_ex (cu
->header
.length
/ 12,
14508 &cu
->comp_unit_obstack
,
14509 hashtab_obstack_allocate
,
14510 dummy_obstack_deallocate
);
14512 dwarf2_read_abbrevs (cu
);
14513 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
14515 init_cu_die_reader (&reader_specs
, cu
);
14517 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
14520 /* We try not to read any attributes in this function, because not
14521 all CUs needed for references have been loaded yet, and symbol
14522 table processing isn't initialized. But we have to set the CU language,
14523 or we won't be able to build types correctly. */
14524 prepare_one_comp_unit (cu
, cu
->dies
);
14526 do_cleanups (back_to
);
14528 /* We've successfully allocated this compilation unit. Let our caller
14529 clean it up when finished with it. */
14530 discard_cleanups (free_cu_cleanup
);
14532 /* Link this TU into read_in_chain. */
14533 sig_type
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
14534 dwarf2_per_objfile
->read_in_chain
= &sig_type
->per_cu
;
14537 /* Decode simple location descriptions.
14538 Given a pointer to a dwarf block that defines a location, compute
14539 the location and return the value.
14541 NOTE drow/2003-11-18: This function is called in two situations
14542 now: for the address of static or global variables (partial symbols
14543 only) and for offsets into structures which are expected to be
14544 (more or less) constant. The partial symbol case should go away,
14545 and only the constant case should remain. That will let this
14546 function complain more accurately. A few special modes are allowed
14547 without complaint for global variables (for instance, global
14548 register values and thread-local values).
14550 A location description containing no operations indicates that the
14551 object is optimized out. The return value is 0 for that case.
14552 FIXME drow/2003-11-16: No callers check for this case any more; soon all
14553 callers will only want a very basic result and this can become a
14556 Note that stack[0] is unused except as a default error return. */
14559 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
14561 struct objfile
*objfile
= cu
->objfile
;
14563 int size
= blk
->size
;
14564 gdb_byte
*data
= blk
->data
;
14565 CORE_ADDR stack
[64];
14567 unsigned int bytes_read
, unsnd
;
14573 stack
[++stacki
] = 0;
14612 stack
[++stacki
] = op
- DW_OP_lit0
;
14647 stack
[++stacki
] = op
- DW_OP_reg0
;
14649 dwarf2_complex_location_expr_complaint ();
14653 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
14655 stack
[++stacki
] = unsnd
;
14657 dwarf2_complex_location_expr_complaint ();
14661 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
14666 case DW_OP_const1u
:
14667 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
14671 case DW_OP_const1s
:
14672 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
14676 case DW_OP_const2u
:
14677 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
14681 case DW_OP_const2s
:
14682 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
14686 case DW_OP_const4u
:
14687 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
14691 case DW_OP_const4s
:
14692 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
14696 case DW_OP_const8u
:
14697 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
14702 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
14708 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
14713 stack
[stacki
+ 1] = stack
[stacki
];
14718 stack
[stacki
- 1] += stack
[stacki
];
14722 case DW_OP_plus_uconst
:
14723 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
14729 stack
[stacki
- 1] -= stack
[stacki
];
14734 /* If we're not the last op, then we definitely can't encode
14735 this using GDB's address_class enum. This is valid for partial
14736 global symbols, although the variable's address will be bogus
14739 dwarf2_complex_location_expr_complaint ();
14742 case DW_OP_GNU_push_tls_address
:
14743 /* The top of the stack has the offset from the beginning
14744 of the thread control block at which the variable is located. */
14745 /* Nothing should follow this operator, so the top of stack would
14747 /* This is valid for partial global symbols, but the variable's
14748 address will be bogus in the psymtab. Make it always at least
14749 non-zero to not look as a variable garbage collected by linker
14750 which have DW_OP_addr 0. */
14752 dwarf2_complex_location_expr_complaint ();
14756 case DW_OP_GNU_uninit
:
14761 const char *name
= dwarf_stack_op_name (op
);
14764 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
14767 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
14771 return (stack
[stacki
]);
14774 /* Enforce maximum stack depth of SIZE-1 to avoid writing
14775 outside of the allocated space. Also enforce minimum>0. */
14776 if (stacki
>= ARRAY_SIZE (stack
) - 1)
14778 complaint (&symfile_complaints
,
14779 _("location description stack overflow"));
14785 complaint (&symfile_complaints
,
14786 _("location description stack underflow"));
14790 return (stack
[stacki
]);
14793 /* memory allocation interface */
14795 static struct dwarf_block
*
14796 dwarf_alloc_block (struct dwarf2_cu
*cu
)
14798 struct dwarf_block
*blk
;
14800 blk
= (struct dwarf_block
*)
14801 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
14805 static struct abbrev_info
*
14806 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
14808 struct abbrev_info
*abbrev
;
14810 abbrev
= (struct abbrev_info
*)
14811 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
14812 memset (abbrev
, 0, sizeof (struct abbrev_info
));
14816 static struct die_info
*
14817 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
14819 struct die_info
*die
;
14820 size_t size
= sizeof (struct die_info
);
14823 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
14825 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
14826 memset (die
, 0, sizeof (struct die_info
));
14831 /* Macro support. */
14833 /* Return the full name of file number I in *LH's file name table.
14834 Use COMP_DIR as the name of the current directory of the
14835 compilation. The result is allocated using xmalloc; the caller is
14836 responsible for freeing it. */
14838 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
14840 /* Is the file number a valid index into the line header's file name
14841 table? Remember that file numbers start with one, not zero. */
14842 if (1 <= file
&& file
<= lh
->num_file_names
)
14844 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
14846 if (IS_ABSOLUTE_PATH (fe
->name
))
14847 return xstrdup (fe
->name
);
14855 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14861 dir_len
= strlen (dir
);
14862 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
14863 strcpy (full_name
, dir
);
14864 full_name
[dir_len
] = '/';
14865 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
14869 return xstrdup (fe
->name
);
14874 /* The compiler produced a bogus file number. We can at least
14875 record the macro definitions made in the file, even if we
14876 won't be able to find the file by name. */
14877 char fake_name
[80];
14879 sprintf (fake_name
, "<bad macro file number %d>", file
);
14881 complaint (&symfile_complaints
,
14882 _("bad file number in macro information (%d)"),
14885 return xstrdup (fake_name
);
14890 static struct macro_source_file
*
14891 macro_start_file (int file
, int line
,
14892 struct macro_source_file
*current_file
,
14893 const char *comp_dir
,
14894 struct line_header
*lh
, struct objfile
*objfile
)
14896 /* The full name of this source file. */
14897 char *full_name
= file_full_name (file
, lh
, comp_dir
);
14899 /* We don't create a macro table for this compilation unit
14900 at all until we actually get a filename. */
14901 if (! pending_macros
)
14902 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
14903 objfile
->macro_cache
);
14905 if (! current_file
)
14906 /* If we have no current file, then this must be the start_file
14907 directive for the compilation unit's main source file. */
14908 current_file
= macro_set_main (pending_macros
, full_name
);
14910 current_file
= macro_include (current_file
, line
, full_name
);
14914 return current_file
;
14918 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
14919 followed by a null byte. */
14921 copy_string (const char *buf
, int len
)
14923 char *s
= xmalloc (len
+ 1);
14925 memcpy (s
, buf
, len
);
14931 static const char *
14932 consume_improper_spaces (const char *p
, const char *body
)
14936 complaint (&symfile_complaints
,
14937 _("macro definition contains spaces "
14938 "in formal argument list:\n`%s'"),
14950 parse_macro_definition (struct macro_source_file
*file
, int line
,
14955 /* The body string takes one of two forms. For object-like macro
14956 definitions, it should be:
14958 <macro name> " " <definition>
14960 For function-like macro definitions, it should be:
14962 <macro name> "() " <definition>
14964 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
14966 Spaces may appear only where explicitly indicated, and in the
14969 The Dwarf 2 spec says that an object-like macro's name is always
14970 followed by a space, but versions of GCC around March 2002 omit
14971 the space when the macro's definition is the empty string.
14973 The Dwarf 2 spec says that there should be no spaces between the
14974 formal arguments in a function-like macro's formal argument list,
14975 but versions of GCC around March 2002 include spaces after the
14979 /* Find the extent of the macro name. The macro name is terminated
14980 by either a space or null character (for an object-like macro) or
14981 an opening paren (for a function-like macro). */
14982 for (p
= body
; *p
; p
++)
14983 if (*p
== ' ' || *p
== '(')
14986 if (*p
== ' ' || *p
== '\0')
14988 /* It's an object-like macro. */
14989 int name_len
= p
- body
;
14990 char *name
= copy_string (body
, name_len
);
14991 const char *replacement
;
14994 replacement
= body
+ name_len
+ 1;
14997 dwarf2_macro_malformed_definition_complaint (body
);
14998 replacement
= body
+ name_len
;
15001 macro_define_object (file
, line
, name
, replacement
);
15005 else if (*p
== '(')
15007 /* It's a function-like macro. */
15008 char *name
= copy_string (body
, p
- body
);
15011 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
15015 p
= consume_improper_spaces (p
, body
);
15017 /* Parse the formal argument list. */
15018 while (*p
&& *p
!= ')')
15020 /* Find the extent of the current argument name. */
15021 const char *arg_start
= p
;
15023 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
15026 if (! *p
|| p
== arg_start
)
15027 dwarf2_macro_malformed_definition_complaint (body
);
15030 /* Make sure argv has room for the new argument. */
15031 if (argc
>= argv_size
)
15034 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
15037 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
15040 p
= consume_improper_spaces (p
, body
);
15042 /* Consume the comma, if present. */
15047 p
= consume_improper_spaces (p
, body
);
15056 /* Perfectly formed definition, no complaints. */
15057 macro_define_function (file
, line
, name
,
15058 argc
, (const char **) argv
,
15060 else if (*p
== '\0')
15062 /* Complain, but do define it. */
15063 dwarf2_macro_malformed_definition_complaint (body
);
15064 macro_define_function (file
, line
, name
,
15065 argc
, (const char **) argv
,
15069 /* Just complain. */
15070 dwarf2_macro_malformed_definition_complaint (body
);
15073 /* Just complain. */
15074 dwarf2_macro_malformed_definition_complaint (body
);
15080 for (i
= 0; i
< argc
; i
++)
15086 dwarf2_macro_malformed_definition_complaint (body
);
15089 /* Skip some bytes from BYTES according to the form given in FORM.
15090 Returns the new pointer. */
15093 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
,
15094 enum dwarf_form form
,
15095 unsigned int offset_size
,
15096 struct dwarf2_section_info
*section
)
15098 unsigned int bytes_read
;
15102 case DW_FORM_data1
:
15107 case DW_FORM_data2
:
15111 case DW_FORM_data4
:
15115 case DW_FORM_data8
:
15119 case DW_FORM_string
:
15120 read_direct_string (abfd
, bytes
, &bytes_read
);
15121 bytes
+= bytes_read
;
15124 case DW_FORM_sec_offset
:
15126 bytes
+= offset_size
;
15129 case DW_FORM_block
:
15130 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
15131 bytes
+= bytes_read
;
15134 case DW_FORM_block1
:
15135 bytes
+= 1 + read_1_byte (abfd
, bytes
);
15137 case DW_FORM_block2
:
15138 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
15140 case DW_FORM_block4
:
15141 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
15144 case DW_FORM_sdata
:
15145 case DW_FORM_udata
:
15146 bytes
= skip_leb128 (abfd
, bytes
);
15152 complaint (&symfile_complaints
,
15153 _("invalid form 0x%x in `%s'"),
15155 section
->asection
->name
);
15163 /* A helper for dwarf_decode_macros that handles skipping an unknown
15164 opcode. Returns an updated pointer to the macro data buffer; or,
15165 on error, issues a complaint and returns NULL. */
15168 skip_unknown_opcode (unsigned int opcode
,
15169 gdb_byte
**opcode_definitions
,
15172 unsigned int offset_size
,
15173 struct dwarf2_section_info
*section
)
15175 unsigned int bytes_read
, i
;
15179 if (opcode_definitions
[opcode
] == NULL
)
15181 complaint (&symfile_complaints
,
15182 _("unrecognized DW_MACFINO opcode 0x%x"),
15187 defn
= opcode_definitions
[opcode
];
15188 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
15189 defn
+= bytes_read
;
15191 for (i
= 0; i
< arg
; ++i
)
15193 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, defn
[i
], offset_size
, section
);
15194 if (mac_ptr
== NULL
)
15196 /* skip_form_bytes already issued the complaint. */
15204 /* A helper function which parses the header of a macro section.
15205 If the macro section is the extended (for now called "GNU") type,
15206 then this updates *OFFSET_SIZE. Returns a pointer to just after
15207 the header, or issues a complaint and returns NULL on error. */
15210 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
15213 unsigned int *offset_size
,
15214 int section_is_gnu
)
15216 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
15218 if (section_is_gnu
)
15220 unsigned int version
, flags
;
15222 version
= read_2_bytes (abfd
, mac_ptr
);
15225 complaint (&symfile_complaints
,
15226 _("unrecognized version `%d' in .debug_macro section"),
15232 flags
= read_1_byte (abfd
, mac_ptr
);
15234 *offset_size
= (flags
& 1) ? 8 : 4;
15236 if ((flags
& 2) != 0)
15237 /* We don't need the line table offset. */
15238 mac_ptr
+= *offset_size
;
15240 /* Vendor opcode descriptions. */
15241 if ((flags
& 4) != 0)
15243 unsigned int i
, count
;
15245 count
= read_1_byte (abfd
, mac_ptr
);
15247 for (i
= 0; i
< count
; ++i
)
15249 unsigned int opcode
, bytes_read
;
15252 opcode
= read_1_byte (abfd
, mac_ptr
);
15254 opcode_definitions
[opcode
] = mac_ptr
;
15255 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15256 mac_ptr
+= bytes_read
;
15265 /* A helper for dwarf_decode_macros that handles the GNU extensions,
15266 including DW_MACRO_GNU_transparent_include. */
15269 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
15270 struct macro_source_file
*current_file
,
15271 struct line_header
*lh
, char *comp_dir
,
15272 struct dwarf2_section_info
*section
,
15273 int section_is_gnu
,
15274 unsigned int offset_size
,
15275 struct objfile
*objfile
,
15276 htab_t include_hash
)
15278 enum dwarf_macro_record_type macinfo_type
;
15279 int at_commandline
;
15280 gdb_byte
*opcode_definitions
[256];
15282 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
15283 &offset_size
, section_is_gnu
);
15284 if (mac_ptr
== NULL
)
15286 /* We already issued a complaint. */
15290 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
15291 GDB is still reading the definitions from command line. First
15292 DW_MACINFO_start_file will need to be ignored as it was already executed
15293 to create CURRENT_FILE for the main source holding also the command line
15294 definitions. On first met DW_MACINFO_start_file this flag is reset to
15295 normally execute all the remaining DW_MACINFO_start_file macinfos. */
15297 at_commandline
= 1;
15301 /* Do we at least have room for a macinfo type byte? */
15302 if (mac_ptr
>= mac_end
)
15304 dwarf2_macros_too_long_complaint (section
);
15308 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
15311 /* Note that we rely on the fact that the corresponding GNU and
15312 DWARF constants are the same. */
15313 switch (macinfo_type
)
15315 /* A zero macinfo type indicates the end of the macro
15320 case DW_MACRO_GNU_define
:
15321 case DW_MACRO_GNU_undef
:
15322 case DW_MACRO_GNU_define_indirect
:
15323 case DW_MACRO_GNU_undef_indirect
:
15325 unsigned int bytes_read
;
15330 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15331 mac_ptr
+= bytes_read
;
15333 if (macinfo_type
== DW_MACRO_GNU_define
15334 || macinfo_type
== DW_MACRO_GNU_undef
)
15336 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15337 mac_ptr
+= bytes_read
;
15341 LONGEST str_offset
;
15343 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
15344 mac_ptr
+= offset_size
;
15346 body
= read_indirect_string_at_offset (abfd
, str_offset
);
15349 is_define
= (macinfo_type
== DW_MACRO_GNU_define
15350 || macinfo_type
== DW_MACRO_GNU_define_indirect
);
15351 if (! current_file
)
15353 /* DWARF violation as no main source is present. */
15354 complaint (&symfile_complaints
,
15355 _("debug info with no main source gives macro %s "
15357 is_define
? _("definition") : _("undefinition"),
15361 if ((line
== 0 && !at_commandline
)
15362 || (line
!= 0 && at_commandline
))
15363 complaint (&symfile_complaints
,
15364 _("debug info gives %s macro %s with %s line %d: %s"),
15365 at_commandline
? _("command-line") : _("in-file"),
15366 is_define
? _("definition") : _("undefinition"),
15367 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
15370 parse_macro_definition (current_file
, line
, body
);
15373 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
15374 || macinfo_type
== DW_MACRO_GNU_undef_indirect
);
15375 macro_undef (current_file
, line
, body
);
15380 case DW_MACRO_GNU_start_file
:
15382 unsigned int bytes_read
;
15385 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15386 mac_ptr
+= bytes_read
;
15387 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15388 mac_ptr
+= bytes_read
;
15390 if ((line
== 0 && !at_commandline
)
15391 || (line
!= 0 && at_commandline
))
15392 complaint (&symfile_complaints
,
15393 _("debug info gives source %d included "
15394 "from %s at %s line %d"),
15395 file
, at_commandline
? _("command-line") : _("file"),
15396 line
== 0 ? _("zero") : _("non-zero"), line
);
15398 if (at_commandline
)
15400 /* This DW_MACRO_GNU_start_file was executed in the
15402 at_commandline
= 0;
15405 current_file
= macro_start_file (file
, line
,
15406 current_file
, comp_dir
,
15411 case DW_MACRO_GNU_end_file
:
15412 if (! current_file
)
15413 complaint (&symfile_complaints
,
15414 _("macro debug info has an unmatched "
15415 "`close_file' directive"));
15418 current_file
= current_file
->included_by
;
15419 if (! current_file
)
15421 enum dwarf_macro_record_type next_type
;
15423 /* GCC circa March 2002 doesn't produce the zero
15424 type byte marking the end of the compilation
15425 unit. Complain if it's not there, but exit no
15428 /* Do we at least have room for a macinfo type byte? */
15429 if (mac_ptr
>= mac_end
)
15431 dwarf2_macros_too_long_complaint (section
);
15435 /* We don't increment mac_ptr here, so this is just
15437 next_type
= read_1_byte (abfd
, mac_ptr
);
15438 if (next_type
!= 0)
15439 complaint (&symfile_complaints
,
15440 _("no terminating 0-type entry for "
15441 "macros in `.debug_macinfo' section"));
15448 case DW_MACRO_GNU_transparent_include
:
15453 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
15454 mac_ptr
+= offset_size
;
15456 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
15459 /* This has actually happened; see
15460 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
15461 complaint (&symfile_complaints
,
15462 _("recursive DW_MACRO_GNU_transparent_include in "
15463 ".debug_macro section"));
15469 dwarf_decode_macro_bytes (abfd
,
15470 section
->buffer
+ offset
,
15471 mac_end
, current_file
,
15473 section
, section_is_gnu
,
15474 offset_size
, objfile
, include_hash
);
15476 htab_remove_elt (include_hash
, mac_ptr
);
15481 case DW_MACINFO_vendor_ext
:
15482 if (!section_is_gnu
)
15484 unsigned int bytes_read
;
15487 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15488 mac_ptr
+= bytes_read
;
15489 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15490 mac_ptr
+= bytes_read
;
15492 /* We don't recognize any vendor extensions. */
15498 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
15499 mac_ptr
, abfd
, offset_size
,
15501 if (mac_ptr
== NULL
)
15505 } while (macinfo_type
!= 0);
15509 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
15510 char *comp_dir
, bfd
*abfd
,
15511 struct dwarf2_cu
*cu
,
15512 struct dwarf2_section_info
*section
,
15513 int section_is_gnu
)
15515 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15516 gdb_byte
*mac_ptr
, *mac_end
;
15517 struct macro_source_file
*current_file
= 0;
15518 enum dwarf_macro_record_type macinfo_type
;
15519 unsigned int offset_size
= cu
->header
.offset_size
;
15520 gdb_byte
*opcode_definitions
[256];
15521 struct cleanup
*cleanup
;
15522 htab_t include_hash
;
15525 dwarf2_read_section (objfile
, section
);
15526 if (section
->buffer
== NULL
)
15528 complaint (&symfile_complaints
, _("missing %s section"),
15529 section
->asection
->name
);
15533 /* First pass: Find the name of the base filename.
15534 This filename is needed in order to process all macros whose definition
15535 (or undefinition) comes from the command line. These macros are defined
15536 before the first DW_MACINFO_start_file entry, and yet still need to be
15537 associated to the base file.
15539 To determine the base file name, we scan the macro definitions until we
15540 reach the first DW_MACINFO_start_file entry. We then initialize
15541 CURRENT_FILE accordingly so that any macro definition found before the
15542 first DW_MACINFO_start_file can still be associated to the base file. */
15544 mac_ptr
= section
->buffer
+ offset
;
15545 mac_end
= section
->buffer
+ section
->size
;
15547 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
15548 &offset_size
, section_is_gnu
);
15549 if (mac_ptr
== NULL
)
15551 /* We already issued a complaint. */
15557 /* Do we at least have room for a macinfo type byte? */
15558 if (mac_ptr
>= mac_end
)
15560 /* Complaint is printed during the second pass as GDB will probably
15561 stop the first pass earlier upon finding
15562 DW_MACINFO_start_file. */
15566 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
15569 /* Note that we rely on the fact that the corresponding GNU and
15570 DWARF constants are the same. */
15571 switch (macinfo_type
)
15573 /* A zero macinfo type indicates the end of the macro
15578 case DW_MACRO_GNU_define
:
15579 case DW_MACRO_GNU_undef
:
15580 /* Only skip the data by MAC_PTR. */
15582 unsigned int bytes_read
;
15584 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15585 mac_ptr
+= bytes_read
;
15586 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15587 mac_ptr
+= bytes_read
;
15591 case DW_MACRO_GNU_start_file
:
15593 unsigned int bytes_read
;
15596 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15597 mac_ptr
+= bytes_read
;
15598 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15599 mac_ptr
+= bytes_read
;
15601 current_file
= macro_start_file (file
, line
, current_file
,
15602 comp_dir
, lh
, objfile
);
15606 case DW_MACRO_GNU_end_file
:
15607 /* No data to skip by MAC_PTR. */
15610 case DW_MACRO_GNU_define_indirect
:
15611 case DW_MACRO_GNU_undef_indirect
:
15613 unsigned int bytes_read
;
15615 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15616 mac_ptr
+= bytes_read
;
15617 mac_ptr
+= offset_size
;
15621 case DW_MACRO_GNU_transparent_include
:
15622 /* Note that, according to the spec, a transparent include
15623 chain cannot call DW_MACRO_GNU_start_file. So, we can just
15624 skip this opcode. */
15625 mac_ptr
+= offset_size
;
15628 case DW_MACINFO_vendor_ext
:
15629 /* Only skip the data by MAC_PTR. */
15630 if (!section_is_gnu
)
15632 unsigned int bytes_read
;
15634 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15635 mac_ptr
+= bytes_read
;
15636 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15637 mac_ptr
+= bytes_read
;
15642 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
15643 mac_ptr
, abfd
, offset_size
,
15645 if (mac_ptr
== NULL
)
15649 } while (macinfo_type
!= 0 && current_file
== NULL
);
15651 /* Second pass: Process all entries.
15653 Use the AT_COMMAND_LINE flag to determine whether we are still processing
15654 command-line macro definitions/undefinitions. This flag is unset when we
15655 reach the first DW_MACINFO_start_file entry. */
15657 include_hash
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
15658 NULL
, xcalloc
, xfree
);
15659 cleanup
= make_cleanup_htab_delete (include_hash
);
15660 mac_ptr
= section
->buffer
+ offset
;
15661 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
15663 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
15664 current_file
, lh
, comp_dir
, section
, section_is_gnu
,
15665 offset_size
, objfile
, include_hash
);
15666 do_cleanups (cleanup
);
15669 /* Check if the attribute's form is a DW_FORM_block*
15670 if so return true else false. */
15672 attr_form_is_block (struct attribute
*attr
)
15674 return (attr
== NULL
? 0 :
15675 attr
->form
== DW_FORM_block1
15676 || attr
->form
== DW_FORM_block2
15677 || attr
->form
== DW_FORM_block4
15678 || attr
->form
== DW_FORM_block
15679 || attr
->form
== DW_FORM_exprloc
);
15682 /* Return non-zero if ATTR's value is a section offset --- classes
15683 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
15684 You may use DW_UNSND (attr) to retrieve such offsets.
15686 Section 7.5.4, "Attribute Encodings", explains that no attribute
15687 may have a value that belongs to more than one of these classes; it
15688 would be ambiguous if we did, because we use the same forms for all
15691 attr_form_is_section_offset (struct attribute
*attr
)
15693 return (attr
->form
== DW_FORM_data4
15694 || attr
->form
== DW_FORM_data8
15695 || attr
->form
== DW_FORM_sec_offset
);
15699 /* Return non-zero if ATTR's value falls in the 'constant' class, or
15700 zero otherwise. When this function returns true, you can apply
15701 dwarf2_get_attr_constant_value to it.
15703 However, note that for some attributes you must check
15704 attr_form_is_section_offset before using this test. DW_FORM_data4
15705 and DW_FORM_data8 are members of both the constant class, and of
15706 the classes that contain offsets into other debug sections
15707 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
15708 that, if an attribute's can be either a constant or one of the
15709 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
15710 taken as section offsets, not constants. */
15712 attr_form_is_constant (struct attribute
*attr
)
15714 switch (attr
->form
)
15716 case DW_FORM_sdata
:
15717 case DW_FORM_udata
:
15718 case DW_FORM_data1
:
15719 case DW_FORM_data2
:
15720 case DW_FORM_data4
:
15721 case DW_FORM_data8
:
15728 /* A helper function that fills in a dwarf2_loclist_baton. */
15731 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
15732 struct dwarf2_loclist_baton
*baton
,
15733 struct attribute
*attr
)
15735 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
15736 &dwarf2_per_objfile
->loc
);
15738 baton
->per_cu
= cu
->per_cu
;
15739 gdb_assert (baton
->per_cu
);
15740 /* We don't know how long the location list is, but make sure we
15741 don't run off the edge of the section. */
15742 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
15743 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
15744 baton
->base_address
= cu
->base_address
;
15748 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
15749 struct dwarf2_cu
*cu
)
15751 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15753 if (attr_form_is_section_offset (attr
)
15754 /* ".debug_loc" may not exist at all, or the offset may be outside
15755 the section. If so, fall through to the complaint in the
15757 && DW_UNSND (attr
) < dwarf2_section_size (objfile
,
15758 &dwarf2_per_objfile
->loc
))
15760 struct dwarf2_loclist_baton
*baton
;
15762 baton
= obstack_alloc (&objfile
->objfile_obstack
,
15763 sizeof (struct dwarf2_loclist_baton
));
15765 fill_in_loclist_baton (cu
, baton
, attr
);
15767 if (cu
->base_known
== 0)
15768 complaint (&symfile_complaints
,
15769 _("Location list used without "
15770 "specifying the CU base address."));
15772 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
15773 SYMBOL_LOCATION_BATON (sym
) = baton
;
15777 struct dwarf2_locexpr_baton
*baton
;
15779 baton
= obstack_alloc (&objfile
->objfile_obstack
,
15780 sizeof (struct dwarf2_locexpr_baton
));
15781 baton
->per_cu
= cu
->per_cu
;
15782 gdb_assert (baton
->per_cu
);
15784 if (attr_form_is_block (attr
))
15786 /* Note that we're just copying the block's data pointer
15787 here, not the actual data. We're still pointing into the
15788 info_buffer for SYM's objfile; right now we never release
15789 that buffer, but when we do clean up properly this may
15791 baton
->size
= DW_BLOCK (attr
)->size
;
15792 baton
->data
= DW_BLOCK (attr
)->data
;
15796 dwarf2_invalid_attrib_class_complaint ("location description",
15797 SYMBOL_NATURAL_NAME (sym
));
15801 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
15802 SYMBOL_LOCATION_BATON (sym
) = baton
;
15806 /* Return the OBJFILE associated with the compilation unit CU. If CU
15807 came from a separate debuginfo file, then the master objfile is
15811 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
15813 struct objfile
*objfile
= per_cu
->objfile
;
15815 /* Return the master objfile, so that we can report and look up the
15816 correct file containing this variable. */
15817 if (objfile
->separate_debug_objfile_backlink
)
15818 objfile
= objfile
->separate_debug_objfile_backlink
;
15823 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
15824 (CU_HEADERP is unused in such case) or prepare a temporary copy at
15825 CU_HEADERP first. */
15827 static const struct comp_unit_head
*
15828 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
15829 struct dwarf2_per_cu_data
*per_cu
)
15831 struct objfile
*objfile
;
15832 struct dwarf2_per_objfile
*per_objfile
;
15833 gdb_byte
*info_ptr
;
15836 return &per_cu
->cu
->header
;
15838 objfile
= per_cu
->objfile
;
15839 per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
15840 info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
.sect_off
;
15842 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
15843 read_comp_unit_head (cu_headerp
, info_ptr
, objfile
->obfd
);
15848 /* Return the address size given in the compilation unit header for CU. */
15851 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
15853 struct comp_unit_head cu_header_local
;
15854 const struct comp_unit_head
*cu_headerp
;
15856 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
15858 return cu_headerp
->addr_size
;
15861 /* Return the offset size given in the compilation unit header for CU. */
15864 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
15866 struct comp_unit_head cu_header_local
;
15867 const struct comp_unit_head
*cu_headerp
;
15869 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
15871 return cu_headerp
->offset_size
;
15874 /* See its dwarf2loc.h declaration. */
15877 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
15879 struct comp_unit_head cu_header_local
;
15880 const struct comp_unit_head
*cu_headerp
;
15882 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
15884 if (cu_headerp
->version
== 2)
15885 return cu_headerp
->addr_size
;
15887 return cu_headerp
->offset_size
;
15890 /* Return the text offset of the CU. The returned offset comes from
15891 this CU's objfile. If this objfile came from a separate debuginfo
15892 file, then the offset may be different from the corresponding
15893 offset in the parent objfile. */
15896 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
15898 struct objfile
*objfile
= per_cu
->objfile
;
15900 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15903 /* Locate the .debug_info compilation unit from CU's objfile which contains
15904 the DIE at OFFSET. Raises an error on failure. */
15906 static struct dwarf2_per_cu_data
*
15907 dwarf2_find_containing_comp_unit (sect_offset offset
,
15908 struct objfile
*objfile
)
15910 struct dwarf2_per_cu_data
*this_cu
;
15914 high
= dwarf2_per_objfile
->n_comp_units
- 1;
15917 int mid
= low
+ (high
- low
) / 2;
15919 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
.sect_off
15920 >= offset
.sect_off
)
15925 gdb_assert (low
== high
);
15926 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
.sect_off
15930 error (_("Dwarf Error: could not find partial DIE containing "
15931 "offset 0x%lx [in module %s]"),
15932 (long) offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
15934 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
.sect_off
15935 <= offset
.sect_off
);
15936 return dwarf2_per_objfile
->all_comp_units
[low
-1];
15940 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
15941 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
15942 && offset
.sect_off
>= this_cu
->offset
.sect_off
+ this_cu
->length
)
15943 error (_("invalid dwarf2 offset %u"), offset
.sect_off
);
15944 gdb_assert (offset
.sect_off
< this_cu
->offset
.sect_off
+ this_cu
->length
);
15949 /* Initialize dwarf2_cu CU, owned by PER_CU. */
15952 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
15954 memset (cu
, 0, sizeof (*cu
));
15956 cu
->per_cu
= per_cu
;
15957 cu
->objfile
= per_cu
->objfile
;
15958 obstack_init (&cu
->comp_unit_obstack
);
15961 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
15964 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
)
15966 struct attribute
*attr
;
15968 /* Set the language we're debugging. */
15969 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
15971 set_cu_language (DW_UNSND (attr
), cu
);
15974 cu
->language
= language_minimal
;
15975 cu
->language_defn
= language_def (cu
->language
);
15979 /* Release one cached compilation unit, CU. We unlink it from the tree
15980 of compilation units, but we don't remove it from the read_in_chain;
15981 the caller is responsible for that.
15982 NOTE: DATA is a void * because this function is also used as a
15983 cleanup routine. */
15986 free_heap_comp_unit (void *data
)
15988 struct dwarf2_cu
*cu
= data
;
15990 gdb_assert (cu
->per_cu
!= NULL
);
15991 cu
->per_cu
->cu
= NULL
;
15994 obstack_free (&cu
->comp_unit_obstack
, NULL
);
15999 /* This cleanup function is passed the address of a dwarf2_cu on the stack
16000 when we're finished with it. We can't free the pointer itself, but be
16001 sure to unlink it from the cache. Also release any associated storage
16002 and perform cache maintenance.
16004 Only used during partial symbol parsing. */
16007 free_stack_comp_unit (void *data
)
16009 struct dwarf2_cu
*cu
= data
;
16011 gdb_assert (cu
->per_cu
!= NULL
);
16012 cu
->per_cu
->cu
= NULL
;
16015 obstack_free (&cu
->comp_unit_obstack
, NULL
);
16016 cu
->partial_dies
= NULL
;
16018 /* The previous code only did this if per_cu != NULL.
16019 But that would always succeed, so now we just unconditionally do
16020 the aging. This seems like the wrong place to do such aging,
16021 but cleaning that up is left for later. */
16022 age_cached_comp_units ();
16025 /* Free all cached compilation units. */
16028 free_cached_comp_units (void *data
)
16030 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
16032 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16033 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
16034 while (per_cu
!= NULL
)
16036 struct dwarf2_per_cu_data
*next_cu
;
16038 next_cu
= per_cu
->cu
->read_in_chain
;
16040 free_heap_comp_unit (per_cu
->cu
);
16041 *last_chain
= next_cu
;
16047 /* Increase the age counter on each cached compilation unit, and free
16048 any that are too old. */
16051 age_cached_comp_units (void)
16053 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
16055 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
16056 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16057 while (per_cu
!= NULL
)
16059 per_cu
->cu
->last_used
++;
16060 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
16061 dwarf2_mark (per_cu
->cu
);
16062 per_cu
= per_cu
->cu
->read_in_chain
;
16065 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16066 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
16067 while (per_cu
!= NULL
)
16069 struct dwarf2_per_cu_data
*next_cu
;
16071 next_cu
= per_cu
->cu
->read_in_chain
;
16073 if (!per_cu
->cu
->mark
)
16075 free_heap_comp_unit (per_cu
->cu
);
16076 *last_chain
= next_cu
;
16079 last_chain
= &per_cu
->cu
->read_in_chain
;
16085 /* Remove a single compilation unit from the cache. */
16088 free_one_cached_comp_unit (void *target_cu
)
16090 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
16092 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16093 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
16094 while (per_cu
!= NULL
)
16096 struct dwarf2_per_cu_data
*next_cu
;
16098 next_cu
= per_cu
->cu
->read_in_chain
;
16100 if (per_cu
->cu
== target_cu
)
16102 free_heap_comp_unit (per_cu
->cu
);
16103 *last_chain
= next_cu
;
16107 last_chain
= &per_cu
->cu
->read_in_chain
;
16113 /* Release all extra memory associated with OBJFILE. */
16116 dwarf2_free_objfile (struct objfile
*objfile
)
16118 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
16120 if (dwarf2_per_objfile
== NULL
)
16123 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
16124 free_cached_comp_units (NULL
);
16126 if (dwarf2_per_objfile
->quick_file_names_table
)
16127 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
16129 /* Everything else should be on the objfile obstack. */
16132 /* A pair of DIE offset and GDB type pointer. We store these
16133 in a hash table separate from the DIEs, and preserve them
16134 when the DIEs are flushed out of cache. */
16136 struct dwarf2_offset_and_type
16138 sect_offset offset
;
16142 /* Hash function for a dwarf2_offset_and_type. */
16145 offset_and_type_hash (const void *item
)
16147 const struct dwarf2_offset_and_type
*ofs
= item
;
16149 return ofs
->offset
.sect_off
;
16152 /* Equality function for a dwarf2_offset_and_type. */
16155 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
16157 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
16158 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
16160 return ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
;
16163 /* Set the type associated with DIE to TYPE. Save it in CU's hash
16164 table if necessary. For convenience, return TYPE.
16166 The DIEs reading must have careful ordering to:
16167 * Not cause infite loops trying to read in DIEs as a prerequisite for
16168 reading current DIE.
16169 * Not trying to dereference contents of still incompletely read in types
16170 while reading in other DIEs.
16171 * Enable referencing still incompletely read in types just by a pointer to
16172 the type without accessing its fields.
16174 Therefore caller should follow these rules:
16175 * Try to fetch any prerequisite types we may need to build this DIE type
16176 before building the type and calling set_die_type.
16177 * After building type call set_die_type for current DIE as soon as
16178 possible before fetching more types to complete the current type.
16179 * Make the type as complete as possible before fetching more types. */
16181 static struct type
*
16182 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
16184 struct dwarf2_offset_and_type
**slot
, ofs
;
16185 struct objfile
*objfile
= cu
->objfile
;
16186 htab_t
*type_hash_ptr
;
16188 /* For Ada types, make sure that the gnat-specific data is always
16189 initialized (if not already set). There are a few types where
16190 we should not be doing so, because the type-specific area is
16191 already used to hold some other piece of info (eg: TYPE_CODE_FLT
16192 where the type-specific area is used to store the floatformat).
16193 But this is not a problem, because the gnat-specific information
16194 is actually not needed for these types. */
16195 if (need_gnat_info (cu
)
16196 && TYPE_CODE (type
) != TYPE_CODE_FUNC
16197 && TYPE_CODE (type
) != TYPE_CODE_FLT
16198 && !HAVE_GNAT_AUX_INFO (type
))
16199 INIT_GNAT_SPECIFIC (type
);
16201 if (cu
->per_cu
->debug_types_section
)
16202 type_hash_ptr
= &dwarf2_per_objfile
->debug_types_type_hash
;
16204 type_hash_ptr
= &dwarf2_per_objfile
->debug_info_type_hash
;
16206 if (*type_hash_ptr
== NULL
)
16209 = htab_create_alloc_ex (127,
16210 offset_and_type_hash
,
16211 offset_and_type_eq
,
16213 &objfile
->objfile_obstack
,
16214 hashtab_obstack_allocate
,
16215 dummy_obstack_deallocate
);
16218 ofs
.offset
= die
->offset
;
16220 slot
= (struct dwarf2_offset_and_type
**)
16221 htab_find_slot_with_hash (*type_hash_ptr
, &ofs
, ofs
.offset
.sect_off
,
16224 complaint (&symfile_complaints
,
16225 _("A problem internal to GDB: DIE 0x%x has type already set"),
16226 die
->offset
.sect_off
);
16227 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
16232 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
16233 table, or return NULL if the die does not have a saved type. */
16235 static struct type
*
16236 get_die_type_at_offset (sect_offset offset
,
16237 struct dwarf2_per_cu_data
*per_cu
)
16239 struct dwarf2_offset_and_type
*slot
, ofs
;
16242 if (per_cu
->debug_types_section
)
16243 type_hash
= dwarf2_per_objfile
->debug_types_type_hash
;
16245 type_hash
= dwarf2_per_objfile
->debug_info_type_hash
;
16246 if (type_hash
== NULL
)
16249 ofs
.offset
= offset
;
16250 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
.sect_off
);
16257 /* Look up the type for DIE in the appropriate type_hash table,
16258 or return NULL if DIE does not have a saved type. */
16260 static struct type
*
16261 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16263 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
16266 /* Add a dependence relationship from CU to REF_PER_CU. */
16269 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
16270 struct dwarf2_per_cu_data
*ref_per_cu
)
16274 if (cu
->dependencies
== NULL
)
16276 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
16277 NULL
, &cu
->comp_unit_obstack
,
16278 hashtab_obstack_allocate
,
16279 dummy_obstack_deallocate
);
16281 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
16283 *slot
= ref_per_cu
;
16286 /* Subroutine of dwarf2_mark to pass to htab_traverse.
16287 Set the mark field in every compilation unit in the
16288 cache that we must keep because we are keeping CU. */
16291 dwarf2_mark_helper (void **slot
, void *data
)
16293 struct dwarf2_per_cu_data
*per_cu
;
16295 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
16297 /* cu->dependencies references may not yet have been ever read if QUIT aborts
16298 reading of the chain. As such dependencies remain valid it is not much
16299 useful to track and undo them during QUIT cleanups. */
16300 if (per_cu
->cu
== NULL
)
16303 if (per_cu
->cu
->mark
)
16305 per_cu
->cu
->mark
= 1;
16307 if (per_cu
->cu
->dependencies
!= NULL
)
16308 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
16313 /* Set the mark field in CU and in every other compilation unit in the
16314 cache that we must keep because we are keeping CU. */
16317 dwarf2_mark (struct dwarf2_cu
*cu
)
16322 if (cu
->dependencies
!= NULL
)
16323 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
16327 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
16331 per_cu
->cu
->mark
= 0;
16332 per_cu
= per_cu
->cu
->read_in_chain
;
16336 /* Trivial hash function for partial_die_info: the hash value of a DIE
16337 is its offset in .debug_info for this objfile. */
16340 partial_die_hash (const void *item
)
16342 const struct partial_die_info
*part_die
= item
;
16344 return part_die
->offset
.sect_off
;
16347 /* Trivial comparison function for partial_die_info structures: two DIEs
16348 are equal if they have the same offset. */
16351 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
16353 const struct partial_die_info
*part_die_lhs
= item_lhs
;
16354 const struct partial_die_info
*part_die_rhs
= item_rhs
;
16356 return part_die_lhs
->offset
.sect_off
== part_die_rhs
->offset
.sect_off
;
16359 static struct cmd_list_element
*set_dwarf2_cmdlist
;
16360 static struct cmd_list_element
*show_dwarf2_cmdlist
;
16363 set_dwarf2_cmd (char *args
, int from_tty
)
16365 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
16369 show_dwarf2_cmd (char *args
, int from_tty
)
16371 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
16374 /* If section described by INFO was mmapped, munmap it now. */
16377 munmap_section_buffer (struct dwarf2_section_info
*info
)
16379 if (info
->map_addr
!= NULL
)
16384 res
= munmap (info
->map_addr
, info
->map_len
);
16385 gdb_assert (res
== 0);
16387 /* Without HAVE_MMAP, we should never be here to begin with. */
16388 gdb_assert_not_reached ("no mmap support");
16393 /* munmap debug sections for OBJFILE, if necessary. */
16396 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
16398 struct dwarf2_per_objfile
*data
= d
;
16400 struct dwarf2_section_info
*section
;
16402 /* This is sorted according to the order they're defined in to make it easier
16403 to keep in sync. */
16404 munmap_section_buffer (&data
->info
);
16405 munmap_section_buffer (&data
->abbrev
);
16406 munmap_section_buffer (&data
->line
);
16407 munmap_section_buffer (&data
->loc
);
16408 munmap_section_buffer (&data
->macinfo
);
16409 munmap_section_buffer (&data
->macro
);
16410 munmap_section_buffer (&data
->str
);
16411 munmap_section_buffer (&data
->ranges
);
16412 munmap_section_buffer (&data
->frame
);
16413 munmap_section_buffer (&data
->eh_frame
);
16414 munmap_section_buffer (&data
->gdb_index
);
16417 VEC_iterate (dwarf2_section_info_def
, data
->types
, ix
, section
);
16419 munmap_section_buffer (section
);
16421 VEC_free (dwarf2_section_info_def
, data
->types
);
16425 /* The "save gdb-index" command. */
16427 /* The contents of the hash table we create when building the string
16429 struct strtab_entry
16431 offset_type offset
;
16435 /* Hash function for a strtab_entry.
16437 Function is used only during write_hash_table so no index format backward
16438 compatibility is needed. */
16441 hash_strtab_entry (const void *e
)
16443 const struct strtab_entry
*entry
= e
;
16444 return mapped_index_string_hash (INT_MAX
, entry
->str
);
16447 /* Equality function for a strtab_entry. */
16450 eq_strtab_entry (const void *a
, const void *b
)
16452 const struct strtab_entry
*ea
= a
;
16453 const struct strtab_entry
*eb
= b
;
16454 return !strcmp (ea
->str
, eb
->str
);
16457 /* Create a strtab_entry hash table. */
16460 create_strtab (void)
16462 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
16463 xfree
, xcalloc
, xfree
);
16466 /* Add a string to the constant pool. Return the string's offset in
16470 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
16473 struct strtab_entry entry
;
16474 struct strtab_entry
*result
;
16477 slot
= htab_find_slot (table
, &entry
, INSERT
);
16482 result
= XNEW (struct strtab_entry
);
16483 result
->offset
= obstack_object_size (cpool
);
16485 obstack_grow_str0 (cpool
, str
);
16488 return result
->offset
;
16491 /* An entry in the symbol table. */
16492 struct symtab_index_entry
16494 /* The name of the symbol. */
16496 /* The offset of the name in the constant pool. */
16497 offset_type index_offset
;
16498 /* A sorted vector of the indices of all the CUs that hold an object
16500 VEC (offset_type
) *cu_indices
;
16503 /* The symbol table. This is a power-of-2-sized hash table. */
16504 struct mapped_symtab
16506 offset_type n_elements
;
16508 struct symtab_index_entry
**data
;
16511 /* Hash function for a symtab_index_entry. */
16514 hash_symtab_entry (const void *e
)
16516 const struct symtab_index_entry
*entry
= e
;
16517 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
16518 sizeof (offset_type
) * VEC_length (offset_type
,
16519 entry
->cu_indices
),
16523 /* Equality function for a symtab_index_entry. */
16526 eq_symtab_entry (const void *a
, const void *b
)
16528 const struct symtab_index_entry
*ea
= a
;
16529 const struct symtab_index_entry
*eb
= b
;
16530 int len
= VEC_length (offset_type
, ea
->cu_indices
);
16531 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
16533 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
16534 VEC_address (offset_type
, eb
->cu_indices
),
16535 sizeof (offset_type
) * len
);
16538 /* Destroy a symtab_index_entry. */
16541 delete_symtab_entry (void *p
)
16543 struct symtab_index_entry
*entry
= p
;
16544 VEC_free (offset_type
, entry
->cu_indices
);
16548 /* Create a hash table holding symtab_index_entry objects. */
16551 create_symbol_hash_table (void)
16553 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
16554 delete_symtab_entry
, xcalloc
, xfree
);
16557 /* Create a new mapped symtab object. */
16559 static struct mapped_symtab
*
16560 create_mapped_symtab (void)
16562 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
16563 symtab
->n_elements
= 0;
16564 symtab
->size
= 1024;
16565 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
16569 /* Destroy a mapped_symtab. */
16572 cleanup_mapped_symtab (void *p
)
16574 struct mapped_symtab
*symtab
= p
;
16575 /* The contents of the array are freed when the other hash table is
16577 xfree (symtab
->data
);
16581 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
16584 Function is used only during write_hash_table so no index format backward
16585 compatibility is needed. */
16587 static struct symtab_index_entry
**
16588 find_slot (struct mapped_symtab
*symtab
, const char *name
)
16590 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
16592 index
= hash
& (symtab
->size
- 1);
16593 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
16597 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
16598 return &symtab
->data
[index
];
16599 index
= (index
+ step
) & (symtab
->size
- 1);
16603 /* Expand SYMTAB's hash table. */
16606 hash_expand (struct mapped_symtab
*symtab
)
16608 offset_type old_size
= symtab
->size
;
16610 struct symtab_index_entry
**old_entries
= symtab
->data
;
16613 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
16615 for (i
= 0; i
< old_size
; ++i
)
16617 if (old_entries
[i
])
16619 struct symtab_index_entry
**slot
= find_slot (symtab
,
16620 old_entries
[i
]->name
);
16621 *slot
= old_entries
[i
];
16625 xfree (old_entries
);
16628 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
16629 is the index of the CU in which the symbol appears. */
16632 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
16633 offset_type cu_index
)
16635 struct symtab_index_entry
**slot
;
16637 ++symtab
->n_elements
;
16638 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
16639 hash_expand (symtab
);
16641 slot
= find_slot (symtab
, name
);
16644 *slot
= XNEW (struct symtab_index_entry
);
16645 (*slot
)->name
= name
;
16646 (*slot
)->cu_indices
= NULL
;
16648 /* Don't push an index twice. Due to how we add entries we only
16649 have to check the last one. */
16650 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
16651 || VEC_last (offset_type
, (*slot
)->cu_indices
) != cu_index
)
16652 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
16655 /* Add a vector of indices to the constant pool. */
16658 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
16659 struct symtab_index_entry
*entry
)
16663 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
16666 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
16667 offset_type val
= MAYBE_SWAP (len
);
16672 entry
->index_offset
= obstack_object_size (cpool
);
16674 obstack_grow (cpool
, &val
, sizeof (val
));
16676 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
16679 val
= MAYBE_SWAP (iter
);
16680 obstack_grow (cpool
, &val
, sizeof (val
));
16685 struct symtab_index_entry
*old_entry
= *slot
;
16686 entry
->index_offset
= old_entry
->index_offset
;
16689 return entry
->index_offset
;
16692 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
16693 constant pool entries going into the obstack CPOOL. */
16696 write_hash_table (struct mapped_symtab
*symtab
,
16697 struct obstack
*output
, struct obstack
*cpool
)
16700 htab_t symbol_hash_table
;
16703 symbol_hash_table
= create_symbol_hash_table ();
16704 str_table
= create_strtab ();
16706 /* We add all the index vectors to the constant pool first, to
16707 ensure alignment is ok. */
16708 for (i
= 0; i
< symtab
->size
; ++i
)
16710 if (symtab
->data
[i
])
16711 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
16714 /* Now write out the hash table. */
16715 for (i
= 0; i
< symtab
->size
; ++i
)
16717 offset_type str_off
, vec_off
;
16719 if (symtab
->data
[i
])
16721 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
16722 vec_off
= symtab
->data
[i
]->index_offset
;
16726 /* While 0 is a valid constant pool index, it is not valid
16727 to have 0 for both offsets. */
16732 str_off
= MAYBE_SWAP (str_off
);
16733 vec_off
= MAYBE_SWAP (vec_off
);
16735 obstack_grow (output
, &str_off
, sizeof (str_off
));
16736 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
16739 htab_delete (str_table
);
16740 htab_delete (symbol_hash_table
);
16743 /* Struct to map psymtab to CU index in the index file. */
16744 struct psymtab_cu_index_map
16746 struct partial_symtab
*psymtab
;
16747 unsigned int cu_index
;
16751 hash_psymtab_cu_index (const void *item
)
16753 const struct psymtab_cu_index_map
*map
= item
;
16755 return htab_hash_pointer (map
->psymtab
);
16759 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
16761 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
16762 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
16764 return lhs
->psymtab
== rhs
->psymtab
;
16767 /* Helper struct for building the address table. */
16768 struct addrmap_index_data
16770 struct objfile
*objfile
;
16771 struct obstack
*addr_obstack
;
16772 htab_t cu_index_htab
;
16774 /* Non-zero if the previous_* fields are valid.
16775 We can't write an entry until we see the next entry (since it is only then
16776 that we know the end of the entry). */
16777 int previous_valid
;
16778 /* Index of the CU in the table of all CUs in the index file. */
16779 unsigned int previous_cu_index
;
16780 /* Start address of the CU. */
16781 CORE_ADDR previous_cu_start
;
16784 /* Write an address entry to OBSTACK. */
16787 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
16788 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
16790 offset_type cu_index_to_write
;
16792 CORE_ADDR baseaddr
;
16794 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
16796 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
16797 obstack_grow (obstack
, addr
, 8);
16798 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
16799 obstack_grow (obstack
, addr
, 8);
16800 cu_index_to_write
= MAYBE_SWAP (cu_index
);
16801 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
16804 /* Worker function for traversing an addrmap to build the address table. */
16807 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
16809 struct addrmap_index_data
*data
= datap
;
16810 struct partial_symtab
*pst
= obj
;
16811 offset_type cu_index
;
16814 if (data
->previous_valid
)
16815 add_address_entry (data
->objfile
, data
->addr_obstack
,
16816 data
->previous_cu_start
, start_addr
,
16817 data
->previous_cu_index
);
16819 data
->previous_cu_start
= start_addr
;
16822 struct psymtab_cu_index_map find_map
, *map
;
16823 find_map
.psymtab
= pst
;
16824 map
= htab_find (data
->cu_index_htab
, &find_map
);
16825 gdb_assert (map
!= NULL
);
16826 data
->previous_cu_index
= map
->cu_index
;
16827 data
->previous_valid
= 1;
16830 data
->previous_valid
= 0;
16835 /* Write OBJFILE's address map to OBSTACK.
16836 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
16837 in the index file. */
16840 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
16841 htab_t cu_index_htab
)
16843 struct addrmap_index_data addrmap_index_data
;
16845 /* When writing the address table, we have to cope with the fact that
16846 the addrmap iterator only provides the start of a region; we have to
16847 wait until the next invocation to get the start of the next region. */
16849 addrmap_index_data
.objfile
= objfile
;
16850 addrmap_index_data
.addr_obstack
= obstack
;
16851 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
16852 addrmap_index_data
.previous_valid
= 0;
16854 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
16855 &addrmap_index_data
);
16857 /* It's highly unlikely the last entry (end address = 0xff...ff)
16858 is valid, but we should still handle it.
16859 The end address is recorded as the start of the next region, but that
16860 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
16862 if (addrmap_index_data
.previous_valid
)
16863 add_address_entry (objfile
, obstack
,
16864 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
16865 addrmap_index_data
.previous_cu_index
);
16868 /* Add a list of partial symbols to SYMTAB. */
16871 write_psymbols (struct mapped_symtab
*symtab
,
16873 struct partial_symbol
**psymp
,
16875 offset_type cu_index
,
16878 for (; count
-- > 0; ++psymp
)
16880 void **slot
, *lookup
;
16882 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
16883 error (_("Ada is not currently supported by the index"));
16885 /* We only want to add a given psymbol once. However, we also
16886 want to account for whether it is global or static. So, we
16887 may add it twice, using slightly different values. */
16890 uintptr_t val
= 1 | (uintptr_t) *psymp
;
16892 lookup
= (void *) val
;
16897 /* Only add a given psymbol once. */
16898 slot
= htab_find_slot (psyms_seen
, lookup
, INSERT
);
16902 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (*psymp
), cu_index
);
16907 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
16908 exception if there is an error. */
16911 write_obstack (FILE *file
, struct obstack
*obstack
)
16913 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
16915 != obstack_object_size (obstack
))
16916 error (_("couldn't data write to file"));
16919 /* Unlink a file if the argument is not NULL. */
16922 unlink_if_set (void *p
)
16924 char **filename
= p
;
16926 unlink (*filename
);
16929 /* A helper struct used when iterating over debug_types. */
16930 struct signatured_type_index_data
16932 struct objfile
*objfile
;
16933 struct mapped_symtab
*symtab
;
16934 struct obstack
*types_list
;
16939 /* A helper function that writes a single signatured_type to an
16943 write_one_signatured_type (void **slot
, void *d
)
16945 struct signatured_type_index_data
*info
= d
;
16946 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
16947 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
16948 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
16951 write_psymbols (info
->symtab
,
16953 info
->objfile
->global_psymbols
.list
16954 + psymtab
->globals_offset
,
16955 psymtab
->n_global_syms
, info
->cu_index
,
16957 write_psymbols (info
->symtab
,
16959 info
->objfile
->static_psymbols
.list
16960 + psymtab
->statics_offset
,
16961 psymtab
->n_static_syms
, info
->cu_index
,
16964 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
16965 entry
->per_cu
.offset
.sect_off
);
16966 obstack_grow (info
->types_list
, val
, 8);
16967 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->type_offset
.cu_off
);
16968 obstack_grow (info
->types_list
, val
, 8);
16969 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
16970 obstack_grow (info
->types_list
, val
, 8);
16977 /* Create an index file for OBJFILE in the directory DIR. */
16980 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
16982 struct cleanup
*cleanup
;
16983 char *filename
, *cleanup_filename
;
16984 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
16985 struct obstack cu_list
, types_cu_list
;
16988 struct mapped_symtab
*symtab
;
16989 offset_type val
, size_of_contents
, total_len
;
16993 htab_t cu_index_htab
;
16994 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
16996 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
16999 if (dwarf2_per_objfile
->using_index
)
17000 error (_("Cannot use an index to create the index"));
17002 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
17003 error (_("Cannot make an index when the file has multiple .debug_types sections"));
17005 if (stat (objfile
->name
, &st
) < 0)
17006 perror_with_name (objfile
->name
);
17008 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
17009 INDEX_SUFFIX
, (char *) NULL
);
17010 cleanup
= make_cleanup (xfree
, filename
);
17012 out_file
= fopen (filename
, "wb");
17014 error (_("Can't open `%s' for writing"), filename
);
17016 cleanup_filename
= filename
;
17017 make_cleanup (unlink_if_set
, &cleanup_filename
);
17019 symtab
= create_mapped_symtab ();
17020 make_cleanup (cleanup_mapped_symtab
, symtab
);
17022 obstack_init (&addr_obstack
);
17023 make_cleanup_obstack_free (&addr_obstack
);
17025 obstack_init (&cu_list
);
17026 make_cleanup_obstack_free (&cu_list
);
17028 obstack_init (&types_cu_list
);
17029 make_cleanup_obstack_free (&types_cu_list
);
17031 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
17032 NULL
, xcalloc
, xfree
);
17033 make_cleanup_htab_delete (psyms_seen
);
17035 /* While we're scanning CU's create a table that maps a psymtab pointer
17036 (which is what addrmap records) to its index (which is what is recorded
17037 in the index file). This will later be needed to write the address
17039 cu_index_htab
= htab_create_alloc (100,
17040 hash_psymtab_cu_index
,
17041 eq_psymtab_cu_index
,
17042 NULL
, xcalloc
, xfree
);
17043 make_cleanup_htab_delete (cu_index_htab
);
17044 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
17045 xmalloc (sizeof (struct psymtab_cu_index_map
)
17046 * dwarf2_per_objfile
->n_comp_units
);
17047 make_cleanup (xfree
, psymtab_cu_index_map
);
17049 /* The CU list is already sorted, so we don't need to do additional
17050 work here. Also, the debug_types entries do not appear in
17051 all_comp_units, but only in their own hash table. */
17052 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
17054 struct dwarf2_per_cu_data
*per_cu
17055 = dwarf2_per_objfile
->all_comp_units
[i
];
17056 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
17058 struct psymtab_cu_index_map
*map
;
17061 write_psymbols (symtab
,
17063 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
17064 psymtab
->n_global_syms
, i
,
17066 write_psymbols (symtab
,
17068 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
17069 psymtab
->n_static_syms
, i
,
17072 map
= &psymtab_cu_index_map
[i
];
17073 map
->psymtab
= psymtab
;
17075 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
17076 gdb_assert (slot
!= NULL
);
17077 gdb_assert (*slot
== NULL
);
17080 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
17081 per_cu
->offset
.sect_off
);
17082 obstack_grow (&cu_list
, val
, 8);
17083 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
17084 obstack_grow (&cu_list
, val
, 8);
17087 /* Dump the address map. */
17088 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
17090 /* Write out the .debug_type entries, if any. */
17091 if (dwarf2_per_objfile
->signatured_types
)
17093 struct signatured_type_index_data sig_data
;
17095 sig_data
.objfile
= objfile
;
17096 sig_data
.symtab
= symtab
;
17097 sig_data
.types_list
= &types_cu_list
;
17098 sig_data
.psyms_seen
= psyms_seen
;
17099 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
17100 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
17101 write_one_signatured_type
, &sig_data
);
17104 obstack_init (&constant_pool
);
17105 make_cleanup_obstack_free (&constant_pool
);
17106 obstack_init (&symtab_obstack
);
17107 make_cleanup_obstack_free (&symtab_obstack
);
17108 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
17110 obstack_init (&contents
);
17111 make_cleanup_obstack_free (&contents
);
17112 size_of_contents
= 6 * sizeof (offset_type
);
17113 total_len
= size_of_contents
;
17115 /* The version number. */
17116 val
= MAYBE_SWAP (6);
17117 obstack_grow (&contents
, &val
, sizeof (val
));
17119 /* The offset of the CU list from the start of the file. */
17120 val
= MAYBE_SWAP (total_len
);
17121 obstack_grow (&contents
, &val
, sizeof (val
));
17122 total_len
+= obstack_object_size (&cu_list
);
17124 /* The offset of the types CU list from the start of the file. */
17125 val
= MAYBE_SWAP (total_len
);
17126 obstack_grow (&contents
, &val
, sizeof (val
));
17127 total_len
+= obstack_object_size (&types_cu_list
);
17129 /* The offset of the address table from the start of the file. */
17130 val
= MAYBE_SWAP (total_len
);
17131 obstack_grow (&contents
, &val
, sizeof (val
));
17132 total_len
+= obstack_object_size (&addr_obstack
);
17134 /* The offset of the symbol table from the start of the file. */
17135 val
= MAYBE_SWAP (total_len
);
17136 obstack_grow (&contents
, &val
, sizeof (val
));
17137 total_len
+= obstack_object_size (&symtab_obstack
);
17139 /* The offset of the constant pool from the start of the file. */
17140 val
= MAYBE_SWAP (total_len
);
17141 obstack_grow (&contents
, &val
, sizeof (val
));
17142 total_len
+= obstack_object_size (&constant_pool
);
17144 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
17146 write_obstack (out_file
, &contents
);
17147 write_obstack (out_file
, &cu_list
);
17148 write_obstack (out_file
, &types_cu_list
);
17149 write_obstack (out_file
, &addr_obstack
);
17150 write_obstack (out_file
, &symtab_obstack
);
17151 write_obstack (out_file
, &constant_pool
);
17155 /* We want to keep the file, so we set cleanup_filename to NULL
17156 here. See unlink_if_set. */
17157 cleanup_filename
= NULL
;
17159 do_cleanups (cleanup
);
17162 /* Implementation of the `save gdb-index' command.
17164 Note that the file format used by this command is documented in the
17165 GDB manual. Any changes here must be documented there. */
17168 save_gdb_index_command (char *arg
, int from_tty
)
17170 struct objfile
*objfile
;
17173 error (_("usage: save gdb-index DIRECTORY"));
17175 ALL_OBJFILES (objfile
)
17179 /* If the objfile does not correspond to an actual file, skip it. */
17180 if (stat (objfile
->name
, &st
) < 0)
17183 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
17184 if (dwarf2_per_objfile
)
17186 volatile struct gdb_exception except
;
17188 TRY_CATCH (except
, RETURN_MASK_ERROR
)
17190 write_psymtabs_to_index (objfile
, arg
);
17192 if (except
.reason
< 0)
17193 exception_fprintf (gdb_stderr
, except
,
17194 _("Error while writing index for `%s': "),
17202 int dwarf2_always_disassemble
;
17205 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
17206 struct cmd_list_element
*c
, const char *value
)
17208 fprintf_filtered (file
,
17209 _("Whether to always disassemble "
17210 "DWARF expressions is %s.\n"),
17215 show_check_physname (struct ui_file
*file
, int from_tty
,
17216 struct cmd_list_element
*c
, const char *value
)
17218 fprintf_filtered (file
,
17219 _("Whether to check \"physname\" is %s.\n"),
17223 void _initialize_dwarf2_read (void);
17226 _initialize_dwarf2_read (void)
17228 struct cmd_list_element
*c
;
17230 dwarf2_objfile_data_key
17231 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
17233 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
17234 Set DWARF 2 specific variables.\n\
17235 Configure DWARF 2 variables such as the cache size"),
17236 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
17237 0/*allow-unknown*/, &maintenance_set_cmdlist
);
17239 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
17240 Show DWARF 2 specific variables\n\
17241 Show DWARF 2 variables such as the cache size"),
17242 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
17243 0/*allow-unknown*/, &maintenance_show_cmdlist
);
17245 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
17246 &dwarf2_max_cache_age
, _("\
17247 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
17248 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
17249 A higher limit means that cached compilation units will be stored\n\
17250 in memory longer, and more total memory will be used. Zero disables\n\
17251 caching, which can slow down startup."),
17253 show_dwarf2_max_cache_age
,
17254 &set_dwarf2_cmdlist
,
17255 &show_dwarf2_cmdlist
);
17257 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
17258 &dwarf2_always_disassemble
, _("\
17259 Set whether `info address' always disassembles DWARF expressions."), _("\
17260 Show whether `info address' always disassembles DWARF expressions."), _("\
17261 When enabled, DWARF expressions are always printed in an assembly-like\n\
17262 syntax. When disabled, expressions will be printed in a more\n\
17263 conversational style, when possible."),
17265 show_dwarf2_always_disassemble
,
17266 &set_dwarf2_cmdlist
,
17267 &show_dwarf2_cmdlist
);
17269 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
17270 Set debugging of the dwarf2 DIE reader."), _("\
17271 Show debugging of the dwarf2 DIE reader."), _("\
17272 When enabled (non-zero), DIEs are dumped after they are read in.\n\
17273 The value is the maximum depth to print."),
17276 &setdebuglist
, &showdebuglist
);
17278 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
17279 Set cross-checking of \"physname\" code against demangler."), _("\
17280 Show cross-checking of \"physname\" code against demangler."), _("\
17281 When enabled, GDB's internal \"physname\" code is checked against\n\
17283 NULL
, show_check_physname
,
17284 &setdebuglist
, &showdebuglist
);
17286 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
17288 Save a gdb-index file.\n\
17289 Usage: save gdb-index DIRECTORY"),
17291 set_cmd_completer (c
, filename_completer
);