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
;
6713 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6716 high
= DW_ADDR (attr
);
6717 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6719 low
= DW_ADDR (attr
);
6721 /* Found high w/o low attribute. */
6724 /* Found consecutive range of addresses. */
6729 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6732 /* Value of the DW_AT_ranges attribute is the offset in the
6733 .debug_ranges section. */
6734 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
6736 /* Found discontinuous range of addresses. */
6741 /* read_partial_die has also the strict LOW < HIGH requirement. */
6745 /* When using the GNU linker, .gnu.linkonce. sections are used to
6746 eliminate duplicate copies of functions and vtables and such.
6747 The linker will arbitrarily choose one and discard the others.
6748 The AT_*_pc values for such functions refer to local labels in
6749 these sections. If the section from that file was discarded, the
6750 labels are not in the output, so the relocs get a value of 0.
6751 If this is a discarded function, mark the pc bounds as invalid,
6752 so that GDB will ignore it. */
6753 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
6762 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
6763 its low and high PC addresses. Do nothing if these addresses could not
6764 be determined. Otherwise, set LOWPC to the low address if it is smaller,
6765 and HIGHPC to the high address if greater than HIGHPC. */
6768 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
6769 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6770 struct dwarf2_cu
*cu
)
6772 CORE_ADDR low
, high
;
6773 struct die_info
*child
= die
->child
;
6775 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
6777 *lowpc
= min (*lowpc
, low
);
6778 *highpc
= max (*highpc
, high
);
6781 /* If the language does not allow nested subprograms (either inside
6782 subprograms or lexical blocks), we're done. */
6783 if (cu
->language
!= language_ada
)
6786 /* Check all the children of the given DIE. If it contains nested
6787 subprograms, then check their pc bounds. Likewise, we need to
6788 check lexical blocks as well, as they may also contain subprogram
6790 while (child
&& child
->tag
)
6792 if (child
->tag
== DW_TAG_subprogram
6793 || child
->tag
== DW_TAG_lexical_block
)
6794 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
6795 child
= sibling_die (child
);
6799 /* Get the low and high pc's represented by the scope DIE, and store
6800 them in *LOWPC and *HIGHPC. If the correct values can't be
6801 determined, set *LOWPC to -1 and *HIGHPC to 0. */
6804 get_scope_pc_bounds (struct die_info
*die
,
6805 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6806 struct dwarf2_cu
*cu
)
6808 CORE_ADDR best_low
= (CORE_ADDR
) -1;
6809 CORE_ADDR best_high
= (CORE_ADDR
) 0;
6810 CORE_ADDR current_low
, current_high
;
6812 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
6814 best_low
= current_low
;
6815 best_high
= current_high
;
6819 struct die_info
*child
= die
->child
;
6821 while (child
&& child
->tag
)
6823 switch (child
->tag
) {
6824 case DW_TAG_subprogram
:
6825 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
6827 case DW_TAG_namespace
:
6829 /* FIXME: carlton/2004-01-16: Should we do this for
6830 DW_TAG_class_type/DW_TAG_structure_type, too? I think
6831 that current GCC's always emit the DIEs corresponding
6832 to definitions of methods of classes as children of a
6833 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
6834 the DIEs giving the declarations, which could be
6835 anywhere). But I don't see any reason why the
6836 standards says that they have to be there. */
6837 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
6839 if (current_low
!= ((CORE_ADDR
) -1))
6841 best_low
= min (best_low
, current_low
);
6842 best_high
= max (best_high
, current_high
);
6850 child
= sibling_die (child
);
6855 *highpc
= best_high
;
6858 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
6862 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
6863 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
6865 struct objfile
*objfile
= cu
->objfile
;
6866 struct attribute
*attr
;
6868 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6871 CORE_ADDR high
= DW_ADDR (attr
);
6873 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6876 CORE_ADDR low
= DW_ADDR (attr
);
6878 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
6882 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6885 bfd
*obfd
= objfile
->obfd
;
6887 /* The value of the DW_AT_ranges attribute is the offset of the
6888 address range list in the .debug_ranges section. */
6889 unsigned long offset
= DW_UNSND (attr
);
6890 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6892 /* For some target architectures, but not others, the
6893 read_address function sign-extends the addresses it returns.
6894 To recognize base address selection entries, we need a
6896 unsigned int addr_size
= cu
->header
.addr_size
;
6897 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6899 /* The base address, to which the next pair is relative. Note
6900 that this 'base' is a DWARF concept: most entries in a range
6901 list are relative, to reduce the number of relocs against the
6902 debugging information. This is separate from this function's
6903 'baseaddr' argument, which GDB uses to relocate debugging
6904 information from a shared library based on the address at
6905 which the library was loaded. */
6906 CORE_ADDR base
= cu
->base_address
;
6907 int base_known
= cu
->base_known
;
6909 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
6910 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6912 complaint (&symfile_complaints
,
6913 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
6920 unsigned int bytes_read
;
6921 CORE_ADDR start
, end
;
6923 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6924 buffer
+= bytes_read
;
6925 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6926 buffer
+= bytes_read
;
6928 /* Did we find the end of the range list? */
6929 if (start
== 0 && end
== 0)
6932 /* Did we find a base address selection entry? */
6933 else if ((start
& base_select_mask
) == base_select_mask
)
6939 /* We found an ordinary address range. */
6944 complaint (&symfile_complaints
,
6945 _("Invalid .debug_ranges data "
6946 "(no base address)"));
6952 /* Inverted range entries are invalid. */
6953 complaint (&symfile_complaints
,
6954 _("Invalid .debug_ranges data "
6955 "(inverted range)"));
6959 /* Empty range entries have no effect. */
6963 record_block_range (block
,
6964 baseaddr
+ base
+ start
,
6965 baseaddr
+ base
+ end
- 1);
6971 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
6972 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
6973 during 4.6.0 experimental. */
6976 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
6979 int major
, minor
, release
;
6982 if (cu
->producer
== NULL
)
6984 /* For unknown compilers expect their behavior is DWARF version
6987 GCC started to support .debug_types sections by -gdwarf-4 since
6988 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
6989 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
6990 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
6991 interpreted incorrectly by GDB now - GCC PR debug/48229. */
6996 if (cu
->checked_producer
)
6997 return cu
->producer_is_gxx_lt_4_6
;
6999 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
7001 if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) != 0)
7003 /* For non-GCC compilers expect their behavior is DWARF version
7008 cs
= &cu
->producer
[strlen ("GNU ")];
7009 while (*cs
&& !isdigit (*cs
))
7011 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
7013 /* Not recognized as GCC. */
7016 result
= major
< 4 || (major
== 4 && minor
< 6);
7019 cu
->checked_producer
= 1;
7020 cu
->producer_is_gxx_lt_4_6
= result
;
7025 /* Return the default accessibility type if it is not overriden by
7026 DW_AT_accessibility. */
7028 static enum dwarf_access_attribute
7029 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
7031 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
7033 /* The default DWARF 2 accessibility for members is public, the default
7034 accessibility for inheritance is private. */
7036 if (die
->tag
!= DW_TAG_inheritance
)
7037 return DW_ACCESS_public
;
7039 return DW_ACCESS_private
;
7043 /* DWARF 3+ defines the default accessibility a different way. The same
7044 rules apply now for DW_TAG_inheritance as for the members and it only
7045 depends on the container kind. */
7047 if (die
->parent
->tag
== DW_TAG_class_type
)
7048 return DW_ACCESS_private
;
7050 return DW_ACCESS_public
;
7054 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
7055 offset. If the attribute was not found return 0, otherwise return
7056 1. If it was found but could not properly be handled, set *OFFSET
7060 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
7063 struct attribute
*attr
;
7065 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
7070 /* Note that we do not check for a section offset first here.
7071 This is because DW_AT_data_member_location is new in DWARF 4,
7072 so if we see it, we can assume that a constant form is really
7073 a constant and not a section offset. */
7074 if (attr_form_is_constant (attr
))
7075 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
7076 else if (attr_form_is_section_offset (attr
))
7077 dwarf2_complex_location_expr_complaint ();
7078 else if (attr_form_is_block (attr
))
7079 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
7081 dwarf2_complex_location_expr_complaint ();
7089 /* Add an aggregate field to the field list. */
7092 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
7093 struct dwarf2_cu
*cu
)
7095 struct objfile
*objfile
= cu
->objfile
;
7096 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7097 struct nextfield
*new_field
;
7098 struct attribute
*attr
;
7100 char *fieldname
= "";
7102 /* Allocate a new field list entry and link it in. */
7103 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
7104 make_cleanup (xfree
, new_field
);
7105 memset (new_field
, 0, sizeof (struct nextfield
));
7107 if (die
->tag
== DW_TAG_inheritance
)
7109 new_field
->next
= fip
->baseclasses
;
7110 fip
->baseclasses
= new_field
;
7114 new_field
->next
= fip
->fields
;
7115 fip
->fields
= new_field
;
7119 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
7121 new_field
->accessibility
= DW_UNSND (attr
);
7123 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
7124 if (new_field
->accessibility
!= DW_ACCESS_public
)
7125 fip
->non_public_fields
= 1;
7127 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
7129 new_field
->virtuality
= DW_UNSND (attr
);
7131 new_field
->virtuality
= DW_VIRTUALITY_none
;
7133 fp
= &new_field
->field
;
7135 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
7139 /* Data member other than a C++ static data member. */
7141 /* Get type of field. */
7142 fp
->type
= die_type (die
, cu
);
7144 SET_FIELD_BITPOS (*fp
, 0);
7146 /* Get bit size of field (zero if none). */
7147 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
7150 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
7154 FIELD_BITSIZE (*fp
) = 0;
7157 /* Get bit offset of field. */
7158 if (handle_data_member_location (die
, cu
, &offset
))
7159 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
7160 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
7163 if (gdbarch_bits_big_endian (gdbarch
))
7165 /* For big endian bits, the DW_AT_bit_offset gives the
7166 additional bit offset from the MSB of the containing
7167 anonymous object to the MSB of the field. We don't
7168 have to do anything special since we don't need to
7169 know the size of the anonymous object. */
7170 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
7174 /* For little endian bits, compute the bit offset to the
7175 MSB of the anonymous object, subtract off the number of
7176 bits from the MSB of the field to the MSB of the
7177 object, and then subtract off the number of bits of
7178 the field itself. The result is the bit offset of
7179 the LSB of the field. */
7181 int bit_offset
= DW_UNSND (attr
);
7183 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7186 /* The size of the anonymous object containing
7187 the bit field is explicit, so use the
7188 indicated size (in bytes). */
7189 anonymous_size
= DW_UNSND (attr
);
7193 /* The size of the anonymous object containing
7194 the bit field must be inferred from the type
7195 attribute of the data member containing the
7197 anonymous_size
= TYPE_LENGTH (fp
->type
);
7199 SET_FIELD_BITPOS (*fp
,
7201 + anonymous_size
* bits_per_byte
7202 - bit_offset
- FIELD_BITSIZE (*fp
)));
7206 /* Get name of field. */
7207 fieldname
= dwarf2_name (die
, cu
);
7208 if (fieldname
== NULL
)
7211 /* The name is already allocated along with this objfile, so we don't
7212 need to duplicate it for the type. */
7213 fp
->name
= fieldname
;
7215 /* Change accessibility for artificial fields (e.g. virtual table
7216 pointer or virtual base class pointer) to private. */
7217 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
7219 FIELD_ARTIFICIAL (*fp
) = 1;
7220 new_field
->accessibility
= DW_ACCESS_private
;
7221 fip
->non_public_fields
= 1;
7224 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
7226 /* C++ static member. */
7228 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
7229 is a declaration, but all versions of G++ as of this writing
7230 (so through at least 3.2.1) incorrectly generate
7231 DW_TAG_variable tags. */
7233 const char *physname
;
7235 /* Get name of field. */
7236 fieldname
= dwarf2_name (die
, cu
);
7237 if (fieldname
== NULL
)
7240 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7242 /* Only create a symbol if this is an external value.
7243 new_symbol checks this and puts the value in the global symbol
7244 table, which we want. If it is not external, new_symbol
7245 will try to put the value in cu->list_in_scope which is wrong. */
7246 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
7248 /* A static const member, not much different than an enum as far as
7249 we're concerned, except that we can support more types. */
7250 new_symbol (die
, NULL
, cu
);
7253 /* Get physical name. */
7254 physname
= dwarf2_physname (fieldname
, die
, cu
);
7256 /* The name is already allocated along with this objfile, so we don't
7257 need to duplicate it for the type. */
7258 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
7259 FIELD_TYPE (*fp
) = die_type (die
, cu
);
7260 FIELD_NAME (*fp
) = fieldname
;
7262 else if (die
->tag
== DW_TAG_inheritance
)
7266 /* C++ base class field. */
7267 if (handle_data_member_location (die
, cu
, &offset
))
7268 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
7269 FIELD_BITSIZE (*fp
) = 0;
7270 FIELD_TYPE (*fp
) = die_type (die
, cu
);
7271 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
7272 fip
->nbaseclasses
++;
7276 /* Add a typedef defined in the scope of the FIP's class. */
7279 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
7280 struct dwarf2_cu
*cu
)
7282 struct objfile
*objfile
= cu
->objfile
;
7283 struct typedef_field_list
*new_field
;
7284 struct attribute
*attr
;
7285 struct typedef_field
*fp
;
7286 char *fieldname
= "";
7288 /* Allocate a new field list entry and link it in. */
7289 new_field
= xzalloc (sizeof (*new_field
));
7290 make_cleanup (xfree
, new_field
);
7292 gdb_assert (die
->tag
== DW_TAG_typedef
);
7294 fp
= &new_field
->field
;
7296 /* Get name of field. */
7297 fp
->name
= dwarf2_name (die
, cu
);
7298 if (fp
->name
== NULL
)
7301 fp
->type
= read_type_die (die
, cu
);
7303 new_field
->next
= fip
->typedef_field_list
;
7304 fip
->typedef_field_list
= new_field
;
7305 fip
->typedef_field_list_count
++;
7308 /* Create the vector of fields, and attach it to the type. */
7311 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
7312 struct dwarf2_cu
*cu
)
7314 int nfields
= fip
->nfields
;
7316 /* Record the field count, allocate space for the array of fields,
7317 and create blank accessibility bitfields if necessary. */
7318 TYPE_NFIELDS (type
) = nfields
;
7319 TYPE_FIELDS (type
) = (struct field
*)
7320 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
7321 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
7323 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
7325 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7327 TYPE_FIELD_PRIVATE_BITS (type
) =
7328 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7329 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
7331 TYPE_FIELD_PROTECTED_BITS (type
) =
7332 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7333 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
7335 TYPE_FIELD_IGNORE_BITS (type
) =
7336 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7337 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
7340 /* If the type has baseclasses, allocate and clear a bit vector for
7341 TYPE_FIELD_VIRTUAL_BITS. */
7342 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
7344 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
7345 unsigned char *pointer
;
7347 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7348 pointer
= TYPE_ALLOC (type
, num_bytes
);
7349 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
7350 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
7351 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
7354 /* Copy the saved-up fields into the field vector. Start from the head of
7355 the list, adding to the tail of the field array, so that they end up in
7356 the same order in the array in which they were added to the list. */
7357 while (nfields
-- > 0)
7359 struct nextfield
*fieldp
;
7363 fieldp
= fip
->fields
;
7364 fip
->fields
= fieldp
->next
;
7368 fieldp
= fip
->baseclasses
;
7369 fip
->baseclasses
= fieldp
->next
;
7372 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
7373 switch (fieldp
->accessibility
)
7375 case DW_ACCESS_private
:
7376 if (cu
->language
!= language_ada
)
7377 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
7380 case DW_ACCESS_protected
:
7381 if (cu
->language
!= language_ada
)
7382 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
7385 case DW_ACCESS_public
:
7389 /* Unknown accessibility. Complain and treat it as public. */
7391 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
7392 fieldp
->accessibility
);
7396 if (nfields
< fip
->nbaseclasses
)
7398 switch (fieldp
->virtuality
)
7400 case DW_VIRTUALITY_virtual
:
7401 case DW_VIRTUALITY_pure_virtual
:
7402 if (cu
->language
== language_ada
)
7403 error (_("unexpected virtuality in component of Ada type"));
7404 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
7411 /* Add a member function to the proper fieldlist. */
7414 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
7415 struct type
*type
, struct dwarf2_cu
*cu
)
7417 struct objfile
*objfile
= cu
->objfile
;
7418 struct attribute
*attr
;
7419 struct fnfieldlist
*flp
;
7421 struct fn_field
*fnp
;
7423 struct nextfnfield
*new_fnfield
;
7424 struct type
*this_type
;
7425 enum dwarf_access_attribute accessibility
;
7427 if (cu
->language
== language_ada
)
7428 error (_("unexpected member function in Ada type"));
7430 /* Get name of member function. */
7431 fieldname
= dwarf2_name (die
, cu
);
7432 if (fieldname
== NULL
)
7435 /* Look up member function name in fieldlist. */
7436 for (i
= 0; i
< fip
->nfnfields
; i
++)
7438 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
7442 /* Create new list element if necessary. */
7443 if (i
< fip
->nfnfields
)
7444 flp
= &fip
->fnfieldlists
[i
];
7447 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7449 fip
->fnfieldlists
= (struct fnfieldlist
*)
7450 xrealloc (fip
->fnfieldlists
,
7451 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
7452 * sizeof (struct fnfieldlist
));
7453 if (fip
->nfnfields
== 0)
7454 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
7456 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
7457 flp
->name
= fieldname
;
7460 i
= fip
->nfnfields
++;
7463 /* Create a new member function field and chain it to the field list
7465 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
7466 make_cleanup (xfree
, new_fnfield
);
7467 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
7468 new_fnfield
->next
= flp
->head
;
7469 flp
->head
= new_fnfield
;
7472 /* Fill in the member function field info. */
7473 fnp
= &new_fnfield
->fnfield
;
7475 /* Delay processing of the physname until later. */
7476 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
7478 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
7483 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
7484 fnp
->physname
= physname
? physname
: "";
7487 fnp
->type
= alloc_type (objfile
);
7488 this_type
= read_type_die (die
, cu
);
7489 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
7491 int nparams
= TYPE_NFIELDS (this_type
);
7493 /* TYPE is the domain of this method, and THIS_TYPE is the type
7494 of the method itself (TYPE_CODE_METHOD). */
7495 smash_to_method_type (fnp
->type
, type
,
7496 TYPE_TARGET_TYPE (this_type
),
7497 TYPE_FIELDS (this_type
),
7498 TYPE_NFIELDS (this_type
),
7499 TYPE_VARARGS (this_type
));
7501 /* Handle static member functions.
7502 Dwarf2 has no clean way to discern C++ static and non-static
7503 member functions. G++ helps GDB by marking the first
7504 parameter for non-static member functions (which is the this
7505 pointer) as artificial. We obtain this information from
7506 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
7507 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
7508 fnp
->voffset
= VOFFSET_STATIC
;
7511 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
7512 dwarf2_full_name (fieldname
, die
, cu
));
7514 /* Get fcontext from DW_AT_containing_type if present. */
7515 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7516 fnp
->fcontext
= die_containing_type (die
, cu
);
7518 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
7519 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
7521 /* Get accessibility. */
7522 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
7524 accessibility
= DW_UNSND (attr
);
7526 accessibility
= dwarf2_default_access_attribute (die
, cu
);
7527 switch (accessibility
)
7529 case DW_ACCESS_private
:
7530 fnp
->is_private
= 1;
7532 case DW_ACCESS_protected
:
7533 fnp
->is_protected
= 1;
7537 /* Check for artificial methods. */
7538 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
7539 if (attr
&& DW_UNSND (attr
) != 0)
7540 fnp
->is_artificial
= 1;
7542 /* Get index in virtual function table if it is a virtual member
7543 function. For older versions of GCC, this is an offset in the
7544 appropriate virtual table, as specified by DW_AT_containing_type.
7545 For everyone else, it is an expression to be evaluated relative
7546 to the object address. */
7548 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
7551 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
7553 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
7555 /* Old-style GCC. */
7556 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
7558 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
7559 || (DW_BLOCK (attr
)->size
> 1
7560 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
7561 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
7563 struct dwarf_block blk
;
7566 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
7568 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
7569 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
7570 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
7571 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
7572 dwarf2_complex_location_expr_complaint ();
7574 fnp
->voffset
/= cu
->header
.addr_size
;
7578 dwarf2_complex_location_expr_complaint ();
7581 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
7583 else if (attr_form_is_section_offset (attr
))
7585 dwarf2_complex_location_expr_complaint ();
7589 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
7595 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
7596 if (attr
&& DW_UNSND (attr
))
7598 /* GCC does this, as of 2008-08-25; PR debug/37237. */
7599 complaint (&symfile_complaints
,
7600 _("Member function \"%s\" (offset %d) is virtual "
7601 "but the vtable offset is not specified"),
7602 fieldname
, die
->offset
.sect_off
);
7603 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7604 TYPE_CPLUS_DYNAMIC (type
) = 1;
7609 /* Create the vector of member function fields, and attach it to the type. */
7612 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
7613 struct dwarf2_cu
*cu
)
7615 struct fnfieldlist
*flp
;
7618 if (cu
->language
== language_ada
)
7619 error (_("unexpected member functions in Ada type"));
7621 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7622 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
7623 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
7625 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
7627 struct nextfnfield
*nfp
= flp
->head
;
7628 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
7631 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
7632 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
7633 fn_flp
->fn_fields
= (struct fn_field
*)
7634 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
7635 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
7636 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
7639 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
7642 /* Returns non-zero if NAME is the name of a vtable member in CU's
7643 language, zero otherwise. */
7645 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
7647 static const char vptr
[] = "_vptr";
7648 static const char vtable
[] = "vtable";
7650 /* Look for the C++ and Java forms of the vtable. */
7651 if ((cu
->language
== language_java
7652 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
7653 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
7654 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
7660 /* GCC outputs unnamed structures that are really pointers to member
7661 functions, with the ABI-specified layout. If TYPE describes
7662 such a structure, smash it into a member function type.
7664 GCC shouldn't do this; it should just output pointer to member DIEs.
7665 This is GCC PR debug/28767. */
7668 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
7670 struct type
*pfn_type
, *domain_type
, *new_type
;
7672 /* Check for a structure with no name and two children. */
7673 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
7676 /* Check for __pfn and __delta members. */
7677 if (TYPE_FIELD_NAME (type
, 0) == NULL
7678 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
7679 || TYPE_FIELD_NAME (type
, 1) == NULL
7680 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
7683 /* Find the type of the method. */
7684 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
7685 if (pfn_type
== NULL
7686 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
7687 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
7690 /* Look for the "this" argument. */
7691 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
7692 if (TYPE_NFIELDS (pfn_type
) == 0
7693 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
7694 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
7697 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
7698 new_type
= alloc_type (objfile
);
7699 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
7700 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
7701 TYPE_VARARGS (pfn_type
));
7702 smash_to_methodptr_type (type
, new_type
);
7705 /* Called when we find the DIE that starts a structure or union scope
7706 (definition) to create a type for the structure or union. Fill in
7707 the type's name and general properties; the members will not be
7708 processed until process_structure_type.
7710 NOTE: we need to call these functions regardless of whether or not the
7711 DIE has a DW_AT_name attribute, since it might be an anonymous
7712 structure or union. This gets the type entered into our set of
7715 However, if the structure is incomplete (an opaque struct/union)
7716 then suppress creating a symbol table entry for it since gdb only
7717 wants to find the one with the complete definition. Note that if
7718 it is complete, we just call new_symbol, which does it's own
7719 checking about whether the struct/union is anonymous or not (and
7720 suppresses creating a symbol table entry itself). */
7722 static struct type
*
7723 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7725 struct objfile
*objfile
= cu
->objfile
;
7727 struct attribute
*attr
;
7730 /* If the definition of this type lives in .debug_types, read that type.
7731 Don't follow DW_AT_specification though, that will take us back up
7732 the chain and we want to go down. */
7733 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7736 struct dwarf2_cu
*type_cu
= cu
;
7737 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7739 /* We could just recurse on read_structure_type, but we need to call
7740 get_die_type to ensure only one type for this DIE is created.
7741 This is important, for example, because for c++ classes we need
7742 TYPE_NAME set which is only done by new_symbol. Blech. */
7743 type
= read_type_die (type_die
, type_cu
);
7745 /* TYPE_CU may not be the same as CU.
7746 Ensure TYPE is recorded in CU's type_hash table. */
7747 return set_die_type (die
, type
, cu
);
7750 type
= alloc_type (objfile
);
7751 INIT_CPLUS_SPECIFIC (type
);
7753 name
= dwarf2_name (die
, cu
);
7756 if (cu
->language
== language_cplus
7757 || cu
->language
== language_java
)
7759 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
7761 /* dwarf2_full_name might have already finished building the DIE's
7762 type. If so, there is no need to continue. */
7763 if (get_die_type (die
, cu
) != NULL
)
7764 return get_die_type (die
, cu
);
7766 TYPE_TAG_NAME (type
) = full_name
;
7767 if (die
->tag
== DW_TAG_structure_type
7768 || die
->tag
== DW_TAG_class_type
)
7769 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7773 /* The name is already allocated along with this objfile, so
7774 we don't need to duplicate it for the type. */
7775 TYPE_TAG_NAME (type
) = (char *) name
;
7776 if (die
->tag
== DW_TAG_class_type
)
7777 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7781 if (die
->tag
== DW_TAG_structure_type
)
7783 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
7785 else if (die
->tag
== DW_TAG_union_type
)
7787 TYPE_CODE (type
) = TYPE_CODE_UNION
;
7791 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
7794 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
7795 TYPE_DECLARED_CLASS (type
) = 1;
7797 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7800 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7804 TYPE_LENGTH (type
) = 0;
7807 TYPE_STUB_SUPPORTED (type
) = 1;
7808 if (die_is_declaration (die
, cu
))
7809 TYPE_STUB (type
) = 1;
7810 else if (attr
== NULL
&& die
->child
== NULL
7811 && producer_is_realview (cu
->producer
))
7812 /* RealView does not output the required DW_AT_declaration
7813 on incomplete types. */
7814 TYPE_STUB (type
) = 1;
7816 /* We need to add the type field to the die immediately so we don't
7817 infinitely recurse when dealing with pointers to the structure
7818 type within the structure itself. */
7819 set_die_type (die
, type
, cu
);
7821 /* set_die_type should be already done. */
7822 set_descriptive_type (type
, die
, cu
);
7827 /* Finish creating a structure or union type, including filling in
7828 its members and creating a symbol for it. */
7831 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7833 struct objfile
*objfile
= cu
->objfile
;
7834 struct die_info
*child_die
= die
->child
;
7837 type
= get_die_type (die
, cu
);
7839 type
= read_structure_type (die
, cu
);
7841 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
7843 struct field_info fi
;
7844 struct die_info
*child_die
;
7845 VEC (symbolp
) *template_args
= NULL
;
7846 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
7848 memset (&fi
, 0, sizeof (struct field_info
));
7850 child_die
= die
->child
;
7852 while (child_die
&& child_die
->tag
)
7854 if (child_die
->tag
== DW_TAG_member
7855 || child_die
->tag
== DW_TAG_variable
)
7857 /* NOTE: carlton/2002-11-05: A C++ static data member
7858 should be a DW_TAG_member that is a declaration, but
7859 all versions of G++ as of this writing (so through at
7860 least 3.2.1) incorrectly generate DW_TAG_variable
7861 tags for them instead. */
7862 dwarf2_add_field (&fi
, child_die
, cu
);
7864 else if (child_die
->tag
== DW_TAG_subprogram
)
7866 /* C++ member function. */
7867 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
7869 else if (child_die
->tag
== DW_TAG_inheritance
)
7871 /* C++ base class field. */
7872 dwarf2_add_field (&fi
, child_die
, cu
);
7874 else if (child_die
->tag
== DW_TAG_typedef
)
7875 dwarf2_add_typedef (&fi
, child_die
, cu
);
7876 else if (child_die
->tag
== DW_TAG_template_type_param
7877 || child_die
->tag
== DW_TAG_template_value_param
)
7879 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
7882 VEC_safe_push (symbolp
, template_args
, arg
);
7885 child_die
= sibling_die (child_die
);
7888 /* Attach template arguments to type. */
7889 if (! VEC_empty (symbolp
, template_args
))
7891 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7892 TYPE_N_TEMPLATE_ARGUMENTS (type
)
7893 = VEC_length (symbolp
, template_args
);
7894 TYPE_TEMPLATE_ARGUMENTS (type
)
7895 = obstack_alloc (&objfile
->objfile_obstack
,
7896 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7897 * sizeof (struct symbol
*)));
7898 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
7899 VEC_address (symbolp
, template_args
),
7900 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7901 * sizeof (struct symbol
*)));
7902 VEC_free (symbolp
, template_args
);
7905 /* Attach fields and member functions to the type. */
7907 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
7910 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
7912 /* Get the type which refers to the base class (possibly this
7913 class itself) which contains the vtable pointer for the current
7914 class from the DW_AT_containing_type attribute. This use of
7915 DW_AT_containing_type is a GNU extension. */
7917 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7919 struct type
*t
= die_containing_type (die
, cu
);
7921 TYPE_VPTR_BASETYPE (type
) = t
;
7926 /* Our own class provides vtbl ptr. */
7927 for (i
= TYPE_NFIELDS (t
) - 1;
7928 i
>= TYPE_N_BASECLASSES (t
);
7931 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
7933 if (is_vtable_name (fieldname
, cu
))
7935 TYPE_VPTR_FIELDNO (type
) = i
;
7940 /* Complain if virtual function table field not found. */
7941 if (i
< TYPE_N_BASECLASSES (t
))
7942 complaint (&symfile_complaints
,
7943 _("virtual function table pointer "
7944 "not found when defining class '%s'"),
7945 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
7950 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
7953 else if (cu
->producer
7954 && strncmp (cu
->producer
,
7955 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
7957 /* The IBM XLC compiler does not provide direct indication
7958 of the containing type, but the vtable pointer is
7959 always named __vfp. */
7963 for (i
= TYPE_NFIELDS (type
) - 1;
7964 i
>= TYPE_N_BASECLASSES (type
);
7967 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
7969 TYPE_VPTR_FIELDNO (type
) = i
;
7970 TYPE_VPTR_BASETYPE (type
) = type
;
7977 /* Copy fi.typedef_field_list linked list elements content into the
7978 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
7979 if (fi
.typedef_field_list
)
7981 int i
= fi
.typedef_field_list_count
;
7983 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7984 TYPE_TYPEDEF_FIELD_ARRAY (type
)
7985 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
7986 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
7988 /* Reverse the list order to keep the debug info elements order. */
7991 struct typedef_field
*dest
, *src
;
7993 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
7994 src
= &fi
.typedef_field_list
->field
;
7995 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
8000 do_cleanups (back_to
);
8002 if (HAVE_CPLUS_STRUCT (type
))
8003 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
8006 quirk_gcc_member_function_pointer (type
, objfile
);
8008 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
8009 snapshots) has been known to create a die giving a declaration
8010 for a class that has, as a child, a die giving a definition for a
8011 nested class. So we have to process our children even if the
8012 current die is a declaration. Normally, of course, a declaration
8013 won't have any children at all. */
8015 while (child_die
!= NULL
&& child_die
->tag
)
8017 if (child_die
->tag
== DW_TAG_member
8018 || child_die
->tag
== DW_TAG_variable
8019 || child_die
->tag
== DW_TAG_inheritance
8020 || child_die
->tag
== DW_TAG_template_value_param
8021 || child_die
->tag
== DW_TAG_template_type_param
)
8026 process_die (child_die
, cu
);
8028 child_die
= sibling_die (child_die
);
8031 /* Do not consider external references. According to the DWARF standard,
8032 these DIEs are identified by the fact that they have no byte_size
8033 attribute, and a declaration attribute. */
8034 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
8035 || !die_is_declaration (die
, cu
))
8036 new_symbol (die
, type
, cu
);
8039 /* Given a DW_AT_enumeration_type die, set its type. We do not
8040 complete the type's fields yet, or create any symbols. */
8042 static struct type
*
8043 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8045 struct objfile
*objfile
= cu
->objfile
;
8047 struct attribute
*attr
;
8050 /* If the definition of this type lives in .debug_types, read that type.
8051 Don't follow DW_AT_specification though, that will take us back up
8052 the chain and we want to go down. */
8053 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
8056 struct dwarf2_cu
*type_cu
= cu
;
8057 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
8059 type
= read_type_die (type_die
, type_cu
);
8061 /* TYPE_CU may not be the same as CU.
8062 Ensure TYPE is recorded in CU's type_hash table. */
8063 return set_die_type (die
, type
, cu
);
8066 type
= alloc_type (objfile
);
8068 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
8069 name
= dwarf2_full_name (NULL
, die
, cu
);
8071 TYPE_TAG_NAME (type
) = (char *) name
;
8073 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8076 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8080 TYPE_LENGTH (type
) = 0;
8083 /* The enumeration DIE can be incomplete. In Ada, any type can be
8084 declared as private in the package spec, and then defined only
8085 inside the package body. Such types are known as Taft Amendment
8086 Types. When another package uses such a type, an incomplete DIE
8087 may be generated by the compiler. */
8088 if (die_is_declaration (die
, cu
))
8089 TYPE_STUB (type
) = 1;
8091 return set_die_type (die
, type
, cu
);
8094 /* Given a pointer to a die which begins an enumeration, process all
8095 the dies that define the members of the enumeration, and create the
8096 symbol for the enumeration type.
8098 NOTE: We reverse the order of the element list. */
8101 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8103 struct type
*this_type
;
8105 this_type
= get_die_type (die
, cu
);
8106 if (this_type
== NULL
)
8107 this_type
= read_enumeration_type (die
, cu
);
8109 if (die
->child
!= NULL
)
8111 struct die_info
*child_die
;
8113 struct field
*fields
= NULL
;
8115 int unsigned_enum
= 1;
8120 child_die
= die
->child
;
8121 while (child_die
&& child_die
->tag
)
8123 if (child_die
->tag
!= DW_TAG_enumerator
)
8125 process_die (child_die
, cu
);
8129 name
= dwarf2_name (child_die
, cu
);
8132 sym
= new_symbol (child_die
, this_type
, cu
);
8133 if (SYMBOL_VALUE (sym
) < 0)
8138 else if ((mask
& SYMBOL_VALUE (sym
)) != 0)
8141 mask
|= SYMBOL_VALUE (sym
);
8143 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
8145 fields
= (struct field
*)
8147 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
8148 * sizeof (struct field
));
8151 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
8152 FIELD_TYPE (fields
[num_fields
]) = NULL
;
8153 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
8154 FIELD_BITSIZE (fields
[num_fields
]) = 0;
8160 child_die
= sibling_die (child_die
);
8165 TYPE_NFIELDS (this_type
) = num_fields
;
8166 TYPE_FIELDS (this_type
) = (struct field
*)
8167 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
8168 memcpy (TYPE_FIELDS (this_type
), fields
,
8169 sizeof (struct field
) * num_fields
);
8173 TYPE_UNSIGNED (this_type
) = 1;
8175 TYPE_FLAG_ENUM (this_type
) = 1;
8178 /* If we are reading an enum from a .debug_types unit, and the enum
8179 is a declaration, and the enum is not the signatured type in the
8180 unit, then we do not want to add a symbol for it. Adding a
8181 symbol would in some cases obscure the true definition of the
8182 enum, giving users an incomplete type when the definition is
8183 actually available. Note that we do not want to do this for all
8184 enums which are just declarations, because C++0x allows forward
8185 enum declarations. */
8186 if (cu
->per_cu
->debug_types_section
8187 && die_is_declaration (die
, cu
))
8189 struct signatured_type
*sig_type
;
8192 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
8193 cu
->per_cu
->debug_types_section
,
8194 cu
->per_cu
->offset
);
8195 if (sig_type
->per_cu
.offset
.sect_off
+ sig_type
->type_offset
.cu_off
8196 != die
->offset
.sect_off
)
8200 new_symbol (die
, this_type
, cu
);
8203 /* Extract all information from a DW_TAG_array_type DIE and put it in
8204 the DIE's type field. For now, this only handles one dimensional
8207 static struct type
*
8208 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8210 struct objfile
*objfile
= cu
->objfile
;
8211 struct die_info
*child_die
;
8213 struct type
*element_type
, *range_type
, *index_type
;
8214 struct type
**range_types
= NULL
;
8215 struct attribute
*attr
;
8217 struct cleanup
*back_to
;
8220 element_type
= die_type (die
, cu
);
8222 /* The die_type call above may have already set the type for this DIE. */
8223 type
= get_die_type (die
, cu
);
8227 /* Irix 6.2 native cc creates array types without children for
8228 arrays with unspecified length. */
8229 if (die
->child
== NULL
)
8231 index_type
= objfile_type (objfile
)->builtin_int
;
8232 range_type
= create_range_type (NULL
, index_type
, 0, -1);
8233 type
= create_array_type (NULL
, element_type
, range_type
);
8234 return set_die_type (die
, type
, cu
);
8237 back_to
= make_cleanup (null_cleanup
, NULL
);
8238 child_die
= die
->child
;
8239 while (child_die
&& child_die
->tag
)
8241 if (child_die
->tag
== DW_TAG_subrange_type
)
8243 struct type
*child_type
= read_type_die (child_die
, cu
);
8245 if (child_type
!= NULL
)
8247 /* The range type was succesfully read. Save it for the
8248 array type creation. */
8249 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
8251 range_types
= (struct type
**)
8252 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
8253 * sizeof (struct type
*));
8255 make_cleanup (free_current_contents
, &range_types
);
8257 range_types
[ndim
++] = child_type
;
8260 child_die
= sibling_die (child_die
);
8263 /* Dwarf2 dimensions are output from left to right, create the
8264 necessary array types in backwards order. */
8266 type
= element_type
;
8268 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
8273 type
= create_array_type (NULL
, type
, range_types
[i
++]);
8278 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
8281 /* Understand Dwarf2 support for vector types (like they occur on
8282 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
8283 array type. This is not part of the Dwarf2/3 standard yet, but a
8284 custom vendor extension. The main difference between a regular
8285 array and the vector variant is that vectors are passed by value
8287 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
8289 make_vector_type (type
);
8291 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
8292 implementation may choose to implement triple vectors using this
8294 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8297 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
8298 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8300 complaint (&symfile_complaints
,
8301 _("DW_AT_byte_size for array type smaller "
8302 "than the total size of elements"));
8305 name
= dwarf2_name (die
, cu
);
8307 TYPE_NAME (type
) = name
;
8309 /* Install the type in the die. */
8310 set_die_type (die
, type
, cu
);
8312 /* set_die_type should be already done. */
8313 set_descriptive_type (type
, die
, cu
);
8315 do_cleanups (back_to
);
8320 static enum dwarf_array_dim_ordering
8321 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
8323 struct attribute
*attr
;
8325 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
8327 if (attr
) return DW_SND (attr
);
8329 /* GNU F77 is a special case, as at 08/2004 array type info is the
8330 opposite order to the dwarf2 specification, but data is still
8331 laid out as per normal fortran.
8333 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
8334 version checking. */
8336 if (cu
->language
== language_fortran
8337 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
8339 return DW_ORD_row_major
;
8342 switch (cu
->language_defn
->la_array_ordering
)
8344 case array_column_major
:
8345 return DW_ORD_col_major
;
8346 case array_row_major
:
8348 return DW_ORD_row_major
;
8352 /* Extract all information from a DW_TAG_set_type DIE and put it in
8353 the DIE's type field. */
8355 static struct type
*
8356 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8358 struct type
*domain_type
, *set_type
;
8359 struct attribute
*attr
;
8361 domain_type
= die_type (die
, cu
);
8363 /* The die_type call above may have already set the type for this DIE. */
8364 set_type
= get_die_type (die
, cu
);
8368 set_type
= create_set_type (NULL
, domain_type
);
8370 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8372 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
8374 return set_die_type (die
, set_type
, cu
);
8377 /* First cut: install each common block member as a global variable. */
8380 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
8382 struct die_info
*child_die
;
8383 struct attribute
*attr
;
8385 CORE_ADDR base
= (CORE_ADDR
) 0;
8387 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
8390 /* Support the .debug_loc offsets. */
8391 if (attr_form_is_block (attr
))
8393 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
8395 else if (attr_form_is_section_offset (attr
))
8397 dwarf2_complex_location_expr_complaint ();
8401 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
8402 "common block member");
8405 if (die
->child
!= NULL
)
8407 child_die
= die
->child
;
8408 while (child_die
&& child_die
->tag
)
8412 sym
= new_symbol (child_die
, NULL
, cu
);
8414 && handle_data_member_location (child_die
, cu
, &offset
))
8416 SYMBOL_VALUE_ADDRESS (sym
) = base
+ offset
;
8417 add_symbol_to_list (sym
, &global_symbols
);
8419 child_die
= sibling_die (child_die
);
8424 /* Create a type for a C++ namespace. */
8426 static struct type
*
8427 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8429 struct objfile
*objfile
= cu
->objfile
;
8430 const char *previous_prefix
, *name
;
8434 /* For extensions, reuse the type of the original namespace. */
8435 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
8437 struct die_info
*ext_die
;
8438 struct dwarf2_cu
*ext_cu
= cu
;
8440 ext_die
= dwarf2_extension (die
, &ext_cu
);
8441 type
= read_type_die (ext_die
, ext_cu
);
8443 /* EXT_CU may not be the same as CU.
8444 Ensure TYPE is recorded in CU's type_hash table. */
8445 return set_die_type (die
, type
, cu
);
8448 name
= namespace_name (die
, &is_anonymous
, cu
);
8450 /* Now build the name of the current namespace. */
8452 previous_prefix
= determine_prefix (die
, cu
);
8453 if (previous_prefix
[0] != '\0')
8454 name
= typename_concat (&objfile
->objfile_obstack
,
8455 previous_prefix
, name
, 0, cu
);
8457 /* Create the type. */
8458 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
8460 TYPE_NAME (type
) = (char *) name
;
8461 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8463 return set_die_type (die
, type
, cu
);
8466 /* Read a C++ namespace. */
8469 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
8471 struct objfile
*objfile
= cu
->objfile
;
8474 /* Add a symbol associated to this if we haven't seen the namespace
8475 before. Also, add a using directive if it's an anonymous
8478 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
8482 type
= read_type_die (die
, cu
);
8483 new_symbol (die
, type
, cu
);
8485 namespace_name (die
, &is_anonymous
, cu
);
8488 const char *previous_prefix
= determine_prefix (die
, cu
);
8490 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
8491 NULL
, NULL
, &objfile
->objfile_obstack
);
8495 if (die
->child
!= NULL
)
8497 struct die_info
*child_die
= die
->child
;
8499 while (child_die
&& child_die
->tag
)
8501 process_die (child_die
, cu
);
8502 child_die
= sibling_die (child_die
);
8507 /* Read a Fortran module as type. This DIE can be only a declaration used for
8508 imported module. Still we need that type as local Fortran "use ... only"
8509 declaration imports depend on the created type in determine_prefix. */
8511 static struct type
*
8512 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8514 struct objfile
*objfile
= cu
->objfile
;
8518 module_name
= dwarf2_name (die
, cu
);
8520 complaint (&symfile_complaints
,
8521 _("DW_TAG_module has no name, offset 0x%x"),
8522 die
->offset
.sect_off
);
8523 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
8525 /* determine_prefix uses TYPE_TAG_NAME. */
8526 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8528 return set_die_type (die
, type
, cu
);
8531 /* Read a Fortran module. */
8534 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
8536 struct die_info
*child_die
= die
->child
;
8538 while (child_die
&& child_die
->tag
)
8540 process_die (child_die
, cu
);
8541 child_die
= sibling_die (child_die
);
8545 /* Return the name of the namespace represented by DIE. Set
8546 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
8550 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
8552 struct die_info
*current_die
;
8553 const char *name
= NULL
;
8555 /* Loop through the extensions until we find a name. */
8557 for (current_die
= die
;
8558 current_die
!= NULL
;
8559 current_die
= dwarf2_extension (die
, &cu
))
8561 name
= dwarf2_name (current_die
, cu
);
8566 /* Is it an anonymous namespace? */
8568 *is_anonymous
= (name
== NULL
);
8570 name
= CP_ANONYMOUS_NAMESPACE_STR
;
8575 /* Extract all information from a DW_TAG_pointer_type DIE and add to
8576 the user defined type vector. */
8578 static struct type
*
8579 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8581 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
8582 struct comp_unit_head
*cu_header
= &cu
->header
;
8584 struct attribute
*attr_byte_size
;
8585 struct attribute
*attr_address_class
;
8586 int byte_size
, addr_class
;
8587 struct type
*target_type
;
8589 target_type
= die_type (die
, cu
);
8591 /* The die_type call above may have already set the type for this DIE. */
8592 type
= get_die_type (die
, cu
);
8596 type
= lookup_pointer_type (target_type
);
8598 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8600 byte_size
= DW_UNSND (attr_byte_size
);
8602 byte_size
= cu_header
->addr_size
;
8604 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
8605 if (attr_address_class
)
8606 addr_class
= DW_UNSND (attr_address_class
);
8608 addr_class
= DW_ADDR_none
;
8610 /* If the pointer size or address class is different than the
8611 default, create a type variant marked as such and set the
8612 length accordingly. */
8613 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
8615 if (gdbarch_address_class_type_flags_p (gdbarch
))
8619 type_flags
= gdbarch_address_class_type_flags
8620 (gdbarch
, byte_size
, addr_class
);
8621 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
8623 type
= make_type_with_address_space (type
, type_flags
);
8625 else if (TYPE_LENGTH (type
) != byte_size
)
8627 complaint (&symfile_complaints
,
8628 _("invalid pointer size %d"), byte_size
);
8632 /* Should we also complain about unhandled address classes? */
8636 TYPE_LENGTH (type
) = byte_size
;
8637 return set_die_type (die
, type
, cu
);
8640 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
8641 the user defined type vector. */
8643 static struct type
*
8644 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8647 struct type
*to_type
;
8648 struct type
*domain
;
8650 to_type
= die_type (die
, cu
);
8651 domain
= die_containing_type (die
, cu
);
8653 /* The calls above may have already set the type for this DIE. */
8654 type
= get_die_type (die
, cu
);
8658 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
8659 type
= lookup_methodptr_type (to_type
);
8661 type
= lookup_memberptr_type (to_type
, domain
);
8663 return set_die_type (die
, type
, cu
);
8666 /* Extract all information from a DW_TAG_reference_type DIE and add to
8667 the user defined type vector. */
8669 static struct type
*
8670 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8672 struct comp_unit_head
*cu_header
= &cu
->header
;
8673 struct type
*type
, *target_type
;
8674 struct attribute
*attr
;
8676 target_type
= die_type (die
, cu
);
8678 /* The die_type call above may have already set the type for this DIE. */
8679 type
= get_die_type (die
, cu
);
8683 type
= lookup_reference_type (target_type
);
8684 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8687 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8691 TYPE_LENGTH (type
) = cu_header
->addr_size
;
8693 return set_die_type (die
, type
, cu
);
8696 static struct type
*
8697 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8699 struct type
*base_type
, *cv_type
;
8701 base_type
= die_type (die
, cu
);
8703 /* The die_type call above may have already set the type for this DIE. */
8704 cv_type
= get_die_type (die
, cu
);
8708 /* In case the const qualifier is applied to an array type, the element type
8709 is so qualified, not the array type (section 6.7.3 of C99). */
8710 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
8712 struct type
*el_type
, *inner_array
;
8714 base_type
= copy_type (base_type
);
8715 inner_array
= base_type
;
8717 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
8719 TYPE_TARGET_TYPE (inner_array
) =
8720 copy_type (TYPE_TARGET_TYPE (inner_array
));
8721 inner_array
= TYPE_TARGET_TYPE (inner_array
);
8724 el_type
= TYPE_TARGET_TYPE (inner_array
);
8725 TYPE_TARGET_TYPE (inner_array
) =
8726 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
8728 return set_die_type (die
, base_type
, cu
);
8731 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
8732 return set_die_type (die
, cv_type
, cu
);
8735 static struct type
*
8736 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8738 struct type
*base_type
, *cv_type
;
8740 base_type
= die_type (die
, cu
);
8742 /* The die_type call above may have already set the type for this DIE. */
8743 cv_type
= get_die_type (die
, cu
);
8747 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
8748 return set_die_type (die
, cv_type
, cu
);
8751 /* Extract all information from a DW_TAG_string_type DIE and add to
8752 the user defined type vector. It isn't really a user defined type,
8753 but it behaves like one, with other DIE's using an AT_user_def_type
8754 attribute to reference it. */
8756 static struct type
*
8757 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8759 struct objfile
*objfile
= cu
->objfile
;
8760 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8761 struct type
*type
, *range_type
, *index_type
, *char_type
;
8762 struct attribute
*attr
;
8763 unsigned int length
;
8765 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
8768 length
= DW_UNSND (attr
);
8772 /* Check for the DW_AT_byte_size attribute. */
8773 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8776 length
= DW_UNSND (attr
);
8784 index_type
= objfile_type (objfile
)->builtin_int
;
8785 range_type
= create_range_type (NULL
, index_type
, 1, length
);
8786 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
8787 type
= create_string_type (NULL
, char_type
, range_type
);
8789 return set_die_type (die
, type
, cu
);
8792 /* Handle DIES due to C code like:
8796 int (*funcp)(int a, long l);
8800 ('funcp' generates a DW_TAG_subroutine_type DIE). */
8802 static struct type
*
8803 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8805 struct objfile
*objfile
= cu
->objfile
;
8806 struct type
*type
; /* Type that this function returns. */
8807 struct type
*ftype
; /* Function that returns above type. */
8808 struct attribute
*attr
;
8810 type
= die_type (die
, cu
);
8812 /* The die_type call above may have already set the type for this DIE. */
8813 ftype
= get_die_type (die
, cu
);
8817 ftype
= lookup_function_type (type
);
8819 /* All functions in C++, Pascal and Java have prototypes. */
8820 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
8821 if ((attr
&& (DW_UNSND (attr
) != 0))
8822 || cu
->language
== language_cplus
8823 || cu
->language
== language_java
8824 || cu
->language
== language_pascal
)
8825 TYPE_PROTOTYPED (ftype
) = 1;
8826 else if (producer_is_realview (cu
->producer
))
8827 /* RealView does not emit DW_AT_prototyped. We can not
8828 distinguish prototyped and unprototyped functions; default to
8829 prototyped, since that is more common in modern code (and
8830 RealView warns about unprototyped functions). */
8831 TYPE_PROTOTYPED (ftype
) = 1;
8833 /* Store the calling convention in the type if it's available in
8834 the subroutine die. Otherwise set the calling convention to
8835 the default value DW_CC_normal. */
8836 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
8838 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
8839 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
8840 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
8842 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
8844 /* We need to add the subroutine type to the die immediately so
8845 we don't infinitely recurse when dealing with parameters
8846 declared as the same subroutine type. */
8847 set_die_type (die
, ftype
, cu
);
8849 if (die
->child
!= NULL
)
8851 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
8852 struct die_info
*child_die
;
8853 int nparams
, iparams
;
8855 /* Count the number of parameters.
8856 FIXME: GDB currently ignores vararg functions, but knows about
8857 vararg member functions. */
8859 child_die
= die
->child
;
8860 while (child_die
&& child_die
->tag
)
8862 if (child_die
->tag
== DW_TAG_formal_parameter
)
8864 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
8865 TYPE_VARARGS (ftype
) = 1;
8866 child_die
= sibling_die (child_die
);
8869 /* Allocate storage for parameters and fill them in. */
8870 TYPE_NFIELDS (ftype
) = nparams
;
8871 TYPE_FIELDS (ftype
) = (struct field
*)
8872 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
8874 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
8875 even if we error out during the parameters reading below. */
8876 for (iparams
= 0; iparams
< nparams
; iparams
++)
8877 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
8880 child_die
= die
->child
;
8881 while (child_die
&& child_die
->tag
)
8883 if (child_die
->tag
== DW_TAG_formal_parameter
)
8885 struct type
*arg_type
;
8887 /* DWARF version 2 has no clean way to discern C++
8888 static and non-static member functions. G++ helps
8889 GDB by marking the first parameter for non-static
8890 member functions (which is the this pointer) as
8891 artificial. We pass this information to
8892 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
8894 DWARF version 3 added DW_AT_object_pointer, which GCC
8895 4.5 does not yet generate. */
8896 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
8898 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
8901 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
8903 /* GCC/43521: In java, the formal parameter
8904 "this" is sometimes not marked with DW_AT_artificial. */
8905 if (cu
->language
== language_java
)
8907 const char *name
= dwarf2_name (child_die
, cu
);
8909 if (name
&& !strcmp (name
, "this"))
8910 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
8913 arg_type
= die_type (child_die
, cu
);
8915 /* RealView does not mark THIS as const, which the testsuite
8916 expects. GCC marks THIS as const in method definitions,
8917 but not in the class specifications (GCC PR 43053). */
8918 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
8919 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
8922 struct dwarf2_cu
*arg_cu
= cu
;
8923 const char *name
= dwarf2_name (child_die
, cu
);
8925 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
8928 /* If the compiler emits this, use it. */
8929 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
8932 else if (name
&& strcmp (name
, "this") == 0)
8933 /* Function definitions will have the argument names. */
8935 else if (name
== NULL
&& iparams
== 0)
8936 /* Declarations may not have the names, so like
8937 elsewhere in GDB, assume an artificial first
8938 argument is "this". */
8942 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
8946 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
8949 child_die
= sibling_die (child_die
);
8956 static struct type
*
8957 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
8959 struct objfile
*objfile
= cu
->objfile
;
8960 const char *name
= NULL
;
8961 struct type
*this_type
, *target_type
;
8963 name
= dwarf2_full_name (NULL
, die
, cu
);
8964 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
8965 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
8966 TYPE_NAME (this_type
) = (char *) name
;
8967 set_die_type (die
, this_type
, cu
);
8968 target_type
= die_type (die
, cu
);
8969 if (target_type
!= this_type
)
8970 TYPE_TARGET_TYPE (this_type
) = target_type
;
8973 /* Self-referential typedefs are, it seems, not allowed by the DWARF
8974 spec and cause infinite loops in GDB. */
8975 complaint (&symfile_complaints
,
8976 _("Self-referential DW_TAG_typedef "
8977 "- DIE at 0x%x [in module %s]"),
8978 die
->offset
.sect_off
, objfile
->name
);
8979 TYPE_TARGET_TYPE (this_type
) = NULL
;
8984 /* Find a representation of a given base type and install
8985 it in the TYPE field of the die. */
8987 static struct type
*
8988 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8990 struct objfile
*objfile
= cu
->objfile
;
8992 struct attribute
*attr
;
8993 int encoding
= 0, size
= 0;
8995 enum type_code code
= TYPE_CODE_INT
;
8997 struct type
*target_type
= NULL
;
8999 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
9002 encoding
= DW_UNSND (attr
);
9004 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9007 size
= DW_UNSND (attr
);
9009 name
= dwarf2_name (die
, cu
);
9012 complaint (&symfile_complaints
,
9013 _("DW_AT_name missing from DW_TAG_base_type"));
9018 case DW_ATE_address
:
9019 /* Turn DW_ATE_address into a void * pointer. */
9020 code
= TYPE_CODE_PTR
;
9021 type_flags
|= TYPE_FLAG_UNSIGNED
;
9022 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
9024 case DW_ATE_boolean
:
9025 code
= TYPE_CODE_BOOL
;
9026 type_flags
|= TYPE_FLAG_UNSIGNED
;
9028 case DW_ATE_complex_float
:
9029 code
= TYPE_CODE_COMPLEX
;
9030 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
9032 case DW_ATE_decimal_float
:
9033 code
= TYPE_CODE_DECFLOAT
;
9036 code
= TYPE_CODE_FLT
;
9040 case DW_ATE_unsigned
:
9041 type_flags
|= TYPE_FLAG_UNSIGNED
;
9042 if (cu
->language
== language_fortran
9044 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
9045 code
= TYPE_CODE_CHAR
;
9047 case DW_ATE_signed_char
:
9048 if (cu
->language
== language_ada
|| cu
->language
== language_m2
9049 || cu
->language
== language_pascal
9050 || cu
->language
== language_fortran
)
9051 code
= TYPE_CODE_CHAR
;
9053 case DW_ATE_unsigned_char
:
9054 if (cu
->language
== language_ada
|| cu
->language
== language_m2
9055 || cu
->language
== language_pascal
9056 || cu
->language
== language_fortran
)
9057 code
= TYPE_CODE_CHAR
;
9058 type_flags
|= TYPE_FLAG_UNSIGNED
;
9061 /* We just treat this as an integer and then recognize the
9062 type by name elsewhere. */
9066 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
9067 dwarf_type_encoding_name (encoding
));
9071 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
9072 TYPE_NAME (type
) = name
;
9073 TYPE_TARGET_TYPE (type
) = target_type
;
9075 if (name
&& strcmp (name
, "char") == 0)
9076 TYPE_NOSIGN (type
) = 1;
9078 return set_die_type (die
, type
, cu
);
9081 /* Read the given DW_AT_subrange DIE. */
9083 static struct type
*
9084 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9086 struct type
*base_type
;
9087 struct type
*range_type
;
9088 struct attribute
*attr
;
9092 LONGEST negative_mask
;
9094 base_type
= die_type (die
, cu
);
9095 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
9096 check_typedef (base_type
);
9098 /* The die_type call above may have already set the type for this DIE. */
9099 range_type
= get_die_type (die
, cu
);
9103 if (cu
->language
== language_fortran
)
9105 /* FORTRAN implies a lower bound of 1, if not given. */
9109 /* FIXME: For variable sized arrays either of these could be
9110 a variable rather than a constant value. We'll allow it,
9111 but we don't know how to handle it. */
9112 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
9114 low
= dwarf2_get_attr_constant_value (attr
, 0);
9116 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
9119 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
9121 /* GCC encodes arrays with unspecified or dynamic length
9122 with a DW_FORM_block1 attribute or a reference attribute.
9123 FIXME: GDB does not yet know how to handle dynamic
9124 arrays properly, treat them as arrays with unspecified
9127 FIXME: jimb/2003-09-22: GDB does not really know
9128 how to handle arrays of unspecified length
9129 either; we just represent them as zero-length
9130 arrays. Choose an appropriate upper bound given
9131 the lower bound we've computed above. */
9135 high
= dwarf2_get_attr_constant_value (attr
, 1);
9139 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
9142 int count
= dwarf2_get_attr_constant_value (attr
, 1);
9143 high
= low
+ count
- 1;
9147 /* Unspecified array length. */
9152 /* Dwarf-2 specifications explicitly allows to create subrange types
9153 without specifying a base type.
9154 In that case, the base type must be set to the type of
9155 the lower bound, upper bound or count, in that order, if any of these
9156 three attributes references an object that has a type.
9157 If no base type is found, the Dwarf-2 specifications say that
9158 a signed integer type of size equal to the size of an address should
9160 For the following C code: `extern char gdb_int [];'
9161 GCC produces an empty range DIE.
9162 FIXME: muller/2010-05-28: Possible references to object for low bound,
9163 high bound or count are not yet handled by this code. */
9164 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
9166 struct objfile
*objfile
= cu
->objfile
;
9167 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9168 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
9169 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
9171 /* Test "int", "long int", and "long long int" objfile types,
9172 and select the first one having a size above or equal to the
9173 architecture address size. */
9174 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
9175 base_type
= int_type
;
9178 int_type
= objfile_type (objfile
)->builtin_long
;
9179 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
9180 base_type
= int_type
;
9183 int_type
= objfile_type (objfile
)->builtin_long_long
;
9184 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
9185 base_type
= int_type
;
9191 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
9192 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
9193 low
|= negative_mask
;
9194 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
9195 high
|= negative_mask
;
9197 range_type
= create_range_type (NULL
, base_type
, low
, high
);
9199 /* Mark arrays with dynamic length at least as an array of unspecified
9200 length. GDB could check the boundary but before it gets implemented at
9201 least allow accessing the array elements. */
9202 if (attr
&& attr_form_is_block (attr
))
9203 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
9205 /* Ada expects an empty array on no boundary attributes. */
9206 if (attr
== NULL
&& cu
->language
!= language_ada
)
9207 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
9209 name
= dwarf2_name (die
, cu
);
9211 TYPE_NAME (range_type
) = name
;
9213 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9215 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
9217 set_die_type (die
, range_type
, cu
);
9219 /* set_die_type should be already done. */
9220 set_descriptive_type (range_type
, die
, cu
);
9225 static struct type
*
9226 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9230 /* For now, we only support the C meaning of an unspecified type: void. */
9232 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
9233 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
9235 return set_die_type (die
, type
, cu
);
9238 /* Trivial hash function for die_info: the hash value of a DIE
9239 is its offset in .debug_info for this objfile. */
9242 die_hash (const void *item
)
9244 const struct die_info
*die
= item
;
9246 return die
->offset
.sect_off
;
9249 /* Trivial comparison function for die_info structures: two DIEs
9250 are equal if they have the same offset. */
9253 die_eq (const void *item_lhs
, const void *item_rhs
)
9255 const struct die_info
*die_lhs
= item_lhs
;
9256 const struct die_info
*die_rhs
= item_rhs
;
9258 return die_lhs
->offset
.sect_off
== die_rhs
->offset
.sect_off
;
9261 /* Read a whole compilation unit into a linked list of dies. */
9263 static struct die_info
*
9264 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
9266 struct die_reader_specs reader_specs
;
9267 int read_abbrevs
= 0;
9268 struct cleanup
*back_to
= NULL
;
9269 struct die_info
*die
;
9271 if (cu
->dwarf2_abbrevs
== NULL
)
9273 dwarf2_read_abbrevs (cu
);
9274 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
9278 gdb_assert (cu
->die_hash
== NULL
);
9280 = htab_create_alloc_ex (cu
->header
.length
/ 12,
9284 &cu
->comp_unit_obstack
,
9285 hashtab_obstack_allocate
,
9286 dummy_obstack_deallocate
);
9288 init_cu_die_reader (&reader_specs
, cu
);
9290 die
= read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
9293 do_cleanups (back_to
);
9298 /* Main entry point for reading a DIE and all children.
9299 Read the DIE and dump it if requested. */
9301 static struct die_info
*
9302 read_die_and_children (const struct die_reader_specs
*reader
,
9304 gdb_byte
**new_info_ptr
,
9305 struct die_info
*parent
)
9307 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
9308 new_info_ptr
, parent
);
9310 if (dwarf2_die_debug
)
9312 fprintf_unfiltered (gdb_stdlog
,
9313 "\nRead die from %s of %s:\n",
9314 (reader
->cu
->per_cu
->debug_types_section
9317 reader
->abfd
->filename
);
9318 dump_die (result
, dwarf2_die_debug
);
9324 /* Read a single die and all its descendents. Set the die's sibling
9325 field to NULL; set other fields in the die correctly, and set all
9326 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
9327 location of the info_ptr after reading all of those dies. PARENT
9328 is the parent of the die in question. */
9330 static struct die_info
*
9331 read_die_and_children_1 (const struct die_reader_specs
*reader
,
9333 gdb_byte
**new_info_ptr
,
9334 struct die_info
*parent
)
9336 struct die_info
*die
;
9340 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
9343 *new_info_ptr
= cur_ptr
;
9346 store_in_ref_table (die
, reader
->cu
);
9349 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
9353 *new_info_ptr
= cur_ptr
;
9356 die
->sibling
= NULL
;
9357 die
->parent
= parent
;
9361 /* Read a die, all of its descendents, and all of its siblings; set
9362 all of the fields of all of the dies correctly. Arguments are as
9363 in read_die_and_children. */
9365 static struct die_info
*
9366 read_die_and_siblings (const struct die_reader_specs
*reader
,
9368 gdb_byte
**new_info_ptr
,
9369 struct die_info
*parent
)
9371 struct die_info
*first_die
, *last_sibling
;
9375 first_die
= last_sibling
= NULL
;
9379 struct die_info
*die
9380 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
9384 *new_info_ptr
= cur_ptr
;
9391 last_sibling
->sibling
= die
;
9397 /* Read the die from the .debug_info section buffer. Set DIEP to
9398 point to a newly allocated die with its information, except for its
9399 child, sibling, and parent fields. Set HAS_CHILDREN to tell
9400 whether the die has children or not. */
9403 read_full_die (const struct die_reader_specs
*reader
,
9404 struct die_info
**diep
, gdb_byte
*info_ptr
,
9407 unsigned int abbrev_number
, bytes_read
, i
;
9409 struct abbrev_info
*abbrev
;
9410 struct die_info
*die
;
9411 struct dwarf2_cu
*cu
= reader
->cu
;
9412 bfd
*abfd
= reader
->abfd
;
9414 offset
.sect_off
= info_ptr
- reader
->buffer
;
9415 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9416 info_ptr
+= bytes_read
;
9424 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
9426 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
9428 bfd_get_filename (abfd
));
9430 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
9431 die
->offset
= offset
;
9432 die
->tag
= abbrev
->tag
;
9433 die
->abbrev
= abbrev_number
;
9435 die
->num_attrs
= abbrev
->num_attrs
;
9437 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9438 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
9439 abfd
, info_ptr
, cu
);
9442 *has_children
= abbrev
->has_children
;
9446 /* In DWARF version 2, the description of the debugging information is
9447 stored in a separate .debug_abbrev section. Before we read any
9448 dies from a section we read in all abbreviations and install them
9449 in a hash table. This function also sets flags in CU describing
9450 the data found in the abbrev table. */
9453 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
)
9455 bfd
*abfd
= cu
->objfile
->obfd
;
9456 struct comp_unit_head
*cu_header
= &cu
->header
;
9457 gdb_byte
*abbrev_ptr
;
9458 struct abbrev_info
*cur_abbrev
;
9459 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
9460 unsigned int abbrev_form
, hash_number
;
9461 struct attr_abbrev
*cur_attrs
;
9462 unsigned int allocated_attrs
;
9464 /* Initialize dwarf2 abbrevs. */
9465 obstack_init (&cu
->abbrev_obstack
);
9466 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
9468 * sizeof (struct abbrev_info
*)));
9469 memset (cu
->dwarf2_abbrevs
, 0,
9470 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
9472 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
9473 &dwarf2_per_objfile
->abbrev
);
9474 abbrev_ptr
= (dwarf2_per_objfile
->abbrev
.buffer
9475 + cu_header
->abbrev_offset
.sect_off
);
9476 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9477 abbrev_ptr
+= bytes_read
;
9479 allocated_attrs
= ATTR_ALLOC_CHUNK
;
9480 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
9482 /* Loop until we reach an abbrev number of 0. */
9483 while (abbrev_number
)
9485 cur_abbrev
= dwarf_alloc_abbrev (cu
);
9487 /* read in abbrev header */
9488 cur_abbrev
->number
= abbrev_number
;
9489 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9490 abbrev_ptr
+= bytes_read
;
9491 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
9494 /* now read in declarations */
9495 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9496 abbrev_ptr
+= bytes_read
;
9497 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9498 abbrev_ptr
+= bytes_read
;
9501 if (cur_abbrev
->num_attrs
== allocated_attrs
)
9503 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
9505 = xrealloc (cur_attrs
, (allocated_attrs
9506 * sizeof (struct attr_abbrev
)));
9509 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
9510 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
9511 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9512 abbrev_ptr
+= bytes_read
;
9513 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9514 abbrev_ptr
+= bytes_read
;
9517 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
9518 (cur_abbrev
->num_attrs
9519 * sizeof (struct attr_abbrev
)));
9520 memcpy (cur_abbrev
->attrs
, cur_attrs
,
9521 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
9523 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
9524 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
9525 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
9527 /* Get next abbreviation.
9528 Under Irix6 the abbreviations for a compilation unit are not
9529 always properly terminated with an abbrev number of 0.
9530 Exit loop if we encounter an abbreviation which we have
9531 already read (which means we are about to read the abbreviations
9532 for the next compile unit) or if the end of the abbreviation
9533 table is reached. */
9534 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
9535 >= dwarf2_per_objfile
->abbrev
.size
)
9537 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9538 abbrev_ptr
+= bytes_read
;
9539 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
9546 /* Release the memory used by the abbrev table for a compilation unit. */
9549 dwarf2_free_abbrev_table (void *ptr_to_cu
)
9551 struct dwarf2_cu
*cu
= ptr_to_cu
;
9553 obstack_free (&cu
->abbrev_obstack
, NULL
);
9554 cu
->dwarf2_abbrevs
= NULL
;
9557 /* Lookup an abbrev_info structure in the abbrev hash table. */
9559 static struct abbrev_info
*
9560 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
9562 unsigned int hash_number
;
9563 struct abbrev_info
*abbrev
;
9565 hash_number
= number
% ABBREV_HASH_SIZE
;
9566 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
9570 if (abbrev
->number
== number
)
9573 abbrev
= abbrev
->next
;
9578 /* Returns nonzero if TAG represents a type that we might generate a partial
9582 is_type_tag_for_partial (int tag
)
9587 /* Some types that would be reasonable to generate partial symbols for,
9588 that we don't at present. */
9589 case DW_TAG_array_type
:
9590 case DW_TAG_file_type
:
9591 case DW_TAG_ptr_to_member_type
:
9592 case DW_TAG_set_type
:
9593 case DW_TAG_string_type
:
9594 case DW_TAG_subroutine_type
:
9596 case DW_TAG_base_type
:
9597 case DW_TAG_class_type
:
9598 case DW_TAG_interface_type
:
9599 case DW_TAG_enumeration_type
:
9600 case DW_TAG_structure_type
:
9601 case DW_TAG_subrange_type
:
9602 case DW_TAG_typedef
:
9603 case DW_TAG_union_type
:
9610 /* Load all DIEs that are interesting for partial symbols into memory. */
9612 static struct partial_die_info
*
9613 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9614 int building_psymtab
, struct dwarf2_cu
*cu
)
9616 struct objfile
*objfile
= cu
->objfile
;
9617 struct partial_die_info
*part_die
;
9618 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
9619 struct abbrev_info
*abbrev
;
9620 unsigned int bytes_read
;
9621 unsigned int load_all
= 0;
9622 int nesting_level
= 1;
9627 gdb_assert (cu
->per_cu
!= NULL
);
9628 if (cu
->per_cu
->load_all_dies
)
9632 = htab_create_alloc_ex (cu
->header
.length
/ 12,
9636 &cu
->comp_unit_obstack
,
9637 hashtab_obstack_allocate
,
9638 dummy_obstack_deallocate
);
9640 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9641 sizeof (struct partial_die_info
));
9645 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
9647 /* A NULL abbrev means the end of a series of children. */
9650 if (--nesting_level
== 0)
9652 /* PART_DIE was probably the last thing allocated on the
9653 comp_unit_obstack, so we could call obstack_free
9654 here. We don't do that because the waste is small,
9655 and will be cleaned up when we're done with this
9656 compilation unit. This way, we're also more robust
9657 against other users of the comp_unit_obstack. */
9660 info_ptr
+= bytes_read
;
9661 last_die
= parent_die
;
9662 parent_die
= parent_die
->die_parent
;
9666 /* Check for template arguments. We never save these; if
9667 they're seen, we just mark the parent, and go on our way. */
9668 if (parent_die
!= NULL
9669 && cu
->language
== language_cplus
9670 && (abbrev
->tag
== DW_TAG_template_type_param
9671 || abbrev
->tag
== DW_TAG_template_value_param
))
9673 parent_die
->has_template_arguments
= 1;
9677 /* We don't need a partial DIE for the template argument. */
9678 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
,
9684 /* We only recurse into c++ subprograms looking for template arguments.
9685 Skip their other children. */
9687 && cu
->language
== language_cplus
9688 && parent_die
!= NULL
9689 && parent_die
->tag
== DW_TAG_subprogram
)
9691 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
9695 /* Check whether this DIE is interesting enough to save. Normally
9696 we would not be interested in members here, but there may be
9697 later variables referencing them via DW_AT_specification (for
9700 && !is_type_tag_for_partial (abbrev
->tag
)
9701 && abbrev
->tag
!= DW_TAG_constant
9702 && abbrev
->tag
!= DW_TAG_enumerator
9703 && abbrev
->tag
!= DW_TAG_subprogram
9704 && abbrev
->tag
!= DW_TAG_lexical_block
9705 && abbrev
->tag
!= DW_TAG_variable
9706 && abbrev
->tag
!= DW_TAG_namespace
9707 && abbrev
->tag
!= DW_TAG_module
9708 && abbrev
->tag
!= DW_TAG_member
)
9710 /* Otherwise we skip to the next sibling, if any. */
9711 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
9715 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
9716 buffer
, info_ptr
, cu
);
9718 /* This two-pass algorithm for processing partial symbols has a
9719 high cost in cache pressure. Thus, handle some simple cases
9720 here which cover the majority of C partial symbols. DIEs
9721 which neither have specification tags in them, nor could have
9722 specification tags elsewhere pointing at them, can simply be
9723 processed and discarded.
9725 This segment is also optional; scan_partial_symbols and
9726 add_partial_symbol will handle these DIEs if we chain
9727 them in normally. When compilers which do not emit large
9728 quantities of duplicate debug information are more common,
9729 this code can probably be removed. */
9731 /* Any complete simple types at the top level (pretty much all
9732 of them, for a language without namespaces), can be processed
9734 if (parent_die
== NULL
9735 && part_die
->has_specification
== 0
9736 && part_die
->is_declaration
== 0
9737 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
9738 || part_die
->tag
== DW_TAG_base_type
9739 || part_die
->tag
== DW_TAG_subrange_type
))
9741 if (building_psymtab
&& part_die
->name
!= NULL
)
9742 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9743 VAR_DOMAIN
, LOC_TYPEDEF
,
9744 &objfile
->static_psymbols
,
9745 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
9746 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9750 /* The exception for DW_TAG_typedef with has_children above is
9751 a workaround of GCC PR debug/47510. In the case of this complaint
9752 type_name_no_tag_or_error will error on such types later.
9754 GDB skipped children of DW_TAG_typedef by the shortcut above and then
9755 it could not find the child DIEs referenced later, this is checked
9756 above. In correct DWARF DW_TAG_typedef should have no children. */
9758 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
9759 complaint (&symfile_complaints
,
9760 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
9761 "- DIE at 0x%x [in module %s]"),
9762 part_die
->offset
.sect_off
, objfile
->name
);
9764 /* If we're at the second level, and we're an enumerator, and
9765 our parent has no specification (meaning possibly lives in a
9766 namespace elsewhere), then we can add the partial symbol now
9767 instead of queueing it. */
9768 if (part_die
->tag
== DW_TAG_enumerator
9769 && parent_die
!= NULL
9770 && parent_die
->die_parent
== NULL
9771 && parent_die
->tag
== DW_TAG_enumeration_type
9772 && parent_die
->has_specification
== 0)
9774 if (part_die
->name
== NULL
)
9775 complaint (&symfile_complaints
,
9776 _("malformed enumerator DIE ignored"));
9777 else if (building_psymtab
)
9778 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9779 VAR_DOMAIN
, LOC_CONST
,
9780 (cu
->language
== language_cplus
9781 || cu
->language
== language_java
)
9782 ? &objfile
->global_psymbols
9783 : &objfile
->static_psymbols
,
9784 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
9786 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9790 /* We'll save this DIE so link it in. */
9791 part_die
->die_parent
= parent_die
;
9792 part_die
->die_sibling
= NULL
;
9793 part_die
->die_child
= NULL
;
9795 if (last_die
&& last_die
== parent_die
)
9796 last_die
->die_child
= part_die
;
9798 last_die
->die_sibling
= part_die
;
9800 last_die
= part_die
;
9802 if (first_die
== NULL
)
9803 first_die
= part_die
;
9805 /* Maybe add the DIE to the hash table. Not all DIEs that we
9806 find interesting need to be in the hash table, because we
9807 also have the parent/sibling/child chains; only those that we
9808 might refer to by offset later during partial symbol reading.
9810 For now this means things that might have be the target of a
9811 DW_AT_specification, DW_AT_abstract_origin, or
9812 DW_AT_extension. DW_AT_extension will refer only to
9813 namespaces; DW_AT_abstract_origin refers to functions (and
9814 many things under the function DIE, but we do not recurse
9815 into function DIEs during partial symbol reading) and
9816 possibly variables as well; DW_AT_specification refers to
9817 declarations. Declarations ought to have the DW_AT_declaration
9818 flag. It happens that GCC forgets to put it in sometimes, but
9819 only for functions, not for types.
9821 Adding more things than necessary to the hash table is harmless
9822 except for the performance cost. Adding too few will result in
9823 wasted time in find_partial_die, when we reread the compilation
9824 unit with load_all_dies set. */
9827 || abbrev
->tag
== DW_TAG_constant
9828 || abbrev
->tag
== DW_TAG_subprogram
9829 || abbrev
->tag
== DW_TAG_variable
9830 || abbrev
->tag
== DW_TAG_namespace
9831 || part_die
->is_declaration
)
9835 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
9836 part_die
->offset
.sect_off
, INSERT
);
9840 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9841 sizeof (struct partial_die_info
));
9843 /* For some DIEs we want to follow their children (if any). For C
9844 we have no reason to follow the children of structures; for other
9845 languages we have to, so that we can get at method physnames
9846 to infer fully qualified class names, for DW_AT_specification,
9847 and for C++ template arguments. For C++, we also look one level
9848 inside functions to find template arguments (if the name of the
9849 function does not already contain the template arguments).
9851 For Ada, we need to scan the children of subprograms and lexical
9852 blocks as well because Ada allows the definition of nested
9853 entities that could be interesting for the debugger, such as
9854 nested subprograms for instance. */
9855 if (last_die
->has_children
9857 || last_die
->tag
== DW_TAG_namespace
9858 || last_die
->tag
== DW_TAG_module
9859 || last_die
->tag
== DW_TAG_enumeration_type
9860 || (cu
->language
== language_cplus
9861 && last_die
->tag
== DW_TAG_subprogram
9862 && (last_die
->name
== NULL
9863 || strchr (last_die
->name
, '<') == NULL
))
9864 || (cu
->language
!= language_c
9865 && (last_die
->tag
== DW_TAG_class_type
9866 || last_die
->tag
== DW_TAG_interface_type
9867 || last_die
->tag
== DW_TAG_structure_type
9868 || last_die
->tag
== DW_TAG_union_type
))
9869 || (cu
->language
== language_ada
9870 && (last_die
->tag
== DW_TAG_subprogram
9871 || last_die
->tag
== DW_TAG_lexical_block
))))
9874 parent_die
= last_die
;
9878 /* Otherwise we skip to the next sibling, if any. */
9879 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
9881 /* Back to the top, do it again. */
9885 /* Read a minimal amount of information into the minimal die structure. */
9888 read_partial_die (struct partial_die_info
*part_die
,
9889 struct abbrev_info
*abbrev
,
9890 unsigned int abbrev_len
, bfd
*abfd
,
9891 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9892 struct dwarf2_cu
*cu
)
9894 struct objfile
*objfile
= cu
->objfile
;
9896 struct attribute attr
;
9897 int has_low_pc_attr
= 0;
9898 int has_high_pc_attr
= 0;
9900 memset (part_die
, 0, sizeof (struct partial_die_info
));
9902 part_die
->offset
.sect_off
= info_ptr
- buffer
;
9904 info_ptr
+= abbrev_len
;
9909 part_die
->tag
= abbrev
->tag
;
9910 part_die
->has_children
= abbrev
->has_children
;
9912 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9914 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
9916 /* Store the data if it is of an attribute we want to keep in a
9917 partial symbol table. */
9921 switch (part_die
->tag
)
9923 case DW_TAG_compile_unit
:
9924 case DW_TAG_type_unit
:
9925 /* Compilation units have a DW_AT_name that is a filename, not
9926 a source language identifier. */
9927 case DW_TAG_enumeration_type
:
9928 case DW_TAG_enumerator
:
9929 /* These tags always have simple identifiers already; no need
9930 to canonicalize them. */
9931 part_die
->name
= DW_STRING (&attr
);
9935 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
9936 &objfile
->objfile_obstack
);
9940 case DW_AT_linkage_name
:
9941 case DW_AT_MIPS_linkage_name
:
9942 /* Note that both forms of linkage name might appear. We
9943 assume they will be the same, and we only store the last
9945 if (cu
->language
== language_ada
)
9946 part_die
->name
= DW_STRING (&attr
);
9947 part_die
->linkage_name
= DW_STRING (&attr
);
9950 has_low_pc_attr
= 1;
9951 part_die
->lowpc
= DW_ADDR (&attr
);
9954 has_high_pc_attr
= 1;
9955 part_die
->highpc
= DW_ADDR (&attr
);
9957 case DW_AT_location
:
9958 /* Support the .debug_loc offsets. */
9959 if (attr_form_is_block (&attr
))
9961 part_die
->locdesc
= DW_BLOCK (&attr
);
9963 else if (attr_form_is_section_offset (&attr
))
9965 dwarf2_complex_location_expr_complaint ();
9969 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9970 "partial symbol information");
9973 case DW_AT_external
:
9974 part_die
->is_external
= DW_UNSND (&attr
);
9976 case DW_AT_declaration
:
9977 part_die
->is_declaration
= DW_UNSND (&attr
);
9980 part_die
->has_type
= 1;
9982 case DW_AT_abstract_origin
:
9983 case DW_AT_specification
:
9984 case DW_AT_extension
:
9985 part_die
->has_specification
= 1;
9986 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
9989 /* Ignore absolute siblings, they might point outside of
9990 the current compile unit. */
9991 if (attr
.form
== DW_FORM_ref_addr
)
9992 complaint (&symfile_complaints
,
9993 _("ignoring absolute DW_AT_sibling"));
9995 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
9997 case DW_AT_byte_size
:
9998 part_die
->has_byte_size
= 1;
10000 case DW_AT_calling_convention
:
10001 /* DWARF doesn't provide a way to identify a program's source-level
10002 entry point. DW_AT_calling_convention attributes are only meant
10003 to describe functions' calling conventions.
10005 However, because it's a necessary piece of information in
10006 Fortran, and because DW_CC_program is the only piece of debugging
10007 information whose definition refers to a 'main program' at all,
10008 several compilers have begun marking Fortran main programs with
10009 DW_CC_program --- even when those functions use the standard
10010 calling conventions.
10012 So until DWARF specifies a way to provide this information and
10013 compilers pick up the new representation, we'll support this
10015 if (DW_UNSND (&attr
) == DW_CC_program
10016 && cu
->language
== language_fortran
)
10018 set_main_name (part_die
->name
);
10020 /* As this DIE has a static linkage the name would be difficult
10021 to look up later. */
10022 language_of_main
= language_fortran
;
10026 if (DW_UNSND (&attr
) == DW_INL_inlined
10027 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
10028 part_die
->may_be_inlined
= 1;
10035 if (has_low_pc_attr
&& has_high_pc_attr
)
10037 /* When using the GNU linker, .gnu.linkonce. sections are used to
10038 eliminate duplicate copies of functions and vtables and such.
10039 The linker will arbitrarily choose one and discard the others.
10040 The AT_*_pc values for such functions refer to local labels in
10041 these sections. If the section from that file was discarded, the
10042 labels are not in the output, so the relocs get a value of 0.
10043 If this is a discarded function, mark the pc bounds as invalid,
10044 so that GDB will ignore it. */
10045 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
10047 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10049 complaint (&symfile_complaints
,
10050 _("DW_AT_low_pc %s is zero "
10051 "for DIE at 0x%x [in module %s]"),
10052 paddress (gdbarch
, part_die
->lowpc
),
10053 part_die
->offset
.sect_off
, objfile
->name
);
10055 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
10056 else if (part_die
->lowpc
>= part_die
->highpc
)
10058 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10060 complaint (&symfile_complaints
,
10061 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
10062 "for DIE at 0x%x [in module %s]"),
10063 paddress (gdbarch
, part_die
->lowpc
),
10064 paddress (gdbarch
, part_die
->highpc
),
10065 part_die
->offset
.sect_off
, objfile
->name
);
10068 part_die
->has_pc_info
= 1;
10074 /* Find a cached partial DIE at OFFSET in CU. */
10076 static struct partial_die_info
*
10077 find_partial_die_in_comp_unit (sect_offset offset
, struct dwarf2_cu
*cu
)
10079 struct partial_die_info
*lookup_die
= NULL
;
10080 struct partial_die_info part_die
;
10082 part_die
.offset
= offset
;
10083 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
,
10089 /* Find a partial DIE at OFFSET, which may or may not be in CU,
10090 except in the case of .debug_types DIEs which do not reference
10091 outside their CU (they do however referencing other types via
10092 DW_FORM_ref_sig8). */
10094 static struct partial_die_info
*
10095 find_partial_die (sect_offset offset
, struct dwarf2_cu
*cu
)
10097 struct objfile
*objfile
= cu
->objfile
;
10098 struct dwarf2_per_cu_data
*per_cu
= NULL
;
10099 struct partial_die_info
*pd
= NULL
;
10101 if (offset_in_cu_p (&cu
->header
, offset
))
10103 pd
= find_partial_die_in_comp_unit (offset
, cu
);
10106 /* We missed recording what we needed.
10107 Load all dies and try again. */
10108 per_cu
= cu
->per_cu
;
10112 /* TUs don't reference other CUs/TUs (except via type signatures). */
10113 if (cu
->per_cu
->debug_types_section
)
10115 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
10116 " external reference to offset 0x%lx [in module %s].\n"),
10117 (long) cu
->header
.offset
.sect_off
, (long) offset
.sect_off
,
10118 bfd_get_filename (objfile
->obfd
));
10120 per_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
10122 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
10123 load_partial_comp_unit (per_cu
);
10125 per_cu
->cu
->last_used
= 0;
10126 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
10129 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
10131 struct cleanup
*back_to
;
10132 struct partial_die_info comp_unit_die
;
10133 struct abbrev_info
*abbrev
;
10134 unsigned int bytes_read
;
10136 struct dwarf2_section_info
*sec
;
10138 per_cu
->load_all_dies
= 1;
10140 if (per_cu
->debug_types_section
)
10141 sec
= per_cu
->debug_types_section
;
10143 sec
= &dwarf2_per_objfile
->info
;
10145 /* Re-read the DIEs, this time reading all of them.
10146 NOTE: We don't discard the previous set of DIEs.
10147 This doesn't happen very often so it's (hopefully) not a problem. */
10148 back_to
= make_cleanup (null_cleanup
, 0);
10149 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
10151 dwarf2_read_abbrevs (per_cu
->cu
);
10152 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
10154 info_ptr
= (sec
->buffer
10155 + per_cu
->cu
->header
.offset
.sect_off
10156 + per_cu
->cu
->header
.first_die_offset
.cu_off
);
10157 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
10158 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
10159 objfile
->obfd
, sec
->buffer
, info_ptr
,
10161 if (comp_unit_die
.has_children
)
10162 load_partial_dies (objfile
->obfd
, sec
->buffer
, info_ptr
, 0,
10164 do_cleanups (back_to
);
10166 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
10170 internal_error (__FILE__
, __LINE__
,
10171 _("could not find partial DIE 0x%x "
10172 "in cache [from module %s]\n"),
10173 offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
10177 /* See if we can figure out if the class lives in a namespace. We do
10178 this by looking for a member function; its demangled name will
10179 contain namespace info, if there is any. */
10182 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
10183 struct dwarf2_cu
*cu
)
10185 /* NOTE: carlton/2003-10-07: Getting the info this way changes
10186 what template types look like, because the demangler
10187 frequently doesn't give the same name as the debug info. We
10188 could fix this by only using the demangled name to get the
10189 prefix (but see comment in read_structure_type). */
10191 struct partial_die_info
*real_pdi
;
10192 struct partial_die_info
*child_pdi
;
10194 /* If this DIE (this DIE's specification, if any) has a parent, then
10195 we should not do this. We'll prepend the parent's fully qualified
10196 name when we create the partial symbol. */
10198 real_pdi
= struct_pdi
;
10199 while (real_pdi
->has_specification
)
10200 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
10202 if (real_pdi
->die_parent
!= NULL
)
10205 for (child_pdi
= struct_pdi
->die_child
;
10207 child_pdi
= child_pdi
->die_sibling
)
10209 if (child_pdi
->tag
== DW_TAG_subprogram
10210 && child_pdi
->linkage_name
!= NULL
)
10212 char *actual_class_name
10213 = language_class_name_from_physname (cu
->language_defn
,
10214 child_pdi
->linkage_name
);
10215 if (actual_class_name
!= NULL
)
10218 = obsavestring (actual_class_name
,
10219 strlen (actual_class_name
),
10220 &cu
->objfile
->objfile_obstack
);
10221 xfree (actual_class_name
);
10228 /* Adjust PART_DIE before generating a symbol for it. This function
10229 may set the is_external flag or change the DIE's name. */
10232 fixup_partial_die (struct partial_die_info
*part_die
,
10233 struct dwarf2_cu
*cu
)
10235 /* Once we've fixed up a die, there's no point in doing so again.
10236 This also avoids a memory leak if we were to call
10237 guess_partial_die_structure_name multiple times. */
10238 if (part_die
->fixup_called
)
10241 /* If we found a reference attribute and the DIE has no name, try
10242 to find a name in the referred to DIE. */
10244 if (part_die
->name
== NULL
&& part_die
->has_specification
)
10246 struct partial_die_info
*spec_die
;
10248 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
10250 fixup_partial_die (spec_die
, cu
);
10252 if (spec_die
->name
)
10254 part_die
->name
= spec_die
->name
;
10256 /* Copy DW_AT_external attribute if it is set. */
10257 if (spec_die
->is_external
)
10258 part_die
->is_external
= spec_die
->is_external
;
10262 /* Set default names for some unnamed DIEs. */
10264 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
10265 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
10267 /* If there is no parent die to provide a namespace, and there are
10268 children, see if we can determine the namespace from their linkage
10270 if (cu
->language
== language_cplus
10271 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
10272 && part_die
->die_parent
== NULL
10273 && part_die
->has_children
10274 && (part_die
->tag
== DW_TAG_class_type
10275 || part_die
->tag
== DW_TAG_structure_type
10276 || part_die
->tag
== DW_TAG_union_type
))
10277 guess_partial_die_structure_name (part_die
, cu
);
10279 /* GCC might emit a nameless struct or union that has a linkage
10280 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
10281 if (part_die
->name
== NULL
10282 && (part_die
->tag
== DW_TAG_class_type
10283 || part_die
->tag
== DW_TAG_interface_type
10284 || part_die
->tag
== DW_TAG_structure_type
10285 || part_die
->tag
== DW_TAG_union_type
)
10286 && part_die
->linkage_name
!= NULL
)
10290 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
10295 /* Strip any leading namespaces/classes, keep only the base name.
10296 DW_AT_name for named DIEs does not contain the prefixes. */
10297 base
= strrchr (demangled
, ':');
10298 if (base
&& base
> demangled
&& base
[-1] == ':')
10303 part_die
->name
= obsavestring (base
, strlen (base
),
10304 &cu
->objfile
->objfile_obstack
);
10309 part_die
->fixup_called
= 1;
10312 /* Read an attribute value described by an attribute form. */
10315 read_attribute_value (struct attribute
*attr
, unsigned form
,
10316 bfd
*abfd
, gdb_byte
*info_ptr
,
10317 struct dwarf2_cu
*cu
)
10319 struct comp_unit_head
*cu_header
= &cu
->header
;
10320 unsigned int bytes_read
;
10321 struct dwarf_block
*blk
;
10326 case DW_FORM_ref_addr
:
10327 if (cu
->header
.version
== 2)
10328 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
10330 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
10331 &cu
->header
, &bytes_read
);
10332 info_ptr
+= bytes_read
;
10335 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
10336 info_ptr
+= bytes_read
;
10338 case DW_FORM_block2
:
10339 blk
= dwarf_alloc_block (cu
);
10340 blk
->size
= read_2_bytes (abfd
, info_ptr
);
10342 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10343 info_ptr
+= blk
->size
;
10344 DW_BLOCK (attr
) = blk
;
10346 case DW_FORM_block4
:
10347 blk
= dwarf_alloc_block (cu
);
10348 blk
->size
= read_4_bytes (abfd
, info_ptr
);
10350 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10351 info_ptr
+= blk
->size
;
10352 DW_BLOCK (attr
) = blk
;
10354 case DW_FORM_data2
:
10355 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
10358 case DW_FORM_data4
:
10359 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
10362 case DW_FORM_data8
:
10363 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
10366 case DW_FORM_sec_offset
:
10367 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
10368 info_ptr
+= bytes_read
;
10370 case DW_FORM_string
:
10371 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
10372 DW_STRING_IS_CANONICAL (attr
) = 0;
10373 info_ptr
+= bytes_read
;
10376 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
10378 DW_STRING_IS_CANONICAL (attr
) = 0;
10379 info_ptr
+= bytes_read
;
10381 case DW_FORM_exprloc
:
10382 case DW_FORM_block
:
10383 blk
= dwarf_alloc_block (cu
);
10384 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10385 info_ptr
+= bytes_read
;
10386 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10387 info_ptr
+= blk
->size
;
10388 DW_BLOCK (attr
) = blk
;
10390 case DW_FORM_block1
:
10391 blk
= dwarf_alloc_block (cu
);
10392 blk
->size
= read_1_byte (abfd
, info_ptr
);
10394 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10395 info_ptr
+= blk
->size
;
10396 DW_BLOCK (attr
) = blk
;
10398 case DW_FORM_data1
:
10399 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
10403 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
10406 case DW_FORM_flag_present
:
10407 DW_UNSND (attr
) = 1;
10409 case DW_FORM_sdata
:
10410 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
10411 info_ptr
+= bytes_read
;
10413 case DW_FORM_udata
:
10414 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10415 info_ptr
+= bytes_read
;
10418 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
10419 + read_1_byte (abfd
, info_ptr
));
10423 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
10424 + read_2_bytes (abfd
, info_ptr
));
10428 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
10429 + read_4_bytes (abfd
, info_ptr
));
10433 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
10434 + read_8_bytes (abfd
, info_ptr
));
10437 case DW_FORM_ref_sig8
:
10438 /* Convert the signature to something we can record in DW_UNSND
10440 NOTE: This is NULL if the type wasn't found. */
10441 DW_SIGNATURED_TYPE (attr
) =
10442 lookup_signatured_type (read_8_bytes (abfd
, info_ptr
));
10445 case DW_FORM_ref_udata
:
10446 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
10447 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
10448 info_ptr
+= bytes_read
;
10450 case DW_FORM_indirect
:
10451 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10452 info_ptr
+= bytes_read
;
10453 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
10456 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
10457 dwarf_form_name (form
),
10458 bfd_get_filename (abfd
));
10461 /* We have seen instances where the compiler tried to emit a byte
10462 size attribute of -1 which ended up being encoded as an unsigned
10463 0xffffffff. Although 0xffffffff is technically a valid size value,
10464 an object of this size seems pretty unlikely so we can relatively
10465 safely treat these cases as if the size attribute was invalid and
10466 treat them as zero by default. */
10467 if (attr
->name
== DW_AT_byte_size
10468 && form
== DW_FORM_data4
10469 && DW_UNSND (attr
) >= 0xffffffff)
10472 (&symfile_complaints
,
10473 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
10474 hex_string (DW_UNSND (attr
)));
10475 DW_UNSND (attr
) = 0;
10481 /* Read an attribute described by an abbreviated attribute. */
10484 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
10485 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
10487 attr
->name
= abbrev
->name
;
10488 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
10491 /* Read dwarf information from a buffer. */
10493 static unsigned int
10494 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
10496 return bfd_get_8 (abfd
, buf
);
10500 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
10502 return bfd_get_signed_8 (abfd
, buf
);
10505 static unsigned int
10506 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
10508 return bfd_get_16 (abfd
, buf
);
10512 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
10514 return bfd_get_signed_16 (abfd
, buf
);
10517 static unsigned int
10518 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
10520 return bfd_get_32 (abfd
, buf
);
10524 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
10526 return bfd_get_signed_32 (abfd
, buf
);
10530 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
10532 return bfd_get_64 (abfd
, buf
);
10536 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
10537 unsigned int *bytes_read
)
10539 struct comp_unit_head
*cu_header
= &cu
->header
;
10540 CORE_ADDR retval
= 0;
10542 if (cu_header
->signed_addr_p
)
10544 switch (cu_header
->addr_size
)
10547 retval
= bfd_get_signed_16 (abfd
, buf
);
10550 retval
= bfd_get_signed_32 (abfd
, buf
);
10553 retval
= bfd_get_signed_64 (abfd
, buf
);
10556 internal_error (__FILE__
, __LINE__
,
10557 _("read_address: bad switch, signed [in module %s]"),
10558 bfd_get_filename (abfd
));
10563 switch (cu_header
->addr_size
)
10566 retval
= bfd_get_16 (abfd
, buf
);
10569 retval
= bfd_get_32 (abfd
, buf
);
10572 retval
= bfd_get_64 (abfd
, buf
);
10575 internal_error (__FILE__
, __LINE__
,
10576 _("read_address: bad switch, "
10577 "unsigned [in module %s]"),
10578 bfd_get_filename (abfd
));
10582 *bytes_read
= cu_header
->addr_size
;
10586 /* Read the initial length from a section. The (draft) DWARF 3
10587 specification allows the initial length to take up either 4 bytes
10588 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
10589 bytes describe the length and all offsets will be 8 bytes in length
10592 An older, non-standard 64-bit format is also handled by this
10593 function. The older format in question stores the initial length
10594 as an 8-byte quantity without an escape value. Lengths greater
10595 than 2^32 aren't very common which means that the initial 4 bytes
10596 is almost always zero. Since a length value of zero doesn't make
10597 sense for the 32-bit format, this initial zero can be considered to
10598 be an escape value which indicates the presence of the older 64-bit
10599 format. As written, the code can't detect (old format) lengths
10600 greater than 4GB. If it becomes necessary to handle lengths
10601 somewhat larger than 4GB, we could allow other small values (such
10602 as the non-sensical values of 1, 2, and 3) to also be used as
10603 escape values indicating the presence of the old format.
10605 The value returned via bytes_read should be used to increment the
10606 relevant pointer after calling read_initial_length().
10608 [ Note: read_initial_length() and read_offset() are based on the
10609 document entitled "DWARF Debugging Information Format", revision
10610 3, draft 8, dated November 19, 2001. This document was obtained
10613 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
10615 This document is only a draft and is subject to change. (So beware.)
10617 Details regarding the older, non-standard 64-bit format were
10618 determined empirically by examining 64-bit ELF files produced by
10619 the SGI toolchain on an IRIX 6.5 machine.
10621 - Kevin, July 16, 2002
10625 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
10627 LONGEST length
= bfd_get_32 (abfd
, buf
);
10629 if (length
== 0xffffffff)
10631 length
= bfd_get_64 (abfd
, buf
+ 4);
10634 else if (length
== 0)
10636 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
10637 length
= bfd_get_64 (abfd
, buf
);
10648 /* Cover function for read_initial_length.
10649 Returns the length of the object at BUF, and stores the size of the
10650 initial length in *BYTES_READ and stores the size that offsets will be in
10652 If the initial length size is not equivalent to that specified in
10653 CU_HEADER then issue a complaint.
10654 This is useful when reading non-comp-unit headers. */
10657 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
10658 const struct comp_unit_head
*cu_header
,
10659 unsigned int *bytes_read
,
10660 unsigned int *offset_size
)
10662 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
10664 gdb_assert (cu_header
->initial_length_size
== 4
10665 || cu_header
->initial_length_size
== 8
10666 || cu_header
->initial_length_size
== 12);
10668 if (cu_header
->initial_length_size
!= *bytes_read
)
10669 complaint (&symfile_complaints
,
10670 _("intermixed 32-bit and 64-bit DWARF sections"));
10672 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
10676 /* Read an offset from the data stream. The size of the offset is
10677 given by cu_header->offset_size. */
10680 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
10681 unsigned int *bytes_read
)
10683 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
10685 *bytes_read
= cu_header
->offset_size
;
10689 /* Read an offset from the data stream. */
10692 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
10694 LONGEST retval
= 0;
10696 switch (offset_size
)
10699 retval
= bfd_get_32 (abfd
, buf
);
10702 retval
= bfd_get_64 (abfd
, buf
);
10705 internal_error (__FILE__
, __LINE__
,
10706 _("read_offset_1: bad switch [in module %s]"),
10707 bfd_get_filename (abfd
));
10714 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
10716 /* If the size of a host char is 8 bits, we can return a pointer
10717 to the buffer, otherwise we have to copy the data to a buffer
10718 allocated on the temporary obstack. */
10719 gdb_assert (HOST_CHAR_BIT
== 8);
10724 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10726 /* If the size of a host char is 8 bits, we can return a pointer
10727 to the string, otherwise we have to copy the string to a buffer
10728 allocated on the temporary obstack. */
10729 gdb_assert (HOST_CHAR_BIT
== 8);
10732 *bytes_read_ptr
= 1;
10735 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
10736 return (char *) buf
;
10740 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
10742 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
10743 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
10744 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
10745 bfd_get_filename (abfd
));
10746 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
10747 error (_("DW_FORM_strp pointing outside of "
10748 ".debug_str section [in module %s]"),
10749 bfd_get_filename (abfd
));
10750 gdb_assert (HOST_CHAR_BIT
== 8);
10751 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
10753 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
10757 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
10758 const struct comp_unit_head
*cu_header
,
10759 unsigned int *bytes_read_ptr
)
10761 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
10763 return read_indirect_string_at_offset (abfd
, str_offset
);
10767 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10770 unsigned int num_read
;
10772 unsigned char byte
;
10780 byte
= bfd_get_8 (abfd
, buf
);
10783 result
|= ((ULONGEST
) (byte
& 127) << shift
);
10784 if ((byte
& 128) == 0)
10790 *bytes_read_ptr
= num_read
;
10795 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10798 int i
, shift
, num_read
;
10799 unsigned char byte
;
10807 byte
= bfd_get_8 (abfd
, buf
);
10810 result
|= ((LONGEST
) (byte
& 127) << shift
);
10812 if ((byte
& 128) == 0)
10817 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
10818 result
|= -(((LONGEST
) 1) << shift
);
10819 *bytes_read_ptr
= num_read
;
10823 /* Return a pointer to just past the end of an LEB128 number in BUF. */
10826 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
10832 byte
= bfd_get_8 (abfd
, buf
);
10834 if ((byte
& 128) == 0)
10840 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
10847 cu
->language
= language_c
;
10849 case DW_LANG_C_plus_plus
:
10850 cu
->language
= language_cplus
;
10853 cu
->language
= language_d
;
10855 case DW_LANG_Fortran77
:
10856 case DW_LANG_Fortran90
:
10857 case DW_LANG_Fortran95
:
10858 cu
->language
= language_fortran
;
10861 cu
->language
= language_go
;
10863 case DW_LANG_Mips_Assembler
:
10864 cu
->language
= language_asm
;
10867 cu
->language
= language_java
;
10869 case DW_LANG_Ada83
:
10870 case DW_LANG_Ada95
:
10871 cu
->language
= language_ada
;
10873 case DW_LANG_Modula2
:
10874 cu
->language
= language_m2
;
10876 case DW_LANG_Pascal83
:
10877 cu
->language
= language_pascal
;
10880 cu
->language
= language_objc
;
10882 case DW_LANG_Cobol74
:
10883 case DW_LANG_Cobol85
:
10885 cu
->language
= language_minimal
;
10888 cu
->language_defn
= language_def (cu
->language
);
10891 /* Return the named attribute or NULL if not there. */
10893 static struct attribute
*
10894 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
10899 struct attribute
*spec
= NULL
;
10901 for (i
= 0; i
< die
->num_attrs
; ++i
)
10903 if (die
->attrs
[i
].name
== name
)
10904 return &die
->attrs
[i
];
10905 if (die
->attrs
[i
].name
== DW_AT_specification
10906 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
10907 spec
= &die
->attrs
[i
];
10913 die
= follow_die_ref (die
, spec
, &cu
);
10919 /* Return the named attribute or NULL if not there,
10920 but do not follow DW_AT_specification, etc.
10921 This is for use in contexts where we're reading .debug_types dies.
10922 Following DW_AT_specification, DW_AT_abstract_origin will take us
10923 back up the chain, and we want to go down. */
10925 static struct attribute
*
10926 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
10927 struct dwarf2_cu
*cu
)
10931 for (i
= 0; i
< die
->num_attrs
; ++i
)
10932 if (die
->attrs
[i
].name
== name
)
10933 return &die
->attrs
[i
];
10938 /* Return non-zero iff the attribute NAME is defined for the given DIE,
10939 and holds a non-zero value. This function should only be used for
10940 DW_FORM_flag or DW_FORM_flag_present attributes. */
10943 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
10945 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
10947 return (attr
&& DW_UNSND (attr
));
10951 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
10953 /* A DIE is a declaration if it has a DW_AT_declaration attribute
10954 which value is non-zero. However, we have to be careful with
10955 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
10956 (via dwarf2_flag_true_p) follows this attribute. So we may
10957 end up accidently finding a declaration attribute that belongs
10958 to a different DIE referenced by the specification attribute,
10959 even though the given DIE does not have a declaration attribute. */
10960 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
10961 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
10964 /* Return the die giving the specification for DIE, if there is
10965 one. *SPEC_CU is the CU containing DIE on input, and the CU
10966 containing the return value on output. If there is no
10967 specification, but there is an abstract origin, that is
10970 static struct die_info
*
10971 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
10973 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
10976 if (spec_attr
== NULL
)
10977 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
10979 if (spec_attr
== NULL
)
10982 return follow_die_ref (die
, spec_attr
, spec_cu
);
10985 /* Free the line_header structure *LH, and any arrays and strings it
10987 NOTE: This is also used as a "cleanup" function. */
10990 free_line_header (struct line_header
*lh
)
10992 if (lh
->standard_opcode_lengths
)
10993 xfree (lh
->standard_opcode_lengths
);
10995 /* Remember that all the lh->file_names[i].name pointers are
10996 pointers into debug_line_buffer, and don't need to be freed. */
10997 if (lh
->file_names
)
10998 xfree (lh
->file_names
);
11000 /* Similarly for the include directory names. */
11001 if (lh
->include_dirs
)
11002 xfree (lh
->include_dirs
);
11007 /* Add an entry to LH's include directory table. */
11010 add_include_dir (struct line_header
*lh
, char *include_dir
)
11012 /* Grow the array if necessary. */
11013 if (lh
->include_dirs_size
== 0)
11015 lh
->include_dirs_size
= 1; /* for testing */
11016 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
11017 * sizeof (*lh
->include_dirs
));
11019 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
11021 lh
->include_dirs_size
*= 2;
11022 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
11023 (lh
->include_dirs_size
11024 * sizeof (*lh
->include_dirs
)));
11027 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
11030 /* Add an entry to LH's file name table. */
11033 add_file_name (struct line_header
*lh
,
11035 unsigned int dir_index
,
11036 unsigned int mod_time
,
11037 unsigned int length
)
11039 struct file_entry
*fe
;
11041 /* Grow the array if necessary. */
11042 if (lh
->file_names_size
== 0)
11044 lh
->file_names_size
= 1; /* for testing */
11045 lh
->file_names
= xmalloc (lh
->file_names_size
11046 * sizeof (*lh
->file_names
));
11048 else if (lh
->num_file_names
>= lh
->file_names_size
)
11050 lh
->file_names_size
*= 2;
11051 lh
->file_names
= xrealloc (lh
->file_names
,
11052 (lh
->file_names_size
11053 * sizeof (*lh
->file_names
)));
11056 fe
= &lh
->file_names
[lh
->num_file_names
++];
11058 fe
->dir_index
= dir_index
;
11059 fe
->mod_time
= mod_time
;
11060 fe
->length
= length
;
11061 fe
->included_p
= 0;
11065 /* Read the statement program header starting at OFFSET in
11066 .debug_line, according to the endianness of ABFD. Return a pointer
11067 to a struct line_header, allocated using xmalloc.
11069 NOTE: the strings in the include directory and file name tables of
11070 the returned object point into debug_line_buffer, and must not be
11073 static struct line_header
*
11074 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
11075 struct dwarf2_cu
*cu
)
11077 struct cleanup
*back_to
;
11078 struct line_header
*lh
;
11079 gdb_byte
*line_ptr
;
11080 unsigned int bytes_read
, offset_size
;
11082 char *cur_dir
, *cur_file
;
11084 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
11085 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
11087 complaint (&symfile_complaints
, _("missing .debug_line section"));
11091 /* Make sure that at least there's room for the total_length field.
11092 That could be 12 bytes long, but we're just going to fudge that. */
11093 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
11095 dwarf2_statement_list_fits_in_line_number_section_complaint ();
11099 lh
= xmalloc (sizeof (*lh
));
11100 memset (lh
, 0, sizeof (*lh
));
11101 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
11104 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
11106 /* Read in the header. */
11108 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
11109 &bytes_read
, &offset_size
);
11110 line_ptr
+= bytes_read
;
11111 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
11112 + dwarf2_per_objfile
->line
.size
))
11114 dwarf2_statement_list_fits_in_line_number_section_complaint ();
11117 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
11118 lh
->version
= read_2_bytes (abfd
, line_ptr
);
11120 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
11121 line_ptr
+= offset_size
;
11122 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
11124 if (lh
->version
>= 4)
11126 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
11130 lh
->maximum_ops_per_instruction
= 1;
11132 if (lh
->maximum_ops_per_instruction
== 0)
11134 lh
->maximum_ops_per_instruction
= 1;
11135 complaint (&symfile_complaints
,
11136 _("invalid maximum_ops_per_instruction "
11137 "in `.debug_line' section"));
11140 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
11142 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
11144 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
11146 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
11148 lh
->standard_opcode_lengths
11149 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
11151 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
11152 for (i
= 1; i
< lh
->opcode_base
; ++i
)
11154 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
11158 /* Read directory table. */
11159 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
11161 line_ptr
+= bytes_read
;
11162 add_include_dir (lh
, cur_dir
);
11164 line_ptr
+= bytes_read
;
11166 /* Read file name table. */
11167 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
11169 unsigned int dir_index
, mod_time
, length
;
11171 line_ptr
+= bytes_read
;
11172 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11173 line_ptr
+= bytes_read
;
11174 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11175 line_ptr
+= bytes_read
;
11176 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11177 line_ptr
+= bytes_read
;
11179 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
11181 line_ptr
+= bytes_read
;
11182 lh
->statement_program_start
= line_ptr
;
11184 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
11185 + dwarf2_per_objfile
->line
.size
))
11186 complaint (&symfile_complaints
,
11187 _("line number info header doesn't "
11188 "fit in `.debug_line' section"));
11190 discard_cleanups (back_to
);
11194 /* Subroutine of dwarf_decode_lines to simplify it.
11195 Return the file name of the psymtab for included file FILE_INDEX
11196 in line header LH of PST.
11197 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
11198 If space for the result is malloc'd, it will be freed by a cleanup.
11199 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
11202 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
11203 const struct partial_symtab
*pst
,
11204 const char *comp_dir
)
11206 const struct file_entry fe
= lh
->file_names
[file_index
];
11207 char *include_name
= fe
.name
;
11208 char *include_name_to_compare
= include_name
;
11209 char *dir_name
= NULL
;
11210 const char *pst_filename
;
11211 char *copied_name
= NULL
;
11215 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
11217 if (!IS_ABSOLUTE_PATH (include_name
)
11218 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
11220 /* Avoid creating a duplicate psymtab for PST.
11221 We do this by comparing INCLUDE_NAME and PST_FILENAME.
11222 Before we do the comparison, however, we need to account
11223 for DIR_NAME and COMP_DIR.
11224 First prepend dir_name (if non-NULL). If we still don't
11225 have an absolute path prepend comp_dir (if non-NULL).
11226 However, the directory we record in the include-file's
11227 psymtab does not contain COMP_DIR (to match the
11228 corresponding symtab(s)).
11233 bash$ gcc -g ./hello.c
11234 include_name = "hello.c"
11236 DW_AT_comp_dir = comp_dir = "/tmp"
11237 DW_AT_name = "./hello.c" */
11239 if (dir_name
!= NULL
)
11241 include_name
= concat (dir_name
, SLASH_STRING
,
11242 include_name
, (char *)NULL
);
11243 include_name_to_compare
= include_name
;
11244 make_cleanup (xfree
, include_name
);
11246 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
11248 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
11249 include_name
, (char *)NULL
);
11253 pst_filename
= pst
->filename
;
11254 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
11256 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
11257 pst_filename
, (char *)NULL
);
11258 pst_filename
= copied_name
;
11261 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
11263 if (include_name_to_compare
!= include_name
)
11264 xfree (include_name_to_compare
);
11265 if (copied_name
!= NULL
)
11266 xfree (copied_name
);
11270 return include_name
;
11273 /* Ignore this record_line request. */
11276 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
11281 /* Subroutine of dwarf_decode_lines to simplify it.
11282 Process the line number information in LH. */
11285 dwarf_decode_lines_1 (struct line_header
*lh
, const char *comp_dir
,
11286 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
11288 gdb_byte
*line_ptr
, *extended_end
;
11289 gdb_byte
*line_end
;
11290 unsigned int bytes_read
, extended_len
;
11291 unsigned char op_code
, extended_op
, adj_opcode
;
11292 CORE_ADDR baseaddr
;
11293 struct objfile
*objfile
= cu
->objfile
;
11294 bfd
*abfd
= objfile
->obfd
;
11295 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11296 const int decode_for_pst_p
= (pst
!= NULL
);
11297 struct subfile
*last_subfile
= NULL
;
11298 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
11301 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11303 line_ptr
= lh
->statement_program_start
;
11304 line_end
= lh
->statement_program_end
;
11306 /* Read the statement sequences until there's nothing left. */
11307 while (line_ptr
< line_end
)
11309 /* state machine registers */
11310 CORE_ADDR address
= 0;
11311 unsigned int file
= 1;
11312 unsigned int line
= 1;
11313 unsigned int column
= 0;
11314 int is_stmt
= lh
->default_is_stmt
;
11315 int basic_block
= 0;
11316 int end_sequence
= 0;
11318 unsigned char op_index
= 0;
11320 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
11322 /* Start a subfile for the current file of the state machine. */
11323 /* lh->include_dirs and lh->file_names are 0-based, but the
11324 directory and file name numbers in the statement program
11326 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
11330 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11332 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11335 /* Decode the table. */
11336 while (!end_sequence
)
11338 op_code
= read_1_byte (abfd
, line_ptr
);
11340 if (line_ptr
> line_end
)
11342 dwarf2_debug_line_missing_end_sequence_complaint ();
11346 if (op_code
>= lh
->opcode_base
)
11348 /* Special operand. */
11349 adj_opcode
= op_code
- lh
->opcode_base
;
11350 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
11351 / lh
->maximum_ops_per_instruction
)
11352 * lh
->minimum_instruction_length
);
11353 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
11354 % lh
->maximum_ops_per_instruction
);
11355 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
11356 if (lh
->num_file_names
< file
|| file
== 0)
11357 dwarf2_debug_line_missing_file_complaint ();
11358 /* For now we ignore lines not starting on an
11359 instruction boundary. */
11360 else if (op_index
== 0)
11362 lh
->file_names
[file
- 1].included_p
= 1;
11363 if (!decode_for_pst_p
&& is_stmt
)
11365 if (last_subfile
!= current_subfile
)
11367 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11369 (*p_record_line
) (last_subfile
, 0, addr
);
11370 last_subfile
= current_subfile
;
11372 /* Append row to matrix using current values. */
11373 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11374 (*p_record_line
) (current_subfile
, line
, addr
);
11379 else switch (op_code
)
11381 case DW_LNS_extended_op
:
11382 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
11384 line_ptr
+= bytes_read
;
11385 extended_end
= line_ptr
+ extended_len
;
11386 extended_op
= read_1_byte (abfd
, line_ptr
);
11388 switch (extended_op
)
11390 case DW_LNE_end_sequence
:
11391 p_record_line
= record_line
;
11394 case DW_LNE_set_address
:
11395 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
11397 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
11399 /* This line table is for a function which has been
11400 GCd by the linker. Ignore it. PR gdb/12528 */
11403 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
11405 complaint (&symfile_complaints
,
11406 _(".debug_line address at offset 0x%lx is 0 "
11408 line_offset
, objfile
->name
);
11409 p_record_line
= noop_record_line
;
11413 line_ptr
+= bytes_read
;
11414 address
+= baseaddr
;
11416 case DW_LNE_define_file
:
11419 unsigned int dir_index
, mod_time
, length
;
11421 cur_file
= read_direct_string (abfd
, line_ptr
,
11423 line_ptr
+= bytes_read
;
11425 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11426 line_ptr
+= bytes_read
;
11428 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11429 line_ptr
+= bytes_read
;
11431 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11432 line_ptr
+= bytes_read
;
11433 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
11436 case DW_LNE_set_discriminator
:
11437 /* The discriminator is not interesting to the debugger;
11439 line_ptr
= extended_end
;
11442 complaint (&symfile_complaints
,
11443 _("mangled .debug_line section"));
11446 /* Make sure that we parsed the extended op correctly. If e.g.
11447 we expected a different address size than the producer used,
11448 we may have read the wrong number of bytes. */
11449 if (line_ptr
!= extended_end
)
11451 complaint (&symfile_complaints
,
11452 _("mangled .debug_line section"));
11457 if (lh
->num_file_names
< file
|| file
== 0)
11458 dwarf2_debug_line_missing_file_complaint ();
11461 lh
->file_names
[file
- 1].included_p
= 1;
11462 if (!decode_for_pst_p
&& is_stmt
)
11464 if (last_subfile
!= current_subfile
)
11466 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11468 (*p_record_line
) (last_subfile
, 0, addr
);
11469 last_subfile
= current_subfile
;
11471 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11472 (*p_record_line
) (current_subfile
, line
, addr
);
11477 case DW_LNS_advance_pc
:
11480 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11482 address
+= (((op_index
+ adjust
)
11483 / lh
->maximum_ops_per_instruction
)
11484 * lh
->minimum_instruction_length
);
11485 op_index
= ((op_index
+ adjust
)
11486 % lh
->maximum_ops_per_instruction
);
11487 line_ptr
+= bytes_read
;
11490 case DW_LNS_advance_line
:
11491 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
11492 line_ptr
+= bytes_read
;
11494 case DW_LNS_set_file
:
11496 /* The arrays lh->include_dirs and lh->file_names are
11497 0-based, but the directory and file name numbers in
11498 the statement program are 1-based. */
11499 struct file_entry
*fe
;
11502 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11503 line_ptr
+= bytes_read
;
11504 if (lh
->num_file_names
< file
|| file
== 0)
11505 dwarf2_debug_line_missing_file_complaint ();
11508 fe
= &lh
->file_names
[file
- 1];
11510 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11511 if (!decode_for_pst_p
)
11513 last_subfile
= current_subfile
;
11514 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11519 case DW_LNS_set_column
:
11520 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11521 line_ptr
+= bytes_read
;
11523 case DW_LNS_negate_stmt
:
11524 is_stmt
= (!is_stmt
);
11526 case DW_LNS_set_basic_block
:
11529 /* Add to the address register of the state machine the
11530 address increment value corresponding to special opcode
11531 255. I.e., this value is scaled by the minimum
11532 instruction length since special opcode 255 would have
11533 scaled the increment. */
11534 case DW_LNS_const_add_pc
:
11536 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
11538 address
+= (((op_index
+ adjust
)
11539 / lh
->maximum_ops_per_instruction
)
11540 * lh
->minimum_instruction_length
);
11541 op_index
= ((op_index
+ adjust
)
11542 % lh
->maximum_ops_per_instruction
);
11545 case DW_LNS_fixed_advance_pc
:
11546 address
+= read_2_bytes (abfd
, line_ptr
);
11552 /* Unknown standard opcode, ignore it. */
11555 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
11557 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11558 line_ptr
+= bytes_read
;
11563 if (lh
->num_file_names
< file
|| file
== 0)
11564 dwarf2_debug_line_missing_file_complaint ();
11567 lh
->file_names
[file
- 1].included_p
= 1;
11568 if (!decode_for_pst_p
)
11570 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11571 (*p_record_line
) (current_subfile
, 0, addr
);
11577 /* Decode the Line Number Program (LNP) for the given line_header
11578 structure and CU. The actual information extracted and the type
11579 of structures created from the LNP depends on the value of PST.
11581 1. If PST is NULL, then this procedure uses the data from the program
11582 to create all necessary symbol tables, and their linetables.
11584 2. If PST is not NULL, this procedure reads the program to determine
11585 the list of files included by the unit represented by PST, and
11586 builds all the associated partial symbol tables.
11588 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
11589 It is used for relative paths in the line table.
11590 NOTE: When processing partial symtabs (pst != NULL),
11591 comp_dir == pst->dirname.
11593 NOTE: It is important that psymtabs have the same file name (via strcmp)
11594 as the corresponding symtab. Since COMP_DIR is not used in the name of the
11595 symtab we don't use it in the name of the psymtabs we create.
11596 E.g. expand_line_sal requires this when finding psymtabs to expand.
11597 A good testcase for this is mb-inline.exp. */
11600 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
11601 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
11602 int want_line_info
)
11604 struct objfile
*objfile
= cu
->objfile
;
11605 const int decode_for_pst_p
= (pst
!= NULL
);
11606 struct subfile
*first_subfile
= current_subfile
;
11608 if (want_line_info
)
11609 dwarf_decode_lines_1 (lh
, comp_dir
, cu
, pst
);
11611 if (decode_for_pst_p
)
11615 /* Now that we're done scanning the Line Header Program, we can
11616 create the psymtab of each included file. */
11617 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
11618 if (lh
->file_names
[file_index
].included_p
== 1)
11620 char *include_name
=
11621 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
11622 if (include_name
!= NULL
)
11623 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
11628 /* Make sure a symtab is created for every file, even files
11629 which contain only variables (i.e. no code with associated
11633 for (i
= 0; i
< lh
->num_file_names
; i
++)
11636 struct file_entry
*fe
;
11638 fe
= &lh
->file_names
[i
];
11640 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11641 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11643 /* Skip the main file; we don't need it, and it must be
11644 allocated last, so that it will show up before the
11645 non-primary symtabs in the objfile's symtab list. */
11646 if (current_subfile
== first_subfile
)
11649 if (current_subfile
->symtab
== NULL
)
11650 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
11652 fe
->symtab
= current_subfile
->symtab
;
11657 /* Start a subfile for DWARF. FILENAME is the name of the file and
11658 DIRNAME the name of the source directory which contains FILENAME
11659 or NULL if not known. COMP_DIR is the compilation directory for the
11660 linetable's compilation unit or NULL if not known.
11661 This routine tries to keep line numbers from identical absolute and
11662 relative file names in a common subfile.
11664 Using the `list' example from the GDB testsuite, which resides in
11665 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
11666 of /srcdir/list0.c yields the following debugging information for list0.c:
11668 DW_AT_name: /srcdir/list0.c
11669 DW_AT_comp_dir: /compdir
11670 files.files[0].name: list0.h
11671 files.files[0].dir: /srcdir
11672 files.files[1].name: list0.c
11673 files.files[1].dir: /srcdir
11675 The line number information for list0.c has to end up in a single
11676 subfile, so that `break /srcdir/list0.c:1' works as expected.
11677 start_subfile will ensure that this happens provided that we pass the
11678 concatenation of files.files[1].dir and files.files[1].name as the
11682 dwarf2_start_subfile (char *filename
, const char *dirname
,
11683 const char *comp_dir
)
11687 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
11688 `start_symtab' will always pass the contents of DW_AT_comp_dir as
11689 second argument to start_subfile. To be consistent, we do the
11690 same here. In order not to lose the line information directory,
11691 we concatenate it to the filename when it makes sense.
11692 Note that the Dwarf3 standard says (speaking of filenames in line
11693 information): ``The directory index is ignored for file names
11694 that represent full path names''. Thus ignoring dirname in the
11695 `else' branch below isn't an issue. */
11697 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
11698 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
11700 fullname
= filename
;
11702 start_subfile (fullname
, comp_dir
);
11704 if (fullname
!= filename
)
11709 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
11710 struct dwarf2_cu
*cu
)
11712 struct objfile
*objfile
= cu
->objfile
;
11713 struct comp_unit_head
*cu_header
= &cu
->header
;
11715 /* NOTE drow/2003-01-30: There used to be a comment and some special
11716 code here to turn a symbol with DW_AT_external and a
11717 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
11718 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
11719 with some versions of binutils) where shared libraries could have
11720 relocations against symbols in their debug information - the
11721 minimal symbol would have the right address, but the debug info
11722 would not. It's no longer necessary, because we will explicitly
11723 apply relocations when we read in the debug information now. */
11725 /* A DW_AT_location attribute with no contents indicates that a
11726 variable has been optimized away. */
11727 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
11729 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11733 /* Handle one degenerate form of location expression specially, to
11734 preserve GDB's previous behavior when section offsets are
11735 specified. If this is just a DW_OP_addr then mark this symbol
11738 if (attr_form_is_block (attr
)
11739 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
11740 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
11742 unsigned int dummy
;
11744 SYMBOL_VALUE_ADDRESS (sym
) =
11745 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
11746 SYMBOL_CLASS (sym
) = LOC_STATIC
;
11747 fixup_symbol_section (sym
, objfile
);
11748 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
11749 SYMBOL_SECTION (sym
));
11753 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
11754 expression evaluator, and use LOC_COMPUTED only when necessary
11755 (i.e. when the value of a register or memory location is
11756 referenced, or a thread-local block, etc.). Then again, it might
11757 not be worthwhile. I'm assuming that it isn't unless performance
11758 or memory numbers show me otherwise. */
11760 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
11761 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11763 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
11764 cu
->has_loclist
= 1;
11767 /* Given a pointer to a DWARF information entry, figure out if we need
11768 to make a symbol table entry for it, and if so, create a new entry
11769 and return a pointer to it.
11770 If TYPE is NULL, determine symbol type from the die, otherwise
11771 used the passed type.
11772 If SPACE is not NULL, use it to hold the new symbol. If it is
11773 NULL, allocate a new symbol on the objfile's obstack. */
11775 static struct symbol
*
11776 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
11777 struct symbol
*space
)
11779 struct objfile
*objfile
= cu
->objfile
;
11780 struct symbol
*sym
= NULL
;
11782 struct attribute
*attr
= NULL
;
11783 struct attribute
*attr2
= NULL
;
11784 CORE_ADDR baseaddr
;
11785 struct pending
**list_to_add
= NULL
;
11787 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
11789 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11791 name
= dwarf2_name (die
, cu
);
11794 const char *linkagename
;
11795 int suppress_add
= 0;
11800 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
11801 OBJSTAT (objfile
, n_syms
++);
11803 /* Cache this symbol's name and the name's demangled form (if any). */
11804 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
11805 linkagename
= dwarf2_physname (name
, die
, cu
);
11806 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
11808 /* Fortran does not have mangling standard and the mangling does differ
11809 between gfortran, iFort etc. */
11810 if (cu
->language
== language_fortran
11811 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
11812 symbol_set_demangled_name (&(sym
->ginfo
),
11813 (char *) dwarf2_full_name (name
, die
, cu
),
11816 /* Default assumptions.
11817 Use the passed type or decode it from the die. */
11818 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11819 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11821 SYMBOL_TYPE (sym
) = type
;
11823 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
11824 attr
= dwarf2_attr (die
,
11825 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
11829 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
11832 attr
= dwarf2_attr (die
,
11833 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
11837 int file_index
= DW_UNSND (attr
);
11839 if (cu
->line_header
== NULL
11840 || file_index
> cu
->line_header
->num_file_names
)
11841 complaint (&symfile_complaints
,
11842 _("file index out of range"));
11843 else if (file_index
> 0)
11845 struct file_entry
*fe
;
11847 fe
= &cu
->line_header
->file_names
[file_index
- 1];
11848 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
11855 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11858 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
11860 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
11861 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
11862 SYMBOL_CLASS (sym
) = LOC_LABEL
;
11863 add_symbol_to_list (sym
, cu
->list_in_scope
);
11865 case DW_TAG_subprogram
:
11866 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11868 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11869 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11870 if ((attr2
&& (DW_UNSND (attr2
) != 0))
11871 || cu
->language
== language_ada
)
11873 /* Subprograms marked external are stored as a global symbol.
11874 Ada subprograms, whether marked external or not, are always
11875 stored as a global symbol, because we want to be able to
11876 access them globally. For instance, we want to be able
11877 to break on a nested subprogram without having to
11878 specify the context. */
11879 list_to_add
= &global_symbols
;
11883 list_to_add
= cu
->list_in_scope
;
11886 case DW_TAG_inlined_subroutine
:
11887 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11889 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11890 SYMBOL_INLINED (sym
) = 1;
11891 list_to_add
= cu
->list_in_scope
;
11893 case DW_TAG_template_value_param
:
11895 /* Fall through. */
11896 case DW_TAG_constant
:
11897 case DW_TAG_variable
:
11898 case DW_TAG_member
:
11899 /* Compilation with minimal debug info may result in
11900 variables with missing type entries. Change the
11901 misleading `void' type to something sensible. */
11902 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
11904 = objfile_type (objfile
)->nodebug_data_symbol
;
11906 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11907 /* In the case of DW_TAG_member, we should only be called for
11908 static const members. */
11909 if (die
->tag
== DW_TAG_member
)
11911 /* dwarf2_add_field uses die_is_declaration,
11912 so we do the same. */
11913 gdb_assert (die_is_declaration (die
, cu
));
11918 dwarf2_const_value (attr
, sym
, cu
);
11919 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11922 if (attr2
&& (DW_UNSND (attr2
) != 0))
11923 list_to_add
= &global_symbols
;
11925 list_to_add
= cu
->list_in_scope
;
11929 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11932 var_decode_location (attr
, sym
, cu
);
11933 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11934 if (SYMBOL_CLASS (sym
) == LOC_STATIC
11935 && SYMBOL_VALUE_ADDRESS (sym
) == 0
11936 && !dwarf2_per_objfile
->has_section_at_zero
)
11938 /* When a static variable is eliminated by the linker,
11939 the corresponding debug information is not stripped
11940 out, but the variable address is set to null;
11941 do not add such variables into symbol table. */
11943 else if (attr2
&& (DW_UNSND (attr2
) != 0))
11945 /* Workaround gfortran PR debug/40040 - it uses
11946 DW_AT_location for variables in -fPIC libraries which may
11947 get overriden by other libraries/executable and get
11948 a different address. Resolve it by the minimal symbol
11949 which may come from inferior's executable using copy
11950 relocation. Make this workaround only for gfortran as for
11951 other compilers GDB cannot guess the minimal symbol
11952 Fortran mangling kind. */
11953 if (cu
->language
== language_fortran
&& die
->parent
11954 && die
->parent
->tag
== DW_TAG_module
11956 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
11957 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11959 /* A variable with DW_AT_external is never static,
11960 but it may be block-scoped. */
11961 list_to_add
= (cu
->list_in_scope
== &file_symbols
11962 ? &global_symbols
: cu
->list_in_scope
);
11965 list_to_add
= cu
->list_in_scope
;
11969 /* We do not know the address of this symbol.
11970 If it is an external symbol and we have type information
11971 for it, enter the symbol as a LOC_UNRESOLVED symbol.
11972 The address of the variable will then be determined from
11973 the minimal symbol table whenever the variable is
11975 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11976 if (attr2
&& (DW_UNSND (attr2
) != 0)
11977 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
11979 /* A variable with DW_AT_external is never static, but it
11980 may be block-scoped. */
11981 list_to_add
= (cu
->list_in_scope
== &file_symbols
11982 ? &global_symbols
: cu
->list_in_scope
);
11984 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11986 else if (!die_is_declaration (die
, cu
))
11988 /* Use the default LOC_OPTIMIZED_OUT class. */
11989 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
11991 list_to_add
= cu
->list_in_scope
;
11995 case DW_TAG_formal_parameter
:
11996 /* If we are inside a function, mark this as an argument. If
11997 not, we might be looking at an argument to an inlined function
11998 when we do not have enough information to show inlined frames;
11999 pretend it's a local variable in that case so that the user can
12001 if (context_stack_depth
> 0
12002 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
12003 SYMBOL_IS_ARGUMENT (sym
) = 1;
12004 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
12007 var_decode_location (attr
, sym
, cu
);
12009 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
12012 dwarf2_const_value (attr
, sym
, cu
);
12015 list_to_add
= cu
->list_in_scope
;
12017 case DW_TAG_unspecified_parameters
:
12018 /* From varargs functions; gdb doesn't seem to have any
12019 interest in this information, so just ignore it for now.
12022 case DW_TAG_template_type_param
:
12024 /* Fall through. */
12025 case DW_TAG_class_type
:
12026 case DW_TAG_interface_type
:
12027 case DW_TAG_structure_type
:
12028 case DW_TAG_union_type
:
12029 case DW_TAG_set_type
:
12030 case DW_TAG_enumeration_type
:
12031 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
12032 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
12035 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
12036 really ever be static objects: otherwise, if you try
12037 to, say, break of a class's method and you're in a file
12038 which doesn't mention that class, it won't work unless
12039 the check for all static symbols in lookup_symbol_aux
12040 saves you. See the OtherFileClass tests in
12041 gdb.c++/namespace.exp. */
12045 list_to_add
= (cu
->list_in_scope
== &file_symbols
12046 && (cu
->language
== language_cplus
12047 || cu
->language
== language_java
)
12048 ? &global_symbols
: cu
->list_in_scope
);
12050 /* The semantics of C++ state that "struct foo {
12051 ... }" also defines a typedef for "foo". A Java
12052 class declaration also defines a typedef for the
12054 if (cu
->language
== language_cplus
12055 || cu
->language
== language_java
12056 || cu
->language
== language_ada
)
12058 /* The symbol's name is already allocated along
12059 with this objfile, so we don't need to
12060 duplicate it for the type. */
12061 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
12062 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
12067 case DW_TAG_typedef
:
12068 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
12069 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
12070 list_to_add
= cu
->list_in_scope
;
12072 case DW_TAG_base_type
:
12073 case DW_TAG_subrange_type
:
12074 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
12075 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
12076 list_to_add
= cu
->list_in_scope
;
12078 case DW_TAG_enumerator
:
12079 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
12082 dwarf2_const_value (attr
, sym
, cu
);
12085 /* NOTE: carlton/2003-11-10: See comment above in the
12086 DW_TAG_class_type, etc. block. */
12088 list_to_add
= (cu
->list_in_scope
== &file_symbols
12089 && (cu
->language
== language_cplus
12090 || cu
->language
== language_java
)
12091 ? &global_symbols
: cu
->list_in_scope
);
12094 case DW_TAG_namespace
:
12095 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
12096 list_to_add
= &global_symbols
;
12099 /* Not a tag we recognize. Hopefully we aren't processing
12100 trash data, but since we must specifically ignore things
12101 we don't recognize, there is nothing else we should do at
12103 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
12104 dwarf_tag_name (die
->tag
));
12110 sym
->hash_next
= objfile
->template_symbols
;
12111 objfile
->template_symbols
= sym
;
12112 list_to_add
= NULL
;
12115 if (list_to_add
!= NULL
)
12116 add_symbol_to_list (sym
, list_to_add
);
12118 /* For the benefit of old versions of GCC, check for anonymous
12119 namespaces based on the demangled name. */
12120 if (!processing_has_namespace_info
12121 && cu
->language
== language_cplus
)
12122 cp_scan_for_anonymous_namespaces (sym
, objfile
);
12127 /* A wrapper for new_symbol_full that always allocates a new symbol. */
12129 static struct symbol
*
12130 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
12132 return new_symbol_full (die
, type
, cu
, NULL
);
12135 /* Given an attr with a DW_FORM_dataN value in host byte order,
12136 zero-extend it as appropriate for the symbol's type. The DWARF
12137 standard (v4) is not entirely clear about the meaning of using
12138 DW_FORM_dataN for a constant with a signed type, where the type is
12139 wider than the data. The conclusion of a discussion on the DWARF
12140 list was that this is unspecified. We choose to always zero-extend
12141 because that is the interpretation long in use by GCC. */
12144 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
12145 const char *name
, struct obstack
*obstack
,
12146 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
12148 struct objfile
*objfile
= cu
->objfile
;
12149 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
12150 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
12151 LONGEST l
= DW_UNSND (attr
);
12153 if (bits
< sizeof (*value
) * 8)
12155 l
&= ((LONGEST
) 1 << bits
) - 1;
12158 else if (bits
== sizeof (*value
) * 8)
12162 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
12163 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
12170 /* Read a constant value from an attribute. Either set *VALUE, or if
12171 the value does not fit in *VALUE, set *BYTES - either already
12172 allocated on the objfile obstack, or newly allocated on OBSTACK,
12173 or, set *BATON, if we translated the constant to a location
12177 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
12178 const char *name
, struct obstack
*obstack
,
12179 struct dwarf2_cu
*cu
,
12180 LONGEST
*value
, gdb_byte
**bytes
,
12181 struct dwarf2_locexpr_baton
**baton
)
12183 struct objfile
*objfile
= cu
->objfile
;
12184 struct comp_unit_head
*cu_header
= &cu
->header
;
12185 struct dwarf_block
*blk
;
12186 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
12187 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
12193 switch (attr
->form
)
12199 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
12200 dwarf2_const_value_length_mismatch_complaint (name
,
12201 cu_header
->addr_size
,
12202 TYPE_LENGTH (type
));
12203 /* Symbols of this form are reasonably rare, so we just
12204 piggyback on the existing location code rather than writing
12205 a new implementation of symbol_computed_ops. */
12206 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
12207 sizeof (struct dwarf2_locexpr_baton
));
12208 (*baton
)->per_cu
= cu
->per_cu
;
12209 gdb_assert ((*baton
)->per_cu
);
12211 (*baton
)->size
= 2 + cu_header
->addr_size
;
12212 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
12213 (*baton
)->data
= data
;
12215 data
[0] = DW_OP_addr
;
12216 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
12217 byte_order
, DW_ADDR (attr
));
12218 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
12221 case DW_FORM_string
:
12223 /* DW_STRING is already allocated on the objfile obstack, point
12225 *bytes
= (gdb_byte
*) DW_STRING (attr
);
12227 case DW_FORM_block1
:
12228 case DW_FORM_block2
:
12229 case DW_FORM_block4
:
12230 case DW_FORM_block
:
12231 case DW_FORM_exprloc
:
12232 blk
= DW_BLOCK (attr
);
12233 if (TYPE_LENGTH (type
) != blk
->size
)
12234 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
12235 TYPE_LENGTH (type
));
12236 *bytes
= blk
->data
;
12239 /* The DW_AT_const_value attributes are supposed to carry the
12240 symbol's value "represented as it would be on the target
12241 architecture." By the time we get here, it's already been
12242 converted to host endianness, so we just need to sign- or
12243 zero-extend it as appropriate. */
12244 case DW_FORM_data1
:
12245 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12246 obstack
, cu
, value
, 8);
12248 case DW_FORM_data2
:
12249 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12250 obstack
, cu
, value
, 16);
12252 case DW_FORM_data4
:
12253 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12254 obstack
, cu
, value
, 32);
12256 case DW_FORM_data8
:
12257 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12258 obstack
, cu
, value
, 64);
12261 case DW_FORM_sdata
:
12262 *value
= DW_SND (attr
);
12265 case DW_FORM_udata
:
12266 *value
= DW_UNSND (attr
);
12270 complaint (&symfile_complaints
,
12271 _("unsupported const value attribute form: '%s'"),
12272 dwarf_form_name (attr
->form
));
12279 /* Copy constant value from an attribute to a symbol. */
12282 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
12283 struct dwarf2_cu
*cu
)
12285 struct objfile
*objfile
= cu
->objfile
;
12286 struct comp_unit_head
*cu_header
= &cu
->header
;
12289 struct dwarf2_locexpr_baton
*baton
;
12291 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
12292 SYMBOL_PRINT_NAME (sym
),
12293 &objfile
->objfile_obstack
, cu
,
12294 &value
, &bytes
, &baton
);
12298 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
12299 SYMBOL_LOCATION_BATON (sym
) = baton
;
12300 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
12302 else if (bytes
!= NULL
)
12304 SYMBOL_VALUE_BYTES (sym
) = bytes
;
12305 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
12309 SYMBOL_VALUE (sym
) = value
;
12310 SYMBOL_CLASS (sym
) = LOC_CONST
;
12314 /* Return the type of the die in question using its DW_AT_type attribute. */
12316 static struct type
*
12317 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12319 struct attribute
*type_attr
;
12321 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
12324 /* A missing DW_AT_type represents a void type. */
12325 return objfile_type (cu
->objfile
)->builtin_void
;
12328 return lookup_die_type (die
, type_attr
, cu
);
12331 /* True iff CU's producer generates GNAT Ada auxiliary information
12332 that allows to find parallel types through that information instead
12333 of having to do expensive parallel lookups by type name. */
12336 need_gnat_info (struct dwarf2_cu
*cu
)
12338 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
12339 of GNAT produces this auxiliary information, without any indication
12340 that it is produced. Part of enhancing the FSF version of GNAT
12341 to produce that information will be to put in place an indicator
12342 that we can use in order to determine whether the descriptive type
12343 info is available or not. One suggestion that has been made is
12344 to use a new attribute, attached to the CU die. For now, assume
12345 that the descriptive type info is not available. */
12349 /* Return the auxiliary type of the die in question using its
12350 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
12351 attribute is not present. */
12353 static struct type
*
12354 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12356 struct attribute
*type_attr
;
12358 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
12362 return lookup_die_type (die
, type_attr
, cu
);
12365 /* If DIE has a descriptive_type attribute, then set the TYPE's
12366 descriptive type accordingly. */
12369 set_descriptive_type (struct type
*type
, struct die_info
*die
,
12370 struct dwarf2_cu
*cu
)
12372 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
12374 if (descriptive_type
)
12376 ALLOCATE_GNAT_AUX_TYPE (type
);
12377 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
12381 /* Return the containing type of the die in question using its
12382 DW_AT_containing_type attribute. */
12384 static struct type
*
12385 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12387 struct attribute
*type_attr
;
12389 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
12391 error (_("Dwarf Error: Problem turning containing type into gdb type "
12392 "[in module %s]"), cu
->objfile
->name
);
12394 return lookup_die_type (die
, type_attr
, cu
);
12397 /* Look up the type of DIE in CU using its type attribute ATTR.
12398 If there is no type substitute an error marker. */
12400 static struct type
*
12401 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
12402 struct dwarf2_cu
*cu
)
12404 struct objfile
*objfile
= cu
->objfile
;
12405 struct type
*this_type
;
12407 /* First see if we have it cached. */
12409 if (is_ref_attr (attr
))
12411 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
12413 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
12415 else if (attr
->form
== DW_FORM_ref_sig8
)
12417 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
12418 struct dwarf2_cu
*sig_cu
;
12419 sect_offset offset
;
12421 /* sig_type will be NULL if the signatured type is missing from
12423 if (sig_type
== NULL
)
12424 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
12425 "at 0x%x [in module %s]"),
12426 die
->offset
.sect_off
, objfile
->name
);
12428 gdb_assert (sig_type
->per_cu
.debug_types_section
);
12429 offset
.sect_off
= (sig_type
->per_cu
.offset
.sect_off
12430 + sig_type
->type_offset
.cu_off
);
12431 this_type
= get_die_type_at_offset (offset
, &sig_type
->per_cu
);
12435 dump_die_for_error (die
);
12436 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
12437 dwarf_attr_name (attr
->name
), objfile
->name
);
12440 /* If not cached we need to read it in. */
12442 if (this_type
== NULL
)
12444 struct die_info
*type_die
;
12445 struct dwarf2_cu
*type_cu
= cu
;
12447 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
12448 /* If the type is cached, we should have found it above. */
12449 gdb_assert (get_die_type (type_die
, type_cu
) == NULL
);
12450 this_type
= read_type_die_1 (type_die
, type_cu
);
12453 /* If we still don't have a type use an error marker. */
12455 if (this_type
== NULL
)
12457 char *message
, *saved
;
12459 /* read_type_die already issued a complaint. */
12460 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
12462 cu
->header
.offset
.sect_off
,
12463 die
->offset
.sect_off
);
12464 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
12465 message
, strlen (message
));
12468 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
12474 /* Return the type in DIE, CU.
12475 Returns NULL for invalid types.
12477 This first does a lookup in the appropriate type_hash table,
12478 and only reads the die in if necessary.
12480 NOTE: This can be called when reading in partial or full symbols. */
12482 static struct type
*
12483 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
12485 struct type
*this_type
;
12487 this_type
= get_die_type (die
, cu
);
12491 return read_type_die_1 (die
, cu
);
12494 /* Read the type in DIE, CU.
12495 Returns NULL for invalid types. */
12497 static struct type
*
12498 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
12500 struct type
*this_type
= NULL
;
12504 case DW_TAG_class_type
:
12505 case DW_TAG_interface_type
:
12506 case DW_TAG_structure_type
:
12507 case DW_TAG_union_type
:
12508 this_type
= read_structure_type (die
, cu
);
12510 case DW_TAG_enumeration_type
:
12511 this_type
= read_enumeration_type (die
, cu
);
12513 case DW_TAG_subprogram
:
12514 case DW_TAG_subroutine_type
:
12515 case DW_TAG_inlined_subroutine
:
12516 this_type
= read_subroutine_type (die
, cu
);
12518 case DW_TAG_array_type
:
12519 this_type
= read_array_type (die
, cu
);
12521 case DW_TAG_set_type
:
12522 this_type
= read_set_type (die
, cu
);
12524 case DW_TAG_pointer_type
:
12525 this_type
= read_tag_pointer_type (die
, cu
);
12527 case DW_TAG_ptr_to_member_type
:
12528 this_type
= read_tag_ptr_to_member_type (die
, cu
);
12530 case DW_TAG_reference_type
:
12531 this_type
= read_tag_reference_type (die
, cu
);
12533 case DW_TAG_const_type
:
12534 this_type
= read_tag_const_type (die
, cu
);
12536 case DW_TAG_volatile_type
:
12537 this_type
= read_tag_volatile_type (die
, cu
);
12539 case DW_TAG_string_type
:
12540 this_type
= read_tag_string_type (die
, cu
);
12542 case DW_TAG_typedef
:
12543 this_type
= read_typedef (die
, cu
);
12545 case DW_TAG_subrange_type
:
12546 this_type
= read_subrange_type (die
, cu
);
12548 case DW_TAG_base_type
:
12549 this_type
= read_base_type (die
, cu
);
12551 case DW_TAG_unspecified_type
:
12552 this_type
= read_unspecified_type (die
, cu
);
12554 case DW_TAG_namespace
:
12555 this_type
= read_namespace_type (die
, cu
);
12557 case DW_TAG_module
:
12558 this_type
= read_module_type (die
, cu
);
12561 complaint (&symfile_complaints
,
12562 _("unexpected tag in read_type_die: '%s'"),
12563 dwarf_tag_name (die
->tag
));
12570 /* See if we can figure out if the class lives in a namespace. We do
12571 this by looking for a member function; its demangled name will
12572 contain namespace info, if there is any.
12573 Return the computed name or NULL.
12574 Space for the result is allocated on the objfile's obstack.
12575 This is the full-die version of guess_partial_die_structure_name.
12576 In this case we know DIE has no useful parent. */
12579 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12581 struct die_info
*spec_die
;
12582 struct dwarf2_cu
*spec_cu
;
12583 struct die_info
*child
;
12586 spec_die
= die_specification (die
, &spec_cu
);
12587 if (spec_die
!= NULL
)
12593 for (child
= die
->child
;
12595 child
= child
->sibling
)
12597 if (child
->tag
== DW_TAG_subprogram
)
12599 struct attribute
*attr
;
12601 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
12603 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
12607 = language_class_name_from_physname (cu
->language_defn
,
12611 if (actual_name
!= NULL
)
12613 char *die_name
= dwarf2_name (die
, cu
);
12615 if (die_name
!= NULL
12616 && strcmp (die_name
, actual_name
) != 0)
12618 /* Strip off the class name from the full name.
12619 We want the prefix. */
12620 int die_name_len
= strlen (die_name
);
12621 int actual_name_len
= strlen (actual_name
);
12623 /* Test for '::' as a sanity check. */
12624 if (actual_name_len
> die_name_len
+ 2
12625 && actual_name
[actual_name_len
12626 - die_name_len
- 1] == ':')
12628 obsavestring (actual_name
,
12629 actual_name_len
- die_name_len
- 2,
12630 &cu
->objfile
->objfile_obstack
);
12633 xfree (actual_name
);
12642 /* GCC might emit a nameless typedef that has a linkage name. Determine the
12643 prefix part in such case. See
12644 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12647 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
12649 struct attribute
*attr
;
12652 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
12653 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
12656 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
12657 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
12660 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
12662 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
12663 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
12666 /* dwarf2_name had to be already called. */
12667 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
12669 /* Strip the base name, keep any leading namespaces/classes. */
12670 base
= strrchr (DW_STRING (attr
), ':');
12671 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
12674 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
12675 &cu
->objfile
->objfile_obstack
);
12678 /* Return the name of the namespace/class that DIE is defined within,
12679 or "" if we can't tell. The caller should not xfree the result.
12681 For example, if we're within the method foo() in the following
12691 then determine_prefix on foo's die will return "N::C". */
12693 static const char *
12694 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
12696 struct die_info
*parent
, *spec_die
;
12697 struct dwarf2_cu
*spec_cu
;
12698 struct type
*parent_type
;
12701 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
12702 && cu
->language
!= language_fortran
)
12705 retval
= anonymous_struct_prefix (die
, cu
);
12709 /* We have to be careful in the presence of DW_AT_specification.
12710 For example, with GCC 3.4, given the code
12714 // Definition of N::foo.
12718 then we'll have a tree of DIEs like this:
12720 1: DW_TAG_compile_unit
12721 2: DW_TAG_namespace // N
12722 3: DW_TAG_subprogram // declaration of N::foo
12723 4: DW_TAG_subprogram // definition of N::foo
12724 DW_AT_specification // refers to die #3
12726 Thus, when processing die #4, we have to pretend that we're in
12727 the context of its DW_AT_specification, namely the contex of die
12730 spec_die
= die_specification (die
, &spec_cu
);
12731 if (spec_die
== NULL
)
12732 parent
= die
->parent
;
12735 parent
= spec_die
->parent
;
12739 if (parent
== NULL
)
12741 else if (parent
->building_fullname
)
12744 const char *parent_name
;
12746 /* It has been seen on RealView 2.2 built binaries,
12747 DW_TAG_template_type_param types actually _defined_ as
12748 children of the parent class:
12751 template class <class Enum> Class{};
12752 Class<enum E> class_e;
12754 1: DW_TAG_class_type (Class)
12755 2: DW_TAG_enumeration_type (E)
12756 3: DW_TAG_enumerator (enum1:0)
12757 3: DW_TAG_enumerator (enum2:1)
12759 2: DW_TAG_template_type_param
12760 DW_AT_type DW_FORM_ref_udata (E)
12762 Besides being broken debug info, it can put GDB into an
12763 infinite loop. Consider:
12765 When we're building the full name for Class<E>, we'll start
12766 at Class, and go look over its template type parameters,
12767 finding E. We'll then try to build the full name of E, and
12768 reach here. We're now trying to build the full name of E,
12769 and look over the parent DIE for containing scope. In the
12770 broken case, if we followed the parent DIE of E, we'd again
12771 find Class, and once again go look at its template type
12772 arguments, etc., etc. Simply don't consider such parent die
12773 as source-level parent of this die (it can't be, the language
12774 doesn't allow it), and break the loop here. */
12775 name
= dwarf2_name (die
, cu
);
12776 parent_name
= dwarf2_name (parent
, cu
);
12777 complaint (&symfile_complaints
,
12778 _("template param type '%s' defined within parent '%s'"),
12779 name
? name
: "<unknown>",
12780 parent_name
? parent_name
: "<unknown>");
12784 switch (parent
->tag
)
12786 case DW_TAG_namespace
:
12787 parent_type
= read_type_die (parent
, cu
);
12788 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
12789 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
12790 Work around this problem here. */
12791 if (cu
->language
== language_cplus
12792 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
12794 /* We give a name to even anonymous namespaces. */
12795 return TYPE_TAG_NAME (parent_type
);
12796 case DW_TAG_class_type
:
12797 case DW_TAG_interface_type
:
12798 case DW_TAG_structure_type
:
12799 case DW_TAG_union_type
:
12800 case DW_TAG_module
:
12801 parent_type
= read_type_die (parent
, cu
);
12802 if (TYPE_TAG_NAME (parent_type
) != NULL
)
12803 return TYPE_TAG_NAME (parent_type
);
12805 /* An anonymous structure is only allowed non-static data
12806 members; no typedefs, no member functions, et cetera.
12807 So it does not need a prefix. */
12809 case DW_TAG_compile_unit
:
12810 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
12811 if (cu
->language
== language_cplus
12812 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
12813 && die
->child
!= NULL
12814 && (die
->tag
== DW_TAG_class_type
12815 || die
->tag
== DW_TAG_structure_type
12816 || die
->tag
== DW_TAG_union_type
))
12818 char *name
= guess_full_die_structure_name (die
, cu
);
12824 return determine_prefix (parent
, cu
);
12828 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
12829 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
12830 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
12831 an obconcat, otherwise allocate storage for the result. The CU argument is
12832 used to determine the language and hence, the appropriate separator. */
12834 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
12837 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
12838 int physname
, struct dwarf2_cu
*cu
)
12840 const char *lead
= "";
12843 if (suffix
== NULL
|| suffix
[0] == '\0'
12844 || prefix
== NULL
|| prefix
[0] == '\0')
12846 else if (cu
->language
== language_java
)
12848 else if (cu
->language
== language_fortran
&& physname
)
12850 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
12851 DW_AT_MIPS_linkage_name is preferred and used instead. */
12859 if (prefix
== NULL
)
12861 if (suffix
== NULL
)
12867 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
12869 strcpy (retval
, lead
);
12870 strcat (retval
, prefix
);
12871 strcat (retval
, sep
);
12872 strcat (retval
, suffix
);
12877 /* We have an obstack. */
12878 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
12882 /* Return sibling of die, NULL if no sibling. */
12884 static struct die_info
*
12885 sibling_die (struct die_info
*die
)
12887 return die
->sibling
;
12890 /* Get name of a die, return NULL if not found. */
12893 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
12894 struct obstack
*obstack
)
12896 if (name
&& cu
->language
== language_cplus
)
12898 char *canon_name
= cp_canonicalize_string (name
);
12900 if (canon_name
!= NULL
)
12902 if (strcmp (canon_name
, name
) != 0)
12903 name
= obsavestring (canon_name
, strlen (canon_name
),
12905 xfree (canon_name
);
12912 /* Get name of a die, return NULL if not found. */
12915 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12917 struct attribute
*attr
;
12919 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
12920 if ((!attr
|| !DW_STRING (attr
))
12921 && die
->tag
!= DW_TAG_class_type
12922 && die
->tag
!= DW_TAG_interface_type
12923 && die
->tag
!= DW_TAG_structure_type
12924 && die
->tag
!= DW_TAG_union_type
)
12929 case DW_TAG_compile_unit
:
12930 /* Compilation units have a DW_AT_name that is a filename, not
12931 a source language identifier. */
12932 case DW_TAG_enumeration_type
:
12933 case DW_TAG_enumerator
:
12934 /* These tags always have simple identifiers already; no need
12935 to canonicalize them. */
12936 return DW_STRING (attr
);
12938 case DW_TAG_subprogram
:
12939 /* Java constructors will all be named "<init>", so return
12940 the class name when we see this special case. */
12941 if (cu
->language
== language_java
12942 && DW_STRING (attr
) != NULL
12943 && strcmp (DW_STRING (attr
), "<init>") == 0)
12945 struct dwarf2_cu
*spec_cu
= cu
;
12946 struct die_info
*spec_die
;
12948 /* GCJ will output '<init>' for Java constructor names.
12949 For this special case, return the name of the parent class. */
12951 /* GCJ may output suprogram DIEs with AT_specification set.
12952 If so, use the name of the specified DIE. */
12953 spec_die
= die_specification (die
, &spec_cu
);
12954 if (spec_die
!= NULL
)
12955 return dwarf2_name (spec_die
, spec_cu
);
12960 if (die
->tag
== DW_TAG_class_type
)
12961 return dwarf2_name (die
, cu
);
12963 while (die
->tag
!= DW_TAG_compile_unit
);
12967 case DW_TAG_class_type
:
12968 case DW_TAG_interface_type
:
12969 case DW_TAG_structure_type
:
12970 case DW_TAG_union_type
:
12971 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
12972 structures or unions. These were of the form "._%d" in GCC 4.1,
12973 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
12974 and GCC 4.4. We work around this problem by ignoring these. */
12975 if (attr
&& DW_STRING (attr
)
12976 && (strncmp (DW_STRING (attr
), "._", 2) == 0
12977 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
12980 /* GCC might emit a nameless typedef that has a linkage name. See
12981 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12982 if (!attr
|| DW_STRING (attr
) == NULL
)
12984 char *demangled
= NULL
;
12986 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
12988 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
12990 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
12993 /* Avoid demangling DW_STRING (attr) the second time on a second
12994 call for the same DIE. */
12995 if (!DW_STRING_IS_CANONICAL (attr
))
12996 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
13002 /* FIXME: we already did this for the partial symbol... */
13003 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
13004 &cu
->objfile
->objfile_obstack
);
13005 DW_STRING_IS_CANONICAL (attr
) = 1;
13008 /* Strip any leading namespaces/classes, keep only the base name.
13009 DW_AT_name for named DIEs does not contain the prefixes. */
13010 base
= strrchr (DW_STRING (attr
), ':');
13011 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
13014 return DW_STRING (attr
);
13023 if (!DW_STRING_IS_CANONICAL (attr
))
13026 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
13027 &cu
->objfile
->objfile_obstack
);
13028 DW_STRING_IS_CANONICAL (attr
) = 1;
13030 return DW_STRING (attr
);
13033 /* Return the die that this die in an extension of, or NULL if there
13034 is none. *EXT_CU is the CU containing DIE on input, and the CU
13035 containing the return value on output. */
13037 static struct die_info
*
13038 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
13040 struct attribute
*attr
;
13042 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
13046 return follow_die_ref (die
, attr
, ext_cu
);
13049 /* Convert a DIE tag into its string name. */
13052 dwarf_tag_name (unsigned tag
)
13056 case DW_TAG_padding
:
13057 return "DW_TAG_padding";
13058 case DW_TAG_array_type
:
13059 return "DW_TAG_array_type";
13060 case DW_TAG_class_type
:
13061 return "DW_TAG_class_type";
13062 case DW_TAG_entry_point
:
13063 return "DW_TAG_entry_point";
13064 case DW_TAG_enumeration_type
:
13065 return "DW_TAG_enumeration_type";
13066 case DW_TAG_formal_parameter
:
13067 return "DW_TAG_formal_parameter";
13068 case DW_TAG_imported_declaration
:
13069 return "DW_TAG_imported_declaration";
13071 return "DW_TAG_label";
13072 case DW_TAG_lexical_block
:
13073 return "DW_TAG_lexical_block";
13074 case DW_TAG_member
:
13075 return "DW_TAG_member";
13076 case DW_TAG_pointer_type
:
13077 return "DW_TAG_pointer_type";
13078 case DW_TAG_reference_type
:
13079 return "DW_TAG_reference_type";
13080 case DW_TAG_compile_unit
:
13081 return "DW_TAG_compile_unit";
13082 case DW_TAG_string_type
:
13083 return "DW_TAG_string_type";
13084 case DW_TAG_structure_type
:
13085 return "DW_TAG_structure_type";
13086 case DW_TAG_subroutine_type
:
13087 return "DW_TAG_subroutine_type";
13088 case DW_TAG_typedef
:
13089 return "DW_TAG_typedef";
13090 case DW_TAG_union_type
:
13091 return "DW_TAG_union_type";
13092 case DW_TAG_unspecified_parameters
:
13093 return "DW_TAG_unspecified_parameters";
13094 case DW_TAG_variant
:
13095 return "DW_TAG_variant";
13096 case DW_TAG_common_block
:
13097 return "DW_TAG_common_block";
13098 case DW_TAG_common_inclusion
:
13099 return "DW_TAG_common_inclusion";
13100 case DW_TAG_inheritance
:
13101 return "DW_TAG_inheritance";
13102 case DW_TAG_inlined_subroutine
:
13103 return "DW_TAG_inlined_subroutine";
13104 case DW_TAG_module
:
13105 return "DW_TAG_module";
13106 case DW_TAG_ptr_to_member_type
:
13107 return "DW_TAG_ptr_to_member_type";
13108 case DW_TAG_set_type
:
13109 return "DW_TAG_set_type";
13110 case DW_TAG_subrange_type
:
13111 return "DW_TAG_subrange_type";
13112 case DW_TAG_with_stmt
:
13113 return "DW_TAG_with_stmt";
13114 case DW_TAG_access_declaration
:
13115 return "DW_TAG_access_declaration";
13116 case DW_TAG_base_type
:
13117 return "DW_TAG_base_type";
13118 case DW_TAG_catch_block
:
13119 return "DW_TAG_catch_block";
13120 case DW_TAG_const_type
:
13121 return "DW_TAG_const_type";
13122 case DW_TAG_constant
:
13123 return "DW_TAG_constant";
13124 case DW_TAG_enumerator
:
13125 return "DW_TAG_enumerator";
13126 case DW_TAG_file_type
:
13127 return "DW_TAG_file_type";
13128 case DW_TAG_friend
:
13129 return "DW_TAG_friend";
13130 case DW_TAG_namelist
:
13131 return "DW_TAG_namelist";
13132 case DW_TAG_namelist_item
:
13133 return "DW_TAG_namelist_item";
13134 case DW_TAG_packed_type
:
13135 return "DW_TAG_packed_type";
13136 case DW_TAG_subprogram
:
13137 return "DW_TAG_subprogram";
13138 case DW_TAG_template_type_param
:
13139 return "DW_TAG_template_type_param";
13140 case DW_TAG_template_value_param
:
13141 return "DW_TAG_template_value_param";
13142 case DW_TAG_thrown_type
:
13143 return "DW_TAG_thrown_type";
13144 case DW_TAG_try_block
:
13145 return "DW_TAG_try_block";
13146 case DW_TAG_variant_part
:
13147 return "DW_TAG_variant_part";
13148 case DW_TAG_variable
:
13149 return "DW_TAG_variable";
13150 case DW_TAG_volatile_type
:
13151 return "DW_TAG_volatile_type";
13152 case DW_TAG_dwarf_procedure
:
13153 return "DW_TAG_dwarf_procedure";
13154 case DW_TAG_restrict_type
:
13155 return "DW_TAG_restrict_type";
13156 case DW_TAG_interface_type
:
13157 return "DW_TAG_interface_type";
13158 case DW_TAG_namespace
:
13159 return "DW_TAG_namespace";
13160 case DW_TAG_imported_module
:
13161 return "DW_TAG_imported_module";
13162 case DW_TAG_unspecified_type
:
13163 return "DW_TAG_unspecified_type";
13164 case DW_TAG_partial_unit
:
13165 return "DW_TAG_partial_unit";
13166 case DW_TAG_imported_unit
:
13167 return "DW_TAG_imported_unit";
13168 case DW_TAG_condition
:
13169 return "DW_TAG_condition";
13170 case DW_TAG_shared_type
:
13171 return "DW_TAG_shared_type";
13172 case DW_TAG_type_unit
:
13173 return "DW_TAG_type_unit";
13174 case DW_TAG_MIPS_loop
:
13175 return "DW_TAG_MIPS_loop";
13176 case DW_TAG_HP_array_descriptor
:
13177 return "DW_TAG_HP_array_descriptor";
13178 case DW_TAG_format_label
:
13179 return "DW_TAG_format_label";
13180 case DW_TAG_function_template
:
13181 return "DW_TAG_function_template";
13182 case DW_TAG_class_template
:
13183 return "DW_TAG_class_template";
13184 case DW_TAG_GNU_BINCL
:
13185 return "DW_TAG_GNU_BINCL";
13186 case DW_TAG_GNU_EINCL
:
13187 return "DW_TAG_GNU_EINCL";
13188 case DW_TAG_upc_shared_type
:
13189 return "DW_TAG_upc_shared_type";
13190 case DW_TAG_upc_strict_type
:
13191 return "DW_TAG_upc_strict_type";
13192 case DW_TAG_upc_relaxed_type
:
13193 return "DW_TAG_upc_relaxed_type";
13194 case DW_TAG_PGI_kanji_type
:
13195 return "DW_TAG_PGI_kanji_type";
13196 case DW_TAG_PGI_interface_block
:
13197 return "DW_TAG_PGI_interface_block";
13198 case DW_TAG_GNU_call_site
:
13199 return "DW_TAG_GNU_call_site";
13201 return "DW_TAG_<unknown>";
13205 /* Convert a DWARF attribute code into its string name. */
13208 dwarf_attr_name (unsigned attr
)
13212 case DW_AT_sibling
:
13213 return "DW_AT_sibling";
13214 case DW_AT_location
:
13215 return "DW_AT_location";
13217 return "DW_AT_name";
13218 case DW_AT_ordering
:
13219 return "DW_AT_ordering";
13220 case DW_AT_subscr_data
:
13221 return "DW_AT_subscr_data";
13222 case DW_AT_byte_size
:
13223 return "DW_AT_byte_size";
13224 case DW_AT_bit_offset
:
13225 return "DW_AT_bit_offset";
13226 case DW_AT_bit_size
:
13227 return "DW_AT_bit_size";
13228 case DW_AT_element_list
:
13229 return "DW_AT_element_list";
13230 case DW_AT_stmt_list
:
13231 return "DW_AT_stmt_list";
13233 return "DW_AT_low_pc";
13234 case DW_AT_high_pc
:
13235 return "DW_AT_high_pc";
13236 case DW_AT_language
:
13237 return "DW_AT_language";
13239 return "DW_AT_member";
13241 return "DW_AT_discr";
13242 case DW_AT_discr_value
:
13243 return "DW_AT_discr_value";
13244 case DW_AT_visibility
:
13245 return "DW_AT_visibility";
13247 return "DW_AT_import";
13248 case DW_AT_string_length
:
13249 return "DW_AT_string_length";
13250 case DW_AT_common_reference
:
13251 return "DW_AT_common_reference";
13252 case DW_AT_comp_dir
:
13253 return "DW_AT_comp_dir";
13254 case DW_AT_const_value
:
13255 return "DW_AT_const_value";
13256 case DW_AT_containing_type
:
13257 return "DW_AT_containing_type";
13258 case DW_AT_default_value
:
13259 return "DW_AT_default_value";
13261 return "DW_AT_inline";
13262 case DW_AT_is_optional
:
13263 return "DW_AT_is_optional";
13264 case DW_AT_lower_bound
:
13265 return "DW_AT_lower_bound";
13266 case DW_AT_producer
:
13267 return "DW_AT_producer";
13268 case DW_AT_prototyped
:
13269 return "DW_AT_prototyped";
13270 case DW_AT_return_addr
:
13271 return "DW_AT_return_addr";
13272 case DW_AT_start_scope
:
13273 return "DW_AT_start_scope";
13274 case DW_AT_bit_stride
:
13275 return "DW_AT_bit_stride";
13276 case DW_AT_upper_bound
:
13277 return "DW_AT_upper_bound";
13278 case DW_AT_abstract_origin
:
13279 return "DW_AT_abstract_origin";
13280 case DW_AT_accessibility
:
13281 return "DW_AT_accessibility";
13282 case DW_AT_address_class
:
13283 return "DW_AT_address_class";
13284 case DW_AT_artificial
:
13285 return "DW_AT_artificial";
13286 case DW_AT_base_types
:
13287 return "DW_AT_base_types";
13288 case DW_AT_calling_convention
:
13289 return "DW_AT_calling_convention";
13291 return "DW_AT_count";
13292 case DW_AT_data_member_location
:
13293 return "DW_AT_data_member_location";
13294 case DW_AT_decl_column
:
13295 return "DW_AT_decl_column";
13296 case DW_AT_decl_file
:
13297 return "DW_AT_decl_file";
13298 case DW_AT_decl_line
:
13299 return "DW_AT_decl_line";
13300 case DW_AT_declaration
:
13301 return "DW_AT_declaration";
13302 case DW_AT_discr_list
:
13303 return "DW_AT_discr_list";
13304 case DW_AT_encoding
:
13305 return "DW_AT_encoding";
13306 case DW_AT_external
:
13307 return "DW_AT_external";
13308 case DW_AT_frame_base
:
13309 return "DW_AT_frame_base";
13311 return "DW_AT_friend";
13312 case DW_AT_identifier_case
:
13313 return "DW_AT_identifier_case";
13314 case DW_AT_macro_info
:
13315 return "DW_AT_macro_info";
13316 case DW_AT_namelist_items
:
13317 return "DW_AT_namelist_items";
13318 case DW_AT_priority
:
13319 return "DW_AT_priority";
13320 case DW_AT_segment
:
13321 return "DW_AT_segment";
13322 case DW_AT_specification
:
13323 return "DW_AT_specification";
13324 case DW_AT_static_link
:
13325 return "DW_AT_static_link";
13327 return "DW_AT_type";
13328 case DW_AT_use_location
:
13329 return "DW_AT_use_location";
13330 case DW_AT_variable_parameter
:
13331 return "DW_AT_variable_parameter";
13332 case DW_AT_virtuality
:
13333 return "DW_AT_virtuality";
13334 case DW_AT_vtable_elem_location
:
13335 return "DW_AT_vtable_elem_location";
13336 /* DWARF 3 values. */
13337 case DW_AT_allocated
:
13338 return "DW_AT_allocated";
13339 case DW_AT_associated
:
13340 return "DW_AT_associated";
13341 case DW_AT_data_location
:
13342 return "DW_AT_data_location";
13343 case DW_AT_byte_stride
:
13344 return "DW_AT_byte_stride";
13345 case DW_AT_entry_pc
:
13346 return "DW_AT_entry_pc";
13347 case DW_AT_use_UTF8
:
13348 return "DW_AT_use_UTF8";
13349 case DW_AT_extension
:
13350 return "DW_AT_extension";
13352 return "DW_AT_ranges";
13353 case DW_AT_trampoline
:
13354 return "DW_AT_trampoline";
13355 case DW_AT_call_column
:
13356 return "DW_AT_call_column";
13357 case DW_AT_call_file
:
13358 return "DW_AT_call_file";
13359 case DW_AT_call_line
:
13360 return "DW_AT_call_line";
13361 case DW_AT_description
:
13362 return "DW_AT_description";
13363 case DW_AT_binary_scale
:
13364 return "DW_AT_binary_scale";
13365 case DW_AT_decimal_scale
:
13366 return "DW_AT_decimal_scale";
13368 return "DW_AT_small";
13369 case DW_AT_decimal_sign
:
13370 return "DW_AT_decimal_sign";
13371 case DW_AT_digit_count
:
13372 return "DW_AT_digit_count";
13373 case DW_AT_picture_string
:
13374 return "DW_AT_picture_string";
13375 case DW_AT_mutable
:
13376 return "DW_AT_mutable";
13377 case DW_AT_threads_scaled
:
13378 return "DW_AT_threads_scaled";
13379 case DW_AT_explicit
:
13380 return "DW_AT_explicit";
13381 case DW_AT_object_pointer
:
13382 return "DW_AT_object_pointer";
13383 case DW_AT_endianity
:
13384 return "DW_AT_endianity";
13385 case DW_AT_elemental
:
13386 return "DW_AT_elemental";
13388 return "DW_AT_pure";
13389 case DW_AT_recursive
:
13390 return "DW_AT_recursive";
13391 /* DWARF 4 values. */
13392 case DW_AT_signature
:
13393 return "DW_AT_signature";
13394 case DW_AT_linkage_name
:
13395 return "DW_AT_linkage_name";
13396 /* SGI/MIPS extensions. */
13397 #ifdef MIPS /* collides with DW_AT_HP_block_index */
13398 case DW_AT_MIPS_fde
:
13399 return "DW_AT_MIPS_fde";
13401 case DW_AT_MIPS_loop_begin
:
13402 return "DW_AT_MIPS_loop_begin";
13403 case DW_AT_MIPS_tail_loop_begin
:
13404 return "DW_AT_MIPS_tail_loop_begin";
13405 case DW_AT_MIPS_epilog_begin
:
13406 return "DW_AT_MIPS_epilog_begin";
13407 case DW_AT_MIPS_loop_unroll_factor
:
13408 return "DW_AT_MIPS_loop_unroll_factor";
13409 case DW_AT_MIPS_software_pipeline_depth
:
13410 return "DW_AT_MIPS_software_pipeline_depth";
13411 case DW_AT_MIPS_linkage_name
:
13412 return "DW_AT_MIPS_linkage_name";
13413 case DW_AT_MIPS_stride
:
13414 return "DW_AT_MIPS_stride";
13415 case DW_AT_MIPS_abstract_name
:
13416 return "DW_AT_MIPS_abstract_name";
13417 case DW_AT_MIPS_clone_origin
:
13418 return "DW_AT_MIPS_clone_origin";
13419 case DW_AT_MIPS_has_inlines
:
13420 return "DW_AT_MIPS_has_inlines";
13421 /* HP extensions. */
13422 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
13423 case DW_AT_HP_block_index
:
13424 return "DW_AT_HP_block_index";
13426 case DW_AT_HP_unmodifiable
:
13427 return "DW_AT_HP_unmodifiable";
13428 case DW_AT_HP_actuals_stmt_list
:
13429 return "DW_AT_HP_actuals_stmt_list";
13430 case DW_AT_HP_proc_per_section
:
13431 return "DW_AT_HP_proc_per_section";
13432 case DW_AT_HP_raw_data_ptr
:
13433 return "DW_AT_HP_raw_data_ptr";
13434 case DW_AT_HP_pass_by_reference
:
13435 return "DW_AT_HP_pass_by_reference";
13436 case DW_AT_HP_opt_level
:
13437 return "DW_AT_HP_opt_level";
13438 case DW_AT_HP_prof_version_id
:
13439 return "DW_AT_HP_prof_version_id";
13440 case DW_AT_HP_opt_flags
:
13441 return "DW_AT_HP_opt_flags";
13442 case DW_AT_HP_cold_region_low_pc
:
13443 return "DW_AT_HP_cold_region_low_pc";
13444 case DW_AT_HP_cold_region_high_pc
:
13445 return "DW_AT_HP_cold_region_high_pc";
13446 case DW_AT_HP_all_variables_modifiable
:
13447 return "DW_AT_HP_all_variables_modifiable";
13448 case DW_AT_HP_linkage_name
:
13449 return "DW_AT_HP_linkage_name";
13450 case DW_AT_HP_prof_flags
:
13451 return "DW_AT_HP_prof_flags";
13452 /* GNU extensions. */
13453 case DW_AT_sf_names
:
13454 return "DW_AT_sf_names";
13455 case DW_AT_src_info
:
13456 return "DW_AT_src_info";
13457 case DW_AT_mac_info
:
13458 return "DW_AT_mac_info";
13459 case DW_AT_src_coords
:
13460 return "DW_AT_src_coords";
13461 case DW_AT_body_begin
:
13462 return "DW_AT_body_begin";
13463 case DW_AT_body_end
:
13464 return "DW_AT_body_end";
13465 case DW_AT_GNU_vector
:
13466 return "DW_AT_GNU_vector";
13467 case DW_AT_GNU_odr_signature
:
13468 return "DW_AT_GNU_odr_signature";
13469 /* VMS extensions. */
13470 case DW_AT_VMS_rtnbeg_pd_address
:
13471 return "DW_AT_VMS_rtnbeg_pd_address";
13472 /* UPC extension. */
13473 case DW_AT_upc_threads_scaled
:
13474 return "DW_AT_upc_threads_scaled";
13475 /* PGI (STMicroelectronics) extensions. */
13476 case DW_AT_PGI_lbase
:
13477 return "DW_AT_PGI_lbase";
13478 case DW_AT_PGI_soffset
:
13479 return "DW_AT_PGI_soffset";
13480 case DW_AT_PGI_lstride
:
13481 return "DW_AT_PGI_lstride";
13483 return "DW_AT_<unknown>";
13487 /* Convert a DWARF value form code into its string name. */
13490 dwarf_form_name (unsigned form
)
13495 return "DW_FORM_addr";
13496 case DW_FORM_block2
:
13497 return "DW_FORM_block2";
13498 case DW_FORM_block4
:
13499 return "DW_FORM_block4";
13500 case DW_FORM_data2
:
13501 return "DW_FORM_data2";
13502 case DW_FORM_data4
:
13503 return "DW_FORM_data4";
13504 case DW_FORM_data8
:
13505 return "DW_FORM_data8";
13506 case DW_FORM_string
:
13507 return "DW_FORM_string";
13508 case DW_FORM_block
:
13509 return "DW_FORM_block";
13510 case DW_FORM_block1
:
13511 return "DW_FORM_block1";
13512 case DW_FORM_data1
:
13513 return "DW_FORM_data1";
13515 return "DW_FORM_flag";
13516 case DW_FORM_sdata
:
13517 return "DW_FORM_sdata";
13519 return "DW_FORM_strp";
13520 case DW_FORM_udata
:
13521 return "DW_FORM_udata";
13522 case DW_FORM_ref_addr
:
13523 return "DW_FORM_ref_addr";
13525 return "DW_FORM_ref1";
13527 return "DW_FORM_ref2";
13529 return "DW_FORM_ref4";
13531 return "DW_FORM_ref8";
13532 case DW_FORM_ref_udata
:
13533 return "DW_FORM_ref_udata";
13534 case DW_FORM_indirect
:
13535 return "DW_FORM_indirect";
13536 case DW_FORM_sec_offset
:
13537 return "DW_FORM_sec_offset";
13538 case DW_FORM_exprloc
:
13539 return "DW_FORM_exprloc";
13540 case DW_FORM_flag_present
:
13541 return "DW_FORM_flag_present";
13542 case DW_FORM_ref_sig8
:
13543 return "DW_FORM_ref_sig8";
13545 return "DW_FORM_<unknown>";
13549 /* Convert a DWARF stack opcode into its string name. */
13552 dwarf_stack_op_name (unsigned op
)
13557 return "DW_OP_addr";
13559 return "DW_OP_deref";
13560 case DW_OP_const1u
:
13561 return "DW_OP_const1u";
13562 case DW_OP_const1s
:
13563 return "DW_OP_const1s";
13564 case DW_OP_const2u
:
13565 return "DW_OP_const2u";
13566 case DW_OP_const2s
:
13567 return "DW_OP_const2s";
13568 case DW_OP_const4u
:
13569 return "DW_OP_const4u";
13570 case DW_OP_const4s
:
13571 return "DW_OP_const4s";
13572 case DW_OP_const8u
:
13573 return "DW_OP_const8u";
13574 case DW_OP_const8s
:
13575 return "DW_OP_const8s";
13577 return "DW_OP_constu";
13579 return "DW_OP_consts";
13581 return "DW_OP_dup";
13583 return "DW_OP_drop";
13585 return "DW_OP_over";
13587 return "DW_OP_pick";
13589 return "DW_OP_swap";
13591 return "DW_OP_rot";
13593 return "DW_OP_xderef";
13595 return "DW_OP_abs";
13597 return "DW_OP_and";
13599 return "DW_OP_div";
13601 return "DW_OP_minus";
13603 return "DW_OP_mod";
13605 return "DW_OP_mul";
13607 return "DW_OP_neg";
13609 return "DW_OP_not";
13613 return "DW_OP_plus";
13614 case DW_OP_plus_uconst
:
13615 return "DW_OP_plus_uconst";
13617 return "DW_OP_shl";
13619 return "DW_OP_shr";
13621 return "DW_OP_shra";
13623 return "DW_OP_xor";
13625 return "DW_OP_bra";
13639 return "DW_OP_skip";
13641 return "DW_OP_lit0";
13643 return "DW_OP_lit1";
13645 return "DW_OP_lit2";
13647 return "DW_OP_lit3";
13649 return "DW_OP_lit4";
13651 return "DW_OP_lit5";
13653 return "DW_OP_lit6";
13655 return "DW_OP_lit7";
13657 return "DW_OP_lit8";
13659 return "DW_OP_lit9";
13661 return "DW_OP_lit10";
13663 return "DW_OP_lit11";
13665 return "DW_OP_lit12";
13667 return "DW_OP_lit13";
13669 return "DW_OP_lit14";
13671 return "DW_OP_lit15";
13673 return "DW_OP_lit16";
13675 return "DW_OP_lit17";
13677 return "DW_OP_lit18";
13679 return "DW_OP_lit19";
13681 return "DW_OP_lit20";
13683 return "DW_OP_lit21";
13685 return "DW_OP_lit22";
13687 return "DW_OP_lit23";
13689 return "DW_OP_lit24";
13691 return "DW_OP_lit25";
13693 return "DW_OP_lit26";
13695 return "DW_OP_lit27";
13697 return "DW_OP_lit28";
13699 return "DW_OP_lit29";
13701 return "DW_OP_lit30";
13703 return "DW_OP_lit31";
13705 return "DW_OP_reg0";
13707 return "DW_OP_reg1";
13709 return "DW_OP_reg2";
13711 return "DW_OP_reg3";
13713 return "DW_OP_reg4";
13715 return "DW_OP_reg5";
13717 return "DW_OP_reg6";
13719 return "DW_OP_reg7";
13721 return "DW_OP_reg8";
13723 return "DW_OP_reg9";
13725 return "DW_OP_reg10";
13727 return "DW_OP_reg11";
13729 return "DW_OP_reg12";
13731 return "DW_OP_reg13";
13733 return "DW_OP_reg14";
13735 return "DW_OP_reg15";
13737 return "DW_OP_reg16";
13739 return "DW_OP_reg17";
13741 return "DW_OP_reg18";
13743 return "DW_OP_reg19";
13745 return "DW_OP_reg20";
13747 return "DW_OP_reg21";
13749 return "DW_OP_reg22";
13751 return "DW_OP_reg23";
13753 return "DW_OP_reg24";
13755 return "DW_OP_reg25";
13757 return "DW_OP_reg26";
13759 return "DW_OP_reg27";
13761 return "DW_OP_reg28";
13763 return "DW_OP_reg29";
13765 return "DW_OP_reg30";
13767 return "DW_OP_reg31";
13769 return "DW_OP_breg0";
13771 return "DW_OP_breg1";
13773 return "DW_OP_breg2";
13775 return "DW_OP_breg3";
13777 return "DW_OP_breg4";
13779 return "DW_OP_breg5";
13781 return "DW_OP_breg6";
13783 return "DW_OP_breg7";
13785 return "DW_OP_breg8";
13787 return "DW_OP_breg9";
13789 return "DW_OP_breg10";
13791 return "DW_OP_breg11";
13793 return "DW_OP_breg12";
13795 return "DW_OP_breg13";
13797 return "DW_OP_breg14";
13799 return "DW_OP_breg15";
13801 return "DW_OP_breg16";
13803 return "DW_OP_breg17";
13805 return "DW_OP_breg18";
13807 return "DW_OP_breg19";
13809 return "DW_OP_breg20";
13811 return "DW_OP_breg21";
13813 return "DW_OP_breg22";
13815 return "DW_OP_breg23";
13817 return "DW_OP_breg24";
13819 return "DW_OP_breg25";
13821 return "DW_OP_breg26";
13823 return "DW_OP_breg27";
13825 return "DW_OP_breg28";
13827 return "DW_OP_breg29";
13829 return "DW_OP_breg30";
13831 return "DW_OP_breg31";
13833 return "DW_OP_regx";
13835 return "DW_OP_fbreg";
13837 return "DW_OP_bregx";
13839 return "DW_OP_piece";
13840 case DW_OP_deref_size
:
13841 return "DW_OP_deref_size";
13842 case DW_OP_xderef_size
:
13843 return "DW_OP_xderef_size";
13845 return "DW_OP_nop";
13846 /* DWARF 3 extensions. */
13847 case DW_OP_push_object_address
:
13848 return "DW_OP_push_object_address";
13850 return "DW_OP_call2";
13852 return "DW_OP_call4";
13853 case DW_OP_call_ref
:
13854 return "DW_OP_call_ref";
13855 case DW_OP_form_tls_address
:
13856 return "DW_OP_form_tls_address";
13857 case DW_OP_call_frame_cfa
:
13858 return "DW_OP_call_frame_cfa";
13859 case DW_OP_bit_piece
:
13860 return "DW_OP_bit_piece";
13861 /* DWARF 4 extensions. */
13862 case DW_OP_implicit_value
:
13863 return "DW_OP_implicit_value";
13864 case DW_OP_stack_value
:
13865 return "DW_OP_stack_value";
13866 /* GNU extensions. */
13867 case DW_OP_GNU_push_tls_address
:
13868 return "DW_OP_GNU_push_tls_address";
13869 case DW_OP_GNU_uninit
:
13870 return "DW_OP_GNU_uninit";
13871 case DW_OP_GNU_encoded_addr
:
13872 return "DW_OP_GNU_encoded_addr";
13873 case DW_OP_GNU_implicit_pointer
:
13874 return "DW_OP_GNU_implicit_pointer";
13875 case DW_OP_GNU_entry_value
:
13876 return "DW_OP_GNU_entry_value";
13877 case DW_OP_GNU_const_type
:
13878 return "DW_OP_GNU_const_type";
13879 case DW_OP_GNU_regval_type
:
13880 return "DW_OP_GNU_regval_type";
13881 case DW_OP_GNU_deref_type
:
13882 return "DW_OP_GNU_deref_type";
13883 case DW_OP_GNU_convert
:
13884 return "DW_OP_GNU_convert";
13885 case DW_OP_GNU_reinterpret
:
13886 return "DW_OP_GNU_reinterpret";
13887 case DW_OP_GNU_parameter_ref
:
13888 return "DW_OP_GNU_parameter_ref";
13895 dwarf_bool_name (unsigned mybool
)
13903 /* Convert a DWARF type code into its string name. */
13906 dwarf_type_encoding_name (unsigned enc
)
13911 return "DW_ATE_void";
13912 case DW_ATE_address
:
13913 return "DW_ATE_address";
13914 case DW_ATE_boolean
:
13915 return "DW_ATE_boolean";
13916 case DW_ATE_complex_float
:
13917 return "DW_ATE_complex_float";
13919 return "DW_ATE_float";
13920 case DW_ATE_signed
:
13921 return "DW_ATE_signed";
13922 case DW_ATE_signed_char
:
13923 return "DW_ATE_signed_char";
13924 case DW_ATE_unsigned
:
13925 return "DW_ATE_unsigned";
13926 case DW_ATE_unsigned_char
:
13927 return "DW_ATE_unsigned_char";
13929 case DW_ATE_imaginary_float
:
13930 return "DW_ATE_imaginary_float";
13931 case DW_ATE_packed_decimal
:
13932 return "DW_ATE_packed_decimal";
13933 case DW_ATE_numeric_string
:
13934 return "DW_ATE_numeric_string";
13935 case DW_ATE_edited
:
13936 return "DW_ATE_edited";
13937 case DW_ATE_signed_fixed
:
13938 return "DW_ATE_signed_fixed";
13939 case DW_ATE_unsigned_fixed
:
13940 return "DW_ATE_unsigned_fixed";
13941 case DW_ATE_decimal_float
:
13942 return "DW_ATE_decimal_float";
13945 return "DW_ATE_UTF";
13946 /* HP extensions. */
13947 case DW_ATE_HP_float80
:
13948 return "DW_ATE_HP_float80";
13949 case DW_ATE_HP_complex_float80
:
13950 return "DW_ATE_HP_complex_float80";
13951 case DW_ATE_HP_float128
:
13952 return "DW_ATE_HP_float128";
13953 case DW_ATE_HP_complex_float128
:
13954 return "DW_ATE_HP_complex_float128";
13955 case DW_ATE_HP_floathpintel
:
13956 return "DW_ATE_HP_floathpintel";
13957 case DW_ATE_HP_imaginary_float80
:
13958 return "DW_ATE_HP_imaginary_float80";
13959 case DW_ATE_HP_imaginary_float128
:
13960 return "DW_ATE_HP_imaginary_float128";
13962 return "DW_ATE_<unknown>";
13966 /* Convert a DWARF call frame info operation to its string name. */
13970 dwarf_cfi_name (unsigned cfi_opc
)
13974 case DW_CFA_advance_loc
:
13975 return "DW_CFA_advance_loc";
13976 case DW_CFA_offset
:
13977 return "DW_CFA_offset";
13978 case DW_CFA_restore
:
13979 return "DW_CFA_restore";
13981 return "DW_CFA_nop";
13982 case DW_CFA_set_loc
:
13983 return "DW_CFA_set_loc";
13984 case DW_CFA_advance_loc1
:
13985 return "DW_CFA_advance_loc1";
13986 case DW_CFA_advance_loc2
:
13987 return "DW_CFA_advance_loc2";
13988 case DW_CFA_advance_loc4
:
13989 return "DW_CFA_advance_loc4";
13990 case DW_CFA_offset_extended
:
13991 return "DW_CFA_offset_extended";
13992 case DW_CFA_restore_extended
:
13993 return "DW_CFA_restore_extended";
13994 case DW_CFA_undefined
:
13995 return "DW_CFA_undefined";
13996 case DW_CFA_same_value
:
13997 return "DW_CFA_same_value";
13998 case DW_CFA_register
:
13999 return "DW_CFA_register";
14000 case DW_CFA_remember_state
:
14001 return "DW_CFA_remember_state";
14002 case DW_CFA_restore_state
:
14003 return "DW_CFA_restore_state";
14004 case DW_CFA_def_cfa
:
14005 return "DW_CFA_def_cfa";
14006 case DW_CFA_def_cfa_register
:
14007 return "DW_CFA_def_cfa_register";
14008 case DW_CFA_def_cfa_offset
:
14009 return "DW_CFA_def_cfa_offset";
14011 case DW_CFA_def_cfa_expression
:
14012 return "DW_CFA_def_cfa_expression";
14013 case DW_CFA_expression
:
14014 return "DW_CFA_expression";
14015 case DW_CFA_offset_extended_sf
:
14016 return "DW_CFA_offset_extended_sf";
14017 case DW_CFA_def_cfa_sf
:
14018 return "DW_CFA_def_cfa_sf";
14019 case DW_CFA_def_cfa_offset_sf
:
14020 return "DW_CFA_def_cfa_offset_sf";
14021 case DW_CFA_val_offset
:
14022 return "DW_CFA_val_offset";
14023 case DW_CFA_val_offset_sf
:
14024 return "DW_CFA_val_offset_sf";
14025 case DW_CFA_val_expression
:
14026 return "DW_CFA_val_expression";
14027 /* SGI/MIPS specific. */
14028 case DW_CFA_MIPS_advance_loc8
:
14029 return "DW_CFA_MIPS_advance_loc8";
14030 /* GNU extensions. */
14031 case DW_CFA_GNU_window_save
:
14032 return "DW_CFA_GNU_window_save";
14033 case DW_CFA_GNU_args_size
:
14034 return "DW_CFA_GNU_args_size";
14035 case DW_CFA_GNU_negative_offset_extended
:
14036 return "DW_CFA_GNU_negative_offset_extended";
14038 return "DW_CFA_<unknown>";
14044 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
14048 print_spaces (indent
, f
);
14049 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
14050 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
.sect_off
);
14052 if (die
->parent
!= NULL
)
14054 print_spaces (indent
, f
);
14055 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
14056 die
->parent
->offset
.sect_off
);
14059 print_spaces (indent
, f
);
14060 fprintf_unfiltered (f
, " has children: %s\n",
14061 dwarf_bool_name (die
->child
!= NULL
));
14063 print_spaces (indent
, f
);
14064 fprintf_unfiltered (f
, " attributes:\n");
14066 for (i
= 0; i
< die
->num_attrs
; ++i
)
14068 print_spaces (indent
, f
);
14069 fprintf_unfiltered (f
, " %s (%s) ",
14070 dwarf_attr_name (die
->attrs
[i
].name
),
14071 dwarf_form_name (die
->attrs
[i
].form
));
14073 switch (die
->attrs
[i
].form
)
14076 fprintf_unfiltered (f
, "address: ");
14077 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
14079 case DW_FORM_block2
:
14080 case DW_FORM_block4
:
14081 case DW_FORM_block
:
14082 case DW_FORM_block1
:
14083 fprintf_unfiltered (f
, "block: size %d",
14084 DW_BLOCK (&die
->attrs
[i
])->size
);
14086 case DW_FORM_exprloc
:
14087 fprintf_unfiltered (f
, "expression: size %u",
14088 DW_BLOCK (&die
->attrs
[i
])->size
);
14090 case DW_FORM_ref_addr
:
14091 fprintf_unfiltered (f
, "ref address: ");
14092 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
14098 case DW_FORM_ref_udata
:
14099 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
14100 (long) (DW_UNSND (&die
->attrs
[i
])));
14102 case DW_FORM_data1
:
14103 case DW_FORM_data2
:
14104 case DW_FORM_data4
:
14105 case DW_FORM_data8
:
14106 case DW_FORM_udata
:
14107 case DW_FORM_sdata
:
14108 fprintf_unfiltered (f
, "constant: %s",
14109 pulongest (DW_UNSND (&die
->attrs
[i
])));
14111 case DW_FORM_sec_offset
:
14112 fprintf_unfiltered (f
, "section offset: %s",
14113 pulongest (DW_UNSND (&die
->attrs
[i
])));
14115 case DW_FORM_ref_sig8
:
14116 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
14117 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
14118 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
.sect_off
);
14120 fprintf_unfiltered (f
, "signatured type, offset: unknown");
14122 case DW_FORM_string
:
14124 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
14125 DW_STRING (&die
->attrs
[i
])
14126 ? DW_STRING (&die
->attrs
[i
]) : "",
14127 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
14130 if (DW_UNSND (&die
->attrs
[i
]))
14131 fprintf_unfiltered (f
, "flag: TRUE");
14133 fprintf_unfiltered (f
, "flag: FALSE");
14135 case DW_FORM_flag_present
:
14136 fprintf_unfiltered (f
, "flag: TRUE");
14138 case DW_FORM_indirect
:
14139 /* The reader will have reduced the indirect form to
14140 the "base form" so this form should not occur. */
14141 fprintf_unfiltered (f
,
14142 "unexpected attribute form: DW_FORM_indirect");
14145 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
14146 die
->attrs
[i
].form
);
14149 fprintf_unfiltered (f
, "\n");
14154 dump_die_for_error (struct die_info
*die
)
14156 dump_die_shallow (gdb_stderr
, 0, die
);
14160 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
14162 int indent
= level
* 4;
14164 gdb_assert (die
!= NULL
);
14166 if (level
>= max_level
)
14169 dump_die_shallow (f
, indent
, die
);
14171 if (die
->child
!= NULL
)
14173 print_spaces (indent
, f
);
14174 fprintf_unfiltered (f
, " Children:");
14175 if (level
+ 1 < max_level
)
14177 fprintf_unfiltered (f
, "\n");
14178 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
14182 fprintf_unfiltered (f
,
14183 " [not printed, max nesting level reached]\n");
14187 if (die
->sibling
!= NULL
&& level
> 0)
14189 dump_die_1 (f
, level
, max_level
, die
->sibling
);
14193 /* This is called from the pdie macro in gdbinit.in.
14194 It's not static so gcc will keep a copy callable from gdb. */
14197 dump_die (struct die_info
*die
, int max_level
)
14199 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
14203 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
14207 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
.sect_off
,
14213 /* DW_ADDR is always stored already as sect_offset; despite for the forms
14214 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
14217 is_ref_attr (struct attribute
*attr
)
14219 switch (attr
->form
)
14221 case DW_FORM_ref_addr
:
14226 case DW_FORM_ref_udata
:
14233 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
14237 dwarf2_get_ref_die_offset (struct attribute
*attr
)
14239 sect_offset retval
= { DW_UNSND (attr
) };
14241 if (is_ref_attr (attr
))
14244 retval
.sect_off
= 0;
14245 complaint (&symfile_complaints
,
14246 _("unsupported die ref attribute form: '%s'"),
14247 dwarf_form_name (attr
->form
));
14251 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
14252 * the value held by the attribute is not constant. */
14255 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
14257 if (attr
->form
== DW_FORM_sdata
)
14258 return DW_SND (attr
);
14259 else if (attr
->form
== DW_FORM_udata
14260 || attr
->form
== DW_FORM_data1
14261 || attr
->form
== DW_FORM_data2
14262 || attr
->form
== DW_FORM_data4
14263 || attr
->form
== DW_FORM_data8
)
14264 return DW_UNSND (attr
);
14267 complaint (&symfile_complaints
,
14268 _("Attribute value is not a constant (%s)"),
14269 dwarf_form_name (attr
->form
));
14270 return default_value
;
14274 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
14275 unit and add it to our queue.
14276 The result is non-zero if PER_CU was queued, otherwise the result is zero
14277 meaning either PER_CU is already queued or it is already loaded. */
14280 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
14281 struct dwarf2_per_cu_data
*per_cu
)
14283 /* We may arrive here during partial symbol reading, if we need full
14284 DIEs to process an unusual case (e.g. template arguments). Do
14285 not queue PER_CU, just tell our caller to load its DIEs. */
14286 if (dwarf2_per_objfile
->reading_partial_symbols
)
14288 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
14293 /* Mark the dependence relation so that we don't flush PER_CU
14295 dwarf2_add_dependence (this_cu
, per_cu
);
14297 /* If it's already on the queue, we have nothing to do. */
14298 if (per_cu
->queued
)
14301 /* If the compilation unit is already loaded, just mark it as
14303 if (per_cu
->cu
!= NULL
)
14305 per_cu
->cu
->last_used
= 0;
14309 /* Add it to the queue. */
14310 queue_comp_unit (per_cu
);
14315 /* Follow reference or signature attribute ATTR of SRC_DIE.
14316 On entry *REF_CU is the CU of SRC_DIE.
14317 On exit *REF_CU is the CU of the result. */
14319 static struct die_info
*
14320 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
14321 struct dwarf2_cu
**ref_cu
)
14323 struct die_info
*die
;
14325 if (is_ref_attr (attr
))
14326 die
= follow_die_ref (src_die
, attr
, ref_cu
);
14327 else if (attr
->form
== DW_FORM_ref_sig8
)
14328 die
= follow_die_sig (src_die
, attr
, ref_cu
);
14331 dump_die_for_error (src_die
);
14332 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
14333 (*ref_cu
)->objfile
->name
);
14339 /* Follow reference OFFSET.
14340 On entry *REF_CU is the CU of the source die referencing OFFSET.
14341 On exit *REF_CU is the CU of the result.
14342 Returns NULL if OFFSET is invalid. */
14344 static struct die_info
*
14345 follow_die_offset (sect_offset offset
, struct dwarf2_cu
**ref_cu
)
14347 struct die_info temp_die
;
14348 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
14350 gdb_assert (cu
->per_cu
!= NULL
);
14354 if (cu
->per_cu
->debug_types_section
)
14356 /* .debug_types CUs cannot reference anything outside their CU.
14357 If they need to, they have to reference a signatured type via
14358 DW_FORM_ref_sig8. */
14359 if (! offset_in_cu_p (&cu
->header
, offset
))
14362 else if (! offset_in_cu_p (&cu
->header
, offset
))
14364 struct dwarf2_per_cu_data
*per_cu
;
14366 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
14368 /* If necessary, add it to the queue and load its DIEs. */
14369 if (maybe_queue_comp_unit (cu
, per_cu
))
14370 load_full_comp_unit (per_cu
);
14372 target_cu
= per_cu
->cu
;
14374 else if (cu
->dies
== NULL
)
14376 /* We're loading full DIEs during partial symbol reading. */
14377 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
14378 load_full_comp_unit (cu
->per_cu
);
14381 *ref_cu
= target_cu
;
14382 temp_die
.offset
= offset
;
14383 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
.sect_off
);
14386 /* Follow reference attribute ATTR of SRC_DIE.
14387 On entry *REF_CU is the CU of SRC_DIE.
14388 On exit *REF_CU is the CU of the result. */
14390 static struct die_info
*
14391 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
14392 struct dwarf2_cu
**ref_cu
)
14394 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
14395 struct dwarf2_cu
*cu
= *ref_cu
;
14396 struct die_info
*die
;
14398 die
= follow_die_offset (offset
, ref_cu
);
14400 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
14401 "at 0x%x [in module %s]"),
14402 offset
.sect_off
, src_die
->offset
.sect_off
, cu
->objfile
->name
);
14407 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
14408 Returned value is intended for DW_OP_call*. Returned
14409 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
14411 struct dwarf2_locexpr_baton
14412 dwarf2_fetch_die_location_block (cu_offset offset_in_cu
,
14413 struct dwarf2_per_cu_data
*per_cu
,
14414 CORE_ADDR (*get_frame_pc
) (void *baton
),
14417 sect_offset offset
= { per_cu
->offset
.sect_off
+ offset_in_cu
.cu_off
};
14418 struct dwarf2_cu
*cu
;
14419 struct die_info
*die
;
14420 struct attribute
*attr
;
14421 struct dwarf2_locexpr_baton retval
;
14423 dw2_setup (per_cu
->objfile
);
14425 if (per_cu
->cu
== NULL
)
14429 die
= follow_die_offset (offset
, &cu
);
14431 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
14432 offset
.sect_off
, per_cu
->objfile
->name
);
14434 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
14437 /* DWARF: "If there is no such attribute, then there is no effect.".
14438 DATA is ignored if SIZE is 0. */
14440 retval
.data
= NULL
;
14443 else if (attr_form_is_section_offset (attr
))
14445 struct dwarf2_loclist_baton loclist_baton
;
14446 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
14449 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
14451 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
14453 retval
.size
= size
;
14457 if (!attr_form_is_block (attr
))
14458 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
14459 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
14460 offset
.sect_off
, per_cu
->objfile
->name
);
14462 retval
.data
= DW_BLOCK (attr
)->data
;
14463 retval
.size
= DW_BLOCK (attr
)->size
;
14465 retval
.per_cu
= cu
->per_cu
;
14467 age_cached_comp_units ();
14472 /* Return the type of the DIE at DIE_OFFSET in the CU named by
14476 dwarf2_get_die_type (cu_offset die_offset
,
14477 struct dwarf2_per_cu_data
*per_cu
)
14479 sect_offset die_offset_sect
;
14481 dw2_setup (per_cu
->objfile
);
14483 die_offset_sect
.sect_off
= per_cu
->offset
.sect_off
+ die_offset
.cu_off
;
14484 return get_die_type_at_offset (die_offset_sect
, per_cu
);
14487 /* Follow the signature attribute ATTR in SRC_DIE.
14488 On entry *REF_CU is the CU of SRC_DIE.
14489 On exit *REF_CU is the CU of the result. */
14491 static struct die_info
*
14492 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
14493 struct dwarf2_cu
**ref_cu
)
14495 struct objfile
*objfile
= (*ref_cu
)->objfile
;
14496 struct die_info temp_die
;
14497 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
14498 struct dwarf2_cu
*sig_cu
;
14499 struct die_info
*die
;
14501 /* sig_type will be NULL if the signatured type is missing from
14503 if (sig_type
== NULL
)
14504 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
14505 "at 0x%x [in module %s]"),
14506 src_die
->offset
.sect_off
, objfile
->name
);
14508 /* If necessary, add it to the queue and load its DIEs. */
14510 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
14511 read_signatured_type (sig_type
);
14513 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
14515 sig_cu
= sig_type
->per_cu
.cu
;
14516 temp_die
.offset
.sect_off
= (sig_type
->per_cu
.offset
.sect_off
14517 + sig_type
->type_offset
.cu_off
);
14518 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
14519 temp_die
.offset
.sect_off
);
14526 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
14527 "from DIE at 0x%x [in module %s]"),
14528 temp_die
.offset
.sect_off
, src_die
->offset
.sect_off
, objfile
->name
);
14531 /* Given an offset of a signatured type, return its signatured_type. */
14533 static struct signatured_type
*
14534 lookup_signatured_type_at_offset (struct objfile
*objfile
,
14535 struct dwarf2_section_info
*section
,
14536 sect_offset offset
)
14538 gdb_byte
*info_ptr
= section
->buffer
+ offset
.sect_off
;
14539 unsigned int length
, initial_length_size
;
14540 unsigned int sig_offset
;
14541 struct signatured_type find_entry
, *sig_type
;
14543 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
14544 sig_offset
= (initial_length_size
14546 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
14547 + 1 /*address_size*/);
14548 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
14549 sig_type
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
14551 /* This is only used to lookup previously recorded types.
14552 If we didn't find it, it's our bug. */
14553 gdb_assert (sig_type
!= NULL
);
14554 gdb_assert (offset
.sect_off
== sig_type
->per_cu
.offset
.sect_off
);
14559 /* Load the DIEs associated with type unit PER_CU into memory. */
14562 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
14564 struct objfile
*objfile
= per_cu
->objfile
;
14565 struct dwarf2_section_info
*sect
= per_cu
->debug_types_section
;
14566 sect_offset offset
= per_cu
->offset
;
14567 struct signatured_type
*sig_type
;
14569 dwarf2_read_section (objfile
, sect
);
14571 /* We have the section offset, but we need the signature to do the
14572 hash table lookup. */
14573 /* FIXME: This is sorta unnecessary, read_signatured_type only uses
14574 the signature to assert we found the right one.
14575 Ok, but it's a lot of work. We should simplify things so any needed
14576 assert doesn't require all this clumsiness. */
14577 sig_type
= lookup_signatured_type_at_offset (objfile
, sect
, offset
);
14579 gdb_assert (sig_type
->per_cu
.cu
== NULL
);
14581 read_signatured_type (sig_type
);
14583 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
14586 /* Read in a signatured type and build its CU and DIEs. */
14589 read_signatured_type (struct signatured_type
*sig_type
)
14591 struct objfile
*objfile
= sig_type
->per_cu
.objfile
;
14592 gdb_byte
*types_ptr
;
14593 struct die_reader_specs reader_specs
;
14594 struct dwarf2_cu
*cu
;
14595 ULONGEST signature
;
14596 struct cleanup
*back_to
, *free_cu_cleanup
;
14597 struct dwarf2_section_info
*section
= sig_type
->per_cu
.debug_types_section
;
14599 dwarf2_read_section (objfile
, section
);
14600 types_ptr
= section
->buffer
+ sig_type
->per_cu
.offset
.sect_off
;
14602 gdb_assert (sig_type
->per_cu
.cu
== NULL
);
14604 cu
= xmalloc (sizeof (*cu
));
14605 init_one_comp_unit (cu
, &sig_type
->per_cu
);
14607 /* If an error occurs while loading, release our storage. */
14608 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
14610 types_ptr
= read_and_check_type_unit_head (&cu
->header
, section
, types_ptr
,
14612 gdb_assert (signature
== sig_type
->signature
);
14615 = htab_create_alloc_ex (cu
->header
.length
/ 12,
14619 &cu
->comp_unit_obstack
,
14620 hashtab_obstack_allocate
,
14621 dummy_obstack_deallocate
);
14623 dwarf2_read_abbrevs (cu
);
14624 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
14626 init_cu_die_reader (&reader_specs
, cu
);
14628 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
14631 /* We try not to read any attributes in this function, because not
14632 all CUs needed for references have been loaded yet, and symbol
14633 table processing isn't initialized. But we have to set the CU language,
14634 or we won't be able to build types correctly. */
14635 prepare_one_comp_unit (cu
, cu
->dies
);
14637 do_cleanups (back_to
);
14639 /* We've successfully allocated this compilation unit. Let our caller
14640 clean it up when finished with it. */
14641 discard_cleanups (free_cu_cleanup
);
14643 /* Link this TU into read_in_chain. */
14644 sig_type
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
14645 dwarf2_per_objfile
->read_in_chain
= &sig_type
->per_cu
;
14648 /* Decode simple location descriptions.
14649 Given a pointer to a dwarf block that defines a location, compute
14650 the location and return the value.
14652 NOTE drow/2003-11-18: This function is called in two situations
14653 now: for the address of static or global variables (partial symbols
14654 only) and for offsets into structures which are expected to be
14655 (more or less) constant. The partial symbol case should go away,
14656 and only the constant case should remain. That will let this
14657 function complain more accurately. A few special modes are allowed
14658 without complaint for global variables (for instance, global
14659 register values and thread-local values).
14661 A location description containing no operations indicates that the
14662 object is optimized out. The return value is 0 for that case.
14663 FIXME drow/2003-11-16: No callers check for this case any more; soon all
14664 callers will only want a very basic result and this can become a
14667 Note that stack[0] is unused except as a default error return. */
14670 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
14672 struct objfile
*objfile
= cu
->objfile
;
14674 int size
= blk
->size
;
14675 gdb_byte
*data
= blk
->data
;
14676 CORE_ADDR stack
[64];
14678 unsigned int bytes_read
, unsnd
;
14684 stack
[++stacki
] = 0;
14723 stack
[++stacki
] = op
- DW_OP_lit0
;
14758 stack
[++stacki
] = op
- DW_OP_reg0
;
14760 dwarf2_complex_location_expr_complaint ();
14764 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
14766 stack
[++stacki
] = unsnd
;
14768 dwarf2_complex_location_expr_complaint ();
14772 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
14777 case DW_OP_const1u
:
14778 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
14782 case DW_OP_const1s
:
14783 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
14787 case DW_OP_const2u
:
14788 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
14792 case DW_OP_const2s
:
14793 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
14797 case DW_OP_const4u
:
14798 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
14802 case DW_OP_const4s
:
14803 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
14807 case DW_OP_const8u
:
14808 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
14813 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
14819 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
14824 stack
[stacki
+ 1] = stack
[stacki
];
14829 stack
[stacki
- 1] += stack
[stacki
];
14833 case DW_OP_plus_uconst
:
14834 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
14840 stack
[stacki
- 1] -= stack
[stacki
];
14845 /* If we're not the last op, then we definitely can't encode
14846 this using GDB's address_class enum. This is valid for partial
14847 global symbols, although the variable's address will be bogus
14850 dwarf2_complex_location_expr_complaint ();
14853 case DW_OP_GNU_push_tls_address
:
14854 /* The top of the stack has the offset from the beginning
14855 of the thread control block at which the variable is located. */
14856 /* Nothing should follow this operator, so the top of stack would
14858 /* This is valid for partial global symbols, but the variable's
14859 address will be bogus in the psymtab. Make it always at least
14860 non-zero to not look as a variable garbage collected by linker
14861 which have DW_OP_addr 0. */
14863 dwarf2_complex_location_expr_complaint ();
14867 case DW_OP_GNU_uninit
:
14872 const char *name
= dwarf_stack_op_name (op
);
14875 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
14878 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
14882 return (stack
[stacki
]);
14885 /* Enforce maximum stack depth of SIZE-1 to avoid writing
14886 outside of the allocated space. Also enforce minimum>0. */
14887 if (stacki
>= ARRAY_SIZE (stack
) - 1)
14889 complaint (&symfile_complaints
,
14890 _("location description stack overflow"));
14896 complaint (&symfile_complaints
,
14897 _("location description stack underflow"));
14901 return (stack
[stacki
]);
14904 /* memory allocation interface */
14906 static struct dwarf_block
*
14907 dwarf_alloc_block (struct dwarf2_cu
*cu
)
14909 struct dwarf_block
*blk
;
14911 blk
= (struct dwarf_block
*)
14912 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
14916 static struct abbrev_info
*
14917 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
14919 struct abbrev_info
*abbrev
;
14921 abbrev
= (struct abbrev_info
*)
14922 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
14923 memset (abbrev
, 0, sizeof (struct abbrev_info
));
14927 static struct die_info
*
14928 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
14930 struct die_info
*die
;
14931 size_t size
= sizeof (struct die_info
);
14934 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
14936 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
14937 memset (die
, 0, sizeof (struct die_info
));
14942 /* Macro support. */
14944 /* Return the full name of file number I in *LH's file name table.
14945 Use COMP_DIR as the name of the current directory of the
14946 compilation. The result is allocated using xmalloc; the caller is
14947 responsible for freeing it. */
14949 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
14951 /* Is the file number a valid index into the line header's file name
14952 table? Remember that file numbers start with one, not zero. */
14953 if (1 <= file
&& file
<= lh
->num_file_names
)
14955 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
14957 if (IS_ABSOLUTE_PATH (fe
->name
))
14958 return xstrdup (fe
->name
);
14966 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14972 dir_len
= strlen (dir
);
14973 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
14974 strcpy (full_name
, dir
);
14975 full_name
[dir_len
] = '/';
14976 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
14980 return xstrdup (fe
->name
);
14985 /* The compiler produced a bogus file number. We can at least
14986 record the macro definitions made in the file, even if we
14987 won't be able to find the file by name. */
14988 char fake_name
[80];
14990 sprintf (fake_name
, "<bad macro file number %d>", file
);
14992 complaint (&symfile_complaints
,
14993 _("bad file number in macro information (%d)"),
14996 return xstrdup (fake_name
);
15001 static struct macro_source_file
*
15002 macro_start_file (int file
, int line
,
15003 struct macro_source_file
*current_file
,
15004 const char *comp_dir
,
15005 struct line_header
*lh
, struct objfile
*objfile
)
15007 /* The full name of this source file. */
15008 char *full_name
= file_full_name (file
, lh
, comp_dir
);
15010 /* We don't create a macro table for this compilation unit
15011 at all until we actually get a filename. */
15012 if (! pending_macros
)
15013 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
15014 objfile
->macro_cache
);
15016 if (! current_file
)
15017 /* If we have no current file, then this must be the start_file
15018 directive for the compilation unit's main source file. */
15019 current_file
= macro_set_main (pending_macros
, full_name
);
15021 current_file
= macro_include (current_file
, line
, full_name
);
15025 return current_file
;
15029 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
15030 followed by a null byte. */
15032 copy_string (const char *buf
, int len
)
15034 char *s
= xmalloc (len
+ 1);
15036 memcpy (s
, buf
, len
);
15042 static const char *
15043 consume_improper_spaces (const char *p
, const char *body
)
15047 complaint (&symfile_complaints
,
15048 _("macro definition contains spaces "
15049 "in formal argument list:\n`%s'"),
15061 parse_macro_definition (struct macro_source_file
*file
, int line
,
15066 /* The body string takes one of two forms. For object-like macro
15067 definitions, it should be:
15069 <macro name> " " <definition>
15071 For function-like macro definitions, it should be:
15073 <macro name> "() " <definition>
15075 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
15077 Spaces may appear only where explicitly indicated, and in the
15080 The Dwarf 2 spec says that an object-like macro's name is always
15081 followed by a space, but versions of GCC around March 2002 omit
15082 the space when the macro's definition is the empty string.
15084 The Dwarf 2 spec says that there should be no spaces between the
15085 formal arguments in a function-like macro's formal argument list,
15086 but versions of GCC around March 2002 include spaces after the
15090 /* Find the extent of the macro name. The macro name is terminated
15091 by either a space or null character (for an object-like macro) or
15092 an opening paren (for a function-like macro). */
15093 for (p
= body
; *p
; p
++)
15094 if (*p
== ' ' || *p
== '(')
15097 if (*p
== ' ' || *p
== '\0')
15099 /* It's an object-like macro. */
15100 int name_len
= p
- body
;
15101 char *name
= copy_string (body
, name_len
);
15102 const char *replacement
;
15105 replacement
= body
+ name_len
+ 1;
15108 dwarf2_macro_malformed_definition_complaint (body
);
15109 replacement
= body
+ name_len
;
15112 macro_define_object (file
, line
, name
, replacement
);
15116 else if (*p
== '(')
15118 /* It's a function-like macro. */
15119 char *name
= copy_string (body
, p
- body
);
15122 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
15126 p
= consume_improper_spaces (p
, body
);
15128 /* Parse the formal argument list. */
15129 while (*p
&& *p
!= ')')
15131 /* Find the extent of the current argument name. */
15132 const char *arg_start
= p
;
15134 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
15137 if (! *p
|| p
== arg_start
)
15138 dwarf2_macro_malformed_definition_complaint (body
);
15141 /* Make sure argv has room for the new argument. */
15142 if (argc
>= argv_size
)
15145 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
15148 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
15151 p
= consume_improper_spaces (p
, body
);
15153 /* Consume the comma, if present. */
15158 p
= consume_improper_spaces (p
, body
);
15167 /* Perfectly formed definition, no complaints. */
15168 macro_define_function (file
, line
, name
,
15169 argc
, (const char **) argv
,
15171 else if (*p
== '\0')
15173 /* Complain, but do define it. */
15174 dwarf2_macro_malformed_definition_complaint (body
);
15175 macro_define_function (file
, line
, name
,
15176 argc
, (const char **) argv
,
15180 /* Just complain. */
15181 dwarf2_macro_malformed_definition_complaint (body
);
15184 /* Just complain. */
15185 dwarf2_macro_malformed_definition_complaint (body
);
15191 for (i
= 0; i
< argc
; i
++)
15197 dwarf2_macro_malformed_definition_complaint (body
);
15200 /* Skip some bytes from BYTES according to the form given in FORM.
15201 Returns the new pointer. */
15204 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
,
15205 enum dwarf_form form
,
15206 unsigned int offset_size
,
15207 struct dwarf2_section_info
*section
)
15209 unsigned int bytes_read
;
15213 case DW_FORM_data1
:
15218 case DW_FORM_data2
:
15222 case DW_FORM_data4
:
15226 case DW_FORM_data8
:
15230 case DW_FORM_string
:
15231 read_direct_string (abfd
, bytes
, &bytes_read
);
15232 bytes
+= bytes_read
;
15235 case DW_FORM_sec_offset
:
15237 bytes
+= offset_size
;
15240 case DW_FORM_block
:
15241 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
15242 bytes
+= bytes_read
;
15245 case DW_FORM_block1
:
15246 bytes
+= 1 + read_1_byte (abfd
, bytes
);
15248 case DW_FORM_block2
:
15249 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
15251 case DW_FORM_block4
:
15252 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
15255 case DW_FORM_sdata
:
15256 case DW_FORM_udata
:
15257 bytes
= skip_leb128 (abfd
, bytes
);
15263 complaint (&symfile_complaints
,
15264 _("invalid form 0x%x in `%s'"),
15266 section
->asection
->name
);
15274 /* A helper for dwarf_decode_macros that handles skipping an unknown
15275 opcode. Returns an updated pointer to the macro data buffer; or,
15276 on error, issues a complaint and returns NULL. */
15279 skip_unknown_opcode (unsigned int opcode
,
15280 gdb_byte
**opcode_definitions
,
15283 unsigned int offset_size
,
15284 struct dwarf2_section_info
*section
)
15286 unsigned int bytes_read
, i
;
15290 if (opcode_definitions
[opcode
] == NULL
)
15292 complaint (&symfile_complaints
,
15293 _("unrecognized DW_MACFINO opcode 0x%x"),
15298 defn
= opcode_definitions
[opcode
];
15299 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
15300 defn
+= bytes_read
;
15302 for (i
= 0; i
< arg
; ++i
)
15304 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, defn
[i
], offset_size
, section
);
15305 if (mac_ptr
== NULL
)
15307 /* skip_form_bytes already issued the complaint. */
15315 /* A helper function which parses the header of a macro section.
15316 If the macro section is the extended (for now called "GNU") type,
15317 then this updates *OFFSET_SIZE. Returns a pointer to just after
15318 the header, or issues a complaint and returns NULL on error. */
15321 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
15324 unsigned int *offset_size
,
15325 int section_is_gnu
)
15327 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
15329 if (section_is_gnu
)
15331 unsigned int version
, flags
;
15333 version
= read_2_bytes (abfd
, mac_ptr
);
15336 complaint (&symfile_complaints
,
15337 _("unrecognized version `%d' in .debug_macro section"),
15343 flags
= read_1_byte (abfd
, mac_ptr
);
15345 *offset_size
= (flags
& 1) ? 8 : 4;
15347 if ((flags
& 2) != 0)
15348 /* We don't need the line table offset. */
15349 mac_ptr
+= *offset_size
;
15351 /* Vendor opcode descriptions. */
15352 if ((flags
& 4) != 0)
15354 unsigned int i
, count
;
15356 count
= read_1_byte (abfd
, mac_ptr
);
15358 for (i
= 0; i
< count
; ++i
)
15360 unsigned int opcode
, bytes_read
;
15363 opcode
= read_1_byte (abfd
, mac_ptr
);
15365 opcode_definitions
[opcode
] = mac_ptr
;
15366 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15367 mac_ptr
+= bytes_read
;
15376 /* A helper for dwarf_decode_macros that handles the GNU extensions,
15377 including DW_MACRO_GNU_transparent_include. */
15380 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
15381 struct macro_source_file
*current_file
,
15382 struct line_header
*lh
, char *comp_dir
,
15383 struct dwarf2_section_info
*section
,
15384 int section_is_gnu
,
15385 unsigned int offset_size
,
15386 struct objfile
*objfile
,
15387 htab_t include_hash
)
15389 enum dwarf_macro_record_type macinfo_type
;
15390 int at_commandline
;
15391 gdb_byte
*opcode_definitions
[256];
15393 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
15394 &offset_size
, section_is_gnu
);
15395 if (mac_ptr
== NULL
)
15397 /* We already issued a complaint. */
15401 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
15402 GDB is still reading the definitions from command line. First
15403 DW_MACINFO_start_file will need to be ignored as it was already executed
15404 to create CURRENT_FILE for the main source holding also the command line
15405 definitions. On first met DW_MACINFO_start_file this flag is reset to
15406 normally execute all the remaining DW_MACINFO_start_file macinfos. */
15408 at_commandline
= 1;
15412 /* Do we at least have room for a macinfo type byte? */
15413 if (mac_ptr
>= mac_end
)
15415 dwarf2_macros_too_long_complaint (section
);
15419 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
15422 /* Note that we rely on the fact that the corresponding GNU and
15423 DWARF constants are the same. */
15424 switch (macinfo_type
)
15426 /* A zero macinfo type indicates the end of the macro
15431 case DW_MACRO_GNU_define
:
15432 case DW_MACRO_GNU_undef
:
15433 case DW_MACRO_GNU_define_indirect
:
15434 case DW_MACRO_GNU_undef_indirect
:
15436 unsigned int bytes_read
;
15441 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15442 mac_ptr
+= bytes_read
;
15444 if (macinfo_type
== DW_MACRO_GNU_define
15445 || macinfo_type
== DW_MACRO_GNU_undef
)
15447 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15448 mac_ptr
+= bytes_read
;
15452 LONGEST str_offset
;
15454 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
15455 mac_ptr
+= offset_size
;
15457 body
= read_indirect_string_at_offset (abfd
, str_offset
);
15460 is_define
= (macinfo_type
== DW_MACRO_GNU_define
15461 || macinfo_type
== DW_MACRO_GNU_define_indirect
);
15462 if (! current_file
)
15464 /* DWARF violation as no main source is present. */
15465 complaint (&symfile_complaints
,
15466 _("debug info with no main source gives macro %s "
15468 is_define
? _("definition") : _("undefinition"),
15472 if ((line
== 0 && !at_commandline
)
15473 || (line
!= 0 && at_commandline
))
15474 complaint (&symfile_complaints
,
15475 _("debug info gives %s macro %s with %s line %d: %s"),
15476 at_commandline
? _("command-line") : _("in-file"),
15477 is_define
? _("definition") : _("undefinition"),
15478 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
15481 parse_macro_definition (current_file
, line
, body
);
15484 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
15485 || macinfo_type
== DW_MACRO_GNU_undef_indirect
);
15486 macro_undef (current_file
, line
, body
);
15491 case DW_MACRO_GNU_start_file
:
15493 unsigned int bytes_read
;
15496 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15497 mac_ptr
+= bytes_read
;
15498 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15499 mac_ptr
+= bytes_read
;
15501 if ((line
== 0 && !at_commandline
)
15502 || (line
!= 0 && at_commandline
))
15503 complaint (&symfile_complaints
,
15504 _("debug info gives source %d included "
15505 "from %s at %s line %d"),
15506 file
, at_commandline
? _("command-line") : _("file"),
15507 line
== 0 ? _("zero") : _("non-zero"), line
);
15509 if (at_commandline
)
15511 /* This DW_MACRO_GNU_start_file was executed in the
15513 at_commandline
= 0;
15516 current_file
= macro_start_file (file
, line
,
15517 current_file
, comp_dir
,
15522 case DW_MACRO_GNU_end_file
:
15523 if (! current_file
)
15524 complaint (&symfile_complaints
,
15525 _("macro debug info has an unmatched "
15526 "`close_file' directive"));
15529 current_file
= current_file
->included_by
;
15530 if (! current_file
)
15532 enum dwarf_macro_record_type next_type
;
15534 /* GCC circa March 2002 doesn't produce the zero
15535 type byte marking the end of the compilation
15536 unit. Complain if it's not there, but exit no
15539 /* Do we at least have room for a macinfo type byte? */
15540 if (mac_ptr
>= mac_end
)
15542 dwarf2_macros_too_long_complaint (section
);
15546 /* We don't increment mac_ptr here, so this is just
15548 next_type
= read_1_byte (abfd
, mac_ptr
);
15549 if (next_type
!= 0)
15550 complaint (&symfile_complaints
,
15551 _("no terminating 0-type entry for "
15552 "macros in `.debug_macinfo' section"));
15559 case DW_MACRO_GNU_transparent_include
:
15564 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
15565 mac_ptr
+= offset_size
;
15567 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
15570 /* This has actually happened; see
15571 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
15572 complaint (&symfile_complaints
,
15573 _("recursive DW_MACRO_GNU_transparent_include in "
15574 ".debug_macro section"));
15580 dwarf_decode_macro_bytes (abfd
,
15581 section
->buffer
+ offset
,
15582 mac_end
, current_file
,
15584 section
, section_is_gnu
,
15585 offset_size
, objfile
, include_hash
);
15587 htab_remove_elt (include_hash
, mac_ptr
);
15592 case DW_MACINFO_vendor_ext
:
15593 if (!section_is_gnu
)
15595 unsigned int bytes_read
;
15598 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15599 mac_ptr
+= bytes_read
;
15600 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15601 mac_ptr
+= bytes_read
;
15603 /* We don't recognize any vendor extensions. */
15609 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
15610 mac_ptr
, abfd
, offset_size
,
15612 if (mac_ptr
== NULL
)
15616 } while (macinfo_type
!= 0);
15620 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
15621 char *comp_dir
, bfd
*abfd
,
15622 struct dwarf2_cu
*cu
,
15623 struct dwarf2_section_info
*section
,
15624 int section_is_gnu
)
15626 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15627 gdb_byte
*mac_ptr
, *mac_end
;
15628 struct macro_source_file
*current_file
= 0;
15629 enum dwarf_macro_record_type macinfo_type
;
15630 unsigned int offset_size
= cu
->header
.offset_size
;
15631 gdb_byte
*opcode_definitions
[256];
15632 struct cleanup
*cleanup
;
15633 htab_t include_hash
;
15636 dwarf2_read_section (objfile
, section
);
15637 if (section
->buffer
== NULL
)
15639 complaint (&symfile_complaints
, _("missing %s section"),
15640 section
->asection
->name
);
15644 /* First pass: Find the name of the base filename.
15645 This filename is needed in order to process all macros whose definition
15646 (or undefinition) comes from the command line. These macros are defined
15647 before the first DW_MACINFO_start_file entry, and yet still need to be
15648 associated to the base file.
15650 To determine the base file name, we scan the macro definitions until we
15651 reach the first DW_MACINFO_start_file entry. We then initialize
15652 CURRENT_FILE accordingly so that any macro definition found before the
15653 first DW_MACINFO_start_file can still be associated to the base file. */
15655 mac_ptr
= section
->buffer
+ offset
;
15656 mac_end
= section
->buffer
+ section
->size
;
15658 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
15659 &offset_size
, section_is_gnu
);
15660 if (mac_ptr
== NULL
)
15662 /* We already issued a complaint. */
15668 /* Do we at least have room for a macinfo type byte? */
15669 if (mac_ptr
>= mac_end
)
15671 /* Complaint is printed during the second pass as GDB will probably
15672 stop the first pass earlier upon finding
15673 DW_MACINFO_start_file. */
15677 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
15680 /* Note that we rely on the fact that the corresponding GNU and
15681 DWARF constants are the same. */
15682 switch (macinfo_type
)
15684 /* A zero macinfo type indicates the end of the macro
15689 case DW_MACRO_GNU_define
:
15690 case DW_MACRO_GNU_undef
:
15691 /* Only skip the data by MAC_PTR. */
15693 unsigned int bytes_read
;
15695 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15696 mac_ptr
+= bytes_read
;
15697 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15698 mac_ptr
+= bytes_read
;
15702 case DW_MACRO_GNU_start_file
:
15704 unsigned int bytes_read
;
15707 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15708 mac_ptr
+= bytes_read
;
15709 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15710 mac_ptr
+= bytes_read
;
15712 current_file
= macro_start_file (file
, line
, current_file
,
15713 comp_dir
, lh
, objfile
);
15717 case DW_MACRO_GNU_end_file
:
15718 /* No data to skip by MAC_PTR. */
15721 case DW_MACRO_GNU_define_indirect
:
15722 case DW_MACRO_GNU_undef_indirect
:
15724 unsigned int bytes_read
;
15726 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15727 mac_ptr
+= bytes_read
;
15728 mac_ptr
+= offset_size
;
15732 case DW_MACRO_GNU_transparent_include
:
15733 /* Note that, according to the spec, a transparent include
15734 chain cannot call DW_MACRO_GNU_start_file. So, we can just
15735 skip this opcode. */
15736 mac_ptr
+= offset_size
;
15739 case DW_MACINFO_vendor_ext
:
15740 /* Only skip the data by MAC_PTR. */
15741 if (!section_is_gnu
)
15743 unsigned int bytes_read
;
15745 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15746 mac_ptr
+= bytes_read
;
15747 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15748 mac_ptr
+= bytes_read
;
15753 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
15754 mac_ptr
, abfd
, offset_size
,
15756 if (mac_ptr
== NULL
)
15760 } while (macinfo_type
!= 0 && current_file
== NULL
);
15762 /* Second pass: Process all entries.
15764 Use the AT_COMMAND_LINE flag to determine whether we are still processing
15765 command-line macro definitions/undefinitions. This flag is unset when we
15766 reach the first DW_MACINFO_start_file entry. */
15768 include_hash
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
15769 NULL
, xcalloc
, xfree
);
15770 cleanup
= make_cleanup_htab_delete (include_hash
);
15771 mac_ptr
= section
->buffer
+ offset
;
15772 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
15774 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
15775 current_file
, lh
, comp_dir
, section
, section_is_gnu
,
15776 offset_size
, objfile
, include_hash
);
15777 do_cleanups (cleanup
);
15780 /* Check if the attribute's form is a DW_FORM_block*
15781 if so return true else false. */
15784 attr_form_is_block (struct attribute
*attr
)
15786 return (attr
== NULL
? 0 :
15787 attr
->form
== DW_FORM_block1
15788 || attr
->form
== DW_FORM_block2
15789 || attr
->form
== DW_FORM_block4
15790 || attr
->form
== DW_FORM_block
15791 || attr
->form
== DW_FORM_exprloc
);
15794 /* Return non-zero if ATTR's value is a section offset --- classes
15795 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
15796 You may use DW_UNSND (attr) to retrieve such offsets.
15798 Section 7.5.4, "Attribute Encodings", explains that no attribute
15799 may have a value that belongs to more than one of these classes; it
15800 would be ambiguous if we did, because we use the same forms for all
15804 attr_form_is_section_offset (struct attribute
*attr
)
15806 return (attr
->form
== DW_FORM_data4
15807 || attr
->form
== DW_FORM_data8
15808 || attr
->form
== DW_FORM_sec_offset
);
15812 /* Return non-zero if ATTR's value falls in the 'constant' class, or
15813 zero otherwise. When this function returns true, you can apply
15814 dwarf2_get_attr_constant_value to it.
15816 However, note that for some attributes you must check
15817 attr_form_is_section_offset before using this test. DW_FORM_data4
15818 and DW_FORM_data8 are members of both the constant class, and of
15819 the classes that contain offsets into other debug sections
15820 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
15821 that, if an attribute's can be either a constant or one of the
15822 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
15823 taken as section offsets, not constants. */
15826 attr_form_is_constant (struct attribute
*attr
)
15828 switch (attr
->form
)
15830 case DW_FORM_sdata
:
15831 case DW_FORM_udata
:
15832 case DW_FORM_data1
:
15833 case DW_FORM_data2
:
15834 case DW_FORM_data4
:
15835 case DW_FORM_data8
:
15842 /* A helper function that fills in a dwarf2_loclist_baton. */
15845 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
15846 struct dwarf2_loclist_baton
*baton
,
15847 struct attribute
*attr
)
15849 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
15850 &dwarf2_per_objfile
->loc
);
15852 baton
->per_cu
= cu
->per_cu
;
15853 gdb_assert (baton
->per_cu
);
15854 /* We don't know how long the location list is, but make sure we
15855 don't run off the edge of the section. */
15856 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
15857 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
15858 baton
->base_address
= cu
->base_address
;
15862 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
15863 struct dwarf2_cu
*cu
)
15865 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15867 if (attr_form_is_section_offset (attr
)
15868 /* ".debug_loc" may not exist at all, or the offset may be outside
15869 the section. If so, fall through to the complaint in the
15871 && DW_UNSND (attr
) < dwarf2_section_size (objfile
,
15872 &dwarf2_per_objfile
->loc
))
15874 struct dwarf2_loclist_baton
*baton
;
15876 baton
= obstack_alloc (&objfile
->objfile_obstack
,
15877 sizeof (struct dwarf2_loclist_baton
));
15879 fill_in_loclist_baton (cu
, baton
, attr
);
15881 if (cu
->base_known
== 0)
15882 complaint (&symfile_complaints
,
15883 _("Location list used without "
15884 "specifying the CU base address."));
15886 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
15887 SYMBOL_LOCATION_BATON (sym
) = baton
;
15891 struct dwarf2_locexpr_baton
*baton
;
15893 baton
= obstack_alloc (&objfile
->objfile_obstack
,
15894 sizeof (struct dwarf2_locexpr_baton
));
15895 baton
->per_cu
= cu
->per_cu
;
15896 gdb_assert (baton
->per_cu
);
15898 if (attr_form_is_block (attr
))
15900 /* Note that we're just copying the block's data pointer
15901 here, not the actual data. We're still pointing into the
15902 info_buffer for SYM's objfile; right now we never release
15903 that buffer, but when we do clean up properly this may
15905 baton
->size
= DW_BLOCK (attr
)->size
;
15906 baton
->data
= DW_BLOCK (attr
)->data
;
15910 dwarf2_invalid_attrib_class_complaint ("location description",
15911 SYMBOL_NATURAL_NAME (sym
));
15915 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
15916 SYMBOL_LOCATION_BATON (sym
) = baton
;
15920 /* Return the OBJFILE associated with the compilation unit CU. If CU
15921 came from a separate debuginfo file, then the master objfile is
15925 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
15927 struct objfile
*objfile
= per_cu
->objfile
;
15929 /* Return the master objfile, so that we can report and look up the
15930 correct file containing this variable. */
15931 if (objfile
->separate_debug_objfile_backlink
)
15932 objfile
= objfile
->separate_debug_objfile_backlink
;
15937 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
15938 (CU_HEADERP is unused in such case) or prepare a temporary copy at
15939 CU_HEADERP first. */
15941 static const struct comp_unit_head
*
15942 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
15943 struct dwarf2_per_cu_data
*per_cu
)
15945 struct objfile
*objfile
;
15946 struct dwarf2_per_objfile
*per_objfile
;
15947 gdb_byte
*info_ptr
;
15950 return &per_cu
->cu
->header
;
15952 objfile
= per_cu
->objfile
;
15953 per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
15954 info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
.sect_off
;
15956 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
15957 read_comp_unit_head (cu_headerp
, info_ptr
, objfile
->obfd
);
15962 /* Return the address size given in the compilation unit header for CU. */
15965 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
15967 struct comp_unit_head cu_header_local
;
15968 const struct comp_unit_head
*cu_headerp
;
15970 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
15972 return cu_headerp
->addr_size
;
15975 /* Return the offset size given in the compilation unit header for CU. */
15978 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
15980 struct comp_unit_head cu_header_local
;
15981 const struct comp_unit_head
*cu_headerp
;
15983 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
15985 return cu_headerp
->offset_size
;
15988 /* See its dwarf2loc.h declaration. */
15991 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
15993 struct comp_unit_head cu_header_local
;
15994 const struct comp_unit_head
*cu_headerp
;
15996 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
15998 if (cu_headerp
->version
== 2)
15999 return cu_headerp
->addr_size
;
16001 return cu_headerp
->offset_size
;
16004 /* Return the text offset of the CU. The returned offset comes from
16005 this CU's objfile. If this objfile came from a separate debuginfo
16006 file, then the offset may be different from the corresponding
16007 offset in the parent objfile. */
16010 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
16012 struct objfile
*objfile
= per_cu
->objfile
;
16014 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
16017 /* Locate the .debug_info compilation unit from CU's objfile which contains
16018 the DIE at OFFSET. Raises an error on failure. */
16020 static struct dwarf2_per_cu_data
*
16021 dwarf2_find_containing_comp_unit (sect_offset offset
,
16022 struct objfile
*objfile
)
16024 struct dwarf2_per_cu_data
*this_cu
;
16028 high
= dwarf2_per_objfile
->n_comp_units
- 1;
16031 int mid
= low
+ (high
- low
) / 2;
16033 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
.sect_off
16034 >= offset
.sect_off
)
16039 gdb_assert (low
== high
);
16040 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
.sect_off
16044 error (_("Dwarf Error: could not find partial DIE containing "
16045 "offset 0x%lx [in module %s]"),
16046 (long) offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
16048 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
.sect_off
16049 <= offset
.sect_off
);
16050 return dwarf2_per_objfile
->all_comp_units
[low
-1];
16054 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
16055 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
16056 && offset
.sect_off
>= this_cu
->offset
.sect_off
+ this_cu
->length
)
16057 error (_("invalid dwarf2 offset %u"), offset
.sect_off
);
16058 gdb_assert (offset
.sect_off
< this_cu
->offset
.sect_off
+ this_cu
->length
);
16063 /* Initialize dwarf2_cu CU, owned by PER_CU. */
16066 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
16068 memset (cu
, 0, sizeof (*cu
));
16070 cu
->per_cu
= per_cu
;
16071 cu
->objfile
= per_cu
->objfile
;
16072 obstack_init (&cu
->comp_unit_obstack
);
16075 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
16078 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
)
16080 struct attribute
*attr
;
16082 /* Set the language we're debugging. */
16083 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
16085 set_cu_language (DW_UNSND (attr
), cu
);
16088 cu
->language
= language_minimal
;
16089 cu
->language_defn
= language_def (cu
->language
);
16093 /* Release one cached compilation unit, CU. We unlink it from the tree
16094 of compilation units, but we don't remove it from the read_in_chain;
16095 the caller is responsible for that.
16096 NOTE: DATA is a void * because this function is also used as a
16097 cleanup routine. */
16100 free_heap_comp_unit (void *data
)
16102 struct dwarf2_cu
*cu
= data
;
16104 gdb_assert (cu
->per_cu
!= NULL
);
16105 cu
->per_cu
->cu
= NULL
;
16108 obstack_free (&cu
->comp_unit_obstack
, NULL
);
16113 /* This cleanup function is passed the address of a dwarf2_cu on the stack
16114 when we're finished with it. We can't free the pointer itself, but be
16115 sure to unlink it from the cache. Also release any associated storage
16116 and perform cache maintenance.
16118 Only used during partial symbol parsing. */
16121 free_stack_comp_unit (void *data
)
16123 struct dwarf2_cu
*cu
= data
;
16125 gdb_assert (cu
->per_cu
!= NULL
);
16126 cu
->per_cu
->cu
= NULL
;
16129 obstack_free (&cu
->comp_unit_obstack
, NULL
);
16130 cu
->partial_dies
= NULL
;
16132 /* The previous code only did this if per_cu != NULL.
16133 But that would always succeed, so now we just unconditionally do
16134 the aging. This seems like the wrong place to do such aging,
16135 but cleaning that up is left for later. */
16136 age_cached_comp_units ();
16139 /* Free all cached compilation units. */
16142 free_cached_comp_units (void *data
)
16144 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
16146 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16147 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
16148 while (per_cu
!= NULL
)
16150 struct dwarf2_per_cu_data
*next_cu
;
16152 next_cu
= per_cu
->cu
->read_in_chain
;
16154 free_heap_comp_unit (per_cu
->cu
);
16155 *last_chain
= next_cu
;
16161 /* Increase the age counter on each cached compilation unit, and free
16162 any that are too old. */
16165 age_cached_comp_units (void)
16167 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
16169 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
16170 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16171 while (per_cu
!= NULL
)
16173 per_cu
->cu
->last_used
++;
16174 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
16175 dwarf2_mark (per_cu
->cu
);
16176 per_cu
= per_cu
->cu
->read_in_chain
;
16179 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16180 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
16181 while (per_cu
!= NULL
)
16183 struct dwarf2_per_cu_data
*next_cu
;
16185 next_cu
= per_cu
->cu
->read_in_chain
;
16187 if (!per_cu
->cu
->mark
)
16189 free_heap_comp_unit (per_cu
->cu
);
16190 *last_chain
= next_cu
;
16193 last_chain
= &per_cu
->cu
->read_in_chain
;
16199 /* Remove a single compilation unit from the cache. */
16202 free_one_cached_comp_unit (void *target_cu
)
16204 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
16206 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16207 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
16208 while (per_cu
!= NULL
)
16210 struct dwarf2_per_cu_data
*next_cu
;
16212 next_cu
= per_cu
->cu
->read_in_chain
;
16214 if (per_cu
->cu
== target_cu
)
16216 free_heap_comp_unit (per_cu
->cu
);
16217 *last_chain
= next_cu
;
16221 last_chain
= &per_cu
->cu
->read_in_chain
;
16227 /* Release all extra memory associated with OBJFILE. */
16230 dwarf2_free_objfile (struct objfile
*objfile
)
16232 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
16234 if (dwarf2_per_objfile
== NULL
)
16237 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
16238 free_cached_comp_units (NULL
);
16240 if (dwarf2_per_objfile
->quick_file_names_table
)
16241 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
16243 /* Everything else should be on the objfile obstack. */
16246 /* A pair of DIE offset and GDB type pointer. We store these
16247 in a hash table separate from the DIEs, and preserve them
16248 when the DIEs are flushed out of cache. */
16250 struct dwarf2_offset_and_type
16252 sect_offset offset
;
16256 /* Hash function for a dwarf2_offset_and_type. */
16259 offset_and_type_hash (const void *item
)
16261 const struct dwarf2_offset_and_type
*ofs
= item
;
16263 return ofs
->offset
.sect_off
;
16266 /* Equality function for a dwarf2_offset_and_type. */
16269 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
16271 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
16272 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
16274 return ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
;
16277 /* Set the type associated with DIE to TYPE. Save it in CU's hash
16278 table if necessary. For convenience, return TYPE.
16280 The DIEs reading must have careful ordering to:
16281 * Not cause infite loops trying to read in DIEs as a prerequisite for
16282 reading current DIE.
16283 * Not trying to dereference contents of still incompletely read in types
16284 while reading in other DIEs.
16285 * Enable referencing still incompletely read in types just by a pointer to
16286 the type without accessing its fields.
16288 Therefore caller should follow these rules:
16289 * Try to fetch any prerequisite types we may need to build this DIE type
16290 before building the type and calling set_die_type.
16291 * After building type call set_die_type for current DIE as soon as
16292 possible before fetching more types to complete the current type.
16293 * Make the type as complete as possible before fetching more types. */
16295 static struct type
*
16296 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
16298 struct dwarf2_offset_and_type
**slot
, ofs
;
16299 struct objfile
*objfile
= cu
->objfile
;
16300 htab_t
*type_hash_ptr
;
16302 /* For Ada types, make sure that the gnat-specific data is always
16303 initialized (if not already set). There are a few types where
16304 we should not be doing so, because the type-specific area is
16305 already used to hold some other piece of info (eg: TYPE_CODE_FLT
16306 where the type-specific area is used to store the floatformat).
16307 But this is not a problem, because the gnat-specific information
16308 is actually not needed for these types. */
16309 if (need_gnat_info (cu
)
16310 && TYPE_CODE (type
) != TYPE_CODE_FUNC
16311 && TYPE_CODE (type
) != TYPE_CODE_FLT
16312 && !HAVE_GNAT_AUX_INFO (type
))
16313 INIT_GNAT_SPECIFIC (type
);
16315 if (cu
->per_cu
->debug_types_section
)
16316 type_hash_ptr
= &dwarf2_per_objfile
->debug_types_type_hash
;
16318 type_hash_ptr
= &dwarf2_per_objfile
->debug_info_type_hash
;
16320 if (*type_hash_ptr
== NULL
)
16323 = htab_create_alloc_ex (127,
16324 offset_and_type_hash
,
16325 offset_and_type_eq
,
16327 &objfile
->objfile_obstack
,
16328 hashtab_obstack_allocate
,
16329 dummy_obstack_deallocate
);
16332 ofs
.offset
= die
->offset
;
16334 slot
= (struct dwarf2_offset_and_type
**)
16335 htab_find_slot_with_hash (*type_hash_ptr
, &ofs
, ofs
.offset
.sect_off
,
16338 complaint (&symfile_complaints
,
16339 _("A problem internal to GDB: DIE 0x%x has type already set"),
16340 die
->offset
.sect_off
);
16341 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
16346 /* Look up the type for the die at OFFSET in the appropriate type_hash
16347 table, or return NULL if the die does not have a saved type. */
16349 static struct type
*
16350 get_die_type_at_offset (sect_offset offset
,
16351 struct dwarf2_per_cu_data
*per_cu
)
16353 struct dwarf2_offset_and_type
*slot
, ofs
;
16356 if (per_cu
->debug_types_section
)
16357 type_hash
= dwarf2_per_objfile
->debug_types_type_hash
;
16359 type_hash
= dwarf2_per_objfile
->debug_info_type_hash
;
16360 if (type_hash
== NULL
)
16363 ofs
.offset
= offset
;
16364 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
.sect_off
);
16371 /* Look up the type for DIE in the appropriate type_hash table,
16372 or return NULL if DIE does not have a saved type. */
16374 static struct type
*
16375 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16377 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
16380 /* Add a dependence relationship from CU to REF_PER_CU. */
16383 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
16384 struct dwarf2_per_cu_data
*ref_per_cu
)
16388 if (cu
->dependencies
== NULL
)
16390 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
16391 NULL
, &cu
->comp_unit_obstack
,
16392 hashtab_obstack_allocate
,
16393 dummy_obstack_deallocate
);
16395 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
16397 *slot
= ref_per_cu
;
16400 /* Subroutine of dwarf2_mark to pass to htab_traverse.
16401 Set the mark field in every compilation unit in the
16402 cache that we must keep because we are keeping CU. */
16405 dwarf2_mark_helper (void **slot
, void *data
)
16407 struct dwarf2_per_cu_data
*per_cu
;
16409 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
16411 /* cu->dependencies references may not yet have been ever read if QUIT aborts
16412 reading of the chain. As such dependencies remain valid it is not much
16413 useful to track and undo them during QUIT cleanups. */
16414 if (per_cu
->cu
== NULL
)
16417 if (per_cu
->cu
->mark
)
16419 per_cu
->cu
->mark
= 1;
16421 if (per_cu
->cu
->dependencies
!= NULL
)
16422 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
16427 /* Set the mark field in CU and in every other compilation unit in the
16428 cache that we must keep because we are keeping CU. */
16431 dwarf2_mark (struct dwarf2_cu
*cu
)
16436 if (cu
->dependencies
!= NULL
)
16437 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
16441 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
16445 per_cu
->cu
->mark
= 0;
16446 per_cu
= per_cu
->cu
->read_in_chain
;
16450 /* Trivial hash function for partial_die_info: the hash value of a DIE
16451 is its offset in .debug_info for this objfile. */
16454 partial_die_hash (const void *item
)
16456 const struct partial_die_info
*part_die
= item
;
16458 return part_die
->offset
.sect_off
;
16461 /* Trivial comparison function for partial_die_info structures: two DIEs
16462 are equal if they have the same offset. */
16465 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
16467 const struct partial_die_info
*part_die_lhs
= item_lhs
;
16468 const struct partial_die_info
*part_die_rhs
= item_rhs
;
16470 return part_die_lhs
->offset
.sect_off
== part_die_rhs
->offset
.sect_off
;
16473 static struct cmd_list_element
*set_dwarf2_cmdlist
;
16474 static struct cmd_list_element
*show_dwarf2_cmdlist
;
16477 set_dwarf2_cmd (char *args
, int from_tty
)
16479 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
16483 show_dwarf2_cmd (char *args
, int from_tty
)
16485 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
16488 /* If section described by INFO was mmapped, munmap it now. */
16491 munmap_section_buffer (struct dwarf2_section_info
*info
)
16493 if (info
->map_addr
!= NULL
)
16498 res
= munmap (info
->map_addr
, info
->map_len
);
16499 gdb_assert (res
== 0);
16501 /* Without HAVE_MMAP, we should never be here to begin with. */
16502 gdb_assert_not_reached ("no mmap support");
16507 /* munmap debug sections for OBJFILE, if necessary. */
16510 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
16512 struct dwarf2_per_objfile
*data
= d
;
16514 struct dwarf2_section_info
*section
;
16516 /* This is sorted according to the order they're defined in to make it easier
16517 to keep in sync. */
16518 munmap_section_buffer (&data
->info
);
16519 munmap_section_buffer (&data
->abbrev
);
16520 munmap_section_buffer (&data
->line
);
16521 munmap_section_buffer (&data
->loc
);
16522 munmap_section_buffer (&data
->macinfo
);
16523 munmap_section_buffer (&data
->macro
);
16524 munmap_section_buffer (&data
->str
);
16525 munmap_section_buffer (&data
->ranges
);
16526 munmap_section_buffer (&data
->frame
);
16527 munmap_section_buffer (&data
->eh_frame
);
16528 munmap_section_buffer (&data
->gdb_index
);
16531 VEC_iterate (dwarf2_section_info_def
, data
->types
, ix
, section
);
16533 munmap_section_buffer (section
);
16535 VEC_free (dwarf2_section_info_def
, data
->types
);
16539 /* The "save gdb-index" command. */
16541 /* The contents of the hash table we create when building the string
16543 struct strtab_entry
16545 offset_type offset
;
16549 /* Hash function for a strtab_entry.
16551 Function is used only during write_hash_table so no index format backward
16552 compatibility is needed. */
16555 hash_strtab_entry (const void *e
)
16557 const struct strtab_entry
*entry
= e
;
16558 return mapped_index_string_hash (INT_MAX
, entry
->str
);
16561 /* Equality function for a strtab_entry. */
16564 eq_strtab_entry (const void *a
, const void *b
)
16566 const struct strtab_entry
*ea
= a
;
16567 const struct strtab_entry
*eb
= b
;
16568 return !strcmp (ea
->str
, eb
->str
);
16571 /* Create a strtab_entry hash table. */
16574 create_strtab (void)
16576 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
16577 xfree
, xcalloc
, xfree
);
16580 /* Add a string to the constant pool. Return the string's offset in
16584 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
16587 struct strtab_entry entry
;
16588 struct strtab_entry
*result
;
16591 slot
= htab_find_slot (table
, &entry
, INSERT
);
16596 result
= XNEW (struct strtab_entry
);
16597 result
->offset
= obstack_object_size (cpool
);
16599 obstack_grow_str0 (cpool
, str
);
16602 return result
->offset
;
16605 /* An entry in the symbol table. */
16606 struct symtab_index_entry
16608 /* The name of the symbol. */
16610 /* The offset of the name in the constant pool. */
16611 offset_type index_offset
;
16612 /* A sorted vector of the indices of all the CUs that hold an object
16614 VEC (offset_type
) *cu_indices
;
16617 /* The symbol table. This is a power-of-2-sized hash table. */
16618 struct mapped_symtab
16620 offset_type n_elements
;
16622 struct symtab_index_entry
**data
;
16625 /* Hash function for a symtab_index_entry. */
16628 hash_symtab_entry (const void *e
)
16630 const struct symtab_index_entry
*entry
= e
;
16631 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
16632 sizeof (offset_type
) * VEC_length (offset_type
,
16633 entry
->cu_indices
),
16637 /* Equality function for a symtab_index_entry. */
16640 eq_symtab_entry (const void *a
, const void *b
)
16642 const struct symtab_index_entry
*ea
= a
;
16643 const struct symtab_index_entry
*eb
= b
;
16644 int len
= VEC_length (offset_type
, ea
->cu_indices
);
16645 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
16647 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
16648 VEC_address (offset_type
, eb
->cu_indices
),
16649 sizeof (offset_type
) * len
);
16652 /* Destroy a symtab_index_entry. */
16655 delete_symtab_entry (void *p
)
16657 struct symtab_index_entry
*entry
= p
;
16658 VEC_free (offset_type
, entry
->cu_indices
);
16662 /* Create a hash table holding symtab_index_entry objects. */
16665 create_symbol_hash_table (void)
16667 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
16668 delete_symtab_entry
, xcalloc
, xfree
);
16671 /* Create a new mapped symtab object. */
16673 static struct mapped_symtab
*
16674 create_mapped_symtab (void)
16676 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
16677 symtab
->n_elements
= 0;
16678 symtab
->size
= 1024;
16679 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
16683 /* Destroy a mapped_symtab. */
16686 cleanup_mapped_symtab (void *p
)
16688 struct mapped_symtab
*symtab
= p
;
16689 /* The contents of the array are freed when the other hash table is
16691 xfree (symtab
->data
);
16695 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
16698 Function is used only during write_hash_table so no index format backward
16699 compatibility is needed. */
16701 static struct symtab_index_entry
**
16702 find_slot (struct mapped_symtab
*symtab
, const char *name
)
16704 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
16706 index
= hash
& (symtab
->size
- 1);
16707 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
16711 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
16712 return &symtab
->data
[index
];
16713 index
= (index
+ step
) & (symtab
->size
- 1);
16717 /* Expand SYMTAB's hash table. */
16720 hash_expand (struct mapped_symtab
*symtab
)
16722 offset_type old_size
= symtab
->size
;
16724 struct symtab_index_entry
**old_entries
= symtab
->data
;
16727 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
16729 for (i
= 0; i
< old_size
; ++i
)
16731 if (old_entries
[i
])
16733 struct symtab_index_entry
**slot
= find_slot (symtab
,
16734 old_entries
[i
]->name
);
16735 *slot
= old_entries
[i
];
16739 xfree (old_entries
);
16742 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
16743 is the index of the CU in which the symbol appears. */
16746 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
16747 offset_type cu_index
)
16749 struct symtab_index_entry
**slot
;
16751 ++symtab
->n_elements
;
16752 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
16753 hash_expand (symtab
);
16755 slot
= find_slot (symtab
, name
);
16758 *slot
= XNEW (struct symtab_index_entry
);
16759 (*slot
)->name
= name
;
16760 (*slot
)->cu_indices
= NULL
;
16762 /* Don't push an index twice. Due to how we add entries we only
16763 have to check the last one. */
16764 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
16765 || VEC_last (offset_type
, (*slot
)->cu_indices
) != cu_index
)
16766 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
16769 /* Add a vector of indices to the constant pool. */
16772 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
16773 struct symtab_index_entry
*entry
)
16777 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
16780 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
16781 offset_type val
= MAYBE_SWAP (len
);
16786 entry
->index_offset
= obstack_object_size (cpool
);
16788 obstack_grow (cpool
, &val
, sizeof (val
));
16790 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
16793 val
= MAYBE_SWAP (iter
);
16794 obstack_grow (cpool
, &val
, sizeof (val
));
16799 struct symtab_index_entry
*old_entry
= *slot
;
16800 entry
->index_offset
= old_entry
->index_offset
;
16803 return entry
->index_offset
;
16806 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
16807 constant pool entries going into the obstack CPOOL. */
16810 write_hash_table (struct mapped_symtab
*symtab
,
16811 struct obstack
*output
, struct obstack
*cpool
)
16814 htab_t symbol_hash_table
;
16817 symbol_hash_table
= create_symbol_hash_table ();
16818 str_table
= create_strtab ();
16820 /* We add all the index vectors to the constant pool first, to
16821 ensure alignment is ok. */
16822 for (i
= 0; i
< symtab
->size
; ++i
)
16824 if (symtab
->data
[i
])
16825 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
16828 /* Now write out the hash table. */
16829 for (i
= 0; i
< symtab
->size
; ++i
)
16831 offset_type str_off
, vec_off
;
16833 if (symtab
->data
[i
])
16835 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
16836 vec_off
= symtab
->data
[i
]->index_offset
;
16840 /* While 0 is a valid constant pool index, it is not valid
16841 to have 0 for both offsets. */
16846 str_off
= MAYBE_SWAP (str_off
);
16847 vec_off
= MAYBE_SWAP (vec_off
);
16849 obstack_grow (output
, &str_off
, sizeof (str_off
));
16850 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
16853 htab_delete (str_table
);
16854 htab_delete (symbol_hash_table
);
16857 /* Struct to map psymtab to CU index in the index file. */
16858 struct psymtab_cu_index_map
16860 struct partial_symtab
*psymtab
;
16861 unsigned int cu_index
;
16865 hash_psymtab_cu_index (const void *item
)
16867 const struct psymtab_cu_index_map
*map
= item
;
16869 return htab_hash_pointer (map
->psymtab
);
16873 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
16875 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
16876 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
16878 return lhs
->psymtab
== rhs
->psymtab
;
16881 /* Helper struct for building the address table. */
16882 struct addrmap_index_data
16884 struct objfile
*objfile
;
16885 struct obstack
*addr_obstack
;
16886 htab_t cu_index_htab
;
16888 /* Non-zero if the previous_* fields are valid.
16889 We can't write an entry until we see the next entry (since it is only then
16890 that we know the end of the entry). */
16891 int previous_valid
;
16892 /* Index of the CU in the table of all CUs in the index file. */
16893 unsigned int previous_cu_index
;
16894 /* Start address of the CU. */
16895 CORE_ADDR previous_cu_start
;
16898 /* Write an address entry to OBSTACK. */
16901 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
16902 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
16904 offset_type cu_index_to_write
;
16906 CORE_ADDR baseaddr
;
16908 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
16910 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
16911 obstack_grow (obstack
, addr
, 8);
16912 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
16913 obstack_grow (obstack
, addr
, 8);
16914 cu_index_to_write
= MAYBE_SWAP (cu_index
);
16915 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
16918 /* Worker function for traversing an addrmap to build the address table. */
16921 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
16923 struct addrmap_index_data
*data
= datap
;
16924 struct partial_symtab
*pst
= obj
;
16925 offset_type cu_index
;
16928 if (data
->previous_valid
)
16929 add_address_entry (data
->objfile
, data
->addr_obstack
,
16930 data
->previous_cu_start
, start_addr
,
16931 data
->previous_cu_index
);
16933 data
->previous_cu_start
= start_addr
;
16936 struct psymtab_cu_index_map find_map
, *map
;
16937 find_map
.psymtab
= pst
;
16938 map
= htab_find (data
->cu_index_htab
, &find_map
);
16939 gdb_assert (map
!= NULL
);
16940 data
->previous_cu_index
= map
->cu_index
;
16941 data
->previous_valid
= 1;
16944 data
->previous_valid
= 0;
16949 /* Write OBJFILE's address map to OBSTACK.
16950 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
16951 in the index file. */
16954 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
16955 htab_t cu_index_htab
)
16957 struct addrmap_index_data addrmap_index_data
;
16959 /* When writing the address table, we have to cope with the fact that
16960 the addrmap iterator only provides the start of a region; we have to
16961 wait until the next invocation to get the start of the next region. */
16963 addrmap_index_data
.objfile
= objfile
;
16964 addrmap_index_data
.addr_obstack
= obstack
;
16965 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
16966 addrmap_index_data
.previous_valid
= 0;
16968 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
16969 &addrmap_index_data
);
16971 /* It's highly unlikely the last entry (end address = 0xff...ff)
16972 is valid, but we should still handle it.
16973 The end address is recorded as the start of the next region, but that
16974 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
16976 if (addrmap_index_data
.previous_valid
)
16977 add_address_entry (objfile
, obstack
,
16978 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
16979 addrmap_index_data
.previous_cu_index
);
16982 /* Add a list of partial symbols to SYMTAB. */
16985 write_psymbols (struct mapped_symtab
*symtab
,
16987 struct partial_symbol
**psymp
,
16989 offset_type cu_index
,
16992 for (; count
-- > 0; ++psymp
)
16994 void **slot
, *lookup
;
16996 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
16997 error (_("Ada is not currently supported by the index"));
16999 /* We only want to add a given psymbol once. However, we also
17000 want to account for whether it is global or static. So, we
17001 may add it twice, using slightly different values. */
17004 uintptr_t val
= 1 | (uintptr_t) *psymp
;
17006 lookup
= (void *) val
;
17011 /* Only add a given psymbol once. */
17012 slot
= htab_find_slot (psyms_seen
, lookup
, INSERT
);
17016 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (*psymp
), cu_index
);
17021 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
17022 exception if there is an error. */
17025 write_obstack (FILE *file
, struct obstack
*obstack
)
17027 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
17029 != obstack_object_size (obstack
))
17030 error (_("couldn't data write to file"));
17033 /* Unlink a file if the argument is not NULL. */
17036 unlink_if_set (void *p
)
17038 char **filename
= p
;
17040 unlink (*filename
);
17043 /* A helper struct used when iterating over debug_types. */
17044 struct signatured_type_index_data
17046 struct objfile
*objfile
;
17047 struct mapped_symtab
*symtab
;
17048 struct obstack
*types_list
;
17053 /* A helper function that writes a single signatured_type to an
17057 write_one_signatured_type (void **slot
, void *d
)
17059 struct signatured_type_index_data
*info
= d
;
17060 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
17061 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
17062 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
17065 write_psymbols (info
->symtab
,
17067 info
->objfile
->global_psymbols
.list
17068 + psymtab
->globals_offset
,
17069 psymtab
->n_global_syms
, info
->cu_index
,
17071 write_psymbols (info
->symtab
,
17073 info
->objfile
->static_psymbols
.list
17074 + psymtab
->statics_offset
,
17075 psymtab
->n_static_syms
, info
->cu_index
,
17078 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
17079 entry
->per_cu
.offset
.sect_off
);
17080 obstack_grow (info
->types_list
, val
, 8);
17081 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->type_offset
.cu_off
);
17082 obstack_grow (info
->types_list
, val
, 8);
17083 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
17084 obstack_grow (info
->types_list
, val
, 8);
17091 /* Create an index file for OBJFILE in the directory DIR. */
17094 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
17096 struct cleanup
*cleanup
;
17097 char *filename
, *cleanup_filename
;
17098 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
17099 struct obstack cu_list
, types_cu_list
;
17102 struct mapped_symtab
*symtab
;
17103 offset_type val
, size_of_contents
, total_len
;
17107 htab_t cu_index_htab
;
17108 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
17110 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
17113 if (dwarf2_per_objfile
->using_index
)
17114 error (_("Cannot use an index to create the index"));
17116 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
17117 error (_("Cannot make an index when the file has multiple .debug_types sections"));
17119 if (stat (objfile
->name
, &st
) < 0)
17120 perror_with_name (objfile
->name
);
17122 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
17123 INDEX_SUFFIX
, (char *) NULL
);
17124 cleanup
= make_cleanup (xfree
, filename
);
17126 out_file
= fopen (filename
, "wb");
17128 error (_("Can't open `%s' for writing"), filename
);
17130 cleanup_filename
= filename
;
17131 make_cleanup (unlink_if_set
, &cleanup_filename
);
17133 symtab
= create_mapped_symtab ();
17134 make_cleanup (cleanup_mapped_symtab
, symtab
);
17136 obstack_init (&addr_obstack
);
17137 make_cleanup_obstack_free (&addr_obstack
);
17139 obstack_init (&cu_list
);
17140 make_cleanup_obstack_free (&cu_list
);
17142 obstack_init (&types_cu_list
);
17143 make_cleanup_obstack_free (&types_cu_list
);
17145 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
17146 NULL
, xcalloc
, xfree
);
17147 make_cleanup_htab_delete (psyms_seen
);
17149 /* While we're scanning CU's create a table that maps a psymtab pointer
17150 (which is what addrmap records) to its index (which is what is recorded
17151 in the index file). This will later be needed to write the address
17153 cu_index_htab
= htab_create_alloc (100,
17154 hash_psymtab_cu_index
,
17155 eq_psymtab_cu_index
,
17156 NULL
, xcalloc
, xfree
);
17157 make_cleanup_htab_delete (cu_index_htab
);
17158 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
17159 xmalloc (sizeof (struct psymtab_cu_index_map
)
17160 * dwarf2_per_objfile
->n_comp_units
);
17161 make_cleanup (xfree
, psymtab_cu_index_map
);
17163 /* The CU list is already sorted, so we don't need to do additional
17164 work here. Also, the debug_types entries do not appear in
17165 all_comp_units, but only in their own hash table. */
17166 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
17168 struct dwarf2_per_cu_data
*per_cu
17169 = dwarf2_per_objfile
->all_comp_units
[i
];
17170 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
17172 struct psymtab_cu_index_map
*map
;
17175 write_psymbols (symtab
,
17177 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
17178 psymtab
->n_global_syms
, i
,
17180 write_psymbols (symtab
,
17182 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
17183 psymtab
->n_static_syms
, i
,
17186 map
= &psymtab_cu_index_map
[i
];
17187 map
->psymtab
= psymtab
;
17189 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
17190 gdb_assert (slot
!= NULL
);
17191 gdb_assert (*slot
== NULL
);
17194 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
17195 per_cu
->offset
.sect_off
);
17196 obstack_grow (&cu_list
, val
, 8);
17197 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
17198 obstack_grow (&cu_list
, val
, 8);
17201 /* Dump the address map. */
17202 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
17204 /* Write out the .debug_type entries, if any. */
17205 if (dwarf2_per_objfile
->signatured_types
)
17207 struct signatured_type_index_data sig_data
;
17209 sig_data
.objfile
= objfile
;
17210 sig_data
.symtab
= symtab
;
17211 sig_data
.types_list
= &types_cu_list
;
17212 sig_data
.psyms_seen
= psyms_seen
;
17213 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
17214 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
17215 write_one_signatured_type
, &sig_data
);
17218 obstack_init (&constant_pool
);
17219 make_cleanup_obstack_free (&constant_pool
);
17220 obstack_init (&symtab_obstack
);
17221 make_cleanup_obstack_free (&symtab_obstack
);
17222 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
17224 obstack_init (&contents
);
17225 make_cleanup_obstack_free (&contents
);
17226 size_of_contents
= 6 * sizeof (offset_type
);
17227 total_len
= size_of_contents
;
17229 /* The version number. */
17230 val
= MAYBE_SWAP (6);
17231 obstack_grow (&contents
, &val
, sizeof (val
));
17233 /* The offset of the CU list from the start of the file. */
17234 val
= MAYBE_SWAP (total_len
);
17235 obstack_grow (&contents
, &val
, sizeof (val
));
17236 total_len
+= obstack_object_size (&cu_list
);
17238 /* The offset of the types CU list from the start of the file. */
17239 val
= MAYBE_SWAP (total_len
);
17240 obstack_grow (&contents
, &val
, sizeof (val
));
17241 total_len
+= obstack_object_size (&types_cu_list
);
17243 /* The offset of the address table from the start of the file. */
17244 val
= MAYBE_SWAP (total_len
);
17245 obstack_grow (&contents
, &val
, sizeof (val
));
17246 total_len
+= obstack_object_size (&addr_obstack
);
17248 /* The offset of the symbol table from the start of the file. */
17249 val
= MAYBE_SWAP (total_len
);
17250 obstack_grow (&contents
, &val
, sizeof (val
));
17251 total_len
+= obstack_object_size (&symtab_obstack
);
17253 /* The offset of the constant pool from the start of the file. */
17254 val
= MAYBE_SWAP (total_len
);
17255 obstack_grow (&contents
, &val
, sizeof (val
));
17256 total_len
+= obstack_object_size (&constant_pool
);
17258 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
17260 write_obstack (out_file
, &contents
);
17261 write_obstack (out_file
, &cu_list
);
17262 write_obstack (out_file
, &types_cu_list
);
17263 write_obstack (out_file
, &addr_obstack
);
17264 write_obstack (out_file
, &symtab_obstack
);
17265 write_obstack (out_file
, &constant_pool
);
17269 /* We want to keep the file, so we set cleanup_filename to NULL
17270 here. See unlink_if_set. */
17271 cleanup_filename
= NULL
;
17273 do_cleanups (cleanup
);
17276 /* Implementation of the `save gdb-index' command.
17278 Note that the file format used by this command is documented in the
17279 GDB manual. Any changes here must be documented there. */
17282 save_gdb_index_command (char *arg
, int from_tty
)
17284 struct objfile
*objfile
;
17287 error (_("usage: save gdb-index DIRECTORY"));
17289 ALL_OBJFILES (objfile
)
17293 /* If the objfile does not correspond to an actual file, skip it. */
17294 if (stat (objfile
->name
, &st
) < 0)
17297 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
17298 if (dwarf2_per_objfile
)
17300 volatile struct gdb_exception except
;
17302 TRY_CATCH (except
, RETURN_MASK_ERROR
)
17304 write_psymtabs_to_index (objfile
, arg
);
17306 if (except
.reason
< 0)
17307 exception_fprintf (gdb_stderr
, except
,
17308 _("Error while writing index for `%s': "),
17316 int dwarf2_always_disassemble
;
17319 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
17320 struct cmd_list_element
*c
, const char *value
)
17322 fprintf_filtered (file
,
17323 _("Whether to always disassemble "
17324 "DWARF expressions is %s.\n"),
17329 show_check_physname (struct ui_file
*file
, int from_tty
,
17330 struct cmd_list_element
*c
, const char *value
)
17332 fprintf_filtered (file
,
17333 _("Whether to check \"physname\" is %s.\n"),
17337 void _initialize_dwarf2_read (void);
17340 _initialize_dwarf2_read (void)
17342 struct cmd_list_element
*c
;
17344 dwarf2_objfile_data_key
17345 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
17347 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
17348 Set DWARF 2 specific variables.\n\
17349 Configure DWARF 2 variables such as the cache size"),
17350 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
17351 0/*allow-unknown*/, &maintenance_set_cmdlist
);
17353 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
17354 Show DWARF 2 specific variables\n\
17355 Show DWARF 2 variables such as the cache size"),
17356 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
17357 0/*allow-unknown*/, &maintenance_show_cmdlist
);
17359 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
17360 &dwarf2_max_cache_age
, _("\
17361 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
17362 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
17363 A higher limit means that cached compilation units will be stored\n\
17364 in memory longer, and more total memory will be used. Zero disables\n\
17365 caching, which can slow down startup."),
17367 show_dwarf2_max_cache_age
,
17368 &set_dwarf2_cmdlist
,
17369 &show_dwarf2_cmdlist
);
17371 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
17372 &dwarf2_always_disassemble
, _("\
17373 Set whether `info address' always disassembles DWARF expressions."), _("\
17374 Show whether `info address' always disassembles DWARF expressions."), _("\
17375 When enabled, DWARF expressions are always printed in an assembly-like\n\
17376 syntax. When disabled, expressions will be printed in a more\n\
17377 conversational style, when possible."),
17379 show_dwarf2_always_disassemble
,
17380 &set_dwarf2_cmdlist
,
17381 &show_dwarf2_cmdlist
);
17383 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
17384 Set debugging of the dwarf2 DIE reader."), _("\
17385 Show debugging of the dwarf2 DIE reader."), _("\
17386 When enabled (non-zero), DIEs are dumped after they are read in.\n\
17387 The value is the maximum depth to print."),
17390 &setdebuglist
, &showdebuglist
);
17392 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
17393 Set cross-checking of \"physname\" code against demangler."), _("\
17394 Show cross-checking of \"physname\" code against demangler."), _("\
17395 When enabled, GDB's internal \"physname\" code is checked against\n\
17397 NULL
, show_check_physname
,
17398 &setdebuglist
, &showdebuglist
);
17400 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
17402 Save a gdb-index file.\n\
17403 Usage: save gdb-index DIRECTORY"),
17405 set_cmd_completer (c
, filename_completer
);