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"
67 #include "gdb_string.h"
68 #include "gdb_assert.h"
69 #include <sys/types.h>
76 #define MAP_FAILED ((void *) -1)
80 typedef struct symbol
*symbolp
;
83 /* When non-zero, dump DIEs after they are read in. */
84 static int dwarf2_die_debug
= 0;
86 /* When non-zero, cross-check physname against demangler. */
87 static int check_physname
= 0;
89 /* When non-zero, do not reject deprecated .gdb_index sections. */
90 int use_deprecated_index_sections
= 0;
94 /* When set, the file that we're processing is known to have debugging
95 info for C++ namespaces. GCC 3.3.x did not produce this information,
96 but later versions do. */
98 static int processing_has_namespace_info
;
100 static const struct objfile_data
*dwarf2_objfile_data_key
;
102 struct dwarf2_section_info
107 /* Not NULL if the section was actually mmapped. */
109 /* Page aligned size of mmapped area. */
110 bfd_size_type map_len
;
111 /* True if we have tried to read this section. */
115 typedef struct dwarf2_section_info dwarf2_section_info_def
;
116 DEF_VEC_O (dwarf2_section_info_def
);
118 /* All offsets in the index are of this type. It must be
119 architecture-independent. */
120 typedef uint32_t offset_type
;
122 DEF_VEC_I (offset_type
);
124 /* A description of the mapped index. The file format is described in
125 a comment by the code that writes the index. */
128 /* Index data format version. */
131 /* The total length of the buffer. */
134 /* A pointer to the address table data. */
135 const gdb_byte
*address_table
;
137 /* Size of the address table data in bytes. */
138 offset_type address_table_size
;
140 /* The symbol table, implemented as a hash table. */
141 const offset_type
*symbol_table
;
143 /* Size in slots, each slot is 2 offset_types. */
144 offset_type symbol_table_slots
;
146 /* A pointer to the constant pool. */
147 const char *constant_pool
;
150 /* Collection of data recorded per objfile.
151 This hangs off of dwarf2_objfile_data_key. */
153 struct dwarf2_per_objfile
155 struct dwarf2_section_info info
;
156 struct dwarf2_section_info abbrev
;
157 struct dwarf2_section_info line
;
158 struct dwarf2_section_info loc
;
159 struct dwarf2_section_info macinfo
;
160 struct dwarf2_section_info macro
;
161 struct dwarf2_section_info str
;
162 struct dwarf2_section_info ranges
;
163 struct dwarf2_section_info frame
;
164 struct dwarf2_section_info eh_frame
;
165 struct dwarf2_section_info gdb_index
;
167 VEC (dwarf2_section_info_def
) *types
;
170 struct objfile
*objfile
;
172 /* Table of all the compilation units. This is used to locate
173 the target compilation unit of a particular reference. */
174 struct dwarf2_per_cu_data
**all_comp_units
;
176 /* The number of compilation units in ALL_COMP_UNITS. */
179 /* The number of .debug_types-related CUs. */
182 /* The .debug_types-related CUs (TUs). */
183 struct dwarf2_per_cu_data
**all_type_units
;
185 /* A chain of compilation units that are currently read in, so that
186 they can be freed later. */
187 struct dwarf2_per_cu_data
*read_in_chain
;
189 /* A table mapping .debug_types signatures to its signatured_type entry.
190 This is NULL if the .debug_types section hasn't been read in yet. */
191 htab_t signatured_types
;
193 /* A flag indicating wether this objfile has a section loaded at a
195 int has_section_at_zero
;
197 /* True if we are using the mapped index,
198 or we are faking it for OBJF_READNOW's sake. */
199 unsigned char using_index
;
201 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
202 struct mapped_index
*index_table
;
204 /* When using index_table, this keeps track of all quick_file_names entries.
205 TUs can share line table entries with CUs or other TUs, and there can be
206 a lot more TUs than unique line tables, so we maintain a separate table
207 of all line table entries to support the sharing. */
208 htab_t quick_file_names_table
;
210 /* Set during partial symbol reading, to prevent queueing of full
212 int reading_partial_symbols
;
214 /* Table mapping type .debug_info DIE offsets to types.
215 This is NULL if not allocated yet.
216 It (currently) makes sense to allocate debug_types_type_hash lazily.
217 To keep things simple we allocate both lazily. */
218 htab_t debug_info_type_hash
;
220 /* Table mapping type .debug_types DIE sect_offset to types.
221 This is NULL if not allocated yet. */
222 htab_t debug_types_type_hash
;
225 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
227 /* Default names of the debugging sections. */
229 /* Note that if the debugging section has been compressed, it might
230 have a name like .zdebug_info. */
232 static const struct dwarf2_debug_sections dwarf2_elf_names
=
234 { ".debug_info", ".zdebug_info" },
235 { ".debug_abbrev", ".zdebug_abbrev" },
236 { ".debug_line", ".zdebug_line" },
237 { ".debug_loc", ".zdebug_loc" },
238 { ".debug_macinfo", ".zdebug_macinfo" },
239 { ".debug_macro", ".zdebug_macro" },
240 { ".debug_str", ".zdebug_str" },
241 { ".debug_ranges", ".zdebug_ranges" },
242 { ".debug_types", ".zdebug_types" },
243 { ".debug_frame", ".zdebug_frame" },
244 { ".eh_frame", NULL
},
245 { ".gdb_index", ".zgdb_index" },
249 /* local data types */
251 /* We hold several abbreviation tables in memory at the same time. */
252 #ifndef ABBREV_HASH_SIZE
253 #define ABBREV_HASH_SIZE 121
256 /* The data in a compilation unit header, after target2host
257 translation, looks like this. */
258 struct comp_unit_head
262 unsigned char addr_size
;
263 unsigned char signed_addr_p
;
264 sect_offset abbrev_offset
;
266 /* Size of file offsets; either 4 or 8. */
267 unsigned int offset_size
;
269 /* Size of the length field; either 4 or 12. */
270 unsigned int initial_length_size
;
272 /* Offset to the first byte of this compilation unit header in the
273 .debug_info section, for resolving relative reference dies. */
276 /* Offset to first die in this cu from the start of the cu.
277 This will be the first byte following the compilation unit header. */
278 cu_offset first_die_offset
;
281 /* Type used for delaying computation of method physnames.
282 See comments for compute_delayed_physnames. */
283 struct delayed_method_info
285 /* The type to which the method is attached, i.e., its parent class. */
288 /* The index of the method in the type's function fieldlists. */
291 /* The index of the method in the fieldlist. */
294 /* The name of the DIE. */
297 /* The DIE associated with this method. */
298 struct die_info
*die
;
301 typedef struct delayed_method_info delayed_method_info
;
302 DEF_VEC_O (delayed_method_info
);
304 /* Internal state when decoding a particular compilation unit. */
307 /* The objfile containing this compilation unit. */
308 struct objfile
*objfile
;
310 /* The header of the compilation unit. */
311 struct comp_unit_head header
;
313 /* Base address of this compilation unit. */
314 CORE_ADDR base_address
;
316 /* Non-zero if base_address has been set. */
319 /* The language we are debugging. */
320 enum language language
;
321 const struct language_defn
*language_defn
;
323 const char *producer
;
325 /* The generic symbol table building routines have separate lists for
326 file scope symbols and all all other scopes (local scopes). So
327 we need to select the right one to pass to add_symbol_to_list().
328 We do it by keeping a pointer to the correct list in list_in_scope.
330 FIXME: The original dwarf code just treated the file scope as the
331 first local scope, and all other local scopes as nested local
332 scopes, and worked fine. Check to see if we really need to
333 distinguish these in buildsym.c. */
334 struct pending
**list_in_scope
;
336 /* DWARF abbreviation table associated with this compilation unit. */
337 struct abbrev_info
**dwarf2_abbrevs
;
339 /* Storage for the abbrev table. */
340 struct obstack abbrev_obstack
;
342 /* Hash table holding all the loaded partial DIEs
343 with partial_die->offset.SECT_OFF as hash. */
346 /* Storage for things with the same lifetime as this read-in compilation
347 unit, including partial DIEs. */
348 struct obstack comp_unit_obstack
;
350 /* When multiple dwarf2_cu structures are living in memory, this field
351 chains them all together, so that they can be released efficiently.
352 We will probably also want a generation counter so that most-recently-used
353 compilation units are cached... */
354 struct dwarf2_per_cu_data
*read_in_chain
;
356 /* Backchain to our per_cu entry if the tree has been built. */
357 struct dwarf2_per_cu_data
*per_cu
;
359 /* How many compilation units ago was this CU last referenced? */
362 /* A hash table of DIE cu_offset for following references with
363 die_info->offset.sect_off as hash. */
366 /* Full DIEs if read in. */
367 struct die_info
*dies
;
369 /* A set of pointers to dwarf2_per_cu_data objects for compilation
370 units referenced by this one. Only set during full symbol processing;
371 partial symbol tables do not have dependencies. */
374 /* Header data from the line table, during full symbol processing. */
375 struct line_header
*line_header
;
377 /* A list of methods which need to have physnames computed
378 after all type information has been read. */
379 VEC (delayed_method_info
) *method_list
;
381 /* To be copied to symtab->call_site_htab. */
382 htab_t call_site_htab
;
384 /* Mark used when releasing cached dies. */
385 unsigned int mark
: 1;
387 /* This CU references .debug_loc. See the symtab->locations_valid field.
388 This test is imperfect as there may exist optimized debug code not using
389 any location list and still facing inlining issues if handled as
390 unoptimized code. For a future better test see GCC PR other/32998. */
391 unsigned int has_loclist
: 1;
393 /* These cache the results of producer_is_gxx_lt_4_6.
394 CHECKED_PRODUCER is set if PRODUCER_IS_GXX_LT_4_6 is valid. This
395 information is cached because profiling CU expansion showed
396 excessive time spent in producer_is_gxx_lt_4_6. */
397 unsigned int checked_producer
: 1;
398 unsigned int producer_is_gxx_lt_4_6
: 1;
401 /* Persistent data held for a compilation unit, even when not
402 processing it. We put a pointer to this structure in the
403 read_symtab_private field of the psymtab. */
405 struct dwarf2_per_cu_data
407 /* The start offset and length of this compilation unit. 2**29-1
408 bytes should suffice to store the length of any compilation unit
409 - if it doesn't, GDB will fall over anyway.
410 NOTE: Unlike comp_unit_head.length, this length includes
411 initial_length_size. */
413 unsigned int length
: 29;
415 /* Flag indicating this compilation unit will be read in before
416 any of the current compilation units are processed. */
417 unsigned int queued
: 1;
419 /* This flag will be set when reading partial DIEs if we need to load
420 absolutely all DIEs for this compilation unit, instead of just the ones
421 we think are interesting. It gets set if we look for a DIE in the
422 hash table and don't find it. */
423 unsigned int load_all_dies
: 1;
425 /* Non-null if this CU is from .debug_types; in which case it points
426 to the section. Otherwise it's from .debug_info. */
427 struct dwarf2_section_info
*debug_types_section
;
429 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
430 of the CU cache it gets reset to NULL again. */
431 struct dwarf2_cu
*cu
;
433 /* The corresponding objfile.
434 Normally we can get the objfile from dwarf2_per_objfile.
435 However we can enter this file with just a "per_cu" handle. */
436 struct objfile
*objfile
;
438 /* When using partial symbol tables, the 'psymtab' field is active.
439 Otherwise the 'quick' field is active. */
442 /* The partial symbol table associated with this compilation unit,
443 or NULL for partial units (which do not have an associated
445 struct partial_symtab
*psymtab
;
447 /* Data needed by the "quick" functions. */
448 struct dwarf2_per_cu_quick_data
*quick
;
452 /* Entry in the signatured_types hash table. */
454 struct signatured_type
458 /* Offset in this TU of the type defined by this TU. */
459 cu_offset type_offset
;
461 /* The CU(/TU) of this type. */
462 struct dwarf2_per_cu_data per_cu
;
465 /* Struct used to pass misc. parameters to read_die_and_children, et
466 al. which are used for both .debug_info and .debug_types dies.
467 All parameters here are unchanging for the life of the call. This
468 struct exists to abstract away the constant parameters of die
471 struct die_reader_specs
473 /* The bfd of this objfile. */
476 /* The CU of the DIE we are parsing. */
477 struct dwarf2_cu
*cu
;
479 /* Pointer to start of section buffer.
480 This is either the start of .debug_info or .debug_types. */
481 const gdb_byte
*buffer
;
484 /* The line number information for a compilation unit (found in the
485 .debug_line section) begins with a "statement program header",
486 which contains the following information. */
489 unsigned int total_length
;
490 unsigned short version
;
491 unsigned int header_length
;
492 unsigned char minimum_instruction_length
;
493 unsigned char maximum_ops_per_instruction
;
494 unsigned char default_is_stmt
;
496 unsigned char line_range
;
497 unsigned char opcode_base
;
499 /* standard_opcode_lengths[i] is the number of operands for the
500 standard opcode whose value is i. This means that
501 standard_opcode_lengths[0] is unused, and the last meaningful
502 element is standard_opcode_lengths[opcode_base - 1]. */
503 unsigned char *standard_opcode_lengths
;
505 /* The include_directories table. NOTE! These strings are not
506 allocated with xmalloc; instead, they are pointers into
507 debug_line_buffer. If you try to free them, `free' will get
509 unsigned int num_include_dirs
, include_dirs_size
;
512 /* The file_names table. NOTE! These strings are not allocated
513 with xmalloc; instead, they are pointers into debug_line_buffer.
514 Don't try to free them directly. */
515 unsigned int num_file_names
, file_names_size
;
519 unsigned int dir_index
;
520 unsigned int mod_time
;
522 int included_p
; /* Non-zero if referenced by the Line Number Program. */
523 struct symtab
*symtab
; /* The associated symbol table, if any. */
526 /* The start and end of the statement program following this
527 header. These point into dwarf2_per_objfile->line_buffer. */
528 gdb_byte
*statement_program_start
, *statement_program_end
;
531 /* When we construct a partial symbol table entry we only
532 need this much information. */
533 struct partial_die_info
535 /* Offset of this DIE. */
538 /* DWARF-2 tag for this DIE. */
539 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
541 /* Assorted flags describing the data found in this DIE. */
542 unsigned int has_children
: 1;
543 unsigned int is_external
: 1;
544 unsigned int is_declaration
: 1;
545 unsigned int has_type
: 1;
546 unsigned int has_specification
: 1;
547 unsigned int has_pc_info
: 1;
548 unsigned int may_be_inlined
: 1;
550 /* Flag set if the SCOPE field of this structure has been
552 unsigned int scope_set
: 1;
554 /* Flag set if the DIE has a byte_size attribute. */
555 unsigned int has_byte_size
: 1;
557 /* Flag set if any of the DIE's children are template arguments. */
558 unsigned int has_template_arguments
: 1;
560 /* Flag set if fixup_partial_die has been called on this die. */
561 unsigned int fixup_called
: 1;
563 /* The name of this DIE. Normally the value of DW_AT_name, but
564 sometimes a default name for unnamed DIEs. */
567 /* The linkage name, if present. */
568 const char *linkage_name
;
570 /* The scope to prepend to our children. This is generally
571 allocated on the comp_unit_obstack, so will disappear
572 when this compilation unit leaves the cache. */
575 /* The location description associated with this DIE, if any. */
576 struct dwarf_block
*locdesc
;
578 /* If HAS_PC_INFO, the PC range associated with this DIE. */
582 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
583 DW_AT_sibling, if any. */
584 /* NOTE: This member isn't strictly necessary, read_partial_die could
585 return DW_AT_sibling values to its caller load_partial_dies. */
588 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
589 DW_AT_specification (or DW_AT_abstract_origin or
591 sect_offset spec_offset
;
593 /* Pointers to this DIE's parent, first child, and next sibling,
595 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
598 /* This data structure holds the information of an abbrev. */
601 unsigned int number
; /* number identifying abbrev */
602 enum dwarf_tag tag
; /* dwarf tag */
603 unsigned short has_children
; /* boolean */
604 unsigned short num_attrs
; /* number of attributes */
605 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
606 struct abbrev_info
*next
; /* next in chain */
611 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
612 ENUM_BITFIELD(dwarf_form
) form
: 16;
615 /* Attributes have a name and a value. */
618 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
619 ENUM_BITFIELD(dwarf_form
) form
: 15;
621 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
622 field should be in u.str (existing only for DW_STRING) but it is kept
623 here for better struct attribute alignment. */
624 unsigned int string_is_canonical
: 1;
629 struct dwarf_block
*blk
;
633 struct signatured_type
*signatured_type
;
638 /* This data structure holds a complete die structure. */
641 /* DWARF-2 tag for this DIE. */
642 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
644 /* Number of attributes */
645 unsigned char num_attrs
;
647 /* True if we're presently building the full type name for the
648 type derived from this DIE. */
649 unsigned char building_fullname
: 1;
654 /* Offset in .debug_info or .debug_types section. */
657 /* The dies in a compilation unit form an n-ary tree. PARENT
658 points to this die's parent; CHILD points to the first child of
659 this node; and all the children of a given node are chained
660 together via their SIBLING fields. */
661 struct die_info
*child
; /* Its first child, if any. */
662 struct die_info
*sibling
; /* Its next sibling, if any. */
663 struct die_info
*parent
; /* Its parent, if any. */
665 /* An array of attributes, with NUM_ATTRS elements. There may be
666 zero, but it's not common and zero-sized arrays are not
667 sufficiently portable C. */
668 struct attribute attrs
[1];
671 /* Get at parts of an attribute structure. */
673 #define DW_STRING(attr) ((attr)->u.str)
674 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
675 #define DW_UNSND(attr) ((attr)->u.unsnd)
676 #define DW_BLOCK(attr) ((attr)->u.blk)
677 #define DW_SND(attr) ((attr)->u.snd)
678 #define DW_ADDR(attr) ((attr)->u.addr)
679 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
681 /* Blocks are a bunch of untyped bytes. */
686 /* Valid only if SIZE is not zero. */
690 #ifndef ATTR_ALLOC_CHUNK
691 #define ATTR_ALLOC_CHUNK 4
694 /* Allocate fields for structs, unions and enums in this size. */
695 #ifndef DW_FIELD_ALLOC_CHUNK
696 #define DW_FIELD_ALLOC_CHUNK 4
699 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
700 but this would require a corresponding change in unpack_field_as_long
702 static int bits_per_byte
= 8;
704 /* The routines that read and process dies for a C struct or C++ class
705 pass lists of data member fields and lists of member function fields
706 in an instance of a field_info structure, as defined below. */
709 /* List of data member and baseclasses fields. */
712 struct nextfield
*next
;
717 *fields
, *baseclasses
;
719 /* Number of fields (including baseclasses). */
722 /* Number of baseclasses. */
725 /* Set if the accesibility of one of the fields is not public. */
726 int non_public_fields
;
728 /* Member function fields array, entries are allocated in the order they
729 are encountered in the object file. */
732 struct nextfnfield
*next
;
733 struct fn_field fnfield
;
737 /* Member function fieldlist array, contains name of possibly overloaded
738 member function, number of overloaded member functions and a pointer
739 to the head of the member function field chain. */
744 struct nextfnfield
*head
;
748 /* Number of entries in the fnfieldlists array. */
751 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
752 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
753 struct typedef_field_list
755 struct typedef_field field
;
756 struct typedef_field_list
*next
;
759 unsigned typedef_field_list_count
;
762 /* One item on the queue of compilation units to read in full symbols
764 struct dwarf2_queue_item
766 struct dwarf2_per_cu_data
*per_cu
;
767 struct dwarf2_queue_item
*next
;
770 /* The current queue. */
771 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
773 /* Loaded secondary compilation units are kept in memory until they
774 have not been referenced for the processing of this many
775 compilation units. Set this to zero to disable caching. Cache
776 sizes of up to at least twenty will improve startup time for
777 typical inter-CU-reference binaries, at an obvious memory cost. */
778 static int dwarf2_max_cache_age
= 5;
780 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
781 struct cmd_list_element
*c
, const char *value
)
783 fprintf_filtered (file
, _("The upper bound on the age of cached "
784 "dwarf2 compilation units is %s.\n"),
789 /* Various complaints about symbol reading that don't abort the process. */
792 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
794 complaint (&symfile_complaints
,
795 _("statement list doesn't fit in .debug_line section"));
799 dwarf2_debug_line_missing_file_complaint (void)
801 complaint (&symfile_complaints
,
802 _(".debug_line section has line data without a file"));
806 dwarf2_debug_line_missing_end_sequence_complaint (void)
808 complaint (&symfile_complaints
,
809 _(".debug_line section has line "
810 "program sequence without an end"));
814 dwarf2_complex_location_expr_complaint (void)
816 complaint (&symfile_complaints
, _("location expression too complex"));
820 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
823 complaint (&symfile_complaints
,
824 _("const value length mismatch for '%s', got %d, expected %d"),
829 dwarf2_macros_too_long_complaint (struct dwarf2_section_info
*section
)
831 complaint (&symfile_complaints
,
832 _("macro info runs off end of `%s' section"),
833 section
->asection
->name
);
837 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
839 complaint (&symfile_complaints
,
840 _("macro debug info contains a "
841 "malformed macro definition:\n`%s'"),
846 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
848 complaint (&symfile_complaints
,
849 _("invalid attribute class or form for '%s' in '%s'"),
853 /* local function prototypes */
855 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
857 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
860 static void dwarf2_find_base_address (struct die_info
*die
,
861 struct dwarf2_cu
*cu
);
863 static void dwarf2_build_psymtabs_hard (struct objfile
*);
865 static void scan_partial_symbols (struct partial_die_info
*,
866 CORE_ADDR
*, CORE_ADDR
*,
867 int, struct dwarf2_cu
*);
869 static void add_partial_symbol (struct partial_die_info
*,
872 static void add_partial_namespace (struct partial_die_info
*pdi
,
873 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
874 int need_pc
, struct dwarf2_cu
*cu
);
876 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
877 CORE_ADDR
*highpc
, int need_pc
,
878 struct dwarf2_cu
*cu
);
880 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
881 struct dwarf2_cu
*cu
);
883 static void add_partial_subprogram (struct partial_die_info
*pdi
,
884 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
885 int need_pc
, struct dwarf2_cu
*cu
);
887 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
888 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
889 bfd
*abfd
, struct dwarf2_cu
*cu
);
891 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
893 static void psymtab_to_symtab_1 (struct partial_symtab
*);
895 static void dwarf2_read_abbrevs (struct dwarf2_cu
*cu
);
897 static void dwarf2_free_abbrev_table (void *);
899 static unsigned int peek_abbrev_code (bfd
*, gdb_byte
*);
901 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
904 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
907 static struct partial_die_info
*load_partial_dies (bfd
*,
908 gdb_byte
*, gdb_byte
*,
909 int, struct dwarf2_cu
*);
911 static gdb_byte
*read_partial_die (struct partial_die_info
*,
912 struct abbrev_info
*abbrev
,
914 gdb_byte
*, gdb_byte
*,
917 static struct partial_die_info
*find_partial_die (sect_offset
,
920 static void fixup_partial_die (struct partial_die_info
*,
923 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
924 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
926 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
927 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
929 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
931 static int read_1_signed_byte (bfd
*, gdb_byte
*);
933 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
935 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
937 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
939 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
942 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
944 static LONGEST read_checked_initial_length_and_offset
945 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
946 unsigned int *, unsigned int *);
948 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
951 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
953 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
955 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
957 static char *read_indirect_string (bfd
*, gdb_byte
*,
958 const struct comp_unit_head
*,
961 static ULONGEST
read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
963 static LONGEST
read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
965 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
967 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
969 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
972 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
976 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
977 struct dwarf2_cu
*cu
);
979 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
981 static struct die_info
*die_specification (struct die_info
*die
,
982 struct dwarf2_cu
**);
984 static void free_line_header (struct line_header
*lh
);
986 static void add_file_name (struct line_header
*, char *, unsigned int,
987 unsigned int, unsigned int);
989 static struct line_header
*(dwarf_decode_line_header
990 (unsigned int offset
,
991 bfd
*abfd
, struct dwarf2_cu
*cu
));
993 static void dwarf_decode_lines (struct line_header
*, const char *,
994 struct dwarf2_cu
*, struct partial_symtab
*,
997 static void dwarf2_start_subfile (char *, const char *, const char *);
999 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1000 struct dwarf2_cu
*);
1002 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1003 struct dwarf2_cu
*, struct symbol
*);
1005 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1006 struct dwarf2_cu
*);
1008 static void dwarf2_const_value_attr (struct attribute
*attr
,
1011 struct obstack
*obstack
,
1012 struct dwarf2_cu
*cu
, LONGEST
*value
,
1014 struct dwarf2_locexpr_baton
**baton
);
1016 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1018 static int need_gnat_info (struct dwarf2_cu
*);
1020 static struct type
*die_descriptive_type (struct die_info
*,
1021 struct dwarf2_cu
*);
1023 static void set_descriptive_type (struct type
*, struct die_info
*,
1024 struct dwarf2_cu
*);
1026 static struct type
*die_containing_type (struct die_info
*,
1027 struct dwarf2_cu
*);
1029 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1030 struct dwarf2_cu
*);
1032 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1034 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1036 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1038 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1039 const char *suffix
, int physname
,
1040 struct dwarf2_cu
*cu
);
1042 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1044 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1046 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1048 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1050 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1052 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1053 struct dwarf2_cu
*, struct partial_symtab
*);
1055 static int dwarf2_get_pc_bounds (struct die_info
*,
1056 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1057 struct partial_symtab
*);
1059 static void get_scope_pc_bounds (struct die_info
*,
1060 CORE_ADDR
*, CORE_ADDR
*,
1061 struct dwarf2_cu
*);
1063 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1064 CORE_ADDR
, struct dwarf2_cu
*);
1066 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1067 struct dwarf2_cu
*);
1069 static void dwarf2_attach_fields_to_type (struct field_info
*,
1070 struct type
*, struct dwarf2_cu
*);
1072 static void dwarf2_add_member_fn (struct field_info
*,
1073 struct die_info
*, struct type
*,
1074 struct dwarf2_cu
*);
1076 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1078 struct dwarf2_cu
*);
1080 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1082 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1084 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1086 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1088 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1090 static struct type
*read_module_type (struct die_info
*die
,
1091 struct dwarf2_cu
*cu
);
1093 static const char *namespace_name (struct die_info
*die
,
1094 int *is_anonymous
, struct dwarf2_cu
*);
1096 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1098 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1100 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1101 struct dwarf2_cu
*);
1103 static struct die_info
*read_comp_unit (gdb_byte
*, struct dwarf2_cu
*);
1105 static struct die_info
*read_die_and_children_1 (const struct die_reader_specs
*reader
,
1107 gdb_byte
**new_info_ptr
,
1108 struct die_info
*parent
);
1110 static struct die_info
*read_die_and_children (const struct die_reader_specs
*reader
,
1112 gdb_byte
**new_info_ptr
,
1113 struct die_info
*parent
);
1115 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*reader
,
1117 gdb_byte
**new_info_ptr
,
1118 struct die_info
*parent
);
1120 static gdb_byte
*read_full_die (const struct die_reader_specs
*reader
,
1121 struct die_info
**, gdb_byte
*,
1124 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1126 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1129 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1131 static const char *dwarf2_full_name (char *name
,
1132 struct die_info
*die
,
1133 struct dwarf2_cu
*cu
);
1135 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1136 struct dwarf2_cu
**);
1138 static char *dwarf_tag_name (unsigned int);
1140 static char *dwarf_attr_name (unsigned int);
1142 static char *dwarf_form_name (unsigned int);
1144 static char *dwarf_bool_name (unsigned int);
1146 static char *dwarf_type_encoding_name (unsigned int);
1149 static char *dwarf_cfi_name (unsigned int);
1152 static struct die_info
*sibling_die (struct die_info
*);
1154 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1156 static void dump_die_for_error (struct die_info
*);
1158 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1161 /*static*/ void dump_die (struct die_info
*, int max_level
);
1163 static void store_in_ref_table (struct die_info
*,
1164 struct dwarf2_cu
*);
1166 static int is_ref_attr (struct attribute
*);
1168 static sect_offset
dwarf2_get_ref_die_offset (struct attribute
*);
1170 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1172 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1174 struct dwarf2_cu
**);
1176 static struct die_info
*follow_die_ref (struct die_info
*,
1178 struct dwarf2_cu
**);
1180 static struct die_info
*follow_die_sig (struct die_info
*,
1182 struct dwarf2_cu
**);
1184 static struct signatured_type
*lookup_signatured_type_at_offset
1185 (struct objfile
*objfile
,
1186 struct dwarf2_section_info
*section
, sect_offset offset
);
1188 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1190 static void read_signatured_type (struct signatured_type
*);
1192 /* memory allocation interface */
1194 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1196 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1198 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1200 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1201 char *, bfd
*, struct dwarf2_cu
*,
1202 struct dwarf2_section_info
*,
1205 static int attr_form_is_block (struct attribute
*);
1207 static int attr_form_is_section_offset (struct attribute
*);
1209 static int attr_form_is_constant (struct attribute
*);
1211 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1212 struct dwarf2_loclist_baton
*baton
,
1213 struct attribute
*attr
);
1215 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1217 struct dwarf2_cu
*cu
);
1219 static gdb_byte
*skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1220 struct abbrev_info
*abbrev
,
1221 struct dwarf2_cu
*cu
);
1223 static void free_stack_comp_unit (void *);
1225 static hashval_t
partial_die_hash (const void *item
);
1227 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1229 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1230 (sect_offset offset
, struct objfile
*objfile
);
1232 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1233 struct dwarf2_per_cu_data
*per_cu
);
1235 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1236 struct die_info
*comp_unit_die
);
1238 static void free_heap_comp_unit (void *);
1240 static void free_cached_comp_units (void *);
1242 static void age_cached_comp_units (void);
1244 static void free_one_cached_comp_unit (void *);
1246 static struct type
*set_die_type (struct die_info
*, struct type
*,
1247 struct dwarf2_cu
*);
1249 static void create_all_comp_units (struct objfile
*);
1251 static int create_all_type_units (struct objfile
*);
1253 static void load_full_comp_unit (struct dwarf2_per_cu_data
*);
1255 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1257 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1258 struct dwarf2_per_cu_data
*);
1260 static void dwarf2_mark (struct dwarf2_cu
*);
1262 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1264 static struct type
*get_die_type_at_offset (sect_offset
,
1265 struct dwarf2_per_cu_data
*per_cu
);
1267 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1269 static void dwarf2_release_queue (void *dummy
);
1271 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
);
1273 static void process_queue (void);
1275 static void find_file_and_directory (struct die_info
*die
,
1276 struct dwarf2_cu
*cu
,
1277 char **name
, char **comp_dir
);
1279 static char *file_full_name (int file
, struct line_header
*lh
,
1280 const char *comp_dir
);
1282 static gdb_byte
*read_and_check_comp_unit_head
1283 (struct comp_unit_head
*header
,
1284 struct dwarf2_section_info
*section
, gdb_byte
*info_ptr
,
1285 int is_debug_types_section
);
1287 static void init_cu_die_reader (struct die_reader_specs
*reader
,
1288 struct dwarf2_cu
*cu
);
1290 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1294 /* Convert VALUE between big- and little-endian. */
1296 byte_swap (offset_type value
)
1300 result
= (value
& 0xff) << 24;
1301 result
|= (value
& 0xff00) << 8;
1302 result
|= (value
& 0xff0000) >> 8;
1303 result
|= (value
& 0xff000000) >> 24;
1307 #define MAYBE_SWAP(V) byte_swap (V)
1310 #define MAYBE_SWAP(V) (V)
1311 #endif /* WORDS_BIGENDIAN */
1313 /* The suffix for an index file. */
1314 #define INDEX_SUFFIX ".gdb-index"
1316 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1317 struct dwarf2_cu
*cu
);
1319 /* Try to locate the sections we need for DWARF 2 debugging
1320 information and return true if we have enough to do something.
1321 NAMES points to the dwarf2 section names, or is NULL if the standard
1322 ELF names are used. */
1325 dwarf2_has_info (struct objfile
*objfile
,
1326 const struct dwarf2_debug_sections
*names
)
1328 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1329 if (!dwarf2_per_objfile
)
1331 /* Initialize per-objfile state. */
1332 struct dwarf2_per_objfile
*data
1333 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1335 memset (data
, 0, sizeof (*data
));
1336 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1337 dwarf2_per_objfile
= data
;
1339 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1341 dwarf2_per_objfile
->objfile
= objfile
;
1343 return (dwarf2_per_objfile
->info
.asection
!= NULL
1344 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1347 /* When loading sections, we look either for uncompressed section or for
1348 compressed section names. */
1351 section_is_p (const char *section_name
,
1352 const struct dwarf2_section_names
*names
)
1354 if (names
->normal
!= NULL
1355 && strcmp (section_name
, names
->normal
) == 0)
1357 if (names
->compressed
!= NULL
1358 && strcmp (section_name
, names
->compressed
) == 0)
1363 /* This function is mapped across the sections and remembers the
1364 offset and size of each of the debugging sections we are interested
1368 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1370 const struct dwarf2_debug_sections
*names
;
1373 names
= &dwarf2_elf_names
;
1375 names
= (const struct dwarf2_debug_sections
*) vnames
;
1377 if (section_is_p (sectp
->name
, &names
->info
))
1379 dwarf2_per_objfile
->info
.asection
= sectp
;
1380 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1382 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1384 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1385 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1387 else if (section_is_p (sectp
->name
, &names
->line
))
1389 dwarf2_per_objfile
->line
.asection
= sectp
;
1390 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1392 else if (section_is_p (sectp
->name
, &names
->loc
))
1394 dwarf2_per_objfile
->loc
.asection
= sectp
;
1395 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1397 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1399 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1400 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1402 else if (section_is_p (sectp
->name
, &names
->macro
))
1404 dwarf2_per_objfile
->macro
.asection
= sectp
;
1405 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
1407 else if (section_is_p (sectp
->name
, &names
->str
))
1409 dwarf2_per_objfile
->str
.asection
= sectp
;
1410 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1412 else if (section_is_p (sectp
->name
, &names
->frame
))
1414 dwarf2_per_objfile
->frame
.asection
= sectp
;
1415 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1417 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1419 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1421 if (aflag
& SEC_HAS_CONTENTS
)
1423 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1424 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1427 else if (section_is_p (sectp
->name
, &names
->ranges
))
1429 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1430 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1432 else if (section_is_p (sectp
->name
, &names
->types
))
1434 struct dwarf2_section_info type_section
;
1436 memset (&type_section
, 0, sizeof (type_section
));
1437 type_section
.asection
= sectp
;
1438 type_section
.size
= bfd_get_section_size (sectp
);
1440 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
1443 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1445 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1446 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1449 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1450 && bfd_section_vma (abfd
, sectp
) == 0)
1451 dwarf2_per_objfile
->has_section_at_zero
= 1;
1454 /* Decompress a section that was compressed using zlib. Store the
1455 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1458 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1459 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1461 bfd
*abfd
= objfile
->obfd
;
1463 error (_("Support for zlib-compressed DWARF data (from '%s') "
1464 "is disabled in this copy of GDB"),
1465 bfd_get_filename (abfd
));
1467 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1468 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1469 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1470 bfd_size_type uncompressed_size
;
1471 gdb_byte
*uncompressed_buffer
;
1474 int header_size
= 12;
1476 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1477 || bfd_bread (compressed_buffer
,
1478 compressed_size
, abfd
) != compressed_size
)
1479 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1480 bfd_get_filename (abfd
));
1482 /* Read the zlib header. In this case, it should be "ZLIB" followed
1483 by the uncompressed section size, 8 bytes in big-endian order. */
1484 if (compressed_size
< header_size
1485 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1486 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1487 bfd_get_filename (abfd
));
1488 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1489 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1490 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1491 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1492 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1493 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1494 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1495 uncompressed_size
+= compressed_buffer
[11];
1497 /* It is possible the section consists of several compressed
1498 buffers concatenated together, so we uncompress in a loop. */
1502 strm
.avail_in
= compressed_size
- header_size
;
1503 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1504 strm
.avail_out
= uncompressed_size
;
1505 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1507 rc
= inflateInit (&strm
);
1508 while (strm
.avail_in
> 0)
1511 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1512 bfd_get_filename (abfd
), rc
);
1513 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1514 + (uncompressed_size
- strm
.avail_out
));
1515 rc
= inflate (&strm
, Z_FINISH
);
1516 if (rc
!= Z_STREAM_END
)
1517 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1518 bfd_get_filename (abfd
), rc
);
1519 rc
= inflateReset (&strm
);
1521 rc
= inflateEnd (&strm
);
1523 || strm
.avail_out
!= 0)
1524 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1525 bfd_get_filename (abfd
), rc
);
1527 do_cleanups (cleanup
);
1528 *outbuf
= uncompressed_buffer
;
1529 *outsize
= uncompressed_size
;
1533 /* A helper function that decides whether a section is empty. */
1536 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1538 return info
->asection
== NULL
|| info
->size
== 0;
1541 /* Read the contents of the section INFO from object file specified by
1542 OBJFILE, store info about the section into INFO.
1543 If the section is compressed, uncompress it before returning. */
1546 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1548 bfd
*abfd
= objfile
->obfd
;
1549 asection
*sectp
= info
->asection
;
1550 gdb_byte
*buf
, *retbuf
;
1551 unsigned char header
[4];
1555 info
->buffer
= NULL
;
1556 info
->map_addr
= NULL
;
1559 if (dwarf2_section_empty_p (info
))
1562 /* Check if the file has a 4-byte header indicating compression. */
1563 if (info
->size
> sizeof (header
)
1564 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1565 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1567 /* Upon decompression, update the buffer and its size. */
1568 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1570 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1578 pagesize
= getpagesize ();
1580 /* Only try to mmap sections which are large enough: we don't want to
1581 waste space due to fragmentation. Also, only try mmap for sections
1582 without relocations. */
1584 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1586 info
->buffer
= bfd_mmap (abfd
, 0, info
->size
, PROT_READ
,
1587 MAP_PRIVATE
, sectp
->filepos
,
1588 &info
->map_addr
, &info
->map_len
);
1590 if ((caddr_t
)info
->buffer
!= MAP_FAILED
)
1592 #if HAVE_POSIX_MADVISE
1593 posix_madvise (info
->map_addr
, info
->map_len
, POSIX_MADV_WILLNEED
);
1600 /* If we get here, we are a normal, not-compressed section. */
1602 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1604 /* When debugging .o files, we may need to apply relocations; see
1605 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1606 We never compress sections in .o files, so we only need to
1607 try this when the section is not compressed. */
1608 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1611 info
->buffer
= retbuf
;
1615 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1616 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1617 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1618 bfd_get_filename (abfd
));
1621 /* A helper function that returns the size of a section in a safe way.
1622 If you are positive that the section has been read before using the
1623 size, then it is safe to refer to the dwarf2_section_info object's
1624 "size" field directly. In other cases, you must call this
1625 function, because for compressed sections the size field is not set
1626 correctly until the section has been read. */
1628 static bfd_size_type
1629 dwarf2_section_size (struct objfile
*objfile
,
1630 struct dwarf2_section_info
*info
)
1633 dwarf2_read_section (objfile
, info
);
1637 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1641 dwarf2_get_section_info (struct objfile
*objfile
,
1642 enum dwarf2_section_enum sect
,
1643 asection
**sectp
, gdb_byte
**bufp
,
1644 bfd_size_type
*sizep
)
1646 struct dwarf2_per_objfile
*data
1647 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1648 struct dwarf2_section_info
*info
;
1650 /* We may see an objfile without any DWARF, in which case we just
1661 case DWARF2_DEBUG_FRAME
:
1662 info
= &data
->frame
;
1664 case DWARF2_EH_FRAME
:
1665 info
= &data
->eh_frame
;
1668 gdb_assert_not_reached ("unexpected section");
1671 dwarf2_read_section (objfile
, info
);
1673 *sectp
= info
->asection
;
1674 *bufp
= info
->buffer
;
1675 *sizep
= info
->size
;
1679 /* DWARF quick_symbols_functions support. */
1681 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1682 unique line tables, so we maintain a separate table of all .debug_line
1683 derived entries to support the sharing.
1684 All the quick functions need is the list of file names. We discard the
1685 line_header when we're done and don't need to record it here. */
1686 struct quick_file_names
1688 /* The offset in .debug_line of the line table. We hash on this. */
1689 unsigned int offset
;
1691 /* The number of entries in file_names, real_names. */
1692 unsigned int num_file_names
;
1694 /* The file names from the line table, after being run through
1696 const char **file_names
;
1698 /* The file names from the line table after being run through
1699 gdb_realpath. These are computed lazily. */
1700 const char **real_names
;
1703 /* When using the index (and thus not using psymtabs), each CU has an
1704 object of this type. This is used to hold information needed by
1705 the various "quick" methods. */
1706 struct dwarf2_per_cu_quick_data
1708 /* The file table. This can be NULL if there was no file table
1709 or it's currently not read in.
1710 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1711 struct quick_file_names
*file_names
;
1713 /* The corresponding symbol table. This is NULL if symbols for this
1714 CU have not yet been read. */
1715 struct symtab
*symtab
;
1717 /* A temporary mark bit used when iterating over all CUs in
1718 expand_symtabs_matching. */
1719 unsigned int mark
: 1;
1721 /* True if we've tried to read the file table and found there isn't one.
1722 There will be no point in trying to read it again next time. */
1723 unsigned int no_file_data
: 1;
1726 /* Hash function for a quick_file_names. */
1729 hash_file_name_entry (const void *e
)
1731 const struct quick_file_names
*file_data
= e
;
1733 return file_data
->offset
;
1736 /* Equality function for a quick_file_names. */
1739 eq_file_name_entry (const void *a
, const void *b
)
1741 const struct quick_file_names
*ea
= a
;
1742 const struct quick_file_names
*eb
= b
;
1744 return ea
->offset
== eb
->offset
;
1747 /* Delete function for a quick_file_names. */
1750 delete_file_name_entry (void *e
)
1752 struct quick_file_names
*file_data
= e
;
1755 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
1757 xfree ((void*) file_data
->file_names
[i
]);
1758 if (file_data
->real_names
)
1759 xfree ((void*) file_data
->real_names
[i
]);
1762 /* The space for the struct itself lives on objfile_obstack,
1763 so we don't free it here. */
1766 /* Create a quick_file_names hash table. */
1769 create_quick_file_names_table (unsigned int nr_initial_entries
)
1771 return htab_create_alloc (nr_initial_entries
,
1772 hash_file_name_entry
, eq_file_name_entry
,
1773 delete_file_name_entry
, xcalloc
, xfree
);
1776 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
1777 have to be created afterwards. You should call age_cached_comp_units after
1778 processing PER_CU->CU. dw2_setup must have been already called. */
1781 load_cu (struct dwarf2_per_cu_data
*per_cu
)
1783 if (per_cu
->debug_types_section
)
1784 load_full_type_unit (per_cu
);
1786 load_full_comp_unit (per_cu
);
1788 gdb_assert (per_cu
->cu
!= NULL
);
1790 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
1793 /* Read in the symbols for PER_CU. */
1796 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
1798 struct cleanup
*back_to
;
1800 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
1802 queue_comp_unit (per_cu
);
1808 /* Age the cache, releasing compilation units that have not
1809 been used recently. */
1810 age_cached_comp_units ();
1812 do_cleanups (back_to
);
1815 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1816 the objfile from which this CU came. Returns the resulting symbol
1819 static struct symtab
*
1820 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
1822 if (!per_cu
->v
.quick
->symtab
)
1824 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1825 increment_reading_symtab ();
1826 dw2_do_instantiate_symtab (per_cu
);
1827 do_cleanups (back_to
);
1829 return per_cu
->v
.quick
->symtab
;
1832 /* Return the CU given its index. */
1834 static struct dwarf2_per_cu_data
*
1835 dw2_get_cu (int index
)
1837 if (index
>= dwarf2_per_objfile
->n_comp_units
)
1839 index
-= dwarf2_per_objfile
->n_comp_units
;
1840 return dwarf2_per_objfile
->all_type_units
[index
];
1842 return dwarf2_per_objfile
->all_comp_units
[index
];
1845 /* A helper function that knows how to read a 64-bit value in a way
1846 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1850 extract_cu_value (const char *bytes
, ULONGEST
*result
)
1852 if (sizeof (ULONGEST
) < 8)
1856 /* Ignore the upper 4 bytes if they are all zero. */
1857 for (i
= 0; i
< 4; ++i
)
1858 if (bytes
[i
+ 4] != 0)
1861 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
1864 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
1868 /* Read the CU list from the mapped index, and use it to create all
1869 the CU objects for this objfile. Return 0 if something went wrong,
1870 1 if everything went ok. */
1873 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
1874 offset_type cu_list_elements
)
1878 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
1879 dwarf2_per_objfile
->all_comp_units
1880 = obstack_alloc (&objfile
->objfile_obstack
,
1881 dwarf2_per_objfile
->n_comp_units
1882 * sizeof (struct dwarf2_per_cu_data
*));
1884 for (i
= 0; i
< cu_list_elements
; i
+= 2)
1886 struct dwarf2_per_cu_data
*the_cu
;
1887 ULONGEST offset
, length
;
1889 if (!extract_cu_value (cu_list
, &offset
)
1890 || !extract_cu_value (cu_list
+ 8, &length
))
1894 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1895 struct dwarf2_per_cu_data
);
1896 the_cu
->offset
.sect_off
= offset
;
1897 the_cu
->length
= length
;
1898 the_cu
->objfile
= objfile
;
1899 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1900 struct dwarf2_per_cu_quick_data
);
1901 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
1907 /* Create the signatured type hash table from the index. */
1910 create_signatured_type_table_from_index (struct objfile
*objfile
,
1911 struct dwarf2_section_info
*section
,
1912 const gdb_byte
*bytes
,
1913 offset_type elements
)
1916 htab_t sig_types_hash
;
1918 dwarf2_per_objfile
->n_type_units
= elements
/ 3;
1919 dwarf2_per_objfile
->all_type_units
1920 = obstack_alloc (&objfile
->objfile_obstack
,
1921 dwarf2_per_objfile
->n_type_units
1922 * sizeof (struct dwarf2_per_cu_data
*));
1924 sig_types_hash
= allocate_signatured_type_table (objfile
);
1926 for (i
= 0; i
< elements
; i
+= 3)
1928 struct signatured_type
*sig_type
;
1929 ULONGEST offset
, type_offset_in_tu
, signature
;
1932 if (!extract_cu_value (bytes
, &offset
)
1933 || !extract_cu_value (bytes
+ 8, &type_offset_in_tu
))
1935 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
1938 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1939 struct signatured_type
);
1940 sig_type
->signature
= signature
;
1941 sig_type
->type_offset
.cu_off
= type_offset_in_tu
;
1942 sig_type
->per_cu
.debug_types_section
= section
;
1943 sig_type
->per_cu
.offset
.sect_off
= offset
;
1944 sig_type
->per_cu
.objfile
= objfile
;
1945 sig_type
->per_cu
.v
.quick
1946 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1947 struct dwarf2_per_cu_quick_data
);
1949 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
1952 dwarf2_per_objfile
->all_type_units
[i
/ 3] = &sig_type
->per_cu
;
1955 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
1960 /* Read the address map data from the mapped index, and use it to
1961 populate the objfile's psymtabs_addrmap. */
1964 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
1966 const gdb_byte
*iter
, *end
;
1967 struct obstack temp_obstack
;
1968 struct addrmap
*mutable_map
;
1969 struct cleanup
*cleanup
;
1972 obstack_init (&temp_obstack
);
1973 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
1974 mutable_map
= addrmap_create_mutable (&temp_obstack
);
1976 iter
= index
->address_table
;
1977 end
= iter
+ index
->address_table_size
;
1979 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1983 ULONGEST hi
, lo
, cu_index
;
1984 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1986 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1988 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
1991 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
1992 dw2_get_cu (cu_index
));
1995 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
1996 &objfile
->objfile_obstack
);
1997 do_cleanups (cleanup
);
2000 /* The hash function for strings in the mapped index. This is the same as
2001 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2002 implementation. This is necessary because the hash function is tied to the
2003 format of the mapped index file. The hash values do not have to match with
2006 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2009 mapped_index_string_hash (int index_version
, const void *p
)
2011 const unsigned char *str
= (const unsigned char *) p
;
2015 while ((c
= *str
++) != 0)
2017 if (index_version
>= 5)
2019 r
= r
* 67 + c
- 113;
2025 /* Find a slot in the mapped index INDEX for the object named NAME.
2026 If NAME is found, set *VEC_OUT to point to the CU vector in the
2027 constant pool and return 1. If NAME cannot be found, return 0. */
2030 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2031 offset_type
**vec_out
)
2033 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2035 offset_type slot
, step
;
2036 int (*cmp
) (const char *, const char *);
2038 if (current_language
->la_language
== language_cplus
2039 || current_language
->la_language
== language_java
2040 || current_language
->la_language
== language_fortran
)
2042 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2044 const char *paren
= strchr (name
, '(');
2050 dup
= xmalloc (paren
- name
+ 1);
2051 memcpy (dup
, name
, paren
- name
);
2052 dup
[paren
- name
] = 0;
2054 make_cleanup (xfree
, dup
);
2059 /* Index version 4 did not support case insensitive searches. But the
2060 indices for case insensitive languages are built in lowercase, therefore
2061 simulate our NAME being searched is also lowercased. */
2062 hash
= mapped_index_string_hash ((index
->version
== 4
2063 && case_sensitivity
== case_sensitive_off
2064 ? 5 : index
->version
),
2067 slot
= hash
& (index
->symbol_table_slots
- 1);
2068 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2069 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2073 /* Convert a slot number to an offset into the table. */
2074 offset_type i
= 2 * slot
;
2076 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2078 do_cleanups (back_to
);
2082 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2083 if (!cmp (name
, str
))
2085 *vec_out
= (offset_type
*) (index
->constant_pool
2086 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2087 do_cleanups (back_to
);
2091 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2095 /* Read the index file. If everything went ok, initialize the "quick"
2096 elements of all the CUs and return 1. Otherwise, return 0. */
2099 dwarf2_read_index (struct objfile
*objfile
)
2102 struct mapped_index
*map
;
2103 offset_type
*metadata
;
2104 const gdb_byte
*cu_list
;
2105 const gdb_byte
*types_list
= NULL
;
2106 offset_type version
, cu_list_elements
;
2107 offset_type types_list_elements
= 0;
2110 if (dwarf2_section_empty_p (&dwarf2_per_objfile
->gdb_index
))
2113 /* Older elfutils strip versions could keep the section in the main
2114 executable while splitting it for the separate debug info file. */
2115 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
2116 & SEC_HAS_CONTENTS
) == 0)
2119 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
2121 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
2122 /* Version check. */
2123 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2124 /* Versions earlier than 3 emitted every copy of a psymbol. This
2125 causes the index to behave very poorly for certain requests. Version 3
2126 contained incomplete addrmap. So, it seems better to just ignore such
2130 static int warning_printed
= 0;
2131 if (!warning_printed
)
2133 warning (_("Skipping obsolete .gdb_index section in %s."),
2135 warning_printed
= 1;
2139 /* Index version 4 uses a different hash function than index version
2142 Versions earlier than 6 did not emit psymbols for inlined
2143 functions. Using these files will cause GDB not to be able to
2144 set breakpoints on inlined functions by name, so we ignore these
2145 indices unless the --use-deprecated-index-sections command line
2146 option was supplied. */
2147 if (version
< 6 && !use_deprecated_index_sections
)
2149 static int warning_printed
= 0;
2150 if (!warning_printed
)
2152 warning (_("Skipping deprecated .gdb_index section in %s, pass "
2153 "--use-deprecated-index-sections to use them anyway"),
2155 warning_printed
= 1;
2159 /* Indexes with higher version than the one supported by GDB may be no
2160 longer backward compatible. */
2164 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
2165 map
->version
= version
;
2166 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
2168 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2171 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2172 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2176 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2177 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2178 - MAYBE_SWAP (metadata
[i
]))
2182 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2183 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2184 - MAYBE_SWAP (metadata
[i
]));
2187 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2188 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2189 - MAYBE_SWAP (metadata
[i
]))
2190 / (2 * sizeof (offset_type
)));
2193 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2195 /* Don't use the index if it's empty. */
2196 if (map
->symbol_table_slots
== 0)
2199 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
2202 if (types_list_elements
)
2204 struct dwarf2_section_info
*section
;
2206 /* We can only handle a single .debug_types when we have an
2208 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2211 section
= VEC_index (dwarf2_section_info_def
,
2212 dwarf2_per_objfile
->types
, 0);
2214 if (!create_signatured_type_table_from_index (objfile
, section
,
2216 types_list_elements
))
2220 create_addrmap_from_index (objfile
, map
);
2222 dwarf2_per_objfile
->index_table
= map
;
2223 dwarf2_per_objfile
->using_index
= 1;
2224 dwarf2_per_objfile
->quick_file_names_table
=
2225 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2230 /* A helper for the "quick" functions which sets the global
2231 dwarf2_per_objfile according to OBJFILE. */
2234 dw2_setup (struct objfile
*objfile
)
2236 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2237 gdb_assert (dwarf2_per_objfile
);
2240 /* A helper for the "quick" functions which attempts to read the line
2241 table for THIS_CU. */
2243 static struct quick_file_names
*
2244 dw2_get_file_names (struct objfile
*objfile
,
2245 struct dwarf2_per_cu_data
*this_cu
)
2247 bfd
*abfd
= objfile
->obfd
;
2248 struct line_header
*lh
;
2249 struct attribute
*attr
;
2250 struct cleanup
*cleanups
;
2251 struct die_info
*comp_unit_die
;
2252 struct dwarf2_section_info
* sec
;
2254 int has_children
, i
;
2255 struct dwarf2_cu cu
;
2256 unsigned int bytes_read
;
2257 struct die_reader_specs reader_specs
;
2258 char *name
, *comp_dir
;
2260 struct quick_file_names
*qfn
;
2261 unsigned int line_offset
;
2263 if (this_cu
->v
.quick
->file_names
!= NULL
)
2264 return this_cu
->v
.quick
->file_names
;
2265 /* If we know there is no line data, no point in looking again. */
2266 if (this_cu
->v
.quick
->no_file_data
)
2269 init_one_comp_unit (&cu
, this_cu
);
2270 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
2272 if (this_cu
->debug_types_section
)
2273 sec
= this_cu
->debug_types_section
;
2275 sec
= &dwarf2_per_objfile
->info
;
2276 dwarf2_read_section (objfile
, sec
);
2277 info_ptr
= sec
->buffer
+ this_cu
->offset
.sect_off
;
2279 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, sec
, info_ptr
,
2280 this_cu
->debug_types_section
!= NULL
);
2282 /* Skip dummy compilation units. */
2283 if (info_ptr
>= (sec
->buffer
+ sec
->size
)
2284 || peek_abbrev_code (abfd
, info_ptr
) == 0)
2286 do_cleanups (cleanups
);
2290 dwarf2_read_abbrevs (&cu
);
2291 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2293 init_cu_die_reader (&reader_specs
, &cu
);
2294 read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2300 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, &cu
);
2303 struct quick_file_names find_entry
;
2305 line_offset
= DW_UNSND (attr
);
2307 /* We may have already read in this line header (TU line header sharing).
2308 If we have we're done. */
2309 find_entry
.offset
= line_offset
;
2310 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2311 &find_entry
, INSERT
);
2314 do_cleanups (cleanups
);
2315 this_cu
->v
.quick
->file_names
= *slot
;
2319 lh
= dwarf_decode_line_header (line_offset
, abfd
, &cu
);
2323 do_cleanups (cleanups
);
2324 this_cu
->v
.quick
->no_file_data
= 1;
2328 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2329 qfn
->offset
= line_offset
;
2330 gdb_assert (slot
!= NULL
);
2333 find_file_and_directory (comp_unit_die
, &cu
, &name
, &comp_dir
);
2335 qfn
->num_file_names
= lh
->num_file_names
;
2336 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2337 lh
->num_file_names
* sizeof (char *));
2338 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2339 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2340 qfn
->real_names
= NULL
;
2342 free_line_header (lh
);
2343 do_cleanups (cleanups
);
2345 this_cu
->v
.quick
->file_names
= qfn
;
2349 /* A helper for the "quick" functions which computes and caches the
2350 real path for a given file name from the line table. */
2353 dw2_get_real_path (struct objfile
*objfile
,
2354 struct quick_file_names
*qfn
, int index
)
2356 if (qfn
->real_names
== NULL
)
2357 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2358 qfn
->num_file_names
, sizeof (char *));
2360 if (qfn
->real_names
[index
] == NULL
)
2361 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2363 return qfn
->real_names
[index
];
2366 static struct symtab
*
2367 dw2_find_last_source_symtab (struct objfile
*objfile
)
2371 dw2_setup (objfile
);
2372 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2373 return dw2_instantiate_symtab (dw2_get_cu (index
));
2376 /* Traversal function for dw2_forget_cached_source_info. */
2379 dw2_free_cached_file_names (void **slot
, void *info
)
2381 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2383 if (file_data
->real_names
)
2387 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2389 xfree ((void*) file_data
->real_names
[i
]);
2390 file_data
->real_names
[i
] = NULL
;
2398 dw2_forget_cached_source_info (struct objfile
*objfile
)
2400 dw2_setup (objfile
);
2402 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2403 dw2_free_cached_file_names
, NULL
);
2406 /* Helper function for dw2_map_symtabs_matching_filename that expands
2407 the symtabs and calls the iterator. */
2410 dw2_map_expand_apply (struct objfile
*objfile
,
2411 struct dwarf2_per_cu_data
*per_cu
,
2413 const char *full_path
, const char *real_path
,
2414 int (*callback
) (struct symtab
*, void *),
2417 struct symtab
*last_made
= objfile
->symtabs
;
2419 /* Don't visit already-expanded CUs. */
2420 if (per_cu
->v
.quick
->symtab
)
2423 /* This may expand more than one symtab, and we want to iterate over
2425 dw2_instantiate_symtab (per_cu
);
2427 return iterate_over_some_symtabs (name
, full_path
, real_path
, callback
, data
,
2428 objfile
->symtabs
, last_made
);
2431 /* Implementation of the map_symtabs_matching_filename method. */
2434 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
2435 const char *full_path
, const char *real_path
,
2436 int (*callback
) (struct symtab
*, void *),
2440 const char *name_basename
= lbasename (name
);
2441 int name_len
= strlen (name
);
2442 int is_abs
= IS_ABSOLUTE_PATH (name
);
2444 dw2_setup (objfile
);
2446 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2447 + dwarf2_per_objfile
->n_type_units
); ++i
)
2450 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2451 struct quick_file_names
*file_data
;
2453 /* We only need to look at symtabs not already expanded. */
2454 if (per_cu
->v
.quick
->symtab
)
2457 file_data
= dw2_get_file_names (objfile
, per_cu
);
2458 if (file_data
== NULL
)
2461 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2463 const char *this_name
= file_data
->file_names
[j
];
2465 if (FILENAME_CMP (name
, this_name
) == 0
2466 || (!is_abs
&& compare_filenames_for_search (this_name
,
2469 if (dw2_map_expand_apply (objfile
, per_cu
,
2470 name
, full_path
, real_path
,
2475 /* Before we invoke realpath, which can get expensive when many
2476 files are involved, do a quick comparison of the basenames. */
2477 if (! basenames_may_differ
2478 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
2481 if (full_path
!= NULL
)
2483 const char *this_real_name
= dw2_get_real_path (objfile
,
2486 if (this_real_name
!= NULL
2487 && (FILENAME_CMP (full_path
, this_real_name
) == 0
2489 && compare_filenames_for_search (this_real_name
,
2492 if (dw2_map_expand_apply (objfile
, per_cu
,
2493 name
, full_path
, real_path
,
2499 if (real_path
!= NULL
)
2501 const char *this_real_name
= dw2_get_real_path (objfile
,
2504 if (this_real_name
!= NULL
2505 && (FILENAME_CMP (real_path
, this_real_name
) == 0
2507 && compare_filenames_for_search (this_real_name
,
2510 if (dw2_map_expand_apply (objfile
, per_cu
,
2511 name
, full_path
, real_path
,
2522 static struct symtab
*
2523 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2524 const char *name
, domain_enum domain
)
2526 /* We do all the work in the pre_expand_symtabs_matching hook
2531 /* A helper function that expands all symtabs that hold an object
2535 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2537 dw2_setup (objfile
);
2539 /* index_table is NULL if OBJF_READNOW. */
2540 if (dwarf2_per_objfile
->index_table
)
2544 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2547 offset_type i
, len
= MAYBE_SWAP (*vec
);
2548 for (i
= 0; i
< len
; ++i
)
2550 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2551 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2553 dw2_instantiate_symtab (per_cu
);
2560 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2561 enum block_enum block_kind
, const char *name
,
2564 dw2_do_expand_symtabs_matching (objfile
, name
);
2568 dw2_print_stats (struct objfile
*objfile
)
2572 dw2_setup (objfile
);
2574 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2575 + dwarf2_per_objfile
->n_type_units
); ++i
)
2577 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2579 if (!per_cu
->v
.quick
->symtab
)
2582 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2586 dw2_dump (struct objfile
*objfile
)
2588 /* Nothing worth printing. */
2592 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2593 struct section_offsets
*delta
)
2595 /* There's nothing to relocate here. */
2599 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2600 const char *func_name
)
2602 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2606 dw2_expand_all_symtabs (struct objfile
*objfile
)
2610 dw2_setup (objfile
);
2612 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2613 + dwarf2_per_objfile
->n_type_units
); ++i
)
2615 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2617 dw2_instantiate_symtab (per_cu
);
2622 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2623 const char *filename
)
2627 dw2_setup (objfile
);
2629 /* We don't need to consider type units here.
2630 This is only called for examining code, e.g. expand_line_sal.
2631 There can be an order of magnitude (or more) more type units
2632 than comp units, and we avoid them if we can. */
2634 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2637 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2638 struct quick_file_names
*file_data
;
2640 /* We only need to look at symtabs not already expanded. */
2641 if (per_cu
->v
.quick
->symtab
)
2644 file_data
= dw2_get_file_names (objfile
, per_cu
);
2645 if (file_data
== NULL
)
2648 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2650 const char *this_name
= file_data
->file_names
[j
];
2651 if (FILENAME_CMP (this_name
, filename
) == 0)
2653 dw2_instantiate_symtab (per_cu
);
2661 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2663 struct dwarf2_per_cu_data
*per_cu
;
2665 struct quick_file_names
*file_data
;
2667 dw2_setup (objfile
);
2669 /* index_table is NULL if OBJF_READNOW. */
2670 if (!dwarf2_per_objfile
->index_table
)
2674 ALL_OBJFILE_SYMTABS (objfile
, s
)
2677 struct blockvector
*bv
= BLOCKVECTOR (s
);
2678 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2679 struct symbol
*sym
= lookup_block_symbol (block
, name
, VAR_DOMAIN
);
2682 return sym
->symtab
->filename
;
2687 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2691 /* Note that this just looks at the very first one named NAME -- but
2692 actually we are looking for a function. find_main_filename
2693 should be rewritten so that it doesn't require a custom hook. It
2694 could just use the ordinary symbol tables. */
2695 /* vec[0] is the length, which must always be >0. */
2696 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[1]));
2698 file_data
= dw2_get_file_names (objfile
, per_cu
);
2699 if (file_data
== NULL
)
2702 return file_data
->file_names
[file_data
->num_file_names
- 1];
2706 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
2707 struct objfile
*objfile
, int global
,
2708 int (*callback
) (struct block
*,
2709 struct symbol
*, void *),
2710 void *data
, symbol_compare_ftype
*match
,
2711 symbol_compare_ftype
*ordered_compare
)
2713 /* Currently unimplemented; used for Ada. The function can be called if the
2714 current language is Ada for a non-Ada objfile using GNU index. As Ada
2715 does not look for non-Ada symbols this function should just return. */
2719 dw2_expand_symtabs_matching
2720 (struct objfile
*objfile
,
2721 int (*file_matcher
) (const char *, void *),
2722 int (*name_matcher
) (const char *, void *),
2723 enum search_domain kind
,
2728 struct mapped_index
*index
;
2730 dw2_setup (objfile
);
2732 /* index_table is NULL if OBJF_READNOW. */
2733 if (!dwarf2_per_objfile
->index_table
)
2735 index
= dwarf2_per_objfile
->index_table
;
2737 if (file_matcher
!= NULL
)
2739 struct cleanup
*cleanup
;
2740 htab_t visited_found
, visited_not_found
;
2742 visited_found
= htab_create_alloc (10,
2743 htab_hash_pointer
, htab_eq_pointer
,
2744 NULL
, xcalloc
, xfree
);
2745 cleanup
= make_cleanup_htab_delete (visited_found
);
2746 visited_not_found
= htab_create_alloc (10,
2747 htab_hash_pointer
, htab_eq_pointer
,
2748 NULL
, xcalloc
, xfree
);
2749 make_cleanup_htab_delete (visited_not_found
);
2751 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2752 + dwarf2_per_objfile
->n_type_units
); ++i
)
2755 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2756 struct quick_file_names
*file_data
;
2759 per_cu
->v
.quick
->mark
= 0;
2761 /* We only need to look at symtabs not already expanded. */
2762 if (per_cu
->v
.quick
->symtab
)
2765 file_data
= dw2_get_file_names (objfile
, per_cu
);
2766 if (file_data
== NULL
)
2769 if (htab_find (visited_not_found
, file_data
) != NULL
)
2771 else if (htab_find (visited_found
, file_data
) != NULL
)
2773 per_cu
->v
.quick
->mark
= 1;
2777 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2779 if (file_matcher (file_data
->file_names
[j
], data
))
2781 per_cu
->v
.quick
->mark
= 1;
2786 slot
= htab_find_slot (per_cu
->v
.quick
->mark
2788 : visited_not_found
,
2793 do_cleanups (cleanup
);
2796 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2798 offset_type idx
= 2 * iter
;
2800 offset_type
*vec
, vec_len
, vec_idx
;
2802 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2805 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
2807 if (! (*name_matcher
) (name
, data
))
2810 /* The name was matched, now expand corresponding CUs that were
2812 vec
= (offset_type
*) (index
->constant_pool
2813 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
2814 vec_len
= MAYBE_SWAP (vec
[0]);
2815 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2817 struct dwarf2_per_cu_data
*per_cu
;
2819 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[vec_idx
+ 1]));
2820 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
2821 dw2_instantiate_symtab (per_cu
);
2826 static struct symtab
*
2827 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
2828 struct minimal_symbol
*msymbol
,
2830 struct obj_section
*section
,
2833 struct dwarf2_per_cu_data
*data
;
2835 dw2_setup (objfile
);
2837 if (!objfile
->psymtabs_addrmap
)
2840 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
2844 if (warn_if_readin
&& data
->v
.quick
->symtab
)
2845 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2846 paddress (get_objfile_arch (objfile
), pc
));
2848 return dw2_instantiate_symtab (data
);
2852 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
2853 void *data
, int need_fullname
)
2856 struct cleanup
*cleanup
;
2857 htab_t visited
= htab_create_alloc (10, htab_hash_pointer
, htab_eq_pointer
,
2858 NULL
, xcalloc
, xfree
);
2860 cleanup
= make_cleanup_htab_delete (visited
);
2861 dw2_setup (objfile
);
2863 /* We can ignore file names coming from already-expanded CUs. */
2864 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2865 + dwarf2_per_objfile
->n_type_units
); ++i
)
2867 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2869 if (per_cu
->v
.quick
->symtab
)
2871 void **slot
= htab_find_slot (visited
, per_cu
->v
.quick
->file_names
,
2874 *slot
= per_cu
->v
.quick
->file_names
;
2878 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2879 + dwarf2_per_objfile
->n_type_units
); ++i
)
2882 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2883 struct quick_file_names
*file_data
;
2886 /* We only need to look at symtabs not already expanded. */
2887 if (per_cu
->v
.quick
->symtab
)
2890 file_data
= dw2_get_file_names (objfile
, per_cu
);
2891 if (file_data
== NULL
)
2894 slot
= htab_find_slot (visited
, file_data
, INSERT
);
2897 /* Already visited. */
2902 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2904 const char *this_real_name
;
2907 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
2909 this_real_name
= NULL
;
2910 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
2914 do_cleanups (cleanup
);
2918 dw2_has_symbols (struct objfile
*objfile
)
2923 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
2926 dw2_find_last_source_symtab
,
2927 dw2_forget_cached_source_info
,
2928 dw2_map_symtabs_matching_filename
,
2930 dw2_pre_expand_symtabs_matching
,
2934 dw2_expand_symtabs_for_function
,
2935 dw2_expand_all_symtabs
,
2936 dw2_expand_symtabs_with_filename
,
2937 dw2_find_symbol_file
,
2938 dw2_map_matching_symbols
,
2939 dw2_expand_symtabs_matching
,
2940 dw2_find_pc_sect_symtab
,
2941 dw2_map_symbol_filenames
2944 /* Initialize for reading DWARF for this objfile. Return 0 if this
2945 file will use psymtabs, or 1 if using the GNU index. */
2948 dwarf2_initialize_objfile (struct objfile
*objfile
)
2950 /* If we're about to read full symbols, don't bother with the
2951 indices. In this case we also don't care if some other debug
2952 format is making psymtabs, because they are all about to be
2954 if ((objfile
->flags
& OBJF_READNOW
))
2958 dwarf2_per_objfile
->using_index
= 1;
2959 create_all_comp_units (objfile
);
2960 create_all_type_units (objfile
);
2961 dwarf2_per_objfile
->quick_file_names_table
=
2962 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2964 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2965 + dwarf2_per_objfile
->n_type_units
); ++i
)
2967 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2969 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2970 struct dwarf2_per_cu_quick_data
);
2973 /* Return 1 so that gdb sees the "quick" functions. However,
2974 these functions will be no-ops because we will have expanded
2979 if (dwarf2_read_index (objfile
))
2987 /* Build a partial symbol table. */
2990 dwarf2_build_psymtabs (struct objfile
*objfile
)
2992 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2994 init_psymbol_list (objfile
, 1024);
2997 dwarf2_build_psymtabs_hard (objfile
);
3000 /* Return TRUE if OFFSET is within CU_HEADER. */
3003 offset_in_cu_p (const struct comp_unit_head
*cu_header
, sect_offset offset
)
3005 sect_offset bottom
= { cu_header
->offset
.sect_off
};
3006 sect_offset top
= { (cu_header
->offset
.sect_off
+ cu_header
->length
3007 + cu_header
->initial_length_size
) };
3009 return (offset
.sect_off
>= bottom
.sect_off
&& offset
.sect_off
< top
.sect_off
);
3012 /* Read in the comp unit header information from the debug_info at info_ptr.
3013 NOTE: This leaves members offset, first_die_offset to be filled in
3017 read_comp_unit_head (struct comp_unit_head
*cu_header
,
3018 gdb_byte
*info_ptr
, bfd
*abfd
)
3021 unsigned int bytes_read
;
3023 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
3024 cu_header
->initial_length_size
= bytes_read
;
3025 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
3026 info_ptr
+= bytes_read
;
3027 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
3029 cu_header
->abbrev_offset
.sect_off
= read_offset (abfd
, info_ptr
, cu_header
,
3031 info_ptr
+= bytes_read
;
3032 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
3034 signed_addr
= bfd_get_sign_extend_vma (abfd
);
3035 if (signed_addr
< 0)
3036 internal_error (__FILE__
, __LINE__
,
3037 _("read_comp_unit_head: dwarf from non elf file"));
3038 cu_header
->signed_addr_p
= signed_addr
;
3043 /* Subroutine of read_and_check_comp_unit_head and
3044 read_and_check_type_unit_head to simplify them.
3045 Perform various error checking on the header. */
3048 error_check_comp_unit_head (struct comp_unit_head
*header
,
3049 struct dwarf2_section_info
*section
)
3051 bfd
*abfd
= section
->asection
->owner
;
3052 const char *filename
= bfd_get_filename (abfd
);
3054 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
3055 error (_("Dwarf Error: wrong version in compilation unit header "
3056 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
3059 if (header
->abbrev_offset
.sect_off
3060 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
3061 &dwarf2_per_objfile
->abbrev
))
3062 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3063 "(offset 0x%lx + 6) [in module %s]"),
3064 (long) header
->abbrev_offset
.sect_off
, (long) header
->offset
.sect_off
,
3067 /* Cast to unsigned long to use 64-bit arithmetic when possible to
3068 avoid potential 32-bit overflow. */
3069 if (((unsigned long) header
->offset
.sect_off
3070 + header
->length
+ header
->initial_length_size
)
3072 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3073 "(offset 0x%lx + 0) [in module %s]"),
3074 (long) header
->length
, (long) header
->offset
.sect_off
,
3078 /* Read in a CU/TU header and perform some basic error checking.
3079 The contents of the header are stored in HEADER.
3080 The result is a pointer to the start of the first DIE. */
3083 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
3084 struct dwarf2_section_info
*section
,
3086 int is_debug_types_section
)
3088 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3089 bfd
*abfd
= section
->asection
->owner
;
3091 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3093 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3095 /* If we're reading a type unit, skip over the signature and
3096 type_offset fields. */
3097 if (is_debug_types_section
)
3098 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
3100 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3102 error_check_comp_unit_head (header
, section
);
3107 /* Read in the types comp unit header information from .debug_types entry at
3108 types_ptr. The result is a pointer to one past the end of the header. */
3111 read_and_check_type_unit_head (struct comp_unit_head
*header
,
3112 struct dwarf2_section_info
*section
,
3114 ULONGEST
*signature
, cu_offset
*type_offset
)
3116 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3117 bfd
*abfd
= section
->asection
->owner
;
3119 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3121 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3123 /* If we're reading a type unit, skip over the signature and
3124 type_offset fields. */
3125 if (signature
!= NULL
)
3126 *signature
= read_8_bytes (abfd
, info_ptr
);
3128 if (type_offset
!= NULL
)
3129 type_offset
->cu_off
= read_offset_1 (abfd
, info_ptr
, header
->offset_size
);
3130 info_ptr
+= header
->offset_size
;
3132 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3134 error_check_comp_unit_head (header
, section
);
3139 /* Allocate a new partial symtab for file named NAME and mark this new
3140 partial symtab as being an include of PST. */
3143 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
3144 struct objfile
*objfile
)
3146 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
3148 subpst
->section_offsets
= pst
->section_offsets
;
3149 subpst
->textlow
= 0;
3150 subpst
->texthigh
= 0;
3152 subpst
->dependencies
= (struct partial_symtab
**)
3153 obstack_alloc (&objfile
->objfile_obstack
,
3154 sizeof (struct partial_symtab
*));
3155 subpst
->dependencies
[0] = pst
;
3156 subpst
->number_of_dependencies
= 1;
3158 subpst
->globals_offset
= 0;
3159 subpst
->n_global_syms
= 0;
3160 subpst
->statics_offset
= 0;
3161 subpst
->n_static_syms
= 0;
3162 subpst
->symtab
= NULL
;
3163 subpst
->read_symtab
= pst
->read_symtab
;
3166 /* No private part is necessary for include psymtabs. This property
3167 can be used to differentiate between such include psymtabs and
3168 the regular ones. */
3169 subpst
->read_symtab_private
= NULL
;
3172 /* Read the Line Number Program data and extract the list of files
3173 included by the source file represented by PST. Build an include
3174 partial symtab for each of these included files. */
3177 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
3178 struct die_info
*die
,
3179 struct partial_symtab
*pst
)
3181 struct objfile
*objfile
= cu
->objfile
;
3182 bfd
*abfd
= objfile
->obfd
;
3183 struct line_header
*lh
= NULL
;
3184 struct attribute
*attr
;
3186 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3189 unsigned int line_offset
= DW_UNSND (attr
);
3191 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
3194 return; /* No linetable, so no includes. */
3196 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3197 dwarf_decode_lines (lh
, pst
->dirname
, cu
, pst
, 1);
3199 free_line_header (lh
);
3203 hash_signatured_type (const void *item
)
3205 const struct signatured_type
*sig_type
= item
;
3207 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3208 return sig_type
->signature
;
3212 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
3214 const struct signatured_type
*lhs
= item_lhs
;
3215 const struct signatured_type
*rhs
= item_rhs
;
3217 return lhs
->signature
== rhs
->signature
;
3220 /* Allocate a hash table for signatured types. */
3223 allocate_signatured_type_table (struct objfile
*objfile
)
3225 return htab_create_alloc_ex (41,
3226 hash_signatured_type
,
3229 &objfile
->objfile_obstack
,
3230 hashtab_obstack_allocate
,
3231 dummy_obstack_deallocate
);
3234 /* A helper function to add a signatured type CU to a table. */
3237 add_signatured_type_cu_to_table (void **slot
, void *datum
)
3239 struct signatured_type
*sigt
= *slot
;
3240 struct dwarf2_per_cu_data
***datap
= datum
;
3242 **datap
= &sigt
->per_cu
;
3248 /* Create the hash table of all entries in the .debug_types section(s).
3249 The result is zero if there are no .debug_types sections,
3250 otherwise non-zero. */
3253 create_all_type_units (struct objfile
*objfile
)
3255 htab_t types_htab
= NULL
;
3256 struct dwarf2_per_cu_data
**iter
;
3258 struct dwarf2_section_info
*section
;
3260 if (VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
))
3262 dwarf2_per_objfile
->signatured_types
= NULL
;
3267 VEC_iterate (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
3271 gdb_byte
*info_ptr
, *end_ptr
;
3273 dwarf2_read_section (objfile
, section
);
3274 info_ptr
= section
->buffer
;
3276 if (info_ptr
== NULL
)
3279 if (types_htab
== NULL
)
3280 types_htab
= allocate_signatured_type_table (objfile
);
3282 if (dwarf2_die_debug
)
3283 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
3285 end_ptr
= info_ptr
+ section
->size
;
3286 while (info_ptr
< end_ptr
)
3289 cu_offset type_offset
;
3291 struct signatured_type
*sig_type
;
3293 gdb_byte
*ptr
= info_ptr
;
3294 struct comp_unit_head header
;
3296 offset
.sect_off
= ptr
- section
->buffer
;
3298 /* We need to read the type's signature in order to build the hash
3299 table, but we don't need anything else just yet. */
3301 ptr
= read_and_check_type_unit_head (&header
, section
, ptr
,
3302 &signature
, &type_offset
);
3304 /* Skip dummy type units. */
3305 if (ptr
>= end_ptr
|| peek_abbrev_code (objfile
->obfd
, ptr
) == 0)
3307 info_ptr
= info_ptr
+ header
.initial_length_size
+ header
.length
;
3311 sig_type
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*sig_type
));
3312 memset (sig_type
, 0, sizeof (*sig_type
));
3313 sig_type
->signature
= signature
;
3314 sig_type
->type_offset
= type_offset
;
3315 sig_type
->per_cu
.objfile
= objfile
;
3316 sig_type
->per_cu
.debug_types_section
= section
;
3317 sig_type
->per_cu
.offset
= offset
;
3319 slot
= htab_find_slot (types_htab
, sig_type
, INSERT
);
3320 gdb_assert (slot
!= NULL
);
3323 const struct signatured_type
*dup_sig
= *slot
;
3325 complaint (&symfile_complaints
,
3326 _("debug type entry at offset 0x%x is duplicate to the "
3327 "entry at offset 0x%x, signature 0x%s"),
3328 offset
.sect_off
, dup_sig
->per_cu
.offset
.sect_off
,
3329 phex (signature
, sizeof (signature
)));
3330 gdb_assert (signature
== dup_sig
->signature
);
3334 if (dwarf2_die_debug
)
3335 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3337 phex (signature
, sizeof (signature
)));
3339 info_ptr
= info_ptr
+ header
.initial_length_size
+ header
.length
;
3343 dwarf2_per_objfile
->signatured_types
= types_htab
;
3345 dwarf2_per_objfile
->n_type_units
= htab_elements (types_htab
);
3346 dwarf2_per_objfile
->all_type_units
3347 = obstack_alloc (&objfile
->objfile_obstack
,
3348 dwarf2_per_objfile
->n_type_units
3349 * sizeof (struct dwarf2_per_cu_data
*));
3350 iter
= &dwarf2_per_objfile
->all_type_units
[0];
3351 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
3352 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
3353 == dwarf2_per_objfile
->n_type_units
);
3358 /* Lookup a signature based type for DW_FORM_ref_sig8.
3359 Returns NULL if signature SIG is not present in the table. */
3361 static struct signatured_type
*
3362 lookup_signatured_type (ULONGEST sig
)
3364 struct signatured_type find_entry
, *entry
;
3366 if (dwarf2_per_objfile
->signatured_types
== NULL
)
3368 complaint (&symfile_complaints
,
3369 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3373 find_entry
.signature
= sig
;
3374 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
3378 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3381 init_cu_die_reader (struct die_reader_specs
*reader
,
3382 struct dwarf2_cu
*cu
)
3384 reader
->abfd
= cu
->objfile
->obfd
;
3386 if (cu
->per_cu
->debug_types_section
)
3388 gdb_assert (cu
->per_cu
->debug_types_section
->readin
);
3389 reader
->buffer
= cu
->per_cu
->debug_types_section
->buffer
;
3393 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3394 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
3398 /* Find the base address of the compilation unit for range lists and
3399 location lists. It will normally be specified by DW_AT_low_pc.
3400 In DWARF-3 draft 4, the base address could be overridden by
3401 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3402 compilation units with discontinuous ranges. */
3405 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3407 struct attribute
*attr
;
3410 cu
->base_address
= 0;
3412 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3415 cu
->base_address
= DW_ADDR (attr
);
3420 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3423 cu
->base_address
= DW_ADDR (attr
);
3429 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
3430 to combine the common parts.
3431 Process compilation unit THIS_CU for a psymtab.
3432 SECTION is the section the CU/TU comes from,
3433 either .debug_info or .debug_types. */
3436 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
3437 struct dwarf2_section_info
*section
,
3438 int is_debug_types_section
)
3440 struct objfile
*objfile
= this_cu
->objfile
;
3441 bfd
*abfd
= objfile
->obfd
;
3442 gdb_byte
*buffer
= section
->buffer
;
3443 gdb_byte
*info_ptr
= buffer
+ this_cu
->offset
.sect_off
;
3444 unsigned int buffer_size
= section
->size
;
3445 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3446 struct die_info
*comp_unit_die
;
3447 struct partial_symtab
*pst
;
3449 struct cleanup
*back_to_inner
;
3450 struct dwarf2_cu cu
;
3451 int has_children
, has_pc_info
;
3452 struct attribute
*attr
;
3453 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
3454 struct die_reader_specs reader_specs
;
3455 const char *filename
;
3457 /* If this compilation unit was already read in, free the
3458 cached copy in order to read it in again. This is
3459 necessary because we skipped some symbols when we first
3460 read in the compilation unit (see load_partial_dies).
3461 This problem could be avoided, but the benefit is
3463 if (this_cu
->cu
!= NULL
)
3464 free_one_cached_comp_unit (this_cu
->cu
);
3466 /* Note that this is a pointer to our stack frame, being
3467 added to a global data structure. It will be cleaned up
3468 in free_stack_comp_unit when we finish with this
3469 compilation unit. */
3470 init_one_comp_unit (&cu
, this_cu
);
3471 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
3473 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
, info_ptr
,
3474 is_debug_types_section
);
3476 /* Skip dummy compilation units. */
3477 if (info_ptr
>= buffer
+ buffer_size
3478 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3480 do_cleanups (back_to_inner
);
3484 cu
.list_in_scope
= &file_symbols
;
3486 /* Read the abbrevs for this compilation unit into a table. */
3487 dwarf2_read_abbrevs (&cu
);
3488 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
3490 /* Read the compilation unit die. */
3491 init_cu_die_reader (&reader_specs
, &cu
);
3492 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3495 if (is_debug_types_section
)
3497 /* LENGTH has not been set yet for type units. */
3498 gdb_assert (this_cu
->offset
.sect_off
== cu
.header
.offset
.sect_off
);
3499 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
3501 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3503 do_cleanups (back_to_inner
);
3507 prepare_one_comp_unit (&cu
, comp_unit_die
);
3509 /* Allocate a new partial symbol table structure. */
3510 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
3511 if (attr
== NULL
|| !DW_STRING (attr
))
3514 filename
= DW_STRING (attr
);
3515 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
3517 /* TEXTLOW and TEXTHIGH are set below. */
3519 objfile
->global_psymbols
.next
,
3520 objfile
->static_psymbols
.next
);
3521 pst
->psymtabs_addrmap_supported
= 1;
3523 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
3525 pst
->dirname
= DW_STRING (attr
);
3527 pst
->read_symtab_private
= this_cu
;
3529 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3531 /* Store the function that reads in the rest of the symbol table. */
3532 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
3534 this_cu
->v
.psymtab
= pst
;
3536 dwarf2_find_base_address (comp_unit_die
, &cu
);
3538 /* Possibly set the default values of LOWPC and HIGHPC from
3540 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
3541 &best_highpc
, &cu
, pst
);
3542 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
3543 /* Store the contiguous range if it is not empty; it can be empty for
3544 CUs with no code. */
3545 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3546 best_lowpc
+ baseaddr
,
3547 best_highpc
+ baseaddr
- 1, pst
);
3549 /* Check if comp unit has_children.
3550 If so, read the rest of the partial symbols from this comp unit.
3551 If not, there's no more debug_info for this comp unit. */
3554 struct partial_die_info
*first_die
;
3555 CORE_ADDR lowpc
, highpc
;
3557 lowpc
= ((CORE_ADDR
) -1);
3558 highpc
= ((CORE_ADDR
) 0);
3560 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
3562 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
3563 ! has_pc_info
, &cu
);
3565 /* If we didn't find a lowpc, set it to highpc to avoid
3566 complaints from `maint check'. */
3567 if (lowpc
== ((CORE_ADDR
) -1))
3570 /* If the compilation unit didn't have an explicit address range,
3571 then use the information extracted from its child dies. */
3575 best_highpc
= highpc
;
3578 pst
->textlow
= best_lowpc
+ baseaddr
;
3579 pst
->texthigh
= best_highpc
+ baseaddr
;
3581 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
3582 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
3583 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
3584 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
3585 sort_pst_symbols (pst
);
3587 if (is_debug_types_section
)
3589 /* It's not clear we want to do anything with stmt lists here.
3590 Waiting to see what gcc ultimately does. */
3594 /* Get the list of files included in the current compilation unit,
3595 and build a psymtab for each of them. */
3596 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
3599 do_cleanups (back_to_inner
);
3602 /* Traversal function for htab_traverse_noresize.
3603 Process one .debug_types comp-unit. */
3606 process_type_comp_unit (void **slot
, void *info
)
3608 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
3609 struct dwarf2_per_cu_data
*this_cu
;
3611 gdb_assert (info
== NULL
);
3612 this_cu
= &entry
->per_cu
;
3614 gdb_assert (this_cu
->debug_types_section
->readin
);
3615 process_psymtab_comp_unit (this_cu
, this_cu
->debug_types_section
, 1);
3620 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3621 Build partial symbol tables for the .debug_types comp-units. */
3624 build_type_psymtabs (struct objfile
*objfile
)
3626 if (! create_all_type_units (objfile
))
3629 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
3630 process_type_comp_unit
, NULL
);
3633 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3636 psymtabs_addrmap_cleanup (void *o
)
3638 struct objfile
*objfile
= o
;
3640 objfile
->psymtabs_addrmap
= NULL
;
3643 /* Build the partial symbol table by doing a quick pass through the
3644 .debug_info and .debug_abbrev sections. */
3647 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
3649 struct cleanup
*back_to
, *addrmap_cleanup
;
3650 struct obstack temp_obstack
;
3653 dwarf2_per_objfile
->reading_partial_symbols
= 1;
3655 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3657 /* Any cached compilation units will be linked by the per-objfile
3658 read_in_chain. Make sure to free them when we're done. */
3659 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
3661 build_type_psymtabs (objfile
);
3663 create_all_comp_units (objfile
);
3665 /* Create a temporary address map on a temporary obstack. We later
3666 copy this to the final obstack. */
3667 obstack_init (&temp_obstack
);
3668 make_cleanup_obstack_free (&temp_obstack
);
3669 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
3670 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
3672 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3674 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3676 process_psymtab_comp_unit (per_cu
, &dwarf2_per_objfile
->info
, 0);
3679 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
3680 &objfile
->objfile_obstack
);
3681 discard_cleanups (addrmap_cleanup
);
3683 do_cleanups (back_to
);
3686 /* Load the partial DIEs for a secondary CU into memory. */
3689 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
3691 struct objfile
*objfile
= this_cu
->objfile
;
3692 bfd
*abfd
= objfile
->obfd
;
3694 struct die_info
*comp_unit_die
;
3695 struct dwarf2_cu
*cu
;
3696 struct cleanup
*free_abbrevs_cleanup
, *free_cu_cleanup
= NULL
;
3698 struct die_reader_specs reader_specs
;
3700 struct dwarf2_section_info
*section
= &dwarf2_per_objfile
->info
;
3702 gdb_assert (! this_cu
->debug_types_section
);
3704 gdb_assert (section
->readin
);
3705 info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
3707 if (this_cu
->cu
== NULL
)
3709 cu
= xmalloc (sizeof (*cu
));
3710 init_one_comp_unit (cu
, this_cu
);
3714 /* If an error occurs while loading, release our storage. */
3715 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
3717 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
, info_ptr
,
3720 /* Skip dummy compilation units. */
3721 if (info_ptr
>= (section
->buffer
+ section
->size
)
3722 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3724 do_cleanups (free_cu_cleanup
);
3731 info_ptr
+= cu
->header
.first_die_offset
.cu_off
;
3734 /* Read the abbrevs for this compilation unit into a table. */
3735 gdb_assert (cu
->dwarf2_abbrevs
== NULL
);
3736 dwarf2_read_abbrevs (cu
);
3737 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3739 /* Read the compilation unit die. */
3740 init_cu_die_reader (&reader_specs
, cu
);
3741 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3744 prepare_one_comp_unit (cu
, comp_unit_die
);
3746 /* Check if comp unit has_children.
3747 If so, read the rest of the partial symbols from this comp unit.
3748 If not, there's no more debug_info for this comp unit. */
3750 load_partial_dies (abfd
, section
->buffer
, info_ptr
, 0, cu
);
3752 do_cleanups (free_abbrevs_cleanup
);
3756 /* We've successfully allocated this compilation unit. Let our
3757 caller clean it up when finished with it. */
3758 discard_cleanups (free_cu_cleanup
);
3760 /* Link this CU into read_in_chain. */
3761 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3762 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3766 /* Create a list of all compilation units in OBJFILE.
3767 This is only done for -readnow and building partial symtabs. */
3770 create_all_comp_units (struct objfile
*objfile
)
3774 struct dwarf2_per_cu_data
**all_comp_units
;
3777 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3778 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3782 all_comp_units
= xmalloc (n_allocated
3783 * sizeof (struct dwarf2_per_cu_data
*));
3785 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
3786 + dwarf2_per_objfile
->info
.size
)
3788 unsigned int length
, initial_length_size
;
3789 struct dwarf2_per_cu_data
*this_cu
;
3792 offset
.sect_off
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
3794 /* Read just enough information to find out where the next
3795 compilation unit is. */
3796 length
= read_initial_length (objfile
->obfd
, info_ptr
,
3797 &initial_length_size
);
3799 /* Save the compilation unit for later lookup. */
3800 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
3801 sizeof (struct dwarf2_per_cu_data
));
3802 memset (this_cu
, 0, sizeof (*this_cu
));
3803 this_cu
->offset
= offset
;
3804 this_cu
->length
= length
+ initial_length_size
;
3805 this_cu
->objfile
= objfile
;
3807 if (n_comp_units
== n_allocated
)
3810 all_comp_units
= xrealloc (all_comp_units
,
3812 * sizeof (struct dwarf2_per_cu_data
*));
3814 all_comp_units
[n_comp_units
++] = this_cu
;
3816 info_ptr
= info_ptr
+ this_cu
->length
;
3819 dwarf2_per_objfile
->all_comp_units
3820 = obstack_alloc (&objfile
->objfile_obstack
,
3821 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3822 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
3823 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3824 xfree (all_comp_units
);
3825 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
3828 /* Process all loaded DIEs for compilation unit CU, starting at
3829 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3830 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3831 DW_AT_ranges). If NEED_PC is set, then this function will set
3832 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3833 and record the covered ranges in the addrmap. */
3836 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
3837 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3839 struct partial_die_info
*pdi
;
3841 /* Now, march along the PDI's, descending into ones which have
3842 interesting children but skipping the children of the other ones,
3843 until we reach the end of the compilation unit. */
3849 fixup_partial_die (pdi
, cu
);
3851 /* Anonymous namespaces or modules have no name but have interesting
3852 children, so we need to look at them. Ditto for anonymous
3855 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
3856 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
3860 case DW_TAG_subprogram
:
3861 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3863 case DW_TAG_constant
:
3864 case DW_TAG_variable
:
3865 case DW_TAG_typedef
:
3866 case DW_TAG_union_type
:
3867 if (!pdi
->is_declaration
)
3869 add_partial_symbol (pdi
, cu
);
3872 case DW_TAG_class_type
:
3873 case DW_TAG_interface_type
:
3874 case DW_TAG_structure_type
:
3875 if (!pdi
->is_declaration
)
3877 add_partial_symbol (pdi
, cu
);
3880 case DW_TAG_enumeration_type
:
3881 if (!pdi
->is_declaration
)
3882 add_partial_enumeration (pdi
, cu
);
3884 case DW_TAG_base_type
:
3885 case DW_TAG_subrange_type
:
3886 /* File scope base type definitions are added to the partial
3888 add_partial_symbol (pdi
, cu
);
3890 case DW_TAG_namespace
:
3891 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
3894 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
3901 /* If the die has a sibling, skip to the sibling. */
3903 pdi
= pdi
->die_sibling
;
3907 /* Functions used to compute the fully scoped name of a partial DIE.
3909 Normally, this is simple. For C++, the parent DIE's fully scoped
3910 name is concatenated with "::" and the partial DIE's name. For
3911 Java, the same thing occurs except that "." is used instead of "::".
3912 Enumerators are an exception; they use the scope of their parent
3913 enumeration type, i.e. the name of the enumeration type is not
3914 prepended to the enumerator.
3916 There are two complexities. One is DW_AT_specification; in this
3917 case "parent" means the parent of the target of the specification,
3918 instead of the direct parent of the DIE. The other is compilers
3919 which do not emit DW_TAG_namespace; in this case we try to guess
3920 the fully qualified name of structure types from their members'
3921 linkage names. This must be done using the DIE's children rather
3922 than the children of any DW_AT_specification target. We only need
3923 to do this for structures at the top level, i.e. if the target of
3924 any DW_AT_specification (if any; otherwise the DIE itself) does not
3927 /* Compute the scope prefix associated with PDI's parent, in
3928 compilation unit CU. The result will be allocated on CU's
3929 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3930 field. NULL is returned if no prefix is necessary. */
3932 partial_die_parent_scope (struct partial_die_info
*pdi
,
3933 struct dwarf2_cu
*cu
)
3935 char *grandparent_scope
;
3936 struct partial_die_info
*parent
, *real_pdi
;
3938 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3939 then this means the parent of the specification DIE. */
3942 while (real_pdi
->has_specification
)
3943 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3945 parent
= real_pdi
->die_parent
;
3949 if (parent
->scope_set
)
3950 return parent
->scope
;
3952 fixup_partial_die (parent
, cu
);
3954 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
3956 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3957 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3958 Work around this problem here. */
3959 if (cu
->language
== language_cplus
3960 && parent
->tag
== DW_TAG_namespace
3961 && strcmp (parent
->name
, "::") == 0
3962 && grandparent_scope
== NULL
)
3964 parent
->scope
= NULL
;
3965 parent
->scope_set
= 1;
3969 if (pdi
->tag
== DW_TAG_enumerator
)
3970 /* Enumerators should not get the name of the enumeration as a prefix. */
3971 parent
->scope
= grandparent_scope
;
3972 else if (parent
->tag
== DW_TAG_namespace
3973 || parent
->tag
== DW_TAG_module
3974 || parent
->tag
== DW_TAG_structure_type
3975 || parent
->tag
== DW_TAG_class_type
3976 || parent
->tag
== DW_TAG_interface_type
3977 || parent
->tag
== DW_TAG_union_type
3978 || parent
->tag
== DW_TAG_enumeration_type
)
3980 if (grandparent_scope
== NULL
)
3981 parent
->scope
= parent
->name
;
3983 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
3985 parent
->name
, 0, cu
);
3989 /* FIXME drow/2004-04-01: What should we be doing with
3990 function-local names? For partial symbols, we should probably be
3992 complaint (&symfile_complaints
,
3993 _("unhandled containing DIE tag %d for DIE at %d"),
3994 parent
->tag
, pdi
->offset
.sect_off
);
3995 parent
->scope
= grandparent_scope
;
3998 parent
->scope_set
= 1;
3999 return parent
->scope
;
4002 /* Return the fully scoped name associated with PDI, from compilation unit
4003 CU. The result will be allocated with malloc. */
4006 partial_die_full_name (struct partial_die_info
*pdi
,
4007 struct dwarf2_cu
*cu
)
4011 /* If this is a template instantiation, we can not work out the
4012 template arguments from partial DIEs. So, unfortunately, we have
4013 to go through the full DIEs. At least any work we do building
4014 types here will be reused if full symbols are loaded later. */
4015 if (pdi
->has_template_arguments
)
4017 fixup_partial_die (pdi
, cu
);
4019 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
4021 struct die_info
*die
;
4022 struct attribute attr
;
4023 struct dwarf2_cu
*ref_cu
= cu
;
4025 /* DW_FORM_ref_addr is using section offset. */
4027 attr
.form
= DW_FORM_ref_addr
;
4028 attr
.u
.unsnd
= pdi
->offset
.sect_off
;
4029 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
4031 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
4035 parent_scope
= partial_die_parent_scope (pdi
, cu
);
4036 if (parent_scope
== NULL
)
4039 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
4043 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
4045 struct objfile
*objfile
= cu
->objfile
;
4047 char *actual_name
= NULL
;
4049 int built_actual_name
= 0;
4051 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4053 actual_name
= partial_die_full_name (pdi
, cu
);
4055 built_actual_name
= 1;
4057 if (actual_name
== NULL
)
4058 actual_name
= pdi
->name
;
4062 case DW_TAG_subprogram
:
4063 if (pdi
->is_external
|| cu
->language
== language_ada
)
4065 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
4066 of the global scope. But in Ada, we want to be able to access
4067 nested procedures globally. So all Ada subprograms are stored
4068 in the global scope. */
4069 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4070 mst_text, objfile); */
4071 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4073 VAR_DOMAIN
, LOC_BLOCK
,
4074 &objfile
->global_psymbols
,
4075 0, pdi
->lowpc
+ baseaddr
,
4076 cu
->language
, objfile
);
4080 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4081 mst_file_text, objfile); */
4082 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4084 VAR_DOMAIN
, LOC_BLOCK
,
4085 &objfile
->static_psymbols
,
4086 0, pdi
->lowpc
+ baseaddr
,
4087 cu
->language
, objfile
);
4090 case DW_TAG_constant
:
4092 struct psymbol_allocation_list
*list
;
4094 if (pdi
->is_external
)
4095 list
= &objfile
->global_psymbols
;
4097 list
= &objfile
->static_psymbols
;
4098 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4099 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
4100 list
, 0, 0, cu
->language
, objfile
);
4103 case DW_TAG_variable
:
4105 addr
= decode_locdesc (pdi
->locdesc
, cu
);
4109 && !dwarf2_per_objfile
->has_section_at_zero
)
4111 /* A global or static variable may also have been stripped
4112 out by the linker if unused, in which case its address
4113 will be nullified; do not add such variables into partial
4114 symbol table then. */
4116 else if (pdi
->is_external
)
4119 Don't enter into the minimal symbol tables as there is
4120 a minimal symbol table entry from the ELF symbols already.
4121 Enter into partial symbol table if it has a location
4122 descriptor or a type.
4123 If the location descriptor is missing, new_symbol will create
4124 a LOC_UNRESOLVED symbol, the address of the variable will then
4125 be determined from the minimal symbol table whenever the variable
4127 The address for the partial symbol table entry is not
4128 used by GDB, but it comes in handy for debugging partial symbol
4131 if (pdi
->locdesc
|| pdi
->has_type
)
4132 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4134 VAR_DOMAIN
, LOC_STATIC
,
4135 &objfile
->global_psymbols
,
4137 cu
->language
, objfile
);
4141 /* Static Variable. Skip symbols without location descriptors. */
4142 if (pdi
->locdesc
== NULL
)
4144 if (built_actual_name
)
4145 xfree (actual_name
);
4148 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
4149 mst_file_data, objfile); */
4150 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4152 VAR_DOMAIN
, LOC_STATIC
,
4153 &objfile
->static_psymbols
,
4155 cu
->language
, objfile
);
4158 case DW_TAG_typedef
:
4159 case DW_TAG_base_type
:
4160 case DW_TAG_subrange_type
:
4161 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4163 VAR_DOMAIN
, LOC_TYPEDEF
,
4164 &objfile
->static_psymbols
,
4165 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4167 case DW_TAG_namespace
:
4168 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4170 VAR_DOMAIN
, LOC_TYPEDEF
,
4171 &objfile
->global_psymbols
,
4172 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4174 case DW_TAG_class_type
:
4175 case DW_TAG_interface_type
:
4176 case DW_TAG_structure_type
:
4177 case DW_TAG_union_type
:
4178 case DW_TAG_enumeration_type
:
4179 /* Skip external references. The DWARF standard says in the section
4180 about "Structure, Union, and Class Type Entries": "An incomplete
4181 structure, union or class type is represented by a structure,
4182 union or class entry that does not have a byte size attribute
4183 and that has a DW_AT_declaration attribute." */
4184 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
4186 if (built_actual_name
)
4187 xfree (actual_name
);
4191 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
4192 static vs. global. */
4193 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4195 STRUCT_DOMAIN
, LOC_TYPEDEF
,
4196 (cu
->language
== language_cplus
4197 || cu
->language
== language_java
)
4198 ? &objfile
->global_psymbols
4199 : &objfile
->static_psymbols
,
4200 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4203 case DW_TAG_enumerator
:
4204 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4206 VAR_DOMAIN
, LOC_CONST
,
4207 (cu
->language
== language_cplus
4208 || cu
->language
== language_java
)
4209 ? &objfile
->global_psymbols
4210 : &objfile
->static_psymbols
,
4211 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4217 if (built_actual_name
)
4218 xfree (actual_name
);
4221 /* Read a partial die corresponding to a namespace; also, add a symbol
4222 corresponding to that namespace to the symbol table. NAMESPACE is
4223 the name of the enclosing namespace. */
4226 add_partial_namespace (struct partial_die_info
*pdi
,
4227 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4228 int need_pc
, struct dwarf2_cu
*cu
)
4230 /* Add a symbol for the namespace. */
4232 add_partial_symbol (pdi
, cu
);
4234 /* Now scan partial symbols in that namespace. */
4236 if (pdi
->has_children
)
4237 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4240 /* Read a partial die corresponding to a Fortran module. */
4243 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
4244 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4246 /* Now scan partial symbols in that module. */
4248 if (pdi
->has_children
)
4249 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4252 /* Read a partial die corresponding to a subprogram and create a partial
4253 symbol for that subprogram. When the CU language allows it, this
4254 routine also defines a partial symbol for each nested subprogram
4255 that this subprogram contains.
4257 DIE my also be a lexical block, in which case we simply search
4258 recursively for suprograms defined inside that lexical block.
4259 Again, this is only performed when the CU language allows this
4260 type of definitions. */
4263 add_partial_subprogram (struct partial_die_info
*pdi
,
4264 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4265 int need_pc
, struct dwarf2_cu
*cu
)
4267 if (pdi
->tag
== DW_TAG_subprogram
)
4269 if (pdi
->has_pc_info
)
4271 if (pdi
->lowpc
< *lowpc
)
4272 *lowpc
= pdi
->lowpc
;
4273 if (pdi
->highpc
> *highpc
)
4274 *highpc
= pdi
->highpc
;
4278 struct objfile
*objfile
= cu
->objfile
;
4280 baseaddr
= ANOFFSET (objfile
->section_offsets
,
4281 SECT_OFF_TEXT (objfile
));
4282 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4283 pdi
->lowpc
+ baseaddr
,
4284 pdi
->highpc
- 1 + baseaddr
,
4285 cu
->per_cu
->v
.psymtab
);
4289 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
4291 if (!pdi
->is_declaration
)
4292 /* Ignore subprogram DIEs that do not have a name, they are
4293 illegal. Do not emit a complaint at this point, we will
4294 do so when we convert this psymtab into a symtab. */
4296 add_partial_symbol (pdi
, cu
);
4300 if (! pdi
->has_children
)
4303 if (cu
->language
== language_ada
)
4305 pdi
= pdi
->die_child
;
4308 fixup_partial_die (pdi
, cu
);
4309 if (pdi
->tag
== DW_TAG_subprogram
4310 || pdi
->tag
== DW_TAG_lexical_block
)
4311 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4312 pdi
= pdi
->die_sibling
;
4317 /* Read a partial die corresponding to an enumeration type. */
4320 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
4321 struct dwarf2_cu
*cu
)
4323 struct partial_die_info
*pdi
;
4325 if (enum_pdi
->name
!= NULL
)
4326 add_partial_symbol (enum_pdi
, cu
);
4328 pdi
= enum_pdi
->die_child
;
4331 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
4332 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
4334 add_partial_symbol (pdi
, cu
);
4335 pdi
= pdi
->die_sibling
;
4339 /* Return the initial uleb128 in the die at INFO_PTR. */
4342 peek_abbrev_code (bfd
*abfd
, gdb_byte
*info_ptr
)
4344 unsigned int bytes_read
;
4346 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4349 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4350 Return the corresponding abbrev, or NULL if the number is zero (indicating
4351 an empty DIE). In either case *BYTES_READ will be set to the length of
4352 the initial number. */
4354 static struct abbrev_info
*
4355 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
4356 struct dwarf2_cu
*cu
)
4358 bfd
*abfd
= cu
->objfile
->obfd
;
4359 unsigned int abbrev_number
;
4360 struct abbrev_info
*abbrev
;
4362 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
4364 if (abbrev_number
== 0)
4367 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4370 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4371 abbrev_number
, bfd_get_filename (abfd
));
4377 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4378 Returns a pointer to the end of a series of DIEs, terminated by an empty
4379 DIE. Any children of the skipped DIEs will also be skipped. */
4382 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
4384 struct abbrev_info
*abbrev
;
4385 unsigned int bytes_read
;
4389 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
4391 return info_ptr
+ bytes_read
;
4393 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
4397 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4398 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4399 abbrev corresponding to that skipped uleb128 should be passed in
4400 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4404 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4405 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
4407 unsigned int bytes_read
;
4408 struct attribute attr
;
4409 bfd
*abfd
= cu
->objfile
->obfd
;
4410 unsigned int form
, i
;
4412 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
4414 /* The only abbrev we care about is DW_AT_sibling. */
4415 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
4417 read_attribute (&attr
, &abbrev
->attrs
[i
],
4418 abfd
, info_ptr
, cu
);
4419 if (attr
.form
== DW_FORM_ref_addr
)
4420 complaint (&symfile_complaints
,
4421 _("ignoring absolute DW_AT_sibling"));
4423 return buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
4426 /* If it isn't DW_AT_sibling, skip this attribute. */
4427 form
= abbrev
->attrs
[i
].form
;
4431 case DW_FORM_ref_addr
:
4432 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4433 and later it is offset sized. */
4434 if (cu
->header
.version
== 2)
4435 info_ptr
+= cu
->header
.addr_size
;
4437 info_ptr
+= cu
->header
.offset_size
;
4440 info_ptr
+= cu
->header
.addr_size
;
4447 case DW_FORM_flag_present
:
4459 case DW_FORM_ref_sig8
:
4462 case DW_FORM_string
:
4463 read_direct_string (abfd
, info_ptr
, &bytes_read
);
4464 info_ptr
+= bytes_read
;
4466 case DW_FORM_sec_offset
:
4468 info_ptr
+= cu
->header
.offset_size
;
4470 case DW_FORM_exprloc
:
4472 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4473 info_ptr
+= bytes_read
;
4475 case DW_FORM_block1
:
4476 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
4478 case DW_FORM_block2
:
4479 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
4481 case DW_FORM_block4
:
4482 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
4486 case DW_FORM_ref_udata
:
4487 info_ptr
= skip_leb128 (abfd
, info_ptr
);
4489 case DW_FORM_indirect
:
4490 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4491 info_ptr
+= bytes_read
;
4492 /* We need to continue parsing from here, so just go back to
4494 goto skip_attribute
;
4497 error (_("Dwarf Error: Cannot handle %s "
4498 "in DWARF reader [in module %s]"),
4499 dwarf_form_name (form
),
4500 bfd_get_filename (abfd
));
4504 if (abbrev
->has_children
)
4505 return skip_children (buffer
, info_ptr
, cu
);
4510 /* Locate ORIG_PDI's sibling.
4511 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4515 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
4516 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4517 bfd
*abfd
, struct dwarf2_cu
*cu
)
4519 /* Do we know the sibling already? */
4521 if (orig_pdi
->sibling
)
4522 return orig_pdi
->sibling
;
4524 /* Are there any children to deal with? */
4526 if (!orig_pdi
->has_children
)
4529 /* Skip the children the long way. */
4531 return skip_children (buffer
, info_ptr
, cu
);
4534 /* Expand this partial symbol table into a full symbol table. */
4537 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
4543 warning (_("bug: psymtab for %s is already read in."),
4550 printf_filtered (_("Reading in symbols for %s..."),
4552 gdb_flush (gdb_stdout
);
4555 /* Restore our global data. */
4556 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
4557 dwarf2_objfile_data_key
);
4559 /* If this psymtab is constructed from a debug-only objfile, the
4560 has_section_at_zero flag will not necessarily be correct. We
4561 can get the correct value for this flag by looking at the data
4562 associated with the (presumably stripped) associated objfile. */
4563 if (pst
->objfile
->separate_debug_objfile_backlink
)
4565 struct dwarf2_per_objfile
*dpo_backlink
4566 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
4567 dwarf2_objfile_data_key
);
4569 dwarf2_per_objfile
->has_section_at_zero
4570 = dpo_backlink
->has_section_at_zero
;
4573 dwarf2_per_objfile
->reading_partial_symbols
= 0;
4575 psymtab_to_symtab_1 (pst
);
4577 /* Finish up the debug error message. */
4579 printf_filtered (_("done.\n"));
4584 /* Reading in full CUs. */
4586 /* Add PER_CU to the queue. */
4589 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4591 struct dwarf2_queue_item
*item
;
4594 item
= xmalloc (sizeof (*item
));
4595 item
->per_cu
= per_cu
;
4598 if (dwarf2_queue
== NULL
)
4599 dwarf2_queue
= item
;
4601 dwarf2_queue_tail
->next
= item
;
4603 dwarf2_queue_tail
= item
;
4606 /* Process the queue. */
4609 process_queue (void)
4611 struct dwarf2_queue_item
*item
, *next_item
;
4613 /* The queue starts out with one item, but following a DIE reference
4614 may load a new CU, adding it to the end of the queue. */
4615 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
4617 if (dwarf2_per_objfile
->using_index
4618 ? !item
->per_cu
->v
.quick
->symtab
4619 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
4620 process_full_comp_unit (item
->per_cu
);
4622 item
->per_cu
->queued
= 0;
4623 next_item
= item
->next
;
4627 dwarf2_queue_tail
= NULL
;
4630 /* Free all allocated queue entries. This function only releases anything if
4631 an error was thrown; if the queue was processed then it would have been
4632 freed as we went along. */
4635 dwarf2_release_queue (void *dummy
)
4637 struct dwarf2_queue_item
*item
, *last
;
4639 item
= dwarf2_queue
;
4642 /* Anything still marked queued is likely to be in an
4643 inconsistent state, so discard it. */
4644 if (item
->per_cu
->queued
)
4646 if (item
->per_cu
->cu
!= NULL
)
4647 free_one_cached_comp_unit (item
->per_cu
->cu
);
4648 item
->per_cu
->queued
= 0;
4656 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
4659 /* Read in full symbols for PST, and anything it depends on. */
4662 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
4664 struct dwarf2_per_cu_data
*per_cu
;
4665 struct cleanup
*back_to
;
4668 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
4669 if (!pst
->dependencies
[i
]->readin
)
4671 /* Inform about additional files that need to be read in. */
4674 /* FIXME: i18n: Need to make this a single string. */
4675 fputs_filtered (" ", gdb_stdout
);
4677 fputs_filtered ("and ", gdb_stdout
);
4679 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
4680 wrap_here (""); /* Flush output. */
4681 gdb_flush (gdb_stdout
);
4683 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
4686 per_cu
= pst
->read_symtab_private
;
4690 /* It's an include file, no symbols to read for it.
4691 Everything is in the parent symtab. */
4696 dw2_do_instantiate_symtab (per_cu
);
4699 /* Load the DIEs associated with PER_CU into memory. */
4702 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4704 struct objfile
*objfile
= per_cu
->objfile
;
4705 bfd
*abfd
= objfile
->obfd
;
4706 struct dwarf2_cu
*cu
;
4708 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
4709 struct cleanup
*free_cu_cleanup
= NULL
;
4710 struct attribute
*attr
;
4713 gdb_assert (! per_cu
->debug_types_section
);
4715 /* Set local variables from the partial symbol table info. */
4716 offset
= per_cu
->offset
;
4718 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4719 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
.sect_off
;
4720 beg_of_comp_unit
= info_ptr
;
4722 if (per_cu
->cu
== NULL
)
4724 cu
= xmalloc (sizeof (*cu
));
4725 init_one_comp_unit (cu
, per_cu
);
4729 /* If an error occurs while loading, release our storage. */
4730 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
4732 /* Read in the comp_unit header. */
4733 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
4735 /* Skip dummy compilation units. */
4736 if (info_ptr
>= (dwarf2_per_objfile
->info
.buffer
4737 + dwarf2_per_objfile
->info
.size
)
4738 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4740 do_cleanups (free_cu_cleanup
);
4744 /* Complete the cu_header. */
4745 cu
->header
.offset
= offset
;
4746 cu
->header
.first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
4751 info_ptr
+= cu
->header
.first_die_offset
.cu_off
;
4754 cu
->dies
= read_comp_unit (info_ptr
, cu
);
4756 /* We try not to read any attributes in this function, because not
4757 all CUs needed for references have been loaded yet, and symbol
4758 table processing isn't initialized. But we have to set the CU language,
4759 or we won't be able to build types correctly. */
4760 prepare_one_comp_unit (cu
, cu
->dies
);
4762 /* Similarly, if we do not read the producer, we can not apply
4763 producer-specific interpretation. */
4764 attr
= dwarf2_attr (cu
->dies
, DW_AT_producer
, cu
);
4766 cu
->producer
= DW_STRING (attr
);
4770 /* We've successfully allocated this compilation unit. Let our
4771 caller clean it up when finished with it. */
4772 discard_cleanups (free_cu_cleanup
);
4774 /* Link this CU into read_in_chain. */
4775 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4776 dwarf2_per_objfile
->read_in_chain
= per_cu
;
4780 /* Add a DIE to the delayed physname list. */
4783 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
4784 const char *name
, struct die_info
*die
,
4785 struct dwarf2_cu
*cu
)
4787 struct delayed_method_info mi
;
4789 mi
.fnfield_index
= fnfield_index
;
4793 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
4796 /* A cleanup for freeing the delayed method list. */
4799 free_delayed_list (void *ptr
)
4801 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
4802 if (cu
->method_list
!= NULL
)
4804 VEC_free (delayed_method_info
, cu
->method_list
);
4805 cu
->method_list
= NULL
;
4809 /* Compute the physnames of any methods on the CU's method list.
4811 The computation of method physnames is delayed in order to avoid the
4812 (bad) condition that one of the method's formal parameters is of an as yet
4816 compute_delayed_physnames (struct dwarf2_cu
*cu
)
4819 struct delayed_method_info
*mi
;
4820 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
4822 const char *physname
;
4823 struct fn_fieldlist
*fn_flp
4824 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
4825 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
4826 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
4830 /* Go objects should be embedded in a DW_TAG_module DIE,
4831 and it's not clear if/how imported objects will appear.
4832 To keep Go support simple until that's worked out,
4833 go back through what we've read and create something usable.
4834 We could do this while processing each DIE, and feels kinda cleaner,
4835 but that way is more invasive.
4836 This is to, for example, allow the user to type "p var" or "b main"
4837 without having to specify the package name, and allow lookups
4838 of module.object to work in contexts that use the expression
4842 fixup_go_packaging (struct dwarf2_cu
*cu
)
4844 char *package_name
= NULL
;
4845 struct pending
*list
;
4848 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
4850 for (i
= 0; i
< list
->nsyms
; ++i
)
4852 struct symbol
*sym
= list
->symbol
[i
];
4854 if (SYMBOL_LANGUAGE (sym
) == language_go
4855 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
4857 char *this_package_name
= go_symbol_package_name (sym
);
4859 if (this_package_name
== NULL
)
4861 if (package_name
== NULL
)
4862 package_name
= this_package_name
;
4865 if (strcmp (package_name
, this_package_name
) != 0)
4866 complaint (&symfile_complaints
,
4867 _("Symtab %s has objects from two different Go packages: %s and %s"),
4868 (sym
->symtab
&& sym
->symtab
->filename
4869 ? sym
->symtab
->filename
4870 : cu
->objfile
->name
),
4871 this_package_name
, package_name
);
4872 xfree (this_package_name
);
4878 if (package_name
!= NULL
)
4880 struct objfile
*objfile
= cu
->objfile
;
4881 struct type
*type
= init_type (TYPE_CODE_MODULE
, 0, 0,
4882 package_name
, objfile
);
4885 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
4887 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
4888 SYMBOL_SET_LANGUAGE (sym
, language_go
);
4889 SYMBOL_SET_NAMES (sym
, package_name
, strlen (package_name
), 1, objfile
);
4890 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
4891 e.g., "main" finds the "main" module and not C's main(). */
4892 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
4893 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4894 SYMBOL_TYPE (sym
) = type
;
4896 add_symbol_to_list (sym
, &global_symbols
);
4898 xfree (package_name
);
4902 /* Generate full symbol information for PER_CU, whose DIEs have
4903 already been loaded into memory. */
4906 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4908 struct dwarf2_cu
*cu
= per_cu
->cu
;
4909 struct objfile
*objfile
= per_cu
->objfile
;
4910 CORE_ADDR lowpc
, highpc
;
4911 struct symtab
*symtab
;
4912 struct cleanup
*back_to
, *delayed_list_cleanup
;
4915 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4918 back_to
= make_cleanup (really_free_pendings
, NULL
);
4919 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
4921 cu
->list_in_scope
= &file_symbols
;
4923 /* Do line number decoding in read_file_scope () */
4924 process_die (cu
->dies
, cu
);
4926 /* For now fudge the Go package. */
4927 if (cu
->language
== language_go
)
4928 fixup_go_packaging (cu
);
4930 /* Now that we have processed all the DIEs in the CU, all the types
4931 should be complete, and it should now be safe to compute all of the
4933 compute_delayed_physnames (cu
);
4934 do_cleanups (delayed_list_cleanup
);
4936 /* Some compilers don't define a DW_AT_high_pc attribute for the
4937 compilation unit. If the DW_AT_high_pc is missing, synthesize
4938 it, by scanning the DIE's below the compilation unit. */
4939 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
4941 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
4945 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
4947 /* Set symtab language to language from DW_AT_language. If the
4948 compilation is from a C file generated by language preprocessors, do
4949 not set the language if it was already deduced by start_subfile. */
4950 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
4951 symtab
->language
= cu
->language
;
4953 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
4954 produce DW_AT_location with location lists but it can be possibly
4955 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
4956 there were bugs in prologue debug info, fixed later in GCC-4.5
4957 by "unwind info for epilogues" patch (which is not directly related).
4959 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
4960 needed, it would be wrong due to missing DW_AT_producer there.
4962 Still one can confuse GDB by using non-standard GCC compilation
4963 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
4965 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
4966 symtab
->locations_valid
= 1;
4968 if (gcc_4_minor
>= 5)
4969 symtab
->epilogue_unwind_valid
= 1;
4971 symtab
->call_site_htab
= cu
->call_site_htab
;
4974 if (dwarf2_per_objfile
->using_index
)
4975 per_cu
->v
.quick
->symtab
= symtab
;
4978 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4979 pst
->symtab
= symtab
;
4983 do_cleanups (back_to
);
4986 /* Process a die and its children. */
4989 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
4993 case DW_TAG_padding
:
4995 case DW_TAG_compile_unit
:
4996 read_file_scope (die
, cu
);
4998 case DW_TAG_type_unit
:
4999 read_type_unit_scope (die
, cu
);
5001 case DW_TAG_subprogram
:
5002 case DW_TAG_inlined_subroutine
:
5003 read_func_scope (die
, cu
);
5005 case DW_TAG_lexical_block
:
5006 case DW_TAG_try_block
:
5007 case DW_TAG_catch_block
:
5008 read_lexical_block_scope (die
, cu
);
5010 case DW_TAG_GNU_call_site
:
5011 read_call_site_scope (die
, cu
);
5013 case DW_TAG_class_type
:
5014 case DW_TAG_interface_type
:
5015 case DW_TAG_structure_type
:
5016 case DW_TAG_union_type
:
5017 process_structure_scope (die
, cu
);
5019 case DW_TAG_enumeration_type
:
5020 process_enumeration_scope (die
, cu
);
5023 /* These dies have a type, but processing them does not create
5024 a symbol or recurse to process the children. Therefore we can
5025 read them on-demand through read_type_die. */
5026 case DW_TAG_subroutine_type
:
5027 case DW_TAG_set_type
:
5028 case DW_TAG_array_type
:
5029 case DW_TAG_pointer_type
:
5030 case DW_TAG_ptr_to_member_type
:
5031 case DW_TAG_reference_type
:
5032 case DW_TAG_string_type
:
5035 case DW_TAG_base_type
:
5036 case DW_TAG_subrange_type
:
5037 case DW_TAG_typedef
:
5038 /* Add a typedef symbol for the type definition, if it has a
5040 new_symbol (die
, read_type_die (die
, cu
), cu
);
5042 case DW_TAG_common_block
:
5043 read_common_block (die
, cu
);
5045 case DW_TAG_common_inclusion
:
5047 case DW_TAG_namespace
:
5048 processing_has_namespace_info
= 1;
5049 read_namespace (die
, cu
);
5052 processing_has_namespace_info
= 1;
5053 read_module (die
, cu
);
5055 case DW_TAG_imported_declaration
:
5056 case DW_TAG_imported_module
:
5057 processing_has_namespace_info
= 1;
5058 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
5059 || cu
->language
!= language_fortran
))
5060 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
5061 dwarf_tag_name (die
->tag
));
5062 read_import_statement (die
, cu
);
5065 new_symbol (die
, NULL
, cu
);
5070 /* A helper function for dwarf2_compute_name which determines whether DIE
5071 needs to have the name of the scope prepended to the name listed in the
5075 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
5077 struct attribute
*attr
;
5081 case DW_TAG_namespace
:
5082 case DW_TAG_typedef
:
5083 case DW_TAG_class_type
:
5084 case DW_TAG_interface_type
:
5085 case DW_TAG_structure_type
:
5086 case DW_TAG_union_type
:
5087 case DW_TAG_enumeration_type
:
5088 case DW_TAG_enumerator
:
5089 case DW_TAG_subprogram
:
5093 case DW_TAG_variable
:
5094 case DW_TAG_constant
:
5095 /* We only need to prefix "globally" visible variables. These include
5096 any variable marked with DW_AT_external or any variable that
5097 lives in a namespace. [Variables in anonymous namespaces
5098 require prefixing, but they are not DW_AT_external.] */
5100 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
5102 struct dwarf2_cu
*spec_cu
= cu
;
5104 return die_needs_namespace (die_specification (die
, &spec_cu
),
5108 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5109 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
5110 && die
->parent
->tag
!= DW_TAG_module
)
5112 /* A variable in a lexical block of some kind does not need a
5113 namespace, even though in C++ such variables may be external
5114 and have a mangled name. */
5115 if (die
->parent
->tag
== DW_TAG_lexical_block
5116 || die
->parent
->tag
== DW_TAG_try_block
5117 || die
->parent
->tag
== DW_TAG_catch_block
5118 || die
->parent
->tag
== DW_TAG_subprogram
)
5127 /* Retrieve the last character from a mem_file. */
5130 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
5132 char *last_char_p
= (char *) object
;
5135 *last_char_p
= buffer
[length
- 1];
5138 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
5139 compute the physname for the object, which include a method's:
5140 - formal parameters (C++/Java),
5141 - receiver type (Go),
5142 - return type (Java).
5144 The term "physname" is a bit confusing.
5145 For C++, for example, it is the demangled name.
5146 For Go, for example, it's the mangled name.
5148 For Ada, return the DIE's linkage name rather than the fully qualified
5149 name. PHYSNAME is ignored..
5151 The result is allocated on the objfile_obstack and canonicalized. */
5154 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
5157 struct objfile
*objfile
= cu
->objfile
;
5160 name
= dwarf2_name (die
, cu
);
5162 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
5163 compute it by typename_concat inside GDB. */
5164 if (cu
->language
== language_ada
5165 || (cu
->language
== language_fortran
&& physname
))
5167 /* For Ada unit, we prefer the linkage name over the name, as
5168 the former contains the exported name, which the user expects
5169 to be able to reference. Ideally, we want the user to be able
5170 to reference this entity using either natural or linkage name,
5171 but we haven't started looking at this enhancement yet. */
5172 struct attribute
*attr
;
5174 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5176 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5177 if (attr
&& DW_STRING (attr
))
5178 return DW_STRING (attr
);
5181 /* These are the only languages we know how to qualify names in. */
5183 && (cu
->language
== language_cplus
|| cu
->language
== language_java
5184 || cu
->language
== language_fortran
))
5186 if (die_needs_namespace (die
, cu
))
5190 struct ui_file
*buf
;
5192 prefix
= determine_prefix (die
, cu
);
5193 buf
= mem_fileopen ();
5194 if (*prefix
!= '\0')
5196 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
5199 fputs_unfiltered (prefixed_name
, buf
);
5200 xfree (prefixed_name
);
5203 fputs_unfiltered (name
, buf
);
5205 /* Template parameters may be specified in the DIE's DW_AT_name, or
5206 as children with DW_TAG_template_type_param or
5207 DW_TAG_value_type_param. If the latter, add them to the name
5208 here. If the name already has template parameters, then
5209 skip this step; some versions of GCC emit both, and
5210 it is more efficient to use the pre-computed name.
5212 Something to keep in mind about this process: it is very
5213 unlikely, or in some cases downright impossible, to produce
5214 something that will match the mangled name of a function.
5215 If the definition of the function has the same debug info,
5216 we should be able to match up with it anyway. But fallbacks
5217 using the minimal symbol, for instance to find a method
5218 implemented in a stripped copy of libstdc++, will not work.
5219 If we do not have debug info for the definition, we will have to
5220 match them up some other way.
5222 When we do name matching there is a related problem with function
5223 templates; two instantiated function templates are allowed to
5224 differ only by their return types, which we do not add here. */
5226 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
5228 struct attribute
*attr
;
5229 struct die_info
*child
;
5232 die
->building_fullname
= 1;
5234 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
5239 struct dwarf2_locexpr_baton
*baton
;
5242 if (child
->tag
!= DW_TAG_template_type_param
5243 && child
->tag
!= DW_TAG_template_value_param
)
5248 fputs_unfiltered ("<", buf
);
5252 fputs_unfiltered (", ", buf
);
5254 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
5257 complaint (&symfile_complaints
,
5258 _("template parameter missing DW_AT_type"));
5259 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
5262 type
= die_type (child
, cu
);
5264 if (child
->tag
== DW_TAG_template_type_param
)
5266 c_print_type (type
, "", buf
, -1, 0);
5270 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
5273 complaint (&symfile_complaints
,
5274 _("template parameter missing "
5275 "DW_AT_const_value"));
5276 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
5280 dwarf2_const_value_attr (attr
, type
, name
,
5281 &cu
->comp_unit_obstack
, cu
,
5282 &value
, &bytes
, &baton
);
5284 if (TYPE_NOSIGN (type
))
5285 /* GDB prints characters as NUMBER 'CHAR'. If that's
5286 changed, this can use value_print instead. */
5287 c_printchar (value
, type
, buf
);
5290 struct value_print_options opts
;
5293 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
5297 else if (bytes
!= NULL
)
5299 v
= allocate_value (type
);
5300 memcpy (value_contents_writeable (v
), bytes
,
5301 TYPE_LENGTH (type
));
5304 v
= value_from_longest (type
, value
);
5306 /* Specify decimal so that we do not depend on
5308 get_formatted_print_options (&opts
, 'd');
5310 value_print (v
, buf
, &opts
);
5316 die
->building_fullname
= 0;
5320 /* Close the argument list, with a space if necessary
5321 (nested templates). */
5322 char last_char
= '\0';
5323 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
5324 if (last_char
== '>')
5325 fputs_unfiltered (" >", buf
);
5327 fputs_unfiltered (">", buf
);
5331 /* For Java and C++ methods, append formal parameter type
5332 information, if PHYSNAME. */
5334 if (physname
&& die
->tag
== DW_TAG_subprogram
5335 && (cu
->language
== language_cplus
5336 || cu
->language
== language_java
))
5338 struct type
*type
= read_type_die (die
, cu
);
5340 c_type_print_args (type
, buf
, 1, cu
->language
);
5342 if (cu
->language
== language_java
)
5344 /* For java, we must append the return type to method
5346 if (die
->tag
== DW_TAG_subprogram
)
5347 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
5350 else if (cu
->language
== language_cplus
)
5352 /* Assume that an artificial first parameter is
5353 "this", but do not crash if it is not. RealView
5354 marks unnamed (and thus unused) parameters as
5355 artificial; there is no way to differentiate
5357 if (TYPE_NFIELDS (type
) > 0
5358 && TYPE_FIELD_ARTIFICIAL (type
, 0)
5359 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
5360 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
5362 fputs_unfiltered (" const", buf
);
5366 name
= ui_file_obsavestring (buf
, &objfile
->objfile_obstack
,
5368 ui_file_delete (buf
);
5370 if (cu
->language
== language_cplus
)
5373 = dwarf2_canonicalize_name (name
, cu
,
5374 &objfile
->objfile_obstack
);
5385 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5386 If scope qualifiers are appropriate they will be added. The result
5387 will be allocated on the objfile_obstack, or NULL if the DIE does
5388 not have a name. NAME may either be from a previous call to
5389 dwarf2_name or NULL.
5391 The output string will be canonicalized (if C++/Java). */
5394 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5396 return dwarf2_compute_name (name
, die
, cu
, 0);
5399 /* Construct a physname for the given DIE in CU. NAME may either be
5400 from a previous call to dwarf2_name or NULL. The result will be
5401 allocated on the objfile_objstack or NULL if the DIE does not have a
5404 The output string will be canonicalized (if C++/Java). */
5407 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5409 struct objfile
*objfile
= cu
->objfile
;
5410 struct attribute
*attr
;
5411 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
5412 struct cleanup
*back_to
;
5415 /* In this case dwarf2_compute_name is just a shortcut not building anything
5417 if (!die_needs_namespace (die
, cu
))
5418 return dwarf2_compute_name (name
, die
, cu
, 1);
5420 back_to
= make_cleanup (null_cleanup
, NULL
);
5422 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5424 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5426 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
5428 if (attr
&& DW_STRING (attr
))
5432 mangled
= DW_STRING (attr
);
5434 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
5435 type. It is easier for GDB users to search for such functions as
5436 `name(params)' than `long name(params)'. In such case the minimal
5437 symbol names do not match the full symbol names but for template
5438 functions there is never a need to look up their definition from their
5439 declaration so the only disadvantage remains the minimal symbol
5440 variant `long name(params)' does not have the proper inferior type.
5443 if (cu
->language
== language_go
)
5445 /* This is a lie, but we already lie to the caller new_symbol_full.
5446 new_symbol_full assumes we return the mangled name.
5447 This just undoes that lie until things are cleaned up. */
5452 demangled
= cplus_demangle (mangled
,
5453 (DMGL_PARAMS
| DMGL_ANSI
5454 | (cu
->language
== language_java
5455 ? DMGL_JAVA
| DMGL_RET_POSTFIX
5460 make_cleanup (xfree
, demangled
);
5470 if (canon
== NULL
|| check_physname
)
5472 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
5474 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
5476 /* It may not mean a bug in GDB. The compiler could also
5477 compute DW_AT_linkage_name incorrectly. But in such case
5478 GDB would need to be bug-to-bug compatible. */
5480 complaint (&symfile_complaints
,
5481 _("Computed physname <%s> does not match demangled <%s> "
5482 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
5483 physname
, canon
, mangled
, die
->offset
.sect_off
, objfile
->name
);
5485 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
5486 is available here - over computed PHYSNAME. It is safer
5487 against both buggy GDB and buggy compilers. */
5501 retval
= obsavestring (retval
, strlen (retval
),
5502 &objfile
->objfile_obstack
);
5504 do_cleanups (back_to
);
5508 /* Read the import statement specified by the given die and record it. */
5511 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
5513 struct objfile
*objfile
= cu
->objfile
;
5514 struct attribute
*import_attr
;
5515 struct die_info
*imported_die
, *child_die
;
5516 struct dwarf2_cu
*imported_cu
;
5517 const char *imported_name
;
5518 const char *imported_name_prefix
;
5519 const char *canonical_name
;
5520 const char *import_alias
;
5521 const char *imported_declaration
= NULL
;
5522 const char *import_prefix
;
5523 VEC (const_char_ptr
) *excludes
= NULL
;
5524 struct cleanup
*cleanups
;
5528 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
5529 if (import_attr
== NULL
)
5531 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5532 dwarf_tag_name (die
->tag
));
5537 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
5538 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5539 if (imported_name
== NULL
)
5541 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
5543 The import in the following code:
5557 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
5558 <52> DW_AT_decl_file : 1
5559 <53> DW_AT_decl_line : 6
5560 <54> DW_AT_import : <0x75>
5561 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
5563 <5b> DW_AT_decl_file : 1
5564 <5c> DW_AT_decl_line : 2
5565 <5d> DW_AT_type : <0x6e>
5567 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
5568 <76> DW_AT_byte_size : 4
5569 <77> DW_AT_encoding : 5 (signed)
5571 imports the wrong die ( 0x75 instead of 0x58 ).
5572 This case will be ignored until the gcc bug is fixed. */
5576 /* Figure out the local name after import. */
5577 import_alias
= dwarf2_name (die
, cu
);
5579 /* Figure out where the statement is being imported to. */
5580 import_prefix
= determine_prefix (die
, cu
);
5582 /* Figure out what the scope of the imported die is and prepend it
5583 to the name of the imported die. */
5584 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
5586 if (imported_die
->tag
!= DW_TAG_namespace
5587 && imported_die
->tag
!= DW_TAG_module
)
5589 imported_declaration
= imported_name
;
5590 canonical_name
= imported_name_prefix
;
5592 else if (strlen (imported_name_prefix
) > 0)
5594 temp
= alloca (strlen (imported_name_prefix
)
5595 + 2 + strlen (imported_name
) + 1);
5596 strcpy (temp
, imported_name_prefix
);
5597 strcat (temp
, "::");
5598 strcat (temp
, imported_name
);
5599 canonical_name
= temp
;
5602 canonical_name
= imported_name
;
5604 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
5606 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
5607 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
5608 child_die
= sibling_die (child_die
))
5610 /* DWARF-4: A Fortran use statement with a “rename list” may be
5611 represented by an imported module entry with an import attribute
5612 referring to the module and owned entries corresponding to those
5613 entities that are renamed as part of being imported. */
5615 if (child_die
->tag
!= DW_TAG_imported_declaration
)
5617 complaint (&symfile_complaints
,
5618 _("child DW_TAG_imported_declaration expected "
5619 "- DIE at 0x%x [in module %s]"),
5620 child_die
->offset
.sect_off
, objfile
->name
);
5624 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
5625 if (import_attr
== NULL
)
5627 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5628 dwarf_tag_name (child_die
->tag
));
5633 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
5635 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5636 if (imported_name
== NULL
)
5638 complaint (&symfile_complaints
,
5639 _("child DW_TAG_imported_declaration has unknown "
5640 "imported name - DIE at 0x%x [in module %s]"),
5641 child_die
->offset
.sect_off
, objfile
->name
);
5645 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
5647 process_die (child_die
, cu
);
5650 cp_add_using_directive (import_prefix
,
5653 imported_declaration
,
5655 &objfile
->objfile_obstack
);
5657 do_cleanups (cleanups
);
5660 /* Cleanup function for read_file_scope. */
5663 free_cu_line_header (void *arg
)
5665 struct dwarf2_cu
*cu
= arg
;
5667 free_line_header (cu
->line_header
);
5668 cu
->line_header
= NULL
;
5672 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
5673 char **name
, char **comp_dir
)
5675 struct attribute
*attr
;
5680 /* Find the filename. Do not use dwarf2_name here, since the filename
5681 is not a source language identifier. */
5682 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5685 *name
= DW_STRING (attr
);
5688 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5690 *comp_dir
= DW_STRING (attr
);
5691 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
5693 *comp_dir
= ldirname (*name
);
5694 if (*comp_dir
!= NULL
)
5695 make_cleanup (xfree
, *comp_dir
);
5697 if (*comp_dir
!= NULL
)
5699 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5700 directory, get rid of it. */
5701 char *cp
= strchr (*comp_dir
, ':');
5703 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
5708 *name
= "<unknown>";
5711 /* Handle DW_AT_stmt_list for a compilation unit or type unit.
5712 DIE is the DW_TAG_compile_unit or DW_TAG_type_unit die for CU.
5713 COMP_DIR is the compilation directory.
5714 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
5717 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
5718 const char *comp_dir
, int want_line_info
)
5720 struct attribute
*attr
;
5721 struct objfile
*objfile
= cu
->objfile
;
5722 bfd
*abfd
= objfile
->obfd
;
5724 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5727 unsigned int line_offset
= DW_UNSND (attr
);
5728 struct line_header
*line_header
5729 = dwarf_decode_line_header (line_offset
, abfd
, cu
);
5733 cu
->line_header
= line_header
;
5734 make_cleanup (free_cu_line_header
, cu
);
5735 dwarf_decode_lines (line_header
, comp_dir
, cu
, NULL
, want_line_info
);
5740 /* Process DW_TAG_compile_unit. */
5743 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5745 struct objfile
*objfile
= cu
->objfile
;
5746 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5747 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
5748 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
5749 struct attribute
*attr
;
5751 char *comp_dir
= NULL
;
5752 struct die_info
*child_die
;
5753 bfd
*abfd
= objfile
->obfd
;
5756 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5758 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
5760 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5761 from finish_block. */
5762 if (lowpc
== ((CORE_ADDR
) -1))
5767 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
5769 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5772 set_cu_language (DW_UNSND (attr
), cu
);
5775 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5777 cu
->producer
= DW_STRING (attr
);
5779 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
5780 standardised yet. As a workaround for the language detection we fall
5781 back to the DW_AT_producer string. */
5782 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
5783 cu
->language
= language_opencl
;
5785 /* Similar hack for Go. */
5786 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
5787 set_cu_language (DW_LANG_Go
, cu
);
5789 /* We assume that we're processing GCC output. */
5790 processing_gcc_compilation
= 2;
5792 processing_has_namespace_info
= 0;
5794 start_symtab (name
, comp_dir
, lowpc
);
5795 record_debugformat ("DWARF 2");
5796 record_producer (cu
->producer
);
5798 /* Decode line number information if present. We do this before
5799 processing child DIEs, so that the line header table is available
5800 for DW_AT_decl_file. */
5801 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, 1);
5803 /* Process all dies in compilation unit. */
5804 if (die
->child
!= NULL
)
5806 child_die
= die
->child
;
5807 while (child_die
&& child_die
->tag
)
5809 process_die (child_die
, cu
);
5810 child_die
= sibling_die (child_die
);
5814 /* Decode macro information, if present. Dwarf 2 macro information
5815 refers to information in the line number info statement program
5816 header, so we can only read it if we've read the header
5818 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
5819 if (attr
&& cu
->line_header
)
5821 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
5822 complaint (&symfile_complaints
,
5823 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
5825 dwarf_decode_macros (cu
->line_header
, DW_UNSND (attr
),
5827 &dwarf2_per_objfile
->macro
, 1);
5831 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
5832 if (attr
&& cu
->line_header
)
5834 unsigned int macro_offset
= DW_UNSND (attr
);
5836 dwarf_decode_macros (cu
->line_header
, macro_offset
,
5838 &dwarf2_per_objfile
->macinfo
, 0);
5842 do_cleanups (back_to
);
5845 /* Process DW_TAG_type_unit.
5846 For TUs we want to skip the first top level sibling if it's not the
5847 actual type being defined by this TU. In this case the first top
5848 level sibling is there to provide context only. */
5851 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5853 struct objfile
*objfile
= cu
->objfile
;
5854 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5856 struct attribute
*attr
;
5858 char *comp_dir
= NULL
;
5859 struct die_info
*child_die
;
5860 bfd
*abfd
= objfile
->obfd
;
5862 /* start_symtab needs a low pc, but we don't really have one.
5863 Do what read_file_scope would do in the absence of such info. */
5864 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5866 /* Find the filename. Do not use dwarf2_name here, since the filename
5867 is not a source language identifier. */
5868 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5870 name
= DW_STRING (attr
);
5872 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5874 comp_dir
= DW_STRING (attr
);
5875 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
5877 comp_dir
= ldirname (name
);
5878 if (comp_dir
!= NULL
)
5879 make_cleanup (xfree
, comp_dir
);
5885 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5887 set_cu_language (DW_UNSND (attr
), cu
);
5889 /* This isn't technically needed today. It is done for symmetry
5890 with read_file_scope. */
5891 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5893 cu
->producer
= DW_STRING (attr
);
5895 /* We assume that we're processing GCC output. */
5896 processing_gcc_compilation
= 2;
5898 processing_has_namespace_info
= 0;
5900 start_symtab (name
, comp_dir
, lowpc
);
5901 record_debugformat ("DWARF 2");
5902 record_producer (cu
->producer
);
5904 /* Decode line number information if present. We do this before
5905 processing child DIEs, so that the line header table is available
5906 for DW_AT_decl_file.
5907 We don't need the pc/line-number mapping for type units. */
5908 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, 0);
5910 /* Process the dies in the type unit. */
5911 if (die
->child
== NULL
)
5913 dump_die_for_error (die
);
5914 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5915 bfd_get_filename (abfd
));
5918 child_die
= die
->child
;
5920 while (child_die
&& child_die
->tag
)
5922 process_die (child_die
, cu
);
5924 child_die
= sibling_die (child_die
);
5927 do_cleanups (back_to
);
5930 /* qsort helper for inherit_abstract_dies. */
5933 unsigned_int_compar (const void *ap
, const void *bp
)
5935 unsigned int a
= *(unsigned int *) ap
;
5936 unsigned int b
= *(unsigned int *) bp
;
5938 return (a
> b
) - (b
> a
);
5941 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5942 Inherit only the children of the DW_AT_abstract_origin DIE not being
5943 already referenced by DW_AT_abstract_origin from the children of the
5947 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
5949 struct die_info
*child_die
;
5950 unsigned die_children_count
;
5951 /* CU offsets which were referenced by children of the current DIE. */
5952 sect_offset
*offsets
;
5953 sect_offset
*offsets_end
, *offsetp
;
5954 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5955 struct die_info
*origin_die
;
5956 /* Iterator of the ORIGIN_DIE children. */
5957 struct die_info
*origin_child_die
;
5958 struct cleanup
*cleanups
;
5959 struct attribute
*attr
;
5960 struct dwarf2_cu
*origin_cu
;
5961 struct pending
**origin_previous_list_in_scope
;
5963 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
5967 /* Note that following die references may follow to a die in a
5971 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
5973 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5975 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
5976 origin_cu
->list_in_scope
= cu
->list_in_scope
;
5978 if (die
->tag
!= origin_die
->tag
5979 && !(die
->tag
== DW_TAG_inlined_subroutine
5980 && origin_die
->tag
== DW_TAG_subprogram
))
5981 complaint (&symfile_complaints
,
5982 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5983 die
->offset
.sect_off
, origin_die
->offset
.sect_off
);
5985 child_die
= die
->child
;
5986 die_children_count
= 0;
5987 while (child_die
&& child_die
->tag
)
5989 child_die
= sibling_die (child_die
);
5990 die_children_count
++;
5992 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
5993 cleanups
= make_cleanup (xfree
, offsets
);
5995 offsets_end
= offsets
;
5996 child_die
= die
->child
;
5997 while (child_die
&& child_die
->tag
)
5999 /* For each CHILD_DIE, find the corresponding child of
6000 ORIGIN_DIE. If there is more than one layer of
6001 DW_AT_abstract_origin, follow them all; there shouldn't be,
6002 but GCC versions at least through 4.4 generate this (GCC PR
6004 struct die_info
*child_origin_die
= child_die
;
6005 struct dwarf2_cu
*child_origin_cu
= cu
;
6009 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
6013 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
6017 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
6018 counterpart may exist. */
6019 if (child_origin_die
!= child_die
)
6021 if (child_die
->tag
!= child_origin_die
->tag
6022 && !(child_die
->tag
== DW_TAG_inlined_subroutine
6023 && child_origin_die
->tag
== DW_TAG_subprogram
))
6024 complaint (&symfile_complaints
,
6025 _("Child DIE 0x%x and its abstract origin 0x%x have "
6026 "different tags"), child_die
->offset
.sect_off
,
6027 child_origin_die
->offset
.sect_off
);
6028 if (child_origin_die
->parent
!= origin_die
)
6029 complaint (&symfile_complaints
,
6030 _("Child DIE 0x%x and its abstract origin 0x%x have "
6031 "different parents"), child_die
->offset
.sect_off
,
6032 child_origin_die
->offset
.sect_off
);
6034 *offsets_end
++ = child_origin_die
->offset
;
6036 child_die
= sibling_die (child_die
);
6038 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
6039 unsigned_int_compar
);
6040 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
6041 if (offsetp
[-1].sect_off
== offsetp
->sect_off
)
6042 complaint (&symfile_complaints
,
6043 _("Multiple children of DIE 0x%x refer "
6044 "to DIE 0x%x as their abstract origin"),
6045 die
->offset
.sect_off
, offsetp
->sect_off
);
6048 origin_child_die
= origin_die
->child
;
6049 while (origin_child_die
&& origin_child_die
->tag
)
6051 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
6052 while (offsetp
< offsets_end
6053 && offsetp
->sect_off
< origin_child_die
->offset
.sect_off
)
6055 if (offsetp
>= offsets_end
6056 || offsetp
->sect_off
> origin_child_die
->offset
.sect_off
)
6058 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
6059 process_die (origin_child_die
, origin_cu
);
6061 origin_child_die
= sibling_die (origin_child_die
);
6063 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
6065 do_cleanups (cleanups
);
6069 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6071 struct objfile
*objfile
= cu
->objfile
;
6072 struct context_stack
*new;
6075 struct die_info
*child_die
;
6076 struct attribute
*attr
, *call_line
, *call_file
;
6079 struct block
*block
;
6080 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
6081 VEC (symbolp
) *template_args
= NULL
;
6082 struct template_symbol
*templ_func
= NULL
;
6086 /* If we do not have call site information, we can't show the
6087 caller of this inlined function. That's too confusing, so
6088 only use the scope for local variables. */
6089 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
6090 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
6091 if (call_line
== NULL
|| call_file
== NULL
)
6093 read_lexical_block_scope (die
, cu
);
6098 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6100 name
= dwarf2_name (die
, cu
);
6102 /* Ignore functions with missing or empty names. These are actually
6103 illegal according to the DWARF standard. */
6106 complaint (&symfile_complaints
,
6107 _("missing name for subprogram DIE at %d"),
6108 die
->offset
.sect_off
);
6112 /* Ignore functions with missing or invalid low and high pc attributes. */
6113 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
6115 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
6116 if (!attr
|| !DW_UNSND (attr
))
6117 complaint (&symfile_complaints
,
6118 _("cannot get low and high bounds "
6119 "for subprogram DIE at %d"),
6120 die
->offset
.sect_off
);
6127 /* If we have any template arguments, then we must allocate a
6128 different sort of symbol. */
6129 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
6131 if (child_die
->tag
== DW_TAG_template_type_param
6132 || child_die
->tag
== DW_TAG_template_value_param
)
6134 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6135 struct template_symbol
);
6136 templ_func
->base
.is_cplus_template_function
= 1;
6141 new = push_context (0, lowpc
);
6142 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
6143 (struct symbol
*) templ_func
);
6145 /* If there is a location expression for DW_AT_frame_base, record
6147 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
6149 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
6150 expression is being recorded directly in the function's symbol
6151 and not in a separate frame-base object. I guess this hack is
6152 to avoid adding some sort of frame-base adjunct/annex to the
6153 function's symbol :-(. The problem with doing this is that it
6154 results in a function symbol with a location expression that
6155 has nothing to do with the location of the function, ouch! The
6156 relationship should be: a function's symbol has-a frame base; a
6157 frame-base has-a location expression. */
6158 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
6160 cu
->list_in_scope
= &local_symbols
;
6162 if (die
->child
!= NULL
)
6164 child_die
= die
->child
;
6165 while (child_die
&& child_die
->tag
)
6167 if (child_die
->tag
== DW_TAG_template_type_param
6168 || child_die
->tag
== DW_TAG_template_value_param
)
6170 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
6173 VEC_safe_push (symbolp
, template_args
, arg
);
6176 process_die (child_die
, cu
);
6177 child_die
= sibling_die (child_die
);
6181 inherit_abstract_dies (die
, cu
);
6183 /* If we have a DW_AT_specification, we might need to import using
6184 directives from the context of the specification DIE. See the
6185 comment in determine_prefix. */
6186 if (cu
->language
== language_cplus
6187 && dwarf2_attr (die
, DW_AT_specification
, cu
))
6189 struct dwarf2_cu
*spec_cu
= cu
;
6190 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
6194 child_die
= spec_die
->child
;
6195 while (child_die
&& child_die
->tag
)
6197 if (child_die
->tag
== DW_TAG_imported_module
)
6198 process_die (child_die
, spec_cu
);
6199 child_die
= sibling_die (child_die
);
6202 /* In some cases, GCC generates specification DIEs that
6203 themselves contain DW_AT_specification attributes. */
6204 spec_die
= die_specification (spec_die
, &spec_cu
);
6208 new = pop_context ();
6209 /* Make a block for the local symbols within. */
6210 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
6211 lowpc
, highpc
, objfile
);
6213 /* For C++, set the block's scope. */
6214 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
6215 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
6216 determine_prefix (die
, cu
),
6217 processing_has_namespace_info
);
6219 /* If we have address ranges, record them. */
6220 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
6222 /* Attach template arguments to function. */
6223 if (! VEC_empty (symbolp
, template_args
))
6225 gdb_assert (templ_func
!= NULL
);
6227 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
6228 templ_func
->template_arguments
6229 = obstack_alloc (&objfile
->objfile_obstack
,
6230 (templ_func
->n_template_arguments
6231 * sizeof (struct symbol
*)));
6232 memcpy (templ_func
->template_arguments
,
6233 VEC_address (symbolp
, template_args
),
6234 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
6235 VEC_free (symbolp
, template_args
);
6238 /* In C++, we can have functions nested inside functions (e.g., when
6239 a function declares a class that has methods). This means that
6240 when we finish processing a function scope, we may need to go
6241 back to building a containing block's symbol lists. */
6242 local_symbols
= new->locals
;
6243 param_symbols
= new->params
;
6244 using_directives
= new->using_directives
;
6246 /* If we've finished processing a top-level function, subsequent
6247 symbols go in the file symbol list. */
6248 if (outermost_context_p ())
6249 cu
->list_in_scope
= &file_symbols
;
6252 /* Process all the DIES contained within a lexical block scope. Start
6253 a new scope, process the dies, and then close the scope. */
6256 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6258 struct objfile
*objfile
= cu
->objfile
;
6259 struct context_stack
*new;
6260 CORE_ADDR lowpc
, highpc
;
6261 struct die_info
*child_die
;
6264 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6266 /* Ignore blocks with missing or invalid low and high pc attributes. */
6267 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
6268 as multiple lexical blocks? Handling children in a sane way would
6269 be nasty. Might be easier to properly extend generic blocks to
6271 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
6276 push_context (0, lowpc
);
6277 if (die
->child
!= NULL
)
6279 child_die
= die
->child
;
6280 while (child_die
&& child_die
->tag
)
6282 process_die (child_die
, cu
);
6283 child_die
= sibling_die (child_die
);
6286 new = pop_context ();
6288 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
6291 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
6294 /* Note that recording ranges after traversing children, as we
6295 do here, means that recording a parent's ranges entails
6296 walking across all its children's ranges as they appear in
6297 the address map, which is quadratic behavior.
6299 It would be nicer to record the parent's ranges before
6300 traversing its children, simply overriding whatever you find
6301 there. But since we don't even decide whether to create a
6302 block until after we've traversed its children, that's hard
6304 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
6306 local_symbols
= new->locals
;
6307 using_directives
= new->using_directives
;
6310 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
6313 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6315 struct objfile
*objfile
= cu
->objfile
;
6316 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6317 CORE_ADDR pc
, baseaddr
;
6318 struct attribute
*attr
;
6319 struct call_site
*call_site
, call_site_local
;
6322 struct die_info
*child_die
;
6324 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6326 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6329 complaint (&symfile_complaints
,
6330 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
6331 "DIE 0x%x [in module %s]"),
6332 die
->offset
.sect_off
, objfile
->name
);
6335 pc
= DW_ADDR (attr
) + baseaddr
;
6337 if (cu
->call_site_htab
== NULL
)
6338 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
6339 NULL
, &objfile
->objfile_obstack
,
6340 hashtab_obstack_allocate
, NULL
);
6341 call_site_local
.pc
= pc
;
6342 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
6345 complaint (&symfile_complaints
,
6346 _("Duplicate PC %s for DW_TAG_GNU_call_site "
6347 "DIE 0x%x [in module %s]"),
6348 paddress (gdbarch
, pc
), die
->offset
.sect_off
, objfile
->name
);
6352 /* Count parameters at the caller. */
6355 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
6356 child_die
= sibling_die (child_die
))
6358 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
6360 complaint (&symfile_complaints
,
6361 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
6362 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6363 child_die
->tag
, child_die
->offset
.sect_off
, objfile
->name
);
6370 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
6371 (sizeof (*call_site
)
6372 + (sizeof (*call_site
->parameter
)
6375 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
6378 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
6380 struct die_info
*func_die
;
6382 /* Skip also over DW_TAG_inlined_subroutine. */
6383 for (func_die
= die
->parent
;
6384 func_die
&& func_die
->tag
!= DW_TAG_subprogram
6385 && func_die
->tag
!= DW_TAG_subroutine_type
;
6386 func_die
= func_die
->parent
);
6388 /* DW_AT_GNU_all_call_sites is a superset
6389 of DW_AT_GNU_all_tail_call_sites. */
6391 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
6392 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
6394 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
6395 not complete. But keep CALL_SITE for look ups via call_site_htab,
6396 both the initial caller containing the real return address PC and
6397 the final callee containing the current PC of a chain of tail
6398 calls do not need to have the tail call list complete. But any
6399 function candidate for a virtual tail call frame searched via
6400 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
6401 determined unambiguously. */
6405 struct type
*func_type
= NULL
;
6408 func_type
= get_die_type (func_die
, cu
);
6409 if (func_type
!= NULL
)
6411 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
6413 /* Enlist this call site to the function. */
6414 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
6415 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
6418 complaint (&symfile_complaints
,
6419 _("Cannot find function owning DW_TAG_GNU_call_site "
6420 "DIE 0x%x [in module %s]"),
6421 die
->offset
.sect_off
, objfile
->name
);
6425 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
6427 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
6428 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
6429 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
6430 /* Keep NULL DWARF_BLOCK. */;
6431 else if (attr_form_is_block (attr
))
6433 struct dwarf2_locexpr_baton
*dlbaton
;
6435 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
6436 dlbaton
->data
= DW_BLOCK (attr
)->data
;
6437 dlbaton
->size
= DW_BLOCK (attr
)->size
;
6438 dlbaton
->per_cu
= cu
->per_cu
;
6440 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
6442 else if (is_ref_attr (attr
))
6444 struct dwarf2_cu
*target_cu
= cu
;
6445 struct die_info
*target_die
;
6447 target_die
= follow_die_ref_or_sig (die
, attr
, &target_cu
);
6448 gdb_assert (target_cu
->objfile
== objfile
);
6449 if (die_is_declaration (target_die
, target_cu
))
6451 const char *target_physname
;
6453 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
6454 if (target_physname
== NULL
)
6455 complaint (&symfile_complaints
,
6456 _("DW_AT_GNU_call_site_target target DIE has invalid "
6457 "physname, for referencing DIE 0x%x [in module %s]"),
6458 die
->offset
.sect_off
, objfile
->name
);
6460 SET_FIELD_PHYSNAME (call_site
->target
, (char *) target_physname
);
6466 /* DW_AT_entry_pc should be preferred. */
6467 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
6468 complaint (&symfile_complaints
,
6469 _("DW_AT_GNU_call_site_target target DIE has invalid "
6470 "low pc, for referencing DIE 0x%x [in module %s]"),
6471 die
->offset
.sect_off
, objfile
->name
);
6473 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
6477 complaint (&symfile_complaints
,
6478 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
6479 "block nor reference, for DIE 0x%x [in module %s]"),
6480 die
->offset
.sect_off
, objfile
->name
);
6482 call_site
->per_cu
= cu
->per_cu
;
6484 for (child_die
= die
->child
;
6485 child_die
&& child_die
->tag
;
6486 child_die
= sibling_die (child_die
))
6488 struct dwarf2_locexpr_baton
*dlbaton
;
6489 struct call_site_parameter
*parameter
;
6491 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
6493 /* Already printed the complaint above. */
6497 gdb_assert (call_site
->parameter_count
< nparams
);
6498 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
6500 /* DW_AT_location specifies the register number. Value of the data
6501 assumed for the register is contained in DW_AT_GNU_call_site_value. */
6503 attr
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
6504 if (!attr
|| !attr_form_is_block (attr
))
6506 complaint (&symfile_complaints
,
6507 _("No DW_FORM_block* DW_AT_location for "
6508 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6509 child_die
->offset
.sect_off
, objfile
->name
);
6512 parameter
->dwarf_reg
= dwarf_block_to_dwarf_reg (DW_BLOCK (attr
)->data
,
6513 &DW_BLOCK (attr
)->data
[DW_BLOCK (attr
)->size
]);
6514 if (parameter
->dwarf_reg
== -1
6515 && !dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (attr
)->data
,
6516 &DW_BLOCK (attr
)->data
[DW_BLOCK (attr
)->size
],
6517 ¶meter
->fb_offset
))
6519 complaint (&symfile_complaints
,
6520 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
6521 "for DW_FORM_block* DW_AT_location for "
6522 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6523 child_die
->offset
.sect_off
, objfile
->name
);
6527 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
6528 if (!attr_form_is_block (attr
))
6530 complaint (&symfile_complaints
,
6531 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
6532 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6533 child_die
->offset
.sect_off
, objfile
->name
);
6536 parameter
->value
= DW_BLOCK (attr
)->data
;
6537 parameter
->value_size
= DW_BLOCK (attr
)->size
;
6539 /* Parameters are not pre-cleared by memset above. */
6540 parameter
->data_value
= NULL
;
6541 parameter
->data_value_size
= 0;
6542 call_site
->parameter_count
++;
6544 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
6547 if (!attr_form_is_block (attr
))
6548 complaint (&symfile_complaints
,
6549 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
6550 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6551 child_die
->offset
.sect_off
, objfile
->name
);
6554 parameter
->data_value
= DW_BLOCK (attr
)->data
;
6555 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
6561 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
6562 Return 1 if the attributes are present and valid, otherwise, return 0.
6563 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
6566 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
6567 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
6568 struct partial_symtab
*ranges_pst
)
6570 struct objfile
*objfile
= cu
->objfile
;
6571 struct comp_unit_head
*cu_header
= &cu
->header
;
6572 bfd
*obfd
= objfile
->obfd
;
6573 unsigned int addr_size
= cu_header
->addr_size
;
6574 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6575 /* Base address selection entry. */
6586 found_base
= cu
->base_known
;
6587 base
= cu
->base_address
;
6589 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
6590 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6592 complaint (&symfile_complaints
,
6593 _("Offset %d out of bounds for DW_AT_ranges attribute"),
6597 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6599 /* Read in the largest possible address. */
6600 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
6601 if ((marker
& mask
) == mask
)
6603 /* If we found the largest possible address, then
6604 read the base address. */
6605 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
6606 buffer
+= 2 * addr_size
;
6607 offset
+= 2 * addr_size
;
6613 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6617 CORE_ADDR range_beginning
, range_end
;
6619 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
6620 buffer
+= addr_size
;
6621 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
6622 buffer
+= addr_size
;
6623 offset
+= 2 * addr_size
;
6625 /* An end of list marker is a pair of zero addresses. */
6626 if (range_beginning
== 0 && range_end
== 0)
6627 /* Found the end of list entry. */
6630 /* Each base address selection entry is a pair of 2 values.
6631 The first is the largest possible address, the second is
6632 the base address. Check for a base address here. */
6633 if ((range_beginning
& mask
) == mask
)
6635 /* If we found the largest possible address, then
6636 read the base address. */
6637 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
6644 /* We have no valid base address for the ranges
6646 complaint (&symfile_complaints
,
6647 _("Invalid .debug_ranges data (no base address)"));
6651 if (range_beginning
> range_end
)
6653 /* Inverted range entries are invalid. */
6654 complaint (&symfile_complaints
,
6655 _("Invalid .debug_ranges data (inverted range)"));
6659 /* Empty range entries have no effect. */
6660 if (range_beginning
== range_end
)
6663 range_beginning
+= base
;
6666 if (ranges_pst
!= NULL
)
6667 addrmap_set_empty (objfile
->psymtabs_addrmap
,
6668 range_beginning
+ baseaddr
,
6669 range_end
- 1 + baseaddr
,
6672 /* FIXME: This is recording everything as a low-high
6673 segment of consecutive addresses. We should have a
6674 data structure for discontiguous block ranges
6678 low
= range_beginning
;
6684 if (range_beginning
< low
)
6685 low
= range_beginning
;
6686 if (range_end
> high
)
6692 /* If the first entry is an end-of-list marker, the range
6693 describes an empty scope, i.e. no instructions. */
6699 *high_return
= high
;
6703 /* Get low and high pc attributes from a die. Return 1 if the attributes
6704 are present and valid, otherwise, return 0. Return -1 if the range is
6705 discontinuous, i.e. derived from DW_AT_ranges information. */
6708 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
6709 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
6710 struct partial_symtab
*pst
)
6712 struct attribute
*attr
;
6713 struct attribute
*attr_high
;
6718 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6721 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6724 low
= DW_ADDR (attr
);
6725 if (attr_high
->form
== DW_FORM_addr
)
6726 high
= DW_ADDR (attr_high
);
6728 high
= low
+ DW_UNSND (attr_high
);
6731 /* Found high w/o low attribute. */
6734 /* Found consecutive range of addresses. */
6739 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6742 /* Value of the DW_AT_ranges attribute is the offset in the
6743 .debug_ranges section. */
6744 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
6746 /* Found discontinuous range of addresses. */
6751 /* read_partial_die has also the strict LOW < HIGH requirement. */
6755 /* When using the GNU linker, .gnu.linkonce. sections are used to
6756 eliminate duplicate copies of functions and vtables and such.
6757 The linker will arbitrarily choose one and discard the others.
6758 The AT_*_pc values for such functions refer to local labels in
6759 these sections. If the section from that file was discarded, the
6760 labels are not in the output, so the relocs get a value of 0.
6761 If this is a discarded function, mark the pc bounds as invalid,
6762 so that GDB will ignore it. */
6763 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
6772 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
6773 its low and high PC addresses. Do nothing if these addresses could not
6774 be determined. Otherwise, set LOWPC to the low address if it is smaller,
6775 and HIGHPC to the high address if greater than HIGHPC. */
6778 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
6779 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6780 struct dwarf2_cu
*cu
)
6782 CORE_ADDR low
, high
;
6783 struct die_info
*child
= die
->child
;
6785 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
6787 *lowpc
= min (*lowpc
, low
);
6788 *highpc
= max (*highpc
, high
);
6791 /* If the language does not allow nested subprograms (either inside
6792 subprograms or lexical blocks), we're done. */
6793 if (cu
->language
!= language_ada
)
6796 /* Check all the children of the given DIE. If it contains nested
6797 subprograms, then check their pc bounds. Likewise, we need to
6798 check lexical blocks as well, as they may also contain subprogram
6800 while (child
&& child
->tag
)
6802 if (child
->tag
== DW_TAG_subprogram
6803 || child
->tag
== DW_TAG_lexical_block
)
6804 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
6805 child
= sibling_die (child
);
6809 /* Get the low and high pc's represented by the scope DIE, and store
6810 them in *LOWPC and *HIGHPC. If the correct values can't be
6811 determined, set *LOWPC to -1 and *HIGHPC to 0. */
6814 get_scope_pc_bounds (struct die_info
*die
,
6815 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6816 struct dwarf2_cu
*cu
)
6818 CORE_ADDR best_low
= (CORE_ADDR
) -1;
6819 CORE_ADDR best_high
= (CORE_ADDR
) 0;
6820 CORE_ADDR current_low
, current_high
;
6822 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
6824 best_low
= current_low
;
6825 best_high
= current_high
;
6829 struct die_info
*child
= die
->child
;
6831 while (child
&& child
->tag
)
6833 switch (child
->tag
) {
6834 case DW_TAG_subprogram
:
6835 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
6837 case DW_TAG_namespace
:
6839 /* FIXME: carlton/2004-01-16: Should we do this for
6840 DW_TAG_class_type/DW_TAG_structure_type, too? I think
6841 that current GCC's always emit the DIEs corresponding
6842 to definitions of methods of classes as children of a
6843 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
6844 the DIEs giving the declarations, which could be
6845 anywhere). But I don't see any reason why the
6846 standards says that they have to be there. */
6847 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
6849 if (current_low
!= ((CORE_ADDR
) -1))
6851 best_low
= min (best_low
, current_low
);
6852 best_high
= max (best_high
, current_high
);
6860 child
= sibling_die (child
);
6865 *highpc
= best_high
;
6868 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
6872 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
6873 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
6875 struct objfile
*objfile
= cu
->objfile
;
6876 struct attribute
*attr
;
6877 struct attribute
*attr_high
;
6879 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6882 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6885 CORE_ADDR low
= DW_ADDR (attr
);
6887 if (attr_high
->form
== DW_FORM_addr
)
6888 high
= DW_ADDR (attr_high
);
6890 high
= low
+ DW_UNSND (attr_high
);
6892 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
6896 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6899 bfd
*obfd
= objfile
->obfd
;
6901 /* The value of the DW_AT_ranges attribute is the offset of the
6902 address range list in the .debug_ranges section. */
6903 unsigned long offset
= DW_UNSND (attr
);
6904 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6906 /* For some target architectures, but not others, the
6907 read_address function sign-extends the addresses it returns.
6908 To recognize base address selection entries, we need a
6910 unsigned int addr_size
= cu
->header
.addr_size
;
6911 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6913 /* The base address, to which the next pair is relative. Note
6914 that this 'base' is a DWARF concept: most entries in a range
6915 list are relative, to reduce the number of relocs against the
6916 debugging information. This is separate from this function's
6917 'baseaddr' argument, which GDB uses to relocate debugging
6918 information from a shared library based on the address at
6919 which the library was loaded. */
6920 CORE_ADDR base
= cu
->base_address
;
6921 int base_known
= cu
->base_known
;
6923 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
6924 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6926 complaint (&symfile_complaints
,
6927 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
6934 unsigned int bytes_read
;
6935 CORE_ADDR start
, end
;
6937 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6938 buffer
+= bytes_read
;
6939 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6940 buffer
+= bytes_read
;
6942 /* Did we find the end of the range list? */
6943 if (start
== 0 && end
== 0)
6946 /* Did we find a base address selection entry? */
6947 else if ((start
& base_select_mask
) == base_select_mask
)
6953 /* We found an ordinary address range. */
6958 complaint (&symfile_complaints
,
6959 _("Invalid .debug_ranges data "
6960 "(no base address)"));
6966 /* Inverted range entries are invalid. */
6967 complaint (&symfile_complaints
,
6968 _("Invalid .debug_ranges data "
6969 "(inverted range)"));
6973 /* Empty range entries have no effect. */
6977 record_block_range (block
,
6978 baseaddr
+ base
+ start
,
6979 baseaddr
+ base
+ end
- 1);
6985 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
6986 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
6987 during 4.6.0 experimental. */
6990 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
6993 int major
, minor
, release
;
6996 if (cu
->producer
== NULL
)
6998 /* For unknown compilers expect their behavior is DWARF version
7001 GCC started to support .debug_types sections by -gdwarf-4 since
7002 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
7003 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
7004 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
7005 interpreted incorrectly by GDB now - GCC PR debug/48229. */
7010 if (cu
->checked_producer
)
7011 return cu
->producer_is_gxx_lt_4_6
;
7013 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
7015 if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) != 0)
7017 /* For non-GCC compilers expect their behavior is DWARF version
7022 cs
= &cu
->producer
[strlen ("GNU ")];
7023 while (*cs
&& !isdigit (*cs
))
7025 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
7027 /* Not recognized as GCC. */
7030 result
= major
< 4 || (major
== 4 && minor
< 6);
7033 cu
->checked_producer
= 1;
7034 cu
->producer_is_gxx_lt_4_6
= result
;
7039 /* Return the default accessibility type if it is not overriden by
7040 DW_AT_accessibility. */
7042 static enum dwarf_access_attribute
7043 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
7045 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
7047 /* The default DWARF 2 accessibility for members is public, the default
7048 accessibility for inheritance is private. */
7050 if (die
->tag
!= DW_TAG_inheritance
)
7051 return DW_ACCESS_public
;
7053 return DW_ACCESS_private
;
7057 /* DWARF 3+ defines the default accessibility a different way. The same
7058 rules apply now for DW_TAG_inheritance as for the members and it only
7059 depends on the container kind. */
7061 if (die
->parent
->tag
== DW_TAG_class_type
)
7062 return DW_ACCESS_private
;
7064 return DW_ACCESS_public
;
7068 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
7069 offset. If the attribute was not found return 0, otherwise return
7070 1. If it was found but could not properly be handled, set *OFFSET
7074 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
7077 struct attribute
*attr
;
7079 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
7084 /* Note that we do not check for a section offset first here.
7085 This is because DW_AT_data_member_location is new in DWARF 4,
7086 so if we see it, we can assume that a constant form is really
7087 a constant and not a section offset. */
7088 if (attr_form_is_constant (attr
))
7089 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
7090 else if (attr_form_is_section_offset (attr
))
7091 dwarf2_complex_location_expr_complaint ();
7092 else if (attr_form_is_block (attr
))
7093 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
7095 dwarf2_complex_location_expr_complaint ();
7103 /* Add an aggregate field to the field list. */
7106 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
7107 struct dwarf2_cu
*cu
)
7109 struct objfile
*objfile
= cu
->objfile
;
7110 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7111 struct nextfield
*new_field
;
7112 struct attribute
*attr
;
7114 char *fieldname
= "";
7116 /* Allocate a new field list entry and link it in. */
7117 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
7118 make_cleanup (xfree
, new_field
);
7119 memset (new_field
, 0, sizeof (struct nextfield
));
7121 if (die
->tag
== DW_TAG_inheritance
)
7123 new_field
->next
= fip
->baseclasses
;
7124 fip
->baseclasses
= new_field
;
7128 new_field
->next
= fip
->fields
;
7129 fip
->fields
= new_field
;
7133 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
7135 new_field
->accessibility
= DW_UNSND (attr
);
7137 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
7138 if (new_field
->accessibility
!= DW_ACCESS_public
)
7139 fip
->non_public_fields
= 1;
7141 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
7143 new_field
->virtuality
= DW_UNSND (attr
);
7145 new_field
->virtuality
= DW_VIRTUALITY_none
;
7147 fp
= &new_field
->field
;
7149 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
7153 /* Data member other than a C++ static data member. */
7155 /* Get type of field. */
7156 fp
->type
= die_type (die
, cu
);
7158 SET_FIELD_BITPOS (*fp
, 0);
7160 /* Get bit size of field (zero if none). */
7161 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
7164 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
7168 FIELD_BITSIZE (*fp
) = 0;
7171 /* Get bit offset of field. */
7172 if (handle_data_member_location (die
, cu
, &offset
))
7173 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
7174 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
7177 if (gdbarch_bits_big_endian (gdbarch
))
7179 /* For big endian bits, the DW_AT_bit_offset gives the
7180 additional bit offset from the MSB of the containing
7181 anonymous object to the MSB of the field. We don't
7182 have to do anything special since we don't need to
7183 know the size of the anonymous object. */
7184 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
7188 /* For little endian bits, compute the bit offset to the
7189 MSB of the anonymous object, subtract off the number of
7190 bits from the MSB of the field to the MSB of the
7191 object, and then subtract off the number of bits of
7192 the field itself. The result is the bit offset of
7193 the LSB of the field. */
7195 int bit_offset
= DW_UNSND (attr
);
7197 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7200 /* The size of the anonymous object containing
7201 the bit field is explicit, so use the
7202 indicated size (in bytes). */
7203 anonymous_size
= DW_UNSND (attr
);
7207 /* The size of the anonymous object containing
7208 the bit field must be inferred from the type
7209 attribute of the data member containing the
7211 anonymous_size
= TYPE_LENGTH (fp
->type
);
7213 SET_FIELD_BITPOS (*fp
,
7215 + anonymous_size
* bits_per_byte
7216 - bit_offset
- FIELD_BITSIZE (*fp
)));
7220 /* Get name of field. */
7221 fieldname
= dwarf2_name (die
, cu
);
7222 if (fieldname
== NULL
)
7225 /* The name is already allocated along with this objfile, so we don't
7226 need to duplicate it for the type. */
7227 fp
->name
= fieldname
;
7229 /* Change accessibility for artificial fields (e.g. virtual table
7230 pointer or virtual base class pointer) to private. */
7231 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
7233 FIELD_ARTIFICIAL (*fp
) = 1;
7234 new_field
->accessibility
= DW_ACCESS_private
;
7235 fip
->non_public_fields
= 1;
7238 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
7240 /* C++ static member. */
7242 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
7243 is a declaration, but all versions of G++ as of this writing
7244 (so through at least 3.2.1) incorrectly generate
7245 DW_TAG_variable tags. */
7247 const char *physname
;
7249 /* Get name of field. */
7250 fieldname
= dwarf2_name (die
, cu
);
7251 if (fieldname
== NULL
)
7254 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7256 /* Only create a symbol if this is an external value.
7257 new_symbol checks this and puts the value in the global symbol
7258 table, which we want. If it is not external, new_symbol
7259 will try to put the value in cu->list_in_scope which is wrong. */
7260 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
7262 /* A static const member, not much different than an enum as far as
7263 we're concerned, except that we can support more types. */
7264 new_symbol (die
, NULL
, cu
);
7267 /* Get physical name. */
7268 physname
= dwarf2_physname (fieldname
, die
, cu
);
7270 /* The name is already allocated along with this objfile, so we don't
7271 need to duplicate it for the type. */
7272 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
7273 FIELD_TYPE (*fp
) = die_type (die
, cu
);
7274 FIELD_NAME (*fp
) = fieldname
;
7276 else if (die
->tag
== DW_TAG_inheritance
)
7280 /* C++ base class field. */
7281 if (handle_data_member_location (die
, cu
, &offset
))
7282 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
7283 FIELD_BITSIZE (*fp
) = 0;
7284 FIELD_TYPE (*fp
) = die_type (die
, cu
);
7285 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
7286 fip
->nbaseclasses
++;
7290 /* Add a typedef defined in the scope of the FIP's class. */
7293 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
7294 struct dwarf2_cu
*cu
)
7296 struct objfile
*objfile
= cu
->objfile
;
7297 struct typedef_field_list
*new_field
;
7298 struct attribute
*attr
;
7299 struct typedef_field
*fp
;
7300 char *fieldname
= "";
7302 /* Allocate a new field list entry and link it in. */
7303 new_field
= xzalloc (sizeof (*new_field
));
7304 make_cleanup (xfree
, new_field
);
7306 gdb_assert (die
->tag
== DW_TAG_typedef
);
7308 fp
= &new_field
->field
;
7310 /* Get name of field. */
7311 fp
->name
= dwarf2_name (die
, cu
);
7312 if (fp
->name
== NULL
)
7315 fp
->type
= read_type_die (die
, cu
);
7317 new_field
->next
= fip
->typedef_field_list
;
7318 fip
->typedef_field_list
= new_field
;
7319 fip
->typedef_field_list_count
++;
7322 /* Create the vector of fields, and attach it to the type. */
7325 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
7326 struct dwarf2_cu
*cu
)
7328 int nfields
= fip
->nfields
;
7330 /* Record the field count, allocate space for the array of fields,
7331 and create blank accessibility bitfields if necessary. */
7332 TYPE_NFIELDS (type
) = nfields
;
7333 TYPE_FIELDS (type
) = (struct field
*)
7334 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
7335 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
7337 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
7339 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7341 TYPE_FIELD_PRIVATE_BITS (type
) =
7342 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7343 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
7345 TYPE_FIELD_PROTECTED_BITS (type
) =
7346 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7347 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
7349 TYPE_FIELD_IGNORE_BITS (type
) =
7350 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7351 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
7354 /* If the type has baseclasses, allocate and clear a bit vector for
7355 TYPE_FIELD_VIRTUAL_BITS. */
7356 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
7358 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
7359 unsigned char *pointer
;
7361 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7362 pointer
= TYPE_ALLOC (type
, num_bytes
);
7363 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
7364 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
7365 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
7368 /* Copy the saved-up fields into the field vector. Start from the head of
7369 the list, adding to the tail of the field array, so that they end up in
7370 the same order in the array in which they were added to the list. */
7371 while (nfields
-- > 0)
7373 struct nextfield
*fieldp
;
7377 fieldp
= fip
->fields
;
7378 fip
->fields
= fieldp
->next
;
7382 fieldp
= fip
->baseclasses
;
7383 fip
->baseclasses
= fieldp
->next
;
7386 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
7387 switch (fieldp
->accessibility
)
7389 case DW_ACCESS_private
:
7390 if (cu
->language
!= language_ada
)
7391 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
7394 case DW_ACCESS_protected
:
7395 if (cu
->language
!= language_ada
)
7396 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
7399 case DW_ACCESS_public
:
7403 /* Unknown accessibility. Complain and treat it as public. */
7405 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
7406 fieldp
->accessibility
);
7410 if (nfields
< fip
->nbaseclasses
)
7412 switch (fieldp
->virtuality
)
7414 case DW_VIRTUALITY_virtual
:
7415 case DW_VIRTUALITY_pure_virtual
:
7416 if (cu
->language
== language_ada
)
7417 error (_("unexpected virtuality in component of Ada type"));
7418 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
7425 /* Add a member function to the proper fieldlist. */
7428 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
7429 struct type
*type
, struct dwarf2_cu
*cu
)
7431 struct objfile
*objfile
= cu
->objfile
;
7432 struct attribute
*attr
;
7433 struct fnfieldlist
*flp
;
7435 struct fn_field
*fnp
;
7437 struct nextfnfield
*new_fnfield
;
7438 struct type
*this_type
;
7439 enum dwarf_access_attribute accessibility
;
7441 if (cu
->language
== language_ada
)
7442 error (_("unexpected member function in Ada type"));
7444 /* Get name of member function. */
7445 fieldname
= dwarf2_name (die
, cu
);
7446 if (fieldname
== NULL
)
7449 /* Look up member function name in fieldlist. */
7450 for (i
= 0; i
< fip
->nfnfields
; i
++)
7452 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
7456 /* Create new list element if necessary. */
7457 if (i
< fip
->nfnfields
)
7458 flp
= &fip
->fnfieldlists
[i
];
7461 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7463 fip
->fnfieldlists
= (struct fnfieldlist
*)
7464 xrealloc (fip
->fnfieldlists
,
7465 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
7466 * sizeof (struct fnfieldlist
));
7467 if (fip
->nfnfields
== 0)
7468 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
7470 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
7471 flp
->name
= fieldname
;
7474 i
= fip
->nfnfields
++;
7477 /* Create a new member function field and chain it to the field list
7479 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
7480 make_cleanup (xfree
, new_fnfield
);
7481 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
7482 new_fnfield
->next
= flp
->head
;
7483 flp
->head
= new_fnfield
;
7486 /* Fill in the member function field info. */
7487 fnp
= &new_fnfield
->fnfield
;
7489 /* Delay processing of the physname until later. */
7490 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
7492 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
7497 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
7498 fnp
->physname
= physname
? physname
: "";
7501 fnp
->type
= alloc_type (objfile
);
7502 this_type
= read_type_die (die
, cu
);
7503 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
7505 int nparams
= TYPE_NFIELDS (this_type
);
7507 /* TYPE is the domain of this method, and THIS_TYPE is the type
7508 of the method itself (TYPE_CODE_METHOD). */
7509 smash_to_method_type (fnp
->type
, type
,
7510 TYPE_TARGET_TYPE (this_type
),
7511 TYPE_FIELDS (this_type
),
7512 TYPE_NFIELDS (this_type
),
7513 TYPE_VARARGS (this_type
));
7515 /* Handle static member functions.
7516 Dwarf2 has no clean way to discern C++ static and non-static
7517 member functions. G++ helps GDB by marking the first
7518 parameter for non-static member functions (which is the this
7519 pointer) as artificial. We obtain this information from
7520 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
7521 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
7522 fnp
->voffset
= VOFFSET_STATIC
;
7525 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
7526 dwarf2_full_name (fieldname
, die
, cu
));
7528 /* Get fcontext from DW_AT_containing_type if present. */
7529 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7530 fnp
->fcontext
= die_containing_type (die
, cu
);
7532 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
7533 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
7535 /* Get accessibility. */
7536 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
7538 accessibility
= DW_UNSND (attr
);
7540 accessibility
= dwarf2_default_access_attribute (die
, cu
);
7541 switch (accessibility
)
7543 case DW_ACCESS_private
:
7544 fnp
->is_private
= 1;
7546 case DW_ACCESS_protected
:
7547 fnp
->is_protected
= 1;
7551 /* Check for artificial methods. */
7552 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
7553 if (attr
&& DW_UNSND (attr
) != 0)
7554 fnp
->is_artificial
= 1;
7556 /* Get index in virtual function table if it is a virtual member
7557 function. For older versions of GCC, this is an offset in the
7558 appropriate virtual table, as specified by DW_AT_containing_type.
7559 For everyone else, it is an expression to be evaluated relative
7560 to the object address. */
7562 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
7565 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
7567 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
7569 /* Old-style GCC. */
7570 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
7572 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
7573 || (DW_BLOCK (attr
)->size
> 1
7574 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
7575 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
7577 struct dwarf_block blk
;
7580 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
7582 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
7583 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
7584 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
7585 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
7586 dwarf2_complex_location_expr_complaint ();
7588 fnp
->voffset
/= cu
->header
.addr_size
;
7592 dwarf2_complex_location_expr_complaint ();
7595 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
7597 else if (attr_form_is_section_offset (attr
))
7599 dwarf2_complex_location_expr_complaint ();
7603 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
7609 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
7610 if (attr
&& DW_UNSND (attr
))
7612 /* GCC does this, as of 2008-08-25; PR debug/37237. */
7613 complaint (&symfile_complaints
,
7614 _("Member function \"%s\" (offset %d) is virtual "
7615 "but the vtable offset is not specified"),
7616 fieldname
, die
->offset
.sect_off
);
7617 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7618 TYPE_CPLUS_DYNAMIC (type
) = 1;
7623 /* Create the vector of member function fields, and attach it to the type. */
7626 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
7627 struct dwarf2_cu
*cu
)
7629 struct fnfieldlist
*flp
;
7632 if (cu
->language
== language_ada
)
7633 error (_("unexpected member functions in Ada type"));
7635 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7636 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
7637 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
7639 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
7641 struct nextfnfield
*nfp
= flp
->head
;
7642 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
7645 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
7646 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
7647 fn_flp
->fn_fields
= (struct fn_field
*)
7648 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
7649 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
7650 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
7653 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
7656 /* Returns non-zero if NAME is the name of a vtable member in CU's
7657 language, zero otherwise. */
7659 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
7661 static const char vptr
[] = "_vptr";
7662 static const char vtable
[] = "vtable";
7664 /* Look for the C++ and Java forms of the vtable. */
7665 if ((cu
->language
== language_java
7666 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
7667 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
7668 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
7674 /* GCC outputs unnamed structures that are really pointers to member
7675 functions, with the ABI-specified layout. If TYPE describes
7676 such a structure, smash it into a member function type.
7678 GCC shouldn't do this; it should just output pointer to member DIEs.
7679 This is GCC PR debug/28767. */
7682 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
7684 struct type
*pfn_type
, *domain_type
, *new_type
;
7686 /* Check for a structure with no name and two children. */
7687 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
7690 /* Check for __pfn and __delta members. */
7691 if (TYPE_FIELD_NAME (type
, 0) == NULL
7692 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
7693 || TYPE_FIELD_NAME (type
, 1) == NULL
7694 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
7697 /* Find the type of the method. */
7698 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
7699 if (pfn_type
== NULL
7700 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
7701 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
7704 /* Look for the "this" argument. */
7705 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
7706 if (TYPE_NFIELDS (pfn_type
) == 0
7707 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
7708 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
7711 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
7712 new_type
= alloc_type (objfile
);
7713 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
7714 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
7715 TYPE_VARARGS (pfn_type
));
7716 smash_to_methodptr_type (type
, new_type
);
7719 /* Called when we find the DIE that starts a structure or union scope
7720 (definition) to create a type for the structure or union. Fill in
7721 the type's name and general properties; the members will not be
7722 processed until process_structure_type.
7724 NOTE: we need to call these functions regardless of whether or not the
7725 DIE has a DW_AT_name attribute, since it might be an anonymous
7726 structure or union. This gets the type entered into our set of
7729 However, if the structure is incomplete (an opaque struct/union)
7730 then suppress creating a symbol table entry for it since gdb only
7731 wants to find the one with the complete definition. Note that if
7732 it is complete, we just call new_symbol, which does it's own
7733 checking about whether the struct/union is anonymous or not (and
7734 suppresses creating a symbol table entry itself). */
7736 static struct type
*
7737 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7739 struct objfile
*objfile
= cu
->objfile
;
7741 struct attribute
*attr
;
7744 /* If the definition of this type lives in .debug_types, read that type.
7745 Don't follow DW_AT_specification though, that will take us back up
7746 the chain and we want to go down. */
7747 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7750 struct dwarf2_cu
*type_cu
= cu
;
7751 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7753 /* We could just recurse on read_structure_type, but we need to call
7754 get_die_type to ensure only one type for this DIE is created.
7755 This is important, for example, because for c++ classes we need
7756 TYPE_NAME set which is only done by new_symbol. Blech. */
7757 type
= read_type_die (type_die
, type_cu
);
7759 /* TYPE_CU may not be the same as CU.
7760 Ensure TYPE is recorded in CU's type_hash table. */
7761 return set_die_type (die
, type
, cu
);
7764 type
= alloc_type (objfile
);
7765 INIT_CPLUS_SPECIFIC (type
);
7767 name
= dwarf2_name (die
, cu
);
7770 if (cu
->language
== language_cplus
7771 || cu
->language
== language_java
)
7773 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
7775 /* dwarf2_full_name might have already finished building the DIE's
7776 type. If so, there is no need to continue. */
7777 if (get_die_type (die
, cu
) != NULL
)
7778 return get_die_type (die
, cu
);
7780 TYPE_TAG_NAME (type
) = full_name
;
7781 if (die
->tag
== DW_TAG_structure_type
7782 || die
->tag
== DW_TAG_class_type
)
7783 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7787 /* The name is already allocated along with this objfile, so
7788 we don't need to duplicate it for the type. */
7789 TYPE_TAG_NAME (type
) = (char *) name
;
7790 if (die
->tag
== DW_TAG_class_type
)
7791 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7795 if (die
->tag
== DW_TAG_structure_type
)
7797 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
7799 else if (die
->tag
== DW_TAG_union_type
)
7801 TYPE_CODE (type
) = TYPE_CODE_UNION
;
7805 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
7808 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
7809 TYPE_DECLARED_CLASS (type
) = 1;
7811 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7814 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7818 TYPE_LENGTH (type
) = 0;
7821 TYPE_STUB_SUPPORTED (type
) = 1;
7822 if (die_is_declaration (die
, cu
))
7823 TYPE_STUB (type
) = 1;
7824 else if (attr
== NULL
&& die
->child
== NULL
7825 && producer_is_realview (cu
->producer
))
7826 /* RealView does not output the required DW_AT_declaration
7827 on incomplete types. */
7828 TYPE_STUB (type
) = 1;
7830 /* We need to add the type field to the die immediately so we don't
7831 infinitely recurse when dealing with pointers to the structure
7832 type within the structure itself. */
7833 set_die_type (die
, type
, cu
);
7835 /* set_die_type should be already done. */
7836 set_descriptive_type (type
, die
, cu
);
7841 /* Finish creating a structure or union type, including filling in
7842 its members and creating a symbol for it. */
7845 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7847 struct objfile
*objfile
= cu
->objfile
;
7848 struct die_info
*child_die
= die
->child
;
7851 type
= get_die_type (die
, cu
);
7853 type
= read_structure_type (die
, cu
);
7855 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
7857 struct field_info fi
;
7858 struct die_info
*child_die
;
7859 VEC (symbolp
) *template_args
= NULL
;
7860 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
7862 memset (&fi
, 0, sizeof (struct field_info
));
7864 child_die
= die
->child
;
7866 while (child_die
&& child_die
->tag
)
7868 if (child_die
->tag
== DW_TAG_member
7869 || child_die
->tag
== DW_TAG_variable
)
7871 /* NOTE: carlton/2002-11-05: A C++ static data member
7872 should be a DW_TAG_member that is a declaration, but
7873 all versions of G++ as of this writing (so through at
7874 least 3.2.1) incorrectly generate DW_TAG_variable
7875 tags for them instead. */
7876 dwarf2_add_field (&fi
, child_die
, cu
);
7878 else if (child_die
->tag
== DW_TAG_subprogram
)
7880 /* C++ member function. */
7881 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
7883 else if (child_die
->tag
== DW_TAG_inheritance
)
7885 /* C++ base class field. */
7886 dwarf2_add_field (&fi
, child_die
, cu
);
7888 else if (child_die
->tag
== DW_TAG_typedef
)
7889 dwarf2_add_typedef (&fi
, child_die
, cu
);
7890 else if (child_die
->tag
== DW_TAG_template_type_param
7891 || child_die
->tag
== DW_TAG_template_value_param
)
7893 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
7896 VEC_safe_push (symbolp
, template_args
, arg
);
7899 child_die
= sibling_die (child_die
);
7902 /* Attach template arguments to type. */
7903 if (! VEC_empty (symbolp
, template_args
))
7905 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7906 TYPE_N_TEMPLATE_ARGUMENTS (type
)
7907 = VEC_length (symbolp
, template_args
);
7908 TYPE_TEMPLATE_ARGUMENTS (type
)
7909 = obstack_alloc (&objfile
->objfile_obstack
,
7910 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7911 * sizeof (struct symbol
*)));
7912 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
7913 VEC_address (symbolp
, template_args
),
7914 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7915 * sizeof (struct symbol
*)));
7916 VEC_free (symbolp
, template_args
);
7919 /* Attach fields and member functions to the type. */
7921 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
7924 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
7926 /* Get the type which refers to the base class (possibly this
7927 class itself) which contains the vtable pointer for the current
7928 class from the DW_AT_containing_type attribute. This use of
7929 DW_AT_containing_type is a GNU extension. */
7931 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7933 struct type
*t
= die_containing_type (die
, cu
);
7935 TYPE_VPTR_BASETYPE (type
) = t
;
7940 /* Our own class provides vtbl ptr. */
7941 for (i
= TYPE_NFIELDS (t
) - 1;
7942 i
>= TYPE_N_BASECLASSES (t
);
7945 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
7947 if (is_vtable_name (fieldname
, cu
))
7949 TYPE_VPTR_FIELDNO (type
) = i
;
7954 /* Complain if virtual function table field not found. */
7955 if (i
< TYPE_N_BASECLASSES (t
))
7956 complaint (&symfile_complaints
,
7957 _("virtual function table pointer "
7958 "not found when defining class '%s'"),
7959 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
7964 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
7967 else if (cu
->producer
7968 && strncmp (cu
->producer
,
7969 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
7971 /* The IBM XLC compiler does not provide direct indication
7972 of the containing type, but the vtable pointer is
7973 always named __vfp. */
7977 for (i
= TYPE_NFIELDS (type
) - 1;
7978 i
>= TYPE_N_BASECLASSES (type
);
7981 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
7983 TYPE_VPTR_FIELDNO (type
) = i
;
7984 TYPE_VPTR_BASETYPE (type
) = type
;
7991 /* Copy fi.typedef_field_list linked list elements content into the
7992 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
7993 if (fi
.typedef_field_list
)
7995 int i
= fi
.typedef_field_list_count
;
7997 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7998 TYPE_TYPEDEF_FIELD_ARRAY (type
)
7999 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
8000 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
8002 /* Reverse the list order to keep the debug info elements order. */
8005 struct typedef_field
*dest
, *src
;
8007 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
8008 src
= &fi
.typedef_field_list
->field
;
8009 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
8014 do_cleanups (back_to
);
8016 if (HAVE_CPLUS_STRUCT (type
))
8017 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
8020 quirk_gcc_member_function_pointer (type
, objfile
);
8022 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
8023 snapshots) has been known to create a die giving a declaration
8024 for a class that has, as a child, a die giving a definition for a
8025 nested class. So we have to process our children even if the
8026 current die is a declaration. Normally, of course, a declaration
8027 won't have any children at all. */
8029 while (child_die
!= NULL
&& child_die
->tag
)
8031 if (child_die
->tag
== DW_TAG_member
8032 || child_die
->tag
== DW_TAG_variable
8033 || child_die
->tag
== DW_TAG_inheritance
8034 || child_die
->tag
== DW_TAG_template_value_param
8035 || child_die
->tag
== DW_TAG_template_type_param
)
8040 process_die (child_die
, cu
);
8042 child_die
= sibling_die (child_die
);
8045 /* Do not consider external references. According to the DWARF standard,
8046 these DIEs are identified by the fact that they have no byte_size
8047 attribute, and a declaration attribute. */
8048 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
8049 || !die_is_declaration (die
, cu
))
8050 new_symbol (die
, type
, cu
);
8053 /* Given a DW_AT_enumeration_type die, set its type. We do not
8054 complete the type's fields yet, or create any symbols. */
8056 static struct type
*
8057 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8059 struct objfile
*objfile
= cu
->objfile
;
8061 struct attribute
*attr
;
8064 /* If the definition of this type lives in .debug_types, read that type.
8065 Don't follow DW_AT_specification though, that will take us back up
8066 the chain and we want to go down. */
8067 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
8070 struct dwarf2_cu
*type_cu
= cu
;
8071 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
8073 type
= read_type_die (type_die
, type_cu
);
8075 /* TYPE_CU may not be the same as CU.
8076 Ensure TYPE is recorded in CU's type_hash table. */
8077 return set_die_type (die
, type
, cu
);
8080 type
= alloc_type (objfile
);
8082 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
8083 name
= dwarf2_full_name (NULL
, die
, cu
);
8085 TYPE_TAG_NAME (type
) = (char *) name
;
8087 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8090 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8094 TYPE_LENGTH (type
) = 0;
8097 /* The enumeration DIE can be incomplete. In Ada, any type can be
8098 declared as private in the package spec, and then defined only
8099 inside the package body. Such types are known as Taft Amendment
8100 Types. When another package uses such a type, an incomplete DIE
8101 may be generated by the compiler. */
8102 if (die_is_declaration (die
, cu
))
8103 TYPE_STUB (type
) = 1;
8105 return set_die_type (die
, type
, cu
);
8108 /* Given a pointer to a die which begins an enumeration, process all
8109 the dies that define the members of the enumeration, and create the
8110 symbol for the enumeration type.
8112 NOTE: We reverse the order of the element list. */
8115 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8117 struct type
*this_type
;
8119 this_type
= get_die_type (die
, cu
);
8120 if (this_type
== NULL
)
8121 this_type
= read_enumeration_type (die
, cu
);
8123 if (die
->child
!= NULL
)
8125 struct die_info
*child_die
;
8127 struct field
*fields
= NULL
;
8129 int unsigned_enum
= 1;
8134 child_die
= die
->child
;
8135 while (child_die
&& child_die
->tag
)
8137 if (child_die
->tag
!= DW_TAG_enumerator
)
8139 process_die (child_die
, cu
);
8143 name
= dwarf2_name (child_die
, cu
);
8146 sym
= new_symbol (child_die
, this_type
, cu
);
8147 if (SYMBOL_VALUE (sym
) < 0)
8152 else if ((mask
& SYMBOL_VALUE (sym
)) != 0)
8155 mask
|= SYMBOL_VALUE (sym
);
8157 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
8159 fields
= (struct field
*)
8161 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
8162 * sizeof (struct field
));
8165 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
8166 FIELD_TYPE (fields
[num_fields
]) = NULL
;
8167 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
8168 FIELD_BITSIZE (fields
[num_fields
]) = 0;
8174 child_die
= sibling_die (child_die
);
8179 TYPE_NFIELDS (this_type
) = num_fields
;
8180 TYPE_FIELDS (this_type
) = (struct field
*)
8181 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
8182 memcpy (TYPE_FIELDS (this_type
), fields
,
8183 sizeof (struct field
) * num_fields
);
8187 TYPE_UNSIGNED (this_type
) = 1;
8189 TYPE_FLAG_ENUM (this_type
) = 1;
8192 /* If we are reading an enum from a .debug_types unit, and the enum
8193 is a declaration, and the enum is not the signatured type in the
8194 unit, then we do not want to add a symbol for it. Adding a
8195 symbol would in some cases obscure the true definition of the
8196 enum, giving users an incomplete type when the definition is
8197 actually available. Note that we do not want to do this for all
8198 enums which are just declarations, because C++0x allows forward
8199 enum declarations. */
8200 if (cu
->per_cu
->debug_types_section
8201 && die_is_declaration (die
, cu
))
8203 struct signatured_type
*sig_type
;
8206 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
8207 cu
->per_cu
->debug_types_section
,
8208 cu
->per_cu
->offset
);
8209 if (sig_type
->per_cu
.offset
.sect_off
+ sig_type
->type_offset
.cu_off
8210 != die
->offset
.sect_off
)
8214 new_symbol (die
, this_type
, cu
);
8217 /* Extract all information from a DW_TAG_array_type DIE and put it in
8218 the DIE's type field. For now, this only handles one dimensional
8221 static struct type
*
8222 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8224 struct objfile
*objfile
= cu
->objfile
;
8225 struct die_info
*child_die
;
8227 struct type
*element_type
, *range_type
, *index_type
;
8228 struct type
**range_types
= NULL
;
8229 struct attribute
*attr
;
8231 struct cleanup
*back_to
;
8234 element_type
= die_type (die
, cu
);
8236 /* The die_type call above may have already set the type for this DIE. */
8237 type
= get_die_type (die
, cu
);
8241 /* Irix 6.2 native cc creates array types without children for
8242 arrays with unspecified length. */
8243 if (die
->child
== NULL
)
8245 index_type
= objfile_type (objfile
)->builtin_int
;
8246 range_type
= create_range_type (NULL
, index_type
, 0, -1);
8247 type
= create_array_type (NULL
, element_type
, range_type
);
8248 return set_die_type (die
, type
, cu
);
8251 back_to
= make_cleanup (null_cleanup
, NULL
);
8252 child_die
= die
->child
;
8253 while (child_die
&& child_die
->tag
)
8255 if (child_die
->tag
== DW_TAG_subrange_type
)
8257 struct type
*child_type
= read_type_die (child_die
, cu
);
8259 if (child_type
!= NULL
)
8261 /* The range type was succesfully read. Save it for the
8262 array type creation. */
8263 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
8265 range_types
= (struct type
**)
8266 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
8267 * sizeof (struct type
*));
8269 make_cleanup (free_current_contents
, &range_types
);
8271 range_types
[ndim
++] = child_type
;
8274 child_die
= sibling_die (child_die
);
8277 /* Dwarf2 dimensions are output from left to right, create the
8278 necessary array types in backwards order. */
8280 type
= element_type
;
8282 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
8287 type
= create_array_type (NULL
, type
, range_types
[i
++]);
8292 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
8295 /* Understand Dwarf2 support for vector types (like they occur on
8296 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
8297 array type. This is not part of the Dwarf2/3 standard yet, but a
8298 custom vendor extension. The main difference between a regular
8299 array and the vector variant is that vectors are passed by value
8301 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
8303 make_vector_type (type
);
8305 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
8306 implementation may choose to implement triple vectors using this
8308 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8311 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
8312 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8314 complaint (&symfile_complaints
,
8315 _("DW_AT_byte_size for array type smaller "
8316 "than the total size of elements"));
8319 name
= dwarf2_name (die
, cu
);
8321 TYPE_NAME (type
) = name
;
8323 /* Install the type in the die. */
8324 set_die_type (die
, type
, cu
);
8326 /* set_die_type should be already done. */
8327 set_descriptive_type (type
, die
, cu
);
8329 do_cleanups (back_to
);
8334 static enum dwarf_array_dim_ordering
8335 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
8337 struct attribute
*attr
;
8339 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
8341 if (attr
) return DW_SND (attr
);
8343 /* GNU F77 is a special case, as at 08/2004 array type info is the
8344 opposite order to the dwarf2 specification, but data is still
8345 laid out as per normal fortran.
8347 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
8348 version checking. */
8350 if (cu
->language
== language_fortran
8351 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
8353 return DW_ORD_row_major
;
8356 switch (cu
->language_defn
->la_array_ordering
)
8358 case array_column_major
:
8359 return DW_ORD_col_major
;
8360 case array_row_major
:
8362 return DW_ORD_row_major
;
8366 /* Extract all information from a DW_TAG_set_type DIE and put it in
8367 the DIE's type field. */
8369 static struct type
*
8370 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8372 struct type
*domain_type
, *set_type
;
8373 struct attribute
*attr
;
8375 domain_type
= die_type (die
, cu
);
8377 /* The die_type call above may have already set the type for this DIE. */
8378 set_type
= get_die_type (die
, cu
);
8382 set_type
= create_set_type (NULL
, domain_type
);
8384 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8386 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
8388 return set_die_type (die
, set_type
, cu
);
8391 /* First cut: install each common block member as a global variable. */
8394 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
8396 struct die_info
*child_die
;
8397 struct attribute
*attr
;
8399 CORE_ADDR base
= (CORE_ADDR
) 0;
8401 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
8404 /* Support the .debug_loc offsets. */
8405 if (attr_form_is_block (attr
))
8407 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
8409 else if (attr_form_is_section_offset (attr
))
8411 dwarf2_complex_location_expr_complaint ();
8415 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
8416 "common block member");
8419 if (die
->child
!= NULL
)
8421 child_die
= die
->child
;
8422 while (child_die
&& child_die
->tag
)
8426 sym
= new_symbol (child_die
, NULL
, cu
);
8428 && handle_data_member_location (child_die
, cu
, &offset
))
8430 SYMBOL_VALUE_ADDRESS (sym
) = base
+ offset
;
8431 add_symbol_to_list (sym
, &global_symbols
);
8433 child_die
= sibling_die (child_die
);
8438 /* Create a type for a C++ namespace. */
8440 static struct type
*
8441 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8443 struct objfile
*objfile
= cu
->objfile
;
8444 const char *previous_prefix
, *name
;
8448 /* For extensions, reuse the type of the original namespace. */
8449 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
8451 struct die_info
*ext_die
;
8452 struct dwarf2_cu
*ext_cu
= cu
;
8454 ext_die
= dwarf2_extension (die
, &ext_cu
);
8455 type
= read_type_die (ext_die
, ext_cu
);
8457 /* EXT_CU may not be the same as CU.
8458 Ensure TYPE is recorded in CU's type_hash table. */
8459 return set_die_type (die
, type
, cu
);
8462 name
= namespace_name (die
, &is_anonymous
, cu
);
8464 /* Now build the name of the current namespace. */
8466 previous_prefix
= determine_prefix (die
, cu
);
8467 if (previous_prefix
[0] != '\0')
8468 name
= typename_concat (&objfile
->objfile_obstack
,
8469 previous_prefix
, name
, 0, cu
);
8471 /* Create the type. */
8472 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
8474 TYPE_NAME (type
) = (char *) name
;
8475 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8477 return set_die_type (die
, type
, cu
);
8480 /* Read a C++ namespace. */
8483 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
8485 struct objfile
*objfile
= cu
->objfile
;
8488 /* Add a symbol associated to this if we haven't seen the namespace
8489 before. Also, add a using directive if it's an anonymous
8492 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
8496 type
= read_type_die (die
, cu
);
8497 new_symbol (die
, type
, cu
);
8499 namespace_name (die
, &is_anonymous
, cu
);
8502 const char *previous_prefix
= determine_prefix (die
, cu
);
8504 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
8505 NULL
, NULL
, &objfile
->objfile_obstack
);
8509 if (die
->child
!= NULL
)
8511 struct die_info
*child_die
= die
->child
;
8513 while (child_die
&& child_die
->tag
)
8515 process_die (child_die
, cu
);
8516 child_die
= sibling_die (child_die
);
8521 /* Read a Fortran module as type. This DIE can be only a declaration used for
8522 imported module. Still we need that type as local Fortran "use ... only"
8523 declaration imports depend on the created type in determine_prefix. */
8525 static struct type
*
8526 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8528 struct objfile
*objfile
= cu
->objfile
;
8532 module_name
= dwarf2_name (die
, cu
);
8534 complaint (&symfile_complaints
,
8535 _("DW_TAG_module has no name, offset 0x%x"),
8536 die
->offset
.sect_off
);
8537 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
8539 /* determine_prefix uses TYPE_TAG_NAME. */
8540 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8542 return set_die_type (die
, type
, cu
);
8545 /* Read a Fortran module. */
8548 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
8550 struct die_info
*child_die
= die
->child
;
8552 while (child_die
&& child_die
->tag
)
8554 process_die (child_die
, cu
);
8555 child_die
= sibling_die (child_die
);
8559 /* Return the name of the namespace represented by DIE. Set
8560 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
8564 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
8566 struct die_info
*current_die
;
8567 const char *name
= NULL
;
8569 /* Loop through the extensions until we find a name. */
8571 for (current_die
= die
;
8572 current_die
!= NULL
;
8573 current_die
= dwarf2_extension (die
, &cu
))
8575 name
= dwarf2_name (current_die
, cu
);
8580 /* Is it an anonymous namespace? */
8582 *is_anonymous
= (name
== NULL
);
8584 name
= CP_ANONYMOUS_NAMESPACE_STR
;
8589 /* Extract all information from a DW_TAG_pointer_type DIE and add to
8590 the user defined type vector. */
8592 static struct type
*
8593 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8595 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
8596 struct comp_unit_head
*cu_header
= &cu
->header
;
8598 struct attribute
*attr_byte_size
;
8599 struct attribute
*attr_address_class
;
8600 int byte_size
, addr_class
;
8601 struct type
*target_type
;
8603 target_type
= die_type (die
, cu
);
8605 /* The die_type call above may have already set the type for this DIE. */
8606 type
= get_die_type (die
, cu
);
8610 type
= lookup_pointer_type (target_type
);
8612 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8614 byte_size
= DW_UNSND (attr_byte_size
);
8616 byte_size
= cu_header
->addr_size
;
8618 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
8619 if (attr_address_class
)
8620 addr_class
= DW_UNSND (attr_address_class
);
8622 addr_class
= DW_ADDR_none
;
8624 /* If the pointer size or address class is different than the
8625 default, create a type variant marked as such and set the
8626 length accordingly. */
8627 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
8629 if (gdbarch_address_class_type_flags_p (gdbarch
))
8633 type_flags
= gdbarch_address_class_type_flags
8634 (gdbarch
, byte_size
, addr_class
);
8635 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
8637 type
= make_type_with_address_space (type
, type_flags
);
8639 else if (TYPE_LENGTH (type
) != byte_size
)
8641 complaint (&symfile_complaints
,
8642 _("invalid pointer size %d"), byte_size
);
8646 /* Should we also complain about unhandled address classes? */
8650 TYPE_LENGTH (type
) = byte_size
;
8651 return set_die_type (die
, type
, cu
);
8654 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
8655 the user defined type vector. */
8657 static struct type
*
8658 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8661 struct type
*to_type
;
8662 struct type
*domain
;
8664 to_type
= die_type (die
, cu
);
8665 domain
= die_containing_type (die
, cu
);
8667 /* The calls above may have already set the type for this DIE. */
8668 type
= get_die_type (die
, cu
);
8672 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
8673 type
= lookup_methodptr_type (to_type
);
8675 type
= lookup_memberptr_type (to_type
, domain
);
8677 return set_die_type (die
, type
, cu
);
8680 /* Extract all information from a DW_TAG_reference_type DIE and add to
8681 the user defined type vector. */
8683 static struct type
*
8684 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8686 struct comp_unit_head
*cu_header
= &cu
->header
;
8687 struct type
*type
, *target_type
;
8688 struct attribute
*attr
;
8690 target_type
= die_type (die
, cu
);
8692 /* The die_type call above may have already set the type for this DIE. */
8693 type
= get_die_type (die
, cu
);
8697 type
= lookup_reference_type (target_type
);
8698 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8701 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8705 TYPE_LENGTH (type
) = cu_header
->addr_size
;
8707 return set_die_type (die
, type
, cu
);
8710 static struct type
*
8711 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8713 struct type
*base_type
, *cv_type
;
8715 base_type
= die_type (die
, cu
);
8717 /* The die_type call above may have already set the type for this DIE. */
8718 cv_type
= get_die_type (die
, cu
);
8722 /* In case the const qualifier is applied to an array type, the element type
8723 is so qualified, not the array type (section 6.7.3 of C99). */
8724 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
8726 struct type
*el_type
, *inner_array
;
8728 base_type
= copy_type (base_type
);
8729 inner_array
= base_type
;
8731 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
8733 TYPE_TARGET_TYPE (inner_array
) =
8734 copy_type (TYPE_TARGET_TYPE (inner_array
));
8735 inner_array
= TYPE_TARGET_TYPE (inner_array
);
8738 el_type
= TYPE_TARGET_TYPE (inner_array
);
8739 TYPE_TARGET_TYPE (inner_array
) =
8740 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
8742 return set_die_type (die
, base_type
, cu
);
8745 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
8746 return set_die_type (die
, cv_type
, cu
);
8749 static struct type
*
8750 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8752 struct type
*base_type
, *cv_type
;
8754 base_type
= die_type (die
, cu
);
8756 /* The die_type call above may have already set the type for this DIE. */
8757 cv_type
= get_die_type (die
, cu
);
8761 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
8762 return set_die_type (die
, cv_type
, cu
);
8765 /* Extract all information from a DW_TAG_string_type DIE and add to
8766 the user defined type vector. It isn't really a user defined type,
8767 but it behaves like one, with other DIE's using an AT_user_def_type
8768 attribute to reference it. */
8770 static struct type
*
8771 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8773 struct objfile
*objfile
= cu
->objfile
;
8774 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8775 struct type
*type
, *range_type
, *index_type
, *char_type
;
8776 struct attribute
*attr
;
8777 unsigned int length
;
8779 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
8782 length
= DW_UNSND (attr
);
8786 /* Check for the DW_AT_byte_size attribute. */
8787 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8790 length
= DW_UNSND (attr
);
8798 index_type
= objfile_type (objfile
)->builtin_int
;
8799 range_type
= create_range_type (NULL
, index_type
, 1, length
);
8800 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
8801 type
= create_string_type (NULL
, char_type
, range_type
);
8803 return set_die_type (die
, type
, cu
);
8806 /* Handle DIES due to C code like:
8810 int (*funcp)(int a, long l);
8814 ('funcp' generates a DW_TAG_subroutine_type DIE). */
8816 static struct type
*
8817 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8819 struct objfile
*objfile
= cu
->objfile
;
8820 struct type
*type
; /* Type that this function returns. */
8821 struct type
*ftype
; /* Function that returns above type. */
8822 struct attribute
*attr
;
8824 type
= die_type (die
, cu
);
8826 /* The die_type call above may have already set the type for this DIE. */
8827 ftype
= get_die_type (die
, cu
);
8831 ftype
= lookup_function_type (type
);
8833 /* All functions in C++, Pascal and Java have prototypes. */
8834 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
8835 if ((attr
&& (DW_UNSND (attr
) != 0))
8836 || cu
->language
== language_cplus
8837 || cu
->language
== language_java
8838 || cu
->language
== language_pascal
)
8839 TYPE_PROTOTYPED (ftype
) = 1;
8840 else if (producer_is_realview (cu
->producer
))
8841 /* RealView does not emit DW_AT_prototyped. We can not
8842 distinguish prototyped and unprototyped functions; default to
8843 prototyped, since that is more common in modern code (and
8844 RealView warns about unprototyped functions). */
8845 TYPE_PROTOTYPED (ftype
) = 1;
8847 /* Store the calling convention in the type if it's available in
8848 the subroutine die. Otherwise set the calling convention to
8849 the default value DW_CC_normal. */
8850 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
8852 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
8853 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
8854 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
8856 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
8858 /* We need to add the subroutine type to the die immediately so
8859 we don't infinitely recurse when dealing with parameters
8860 declared as the same subroutine type. */
8861 set_die_type (die
, ftype
, cu
);
8863 if (die
->child
!= NULL
)
8865 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
8866 struct die_info
*child_die
;
8867 int nparams
, iparams
;
8869 /* Count the number of parameters.
8870 FIXME: GDB currently ignores vararg functions, but knows about
8871 vararg member functions. */
8873 child_die
= die
->child
;
8874 while (child_die
&& child_die
->tag
)
8876 if (child_die
->tag
== DW_TAG_formal_parameter
)
8878 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
8879 TYPE_VARARGS (ftype
) = 1;
8880 child_die
= sibling_die (child_die
);
8883 /* Allocate storage for parameters and fill them in. */
8884 TYPE_NFIELDS (ftype
) = nparams
;
8885 TYPE_FIELDS (ftype
) = (struct field
*)
8886 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
8888 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
8889 even if we error out during the parameters reading below. */
8890 for (iparams
= 0; iparams
< nparams
; iparams
++)
8891 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
8894 child_die
= die
->child
;
8895 while (child_die
&& child_die
->tag
)
8897 if (child_die
->tag
== DW_TAG_formal_parameter
)
8899 struct type
*arg_type
;
8901 /* DWARF version 2 has no clean way to discern C++
8902 static and non-static member functions. G++ helps
8903 GDB by marking the first parameter for non-static
8904 member functions (which is the this pointer) as
8905 artificial. We pass this information to
8906 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
8908 DWARF version 3 added DW_AT_object_pointer, which GCC
8909 4.5 does not yet generate. */
8910 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
8912 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
8915 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
8917 /* GCC/43521: In java, the formal parameter
8918 "this" is sometimes not marked with DW_AT_artificial. */
8919 if (cu
->language
== language_java
)
8921 const char *name
= dwarf2_name (child_die
, cu
);
8923 if (name
&& !strcmp (name
, "this"))
8924 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
8927 arg_type
= die_type (child_die
, cu
);
8929 /* RealView does not mark THIS as const, which the testsuite
8930 expects. GCC marks THIS as const in method definitions,
8931 but not in the class specifications (GCC PR 43053). */
8932 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
8933 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
8936 struct dwarf2_cu
*arg_cu
= cu
;
8937 const char *name
= dwarf2_name (child_die
, cu
);
8939 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
8942 /* If the compiler emits this, use it. */
8943 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
8946 else if (name
&& strcmp (name
, "this") == 0)
8947 /* Function definitions will have the argument names. */
8949 else if (name
== NULL
&& iparams
== 0)
8950 /* Declarations may not have the names, so like
8951 elsewhere in GDB, assume an artificial first
8952 argument is "this". */
8956 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
8960 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
8963 child_die
= sibling_die (child_die
);
8970 static struct type
*
8971 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
8973 struct objfile
*objfile
= cu
->objfile
;
8974 const char *name
= NULL
;
8975 struct type
*this_type
, *target_type
;
8977 name
= dwarf2_full_name (NULL
, die
, cu
);
8978 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
8979 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
8980 TYPE_NAME (this_type
) = (char *) name
;
8981 set_die_type (die
, this_type
, cu
);
8982 target_type
= die_type (die
, cu
);
8983 if (target_type
!= this_type
)
8984 TYPE_TARGET_TYPE (this_type
) = target_type
;
8987 /* Self-referential typedefs are, it seems, not allowed by the DWARF
8988 spec and cause infinite loops in GDB. */
8989 complaint (&symfile_complaints
,
8990 _("Self-referential DW_TAG_typedef "
8991 "- DIE at 0x%x [in module %s]"),
8992 die
->offset
.sect_off
, objfile
->name
);
8993 TYPE_TARGET_TYPE (this_type
) = NULL
;
8998 /* Find a representation of a given base type and install
8999 it in the TYPE field of the die. */
9001 static struct type
*
9002 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9004 struct objfile
*objfile
= cu
->objfile
;
9006 struct attribute
*attr
;
9007 int encoding
= 0, size
= 0;
9009 enum type_code code
= TYPE_CODE_INT
;
9011 struct type
*target_type
= NULL
;
9013 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
9016 encoding
= DW_UNSND (attr
);
9018 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9021 size
= DW_UNSND (attr
);
9023 name
= dwarf2_name (die
, cu
);
9026 complaint (&symfile_complaints
,
9027 _("DW_AT_name missing from DW_TAG_base_type"));
9032 case DW_ATE_address
:
9033 /* Turn DW_ATE_address into a void * pointer. */
9034 code
= TYPE_CODE_PTR
;
9035 type_flags
|= TYPE_FLAG_UNSIGNED
;
9036 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
9038 case DW_ATE_boolean
:
9039 code
= TYPE_CODE_BOOL
;
9040 type_flags
|= TYPE_FLAG_UNSIGNED
;
9042 case DW_ATE_complex_float
:
9043 code
= TYPE_CODE_COMPLEX
;
9044 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
9046 case DW_ATE_decimal_float
:
9047 code
= TYPE_CODE_DECFLOAT
;
9050 code
= TYPE_CODE_FLT
;
9054 case DW_ATE_unsigned
:
9055 type_flags
|= TYPE_FLAG_UNSIGNED
;
9056 if (cu
->language
== language_fortran
9058 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
9059 code
= TYPE_CODE_CHAR
;
9061 case DW_ATE_signed_char
:
9062 if (cu
->language
== language_ada
|| cu
->language
== language_m2
9063 || cu
->language
== language_pascal
9064 || cu
->language
== language_fortran
)
9065 code
= TYPE_CODE_CHAR
;
9067 case DW_ATE_unsigned_char
:
9068 if (cu
->language
== language_ada
|| cu
->language
== language_m2
9069 || cu
->language
== language_pascal
9070 || cu
->language
== language_fortran
)
9071 code
= TYPE_CODE_CHAR
;
9072 type_flags
|= TYPE_FLAG_UNSIGNED
;
9075 /* We just treat this as an integer and then recognize the
9076 type by name elsewhere. */
9080 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
9081 dwarf_type_encoding_name (encoding
));
9085 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
9086 TYPE_NAME (type
) = name
;
9087 TYPE_TARGET_TYPE (type
) = target_type
;
9089 if (name
&& strcmp (name
, "char") == 0)
9090 TYPE_NOSIGN (type
) = 1;
9092 return set_die_type (die
, type
, cu
);
9095 /* Read the given DW_AT_subrange DIE. */
9097 static struct type
*
9098 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9100 struct type
*base_type
;
9101 struct type
*range_type
;
9102 struct attribute
*attr
;
9104 int low_default_is_valid
;
9106 LONGEST negative_mask
;
9108 base_type
= die_type (die
, cu
);
9109 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
9110 check_typedef (base_type
);
9112 /* The die_type call above may have already set the type for this DIE. */
9113 range_type
= get_die_type (die
, cu
);
9117 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
9118 omitting DW_AT_lower_bound. */
9119 switch (cu
->language
)
9122 case language_cplus
:
9124 low_default_is_valid
= 1;
9126 case language_fortran
:
9128 low_default_is_valid
= 1;
9134 low_default_is_valid
= (cu
->header
.version
>= 4);
9138 case language_pascal
:
9140 low_default_is_valid
= (cu
->header
.version
>= 4);
9144 low_default_is_valid
= 0;
9148 /* FIXME: For variable sized arrays either of these could be
9149 a variable rather than a constant value. We'll allow it,
9150 but we don't know how to handle it. */
9151 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
9153 low
= dwarf2_get_attr_constant_value (attr
, low
);
9154 else if (!low_default_is_valid
)
9155 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
9156 "- DIE at 0x%x [in module %s]"),
9157 die
->offset
.sect_off
, cu
->objfile
->name
);
9159 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
9162 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
9164 /* GCC encodes arrays with unspecified or dynamic length
9165 with a DW_FORM_block1 attribute or a reference attribute.
9166 FIXME: GDB does not yet know how to handle dynamic
9167 arrays properly, treat them as arrays with unspecified
9170 FIXME: jimb/2003-09-22: GDB does not really know
9171 how to handle arrays of unspecified length
9172 either; we just represent them as zero-length
9173 arrays. Choose an appropriate upper bound given
9174 the lower bound we've computed above. */
9178 high
= dwarf2_get_attr_constant_value (attr
, 1);
9182 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
9185 int count
= dwarf2_get_attr_constant_value (attr
, 1);
9186 high
= low
+ count
- 1;
9190 /* Unspecified array length. */
9195 /* Dwarf-2 specifications explicitly allows to create subrange types
9196 without specifying a base type.
9197 In that case, the base type must be set to the type of
9198 the lower bound, upper bound or count, in that order, if any of these
9199 three attributes references an object that has a type.
9200 If no base type is found, the Dwarf-2 specifications say that
9201 a signed integer type of size equal to the size of an address should
9203 For the following C code: `extern char gdb_int [];'
9204 GCC produces an empty range DIE.
9205 FIXME: muller/2010-05-28: Possible references to object for low bound,
9206 high bound or count are not yet handled by this code. */
9207 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
9209 struct objfile
*objfile
= cu
->objfile
;
9210 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9211 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
9212 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
9214 /* Test "int", "long int", and "long long int" objfile types,
9215 and select the first one having a size above or equal to the
9216 architecture address size. */
9217 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
9218 base_type
= int_type
;
9221 int_type
= objfile_type (objfile
)->builtin_long
;
9222 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
9223 base_type
= int_type
;
9226 int_type
= objfile_type (objfile
)->builtin_long_long
;
9227 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
9228 base_type
= int_type
;
9234 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
9235 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
9236 low
|= negative_mask
;
9237 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
9238 high
|= negative_mask
;
9240 range_type
= create_range_type (NULL
, base_type
, low
, high
);
9242 /* Mark arrays with dynamic length at least as an array of unspecified
9243 length. GDB could check the boundary but before it gets implemented at
9244 least allow accessing the array elements. */
9245 if (attr
&& attr_form_is_block (attr
))
9246 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
9248 /* Ada expects an empty array on no boundary attributes. */
9249 if (attr
== NULL
&& cu
->language
!= language_ada
)
9250 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
9252 name
= dwarf2_name (die
, cu
);
9254 TYPE_NAME (range_type
) = name
;
9256 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9258 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
9260 set_die_type (die
, range_type
, cu
);
9262 /* set_die_type should be already done. */
9263 set_descriptive_type (range_type
, die
, cu
);
9268 static struct type
*
9269 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9273 /* For now, we only support the C meaning of an unspecified type: void. */
9275 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
9276 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
9278 return set_die_type (die
, type
, cu
);
9281 /* Trivial hash function for die_info: the hash value of a DIE
9282 is its offset in .debug_info for this objfile. */
9285 die_hash (const void *item
)
9287 const struct die_info
*die
= item
;
9289 return die
->offset
.sect_off
;
9292 /* Trivial comparison function for die_info structures: two DIEs
9293 are equal if they have the same offset. */
9296 die_eq (const void *item_lhs
, const void *item_rhs
)
9298 const struct die_info
*die_lhs
= item_lhs
;
9299 const struct die_info
*die_rhs
= item_rhs
;
9301 return die_lhs
->offset
.sect_off
== die_rhs
->offset
.sect_off
;
9304 /* Read a whole compilation unit into a linked list of dies. */
9306 static struct die_info
*
9307 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
9309 struct die_reader_specs reader_specs
;
9310 int read_abbrevs
= 0;
9311 struct cleanup
*back_to
= NULL
;
9312 struct die_info
*die
;
9314 if (cu
->dwarf2_abbrevs
== NULL
)
9316 dwarf2_read_abbrevs (cu
);
9317 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
9321 gdb_assert (cu
->die_hash
== NULL
);
9323 = htab_create_alloc_ex (cu
->header
.length
/ 12,
9327 &cu
->comp_unit_obstack
,
9328 hashtab_obstack_allocate
,
9329 dummy_obstack_deallocate
);
9331 init_cu_die_reader (&reader_specs
, cu
);
9333 die
= read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
9336 do_cleanups (back_to
);
9341 /* Main entry point for reading a DIE and all children.
9342 Read the DIE and dump it if requested. */
9344 static struct die_info
*
9345 read_die_and_children (const struct die_reader_specs
*reader
,
9347 gdb_byte
**new_info_ptr
,
9348 struct die_info
*parent
)
9350 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
9351 new_info_ptr
, parent
);
9353 if (dwarf2_die_debug
)
9355 fprintf_unfiltered (gdb_stdlog
,
9356 "\nRead die from %s of %s:\n",
9357 (reader
->cu
->per_cu
->debug_types_section
9360 reader
->abfd
->filename
);
9361 dump_die (result
, dwarf2_die_debug
);
9367 /* Read a single die and all its descendents. Set the die's sibling
9368 field to NULL; set other fields in the die correctly, and set all
9369 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
9370 location of the info_ptr after reading all of those dies. PARENT
9371 is the parent of the die in question. */
9373 static struct die_info
*
9374 read_die_and_children_1 (const struct die_reader_specs
*reader
,
9376 gdb_byte
**new_info_ptr
,
9377 struct die_info
*parent
)
9379 struct die_info
*die
;
9383 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
9386 *new_info_ptr
= cur_ptr
;
9389 store_in_ref_table (die
, reader
->cu
);
9392 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
9396 *new_info_ptr
= cur_ptr
;
9399 die
->sibling
= NULL
;
9400 die
->parent
= parent
;
9404 /* Read a die, all of its descendents, and all of its siblings; set
9405 all of the fields of all of the dies correctly. Arguments are as
9406 in read_die_and_children. */
9408 static struct die_info
*
9409 read_die_and_siblings (const struct die_reader_specs
*reader
,
9411 gdb_byte
**new_info_ptr
,
9412 struct die_info
*parent
)
9414 struct die_info
*first_die
, *last_sibling
;
9418 first_die
= last_sibling
= NULL
;
9422 struct die_info
*die
9423 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
9427 *new_info_ptr
= cur_ptr
;
9434 last_sibling
->sibling
= die
;
9440 /* Read the die from the .debug_info section buffer. Set DIEP to
9441 point to a newly allocated die with its information, except for its
9442 child, sibling, and parent fields. Set HAS_CHILDREN to tell
9443 whether the die has children or not. */
9446 read_full_die (const struct die_reader_specs
*reader
,
9447 struct die_info
**diep
, gdb_byte
*info_ptr
,
9450 unsigned int abbrev_number
, bytes_read
, i
;
9452 struct abbrev_info
*abbrev
;
9453 struct die_info
*die
;
9454 struct dwarf2_cu
*cu
= reader
->cu
;
9455 bfd
*abfd
= reader
->abfd
;
9457 offset
.sect_off
= info_ptr
- reader
->buffer
;
9458 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9459 info_ptr
+= bytes_read
;
9467 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
9469 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
9471 bfd_get_filename (abfd
));
9473 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
9474 die
->offset
= offset
;
9475 die
->tag
= abbrev
->tag
;
9476 die
->abbrev
= abbrev_number
;
9478 die
->num_attrs
= abbrev
->num_attrs
;
9480 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9481 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
9482 abfd
, info_ptr
, cu
);
9485 *has_children
= abbrev
->has_children
;
9489 /* In DWARF version 2, the description of the debugging information is
9490 stored in a separate .debug_abbrev section. Before we read any
9491 dies from a section we read in all abbreviations and install them
9492 in a hash table. This function also sets flags in CU describing
9493 the data found in the abbrev table. */
9496 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
)
9498 bfd
*abfd
= cu
->objfile
->obfd
;
9499 struct comp_unit_head
*cu_header
= &cu
->header
;
9500 gdb_byte
*abbrev_ptr
;
9501 struct abbrev_info
*cur_abbrev
;
9502 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
9503 unsigned int abbrev_form
, hash_number
;
9504 struct attr_abbrev
*cur_attrs
;
9505 unsigned int allocated_attrs
;
9507 /* Initialize dwarf2 abbrevs. */
9508 obstack_init (&cu
->abbrev_obstack
);
9509 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
9511 * sizeof (struct abbrev_info
*)));
9512 memset (cu
->dwarf2_abbrevs
, 0,
9513 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
9515 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
9516 &dwarf2_per_objfile
->abbrev
);
9517 abbrev_ptr
= (dwarf2_per_objfile
->abbrev
.buffer
9518 + cu_header
->abbrev_offset
.sect_off
);
9519 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9520 abbrev_ptr
+= bytes_read
;
9522 allocated_attrs
= ATTR_ALLOC_CHUNK
;
9523 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
9525 /* Loop until we reach an abbrev number of 0. */
9526 while (abbrev_number
)
9528 cur_abbrev
= dwarf_alloc_abbrev (cu
);
9530 /* read in abbrev header */
9531 cur_abbrev
->number
= abbrev_number
;
9532 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9533 abbrev_ptr
+= bytes_read
;
9534 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
9537 /* now read in declarations */
9538 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9539 abbrev_ptr
+= bytes_read
;
9540 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9541 abbrev_ptr
+= bytes_read
;
9544 if (cur_abbrev
->num_attrs
== allocated_attrs
)
9546 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
9548 = xrealloc (cur_attrs
, (allocated_attrs
9549 * sizeof (struct attr_abbrev
)));
9552 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
9553 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
9554 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9555 abbrev_ptr
+= bytes_read
;
9556 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9557 abbrev_ptr
+= bytes_read
;
9560 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
9561 (cur_abbrev
->num_attrs
9562 * sizeof (struct attr_abbrev
)));
9563 memcpy (cur_abbrev
->attrs
, cur_attrs
,
9564 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
9566 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
9567 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
9568 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
9570 /* Get next abbreviation.
9571 Under Irix6 the abbreviations for a compilation unit are not
9572 always properly terminated with an abbrev number of 0.
9573 Exit loop if we encounter an abbreviation which we have
9574 already read (which means we are about to read the abbreviations
9575 for the next compile unit) or if the end of the abbreviation
9576 table is reached. */
9577 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
9578 >= dwarf2_per_objfile
->abbrev
.size
)
9580 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9581 abbrev_ptr
+= bytes_read
;
9582 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
9589 /* Release the memory used by the abbrev table for a compilation unit. */
9592 dwarf2_free_abbrev_table (void *ptr_to_cu
)
9594 struct dwarf2_cu
*cu
= ptr_to_cu
;
9596 obstack_free (&cu
->abbrev_obstack
, NULL
);
9597 cu
->dwarf2_abbrevs
= NULL
;
9600 /* Lookup an abbrev_info structure in the abbrev hash table. */
9602 static struct abbrev_info
*
9603 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
9605 unsigned int hash_number
;
9606 struct abbrev_info
*abbrev
;
9608 hash_number
= number
% ABBREV_HASH_SIZE
;
9609 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
9613 if (abbrev
->number
== number
)
9616 abbrev
= abbrev
->next
;
9621 /* Returns nonzero if TAG represents a type that we might generate a partial
9625 is_type_tag_for_partial (int tag
)
9630 /* Some types that would be reasonable to generate partial symbols for,
9631 that we don't at present. */
9632 case DW_TAG_array_type
:
9633 case DW_TAG_file_type
:
9634 case DW_TAG_ptr_to_member_type
:
9635 case DW_TAG_set_type
:
9636 case DW_TAG_string_type
:
9637 case DW_TAG_subroutine_type
:
9639 case DW_TAG_base_type
:
9640 case DW_TAG_class_type
:
9641 case DW_TAG_interface_type
:
9642 case DW_TAG_enumeration_type
:
9643 case DW_TAG_structure_type
:
9644 case DW_TAG_subrange_type
:
9645 case DW_TAG_typedef
:
9646 case DW_TAG_union_type
:
9653 /* Load all DIEs that are interesting for partial symbols into memory. */
9655 static struct partial_die_info
*
9656 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9657 int building_psymtab
, struct dwarf2_cu
*cu
)
9659 struct objfile
*objfile
= cu
->objfile
;
9660 struct partial_die_info
*part_die
;
9661 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
9662 struct abbrev_info
*abbrev
;
9663 unsigned int bytes_read
;
9664 unsigned int load_all
= 0;
9665 int nesting_level
= 1;
9670 gdb_assert (cu
->per_cu
!= NULL
);
9671 if (cu
->per_cu
->load_all_dies
)
9675 = htab_create_alloc_ex (cu
->header
.length
/ 12,
9679 &cu
->comp_unit_obstack
,
9680 hashtab_obstack_allocate
,
9681 dummy_obstack_deallocate
);
9683 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9684 sizeof (struct partial_die_info
));
9688 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
9690 /* A NULL abbrev means the end of a series of children. */
9693 if (--nesting_level
== 0)
9695 /* PART_DIE was probably the last thing allocated on the
9696 comp_unit_obstack, so we could call obstack_free
9697 here. We don't do that because the waste is small,
9698 and will be cleaned up when we're done with this
9699 compilation unit. This way, we're also more robust
9700 against other users of the comp_unit_obstack. */
9703 info_ptr
+= bytes_read
;
9704 last_die
= parent_die
;
9705 parent_die
= parent_die
->die_parent
;
9709 /* Check for template arguments. We never save these; if
9710 they're seen, we just mark the parent, and go on our way. */
9711 if (parent_die
!= NULL
9712 && cu
->language
== language_cplus
9713 && (abbrev
->tag
== DW_TAG_template_type_param
9714 || abbrev
->tag
== DW_TAG_template_value_param
))
9716 parent_die
->has_template_arguments
= 1;
9720 /* We don't need a partial DIE for the template argument. */
9721 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
,
9727 /* We only recurse into c++ subprograms looking for template arguments.
9728 Skip their other children. */
9730 && cu
->language
== language_cplus
9731 && parent_die
!= NULL
9732 && parent_die
->tag
== DW_TAG_subprogram
)
9734 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
9738 /* Check whether this DIE is interesting enough to save. Normally
9739 we would not be interested in members here, but there may be
9740 later variables referencing them via DW_AT_specification (for
9743 && !is_type_tag_for_partial (abbrev
->tag
)
9744 && abbrev
->tag
!= DW_TAG_constant
9745 && abbrev
->tag
!= DW_TAG_enumerator
9746 && abbrev
->tag
!= DW_TAG_subprogram
9747 && abbrev
->tag
!= DW_TAG_lexical_block
9748 && abbrev
->tag
!= DW_TAG_variable
9749 && abbrev
->tag
!= DW_TAG_namespace
9750 && abbrev
->tag
!= DW_TAG_module
9751 && abbrev
->tag
!= DW_TAG_member
)
9753 /* Otherwise we skip to the next sibling, if any. */
9754 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
9758 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
9759 buffer
, info_ptr
, cu
);
9761 /* This two-pass algorithm for processing partial symbols has a
9762 high cost in cache pressure. Thus, handle some simple cases
9763 here which cover the majority of C partial symbols. DIEs
9764 which neither have specification tags in them, nor could have
9765 specification tags elsewhere pointing at them, can simply be
9766 processed and discarded.
9768 This segment is also optional; scan_partial_symbols and
9769 add_partial_symbol will handle these DIEs if we chain
9770 them in normally. When compilers which do not emit large
9771 quantities of duplicate debug information are more common,
9772 this code can probably be removed. */
9774 /* Any complete simple types at the top level (pretty much all
9775 of them, for a language without namespaces), can be processed
9777 if (parent_die
== NULL
9778 && part_die
->has_specification
== 0
9779 && part_die
->is_declaration
== 0
9780 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
9781 || part_die
->tag
== DW_TAG_base_type
9782 || part_die
->tag
== DW_TAG_subrange_type
))
9784 if (building_psymtab
&& part_die
->name
!= NULL
)
9785 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9786 VAR_DOMAIN
, LOC_TYPEDEF
,
9787 &objfile
->static_psymbols
,
9788 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
9789 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9793 /* The exception for DW_TAG_typedef with has_children above is
9794 a workaround of GCC PR debug/47510. In the case of this complaint
9795 type_name_no_tag_or_error will error on such types later.
9797 GDB skipped children of DW_TAG_typedef by the shortcut above and then
9798 it could not find the child DIEs referenced later, this is checked
9799 above. In correct DWARF DW_TAG_typedef should have no children. */
9801 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
9802 complaint (&symfile_complaints
,
9803 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
9804 "- DIE at 0x%x [in module %s]"),
9805 part_die
->offset
.sect_off
, objfile
->name
);
9807 /* If we're at the second level, and we're an enumerator, and
9808 our parent has no specification (meaning possibly lives in a
9809 namespace elsewhere), then we can add the partial symbol now
9810 instead of queueing it. */
9811 if (part_die
->tag
== DW_TAG_enumerator
9812 && parent_die
!= NULL
9813 && parent_die
->die_parent
== NULL
9814 && parent_die
->tag
== DW_TAG_enumeration_type
9815 && parent_die
->has_specification
== 0)
9817 if (part_die
->name
== NULL
)
9818 complaint (&symfile_complaints
,
9819 _("malformed enumerator DIE ignored"));
9820 else if (building_psymtab
)
9821 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9822 VAR_DOMAIN
, LOC_CONST
,
9823 (cu
->language
== language_cplus
9824 || cu
->language
== language_java
)
9825 ? &objfile
->global_psymbols
9826 : &objfile
->static_psymbols
,
9827 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
9829 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9833 /* We'll save this DIE so link it in. */
9834 part_die
->die_parent
= parent_die
;
9835 part_die
->die_sibling
= NULL
;
9836 part_die
->die_child
= NULL
;
9838 if (last_die
&& last_die
== parent_die
)
9839 last_die
->die_child
= part_die
;
9841 last_die
->die_sibling
= part_die
;
9843 last_die
= part_die
;
9845 if (first_die
== NULL
)
9846 first_die
= part_die
;
9848 /* Maybe add the DIE to the hash table. Not all DIEs that we
9849 find interesting need to be in the hash table, because we
9850 also have the parent/sibling/child chains; only those that we
9851 might refer to by offset later during partial symbol reading.
9853 For now this means things that might have be the target of a
9854 DW_AT_specification, DW_AT_abstract_origin, or
9855 DW_AT_extension. DW_AT_extension will refer only to
9856 namespaces; DW_AT_abstract_origin refers to functions (and
9857 many things under the function DIE, but we do not recurse
9858 into function DIEs during partial symbol reading) and
9859 possibly variables as well; DW_AT_specification refers to
9860 declarations. Declarations ought to have the DW_AT_declaration
9861 flag. It happens that GCC forgets to put it in sometimes, but
9862 only for functions, not for types.
9864 Adding more things than necessary to the hash table is harmless
9865 except for the performance cost. Adding too few will result in
9866 wasted time in find_partial_die, when we reread the compilation
9867 unit with load_all_dies set. */
9870 || abbrev
->tag
== DW_TAG_constant
9871 || abbrev
->tag
== DW_TAG_subprogram
9872 || abbrev
->tag
== DW_TAG_variable
9873 || abbrev
->tag
== DW_TAG_namespace
9874 || part_die
->is_declaration
)
9878 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
9879 part_die
->offset
.sect_off
, INSERT
);
9883 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9884 sizeof (struct partial_die_info
));
9886 /* For some DIEs we want to follow their children (if any). For C
9887 we have no reason to follow the children of structures; for other
9888 languages we have to, so that we can get at method physnames
9889 to infer fully qualified class names, for DW_AT_specification,
9890 and for C++ template arguments. For C++, we also look one level
9891 inside functions to find template arguments (if the name of the
9892 function does not already contain the template arguments).
9894 For Ada, we need to scan the children of subprograms and lexical
9895 blocks as well because Ada allows the definition of nested
9896 entities that could be interesting for the debugger, such as
9897 nested subprograms for instance. */
9898 if (last_die
->has_children
9900 || last_die
->tag
== DW_TAG_namespace
9901 || last_die
->tag
== DW_TAG_module
9902 || last_die
->tag
== DW_TAG_enumeration_type
9903 || (cu
->language
== language_cplus
9904 && last_die
->tag
== DW_TAG_subprogram
9905 && (last_die
->name
== NULL
9906 || strchr (last_die
->name
, '<') == NULL
))
9907 || (cu
->language
!= language_c
9908 && (last_die
->tag
== DW_TAG_class_type
9909 || last_die
->tag
== DW_TAG_interface_type
9910 || last_die
->tag
== DW_TAG_structure_type
9911 || last_die
->tag
== DW_TAG_union_type
))
9912 || (cu
->language
== language_ada
9913 && (last_die
->tag
== DW_TAG_subprogram
9914 || last_die
->tag
== DW_TAG_lexical_block
))))
9917 parent_die
= last_die
;
9921 /* Otherwise we skip to the next sibling, if any. */
9922 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
9924 /* Back to the top, do it again. */
9928 /* Read a minimal amount of information into the minimal die structure. */
9931 read_partial_die (struct partial_die_info
*part_die
,
9932 struct abbrev_info
*abbrev
,
9933 unsigned int abbrev_len
, bfd
*abfd
,
9934 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9935 struct dwarf2_cu
*cu
)
9937 struct objfile
*objfile
= cu
->objfile
;
9939 struct attribute attr
;
9940 int has_low_pc_attr
= 0;
9941 int has_high_pc_attr
= 0;
9942 int high_pc_relative
= 0;
9944 memset (part_die
, 0, sizeof (struct partial_die_info
));
9946 part_die
->offset
.sect_off
= info_ptr
- buffer
;
9948 info_ptr
+= abbrev_len
;
9953 part_die
->tag
= abbrev
->tag
;
9954 part_die
->has_children
= abbrev
->has_children
;
9956 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9958 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
9960 /* Store the data if it is of an attribute we want to keep in a
9961 partial symbol table. */
9965 switch (part_die
->tag
)
9967 case DW_TAG_compile_unit
:
9968 case DW_TAG_type_unit
:
9969 /* Compilation units have a DW_AT_name that is a filename, not
9970 a source language identifier. */
9971 case DW_TAG_enumeration_type
:
9972 case DW_TAG_enumerator
:
9973 /* These tags always have simple identifiers already; no need
9974 to canonicalize them. */
9975 part_die
->name
= DW_STRING (&attr
);
9979 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
9980 &objfile
->objfile_obstack
);
9984 case DW_AT_linkage_name
:
9985 case DW_AT_MIPS_linkage_name
:
9986 /* Note that both forms of linkage name might appear. We
9987 assume they will be the same, and we only store the last
9989 if (cu
->language
== language_ada
)
9990 part_die
->name
= DW_STRING (&attr
);
9991 part_die
->linkage_name
= DW_STRING (&attr
);
9994 has_low_pc_attr
= 1;
9995 part_die
->lowpc
= DW_ADDR (&attr
);
9998 has_high_pc_attr
= 1;
9999 if (attr
.form
== DW_FORM_addr
)
10000 part_die
->highpc
= DW_ADDR (&attr
);
10003 high_pc_relative
= 1;
10004 part_die
->highpc
= DW_UNSND (&attr
);
10007 case DW_AT_location
:
10008 /* Support the .debug_loc offsets. */
10009 if (attr_form_is_block (&attr
))
10011 part_die
->locdesc
= DW_BLOCK (&attr
);
10013 else if (attr_form_is_section_offset (&attr
))
10015 dwarf2_complex_location_expr_complaint ();
10019 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
10020 "partial symbol information");
10023 case DW_AT_external
:
10024 part_die
->is_external
= DW_UNSND (&attr
);
10026 case DW_AT_declaration
:
10027 part_die
->is_declaration
= DW_UNSND (&attr
);
10030 part_die
->has_type
= 1;
10032 case DW_AT_abstract_origin
:
10033 case DW_AT_specification
:
10034 case DW_AT_extension
:
10035 part_die
->has_specification
= 1;
10036 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
10038 case DW_AT_sibling
:
10039 /* Ignore absolute siblings, they might point outside of
10040 the current compile unit. */
10041 if (attr
.form
== DW_FORM_ref_addr
)
10042 complaint (&symfile_complaints
,
10043 _("ignoring absolute DW_AT_sibling"));
10045 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
10047 case DW_AT_byte_size
:
10048 part_die
->has_byte_size
= 1;
10050 case DW_AT_calling_convention
:
10051 /* DWARF doesn't provide a way to identify a program's source-level
10052 entry point. DW_AT_calling_convention attributes are only meant
10053 to describe functions' calling conventions.
10055 However, because it's a necessary piece of information in
10056 Fortran, and because DW_CC_program is the only piece of debugging
10057 information whose definition refers to a 'main program' at all,
10058 several compilers have begun marking Fortran main programs with
10059 DW_CC_program --- even when those functions use the standard
10060 calling conventions.
10062 So until DWARF specifies a way to provide this information and
10063 compilers pick up the new representation, we'll support this
10065 if (DW_UNSND (&attr
) == DW_CC_program
10066 && cu
->language
== language_fortran
)
10068 set_main_name (part_die
->name
);
10070 /* As this DIE has a static linkage the name would be difficult
10071 to look up later. */
10072 language_of_main
= language_fortran
;
10076 if (DW_UNSND (&attr
) == DW_INL_inlined
10077 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
10078 part_die
->may_be_inlined
= 1;
10085 if (high_pc_relative
)
10086 part_die
->highpc
+= part_die
->lowpc
;
10088 if (has_low_pc_attr
&& has_high_pc_attr
)
10090 /* When using the GNU linker, .gnu.linkonce. sections are used to
10091 eliminate duplicate copies of functions and vtables and such.
10092 The linker will arbitrarily choose one and discard the others.
10093 The AT_*_pc values for such functions refer to local labels in
10094 these sections. If the section from that file was discarded, the
10095 labels are not in the output, so the relocs get a value of 0.
10096 If this is a discarded function, mark the pc bounds as invalid,
10097 so that GDB will ignore it. */
10098 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
10100 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10102 complaint (&symfile_complaints
,
10103 _("DW_AT_low_pc %s is zero "
10104 "for DIE at 0x%x [in module %s]"),
10105 paddress (gdbarch
, part_die
->lowpc
),
10106 part_die
->offset
.sect_off
, objfile
->name
);
10108 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
10109 else if (part_die
->lowpc
>= part_die
->highpc
)
10111 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10113 complaint (&symfile_complaints
,
10114 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
10115 "for DIE at 0x%x [in module %s]"),
10116 paddress (gdbarch
, part_die
->lowpc
),
10117 paddress (gdbarch
, part_die
->highpc
),
10118 part_die
->offset
.sect_off
, objfile
->name
);
10121 part_die
->has_pc_info
= 1;
10127 /* Find a cached partial DIE at OFFSET in CU. */
10129 static struct partial_die_info
*
10130 find_partial_die_in_comp_unit (sect_offset offset
, struct dwarf2_cu
*cu
)
10132 struct partial_die_info
*lookup_die
= NULL
;
10133 struct partial_die_info part_die
;
10135 part_die
.offset
= offset
;
10136 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
,
10142 /* Find a partial DIE at OFFSET, which may or may not be in CU,
10143 except in the case of .debug_types DIEs which do not reference
10144 outside their CU (they do however referencing other types via
10145 DW_FORM_ref_sig8). */
10147 static struct partial_die_info
*
10148 find_partial_die (sect_offset offset
, struct dwarf2_cu
*cu
)
10150 struct objfile
*objfile
= cu
->objfile
;
10151 struct dwarf2_per_cu_data
*per_cu
= NULL
;
10152 struct partial_die_info
*pd
= NULL
;
10154 if (offset_in_cu_p (&cu
->header
, offset
))
10156 pd
= find_partial_die_in_comp_unit (offset
, cu
);
10159 /* We missed recording what we needed.
10160 Load all dies and try again. */
10161 per_cu
= cu
->per_cu
;
10165 /* TUs don't reference other CUs/TUs (except via type signatures). */
10166 if (cu
->per_cu
->debug_types_section
)
10168 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
10169 " external reference to offset 0x%lx [in module %s].\n"),
10170 (long) cu
->header
.offset
.sect_off
, (long) offset
.sect_off
,
10171 bfd_get_filename (objfile
->obfd
));
10173 per_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
10175 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
10176 load_partial_comp_unit (per_cu
);
10178 per_cu
->cu
->last_used
= 0;
10179 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
10182 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
10184 struct cleanup
*back_to
;
10185 struct partial_die_info comp_unit_die
;
10186 struct abbrev_info
*abbrev
;
10187 unsigned int bytes_read
;
10189 struct dwarf2_section_info
*sec
;
10191 per_cu
->load_all_dies
= 1;
10193 if (per_cu
->debug_types_section
)
10194 sec
= per_cu
->debug_types_section
;
10196 sec
= &dwarf2_per_objfile
->info
;
10198 /* Re-read the DIEs, this time reading all of them.
10199 NOTE: We don't discard the previous set of DIEs.
10200 This doesn't happen very often so it's (hopefully) not a problem. */
10201 back_to
= make_cleanup (null_cleanup
, 0);
10202 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
10204 dwarf2_read_abbrevs (per_cu
->cu
);
10205 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
10207 info_ptr
= (sec
->buffer
10208 + per_cu
->cu
->header
.offset
.sect_off
10209 + per_cu
->cu
->header
.first_die_offset
.cu_off
);
10210 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
10211 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
10212 objfile
->obfd
, sec
->buffer
, info_ptr
,
10214 if (comp_unit_die
.has_children
)
10215 load_partial_dies (objfile
->obfd
, sec
->buffer
, info_ptr
, 0,
10217 do_cleanups (back_to
);
10219 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
10223 internal_error (__FILE__
, __LINE__
,
10224 _("could not find partial DIE 0x%x "
10225 "in cache [from module %s]\n"),
10226 offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
10230 /* See if we can figure out if the class lives in a namespace. We do
10231 this by looking for a member function; its demangled name will
10232 contain namespace info, if there is any. */
10235 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
10236 struct dwarf2_cu
*cu
)
10238 /* NOTE: carlton/2003-10-07: Getting the info this way changes
10239 what template types look like, because the demangler
10240 frequently doesn't give the same name as the debug info. We
10241 could fix this by only using the demangled name to get the
10242 prefix (but see comment in read_structure_type). */
10244 struct partial_die_info
*real_pdi
;
10245 struct partial_die_info
*child_pdi
;
10247 /* If this DIE (this DIE's specification, if any) has a parent, then
10248 we should not do this. We'll prepend the parent's fully qualified
10249 name when we create the partial symbol. */
10251 real_pdi
= struct_pdi
;
10252 while (real_pdi
->has_specification
)
10253 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
10255 if (real_pdi
->die_parent
!= NULL
)
10258 for (child_pdi
= struct_pdi
->die_child
;
10260 child_pdi
= child_pdi
->die_sibling
)
10262 if (child_pdi
->tag
== DW_TAG_subprogram
10263 && child_pdi
->linkage_name
!= NULL
)
10265 char *actual_class_name
10266 = language_class_name_from_physname (cu
->language_defn
,
10267 child_pdi
->linkage_name
);
10268 if (actual_class_name
!= NULL
)
10271 = obsavestring (actual_class_name
,
10272 strlen (actual_class_name
),
10273 &cu
->objfile
->objfile_obstack
);
10274 xfree (actual_class_name
);
10281 /* Adjust PART_DIE before generating a symbol for it. This function
10282 may set the is_external flag or change the DIE's name. */
10285 fixup_partial_die (struct partial_die_info
*part_die
,
10286 struct dwarf2_cu
*cu
)
10288 /* Once we've fixed up a die, there's no point in doing so again.
10289 This also avoids a memory leak if we were to call
10290 guess_partial_die_structure_name multiple times. */
10291 if (part_die
->fixup_called
)
10294 /* If we found a reference attribute and the DIE has no name, try
10295 to find a name in the referred to DIE. */
10297 if (part_die
->name
== NULL
&& part_die
->has_specification
)
10299 struct partial_die_info
*spec_die
;
10301 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
10303 fixup_partial_die (spec_die
, cu
);
10305 if (spec_die
->name
)
10307 part_die
->name
= spec_die
->name
;
10309 /* Copy DW_AT_external attribute if it is set. */
10310 if (spec_die
->is_external
)
10311 part_die
->is_external
= spec_die
->is_external
;
10315 /* Set default names for some unnamed DIEs. */
10317 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
10318 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
10320 /* If there is no parent die to provide a namespace, and there are
10321 children, see if we can determine the namespace from their linkage
10323 if (cu
->language
== language_cplus
10324 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
10325 && part_die
->die_parent
== NULL
10326 && part_die
->has_children
10327 && (part_die
->tag
== DW_TAG_class_type
10328 || part_die
->tag
== DW_TAG_structure_type
10329 || part_die
->tag
== DW_TAG_union_type
))
10330 guess_partial_die_structure_name (part_die
, cu
);
10332 /* GCC might emit a nameless struct or union that has a linkage
10333 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
10334 if (part_die
->name
== NULL
10335 && (part_die
->tag
== DW_TAG_class_type
10336 || part_die
->tag
== DW_TAG_interface_type
10337 || part_die
->tag
== DW_TAG_structure_type
10338 || part_die
->tag
== DW_TAG_union_type
)
10339 && part_die
->linkage_name
!= NULL
)
10343 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
10348 /* Strip any leading namespaces/classes, keep only the base name.
10349 DW_AT_name for named DIEs does not contain the prefixes. */
10350 base
= strrchr (demangled
, ':');
10351 if (base
&& base
> demangled
&& base
[-1] == ':')
10356 part_die
->name
= obsavestring (base
, strlen (base
),
10357 &cu
->objfile
->objfile_obstack
);
10362 part_die
->fixup_called
= 1;
10365 /* Read an attribute value described by an attribute form. */
10368 read_attribute_value (struct attribute
*attr
, unsigned form
,
10369 bfd
*abfd
, gdb_byte
*info_ptr
,
10370 struct dwarf2_cu
*cu
)
10372 struct comp_unit_head
*cu_header
= &cu
->header
;
10373 unsigned int bytes_read
;
10374 struct dwarf_block
*blk
;
10379 case DW_FORM_ref_addr
:
10380 if (cu
->header
.version
== 2)
10381 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
10383 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
10384 &cu
->header
, &bytes_read
);
10385 info_ptr
+= bytes_read
;
10388 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
10389 info_ptr
+= bytes_read
;
10391 case DW_FORM_block2
:
10392 blk
= dwarf_alloc_block (cu
);
10393 blk
->size
= read_2_bytes (abfd
, info_ptr
);
10395 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10396 info_ptr
+= blk
->size
;
10397 DW_BLOCK (attr
) = blk
;
10399 case DW_FORM_block4
:
10400 blk
= dwarf_alloc_block (cu
);
10401 blk
->size
= read_4_bytes (abfd
, info_ptr
);
10403 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10404 info_ptr
+= blk
->size
;
10405 DW_BLOCK (attr
) = blk
;
10407 case DW_FORM_data2
:
10408 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
10411 case DW_FORM_data4
:
10412 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
10415 case DW_FORM_data8
:
10416 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
10419 case DW_FORM_sec_offset
:
10420 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
10421 info_ptr
+= bytes_read
;
10423 case DW_FORM_string
:
10424 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
10425 DW_STRING_IS_CANONICAL (attr
) = 0;
10426 info_ptr
+= bytes_read
;
10429 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
10431 DW_STRING_IS_CANONICAL (attr
) = 0;
10432 info_ptr
+= bytes_read
;
10434 case DW_FORM_exprloc
:
10435 case DW_FORM_block
:
10436 blk
= dwarf_alloc_block (cu
);
10437 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10438 info_ptr
+= bytes_read
;
10439 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10440 info_ptr
+= blk
->size
;
10441 DW_BLOCK (attr
) = blk
;
10443 case DW_FORM_block1
:
10444 blk
= dwarf_alloc_block (cu
);
10445 blk
->size
= read_1_byte (abfd
, info_ptr
);
10447 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10448 info_ptr
+= blk
->size
;
10449 DW_BLOCK (attr
) = blk
;
10451 case DW_FORM_data1
:
10452 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
10456 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
10459 case DW_FORM_flag_present
:
10460 DW_UNSND (attr
) = 1;
10462 case DW_FORM_sdata
:
10463 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
10464 info_ptr
+= bytes_read
;
10466 case DW_FORM_udata
:
10467 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10468 info_ptr
+= bytes_read
;
10471 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
10472 + read_1_byte (abfd
, info_ptr
));
10476 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
10477 + read_2_bytes (abfd
, info_ptr
));
10481 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
10482 + read_4_bytes (abfd
, info_ptr
));
10486 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
10487 + read_8_bytes (abfd
, info_ptr
));
10490 case DW_FORM_ref_sig8
:
10491 /* Convert the signature to something we can record in DW_UNSND
10493 NOTE: This is NULL if the type wasn't found. */
10494 DW_SIGNATURED_TYPE (attr
) =
10495 lookup_signatured_type (read_8_bytes (abfd
, info_ptr
));
10498 case DW_FORM_ref_udata
:
10499 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
10500 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
10501 info_ptr
+= bytes_read
;
10503 case DW_FORM_indirect
:
10504 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10505 info_ptr
+= bytes_read
;
10506 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
10509 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
10510 dwarf_form_name (form
),
10511 bfd_get_filename (abfd
));
10514 /* We have seen instances where the compiler tried to emit a byte
10515 size attribute of -1 which ended up being encoded as an unsigned
10516 0xffffffff. Although 0xffffffff is technically a valid size value,
10517 an object of this size seems pretty unlikely so we can relatively
10518 safely treat these cases as if the size attribute was invalid and
10519 treat them as zero by default. */
10520 if (attr
->name
== DW_AT_byte_size
10521 && form
== DW_FORM_data4
10522 && DW_UNSND (attr
) >= 0xffffffff)
10525 (&symfile_complaints
,
10526 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
10527 hex_string (DW_UNSND (attr
)));
10528 DW_UNSND (attr
) = 0;
10534 /* Read an attribute described by an abbreviated attribute. */
10537 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
10538 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
10540 attr
->name
= abbrev
->name
;
10541 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
10544 /* Read dwarf information from a buffer. */
10546 static unsigned int
10547 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
10549 return bfd_get_8 (abfd
, buf
);
10553 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
10555 return bfd_get_signed_8 (abfd
, buf
);
10558 static unsigned int
10559 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
10561 return bfd_get_16 (abfd
, buf
);
10565 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
10567 return bfd_get_signed_16 (abfd
, buf
);
10570 static unsigned int
10571 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
10573 return bfd_get_32 (abfd
, buf
);
10577 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
10579 return bfd_get_signed_32 (abfd
, buf
);
10583 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
10585 return bfd_get_64 (abfd
, buf
);
10589 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
10590 unsigned int *bytes_read
)
10592 struct comp_unit_head
*cu_header
= &cu
->header
;
10593 CORE_ADDR retval
= 0;
10595 if (cu_header
->signed_addr_p
)
10597 switch (cu_header
->addr_size
)
10600 retval
= bfd_get_signed_16 (abfd
, buf
);
10603 retval
= bfd_get_signed_32 (abfd
, buf
);
10606 retval
= bfd_get_signed_64 (abfd
, buf
);
10609 internal_error (__FILE__
, __LINE__
,
10610 _("read_address: bad switch, signed [in module %s]"),
10611 bfd_get_filename (abfd
));
10616 switch (cu_header
->addr_size
)
10619 retval
= bfd_get_16 (abfd
, buf
);
10622 retval
= bfd_get_32 (abfd
, buf
);
10625 retval
= bfd_get_64 (abfd
, buf
);
10628 internal_error (__FILE__
, __LINE__
,
10629 _("read_address: bad switch, "
10630 "unsigned [in module %s]"),
10631 bfd_get_filename (abfd
));
10635 *bytes_read
= cu_header
->addr_size
;
10639 /* Read the initial length from a section. The (draft) DWARF 3
10640 specification allows the initial length to take up either 4 bytes
10641 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
10642 bytes describe the length and all offsets will be 8 bytes in length
10645 An older, non-standard 64-bit format is also handled by this
10646 function. The older format in question stores the initial length
10647 as an 8-byte quantity without an escape value. Lengths greater
10648 than 2^32 aren't very common which means that the initial 4 bytes
10649 is almost always zero. Since a length value of zero doesn't make
10650 sense for the 32-bit format, this initial zero can be considered to
10651 be an escape value which indicates the presence of the older 64-bit
10652 format. As written, the code can't detect (old format) lengths
10653 greater than 4GB. If it becomes necessary to handle lengths
10654 somewhat larger than 4GB, we could allow other small values (such
10655 as the non-sensical values of 1, 2, and 3) to also be used as
10656 escape values indicating the presence of the old format.
10658 The value returned via bytes_read should be used to increment the
10659 relevant pointer after calling read_initial_length().
10661 [ Note: read_initial_length() and read_offset() are based on the
10662 document entitled "DWARF Debugging Information Format", revision
10663 3, draft 8, dated November 19, 2001. This document was obtained
10666 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
10668 This document is only a draft and is subject to change. (So beware.)
10670 Details regarding the older, non-standard 64-bit format were
10671 determined empirically by examining 64-bit ELF files produced by
10672 the SGI toolchain on an IRIX 6.5 machine.
10674 - Kevin, July 16, 2002
10678 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
10680 LONGEST length
= bfd_get_32 (abfd
, buf
);
10682 if (length
== 0xffffffff)
10684 length
= bfd_get_64 (abfd
, buf
+ 4);
10687 else if (length
== 0)
10689 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
10690 length
= bfd_get_64 (abfd
, buf
);
10701 /* Cover function for read_initial_length.
10702 Returns the length of the object at BUF, and stores the size of the
10703 initial length in *BYTES_READ and stores the size that offsets will be in
10705 If the initial length size is not equivalent to that specified in
10706 CU_HEADER then issue a complaint.
10707 This is useful when reading non-comp-unit headers. */
10710 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
10711 const struct comp_unit_head
*cu_header
,
10712 unsigned int *bytes_read
,
10713 unsigned int *offset_size
)
10715 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
10717 gdb_assert (cu_header
->initial_length_size
== 4
10718 || cu_header
->initial_length_size
== 8
10719 || cu_header
->initial_length_size
== 12);
10721 if (cu_header
->initial_length_size
!= *bytes_read
)
10722 complaint (&symfile_complaints
,
10723 _("intermixed 32-bit and 64-bit DWARF sections"));
10725 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
10729 /* Read an offset from the data stream. The size of the offset is
10730 given by cu_header->offset_size. */
10733 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
10734 unsigned int *bytes_read
)
10736 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
10738 *bytes_read
= cu_header
->offset_size
;
10742 /* Read an offset from the data stream. */
10745 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
10747 LONGEST retval
= 0;
10749 switch (offset_size
)
10752 retval
= bfd_get_32 (abfd
, buf
);
10755 retval
= bfd_get_64 (abfd
, buf
);
10758 internal_error (__FILE__
, __LINE__
,
10759 _("read_offset_1: bad switch [in module %s]"),
10760 bfd_get_filename (abfd
));
10767 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
10769 /* If the size of a host char is 8 bits, we can return a pointer
10770 to the buffer, otherwise we have to copy the data to a buffer
10771 allocated on the temporary obstack. */
10772 gdb_assert (HOST_CHAR_BIT
== 8);
10777 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10779 /* If the size of a host char is 8 bits, we can return a pointer
10780 to the string, otherwise we have to copy the string to a buffer
10781 allocated on the temporary obstack. */
10782 gdb_assert (HOST_CHAR_BIT
== 8);
10785 *bytes_read_ptr
= 1;
10788 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
10789 return (char *) buf
;
10793 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
10795 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
10796 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
10797 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
10798 bfd_get_filename (abfd
));
10799 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
10800 error (_("DW_FORM_strp pointing outside of "
10801 ".debug_str section [in module %s]"),
10802 bfd_get_filename (abfd
));
10803 gdb_assert (HOST_CHAR_BIT
== 8);
10804 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
10806 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
10810 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
10811 const struct comp_unit_head
*cu_header
,
10812 unsigned int *bytes_read_ptr
)
10814 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
10816 return read_indirect_string_at_offset (abfd
, str_offset
);
10820 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10823 unsigned int num_read
;
10825 unsigned char byte
;
10833 byte
= bfd_get_8 (abfd
, buf
);
10836 result
|= ((ULONGEST
) (byte
& 127) << shift
);
10837 if ((byte
& 128) == 0)
10843 *bytes_read_ptr
= num_read
;
10848 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10851 int i
, shift
, num_read
;
10852 unsigned char byte
;
10860 byte
= bfd_get_8 (abfd
, buf
);
10863 result
|= ((LONGEST
) (byte
& 127) << shift
);
10865 if ((byte
& 128) == 0)
10870 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
10871 result
|= -(((LONGEST
) 1) << shift
);
10872 *bytes_read_ptr
= num_read
;
10876 /* Return a pointer to just past the end of an LEB128 number in BUF. */
10879 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
10885 byte
= bfd_get_8 (abfd
, buf
);
10887 if ((byte
& 128) == 0)
10893 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
10900 cu
->language
= language_c
;
10902 case DW_LANG_C_plus_plus
:
10903 cu
->language
= language_cplus
;
10906 cu
->language
= language_d
;
10908 case DW_LANG_Fortran77
:
10909 case DW_LANG_Fortran90
:
10910 case DW_LANG_Fortran95
:
10911 cu
->language
= language_fortran
;
10914 cu
->language
= language_go
;
10916 case DW_LANG_Mips_Assembler
:
10917 cu
->language
= language_asm
;
10920 cu
->language
= language_java
;
10922 case DW_LANG_Ada83
:
10923 case DW_LANG_Ada95
:
10924 cu
->language
= language_ada
;
10926 case DW_LANG_Modula2
:
10927 cu
->language
= language_m2
;
10929 case DW_LANG_Pascal83
:
10930 cu
->language
= language_pascal
;
10933 cu
->language
= language_objc
;
10935 case DW_LANG_Cobol74
:
10936 case DW_LANG_Cobol85
:
10938 cu
->language
= language_minimal
;
10941 cu
->language_defn
= language_def (cu
->language
);
10944 /* Return the named attribute or NULL if not there. */
10946 static struct attribute
*
10947 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
10952 struct attribute
*spec
= NULL
;
10954 for (i
= 0; i
< die
->num_attrs
; ++i
)
10956 if (die
->attrs
[i
].name
== name
)
10957 return &die
->attrs
[i
];
10958 if (die
->attrs
[i
].name
== DW_AT_specification
10959 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
10960 spec
= &die
->attrs
[i
];
10966 die
= follow_die_ref (die
, spec
, &cu
);
10972 /* Return the named attribute or NULL if not there,
10973 but do not follow DW_AT_specification, etc.
10974 This is for use in contexts where we're reading .debug_types dies.
10975 Following DW_AT_specification, DW_AT_abstract_origin will take us
10976 back up the chain, and we want to go down. */
10978 static struct attribute
*
10979 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
10980 struct dwarf2_cu
*cu
)
10984 for (i
= 0; i
< die
->num_attrs
; ++i
)
10985 if (die
->attrs
[i
].name
== name
)
10986 return &die
->attrs
[i
];
10991 /* Return non-zero iff the attribute NAME is defined for the given DIE,
10992 and holds a non-zero value. This function should only be used for
10993 DW_FORM_flag or DW_FORM_flag_present attributes. */
10996 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
10998 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
11000 return (attr
&& DW_UNSND (attr
));
11004 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
11006 /* A DIE is a declaration if it has a DW_AT_declaration attribute
11007 which value is non-zero. However, we have to be careful with
11008 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
11009 (via dwarf2_flag_true_p) follows this attribute. So we may
11010 end up accidently finding a declaration attribute that belongs
11011 to a different DIE referenced by the specification attribute,
11012 even though the given DIE does not have a declaration attribute. */
11013 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
11014 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
11017 /* Return the die giving the specification for DIE, if there is
11018 one. *SPEC_CU is the CU containing DIE on input, and the CU
11019 containing the return value on output. If there is no
11020 specification, but there is an abstract origin, that is
11023 static struct die_info
*
11024 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
11026 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
11029 if (spec_attr
== NULL
)
11030 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
11032 if (spec_attr
== NULL
)
11035 return follow_die_ref (die
, spec_attr
, spec_cu
);
11038 /* Free the line_header structure *LH, and any arrays and strings it
11040 NOTE: This is also used as a "cleanup" function. */
11043 free_line_header (struct line_header
*lh
)
11045 if (lh
->standard_opcode_lengths
)
11046 xfree (lh
->standard_opcode_lengths
);
11048 /* Remember that all the lh->file_names[i].name pointers are
11049 pointers into debug_line_buffer, and don't need to be freed. */
11050 if (lh
->file_names
)
11051 xfree (lh
->file_names
);
11053 /* Similarly for the include directory names. */
11054 if (lh
->include_dirs
)
11055 xfree (lh
->include_dirs
);
11060 /* Add an entry to LH's include directory table. */
11063 add_include_dir (struct line_header
*lh
, char *include_dir
)
11065 /* Grow the array if necessary. */
11066 if (lh
->include_dirs_size
== 0)
11068 lh
->include_dirs_size
= 1; /* for testing */
11069 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
11070 * sizeof (*lh
->include_dirs
));
11072 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
11074 lh
->include_dirs_size
*= 2;
11075 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
11076 (lh
->include_dirs_size
11077 * sizeof (*lh
->include_dirs
)));
11080 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
11083 /* Add an entry to LH's file name table. */
11086 add_file_name (struct line_header
*lh
,
11088 unsigned int dir_index
,
11089 unsigned int mod_time
,
11090 unsigned int length
)
11092 struct file_entry
*fe
;
11094 /* Grow the array if necessary. */
11095 if (lh
->file_names_size
== 0)
11097 lh
->file_names_size
= 1; /* for testing */
11098 lh
->file_names
= xmalloc (lh
->file_names_size
11099 * sizeof (*lh
->file_names
));
11101 else if (lh
->num_file_names
>= lh
->file_names_size
)
11103 lh
->file_names_size
*= 2;
11104 lh
->file_names
= xrealloc (lh
->file_names
,
11105 (lh
->file_names_size
11106 * sizeof (*lh
->file_names
)));
11109 fe
= &lh
->file_names
[lh
->num_file_names
++];
11111 fe
->dir_index
= dir_index
;
11112 fe
->mod_time
= mod_time
;
11113 fe
->length
= length
;
11114 fe
->included_p
= 0;
11118 /* Read the statement program header starting at OFFSET in
11119 .debug_line, according to the endianness of ABFD. Return a pointer
11120 to a struct line_header, allocated using xmalloc.
11122 NOTE: the strings in the include directory and file name tables of
11123 the returned object point into debug_line_buffer, and must not be
11126 static struct line_header
*
11127 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
11128 struct dwarf2_cu
*cu
)
11130 struct cleanup
*back_to
;
11131 struct line_header
*lh
;
11132 gdb_byte
*line_ptr
;
11133 unsigned int bytes_read
, offset_size
;
11135 char *cur_dir
, *cur_file
;
11137 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
11138 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
11140 complaint (&symfile_complaints
, _("missing .debug_line section"));
11144 /* Make sure that at least there's room for the total_length field.
11145 That could be 12 bytes long, but we're just going to fudge that. */
11146 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
11148 dwarf2_statement_list_fits_in_line_number_section_complaint ();
11152 lh
= xmalloc (sizeof (*lh
));
11153 memset (lh
, 0, sizeof (*lh
));
11154 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
11157 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
11159 /* Read in the header. */
11161 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
11162 &bytes_read
, &offset_size
);
11163 line_ptr
+= bytes_read
;
11164 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
11165 + dwarf2_per_objfile
->line
.size
))
11167 dwarf2_statement_list_fits_in_line_number_section_complaint ();
11170 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
11171 lh
->version
= read_2_bytes (abfd
, line_ptr
);
11173 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
11174 line_ptr
+= offset_size
;
11175 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
11177 if (lh
->version
>= 4)
11179 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
11183 lh
->maximum_ops_per_instruction
= 1;
11185 if (lh
->maximum_ops_per_instruction
== 0)
11187 lh
->maximum_ops_per_instruction
= 1;
11188 complaint (&symfile_complaints
,
11189 _("invalid maximum_ops_per_instruction "
11190 "in `.debug_line' section"));
11193 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
11195 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
11197 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
11199 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
11201 lh
->standard_opcode_lengths
11202 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
11204 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
11205 for (i
= 1; i
< lh
->opcode_base
; ++i
)
11207 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
11211 /* Read directory table. */
11212 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
11214 line_ptr
+= bytes_read
;
11215 add_include_dir (lh
, cur_dir
);
11217 line_ptr
+= bytes_read
;
11219 /* Read file name table. */
11220 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
11222 unsigned int dir_index
, mod_time
, length
;
11224 line_ptr
+= bytes_read
;
11225 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11226 line_ptr
+= bytes_read
;
11227 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11228 line_ptr
+= bytes_read
;
11229 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11230 line_ptr
+= bytes_read
;
11232 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
11234 line_ptr
+= bytes_read
;
11235 lh
->statement_program_start
= line_ptr
;
11237 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
11238 + dwarf2_per_objfile
->line
.size
))
11239 complaint (&symfile_complaints
,
11240 _("line number info header doesn't "
11241 "fit in `.debug_line' section"));
11243 discard_cleanups (back_to
);
11247 /* Subroutine of dwarf_decode_lines to simplify it.
11248 Return the file name of the psymtab for included file FILE_INDEX
11249 in line header LH of PST.
11250 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
11251 If space for the result is malloc'd, it will be freed by a cleanup.
11252 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
11255 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
11256 const struct partial_symtab
*pst
,
11257 const char *comp_dir
)
11259 const struct file_entry fe
= lh
->file_names
[file_index
];
11260 char *include_name
= fe
.name
;
11261 char *include_name_to_compare
= include_name
;
11262 char *dir_name
= NULL
;
11263 const char *pst_filename
;
11264 char *copied_name
= NULL
;
11268 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
11270 if (!IS_ABSOLUTE_PATH (include_name
)
11271 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
11273 /* Avoid creating a duplicate psymtab for PST.
11274 We do this by comparing INCLUDE_NAME and PST_FILENAME.
11275 Before we do the comparison, however, we need to account
11276 for DIR_NAME and COMP_DIR.
11277 First prepend dir_name (if non-NULL). If we still don't
11278 have an absolute path prepend comp_dir (if non-NULL).
11279 However, the directory we record in the include-file's
11280 psymtab does not contain COMP_DIR (to match the
11281 corresponding symtab(s)).
11286 bash$ gcc -g ./hello.c
11287 include_name = "hello.c"
11289 DW_AT_comp_dir = comp_dir = "/tmp"
11290 DW_AT_name = "./hello.c" */
11292 if (dir_name
!= NULL
)
11294 include_name
= concat (dir_name
, SLASH_STRING
,
11295 include_name
, (char *)NULL
);
11296 include_name_to_compare
= include_name
;
11297 make_cleanup (xfree
, include_name
);
11299 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
11301 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
11302 include_name
, (char *)NULL
);
11306 pst_filename
= pst
->filename
;
11307 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
11309 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
11310 pst_filename
, (char *)NULL
);
11311 pst_filename
= copied_name
;
11314 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
11316 if (include_name_to_compare
!= include_name
)
11317 xfree (include_name_to_compare
);
11318 if (copied_name
!= NULL
)
11319 xfree (copied_name
);
11323 return include_name
;
11326 /* Ignore this record_line request. */
11329 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
11334 /* Subroutine of dwarf_decode_lines to simplify it.
11335 Process the line number information in LH. */
11338 dwarf_decode_lines_1 (struct line_header
*lh
, const char *comp_dir
,
11339 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
11341 gdb_byte
*line_ptr
, *extended_end
;
11342 gdb_byte
*line_end
;
11343 unsigned int bytes_read
, extended_len
;
11344 unsigned char op_code
, extended_op
, adj_opcode
;
11345 CORE_ADDR baseaddr
;
11346 struct objfile
*objfile
= cu
->objfile
;
11347 bfd
*abfd
= objfile
->obfd
;
11348 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11349 const int decode_for_pst_p
= (pst
!= NULL
);
11350 struct subfile
*last_subfile
= NULL
;
11351 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
11354 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11356 line_ptr
= lh
->statement_program_start
;
11357 line_end
= lh
->statement_program_end
;
11359 /* Read the statement sequences until there's nothing left. */
11360 while (line_ptr
< line_end
)
11362 /* state machine registers */
11363 CORE_ADDR address
= 0;
11364 unsigned int file
= 1;
11365 unsigned int line
= 1;
11366 unsigned int column
= 0;
11367 int is_stmt
= lh
->default_is_stmt
;
11368 int basic_block
= 0;
11369 int end_sequence
= 0;
11371 unsigned char op_index
= 0;
11373 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
11375 /* Start a subfile for the current file of the state machine. */
11376 /* lh->include_dirs and lh->file_names are 0-based, but the
11377 directory and file name numbers in the statement program
11379 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
11383 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11385 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11388 /* Decode the table. */
11389 while (!end_sequence
)
11391 op_code
= read_1_byte (abfd
, line_ptr
);
11393 if (line_ptr
> line_end
)
11395 dwarf2_debug_line_missing_end_sequence_complaint ();
11399 if (op_code
>= lh
->opcode_base
)
11401 /* Special operand. */
11402 adj_opcode
= op_code
- lh
->opcode_base
;
11403 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
11404 / lh
->maximum_ops_per_instruction
)
11405 * lh
->minimum_instruction_length
);
11406 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
11407 % lh
->maximum_ops_per_instruction
);
11408 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
11409 if (lh
->num_file_names
< file
|| file
== 0)
11410 dwarf2_debug_line_missing_file_complaint ();
11411 /* For now we ignore lines not starting on an
11412 instruction boundary. */
11413 else if (op_index
== 0)
11415 lh
->file_names
[file
- 1].included_p
= 1;
11416 if (!decode_for_pst_p
&& is_stmt
)
11418 if (last_subfile
!= current_subfile
)
11420 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11422 (*p_record_line
) (last_subfile
, 0, addr
);
11423 last_subfile
= current_subfile
;
11425 /* Append row to matrix using current values. */
11426 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11427 (*p_record_line
) (current_subfile
, line
, addr
);
11432 else switch (op_code
)
11434 case DW_LNS_extended_op
:
11435 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
11437 line_ptr
+= bytes_read
;
11438 extended_end
= line_ptr
+ extended_len
;
11439 extended_op
= read_1_byte (abfd
, line_ptr
);
11441 switch (extended_op
)
11443 case DW_LNE_end_sequence
:
11444 p_record_line
= record_line
;
11447 case DW_LNE_set_address
:
11448 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
11450 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
11452 /* This line table is for a function which has been
11453 GCd by the linker. Ignore it. PR gdb/12528 */
11456 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
11458 complaint (&symfile_complaints
,
11459 _(".debug_line address at offset 0x%lx is 0 "
11461 line_offset
, objfile
->name
);
11462 p_record_line
= noop_record_line
;
11466 line_ptr
+= bytes_read
;
11467 address
+= baseaddr
;
11469 case DW_LNE_define_file
:
11472 unsigned int dir_index
, mod_time
, length
;
11474 cur_file
= read_direct_string (abfd
, line_ptr
,
11476 line_ptr
+= bytes_read
;
11478 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11479 line_ptr
+= bytes_read
;
11481 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11482 line_ptr
+= bytes_read
;
11484 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11485 line_ptr
+= bytes_read
;
11486 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
11489 case DW_LNE_set_discriminator
:
11490 /* The discriminator is not interesting to the debugger;
11492 line_ptr
= extended_end
;
11495 complaint (&symfile_complaints
,
11496 _("mangled .debug_line section"));
11499 /* Make sure that we parsed the extended op correctly. If e.g.
11500 we expected a different address size than the producer used,
11501 we may have read the wrong number of bytes. */
11502 if (line_ptr
!= extended_end
)
11504 complaint (&symfile_complaints
,
11505 _("mangled .debug_line section"));
11510 if (lh
->num_file_names
< file
|| file
== 0)
11511 dwarf2_debug_line_missing_file_complaint ();
11514 lh
->file_names
[file
- 1].included_p
= 1;
11515 if (!decode_for_pst_p
&& is_stmt
)
11517 if (last_subfile
!= current_subfile
)
11519 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11521 (*p_record_line
) (last_subfile
, 0, addr
);
11522 last_subfile
= current_subfile
;
11524 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11525 (*p_record_line
) (current_subfile
, line
, addr
);
11530 case DW_LNS_advance_pc
:
11533 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11535 address
+= (((op_index
+ adjust
)
11536 / lh
->maximum_ops_per_instruction
)
11537 * lh
->minimum_instruction_length
);
11538 op_index
= ((op_index
+ adjust
)
11539 % lh
->maximum_ops_per_instruction
);
11540 line_ptr
+= bytes_read
;
11543 case DW_LNS_advance_line
:
11544 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
11545 line_ptr
+= bytes_read
;
11547 case DW_LNS_set_file
:
11549 /* The arrays lh->include_dirs and lh->file_names are
11550 0-based, but the directory and file name numbers in
11551 the statement program are 1-based. */
11552 struct file_entry
*fe
;
11555 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11556 line_ptr
+= bytes_read
;
11557 if (lh
->num_file_names
< file
|| file
== 0)
11558 dwarf2_debug_line_missing_file_complaint ();
11561 fe
= &lh
->file_names
[file
- 1];
11563 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11564 if (!decode_for_pst_p
)
11566 last_subfile
= current_subfile
;
11567 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11572 case DW_LNS_set_column
:
11573 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11574 line_ptr
+= bytes_read
;
11576 case DW_LNS_negate_stmt
:
11577 is_stmt
= (!is_stmt
);
11579 case DW_LNS_set_basic_block
:
11582 /* Add to the address register of the state machine the
11583 address increment value corresponding to special opcode
11584 255. I.e., this value is scaled by the minimum
11585 instruction length since special opcode 255 would have
11586 scaled the increment. */
11587 case DW_LNS_const_add_pc
:
11589 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
11591 address
+= (((op_index
+ adjust
)
11592 / lh
->maximum_ops_per_instruction
)
11593 * lh
->minimum_instruction_length
);
11594 op_index
= ((op_index
+ adjust
)
11595 % lh
->maximum_ops_per_instruction
);
11598 case DW_LNS_fixed_advance_pc
:
11599 address
+= read_2_bytes (abfd
, line_ptr
);
11605 /* Unknown standard opcode, ignore it. */
11608 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
11610 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11611 line_ptr
+= bytes_read
;
11616 if (lh
->num_file_names
< file
|| file
== 0)
11617 dwarf2_debug_line_missing_file_complaint ();
11620 lh
->file_names
[file
- 1].included_p
= 1;
11621 if (!decode_for_pst_p
)
11623 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11624 (*p_record_line
) (current_subfile
, 0, addr
);
11630 /* Decode the Line Number Program (LNP) for the given line_header
11631 structure and CU. The actual information extracted and the type
11632 of structures created from the LNP depends on the value of PST.
11634 1. If PST is NULL, then this procedure uses the data from the program
11635 to create all necessary symbol tables, and their linetables.
11637 2. If PST is not NULL, this procedure reads the program to determine
11638 the list of files included by the unit represented by PST, and
11639 builds all the associated partial symbol tables.
11641 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
11642 It is used for relative paths in the line table.
11643 NOTE: When processing partial symtabs (pst != NULL),
11644 comp_dir == pst->dirname.
11646 NOTE: It is important that psymtabs have the same file name (via strcmp)
11647 as the corresponding symtab. Since COMP_DIR is not used in the name of the
11648 symtab we don't use it in the name of the psymtabs we create.
11649 E.g. expand_line_sal requires this when finding psymtabs to expand.
11650 A good testcase for this is mb-inline.exp. */
11653 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
11654 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
11655 int want_line_info
)
11657 struct objfile
*objfile
= cu
->objfile
;
11658 const int decode_for_pst_p
= (pst
!= NULL
);
11659 struct subfile
*first_subfile
= current_subfile
;
11661 if (want_line_info
)
11662 dwarf_decode_lines_1 (lh
, comp_dir
, cu
, pst
);
11664 if (decode_for_pst_p
)
11668 /* Now that we're done scanning the Line Header Program, we can
11669 create the psymtab of each included file. */
11670 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
11671 if (lh
->file_names
[file_index
].included_p
== 1)
11673 char *include_name
=
11674 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
11675 if (include_name
!= NULL
)
11676 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
11681 /* Make sure a symtab is created for every file, even files
11682 which contain only variables (i.e. no code with associated
11686 for (i
= 0; i
< lh
->num_file_names
; i
++)
11689 struct file_entry
*fe
;
11691 fe
= &lh
->file_names
[i
];
11693 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11694 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11696 /* Skip the main file; we don't need it, and it must be
11697 allocated last, so that it will show up before the
11698 non-primary symtabs in the objfile's symtab list. */
11699 if (current_subfile
== first_subfile
)
11702 if (current_subfile
->symtab
== NULL
)
11703 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
11705 fe
->symtab
= current_subfile
->symtab
;
11710 /* Start a subfile for DWARF. FILENAME is the name of the file and
11711 DIRNAME the name of the source directory which contains FILENAME
11712 or NULL if not known. COMP_DIR is the compilation directory for the
11713 linetable's compilation unit or NULL if not known.
11714 This routine tries to keep line numbers from identical absolute and
11715 relative file names in a common subfile.
11717 Using the `list' example from the GDB testsuite, which resides in
11718 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
11719 of /srcdir/list0.c yields the following debugging information for list0.c:
11721 DW_AT_name: /srcdir/list0.c
11722 DW_AT_comp_dir: /compdir
11723 files.files[0].name: list0.h
11724 files.files[0].dir: /srcdir
11725 files.files[1].name: list0.c
11726 files.files[1].dir: /srcdir
11728 The line number information for list0.c has to end up in a single
11729 subfile, so that `break /srcdir/list0.c:1' works as expected.
11730 start_subfile will ensure that this happens provided that we pass the
11731 concatenation of files.files[1].dir and files.files[1].name as the
11735 dwarf2_start_subfile (char *filename
, const char *dirname
,
11736 const char *comp_dir
)
11740 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
11741 `start_symtab' will always pass the contents of DW_AT_comp_dir as
11742 second argument to start_subfile. To be consistent, we do the
11743 same here. In order not to lose the line information directory,
11744 we concatenate it to the filename when it makes sense.
11745 Note that the Dwarf3 standard says (speaking of filenames in line
11746 information): ``The directory index is ignored for file names
11747 that represent full path names''. Thus ignoring dirname in the
11748 `else' branch below isn't an issue. */
11750 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
11751 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
11753 fullname
= filename
;
11755 start_subfile (fullname
, comp_dir
);
11757 if (fullname
!= filename
)
11762 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
11763 struct dwarf2_cu
*cu
)
11765 struct objfile
*objfile
= cu
->objfile
;
11766 struct comp_unit_head
*cu_header
= &cu
->header
;
11768 /* NOTE drow/2003-01-30: There used to be a comment and some special
11769 code here to turn a symbol with DW_AT_external and a
11770 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
11771 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
11772 with some versions of binutils) where shared libraries could have
11773 relocations against symbols in their debug information - the
11774 minimal symbol would have the right address, but the debug info
11775 would not. It's no longer necessary, because we will explicitly
11776 apply relocations when we read in the debug information now. */
11778 /* A DW_AT_location attribute with no contents indicates that a
11779 variable has been optimized away. */
11780 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
11782 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11786 /* Handle one degenerate form of location expression specially, to
11787 preserve GDB's previous behavior when section offsets are
11788 specified. If this is just a DW_OP_addr then mark this symbol
11791 if (attr_form_is_block (attr
)
11792 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
11793 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
11795 unsigned int dummy
;
11797 SYMBOL_VALUE_ADDRESS (sym
) =
11798 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
11799 SYMBOL_CLASS (sym
) = LOC_STATIC
;
11800 fixup_symbol_section (sym
, objfile
);
11801 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
11802 SYMBOL_SECTION (sym
));
11806 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
11807 expression evaluator, and use LOC_COMPUTED only when necessary
11808 (i.e. when the value of a register or memory location is
11809 referenced, or a thread-local block, etc.). Then again, it might
11810 not be worthwhile. I'm assuming that it isn't unless performance
11811 or memory numbers show me otherwise. */
11813 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
11814 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11816 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
11817 cu
->has_loclist
= 1;
11820 /* Given a pointer to a DWARF information entry, figure out if we need
11821 to make a symbol table entry for it, and if so, create a new entry
11822 and return a pointer to it.
11823 If TYPE is NULL, determine symbol type from the die, otherwise
11824 used the passed type.
11825 If SPACE is not NULL, use it to hold the new symbol. If it is
11826 NULL, allocate a new symbol on the objfile's obstack. */
11828 static struct symbol
*
11829 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
11830 struct symbol
*space
)
11832 struct objfile
*objfile
= cu
->objfile
;
11833 struct symbol
*sym
= NULL
;
11835 struct attribute
*attr
= NULL
;
11836 struct attribute
*attr2
= NULL
;
11837 CORE_ADDR baseaddr
;
11838 struct pending
**list_to_add
= NULL
;
11840 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
11842 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11844 name
= dwarf2_name (die
, cu
);
11847 const char *linkagename
;
11848 int suppress_add
= 0;
11853 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
11854 OBJSTAT (objfile
, n_syms
++);
11856 /* Cache this symbol's name and the name's demangled form (if any). */
11857 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
11858 linkagename
= dwarf2_physname (name
, die
, cu
);
11859 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
11861 /* Fortran does not have mangling standard and the mangling does differ
11862 between gfortran, iFort etc. */
11863 if (cu
->language
== language_fortran
11864 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
11865 symbol_set_demangled_name (&(sym
->ginfo
),
11866 (char *) dwarf2_full_name (name
, die
, cu
),
11869 /* Default assumptions.
11870 Use the passed type or decode it from the die. */
11871 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11872 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11874 SYMBOL_TYPE (sym
) = type
;
11876 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
11877 attr
= dwarf2_attr (die
,
11878 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
11882 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
11885 attr
= dwarf2_attr (die
,
11886 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
11890 int file_index
= DW_UNSND (attr
);
11892 if (cu
->line_header
== NULL
11893 || file_index
> cu
->line_header
->num_file_names
)
11894 complaint (&symfile_complaints
,
11895 _("file index out of range"));
11896 else if (file_index
> 0)
11898 struct file_entry
*fe
;
11900 fe
= &cu
->line_header
->file_names
[file_index
- 1];
11901 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
11908 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11911 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
11913 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
11914 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
11915 SYMBOL_CLASS (sym
) = LOC_LABEL
;
11916 add_symbol_to_list (sym
, cu
->list_in_scope
);
11918 case DW_TAG_subprogram
:
11919 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11921 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11922 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11923 if ((attr2
&& (DW_UNSND (attr2
) != 0))
11924 || cu
->language
== language_ada
)
11926 /* Subprograms marked external are stored as a global symbol.
11927 Ada subprograms, whether marked external or not, are always
11928 stored as a global symbol, because we want to be able to
11929 access them globally. For instance, we want to be able
11930 to break on a nested subprogram without having to
11931 specify the context. */
11932 list_to_add
= &global_symbols
;
11936 list_to_add
= cu
->list_in_scope
;
11939 case DW_TAG_inlined_subroutine
:
11940 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11942 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11943 SYMBOL_INLINED (sym
) = 1;
11944 list_to_add
= cu
->list_in_scope
;
11946 case DW_TAG_template_value_param
:
11948 /* Fall through. */
11949 case DW_TAG_constant
:
11950 case DW_TAG_variable
:
11951 case DW_TAG_member
:
11952 /* Compilation with minimal debug info may result in
11953 variables with missing type entries. Change the
11954 misleading `void' type to something sensible. */
11955 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
11957 = objfile_type (objfile
)->nodebug_data_symbol
;
11959 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11960 /* In the case of DW_TAG_member, we should only be called for
11961 static const members. */
11962 if (die
->tag
== DW_TAG_member
)
11964 /* dwarf2_add_field uses die_is_declaration,
11965 so we do the same. */
11966 gdb_assert (die_is_declaration (die
, cu
));
11971 dwarf2_const_value (attr
, sym
, cu
);
11972 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11975 if (attr2
&& (DW_UNSND (attr2
) != 0))
11976 list_to_add
= &global_symbols
;
11978 list_to_add
= cu
->list_in_scope
;
11982 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11985 var_decode_location (attr
, sym
, cu
);
11986 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11987 if (SYMBOL_CLASS (sym
) == LOC_STATIC
11988 && SYMBOL_VALUE_ADDRESS (sym
) == 0
11989 && !dwarf2_per_objfile
->has_section_at_zero
)
11991 /* When a static variable is eliminated by the linker,
11992 the corresponding debug information is not stripped
11993 out, but the variable address is set to null;
11994 do not add such variables into symbol table. */
11996 else if (attr2
&& (DW_UNSND (attr2
) != 0))
11998 /* Workaround gfortran PR debug/40040 - it uses
11999 DW_AT_location for variables in -fPIC libraries which may
12000 get overriden by other libraries/executable and get
12001 a different address. Resolve it by the minimal symbol
12002 which may come from inferior's executable using copy
12003 relocation. Make this workaround only for gfortran as for
12004 other compilers GDB cannot guess the minimal symbol
12005 Fortran mangling kind. */
12006 if (cu
->language
== language_fortran
&& die
->parent
12007 && die
->parent
->tag
== DW_TAG_module
12009 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
12010 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
12012 /* A variable with DW_AT_external is never static,
12013 but it may be block-scoped. */
12014 list_to_add
= (cu
->list_in_scope
== &file_symbols
12015 ? &global_symbols
: cu
->list_in_scope
);
12018 list_to_add
= cu
->list_in_scope
;
12022 /* We do not know the address of this symbol.
12023 If it is an external symbol and we have type information
12024 for it, enter the symbol as a LOC_UNRESOLVED symbol.
12025 The address of the variable will then be determined from
12026 the minimal symbol table whenever the variable is
12028 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
12029 if (attr2
&& (DW_UNSND (attr2
) != 0)
12030 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
12032 /* A variable with DW_AT_external is never static, but it
12033 may be block-scoped. */
12034 list_to_add
= (cu
->list_in_scope
== &file_symbols
12035 ? &global_symbols
: cu
->list_in_scope
);
12037 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
12039 else if (!die_is_declaration (die
, cu
))
12041 /* Use the default LOC_OPTIMIZED_OUT class. */
12042 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
12044 list_to_add
= cu
->list_in_scope
;
12048 case DW_TAG_formal_parameter
:
12049 /* If we are inside a function, mark this as an argument. If
12050 not, we might be looking at an argument to an inlined function
12051 when we do not have enough information to show inlined frames;
12052 pretend it's a local variable in that case so that the user can
12054 if (context_stack_depth
> 0
12055 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
12056 SYMBOL_IS_ARGUMENT (sym
) = 1;
12057 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
12060 var_decode_location (attr
, sym
, cu
);
12062 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
12065 dwarf2_const_value (attr
, sym
, cu
);
12068 list_to_add
= cu
->list_in_scope
;
12070 case DW_TAG_unspecified_parameters
:
12071 /* From varargs functions; gdb doesn't seem to have any
12072 interest in this information, so just ignore it for now.
12075 case DW_TAG_template_type_param
:
12077 /* Fall through. */
12078 case DW_TAG_class_type
:
12079 case DW_TAG_interface_type
:
12080 case DW_TAG_structure_type
:
12081 case DW_TAG_union_type
:
12082 case DW_TAG_set_type
:
12083 case DW_TAG_enumeration_type
:
12084 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
12085 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
12088 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
12089 really ever be static objects: otherwise, if you try
12090 to, say, break of a class's method and you're in a file
12091 which doesn't mention that class, it won't work unless
12092 the check for all static symbols in lookup_symbol_aux
12093 saves you. See the OtherFileClass tests in
12094 gdb.c++/namespace.exp. */
12098 list_to_add
= (cu
->list_in_scope
== &file_symbols
12099 && (cu
->language
== language_cplus
12100 || cu
->language
== language_java
)
12101 ? &global_symbols
: cu
->list_in_scope
);
12103 /* The semantics of C++ state that "struct foo {
12104 ... }" also defines a typedef for "foo". A Java
12105 class declaration also defines a typedef for the
12107 if (cu
->language
== language_cplus
12108 || cu
->language
== language_java
12109 || cu
->language
== language_ada
)
12111 /* The symbol's name is already allocated along
12112 with this objfile, so we don't need to
12113 duplicate it for the type. */
12114 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
12115 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
12120 case DW_TAG_typedef
:
12121 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
12122 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
12123 list_to_add
= cu
->list_in_scope
;
12125 case DW_TAG_base_type
:
12126 case DW_TAG_subrange_type
:
12127 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
12128 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
12129 list_to_add
= cu
->list_in_scope
;
12131 case DW_TAG_enumerator
:
12132 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
12135 dwarf2_const_value (attr
, sym
, cu
);
12138 /* NOTE: carlton/2003-11-10: See comment above in the
12139 DW_TAG_class_type, etc. block. */
12141 list_to_add
= (cu
->list_in_scope
== &file_symbols
12142 && (cu
->language
== language_cplus
12143 || cu
->language
== language_java
)
12144 ? &global_symbols
: cu
->list_in_scope
);
12147 case DW_TAG_namespace
:
12148 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
12149 list_to_add
= &global_symbols
;
12152 /* Not a tag we recognize. Hopefully we aren't processing
12153 trash data, but since we must specifically ignore things
12154 we don't recognize, there is nothing else we should do at
12156 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
12157 dwarf_tag_name (die
->tag
));
12163 sym
->hash_next
= objfile
->template_symbols
;
12164 objfile
->template_symbols
= sym
;
12165 list_to_add
= NULL
;
12168 if (list_to_add
!= NULL
)
12169 add_symbol_to_list (sym
, list_to_add
);
12171 /* For the benefit of old versions of GCC, check for anonymous
12172 namespaces based on the demangled name. */
12173 if (!processing_has_namespace_info
12174 && cu
->language
== language_cplus
)
12175 cp_scan_for_anonymous_namespaces (sym
, objfile
);
12180 /* A wrapper for new_symbol_full that always allocates a new symbol. */
12182 static struct symbol
*
12183 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
12185 return new_symbol_full (die
, type
, cu
, NULL
);
12188 /* Given an attr with a DW_FORM_dataN value in host byte order,
12189 zero-extend it as appropriate for the symbol's type. The DWARF
12190 standard (v4) is not entirely clear about the meaning of using
12191 DW_FORM_dataN for a constant with a signed type, where the type is
12192 wider than the data. The conclusion of a discussion on the DWARF
12193 list was that this is unspecified. We choose to always zero-extend
12194 because that is the interpretation long in use by GCC. */
12197 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
12198 const char *name
, struct obstack
*obstack
,
12199 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
12201 struct objfile
*objfile
= cu
->objfile
;
12202 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
12203 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
12204 LONGEST l
= DW_UNSND (attr
);
12206 if (bits
< sizeof (*value
) * 8)
12208 l
&= ((LONGEST
) 1 << bits
) - 1;
12211 else if (bits
== sizeof (*value
) * 8)
12215 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
12216 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
12223 /* Read a constant value from an attribute. Either set *VALUE, or if
12224 the value does not fit in *VALUE, set *BYTES - either already
12225 allocated on the objfile obstack, or newly allocated on OBSTACK,
12226 or, set *BATON, if we translated the constant to a location
12230 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
12231 const char *name
, struct obstack
*obstack
,
12232 struct dwarf2_cu
*cu
,
12233 LONGEST
*value
, gdb_byte
**bytes
,
12234 struct dwarf2_locexpr_baton
**baton
)
12236 struct objfile
*objfile
= cu
->objfile
;
12237 struct comp_unit_head
*cu_header
= &cu
->header
;
12238 struct dwarf_block
*blk
;
12239 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
12240 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
12246 switch (attr
->form
)
12252 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
12253 dwarf2_const_value_length_mismatch_complaint (name
,
12254 cu_header
->addr_size
,
12255 TYPE_LENGTH (type
));
12256 /* Symbols of this form are reasonably rare, so we just
12257 piggyback on the existing location code rather than writing
12258 a new implementation of symbol_computed_ops. */
12259 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
12260 sizeof (struct dwarf2_locexpr_baton
));
12261 (*baton
)->per_cu
= cu
->per_cu
;
12262 gdb_assert ((*baton
)->per_cu
);
12264 (*baton
)->size
= 2 + cu_header
->addr_size
;
12265 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
12266 (*baton
)->data
= data
;
12268 data
[0] = DW_OP_addr
;
12269 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
12270 byte_order
, DW_ADDR (attr
));
12271 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
12274 case DW_FORM_string
:
12276 /* DW_STRING is already allocated on the objfile obstack, point
12278 *bytes
= (gdb_byte
*) DW_STRING (attr
);
12280 case DW_FORM_block1
:
12281 case DW_FORM_block2
:
12282 case DW_FORM_block4
:
12283 case DW_FORM_block
:
12284 case DW_FORM_exprloc
:
12285 blk
= DW_BLOCK (attr
);
12286 if (TYPE_LENGTH (type
) != blk
->size
)
12287 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
12288 TYPE_LENGTH (type
));
12289 *bytes
= blk
->data
;
12292 /* The DW_AT_const_value attributes are supposed to carry the
12293 symbol's value "represented as it would be on the target
12294 architecture." By the time we get here, it's already been
12295 converted to host endianness, so we just need to sign- or
12296 zero-extend it as appropriate. */
12297 case DW_FORM_data1
:
12298 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12299 obstack
, cu
, value
, 8);
12301 case DW_FORM_data2
:
12302 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12303 obstack
, cu
, value
, 16);
12305 case DW_FORM_data4
:
12306 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12307 obstack
, cu
, value
, 32);
12309 case DW_FORM_data8
:
12310 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12311 obstack
, cu
, value
, 64);
12314 case DW_FORM_sdata
:
12315 *value
= DW_SND (attr
);
12318 case DW_FORM_udata
:
12319 *value
= DW_UNSND (attr
);
12323 complaint (&symfile_complaints
,
12324 _("unsupported const value attribute form: '%s'"),
12325 dwarf_form_name (attr
->form
));
12332 /* Copy constant value from an attribute to a symbol. */
12335 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
12336 struct dwarf2_cu
*cu
)
12338 struct objfile
*objfile
= cu
->objfile
;
12339 struct comp_unit_head
*cu_header
= &cu
->header
;
12342 struct dwarf2_locexpr_baton
*baton
;
12344 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
12345 SYMBOL_PRINT_NAME (sym
),
12346 &objfile
->objfile_obstack
, cu
,
12347 &value
, &bytes
, &baton
);
12351 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
12352 SYMBOL_LOCATION_BATON (sym
) = baton
;
12353 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
12355 else if (bytes
!= NULL
)
12357 SYMBOL_VALUE_BYTES (sym
) = bytes
;
12358 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
12362 SYMBOL_VALUE (sym
) = value
;
12363 SYMBOL_CLASS (sym
) = LOC_CONST
;
12367 /* Return the type of the die in question using its DW_AT_type attribute. */
12369 static struct type
*
12370 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12372 struct attribute
*type_attr
;
12374 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
12377 /* A missing DW_AT_type represents a void type. */
12378 return objfile_type (cu
->objfile
)->builtin_void
;
12381 return lookup_die_type (die
, type_attr
, cu
);
12384 /* True iff CU's producer generates GNAT Ada auxiliary information
12385 that allows to find parallel types through that information instead
12386 of having to do expensive parallel lookups by type name. */
12389 need_gnat_info (struct dwarf2_cu
*cu
)
12391 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
12392 of GNAT produces this auxiliary information, without any indication
12393 that it is produced. Part of enhancing the FSF version of GNAT
12394 to produce that information will be to put in place an indicator
12395 that we can use in order to determine whether the descriptive type
12396 info is available or not. One suggestion that has been made is
12397 to use a new attribute, attached to the CU die. For now, assume
12398 that the descriptive type info is not available. */
12402 /* Return the auxiliary type of the die in question using its
12403 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
12404 attribute is not present. */
12406 static struct type
*
12407 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12409 struct attribute
*type_attr
;
12411 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
12415 return lookup_die_type (die
, type_attr
, cu
);
12418 /* If DIE has a descriptive_type attribute, then set the TYPE's
12419 descriptive type accordingly. */
12422 set_descriptive_type (struct type
*type
, struct die_info
*die
,
12423 struct dwarf2_cu
*cu
)
12425 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
12427 if (descriptive_type
)
12429 ALLOCATE_GNAT_AUX_TYPE (type
);
12430 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
12434 /* Return the containing type of the die in question using its
12435 DW_AT_containing_type attribute. */
12437 static struct type
*
12438 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12440 struct attribute
*type_attr
;
12442 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
12444 error (_("Dwarf Error: Problem turning containing type into gdb type "
12445 "[in module %s]"), cu
->objfile
->name
);
12447 return lookup_die_type (die
, type_attr
, cu
);
12450 /* Look up the type of DIE in CU using its type attribute ATTR.
12451 If there is no type substitute an error marker. */
12453 static struct type
*
12454 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
12455 struct dwarf2_cu
*cu
)
12457 struct objfile
*objfile
= cu
->objfile
;
12458 struct type
*this_type
;
12460 /* First see if we have it cached. */
12462 if (is_ref_attr (attr
))
12464 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
12466 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
12468 else if (attr
->form
== DW_FORM_ref_sig8
)
12470 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
12471 struct dwarf2_cu
*sig_cu
;
12472 sect_offset offset
;
12474 /* sig_type will be NULL if the signatured type is missing from
12476 if (sig_type
== NULL
)
12477 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
12478 "at 0x%x [in module %s]"),
12479 die
->offset
.sect_off
, objfile
->name
);
12481 gdb_assert (sig_type
->per_cu
.debug_types_section
);
12482 offset
.sect_off
= (sig_type
->per_cu
.offset
.sect_off
12483 + sig_type
->type_offset
.cu_off
);
12484 this_type
= get_die_type_at_offset (offset
, &sig_type
->per_cu
);
12488 dump_die_for_error (die
);
12489 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
12490 dwarf_attr_name (attr
->name
), objfile
->name
);
12493 /* If not cached we need to read it in. */
12495 if (this_type
== NULL
)
12497 struct die_info
*type_die
;
12498 struct dwarf2_cu
*type_cu
= cu
;
12500 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
12501 /* If the type is cached, we should have found it above. */
12502 gdb_assert (get_die_type (type_die
, type_cu
) == NULL
);
12503 this_type
= read_type_die_1 (type_die
, type_cu
);
12506 /* If we still don't have a type use an error marker. */
12508 if (this_type
== NULL
)
12510 char *message
, *saved
;
12512 /* read_type_die already issued a complaint. */
12513 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
12515 cu
->header
.offset
.sect_off
,
12516 die
->offset
.sect_off
);
12517 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
12518 message
, strlen (message
));
12521 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
12527 /* Return the type in DIE, CU.
12528 Returns NULL for invalid types.
12530 This first does a lookup in the appropriate type_hash table,
12531 and only reads the die in if necessary.
12533 NOTE: This can be called when reading in partial or full symbols. */
12535 static struct type
*
12536 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
12538 struct type
*this_type
;
12540 this_type
= get_die_type (die
, cu
);
12544 return read_type_die_1 (die
, cu
);
12547 /* Read the type in DIE, CU.
12548 Returns NULL for invalid types. */
12550 static struct type
*
12551 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
12553 struct type
*this_type
= NULL
;
12557 case DW_TAG_class_type
:
12558 case DW_TAG_interface_type
:
12559 case DW_TAG_structure_type
:
12560 case DW_TAG_union_type
:
12561 this_type
= read_structure_type (die
, cu
);
12563 case DW_TAG_enumeration_type
:
12564 this_type
= read_enumeration_type (die
, cu
);
12566 case DW_TAG_subprogram
:
12567 case DW_TAG_subroutine_type
:
12568 case DW_TAG_inlined_subroutine
:
12569 this_type
= read_subroutine_type (die
, cu
);
12571 case DW_TAG_array_type
:
12572 this_type
= read_array_type (die
, cu
);
12574 case DW_TAG_set_type
:
12575 this_type
= read_set_type (die
, cu
);
12577 case DW_TAG_pointer_type
:
12578 this_type
= read_tag_pointer_type (die
, cu
);
12580 case DW_TAG_ptr_to_member_type
:
12581 this_type
= read_tag_ptr_to_member_type (die
, cu
);
12583 case DW_TAG_reference_type
:
12584 this_type
= read_tag_reference_type (die
, cu
);
12586 case DW_TAG_const_type
:
12587 this_type
= read_tag_const_type (die
, cu
);
12589 case DW_TAG_volatile_type
:
12590 this_type
= read_tag_volatile_type (die
, cu
);
12592 case DW_TAG_string_type
:
12593 this_type
= read_tag_string_type (die
, cu
);
12595 case DW_TAG_typedef
:
12596 this_type
= read_typedef (die
, cu
);
12598 case DW_TAG_subrange_type
:
12599 this_type
= read_subrange_type (die
, cu
);
12601 case DW_TAG_base_type
:
12602 this_type
= read_base_type (die
, cu
);
12604 case DW_TAG_unspecified_type
:
12605 this_type
= read_unspecified_type (die
, cu
);
12607 case DW_TAG_namespace
:
12608 this_type
= read_namespace_type (die
, cu
);
12610 case DW_TAG_module
:
12611 this_type
= read_module_type (die
, cu
);
12614 complaint (&symfile_complaints
,
12615 _("unexpected tag in read_type_die: '%s'"),
12616 dwarf_tag_name (die
->tag
));
12623 /* See if we can figure out if the class lives in a namespace. We do
12624 this by looking for a member function; its demangled name will
12625 contain namespace info, if there is any.
12626 Return the computed name or NULL.
12627 Space for the result is allocated on the objfile's obstack.
12628 This is the full-die version of guess_partial_die_structure_name.
12629 In this case we know DIE has no useful parent. */
12632 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12634 struct die_info
*spec_die
;
12635 struct dwarf2_cu
*spec_cu
;
12636 struct die_info
*child
;
12639 spec_die
= die_specification (die
, &spec_cu
);
12640 if (spec_die
!= NULL
)
12646 for (child
= die
->child
;
12648 child
= child
->sibling
)
12650 if (child
->tag
== DW_TAG_subprogram
)
12652 struct attribute
*attr
;
12654 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
12656 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
12660 = language_class_name_from_physname (cu
->language_defn
,
12664 if (actual_name
!= NULL
)
12666 char *die_name
= dwarf2_name (die
, cu
);
12668 if (die_name
!= NULL
12669 && strcmp (die_name
, actual_name
) != 0)
12671 /* Strip off the class name from the full name.
12672 We want the prefix. */
12673 int die_name_len
= strlen (die_name
);
12674 int actual_name_len
= strlen (actual_name
);
12676 /* Test for '::' as a sanity check. */
12677 if (actual_name_len
> die_name_len
+ 2
12678 && actual_name
[actual_name_len
12679 - die_name_len
- 1] == ':')
12681 obsavestring (actual_name
,
12682 actual_name_len
- die_name_len
- 2,
12683 &cu
->objfile
->objfile_obstack
);
12686 xfree (actual_name
);
12695 /* GCC might emit a nameless typedef that has a linkage name. Determine the
12696 prefix part in such case. See
12697 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12700 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
12702 struct attribute
*attr
;
12705 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
12706 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
12709 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
12710 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
12713 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
12715 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
12716 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
12719 /* dwarf2_name had to be already called. */
12720 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
12722 /* Strip the base name, keep any leading namespaces/classes. */
12723 base
= strrchr (DW_STRING (attr
), ':');
12724 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
12727 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
12728 &cu
->objfile
->objfile_obstack
);
12731 /* Return the name of the namespace/class that DIE is defined within,
12732 or "" if we can't tell. The caller should not xfree the result.
12734 For example, if we're within the method foo() in the following
12744 then determine_prefix on foo's die will return "N::C". */
12746 static const char *
12747 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
12749 struct die_info
*parent
, *spec_die
;
12750 struct dwarf2_cu
*spec_cu
;
12751 struct type
*parent_type
;
12754 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
12755 && cu
->language
!= language_fortran
)
12758 retval
= anonymous_struct_prefix (die
, cu
);
12762 /* We have to be careful in the presence of DW_AT_specification.
12763 For example, with GCC 3.4, given the code
12767 // Definition of N::foo.
12771 then we'll have a tree of DIEs like this:
12773 1: DW_TAG_compile_unit
12774 2: DW_TAG_namespace // N
12775 3: DW_TAG_subprogram // declaration of N::foo
12776 4: DW_TAG_subprogram // definition of N::foo
12777 DW_AT_specification // refers to die #3
12779 Thus, when processing die #4, we have to pretend that we're in
12780 the context of its DW_AT_specification, namely the contex of die
12783 spec_die
= die_specification (die
, &spec_cu
);
12784 if (spec_die
== NULL
)
12785 parent
= die
->parent
;
12788 parent
= spec_die
->parent
;
12792 if (parent
== NULL
)
12794 else if (parent
->building_fullname
)
12797 const char *parent_name
;
12799 /* It has been seen on RealView 2.2 built binaries,
12800 DW_TAG_template_type_param types actually _defined_ as
12801 children of the parent class:
12804 template class <class Enum> Class{};
12805 Class<enum E> class_e;
12807 1: DW_TAG_class_type (Class)
12808 2: DW_TAG_enumeration_type (E)
12809 3: DW_TAG_enumerator (enum1:0)
12810 3: DW_TAG_enumerator (enum2:1)
12812 2: DW_TAG_template_type_param
12813 DW_AT_type DW_FORM_ref_udata (E)
12815 Besides being broken debug info, it can put GDB into an
12816 infinite loop. Consider:
12818 When we're building the full name for Class<E>, we'll start
12819 at Class, and go look over its template type parameters,
12820 finding E. We'll then try to build the full name of E, and
12821 reach here. We're now trying to build the full name of E,
12822 and look over the parent DIE for containing scope. In the
12823 broken case, if we followed the parent DIE of E, we'd again
12824 find Class, and once again go look at its template type
12825 arguments, etc., etc. Simply don't consider such parent die
12826 as source-level parent of this die (it can't be, the language
12827 doesn't allow it), and break the loop here. */
12828 name
= dwarf2_name (die
, cu
);
12829 parent_name
= dwarf2_name (parent
, cu
);
12830 complaint (&symfile_complaints
,
12831 _("template param type '%s' defined within parent '%s'"),
12832 name
? name
: "<unknown>",
12833 parent_name
? parent_name
: "<unknown>");
12837 switch (parent
->tag
)
12839 case DW_TAG_namespace
:
12840 parent_type
= read_type_die (parent
, cu
);
12841 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
12842 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
12843 Work around this problem here. */
12844 if (cu
->language
== language_cplus
12845 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
12847 /* We give a name to even anonymous namespaces. */
12848 return TYPE_TAG_NAME (parent_type
);
12849 case DW_TAG_class_type
:
12850 case DW_TAG_interface_type
:
12851 case DW_TAG_structure_type
:
12852 case DW_TAG_union_type
:
12853 case DW_TAG_module
:
12854 parent_type
= read_type_die (parent
, cu
);
12855 if (TYPE_TAG_NAME (parent_type
) != NULL
)
12856 return TYPE_TAG_NAME (parent_type
);
12858 /* An anonymous structure is only allowed non-static data
12859 members; no typedefs, no member functions, et cetera.
12860 So it does not need a prefix. */
12862 case DW_TAG_compile_unit
:
12863 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
12864 if (cu
->language
== language_cplus
12865 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
12866 && die
->child
!= NULL
12867 && (die
->tag
== DW_TAG_class_type
12868 || die
->tag
== DW_TAG_structure_type
12869 || die
->tag
== DW_TAG_union_type
))
12871 char *name
= guess_full_die_structure_name (die
, cu
);
12877 return determine_prefix (parent
, cu
);
12881 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
12882 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
12883 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
12884 an obconcat, otherwise allocate storage for the result. The CU argument is
12885 used to determine the language and hence, the appropriate separator. */
12887 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
12890 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
12891 int physname
, struct dwarf2_cu
*cu
)
12893 const char *lead
= "";
12896 if (suffix
== NULL
|| suffix
[0] == '\0'
12897 || prefix
== NULL
|| prefix
[0] == '\0')
12899 else if (cu
->language
== language_java
)
12901 else if (cu
->language
== language_fortran
&& physname
)
12903 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
12904 DW_AT_MIPS_linkage_name is preferred and used instead. */
12912 if (prefix
== NULL
)
12914 if (suffix
== NULL
)
12920 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
12922 strcpy (retval
, lead
);
12923 strcat (retval
, prefix
);
12924 strcat (retval
, sep
);
12925 strcat (retval
, suffix
);
12930 /* We have an obstack. */
12931 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
12935 /* Return sibling of die, NULL if no sibling. */
12937 static struct die_info
*
12938 sibling_die (struct die_info
*die
)
12940 return die
->sibling
;
12943 /* Get name of a die, return NULL if not found. */
12946 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
12947 struct obstack
*obstack
)
12949 if (name
&& cu
->language
== language_cplus
)
12951 char *canon_name
= cp_canonicalize_string (name
);
12953 if (canon_name
!= NULL
)
12955 if (strcmp (canon_name
, name
) != 0)
12956 name
= obsavestring (canon_name
, strlen (canon_name
),
12958 xfree (canon_name
);
12965 /* Get name of a die, return NULL if not found. */
12968 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12970 struct attribute
*attr
;
12972 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
12973 if ((!attr
|| !DW_STRING (attr
))
12974 && die
->tag
!= DW_TAG_class_type
12975 && die
->tag
!= DW_TAG_interface_type
12976 && die
->tag
!= DW_TAG_structure_type
12977 && die
->tag
!= DW_TAG_union_type
)
12982 case DW_TAG_compile_unit
:
12983 /* Compilation units have a DW_AT_name that is a filename, not
12984 a source language identifier. */
12985 case DW_TAG_enumeration_type
:
12986 case DW_TAG_enumerator
:
12987 /* These tags always have simple identifiers already; no need
12988 to canonicalize them. */
12989 return DW_STRING (attr
);
12991 case DW_TAG_subprogram
:
12992 /* Java constructors will all be named "<init>", so return
12993 the class name when we see this special case. */
12994 if (cu
->language
== language_java
12995 && DW_STRING (attr
) != NULL
12996 && strcmp (DW_STRING (attr
), "<init>") == 0)
12998 struct dwarf2_cu
*spec_cu
= cu
;
12999 struct die_info
*spec_die
;
13001 /* GCJ will output '<init>' for Java constructor names.
13002 For this special case, return the name of the parent class. */
13004 /* GCJ may output suprogram DIEs with AT_specification set.
13005 If so, use the name of the specified DIE. */
13006 spec_die
= die_specification (die
, &spec_cu
);
13007 if (spec_die
!= NULL
)
13008 return dwarf2_name (spec_die
, spec_cu
);
13013 if (die
->tag
== DW_TAG_class_type
)
13014 return dwarf2_name (die
, cu
);
13016 while (die
->tag
!= DW_TAG_compile_unit
);
13020 case DW_TAG_class_type
:
13021 case DW_TAG_interface_type
:
13022 case DW_TAG_structure_type
:
13023 case DW_TAG_union_type
:
13024 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
13025 structures or unions. These were of the form "._%d" in GCC 4.1,
13026 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
13027 and GCC 4.4. We work around this problem by ignoring these. */
13028 if (attr
&& DW_STRING (attr
)
13029 && (strncmp (DW_STRING (attr
), "._", 2) == 0
13030 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
13033 /* GCC might emit a nameless typedef that has a linkage name. See
13034 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
13035 if (!attr
|| DW_STRING (attr
) == NULL
)
13037 char *demangled
= NULL
;
13039 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
13041 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
13043 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
13046 /* Avoid demangling DW_STRING (attr) the second time on a second
13047 call for the same DIE. */
13048 if (!DW_STRING_IS_CANONICAL (attr
))
13049 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
13055 /* FIXME: we already did this for the partial symbol... */
13056 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
13057 &cu
->objfile
->objfile_obstack
);
13058 DW_STRING_IS_CANONICAL (attr
) = 1;
13061 /* Strip any leading namespaces/classes, keep only the base name.
13062 DW_AT_name for named DIEs does not contain the prefixes. */
13063 base
= strrchr (DW_STRING (attr
), ':');
13064 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
13067 return DW_STRING (attr
);
13076 if (!DW_STRING_IS_CANONICAL (attr
))
13079 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
13080 &cu
->objfile
->objfile_obstack
);
13081 DW_STRING_IS_CANONICAL (attr
) = 1;
13083 return DW_STRING (attr
);
13086 /* Return the die that this die in an extension of, or NULL if there
13087 is none. *EXT_CU is the CU containing DIE on input, and the CU
13088 containing the return value on output. */
13090 static struct die_info
*
13091 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
13093 struct attribute
*attr
;
13095 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
13099 return follow_die_ref (die
, attr
, ext_cu
);
13102 /* Convert a DIE tag into its string name. */
13105 dwarf_tag_name (unsigned tag
)
13109 case DW_TAG_padding
:
13110 return "DW_TAG_padding";
13111 case DW_TAG_array_type
:
13112 return "DW_TAG_array_type";
13113 case DW_TAG_class_type
:
13114 return "DW_TAG_class_type";
13115 case DW_TAG_entry_point
:
13116 return "DW_TAG_entry_point";
13117 case DW_TAG_enumeration_type
:
13118 return "DW_TAG_enumeration_type";
13119 case DW_TAG_formal_parameter
:
13120 return "DW_TAG_formal_parameter";
13121 case DW_TAG_imported_declaration
:
13122 return "DW_TAG_imported_declaration";
13124 return "DW_TAG_label";
13125 case DW_TAG_lexical_block
:
13126 return "DW_TAG_lexical_block";
13127 case DW_TAG_member
:
13128 return "DW_TAG_member";
13129 case DW_TAG_pointer_type
:
13130 return "DW_TAG_pointer_type";
13131 case DW_TAG_reference_type
:
13132 return "DW_TAG_reference_type";
13133 case DW_TAG_compile_unit
:
13134 return "DW_TAG_compile_unit";
13135 case DW_TAG_string_type
:
13136 return "DW_TAG_string_type";
13137 case DW_TAG_structure_type
:
13138 return "DW_TAG_structure_type";
13139 case DW_TAG_subroutine_type
:
13140 return "DW_TAG_subroutine_type";
13141 case DW_TAG_typedef
:
13142 return "DW_TAG_typedef";
13143 case DW_TAG_union_type
:
13144 return "DW_TAG_union_type";
13145 case DW_TAG_unspecified_parameters
:
13146 return "DW_TAG_unspecified_parameters";
13147 case DW_TAG_variant
:
13148 return "DW_TAG_variant";
13149 case DW_TAG_common_block
:
13150 return "DW_TAG_common_block";
13151 case DW_TAG_common_inclusion
:
13152 return "DW_TAG_common_inclusion";
13153 case DW_TAG_inheritance
:
13154 return "DW_TAG_inheritance";
13155 case DW_TAG_inlined_subroutine
:
13156 return "DW_TAG_inlined_subroutine";
13157 case DW_TAG_module
:
13158 return "DW_TAG_module";
13159 case DW_TAG_ptr_to_member_type
:
13160 return "DW_TAG_ptr_to_member_type";
13161 case DW_TAG_set_type
:
13162 return "DW_TAG_set_type";
13163 case DW_TAG_subrange_type
:
13164 return "DW_TAG_subrange_type";
13165 case DW_TAG_with_stmt
:
13166 return "DW_TAG_with_stmt";
13167 case DW_TAG_access_declaration
:
13168 return "DW_TAG_access_declaration";
13169 case DW_TAG_base_type
:
13170 return "DW_TAG_base_type";
13171 case DW_TAG_catch_block
:
13172 return "DW_TAG_catch_block";
13173 case DW_TAG_const_type
:
13174 return "DW_TAG_const_type";
13175 case DW_TAG_constant
:
13176 return "DW_TAG_constant";
13177 case DW_TAG_enumerator
:
13178 return "DW_TAG_enumerator";
13179 case DW_TAG_file_type
:
13180 return "DW_TAG_file_type";
13181 case DW_TAG_friend
:
13182 return "DW_TAG_friend";
13183 case DW_TAG_namelist
:
13184 return "DW_TAG_namelist";
13185 case DW_TAG_namelist_item
:
13186 return "DW_TAG_namelist_item";
13187 case DW_TAG_packed_type
:
13188 return "DW_TAG_packed_type";
13189 case DW_TAG_subprogram
:
13190 return "DW_TAG_subprogram";
13191 case DW_TAG_template_type_param
:
13192 return "DW_TAG_template_type_param";
13193 case DW_TAG_template_value_param
:
13194 return "DW_TAG_template_value_param";
13195 case DW_TAG_thrown_type
:
13196 return "DW_TAG_thrown_type";
13197 case DW_TAG_try_block
:
13198 return "DW_TAG_try_block";
13199 case DW_TAG_variant_part
:
13200 return "DW_TAG_variant_part";
13201 case DW_TAG_variable
:
13202 return "DW_TAG_variable";
13203 case DW_TAG_volatile_type
:
13204 return "DW_TAG_volatile_type";
13205 case DW_TAG_dwarf_procedure
:
13206 return "DW_TAG_dwarf_procedure";
13207 case DW_TAG_restrict_type
:
13208 return "DW_TAG_restrict_type";
13209 case DW_TAG_interface_type
:
13210 return "DW_TAG_interface_type";
13211 case DW_TAG_namespace
:
13212 return "DW_TAG_namespace";
13213 case DW_TAG_imported_module
:
13214 return "DW_TAG_imported_module";
13215 case DW_TAG_unspecified_type
:
13216 return "DW_TAG_unspecified_type";
13217 case DW_TAG_partial_unit
:
13218 return "DW_TAG_partial_unit";
13219 case DW_TAG_imported_unit
:
13220 return "DW_TAG_imported_unit";
13221 case DW_TAG_condition
:
13222 return "DW_TAG_condition";
13223 case DW_TAG_shared_type
:
13224 return "DW_TAG_shared_type";
13225 case DW_TAG_type_unit
:
13226 return "DW_TAG_type_unit";
13227 case DW_TAG_MIPS_loop
:
13228 return "DW_TAG_MIPS_loop";
13229 case DW_TAG_HP_array_descriptor
:
13230 return "DW_TAG_HP_array_descriptor";
13231 case DW_TAG_format_label
:
13232 return "DW_TAG_format_label";
13233 case DW_TAG_function_template
:
13234 return "DW_TAG_function_template";
13235 case DW_TAG_class_template
:
13236 return "DW_TAG_class_template";
13237 case DW_TAG_GNU_BINCL
:
13238 return "DW_TAG_GNU_BINCL";
13239 case DW_TAG_GNU_EINCL
:
13240 return "DW_TAG_GNU_EINCL";
13241 case DW_TAG_upc_shared_type
:
13242 return "DW_TAG_upc_shared_type";
13243 case DW_TAG_upc_strict_type
:
13244 return "DW_TAG_upc_strict_type";
13245 case DW_TAG_upc_relaxed_type
:
13246 return "DW_TAG_upc_relaxed_type";
13247 case DW_TAG_PGI_kanji_type
:
13248 return "DW_TAG_PGI_kanji_type";
13249 case DW_TAG_PGI_interface_block
:
13250 return "DW_TAG_PGI_interface_block";
13251 case DW_TAG_GNU_call_site
:
13252 return "DW_TAG_GNU_call_site";
13254 return "DW_TAG_<unknown>";
13258 /* Convert a DWARF attribute code into its string name. */
13261 dwarf_attr_name (unsigned attr
)
13265 case DW_AT_sibling
:
13266 return "DW_AT_sibling";
13267 case DW_AT_location
:
13268 return "DW_AT_location";
13270 return "DW_AT_name";
13271 case DW_AT_ordering
:
13272 return "DW_AT_ordering";
13273 case DW_AT_subscr_data
:
13274 return "DW_AT_subscr_data";
13275 case DW_AT_byte_size
:
13276 return "DW_AT_byte_size";
13277 case DW_AT_bit_offset
:
13278 return "DW_AT_bit_offset";
13279 case DW_AT_bit_size
:
13280 return "DW_AT_bit_size";
13281 case DW_AT_element_list
:
13282 return "DW_AT_element_list";
13283 case DW_AT_stmt_list
:
13284 return "DW_AT_stmt_list";
13286 return "DW_AT_low_pc";
13287 case DW_AT_high_pc
:
13288 return "DW_AT_high_pc";
13289 case DW_AT_language
:
13290 return "DW_AT_language";
13292 return "DW_AT_member";
13294 return "DW_AT_discr";
13295 case DW_AT_discr_value
:
13296 return "DW_AT_discr_value";
13297 case DW_AT_visibility
:
13298 return "DW_AT_visibility";
13300 return "DW_AT_import";
13301 case DW_AT_string_length
:
13302 return "DW_AT_string_length";
13303 case DW_AT_common_reference
:
13304 return "DW_AT_common_reference";
13305 case DW_AT_comp_dir
:
13306 return "DW_AT_comp_dir";
13307 case DW_AT_const_value
:
13308 return "DW_AT_const_value";
13309 case DW_AT_containing_type
:
13310 return "DW_AT_containing_type";
13311 case DW_AT_default_value
:
13312 return "DW_AT_default_value";
13314 return "DW_AT_inline";
13315 case DW_AT_is_optional
:
13316 return "DW_AT_is_optional";
13317 case DW_AT_lower_bound
:
13318 return "DW_AT_lower_bound";
13319 case DW_AT_producer
:
13320 return "DW_AT_producer";
13321 case DW_AT_prototyped
:
13322 return "DW_AT_prototyped";
13323 case DW_AT_return_addr
:
13324 return "DW_AT_return_addr";
13325 case DW_AT_start_scope
:
13326 return "DW_AT_start_scope";
13327 case DW_AT_bit_stride
:
13328 return "DW_AT_bit_stride";
13329 case DW_AT_upper_bound
:
13330 return "DW_AT_upper_bound";
13331 case DW_AT_abstract_origin
:
13332 return "DW_AT_abstract_origin";
13333 case DW_AT_accessibility
:
13334 return "DW_AT_accessibility";
13335 case DW_AT_address_class
:
13336 return "DW_AT_address_class";
13337 case DW_AT_artificial
:
13338 return "DW_AT_artificial";
13339 case DW_AT_base_types
:
13340 return "DW_AT_base_types";
13341 case DW_AT_calling_convention
:
13342 return "DW_AT_calling_convention";
13344 return "DW_AT_count";
13345 case DW_AT_data_member_location
:
13346 return "DW_AT_data_member_location";
13347 case DW_AT_decl_column
:
13348 return "DW_AT_decl_column";
13349 case DW_AT_decl_file
:
13350 return "DW_AT_decl_file";
13351 case DW_AT_decl_line
:
13352 return "DW_AT_decl_line";
13353 case DW_AT_declaration
:
13354 return "DW_AT_declaration";
13355 case DW_AT_discr_list
:
13356 return "DW_AT_discr_list";
13357 case DW_AT_encoding
:
13358 return "DW_AT_encoding";
13359 case DW_AT_external
:
13360 return "DW_AT_external";
13361 case DW_AT_frame_base
:
13362 return "DW_AT_frame_base";
13364 return "DW_AT_friend";
13365 case DW_AT_identifier_case
:
13366 return "DW_AT_identifier_case";
13367 case DW_AT_macro_info
:
13368 return "DW_AT_macro_info";
13369 case DW_AT_namelist_items
:
13370 return "DW_AT_namelist_items";
13371 case DW_AT_priority
:
13372 return "DW_AT_priority";
13373 case DW_AT_segment
:
13374 return "DW_AT_segment";
13375 case DW_AT_specification
:
13376 return "DW_AT_specification";
13377 case DW_AT_static_link
:
13378 return "DW_AT_static_link";
13380 return "DW_AT_type";
13381 case DW_AT_use_location
:
13382 return "DW_AT_use_location";
13383 case DW_AT_variable_parameter
:
13384 return "DW_AT_variable_parameter";
13385 case DW_AT_virtuality
:
13386 return "DW_AT_virtuality";
13387 case DW_AT_vtable_elem_location
:
13388 return "DW_AT_vtable_elem_location";
13389 /* DWARF 3 values. */
13390 case DW_AT_allocated
:
13391 return "DW_AT_allocated";
13392 case DW_AT_associated
:
13393 return "DW_AT_associated";
13394 case DW_AT_data_location
:
13395 return "DW_AT_data_location";
13396 case DW_AT_byte_stride
:
13397 return "DW_AT_byte_stride";
13398 case DW_AT_entry_pc
:
13399 return "DW_AT_entry_pc";
13400 case DW_AT_use_UTF8
:
13401 return "DW_AT_use_UTF8";
13402 case DW_AT_extension
:
13403 return "DW_AT_extension";
13405 return "DW_AT_ranges";
13406 case DW_AT_trampoline
:
13407 return "DW_AT_trampoline";
13408 case DW_AT_call_column
:
13409 return "DW_AT_call_column";
13410 case DW_AT_call_file
:
13411 return "DW_AT_call_file";
13412 case DW_AT_call_line
:
13413 return "DW_AT_call_line";
13414 case DW_AT_description
:
13415 return "DW_AT_description";
13416 case DW_AT_binary_scale
:
13417 return "DW_AT_binary_scale";
13418 case DW_AT_decimal_scale
:
13419 return "DW_AT_decimal_scale";
13421 return "DW_AT_small";
13422 case DW_AT_decimal_sign
:
13423 return "DW_AT_decimal_sign";
13424 case DW_AT_digit_count
:
13425 return "DW_AT_digit_count";
13426 case DW_AT_picture_string
:
13427 return "DW_AT_picture_string";
13428 case DW_AT_mutable
:
13429 return "DW_AT_mutable";
13430 case DW_AT_threads_scaled
:
13431 return "DW_AT_threads_scaled";
13432 case DW_AT_explicit
:
13433 return "DW_AT_explicit";
13434 case DW_AT_object_pointer
:
13435 return "DW_AT_object_pointer";
13436 case DW_AT_endianity
:
13437 return "DW_AT_endianity";
13438 case DW_AT_elemental
:
13439 return "DW_AT_elemental";
13441 return "DW_AT_pure";
13442 case DW_AT_recursive
:
13443 return "DW_AT_recursive";
13444 /* DWARF 4 values. */
13445 case DW_AT_signature
:
13446 return "DW_AT_signature";
13447 case DW_AT_linkage_name
:
13448 return "DW_AT_linkage_name";
13449 /* SGI/MIPS extensions. */
13450 #ifdef MIPS /* collides with DW_AT_HP_block_index */
13451 case DW_AT_MIPS_fde
:
13452 return "DW_AT_MIPS_fde";
13454 case DW_AT_MIPS_loop_begin
:
13455 return "DW_AT_MIPS_loop_begin";
13456 case DW_AT_MIPS_tail_loop_begin
:
13457 return "DW_AT_MIPS_tail_loop_begin";
13458 case DW_AT_MIPS_epilog_begin
:
13459 return "DW_AT_MIPS_epilog_begin";
13460 case DW_AT_MIPS_loop_unroll_factor
:
13461 return "DW_AT_MIPS_loop_unroll_factor";
13462 case DW_AT_MIPS_software_pipeline_depth
:
13463 return "DW_AT_MIPS_software_pipeline_depth";
13464 case DW_AT_MIPS_linkage_name
:
13465 return "DW_AT_MIPS_linkage_name";
13466 case DW_AT_MIPS_stride
:
13467 return "DW_AT_MIPS_stride";
13468 case DW_AT_MIPS_abstract_name
:
13469 return "DW_AT_MIPS_abstract_name";
13470 case DW_AT_MIPS_clone_origin
:
13471 return "DW_AT_MIPS_clone_origin";
13472 case DW_AT_MIPS_has_inlines
:
13473 return "DW_AT_MIPS_has_inlines";
13474 /* HP extensions. */
13475 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
13476 case DW_AT_HP_block_index
:
13477 return "DW_AT_HP_block_index";
13479 case DW_AT_HP_unmodifiable
:
13480 return "DW_AT_HP_unmodifiable";
13481 case DW_AT_HP_actuals_stmt_list
:
13482 return "DW_AT_HP_actuals_stmt_list";
13483 case DW_AT_HP_proc_per_section
:
13484 return "DW_AT_HP_proc_per_section";
13485 case DW_AT_HP_raw_data_ptr
:
13486 return "DW_AT_HP_raw_data_ptr";
13487 case DW_AT_HP_pass_by_reference
:
13488 return "DW_AT_HP_pass_by_reference";
13489 case DW_AT_HP_opt_level
:
13490 return "DW_AT_HP_opt_level";
13491 case DW_AT_HP_prof_version_id
:
13492 return "DW_AT_HP_prof_version_id";
13493 case DW_AT_HP_opt_flags
:
13494 return "DW_AT_HP_opt_flags";
13495 case DW_AT_HP_cold_region_low_pc
:
13496 return "DW_AT_HP_cold_region_low_pc";
13497 case DW_AT_HP_cold_region_high_pc
:
13498 return "DW_AT_HP_cold_region_high_pc";
13499 case DW_AT_HP_all_variables_modifiable
:
13500 return "DW_AT_HP_all_variables_modifiable";
13501 case DW_AT_HP_linkage_name
:
13502 return "DW_AT_HP_linkage_name";
13503 case DW_AT_HP_prof_flags
:
13504 return "DW_AT_HP_prof_flags";
13505 /* GNU extensions. */
13506 case DW_AT_sf_names
:
13507 return "DW_AT_sf_names";
13508 case DW_AT_src_info
:
13509 return "DW_AT_src_info";
13510 case DW_AT_mac_info
:
13511 return "DW_AT_mac_info";
13512 case DW_AT_src_coords
:
13513 return "DW_AT_src_coords";
13514 case DW_AT_body_begin
:
13515 return "DW_AT_body_begin";
13516 case DW_AT_body_end
:
13517 return "DW_AT_body_end";
13518 case DW_AT_GNU_vector
:
13519 return "DW_AT_GNU_vector";
13520 case DW_AT_GNU_odr_signature
:
13521 return "DW_AT_GNU_odr_signature";
13522 /* VMS extensions. */
13523 case DW_AT_VMS_rtnbeg_pd_address
:
13524 return "DW_AT_VMS_rtnbeg_pd_address";
13525 /* UPC extension. */
13526 case DW_AT_upc_threads_scaled
:
13527 return "DW_AT_upc_threads_scaled";
13528 /* PGI (STMicroelectronics) extensions. */
13529 case DW_AT_PGI_lbase
:
13530 return "DW_AT_PGI_lbase";
13531 case DW_AT_PGI_soffset
:
13532 return "DW_AT_PGI_soffset";
13533 case DW_AT_PGI_lstride
:
13534 return "DW_AT_PGI_lstride";
13536 return "DW_AT_<unknown>";
13540 /* Convert a DWARF value form code into its string name. */
13543 dwarf_form_name (unsigned form
)
13548 return "DW_FORM_addr";
13549 case DW_FORM_block2
:
13550 return "DW_FORM_block2";
13551 case DW_FORM_block4
:
13552 return "DW_FORM_block4";
13553 case DW_FORM_data2
:
13554 return "DW_FORM_data2";
13555 case DW_FORM_data4
:
13556 return "DW_FORM_data4";
13557 case DW_FORM_data8
:
13558 return "DW_FORM_data8";
13559 case DW_FORM_string
:
13560 return "DW_FORM_string";
13561 case DW_FORM_block
:
13562 return "DW_FORM_block";
13563 case DW_FORM_block1
:
13564 return "DW_FORM_block1";
13565 case DW_FORM_data1
:
13566 return "DW_FORM_data1";
13568 return "DW_FORM_flag";
13569 case DW_FORM_sdata
:
13570 return "DW_FORM_sdata";
13572 return "DW_FORM_strp";
13573 case DW_FORM_udata
:
13574 return "DW_FORM_udata";
13575 case DW_FORM_ref_addr
:
13576 return "DW_FORM_ref_addr";
13578 return "DW_FORM_ref1";
13580 return "DW_FORM_ref2";
13582 return "DW_FORM_ref4";
13584 return "DW_FORM_ref8";
13585 case DW_FORM_ref_udata
:
13586 return "DW_FORM_ref_udata";
13587 case DW_FORM_indirect
:
13588 return "DW_FORM_indirect";
13589 case DW_FORM_sec_offset
:
13590 return "DW_FORM_sec_offset";
13591 case DW_FORM_exprloc
:
13592 return "DW_FORM_exprloc";
13593 case DW_FORM_flag_present
:
13594 return "DW_FORM_flag_present";
13595 case DW_FORM_ref_sig8
:
13596 return "DW_FORM_ref_sig8";
13598 return "DW_FORM_<unknown>";
13602 /* Convert a DWARF stack opcode into its string name. */
13605 dwarf_stack_op_name (unsigned op
)
13610 return "DW_OP_addr";
13612 return "DW_OP_deref";
13613 case DW_OP_const1u
:
13614 return "DW_OP_const1u";
13615 case DW_OP_const1s
:
13616 return "DW_OP_const1s";
13617 case DW_OP_const2u
:
13618 return "DW_OP_const2u";
13619 case DW_OP_const2s
:
13620 return "DW_OP_const2s";
13621 case DW_OP_const4u
:
13622 return "DW_OP_const4u";
13623 case DW_OP_const4s
:
13624 return "DW_OP_const4s";
13625 case DW_OP_const8u
:
13626 return "DW_OP_const8u";
13627 case DW_OP_const8s
:
13628 return "DW_OP_const8s";
13630 return "DW_OP_constu";
13632 return "DW_OP_consts";
13634 return "DW_OP_dup";
13636 return "DW_OP_drop";
13638 return "DW_OP_over";
13640 return "DW_OP_pick";
13642 return "DW_OP_swap";
13644 return "DW_OP_rot";
13646 return "DW_OP_xderef";
13648 return "DW_OP_abs";
13650 return "DW_OP_and";
13652 return "DW_OP_div";
13654 return "DW_OP_minus";
13656 return "DW_OP_mod";
13658 return "DW_OP_mul";
13660 return "DW_OP_neg";
13662 return "DW_OP_not";
13666 return "DW_OP_plus";
13667 case DW_OP_plus_uconst
:
13668 return "DW_OP_plus_uconst";
13670 return "DW_OP_shl";
13672 return "DW_OP_shr";
13674 return "DW_OP_shra";
13676 return "DW_OP_xor";
13678 return "DW_OP_bra";
13692 return "DW_OP_skip";
13694 return "DW_OP_lit0";
13696 return "DW_OP_lit1";
13698 return "DW_OP_lit2";
13700 return "DW_OP_lit3";
13702 return "DW_OP_lit4";
13704 return "DW_OP_lit5";
13706 return "DW_OP_lit6";
13708 return "DW_OP_lit7";
13710 return "DW_OP_lit8";
13712 return "DW_OP_lit9";
13714 return "DW_OP_lit10";
13716 return "DW_OP_lit11";
13718 return "DW_OP_lit12";
13720 return "DW_OP_lit13";
13722 return "DW_OP_lit14";
13724 return "DW_OP_lit15";
13726 return "DW_OP_lit16";
13728 return "DW_OP_lit17";
13730 return "DW_OP_lit18";
13732 return "DW_OP_lit19";
13734 return "DW_OP_lit20";
13736 return "DW_OP_lit21";
13738 return "DW_OP_lit22";
13740 return "DW_OP_lit23";
13742 return "DW_OP_lit24";
13744 return "DW_OP_lit25";
13746 return "DW_OP_lit26";
13748 return "DW_OP_lit27";
13750 return "DW_OP_lit28";
13752 return "DW_OP_lit29";
13754 return "DW_OP_lit30";
13756 return "DW_OP_lit31";
13758 return "DW_OP_reg0";
13760 return "DW_OP_reg1";
13762 return "DW_OP_reg2";
13764 return "DW_OP_reg3";
13766 return "DW_OP_reg4";
13768 return "DW_OP_reg5";
13770 return "DW_OP_reg6";
13772 return "DW_OP_reg7";
13774 return "DW_OP_reg8";
13776 return "DW_OP_reg9";
13778 return "DW_OP_reg10";
13780 return "DW_OP_reg11";
13782 return "DW_OP_reg12";
13784 return "DW_OP_reg13";
13786 return "DW_OP_reg14";
13788 return "DW_OP_reg15";
13790 return "DW_OP_reg16";
13792 return "DW_OP_reg17";
13794 return "DW_OP_reg18";
13796 return "DW_OP_reg19";
13798 return "DW_OP_reg20";
13800 return "DW_OP_reg21";
13802 return "DW_OP_reg22";
13804 return "DW_OP_reg23";
13806 return "DW_OP_reg24";
13808 return "DW_OP_reg25";
13810 return "DW_OP_reg26";
13812 return "DW_OP_reg27";
13814 return "DW_OP_reg28";
13816 return "DW_OP_reg29";
13818 return "DW_OP_reg30";
13820 return "DW_OP_reg31";
13822 return "DW_OP_breg0";
13824 return "DW_OP_breg1";
13826 return "DW_OP_breg2";
13828 return "DW_OP_breg3";
13830 return "DW_OP_breg4";
13832 return "DW_OP_breg5";
13834 return "DW_OP_breg6";
13836 return "DW_OP_breg7";
13838 return "DW_OP_breg8";
13840 return "DW_OP_breg9";
13842 return "DW_OP_breg10";
13844 return "DW_OP_breg11";
13846 return "DW_OP_breg12";
13848 return "DW_OP_breg13";
13850 return "DW_OP_breg14";
13852 return "DW_OP_breg15";
13854 return "DW_OP_breg16";
13856 return "DW_OP_breg17";
13858 return "DW_OP_breg18";
13860 return "DW_OP_breg19";
13862 return "DW_OP_breg20";
13864 return "DW_OP_breg21";
13866 return "DW_OP_breg22";
13868 return "DW_OP_breg23";
13870 return "DW_OP_breg24";
13872 return "DW_OP_breg25";
13874 return "DW_OP_breg26";
13876 return "DW_OP_breg27";
13878 return "DW_OP_breg28";
13880 return "DW_OP_breg29";
13882 return "DW_OP_breg30";
13884 return "DW_OP_breg31";
13886 return "DW_OP_regx";
13888 return "DW_OP_fbreg";
13890 return "DW_OP_bregx";
13892 return "DW_OP_piece";
13893 case DW_OP_deref_size
:
13894 return "DW_OP_deref_size";
13895 case DW_OP_xderef_size
:
13896 return "DW_OP_xderef_size";
13898 return "DW_OP_nop";
13899 /* DWARF 3 extensions. */
13900 case DW_OP_push_object_address
:
13901 return "DW_OP_push_object_address";
13903 return "DW_OP_call2";
13905 return "DW_OP_call4";
13906 case DW_OP_call_ref
:
13907 return "DW_OP_call_ref";
13908 case DW_OP_form_tls_address
:
13909 return "DW_OP_form_tls_address";
13910 case DW_OP_call_frame_cfa
:
13911 return "DW_OP_call_frame_cfa";
13912 case DW_OP_bit_piece
:
13913 return "DW_OP_bit_piece";
13914 /* DWARF 4 extensions. */
13915 case DW_OP_implicit_value
:
13916 return "DW_OP_implicit_value";
13917 case DW_OP_stack_value
:
13918 return "DW_OP_stack_value";
13919 /* GNU extensions. */
13920 case DW_OP_GNU_push_tls_address
:
13921 return "DW_OP_GNU_push_tls_address";
13922 case DW_OP_GNU_uninit
:
13923 return "DW_OP_GNU_uninit";
13924 case DW_OP_GNU_encoded_addr
:
13925 return "DW_OP_GNU_encoded_addr";
13926 case DW_OP_GNU_implicit_pointer
:
13927 return "DW_OP_GNU_implicit_pointer";
13928 case DW_OP_GNU_entry_value
:
13929 return "DW_OP_GNU_entry_value";
13930 case DW_OP_GNU_const_type
:
13931 return "DW_OP_GNU_const_type";
13932 case DW_OP_GNU_regval_type
:
13933 return "DW_OP_GNU_regval_type";
13934 case DW_OP_GNU_deref_type
:
13935 return "DW_OP_GNU_deref_type";
13936 case DW_OP_GNU_convert
:
13937 return "DW_OP_GNU_convert";
13938 case DW_OP_GNU_reinterpret
:
13939 return "DW_OP_GNU_reinterpret";
13940 case DW_OP_GNU_parameter_ref
:
13941 return "DW_OP_GNU_parameter_ref";
13948 dwarf_bool_name (unsigned mybool
)
13956 /* Convert a DWARF type code into its string name. */
13959 dwarf_type_encoding_name (unsigned enc
)
13964 return "DW_ATE_void";
13965 case DW_ATE_address
:
13966 return "DW_ATE_address";
13967 case DW_ATE_boolean
:
13968 return "DW_ATE_boolean";
13969 case DW_ATE_complex_float
:
13970 return "DW_ATE_complex_float";
13972 return "DW_ATE_float";
13973 case DW_ATE_signed
:
13974 return "DW_ATE_signed";
13975 case DW_ATE_signed_char
:
13976 return "DW_ATE_signed_char";
13977 case DW_ATE_unsigned
:
13978 return "DW_ATE_unsigned";
13979 case DW_ATE_unsigned_char
:
13980 return "DW_ATE_unsigned_char";
13982 case DW_ATE_imaginary_float
:
13983 return "DW_ATE_imaginary_float";
13984 case DW_ATE_packed_decimal
:
13985 return "DW_ATE_packed_decimal";
13986 case DW_ATE_numeric_string
:
13987 return "DW_ATE_numeric_string";
13988 case DW_ATE_edited
:
13989 return "DW_ATE_edited";
13990 case DW_ATE_signed_fixed
:
13991 return "DW_ATE_signed_fixed";
13992 case DW_ATE_unsigned_fixed
:
13993 return "DW_ATE_unsigned_fixed";
13994 case DW_ATE_decimal_float
:
13995 return "DW_ATE_decimal_float";
13998 return "DW_ATE_UTF";
13999 /* HP extensions. */
14000 case DW_ATE_HP_float80
:
14001 return "DW_ATE_HP_float80";
14002 case DW_ATE_HP_complex_float80
:
14003 return "DW_ATE_HP_complex_float80";
14004 case DW_ATE_HP_float128
:
14005 return "DW_ATE_HP_float128";
14006 case DW_ATE_HP_complex_float128
:
14007 return "DW_ATE_HP_complex_float128";
14008 case DW_ATE_HP_floathpintel
:
14009 return "DW_ATE_HP_floathpintel";
14010 case DW_ATE_HP_imaginary_float80
:
14011 return "DW_ATE_HP_imaginary_float80";
14012 case DW_ATE_HP_imaginary_float128
:
14013 return "DW_ATE_HP_imaginary_float128";
14015 return "DW_ATE_<unknown>";
14019 /* Convert a DWARF call frame info operation to its string name. */
14023 dwarf_cfi_name (unsigned cfi_opc
)
14027 case DW_CFA_advance_loc
:
14028 return "DW_CFA_advance_loc";
14029 case DW_CFA_offset
:
14030 return "DW_CFA_offset";
14031 case DW_CFA_restore
:
14032 return "DW_CFA_restore";
14034 return "DW_CFA_nop";
14035 case DW_CFA_set_loc
:
14036 return "DW_CFA_set_loc";
14037 case DW_CFA_advance_loc1
:
14038 return "DW_CFA_advance_loc1";
14039 case DW_CFA_advance_loc2
:
14040 return "DW_CFA_advance_loc2";
14041 case DW_CFA_advance_loc4
:
14042 return "DW_CFA_advance_loc4";
14043 case DW_CFA_offset_extended
:
14044 return "DW_CFA_offset_extended";
14045 case DW_CFA_restore_extended
:
14046 return "DW_CFA_restore_extended";
14047 case DW_CFA_undefined
:
14048 return "DW_CFA_undefined";
14049 case DW_CFA_same_value
:
14050 return "DW_CFA_same_value";
14051 case DW_CFA_register
:
14052 return "DW_CFA_register";
14053 case DW_CFA_remember_state
:
14054 return "DW_CFA_remember_state";
14055 case DW_CFA_restore_state
:
14056 return "DW_CFA_restore_state";
14057 case DW_CFA_def_cfa
:
14058 return "DW_CFA_def_cfa";
14059 case DW_CFA_def_cfa_register
:
14060 return "DW_CFA_def_cfa_register";
14061 case DW_CFA_def_cfa_offset
:
14062 return "DW_CFA_def_cfa_offset";
14064 case DW_CFA_def_cfa_expression
:
14065 return "DW_CFA_def_cfa_expression";
14066 case DW_CFA_expression
:
14067 return "DW_CFA_expression";
14068 case DW_CFA_offset_extended_sf
:
14069 return "DW_CFA_offset_extended_sf";
14070 case DW_CFA_def_cfa_sf
:
14071 return "DW_CFA_def_cfa_sf";
14072 case DW_CFA_def_cfa_offset_sf
:
14073 return "DW_CFA_def_cfa_offset_sf";
14074 case DW_CFA_val_offset
:
14075 return "DW_CFA_val_offset";
14076 case DW_CFA_val_offset_sf
:
14077 return "DW_CFA_val_offset_sf";
14078 case DW_CFA_val_expression
:
14079 return "DW_CFA_val_expression";
14080 /* SGI/MIPS specific. */
14081 case DW_CFA_MIPS_advance_loc8
:
14082 return "DW_CFA_MIPS_advance_loc8";
14083 /* GNU extensions. */
14084 case DW_CFA_GNU_window_save
:
14085 return "DW_CFA_GNU_window_save";
14086 case DW_CFA_GNU_args_size
:
14087 return "DW_CFA_GNU_args_size";
14088 case DW_CFA_GNU_negative_offset_extended
:
14089 return "DW_CFA_GNU_negative_offset_extended";
14091 return "DW_CFA_<unknown>";
14097 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
14101 print_spaces (indent
, f
);
14102 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
14103 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
.sect_off
);
14105 if (die
->parent
!= NULL
)
14107 print_spaces (indent
, f
);
14108 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
14109 die
->parent
->offset
.sect_off
);
14112 print_spaces (indent
, f
);
14113 fprintf_unfiltered (f
, " has children: %s\n",
14114 dwarf_bool_name (die
->child
!= NULL
));
14116 print_spaces (indent
, f
);
14117 fprintf_unfiltered (f
, " attributes:\n");
14119 for (i
= 0; i
< die
->num_attrs
; ++i
)
14121 print_spaces (indent
, f
);
14122 fprintf_unfiltered (f
, " %s (%s) ",
14123 dwarf_attr_name (die
->attrs
[i
].name
),
14124 dwarf_form_name (die
->attrs
[i
].form
));
14126 switch (die
->attrs
[i
].form
)
14129 fprintf_unfiltered (f
, "address: ");
14130 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
14132 case DW_FORM_block2
:
14133 case DW_FORM_block4
:
14134 case DW_FORM_block
:
14135 case DW_FORM_block1
:
14136 fprintf_unfiltered (f
, "block: size %d",
14137 DW_BLOCK (&die
->attrs
[i
])->size
);
14139 case DW_FORM_exprloc
:
14140 fprintf_unfiltered (f
, "expression: size %u",
14141 DW_BLOCK (&die
->attrs
[i
])->size
);
14143 case DW_FORM_ref_addr
:
14144 fprintf_unfiltered (f
, "ref address: ");
14145 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
14151 case DW_FORM_ref_udata
:
14152 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
14153 (long) (DW_UNSND (&die
->attrs
[i
])));
14155 case DW_FORM_data1
:
14156 case DW_FORM_data2
:
14157 case DW_FORM_data4
:
14158 case DW_FORM_data8
:
14159 case DW_FORM_udata
:
14160 case DW_FORM_sdata
:
14161 fprintf_unfiltered (f
, "constant: %s",
14162 pulongest (DW_UNSND (&die
->attrs
[i
])));
14164 case DW_FORM_sec_offset
:
14165 fprintf_unfiltered (f
, "section offset: %s",
14166 pulongest (DW_UNSND (&die
->attrs
[i
])));
14168 case DW_FORM_ref_sig8
:
14169 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
14170 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
14171 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
.sect_off
);
14173 fprintf_unfiltered (f
, "signatured type, offset: unknown");
14175 case DW_FORM_string
:
14177 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
14178 DW_STRING (&die
->attrs
[i
])
14179 ? DW_STRING (&die
->attrs
[i
]) : "",
14180 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
14183 if (DW_UNSND (&die
->attrs
[i
]))
14184 fprintf_unfiltered (f
, "flag: TRUE");
14186 fprintf_unfiltered (f
, "flag: FALSE");
14188 case DW_FORM_flag_present
:
14189 fprintf_unfiltered (f
, "flag: TRUE");
14191 case DW_FORM_indirect
:
14192 /* The reader will have reduced the indirect form to
14193 the "base form" so this form should not occur. */
14194 fprintf_unfiltered (f
,
14195 "unexpected attribute form: DW_FORM_indirect");
14198 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
14199 die
->attrs
[i
].form
);
14202 fprintf_unfiltered (f
, "\n");
14207 dump_die_for_error (struct die_info
*die
)
14209 dump_die_shallow (gdb_stderr
, 0, die
);
14213 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
14215 int indent
= level
* 4;
14217 gdb_assert (die
!= NULL
);
14219 if (level
>= max_level
)
14222 dump_die_shallow (f
, indent
, die
);
14224 if (die
->child
!= NULL
)
14226 print_spaces (indent
, f
);
14227 fprintf_unfiltered (f
, " Children:");
14228 if (level
+ 1 < max_level
)
14230 fprintf_unfiltered (f
, "\n");
14231 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
14235 fprintf_unfiltered (f
,
14236 " [not printed, max nesting level reached]\n");
14240 if (die
->sibling
!= NULL
&& level
> 0)
14242 dump_die_1 (f
, level
, max_level
, die
->sibling
);
14246 /* This is called from the pdie macro in gdbinit.in.
14247 It's not static so gcc will keep a copy callable from gdb. */
14250 dump_die (struct die_info
*die
, int max_level
)
14252 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
14256 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
14260 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
.sect_off
,
14266 /* DW_ADDR is always stored already as sect_offset; despite for the forms
14267 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
14270 is_ref_attr (struct attribute
*attr
)
14272 switch (attr
->form
)
14274 case DW_FORM_ref_addr
:
14279 case DW_FORM_ref_udata
:
14286 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
14290 dwarf2_get_ref_die_offset (struct attribute
*attr
)
14292 sect_offset retval
= { DW_UNSND (attr
) };
14294 if (is_ref_attr (attr
))
14297 retval
.sect_off
= 0;
14298 complaint (&symfile_complaints
,
14299 _("unsupported die ref attribute form: '%s'"),
14300 dwarf_form_name (attr
->form
));
14304 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
14305 * the value held by the attribute is not constant. */
14308 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
14310 if (attr
->form
== DW_FORM_sdata
)
14311 return DW_SND (attr
);
14312 else if (attr
->form
== DW_FORM_udata
14313 || attr
->form
== DW_FORM_data1
14314 || attr
->form
== DW_FORM_data2
14315 || attr
->form
== DW_FORM_data4
14316 || attr
->form
== DW_FORM_data8
)
14317 return DW_UNSND (attr
);
14320 complaint (&symfile_complaints
,
14321 _("Attribute value is not a constant (%s)"),
14322 dwarf_form_name (attr
->form
));
14323 return default_value
;
14327 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
14328 unit and add it to our queue.
14329 The result is non-zero if PER_CU was queued, otherwise the result is zero
14330 meaning either PER_CU is already queued or it is already loaded. */
14333 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
14334 struct dwarf2_per_cu_data
*per_cu
)
14336 /* We may arrive here during partial symbol reading, if we need full
14337 DIEs to process an unusual case (e.g. template arguments). Do
14338 not queue PER_CU, just tell our caller to load its DIEs. */
14339 if (dwarf2_per_objfile
->reading_partial_symbols
)
14341 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
14346 /* Mark the dependence relation so that we don't flush PER_CU
14348 dwarf2_add_dependence (this_cu
, per_cu
);
14350 /* If it's already on the queue, we have nothing to do. */
14351 if (per_cu
->queued
)
14354 /* If the compilation unit is already loaded, just mark it as
14356 if (per_cu
->cu
!= NULL
)
14358 per_cu
->cu
->last_used
= 0;
14362 /* Add it to the queue. */
14363 queue_comp_unit (per_cu
);
14368 /* Follow reference or signature attribute ATTR of SRC_DIE.
14369 On entry *REF_CU is the CU of SRC_DIE.
14370 On exit *REF_CU is the CU of the result. */
14372 static struct die_info
*
14373 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
14374 struct dwarf2_cu
**ref_cu
)
14376 struct die_info
*die
;
14378 if (is_ref_attr (attr
))
14379 die
= follow_die_ref (src_die
, attr
, ref_cu
);
14380 else if (attr
->form
== DW_FORM_ref_sig8
)
14381 die
= follow_die_sig (src_die
, attr
, ref_cu
);
14384 dump_die_for_error (src_die
);
14385 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
14386 (*ref_cu
)->objfile
->name
);
14392 /* Follow reference OFFSET.
14393 On entry *REF_CU is the CU of the source die referencing OFFSET.
14394 On exit *REF_CU is the CU of the result.
14395 Returns NULL if OFFSET is invalid. */
14397 static struct die_info
*
14398 follow_die_offset (sect_offset offset
, struct dwarf2_cu
**ref_cu
)
14400 struct die_info temp_die
;
14401 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
14403 gdb_assert (cu
->per_cu
!= NULL
);
14407 if (cu
->per_cu
->debug_types_section
)
14409 /* .debug_types CUs cannot reference anything outside their CU.
14410 If they need to, they have to reference a signatured type via
14411 DW_FORM_ref_sig8. */
14412 if (! offset_in_cu_p (&cu
->header
, offset
))
14415 else if (! offset_in_cu_p (&cu
->header
, offset
))
14417 struct dwarf2_per_cu_data
*per_cu
;
14419 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
14421 /* If necessary, add it to the queue and load its DIEs. */
14422 if (maybe_queue_comp_unit (cu
, per_cu
))
14423 load_full_comp_unit (per_cu
);
14425 target_cu
= per_cu
->cu
;
14427 else if (cu
->dies
== NULL
)
14429 /* We're loading full DIEs during partial symbol reading. */
14430 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
14431 load_full_comp_unit (cu
->per_cu
);
14434 *ref_cu
= target_cu
;
14435 temp_die
.offset
= offset
;
14436 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
.sect_off
);
14439 /* Follow reference attribute ATTR of SRC_DIE.
14440 On entry *REF_CU is the CU of SRC_DIE.
14441 On exit *REF_CU is the CU of the result. */
14443 static struct die_info
*
14444 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
14445 struct dwarf2_cu
**ref_cu
)
14447 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
14448 struct dwarf2_cu
*cu
= *ref_cu
;
14449 struct die_info
*die
;
14451 die
= follow_die_offset (offset
, ref_cu
);
14453 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
14454 "at 0x%x [in module %s]"),
14455 offset
.sect_off
, src_die
->offset
.sect_off
, cu
->objfile
->name
);
14460 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
14461 Returned value is intended for DW_OP_call*. Returned
14462 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
14464 struct dwarf2_locexpr_baton
14465 dwarf2_fetch_die_location_block (cu_offset offset_in_cu
,
14466 struct dwarf2_per_cu_data
*per_cu
,
14467 CORE_ADDR (*get_frame_pc
) (void *baton
),
14470 sect_offset offset
= { per_cu
->offset
.sect_off
+ offset_in_cu
.cu_off
};
14471 struct dwarf2_cu
*cu
;
14472 struct die_info
*die
;
14473 struct attribute
*attr
;
14474 struct dwarf2_locexpr_baton retval
;
14476 dw2_setup (per_cu
->objfile
);
14478 if (per_cu
->cu
== NULL
)
14482 die
= follow_die_offset (offset
, &cu
);
14484 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
14485 offset
.sect_off
, per_cu
->objfile
->name
);
14487 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
14490 /* DWARF: "If there is no such attribute, then there is no effect.".
14491 DATA is ignored if SIZE is 0. */
14493 retval
.data
= NULL
;
14496 else if (attr_form_is_section_offset (attr
))
14498 struct dwarf2_loclist_baton loclist_baton
;
14499 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
14502 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
14504 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
14506 retval
.size
= size
;
14510 if (!attr_form_is_block (attr
))
14511 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
14512 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
14513 offset
.sect_off
, per_cu
->objfile
->name
);
14515 retval
.data
= DW_BLOCK (attr
)->data
;
14516 retval
.size
= DW_BLOCK (attr
)->size
;
14518 retval
.per_cu
= cu
->per_cu
;
14520 age_cached_comp_units ();
14525 /* Return the type of the DIE at DIE_OFFSET in the CU named by
14529 dwarf2_get_die_type (cu_offset die_offset
,
14530 struct dwarf2_per_cu_data
*per_cu
)
14532 sect_offset die_offset_sect
;
14534 dw2_setup (per_cu
->objfile
);
14536 die_offset_sect
.sect_off
= per_cu
->offset
.sect_off
+ die_offset
.cu_off
;
14537 return get_die_type_at_offset (die_offset_sect
, per_cu
);
14540 /* Follow the signature attribute ATTR in SRC_DIE.
14541 On entry *REF_CU is the CU of SRC_DIE.
14542 On exit *REF_CU is the CU of the result. */
14544 static struct die_info
*
14545 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
14546 struct dwarf2_cu
**ref_cu
)
14548 struct objfile
*objfile
= (*ref_cu
)->objfile
;
14549 struct die_info temp_die
;
14550 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
14551 struct dwarf2_cu
*sig_cu
;
14552 struct die_info
*die
;
14554 /* sig_type will be NULL if the signatured type is missing from
14556 if (sig_type
== NULL
)
14557 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
14558 "at 0x%x [in module %s]"),
14559 src_die
->offset
.sect_off
, objfile
->name
);
14561 /* If necessary, add it to the queue and load its DIEs. */
14563 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
14564 read_signatured_type (sig_type
);
14566 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
14568 sig_cu
= sig_type
->per_cu
.cu
;
14569 temp_die
.offset
.sect_off
= (sig_type
->per_cu
.offset
.sect_off
14570 + sig_type
->type_offset
.cu_off
);
14571 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
14572 temp_die
.offset
.sect_off
);
14579 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
14580 "from DIE at 0x%x [in module %s]"),
14581 temp_die
.offset
.sect_off
, src_die
->offset
.sect_off
, objfile
->name
);
14584 /* Given an offset of a signatured type, return its signatured_type. */
14586 static struct signatured_type
*
14587 lookup_signatured_type_at_offset (struct objfile
*objfile
,
14588 struct dwarf2_section_info
*section
,
14589 sect_offset offset
)
14591 gdb_byte
*info_ptr
= section
->buffer
+ offset
.sect_off
;
14592 unsigned int length
, initial_length_size
;
14593 unsigned int sig_offset
;
14594 struct signatured_type find_entry
, *sig_type
;
14596 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
14597 sig_offset
= (initial_length_size
14599 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
14600 + 1 /*address_size*/);
14601 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
14602 sig_type
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
14604 /* This is only used to lookup previously recorded types.
14605 If we didn't find it, it's our bug. */
14606 gdb_assert (sig_type
!= NULL
);
14607 gdb_assert (offset
.sect_off
== sig_type
->per_cu
.offset
.sect_off
);
14612 /* Load the DIEs associated with type unit PER_CU into memory. */
14615 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
14617 struct objfile
*objfile
= per_cu
->objfile
;
14618 struct dwarf2_section_info
*sect
= per_cu
->debug_types_section
;
14619 sect_offset offset
= per_cu
->offset
;
14620 struct signatured_type
*sig_type
;
14622 dwarf2_read_section (objfile
, sect
);
14624 /* We have the section offset, but we need the signature to do the
14625 hash table lookup. */
14626 /* FIXME: This is sorta unnecessary, read_signatured_type only uses
14627 the signature to assert we found the right one.
14628 Ok, but it's a lot of work. We should simplify things so any needed
14629 assert doesn't require all this clumsiness. */
14630 sig_type
= lookup_signatured_type_at_offset (objfile
, sect
, offset
);
14632 gdb_assert (sig_type
->per_cu
.cu
== NULL
);
14634 read_signatured_type (sig_type
);
14636 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
14639 /* Read in a signatured type and build its CU and DIEs. */
14642 read_signatured_type (struct signatured_type
*sig_type
)
14644 struct objfile
*objfile
= sig_type
->per_cu
.objfile
;
14645 gdb_byte
*types_ptr
;
14646 struct die_reader_specs reader_specs
;
14647 struct dwarf2_cu
*cu
;
14648 ULONGEST signature
;
14649 struct cleanup
*back_to
, *free_cu_cleanup
;
14650 struct dwarf2_section_info
*section
= sig_type
->per_cu
.debug_types_section
;
14652 dwarf2_read_section (objfile
, section
);
14653 types_ptr
= section
->buffer
+ sig_type
->per_cu
.offset
.sect_off
;
14655 gdb_assert (sig_type
->per_cu
.cu
== NULL
);
14657 cu
= xmalloc (sizeof (*cu
));
14658 init_one_comp_unit (cu
, &sig_type
->per_cu
);
14660 /* If an error occurs while loading, release our storage. */
14661 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
14663 types_ptr
= read_and_check_type_unit_head (&cu
->header
, section
, types_ptr
,
14665 gdb_assert (signature
== sig_type
->signature
);
14668 = htab_create_alloc_ex (cu
->header
.length
/ 12,
14672 &cu
->comp_unit_obstack
,
14673 hashtab_obstack_allocate
,
14674 dummy_obstack_deallocate
);
14676 dwarf2_read_abbrevs (cu
);
14677 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
14679 init_cu_die_reader (&reader_specs
, cu
);
14681 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
14684 /* We try not to read any attributes in this function, because not
14685 all CUs needed for references have been loaded yet, and symbol
14686 table processing isn't initialized. But we have to set the CU language,
14687 or we won't be able to build types correctly. */
14688 prepare_one_comp_unit (cu
, cu
->dies
);
14690 do_cleanups (back_to
);
14692 /* We've successfully allocated this compilation unit. Let our caller
14693 clean it up when finished with it. */
14694 discard_cleanups (free_cu_cleanup
);
14696 /* Link this TU into read_in_chain. */
14697 sig_type
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
14698 dwarf2_per_objfile
->read_in_chain
= &sig_type
->per_cu
;
14701 /* Decode simple location descriptions.
14702 Given a pointer to a dwarf block that defines a location, compute
14703 the location and return the value.
14705 NOTE drow/2003-11-18: This function is called in two situations
14706 now: for the address of static or global variables (partial symbols
14707 only) and for offsets into structures which are expected to be
14708 (more or less) constant. The partial symbol case should go away,
14709 and only the constant case should remain. That will let this
14710 function complain more accurately. A few special modes are allowed
14711 without complaint for global variables (for instance, global
14712 register values and thread-local values).
14714 A location description containing no operations indicates that the
14715 object is optimized out. The return value is 0 for that case.
14716 FIXME drow/2003-11-16: No callers check for this case any more; soon all
14717 callers will only want a very basic result and this can become a
14720 Note that stack[0] is unused except as a default error return. */
14723 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
14725 struct objfile
*objfile
= cu
->objfile
;
14727 int size
= blk
->size
;
14728 gdb_byte
*data
= blk
->data
;
14729 CORE_ADDR stack
[64];
14731 unsigned int bytes_read
, unsnd
;
14737 stack
[++stacki
] = 0;
14776 stack
[++stacki
] = op
- DW_OP_lit0
;
14811 stack
[++stacki
] = op
- DW_OP_reg0
;
14813 dwarf2_complex_location_expr_complaint ();
14817 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
14819 stack
[++stacki
] = unsnd
;
14821 dwarf2_complex_location_expr_complaint ();
14825 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
14830 case DW_OP_const1u
:
14831 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
14835 case DW_OP_const1s
:
14836 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
14840 case DW_OP_const2u
:
14841 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
14845 case DW_OP_const2s
:
14846 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
14850 case DW_OP_const4u
:
14851 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
14855 case DW_OP_const4s
:
14856 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
14860 case DW_OP_const8u
:
14861 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
14866 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
14872 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
14877 stack
[stacki
+ 1] = stack
[stacki
];
14882 stack
[stacki
- 1] += stack
[stacki
];
14886 case DW_OP_plus_uconst
:
14887 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
14893 stack
[stacki
- 1] -= stack
[stacki
];
14898 /* If we're not the last op, then we definitely can't encode
14899 this using GDB's address_class enum. This is valid for partial
14900 global symbols, although the variable's address will be bogus
14903 dwarf2_complex_location_expr_complaint ();
14906 case DW_OP_GNU_push_tls_address
:
14907 /* The top of the stack has the offset from the beginning
14908 of the thread control block at which the variable is located. */
14909 /* Nothing should follow this operator, so the top of stack would
14911 /* This is valid for partial global symbols, but the variable's
14912 address will be bogus in the psymtab. Make it always at least
14913 non-zero to not look as a variable garbage collected by linker
14914 which have DW_OP_addr 0. */
14916 dwarf2_complex_location_expr_complaint ();
14920 case DW_OP_GNU_uninit
:
14925 const char *name
= dwarf_stack_op_name (op
);
14928 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
14931 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
14935 return (stack
[stacki
]);
14938 /* Enforce maximum stack depth of SIZE-1 to avoid writing
14939 outside of the allocated space. Also enforce minimum>0. */
14940 if (stacki
>= ARRAY_SIZE (stack
) - 1)
14942 complaint (&symfile_complaints
,
14943 _("location description stack overflow"));
14949 complaint (&symfile_complaints
,
14950 _("location description stack underflow"));
14954 return (stack
[stacki
]);
14957 /* memory allocation interface */
14959 static struct dwarf_block
*
14960 dwarf_alloc_block (struct dwarf2_cu
*cu
)
14962 struct dwarf_block
*blk
;
14964 blk
= (struct dwarf_block
*)
14965 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
14969 static struct abbrev_info
*
14970 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
14972 struct abbrev_info
*abbrev
;
14974 abbrev
= (struct abbrev_info
*)
14975 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
14976 memset (abbrev
, 0, sizeof (struct abbrev_info
));
14980 static struct die_info
*
14981 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
14983 struct die_info
*die
;
14984 size_t size
= sizeof (struct die_info
);
14987 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
14989 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
14990 memset (die
, 0, sizeof (struct die_info
));
14995 /* Macro support. */
14997 /* Return the full name of file number I in *LH's file name table.
14998 Use COMP_DIR as the name of the current directory of the
14999 compilation. The result is allocated using xmalloc; the caller is
15000 responsible for freeing it. */
15002 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
15004 /* Is the file number a valid index into the line header's file name
15005 table? Remember that file numbers start with one, not zero. */
15006 if (1 <= file
&& file
<= lh
->num_file_names
)
15008 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
15010 if (IS_ABSOLUTE_PATH (fe
->name
))
15011 return xstrdup (fe
->name
);
15019 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
15025 dir_len
= strlen (dir
);
15026 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
15027 strcpy (full_name
, dir
);
15028 full_name
[dir_len
] = '/';
15029 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
15033 return xstrdup (fe
->name
);
15038 /* The compiler produced a bogus file number. We can at least
15039 record the macro definitions made in the file, even if we
15040 won't be able to find the file by name. */
15041 char fake_name
[80];
15043 sprintf (fake_name
, "<bad macro file number %d>", file
);
15045 complaint (&symfile_complaints
,
15046 _("bad file number in macro information (%d)"),
15049 return xstrdup (fake_name
);
15054 static struct macro_source_file
*
15055 macro_start_file (int file
, int line
,
15056 struct macro_source_file
*current_file
,
15057 const char *comp_dir
,
15058 struct line_header
*lh
, struct objfile
*objfile
)
15060 /* The full name of this source file. */
15061 char *full_name
= file_full_name (file
, lh
, comp_dir
);
15063 /* We don't create a macro table for this compilation unit
15064 at all until we actually get a filename. */
15065 if (! pending_macros
)
15066 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
15067 objfile
->macro_cache
);
15069 if (! current_file
)
15070 /* If we have no current file, then this must be the start_file
15071 directive for the compilation unit's main source file. */
15072 current_file
= macro_set_main (pending_macros
, full_name
);
15074 current_file
= macro_include (current_file
, line
, full_name
);
15078 return current_file
;
15082 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
15083 followed by a null byte. */
15085 copy_string (const char *buf
, int len
)
15087 char *s
= xmalloc (len
+ 1);
15089 memcpy (s
, buf
, len
);
15095 static const char *
15096 consume_improper_spaces (const char *p
, const char *body
)
15100 complaint (&symfile_complaints
,
15101 _("macro definition contains spaces "
15102 "in formal argument list:\n`%s'"),
15114 parse_macro_definition (struct macro_source_file
*file
, int line
,
15119 /* The body string takes one of two forms. For object-like macro
15120 definitions, it should be:
15122 <macro name> " " <definition>
15124 For function-like macro definitions, it should be:
15126 <macro name> "() " <definition>
15128 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
15130 Spaces may appear only where explicitly indicated, and in the
15133 The Dwarf 2 spec says that an object-like macro's name is always
15134 followed by a space, but versions of GCC around March 2002 omit
15135 the space when the macro's definition is the empty string.
15137 The Dwarf 2 spec says that there should be no spaces between the
15138 formal arguments in a function-like macro's formal argument list,
15139 but versions of GCC around March 2002 include spaces after the
15143 /* Find the extent of the macro name. The macro name is terminated
15144 by either a space or null character (for an object-like macro) or
15145 an opening paren (for a function-like macro). */
15146 for (p
= body
; *p
; p
++)
15147 if (*p
== ' ' || *p
== '(')
15150 if (*p
== ' ' || *p
== '\0')
15152 /* It's an object-like macro. */
15153 int name_len
= p
- body
;
15154 char *name
= copy_string (body
, name_len
);
15155 const char *replacement
;
15158 replacement
= body
+ name_len
+ 1;
15161 dwarf2_macro_malformed_definition_complaint (body
);
15162 replacement
= body
+ name_len
;
15165 macro_define_object (file
, line
, name
, replacement
);
15169 else if (*p
== '(')
15171 /* It's a function-like macro. */
15172 char *name
= copy_string (body
, p
- body
);
15175 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
15179 p
= consume_improper_spaces (p
, body
);
15181 /* Parse the formal argument list. */
15182 while (*p
&& *p
!= ')')
15184 /* Find the extent of the current argument name. */
15185 const char *arg_start
= p
;
15187 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
15190 if (! *p
|| p
== arg_start
)
15191 dwarf2_macro_malformed_definition_complaint (body
);
15194 /* Make sure argv has room for the new argument. */
15195 if (argc
>= argv_size
)
15198 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
15201 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
15204 p
= consume_improper_spaces (p
, body
);
15206 /* Consume the comma, if present. */
15211 p
= consume_improper_spaces (p
, body
);
15220 /* Perfectly formed definition, no complaints. */
15221 macro_define_function (file
, line
, name
,
15222 argc
, (const char **) argv
,
15224 else if (*p
== '\0')
15226 /* Complain, but do define it. */
15227 dwarf2_macro_malformed_definition_complaint (body
);
15228 macro_define_function (file
, line
, name
,
15229 argc
, (const char **) argv
,
15233 /* Just complain. */
15234 dwarf2_macro_malformed_definition_complaint (body
);
15237 /* Just complain. */
15238 dwarf2_macro_malformed_definition_complaint (body
);
15244 for (i
= 0; i
< argc
; i
++)
15250 dwarf2_macro_malformed_definition_complaint (body
);
15253 /* Skip some bytes from BYTES according to the form given in FORM.
15254 Returns the new pointer. */
15257 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
,
15258 enum dwarf_form form
,
15259 unsigned int offset_size
,
15260 struct dwarf2_section_info
*section
)
15262 unsigned int bytes_read
;
15266 case DW_FORM_data1
:
15271 case DW_FORM_data2
:
15275 case DW_FORM_data4
:
15279 case DW_FORM_data8
:
15283 case DW_FORM_string
:
15284 read_direct_string (abfd
, bytes
, &bytes_read
);
15285 bytes
+= bytes_read
;
15288 case DW_FORM_sec_offset
:
15290 bytes
+= offset_size
;
15293 case DW_FORM_block
:
15294 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
15295 bytes
+= bytes_read
;
15298 case DW_FORM_block1
:
15299 bytes
+= 1 + read_1_byte (abfd
, bytes
);
15301 case DW_FORM_block2
:
15302 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
15304 case DW_FORM_block4
:
15305 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
15308 case DW_FORM_sdata
:
15309 case DW_FORM_udata
:
15310 bytes
= skip_leb128 (abfd
, bytes
);
15316 complaint (&symfile_complaints
,
15317 _("invalid form 0x%x in `%s'"),
15319 section
->asection
->name
);
15327 /* A helper for dwarf_decode_macros that handles skipping an unknown
15328 opcode. Returns an updated pointer to the macro data buffer; or,
15329 on error, issues a complaint and returns NULL. */
15332 skip_unknown_opcode (unsigned int opcode
,
15333 gdb_byte
**opcode_definitions
,
15336 unsigned int offset_size
,
15337 struct dwarf2_section_info
*section
)
15339 unsigned int bytes_read
, i
;
15343 if (opcode_definitions
[opcode
] == NULL
)
15345 complaint (&symfile_complaints
,
15346 _("unrecognized DW_MACFINO opcode 0x%x"),
15351 defn
= opcode_definitions
[opcode
];
15352 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
15353 defn
+= bytes_read
;
15355 for (i
= 0; i
< arg
; ++i
)
15357 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, defn
[i
], offset_size
, section
);
15358 if (mac_ptr
== NULL
)
15360 /* skip_form_bytes already issued the complaint. */
15368 /* A helper function which parses the header of a macro section.
15369 If the macro section is the extended (for now called "GNU") type,
15370 then this updates *OFFSET_SIZE. Returns a pointer to just after
15371 the header, or issues a complaint and returns NULL on error. */
15374 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
15377 unsigned int *offset_size
,
15378 int section_is_gnu
)
15380 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
15382 if (section_is_gnu
)
15384 unsigned int version
, flags
;
15386 version
= read_2_bytes (abfd
, mac_ptr
);
15389 complaint (&symfile_complaints
,
15390 _("unrecognized version `%d' in .debug_macro section"),
15396 flags
= read_1_byte (abfd
, mac_ptr
);
15398 *offset_size
= (flags
& 1) ? 8 : 4;
15400 if ((flags
& 2) != 0)
15401 /* We don't need the line table offset. */
15402 mac_ptr
+= *offset_size
;
15404 /* Vendor opcode descriptions. */
15405 if ((flags
& 4) != 0)
15407 unsigned int i
, count
;
15409 count
= read_1_byte (abfd
, mac_ptr
);
15411 for (i
= 0; i
< count
; ++i
)
15413 unsigned int opcode
, bytes_read
;
15416 opcode
= read_1_byte (abfd
, mac_ptr
);
15418 opcode_definitions
[opcode
] = mac_ptr
;
15419 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15420 mac_ptr
+= bytes_read
;
15429 /* A helper for dwarf_decode_macros that handles the GNU extensions,
15430 including DW_MACRO_GNU_transparent_include. */
15433 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
15434 struct macro_source_file
*current_file
,
15435 struct line_header
*lh
, char *comp_dir
,
15436 struct dwarf2_section_info
*section
,
15437 int section_is_gnu
,
15438 unsigned int offset_size
,
15439 struct objfile
*objfile
,
15440 htab_t include_hash
)
15442 enum dwarf_macro_record_type macinfo_type
;
15443 int at_commandline
;
15444 gdb_byte
*opcode_definitions
[256];
15446 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
15447 &offset_size
, section_is_gnu
);
15448 if (mac_ptr
== NULL
)
15450 /* We already issued a complaint. */
15454 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
15455 GDB is still reading the definitions from command line. First
15456 DW_MACINFO_start_file will need to be ignored as it was already executed
15457 to create CURRENT_FILE for the main source holding also the command line
15458 definitions. On first met DW_MACINFO_start_file this flag is reset to
15459 normally execute all the remaining DW_MACINFO_start_file macinfos. */
15461 at_commandline
= 1;
15465 /* Do we at least have room for a macinfo type byte? */
15466 if (mac_ptr
>= mac_end
)
15468 dwarf2_macros_too_long_complaint (section
);
15472 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
15475 /* Note that we rely on the fact that the corresponding GNU and
15476 DWARF constants are the same. */
15477 switch (macinfo_type
)
15479 /* A zero macinfo type indicates the end of the macro
15484 case DW_MACRO_GNU_define
:
15485 case DW_MACRO_GNU_undef
:
15486 case DW_MACRO_GNU_define_indirect
:
15487 case DW_MACRO_GNU_undef_indirect
:
15489 unsigned int bytes_read
;
15494 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15495 mac_ptr
+= bytes_read
;
15497 if (macinfo_type
== DW_MACRO_GNU_define
15498 || macinfo_type
== DW_MACRO_GNU_undef
)
15500 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15501 mac_ptr
+= bytes_read
;
15505 LONGEST str_offset
;
15507 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
15508 mac_ptr
+= offset_size
;
15510 body
= read_indirect_string_at_offset (abfd
, str_offset
);
15513 is_define
= (macinfo_type
== DW_MACRO_GNU_define
15514 || macinfo_type
== DW_MACRO_GNU_define_indirect
);
15515 if (! current_file
)
15517 /* DWARF violation as no main source is present. */
15518 complaint (&symfile_complaints
,
15519 _("debug info with no main source gives macro %s "
15521 is_define
? _("definition") : _("undefinition"),
15525 if ((line
== 0 && !at_commandline
)
15526 || (line
!= 0 && at_commandline
))
15527 complaint (&symfile_complaints
,
15528 _("debug info gives %s macro %s with %s line %d: %s"),
15529 at_commandline
? _("command-line") : _("in-file"),
15530 is_define
? _("definition") : _("undefinition"),
15531 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
15534 parse_macro_definition (current_file
, line
, body
);
15537 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
15538 || macinfo_type
== DW_MACRO_GNU_undef_indirect
);
15539 macro_undef (current_file
, line
, body
);
15544 case DW_MACRO_GNU_start_file
:
15546 unsigned int bytes_read
;
15549 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15550 mac_ptr
+= bytes_read
;
15551 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15552 mac_ptr
+= bytes_read
;
15554 if ((line
== 0 && !at_commandline
)
15555 || (line
!= 0 && at_commandline
))
15556 complaint (&symfile_complaints
,
15557 _("debug info gives source %d included "
15558 "from %s at %s line %d"),
15559 file
, at_commandline
? _("command-line") : _("file"),
15560 line
== 0 ? _("zero") : _("non-zero"), line
);
15562 if (at_commandline
)
15564 /* This DW_MACRO_GNU_start_file was executed in the
15566 at_commandline
= 0;
15569 current_file
= macro_start_file (file
, line
,
15570 current_file
, comp_dir
,
15575 case DW_MACRO_GNU_end_file
:
15576 if (! current_file
)
15577 complaint (&symfile_complaints
,
15578 _("macro debug info has an unmatched "
15579 "`close_file' directive"));
15582 current_file
= current_file
->included_by
;
15583 if (! current_file
)
15585 enum dwarf_macro_record_type next_type
;
15587 /* GCC circa March 2002 doesn't produce the zero
15588 type byte marking the end of the compilation
15589 unit. Complain if it's not there, but exit no
15592 /* Do we at least have room for a macinfo type byte? */
15593 if (mac_ptr
>= mac_end
)
15595 dwarf2_macros_too_long_complaint (section
);
15599 /* We don't increment mac_ptr here, so this is just
15601 next_type
= read_1_byte (abfd
, mac_ptr
);
15602 if (next_type
!= 0)
15603 complaint (&symfile_complaints
,
15604 _("no terminating 0-type entry for "
15605 "macros in `.debug_macinfo' section"));
15612 case DW_MACRO_GNU_transparent_include
:
15617 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
15618 mac_ptr
+= offset_size
;
15620 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
15623 /* This has actually happened; see
15624 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
15625 complaint (&symfile_complaints
,
15626 _("recursive DW_MACRO_GNU_transparent_include in "
15627 ".debug_macro section"));
15633 dwarf_decode_macro_bytes (abfd
,
15634 section
->buffer
+ offset
,
15635 mac_end
, current_file
,
15637 section
, section_is_gnu
,
15638 offset_size
, objfile
, include_hash
);
15640 htab_remove_elt (include_hash
, mac_ptr
);
15645 case DW_MACINFO_vendor_ext
:
15646 if (!section_is_gnu
)
15648 unsigned int bytes_read
;
15651 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15652 mac_ptr
+= bytes_read
;
15653 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15654 mac_ptr
+= bytes_read
;
15656 /* We don't recognize any vendor extensions. */
15662 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
15663 mac_ptr
, abfd
, offset_size
,
15665 if (mac_ptr
== NULL
)
15669 } while (macinfo_type
!= 0);
15673 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
15674 char *comp_dir
, bfd
*abfd
,
15675 struct dwarf2_cu
*cu
,
15676 struct dwarf2_section_info
*section
,
15677 int section_is_gnu
)
15679 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15680 gdb_byte
*mac_ptr
, *mac_end
;
15681 struct macro_source_file
*current_file
= 0;
15682 enum dwarf_macro_record_type macinfo_type
;
15683 unsigned int offset_size
= cu
->header
.offset_size
;
15684 gdb_byte
*opcode_definitions
[256];
15685 struct cleanup
*cleanup
;
15686 htab_t include_hash
;
15689 dwarf2_read_section (objfile
, section
);
15690 if (section
->buffer
== NULL
)
15692 complaint (&symfile_complaints
, _("missing %s section"),
15693 section
->asection
->name
);
15697 /* First pass: Find the name of the base filename.
15698 This filename is needed in order to process all macros whose definition
15699 (or undefinition) comes from the command line. These macros are defined
15700 before the first DW_MACINFO_start_file entry, and yet still need to be
15701 associated to the base file.
15703 To determine the base file name, we scan the macro definitions until we
15704 reach the first DW_MACINFO_start_file entry. We then initialize
15705 CURRENT_FILE accordingly so that any macro definition found before the
15706 first DW_MACINFO_start_file can still be associated to the base file. */
15708 mac_ptr
= section
->buffer
+ offset
;
15709 mac_end
= section
->buffer
+ section
->size
;
15711 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
15712 &offset_size
, section_is_gnu
);
15713 if (mac_ptr
== NULL
)
15715 /* We already issued a complaint. */
15721 /* Do we at least have room for a macinfo type byte? */
15722 if (mac_ptr
>= mac_end
)
15724 /* Complaint is printed during the second pass as GDB will probably
15725 stop the first pass earlier upon finding
15726 DW_MACINFO_start_file. */
15730 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
15733 /* Note that we rely on the fact that the corresponding GNU and
15734 DWARF constants are the same. */
15735 switch (macinfo_type
)
15737 /* A zero macinfo type indicates the end of the macro
15742 case DW_MACRO_GNU_define
:
15743 case DW_MACRO_GNU_undef
:
15744 /* Only skip the data by MAC_PTR. */
15746 unsigned int bytes_read
;
15748 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15749 mac_ptr
+= bytes_read
;
15750 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15751 mac_ptr
+= bytes_read
;
15755 case DW_MACRO_GNU_start_file
:
15757 unsigned int bytes_read
;
15760 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15761 mac_ptr
+= bytes_read
;
15762 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15763 mac_ptr
+= bytes_read
;
15765 current_file
= macro_start_file (file
, line
, current_file
,
15766 comp_dir
, lh
, objfile
);
15770 case DW_MACRO_GNU_end_file
:
15771 /* No data to skip by MAC_PTR. */
15774 case DW_MACRO_GNU_define_indirect
:
15775 case DW_MACRO_GNU_undef_indirect
:
15777 unsigned int bytes_read
;
15779 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15780 mac_ptr
+= bytes_read
;
15781 mac_ptr
+= offset_size
;
15785 case DW_MACRO_GNU_transparent_include
:
15786 /* Note that, according to the spec, a transparent include
15787 chain cannot call DW_MACRO_GNU_start_file. So, we can just
15788 skip this opcode. */
15789 mac_ptr
+= offset_size
;
15792 case DW_MACINFO_vendor_ext
:
15793 /* Only skip the data by MAC_PTR. */
15794 if (!section_is_gnu
)
15796 unsigned int bytes_read
;
15798 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15799 mac_ptr
+= bytes_read
;
15800 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15801 mac_ptr
+= bytes_read
;
15806 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
15807 mac_ptr
, abfd
, offset_size
,
15809 if (mac_ptr
== NULL
)
15813 } while (macinfo_type
!= 0 && current_file
== NULL
);
15815 /* Second pass: Process all entries.
15817 Use the AT_COMMAND_LINE flag to determine whether we are still processing
15818 command-line macro definitions/undefinitions. This flag is unset when we
15819 reach the first DW_MACINFO_start_file entry. */
15821 include_hash
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
15822 NULL
, xcalloc
, xfree
);
15823 cleanup
= make_cleanup_htab_delete (include_hash
);
15824 mac_ptr
= section
->buffer
+ offset
;
15825 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
15827 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
15828 current_file
, lh
, comp_dir
, section
, section_is_gnu
,
15829 offset_size
, objfile
, include_hash
);
15830 do_cleanups (cleanup
);
15833 /* Check if the attribute's form is a DW_FORM_block*
15834 if so return true else false. */
15837 attr_form_is_block (struct attribute
*attr
)
15839 return (attr
== NULL
? 0 :
15840 attr
->form
== DW_FORM_block1
15841 || attr
->form
== DW_FORM_block2
15842 || attr
->form
== DW_FORM_block4
15843 || attr
->form
== DW_FORM_block
15844 || attr
->form
== DW_FORM_exprloc
);
15847 /* Return non-zero if ATTR's value is a section offset --- classes
15848 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
15849 You may use DW_UNSND (attr) to retrieve such offsets.
15851 Section 7.5.4, "Attribute Encodings", explains that no attribute
15852 may have a value that belongs to more than one of these classes; it
15853 would be ambiguous if we did, because we use the same forms for all
15857 attr_form_is_section_offset (struct attribute
*attr
)
15859 return (attr
->form
== DW_FORM_data4
15860 || attr
->form
== DW_FORM_data8
15861 || attr
->form
== DW_FORM_sec_offset
);
15865 /* Return non-zero if ATTR's value falls in the 'constant' class, or
15866 zero otherwise. When this function returns true, you can apply
15867 dwarf2_get_attr_constant_value to it.
15869 However, note that for some attributes you must check
15870 attr_form_is_section_offset before using this test. DW_FORM_data4
15871 and DW_FORM_data8 are members of both the constant class, and of
15872 the classes that contain offsets into other debug sections
15873 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
15874 that, if an attribute's can be either a constant or one of the
15875 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
15876 taken as section offsets, not constants. */
15879 attr_form_is_constant (struct attribute
*attr
)
15881 switch (attr
->form
)
15883 case DW_FORM_sdata
:
15884 case DW_FORM_udata
:
15885 case DW_FORM_data1
:
15886 case DW_FORM_data2
:
15887 case DW_FORM_data4
:
15888 case DW_FORM_data8
:
15895 /* A helper function that fills in a dwarf2_loclist_baton. */
15898 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
15899 struct dwarf2_loclist_baton
*baton
,
15900 struct attribute
*attr
)
15902 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
15903 &dwarf2_per_objfile
->loc
);
15905 baton
->per_cu
= cu
->per_cu
;
15906 gdb_assert (baton
->per_cu
);
15907 /* We don't know how long the location list is, but make sure we
15908 don't run off the edge of the section. */
15909 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
15910 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
15911 baton
->base_address
= cu
->base_address
;
15915 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
15916 struct dwarf2_cu
*cu
)
15918 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15920 if (attr_form_is_section_offset (attr
)
15921 /* ".debug_loc" may not exist at all, or the offset may be outside
15922 the section. If so, fall through to the complaint in the
15924 && DW_UNSND (attr
) < dwarf2_section_size (objfile
,
15925 &dwarf2_per_objfile
->loc
))
15927 struct dwarf2_loclist_baton
*baton
;
15929 baton
= obstack_alloc (&objfile
->objfile_obstack
,
15930 sizeof (struct dwarf2_loclist_baton
));
15932 fill_in_loclist_baton (cu
, baton
, attr
);
15934 if (cu
->base_known
== 0)
15935 complaint (&symfile_complaints
,
15936 _("Location list used without "
15937 "specifying the CU base address."));
15939 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
15940 SYMBOL_LOCATION_BATON (sym
) = baton
;
15944 struct dwarf2_locexpr_baton
*baton
;
15946 baton
= obstack_alloc (&objfile
->objfile_obstack
,
15947 sizeof (struct dwarf2_locexpr_baton
));
15948 baton
->per_cu
= cu
->per_cu
;
15949 gdb_assert (baton
->per_cu
);
15951 if (attr_form_is_block (attr
))
15953 /* Note that we're just copying the block's data pointer
15954 here, not the actual data. We're still pointing into the
15955 info_buffer for SYM's objfile; right now we never release
15956 that buffer, but when we do clean up properly this may
15958 baton
->size
= DW_BLOCK (attr
)->size
;
15959 baton
->data
= DW_BLOCK (attr
)->data
;
15963 dwarf2_invalid_attrib_class_complaint ("location description",
15964 SYMBOL_NATURAL_NAME (sym
));
15968 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
15969 SYMBOL_LOCATION_BATON (sym
) = baton
;
15973 /* Return the OBJFILE associated with the compilation unit CU. If CU
15974 came from a separate debuginfo file, then the master objfile is
15978 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
15980 struct objfile
*objfile
= per_cu
->objfile
;
15982 /* Return the master objfile, so that we can report and look up the
15983 correct file containing this variable. */
15984 if (objfile
->separate_debug_objfile_backlink
)
15985 objfile
= objfile
->separate_debug_objfile_backlink
;
15990 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
15991 (CU_HEADERP is unused in such case) or prepare a temporary copy at
15992 CU_HEADERP first. */
15994 static const struct comp_unit_head
*
15995 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
15996 struct dwarf2_per_cu_data
*per_cu
)
15998 struct objfile
*objfile
;
15999 struct dwarf2_per_objfile
*per_objfile
;
16000 gdb_byte
*info_ptr
;
16003 return &per_cu
->cu
->header
;
16005 objfile
= per_cu
->objfile
;
16006 per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
16007 info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
.sect_off
;
16009 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
16010 read_comp_unit_head (cu_headerp
, info_ptr
, objfile
->obfd
);
16015 /* Return the address size given in the compilation unit header for CU. */
16018 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
16020 struct comp_unit_head cu_header_local
;
16021 const struct comp_unit_head
*cu_headerp
;
16023 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
16025 return cu_headerp
->addr_size
;
16028 /* Return the offset size given in the compilation unit header for CU. */
16031 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
16033 struct comp_unit_head cu_header_local
;
16034 const struct comp_unit_head
*cu_headerp
;
16036 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
16038 return cu_headerp
->offset_size
;
16041 /* See its dwarf2loc.h declaration. */
16044 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
16046 struct comp_unit_head cu_header_local
;
16047 const struct comp_unit_head
*cu_headerp
;
16049 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
16051 if (cu_headerp
->version
== 2)
16052 return cu_headerp
->addr_size
;
16054 return cu_headerp
->offset_size
;
16057 /* Return the text offset of the CU. The returned offset comes from
16058 this CU's objfile. If this objfile came from a separate debuginfo
16059 file, then the offset may be different from the corresponding
16060 offset in the parent objfile. */
16063 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
16065 struct objfile
*objfile
= per_cu
->objfile
;
16067 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
16070 /* Locate the .debug_info compilation unit from CU's objfile which contains
16071 the DIE at OFFSET. Raises an error on failure. */
16073 static struct dwarf2_per_cu_data
*
16074 dwarf2_find_containing_comp_unit (sect_offset offset
,
16075 struct objfile
*objfile
)
16077 struct dwarf2_per_cu_data
*this_cu
;
16081 high
= dwarf2_per_objfile
->n_comp_units
- 1;
16084 int mid
= low
+ (high
- low
) / 2;
16086 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
.sect_off
16087 >= offset
.sect_off
)
16092 gdb_assert (low
== high
);
16093 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
.sect_off
16097 error (_("Dwarf Error: could not find partial DIE containing "
16098 "offset 0x%lx [in module %s]"),
16099 (long) offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
16101 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
.sect_off
16102 <= offset
.sect_off
);
16103 return dwarf2_per_objfile
->all_comp_units
[low
-1];
16107 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
16108 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
16109 && offset
.sect_off
>= this_cu
->offset
.sect_off
+ this_cu
->length
)
16110 error (_("invalid dwarf2 offset %u"), offset
.sect_off
);
16111 gdb_assert (offset
.sect_off
< this_cu
->offset
.sect_off
+ this_cu
->length
);
16116 /* Initialize dwarf2_cu CU, owned by PER_CU. */
16119 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
16121 memset (cu
, 0, sizeof (*cu
));
16123 cu
->per_cu
= per_cu
;
16124 cu
->objfile
= per_cu
->objfile
;
16125 obstack_init (&cu
->comp_unit_obstack
);
16128 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
16131 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
)
16133 struct attribute
*attr
;
16135 /* Set the language we're debugging. */
16136 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
16138 set_cu_language (DW_UNSND (attr
), cu
);
16141 cu
->language
= language_minimal
;
16142 cu
->language_defn
= language_def (cu
->language
);
16146 /* Release one cached compilation unit, CU. We unlink it from the tree
16147 of compilation units, but we don't remove it from the read_in_chain;
16148 the caller is responsible for that.
16149 NOTE: DATA is a void * because this function is also used as a
16150 cleanup routine. */
16153 free_heap_comp_unit (void *data
)
16155 struct dwarf2_cu
*cu
= data
;
16157 gdb_assert (cu
->per_cu
!= NULL
);
16158 cu
->per_cu
->cu
= NULL
;
16161 obstack_free (&cu
->comp_unit_obstack
, NULL
);
16166 /* This cleanup function is passed the address of a dwarf2_cu on the stack
16167 when we're finished with it. We can't free the pointer itself, but be
16168 sure to unlink it from the cache. Also release any associated storage
16169 and perform cache maintenance.
16171 Only used during partial symbol parsing. */
16174 free_stack_comp_unit (void *data
)
16176 struct dwarf2_cu
*cu
= data
;
16178 gdb_assert (cu
->per_cu
!= NULL
);
16179 cu
->per_cu
->cu
= NULL
;
16182 obstack_free (&cu
->comp_unit_obstack
, NULL
);
16183 cu
->partial_dies
= NULL
;
16185 /* The previous code only did this if per_cu != NULL.
16186 But that would always succeed, so now we just unconditionally do
16187 the aging. This seems like the wrong place to do such aging,
16188 but cleaning that up is left for later. */
16189 age_cached_comp_units ();
16192 /* Free all cached compilation units. */
16195 free_cached_comp_units (void *data
)
16197 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
16199 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16200 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
16201 while (per_cu
!= NULL
)
16203 struct dwarf2_per_cu_data
*next_cu
;
16205 next_cu
= per_cu
->cu
->read_in_chain
;
16207 free_heap_comp_unit (per_cu
->cu
);
16208 *last_chain
= next_cu
;
16214 /* Increase the age counter on each cached compilation unit, and free
16215 any that are too old. */
16218 age_cached_comp_units (void)
16220 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
16222 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
16223 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16224 while (per_cu
!= NULL
)
16226 per_cu
->cu
->last_used
++;
16227 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
16228 dwarf2_mark (per_cu
->cu
);
16229 per_cu
= per_cu
->cu
->read_in_chain
;
16232 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16233 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
16234 while (per_cu
!= NULL
)
16236 struct dwarf2_per_cu_data
*next_cu
;
16238 next_cu
= per_cu
->cu
->read_in_chain
;
16240 if (!per_cu
->cu
->mark
)
16242 free_heap_comp_unit (per_cu
->cu
);
16243 *last_chain
= next_cu
;
16246 last_chain
= &per_cu
->cu
->read_in_chain
;
16252 /* Remove a single compilation unit from the cache. */
16255 free_one_cached_comp_unit (void *target_cu
)
16257 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
16259 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16260 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
16261 while (per_cu
!= NULL
)
16263 struct dwarf2_per_cu_data
*next_cu
;
16265 next_cu
= per_cu
->cu
->read_in_chain
;
16267 if (per_cu
->cu
== target_cu
)
16269 free_heap_comp_unit (per_cu
->cu
);
16270 *last_chain
= next_cu
;
16274 last_chain
= &per_cu
->cu
->read_in_chain
;
16280 /* Release all extra memory associated with OBJFILE. */
16283 dwarf2_free_objfile (struct objfile
*objfile
)
16285 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
16287 if (dwarf2_per_objfile
== NULL
)
16290 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
16291 free_cached_comp_units (NULL
);
16293 if (dwarf2_per_objfile
->quick_file_names_table
)
16294 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
16296 /* Everything else should be on the objfile obstack. */
16299 /* A pair of DIE offset and GDB type pointer. We store these
16300 in a hash table separate from the DIEs, and preserve them
16301 when the DIEs are flushed out of cache. */
16303 struct dwarf2_offset_and_type
16305 sect_offset offset
;
16309 /* Hash function for a dwarf2_offset_and_type. */
16312 offset_and_type_hash (const void *item
)
16314 const struct dwarf2_offset_and_type
*ofs
= item
;
16316 return ofs
->offset
.sect_off
;
16319 /* Equality function for a dwarf2_offset_and_type. */
16322 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
16324 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
16325 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
16327 return ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
;
16330 /* Set the type associated with DIE to TYPE. Save it in CU's hash
16331 table if necessary. For convenience, return TYPE.
16333 The DIEs reading must have careful ordering to:
16334 * Not cause infite loops trying to read in DIEs as a prerequisite for
16335 reading current DIE.
16336 * Not trying to dereference contents of still incompletely read in types
16337 while reading in other DIEs.
16338 * Enable referencing still incompletely read in types just by a pointer to
16339 the type without accessing its fields.
16341 Therefore caller should follow these rules:
16342 * Try to fetch any prerequisite types we may need to build this DIE type
16343 before building the type and calling set_die_type.
16344 * After building type call set_die_type for current DIE as soon as
16345 possible before fetching more types to complete the current type.
16346 * Make the type as complete as possible before fetching more types. */
16348 static struct type
*
16349 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
16351 struct dwarf2_offset_and_type
**slot
, ofs
;
16352 struct objfile
*objfile
= cu
->objfile
;
16353 htab_t
*type_hash_ptr
;
16355 /* For Ada types, make sure that the gnat-specific data is always
16356 initialized (if not already set). There are a few types where
16357 we should not be doing so, because the type-specific area is
16358 already used to hold some other piece of info (eg: TYPE_CODE_FLT
16359 where the type-specific area is used to store the floatformat).
16360 But this is not a problem, because the gnat-specific information
16361 is actually not needed for these types. */
16362 if (need_gnat_info (cu
)
16363 && TYPE_CODE (type
) != TYPE_CODE_FUNC
16364 && TYPE_CODE (type
) != TYPE_CODE_FLT
16365 && !HAVE_GNAT_AUX_INFO (type
))
16366 INIT_GNAT_SPECIFIC (type
);
16368 if (cu
->per_cu
->debug_types_section
)
16369 type_hash_ptr
= &dwarf2_per_objfile
->debug_types_type_hash
;
16371 type_hash_ptr
= &dwarf2_per_objfile
->debug_info_type_hash
;
16373 if (*type_hash_ptr
== NULL
)
16376 = htab_create_alloc_ex (127,
16377 offset_and_type_hash
,
16378 offset_and_type_eq
,
16380 &objfile
->objfile_obstack
,
16381 hashtab_obstack_allocate
,
16382 dummy_obstack_deallocate
);
16385 ofs
.offset
= die
->offset
;
16387 slot
= (struct dwarf2_offset_and_type
**)
16388 htab_find_slot_with_hash (*type_hash_ptr
, &ofs
, ofs
.offset
.sect_off
,
16391 complaint (&symfile_complaints
,
16392 _("A problem internal to GDB: DIE 0x%x has type already set"),
16393 die
->offset
.sect_off
);
16394 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
16399 /* Look up the type for the die at OFFSET in the appropriate type_hash
16400 table, or return NULL if the die does not have a saved type. */
16402 static struct type
*
16403 get_die_type_at_offset (sect_offset offset
,
16404 struct dwarf2_per_cu_data
*per_cu
)
16406 struct dwarf2_offset_and_type
*slot
, ofs
;
16409 if (per_cu
->debug_types_section
)
16410 type_hash
= dwarf2_per_objfile
->debug_types_type_hash
;
16412 type_hash
= dwarf2_per_objfile
->debug_info_type_hash
;
16413 if (type_hash
== NULL
)
16416 ofs
.offset
= offset
;
16417 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
.sect_off
);
16424 /* Look up the type for DIE in the appropriate type_hash table,
16425 or return NULL if DIE does not have a saved type. */
16427 static struct type
*
16428 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16430 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
16433 /* Add a dependence relationship from CU to REF_PER_CU. */
16436 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
16437 struct dwarf2_per_cu_data
*ref_per_cu
)
16441 if (cu
->dependencies
== NULL
)
16443 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
16444 NULL
, &cu
->comp_unit_obstack
,
16445 hashtab_obstack_allocate
,
16446 dummy_obstack_deallocate
);
16448 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
16450 *slot
= ref_per_cu
;
16453 /* Subroutine of dwarf2_mark to pass to htab_traverse.
16454 Set the mark field in every compilation unit in the
16455 cache that we must keep because we are keeping CU. */
16458 dwarf2_mark_helper (void **slot
, void *data
)
16460 struct dwarf2_per_cu_data
*per_cu
;
16462 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
16464 /* cu->dependencies references may not yet have been ever read if QUIT aborts
16465 reading of the chain. As such dependencies remain valid it is not much
16466 useful to track and undo them during QUIT cleanups. */
16467 if (per_cu
->cu
== NULL
)
16470 if (per_cu
->cu
->mark
)
16472 per_cu
->cu
->mark
= 1;
16474 if (per_cu
->cu
->dependencies
!= NULL
)
16475 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
16480 /* Set the mark field in CU and in every other compilation unit in the
16481 cache that we must keep because we are keeping CU. */
16484 dwarf2_mark (struct dwarf2_cu
*cu
)
16489 if (cu
->dependencies
!= NULL
)
16490 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
16494 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
16498 per_cu
->cu
->mark
= 0;
16499 per_cu
= per_cu
->cu
->read_in_chain
;
16503 /* Trivial hash function for partial_die_info: the hash value of a DIE
16504 is its offset in .debug_info for this objfile. */
16507 partial_die_hash (const void *item
)
16509 const struct partial_die_info
*part_die
= item
;
16511 return part_die
->offset
.sect_off
;
16514 /* Trivial comparison function for partial_die_info structures: two DIEs
16515 are equal if they have the same offset. */
16518 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
16520 const struct partial_die_info
*part_die_lhs
= item_lhs
;
16521 const struct partial_die_info
*part_die_rhs
= item_rhs
;
16523 return part_die_lhs
->offset
.sect_off
== part_die_rhs
->offset
.sect_off
;
16526 static struct cmd_list_element
*set_dwarf2_cmdlist
;
16527 static struct cmd_list_element
*show_dwarf2_cmdlist
;
16530 set_dwarf2_cmd (char *args
, int from_tty
)
16532 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
16536 show_dwarf2_cmd (char *args
, int from_tty
)
16538 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
16541 /* If section described by INFO was mmapped, munmap it now. */
16544 munmap_section_buffer (struct dwarf2_section_info
*info
)
16546 if (info
->map_addr
!= NULL
)
16551 res
= munmap (info
->map_addr
, info
->map_len
);
16552 gdb_assert (res
== 0);
16554 /* Without HAVE_MMAP, we should never be here to begin with. */
16555 gdb_assert_not_reached ("no mmap support");
16560 /* munmap debug sections for OBJFILE, if necessary. */
16563 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
16565 struct dwarf2_per_objfile
*data
= d
;
16567 struct dwarf2_section_info
*section
;
16569 /* This is sorted according to the order they're defined in to make it easier
16570 to keep in sync. */
16571 munmap_section_buffer (&data
->info
);
16572 munmap_section_buffer (&data
->abbrev
);
16573 munmap_section_buffer (&data
->line
);
16574 munmap_section_buffer (&data
->loc
);
16575 munmap_section_buffer (&data
->macinfo
);
16576 munmap_section_buffer (&data
->macro
);
16577 munmap_section_buffer (&data
->str
);
16578 munmap_section_buffer (&data
->ranges
);
16579 munmap_section_buffer (&data
->frame
);
16580 munmap_section_buffer (&data
->eh_frame
);
16581 munmap_section_buffer (&data
->gdb_index
);
16584 VEC_iterate (dwarf2_section_info_def
, data
->types
, ix
, section
);
16586 munmap_section_buffer (section
);
16588 VEC_free (dwarf2_section_info_def
, data
->types
);
16592 /* The "save gdb-index" command. */
16594 /* The contents of the hash table we create when building the string
16596 struct strtab_entry
16598 offset_type offset
;
16602 /* Hash function for a strtab_entry.
16604 Function is used only during write_hash_table so no index format backward
16605 compatibility is needed. */
16608 hash_strtab_entry (const void *e
)
16610 const struct strtab_entry
*entry
= e
;
16611 return mapped_index_string_hash (INT_MAX
, entry
->str
);
16614 /* Equality function for a strtab_entry. */
16617 eq_strtab_entry (const void *a
, const void *b
)
16619 const struct strtab_entry
*ea
= a
;
16620 const struct strtab_entry
*eb
= b
;
16621 return !strcmp (ea
->str
, eb
->str
);
16624 /* Create a strtab_entry hash table. */
16627 create_strtab (void)
16629 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
16630 xfree
, xcalloc
, xfree
);
16633 /* Add a string to the constant pool. Return the string's offset in
16637 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
16640 struct strtab_entry entry
;
16641 struct strtab_entry
*result
;
16644 slot
= htab_find_slot (table
, &entry
, INSERT
);
16649 result
= XNEW (struct strtab_entry
);
16650 result
->offset
= obstack_object_size (cpool
);
16652 obstack_grow_str0 (cpool
, str
);
16655 return result
->offset
;
16658 /* An entry in the symbol table. */
16659 struct symtab_index_entry
16661 /* The name of the symbol. */
16663 /* The offset of the name in the constant pool. */
16664 offset_type index_offset
;
16665 /* A sorted vector of the indices of all the CUs that hold an object
16667 VEC (offset_type
) *cu_indices
;
16670 /* The symbol table. This is a power-of-2-sized hash table. */
16671 struct mapped_symtab
16673 offset_type n_elements
;
16675 struct symtab_index_entry
**data
;
16678 /* Hash function for a symtab_index_entry. */
16681 hash_symtab_entry (const void *e
)
16683 const struct symtab_index_entry
*entry
= e
;
16684 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
16685 sizeof (offset_type
) * VEC_length (offset_type
,
16686 entry
->cu_indices
),
16690 /* Equality function for a symtab_index_entry. */
16693 eq_symtab_entry (const void *a
, const void *b
)
16695 const struct symtab_index_entry
*ea
= a
;
16696 const struct symtab_index_entry
*eb
= b
;
16697 int len
= VEC_length (offset_type
, ea
->cu_indices
);
16698 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
16700 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
16701 VEC_address (offset_type
, eb
->cu_indices
),
16702 sizeof (offset_type
) * len
);
16705 /* Destroy a symtab_index_entry. */
16708 delete_symtab_entry (void *p
)
16710 struct symtab_index_entry
*entry
= p
;
16711 VEC_free (offset_type
, entry
->cu_indices
);
16715 /* Create a hash table holding symtab_index_entry objects. */
16718 create_symbol_hash_table (void)
16720 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
16721 delete_symtab_entry
, xcalloc
, xfree
);
16724 /* Create a new mapped symtab object. */
16726 static struct mapped_symtab
*
16727 create_mapped_symtab (void)
16729 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
16730 symtab
->n_elements
= 0;
16731 symtab
->size
= 1024;
16732 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
16736 /* Destroy a mapped_symtab. */
16739 cleanup_mapped_symtab (void *p
)
16741 struct mapped_symtab
*symtab
= p
;
16742 /* The contents of the array are freed when the other hash table is
16744 xfree (symtab
->data
);
16748 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
16751 Function is used only during write_hash_table so no index format backward
16752 compatibility is needed. */
16754 static struct symtab_index_entry
**
16755 find_slot (struct mapped_symtab
*symtab
, const char *name
)
16757 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
16759 index
= hash
& (symtab
->size
- 1);
16760 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
16764 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
16765 return &symtab
->data
[index
];
16766 index
= (index
+ step
) & (symtab
->size
- 1);
16770 /* Expand SYMTAB's hash table. */
16773 hash_expand (struct mapped_symtab
*symtab
)
16775 offset_type old_size
= symtab
->size
;
16777 struct symtab_index_entry
**old_entries
= symtab
->data
;
16780 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
16782 for (i
= 0; i
< old_size
; ++i
)
16784 if (old_entries
[i
])
16786 struct symtab_index_entry
**slot
= find_slot (symtab
,
16787 old_entries
[i
]->name
);
16788 *slot
= old_entries
[i
];
16792 xfree (old_entries
);
16795 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
16796 is the index of the CU in which the symbol appears. */
16799 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
16800 offset_type cu_index
)
16802 struct symtab_index_entry
**slot
;
16804 ++symtab
->n_elements
;
16805 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
16806 hash_expand (symtab
);
16808 slot
= find_slot (symtab
, name
);
16811 *slot
= XNEW (struct symtab_index_entry
);
16812 (*slot
)->name
= name
;
16813 (*slot
)->cu_indices
= NULL
;
16815 /* Don't push an index twice. Due to how we add entries we only
16816 have to check the last one. */
16817 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
16818 || VEC_last (offset_type
, (*slot
)->cu_indices
) != cu_index
)
16819 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
16822 /* Add a vector of indices to the constant pool. */
16825 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
16826 struct symtab_index_entry
*entry
)
16830 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
16833 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
16834 offset_type val
= MAYBE_SWAP (len
);
16839 entry
->index_offset
= obstack_object_size (cpool
);
16841 obstack_grow (cpool
, &val
, sizeof (val
));
16843 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
16846 val
= MAYBE_SWAP (iter
);
16847 obstack_grow (cpool
, &val
, sizeof (val
));
16852 struct symtab_index_entry
*old_entry
= *slot
;
16853 entry
->index_offset
= old_entry
->index_offset
;
16856 return entry
->index_offset
;
16859 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
16860 constant pool entries going into the obstack CPOOL. */
16863 write_hash_table (struct mapped_symtab
*symtab
,
16864 struct obstack
*output
, struct obstack
*cpool
)
16867 htab_t symbol_hash_table
;
16870 symbol_hash_table
= create_symbol_hash_table ();
16871 str_table
= create_strtab ();
16873 /* We add all the index vectors to the constant pool first, to
16874 ensure alignment is ok. */
16875 for (i
= 0; i
< symtab
->size
; ++i
)
16877 if (symtab
->data
[i
])
16878 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
16881 /* Now write out the hash table. */
16882 for (i
= 0; i
< symtab
->size
; ++i
)
16884 offset_type str_off
, vec_off
;
16886 if (symtab
->data
[i
])
16888 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
16889 vec_off
= symtab
->data
[i
]->index_offset
;
16893 /* While 0 is a valid constant pool index, it is not valid
16894 to have 0 for both offsets. */
16899 str_off
= MAYBE_SWAP (str_off
);
16900 vec_off
= MAYBE_SWAP (vec_off
);
16902 obstack_grow (output
, &str_off
, sizeof (str_off
));
16903 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
16906 htab_delete (str_table
);
16907 htab_delete (symbol_hash_table
);
16910 /* Struct to map psymtab to CU index in the index file. */
16911 struct psymtab_cu_index_map
16913 struct partial_symtab
*psymtab
;
16914 unsigned int cu_index
;
16918 hash_psymtab_cu_index (const void *item
)
16920 const struct psymtab_cu_index_map
*map
= item
;
16922 return htab_hash_pointer (map
->psymtab
);
16926 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
16928 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
16929 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
16931 return lhs
->psymtab
== rhs
->psymtab
;
16934 /* Helper struct for building the address table. */
16935 struct addrmap_index_data
16937 struct objfile
*objfile
;
16938 struct obstack
*addr_obstack
;
16939 htab_t cu_index_htab
;
16941 /* Non-zero if the previous_* fields are valid.
16942 We can't write an entry until we see the next entry (since it is only then
16943 that we know the end of the entry). */
16944 int previous_valid
;
16945 /* Index of the CU in the table of all CUs in the index file. */
16946 unsigned int previous_cu_index
;
16947 /* Start address of the CU. */
16948 CORE_ADDR previous_cu_start
;
16951 /* Write an address entry to OBSTACK. */
16954 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
16955 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
16957 offset_type cu_index_to_write
;
16959 CORE_ADDR baseaddr
;
16961 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
16963 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
16964 obstack_grow (obstack
, addr
, 8);
16965 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
16966 obstack_grow (obstack
, addr
, 8);
16967 cu_index_to_write
= MAYBE_SWAP (cu_index
);
16968 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
16971 /* Worker function for traversing an addrmap to build the address table. */
16974 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
16976 struct addrmap_index_data
*data
= datap
;
16977 struct partial_symtab
*pst
= obj
;
16978 offset_type cu_index
;
16981 if (data
->previous_valid
)
16982 add_address_entry (data
->objfile
, data
->addr_obstack
,
16983 data
->previous_cu_start
, start_addr
,
16984 data
->previous_cu_index
);
16986 data
->previous_cu_start
= start_addr
;
16989 struct psymtab_cu_index_map find_map
, *map
;
16990 find_map
.psymtab
= pst
;
16991 map
= htab_find (data
->cu_index_htab
, &find_map
);
16992 gdb_assert (map
!= NULL
);
16993 data
->previous_cu_index
= map
->cu_index
;
16994 data
->previous_valid
= 1;
16997 data
->previous_valid
= 0;
17002 /* Write OBJFILE's address map to OBSTACK.
17003 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
17004 in the index file. */
17007 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
17008 htab_t cu_index_htab
)
17010 struct addrmap_index_data addrmap_index_data
;
17012 /* When writing the address table, we have to cope with the fact that
17013 the addrmap iterator only provides the start of a region; we have to
17014 wait until the next invocation to get the start of the next region. */
17016 addrmap_index_data
.objfile
= objfile
;
17017 addrmap_index_data
.addr_obstack
= obstack
;
17018 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
17019 addrmap_index_data
.previous_valid
= 0;
17021 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
17022 &addrmap_index_data
);
17024 /* It's highly unlikely the last entry (end address = 0xff...ff)
17025 is valid, but we should still handle it.
17026 The end address is recorded as the start of the next region, but that
17027 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
17029 if (addrmap_index_data
.previous_valid
)
17030 add_address_entry (objfile
, obstack
,
17031 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
17032 addrmap_index_data
.previous_cu_index
);
17035 /* Add a list of partial symbols to SYMTAB. */
17038 write_psymbols (struct mapped_symtab
*symtab
,
17040 struct partial_symbol
**psymp
,
17042 offset_type cu_index
,
17045 for (; count
-- > 0; ++psymp
)
17047 void **slot
, *lookup
;
17049 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
17050 error (_("Ada is not currently supported by the index"));
17052 /* We only want to add a given psymbol once. However, we also
17053 want to account for whether it is global or static. So, we
17054 may add it twice, using slightly different values. */
17057 uintptr_t val
= 1 | (uintptr_t) *psymp
;
17059 lookup
= (void *) val
;
17064 /* Only add a given psymbol once. */
17065 slot
= htab_find_slot (psyms_seen
, lookup
, INSERT
);
17069 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (*psymp
), cu_index
);
17074 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
17075 exception if there is an error. */
17078 write_obstack (FILE *file
, struct obstack
*obstack
)
17080 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
17082 != obstack_object_size (obstack
))
17083 error (_("couldn't data write to file"));
17086 /* Unlink a file if the argument is not NULL. */
17089 unlink_if_set (void *p
)
17091 char **filename
= p
;
17093 unlink (*filename
);
17096 /* A helper struct used when iterating over debug_types. */
17097 struct signatured_type_index_data
17099 struct objfile
*objfile
;
17100 struct mapped_symtab
*symtab
;
17101 struct obstack
*types_list
;
17106 /* A helper function that writes a single signatured_type to an
17110 write_one_signatured_type (void **slot
, void *d
)
17112 struct signatured_type_index_data
*info
= d
;
17113 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
17114 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
17115 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
17118 write_psymbols (info
->symtab
,
17120 info
->objfile
->global_psymbols
.list
17121 + psymtab
->globals_offset
,
17122 psymtab
->n_global_syms
, info
->cu_index
,
17124 write_psymbols (info
->symtab
,
17126 info
->objfile
->static_psymbols
.list
17127 + psymtab
->statics_offset
,
17128 psymtab
->n_static_syms
, info
->cu_index
,
17131 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
17132 entry
->per_cu
.offset
.sect_off
);
17133 obstack_grow (info
->types_list
, val
, 8);
17134 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->type_offset
.cu_off
);
17135 obstack_grow (info
->types_list
, val
, 8);
17136 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
17137 obstack_grow (info
->types_list
, val
, 8);
17144 /* Create an index file for OBJFILE in the directory DIR. */
17147 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
17149 struct cleanup
*cleanup
;
17150 char *filename
, *cleanup_filename
;
17151 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
17152 struct obstack cu_list
, types_cu_list
;
17155 struct mapped_symtab
*symtab
;
17156 offset_type val
, size_of_contents
, total_len
;
17160 htab_t cu_index_htab
;
17161 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
17163 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
17166 if (dwarf2_per_objfile
->using_index
)
17167 error (_("Cannot use an index to create the index"));
17169 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
17170 error (_("Cannot make an index when the file has multiple .debug_types sections"));
17172 if (stat (objfile
->name
, &st
) < 0)
17173 perror_with_name (objfile
->name
);
17175 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
17176 INDEX_SUFFIX
, (char *) NULL
);
17177 cleanup
= make_cleanup (xfree
, filename
);
17179 out_file
= fopen (filename
, "wb");
17181 error (_("Can't open `%s' for writing"), filename
);
17183 cleanup_filename
= filename
;
17184 make_cleanup (unlink_if_set
, &cleanup_filename
);
17186 symtab
= create_mapped_symtab ();
17187 make_cleanup (cleanup_mapped_symtab
, symtab
);
17189 obstack_init (&addr_obstack
);
17190 make_cleanup_obstack_free (&addr_obstack
);
17192 obstack_init (&cu_list
);
17193 make_cleanup_obstack_free (&cu_list
);
17195 obstack_init (&types_cu_list
);
17196 make_cleanup_obstack_free (&types_cu_list
);
17198 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
17199 NULL
, xcalloc
, xfree
);
17200 make_cleanup_htab_delete (psyms_seen
);
17202 /* While we're scanning CU's create a table that maps a psymtab pointer
17203 (which is what addrmap records) to its index (which is what is recorded
17204 in the index file). This will later be needed to write the address
17206 cu_index_htab
= htab_create_alloc (100,
17207 hash_psymtab_cu_index
,
17208 eq_psymtab_cu_index
,
17209 NULL
, xcalloc
, xfree
);
17210 make_cleanup_htab_delete (cu_index_htab
);
17211 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
17212 xmalloc (sizeof (struct psymtab_cu_index_map
)
17213 * dwarf2_per_objfile
->n_comp_units
);
17214 make_cleanup (xfree
, psymtab_cu_index_map
);
17216 /* The CU list is already sorted, so we don't need to do additional
17217 work here. Also, the debug_types entries do not appear in
17218 all_comp_units, but only in their own hash table. */
17219 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
17221 struct dwarf2_per_cu_data
*per_cu
17222 = dwarf2_per_objfile
->all_comp_units
[i
];
17223 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
17225 struct psymtab_cu_index_map
*map
;
17228 write_psymbols (symtab
,
17230 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
17231 psymtab
->n_global_syms
, i
,
17233 write_psymbols (symtab
,
17235 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
17236 psymtab
->n_static_syms
, i
,
17239 map
= &psymtab_cu_index_map
[i
];
17240 map
->psymtab
= psymtab
;
17242 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
17243 gdb_assert (slot
!= NULL
);
17244 gdb_assert (*slot
== NULL
);
17247 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
17248 per_cu
->offset
.sect_off
);
17249 obstack_grow (&cu_list
, val
, 8);
17250 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
17251 obstack_grow (&cu_list
, val
, 8);
17254 /* Dump the address map. */
17255 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
17257 /* Write out the .debug_type entries, if any. */
17258 if (dwarf2_per_objfile
->signatured_types
)
17260 struct signatured_type_index_data sig_data
;
17262 sig_data
.objfile
= objfile
;
17263 sig_data
.symtab
= symtab
;
17264 sig_data
.types_list
= &types_cu_list
;
17265 sig_data
.psyms_seen
= psyms_seen
;
17266 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
17267 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
17268 write_one_signatured_type
, &sig_data
);
17271 obstack_init (&constant_pool
);
17272 make_cleanup_obstack_free (&constant_pool
);
17273 obstack_init (&symtab_obstack
);
17274 make_cleanup_obstack_free (&symtab_obstack
);
17275 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
17277 obstack_init (&contents
);
17278 make_cleanup_obstack_free (&contents
);
17279 size_of_contents
= 6 * sizeof (offset_type
);
17280 total_len
= size_of_contents
;
17282 /* The version number. */
17283 val
= MAYBE_SWAP (6);
17284 obstack_grow (&contents
, &val
, sizeof (val
));
17286 /* The offset of the CU list from the start of the file. */
17287 val
= MAYBE_SWAP (total_len
);
17288 obstack_grow (&contents
, &val
, sizeof (val
));
17289 total_len
+= obstack_object_size (&cu_list
);
17291 /* The offset of the types CU list from the start of the file. */
17292 val
= MAYBE_SWAP (total_len
);
17293 obstack_grow (&contents
, &val
, sizeof (val
));
17294 total_len
+= obstack_object_size (&types_cu_list
);
17296 /* The offset of the address table from the start of the file. */
17297 val
= MAYBE_SWAP (total_len
);
17298 obstack_grow (&contents
, &val
, sizeof (val
));
17299 total_len
+= obstack_object_size (&addr_obstack
);
17301 /* The offset of the symbol table from the start of the file. */
17302 val
= MAYBE_SWAP (total_len
);
17303 obstack_grow (&contents
, &val
, sizeof (val
));
17304 total_len
+= obstack_object_size (&symtab_obstack
);
17306 /* The offset of the constant pool from the start of the file. */
17307 val
= MAYBE_SWAP (total_len
);
17308 obstack_grow (&contents
, &val
, sizeof (val
));
17309 total_len
+= obstack_object_size (&constant_pool
);
17311 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
17313 write_obstack (out_file
, &contents
);
17314 write_obstack (out_file
, &cu_list
);
17315 write_obstack (out_file
, &types_cu_list
);
17316 write_obstack (out_file
, &addr_obstack
);
17317 write_obstack (out_file
, &symtab_obstack
);
17318 write_obstack (out_file
, &constant_pool
);
17322 /* We want to keep the file, so we set cleanup_filename to NULL
17323 here. See unlink_if_set. */
17324 cleanup_filename
= NULL
;
17326 do_cleanups (cleanup
);
17329 /* Implementation of the `save gdb-index' command.
17331 Note that the file format used by this command is documented in the
17332 GDB manual. Any changes here must be documented there. */
17335 save_gdb_index_command (char *arg
, int from_tty
)
17337 struct objfile
*objfile
;
17340 error (_("usage: save gdb-index DIRECTORY"));
17342 ALL_OBJFILES (objfile
)
17346 /* If the objfile does not correspond to an actual file, skip it. */
17347 if (stat (objfile
->name
, &st
) < 0)
17350 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
17351 if (dwarf2_per_objfile
)
17353 volatile struct gdb_exception except
;
17355 TRY_CATCH (except
, RETURN_MASK_ERROR
)
17357 write_psymtabs_to_index (objfile
, arg
);
17359 if (except
.reason
< 0)
17360 exception_fprintf (gdb_stderr
, except
,
17361 _("Error while writing index for `%s': "),
17369 int dwarf2_always_disassemble
;
17372 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
17373 struct cmd_list_element
*c
, const char *value
)
17375 fprintf_filtered (file
,
17376 _("Whether to always disassemble "
17377 "DWARF expressions is %s.\n"),
17382 show_check_physname (struct ui_file
*file
, int from_tty
,
17383 struct cmd_list_element
*c
, const char *value
)
17385 fprintf_filtered (file
,
17386 _("Whether to check \"physname\" is %s.\n"),
17390 void _initialize_dwarf2_read (void);
17393 _initialize_dwarf2_read (void)
17395 struct cmd_list_element
*c
;
17397 dwarf2_objfile_data_key
17398 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
17400 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
17401 Set DWARF 2 specific variables.\n\
17402 Configure DWARF 2 variables such as the cache size"),
17403 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
17404 0/*allow-unknown*/, &maintenance_set_cmdlist
);
17406 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
17407 Show DWARF 2 specific variables\n\
17408 Show DWARF 2 variables such as the cache size"),
17409 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
17410 0/*allow-unknown*/, &maintenance_show_cmdlist
);
17412 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
17413 &dwarf2_max_cache_age
, _("\
17414 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
17415 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
17416 A higher limit means that cached compilation units will be stored\n\
17417 in memory longer, and more total memory will be used. Zero disables\n\
17418 caching, which can slow down startup."),
17420 show_dwarf2_max_cache_age
,
17421 &set_dwarf2_cmdlist
,
17422 &show_dwarf2_cmdlist
);
17424 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
17425 &dwarf2_always_disassemble
, _("\
17426 Set whether `info address' always disassembles DWARF expressions."), _("\
17427 Show whether `info address' always disassembles DWARF expressions."), _("\
17428 When enabled, DWARF expressions are always printed in an assembly-like\n\
17429 syntax. When disabled, expressions will be printed in a more\n\
17430 conversational style, when possible."),
17432 show_dwarf2_always_disassemble
,
17433 &set_dwarf2_cmdlist
,
17434 &show_dwarf2_cmdlist
);
17436 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
17437 Set debugging of the dwarf2 DIE reader."), _("\
17438 Show debugging of the dwarf2 DIE reader."), _("\
17439 When enabled (non-zero), DIEs are dumped after they are read in.\n\
17440 The value is the maximum depth to print."),
17443 &setdebuglist
, &showdebuglist
);
17445 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
17446 Set cross-checking of \"physname\" code against demangler."), _("\
17447 Show cross-checking of \"physname\" code against demangler."), _("\
17448 When enabled, GDB's internal \"physname\" code is checked against\n\
17450 NULL
, show_check_physname
,
17451 &setdebuglist
, &showdebuglist
);
17453 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
17455 Save a gdb-index file.\n\
17456 Usage: save gdb-index DIRECTORY"),
17458 set_cmd_completer (c
, filename_completer
);