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 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
2198 if (types_list_elements
)
2200 struct dwarf2_section_info
*section
;
2202 /* We can only handle a single .debug_types when we have an
2204 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2207 section
= VEC_index (dwarf2_section_info_def
,
2208 dwarf2_per_objfile
->types
, 0);
2210 if (!create_signatured_type_table_from_index (objfile
, section
,
2212 types_list_elements
))
2216 create_addrmap_from_index (objfile
, map
);
2218 dwarf2_per_objfile
->index_table
= map
;
2219 dwarf2_per_objfile
->using_index
= 1;
2220 dwarf2_per_objfile
->quick_file_names_table
=
2221 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2226 /* A helper for the "quick" functions which sets the global
2227 dwarf2_per_objfile according to OBJFILE. */
2230 dw2_setup (struct objfile
*objfile
)
2232 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2233 gdb_assert (dwarf2_per_objfile
);
2236 /* A helper for the "quick" functions which attempts to read the line
2237 table for THIS_CU. */
2239 static struct quick_file_names
*
2240 dw2_get_file_names (struct objfile
*objfile
,
2241 struct dwarf2_per_cu_data
*this_cu
)
2243 bfd
*abfd
= objfile
->obfd
;
2244 struct line_header
*lh
;
2245 struct attribute
*attr
;
2246 struct cleanup
*cleanups
;
2247 struct die_info
*comp_unit_die
;
2248 struct dwarf2_section_info
* sec
;
2250 int has_children
, i
;
2251 struct dwarf2_cu cu
;
2252 unsigned int bytes_read
;
2253 struct die_reader_specs reader_specs
;
2254 char *name
, *comp_dir
;
2256 struct quick_file_names
*qfn
;
2257 unsigned int line_offset
;
2259 if (this_cu
->v
.quick
->file_names
!= NULL
)
2260 return this_cu
->v
.quick
->file_names
;
2261 /* If we know there is no line data, no point in looking again. */
2262 if (this_cu
->v
.quick
->no_file_data
)
2265 init_one_comp_unit (&cu
, this_cu
);
2266 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
2268 if (this_cu
->debug_types_section
)
2269 sec
= this_cu
->debug_types_section
;
2271 sec
= &dwarf2_per_objfile
->info
;
2272 dwarf2_read_section (objfile
, sec
);
2273 info_ptr
= sec
->buffer
+ this_cu
->offset
.sect_off
;
2275 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, sec
, info_ptr
,
2276 this_cu
->debug_types_section
!= NULL
);
2278 /* Skip dummy compilation units. */
2279 if (info_ptr
>= (sec
->buffer
+ sec
->size
)
2280 || peek_abbrev_code (abfd
, info_ptr
) == 0)
2282 do_cleanups (cleanups
);
2286 dwarf2_read_abbrevs (&cu
);
2287 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2289 init_cu_die_reader (&reader_specs
, &cu
);
2290 read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2296 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, &cu
);
2299 struct quick_file_names find_entry
;
2301 line_offset
= DW_UNSND (attr
);
2303 /* We may have already read in this line header (TU line header sharing).
2304 If we have we're done. */
2305 find_entry
.offset
= line_offset
;
2306 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2307 &find_entry
, INSERT
);
2310 do_cleanups (cleanups
);
2311 this_cu
->v
.quick
->file_names
= *slot
;
2315 lh
= dwarf_decode_line_header (line_offset
, abfd
, &cu
);
2319 do_cleanups (cleanups
);
2320 this_cu
->v
.quick
->no_file_data
= 1;
2324 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2325 qfn
->offset
= line_offset
;
2326 gdb_assert (slot
!= NULL
);
2329 find_file_and_directory (comp_unit_die
, &cu
, &name
, &comp_dir
);
2331 qfn
->num_file_names
= lh
->num_file_names
;
2332 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2333 lh
->num_file_names
* sizeof (char *));
2334 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2335 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2336 qfn
->real_names
= NULL
;
2338 free_line_header (lh
);
2339 do_cleanups (cleanups
);
2341 this_cu
->v
.quick
->file_names
= qfn
;
2345 /* A helper for the "quick" functions which computes and caches the
2346 real path for a given file name from the line table. */
2349 dw2_get_real_path (struct objfile
*objfile
,
2350 struct quick_file_names
*qfn
, int index
)
2352 if (qfn
->real_names
== NULL
)
2353 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2354 qfn
->num_file_names
, sizeof (char *));
2356 if (qfn
->real_names
[index
] == NULL
)
2357 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2359 return qfn
->real_names
[index
];
2362 static struct symtab
*
2363 dw2_find_last_source_symtab (struct objfile
*objfile
)
2367 dw2_setup (objfile
);
2368 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2369 return dw2_instantiate_symtab (dw2_get_cu (index
));
2372 /* Traversal function for dw2_forget_cached_source_info. */
2375 dw2_free_cached_file_names (void **slot
, void *info
)
2377 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2379 if (file_data
->real_names
)
2383 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2385 xfree ((void*) file_data
->real_names
[i
]);
2386 file_data
->real_names
[i
] = NULL
;
2394 dw2_forget_cached_source_info (struct objfile
*objfile
)
2396 dw2_setup (objfile
);
2398 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2399 dw2_free_cached_file_names
, NULL
);
2402 /* Helper function for dw2_map_symtabs_matching_filename that expands
2403 the symtabs and calls the iterator. */
2406 dw2_map_expand_apply (struct objfile
*objfile
,
2407 struct dwarf2_per_cu_data
*per_cu
,
2409 const char *full_path
, const char *real_path
,
2410 int (*callback
) (struct symtab
*, void *),
2413 struct symtab
*last_made
= objfile
->symtabs
;
2415 /* Don't visit already-expanded CUs. */
2416 if (per_cu
->v
.quick
->symtab
)
2419 /* This may expand more than one symtab, and we want to iterate over
2421 dw2_instantiate_symtab (per_cu
);
2423 return iterate_over_some_symtabs (name
, full_path
, real_path
, callback
, data
,
2424 objfile
->symtabs
, last_made
);
2427 /* Implementation of the map_symtabs_matching_filename method. */
2430 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
2431 const char *full_path
, const char *real_path
,
2432 int (*callback
) (struct symtab
*, void *),
2436 const char *name_basename
= lbasename (name
);
2437 int name_len
= strlen (name
);
2438 int is_abs
= IS_ABSOLUTE_PATH (name
);
2440 dw2_setup (objfile
);
2442 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2443 + dwarf2_per_objfile
->n_type_units
); ++i
)
2446 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2447 struct quick_file_names
*file_data
;
2449 /* We only need to look at symtabs not already expanded. */
2450 if (per_cu
->v
.quick
->symtab
)
2453 file_data
= dw2_get_file_names (objfile
, per_cu
);
2454 if (file_data
== NULL
)
2457 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2459 const char *this_name
= file_data
->file_names
[j
];
2461 if (FILENAME_CMP (name
, this_name
) == 0
2462 || (!is_abs
&& compare_filenames_for_search (this_name
,
2465 if (dw2_map_expand_apply (objfile
, per_cu
,
2466 name
, full_path
, real_path
,
2471 /* Before we invoke realpath, which can get expensive when many
2472 files are involved, do a quick comparison of the basenames. */
2473 if (! basenames_may_differ
2474 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
2477 if (full_path
!= NULL
)
2479 const char *this_real_name
= dw2_get_real_path (objfile
,
2482 if (this_real_name
!= NULL
2483 && (FILENAME_CMP (full_path
, this_real_name
) == 0
2485 && compare_filenames_for_search (this_real_name
,
2488 if (dw2_map_expand_apply (objfile
, per_cu
,
2489 name
, full_path
, real_path
,
2495 if (real_path
!= NULL
)
2497 const char *this_real_name
= dw2_get_real_path (objfile
,
2500 if (this_real_name
!= NULL
2501 && (FILENAME_CMP (real_path
, this_real_name
) == 0
2503 && compare_filenames_for_search (this_real_name
,
2506 if (dw2_map_expand_apply (objfile
, per_cu
,
2507 name
, full_path
, real_path
,
2518 static struct symtab
*
2519 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2520 const char *name
, domain_enum domain
)
2522 /* We do all the work in the pre_expand_symtabs_matching hook
2527 /* A helper function that expands all symtabs that hold an object
2531 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2533 dw2_setup (objfile
);
2535 /* index_table is NULL if OBJF_READNOW. */
2536 if (dwarf2_per_objfile
->index_table
)
2540 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2543 offset_type i
, len
= MAYBE_SWAP (*vec
);
2544 for (i
= 0; i
< len
; ++i
)
2546 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2547 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2549 dw2_instantiate_symtab (per_cu
);
2556 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2557 enum block_enum block_kind
, const char *name
,
2560 dw2_do_expand_symtabs_matching (objfile
, name
);
2564 dw2_print_stats (struct objfile
*objfile
)
2568 dw2_setup (objfile
);
2570 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2571 + dwarf2_per_objfile
->n_type_units
); ++i
)
2573 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2575 if (!per_cu
->v
.quick
->symtab
)
2578 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2582 dw2_dump (struct objfile
*objfile
)
2584 /* Nothing worth printing. */
2588 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2589 struct section_offsets
*delta
)
2591 /* There's nothing to relocate here. */
2595 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2596 const char *func_name
)
2598 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2602 dw2_expand_all_symtabs (struct objfile
*objfile
)
2606 dw2_setup (objfile
);
2608 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2609 + dwarf2_per_objfile
->n_type_units
); ++i
)
2611 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2613 dw2_instantiate_symtab (per_cu
);
2618 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2619 const char *filename
)
2623 dw2_setup (objfile
);
2625 /* We don't need to consider type units here.
2626 This is only called for examining code, e.g. expand_line_sal.
2627 There can be an order of magnitude (or more) more type units
2628 than comp units, and we avoid them if we can. */
2630 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2633 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2634 struct quick_file_names
*file_data
;
2636 /* We only need to look at symtabs not already expanded. */
2637 if (per_cu
->v
.quick
->symtab
)
2640 file_data
= dw2_get_file_names (objfile
, per_cu
);
2641 if (file_data
== NULL
)
2644 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2646 const char *this_name
= file_data
->file_names
[j
];
2647 if (FILENAME_CMP (this_name
, filename
) == 0)
2649 dw2_instantiate_symtab (per_cu
);
2657 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2659 struct dwarf2_per_cu_data
*per_cu
;
2661 struct quick_file_names
*file_data
;
2663 dw2_setup (objfile
);
2665 /* index_table is NULL if OBJF_READNOW. */
2666 if (!dwarf2_per_objfile
->index_table
)
2670 ALL_OBJFILE_SYMTABS (objfile
, s
)
2673 struct blockvector
*bv
= BLOCKVECTOR (s
);
2674 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2675 struct symbol
*sym
= lookup_block_symbol (block
, name
, VAR_DOMAIN
);
2678 return sym
->symtab
->filename
;
2683 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2687 /* Note that this just looks at the very first one named NAME -- but
2688 actually we are looking for a function. find_main_filename
2689 should be rewritten so that it doesn't require a custom hook. It
2690 could just use the ordinary symbol tables. */
2691 /* vec[0] is the length, which must always be >0. */
2692 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[1]));
2694 file_data
= dw2_get_file_names (objfile
, per_cu
);
2695 if (file_data
== NULL
)
2698 return file_data
->file_names
[file_data
->num_file_names
- 1];
2702 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
2703 struct objfile
*objfile
, int global
,
2704 int (*callback
) (struct block
*,
2705 struct symbol
*, void *),
2706 void *data
, symbol_compare_ftype
*match
,
2707 symbol_compare_ftype
*ordered_compare
)
2709 /* Currently unimplemented; used for Ada. The function can be called if the
2710 current language is Ada for a non-Ada objfile using GNU index. As Ada
2711 does not look for non-Ada symbols this function should just return. */
2715 dw2_expand_symtabs_matching
2716 (struct objfile
*objfile
,
2717 int (*file_matcher
) (const char *, void *),
2718 int (*name_matcher
) (const char *, void *),
2719 enum search_domain kind
,
2724 struct mapped_index
*index
;
2726 dw2_setup (objfile
);
2728 /* index_table is NULL if OBJF_READNOW. */
2729 if (!dwarf2_per_objfile
->index_table
)
2731 index
= dwarf2_per_objfile
->index_table
;
2733 if (file_matcher
!= NULL
)
2735 struct cleanup
*cleanup
;
2736 htab_t visited_found
, visited_not_found
;
2738 visited_found
= htab_create_alloc (10,
2739 htab_hash_pointer
, htab_eq_pointer
,
2740 NULL
, xcalloc
, xfree
);
2741 cleanup
= make_cleanup_htab_delete (visited_found
);
2742 visited_not_found
= htab_create_alloc (10,
2743 htab_hash_pointer
, htab_eq_pointer
,
2744 NULL
, xcalloc
, xfree
);
2745 make_cleanup_htab_delete (visited_not_found
);
2747 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2748 + dwarf2_per_objfile
->n_type_units
); ++i
)
2751 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2752 struct quick_file_names
*file_data
;
2755 per_cu
->v
.quick
->mark
= 0;
2757 /* We only need to look at symtabs not already expanded. */
2758 if (per_cu
->v
.quick
->symtab
)
2761 file_data
= dw2_get_file_names (objfile
, per_cu
);
2762 if (file_data
== NULL
)
2765 if (htab_find (visited_not_found
, file_data
) != NULL
)
2767 else if (htab_find (visited_found
, file_data
) != NULL
)
2769 per_cu
->v
.quick
->mark
= 1;
2773 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2775 if (file_matcher (file_data
->file_names
[j
], data
))
2777 per_cu
->v
.quick
->mark
= 1;
2782 slot
= htab_find_slot (per_cu
->v
.quick
->mark
2784 : visited_not_found
,
2789 do_cleanups (cleanup
);
2792 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2794 offset_type idx
= 2 * iter
;
2796 offset_type
*vec
, vec_len
, vec_idx
;
2798 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2801 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
2803 if (! (*name_matcher
) (name
, data
))
2806 /* The name was matched, now expand corresponding CUs that were
2808 vec
= (offset_type
*) (index
->constant_pool
2809 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
2810 vec_len
= MAYBE_SWAP (vec
[0]);
2811 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2813 struct dwarf2_per_cu_data
*per_cu
;
2815 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[vec_idx
+ 1]));
2816 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
2817 dw2_instantiate_symtab (per_cu
);
2822 static struct symtab
*
2823 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
2824 struct minimal_symbol
*msymbol
,
2826 struct obj_section
*section
,
2829 struct dwarf2_per_cu_data
*data
;
2831 dw2_setup (objfile
);
2833 if (!objfile
->psymtabs_addrmap
)
2836 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
2840 if (warn_if_readin
&& data
->v
.quick
->symtab
)
2841 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2842 paddress (get_objfile_arch (objfile
), pc
));
2844 return dw2_instantiate_symtab (data
);
2848 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
2849 void *data
, int need_fullname
)
2852 struct cleanup
*cleanup
;
2853 htab_t visited
= htab_create_alloc (10, htab_hash_pointer
, htab_eq_pointer
,
2854 NULL
, xcalloc
, xfree
);
2856 cleanup
= make_cleanup_htab_delete (visited
);
2857 dw2_setup (objfile
);
2859 /* We can ignore file names coming from already-expanded CUs. */
2860 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2861 + dwarf2_per_objfile
->n_type_units
); ++i
)
2863 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2865 if (per_cu
->v
.quick
->symtab
)
2867 void **slot
= htab_find_slot (visited
, per_cu
->v
.quick
->file_names
,
2870 *slot
= per_cu
->v
.quick
->file_names
;
2874 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2875 + dwarf2_per_objfile
->n_type_units
); ++i
)
2878 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2879 struct quick_file_names
*file_data
;
2882 /* We only need to look at symtabs not already expanded. */
2883 if (per_cu
->v
.quick
->symtab
)
2886 file_data
= dw2_get_file_names (objfile
, per_cu
);
2887 if (file_data
== NULL
)
2890 slot
= htab_find_slot (visited
, file_data
, INSERT
);
2893 /* Already visited. */
2898 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2900 const char *this_real_name
;
2903 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
2905 this_real_name
= NULL
;
2906 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
2910 do_cleanups (cleanup
);
2914 dw2_has_symbols (struct objfile
*objfile
)
2919 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
2922 dw2_find_last_source_symtab
,
2923 dw2_forget_cached_source_info
,
2924 dw2_map_symtabs_matching_filename
,
2926 dw2_pre_expand_symtabs_matching
,
2930 dw2_expand_symtabs_for_function
,
2931 dw2_expand_all_symtabs
,
2932 dw2_expand_symtabs_with_filename
,
2933 dw2_find_symbol_file
,
2934 dw2_map_matching_symbols
,
2935 dw2_expand_symtabs_matching
,
2936 dw2_find_pc_sect_symtab
,
2937 dw2_map_symbol_filenames
2940 /* Initialize for reading DWARF for this objfile. Return 0 if this
2941 file will use psymtabs, or 1 if using the GNU index. */
2944 dwarf2_initialize_objfile (struct objfile
*objfile
)
2946 /* If we're about to read full symbols, don't bother with the
2947 indices. In this case we also don't care if some other debug
2948 format is making psymtabs, because they are all about to be
2950 if ((objfile
->flags
& OBJF_READNOW
))
2954 dwarf2_per_objfile
->using_index
= 1;
2955 create_all_comp_units (objfile
);
2956 create_all_type_units (objfile
);
2957 dwarf2_per_objfile
->quick_file_names_table
=
2958 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2960 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2961 + dwarf2_per_objfile
->n_type_units
); ++i
)
2963 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2965 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2966 struct dwarf2_per_cu_quick_data
);
2969 /* Return 1 so that gdb sees the "quick" functions. However,
2970 these functions will be no-ops because we will have expanded
2975 if (dwarf2_read_index (objfile
))
2983 /* Build a partial symbol table. */
2986 dwarf2_build_psymtabs (struct objfile
*objfile
)
2988 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2990 init_psymbol_list (objfile
, 1024);
2993 dwarf2_build_psymtabs_hard (objfile
);
2996 /* Return TRUE if OFFSET is within CU_HEADER. */
2999 offset_in_cu_p (const struct comp_unit_head
*cu_header
, sect_offset offset
)
3001 sect_offset bottom
= { cu_header
->offset
.sect_off
};
3002 sect_offset top
= { (cu_header
->offset
.sect_off
+ cu_header
->length
3003 + cu_header
->initial_length_size
) };
3005 return (offset
.sect_off
>= bottom
.sect_off
&& offset
.sect_off
< top
.sect_off
);
3008 /* Read in the comp unit header information from the debug_info at info_ptr.
3009 NOTE: This leaves members offset, first_die_offset to be filled in
3013 read_comp_unit_head (struct comp_unit_head
*cu_header
,
3014 gdb_byte
*info_ptr
, bfd
*abfd
)
3017 unsigned int bytes_read
;
3019 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
3020 cu_header
->initial_length_size
= bytes_read
;
3021 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
3022 info_ptr
+= bytes_read
;
3023 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
3025 cu_header
->abbrev_offset
.sect_off
= read_offset (abfd
, info_ptr
, cu_header
,
3027 info_ptr
+= bytes_read
;
3028 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
3030 signed_addr
= bfd_get_sign_extend_vma (abfd
);
3031 if (signed_addr
< 0)
3032 internal_error (__FILE__
, __LINE__
,
3033 _("read_comp_unit_head: dwarf from non elf file"));
3034 cu_header
->signed_addr_p
= signed_addr
;
3039 /* Subroutine of read_and_check_comp_unit_head and
3040 read_and_check_type_unit_head to simplify them.
3041 Perform various error checking on the header. */
3044 error_check_comp_unit_head (struct comp_unit_head
*header
,
3045 struct dwarf2_section_info
*section
)
3047 bfd
*abfd
= section
->asection
->owner
;
3048 const char *filename
= bfd_get_filename (abfd
);
3050 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
3051 error (_("Dwarf Error: wrong version in compilation unit header "
3052 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
3055 if (header
->abbrev_offset
.sect_off
3056 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
3057 &dwarf2_per_objfile
->abbrev
))
3058 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3059 "(offset 0x%lx + 6) [in module %s]"),
3060 (long) header
->abbrev_offset
.sect_off
, (long) header
->offset
.sect_off
,
3063 /* Cast to unsigned long to use 64-bit arithmetic when possible to
3064 avoid potential 32-bit overflow. */
3065 if (((unsigned long) header
->offset
.sect_off
3066 + header
->length
+ header
->initial_length_size
)
3068 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3069 "(offset 0x%lx + 0) [in module %s]"),
3070 (long) header
->length
, (long) header
->offset
.sect_off
,
3074 /* Read in a CU/TU header and perform some basic error checking.
3075 The contents of the header are stored in HEADER.
3076 The result is a pointer to the start of the first DIE. */
3079 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
3080 struct dwarf2_section_info
*section
,
3082 int is_debug_types_section
)
3084 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3085 bfd
*abfd
= section
->asection
->owner
;
3087 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3089 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3091 /* If we're reading a type unit, skip over the signature and
3092 type_offset fields. */
3093 if (is_debug_types_section
)
3094 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
3096 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3098 error_check_comp_unit_head (header
, section
);
3103 /* Read in the types comp unit header information from .debug_types entry at
3104 types_ptr. The result is a pointer to one past the end of the header. */
3107 read_and_check_type_unit_head (struct comp_unit_head
*header
,
3108 struct dwarf2_section_info
*section
,
3110 ULONGEST
*signature
, cu_offset
*type_offset
)
3112 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3113 bfd
*abfd
= section
->asection
->owner
;
3115 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3117 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3119 /* If we're reading a type unit, skip over the signature and
3120 type_offset fields. */
3121 if (signature
!= NULL
)
3122 *signature
= read_8_bytes (abfd
, info_ptr
);
3124 if (type_offset
!= NULL
)
3125 type_offset
->cu_off
= read_offset_1 (abfd
, info_ptr
, header
->offset_size
);
3126 info_ptr
+= header
->offset_size
;
3128 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3130 error_check_comp_unit_head (header
, section
);
3135 /* Allocate a new partial symtab for file named NAME and mark this new
3136 partial symtab as being an include of PST. */
3139 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
3140 struct objfile
*objfile
)
3142 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
3144 subpst
->section_offsets
= pst
->section_offsets
;
3145 subpst
->textlow
= 0;
3146 subpst
->texthigh
= 0;
3148 subpst
->dependencies
= (struct partial_symtab
**)
3149 obstack_alloc (&objfile
->objfile_obstack
,
3150 sizeof (struct partial_symtab
*));
3151 subpst
->dependencies
[0] = pst
;
3152 subpst
->number_of_dependencies
= 1;
3154 subpst
->globals_offset
= 0;
3155 subpst
->n_global_syms
= 0;
3156 subpst
->statics_offset
= 0;
3157 subpst
->n_static_syms
= 0;
3158 subpst
->symtab
= NULL
;
3159 subpst
->read_symtab
= pst
->read_symtab
;
3162 /* No private part is necessary for include psymtabs. This property
3163 can be used to differentiate between such include psymtabs and
3164 the regular ones. */
3165 subpst
->read_symtab_private
= NULL
;
3168 /* Read the Line Number Program data and extract the list of files
3169 included by the source file represented by PST. Build an include
3170 partial symtab for each of these included files. */
3173 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
3174 struct die_info
*die
,
3175 struct partial_symtab
*pst
)
3177 struct objfile
*objfile
= cu
->objfile
;
3178 bfd
*abfd
= objfile
->obfd
;
3179 struct line_header
*lh
= NULL
;
3180 struct attribute
*attr
;
3182 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3185 unsigned int line_offset
= DW_UNSND (attr
);
3187 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
3190 return; /* No linetable, so no includes. */
3192 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3193 dwarf_decode_lines (lh
, pst
->dirname
, cu
, pst
, 1);
3195 free_line_header (lh
);
3199 hash_signatured_type (const void *item
)
3201 const struct signatured_type
*sig_type
= item
;
3203 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3204 return sig_type
->signature
;
3208 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
3210 const struct signatured_type
*lhs
= item_lhs
;
3211 const struct signatured_type
*rhs
= item_rhs
;
3213 return lhs
->signature
== rhs
->signature
;
3216 /* Allocate a hash table for signatured types. */
3219 allocate_signatured_type_table (struct objfile
*objfile
)
3221 return htab_create_alloc_ex (41,
3222 hash_signatured_type
,
3225 &objfile
->objfile_obstack
,
3226 hashtab_obstack_allocate
,
3227 dummy_obstack_deallocate
);
3230 /* A helper function to add a signatured type CU to a table. */
3233 add_signatured_type_cu_to_table (void **slot
, void *datum
)
3235 struct signatured_type
*sigt
= *slot
;
3236 struct dwarf2_per_cu_data
***datap
= datum
;
3238 **datap
= &sigt
->per_cu
;
3244 /* Create the hash table of all entries in the .debug_types section(s).
3245 The result is zero if there are no .debug_types sections,
3246 otherwise non-zero. */
3249 create_all_type_units (struct objfile
*objfile
)
3251 htab_t types_htab
= NULL
;
3252 struct dwarf2_per_cu_data
**iter
;
3254 struct dwarf2_section_info
*section
;
3256 if (VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
))
3258 dwarf2_per_objfile
->signatured_types
= NULL
;
3263 VEC_iterate (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
3267 gdb_byte
*info_ptr
, *end_ptr
;
3269 dwarf2_read_section (objfile
, section
);
3270 info_ptr
= section
->buffer
;
3272 if (info_ptr
== NULL
)
3275 if (types_htab
== NULL
)
3276 types_htab
= allocate_signatured_type_table (objfile
);
3278 if (dwarf2_die_debug
)
3279 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
3281 end_ptr
= info_ptr
+ section
->size
;
3282 while (info_ptr
< end_ptr
)
3285 cu_offset type_offset
;
3287 struct signatured_type
*sig_type
;
3289 gdb_byte
*ptr
= info_ptr
;
3290 struct comp_unit_head header
;
3292 offset
.sect_off
= ptr
- section
->buffer
;
3294 /* We need to read the type's signature in order to build the hash
3295 table, but we don't need anything else just yet. */
3297 ptr
= read_and_check_type_unit_head (&header
, section
, ptr
,
3298 &signature
, &type_offset
);
3300 /* Skip dummy type units. */
3301 if (ptr
>= end_ptr
|| peek_abbrev_code (objfile
->obfd
, ptr
) == 0)
3303 info_ptr
= info_ptr
+ header
.initial_length_size
+ header
.length
;
3307 sig_type
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*sig_type
));
3308 memset (sig_type
, 0, sizeof (*sig_type
));
3309 sig_type
->signature
= signature
;
3310 sig_type
->type_offset
= type_offset
;
3311 sig_type
->per_cu
.objfile
= objfile
;
3312 sig_type
->per_cu
.debug_types_section
= section
;
3313 sig_type
->per_cu
.offset
= offset
;
3315 slot
= htab_find_slot (types_htab
, sig_type
, INSERT
);
3316 gdb_assert (slot
!= NULL
);
3319 const struct signatured_type
*dup_sig
= *slot
;
3321 complaint (&symfile_complaints
,
3322 _("debug type entry at offset 0x%x is duplicate to the "
3323 "entry at offset 0x%x, signature 0x%s"),
3324 offset
.sect_off
, dup_sig
->per_cu
.offset
.sect_off
,
3325 phex (signature
, sizeof (signature
)));
3326 gdb_assert (signature
== dup_sig
->signature
);
3330 if (dwarf2_die_debug
)
3331 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3333 phex (signature
, sizeof (signature
)));
3335 info_ptr
= info_ptr
+ header
.initial_length_size
+ header
.length
;
3339 dwarf2_per_objfile
->signatured_types
= types_htab
;
3341 dwarf2_per_objfile
->n_type_units
= htab_elements (types_htab
);
3342 dwarf2_per_objfile
->all_type_units
3343 = obstack_alloc (&objfile
->objfile_obstack
,
3344 dwarf2_per_objfile
->n_type_units
3345 * sizeof (struct dwarf2_per_cu_data
*));
3346 iter
= &dwarf2_per_objfile
->all_type_units
[0];
3347 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
3348 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
3349 == dwarf2_per_objfile
->n_type_units
);
3354 /* Lookup a signature based type for DW_FORM_ref_sig8.
3355 Returns NULL if signature SIG is not present in the table. */
3357 static struct signatured_type
*
3358 lookup_signatured_type (ULONGEST sig
)
3360 struct signatured_type find_entry
, *entry
;
3362 if (dwarf2_per_objfile
->signatured_types
== NULL
)
3364 complaint (&symfile_complaints
,
3365 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3369 find_entry
.signature
= sig
;
3370 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
3374 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3377 init_cu_die_reader (struct die_reader_specs
*reader
,
3378 struct dwarf2_cu
*cu
)
3380 reader
->abfd
= cu
->objfile
->obfd
;
3382 if (cu
->per_cu
->debug_types_section
)
3384 gdb_assert (cu
->per_cu
->debug_types_section
->readin
);
3385 reader
->buffer
= cu
->per_cu
->debug_types_section
->buffer
;
3389 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3390 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
3394 /* Find the base address of the compilation unit for range lists and
3395 location lists. It will normally be specified by DW_AT_low_pc.
3396 In DWARF-3 draft 4, the base address could be overridden by
3397 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3398 compilation units with discontinuous ranges. */
3401 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3403 struct attribute
*attr
;
3406 cu
->base_address
= 0;
3408 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3411 cu
->base_address
= DW_ADDR (attr
);
3416 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3419 cu
->base_address
= DW_ADDR (attr
);
3425 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
3426 to combine the common parts.
3427 Process compilation unit THIS_CU for a psymtab.
3428 SECTION is the section the CU/TU comes from,
3429 either .debug_info or .debug_types. */
3432 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
3433 struct dwarf2_section_info
*section
,
3434 int is_debug_types_section
)
3436 struct objfile
*objfile
= this_cu
->objfile
;
3437 bfd
*abfd
= objfile
->obfd
;
3438 gdb_byte
*buffer
= section
->buffer
;
3439 gdb_byte
*info_ptr
= buffer
+ this_cu
->offset
.sect_off
;
3440 unsigned int buffer_size
= section
->size
;
3441 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3442 struct die_info
*comp_unit_die
;
3443 struct partial_symtab
*pst
;
3445 struct cleanup
*back_to_inner
;
3446 struct dwarf2_cu cu
;
3447 int has_children
, has_pc_info
;
3448 struct attribute
*attr
;
3449 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
3450 struct die_reader_specs reader_specs
;
3451 const char *filename
;
3453 /* If this compilation unit was already read in, free the
3454 cached copy in order to read it in again. This is
3455 necessary because we skipped some symbols when we first
3456 read in the compilation unit (see load_partial_dies).
3457 This problem could be avoided, but the benefit is
3459 if (this_cu
->cu
!= NULL
)
3460 free_one_cached_comp_unit (this_cu
->cu
);
3462 /* Note that this is a pointer to our stack frame, being
3463 added to a global data structure. It will be cleaned up
3464 in free_stack_comp_unit when we finish with this
3465 compilation unit. */
3466 init_one_comp_unit (&cu
, this_cu
);
3467 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
3469 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
, info_ptr
,
3470 is_debug_types_section
);
3472 /* Skip dummy compilation units. */
3473 if (info_ptr
>= buffer
+ buffer_size
3474 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3476 do_cleanups (back_to_inner
);
3480 cu
.list_in_scope
= &file_symbols
;
3482 /* Read the abbrevs for this compilation unit into a table. */
3483 dwarf2_read_abbrevs (&cu
);
3484 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
3486 /* Read the compilation unit die. */
3487 init_cu_die_reader (&reader_specs
, &cu
);
3488 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3491 if (is_debug_types_section
)
3493 /* LENGTH has not been set yet for type units. */
3494 gdb_assert (this_cu
->offset
.sect_off
== cu
.header
.offset
.sect_off
);
3495 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
3497 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3499 do_cleanups (back_to_inner
);
3503 prepare_one_comp_unit (&cu
, comp_unit_die
);
3505 /* Allocate a new partial symbol table structure. */
3506 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
3507 if (attr
== NULL
|| !DW_STRING (attr
))
3510 filename
= DW_STRING (attr
);
3511 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
3513 /* TEXTLOW and TEXTHIGH are set below. */
3515 objfile
->global_psymbols
.next
,
3516 objfile
->static_psymbols
.next
);
3517 pst
->psymtabs_addrmap_supported
= 1;
3519 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
3521 pst
->dirname
= DW_STRING (attr
);
3523 pst
->read_symtab_private
= this_cu
;
3525 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3527 /* Store the function that reads in the rest of the symbol table. */
3528 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
3530 this_cu
->v
.psymtab
= pst
;
3532 dwarf2_find_base_address (comp_unit_die
, &cu
);
3534 /* Possibly set the default values of LOWPC and HIGHPC from
3536 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
3537 &best_highpc
, &cu
, pst
);
3538 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
3539 /* Store the contiguous range if it is not empty; it can be empty for
3540 CUs with no code. */
3541 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3542 best_lowpc
+ baseaddr
,
3543 best_highpc
+ baseaddr
- 1, pst
);
3545 /* Check if comp unit has_children.
3546 If so, read the rest of the partial symbols from this comp unit.
3547 If not, there's no more debug_info for this comp unit. */
3550 struct partial_die_info
*first_die
;
3551 CORE_ADDR lowpc
, highpc
;
3553 lowpc
= ((CORE_ADDR
) -1);
3554 highpc
= ((CORE_ADDR
) 0);
3556 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
3558 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
3559 ! has_pc_info
, &cu
);
3561 /* If we didn't find a lowpc, set it to highpc to avoid
3562 complaints from `maint check'. */
3563 if (lowpc
== ((CORE_ADDR
) -1))
3566 /* If the compilation unit didn't have an explicit address range,
3567 then use the information extracted from its child dies. */
3571 best_highpc
= highpc
;
3574 pst
->textlow
= best_lowpc
+ baseaddr
;
3575 pst
->texthigh
= best_highpc
+ baseaddr
;
3577 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
3578 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
3579 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
3580 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
3581 sort_pst_symbols (pst
);
3583 if (is_debug_types_section
)
3585 /* It's not clear we want to do anything with stmt lists here.
3586 Waiting to see what gcc ultimately does. */
3590 /* Get the list of files included in the current compilation unit,
3591 and build a psymtab for each of them. */
3592 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
3595 do_cleanups (back_to_inner
);
3598 /* Traversal function for htab_traverse_noresize.
3599 Process one .debug_types comp-unit. */
3602 process_type_comp_unit (void **slot
, void *info
)
3604 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
3605 struct dwarf2_per_cu_data
*this_cu
;
3607 gdb_assert (info
== NULL
);
3608 this_cu
= &entry
->per_cu
;
3610 gdb_assert (this_cu
->debug_types_section
->readin
);
3611 process_psymtab_comp_unit (this_cu
, this_cu
->debug_types_section
, 1);
3616 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3617 Build partial symbol tables for the .debug_types comp-units. */
3620 build_type_psymtabs (struct objfile
*objfile
)
3622 if (! create_all_type_units (objfile
))
3625 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
3626 process_type_comp_unit
, NULL
);
3629 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3632 psymtabs_addrmap_cleanup (void *o
)
3634 struct objfile
*objfile
= o
;
3636 objfile
->psymtabs_addrmap
= NULL
;
3639 /* Build the partial symbol table by doing a quick pass through the
3640 .debug_info and .debug_abbrev sections. */
3643 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
3645 struct cleanup
*back_to
, *addrmap_cleanup
;
3646 struct obstack temp_obstack
;
3649 dwarf2_per_objfile
->reading_partial_symbols
= 1;
3651 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3653 /* Any cached compilation units will be linked by the per-objfile
3654 read_in_chain. Make sure to free them when we're done. */
3655 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
3657 build_type_psymtabs (objfile
);
3659 create_all_comp_units (objfile
);
3661 /* Create a temporary address map on a temporary obstack. We later
3662 copy this to the final obstack. */
3663 obstack_init (&temp_obstack
);
3664 make_cleanup_obstack_free (&temp_obstack
);
3665 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
3666 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
3668 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3670 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3672 process_psymtab_comp_unit (per_cu
, &dwarf2_per_objfile
->info
, 0);
3675 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
3676 &objfile
->objfile_obstack
);
3677 discard_cleanups (addrmap_cleanup
);
3679 do_cleanups (back_to
);
3682 /* Load the partial DIEs for a secondary CU into memory. */
3685 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
3687 struct objfile
*objfile
= this_cu
->objfile
;
3688 bfd
*abfd
= objfile
->obfd
;
3690 struct die_info
*comp_unit_die
;
3691 struct dwarf2_cu
*cu
;
3692 struct cleanup
*free_abbrevs_cleanup
, *free_cu_cleanup
= NULL
;
3694 struct die_reader_specs reader_specs
;
3696 struct dwarf2_section_info
*section
= &dwarf2_per_objfile
->info
;
3698 gdb_assert (! this_cu
->debug_types_section
);
3700 gdb_assert (section
->readin
);
3701 info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
3703 if (this_cu
->cu
== NULL
)
3705 cu
= xmalloc (sizeof (*cu
));
3706 init_one_comp_unit (cu
, this_cu
);
3710 /* If an error occurs while loading, release our storage. */
3711 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
3713 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
, info_ptr
,
3716 /* Skip dummy compilation units. */
3717 if (info_ptr
>= (section
->buffer
+ section
->size
)
3718 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3720 do_cleanups (free_cu_cleanup
);
3727 info_ptr
+= cu
->header
.first_die_offset
.cu_off
;
3730 /* Read the abbrevs for this compilation unit into a table. */
3731 gdb_assert (cu
->dwarf2_abbrevs
== NULL
);
3732 dwarf2_read_abbrevs (cu
);
3733 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3735 /* Read the compilation unit die. */
3736 init_cu_die_reader (&reader_specs
, cu
);
3737 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3740 prepare_one_comp_unit (cu
, comp_unit_die
);
3742 /* Check if comp unit has_children.
3743 If so, read the rest of the partial symbols from this comp unit.
3744 If not, there's no more debug_info for this comp unit. */
3746 load_partial_dies (abfd
, section
->buffer
, info_ptr
, 0, cu
);
3748 do_cleanups (free_abbrevs_cleanup
);
3752 /* We've successfully allocated this compilation unit. Let our
3753 caller clean it up when finished with it. */
3754 discard_cleanups (free_cu_cleanup
);
3756 /* Link this CU into read_in_chain. */
3757 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3758 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3762 /* Create a list of all compilation units in OBJFILE.
3763 This is only done for -readnow and building partial symtabs. */
3766 create_all_comp_units (struct objfile
*objfile
)
3770 struct dwarf2_per_cu_data
**all_comp_units
;
3773 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3774 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3778 all_comp_units
= xmalloc (n_allocated
3779 * sizeof (struct dwarf2_per_cu_data
*));
3781 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
3782 + dwarf2_per_objfile
->info
.size
)
3784 unsigned int length
, initial_length_size
;
3785 struct dwarf2_per_cu_data
*this_cu
;
3788 offset
.sect_off
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
3790 /* Read just enough information to find out where the next
3791 compilation unit is. */
3792 length
= read_initial_length (objfile
->obfd
, info_ptr
,
3793 &initial_length_size
);
3795 /* Save the compilation unit for later lookup. */
3796 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
3797 sizeof (struct dwarf2_per_cu_data
));
3798 memset (this_cu
, 0, sizeof (*this_cu
));
3799 this_cu
->offset
= offset
;
3800 this_cu
->length
= length
+ initial_length_size
;
3801 this_cu
->objfile
= objfile
;
3803 if (n_comp_units
== n_allocated
)
3806 all_comp_units
= xrealloc (all_comp_units
,
3808 * sizeof (struct dwarf2_per_cu_data
*));
3810 all_comp_units
[n_comp_units
++] = this_cu
;
3812 info_ptr
= info_ptr
+ this_cu
->length
;
3815 dwarf2_per_objfile
->all_comp_units
3816 = obstack_alloc (&objfile
->objfile_obstack
,
3817 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3818 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
3819 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3820 xfree (all_comp_units
);
3821 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
3824 /* Process all loaded DIEs for compilation unit CU, starting at
3825 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3826 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3827 DW_AT_ranges). If NEED_PC is set, then this function will set
3828 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3829 and record the covered ranges in the addrmap. */
3832 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
3833 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3835 struct partial_die_info
*pdi
;
3837 /* Now, march along the PDI's, descending into ones which have
3838 interesting children but skipping the children of the other ones,
3839 until we reach the end of the compilation unit. */
3845 fixup_partial_die (pdi
, cu
);
3847 /* Anonymous namespaces or modules have no name but have interesting
3848 children, so we need to look at them. Ditto for anonymous
3851 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
3852 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
3856 case DW_TAG_subprogram
:
3857 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3859 case DW_TAG_constant
:
3860 case DW_TAG_variable
:
3861 case DW_TAG_typedef
:
3862 case DW_TAG_union_type
:
3863 if (!pdi
->is_declaration
)
3865 add_partial_symbol (pdi
, cu
);
3868 case DW_TAG_class_type
:
3869 case DW_TAG_interface_type
:
3870 case DW_TAG_structure_type
:
3871 if (!pdi
->is_declaration
)
3873 add_partial_symbol (pdi
, cu
);
3876 case DW_TAG_enumeration_type
:
3877 if (!pdi
->is_declaration
)
3878 add_partial_enumeration (pdi
, cu
);
3880 case DW_TAG_base_type
:
3881 case DW_TAG_subrange_type
:
3882 /* File scope base type definitions are added to the partial
3884 add_partial_symbol (pdi
, cu
);
3886 case DW_TAG_namespace
:
3887 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
3890 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
3897 /* If the die has a sibling, skip to the sibling. */
3899 pdi
= pdi
->die_sibling
;
3903 /* Functions used to compute the fully scoped name of a partial DIE.
3905 Normally, this is simple. For C++, the parent DIE's fully scoped
3906 name is concatenated with "::" and the partial DIE's name. For
3907 Java, the same thing occurs except that "." is used instead of "::".
3908 Enumerators are an exception; they use the scope of their parent
3909 enumeration type, i.e. the name of the enumeration type is not
3910 prepended to the enumerator.
3912 There are two complexities. One is DW_AT_specification; in this
3913 case "parent" means the parent of the target of the specification,
3914 instead of the direct parent of the DIE. The other is compilers
3915 which do not emit DW_TAG_namespace; in this case we try to guess
3916 the fully qualified name of structure types from their members'
3917 linkage names. This must be done using the DIE's children rather
3918 than the children of any DW_AT_specification target. We only need
3919 to do this for structures at the top level, i.e. if the target of
3920 any DW_AT_specification (if any; otherwise the DIE itself) does not
3923 /* Compute the scope prefix associated with PDI's parent, in
3924 compilation unit CU. The result will be allocated on CU's
3925 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3926 field. NULL is returned if no prefix is necessary. */
3928 partial_die_parent_scope (struct partial_die_info
*pdi
,
3929 struct dwarf2_cu
*cu
)
3931 char *grandparent_scope
;
3932 struct partial_die_info
*parent
, *real_pdi
;
3934 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3935 then this means the parent of the specification DIE. */
3938 while (real_pdi
->has_specification
)
3939 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3941 parent
= real_pdi
->die_parent
;
3945 if (parent
->scope_set
)
3946 return parent
->scope
;
3948 fixup_partial_die (parent
, cu
);
3950 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
3952 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3953 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3954 Work around this problem here. */
3955 if (cu
->language
== language_cplus
3956 && parent
->tag
== DW_TAG_namespace
3957 && strcmp (parent
->name
, "::") == 0
3958 && grandparent_scope
== NULL
)
3960 parent
->scope
= NULL
;
3961 parent
->scope_set
= 1;
3965 if (pdi
->tag
== DW_TAG_enumerator
)
3966 /* Enumerators should not get the name of the enumeration as a prefix. */
3967 parent
->scope
= grandparent_scope
;
3968 else if (parent
->tag
== DW_TAG_namespace
3969 || parent
->tag
== DW_TAG_module
3970 || parent
->tag
== DW_TAG_structure_type
3971 || parent
->tag
== DW_TAG_class_type
3972 || parent
->tag
== DW_TAG_interface_type
3973 || parent
->tag
== DW_TAG_union_type
3974 || parent
->tag
== DW_TAG_enumeration_type
)
3976 if (grandparent_scope
== NULL
)
3977 parent
->scope
= parent
->name
;
3979 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
3981 parent
->name
, 0, cu
);
3985 /* FIXME drow/2004-04-01: What should we be doing with
3986 function-local names? For partial symbols, we should probably be
3988 complaint (&symfile_complaints
,
3989 _("unhandled containing DIE tag %d for DIE at %d"),
3990 parent
->tag
, pdi
->offset
.sect_off
);
3991 parent
->scope
= grandparent_scope
;
3994 parent
->scope_set
= 1;
3995 return parent
->scope
;
3998 /* Return the fully scoped name associated with PDI, from compilation unit
3999 CU. The result will be allocated with malloc. */
4002 partial_die_full_name (struct partial_die_info
*pdi
,
4003 struct dwarf2_cu
*cu
)
4007 /* If this is a template instantiation, we can not work out the
4008 template arguments from partial DIEs. So, unfortunately, we have
4009 to go through the full DIEs. At least any work we do building
4010 types here will be reused if full symbols are loaded later. */
4011 if (pdi
->has_template_arguments
)
4013 fixup_partial_die (pdi
, cu
);
4015 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
4017 struct die_info
*die
;
4018 struct attribute attr
;
4019 struct dwarf2_cu
*ref_cu
= cu
;
4021 /* DW_FORM_ref_addr is using section offset. */
4023 attr
.form
= DW_FORM_ref_addr
;
4024 attr
.u
.unsnd
= pdi
->offset
.sect_off
;
4025 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
4027 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
4031 parent_scope
= partial_die_parent_scope (pdi
, cu
);
4032 if (parent_scope
== NULL
)
4035 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
4039 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
4041 struct objfile
*objfile
= cu
->objfile
;
4043 char *actual_name
= NULL
;
4045 int built_actual_name
= 0;
4047 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4049 actual_name
= partial_die_full_name (pdi
, cu
);
4051 built_actual_name
= 1;
4053 if (actual_name
== NULL
)
4054 actual_name
= pdi
->name
;
4058 case DW_TAG_subprogram
:
4059 if (pdi
->is_external
|| cu
->language
== language_ada
)
4061 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
4062 of the global scope. But in Ada, we want to be able to access
4063 nested procedures globally. So all Ada subprograms are stored
4064 in the global scope. */
4065 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4066 mst_text, objfile); */
4067 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4069 VAR_DOMAIN
, LOC_BLOCK
,
4070 &objfile
->global_psymbols
,
4071 0, pdi
->lowpc
+ baseaddr
,
4072 cu
->language
, objfile
);
4076 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4077 mst_file_text, objfile); */
4078 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4080 VAR_DOMAIN
, LOC_BLOCK
,
4081 &objfile
->static_psymbols
,
4082 0, pdi
->lowpc
+ baseaddr
,
4083 cu
->language
, objfile
);
4086 case DW_TAG_constant
:
4088 struct psymbol_allocation_list
*list
;
4090 if (pdi
->is_external
)
4091 list
= &objfile
->global_psymbols
;
4093 list
= &objfile
->static_psymbols
;
4094 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4095 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
4096 list
, 0, 0, cu
->language
, objfile
);
4099 case DW_TAG_variable
:
4101 addr
= decode_locdesc (pdi
->locdesc
, cu
);
4105 && !dwarf2_per_objfile
->has_section_at_zero
)
4107 /* A global or static variable may also have been stripped
4108 out by the linker if unused, in which case its address
4109 will be nullified; do not add such variables into partial
4110 symbol table then. */
4112 else if (pdi
->is_external
)
4115 Don't enter into the minimal symbol tables as there is
4116 a minimal symbol table entry from the ELF symbols already.
4117 Enter into partial symbol table if it has a location
4118 descriptor or a type.
4119 If the location descriptor is missing, new_symbol will create
4120 a LOC_UNRESOLVED symbol, the address of the variable will then
4121 be determined from the minimal symbol table whenever the variable
4123 The address for the partial symbol table entry is not
4124 used by GDB, but it comes in handy for debugging partial symbol
4127 if (pdi
->locdesc
|| pdi
->has_type
)
4128 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4130 VAR_DOMAIN
, LOC_STATIC
,
4131 &objfile
->global_psymbols
,
4133 cu
->language
, objfile
);
4137 /* Static Variable. Skip symbols without location descriptors. */
4138 if (pdi
->locdesc
== NULL
)
4140 if (built_actual_name
)
4141 xfree (actual_name
);
4144 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
4145 mst_file_data, objfile); */
4146 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4148 VAR_DOMAIN
, LOC_STATIC
,
4149 &objfile
->static_psymbols
,
4151 cu
->language
, objfile
);
4154 case DW_TAG_typedef
:
4155 case DW_TAG_base_type
:
4156 case DW_TAG_subrange_type
:
4157 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4159 VAR_DOMAIN
, LOC_TYPEDEF
,
4160 &objfile
->static_psymbols
,
4161 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4163 case DW_TAG_namespace
:
4164 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4166 VAR_DOMAIN
, LOC_TYPEDEF
,
4167 &objfile
->global_psymbols
,
4168 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4170 case DW_TAG_class_type
:
4171 case DW_TAG_interface_type
:
4172 case DW_TAG_structure_type
:
4173 case DW_TAG_union_type
:
4174 case DW_TAG_enumeration_type
:
4175 /* Skip external references. The DWARF standard says in the section
4176 about "Structure, Union, and Class Type Entries": "An incomplete
4177 structure, union or class type is represented by a structure,
4178 union or class entry that does not have a byte size attribute
4179 and that has a DW_AT_declaration attribute." */
4180 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
4182 if (built_actual_name
)
4183 xfree (actual_name
);
4187 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
4188 static vs. global. */
4189 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4191 STRUCT_DOMAIN
, LOC_TYPEDEF
,
4192 (cu
->language
== language_cplus
4193 || cu
->language
== language_java
)
4194 ? &objfile
->global_psymbols
4195 : &objfile
->static_psymbols
,
4196 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4199 case DW_TAG_enumerator
:
4200 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4202 VAR_DOMAIN
, LOC_CONST
,
4203 (cu
->language
== language_cplus
4204 || cu
->language
== language_java
)
4205 ? &objfile
->global_psymbols
4206 : &objfile
->static_psymbols
,
4207 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4213 if (built_actual_name
)
4214 xfree (actual_name
);
4217 /* Read a partial die corresponding to a namespace; also, add a symbol
4218 corresponding to that namespace to the symbol table. NAMESPACE is
4219 the name of the enclosing namespace. */
4222 add_partial_namespace (struct partial_die_info
*pdi
,
4223 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4224 int need_pc
, struct dwarf2_cu
*cu
)
4226 /* Add a symbol for the namespace. */
4228 add_partial_symbol (pdi
, cu
);
4230 /* Now scan partial symbols in that namespace. */
4232 if (pdi
->has_children
)
4233 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4236 /* Read a partial die corresponding to a Fortran module. */
4239 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
4240 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4242 /* Now scan partial symbols in that module. */
4244 if (pdi
->has_children
)
4245 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4248 /* Read a partial die corresponding to a subprogram and create a partial
4249 symbol for that subprogram. When the CU language allows it, this
4250 routine also defines a partial symbol for each nested subprogram
4251 that this subprogram contains.
4253 DIE my also be a lexical block, in which case we simply search
4254 recursively for suprograms defined inside that lexical block.
4255 Again, this is only performed when the CU language allows this
4256 type of definitions. */
4259 add_partial_subprogram (struct partial_die_info
*pdi
,
4260 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4261 int need_pc
, struct dwarf2_cu
*cu
)
4263 if (pdi
->tag
== DW_TAG_subprogram
)
4265 if (pdi
->has_pc_info
)
4267 if (pdi
->lowpc
< *lowpc
)
4268 *lowpc
= pdi
->lowpc
;
4269 if (pdi
->highpc
> *highpc
)
4270 *highpc
= pdi
->highpc
;
4274 struct objfile
*objfile
= cu
->objfile
;
4276 baseaddr
= ANOFFSET (objfile
->section_offsets
,
4277 SECT_OFF_TEXT (objfile
));
4278 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4279 pdi
->lowpc
+ baseaddr
,
4280 pdi
->highpc
- 1 + baseaddr
,
4281 cu
->per_cu
->v
.psymtab
);
4285 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
4287 if (!pdi
->is_declaration
)
4288 /* Ignore subprogram DIEs that do not have a name, they are
4289 illegal. Do not emit a complaint at this point, we will
4290 do so when we convert this psymtab into a symtab. */
4292 add_partial_symbol (pdi
, cu
);
4296 if (! pdi
->has_children
)
4299 if (cu
->language
== language_ada
)
4301 pdi
= pdi
->die_child
;
4304 fixup_partial_die (pdi
, cu
);
4305 if (pdi
->tag
== DW_TAG_subprogram
4306 || pdi
->tag
== DW_TAG_lexical_block
)
4307 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4308 pdi
= pdi
->die_sibling
;
4313 /* Read a partial die corresponding to an enumeration type. */
4316 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
4317 struct dwarf2_cu
*cu
)
4319 struct partial_die_info
*pdi
;
4321 if (enum_pdi
->name
!= NULL
)
4322 add_partial_symbol (enum_pdi
, cu
);
4324 pdi
= enum_pdi
->die_child
;
4327 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
4328 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
4330 add_partial_symbol (pdi
, cu
);
4331 pdi
= pdi
->die_sibling
;
4335 /* Return the initial uleb128 in the die at INFO_PTR. */
4338 peek_abbrev_code (bfd
*abfd
, gdb_byte
*info_ptr
)
4340 unsigned int bytes_read
;
4342 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4345 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4346 Return the corresponding abbrev, or NULL if the number is zero (indicating
4347 an empty DIE). In either case *BYTES_READ will be set to the length of
4348 the initial number. */
4350 static struct abbrev_info
*
4351 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
4352 struct dwarf2_cu
*cu
)
4354 bfd
*abfd
= cu
->objfile
->obfd
;
4355 unsigned int abbrev_number
;
4356 struct abbrev_info
*abbrev
;
4358 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
4360 if (abbrev_number
== 0)
4363 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4366 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4367 abbrev_number
, bfd_get_filename (abfd
));
4373 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4374 Returns a pointer to the end of a series of DIEs, terminated by an empty
4375 DIE. Any children of the skipped DIEs will also be skipped. */
4378 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
4380 struct abbrev_info
*abbrev
;
4381 unsigned int bytes_read
;
4385 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
4387 return info_ptr
+ bytes_read
;
4389 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
4393 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4394 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4395 abbrev corresponding to that skipped uleb128 should be passed in
4396 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4400 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4401 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
4403 unsigned int bytes_read
;
4404 struct attribute attr
;
4405 bfd
*abfd
= cu
->objfile
->obfd
;
4406 unsigned int form
, i
;
4408 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
4410 /* The only abbrev we care about is DW_AT_sibling. */
4411 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
4413 read_attribute (&attr
, &abbrev
->attrs
[i
],
4414 abfd
, info_ptr
, cu
);
4415 if (attr
.form
== DW_FORM_ref_addr
)
4416 complaint (&symfile_complaints
,
4417 _("ignoring absolute DW_AT_sibling"));
4419 return buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
4422 /* If it isn't DW_AT_sibling, skip this attribute. */
4423 form
= abbrev
->attrs
[i
].form
;
4427 case DW_FORM_ref_addr
:
4428 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4429 and later it is offset sized. */
4430 if (cu
->header
.version
== 2)
4431 info_ptr
+= cu
->header
.addr_size
;
4433 info_ptr
+= cu
->header
.offset_size
;
4436 info_ptr
+= cu
->header
.addr_size
;
4443 case DW_FORM_flag_present
:
4455 case DW_FORM_ref_sig8
:
4458 case DW_FORM_string
:
4459 read_direct_string (abfd
, info_ptr
, &bytes_read
);
4460 info_ptr
+= bytes_read
;
4462 case DW_FORM_sec_offset
:
4464 info_ptr
+= cu
->header
.offset_size
;
4466 case DW_FORM_exprloc
:
4468 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4469 info_ptr
+= bytes_read
;
4471 case DW_FORM_block1
:
4472 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
4474 case DW_FORM_block2
:
4475 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
4477 case DW_FORM_block4
:
4478 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
4482 case DW_FORM_ref_udata
:
4483 info_ptr
= skip_leb128 (abfd
, info_ptr
);
4485 case DW_FORM_indirect
:
4486 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4487 info_ptr
+= bytes_read
;
4488 /* We need to continue parsing from here, so just go back to
4490 goto skip_attribute
;
4493 error (_("Dwarf Error: Cannot handle %s "
4494 "in DWARF reader [in module %s]"),
4495 dwarf_form_name (form
),
4496 bfd_get_filename (abfd
));
4500 if (abbrev
->has_children
)
4501 return skip_children (buffer
, info_ptr
, cu
);
4506 /* Locate ORIG_PDI's sibling.
4507 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4511 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
4512 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4513 bfd
*abfd
, struct dwarf2_cu
*cu
)
4515 /* Do we know the sibling already? */
4517 if (orig_pdi
->sibling
)
4518 return orig_pdi
->sibling
;
4520 /* Are there any children to deal with? */
4522 if (!orig_pdi
->has_children
)
4525 /* Skip the children the long way. */
4527 return skip_children (buffer
, info_ptr
, cu
);
4530 /* Expand this partial symbol table into a full symbol table. */
4533 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
4539 warning (_("bug: psymtab for %s is already read in."),
4546 printf_filtered (_("Reading in symbols for %s..."),
4548 gdb_flush (gdb_stdout
);
4551 /* Restore our global data. */
4552 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
4553 dwarf2_objfile_data_key
);
4555 /* If this psymtab is constructed from a debug-only objfile, the
4556 has_section_at_zero flag will not necessarily be correct. We
4557 can get the correct value for this flag by looking at the data
4558 associated with the (presumably stripped) associated objfile. */
4559 if (pst
->objfile
->separate_debug_objfile_backlink
)
4561 struct dwarf2_per_objfile
*dpo_backlink
4562 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
4563 dwarf2_objfile_data_key
);
4565 dwarf2_per_objfile
->has_section_at_zero
4566 = dpo_backlink
->has_section_at_zero
;
4569 dwarf2_per_objfile
->reading_partial_symbols
= 0;
4571 psymtab_to_symtab_1 (pst
);
4573 /* Finish up the debug error message. */
4575 printf_filtered (_("done.\n"));
4580 /* Reading in full CUs. */
4582 /* Add PER_CU to the queue. */
4585 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4587 struct dwarf2_queue_item
*item
;
4590 item
= xmalloc (sizeof (*item
));
4591 item
->per_cu
= per_cu
;
4594 if (dwarf2_queue
== NULL
)
4595 dwarf2_queue
= item
;
4597 dwarf2_queue_tail
->next
= item
;
4599 dwarf2_queue_tail
= item
;
4602 /* Process the queue. */
4605 process_queue (void)
4607 struct dwarf2_queue_item
*item
, *next_item
;
4609 /* The queue starts out with one item, but following a DIE reference
4610 may load a new CU, adding it to the end of the queue. */
4611 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
4613 if (dwarf2_per_objfile
->using_index
4614 ? !item
->per_cu
->v
.quick
->symtab
4615 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
4616 process_full_comp_unit (item
->per_cu
);
4618 item
->per_cu
->queued
= 0;
4619 next_item
= item
->next
;
4623 dwarf2_queue_tail
= NULL
;
4626 /* Free all allocated queue entries. This function only releases anything if
4627 an error was thrown; if the queue was processed then it would have been
4628 freed as we went along. */
4631 dwarf2_release_queue (void *dummy
)
4633 struct dwarf2_queue_item
*item
, *last
;
4635 item
= dwarf2_queue
;
4638 /* Anything still marked queued is likely to be in an
4639 inconsistent state, so discard it. */
4640 if (item
->per_cu
->queued
)
4642 if (item
->per_cu
->cu
!= NULL
)
4643 free_one_cached_comp_unit (item
->per_cu
->cu
);
4644 item
->per_cu
->queued
= 0;
4652 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
4655 /* Read in full symbols for PST, and anything it depends on. */
4658 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
4660 struct dwarf2_per_cu_data
*per_cu
;
4661 struct cleanup
*back_to
;
4664 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
4665 if (!pst
->dependencies
[i
]->readin
)
4667 /* Inform about additional files that need to be read in. */
4670 /* FIXME: i18n: Need to make this a single string. */
4671 fputs_filtered (" ", gdb_stdout
);
4673 fputs_filtered ("and ", gdb_stdout
);
4675 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
4676 wrap_here (""); /* Flush output. */
4677 gdb_flush (gdb_stdout
);
4679 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
4682 per_cu
= pst
->read_symtab_private
;
4686 /* It's an include file, no symbols to read for it.
4687 Everything is in the parent symtab. */
4692 dw2_do_instantiate_symtab (per_cu
);
4695 /* Load the DIEs associated with PER_CU into memory. */
4698 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4700 struct objfile
*objfile
= per_cu
->objfile
;
4701 bfd
*abfd
= objfile
->obfd
;
4702 struct dwarf2_cu
*cu
;
4704 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
4705 struct cleanup
*free_cu_cleanup
= NULL
;
4706 struct attribute
*attr
;
4709 gdb_assert (! per_cu
->debug_types_section
);
4711 /* Set local variables from the partial symbol table info. */
4712 offset
= per_cu
->offset
;
4714 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4715 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
.sect_off
;
4716 beg_of_comp_unit
= info_ptr
;
4718 if (per_cu
->cu
== NULL
)
4720 cu
= xmalloc (sizeof (*cu
));
4721 init_one_comp_unit (cu
, per_cu
);
4725 /* If an error occurs while loading, release our storage. */
4726 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
4728 /* Read in the comp_unit header. */
4729 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
4731 /* Skip dummy compilation units. */
4732 if (info_ptr
>= (dwarf2_per_objfile
->info
.buffer
4733 + dwarf2_per_objfile
->info
.size
)
4734 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4736 do_cleanups (free_cu_cleanup
);
4740 /* Complete the cu_header. */
4741 cu
->header
.offset
= offset
;
4742 cu
->header
.first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
4747 info_ptr
+= cu
->header
.first_die_offset
.cu_off
;
4750 cu
->dies
= read_comp_unit (info_ptr
, cu
);
4752 /* We try not to read any attributes in this function, because not
4753 all CUs needed for references have been loaded yet, and symbol
4754 table processing isn't initialized. But we have to set the CU language,
4755 or we won't be able to build types correctly. */
4756 prepare_one_comp_unit (cu
, cu
->dies
);
4758 /* Similarly, if we do not read the producer, we can not apply
4759 producer-specific interpretation. */
4760 attr
= dwarf2_attr (cu
->dies
, DW_AT_producer
, cu
);
4762 cu
->producer
= DW_STRING (attr
);
4766 /* We've successfully allocated this compilation unit. Let our
4767 caller clean it up when finished with it. */
4768 discard_cleanups (free_cu_cleanup
);
4770 /* Link this CU into read_in_chain. */
4771 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4772 dwarf2_per_objfile
->read_in_chain
= per_cu
;
4776 /* Add a DIE to the delayed physname list. */
4779 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
4780 const char *name
, struct die_info
*die
,
4781 struct dwarf2_cu
*cu
)
4783 struct delayed_method_info mi
;
4785 mi
.fnfield_index
= fnfield_index
;
4789 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
4792 /* A cleanup for freeing the delayed method list. */
4795 free_delayed_list (void *ptr
)
4797 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
4798 if (cu
->method_list
!= NULL
)
4800 VEC_free (delayed_method_info
, cu
->method_list
);
4801 cu
->method_list
= NULL
;
4805 /* Compute the physnames of any methods on the CU's method list.
4807 The computation of method physnames is delayed in order to avoid the
4808 (bad) condition that one of the method's formal parameters is of an as yet
4812 compute_delayed_physnames (struct dwarf2_cu
*cu
)
4815 struct delayed_method_info
*mi
;
4816 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
4818 const char *physname
;
4819 struct fn_fieldlist
*fn_flp
4820 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
4821 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
4822 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
4826 /* Go objects should be embedded in a DW_TAG_module DIE,
4827 and it's not clear if/how imported objects will appear.
4828 To keep Go support simple until that's worked out,
4829 go back through what we've read and create something usable.
4830 We could do this while processing each DIE, and feels kinda cleaner,
4831 but that way is more invasive.
4832 This is to, for example, allow the user to type "p var" or "b main"
4833 without having to specify the package name, and allow lookups
4834 of module.object to work in contexts that use the expression
4838 fixup_go_packaging (struct dwarf2_cu
*cu
)
4840 char *package_name
= NULL
;
4841 struct pending
*list
;
4844 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
4846 for (i
= 0; i
< list
->nsyms
; ++i
)
4848 struct symbol
*sym
= list
->symbol
[i
];
4850 if (SYMBOL_LANGUAGE (sym
) == language_go
4851 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
4853 char *this_package_name
= go_symbol_package_name (sym
);
4855 if (this_package_name
== NULL
)
4857 if (package_name
== NULL
)
4858 package_name
= this_package_name
;
4861 if (strcmp (package_name
, this_package_name
) != 0)
4862 complaint (&symfile_complaints
,
4863 _("Symtab %s has objects from two different Go packages: %s and %s"),
4864 (sym
->symtab
&& sym
->symtab
->filename
4865 ? sym
->symtab
->filename
4866 : cu
->objfile
->name
),
4867 this_package_name
, package_name
);
4868 xfree (this_package_name
);
4874 if (package_name
!= NULL
)
4876 struct objfile
*objfile
= cu
->objfile
;
4877 struct type
*type
= init_type (TYPE_CODE_MODULE
, 0, 0,
4878 package_name
, objfile
);
4881 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
4883 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
4884 SYMBOL_SET_LANGUAGE (sym
, language_go
);
4885 SYMBOL_SET_NAMES (sym
, package_name
, strlen (package_name
), 1, objfile
);
4886 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
4887 e.g., "main" finds the "main" module and not C's main(). */
4888 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
4889 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4890 SYMBOL_TYPE (sym
) = type
;
4892 add_symbol_to_list (sym
, &global_symbols
);
4894 xfree (package_name
);
4898 /* Generate full symbol information for PER_CU, whose DIEs have
4899 already been loaded into memory. */
4902 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4904 struct dwarf2_cu
*cu
= per_cu
->cu
;
4905 struct objfile
*objfile
= per_cu
->objfile
;
4906 CORE_ADDR lowpc
, highpc
;
4907 struct symtab
*symtab
;
4908 struct cleanup
*back_to
, *delayed_list_cleanup
;
4911 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4914 back_to
= make_cleanup (really_free_pendings
, NULL
);
4915 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
4917 cu
->list_in_scope
= &file_symbols
;
4919 /* Do line number decoding in read_file_scope () */
4920 process_die (cu
->dies
, cu
);
4922 /* For now fudge the Go package. */
4923 if (cu
->language
== language_go
)
4924 fixup_go_packaging (cu
);
4926 /* Now that we have processed all the DIEs in the CU, all the types
4927 should be complete, and it should now be safe to compute all of the
4929 compute_delayed_physnames (cu
);
4930 do_cleanups (delayed_list_cleanup
);
4932 /* Some compilers don't define a DW_AT_high_pc attribute for the
4933 compilation unit. If the DW_AT_high_pc is missing, synthesize
4934 it, by scanning the DIE's below the compilation unit. */
4935 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
4937 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
4941 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
4943 /* Set symtab language to language from DW_AT_language. If the
4944 compilation is from a C file generated by language preprocessors, do
4945 not set the language if it was already deduced by start_subfile. */
4946 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
4947 symtab
->language
= cu
->language
;
4949 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
4950 produce DW_AT_location with location lists but it can be possibly
4951 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
4952 there were bugs in prologue debug info, fixed later in GCC-4.5
4953 by "unwind info for epilogues" patch (which is not directly related).
4955 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
4956 needed, it would be wrong due to missing DW_AT_producer there.
4958 Still one can confuse GDB by using non-standard GCC compilation
4959 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
4961 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
4962 symtab
->locations_valid
= 1;
4964 if (gcc_4_minor
>= 5)
4965 symtab
->epilogue_unwind_valid
= 1;
4967 symtab
->call_site_htab
= cu
->call_site_htab
;
4970 if (dwarf2_per_objfile
->using_index
)
4971 per_cu
->v
.quick
->symtab
= symtab
;
4974 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4975 pst
->symtab
= symtab
;
4979 do_cleanups (back_to
);
4982 /* Process a die and its children. */
4985 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
4989 case DW_TAG_padding
:
4991 case DW_TAG_compile_unit
:
4992 read_file_scope (die
, cu
);
4994 case DW_TAG_type_unit
:
4995 read_type_unit_scope (die
, cu
);
4997 case DW_TAG_subprogram
:
4998 case DW_TAG_inlined_subroutine
:
4999 read_func_scope (die
, cu
);
5001 case DW_TAG_lexical_block
:
5002 case DW_TAG_try_block
:
5003 case DW_TAG_catch_block
:
5004 read_lexical_block_scope (die
, cu
);
5006 case DW_TAG_GNU_call_site
:
5007 read_call_site_scope (die
, cu
);
5009 case DW_TAG_class_type
:
5010 case DW_TAG_interface_type
:
5011 case DW_TAG_structure_type
:
5012 case DW_TAG_union_type
:
5013 process_structure_scope (die
, cu
);
5015 case DW_TAG_enumeration_type
:
5016 process_enumeration_scope (die
, cu
);
5019 /* These dies have a type, but processing them does not create
5020 a symbol or recurse to process the children. Therefore we can
5021 read them on-demand through read_type_die. */
5022 case DW_TAG_subroutine_type
:
5023 case DW_TAG_set_type
:
5024 case DW_TAG_array_type
:
5025 case DW_TAG_pointer_type
:
5026 case DW_TAG_ptr_to_member_type
:
5027 case DW_TAG_reference_type
:
5028 case DW_TAG_string_type
:
5031 case DW_TAG_base_type
:
5032 case DW_TAG_subrange_type
:
5033 case DW_TAG_typedef
:
5034 /* Add a typedef symbol for the type definition, if it has a
5036 new_symbol (die
, read_type_die (die
, cu
), cu
);
5038 case DW_TAG_common_block
:
5039 read_common_block (die
, cu
);
5041 case DW_TAG_common_inclusion
:
5043 case DW_TAG_namespace
:
5044 processing_has_namespace_info
= 1;
5045 read_namespace (die
, cu
);
5048 processing_has_namespace_info
= 1;
5049 read_module (die
, cu
);
5051 case DW_TAG_imported_declaration
:
5052 case DW_TAG_imported_module
:
5053 processing_has_namespace_info
= 1;
5054 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
5055 || cu
->language
!= language_fortran
))
5056 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
5057 dwarf_tag_name (die
->tag
));
5058 read_import_statement (die
, cu
);
5061 new_symbol (die
, NULL
, cu
);
5066 /* A helper function for dwarf2_compute_name which determines whether DIE
5067 needs to have the name of the scope prepended to the name listed in the
5071 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
5073 struct attribute
*attr
;
5077 case DW_TAG_namespace
:
5078 case DW_TAG_typedef
:
5079 case DW_TAG_class_type
:
5080 case DW_TAG_interface_type
:
5081 case DW_TAG_structure_type
:
5082 case DW_TAG_union_type
:
5083 case DW_TAG_enumeration_type
:
5084 case DW_TAG_enumerator
:
5085 case DW_TAG_subprogram
:
5089 case DW_TAG_variable
:
5090 case DW_TAG_constant
:
5091 /* We only need to prefix "globally" visible variables. These include
5092 any variable marked with DW_AT_external or any variable that
5093 lives in a namespace. [Variables in anonymous namespaces
5094 require prefixing, but they are not DW_AT_external.] */
5096 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
5098 struct dwarf2_cu
*spec_cu
= cu
;
5100 return die_needs_namespace (die_specification (die
, &spec_cu
),
5104 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5105 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
5106 && die
->parent
->tag
!= DW_TAG_module
)
5108 /* A variable in a lexical block of some kind does not need a
5109 namespace, even though in C++ such variables may be external
5110 and have a mangled name. */
5111 if (die
->parent
->tag
== DW_TAG_lexical_block
5112 || die
->parent
->tag
== DW_TAG_try_block
5113 || die
->parent
->tag
== DW_TAG_catch_block
5114 || die
->parent
->tag
== DW_TAG_subprogram
)
5123 /* Retrieve the last character from a mem_file. */
5126 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
5128 char *last_char_p
= (char *) object
;
5131 *last_char_p
= buffer
[length
- 1];
5134 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
5135 compute the physname for the object, which include a method's:
5136 - formal parameters (C++/Java),
5137 - receiver type (Go),
5138 - return type (Java).
5140 The term "physname" is a bit confusing.
5141 For C++, for example, it is the demangled name.
5142 For Go, for example, it's the mangled name.
5144 For Ada, return the DIE's linkage name rather than the fully qualified
5145 name. PHYSNAME is ignored..
5147 The result is allocated on the objfile_obstack and canonicalized. */
5150 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
5153 struct objfile
*objfile
= cu
->objfile
;
5156 name
= dwarf2_name (die
, cu
);
5158 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
5159 compute it by typename_concat inside GDB. */
5160 if (cu
->language
== language_ada
5161 || (cu
->language
== language_fortran
&& physname
))
5163 /* For Ada unit, we prefer the linkage name over the name, as
5164 the former contains the exported name, which the user expects
5165 to be able to reference. Ideally, we want the user to be able
5166 to reference this entity using either natural or linkage name,
5167 but we haven't started looking at this enhancement yet. */
5168 struct attribute
*attr
;
5170 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5172 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5173 if (attr
&& DW_STRING (attr
))
5174 return DW_STRING (attr
);
5177 /* These are the only languages we know how to qualify names in. */
5179 && (cu
->language
== language_cplus
|| cu
->language
== language_java
5180 || cu
->language
== language_fortran
))
5182 if (die_needs_namespace (die
, cu
))
5186 struct ui_file
*buf
;
5188 prefix
= determine_prefix (die
, cu
);
5189 buf
= mem_fileopen ();
5190 if (*prefix
!= '\0')
5192 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
5195 fputs_unfiltered (prefixed_name
, buf
);
5196 xfree (prefixed_name
);
5199 fputs_unfiltered (name
, buf
);
5201 /* Template parameters may be specified in the DIE's DW_AT_name, or
5202 as children with DW_TAG_template_type_param or
5203 DW_TAG_value_type_param. If the latter, add them to the name
5204 here. If the name already has template parameters, then
5205 skip this step; some versions of GCC emit both, and
5206 it is more efficient to use the pre-computed name.
5208 Something to keep in mind about this process: it is very
5209 unlikely, or in some cases downright impossible, to produce
5210 something that will match the mangled name of a function.
5211 If the definition of the function has the same debug info,
5212 we should be able to match up with it anyway. But fallbacks
5213 using the minimal symbol, for instance to find a method
5214 implemented in a stripped copy of libstdc++, will not work.
5215 If we do not have debug info for the definition, we will have to
5216 match them up some other way.
5218 When we do name matching there is a related problem with function
5219 templates; two instantiated function templates are allowed to
5220 differ only by their return types, which we do not add here. */
5222 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
5224 struct attribute
*attr
;
5225 struct die_info
*child
;
5228 die
->building_fullname
= 1;
5230 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
5235 struct dwarf2_locexpr_baton
*baton
;
5238 if (child
->tag
!= DW_TAG_template_type_param
5239 && child
->tag
!= DW_TAG_template_value_param
)
5244 fputs_unfiltered ("<", buf
);
5248 fputs_unfiltered (", ", buf
);
5250 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
5253 complaint (&symfile_complaints
,
5254 _("template parameter missing DW_AT_type"));
5255 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
5258 type
= die_type (child
, cu
);
5260 if (child
->tag
== DW_TAG_template_type_param
)
5262 c_print_type (type
, "", buf
, -1, 0);
5266 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
5269 complaint (&symfile_complaints
,
5270 _("template parameter missing "
5271 "DW_AT_const_value"));
5272 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
5276 dwarf2_const_value_attr (attr
, type
, name
,
5277 &cu
->comp_unit_obstack
, cu
,
5278 &value
, &bytes
, &baton
);
5280 if (TYPE_NOSIGN (type
))
5281 /* GDB prints characters as NUMBER 'CHAR'. If that's
5282 changed, this can use value_print instead. */
5283 c_printchar (value
, type
, buf
);
5286 struct value_print_options opts
;
5289 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
5293 else if (bytes
!= NULL
)
5295 v
= allocate_value (type
);
5296 memcpy (value_contents_writeable (v
), bytes
,
5297 TYPE_LENGTH (type
));
5300 v
= value_from_longest (type
, value
);
5302 /* Specify decimal so that we do not depend on
5304 get_formatted_print_options (&opts
, 'd');
5306 value_print (v
, buf
, &opts
);
5312 die
->building_fullname
= 0;
5316 /* Close the argument list, with a space if necessary
5317 (nested templates). */
5318 char last_char
= '\0';
5319 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
5320 if (last_char
== '>')
5321 fputs_unfiltered (" >", buf
);
5323 fputs_unfiltered (">", buf
);
5327 /* For Java and C++ methods, append formal parameter type
5328 information, if PHYSNAME. */
5330 if (physname
&& die
->tag
== DW_TAG_subprogram
5331 && (cu
->language
== language_cplus
5332 || cu
->language
== language_java
))
5334 struct type
*type
= read_type_die (die
, cu
);
5336 c_type_print_args (type
, buf
, 1, cu
->language
);
5338 if (cu
->language
== language_java
)
5340 /* For java, we must append the return type to method
5342 if (die
->tag
== DW_TAG_subprogram
)
5343 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
5346 else if (cu
->language
== language_cplus
)
5348 /* Assume that an artificial first parameter is
5349 "this", but do not crash if it is not. RealView
5350 marks unnamed (and thus unused) parameters as
5351 artificial; there is no way to differentiate
5353 if (TYPE_NFIELDS (type
) > 0
5354 && TYPE_FIELD_ARTIFICIAL (type
, 0)
5355 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
5356 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
5358 fputs_unfiltered (" const", buf
);
5362 name
= ui_file_obsavestring (buf
, &objfile
->objfile_obstack
,
5364 ui_file_delete (buf
);
5366 if (cu
->language
== language_cplus
)
5369 = dwarf2_canonicalize_name (name
, cu
,
5370 &objfile
->objfile_obstack
);
5381 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5382 If scope qualifiers are appropriate they will be added. The result
5383 will be allocated on the objfile_obstack, or NULL if the DIE does
5384 not have a name. NAME may either be from a previous call to
5385 dwarf2_name or NULL.
5387 The output string will be canonicalized (if C++/Java). */
5390 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5392 return dwarf2_compute_name (name
, die
, cu
, 0);
5395 /* Construct a physname for the given DIE in CU. NAME may either be
5396 from a previous call to dwarf2_name or NULL. The result will be
5397 allocated on the objfile_objstack or NULL if the DIE does not have a
5400 The output string will be canonicalized (if C++/Java). */
5403 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5405 struct objfile
*objfile
= cu
->objfile
;
5406 struct attribute
*attr
;
5407 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
5408 struct cleanup
*back_to
;
5411 /* In this case dwarf2_compute_name is just a shortcut not building anything
5413 if (!die_needs_namespace (die
, cu
))
5414 return dwarf2_compute_name (name
, die
, cu
, 1);
5416 back_to
= make_cleanup (null_cleanup
, NULL
);
5418 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5420 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5422 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
5424 if (attr
&& DW_STRING (attr
))
5428 mangled
= DW_STRING (attr
);
5430 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
5431 type. It is easier for GDB users to search for such functions as
5432 `name(params)' than `long name(params)'. In such case the minimal
5433 symbol names do not match the full symbol names but for template
5434 functions there is never a need to look up their definition from their
5435 declaration so the only disadvantage remains the minimal symbol
5436 variant `long name(params)' does not have the proper inferior type.
5439 if (cu
->language
== language_go
)
5441 /* This is a lie, but we already lie to the caller new_symbol_full.
5442 new_symbol_full assumes we return the mangled name.
5443 This just undoes that lie until things are cleaned up. */
5448 demangled
= cplus_demangle (mangled
,
5449 (DMGL_PARAMS
| DMGL_ANSI
5450 | (cu
->language
== language_java
5451 ? DMGL_JAVA
| DMGL_RET_POSTFIX
5456 make_cleanup (xfree
, demangled
);
5466 if (canon
== NULL
|| check_physname
)
5468 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
5470 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
5472 /* It may not mean a bug in GDB. The compiler could also
5473 compute DW_AT_linkage_name incorrectly. But in such case
5474 GDB would need to be bug-to-bug compatible. */
5476 complaint (&symfile_complaints
,
5477 _("Computed physname <%s> does not match demangled <%s> "
5478 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
5479 physname
, canon
, mangled
, die
->offset
.sect_off
, objfile
->name
);
5481 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
5482 is available here - over computed PHYSNAME. It is safer
5483 against both buggy GDB and buggy compilers. */
5497 retval
= obsavestring (retval
, strlen (retval
),
5498 &objfile
->objfile_obstack
);
5500 do_cleanups (back_to
);
5504 /* Read the import statement specified by the given die and record it. */
5507 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
5509 struct objfile
*objfile
= cu
->objfile
;
5510 struct attribute
*import_attr
;
5511 struct die_info
*imported_die
, *child_die
;
5512 struct dwarf2_cu
*imported_cu
;
5513 const char *imported_name
;
5514 const char *imported_name_prefix
;
5515 const char *canonical_name
;
5516 const char *import_alias
;
5517 const char *imported_declaration
= NULL
;
5518 const char *import_prefix
;
5519 VEC (const_char_ptr
) *excludes
= NULL
;
5520 struct cleanup
*cleanups
;
5524 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
5525 if (import_attr
== NULL
)
5527 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5528 dwarf_tag_name (die
->tag
));
5533 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
5534 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5535 if (imported_name
== NULL
)
5537 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
5539 The import in the following code:
5553 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
5554 <52> DW_AT_decl_file : 1
5555 <53> DW_AT_decl_line : 6
5556 <54> DW_AT_import : <0x75>
5557 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
5559 <5b> DW_AT_decl_file : 1
5560 <5c> DW_AT_decl_line : 2
5561 <5d> DW_AT_type : <0x6e>
5563 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
5564 <76> DW_AT_byte_size : 4
5565 <77> DW_AT_encoding : 5 (signed)
5567 imports the wrong die ( 0x75 instead of 0x58 ).
5568 This case will be ignored until the gcc bug is fixed. */
5572 /* Figure out the local name after import. */
5573 import_alias
= dwarf2_name (die
, cu
);
5575 /* Figure out where the statement is being imported to. */
5576 import_prefix
= determine_prefix (die
, cu
);
5578 /* Figure out what the scope of the imported die is and prepend it
5579 to the name of the imported die. */
5580 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
5582 if (imported_die
->tag
!= DW_TAG_namespace
5583 && imported_die
->tag
!= DW_TAG_module
)
5585 imported_declaration
= imported_name
;
5586 canonical_name
= imported_name_prefix
;
5588 else if (strlen (imported_name_prefix
) > 0)
5590 temp
= alloca (strlen (imported_name_prefix
)
5591 + 2 + strlen (imported_name
) + 1);
5592 strcpy (temp
, imported_name_prefix
);
5593 strcat (temp
, "::");
5594 strcat (temp
, imported_name
);
5595 canonical_name
= temp
;
5598 canonical_name
= imported_name
;
5600 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
5602 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
5603 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
5604 child_die
= sibling_die (child_die
))
5606 /* DWARF-4: A Fortran use statement with a “rename list” may be
5607 represented by an imported module entry with an import attribute
5608 referring to the module and owned entries corresponding to those
5609 entities that are renamed as part of being imported. */
5611 if (child_die
->tag
!= DW_TAG_imported_declaration
)
5613 complaint (&symfile_complaints
,
5614 _("child DW_TAG_imported_declaration expected "
5615 "- DIE at 0x%x [in module %s]"),
5616 child_die
->offset
.sect_off
, objfile
->name
);
5620 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
5621 if (import_attr
== NULL
)
5623 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5624 dwarf_tag_name (child_die
->tag
));
5629 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
5631 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5632 if (imported_name
== NULL
)
5634 complaint (&symfile_complaints
,
5635 _("child DW_TAG_imported_declaration has unknown "
5636 "imported name - DIE at 0x%x [in module %s]"),
5637 child_die
->offset
.sect_off
, objfile
->name
);
5641 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
5643 process_die (child_die
, cu
);
5646 cp_add_using_directive (import_prefix
,
5649 imported_declaration
,
5651 &objfile
->objfile_obstack
);
5653 do_cleanups (cleanups
);
5656 /* Cleanup function for read_file_scope. */
5659 free_cu_line_header (void *arg
)
5661 struct dwarf2_cu
*cu
= arg
;
5663 free_line_header (cu
->line_header
);
5664 cu
->line_header
= NULL
;
5668 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
5669 char **name
, char **comp_dir
)
5671 struct attribute
*attr
;
5676 /* Find the filename. Do not use dwarf2_name here, since the filename
5677 is not a source language identifier. */
5678 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5681 *name
= DW_STRING (attr
);
5684 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5686 *comp_dir
= DW_STRING (attr
);
5687 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
5689 *comp_dir
= ldirname (*name
);
5690 if (*comp_dir
!= NULL
)
5691 make_cleanup (xfree
, *comp_dir
);
5693 if (*comp_dir
!= NULL
)
5695 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5696 directory, get rid of it. */
5697 char *cp
= strchr (*comp_dir
, ':');
5699 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
5704 *name
= "<unknown>";
5707 /* Handle DW_AT_stmt_list for a compilation unit or type unit.
5708 DIE is the DW_TAG_compile_unit or DW_TAG_type_unit die for CU.
5709 COMP_DIR is the compilation directory.
5710 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
5713 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
5714 const char *comp_dir
, int want_line_info
)
5716 struct attribute
*attr
;
5717 struct objfile
*objfile
= cu
->objfile
;
5718 bfd
*abfd
= objfile
->obfd
;
5720 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5723 unsigned int line_offset
= DW_UNSND (attr
);
5724 struct line_header
*line_header
5725 = dwarf_decode_line_header (line_offset
, abfd
, cu
);
5729 cu
->line_header
= line_header
;
5730 make_cleanup (free_cu_line_header
, cu
);
5731 dwarf_decode_lines (line_header
, comp_dir
, cu
, NULL
, want_line_info
);
5736 /* Process DW_TAG_compile_unit. */
5739 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5741 struct objfile
*objfile
= cu
->objfile
;
5742 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5743 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
5744 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
5745 struct attribute
*attr
;
5747 char *comp_dir
= NULL
;
5748 struct die_info
*child_die
;
5749 bfd
*abfd
= objfile
->obfd
;
5752 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5754 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
5756 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5757 from finish_block. */
5758 if (lowpc
== ((CORE_ADDR
) -1))
5763 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
5765 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5768 set_cu_language (DW_UNSND (attr
), cu
);
5771 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5773 cu
->producer
= DW_STRING (attr
);
5775 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
5776 standardised yet. As a workaround for the language detection we fall
5777 back to the DW_AT_producer string. */
5778 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
5779 cu
->language
= language_opencl
;
5781 /* Similar hack for Go. */
5782 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
5783 set_cu_language (DW_LANG_Go
, cu
);
5785 /* We assume that we're processing GCC output. */
5786 processing_gcc_compilation
= 2;
5788 processing_has_namespace_info
= 0;
5790 start_symtab (name
, comp_dir
, lowpc
);
5791 record_debugformat ("DWARF 2");
5792 record_producer (cu
->producer
);
5794 /* Decode line number information if present. We do this before
5795 processing child DIEs, so that the line header table is available
5796 for DW_AT_decl_file. */
5797 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, 1);
5799 /* Process all dies in compilation unit. */
5800 if (die
->child
!= NULL
)
5802 child_die
= die
->child
;
5803 while (child_die
&& child_die
->tag
)
5805 process_die (child_die
, cu
);
5806 child_die
= sibling_die (child_die
);
5810 /* Decode macro information, if present. Dwarf 2 macro information
5811 refers to information in the line number info statement program
5812 header, so we can only read it if we've read the header
5814 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
5815 if (attr
&& cu
->line_header
)
5817 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
5818 complaint (&symfile_complaints
,
5819 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
5821 dwarf_decode_macros (cu
->line_header
, DW_UNSND (attr
),
5823 &dwarf2_per_objfile
->macro
, 1);
5827 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
5828 if (attr
&& cu
->line_header
)
5830 unsigned int macro_offset
= DW_UNSND (attr
);
5832 dwarf_decode_macros (cu
->line_header
, macro_offset
,
5834 &dwarf2_per_objfile
->macinfo
, 0);
5838 do_cleanups (back_to
);
5841 /* Process DW_TAG_type_unit.
5842 For TUs we want to skip the first top level sibling if it's not the
5843 actual type being defined by this TU. In this case the first top
5844 level sibling is there to provide context only. */
5847 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5849 struct objfile
*objfile
= cu
->objfile
;
5850 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5852 struct attribute
*attr
;
5854 char *comp_dir
= NULL
;
5855 struct die_info
*child_die
;
5856 bfd
*abfd
= objfile
->obfd
;
5858 /* start_symtab needs a low pc, but we don't really have one.
5859 Do what read_file_scope would do in the absence of such info. */
5860 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5862 /* Find the filename. Do not use dwarf2_name here, since the filename
5863 is not a source language identifier. */
5864 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5866 name
= DW_STRING (attr
);
5868 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5870 comp_dir
= DW_STRING (attr
);
5871 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
5873 comp_dir
= ldirname (name
);
5874 if (comp_dir
!= NULL
)
5875 make_cleanup (xfree
, comp_dir
);
5881 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5883 set_cu_language (DW_UNSND (attr
), cu
);
5885 /* This isn't technically needed today. It is done for symmetry
5886 with read_file_scope. */
5887 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5889 cu
->producer
= DW_STRING (attr
);
5891 /* We assume that we're processing GCC output. */
5892 processing_gcc_compilation
= 2;
5894 processing_has_namespace_info
= 0;
5896 start_symtab (name
, comp_dir
, lowpc
);
5897 record_debugformat ("DWARF 2");
5898 record_producer (cu
->producer
);
5900 /* Decode line number information if present. We do this before
5901 processing child DIEs, so that the line header table is available
5902 for DW_AT_decl_file.
5903 We don't need the pc/line-number mapping for type units. */
5904 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, 0);
5906 /* Process the dies in the type unit. */
5907 if (die
->child
== NULL
)
5909 dump_die_for_error (die
);
5910 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5911 bfd_get_filename (abfd
));
5914 child_die
= die
->child
;
5916 while (child_die
&& child_die
->tag
)
5918 process_die (child_die
, cu
);
5920 child_die
= sibling_die (child_die
);
5923 do_cleanups (back_to
);
5926 /* qsort helper for inherit_abstract_dies. */
5929 unsigned_int_compar (const void *ap
, const void *bp
)
5931 unsigned int a
= *(unsigned int *) ap
;
5932 unsigned int b
= *(unsigned int *) bp
;
5934 return (a
> b
) - (b
> a
);
5937 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5938 Inherit only the children of the DW_AT_abstract_origin DIE not being
5939 already referenced by DW_AT_abstract_origin from the children of the
5943 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
5945 struct die_info
*child_die
;
5946 unsigned die_children_count
;
5947 /* CU offsets which were referenced by children of the current DIE. */
5948 sect_offset
*offsets
;
5949 sect_offset
*offsets_end
, *offsetp
;
5950 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5951 struct die_info
*origin_die
;
5952 /* Iterator of the ORIGIN_DIE children. */
5953 struct die_info
*origin_child_die
;
5954 struct cleanup
*cleanups
;
5955 struct attribute
*attr
;
5956 struct dwarf2_cu
*origin_cu
;
5957 struct pending
**origin_previous_list_in_scope
;
5959 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
5963 /* Note that following die references may follow to a die in a
5967 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
5969 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5971 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
5972 origin_cu
->list_in_scope
= cu
->list_in_scope
;
5974 if (die
->tag
!= origin_die
->tag
5975 && !(die
->tag
== DW_TAG_inlined_subroutine
5976 && origin_die
->tag
== DW_TAG_subprogram
))
5977 complaint (&symfile_complaints
,
5978 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5979 die
->offset
.sect_off
, origin_die
->offset
.sect_off
);
5981 child_die
= die
->child
;
5982 die_children_count
= 0;
5983 while (child_die
&& child_die
->tag
)
5985 child_die
= sibling_die (child_die
);
5986 die_children_count
++;
5988 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
5989 cleanups
= make_cleanup (xfree
, offsets
);
5991 offsets_end
= offsets
;
5992 child_die
= die
->child
;
5993 while (child_die
&& child_die
->tag
)
5995 /* For each CHILD_DIE, find the corresponding child of
5996 ORIGIN_DIE. If there is more than one layer of
5997 DW_AT_abstract_origin, follow them all; there shouldn't be,
5998 but GCC versions at least through 4.4 generate this (GCC PR
6000 struct die_info
*child_origin_die
= child_die
;
6001 struct dwarf2_cu
*child_origin_cu
= cu
;
6005 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
6009 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
6013 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
6014 counterpart may exist. */
6015 if (child_origin_die
!= child_die
)
6017 if (child_die
->tag
!= child_origin_die
->tag
6018 && !(child_die
->tag
== DW_TAG_inlined_subroutine
6019 && child_origin_die
->tag
== DW_TAG_subprogram
))
6020 complaint (&symfile_complaints
,
6021 _("Child DIE 0x%x and its abstract origin 0x%x have "
6022 "different tags"), child_die
->offset
.sect_off
,
6023 child_origin_die
->offset
.sect_off
);
6024 if (child_origin_die
->parent
!= origin_die
)
6025 complaint (&symfile_complaints
,
6026 _("Child DIE 0x%x and its abstract origin 0x%x have "
6027 "different parents"), child_die
->offset
.sect_off
,
6028 child_origin_die
->offset
.sect_off
);
6030 *offsets_end
++ = child_origin_die
->offset
;
6032 child_die
= sibling_die (child_die
);
6034 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
6035 unsigned_int_compar
);
6036 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
6037 if (offsetp
[-1].sect_off
== offsetp
->sect_off
)
6038 complaint (&symfile_complaints
,
6039 _("Multiple children of DIE 0x%x refer "
6040 "to DIE 0x%x as their abstract origin"),
6041 die
->offset
.sect_off
, offsetp
->sect_off
);
6044 origin_child_die
= origin_die
->child
;
6045 while (origin_child_die
&& origin_child_die
->tag
)
6047 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
6048 while (offsetp
< offsets_end
6049 && offsetp
->sect_off
< origin_child_die
->offset
.sect_off
)
6051 if (offsetp
>= offsets_end
6052 || offsetp
->sect_off
> origin_child_die
->offset
.sect_off
)
6054 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
6055 process_die (origin_child_die
, origin_cu
);
6057 origin_child_die
= sibling_die (origin_child_die
);
6059 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
6061 do_cleanups (cleanups
);
6065 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6067 struct objfile
*objfile
= cu
->objfile
;
6068 struct context_stack
*new;
6071 struct die_info
*child_die
;
6072 struct attribute
*attr
, *call_line
, *call_file
;
6075 struct block
*block
;
6076 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
6077 VEC (symbolp
) *template_args
= NULL
;
6078 struct template_symbol
*templ_func
= NULL
;
6082 /* If we do not have call site information, we can't show the
6083 caller of this inlined function. That's too confusing, so
6084 only use the scope for local variables. */
6085 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
6086 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
6087 if (call_line
== NULL
|| call_file
== NULL
)
6089 read_lexical_block_scope (die
, cu
);
6094 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6096 name
= dwarf2_name (die
, cu
);
6098 /* Ignore functions with missing or empty names. These are actually
6099 illegal according to the DWARF standard. */
6102 complaint (&symfile_complaints
,
6103 _("missing name for subprogram DIE at %d"),
6104 die
->offset
.sect_off
);
6108 /* Ignore functions with missing or invalid low and high pc attributes. */
6109 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
6111 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
6112 if (!attr
|| !DW_UNSND (attr
))
6113 complaint (&symfile_complaints
,
6114 _("cannot get low and high bounds "
6115 "for subprogram DIE at %d"),
6116 die
->offset
.sect_off
);
6123 /* If we have any template arguments, then we must allocate a
6124 different sort of symbol. */
6125 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
6127 if (child_die
->tag
== DW_TAG_template_type_param
6128 || child_die
->tag
== DW_TAG_template_value_param
)
6130 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6131 struct template_symbol
);
6132 templ_func
->base
.is_cplus_template_function
= 1;
6137 new = push_context (0, lowpc
);
6138 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
6139 (struct symbol
*) templ_func
);
6141 /* If there is a location expression for DW_AT_frame_base, record
6143 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
6145 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
6146 expression is being recorded directly in the function's symbol
6147 and not in a separate frame-base object. I guess this hack is
6148 to avoid adding some sort of frame-base adjunct/annex to the
6149 function's symbol :-(. The problem with doing this is that it
6150 results in a function symbol with a location expression that
6151 has nothing to do with the location of the function, ouch! The
6152 relationship should be: a function's symbol has-a frame base; a
6153 frame-base has-a location expression. */
6154 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
6156 cu
->list_in_scope
= &local_symbols
;
6158 if (die
->child
!= NULL
)
6160 child_die
= die
->child
;
6161 while (child_die
&& child_die
->tag
)
6163 if (child_die
->tag
== DW_TAG_template_type_param
6164 || child_die
->tag
== DW_TAG_template_value_param
)
6166 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
6169 VEC_safe_push (symbolp
, template_args
, arg
);
6172 process_die (child_die
, cu
);
6173 child_die
= sibling_die (child_die
);
6177 inherit_abstract_dies (die
, cu
);
6179 /* If we have a DW_AT_specification, we might need to import using
6180 directives from the context of the specification DIE. See the
6181 comment in determine_prefix. */
6182 if (cu
->language
== language_cplus
6183 && dwarf2_attr (die
, DW_AT_specification
, cu
))
6185 struct dwarf2_cu
*spec_cu
= cu
;
6186 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
6190 child_die
= spec_die
->child
;
6191 while (child_die
&& child_die
->tag
)
6193 if (child_die
->tag
== DW_TAG_imported_module
)
6194 process_die (child_die
, spec_cu
);
6195 child_die
= sibling_die (child_die
);
6198 /* In some cases, GCC generates specification DIEs that
6199 themselves contain DW_AT_specification attributes. */
6200 spec_die
= die_specification (spec_die
, &spec_cu
);
6204 new = pop_context ();
6205 /* Make a block for the local symbols within. */
6206 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
6207 lowpc
, highpc
, objfile
);
6209 /* For C++, set the block's scope. */
6210 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
6211 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
6212 determine_prefix (die
, cu
),
6213 processing_has_namespace_info
);
6215 /* If we have address ranges, record them. */
6216 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
6218 /* Attach template arguments to function. */
6219 if (! VEC_empty (symbolp
, template_args
))
6221 gdb_assert (templ_func
!= NULL
);
6223 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
6224 templ_func
->template_arguments
6225 = obstack_alloc (&objfile
->objfile_obstack
,
6226 (templ_func
->n_template_arguments
6227 * sizeof (struct symbol
*)));
6228 memcpy (templ_func
->template_arguments
,
6229 VEC_address (symbolp
, template_args
),
6230 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
6231 VEC_free (symbolp
, template_args
);
6234 /* In C++, we can have functions nested inside functions (e.g., when
6235 a function declares a class that has methods). This means that
6236 when we finish processing a function scope, we may need to go
6237 back to building a containing block's symbol lists. */
6238 local_symbols
= new->locals
;
6239 param_symbols
= new->params
;
6240 using_directives
= new->using_directives
;
6242 /* If we've finished processing a top-level function, subsequent
6243 symbols go in the file symbol list. */
6244 if (outermost_context_p ())
6245 cu
->list_in_scope
= &file_symbols
;
6248 /* Process all the DIES contained within a lexical block scope. Start
6249 a new scope, process the dies, and then close the scope. */
6252 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6254 struct objfile
*objfile
= cu
->objfile
;
6255 struct context_stack
*new;
6256 CORE_ADDR lowpc
, highpc
;
6257 struct die_info
*child_die
;
6260 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6262 /* Ignore blocks with missing or invalid low and high pc attributes. */
6263 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
6264 as multiple lexical blocks? Handling children in a sane way would
6265 be nasty. Might be easier to properly extend generic blocks to
6267 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
6272 push_context (0, lowpc
);
6273 if (die
->child
!= NULL
)
6275 child_die
= die
->child
;
6276 while (child_die
&& child_die
->tag
)
6278 process_die (child_die
, cu
);
6279 child_die
= sibling_die (child_die
);
6282 new = pop_context ();
6284 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
6287 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
6290 /* Note that recording ranges after traversing children, as we
6291 do here, means that recording a parent's ranges entails
6292 walking across all its children's ranges as they appear in
6293 the address map, which is quadratic behavior.
6295 It would be nicer to record the parent's ranges before
6296 traversing its children, simply overriding whatever you find
6297 there. But since we don't even decide whether to create a
6298 block until after we've traversed its children, that's hard
6300 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
6302 local_symbols
= new->locals
;
6303 using_directives
= new->using_directives
;
6306 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
6309 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6311 struct objfile
*objfile
= cu
->objfile
;
6312 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6313 CORE_ADDR pc
, baseaddr
;
6314 struct attribute
*attr
;
6315 struct call_site
*call_site
, call_site_local
;
6318 struct die_info
*child_die
;
6320 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6322 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6325 complaint (&symfile_complaints
,
6326 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
6327 "DIE 0x%x [in module %s]"),
6328 die
->offset
.sect_off
, objfile
->name
);
6331 pc
= DW_ADDR (attr
) + baseaddr
;
6333 if (cu
->call_site_htab
== NULL
)
6334 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
6335 NULL
, &objfile
->objfile_obstack
,
6336 hashtab_obstack_allocate
, NULL
);
6337 call_site_local
.pc
= pc
;
6338 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
6341 complaint (&symfile_complaints
,
6342 _("Duplicate PC %s for DW_TAG_GNU_call_site "
6343 "DIE 0x%x [in module %s]"),
6344 paddress (gdbarch
, pc
), die
->offset
.sect_off
, objfile
->name
);
6348 /* Count parameters at the caller. */
6351 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
6352 child_die
= sibling_die (child_die
))
6354 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
6356 complaint (&symfile_complaints
,
6357 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
6358 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6359 child_die
->tag
, child_die
->offset
.sect_off
, objfile
->name
);
6366 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
6367 (sizeof (*call_site
)
6368 + (sizeof (*call_site
->parameter
)
6371 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
6374 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
6376 struct die_info
*func_die
;
6378 /* Skip also over DW_TAG_inlined_subroutine. */
6379 for (func_die
= die
->parent
;
6380 func_die
&& func_die
->tag
!= DW_TAG_subprogram
6381 && func_die
->tag
!= DW_TAG_subroutine_type
;
6382 func_die
= func_die
->parent
);
6384 /* DW_AT_GNU_all_call_sites is a superset
6385 of DW_AT_GNU_all_tail_call_sites. */
6387 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
6388 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
6390 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
6391 not complete. But keep CALL_SITE for look ups via call_site_htab,
6392 both the initial caller containing the real return address PC and
6393 the final callee containing the current PC of a chain of tail
6394 calls do not need to have the tail call list complete. But any
6395 function candidate for a virtual tail call frame searched via
6396 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
6397 determined unambiguously. */
6401 struct type
*func_type
= NULL
;
6404 func_type
= get_die_type (func_die
, cu
);
6405 if (func_type
!= NULL
)
6407 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
6409 /* Enlist this call site to the function. */
6410 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
6411 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
6414 complaint (&symfile_complaints
,
6415 _("Cannot find function owning DW_TAG_GNU_call_site "
6416 "DIE 0x%x [in module %s]"),
6417 die
->offset
.sect_off
, objfile
->name
);
6421 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
6423 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
6424 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
6425 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
6426 /* Keep NULL DWARF_BLOCK. */;
6427 else if (attr_form_is_block (attr
))
6429 struct dwarf2_locexpr_baton
*dlbaton
;
6431 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
6432 dlbaton
->data
= DW_BLOCK (attr
)->data
;
6433 dlbaton
->size
= DW_BLOCK (attr
)->size
;
6434 dlbaton
->per_cu
= cu
->per_cu
;
6436 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
6438 else if (is_ref_attr (attr
))
6440 struct dwarf2_cu
*target_cu
= cu
;
6441 struct die_info
*target_die
;
6443 target_die
= follow_die_ref_or_sig (die
, attr
, &target_cu
);
6444 gdb_assert (target_cu
->objfile
== objfile
);
6445 if (die_is_declaration (target_die
, target_cu
))
6447 const char *target_physname
;
6449 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
6450 if (target_physname
== NULL
)
6451 complaint (&symfile_complaints
,
6452 _("DW_AT_GNU_call_site_target target DIE has invalid "
6453 "physname, for referencing DIE 0x%x [in module %s]"),
6454 die
->offset
.sect_off
, objfile
->name
);
6456 SET_FIELD_PHYSNAME (call_site
->target
, (char *) target_physname
);
6462 /* DW_AT_entry_pc should be preferred. */
6463 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
6464 complaint (&symfile_complaints
,
6465 _("DW_AT_GNU_call_site_target target DIE has invalid "
6466 "low pc, for referencing DIE 0x%x [in module %s]"),
6467 die
->offset
.sect_off
, objfile
->name
);
6469 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
6473 complaint (&symfile_complaints
,
6474 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
6475 "block nor reference, for DIE 0x%x [in module %s]"),
6476 die
->offset
.sect_off
, objfile
->name
);
6478 call_site
->per_cu
= cu
->per_cu
;
6480 for (child_die
= die
->child
;
6481 child_die
&& child_die
->tag
;
6482 child_die
= sibling_die (child_die
))
6484 struct dwarf2_locexpr_baton
*dlbaton
;
6485 struct call_site_parameter
*parameter
;
6487 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
6489 /* Already printed the complaint above. */
6493 gdb_assert (call_site
->parameter_count
< nparams
);
6494 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
6496 /* DW_AT_location specifies the register number. Value of the data
6497 assumed for the register is contained in DW_AT_GNU_call_site_value. */
6499 attr
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
6500 if (!attr
|| !attr_form_is_block (attr
))
6502 complaint (&symfile_complaints
,
6503 _("No DW_FORM_block* DW_AT_location for "
6504 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6505 child_die
->offset
.sect_off
, objfile
->name
);
6508 parameter
->dwarf_reg
= dwarf_block_to_dwarf_reg (DW_BLOCK (attr
)->data
,
6509 &DW_BLOCK (attr
)->data
[DW_BLOCK (attr
)->size
]);
6510 if (parameter
->dwarf_reg
== -1
6511 && !dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (attr
)->data
,
6512 &DW_BLOCK (attr
)->data
[DW_BLOCK (attr
)->size
],
6513 ¶meter
->fb_offset
))
6515 complaint (&symfile_complaints
,
6516 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
6517 "for DW_FORM_block* DW_AT_location for "
6518 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6519 child_die
->offset
.sect_off
, objfile
->name
);
6523 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
6524 if (!attr_form_is_block (attr
))
6526 complaint (&symfile_complaints
,
6527 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
6528 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6529 child_die
->offset
.sect_off
, objfile
->name
);
6532 parameter
->value
= DW_BLOCK (attr
)->data
;
6533 parameter
->value_size
= DW_BLOCK (attr
)->size
;
6535 /* Parameters are not pre-cleared by memset above. */
6536 parameter
->data_value
= NULL
;
6537 parameter
->data_value_size
= 0;
6538 call_site
->parameter_count
++;
6540 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
6543 if (!attr_form_is_block (attr
))
6544 complaint (&symfile_complaints
,
6545 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
6546 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6547 child_die
->offset
.sect_off
, objfile
->name
);
6550 parameter
->data_value
= DW_BLOCK (attr
)->data
;
6551 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
6557 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
6558 Return 1 if the attributes are present and valid, otherwise, return 0.
6559 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
6562 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
6563 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
6564 struct partial_symtab
*ranges_pst
)
6566 struct objfile
*objfile
= cu
->objfile
;
6567 struct comp_unit_head
*cu_header
= &cu
->header
;
6568 bfd
*obfd
= objfile
->obfd
;
6569 unsigned int addr_size
= cu_header
->addr_size
;
6570 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6571 /* Base address selection entry. */
6582 found_base
= cu
->base_known
;
6583 base
= cu
->base_address
;
6585 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
6586 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6588 complaint (&symfile_complaints
,
6589 _("Offset %d out of bounds for DW_AT_ranges attribute"),
6593 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6595 /* Read in the largest possible address. */
6596 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
6597 if ((marker
& mask
) == mask
)
6599 /* If we found the largest possible address, then
6600 read the base address. */
6601 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
6602 buffer
+= 2 * addr_size
;
6603 offset
+= 2 * addr_size
;
6609 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6613 CORE_ADDR range_beginning
, range_end
;
6615 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
6616 buffer
+= addr_size
;
6617 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
6618 buffer
+= addr_size
;
6619 offset
+= 2 * addr_size
;
6621 /* An end of list marker is a pair of zero addresses. */
6622 if (range_beginning
== 0 && range_end
== 0)
6623 /* Found the end of list entry. */
6626 /* Each base address selection entry is a pair of 2 values.
6627 The first is the largest possible address, the second is
6628 the base address. Check for a base address here. */
6629 if ((range_beginning
& mask
) == mask
)
6631 /* If we found the largest possible address, then
6632 read the base address. */
6633 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
6640 /* We have no valid base address for the ranges
6642 complaint (&symfile_complaints
,
6643 _("Invalid .debug_ranges data (no base address)"));
6647 if (range_beginning
> range_end
)
6649 /* Inverted range entries are invalid. */
6650 complaint (&symfile_complaints
,
6651 _("Invalid .debug_ranges data (inverted range)"));
6655 /* Empty range entries have no effect. */
6656 if (range_beginning
== range_end
)
6659 range_beginning
+= base
;
6662 if (ranges_pst
!= NULL
)
6663 addrmap_set_empty (objfile
->psymtabs_addrmap
,
6664 range_beginning
+ baseaddr
,
6665 range_end
- 1 + baseaddr
,
6668 /* FIXME: This is recording everything as a low-high
6669 segment of consecutive addresses. We should have a
6670 data structure for discontiguous block ranges
6674 low
= range_beginning
;
6680 if (range_beginning
< low
)
6681 low
= range_beginning
;
6682 if (range_end
> high
)
6688 /* If the first entry is an end-of-list marker, the range
6689 describes an empty scope, i.e. no instructions. */
6695 *high_return
= high
;
6699 /* Get low and high pc attributes from a die. Return 1 if the attributes
6700 are present and valid, otherwise, return 0. Return -1 if the range is
6701 discontinuous, i.e. derived from DW_AT_ranges information. */
6704 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
6705 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
6706 struct partial_symtab
*pst
)
6708 struct attribute
*attr
;
6709 struct attribute
*attr_high
;
6714 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6717 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6720 low
= DW_ADDR (attr
);
6721 if (attr_high
->form
== DW_FORM_addr
)
6722 high
= DW_ADDR (attr_high
);
6724 high
= low
+ DW_UNSND (attr_high
);
6727 /* Found high w/o low attribute. */
6730 /* Found consecutive range of addresses. */
6735 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6738 /* Value of the DW_AT_ranges attribute is the offset in the
6739 .debug_ranges section. */
6740 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
6742 /* Found discontinuous range of addresses. */
6747 /* read_partial_die has also the strict LOW < HIGH requirement. */
6751 /* When using the GNU linker, .gnu.linkonce. sections are used to
6752 eliminate duplicate copies of functions and vtables and such.
6753 The linker will arbitrarily choose one and discard the others.
6754 The AT_*_pc values for such functions refer to local labels in
6755 these sections. If the section from that file was discarded, the
6756 labels are not in the output, so the relocs get a value of 0.
6757 If this is a discarded function, mark the pc bounds as invalid,
6758 so that GDB will ignore it. */
6759 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
6768 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
6769 its low and high PC addresses. Do nothing if these addresses could not
6770 be determined. Otherwise, set LOWPC to the low address if it is smaller,
6771 and HIGHPC to the high address if greater than HIGHPC. */
6774 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
6775 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6776 struct dwarf2_cu
*cu
)
6778 CORE_ADDR low
, high
;
6779 struct die_info
*child
= die
->child
;
6781 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
6783 *lowpc
= min (*lowpc
, low
);
6784 *highpc
= max (*highpc
, high
);
6787 /* If the language does not allow nested subprograms (either inside
6788 subprograms or lexical blocks), we're done. */
6789 if (cu
->language
!= language_ada
)
6792 /* Check all the children of the given DIE. If it contains nested
6793 subprograms, then check their pc bounds. Likewise, we need to
6794 check lexical blocks as well, as they may also contain subprogram
6796 while (child
&& child
->tag
)
6798 if (child
->tag
== DW_TAG_subprogram
6799 || child
->tag
== DW_TAG_lexical_block
)
6800 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
6801 child
= sibling_die (child
);
6805 /* Get the low and high pc's represented by the scope DIE, and store
6806 them in *LOWPC and *HIGHPC. If the correct values can't be
6807 determined, set *LOWPC to -1 and *HIGHPC to 0. */
6810 get_scope_pc_bounds (struct die_info
*die
,
6811 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6812 struct dwarf2_cu
*cu
)
6814 CORE_ADDR best_low
= (CORE_ADDR
) -1;
6815 CORE_ADDR best_high
= (CORE_ADDR
) 0;
6816 CORE_ADDR current_low
, current_high
;
6818 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
6820 best_low
= current_low
;
6821 best_high
= current_high
;
6825 struct die_info
*child
= die
->child
;
6827 while (child
&& child
->tag
)
6829 switch (child
->tag
) {
6830 case DW_TAG_subprogram
:
6831 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
6833 case DW_TAG_namespace
:
6835 /* FIXME: carlton/2004-01-16: Should we do this for
6836 DW_TAG_class_type/DW_TAG_structure_type, too? I think
6837 that current GCC's always emit the DIEs corresponding
6838 to definitions of methods of classes as children of a
6839 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
6840 the DIEs giving the declarations, which could be
6841 anywhere). But I don't see any reason why the
6842 standards says that they have to be there. */
6843 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
6845 if (current_low
!= ((CORE_ADDR
) -1))
6847 best_low
= min (best_low
, current_low
);
6848 best_high
= max (best_high
, current_high
);
6856 child
= sibling_die (child
);
6861 *highpc
= best_high
;
6864 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
6868 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
6869 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
6871 struct objfile
*objfile
= cu
->objfile
;
6872 struct attribute
*attr
;
6873 struct attribute
*attr_high
;
6875 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6878 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6881 CORE_ADDR low
= DW_ADDR (attr
);
6883 if (attr_high
->form
== DW_FORM_addr
)
6884 high
= DW_ADDR (attr_high
);
6886 high
= low
+ DW_UNSND (attr_high
);
6888 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
6892 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6895 bfd
*obfd
= objfile
->obfd
;
6897 /* The value of the DW_AT_ranges attribute is the offset of the
6898 address range list in the .debug_ranges section. */
6899 unsigned long offset
= DW_UNSND (attr
);
6900 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6902 /* For some target architectures, but not others, the
6903 read_address function sign-extends the addresses it returns.
6904 To recognize base address selection entries, we need a
6906 unsigned int addr_size
= cu
->header
.addr_size
;
6907 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6909 /* The base address, to which the next pair is relative. Note
6910 that this 'base' is a DWARF concept: most entries in a range
6911 list are relative, to reduce the number of relocs against the
6912 debugging information. This is separate from this function's
6913 'baseaddr' argument, which GDB uses to relocate debugging
6914 information from a shared library based on the address at
6915 which the library was loaded. */
6916 CORE_ADDR base
= cu
->base_address
;
6917 int base_known
= cu
->base_known
;
6919 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
6920 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6922 complaint (&symfile_complaints
,
6923 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
6930 unsigned int bytes_read
;
6931 CORE_ADDR start
, end
;
6933 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6934 buffer
+= bytes_read
;
6935 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6936 buffer
+= bytes_read
;
6938 /* Did we find the end of the range list? */
6939 if (start
== 0 && end
== 0)
6942 /* Did we find a base address selection entry? */
6943 else if ((start
& base_select_mask
) == base_select_mask
)
6949 /* We found an ordinary address range. */
6954 complaint (&symfile_complaints
,
6955 _("Invalid .debug_ranges data "
6956 "(no base address)"));
6962 /* Inverted range entries are invalid. */
6963 complaint (&symfile_complaints
,
6964 _("Invalid .debug_ranges data "
6965 "(inverted range)"));
6969 /* Empty range entries have no effect. */
6973 record_block_range (block
,
6974 baseaddr
+ base
+ start
,
6975 baseaddr
+ base
+ end
- 1);
6981 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
6982 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
6983 during 4.6.0 experimental. */
6986 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
6989 int major
, minor
, release
;
6992 if (cu
->producer
== NULL
)
6994 /* For unknown compilers expect their behavior is DWARF version
6997 GCC started to support .debug_types sections by -gdwarf-4 since
6998 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
6999 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
7000 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
7001 interpreted incorrectly by GDB now - GCC PR debug/48229. */
7006 if (cu
->checked_producer
)
7007 return cu
->producer_is_gxx_lt_4_6
;
7009 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
7011 if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) != 0)
7013 /* For non-GCC compilers expect their behavior is DWARF version
7018 cs
= &cu
->producer
[strlen ("GNU ")];
7019 while (*cs
&& !isdigit (*cs
))
7021 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
7023 /* Not recognized as GCC. */
7026 result
= major
< 4 || (major
== 4 && minor
< 6);
7029 cu
->checked_producer
= 1;
7030 cu
->producer_is_gxx_lt_4_6
= result
;
7035 /* Return the default accessibility type if it is not overriden by
7036 DW_AT_accessibility. */
7038 static enum dwarf_access_attribute
7039 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
7041 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
7043 /* The default DWARF 2 accessibility for members is public, the default
7044 accessibility for inheritance is private. */
7046 if (die
->tag
!= DW_TAG_inheritance
)
7047 return DW_ACCESS_public
;
7049 return DW_ACCESS_private
;
7053 /* DWARF 3+ defines the default accessibility a different way. The same
7054 rules apply now for DW_TAG_inheritance as for the members and it only
7055 depends on the container kind. */
7057 if (die
->parent
->tag
== DW_TAG_class_type
)
7058 return DW_ACCESS_private
;
7060 return DW_ACCESS_public
;
7064 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
7065 offset. If the attribute was not found return 0, otherwise return
7066 1. If it was found but could not properly be handled, set *OFFSET
7070 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
7073 struct attribute
*attr
;
7075 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
7080 /* Note that we do not check for a section offset first here.
7081 This is because DW_AT_data_member_location is new in DWARF 4,
7082 so if we see it, we can assume that a constant form is really
7083 a constant and not a section offset. */
7084 if (attr_form_is_constant (attr
))
7085 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
7086 else if (attr_form_is_section_offset (attr
))
7087 dwarf2_complex_location_expr_complaint ();
7088 else if (attr_form_is_block (attr
))
7089 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
7091 dwarf2_complex_location_expr_complaint ();
7099 /* Add an aggregate field to the field list. */
7102 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
7103 struct dwarf2_cu
*cu
)
7105 struct objfile
*objfile
= cu
->objfile
;
7106 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7107 struct nextfield
*new_field
;
7108 struct attribute
*attr
;
7110 char *fieldname
= "";
7112 /* Allocate a new field list entry and link it in. */
7113 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
7114 make_cleanup (xfree
, new_field
);
7115 memset (new_field
, 0, sizeof (struct nextfield
));
7117 if (die
->tag
== DW_TAG_inheritance
)
7119 new_field
->next
= fip
->baseclasses
;
7120 fip
->baseclasses
= new_field
;
7124 new_field
->next
= fip
->fields
;
7125 fip
->fields
= new_field
;
7129 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
7131 new_field
->accessibility
= DW_UNSND (attr
);
7133 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
7134 if (new_field
->accessibility
!= DW_ACCESS_public
)
7135 fip
->non_public_fields
= 1;
7137 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
7139 new_field
->virtuality
= DW_UNSND (attr
);
7141 new_field
->virtuality
= DW_VIRTUALITY_none
;
7143 fp
= &new_field
->field
;
7145 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
7149 /* Data member other than a C++ static data member. */
7151 /* Get type of field. */
7152 fp
->type
= die_type (die
, cu
);
7154 SET_FIELD_BITPOS (*fp
, 0);
7156 /* Get bit size of field (zero if none). */
7157 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
7160 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
7164 FIELD_BITSIZE (*fp
) = 0;
7167 /* Get bit offset of field. */
7168 if (handle_data_member_location (die
, cu
, &offset
))
7169 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
7170 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
7173 if (gdbarch_bits_big_endian (gdbarch
))
7175 /* For big endian bits, the DW_AT_bit_offset gives the
7176 additional bit offset from the MSB of the containing
7177 anonymous object to the MSB of the field. We don't
7178 have to do anything special since we don't need to
7179 know the size of the anonymous object. */
7180 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
7184 /* For little endian bits, compute the bit offset to the
7185 MSB of the anonymous object, subtract off the number of
7186 bits from the MSB of the field to the MSB of the
7187 object, and then subtract off the number of bits of
7188 the field itself. The result is the bit offset of
7189 the LSB of the field. */
7191 int bit_offset
= DW_UNSND (attr
);
7193 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7196 /* The size of the anonymous object containing
7197 the bit field is explicit, so use the
7198 indicated size (in bytes). */
7199 anonymous_size
= DW_UNSND (attr
);
7203 /* The size of the anonymous object containing
7204 the bit field must be inferred from the type
7205 attribute of the data member containing the
7207 anonymous_size
= TYPE_LENGTH (fp
->type
);
7209 SET_FIELD_BITPOS (*fp
,
7211 + anonymous_size
* bits_per_byte
7212 - bit_offset
- FIELD_BITSIZE (*fp
)));
7216 /* Get name of field. */
7217 fieldname
= dwarf2_name (die
, cu
);
7218 if (fieldname
== NULL
)
7221 /* The name is already allocated along with this objfile, so we don't
7222 need to duplicate it for the type. */
7223 fp
->name
= fieldname
;
7225 /* Change accessibility for artificial fields (e.g. virtual table
7226 pointer or virtual base class pointer) to private. */
7227 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
7229 FIELD_ARTIFICIAL (*fp
) = 1;
7230 new_field
->accessibility
= DW_ACCESS_private
;
7231 fip
->non_public_fields
= 1;
7234 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
7236 /* C++ static member. */
7238 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
7239 is a declaration, but all versions of G++ as of this writing
7240 (so through at least 3.2.1) incorrectly generate
7241 DW_TAG_variable tags. */
7243 const char *physname
;
7245 /* Get name of field. */
7246 fieldname
= dwarf2_name (die
, cu
);
7247 if (fieldname
== NULL
)
7250 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7252 /* Only create a symbol if this is an external value.
7253 new_symbol checks this and puts the value in the global symbol
7254 table, which we want. If it is not external, new_symbol
7255 will try to put the value in cu->list_in_scope which is wrong. */
7256 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
7258 /* A static const member, not much different than an enum as far as
7259 we're concerned, except that we can support more types. */
7260 new_symbol (die
, NULL
, cu
);
7263 /* Get physical name. */
7264 physname
= dwarf2_physname (fieldname
, die
, cu
);
7266 /* The name is already allocated along with this objfile, so we don't
7267 need to duplicate it for the type. */
7268 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
7269 FIELD_TYPE (*fp
) = die_type (die
, cu
);
7270 FIELD_NAME (*fp
) = fieldname
;
7272 else if (die
->tag
== DW_TAG_inheritance
)
7276 /* C++ base class field. */
7277 if (handle_data_member_location (die
, cu
, &offset
))
7278 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
7279 FIELD_BITSIZE (*fp
) = 0;
7280 FIELD_TYPE (*fp
) = die_type (die
, cu
);
7281 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
7282 fip
->nbaseclasses
++;
7286 /* Add a typedef defined in the scope of the FIP's class. */
7289 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
7290 struct dwarf2_cu
*cu
)
7292 struct objfile
*objfile
= cu
->objfile
;
7293 struct typedef_field_list
*new_field
;
7294 struct attribute
*attr
;
7295 struct typedef_field
*fp
;
7296 char *fieldname
= "";
7298 /* Allocate a new field list entry and link it in. */
7299 new_field
= xzalloc (sizeof (*new_field
));
7300 make_cleanup (xfree
, new_field
);
7302 gdb_assert (die
->tag
== DW_TAG_typedef
);
7304 fp
= &new_field
->field
;
7306 /* Get name of field. */
7307 fp
->name
= dwarf2_name (die
, cu
);
7308 if (fp
->name
== NULL
)
7311 fp
->type
= read_type_die (die
, cu
);
7313 new_field
->next
= fip
->typedef_field_list
;
7314 fip
->typedef_field_list
= new_field
;
7315 fip
->typedef_field_list_count
++;
7318 /* Create the vector of fields, and attach it to the type. */
7321 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
7322 struct dwarf2_cu
*cu
)
7324 int nfields
= fip
->nfields
;
7326 /* Record the field count, allocate space for the array of fields,
7327 and create blank accessibility bitfields if necessary. */
7328 TYPE_NFIELDS (type
) = nfields
;
7329 TYPE_FIELDS (type
) = (struct field
*)
7330 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
7331 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
7333 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
7335 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7337 TYPE_FIELD_PRIVATE_BITS (type
) =
7338 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7339 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
7341 TYPE_FIELD_PROTECTED_BITS (type
) =
7342 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7343 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
7345 TYPE_FIELD_IGNORE_BITS (type
) =
7346 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7347 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
7350 /* If the type has baseclasses, allocate and clear a bit vector for
7351 TYPE_FIELD_VIRTUAL_BITS. */
7352 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
7354 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
7355 unsigned char *pointer
;
7357 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7358 pointer
= TYPE_ALLOC (type
, num_bytes
);
7359 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
7360 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
7361 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
7364 /* Copy the saved-up fields into the field vector. Start from the head of
7365 the list, adding to the tail of the field array, so that they end up in
7366 the same order in the array in which they were added to the list. */
7367 while (nfields
-- > 0)
7369 struct nextfield
*fieldp
;
7373 fieldp
= fip
->fields
;
7374 fip
->fields
= fieldp
->next
;
7378 fieldp
= fip
->baseclasses
;
7379 fip
->baseclasses
= fieldp
->next
;
7382 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
7383 switch (fieldp
->accessibility
)
7385 case DW_ACCESS_private
:
7386 if (cu
->language
!= language_ada
)
7387 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
7390 case DW_ACCESS_protected
:
7391 if (cu
->language
!= language_ada
)
7392 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
7395 case DW_ACCESS_public
:
7399 /* Unknown accessibility. Complain and treat it as public. */
7401 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
7402 fieldp
->accessibility
);
7406 if (nfields
< fip
->nbaseclasses
)
7408 switch (fieldp
->virtuality
)
7410 case DW_VIRTUALITY_virtual
:
7411 case DW_VIRTUALITY_pure_virtual
:
7412 if (cu
->language
== language_ada
)
7413 error (_("unexpected virtuality in component of Ada type"));
7414 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
7421 /* Add a member function to the proper fieldlist. */
7424 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
7425 struct type
*type
, struct dwarf2_cu
*cu
)
7427 struct objfile
*objfile
= cu
->objfile
;
7428 struct attribute
*attr
;
7429 struct fnfieldlist
*flp
;
7431 struct fn_field
*fnp
;
7433 struct nextfnfield
*new_fnfield
;
7434 struct type
*this_type
;
7435 enum dwarf_access_attribute accessibility
;
7437 if (cu
->language
== language_ada
)
7438 error (_("unexpected member function in Ada type"));
7440 /* Get name of member function. */
7441 fieldname
= dwarf2_name (die
, cu
);
7442 if (fieldname
== NULL
)
7445 /* Look up member function name in fieldlist. */
7446 for (i
= 0; i
< fip
->nfnfields
; i
++)
7448 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
7452 /* Create new list element if necessary. */
7453 if (i
< fip
->nfnfields
)
7454 flp
= &fip
->fnfieldlists
[i
];
7457 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7459 fip
->fnfieldlists
= (struct fnfieldlist
*)
7460 xrealloc (fip
->fnfieldlists
,
7461 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
7462 * sizeof (struct fnfieldlist
));
7463 if (fip
->nfnfields
== 0)
7464 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
7466 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
7467 flp
->name
= fieldname
;
7470 i
= fip
->nfnfields
++;
7473 /* Create a new member function field and chain it to the field list
7475 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
7476 make_cleanup (xfree
, new_fnfield
);
7477 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
7478 new_fnfield
->next
= flp
->head
;
7479 flp
->head
= new_fnfield
;
7482 /* Fill in the member function field info. */
7483 fnp
= &new_fnfield
->fnfield
;
7485 /* Delay processing of the physname until later. */
7486 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
7488 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
7493 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
7494 fnp
->physname
= physname
? physname
: "";
7497 fnp
->type
= alloc_type (objfile
);
7498 this_type
= read_type_die (die
, cu
);
7499 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
7501 int nparams
= TYPE_NFIELDS (this_type
);
7503 /* TYPE is the domain of this method, and THIS_TYPE is the type
7504 of the method itself (TYPE_CODE_METHOD). */
7505 smash_to_method_type (fnp
->type
, type
,
7506 TYPE_TARGET_TYPE (this_type
),
7507 TYPE_FIELDS (this_type
),
7508 TYPE_NFIELDS (this_type
),
7509 TYPE_VARARGS (this_type
));
7511 /* Handle static member functions.
7512 Dwarf2 has no clean way to discern C++ static and non-static
7513 member functions. G++ helps GDB by marking the first
7514 parameter for non-static member functions (which is the this
7515 pointer) as artificial. We obtain this information from
7516 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
7517 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
7518 fnp
->voffset
= VOFFSET_STATIC
;
7521 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
7522 dwarf2_full_name (fieldname
, die
, cu
));
7524 /* Get fcontext from DW_AT_containing_type if present. */
7525 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7526 fnp
->fcontext
= die_containing_type (die
, cu
);
7528 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
7529 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
7531 /* Get accessibility. */
7532 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
7534 accessibility
= DW_UNSND (attr
);
7536 accessibility
= dwarf2_default_access_attribute (die
, cu
);
7537 switch (accessibility
)
7539 case DW_ACCESS_private
:
7540 fnp
->is_private
= 1;
7542 case DW_ACCESS_protected
:
7543 fnp
->is_protected
= 1;
7547 /* Check for artificial methods. */
7548 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
7549 if (attr
&& DW_UNSND (attr
) != 0)
7550 fnp
->is_artificial
= 1;
7552 /* Get index in virtual function table if it is a virtual member
7553 function. For older versions of GCC, this is an offset in the
7554 appropriate virtual table, as specified by DW_AT_containing_type.
7555 For everyone else, it is an expression to be evaluated relative
7556 to the object address. */
7558 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
7561 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
7563 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
7565 /* Old-style GCC. */
7566 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
7568 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
7569 || (DW_BLOCK (attr
)->size
> 1
7570 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
7571 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
7573 struct dwarf_block blk
;
7576 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
7578 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
7579 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
7580 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
7581 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
7582 dwarf2_complex_location_expr_complaint ();
7584 fnp
->voffset
/= cu
->header
.addr_size
;
7588 dwarf2_complex_location_expr_complaint ();
7591 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
7593 else if (attr_form_is_section_offset (attr
))
7595 dwarf2_complex_location_expr_complaint ();
7599 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
7605 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
7606 if (attr
&& DW_UNSND (attr
))
7608 /* GCC does this, as of 2008-08-25; PR debug/37237. */
7609 complaint (&symfile_complaints
,
7610 _("Member function \"%s\" (offset %d) is virtual "
7611 "but the vtable offset is not specified"),
7612 fieldname
, die
->offset
.sect_off
);
7613 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7614 TYPE_CPLUS_DYNAMIC (type
) = 1;
7619 /* Create the vector of member function fields, and attach it to the type. */
7622 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
7623 struct dwarf2_cu
*cu
)
7625 struct fnfieldlist
*flp
;
7628 if (cu
->language
== language_ada
)
7629 error (_("unexpected member functions in Ada type"));
7631 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7632 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
7633 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
7635 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
7637 struct nextfnfield
*nfp
= flp
->head
;
7638 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
7641 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
7642 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
7643 fn_flp
->fn_fields
= (struct fn_field
*)
7644 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
7645 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
7646 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
7649 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
7652 /* Returns non-zero if NAME is the name of a vtable member in CU's
7653 language, zero otherwise. */
7655 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
7657 static const char vptr
[] = "_vptr";
7658 static const char vtable
[] = "vtable";
7660 /* Look for the C++ and Java forms of the vtable. */
7661 if ((cu
->language
== language_java
7662 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
7663 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
7664 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
7670 /* GCC outputs unnamed structures that are really pointers to member
7671 functions, with the ABI-specified layout. If TYPE describes
7672 such a structure, smash it into a member function type.
7674 GCC shouldn't do this; it should just output pointer to member DIEs.
7675 This is GCC PR debug/28767. */
7678 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
7680 struct type
*pfn_type
, *domain_type
, *new_type
;
7682 /* Check for a structure with no name and two children. */
7683 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
7686 /* Check for __pfn and __delta members. */
7687 if (TYPE_FIELD_NAME (type
, 0) == NULL
7688 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
7689 || TYPE_FIELD_NAME (type
, 1) == NULL
7690 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
7693 /* Find the type of the method. */
7694 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
7695 if (pfn_type
== NULL
7696 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
7697 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
7700 /* Look for the "this" argument. */
7701 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
7702 if (TYPE_NFIELDS (pfn_type
) == 0
7703 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
7704 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
7707 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
7708 new_type
= alloc_type (objfile
);
7709 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
7710 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
7711 TYPE_VARARGS (pfn_type
));
7712 smash_to_methodptr_type (type
, new_type
);
7715 /* Called when we find the DIE that starts a structure or union scope
7716 (definition) to create a type for the structure or union. Fill in
7717 the type's name and general properties; the members will not be
7718 processed until process_structure_type.
7720 NOTE: we need to call these functions regardless of whether or not the
7721 DIE has a DW_AT_name attribute, since it might be an anonymous
7722 structure or union. This gets the type entered into our set of
7725 However, if the structure is incomplete (an opaque struct/union)
7726 then suppress creating a symbol table entry for it since gdb only
7727 wants to find the one with the complete definition. Note that if
7728 it is complete, we just call new_symbol, which does it's own
7729 checking about whether the struct/union is anonymous or not (and
7730 suppresses creating a symbol table entry itself). */
7732 static struct type
*
7733 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7735 struct objfile
*objfile
= cu
->objfile
;
7737 struct attribute
*attr
;
7740 /* If the definition of this type lives in .debug_types, read that type.
7741 Don't follow DW_AT_specification though, that will take us back up
7742 the chain and we want to go down. */
7743 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7746 struct dwarf2_cu
*type_cu
= cu
;
7747 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7749 /* We could just recurse on read_structure_type, but we need to call
7750 get_die_type to ensure only one type for this DIE is created.
7751 This is important, for example, because for c++ classes we need
7752 TYPE_NAME set which is only done by new_symbol. Blech. */
7753 type
= read_type_die (type_die
, type_cu
);
7755 /* TYPE_CU may not be the same as CU.
7756 Ensure TYPE is recorded in CU's type_hash table. */
7757 return set_die_type (die
, type
, cu
);
7760 type
= alloc_type (objfile
);
7761 INIT_CPLUS_SPECIFIC (type
);
7763 name
= dwarf2_name (die
, cu
);
7766 if (cu
->language
== language_cplus
7767 || cu
->language
== language_java
)
7769 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
7771 /* dwarf2_full_name might have already finished building the DIE's
7772 type. If so, there is no need to continue. */
7773 if (get_die_type (die
, cu
) != NULL
)
7774 return get_die_type (die
, cu
);
7776 TYPE_TAG_NAME (type
) = full_name
;
7777 if (die
->tag
== DW_TAG_structure_type
7778 || die
->tag
== DW_TAG_class_type
)
7779 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7783 /* The name is already allocated along with this objfile, so
7784 we don't need to duplicate it for the type. */
7785 TYPE_TAG_NAME (type
) = (char *) name
;
7786 if (die
->tag
== DW_TAG_class_type
)
7787 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7791 if (die
->tag
== DW_TAG_structure_type
)
7793 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
7795 else if (die
->tag
== DW_TAG_union_type
)
7797 TYPE_CODE (type
) = TYPE_CODE_UNION
;
7801 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
7804 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
7805 TYPE_DECLARED_CLASS (type
) = 1;
7807 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7810 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7814 TYPE_LENGTH (type
) = 0;
7817 TYPE_STUB_SUPPORTED (type
) = 1;
7818 if (die_is_declaration (die
, cu
))
7819 TYPE_STUB (type
) = 1;
7820 else if (attr
== NULL
&& die
->child
== NULL
7821 && producer_is_realview (cu
->producer
))
7822 /* RealView does not output the required DW_AT_declaration
7823 on incomplete types. */
7824 TYPE_STUB (type
) = 1;
7826 /* We need to add the type field to the die immediately so we don't
7827 infinitely recurse when dealing with pointers to the structure
7828 type within the structure itself. */
7829 set_die_type (die
, type
, cu
);
7831 /* set_die_type should be already done. */
7832 set_descriptive_type (type
, die
, cu
);
7837 /* Finish creating a structure or union type, including filling in
7838 its members and creating a symbol for it. */
7841 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7843 struct objfile
*objfile
= cu
->objfile
;
7844 struct die_info
*child_die
= die
->child
;
7847 type
= get_die_type (die
, cu
);
7849 type
= read_structure_type (die
, cu
);
7851 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
7853 struct field_info fi
;
7854 struct die_info
*child_die
;
7855 VEC (symbolp
) *template_args
= NULL
;
7856 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
7858 memset (&fi
, 0, sizeof (struct field_info
));
7860 child_die
= die
->child
;
7862 while (child_die
&& child_die
->tag
)
7864 if (child_die
->tag
== DW_TAG_member
7865 || child_die
->tag
== DW_TAG_variable
)
7867 /* NOTE: carlton/2002-11-05: A C++ static data member
7868 should be a DW_TAG_member that is a declaration, but
7869 all versions of G++ as of this writing (so through at
7870 least 3.2.1) incorrectly generate DW_TAG_variable
7871 tags for them instead. */
7872 dwarf2_add_field (&fi
, child_die
, cu
);
7874 else if (child_die
->tag
== DW_TAG_subprogram
)
7876 /* C++ member function. */
7877 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
7879 else if (child_die
->tag
== DW_TAG_inheritance
)
7881 /* C++ base class field. */
7882 dwarf2_add_field (&fi
, child_die
, cu
);
7884 else if (child_die
->tag
== DW_TAG_typedef
)
7885 dwarf2_add_typedef (&fi
, child_die
, cu
);
7886 else if (child_die
->tag
== DW_TAG_template_type_param
7887 || child_die
->tag
== DW_TAG_template_value_param
)
7889 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
7892 VEC_safe_push (symbolp
, template_args
, arg
);
7895 child_die
= sibling_die (child_die
);
7898 /* Attach template arguments to type. */
7899 if (! VEC_empty (symbolp
, template_args
))
7901 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7902 TYPE_N_TEMPLATE_ARGUMENTS (type
)
7903 = VEC_length (symbolp
, template_args
);
7904 TYPE_TEMPLATE_ARGUMENTS (type
)
7905 = obstack_alloc (&objfile
->objfile_obstack
,
7906 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7907 * sizeof (struct symbol
*)));
7908 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
7909 VEC_address (symbolp
, template_args
),
7910 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7911 * sizeof (struct symbol
*)));
7912 VEC_free (symbolp
, template_args
);
7915 /* Attach fields and member functions to the type. */
7917 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
7920 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
7922 /* Get the type which refers to the base class (possibly this
7923 class itself) which contains the vtable pointer for the current
7924 class from the DW_AT_containing_type attribute. This use of
7925 DW_AT_containing_type is a GNU extension. */
7927 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7929 struct type
*t
= die_containing_type (die
, cu
);
7931 TYPE_VPTR_BASETYPE (type
) = t
;
7936 /* Our own class provides vtbl ptr. */
7937 for (i
= TYPE_NFIELDS (t
) - 1;
7938 i
>= TYPE_N_BASECLASSES (t
);
7941 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
7943 if (is_vtable_name (fieldname
, cu
))
7945 TYPE_VPTR_FIELDNO (type
) = i
;
7950 /* Complain if virtual function table field not found. */
7951 if (i
< TYPE_N_BASECLASSES (t
))
7952 complaint (&symfile_complaints
,
7953 _("virtual function table pointer "
7954 "not found when defining class '%s'"),
7955 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
7960 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
7963 else if (cu
->producer
7964 && strncmp (cu
->producer
,
7965 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
7967 /* The IBM XLC compiler does not provide direct indication
7968 of the containing type, but the vtable pointer is
7969 always named __vfp. */
7973 for (i
= TYPE_NFIELDS (type
) - 1;
7974 i
>= TYPE_N_BASECLASSES (type
);
7977 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
7979 TYPE_VPTR_FIELDNO (type
) = i
;
7980 TYPE_VPTR_BASETYPE (type
) = type
;
7987 /* Copy fi.typedef_field_list linked list elements content into the
7988 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
7989 if (fi
.typedef_field_list
)
7991 int i
= fi
.typedef_field_list_count
;
7993 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7994 TYPE_TYPEDEF_FIELD_ARRAY (type
)
7995 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
7996 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
7998 /* Reverse the list order to keep the debug info elements order. */
8001 struct typedef_field
*dest
, *src
;
8003 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
8004 src
= &fi
.typedef_field_list
->field
;
8005 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
8010 do_cleanups (back_to
);
8012 if (HAVE_CPLUS_STRUCT (type
))
8013 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
8016 quirk_gcc_member_function_pointer (type
, objfile
);
8018 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
8019 snapshots) has been known to create a die giving a declaration
8020 for a class that has, as a child, a die giving a definition for a
8021 nested class. So we have to process our children even if the
8022 current die is a declaration. Normally, of course, a declaration
8023 won't have any children at all. */
8025 while (child_die
!= NULL
&& child_die
->tag
)
8027 if (child_die
->tag
== DW_TAG_member
8028 || child_die
->tag
== DW_TAG_variable
8029 || child_die
->tag
== DW_TAG_inheritance
8030 || child_die
->tag
== DW_TAG_template_value_param
8031 || child_die
->tag
== DW_TAG_template_type_param
)
8036 process_die (child_die
, cu
);
8038 child_die
= sibling_die (child_die
);
8041 /* Do not consider external references. According to the DWARF standard,
8042 these DIEs are identified by the fact that they have no byte_size
8043 attribute, and a declaration attribute. */
8044 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
8045 || !die_is_declaration (die
, cu
))
8046 new_symbol (die
, type
, cu
);
8049 /* Given a DW_AT_enumeration_type die, set its type. We do not
8050 complete the type's fields yet, or create any symbols. */
8052 static struct type
*
8053 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8055 struct objfile
*objfile
= cu
->objfile
;
8057 struct attribute
*attr
;
8060 /* If the definition of this type lives in .debug_types, read that type.
8061 Don't follow DW_AT_specification though, that will take us back up
8062 the chain and we want to go down. */
8063 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
8066 struct dwarf2_cu
*type_cu
= cu
;
8067 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
8069 type
= read_type_die (type_die
, type_cu
);
8071 /* TYPE_CU may not be the same as CU.
8072 Ensure TYPE is recorded in CU's type_hash table. */
8073 return set_die_type (die
, type
, cu
);
8076 type
= alloc_type (objfile
);
8078 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
8079 name
= dwarf2_full_name (NULL
, die
, cu
);
8081 TYPE_TAG_NAME (type
) = (char *) name
;
8083 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8086 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8090 TYPE_LENGTH (type
) = 0;
8093 /* The enumeration DIE can be incomplete. In Ada, any type can be
8094 declared as private in the package spec, and then defined only
8095 inside the package body. Such types are known as Taft Amendment
8096 Types. When another package uses such a type, an incomplete DIE
8097 may be generated by the compiler. */
8098 if (die_is_declaration (die
, cu
))
8099 TYPE_STUB (type
) = 1;
8101 return set_die_type (die
, type
, cu
);
8104 /* Given a pointer to a die which begins an enumeration, process all
8105 the dies that define the members of the enumeration, and create the
8106 symbol for the enumeration type.
8108 NOTE: We reverse the order of the element list. */
8111 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8113 struct type
*this_type
;
8115 this_type
= get_die_type (die
, cu
);
8116 if (this_type
== NULL
)
8117 this_type
= read_enumeration_type (die
, cu
);
8119 if (die
->child
!= NULL
)
8121 struct die_info
*child_die
;
8123 struct field
*fields
= NULL
;
8125 int unsigned_enum
= 1;
8130 child_die
= die
->child
;
8131 while (child_die
&& child_die
->tag
)
8133 if (child_die
->tag
!= DW_TAG_enumerator
)
8135 process_die (child_die
, cu
);
8139 name
= dwarf2_name (child_die
, cu
);
8142 sym
= new_symbol (child_die
, this_type
, cu
);
8143 if (SYMBOL_VALUE (sym
) < 0)
8148 else if ((mask
& SYMBOL_VALUE (sym
)) != 0)
8151 mask
|= SYMBOL_VALUE (sym
);
8153 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
8155 fields
= (struct field
*)
8157 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
8158 * sizeof (struct field
));
8161 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
8162 FIELD_TYPE (fields
[num_fields
]) = NULL
;
8163 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
8164 FIELD_BITSIZE (fields
[num_fields
]) = 0;
8170 child_die
= sibling_die (child_die
);
8175 TYPE_NFIELDS (this_type
) = num_fields
;
8176 TYPE_FIELDS (this_type
) = (struct field
*)
8177 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
8178 memcpy (TYPE_FIELDS (this_type
), fields
,
8179 sizeof (struct field
) * num_fields
);
8183 TYPE_UNSIGNED (this_type
) = 1;
8185 TYPE_FLAG_ENUM (this_type
) = 1;
8188 /* If we are reading an enum from a .debug_types unit, and the enum
8189 is a declaration, and the enum is not the signatured type in the
8190 unit, then we do not want to add a symbol for it. Adding a
8191 symbol would in some cases obscure the true definition of the
8192 enum, giving users an incomplete type when the definition is
8193 actually available. Note that we do not want to do this for all
8194 enums which are just declarations, because C++0x allows forward
8195 enum declarations. */
8196 if (cu
->per_cu
->debug_types_section
8197 && die_is_declaration (die
, cu
))
8199 struct signatured_type
*sig_type
;
8202 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
8203 cu
->per_cu
->debug_types_section
,
8204 cu
->per_cu
->offset
);
8205 if (sig_type
->per_cu
.offset
.sect_off
+ sig_type
->type_offset
.cu_off
8206 != die
->offset
.sect_off
)
8210 new_symbol (die
, this_type
, cu
);
8213 /* Extract all information from a DW_TAG_array_type DIE and put it in
8214 the DIE's type field. For now, this only handles one dimensional
8217 static struct type
*
8218 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8220 struct objfile
*objfile
= cu
->objfile
;
8221 struct die_info
*child_die
;
8223 struct type
*element_type
, *range_type
, *index_type
;
8224 struct type
**range_types
= NULL
;
8225 struct attribute
*attr
;
8227 struct cleanup
*back_to
;
8230 element_type
= die_type (die
, cu
);
8232 /* The die_type call above may have already set the type for this DIE. */
8233 type
= get_die_type (die
, cu
);
8237 /* Irix 6.2 native cc creates array types without children for
8238 arrays with unspecified length. */
8239 if (die
->child
== NULL
)
8241 index_type
= objfile_type (objfile
)->builtin_int
;
8242 range_type
= create_range_type (NULL
, index_type
, 0, -1);
8243 type
= create_array_type (NULL
, element_type
, range_type
);
8244 return set_die_type (die
, type
, cu
);
8247 back_to
= make_cleanup (null_cleanup
, NULL
);
8248 child_die
= die
->child
;
8249 while (child_die
&& child_die
->tag
)
8251 if (child_die
->tag
== DW_TAG_subrange_type
)
8253 struct type
*child_type
= read_type_die (child_die
, cu
);
8255 if (child_type
!= NULL
)
8257 /* The range type was succesfully read. Save it for the
8258 array type creation. */
8259 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
8261 range_types
= (struct type
**)
8262 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
8263 * sizeof (struct type
*));
8265 make_cleanup (free_current_contents
, &range_types
);
8267 range_types
[ndim
++] = child_type
;
8270 child_die
= sibling_die (child_die
);
8273 /* Dwarf2 dimensions are output from left to right, create the
8274 necessary array types in backwards order. */
8276 type
= element_type
;
8278 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
8283 type
= create_array_type (NULL
, type
, range_types
[i
++]);
8288 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
8291 /* Understand Dwarf2 support for vector types (like they occur on
8292 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
8293 array type. This is not part of the Dwarf2/3 standard yet, but a
8294 custom vendor extension. The main difference between a regular
8295 array and the vector variant is that vectors are passed by value
8297 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
8299 make_vector_type (type
);
8301 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
8302 implementation may choose to implement triple vectors using this
8304 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8307 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
8308 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8310 complaint (&symfile_complaints
,
8311 _("DW_AT_byte_size for array type smaller "
8312 "than the total size of elements"));
8315 name
= dwarf2_name (die
, cu
);
8317 TYPE_NAME (type
) = name
;
8319 /* Install the type in the die. */
8320 set_die_type (die
, type
, cu
);
8322 /* set_die_type should be already done. */
8323 set_descriptive_type (type
, die
, cu
);
8325 do_cleanups (back_to
);
8330 static enum dwarf_array_dim_ordering
8331 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
8333 struct attribute
*attr
;
8335 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
8337 if (attr
) return DW_SND (attr
);
8339 /* GNU F77 is a special case, as at 08/2004 array type info is the
8340 opposite order to the dwarf2 specification, but data is still
8341 laid out as per normal fortran.
8343 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
8344 version checking. */
8346 if (cu
->language
== language_fortran
8347 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
8349 return DW_ORD_row_major
;
8352 switch (cu
->language_defn
->la_array_ordering
)
8354 case array_column_major
:
8355 return DW_ORD_col_major
;
8356 case array_row_major
:
8358 return DW_ORD_row_major
;
8362 /* Extract all information from a DW_TAG_set_type DIE and put it in
8363 the DIE's type field. */
8365 static struct type
*
8366 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8368 struct type
*domain_type
, *set_type
;
8369 struct attribute
*attr
;
8371 domain_type
= die_type (die
, cu
);
8373 /* The die_type call above may have already set the type for this DIE. */
8374 set_type
= get_die_type (die
, cu
);
8378 set_type
= create_set_type (NULL
, domain_type
);
8380 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8382 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
8384 return set_die_type (die
, set_type
, cu
);
8387 /* First cut: install each common block member as a global variable. */
8390 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
8392 struct die_info
*child_die
;
8393 struct attribute
*attr
;
8395 CORE_ADDR base
= (CORE_ADDR
) 0;
8397 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
8400 /* Support the .debug_loc offsets. */
8401 if (attr_form_is_block (attr
))
8403 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
8405 else if (attr_form_is_section_offset (attr
))
8407 dwarf2_complex_location_expr_complaint ();
8411 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
8412 "common block member");
8415 if (die
->child
!= NULL
)
8417 child_die
= die
->child
;
8418 while (child_die
&& child_die
->tag
)
8422 sym
= new_symbol (child_die
, NULL
, cu
);
8424 && handle_data_member_location (child_die
, cu
, &offset
))
8426 SYMBOL_VALUE_ADDRESS (sym
) = base
+ offset
;
8427 add_symbol_to_list (sym
, &global_symbols
);
8429 child_die
= sibling_die (child_die
);
8434 /* Create a type for a C++ namespace. */
8436 static struct type
*
8437 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8439 struct objfile
*objfile
= cu
->objfile
;
8440 const char *previous_prefix
, *name
;
8444 /* For extensions, reuse the type of the original namespace. */
8445 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
8447 struct die_info
*ext_die
;
8448 struct dwarf2_cu
*ext_cu
= cu
;
8450 ext_die
= dwarf2_extension (die
, &ext_cu
);
8451 type
= read_type_die (ext_die
, ext_cu
);
8453 /* EXT_CU may not be the same as CU.
8454 Ensure TYPE is recorded in CU's type_hash table. */
8455 return set_die_type (die
, type
, cu
);
8458 name
= namespace_name (die
, &is_anonymous
, cu
);
8460 /* Now build the name of the current namespace. */
8462 previous_prefix
= determine_prefix (die
, cu
);
8463 if (previous_prefix
[0] != '\0')
8464 name
= typename_concat (&objfile
->objfile_obstack
,
8465 previous_prefix
, name
, 0, cu
);
8467 /* Create the type. */
8468 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
8470 TYPE_NAME (type
) = (char *) name
;
8471 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8473 return set_die_type (die
, type
, cu
);
8476 /* Read a C++ namespace. */
8479 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
8481 struct objfile
*objfile
= cu
->objfile
;
8484 /* Add a symbol associated to this if we haven't seen the namespace
8485 before. Also, add a using directive if it's an anonymous
8488 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
8492 type
= read_type_die (die
, cu
);
8493 new_symbol (die
, type
, cu
);
8495 namespace_name (die
, &is_anonymous
, cu
);
8498 const char *previous_prefix
= determine_prefix (die
, cu
);
8500 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
8501 NULL
, NULL
, &objfile
->objfile_obstack
);
8505 if (die
->child
!= NULL
)
8507 struct die_info
*child_die
= die
->child
;
8509 while (child_die
&& child_die
->tag
)
8511 process_die (child_die
, cu
);
8512 child_die
= sibling_die (child_die
);
8517 /* Read a Fortran module as type. This DIE can be only a declaration used for
8518 imported module. Still we need that type as local Fortran "use ... only"
8519 declaration imports depend on the created type in determine_prefix. */
8521 static struct type
*
8522 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8524 struct objfile
*objfile
= cu
->objfile
;
8528 module_name
= dwarf2_name (die
, cu
);
8530 complaint (&symfile_complaints
,
8531 _("DW_TAG_module has no name, offset 0x%x"),
8532 die
->offset
.sect_off
);
8533 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
8535 /* determine_prefix uses TYPE_TAG_NAME. */
8536 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8538 return set_die_type (die
, type
, cu
);
8541 /* Read a Fortran module. */
8544 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
8546 struct die_info
*child_die
= die
->child
;
8548 while (child_die
&& child_die
->tag
)
8550 process_die (child_die
, cu
);
8551 child_die
= sibling_die (child_die
);
8555 /* Return the name of the namespace represented by DIE. Set
8556 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
8560 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
8562 struct die_info
*current_die
;
8563 const char *name
= NULL
;
8565 /* Loop through the extensions until we find a name. */
8567 for (current_die
= die
;
8568 current_die
!= NULL
;
8569 current_die
= dwarf2_extension (die
, &cu
))
8571 name
= dwarf2_name (current_die
, cu
);
8576 /* Is it an anonymous namespace? */
8578 *is_anonymous
= (name
== NULL
);
8580 name
= CP_ANONYMOUS_NAMESPACE_STR
;
8585 /* Extract all information from a DW_TAG_pointer_type DIE and add to
8586 the user defined type vector. */
8588 static struct type
*
8589 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8591 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
8592 struct comp_unit_head
*cu_header
= &cu
->header
;
8594 struct attribute
*attr_byte_size
;
8595 struct attribute
*attr_address_class
;
8596 int byte_size
, addr_class
;
8597 struct type
*target_type
;
8599 target_type
= die_type (die
, cu
);
8601 /* The die_type call above may have already set the type for this DIE. */
8602 type
= get_die_type (die
, cu
);
8606 type
= lookup_pointer_type (target_type
);
8608 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8610 byte_size
= DW_UNSND (attr_byte_size
);
8612 byte_size
= cu_header
->addr_size
;
8614 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
8615 if (attr_address_class
)
8616 addr_class
= DW_UNSND (attr_address_class
);
8618 addr_class
= DW_ADDR_none
;
8620 /* If the pointer size or address class is different than the
8621 default, create a type variant marked as such and set the
8622 length accordingly. */
8623 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
8625 if (gdbarch_address_class_type_flags_p (gdbarch
))
8629 type_flags
= gdbarch_address_class_type_flags
8630 (gdbarch
, byte_size
, addr_class
);
8631 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
8633 type
= make_type_with_address_space (type
, type_flags
);
8635 else if (TYPE_LENGTH (type
) != byte_size
)
8637 complaint (&symfile_complaints
,
8638 _("invalid pointer size %d"), byte_size
);
8642 /* Should we also complain about unhandled address classes? */
8646 TYPE_LENGTH (type
) = byte_size
;
8647 return set_die_type (die
, type
, cu
);
8650 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
8651 the user defined type vector. */
8653 static struct type
*
8654 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8657 struct type
*to_type
;
8658 struct type
*domain
;
8660 to_type
= die_type (die
, cu
);
8661 domain
= die_containing_type (die
, cu
);
8663 /* The calls above may have already set the type for this DIE. */
8664 type
= get_die_type (die
, cu
);
8668 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
8669 type
= lookup_methodptr_type (to_type
);
8671 type
= lookup_memberptr_type (to_type
, domain
);
8673 return set_die_type (die
, type
, cu
);
8676 /* Extract all information from a DW_TAG_reference_type DIE and add to
8677 the user defined type vector. */
8679 static struct type
*
8680 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8682 struct comp_unit_head
*cu_header
= &cu
->header
;
8683 struct type
*type
, *target_type
;
8684 struct attribute
*attr
;
8686 target_type
= die_type (die
, cu
);
8688 /* The die_type call above may have already set the type for this DIE. */
8689 type
= get_die_type (die
, cu
);
8693 type
= lookup_reference_type (target_type
);
8694 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8697 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8701 TYPE_LENGTH (type
) = cu_header
->addr_size
;
8703 return set_die_type (die
, type
, cu
);
8706 static struct type
*
8707 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8709 struct type
*base_type
, *cv_type
;
8711 base_type
= die_type (die
, cu
);
8713 /* The die_type call above may have already set the type for this DIE. */
8714 cv_type
= get_die_type (die
, cu
);
8718 /* In case the const qualifier is applied to an array type, the element type
8719 is so qualified, not the array type (section 6.7.3 of C99). */
8720 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
8722 struct type
*el_type
, *inner_array
;
8724 base_type
= copy_type (base_type
);
8725 inner_array
= base_type
;
8727 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
8729 TYPE_TARGET_TYPE (inner_array
) =
8730 copy_type (TYPE_TARGET_TYPE (inner_array
));
8731 inner_array
= TYPE_TARGET_TYPE (inner_array
);
8734 el_type
= TYPE_TARGET_TYPE (inner_array
);
8735 TYPE_TARGET_TYPE (inner_array
) =
8736 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
8738 return set_die_type (die
, base_type
, cu
);
8741 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
8742 return set_die_type (die
, cv_type
, cu
);
8745 static struct type
*
8746 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8748 struct type
*base_type
, *cv_type
;
8750 base_type
= die_type (die
, cu
);
8752 /* The die_type call above may have already set the type for this DIE. */
8753 cv_type
= get_die_type (die
, cu
);
8757 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
8758 return set_die_type (die
, cv_type
, cu
);
8761 /* Extract all information from a DW_TAG_string_type DIE and add to
8762 the user defined type vector. It isn't really a user defined type,
8763 but it behaves like one, with other DIE's using an AT_user_def_type
8764 attribute to reference it. */
8766 static struct type
*
8767 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8769 struct objfile
*objfile
= cu
->objfile
;
8770 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8771 struct type
*type
, *range_type
, *index_type
, *char_type
;
8772 struct attribute
*attr
;
8773 unsigned int length
;
8775 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
8778 length
= DW_UNSND (attr
);
8782 /* Check for the DW_AT_byte_size attribute. */
8783 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8786 length
= DW_UNSND (attr
);
8794 index_type
= objfile_type (objfile
)->builtin_int
;
8795 range_type
= create_range_type (NULL
, index_type
, 1, length
);
8796 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
8797 type
= create_string_type (NULL
, char_type
, range_type
);
8799 return set_die_type (die
, type
, cu
);
8802 /* Handle DIES due to C code like:
8806 int (*funcp)(int a, long l);
8810 ('funcp' generates a DW_TAG_subroutine_type DIE). */
8812 static struct type
*
8813 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8815 struct objfile
*objfile
= cu
->objfile
;
8816 struct type
*type
; /* Type that this function returns. */
8817 struct type
*ftype
; /* Function that returns above type. */
8818 struct attribute
*attr
;
8820 type
= die_type (die
, cu
);
8822 /* The die_type call above may have already set the type for this DIE. */
8823 ftype
= get_die_type (die
, cu
);
8827 ftype
= lookup_function_type (type
);
8829 /* All functions in C++, Pascal and Java have prototypes. */
8830 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
8831 if ((attr
&& (DW_UNSND (attr
) != 0))
8832 || cu
->language
== language_cplus
8833 || cu
->language
== language_java
8834 || cu
->language
== language_pascal
)
8835 TYPE_PROTOTYPED (ftype
) = 1;
8836 else if (producer_is_realview (cu
->producer
))
8837 /* RealView does not emit DW_AT_prototyped. We can not
8838 distinguish prototyped and unprototyped functions; default to
8839 prototyped, since that is more common in modern code (and
8840 RealView warns about unprototyped functions). */
8841 TYPE_PROTOTYPED (ftype
) = 1;
8843 /* Store the calling convention in the type if it's available in
8844 the subroutine die. Otherwise set the calling convention to
8845 the default value DW_CC_normal. */
8846 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
8848 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
8849 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
8850 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
8852 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
8854 /* We need to add the subroutine type to the die immediately so
8855 we don't infinitely recurse when dealing with parameters
8856 declared as the same subroutine type. */
8857 set_die_type (die
, ftype
, cu
);
8859 if (die
->child
!= NULL
)
8861 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
8862 struct die_info
*child_die
;
8863 int nparams
, iparams
;
8865 /* Count the number of parameters.
8866 FIXME: GDB currently ignores vararg functions, but knows about
8867 vararg member functions. */
8869 child_die
= die
->child
;
8870 while (child_die
&& child_die
->tag
)
8872 if (child_die
->tag
== DW_TAG_formal_parameter
)
8874 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
8875 TYPE_VARARGS (ftype
) = 1;
8876 child_die
= sibling_die (child_die
);
8879 /* Allocate storage for parameters and fill them in. */
8880 TYPE_NFIELDS (ftype
) = nparams
;
8881 TYPE_FIELDS (ftype
) = (struct field
*)
8882 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
8884 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
8885 even if we error out during the parameters reading below. */
8886 for (iparams
= 0; iparams
< nparams
; iparams
++)
8887 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
8890 child_die
= die
->child
;
8891 while (child_die
&& child_die
->tag
)
8893 if (child_die
->tag
== DW_TAG_formal_parameter
)
8895 struct type
*arg_type
;
8897 /* DWARF version 2 has no clean way to discern C++
8898 static and non-static member functions. G++ helps
8899 GDB by marking the first parameter for non-static
8900 member functions (which is the this pointer) as
8901 artificial. We pass this information to
8902 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
8904 DWARF version 3 added DW_AT_object_pointer, which GCC
8905 4.5 does not yet generate. */
8906 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
8908 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
8911 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
8913 /* GCC/43521: In java, the formal parameter
8914 "this" is sometimes not marked with DW_AT_artificial. */
8915 if (cu
->language
== language_java
)
8917 const char *name
= dwarf2_name (child_die
, cu
);
8919 if (name
&& !strcmp (name
, "this"))
8920 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
8923 arg_type
= die_type (child_die
, cu
);
8925 /* RealView does not mark THIS as const, which the testsuite
8926 expects. GCC marks THIS as const in method definitions,
8927 but not in the class specifications (GCC PR 43053). */
8928 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
8929 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
8932 struct dwarf2_cu
*arg_cu
= cu
;
8933 const char *name
= dwarf2_name (child_die
, cu
);
8935 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
8938 /* If the compiler emits this, use it. */
8939 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
8942 else if (name
&& strcmp (name
, "this") == 0)
8943 /* Function definitions will have the argument names. */
8945 else if (name
== NULL
&& iparams
== 0)
8946 /* Declarations may not have the names, so like
8947 elsewhere in GDB, assume an artificial first
8948 argument is "this". */
8952 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
8956 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
8959 child_die
= sibling_die (child_die
);
8966 static struct type
*
8967 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
8969 struct objfile
*objfile
= cu
->objfile
;
8970 const char *name
= NULL
;
8971 struct type
*this_type
, *target_type
;
8973 name
= dwarf2_full_name (NULL
, die
, cu
);
8974 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
8975 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
8976 TYPE_NAME (this_type
) = (char *) name
;
8977 set_die_type (die
, this_type
, cu
);
8978 target_type
= die_type (die
, cu
);
8979 if (target_type
!= this_type
)
8980 TYPE_TARGET_TYPE (this_type
) = target_type
;
8983 /* Self-referential typedefs are, it seems, not allowed by the DWARF
8984 spec and cause infinite loops in GDB. */
8985 complaint (&symfile_complaints
,
8986 _("Self-referential DW_TAG_typedef "
8987 "- DIE at 0x%x [in module %s]"),
8988 die
->offset
.sect_off
, objfile
->name
);
8989 TYPE_TARGET_TYPE (this_type
) = NULL
;
8994 /* Find a representation of a given base type and install
8995 it in the TYPE field of the die. */
8997 static struct type
*
8998 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9000 struct objfile
*objfile
= cu
->objfile
;
9002 struct attribute
*attr
;
9003 int encoding
= 0, size
= 0;
9005 enum type_code code
= TYPE_CODE_INT
;
9007 struct type
*target_type
= NULL
;
9009 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
9012 encoding
= DW_UNSND (attr
);
9014 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9017 size
= DW_UNSND (attr
);
9019 name
= dwarf2_name (die
, cu
);
9022 complaint (&symfile_complaints
,
9023 _("DW_AT_name missing from DW_TAG_base_type"));
9028 case DW_ATE_address
:
9029 /* Turn DW_ATE_address into a void * pointer. */
9030 code
= TYPE_CODE_PTR
;
9031 type_flags
|= TYPE_FLAG_UNSIGNED
;
9032 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
9034 case DW_ATE_boolean
:
9035 code
= TYPE_CODE_BOOL
;
9036 type_flags
|= TYPE_FLAG_UNSIGNED
;
9038 case DW_ATE_complex_float
:
9039 code
= TYPE_CODE_COMPLEX
;
9040 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
9042 case DW_ATE_decimal_float
:
9043 code
= TYPE_CODE_DECFLOAT
;
9046 code
= TYPE_CODE_FLT
;
9050 case DW_ATE_unsigned
:
9051 type_flags
|= TYPE_FLAG_UNSIGNED
;
9052 if (cu
->language
== language_fortran
9054 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
9055 code
= TYPE_CODE_CHAR
;
9057 case DW_ATE_signed_char
:
9058 if (cu
->language
== language_ada
|| cu
->language
== language_m2
9059 || cu
->language
== language_pascal
9060 || cu
->language
== language_fortran
)
9061 code
= TYPE_CODE_CHAR
;
9063 case DW_ATE_unsigned_char
:
9064 if (cu
->language
== language_ada
|| cu
->language
== language_m2
9065 || cu
->language
== language_pascal
9066 || cu
->language
== language_fortran
)
9067 code
= TYPE_CODE_CHAR
;
9068 type_flags
|= TYPE_FLAG_UNSIGNED
;
9071 /* We just treat this as an integer and then recognize the
9072 type by name elsewhere. */
9076 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
9077 dwarf_type_encoding_name (encoding
));
9081 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
9082 TYPE_NAME (type
) = name
;
9083 TYPE_TARGET_TYPE (type
) = target_type
;
9085 if (name
&& strcmp (name
, "char") == 0)
9086 TYPE_NOSIGN (type
) = 1;
9088 return set_die_type (die
, type
, cu
);
9091 /* Read the given DW_AT_subrange DIE. */
9093 static struct type
*
9094 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9096 struct type
*base_type
;
9097 struct type
*range_type
;
9098 struct attribute
*attr
;
9100 int low_default_is_valid
;
9102 LONGEST negative_mask
;
9104 base_type
= die_type (die
, cu
);
9105 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
9106 check_typedef (base_type
);
9108 /* The die_type call above may have already set the type for this DIE. */
9109 range_type
= get_die_type (die
, cu
);
9113 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
9114 omitting DW_AT_lower_bound. */
9115 switch (cu
->language
)
9118 case language_cplus
:
9120 low_default_is_valid
= 1;
9122 case language_fortran
:
9124 low_default_is_valid
= 1;
9130 low_default_is_valid
= (cu
->header
.version
>= 4);
9134 case language_pascal
:
9136 low_default_is_valid
= (cu
->header
.version
>= 4);
9140 low_default_is_valid
= 0;
9144 /* FIXME: For variable sized arrays either of these could be
9145 a variable rather than a constant value. We'll allow it,
9146 but we don't know how to handle it. */
9147 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
9149 low
= dwarf2_get_attr_constant_value (attr
, low
);
9150 else if (!low_default_is_valid
)
9151 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
9152 "- DIE at 0x%x [in module %s]"),
9153 die
->offset
.sect_off
, cu
->objfile
->name
);
9155 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
9158 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
9160 /* GCC encodes arrays with unspecified or dynamic length
9161 with a DW_FORM_block1 attribute or a reference attribute.
9162 FIXME: GDB does not yet know how to handle dynamic
9163 arrays properly, treat them as arrays with unspecified
9166 FIXME: jimb/2003-09-22: GDB does not really know
9167 how to handle arrays of unspecified length
9168 either; we just represent them as zero-length
9169 arrays. Choose an appropriate upper bound given
9170 the lower bound we've computed above. */
9174 high
= dwarf2_get_attr_constant_value (attr
, 1);
9178 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
9181 int count
= dwarf2_get_attr_constant_value (attr
, 1);
9182 high
= low
+ count
- 1;
9186 /* Unspecified array length. */
9191 /* Dwarf-2 specifications explicitly allows to create subrange types
9192 without specifying a base type.
9193 In that case, the base type must be set to the type of
9194 the lower bound, upper bound or count, in that order, if any of these
9195 three attributes references an object that has a type.
9196 If no base type is found, the Dwarf-2 specifications say that
9197 a signed integer type of size equal to the size of an address should
9199 For the following C code: `extern char gdb_int [];'
9200 GCC produces an empty range DIE.
9201 FIXME: muller/2010-05-28: Possible references to object for low bound,
9202 high bound or count are not yet handled by this code. */
9203 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
9205 struct objfile
*objfile
= cu
->objfile
;
9206 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9207 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
9208 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
9210 /* Test "int", "long int", and "long long int" objfile types,
9211 and select the first one having a size above or equal to the
9212 architecture address size. */
9213 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
9214 base_type
= int_type
;
9217 int_type
= objfile_type (objfile
)->builtin_long
;
9218 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
9219 base_type
= int_type
;
9222 int_type
= objfile_type (objfile
)->builtin_long_long
;
9223 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
9224 base_type
= int_type
;
9230 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
9231 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
9232 low
|= negative_mask
;
9233 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
9234 high
|= negative_mask
;
9236 range_type
= create_range_type (NULL
, base_type
, low
, high
);
9238 /* Mark arrays with dynamic length at least as an array of unspecified
9239 length. GDB could check the boundary but before it gets implemented at
9240 least allow accessing the array elements. */
9241 if (attr
&& attr_form_is_block (attr
))
9242 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
9244 /* Ada expects an empty array on no boundary attributes. */
9245 if (attr
== NULL
&& cu
->language
!= language_ada
)
9246 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
9248 name
= dwarf2_name (die
, cu
);
9250 TYPE_NAME (range_type
) = name
;
9252 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9254 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
9256 set_die_type (die
, range_type
, cu
);
9258 /* set_die_type should be already done. */
9259 set_descriptive_type (range_type
, die
, cu
);
9264 static struct type
*
9265 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9269 /* For now, we only support the C meaning of an unspecified type: void. */
9271 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
9272 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
9274 return set_die_type (die
, type
, cu
);
9277 /* Trivial hash function for die_info: the hash value of a DIE
9278 is its offset in .debug_info for this objfile. */
9281 die_hash (const void *item
)
9283 const struct die_info
*die
= item
;
9285 return die
->offset
.sect_off
;
9288 /* Trivial comparison function for die_info structures: two DIEs
9289 are equal if they have the same offset. */
9292 die_eq (const void *item_lhs
, const void *item_rhs
)
9294 const struct die_info
*die_lhs
= item_lhs
;
9295 const struct die_info
*die_rhs
= item_rhs
;
9297 return die_lhs
->offset
.sect_off
== die_rhs
->offset
.sect_off
;
9300 /* Read a whole compilation unit into a linked list of dies. */
9302 static struct die_info
*
9303 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
9305 struct die_reader_specs reader_specs
;
9306 int read_abbrevs
= 0;
9307 struct cleanup
*back_to
= NULL
;
9308 struct die_info
*die
;
9310 if (cu
->dwarf2_abbrevs
== NULL
)
9312 dwarf2_read_abbrevs (cu
);
9313 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
9317 gdb_assert (cu
->die_hash
== NULL
);
9319 = htab_create_alloc_ex (cu
->header
.length
/ 12,
9323 &cu
->comp_unit_obstack
,
9324 hashtab_obstack_allocate
,
9325 dummy_obstack_deallocate
);
9327 init_cu_die_reader (&reader_specs
, cu
);
9329 die
= read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
9332 do_cleanups (back_to
);
9337 /* Main entry point for reading a DIE and all children.
9338 Read the DIE and dump it if requested. */
9340 static struct die_info
*
9341 read_die_and_children (const struct die_reader_specs
*reader
,
9343 gdb_byte
**new_info_ptr
,
9344 struct die_info
*parent
)
9346 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
9347 new_info_ptr
, parent
);
9349 if (dwarf2_die_debug
)
9351 fprintf_unfiltered (gdb_stdlog
,
9352 "\nRead die from %s of %s:\n",
9353 (reader
->cu
->per_cu
->debug_types_section
9356 reader
->abfd
->filename
);
9357 dump_die (result
, dwarf2_die_debug
);
9363 /* Read a single die and all its descendents. Set the die's sibling
9364 field to NULL; set other fields in the die correctly, and set all
9365 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
9366 location of the info_ptr after reading all of those dies. PARENT
9367 is the parent of the die in question. */
9369 static struct die_info
*
9370 read_die_and_children_1 (const struct die_reader_specs
*reader
,
9372 gdb_byte
**new_info_ptr
,
9373 struct die_info
*parent
)
9375 struct die_info
*die
;
9379 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
9382 *new_info_ptr
= cur_ptr
;
9385 store_in_ref_table (die
, reader
->cu
);
9388 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
9392 *new_info_ptr
= cur_ptr
;
9395 die
->sibling
= NULL
;
9396 die
->parent
= parent
;
9400 /* Read a die, all of its descendents, and all of its siblings; set
9401 all of the fields of all of the dies correctly. Arguments are as
9402 in read_die_and_children. */
9404 static struct die_info
*
9405 read_die_and_siblings (const struct die_reader_specs
*reader
,
9407 gdb_byte
**new_info_ptr
,
9408 struct die_info
*parent
)
9410 struct die_info
*first_die
, *last_sibling
;
9414 first_die
= last_sibling
= NULL
;
9418 struct die_info
*die
9419 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
9423 *new_info_ptr
= cur_ptr
;
9430 last_sibling
->sibling
= die
;
9436 /* Read the die from the .debug_info section buffer. Set DIEP to
9437 point to a newly allocated die with its information, except for its
9438 child, sibling, and parent fields. Set HAS_CHILDREN to tell
9439 whether the die has children or not. */
9442 read_full_die (const struct die_reader_specs
*reader
,
9443 struct die_info
**diep
, gdb_byte
*info_ptr
,
9446 unsigned int abbrev_number
, bytes_read
, i
;
9448 struct abbrev_info
*abbrev
;
9449 struct die_info
*die
;
9450 struct dwarf2_cu
*cu
= reader
->cu
;
9451 bfd
*abfd
= reader
->abfd
;
9453 offset
.sect_off
= info_ptr
- reader
->buffer
;
9454 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9455 info_ptr
+= bytes_read
;
9463 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
9465 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
9467 bfd_get_filename (abfd
));
9469 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
9470 die
->offset
= offset
;
9471 die
->tag
= abbrev
->tag
;
9472 die
->abbrev
= abbrev_number
;
9474 die
->num_attrs
= abbrev
->num_attrs
;
9476 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9477 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
9478 abfd
, info_ptr
, cu
);
9481 *has_children
= abbrev
->has_children
;
9485 /* In DWARF version 2, the description of the debugging information is
9486 stored in a separate .debug_abbrev section. Before we read any
9487 dies from a section we read in all abbreviations and install them
9488 in a hash table. This function also sets flags in CU describing
9489 the data found in the abbrev table. */
9492 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
)
9494 bfd
*abfd
= cu
->objfile
->obfd
;
9495 struct comp_unit_head
*cu_header
= &cu
->header
;
9496 gdb_byte
*abbrev_ptr
;
9497 struct abbrev_info
*cur_abbrev
;
9498 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
9499 unsigned int abbrev_form
, hash_number
;
9500 struct attr_abbrev
*cur_attrs
;
9501 unsigned int allocated_attrs
;
9503 /* Initialize dwarf2 abbrevs. */
9504 obstack_init (&cu
->abbrev_obstack
);
9505 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
9507 * sizeof (struct abbrev_info
*)));
9508 memset (cu
->dwarf2_abbrevs
, 0,
9509 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
9511 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
9512 &dwarf2_per_objfile
->abbrev
);
9513 abbrev_ptr
= (dwarf2_per_objfile
->abbrev
.buffer
9514 + cu_header
->abbrev_offset
.sect_off
);
9515 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9516 abbrev_ptr
+= bytes_read
;
9518 allocated_attrs
= ATTR_ALLOC_CHUNK
;
9519 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
9521 /* Loop until we reach an abbrev number of 0. */
9522 while (abbrev_number
)
9524 cur_abbrev
= dwarf_alloc_abbrev (cu
);
9526 /* read in abbrev header */
9527 cur_abbrev
->number
= abbrev_number
;
9528 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9529 abbrev_ptr
+= bytes_read
;
9530 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
9533 /* now read in declarations */
9534 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9535 abbrev_ptr
+= bytes_read
;
9536 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9537 abbrev_ptr
+= bytes_read
;
9540 if (cur_abbrev
->num_attrs
== allocated_attrs
)
9542 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
9544 = xrealloc (cur_attrs
, (allocated_attrs
9545 * sizeof (struct attr_abbrev
)));
9548 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
9549 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
9550 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9551 abbrev_ptr
+= bytes_read
;
9552 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9553 abbrev_ptr
+= bytes_read
;
9556 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
9557 (cur_abbrev
->num_attrs
9558 * sizeof (struct attr_abbrev
)));
9559 memcpy (cur_abbrev
->attrs
, cur_attrs
,
9560 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
9562 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
9563 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
9564 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
9566 /* Get next abbreviation.
9567 Under Irix6 the abbreviations for a compilation unit are not
9568 always properly terminated with an abbrev number of 0.
9569 Exit loop if we encounter an abbreviation which we have
9570 already read (which means we are about to read the abbreviations
9571 for the next compile unit) or if the end of the abbreviation
9572 table is reached. */
9573 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
9574 >= dwarf2_per_objfile
->abbrev
.size
)
9576 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9577 abbrev_ptr
+= bytes_read
;
9578 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
9585 /* Release the memory used by the abbrev table for a compilation unit. */
9588 dwarf2_free_abbrev_table (void *ptr_to_cu
)
9590 struct dwarf2_cu
*cu
= ptr_to_cu
;
9592 obstack_free (&cu
->abbrev_obstack
, NULL
);
9593 cu
->dwarf2_abbrevs
= NULL
;
9596 /* Lookup an abbrev_info structure in the abbrev hash table. */
9598 static struct abbrev_info
*
9599 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
9601 unsigned int hash_number
;
9602 struct abbrev_info
*abbrev
;
9604 hash_number
= number
% ABBREV_HASH_SIZE
;
9605 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
9609 if (abbrev
->number
== number
)
9612 abbrev
= abbrev
->next
;
9617 /* Returns nonzero if TAG represents a type that we might generate a partial
9621 is_type_tag_for_partial (int tag
)
9626 /* Some types that would be reasonable to generate partial symbols for,
9627 that we don't at present. */
9628 case DW_TAG_array_type
:
9629 case DW_TAG_file_type
:
9630 case DW_TAG_ptr_to_member_type
:
9631 case DW_TAG_set_type
:
9632 case DW_TAG_string_type
:
9633 case DW_TAG_subroutine_type
:
9635 case DW_TAG_base_type
:
9636 case DW_TAG_class_type
:
9637 case DW_TAG_interface_type
:
9638 case DW_TAG_enumeration_type
:
9639 case DW_TAG_structure_type
:
9640 case DW_TAG_subrange_type
:
9641 case DW_TAG_typedef
:
9642 case DW_TAG_union_type
:
9649 /* Load all DIEs that are interesting for partial symbols into memory. */
9651 static struct partial_die_info
*
9652 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9653 int building_psymtab
, struct dwarf2_cu
*cu
)
9655 struct objfile
*objfile
= cu
->objfile
;
9656 struct partial_die_info
*part_die
;
9657 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
9658 struct abbrev_info
*abbrev
;
9659 unsigned int bytes_read
;
9660 unsigned int load_all
= 0;
9661 int nesting_level
= 1;
9666 gdb_assert (cu
->per_cu
!= NULL
);
9667 if (cu
->per_cu
->load_all_dies
)
9671 = htab_create_alloc_ex (cu
->header
.length
/ 12,
9675 &cu
->comp_unit_obstack
,
9676 hashtab_obstack_allocate
,
9677 dummy_obstack_deallocate
);
9679 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9680 sizeof (struct partial_die_info
));
9684 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
9686 /* A NULL abbrev means the end of a series of children. */
9689 if (--nesting_level
== 0)
9691 /* PART_DIE was probably the last thing allocated on the
9692 comp_unit_obstack, so we could call obstack_free
9693 here. We don't do that because the waste is small,
9694 and will be cleaned up when we're done with this
9695 compilation unit. This way, we're also more robust
9696 against other users of the comp_unit_obstack. */
9699 info_ptr
+= bytes_read
;
9700 last_die
= parent_die
;
9701 parent_die
= parent_die
->die_parent
;
9705 /* Check for template arguments. We never save these; if
9706 they're seen, we just mark the parent, and go on our way. */
9707 if (parent_die
!= NULL
9708 && cu
->language
== language_cplus
9709 && (abbrev
->tag
== DW_TAG_template_type_param
9710 || abbrev
->tag
== DW_TAG_template_value_param
))
9712 parent_die
->has_template_arguments
= 1;
9716 /* We don't need a partial DIE for the template argument. */
9717 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
,
9723 /* We only recurse into c++ subprograms looking for template arguments.
9724 Skip their other children. */
9726 && cu
->language
== language_cplus
9727 && parent_die
!= NULL
9728 && parent_die
->tag
== DW_TAG_subprogram
)
9730 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
9734 /* Check whether this DIE is interesting enough to save. Normally
9735 we would not be interested in members here, but there may be
9736 later variables referencing them via DW_AT_specification (for
9739 && !is_type_tag_for_partial (abbrev
->tag
)
9740 && abbrev
->tag
!= DW_TAG_constant
9741 && abbrev
->tag
!= DW_TAG_enumerator
9742 && abbrev
->tag
!= DW_TAG_subprogram
9743 && abbrev
->tag
!= DW_TAG_lexical_block
9744 && abbrev
->tag
!= DW_TAG_variable
9745 && abbrev
->tag
!= DW_TAG_namespace
9746 && abbrev
->tag
!= DW_TAG_module
9747 && abbrev
->tag
!= DW_TAG_member
)
9749 /* Otherwise we skip to the next sibling, if any. */
9750 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
9754 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
9755 buffer
, info_ptr
, cu
);
9757 /* This two-pass algorithm for processing partial symbols has a
9758 high cost in cache pressure. Thus, handle some simple cases
9759 here which cover the majority of C partial symbols. DIEs
9760 which neither have specification tags in them, nor could have
9761 specification tags elsewhere pointing at them, can simply be
9762 processed and discarded.
9764 This segment is also optional; scan_partial_symbols and
9765 add_partial_symbol will handle these DIEs if we chain
9766 them in normally. When compilers which do not emit large
9767 quantities of duplicate debug information are more common,
9768 this code can probably be removed. */
9770 /* Any complete simple types at the top level (pretty much all
9771 of them, for a language without namespaces), can be processed
9773 if (parent_die
== NULL
9774 && part_die
->has_specification
== 0
9775 && part_die
->is_declaration
== 0
9776 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
9777 || part_die
->tag
== DW_TAG_base_type
9778 || part_die
->tag
== DW_TAG_subrange_type
))
9780 if (building_psymtab
&& part_die
->name
!= NULL
)
9781 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9782 VAR_DOMAIN
, LOC_TYPEDEF
,
9783 &objfile
->static_psymbols
,
9784 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
9785 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9789 /* The exception for DW_TAG_typedef with has_children above is
9790 a workaround of GCC PR debug/47510. In the case of this complaint
9791 type_name_no_tag_or_error will error on such types later.
9793 GDB skipped children of DW_TAG_typedef by the shortcut above and then
9794 it could not find the child DIEs referenced later, this is checked
9795 above. In correct DWARF DW_TAG_typedef should have no children. */
9797 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
9798 complaint (&symfile_complaints
,
9799 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
9800 "- DIE at 0x%x [in module %s]"),
9801 part_die
->offset
.sect_off
, objfile
->name
);
9803 /* If we're at the second level, and we're an enumerator, and
9804 our parent has no specification (meaning possibly lives in a
9805 namespace elsewhere), then we can add the partial symbol now
9806 instead of queueing it. */
9807 if (part_die
->tag
== DW_TAG_enumerator
9808 && parent_die
!= NULL
9809 && parent_die
->die_parent
== NULL
9810 && parent_die
->tag
== DW_TAG_enumeration_type
9811 && parent_die
->has_specification
== 0)
9813 if (part_die
->name
== NULL
)
9814 complaint (&symfile_complaints
,
9815 _("malformed enumerator DIE ignored"));
9816 else if (building_psymtab
)
9817 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9818 VAR_DOMAIN
, LOC_CONST
,
9819 (cu
->language
== language_cplus
9820 || cu
->language
== language_java
)
9821 ? &objfile
->global_psymbols
9822 : &objfile
->static_psymbols
,
9823 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
9825 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9829 /* We'll save this DIE so link it in. */
9830 part_die
->die_parent
= parent_die
;
9831 part_die
->die_sibling
= NULL
;
9832 part_die
->die_child
= NULL
;
9834 if (last_die
&& last_die
== parent_die
)
9835 last_die
->die_child
= part_die
;
9837 last_die
->die_sibling
= part_die
;
9839 last_die
= part_die
;
9841 if (first_die
== NULL
)
9842 first_die
= part_die
;
9844 /* Maybe add the DIE to the hash table. Not all DIEs that we
9845 find interesting need to be in the hash table, because we
9846 also have the parent/sibling/child chains; only those that we
9847 might refer to by offset later during partial symbol reading.
9849 For now this means things that might have be the target of a
9850 DW_AT_specification, DW_AT_abstract_origin, or
9851 DW_AT_extension. DW_AT_extension will refer only to
9852 namespaces; DW_AT_abstract_origin refers to functions (and
9853 many things under the function DIE, but we do not recurse
9854 into function DIEs during partial symbol reading) and
9855 possibly variables as well; DW_AT_specification refers to
9856 declarations. Declarations ought to have the DW_AT_declaration
9857 flag. It happens that GCC forgets to put it in sometimes, but
9858 only for functions, not for types.
9860 Adding more things than necessary to the hash table is harmless
9861 except for the performance cost. Adding too few will result in
9862 wasted time in find_partial_die, when we reread the compilation
9863 unit with load_all_dies set. */
9866 || abbrev
->tag
== DW_TAG_constant
9867 || abbrev
->tag
== DW_TAG_subprogram
9868 || abbrev
->tag
== DW_TAG_variable
9869 || abbrev
->tag
== DW_TAG_namespace
9870 || part_die
->is_declaration
)
9874 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
9875 part_die
->offset
.sect_off
, INSERT
);
9879 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9880 sizeof (struct partial_die_info
));
9882 /* For some DIEs we want to follow their children (if any). For C
9883 we have no reason to follow the children of structures; for other
9884 languages we have to, so that we can get at method physnames
9885 to infer fully qualified class names, for DW_AT_specification,
9886 and for C++ template arguments. For C++, we also look one level
9887 inside functions to find template arguments (if the name of the
9888 function does not already contain the template arguments).
9890 For Ada, we need to scan the children of subprograms and lexical
9891 blocks as well because Ada allows the definition of nested
9892 entities that could be interesting for the debugger, such as
9893 nested subprograms for instance. */
9894 if (last_die
->has_children
9896 || last_die
->tag
== DW_TAG_namespace
9897 || last_die
->tag
== DW_TAG_module
9898 || last_die
->tag
== DW_TAG_enumeration_type
9899 || (cu
->language
== language_cplus
9900 && last_die
->tag
== DW_TAG_subprogram
9901 && (last_die
->name
== NULL
9902 || strchr (last_die
->name
, '<') == NULL
))
9903 || (cu
->language
!= language_c
9904 && (last_die
->tag
== DW_TAG_class_type
9905 || last_die
->tag
== DW_TAG_interface_type
9906 || last_die
->tag
== DW_TAG_structure_type
9907 || last_die
->tag
== DW_TAG_union_type
))
9908 || (cu
->language
== language_ada
9909 && (last_die
->tag
== DW_TAG_subprogram
9910 || last_die
->tag
== DW_TAG_lexical_block
))))
9913 parent_die
= last_die
;
9917 /* Otherwise we skip to the next sibling, if any. */
9918 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
9920 /* Back to the top, do it again. */
9924 /* Read a minimal amount of information into the minimal die structure. */
9927 read_partial_die (struct partial_die_info
*part_die
,
9928 struct abbrev_info
*abbrev
,
9929 unsigned int abbrev_len
, bfd
*abfd
,
9930 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9931 struct dwarf2_cu
*cu
)
9933 struct objfile
*objfile
= cu
->objfile
;
9935 struct attribute attr
;
9936 int has_low_pc_attr
= 0;
9937 int has_high_pc_attr
= 0;
9938 int high_pc_relative
= 0;
9940 memset (part_die
, 0, sizeof (struct partial_die_info
));
9942 part_die
->offset
.sect_off
= info_ptr
- buffer
;
9944 info_ptr
+= abbrev_len
;
9949 part_die
->tag
= abbrev
->tag
;
9950 part_die
->has_children
= abbrev
->has_children
;
9952 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9954 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
9956 /* Store the data if it is of an attribute we want to keep in a
9957 partial symbol table. */
9961 switch (part_die
->tag
)
9963 case DW_TAG_compile_unit
:
9964 case DW_TAG_type_unit
:
9965 /* Compilation units have a DW_AT_name that is a filename, not
9966 a source language identifier. */
9967 case DW_TAG_enumeration_type
:
9968 case DW_TAG_enumerator
:
9969 /* These tags always have simple identifiers already; no need
9970 to canonicalize them. */
9971 part_die
->name
= DW_STRING (&attr
);
9975 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
9976 &objfile
->objfile_obstack
);
9980 case DW_AT_linkage_name
:
9981 case DW_AT_MIPS_linkage_name
:
9982 /* Note that both forms of linkage name might appear. We
9983 assume they will be the same, and we only store the last
9985 if (cu
->language
== language_ada
)
9986 part_die
->name
= DW_STRING (&attr
);
9987 part_die
->linkage_name
= DW_STRING (&attr
);
9990 has_low_pc_attr
= 1;
9991 part_die
->lowpc
= DW_ADDR (&attr
);
9994 has_high_pc_attr
= 1;
9995 if (attr
.form
== DW_FORM_addr
)
9996 part_die
->highpc
= DW_ADDR (&attr
);
9999 high_pc_relative
= 1;
10000 part_die
->highpc
= DW_UNSND (&attr
);
10003 case DW_AT_location
:
10004 /* Support the .debug_loc offsets. */
10005 if (attr_form_is_block (&attr
))
10007 part_die
->locdesc
= DW_BLOCK (&attr
);
10009 else if (attr_form_is_section_offset (&attr
))
10011 dwarf2_complex_location_expr_complaint ();
10015 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
10016 "partial symbol information");
10019 case DW_AT_external
:
10020 part_die
->is_external
= DW_UNSND (&attr
);
10022 case DW_AT_declaration
:
10023 part_die
->is_declaration
= DW_UNSND (&attr
);
10026 part_die
->has_type
= 1;
10028 case DW_AT_abstract_origin
:
10029 case DW_AT_specification
:
10030 case DW_AT_extension
:
10031 part_die
->has_specification
= 1;
10032 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
10034 case DW_AT_sibling
:
10035 /* Ignore absolute siblings, they might point outside of
10036 the current compile unit. */
10037 if (attr
.form
== DW_FORM_ref_addr
)
10038 complaint (&symfile_complaints
,
10039 _("ignoring absolute DW_AT_sibling"));
10041 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
10043 case DW_AT_byte_size
:
10044 part_die
->has_byte_size
= 1;
10046 case DW_AT_calling_convention
:
10047 /* DWARF doesn't provide a way to identify a program's source-level
10048 entry point. DW_AT_calling_convention attributes are only meant
10049 to describe functions' calling conventions.
10051 However, because it's a necessary piece of information in
10052 Fortran, and because DW_CC_program is the only piece of debugging
10053 information whose definition refers to a 'main program' at all,
10054 several compilers have begun marking Fortran main programs with
10055 DW_CC_program --- even when those functions use the standard
10056 calling conventions.
10058 So until DWARF specifies a way to provide this information and
10059 compilers pick up the new representation, we'll support this
10061 if (DW_UNSND (&attr
) == DW_CC_program
10062 && cu
->language
== language_fortran
)
10064 set_main_name (part_die
->name
);
10066 /* As this DIE has a static linkage the name would be difficult
10067 to look up later. */
10068 language_of_main
= language_fortran
;
10072 if (DW_UNSND (&attr
) == DW_INL_inlined
10073 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
10074 part_die
->may_be_inlined
= 1;
10081 if (high_pc_relative
)
10082 part_die
->highpc
+= part_die
->lowpc
;
10084 if (has_low_pc_attr
&& has_high_pc_attr
)
10086 /* When using the GNU linker, .gnu.linkonce. sections are used to
10087 eliminate duplicate copies of functions and vtables and such.
10088 The linker will arbitrarily choose one and discard the others.
10089 The AT_*_pc values for such functions refer to local labels in
10090 these sections. If the section from that file was discarded, the
10091 labels are not in the output, so the relocs get a value of 0.
10092 If this is a discarded function, mark the pc bounds as invalid,
10093 so that GDB will ignore it. */
10094 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
10096 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10098 complaint (&symfile_complaints
,
10099 _("DW_AT_low_pc %s is zero "
10100 "for DIE at 0x%x [in module %s]"),
10101 paddress (gdbarch
, part_die
->lowpc
),
10102 part_die
->offset
.sect_off
, objfile
->name
);
10104 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
10105 else if (part_die
->lowpc
>= part_die
->highpc
)
10107 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10109 complaint (&symfile_complaints
,
10110 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
10111 "for DIE at 0x%x [in module %s]"),
10112 paddress (gdbarch
, part_die
->lowpc
),
10113 paddress (gdbarch
, part_die
->highpc
),
10114 part_die
->offset
.sect_off
, objfile
->name
);
10117 part_die
->has_pc_info
= 1;
10123 /* Find a cached partial DIE at OFFSET in CU. */
10125 static struct partial_die_info
*
10126 find_partial_die_in_comp_unit (sect_offset offset
, struct dwarf2_cu
*cu
)
10128 struct partial_die_info
*lookup_die
= NULL
;
10129 struct partial_die_info part_die
;
10131 part_die
.offset
= offset
;
10132 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
,
10138 /* Find a partial DIE at OFFSET, which may or may not be in CU,
10139 except in the case of .debug_types DIEs which do not reference
10140 outside their CU (they do however referencing other types via
10141 DW_FORM_ref_sig8). */
10143 static struct partial_die_info
*
10144 find_partial_die (sect_offset offset
, struct dwarf2_cu
*cu
)
10146 struct objfile
*objfile
= cu
->objfile
;
10147 struct dwarf2_per_cu_data
*per_cu
= NULL
;
10148 struct partial_die_info
*pd
= NULL
;
10150 if (offset_in_cu_p (&cu
->header
, offset
))
10152 pd
= find_partial_die_in_comp_unit (offset
, cu
);
10155 /* We missed recording what we needed.
10156 Load all dies and try again. */
10157 per_cu
= cu
->per_cu
;
10161 /* TUs don't reference other CUs/TUs (except via type signatures). */
10162 if (cu
->per_cu
->debug_types_section
)
10164 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
10165 " external reference to offset 0x%lx [in module %s].\n"),
10166 (long) cu
->header
.offset
.sect_off
, (long) offset
.sect_off
,
10167 bfd_get_filename (objfile
->obfd
));
10169 per_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
10171 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
10172 load_partial_comp_unit (per_cu
);
10174 per_cu
->cu
->last_used
= 0;
10175 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
10178 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
10180 struct cleanup
*back_to
;
10181 struct partial_die_info comp_unit_die
;
10182 struct abbrev_info
*abbrev
;
10183 unsigned int bytes_read
;
10185 struct dwarf2_section_info
*sec
;
10187 per_cu
->load_all_dies
= 1;
10189 if (per_cu
->debug_types_section
)
10190 sec
= per_cu
->debug_types_section
;
10192 sec
= &dwarf2_per_objfile
->info
;
10194 /* Re-read the DIEs, this time reading all of them.
10195 NOTE: We don't discard the previous set of DIEs.
10196 This doesn't happen very often so it's (hopefully) not a problem. */
10197 back_to
= make_cleanup (null_cleanup
, 0);
10198 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
10200 dwarf2_read_abbrevs (per_cu
->cu
);
10201 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
10203 info_ptr
= (sec
->buffer
10204 + per_cu
->cu
->header
.offset
.sect_off
10205 + per_cu
->cu
->header
.first_die_offset
.cu_off
);
10206 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
10207 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
10208 objfile
->obfd
, sec
->buffer
, info_ptr
,
10210 if (comp_unit_die
.has_children
)
10211 load_partial_dies (objfile
->obfd
, sec
->buffer
, info_ptr
, 0,
10213 do_cleanups (back_to
);
10215 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
10219 internal_error (__FILE__
, __LINE__
,
10220 _("could not find partial DIE 0x%x "
10221 "in cache [from module %s]\n"),
10222 offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
10226 /* See if we can figure out if the class lives in a namespace. We do
10227 this by looking for a member function; its demangled name will
10228 contain namespace info, if there is any. */
10231 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
10232 struct dwarf2_cu
*cu
)
10234 /* NOTE: carlton/2003-10-07: Getting the info this way changes
10235 what template types look like, because the demangler
10236 frequently doesn't give the same name as the debug info. We
10237 could fix this by only using the demangled name to get the
10238 prefix (but see comment in read_structure_type). */
10240 struct partial_die_info
*real_pdi
;
10241 struct partial_die_info
*child_pdi
;
10243 /* If this DIE (this DIE's specification, if any) has a parent, then
10244 we should not do this. We'll prepend the parent's fully qualified
10245 name when we create the partial symbol. */
10247 real_pdi
= struct_pdi
;
10248 while (real_pdi
->has_specification
)
10249 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
10251 if (real_pdi
->die_parent
!= NULL
)
10254 for (child_pdi
= struct_pdi
->die_child
;
10256 child_pdi
= child_pdi
->die_sibling
)
10258 if (child_pdi
->tag
== DW_TAG_subprogram
10259 && child_pdi
->linkage_name
!= NULL
)
10261 char *actual_class_name
10262 = language_class_name_from_physname (cu
->language_defn
,
10263 child_pdi
->linkage_name
);
10264 if (actual_class_name
!= NULL
)
10267 = obsavestring (actual_class_name
,
10268 strlen (actual_class_name
),
10269 &cu
->objfile
->objfile_obstack
);
10270 xfree (actual_class_name
);
10277 /* Adjust PART_DIE before generating a symbol for it. This function
10278 may set the is_external flag or change the DIE's name. */
10281 fixup_partial_die (struct partial_die_info
*part_die
,
10282 struct dwarf2_cu
*cu
)
10284 /* Once we've fixed up a die, there's no point in doing so again.
10285 This also avoids a memory leak if we were to call
10286 guess_partial_die_structure_name multiple times. */
10287 if (part_die
->fixup_called
)
10290 /* If we found a reference attribute and the DIE has no name, try
10291 to find a name in the referred to DIE. */
10293 if (part_die
->name
== NULL
&& part_die
->has_specification
)
10295 struct partial_die_info
*spec_die
;
10297 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
10299 fixup_partial_die (spec_die
, cu
);
10301 if (spec_die
->name
)
10303 part_die
->name
= spec_die
->name
;
10305 /* Copy DW_AT_external attribute if it is set. */
10306 if (spec_die
->is_external
)
10307 part_die
->is_external
= spec_die
->is_external
;
10311 /* Set default names for some unnamed DIEs. */
10313 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
10314 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
10316 /* If there is no parent die to provide a namespace, and there are
10317 children, see if we can determine the namespace from their linkage
10319 if (cu
->language
== language_cplus
10320 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
10321 && part_die
->die_parent
== NULL
10322 && part_die
->has_children
10323 && (part_die
->tag
== DW_TAG_class_type
10324 || part_die
->tag
== DW_TAG_structure_type
10325 || part_die
->tag
== DW_TAG_union_type
))
10326 guess_partial_die_structure_name (part_die
, cu
);
10328 /* GCC might emit a nameless struct or union that has a linkage
10329 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
10330 if (part_die
->name
== NULL
10331 && (part_die
->tag
== DW_TAG_class_type
10332 || part_die
->tag
== DW_TAG_interface_type
10333 || part_die
->tag
== DW_TAG_structure_type
10334 || part_die
->tag
== DW_TAG_union_type
)
10335 && part_die
->linkage_name
!= NULL
)
10339 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
10344 /* Strip any leading namespaces/classes, keep only the base name.
10345 DW_AT_name for named DIEs does not contain the prefixes. */
10346 base
= strrchr (demangled
, ':');
10347 if (base
&& base
> demangled
&& base
[-1] == ':')
10352 part_die
->name
= obsavestring (base
, strlen (base
),
10353 &cu
->objfile
->objfile_obstack
);
10358 part_die
->fixup_called
= 1;
10361 /* Read an attribute value described by an attribute form. */
10364 read_attribute_value (struct attribute
*attr
, unsigned form
,
10365 bfd
*abfd
, gdb_byte
*info_ptr
,
10366 struct dwarf2_cu
*cu
)
10368 struct comp_unit_head
*cu_header
= &cu
->header
;
10369 unsigned int bytes_read
;
10370 struct dwarf_block
*blk
;
10375 case DW_FORM_ref_addr
:
10376 if (cu
->header
.version
== 2)
10377 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
10379 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
10380 &cu
->header
, &bytes_read
);
10381 info_ptr
+= bytes_read
;
10384 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
10385 info_ptr
+= bytes_read
;
10387 case DW_FORM_block2
:
10388 blk
= dwarf_alloc_block (cu
);
10389 blk
->size
= read_2_bytes (abfd
, info_ptr
);
10391 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10392 info_ptr
+= blk
->size
;
10393 DW_BLOCK (attr
) = blk
;
10395 case DW_FORM_block4
:
10396 blk
= dwarf_alloc_block (cu
);
10397 blk
->size
= read_4_bytes (abfd
, info_ptr
);
10399 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10400 info_ptr
+= blk
->size
;
10401 DW_BLOCK (attr
) = blk
;
10403 case DW_FORM_data2
:
10404 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
10407 case DW_FORM_data4
:
10408 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
10411 case DW_FORM_data8
:
10412 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
10415 case DW_FORM_sec_offset
:
10416 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
10417 info_ptr
+= bytes_read
;
10419 case DW_FORM_string
:
10420 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
10421 DW_STRING_IS_CANONICAL (attr
) = 0;
10422 info_ptr
+= bytes_read
;
10425 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
10427 DW_STRING_IS_CANONICAL (attr
) = 0;
10428 info_ptr
+= bytes_read
;
10430 case DW_FORM_exprloc
:
10431 case DW_FORM_block
:
10432 blk
= dwarf_alloc_block (cu
);
10433 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10434 info_ptr
+= bytes_read
;
10435 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10436 info_ptr
+= blk
->size
;
10437 DW_BLOCK (attr
) = blk
;
10439 case DW_FORM_block1
:
10440 blk
= dwarf_alloc_block (cu
);
10441 blk
->size
= read_1_byte (abfd
, info_ptr
);
10443 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10444 info_ptr
+= blk
->size
;
10445 DW_BLOCK (attr
) = blk
;
10447 case DW_FORM_data1
:
10448 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
10452 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
10455 case DW_FORM_flag_present
:
10456 DW_UNSND (attr
) = 1;
10458 case DW_FORM_sdata
:
10459 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
10460 info_ptr
+= bytes_read
;
10462 case DW_FORM_udata
:
10463 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10464 info_ptr
+= bytes_read
;
10467 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
10468 + read_1_byte (abfd
, info_ptr
));
10472 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
10473 + read_2_bytes (abfd
, info_ptr
));
10477 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
10478 + read_4_bytes (abfd
, info_ptr
));
10482 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
10483 + read_8_bytes (abfd
, info_ptr
));
10486 case DW_FORM_ref_sig8
:
10487 /* Convert the signature to something we can record in DW_UNSND
10489 NOTE: This is NULL if the type wasn't found. */
10490 DW_SIGNATURED_TYPE (attr
) =
10491 lookup_signatured_type (read_8_bytes (abfd
, info_ptr
));
10494 case DW_FORM_ref_udata
:
10495 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
10496 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
10497 info_ptr
+= bytes_read
;
10499 case DW_FORM_indirect
:
10500 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10501 info_ptr
+= bytes_read
;
10502 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
10505 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
10506 dwarf_form_name (form
),
10507 bfd_get_filename (abfd
));
10510 /* We have seen instances where the compiler tried to emit a byte
10511 size attribute of -1 which ended up being encoded as an unsigned
10512 0xffffffff. Although 0xffffffff is technically a valid size value,
10513 an object of this size seems pretty unlikely so we can relatively
10514 safely treat these cases as if the size attribute was invalid and
10515 treat them as zero by default. */
10516 if (attr
->name
== DW_AT_byte_size
10517 && form
== DW_FORM_data4
10518 && DW_UNSND (attr
) >= 0xffffffff)
10521 (&symfile_complaints
,
10522 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
10523 hex_string (DW_UNSND (attr
)));
10524 DW_UNSND (attr
) = 0;
10530 /* Read an attribute described by an abbreviated attribute. */
10533 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
10534 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
10536 attr
->name
= abbrev
->name
;
10537 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
10540 /* Read dwarf information from a buffer. */
10542 static unsigned int
10543 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
10545 return bfd_get_8 (abfd
, buf
);
10549 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
10551 return bfd_get_signed_8 (abfd
, buf
);
10554 static unsigned int
10555 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
10557 return bfd_get_16 (abfd
, buf
);
10561 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
10563 return bfd_get_signed_16 (abfd
, buf
);
10566 static unsigned int
10567 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
10569 return bfd_get_32 (abfd
, buf
);
10573 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
10575 return bfd_get_signed_32 (abfd
, buf
);
10579 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
10581 return bfd_get_64 (abfd
, buf
);
10585 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
10586 unsigned int *bytes_read
)
10588 struct comp_unit_head
*cu_header
= &cu
->header
;
10589 CORE_ADDR retval
= 0;
10591 if (cu_header
->signed_addr_p
)
10593 switch (cu_header
->addr_size
)
10596 retval
= bfd_get_signed_16 (abfd
, buf
);
10599 retval
= bfd_get_signed_32 (abfd
, buf
);
10602 retval
= bfd_get_signed_64 (abfd
, buf
);
10605 internal_error (__FILE__
, __LINE__
,
10606 _("read_address: bad switch, signed [in module %s]"),
10607 bfd_get_filename (abfd
));
10612 switch (cu_header
->addr_size
)
10615 retval
= bfd_get_16 (abfd
, buf
);
10618 retval
= bfd_get_32 (abfd
, buf
);
10621 retval
= bfd_get_64 (abfd
, buf
);
10624 internal_error (__FILE__
, __LINE__
,
10625 _("read_address: bad switch, "
10626 "unsigned [in module %s]"),
10627 bfd_get_filename (abfd
));
10631 *bytes_read
= cu_header
->addr_size
;
10635 /* Read the initial length from a section. The (draft) DWARF 3
10636 specification allows the initial length to take up either 4 bytes
10637 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
10638 bytes describe the length and all offsets will be 8 bytes in length
10641 An older, non-standard 64-bit format is also handled by this
10642 function. The older format in question stores the initial length
10643 as an 8-byte quantity without an escape value. Lengths greater
10644 than 2^32 aren't very common which means that the initial 4 bytes
10645 is almost always zero. Since a length value of zero doesn't make
10646 sense for the 32-bit format, this initial zero can be considered to
10647 be an escape value which indicates the presence of the older 64-bit
10648 format. As written, the code can't detect (old format) lengths
10649 greater than 4GB. If it becomes necessary to handle lengths
10650 somewhat larger than 4GB, we could allow other small values (such
10651 as the non-sensical values of 1, 2, and 3) to also be used as
10652 escape values indicating the presence of the old format.
10654 The value returned via bytes_read should be used to increment the
10655 relevant pointer after calling read_initial_length().
10657 [ Note: read_initial_length() and read_offset() are based on the
10658 document entitled "DWARF Debugging Information Format", revision
10659 3, draft 8, dated November 19, 2001. This document was obtained
10662 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
10664 This document is only a draft and is subject to change. (So beware.)
10666 Details regarding the older, non-standard 64-bit format were
10667 determined empirically by examining 64-bit ELF files produced by
10668 the SGI toolchain on an IRIX 6.5 machine.
10670 - Kevin, July 16, 2002
10674 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
10676 LONGEST length
= bfd_get_32 (abfd
, buf
);
10678 if (length
== 0xffffffff)
10680 length
= bfd_get_64 (abfd
, buf
+ 4);
10683 else if (length
== 0)
10685 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
10686 length
= bfd_get_64 (abfd
, buf
);
10697 /* Cover function for read_initial_length.
10698 Returns the length of the object at BUF, and stores the size of the
10699 initial length in *BYTES_READ and stores the size that offsets will be in
10701 If the initial length size is not equivalent to that specified in
10702 CU_HEADER then issue a complaint.
10703 This is useful when reading non-comp-unit headers. */
10706 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
10707 const struct comp_unit_head
*cu_header
,
10708 unsigned int *bytes_read
,
10709 unsigned int *offset_size
)
10711 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
10713 gdb_assert (cu_header
->initial_length_size
== 4
10714 || cu_header
->initial_length_size
== 8
10715 || cu_header
->initial_length_size
== 12);
10717 if (cu_header
->initial_length_size
!= *bytes_read
)
10718 complaint (&symfile_complaints
,
10719 _("intermixed 32-bit and 64-bit DWARF sections"));
10721 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
10725 /* Read an offset from the data stream. The size of the offset is
10726 given by cu_header->offset_size. */
10729 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
10730 unsigned int *bytes_read
)
10732 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
10734 *bytes_read
= cu_header
->offset_size
;
10738 /* Read an offset from the data stream. */
10741 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
10743 LONGEST retval
= 0;
10745 switch (offset_size
)
10748 retval
= bfd_get_32 (abfd
, buf
);
10751 retval
= bfd_get_64 (abfd
, buf
);
10754 internal_error (__FILE__
, __LINE__
,
10755 _("read_offset_1: bad switch [in module %s]"),
10756 bfd_get_filename (abfd
));
10763 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
10765 /* If the size of a host char is 8 bits, we can return a pointer
10766 to the buffer, otherwise we have to copy the data to a buffer
10767 allocated on the temporary obstack. */
10768 gdb_assert (HOST_CHAR_BIT
== 8);
10773 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10775 /* If the size of a host char is 8 bits, we can return a pointer
10776 to the string, otherwise we have to copy the string to a buffer
10777 allocated on the temporary obstack. */
10778 gdb_assert (HOST_CHAR_BIT
== 8);
10781 *bytes_read_ptr
= 1;
10784 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
10785 return (char *) buf
;
10789 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
10791 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
10792 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
10793 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
10794 bfd_get_filename (abfd
));
10795 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
10796 error (_("DW_FORM_strp pointing outside of "
10797 ".debug_str section [in module %s]"),
10798 bfd_get_filename (abfd
));
10799 gdb_assert (HOST_CHAR_BIT
== 8);
10800 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
10802 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
10806 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
10807 const struct comp_unit_head
*cu_header
,
10808 unsigned int *bytes_read_ptr
)
10810 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
10812 return read_indirect_string_at_offset (abfd
, str_offset
);
10816 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10819 unsigned int num_read
;
10821 unsigned char byte
;
10829 byte
= bfd_get_8 (abfd
, buf
);
10832 result
|= ((ULONGEST
) (byte
& 127) << shift
);
10833 if ((byte
& 128) == 0)
10839 *bytes_read_ptr
= num_read
;
10844 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10847 int i
, shift
, num_read
;
10848 unsigned char byte
;
10856 byte
= bfd_get_8 (abfd
, buf
);
10859 result
|= ((LONGEST
) (byte
& 127) << shift
);
10861 if ((byte
& 128) == 0)
10866 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
10867 result
|= -(((LONGEST
) 1) << shift
);
10868 *bytes_read_ptr
= num_read
;
10872 /* Return a pointer to just past the end of an LEB128 number in BUF. */
10875 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
10881 byte
= bfd_get_8 (abfd
, buf
);
10883 if ((byte
& 128) == 0)
10889 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
10896 cu
->language
= language_c
;
10898 case DW_LANG_C_plus_plus
:
10899 cu
->language
= language_cplus
;
10902 cu
->language
= language_d
;
10904 case DW_LANG_Fortran77
:
10905 case DW_LANG_Fortran90
:
10906 case DW_LANG_Fortran95
:
10907 cu
->language
= language_fortran
;
10910 cu
->language
= language_go
;
10912 case DW_LANG_Mips_Assembler
:
10913 cu
->language
= language_asm
;
10916 cu
->language
= language_java
;
10918 case DW_LANG_Ada83
:
10919 case DW_LANG_Ada95
:
10920 cu
->language
= language_ada
;
10922 case DW_LANG_Modula2
:
10923 cu
->language
= language_m2
;
10925 case DW_LANG_Pascal83
:
10926 cu
->language
= language_pascal
;
10929 cu
->language
= language_objc
;
10931 case DW_LANG_Cobol74
:
10932 case DW_LANG_Cobol85
:
10934 cu
->language
= language_minimal
;
10937 cu
->language_defn
= language_def (cu
->language
);
10940 /* Return the named attribute or NULL if not there. */
10942 static struct attribute
*
10943 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
10948 struct attribute
*spec
= NULL
;
10950 for (i
= 0; i
< die
->num_attrs
; ++i
)
10952 if (die
->attrs
[i
].name
== name
)
10953 return &die
->attrs
[i
];
10954 if (die
->attrs
[i
].name
== DW_AT_specification
10955 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
10956 spec
= &die
->attrs
[i
];
10962 die
= follow_die_ref (die
, spec
, &cu
);
10968 /* Return the named attribute or NULL if not there,
10969 but do not follow DW_AT_specification, etc.
10970 This is for use in contexts where we're reading .debug_types dies.
10971 Following DW_AT_specification, DW_AT_abstract_origin will take us
10972 back up the chain, and we want to go down. */
10974 static struct attribute
*
10975 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
10976 struct dwarf2_cu
*cu
)
10980 for (i
= 0; i
< die
->num_attrs
; ++i
)
10981 if (die
->attrs
[i
].name
== name
)
10982 return &die
->attrs
[i
];
10987 /* Return non-zero iff the attribute NAME is defined for the given DIE,
10988 and holds a non-zero value. This function should only be used for
10989 DW_FORM_flag or DW_FORM_flag_present attributes. */
10992 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
10994 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
10996 return (attr
&& DW_UNSND (attr
));
11000 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
11002 /* A DIE is a declaration if it has a DW_AT_declaration attribute
11003 which value is non-zero. However, we have to be careful with
11004 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
11005 (via dwarf2_flag_true_p) follows this attribute. So we may
11006 end up accidently finding a declaration attribute that belongs
11007 to a different DIE referenced by the specification attribute,
11008 even though the given DIE does not have a declaration attribute. */
11009 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
11010 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
11013 /* Return the die giving the specification for DIE, if there is
11014 one. *SPEC_CU is the CU containing DIE on input, and the CU
11015 containing the return value on output. If there is no
11016 specification, but there is an abstract origin, that is
11019 static struct die_info
*
11020 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
11022 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
11025 if (spec_attr
== NULL
)
11026 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
11028 if (spec_attr
== NULL
)
11031 return follow_die_ref (die
, spec_attr
, spec_cu
);
11034 /* Free the line_header structure *LH, and any arrays and strings it
11036 NOTE: This is also used as a "cleanup" function. */
11039 free_line_header (struct line_header
*lh
)
11041 if (lh
->standard_opcode_lengths
)
11042 xfree (lh
->standard_opcode_lengths
);
11044 /* Remember that all the lh->file_names[i].name pointers are
11045 pointers into debug_line_buffer, and don't need to be freed. */
11046 if (lh
->file_names
)
11047 xfree (lh
->file_names
);
11049 /* Similarly for the include directory names. */
11050 if (lh
->include_dirs
)
11051 xfree (lh
->include_dirs
);
11056 /* Add an entry to LH's include directory table. */
11059 add_include_dir (struct line_header
*lh
, char *include_dir
)
11061 /* Grow the array if necessary. */
11062 if (lh
->include_dirs_size
== 0)
11064 lh
->include_dirs_size
= 1; /* for testing */
11065 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
11066 * sizeof (*lh
->include_dirs
));
11068 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
11070 lh
->include_dirs_size
*= 2;
11071 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
11072 (lh
->include_dirs_size
11073 * sizeof (*lh
->include_dirs
)));
11076 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
11079 /* Add an entry to LH's file name table. */
11082 add_file_name (struct line_header
*lh
,
11084 unsigned int dir_index
,
11085 unsigned int mod_time
,
11086 unsigned int length
)
11088 struct file_entry
*fe
;
11090 /* Grow the array if necessary. */
11091 if (lh
->file_names_size
== 0)
11093 lh
->file_names_size
= 1; /* for testing */
11094 lh
->file_names
= xmalloc (lh
->file_names_size
11095 * sizeof (*lh
->file_names
));
11097 else if (lh
->num_file_names
>= lh
->file_names_size
)
11099 lh
->file_names_size
*= 2;
11100 lh
->file_names
= xrealloc (lh
->file_names
,
11101 (lh
->file_names_size
11102 * sizeof (*lh
->file_names
)));
11105 fe
= &lh
->file_names
[lh
->num_file_names
++];
11107 fe
->dir_index
= dir_index
;
11108 fe
->mod_time
= mod_time
;
11109 fe
->length
= length
;
11110 fe
->included_p
= 0;
11114 /* Read the statement program header starting at OFFSET in
11115 .debug_line, according to the endianness of ABFD. Return a pointer
11116 to a struct line_header, allocated using xmalloc.
11118 NOTE: the strings in the include directory and file name tables of
11119 the returned object point into debug_line_buffer, and must not be
11122 static struct line_header
*
11123 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
11124 struct dwarf2_cu
*cu
)
11126 struct cleanup
*back_to
;
11127 struct line_header
*lh
;
11128 gdb_byte
*line_ptr
;
11129 unsigned int bytes_read
, offset_size
;
11131 char *cur_dir
, *cur_file
;
11133 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
11134 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
11136 complaint (&symfile_complaints
, _("missing .debug_line section"));
11140 /* Make sure that at least there's room for the total_length field.
11141 That could be 12 bytes long, but we're just going to fudge that. */
11142 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
11144 dwarf2_statement_list_fits_in_line_number_section_complaint ();
11148 lh
= xmalloc (sizeof (*lh
));
11149 memset (lh
, 0, sizeof (*lh
));
11150 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
11153 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
11155 /* Read in the header. */
11157 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
11158 &bytes_read
, &offset_size
);
11159 line_ptr
+= bytes_read
;
11160 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
11161 + dwarf2_per_objfile
->line
.size
))
11163 dwarf2_statement_list_fits_in_line_number_section_complaint ();
11166 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
11167 lh
->version
= read_2_bytes (abfd
, line_ptr
);
11169 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
11170 line_ptr
+= offset_size
;
11171 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
11173 if (lh
->version
>= 4)
11175 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
11179 lh
->maximum_ops_per_instruction
= 1;
11181 if (lh
->maximum_ops_per_instruction
== 0)
11183 lh
->maximum_ops_per_instruction
= 1;
11184 complaint (&symfile_complaints
,
11185 _("invalid maximum_ops_per_instruction "
11186 "in `.debug_line' section"));
11189 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
11191 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
11193 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
11195 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
11197 lh
->standard_opcode_lengths
11198 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
11200 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
11201 for (i
= 1; i
< lh
->opcode_base
; ++i
)
11203 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
11207 /* Read directory table. */
11208 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
11210 line_ptr
+= bytes_read
;
11211 add_include_dir (lh
, cur_dir
);
11213 line_ptr
+= bytes_read
;
11215 /* Read file name table. */
11216 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
11218 unsigned int dir_index
, mod_time
, length
;
11220 line_ptr
+= bytes_read
;
11221 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11222 line_ptr
+= bytes_read
;
11223 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11224 line_ptr
+= bytes_read
;
11225 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11226 line_ptr
+= bytes_read
;
11228 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
11230 line_ptr
+= bytes_read
;
11231 lh
->statement_program_start
= line_ptr
;
11233 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
11234 + dwarf2_per_objfile
->line
.size
))
11235 complaint (&symfile_complaints
,
11236 _("line number info header doesn't "
11237 "fit in `.debug_line' section"));
11239 discard_cleanups (back_to
);
11243 /* Subroutine of dwarf_decode_lines to simplify it.
11244 Return the file name of the psymtab for included file FILE_INDEX
11245 in line header LH of PST.
11246 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
11247 If space for the result is malloc'd, it will be freed by a cleanup.
11248 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
11251 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
11252 const struct partial_symtab
*pst
,
11253 const char *comp_dir
)
11255 const struct file_entry fe
= lh
->file_names
[file_index
];
11256 char *include_name
= fe
.name
;
11257 char *include_name_to_compare
= include_name
;
11258 char *dir_name
= NULL
;
11259 const char *pst_filename
;
11260 char *copied_name
= NULL
;
11264 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
11266 if (!IS_ABSOLUTE_PATH (include_name
)
11267 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
11269 /* Avoid creating a duplicate psymtab for PST.
11270 We do this by comparing INCLUDE_NAME and PST_FILENAME.
11271 Before we do the comparison, however, we need to account
11272 for DIR_NAME and COMP_DIR.
11273 First prepend dir_name (if non-NULL). If we still don't
11274 have an absolute path prepend comp_dir (if non-NULL).
11275 However, the directory we record in the include-file's
11276 psymtab does not contain COMP_DIR (to match the
11277 corresponding symtab(s)).
11282 bash$ gcc -g ./hello.c
11283 include_name = "hello.c"
11285 DW_AT_comp_dir = comp_dir = "/tmp"
11286 DW_AT_name = "./hello.c" */
11288 if (dir_name
!= NULL
)
11290 include_name
= concat (dir_name
, SLASH_STRING
,
11291 include_name
, (char *)NULL
);
11292 include_name_to_compare
= include_name
;
11293 make_cleanup (xfree
, include_name
);
11295 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
11297 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
11298 include_name
, (char *)NULL
);
11302 pst_filename
= pst
->filename
;
11303 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
11305 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
11306 pst_filename
, (char *)NULL
);
11307 pst_filename
= copied_name
;
11310 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
11312 if (include_name_to_compare
!= include_name
)
11313 xfree (include_name_to_compare
);
11314 if (copied_name
!= NULL
)
11315 xfree (copied_name
);
11319 return include_name
;
11322 /* Ignore this record_line request. */
11325 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
11330 /* Subroutine of dwarf_decode_lines to simplify it.
11331 Process the line number information in LH. */
11334 dwarf_decode_lines_1 (struct line_header
*lh
, const char *comp_dir
,
11335 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
11337 gdb_byte
*line_ptr
, *extended_end
;
11338 gdb_byte
*line_end
;
11339 unsigned int bytes_read
, extended_len
;
11340 unsigned char op_code
, extended_op
, adj_opcode
;
11341 CORE_ADDR baseaddr
;
11342 struct objfile
*objfile
= cu
->objfile
;
11343 bfd
*abfd
= objfile
->obfd
;
11344 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11345 const int decode_for_pst_p
= (pst
!= NULL
);
11346 struct subfile
*last_subfile
= NULL
;
11347 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
11350 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11352 line_ptr
= lh
->statement_program_start
;
11353 line_end
= lh
->statement_program_end
;
11355 /* Read the statement sequences until there's nothing left. */
11356 while (line_ptr
< line_end
)
11358 /* state machine registers */
11359 CORE_ADDR address
= 0;
11360 unsigned int file
= 1;
11361 unsigned int line
= 1;
11362 unsigned int column
= 0;
11363 int is_stmt
= lh
->default_is_stmt
;
11364 int basic_block
= 0;
11365 int end_sequence
= 0;
11367 unsigned char op_index
= 0;
11369 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
11371 /* Start a subfile for the current file of the state machine. */
11372 /* lh->include_dirs and lh->file_names are 0-based, but the
11373 directory and file name numbers in the statement program
11375 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
11379 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11381 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11384 /* Decode the table. */
11385 while (!end_sequence
)
11387 op_code
= read_1_byte (abfd
, line_ptr
);
11389 if (line_ptr
> line_end
)
11391 dwarf2_debug_line_missing_end_sequence_complaint ();
11395 if (op_code
>= lh
->opcode_base
)
11397 /* Special operand. */
11398 adj_opcode
= op_code
- lh
->opcode_base
;
11399 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
11400 / lh
->maximum_ops_per_instruction
)
11401 * lh
->minimum_instruction_length
);
11402 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
11403 % lh
->maximum_ops_per_instruction
);
11404 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
11405 if (lh
->num_file_names
< file
|| file
== 0)
11406 dwarf2_debug_line_missing_file_complaint ();
11407 /* For now we ignore lines not starting on an
11408 instruction boundary. */
11409 else if (op_index
== 0)
11411 lh
->file_names
[file
- 1].included_p
= 1;
11412 if (!decode_for_pst_p
&& is_stmt
)
11414 if (last_subfile
!= current_subfile
)
11416 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11418 (*p_record_line
) (last_subfile
, 0, addr
);
11419 last_subfile
= current_subfile
;
11421 /* Append row to matrix using current values. */
11422 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11423 (*p_record_line
) (current_subfile
, line
, addr
);
11428 else switch (op_code
)
11430 case DW_LNS_extended_op
:
11431 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
11433 line_ptr
+= bytes_read
;
11434 extended_end
= line_ptr
+ extended_len
;
11435 extended_op
= read_1_byte (abfd
, line_ptr
);
11437 switch (extended_op
)
11439 case DW_LNE_end_sequence
:
11440 p_record_line
= record_line
;
11443 case DW_LNE_set_address
:
11444 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
11446 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
11448 /* This line table is for a function which has been
11449 GCd by the linker. Ignore it. PR gdb/12528 */
11452 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
11454 complaint (&symfile_complaints
,
11455 _(".debug_line address at offset 0x%lx is 0 "
11457 line_offset
, objfile
->name
);
11458 p_record_line
= noop_record_line
;
11462 line_ptr
+= bytes_read
;
11463 address
+= baseaddr
;
11465 case DW_LNE_define_file
:
11468 unsigned int dir_index
, mod_time
, length
;
11470 cur_file
= read_direct_string (abfd
, line_ptr
,
11472 line_ptr
+= bytes_read
;
11474 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11475 line_ptr
+= bytes_read
;
11477 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11478 line_ptr
+= bytes_read
;
11480 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11481 line_ptr
+= bytes_read
;
11482 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
11485 case DW_LNE_set_discriminator
:
11486 /* The discriminator is not interesting to the debugger;
11488 line_ptr
= extended_end
;
11491 complaint (&symfile_complaints
,
11492 _("mangled .debug_line section"));
11495 /* Make sure that we parsed the extended op correctly. If e.g.
11496 we expected a different address size than the producer used,
11497 we may have read the wrong number of bytes. */
11498 if (line_ptr
!= extended_end
)
11500 complaint (&symfile_complaints
,
11501 _("mangled .debug_line section"));
11506 if (lh
->num_file_names
< file
|| file
== 0)
11507 dwarf2_debug_line_missing_file_complaint ();
11510 lh
->file_names
[file
- 1].included_p
= 1;
11511 if (!decode_for_pst_p
&& is_stmt
)
11513 if (last_subfile
!= current_subfile
)
11515 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11517 (*p_record_line
) (last_subfile
, 0, addr
);
11518 last_subfile
= current_subfile
;
11520 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11521 (*p_record_line
) (current_subfile
, line
, addr
);
11526 case DW_LNS_advance_pc
:
11529 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11531 address
+= (((op_index
+ adjust
)
11532 / lh
->maximum_ops_per_instruction
)
11533 * lh
->minimum_instruction_length
);
11534 op_index
= ((op_index
+ adjust
)
11535 % lh
->maximum_ops_per_instruction
);
11536 line_ptr
+= bytes_read
;
11539 case DW_LNS_advance_line
:
11540 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
11541 line_ptr
+= bytes_read
;
11543 case DW_LNS_set_file
:
11545 /* The arrays lh->include_dirs and lh->file_names are
11546 0-based, but the directory and file name numbers in
11547 the statement program are 1-based. */
11548 struct file_entry
*fe
;
11551 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11552 line_ptr
+= bytes_read
;
11553 if (lh
->num_file_names
< file
|| file
== 0)
11554 dwarf2_debug_line_missing_file_complaint ();
11557 fe
= &lh
->file_names
[file
- 1];
11559 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11560 if (!decode_for_pst_p
)
11562 last_subfile
= current_subfile
;
11563 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11568 case DW_LNS_set_column
:
11569 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11570 line_ptr
+= bytes_read
;
11572 case DW_LNS_negate_stmt
:
11573 is_stmt
= (!is_stmt
);
11575 case DW_LNS_set_basic_block
:
11578 /* Add to the address register of the state machine the
11579 address increment value corresponding to special opcode
11580 255. I.e., this value is scaled by the minimum
11581 instruction length since special opcode 255 would have
11582 scaled the increment. */
11583 case DW_LNS_const_add_pc
:
11585 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
11587 address
+= (((op_index
+ adjust
)
11588 / lh
->maximum_ops_per_instruction
)
11589 * lh
->minimum_instruction_length
);
11590 op_index
= ((op_index
+ adjust
)
11591 % lh
->maximum_ops_per_instruction
);
11594 case DW_LNS_fixed_advance_pc
:
11595 address
+= read_2_bytes (abfd
, line_ptr
);
11601 /* Unknown standard opcode, ignore it. */
11604 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
11606 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11607 line_ptr
+= bytes_read
;
11612 if (lh
->num_file_names
< file
|| file
== 0)
11613 dwarf2_debug_line_missing_file_complaint ();
11616 lh
->file_names
[file
- 1].included_p
= 1;
11617 if (!decode_for_pst_p
)
11619 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11620 (*p_record_line
) (current_subfile
, 0, addr
);
11626 /* Decode the Line Number Program (LNP) for the given line_header
11627 structure and CU. The actual information extracted and the type
11628 of structures created from the LNP depends on the value of PST.
11630 1. If PST is NULL, then this procedure uses the data from the program
11631 to create all necessary symbol tables, and their linetables.
11633 2. If PST is not NULL, this procedure reads the program to determine
11634 the list of files included by the unit represented by PST, and
11635 builds all the associated partial symbol tables.
11637 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
11638 It is used for relative paths in the line table.
11639 NOTE: When processing partial symtabs (pst != NULL),
11640 comp_dir == pst->dirname.
11642 NOTE: It is important that psymtabs have the same file name (via strcmp)
11643 as the corresponding symtab. Since COMP_DIR is not used in the name of the
11644 symtab we don't use it in the name of the psymtabs we create.
11645 E.g. expand_line_sal requires this when finding psymtabs to expand.
11646 A good testcase for this is mb-inline.exp. */
11649 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
11650 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
11651 int want_line_info
)
11653 struct objfile
*objfile
= cu
->objfile
;
11654 const int decode_for_pst_p
= (pst
!= NULL
);
11655 struct subfile
*first_subfile
= current_subfile
;
11657 if (want_line_info
)
11658 dwarf_decode_lines_1 (lh
, comp_dir
, cu
, pst
);
11660 if (decode_for_pst_p
)
11664 /* Now that we're done scanning the Line Header Program, we can
11665 create the psymtab of each included file. */
11666 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
11667 if (lh
->file_names
[file_index
].included_p
== 1)
11669 char *include_name
=
11670 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
11671 if (include_name
!= NULL
)
11672 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
11677 /* Make sure a symtab is created for every file, even files
11678 which contain only variables (i.e. no code with associated
11682 for (i
= 0; i
< lh
->num_file_names
; i
++)
11685 struct file_entry
*fe
;
11687 fe
= &lh
->file_names
[i
];
11689 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11690 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11692 /* Skip the main file; we don't need it, and it must be
11693 allocated last, so that it will show up before the
11694 non-primary symtabs in the objfile's symtab list. */
11695 if (current_subfile
== first_subfile
)
11698 if (current_subfile
->symtab
== NULL
)
11699 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
11701 fe
->symtab
= current_subfile
->symtab
;
11706 /* Start a subfile for DWARF. FILENAME is the name of the file and
11707 DIRNAME the name of the source directory which contains FILENAME
11708 or NULL if not known. COMP_DIR is the compilation directory for the
11709 linetable's compilation unit or NULL if not known.
11710 This routine tries to keep line numbers from identical absolute and
11711 relative file names in a common subfile.
11713 Using the `list' example from the GDB testsuite, which resides in
11714 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
11715 of /srcdir/list0.c yields the following debugging information for list0.c:
11717 DW_AT_name: /srcdir/list0.c
11718 DW_AT_comp_dir: /compdir
11719 files.files[0].name: list0.h
11720 files.files[0].dir: /srcdir
11721 files.files[1].name: list0.c
11722 files.files[1].dir: /srcdir
11724 The line number information for list0.c has to end up in a single
11725 subfile, so that `break /srcdir/list0.c:1' works as expected.
11726 start_subfile will ensure that this happens provided that we pass the
11727 concatenation of files.files[1].dir and files.files[1].name as the
11731 dwarf2_start_subfile (char *filename
, const char *dirname
,
11732 const char *comp_dir
)
11736 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
11737 `start_symtab' will always pass the contents of DW_AT_comp_dir as
11738 second argument to start_subfile. To be consistent, we do the
11739 same here. In order not to lose the line information directory,
11740 we concatenate it to the filename when it makes sense.
11741 Note that the Dwarf3 standard says (speaking of filenames in line
11742 information): ``The directory index is ignored for file names
11743 that represent full path names''. Thus ignoring dirname in the
11744 `else' branch below isn't an issue. */
11746 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
11747 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
11749 fullname
= filename
;
11751 start_subfile (fullname
, comp_dir
);
11753 if (fullname
!= filename
)
11758 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
11759 struct dwarf2_cu
*cu
)
11761 struct objfile
*objfile
= cu
->objfile
;
11762 struct comp_unit_head
*cu_header
= &cu
->header
;
11764 /* NOTE drow/2003-01-30: There used to be a comment and some special
11765 code here to turn a symbol with DW_AT_external and a
11766 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
11767 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
11768 with some versions of binutils) where shared libraries could have
11769 relocations against symbols in their debug information - the
11770 minimal symbol would have the right address, but the debug info
11771 would not. It's no longer necessary, because we will explicitly
11772 apply relocations when we read in the debug information now. */
11774 /* A DW_AT_location attribute with no contents indicates that a
11775 variable has been optimized away. */
11776 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
11778 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11782 /* Handle one degenerate form of location expression specially, to
11783 preserve GDB's previous behavior when section offsets are
11784 specified. If this is just a DW_OP_addr then mark this symbol
11787 if (attr_form_is_block (attr
)
11788 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
11789 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
11791 unsigned int dummy
;
11793 SYMBOL_VALUE_ADDRESS (sym
) =
11794 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
11795 SYMBOL_CLASS (sym
) = LOC_STATIC
;
11796 fixup_symbol_section (sym
, objfile
);
11797 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
11798 SYMBOL_SECTION (sym
));
11802 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
11803 expression evaluator, and use LOC_COMPUTED only when necessary
11804 (i.e. when the value of a register or memory location is
11805 referenced, or a thread-local block, etc.). Then again, it might
11806 not be worthwhile. I'm assuming that it isn't unless performance
11807 or memory numbers show me otherwise. */
11809 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
11810 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11812 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
11813 cu
->has_loclist
= 1;
11816 /* Given a pointer to a DWARF information entry, figure out if we need
11817 to make a symbol table entry for it, and if so, create a new entry
11818 and return a pointer to it.
11819 If TYPE is NULL, determine symbol type from the die, otherwise
11820 used the passed type.
11821 If SPACE is not NULL, use it to hold the new symbol. If it is
11822 NULL, allocate a new symbol on the objfile's obstack. */
11824 static struct symbol
*
11825 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
11826 struct symbol
*space
)
11828 struct objfile
*objfile
= cu
->objfile
;
11829 struct symbol
*sym
= NULL
;
11831 struct attribute
*attr
= NULL
;
11832 struct attribute
*attr2
= NULL
;
11833 CORE_ADDR baseaddr
;
11834 struct pending
**list_to_add
= NULL
;
11836 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
11838 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11840 name
= dwarf2_name (die
, cu
);
11843 const char *linkagename
;
11844 int suppress_add
= 0;
11849 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
11850 OBJSTAT (objfile
, n_syms
++);
11852 /* Cache this symbol's name and the name's demangled form (if any). */
11853 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
11854 linkagename
= dwarf2_physname (name
, die
, cu
);
11855 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
11857 /* Fortran does not have mangling standard and the mangling does differ
11858 between gfortran, iFort etc. */
11859 if (cu
->language
== language_fortran
11860 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
11861 symbol_set_demangled_name (&(sym
->ginfo
),
11862 (char *) dwarf2_full_name (name
, die
, cu
),
11865 /* Default assumptions.
11866 Use the passed type or decode it from the die. */
11867 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11868 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11870 SYMBOL_TYPE (sym
) = type
;
11872 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
11873 attr
= dwarf2_attr (die
,
11874 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
11878 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
11881 attr
= dwarf2_attr (die
,
11882 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
11886 int file_index
= DW_UNSND (attr
);
11888 if (cu
->line_header
== NULL
11889 || file_index
> cu
->line_header
->num_file_names
)
11890 complaint (&symfile_complaints
,
11891 _("file index out of range"));
11892 else if (file_index
> 0)
11894 struct file_entry
*fe
;
11896 fe
= &cu
->line_header
->file_names
[file_index
- 1];
11897 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
11904 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11907 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
11909 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
11910 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
11911 SYMBOL_CLASS (sym
) = LOC_LABEL
;
11912 add_symbol_to_list (sym
, cu
->list_in_scope
);
11914 case DW_TAG_subprogram
:
11915 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11917 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11918 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11919 if ((attr2
&& (DW_UNSND (attr2
) != 0))
11920 || cu
->language
== language_ada
)
11922 /* Subprograms marked external are stored as a global symbol.
11923 Ada subprograms, whether marked external or not, are always
11924 stored as a global symbol, because we want to be able to
11925 access them globally. For instance, we want to be able
11926 to break on a nested subprogram without having to
11927 specify the context. */
11928 list_to_add
= &global_symbols
;
11932 list_to_add
= cu
->list_in_scope
;
11935 case DW_TAG_inlined_subroutine
:
11936 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11938 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11939 SYMBOL_INLINED (sym
) = 1;
11940 list_to_add
= cu
->list_in_scope
;
11942 case DW_TAG_template_value_param
:
11944 /* Fall through. */
11945 case DW_TAG_constant
:
11946 case DW_TAG_variable
:
11947 case DW_TAG_member
:
11948 /* Compilation with minimal debug info may result in
11949 variables with missing type entries. Change the
11950 misleading `void' type to something sensible. */
11951 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
11953 = objfile_type (objfile
)->nodebug_data_symbol
;
11955 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11956 /* In the case of DW_TAG_member, we should only be called for
11957 static const members. */
11958 if (die
->tag
== DW_TAG_member
)
11960 /* dwarf2_add_field uses die_is_declaration,
11961 so we do the same. */
11962 gdb_assert (die_is_declaration (die
, cu
));
11967 dwarf2_const_value (attr
, sym
, cu
);
11968 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11971 if (attr2
&& (DW_UNSND (attr2
) != 0))
11972 list_to_add
= &global_symbols
;
11974 list_to_add
= cu
->list_in_scope
;
11978 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11981 var_decode_location (attr
, sym
, cu
);
11982 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11983 if (SYMBOL_CLASS (sym
) == LOC_STATIC
11984 && SYMBOL_VALUE_ADDRESS (sym
) == 0
11985 && !dwarf2_per_objfile
->has_section_at_zero
)
11987 /* When a static variable is eliminated by the linker,
11988 the corresponding debug information is not stripped
11989 out, but the variable address is set to null;
11990 do not add such variables into symbol table. */
11992 else if (attr2
&& (DW_UNSND (attr2
) != 0))
11994 /* Workaround gfortran PR debug/40040 - it uses
11995 DW_AT_location for variables in -fPIC libraries which may
11996 get overriden by other libraries/executable and get
11997 a different address. Resolve it by the minimal symbol
11998 which may come from inferior's executable using copy
11999 relocation. Make this workaround only for gfortran as for
12000 other compilers GDB cannot guess the minimal symbol
12001 Fortran mangling kind. */
12002 if (cu
->language
== language_fortran
&& die
->parent
12003 && die
->parent
->tag
== DW_TAG_module
12005 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
12006 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
12008 /* A variable with DW_AT_external is never static,
12009 but it may be block-scoped. */
12010 list_to_add
= (cu
->list_in_scope
== &file_symbols
12011 ? &global_symbols
: cu
->list_in_scope
);
12014 list_to_add
= cu
->list_in_scope
;
12018 /* We do not know the address of this symbol.
12019 If it is an external symbol and we have type information
12020 for it, enter the symbol as a LOC_UNRESOLVED symbol.
12021 The address of the variable will then be determined from
12022 the minimal symbol table whenever the variable is
12024 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
12025 if (attr2
&& (DW_UNSND (attr2
) != 0)
12026 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
12028 /* A variable with DW_AT_external is never static, but it
12029 may be block-scoped. */
12030 list_to_add
= (cu
->list_in_scope
== &file_symbols
12031 ? &global_symbols
: cu
->list_in_scope
);
12033 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
12035 else if (!die_is_declaration (die
, cu
))
12037 /* Use the default LOC_OPTIMIZED_OUT class. */
12038 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
12040 list_to_add
= cu
->list_in_scope
;
12044 case DW_TAG_formal_parameter
:
12045 /* If we are inside a function, mark this as an argument. If
12046 not, we might be looking at an argument to an inlined function
12047 when we do not have enough information to show inlined frames;
12048 pretend it's a local variable in that case so that the user can
12050 if (context_stack_depth
> 0
12051 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
12052 SYMBOL_IS_ARGUMENT (sym
) = 1;
12053 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
12056 var_decode_location (attr
, sym
, cu
);
12058 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
12061 dwarf2_const_value (attr
, sym
, cu
);
12064 list_to_add
= cu
->list_in_scope
;
12066 case DW_TAG_unspecified_parameters
:
12067 /* From varargs functions; gdb doesn't seem to have any
12068 interest in this information, so just ignore it for now.
12071 case DW_TAG_template_type_param
:
12073 /* Fall through. */
12074 case DW_TAG_class_type
:
12075 case DW_TAG_interface_type
:
12076 case DW_TAG_structure_type
:
12077 case DW_TAG_union_type
:
12078 case DW_TAG_set_type
:
12079 case DW_TAG_enumeration_type
:
12080 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
12081 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
12084 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
12085 really ever be static objects: otherwise, if you try
12086 to, say, break of a class's method and you're in a file
12087 which doesn't mention that class, it won't work unless
12088 the check for all static symbols in lookup_symbol_aux
12089 saves you. See the OtherFileClass tests in
12090 gdb.c++/namespace.exp. */
12094 list_to_add
= (cu
->list_in_scope
== &file_symbols
12095 && (cu
->language
== language_cplus
12096 || cu
->language
== language_java
)
12097 ? &global_symbols
: cu
->list_in_scope
);
12099 /* The semantics of C++ state that "struct foo {
12100 ... }" also defines a typedef for "foo". A Java
12101 class declaration also defines a typedef for the
12103 if (cu
->language
== language_cplus
12104 || cu
->language
== language_java
12105 || cu
->language
== language_ada
)
12107 /* The symbol's name is already allocated along
12108 with this objfile, so we don't need to
12109 duplicate it for the type. */
12110 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
12111 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
12116 case DW_TAG_typedef
:
12117 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
12118 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
12119 list_to_add
= cu
->list_in_scope
;
12121 case DW_TAG_base_type
:
12122 case DW_TAG_subrange_type
:
12123 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
12124 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
12125 list_to_add
= cu
->list_in_scope
;
12127 case DW_TAG_enumerator
:
12128 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
12131 dwarf2_const_value (attr
, sym
, cu
);
12134 /* NOTE: carlton/2003-11-10: See comment above in the
12135 DW_TAG_class_type, etc. block. */
12137 list_to_add
= (cu
->list_in_scope
== &file_symbols
12138 && (cu
->language
== language_cplus
12139 || cu
->language
== language_java
)
12140 ? &global_symbols
: cu
->list_in_scope
);
12143 case DW_TAG_namespace
:
12144 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
12145 list_to_add
= &global_symbols
;
12148 /* Not a tag we recognize. Hopefully we aren't processing
12149 trash data, but since we must specifically ignore things
12150 we don't recognize, there is nothing else we should do at
12152 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
12153 dwarf_tag_name (die
->tag
));
12159 sym
->hash_next
= objfile
->template_symbols
;
12160 objfile
->template_symbols
= sym
;
12161 list_to_add
= NULL
;
12164 if (list_to_add
!= NULL
)
12165 add_symbol_to_list (sym
, list_to_add
);
12167 /* For the benefit of old versions of GCC, check for anonymous
12168 namespaces based on the demangled name. */
12169 if (!processing_has_namespace_info
12170 && cu
->language
== language_cplus
)
12171 cp_scan_for_anonymous_namespaces (sym
, objfile
);
12176 /* A wrapper for new_symbol_full that always allocates a new symbol. */
12178 static struct symbol
*
12179 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
12181 return new_symbol_full (die
, type
, cu
, NULL
);
12184 /* Given an attr with a DW_FORM_dataN value in host byte order,
12185 zero-extend it as appropriate for the symbol's type. The DWARF
12186 standard (v4) is not entirely clear about the meaning of using
12187 DW_FORM_dataN for a constant with a signed type, where the type is
12188 wider than the data. The conclusion of a discussion on the DWARF
12189 list was that this is unspecified. We choose to always zero-extend
12190 because that is the interpretation long in use by GCC. */
12193 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
12194 const char *name
, struct obstack
*obstack
,
12195 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
12197 struct objfile
*objfile
= cu
->objfile
;
12198 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
12199 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
12200 LONGEST l
= DW_UNSND (attr
);
12202 if (bits
< sizeof (*value
) * 8)
12204 l
&= ((LONGEST
) 1 << bits
) - 1;
12207 else if (bits
== sizeof (*value
) * 8)
12211 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
12212 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
12219 /* Read a constant value from an attribute. Either set *VALUE, or if
12220 the value does not fit in *VALUE, set *BYTES - either already
12221 allocated on the objfile obstack, or newly allocated on OBSTACK,
12222 or, set *BATON, if we translated the constant to a location
12226 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
12227 const char *name
, struct obstack
*obstack
,
12228 struct dwarf2_cu
*cu
,
12229 LONGEST
*value
, gdb_byte
**bytes
,
12230 struct dwarf2_locexpr_baton
**baton
)
12232 struct objfile
*objfile
= cu
->objfile
;
12233 struct comp_unit_head
*cu_header
= &cu
->header
;
12234 struct dwarf_block
*blk
;
12235 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
12236 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
12242 switch (attr
->form
)
12248 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
12249 dwarf2_const_value_length_mismatch_complaint (name
,
12250 cu_header
->addr_size
,
12251 TYPE_LENGTH (type
));
12252 /* Symbols of this form are reasonably rare, so we just
12253 piggyback on the existing location code rather than writing
12254 a new implementation of symbol_computed_ops. */
12255 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
12256 sizeof (struct dwarf2_locexpr_baton
));
12257 (*baton
)->per_cu
= cu
->per_cu
;
12258 gdb_assert ((*baton
)->per_cu
);
12260 (*baton
)->size
= 2 + cu_header
->addr_size
;
12261 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
12262 (*baton
)->data
= data
;
12264 data
[0] = DW_OP_addr
;
12265 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
12266 byte_order
, DW_ADDR (attr
));
12267 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
12270 case DW_FORM_string
:
12272 /* DW_STRING is already allocated on the objfile obstack, point
12274 *bytes
= (gdb_byte
*) DW_STRING (attr
);
12276 case DW_FORM_block1
:
12277 case DW_FORM_block2
:
12278 case DW_FORM_block4
:
12279 case DW_FORM_block
:
12280 case DW_FORM_exprloc
:
12281 blk
= DW_BLOCK (attr
);
12282 if (TYPE_LENGTH (type
) != blk
->size
)
12283 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
12284 TYPE_LENGTH (type
));
12285 *bytes
= blk
->data
;
12288 /* The DW_AT_const_value attributes are supposed to carry the
12289 symbol's value "represented as it would be on the target
12290 architecture." By the time we get here, it's already been
12291 converted to host endianness, so we just need to sign- or
12292 zero-extend it as appropriate. */
12293 case DW_FORM_data1
:
12294 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12295 obstack
, cu
, value
, 8);
12297 case DW_FORM_data2
:
12298 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12299 obstack
, cu
, value
, 16);
12301 case DW_FORM_data4
:
12302 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12303 obstack
, cu
, value
, 32);
12305 case DW_FORM_data8
:
12306 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12307 obstack
, cu
, value
, 64);
12310 case DW_FORM_sdata
:
12311 *value
= DW_SND (attr
);
12314 case DW_FORM_udata
:
12315 *value
= DW_UNSND (attr
);
12319 complaint (&symfile_complaints
,
12320 _("unsupported const value attribute form: '%s'"),
12321 dwarf_form_name (attr
->form
));
12328 /* Copy constant value from an attribute to a symbol. */
12331 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
12332 struct dwarf2_cu
*cu
)
12334 struct objfile
*objfile
= cu
->objfile
;
12335 struct comp_unit_head
*cu_header
= &cu
->header
;
12338 struct dwarf2_locexpr_baton
*baton
;
12340 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
12341 SYMBOL_PRINT_NAME (sym
),
12342 &objfile
->objfile_obstack
, cu
,
12343 &value
, &bytes
, &baton
);
12347 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
12348 SYMBOL_LOCATION_BATON (sym
) = baton
;
12349 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
12351 else if (bytes
!= NULL
)
12353 SYMBOL_VALUE_BYTES (sym
) = bytes
;
12354 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
12358 SYMBOL_VALUE (sym
) = value
;
12359 SYMBOL_CLASS (sym
) = LOC_CONST
;
12363 /* Return the type of the die in question using its DW_AT_type attribute. */
12365 static struct type
*
12366 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12368 struct attribute
*type_attr
;
12370 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
12373 /* A missing DW_AT_type represents a void type. */
12374 return objfile_type (cu
->objfile
)->builtin_void
;
12377 return lookup_die_type (die
, type_attr
, cu
);
12380 /* True iff CU's producer generates GNAT Ada auxiliary information
12381 that allows to find parallel types through that information instead
12382 of having to do expensive parallel lookups by type name. */
12385 need_gnat_info (struct dwarf2_cu
*cu
)
12387 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
12388 of GNAT produces this auxiliary information, without any indication
12389 that it is produced. Part of enhancing the FSF version of GNAT
12390 to produce that information will be to put in place an indicator
12391 that we can use in order to determine whether the descriptive type
12392 info is available or not. One suggestion that has been made is
12393 to use a new attribute, attached to the CU die. For now, assume
12394 that the descriptive type info is not available. */
12398 /* Return the auxiliary type of the die in question using its
12399 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
12400 attribute is not present. */
12402 static struct type
*
12403 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12405 struct attribute
*type_attr
;
12407 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
12411 return lookup_die_type (die
, type_attr
, cu
);
12414 /* If DIE has a descriptive_type attribute, then set the TYPE's
12415 descriptive type accordingly. */
12418 set_descriptive_type (struct type
*type
, struct die_info
*die
,
12419 struct dwarf2_cu
*cu
)
12421 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
12423 if (descriptive_type
)
12425 ALLOCATE_GNAT_AUX_TYPE (type
);
12426 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
12430 /* Return the containing type of the die in question using its
12431 DW_AT_containing_type attribute. */
12433 static struct type
*
12434 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12436 struct attribute
*type_attr
;
12438 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
12440 error (_("Dwarf Error: Problem turning containing type into gdb type "
12441 "[in module %s]"), cu
->objfile
->name
);
12443 return lookup_die_type (die
, type_attr
, cu
);
12446 /* Look up the type of DIE in CU using its type attribute ATTR.
12447 If there is no type substitute an error marker. */
12449 static struct type
*
12450 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
12451 struct dwarf2_cu
*cu
)
12453 struct objfile
*objfile
= cu
->objfile
;
12454 struct type
*this_type
;
12456 /* First see if we have it cached. */
12458 if (is_ref_attr (attr
))
12460 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
12462 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
12464 else if (attr
->form
== DW_FORM_ref_sig8
)
12466 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
12467 struct dwarf2_cu
*sig_cu
;
12468 sect_offset offset
;
12470 /* sig_type will be NULL if the signatured type is missing from
12472 if (sig_type
== NULL
)
12473 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
12474 "at 0x%x [in module %s]"),
12475 die
->offset
.sect_off
, objfile
->name
);
12477 gdb_assert (sig_type
->per_cu
.debug_types_section
);
12478 offset
.sect_off
= (sig_type
->per_cu
.offset
.sect_off
12479 + sig_type
->type_offset
.cu_off
);
12480 this_type
= get_die_type_at_offset (offset
, &sig_type
->per_cu
);
12484 dump_die_for_error (die
);
12485 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
12486 dwarf_attr_name (attr
->name
), objfile
->name
);
12489 /* If not cached we need to read it in. */
12491 if (this_type
== NULL
)
12493 struct die_info
*type_die
;
12494 struct dwarf2_cu
*type_cu
= cu
;
12496 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
12497 /* If the type is cached, we should have found it above. */
12498 gdb_assert (get_die_type (type_die
, type_cu
) == NULL
);
12499 this_type
= read_type_die_1 (type_die
, type_cu
);
12502 /* If we still don't have a type use an error marker. */
12504 if (this_type
== NULL
)
12506 char *message
, *saved
;
12508 /* read_type_die already issued a complaint. */
12509 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
12511 cu
->header
.offset
.sect_off
,
12512 die
->offset
.sect_off
);
12513 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
12514 message
, strlen (message
));
12517 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
12523 /* Return the type in DIE, CU.
12524 Returns NULL for invalid types.
12526 This first does a lookup in the appropriate type_hash table,
12527 and only reads the die in if necessary.
12529 NOTE: This can be called when reading in partial or full symbols. */
12531 static struct type
*
12532 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
12534 struct type
*this_type
;
12536 this_type
= get_die_type (die
, cu
);
12540 return read_type_die_1 (die
, cu
);
12543 /* Read the type in DIE, CU.
12544 Returns NULL for invalid types. */
12546 static struct type
*
12547 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
12549 struct type
*this_type
= NULL
;
12553 case DW_TAG_class_type
:
12554 case DW_TAG_interface_type
:
12555 case DW_TAG_structure_type
:
12556 case DW_TAG_union_type
:
12557 this_type
= read_structure_type (die
, cu
);
12559 case DW_TAG_enumeration_type
:
12560 this_type
= read_enumeration_type (die
, cu
);
12562 case DW_TAG_subprogram
:
12563 case DW_TAG_subroutine_type
:
12564 case DW_TAG_inlined_subroutine
:
12565 this_type
= read_subroutine_type (die
, cu
);
12567 case DW_TAG_array_type
:
12568 this_type
= read_array_type (die
, cu
);
12570 case DW_TAG_set_type
:
12571 this_type
= read_set_type (die
, cu
);
12573 case DW_TAG_pointer_type
:
12574 this_type
= read_tag_pointer_type (die
, cu
);
12576 case DW_TAG_ptr_to_member_type
:
12577 this_type
= read_tag_ptr_to_member_type (die
, cu
);
12579 case DW_TAG_reference_type
:
12580 this_type
= read_tag_reference_type (die
, cu
);
12582 case DW_TAG_const_type
:
12583 this_type
= read_tag_const_type (die
, cu
);
12585 case DW_TAG_volatile_type
:
12586 this_type
= read_tag_volatile_type (die
, cu
);
12588 case DW_TAG_string_type
:
12589 this_type
= read_tag_string_type (die
, cu
);
12591 case DW_TAG_typedef
:
12592 this_type
= read_typedef (die
, cu
);
12594 case DW_TAG_subrange_type
:
12595 this_type
= read_subrange_type (die
, cu
);
12597 case DW_TAG_base_type
:
12598 this_type
= read_base_type (die
, cu
);
12600 case DW_TAG_unspecified_type
:
12601 this_type
= read_unspecified_type (die
, cu
);
12603 case DW_TAG_namespace
:
12604 this_type
= read_namespace_type (die
, cu
);
12606 case DW_TAG_module
:
12607 this_type
= read_module_type (die
, cu
);
12610 complaint (&symfile_complaints
,
12611 _("unexpected tag in read_type_die: '%s'"),
12612 dwarf_tag_name (die
->tag
));
12619 /* See if we can figure out if the class lives in a namespace. We do
12620 this by looking for a member function; its demangled name will
12621 contain namespace info, if there is any.
12622 Return the computed name or NULL.
12623 Space for the result is allocated on the objfile's obstack.
12624 This is the full-die version of guess_partial_die_structure_name.
12625 In this case we know DIE has no useful parent. */
12628 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12630 struct die_info
*spec_die
;
12631 struct dwarf2_cu
*spec_cu
;
12632 struct die_info
*child
;
12635 spec_die
= die_specification (die
, &spec_cu
);
12636 if (spec_die
!= NULL
)
12642 for (child
= die
->child
;
12644 child
= child
->sibling
)
12646 if (child
->tag
== DW_TAG_subprogram
)
12648 struct attribute
*attr
;
12650 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
12652 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
12656 = language_class_name_from_physname (cu
->language_defn
,
12660 if (actual_name
!= NULL
)
12662 char *die_name
= dwarf2_name (die
, cu
);
12664 if (die_name
!= NULL
12665 && strcmp (die_name
, actual_name
) != 0)
12667 /* Strip off the class name from the full name.
12668 We want the prefix. */
12669 int die_name_len
= strlen (die_name
);
12670 int actual_name_len
= strlen (actual_name
);
12672 /* Test for '::' as a sanity check. */
12673 if (actual_name_len
> die_name_len
+ 2
12674 && actual_name
[actual_name_len
12675 - die_name_len
- 1] == ':')
12677 obsavestring (actual_name
,
12678 actual_name_len
- die_name_len
- 2,
12679 &cu
->objfile
->objfile_obstack
);
12682 xfree (actual_name
);
12691 /* GCC might emit a nameless typedef that has a linkage name. Determine the
12692 prefix part in such case. See
12693 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12696 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
12698 struct attribute
*attr
;
12701 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
12702 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
12705 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
12706 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
12709 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
12711 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
12712 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
12715 /* dwarf2_name had to be already called. */
12716 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
12718 /* Strip the base name, keep any leading namespaces/classes. */
12719 base
= strrchr (DW_STRING (attr
), ':');
12720 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
12723 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
12724 &cu
->objfile
->objfile_obstack
);
12727 /* Return the name of the namespace/class that DIE is defined within,
12728 or "" if we can't tell. The caller should not xfree the result.
12730 For example, if we're within the method foo() in the following
12740 then determine_prefix on foo's die will return "N::C". */
12742 static const char *
12743 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
12745 struct die_info
*parent
, *spec_die
;
12746 struct dwarf2_cu
*spec_cu
;
12747 struct type
*parent_type
;
12750 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
12751 && cu
->language
!= language_fortran
)
12754 retval
= anonymous_struct_prefix (die
, cu
);
12758 /* We have to be careful in the presence of DW_AT_specification.
12759 For example, with GCC 3.4, given the code
12763 // Definition of N::foo.
12767 then we'll have a tree of DIEs like this:
12769 1: DW_TAG_compile_unit
12770 2: DW_TAG_namespace // N
12771 3: DW_TAG_subprogram // declaration of N::foo
12772 4: DW_TAG_subprogram // definition of N::foo
12773 DW_AT_specification // refers to die #3
12775 Thus, when processing die #4, we have to pretend that we're in
12776 the context of its DW_AT_specification, namely the contex of die
12779 spec_die
= die_specification (die
, &spec_cu
);
12780 if (spec_die
== NULL
)
12781 parent
= die
->parent
;
12784 parent
= spec_die
->parent
;
12788 if (parent
== NULL
)
12790 else if (parent
->building_fullname
)
12793 const char *parent_name
;
12795 /* It has been seen on RealView 2.2 built binaries,
12796 DW_TAG_template_type_param types actually _defined_ as
12797 children of the parent class:
12800 template class <class Enum> Class{};
12801 Class<enum E> class_e;
12803 1: DW_TAG_class_type (Class)
12804 2: DW_TAG_enumeration_type (E)
12805 3: DW_TAG_enumerator (enum1:0)
12806 3: DW_TAG_enumerator (enum2:1)
12808 2: DW_TAG_template_type_param
12809 DW_AT_type DW_FORM_ref_udata (E)
12811 Besides being broken debug info, it can put GDB into an
12812 infinite loop. Consider:
12814 When we're building the full name for Class<E>, we'll start
12815 at Class, and go look over its template type parameters,
12816 finding E. We'll then try to build the full name of E, and
12817 reach here. We're now trying to build the full name of E,
12818 and look over the parent DIE for containing scope. In the
12819 broken case, if we followed the parent DIE of E, we'd again
12820 find Class, and once again go look at its template type
12821 arguments, etc., etc. Simply don't consider such parent die
12822 as source-level parent of this die (it can't be, the language
12823 doesn't allow it), and break the loop here. */
12824 name
= dwarf2_name (die
, cu
);
12825 parent_name
= dwarf2_name (parent
, cu
);
12826 complaint (&symfile_complaints
,
12827 _("template param type '%s' defined within parent '%s'"),
12828 name
? name
: "<unknown>",
12829 parent_name
? parent_name
: "<unknown>");
12833 switch (parent
->tag
)
12835 case DW_TAG_namespace
:
12836 parent_type
= read_type_die (parent
, cu
);
12837 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
12838 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
12839 Work around this problem here. */
12840 if (cu
->language
== language_cplus
12841 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
12843 /* We give a name to even anonymous namespaces. */
12844 return TYPE_TAG_NAME (parent_type
);
12845 case DW_TAG_class_type
:
12846 case DW_TAG_interface_type
:
12847 case DW_TAG_structure_type
:
12848 case DW_TAG_union_type
:
12849 case DW_TAG_module
:
12850 parent_type
= read_type_die (parent
, cu
);
12851 if (TYPE_TAG_NAME (parent_type
) != NULL
)
12852 return TYPE_TAG_NAME (parent_type
);
12854 /* An anonymous structure is only allowed non-static data
12855 members; no typedefs, no member functions, et cetera.
12856 So it does not need a prefix. */
12858 case DW_TAG_compile_unit
:
12859 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
12860 if (cu
->language
== language_cplus
12861 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
12862 && die
->child
!= NULL
12863 && (die
->tag
== DW_TAG_class_type
12864 || die
->tag
== DW_TAG_structure_type
12865 || die
->tag
== DW_TAG_union_type
))
12867 char *name
= guess_full_die_structure_name (die
, cu
);
12873 return determine_prefix (parent
, cu
);
12877 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
12878 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
12879 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
12880 an obconcat, otherwise allocate storage for the result. The CU argument is
12881 used to determine the language and hence, the appropriate separator. */
12883 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
12886 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
12887 int physname
, struct dwarf2_cu
*cu
)
12889 const char *lead
= "";
12892 if (suffix
== NULL
|| suffix
[0] == '\0'
12893 || prefix
== NULL
|| prefix
[0] == '\0')
12895 else if (cu
->language
== language_java
)
12897 else if (cu
->language
== language_fortran
&& physname
)
12899 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
12900 DW_AT_MIPS_linkage_name is preferred and used instead. */
12908 if (prefix
== NULL
)
12910 if (suffix
== NULL
)
12916 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
12918 strcpy (retval
, lead
);
12919 strcat (retval
, prefix
);
12920 strcat (retval
, sep
);
12921 strcat (retval
, suffix
);
12926 /* We have an obstack. */
12927 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
12931 /* Return sibling of die, NULL if no sibling. */
12933 static struct die_info
*
12934 sibling_die (struct die_info
*die
)
12936 return die
->sibling
;
12939 /* Get name of a die, return NULL if not found. */
12942 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
12943 struct obstack
*obstack
)
12945 if (name
&& cu
->language
== language_cplus
)
12947 char *canon_name
= cp_canonicalize_string (name
);
12949 if (canon_name
!= NULL
)
12951 if (strcmp (canon_name
, name
) != 0)
12952 name
= obsavestring (canon_name
, strlen (canon_name
),
12954 xfree (canon_name
);
12961 /* Get name of a die, return NULL if not found. */
12964 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12966 struct attribute
*attr
;
12968 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
12969 if ((!attr
|| !DW_STRING (attr
))
12970 && die
->tag
!= DW_TAG_class_type
12971 && die
->tag
!= DW_TAG_interface_type
12972 && die
->tag
!= DW_TAG_structure_type
12973 && die
->tag
!= DW_TAG_union_type
)
12978 case DW_TAG_compile_unit
:
12979 /* Compilation units have a DW_AT_name that is a filename, not
12980 a source language identifier. */
12981 case DW_TAG_enumeration_type
:
12982 case DW_TAG_enumerator
:
12983 /* These tags always have simple identifiers already; no need
12984 to canonicalize them. */
12985 return DW_STRING (attr
);
12987 case DW_TAG_subprogram
:
12988 /* Java constructors will all be named "<init>", so return
12989 the class name when we see this special case. */
12990 if (cu
->language
== language_java
12991 && DW_STRING (attr
) != NULL
12992 && strcmp (DW_STRING (attr
), "<init>") == 0)
12994 struct dwarf2_cu
*spec_cu
= cu
;
12995 struct die_info
*spec_die
;
12997 /* GCJ will output '<init>' for Java constructor names.
12998 For this special case, return the name of the parent class. */
13000 /* GCJ may output suprogram DIEs with AT_specification set.
13001 If so, use the name of the specified DIE. */
13002 spec_die
= die_specification (die
, &spec_cu
);
13003 if (spec_die
!= NULL
)
13004 return dwarf2_name (spec_die
, spec_cu
);
13009 if (die
->tag
== DW_TAG_class_type
)
13010 return dwarf2_name (die
, cu
);
13012 while (die
->tag
!= DW_TAG_compile_unit
);
13016 case DW_TAG_class_type
:
13017 case DW_TAG_interface_type
:
13018 case DW_TAG_structure_type
:
13019 case DW_TAG_union_type
:
13020 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
13021 structures or unions. These were of the form "._%d" in GCC 4.1,
13022 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
13023 and GCC 4.4. We work around this problem by ignoring these. */
13024 if (attr
&& DW_STRING (attr
)
13025 && (strncmp (DW_STRING (attr
), "._", 2) == 0
13026 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
13029 /* GCC might emit a nameless typedef that has a linkage name. See
13030 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
13031 if (!attr
|| DW_STRING (attr
) == NULL
)
13033 char *demangled
= NULL
;
13035 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
13037 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
13039 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
13042 /* Avoid demangling DW_STRING (attr) the second time on a second
13043 call for the same DIE. */
13044 if (!DW_STRING_IS_CANONICAL (attr
))
13045 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
13051 /* FIXME: we already did this for the partial symbol... */
13052 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
13053 &cu
->objfile
->objfile_obstack
);
13054 DW_STRING_IS_CANONICAL (attr
) = 1;
13057 /* Strip any leading namespaces/classes, keep only the base name.
13058 DW_AT_name for named DIEs does not contain the prefixes. */
13059 base
= strrchr (DW_STRING (attr
), ':');
13060 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
13063 return DW_STRING (attr
);
13072 if (!DW_STRING_IS_CANONICAL (attr
))
13075 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
13076 &cu
->objfile
->objfile_obstack
);
13077 DW_STRING_IS_CANONICAL (attr
) = 1;
13079 return DW_STRING (attr
);
13082 /* Return the die that this die in an extension of, or NULL if there
13083 is none. *EXT_CU is the CU containing DIE on input, and the CU
13084 containing the return value on output. */
13086 static struct die_info
*
13087 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
13089 struct attribute
*attr
;
13091 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
13095 return follow_die_ref (die
, attr
, ext_cu
);
13098 /* Convert a DIE tag into its string name. */
13101 dwarf_tag_name (unsigned tag
)
13105 case DW_TAG_padding
:
13106 return "DW_TAG_padding";
13107 case DW_TAG_array_type
:
13108 return "DW_TAG_array_type";
13109 case DW_TAG_class_type
:
13110 return "DW_TAG_class_type";
13111 case DW_TAG_entry_point
:
13112 return "DW_TAG_entry_point";
13113 case DW_TAG_enumeration_type
:
13114 return "DW_TAG_enumeration_type";
13115 case DW_TAG_formal_parameter
:
13116 return "DW_TAG_formal_parameter";
13117 case DW_TAG_imported_declaration
:
13118 return "DW_TAG_imported_declaration";
13120 return "DW_TAG_label";
13121 case DW_TAG_lexical_block
:
13122 return "DW_TAG_lexical_block";
13123 case DW_TAG_member
:
13124 return "DW_TAG_member";
13125 case DW_TAG_pointer_type
:
13126 return "DW_TAG_pointer_type";
13127 case DW_TAG_reference_type
:
13128 return "DW_TAG_reference_type";
13129 case DW_TAG_compile_unit
:
13130 return "DW_TAG_compile_unit";
13131 case DW_TAG_string_type
:
13132 return "DW_TAG_string_type";
13133 case DW_TAG_structure_type
:
13134 return "DW_TAG_structure_type";
13135 case DW_TAG_subroutine_type
:
13136 return "DW_TAG_subroutine_type";
13137 case DW_TAG_typedef
:
13138 return "DW_TAG_typedef";
13139 case DW_TAG_union_type
:
13140 return "DW_TAG_union_type";
13141 case DW_TAG_unspecified_parameters
:
13142 return "DW_TAG_unspecified_parameters";
13143 case DW_TAG_variant
:
13144 return "DW_TAG_variant";
13145 case DW_TAG_common_block
:
13146 return "DW_TAG_common_block";
13147 case DW_TAG_common_inclusion
:
13148 return "DW_TAG_common_inclusion";
13149 case DW_TAG_inheritance
:
13150 return "DW_TAG_inheritance";
13151 case DW_TAG_inlined_subroutine
:
13152 return "DW_TAG_inlined_subroutine";
13153 case DW_TAG_module
:
13154 return "DW_TAG_module";
13155 case DW_TAG_ptr_to_member_type
:
13156 return "DW_TAG_ptr_to_member_type";
13157 case DW_TAG_set_type
:
13158 return "DW_TAG_set_type";
13159 case DW_TAG_subrange_type
:
13160 return "DW_TAG_subrange_type";
13161 case DW_TAG_with_stmt
:
13162 return "DW_TAG_with_stmt";
13163 case DW_TAG_access_declaration
:
13164 return "DW_TAG_access_declaration";
13165 case DW_TAG_base_type
:
13166 return "DW_TAG_base_type";
13167 case DW_TAG_catch_block
:
13168 return "DW_TAG_catch_block";
13169 case DW_TAG_const_type
:
13170 return "DW_TAG_const_type";
13171 case DW_TAG_constant
:
13172 return "DW_TAG_constant";
13173 case DW_TAG_enumerator
:
13174 return "DW_TAG_enumerator";
13175 case DW_TAG_file_type
:
13176 return "DW_TAG_file_type";
13177 case DW_TAG_friend
:
13178 return "DW_TAG_friend";
13179 case DW_TAG_namelist
:
13180 return "DW_TAG_namelist";
13181 case DW_TAG_namelist_item
:
13182 return "DW_TAG_namelist_item";
13183 case DW_TAG_packed_type
:
13184 return "DW_TAG_packed_type";
13185 case DW_TAG_subprogram
:
13186 return "DW_TAG_subprogram";
13187 case DW_TAG_template_type_param
:
13188 return "DW_TAG_template_type_param";
13189 case DW_TAG_template_value_param
:
13190 return "DW_TAG_template_value_param";
13191 case DW_TAG_thrown_type
:
13192 return "DW_TAG_thrown_type";
13193 case DW_TAG_try_block
:
13194 return "DW_TAG_try_block";
13195 case DW_TAG_variant_part
:
13196 return "DW_TAG_variant_part";
13197 case DW_TAG_variable
:
13198 return "DW_TAG_variable";
13199 case DW_TAG_volatile_type
:
13200 return "DW_TAG_volatile_type";
13201 case DW_TAG_dwarf_procedure
:
13202 return "DW_TAG_dwarf_procedure";
13203 case DW_TAG_restrict_type
:
13204 return "DW_TAG_restrict_type";
13205 case DW_TAG_interface_type
:
13206 return "DW_TAG_interface_type";
13207 case DW_TAG_namespace
:
13208 return "DW_TAG_namespace";
13209 case DW_TAG_imported_module
:
13210 return "DW_TAG_imported_module";
13211 case DW_TAG_unspecified_type
:
13212 return "DW_TAG_unspecified_type";
13213 case DW_TAG_partial_unit
:
13214 return "DW_TAG_partial_unit";
13215 case DW_TAG_imported_unit
:
13216 return "DW_TAG_imported_unit";
13217 case DW_TAG_condition
:
13218 return "DW_TAG_condition";
13219 case DW_TAG_shared_type
:
13220 return "DW_TAG_shared_type";
13221 case DW_TAG_type_unit
:
13222 return "DW_TAG_type_unit";
13223 case DW_TAG_MIPS_loop
:
13224 return "DW_TAG_MIPS_loop";
13225 case DW_TAG_HP_array_descriptor
:
13226 return "DW_TAG_HP_array_descriptor";
13227 case DW_TAG_format_label
:
13228 return "DW_TAG_format_label";
13229 case DW_TAG_function_template
:
13230 return "DW_TAG_function_template";
13231 case DW_TAG_class_template
:
13232 return "DW_TAG_class_template";
13233 case DW_TAG_GNU_BINCL
:
13234 return "DW_TAG_GNU_BINCL";
13235 case DW_TAG_GNU_EINCL
:
13236 return "DW_TAG_GNU_EINCL";
13237 case DW_TAG_upc_shared_type
:
13238 return "DW_TAG_upc_shared_type";
13239 case DW_TAG_upc_strict_type
:
13240 return "DW_TAG_upc_strict_type";
13241 case DW_TAG_upc_relaxed_type
:
13242 return "DW_TAG_upc_relaxed_type";
13243 case DW_TAG_PGI_kanji_type
:
13244 return "DW_TAG_PGI_kanji_type";
13245 case DW_TAG_PGI_interface_block
:
13246 return "DW_TAG_PGI_interface_block";
13247 case DW_TAG_GNU_call_site
:
13248 return "DW_TAG_GNU_call_site";
13250 return "DW_TAG_<unknown>";
13254 /* Convert a DWARF attribute code into its string name. */
13257 dwarf_attr_name (unsigned attr
)
13261 case DW_AT_sibling
:
13262 return "DW_AT_sibling";
13263 case DW_AT_location
:
13264 return "DW_AT_location";
13266 return "DW_AT_name";
13267 case DW_AT_ordering
:
13268 return "DW_AT_ordering";
13269 case DW_AT_subscr_data
:
13270 return "DW_AT_subscr_data";
13271 case DW_AT_byte_size
:
13272 return "DW_AT_byte_size";
13273 case DW_AT_bit_offset
:
13274 return "DW_AT_bit_offset";
13275 case DW_AT_bit_size
:
13276 return "DW_AT_bit_size";
13277 case DW_AT_element_list
:
13278 return "DW_AT_element_list";
13279 case DW_AT_stmt_list
:
13280 return "DW_AT_stmt_list";
13282 return "DW_AT_low_pc";
13283 case DW_AT_high_pc
:
13284 return "DW_AT_high_pc";
13285 case DW_AT_language
:
13286 return "DW_AT_language";
13288 return "DW_AT_member";
13290 return "DW_AT_discr";
13291 case DW_AT_discr_value
:
13292 return "DW_AT_discr_value";
13293 case DW_AT_visibility
:
13294 return "DW_AT_visibility";
13296 return "DW_AT_import";
13297 case DW_AT_string_length
:
13298 return "DW_AT_string_length";
13299 case DW_AT_common_reference
:
13300 return "DW_AT_common_reference";
13301 case DW_AT_comp_dir
:
13302 return "DW_AT_comp_dir";
13303 case DW_AT_const_value
:
13304 return "DW_AT_const_value";
13305 case DW_AT_containing_type
:
13306 return "DW_AT_containing_type";
13307 case DW_AT_default_value
:
13308 return "DW_AT_default_value";
13310 return "DW_AT_inline";
13311 case DW_AT_is_optional
:
13312 return "DW_AT_is_optional";
13313 case DW_AT_lower_bound
:
13314 return "DW_AT_lower_bound";
13315 case DW_AT_producer
:
13316 return "DW_AT_producer";
13317 case DW_AT_prototyped
:
13318 return "DW_AT_prototyped";
13319 case DW_AT_return_addr
:
13320 return "DW_AT_return_addr";
13321 case DW_AT_start_scope
:
13322 return "DW_AT_start_scope";
13323 case DW_AT_bit_stride
:
13324 return "DW_AT_bit_stride";
13325 case DW_AT_upper_bound
:
13326 return "DW_AT_upper_bound";
13327 case DW_AT_abstract_origin
:
13328 return "DW_AT_abstract_origin";
13329 case DW_AT_accessibility
:
13330 return "DW_AT_accessibility";
13331 case DW_AT_address_class
:
13332 return "DW_AT_address_class";
13333 case DW_AT_artificial
:
13334 return "DW_AT_artificial";
13335 case DW_AT_base_types
:
13336 return "DW_AT_base_types";
13337 case DW_AT_calling_convention
:
13338 return "DW_AT_calling_convention";
13340 return "DW_AT_count";
13341 case DW_AT_data_member_location
:
13342 return "DW_AT_data_member_location";
13343 case DW_AT_decl_column
:
13344 return "DW_AT_decl_column";
13345 case DW_AT_decl_file
:
13346 return "DW_AT_decl_file";
13347 case DW_AT_decl_line
:
13348 return "DW_AT_decl_line";
13349 case DW_AT_declaration
:
13350 return "DW_AT_declaration";
13351 case DW_AT_discr_list
:
13352 return "DW_AT_discr_list";
13353 case DW_AT_encoding
:
13354 return "DW_AT_encoding";
13355 case DW_AT_external
:
13356 return "DW_AT_external";
13357 case DW_AT_frame_base
:
13358 return "DW_AT_frame_base";
13360 return "DW_AT_friend";
13361 case DW_AT_identifier_case
:
13362 return "DW_AT_identifier_case";
13363 case DW_AT_macro_info
:
13364 return "DW_AT_macro_info";
13365 case DW_AT_namelist_items
:
13366 return "DW_AT_namelist_items";
13367 case DW_AT_priority
:
13368 return "DW_AT_priority";
13369 case DW_AT_segment
:
13370 return "DW_AT_segment";
13371 case DW_AT_specification
:
13372 return "DW_AT_specification";
13373 case DW_AT_static_link
:
13374 return "DW_AT_static_link";
13376 return "DW_AT_type";
13377 case DW_AT_use_location
:
13378 return "DW_AT_use_location";
13379 case DW_AT_variable_parameter
:
13380 return "DW_AT_variable_parameter";
13381 case DW_AT_virtuality
:
13382 return "DW_AT_virtuality";
13383 case DW_AT_vtable_elem_location
:
13384 return "DW_AT_vtable_elem_location";
13385 /* DWARF 3 values. */
13386 case DW_AT_allocated
:
13387 return "DW_AT_allocated";
13388 case DW_AT_associated
:
13389 return "DW_AT_associated";
13390 case DW_AT_data_location
:
13391 return "DW_AT_data_location";
13392 case DW_AT_byte_stride
:
13393 return "DW_AT_byte_stride";
13394 case DW_AT_entry_pc
:
13395 return "DW_AT_entry_pc";
13396 case DW_AT_use_UTF8
:
13397 return "DW_AT_use_UTF8";
13398 case DW_AT_extension
:
13399 return "DW_AT_extension";
13401 return "DW_AT_ranges";
13402 case DW_AT_trampoline
:
13403 return "DW_AT_trampoline";
13404 case DW_AT_call_column
:
13405 return "DW_AT_call_column";
13406 case DW_AT_call_file
:
13407 return "DW_AT_call_file";
13408 case DW_AT_call_line
:
13409 return "DW_AT_call_line";
13410 case DW_AT_description
:
13411 return "DW_AT_description";
13412 case DW_AT_binary_scale
:
13413 return "DW_AT_binary_scale";
13414 case DW_AT_decimal_scale
:
13415 return "DW_AT_decimal_scale";
13417 return "DW_AT_small";
13418 case DW_AT_decimal_sign
:
13419 return "DW_AT_decimal_sign";
13420 case DW_AT_digit_count
:
13421 return "DW_AT_digit_count";
13422 case DW_AT_picture_string
:
13423 return "DW_AT_picture_string";
13424 case DW_AT_mutable
:
13425 return "DW_AT_mutable";
13426 case DW_AT_threads_scaled
:
13427 return "DW_AT_threads_scaled";
13428 case DW_AT_explicit
:
13429 return "DW_AT_explicit";
13430 case DW_AT_object_pointer
:
13431 return "DW_AT_object_pointer";
13432 case DW_AT_endianity
:
13433 return "DW_AT_endianity";
13434 case DW_AT_elemental
:
13435 return "DW_AT_elemental";
13437 return "DW_AT_pure";
13438 case DW_AT_recursive
:
13439 return "DW_AT_recursive";
13440 /* DWARF 4 values. */
13441 case DW_AT_signature
:
13442 return "DW_AT_signature";
13443 case DW_AT_linkage_name
:
13444 return "DW_AT_linkage_name";
13445 /* SGI/MIPS extensions. */
13446 #ifdef MIPS /* collides with DW_AT_HP_block_index */
13447 case DW_AT_MIPS_fde
:
13448 return "DW_AT_MIPS_fde";
13450 case DW_AT_MIPS_loop_begin
:
13451 return "DW_AT_MIPS_loop_begin";
13452 case DW_AT_MIPS_tail_loop_begin
:
13453 return "DW_AT_MIPS_tail_loop_begin";
13454 case DW_AT_MIPS_epilog_begin
:
13455 return "DW_AT_MIPS_epilog_begin";
13456 case DW_AT_MIPS_loop_unroll_factor
:
13457 return "DW_AT_MIPS_loop_unroll_factor";
13458 case DW_AT_MIPS_software_pipeline_depth
:
13459 return "DW_AT_MIPS_software_pipeline_depth";
13460 case DW_AT_MIPS_linkage_name
:
13461 return "DW_AT_MIPS_linkage_name";
13462 case DW_AT_MIPS_stride
:
13463 return "DW_AT_MIPS_stride";
13464 case DW_AT_MIPS_abstract_name
:
13465 return "DW_AT_MIPS_abstract_name";
13466 case DW_AT_MIPS_clone_origin
:
13467 return "DW_AT_MIPS_clone_origin";
13468 case DW_AT_MIPS_has_inlines
:
13469 return "DW_AT_MIPS_has_inlines";
13470 /* HP extensions. */
13471 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
13472 case DW_AT_HP_block_index
:
13473 return "DW_AT_HP_block_index";
13475 case DW_AT_HP_unmodifiable
:
13476 return "DW_AT_HP_unmodifiable";
13477 case DW_AT_HP_actuals_stmt_list
:
13478 return "DW_AT_HP_actuals_stmt_list";
13479 case DW_AT_HP_proc_per_section
:
13480 return "DW_AT_HP_proc_per_section";
13481 case DW_AT_HP_raw_data_ptr
:
13482 return "DW_AT_HP_raw_data_ptr";
13483 case DW_AT_HP_pass_by_reference
:
13484 return "DW_AT_HP_pass_by_reference";
13485 case DW_AT_HP_opt_level
:
13486 return "DW_AT_HP_opt_level";
13487 case DW_AT_HP_prof_version_id
:
13488 return "DW_AT_HP_prof_version_id";
13489 case DW_AT_HP_opt_flags
:
13490 return "DW_AT_HP_opt_flags";
13491 case DW_AT_HP_cold_region_low_pc
:
13492 return "DW_AT_HP_cold_region_low_pc";
13493 case DW_AT_HP_cold_region_high_pc
:
13494 return "DW_AT_HP_cold_region_high_pc";
13495 case DW_AT_HP_all_variables_modifiable
:
13496 return "DW_AT_HP_all_variables_modifiable";
13497 case DW_AT_HP_linkage_name
:
13498 return "DW_AT_HP_linkage_name";
13499 case DW_AT_HP_prof_flags
:
13500 return "DW_AT_HP_prof_flags";
13501 /* GNU extensions. */
13502 case DW_AT_sf_names
:
13503 return "DW_AT_sf_names";
13504 case DW_AT_src_info
:
13505 return "DW_AT_src_info";
13506 case DW_AT_mac_info
:
13507 return "DW_AT_mac_info";
13508 case DW_AT_src_coords
:
13509 return "DW_AT_src_coords";
13510 case DW_AT_body_begin
:
13511 return "DW_AT_body_begin";
13512 case DW_AT_body_end
:
13513 return "DW_AT_body_end";
13514 case DW_AT_GNU_vector
:
13515 return "DW_AT_GNU_vector";
13516 case DW_AT_GNU_odr_signature
:
13517 return "DW_AT_GNU_odr_signature";
13518 /* VMS extensions. */
13519 case DW_AT_VMS_rtnbeg_pd_address
:
13520 return "DW_AT_VMS_rtnbeg_pd_address";
13521 /* UPC extension. */
13522 case DW_AT_upc_threads_scaled
:
13523 return "DW_AT_upc_threads_scaled";
13524 /* PGI (STMicroelectronics) extensions. */
13525 case DW_AT_PGI_lbase
:
13526 return "DW_AT_PGI_lbase";
13527 case DW_AT_PGI_soffset
:
13528 return "DW_AT_PGI_soffset";
13529 case DW_AT_PGI_lstride
:
13530 return "DW_AT_PGI_lstride";
13532 return "DW_AT_<unknown>";
13536 /* Convert a DWARF value form code into its string name. */
13539 dwarf_form_name (unsigned form
)
13544 return "DW_FORM_addr";
13545 case DW_FORM_block2
:
13546 return "DW_FORM_block2";
13547 case DW_FORM_block4
:
13548 return "DW_FORM_block4";
13549 case DW_FORM_data2
:
13550 return "DW_FORM_data2";
13551 case DW_FORM_data4
:
13552 return "DW_FORM_data4";
13553 case DW_FORM_data8
:
13554 return "DW_FORM_data8";
13555 case DW_FORM_string
:
13556 return "DW_FORM_string";
13557 case DW_FORM_block
:
13558 return "DW_FORM_block";
13559 case DW_FORM_block1
:
13560 return "DW_FORM_block1";
13561 case DW_FORM_data1
:
13562 return "DW_FORM_data1";
13564 return "DW_FORM_flag";
13565 case DW_FORM_sdata
:
13566 return "DW_FORM_sdata";
13568 return "DW_FORM_strp";
13569 case DW_FORM_udata
:
13570 return "DW_FORM_udata";
13571 case DW_FORM_ref_addr
:
13572 return "DW_FORM_ref_addr";
13574 return "DW_FORM_ref1";
13576 return "DW_FORM_ref2";
13578 return "DW_FORM_ref4";
13580 return "DW_FORM_ref8";
13581 case DW_FORM_ref_udata
:
13582 return "DW_FORM_ref_udata";
13583 case DW_FORM_indirect
:
13584 return "DW_FORM_indirect";
13585 case DW_FORM_sec_offset
:
13586 return "DW_FORM_sec_offset";
13587 case DW_FORM_exprloc
:
13588 return "DW_FORM_exprloc";
13589 case DW_FORM_flag_present
:
13590 return "DW_FORM_flag_present";
13591 case DW_FORM_ref_sig8
:
13592 return "DW_FORM_ref_sig8";
13594 return "DW_FORM_<unknown>";
13598 /* Convert a DWARF stack opcode into its string name. */
13601 dwarf_stack_op_name (unsigned op
)
13606 return "DW_OP_addr";
13608 return "DW_OP_deref";
13609 case DW_OP_const1u
:
13610 return "DW_OP_const1u";
13611 case DW_OP_const1s
:
13612 return "DW_OP_const1s";
13613 case DW_OP_const2u
:
13614 return "DW_OP_const2u";
13615 case DW_OP_const2s
:
13616 return "DW_OP_const2s";
13617 case DW_OP_const4u
:
13618 return "DW_OP_const4u";
13619 case DW_OP_const4s
:
13620 return "DW_OP_const4s";
13621 case DW_OP_const8u
:
13622 return "DW_OP_const8u";
13623 case DW_OP_const8s
:
13624 return "DW_OP_const8s";
13626 return "DW_OP_constu";
13628 return "DW_OP_consts";
13630 return "DW_OP_dup";
13632 return "DW_OP_drop";
13634 return "DW_OP_over";
13636 return "DW_OP_pick";
13638 return "DW_OP_swap";
13640 return "DW_OP_rot";
13642 return "DW_OP_xderef";
13644 return "DW_OP_abs";
13646 return "DW_OP_and";
13648 return "DW_OP_div";
13650 return "DW_OP_minus";
13652 return "DW_OP_mod";
13654 return "DW_OP_mul";
13656 return "DW_OP_neg";
13658 return "DW_OP_not";
13662 return "DW_OP_plus";
13663 case DW_OP_plus_uconst
:
13664 return "DW_OP_plus_uconst";
13666 return "DW_OP_shl";
13668 return "DW_OP_shr";
13670 return "DW_OP_shra";
13672 return "DW_OP_xor";
13674 return "DW_OP_bra";
13688 return "DW_OP_skip";
13690 return "DW_OP_lit0";
13692 return "DW_OP_lit1";
13694 return "DW_OP_lit2";
13696 return "DW_OP_lit3";
13698 return "DW_OP_lit4";
13700 return "DW_OP_lit5";
13702 return "DW_OP_lit6";
13704 return "DW_OP_lit7";
13706 return "DW_OP_lit8";
13708 return "DW_OP_lit9";
13710 return "DW_OP_lit10";
13712 return "DW_OP_lit11";
13714 return "DW_OP_lit12";
13716 return "DW_OP_lit13";
13718 return "DW_OP_lit14";
13720 return "DW_OP_lit15";
13722 return "DW_OP_lit16";
13724 return "DW_OP_lit17";
13726 return "DW_OP_lit18";
13728 return "DW_OP_lit19";
13730 return "DW_OP_lit20";
13732 return "DW_OP_lit21";
13734 return "DW_OP_lit22";
13736 return "DW_OP_lit23";
13738 return "DW_OP_lit24";
13740 return "DW_OP_lit25";
13742 return "DW_OP_lit26";
13744 return "DW_OP_lit27";
13746 return "DW_OP_lit28";
13748 return "DW_OP_lit29";
13750 return "DW_OP_lit30";
13752 return "DW_OP_lit31";
13754 return "DW_OP_reg0";
13756 return "DW_OP_reg1";
13758 return "DW_OP_reg2";
13760 return "DW_OP_reg3";
13762 return "DW_OP_reg4";
13764 return "DW_OP_reg5";
13766 return "DW_OP_reg6";
13768 return "DW_OP_reg7";
13770 return "DW_OP_reg8";
13772 return "DW_OP_reg9";
13774 return "DW_OP_reg10";
13776 return "DW_OP_reg11";
13778 return "DW_OP_reg12";
13780 return "DW_OP_reg13";
13782 return "DW_OP_reg14";
13784 return "DW_OP_reg15";
13786 return "DW_OP_reg16";
13788 return "DW_OP_reg17";
13790 return "DW_OP_reg18";
13792 return "DW_OP_reg19";
13794 return "DW_OP_reg20";
13796 return "DW_OP_reg21";
13798 return "DW_OP_reg22";
13800 return "DW_OP_reg23";
13802 return "DW_OP_reg24";
13804 return "DW_OP_reg25";
13806 return "DW_OP_reg26";
13808 return "DW_OP_reg27";
13810 return "DW_OP_reg28";
13812 return "DW_OP_reg29";
13814 return "DW_OP_reg30";
13816 return "DW_OP_reg31";
13818 return "DW_OP_breg0";
13820 return "DW_OP_breg1";
13822 return "DW_OP_breg2";
13824 return "DW_OP_breg3";
13826 return "DW_OP_breg4";
13828 return "DW_OP_breg5";
13830 return "DW_OP_breg6";
13832 return "DW_OP_breg7";
13834 return "DW_OP_breg8";
13836 return "DW_OP_breg9";
13838 return "DW_OP_breg10";
13840 return "DW_OP_breg11";
13842 return "DW_OP_breg12";
13844 return "DW_OP_breg13";
13846 return "DW_OP_breg14";
13848 return "DW_OP_breg15";
13850 return "DW_OP_breg16";
13852 return "DW_OP_breg17";
13854 return "DW_OP_breg18";
13856 return "DW_OP_breg19";
13858 return "DW_OP_breg20";
13860 return "DW_OP_breg21";
13862 return "DW_OP_breg22";
13864 return "DW_OP_breg23";
13866 return "DW_OP_breg24";
13868 return "DW_OP_breg25";
13870 return "DW_OP_breg26";
13872 return "DW_OP_breg27";
13874 return "DW_OP_breg28";
13876 return "DW_OP_breg29";
13878 return "DW_OP_breg30";
13880 return "DW_OP_breg31";
13882 return "DW_OP_regx";
13884 return "DW_OP_fbreg";
13886 return "DW_OP_bregx";
13888 return "DW_OP_piece";
13889 case DW_OP_deref_size
:
13890 return "DW_OP_deref_size";
13891 case DW_OP_xderef_size
:
13892 return "DW_OP_xderef_size";
13894 return "DW_OP_nop";
13895 /* DWARF 3 extensions. */
13896 case DW_OP_push_object_address
:
13897 return "DW_OP_push_object_address";
13899 return "DW_OP_call2";
13901 return "DW_OP_call4";
13902 case DW_OP_call_ref
:
13903 return "DW_OP_call_ref";
13904 case DW_OP_form_tls_address
:
13905 return "DW_OP_form_tls_address";
13906 case DW_OP_call_frame_cfa
:
13907 return "DW_OP_call_frame_cfa";
13908 case DW_OP_bit_piece
:
13909 return "DW_OP_bit_piece";
13910 /* DWARF 4 extensions. */
13911 case DW_OP_implicit_value
:
13912 return "DW_OP_implicit_value";
13913 case DW_OP_stack_value
:
13914 return "DW_OP_stack_value";
13915 /* GNU extensions. */
13916 case DW_OP_GNU_push_tls_address
:
13917 return "DW_OP_GNU_push_tls_address";
13918 case DW_OP_GNU_uninit
:
13919 return "DW_OP_GNU_uninit";
13920 case DW_OP_GNU_encoded_addr
:
13921 return "DW_OP_GNU_encoded_addr";
13922 case DW_OP_GNU_implicit_pointer
:
13923 return "DW_OP_GNU_implicit_pointer";
13924 case DW_OP_GNU_entry_value
:
13925 return "DW_OP_GNU_entry_value";
13926 case DW_OP_GNU_const_type
:
13927 return "DW_OP_GNU_const_type";
13928 case DW_OP_GNU_regval_type
:
13929 return "DW_OP_GNU_regval_type";
13930 case DW_OP_GNU_deref_type
:
13931 return "DW_OP_GNU_deref_type";
13932 case DW_OP_GNU_convert
:
13933 return "DW_OP_GNU_convert";
13934 case DW_OP_GNU_reinterpret
:
13935 return "DW_OP_GNU_reinterpret";
13936 case DW_OP_GNU_parameter_ref
:
13937 return "DW_OP_GNU_parameter_ref";
13944 dwarf_bool_name (unsigned mybool
)
13952 /* Convert a DWARF type code into its string name. */
13955 dwarf_type_encoding_name (unsigned enc
)
13960 return "DW_ATE_void";
13961 case DW_ATE_address
:
13962 return "DW_ATE_address";
13963 case DW_ATE_boolean
:
13964 return "DW_ATE_boolean";
13965 case DW_ATE_complex_float
:
13966 return "DW_ATE_complex_float";
13968 return "DW_ATE_float";
13969 case DW_ATE_signed
:
13970 return "DW_ATE_signed";
13971 case DW_ATE_signed_char
:
13972 return "DW_ATE_signed_char";
13973 case DW_ATE_unsigned
:
13974 return "DW_ATE_unsigned";
13975 case DW_ATE_unsigned_char
:
13976 return "DW_ATE_unsigned_char";
13978 case DW_ATE_imaginary_float
:
13979 return "DW_ATE_imaginary_float";
13980 case DW_ATE_packed_decimal
:
13981 return "DW_ATE_packed_decimal";
13982 case DW_ATE_numeric_string
:
13983 return "DW_ATE_numeric_string";
13984 case DW_ATE_edited
:
13985 return "DW_ATE_edited";
13986 case DW_ATE_signed_fixed
:
13987 return "DW_ATE_signed_fixed";
13988 case DW_ATE_unsigned_fixed
:
13989 return "DW_ATE_unsigned_fixed";
13990 case DW_ATE_decimal_float
:
13991 return "DW_ATE_decimal_float";
13994 return "DW_ATE_UTF";
13995 /* HP extensions. */
13996 case DW_ATE_HP_float80
:
13997 return "DW_ATE_HP_float80";
13998 case DW_ATE_HP_complex_float80
:
13999 return "DW_ATE_HP_complex_float80";
14000 case DW_ATE_HP_float128
:
14001 return "DW_ATE_HP_float128";
14002 case DW_ATE_HP_complex_float128
:
14003 return "DW_ATE_HP_complex_float128";
14004 case DW_ATE_HP_floathpintel
:
14005 return "DW_ATE_HP_floathpintel";
14006 case DW_ATE_HP_imaginary_float80
:
14007 return "DW_ATE_HP_imaginary_float80";
14008 case DW_ATE_HP_imaginary_float128
:
14009 return "DW_ATE_HP_imaginary_float128";
14011 return "DW_ATE_<unknown>";
14015 /* Convert a DWARF call frame info operation to its string name. */
14019 dwarf_cfi_name (unsigned cfi_opc
)
14023 case DW_CFA_advance_loc
:
14024 return "DW_CFA_advance_loc";
14025 case DW_CFA_offset
:
14026 return "DW_CFA_offset";
14027 case DW_CFA_restore
:
14028 return "DW_CFA_restore";
14030 return "DW_CFA_nop";
14031 case DW_CFA_set_loc
:
14032 return "DW_CFA_set_loc";
14033 case DW_CFA_advance_loc1
:
14034 return "DW_CFA_advance_loc1";
14035 case DW_CFA_advance_loc2
:
14036 return "DW_CFA_advance_loc2";
14037 case DW_CFA_advance_loc4
:
14038 return "DW_CFA_advance_loc4";
14039 case DW_CFA_offset_extended
:
14040 return "DW_CFA_offset_extended";
14041 case DW_CFA_restore_extended
:
14042 return "DW_CFA_restore_extended";
14043 case DW_CFA_undefined
:
14044 return "DW_CFA_undefined";
14045 case DW_CFA_same_value
:
14046 return "DW_CFA_same_value";
14047 case DW_CFA_register
:
14048 return "DW_CFA_register";
14049 case DW_CFA_remember_state
:
14050 return "DW_CFA_remember_state";
14051 case DW_CFA_restore_state
:
14052 return "DW_CFA_restore_state";
14053 case DW_CFA_def_cfa
:
14054 return "DW_CFA_def_cfa";
14055 case DW_CFA_def_cfa_register
:
14056 return "DW_CFA_def_cfa_register";
14057 case DW_CFA_def_cfa_offset
:
14058 return "DW_CFA_def_cfa_offset";
14060 case DW_CFA_def_cfa_expression
:
14061 return "DW_CFA_def_cfa_expression";
14062 case DW_CFA_expression
:
14063 return "DW_CFA_expression";
14064 case DW_CFA_offset_extended_sf
:
14065 return "DW_CFA_offset_extended_sf";
14066 case DW_CFA_def_cfa_sf
:
14067 return "DW_CFA_def_cfa_sf";
14068 case DW_CFA_def_cfa_offset_sf
:
14069 return "DW_CFA_def_cfa_offset_sf";
14070 case DW_CFA_val_offset
:
14071 return "DW_CFA_val_offset";
14072 case DW_CFA_val_offset_sf
:
14073 return "DW_CFA_val_offset_sf";
14074 case DW_CFA_val_expression
:
14075 return "DW_CFA_val_expression";
14076 /* SGI/MIPS specific. */
14077 case DW_CFA_MIPS_advance_loc8
:
14078 return "DW_CFA_MIPS_advance_loc8";
14079 /* GNU extensions. */
14080 case DW_CFA_GNU_window_save
:
14081 return "DW_CFA_GNU_window_save";
14082 case DW_CFA_GNU_args_size
:
14083 return "DW_CFA_GNU_args_size";
14084 case DW_CFA_GNU_negative_offset_extended
:
14085 return "DW_CFA_GNU_negative_offset_extended";
14087 return "DW_CFA_<unknown>";
14093 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
14097 print_spaces (indent
, f
);
14098 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
14099 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
.sect_off
);
14101 if (die
->parent
!= NULL
)
14103 print_spaces (indent
, f
);
14104 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
14105 die
->parent
->offset
.sect_off
);
14108 print_spaces (indent
, f
);
14109 fprintf_unfiltered (f
, " has children: %s\n",
14110 dwarf_bool_name (die
->child
!= NULL
));
14112 print_spaces (indent
, f
);
14113 fprintf_unfiltered (f
, " attributes:\n");
14115 for (i
= 0; i
< die
->num_attrs
; ++i
)
14117 print_spaces (indent
, f
);
14118 fprintf_unfiltered (f
, " %s (%s) ",
14119 dwarf_attr_name (die
->attrs
[i
].name
),
14120 dwarf_form_name (die
->attrs
[i
].form
));
14122 switch (die
->attrs
[i
].form
)
14125 fprintf_unfiltered (f
, "address: ");
14126 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
14128 case DW_FORM_block2
:
14129 case DW_FORM_block4
:
14130 case DW_FORM_block
:
14131 case DW_FORM_block1
:
14132 fprintf_unfiltered (f
, "block: size %d",
14133 DW_BLOCK (&die
->attrs
[i
])->size
);
14135 case DW_FORM_exprloc
:
14136 fprintf_unfiltered (f
, "expression: size %u",
14137 DW_BLOCK (&die
->attrs
[i
])->size
);
14139 case DW_FORM_ref_addr
:
14140 fprintf_unfiltered (f
, "ref address: ");
14141 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
14147 case DW_FORM_ref_udata
:
14148 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
14149 (long) (DW_UNSND (&die
->attrs
[i
])));
14151 case DW_FORM_data1
:
14152 case DW_FORM_data2
:
14153 case DW_FORM_data4
:
14154 case DW_FORM_data8
:
14155 case DW_FORM_udata
:
14156 case DW_FORM_sdata
:
14157 fprintf_unfiltered (f
, "constant: %s",
14158 pulongest (DW_UNSND (&die
->attrs
[i
])));
14160 case DW_FORM_sec_offset
:
14161 fprintf_unfiltered (f
, "section offset: %s",
14162 pulongest (DW_UNSND (&die
->attrs
[i
])));
14164 case DW_FORM_ref_sig8
:
14165 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
14166 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
14167 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
.sect_off
);
14169 fprintf_unfiltered (f
, "signatured type, offset: unknown");
14171 case DW_FORM_string
:
14173 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
14174 DW_STRING (&die
->attrs
[i
])
14175 ? DW_STRING (&die
->attrs
[i
]) : "",
14176 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
14179 if (DW_UNSND (&die
->attrs
[i
]))
14180 fprintf_unfiltered (f
, "flag: TRUE");
14182 fprintf_unfiltered (f
, "flag: FALSE");
14184 case DW_FORM_flag_present
:
14185 fprintf_unfiltered (f
, "flag: TRUE");
14187 case DW_FORM_indirect
:
14188 /* The reader will have reduced the indirect form to
14189 the "base form" so this form should not occur. */
14190 fprintf_unfiltered (f
,
14191 "unexpected attribute form: DW_FORM_indirect");
14194 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
14195 die
->attrs
[i
].form
);
14198 fprintf_unfiltered (f
, "\n");
14203 dump_die_for_error (struct die_info
*die
)
14205 dump_die_shallow (gdb_stderr
, 0, die
);
14209 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
14211 int indent
= level
* 4;
14213 gdb_assert (die
!= NULL
);
14215 if (level
>= max_level
)
14218 dump_die_shallow (f
, indent
, die
);
14220 if (die
->child
!= NULL
)
14222 print_spaces (indent
, f
);
14223 fprintf_unfiltered (f
, " Children:");
14224 if (level
+ 1 < max_level
)
14226 fprintf_unfiltered (f
, "\n");
14227 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
14231 fprintf_unfiltered (f
,
14232 " [not printed, max nesting level reached]\n");
14236 if (die
->sibling
!= NULL
&& level
> 0)
14238 dump_die_1 (f
, level
, max_level
, die
->sibling
);
14242 /* This is called from the pdie macro in gdbinit.in.
14243 It's not static so gcc will keep a copy callable from gdb. */
14246 dump_die (struct die_info
*die
, int max_level
)
14248 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
14252 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
14256 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
.sect_off
,
14262 /* DW_ADDR is always stored already as sect_offset; despite for the forms
14263 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
14266 is_ref_attr (struct attribute
*attr
)
14268 switch (attr
->form
)
14270 case DW_FORM_ref_addr
:
14275 case DW_FORM_ref_udata
:
14282 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
14286 dwarf2_get_ref_die_offset (struct attribute
*attr
)
14288 sect_offset retval
= { DW_UNSND (attr
) };
14290 if (is_ref_attr (attr
))
14293 retval
.sect_off
= 0;
14294 complaint (&symfile_complaints
,
14295 _("unsupported die ref attribute form: '%s'"),
14296 dwarf_form_name (attr
->form
));
14300 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
14301 * the value held by the attribute is not constant. */
14304 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
14306 if (attr
->form
== DW_FORM_sdata
)
14307 return DW_SND (attr
);
14308 else if (attr
->form
== DW_FORM_udata
14309 || attr
->form
== DW_FORM_data1
14310 || attr
->form
== DW_FORM_data2
14311 || attr
->form
== DW_FORM_data4
14312 || attr
->form
== DW_FORM_data8
)
14313 return DW_UNSND (attr
);
14316 complaint (&symfile_complaints
,
14317 _("Attribute value is not a constant (%s)"),
14318 dwarf_form_name (attr
->form
));
14319 return default_value
;
14323 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
14324 unit and add it to our queue.
14325 The result is non-zero if PER_CU was queued, otherwise the result is zero
14326 meaning either PER_CU is already queued or it is already loaded. */
14329 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
14330 struct dwarf2_per_cu_data
*per_cu
)
14332 /* We may arrive here during partial symbol reading, if we need full
14333 DIEs to process an unusual case (e.g. template arguments). Do
14334 not queue PER_CU, just tell our caller to load its DIEs. */
14335 if (dwarf2_per_objfile
->reading_partial_symbols
)
14337 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
14342 /* Mark the dependence relation so that we don't flush PER_CU
14344 dwarf2_add_dependence (this_cu
, per_cu
);
14346 /* If it's already on the queue, we have nothing to do. */
14347 if (per_cu
->queued
)
14350 /* If the compilation unit is already loaded, just mark it as
14352 if (per_cu
->cu
!= NULL
)
14354 per_cu
->cu
->last_used
= 0;
14358 /* Add it to the queue. */
14359 queue_comp_unit (per_cu
);
14364 /* Follow reference or signature attribute ATTR of SRC_DIE.
14365 On entry *REF_CU is the CU of SRC_DIE.
14366 On exit *REF_CU is the CU of the result. */
14368 static struct die_info
*
14369 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
14370 struct dwarf2_cu
**ref_cu
)
14372 struct die_info
*die
;
14374 if (is_ref_attr (attr
))
14375 die
= follow_die_ref (src_die
, attr
, ref_cu
);
14376 else if (attr
->form
== DW_FORM_ref_sig8
)
14377 die
= follow_die_sig (src_die
, attr
, ref_cu
);
14380 dump_die_for_error (src_die
);
14381 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
14382 (*ref_cu
)->objfile
->name
);
14388 /* Follow reference OFFSET.
14389 On entry *REF_CU is the CU of the source die referencing OFFSET.
14390 On exit *REF_CU is the CU of the result.
14391 Returns NULL if OFFSET is invalid. */
14393 static struct die_info
*
14394 follow_die_offset (sect_offset offset
, struct dwarf2_cu
**ref_cu
)
14396 struct die_info temp_die
;
14397 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
14399 gdb_assert (cu
->per_cu
!= NULL
);
14403 if (cu
->per_cu
->debug_types_section
)
14405 /* .debug_types CUs cannot reference anything outside their CU.
14406 If they need to, they have to reference a signatured type via
14407 DW_FORM_ref_sig8. */
14408 if (! offset_in_cu_p (&cu
->header
, offset
))
14411 else if (! offset_in_cu_p (&cu
->header
, offset
))
14413 struct dwarf2_per_cu_data
*per_cu
;
14415 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
14417 /* If necessary, add it to the queue and load its DIEs. */
14418 if (maybe_queue_comp_unit (cu
, per_cu
))
14419 load_full_comp_unit (per_cu
);
14421 target_cu
= per_cu
->cu
;
14423 else if (cu
->dies
== NULL
)
14425 /* We're loading full DIEs during partial symbol reading. */
14426 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
14427 load_full_comp_unit (cu
->per_cu
);
14430 *ref_cu
= target_cu
;
14431 temp_die
.offset
= offset
;
14432 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
.sect_off
);
14435 /* Follow reference attribute ATTR of SRC_DIE.
14436 On entry *REF_CU is the CU of SRC_DIE.
14437 On exit *REF_CU is the CU of the result. */
14439 static struct die_info
*
14440 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
14441 struct dwarf2_cu
**ref_cu
)
14443 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
14444 struct dwarf2_cu
*cu
= *ref_cu
;
14445 struct die_info
*die
;
14447 die
= follow_die_offset (offset
, ref_cu
);
14449 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
14450 "at 0x%x [in module %s]"),
14451 offset
.sect_off
, src_die
->offset
.sect_off
, cu
->objfile
->name
);
14456 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
14457 Returned value is intended for DW_OP_call*. Returned
14458 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
14460 struct dwarf2_locexpr_baton
14461 dwarf2_fetch_die_location_block (cu_offset offset_in_cu
,
14462 struct dwarf2_per_cu_data
*per_cu
,
14463 CORE_ADDR (*get_frame_pc
) (void *baton
),
14466 sect_offset offset
= { per_cu
->offset
.sect_off
+ offset_in_cu
.cu_off
};
14467 struct dwarf2_cu
*cu
;
14468 struct die_info
*die
;
14469 struct attribute
*attr
;
14470 struct dwarf2_locexpr_baton retval
;
14472 dw2_setup (per_cu
->objfile
);
14474 if (per_cu
->cu
== NULL
)
14478 die
= follow_die_offset (offset
, &cu
);
14480 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
14481 offset
.sect_off
, per_cu
->objfile
->name
);
14483 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
14486 /* DWARF: "If there is no such attribute, then there is no effect.".
14487 DATA is ignored if SIZE is 0. */
14489 retval
.data
= NULL
;
14492 else if (attr_form_is_section_offset (attr
))
14494 struct dwarf2_loclist_baton loclist_baton
;
14495 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
14498 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
14500 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
14502 retval
.size
= size
;
14506 if (!attr_form_is_block (attr
))
14507 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
14508 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
14509 offset
.sect_off
, per_cu
->objfile
->name
);
14511 retval
.data
= DW_BLOCK (attr
)->data
;
14512 retval
.size
= DW_BLOCK (attr
)->size
;
14514 retval
.per_cu
= cu
->per_cu
;
14516 age_cached_comp_units ();
14521 /* Return the type of the DIE at DIE_OFFSET in the CU named by
14525 dwarf2_get_die_type (cu_offset die_offset
,
14526 struct dwarf2_per_cu_data
*per_cu
)
14528 sect_offset die_offset_sect
;
14530 dw2_setup (per_cu
->objfile
);
14532 die_offset_sect
.sect_off
= per_cu
->offset
.sect_off
+ die_offset
.cu_off
;
14533 return get_die_type_at_offset (die_offset_sect
, per_cu
);
14536 /* Follow the signature attribute ATTR in SRC_DIE.
14537 On entry *REF_CU is the CU of SRC_DIE.
14538 On exit *REF_CU is the CU of the result. */
14540 static struct die_info
*
14541 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
14542 struct dwarf2_cu
**ref_cu
)
14544 struct objfile
*objfile
= (*ref_cu
)->objfile
;
14545 struct die_info temp_die
;
14546 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
14547 struct dwarf2_cu
*sig_cu
;
14548 struct die_info
*die
;
14550 /* sig_type will be NULL if the signatured type is missing from
14552 if (sig_type
== NULL
)
14553 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
14554 "at 0x%x [in module %s]"),
14555 src_die
->offset
.sect_off
, objfile
->name
);
14557 /* If necessary, add it to the queue and load its DIEs. */
14559 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
14560 read_signatured_type (sig_type
);
14562 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
14564 sig_cu
= sig_type
->per_cu
.cu
;
14565 temp_die
.offset
.sect_off
= (sig_type
->per_cu
.offset
.sect_off
14566 + sig_type
->type_offset
.cu_off
);
14567 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
14568 temp_die
.offset
.sect_off
);
14575 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
14576 "from DIE at 0x%x [in module %s]"),
14577 temp_die
.offset
.sect_off
, src_die
->offset
.sect_off
, objfile
->name
);
14580 /* Given an offset of a signatured type, return its signatured_type. */
14582 static struct signatured_type
*
14583 lookup_signatured_type_at_offset (struct objfile
*objfile
,
14584 struct dwarf2_section_info
*section
,
14585 sect_offset offset
)
14587 gdb_byte
*info_ptr
= section
->buffer
+ offset
.sect_off
;
14588 unsigned int length
, initial_length_size
;
14589 unsigned int sig_offset
;
14590 struct signatured_type find_entry
, *sig_type
;
14592 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
14593 sig_offset
= (initial_length_size
14595 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
14596 + 1 /*address_size*/);
14597 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
14598 sig_type
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
14600 /* This is only used to lookup previously recorded types.
14601 If we didn't find it, it's our bug. */
14602 gdb_assert (sig_type
!= NULL
);
14603 gdb_assert (offset
.sect_off
== sig_type
->per_cu
.offset
.sect_off
);
14608 /* Load the DIEs associated with type unit PER_CU into memory. */
14611 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
14613 struct objfile
*objfile
= per_cu
->objfile
;
14614 struct dwarf2_section_info
*sect
= per_cu
->debug_types_section
;
14615 sect_offset offset
= per_cu
->offset
;
14616 struct signatured_type
*sig_type
;
14618 dwarf2_read_section (objfile
, sect
);
14620 /* We have the section offset, but we need the signature to do the
14621 hash table lookup. */
14622 /* FIXME: This is sorta unnecessary, read_signatured_type only uses
14623 the signature to assert we found the right one.
14624 Ok, but it's a lot of work. We should simplify things so any needed
14625 assert doesn't require all this clumsiness. */
14626 sig_type
= lookup_signatured_type_at_offset (objfile
, sect
, offset
);
14628 gdb_assert (sig_type
->per_cu
.cu
== NULL
);
14630 read_signatured_type (sig_type
);
14632 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
14635 /* Read in a signatured type and build its CU and DIEs. */
14638 read_signatured_type (struct signatured_type
*sig_type
)
14640 struct objfile
*objfile
= sig_type
->per_cu
.objfile
;
14641 gdb_byte
*types_ptr
;
14642 struct die_reader_specs reader_specs
;
14643 struct dwarf2_cu
*cu
;
14644 ULONGEST signature
;
14645 struct cleanup
*back_to
, *free_cu_cleanup
;
14646 struct dwarf2_section_info
*section
= sig_type
->per_cu
.debug_types_section
;
14648 dwarf2_read_section (objfile
, section
);
14649 types_ptr
= section
->buffer
+ sig_type
->per_cu
.offset
.sect_off
;
14651 gdb_assert (sig_type
->per_cu
.cu
== NULL
);
14653 cu
= xmalloc (sizeof (*cu
));
14654 init_one_comp_unit (cu
, &sig_type
->per_cu
);
14656 /* If an error occurs while loading, release our storage. */
14657 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
14659 types_ptr
= read_and_check_type_unit_head (&cu
->header
, section
, types_ptr
,
14661 gdb_assert (signature
== sig_type
->signature
);
14664 = htab_create_alloc_ex (cu
->header
.length
/ 12,
14668 &cu
->comp_unit_obstack
,
14669 hashtab_obstack_allocate
,
14670 dummy_obstack_deallocate
);
14672 dwarf2_read_abbrevs (cu
);
14673 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
14675 init_cu_die_reader (&reader_specs
, cu
);
14677 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
14680 /* We try not to read any attributes in this function, because not
14681 all CUs needed for references have been loaded yet, and symbol
14682 table processing isn't initialized. But we have to set the CU language,
14683 or we won't be able to build types correctly. */
14684 prepare_one_comp_unit (cu
, cu
->dies
);
14686 do_cleanups (back_to
);
14688 /* We've successfully allocated this compilation unit. Let our caller
14689 clean it up when finished with it. */
14690 discard_cleanups (free_cu_cleanup
);
14692 /* Link this TU into read_in_chain. */
14693 sig_type
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
14694 dwarf2_per_objfile
->read_in_chain
= &sig_type
->per_cu
;
14697 /* Decode simple location descriptions.
14698 Given a pointer to a dwarf block that defines a location, compute
14699 the location and return the value.
14701 NOTE drow/2003-11-18: This function is called in two situations
14702 now: for the address of static or global variables (partial symbols
14703 only) and for offsets into structures which are expected to be
14704 (more or less) constant. The partial symbol case should go away,
14705 and only the constant case should remain. That will let this
14706 function complain more accurately. A few special modes are allowed
14707 without complaint for global variables (for instance, global
14708 register values and thread-local values).
14710 A location description containing no operations indicates that the
14711 object is optimized out. The return value is 0 for that case.
14712 FIXME drow/2003-11-16: No callers check for this case any more; soon all
14713 callers will only want a very basic result and this can become a
14716 Note that stack[0] is unused except as a default error return. */
14719 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
14721 struct objfile
*objfile
= cu
->objfile
;
14723 int size
= blk
->size
;
14724 gdb_byte
*data
= blk
->data
;
14725 CORE_ADDR stack
[64];
14727 unsigned int bytes_read
, unsnd
;
14733 stack
[++stacki
] = 0;
14772 stack
[++stacki
] = op
- DW_OP_lit0
;
14807 stack
[++stacki
] = op
- DW_OP_reg0
;
14809 dwarf2_complex_location_expr_complaint ();
14813 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
14815 stack
[++stacki
] = unsnd
;
14817 dwarf2_complex_location_expr_complaint ();
14821 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
14826 case DW_OP_const1u
:
14827 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
14831 case DW_OP_const1s
:
14832 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
14836 case DW_OP_const2u
:
14837 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
14841 case DW_OP_const2s
:
14842 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
14846 case DW_OP_const4u
:
14847 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
14851 case DW_OP_const4s
:
14852 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
14856 case DW_OP_const8u
:
14857 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
14862 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
14868 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
14873 stack
[stacki
+ 1] = stack
[stacki
];
14878 stack
[stacki
- 1] += stack
[stacki
];
14882 case DW_OP_plus_uconst
:
14883 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
14889 stack
[stacki
- 1] -= stack
[stacki
];
14894 /* If we're not the last op, then we definitely can't encode
14895 this using GDB's address_class enum. This is valid for partial
14896 global symbols, although the variable's address will be bogus
14899 dwarf2_complex_location_expr_complaint ();
14902 case DW_OP_GNU_push_tls_address
:
14903 /* The top of the stack has the offset from the beginning
14904 of the thread control block at which the variable is located. */
14905 /* Nothing should follow this operator, so the top of stack would
14907 /* This is valid for partial global symbols, but the variable's
14908 address will be bogus in the psymtab. Make it always at least
14909 non-zero to not look as a variable garbage collected by linker
14910 which have DW_OP_addr 0. */
14912 dwarf2_complex_location_expr_complaint ();
14916 case DW_OP_GNU_uninit
:
14921 const char *name
= dwarf_stack_op_name (op
);
14924 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
14927 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
14931 return (stack
[stacki
]);
14934 /* Enforce maximum stack depth of SIZE-1 to avoid writing
14935 outside of the allocated space. Also enforce minimum>0. */
14936 if (stacki
>= ARRAY_SIZE (stack
) - 1)
14938 complaint (&symfile_complaints
,
14939 _("location description stack overflow"));
14945 complaint (&symfile_complaints
,
14946 _("location description stack underflow"));
14950 return (stack
[stacki
]);
14953 /* memory allocation interface */
14955 static struct dwarf_block
*
14956 dwarf_alloc_block (struct dwarf2_cu
*cu
)
14958 struct dwarf_block
*blk
;
14960 blk
= (struct dwarf_block
*)
14961 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
14965 static struct abbrev_info
*
14966 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
14968 struct abbrev_info
*abbrev
;
14970 abbrev
= (struct abbrev_info
*)
14971 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
14972 memset (abbrev
, 0, sizeof (struct abbrev_info
));
14976 static struct die_info
*
14977 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
14979 struct die_info
*die
;
14980 size_t size
= sizeof (struct die_info
);
14983 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
14985 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
14986 memset (die
, 0, sizeof (struct die_info
));
14991 /* Macro support. */
14993 /* Return the full name of file number I in *LH's file name table.
14994 Use COMP_DIR as the name of the current directory of the
14995 compilation. The result is allocated using xmalloc; the caller is
14996 responsible for freeing it. */
14998 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
15000 /* Is the file number a valid index into the line header's file name
15001 table? Remember that file numbers start with one, not zero. */
15002 if (1 <= file
&& file
<= lh
->num_file_names
)
15004 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
15006 if (IS_ABSOLUTE_PATH (fe
->name
))
15007 return xstrdup (fe
->name
);
15015 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
15021 dir_len
= strlen (dir
);
15022 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
15023 strcpy (full_name
, dir
);
15024 full_name
[dir_len
] = '/';
15025 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
15029 return xstrdup (fe
->name
);
15034 /* The compiler produced a bogus file number. We can at least
15035 record the macro definitions made in the file, even if we
15036 won't be able to find the file by name. */
15037 char fake_name
[80];
15039 sprintf (fake_name
, "<bad macro file number %d>", file
);
15041 complaint (&symfile_complaints
,
15042 _("bad file number in macro information (%d)"),
15045 return xstrdup (fake_name
);
15050 static struct macro_source_file
*
15051 macro_start_file (int file
, int line
,
15052 struct macro_source_file
*current_file
,
15053 const char *comp_dir
,
15054 struct line_header
*lh
, struct objfile
*objfile
)
15056 /* The full name of this source file. */
15057 char *full_name
= file_full_name (file
, lh
, comp_dir
);
15059 /* We don't create a macro table for this compilation unit
15060 at all until we actually get a filename. */
15061 if (! pending_macros
)
15062 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
15063 objfile
->macro_cache
);
15065 if (! current_file
)
15066 /* If we have no current file, then this must be the start_file
15067 directive for the compilation unit's main source file. */
15068 current_file
= macro_set_main (pending_macros
, full_name
);
15070 current_file
= macro_include (current_file
, line
, full_name
);
15074 return current_file
;
15078 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
15079 followed by a null byte. */
15081 copy_string (const char *buf
, int len
)
15083 char *s
= xmalloc (len
+ 1);
15085 memcpy (s
, buf
, len
);
15091 static const char *
15092 consume_improper_spaces (const char *p
, const char *body
)
15096 complaint (&symfile_complaints
,
15097 _("macro definition contains spaces "
15098 "in formal argument list:\n`%s'"),
15110 parse_macro_definition (struct macro_source_file
*file
, int line
,
15115 /* The body string takes one of two forms. For object-like macro
15116 definitions, it should be:
15118 <macro name> " " <definition>
15120 For function-like macro definitions, it should be:
15122 <macro name> "() " <definition>
15124 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
15126 Spaces may appear only where explicitly indicated, and in the
15129 The Dwarf 2 spec says that an object-like macro's name is always
15130 followed by a space, but versions of GCC around March 2002 omit
15131 the space when the macro's definition is the empty string.
15133 The Dwarf 2 spec says that there should be no spaces between the
15134 formal arguments in a function-like macro's formal argument list,
15135 but versions of GCC around March 2002 include spaces after the
15139 /* Find the extent of the macro name. The macro name is terminated
15140 by either a space or null character (for an object-like macro) or
15141 an opening paren (for a function-like macro). */
15142 for (p
= body
; *p
; p
++)
15143 if (*p
== ' ' || *p
== '(')
15146 if (*p
== ' ' || *p
== '\0')
15148 /* It's an object-like macro. */
15149 int name_len
= p
- body
;
15150 char *name
= copy_string (body
, name_len
);
15151 const char *replacement
;
15154 replacement
= body
+ name_len
+ 1;
15157 dwarf2_macro_malformed_definition_complaint (body
);
15158 replacement
= body
+ name_len
;
15161 macro_define_object (file
, line
, name
, replacement
);
15165 else if (*p
== '(')
15167 /* It's a function-like macro. */
15168 char *name
= copy_string (body
, p
- body
);
15171 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
15175 p
= consume_improper_spaces (p
, body
);
15177 /* Parse the formal argument list. */
15178 while (*p
&& *p
!= ')')
15180 /* Find the extent of the current argument name. */
15181 const char *arg_start
= p
;
15183 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
15186 if (! *p
|| p
== arg_start
)
15187 dwarf2_macro_malformed_definition_complaint (body
);
15190 /* Make sure argv has room for the new argument. */
15191 if (argc
>= argv_size
)
15194 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
15197 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
15200 p
= consume_improper_spaces (p
, body
);
15202 /* Consume the comma, if present. */
15207 p
= consume_improper_spaces (p
, body
);
15216 /* Perfectly formed definition, no complaints. */
15217 macro_define_function (file
, line
, name
,
15218 argc
, (const char **) argv
,
15220 else if (*p
== '\0')
15222 /* Complain, but do define it. */
15223 dwarf2_macro_malformed_definition_complaint (body
);
15224 macro_define_function (file
, line
, name
,
15225 argc
, (const char **) argv
,
15229 /* Just complain. */
15230 dwarf2_macro_malformed_definition_complaint (body
);
15233 /* Just complain. */
15234 dwarf2_macro_malformed_definition_complaint (body
);
15240 for (i
= 0; i
< argc
; i
++)
15246 dwarf2_macro_malformed_definition_complaint (body
);
15249 /* Skip some bytes from BYTES according to the form given in FORM.
15250 Returns the new pointer. */
15253 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
,
15254 enum dwarf_form form
,
15255 unsigned int offset_size
,
15256 struct dwarf2_section_info
*section
)
15258 unsigned int bytes_read
;
15262 case DW_FORM_data1
:
15267 case DW_FORM_data2
:
15271 case DW_FORM_data4
:
15275 case DW_FORM_data8
:
15279 case DW_FORM_string
:
15280 read_direct_string (abfd
, bytes
, &bytes_read
);
15281 bytes
+= bytes_read
;
15284 case DW_FORM_sec_offset
:
15286 bytes
+= offset_size
;
15289 case DW_FORM_block
:
15290 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
15291 bytes
+= bytes_read
;
15294 case DW_FORM_block1
:
15295 bytes
+= 1 + read_1_byte (abfd
, bytes
);
15297 case DW_FORM_block2
:
15298 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
15300 case DW_FORM_block4
:
15301 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
15304 case DW_FORM_sdata
:
15305 case DW_FORM_udata
:
15306 bytes
= skip_leb128 (abfd
, bytes
);
15312 complaint (&symfile_complaints
,
15313 _("invalid form 0x%x in `%s'"),
15315 section
->asection
->name
);
15323 /* A helper for dwarf_decode_macros that handles skipping an unknown
15324 opcode. Returns an updated pointer to the macro data buffer; or,
15325 on error, issues a complaint and returns NULL. */
15328 skip_unknown_opcode (unsigned int opcode
,
15329 gdb_byte
**opcode_definitions
,
15332 unsigned int offset_size
,
15333 struct dwarf2_section_info
*section
)
15335 unsigned int bytes_read
, i
;
15339 if (opcode_definitions
[opcode
] == NULL
)
15341 complaint (&symfile_complaints
,
15342 _("unrecognized DW_MACFINO opcode 0x%x"),
15347 defn
= opcode_definitions
[opcode
];
15348 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
15349 defn
+= bytes_read
;
15351 for (i
= 0; i
< arg
; ++i
)
15353 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, defn
[i
], offset_size
, section
);
15354 if (mac_ptr
== NULL
)
15356 /* skip_form_bytes already issued the complaint. */
15364 /* A helper function which parses the header of a macro section.
15365 If the macro section is the extended (for now called "GNU") type,
15366 then this updates *OFFSET_SIZE. Returns a pointer to just after
15367 the header, or issues a complaint and returns NULL on error. */
15370 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
15373 unsigned int *offset_size
,
15374 int section_is_gnu
)
15376 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
15378 if (section_is_gnu
)
15380 unsigned int version
, flags
;
15382 version
= read_2_bytes (abfd
, mac_ptr
);
15385 complaint (&symfile_complaints
,
15386 _("unrecognized version `%d' in .debug_macro section"),
15392 flags
= read_1_byte (abfd
, mac_ptr
);
15394 *offset_size
= (flags
& 1) ? 8 : 4;
15396 if ((flags
& 2) != 0)
15397 /* We don't need the line table offset. */
15398 mac_ptr
+= *offset_size
;
15400 /* Vendor opcode descriptions. */
15401 if ((flags
& 4) != 0)
15403 unsigned int i
, count
;
15405 count
= read_1_byte (abfd
, mac_ptr
);
15407 for (i
= 0; i
< count
; ++i
)
15409 unsigned int opcode
, bytes_read
;
15412 opcode
= read_1_byte (abfd
, mac_ptr
);
15414 opcode_definitions
[opcode
] = mac_ptr
;
15415 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15416 mac_ptr
+= bytes_read
;
15425 /* A helper for dwarf_decode_macros that handles the GNU extensions,
15426 including DW_MACRO_GNU_transparent_include. */
15429 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
15430 struct macro_source_file
*current_file
,
15431 struct line_header
*lh
, char *comp_dir
,
15432 struct dwarf2_section_info
*section
,
15433 int section_is_gnu
,
15434 unsigned int offset_size
,
15435 struct objfile
*objfile
,
15436 htab_t include_hash
)
15438 enum dwarf_macro_record_type macinfo_type
;
15439 int at_commandline
;
15440 gdb_byte
*opcode_definitions
[256];
15442 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
15443 &offset_size
, section_is_gnu
);
15444 if (mac_ptr
== NULL
)
15446 /* We already issued a complaint. */
15450 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
15451 GDB is still reading the definitions from command line. First
15452 DW_MACINFO_start_file will need to be ignored as it was already executed
15453 to create CURRENT_FILE for the main source holding also the command line
15454 definitions. On first met DW_MACINFO_start_file this flag is reset to
15455 normally execute all the remaining DW_MACINFO_start_file macinfos. */
15457 at_commandline
= 1;
15461 /* Do we at least have room for a macinfo type byte? */
15462 if (mac_ptr
>= mac_end
)
15464 dwarf2_macros_too_long_complaint (section
);
15468 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
15471 /* Note that we rely on the fact that the corresponding GNU and
15472 DWARF constants are the same. */
15473 switch (macinfo_type
)
15475 /* A zero macinfo type indicates the end of the macro
15480 case DW_MACRO_GNU_define
:
15481 case DW_MACRO_GNU_undef
:
15482 case DW_MACRO_GNU_define_indirect
:
15483 case DW_MACRO_GNU_undef_indirect
:
15485 unsigned int bytes_read
;
15490 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15491 mac_ptr
+= bytes_read
;
15493 if (macinfo_type
== DW_MACRO_GNU_define
15494 || macinfo_type
== DW_MACRO_GNU_undef
)
15496 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15497 mac_ptr
+= bytes_read
;
15501 LONGEST str_offset
;
15503 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
15504 mac_ptr
+= offset_size
;
15506 body
= read_indirect_string_at_offset (abfd
, str_offset
);
15509 is_define
= (macinfo_type
== DW_MACRO_GNU_define
15510 || macinfo_type
== DW_MACRO_GNU_define_indirect
);
15511 if (! current_file
)
15513 /* DWARF violation as no main source is present. */
15514 complaint (&symfile_complaints
,
15515 _("debug info with no main source gives macro %s "
15517 is_define
? _("definition") : _("undefinition"),
15521 if ((line
== 0 && !at_commandline
)
15522 || (line
!= 0 && at_commandline
))
15523 complaint (&symfile_complaints
,
15524 _("debug info gives %s macro %s with %s line %d: %s"),
15525 at_commandline
? _("command-line") : _("in-file"),
15526 is_define
? _("definition") : _("undefinition"),
15527 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
15530 parse_macro_definition (current_file
, line
, body
);
15533 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
15534 || macinfo_type
== DW_MACRO_GNU_undef_indirect
);
15535 macro_undef (current_file
, line
, body
);
15540 case DW_MACRO_GNU_start_file
:
15542 unsigned int bytes_read
;
15545 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15546 mac_ptr
+= bytes_read
;
15547 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15548 mac_ptr
+= bytes_read
;
15550 if ((line
== 0 && !at_commandline
)
15551 || (line
!= 0 && at_commandline
))
15552 complaint (&symfile_complaints
,
15553 _("debug info gives source %d included "
15554 "from %s at %s line %d"),
15555 file
, at_commandline
? _("command-line") : _("file"),
15556 line
== 0 ? _("zero") : _("non-zero"), line
);
15558 if (at_commandline
)
15560 /* This DW_MACRO_GNU_start_file was executed in the
15562 at_commandline
= 0;
15565 current_file
= macro_start_file (file
, line
,
15566 current_file
, comp_dir
,
15571 case DW_MACRO_GNU_end_file
:
15572 if (! current_file
)
15573 complaint (&symfile_complaints
,
15574 _("macro debug info has an unmatched "
15575 "`close_file' directive"));
15578 current_file
= current_file
->included_by
;
15579 if (! current_file
)
15581 enum dwarf_macro_record_type next_type
;
15583 /* GCC circa March 2002 doesn't produce the zero
15584 type byte marking the end of the compilation
15585 unit. Complain if it's not there, but exit no
15588 /* Do we at least have room for a macinfo type byte? */
15589 if (mac_ptr
>= mac_end
)
15591 dwarf2_macros_too_long_complaint (section
);
15595 /* We don't increment mac_ptr here, so this is just
15597 next_type
= read_1_byte (abfd
, mac_ptr
);
15598 if (next_type
!= 0)
15599 complaint (&symfile_complaints
,
15600 _("no terminating 0-type entry for "
15601 "macros in `.debug_macinfo' section"));
15608 case DW_MACRO_GNU_transparent_include
:
15613 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
15614 mac_ptr
+= offset_size
;
15616 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
15619 /* This has actually happened; see
15620 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
15621 complaint (&symfile_complaints
,
15622 _("recursive DW_MACRO_GNU_transparent_include in "
15623 ".debug_macro section"));
15629 dwarf_decode_macro_bytes (abfd
,
15630 section
->buffer
+ offset
,
15631 mac_end
, current_file
,
15633 section
, section_is_gnu
,
15634 offset_size
, objfile
, include_hash
);
15636 htab_remove_elt (include_hash
, mac_ptr
);
15641 case DW_MACINFO_vendor_ext
:
15642 if (!section_is_gnu
)
15644 unsigned int bytes_read
;
15647 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15648 mac_ptr
+= bytes_read
;
15649 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15650 mac_ptr
+= bytes_read
;
15652 /* We don't recognize any vendor extensions. */
15658 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
15659 mac_ptr
, abfd
, offset_size
,
15661 if (mac_ptr
== NULL
)
15665 } while (macinfo_type
!= 0);
15669 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
15670 char *comp_dir
, bfd
*abfd
,
15671 struct dwarf2_cu
*cu
,
15672 struct dwarf2_section_info
*section
,
15673 int section_is_gnu
)
15675 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15676 gdb_byte
*mac_ptr
, *mac_end
;
15677 struct macro_source_file
*current_file
= 0;
15678 enum dwarf_macro_record_type macinfo_type
;
15679 unsigned int offset_size
= cu
->header
.offset_size
;
15680 gdb_byte
*opcode_definitions
[256];
15681 struct cleanup
*cleanup
;
15682 htab_t include_hash
;
15685 dwarf2_read_section (objfile
, section
);
15686 if (section
->buffer
== NULL
)
15688 complaint (&symfile_complaints
, _("missing %s section"),
15689 section
->asection
->name
);
15693 /* First pass: Find the name of the base filename.
15694 This filename is needed in order to process all macros whose definition
15695 (or undefinition) comes from the command line. These macros are defined
15696 before the first DW_MACINFO_start_file entry, and yet still need to be
15697 associated to the base file.
15699 To determine the base file name, we scan the macro definitions until we
15700 reach the first DW_MACINFO_start_file entry. We then initialize
15701 CURRENT_FILE accordingly so that any macro definition found before the
15702 first DW_MACINFO_start_file can still be associated to the base file. */
15704 mac_ptr
= section
->buffer
+ offset
;
15705 mac_end
= section
->buffer
+ section
->size
;
15707 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
15708 &offset_size
, section_is_gnu
);
15709 if (mac_ptr
== NULL
)
15711 /* We already issued a complaint. */
15717 /* Do we at least have room for a macinfo type byte? */
15718 if (mac_ptr
>= mac_end
)
15720 /* Complaint is printed during the second pass as GDB will probably
15721 stop the first pass earlier upon finding
15722 DW_MACINFO_start_file. */
15726 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
15729 /* Note that we rely on the fact that the corresponding GNU and
15730 DWARF constants are the same. */
15731 switch (macinfo_type
)
15733 /* A zero macinfo type indicates the end of the macro
15738 case DW_MACRO_GNU_define
:
15739 case DW_MACRO_GNU_undef
:
15740 /* Only skip the data by MAC_PTR. */
15742 unsigned int bytes_read
;
15744 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15745 mac_ptr
+= bytes_read
;
15746 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15747 mac_ptr
+= bytes_read
;
15751 case DW_MACRO_GNU_start_file
:
15753 unsigned int bytes_read
;
15756 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15757 mac_ptr
+= bytes_read
;
15758 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15759 mac_ptr
+= bytes_read
;
15761 current_file
= macro_start_file (file
, line
, current_file
,
15762 comp_dir
, lh
, objfile
);
15766 case DW_MACRO_GNU_end_file
:
15767 /* No data to skip by MAC_PTR. */
15770 case DW_MACRO_GNU_define_indirect
:
15771 case DW_MACRO_GNU_undef_indirect
:
15773 unsigned int bytes_read
;
15775 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15776 mac_ptr
+= bytes_read
;
15777 mac_ptr
+= offset_size
;
15781 case DW_MACRO_GNU_transparent_include
:
15782 /* Note that, according to the spec, a transparent include
15783 chain cannot call DW_MACRO_GNU_start_file. So, we can just
15784 skip this opcode. */
15785 mac_ptr
+= offset_size
;
15788 case DW_MACINFO_vendor_ext
:
15789 /* Only skip the data by MAC_PTR. */
15790 if (!section_is_gnu
)
15792 unsigned int bytes_read
;
15794 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15795 mac_ptr
+= bytes_read
;
15796 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15797 mac_ptr
+= bytes_read
;
15802 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
15803 mac_ptr
, abfd
, offset_size
,
15805 if (mac_ptr
== NULL
)
15809 } while (macinfo_type
!= 0 && current_file
== NULL
);
15811 /* Second pass: Process all entries.
15813 Use the AT_COMMAND_LINE flag to determine whether we are still processing
15814 command-line macro definitions/undefinitions. This flag is unset when we
15815 reach the first DW_MACINFO_start_file entry. */
15817 include_hash
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
15818 NULL
, xcalloc
, xfree
);
15819 cleanup
= make_cleanup_htab_delete (include_hash
);
15820 mac_ptr
= section
->buffer
+ offset
;
15821 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
15823 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
15824 current_file
, lh
, comp_dir
, section
, section_is_gnu
,
15825 offset_size
, objfile
, include_hash
);
15826 do_cleanups (cleanup
);
15829 /* Check if the attribute's form is a DW_FORM_block*
15830 if so return true else false. */
15833 attr_form_is_block (struct attribute
*attr
)
15835 return (attr
== NULL
? 0 :
15836 attr
->form
== DW_FORM_block1
15837 || attr
->form
== DW_FORM_block2
15838 || attr
->form
== DW_FORM_block4
15839 || attr
->form
== DW_FORM_block
15840 || attr
->form
== DW_FORM_exprloc
);
15843 /* Return non-zero if ATTR's value is a section offset --- classes
15844 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
15845 You may use DW_UNSND (attr) to retrieve such offsets.
15847 Section 7.5.4, "Attribute Encodings", explains that no attribute
15848 may have a value that belongs to more than one of these classes; it
15849 would be ambiguous if we did, because we use the same forms for all
15853 attr_form_is_section_offset (struct attribute
*attr
)
15855 return (attr
->form
== DW_FORM_data4
15856 || attr
->form
== DW_FORM_data8
15857 || attr
->form
== DW_FORM_sec_offset
);
15861 /* Return non-zero if ATTR's value falls in the 'constant' class, or
15862 zero otherwise. When this function returns true, you can apply
15863 dwarf2_get_attr_constant_value to it.
15865 However, note that for some attributes you must check
15866 attr_form_is_section_offset before using this test. DW_FORM_data4
15867 and DW_FORM_data8 are members of both the constant class, and of
15868 the classes that contain offsets into other debug sections
15869 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
15870 that, if an attribute's can be either a constant or one of the
15871 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
15872 taken as section offsets, not constants. */
15875 attr_form_is_constant (struct attribute
*attr
)
15877 switch (attr
->form
)
15879 case DW_FORM_sdata
:
15880 case DW_FORM_udata
:
15881 case DW_FORM_data1
:
15882 case DW_FORM_data2
:
15883 case DW_FORM_data4
:
15884 case DW_FORM_data8
:
15891 /* A helper function that fills in a dwarf2_loclist_baton. */
15894 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
15895 struct dwarf2_loclist_baton
*baton
,
15896 struct attribute
*attr
)
15898 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
15899 &dwarf2_per_objfile
->loc
);
15901 baton
->per_cu
= cu
->per_cu
;
15902 gdb_assert (baton
->per_cu
);
15903 /* We don't know how long the location list is, but make sure we
15904 don't run off the edge of the section. */
15905 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
15906 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
15907 baton
->base_address
= cu
->base_address
;
15911 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
15912 struct dwarf2_cu
*cu
)
15914 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15916 if (attr_form_is_section_offset (attr
)
15917 /* ".debug_loc" may not exist at all, or the offset may be outside
15918 the section. If so, fall through to the complaint in the
15920 && DW_UNSND (attr
) < dwarf2_section_size (objfile
,
15921 &dwarf2_per_objfile
->loc
))
15923 struct dwarf2_loclist_baton
*baton
;
15925 baton
= obstack_alloc (&objfile
->objfile_obstack
,
15926 sizeof (struct dwarf2_loclist_baton
));
15928 fill_in_loclist_baton (cu
, baton
, attr
);
15930 if (cu
->base_known
== 0)
15931 complaint (&symfile_complaints
,
15932 _("Location list used without "
15933 "specifying the CU base address."));
15935 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
15936 SYMBOL_LOCATION_BATON (sym
) = baton
;
15940 struct dwarf2_locexpr_baton
*baton
;
15942 baton
= obstack_alloc (&objfile
->objfile_obstack
,
15943 sizeof (struct dwarf2_locexpr_baton
));
15944 baton
->per_cu
= cu
->per_cu
;
15945 gdb_assert (baton
->per_cu
);
15947 if (attr_form_is_block (attr
))
15949 /* Note that we're just copying the block's data pointer
15950 here, not the actual data. We're still pointing into the
15951 info_buffer for SYM's objfile; right now we never release
15952 that buffer, but when we do clean up properly this may
15954 baton
->size
= DW_BLOCK (attr
)->size
;
15955 baton
->data
= DW_BLOCK (attr
)->data
;
15959 dwarf2_invalid_attrib_class_complaint ("location description",
15960 SYMBOL_NATURAL_NAME (sym
));
15964 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
15965 SYMBOL_LOCATION_BATON (sym
) = baton
;
15969 /* Return the OBJFILE associated with the compilation unit CU. If CU
15970 came from a separate debuginfo file, then the master objfile is
15974 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
15976 struct objfile
*objfile
= per_cu
->objfile
;
15978 /* Return the master objfile, so that we can report and look up the
15979 correct file containing this variable. */
15980 if (objfile
->separate_debug_objfile_backlink
)
15981 objfile
= objfile
->separate_debug_objfile_backlink
;
15986 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
15987 (CU_HEADERP is unused in such case) or prepare a temporary copy at
15988 CU_HEADERP first. */
15990 static const struct comp_unit_head
*
15991 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
15992 struct dwarf2_per_cu_data
*per_cu
)
15994 struct objfile
*objfile
;
15995 struct dwarf2_per_objfile
*per_objfile
;
15996 gdb_byte
*info_ptr
;
15999 return &per_cu
->cu
->header
;
16001 objfile
= per_cu
->objfile
;
16002 per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
16003 info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
.sect_off
;
16005 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
16006 read_comp_unit_head (cu_headerp
, info_ptr
, objfile
->obfd
);
16011 /* Return the address size given in the compilation unit header for CU. */
16014 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
16016 struct comp_unit_head cu_header_local
;
16017 const struct comp_unit_head
*cu_headerp
;
16019 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
16021 return cu_headerp
->addr_size
;
16024 /* Return the offset size given in the compilation unit header for CU. */
16027 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
16029 struct comp_unit_head cu_header_local
;
16030 const struct comp_unit_head
*cu_headerp
;
16032 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
16034 return cu_headerp
->offset_size
;
16037 /* See its dwarf2loc.h declaration. */
16040 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
16042 struct comp_unit_head cu_header_local
;
16043 const struct comp_unit_head
*cu_headerp
;
16045 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
16047 if (cu_headerp
->version
== 2)
16048 return cu_headerp
->addr_size
;
16050 return cu_headerp
->offset_size
;
16053 /* Return the text offset of the CU. The returned offset comes from
16054 this CU's objfile. If this objfile came from a separate debuginfo
16055 file, then the offset may be different from the corresponding
16056 offset in the parent objfile. */
16059 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
16061 struct objfile
*objfile
= per_cu
->objfile
;
16063 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
16066 /* Locate the .debug_info compilation unit from CU's objfile which contains
16067 the DIE at OFFSET. Raises an error on failure. */
16069 static struct dwarf2_per_cu_data
*
16070 dwarf2_find_containing_comp_unit (sect_offset offset
,
16071 struct objfile
*objfile
)
16073 struct dwarf2_per_cu_data
*this_cu
;
16077 high
= dwarf2_per_objfile
->n_comp_units
- 1;
16080 int mid
= low
+ (high
- low
) / 2;
16082 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
.sect_off
16083 >= offset
.sect_off
)
16088 gdb_assert (low
== high
);
16089 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
.sect_off
16093 error (_("Dwarf Error: could not find partial DIE containing "
16094 "offset 0x%lx [in module %s]"),
16095 (long) offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
16097 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
.sect_off
16098 <= offset
.sect_off
);
16099 return dwarf2_per_objfile
->all_comp_units
[low
-1];
16103 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
16104 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
16105 && offset
.sect_off
>= this_cu
->offset
.sect_off
+ this_cu
->length
)
16106 error (_("invalid dwarf2 offset %u"), offset
.sect_off
);
16107 gdb_assert (offset
.sect_off
< this_cu
->offset
.sect_off
+ this_cu
->length
);
16112 /* Initialize dwarf2_cu CU, owned by PER_CU. */
16115 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
16117 memset (cu
, 0, sizeof (*cu
));
16119 cu
->per_cu
= per_cu
;
16120 cu
->objfile
= per_cu
->objfile
;
16121 obstack_init (&cu
->comp_unit_obstack
);
16124 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
16127 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
)
16129 struct attribute
*attr
;
16131 /* Set the language we're debugging. */
16132 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
16134 set_cu_language (DW_UNSND (attr
), cu
);
16137 cu
->language
= language_minimal
;
16138 cu
->language_defn
= language_def (cu
->language
);
16142 /* Release one cached compilation unit, CU. We unlink it from the tree
16143 of compilation units, but we don't remove it from the read_in_chain;
16144 the caller is responsible for that.
16145 NOTE: DATA is a void * because this function is also used as a
16146 cleanup routine. */
16149 free_heap_comp_unit (void *data
)
16151 struct dwarf2_cu
*cu
= data
;
16153 gdb_assert (cu
->per_cu
!= NULL
);
16154 cu
->per_cu
->cu
= NULL
;
16157 obstack_free (&cu
->comp_unit_obstack
, NULL
);
16162 /* This cleanup function is passed the address of a dwarf2_cu on the stack
16163 when we're finished with it. We can't free the pointer itself, but be
16164 sure to unlink it from the cache. Also release any associated storage
16165 and perform cache maintenance.
16167 Only used during partial symbol parsing. */
16170 free_stack_comp_unit (void *data
)
16172 struct dwarf2_cu
*cu
= data
;
16174 gdb_assert (cu
->per_cu
!= NULL
);
16175 cu
->per_cu
->cu
= NULL
;
16178 obstack_free (&cu
->comp_unit_obstack
, NULL
);
16179 cu
->partial_dies
= NULL
;
16181 /* The previous code only did this if per_cu != NULL.
16182 But that would always succeed, so now we just unconditionally do
16183 the aging. This seems like the wrong place to do such aging,
16184 but cleaning that up is left for later. */
16185 age_cached_comp_units ();
16188 /* Free all cached compilation units. */
16191 free_cached_comp_units (void *data
)
16193 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
16195 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16196 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
16197 while (per_cu
!= NULL
)
16199 struct dwarf2_per_cu_data
*next_cu
;
16201 next_cu
= per_cu
->cu
->read_in_chain
;
16203 free_heap_comp_unit (per_cu
->cu
);
16204 *last_chain
= next_cu
;
16210 /* Increase the age counter on each cached compilation unit, and free
16211 any that are too old. */
16214 age_cached_comp_units (void)
16216 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
16218 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
16219 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16220 while (per_cu
!= NULL
)
16222 per_cu
->cu
->last_used
++;
16223 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
16224 dwarf2_mark (per_cu
->cu
);
16225 per_cu
= per_cu
->cu
->read_in_chain
;
16228 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16229 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
16230 while (per_cu
!= NULL
)
16232 struct dwarf2_per_cu_data
*next_cu
;
16234 next_cu
= per_cu
->cu
->read_in_chain
;
16236 if (!per_cu
->cu
->mark
)
16238 free_heap_comp_unit (per_cu
->cu
);
16239 *last_chain
= next_cu
;
16242 last_chain
= &per_cu
->cu
->read_in_chain
;
16248 /* Remove a single compilation unit from the cache. */
16251 free_one_cached_comp_unit (void *target_cu
)
16253 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
16255 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16256 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
16257 while (per_cu
!= NULL
)
16259 struct dwarf2_per_cu_data
*next_cu
;
16261 next_cu
= per_cu
->cu
->read_in_chain
;
16263 if (per_cu
->cu
== target_cu
)
16265 free_heap_comp_unit (per_cu
->cu
);
16266 *last_chain
= next_cu
;
16270 last_chain
= &per_cu
->cu
->read_in_chain
;
16276 /* Release all extra memory associated with OBJFILE. */
16279 dwarf2_free_objfile (struct objfile
*objfile
)
16281 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
16283 if (dwarf2_per_objfile
== NULL
)
16286 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
16287 free_cached_comp_units (NULL
);
16289 if (dwarf2_per_objfile
->quick_file_names_table
)
16290 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
16292 /* Everything else should be on the objfile obstack. */
16295 /* A pair of DIE offset and GDB type pointer. We store these
16296 in a hash table separate from the DIEs, and preserve them
16297 when the DIEs are flushed out of cache. */
16299 struct dwarf2_offset_and_type
16301 sect_offset offset
;
16305 /* Hash function for a dwarf2_offset_and_type. */
16308 offset_and_type_hash (const void *item
)
16310 const struct dwarf2_offset_and_type
*ofs
= item
;
16312 return ofs
->offset
.sect_off
;
16315 /* Equality function for a dwarf2_offset_and_type. */
16318 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
16320 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
16321 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
16323 return ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
;
16326 /* Set the type associated with DIE to TYPE. Save it in CU's hash
16327 table if necessary. For convenience, return TYPE.
16329 The DIEs reading must have careful ordering to:
16330 * Not cause infite loops trying to read in DIEs as a prerequisite for
16331 reading current DIE.
16332 * Not trying to dereference contents of still incompletely read in types
16333 while reading in other DIEs.
16334 * Enable referencing still incompletely read in types just by a pointer to
16335 the type without accessing its fields.
16337 Therefore caller should follow these rules:
16338 * Try to fetch any prerequisite types we may need to build this DIE type
16339 before building the type and calling set_die_type.
16340 * After building type call set_die_type for current DIE as soon as
16341 possible before fetching more types to complete the current type.
16342 * Make the type as complete as possible before fetching more types. */
16344 static struct type
*
16345 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
16347 struct dwarf2_offset_and_type
**slot
, ofs
;
16348 struct objfile
*objfile
= cu
->objfile
;
16349 htab_t
*type_hash_ptr
;
16351 /* For Ada types, make sure that the gnat-specific data is always
16352 initialized (if not already set). There are a few types where
16353 we should not be doing so, because the type-specific area is
16354 already used to hold some other piece of info (eg: TYPE_CODE_FLT
16355 where the type-specific area is used to store the floatformat).
16356 But this is not a problem, because the gnat-specific information
16357 is actually not needed for these types. */
16358 if (need_gnat_info (cu
)
16359 && TYPE_CODE (type
) != TYPE_CODE_FUNC
16360 && TYPE_CODE (type
) != TYPE_CODE_FLT
16361 && !HAVE_GNAT_AUX_INFO (type
))
16362 INIT_GNAT_SPECIFIC (type
);
16364 if (cu
->per_cu
->debug_types_section
)
16365 type_hash_ptr
= &dwarf2_per_objfile
->debug_types_type_hash
;
16367 type_hash_ptr
= &dwarf2_per_objfile
->debug_info_type_hash
;
16369 if (*type_hash_ptr
== NULL
)
16372 = htab_create_alloc_ex (127,
16373 offset_and_type_hash
,
16374 offset_and_type_eq
,
16376 &objfile
->objfile_obstack
,
16377 hashtab_obstack_allocate
,
16378 dummy_obstack_deallocate
);
16381 ofs
.offset
= die
->offset
;
16383 slot
= (struct dwarf2_offset_and_type
**)
16384 htab_find_slot_with_hash (*type_hash_ptr
, &ofs
, ofs
.offset
.sect_off
,
16387 complaint (&symfile_complaints
,
16388 _("A problem internal to GDB: DIE 0x%x has type already set"),
16389 die
->offset
.sect_off
);
16390 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
16395 /* Look up the type for the die at OFFSET in the appropriate type_hash
16396 table, or return NULL if the die does not have a saved type. */
16398 static struct type
*
16399 get_die_type_at_offset (sect_offset offset
,
16400 struct dwarf2_per_cu_data
*per_cu
)
16402 struct dwarf2_offset_and_type
*slot
, ofs
;
16405 if (per_cu
->debug_types_section
)
16406 type_hash
= dwarf2_per_objfile
->debug_types_type_hash
;
16408 type_hash
= dwarf2_per_objfile
->debug_info_type_hash
;
16409 if (type_hash
== NULL
)
16412 ofs
.offset
= offset
;
16413 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
.sect_off
);
16420 /* Look up the type for DIE in the appropriate type_hash table,
16421 or return NULL if DIE does not have a saved type. */
16423 static struct type
*
16424 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16426 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
16429 /* Add a dependence relationship from CU to REF_PER_CU. */
16432 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
16433 struct dwarf2_per_cu_data
*ref_per_cu
)
16437 if (cu
->dependencies
== NULL
)
16439 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
16440 NULL
, &cu
->comp_unit_obstack
,
16441 hashtab_obstack_allocate
,
16442 dummy_obstack_deallocate
);
16444 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
16446 *slot
= ref_per_cu
;
16449 /* Subroutine of dwarf2_mark to pass to htab_traverse.
16450 Set the mark field in every compilation unit in the
16451 cache that we must keep because we are keeping CU. */
16454 dwarf2_mark_helper (void **slot
, void *data
)
16456 struct dwarf2_per_cu_data
*per_cu
;
16458 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
16460 /* cu->dependencies references may not yet have been ever read if QUIT aborts
16461 reading of the chain. As such dependencies remain valid it is not much
16462 useful to track and undo them during QUIT cleanups. */
16463 if (per_cu
->cu
== NULL
)
16466 if (per_cu
->cu
->mark
)
16468 per_cu
->cu
->mark
= 1;
16470 if (per_cu
->cu
->dependencies
!= NULL
)
16471 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
16476 /* Set the mark field in CU and in every other compilation unit in the
16477 cache that we must keep because we are keeping CU. */
16480 dwarf2_mark (struct dwarf2_cu
*cu
)
16485 if (cu
->dependencies
!= NULL
)
16486 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
16490 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
16494 per_cu
->cu
->mark
= 0;
16495 per_cu
= per_cu
->cu
->read_in_chain
;
16499 /* Trivial hash function for partial_die_info: the hash value of a DIE
16500 is its offset in .debug_info for this objfile. */
16503 partial_die_hash (const void *item
)
16505 const struct partial_die_info
*part_die
= item
;
16507 return part_die
->offset
.sect_off
;
16510 /* Trivial comparison function for partial_die_info structures: two DIEs
16511 are equal if they have the same offset. */
16514 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
16516 const struct partial_die_info
*part_die_lhs
= item_lhs
;
16517 const struct partial_die_info
*part_die_rhs
= item_rhs
;
16519 return part_die_lhs
->offset
.sect_off
== part_die_rhs
->offset
.sect_off
;
16522 static struct cmd_list_element
*set_dwarf2_cmdlist
;
16523 static struct cmd_list_element
*show_dwarf2_cmdlist
;
16526 set_dwarf2_cmd (char *args
, int from_tty
)
16528 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
16532 show_dwarf2_cmd (char *args
, int from_tty
)
16534 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
16537 /* If section described by INFO was mmapped, munmap it now. */
16540 munmap_section_buffer (struct dwarf2_section_info
*info
)
16542 if (info
->map_addr
!= NULL
)
16547 res
= munmap (info
->map_addr
, info
->map_len
);
16548 gdb_assert (res
== 0);
16550 /* Without HAVE_MMAP, we should never be here to begin with. */
16551 gdb_assert_not_reached ("no mmap support");
16556 /* munmap debug sections for OBJFILE, if necessary. */
16559 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
16561 struct dwarf2_per_objfile
*data
= d
;
16563 struct dwarf2_section_info
*section
;
16565 /* This is sorted according to the order they're defined in to make it easier
16566 to keep in sync. */
16567 munmap_section_buffer (&data
->info
);
16568 munmap_section_buffer (&data
->abbrev
);
16569 munmap_section_buffer (&data
->line
);
16570 munmap_section_buffer (&data
->loc
);
16571 munmap_section_buffer (&data
->macinfo
);
16572 munmap_section_buffer (&data
->macro
);
16573 munmap_section_buffer (&data
->str
);
16574 munmap_section_buffer (&data
->ranges
);
16575 munmap_section_buffer (&data
->frame
);
16576 munmap_section_buffer (&data
->eh_frame
);
16577 munmap_section_buffer (&data
->gdb_index
);
16580 VEC_iterate (dwarf2_section_info_def
, data
->types
, ix
, section
);
16582 munmap_section_buffer (section
);
16584 VEC_free (dwarf2_section_info_def
, data
->types
);
16588 /* The "save gdb-index" command. */
16590 /* The contents of the hash table we create when building the string
16592 struct strtab_entry
16594 offset_type offset
;
16598 /* Hash function for a strtab_entry.
16600 Function is used only during write_hash_table so no index format backward
16601 compatibility is needed. */
16604 hash_strtab_entry (const void *e
)
16606 const struct strtab_entry
*entry
= e
;
16607 return mapped_index_string_hash (INT_MAX
, entry
->str
);
16610 /* Equality function for a strtab_entry. */
16613 eq_strtab_entry (const void *a
, const void *b
)
16615 const struct strtab_entry
*ea
= a
;
16616 const struct strtab_entry
*eb
= b
;
16617 return !strcmp (ea
->str
, eb
->str
);
16620 /* Create a strtab_entry hash table. */
16623 create_strtab (void)
16625 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
16626 xfree
, xcalloc
, xfree
);
16629 /* Add a string to the constant pool. Return the string's offset in
16633 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
16636 struct strtab_entry entry
;
16637 struct strtab_entry
*result
;
16640 slot
= htab_find_slot (table
, &entry
, INSERT
);
16645 result
= XNEW (struct strtab_entry
);
16646 result
->offset
= obstack_object_size (cpool
);
16648 obstack_grow_str0 (cpool
, str
);
16651 return result
->offset
;
16654 /* An entry in the symbol table. */
16655 struct symtab_index_entry
16657 /* The name of the symbol. */
16659 /* The offset of the name in the constant pool. */
16660 offset_type index_offset
;
16661 /* A sorted vector of the indices of all the CUs that hold an object
16663 VEC (offset_type
) *cu_indices
;
16666 /* The symbol table. This is a power-of-2-sized hash table. */
16667 struct mapped_symtab
16669 offset_type n_elements
;
16671 struct symtab_index_entry
**data
;
16674 /* Hash function for a symtab_index_entry. */
16677 hash_symtab_entry (const void *e
)
16679 const struct symtab_index_entry
*entry
= e
;
16680 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
16681 sizeof (offset_type
) * VEC_length (offset_type
,
16682 entry
->cu_indices
),
16686 /* Equality function for a symtab_index_entry. */
16689 eq_symtab_entry (const void *a
, const void *b
)
16691 const struct symtab_index_entry
*ea
= a
;
16692 const struct symtab_index_entry
*eb
= b
;
16693 int len
= VEC_length (offset_type
, ea
->cu_indices
);
16694 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
16696 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
16697 VEC_address (offset_type
, eb
->cu_indices
),
16698 sizeof (offset_type
) * len
);
16701 /* Destroy a symtab_index_entry. */
16704 delete_symtab_entry (void *p
)
16706 struct symtab_index_entry
*entry
= p
;
16707 VEC_free (offset_type
, entry
->cu_indices
);
16711 /* Create a hash table holding symtab_index_entry objects. */
16714 create_symbol_hash_table (void)
16716 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
16717 delete_symtab_entry
, xcalloc
, xfree
);
16720 /* Create a new mapped symtab object. */
16722 static struct mapped_symtab
*
16723 create_mapped_symtab (void)
16725 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
16726 symtab
->n_elements
= 0;
16727 symtab
->size
= 1024;
16728 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
16732 /* Destroy a mapped_symtab. */
16735 cleanup_mapped_symtab (void *p
)
16737 struct mapped_symtab
*symtab
= p
;
16738 /* The contents of the array are freed when the other hash table is
16740 xfree (symtab
->data
);
16744 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
16747 Function is used only during write_hash_table so no index format backward
16748 compatibility is needed. */
16750 static struct symtab_index_entry
**
16751 find_slot (struct mapped_symtab
*symtab
, const char *name
)
16753 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
16755 index
= hash
& (symtab
->size
- 1);
16756 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
16760 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
16761 return &symtab
->data
[index
];
16762 index
= (index
+ step
) & (symtab
->size
- 1);
16766 /* Expand SYMTAB's hash table. */
16769 hash_expand (struct mapped_symtab
*symtab
)
16771 offset_type old_size
= symtab
->size
;
16773 struct symtab_index_entry
**old_entries
= symtab
->data
;
16776 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
16778 for (i
= 0; i
< old_size
; ++i
)
16780 if (old_entries
[i
])
16782 struct symtab_index_entry
**slot
= find_slot (symtab
,
16783 old_entries
[i
]->name
);
16784 *slot
= old_entries
[i
];
16788 xfree (old_entries
);
16791 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
16792 is the index of the CU in which the symbol appears. */
16795 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
16796 offset_type cu_index
)
16798 struct symtab_index_entry
**slot
;
16800 ++symtab
->n_elements
;
16801 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
16802 hash_expand (symtab
);
16804 slot
= find_slot (symtab
, name
);
16807 *slot
= XNEW (struct symtab_index_entry
);
16808 (*slot
)->name
= name
;
16809 (*slot
)->cu_indices
= NULL
;
16811 /* Don't push an index twice. Due to how we add entries we only
16812 have to check the last one. */
16813 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
16814 || VEC_last (offset_type
, (*slot
)->cu_indices
) != cu_index
)
16815 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
16818 /* Add a vector of indices to the constant pool. */
16821 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
16822 struct symtab_index_entry
*entry
)
16826 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
16829 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
16830 offset_type val
= MAYBE_SWAP (len
);
16835 entry
->index_offset
= obstack_object_size (cpool
);
16837 obstack_grow (cpool
, &val
, sizeof (val
));
16839 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
16842 val
= MAYBE_SWAP (iter
);
16843 obstack_grow (cpool
, &val
, sizeof (val
));
16848 struct symtab_index_entry
*old_entry
= *slot
;
16849 entry
->index_offset
= old_entry
->index_offset
;
16852 return entry
->index_offset
;
16855 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
16856 constant pool entries going into the obstack CPOOL. */
16859 write_hash_table (struct mapped_symtab
*symtab
,
16860 struct obstack
*output
, struct obstack
*cpool
)
16863 htab_t symbol_hash_table
;
16866 symbol_hash_table
= create_symbol_hash_table ();
16867 str_table
= create_strtab ();
16869 /* We add all the index vectors to the constant pool first, to
16870 ensure alignment is ok. */
16871 for (i
= 0; i
< symtab
->size
; ++i
)
16873 if (symtab
->data
[i
])
16874 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
16877 /* Now write out the hash table. */
16878 for (i
= 0; i
< symtab
->size
; ++i
)
16880 offset_type str_off
, vec_off
;
16882 if (symtab
->data
[i
])
16884 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
16885 vec_off
= symtab
->data
[i
]->index_offset
;
16889 /* While 0 is a valid constant pool index, it is not valid
16890 to have 0 for both offsets. */
16895 str_off
= MAYBE_SWAP (str_off
);
16896 vec_off
= MAYBE_SWAP (vec_off
);
16898 obstack_grow (output
, &str_off
, sizeof (str_off
));
16899 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
16902 htab_delete (str_table
);
16903 htab_delete (symbol_hash_table
);
16906 /* Struct to map psymtab to CU index in the index file. */
16907 struct psymtab_cu_index_map
16909 struct partial_symtab
*psymtab
;
16910 unsigned int cu_index
;
16914 hash_psymtab_cu_index (const void *item
)
16916 const struct psymtab_cu_index_map
*map
= item
;
16918 return htab_hash_pointer (map
->psymtab
);
16922 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
16924 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
16925 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
16927 return lhs
->psymtab
== rhs
->psymtab
;
16930 /* Helper struct for building the address table. */
16931 struct addrmap_index_data
16933 struct objfile
*objfile
;
16934 struct obstack
*addr_obstack
;
16935 htab_t cu_index_htab
;
16937 /* Non-zero if the previous_* fields are valid.
16938 We can't write an entry until we see the next entry (since it is only then
16939 that we know the end of the entry). */
16940 int previous_valid
;
16941 /* Index of the CU in the table of all CUs in the index file. */
16942 unsigned int previous_cu_index
;
16943 /* Start address of the CU. */
16944 CORE_ADDR previous_cu_start
;
16947 /* Write an address entry to OBSTACK. */
16950 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
16951 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
16953 offset_type cu_index_to_write
;
16955 CORE_ADDR baseaddr
;
16957 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
16959 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
16960 obstack_grow (obstack
, addr
, 8);
16961 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
16962 obstack_grow (obstack
, addr
, 8);
16963 cu_index_to_write
= MAYBE_SWAP (cu_index
);
16964 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
16967 /* Worker function for traversing an addrmap to build the address table. */
16970 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
16972 struct addrmap_index_data
*data
= datap
;
16973 struct partial_symtab
*pst
= obj
;
16974 offset_type cu_index
;
16977 if (data
->previous_valid
)
16978 add_address_entry (data
->objfile
, data
->addr_obstack
,
16979 data
->previous_cu_start
, start_addr
,
16980 data
->previous_cu_index
);
16982 data
->previous_cu_start
= start_addr
;
16985 struct psymtab_cu_index_map find_map
, *map
;
16986 find_map
.psymtab
= pst
;
16987 map
= htab_find (data
->cu_index_htab
, &find_map
);
16988 gdb_assert (map
!= NULL
);
16989 data
->previous_cu_index
= map
->cu_index
;
16990 data
->previous_valid
= 1;
16993 data
->previous_valid
= 0;
16998 /* Write OBJFILE's address map to OBSTACK.
16999 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
17000 in the index file. */
17003 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
17004 htab_t cu_index_htab
)
17006 struct addrmap_index_data addrmap_index_data
;
17008 /* When writing the address table, we have to cope with the fact that
17009 the addrmap iterator only provides the start of a region; we have to
17010 wait until the next invocation to get the start of the next region. */
17012 addrmap_index_data
.objfile
= objfile
;
17013 addrmap_index_data
.addr_obstack
= obstack
;
17014 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
17015 addrmap_index_data
.previous_valid
= 0;
17017 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
17018 &addrmap_index_data
);
17020 /* It's highly unlikely the last entry (end address = 0xff...ff)
17021 is valid, but we should still handle it.
17022 The end address is recorded as the start of the next region, but that
17023 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
17025 if (addrmap_index_data
.previous_valid
)
17026 add_address_entry (objfile
, obstack
,
17027 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
17028 addrmap_index_data
.previous_cu_index
);
17031 /* Add a list of partial symbols to SYMTAB. */
17034 write_psymbols (struct mapped_symtab
*symtab
,
17036 struct partial_symbol
**psymp
,
17038 offset_type cu_index
,
17041 for (; count
-- > 0; ++psymp
)
17043 void **slot
, *lookup
;
17045 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
17046 error (_("Ada is not currently supported by the index"));
17048 /* We only want to add a given psymbol once. However, we also
17049 want to account for whether it is global or static. So, we
17050 may add it twice, using slightly different values. */
17053 uintptr_t val
= 1 | (uintptr_t) *psymp
;
17055 lookup
= (void *) val
;
17060 /* Only add a given psymbol once. */
17061 slot
= htab_find_slot (psyms_seen
, lookup
, INSERT
);
17065 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (*psymp
), cu_index
);
17070 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
17071 exception if there is an error. */
17074 write_obstack (FILE *file
, struct obstack
*obstack
)
17076 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
17078 != obstack_object_size (obstack
))
17079 error (_("couldn't data write to file"));
17082 /* Unlink a file if the argument is not NULL. */
17085 unlink_if_set (void *p
)
17087 char **filename
= p
;
17089 unlink (*filename
);
17092 /* A helper struct used when iterating over debug_types. */
17093 struct signatured_type_index_data
17095 struct objfile
*objfile
;
17096 struct mapped_symtab
*symtab
;
17097 struct obstack
*types_list
;
17102 /* A helper function that writes a single signatured_type to an
17106 write_one_signatured_type (void **slot
, void *d
)
17108 struct signatured_type_index_data
*info
= d
;
17109 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
17110 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
17111 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
17114 write_psymbols (info
->symtab
,
17116 info
->objfile
->global_psymbols
.list
17117 + psymtab
->globals_offset
,
17118 psymtab
->n_global_syms
, info
->cu_index
,
17120 write_psymbols (info
->symtab
,
17122 info
->objfile
->static_psymbols
.list
17123 + psymtab
->statics_offset
,
17124 psymtab
->n_static_syms
, info
->cu_index
,
17127 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
17128 entry
->per_cu
.offset
.sect_off
);
17129 obstack_grow (info
->types_list
, val
, 8);
17130 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->type_offset
.cu_off
);
17131 obstack_grow (info
->types_list
, val
, 8);
17132 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
17133 obstack_grow (info
->types_list
, val
, 8);
17140 /* Create an index file for OBJFILE in the directory DIR. */
17143 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
17145 struct cleanup
*cleanup
;
17146 char *filename
, *cleanup_filename
;
17147 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
17148 struct obstack cu_list
, types_cu_list
;
17151 struct mapped_symtab
*symtab
;
17152 offset_type val
, size_of_contents
, total_len
;
17156 htab_t cu_index_htab
;
17157 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
17159 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
17162 if (dwarf2_per_objfile
->using_index
)
17163 error (_("Cannot use an index to create the index"));
17165 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
17166 error (_("Cannot make an index when the file has multiple .debug_types sections"));
17168 if (stat (objfile
->name
, &st
) < 0)
17169 perror_with_name (objfile
->name
);
17171 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
17172 INDEX_SUFFIX
, (char *) NULL
);
17173 cleanup
= make_cleanup (xfree
, filename
);
17175 out_file
= fopen (filename
, "wb");
17177 error (_("Can't open `%s' for writing"), filename
);
17179 cleanup_filename
= filename
;
17180 make_cleanup (unlink_if_set
, &cleanup_filename
);
17182 symtab
= create_mapped_symtab ();
17183 make_cleanup (cleanup_mapped_symtab
, symtab
);
17185 obstack_init (&addr_obstack
);
17186 make_cleanup_obstack_free (&addr_obstack
);
17188 obstack_init (&cu_list
);
17189 make_cleanup_obstack_free (&cu_list
);
17191 obstack_init (&types_cu_list
);
17192 make_cleanup_obstack_free (&types_cu_list
);
17194 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
17195 NULL
, xcalloc
, xfree
);
17196 make_cleanup_htab_delete (psyms_seen
);
17198 /* While we're scanning CU's create a table that maps a psymtab pointer
17199 (which is what addrmap records) to its index (which is what is recorded
17200 in the index file). This will later be needed to write the address
17202 cu_index_htab
= htab_create_alloc (100,
17203 hash_psymtab_cu_index
,
17204 eq_psymtab_cu_index
,
17205 NULL
, xcalloc
, xfree
);
17206 make_cleanup_htab_delete (cu_index_htab
);
17207 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
17208 xmalloc (sizeof (struct psymtab_cu_index_map
)
17209 * dwarf2_per_objfile
->n_comp_units
);
17210 make_cleanup (xfree
, psymtab_cu_index_map
);
17212 /* The CU list is already sorted, so we don't need to do additional
17213 work here. Also, the debug_types entries do not appear in
17214 all_comp_units, but only in their own hash table. */
17215 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
17217 struct dwarf2_per_cu_data
*per_cu
17218 = dwarf2_per_objfile
->all_comp_units
[i
];
17219 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
17221 struct psymtab_cu_index_map
*map
;
17224 write_psymbols (symtab
,
17226 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
17227 psymtab
->n_global_syms
, i
,
17229 write_psymbols (symtab
,
17231 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
17232 psymtab
->n_static_syms
, i
,
17235 map
= &psymtab_cu_index_map
[i
];
17236 map
->psymtab
= psymtab
;
17238 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
17239 gdb_assert (slot
!= NULL
);
17240 gdb_assert (*slot
== NULL
);
17243 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
17244 per_cu
->offset
.sect_off
);
17245 obstack_grow (&cu_list
, val
, 8);
17246 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
17247 obstack_grow (&cu_list
, val
, 8);
17250 /* Dump the address map. */
17251 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
17253 /* Write out the .debug_type entries, if any. */
17254 if (dwarf2_per_objfile
->signatured_types
)
17256 struct signatured_type_index_data sig_data
;
17258 sig_data
.objfile
= objfile
;
17259 sig_data
.symtab
= symtab
;
17260 sig_data
.types_list
= &types_cu_list
;
17261 sig_data
.psyms_seen
= psyms_seen
;
17262 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
17263 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
17264 write_one_signatured_type
, &sig_data
);
17267 obstack_init (&constant_pool
);
17268 make_cleanup_obstack_free (&constant_pool
);
17269 obstack_init (&symtab_obstack
);
17270 make_cleanup_obstack_free (&symtab_obstack
);
17271 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
17273 obstack_init (&contents
);
17274 make_cleanup_obstack_free (&contents
);
17275 size_of_contents
= 6 * sizeof (offset_type
);
17276 total_len
= size_of_contents
;
17278 /* The version number. */
17279 val
= MAYBE_SWAP (6);
17280 obstack_grow (&contents
, &val
, sizeof (val
));
17282 /* The offset of the CU list from the start of the file. */
17283 val
= MAYBE_SWAP (total_len
);
17284 obstack_grow (&contents
, &val
, sizeof (val
));
17285 total_len
+= obstack_object_size (&cu_list
);
17287 /* The offset of the types CU list from the start of the file. */
17288 val
= MAYBE_SWAP (total_len
);
17289 obstack_grow (&contents
, &val
, sizeof (val
));
17290 total_len
+= obstack_object_size (&types_cu_list
);
17292 /* The offset of the address table from the start of the file. */
17293 val
= MAYBE_SWAP (total_len
);
17294 obstack_grow (&contents
, &val
, sizeof (val
));
17295 total_len
+= obstack_object_size (&addr_obstack
);
17297 /* The offset of the symbol table from the start of the file. */
17298 val
= MAYBE_SWAP (total_len
);
17299 obstack_grow (&contents
, &val
, sizeof (val
));
17300 total_len
+= obstack_object_size (&symtab_obstack
);
17302 /* The offset of the constant pool from the start of the file. */
17303 val
= MAYBE_SWAP (total_len
);
17304 obstack_grow (&contents
, &val
, sizeof (val
));
17305 total_len
+= obstack_object_size (&constant_pool
);
17307 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
17309 write_obstack (out_file
, &contents
);
17310 write_obstack (out_file
, &cu_list
);
17311 write_obstack (out_file
, &types_cu_list
);
17312 write_obstack (out_file
, &addr_obstack
);
17313 write_obstack (out_file
, &symtab_obstack
);
17314 write_obstack (out_file
, &constant_pool
);
17318 /* We want to keep the file, so we set cleanup_filename to NULL
17319 here. See unlink_if_set. */
17320 cleanup_filename
= NULL
;
17322 do_cleanups (cleanup
);
17325 /* Implementation of the `save gdb-index' command.
17327 Note that the file format used by this command is documented in the
17328 GDB manual. Any changes here must be documented there. */
17331 save_gdb_index_command (char *arg
, int from_tty
)
17333 struct objfile
*objfile
;
17336 error (_("usage: save gdb-index DIRECTORY"));
17338 ALL_OBJFILES (objfile
)
17342 /* If the objfile does not correspond to an actual file, skip it. */
17343 if (stat (objfile
->name
, &st
) < 0)
17346 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
17347 if (dwarf2_per_objfile
)
17349 volatile struct gdb_exception except
;
17351 TRY_CATCH (except
, RETURN_MASK_ERROR
)
17353 write_psymtabs_to_index (objfile
, arg
);
17355 if (except
.reason
< 0)
17356 exception_fprintf (gdb_stderr
, except
,
17357 _("Error while writing index for `%s': "),
17365 int dwarf2_always_disassemble
;
17368 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
17369 struct cmd_list_element
*c
, const char *value
)
17371 fprintf_filtered (file
,
17372 _("Whether to always disassemble "
17373 "DWARF expressions is %s.\n"),
17378 show_check_physname (struct ui_file
*file
, int from_tty
,
17379 struct cmd_list_element
*c
, const char *value
)
17381 fprintf_filtered (file
,
17382 _("Whether to check \"physname\" is %s.\n"),
17386 void _initialize_dwarf2_read (void);
17389 _initialize_dwarf2_read (void)
17391 struct cmd_list_element
*c
;
17393 dwarf2_objfile_data_key
17394 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
17396 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
17397 Set DWARF 2 specific variables.\n\
17398 Configure DWARF 2 variables such as the cache size"),
17399 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
17400 0/*allow-unknown*/, &maintenance_set_cmdlist
);
17402 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
17403 Show DWARF 2 specific variables\n\
17404 Show DWARF 2 variables such as the cache size"),
17405 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
17406 0/*allow-unknown*/, &maintenance_show_cmdlist
);
17408 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
17409 &dwarf2_max_cache_age
, _("\
17410 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
17411 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
17412 A higher limit means that cached compilation units will be stored\n\
17413 in memory longer, and more total memory will be used. Zero disables\n\
17414 caching, which can slow down startup."),
17416 show_dwarf2_max_cache_age
,
17417 &set_dwarf2_cmdlist
,
17418 &show_dwarf2_cmdlist
);
17420 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
17421 &dwarf2_always_disassemble
, _("\
17422 Set whether `info address' always disassembles DWARF expressions."), _("\
17423 Show whether `info address' always disassembles DWARF expressions."), _("\
17424 When enabled, DWARF expressions are always printed in an assembly-like\n\
17425 syntax. When disabled, expressions will be printed in a more\n\
17426 conversational style, when possible."),
17428 show_dwarf2_always_disassemble
,
17429 &set_dwarf2_cmdlist
,
17430 &show_dwarf2_cmdlist
);
17432 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
17433 Set debugging of the dwarf2 DIE reader."), _("\
17434 Show debugging of the dwarf2 DIE reader."), _("\
17435 When enabled (non-zero), DIEs are dumped after they are read in.\n\
17436 The value is the maximum depth to print."),
17439 &setdebuglist
, &showdebuglist
);
17441 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
17442 Set cross-checking of \"physname\" code against demangler."), _("\
17443 Show cross-checking of \"physname\" code against demangler."), _("\
17444 When enabled, GDB's internal \"physname\" code is checked against\n\
17446 NULL
, show_check_physname
,
17447 &setdebuglist
, &showdebuglist
);
17449 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
17451 Save a gdb-index file.\n\
17452 Usage: save gdb-index DIRECTORY"),
17454 set_cmd_completer (c
, filename_completer
);