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;
90 /* When set, the file that we're processing is known to have debugging
91 info for C++ namespaces. GCC 3.3.x did not produce this information,
92 but later versions do. */
94 static int processing_has_namespace_info
;
96 static const struct objfile_data
*dwarf2_objfile_data_key
;
98 struct dwarf2_section_info
103 /* Not NULL if the section was actually mmapped. */
105 /* Page aligned size of mmapped area. */
106 bfd_size_type map_len
;
107 /* True if we have tried to read this section. */
111 typedef struct dwarf2_section_info dwarf2_section_info_def
;
112 DEF_VEC_O (dwarf2_section_info_def
);
114 /* All offsets in the index are of this type. It must be
115 architecture-independent. */
116 typedef uint32_t offset_type
;
118 DEF_VEC_I (offset_type
);
120 /* A description of the mapped index. The file format is described in
121 a comment by the code that writes the index. */
124 /* Index data format version. */
127 /* The total length of the buffer. */
130 /* A pointer to the address table data. */
131 const gdb_byte
*address_table
;
133 /* Size of the address table data in bytes. */
134 offset_type address_table_size
;
136 /* The symbol table, implemented as a hash table. */
137 const offset_type
*symbol_table
;
139 /* Size in slots, each slot is 2 offset_types. */
140 offset_type symbol_table_slots
;
142 /* A pointer to the constant pool. */
143 const char *constant_pool
;
146 /* Collection of data recorded per objfile.
147 This hangs off of dwarf2_objfile_data_key. */
149 struct dwarf2_per_objfile
151 struct dwarf2_section_info info
;
152 struct dwarf2_section_info abbrev
;
153 struct dwarf2_section_info line
;
154 struct dwarf2_section_info loc
;
155 struct dwarf2_section_info macinfo
;
156 struct dwarf2_section_info macro
;
157 struct dwarf2_section_info str
;
158 struct dwarf2_section_info ranges
;
159 struct dwarf2_section_info frame
;
160 struct dwarf2_section_info eh_frame
;
161 struct dwarf2_section_info gdb_index
;
163 VEC (dwarf2_section_info_def
) *types
;
166 struct objfile
*objfile
;
168 /* Table of all the compilation units. This is used to locate
169 the target compilation unit of a particular reference. */
170 struct dwarf2_per_cu_data
**all_comp_units
;
172 /* The number of compilation units in ALL_COMP_UNITS. */
175 /* The number of .debug_types-related CUs. */
178 /* The .debug_types-related CUs (TUs). */
179 struct dwarf2_per_cu_data
**all_type_units
;
181 /* A chain of compilation units that are currently read in, so that
182 they can be freed later. */
183 struct dwarf2_per_cu_data
*read_in_chain
;
185 /* A table mapping .debug_types signatures to its signatured_type entry.
186 This is NULL if the .debug_types section hasn't been read in yet. */
187 htab_t signatured_types
;
189 /* A flag indicating wether this objfile has a section loaded at a
191 int has_section_at_zero
;
193 /* True if we are using the mapped index,
194 or we are faking it for OBJF_READNOW's sake. */
195 unsigned char using_index
;
197 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
198 struct mapped_index
*index_table
;
200 /* When using index_table, this keeps track of all quick_file_names entries.
201 TUs can share line table entries with CUs or other TUs, and there can be
202 a lot more TUs than unique line tables, so we maintain a separate table
203 of all line table entries to support the sharing. */
204 htab_t quick_file_names_table
;
206 /* Set during partial symbol reading, to prevent queueing of full
208 int reading_partial_symbols
;
210 /* Table mapping type .debug_info DIE offsets to types.
211 This is NULL if not allocated yet.
212 It (currently) makes sense to allocate debug_types_type_hash lazily.
213 To keep things simple we allocate both lazily. */
214 htab_t debug_info_type_hash
;
216 /* Table mapping type .debug_types DIE offsets to types.
217 This is NULL if not allocated yet. */
218 htab_t debug_types_type_hash
;
221 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
223 /* Default names of the debugging sections. */
225 /* Note that if the debugging section has been compressed, it might
226 have a name like .zdebug_info. */
228 static const struct dwarf2_debug_sections dwarf2_elf_names
=
230 { ".debug_info", ".zdebug_info" },
231 { ".debug_abbrev", ".zdebug_abbrev" },
232 { ".debug_line", ".zdebug_line" },
233 { ".debug_loc", ".zdebug_loc" },
234 { ".debug_macinfo", ".zdebug_macinfo" },
235 { ".debug_macro", ".zdebug_macro" },
236 { ".debug_str", ".zdebug_str" },
237 { ".debug_ranges", ".zdebug_ranges" },
238 { ".debug_types", ".zdebug_types" },
239 { ".debug_frame", ".zdebug_frame" },
240 { ".eh_frame", NULL
},
241 { ".gdb_index", ".zgdb_index" },
245 /* local data types */
247 /* We hold several abbreviation tables in memory at the same time. */
248 #ifndef ABBREV_HASH_SIZE
249 #define ABBREV_HASH_SIZE 121
252 /* The data in a compilation unit header, after target2host
253 translation, looks like this. */
254 struct comp_unit_head
258 unsigned char addr_size
;
259 unsigned char signed_addr_p
;
260 unsigned int abbrev_offset
;
262 /* Size of file offsets; either 4 or 8. */
263 unsigned int offset_size
;
265 /* Size of the length field; either 4 or 12. */
266 unsigned int initial_length_size
;
268 /* Offset to the first byte of this compilation unit header in the
269 .debug_info section, for resolving relative reference dies. */
272 /* Offset to first die in this cu from the start of the cu.
273 This will be the first byte following the compilation unit header. */
274 unsigned int first_die_offset
;
277 /* Type used for delaying computation of method physnames.
278 See comments for compute_delayed_physnames. */
279 struct delayed_method_info
281 /* The type to which the method is attached, i.e., its parent class. */
284 /* The index of the method in the type's function fieldlists. */
287 /* The index of the method in the fieldlist. */
290 /* The name of the DIE. */
293 /* The DIE associated with this method. */
294 struct die_info
*die
;
297 typedef struct delayed_method_info delayed_method_info
;
298 DEF_VEC_O (delayed_method_info
);
300 /* Internal state when decoding a particular compilation unit. */
303 /* The objfile containing this compilation unit. */
304 struct objfile
*objfile
;
306 /* The header of the compilation unit. */
307 struct comp_unit_head header
;
309 /* Base address of this compilation unit. */
310 CORE_ADDR base_address
;
312 /* Non-zero if base_address has been set. */
315 /* The language we are debugging. */
316 enum language language
;
317 const struct language_defn
*language_defn
;
319 const char *producer
;
321 /* The generic symbol table building routines have separate lists for
322 file scope symbols and all all other scopes (local scopes). So
323 we need to select the right one to pass to add_symbol_to_list().
324 We do it by keeping a pointer to the correct list in list_in_scope.
326 FIXME: The original dwarf code just treated the file scope as the
327 first local scope, and all other local scopes as nested local
328 scopes, and worked fine. Check to see if we really need to
329 distinguish these in buildsym.c. */
330 struct pending
**list_in_scope
;
332 /* DWARF abbreviation table associated with this compilation unit. */
333 struct abbrev_info
**dwarf2_abbrevs
;
335 /* Storage for the abbrev table. */
336 struct obstack abbrev_obstack
;
338 /* Hash table holding all the loaded partial DIEs. */
341 /* Storage for things with the same lifetime as this read-in compilation
342 unit, including partial DIEs. */
343 struct obstack comp_unit_obstack
;
345 /* When multiple dwarf2_cu structures are living in memory, this field
346 chains them all together, so that they can be released efficiently.
347 We will probably also want a generation counter so that most-recently-used
348 compilation units are cached... */
349 struct dwarf2_per_cu_data
*read_in_chain
;
351 /* Backchain to our per_cu entry if the tree has been built. */
352 struct dwarf2_per_cu_data
*per_cu
;
354 /* How many compilation units ago was this CU last referenced? */
357 /* A hash table of die offsets for following references. */
360 /* Full DIEs if read in. */
361 struct die_info
*dies
;
363 /* A set of pointers to dwarf2_per_cu_data objects for compilation
364 units referenced by this one. Only set during full symbol processing;
365 partial symbol tables do not have dependencies. */
368 /* Header data from the line table, during full symbol processing. */
369 struct line_header
*line_header
;
371 /* A list of methods which need to have physnames computed
372 after all type information has been read. */
373 VEC (delayed_method_info
) *method_list
;
375 /* To be copied to symtab->call_site_htab. */
376 htab_t call_site_htab
;
378 /* Mark used when releasing cached dies. */
379 unsigned int mark
: 1;
381 /* This flag will be set if this compilation unit might include
382 inter-compilation-unit references. */
383 unsigned int has_form_ref_addr
: 1;
385 /* This flag will be set if this compilation unit includes any
386 DW_TAG_namespace DIEs. If we know that there are explicit
387 DIEs for namespaces, we don't need to try to infer them
388 from mangled names. */
389 unsigned int has_namespace_info
: 1;
391 /* This CU references .debug_loc. See the symtab->locations_valid field.
392 This test is imperfect as there may exist optimized debug code not using
393 any location list and still facing inlining issues if handled as
394 unoptimized code. For a future better test see GCC PR other/32998. */
395 unsigned int has_loclist
: 1;
398 /* Persistent data held for a compilation unit, even when not
399 processing it. We put a pointer to this structure in the
400 read_symtab_private field of the psymtab. */
402 struct dwarf2_per_cu_data
404 /* The start offset and length of this compilation unit. 2**29-1
405 bytes should suffice to store the length of any compilation unit
406 - if it doesn't, GDB will fall over anyway.
407 NOTE: Unlike comp_unit_head.length, this length includes
408 initial_length_size. */
410 unsigned int length
: 29;
412 /* Flag indicating this compilation unit will be read in before
413 any of the current compilation units are processed. */
414 unsigned int queued
: 1;
416 /* This flag will be set if we need to load absolutely all DIEs
417 for this compilation unit, instead of just the ones we think
418 are interesting. It gets set if we look for a DIE in the
419 hash table and don't find it. */
420 unsigned int load_all_dies
: 1;
422 /* Non-null if this CU is from .debug_types; in which case it points
423 to the section. Otherwise it's from .debug_info. */
424 struct dwarf2_section_info
*debug_types_section
;
426 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
427 of the CU cache it gets reset to NULL again. */
428 struct dwarf2_cu
*cu
;
430 /* The corresponding objfile.
431 Normally we can get the objfile from dwarf2_per_objfile.
432 However we can enter this file with just a "per_cu" handle. */
433 struct objfile
*objfile
;
435 /* When using partial symbol tables, the 'psymtab' field is active.
436 Otherwise the 'quick' field is active. */
439 /* The partial symbol table associated with this compilation unit,
440 or NULL for partial units (which do not have an associated
442 struct partial_symtab
*psymtab
;
444 /* Data needed by the "quick" functions. */
445 struct dwarf2_per_cu_quick_data
*quick
;
449 /* Entry in the signatured_types hash table. */
451 struct signatured_type
455 /* Offset in .debug_types of the type defined by this TU. */
456 unsigned int type_offset
;
458 /* The CU(/TU) of this type. */
459 struct dwarf2_per_cu_data per_cu
;
462 /* Struct used to pass misc. parameters to read_die_and_children, et
463 al. which are used for both .debug_info and .debug_types dies.
464 All parameters here are unchanging for the life of the call. This
465 struct exists to abstract away the constant parameters of die
468 struct die_reader_specs
470 /* The bfd of this objfile. */
473 /* The CU of the DIE we are parsing. */
474 struct dwarf2_cu
*cu
;
476 /* Pointer to start of section buffer.
477 This is either the start of .debug_info or .debug_types. */
478 const gdb_byte
*buffer
;
481 /* The line number information for a compilation unit (found in the
482 .debug_line section) begins with a "statement program header",
483 which contains the following information. */
486 unsigned int total_length
;
487 unsigned short version
;
488 unsigned int header_length
;
489 unsigned char minimum_instruction_length
;
490 unsigned char maximum_ops_per_instruction
;
491 unsigned char default_is_stmt
;
493 unsigned char line_range
;
494 unsigned char opcode_base
;
496 /* standard_opcode_lengths[i] is the number of operands for the
497 standard opcode whose value is i. This means that
498 standard_opcode_lengths[0] is unused, and the last meaningful
499 element is standard_opcode_lengths[opcode_base - 1]. */
500 unsigned char *standard_opcode_lengths
;
502 /* The include_directories table. NOTE! These strings are not
503 allocated with xmalloc; instead, they are pointers into
504 debug_line_buffer. If you try to free them, `free' will get
506 unsigned int num_include_dirs
, include_dirs_size
;
509 /* The file_names table. NOTE! These strings are not allocated
510 with xmalloc; instead, they are pointers into debug_line_buffer.
511 Don't try to free them directly. */
512 unsigned int num_file_names
, file_names_size
;
516 unsigned int dir_index
;
517 unsigned int mod_time
;
519 int included_p
; /* Non-zero if referenced by the Line Number Program. */
520 struct symtab
*symtab
; /* The associated symbol table, if any. */
523 /* The start and end of the statement program following this
524 header. These point into dwarf2_per_objfile->line_buffer. */
525 gdb_byte
*statement_program_start
, *statement_program_end
;
528 /* When we construct a partial symbol table entry we only
529 need this much information. */
530 struct partial_die_info
532 /* Offset of this DIE. */
535 /* DWARF-2 tag for this DIE. */
536 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
538 /* Assorted flags describing the data found in this DIE. */
539 unsigned int has_children
: 1;
540 unsigned int is_external
: 1;
541 unsigned int is_declaration
: 1;
542 unsigned int has_type
: 1;
543 unsigned int has_specification
: 1;
544 unsigned int has_pc_info
: 1;
546 /* Flag set if the SCOPE field of this structure has been
548 unsigned int scope_set
: 1;
550 /* Flag set if the DIE has a byte_size attribute. */
551 unsigned int has_byte_size
: 1;
553 /* Flag set if any of the DIE's children are template arguments. */
554 unsigned int has_template_arguments
: 1;
556 /* Flag set if fixup_partial_die has been called on this die. */
557 unsigned int fixup_called
: 1;
559 /* The name of this DIE. Normally the value of DW_AT_name, but
560 sometimes a default name for unnamed DIEs. */
563 /* The linkage name, if present. */
564 const char *linkage_name
;
566 /* The scope to prepend to our children. This is generally
567 allocated on the comp_unit_obstack, so will disappear
568 when this compilation unit leaves the cache. */
571 /* The location description associated with this DIE, if any. */
572 struct dwarf_block
*locdesc
;
574 /* If HAS_PC_INFO, the PC range associated with this DIE. */
578 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
579 DW_AT_sibling, if any. */
580 /* NOTE: This member isn't strictly necessary, read_partial_die could
581 return DW_AT_sibling values to its caller load_partial_dies. */
584 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
585 DW_AT_specification (or DW_AT_abstract_origin or
587 unsigned int spec_offset
;
589 /* Pointers to this DIE's parent, first child, and next sibling,
591 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
594 /* This data structure holds the information of an abbrev. */
597 unsigned int number
; /* number identifying abbrev */
598 enum dwarf_tag tag
; /* dwarf tag */
599 unsigned short has_children
; /* boolean */
600 unsigned short num_attrs
; /* number of attributes */
601 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
602 struct abbrev_info
*next
; /* next in chain */
607 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
608 ENUM_BITFIELD(dwarf_form
) form
: 16;
611 /* Attributes have a name and a value. */
614 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
615 ENUM_BITFIELD(dwarf_form
) form
: 15;
617 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
618 field should be in u.str (existing only for DW_STRING) but it is kept
619 here for better struct attribute alignment. */
620 unsigned int string_is_canonical
: 1;
625 struct dwarf_block
*blk
;
629 struct signatured_type
*signatured_type
;
634 /* This data structure holds a complete die structure. */
637 /* DWARF-2 tag for this DIE. */
638 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
640 /* Number of attributes */
641 unsigned char num_attrs
;
643 /* True if we're presently building the full type name for the
644 type derived from this DIE. */
645 unsigned char building_fullname
: 1;
650 /* Offset in .debug_info or .debug_types section. */
653 /* The dies in a compilation unit form an n-ary tree. PARENT
654 points to this die's parent; CHILD points to the first child of
655 this node; and all the children of a given node are chained
656 together via their SIBLING fields. */
657 struct die_info
*child
; /* Its first child, if any. */
658 struct die_info
*sibling
; /* Its next sibling, if any. */
659 struct die_info
*parent
; /* Its parent, if any. */
661 /* An array of attributes, with NUM_ATTRS elements. There may be
662 zero, but it's not common and zero-sized arrays are not
663 sufficiently portable C. */
664 struct attribute attrs
[1];
667 /* Get at parts of an attribute structure. */
669 #define DW_STRING(attr) ((attr)->u.str)
670 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
671 #define DW_UNSND(attr) ((attr)->u.unsnd)
672 #define DW_BLOCK(attr) ((attr)->u.blk)
673 #define DW_SND(attr) ((attr)->u.snd)
674 #define DW_ADDR(attr) ((attr)->u.addr)
675 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
677 /* Blocks are a bunch of untyped bytes. */
682 /* Valid only if SIZE is not zero. */
686 #ifndef ATTR_ALLOC_CHUNK
687 #define ATTR_ALLOC_CHUNK 4
690 /* Allocate fields for structs, unions and enums in this size. */
691 #ifndef DW_FIELD_ALLOC_CHUNK
692 #define DW_FIELD_ALLOC_CHUNK 4
695 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
696 but this would require a corresponding change in unpack_field_as_long
698 static int bits_per_byte
= 8;
700 /* The routines that read and process dies for a C struct or C++ class
701 pass lists of data member fields and lists of member function fields
702 in an instance of a field_info structure, as defined below. */
705 /* List of data member and baseclasses fields. */
708 struct nextfield
*next
;
713 *fields
, *baseclasses
;
715 /* Number of fields (including baseclasses). */
718 /* Number of baseclasses. */
721 /* Set if the accesibility of one of the fields is not public. */
722 int non_public_fields
;
724 /* Member function fields array, entries are allocated in the order they
725 are encountered in the object file. */
728 struct nextfnfield
*next
;
729 struct fn_field fnfield
;
733 /* Member function fieldlist array, contains name of possibly overloaded
734 member function, number of overloaded member functions and a pointer
735 to the head of the member function field chain. */
740 struct nextfnfield
*head
;
744 /* Number of entries in the fnfieldlists array. */
747 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
748 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
749 struct typedef_field_list
751 struct typedef_field field
;
752 struct typedef_field_list
*next
;
755 unsigned typedef_field_list_count
;
758 /* One item on the queue of compilation units to read in full symbols
760 struct dwarf2_queue_item
762 struct dwarf2_per_cu_data
*per_cu
;
763 struct dwarf2_queue_item
*next
;
766 /* The current queue. */
767 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
769 /* Loaded secondary compilation units are kept in memory until they
770 have not been referenced for the processing of this many
771 compilation units. Set this to zero to disable caching. Cache
772 sizes of up to at least twenty will improve startup time for
773 typical inter-CU-reference binaries, at an obvious memory cost. */
774 static int dwarf2_max_cache_age
= 5;
776 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
777 struct cmd_list_element
*c
, const char *value
)
779 fprintf_filtered (file
, _("The upper bound on the age of cached "
780 "dwarf2 compilation units is %s.\n"),
785 /* Various complaints about symbol reading that don't abort the process. */
788 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
790 complaint (&symfile_complaints
,
791 _("statement list doesn't fit in .debug_line section"));
795 dwarf2_debug_line_missing_file_complaint (void)
797 complaint (&symfile_complaints
,
798 _(".debug_line section has line data without a file"));
802 dwarf2_debug_line_missing_end_sequence_complaint (void)
804 complaint (&symfile_complaints
,
805 _(".debug_line section has line "
806 "program sequence without an end"));
810 dwarf2_complex_location_expr_complaint (void)
812 complaint (&symfile_complaints
, _("location expression too complex"));
816 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
819 complaint (&symfile_complaints
,
820 _("const value length mismatch for '%s', got %d, expected %d"),
825 dwarf2_macros_too_long_complaint (struct dwarf2_section_info
*section
)
827 complaint (&symfile_complaints
,
828 _("macro info runs off end of `%s' section"),
829 section
->asection
->name
);
833 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
835 complaint (&symfile_complaints
,
836 _("macro debug info contains a "
837 "malformed macro definition:\n`%s'"),
842 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
844 complaint (&symfile_complaints
,
845 _("invalid attribute class or form for '%s' in '%s'"),
849 /* local function prototypes */
851 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
853 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
856 static void dwarf2_find_base_address (struct die_info
*die
,
857 struct dwarf2_cu
*cu
);
859 static void dwarf2_build_psymtabs_hard (struct objfile
*);
861 static void scan_partial_symbols (struct partial_die_info
*,
862 CORE_ADDR
*, CORE_ADDR
*,
863 int, struct dwarf2_cu
*);
865 static void add_partial_symbol (struct partial_die_info
*,
868 static void add_partial_namespace (struct partial_die_info
*pdi
,
869 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
870 int need_pc
, struct dwarf2_cu
*cu
);
872 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
873 CORE_ADDR
*highpc
, int need_pc
,
874 struct dwarf2_cu
*cu
);
876 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
877 struct dwarf2_cu
*cu
);
879 static void add_partial_subprogram (struct partial_die_info
*pdi
,
880 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
881 int need_pc
, struct dwarf2_cu
*cu
);
883 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
884 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
885 bfd
*abfd
, struct dwarf2_cu
*cu
);
887 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
889 static void psymtab_to_symtab_1 (struct partial_symtab
*);
891 static void dwarf2_read_abbrevs (struct dwarf2_cu
*cu
);
893 static void dwarf2_free_abbrev_table (void *);
895 static unsigned int peek_abbrev_code (bfd
*, gdb_byte
*);
897 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
900 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
903 static struct partial_die_info
*load_partial_dies (bfd
*,
904 gdb_byte
*, gdb_byte
*,
905 int, struct dwarf2_cu
*);
907 static gdb_byte
*read_partial_die (struct partial_die_info
*,
908 struct abbrev_info
*abbrev
,
910 gdb_byte
*, gdb_byte
*,
913 static struct partial_die_info
*find_partial_die (unsigned int,
916 static void fixup_partial_die (struct partial_die_info
*,
919 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
920 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
922 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
923 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
925 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
927 static int read_1_signed_byte (bfd
*, gdb_byte
*);
929 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
931 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
933 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
935 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
938 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
940 static LONGEST read_checked_initial_length_and_offset
941 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
942 unsigned int *, unsigned int *);
944 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
947 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
949 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
951 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
953 static char *read_indirect_string (bfd
*, gdb_byte
*,
954 const struct comp_unit_head
*,
957 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
959 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
961 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
963 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
965 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
968 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
972 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
973 struct dwarf2_cu
*cu
);
975 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
977 static struct die_info
*die_specification (struct die_info
*die
,
978 struct dwarf2_cu
**);
980 static void free_line_header (struct line_header
*lh
);
982 static void add_file_name (struct line_header
*, char *, unsigned int,
983 unsigned int, unsigned int);
985 static struct line_header
*(dwarf_decode_line_header
986 (unsigned int offset
,
987 bfd
*abfd
, struct dwarf2_cu
*cu
));
989 static void dwarf_decode_lines (struct line_header
*, const char *,
990 struct dwarf2_cu
*, struct partial_symtab
*,
993 static void dwarf2_start_subfile (char *, const char *, const char *);
995 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
998 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
999 struct dwarf2_cu
*, struct symbol
*);
1001 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1002 struct dwarf2_cu
*);
1004 static void dwarf2_const_value_attr (struct attribute
*attr
,
1007 struct obstack
*obstack
,
1008 struct dwarf2_cu
*cu
, long *value
,
1010 struct dwarf2_locexpr_baton
**baton
);
1012 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1014 static int need_gnat_info (struct dwarf2_cu
*);
1016 static struct type
*die_descriptive_type (struct die_info
*,
1017 struct dwarf2_cu
*);
1019 static void set_descriptive_type (struct type
*, struct die_info
*,
1020 struct dwarf2_cu
*);
1022 static struct type
*die_containing_type (struct die_info
*,
1023 struct dwarf2_cu
*);
1025 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1026 struct dwarf2_cu
*);
1028 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1030 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1032 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1034 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1035 const char *suffix
, int physname
,
1036 struct dwarf2_cu
*cu
);
1038 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1040 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1042 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1044 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1046 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1048 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1049 struct dwarf2_cu
*, struct partial_symtab
*);
1051 static int dwarf2_get_pc_bounds (struct die_info
*,
1052 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1053 struct partial_symtab
*);
1055 static void get_scope_pc_bounds (struct die_info
*,
1056 CORE_ADDR
*, CORE_ADDR
*,
1057 struct dwarf2_cu
*);
1059 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1060 CORE_ADDR
, struct dwarf2_cu
*);
1062 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1063 struct dwarf2_cu
*);
1065 static void dwarf2_attach_fields_to_type (struct field_info
*,
1066 struct type
*, struct dwarf2_cu
*);
1068 static void dwarf2_add_member_fn (struct field_info
*,
1069 struct die_info
*, struct type
*,
1070 struct dwarf2_cu
*);
1072 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1074 struct dwarf2_cu
*);
1076 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1078 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1080 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1082 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1084 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1086 static struct type
*read_module_type (struct die_info
*die
,
1087 struct dwarf2_cu
*cu
);
1089 static const char *namespace_name (struct die_info
*die
,
1090 int *is_anonymous
, struct dwarf2_cu
*);
1092 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1094 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1096 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1097 struct dwarf2_cu
*);
1099 static struct die_info
*read_comp_unit (gdb_byte
*, struct dwarf2_cu
*);
1101 static struct die_info
*read_die_and_children_1 (const struct die_reader_specs
*reader
,
1103 gdb_byte
**new_info_ptr
,
1104 struct die_info
*parent
);
1106 static struct die_info
*read_die_and_children (const struct die_reader_specs
*reader
,
1108 gdb_byte
**new_info_ptr
,
1109 struct die_info
*parent
);
1111 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*reader
,
1113 gdb_byte
**new_info_ptr
,
1114 struct die_info
*parent
);
1116 static gdb_byte
*read_full_die (const struct die_reader_specs
*reader
,
1117 struct die_info
**, gdb_byte
*,
1120 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1122 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1125 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1127 static const char *dwarf2_full_name (char *name
,
1128 struct die_info
*die
,
1129 struct dwarf2_cu
*cu
);
1131 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1132 struct dwarf2_cu
**);
1134 static char *dwarf_tag_name (unsigned int);
1136 static char *dwarf_attr_name (unsigned int);
1138 static char *dwarf_form_name (unsigned int);
1140 static char *dwarf_bool_name (unsigned int);
1142 static char *dwarf_type_encoding_name (unsigned int);
1145 static char *dwarf_cfi_name (unsigned int);
1148 static struct die_info
*sibling_die (struct die_info
*);
1150 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1152 static void dump_die_for_error (struct die_info
*);
1154 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1157 /*static*/ void dump_die (struct die_info
*, int max_level
);
1159 static void store_in_ref_table (struct die_info
*,
1160 struct dwarf2_cu
*);
1162 static int is_ref_attr (struct attribute
*);
1164 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1166 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1168 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1170 struct dwarf2_cu
**);
1172 static struct die_info
*follow_die_ref (struct die_info
*,
1174 struct dwarf2_cu
**);
1176 static struct die_info
*follow_die_sig (struct die_info
*,
1178 struct dwarf2_cu
**);
1180 static struct signatured_type
*lookup_signatured_type_at_offset
1181 (struct objfile
*objfile
,
1182 struct dwarf2_section_info
*section
,
1183 unsigned int offset
);
1185 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1187 static void read_signatured_type (struct signatured_type
*type_sig
);
1189 /* memory allocation interface */
1191 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1193 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1195 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1197 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1198 char *, bfd
*, struct dwarf2_cu
*,
1199 struct dwarf2_section_info
*,
1202 static int attr_form_is_block (struct attribute
*);
1204 static int attr_form_is_section_offset (struct attribute
*);
1206 static int attr_form_is_constant (struct attribute
*);
1208 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1209 struct dwarf2_loclist_baton
*baton
,
1210 struct attribute
*attr
);
1212 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1214 struct dwarf2_cu
*cu
);
1216 static gdb_byte
*skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1217 struct abbrev_info
*abbrev
,
1218 struct dwarf2_cu
*cu
);
1220 static void free_stack_comp_unit (void *);
1222 static hashval_t
partial_die_hash (const void *item
);
1224 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1226 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1227 (unsigned int offset
, struct objfile
*objfile
);
1229 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1230 struct dwarf2_per_cu_data
*per_cu
);
1232 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1233 struct die_info
*comp_unit_die
);
1235 static void free_heap_comp_unit (void *);
1237 static void free_cached_comp_units (void *);
1239 static void age_cached_comp_units (void);
1241 static void free_one_cached_comp_unit (void *);
1243 static struct type
*set_die_type (struct die_info
*, struct type
*,
1244 struct dwarf2_cu
*);
1246 static void create_all_comp_units (struct objfile
*);
1248 static int create_debug_types_hash_table (struct objfile
*objfile
);
1250 static void load_full_comp_unit (struct dwarf2_per_cu_data
*);
1252 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1254 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1255 struct dwarf2_per_cu_data
*);
1257 static void dwarf2_mark (struct dwarf2_cu
*);
1259 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1261 static struct type
*get_die_type_at_offset (unsigned int,
1262 struct dwarf2_per_cu_data
*per_cu
);
1264 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1266 static void dwarf2_release_queue (void *dummy
);
1268 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
);
1270 static void process_queue (void);
1272 static void find_file_and_directory (struct die_info
*die
,
1273 struct dwarf2_cu
*cu
,
1274 char **name
, char **comp_dir
);
1276 static char *file_full_name (int file
, struct line_header
*lh
,
1277 const char *comp_dir
);
1279 static gdb_byte
*read_and_check_comp_unit_head
1280 (struct comp_unit_head
*header
,
1281 struct dwarf2_section_info
*section
, gdb_byte
*info_ptr
,
1282 int is_debug_types_section
);
1284 static void init_cu_die_reader (struct die_reader_specs
*reader
,
1285 struct dwarf2_cu
*cu
);
1287 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1291 /* Convert VALUE between big- and little-endian. */
1293 byte_swap (offset_type value
)
1297 result
= (value
& 0xff) << 24;
1298 result
|= (value
& 0xff00) << 8;
1299 result
|= (value
& 0xff0000) >> 8;
1300 result
|= (value
& 0xff000000) >> 24;
1304 #define MAYBE_SWAP(V) byte_swap (V)
1307 #define MAYBE_SWAP(V) (V)
1308 #endif /* WORDS_BIGENDIAN */
1310 /* The suffix for an index file. */
1311 #define INDEX_SUFFIX ".gdb-index"
1313 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1314 struct dwarf2_cu
*cu
);
1316 /* Try to locate the sections we need for DWARF 2 debugging
1317 information and return true if we have enough to do something.
1318 NAMES points to the dwarf2 section names, or is NULL if the standard
1319 ELF names are used. */
1322 dwarf2_has_info (struct objfile
*objfile
,
1323 const struct dwarf2_debug_sections
*names
)
1325 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1326 if (!dwarf2_per_objfile
)
1328 /* Initialize per-objfile state. */
1329 struct dwarf2_per_objfile
*data
1330 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1332 memset (data
, 0, sizeof (*data
));
1333 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1334 dwarf2_per_objfile
= data
;
1336 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1338 dwarf2_per_objfile
->objfile
= objfile
;
1340 return (dwarf2_per_objfile
->info
.asection
!= NULL
1341 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1344 /* When loading sections, we look either for uncompressed section or for
1345 compressed section names. */
1348 section_is_p (const char *section_name
,
1349 const struct dwarf2_section_names
*names
)
1351 if (names
->normal
!= NULL
1352 && strcmp (section_name
, names
->normal
) == 0)
1354 if (names
->compressed
!= NULL
1355 && strcmp (section_name
, names
->compressed
) == 0)
1360 /* This function is mapped across the sections and remembers the
1361 offset and size of each of the debugging sections we are interested
1365 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1367 const struct dwarf2_debug_sections
*names
;
1370 names
= &dwarf2_elf_names
;
1372 names
= (const struct dwarf2_debug_sections
*) vnames
;
1374 if (section_is_p (sectp
->name
, &names
->info
))
1376 dwarf2_per_objfile
->info
.asection
= sectp
;
1377 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1379 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1381 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1382 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1384 else if (section_is_p (sectp
->name
, &names
->line
))
1386 dwarf2_per_objfile
->line
.asection
= sectp
;
1387 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1389 else if (section_is_p (sectp
->name
, &names
->loc
))
1391 dwarf2_per_objfile
->loc
.asection
= sectp
;
1392 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1394 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1396 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1397 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1399 else if (section_is_p (sectp
->name
, &names
->macro
))
1401 dwarf2_per_objfile
->macro
.asection
= sectp
;
1402 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
1404 else if (section_is_p (sectp
->name
, &names
->str
))
1406 dwarf2_per_objfile
->str
.asection
= sectp
;
1407 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1409 else if (section_is_p (sectp
->name
, &names
->frame
))
1411 dwarf2_per_objfile
->frame
.asection
= sectp
;
1412 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1414 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1416 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1418 if (aflag
& SEC_HAS_CONTENTS
)
1420 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1421 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1424 else if (section_is_p (sectp
->name
, &names
->ranges
))
1426 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1427 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1429 else if (section_is_p (sectp
->name
, &names
->types
))
1431 struct dwarf2_section_info type_section
;
1433 memset (&type_section
, 0, sizeof (type_section
));
1434 type_section
.asection
= sectp
;
1435 type_section
.size
= bfd_get_section_size (sectp
);
1437 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
1440 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1442 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1443 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1446 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1447 && bfd_section_vma (abfd
, sectp
) == 0)
1448 dwarf2_per_objfile
->has_section_at_zero
= 1;
1451 /* Decompress a section that was compressed using zlib. Store the
1452 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1455 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1456 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1458 bfd
*abfd
= objfile
->obfd
;
1460 error (_("Support for zlib-compressed DWARF data (from '%s') "
1461 "is disabled in this copy of GDB"),
1462 bfd_get_filename (abfd
));
1464 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1465 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1466 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1467 bfd_size_type uncompressed_size
;
1468 gdb_byte
*uncompressed_buffer
;
1471 int header_size
= 12;
1473 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1474 || bfd_bread (compressed_buffer
,
1475 compressed_size
, abfd
) != compressed_size
)
1476 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1477 bfd_get_filename (abfd
));
1479 /* Read the zlib header. In this case, it should be "ZLIB" followed
1480 by the uncompressed section size, 8 bytes in big-endian order. */
1481 if (compressed_size
< header_size
1482 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1483 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1484 bfd_get_filename (abfd
));
1485 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1486 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1487 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1488 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1489 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1490 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1491 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1492 uncompressed_size
+= compressed_buffer
[11];
1494 /* It is possible the section consists of several compressed
1495 buffers concatenated together, so we uncompress in a loop. */
1499 strm
.avail_in
= compressed_size
- header_size
;
1500 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1501 strm
.avail_out
= uncompressed_size
;
1502 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1504 rc
= inflateInit (&strm
);
1505 while (strm
.avail_in
> 0)
1508 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1509 bfd_get_filename (abfd
), rc
);
1510 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1511 + (uncompressed_size
- strm
.avail_out
));
1512 rc
= inflate (&strm
, Z_FINISH
);
1513 if (rc
!= Z_STREAM_END
)
1514 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1515 bfd_get_filename (abfd
), rc
);
1516 rc
= inflateReset (&strm
);
1518 rc
= inflateEnd (&strm
);
1520 || strm
.avail_out
!= 0)
1521 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1522 bfd_get_filename (abfd
), rc
);
1524 do_cleanups (cleanup
);
1525 *outbuf
= uncompressed_buffer
;
1526 *outsize
= uncompressed_size
;
1530 /* A helper function that decides whether a section is empty. */
1533 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1535 return info
->asection
== NULL
|| info
->size
== 0;
1538 /* Read the contents of the section INFO from object file specified by
1539 OBJFILE, store info about the section into INFO.
1540 If the section is compressed, uncompress it before returning. */
1543 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1545 bfd
*abfd
= objfile
->obfd
;
1546 asection
*sectp
= info
->asection
;
1547 gdb_byte
*buf
, *retbuf
;
1548 unsigned char header
[4];
1552 info
->buffer
= NULL
;
1553 info
->map_addr
= NULL
;
1556 if (dwarf2_section_empty_p (info
))
1559 /* Check if the file has a 4-byte header indicating compression. */
1560 if (info
->size
> sizeof (header
)
1561 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1562 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1564 /* Upon decompression, update the buffer and its size. */
1565 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1567 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1575 pagesize
= getpagesize ();
1577 /* Only try to mmap sections which are large enough: we don't want to
1578 waste space due to fragmentation. Also, only try mmap for sections
1579 without relocations. */
1581 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1583 info
->buffer
= bfd_mmap (abfd
, 0, info
->size
, PROT_READ
,
1584 MAP_PRIVATE
, sectp
->filepos
,
1585 &info
->map_addr
, &info
->map_len
);
1587 if ((caddr_t
)info
->buffer
!= MAP_FAILED
)
1589 #if HAVE_POSIX_MADVISE
1590 posix_madvise (info
->map_addr
, info
->map_len
, POSIX_MADV_WILLNEED
);
1597 /* If we get here, we are a normal, not-compressed section. */
1599 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1601 /* When debugging .o files, we may need to apply relocations; see
1602 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1603 We never compress sections in .o files, so we only need to
1604 try this when the section is not compressed. */
1605 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1608 info
->buffer
= retbuf
;
1612 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1613 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1614 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1615 bfd_get_filename (abfd
));
1618 /* A helper function that returns the size of a section in a safe way.
1619 If you are positive that the section has been read before using the
1620 size, then it is safe to refer to the dwarf2_section_info object's
1621 "size" field directly. In other cases, you must call this
1622 function, because for compressed sections the size field is not set
1623 correctly until the section has been read. */
1625 static bfd_size_type
1626 dwarf2_section_size (struct objfile
*objfile
,
1627 struct dwarf2_section_info
*info
)
1630 dwarf2_read_section (objfile
, info
);
1634 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1638 dwarf2_get_section_info (struct objfile
*objfile
,
1639 enum dwarf2_section_enum sect
,
1640 asection
**sectp
, gdb_byte
**bufp
,
1641 bfd_size_type
*sizep
)
1643 struct dwarf2_per_objfile
*data
1644 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1645 struct dwarf2_section_info
*info
;
1647 /* We may see an objfile without any DWARF, in which case we just
1658 case DWARF2_DEBUG_FRAME
:
1659 info
= &data
->frame
;
1661 case DWARF2_EH_FRAME
:
1662 info
= &data
->eh_frame
;
1665 gdb_assert_not_reached ("unexpected section");
1668 dwarf2_read_section (objfile
, info
);
1670 *sectp
= info
->asection
;
1671 *bufp
= info
->buffer
;
1672 *sizep
= info
->size
;
1676 /* DWARF quick_symbols_functions support. */
1678 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1679 unique line tables, so we maintain a separate table of all .debug_line
1680 derived entries to support the sharing.
1681 All the quick functions need is the list of file names. We discard the
1682 line_header when we're done and don't need to record it here. */
1683 struct quick_file_names
1685 /* The offset in .debug_line of the line table. We hash on this. */
1686 unsigned int offset
;
1688 /* The number of entries in file_names, real_names. */
1689 unsigned int num_file_names
;
1691 /* The file names from the line table, after being run through
1693 const char **file_names
;
1695 /* The file names from the line table after being run through
1696 gdb_realpath. These are computed lazily. */
1697 const char **real_names
;
1700 /* When using the index (and thus not using psymtabs), each CU has an
1701 object of this type. This is used to hold information needed by
1702 the various "quick" methods. */
1703 struct dwarf2_per_cu_quick_data
1705 /* The file table. This can be NULL if there was no file table
1706 or it's currently not read in.
1707 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1708 struct quick_file_names
*file_names
;
1710 /* The corresponding symbol table. This is NULL if symbols for this
1711 CU have not yet been read. */
1712 struct symtab
*symtab
;
1714 /* A temporary mark bit used when iterating over all CUs in
1715 expand_symtabs_matching. */
1716 unsigned int mark
: 1;
1718 /* True if we've tried to read the file table and found there isn't one.
1719 There will be no point in trying to read it again next time. */
1720 unsigned int no_file_data
: 1;
1723 /* Hash function for a quick_file_names. */
1726 hash_file_name_entry (const void *e
)
1728 const struct quick_file_names
*file_data
= e
;
1730 return file_data
->offset
;
1733 /* Equality function for a quick_file_names. */
1736 eq_file_name_entry (const void *a
, const void *b
)
1738 const struct quick_file_names
*ea
= a
;
1739 const struct quick_file_names
*eb
= b
;
1741 return ea
->offset
== eb
->offset
;
1744 /* Delete function for a quick_file_names. */
1747 delete_file_name_entry (void *e
)
1749 struct quick_file_names
*file_data
= e
;
1752 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
1754 xfree ((void*) file_data
->file_names
[i
]);
1755 if (file_data
->real_names
)
1756 xfree ((void*) file_data
->real_names
[i
]);
1759 /* The space for the struct itself lives on objfile_obstack,
1760 so we don't free it here. */
1763 /* Create a quick_file_names hash table. */
1766 create_quick_file_names_table (unsigned int nr_initial_entries
)
1768 return htab_create_alloc (nr_initial_entries
,
1769 hash_file_name_entry
, eq_file_name_entry
,
1770 delete_file_name_entry
, xcalloc
, xfree
);
1773 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
1774 have to be created afterwards. You should call age_cached_comp_units after
1775 processing PER_CU->CU. dw2_setup must have been already called. */
1778 load_cu (struct dwarf2_per_cu_data
*per_cu
)
1780 if (per_cu
->debug_types_section
)
1781 load_full_type_unit (per_cu
);
1783 load_full_comp_unit (per_cu
);
1785 gdb_assert (per_cu
->cu
!= NULL
);
1787 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
1790 /* Read in the symbols for PER_CU. */
1793 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
1795 struct cleanup
*back_to
;
1797 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
1799 queue_comp_unit (per_cu
);
1805 /* Age the cache, releasing compilation units that have not
1806 been used recently. */
1807 age_cached_comp_units ();
1809 do_cleanups (back_to
);
1812 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1813 the objfile from which this CU came. Returns the resulting symbol
1816 static struct symtab
*
1817 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
1819 if (!per_cu
->v
.quick
->symtab
)
1821 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1822 increment_reading_symtab ();
1823 dw2_do_instantiate_symtab (per_cu
);
1824 do_cleanups (back_to
);
1826 return per_cu
->v
.quick
->symtab
;
1829 /* Return the CU given its index. */
1831 static struct dwarf2_per_cu_data
*
1832 dw2_get_cu (int index
)
1834 if (index
>= dwarf2_per_objfile
->n_comp_units
)
1836 index
-= dwarf2_per_objfile
->n_comp_units
;
1837 return dwarf2_per_objfile
->all_type_units
[index
];
1839 return dwarf2_per_objfile
->all_comp_units
[index
];
1842 /* A helper function that knows how to read a 64-bit value in a way
1843 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1847 extract_cu_value (const char *bytes
, ULONGEST
*result
)
1849 if (sizeof (ULONGEST
) < 8)
1853 /* Ignore the upper 4 bytes if they are all zero. */
1854 for (i
= 0; i
< 4; ++i
)
1855 if (bytes
[i
+ 4] != 0)
1858 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
1861 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
1865 /* Read the CU list from the mapped index, and use it to create all
1866 the CU objects for this objfile. Return 0 if something went wrong,
1867 1 if everything went ok. */
1870 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
1871 offset_type cu_list_elements
)
1875 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
1876 dwarf2_per_objfile
->all_comp_units
1877 = obstack_alloc (&objfile
->objfile_obstack
,
1878 dwarf2_per_objfile
->n_comp_units
1879 * sizeof (struct dwarf2_per_cu_data
*));
1881 for (i
= 0; i
< cu_list_elements
; i
+= 2)
1883 struct dwarf2_per_cu_data
*the_cu
;
1884 ULONGEST offset
, length
;
1886 if (!extract_cu_value (cu_list
, &offset
)
1887 || !extract_cu_value (cu_list
+ 8, &length
))
1891 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1892 struct dwarf2_per_cu_data
);
1893 the_cu
->offset
= offset
;
1894 the_cu
->length
= length
;
1895 the_cu
->objfile
= objfile
;
1896 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1897 struct dwarf2_per_cu_quick_data
);
1898 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
1904 /* Create the signatured type hash table from the index. */
1907 create_signatured_type_table_from_index (struct objfile
*objfile
,
1908 struct dwarf2_section_info
*section
,
1909 const gdb_byte
*bytes
,
1910 offset_type elements
)
1913 htab_t sig_types_hash
;
1915 dwarf2_per_objfile
->n_type_units
= elements
/ 3;
1916 dwarf2_per_objfile
->all_type_units
1917 = obstack_alloc (&objfile
->objfile_obstack
,
1918 dwarf2_per_objfile
->n_type_units
1919 * sizeof (struct dwarf2_per_cu_data
*));
1921 sig_types_hash
= allocate_signatured_type_table (objfile
);
1923 for (i
= 0; i
< elements
; i
+= 3)
1925 struct signatured_type
*type_sig
;
1926 ULONGEST offset
, type_offset
, signature
;
1929 if (!extract_cu_value (bytes
, &offset
)
1930 || !extract_cu_value (bytes
+ 8, &type_offset
))
1932 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
1935 type_sig
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1936 struct signatured_type
);
1937 type_sig
->signature
= signature
;
1938 type_sig
->type_offset
= type_offset
;
1939 type_sig
->per_cu
.debug_types_section
= section
;
1940 type_sig
->per_cu
.offset
= offset
;
1941 type_sig
->per_cu
.objfile
= objfile
;
1942 type_sig
->per_cu
.v
.quick
1943 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1944 struct dwarf2_per_cu_quick_data
);
1946 slot
= htab_find_slot (sig_types_hash
, type_sig
, INSERT
);
1949 dwarf2_per_objfile
->all_type_units
[i
/ 3] = &type_sig
->per_cu
;
1952 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
1957 /* Read the address map data from the mapped index, and use it to
1958 populate the objfile's psymtabs_addrmap. */
1961 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
1963 const gdb_byte
*iter
, *end
;
1964 struct obstack temp_obstack
;
1965 struct addrmap
*mutable_map
;
1966 struct cleanup
*cleanup
;
1969 obstack_init (&temp_obstack
);
1970 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
1971 mutable_map
= addrmap_create_mutable (&temp_obstack
);
1973 iter
= index
->address_table
;
1974 end
= iter
+ index
->address_table_size
;
1976 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1980 ULONGEST hi
, lo
, cu_index
;
1981 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1983 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1985 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
1988 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
1989 dw2_get_cu (cu_index
));
1992 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
1993 &objfile
->objfile_obstack
);
1994 do_cleanups (cleanup
);
1997 /* The hash function for strings in the mapped index. This is the same as
1998 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
1999 implementation. This is necessary because the hash function is tied to the
2000 format of the mapped index file. The hash values do not have to match with
2003 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2006 mapped_index_string_hash (int index_version
, const void *p
)
2008 const unsigned char *str
= (const unsigned char *) p
;
2012 while ((c
= *str
++) != 0)
2014 if (index_version
>= 5)
2016 r
= r
* 67 + c
- 113;
2022 /* Find a slot in the mapped index INDEX for the object named NAME.
2023 If NAME is found, set *VEC_OUT to point to the CU vector in the
2024 constant pool and return 1. If NAME cannot be found, return 0. */
2027 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2028 offset_type
**vec_out
)
2030 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2032 offset_type slot
, step
;
2033 int (*cmp
) (const char *, const char *);
2035 if (current_language
->la_language
== language_cplus
2036 || current_language
->la_language
== language_java
2037 || current_language
->la_language
== language_fortran
)
2039 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2041 const char *paren
= strchr (name
, '(');
2047 dup
= xmalloc (paren
- name
+ 1);
2048 memcpy (dup
, name
, paren
- name
);
2049 dup
[paren
- name
] = 0;
2051 make_cleanup (xfree
, dup
);
2056 /* Index version 4 did not support case insensitive searches. But the
2057 indices for case insensitive languages are built in lowercase, therefore
2058 simulate our NAME being searched is also lowercased. */
2059 hash
= mapped_index_string_hash ((index
->version
== 4
2060 && case_sensitivity
== case_sensitive_off
2061 ? 5 : index
->version
),
2064 slot
= hash
& (index
->symbol_table_slots
- 1);
2065 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2066 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2070 /* Convert a slot number to an offset into the table. */
2071 offset_type i
= 2 * slot
;
2073 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2075 do_cleanups (back_to
);
2079 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2080 if (!cmp (name
, str
))
2082 *vec_out
= (offset_type
*) (index
->constant_pool
2083 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2084 do_cleanups (back_to
);
2088 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2092 /* Read the index file. If everything went ok, initialize the "quick"
2093 elements of all the CUs and return 1. Otherwise, return 0. */
2096 dwarf2_read_index (struct objfile
*objfile
)
2099 struct mapped_index
*map
;
2100 offset_type
*metadata
;
2101 const gdb_byte
*cu_list
;
2102 const gdb_byte
*types_list
= NULL
;
2103 offset_type version
, cu_list_elements
;
2104 offset_type types_list_elements
= 0;
2107 if (dwarf2_section_empty_p (&dwarf2_per_objfile
->gdb_index
))
2110 /* Older elfutils strip versions could keep the section in the main
2111 executable while splitting it for the separate debug info file. */
2112 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
2113 & SEC_HAS_CONTENTS
) == 0)
2116 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
2118 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
2119 /* Version check. */
2120 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2121 /* Versions earlier than 3 emitted every copy of a psymbol. This
2122 causes the index to behave very poorly for certain requests. Version 3
2123 contained incomplete addrmap. So, it seems better to just ignore such
2124 indices. Index version 4 uses a different hash function than index
2125 version 5 and later. */
2128 /* Indices with higher version than the one supported by GDB may be no
2129 longer backward compatible. */
2133 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
2134 map
->version
= version
;
2135 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
2137 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2140 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2141 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2145 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2146 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2147 - MAYBE_SWAP (metadata
[i
]))
2151 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2152 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2153 - MAYBE_SWAP (metadata
[i
]));
2156 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2157 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2158 - MAYBE_SWAP (metadata
[i
]))
2159 / (2 * sizeof (offset_type
)));
2162 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2164 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
2167 if (types_list_elements
)
2169 struct dwarf2_section_info
*section
;
2171 /* We can only handle a single .debug_types when we have an
2173 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2176 section
= VEC_index (dwarf2_section_info_def
,
2177 dwarf2_per_objfile
->types
, 0);
2179 if (!create_signatured_type_table_from_index (objfile
, section
,
2181 types_list_elements
))
2185 create_addrmap_from_index (objfile
, map
);
2187 dwarf2_per_objfile
->index_table
= map
;
2188 dwarf2_per_objfile
->using_index
= 1;
2189 dwarf2_per_objfile
->quick_file_names_table
=
2190 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2195 /* A helper for the "quick" functions which sets the global
2196 dwarf2_per_objfile according to OBJFILE. */
2199 dw2_setup (struct objfile
*objfile
)
2201 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2202 gdb_assert (dwarf2_per_objfile
);
2205 /* A helper for the "quick" functions which attempts to read the line
2206 table for THIS_CU. */
2208 static struct quick_file_names
*
2209 dw2_get_file_names (struct objfile
*objfile
,
2210 struct dwarf2_per_cu_data
*this_cu
)
2212 bfd
*abfd
= objfile
->obfd
;
2213 struct line_header
*lh
;
2214 struct attribute
*attr
;
2215 struct cleanup
*cleanups
;
2216 struct die_info
*comp_unit_die
;
2217 struct dwarf2_section_info
* sec
;
2219 int has_children
, i
;
2220 struct dwarf2_cu cu
;
2221 unsigned int bytes_read
;
2222 struct die_reader_specs reader_specs
;
2223 char *name
, *comp_dir
;
2225 struct quick_file_names
*qfn
;
2226 unsigned int line_offset
;
2228 if (this_cu
->v
.quick
->file_names
!= NULL
)
2229 return this_cu
->v
.quick
->file_names
;
2230 /* If we know there is no line data, no point in looking again. */
2231 if (this_cu
->v
.quick
->no_file_data
)
2234 init_one_comp_unit (&cu
, this_cu
);
2235 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
2237 if (this_cu
->debug_types_section
)
2238 sec
= this_cu
->debug_types_section
;
2240 sec
= &dwarf2_per_objfile
->info
;
2241 dwarf2_read_section (objfile
, sec
);
2242 info_ptr
= sec
->buffer
+ this_cu
->offset
;
2244 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, sec
, info_ptr
,
2245 this_cu
->debug_types_section
!= NULL
);
2247 /* Skip dummy compilation units. */
2248 if (info_ptr
>= (sec
->buffer
+ sec
->size
)
2249 || peek_abbrev_code (abfd
, info_ptr
) == 0)
2251 do_cleanups (cleanups
);
2255 dwarf2_read_abbrevs (&cu
);
2256 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2258 init_cu_die_reader (&reader_specs
, &cu
);
2259 read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2265 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, &cu
);
2268 struct quick_file_names find_entry
;
2270 line_offset
= DW_UNSND (attr
);
2272 /* We may have already read in this line header (TU line header sharing).
2273 If we have we're done. */
2274 find_entry
.offset
= line_offset
;
2275 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2276 &find_entry
, INSERT
);
2279 do_cleanups (cleanups
);
2280 this_cu
->v
.quick
->file_names
= *slot
;
2284 lh
= dwarf_decode_line_header (line_offset
, abfd
, &cu
);
2288 do_cleanups (cleanups
);
2289 this_cu
->v
.quick
->no_file_data
= 1;
2293 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2294 qfn
->offset
= line_offset
;
2295 gdb_assert (slot
!= NULL
);
2298 find_file_and_directory (comp_unit_die
, &cu
, &name
, &comp_dir
);
2300 qfn
->num_file_names
= lh
->num_file_names
;
2301 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2302 lh
->num_file_names
* sizeof (char *));
2303 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2304 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2305 qfn
->real_names
= NULL
;
2307 free_line_header (lh
);
2308 do_cleanups (cleanups
);
2310 this_cu
->v
.quick
->file_names
= qfn
;
2314 /* A helper for the "quick" functions which computes and caches the
2315 real path for a given file name from the line table. */
2318 dw2_get_real_path (struct objfile
*objfile
,
2319 struct quick_file_names
*qfn
, int index
)
2321 if (qfn
->real_names
== NULL
)
2322 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2323 qfn
->num_file_names
, sizeof (char *));
2325 if (qfn
->real_names
[index
] == NULL
)
2326 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2328 return qfn
->real_names
[index
];
2331 static struct symtab
*
2332 dw2_find_last_source_symtab (struct objfile
*objfile
)
2336 dw2_setup (objfile
);
2337 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2338 return dw2_instantiate_symtab (dw2_get_cu (index
));
2341 /* Traversal function for dw2_forget_cached_source_info. */
2344 dw2_free_cached_file_names (void **slot
, void *info
)
2346 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2348 if (file_data
->real_names
)
2352 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2354 xfree ((void*) file_data
->real_names
[i
]);
2355 file_data
->real_names
[i
] = NULL
;
2363 dw2_forget_cached_source_info (struct objfile
*objfile
)
2365 dw2_setup (objfile
);
2367 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2368 dw2_free_cached_file_names
, NULL
);
2371 /* Helper function for dw2_map_symtabs_matching_filename that expands
2372 the symtabs and calls the iterator. */
2375 dw2_map_expand_apply (struct objfile
*objfile
,
2376 struct dwarf2_per_cu_data
*per_cu
,
2378 const char *full_path
, const char *real_path
,
2379 int (*callback
) (struct symtab
*, void *),
2382 struct symtab
*last_made
= objfile
->symtabs
;
2384 /* Don't visit already-expanded CUs. */
2385 if (per_cu
->v
.quick
->symtab
)
2388 /* This may expand more than one symtab, and we want to iterate over
2390 dw2_instantiate_symtab (per_cu
);
2392 return iterate_over_some_symtabs (name
, full_path
, real_path
, callback
, data
,
2393 objfile
->symtabs
, last_made
);
2396 /* Implementation of the map_symtabs_matching_filename method. */
2399 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
2400 const char *full_path
, const char *real_path
,
2401 int (*callback
) (struct symtab
*, void *),
2405 const char *name_basename
= lbasename (name
);
2406 int name_len
= strlen (name
);
2407 int is_abs
= IS_ABSOLUTE_PATH (name
);
2409 dw2_setup (objfile
);
2411 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2412 + dwarf2_per_objfile
->n_type_units
); ++i
)
2415 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2416 struct quick_file_names
*file_data
;
2418 /* We only need to look at symtabs not already expanded. */
2419 if (per_cu
->v
.quick
->symtab
)
2422 file_data
= dw2_get_file_names (objfile
, per_cu
);
2423 if (file_data
== NULL
)
2426 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2428 const char *this_name
= file_data
->file_names
[j
];
2430 if (FILENAME_CMP (name
, this_name
) == 0
2431 || (!is_abs
&& compare_filenames_for_search (this_name
,
2434 if (dw2_map_expand_apply (objfile
, per_cu
,
2435 name
, full_path
, real_path
,
2440 /* Before we invoke realpath, which can get expensive when many
2441 files are involved, do a quick comparison of the basenames. */
2442 if (! basenames_may_differ
2443 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
2446 if (full_path
!= NULL
)
2448 const char *this_real_name
= dw2_get_real_path (objfile
,
2451 if (this_real_name
!= NULL
2452 && (FILENAME_CMP (full_path
, this_real_name
) == 0
2454 && compare_filenames_for_search (this_real_name
,
2457 if (dw2_map_expand_apply (objfile
, per_cu
,
2458 name
, full_path
, real_path
,
2464 if (real_path
!= NULL
)
2466 const char *this_real_name
= dw2_get_real_path (objfile
,
2469 if (this_real_name
!= NULL
2470 && (FILENAME_CMP (real_path
, this_real_name
) == 0
2472 && compare_filenames_for_search (this_real_name
,
2475 if (dw2_map_expand_apply (objfile
, per_cu
,
2476 name
, full_path
, real_path
,
2487 static struct symtab
*
2488 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2489 const char *name
, domain_enum domain
)
2491 /* We do all the work in the pre_expand_symtabs_matching hook
2496 /* A helper function that expands all symtabs that hold an object
2500 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2502 dw2_setup (objfile
);
2504 /* index_table is NULL if OBJF_READNOW. */
2505 if (dwarf2_per_objfile
->index_table
)
2509 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2512 offset_type i
, len
= MAYBE_SWAP (*vec
);
2513 for (i
= 0; i
< len
; ++i
)
2515 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2516 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2518 dw2_instantiate_symtab (per_cu
);
2525 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2526 enum block_enum block_kind
, const char *name
,
2529 dw2_do_expand_symtabs_matching (objfile
, name
);
2533 dw2_print_stats (struct objfile
*objfile
)
2537 dw2_setup (objfile
);
2539 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2540 + dwarf2_per_objfile
->n_type_units
); ++i
)
2542 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2544 if (!per_cu
->v
.quick
->symtab
)
2547 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2551 dw2_dump (struct objfile
*objfile
)
2553 /* Nothing worth printing. */
2557 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2558 struct section_offsets
*delta
)
2560 /* There's nothing to relocate here. */
2564 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2565 const char *func_name
)
2567 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2571 dw2_expand_all_symtabs (struct objfile
*objfile
)
2575 dw2_setup (objfile
);
2577 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2578 + dwarf2_per_objfile
->n_type_units
); ++i
)
2580 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2582 dw2_instantiate_symtab (per_cu
);
2587 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2588 const char *filename
)
2592 dw2_setup (objfile
);
2594 /* We don't need to consider type units here.
2595 This is only called for examining code, e.g. expand_line_sal.
2596 There can be an order of magnitude (or more) more type units
2597 than comp units, and we avoid them if we can. */
2599 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2602 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2603 struct quick_file_names
*file_data
;
2605 /* We only need to look at symtabs not already expanded. */
2606 if (per_cu
->v
.quick
->symtab
)
2609 file_data
= dw2_get_file_names (objfile
, per_cu
);
2610 if (file_data
== NULL
)
2613 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2615 const char *this_name
= file_data
->file_names
[j
];
2616 if (FILENAME_CMP (this_name
, filename
) == 0)
2618 dw2_instantiate_symtab (per_cu
);
2626 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2628 struct dwarf2_per_cu_data
*per_cu
;
2630 struct quick_file_names
*file_data
;
2632 dw2_setup (objfile
);
2634 /* index_table is NULL if OBJF_READNOW. */
2635 if (!dwarf2_per_objfile
->index_table
)
2639 ALL_OBJFILE_SYMTABS (objfile
, s
)
2642 struct blockvector
*bv
= BLOCKVECTOR (s
);
2643 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2644 struct symbol
*sym
= lookup_block_symbol (block
, name
, VAR_DOMAIN
);
2647 return sym
->symtab
->filename
;
2652 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2656 /* Note that this just looks at the very first one named NAME -- but
2657 actually we are looking for a function. find_main_filename
2658 should be rewritten so that it doesn't require a custom hook. It
2659 could just use the ordinary symbol tables. */
2660 /* vec[0] is the length, which must always be >0. */
2661 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[1]));
2663 file_data
= dw2_get_file_names (objfile
, per_cu
);
2664 if (file_data
== NULL
)
2667 return file_data
->file_names
[file_data
->num_file_names
- 1];
2671 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
2672 struct objfile
*objfile
, int global
,
2673 int (*callback
) (struct block
*,
2674 struct symbol
*, void *),
2675 void *data
, symbol_compare_ftype
*match
,
2676 symbol_compare_ftype
*ordered_compare
)
2678 /* Currently unimplemented; used for Ada. The function can be called if the
2679 current language is Ada for a non-Ada objfile using GNU index. As Ada
2680 does not look for non-Ada symbols this function should just return. */
2684 dw2_expand_symtabs_matching
2685 (struct objfile
*objfile
,
2686 int (*file_matcher
) (const char *, void *),
2687 int (*name_matcher
) (const char *, void *),
2688 enum search_domain kind
,
2693 struct mapped_index
*index
;
2695 dw2_setup (objfile
);
2697 /* index_table is NULL if OBJF_READNOW. */
2698 if (!dwarf2_per_objfile
->index_table
)
2700 index
= dwarf2_per_objfile
->index_table
;
2702 if (file_matcher
!= NULL
)
2704 struct cleanup
*cleanup
;
2705 htab_t visited_found
, visited_not_found
;
2707 visited_found
= htab_create_alloc (10,
2708 htab_hash_pointer
, htab_eq_pointer
,
2709 NULL
, xcalloc
, xfree
);
2710 cleanup
= make_cleanup_htab_delete (visited_found
);
2711 visited_not_found
= htab_create_alloc (10,
2712 htab_hash_pointer
, htab_eq_pointer
,
2713 NULL
, xcalloc
, xfree
);
2714 make_cleanup_htab_delete (visited_not_found
);
2716 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2717 + dwarf2_per_objfile
->n_type_units
); ++i
)
2720 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2721 struct quick_file_names
*file_data
;
2724 per_cu
->v
.quick
->mark
= 0;
2726 /* We only need to look at symtabs not already expanded. */
2727 if (per_cu
->v
.quick
->symtab
)
2730 file_data
= dw2_get_file_names (objfile
, per_cu
);
2731 if (file_data
== NULL
)
2734 if (htab_find (visited_not_found
, file_data
) != NULL
)
2736 else if (htab_find (visited_found
, file_data
) != NULL
)
2738 per_cu
->v
.quick
->mark
= 1;
2742 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2744 if (file_matcher (file_data
->file_names
[j
], data
))
2746 per_cu
->v
.quick
->mark
= 1;
2751 slot
= htab_find_slot (per_cu
->v
.quick
->mark
2753 : visited_not_found
,
2758 do_cleanups (cleanup
);
2761 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2763 offset_type idx
= 2 * iter
;
2765 offset_type
*vec
, vec_len
, vec_idx
;
2767 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2770 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
2772 if (! (*name_matcher
) (name
, data
))
2775 /* The name was matched, now expand corresponding CUs that were
2777 vec
= (offset_type
*) (index
->constant_pool
2778 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
2779 vec_len
= MAYBE_SWAP (vec
[0]);
2780 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2782 struct dwarf2_per_cu_data
*per_cu
;
2784 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[vec_idx
+ 1]));
2785 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
2786 dw2_instantiate_symtab (per_cu
);
2791 static struct symtab
*
2792 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
2793 struct minimal_symbol
*msymbol
,
2795 struct obj_section
*section
,
2798 struct dwarf2_per_cu_data
*data
;
2800 dw2_setup (objfile
);
2802 if (!objfile
->psymtabs_addrmap
)
2805 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
2809 if (warn_if_readin
&& data
->v
.quick
->symtab
)
2810 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2811 paddress (get_objfile_arch (objfile
), pc
));
2813 return dw2_instantiate_symtab (data
);
2817 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
2818 void *data
, int need_fullname
)
2821 struct cleanup
*cleanup
;
2822 htab_t visited
= htab_create_alloc (10, htab_hash_pointer
, htab_eq_pointer
,
2823 NULL
, xcalloc
, xfree
);
2825 cleanup
= make_cleanup_htab_delete (visited
);
2826 dw2_setup (objfile
);
2828 /* We can ignore file names coming from already-expanded CUs. */
2829 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2830 + dwarf2_per_objfile
->n_type_units
); ++i
)
2832 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2834 if (per_cu
->v
.quick
->symtab
)
2836 void **slot
= htab_find_slot (visited
, per_cu
->v
.quick
->file_names
,
2839 *slot
= per_cu
->v
.quick
->file_names
;
2843 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2844 + dwarf2_per_objfile
->n_type_units
); ++i
)
2847 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2848 struct quick_file_names
*file_data
;
2851 /* We only need to look at symtabs not already expanded. */
2852 if (per_cu
->v
.quick
->symtab
)
2855 file_data
= dw2_get_file_names (objfile
, per_cu
);
2856 if (file_data
== NULL
)
2859 slot
= htab_find_slot (visited
, file_data
, INSERT
);
2862 /* Already visited. */
2867 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2869 const char *this_real_name
;
2872 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
2874 this_real_name
= NULL
;
2875 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
2879 do_cleanups (cleanup
);
2883 dw2_has_symbols (struct objfile
*objfile
)
2888 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
2891 dw2_find_last_source_symtab
,
2892 dw2_forget_cached_source_info
,
2893 dw2_map_symtabs_matching_filename
,
2895 dw2_pre_expand_symtabs_matching
,
2899 dw2_expand_symtabs_for_function
,
2900 dw2_expand_all_symtabs
,
2901 dw2_expand_symtabs_with_filename
,
2902 dw2_find_symbol_file
,
2903 dw2_map_matching_symbols
,
2904 dw2_expand_symtabs_matching
,
2905 dw2_find_pc_sect_symtab
,
2906 dw2_map_symbol_filenames
2909 /* Initialize for reading DWARF for this objfile. Return 0 if this
2910 file will use psymtabs, or 1 if using the GNU index. */
2913 dwarf2_initialize_objfile (struct objfile
*objfile
)
2915 /* If we're about to read full symbols, don't bother with the
2916 indices. In this case we also don't care if some other debug
2917 format is making psymtabs, because they are all about to be
2919 if ((objfile
->flags
& OBJF_READNOW
))
2923 dwarf2_per_objfile
->using_index
= 1;
2924 create_all_comp_units (objfile
);
2925 create_debug_types_hash_table (objfile
);
2926 dwarf2_per_objfile
->quick_file_names_table
=
2927 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2929 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2930 + dwarf2_per_objfile
->n_type_units
); ++i
)
2932 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2934 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2935 struct dwarf2_per_cu_quick_data
);
2938 /* Return 1 so that gdb sees the "quick" functions. However,
2939 these functions will be no-ops because we will have expanded
2944 if (dwarf2_read_index (objfile
))
2952 /* Build a partial symbol table. */
2955 dwarf2_build_psymtabs (struct objfile
*objfile
)
2957 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2959 init_psymbol_list (objfile
, 1024);
2962 dwarf2_build_psymtabs_hard (objfile
);
2965 /* Return TRUE if OFFSET is within CU_HEADER. */
2968 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
2970 unsigned int bottom
= cu_header
->offset
;
2971 unsigned int top
= (cu_header
->offset
2973 + cu_header
->initial_length_size
);
2975 return (offset
>= bottom
&& offset
< top
);
2978 /* Read in the comp unit header information from the debug_info at info_ptr.
2979 NOTE: This leaves members offset, first_die_offset to be filled in
2983 read_comp_unit_head (struct comp_unit_head
*cu_header
,
2984 gdb_byte
*info_ptr
, bfd
*abfd
)
2987 unsigned int bytes_read
;
2989 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
2990 cu_header
->initial_length_size
= bytes_read
;
2991 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
2992 info_ptr
+= bytes_read
;
2993 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
2995 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
2997 info_ptr
+= bytes_read
;
2998 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
3000 signed_addr
= bfd_get_sign_extend_vma (abfd
);
3001 if (signed_addr
< 0)
3002 internal_error (__FILE__
, __LINE__
,
3003 _("read_comp_unit_head: dwarf from non elf file"));
3004 cu_header
->signed_addr_p
= signed_addr
;
3009 /* Subroutine of read_and_check_comp_unit_head and
3010 read_and_check_type_unit_head to simplify them.
3011 Perform various error checking on the header. */
3014 error_check_comp_unit_head (struct comp_unit_head
*header
,
3015 struct dwarf2_section_info
*section
)
3017 bfd
*abfd
= section
->asection
->owner
;
3018 const char *filename
= bfd_get_filename (abfd
);
3020 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
3021 error (_("Dwarf Error: wrong version in compilation unit header "
3022 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
3025 if (header
->abbrev_offset
3026 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
3027 &dwarf2_per_objfile
->abbrev
))
3028 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3029 "(offset 0x%lx + 6) [in module %s]"),
3030 (long) header
->abbrev_offset
, (long) header
->offset
,
3033 /* Cast to unsigned long to use 64-bit arithmetic when possible to
3034 avoid potential 32-bit overflow. */
3035 if (((unsigned long) header
->offset
3036 + header
->length
+ header
->initial_length_size
)
3038 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3039 "(offset 0x%lx + 0) [in module %s]"),
3040 (long) header
->length
, (long) header
->offset
,
3044 /* Read in a CU/TU header and perform some basic error checking.
3045 The contents of the header are stored in HEADER.
3046 The result is a pointer to the start of the first DIE. */
3049 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
3050 struct dwarf2_section_info
*section
,
3052 int is_debug_types_section
)
3054 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3055 bfd
*abfd
= section
->asection
->owner
;
3057 header
->offset
= beg_of_comp_unit
- section
->buffer
;
3059 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3061 /* If we're reading a type unit, skip over the signature and
3062 type_offset fields. */
3063 if (is_debug_types_section
)
3064 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
3066 header
->first_die_offset
= info_ptr
- beg_of_comp_unit
;
3068 error_check_comp_unit_head (header
, section
);
3073 /* Read in the types comp unit header information from .debug_types entry at
3074 types_ptr. The result is a pointer to one past the end of the header. */
3077 read_and_check_type_unit_head (struct comp_unit_head
*header
,
3078 struct dwarf2_section_info
*section
,
3080 ULONGEST
*signature
, unsigned int *type_offset
)
3082 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3083 bfd
*abfd
= section
->asection
->owner
;
3085 header
->offset
= beg_of_comp_unit
- section
->buffer
;
3087 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3089 /* If we're reading a type unit, skip over the signature and
3090 type_offset fields. */
3091 if (signature
!= NULL
)
3092 *signature
= read_8_bytes (abfd
, info_ptr
);
3094 if (type_offset
!= NULL
)
3095 *type_offset
= read_offset_1 (abfd
, info_ptr
, header
->offset_size
);
3096 info_ptr
+= header
->offset_size
;
3098 header
->first_die_offset
= info_ptr
- beg_of_comp_unit
;
3100 error_check_comp_unit_head (header
, section
);
3105 /* Allocate a new partial symtab for file named NAME and mark this new
3106 partial symtab as being an include of PST. */
3109 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
3110 struct objfile
*objfile
)
3112 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
3114 subpst
->section_offsets
= pst
->section_offsets
;
3115 subpst
->textlow
= 0;
3116 subpst
->texthigh
= 0;
3118 subpst
->dependencies
= (struct partial_symtab
**)
3119 obstack_alloc (&objfile
->objfile_obstack
,
3120 sizeof (struct partial_symtab
*));
3121 subpst
->dependencies
[0] = pst
;
3122 subpst
->number_of_dependencies
= 1;
3124 subpst
->globals_offset
= 0;
3125 subpst
->n_global_syms
= 0;
3126 subpst
->statics_offset
= 0;
3127 subpst
->n_static_syms
= 0;
3128 subpst
->symtab
= NULL
;
3129 subpst
->read_symtab
= pst
->read_symtab
;
3132 /* No private part is necessary for include psymtabs. This property
3133 can be used to differentiate between such include psymtabs and
3134 the regular ones. */
3135 subpst
->read_symtab_private
= NULL
;
3138 /* Read the Line Number Program data and extract the list of files
3139 included by the source file represented by PST. Build an include
3140 partial symtab for each of these included files. */
3143 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
3144 struct die_info
*die
,
3145 struct partial_symtab
*pst
)
3147 struct objfile
*objfile
= cu
->objfile
;
3148 bfd
*abfd
= objfile
->obfd
;
3149 struct line_header
*lh
= NULL
;
3150 struct attribute
*attr
;
3152 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3155 unsigned int line_offset
= DW_UNSND (attr
);
3157 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
3160 return; /* No linetable, so no includes. */
3162 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3163 dwarf_decode_lines (lh
, pst
->dirname
, cu
, pst
, 1);
3165 free_line_header (lh
);
3169 hash_type_signature (const void *item
)
3171 const struct signatured_type
*type_sig
= item
;
3173 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3174 return type_sig
->signature
;
3178 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
3180 const struct signatured_type
*lhs
= item_lhs
;
3181 const struct signatured_type
*rhs
= item_rhs
;
3183 return lhs
->signature
== rhs
->signature
;
3186 /* Allocate a hash table for signatured types. */
3189 allocate_signatured_type_table (struct objfile
*objfile
)
3191 return htab_create_alloc_ex (41,
3192 hash_type_signature
,
3195 &objfile
->objfile_obstack
,
3196 hashtab_obstack_allocate
,
3197 dummy_obstack_deallocate
);
3200 /* A helper function to add a signatured type CU to a table. */
3203 add_signatured_type_cu_to_table (void **slot
, void *datum
)
3205 struct signatured_type
*sigt
= *slot
;
3206 struct dwarf2_per_cu_data
***datap
= datum
;
3208 **datap
= &sigt
->per_cu
;
3214 /* Create the hash table of all entries in the .debug_types section(s).
3215 The result is zero if there is an error (e.g. missing .debug_types section),
3216 otherwise non-zero. */
3219 create_debug_types_hash_table (struct objfile
*objfile
)
3221 htab_t types_htab
= NULL
;
3222 struct dwarf2_per_cu_data
**iter
;
3224 struct dwarf2_section_info
*section
;
3226 if (VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
))
3228 dwarf2_per_objfile
->signatured_types
= NULL
;
3233 VEC_iterate (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
3237 gdb_byte
*info_ptr
, *end_ptr
;
3239 dwarf2_read_section (objfile
, section
);
3240 info_ptr
= section
->buffer
;
3242 if (info_ptr
== NULL
)
3245 if (types_htab
== NULL
)
3246 types_htab
= allocate_signatured_type_table (objfile
);
3248 if (dwarf2_die_debug
)
3249 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
3251 end_ptr
= info_ptr
+ section
->size
;
3252 while (info_ptr
< end_ptr
)
3254 unsigned int offset
;
3255 unsigned int type_offset
;
3257 struct signatured_type
*type_sig
;
3259 gdb_byte
*ptr
= info_ptr
;
3260 struct comp_unit_head header
;
3262 offset
= ptr
- section
->buffer
;
3264 /* We need to read the type's signature in order to build the hash
3265 table, but we don't need anything else just yet. */
3267 ptr
= read_and_check_type_unit_head (&header
, section
, ptr
,
3268 &signature
, &type_offset
);
3270 /* Skip dummy type units. */
3271 if (ptr
>= end_ptr
|| peek_abbrev_code (objfile
->obfd
, ptr
) == 0)
3273 info_ptr
= info_ptr
+ header
.initial_length_size
+ header
.length
;
3277 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
3278 memset (type_sig
, 0, sizeof (*type_sig
));
3279 type_sig
->signature
= signature
;
3280 type_sig
->type_offset
= type_offset
;
3281 type_sig
->per_cu
.objfile
= objfile
;
3282 type_sig
->per_cu
.debug_types_section
= section
;
3283 type_sig
->per_cu
.offset
= offset
;
3285 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
3286 gdb_assert (slot
!= NULL
);
3289 const struct signatured_type
*dup_sig
= *slot
;
3291 complaint (&symfile_complaints
,
3292 _("debug type entry at offset 0x%x is duplicate to the "
3293 "entry at offset 0x%x, signature 0x%s"),
3294 offset
, dup_sig
->per_cu
.offset
,
3295 phex (signature
, sizeof (signature
)));
3296 gdb_assert (signature
== dup_sig
->signature
);
3300 if (dwarf2_die_debug
)
3301 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3302 offset
, phex (signature
, sizeof (signature
)));
3304 info_ptr
= info_ptr
+ header
.initial_length_size
+ header
.length
;
3308 dwarf2_per_objfile
->signatured_types
= types_htab
;
3310 dwarf2_per_objfile
->n_type_units
= htab_elements (types_htab
);
3311 dwarf2_per_objfile
->all_type_units
3312 = obstack_alloc (&objfile
->objfile_obstack
,
3313 dwarf2_per_objfile
->n_type_units
3314 * sizeof (struct dwarf2_per_cu_data
*));
3315 iter
= &dwarf2_per_objfile
->all_type_units
[0];
3316 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
3317 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
3318 == dwarf2_per_objfile
->n_type_units
);
3323 /* Lookup a signature based type.
3324 Returns NULL if SIG is not present in the table. */
3326 static struct signatured_type
*
3327 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
3329 struct signatured_type find_entry
, *entry
;
3331 if (dwarf2_per_objfile
->signatured_types
== NULL
)
3333 complaint (&symfile_complaints
,
3334 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3338 find_entry
.signature
= sig
;
3339 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
3343 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3346 init_cu_die_reader (struct die_reader_specs
*reader
,
3347 struct dwarf2_cu
*cu
)
3349 reader
->abfd
= cu
->objfile
->obfd
;
3351 if (cu
->per_cu
->debug_types_section
)
3353 gdb_assert (cu
->per_cu
->debug_types_section
->readin
);
3354 reader
->buffer
= cu
->per_cu
->debug_types_section
->buffer
;
3358 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3359 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
3363 /* Find the base address of the compilation unit for range lists and
3364 location lists. It will normally be specified by DW_AT_low_pc.
3365 In DWARF-3 draft 4, the base address could be overridden by
3366 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3367 compilation units with discontinuous ranges. */
3370 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3372 struct attribute
*attr
;
3375 cu
->base_address
= 0;
3377 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3380 cu
->base_address
= DW_ADDR (attr
);
3385 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3388 cu
->base_address
= DW_ADDR (attr
);
3394 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
3395 to combine the common parts.
3396 Process compilation unit THIS_CU for a psymtab.
3397 SECTION is the section the CU/TU comes from,
3398 either .debug_info or .debug_types. */
3401 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
3402 struct dwarf2_section_info
*section
,
3403 int is_debug_types_section
)
3405 struct objfile
*objfile
= this_cu
->objfile
;
3406 bfd
*abfd
= objfile
->obfd
;
3407 gdb_byte
*buffer
= section
->buffer
;
3408 gdb_byte
*info_ptr
= buffer
+ this_cu
->offset
;
3409 unsigned int buffer_size
= section
->size
;
3410 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3411 struct die_info
*comp_unit_die
;
3412 struct partial_symtab
*pst
;
3414 struct cleanup
*back_to_inner
;
3415 struct dwarf2_cu cu
;
3416 int has_children
, has_pc_info
;
3417 struct attribute
*attr
;
3418 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
3419 struct die_reader_specs reader_specs
;
3420 const char *filename
;
3422 /* If this compilation unit was already read in, free the
3423 cached copy in order to read it in again. This is
3424 necessary because we skipped some symbols when we first
3425 read in the compilation unit (see load_partial_dies).
3426 This problem could be avoided, but the benefit is
3428 if (this_cu
->cu
!= NULL
)
3429 free_one_cached_comp_unit (this_cu
->cu
);
3431 /* Note that this is a pointer to our stack frame, being
3432 added to a global data structure. It will be cleaned up
3433 in free_stack_comp_unit when we finish with this
3434 compilation unit. */
3435 init_one_comp_unit (&cu
, this_cu
);
3436 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
3438 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
, info_ptr
,
3439 is_debug_types_section
);
3441 /* Skip dummy compilation units. */
3442 if (info_ptr
>= buffer
+ buffer_size
3443 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3445 do_cleanups (back_to_inner
);
3449 cu
.list_in_scope
= &file_symbols
;
3451 /* Read the abbrevs for this compilation unit into a table. */
3452 dwarf2_read_abbrevs (&cu
);
3453 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
3455 /* Read the compilation unit die. */
3456 init_cu_die_reader (&reader_specs
, &cu
);
3457 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3460 if (is_debug_types_section
)
3462 /* LENGTH has not been set yet for type units. */
3463 gdb_assert (this_cu
->offset
== cu
.header
.offset
);
3464 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
3466 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3468 do_cleanups (back_to_inner
);
3472 prepare_one_comp_unit (&cu
, comp_unit_die
);
3474 /* Allocate a new partial symbol table structure. */
3475 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
3476 if (attr
== NULL
|| !DW_STRING (attr
))
3479 filename
= DW_STRING (attr
);
3480 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
3482 /* TEXTLOW and TEXTHIGH are set below. */
3484 objfile
->global_psymbols
.next
,
3485 objfile
->static_psymbols
.next
);
3486 pst
->psymtabs_addrmap_supported
= 1;
3488 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
3490 pst
->dirname
= DW_STRING (attr
);
3492 pst
->read_symtab_private
= this_cu
;
3494 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3496 /* Store the function that reads in the rest of the symbol table. */
3497 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
3499 this_cu
->v
.psymtab
= pst
;
3501 dwarf2_find_base_address (comp_unit_die
, &cu
);
3503 /* Possibly set the default values of LOWPC and HIGHPC from
3505 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
3506 &best_highpc
, &cu
, pst
);
3507 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
3508 /* Store the contiguous range if it is not empty; it can be empty for
3509 CUs with no code. */
3510 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3511 best_lowpc
+ baseaddr
,
3512 best_highpc
+ baseaddr
- 1, pst
);
3514 /* Check if comp unit has_children.
3515 If so, read the rest of the partial symbols from this comp unit.
3516 If not, there's no more debug_info for this comp unit. */
3519 struct partial_die_info
*first_die
;
3520 CORE_ADDR lowpc
, highpc
;
3522 lowpc
= ((CORE_ADDR
) -1);
3523 highpc
= ((CORE_ADDR
) 0);
3525 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
3527 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
3528 ! has_pc_info
, &cu
);
3530 /* If we didn't find a lowpc, set it to highpc to avoid
3531 complaints from `maint check'. */
3532 if (lowpc
== ((CORE_ADDR
) -1))
3535 /* If the compilation unit didn't have an explicit address range,
3536 then use the information extracted from its child dies. */
3540 best_highpc
= highpc
;
3543 pst
->textlow
= best_lowpc
+ baseaddr
;
3544 pst
->texthigh
= best_highpc
+ baseaddr
;
3546 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
3547 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
3548 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
3549 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
3550 sort_pst_symbols (pst
);
3552 if (is_debug_types_section
)
3554 /* It's not clear we want to do anything with stmt lists here.
3555 Waiting to see what gcc ultimately does. */
3559 /* Get the list of files included in the current compilation unit,
3560 and build a psymtab for each of them. */
3561 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
3564 do_cleanups (back_to_inner
);
3567 /* Traversal function for htab_traverse_noresize.
3568 Process one .debug_types comp-unit. */
3571 process_type_comp_unit (void **slot
, void *info
)
3573 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
3574 struct dwarf2_per_cu_data
*this_cu
;
3576 gdb_assert (info
== NULL
);
3577 this_cu
= &entry
->per_cu
;
3579 gdb_assert (this_cu
->debug_types_section
->readin
);
3580 process_psymtab_comp_unit (this_cu
, this_cu
->debug_types_section
, 1);
3585 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3586 Build partial symbol tables for the .debug_types comp-units. */
3589 build_type_psymtabs (struct objfile
*objfile
)
3591 if (! create_debug_types_hash_table (objfile
))
3594 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
3595 process_type_comp_unit
, NULL
);
3598 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3601 psymtabs_addrmap_cleanup (void *o
)
3603 struct objfile
*objfile
= o
;
3605 objfile
->psymtabs_addrmap
= NULL
;
3608 /* Build the partial symbol table by doing a quick pass through the
3609 .debug_info and .debug_abbrev sections. */
3612 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
3614 struct cleanup
*back_to
, *addrmap_cleanup
;
3615 struct obstack temp_obstack
;
3618 dwarf2_per_objfile
->reading_partial_symbols
= 1;
3620 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3622 /* Any cached compilation units will be linked by the per-objfile
3623 read_in_chain. Make sure to free them when we're done. */
3624 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
3626 build_type_psymtabs (objfile
);
3628 create_all_comp_units (objfile
);
3630 /* Create a temporary address map on a temporary obstack. We later
3631 copy this to the final obstack. */
3632 obstack_init (&temp_obstack
);
3633 make_cleanup_obstack_free (&temp_obstack
);
3634 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
3635 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
3637 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3639 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3641 process_psymtab_comp_unit (per_cu
, &dwarf2_per_objfile
->info
, 0);
3644 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
3645 &objfile
->objfile_obstack
);
3646 discard_cleanups (addrmap_cleanup
);
3648 do_cleanups (back_to
);
3651 /* Load the partial DIEs for a secondary CU into memory. */
3654 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
3656 struct objfile
*objfile
= this_cu
->objfile
;
3657 bfd
*abfd
= objfile
->obfd
;
3659 struct die_info
*comp_unit_die
;
3660 struct dwarf2_cu
*cu
;
3661 struct cleanup
*free_abbrevs_cleanup
, *free_cu_cleanup
= NULL
;
3663 struct die_reader_specs reader_specs
;
3665 struct dwarf2_section_info
*section
= &dwarf2_per_objfile
->info
;
3667 gdb_assert (! this_cu
->debug_types_section
);
3669 gdb_assert (section
->readin
);
3670 info_ptr
= section
->buffer
+ this_cu
->offset
;
3672 if (this_cu
->cu
== NULL
)
3674 cu
= xmalloc (sizeof (*cu
));
3675 init_one_comp_unit (cu
, this_cu
);
3679 /* If an error occurs while loading, release our storage. */
3680 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
3682 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
, info_ptr
,
3685 /* Skip dummy compilation units. */
3686 if (info_ptr
>= (section
->buffer
+ section
->size
)
3687 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3689 do_cleanups (free_cu_cleanup
);
3693 /* Link this CU into read_in_chain. */
3694 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3695 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3700 info_ptr
+= cu
->header
.first_die_offset
;
3703 /* Read the abbrevs for this compilation unit into a table. */
3704 gdb_assert (cu
->dwarf2_abbrevs
== NULL
);
3705 dwarf2_read_abbrevs (cu
);
3706 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3708 /* Read the compilation unit die. */
3709 init_cu_die_reader (&reader_specs
, cu
);
3710 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3713 prepare_one_comp_unit (cu
, comp_unit_die
);
3715 /* Check if comp unit has_children.
3716 If so, read the rest of the partial symbols from this comp unit.
3717 If not, there's no more debug_info for this comp unit. */
3719 load_partial_dies (abfd
, section
->buffer
, info_ptr
, 0, cu
);
3721 do_cleanups (free_abbrevs_cleanup
);
3725 /* We've successfully allocated this compilation unit. Let our
3726 caller clean it up when finished with it. */
3727 discard_cleanups (free_cu_cleanup
);
3731 /* Create a list of all compilation units in OBJFILE.
3732 This is only done for -readnow and building partial symtabs. */
3735 create_all_comp_units (struct objfile
*objfile
)
3739 struct dwarf2_per_cu_data
**all_comp_units
;
3742 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3743 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3747 all_comp_units
= xmalloc (n_allocated
3748 * sizeof (struct dwarf2_per_cu_data
*));
3750 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
3751 + dwarf2_per_objfile
->info
.size
)
3753 unsigned int length
, initial_length_size
;
3754 struct dwarf2_per_cu_data
*this_cu
;
3755 unsigned int offset
;
3757 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
3759 /* Read just enough information to find out where the next
3760 compilation unit is. */
3761 length
= read_initial_length (objfile
->obfd
, info_ptr
,
3762 &initial_length_size
);
3764 /* Save the compilation unit for later lookup. */
3765 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
3766 sizeof (struct dwarf2_per_cu_data
));
3767 memset (this_cu
, 0, sizeof (*this_cu
));
3768 this_cu
->offset
= offset
;
3769 this_cu
->length
= length
+ initial_length_size
;
3770 this_cu
->objfile
= objfile
;
3772 if (n_comp_units
== n_allocated
)
3775 all_comp_units
= xrealloc (all_comp_units
,
3777 * sizeof (struct dwarf2_per_cu_data
*));
3779 all_comp_units
[n_comp_units
++] = this_cu
;
3781 info_ptr
= info_ptr
+ this_cu
->length
;
3784 dwarf2_per_objfile
->all_comp_units
3785 = obstack_alloc (&objfile
->objfile_obstack
,
3786 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3787 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
3788 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3789 xfree (all_comp_units
);
3790 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
3793 /* Process all loaded DIEs for compilation unit CU, starting at
3794 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3795 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3796 DW_AT_ranges). If NEED_PC is set, then this function will set
3797 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3798 and record the covered ranges in the addrmap. */
3801 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
3802 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3804 struct partial_die_info
*pdi
;
3806 /* Now, march along the PDI's, descending into ones which have
3807 interesting children but skipping the children of the other ones,
3808 until we reach the end of the compilation unit. */
3814 fixup_partial_die (pdi
, cu
);
3816 /* Anonymous namespaces or modules have no name but have interesting
3817 children, so we need to look at them. Ditto for anonymous
3820 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
3821 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
3825 case DW_TAG_subprogram
:
3826 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3828 case DW_TAG_constant
:
3829 case DW_TAG_variable
:
3830 case DW_TAG_typedef
:
3831 case DW_TAG_union_type
:
3832 if (!pdi
->is_declaration
)
3834 add_partial_symbol (pdi
, cu
);
3837 case DW_TAG_class_type
:
3838 case DW_TAG_interface_type
:
3839 case DW_TAG_structure_type
:
3840 if (!pdi
->is_declaration
)
3842 add_partial_symbol (pdi
, cu
);
3845 case DW_TAG_enumeration_type
:
3846 if (!pdi
->is_declaration
)
3847 add_partial_enumeration (pdi
, cu
);
3849 case DW_TAG_base_type
:
3850 case DW_TAG_subrange_type
:
3851 /* File scope base type definitions are added to the partial
3853 add_partial_symbol (pdi
, cu
);
3855 case DW_TAG_namespace
:
3856 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
3859 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
3866 /* If the die has a sibling, skip to the sibling. */
3868 pdi
= pdi
->die_sibling
;
3872 /* Functions used to compute the fully scoped name of a partial DIE.
3874 Normally, this is simple. For C++, the parent DIE's fully scoped
3875 name is concatenated with "::" and the partial DIE's name. For
3876 Java, the same thing occurs except that "." is used instead of "::".
3877 Enumerators are an exception; they use the scope of their parent
3878 enumeration type, i.e. the name of the enumeration type is not
3879 prepended to the enumerator.
3881 There are two complexities. One is DW_AT_specification; in this
3882 case "parent" means the parent of the target of the specification,
3883 instead of the direct parent of the DIE. The other is compilers
3884 which do not emit DW_TAG_namespace; in this case we try to guess
3885 the fully qualified name of structure types from their members'
3886 linkage names. This must be done using the DIE's children rather
3887 than the children of any DW_AT_specification target. We only need
3888 to do this for structures at the top level, i.e. if the target of
3889 any DW_AT_specification (if any; otherwise the DIE itself) does not
3892 /* Compute the scope prefix associated with PDI's parent, in
3893 compilation unit CU. The result will be allocated on CU's
3894 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3895 field. NULL is returned if no prefix is necessary. */
3897 partial_die_parent_scope (struct partial_die_info
*pdi
,
3898 struct dwarf2_cu
*cu
)
3900 char *grandparent_scope
;
3901 struct partial_die_info
*parent
, *real_pdi
;
3903 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3904 then this means the parent of the specification DIE. */
3907 while (real_pdi
->has_specification
)
3908 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3910 parent
= real_pdi
->die_parent
;
3914 if (parent
->scope_set
)
3915 return parent
->scope
;
3917 fixup_partial_die (parent
, cu
);
3919 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
3921 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3922 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3923 Work around this problem here. */
3924 if (cu
->language
== language_cplus
3925 && parent
->tag
== DW_TAG_namespace
3926 && strcmp (parent
->name
, "::") == 0
3927 && grandparent_scope
== NULL
)
3929 parent
->scope
= NULL
;
3930 parent
->scope_set
= 1;
3934 if (pdi
->tag
== DW_TAG_enumerator
)
3935 /* Enumerators should not get the name of the enumeration as a prefix. */
3936 parent
->scope
= grandparent_scope
;
3937 else if (parent
->tag
== DW_TAG_namespace
3938 || parent
->tag
== DW_TAG_module
3939 || parent
->tag
== DW_TAG_structure_type
3940 || parent
->tag
== DW_TAG_class_type
3941 || parent
->tag
== DW_TAG_interface_type
3942 || parent
->tag
== DW_TAG_union_type
3943 || parent
->tag
== DW_TAG_enumeration_type
)
3945 if (grandparent_scope
== NULL
)
3946 parent
->scope
= parent
->name
;
3948 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
3950 parent
->name
, 0, cu
);
3954 /* FIXME drow/2004-04-01: What should we be doing with
3955 function-local names? For partial symbols, we should probably be
3957 complaint (&symfile_complaints
,
3958 _("unhandled containing DIE tag %d for DIE at %d"),
3959 parent
->tag
, pdi
->offset
);
3960 parent
->scope
= grandparent_scope
;
3963 parent
->scope_set
= 1;
3964 return parent
->scope
;
3967 /* Return the fully scoped name associated with PDI, from compilation unit
3968 CU. The result will be allocated with malloc. */
3970 partial_die_full_name (struct partial_die_info
*pdi
,
3971 struct dwarf2_cu
*cu
)
3975 /* If this is a template instantiation, we can not work out the
3976 template arguments from partial DIEs. So, unfortunately, we have
3977 to go through the full DIEs. At least any work we do building
3978 types here will be reused if full symbols are loaded later. */
3979 if (pdi
->has_template_arguments
)
3981 fixup_partial_die (pdi
, cu
);
3983 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
3985 struct die_info
*die
;
3986 struct attribute attr
;
3987 struct dwarf2_cu
*ref_cu
= cu
;
3990 attr
.form
= DW_FORM_ref_addr
;
3991 attr
.u
.addr
= pdi
->offset
;
3992 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
3994 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
3998 parent_scope
= partial_die_parent_scope (pdi
, cu
);
3999 if (parent_scope
== NULL
)
4002 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
4006 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
4008 struct objfile
*objfile
= cu
->objfile
;
4010 char *actual_name
= NULL
;
4012 int built_actual_name
= 0;
4014 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4016 actual_name
= partial_die_full_name (pdi
, cu
);
4018 built_actual_name
= 1;
4020 if (actual_name
== NULL
)
4021 actual_name
= pdi
->name
;
4025 case DW_TAG_subprogram
:
4026 if (pdi
->is_external
|| cu
->language
== language_ada
)
4028 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
4029 of the global scope. But in Ada, we want to be able to access
4030 nested procedures globally. So all Ada subprograms are stored
4031 in the global scope. */
4032 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4033 mst_text, objfile); */
4034 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4036 VAR_DOMAIN
, LOC_BLOCK
,
4037 &objfile
->global_psymbols
,
4038 0, pdi
->lowpc
+ baseaddr
,
4039 cu
->language
, objfile
);
4043 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4044 mst_file_text, objfile); */
4045 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4047 VAR_DOMAIN
, LOC_BLOCK
,
4048 &objfile
->static_psymbols
,
4049 0, pdi
->lowpc
+ baseaddr
,
4050 cu
->language
, objfile
);
4053 case DW_TAG_constant
:
4055 struct psymbol_allocation_list
*list
;
4057 if (pdi
->is_external
)
4058 list
= &objfile
->global_psymbols
;
4060 list
= &objfile
->static_psymbols
;
4061 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4062 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
4063 list
, 0, 0, cu
->language
, objfile
);
4066 case DW_TAG_variable
:
4068 addr
= decode_locdesc (pdi
->locdesc
, cu
);
4072 && !dwarf2_per_objfile
->has_section_at_zero
)
4074 /* A global or static variable may also have been stripped
4075 out by the linker if unused, in which case its address
4076 will be nullified; do not add such variables into partial
4077 symbol table then. */
4079 else if (pdi
->is_external
)
4082 Don't enter into the minimal symbol tables as there is
4083 a minimal symbol table entry from the ELF symbols already.
4084 Enter into partial symbol table if it has a location
4085 descriptor or a type.
4086 If the location descriptor is missing, new_symbol will create
4087 a LOC_UNRESOLVED symbol, the address of the variable will then
4088 be determined from the minimal symbol table whenever the variable
4090 The address for the partial symbol table entry is not
4091 used by GDB, but it comes in handy for debugging partial symbol
4094 if (pdi
->locdesc
|| pdi
->has_type
)
4095 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4097 VAR_DOMAIN
, LOC_STATIC
,
4098 &objfile
->global_psymbols
,
4100 cu
->language
, objfile
);
4104 /* Static Variable. Skip symbols without location descriptors. */
4105 if (pdi
->locdesc
== NULL
)
4107 if (built_actual_name
)
4108 xfree (actual_name
);
4111 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
4112 mst_file_data, objfile); */
4113 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4115 VAR_DOMAIN
, LOC_STATIC
,
4116 &objfile
->static_psymbols
,
4118 cu
->language
, objfile
);
4121 case DW_TAG_typedef
:
4122 case DW_TAG_base_type
:
4123 case DW_TAG_subrange_type
:
4124 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4126 VAR_DOMAIN
, LOC_TYPEDEF
,
4127 &objfile
->static_psymbols
,
4128 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4130 case DW_TAG_namespace
:
4131 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4133 VAR_DOMAIN
, LOC_TYPEDEF
,
4134 &objfile
->global_psymbols
,
4135 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4137 case DW_TAG_class_type
:
4138 case DW_TAG_interface_type
:
4139 case DW_TAG_structure_type
:
4140 case DW_TAG_union_type
:
4141 case DW_TAG_enumeration_type
:
4142 /* Skip external references. The DWARF standard says in the section
4143 about "Structure, Union, and Class Type Entries": "An incomplete
4144 structure, union or class type is represented by a structure,
4145 union or class entry that does not have a byte size attribute
4146 and that has a DW_AT_declaration attribute." */
4147 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
4149 if (built_actual_name
)
4150 xfree (actual_name
);
4154 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
4155 static vs. global. */
4156 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4158 STRUCT_DOMAIN
, LOC_TYPEDEF
,
4159 (cu
->language
== language_cplus
4160 || cu
->language
== language_java
)
4161 ? &objfile
->global_psymbols
4162 : &objfile
->static_psymbols
,
4163 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4166 case DW_TAG_enumerator
:
4167 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4169 VAR_DOMAIN
, LOC_CONST
,
4170 (cu
->language
== language_cplus
4171 || cu
->language
== language_java
)
4172 ? &objfile
->global_psymbols
4173 : &objfile
->static_psymbols
,
4174 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4180 if (built_actual_name
)
4181 xfree (actual_name
);
4184 /* Read a partial die corresponding to a namespace; also, add a symbol
4185 corresponding to that namespace to the symbol table. NAMESPACE is
4186 the name of the enclosing namespace. */
4189 add_partial_namespace (struct partial_die_info
*pdi
,
4190 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4191 int need_pc
, struct dwarf2_cu
*cu
)
4193 /* Add a symbol for the namespace. */
4195 add_partial_symbol (pdi
, cu
);
4197 /* Now scan partial symbols in that namespace. */
4199 if (pdi
->has_children
)
4200 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4203 /* Read a partial die corresponding to a Fortran module. */
4206 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
4207 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4209 /* Now scan partial symbols in that module. */
4211 if (pdi
->has_children
)
4212 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4215 /* Read a partial die corresponding to a subprogram and create a partial
4216 symbol for that subprogram. When the CU language allows it, this
4217 routine also defines a partial symbol for each nested subprogram
4218 that this subprogram contains.
4220 DIE my also be a lexical block, in which case we simply search
4221 recursively for suprograms defined inside that lexical block.
4222 Again, this is only performed when the CU language allows this
4223 type of definitions. */
4226 add_partial_subprogram (struct partial_die_info
*pdi
,
4227 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4228 int need_pc
, struct dwarf2_cu
*cu
)
4230 if (pdi
->tag
== DW_TAG_subprogram
)
4232 if (pdi
->has_pc_info
)
4234 if (pdi
->lowpc
< *lowpc
)
4235 *lowpc
= pdi
->lowpc
;
4236 if (pdi
->highpc
> *highpc
)
4237 *highpc
= pdi
->highpc
;
4241 struct objfile
*objfile
= cu
->objfile
;
4243 baseaddr
= ANOFFSET (objfile
->section_offsets
,
4244 SECT_OFF_TEXT (objfile
));
4245 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4246 pdi
->lowpc
+ baseaddr
,
4247 pdi
->highpc
- 1 + baseaddr
,
4248 cu
->per_cu
->v
.psymtab
);
4250 if (!pdi
->is_declaration
)
4251 /* Ignore subprogram DIEs that do not have a name, they are
4252 illegal. Do not emit a complaint at this point, we will
4253 do so when we convert this psymtab into a symtab. */
4255 add_partial_symbol (pdi
, cu
);
4259 if (! pdi
->has_children
)
4262 if (cu
->language
== language_ada
)
4264 pdi
= pdi
->die_child
;
4267 fixup_partial_die (pdi
, cu
);
4268 if (pdi
->tag
== DW_TAG_subprogram
4269 || pdi
->tag
== DW_TAG_lexical_block
)
4270 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4271 pdi
= pdi
->die_sibling
;
4276 /* Read a partial die corresponding to an enumeration type. */
4279 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
4280 struct dwarf2_cu
*cu
)
4282 struct partial_die_info
*pdi
;
4284 if (enum_pdi
->name
!= NULL
)
4285 add_partial_symbol (enum_pdi
, cu
);
4287 pdi
= enum_pdi
->die_child
;
4290 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
4291 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
4293 add_partial_symbol (pdi
, cu
);
4294 pdi
= pdi
->die_sibling
;
4298 /* Return the initial uleb128 in the die at INFO_PTR. */
4301 peek_abbrev_code (bfd
*abfd
, gdb_byte
*info_ptr
)
4303 unsigned int bytes_read
;
4305 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4308 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4309 Return the corresponding abbrev, or NULL if the number is zero (indicating
4310 an empty DIE). In either case *BYTES_READ will be set to the length of
4311 the initial number. */
4313 static struct abbrev_info
*
4314 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
4315 struct dwarf2_cu
*cu
)
4317 bfd
*abfd
= cu
->objfile
->obfd
;
4318 unsigned int abbrev_number
;
4319 struct abbrev_info
*abbrev
;
4321 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
4323 if (abbrev_number
== 0)
4326 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4329 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4330 abbrev_number
, bfd_get_filename (abfd
));
4336 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4337 Returns a pointer to the end of a series of DIEs, terminated by an empty
4338 DIE. Any children of the skipped DIEs will also be skipped. */
4341 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
4343 struct abbrev_info
*abbrev
;
4344 unsigned int bytes_read
;
4348 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
4350 return info_ptr
+ bytes_read
;
4352 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
4356 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4357 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4358 abbrev corresponding to that skipped uleb128 should be passed in
4359 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4363 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4364 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
4366 unsigned int bytes_read
;
4367 struct attribute attr
;
4368 bfd
*abfd
= cu
->objfile
->obfd
;
4369 unsigned int form
, i
;
4371 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
4373 /* The only abbrev we care about is DW_AT_sibling. */
4374 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
4376 read_attribute (&attr
, &abbrev
->attrs
[i
],
4377 abfd
, info_ptr
, cu
);
4378 if (attr
.form
== DW_FORM_ref_addr
)
4379 complaint (&symfile_complaints
,
4380 _("ignoring absolute DW_AT_sibling"));
4382 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
4385 /* If it isn't DW_AT_sibling, skip this attribute. */
4386 form
= abbrev
->attrs
[i
].form
;
4390 case DW_FORM_ref_addr
:
4391 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4392 and later it is offset sized. */
4393 if (cu
->header
.version
== 2)
4394 info_ptr
+= cu
->header
.addr_size
;
4396 info_ptr
+= cu
->header
.offset_size
;
4399 info_ptr
+= cu
->header
.addr_size
;
4406 case DW_FORM_flag_present
:
4418 case DW_FORM_ref_sig8
:
4421 case DW_FORM_string
:
4422 read_direct_string (abfd
, info_ptr
, &bytes_read
);
4423 info_ptr
+= bytes_read
;
4425 case DW_FORM_sec_offset
:
4427 info_ptr
+= cu
->header
.offset_size
;
4429 case DW_FORM_exprloc
:
4431 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4432 info_ptr
+= bytes_read
;
4434 case DW_FORM_block1
:
4435 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
4437 case DW_FORM_block2
:
4438 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
4440 case DW_FORM_block4
:
4441 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
4445 case DW_FORM_ref_udata
:
4446 info_ptr
= skip_leb128 (abfd
, info_ptr
);
4448 case DW_FORM_indirect
:
4449 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4450 info_ptr
+= bytes_read
;
4451 /* We need to continue parsing from here, so just go back to
4453 goto skip_attribute
;
4456 error (_("Dwarf Error: Cannot handle %s "
4457 "in DWARF reader [in module %s]"),
4458 dwarf_form_name (form
),
4459 bfd_get_filename (abfd
));
4463 if (abbrev
->has_children
)
4464 return skip_children (buffer
, info_ptr
, cu
);
4469 /* Locate ORIG_PDI's sibling.
4470 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4474 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
4475 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4476 bfd
*abfd
, struct dwarf2_cu
*cu
)
4478 /* Do we know the sibling already? */
4480 if (orig_pdi
->sibling
)
4481 return orig_pdi
->sibling
;
4483 /* Are there any children to deal with? */
4485 if (!orig_pdi
->has_children
)
4488 /* Skip the children the long way. */
4490 return skip_children (buffer
, info_ptr
, cu
);
4493 /* Expand this partial symbol table into a full symbol table. */
4496 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
4502 warning (_("bug: psymtab for %s is already read in."),
4509 printf_filtered (_("Reading in symbols for %s..."),
4511 gdb_flush (gdb_stdout
);
4514 /* Restore our global data. */
4515 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
4516 dwarf2_objfile_data_key
);
4518 /* If this psymtab is constructed from a debug-only objfile, the
4519 has_section_at_zero flag will not necessarily be correct. We
4520 can get the correct value for this flag by looking at the data
4521 associated with the (presumably stripped) associated objfile. */
4522 if (pst
->objfile
->separate_debug_objfile_backlink
)
4524 struct dwarf2_per_objfile
*dpo_backlink
4525 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
4526 dwarf2_objfile_data_key
);
4528 dwarf2_per_objfile
->has_section_at_zero
4529 = dpo_backlink
->has_section_at_zero
;
4532 dwarf2_per_objfile
->reading_partial_symbols
= 0;
4534 psymtab_to_symtab_1 (pst
);
4536 /* Finish up the debug error message. */
4538 printf_filtered (_("done.\n"));
4543 /* Reading in full CUs. */
4545 /* Add PER_CU to the queue. */
4548 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4550 struct dwarf2_queue_item
*item
;
4553 item
= xmalloc (sizeof (*item
));
4554 item
->per_cu
= per_cu
;
4557 if (dwarf2_queue
== NULL
)
4558 dwarf2_queue
= item
;
4560 dwarf2_queue_tail
->next
= item
;
4562 dwarf2_queue_tail
= item
;
4565 /* Process the queue. */
4568 process_queue (void)
4570 struct dwarf2_queue_item
*item
, *next_item
;
4572 /* The queue starts out with one item, but following a DIE reference
4573 may load a new CU, adding it to the end of the queue. */
4574 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
4576 if (dwarf2_per_objfile
->using_index
4577 ? !item
->per_cu
->v
.quick
->symtab
4578 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
4579 process_full_comp_unit (item
->per_cu
);
4581 item
->per_cu
->queued
= 0;
4582 next_item
= item
->next
;
4586 dwarf2_queue_tail
= NULL
;
4589 /* Free all allocated queue entries. This function only releases anything if
4590 an error was thrown; if the queue was processed then it would have been
4591 freed as we went along. */
4594 dwarf2_release_queue (void *dummy
)
4596 struct dwarf2_queue_item
*item
, *last
;
4598 item
= dwarf2_queue
;
4601 /* Anything still marked queued is likely to be in an
4602 inconsistent state, so discard it. */
4603 if (item
->per_cu
->queued
)
4605 if (item
->per_cu
->cu
!= NULL
)
4606 free_one_cached_comp_unit (item
->per_cu
->cu
);
4607 item
->per_cu
->queued
= 0;
4615 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
4618 /* Read in full symbols for PST, and anything it depends on. */
4621 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
4623 struct dwarf2_per_cu_data
*per_cu
;
4624 struct cleanup
*back_to
;
4627 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
4628 if (!pst
->dependencies
[i
]->readin
)
4630 /* Inform about additional files that need to be read in. */
4633 /* FIXME: i18n: Need to make this a single string. */
4634 fputs_filtered (" ", gdb_stdout
);
4636 fputs_filtered ("and ", gdb_stdout
);
4638 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
4639 wrap_here (""); /* Flush output. */
4640 gdb_flush (gdb_stdout
);
4642 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
4645 per_cu
= pst
->read_symtab_private
;
4649 /* It's an include file, no symbols to read for it.
4650 Everything is in the parent symtab. */
4655 dw2_do_instantiate_symtab (per_cu
);
4658 /* Load the DIEs associated with PER_CU into memory. */
4661 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4663 struct objfile
*objfile
= per_cu
->objfile
;
4664 bfd
*abfd
= objfile
->obfd
;
4665 struct dwarf2_cu
*cu
;
4666 unsigned int offset
;
4667 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
4668 struct cleanup
*free_abbrevs_cleanup
= NULL
, *free_cu_cleanup
= NULL
;
4669 struct attribute
*attr
;
4672 gdb_assert (! per_cu
->debug_types_section
);
4674 /* Set local variables from the partial symbol table info. */
4675 offset
= per_cu
->offset
;
4677 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4678 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
4679 beg_of_comp_unit
= info_ptr
;
4681 if (per_cu
->cu
== NULL
)
4683 cu
= xmalloc (sizeof (*cu
));
4684 init_one_comp_unit (cu
, per_cu
);
4688 /* If an error occurs while loading, release our storage. */
4689 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
4691 /* Read in the comp_unit header. */
4692 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
4694 /* Skip dummy compilation units. */
4695 if (info_ptr
>= (dwarf2_per_objfile
->info
.buffer
4696 + dwarf2_per_objfile
->info
.size
)
4697 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4699 do_cleanups (free_cu_cleanup
);
4703 /* Complete the cu_header. */
4704 cu
->header
.offset
= offset
;
4705 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
4707 /* Read the abbrevs for this compilation unit. */
4708 dwarf2_read_abbrevs (cu
);
4709 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
4711 /* Link this CU into read_in_chain. */
4712 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4713 dwarf2_per_objfile
->read_in_chain
= per_cu
;
4718 info_ptr
+= cu
->header
.first_die_offset
;
4721 cu
->dies
= read_comp_unit (info_ptr
, cu
);
4723 /* We try not to read any attributes in this function, because not
4724 all CUs needed for references have been loaded yet, and symbol
4725 table processing isn't initialized. But we have to set the CU language,
4726 or we won't be able to build types correctly. */
4727 prepare_one_comp_unit (cu
, cu
->dies
);
4729 /* Similarly, if we do not read the producer, we can not apply
4730 producer-specific interpretation. */
4731 attr
= dwarf2_attr (cu
->dies
, DW_AT_producer
, cu
);
4733 cu
->producer
= DW_STRING (attr
);
4737 do_cleanups (free_abbrevs_cleanup
);
4739 /* We've successfully allocated this compilation unit. Let our
4740 caller clean it up when finished with it. */
4741 discard_cleanups (free_cu_cleanup
);
4745 /* Add a DIE to the delayed physname list. */
4748 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
4749 const char *name
, struct die_info
*die
,
4750 struct dwarf2_cu
*cu
)
4752 struct delayed_method_info mi
;
4754 mi
.fnfield_index
= fnfield_index
;
4758 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
4761 /* A cleanup for freeing the delayed method list. */
4764 free_delayed_list (void *ptr
)
4766 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
4767 if (cu
->method_list
!= NULL
)
4769 VEC_free (delayed_method_info
, cu
->method_list
);
4770 cu
->method_list
= NULL
;
4774 /* Compute the physnames of any methods on the CU's method list.
4776 The computation of method physnames is delayed in order to avoid the
4777 (bad) condition that one of the method's formal parameters is of an as yet
4781 compute_delayed_physnames (struct dwarf2_cu
*cu
)
4784 struct delayed_method_info
*mi
;
4785 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
4787 const char *physname
;
4788 struct fn_fieldlist
*fn_flp
4789 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
4790 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
4791 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
4795 /* Generate full symbol information for PER_CU, whose DIEs have
4796 already been loaded into memory. */
4799 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4801 struct dwarf2_cu
*cu
= per_cu
->cu
;
4802 struct objfile
*objfile
= per_cu
->objfile
;
4803 CORE_ADDR lowpc
, highpc
;
4804 struct symtab
*symtab
;
4805 struct cleanup
*back_to
, *delayed_list_cleanup
;
4808 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4811 back_to
= make_cleanup (really_free_pendings
, NULL
);
4812 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
4814 cu
->list_in_scope
= &file_symbols
;
4816 /* Do line number decoding in read_file_scope () */
4817 process_die (cu
->dies
, cu
);
4819 /* Now that we have processed all the DIEs in the CU, all the types
4820 should be complete, and it should now be safe to compute all of the
4822 compute_delayed_physnames (cu
);
4823 do_cleanups (delayed_list_cleanup
);
4825 /* Some compilers don't define a DW_AT_high_pc attribute for the
4826 compilation unit. If the DW_AT_high_pc is missing, synthesize
4827 it, by scanning the DIE's below the compilation unit. */
4828 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
4830 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
4834 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
4836 /* Set symtab language to language from DW_AT_language. If the
4837 compilation is from a C file generated by language preprocessors, do
4838 not set the language if it was already deduced by start_subfile. */
4839 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
4840 symtab
->language
= cu
->language
;
4842 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
4843 produce DW_AT_location with location lists but it can be possibly
4844 invalid without -fvar-tracking.
4846 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
4847 needed, it would be wrong due to missing DW_AT_producer there.
4849 Still one can confuse GDB by using non-standard GCC compilation
4850 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
4852 if (cu
->has_loclist
&& gcc_4_minor
>= 0)
4853 symtab
->locations_valid
= 1;
4855 if (gcc_4_minor
>= 5)
4856 symtab
->epilogue_unwind_valid
= 1;
4858 symtab
->call_site_htab
= cu
->call_site_htab
;
4861 if (dwarf2_per_objfile
->using_index
)
4862 per_cu
->v
.quick
->symtab
= symtab
;
4865 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4866 pst
->symtab
= symtab
;
4870 do_cleanups (back_to
);
4873 /* Process a die and its children. */
4876 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
4880 case DW_TAG_padding
:
4882 case DW_TAG_compile_unit
:
4883 read_file_scope (die
, cu
);
4885 case DW_TAG_type_unit
:
4886 read_type_unit_scope (die
, cu
);
4888 case DW_TAG_subprogram
:
4889 case DW_TAG_inlined_subroutine
:
4890 read_func_scope (die
, cu
);
4892 case DW_TAG_lexical_block
:
4893 case DW_TAG_try_block
:
4894 case DW_TAG_catch_block
:
4895 read_lexical_block_scope (die
, cu
);
4897 case DW_TAG_GNU_call_site
:
4898 read_call_site_scope (die
, cu
);
4900 case DW_TAG_class_type
:
4901 case DW_TAG_interface_type
:
4902 case DW_TAG_structure_type
:
4903 case DW_TAG_union_type
:
4904 process_structure_scope (die
, cu
);
4906 case DW_TAG_enumeration_type
:
4907 process_enumeration_scope (die
, cu
);
4910 /* These dies have a type, but processing them does not create
4911 a symbol or recurse to process the children. Therefore we can
4912 read them on-demand through read_type_die. */
4913 case DW_TAG_subroutine_type
:
4914 case DW_TAG_set_type
:
4915 case DW_TAG_array_type
:
4916 case DW_TAG_pointer_type
:
4917 case DW_TAG_ptr_to_member_type
:
4918 case DW_TAG_reference_type
:
4919 case DW_TAG_string_type
:
4922 case DW_TAG_base_type
:
4923 case DW_TAG_subrange_type
:
4924 case DW_TAG_typedef
:
4925 /* Add a typedef symbol for the type definition, if it has a
4927 new_symbol (die
, read_type_die (die
, cu
), cu
);
4929 case DW_TAG_common_block
:
4930 read_common_block (die
, cu
);
4932 case DW_TAG_common_inclusion
:
4934 case DW_TAG_namespace
:
4935 processing_has_namespace_info
= 1;
4936 read_namespace (die
, cu
);
4939 processing_has_namespace_info
= 1;
4940 read_module (die
, cu
);
4942 case DW_TAG_imported_declaration
:
4943 case DW_TAG_imported_module
:
4944 processing_has_namespace_info
= 1;
4945 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
4946 || cu
->language
!= language_fortran
))
4947 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
4948 dwarf_tag_name (die
->tag
));
4949 read_import_statement (die
, cu
);
4952 new_symbol (die
, NULL
, cu
);
4957 /* A helper function for dwarf2_compute_name which determines whether DIE
4958 needs to have the name of the scope prepended to the name listed in the
4962 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4964 struct attribute
*attr
;
4968 case DW_TAG_namespace
:
4969 case DW_TAG_typedef
:
4970 case DW_TAG_class_type
:
4971 case DW_TAG_interface_type
:
4972 case DW_TAG_structure_type
:
4973 case DW_TAG_union_type
:
4974 case DW_TAG_enumeration_type
:
4975 case DW_TAG_enumerator
:
4976 case DW_TAG_subprogram
:
4980 case DW_TAG_variable
:
4981 case DW_TAG_constant
:
4982 /* We only need to prefix "globally" visible variables. These include
4983 any variable marked with DW_AT_external or any variable that
4984 lives in a namespace. [Variables in anonymous namespaces
4985 require prefixing, but they are not DW_AT_external.] */
4987 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
4989 struct dwarf2_cu
*spec_cu
= cu
;
4991 return die_needs_namespace (die_specification (die
, &spec_cu
),
4995 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
4996 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
4997 && die
->parent
->tag
!= DW_TAG_module
)
4999 /* A variable in a lexical block of some kind does not need a
5000 namespace, even though in C++ such variables may be external
5001 and have a mangled name. */
5002 if (die
->parent
->tag
== DW_TAG_lexical_block
5003 || die
->parent
->tag
== DW_TAG_try_block
5004 || die
->parent
->tag
== DW_TAG_catch_block
5005 || die
->parent
->tag
== DW_TAG_subprogram
)
5014 /* Retrieve the last character from a mem_file. */
5017 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
5019 char *last_char_p
= (char *) object
;
5022 *last_char_p
= buffer
[length
- 1];
5025 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
5026 compute the physname for the object, which include a method's
5027 formal parameters (C++/Java) and return type (Java).
5029 For Ada, return the DIE's linkage name rather than the fully qualified
5030 name. PHYSNAME is ignored..
5032 The result is allocated on the objfile_obstack and canonicalized. */
5035 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
5038 struct objfile
*objfile
= cu
->objfile
;
5041 name
= dwarf2_name (die
, cu
);
5043 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
5044 compute it by typename_concat inside GDB. */
5045 if (cu
->language
== language_ada
5046 || (cu
->language
== language_fortran
&& physname
))
5048 /* For Ada unit, we prefer the linkage name over the name, as
5049 the former contains the exported name, which the user expects
5050 to be able to reference. Ideally, we want the user to be able
5051 to reference this entity using either natural or linkage name,
5052 but we haven't started looking at this enhancement yet. */
5053 struct attribute
*attr
;
5055 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5057 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5058 if (attr
&& DW_STRING (attr
))
5059 return DW_STRING (attr
);
5062 /* These are the only languages we know how to qualify names in. */
5064 && (cu
->language
== language_cplus
|| cu
->language
== language_java
5065 || cu
->language
== language_fortran
))
5067 if (die_needs_namespace (die
, cu
))
5071 struct ui_file
*buf
;
5073 prefix
= determine_prefix (die
, cu
);
5074 buf
= mem_fileopen ();
5075 if (*prefix
!= '\0')
5077 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
5080 fputs_unfiltered (prefixed_name
, buf
);
5081 xfree (prefixed_name
);
5084 fputs_unfiltered (name
, buf
);
5086 /* Template parameters may be specified in the DIE's DW_AT_name, or
5087 as children with DW_TAG_template_type_param or
5088 DW_TAG_value_type_param. If the latter, add them to the name
5089 here. If the name already has template parameters, then
5090 skip this step; some versions of GCC emit both, and
5091 it is more efficient to use the pre-computed name.
5093 Something to keep in mind about this process: it is very
5094 unlikely, or in some cases downright impossible, to produce
5095 something that will match the mangled name of a function.
5096 If the definition of the function has the same debug info,
5097 we should be able to match up with it anyway. But fallbacks
5098 using the minimal symbol, for instance to find a method
5099 implemented in a stripped copy of libstdc++, will not work.
5100 If we do not have debug info for the definition, we will have to
5101 match them up some other way.
5103 When we do name matching there is a related problem with function
5104 templates; two instantiated function templates are allowed to
5105 differ only by their return types, which we do not add here. */
5107 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
5109 struct attribute
*attr
;
5110 struct die_info
*child
;
5113 die
->building_fullname
= 1;
5115 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
5120 struct dwarf2_locexpr_baton
*baton
;
5123 if (child
->tag
!= DW_TAG_template_type_param
5124 && child
->tag
!= DW_TAG_template_value_param
)
5129 fputs_unfiltered ("<", buf
);
5133 fputs_unfiltered (", ", buf
);
5135 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
5138 complaint (&symfile_complaints
,
5139 _("template parameter missing DW_AT_type"));
5140 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
5143 type
= die_type (child
, cu
);
5145 if (child
->tag
== DW_TAG_template_type_param
)
5147 c_print_type (type
, "", buf
, -1, 0);
5151 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
5154 complaint (&symfile_complaints
,
5155 _("template parameter missing "
5156 "DW_AT_const_value"));
5157 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
5161 dwarf2_const_value_attr (attr
, type
, name
,
5162 &cu
->comp_unit_obstack
, cu
,
5163 &value
, &bytes
, &baton
);
5165 if (TYPE_NOSIGN (type
))
5166 /* GDB prints characters as NUMBER 'CHAR'. If that's
5167 changed, this can use value_print instead. */
5168 c_printchar (value
, type
, buf
);
5171 struct value_print_options opts
;
5174 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
5178 else if (bytes
!= NULL
)
5180 v
= allocate_value (type
);
5181 memcpy (value_contents_writeable (v
), bytes
,
5182 TYPE_LENGTH (type
));
5185 v
= value_from_longest (type
, value
);
5187 /* Specify decimal so that we do not depend on
5189 get_formatted_print_options (&opts
, 'd');
5191 value_print (v
, buf
, &opts
);
5197 die
->building_fullname
= 0;
5201 /* Close the argument list, with a space if necessary
5202 (nested templates). */
5203 char last_char
= '\0';
5204 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
5205 if (last_char
== '>')
5206 fputs_unfiltered (" >", buf
);
5208 fputs_unfiltered (">", buf
);
5212 /* For Java and C++ methods, append formal parameter type
5213 information, if PHYSNAME. */
5215 if (physname
&& die
->tag
== DW_TAG_subprogram
5216 && (cu
->language
== language_cplus
5217 || cu
->language
== language_java
))
5219 struct type
*type
= read_type_die (die
, cu
);
5221 c_type_print_args (type
, buf
, 1, cu
->language
);
5223 if (cu
->language
== language_java
)
5225 /* For java, we must append the return type to method
5227 if (die
->tag
== DW_TAG_subprogram
)
5228 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
5231 else if (cu
->language
== language_cplus
)
5233 /* Assume that an artificial first parameter is
5234 "this", but do not crash if it is not. RealView
5235 marks unnamed (and thus unused) parameters as
5236 artificial; there is no way to differentiate
5238 if (TYPE_NFIELDS (type
) > 0
5239 && TYPE_FIELD_ARTIFICIAL (type
, 0)
5240 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
5241 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
5243 fputs_unfiltered (" const", buf
);
5247 name
= ui_file_obsavestring (buf
, &objfile
->objfile_obstack
,
5249 ui_file_delete (buf
);
5251 if (cu
->language
== language_cplus
)
5254 = dwarf2_canonicalize_name (name
, cu
,
5255 &objfile
->objfile_obstack
);
5266 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5267 If scope qualifiers are appropriate they will be added. The result
5268 will be allocated on the objfile_obstack, or NULL if the DIE does
5269 not have a name. NAME may either be from a previous call to
5270 dwarf2_name or NULL.
5272 The output string will be canonicalized (if C++/Java). */
5275 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5277 return dwarf2_compute_name (name
, die
, cu
, 0);
5280 /* Construct a physname for the given DIE in CU. NAME may either be
5281 from a previous call to dwarf2_name or NULL. The result will be
5282 allocated on the objfile_objstack or NULL if the DIE does not have a
5285 The output string will be canonicalized (if C++/Java). */
5288 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5290 struct objfile
*objfile
= cu
->objfile
;
5291 struct attribute
*attr
;
5292 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
5293 struct cleanup
*back_to
;
5296 /* In this case dwarf2_compute_name is just a shortcut not building anything
5298 if (!die_needs_namespace (die
, cu
))
5299 return dwarf2_compute_name (name
, die
, cu
, 1);
5301 back_to
= make_cleanup (null_cleanup
, NULL
);
5303 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5305 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5307 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
5309 if (attr
&& DW_STRING (attr
))
5313 mangled
= DW_STRING (attr
);
5315 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
5316 type. It is easier for GDB users to search for such functions as
5317 `name(params)' than `long name(params)'. In such case the minimal
5318 symbol names do not match the full symbol names but for template
5319 functions there is never a need to look up their definition from their
5320 declaration so the only disadvantage remains the minimal symbol
5321 variant `long name(params)' does not have the proper inferior type.
5324 demangled
= cplus_demangle (mangled
, (DMGL_PARAMS
| DMGL_ANSI
5325 | (cu
->language
== language_java
5326 ? DMGL_JAVA
| DMGL_RET_POSTFIX
5330 make_cleanup (xfree
, demangled
);
5340 if (canon
== NULL
|| check_physname
)
5342 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
5344 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
5346 /* It may not mean a bug in GDB. The compiler could also
5347 compute DW_AT_linkage_name incorrectly. But in such case
5348 GDB would need to be bug-to-bug compatible. */
5350 complaint (&symfile_complaints
,
5351 _("Computed physname <%s> does not match demangled <%s> "
5352 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
5353 physname
, canon
, mangled
, die
->offset
, objfile
->name
);
5355 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
5356 is available here - over computed PHYSNAME. It is safer
5357 against both buggy GDB and buggy compilers. */
5371 retval
= obsavestring (retval
, strlen (retval
),
5372 &objfile
->objfile_obstack
);
5374 do_cleanups (back_to
);
5378 /* Read the import statement specified by the given die and record it. */
5381 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
5383 struct objfile
*objfile
= cu
->objfile
;
5384 struct attribute
*import_attr
;
5385 struct die_info
*imported_die
, *child_die
;
5386 struct dwarf2_cu
*imported_cu
;
5387 const char *imported_name
;
5388 const char *imported_name_prefix
;
5389 const char *canonical_name
;
5390 const char *import_alias
;
5391 const char *imported_declaration
= NULL
;
5392 const char *import_prefix
;
5393 VEC (const_char_ptr
) *excludes
= NULL
;
5394 struct cleanup
*cleanups
;
5398 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
5399 if (import_attr
== NULL
)
5401 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5402 dwarf_tag_name (die
->tag
));
5407 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
5408 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5409 if (imported_name
== NULL
)
5411 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
5413 The import in the following code:
5427 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
5428 <52> DW_AT_decl_file : 1
5429 <53> DW_AT_decl_line : 6
5430 <54> DW_AT_import : <0x75>
5431 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
5433 <5b> DW_AT_decl_file : 1
5434 <5c> DW_AT_decl_line : 2
5435 <5d> DW_AT_type : <0x6e>
5437 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
5438 <76> DW_AT_byte_size : 4
5439 <77> DW_AT_encoding : 5 (signed)
5441 imports the wrong die ( 0x75 instead of 0x58 ).
5442 This case will be ignored until the gcc bug is fixed. */
5446 /* Figure out the local name after import. */
5447 import_alias
= dwarf2_name (die
, cu
);
5449 /* Figure out where the statement is being imported to. */
5450 import_prefix
= determine_prefix (die
, cu
);
5452 /* Figure out what the scope of the imported die is and prepend it
5453 to the name of the imported die. */
5454 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
5456 if (imported_die
->tag
!= DW_TAG_namespace
5457 && imported_die
->tag
!= DW_TAG_module
)
5459 imported_declaration
= imported_name
;
5460 canonical_name
= imported_name_prefix
;
5462 else if (strlen (imported_name_prefix
) > 0)
5464 temp
= alloca (strlen (imported_name_prefix
)
5465 + 2 + strlen (imported_name
) + 1);
5466 strcpy (temp
, imported_name_prefix
);
5467 strcat (temp
, "::");
5468 strcat (temp
, imported_name
);
5469 canonical_name
= temp
;
5472 canonical_name
= imported_name
;
5474 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
5476 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
5477 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
5478 child_die
= sibling_die (child_die
))
5480 /* DWARF-4: A Fortran use statement with a “rename list” may be
5481 represented by an imported module entry with an import attribute
5482 referring to the module and owned entries corresponding to those
5483 entities that are renamed as part of being imported. */
5485 if (child_die
->tag
!= DW_TAG_imported_declaration
)
5487 complaint (&symfile_complaints
,
5488 _("child DW_TAG_imported_declaration expected "
5489 "- DIE at 0x%x [in module %s]"),
5490 child_die
->offset
, objfile
->name
);
5494 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
5495 if (import_attr
== NULL
)
5497 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5498 dwarf_tag_name (child_die
->tag
));
5503 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
5505 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5506 if (imported_name
== NULL
)
5508 complaint (&symfile_complaints
,
5509 _("child DW_TAG_imported_declaration has unknown "
5510 "imported name - DIE at 0x%x [in module %s]"),
5511 child_die
->offset
, objfile
->name
);
5515 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
5517 process_die (child_die
, cu
);
5520 cp_add_using_directive (import_prefix
,
5523 imported_declaration
,
5525 &objfile
->objfile_obstack
);
5527 do_cleanups (cleanups
);
5530 /* Cleanup function for read_file_scope. */
5533 free_cu_line_header (void *arg
)
5535 struct dwarf2_cu
*cu
= arg
;
5537 free_line_header (cu
->line_header
);
5538 cu
->line_header
= NULL
;
5542 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
5543 char **name
, char **comp_dir
)
5545 struct attribute
*attr
;
5550 /* Find the filename. Do not use dwarf2_name here, since the filename
5551 is not a source language identifier. */
5552 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5555 *name
= DW_STRING (attr
);
5558 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5560 *comp_dir
= DW_STRING (attr
);
5561 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
5563 *comp_dir
= ldirname (*name
);
5564 if (*comp_dir
!= NULL
)
5565 make_cleanup (xfree
, *comp_dir
);
5567 if (*comp_dir
!= NULL
)
5569 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5570 directory, get rid of it. */
5571 char *cp
= strchr (*comp_dir
, ':');
5573 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
5578 *name
= "<unknown>";
5581 /* Handle DW_AT_stmt_list for a compilation unit or type unit.
5582 DIE is the DW_TAG_compile_unit or DW_TAG_type_unit die for CU.
5583 COMP_DIR is the compilation directory.
5584 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
5587 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
5588 const char *comp_dir
, int want_line_info
)
5590 struct attribute
*attr
;
5591 struct objfile
*objfile
= cu
->objfile
;
5592 bfd
*abfd
= objfile
->obfd
;
5594 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5597 unsigned int line_offset
= DW_UNSND (attr
);
5598 struct line_header
*line_header
5599 = dwarf_decode_line_header (line_offset
, abfd
, cu
);
5603 cu
->line_header
= line_header
;
5604 make_cleanup (free_cu_line_header
, cu
);
5605 dwarf_decode_lines (line_header
, comp_dir
, cu
, NULL
, want_line_info
);
5610 /* Process DW_TAG_compile_unit. */
5613 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5615 struct objfile
*objfile
= cu
->objfile
;
5616 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5617 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
5618 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
5619 struct attribute
*attr
;
5621 char *comp_dir
= NULL
;
5622 struct die_info
*child_die
;
5623 bfd
*abfd
= objfile
->obfd
;
5626 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5628 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
5630 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5631 from finish_block. */
5632 if (lowpc
== ((CORE_ADDR
) -1))
5637 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
5639 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5642 set_cu_language (DW_UNSND (attr
), cu
);
5645 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5647 cu
->producer
= DW_STRING (attr
);
5649 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
5650 standardised yet. As a workaround for the language detection we fall
5651 back to the DW_AT_producer string. */
5652 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
5653 cu
->language
= language_opencl
;
5655 /* We assume that we're processing GCC output. */
5656 processing_gcc_compilation
= 2;
5658 processing_has_namespace_info
= 0;
5660 start_symtab (name
, comp_dir
, lowpc
);
5661 record_debugformat ("DWARF 2");
5662 record_producer (cu
->producer
);
5664 /* Decode line number information if present. We do this before
5665 processing child DIEs, so that the line header table is available
5666 for DW_AT_decl_file. */
5667 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, 1);
5669 /* Process all dies in compilation unit. */
5670 if (die
->child
!= NULL
)
5672 child_die
= die
->child
;
5673 while (child_die
&& child_die
->tag
)
5675 process_die (child_die
, cu
);
5676 child_die
= sibling_die (child_die
);
5680 /* Decode macro information, if present. Dwarf 2 macro information
5681 refers to information in the line number info statement program
5682 header, so we can only read it if we've read the header
5684 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
5685 if (attr
&& cu
->line_header
)
5687 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
5688 complaint (&symfile_complaints
,
5689 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
5691 dwarf_decode_macros (cu
->line_header
, DW_UNSND (attr
),
5693 &dwarf2_per_objfile
->macro
, 1);
5697 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
5698 if (attr
&& cu
->line_header
)
5700 unsigned int macro_offset
= DW_UNSND (attr
);
5702 dwarf_decode_macros (cu
->line_header
, macro_offset
,
5704 &dwarf2_per_objfile
->macinfo
, 0);
5708 do_cleanups (back_to
);
5711 /* Process DW_TAG_type_unit.
5712 For TUs we want to skip the first top level sibling if it's not the
5713 actual type being defined by this TU. In this case the first top
5714 level sibling is there to provide context only. */
5717 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5719 struct objfile
*objfile
= cu
->objfile
;
5720 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5722 struct attribute
*attr
;
5724 char *comp_dir
= NULL
;
5725 struct die_info
*child_die
;
5726 bfd
*abfd
= objfile
->obfd
;
5728 /* start_symtab needs a low pc, but we don't really have one.
5729 Do what read_file_scope would do in the absence of such info. */
5730 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5732 /* Find the filename. Do not use dwarf2_name here, since the filename
5733 is not a source language identifier. */
5734 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5736 name
= DW_STRING (attr
);
5738 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5740 comp_dir
= DW_STRING (attr
);
5741 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
5743 comp_dir
= ldirname (name
);
5744 if (comp_dir
!= NULL
)
5745 make_cleanup (xfree
, comp_dir
);
5751 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5753 set_cu_language (DW_UNSND (attr
), cu
);
5755 /* This isn't technically needed today. It is done for symmetry
5756 with read_file_scope. */
5757 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5759 cu
->producer
= DW_STRING (attr
);
5761 /* We assume that we're processing GCC output. */
5762 processing_gcc_compilation
= 2;
5764 processing_has_namespace_info
= 0;
5766 start_symtab (name
, comp_dir
, lowpc
);
5767 record_debugformat ("DWARF 2");
5768 record_producer (cu
->producer
);
5770 /* Decode line number information if present. We do this before
5771 processing child DIEs, so that the line header table is available
5772 for DW_AT_decl_file.
5773 We don't need the pc/line-number mapping for type units. */
5774 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, 0);
5776 /* Process the dies in the type unit. */
5777 if (die
->child
== NULL
)
5779 dump_die_for_error (die
);
5780 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5781 bfd_get_filename (abfd
));
5784 child_die
= die
->child
;
5786 while (child_die
&& child_die
->tag
)
5788 process_die (child_die
, cu
);
5790 child_die
= sibling_die (child_die
);
5793 do_cleanups (back_to
);
5796 /* qsort helper for inherit_abstract_dies. */
5799 unsigned_int_compar (const void *ap
, const void *bp
)
5801 unsigned int a
= *(unsigned int *) ap
;
5802 unsigned int b
= *(unsigned int *) bp
;
5804 return (a
> b
) - (b
> a
);
5807 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5808 Inherit only the children of the DW_AT_abstract_origin DIE not being
5809 already referenced by DW_AT_abstract_origin from the children of the
5813 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
5815 struct die_info
*child_die
;
5816 unsigned die_children_count
;
5817 /* CU offsets which were referenced by children of the current DIE. */
5819 unsigned *offsets_end
, *offsetp
;
5820 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5821 struct die_info
*origin_die
;
5822 /* Iterator of the ORIGIN_DIE children. */
5823 struct die_info
*origin_child_die
;
5824 struct cleanup
*cleanups
;
5825 struct attribute
*attr
;
5826 struct dwarf2_cu
*origin_cu
;
5827 struct pending
**origin_previous_list_in_scope
;
5829 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
5833 /* Note that following die references may follow to a die in a
5837 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
5839 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5841 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
5842 origin_cu
->list_in_scope
= cu
->list_in_scope
;
5844 if (die
->tag
!= origin_die
->tag
5845 && !(die
->tag
== DW_TAG_inlined_subroutine
5846 && origin_die
->tag
== DW_TAG_subprogram
))
5847 complaint (&symfile_complaints
,
5848 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5849 die
->offset
, origin_die
->offset
);
5851 child_die
= die
->child
;
5852 die_children_count
= 0;
5853 while (child_die
&& child_die
->tag
)
5855 child_die
= sibling_die (child_die
);
5856 die_children_count
++;
5858 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
5859 cleanups
= make_cleanup (xfree
, offsets
);
5861 offsets_end
= offsets
;
5862 child_die
= die
->child
;
5863 while (child_die
&& child_die
->tag
)
5865 /* For each CHILD_DIE, find the corresponding child of
5866 ORIGIN_DIE. If there is more than one layer of
5867 DW_AT_abstract_origin, follow them all; there shouldn't be,
5868 but GCC versions at least through 4.4 generate this (GCC PR
5870 struct die_info
*child_origin_die
= child_die
;
5871 struct dwarf2_cu
*child_origin_cu
= cu
;
5875 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
5879 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
5883 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5884 counterpart may exist. */
5885 if (child_origin_die
!= child_die
)
5887 if (child_die
->tag
!= child_origin_die
->tag
5888 && !(child_die
->tag
== DW_TAG_inlined_subroutine
5889 && child_origin_die
->tag
== DW_TAG_subprogram
))
5890 complaint (&symfile_complaints
,
5891 _("Child DIE 0x%x and its abstract origin 0x%x have "
5892 "different tags"), child_die
->offset
,
5893 child_origin_die
->offset
);
5894 if (child_origin_die
->parent
!= origin_die
)
5895 complaint (&symfile_complaints
,
5896 _("Child DIE 0x%x and its abstract origin 0x%x have "
5897 "different parents"), child_die
->offset
,
5898 child_origin_die
->offset
);
5900 *offsets_end
++ = child_origin_die
->offset
;
5902 child_die
= sibling_die (child_die
);
5904 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
5905 unsigned_int_compar
);
5906 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
5907 if (offsetp
[-1] == *offsetp
)
5908 complaint (&symfile_complaints
,
5909 _("Multiple children of DIE 0x%x refer "
5910 "to DIE 0x%x as their abstract origin"),
5911 die
->offset
, *offsetp
);
5914 origin_child_die
= origin_die
->child
;
5915 while (origin_child_die
&& origin_child_die
->tag
)
5917 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5918 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
5920 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
5922 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5923 process_die (origin_child_die
, origin_cu
);
5925 origin_child_die
= sibling_die (origin_child_die
);
5927 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
5929 do_cleanups (cleanups
);
5933 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5935 struct objfile
*objfile
= cu
->objfile
;
5936 struct context_stack
*new;
5939 struct die_info
*child_die
;
5940 struct attribute
*attr
, *call_line
, *call_file
;
5943 struct block
*block
;
5944 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
5945 VEC (symbolp
) *template_args
= NULL
;
5946 struct template_symbol
*templ_func
= NULL
;
5950 /* If we do not have call site information, we can't show the
5951 caller of this inlined function. That's too confusing, so
5952 only use the scope for local variables. */
5953 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
5954 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
5955 if (call_line
== NULL
|| call_file
== NULL
)
5957 read_lexical_block_scope (die
, cu
);
5962 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5964 name
= dwarf2_name (die
, cu
);
5966 /* Ignore functions with missing or empty names. These are actually
5967 illegal according to the DWARF standard. */
5970 complaint (&symfile_complaints
,
5971 _("missing name for subprogram DIE at %d"), die
->offset
);
5975 /* Ignore functions with missing or invalid low and high pc attributes. */
5976 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5978 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5979 if (!attr
|| !DW_UNSND (attr
))
5980 complaint (&symfile_complaints
,
5981 _("cannot get low and high bounds "
5982 "for subprogram DIE at %d"),
5990 /* If we have any template arguments, then we must allocate a
5991 different sort of symbol. */
5992 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
5994 if (child_die
->tag
== DW_TAG_template_type_param
5995 || child_die
->tag
== DW_TAG_template_value_param
)
5997 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5998 struct template_symbol
);
5999 templ_func
->base
.is_cplus_template_function
= 1;
6004 new = push_context (0, lowpc
);
6005 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
6006 (struct symbol
*) templ_func
);
6008 /* If there is a location expression for DW_AT_frame_base, record
6010 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
6012 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
6013 expression is being recorded directly in the function's symbol
6014 and not in a separate frame-base object. I guess this hack is
6015 to avoid adding some sort of frame-base adjunct/annex to the
6016 function's symbol :-(. The problem with doing this is that it
6017 results in a function symbol with a location expression that
6018 has nothing to do with the location of the function, ouch! The
6019 relationship should be: a function's symbol has-a frame base; a
6020 frame-base has-a location expression. */
6021 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
6023 cu
->list_in_scope
= &local_symbols
;
6025 if (die
->child
!= NULL
)
6027 child_die
= die
->child
;
6028 while (child_die
&& child_die
->tag
)
6030 if (child_die
->tag
== DW_TAG_template_type_param
6031 || child_die
->tag
== DW_TAG_template_value_param
)
6033 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
6036 VEC_safe_push (symbolp
, template_args
, arg
);
6039 process_die (child_die
, cu
);
6040 child_die
= sibling_die (child_die
);
6044 inherit_abstract_dies (die
, cu
);
6046 /* If we have a DW_AT_specification, we might need to import using
6047 directives from the context of the specification DIE. See the
6048 comment in determine_prefix. */
6049 if (cu
->language
== language_cplus
6050 && dwarf2_attr (die
, DW_AT_specification
, cu
))
6052 struct dwarf2_cu
*spec_cu
= cu
;
6053 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
6057 child_die
= spec_die
->child
;
6058 while (child_die
&& child_die
->tag
)
6060 if (child_die
->tag
== DW_TAG_imported_module
)
6061 process_die (child_die
, spec_cu
);
6062 child_die
= sibling_die (child_die
);
6065 /* In some cases, GCC generates specification DIEs that
6066 themselves contain DW_AT_specification attributes. */
6067 spec_die
= die_specification (spec_die
, &spec_cu
);
6071 new = pop_context ();
6072 /* Make a block for the local symbols within. */
6073 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
6074 lowpc
, highpc
, objfile
);
6076 /* For C++, set the block's scope. */
6077 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
6078 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
6079 determine_prefix (die
, cu
),
6080 processing_has_namespace_info
);
6082 /* If we have address ranges, record them. */
6083 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
6085 /* Attach template arguments to function. */
6086 if (! VEC_empty (symbolp
, template_args
))
6088 gdb_assert (templ_func
!= NULL
);
6090 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
6091 templ_func
->template_arguments
6092 = obstack_alloc (&objfile
->objfile_obstack
,
6093 (templ_func
->n_template_arguments
6094 * sizeof (struct symbol
*)));
6095 memcpy (templ_func
->template_arguments
,
6096 VEC_address (symbolp
, template_args
),
6097 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
6098 VEC_free (symbolp
, template_args
);
6101 /* In C++, we can have functions nested inside functions (e.g., when
6102 a function declares a class that has methods). This means that
6103 when we finish processing a function scope, we may need to go
6104 back to building a containing block's symbol lists. */
6105 local_symbols
= new->locals
;
6106 param_symbols
= new->params
;
6107 using_directives
= new->using_directives
;
6109 /* If we've finished processing a top-level function, subsequent
6110 symbols go in the file symbol list. */
6111 if (outermost_context_p ())
6112 cu
->list_in_scope
= &file_symbols
;
6115 /* Process all the DIES contained within a lexical block scope. Start
6116 a new scope, process the dies, and then close the scope. */
6119 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6121 struct objfile
*objfile
= cu
->objfile
;
6122 struct context_stack
*new;
6123 CORE_ADDR lowpc
, highpc
;
6124 struct die_info
*child_die
;
6127 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6129 /* Ignore blocks with missing or invalid low and high pc attributes. */
6130 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
6131 as multiple lexical blocks? Handling children in a sane way would
6132 be nasty. Might be easier to properly extend generic blocks to
6134 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
6139 push_context (0, lowpc
);
6140 if (die
->child
!= NULL
)
6142 child_die
= die
->child
;
6143 while (child_die
&& child_die
->tag
)
6145 process_die (child_die
, cu
);
6146 child_die
= sibling_die (child_die
);
6149 new = pop_context ();
6151 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
6154 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
6157 /* Note that recording ranges after traversing children, as we
6158 do here, means that recording a parent's ranges entails
6159 walking across all its children's ranges as they appear in
6160 the address map, which is quadratic behavior.
6162 It would be nicer to record the parent's ranges before
6163 traversing its children, simply overriding whatever you find
6164 there. But since we don't even decide whether to create a
6165 block until after we've traversed its children, that's hard
6167 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
6169 local_symbols
= new->locals
;
6170 using_directives
= new->using_directives
;
6173 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
6176 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6178 struct objfile
*objfile
= cu
->objfile
;
6179 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6180 CORE_ADDR pc
, baseaddr
;
6181 struct attribute
*attr
;
6182 struct call_site
*call_site
, call_site_local
;
6185 struct die_info
*child_die
;
6187 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6189 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6192 complaint (&symfile_complaints
,
6193 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
6194 "DIE 0x%x [in module %s]"),
6195 die
->offset
, objfile
->name
);
6198 pc
= DW_ADDR (attr
) + baseaddr
;
6200 if (cu
->call_site_htab
== NULL
)
6201 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
6202 NULL
, &objfile
->objfile_obstack
,
6203 hashtab_obstack_allocate
, NULL
);
6204 call_site_local
.pc
= pc
;
6205 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
6208 complaint (&symfile_complaints
,
6209 _("Duplicate PC %s for DW_TAG_GNU_call_site "
6210 "DIE 0x%x [in module %s]"),
6211 paddress (gdbarch
, pc
), die
->offset
, objfile
->name
);
6215 /* Count parameters at the caller. */
6218 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
6219 child_die
= sibling_die (child_die
))
6221 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
6223 complaint (&symfile_complaints
,
6224 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
6225 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6226 child_die
->tag
, child_die
->offset
, objfile
->name
);
6233 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
6234 (sizeof (*call_site
)
6235 + (sizeof (*call_site
->parameter
)
6238 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
6241 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
6243 struct die_info
*func_die
;
6245 /* Skip also over DW_TAG_inlined_subroutine. */
6246 for (func_die
= die
->parent
;
6247 func_die
&& func_die
->tag
!= DW_TAG_subprogram
6248 && func_die
->tag
!= DW_TAG_subroutine_type
;
6249 func_die
= func_die
->parent
);
6251 /* DW_AT_GNU_all_call_sites is a superset
6252 of DW_AT_GNU_all_tail_call_sites. */
6254 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
6255 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
6257 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
6258 not complete. But keep CALL_SITE for look ups via call_site_htab,
6259 both the initial caller containing the real return address PC and
6260 the final callee containing the current PC of a chain of tail
6261 calls do not need to have the tail call list complete. But any
6262 function candidate for a virtual tail call frame searched via
6263 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
6264 determined unambiguously. */
6268 struct type
*func_type
= NULL
;
6271 func_type
= get_die_type (func_die
, cu
);
6272 if (func_type
!= NULL
)
6274 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
6276 /* Enlist this call site to the function. */
6277 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
6278 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
6281 complaint (&symfile_complaints
,
6282 _("Cannot find function owning DW_TAG_GNU_call_site "
6283 "DIE 0x%x [in module %s]"),
6284 die
->offset
, objfile
->name
);
6288 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
6290 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
6291 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
6292 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
6293 /* Keep NULL DWARF_BLOCK. */;
6294 else if (attr_form_is_block (attr
))
6296 struct dwarf2_locexpr_baton
*dlbaton
;
6298 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
6299 dlbaton
->data
= DW_BLOCK (attr
)->data
;
6300 dlbaton
->size
= DW_BLOCK (attr
)->size
;
6301 dlbaton
->per_cu
= cu
->per_cu
;
6303 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
6305 else if (is_ref_attr (attr
))
6307 struct dwarf2_cu
*target_cu
= cu
;
6308 struct die_info
*target_die
;
6310 target_die
= follow_die_ref_or_sig (die
, attr
, &target_cu
);
6311 gdb_assert (target_cu
->objfile
== objfile
);
6312 if (die_is_declaration (target_die
, target_cu
))
6314 const char *target_physname
;
6316 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
6317 if (target_physname
== NULL
)
6318 complaint (&symfile_complaints
,
6319 _("DW_AT_GNU_call_site_target target DIE has invalid "
6320 "physname, for referencing DIE 0x%x [in module %s]"),
6321 die
->offset
, objfile
->name
);
6323 SET_FIELD_PHYSNAME (call_site
->target
, (char *) target_physname
);
6329 /* DW_AT_entry_pc should be preferred. */
6330 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
6331 complaint (&symfile_complaints
,
6332 _("DW_AT_GNU_call_site_target target DIE has invalid "
6333 "low pc, for referencing DIE 0x%x [in module %s]"),
6334 die
->offset
, objfile
->name
);
6336 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
6340 complaint (&symfile_complaints
,
6341 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
6342 "block nor reference, for DIE 0x%x [in module %s]"),
6343 die
->offset
, objfile
->name
);
6345 call_site
->per_cu
= cu
->per_cu
;
6347 for (child_die
= die
->child
;
6348 child_die
&& child_die
->tag
;
6349 child_die
= sibling_die (child_die
))
6351 struct dwarf2_locexpr_baton
*dlbaton
;
6352 struct call_site_parameter
*parameter
;
6354 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
6356 /* Already printed the complaint above. */
6360 gdb_assert (call_site
->parameter_count
< nparams
);
6361 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
6363 /* DW_AT_location specifies the register number. Value of the data
6364 assumed for the register is contained in DW_AT_GNU_call_site_value. */
6366 attr
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
6367 if (!attr
|| !attr_form_is_block (attr
))
6369 complaint (&symfile_complaints
,
6370 _("No DW_FORM_block* DW_AT_location for "
6371 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6372 child_die
->offset
, objfile
->name
);
6375 parameter
->dwarf_reg
= dwarf_block_to_dwarf_reg (DW_BLOCK (attr
)->data
,
6376 &DW_BLOCK (attr
)->data
[DW_BLOCK (attr
)->size
]);
6377 if (parameter
->dwarf_reg
== -1
6378 && !dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (attr
)->data
,
6379 &DW_BLOCK (attr
)->data
[DW_BLOCK (attr
)->size
],
6380 ¶meter
->fb_offset
))
6382 complaint (&symfile_complaints
,
6383 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
6384 "for DW_FORM_block* DW_AT_location for "
6385 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6386 child_die
->offset
, objfile
->name
);
6390 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
6391 if (!attr_form_is_block (attr
))
6393 complaint (&symfile_complaints
,
6394 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
6395 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6396 child_die
->offset
, objfile
->name
);
6399 parameter
->value
= DW_BLOCK (attr
)->data
;
6400 parameter
->value_size
= DW_BLOCK (attr
)->size
;
6402 /* Parameters are not pre-cleared by memset above. */
6403 parameter
->data_value
= NULL
;
6404 parameter
->data_value_size
= 0;
6405 call_site
->parameter_count
++;
6407 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
6410 if (!attr_form_is_block (attr
))
6411 complaint (&symfile_complaints
,
6412 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
6413 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6414 child_die
->offset
, objfile
->name
);
6417 parameter
->data_value
= DW_BLOCK (attr
)->data
;
6418 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
6424 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
6425 Return 1 if the attributes are present and valid, otherwise, return 0.
6426 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
6429 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
6430 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
6431 struct partial_symtab
*ranges_pst
)
6433 struct objfile
*objfile
= cu
->objfile
;
6434 struct comp_unit_head
*cu_header
= &cu
->header
;
6435 bfd
*obfd
= objfile
->obfd
;
6436 unsigned int addr_size
= cu_header
->addr_size
;
6437 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6438 /* Base address selection entry. */
6449 found_base
= cu
->base_known
;
6450 base
= cu
->base_address
;
6452 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
6453 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6455 complaint (&symfile_complaints
,
6456 _("Offset %d out of bounds for DW_AT_ranges attribute"),
6460 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6462 /* Read in the largest possible address. */
6463 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
6464 if ((marker
& mask
) == mask
)
6466 /* If we found the largest possible address, then
6467 read the base address. */
6468 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
6469 buffer
+= 2 * addr_size
;
6470 offset
+= 2 * addr_size
;
6476 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6480 CORE_ADDR range_beginning
, range_end
;
6482 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
6483 buffer
+= addr_size
;
6484 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
6485 buffer
+= addr_size
;
6486 offset
+= 2 * addr_size
;
6488 /* An end of list marker is a pair of zero addresses. */
6489 if (range_beginning
== 0 && range_end
== 0)
6490 /* Found the end of list entry. */
6493 /* Each base address selection entry is a pair of 2 values.
6494 The first is the largest possible address, the second is
6495 the base address. Check for a base address here. */
6496 if ((range_beginning
& mask
) == mask
)
6498 /* If we found the largest possible address, then
6499 read the base address. */
6500 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
6507 /* We have no valid base address for the ranges
6509 complaint (&symfile_complaints
,
6510 _("Invalid .debug_ranges data (no base address)"));
6514 if (range_beginning
> range_end
)
6516 /* Inverted range entries are invalid. */
6517 complaint (&symfile_complaints
,
6518 _("Invalid .debug_ranges data (inverted range)"));
6522 /* Empty range entries have no effect. */
6523 if (range_beginning
== range_end
)
6526 range_beginning
+= base
;
6529 if (ranges_pst
!= NULL
)
6530 addrmap_set_empty (objfile
->psymtabs_addrmap
,
6531 range_beginning
+ baseaddr
,
6532 range_end
- 1 + baseaddr
,
6535 /* FIXME: This is recording everything as a low-high
6536 segment of consecutive addresses. We should have a
6537 data structure for discontiguous block ranges
6541 low
= range_beginning
;
6547 if (range_beginning
< low
)
6548 low
= range_beginning
;
6549 if (range_end
> high
)
6555 /* If the first entry is an end-of-list marker, the range
6556 describes an empty scope, i.e. no instructions. */
6562 *high_return
= high
;
6566 /* Get low and high pc attributes from a die. Return 1 if the attributes
6567 are present and valid, otherwise, return 0. Return -1 if the range is
6568 discontinuous, i.e. derived from DW_AT_ranges information. */
6570 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
6571 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
6572 struct partial_symtab
*pst
)
6574 struct attribute
*attr
;
6579 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6582 high
= DW_ADDR (attr
);
6583 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6585 low
= DW_ADDR (attr
);
6587 /* Found high w/o low attribute. */
6590 /* Found consecutive range of addresses. */
6595 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6598 /* Value of the DW_AT_ranges attribute is the offset in the
6599 .debug_ranges section. */
6600 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
6602 /* Found discontinuous range of addresses. */
6607 /* read_partial_die has also the strict LOW < HIGH requirement. */
6611 /* When using the GNU linker, .gnu.linkonce. sections are used to
6612 eliminate duplicate copies of functions and vtables and such.
6613 The linker will arbitrarily choose one and discard the others.
6614 The AT_*_pc values for such functions refer to local labels in
6615 these sections. If the section from that file was discarded, the
6616 labels are not in the output, so the relocs get a value of 0.
6617 If this is a discarded function, mark the pc bounds as invalid,
6618 so that GDB will ignore it. */
6619 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
6628 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
6629 its low and high PC addresses. Do nothing if these addresses could not
6630 be determined. Otherwise, set LOWPC to the low address if it is smaller,
6631 and HIGHPC to the high address if greater than HIGHPC. */
6634 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
6635 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6636 struct dwarf2_cu
*cu
)
6638 CORE_ADDR low
, high
;
6639 struct die_info
*child
= die
->child
;
6641 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
6643 *lowpc
= min (*lowpc
, low
);
6644 *highpc
= max (*highpc
, high
);
6647 /* If the language does not allow nested subprograms (either inside
6648 subprograms or lexical blocks), we're done. */
6649 if (cu
->language
!= language_ada
)
6652 /* Check all the children of the given DIE. If it contains nested
6653 subprograms, then check their pc bounds. Likewise, we need to
6654 check lexical blocks as well, as they may also contain subprogram
6656 while (child
&& child
->tag
)
6658 if (child
->tag
== DW_TAG_subprogram
6659 || child
->tag
== DW_TAG_lexical_block
)
6660 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
6661 child
= sibling_die (child
);
6665 /* Get the low and high pc's represented by the scope DIE, and store
6666 them in *LOWPC and *HIGHPC. If the correct values can't be
6667 determined, set *LOWPC to -1 and *HIGHPC to 0. */
6670 get_scope_pc_bounds (struct die_info
*die
,
6671 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6672 struct dwarf2_cu
*cu
)
6674 CORE_ADDR best_low
= (CORE_ADDR
) -1;
6675 CORE_ADDR best_high
= (CORE_ADDR
) 0;
6676 CORE_ADDR current_low
, current_high
;
6678 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
6680 best_low
= current_low
;
6681 best_high
= current_high
;
6685 struct die_info
*child
= die
->child
;
6687 while (child
&& child
->tag
)
6689 switch (child
->tag
) {
6690 case DW_TAG_subprogram
:
6691 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
6693 case DW_TAG_namespace
:
6695 /* FIXME: carlton/2004-01-16: Should we do this for
6696 DW_TAG_class_type/DW_TAG_structure_type, too? I think
6697 that current GCC's always emit the DIEs corresponding
6698 to definitions of methods of classes as children of a
6699 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
6700 the DIEs giving the declarations, which could be
6701 anywhere). But I don't see any reason why the
6702 standards says that they have to be there. */
6703 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
6705 if (current_low
!= ((CORE_ADDR
) -1))
6707 best_low
= min (best_low
, current_low
);
6708 best_high
= max (best_high
, current_high
);
6716 child
= sibling_die (child
);
6721 *highpc
= best_high
;
6724 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
6727 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
6728 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
6730 struct objfile
*objfile
= cu
->objfile
;
6731 struct attribute
*attr
;
6733 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6736 CORE_ADDR high
= DW_ADDR (attr
);
6738 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6741 CORE_ADDR low
= DW_ADDR (attr
);
6743 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
6747 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6750 bfd
*obfd
= objfile
->obfd
;
6752 /* The value of the DW_AT_ranges attribute is the offset of the
6753 address range list in the .debug_ranges section. */
6754 unsigned long offset
= DW_UNSND (attr
);
6755 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6757 /* For some target architectures, but not others, the
6758 read_address function sign-extends the addresses it returns.
6759 To recognize base address selection entries, we need a
6761 unsigned int addr_size
= cu
->header
.addr_size
;
6762 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6764 /* The base address, to which the next pair is relative. Note
6765 that this 'base' is a DWARF concept: most entries in a range
6766 list are relative, to reduce the number of relocs against the
6767 debugging information. This is separate from this function's
6768 'baseaddr' argument, which GDB uses to relocate debugging
6769 information from a shared library based on the address at
6770 which the library was loaded. */
6771 CORE_ADDR base
= cu
->base_address
;
6772 int base_known
= cu
->base_known
;
6774 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
6775 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6777 complaint (&symfile_complaints
,
6778 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
6785 unsigned int bytes_read
;
6786 CORE_ADDR start
, end
;
6788 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6789 buffer
+= bytes_read
;
6790 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6791 buffer
+= bytes_read
;
6793 /* Did we find the end of the range list? */
6794 if (start
== 0 && end
== 0)
6797 /* Did we find a base address selection entry? */
6798 else if ((start
& base_select_mask
) == base_select_mask
)
6804 /* We found an ordinary address range. */
6809 complaint (&symfile_complaints
,
6810 _("Invalid .debug_ranges data "
6811 "(no base address)"));
6817 /* Inverted range entries are invalid. */
6818 complaint (&symfile_complaints
,
6819 _("Invalid .debug_ranges data "
6820 "(inverted range)"));
6824 /* Empty range entries have no effect. */
6828 record_block_range (block
,
6829 baseaddr
+ base
+ start
,
6830 baseaddr
+ base
+ end
- 1);
6836 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
6837 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
6838 during 4.6.0 experimental. */
6841 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
6844 int major
, minor
, release
;
6846 if (cu
->producer
== NULL
)
6848 /* For unknown compilers expect their behavior is DWARF version
6851 GCC started to support .debug_types sections by -gdwarf-4 since
6852 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
6853 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
6854 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
6855 interpreted incorrectly by GDB now - GCC PR debug/48229. */
6860 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
6862 if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) != 0)
6864 /* For non-GCC compilers expect their behavior is DWARF version
6869 cs
= &cu
->producer
[strlen ("GNU ")];
6870 while (*cs
&& !isdigit (*cs
))
6872 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
6874 /* Not recognized as GCC. */
6879 return major
< 4 || (major
== 4 && minor
< 6);
6882 /* Return the default accessibility type if it is not overriden by
6883 DW_AT_accessibility. */
6885 static enum dwarf_access_attribute
6886 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
6888 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
6890 /* The default DWARF 2 accessibility for members is public, the default
6891 accessibility for inheritance is private. */
6893 if (die
->tag
!= DW_TAG_inheritance
)
6894 return DW_ACCESS_public
;
6896 return DW_ACCESS_private
;
6900 /* DWARF 3+ defines the default accessibility a different way. The same
6901 rules apply now for DW_TAG_inheritance as for the members and it only
6902 depends on the container kind. */
6904 if (die
->parent
->tag
== DW_TAG_class_type
)
6905 return DW_ACCESS_private
;
6907 return DW_ACCESS_public
;
6911 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
6912 offset. If the attribute was not found return 0, otherwise return
6913 1. If it was found but could not properly be handled, set *OFFSET
6917 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
6920 struct attribute
*attr
;
6922 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6927 /* Note that we do not check for a section offset first here.
6928 This is because DW_AT_data_member_location is new in DWARF 4,
6929 so if we see it, we can assume that a constant form is really
6930 a constant and not a section offset. */
6931 if (attr_form_is_constant (attr
))
6932 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
6933 else if (attr_form_is_section_offset (attr
))
6934 dwarf2_complex_location_expr_complaint ();
6935 else if (attr_form_is_block (attr
))
6936 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6938 dwarf2_complex_location_expr_complaint ();
6946 /* Add an aggregate field to the field list. */
6949 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
6950 struct dwarf2_cu
*cu
)
6952 struct objfile
*objfile
= cu
->objfile
;
6953 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6954 struct nextfield
*new_field
;
6955 struct attribute
*attr
;
6957 char *fieldname
= "";
6959 /* Allocate a new field list entry and link it in. */
6960 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
6961 make_cleanup (xfree
, new_field
);
6962 memset (new_field
, 0, sizeof (struct nextfield
));
6964 if (die
->tag
== DW_TAG_inheritance
)
6966 new_field
->next
= fip
->baseclasses
;
6967 fip
->baseclasses
= new_field
;
6971 new_field
->next
= fip
->fields
;
6972 fip
->fields
= new_field
;
6976 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6978 new_field
->accessibility
= DW_UNSND (attr
);
6980 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
6981 if (new_field
->accessibility
!= DW_ACCESS_public
)
6982 fip
->non_public_fields
= 1;
6984 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6986 new_field
->virtuality
= DW_UNSND (attr
);
6988 new_field
->virtuality
= DW_VIRTUALITY_none
;
6990 fp
= &new_field
->field
;
6992 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
6996 /* Data member other than a C++ static data member. */
6998 /* Get type of field. */
6999 fp
->type
= die_type (die
, cu
);
7001 SET_FIELD_BITPOS (*fp
, 0);
7003 /* Get bit size of field (zero if none). */
7004 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
7007 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
7011 FIELD_BITSIZE (*fp
) = 0;
7014 /* Get bit offset of field. */
7015 if (handle_data_member_location (die
, cu
, &offset
))
7016 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
7017 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
7020 if (gdbarch_bits_big_endian (gdbarch
))
7022 /* For big endian bits, the DW_AT_bit_offset gives the
7023 additional bit offset from the MSB of the containing
7024 anonymous object to the MSB of the field. We don't
7025 have to do anything special since we don't need to
7026 know the size of the anonymous object. */
7027 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
7031 /* For little endian bits, compute the bit offset to the
7032 MSB of the anonymous object, subtract off the number of
7033 bits from the MSB of the field to the MSB of the
7034 object, and then subtract off the number of bits of
7035 the field itself. The result is the bit offset of
7036 the LSB of the field. */
7038 int bit_offset
= DW_UNSND (attr
);
7040 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7043 /* The size of the anonymous object containing
7044 the bit field is explicit, so use the
7045 indicated size (in bytes). */
7046 anonymous_size
= DW_UNSND (attr
);
7050 /* The size of the anonymous object containing
7051 the bit field must be inferred from the type
7052 attribute of the data member containing the
7054 anonymous_size
= TYPE_LENGTH (fp
->type
);
7056 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
7057 - bit_offset
- FIELD_BITSIZE (*fp
);
7061 /* Get name of field. */
7062 fieldname
= dwarf2_name (die
, cu
);
7063 if (fieldname
== NULL
)
7066 /* The name is already allocated along with this objfile, so we don't
7067 need to duplicate it for the type. */
7068 fp
->name
= fieldname
;
7070 /* Change accessibility for artificial fields (e.g. virtual table
7071 pointer or virtual base class pointer) to private. */
7072 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
7074 FIELD_ARTIFICIAL (*fp
) = 1;
7075 new_field
->accessibility
= DW_ACCESS_private
;
7076 fip
->non_public_fields
= 1;
7079 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
7081 /* C++ static member. */
7083 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
7084 is a declaration, but all versions of G++ as of this writing
7085 (so through at least 3.2.1) incorrectly generate
7086 DW_TAG_variable tags. */
7088 const char *physname
;
7090 /* Get name of field. */
7091 fieldname
= dwarf2_name (die
, cu
);
7092 if (fieldname
== NULL
)
7095 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7097 /* Only create a symbol if this is an external value.
7098 new_symbol checks this and puts the value in the global symbol
7099 table, which we want. If it is not external, new_symbol
7100 will try to put the value in cu->list_in_scope which is wrong. */
7101 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
7103 /* A static const member, not much different than an enum as far as
7104 we're concerned, except that we can support more types. */
7105 new_symbol (die
, NULL
, cu
);
7108 /* Get physical name. */
7109 physname
= dwarf2_physname (fieldname
, die
, cu
);
7111 /* The name is already allocated along with this objfile, so we don't
7112 need to duplicate it for the type. */
7113 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
7114 FIELD_TYPE (*fp
) = die_type (die
, cu
);
7115 FIELD_NAME (*fp
) = fieldname
;
7117 else if (die
->tag
== DW_TAG_inheritance
)
7121 /* C++ base class field. */
7122 if (handle_data_member_location (die
, cu
, &offset
))
7123 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
7124 FIELD_BITSIZE (*fp
) = 0;
7125 FIELD_TYPE (*fp
) = die_type (die
, cu
);
7126 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
7127 fip
->nbaseclasses
++;
7131 /* Add a typedef defined in the scope of the FIP's class. */
7134 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
7135 struct dwarf2_cu
*cu
)
7137 struct objfile
*objfile
= cu
->objfile
;
7138 struct typedef_field_list
*new_field
;
7139 struct attribute
*attr
;
7140 struct typedef_field
*fp
;
7141 char *fieldname
= "";
7143 /* Allocate a new field list entry and link it in. */
7144 new_field
= xzalloc (sizeof (*new_field
));
7145 make_cleanup (xfree
, new_field
);
7147 gdb_assert (die
->tag
== DW_TAG_typedef
);
7149 fp
= &new_field
->field
;
7151 /* Get name of field. */
7152 fp
->name
= dwarf2_name (die
, cu
);
7153 if (fp
->name
== NULL
)
7156 fp
->type
= read_type_die (die
, cu
);
7158 new_field
->next
= fip
->typedef_field_list
;
7159 fip
->typedef_field_list
= new_field
;
7160 fip
->typedef_field_list_count
++;
7163 /* Create the vector of fields, and attach it to the type. */
7166 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
7167 struct dwarf2_cu
*cu
)
7169 int nfields
= fip
->nfields
;
7171 /* Record the field count, allocate space for the array of fields,
7172 and create blank accessibility bitfields if necessary. */
7173 TYPE_NFIELDS (type
) = nfields
;
7174 TYPE_FIELDS (type
) = (struct field
*)
7175 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
7176 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
7178 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
7180 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7182 TYPE_FIELD_PRIVATE_BITS (type
) =
7183 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7184 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
7186 TYPE_FIELD_PROTECTED_BITS (type
) =
7187 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7188 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
7190 TYPE_FIELD_IGNORE_BITS (type
) =
7191 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7192 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
7195 /* If the type has baseclasses, allocate and clear a bit vector for
7196 TYPE_FIELD_VIRTUAL_BITS. */
7197 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
7199 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
7200 unsigned char *pointer
;
7202 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7203 pointer
= TYPE_ALLOC (type
, num_bytes
);
7204 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
7205 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
7206 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
7209 /* Copy the saved-up fields into the field vector. Start from the head of
7210 the list, adding to the tail of the field array, so that they end up in
7211 the same order in the array in which they were added to the list. */
7212 while (nfields
-- > 0)
7214 struct nextfield
*fieldp
;
7218 fieldp
= fip
->fields
;
7219 fip
->fields
= fieldp
->next
;
7223 fieldp
= fip
->baseclasses
;
7224 fip
->baseclasses
= fieldp
->next
;
7227 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
7228 switch (fieldp
->accessibility
)
7230 case DW_ACCESS_private
:
7231 if (cu
->language
!= language_ada
)
7232 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
7235 case DW_ACCESS_protected
:
7236 if (cu
->language
!= language_ada
)
7237 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
7240 case DW_ACCESS_public
:
7244 /* Unknown accessibility. Complain and treat it as public. */
7246 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
7247 fieldp
->accessibility
);
7251 if (nfields
< fip
->nbaseclasses
)
7253 switch (fieldp
->virtuality
)
7255 case DW_VIRTUALITY_virtual
:
7256 case DW_VIRTUALITY_pure_virtual
:
7257 if (cu
->language
== language_ada
)
7258 error (_("unexpected virtuality in component of Ada type"));
7259 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
7266 /* Add a member function to the proper fieldlist. */
7269 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
7270 struct type
*type
, struct dwarf2_cu
*cu
)
7272 struct objfile
*objfile
= cu
->objfile
;
7273 struct attribute
*attr
;
7274 struct fnfieldlist
*flp
;
7276 struct fn_field
*fnp
;
7278 struct nextfnfield
*new_fnfield
;
7279 struct type
*this_type
;
7280 enum dwarf_access_attribute accessibility
;
7282 if (cu
->language
== language_ada
)
7283 error (_("unexpected member function in Ada type"));
7285 /* Get name of member function. */
7286 fieldname
= dwarf2_name (die
, cu
);
7287 if (fieldname
== NULL
)
7290 /* Look up member function name in fieldlist. */
7291 for (i
= 0; i
< fip
->nfnfields
; i
++)
7293 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
7297 /* Create new list element if necessary. */
7298 if (i
< fip
->nfnfields
)
7299 flp
= &fip
->fnfieldlists
[i
];
7302 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7304 fip
->fnfieldlists
= (struct fnfieldlist
*)
7305 xrealloc (fip
->fnfieldlists
,
7306 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
7307 * sizeof (struct fnfieldlist
));
7308 if (fip
->nfnfields
== 0)
7309 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
7311 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
7312 flp
->name
= fieldname
;
7315 i
= fip
->nfnfields
++;
7318 /* Create a new member function field and chain it to the field list
7320 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
7321 make_cleanup (xfree
, new_fnfield
);
7322 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
7323 new_fnfield
->next
= flp
->head
;
7324 flp
->head
= new_fnfield
;
7327 /* Fill in the member function field info. */
7328 fnp
= &new_fnfield
->fnfield
;
7330 /* Delay processing of the physname until later. */
7331 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
7333 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
7338 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
7339 fnp
->physname
= physname
? physname
: "";
7342 fnp
->type
= alloc_type (objfile
);
7343 this_type
= read_type_die (die
, cu
);
7344 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
7346 int nparams
= TYPE_NFIELDS (this_type
);
7348 /* TYPE is the domain of this method, and THIS_TYPE is the type
7349 of the method itself (TYPE_CODE_METHOD). */
7350 smash_to_method_type (fnp
->type
, type
,
7351 TYPE_TARGET_TYPE (this_type
),
7352 TYPE_FIELDS (this_type
),
7353 TYPE_NFIELDS (this_type
),
7354 TYPE_VARARGS (this_type
));
7356 /* Handle static member functions.
7357 Dwarf2 has no clean way to discern C++ static and non-static
7358 member functions. G++ helps GDB by marking the first
7359 parameter for non-static member functions (which is the this
7360 pointer) as artificial. We obtain this information from
7361 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
7362 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
7363 fnp
->voffset
= VOFFSET_STATIC
;
7366 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
7367 dwarf2_full_name (fieldname
, die
, cu
));
7369 /* Get fcontext from DW_AT_containing_type if present. */
7370 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7371 fnp
->fcontext
= die_containing_type (die
, cu
);
7373 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
7374 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
7376 /* Get accessibility. */
7377 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
7379 accessibility
= DW_UNSND (attr
);
7381 accessibility
= dwarf2_default_access_attribute (die
, cu
);
7382 switch (accessibility
)
7384 case DW_ACCESS_private
:
7385 fnp
->is_private
= 1;
7387 case DW_ACCESS_protected
:
7388 fnp
->is_protected
= 1;
7392 /* Check for artificial methods. */
7393 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
7394 if (attr
&& DW_UNSND (attr
) != 0)
7395 fnp
->is_artificial
= 1;
7397 /* Get index in virtual function table if it is a virtual member
7398 function. For older versions of GCC, this is an offset in the
7399 appropriate virtual table, as specified by DW_AT_containing_type.
7400 For everyone else, it is an expression to be evaluated relative
7401 to the object address. */
7403 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
7406 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
7408 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
7410 /* Old-style GCC. */
7411 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
7413 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
7414 || (DW_BLOCK (attr
)->size
> 1
7415 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
7416 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
7418 struct dwarf_block blk
;
7421 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
7423 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
7424 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
7425 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
7426 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
7427 dwarf2_complex_location_expr_complaint ();
7429 fnp
->voffset
/= cu
->header
.addr_size
;
7433 dwarf2_complex_location_expr_complaint ();
7436 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
7438 else if (attr_form_is_section_offset (attr
))
7440 dwarf2_complex_location_expr_complaint ();
7444 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
7450 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
7451 if (attr
&& DW_UNSND (attr
))
7453 /* GCC does this, as of 2008-08-25; PR debug/37237. */
7454 complaint (&symfile_complaints
,
7455 _("Member function \"%s\" (offset %d) is virtual "
7456 "but the vtable offset is not specified"),
7457 fieldname
, die
->offset
);
7458 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7459 TYPE_CPLUS_DYNAMIC (type
) = 1;
7464 /* Create the vector of member function fields, and attach it to the type. */
7467 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
7468 struct dwarf2_cu
*cu
)
7470 struct fnfieldlist
*flp
;
7473 if (cu
->language
== language_ada
)
7474 error (_("unexpected member functions in Ada type"));
7476 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7477 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
7478 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
7480 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
7482 struct nextfnfield
*nfp
= flp
->head
;
7483 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
7486 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
7487 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
7488 fn_flp
->fn_fields
= (struct fn_field
*)
7489 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
7490 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
7491 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
7494 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
7497 /* Returns non-zero if NAME is the name of a vtable member in CU's
7498 language, zero otherwise. */
7500 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
7502 static const char vptr
[] = "_vptr";
7503 static const char vtable
[] = "vtable";
7505 /* Look for the C++ and Java forms of the vtable. */
7506 if ((cu
->language
== language_java
7507 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
7508 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
7509 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
7515 /* GCC outputs unnamed structures that are really pointers to member
7516 functions, with the ABI-specified layout. If TYPE describes
7517 such a structure, smash it into a member function type.
7519 GCC shouldn't do this; it should just output pointer to member DIEs.
7520 This is GCC PR debug/28767. */
7523 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
7525 struct type
*pfn_type
, *domain_type
, *new_type
;
7527 /* Check for a structure with no name and two children. */
7528 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
7531 /* Check for __pfn and __delta members. */
7532 if (TYPE_FIELD_NAME (type
, 0) == NULL
7533 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
7534 || TYPE_FIELD_NAME (type
, 1) == NULL
7535 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
7538 /* Find the type of the method. */
7539 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
7540 if (pfn_type
== NULL
7541 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
7542 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
7545 /* Look for the "this" argument. */
7546 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
7547 if (TYPE_NFIELDS (pfn_type
) == 0
7548 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
7549 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
7552 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
7553 new_type
= alloc_type (objfile
);
7554 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
7555 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
7556 TYPE_VARARGS (pfn_type
));
7557 smash_to_methodptr_type (type
, new_type
);
7560 /* Called when we find the DIE that starts a structure or union scope
7561 (definition) to create a type for the structure or union. Fill in
7562 the type's name and general properties; the members will not be
7563 processed until process_structure_type.
7565 NOTE: we need to call these functions regardless of whether or not the
7566 DIE has a DW_AT_name attribute, since it might be an anonymous
7567 structure or union. This gets the type entered into our set of
7570 However, if the structure is incomplete (an opaque struct/union)
7571 then suppress creating a symbol table entry for it since gdb only
7572 wants to find the one with the complete definition. Note that if
7573 it is complete, we just call new_symbol, which does it's own
7574 checking about whether the struct/union is anonymous or not (and
7575 suppresses creating a symbol table entry itself). */
7577 static struct type
*
7578 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7580 struct objfile
*objfile
= cu
->objfile
;
7582 struct attribute
*attr
;
7585 /* If the definition of this type lives in .debug_types, read that type.
7586 Don't follow DW_AT_specification though, that will take us back up
7587 the chain and we want to go down. */
7588 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7591 struct dwarf2_cu
*type_cu
= cu
;
7592 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7594 /* We could just recurse on read_structure_type, but we need to call
7595 get_die_type to ensure only one type for this DIE is created.
7596 This is important, for example, because for c++ classes we need
7597 TYPE_NAME set which is only done by new_symbol. Blech. */
7598 type
= read_type_die (type_die
, type_cu
);
7600 /* TYPE_CU may not be the same as CU.
7601 Ensure TYPE is recorded in CU's type_hash table. */
7602 return set_die_type (die
, type
, cu
);
7605 type
= alloc_type (objfile
);
7606 INIT_CPLUS_SPECIFIC (type
);
7608 name
= dwarf2_name (die
, cu
);
7611 if (cu
->language
== language_cplus
7612 || cu
->language
== language_java
)
7614 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
7616 /* dwarf2_full_name might have already finished building the DIE's
7617 type. If so, there is no need to continue. */
7618 if (get_die_type (die
, cu
) != NULL
)
7619 return get_die_type (die
, cu
);
7621 TYPE_TAG_NAME (type
) = full_name
;
7622 if (die
->tag
== DW_TAG_structure_type
7623 || die
->tag
== DW_TAG_class_type
)
7624 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7628 /* The name is already allocated along with this objfile, so
7629 we don't need to duplicate it for the type. */
7630 TYPE_TAG_NAME (type
) = (char *) name
;
7631 if (die
->tag
== DW_TAG_class_type
)
7632 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7636 if (die
->tag
== DW_TAG_structure_type
)
7638 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
7640 else if (die
->tag
== DW_TAG_union_type
)
7642 TYPE_CODE (type
) = TYPE_CODE_UNION
;
7646 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
7649 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
7650 TYPE_DECLARED_CLASS (type
) = 1;
7652 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7655 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7659 TYPE_LENGTH (type
) = 0;
7662 TYPE_STUB_SUPPORTED (type
) = 1;
7663 if (die_is_declaration (die
, cu
))
7664 TYPE_STUB (type
) = 1;
7665 else if (attr
== NULL
&& die
->child
== NULL
7666 && producer_is_realview (cu
->producer
))
7667 /* RealView does not output the required DW_AT_declaration
7668 on incomplete types. */
7669 TYPE_STUB (type
) = 1;
7671 /* We need to add the type field to the die immediately so we don't
7672 infinitely recurse when dealing with pointers to the structure
7673 type within the structure itself. */
7674 set_die_type (die
, type
, cu
);
7676 /* set_die_type should be already done. */
7677 set_descriptive_type (type
, die
, cu
);
7682 /* Finish creating a structure or union type, including filling in
7683 its members and creating a symbol for it. */
7686 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7688 struct objfile
*objfile
= cu
->objfile
;
7689 struct die_info
*child_die
= die
->child
;
7692 type
= get_die_type (die
, cu
);
7694 type
= read_structure_type (die
, cu
);
7696 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
7698 struct field_info fi
;
7699 struct die_info
*child_die
;
7700 VEC (symbolp
) *template_args
= NULL
;
7701 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
7703 memset (&fi
, 0, sizeof (struct field_info
));
7705 child_die
= die
->child
;
7707 while (child_die
&& child_die
->tag
)
7709 if (child_die
->tag
== DW_TAG_member
7710 || child_die
->tag
== DW_TAG_variable
)
7712 /* NOTE: carlton/2002-11-05: A C++ static data member
7713 should be a DW_TAG_member that is a declaration, but
7714 all versions of G++ as of this writing (so through at
7715 least 3.2.1) incorrectly generate DW_TAG_variable
7716 tags for them instead. */
7717 dwarf2_add_field (&fi
, child_die
, cu
);
7719 else if (child_die
->tag
== DW_TAG_subprogram
)
7721 /* C++ member function. */
7722 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
7724 else if (child_die
->tag
== DW_TAG_inheritance
)
7726 /* C++ base class field. */
7727 dwarf2_add_field (&fi
, child_die
, cu
);
7729 else if (child_die
->tag
== DW_TAG_typedef
)
7730 dwarf2_add_typedef (&fi
, child_die
, cu
);
7731 else if (child_die
->tag
== DW_TAG_template_type_param
7732 || child_die
->tag
== DW_TAG_template_value_param
)
7734 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
7737 VEC_safe_push (symbolp
, template_args
, arg
);
7740 child_die
= sibling_die (child_die
);
7743 /* Attach template arguments to type. */
7744 if (! VEC_empty (symbolp
, template_args
))
7746 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7747 TYPE_N_TEMPLATE_ARGUMENTS (type
)
7748 = VEC_length (symbolp
, template_args
);
7749 TYPE_TEMPLATE_ARGUMENTS (type
)
7750 = obstack_alloc (&objfile
->objfile_obstack
,
7751 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7752 * sizeof (struct symbol
*)));
7753 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
7754 VEC_address (symbolp
, template_args
),
7755 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7756 * sizeof (struct symbol
*)));
7757 VEC_free (symbolp
, template_args
);
7760 /* Attach fields and member functions to the type. */
7762 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
7765 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
7767 /* Get the type which refers to the base class (possibly this
7768 class itself) which contains the vtable pointer for the current
7769 class from the DW_AT_containing_type attribute. This use of
7770 DW_AT_containing_type is a GNU extension. */
7772 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7774 struct type
*t
= die_containing_type (die
, cu
);
7776 TYPE_VPTR_BASETYPE (type
) = t
;
7781 /* Our own class provides vtbl ptr. */
7782 for (i
= TYPE_NFIELDS (t
) - 1;
7783 i
>= TYPE_N_BASECLASSES (t
);
7786 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
7788 if (is_vtable_name (fieldname
, cu
))
7790 TYPE_VPTR_FIELDNO (type
) = i
;
7795 /* Complain if virtual function table field not found. */
7796 if (i
< TYPE_N_BASECLASSES (t
))
7797 complaint (&symfile_complaints
,
7798 _("virtual function table pointer "
7799 "not found when defining class '%s'"),
7800 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
7805 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
7808 else if (cu
->producer
7809 && strncmp (cu
->producer
,
7810 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
7812 /* The IBM XLC compiler does not provide direct indication
7813 of the containing type, but the vtable pointer is
7814 always named __vfp. */
7818 for (i
= TYPE_NFIELDS (type
) - 1;
7819 i
>= TYPE_N_BASECLASSES (type
);
7822 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
7824 TYPE_VPTR_FIELDNO (type
) = i
;
7825 TYPE_VPTR_BASETYPE (type
) = type
;
7832 /* Copy fi.typedef_field_list linked list elements content into the
7833 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
7834 if (fi
.typedef_field_list
)
7836 int i
= fi
.typedef_field_list_count
;
7838 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7839 TYPE_TYPEDEF_FIELD_ARRAY (type
)
7840 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
7841 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
7843 /* Reverse the list order to keep the debug info elements order. */
7846 struct typedef_field
*dest
, *src
;
7848 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
7849 src
= &fi
.typedef_field_list
->field
;
7850 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
7855 do_cleanups (back_to
);
7857 if (HAVE_CPLUS_STRUCT (type
))
7858 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
7861 quirk_gcc_member_function_pointer (type
, objfile
);
7863 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
7864 snapshots) has been known to create a die giving a declaration
7865 for a class that has, as a child, a die giving a definition for a
7866 nested class. So we have to process our children even if the
7867 current die is a declaration. Normally, of course, a declaration
7868 won't have any children at all. */
7870 while (child_die
!= NULL
&& child_die
->tag
)
7872 if (child_die
->tag
== DW_TAG_member
7873 || child_die
->tag
== DW_TAG_variable
7874 || child_die
->tag
== DW_TAG_inheritance
7875 || child_die
->tag
== DW_TAG_template_value_param
7876 || child_die
->tag
== DW_TAG_template_type_param
)
7881 process_die (child_die
, cu
);
7883 child_die
= sibling_die (child_die
);
7886 /* Do not consider external references. According to the DWARF standard,
7887 these DIEs are identified by the fact that they have no byte_size
7888 attribute, and a declaration attribute. */
7889 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
7890 || !die_is_declaration (die
, cu
))
7891 new_symbol (die
, type
, cu
);
7894 /* Given a DW_AT_enumeration_type die, set its type. We do not
7895 complete the type's fields yet, or create any symbols. */
7897 static struct type
*
7898 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7900 struct objfile
*objfile
= cu
->objfile
;
7902 struct attribute
*attr
;
7905 /* If the definition of this type lives in .debug_types, read that type.
7906 Don't follow DW_AT_specification though, that will take us back up
7907 the chain and we want to go down. */
7908 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7911 struct dwarf2_cu
*type_cu
= cu
;
7912 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7914 type
= read_type_die (type_die
, type_cu
);
7916 /* TYPE_CU may not be the same as CU.
7917 Ensure TYPE is recorded in CU's type_hash table. */
7918 return set_die_type (die
, type
, cu
);
7921 type
= alloc_type (objfile
);
7923 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
7924 name
= dwarf2_full_name (NULL
, die
, cu
);
7926 TYPE_TAG_NAME (type
) = (char *) name
;
7928 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7931 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7935 TYPE_LENGTH (type
) = 0;
7938 /* The enumeration DIE can be incomplete. In Ada, any type can be
7939 declared as private in the package spec, and then defined only
7940 inside the package body. Such types are known as Taft Amendment
7941 Types. When another package uses such a type, an incomplete DIE
7942 may be generated by the compiler. */
7943 if (die_is_declaration (die
, cu
))
7944 TYPE_STUB (type
) = 1;
7946 return set_die_type (die
, type
, cu
);
7949 /* Given a pointer to a die which begins an enumeration, process all
7950 the dies that define the members of the enumeration, and create the
7951 symbol for the enumeration type.
7953 NOTE: We reverse the order of the element list. */
7956 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7958 struct type
*this_type
;
7960 this_type
= get_die_type (die
, cu
);
7961 if (this_type
== NULL
)
7962 this_type
= read_enumeration_type (die
, cu
);
7964 if (die
->child
!= NULL
)
7966 struct die_info
*child_die
;
7968 struct field
*fields
= NULL
;
7970 int unsigned_enum
= 1;
7975 child_die
= die
->child
;
7976 while (child_die
&& child_die
->tag
)
7978 if (child_die
->tag
!= DW_TAG_enumerator
)
7980 process_die (child_die
, cu
);
7984 name
= dwarf2_name (child_die
, cu
);
7987 sym
= new_symbol (child_die
, this_type
, cu
);
7988 if (SYMBOL_VALUE (sym
) < 0)
7993 else if ((mask
& SYMBOL_VALUE (sym
)) != 0)
7996 mask
|= SYMBOL_VALUE (sym
);
7998 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
8000 fields
= (struct field
*)
8002 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
8003 * sizeof (struct field
));
8006 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
8007 FIELD_TYPE (fields
[num_fields
]) = NULL
;
8008 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
8009 FIELD_BITSIZE (fields
[num_fields
]) = 0;
8015 child_die
= sibling_die (child_die
);
8020 TYPE_NFIELDS (this_type
) = num_fields
;
8021 TYPE_FIELDS (this_type
) = (struct field
*)
8022 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
8023 memcpy (TYPE_FIELDS (this_type
), fields
,
8024 sizeof (struct field
) * num_fields
);
8028 TYPE_UNSIGNED (this_type
) = 1;
8030 TYPE_FLAG_ENUM (this_type
) = 1;
8033 /* If we are reading an enum from a .debug_types unit, and the enum
8034 is a declaration, and the enum is not the signatured type in the
8035 unit, then we do not want to add a symbol for it. Adding a
8036 symbol would in some cases obscure the true definition of the
8037 enum, giving users an incomplete type when the definition is
8038 actually available. Note that we do not want to do this for all
8039 enums which are just declarations, because C++0x allows forward
8040 enum declarations. */
8041 if (cu
->per_cu
->debug_types_section
8042 && die_is_declaration (die
, cu
))
8044 struct signatured_type
*type_sig
;
8047 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
8048 cu
->per_cu
->debug_types_section
,
8049 cu
->per_cu
->offset
);
8050 if (type_sig
->type_offset
!= die
->offset
)
8054 new_symbol (die
, this_type
, cu
);
8057 /* Extract all information from a DW_TAG_array_type DIE and put it in
8058 the DIE's type field. For now, this only handles one dimensional
8061 static struct type
*
8062 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8064 struct objfile
*objfile
= cu
->objfile
;
8065 struct die_info
*child_die
;
8067 struct type
*element_type
, *range_type
, *index_type
;
8068 struct type
**range_types
= NULL
;
8069 struct attribute
*attr
;
8071 struct cleanup
*back_to
;
8074 element_type
= die_type (die
, cu
);
8076 /* The die_type call above may have already set the type for this DIE. */
8077 type
= get_die_type (die
, cu
);
8081 /* Irix 6.2 native cc creates array types without children for
8082 arrays with unspecified length. */
8083 if (die
->child
== NULL
)
8085 index_type
= objfile_type (objfile
)->builtin_int
;
8086 range_type
= create_range_type (NULL
, index_type
, 0, -1);
8087 type
= create_array_type (NULL
, element_type
, range_type
);
8088 return set_die_type (die
, type
, cu
);
8091 back_to
= make_cleanup (null_cleanup
, NULL
);
8092 child_die
= die
->child
;
8093 while (child_die
&& child_die
->tag
)
8095 if (child_die
->tag
== DW_TAG_subrange_type
)
8097 struct type
*child_type
= read_type_die (child_die
, cu
);
8099 if (child_type
!= NULL
)
8101 /* The range type was succesfully read. Save it for the
8102 array type creation. */
8103 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
8105 range_types
= (struct type
**)
8106 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
8107 * sizeof (struct type
*));
8109 make_cleanup (free_current_contents
, &range_types
);
8111 range_types
[ndim
++] = child_type
;
8114 child_die
= sibling_die (child_die
);
8117 /* Dwarf2 dimensions are output from left to right, create the
8118 necessary array types in backwards order. */
8120 type
= element_type
;
8122 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
8127 type
= create_array_type (NULL
, type
, range_types
[i
++]);
8132 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
8135 /* Understand Dwarf2 support for vector types (like they occur on
8136 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
8137 array type. This is not part of the Dwarf2/3 standard yet, but a
8138 custom vendor extension. The main difference between a regular
8139 array and the vector variant is that vectors are passed by value
8141 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
8143 make_vector_type (type
);
8145 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
8146 implementation may choose to implement triple vectors using this
8148 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8151 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
8152 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8154 complaint (&symfile_complaints
,
8155 _("DW_AT_byte_size for array type smaller "
8156 "than the total size of elements"));
8159 name
= dwarf2_name (die
, cu
);
8161 TYPE_NAME (type
) = name
;
8163 /* Install the type in the die. */
8164 set_die_type (die
, type
, cu
);
8166 /* set_die_type should be already done. */
8167 set_descriptive_type (type
, die
, cu
);
8169 do_cleanups (back_to
);
8174 static enum dwarf_array_dim_ordering
8175 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
8177 struct attribute
*attr
;
8179 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
8181 if (attr
) return DW_SND (attr
);
8183 /* GNU F77 is a special case, as at 08/2004 array type info is the
8184 opposite order to the dwarf2 specification, but data is still
8185 laid out as per normal fortran.
8187 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
8188 version checking. */
8190 if (cu
->language
== language_fortran
8191 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
8193 return DW_ORD_row_major
;
8196 switch (cu
->language_defn
->la_array_ordering
)
8198 case array_column_major
:
8199 return DW_ORD_col_major
;
8200 case array_row_major
:
8202 return DW_ORD_row_major
;
8206 /* Extract all information from a DW_TAG_set_type DIE and put it in
8207 the DIE's type field. */
8209 static struct type
*
8210 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8212 struct type
*domain_type
, *set_type
;
8213 struct attribute
*attr
;
8215 domain_type
= die_type (die
, cu
);
8217 /* The die_type call above may have already set the type for this DIE. */
8218 set_type
= get_die_type (die
, cu
);
8222 set_type
= create_set_type (NULL
, domain_type
);
8224 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8226 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
8228 return set_die_type (die
, set_type
, cu
);
8231 /* First cut: install each common block member as a global variable. */
8234 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
8236 struct die_info
*child_die
;
8237 struct attribute
*attr
;
8239 CORE_ADDR base
= (CORE_ADDR
) 0;
8241 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
8244 /* Support the .debug_loc offsets. */
8245 if (attr_form_is_block (attr
))
8247 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
8249 else if (attr_form_is_section_offset (attr
))
8251 dwarf2_complex_location_expr_complaint ();
8255 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
8256 "common block member");
8259 if (die
->child
!= NULL
)
8261 child_die
= die
->child
;
8262 while (child_die
&& child_die
->tag
)
8266 sym
= new_symbol (child_die
, NULL
, cu
);
8268 && handle_data_member_location (child_die
, cu
, &offset
))
8270 SYMBOL_VALUE_ADDRESS (sym
) = base
+ offset
;
8271 add_symbol_to_list (sym
, &global_symbols
);
8273 child_die
= sibling_die (child_die
);
8278 /* Create a type for a C++ namespace. */
8280 static struct type
*
8281 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8283 struct objfile
*objfile
= cu
->objfile
;
8284 const char *previous_prefix
, *name
;
8288 /* For extensions, reuse the type of the original namespace. */
8289 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
8291 struct die_info
*ext_die
;
8292 struct dwarf2_cu
*ext_cu
= cu
;
8294 ext_die
= dwarf2_extension (die
, &ext_cu
);
8295 type
= read_type_die (ext_die
, ext_cu
);
8297 /* EXT_CU may not be the same as CU.
8298 Ensure TYPE is recorded in CU's type_hash table. */
8299 return set_die_type (die
, type
, cu
);
8302 name
= namespace_name (die
, &is_anonymous
, cu
);
8304 /* Now build the name of the current namespace. */
8306 previous_prefix
= determine_prefix (die
, cu
);
8307 if (previous_prefix
[0] != '\0')
8308 name
= typename_concat (&objfile
->objfile_obstack
,
8309 previous_prefix
, name
, 0, cu
);
8311 /* Create the type. */
8312 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
8314 TYPE_NAME (type
) = (char *) name
;
8315 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8317 return set_die_type (die
, type
, cu
);
8320 /* Read a C++ namespace. */
8323 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
8325 struct objfile
*objfile
= cu
->objfile
;
8328 /* Add a symbol associated to this if we haven't seen the namespace
8329 before. Also, add a using directive if it's an anonymous
8332 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
8336 type
= read_type_die (die
, cu
);
8337 new_symbol (die
, type
, cu
);
8339 namespace_name (die
, &is_anonymous
, cu
);
8342 const char *previous_prefix
= determine_prefix (die
, cu
);
8344 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
8345 NULL
, NULL
, &objfile
->objfile_obstack
);
8349 if (die
->child
!= NULL
)
8351 struct die_info
*child_die
= die
->child
;
8353 while (child_die
&& child_die
->tag
)
8355 process_die (child_die
, cu
);
8356 child_die
= sibling_die (child_die
);
8361 /* Read a Fortran module as type. This DIE can be only a declaration used for
8362 imported module. Still we need that type as local Fortran "use ... only"
8363 declaration imports depend on the created type in determine_prefix. */
8365 static struct type
*
8366 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8368 struct objfile
*objfile
= cu
->objfile
;
8372 module_name
= dwarf2_name (die
, cu
);
8374 complaint (&symfile_complaints
,
8375 _("DW_TAG_module has no name, offset 0x%x"),
8377 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
8379 /* determine_prefix uses TYPE_TAG_NAME. */
8380 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8382 return set_die_type (die
, type
, cu
);
8385 /* Read a Fortran module. */
8388 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
8390 struct die_info
*child_die
= die
->child
;
8392 while (child_die
&& child_die
->tag
)
8394 process_die (child_die
, cu
);
8395 child_die
= sibling_die (child_die
);
8399 /* Return the name of the namespace represented by DIE. Set
8400 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
8404 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
8406 struct die_info
*current_die
;
8407 const char *name
= NULL
;
8409 /* Loop through the extensions until we find a name. */
8411 for (current_die
= die
;
8412 current_die
!= NULL
;
8413 current_die
= dwarf2_extension (die
, &cu
))
8415 name
= dwarf2_name (current_die
, cu
);
8420 /* Is it an anonymous namespace? */
8422 *is_anonymous
= (name
== NULL
);
8424 name
= CP_ANONYMOUS_NAMESPACE_STR
;
8429 /* Extract all information from a DW_TAG_pointer_type DIE and add to
8430 the user defined type vector. */
8432 static struct type
*
8433 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8435 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
8436 struct comp_unit_head
*cu_header
= &cu
->header
;
8438 struct attribute
*attr_byte_size
;
8439 struct attribute
*attr_address_class
;
8440 int byte_size
, addr_class
;
8441 struct type
*target_type
;
8443 target_type
= die_type (die
, cu
);
8445 /* The die_type call above may have already set the type for this DIE. */
8446 type
= get_die_type (die
, cu
);
8450 type
= lookup_pointer_type (target_type
);
8452 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8454 byte_size
= DW_UNSND (attr_byte_size
);
8456 byte_size
= cu_header
->addr_size
;
8458 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
8459 if (attr_address_class
)
8460 addr_class
= DW_UNSND (attr_address_class
);
8462 addr_class
= DW_ADDR_none
;
8464 /* If the pointer size or address class is different than the
8465 default, create a type variant marked as such and set the
8466 length accordingly. */
8467 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
8469 if (gdbarch_address_class_type_flags_p (gdbarch
))
8473 type_flags
= gdbarch_address_class_type_flags
8474 (gdbarch
, byte_size
, addr_class
);
8475 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
8477 type
= make_type_with_address_space (type
, type_flags
);
8479 else if (TYPE_LENGTH (type
) != byte_size
)
8481 complaint (&symfile_complaints
,
8482 _("invalid pointer size %d"), byte_size
);
8486 /* Should we also complain about unhandled address classes? */
8490 TYPE_LENGTH (type
) = byte_size
;
8491 return set_die_type (die
, type
, cu
);
8494 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
8495 the user defined type vector. */
8497 static struct type
*
8498 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8501 struct type
*to_type
;
8502 struct type
*domain
;
8504 to_type
= die_type (die
, cu
);
8505 domain
= die_containing_type (die
, cu
);
8507 /* The calls above may have already set the type for this DIE. */
8508 type
= get_die_type (die
, cu
);
8512 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
8513 type
= lookup_methodptr_type (to_type
);
8515 type
= lookup_memberptr_type (to_type
, domain
);
8517 return set_die_type (die
, type
, cu
);
8520 /* Extract all information from a DW_TAG_reference_type DIE and add to
8521 the user defined type vector. */
8523 static struct type
*
8524 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8526 struct comp_unit_head
*cu_header
= &cu
->header
;
8527 struct type
*type
, *target_type
;
8528 struct attribute
*attr
;
8530 target_type
= die_type (die
, cu
);
8532 /* The die_type call above may have already set the type for this DIE. */
8533 type
= get_die_type (die
, cu
);
8537 type
= lookup_reference_type (target_type
);
8538 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8541 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8545 TYPE_LENGTH (type
) = cu_header
->addr_size
;
8547 return set_die_type (die
, type
, cu
);
8550 static struct type
*
8551 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8553 struct type
*base_type
, *cv_type
;
8555 base_type
= die_type (die
, cu
);
8557 /* The die_type call above may have already set the type for this DIE. */
8558 cv_type
= get_die_type (die
, cu
);
8562 /* In case the const qualifier is applied to an array type, the element type
8563 is so qualified, not the array type (section 6.7.3 of C99). */
8564 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
8566 struct type
*el_type
, *inner_array
;
8568 base_type
= copy_type (base_type
);
8569 inner_array
= base_type
;
8571 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
8573 TYPE_TARGET_TYPE (inner_array
) =
8574 copy_type (TYPE_TARGET_TYPE (inner_array
));
8575 inner_array
= TYPE_TARGET_TYPE (inner_array
);
8578 el_type
= TYPE_TARGET_TYPE (inner_array
);
8579 TYPE_TARGET_TYPE (inner_array
) =
8580 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
8582 return set_die_type (die
, base_type
, cu
);
8585 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
8586 return set_die_type (die
, cv_type
, cu
);
8589 static struct type
*
8590 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8592 struct type
*base_type
, *cv_type
;
8594 base_type
= die_type (die
, cu
);
8596 /* The die_type call above may have already set the type for this DIE. */
8597 cv_type
= get_die_type (die
, cu
);
8601 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
8602 return set_die_type (die
, cv_type
, cu
);
8605 /* Extract all information from a DW_TAG_string_type DIE and add to
8606 the user defined type vector. It isn't really a user defined type,
8607 but it behaves like one, with other DIE's using an AT_user_def_type
8608 attribute to reference it. */
8610 static struct type
*
8611 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8613 struct objfile
*objfile
= cu
->objfile
;
8614 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8615 struct type
*type
, *range_type
, *index_type
, *char_type
;
8616 struct attribute
*attr
;
8617 unsigned int length
;
8619 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
8622 length
= DW_UNSND (attr
);
8626 /* Check for the DW_AT_byte_size attribute. */
8627 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8630 length
= DW_UNSND (attr
);
8638 index_type
= objfile_type (objfile
)->builtin_int
;
8639 range_type
= create_range_type (NULL
, index_type
, 1, length
);
8640 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
8641 type
= create_string_type (NULL
, char_type
, range_type
);
8643 return set_die_type (die
, type
, cu
);
8646 /* Handle DIES due to C code like:
8650 int (*funcp)(int a, long l);
8654 ('funcp' generates a DW_TAG_subroutine_type DIE). */
8656 static struct type
*
8657 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8659 struct objfile
*objfile
= cu
->objfile
;
8660 struct type
*type
; /* Type that this function returns. */
8661 struct type
*ftype
; /* Function that returns above type. */
8662 struct attribute
*attr
;
8664 type
= die_type (die
, cu
);
8666 /* The die_type call above may have already set the type for this DIE. */
8667 ftype
= get_die_type (die
, cu
);
8671 ftype
= lookup_function_type (type
);
8673 /* All functions in C++, Pascal and Java have prototypes. */
8674 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
8675 if ((attr
&& (DW_UNSND (attr
) != 0))
8676 || cu
->language
== language_cplus
8677 || cu
->language
== language_java
8678 || cu
->language
== language_pascal
)
8679 TYPE_PROTOTYPED (ftype
) = 1;
8680 else if (producer_is_realview (cu
->producer
))
8681 /* RealView does not emit DW_AT_prototyped. We can not
8682 distinguish prototyped and unprototyped functions; default to
8683 prototyped, since that is more common in modern code (and
8684 RealView warns about unprototyped functions). */
8685 TYPE_PROTOTYPED (ftype
) = 1;
8687 /* Store the calling convention in the type if it's available in
8688 the subroutine die. Otherwise set the calling convention to
8689 the default value DW_CC_normal. */
8690 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
8692 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
8693 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
8694 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
8696 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
8698 /* We need to add the subroutine type to the die immediately so
8699 we don't infinitely recurse when dealing with parameters
8700 declared as the same subroutine type. */
8701 set_die_type (die
, ftype
, cu
);
8703 if (die
->child
!= NULL
)
8705 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
8706 struct die_info
*child_die
;
8707 int nparams
, iparams
;
8709 /* Count the number of parameters.
8710 FIXME: GDB currently ignores vararg functions, but knows about
8711 vararg member functions. */
8713 child_die
= die
->child
;
8714 while (child_die
&& child_die
->tag
)
8716 if (child_die
->tag
== DW_TAG_formal_parameter
)
8718 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
8719 TYPE_VARARGS (ftype
) = 1;
8720 child_die
= sibling_die (child_die
);
8723 /* Allocate storage for parameters and fill them in. */
8724 TYPE_NFIELDS (ftype
) = nparams
;
8725 TYPE_FIELDS (ftype
) = (struct field
*)
8726 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
8728 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
8729 even if we error out during the parameters reading below. */
8730 for (iparams
= 0; iparams
< nparams
; iparams
++)
8731 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
8734 child_die
= die
->child
;
8735 while (child_die
&& child_die
->tag
)
8737 if (child_die
->tag
== DW_TAG_formal_parameter
)
8739 struct type
*arg_type
;
8741 /* DWARF version 2 has no clean way to discern C++
8742 static and non-static member functions. G++ helps
8743 GDB by marking the first parameter for non-static
8744 member functions (which is the this pointer) as
8745 artificial. We pass this information to
8746 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
8748 DWARF version 3 added DW_AT_object_pointer, which GCC
8749 4.5 does not yet generate. */
8750 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
8752 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
8755 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
8757 /* GCC/43521: In java, the formal parameter
8758 "this" is sometimes not marked with DW_AT_artificial. */
8759 if (cu
->language
== language_java
)
8761 const char *name
= dwarf2_name (child_die
, cu
);
8763 if (name
&& !strcmp (name
, "this"))
8764 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
8767 arg_type
= die_type (child_die
, cu
);
8769 /* RealView does not mark THIS as const, which the testsuite
8770 expects. GCC marks THIS as const in method definitions,
8771 but not in the class specifications (GCC PR 43053). */
8772 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
8773 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
8776 struct dwarf2_cu
*arg_cu
= cu
;
8777 const char *name
= dwarf2_name (child_die
, cu
);
8779 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
8782 /* If the compiler emits this, use it. */
8783 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
8786 else if (name
&& strcmp (name
, "this") == 0)
8787 /* Function definitions will have the argument names. */
8789 else if (name
== NULL
&& iparams
== 0)
8790 /* Declarations may not have the names, so like
8791 elsewhere in GDB, assume an artificial first
8792 argument is "this". */
8796 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
8800 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
8803 child_die
= sibling_die (child_die
);
8810 static struct type
*
8811 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
8813 struct objfile
*objfile
= cu
->objfile
;
8814 const char *name
= NULL
;
8815 struct type
*this_type
, *target_type
;
8817 name
= dwarf2_full_name (NULL
, die
, cu
);
8818 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
8819 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
8820 TYPE_NAME (this_type
) = (char *) name
;
8821 set_die_type (die
, this_type
, cu
);
8822 target_type
= die_type (die
, cu
);
8823 if (target_type
!= this_type
)
8824 TYPE_TARGET_TYPE (this_type
) = target_type
;
8827 /* Self-referential typedefs are, it seems, not allowed by the DWARF
8828 spec and cause infinite loops in GDB. */
8829 complaint (&symfile_complaints
,
8830 _("Self-referential DW_TAG_typedef "
8831 "- DIE at 0x%x [in module %s]"),
8832 die
->offset
, objfile
->name
);
8833 TYPE_TARGET_TYPE (this_type
) = NULL
;
8838 /* Find a representation of a given base type and install
8839 it in the TYPE field of the die. */
8841 static struct type
*
8842 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8844 struct objfile
*objfile
= cu
->objfile
;
8846 struct attribute
*attr
;
8847 int encoding
= 0, size
= 0;
8849 enum type_code code
= TYPE_CODE_INT
;
8851 struct type
*target_type
= NULL
;
8853 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
8856 encoding
= DW_UNSND (attr
);
8858 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8861 size
= DW_UNSND (attr
);
8863 name
= dwarf2_name (die
, cu
);
8866 complaint (&symfile_complaints
,
8867 _("DW_AT_name missing from DW_TAG_base_type"));
8872 case DW_ATE_address
:
8873 /* Turn DW_ATE_address into a void * pointer. */
8874 code
= TYPE_CODE_PTR
;
8875 type_flags
|= TYPE_FLAG_UNSIGNED
;
8876 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
8878 case DW_ATE_boolean
:
8879 code
= TYPE_CODE_BOOL
;
8880 type_flags
|= TYPE_FLAG_UNSIGNED
;
8882 case DW_ATE_complex_float
:
8883 code
= TYPE_CODE_COMPLEX
;
8884 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
8886 case DW_ATE_decimal_float
:
8887 code
= TYPE_CODE_DECFLOAT
;
8890 code
= TYPE_CODE_FLT
;
8894 case DW_ATE_unsigned
:
8895 type_flags
|= TYPE_FLAG_UNSIGNED
;
8896 if (cu
->language
== language_fortran
8898 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
8899 code
= TYPE_CODE_CHAR
;
8901 case DW_ATE_signed_char
:
8902 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8903 || cu
->language
== language_pascal
8904 || cu
->language
== language_fortran
)
8905 code
= TYPE_CODE_CHAR
;
8907 case DW_ATE_unsigned_char
:
8908 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8909 || cu
->language
== language_pascal
8910 || cu
->language
== language_fortran
)
8911 code
= TYPE_CODE_CHAR
;
8912 type_flags
|= TYPE_FLAG_UNSIGNED
;
8915 /* We just treat this as an integer and then recognize the
8916 type by name elsewhere. */
8920 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
8921 dwarf_type_encoding_name (encoding
));
8925 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
8926 TYPE_NAME (type
) = name
;
8927 TYPE_TARGET_TYPE (type
) = target_type
;
8929 if (name
&& strcmp (name
, "char") == 0)
8930 TYPE_NOSIGN (type
) = 1;
8932 return set_die_type (die
, type
, cu
);
8935 /* Read the given DW_AT_subrange DIE. */
8937 static struct type
*
8938 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8940 struct type
*base_type
;
8941 struct type
*range_type
;
8942 struct attribute
*attr
;
8946 LONGEST negative_mask
;
8948 base_type
= die_type (die
, cu
);
8949 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
8950 check_typedef (base_type
);
8952 /* The die_type call above may have already set the type for this DIE. */
8953 range_type
= get_die_type (die
, cu
);
8957 if (cu
->language
== language_fortran
)
8959 /* FORTRAN implies a lower bound of 1, if not given. */
8963 /* FIXME: For variable sized arrays either of these could be
8964 a variable rather than a constant value. We'll allow it,
8965 but we don't know how to handle it. */
8966 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
8968 low
= dwarf2_get_attr_constant_value (attr
, 0);
8970 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
8973 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
8975 /* GCC encodes arrays with unspecified or dynamic length
8976 with a DW_FORM_block1 attribute or a reference attribute.
8977 FIXME: GDB does not yet know how to handle dynamic
8978 arrays properly, treat them as arrays with unspecified
8981 FIXME: jimb/2003-09-22: GDB does not really know
8982 how to handle arrays of unspecified length
8983 either; we just represent them as zero-length
8984 arrays. Choose an appropriate upper bound given
8985 the lower bound we've computed above. */
8989 high
= dwarf2_get_attr_constant_value (attr
, 1);
8993 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
8996 int count
= dwarf2_get_attr_constant_value (attr
, 1);
8997 high
= low
+ count
- 1;
9001 /* Unspecified array length. */
9006 /* Dwarf-2 specifications explicitly allows to create subrange types
9007 without specifying a base type.
9008 In that case, the base type must be set to the type of
9009 the lower bound, upper bound or count, in that order, if any of these
9010 three attributes references an object that has a type.
9011 If no base type is found, the Dwarf-2 specifications say that
9012 a signed integer type of size equal to the size of an address should
9014 For the following C code: `extern char gdb_int [];'
9015 GCC produces an empty range DIE.
9016 FIXME: muller/2010-05-28: Possible references to object for low bound,
9017 high bound or count are not yet handled by this code. */
9018 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
9020 struct objfile
*objfile
= cu
->objfile
;
9021 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9022 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
9023 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
9025 /* Test "int", "long int", and "long long int" objfile types,
9026 and select the first one having a size above or equal to the
9027 architecture address size. */
9028 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
9029 base_type
= int_type
;
9032 int_type
= objfile_type (objfile
)->builtin_long
;
9033 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
9034 base_type
= int_type
;
9037 int_type
= objfile_type (objfile
)->builtin_long_long
;
9038 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
9039 base_type
= int_type
;
9045 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
9046 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
9047 low
|= negative_mask
;
9048 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
9049 high
|= negative_mask
;
9051 range_type
= create_range_type (NULL
, base_type
, low
, high
);
9053 /* Mark arrays with dynamic length at least as an array of unspecified
9054 length. GDB could check the boundary but before it gets implemented at
9055 least allow accessing the array elements. */
9056 if (attr
&& attr_form_is_block (attr
))
9057 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
9059 /* Ada expects an empty array on no boundary attributes. */
9060 if (attr
== NULL
&& cu
->language
!= language_ada
)
9061 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
9063 name
= dwarf2_name (die
, cu
);
9065 TYPE_NAME (range_type
) = name
;
9067 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9069 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
9071 set_die_type (die
, range_type
, cu
);
9073 /* set_die_type should be already done. */
9074 set_descriptive_type (range_type
, die
, cu
);
9079 static struct type
*
9080 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9084 /* For now, we only support the C meaning of an unspecified type: void. */
9086 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
9087 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
9089 return set_die_type (die
, type
, cu
);
9092 /* Trivial hash function for die_info: the hash value of a DIE
9093 is its offset in .debug_info for this objfile. */
9096 die_hash (const void *item
)
9098 const struct die_info
*die
= item
;
9103 /* Trivial comparison function for die_info structures: two DIEs
9104 are equal if they have the same offset. */
9107 die_eq (const void *item_lhs
, const void *item_rhs
)
9109 const struct die_info
*die_lhs
= item_lhs
;
9110 const struct die_info
*die_rhs
= item_rhs
;
9112 return die_lhs
->offset
== die_rhs
->offset
;
9115 /* Read a whole compilation unit into a linked list of dies. */
9117 static struct die_info
*
9118 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
9120 struct die_reader_specs reader_specs
;
9121 int read_abbrevs
= 0;
9122 struct cleanup
*back_to
= NULL
;
9123 struct die_info
*die
;
9125 if (cu
->dwarf2_abbrevs
== NULL
)
9127 dwarf2_read_abbrevs (cu
);
9128 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
9132 gdb_assert (cu
->die_hash
== NULL
);
9134 = htab_create_alloc_ex (cu
->header
.length
/ 12,
9138 &cu
->comp_unit_obstack
,
9139 hashtab_obstack_allocate
,
9140 dummy_obstack_deallocate
);
9142 init_cu_die_reader (&reader_specs
, cu
);
9144 die
= read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
9147 do_cleanups (back_to
);
9152 /* Main entry point for reading a DIE and all children.
9153 Read the DIE and dump it if requested. */
9155 static struct die_info
*
9156 read_die_and_children (const struct die_reader_specs
*reader
,
9158 gdb_byte
**new_info_ptr
,
9159 struct die_info
*parent
)
9161 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
9162 new_info_ptr
, parent
);
9164 if (dwarf2_die_debug
)
9166 fprintf_unfiltered (gdb_stdlog
,
9167 "\nRead die from %s of %s:\n",
9168 (reader
->cu
->per_cu
->debug_types_section
9171 reader
->abfd
->filename
);
9172 dump_die (result
, dwarf2_die_debug
);
9178 /* Read a single die and all its descendents. Set the die's sibling
9179 field to NULL; set other fields in the die correctly, and set all
9180 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
9181 location of the info_ptr after reading all of those dies. PARENT
9182 is the parent of the die in question. */
9184 static struct die_info
*
9185 read_die_and_children_1 (const struct die_reader_specs
*reader
,
9187 gdb_byte
**new_info_ptr
,
9188 struct die_info
*parent
)
9190 struct die_info
*die
;
9194 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
9197 *new_info_ptr
= cur_ptr
;
9200 store_in_ref_table (die
, reader
->cu
);
9203 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
9207 *new_info_ptr
= cur_ptr
;
9210 die
->sibling
= NULL
;
9211 die
->parent
= parent
;
9215 /* Read a die, all of its descendents, and all of its siblings; set
9216 all of the fields of all of the dies correctly. Arguments are as
9217 in read_die_and_children. */
9219 static struct die_info
*
9220 read_die_and_siblings (const struct die_reader_specs
*reader
,
9222 gdb_byte
**new_info_ptr
,
9223 struct die_info
*parent
)
9225 struct die_info
*first_die
, *last_sibling
;
9229 first_die
= last_sibling
= NULL
;
9233 struct die_info
*die
9234 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
9238 *new_info_ptr
= cur_ptr
;
9245 last_sibling
->sibling
= die
;
9251 /* Read the die from the .debug_info section buffer. Set DIEP to
9252 point to a newly allocated die with its information, except for its
9253 child, sibling, and parent fields. Set HAS_CHILDREN to tell
9254 whether the die has children or not. */
9257 read_full_die (const struct die_reader_specs
*reader
,
9258 struct die_info
**diep
, gdb_byte
*info_ptr
,
9261 unsigned int abbrev_number
, bytes_read
, i
, offset
;
9262 struct abbrev_info
*abbrev
;
9263 struct die_info
*die
;
9264 struct dwarf2_cu
*cu
= reader
->cu
;
9265 bfd
*abfd
= reader
->abfd
;
9267 offset
= info_ptr
- reader
->buffer
;
9268 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9269 info_ptr
+= bytes_read
;
9277 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
9279 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
9281 bfd_get_filename (abfd
));
9283 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
9284 die
->offset
= offset
;
9285 die
->tag
= abbrev
->tag
;
9286 die
->abbrev
= abbrev_number
;
9288 die
->num_attrs
= abbrev
->num_attrs
;
9290 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9291 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
9292 abfd
, info_ptr
, cu
);
9295 *has_children
= abbrev
->has_children
;
9299 /* In DWARF version 2, the description of the debugging information is
9300 stored in a separate .debug_abbrev section. Before we read any
9301 dies from a section we read in all abbreviations and install them
9302 in a hash table. This function also sets flags in CU describing
9303 the data found in the abbrev table. */
9306 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
)
9308 bfd
*abfd
= cu
->objfile
->obfd
;
9309 struct comp_unit_head
*cu_header
= &cu
->header
;
9310 gdb_byte
*abbrev_ptr
;
9311 struct abbrev_info
*cur_abbrev
;
9312 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
9313 unsigned int abbrev_form
, hash_number
;
9314 struct attr_abbrev
*cur_attrs
;
9315 unsigned int allocated_attrs
;
9317 /* Initialize dwarf2 abbrevs. */
9318 obstack_init (&cu
->abbrev_obstack
);
9319 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
9321 * sizeof (struct abbrev_info
*)));
9322 memset (cu
->dwarf2_abbrevs
, 0,
9323 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
9325 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
9326 &dwarf2_per_objfile
->abbrev
);
9327 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
9328 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9329 abbrev_ptr
+= bytes_read
;
9331 allocated_attrs
= ATTR_ALLOC_CHUNK
;
9332 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
9334 /* Loop until we reach an abbrev number of 0. */
9335 while (abbrev_number
)
9337 cur_abbrev
= dwarf_alloc_abbrev (cu
);
9339 /* read in abbrev header */
9340 cur_abbrev
->number
= abbrev_number
;
9341 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9342 abbrev_ptr
+= bytes_read
;
9343 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
9346 if (cur_abbrev
->tag
== DW_TAG_namespace
)
9347 cu
->has_namespace_info
= 1;
9349 /* now read in declarations */
9350 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9351 abbrev_ptr
+= bytes_read
;
9352 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9353 abbrev_ptr
+= bytes_read
;
9356 if (cur_abbrev
->num_attrs
== allocated_attrs
)
9358 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
9360 = xrealloc (cur_attrs
, (allocated_attrs
9361 * sizeof (struct attr_abbrev
)));
9364 /* Record whether this compilation unit might have
9365 inter-compilation-unit references. If we don't know what form
9366 this attribute will have, then it might potentially be a
9367 DW_FORM_ref_addr, so we conservatively expect inter-CU
9370 if (abbrev_form
== DW_FORM_ref_addr
9371 || abbrev_form
== DW_FORM_indirect
)
9372 cu
->has_form_ref_addr
= 1;
9374 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
9375 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
9376 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9377 abbrev_ptr
+= bytes_read
;
9378 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9379 abbrev_ptr
+= bytes_read
;
9382 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
9383 (cur_abbrev
->num_attrs
9384 * sizeof (struct attr_abbrev
)));
9385 memcpy (cur_abbrev
->attrs
, cur_attrs
,
9386 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
9388 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
9389 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
9390 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
9392 /* Get next abbreviation.
9393 Under Irix6 the abbreviations for a compilation unit are not
9394 always properly terminated with an abbrev number of 0.
9395 Exit loop if we encounter an abbreviation which we have
9396 already read (which means we are about to read the abbreviations
9397 for the next compile unit) or if the end of the abbreviation
9398 table is reached. */
9399 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
9400 >= dwarf2_per_objfile
->abbrev
.size
)
9402 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9403 abbrev_ptr
+= bytes_read
;
9404 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
9411 /* Release the memory used by the abbrev table for a compilation unit. */
9414 dwarf2_free_abbrev_table (void *ptr_to_cu
)
9416 struct dwarf2_cu
*cu
= ptr_to_cu
;
9418 obstack_free (&cu
->abbrev_obstack
, NULL
);
9419 cu
->dwarf2_abbrevs
= NULL
;
9422 /* Lookup an abbrev_info structure in the abbrev hash table. */
9424 static struct abbrev_info
*
9425 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
9427 unsigned int hash_number
;
9428 struct abbrev_info
*abbrev
;
9430 hash_number
= number
% ABBREV_HASH_SIZE
;
9431 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
9435 if (abbrev
->number
== number
)
9438 abbrev
= abbrev
->next
;
9443 /* Returns nonzero if TAG represents a type that we might generate a partial
9447 is_type_tag_for_partial (int tag
)
9452 /* Some types that would be reasonable to generate partial symbols for,
9453 that we don't at present. */
9454 case DW_TAG_array_type
:
9455 case DW_TAG_file_type
:
9456 case DW_TAG_ptr_to_member_type
:
9457 case DW_TAG_set_type
:
9458 case DW_TAG_string_type
:
9459 case DW_TAG_subroutine_type
:
9461 case DW_TAG_base_type
:
9462 case DW_TAG_class_type
:
9463 case DW_TAG_interface_type
:
9464 case DW_TAG_enumeration_type
:
9465 case DW_TAG_structure_type
:
9466 case DW_TAG_subrange_type
:
9467 case DW_TAG_typedef
:
9468 case DW_TAG_union_type
:
9475 /* Load all DIEs that are interesting for partial symbols into memory. */
9477 static struct partial_die_info
*
9478 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9479 int building_psymtab
, struct dwarf2_cu
*cu
)
9481 struct objfile
*objfile
= cu
->objfile
;
9482 struct partial_die_info
*part_die
;
9483 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
9484 struct abbrev_info
*abbrev
;
9485 unsigned int bytes_read
;
9486 unsigned int load_all
= 0;
9488 int nesting_level
= 1;
9493 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
9497 = htab_create_alloc_ex (cu
->header
.length
/ 12,
9501 &cu
->comp_unit_obstack
,
9502 hashtab_obstack_allocate
,
9503 dummy_obstack_deallocate
);
9505 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9506 sizeof (struct partial_die_info
));
9510 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
9512 /* A NULL abbrev means the end of a series of children. */
9515 if (--nesting_level
== 0)
9517 /* PART_DIE was probably the last thing allocated on the
9518 comp_unit_obstack, so we could call obstack_free
9519 here. We don't do that because the waste is small,
9520 and will be cleaned up when we're done with this
9521 compilation unit. This way, we're also more robust
9522 against other users of the comp_unit_obstack. */
9525 info_ptr
+= bytes_read
;
9526 last_die
= parent_die
;
9527 parent_die
= parent_die
->die_parent
;
9531 /* Check for template arguments. We never save these; if
9532 they're seen, we just mark the parent, and go on our way. */
9533 if (parent_die
!= NULL
9534 && cu
->language
== language_cplus
9535 && (abbrev
->tag
== DW_TAG_template_type_param
9536 || abbrev
->tag
== DW_TAG_template_value_param
))
9538 parent_die
->has_template_arguments
= 1;
9542 /* We don't need a partial DIE for the template argument. */
9543 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
,
9549 /* We only recurse into subprograms looking for template arguments.
9550 Skip their other children. */
9552 && cu
->language
== language_cplus
9553 && parent_die
!= NULL
9554 && parent_die
->tag
== DW_TAG_subprogram
)
9556 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
9560 /* Check whether this DIE is interesting enough to save. Normally
9561 we would not be interested in members here, but there may be
9562 later variables referencing them via DW_AT_specification (for
9565 && !is_type_tag_for_partial (abbrev
->tag
)
9566 && abbrev
->tag
!= DW_TAG_constant
9567 && abbrev
->tag
!= DW_TAG_enumerator
9568 && abbrev
->tag
!= DW_TAG_subprogram
9569 && abbrev
->tag
!= DW_TAG_lexical_block
9570 && abbrev
->tag
!= DW_TAG_variable
9571 && abbrev
->tag
!= DW_TAG_namespace
9572 && abbrev
->tag
!= DW_TAG_module
9573 && abbrev
->tag
!= DW_TAG_member
)
9575 /* Otherwise we skip to the next sibling, if any. */
9576 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
9580 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
9581 buffer
, info_ptr
, cu
);
9583 /* This two-pass algorithm for processing partial symbols has a
9584 high cost in cache pressure. Thus, handle some simple cases
9585 here which cover the majority of C partial symbols. DIEs
9586 which neither have specification tags in them, nor could have
9587 specification tags elsewhere pointing at them, can simply be
9588 processed and discarded.
9590 This segment is also optional; scan_partial_symbols and
9591 add_partial_symbol will handle these DIEs if we chain
9592 them in normally. When compilers which do not emit large
9593 quantities of duplicate debug information are more common,
9594 this code can probably be removed. */
9596 /* Any complete simple types at the top level (pretty much all
9597 of them, for a language without namespaces), can be processed
9599 if (parent_die
== NULL
9600 && part_die
->has_specification
== 0
9601 && part_die
->is_declaration
== 0
9602 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
9603 || part_die
->tag
== DW_TAG_base_type
9604 || part_die
->tag
== DW_TAG_subrange_type
))
9606 if (building_psymtab
&& part_die
->name
!= NULL
)
9607 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9608 VAR_DOMAIN
, LOC_TYPEDEF
,
9609 &objfile
->static_psymbols
,
9610 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
9611 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9615 /* The exception for DW_TAG_typedef with has_children above is
9616 a workaround of GCC PR debug/47510. In the case of this complaint
9617 type_name_no_tag_or_error will error on such types later.
9619 GDB skipped children of DW_TAG_typedef by the shortcut above and then
9620 it could not find the child DIEs referenced later, this is checked
9621 above. In correct DWARF DW_TAG_typedef should have no children. */
9623 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
9624 complaint (&symfile_complaints
,
9625 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
9626 "- DIE at 0x%x [in module %s]"),
9627 part_die
->offset
, objfile
->name
);
9629 /* If we're at the second level, and we're an enumerator, and
9630 our parent has no specification (meaning possibly lives in a
9631 namespace elsewhere), then we can add the partial symbol now
9632 instead of queueing it. */
9633 if (part_die
->tag
== DW_TAG_enumerator
9634 && parent_die
!= NULL
9635 && parent_die
->die_parent
== NULL
9636 && parent_die
->tag
== DW_TAG_enumeration_type
9637 && parent_die
->has_specification
== 0)
9639 if (part_die
->name
== NULL
)
9640 complaint (&symfile_complaints
,
9641 _("malformed enumerator DIE ignored"));
9642 else if (building_psymtab
)
9643 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9644 VAR_DOMAIN
, LOC_CONST
,
9645 (cu
->language
== language_cplus
9646 || cu
->language
== language_java
)
9647 ? &objfile
->global_psymbols
9648 : &objfile
->static_psymbols
,
9649 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
9651 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9655 /* We'll save this DIE so link it in. */
9656 part_die
->die_parent
= parent_die
;
9657 part_die
->die_sibling
= NULL
;
9658 part_die
->die_child
= NULL
;
9660 if (last_die
&& last_die
== parent_die
)
9661 last_die
->die_child
= part_die
;
9663 last_die
->die_sibling
= part_die
;
9665 last_die
= part_die
;
9667 if (first_die
== NULL
)
9668 first_die
= part_die
;
9670 /* Maybe add the DIE to the hash table. Not all DIEs that we
9671 find interesting need to be in the hash table, because we
9672 also have the parent/sibling/child chains; only those that we
9673 might refer to by offset later during partial symbol reading.
9675 For now this means things that might have be the target of a
9676 DW_AT_specification, DW_AT_abstract_origin, or
9677 DW_AT_extension. DW_AT_extension will refer only to
9678 namespaces; DW_AT_abstract_origin refers to functions (and
9679 many things under the function DIE, but we do not recurse
9680 into function DIEs during partial symbol reading) and
9681 possibly variables as well; DW_AT_specification refers to
9682 declarations. Declarations ought to have the DW_AT_declaration
9683 flag. It happens that GCC forgets to put it in sometimes, but
9684 only for functions, not for types.
9686 Adding more things than necessary to the hash table is harmless
9687 except for the performance cost. Adding too few will result in
9688 wasted time in find_partial_die, when we reread the compilation
9689 unit with load_all_dies set. */
9692 || abbrev
->tag
== DW_TAG_constant
9693 || abbrev
->tag
== DW_TAG_subprogram
9694 || abbrev
->tag
== DW_TAG_variable
9695 || abbrev
->tag
== DW_TAG_namespace
9696 || part_die
->is_declaration
)
9700 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
9701 part_die
->offset
, INSERT
);
9705 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9706 sizeof (struct partial_die_info
));
9708 /* For some DIEs we want to follow their children (if any). For C
9709 we have no reason to follow the children of structures; for other
9710 languages we have to, so that we can get at method physnames
9711 to infer fully qualified class names, for DW_AT_specification,
9712 and for C++ template arguments. For C++, we also look one level
9713 inside functions to find template arguments (if the name of the
9714 function does not already contain the template arguments).
9716 For Ada, we need to scan the children of subprograms and lexical
9717 blocks as well because Ada allows the definition of nested
9718 entities that could be interesting for the debugger, such as
9719 nested subprograms for instance. */
9720 if (last_die
->has_children
9722 || last_die
->tag
== DW_TAG_namespace
9723 || last_die
->tag
== DW_TAG_module
9724 || last_die
->tag
== DW_TAG_enumeration_type
9725 || (cu
->language
== language_cplus
9726 && last_die
->tag
== DW_TAG_subprogram
9727 && (last_die
->name
== NULL
9728 || strchr (last_die
->name
, '<') == NULL
))
9729 || (cu
->language
!= language_c
9730 && (last_die
->tag
== DW_TAG_class_type
9731 || last_die
->tag
== DW_TAG_interface_type
9732 || last_die
->tag
== DW_TAG_structure_type
9733 || last_die
->tag
== DW_TAG_union_type
))
9734 || (cu
->language
== language_ada
9735 && (last_die
->tag
== DW_TAG_subprogram
9736 || last_die
->tag
== DW_TAG_lexical_block
))))
9739 parent_die
= last_die
;
9743 /* Otherwise we skip to the next sibling, if any. */
9744 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
9746 /* Back to the top, do it again. */
9750 /* Read a minimal amount of information into the minimal die structure. */
9753 read_partial_die (struct partial_die_info
*part_die
,
9754 struct abbrev_info
*abbrev
,
9755 unsigned int abbrev_len
, bfd
*abfd
,
9756 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9757 struct dwarf2_cu
*cu
)
9759 struct objfile
*objfile
= cu
->objfile
;
9761 struct attribute attr
;
9762 int has_low_pc_attr
= 0;
9763 int has_high_pc_attr
= 0;
9765 memset (part_die
, 0, sizeof (struct partial_die_info
));
9767 part_die
->offset
= info_ptr
- buffer
;
9769 info_ptr
+= abbrev_len
;
9774 part_die
->tag
= abbrev
->tag
;
9775 part_die
->has_children
= abbrev
->has_children
;
9777 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9779 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
9781 /* Store the data if it is of an attribute we want to keep in a
9782 partial symbol table. */
9786 switch (part_die
->tag
)
9788 case DW_TAG_compile_unit
:
9789 case DW_TAG_type_unit
:
9790 /* Compilation units have a DW_AT_name that is a filename, not
9791 a source language identifier. */
9792 case DW_TAG_enumeration_type
:
9793 case DW_TAG_enumerator
:
9794 /* These tags always have simple identifiers already; no need
9795 to canonicalize them. */
9796 part_die
->name
= DW_STRING (&attr
);
9800 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
9801 &objfile
->objfile_obstack
);
9805 case DW_AT_linkage_name
:
9806 case DW_AT_MIPS_linkage_name
:
9807 /* Note that both forms of linkage name might appear. We
9808 assume they will be the same, and we only store the last
9810 if (cu
->language
== language_ada
)
9811 part_die
->name
= DW_STRING (&attr
);
9812 part_die
->linkage_name
= DW_STRING (&attr
);
9815 has_low_pc_attr
= 1;
9816 part_die
->lowpc
= DW_ADDR (&attr
);
9819 has_high_pc_attr
= 1;
9820 part_die
->highpc
= DW_ADDR (&attr
);
9822 case DW_AT_location
:
9823 /* Support the .debug_loc offsets. */
9824 if (attr_form_is_block (&attr
))
9826 part_die
->locdesc
= DW_BLOCK (&attr
);
9828 else if (attr_form_is_section_offset (&attr
))
9830 dwarf2_complex_location_expr_complaint ();
9834 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9835 "partial symbol information");
9838 case DW_AT_external
:
9839 part_die
->is_external
= DW_UNSND (&attr
);
9841 case DW_AT_declaration
:
9842 part_die
->is_declaration
= DW_UNSND (&attr
);
9845 part_die
->has_type
= 1;
9847 case DW_AT_abstract_origin
:
9848 case DW_AT_specification
:
9849 case DW_AT_extension
:
9850 part_die
->has_specification
= 1;
9851 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
9854 /* Ignore absolute siblings, they might point outside of
9855 the current compile unit. */
9856 if (attr
.form
== DW_FORM_ref_addr
)
9857 complaint (&symfile_complaints
,
9858 _("ignoring absolute DW_AT_sibling"));
9860 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
9862 case DW_AT_byte_size
:
9863 part_die
->has_byte_size
= 1;
9865 case DW_AT_calling_convention
:
9866 /* DWARF doesn't provide a way to identify a program's source-level
9867 entry point. DW_AT_calling_convention attributes are only meant
9868 to describe functions' calling conventions.
9870 However, because it's a necessary piece of information in
9871 Fortran, and because DW_CC_program is the only piece of debugging
9872 information whose definition refers to a 'main program' at all,
9873 several compilers have begun marking Fortran main programs with
9874 DW_CC_program --- even when those functions use the standard
9875 calling conventions.
9877 So until DWARF specifies a way to provide this information and
9878 compilers pick up the new representation, we'll support this
9880 if (DW_UNSND (&attr
) == DW_CC_program
9881 && cu
->language
== language_fortran
)
9883 set_main_name (part_die
->name
);
9885 /* As this DIE has a static linkage the name would be difficult
9886 to look up later. */
9887 language_of_main
= language_fortran
;
9895 if (has_low_pc_attr
&& has_high_pc_attr
)
9897 /* When using the GNU linker, .gnu.linkonce. sections are used to
9898 eliminate duplicate copies of functions and vtables and such.
9899 The linker will arbitrarily choose one and discard the others.
9900 The AT_*_pc values for such functions refer to local labels in
9901 these sections. If the section from that file was discarded, the
9902 labels are not in the output, so the relocs get a value of 0.
9903 If this is a discarded function, mark the pc bounds as invalid,
9904 so that GDB will ignore it. */
9905 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
9907 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9909 complaint (&symfile_complaints
,
9910 _("DW_AT_low_pc %s is zero "
9911 "for DIE at 0x%x [in module %s]"),
9912 paddress (gdbarch
, part_die
->lowpc
),
9913 part_die
->offset
, objfile
->name
);
9915 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
9916 else if (part_die
->lowpc
>= part_die
->highpc
)
9918 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9920 complaint (&symfile_complaints
,
9921 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
9922 "for DIE at 0x%x [in module %s]"),
9923 paddress (gdbarch
, part_die
->lowpc
),
9924 paddress (gdbarch
, part_die
->highpc
),
9925 part_die
->offset
, objfile
->name
);
9928 part_die
->has_pc_info
= 1;
9934 /* Find a cached partial DIE at OFFSET in CU. */
9936 static struct partial_die_info
*
9937 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
9939 struct partial_die_info
*lookup_die
= NULL
;
9940 struct partial_die_info part_die
;
9942 part_die
.offset
= offset
;
9943 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
9948 /* Find a partial DIE at OFFSET, which may or may not be in CU,
9949 except in the case of .debug_types DIEs which do not reference
9950 outside their CU (they do however referencing other types via
9951 DW_FORM_ref_sig8). */
9953 static struct partial_die_info
*
9954 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
9956 struct objfile
*objfile
= cu
->objfile
;
9957 struct dwarf2_per_cu_data
*per_cu
= NULL
;
9958 struct partial_die_info
*pd
= NULL
;
9960 if (cu
->per_cu
->debug_types_section
)
9962 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9968 if (offset_in_cu_p (&cu
->header
, offset
))
9970 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9975 per_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
9977 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
9978 load_partial_comp_unit (per_cu
);
9980 per_cu
->cu
->last_used
= 0;
9981 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
9983 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
9985 struct cleanup
*back_to
;
9986 struct partial_die_info comp_unit_die
;
9987 struct abbrev_info
*abbrev
;
9988 unsigned int bytes_read
;
9991 per_cu
->load_all_dies
= 1;
9993 /* Re-read the DIEs. */
9994 back_to
= make_cleanup (null_cleanup
, 0);
9995 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
9997 dwarf2_read_abbrevs (per_cu
->cu
);
9998 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
10000 info_ptr
= (dwarf2_per_objfile
->info
.buffer
10001 + per_cu
->cu
->header
.offset
10002 + per_cu
->cu
->header
.first_die_offset
);
10003 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
10004 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
10006 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
10008 if (comp_unit_die
.has_children
)
10009 load_partial_dies (objfile
->obfd
,
10010 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
10012 do_cleanups (back_to
);
10014 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
10020 internal_error (__FILE__
, __LINE__
,
10021 _("could not find partial DIE 0x%x "
10022 "in cache [from module %s]\n"),
10023 offset
, bfd_get_filename (objfile
->obfd
));
10027 /* See if we can figure out if the class lives in a namespace. We do
10028 this by looking for a member function; its demangled name will
10029 contain namespace info, if there is any. */
10032 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
10033 struct dwarf2_cu
*cu
)
10035 /* NOTE: carlton/2003-10-07: Getting the info this way changes
10036 what template types look like, because the demangler
10037 frequently doesn't give the same name as the debug info. We
10038 could fix this by only using the demangled name to get the
10039 prefix (but see comment in read_structure_type). */
10041 struct partial_die_info
*real_pdi
;
10042 struct partial_die_info
*child_pdi
;
10044 /* If this DIE (this DIE's specification, if any) has a parent, then
10045 we should not do this. We'll prepend the parent's fully qualified
10046 name when we create the partial symbol. */
10048 real_pdi
= struct_pdi
;
10049 while (real_pdi
->has_specification
)
10050 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
10052 if (real_pdi
->die_parent
!= NULL
)
10055 for (child_pdi
= struct_pdi
->die_child
;
10057 child_pdi
= child_pdi
->die_sibling
)
10059 if (child_pdi
->tag
== DW_TAG_subprogram
10060 && child_pdi
->linkage_name
!= NULL
)
10062 char *actual_class_name
10063 = language_class_name_from_physname (cu
->language_defn
,
10064 child_pdi
->linkage_name
);
10065 if (actual_class_name
!= NULL
)
10068 = obsavestring (actual_class_name
,
10069 strlen (actual_class_name
),
10070 &cu
->objfile
->objfile_obstack
);
10071 xfree (actual_class_name
);
10078 /* Adjust PART_DIE before generating a symbol for it. This function
10079 may set the is_external flag or change the DIE's name. */
10082 fixup_partial_die (struct partial_die_info
*part_die
,
10083 struct dwarf2_cu
*cu
)
10085 /* Once we've fixed up a die, there's no point in doing so again.
10086 This also avoids a memory leak if we were to call
10087 guess_partial_die_structure_name multiple times. */
10088 if (part_die
->fixup_called
)
10091 /* If we found a reference attribute and the DIE has no name, try
10092 to find a name in the referred to DIE. */
10094 if (part_die
->name
== NULL
&& part_die
->has_specification
)
10096 struct partial_die_info
*spec_die
;
10098 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
10100 fixup_partial_die (spec_die
, cu
);
10102 if (spec_die
->name
)
10104 part_die
->name
= spec_die
->name
;
10106 /* Copy DW_AT_external attribute if it is set. */
10107 if (spec_die
->is_external
)
10108 part_die
->is_external
= spec_die
->is_external
;
10112 /* Set default names for some unnamed DIEs. */
10114 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
10115 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
10117 /* If there is no parent die to provide a namespace, and there are
10118 children, see if we can determine the namespace from their linkage
10120 NOTE: We need to do this even if cu->has_namespace_info != 0.
10121 gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */
10122 if (cu
->language
== language_cplus
10123 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
10124 && part_die
->die_parent
== NULL
10125 && part_die
->has_children
10126 && (part_die
->tag
== DW_TAG_class_type
10127 || part_die
->tag
== DW_TAG_structure_type
10128 || part_die
->tag
== DW_TAG_union_type
))
10129 guess_partial_die_structure_name (part_die
, cu
);
10131 /* GCC might emit a nameless struct or union that has a linkage
10132 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
10133 if (part_die
->name
== NULL
10134 && (part_die
->tag
== DW_TAG_class_type
10135 || part_die
->tag
== DW_TAG_interface_type
10136 || part_die
->tag
== DW_TAG_structure_type
10137 || part_die
->tag
== DW_TAG_union_type
)
10138 && part_die
->linkage_name
!= NULL
)
10142 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
10147 /* Strip any leading namespaces/classes, keep only the base name.
10148 DW_AT_name for named DIEs does not contain the prefixes. */
10149 base
= strrchr (demangled
, ':');
10150 if (base
&& base
> demangled
&& base
[-1] == ':')
10155 part_die
->name
= obsavestring (base
, strlen (base
),
10156 &cu
->objfile
->objfile_obstack
);
10161 part_die
->fixup_called
= 1;
10164 /* Read an attribute value described by an attribute form. */
10167 read_attribute_value (struct attribute
*attr
, unsigned form
,
10168 bfd
*abfd
, gdb_byte
*info_ptr
,
10169 struct dwarf2_cu
*cu
)
10171 struct comp_unit_head
*cu_header
= &cu
->header
;
10172 unsigned int bytes_read
;
10173 struct dwarf_block
*blk
;
10178 case DW_FORM_ref_addr
:
10179 if (cu
->header
.version
== 2)
10180 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
10182 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
,
10183 &cu
->header
, &bytes_read
);
10184 info_ptr
+= bytes_read
;
10187 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
10188 info_ptr
+= bytes_read
;
10190 case DW_FORM_block2
:
10191 blk
= dwarf_alloc_block (cu
);
10192 blk
->size
= read_2_bytes (abfd
, info_ptr
);
10194 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10195 info_ptr
+= blk
->size
;
10196 DW_BLOCK (attr
) = blk
;
10198 case DW_FORM_block4
:
10199 blk
= dwarf_alloc_block (cu
);
10200 blk
->size
= read_4_bytes (abfd
, info_ptr
);
10202 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10203 info_ptr
+= blk
->size
;
10204 DW_BLOCK (attr
) = blk
;
10206 case DW_FORM_data2
:
10207 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
10210 case DW_FORM_data4
:
10211 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
10214 case DW_FORM_data8
:
10215 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
10218 case DW_FORM_sec_offset
:
10219 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
10220 info_ptr
+= bytes_read
;
10222 case DW_FORM_string
:
10223 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
10224 DW_STRING_IS_CANONICAL (attr
) = 0;
10225 info_ptr
+= bytes_read
;
10228 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
10230 DW_STRING_IS_CANONICAL (attr
) = 0;
10231 info_ptr
+= bytes_read
;
10233 case DW_FORM_exprloc
:
10234 case DW_FORM_block
:
10235 blk
= dwarf_alloc_block (cu
);
10236 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10237 info_ptr
+= bytes_read
;
10238 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10239 info_ptr
+= blk
->size
;
10240 DW_BLOCK (attr
) = blk
;
10242 case DW_FORM_block1
:
10243 blk
= dwarf_alloc_block (cu
);
10244 blk
->size
= read_1_byte (abfd
, info_ptr
);
10246 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10247 info_ptr
+= blk
->size
;
10248 DW_BLOCK (attr
) = blk
;
10250 case DW_FORM_data1
:
10251 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
10255 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
10258 case DW_FORM_flag_present
:
10259 DW_UNSND (attr
) = 1;
10261 case DW_FORM_sdata
:
10262 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
10263 info_ptr
+= bytes_read
;
10265 case DW_FORM_udata
:
10266 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10267 info_ptr
+= bytes_read
;
10270 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
10274 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
10278 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
10282 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
10285 case DW_FORM_ref_sig8
:
10286 /* Convert the signature to something we can record in DW_UNSND
10288 NOTE: This is NULL if the type wasn't found. */
10289 DW_SIGNATURED_TYPE (attr
) =
10290 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
10293 case DW_FORM_ref_udata
:
10294 DW_ADDR (attr
) = (cu
->header
.offset
10295 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
10296 info_ptr
+= bytes_read
;
10298 case DW_FORM_indirect
:
10299 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10300 info_ptr
+= bytes_read
;
10301 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
10304 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
10305 dwarf_form_name (form
),
10306 bfd_get_filename (abfd
));
10309 /* We have seen instances where the compiler tried to emit a byte
10310 size attribute of -1 which ended up being encoded as an unsigned
10311 0xffffffff. Although 0xffffffff is technically a valid size value,
10312 an object of this size seems pretty unlikely so we can relatively
10313 safely treat these cases as if the size attribute was invalid and
10314 treat them as zero by default. */
10315 if (attr
->name
== DW_AT_byte_size
10316 && form
== DW_FORM_data4
10317 && DW_UNSND (attr
) >= 0xffffffff)
10320 (&symfile_complaints
,
10321 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
10322 hex_string (DW_UNSND (attr
)));
10323 DW_UNSND (attr
) = 0;
10329 /* Read an attribute described by an abbreviated attribute. */
10332 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
10333 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
10335 attr
->name
= abbrev
->name
;
10336 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
10339 /* Read dwarf information from a buffer. */
10341 static unsigned int
10342 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
10344 return bfd_get_8 (abfd
, buf
);
10348 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
10350 return bfd_get_signed_8 (abfd
, buf
);
10353 static unsigned int
10354 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
10356 return bfd_get_16 (abfd
, buf
);
10360 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
10362 return bfd_get_signed_16 (abfd
, buf
);
10365 static unsigned int
10366 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
10368 return bfd_get_32 (abfd
, buf
);
10372 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
10374 return bfd_get_signed_32 (abfd
, buf
);
10378 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
10380 return bfd_get_64 (abfd
, buf
);
10384 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
10385 unsigned int *bytes_read
)
10387 struct comp_unit_head
*cu_header
= &cu
->header
;
10388 CORE_ADDR retval
= 0;
10390 if (cu_header
->signed_addr_p
)
10392 switch (cu_header
->addr_size
)
10395 retval
= bfd_get_signed_16 (abfd
, buf
);
10398 retval
= bfd_get_signed_32 (abfd
, buf
);
10401 retval
= bfd_get_signed_64 (abfd
, buf
);
10404 internal_error (__FILE__
, __LINE__
,
10405 _("read_address: bad switch, signed [in module %s]"),
10406 bfd_get_filename (abfd
));
10411 switch (cu_header
->addr_size
)
10414 retval
= bfd_get_16 (abfd
, buf
);
10417 retval
= bfd_get_32 (abfd
, buf
);
10420 retval
= bfd_get_64 (abfd
, buf
);
10423 internal_error (__FILE__
, __LINE__
,
10424 _("read_address: bad switch, "
10425 "unsigned [in module %s]"),
10426 bfd_get_filename (abfd
));
10430 *bytes_read
= cu_header
->addr_size
;
10434 /* Read the initial length from a section. The (draft) DWARF 3
10435 specification allows the initial length to take up either 4 bytes
10436 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
10437 bytes describe the length and all offsets will be 8 bytes in length
10440 An older, non-standard 64-bit format is also handled by this
10441 function. The older format in question stores the initial length
10442 as an 8-byte quantity without an escape value. Lengths greater
10443 than 2^32 aren't very common which means that the initial 4 bytes
10444 is almost always zero. Since a length value of zero doesn't make
10445 sense for the 32-bit format, this initial zero can be considered to
10446 be an escape value which indicates the presence of the older 64-bit
10447 format. As written, the code can't detect (old format) lengths
10448 greater than 4GB. If it becomes necessary to handle lengths
10449 somewhat larger than 4GB, we could allow other small values (such
10450 as the non-sensical values of 1, 2, and 3) to also be used as
10451 escape values indicating the presence of the old format.
10453 The value returned via bytes_read should be used to increment the
10454 relevant pointer after calling read_initial_length().
10456 [ Note: read_initial_length() and read_offset() are based on the
10457 document entitled "DWARF Debugging Information Format", revision
10458 3, draft 8, dated November 19, 2001. This document was obtained
10461 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
10463 This document is only a draft and is subject to change. (So beware.)
10465 Details regarding the older, non-standard 64-bit format were
10466 determined empirically by examining 64-bit ELF files produced by
10467 the SGI toolchain on an IRIX 6.5 machine.
10469 - Kevin, July 16, 2002
10473 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
10475 LONGEST length
= bfd_get_32 (abfd
, buf
);
10477 if (length
== 0xffffffff)
10479 length
= bfd_get_64 (abfd
, buf
+ 4);
10482 else if (length
== 0)
10484 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
10485 length
= bfd_get_64 (abfd
, buf
);
10496 /* Cover function for read_initial_length.
10497 Returns the length of the object at BUF, and stores the size of the
10498 initial length in *BYTES_READ and stores the size that offsets will be in
10500 If the initial length size is not equivalent to that specified in
10501 CU_HEADER then issue a complaint.
10502 This is useful when reading non-comp-unit headers. */
10505 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
10506 const struct comp_unit_head
*cu_header
,
10507 unsigned int *bytes_read
,
10508 unsigned int *offset_size
)
10510 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
10512 gdb_assert (cu_header
->initial_length_size
== 4
10513 || cu_header
->initial_length_size
== 8
10514 || cu_header
->initial_length_size
== 12);
10516 if (cu_header
->initial_length_size
!= *bytes_read
)
10517 complaint (&symfile_complaints
,
10518 _("intermixed 32-bit and 64-bit DWARF sections"));
10520 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
10524 /* Read an offset from the data stream. The size of the offset is
10525 given by cu_header->offset_size. */
10528 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
10529 unsigned int *bytes_read
)
10531 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
10533 *bytes_read
= cu_header
->offset_size
;
10537 /* Read an offset from the data stream. */
10540 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
10542 LONGEST retval
= 0;
10544 switch (offset_size
)
10547 retval
= bfd_get_32 (abfd
, buf
);
10550 retval
= bfd_get_64 (abfd
, buf
);
10553 internal_error (__FILE__
, __LINE__
,
10554 _("read_offset_1: bad switch [in module %s]"),
10555 bfd_get_filename (abfd
));
10562 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
10564 /* If the size of a host char is 8 bits, we can return a pointer
10565 to the buffer, otherwise we have to copy the data to a buffer
10566 allocated on the temporary obstack. */
10567 gdb_assert (HOST_CHAR_BIT
== 8);
10572 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10574 /* If the size of a host char is 8 bits, we can return a pointer
10575 to the string, otherwise we have to copy the string to a buffer
10576 allocated on the temporary obstack. */
10577 gdb_assert (HOST_CHAR_BIT
== 8);
10580 *bytes_read_ptr
= 1;
10583 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
10584 return (char *) buf
;
10588 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
10590 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
10591 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
10592 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
10593 bfd_get_filename (abfd
));
10594 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
10595 error (_("DW_FORM_strp pointing outside of "
10596 ".debug_str section [in module %s]"),
10597 bfd_get_filename (abfd
));
10598 gdb_assert (HOST_CHAR_BIT
== 8);
10599 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
10601 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
10605 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
10606 const struct comp_unit_head
*cu_header
,
10607 unsigned int *bytes_read_ptr
)
10609 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
10611 return read_indirect_string_at_offset (abfd
, str_offset
);
10614 static unsigned long
10615 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10617 unsigned long result
;
10618 unsigned int num_read
;
10620 unsigned char byte
;
10628 byte
= bfd_get_8 (abfd
, buf
);
10631 result
|= ((unsigned long)(byte
& 127) << shift
);
10632 if ((byte
& 128) == 0)
10638 *bytes_read_ptr
= num_read
;
10643 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10646 int i
, shift
, num_read
;
10647 unsigned char byte
;
10655 byte
= bfd_get_8 (abfd
, buf
);
10658 result
|= ((long)(byte
& 127) << shift
);
10660 if ((byte
& 128) == 0)
10665 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
10666 result
|= -(((long)1) << shift
);
10667 *bytes_read_ptr
= num_read
;
10671 /* Return a pointer to just past the end of an LEB128 number in BUF. */
10674 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
10680 byte
= bfd_get_8 (abfd
, buf
);
10682 if ((byte
& 128) == 0)
10688 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
10695 cu
->language
= language_c
;
10697 case DW_LANG_C_plus_plus
:
10698 cu
->language
= language_cplus
;
10701 cu
->language
= language_d
;
10703 case DW_LANG_Fortran77
:
10704 case DW_LANG_Fortran90
:
10705 case DW_LANG_Fortran95
:
10706 cu
->language
= language_fortran
;
10708 case DW_LANG_Mips_Assembler
:
10709 cu
->language
= language_asm
;
10712 cu
->language
= language_java
;
10714 case DW_LANG_Ada83
:
10715 case DW_LANG_Ada95
:
10716 cu
->language
= language_ada
;
10718 case DW_LANG_Modula2
:
10719 cu
->language
= language_m2
;
10721 case DW_LANG_Pascal83
:
10722 cu
->language
= language_pascal
;
10725 cu
->language
= language_objc
;
10727 case DW_LANG_Cobol74
:
10728 case DW_LANG_Cobol85
:
10730 cu
->language
= language_minimal
;
10733 cu
->language_defn
= language_def (cu
->language
);
10736 /* Return the named attribute or NULL if not there. */
10738 static struct attribute
*
10739 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
10742 struct attribute
*spec
= NULL
;
10744 for (i
= 0; i
< die
->num_attrs
; ++i
)
10746 if (die
->attrs
[i
].name
== name
)
10747 return &die
->attrs
[i
];
10748 if (die
->attrs
[i
].name
== DW_AT_specification
10749 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
10750 spec
= &die
->attrs
[i
];
10755 die
= follow_die_ref (die
, spec
, &cu
);
10756 return dwarf2_attr (die
, name
, cu
);
10762 /* Return the named attribute or NULL if not there,
10763 but do not follow DW_AT_specification, etc.
10764 This is for use in contexts where we're reading .debug_types dies.
10765 Following DW_AT_specification, DW_AT_abstract_origin will take us
10766 back up the chain, and we want to go down. */
10768 static struct attribute
*
10769 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
10770 struct dwarf2_cu
*cu
)
10774 for (i
= 0; i
< die
->num_attrs
; ++i
)
10775 if (die
->attrs
[i
].name
== name
)
10776 return &die
->attrs
[i
];
10781 /* Return non-zero iff the attribute NAME is defined for the given DIE,
10782 and holds a non-zero value. This function should only be used for
10783 DW_FORM_flag or DW_FORM_flag_present attributes. */
10786 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
10788 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
10790 return (attr
&& DW_UNSND (attr
));
10794 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
10796 /* A DIE is a declaration if it has a DW_AT_declaration attribute
10797 which value is non-zero. However, we have to be careful with
10798 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
10799 (via dwarf2_flag_true_p) follows this attribute. So we may
10800 end up accidently finding a declaration attribute that belongs
10801 to a different DIE referenced by the specification attribute,
10802 even though the given DIE does not have a declaration attribute. */
10803 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
10804 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
10807 /* Return the die giving the specification for DIE, if there is
10808 one. *SPEC_CU is the CU containing DIE on input, and the CU
10809 containing the return value on output. If there is no
10810 specification, but there is an abstract origin, that is
10813 static struct die_info
*
10814 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
10816 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
10819 if (spec_attr
== NULL
)
10820 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
10822 if (spec_attr
== NULL
)
10825 return follow_die_ref (die
, spec_attr
, spec_cu
);
10828 /* Free the line_header structure *LH, and any arrays and strings it
10830 NOTE: This is also used as a "cleanup" function. */
10833 free_line_header (struct line_header
*lh
)
10835 if (lh
->standard_opcode_lengths
)
10836 xfree (lh
->standard_opcode_lengths
);
10838 /* Remember that all the lh->file_names[i].name pointers are
10839 pointers into debug_line_buffer, and don't need to be freed. */
10840 if (lh
->file_names
)
10841 xfree (lh
->file_names
);
10843 /* Similarly for the include directory names. */
10844 if (lh
->include_dirs
)
10845 xfree (lh
->include_dirs
);
10850 /* Add an entry to LH's include directory table. */
10853 add_include_dir (struct line_header
*lh
, char *include_dir
)
10855 /* Grow the array if necessary. */
10856 if (lh
->include_dirs_size
== 0)
10858 lh
->include_dirs_size
= 1; /* for testing */
10859 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
10860 * sizeof (*lh
->include_dirs
));
10862 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
10864 lh
->include_dirs_size
*= 2;
10865 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
10866 (lh
->include_dirs_size
10867 * sizeof (*lh
->include_dirs
)));
10870 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
10873 /* Add an entry to LH's file name table. */
10876 add_file_name (struct line_header
*lh
,
10878 unsigned int dir_index
,
10879 unsigned int mod_time
,
10880 unsigned int length
)
10882 struct file_entry
*fe
;
10884 /* Grow the array if necessary. */
10885 if (lh
->file_names_size
== 0)
10887 lh
->file_names_size
= 1; /* for testing */
10888 lh
->file_names
= xmalloc (lh
->file_names_size
10889 * sizeof (*lh
->file_names
));
10891 else if (lh
->num_file_names
>= lh
->file_names_size
)
10893 lh
->file_names_size
*= 2;
10894 lh
->file_names
= xrealloc (lh
->file_names
,
10895 (lh
->file_names_size
10896 * sizeof (*lh
->file_names
)));
10899 fe
= &lh
->file_names
[lh
->num_file_names
++];
10901 fe
->dir_index
= dir_index
;
10902 fe
->mod_time
= mod_time
;
10903 fe
->length
= length
;
10904 fe
->included_p
= 0;
10908 /* Read the statement program header starting at OFFSET in
10909 .debug_line, according to the endianness of ABFD. Return a pointer
10910 to a struct line_header, allocated using xmalloc.
10912 NOTE: the strings in the include directory and file name tables of
10913 the returned object point into debug_line_buffer, and must not be
10916 static struct line_header
*
10917 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
10918 struct dwarf2_cu
*cu
)
10920 struct cleanup
*back_to
;
10921 struct line_header
*lh
;
10922 gdb_byte
*line_ptr
;
10923 unsigned int bytes_read
, offset_size
;
10925 char *cur_dir
, *cur_file
;
10927 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
10928 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
10930 complaint (&symfile_complaints
, _("missing .debug_line section"));
10934 /* Make sure that at least there's room for the total_length field.
10935 That could be 12 bytes long, but we're just going to fudge that. */
10936 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
10938 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10942 lh
= xmalloc (sizeof (*lh
));
10943 memset (lh
, 0, sizeof (*lh
));
10944 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
10947 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
10949 /* Read in the header. */
10951 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
10952 &bytes_read
, &offset_size
);
10953 line_ptr
+= bytes_read
;
10954 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
10955 + dwarf2_per_objfile
->line
.size
))
10957 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10960 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
10961 lh
->version
= read_2_bytes (abfd
, line_ptr
);
10963 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
10964 line_ptr
+= offset_size
;
10965 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
10967 if (lh
->version
>= 4)
10969 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
10973 lh
->maximum_ops_per_instruction
= 1;
10975 if (lh
->maximum_ops_per_instruction
== 0)
10977 lh
->maximum_ops_per_instruction
= 1;
10978 complaint (&symfile_complaints
,
10979 _("invalid maximum_ops_per_instruction "
10980 "in `.debug_line' section"));
10983 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
10985 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
10987 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
10989 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
10991 lh
->standard_opcode_lengths
10992 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
10994 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
10995 for (i
= 1; i
< lh
->opcode_base
; ++i
)
10997 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
11001 /* Read directory table. */
11002 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
11004 line_ptr
+= bytes_read
;
11005 add_include_dir (lh
, cur_dir
);
11007 line_ptr
+= bytes_read
;
11009 /* Read file name table. */
11010 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
11012 unsigned int dir_index
, mod_time
, length
;
11014 line_ptr
+= bytes_read
;
11015 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11016 line_ptr
+= bytes_read
;
11017 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11018 line_ptr
+= bytes_read
;
11019 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11020 line_ptr
+= bytes_read
;
11022 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
11024 line_ptr
+= bytes_read
;
11025 lh
->statement_program_start
= line_ptr
;
11027 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
11028 + dwarf2_per_objfile
->line
.size
))
11029 complaint (&symfile_complaints
,
11030 _("line number info header doesn't "
11031 "fit in `.debug_line' section"));
11033 discard_cleanups (back_to
);
11037 /* Subroutine of dwarf_decode_lines to simplify it.
11038 Return the file name of the psymtab for included file FILE_INDEX
11039 in line header LH of PST.
11040 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
11041 If space for the result is malloc'd, it will be freed by a cleanup.
11042 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
11045 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
11046 const struct partial_symtab
*pst
,
11047 const char *comp_dir
)
11049 const struct file_entry fe
= lh
->file_names
[file_index
];
11050 char *include_name
= fe
.name
;
11051 char *include_name_to_compare
= include_name
;
11052 char *dir_name
= NULL
;
11053 const char *pst_filename
;
11054 char *copied_name
= NULL
;
11058 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
11060 if (!IS_ABSOLUTE_PATH (include_name
)
11061 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
11063 /* Avoid creating a duplicate psymtab for PST.
11064 We do this by comparing INCLUDE_NAME and PST_FILENAME.
11065 Before we do the comparison, however, we need to account
11066 for DIR_NAME and COMP_DIR.
11067 First prepend dir_name (if non-NULL). If we still don't
11068 have an absolute path prepend comp_dir (if non-NULL).
11069 However, the directory we record in the include-file's
11070 psymtab does not contain COMP_DIR (to match the
11071 corresponding symtab(s)).
11076 bash$ gcc -g ./hello.c
11077 include_name = "hello.c"
11079 DW_AT_comp_dir = comp_dir = "/tmp"
11080 DW_AT_name = "./hello.c" */
11082 if (dir_name
!= NULL
)
11084 include_name
= concat (dir_name
, SLASH_STRING
,
11085 include_name
, (char *)NULL
);
11086 include_name_to_compare
= include_name
;
11087 make_cleanup (xfree
, include_name
);
11089 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
11091 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
11092 include_name
, (char *)NULL
);
11096 pst_filename
= pst
->filename
;
11097 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
11099 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
11100 pst_filename
, (char *)NULL
);
11101 pst_filename
= copied_name
;
11104 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
11106 if (include_name_to_compare
!= include_name
)
11107 xfree (include_name_to_compare
);
11108 if (copied_name
!= NULL
)
11109 xfree (copied_name
);
11113 return include_name
;
11116 /* Ignore this record_line request. */
11119 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
11124 /* Subroutine of dwarf_decode_lines to simplify it.
11125 Process the line number information in LH. */
11128 dwarf_decode_lines_1 (struct line_header
*lh
, const char *comp_dir
,
11129 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
11131 gdb_byte
*line_ptr
, *extended_end
;
11132 gdb_byte
*line_end
;
11133 unsigned int bytes_read
, extended_len
;
11134 unsigned char op_code
, extended_op
, adj_opcode
;
11135 CORE_ADDR baseaddr
;
11136 struct objfile
*objfile
= cu
->objfile
;
11137 bfd
*abfd
= objfile
->obfd
;
11138 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11139 const int decode_for_pst_p
= (pst
!= NULL
);
11140 struct subfile
*last_subfile
= NULL
;
11141 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
11144 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11146 line_ptr
= lh
->statement_program_start
;
11147 line_end
= lh
->statement_program_end
;
11149 /* Read the statement sequences until there's nothing left. */
11150 while (line_ptr
< line_end
)
11152 /* state machine registers */
11153 CORE_ADDR address
= 0;
11154 unsigned int file
= 1;
11155 unsigned int line
= 1;
11156 unsigned int column
= 0;
11157 int is_stmt
= lh
->default_is_stmt
;
11158 int basic_block
= 0;
11159 int end_sequence
= 0;
11161 unsigned char op_index
= 0;
11163 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
11165 /* Start a subfile for the current file of the state machine. */
11166 /* lh->include_dirs and lh->file_names are 0-based, but the
11167 directory and file name numbers in the statement program
11169 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
11173 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11175 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11178 /* Decode the table. */
11179 while (!end_sequence
)
11181 op_code
= read_1_byte (abfd
, line_ptr
);
11183 if (line_ptr
> line_end
)
11185 dwarf2_debug_line_missing_end_sequence_complaint ();
11189 if (op_code
>= lh
->opcode_base
)
11191 /* Special operand. */
11192 adj_opcode
= op_code
- lh
->opcode_base
;
11193 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
11194 / lh
->maximum_ops_per_instruction
)
11195 * lh
->minimum_instruction_length
);
11196 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
11197 % lh
->maximum_ops_per_instruction
);
11198 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
11199 if (lh
->num_file_names
< file
|| file
== 0)
11200 dwarf2_debug_line_missing_file_complaint ();
11201 /* For now we ignore lines not starting on an
11202 instruction boundary. */
11203 else if (op_index
== 0)
11205 lh
->file_names
[file
- 1].included_p
= 1;
11206 if (!decode_for_pst_p
&& is_stmt
)
11208 if (last_subfile
!= current_subfile
)
11210 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11212 (*p_record_line
) (last_subfile
, 0, addr
);
11213 last_subfile
= current_subfile
;
11215 /* Append row to matrix using current values. */
11216 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11217 (*p_record_line
) (current_subfile
, line
, addr
);
11222 else switch (op_code
)
11224 case DW_LNS_extended_op
:
11225 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
11227 line_ptr
+= bytes_read
;
11228 extended_end
= line_ptr
+ extended_len
;
11229 extended_op
= read_1_byte (abfd
, line_ptr
);
11231 switch (extended_op
)
11233 case DW_LNE_end_sequence
:
11234 p_record_line
= record_line
;
11237 case DW_LNE_set_address
:
11238 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
11240 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
11242 /* This line table is for a function which has been
11243 GCd by the linker. Ignore it. PR gdb/12528 */
11246 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
11248 complaint (&symfile_complaints
,
11249 _(".debug_line address at offset 0x%lx is 0 "
11251 line_offset
, objfile
->name
);
11252 p_record_line
= noop_record_line
;
11256 line_ptr
+= bytes_read
;
11257 address
+= baseaddr
;
11259 case DW_LNE_define_file
:
11262 unsigned int dir_index
, mod_time
, length
;
11264 cur_file
= read_direct_string (abfd
, line_ptr
,
11266 line_ptr
+= bytes_read
;
11268 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11269 line_ptr
+= bytes_read
;
11271 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11272 line_ptr
+= bytes_read
;
11274 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11275 line_ptr
+= bytes_read
;
11276 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
11279 case DW_LNE_set_discriminator
:
11280 /* The discriminator is not interesting to the debugger;
11282 line_ptr
= extended_end
;
11285 complaint (&symfile_complaints
,
11286 _("mangled .debug_line section"));
11289 /* Make sure that we parsed the extended op correctly. If e.g.
11290 we expected a different address size than the producer used,
11291 we may have read the wrong number of bytes. */
11292 if (line_ptr
!= extended_end
)
11294 complaint (&symfile_complaints
,
11295 _("mangled .debug_line section"));
11300 if (lh
->num_file_names
< file
|| file
== 0)
11301 dwarf2_debug_line_missing_file_complaint ();
11304 lh
->file_names
[file
- 1].included_p
= 1;
11305 if (!decode_for_pst_p
&& is_stmt
)
11307 if (last_subfile
!= current_subfile
)
11309 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11311 (*p_record_line
) (last_subfile
, 0, addr
);
11312 last_subfile
= current_subfile
;
11314 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11315 (*p_record_line
) (current_subfile
, line
, addr
);
11320 case DW_LNS_advance_pc
:
11323 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11325 address
+= (((op_index
+ adjust
)
11326 / lh
->maximum_ops_per_instruction
)
11327 * lh
->minimum_instruction_length
);
11328 op_index
= ((op_index
+ adjust
)
11329 % lh
->maximum_ops_per_instruction
);
11330 line_ptr
+= bytes_read
;
11333 case DW_LNS_advance_line
:
11334 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
11335 line_ptr
+= bytes_read
;
11337 case DW_LNS_set_file
:
11339 /* The arrays lh->include_dirs and lh->file_names are
11340 0-based, but the directory and file name numbers in
11341 the statement program are 1-based. */
11342 struct file_entry
*fe
;
11345 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11346 line_ptr
+= bytes_read
;
11347 if (lh
->num_file_names
< file
|| file
== 0)
11348 dwarf2_debug_line_missing_file_complaint ();
11351 fe
= &lh
->file_names
[file
- 1];
11353 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11354 if (!decode_for_pst_p
)
11356 last_subfile
= current_subfile
;
11357 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11362 case DW_LNS_set_column
:
11363 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11364 line_ptr
+= bytes_read
;
11366 case DW_LNS_negate_stmt
:
11367 is_stmt
= (!is_stmt
);
11369 case DW_LNS_set_basic_block
:
11372 /* Add to the address register of the state machine the
11373 address increment value corresponding to special opcode
11374 255. I.e., this value is scaled by the minimum
11375 instruction length since special opcode 255 would have
11376 scaled the increment. */
11377 case DW_LNS_const_add_pc
:
11379 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
11381 address
+= (((op_index
+ adjust
)
11382 / lh
->maximum_ops_per_instruction
)
11383 * lh
->minimum_instruction_length
);
11384 op_index
= ((op_index
+ adjust
)
11385 % lh
->maximum_ops_per_instruction
);
11388 case DW_LNS_fixed_advance_pc
:
11389 address
+= read_2_bytes (abfd
, line_ptr
);
11395 /* Unknown standard opcode, ignore it. */
11398 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
11400 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11401 line_ptr
+= bytes_read
;
11406 if (lh
->num_file_names
< file
|| file
== 0)
11407 dwarf2_debug_line_missing_file_complaint ();
11410 lh
->file_names
[file
- 1].included_p
= 1;
11411 if (!decode_for_pst_p
)
11413 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11414 (*p_record_line
) (current_subfile
, 0, addr
);
11420 /* Decode the Line Number Program (LNP) for the given line_header
11421 structure and CU. The actual information extracted and the type
11422 of structures created from the LNP depends on the value of PST.
11424 1. If PST is NULL, then this procedure uses the data from the program
11425 to create all necessary symbol tables, and their linetables.
11427 2. If PST is not NULL, this procedure reads the program to determine
11428 the list of files included by the unit represented by PST, and
11429 builds all the associated partial symbol tables.
11431 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
11432 It is used for relative paths in the line table.
11433 NOTE: When processing partial symtabs (pst != NULL),
11434 comp_dir == pst->dirname.
11436 NOTE: It is important that psymtabs have the same file name (via strcmp)
11437 as the corresponding symtab. Since COMP_DIR is not used in the name of the
11438 symtab we don't use it in the name of the psymtabs we create.
11439 E.g. expand_line_sal requires this when finding psymtabs to expand.
11440 A good testcase for this is mb-inline.exp. */
11443 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
11444 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
11445 int want_line_info
)
11447 struct objfile
*objfile
= cu
->objfile
;
11448 const int decode_for_pst_p
= (pst
!= NULL
);
11449 struct subfile
*first_subfile
= current_subfile
;
11451 if (want_line_info
)
11452 dwarf_decode_lines_1 (lh
, comp_dir
, cu
, pst
);
11454 if (decode_for_pst_p
)
11458 /* Now that we're done scanning the Line Header Program, we can
11459 create the psymtab of each included file. */
11460 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
11461 if (lh
->file_names
[file_index
].included_p
== 1)
11463 char *include_name
=
11464 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
11465 if (include_name
!= NULL
)
11466 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
11471 /* Make sure a symtab is created for every file, even files
11472 which contain only variables (i.e. no code with associated
11476 for (i
= 0; i
< lh
->num_file_names
; i
++)
11479 struct file_entry
*fe
;
11481 fe
= &lh
->file_names
[i
];
11483 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11484 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11486 /* Skip the main file; we don't need it, and it must be
11487 allocated last, so that it will show up before the
11488 non-primary symtabs in the objfile's symtab list. */
11489 if (current_subfile
== first_subfile
)
11492 if (current_subfile
->symtab
== NULL
)
11493 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
11495 fe
->symtab
= current_subfile
->symtab
;
11500 /* Start a subfile for DWARF. FILENAME is the name of the file and
11501 DIRNAME the name of the source directory which contains FILENAME
11502 or NULL if not known. COMP_DIR is the compilation directory for the
11503 linetable's compilation unit or NULL if not known.
11504 This routine tries to keep line numbers from identical absolute and
11505 relative file names in a common subfile.
11507 Using the `list' example from the GDB testsuite, which resides in
11508 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
11509 of /srcdir/list0.c yields the following debugging information for list0.c:
11511 DW_AT_name: /srcdir/list0.c
11512 DW_AT_comp_dir: /compdir
11513 files.files[0].name: list0.h
11514 files.files[0].dir: /srcdir
11515 files.files[1].name: list0.c
11516 files.files[1].dir: /srcdir
11518 The line number information for list0.c has to end up in a single
11519 subfile, so that `break /srcdir/list0.c:1' works as expected.
11520 start_subfile will ensure that this happens provided that we pass the
11521 concatenation of files.files[1].dir and files.files[1].name as the
11525 dwarf2_start_subfile (char *filename
, const char *dirname
,
11526 const char *comp_dir
)
11530 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
11531 `start_symtab' will always pass the contents of DW_AT_comp_dir as
11532 second argument to start_subfile. To be consistent, we do the
11533 same here. In order not to lose the line information directory,
11534 we concatenate it to the filename when it makes sense.
11535 Note that the Dwarf3 standard says (speaking of filenames in line
11536 information): ``The directory index is ignored for file names
11537 that represent full path names''. Thus ignoring dirname in the
11538 `else' branch below isn't an issue. */
11540 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
11541 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
11543 fullname
= filename
;
11545 start_subfile (fullname
, comp_dir
);
11547 if (fullname
!= filename
)
11552 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
11553 struct dwarf2_cu
*cu
)
11555 struct objfile
*objfile
= cu
->objfile
;
11556 struct comp_unit_head
*cu_header
= &cu
->header
;
11558 /* NOTE drow/2003-01-30: There used to be a comment and some special
11559 code here to turn a symbol with DW_AT_external and a
11560 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
11561 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
11562 with some versions of binutils) where shared libraries could have
11563 relocations against symbols in their debug information - the
11564 minimal symbol would have the right address, but the debug info
11565 would not. It's no longer necessary, because we will explicitly
11566 apply relocations when we read in the debug information now. */
11568 /* A DW_AT_location attribute with no contents indicates that a
11569 variable has been optimized away. */
11570 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
11572 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11576 /* Handle one degenerate form of location expression specially, to
11577 preserve GDB's previous behavior when section offsets are
11578 specified. If this is just a DW_OP_addr then mark this symbol
11581 if (attr_form_is_block (attr
)
11582 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
11583 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
11585 unsigned int dummy
;
11587 SYMBOL_VALUE_ADDRESS (sym
) =
11588 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
11589 SYMBOL_CLASS (sym
) = LOC_STATIC
;
11590 fixup_symbol_section (sym
, objfile
);
11591 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
11592 SYMBOL_SECTION (sym
));
11596 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
11597 expression evaluator, and use LOC_COMPUTED only when necessary
11598 (i.e. when the value of a register or memory location is
11599 referenced, or a thread-local block, etc.). Then again, it might
11600 not be worthwhile. I'm assuming that it isn't unless performance
11601 or memory numbers show me otherwise. */
11603 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
11604 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11606 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
11607 cu
->has_loclist
= 1;
11610 /* Given a pointer to a DWARF information entry, figure out if we need
11611 to make a symbol table entry for it, and if so, create a new entry
11612 and return a pointer to it.
11613 If TYPE is NULL, determine symbol type from the die, otherwise
11614 used the passed type.
11615 If SPACE is not NULL, use it to hold the new symbol. If it is
11616 NULL, allocate a new symbol on the objfile's obstack. */
11618 static struct symbol
*
11619 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
11620 struct symbol
*space
)
11622 struct objfile
*objfile
= cu
->objfile
;
11623 struct symbol
*sym
= NULL
;
11625 struct attribute
*attr
= NULL
;
11626 struct attribute
*attr2
= NULL
;
11627 CORE_ADDR baseaddr
;
11628 struct pending
**list_to_add
= NULL
;
11630 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
11632 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11634 name
= dwarf2_name (die
, cu
);
11637 const char *linkagename
;
11638 int suppress_add
= 0;
11643 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
11644 OBJSTAT (objfile
, n_syms
++);
11646 /* Cache this symbol's name and the name's demangled form (if any). */
11647 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
11648 linkagename
= dwarf2_physname (name
, die
, cu
);
11649 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
11651 /* Fortran does not have mangling standard and the mangling does differ
11652 between gfortran, iFort etc. */
11653 if (cu
->language
== language_fortran
11654 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
11655 symbol_set_demangled_name (&(sym
->ginfo
),
11656 (char *) dwarf2_full_name (name
, die
, cu
),
11659 /* Default assumptions.
11660 Use the passed type or decode it from the die. */
11661 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11662 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11664 SYMBOL_TYPE (sym
) = type
;
11666 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
11667 attr
= dwarf2_attr (die
,
11668 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
11672 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
11675 attr
= dwarf2_attr (die
,
11676 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
11680 int file_index
= DW_UNSND (attr
);
11682 if (cu
->line_header
== NULL
11683 || file_index
> cu
->line_header
->num_file_names
)
11684 complaint (&symfile_complaints
,
11685 _("file index out of range"));
11686 else if (file_index
> 0)
11688 struct file_entry
*fe
;
11690 fe
= &cu
->line_header
->file_names
[file_index
- 1];
11691 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
11698 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11701 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
11703 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
11704 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
11705 SYMBOL_CLASS (sym
) = LOC_LABEL
;
11706 add_symbol_to_list (sym
, cu
->list_in_scope
);
11708 case DW_TAG_subprogram
:
11709 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11711 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11712 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11713 if ((attr2
&& (DW_UNSND (attr2
) != 0))
11714 || cu
->language
== language_ada
)
11716 /* Subprograms marked external are stored as a global symbol.
11717 Ada subprograms, whether marked external or not, are always
11718 stored as a global symbol, because we want to be able to
11719 access them globally. For instance, we want to be able
11720 to break on a nested subprogram without having to
11721 specify the context. */
11722 list_to_add
= &global_symbols
;
11726 list_to_add
= cu
->list_in_scope
;
11729 case DW_TAG_inlined_subroutine
:
11730 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11732 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11733 SYMBOL_INLINED (sym
) = 1;
11734 /* Do not add the symbol to any lists. It will be found via
11735 BLOCK_FUNCTION from the blockvector. */
11737 case DW_TAG_template_value_param
:
11739 /* Fall through. */
11740 case DW_TAG_constant
:
11741 case DW_TAG_variable
:
11742 case DW_TAG_member
:
11743 /* Compilation with minimal debug info may result in
11744 variables with missing type entries. Change the
11745 misleading `void' type to something sensible. */
11746 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
11748 = objfile_type (objfile
)->nodebug_data_symbol
;
11750 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11751 /* In the case of DW_TAG_member, we should only be called for
11752 static const members. */
11753 if (die
->tag
== DW_TAG_member
)
11755 /* dwarf2_add_field uses die_is_declaration,
11756 so we do the same. */
11757 gdb_assert (die_is_declaration (die
, cu
));
11762 dwarf2_const_value (attr
, sym
, cu
);
11763 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11766 if (attr2
&& (DW_UNSND (attr2
) != 0))
11767 list_to_add
= &global_symbols
;
11769 list_to_add
= cu
->list_in_scope
;
11773 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11776 var_decode_location (attr
, sym
, cu
);
11777 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11778 if (SYMBOL_CLASS (sym
) == LOC_STATIC
11779 && SYMBOL_VALUE_ADDRESS (sym
) == 0
11780 && !dwarf2_per_objfile
->has_section_at_zero
)
11782 /* When a static variable is eliminated by the linker,
11783 the corresponding debug information is not stripped
11784 out, but the variable address is set to null;
11785 do not add such variables into symbol table. */
11787 else if (attr2
&& (DW_UNSND (attr2
) != 0))
11789 /* Workaround gfortran PR debug/40040 - it uses
11790 DW_AT_location for variables in -fPIC libraries which may
11791 get overriden by other libraries/executable and get
11792 a different address. Resolve it by the minimal symbol
11793 which may come from inferior's executable using copy
11794 relocation. Make this workaround only for gfortran as for
11795 other compilers GDB cannot guess the minimal symbol
11796 Fortran mangling kind. */
11797 if (cu
->language
== language_fortran
&& die
->parent
11798 && die
->parent
->tag
== DW_TAG_module
11800 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
11801 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11803 /* A variable with DW_AT_external is never static,
11804 but it may be block-scoped. */
11805 list_to_add
= (cu
->list_in_scope
== &file_symbols
11806 ? &global_symbols
: cu
->list_in_scope
);
11809 list_to_add
= cu
->list_in_scope
;
11813 /* We do not know the address of this symbol.
11814 If it is an external symbol and we have type information
11815 for it, enter the symbol as a LOC_UNRESOLVED symbol.
11816 The address of the variable will then be determined from
11817 the minimal symbol table whenever the variable is
11819 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11820 if (attr2
&& (DW_UNSND (attr2
) != 0)
11821 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
11823 /* A variable with DW_AT_external is never static, but it
11824 may be block-scoped. */
11825 list_to_add
= (cu
->list_in_scope
== &file_symbols
11826 ? &global_symbols
: cu
->list_in_scope
);
11828 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11830 else if (!die_is_declaration (die
, cu
))
11832 /* Use the default LOC_OPTIMIZED_OUT class. */
11833 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
11835 list_to_add
= cu
->list_in_scope
;
11839 case DW_TAG_formal_parameter
:
11840 /* If we are inside a function, mark this as an argument. If
11841 not, we might be looking at an argument to an inlined function
11842 when we do not have enough information to show inlined frames;
11843 pretend it's a local variable in that case so that the user can
11845 if (context_stack_depth
> 0
11846 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
11847 SYMBOL_IS_ARGUMENT (sym
) = 1;
11848 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11851 var_decode_location (attr
, sym
, cu
);
11853 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11856 dwarf2_const_value (attr
, sym
, cu
);
11859 list_to_add
= cu
->list_in_scope
;
11861 case DW_TAG_unspecified_parameters
:
11862 /* From varargs functions; gdb doesn't seem to have any
11863 interest in this information, so just ignore it for now.
11866 case DW_TAG_template_type_param
:
11868 /* Fall through. */
11869 case DW_TAG_class_type
:
11870 case DW_TAG_interface_type
:
11871 case DW_TAG_structure_type
:
11872 case DW_TAG_union_type
:
11873 case DW_TAG_set_type
:
11874 case DW_TAG_enumeration_type
:
11875 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11876 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
11879 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
11880 really ever be static objects: otherwise, if you try
11881 to, say, break of a class's method and you're in a file
11882 which doesn't mention that class, it won't work unless
11883 the check for all static symbols in lookup_symbol_aux
11884 saves you. See the OtherFileClass tests in
11885 gdb.c++/namespace.exp. */
11889 list_to_add
= (cu
->list_in_scope
== &file_symbols
11890 && (cu
->language
== language_cplus
11891 || cu
->language
== language_java
)
11892 ? &global_symbols
: cu
->list_in_scope
);
11894 /* The semantics of C++ state that "struct foo {
11895 ... }" also defines a typedef for "foo". A Java
11896 class declaration also defines a typedef for the
11898 if (cu
->language
== language_cplus
11899 || cu
->language
== language_java
11900 || cu
->language
== language_ada
)
11902 /* The symbol's name is already allocated along
11903 with this objfile, so we don't need to
11904 duplicate it for the type. */
11905 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
11906 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
11911 case DW_TAG_typedef
:
11912 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11913 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11914 list_to_add
= cu
->list_in_scope
;
11916 case DW_TAG_base_type
:
11917 case DW_TAG_subrange_type
:
11918 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11919 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11920 list_to_add
= cu
->list_in_scope
;
11922 case DW_TAG_enumerator
:
11923 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11926 dwarf2_const_value (attr
, sym
, cu
);
11929 /* NOTE: carlton/2003-11-10: See comment above in the
11930 DW_TAG_class_type, etc. block. */
11932 list_to_add
= (cu
->list_in_scope
== &file_symbols
11933 && (cu
->language
== language_cplus
11934 || cu
->language
== language_java
)
11935 ? &global_symbols
: cu
->list_in_scope
);
11938 case DW_TAG_namespace
:
11939 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11940 list_to_add
= &global_symbols
;
11943 /* Not a tag we recognize. Hopefully we aren't processing
11944 trash data, but since we must specifically ignore things
11945 we don't recognize, there is nothing else we should do at
11947 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
11948 dwarf_tag_name (die
->tag
));
11954 sym
->hash_next
= objfile
->template_symbols
;
11955 objfile
->template_symbols
= sym
;
11956 list_to_add
= NULL
;
11959 if (list_to_add
!= NULL
)
11960 add_symbol_to_list (sym
, list_to_add
);
11962 /* For the benefit of old versions of GCC, check for anonymous
11963 namespaces based on the demangled name. */
11964 if (!processing_has_namespace_info
11965 && cu
->language
== language_cplus
)
11966 cp_scan_for_anonymous_namespaces (sym
, objfile
);
11971 /* A wrapper for new_symbol_full that always allocates a new symbol. */
11973 static struct symbol
*
11974 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
11976 return new_symbol_full (die
, type
, cu
, NULL
);
11979 /* Given an attr with a DW_FORM_dataN value in host byte order,
11980 zero-extend it as appropriate for the symbol's type. The DWARF
11981 standard (v4) is not entirely clear about the meaning of using
11982 DW_FORM_dataN for a constant with a signed type, where the type is
11983 wider than the data. The conclusion of a discussion on the DWARF
11984 list was that this is unspecified. We choose to always zero-extend
11985 because that is the interpretation long in use by GCC. */
11988 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
11989 const char *name
, struct obstack
*obstack
,
11990 struct dwarf2_cu
*cu
, long *value
, int bits
)
11992 struct objfile
*objfile
= cu
->objfile
;
11993 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
11994 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
11995 LONGEST l
= DW_UNSND (attr
);
11997 if (bits
< sizeof (*value
) * 8)
11999 l
&= ((LONGEST
) 1 << bits
) - 1;
12002 else if (bits
== sizeof (*value
) * 8)
12006 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
12007 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
12014 /* Read a constant value from an attribute. Either set *VALUE, or if
12015 the value does not fit in *VALUE, set *BYTES - either already
12016 allocated on the objfile obstack, or newly allocated on OBSTACK,
12017 or, set *BATON, if we translated the constant to a location
12021 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
12022 const char *name
, struct obstack
*obstack
,
12023 struct dwarf2_cu
*cu
,
12024 long *value
, gdb_byte
**bytes
,
12025 struct dwarf2_locexpr_baton
**baton
)
12027 struct objfile
*objfile
= cu
->objfile
;
12028 struct comp_unit_head
*cu_header
= &cu
->header
;
12029 struct dwarf_block
*blk
;
12030 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
12031 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
12037 switch (attr
->form
)
12043 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
12044 dwarf2_const_value_length_mismatch_complaint (name
,
12045 cu_header
->addr_size
,
12046 TYPE_LENGTH (type
));
12047 /* Symbols of this form are reasonably rare, so we just
12048 piggyback on the existing location code rather than writing
12049 a new implementation of symbol_computed_ops. */
12050 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
12051 sizeof (struct dwarf2_locexpr_baton
));
12052 (*baton
)->per_cu
= cu
->per_cu
;
12053 gdb_assert ((*baton
)->per_cu
);
12055 (*baton
)->size
= 2 + cu_header
->addr_size
;
12056 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
12057 (*baton
)->data
= data
;
12059 data
[0] = DW_OP_addr
;
12060 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
12061 byte_order
, DW_ADDR (attr
));
12062 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
12065 case DW_FORM_string
:
12067 /* DW_STRING is already allocated on the objfile obstack, point
12069 *bytes
= (gdb_byte
*) DW_STRING (attr
);
12071 case DW_FORM_block1
:
12072 case DW_FORM_block2
:
12073 case DW_FORM_block4
:
12074 case DW_FORM_block
:
12075 case DW_FORM_exprloc
:
12076 blk
= DW_BLOCK (attr
);
12077 if (TYPE_LENGTH (type
) != blk
->size
)
12078 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
12079 TYPE_LENGTH (type
));
12080 *bytes
= blk
->data
;
12083 /* The DW_AT_const_value attributes are supposed to carry the
12084 symbol's value "represented as it would be on the target
12085 architecture." By the time we get here, it's already been
12086 converted to host endianness, so we just need to sign- or
12087 zero-extend it as appropriate. */
12088 case DW_FORM_data1
:
12089 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12090 obstack
, cu
, value
, 8);
12092 case DW_FORM_data2
:
12093 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12094 obstack
, cu
, value
, 16);
12096 case DW_FORM_data4
:
12097 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12098 obstack
, cu
, value
, 32);
12100 case DW_FORM_data8
:
12101 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12102 obstack
, cu
, value
, 64);
12105 case DW_FORM_sdata
:
12106 *value
= DW_SND (attr
);
12109 case DW_FORM_udata
:
12110 *value
= DW_UNSND (attr
);
12114 complaint (&symfile_complaints
,
12115 _("unsupported const value attribute form: '%s'"),
12116 dwarf_form_name (attr
->form
));
12123 /* Copy constant value from an attribute to a symbol. */
12126 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
12127 struct dwarf2_cu
*cu
)
12129 struct objfile
*objfile
= cu
->objfile
;
12130 struct comp_unit_head
*cu_header
= &cu
->header
;
12133 struct dwarf2_locexpr_baton
*baton
;
12135 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
12136 SYMBOL_PRINT_NAME (sym
),
12137 &objfile
->objfile_obstack
, cu
,
12138 &value
, &bytes
, &baton
);
12142 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
12143 SYMBOL_LOCATION_BATON (sym
) = baton
;
12144 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
12146 else if (bytes
!= NULL
)
12148 SYMBOL_VALUE_BYTES (sym
) = bytes
;
12149 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
12153 SYMBOL_VALUE (sym
) = value
;
12154 SYMBOL_CLASS (sym
) = LOC_CONST
;
12158 /* Return the type of the die in question using its DW_AT_type attribute. */
12160 static struct type
*
12161 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12163 struct attribute
*type_attr
;
12165 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
12168 /* A missing DW_AT_type represents a void type. */
12169 return objfile_type (cu
->objfile
)->builtin_void
;
12172 return lookup_die_type (die
, type_attr
, cu
);
12175 /* True iff CU's producer generates GNAT Ada auxiliary information
12176 that allows to find parallel types through that information instead
12177 of having to do expensive parallel lookups by type name. */
12180 need_gnat_info (struct dwarf2_cu
*cu
)
12182 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
12183 of GNAT produces this auxiliary information, without any indication
12184 that it is produced. Part of enhancing the FSF version of GNAT
12185 to produce that information will be to put in place an indicator
12186 that we can use in order to determine whether the descriptive type
12187 info is available or not. One suggestion that has been made is
12188 to use a new attribute, attached to the CU die. For now, assume
12189 that the descriptive type info is not available. */
12193 /* Return the auxiliary type of the die in question using its
12194 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
12195 attribute is not present. */
12197 static struct type
*
12198 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12200 struct attribute
*type_attr
;
12202 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
12206 return lookup_die_type (die
, type_attr
, cu
);
12209 /* If DIE has a descriptive_type attribute, then set the TYPE's
12210 descriptive type accordingly. */
12213 set_descriptive_type (struct type
*type
, struct die_info
*die
,
12214 struct dwarf2_cu
*cu
)
12216 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
12218 if (descriptive_type
)
12220 ALLOCATE_GNAT_AUX_TYPE (type
);
12221 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
12225 /* Return the containing type of the die in question using its
12226 DW_AT_containing_type attribute. */
12228 static struct type
*
12229 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12231 struct attribute
*type_attr
;
12233 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
12235 error (_("Dwarf Error: Problem turning containing type into gdb type "
12236 "[in module %s]"), cu
->objfile
->name
);
12238 return lookup_die_type (die
, type_attr
, cu
);
12241 /* Look up the type of DIE in CU using its type attribute ATTR.
12242 If there is no type substitute an error marker. */
12244 static struct type
*
12245 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
12246 struct dwarf2_cu
*cu
)
12248 struct objfile
*objfile
= cu
->objfile
;
12249 struct type
*this_type
;
12251 /* First see if we have it cached. */
12253 if (is_ref_attr (attr
))
12255 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
12257 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
12259 else if (attr
->form
== DW_FORM_ref_sig8
)
12261 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
12262 struct dwarf2_cu
*sig_cu
;
12263 unsigned int offset
;
12265 /* sig_type will be NULL if the signatured type is missing from
12267 if (sig_type
== NULL
)
12268 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
12269 "at 0x%x [in module %s]"),
12270 die
->offset
, objfile
->name
);
12272 gdb_assert (sig_type
->per_cu
.debug_types_section
);
12273 offset
= sig_type
->per_cu
.offset
+ sig_type
->type_offset
;
12274 this_type
= get_die_type_at_offset (offset
, &sig_type
->per_cu
);
12278 dump_die_for_error (die
);
12279 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
12280 dwarf_attr_name (attr
->name
), objfile
->name
);
12283 /* If not cached we need to read it in. */
12285 if (this_type
== NULL
)
12287 struct die_info
*type_die
;
12288 struct dwarf2_cu
*type_cu
= cu
;
12290 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
12291 /* If the type is cached, we should have found it above. */
12292 gdb_assert (get_die_type (type_die
, type_cu
) == NULL
);
12293 this_type
= read_type_die_1 (type_die
, type_cu
);
12296 /* If we still don't have a type use an error marker. */
12298 if (this_type
== NULL
)
12300 char *message
, *saved
;
12302 /* read_type_die already issued a complaint. */
12303 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
12307 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
12308 message
, strlen (message
));
12311 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
12317 /* Return the type in DIE, CU.
12318 Returns NULL for invalid types.
12320 This first does a lookup in the appropriate type_hash table,
12321 and only reads the die in if necessary.
12323 NOTE: This can be called when reading in partial or full symbols. */
12325 static struct type
*
12326 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
12328 struct type
*this_type
;
12330 this_type
= get_die_type (die
, cu
);
12334 return read_type_die_1 (die
, cu
);
12337 /* Read the type in DIE, CU.
12338 Returns NULL for invalid types. */
12340 static struct type
*
12341 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
12343 struct type
*this_type
= NULL
;
12347 case DW_TAG_class_type
:
12348 case DW_TAG_interface_type
:
12349 case DW_TAG_structure_type
:
12350 case DW_TAG_union_type
:
12351 this_type
= read_structure_type (die
, cu
);
12353 case DW_TAG_enumeration_type
:
12354 this_type
= read_enumeration_type (die
, cu
);
12356 case DW_TAG_subprogram
:
12357 case DW_TAG_subroutine_type
:
12358 case DW_TAG_inlined_subroutine
:
12359 this_type
= read_subroutine_type (die
, cu
);
12361 case DW_TAG_array_type
:
12362 this_type
= read_array_type (die
, cu
);
12364 case DW_TAG_set_type
:
12365 this_type
= read_set_type (die
, cu
);
12367 case DW_TAG_pointer_type
:
12368 this_type
= read_tag_pointer_type (die
, cu
);
12370 case DW_TAG_ptr_to_member_type
:
12371 this_type
= read_tag_ptr_to_member_type (die
, cu
);
12373 case DW_TAG_reference_type
:
12374 this_type
= read_tag_reference_type (die
, cu
);
12376 case DW_TAG_const_type
:
12377 this_type
= read_tag_const_type (die
, cu
);
12379 case DW_TAG_volatile_type
:
12380 this_type
= read_tag_volatile_type (die
, cu
);
12382 case DW_TAG_string_type
:
12383 this_type
= read_tag_string_type (die
, cu
);
12385 case DW_TAG_typedef
:
12386 this_type
= read_typedef (die
, cu
);
12388 case DW_TAG_subrange_type
:
12389 this_type
= read_subrange_type (die
, cu
);
12391 case DW_TAG_base_type
:
12392 this_type
= read_base_type (die
, cu
);
12394 case DW_TAG_unspecified_type
:
12395 this_type
= read_unspecified_type (die
, cu
);
12397 case DW_TAG_namespace
:
12398 this_type
= read_namespace_type (die
, cu
);
12400 case DW_TAG_module
:
12401 this_type
= read_module_type (die
, cu
);
12404 complaint (&symfile_complaints
,
12405 _("unexpected tag in read_type_die: '%s'"),
12406 dwarf_tag_name (die
->tag
));
12413 /* See if we can figure out if the class lives in a namespace. We do
12414 this by looking for a member function; its demangled name will
12415 contain namespace info, if there is any.
12416 Return the computed name or NULL.
12417 Space for the result is allocated on the objfile's obstack.
12418 This is the full-die version of guess_partial_die_structure_name.
12419 In this case we know DIE has no useful parent. */
12422 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12424 struct die_info
*spec_die
;
12425 struct dwarf2_cu
*spec_cu
;
12426 struct die_info
*child
;
12429 spec_die
= die_specification (die
, &spec_cu
);
12430 if (spec_die
!= NULL
)
12436 for (child
= die
->child
;
12438 child
= child
->sibling
)
12440 if (child
->tag
== DW_TAG_subprogram
)
12442 struct attribute
*attr
;
12444 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
12446 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
12450 = language_class_name_from_physname (cu
->language_defn
,
12454 if (actual_name
!= NULL
)
12456 char *die_name
= dwarf2_name (die
, cu
);
12458 if (die_name
!= NULL
12459 && strcmp (die_name
, actual_name
) != 0)
12461 /* Strip off the class name from the full name.
12462 We want the prefix. */
12463 int die_name_len
= strlen (die_name
);
12464 int actual_name_len
= strlen (actual_name
);
12466 /* Test for '::' as a sanity check. */
12467 if (actual_name_len
> die_name_len
+ 2
12468 && actual_name
[actual_name_len
12469 - die_name_len
- 1] == ':')
12471 obsavestring (actual_name
,
12472 actual_name_len
- die_name_len
- 2,
12473 &cu
->objfile
->objfile_obstack
);
12476 xfree (actual_name
);
12485 /* GCC might emit a nameless typedef that has a linkage name. Determine the
12486 prefix part in such case. See
12487 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12490 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
12492 struct attribute
*attr
;
12495 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
12496 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
12499 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
12500 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
12503 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
12505 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
12506 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
12509 /* dwarf2_name had to be already called. */
12510 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
12512 /* Strip the base name, keep any leading namespaces/classes. */
12513 base
= strrchr (DW_STRING (attr
), ':');
12514 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
12517 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
12518 &cu
->objfile
->objfile_obstack
);
12521 /* Return the name of the namespace/class that DIE is defined within,
12522 or "" if we can't tell. The caller should not xfree the result.
12524 For example, if we're within the method foo() in the following
12534 then determine_prefix on foo's die will return "N::C". */
12536 static const char *
12537 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
12539 struct die_info
*parent
, *spec_die
;
12540 struct dwarf2_cu
*spec_cu
;
12541 struct type
*parent_type
;
12544 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
12545 && cu
->language
!= language_fortran
)
12548 retval
= anonymous_struct_prefix (die
, cu
);
12552 /* We have to be careful in the presence of DW_AT_specification.
12553 For example, with GCC 3.4, given the code
12557 // Definition of N::foo.
12561 then we'll have a tree of DIEs like this:
12563 1: DW_TAG_compile_unit
12564 2: DW_TAG_namespace // N
12565 3: DW_TAG_subprogram // declaration of N::foo
12566 4: DW_TAG_subprogram // definition of N::foo
12567 DW_AT_specification // refers to die #3
12569 Thus, when processing die #4, we have to pretend that we're in
12570 the context of its DW_AT_specification, namely the contex of die
12573 spec_die
= die_specification (die
, &spec_cu
);
12574 if (spec_die
== NULL
)
12575 parent
= die
->parent
;
12578 parent
= spec_die
->parent
;
12582 if (parent
== NULL
)
12584 else if (parent
->building_fullname
)
12587 const char *parent_name
;
12589 /* It has been seen on RealView 2.2 built binaries,
12590 DW_TAG_template_type_param types actually _defined_ as
12591 children of the parent class:
12594 template class <class Enum> Class{};
12595 Class<enum E> class_e;
12597 1: DW_TAG_class_type (Class)
12598 2: DW_TAG_enumeration_type (E)
12599 3: DW_TAG_enumerator (enum1:0)
12600 3: DW_TAG_enumerator (enum2:1)
12602 2: DW_TAG_template_type_param
12603 DW_AT_type DW_FORM_ref_udata (E)
12605 Besides being broken debug info, it can put GDB into an
12606 infinite loop. Consider:
12608 When we're building the full name for Class<E>, we'll start
12609 at Class, and go look over its template type parameters,
12610 finding E. We'll then try to build the full name of E, and
12611 reach here. We're now trying to build the full name of E,
12612 and look over the parent DIE for containing scope. In the
12613 broken case, if we followed the parent DIE of E, we'd again
12614 find Class, and once again go look at its template type
12615 arguments, etc., etc. Simply don't consider such parent die
12616 as source-level parent of this die (it can't be, the language
12617 doesn't allow it), and break the loop here. */
12618 name
= dwarf2_name (die
, cu
);
12619 parent_name
= dwarf2_name (parent
, cu
);
12620 complaint (&symfile_complaints
,
12621 _("template param type '%s' defined within parent '%s'"),
12622 name
? name
: "<unknown>",
12623 parent_name
? parent_name
: "<unknown>");
12627 switch (parent
->tag
)
12629 case DW_TAG_namespace
:
12630 parent_type
= read_type_die (parent
, cu
);
12631 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
12632 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
12633 Work around this problem here. */
12634 if (cu
->language
== language_cplus
12635 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
12637 /* We give a name to even anonymous namespaces. */
12638 return TYPE_TAG_NAME (parent_type
);
12639 case DW_TAG_class_type
:
12640 case DW_TAG_interface_type
:
12641 case DW_TAG_structure_type
:
12642 case DW_TAG_union_type
:
12643 case DW_TAG_module
:
12644 parent_type
= read_type_die (parent
, cu
);
12645 if (TYPE_TAG_NAME (parent_type
) != NULL
)
12646 return TYPE_TAG_NAME (parent_type
);
12648 /* An anonymous structure is only allowed non-static data
12649 members; no typedefs, no member functions, et cetera.
12650 So it does not need a prefix. */
12652 case DW_TAG_compile_unit
:
12653 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
12654 if (cu
->language
== language_cplus
12655 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
12656 && die
->child
!= NULL
12657 && (die
->tag
== DW_TAG_class_type
12658 || die
->tag
== DW_TAG_structure_type
12659 || die
->tag
== DW_TAG_union_type
))
12661 char *name
= guess_full_die_structure_name (die
, cu
);
12667 return determine_prefix (parent
, cu
);
12671 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
12672 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
12673 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
12674 an obconcat, otherwise allocate storage for the result. The CU argument is
12675 used to determine the language and hence, the appropriate separator. */
12677 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
12680 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
12681 int physname
, struct dwarf2_cu
*cu
)
12683 const char *lead
= "";
12686 if (suffix
== NULL
|| suffix
[0] == '\0'
12687 || prefix
== NULL
|| prefix
[0] == '\0')
12689 else if (cu
->language
== language_java
)
12691 else if (cu
->language
== language_fortran
&& physname
)
12693 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
12694 DW_AT_MIPS_linkage_name is preferred and used instead. */
12702 if (prefix
== NULL
)
12704 if (suffix
== NULL
)
12710 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
12712 strcpy (retval
, lead
);
12713 strcat (retval
, prefix
);
12714 strcat (retval
, sep
);
12715 strcat (retval
, suffix
);
12720 /* We have an obstack. */
12721 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
12725 /* Return sibling of die, NULL if no sibling. */
12727 static struct die_info
*
12728 sibling_die (struct die_info
*die
)
12730 return die
->sibling
;
12733 /* Get name of a die, return NULL if not found. */
12736 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
12737 struct obstack
*obstack
)
12739 if (name
&& cu
->language
== language_cplus
)
12741 char *canon_name
= cp_canonicalize_string (name
);
12743 if (canon_name
!= NULL
)
12745 if (strcmp (canon_name
, name
) != 0)
12746 name
= obsavestring (canon_name
, strlen (canon_name
),
12748 xfree (canon_name
);
12755 /* Get name of a die, return NULL if not found. */
12758 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12760 struct attribute
*attr
;
12762 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
12763 if ((!attr
|| !DW_STRING (attr
))
12764 && die
->tag
!= DW_TAG_class_type
12765 && die
->tag
!= DW_TAG_interface_type
12766 && die
->tag
!= DW_TAG_structure_type
12767 && die
->tag
!= DW_TAG_union_type
)
12772 case DW_TAG_compile_unit
:
12773 /* Compilation units have a DW_AT_name that is a filename, not
12774 a source language identifier. */
12775 case DW_TAG_enumeration_type
:
12776 case DW_TAG_enumerator
:
12777 /* These tags always have simple identifiers already; no need
12778 to canonicalize them. */
12779 return DW_STRING (attr
);
12781 case DW_TAG_subprogram
:
12782 /* Java constructors will all be named "<init>", so return
12783 the class name when we see this special case. */
12784 if (cu
->language
== language_java
12785 && DW_STRING (attr
) != NULL
12786 && strcmp (DW_STRING (attr
), "<init>") == 0)
12788 struct dwarf2_cu
*spec_cu
= cu
;
12789 struct die_info
*spec_die
;
12791 /* GCJ will output '<init>' for Java constructor names.
12792 For this special case, return the name of the parent class. */
12794 /* GCJ may output suprogram DIEs with AT_specification set.
12795 If so, use the name of the specified DIE. */
12796 spec_die
= die_specification (die
, &spec_cu
);
12797 if (spec_die
!= NULL
)
12798 return dwarf2_name (spec_die
, spec_cu
);
12803 if (die
->tag
== DW_TAG_class_type
)
12804 return dwarf2_name (die
, cu
);
12806 while (die
->tag
!= DW_TAG_compile_unit
);
12810 case DW_TAG_class_type
:
12811 case DW_TAG_interface_type
:
12812 case DW_TAG_structure_type
:
12813 case DW_TAG_union_type
:
12814 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
12815 structures or unions. These were of the form "._%d" in GCC 4.1,
12816 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
12817 and GCC 4.4. We work around this problem by ignoring these. */
12818 if (attr
&& DW_STRING (attr
)
12819 && (strncmp (DW_STRING (attr
), "._", 2) == 0
12820 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
12823 /* GCC might emit a nameless typedef that has a linkage name. See
12824 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12825 if (!attr
|| DW_STRING (attr
) == NULL
)
12827 char *demangled
= NULL
;
12829 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
12831 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
12833 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
12836 /* Avoid demangling DW_STRING (attr) the second time on a second
12837 call for the same DIE. */
12838 if (!DW_STRING_IS_CANONICAL (attr
))
12839 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
12845 /* FIXME: we already did this for the partial symbol... */
12846 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
12847 &cu
->objfile
->objfile_obstack
);
12848 DW_STRING_IS_CANONICAL (attr
) = 1;
12851 /* Strip any leading namespaces/classes, keep only the base name.
12852 DW_AT_name for named DIEs does not contain the prefixes. */
12853 base
= strrchr (DW_STRING (attr
), ':');
12854 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
12857 return DW_STRING (attr
);
12866 if (!DW_STRING_IS_CANONICAL (attr
))
12869 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
12870 &cu
->objfile
->objfile_obstack
);
12871 DW_STRING_IS_CANONICAL (attr
) = 1;
12873 return DW_STRING (attr
);
12876 /* Return the die that this die in an extension of, or NULL if there
12877 is none. *EXT_CU is the CU containing DIE on input, and the CU
12878 containing the return value on output. */
12880 static struct die_info
*
12881 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
12883 struct attribute
*attr
;
12885 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
12889 return follow_die_ref (die
, attr
, ext_cu
);
12892 /* Convert a DIE tag into its string name. */
12895 dwarf_tag_name (unsigned tag
)
12899 case DW_TAG_padding
:
12900 return "DW_TAG_padding";
12901 case DW_TAG_array_type
:
12902 return "DW_TAG_array_type";
12903 case DW_TAG_class_type
:
12904 return "DW_TAG_class_type";
12905 case DW_TAG_entry_point
:
12906 return "DW_TAG_entry_point";
12907 case DW_TAG_enumeration_type
:
12908 return "DW_TAG_enumeration_type";
12909 case DW_TAG_formal_parameter
:
12910 return "DW_TAG_formal_parameter";
12911 case DW_TAG_imported_declaration
:
12912 return "DW_TAG_imported_declaration";
12914 return "DW_TAG_label";
12915 case DW_TAG_lexical_block
:
12916 return "DW_TAG_lexical_block";
12917 case DW_TAG_member
:
12918 return "DW_TAG_member";
12919 case DW_TAG_pointer_type
:
12920 return "DW_TAG_pointer_type";
12921 case DW_TAG_reference_type
:
12922 return "DW_TAG_reference_type";
12923 case DW_TAG_compile_unit
:
12924 return "DW_TAG_compile_unit";
12925 case DW_TAG_string_type
:
12926 return "DW_TAG_string_type";
12927 case DW_TAG_structure_type
:
12928 return "DW_TAG_structure_type";
12929 case DW_TAG_subroutine_type
:
12930 return "DW_TAG_subroutine_type";
12931 case DW_TAG_typedef
:
12932 return "DW_TAG_typedef";
12933 case DW_TAG_union_type
:
12934 return "DW_TAG_union_type";
12935 case DW_TAG_unspecified_parameters
:
12936 return "DW_TAG_unspecified_parameters";
12937 case DW_TAG_variant
:
12938 return "DW_TAG_variant";
12939 case DW_TAG_common_block
:
12940 return "DW_TAG_common_block";
12941 case DW_TAG_common_inclusion
:
12942 return "DW_TAG_common_inclusion";
12943 case DW_TAG_inheritance
:
12944 return "DW_TAG_inheritance";
12945 case DW_TAG_inlined_subroutine
:
12946 return "DW_TAG_inlined_subroutine";
12947 case DW_TAG_module
:
12948 return "DW_TAG_module";
12949 case DW_TAG_ptr_to_member_type
:
12950 return "DW_TAG_ptr_to_member_type";
12951 case DW_TAG_set_type
:
12952 return "DW_TAG_set_type";
12953 case DW_TAG_subrange_type
:
12954 return "DW_TAG_subrange_type";
12955 case DW_TAG_with_stmt
:
12956 return "DW_TAG_with_stmt";
12957 case DW_TAG_access_declaration
:
12958 return "DW_TAG_access_declaration";
12959 case DW_TAG_base_type
:
12960 return "DW_TAG_base_type";
12961 case DW_TAG_catch_block
:
12962 return "DW_TAG_catch_block";
12963 case DW_TAG_const_type
:
12964 return "DW_TAG_const_type";
12965 case DW_TAG_constant
:
12966 return "DW_TAG_constant";
12967 case DW_TAG_enumerator
:
12968 return "DW_TAG_enumerator";
12969 case DW_TAG_file_type
:
12970 return "DW_TAG_file_type";
12971 case DW_TAG_friend
:
12972 return "DW_TAG_friend";
12973 case DW_TAG_namelist
:
12974 return "DW_TAG_namelist";
12975 case DW_TAG_namelist_item
:
12976 return "DW_TAG_namelist_item";
12977 case DW_TAG_packed_type
:
12978 return "DW_TAG_packed_type";
12979 case DW_TAG_subprogram
:
12980 return "DW_TAG_subprogram";
12981 case DW_TAG_template_type_param
:
12982 return "DW_TAG_template_type_param";
12983 case DW_TAG_template_value_param
:
12984 return "DW_TAG_template_value_param";
12985 case DW_TAG_thrown_type
:
12986 return "DW_TAG_thrown_type";
12987 case DW_TAG_try_block
:
12988 return "DW_TAG_try_block";
12989 case DW_TAG_variant_part
:
12990 return "DW_TAG_variant_part";
12991 case DW_TAG_variable
:
12992 return "DW_TAG_variable";
12993 case DW_TAG_volatile_type
:
12994 return "DW_TAG_volatile_type";
12995 case DW_TAG_dwarf_procedure
:
12996 return "DW_TAG_dwarf_procedure";
12997 case DW_TAG_restrict_type
:
12998 return "DW_TAG_restrict_type";
12999 case DW_TAG_interface_type
:
13000 return "DW_TAG_interface_type";
13001 case DW_TAG_namespace
:
13002 return "DW_TAG_namespace";
13003 case DW_TAG_imported_module
:
13004 return "DW_TAG_imported_module";
13005 case DW_TAG_unspecified_type
:
13006 return "DW_TAG_unspecified_type";
13007 case DW_TAG_partial_unit
:
13008 return "DW_TAG_partial_unit";
13009 case DW_TAG_imported_unit
:
13010 return "DW_TAG_imported_unit";
13011 case DW_TAG_condition
:
13012 return "DW_TAG_condition";
13013 case DW_TAG_shared_type
:
13014 return "DW_TAG_shared_type";
13015 case DW_TAG_type_unit
:
13016 return "DW_TAG_type_unit";
13017 case DW_TAG_MIPS_loop
:
13018 return "DW_TAG_MIPS_loop";
13019 case DW_TAG_HP_array_descriptor
:
13020 return "DW_TAG_HP_array_descriptor";
13021 case DW_TAG_format_label
:
13022 return "DW_TAG_format_label";
13023 case DW_TAG_function_template
:
13024 return "DW_TAG_function_template";
13025 case DW_TAG_class_template
:
13026 return "DW_TAG_class_template";
13027 case DW_TAG_GNU_BINCL
:
13028 return "DW_TAG_GNU_BINCL";
13029 case DW_TAG_GNU_EINCL
:
13030 return "DW_TAG_GNU_EINCL";
13031 case DW_TAG_upc_shared_type
:
13032 return "DW_TAG_upc_shared_type";
13033 case DW_TAG_upc_strict_type
:
13034 return "DW_TAG_upc_strict_type";
13035 case DW_TAG_upc_relaxed_type
:
13036 return "DW_TAG_upc_relaxed_type";
13037 case DW_TAG_PGI_kanji_type
:
13038 return "DW_TAG_PGI_kanji_type";
13039 case DW_TAG_PGI_interface_block
:
13040 return "DW_TAG_PGI_interface_block";
13041 case DW_TAG_GNU_call_site
:
13042 return "DW_TAG_GNU_call_site";
13044 return "DW_TAG_<unknown>";
13048 /* Convert a DWARF attribute code into its string name. */
13051 dwarf_attr_name (unsigned attr
)
13055 case DW_AT_sibling
:
13056 return "DW_AT_sibling";
13057 case DW_AT_location
:
13058 return "DW_AT_location";
13060 return "DW_AT_name";
13061 case DW_AT_ordering
:
13062 return "DW_AT_ordering";
13063 case DW_AT_subscr_data
:
13064 return "DW_AT_subscr_data";
13065 case DW_AT_byte_size
:
13066 return "DW_AT_byte_size";
13067 case DW_AT_bit_offset
:
13068 return "DW_AT_bit_offset";
13069 case DW_AT_bit_size
:
13070 return "DW_AT_bit_size";
13071 case DW_AT_element_list
:
13072 return "DW_AT_element_list";
13073 case DW_AT_stmt_list
:
13074 return "DW_AT_stmt_list";
13076 return "DW_AT_low_pc";
13077 case DW_AT_high_pc
:
13078 return "DW_AT_high_pc";
13079 case DW_AT_language
:
13080 return "DW_AT_language";
13082 return "DW_AT_member";
13084 return "DW_AT_discr";
13085 case DW_AT_discr_value
:
13086 return "DW_AT_discr_value";
13087 case DW_AT_visibility
:
13088 return "DW_AT_visibility";
13090 return "DW_AT_import";
13091 case DW_AT_string_length
:
13092 return "DW_AT_string_length";
13093 case DW_AT_common_reference
:
13094 return "DW_AT_common_reference";
13095 case DW_AT_comp_dir
:
13096 return "DW_AT_comp_dir";
13097 case DW_AT_const_value
:
13098 return "DW_AT_const_value";
13099 case DW_AT_containing_type
:
13100 return "DW_AT_containing_type";
13101 case DW_AT_default_value
:
13102 return "DW_AT_default_value";
13104 return "DW_AT_inline";
13105 case DW_AT_is_optional
:
13106 return "DW_AT_is_optional";
13107 case DW_AT_lower_bound
:
13108 return "DW_AT_lower_bound";
13109 case DW_AT_producer
:
13110 return "DW_AT_producer";
13111 case DW_AT_prototyped
:
13112 return "DW_AT_prototyped";
13113 case DW_AT_return_addr
:
13114 return "DW_AT_return_addr";
13115 case DW_AT_start_scope
:
13116 return "DW_AT_start_scope";
13117 case DW_AT_bit_stride
:
13118 return "DW_AT_bit_stride";
13119 case DW_AT_upper_bound
:
13120 return "DW_AT_upper_bound";
13121 case DW_AT_abstract_origin
:
13122 return "DW_AT_abstract_origin";
13123 case DW_AT_accessibility
:
13124 return "DW_AT_accessibility";
13125 case DW_AT_address_class
:
13126 return "DW_AT_address_class";
13127 case DW_AT_artificial
:
13128 return "DW_AT_artificial";
13129 case DW_AT_base_types
:
13130 return "DW_AT_base_types";
13131 case DW_AT_calling_convention
:
13132 return "DW_AT_calling_convention";
13134 return "DW_AT_count";
13135 case DW_AT_data_member_location
:
13136 return "DW_AT_data_member_location";
13137 case DW_AT_decl_column
:
13138 return "DW_AT_decl_column";
13139 case DW_AT_decl_file
:
13140 return "DW_AT_decl_file";
13141 case DW_AT_decl_line
:
13142 return "DW_AT_decl_line";
13143 case DW_AT_declaration
:
13144 return "DW_AT_declaration";
13145 case DW_AT_discr_list
:
13146 return "DW_AT_discr_list";
13147 case DW_AT_encoding
:
13148 return "DW_AT_encoding";
13149 case DW_AT_external
:
13150 return "DW_AT_external";
13151 case DW_AT_frame_base
:
13152 return "DW_AT_frame_base";
13154 return "DW_AT_friend";
13155 case DW_AT_identifier_case
:
13156 return "DW_AT_identifier_case";
13157 case DW_AT_macro_info
:
13158 return "DW_AT_macro_info";
13159 case DW_AT_namelist_items
:
13160 return "DW_AT_namelist_items";
13161 case DW_AT_priority
:
13162 return "DW_AT_priority";
13163 case DW_AT_segment
:
13164 return "DW_AT_segment";
13165 case DW_AT_specification
:
13166 return "DW_AT_specification";
13167 case DW_AT_static_link
:
13168 return "DW_AT_static_link";
13170 return "DW_AT_type";
13171 case DW_AT_use_location
:
13172 return "DW_AT_use_location";
13173 case DW_AT_variable_parameter
:
13174 return "DW_AT_variable_parameter";
13175 case DW_AT_virtuality
:
13176 return "DW_AT_virtuality";
13177 case DW_AT_vtable_elem_location
:
13178 return "DW_AT_vtable_elem_location";
13179 /* DWARF 3 values. */
13180 case DW_AT_allocated
:
13181 return "DW_AT_allocated";
13182 case DW_AT_associated
:
13183 return "DW_AT_associated";
13184 case DW_AT_data_location
:
13185 return "DW_AT_data_location";
13186 case DW_AT_byte_stride
:
13187 return "DW_AT_byte_stride";
13188 case DW_AT_entry_pc
:
13189 return "DW_AT_entry_pc";
13190 case DW_AT_use_UTF8
:
13191 return "DW_AT_use_UTF8";
13192 case DW_AT_extension
:
13193 return "DW_AT_extension";
13195 return "DW_AT_ranges";
13196 case DW_AT_trampoline
:
13197 return "DW_AT_trampoline";
13198 case DW_AT_call_column
:
13199 return "DW_AT_call_column";
13200 case DW_AT_call_file
:
13201 return "DW_AT_call_file";
13202 case DW_AT_call_line
:
13203 return "DW_AT_call_line";
13204 case DW_AT_description
:
13205 return "DW_AT_description";
13206 case DW_AT_binary_scale
:
13207 return "DW_AT_binary_scale";
13208 case DW_AT_decimal_scale
:
13209 return "DW_AT_decimal_scale";
13211 return "DW_AT_small";
13212 case DW_AT_decimal_sign
:
13213 return "DW_AT_decimal_sign";
13214 case DW_AT_digit_count
:
13215 return "DW_AT_digit_count";
13216 case DW_AT_picture_string
:
13217 return "DW_AT_picture_string";
13218 case DW_AT_mutable
:
13219 return "DW_AT_mutable";
13220 case DW_AT_threads_scaled
:
13221 return "DW_AT_threads_scaled";
13222 case DW_AT_explicit
:
13223 return "DW_AT_explicit";
13224 case DW_AT_object_pointer
:
13225 return "DW_AT_object_pointer";
13226 case DW_AT_endianity
:
13227 return "DW_AT_endianity";
13228 case DW_AT_elemental
:
13229 return "DW_AT_elemental";
13231 return "DW_AT_pure";
13232 case DW_AT_recursive
:
13233 return "DW_AT_recursive";
13234 /* DWARF 4 values. */
13235 case DW_AT_signature
:
13236 return "DW_AT_signature";
13237 case DW_AT_linkage_name
:
13238 return "DW_AT_linkage_name";
13239 /* SGI/MIPS extensions. */
13240 #ifdef MIPS /* collides with DW_AT_HP_block_index */
13241 case DW_AT_MIPS_fde
:
13242 return "DW_AT_MIPS_fde";
13244 case DW_AT_MIPS_loop_begin
:
13245 return "DW_AT_MIPS_loop_begin";
13246 case DW_AT_MIPS_tail_loop_begin
:
13247 return "DW_AT_MIPS_tail_loop_begin";
13248 case DW_AT_MIPS_epilog_begin
:
13249 return "DW_AT_MIPS_epilog_begin";
13250 case DW_AT_MIPS_loop_unroll_factor
:
13251 return "DW_AT_MIPS_loop_unroll_factor";
13252 case DW_AT_MIPS_software_pipeline_depth
:
13253 return "DW_AT_MIPS_software_pipeline_depth";
13254 case DW_AT_MIPS_linkage_name
:
13255 return "DW_AT_MIPS_linkage_name";
13256 case DW_AT_MIPS_stride
:
13257 return "DW_AT_MIPS_stride";
13258 case DW_AT_MIPS_abstract_name
:
13259 return "DW_AT_MIPS_abstract_name";
13260 case DW_AT_MIPS_clone_origin
:
13261 return "DW_AT_MIPS_clone_origin";
13262 case DW_AT_MIPS_has_inlines
:
13263 return "DW_AT_MIPS_has_inlines";
13264 /* HP extensions. */
13265 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
13266 case DW_AT_HP_block_index
:
13267 return "DW_AT_HP_block_index";
13269 case DW_AT_HP_unmodifiable
:
13270 return "DW_AT_HP_unmodifiable";
13271 case DW_AT_HP_actuals_stmt_list
:
13272 return "DW_AT_HP_actuals_stmt_list";
13273 case DW_AT_HP_proc_per_section
:
13274 return "DW_AT_HP_proc_per_section";
13275 case DW_AT_HP_raw_data_ptr
:
13276 return "DW_AT_HP_raw_data_ptr";
13277 case DW_AT_HP_pass_by_reference
:
13278 return "DW_AT_HP_pass_by_reference";
13279 case DW_AT_HP_opt_level
:
13280 return "DW_AT_HP_opt_level";
13281 case DW_AT_HP_prof_version_id
:
13282 return "DW_AT_HP_prof_version_id";
13283 case DW_AT_HP_opt_flags
:
13284 return "DW_AT_HP_opt_flags";
13285 case DW_AT_HP_cold_region_low_pc
:
13286 return "DW_AT_HP_cold_region_low_pc";
13287 case DW_AT_HP_cold_region_high_pc
:
13288 return "DW_AT_HP_cold_region_high_pc";
13289 case DW_AT_HP_all_variables_modifiable
:
13290 return "DW_AT_HP_all_variables_modifiable";
13291 case DW_AT_HP_linkage_name
:
13292 return "DW_AT_HP_linkage_name";
13293 case DW_AT_HP_prof_flags
:
13294 return "DW_AT_HP_prof_flags";
13295 /* GNU extensions. */
13296 case DW_AT_sf_names
:
13297 return "DW_AT_sf_names";
13298 case DW_AT_src_info
:
13299 return "DW_AT_src_info";
13300 case DW_AT_mac_info
:
13301 return "DW_AT_mac_info";
13302 case DW_AT_src_coords
:
13303 return "DW_AT_src_coords";
13304 case DW_AT_body_begin
:
13305 return "DW_AT_body_begin";
13306 case DW_AT_body_end
:
13307 return "DW_AT_body_end";
13308 case DW_AT_GNU_vector
:
13309 return "DW_AT_GNU_vector";
13310 case DW_AT_GNU_odr_signature
:
13311 return "DW_AT_GNU_odr_signature";
13312 /* VMS extensions. */
13313 case DW_AT_VMS_rtnbeg_pd_address
:
13314 return "DW_AT_VMS_rtnbeg_pd_address";
13315 /* UPC extension. */
13316 case DW_AT_upc_threads_scaled
:
13317 return "DW_AT_upc_threads_scaled";
13318 /* PGI (STMicroelectronics) extensions. */
13319 case DW_AT_PGI_lbase
:
13320 return "DW_AT_PGI_lbase";
13321 case DW_AT_PGI_soffset
:
13322 return "DW_AT_PGI_soffset";
13323 case DW_AT_PGI_lstride
:
13324 return "DW_AT_PGI_lstride";
13326 return "DW_AT_<unknown>";
13330 /* Convert a DWARF value form code into its string name. */
13333 dwarf_form_name (unsigned form
)
13338 return "DW_FORM_addr";
13339 case DW_FORM_block2
:
13340 return "DW_FORM_block2";
13341 case DW_FORM_block4
:
13342 return "DW_FORM_block4";
13343 case DW_FORM_data2
:
13344 return "DW_FORM_data2";
13345 case DW_FORM_data4
:
13346 return "DW_FORM_data4";
13347 case DW_FORM_data8
:
13348 return "DW_FORM_data8";
13349 case DW_FORM_string
:
13350 return "DW_FORM_string";
13351 case DW_FORM_block
:
13352 return "DW_FORM_block";
13353 case DW_FORM_block1
:
13354 return "DW_FORM_block1";
13355 case DW_FORM_data1
:
13356 return "DW_FORM_data1";
13358 return "DW_FORM_flag";
13359 case DW_FORM_sdata
:
13360 return "DW_FORM_sdata";
13362 return "DW_FORM_strp";
13363 case DW_FORM_udata
:
13364 return "DW_FORM_udata";
13365 case DW_FORM_ref_addr
:
13366 return "DW_FORM_ref_addr";
13368 return "DW_FORM_ref1";
13370 return "DW_FORM_ref2";
13372 return "DW_FORM_ref4";
13374 return "DW_FORM_ref8";
13375 case DW_FORM_ref_udata
:
13376 return "DW_FORM_ref_udata";
13377 case DW_FORM_indirect
:
13378 return "DW_FORM_indirect";
13379 case DW_FORM_sec_offset
:
13380 return "DW_FORM_sec_offset";
13381 case DW_FORM_exprloc
:
13382 return "DW_FORM_exprloc";
13383 case DW_FORM_flag_present
:
13384 return "DW_FORM_flag_present";
13385 case DW_FORM_ref_sig8
:
13386 return "DW_FORM_ref_sig8";
13388 return "DW_FORM_<unknown>";
13392 /* Convert a DWARF stack opcode into its string name. */
13395 dwarf_stack_op_name (unsigned op
)
13400 return "DW_OP_addr";
13402 return "DW_OP_deref";
13403 case DW_OP_const1u
:
13404 return "DW_OP_const1u";
13405 case DW_OP_const1s
:
13406 return "DW_OP_const1s";
13407 case DW_OP_const2u
:
13408 return "DW_OP_const2u";
13409 case DW_OP_const2s
:
13410 return "DW_OP_const2s";
13411 case DW_OP_const4u
:
13412 return "DW_OP_const4u";
13413 case DW_OP_const4s
:
13414 return "DW_OP_const4s";
13415 case DW_OP_const8u
:
13416 return "DW_OP_const8u";
13417 case DW_OP_const8s
:
13418 return "DW_OP_const8s";
13420 return "DW_OP_constu";
13422 return "DW_OP_consts";
13424 return "DW_OP_dup";
13426 return "DW_OP_drop";
13428 return "DW_OP_over";
13430 return "DW_OP_pick";
13432 return "DW_OP_swap";
13434 return "DW_OP_rot";
13436 return "DW_OP_xderef";
13438 return "DW_OP_abs";
13440 return "DW_OP_and";
13442 return "DW_OP_div";
13444 return "DW_OP_minus";
13446 return "DW_OP_mod";
13448 return "DW_OP_mul";
13450 return "DW_OP_neg";
13452 return "DW_OP_not";
13456 return "DW_OP_plus";
13457 case DW_OP_plus_uconst
:
13458 return "DW_OP_plus_uconst";
13460 return "DW_OP_shl";
13462 return "DW_OP_shr";
13464 return "DW_OP_shra";
13466 return "DW_OP_xor";
13468 return "DW_OP_bra";
13482 return "DW_OP_skip";
13484 return "DW_OP_lit0";
13486 return "DW_OP_lit1";
13488 return "DW_OP_lit2";
13490 return "DW_OP_lit3";
13492 return "DW_OP_lit4";
13494 return "DW_OP_lit5";
13496 return "DW_OP_lit6";
13498 return "DW_OP_lit7";
13500 return "DW_OP_lit8";
13502 return "DW_OP_lit9";
13504 return "DW_OP_lit10";
13506 return "DW_OP_lit11";
13508 return "DW_OP_lit12";
13510 return "DW_OP_lit13";
13512 return "DW_OP_lit14";
13514 return "DW_OP_lit15";
13516 return "DW_OP_lit16";
13518 return "DW_OP_lit17";
13520 return "DW_OP_lit18";
13522 return "DW_OP_lit19";
13524 return "DW_OP_lit20";
13526 return "DW_OP_lit21";
13528 return "DW_OP_lit22";
13530 return "DW_OP_lit23";
13532 return "DW_OP_lit24";
13534 return "DW_OP_lit25";
13536 return "DW_OP_lit26";
13538 return "DW_OP_lit27";
13540 return "DW_OP_lit28";
13542 return "DW_OP_lit29";
13544 return "DW_OP_lit30";
13546 return "DW_OP_lit31";
13548 return "DW_OP_reg0";
13550 return "DW_OP_reg1";
13552 return "DW_OP_reg2";
13554 return "DW_OP_reg3";
13556 return "DW_OP_reg4";
13558 return "DW_OP_reg5";
13560 return "DW_OP_reg6";
13562 return "DW_OP_reg7";
13564 return "DW_OP_reg8";
13566 return "DW_OP_reg9";
13568 return "DW_OP_reg10";
13570 return "DW_OP_reg11";
13572 return "DW_OP_reg12";
13574 return "DW_OP_reg13";
13576 return "DW_OP_reg14";
13578 return "DW_OP_reg15";
13580 return "DW_OP_reg16";
13582 return "DW_OP_reg17";
13584 return "DW_OP_reg18";
13586 return "DW_OP_reg19";
13588 return "DW_OP_reg20";
13590 return "DW_OP_reg21";
13592 return "DW_OP_reg22";
13594 return "DW_OP_reg23";
13596 return "DW_OP_reg24";
13598 return "DW_OP_reg25";
13600 return "DW_OP_reg26";
13602 return "DW_OP_reg27";
13604 return "DW_OP_reg28";
13606 return "DW_OP_reg29";
13608 return "DW_OP_reg30";
13610 return "DW_OP_reg31";
13612 return "DW_OP_breg0";
13614 return "DW_OP_breg1";
13616 return "DW_OP_breg2";
13618 return "DW_OP_breg3";
13620 return "DW_OP_breg4";
13622 return "DW_OP_breg5";
13624 return "DW_OP_breg6";
13626 return "DW_OP_breg7";
13628 return "DW_OP_breg8";
13630 return "DW_OP_breg9";
13632 return "DW_OP_breg10";
13634 return "DW_OP_breg11";
13636 return "DW_OP_breg12";
13638 return "DW_OP_breg13";
13640 return "DW_OP_breg14";
13642 return "DW_OP_breg15";
13644 return "DW_OP_breg16";
13646 return "DW_OP_breg17";
13648 return "DW_OP_breg18";
13650 return "DW_OP_breg19";
13652 return "DW_OP_breg20";
13654 return "DW_OP_breg21";
13656 return "DW_OP_breg22";
13658 return "DW_OP_breg23";
13660 return "DW_OP_breg24";
13662 return "DW_OP_breg25";
13664 return "DW_OP_breg26";
13666 return "DW_OP_breg27";
13668 return "DW_OP_breg28";
13670 return "DW_OP_breg29";
13672 return "DW_OP_breg30";
13674 return "DW_OP_breg31";
13676 return "DW_OP_regx";
13678 return "DW_OP_fbreg";
13680 return "DW_OP_bregx";
13682 return "DW_OP_piece";
13683 case DW_OP_deref_size
:
13684 return "DW_OP_deref_size";
13685 case DW_OP_xderef_size
:
13686 return "DW_OP_xderef_size";
13688 return "DW_OP_nop";
13689 /* DWARF 3 extensions. */
13690 case DW_OP_push_object_address
:
13691 return "DW_OP_push_object_address";
13693 return "DW_OP_call2";
13695 return "DW_OP_call4";
13696 case DW_OP_call_ref
:
13697 return "DW_OP_call_ref";
13698 case DW_OP_form_tls_address
:
13699 return "DW_OP_form_tls_address";
13700 case DW_OP_call_frame_cfa
:
13701 return "DW_OP_call_frame_cfa";
13702 case DW_OP_bit_piece
:
13703 return "DW_OP_bit_piece";
13704 /* DWARF 4 extensions. */
13705 case DW_OP_implicit_value
:
13706 return "DW_OP_implicit_value";
13707 case DW_OP_stack_value
:
13708 return "DW_OP_stack_value";
13709 /* GNU extensions. */
13710 case DW_OP_GNU_push_tls_address
:
13711 return "DW_OP_GNU_push_tls_address";
13712 case DW_OP_GNU_uninit
:
13713 return "DW_OP_GNU_uninit";
13714 case DW_OP_GNU_implicit_pointer
:
13715 return "DW_OP_GNU_implicit_pointer";
13716 case DW_OP_GNU_entry_value
:
13717 return "DW_OP_GNU_entry_value";
13718 case DW_OP_GNU_const_type
:
13719 return "DW_OP_GNU_const_type";
13720 case DW_OP_GNU_regval_type
:
13721 return "DW_OP_GNU_regval_type";
13722 case DW_OP_GNU_deref_type
:
13723 return "DW_OP_GNU_deref_type";
13724 case DW_OP_GNU_convert
:
13725 return "DW_OP_GNU_convert";
13726 case DW_OP_GNU_reinterpret
:
13727 return "DW_OP_GNU_reinterpret";
13734 dwarf_bool_name (unsigned mybool
)
13742 /* Convert a DWARF type code into its string name. */
13745 dwarf_type_encoding_name (unsigned enc
)
13750 return "DW_ATE_void";
13751 case DW_ATE_address
:
13752 return "DW_ATE_address";
13753 case DW_ATE_boolean
:
13754 return "DW_ATE_boolean";
13755 case DW_ATE_complex_float
:
13756 return "DW_ATE_complex_float";
13758 return "DW_ATE_float";
13759 case DW_ATE_signed
:
13760 return "DW_ATE_signed";
13761 case DW_ATE_signed_char
:
13762 return "DW_ATE_signed_char";
13763 case DW_ATE_unsigned
:
13764 return "DW_ATE_unsigned";
13765 case DW_ATE_unsigned_char
:
13766 return "DW_ATE_unsigned_char";
13768 case DW_ATE_imaginary_float
:
13769 return "DW_ATE_imaginary_float";
13770 case DW_ATE_packed_decimal
:
13771 return "DW_ATE_packed_decimal";
13772 case DW_ATE_numeric_string
:
13773 return "DW_ATE_numeric_string";
13774 case DW_ATE_edited
:
13775 return "DW_ATE_edited";
13776 case DW_ATE_signed_fixed
:
13777 return "DW_ATE_signed_fixed";
13778 case DW_ATE_unsigned_fixed
:
13779 return "DW_ATE_unsigned_fixed";
13780 case DW_ATE_decimal_float
:
13781 return "DW_ATE_decimal_float";
13784 return "DW_ATE_UTF";
13785 /* HP extensions. */
13786 case DW_ATE_HP_float80
:
13787 return "DW_ATE_HP_float80";
13788 case DW_ATE_HP_complex_float80
:
13789 return "DW_ATE_HP_complex_float80";
13790 case DW_ATE_HP_float128
:
13791 return "DW_ATE_HP_float128";
13792 case DW_ATE_HP_complex_float128
:
13793 return "DW_ATE_HP_complex_float128";
13794 case DW_ATE_HP_floathpintel
:
13795 return "DW_ATE_HP_floathpintel";
13796 case DW_ATE_HP_imaginary_float80
:
13797 return "DW_ATE_HP_imaginary_float80";
13798 case DW_ATE_HP_imaginary_float128
:
13799 return "DW_ATE_HP_imaginary_float128";
13801 return "DW_ATE_<unknown>";
13805 /* Convert a DWARF call frame info operation to its string name. */
13809 dwarf_cfi_name (unsigned cfi_opc
)
13813 case DW_CFA_advance_loc
:
13814 return "DW_CFA_advance_loc";
13815 case DW_CFA_offset
:
13816 return "DW_CFA_offset";
13817 case DW_CFA_restore
:
13818 return "DW_CFA_restore";
13820 return "DW_CFA_nop";
13821 case DW_CFA_set_loc
:
13822 return "DW_CFA_set_loc";
13823 case DW_CFA_advance_loc1
:
13824 return "DW_CFA_advance_loc1";
13825 case DW_CFA_advance_loc2
:
13826 return "DW_CFA_advance_loc2";
13827 case DW_CFA_advance_loc4
:
13828 return "DW_CFA_advance_loc4";
13829 case DW_CFA_offset_extended
:
13830 return "DW_CFA_offset_extended";
13831 case DW_CFA_restore_extended
:
13832 return "DW_CFA_restore_extended";
13833 case DW_CFA_undefined
:
13834 return "DW_CFA_undefined";
13835 case DW_CFA_same_value
:
13836 return "DW_CFA_same_value";
13837 case DW_CFA_register
:
13838 return "DW_CFA_register";
13839 case DW_CFA_remember_state
:
13840 return "DW_CFA_remember_state";
13841 case DW_CFA_restore_state
:
13842 return "DW_CFA_restore_state";
13843 case DW_CFA_def_cfa
:
13844 return "DW_CFA_def_cfa";
13845 case DW_CFA_def_cfa_register
:
13846 return "DW_CFA_def_cfa_register";
13847 case DW_CFA_def_cfa_offset
:
13848 return "DW_CFA_def_cfa_offset";
13850 case DW_CFA_def_cfa_expression
:
13851 return "DW_CFA_def_cfa_expression";
13852 case DW_CFA_expression
:
13853 return "DW_CFA_expression";
13854 case DW_CFA_offset_extended_sf
:
13855 return "DW_CFA_offset_extended_sf";
13856 case DW_CFA_def_cfa_sf
:
13857 return "DW_CFA_def_cfa_sf";
13858 case DW_CFA_def_cfa_offset_sf
:
13859 return "DW_CFA_def_cfa_offset_sf";
13860 case DW_CFA_val_offset
:
13861 return "DW_CFA_val_offset";
13862 case DW_CFA_val_offset_sf
:
13863 return "DW_CFA_val_offset_sf";
13864 case DW_CFA_val_expression
:
13865 return "DW_CFA_val_expression";
13866 /* SGI/MIPS specific. */
13867 case DW_CFA_MIPS_advance_loc8
:
13868 return "DW_CFA_MIPS_advance_loc8";
13869 /* GNU extensions. */
13870 case DW_CFA_GNU_window_save
:
13871 return "DW_CFA_GNU_window_save";
13872 case DW_CFA_GNU_args_size
:
13873 return "DW_CFA_GNU_args_size";
13874 case DW_CFA_GNU_negative_offset_extended
:
13875 return "DW_CFA_GNU_negative_offset_extended";
13877 return "DW_CFA_<unknown>";
13883 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
13887 print_spaces (indent
, f
);
13888 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
13889 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
13891 if (die
->parent
!= NULL
)
13893 print_spaces (indent
, f
);
13894 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
13895 die
->parent
->offset
);
13898 print_spaces (indent
, f
);
13899 fprintf_unfiltered (f
, " has children: %s\n",
13900 dwarf_bool_name (die
->child
!= NULL
));
13902 print_spaces (indent
, f
);
13903 fprintf_unfiltered (f
, " attributes:\n");
13905 for (i
= 0; i
< die
->num_attrs
; ++i
)
13907 print_spaces (indent
, f
);
13908 fprintf_unfiltered (f
, " %s (%s) ",
13909 dwarf_attr_name (die
->attrs
[i
].name
),
13910 dwarf_form_name (die
->attrs
[i
].form
));
13912 switch (die
->attrs
[i
].form
)
13914 case DW_FORM_ref_addr
:
13916 fprintf_unfiltered (f
, "address: ");
13917 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
13919 case DW_FORM_block2
:
13920 case DW_FORM_block4
:
13921 case DW_FORM_block
:
13922 case DW_FORM_block1
:
13923 fprintf_unfiltered (f
, "block: size %d",
13924 DW_BLOCK (&die
->attrs
[i
])->size
);
13926 case DW_FORM_exprloc
:
13927 fprintf_unfiltered (f
, "expression: size %u",
13928 DW_BLOCK (&die
->attrs
[i
])->size
);
13933 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
13934 (long) (DW_ADDR (&die
->attrs
[i
])));
13936 case DW_FORM_data1
:
13937 case DW_FORM_data2
:
13938 case DW_FORM_data4
:
13939 case DW_FORM_data8
:
13940 case DW_FORM_udata
:
13941 case DW_FORM_sdata
:
13942 fprintf_unfiltered (f
, "constant: %s",
13943 pulongest (DW_UNSND (&die
->attrs
[i
])));
13945 case DW_FORM_sec_offset
:
13946 fprintf_unfiltered (f
, "section offset: %s",
13947 pulongest (DW_UNSND (&die
->attrs
[i
])));
13949 case DW_FORM_ref_sig8
:
13950 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
13951 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
13952 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
);
13954 fprintf_unfiltered (f
, "signatured type, offset: unknown");
13956 case DW_FORM_string
:
13958 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
13959 DW_STRING (&die
->attrs
[i
])
13960 ? DW_STRING (&die
->attrs
[i
]) : "",
13961 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
13964 if (DW_UNSND (&die
->attrs
[i
]))
13965 fprintf_unfiltered (f
, "flag: TRUE");
13967 fprintf_unfiltered (f
, "flag: FALSE");
13969 case DW_FORM_flag_present
:
13970 fprintf_unfiltered (f
, "flag: TRUE");
13972 case DW_FORM_indirect
:
13973 /* The reader will have reduced the indirect form to
13974 the "base form" so this form should not occur. */
13975 fprintf_unfiltered (f
,
13976 "unexpected attribute form: DW_FORM_indirect");
13979 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
13980 die
->attrs
[i
].form
);
13983 fprintf_unfiltered (f
, "\n");
13988 dump_die_for_error (struct die_info
*die
)
13990 dump_die_shallow (gdb_stderr
, 0, die
);
13994 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
13996 int indent
= level
* 4;
13998 gdb_assert (die
!= NULL
);
14000 if (level
>= max_level
)
14003 dump_die_shallow (f
, indent
, die
);
14005 if (die
->child
!= NULL
)
14007 print_spaces (indent
, f
);
14008 fprintf_unfiltered (f
, " Children:");
14009 if (level
+ 1 < max_level
)
14011 fprintf_unfiltered (f
, "\n");
14012 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
14016 fprintf_unfiltered (f
,
14017 " [not printed, max nesting level reached]\n");
14021 if (die
->sibling
!= NULL
&& level
> 0)
14023 dump_die_1 (f
, level
, max_level
, die
->sibling
);
14027 /* This is called from the pdie macro in gdbinit.in.
14028 It's not static so gcc will keep a copy callable from gdb. */
14031 dump_die (struct die_info
*die
, int max_level
)
14033 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
14037 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
14041 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
14047 is_ref_attr (struct attribute
*attr
)
14049 switch (attr
->form
)
14051 case DW_FORM_ref_addr
:
14056 case DW_FORM_ref_udata
:
14063 static unsigned int
14064 dwarf2_get_ref_die_offset (struct attribute
*attr
)
14066 if (is_ref_attr (attr
))
14067 return DW_ADDR (attr
);
14069 complaint (&symfile_complaints
,
14070 _("unsupported die ref attribute form: '%s'"),
14071 dwarf_form_name (attr
->form
));
14075 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
14076 * the value held by the attribute is not constant. */
14079 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
14081 if (attr
->form
== DW_FORM_sdata
)
14082 return DW_SND (attr
);
14083 else if (attr
->form
== DW_FORM_udata
14084 || attr
->form
== DW_FORM_data1
14085 || attr
->form
== DW_FORM_data2
14086 || attr
->form
== DW_FORM_data4
14087 || attr
->form
== DW_FORM_data8
)
14088 return DW_UNSND (attr
);
14091 complaint (&symfile_complaints
,
14092 _("Attribute value is not a constant (%s)"),
14093 dwarf_form_name (attr
->form
));
14094 return default_value
;
14098 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
14099 unit and add it to our queue.
14100 The result is non-zero if PER_CU was queued, otherwise the result is zero
14101 meaning either PER_CU is already queued or it is already loaded. */
14104 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
14105 struct dwarf2_per_cu_data
*per_cu
)
14107 /* We may arrive here during partial symbol reading, if we need full
14108 DIEs to process an unusual case (e.g. template arguments). Do
14109 not queue PER_CU, just tell our caller to load its DIEs. */
14110 if (dwarf2_per_objfile
->reading_partial_symbols
)
14112 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
14117 /* Mark the dependence relation so that we don't flush PER_CU
14119 dwarf2_add_dependence (this_cu
, per_cu
);
14121 /* If it's already on the queue, we have nothing to do. */
14122 if (per_cu
->queued
)
14125 /* If the compilation unit is already loaded, just mark it as
14127 if (per_cu
->cu
!= NULL
)
14129 per_cu
->cu
->last_used
= 0;
14133 /* Add it to the queue. */
14134 queue_comp_unit (per_cu
);
14139 /* Follow reference or signature attribute ATTR of SRC_DIE.
14140 On entry *REF_CU is the CU of SRC_DIE.
14141 On exit *REF_CU is the CU of the result. */
14143 static struct die_info
*
14144 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
14145 struct dwarf2_cu
**ref_cu
)
14147 struct die_info
*die
;
14149 if (is_ref_attr (attr
))
14150 die
= follow_die_ref (src_die
, attr
, ref_cu
);
14151 else if (attr
->form
== DW_FORM_ref_sig8
)
14152 die
= follow_die_sig (src_die
, attr
, ref_cu
);
14155 dump_die_for_error (src_die
);
14156 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
14157 (*ref_cu
)->objfile
->name
);
14163 /* Follow reference OFFSET.
14164 On entry *REF_CU is the CU of the source die referencing OFFSET.
14165 On exit *REF_CU is the CU of the result.
14166 Returns NULL if OFFSET is invalid. */
14168 static struct die_info
*
14169 follow_die_offset (unsigned int offset
, struct dwarf2_cu
**ref_cu
)
14171 struct die_info temp_die
;
14172 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
14174 gdb_assert (cu
->per_cu
!= NULL
);
14178 if (cu
->per_cu
->debug_types_section
)
14180 /* .debug_types CUs cannot reference anything outside their CU.
14181 If they need to, they have to reference a signatured type via
14182 DW_FORM_ref_sig8. */
14183 if (! offset_in_cu_p (&cu
->header
, offset
))
14186 else if (! offset_in_cu_p (&cu
->header
, offset
))
14188 struct dwarf2_per_cu_data
*per_cu
;
14190 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
14192 /* If necessary, add it to the queue and load its DIEs. */
14193 if (maybe_queue_comp_unit (cu
, per_cu
))
14194 load_full_comp_unit (per_cu
);
14196 target_cu
= per_cu
->cu
;
14198 else if (cu
->dies
== NULL
)
14200 /* We're loading full DIEs during partial symbol reading. */
14201 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
14202 load_full_comp_unit (cu
->per_cu
);
14205 *ref_cu
= target_cu
;
14206 temp_die
.offset
= offset
;
14207 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
14210 /* Follow reference attribute ATTR of SRC_DIE.
14211 On entry *REF_CU is the CU of SRC_DIE.
14212 On exit *REF_CU is the CU of the result. */
14214 static struct die_info
*
14215 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
14216 struct dwarf2_cu
**ref_cu
)
14218 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
14219 struct dwarf2_cu
*cu
= *ref_cu
;
14220 struct die_info
*die
;
14222 die
= follow_die_offset (offset
, ref_cu
);
14224 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
14225 "at 0x%x [in module %s]"),
14226 offset
, src_die
->offset
, cu
->objfile
->name
);
14231 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
14232 Returned value is intended for DW_OP_call*. Returned
14233 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
14235 struct dwarf2_locexpr_baton
14236 dwarf2_fetch_die_location_block (unsigned int offset
,
14237 struct dwarf2_per_cu_data
*per_cu
,
14238 CORE_ADDR (*get_frame_pc
) (void *baton
),
14241 struct dwarf2_cu
*cu
;
14242 struct die_info
*die
;
14243 struct attribute
*attr
;
14244 struct dwarf2_locexpr_baton retval
;
14246 dw2_setup (per_cu
->objfile
);
14248 if (per_cu
->cu
== NULL
)
14252 die
= follow_die_offset (offset
, &cu
);
14254 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
14255 offset
, per_cu
->objfile
->name
);
14257 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
14260 /* DWARF: "If there is no such attribute, then there is no effect.".
14261 DATA is ignored if SIZE is 0. */
14263 retval
.data
= NULL
;
14266 else if (attr_form_is_section_offset (attr
))
14268 struct dwarf2_loclist_baton loclist_baton
;
14269 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
14272 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
14274 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
14276 retval
.size
= size
;
14280 if (!attr_form_is_block (attr
))
14281 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
14282 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
14283 offset
, per_cu
->objfile
->name
);
14285 retval
.data
= DW_BLOCK (attr
)->data
;
14286 retval
.size
= DW_BLOCK (attr
)->size
;
14288 retval
.per_cu
= cu
->per_cu
;
14290 age_cached_comp_units ();
14295 /* Return the type of the DIE at DIE_OFFSET in the CU named by
14299 dwarf2_get_die_type (unsigned int die_offset
,
14300 struct dwarf2_per_cu_data
*per_cu
)
14302 dw2_setup (per_cu
->objfile
);
14303 return get_die_type_at_offset (die_offset
, per_cu
);
14306 /* Follow the signature attribute ATTR in SRC_DIE.
14307 On entry *REF_CU is the CU of SRC_DIE.
14308 On exit *REF_CU is the CU of the result. */
14310 static struct die_info
*
14311 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
14312 struct dwarf2_cu
**ref_cu
)
14314 struct objfile
*objfile
= (*ref_cu
)->objfile
;
14315 struct die_info temp_die
;
14316 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
14317 struct dwarf2_cu
*sig_cu
;
14318 struct die_info
*die
;
14320 /* sig_type will be NULL if the signatured type is missing from
14322 if (sig_type
== NULL
)
14323 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
14324 "at 0x%x [in module %s]"),
14325 src_die
->offset
, objfile
->name
);
14327 /* If necessary, add it to the queue and load its DIEs. */
14329 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
14330 read_signatured_type (sig_type
);
14332 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
14334 sig_cu
= sig_type
->per_cu
.cu
;
14335 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
14336 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
14343 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
14344 "from DIE at 0x%x [in module %s]"),
14345 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
14348 /* Given an offset of a signatured type, return its signatured_type. */
14350 static struct signatured_type
*
14351 lookup_signatured_type_at_offset (struct objfile
*objfile
,
14352 struct dwarf2_section_info
*section
,
14353 unsigned int offset
)
14355 gdb_byte
*info_ptr
= section
->buffer
+ offset
;
14356 unsigned int length
, initial_length_size
;
14357 unsigned int sig_offset
;
14358 struct signatured_type find_entry
, *type_sig
;
14360 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
14361 sig_offset
= (initial_length_size
14363 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
14364 + 1 /*address_size*/);
14365 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
14366 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
14368 /* This is only used to lookup previously recorded types.
14369 If we didn't find it, it's our bug. */
14370 gdb_assert (type_sig
!= NULL
);
14371 gdb_assert (offset
== type_sig
->per_cu
.offset
);
14376 /* Load the DIEs associated with type unit PER_CU into memory. */
14379 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
14381 struct objfile
*objfile
= per_cu
->objfile
;
14382 struct dwarf2_section_info
*sect
= per_cu
->debug_types_section
;
14383 unsigned int offset
= per_cu
->offset
;
14384 struct signatured_type
*type_sig
;
14386 dwarf2_read_section (objfile
, sect
);
14388 /* We have the section offset, but we need the signature to do the
14389 hash table lookup. */
14390 /* FIXME: This is sorta unnecessary, read_signatured_type only uses
14391 the signature to assert we found the right one.
14392 Ok, but it's a lot of work. We should simplify things so any needed
14393 assert doesn't require all this clumsiness. */
14394 type_sig
= lookup_signatured_type_at_offset (objfile
, sect
, offset
);
14396 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
14398 read_signatured_type (type_sig
);
14400 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
14403 /* Read in a signatured type and build its CU and DIEs. */
14406 read_signatured_type (struct signatured_type
*type_sig
)
14408 struct objfile
*objfile
= type_sig
->per_cu
.objfile
;
14409 gdb_byte
*types_ptr
;
14410 struct die_reader_specs reader_specs
;
14411 struct dwarf2_cu
*cu
;
14412 ULONGEST signature
;
14413 struct cleanup
*back_to
, *free_cu_cleanup
;
14414 struct dwarf2_section_info
*section
= type_sig
->per_cu
.debug_types_section
;
14416 dwarf2_read_section (objfile
, section
);
14417 types_ptr
= section
->buffer
+ type_sig
->per_cu
.offset
;
14419 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
14421 cu
= xmalloc (sizeof (*cu
));
14422 init_one_comp_unit (cu
, &type_sig
->per_cu
);
14424 /* If an error occurs while loading, release our storage. */
14425 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
14427 types_ptr
= read_and_check_type_unit_head (&cu
->header
, section
, types_ptr
,
14429 gdb_assert (signature
== type_sig
->signature
);
14432 = htab_create_alloc_ex (cu
->header
.length
/ 12,
14436 &cu
->comp_unit_obstack
,
14437 hashtab_obstack_allocate
,
14438 dummy_obstack_deallocate
);
14440 dwarf2_read_abbrevs (cu
);
14441 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
14443 init_cu_die_reader (&reader_specs
, cu
);
14445 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
14448 /* We try not to read any attributes in this function, because not
14449 all CUs needed for references have been loaded yet, and symbol
14450 table processing isn't initialized. But we have to set the CU language,
14451 or we won't be able to build types correctly. */
14452 prepare_one_comp_unit (cu
, cu
->dies
);
14454 do_cleanups (back_to
);
14456 /* We've successfully allocated this compilation unit. Let our caller
14457 clean it up when finished with it. */
14458 discard_cleanups (free_cu_cleanup
);
14460 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
14461 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
14464 /* Decode simple location descriptions.
14465 Given a pointer to a dwarf block that defines a location, compute
14466 the location and return the value.
14468 NOTE drow/2003-11-18: This function is called in two situations
14469 now: for the address of static or global variables (partial symbols
14470 only) and for offsets into structures which are expected to be
14471 (more or less) constant. The partial symbol case should go away,
14472 and only the constant case should remain. That will let this
14473 function complain more accurately. A few special modes are allowed
14474 without complaint for global variables (for instance, global
14475 register values and thread-local values).
14477 A location description containing no operations indicates that the
14478 object is optimized out. The return value is 0 for that case.
14479 FIXME drow/2003-11-16: No callers check for this case any more; soon all
14480 callers will only want a very basic result and this can become a
14483 Note that stack[0] is unused except as a default error return. */
14486 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
14488 struct objfile
*objfile
= cu
->objfile
;
14490 int size
= blk
->size
;
14491 gdb_byte
*data
= blk
->data
;
14492 CORE_ADDR stack
[64];
14494 unsigned int bytes_read
, unsnd
;
14500 stack
[++stacki
] = 0;
14539 stack
[++stacki
] = op
- DW_OP_lit0
;
14574 stack
[++stacki
] = op
- DW_OP_reg0
;
14576 dwarf2_complex_location_expr_complaint ();
14580 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
14582 stack
[++stacki
] = unsnd
;
14584 dwarf2_complex_location_expr_complaint ();
14588 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
14593 case DW_OP_const1u
:
14594 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
14598 case DW_OP_const1s
:
14599 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
14603 case DW_OP_const2u
:
14604 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
14608 case DW_OP_const2s
:
14609 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
14613 case DW_OP_const4u
:
14614 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
14618 case DW_OP_const4s
:
14619 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
14623 case DW_OP_const8u
:
14624 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
14629 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
14635 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
14640 stack
[stacki
+ 1] = stack
[stacki
];
14645 stack
[stacki
- 1] += stack
[stacki
];
14649 case DW_OP_plus_uconst
:
14650 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
14656 stack
[stacki
- 1] -= stack
[stacki
];
14661 /* If we're not the last op, then we definitely can't encode
14662 this using GDB's address_class enum. This is valid for partial
14663 global symbols, although the variable's address will be bogus
14666 dwarf2_complex_location_expr_complaint ();
14669 case DW_OP_GNU_push_tls_address
:
14670 /* The top of the stack has the offset from the beginning
14671 of the thread control block at which the variable is located. */
14672 /* Nothing should follow this operator, so the top of stack would
14674 /* This is valid for partial global symbols, but the variable's
14675 address will be bogus in the psymtab. Make it always at least
14676 non-zero to not look as a variable garbage collected by linker
14677 which have DW_OP_addr 0. */
14679 dwarf2_complex_location_expr_complaint ();
14683 case DW_OP_GNU_uninit
:
14688 const char *name
= dwarf_stack_op_name (op
);
14691 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
14694 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
14698 return (stack
[stacki
]);
14701 /* Enforce maximum stack depth of SIZE-1 to avoid writing
14702 outside of the allocated space. Also enforce minimum>0. */
14703 if (stacki
>= ARRAY_SIZE (stack
) - 1)
14705 complaint (&symfile_complaints
,
14706 _("location description stack overflow"));
14712 complaint (&symfile_complaints
,
14713 _("location description stack underflow"));
14717 return (stack
[stacki
]);
14720 /* memory allocation interface */
14722 static struct dwarf_block
*
14723 dwarf_alloc_block (struct dwarf2_cu
*cu
)
14725 struct dwarf_block
*blk
;
14727 blk
= (struct dwarf_block
*)
14728 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
14732 static struct abbrev_info
*
14733 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
14735 struct abbrev_info
*abbrev
;
14737 abbrev
= (struct abbrev_info
*)
14738 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
14739 memset (abbrev
, 0, sizeof (struct abbrev_info
));
14743 static struct die_info
*
14744 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
14746 struct die_info
*die
;
14747 size_t size
= sizeof (struct die_info
);
14750 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
14752 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
14753 memset (die
, 0, sizeof (struct die_info
));
14758 /* Macro support. */
14760 /* Return the full name of file number I in *LH's file name table.
14761 Use COMP_DIR as the name of the current directory of the
14762 compilation. The result is allocated using xmalloc; the caller is
14763 responsible for freeing it. */
14765 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
14767 /* Is the file number a valid index into the line header's file name
14768 table? Remember that file numbers start with one, not zero. */
14769 if (1 <= file
&& file
<= lh
->num_file_names
)
14771 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
14773 if (IS_ABSOLUTE_PATH (fe
->name
))
14774 return xstrdup (fe
->name
);
14782 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14788 dir_len
= strlen (dir
);
14789 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
14790 strcpy (full_name
, dir
);
14791 full_name
[dir_len
] = '/';
14792 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
14796 return xstrdup (fe
->name
);
14801 /* The compiler produced a bogus file number. We can at least
14802 record the macro definitions made in the file, even if we
14803 won't be able to find the file by name. */
14804 char fake_name
[80];
14806 sprintf (fake_name
, "<bad macro file number %d>", file
);
14808 complaint (&symfile_complaints
,
14809 _("bad file number in macro information (%d)"),
14812 return xstrdup (fake_name
);
14817 static struct macro_source_file
*
14818 macro_start_file (int file
, int line
,
14819 struct macro_source_file
*current_file
,
14820 const char *comp_dir
,
14821 struct line_header
*lh
, struct objfile
*objfile
)
14823 /* The full name of this source file. */
14824 char *full_name
= file_full_name (file
, lh
, comp_dir
);
14826 /* We don't create a macro table for this compilation unit
14827 at all until we actually get a filename. */
14828 if (! pending_macros
)
14829 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
14830 objfile
->macro_cache
);
14832 if (! current_file
)
14833 /* If we have no current file, then this must be the start_file
14834 directive for the compilation unit's main source file. */
14835 current_file
= macro_set_main (pending_macros
, full_name
);
14837 current_file
= macro_include (current_file
, line
, full_name
);
14841 return current_file
;
14845 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
14846 followed by a null byte. */
14848 copy_string (const char *buf
, int len
)
14850 char *s
= xmalloc (len
+ 1);
14852 memcpy (s
, buf
, len
);
14858 static const char *
14859 consume_improper_spaces (const char *p
, const char *body
)
14863 complaint (&symfile_complaints
,
14864 _("macro definition contains spaces "
14865 "in formal argument list:\n`%s'"),
14877 parse_macro_definition (struct macro_source_file
*file
, int line
,
14882 /* The body string takes one of two forms. For object-like macro
14883 definitions, it should be:
14885 <macro name> " " <definition>
14887 For function-like macro definitions, it should be:
14889 <macro name> "() " <definition>
14891 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
14893 Spaces may appear only where explicitly indicated, and in the
14896 The Dwarf 2 spec says that an object-like macro's name is always
14897 followed by a space, but versions of GCC around March 2002 omit
14898 the space when the macro's definition is the empty string.
14900 The Dwarf 2 spec says that there should be no spaces between the
14901 formal arguments in a function-like macro's formal argument list,
14902 but versions of GCC around March 2002 include spaces after the
14906 /* Find the extent of the macro name. The macro name is terminated
14907 by either a space or null character (for an object-like macro) or
14908 an opening paren (for a function-like macro). */
14909 for (p
= body
; *p
; p
++)
14910 if (*p
== ' ' || *p
== '(')
14913 if (*p
== ' ' || *p
== '\0')
14915 /* It's an object-like macro. */
14916 int name_len
= p
- body
;
14917 char *name
= copy_string (body
, name_len
);
14918 const char *replacement
;
14921 replacement
= body
+ name_len
+ 1;
14924 dwarf2_macro_malformed_definition_complaint (body
);
14925 replacement
= body
+ name_len
;
14928 macro_define_object (file
, line
, name
, replacement
);
14932 else if (*p
== '(')
14934 /* It's a function-like macro. */
14935 char *name
= copy_string (body
, p
- body
);
14938 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
14942 p
= consume_improper_spaces (p
, body
);
14944 /* Parse the formal argument list. */
14945 while (*p
&& *p
!= ')')
14947 /* Find the extent of the current argument name. */
14948 const char *arg_start
= p
;
14950 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
14953 if (! *p
|| p
== arg_start
)
14954 dwarf2_macro_malformed_definition_complaint (body
);
14957 /* Make sure argv has room for the new argument. */
14958 if (argc
>= argv_size
)
14961 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
14964 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
14967 p
= consume_improper_spaces (p
, body
);
14969 /* Consume the comma, if present. */
14974 p
= consume_improper_spaces (p
, body
);
14983 /* Perfectly formed definition, no complaints. */
14984 macro_define_function (file
, line
, name
,
14985 argc
, (const char **) argv
,
14987 else if (*p
== '\0')
14989 /* Complain, but do define it. */
14990 dwarf2_macro_malformed_definition_complaint (body
);
14991 macro_define_function (file
, line
, name
,
14992 argc
, (const char **) argv
,
14996 /* Just complain. */
14997 dwarf2_macro_malformed_definition_complaint (body
);
15000 /* Just complain. */
15001 dwarf2_macro_malformed_definition_complaint (body
);
15007 for (i
= 0; i
< argc
; i
++)
15013 dwarf2_macro_malformed_definition_complaint (body
);
15016 /* Skip some bytes from BYTES according to the form given in FORM.
15017 Returns the new pointer. */
15020 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
,
15021 enum dwarf_form form
,
15022 unsigned int offset_size
,
15023 struct dwarf2_section_info
*section
)
15025 unsigned int bytes_read
;
15029 case DW_FORM_data1
:
15034 case DW_FORM_data2
:
15038 case DW_FORM_data4
:
15042 case DW_FORM_data8
:
15046 case DW_FORM_string
:
15047 read_direct_string (abfd
, bytes
, &bytes_read
);
15048 bytes
+= bytes_read
;
15051 case DW_FORM_sec_offset
:
15053 bytes
+= offset_size
;
15056 case DW_FORM_block
:
15057 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
15058 bytes
+= bytes_read
;
15061 case DW_FORM_block1
:
15062 bytes
+= 1 + read_1_byte (abfd
, bytes
);
15064 case DW_FORM_block2
:
15065 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
15067 case DW_FORM_block4
:
15068 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
15071 case DW_FORM_sdata
:
15072 case DW_FORM_udata
:
15073 bytes
= skip_leb128 (abfd
, bytes
);
15079 complaint (&symfile_complaints
,
15080 _("invalid form 0x%x in `%s'"),
15082 section
->asection
->name
);
15090 /* A helper for dwarf_decode_macros that handles skipping an unknown
15091 opcode. Returns an updated pointer to the macro data buffer; or,
15092 on error, issues a complaint and returns NULL. */
15095 skip_unknown_opcode (unsigned int opcode
,
15096 gdb_byte
**opcode_definitions
,
15099 unsigned int offset_size
,
15100 struct dwarf2_section_info
*section
)
15102 unsigned int bytes_read
, i
;
15106 if (opcode_definitions
[opcode
] == NULL
)
15108 complaint (&symfile_complaints
,
15109 _("unrecognized DW_MACFINO opcode 0x%x"),
15114 defn
= opcode_definitions
[opcode
];
15115 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
15116 defn
+= bytes_read
;
15118 for (i
= 0; i
< arg
; ++i
)
15120 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, defn
[i
], offset_size
, section
);
15121 if (mac_ptr
== NULL
)
15123 /* skip_form_bytes already issued the complaint. */
15131 /* A helper function which parses the header of a macro section.
15132 If the macro section is the extended (for now called "GNU") type,
15133 then this updates *OFFSET_SIZE. Returns a pointer to just after
15134 the header, or issues a complaint and returns NULL on error. */
15137 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
15140 unsigned int *offset_size
,
15141 int section_is_gnu
)
15143 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
15145 if (section_is_gnu
)
15147 unsigned int version
, flags
;
15149 version
= read_2_bytes (abfd
, mac_ptr
);
15152 complaint (&symfile_complaints
,
15153 _("unrecognized version `%d' in .debug_macro section"),
15159 flags
= read_1_byte (abfd
, mac_ptr
);
15161 *offset_size
= (flags
& 1) ? 8 : 4;
15163 if ((flags
& 2) != 0)
15164 /* We don't need the line table offset. */
15165 mac_ptr
+= *offset_size
;
15167 /* Vendor opcode descriptions. */
15168 if ((flags
& 4) != 0)
15170 unsigned int i
, count
;
15172 count
= read_1_byte (abfd
, mac_ptr
);
15174 for (i
= 0; i
< count
; ++i
)
15176 unsigned int opcode
, bytes_read
;
15179 opcode
= read_1_byte (abfd
, mac_ptr
);
15181 opcode_definitions
[opcode
] = mac_ptr
;
15182 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15183 mac_ptr
+= bytes_read
;
15192 /* A helper for dwarf_decode_macros that handles the GNU extensions,
15193 including DW_MACRO_GNU_transparent_include. */
15196 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
15197 struct macro_source_file
*current_file
,
15198 struct line_header
*lh
, char *comp_dir
,
15199 struct dwarf2_section_info
*section
,
15200 int section_is_gnu
,
15201 unsigned int offset_size
,
15202 struct objfile
*objfile
,
15203 htab_t include_hash
)
15205 enum dwarf_macro_record_type macinfo_type
;
15206 int at_commandline
;
15207 gdb_byte
*opcode_definitions
[256];
15209 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
15210 &offset_size
, section_is_gnu
);
15211 if (mac_ptr
== NULL
)
15213 /* We already issued a complaint. */
15217 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
15218 GDB is still reading the definitions from command line. First
15219 DW_MACINFO_start_file will need to be ignored as it was already executed
15220 to create CURRENT_FILE for the main source holding also the command line
15221 definitions. On first met DW_MACINFO_start_file this flag is reset to
15222 normally execute all the remaining DW_MACINFO_start_file macinfos. */
15224 at_commandline
= 1;
15228 /* Do we at least have room for a macinfo type byte? */
15229 if (mac_ptr
>= mac_end
)
15231 dwarf2_macros_too_long_complaint (section
);
15235 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
15238 /* Note that we rely on the fact that the corresponding GNU and
15239 DWARF constants are the same. */
15240 switch (macinfo_type
)
15242 /* A zero macinfo type indicates the end of the macro
15247 case DW_MACRO_GNU_define
:
15248 case DW_MACRO_GNU_undef
:
15249 case DW_MACRO_GNU_define_indirect
:
15250 case DW_MACRO_GNU_undef_indirect
:
15252 unsigned int bytes_read
;
15257 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15258 mac_ptr
+= bytes_read
;
15260 if (macinfo_type
== DW_MACRO_GNU_define
15261 || macinfo_type
== DW_MACRO_GNU_undef
)
15263 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15264 mac_ptr
+= bytes_read
;
15268 LONGEST str_offset
;
15270 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
15271 mac_ptr
+= offset_size
;
15273 body
= read_indirect_string_at_offset (abfd
, str_offset
);
15276 is_define
= (macinfo_type
== DW_MACRO_GNU_define
15277 || macinfo_type
== DW_MACRO_GNU_define_indirect
);
15278 if (! current_file
)
15280 /* DWARF violation as no main source is present. */
15281 complaint (&symfile_complaints
,
15282 _("debug info with no main source gives macro %s "
15284 is_define
? _("definition") : _("undefinition"),
15288 if ((line
== 0 && !at_commandline
)
15289 || (line
!= 0 && at_commandline
))
15290 complaint (&symfile_complaints
,
15291 _("debug info gives %s macro %s with %s line %d: %s"),
15292 at_commandline
? _("command-line") : _("in-file"),
15293 is_define
? _("definition") : _("undefinition"),
15294 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
15297 parse_macro_definition (current_file
, line
, body
);
15300 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
15301 || macinfo_type
== DW_MACRO_GNU_undef_indirect
);
15302 macro_undef (current_file
, line
, body
);
15307 case DW_MACRO_GNU_start_file
:
15309 unsigned int bytes_read
;
15312 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15313 mac_ptr
+= bytes_read
;
15314 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15315 mac_ptr
+= bytes_read
;
15317 if ((line
== 0 && !at_commandline
)
15318 || (line
!= 0 && at_commandline
))
15319 complaint (&symfile_complaints
,
15320 _("debug info gives source %d included "
15321 "from %s at %s line %d"),
15322 file
, at_commandline
? _("command-line") : _("file"),
15323 line
== 0 ? _("zero") : _("non-zero"), line
);
15325 if (at_commandline
)
15327 /* This DW_MACRO_GNU_start_file was executed in the
15329 at_commandline
= 0;
15332 current_file
= macro_start_file (file
, line
,
15333 current_file
, comp_dir
,
15338 case DW_MACRO_GNU_end_file
:
15339 if (! current_file
)
15340 complaint (&symfile_complaints
,
15341 _("macro debug info has an unmatched "
15342 "`close_file' directive"));
15345 current_file
= current_file
->included_by
;
15346 if (! current_file
)
15348 enum dwarf_macro_record_type next_type
;
15350 /* GCC circa March 2002 doesn't produce the zero
15351 type byte marking the end of the compilation
15352 unit. Complain if it's not there, but exit no
15355 /* Do we at least have room for a macinfo type byte? */
15356 if (mac_ptr
>= mac_end
)
15358 dwarf2_macros_too_long_complaint (section
);
15362 /* We don't increment mac_ptr here, so this is just
15364 next_type
= read_1_byte (abfd
, mac_ptr
);
15365 if (next_type
!= 0)
15366 complaint (&symfile_complaints
,
15367 _("no terminating 0-type entry for "
15368 "macros in `.debug_macinfo' section"));
15375 case DW_MACRO_GNU_transparent_include
:
15380 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
15381 mac_ptr
+= offset_size
;
15383 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
15386 /* This has actually happened; see
15387 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
15388 complaint (&symfile_complaints
,
15389 _("recursive DW_MACRO_GNU_transparent_include in "
15390 ".debug_macro section"));
15396 dwarf_decode_macro_bytes (abfd
,
15397 section
->buffer
+ offset
,
15398 mac_end
, current_file
,
15400 section
, section_is_gnu
,
15401 offset_size
, objfile
, include_hash
);
15403 htab_remove_elt (include_hash
, mac_ptr
);
15408 case DW_MACINFO_vendor_ext
:
15409 if (!section_is_gnu
)
15411 unsigned int bytes_read
;
15414 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15415 mac_ptr
+= bytes_read
;
15416 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15417 mac_ptr
+= bytes_read
;
15419 /* We don't recognize any vendor extensions. */
15425 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
15426 mac_ptr
, abfd
, offset_size
,
15428 if (mac_ptr
== NULL
)
15432 } while (macinfo_type
!= 0);
15436 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
15437 char *comp_dir
, bfd
*abfd
,
15438 struct dwarf2_cu
*cu
,
15439 struct dwarf2_section_info
*section
,
15440 int section_is_gnu
)
15442 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15443 gdb_byte
*mac_ptr
, *mac_end
;
15444 struct macro_source_file
*current_file
= 0;
15445 enum dwarf_macro_record_type macinfo_type
;
15446 unsigned int offset_size
= cu
->header
.offset_size
;
15447 gdb_byte
*opcode_definitions
[256];
15448 struct cleanup
*cleanup
;
15449 htab_t include_hash
;
15452 dwarf2_read_section (objfile
, section
);
15453 if (section
->buffer
== NULL
)
15455 complaint (&symfile_complaints
, _("missing %s section"),
15456 section
->asection
->name
);
15460 /* First pass: Find the name of the base filename.
15461 This filename is needed in order to process all macros whose definition
15462 (or undefinition) comes from the command line. These macros are defined
15463 before the first DW_MACINFO_start_file entry, and yet still need to be
15464 associated to the base file.
15466 To determine the base file name, we scan the macro definitions until we
15467 reach the first DW_MACINFO_start_file entry. We then initialize
15468 CURRENT_FILE accordingly so that any macro definition found before the
15469 first DW_MACINFO_start_file can still be associated to the base file. */
15471 mac_ptr
= section
->buffer
+ offset
;
15472 mac_end
= section
->buffer
+ section
->size
;
15474 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
15475 &offset_size
, section_is_gnu
);
15476 if (mac_ptr
== NULL
)
15478 /* We already issued a complaint. */
15484 /* Do we at least have room for a macinfo type byte? */
15485 if (mac_ptr
>= mac_end
)
15487 /* Complaint is printed during the second pass as GDB will probably
15488 stop the first pass earlier upon finding
15489 DW_MACINFO_start_file. */
15493 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
15496 /* Note that we rely on the fact that the corresponding GNU and
15497 DWARF constants are the same. */
15498 switch (macinfo_type
)
15500 /* A zero macinfo type indicates the end of the macro
15505 case DW_MACRO_GNU_define
:
15506 case DW_MACRO_GNU_undef
:
15507 /* Only skip the data by MAC_PTR. */
15509 unsigned int bytes_read
;
15511 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15512 mac_ptr
+= bytes_read
;
15513 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15514 mac_ptr
+= bytes_read
;
15518 case DW_MACRO_GNU_start_file
:
15520 unsigned int bytes_read
;
15523 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15524 mac_ptr
+= bytes_read
;
15525 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15526 mac_ptr
+= bytes_read
;
15528 current_file
= macro_start_file (file
, line
, current_file
,
15529 comp_dir
, lh
, objfile
);
15533 case DW_MACRO_GNU_end_file
:
15534 /* No data to skip by MAC_PTR. */
15537 case DW_MACRO_GNU_define_indirect
:
15538 case DW_MACRO_GNU_undef_indirect
:
15540 unsigned int bytes_read
;
15542 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15543 mac_ptr
+= bytes_read
;
15544 mac_ptr
+= offset_size
;
15548 case DW_MACRO_GNU_transparent_include
:
15549 /* Note that, according to the spec, a transparent include
15550 chain cannot call DW_MACRO_GNU_start_file. So, we can just
15551 skip this opcode. */
15552 mac_ptr
+= offset_size
;
15555 case DW_MACINFO_vendor_ext
:
15556 /* Only skip the data by MAC_PTR. */
15557 if (!section_is_gnu
)
15559 unsigned int bytes_read
;
15561 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15562 mac_ptr
+= bytes_read
;
15563 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15564 mac_ptr
+= bytes_read
;
15569 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
15570 mac_ptr
, abfd
, offset_size
,
15572 if (mac_ptr
== NULL
)
15576 } while (macinfo_type
!= 0 && current_file
== NULL
);
15578 /* Second pass: Process all entries.
15580 Use the AT_COMMAND_LINE flag to determine whether we are still processing
15581 command-line macro definitions/undefinitions. This flag is unset when we
15582 reach the first DW_MACINFO_start_file entry. */
15584 include_hash
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
15585 NULL
, xcalloc
, xfree
);
15586 cleanup
= make_cleanup_htab_delete (include_hash
);
15587 mac_ptr
= section
->buffer
+ offset
;
15588 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
15590 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
15591 current_file
, lh
, comp_dir
, section
, section_is_gnu
,
15592 offset_size
, objfile
, include_hash
);
15593 do_cleanups (cleanup
);
15596 /* Check if the attribute's form is a DW_FORM_block*
15597 if so return true else false. */
15599 attr_form_is_block (struct attribute
*attr
)
15601 return (attr
== NULL
? 0 :
15602 attr
->form
== DW_FORM_block1
15603 || attr
->form
== DW_FORM_block2
15604 || attr
->form
== DW_FORM_block4
15605 || attr
->form
== DW_FORM_block
15606 || attr
->form
== DW_FORM_exprloc
);
15609 /* Return non-zero if ATTR's value is a section offset --- classes
15610 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
15611 You may use DW_UNSND (attr) to retrieve such offsets.
15613 Section 7.5.4, "Attribute Encodings", explains that no attribute
15614 may have a value that belongs to more than one of these classes; it
15615 would be ambiguous if we did, because we use the same forms for all
15618 attr_form_is_section_offset (struct attribute
*attr
)
15620 return (attr
->form
== DW_FORM_data4
15621 || attr
->form
== DW_FORM_data8
15622 || attr
->form
== DW_FORM_sec_offset
);
15626 /* Return non-zero if ATTR's value falls in the 'constant' class, or
15627 zero otherwise. When this function returns true, you can apply
15628 dwarf2_get_attr_constant_value to it.
15630 However, note that for some attributes you must check
15631 attr_form_is_section_offset before using this test. DW_FORM_data4
15632 and DW_FORM_data8 are members of both the constant class, and of
15633 the classes that contain offsets into other debug sections
15634 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
15635 that, if an attribute's can be either a constant or one of the
15636 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
15637 taken as section offsets, not constants. */
15639 attr_form_is_constant (struct attribute
*attr
)
15641 switch (attr
->form
)
15643 case DW_FORM_sdata
:
15644 case DW_FORM_udata
:
15645 case DW_FORM_data1
:
15646 case DW_FORM_data2
:
15647 case DW_FORM_data4
:
15648 case DW_FORM_data8
:
15655 /* A helper function that fills in a dwarf2_loclist_baton. */
15658 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
15659 struct dwarf2_loclist_baton
*baton
,
15660 struct attribute
*attr
)
15662 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
15663 &dwarf2_per_objfile
->loc
);
15665 baton
->per_cu
= cu
->per_cu
;
15666 gdb_assert (baton
->per_cu
);
15667 /* We don't know how long the location list is, but make sure we
15668 don't run off the edge of the section. */
15669 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
15670 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
15671 baton
->base_address
= cu
->base_address
;
15675 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
15676 struct dwarf2_cu
*cu
)
15678 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15680 if (attr_form_is_section_offset (attr
)
15681 /* ".debug_loc" may not exist at all, or the offset may be outside
15682 the section. If so, fall through to the complaint in the
15684 && DW_UNSND (attr
) < dwarf2_section_size (objfile
,
15685 &dwarf2_per_objfile
->loc
))
15687 struct dwarf2_loclist_baton
*baton
;
15689 baton
= obstack_alloc (&objfile
->objfile_obstack
,
15690 sizeof (struct dwarf2_loclist_baton
));
15692 fill_in_loclist_baton (cu
, baton
, attr
);
15694 if (cu
->base_known
== 0)
15695 complaint (&symfile_complaints
,
15696 _("Location list used without "
15697 "specifying the CU base address."));
15699 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
15700 SYMBOL_LOCATION_BATON (sym
) = baton
;
15704 struct dwarf2_locexpr_baton
*baton
;
15706 baton
= obstack_alloc (&objfile
->objfile_obstack
,
15707 sizeof (struct dwarf2_locexpr_baton
));
15708 baton
->per_cu
= cu
->per_cu
;
15709 gdb_assert (baton
->per_cu
);
15711 if (attr_form_is_block (attr
))
15713 /* Note that we're just copying the block's data pointer
15714 here, not the actual data. We're still pointing into the
15715 info_buffer for SYM's objfile; right now we never release
15716 that buffer, but when we do clean up properly this may
15718 baton
->size
= DW_BLOCK (attr
)->size
;
15719 baton
->data
= DW_BLOCK (attr
)->data
;
15723 dwarf2_invalid_attrib_class_complaint ("location description",
15724 SYMBOL_NATURAL_NAME (sym
));
15728 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
15729 SYMBOL_LOCATION_BATON (sym
) = baton
;
15733 /* Return the OBJFILE associated with the compilation unit CU. If CU
15734 came from a separate debuginfo file, then the master objfile is
15738 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
15740 struct objfile
*objfile
= per_cu
->objfile
;
15742 /* Return the master objfile, so that we can report and look up the
15743 correct file containing this variable. */
15744 if (objfile
->separate_debug_objfile_backlink
)
15745 objfile
= objfile
->separate_debug_objfile_backlink
;
15750 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
15751 (CU_HEADERP is unused in such case) or prepare a temporary copy at
15752 CU_HEADERP first. */
15754 static const struct comp_unit_head
*
15755 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
15756 struct dwarf2_per_cu_data
*per_cu
)
15758 struct objfile
*objfile
;
15759 struct dwarf2_per_objfile
*per_objfile
;
15760 gdb_byte
*info_ptr
;
15763 return &per_cu
->cu
->header
;
15765 objfile
= per_cu
->objfile
;
15766 per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
15767 info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
15769 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
15770 read_comp_unit_head (cu_headerp
, info_ptr
, objfile
->obfd
);
15775 /* Return the address size given in the compilation unit header for CU. */
15778 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
15780 struct comp_unit_head cu_header_local
;
15781 const struct comp_unit_head
*cu_headerp
;
15783 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
15785 return cu_headerp
->addr_size
;
15788 /* Return the offset size given in the compilation unit header for CU. */
15791 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
15793 struct comp_unit_head cu_header_local
;
15794 const struct comp_unit_head
*cu_headerp
;
15796 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
15798 return cu_headerp
->offset_size
;
15801 /* See its dwarf2loc.h declaration. */
15804 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
15806 struct comp_unit_head cu_header_local
;
15807 const struct comp_unit_head
*cu_headerp
;
15809 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
15811 if (cu_headerp
->version
== 2)
15812 return cu_headerp
->addr_size
;
15814 return cu_headerp
->offset_size
;
15817 /* Return the text offset of the CU. The returned offset comes from
15818 this CU's objfile. If this objfile came from a separate debuginfo
15819 file, then the offset may be different from the corresponding
15820 offset in the parent objfile. */
15823 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
15825 struct objfile
*objfile
= per_cu
->objfile
;
15827 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15830 /* Locate the .debug_info compilation unit from CU's objfile which contains
15831 the DIE at OFFSET. Raises an error on failure. */
15833 static struct dwarf2_per_cu_data
*
15834 dwarf2_find_containing_comp_unit (unsigned int offset
,
15835 struct objfile
*objfile
)
15837 struct dwarf2_per_cu_data
*this_cu
;
15841 high
= dwarf2_per_objfile
->n_comp_units
- 1;
15844 int mid
= low
+ (high
- low
) / 2;
15846 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
15851 gdb_assert (low
== high
);
15852 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
15855 error (_("Dwarf Error: could not find partial DIE containing "
15856 "offset 0x%lx [in module %s]"),
15857 (long) offset
, bfd_get_filename (objfile
->obfd
));
15859 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
15860 return dwarf2_per_objfile
->all_comp_units
[low
-1];
15864 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
15865 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
15866 && offset
>= this_cu
->offset
+ this_cu
->length
)
15867 error (_("invalid dwarf2 offset %u"), offset
);
15868 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
15873 /* Initialize dwarf2_cu CU, owned by PER_CU. */
15876 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
15878 memset (cu
, 0, sizeof (*cu
));
15880 cu
->per_cu
= per_cu
;
15881 cu
->objfile
= per_cu
->objfile
;
15882 obstack_init (&cu
->comp_unit_obstack
);
15885 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
15888 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
)
15890 struct attribute
*attr
;
15892 /* Set the language we're debugging. */
15893 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
15895 set_cu_language (DW_UNSND (attr
), cu
);
15898 cu
->language
= language_minimal
;
15899 cu
->language_defn
= language_def (cu
->language
);
15903 /* Release one cached compilation unit, CU. We unlink it from the tree
15904 of compilation units, but we don't remove it from the read_in_chain;
15905 the caller is responsible for that.
15906 NOTE: DATA is a void * because this function is also used as a
15907 cleanup routine. */
15910 free_heap_comp_unit (void *data
)
15912 struct dwarf2_cu
*cu
= data
;
15914 gdb_assert (cu
->per_cu
!= NULL
);
15915 cu
->per_cu
->cu
= NULL
;
15918 obstack_free (&cu
->comp_unit_obstack
, NULL
);
15923 /* This cleanup function is passed the address of a dwarf2_cu on the stack
15924 when we're finished with it. We can't free the pointer itself, but be
15925 sure to unlink it from the cache. Also release any associated storage
15926 and perform cache maintenance.
15928 Only used during partial symbol parsing. */
15931 free_stack_comp_unit (void *data
)
15933 struct dwarf2_cu
*cu
= data
;
15935 gdb_assert (cu
->per_cu
!= NULL
);
15936 cu
->per_cu
->cu
= NULL
;
15939 obstack_free (&cu
->comp_unit_obstack
, NULL
);
15940 cu
->partial_dies
= NULL
;
15942 /* The previous code only did this if per_cu != NULL.
15943 But that would always succeed, so now we just unconditionally do
15944 the aging. This seems like the wrong place to do such aging,
15945 but cleaning that up is left for later. */
15946 age_cached_comp_units ();
15949 /* Free all cached compilation units. */
15952 free_cached_comp_units (void *data
)
15954 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15956 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15957 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15958 while (per_cu
!= NULL
)
15960 struct dwarf2_per_cu_data
*next_cu
;
15962 next_cu
= per_cu
->cu
->read_in_chain
;
15964 free_heap_comp_unit (per_cu
->cu
);
15965 *last_chain
= next_cu
;
15971 /* Increase the age counter on each cached compilation unit, and free
15972 any that are too old. */
15975 age_cached_comp_units (void)
15977 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15979 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
15980 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15981 while (per_cu
!= NULL
)
15983 per_cu
->cu
->last_used
++;
15984 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
15985 dwarf2_mark (per_cu
->cu
);
15986 per_cu
= per_cu
->cu
->read_in_chain
;
15989 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15990 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15991 while (per_cu
!= NULL
)
15993 struct dwarf2_per_cu_data
*next_cu
;
15995 next_cu
= per_cu
->cu
->read_in_chain
;
15997 if (!per_cu
->cu
->mark
)
15999 free_heap_comp_unit (per_cu
->cu
);
16000 *last_chain
= next_cu
;
16003 last_chain
= &per_cu
->cu
->read_in_chain
;
16009 /* Remove a single compilation unit from the cache. */
16012 free_one_cached_comp_unit (void *target_cu
)
16014 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
16016 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16017 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
16018 while (per_cu
!= NULL
)
16020 struct dwarf2_per_cu_data
*next_cu
;
16022 next_cu
= per_cu
->cu
->read_in_chain
;
16024 if (per_cu
->cu
== target_cu
)
16026 free_heap_comp_unit (per_cu
->cu
);
16027 *last_chain
= next_cu
;
16031 last_chain
= &per_cu
->cu
->read_in_chain
;
16037 /* Release all extra memory associated with OBJFILE. */
16040 dwarf2_free_objfile (struct objfile
*objfile
)
16042 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
16044 if (dwarf2_per_objfile
== NULL
)
16047 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
16048 free_cached_comp_units (NULL
);
16050 if (dwarf2_per_objfile
->quick_file_names_table
)
16051 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
16053 /* Everything else should be on the objfile obstack. */
16056 /* A pair of DIE offset and GDB type pointer. We store these
16057 in a hash table separate from the DIEs, and preserve them
16058 when the DIEs are flushed out of cache. */
16060 struct dwarf2_offset_and_type
16062 unsigned int offset
;
16066 /* Hash function for a dwarf2_offset_and_type. */
16069 offset_and_type_hash (const void *item
)
16071 const struct dwarf2_offset_and_type
*ofs
= item
;
16073 return ofs
->offset
;
16076 /* Equality function for a dwarf2_offset_and_type. */
16079 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
16081 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
16082 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
16084 return ofs_lhs
->offset
== ofs_rhs
->offset
;
16087 /* Set the type associated with DIE to TYPE. Save it in CU's hash
16088 table if necessary. For convenience, return TYPE.
16090 The DIEs reading must have careful ordering to:
16091 * Not cause infite loops trying to read in DIEs as a prerequisite for
16092 reading current DIE.
16093 * Not trying to dereference contents of still incompletely read in types
16094 while reading in other DIEs.
16095 * Enable referencing still incompletely read in types just by a pointer to
16096 the type without accessing its fields.
16098 Therefore caller should follow these rules:
16099 * Try to fetch any prerequisite types we may need to build this DIE type
16100 before building the type and calling set_die_type.
16101 * After building type call set_die_type for current DIE as soon as
16102 possible before fetching more types to complete the current type.
16103 * Make the type as complete as possible before fetching more types. */
16105 static struct type
*
16106 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
16108 struct dwarf2_offset_and_type
**slot
, ofs
;
16109 struct objfile
*objfile
= cu
->objfile
;
16110 htab_t
*type_hash_ptr
;
16112 /* For Ada types, make sure that the gnat-specific data is always
16113 initialized (if not already set). There are a few types where
16114 we should not be doing so, because the type-specific area is
16115 already used to hold some other piece of info (eg: TYPE_CODE_FLT
16116 where the type-specific area is used to store the floatformat).
16117 But this is not a problem, because the gnat-specific information
16118 is actually not needed for these types. */
16119 if (need_gnat_info (cu
)
16120 && TYPE_CODE (type
) != TYPE_CODE_FUNC
16121 && TYPE_CODE (type
) != TYPE_CODE_FLT
16122 && !HAVE_GNAT_AUX_INFO (type
))
16123 INIT_GNAT_SPECIFIC (type
);
16125 if (cu
->per_cu
->debug_types_section
)
16126 type_hash_ptr
= &dwarf2_per_objfile
->debug_types_type_hash
;
16128 type_hash_ptr
= &dwarf2_per_objfile
->debug_info_type_hash
;
16130 if (*type_hash_ptr
== NULL
)
16133 = htab_create_alloc_ex (127,
16134 offset_and_type_hash
,
16135 offset_and_type_eq
,
16137 &objfile
->objfile_obstack
,
16138 hashtab_obstack_allocate
,
16139 dummy_obstack_deallocate
);
16142 ofs
.offset
= die
->offset
;
16144 slot
= (struct dwarf2_offset_and_type
**)
16145 htab_find_slot_with_hash (*type_hash_ptr
, &ofs
, ofs
.offset
, INSERT
);
16147 complaint (&symfile_complaints
,
16148 _("A problem internal to GDB: DIE 0x%x has type already set"),
16150 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
16155 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
16156 table, or return NULL if the die does not have a saved type. */
16158 static struct type
*
16159 get_die_type_at_offset (unsigned int offset
,
16160 struct dwarf2_per_cu_data
*per_cu
)
16162 struct dwarf2_offset_and_type
*slot
, ofs
;
16165 if (per_cu
->debug_types_section
)
16166 type_hash
= dwarf2_per_objfile
->debug_types_type_hash
;
16168 type_hash
= dwarf2_per_objfile
->debug_info_type_hash
;
16169 if (type_hash
== NULL
)
16172 ofs
.offset
= offset
;
16173 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
16180 /* Look up the type for DIE in the appropriate type_hash table,
16181 or return NULL if DIE does not have a saved type. */
16183 static struct type
*
16184 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16186 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
16189 /* Add a dependence relationship from CU to REF_PER_CU. */
16192 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
16193 struct dwarf2_per_cu_data
*ref_per_cu
)
16197 if (cu
->dependencies
== NULL
)
16199 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
16200 NULL
, &cu
->comp_unit_obstack
,
16201 hashtab_obstack_allocate
,
16202 dummy_obstack_deallocate
);
16204 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
16206 *slot
= ref_per_cu
;
16209 /* Subroutine of dwarf2_mark to pass to htab_traverse.
16210 Set the mark field in every compilation unit in the
16211 cache that we must keep because we are keeping CU. */
16214 dwarf2_mark_helper (void **slot
, void *data
)
16216 struct dwarf2_per_cu_data
*per_cu
;
16218 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
16220 /* cu->dependencies references may not yet have been ever read if QUIT aborts
16221 reading of the chain. As such dependencies remain valid it is not much
16222 useful to track and undo them during QUIT cleanups. */
16223 if (per_cu
->cu
== NULL
)
16226 if (per_cu
->cu
->mark
)
16228 per_cu
->cu
->mark
= 1;
16230 if (per_cu
->cu
->dependencies
!= NULL
)
16231 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
16236 /* Set the mark field in CU and in every other compilation unit in the
16237 cache that we must keep because we are keeping CU. */
16240 dwarf2_mark (struct dwarf2_cu
*cu
)
16245 if (cu
->dependencies
!= NULL
)
16246 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
16250 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
16254 per_cu
->cu
->mark
= 0;
16255 per_cu
= per_cu
->cu
->read_in_chain
;
16259 /* Trivial hash function for partial_die_info: the hash value of a DIE
16260 is its offset in .debug_info for this objfile. */
16263 partial_die_hash (const void *item
)
16265 const struct partial_die_info
*part_die
= item
;
16267 return part_die
->offset
;
16270 /* Trivial comparison function for partial_die_info structures: two DIEs
16271 are equal if they have the same offset. */
16274 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
16276 const struct partial_die_info
*part_die_lhs
= item_lhs
;
16277 const struct partial_die_info
*part_die_rhs
= item_rhs
;
16279 return part_die_lhs
->offset
== part_die_rhs
->offset
;
16282 static struct cmd_list_element
*set_dwarf2_cmdlist
;
16283 static struct cmd_list_element
*show_dwarf2_cmdlist
;
16286 set_dwarf2_cmd (char *args
, int from_tty
)
16288 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
16292 show_dwarf2_cmd (char *args
, int from_tty
)
16294 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
16297 /* If section described by INFO was mmapped, munmap it now. */
16300 munmap_section_buffer (struct dwarf2_section_info
*info
)
16302 if (info
->map_addr
!= NULL
)
16307 res
= munmap (info
->map_addr
, info
->map_len
);
16308 gdb_assert (res
== 0);
16310 /* Without HAVE_MMAP, we should never be here to begin with. */
16311 gdb_assert_not_reached ("no mmap support");
16316 /* munmap debug sections for OBJFILE, if necessary. */
16319 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
16321 struct dwarf2_per_objfile
*data
= d
;
16323 struct dwarf2_section_info
*section
;
16325 /* This is sorted according to the order they're defined in to make it easier
16326 to keep in sync. */
16327 munmap_section_buffer (&data
->info
);
16328 munmap_section_buffer (&data
->abbrev
);
16329 munmap_section_buffer (&data
->line
);
16330 munmap_section_buffer (&data
->loc
);
16331 munmap_section_buffer (&data
->macinfo
);
16332 munmap_section_buffer (&data
->macro
);
16333 munmap_section_buffer (&data
->str
);
16334 munmap_section_buffer (&data
->ranges
);
16335 munmap_section_buffer (&data
->frame
);
16336 munmap_section_buffer (&data
->eh_frame
);
16337 munmap_section_buffer (&data
->gdb_index
);
16340 VEC_iterate (dwarf2_section_info_def
, data
->types
, ix
, section
);
16342 munmap_section_buffer (section
);
16344 VEC_free (dwarf2_section_info_def
, data
->types
);
16348 /* The "save gdb-index" command. */
16350 /* The contents of the hash table we create when building the string
16352 struct strtab_entry
16354 offset_type offset
;
16358 /* Hash function for a strtab_entry.
16360 Function is used only during write_hash_table so no index format backward
16361 compatibility is needed. */
16364 hash_strtab_entry (const void *e
)
16366 const struct strtab_entry
*entry
= e
;
16367 return mapped_index_string_hash (INT_MAX
, entry
->str
);
16370 /* Equality function for a strtab_entry. */
16373 eq_strtab_entry (const void *a
, const void *b
)
16375 const struct strtab_entry
*ea
= a
;
16376 const struct strtab_entry
*eb
= b
;
16377 return !strcmp (ea
->str
, eb
->str
);
16380 /* Create a strtab_entry hash table. */
16383 create_strtab (void)
16385 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
16386 xfree
, xcalloc
, xfree
);
16389 /* Add a string to the constant pool. Return the string's offset in
16393 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
16396 struct strtab_entry entry
;
16397 struct strtab_entry
*result
;
16400 slot
= htab_find_slot (table
, &entry
, INSERT
);
16405 result
= XNEW (struct strtab_entry
);
16406 result
->offset
= obstack_object_size (cpool
);
16408 obstack_grow_str0 (cpool
, str
);
16411 return result
->offset
;
16414 /* An entry in the symbol table. */
16415 struct symtab_index_entry
16417 /* The name of the symbol. */
16419 /* The offset of the name in the constant pool. */
16420 offset_type index_offset
;
16421 /* A sorted vector of the indices of all the CUs that hold an object
16423 VEC (offset_type
) *cu_indices
;
16426 /* The symbol table. This is a power-of-2-sized hash table. */
16427 struct mapped_symtab
16429 offset_type n_elements
;
16431 struct symtab_index_entry
**data
;
16434 /* Hash function for a symtab_index_entry. */
16437 hash_symtab_entry (const void *e
)
16439 const struct symtab_index_entry
*entry
= e
;
16440 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
16441 sizeof (offset_type
) * VEC_length (offset_type
,
16442 entry
->cu_indices
),
16446 /* Equality function for a symtab_index_entry. */
16449 eq_symtab_entry (const void *a
, const void *b
)
16451 const struct symtab_index_entry
*ea
= a
;
16452 const struct symtab_index_entry
*eb
= b
;
16453 int len
= VEC_length (offset_type
, ea
->cu_indices
);
16454 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
16456 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
16457 VEC_address (offset_type
, eb
->cu_indices
),
16458 sizeof (offset_type
) * len
);
16461 /* Destroy a symtab_index_entry. */
16464 delete_symtab_entry (void *p
)
16466 struct symtab_index_entry
*entry
= p
;
16467 VEC_free (offset_type
, entry
->cu_indices
);
16471 /* Create a hash table holding symtab_index_entry objects. */
16474 create_symbol_hash_table (void)
16476 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
16477 delete_symtab_entry
, xcalloc
, xfree
);
16480 /* Create a new mapped symtab object. */
16482 static struct mapped_symtab
*
16483 create_mapped_symtab (void)
16485 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
16486 symtab
->n_elements
= 0;
16487 symtab
->size
= 1024;
16488 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
16492 /* Destroy a mapped_symtab. */
16495 cleanup_mapped_symtab (void *p
)
16497 struct mapped_symtab
*symtab
= p
;
16498 /* The contents of the array are freed when the other hash table is
16500 xfree (symtab
->data
);
16504 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
16507 Function is used only during write_hash_table so no index format backward
16508 compatibility is needed. */
16510 static struct symtab_index_entry
**
16511 find_slot (struct mapped_symtab
*symtab
, const char *name
)
16513 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
16515 index
= hash
& (symtab
->size
- 1);
16516 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
16520 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
16521 return &symtab
->data
[index
];
16522 index
= (index
+ step
) & (symtab
->size
- 1);
16526 /* Expand SYMTAB's hash table. */
16529 hash_expand (struct mapped_symtab
*symtab
)
16531 offset_type old_size
= symtab
->size
;
16533 struct symtab_index_entry
**old_entries
= symtab
->data
;
16536 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
16538 for (i
= 0; i
< old_size
; ++i
)
16540 if (old_entries
[i
])
16542 struct symtab_index_entry
**slot
= find_slot (symtab
,
16543 old_entries
[i
]->name
);
16544 *slot
= old_entries
[i
];
16548 xfree (old_entries
);
16551 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
16552 is the index of the CU in which the symbol appears. */
16555 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
16556 offset_type cu_index
)
16558 struct symtab_index_entry
**slot
;
16560 ++symtab
->n_elements
;
16561 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
16562 hash_expand (symtab
);
16564 slot
= find_slot (symtab
, name
);
16567 *slot
= XNEW (struct symtab_index_entry
);
16568 (*slot
)->name
= name
;
16569 (*slot
)->cu_indices
= NULL
;
16571 /* Don't push an index twice. Due to how we add entries we only
16572 have to check the last one. */
16573 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
16574 || VEC_last (offset_type
, (*slot
)->cu_indices
) != cu_index
)
16575 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
16578 /* Add a vector of indices to the constant pool. */
16581 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
16582 struct symtab_index_entry
*entry
)
16586 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
16589 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
16590 offset_type val
= MAYBE_SWAP (len
);
16595 entry
->index_offset
= obstack_object_size (cpool
);
16597 obstack_grow (cpool
, &val
, sizeof (val
));
16599 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
16602 val
= MAYBE_SWAP (iter
);
16603 obstack_grow (cpool
, &val
, sizeof (val
));
16608 struct symtab_index_entry
*old_entry
= *slot
;
16609 entry
->index_offset
= old_entry
->index_offset
;
16612 return entry
->index_offset
;
16615 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
16616 constant pool entries going into the obstack CPOOL. */
16619 write_hash_table (struct mapped_symtab
*symtab
,
16620 struct obstack
*output
, struct obstack
*cpool
)
16623 htab_t symbol_hash_table
;
16626 symbol_hash_table
= create_symbol_hash_table ();
16627 str_table
= create_strtab ();
16629 /* We add all the index vectors to the constant pool first, to
16630 ensure alignment is ok. */
16631 for (i
= 0; i
< symtab
->size
; ++i
)
16633 if (symtab
->data
[i
])
16634 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
16637 /* Now write out the hash table. */
16638 for (i
= 0; i
< symtab
->size
; ++i
)
16640 offset_type str_off
, vec_off
;
16642 if (symtab
->data
[i
])
16644 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
16645 vec_off
= symtab
->data
[i
]->index_offset
;
16649 /* While 0 is a valid constant pool index, it is not valid
16650 to have 0 for both offsets. */
16655 str_off
= MAYBE_SWAP (str_off
);
16656 vec_off
= MAYBE_SWAP (vec_off
);
16658 obstack_grow (output
, &str_off
, sizeof (str_off
));
16659 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
16662 htab_delete (str_table
);
16663 htab_delete (symbol_hash_table
);
16666 /* Struct to map psymtab to CU index in the index file. */
16667 struct psymtab_cu_index_map
16669 struct partial_symtab
*psymtab
;
16670 unsigned int cu_index
;
16674 hash_psymtab_cu_index (const void *item
)
16676 const struct psymtab_cu_index_map
*map
= item
;
16678 return htab_hash_pointer (map
->psymtab
);
16682 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
16684 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
16685 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
16687 return lhs
->psymtab
== rhs
->psymtab
;
16690 /* Helper struct for building the address table. */
16691 struct addrmap_index_data
16693 struct objfile
*objfile
;
16694 struct obstack
*addr_obstack
;
16695 htab_t cu_index_htab
;
16697 /* Non-zero if the previous_* fields are valid.
16698 We can't write an entry until we see the next entry (since it is only then
16699 that we know the end of the entry). */
16700 int previous_valid
;
16701 /* Index of the CU in the table of all CUs in the index file. */
16702 unsigned int previous_cu_index
;
16703 /* Start address of the CU. */
16704 CORE_ADDR previous_cu_start
;
16707 /* Write an address entry to OBSTACK. */
16710 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
16711 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
16713 offset_type cu_index_to_write
;
16715 CORE_ADDR baseaddr
;
16717 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
16719 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
16720 obstack_grow (obstack
, addr
, 8);
16721 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
16722 obstack_grow (obstack
, addr
, 8);
16723 cu_index_to_write
= MAYBE_SWAP (cu_index
);
16724 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
16727 /* Worker function for traversing an addrmap to build the address table. */
16730 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
16732 struct addrmap_index_data
*data
= datap
;
16733 struct partial_symtab
*pst
= obj
;
16734 offset_type cu_index
;
16737 if (data
->previous_valid
)
16738 add_address_entry (data
->objfile
, data
->addr_obstack
,
16739 data
->previous_cu_start
, start_addr
,
16740 data
->previous_cu_index
);
16742 data
->previous_cu_start
= start_addr
;
16745 struct psymtab_cu_index_map find_map
, *map
;
16746 find_map
.psymtab
= pst
;
16747 map
= htab_find (data
->cu_index_htab
, &find_map
);
16748 gdb_assert (map
!= NULL
);
16749 data
->previous_cu_index
= map
->cu_index
;
16750 data
->previous_valid
= 1;
16753 data
->previous_valid
= 0;
16758 /* Write OBJFILE's address map to OBSTACK.
16759 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
16760 in the index file. */
16763 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
16764 htab_t cu_index_htab
)
16766 struct addrmap_index_data addrmap_index_data
;
16768 /* When writing the address table, we have to cope with the fact that
16769 the addrmap iterator only provides the start of a region; we have to
16770 wait until the next invocation to get the start of the next region. */
16772 addrmap_index_data
.objfile
= objfile
;
16773 addrmap_index_data
.addr_obstack
= obstack
;
16774 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
16775 addrmap_index_data
.previous_valid
= 0;
16777 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
16778 &addrmap_index_data
);
16780 /* It's highly unlikely the last entry (end address = 0xff...ff)
16781 is valid, but we should still handle it.
16782 The end address is recorded as the start of the next region, but that
16783 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
16785 if (addrmap_index_data
.previous_valid
)
16786 add_address_entry (objfile
, obstack
,
16787 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
16788 addrmap_index_data
.previous_cu_index
);
16791 /* Add a list of partial symbols to SYMTAB. */
16794 write_psymbols (struct mapped_symtab
*symtab
,
16796 struct partial_symbol
**psymp
,
16798 offset_type cu_index
,
16801 for (; count
-- > 0; ++psymp
)
16803 void **slot
, *lookup
;
16805 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
16806 error (_("Ada is not currently supported by the index"));
16808 /* We only want to add a given psymbol once. However, we also
16809 want to account for whether it is global or static. So, we
16810 may add it twice, using slightly different values. */
16813 uintptr_t val
= 1 | (uintptr_t) *psymp
;
16815 lookup
= (void *) val
;
16820 /* Only add a given psymbol once. */
16821 slot
= htab_find_slot (psyms_seen
, lookup
, INSERT
);
16825 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (*psymp
), cu_index
);
16830 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
16831 exception if there is an error. */
16834 write_obstack (FILE *file
, struct obstack
*obstack
)
16836 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
16838 != obstack_object_size (obstack
))
16839 error (_("couldn't data write to file"));
16842 /* Unlink a file if the argument is not NULL. */
16845 unlink_if_set (void *p
)
16847 char **filename
= p
;
16849 unlink (*filename
);
16852 /* A helper struct used when iterating over debug_types. */
16853 struct signatured_type_index_data
16855 struct objfile
*objfile
;
16856 struct mapped_symtab
*symtab
;
16857 struct obstack
*types_list
;
16862 /* A helper function that writes a single signatured_type to an
16866 write_one_signatured_type (void **slot
, void *d
)
16868 struct signatured_type_index_data
*info
= d
;
16869 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
16870 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
16871 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
16874 write_psymbols (info
->symtab
,
16876 info
->objfile
->global_psymbols
.list
16877 + psymtab
->globals_offset
,
16878 psymtab
->n_global_syms
, info
->cu_index
,
16880 write_psymbols (info
->symtab
,
16882 info
->objfile
->static_psymbols
.list
16883 + psymtab
->statics_offset
,
16884 psymtab
->n_static_syms
, info
->cu_index
,
16887 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->per_cu
.offset
);
16888 obstack_grow (info
->types_list
, val
, 8);
16889 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->type_offset
);
16890 obstack_grow (info
->types_list
, val
, 8);
16891 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
16892 obstack_grow (info
->types_list
, val
, 8);
16899 /* Create an index file for OBJFILE in the directory DIR. */
16902 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
16904 struct cleanup
*cleanup
;
16905 char *filename
, *cleanup_filename
;
16906 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
16907 struct obstack cu_list
, types_cu_list
;
16910 struct mapped_symtab
*symtab
;
16911 offset_type val
, size_of_contents
, total_len
;
16915 htab_t cu_index_htab
;
16916 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
16918 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
16921 if (dwarf2_per_objfile
->using_index
)
16922 error (_("Cannot use an index to create the index"));
16924 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
16925 error (_("Cannot make an index when the file has multiple .debug_types sections"));
16927 if (stat (objfile
->name
, &st
) < 0)
16928 perror_with_name (objfile
->name
);
16930 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
16931 INDEX_SUFFIX
, (char *) NULL
);
16932 cleanup
= make_cleanup (xfree
, filename
);
16934 out_file
= fopen (filename
, "wb");
16936 error (_("Can't open `%s' for writing"), filename
);
16938 cleanup_filename
= filename
;
16939 make_cleanup (unlink_if_set
, &cleanup_filename
);
16941 symtab
= create_mapped_symtab ();
16942 make_cleanup (cleanup_mapped_symtab
, symtab
);
16944 obstack_init (&addr_obstack
);
16945 make_cleanup_obstack_free (&addr_obstack
);
16947 obstack_init (&cu_list
);
16948 make_cleanup_obstack_free (&cu_list
);
16950 obstack_init (&types_cu_list
);
16951 make_cleanup_obstack_free (&types_cu_list
);
16953 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
16954 NULL
, xcalloc
, xfree
);
16955 make_cleanup_htab_delete (psyms_seen
);
16957 /* While we're scanning CU's create a table that maps a psymtab pointer
16958 (which is what addrmap records) to its index (which is what is recorded
16959 in the index file). This will later be needed to write the address
16961 cu_index_htab
= htab_create_alloc (100,
16962 hash_psymtab_cu_index
,
16963 eq_psymtab_cu_index
,
16964 NULL
, xcalloc
, xfree
);
16965 make_cleanup_htab_delete (cu_index_htab
);
16966 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
16967 xmalloc (sizeof (struct psymtab_cu_index_map
)
16968 * dwarf2_per_objfile
->n_comp_units
);
16969 make_cleanup (xfree
, psymtab_cu_index_map
);
16971 /* The CU list is already sorted, so we don't need to do additional
16972 work here. Also, the debug_types entries do not appear in
16973 all_comp_units, but only in their own hash table. */
16974 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
16976 struct dwarf2_per_cu_data
*per_cu
16977 = dwarf2_per_objfile
->all_comp_units
[i
];
16978 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
16980 struct psymtab_cu_index_map
*map
;
16983 write_psymbols (symtab
,
16985 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
16986 psymtab
->n_global_syms
, i
,
16988 write_psymbols (symtab
,
16990 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
16991 psymtab
->n_static_syms
, i
,
16994 map
= &psymtab_cu_index_map
[i
];
16995 map
->psymtab
= psymtab
;
16997 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
16998 gdb_assert (slot
!= NULL
);
16999 gdb_assert (*slot
== NULL
);
17002 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->offset
);
17003 obstack_grow (&cu_list
, val
, 8);
17004 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
17005 obstack_grow (&cu_list
, val
, 8);
17008 /* Dump the address map. */
17009 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
17011 /* Write out the .debug_type entries, if any. */
17012 if (dwarf2_per_objfile
->signatured_types
)
17014 struct signatured_type_index_data sig_data
;
17016 sig_data
.objfile
= objfile
;
17017 sig_data
.symtab
= symtab
;
17018 sig_data
.types_list
= &types_cu_list
;
17019 sig_data
.psyms_seen
= psyms_seen
;
17020 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
17021 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
17022 write_one_signatured_type
, &sig_data
);
17025 obstack_init (&constant_pool
);
17026 make_cleanup_obstack_free (&constant_pool
);
17027 obstack_init (&symtab_obstack
);
17028 make_cleanup_obstack_free (&symtab_obstack
);
17029 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
17031 obstack_init (&contents
);
17032 make_cleanup_obstack_free (&contents
);
17033 size_of_contents
= 6 * sizeof (offset_type
);
17034 total_len
= size_of_contents
;
17036 /* The version number. */
17037 val
= MAYBE_SWAP (5);
17038 obstack_grow (&contents
, &val
, sizeof (val
));
17040 /* The offset of the CU list from the start of the file. */
17041 val
= MAYBE_SWAP (total_len
);
17042 obstack_grow (&contents
, &val
, sizeof (val
));
17043 total_len
+= obstack_object_size (&cu_list
);
17045 /* The offset of the types CU list from the start of the file. */
17046 val
= MAYBE_SWAP (total_len
);
17047 obstack_grow (&contents
, &val
, sizeof (val
));
17048 total_len
+= obstack_object_size (&types_cu_list
);
17050 /* The offset of the address table from the start of the file. */
17051 val
= MAYBE_SWAP (total_len
);
17052 obstack_grow (&contents
, &val
, sizeof (val
));
17053 total_len
+= obstack_object_size (&addr_obstack
);
17055 /* The offset of the symbol table from the start of the file. */
17056 val
= MAYBE_SWAP (total_len
);
17057 obstack_grow (&contents
, &val
, sizeof (val
));
17058 total_len
+= obstack_object_size (&symtab_obstack
);
17060 /* The offset of the constant pool from the start of the file. */
17061 val
= MAYBE_SWAP (total_len
);
17062 obstack_grow (&contents
, &val
, sizeof (val
));
17063 total_len
+= obstack_object_size (&constant_pool
);
17065 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
17067 write_obstack (out_file
, &contents
);
17068 write_obstack (out_file
, &cu_list
);
17069 write_obstack (out_file
, &types_cu_list
);
17070 write_obstack (out_file
, &addr_obstack
);
17071 write_obstack (out_file
, &symtab_obstack
);
17072 write_obstack (out_file
, &constant_pool
);
17076 /* We want to keep the file, so we set cleanup_filename to NULL
17077 here. See unlink_if_set. */
17078 cleanup_filename
= NULL
;
17080 do_cleanups (cleanup
);
17083 /* Implementation of the `save gdb-index' command.
17085 Note that the file format used by this command is documented in the
17086 GDB manual. Any changes here must be documented there. */
17089 save_gdb_index_command (char *arg
, int from_tty
)
17091 struct objfile
*objfile
;
17094 error (_("usage: save gdb-index DIRECTORY"));
17096 ALL_OBJFILES (objfile
)
17100 /* If the objfile does not correspond to an actual file, skip it. */
17101 if (stat (objfile
->name
, &st
) < 0)
17104 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
17105 if (dwarf2_per_objfile
)
17107 volatile struct gdb_exception except
;
17109 TRY_CATCH (except
, RETURN_MASK_ERROR
)
17111 write_psymtabs_to_index (objfile
, arg
);
17113 if (except
.reason
< 0)
17114 exception_fprintf (gdb_stderr
, except
,
17115 _("Error while writing index for `%s': "),
17123 int dwarf2_always_disassemble
;
17126 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
17127 struct cmd_list_element
*c
, const char *value
)
17129 fprintf_filtered (file
,
17130 _("Whether to always disassemble "
17131 "DWARF expressions is %s.\n"),
17136 show_check_physname (struct ui_file
*file
, int from_tty
,
17137 struct cmd_list_element
*c
, const char *value
)
17139 fprintf_filtered (file
,
17140 _("Whether to check \"physname\" is %s.\n"),
17144 void _initialize_dwarf2_read (void);
17147 _initialize_dwarf2_read (void)
17149 struct cmd_list_element
*c
;
17151 dwarf2_objfile_data_key
17152 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
17154 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
17155 Set DWARF 2 specific variables.\n\
17156 Configure DWARF 2 variables such as the cache size"),
17157 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
17158 0/*allow-unknown*/, &maintenance_set_cmdlist
);
17160 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
17161 Show DWARF 2 specific variables\n\
17162 Show DWARF 2 variables such as the cache size"),
17163 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
17164 0/*allow-unknown*/, &maintenance_show_cmdlist
);
17166 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
17167 &dwarf2_max_cache_age
, _("\
17168 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
17169 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
17170 A higher limit means that cached compilation units will be stored\n\
17171 in memory longer, and more total memory will be used. Zero disables\n\
17172 caching, which can slow down startup."),
17174 show_dwarf2_max_cache_age
,
17175 &set_dwarf2_cmdlist
,
17176 &show_dwarf2_cmdlist
);
17178 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
17179 &dwarf2_always_disassemble
, _("\
17180 Set whether `info address' always disassembles DWARF expressions."), _("\
17181 Show whether `info address' always disassembles DWARF expressions."), _("\
17182 When enabled, DWARF expressions are always printed in an assembly-like\n\
17183 syntax. When disabled, expressions will be printed in a more\n\
17184 conversational style, when possible."),
17186 show_dwarf2_always_disassemble
,
17187 &set_dwarf2_cmdlist
,
17188 &show_dwarf2_cmdlist
);
17190 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
17191 Set debugging of the dwarf2 DIE reader."), _("\
17192 Show debugging of the dwarf2 DIE reader."), _("\
17193 When enabled (non-zero), DIEs are dumped after they are read in.\n\
17194 The value is the maximum depth to print."),
17197 &setdebuglist
, &showdebuglist
);
17199 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
17200 Set cross-checking of \"physname\" code against demangler."), _("\
17201 Show cross-checking of \"physname\" code against demangler."), _("\
17202 When enabled, GDB's internal \"physname\" code is checked against\n\
17204 NULL
, show_check_physname
,
17205 &setdebuglist
, &showdebuglist
);
17207 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
17209 Save a gdb-index file.\n\
17210 Usage: save gdb-index DIRECTORY"),
17212 set_cmd_completer (c
, filename_completer
);