1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2012 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
39 #include "gdb-demangle.h"
40 #include "expression.h"
41 #include "filenames.h" /* for DOSish file names */
44 #include "complaints.h"
46 #include "dwarf2expr.h"
47 #include "dwarf2loc.h"
48 #include "cp-support.h"
54 #include "typeprint.h"
57 #include "exceptions.h"
59 #include "completer.h"
66 #include "gdb_string.h"
67 #include "gdb_assert.h"
68 #include <sys/types.h>
75 #define MAP_FAILED ((void *) -1)
79 typedef struct symbol
*symbolp
;
82 /* When non-zero, dump DIEs after they are read in. */
83 static int dwarf2_die_debug
= 0;
85 /* When non-zero, cross-check physname against demangler. */
86 static int check_physname
= 0;
88 /* When non-zero, do not reject deprecated .gdb_index sections. */
89 int use_deprecated_index_sections
= 0;
93 /* When set, the file that we're processing is known to have debugging
94 info for C++ namespaces. GCC 3.3.x did not produce this information,
95 but later versions do. */
97 static int processing_has_namespace_info
;
99 static const struct objfile_data
*dwarf2_objfile_data_key
;
101 struct dwarf2_section_info
106 /* Not NULL if the section was actually mmapped. */
108 /* Page aligned size of mmapped area. */
109 bfd_size_type map_len
;
110 /* True if we have tried to read this section. */
114 typedef struct dwarf2_section_info dwarf2_section_info_def
;
115 DEF_VEC_O (dwarf2_section_info_def
);
117 /* All offsets in the index are of this type. It must be
118 architecture-independent. */
119 typedef uint32_t offset_type
;
121 DEF_VEC_I (offset_type
);
123 /* A description of the mapped index. The file format is described in
124 a comment by the code that writes the index. */
127 /* Index data format version. */
130 /* The total length of the buffer. */
133 /* A pointer to the address table data. */
134 const gdb_byte
*address_table
;
136 /* Size of the address table data in bytes. */
137 offset_type address_table_size
;
139 /* The symbol table, implemented as a hash table. */
140 const offset_type
*symbol_table
;
142 /* Size in slots, each slot is 2 offset_types. */
143 offset_type symbol_table_slots
;
145 /* A pointer to the constant pool. */
146 const char *constant_pool
;
149 /* Collection of data recorded per objfile.
150 This hangs off of dwarf2_objfile_data_key. */
152 struct dwarf2_per_objfile
154 struct dwarf2_section_info info
;
155 struct dwarf2_section_info abbrev
;
156 struct dwarf2_section_info line
;
157 struct dwarf2_section_info loc
;
158 struct dwarf2_section_info macinfo
;
159 struct dwarf2_section_info macro
;
160 struct dwarf2_section_info str
;
161 struct dwarf2_section_info ranges
;
162 struct dwarf2_section_info frame
;
163 struct dwarf2_section_info eh_frame
;
164 struct dwarf2_section_info gdb_index
;
166 VEC (dwarf2_section_info_def
) *types
;
169 struct objfile
*objfile
;
171 /* Table of all the compilation units. This is used to locate
172 the target compilation unit of a particular reference. */
173 struct dwarf2_per_cu_data
**all_comp_units
;
175 /* The number of compilation units in ALL_COMP_UNITS. */
178 /* The number of .debug_types-related CUs. */
181 /* The .debug_types-related CUs (TUs). */
182 struct dwarf2_per_cu_data
**all_type_units
;
184 /* A chain of compilation units that are currently read in, so that
185 they can be freed later. */
186 struct dwarf2_per_cu_data
*read_in_chain
;
188 /* A table mapping .debug_types signatures to its signatured_type entry.
189 This is NULL if the .debug_types section hasn't been read in yet. */
190 htab_t signatured_types
;
192 /* A flag indicating wether this objfile has a section loaded at a
194 int has_section_at_zero
;
196 /* True if we are using the mapped index,
197 or we are faking it for OBJF_READNOW's sake. */
198 unsigned char using_index
;
200 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
201 struct mapped_index
*index_table
;
203 /* When using index_table, this keeps track of all quick_file_names entries.
204 TUs can share line table entries with CUs or other TUs, and there can be
205 a lot more TUs than unique line tables, so we maintain a separate table
206 of all line table entries to support the sharing. */
207 htab_t quick_file_names_table
;
209 /* Set during partial symbol reading, to prevent queueing of full
211 int reading_partial_symbols
;
213 /* Table mapping type .debug_info DIE offsets to types.
214 This is NULL if not allocated yet.
215 It (currently) makes sense to allocate debug_types_type_hash lazily.
216 To keep things simple we allocate both lazily. */
217 htab_t debug_info_type_hash
;
219 /* Table mapping type .debug_types DIE offsets to types.
220 This is NULL if not allocated yet. */
221 htab_t debug_types_type_hash
;
224 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
226 /* Default names of the debugging sections. */
228 /* Note that if the debugging section has been compressed, it might
229 have a name like .zdebug_info. */
231 static const struct dwarf2_debug_sections dwarf2_elf_names
=
233 { ".debug_info", ".zdebug_info" },
234 { ".debug_abbrev", ".zdebug_abbrev" },
235 { ".debug_line", ".zdebug_line" },
236 { ".debug_loc", ".zdebug_loc" },
237 { ".debug_macinfo", ".zdebug_macinfo" },
238 { ".debug_macro", ".zdebug_macro" },
239 { ".debug_str", ".zdebug_str" },
240 { ".debug_ranges", ".zdebug_ranges" },
241 { ".debug_types", ".zdebug_types" },
242 { ".debug_frame", ".zdebug_frame" },
243 { ".eh_frame", NULL
},
244 { ".gdb_index", ".zgdb_index" },
248 /* local data types */
250 /* We hold several abbreviation tables in memory at the same time. */
251 #ifndef ABBREV_HASH_SIZE
252 #define ABBREV_HASH_SIZE 121
255 /* The data in a compilation unit header, after target2host
256 translation, looks like this. */
257 struct comp_unit_head
261 unsigned char addr_size
;
262 unsigned char signed_addr_p
;
263 unsigned int abbrev_offset
;
265 /* Size of file offsets; either 4 or 8. */
266 unsigned int offset_size
;
268 /* Size of the length field; either 4 or 12. */
269 unsigned int initial_length_size
;
271 /* Offset to the first byte of this compilation unit header in the
272 .debug_info section, for resolving relative reference dies. */
275 /* Offset to first die in this cu from the start of the cu.
276 This will be the first byte following the compilation unit header. */
277 unsigned int first_die_offset
;
280 /* Type used for delaying computation of method physnames.
281 See comments for compute_delayed_physnames. */
282 struct delayed_method_info
284 /* The type to which the method is attached, i.e., its parent class. */
287 /* The index of the method in the type's function fieldlists. */
290 /* The index of the method in the fieldlist. */
293 /* The name of the DIE. */
296 /* The DIE associated with this method. */
297 struct die_info
*die
;
300 typedef struct delayed_method_info delayed_method_info
;
301 DEF_VEC_O (delayed_method_info
);
303 /* Internal state when decoding a particular compilation unit. */
306 /* The objfile containing this compilation unit. */
307 struct objfile
*objfile
;
309 /* The header of the compilation unit. */
310 struct comp_unit_head header
;
312 /* Base address of this compilation unit. */
313 CORE_ADDR base_address
;
315 /* Non-zero if base_address has been set. */
318 /* The language we are debugging. */
319 enum language language
;
320 const struct language_defn
*language_defn
;
322 const char *producer
;
324 /* The generic symbol table building routines have separate lists for
325 file scope symbols and all all other scopes (local scopes). So
326 we need to select the right one to pass to add_symbol_to_list().
327 We do it by keeping a pointer to the correct list in list_in_scope.
329 FIXME: The original dwarf code just treated the file scope as the
330 first local scope, and all other local scopes as nested local
331 scopes, and worked fine. Check to see if we really need to
332 distinguish these in buildsym.c. */
333 struct pending
**list_in_scope
;
335 /* DWARF abbreviation table associated with this compilation unit. */
336 struct abbrev_info
**dwarf2_abbrevs
;
338 /* Storage for the abbrev table. */
339 struct obstack abbrev_obstack
;
341 /* Hash table holding all the loaded partial DIEs. */
344 /* Storage for things with the same lifetime as this read-in compilation
345 unit, including partial DIEs. */
346 struct obstack comp_unit_obstack
;
348 /* When multiple dwarf2_cu structures are living in memory, this field
349 chains them all together, so that they can be released efficiently.
350 We will probably also want a generation counter so that most-recently-used
351 compilation units are cached... */
352 struct dwarf2_per_cu_data
*read_in_chain
;
354 /* Backchain to our per_cu entry if the tree has been built. */
355 struct dwarf2_per_cu_data
*per_cu
;
357 /* How many compilation units ago was this CU last referenced? */
360 /* A hash table of die offsets for following references. */
363 /* Full DIEs if read in. */
364 struct die_info
*dies
;
366 /* A set of pointers to dwarf2_per_cu_data objects for compilation
367 units referenced by this one. Only set during full symbol processing;
368 partial symbol tables do not have dependencies. */
371 /* Header data from the line table, during full symbol processing. */
372 struct line_header
*line_header
;
374 /* A list of methods which need to have physnames computed
375 after all type information has been read. */
376 VEC (delayed_method_info
) *method_list
;
378 /* To be copied to symtab->call_site_htab. */
379 htab_t call_site_htab
;
381 /* Mark used when releasing cached dies. */
382 unsigned int mark
: 1;
384 /* This CU references .debug_loc. See the symtab->locations_valid field.
385 This test is imperfect as there may exist optimized debug code not using
386 any location list and still facing inlining issues if handled as
387 unoptimized code. For a future better test see GCC PR other/32998. */
388 unsigned int has_loclist
: 1;
390 /* These cache the results of producer_is_gxx_lt_4_6.
391 CHECKED_PRODUCER is set if PRODUCER_IS_GXX_LT_4_6 is valid. This
392 information is cached because profiling CU expansion showed
393 excessive time spent in producer_is_gxx_lt_4_6. */
394 unsigned int checked_producer
: 1;
395 unsigned int producer_is_gxx_lt_4_6
: 1;
398 /* Persistent data held for a compilation unit, even when not
399 processing it. We put a pointer to this structure in the
400 read_symtab_private field of the psymtab. */
402 struct dwarf2_per_cu_data
404 /* The start offset and length of this compilation unit. 2**29-1
405 bytes should suffice to store the length of any compilation unit
406 - if it doesn't, GDB will fall over anyway.
407 NOTE: Unlike comp_unit_head.length, this length includes
408 initial_length_size. */
410 unsigned int length
: 29;
412 /* Flag indicating this compilation unit will be read in before
413 any of the current compilation units are processed. */
414 unsigned int queued
: 1;
416 /* This flag will be set if we need to load absolutely all DIEs
417 for this compilation unit, instead of just the ones we think
418 are interesting. It gets set if we look for a DIE in the
419 hash table and don't find it. */
420 unsigned int load_all_dies
: 1;
422 /* Non-null if this CU is from .debug_types; in which case it points
423 to the section. Otherwise it's from .debug_info. */
424 struct dwarf2_section_info
*debug_types_section
;
426 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
427 of the CU cache it gets reset to NULL again. */
428 struct dwarf2_cu
*cu
;
430 /* The corresponding objfile.
431 Normally we can get the objfile from dwarf2_per_objfile.
432 However we can enter this file with just a "per_cu" handle. */
433 struct objfile
*objfile
;
435 /* When using partial symbol tables, the 'psymtab' field is active.
436 Otherwise the 'quick' field is active. */
439 /* The partial symbol table associated with this compilation unit,
440 or NULL for partial units (which do not have an associated
442 struct partial_symtab
*psymtab
;
444 /* Data needed by the "quick" functions. */
445 struct dwarf2_per_cu_quick_data
*quick
;
449 /* Entry in the signatured_types hash table. */
451 struct signatured_type
455 /* Offset in .debug_types of the type defined by this TU. */
456 unsigned int type_offset
;
458 /* The CU(/TU) of this type. */
459 struct dwarf2_per_cu_data per_cu
;
462 /* Struct used to pass misc. parameters to read_die_and_children, et
463 al. which are used for both .debug_info and .debug_types dies.
464 All parameters here are unchanging for the life of the call. This
465 struct exists to abstract away the constant parameters of die
468 struct die_reader_specs
470 /* The bfd of this objfile. */
473 /* The CU of the DIE we are parsing. */
474 struct dwarf2_cu
*cu
;
476 /* Pointer to start of section buffer.
477 This is either the start of .debug_info or .debug_types. */
478 const gdb_byte
*buffer
;
481 /* The line number information for a compilation unit (found in the
482 .debug_line section) begins with a "statement program header",
483 which contains the following information. */
486 unsigned int total_length
;
487 unsigned short version
;
488 unsigned int header_length
;
489 unsigned char minimum_instruction_length
;
490 unsigned char maximum_ops_per_instruction
;
491 unsigned char default_is_stmt
;
493 unsigned char line_range
;
494 unsigned char opcode_base
;
496 /* standard_opcode_lengths[i] is the number of operands for the
497 standard opcode whose value is i. This means that
498 standard_opcode_lengths[0] is unused, and the last meaningful
499 element is standard_opcode_lengths[opcode_base - 1]. */
500 unsigned char *standard_opcode_lengths
;
502 /* The include_directories table. NOTE! These strings are not
503 allocated with xmalloc; instead, they are pointers into
504 debug_line_buffer. If you try to free them, `free' will get
506 unsigned int num_include_dirs
, include_dirs_size
;
509 /* The file_names table. NOTE! These strings are not allocated
510 with xmalloc; instead, they are pointers into debug_line_buffer.
511 Don't try to free them directly. */
512 unsigned int num_file_names
, file_names_size
;
516 unsigned int dir_index
;
517 unsigned int mod_time
;
519 int included_p
; /* Non-zero if referenced by the Line Number Program. */
520 struct symtab
*symtab
; /* The associated symbol table, if any. */
523 /* The start and end of the statement program following this
524 header. These point into dwarf2_per_objfile->line_buffer. */
525 gdb_byte
*statement_program_start
, *statement_program_end
;
528 /* When we construct a partial symbol table entry we only
529 need this much information. */
530 struct partial_die_info
532 /* Offset of this DIE. */
535 /* DWARF-2 tag for this DIE. */
536 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
538 /* Assorted flags describing the data found in this DIE. */
539 unsigned int has_children
: 1;
540 unsigned int is_external
: 1;
541 unsigned int is_declaration
: 1;
542 unsigned int has_type
: 1;
543 unsigned int has_specification
: 1;
544 unsigned int has_pc_info
: 1;
545 unsigned int may_be_inlined
: 1;
547 /* Flag set if the SCOPE field of this structure has been
549 unsigned int scope_set
: 1;
551 /* Flag set if the DIE has a byte_size attribute. */
552 unsigned int has_byte_size
: 1;
554 /* Flag set if any of the DIE's children are template arguments. */
555 unsigned int has_template_arguments
: 1;
557 /* Flag set if fixup_partial_die has been called on this die. */
558 unsigned int fixup_called
: 1;
560 /* The name of this DIE. Normally the value of DW_AT_name, but
561 sometimes a default name for unnamed DIEs. */
564 /* The linkage name, if present. */
565 const char *linkage_name
;
567 /* The scope to prepend to our children. This is generally
568 allocated on the comp_unit_obstack, so will disappear
569 when this compilation unit leaves the cache. */
572 /* The location description associated with this DIE, if any. */
573 struct dwarf_block
*locdesc
;
575 /* If HAS_PC_INFO, the PC range associated with this DIE. */
579 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
580 DW_AT_sibling, if any. */
581 /* NOTE: This member isn't strictly necessary, read_partial_die could
582 return DW_AT_sibling values to its caller load_partial_dies. */
585 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
586 DW_AT_specification (or DW_AT_abstract_origin or
588 unsigned int spec_offset
;
590 /* Pointers to this DIE's parent, first child, and next sibling,
592 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
595 /* This data structure holds the information of an abbrev. */
598 unsigned int number
; /* number identifying abbrev */
599 enum dwarf_tag tag
; /* dwarf tag */
600 unsigned short has_children
; /* boolean */
601 unsigned short num_attrs
; /* number of attributes */
602 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
603 struct abbrev_info
*next
; /* next in chain */
608 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
609 ENUM_BITFIELD(dwarf_form
) form
: 16;
612 /* Attributes have a name and a value. */
615 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
616 ENUM_BITFIELD(dwarf_form
) form
: 15;
618 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
619 field should be in u.str (existing only for DW_STRING) but it is kept
620 here for better struct attribute alignment. */
621 unsigned int string_is_canonical
: 1;
626 struct dwarf_block
*blk
;
630 struct signatured_type
*signatured_type
;
635 /* This data structure holds a complete die structure. */
638 /* DWARF-2 tag for this DIE. */
639 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
641 /* Number of attributes */
642 unsigned char num_attrs
;
644 /* True if we're presently building the full type name for the
645 type derived from this DIE. */
646 unsigned char building_fullname
: 1;
651 /* Offset in .debug_info or .debug_types section. */
654 /* The dies in a compilation unit form an n-ary tree. PARENT
655 points to this die's parent; CHILD points to the first child of
656 this node; and all the children of a given node are chained
657 together via their SIBLING fields. */
658 struct die_info
*child
; /* Its first child, if any. */
659 struct die_info
*sibling
; /* Its next sibling, if any. */
660 struct die_info
*parent
; /* Its parent, if any. */
662 /* An array of attributes, with NUM_ATTRS elements. There may be
663 zero, but it's not common and zero-sized arrays are not
664 sufficiently portable C. */
665 struct attribute attrs
[1];
668 /* Get at parts of an attribute structure. */
670 #define DW_STRING(attr) ((attr)->u.str)
671 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
672 #define DW_UNSND(attr) ((attr)->u.unsnd)
673 #define DW_BLOCK(attr) ((attr)->u.blk)
674 #define DW_SND(attr) ((attr)->u.snd)
675 #define DW_ADDR(attr) ((attr)->u.addr)
676 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
678 /* Blocks are a bunch of untyped bytes. */
683 /* Valid only if SIZE is not zero. */
687 #ifndef ATTR_ALLOC_CHUNK
688 #define ATTR_ALLOC_CHUNK 4
691 /* Allocate fields for structs, unions and enums in this size. */
692 #ifndef DW_FIELD_ALLOC_CHUNK
693 #define DW_FIELD_ALLOC_CHUNK 4
696 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
697 but this would require a corresponding change in unpack_field_as_long
699 static int bits_per_byte
= 8;
701 /* The routines that read and process dies for a C struct or C++ class
702 pass lists of data member fields and lists of member function fields
703 in an instance of a field_info structure, as defined below. */
706 /* List of data member and baseclasses fields. */
709 struct nextfield
*next
;
714 *fields
, *baseclasses
;
716 /* Number of fields (including baseclasses). */
719 /* Number of baseclasses. */
722 /* Set if the accesibility of one of the fields is not public. */
723 int non_public_fields
;
725 /* Member function fields array, entries are allocated in the order they
726 are encountered in the object file. */
729 struct nextfnfield
*next
;
730 struct fn_field fnfield
;
734 /* Member function fieldlist array, contains name of possibly overloaded
735 member function, number of overloaded member functions and a pointer
736 to the head of the member function field chain. */
741 struct nextfnfield
*head
;
745 /* Number of entries in the fnfieldlists array. */
748 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
749 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
750 struct typedef_field_list
752 struct typedef_field field
;
753 struct typedef_field_list
*next
;
756 unsigned typedef_field_list_count
;
759 /* One item on the queue of compilation units to read in full symbols
761 struct dwarf2_queue_item
763 struct dwarf2_per_cu_data
*per_cu
;
764 struct dwarf2_queue_item
*next
;
767 /* The current queue. */
768 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
770 /* Loaded secondary compilation units are kept in memory until they
771 have not been referenced for the processing of this many
772 compilation units. Set this to zero to disable caching. Cache
773 sizes of up to at least twenty will improve startup time for
774 typical inter-CU-reference binaries, at an obvious memory cost. */
775 static int dwarf2_max_cache_age
= 5;
777 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
778 struct cmd_list_element
*c
, const char *value
)
780 fprintf_filtered (file
, _("The upper bound on the age of cached "
781 "dwarf2 compilation units is %s.\n"),
786 /* Various complaints about symbol reading that don't abort the process. */
789 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
791 complaint (&symfile_complaints
,
792 _("statement list doesn't fit in .debug_line section"));
796 dwarf2_debug_line_missing_file_complaint (void)
798 complaint (&symfile_complaints
,
799 _(".debug_line section has line data without a file"));
803 dwarf2_debug_line_missing_end_sequence_complaint (void)
805 complaint (&symfile_complaints
,
806 _(".debug_line section has line "
807 "program sequence without an end"));
811 dwarf2_complex_location_expr_complaint (void)
813 complaint (&symfile_complaints
, _("location expression too complex"));
817 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
820 complaint (&symfile_complaints
,
821 _("const value length mismatch for '%s', got %d, expected %d"),
826 dwarf2_macros_too_long_complaint (struct dwarf2_section_info
*section
)
828 complaint (&symfile_complaints
,
829 _("macro info runs off end of `%s' section"),
830 section
->asection
->name
);
834 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
836 complaint (&symfile_complaints
,
837 _("macro debug info contains a "
838 "malformed macro definition:\n`%s'"),
843 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
845 complaint (&symfile_complaints
,
846 _("invalid attribute class or form for '%s' in '%s'"),
850 /* local function prototypes */
852 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
854 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
857 static void dwarf2_find_base_address (struct die_info
*die
,
858 struct dwarf2_cu
*cu
);
860 static void dwarf2_build_psymtabs_hard (struct objfile
*);
862 static void scan_partial_symbols (struct partial_die_info
*,
863 CORE_ADDR
*, CORE_ADDR
*,
864 int, struct dwarf2_cu
*);
866 static void add_partial_symbol (struct partial_die_info
*,
869 static void add_partial_namespace (struct partial_die_info
*pdi
,
870 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
871 int need_pc
, struct dwarf2_cu
*cu
);
873 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
874 CORE_ADDR
*highpc
, int need_pc
,
875 struct dwarf2_cu
*cu
);
877 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
878 struct dwarf2_cu
*cu
);
880 static void add_partial_subprogram (struct partial_die_info
*pdi
,
881 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
882 int need_pc
, struct dwarf2_cu
*cu
);
884 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
885 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
886 bfd
*abfd
, struct dwarf2_cu
*cu
);
888 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
890 static void psymtab_to_symtab_1 (struct partial_symtab
*);
892 static void dwarf2_read_abbrevs (struct dwarf2_cu
*cu
);
894 static void dwarf2_free_abbrev_table (void *);
896 static unsigned int peek_abbrev_code (bfd
*, gdb_byte
*);
898 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
901 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
904 static struct partial_die_info
*load_partial_dies (bfd
*,
905 gdb_byte
*, gdb_byte
*,
906 int, struct dwarf2_cu
*);
908 static gdb_byte
*read_partial_die (struct partial_die_info
*,
909 struct abbrev_info
*abbrev
,
911 gdb_byte
*, gdb_byte
*,
914 static struct partial_die_info
*find_partial_die (unsigned int,
917 static void fixup_partial_die (struct partial_die_info
*,
920 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
921 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
923 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
924 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
926 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
928 static int read_1_signed_byte (bfd
*, gdb_byte
*);
930 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
932 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
934 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
936 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
939 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
941 static LONGEST read_checked_initial_length_and_offset
942 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
943 unsigned int *, unsigned int *);
945 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
948 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
950 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
952 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
954 static char *read_indirect_string (bfd
*, gdb_byte
*,
955 const struct comp_unit_head
*,
958 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
960 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
962 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
964 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
966 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
969 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
973 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
974 struct dwarf2_cu
*cu
);
976 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
978 static struct die_info
*die_specification (struct die_info
*die
,
979 struct dwarf2_cu
**);
981 static void free_line_header (struct line_header
*lh
);
983 static void add_file_name (struct line_header
*, char *, unsigned int,
984 unsigned int, unsigned int);
986 static struct line_header
*(dwarf_decode_line_header
987 (unsigned int offset
,
988 bfd
*abfd
, struct dwarf2_cu
*cu
));
990 static void dwarf_decode_lines (struct line_header
*, const char *,
991 struct dwarf2_cu
*, struct partial_symtab
*,
994 static void dwarf2_start_subfile (char *, const char *, const char *);
996 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
999 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1000 struct dwarf2_cu
*, struct symbol
*);
1002 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1003 struct dwarf2_cu
*);
1005 static void dwarf2_const_value_attr (struct attribute
*attr
,
1008 struct obstack
*obstack
,
1009 struct dwarf2_cu
*cu
, long *value
,
1011 struct dwarf2_locexpr_baton
**baton
);
1013 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1015 static int need_gnat_info (struct dwarf2_cu
*);
1017 static struct type
*die_descriptive_type (struct die_info
*,
1018 struct dwarf2_cu
*);
1020 static void set_descriptive_type (struct type
*, struct die_info
*,
1021 struct dwarf2_cu
*);
1023 static struct type
*die_containing_type (struct die_info
*,
1024 struct dwarf2_cu
*);
1026 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1027 struct dwarf2_cu
*);
1029 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1031 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1033 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1035 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1036 const char *suffix
, int physname
,
1037 struct dwarf2_cu
*cu
);
1039 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1041 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1043 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1045 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1047 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1049 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1050 struct dwarf2_cu
*, struct partial_symtab
*);
1052 static int dwarf2_get_pc_bounds (struct die_info
*,
1053 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1054 struct partial_symtab
*);
1056 static void get_scope_pc_bounds (struct die_info
*,
1057 CORE_ADDR
*, CORE_ADDR
*,
1058 struct dwarf2_cu
*);
1060 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1061 CORE_ADDR
, struct dwarf2_cu
*);
1063 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1064 struct dwarf2_cu
*);
1066 static void dwarf2_attach_fields_to_type (struct field_info
*,
1067 struct type
*, struct dwarf2_cu
*);
1069 static void dwarf2_add_member_fn (struct field_info
*,
1070 struct die_info
*, struct type
*,
1071 struct dwarf2_cu
*);
1073 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1075 struct dwarf2_cu
*);
1077 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1079 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1081 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1083 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1085 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1087 static struct type
*read_module_type (struct die_info
*die
,
1088 struct dwarf2_cu
*cu
);
1090 static const char *namespace_name (struct die_info
*die
,
1091 int *is_anonymous
, struct dwarf2_cu
*);
1093 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1095 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1097 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1098 struct dwarf2_cu
*);
1100 static struct die_info
*read_comp_unit (gdb_byte
*, struct dwarf2_cu
*);
1102 static struct die_info
*read_die_and_children_1 (const struct die_reader_specs
*reader
,
1104 gdb_byte
**new_info_ptr
,
1105 struct die_info
*parent
);
1107 static struct die_info
*read_die_and_children (const struct die_reader_specs
*reader
,
1109 gdb_byte
**new_info_ptr
,
1110 struct die_info
*parent
);
1112 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*reader
,
1114 gdb_byte
**new_info_ptr
,
1115 struct die_info
*parent
);
1117 static gdb_byte
*read_full_die (const struct die_reader_specs
*reader
,
1118 struct die_info
**, gdb_byte
*,
1121 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1123 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1126 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1128 static const char *dwarf2_full_name (char *name
,
1129 struct die_info
*die
,
1130 struct dwarf2_cu
*cu
);
1132 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1133 struct dwarf2_cu
**);
1135 static char *dwarf_tag_name (unsigned int);
1137 static char *dwarf_attr_name (unsigned int);
1139 static char *dwarf_form_name (unsigned int);
1141 static char *dwarf_bool_name (unsigned int);
1143 static char *dwarf_type_encoding_name (unsigned int);
1146 static char *dwarf_cfi_name (unsigned int);
1149 static struct die_info
*sibling_die (struct die_info
*);
1151 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1153 static void dump_die_for_error (struct die_info
*);
1155 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1158 /*static*/ void dump_die (struct die_info
*, int max_level
);
1160 static void store_in_ref_table (struct die_info
*,
1161 struct dwarf2_cu
*);
1163 static int is_ref_attr (struct attribute
*);
1165 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1167 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1169 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1171 struct dwarf2_cu
**);
1173 static struct die_info
*follow_die_ref (struct die_info
*,
1175 struct dwarf2_cu
**);
1177 static struct die_info
*follow_die_sig (struct die_info
*,
1179 struct dwarf2_cu
**);
1181 static struct signatured_type
*lookup_signatured_type_at_offset
1182 (struct objfile
*objfile
,
1183 struct dwarf2_section_info
*section
,
1184 unsigned int offset
);
1186 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1188 static void read_signatured_type (struct signatured_type
*type_sig
);
1190 /* memory allocation interface */
1192 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1194 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1196 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1198 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1199 char *, bfd
*, struct dwarf2_cu
*,
1200 struct dwarf2_section_info
*,
1203 static int attr_form_is_block (struct attribute
*);
1205 static int attr_form_is_section_offset (struct attribute
*);
1207 static int attr_form_is_constant (struct attribute
*);
1209 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1210 struct dwarf2_loclist_baton
*baton
,
1211 struct attribute
*attr
);
1213 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1215 struct dwarf2_cu
*cu
);
1217 static gdb_byte
*skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1218 struct abbrev_info
*abbrev
,
1219 struct dwarf2_cu
*cu
);
1221 static void free_stack_comp_unit (void *);
1223 static hashval_t
partial_die_hash (const void *item
);
1225 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1227 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1228 (unsigned int offset
, struct objfile
*objfile
);
1230 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1231 struct dwarf2_per_cu_data
*per_cu
);
1233 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1234 struct die_info
*comp_unit_die
);
1236 static void free_heap_comp_unit (void *);
1238 static void free_cached_comp_units (void *);
1240 static void age_cached_comp_units (void);
1242 static void free_one_cached_comp_unit (void *);
1244 static struct type
*set_die_type (struct die_info
*, struct type
*,
1245 struct dwarf2_cu
*);
1247 static void create_all_comp_units (struct objfile
*);
1249 static int create_debug_types_hash_table (struct objfile
*objfile
);
1251 static void load_full_comp_unit (struct dwarf2_per_cu_data
*);
1253 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1255 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1256 struct dwarf2_per_cu_data
*);
1258 static void dwarf2_mark (struct dwarf2_cu
*);
1260 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1262 static struct type
*get_die_type_at_offset (unsigned int,
1263 struct dwarf2_per_cu_data
*per_cu
);
1265 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1267 static void dwarf2_release_queue (void *dummy
);
1269 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
);
1271 static void process_queue (void);
1273 static void find_file_and_directory (struct die_info
*die
,
1274 struct dwarf2_cu
*cu
,
1275 char **name
, char **comp_dir
);
1277 static char *file_full_name (int file
, struct line_header
*lh
,
1278 const char *comp_dir
);
1280 static gdb_byte
*read_and_check_comp_unit_head
1281 (struct comp_unit_head
*header
,
1282 struct dwarf2_section_info
*section
, gdb_byte
*info_ptr
,
1283 int is_debug_types_section
);
1285 static void init_cu_die_reader (struct die_reader_specs
*reader
,
1286 struct dwarf2_cu
*cu
);
1288 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1292 /* Convert VALUE between big- and little-endian. */
1294 byte_swap (offset_type value
)
1298 result
= (value
& 0xff) << 24;
1299 result
|= (value
& 0xff00) << 8;
1300 result
|= (value
& 0xff0000) >> 8;
1301 result
|= (value
& 0xff000000) >> 24;
1305 #define MAYBE_SWAP(V) byte_swap (V)
1308 #define MAYBE_SWAP(V) (V)
1309 #endif /* WORDS_BIGENDIAN */
1311 /* The suffix for an index file. */
1312 #define INDEX_SUFFIX ".gdb-index"
1314 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1315 struct dwarf2_cu
*cu
);
1317 /* Try to locate the sections we need for DWARF 2 debugging
1318 information and return true if we have enough to do something.
1319 NAMES points to the dwarf2 section names, or is NULL if the standard
1320 ELF names are used. */
1323 dwarf2_has_info (struct objfile
*objfile
,
1324 const struct dwarf2_debug_sections
*names
)
1326 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1327 if (!dwarf2_per_objfile
)
1329 /* Initialize per-objfile state. */
1330 struct dwarf2_per_objfile
*data
1331 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1333 memset (data
, 0, sizeof (*data
));
1334 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1335 dwarf2_per_objfile
= data
;
1337 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1339 dwarf2_per_objfile
->objfile
= objfile
;
1341 return (dwarf2_per_objfile
->info
.asection
!= NULL
1342 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1345 /* When loading sections, we look either for uncompressed section or for
1346 compressed section names. */
1349 section_is_p (const char *section_name
,
1350 const struct dwarf2_section_names
*names
)
1352 if (names
->normal
!= NULL
1353 && strcmp (section_name
, names
->normal
) == 0)
1355 if (names
->compressed
!= NULL
1356 && strcmp (section_name
, names
->compressed
) == 0)
1361 /* This function is mapped across the sections and remembers the
1362 offset and size of each of the debugging sections we are interested
1366 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1368 const struct dwarf2_debug_sections
*names
;
1371 names
= &dwarf2_elf_names
;
1373 names
= (const struct dwarf2_debug_sections
*) vnames
;
1375 if (section_is_p (sectp
->name
, &names
->info
))
1377 dwarf2_per_objfile
->info
.asection
= sectp
;
1378 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1380 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1382 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1383 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1385 else if (section_is_p (sectp
->name
, &names
->line
))
1387 dwarf2_per_objfile
->line
.asection
= sectp
;
1388 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1390 else if (section_is_p (sectp
->name
, &names
->loc
))
1392 dwarf2_per_objfile
->loc
.asection
= sectp
;
1393 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1395 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1397 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1398 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1400 else if (section_is_p (sectp
->name
, &names
->macro
))
1402 dwarf2_per_objfile
->macro
.asection
= sectp
;
1403 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
1405 else if (section_is_p (sectp
->name
, &names
->str
))
1407 dwarf2_per_objfile
->str
.asection
= sectp
;
1408 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1410 else if (section_is_p (sectp
->name
, &names
->frame
))
1412 dwarf2_per_objfile
->frame
.asection
= sectp
;
1413 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1415 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1417 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1419 if (aflag
& SEC_HAS_CONTENTS
)
1421 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1422 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1425 else if (section_is_p (sectp
->name
, &names
->ranges
))
1427 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1428 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1430 else if (section_is_p (sectp
->name
, &names
->types
))
1432 struct dwarf2_section_info type_section
;
1434 memset (&type_section
, 0, sizeof (type_section
));
1435 type_section
.asection
= sectp
;
1436 type_section
.size
= bfd_get_section_size (sectp
);
1438 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
1441 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1443 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1444 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1447 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1448 && bfd_section_vma (abfd
, sectp
) == 0)
1449 dwarf2_per_objfile
->has_section_at_zero
= 1;
1452 /* Decompress a section that was compressed using zlib. Store the
1453 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1456 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1457 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1459 bfd
*abfd
= objfile
->obfd
;
1461 error (_("Support for zlib-compressed DWARF data (from '%s') "
1462 "is disabled in this copy of GDB"),
1463 bfd_get_filename (abfd
));
1465 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1466 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1467 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1468 bfd_size_type uncompressed_size
;
1469 gdb_byte
*uncompressed_buffer
;
1472 int header_size
= 12;
1474 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1475 || bfd_bread (compressed_buffer
,
1476 compressed_size
, abfd
) != compressed_size
)
1477 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1478 bfd_get_filename (abfd
));
1480 /* Read the zlib header. In this case, it should be "ZLIB" followed
1481 by the uncompressed section size, 8 bytes in big-endian order. */
1482 if (compressed_size
< header_size
1483 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1484 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1485 bfd_get_filename (abfd
));
1486 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1487 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1488 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1489 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1490 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1491 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1492 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1493 uncompressed_size
+= compressed_buffer
[11];
1495 /* It is possible the section consists of several compressed
1496 buffers concatenated together, so we uncompress in a loop. */
1500 strm
.avail_in
= compressed_size
- header_size
;
1501 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1502 strm
.avail_out
= uncompressed_size
;
1503 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1505 rc
= inflateInit (&strm
);
1506 while (strm
.avail_in
> 0)
1509 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1510 bfd_get_filename (abfd
), rc
);
1511 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1512 + (uncompressed_size
- strm
.avail_out
));
1513 rc
= inflate (&strm
, Z_FINISH
);
1514 if (rc
!= Z_STREAM_END
)
1515 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1516 bfd_get_filename (abfd
), rc
);
1517 rc
= inflateReset (&strm
);
1519 rc
= inflateEnd (&strm
);
1521 || strm
.avail_out
!= 0)
1522 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1523 bfd_get_filename (abfd
), rc
);
1525 do_cleanups (cleanup
);
1526 *outbuf
= uncompressed_buffer
;
1527 *outsize
= uncompressed_size
;
1531 /* A helper function that decides whether a section is empty. */
1534 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1536 return info
->asection
== NULL
|| info
->size
== 0;
1539 /* Read the contents of the section INFO from object file specified by
1540 OBJFILE, store info about the section into INFO.
1541 If the section is compressed, uncompress it before returning. */
1544 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1546 bfd
*abfd
= objfile
->obfd
;
1547 asection
*sectp
= info
->asection
;
1548 gdb_byte
*buf
, *retbuf
;
1549 unsigned char header
[4];
1553 info
->buffer
= NULL
;
1554 info
->map_addr
= NULL
;
1557 if (dwarf2_section_empty_p (info
))
1560 /* Check if the file has a 4-byte header indicating compression. */
1561 if (info
->size
> sizeof (header
)
1562 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1563 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1565 /* Upon decompression, update the buffer and its size. */
1566 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1568 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1576 pagesize
= getpagesize ();
1578 /* Only try to mmap sections which are large enough: we don't want to
1579 waste space due to fragmentation. Also, only try mmap for sections
1580 without relocations. */
1582 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1584 info
->buffer
= bfd_mmap (abfd
, 0, info
->size
, PROT_READ
,
1585 MAP_PRIVATE
, sectp
->filepos
,
1586 &info
->map_addr
, &info
->map_len
);
1588 if ((caddr_t
)info
->buffer
!= MAP_FAILED
)
1590 #if HAVE_POSIX_MADVISE
1591 posix_madvise (info
->map_addr
, info
->map_len
, POSIX_MADV_WILLNEED
);
1598 /* If we get here, we are a normal, not-compressed section. */
1600 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1602 /* When debugging .o files, we may need to apply relocations; see
1603 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1604 We never compress sections in .o files, so we only need to
1605 try this when the section is not compressed. */
1606 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1609 info
->buffer
= retbuf
;
1613 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1614 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1615 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1616 bfd_get_filename (abfd
));
1619 /* A helper function that returns the size of a section in a safe way.
1620 If you are positive that the section has been read before using the
1621 size, then it is safe to refer to the dwarf2_section_info object's
1622 "size" field directly. In other cases, you must call this
1623 function, because for compressed sections the size field is not set
1624 correctly until the section has been read. */
1626 static bfd_size_type
1627 dwarf2_section_size (struct objfile
*objfile
,
1628 struct dwarf2_section_info
*info
)
1631 dwarf2_read_section (objfile
, info
);
1635 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1639 dwarf2_get_section_info (struct objfile
*objfile
,
1640 enum dwarf2_section_enum sect
,
1641 asection
**sectp
, gdb_byte
**bufp
,
1642 bfd_size_type
*sizep
)
1644 struct dwarf2_per_objfile
*data
1645 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1646 struct dwarf2_section_info
*info
;
1648 /* We may see an objfile without any DWARF, in which case we just
1659 case DWARF2_DEBUG_FRAME
:
1660 info
= &data
->frame
;
1662 case DWARF2_EH_FRAME
:
1663 info
= &data
->eh_frame
;
1666 gdb_assert_not_reached ("unexpected section");
1669 dwarf2_read_section (objfile
, info
);
1671 *sectp
= info
->asection
;
1672 *bufp
= info
->buffer
;
1673 *sizep
= info
->size
;
1677 /* DWARF quick_symbols_functions support. */
1679 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1680 unique line tables, so we maintain a separate table of all .debug_line
1681 derived entries to support the sharing.
1682 All the quick functions need is the list of file names. We discard the
1683 line_header when we're done and don't need to record it here. */
1684 struct quick_file_names
1686 /* The offset in .debug_line of the line table. We hash on this. */
1687 unsigned int offset
;
1689 /* The number of entries in file_names, real_names. */
1690 unsigned int num_file_names
;
1692 /* The file names from the line table, after being run through
1694 const char **file_names
;
1696 /* The file names from the line table after being run through
1697 gdb_realpath. These are computed lazily. */
1698 const char **real_names
;
1701 /* When using the index (and thus not using psymtabs), each CU has an
1702 object of this type. This is used to hold information needed by
1703 the various "quick" methods. */
1704 struct dwarf2_per_cu_quick_data
1706 /* The file table. This can be NULL if there was no file table
1707 or it's currently not read in.
1708 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1709 struct quick_file_names
*file_names
;
1711 /* The corresponding symbol table. This is NULL if symbols for this
1712 CU have not yet been read. */
1713 struct symtab
*symtab
;
1715 /* A temporary mark bit used when iterating over all CUs in
1716 expand_symtabs_matching. */
1717 unsigned int mark
: 1;
1719 /* True if we've tried to read the file table and found there isn't one.
1720 There will be no point in trying to read it again next time. */
1721 unsigned int no_file_data
: 1;
1724 /* Hash function for a quick_file_names. */
1727 hash_file_name_entry (const void *e
)
1729 const struct quick_file_names
*file_data
= e
;
1731 return file_data
->offset
;
1734 /* Equality function for a quick_file_names. */
1737 eq_file_name_entry (const void *a
, const void *b
)
1739 const struct quick_file_names
*ea
= a
;
1740 const struct quick_file_names
*eb
= b
;
1742 return ea
->offset
== eb
->offset
;
1745 /* Delete function for a quick_file_names. */
1748 delete_file_name_entry (void *e
)
1750 struct quick_file_names
*file_data
= e
;
1753 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
1755 xfree ((void*) file_data
->file_names
[i
]);
1756 if (file_data
->real_names
)
1757 xfree ((void*) file_data
->real_names
[i
]);
1760 /* The space for the struct itself lives on objfile_obstack,
1761 so we don't free it here. */
1764 /* Create a quick_file_names hash table. */
1767 create_quick_file_names_table (unsigned int nr_initial_entries
)
1769 return htab_create_alloc (nr_initial_entries
,
1770 hash_file_name_entry
, eq_file_name_entry
,
1771 delete_file_name_entry
, xcalloc
, xfree
);
1774 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
1775 have to be created afterwards. You should call age_cached_comp_units after
1776 processing PER_CU->CU. dw2_setup must have been already called. */
1779 load_cu (struct dwarf2_per_cu_data
*per_cu
)
1781 if (per_cu
->debug_types_section
)
1782 load_full_type_unit (per_cu
);
1784 load_full_comp_unit (per_cu
);
1786 gdb_assert (per_cu
->cu
!= NULL
);
1788 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
1791 /* Read in the symbols for PER_CU. */
1794 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
1796 struct cleanup
*back_to
;
1798 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
1800 queue_comp_unit (per_cu
);
1806 /* Age the cache, releasing compilation units that have not
1807 been used recently. */
1808 age_cached_comp_units ();
1810 do_cleanups (back_to
);
1813 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1814 the objfile from which this CU came. Returns the resulting symbol
1817 static struct symtab
*
1818 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
1820 if (!per_cu
->v
.quick
->symtab
)
1822 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1823 increment_reading_symtab ();
1824 dw2_do_instantiate_symtab (per_cu
);
1825 do_cleanups (back_to
);
1827 return per_cu
->v
.quick
->symtab
;
1830 /* Return the CU given its index. */
1832 static struct dwarf2_per_cu_data
*
1833 dw2_get_cu (int index
)
1835 if (index
>= dwarf2_per_objfile
->n_comp_units
)
1837 index
-= dwarf2_per_objfile
->n_comp_units
;
1838 return dwarf2_per_objfile
->all_type_units
[index
];
1840 return dwarf2_per_objfile
->all_comp_units
[index
];
1843 /* A helper function that knows how to read a 64-bit value in a way
1844 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1848 extract_cu_value (const char *bytes
, ULONGEST
*result
)
1850 if (sizeof (ULONGEST
) < 8)
1854 /* Ignore the upper 4 bytes if they are all zero. */
1855 for (i
= 0; i
< 4; ++i
)
1856 if (bytes
[i
+ 4] != 0)
1859 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
1862 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
1866 /* Read the CU list from the mapped index, and use it to create all
1867 the CU objects for this objfile. Return 0 if something went wrong,
1868 1 if everything went ok. */
1871 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
1872 offset_type cu_list_elements
)
1876 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
1877 dwarf2_per_objfile
->all_comp_units
1878 = obstack_alloc (&objfile
->objfile_obstack
,
1879 dwarf2_per_objfile
->n_comp_units
1880 * sizeof (struct dwarf2_per_cu_data
*));
1882 for (i
= 0; i
< cu_list_elements
; i
+= 2)
1884 struct dwarf2_per_cu_data
*the_cu
;
1885 ULONGEST offset
, length
;
1887 if (!extract_cu_value (cu_list
, &offset
)
1888 || !extract_cu_value (cu_list
+ 8, &length
))
1892 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1893 struct dwarf2_per_cu_data
);
1894 the_cu
->offset
= offset
;
1895 the_cu
->length
= length
;
1896 the_cu
->objfile
= objfile
;
1897 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1898 struct dwarf2_per_cu_quick_data
);
1899 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
1905 /* Create the signatured type hash table from the index. */
1908 create_signatured_type_table_from_index (struct objfile
*objfile
,
1909 struct dwarf2_section_info
*section
,
1910 const gdb_byte
*bytes
,
1911 offset_type elements
)
1914 htab_t sig_types_hash
;
1916 dwarf2_per_objfile
->n_type_units
= elements
/ 3;
1917 dwarf2_per_objfile
->all_type_units
1918 = obstack_alloc (&objfile
->objfile_obstack
,
1919 dwarf2_per_objfile
->n_type_units
1920 * sizeof (struct dwarf2_per_cu_data
*));
1922 sig_types_hash
= allocate_signatured_type_table (objfile
);
1924 for (i
= 0; i
< elements
; i
+= 3)
1926 struct signatured_type
*type_sig
;
1927 ULONGEST offset
, type_offset
, signature
;
1930 if (!extract_cu_value (bytes
, &offset
)
1931 || !extract_cu_value (bytes
+ 8, &type_offset
))
1933 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
1936 type_sig
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1937 struct signatured_type
);
1938 type_sig
->signature
= signature
;
1939 type_sig
->type_offset
= type_offset
;
1940 type_sig
->per_cu
.debug_types_section
= section
;
1941 type_sig
->per_cu
.offset
= offset
;
1942 type_sig
->per_cu
.objfile
= objfile
;
1943 type_sig
->per_cu
.v
.quick
1944 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1945 struct dwarf2_per_cu_quick_data
);
1947 slot
= htab_find_slot (sig_types_hash
, type_sig
, INSERT
);
1950 dwarf2_per_objfile
->all_type_units
[i
/ 3] = &type_sig
->per_cu
;
1953 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
1958 /* Read the address map data from the mapped index, and use it to
1959 populate the objfile's psymtabs_addrmap. */
1962 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
1964 const gdb_byte
*iter
, *end
;
1965 struct obstack temp_obstack
;
1966 struct addrmap
*mutable_map
;
1967 struct cleanup
*cleanup
;
1970 obstack_init (&temp_obstack
);
1971 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
1972 mutable_map
= addrmap_create_mutable (&temp_obstack
);
1974 iter
= index
->address_table
;
1975 end
= iter
+ index
->address_table_size
;
1977 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1981 ULONGEST hi
, lo
, cu_index
;
1982 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1984 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1986 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
1989 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
1990 dw2_get_cu (cu_index
));
1993 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
1994 &objfile
->objfile_obstack
);
1995 do_cleanups (cleanup
);
1998 /* The hash function for strings in the mapped index. This is the same as
1999 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2000 implementation. This is necessary because the hash function is tied to the
2001 format of the mapped index file. The hash values do not have to match with
2004 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2007 mapped_index_string_hash (int index_version
, const void *p
)
2009 const unsigned char *str
= (const unsigned char *) p
;
2013 while ((c
= *str
++) != 0)
2015 if (index_version
>= 5)
2017 r
= r
* 67 + c
- 113;
2023 /* Find a slot in the mapped index INDEX for the object named NAME.
2024 If NAME is found, set *VEC_OUT to point to the CU vector in the
2025 constant pool and return 1. If NAME cannot be found, return 0. */
2028 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2029 offset_type
**vec_out
)
2031 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2033 offset_type slot
, step
;
2034 int (*cmp
) (const char *, const char *);
2036 if (current_language
->la_language
== language_cplus
2037 || current_language
->la_language
== language_java
2038 || current_language
->la_language
== language_fortran
)
2040 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2042 const char *paren
= strchr (name
, '(');
2048 dup
= xmalloc (paren
- name
+ 1);
2049 memcpy (dup
, name
, paren
- name
);
2050 dup
[paren
- name
] = 0;
2052 make_cleanup (xfree
, dup
);
2057 /* Index version 4 did not support case insensitive searches. But the
2058 indices for case insensitive languages are built in lowercase, therefore
2059 simulate our NAME being searched is also lowercased. */
2060 hash
= mapped_index_string_hash ((index
->version
== 4
2061 && case_sensitivity
== case_sensitive_off
2062 ? 5 : index
->version
),
2065 slot
= hash
& (index
->symbol_table_slots
- 1);
2066 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2067 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2071 /* Convert a slot number to an offset into the table. */
2072 offset_type i
= 2 * slot
;
2074 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2076 do_cleanups (back_to
);
2080 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2081 if (!cmp (name
, str
))
2083 *vec_out
= (offset_type
*) (index
->constant_pool
2084 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2085 do_cleanups (back_to
);
2089 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2093 /* Read the index file. If everything went ok, initialize the "quick"
2094 elements of all the CUs and return 1. Otherwise, return 0. */
2097 dwarf2_read_index (struct objfile
*objfile
)
2100 struct mapped_index
*map
;
2101 offset_type
*metadata
;
2102 const gdb_byte
*cu_list
;
2103 const gdb_byte
*types_list
= NULL
;
2104 offset_type version
, cu_list_elements
;
2105 offset_type types_list_elements
= 0;
2108 if (dwarf2_section_empty_p (&dwarf2_per_objfile
->gdb_index
))
2111 /* Older elfutils strip versions could keep the section in the main
2112 executable while splitting it for the separate debug info file. */
2113 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
2114 & SEC_HAS_CONTENTS
) == 0)
2117 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
2119 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
2120 /* Version check. */
2121 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2122 /* Versions earlier than 3 emitted every copy of a psymbol. This
2123 causes the index to behave very poorly for certain requests. Version 3
2124 contained incomplete addrmap. So, it seems better to just ignore such
2128 static int warning_printed
= 0;
2129 if (!warning_printed
)
2131 warning (_("Skipping obsolete .gdb_index section in %s."),
2133 warning_printed
= 1;
2137 /* Index version 4 uses a different hash function than index version
2140 Versions earlier than 6 did not emit psymbols for inlined
2141 functions. Using these files will cause GDB not to be able to
2142 set breakpoints on inlined functions by name, so we ignore these
2143 indices unless the --use-deprecated-index-sections command line
2144 option was supplied. */
2145 if (version
< 6 && !use_deprecated_index_sections
)
2147 static int warning_printed
= 0;
2148 if (!warning_printed
)
2150 warning (_("Skipping deprecated .gdb_index section in %s, pass "
2151 "--use-deprecated-index-sections to use them anyway"),
2153 warning_printed
= 1;
2157 /* Indexes with higher version than the one supported by GDB may be no
2158 longer backward compatible. */
2162 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
2163 map
->version
= version
;
2164 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
2166 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2169 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2170 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2174 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2175 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2176 - MAYBE_SWAP (metadata
[i
]))
2180 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2181 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2182 - MAYBE_SWAP (metadata
[i
]));
2185 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2186 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2187 - MAYBE_SWAP (metadata
[i
]))
2188 / (2 * sizeof (offset_type
)));
2191 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2193 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
2196 if (types_list_elements
)
2198 struct dwarf2_section_info
*section
;
2200 /* We can only handle a single .debug_types when we have an
2202 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2205 section
= VEC_index (dwarf2_section_info_def
,
2206 dwarf2_per_objfile
->types
, 0);
2208 if (!create_signatured_type_table_from_index (objfile
, section
,
2210 types_list_elements
))
2214 create_addrmap_from_index (objfile
, map
);
2216 dwarf2_per_objfile
->index_table
= map
;
2217 dwarf2_per_objfile
->using_index
= 1;
2218 dwarf2_per_objfile
->quick_file_names_table
=
2219 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2224 /* A helper for the "quick" functions which sets the global
2225 dwarf2_per_objfile according to OBJFILE. */
2228 dw2_setup (struct objfile
*objfile
)
2230 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2231 gdb_assert (dwarf2_per_objfile
);
2234 /* A helper for the "quick" functions which attempts to read the line
2235 table for THIS_CU. */
2237 static struct quick_file_names
*
2238 dw2_get_file_names (struct objfile
*objfile
,
2239 struct dwarf2_per_cu_data
*this_cu
)
2241 bfd
*abfd
= objfile
->obfd
;
2242 struct line_header
*lh
;
2243 struct attribute
*attr
;
2244 struct cleanup
*cleanups
;
2245 struct die_info
*comp_unit_die
;
2246 struct dwarf2_section_info
* sec
;
2248 int has_children
, i
;
2249 struct dwarf2_cu cu
;
2250 unsigned int bytes_read
;
2251 struct die_reader_specs reader_specs
;
2252 char *name
, *comp_dir
;
2254 struct quick_file_names
*qfn
;
2255 unsigned int line_offset
;
2257 if (this_cu
->v
.quick
->file_names
!= NULL
)
2258 return this_cu
->v
.quick
->file_names
;
2259 /* If we know there is no line data, no point in looking again. */
2260 if (this_cu
->v
.quick
->no_file_data
)
2263 init_one_comp_unit (&cu
, this_cu
);
2264 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
2266 if (this_cu
->debug_types_section
)
2267 sec
= this_cu
->debug_types_section
;
2269 sec
= &dwarf2_per_objfile
->info
;
2270 dwarf2_read_section (objfile
, sec
);
2271 info_ptr
= sec
->buffer
+ this_cu
->offset
;
2273 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, sec
, info_ptr
,
2274 this_cu
->debug_types_section
!= NULL
);
2276 /* Skip dummy compilation units. */
2277 if (info_ptr
>= (sec
->buffer
+ sec
->size
)
2278 || peek_abbrev_code (abfd
, info_ptr
) == 0)
2280 do_cleanups (cleanups
);
2284 dwarf2_read_abbrevs (&cu
);
2285 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2287 init_cu_die_reader (&reader_specs
, &cu
);
2288 read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2294 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, &cu
);
2297 struct quick_file_names find_entry
;
2299 line_offset
= DW_UNSND (attr
);
2301 /* We may have already read in this line header (TU line header sharing).
2302 If we have we're done. */
2303 find_entry
.offset
= line_offset
;
2304 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2305 &find_entry
, INSERT
);
2308 do_cleanups (cleanups
);
2309 this_cu
->v
.quick
->file_names
= *slot
;
2313 lh
= dwarf_decode_line_header (line_offset
, abfd
, &cu
);
2317 do_cleanups (cleanups
);
2318 this_cu
->v
.quick
->no_file_data
= 1;
2322 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2323 qfn
->offset
= line_offset
;
2324 gdb_assert (slot
!= NULL
);
2327 find_file_and_directory (comp_unit_die
, &cu
, &name
, &comp_dir
);
2329 qfn
->num_file_names
= lh
->num_file_names
;
2330 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2331 lh
->num_file_names
* sizeof (char *));
2332 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2333 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2334 qfn
->real_names
= NULL
;
2336 free_line_header (lh
);
2337 do_cleanups (cleanups
);
2339 this_cu
->v
.quick
->file_names
= qfn
;
2343 /* A helper for the "quick" functions which computes and caches the
2344 real path for a given file name from the line table. */
2347 dw2_get_real_path (struct objfile
*objfile
,
2348 struct quick_file_names
*qfn
, int index
)
2350 if (qfn
->real_names
== NULL
)
2351 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2352 qfn
->num_file_names
, sizeof (char *));
2354 if (qfn
->real_names
[index
] == NULL
)
2355 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2357 return qfn
->real_names
[index
];
2360 static struct symtab
*
2361 dw2_find_last_source_symtab (struct objfile
*objfile
)
2365 dw2_setup (objfile
);
2366 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2367 return dw2_instantiate_symtab (dw2_get_cu (index
));
2370 /* Traversal function for dw2_forget_cached_source_info. */
2373 dw2_free_cached_file_names (void **slot
, void *info
)
2375 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2377 if (file_data
->real_names
)
2381 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2383 xfree ((void*) file_data
->real_names
[i
]);
2384 file_data
->real_names
[i
] = NULL
;
2392 dw2_forget_cached_source_info (struct objfile
*objfile
)
2394 dw2_setup (objfile
);
2396 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2397 dw2_free_cached_file_names
, NULL
);
2400 /* Helper function for dw2_map_symtabs_matching_filename that expands
2401 the symtabs and calls the iterator. */
2404 dw2_map_expand_apply (struct objfile
*objfile
,
2405 struct dwarf2_per_cu_data
*per_cu
,
2407 const char *full_path
, const char *real_path
,
2408 int (*callback
) (struct symtab
*, void *),
2411 struct symtab
*last_made
= objfile
->symtabs
;
2413 /* Don't visit already-expanded CUs. */
2414 if (per_cu
->v
.quick
->symtab
)
2417 /* This may expand more than one symtab, and we want to iterate over
2419 dw2_instantiate_symtab (per_cu
);
2421 return iterate_over_some_symtabs (name
, full_path
, real_path
, callback
, data
,
2422 objfile
->symtabs
, last_made
);
2425 /* Implementation of the map_symtabs_matching_filename method. */
2428 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
2429 const char *full_path
, const char *real_path
,
2430 int (*callback
) (struct symtab
*, void *),
2434 const char *name_basename
= lbasename (name
);
2435 int name_len
= strlen (name
);
2436 int is_abs
= IS_ABSOLUTE_PATH (name
);
2438 dw2_setup (objfile
);
2440 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2441 + dwarf2_per_objfile
->n_type_units
); ++i
)
2444 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2445 struct quick_file_names
*file_data
;
2447 /* We only need to look at symtabs not already expanded. */
2448 if (per_cu
->v
.quick
->symtab
)
2451 file_data
= dw2_get_file_names (objfile
, per_cu
);
2452 if (file_data
== NULL
)
2455 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2457 const char *this_name
= file_data
->file_names
[j
];
2459 if (FILENAME_CMP (name
, this_name
) == 0
2460 || (!is_abs
&& compare_filenames_for_search (this_name
,
2463 if (dw2_map_expand_apply (objfile
, per_cu
,
2464 name
, full_path
, real_path
,
2469 /* Before we invoke realpath, which can get expensive when many
2470 files are involved, do a quick comparison of the basenames. */
2471 if (! basenames_may_differ
2472 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
2475 if (full_path
!= NULL
)
2477 const char *this_real_name
= dw2_get_real_path (objfile
,
2480 if (this_real_name
!= NULL
2481 && (FILENAME_CMP (full_path
, this_real_name
) == 0
2483 && compare_filenames_for_search (this_real_name
,
2486 if (dw2_map_expand_apply (objfile
, per_cu
,
2487 name
, full_path
, real_path
,
2493 if (real_path
!= NULL
)
2495 const char *this_real_name
= dw2_get_real_path (objfile
,
2498 if (this_real_name
!= NULL
2499 && (FILENAME_CMP (real_path
, this_real_name
) == 0
2501 && compare_filenames_for_search (this_real_name
,
2504 if (dw2_map_expand_apply (objfile
, per_cu
,
2505 name
, full_path
, real_path
,
2516 static struct symtab
*
2517 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2518 const char *name
, domain_enum domain
)
2520 /* We do all the work in the pre_expand_symtabs_matching hook
2525 /* A helper function that expands all symtabs that hold an object
2529 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2531 dw2_setup (objfile
);
2533 /* index_table is NULL if OBJF_READNOW. */
2534 if (dwarf2_per_objfile
->index_table
)
2538 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2541 offset_type i
, len
= MAYBE_SWAP (*vec
);
2542 for (i
= 0; i
< len
; ++i
)
2544 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2545 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2547 dw2_instantiate_symtab (per_cu
);
2554 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2555 enum block_enum block_kind
, const char *name
,
2558 dw2_do_expand_symtabs_matching (objfile
, name
);
2562 dw2_print_stats (struct objfile
*objfile
)
2566 dw2_setup (objfile
);
2568 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2569 + dwarf2_per_objfile
->n_type_units
); ++i
)
2571 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2573 if (!per_cu
->v
.quick
->symtab
)
2576 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2580 dw2_dump (struct objfile
*objfile
)
2582 /* Nothing worth printing. */
2586 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2587 struct section_offsets
*delta
)
2589 /* There's nothing to relocate here. */
2593 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2594 const char *func_name
)
2596 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2600 dw2_expand_all_symtabs (struct objfile
*objfile
)
2604 dw2_setup (objfile
);
2606 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2607 + dwarf2_per_objfile
->n_type_units
); ++i
)
2609 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2611 dw2_instantiate_symtab (per_cu
);
2616 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2617 const char *filename
)
2621 dw2_setup (objfile
);
2623 /* We don't need to consider type units here.
2624 This is only called for examining code, e.g. expand_line_sal.
2625 There can be an order of magnitude (or more) more type units
2626 than comp units, and we avoid them if we can. */
2628 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2631 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2632 struct quick_file_names
*file_data
;
2634 /* We only need to look at symtabs not already expanded. */
2635 if (per_cu
->v
.quick
->symtab
)
2638 file_data
= dw2_get_file_names (objfile
, per_cu
);
2639 if (file_data
== NULL
)
2642 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2644 const char *this_name
= file_data
->file_names
[j
];
2645 if (FILENAME_CMP (this_name
, filename
) == 0)
2647 dw2_instantiate_symtab (per_cu
);
2655 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2657 struct dwarf2_per_cu_data
*per_cu
;
2659 struct quick_file_names
*file_data
;
2661 dw2_setup (objfile
);
2663 /* index_table is NULL if OBJF_READNOW. */
2664 if (!dwarf2_per_objfile
->index_table
)
2668 ALL_OBJFILE_SYMTABS (objfile
, s
)
2671 struct blockvector
*bv
= BLOCKVECTOR (s
);
2672 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2673 struct symbol
*sym
= lookup_block_symbol (block
, name
, VAR_DOMAIN
);
2676 return sym
->symtab
->filename
;
2681 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2685 /* Note that this just looks at the very first one named NAME -- but
2686 actually we are looking for a function. find_main_filename
2687 should be rewritten so that it doesn't require a custom hook. It
2688 could just use the ordinary symbol tables. */
2689 /* vec[0] is the length, which must always be >0. */
2690 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[1]));
2692 file_data
= dw2_get_file_names (objfile
, per_cu
);
2693 if (file_data
== NULL
)
2696 return file_data
->file_names
[file_data
->num_file_names
- 1];
2700 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
2701 struct objfile
*objfile
, int global
,
2702 int (*callback
) (struct block
*,
2703 struct symbol
*, void *),
2704 void *data
, symbol_compare_ftype
*match
,
2705 symbol_compare_ftype
*ordered_compare
)
2707 /* Currently unimplemented; used for Ada. The function can be called if the
2708 current language is Ada for a non-Ada objfile using GNU index. As Ada
2709 does not look for non-Ada symbols this function should just return. */
2713 dw2_expand_symtabs_matching
2714 (struct objfile
*objfile
,
2715 int (*file_matcher
) (const char *, void *),
2716 int (*name_matcher
) (const char *, void *),
2717 enum search_domain kind
,
2722 struct mapped_index
*index
;
2724 dw2_setup (objfile
);
2726 /* index_table is NULL if OBJF_READNOW. */
2727 if (!dwarf2_per_objfile
->index_table
)
2729 index
= dwarf2_per_objfile
->index_table
;
2731 if (file_matcher
!= NULL
)
2733 struct cleanup
*cleanup
;
2734 htab_t visited_found
, visited_not_found
;
2736 visited_found
= htab_create_alloc (10,
2737 htab_hash_pointer
, htab_eq_pointer
,
2738 NULL
, xcalloc
, xfree
);
2739 cleanup
= make_cleanup_htab_delete (visited_found
);
2740 visited_not_found
= htab_create_alloc (10,
2741 htab_hash_pointer
, htab_eq_pointer
,
2742 NULL
, xcalloc
, xfree
);
2743 make_cleanup_htab_delete (visited_not_found
);
2745 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2746 + dwarf2_per_objfile
->n_type_units
); ++i
)
2749 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2750 struct quick_file_names
*file_data
;
2753 per_cu
->v
.quick
->mark
= 0;
2755 /* We only need to look at symtabs not already expanded. */
2756 if (per_cu
->v
.quick
->symtab
)
2759 file_data
= dw2_get_file_names (objfile
, per_cu
);
2760 if (file_data
== NULL
)
2763 if (htab_find (visited_not_found
, file_data
) != NULL
)
2765 else if (htab_find (visited_found
, file_data
) != NULL
)
2767 per_cu
->v
.quick
->mark
= 1;
2771 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2773 if (file_matcher (file_data
->file_names
[j
], data
))
2775 per_cu
->v
.quick
->mark
= 1;
2780 slot
= htab_find_slot (per_cu
->v
.quick
->mark
2782 : visited_not_found
,
2787 do_cleanups (cleanup
);
2790 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2792 offset_type idx
= 2 * iter
;
2794 offset_type
*vec
, vec_len
, vec_idx
;
2796 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2799 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
2801 if (! (*name_matcher
) (name
, data
))
2804 /* The name was matched, now expand corresponding CUs that were
2806 vec
= (offset_type
*) (index
->constant_pool
2807 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
2808 vec_len
= MAYBE_SWAP (vec
[0]);
2809 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2811 struct dwarf2_per_cu_data
*per_cu
;
2813 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[vec_idx
+ 1]));
2814 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
2815 dw2_instantiate_symtab (per_cu
);
2820 static struct symtab
*
2821 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
2822 struct minimal_symbol
*msymbol
,
2824 struct obj_section
*section
,
2827 struct dwarf2_per_cu_data
*data
;
2829 dw2_setup (objfile
);
2831 if (!objfile
->psymtabs_addrmap
)
2834 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
2838 if (warn_if_readin
&& data
->v
.quick
->symtab
)
2839 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2840 paddress (get_objfile_arch (objfile
), pc
));
2842 return dw2_instantiate_symtab (data
);
2846 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
2847 void *data
, int need_fullname
)
2850 struct cleanup
*cleanup
;
2851 htab_t visited
= htab_create_alloc (10, htab_hash_pointer
, htab_eq_pointer
,
2852 NULL
, xcalloc
, xfree
);
2854 cleanup
= make_cleanup_htab_delete (visited
);
2855 dw2_setup (objfile
);
2857 /* We can ignore file names coming from already-expanded CUs. */
2858 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2859 + dwarf2_per_objfile
->n_type_units
); ++i
)
2861 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2863 if (per_cu
->v
.quick
->symtab
)
2865 void **slot
= htab_find_slot (visited
, per_cu
->v
.quick
->file_names
,
2868 *slot
= per_cu
->v
.quick
->file_names
;
2872 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2873 + dwarf2_per_objfile
->n_type_units
); ++i
)
2876 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2877 struct quick_file_names
*file_data
;
2880 /* We only need to look at symtabs not already expanded. */
2881 if (per_cu
->v
.quick
->symtab
)
2884 file_data
= dw2_get_file_names (objfile
, per_cu
);
2885 if (file_data
== NULL
)
2888 slot
= htab_find_slot (visited
, file_data
, INSERT
);
2891 /* Already visited. */
2896 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2898 const char *this_real_name
;
2901 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
2903 this_real_name
= NULL
;
2904 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
2908 do_cleanups (cleanup
);
2912 dw2_has_symbols (struct objfile
*objfile
)
2917 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
2920 dw2_find_last_source_symtab
,
2921 dw2_forget_cached_source_info
,
2922 dw2_map_symtabs_matching_filename
,
2924 dw2_pre_expand_symtabs_matching
,
2928 dw2_expand_symtabs_for_function
,
2929 dw2_expand_all_symtabs
,
2930 dw2_expand_symtabs_with_filename
,
2931 dw2_find_symbol_file
,
2932 dw2_map_matching_symbols
,
2933 dw2_expand_symtabs_matching
,
2934 dw2_find_pc_sect_symtab
,
2935 dw2_map_symbol_filenames
2938 /* Initialize for reading DWARF for this objfile. Return 0 if this
2939 file will use psymtabs, or 1 if using the GNU index. */
2942 dwarf2_initialize_objfile (struct objfile
*objfile
)
2944 /* If we're about to read full symbols, don't bother with the
2945 indices. In this case we also don't care if some other debug
2946 format is making psymtabs, because they are all about to be
2948 if ((objfile
->flags
& OBJF_READNOW
))
2952 dwarf2_per_objfile
->using_index
= 1;
2953 create_all_comp_units (objfile
);
2954 create_debug_types_hash_table (objfile
);
2955 dwarf2_per_objfile
->quick_file_names_table
=
2956 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2958 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2959 + dwarf2_per_objfile
->n_type_units
); ++i
)
2961 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2963 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2964 struct dwarf2_per_cu_quick_data
);
2967 /* Return 1 so that gdb sees the "quick" functions. However,
2968 these functions will be no-ops because we will have expanded
2973 if (dwarf2_read_index (objfile
))
2981 /* Build a partial symbol table. */
2984 dwarf2_build_psymtabs (struct objfile
*objfile
)
2986 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2988 init_psymbol_list (objfile
, 1024);
2991 dwarf2_build_psymtabs_hard (objfile
);
2994 /* Return TRUE if OFFSET is within CU_HEADER. */
2997 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
2999 unsigned int bottom
= cu_header
->offset
;
3000 unsigned int top
= (cu_header
->offset
3002 + cu_header
->initial_length_size
);
3004 return (offset
>= bottom
&& offset
< top
);
3007 /* Read in the comp unit header information from the debug_info at info_ptr.
3008 NOTE: This leaves members offset, first_die_offset to be filled in
3012 read_comp_unit_head (struct comp_unit_head
*cu_header
,
3013 gdb_byte
*info_ptr
, bfd
*abfd
)
3016 unsigned int bytes_read
;
3018 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
3019 cu_header
->initial_length_size
= bytes_read
;
3020 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
3021 info_ptr
+= bytes_read
;
3022 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
3024 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
3026 info_ptr
+= bytes_read
;
3027 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
3029 signed_addr
= bfd_get_sign_extend_vma (abfd
);
3030 if (signed_addr
< 0)
3031 internal_error (__FILE__
, __LINE__
,
3032 _("read_comp_unit_head: dwarf from non elf file"));
3033 cu_header
->signed_addr_p
= signed_addr
;
3038 /* Subroutine of read_and_check_comp_unit_head and
3039 read_and_check_type_unit_head to simplify them.
3040 Perform various error checking on the header. */
3043 error_check_comp_unit_head (struct comp_unit_head
*header
,
3044 struct dwarf2_section_info
*section
)
3046 bfd
*abfd
= section
->asection
->owner
;
3047 const char *filename
= bfd_get_filename (abfd
);
3049 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
3050 error (_("Dwarf Error: wrong version in compilation unit header "
3051 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
3054 if (header
->abbrev_offset
3055 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
3056 &dwarf2_per_objfile
->abbrev
))
3057 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3058 "(offset 0x%lx + 6) [in module %s]"),
3059 (long) header
->abbrev_offset
, (long) header
->offset
,
3062 /* Cast to unsigned long to use 64-bit arithmetic when possible to
3063 avoid potential 32-bit overflow. */
3064 if (((unsigned long) header
->offset
3065 + header
->length
+ header
->initial_length_size
)
3067 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3068 "(offset 0x%lx + 0) [in module %s]"),
3069 (long) header
->length
, (long) header
->offset
,
3073 /* Read in a CU/TU header and perform some basic error checking.
3074 The contents of the header are stored in HEADER.
3075 The result is a pointer to the start of the first DIE. */
3078 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
3079 struct dwarf2_section_info
*section
,
3081 int is_debug_types_section
)
3083 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3084 bfd
*abfd
= section
->asection
->owner
;
3086 header
->offset
= beg_of_comp_unit
- section
->buffer
;
3088 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3090 /* If we're reading a type unit, skip over the signature and
3091 type_offset fields. */
3092 if (is_debug_types_section
)
3093 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
3095 header
->first_die_offset
= info_ptr
- beg_of_comp_unit
;
3097 error_check_comp_unit_head (header
, section
);
3102 /* Read in the types comp unit header information from .debug_types entry at
3103 types_ptr. The result is a pointer to one past the end of the header. */
3106 read_and_check_type_unit_head (struct comp_unit_head
*header
,
3107 struct dwarf2_section_info
*section
,
3109 ULONGEST
*signature
, unsigned int *type_offset
)
3111 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3112 bfd
*abfd
= section
->asection
->owner
;
3114 header
->offset
= beg_of_comp_unit
- section
->buffer
;
3116 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3118 /* If we're reading a type unit, skip over the signature and
3119 type_offset fields. */
3120 if (signature
!= NULL
)
3121 *signature
= read_8_bytes (abfd
, info_ptr
);
3123 if (type_offset
!= NULL
)
3124 *type_offset
= read_offset_1 (abfd
, info_ptr
, header
->offset_size
);
3125 info_ptr
+= header
->offset_size
;
3127 header
->first_die_offset
= info_ptr
- beg_of_comp_unit
;
3129 error_check_comp_unit_head (header
, section
);
3134 /* Allocate a new partial symtab for file named NAME and mark this new
3135 partial symtab as being an include of PST. */
3138 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
3139 struct objfile
*objfile
)
3141 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
3143 subpst
->section_offsets
= pst
->section_offsets
;
3144 subpst
->textlow
= 0;
3145 subpst
->texthigh
= 0;
3147 subpst
->dependencies
= (struct partial_symtab
**)
3148 obstack_alloc (&objfile
->objfile_obstack
,
3149 sizeof (struct partial_symtab
*));
3150 subpst
->dependencies
[0] = pst
;
3151 subpst
->number_of_dependencies
= 1;
3153 subpst
->globals_offset
= 0;
3154 subpst
->n_global_syms
= 0;
3155 subpst
->statics_offset
= 0;
3156 subpst
->n_static_syms
= 0;
3157 subpst
->symtab
= NULL
;
3158 subpst
->read_symtab
= pst
->read_symtab
;
3161 /* No private part is necessary for include psymtabs. This property
3162 can be used to differentiate between such include psymtabs and
3163 the regular ones. */
3164 subpst
->read_symtab_private
= NULL
;
3167 /* Read the Line Number Program data and extract the list of files
3168 included by the source file represented by PST. Build an include
3169 partial symtab for each of these included files. */
3172 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
3173 struct die_info
*die
,
3174 struct partial_symtab
*pst
)
3176 struct objfile
*objfile
= cu
->objfile
;
3177 bfd
*abfd
= objfile
->obfd
;
3178 struct line_header
*lh
= NULL
;
3179 struct attribute
*attr
;
3181 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3184 unsigned int line_offset
= DW_UNSND (attr
);
3186 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
3189 return; /* No linetable, so no includes. */
3191 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3192 dwarf_decode_lines (lh
, pst
->dirname
, cu
, pst
, 1);
3194 free_line_header (lh
);
3198 hash_type_signature (const void *item
)
3200 const struct signatured_type
*type_sig
= item
;
3202 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3203 return type_sig
->signature
;
3207 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
3209 const struct signatured_type
*lhs
= item_lhs
;
3210 const struct signatured_type
*rhs
= item_rhs
;
3212 return lhs
->signature
== rhs
->signature
;
3215 /* Allocate a hash table for signatured types. */
3218 allocate_signatured_type_table (struct objfile
*objfile
)
3220 return htab_create_alloc_ex (41,
3221 hash_type_signature
,
3224 &objfile
->objfile_obstack
,
3225 hashtab_obstack_allocate
,
3226 dummy_obstack_deallocate
);
3229 /* A helper function to add a signatured type CU to a table. */
3232 add_signatured_type_cu_to_table (void **slot
, void *datum
)
3234 struct signatured_type
*sigt
= *slot
;
3235 struct dwarf2_per_cu_data
***datap
= datum
;
3237 **datap
= &sigt
->per_cu
;
3243 /* Create the hash table of all entries in the .debug_types section(s).
3244 The result is zero if there is an error (e.g. missing .debug_types section),
3245 otherwise non-zero. */
3248 create_debug_types_hash_table (struct objfile
*objfile
)
3250 htab_t types_htab
= NULL
;
3251 struct dwarf2_per_cu_data
**iter
;
3253 struct dwarf2_section_info
*section
;
3255 if (VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
))
3257 dwarf2_per_objfile
->signatured_types
= NULL
;
3262 VEC_iterate (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
3266 gdb_byte
*info_ptr
, *end_ptr
;
3268 dwarf2_read_section (objfile
, section
);
3269 info_ptr
= section
->buffer
;
3271 if (info_ptr
== NULL
)
3274 if (types_htab
== NULL
)
3275 types_htab
= allocate_signatured_type_table (objfile
);
3277 if (dwarf2_die_debug
)
3278 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
3280 end_ptr
= info_ptr
+ section
->size
;
3281 while (info_ptr
< end_ptr
)
3283 unsigned int offset
;
3284 unsigned int type_offset
;
3286 struct signatured_type
*type_sig
;
3288 gdb_byte
*ptr
= info_ptr
;
3289 struct comp_unit_head header
;
3291 offset
= ptr
- section
->buffer
;
3293 /* We need to read the type's signature in order to build the hash
3294 table, but we don't need anything else just yet. */
3296 ptr
= read_and_check_type_unit_head (&header
, section
, ptr
,
3297 &signature
, &type_offset
);
3299 /* Skip dummy type units. */
3300 if (ptr
>= end_ptr
|| peek_abbrev_code (objfile
->obfd
, ptr
) == 0)
3302 info_ptr
= info_ptr
+ header
.initial_length_size
+ header
.length
;
3306 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
3307 memset (type_sig
, 0, sizeof (*type_sig
));
3308 type_sig
->signature
= signature
;
3309 type_sig
->type_offset
= type_offset
;
3310 type_sig
->per_cu
.objfile
= objfile
;
3311 type_sig
->per_cu
.debug_types_section
= section
;
3312 type_sig
->per_cu
.offset
= offset
;
3314 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
3315 gdb_assert (slot
!= NULL
);
3318 const struct signatured_type
*dup_sig
= *slot
;
3320 complaint (&symfile_complaints
,
3321 _("debug type entry at offset 0x%x is duplicate to the "
3322 "entry at offset 0x%x, signature 0x%s"),
3323 offset
, dup_sig
->per_cu
.offset
,
3324 phex (signature
, sizeof (signature
)));
3325 gdb_assert (signature
== dup_sig
->signature
);
3329 if (dwarf2_die_debug
)
3330 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3331 offset
, phex (signature
, sizeof (signature
)));
3333 info_ptr
= info_ptr
+ header
.initial_length_size
+ header
.length
;
3337 dwarf2_per_objfile
->signatured_types
= types_htab
;
3339 dwarf2_per_objfile
->n_type_units
= htab_elements (types_htab
);
3340 dwarf2_per_objfile
->all_type_units
3341 = obstack_alloc (&objfile
->objfile_obstack
,
3342 dwarf2_per_objfile
->n_type_units
3343 * sizeof (struct dwarf2_per_cu_data
*));
3344 iter
= &dwarf2_per_objfile
->all_type_units
[0];
3345 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
3346 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
3347 == dwarf2_per_objfile
->n_type_units
);
3352 /* Lookup a signature based type.
3353 Returns NULL if SIG is not present in the table. */
3355 static struct signatured_type
*
3356 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
3358 struct signatured_type find_entry
, *entry
;
3360 if (dwarf2_per_objfile
->signatured_types
== NULL
)
3362 complaint (&symfile_complaints
,
3363 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3367 find_entry
.signature
= sig
;
3368 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
3372 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3375 init_cu_die_reader (struct die_reader_specs
*reader
,
3376 struct dwarf2_cu
*cu
)
3378 reader
->abfd
= cu
->objfile
->obfd
;
3380 if (cu
->per_cu
->debug_types_section
)
3382 gdb_assert (cu
->per_cu
->debug_types_section
->readin
);
3383 reader
->buffer
= cu
->per_cu
->debug_types_section
->buffer
;
3387 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3388 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
3392 /* Find the base address of the compilation unit for range lists and
3393 location lists. It will normally be specified by DW_AT_low_pc.
3394 In DWARF-3 draft 4, the base address could be overridden by
3395 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3396 compilation units with discontinuous ranges. */
3399 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3401 struct attribute
*attr
;
3404 cu
->base_address
= 0;
3406 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3409 cu
->base_address
= DW_ADDR (attr
);
3414 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3417 cu
->base_address
= DW_ADDR (attr
);
3423 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
3424 to combine the common parts.
3425 Process compilation unit THIS_CU for a psymtab.
3426 SECTION is the section the CU/TU comes from,
3427 either .debug_info or .debug_types. */
3430 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
3431 struct dwarf2_section_info
*section
,
3432 int is_debug_types_section
)
3434 struct objfile
*objfile
= this_cu
->objfile
;
3435 bfd
*abfd
= objfile
->obfd
;
3436 gdb_byte
*buffer
= section
->buffer
;
3437 gdb_byte
*info_ptr
= buffer
+ this_cu
->offset
;
3438 unsigned int buffer_size
= section
->size
;
3439 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3440 struct die_info
*comp_unit_die
;
3441 struct partial_symtab
*pst
;
3443 struct cleanup
*back_to_inner
;
3444 struct dwarf2_cu cu
;
3445 int has_children
, has_pc_info
;
3446 struct attribute
*attr
;
3447 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
3448 struct die_reader_specs reader_specs
;
3449 const char *filename
;
3451 /* If this compilation unit was already read in, free the
3452 cached copy in order to read it in again. This is
3453 necessary because we skipped some symbols when we first
3454 read in the compilation unit (see load_partial_dies).
3455 This problem could be avoided, but the benefit is
3457 if (this_cu
->cu
!= NULL
)
3458 free_one_cached_comp_unit (this_cu
->cu
);
3460 /* Note that this is a pointer to our stack frame, being
3461 added to a global data structure. It will be cleaned up
3462 in free_stack_comp_unit when we finish with this
3463 compilation unit. */
3464 init_one_comp_unit (&cu
, this_cu
);
3465 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
3467 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
, info_ptr
,
3468 is_debug_types_section
);
3470 /* Skip dummy compilation units. */
3471 if (info_ptr
>= buffer
+ buffer_size
3472 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3474 do_cleanups (back_to_inner
);
3478 cu
.list_in_scope
= &file_symbols
;
3480 /* Read the abbrevs for this compilation unit into a table. */
3481 dwarf2_read_abbrevs (&cu
);
3482 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
3484 /* Read the compilation unit die. */
3485 init_cu_die_reader (&reader_specs
, &cu
);
3486 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3489 if (is_debug_types_section
)
3491 /* LENGTH has not been set yet for type units. */
3492 gdb_assert (this_cu
->offset
== cu
.header
.offset
);
3493 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
3495 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3497 do_cleanups (back_to_inner
);
3501 prepare_one_comp_unit (&cu
, comp_unit_die
);
3503 /* Allocate a new partial symbol table structure. */
3504 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
3505 if (attr
== NULL
|| !DW_STRING (attr
))
3508 filename
= DW_STRING (attr
);
3509 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
3511 /* TEXTLOW and TEXTHIGH are set below. */
3513 objfile
->global_psymbols
.next
,
3514 objfile
->static_psymbols
.next
);
3515 pst
->psymtabs_addrmap_supported
= 1;
3517 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
3519 pst
->dirname
= DW_STRING (attr
);
3521 pst
->read_symtab_private
= this_cu
;
3523 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3525 /* Store the function that reads in the rest of the symbol table. */
3526 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
3528 this_cu
->v
.psymtab
= pst
;
3530 dwarf2_find_base_address (comp_unit_die
, &cu
);
3532 /* Possibly set the default values of LOWPC and HIGHPC from
3534 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
3535 &best_highpc
, &cu
, pst
);
3536 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
3537 /* Store the contiguous range if it is not empty; it can be empty for
3538 CUs with no code. */
3539 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3540 best_lowpc
+ baseaddr
,
3541 best_highpc
+ baseaddr
- 1, pst
);
3543 /* Check if comp unit has_children.
3544 If so, read the rest of the partial symbols from this comp unit.
3545 If not, there's no more debug_info for this comp unit. */
3548 struct partial_die_info
*first_die
;
3549 CORE_ADDR lowpc
, highpc
;
3551 lowpc
= ((CORE_ADDR
) -1);
3552 highpc
= ((CORE_ADDR
) 0);
3554 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
3556 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
3557 ! has_pc_info
, &cu
);
3559 /* If we didn't find a lowpc, set it to highpc to avoid
3560 complaints from `maint check'. */
3561 if (lowpc
== ((CORE_ADDR
) -1))
3564 /* If the compilation unit didn't have an explicit address range,
3565 then use the information extracted from its child dies. */
3569 best_highpc
= highpc
;
3572 pst
->textlow
= best_lowpc
+ baseaddr
;
3573 pst
->texthigh
= best_highpc
+ baseaddr
;
3575 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
3576 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
3577 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
3578 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
3579 sort_pst_symbols (pst
);
3581 if (is_debug_types_section
)
3583 /* It's not clear we want to do anything with stmt lists here.
3584 Waiting to see what gcc ultimately does. */
3588 /* Get the list of files included in the current compilation unit,
3589 and build a psymtab for each of them. */
3590 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
3593 do_cleanups (back_to_inner
);
3596 /* Traversal function for htab_traverse_noresize.
3597 Process one .debug_types comp-unit. */
3600 process_type_comp_unit (void **slot
, void *info
)
3602 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
3603 struct dwarf2_per_cu_data
*this_cu
;
3605 gdb_assert (info
== NULL
);
3606 this_cu
= &entry
->per_cu
;
3608 gdb_assert (this_cu
->debug_types_section
->readin
);
3609 process_psymtab_comp_unit (this_cu
, this_cu
->debug_types_section
, 1);
3614 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3615 Build partial symbol tables for the .debug_types comp-units. */
3618 build_type_psymtabs (struct objfile
*objfile
)
3620 if (! create_debug_types_hash_table (objfile
))
3623 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
3624 process_type_comp_unit
, NULL
);
3627 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3630 psymtabs_addrmap_cleanup (void *o
)
3632 struct objfile
*objfile
= o
;
3634 objfile
->psymtabs_addrmap
= NULL
;
3637 /* Build the partial symbol table by doing a quick pass through the
3638 .debug_info and .debug_abbrev sections. */
3641 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
3643 struct cleanup
*back_to
, *addrmap_cleanup
;
3644 struct obstack temp_obstack
;
3647 dwarf2_per_objfile
->reading_partial_symbols
= 1;
3649 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3651 /* Any cached compilation units will be linked by the per-objfile
3652 read_in_chain. Make sure to free them when we're done. */
3653 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
3655 build_type_psymtabs (objfile
);
3657 create_all_comp_units (objfile
);
3659 /* Create a temporary address map on a temporary obstack. We later
3660 copy this to the final obstack. */
3661 obstack_init (&temp_obstack
);
3662 make_cleanup_obstack_free (&temp_obstack
);
3663 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
3664 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
3666 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3668 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3670 process_psymtab_comp_unit (per_cu
, &dwarf2_per_objfile
->info
, 0);
3673 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
3674 &objfile
->objfile_obstack
);
3675 discard_cleanups (addrmap_cleanup
);
3677 do_cleanups (back_to
);
3680 /* Load the partial DIEs for a secondary CU into memory. */
3683 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
3685 struct objfile
*objfile
= this_cu
->objfile
;
3686 bfd
*abfd
= objfile
->obfd
;
3688 struct die_info
*comp_unit_die
;
3689 struct dwarf2_cu
*cu
;
3690 struct cleanup
*free_abbrevs_cleanup
, *free_cu_cleanup
= NULL
;
3692 struct die_reader_specs reader_specs
;
3694 struct dwarf2_section_info
*section
= &dwarf2_per_objfile
->info
;
3696 gdb_assert (! this_cu
->debug_types_section
);
3698 gdb_assert (section
->readin
);
3699 info_ptr
= section
->buffer
+ this_cu
->offset
;
3701 if (this_cu
->cu
== NULL
)
3703 cu
= xmalloc (sizeof (*cu
));
3704 init_one_comp_unit (cu
, this_cu
);
3708 /* If an error occurs while loading, release our storage. */
3709 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
3711 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
, info_ptr
,
3714 /* Skip dummy compilation units. */
3715 if (info_ptr
>= (section
->buffer
+ section
->size
)
3716 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3718 do_cleanups (free_cu_cleanup
);
3725 info_ptr
+= cu
->header
.first_die_offset
;
3728 /* Read the abbrevs for this compilation unit into a table. */
3729 gdb_assert (cu
->dwarf2_abbrevs
== NULL
);
3730 dwarf2_read_abbrevs (cu
);
3731 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3733 /* Read the compilation unit die. */
3734 init_cu_die_reader (&reader_specs
, cu
);
3735 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3738 prepare_one_comp_unit (cu
, comp_unit_die
);
3740 /* Check if comp unit has_children.
3741 If so, read the rest of the partial symbols from this comp unit.
3742 If not, there's no more debug_info for this comp unit. */
3744 load_partial_dies (abfd
, section
->buffer
, info_ptr
, 0, cu
);
3746 do_cleanups (free_abbrevs_cleanup
);
3750 /* We've successfully allocated this compilation unit. Let our
3751 caller clean it up when finished with it. */
3752 discard_cleanups (free_cu_cleanup
);
3754 /* Link this CU into read_in_chain. */
3755 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3756 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3760 /* Create a list of all compilation units in OBJFILE.
3761 This is only done for -readnow and building partial symtabs. */
3764 create_all_comp_units (struct objfile
*objfile
)
3768 struct dwarf2_per_cu_data
**all_comp_units
;
3771 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3772 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3776 all_comp_units
= xmalloc (n_allocated
3777 * sizeof (struct dwarf2_per_cu_data
*));
3779 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
3780 + dwarf2_per_objfile
->info
.size
)
3782 unsigned int length
, initial_length_size
;
3783 struct dwarf2_per_cu_data
*this_cu
;
3784 unsigned int offset
;
3786 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
3788 /* Read just enough information to find out where the next
3789 compilation unit is. */
3790 length
= read_initial_length (objfile
->obfd
, info_ptr
,
3791 &initial_length_size
);
3793 /* Save the compilation unit for later lookup. */
3794 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
3795 sizeof (struct dwarf2_per_cu_data
));
3796 memset (this_cu
, 0, sizeof (*this_cu
));
3797 this_cu
->offset
= offset
;
3798 this_cu
->length
= length
+ initial_length_size
;
3799 this_cu
->objfile
= objfile
;
3801 if (n_comp_units
== n_allocated
)
3804 all_comp_units
= xrealloc (all_comp_units
,
3806 * sizeof (struct dwarf2_per_cu_data
*));
3808 all_comp_units
[n_comp_units
++] = this_cu
;
3810 info_ptr
= info_ptr
+ this_cu
->length
;
3813 dwarf2_per_objfile
->all_comp_units
3814 = obstack_alloc (&objfile
->objfile_obstack
,
3815 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3816 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
3817 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3818 xfree (all_comp_units
);
3819 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
3822 /* Process all loaded DIEs for compilation unit CU, starting at
3823 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3824 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3825 DW_AT_ranges). If NEED_PC is set, then this function will set
3826 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3827 and record the covered ranges in the addrmap. */
3830 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
3831 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3833 struct partial_die_info
*pdi
;
3835 /* Now, march along the PDI's, descending into ones which have
3836 interesting children but skipping the children of the other ones,
3837 until we reach the end of the compilation unit. */
3843 fixup_partial_die (pdi
, cu
);
3845 /* Anonymous namespaces or modules have no name but have interesting
3846 children, so we need to look at them. Ditto for anonymous
3849 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
3850 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
3854 case DW_TAG_subprogram
:
3855 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3857 case DW_TAG_constant
:
3858 case DW_TAG_variable
:
3859 case DW_TAG_typedef
:
3860 case DW_TAG_union_type
:
3861 if (!pdi
->is_declaration
)
3863 add_partial_symbol (pdi
, cu
);
3866 case DW_TAG_class_type
:
3867 case DW_TAG_interface_type
:
3868 case DW_TAG_structure_type
:
3869 if (!pdi
->is_declaration
)
3871 add_partial_symbol (pdi
, cu
);
3874 case DW_TAG_enumeration_type
:
3875 if (!pdi
->is_declaration
)
3876 add_partial_enumeration (pdi
, cu
);
3878 case DW_TAG_base_type
:
3879 case DW_TAG_subrange_type
:
3880 /* File scope base type definitions are added to the partial
3882 add_partial_symbol (pdi
, cu
);
3884 case DW_TAG_namespace
:
3885 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
3888 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
3895 /* If the die has a sibling, skip to the sibling. */
3897 pdi
= pdi
->die_sibling
;
3901 /* Functions used to compute the fully scoped name of a partial DIE.
3903 Normally, this is simple. For C++, the parent DIE's fully scoped
3904 name is concatenated with "::" and the partial DIE's name. For
3905 Java, the same thing occurs except that "." is used instead of "::".
3906 Enumerators are an exception; they use the scope of their parent
3907 enumeration type, i.e. the name of the enumeration type is not
3908 prepended to the enumerator.
3910 There are two complexities. One is DW_AT_specification; in this
3911 case "parent" means the parent of the target of the specification,
3912 instead of the direct parent of the DIE. The other is compilers
3913 which do not emit DW_TAG_namespace; in this case we try to guess
3914 the fully qualified name of structure types from their members'
3915 linkage names. This must be done using the DIE's children rather
3916 than the children of any DW_AT_specification target. We only need
3917 to do this for structures at the top level, i.e. if the target of
3918 any DW_AT_specification (if any; otherwise the DIE itself) does not
3921 /* Compute the scope prefix associated with PDI's parent, in
3922 compilation unit CU. The result will be allocated on CU's
3923 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3924 field. NULL is returned if no prefix is necessary. */
3926 partial_die_parent_scope (struct partial_die_info
*pdi
,
3927 struct dwarf2_cu
*cu
)
3929 char *grandparent_scope
;
3930 struct partial_die_info
*parent
, *real_pdi
;
3932 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3933 then this means the parent of the specification DIE. */
3936 while (real_pdi
->has_specification
)
3937 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3939 parent
= real_pdi
->die_parent
;
3943 if (parent
->scope_set
)
3944 return parent
->scope
;
3946 fixup_partial_die (parent
, cu
);
3948 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
3950 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3951 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3952 Work around this problem here. */
3953 if (cu
->language
== language_cplus
3954 && parent
->tag
== DW_TAG_namespace
3955 && strcmp (parent
->name
, "::") == 0
3956 && grandparent_scope
== NULL
)
3958 parent
->scope
= NULL
;
3959 parent
->scope_set
= 1;
3963 if (pdi
->tag
== DW_TAG_enumerator
)
3964 /* Enumerators should not get the name of the enumeration as a prefix. */
3965 parent
->scope
= grandparent_scope
;
3966 else if (parent
->tag
== DW_TAG_namespace
3967 || parent
->tag
== DW_TAG_module
3968 || parent
->tag
== DW_TAG_structure_type
3969 || parent
->tag
== DW_TAG_class_type
3970 || parent
->tag
== DW_TAG_interface_type
3971 || parent
->tag
== DW_TAG_union_type
3972 || parent
->tag
== DW_TAG_enumeration_type
)
3974 if (grandparent_scope
== NULL
)
3975 parent
->scope
= parent
->name
;
3977 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
3979 parent
->name
, 0, cu
);
3983 /* FIXME drow/2004-04-01: What should we be doing with
3984 function-local names? For partial symbols, we should probably be
3986 complaint (&symfile_complaints
,
3987 _("unhandled containing DIE tag %d for DIE at %d"),
3988 parent
->tag
, pdi
->offset
);
3989 parent
->scope
= grandparent_scope
;
3992 parent
->scope_set
= 1;
3993 return parent
->scope
;
3996 /* Return the fully scoped name associated with PDI, from compilation unit
3997 CU. The result will be allocated with malloc. */
3999 partial_die_full_name (struct partial_die_info
*pdi
,
4000 struct dwarf2_cu
*cu
)
4004 /* If this is a template instantiation, we can not work out the
4005 template arguments from partial DIEs. So, unfortunately, we have
4006 to go through the full DIEs. At least any work we do building
4007 types here will be reused if full symbols are loaded later. */
4008 if (pdi
->has_template_arguments
)
4010 fixup_partial_die (pdi
, cu
);
4012 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
4014 struct die_info
*die
;
4015 struct attribute attr
;
4016 struct dwarf2_cu
*ref_cu
= cu
;
4019 attr
.form
= DW_FORM_ref_addr
;
4020 attr
.u
.addr
= pdi
->offset
;
4021 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
4023 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
4027 parent_scope
= partial_die_parent_scope (pdi
, cu
);
4028 if (parent_scope
== NULL
)
4031 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
4035 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
4037 struct objfile
*objfile
= cu
->objfile
;
4039 char *actual_name
= NULL
;
4041 int built_actual_name
= 0;
4043 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4045 actual_name
= partial_die_full_name (pdi
, cu
);
4047 built_actual_name
= 1;
4049 if (actual_name
== NULL
)
4050 actual_name
= pdi
->name
;
4054 case DW_TAG_subprogram
:
4055 if (pdi
->is_external
|| cu
->language
== language_ada
)
4057 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
4058 of the global scope. But in Ada, we want to be able to access
4059 nested procedures globally. So all Ada subprograms are stored
4060 in the global scope. */
4061 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4062 mst_text, objfile); */
4063 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4065 VAR_DOMAIN
, LOC_BLOCK
,
4066 &objfile
->global_psymbols
,
4067 0, pdi
->lowpc
+ baseaddr
,
4068 cu
->language
, objfile
);
4072 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4073 mst_file_text, objfile); */
4074 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4076 VAR_DOMAIN
, LOC_BLOCK
,
4077 &objfile
->static_psymbols
,
4078 0, pdi
->lowpc
+ baseaddr
,
4079 cu
->language
, objfile
);
4082 case DW_TAG_constant
:
4084 struct psymbol_allocation_list
*list
;
4086 if (pdi
->is_external
)
4087 list
= &objfile
->global_psymbols
;
4089 list
= &objfile
->static_psymbols
;
4090 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4091 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
4092 list
, 0, 0, cu
->language
, objfile
);
4095 case DW_TAG_variable
:
4097 addr
= decode_locdesc (pdi
->locdesc
, cu
);
4101 && !dwarf2_per_objfile
->has_section_at_zero
)
4103 /* A global or static variable may also have been stripped
4104 out by the linker if unused, in which case its address
4105 will be nullified; do not add such variables into partial
4106 symbol table then. */
4108 else if (pdi
->is_external
)
4111 Don't enter into the minimal symbol tables as there is
4112 a minimal symbol table entry from the ELF symbols already.
4113 Enter into partial symbol table if it has a location
4114 descriptor or a type.
4115 If the location descriptor is missing, new_symbol will create
4116 a LOC_UNRESOLVED symbol, the address of the variable will then
4117 be determined from the minimal symbol table whenever the variable
4119 The address for the partial symbol table entry is not
4120 used by GDB, but it comes in handy for debugging partial symbol
4123 if (pdi
->locdesc
|| pdi
->has_type
)
4124 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4126 VAR_DOMAIN
, LOC_STATIC
,
4127 &objfile
->global_psymbols
,
4129 cu
->language
, objfile
);
4133 /* Static Variable. Skip symbols without location descriptors. */
4134 if (pdi
->locdesc
== NULL
)
4136 if (built_actual_name
)
4137 xfree (actual_name
);
4140 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
4141 mst_file_data, objfile); */
4142 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4144 VAR_DOMAIN
, LOC_STATIC
,
4145 &objfile
->static_psymbols
,
4147 cu
->language
, objfile
);
4150 case DW_TAG_typedef
:
4151 case DW_TAG_base_type
:
4152 case DW_TAG_subrange_type
:
4153 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4155 VAR_DOMAIN
, LOC_TYPEDEF
,
4156 &objfile
->static_psymbols
,
4157 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4159 case DW_TAG_namespace
:
4160 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4162 VAR_DOMAIN
, LOC_TYPEDEF
,
4163 &objfile
->global_psymbols
,
4164 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4166 case DW_TAG_class_type
:
4167 case DW_TAG_interface_type
:
4168 case DW_TAG_structure_type
:
4169 case DW_TAG_union_type
:
4170 case DW_TAG_enumeration_type
:
4171 /* Skip external references. The DWARF standard says in the section
4172 about "Structure, Union, and Class Type Entries": "An incomplete
4173 structure, union or class type is represented by a structure,
4174 union or class entry that does not have a byte size attribute
4175 and that has a DW_AT_declaration attribute." */
4176 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
4178 if (built_actual_name
)
4179 xfree (actual_name
);
4183 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
4184 static vs. global. */
4185 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4187 STRUCT_DOMAIN
, LOC_TYPEDEF
,
4188 (cu
->language
== language_cplus
4189 || cu
->language
== language_java
)
4190 ? &objfile
->global_psymbols
4191 : &objfile
->static_psymbols
,
4192 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4195 case DW_TAG_enumerator
:
4196 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4198 VAR_DOMAIN
, LOC_CONST
,
4199 (cu
->language
== language_cplus
4200 || cu
->language
== language_java
)
4201 ? &objfile
->global_psymbols
4202 : &objfile
->static_psymbols
,
4203 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4209 if (built_actual_name
)
4210 xfree (actual_name
);
4213 /* Read a partial die corresponding to a namespace; also, add a symbol
4214 corresponding to that namespace to the symbol table. NAMESPACE is
4215 the name of the enclosing namespace. */
4218 add_partial_namespace (struct partial_die_info
*pdi
,
4219 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4220 int need_pc
, struct dwarf2_cu
*cu
)
4222 /* Add a symbol for the namespace. */
4224 add_partial_symbol (pdi
, cu
);
4226 /* Now scan partial symbols in that namespace. */
4228 if (pdi
->has_children
)
4229 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4232 /* Read a partial die corresponding to a Fortran module. */
4235 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
4236 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4238 /* Now scan partial symbols in that module. */
4240 if (pdi
->has_children
)
4241 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4244 /* Read a partial die corresponding to a subprogram and create a partial
4245 symbol for that subprogram. When the CU language allows it, this
4246 routine also defines a partial symbol for each nested subprogram
4247 that this subprogram contains.
4249 DIE my also be a lexical block, in which case we simply search
4250 recursively for suprograms defined inside that lexical block.
4251 Again, this is only performed when the CU language allows this
4252 type of definitions. */
4255 add_partial_subprogram (struct partial_die_info
*pdi
,
4256 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4257 int need_pc
, struct dwarf2_cu
*cu
)
4259 if (pdi
->tag
== DW_TAG_subprogram
)
4261 if (pdi
->has_pc_info
)
4263 if (pdi
->lowpc
< *lowpc
)
4264 *lowpc
= pdi
->lowpc
;
4265 if (pdi
->highpc
> *highpc
)
4266 *highpc
= pdi
->highpc
;
4270 struct objfile
*objfile
= cu
->objfile
;
4272 baseaddr
= ANOFFSET (objfile
->section_offsets
,
4273 SECT_OFF_TEXT (objfile
));
4274 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4275 pdi
->lowpc
+ baseaddr
,
4276 pdi
->highpc
- 1 + baseaddr
,
4277 cu
->per_cu
->v
.psymtab
);
4281 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
4283 if (!pdi
->is_declaration
)
4284 /* Ignore subprogram DIEs that do not have a name, they are
4285 illegal. Do not emit a complaint at this point, we will
4286 do so when we convert this psymtab into a symtab. */
4288 add_partial_symbol (pdi
, cu
);
4292 if (! pdi
->has_children
)
4295 if (cu
->language
== language_ada
)
4297 pdi
= pdi
->die_child
;
4300 fixup_partial_die (pdi
, cu
);
4301 if (pdi
->tag
== DW_TAG_subprogram
4302 || pdi
->tag
== DW_TAG_lexical_block
)
4303 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4304 pdi
= pdi
->die_sibling
;
4309 /* Read a partial die corresponding to an enumeration type. */
4312 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
4313 struct dwarf2_cu
*cu
)
4315 struct partial_die_info
*pdi
;
4317 if (enum_pdi
->name
!= NULL
)
4318 add_partial_symbol (enum_pdi
, cu
);
4320 pdi
= enum_pdi
->die_child
;
4323 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
4324 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
4326 add_partial_symbol (pdi
, cu
);
4327 pdi
= pdi
->die_sibling
;
4331 /* Return the initial uleb128 in the die at INFO_PTR. */
4334 peek_abbrev_code (bfd
*abfd
, gdb_byte
*info_ptr
)
4336 unsigned int bytes_read
;
4338 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4341 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4342 Return the corresponding abbrev, or NULL if the number is zero (indicating
4343 an empty DIE). In either case *BYTES_READ will be set to the length of
4344 the initial number. */
4346 static struct abbrev_info
*
4347 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
4348 struct dwarf2_cu
*cu
)
4350 bfd
*abfd
= cu
->objfile
->obfd
;
4351 unsigned int abbrev_number
;
4352 struct abbrev_info
*abbrev
;
4354 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
4356 if (abbrev_number
== 0)
4359 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4362 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4363 abbrev_number
, bfd_get_filename (abfd
));
4369 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4370 Returns a pointer to the end of a series of DIEs, terminated by an empty
4371 DIE. Any children of the skipped DIEs will also be skipped. */
4374 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
4376 struct abbrev_info
*abbrev
;
4377 unsigned int bytes_read
;
4381 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
4383 return info_ptr
+ bytes_read
;
4385 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
4389 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4390 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4391 abbrev corresponding to that skipped uleb128 should be passed in
4392 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4396 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4397 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
4399 unsigned int bytes_read
;
4400 struct attribute attr
;
4401 bfd
*abfd
= cu
->objfile
->obfd
;
4402 unsigned int form
, i
;
4404 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
4406 /* The only abbrev we care about is DW_AT_sibling. */
4407 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
4409 read_attribute (&attr
, &abbrev
->attrs
[i
],
4410 abfd
, info_ptr
, cu
);
4411 if (attr
.form
== DW_FORM_ref_addr
)
4412 complaint (&symfile_complaints
,
4413 _("ignoring absolute DW_AT_sibling"));
4415 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
4418 /* If it isn't DW_AT_sibling, skip this attribute. */
4419 form
= abbrev
->attrs
[i
].form
;
4423 case DW_FORM_ref_addr
:
4424 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4425 and later it is offset sized. */
4426 if (cu
->header
.version
== 2)
4427 info_ptr
+= cu
->header
.addr_size
;
4429 info_ptr
+= cu
->header
.offset_size
;
4432 info_ptr
+= cu
->header
.addr_size
;
4439 case DW_FORM_flag_present
:
4451 case DW_FORM_ref_sig8
:
4454 case DW_FORM_string
:
4455 read_direct_string (abfd
, info_ptr
, &bytes_read
);
4456 info_ptr
+= bytes_read
;
4458 case DW_FORM_sec_offset
:
4460 info_ptr
+= cu
->header
.offset_size
;
4462 case DW_FORM_exprloc
:
4464 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4465 info_ptr
+= bytes_read
;
4467 case DW_FORM_block1
:
4468 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
4470 case DW_FORM_block2
:
4471 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
4473 case DW_FORM_block4
:
4474 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
4478 case DW_FORM_ref_udata
:
4479 info_ptr
= skip_leb128 (abfd
, info_ptr
);
4481 case DW_FORM_indirect
:
4482 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4483 info_ptr
+= bytes_read
;
4484 /* We need to continue parsing from here, so just go back to
4486 goto skip_attribute
;
4489 error (_("Dwarf Error: Cannot handle %s "
4490 "in DWARF reader [in module %s]"),
4491 dwarf_form_name (form
),
4492 bfd_get_filename (abfd
));
4496 if (abbrev
->has_children
)
4497 return skip_children (buffer
, info_ptr
, cu
);
4502 /* Locate ORIG_PDI's sibling.
4503 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4507 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
4508 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4509 bfd
*abfd
, struct dwarf2_cu
*cu
)
4511 /* Do we know the sibling already? */
4513 if (orig_pdi
->sibling
)
4514 return orig_pdi
->sibling
;
4516 /* Are there any children to deal with? */
4518 if (!orig_pdi
->has_children
)
4521 /* Skip the children the long way. */
4523 return skip_children (buffer
, info_ptr
, cu
);
4526 /* Expand this partial symbol table into a full symbol table. */
4529 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
4535 warning (_("bug: psymtab for %s is already read in."),
4542 printf_filtered (_("Reading in symbols for %s..."),
4544 gdb_flush (gdb_stdout
);
4547 /* Restore our global data. */
4548 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
4549 dwarf2_objfile_data_key
);
4551 /* If this psymtab is constructed from a debug-only objfile, the
4552 has_section_at_zero flag will not necessarily be correct. We
4553 can get the correct value for this flag by looking at the data
4554 associated with the (presumably stripped) associated objfile. */
4555 if (pst
->objfile
->separate_debug_objfile_backlink
)
4557 struct dwarf2_per_objfile
*dpo_backlink
4558 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
4559 dwarf2_objfile_data_key
);
4561 dwarf2_per_objfile
->has_section_at_zero
4562 = dpo_backlink
->has_section_at_zero
;
4565 dwarf2_per_objfile
->reading_partial_symbols
= 0;
4567 psymtab_to_symtab_1 (pst
);
4569 /* Finish up the debug error message. */
4571 printf_filtered (_("done.\n"));
4576 /* Reading in full CUs. */
4578 /* Add PER_CU to the queue. */
4581 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4583 struct dwarf2_queue_item
*item
;
4586 item
= xmalloc (sizeof (*item
));
4587 item
->per_cu
= per_cu
;
4590 if (dwarf2_queue
== NULL
)
4591 dwarf2_queue
= item
;
4593 dwarf2_queue_tail
->next
= item
;
4595 dwarf2_queue_tail
= item
;
4598 /* Process the queue. */
4601 process_queue (void)
4603 struct dwarf2_queue_item
*item
, *next_item
;
4605 /* The queue starts out with one item, but following a DIE reference
4606 may load a new CU, adding it to the end of the queue. */
4607 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
4609 if (dwarf2_per_objfile
->using_index
4610 ? !item
->per_cu
->v
.quick
->symtab
4611 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
4612 process_full_comp_unit (item
->per_cu
);
4614 item
->per_cu
->queued
= 0;
4615 next_item
= item
->next
;
4619 dwarf2_queue_tail
= NULL
;
4622 /* Free all allocated queue entries. This function only releases anything if
4623 an error was thrown; if the queue was processed then it would have been
4624 freed as we went along. */
4627 dwarf2_release_queue (void *dummy
)
4629 struct dwarf2_queue_item
*item
, *last
;
4631 item
= dwarf2_queue
;
4634 /* Anything still marked queued is likely to be in an
4635 inconsistent state, so discard it. */
4636 if (item
->per_cu
->queued
)
4638 if (item
->per_cu
->cu
!= NULL
)
4639 free_one_cached_comp_unit (item
->per_cu
->cu
);
4640 item
->per_cu
->queued
= 0;
4648 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
4651 /* Read in full symbols for PST, and anything it depends on. */
4654 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
4656 struct dwarf2_per_cu_data
*per_cu
;
4657 struct cleanup
*back_to
;
4660 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
4661 if (!pst
->dependencies
[i
]->readin
)
4663 /* Inform about additional files that need to be read in. */
4666 /* FIXME: i18n: Need to make this a single string. */
4667 fputs_filtered (" ", gdb_stdout
);
4669 fputs_filtered ("and ", gdb_stdout
);
4671 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
4672 wrap_here (""); /* Flush output. */
4673 gdb_flush (gdb_stdout
);
4675 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
4678 per_cu
= pst
->read_symtab_private
;
4682 /* It's an include file, no symbols to read for it.
4683 Everything is in the parent symtab. */
4688 dw2_do_instantiate_symtab (per_cu
);
4691 /* Load the DIEs associated with PER_CU into memory. */
4694 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4696 struct objfile
*objfile
= per_cu
->objfile
;
4697 bfd
*abfd
= objfile
->obfd
;
4698 struct dwarf2_cu
*cu
;
4699 unsigned int offset
;
4700 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
4701 struct cleanup
*free_cu_cleanup
= NULL
;
4702 struct attribute
*attr
;
4705 gdb_assert (! per_cu
->debug_types_section
);
4707 /* Set local variables from the partial symbol table info. */
4708 offset
= per_cu
->offset
;
4710 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4711 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
4712 beg_of_comp_unit
= info_ptr
;
4714 if (per_cu
->cu
== NULL
)
4716 cu
= xmalloc (sizeof (*cu
));
4717 init_one_comp_unit (cu
, per_cu
);
4721 /* If an error occurs while loading, release our storage. */
4722 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
4724 /* Read in the comp_unit header. */
4725 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
4727 /* Skip dummy compilation units. */
4728 if (info_ptr
>= (dwarf2_per_objfile
->info
.buffer
4729 + dwarf2_per_objfile
->info
.size
)
4730 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4732 do_cleanups (free_cu_cleanup
);
4736 /* Complete the cu_header. */
4737 cu
->header
.offset
= offset
;
4738 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
4743 info_ptr
+= cu
->header
.first_die_offset
;
4746 cu
->dies
= read_comp_unit (info_ptr
, cu
);
4748 /* We try not to read any attributes in this function, because not
4749 all CUs needed for references have been loaded yet, and symbol
4750 table processing isn't initialized. But we have to set the CU language,
4751 or we won't be able to build types correctly. */
4752 prepare_one_comp_unit (cu
, cu
->dies
);
4754 /* Similarly, if we do not read the producer, we can not apply
4755 producer-specific interpretation. */
4756 attr
= dwarf2_attr (cu
->dies
, DW_AT_producer
, cu
);
4758 cu
->producer
= DW_STRING (attr
);
4762 /* We've successfully allocated this compilation unit. Let our
4763 caller clean it up when finished with it. */
4764 discard_cleanups (free_cu_cleanup
);
4766 /* Link this CU into read_in_chain. */
4767 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4768 dwarf2_per_objfile
->read_in_chain
= per_cu
;
4772 /* Add a DIE to the delayed physname list. */
4775 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
4776 const char *name
, struct die_info
*die
,
4777 struct dwarf2_cu
*cu
)
4779 struct delayed_method_info mi
;
4781 mi
.fnfield_index
= fnfield_index
;
4785 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
4788 /* A cleanup for freeing the delayed method list. */
4791 free_delayed_list (void *ptr
)
4793 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
4794 if (cu
->method_list
!= NULL
)
4796 VEC_free (delayed_method_info
, cu
->method_list
);
4797 cu
->method_list
= NULL
;
4801 /* Compute the physnames of any methods on the CU's method list.
4803 The computation of method physnames is delayed in order to avoid the
4804 (bad) condition that one of the method's formal parameters is of an as yet
4808 compute_delayed_physnames (struct dwarf2_cu
*cu
)
4811 struct delayed_method_info
*mi
;
4812 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
4814 const char *physname
;
4815 struct fn_fieldlist
*fn_flp
4816 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
4817 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
4818 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
4822 /* Generate full symbol information for PER_CU, whose DIEs have
4823 already been loaded into memory. */
4826 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4828 struct dwarf2_cu
*cu
= per_cu
->cu
;
4829 struct objfile
*objfile
= per_cu
->objfile
;
4830 CORE_ADDR lowpc
, highpc
;
4831 struct symtab
*symtab
;
4832 struct cleanup
*back_to
, *delayed_list_cleanup
;
4835 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4838 back_to
= make_cleanup (really_free_pendings
, NULL
);
4839 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
4841 cu
->list_in_scope
= &file_symbols
;
4843 /* Do line number decoding in read_file_scope () */
4844 process_die (cu
->dies
, cu
);
4846 /* Now that we have processed all the DIEs in the CU, all the types
4847 should be complete, and it should now be safe to compute all of the
4849 compute_delayed_physnames (cu
);
4850 do_cleanups (delayed_list_cleanup
);
4852 /* Some compilers don't define a DW_AT_high_pc attribute for the
4853 compilation unit. If the DW_AT_high_pc is missing, synthesize
4854 it, by scanning the DIE's below the compilation unit. */
4855 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
4857 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
4861 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
4863 /* Set symtab language to language from DW_AT_language. If the
4864 compilation is from a C file generated by language preprocessors, do
4865 not set the language if it was already deduced by start_subfile. */
4866 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
4867 symtab
->language
= cu
->language
;
4869 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
4870 produce DW_AT_location with location lists but it can be possibly
4871 invalid without -fvar-tracking.
4873 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
4874 needed, it would be wrong due to missing DW_AT_producer there.
4876 Still one can confuse GDB by using non-standard GCC compilation
4877 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
4879 if (cu
->has_loclist
&& gcc_4_minor
>= 0)
4880 symtab
->locations_valid
= 1;
4882 if (gcc_4_minor
>= 5)
4883 symtab
->epilogue_unwind_valid
= 1;
4885 symtab
->call_site_htab
= cu
->call_site_htab
;
4888 if (dwarf2_per_objfile
->using_index
)
4889 per_cu
->v
.quick
->symtab
= symtab
;
4892 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4893 pst
->symtab
= symtab
;
4897 do_cleanups (back_to
);
4900 /* Process a die and its children. */
4903 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
4907 case DW_TAG_padding
:
4909 case DW_TAG_compile_unit
:
4910 read_file_scope (die
, cu
);
4912 case DW_TAG_type_unit
:
4913 read_type_unit_scope (die
, cu
);
4915 case DW_TAG_subprogram
:
4916 case DW_TAG_inlined_subroutine
:
4917 read_func_scope (die
, cu
);
4919 case DW_TAG_lexical_block
:
4920 case DW_TAG_try_block
:
4921 case DW_TAG_catch_block
:
4922 read_lexical_block_scope (die
, cu
);
4924 case DW_TAG_GNU_call_site
:
4925 read_call_site_scope (die
, cu
);
4927 case DW_TAG_class_type
:
4928 case DW_TAG_interface_type
:
4929 case DW_TAG_structure_type
:
4930 case DW_TAG_union_type
:
4931 process_structure_scope (die
, cu
);
4933 case DW_TAG_enumeration_type
:
4934 process_enumeration_scope (die
, cu
);
4937 /* These dies have a type, but processing them does not create
4938 a symbol or recurse to process the children. Therefore we can
4939 read them on-demand through read_type_die. */
4940 case DW_TAG_subroutine_type
:
4941 case DW_TAG_set_type
:
4942 case DW_TAG_array_type
:
4943 case DW_TAG_pointer_type
:
4944 case DW_TAG_ptr_to_member_type
:
4945 case DW_TAG_reference_type
:
4946 case DW_TAG_string_type
:
4949 case DW_TAG_base_type
:
4950 case DW_TAG_subrange_type
:
4951 case DW_TAG_typedef
:
4952 /* Add a typedef symbol for the type definition, if it has a
4954 new_symbol (die
, read_type_die (die
, cu
), cu
);
4956 case DW_TAG_common_block
:
4957 read_common_block (die
, cu
);
4959 case DW_TAG_common_inclusion
:
4961 case DW_TAG_namespace
:
4962 processing_has_namespace_info
= 1;
4963 read_namespace (die
, cu
);
4966 processing_has_namespace_info
= 1;
4967 read_module (die
, cu
);
4969 case DW_TAG_imported_declaration
:
4970 case DW_TAG_imported_module
:
4971 processing_has_namespace_info
= 1;
4972 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
4973 || cu
->language
!= language_fortran
))
4974 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
4975 dwarf_tag_name (die
->tag
));
4976 read_import_statement (die
, cu
);
4979 new_symbol (die
, NULL
, cu
);
4984 /* A helper function for dwarf2_compute_name which determines whether DIE
4985 needs to have the name of the scope prepended to the name listed in the
4989 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4991 struct attribute
*attr
;
4995 case DW_TAG_namespace
:
4996 case DW_TAG_typedef
:
4997 case DW_TAG_class_type
:
4998 case DW_TAG_interface_type
:
4999 case DW_TAG_structure_type
:
5000 case DW_TAG_union_type
:
5001 case DW_TAG_enumeration_type
:
5002 case DW_TAG_enumerator
:
5003 case DW_TAG_subprogram
:
5007 case DW_TAG_variable
:
5008 case DW_TAG_constant
:
5009 /* We only need to prefix "globally" visible variables. These include
5010 any variable marked with DW_AT_external or any variable that
5011 lives in a namespace. [Variables in anonymous namespaces
5012 require prefixing, but they are not DW_AT_external.] */
5014 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
5016 struct dwarf2_cu
*spec_cu
= cu
;
5018 return die_needs_namespace (die_specification (die
, &spec_cu
),
5022 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5023 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
5024 && die
->parent
->tag
!= DW_TAG_module
)
5026 /* A variable in a lexical block of some kind does not need a
5027 namespace, even though in C++ such variables may be external
5028 and have a mangled name. */
5029 if (die
->parent
->tag
== DW_TAG_lexical_block
5030 || die
->parent
->tag
== DW_TAG_try_block
5031 || die
->parent
->tag
== DW_TAG_catch_block
5032 || die
->parent
->tag
== DW_TAG_subprogram
)
5041 /* Retrieve the last character from a mem_file. */
5044 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
5046 char *last_char_p
= (char *) object
;
5049 *last_char_p
= buffer
[length
- 1];
5052 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
5053 compute the physname for the object, which include a method's
5054 formal parameters (C++/Java) and return type (Java).
5056 For Ada, return the DIE's linkage name rather than the fully qualified
5057 name. PHYSNAME is ignored..
5059 The result is allocated on the objfile_obstack and canonicalized. */
5062 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
5065 struct objfile
*objfile
= cu
->objfile
;
5068 name
= dwarf2_name (die
, cu
);
5070 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
5071 compute it by typename_concat inside GDB. */
5072 if (cu
->language
== language_ada
5073 || (cu
->language
== language_fortran
&& physname
))
5075 /* For Ada unit, we prefer the linkage name over the name, as
5076 the former contains the exported name, which the user expects
5077 to be able to reference. Ideally, we want the user to be able
5078 to reference this entity using either natural or linkage name,
5079 but we haven't started looking at this enhancement yet. */
5080 struct attribute
*attr
;
5082 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5084 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5085 if (attr
&& DW_STRING (attr
))
5086 return DW_STRING (attr
);
5089 /* These are the only languages we know how to qualify names in. */
5091 && (cu
->language
== language_cplus
|| cu
->language
== language_java
5092 || cu
->language
== language_fortran
))
5094 if (die_needs_namespace (die
, cu
))
5098 struct ui_file
*buf
;
5100 prefix
= determine_prefix (die
, cu
);
5101 buf
= mem_fileopen ();
5102 if (*prefix
!= '\0')
5104 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
5107 fputs_unfiltered (prefixed_name
, buf
);
5108 xfree (prefixed_name
);
5111 fputs_unfiltered (name
, buf
);
5113 /* Template parameters may be specified in the DIE's DW_AT_name, or
5114 as children with DW_TAG_template_type_param or
5115 DW_TAG_value_type_param. If the latter, add them to the name
5116 here. If the name already has template parameters, then
5117 skip this step; some versions of GCC emit both, and
5118 it is more efficient to use the pre-computed name.
5120 Something to keep in mind about this process: it is very
5121 unlikely, or in some cases downright impossible, to produce
5122 something that will match the mangled name of a function.
5123 If the definition of the function has the same debug info,
5124 we should be able to match up with it anyway. But fallbacks
5125 using the minimal symbol, for instance to find a method
5126 implemented in a stripped copy of libstdc++, will not work.
5127 If we do not have debug info for the definition, we will have to
5128 match them up some other way.
5130 When we do name matching there is a related problem with function
5131 templates; two instantiated function templates are allowed to
5132 differ only by their return types, which we do not add here. */
5134 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
5136 struct attribute
*attr
;
5137 struct die_info
*child
;
5140 die
->building_fullname
= 1;
5142 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
5147 struct dwarf2_locexpr_baton
*baton
;
5150 if (child
->tag
!= DW_TAG_template_type_param
5151 && child
->tag
!= DW_TAG_template_value_param
)
5156 fputs_unfiltered ("<", buf
);
5160 fputs_unfiltered (", ", buf
);
5162 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
5165 complaint (&symfile_complaints
,
5166 _("template parameter missing DW_AT_type"));
5167 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
5170 type
= die_type (child
, cu
);
5172 if (child
->tag
== DW_TAG_template_type_param
)
5174 c_print_type (type
, "", buf
, -1, 0);
5178 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
5181 complaint (&symfile_complaints
,
5182 _("template parameter missing "
5183 "DW_AT_const_value"));
5184 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
5188 dwarf2_const_value_attr (attr
, type
, name
,
5189 &cu
->comp_unit_obstack
, cu
,
5190 &value
, &bytes
, &baton
);
5192 if (TYPE_NOSIGN (type
))
5193 /* GDB prints characters as NUMBER 'CHAR'. If that's
5194 changed, this can use value_print instead. */
5195 c_printchar (value
, type
, buf
);
5198 struct value_print_options opts
;
5201 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
5205 else if (bytes
!= NULL
)
5207 v
= allocate_value (type
);
5208 memcpy (value_contents_writeable (v
), bytes
,
5209 TYPE_LENGTH (type
));
5212 v
= value_from_longest (type
, value
);
5214 /* Specify decimal so that we do not depend on
5216 get_formatted_print_options (&opts
, 'd');
5218 value_print (v
, buf
, &opts
);
5224 die
->building_fullname
= 0;
5228 /* Close the argument list, with a space if necessary
5229 (nested templates). */
5230 char last_char
= '\0';
5231 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
5232 if (last_char
== '>')
5233 fputs_unfiltered (" >", buf
);
5235 fputs_unfiltered (">", buf
);
5239 /* For Java and C++ methods, append formal parameter type
5240 information, if PHYSNAME. */
5242 if (physname
&& die
->tag
== DW_TAG_subprogram
5243 && (cu
->language
== language_cplus
5244 || cu
->language
== language_java
))
5246 struct type
*type
= read_type_die (die
, cu
);
5248 c_type_print_args (type
, buf
, 1, cu
->language
);
5250 if (cu
->language
== language_java
)
5252 /* For java, we must append the return type to method
5254 if (die
->tag
== DW_TAG_subprogram
)
5255 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
5258 else if (cu
->language
== language_cplus
)
5260 /* Assume that an artificial first parameter is
5261 "this", but do not crash if it is not. RealView
5262 marks unnamed (and thus unused) parameters as
5263 artificial; there is no way to differentiate
5265 if (TYPE_NFIELDS (type
) > 0
5266 && TYPE_FIELD_ARTIFICIAL (type
, 0)
5267 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
5268 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
5270 fputs_unfiltered (" const", buf
);
5274 name
= ui_file_obsavestring (buf
, &objfile
->objfile_obstack
,
5276 ui_file_delete (buf
);
5278 if (cu
->language
== language_cplus
)
5281 = dwarf2_canonicalize_name (name
, cu
,
5282 &objfile
->objfile_obstack
);
5293 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5294 If scope qualifiers are appropriate they will be added. The result
5295 will be allocated on the objfile_obstack, or NULL if the DIE does
5296 not have a name. NAME may either be from a previous call to
5297 dwarf2_name or NULL.
5299 The output string will be canonicalized (if C++/Java). */
5302 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5304 return dwarf2_compute_name (name
, die
, cu
, 0);
5307 /* Construct a physname for the given DIE in CU. NAME may either be
5308 from a previous call to dwarf2_name or NULL. The result will be
5309 allocated on the objfile_objstack or NULL if the DIE does not have a
5312 The output string will be canonicalized (if C++/Java). */
5315 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5317 struct objfile
*objfile
= cu
->objfile
;
5318 struct attribute
*attr
;
5319 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
5320 struct cleanup
*back_to
;
5323 /* In this case dwarf2_compute_name is just a shortcut not building anything
5325 if (!die_needs_namespace (die
, cu
))
5326 return dwarf2_compute_name (name
, die
, cu
, 1);
5328 back_to
= make_cleanup (null_cleanup
, NULL
);
5330 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5332 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5334 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
5336 if (attr
&& DW_STRING (attr
))
5340 mangled
= DW_STRING (attr
);
5342 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
5343 type. It is easier for GDB users to search for such functions as
5344 `name(params)' than `long name(params)'. In such case the minimal
5345 symbol names do not match the full symbol names but for template
5346 functions there is never a need to look up their definition from their
5347 declaration so the only disadvantage remains the minimal symbol
5348 variant `long name(params)' does not have the proper inferior type.
5351 demangled
= cplus_demangle (mangled
, (DMGL_PARAMS
| DMGL_ANSI
5352 | (cu
->language
== language_java
5353 ? DMGL_JAVA
| DMGL_RET_POSTFIX
5357 make_cleanup (xfree
, demangled
);
5367 if (canon
== NULL
|| check_physname
)
5369 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
5371 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
5373 /* It may not mean a bug in GDB. The compiler could also
5374 compute DW_AT_linkage_name incorrectly. But in such case
5375 GDB would need to be bug-to-bug compatible. */
5377 complaint (&symfile_complaints
,
5378 _("Computed physname <%s> does not match demangled <%s> "
5379 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
5380 physname
, canon
, mangled
, die
->offset
, objfile
->name
);
5382 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
5383 is available here - over computed PHYSNAME. It is safer
5384 against both buggy GDB and buggy compilers. */
5398 retval
= obsavestring (retval
, strlen (retval
),
5399 &objfile
->objfile_obstack
);
5401 do_cleanups (back_to
);
5405 /* Read the import statement specified by the given die and record it. */
5408 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
5410 struct objfile
*objfile
= cu
->objfile
;
5411 struct attribute
*import_attr
;
5412 struct die_info
*imported_die
, *child_die
;
5413 struct dwarf2_cu
*imported_cu
;
5414 const char *imported_name
;
5415 const char *imported_name_prefix
;
5416 const char *canonical_name
;
5417 const char *import_alias
;
5418 const char *imported_declaration
= NULL
;
5419 const char *import_prefix
;
5420 VEC (const_char_ptr
) *excludes
= NULL
;
5421 struct cleanup
*cleanups
;
5425 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
5426 if (import_attr
== NULL
)
5428 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5429 dwarf_tag_name (die
->tag
));
5434 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
5435 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5436 if (imported_name
== NULL
)
5438 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
5440 The import in the following code:
5454 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
5455 <52> DW_AT_decl_file : 1
5456 <53> DW_AT_decl_line : 6
5457 <54> DW_AT_import : <0x75>
5458 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
5460 <5b> DW_AT_decl_file : 1
5461 <5c> DW_AT_decl_line : 2
5462 <5d> DW_AT_type : <0x6e>
5464 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
5465 <76> DW_AT_byte_size : 4
5466 <77> DW_AT_encoding : 5 (signed)
5468 imports the wrong die ( 0x75 instead of 0x58 ).
5469 This case will be ignored until the gcc bug is fixed. */
5473 /* Figure out the local name after import. */
5474 import_alias
= dwarf2_name (die
, cu
);
5476 /* Figure out where the statement is being imported to. */
5477 import_prefix
= determine_prefix (die
, cu
);
5479 /* Figure out what the scope of the imported die is and prepend it
5480 to the name of the imported die. */
5481 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
5483 if (imported_die
->tag
!= DW_TAG_namespace
5484 && imported_die
->tag
!= DW_TAG_module
)
5486 imported_declaration
= imported_name
;
5487 canonical_name
= imported_name_prefix
;
5489 else if (strlen (imported_name_prefix
) > 0)
5491 temp
= alloca (strlen (imported_name_prefix
)
5492 + 2 + strlen (imported_name
) + 1);
5493 strcpy (temp
, imported_name_prefix
);
5494 strcat (temp
, "::");
5495 strcat (temp
, imported_name
);
5496 canonical_name
= temp
;
5499 canonical_name
= imported_name
;
5501 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
5503 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
5504 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
5505 child_die
= sibling_die (child_die
))
5507 /* DWARF-4: A Fortran use statement with a “rename list” may be
5508 represented by an imported module entry with an import attribute
5509 referring to the module and owned entries corresponding to those
5510 entities that are renamed as part of being imported. */
5512 if (child_die
->tag
!= DW_TAG_imported_declaration
)
5514 complaint (&symfile_complaints
,
5515 _("child DW_TAG_imported_declaration expected "
5516 "- DIE at 0x%x [in module %s]"),
5517 child_die
->offset
, objfile
->name
);
5521 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
5522 if (import_attr
== NULL
)
5524 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5525 dwarf_tag_name (child_die
->tag
));
5530 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
5532 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5533 if (imported_name
== NULL
)
5535 complaint (&symfile_complaints
,
5536 _("child DW_TAG_imported_declaration has unknown "
5537 "imported name - DIE at 0x%x [in module %s]"),
5538 child_die
->offset
, objfile
->name
);
5542 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
5544 process_die (child_die
, cu
);
5547 cp_add_using_directive (import_prefix
,
5550 imported_declaration
,
5552 &objfile
->objfile_obstack
);
5554 do_cleanups (cleanups
);
5557 /* Cleanup function for read_file_scope. */
5560 free_cu_line_header (void *arg
)
5562 struct dwarf2_cu
*cu
= arg
;
5564 free_line_header (cu
->line_header
);
5565 cu
->line_header
= NULL
;
5569 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
5570 char **name
, char **comp_dir
)
5572 struct attribute
*attr
;
5577 /* Find the filename. Do not use dwarf2_name here, since the filename
5578 is not a source language identifier. */
5579 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5582 *name
= DW_STRING (attr
);
5585 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5587 *comp_dir
= DW_STRING (attr
);
5588 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
5590 *comp_dir
= ldirname (*name
);
5591 if (*comp_dir
!= NULL
)
5592 make_cleanup (xfree
, *comp_dir
);
5594 if (*comp_dir
!= NULL
)
5596 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5597 directory, get rid of it. */
5598 char *cp
= strchr (*comp_dir
, ':');
5600 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
5605 *name
= "<unknown>";
5608 /* Handle DW_AT_stmt_list for a compilation unit or type unit.
5609 DIE is the DW_TAG_compile_unit or DW_TAG_type_unit die for CU.
5610 COMP_DIR is the compilation directory.
5611 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
5614 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
5615 const char *comp_dir
, int want_line_info
)
5617 struct attribute
*attr
;
5618 struct objfile
*objfile
= cu
->objfile
;
5619 bfd
*abfd
= objfile
->obfd
;
5621 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5624 unsigned int line_offset
= DW_UNSND (attr
);
5625 struct line_header
*line_header
5626 = dwarf_decode_line_header (line_offset
, abfd
, cu
);
5630 cu
->line_header
= line_header
;
5631 make_cleanup (free_cu_line_header
, cu
);
5632 dwarf_decode_lines (line_header
, comp_dir
, cu
, NULL
, want_line_info
);
5637 /* Process DW_TAG_compile_unit. */
5640 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5642 struct objfile
*objfile
= cu
->objfile
;
5643 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5644 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
5645 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
5646 struct attribute
*attr
;
5648 char *comp_dir
= NULL
;
5649 struct die_info
*child_die
;
5650 bfd
*abfd
= objfile
->obfd
;
5653 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5655 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
5657 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5658 from finish_block. */
5659 if (lowpc
== ((CORE_ADDR
) -1))
5664 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
5666 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5669 set_cu_language (DW_UNSND (attr
), cu
);
5672 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5674 cu
->producer
= DW_STRING (attr
);
5676 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
5677 standardised yet. As a workaround for the language detection we fall
5678 back to the DW_AT_producer string. */
5679 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
5680 cu
->language
= language_opencl
;
5682 /* We assume that we're processing GCC output. */
5683 processing_gcc_compilation
= 2;
5685 processing_has_namespace_info
= 0;
5687 start_symtab (name
, comp_dir
, lowpc
);
5688 record_debugformat ("DWARF 2");
5689 record_producer (cu
->producer
);
5691 /* Decode line number information if present. We do this before
5692 processing child DIEs, so that the line header table is available
5693 for DW_AT_decl_file. */
5694 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, 1);
5696 /* Process all dies in compilation unit. */
5697 if (die
->child
!= NULL
)
5699 child_die
= die
->child
;
5700 while (child_die
&& child_die
->tag
)
5702 process_die (child_die
, cu
);
5703 child_die
= sibling_die (child_die
);
5707 /* Decode macro information, if present. Dwarf 2 macro information
5708 refers to information in the line number info statement program
5709 header, so we can only read it if we've read the header
5711 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
5712 if (attr
&& cu
->line_header
)
5714 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
5715 complaint (&symfile_complaints
,
5716 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
5718 dwarf_decode_macros (cu
->line_header
, DW_UNSND (attr
),
5720 &dwarf2_per_objfile
->macro
, 1);
5724 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
5725 if (attr
&& cu
->line_header
)
5727 unsigned int macro_offset
= DW_UNSND (attr
);
5729 dwarf_decode_macros (cu
->line_header
, macro_offset
,
5731 &dwarf2_per_objfile
->macinfo
, 0);
5735 do_cleanups (back_to
);
5738 /* Process DW_TAG_type_unit.
5739 For TUs we want to skip the first top level sibling if it's not the
5740 actual type being defined by this TU. In this case the first top
5741 level sibling is there to provide context only. */
5744 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5746 struct objfile
*objfile
= cu
->objfile
;
5747 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5749 struct attribute
*attr
;
5751 char *comp_dir
= NULL
;
5752 struct die_info
*child_die
;
5753 bfd
*abfd
= objfile
->obfd
;
5755 /* start_symtab needs a low pc, but we don't really have one.
5756 Do what read_file_scope would do in the absence of such info. */
5757 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5759 /* Find the filename. Do not use dwarf2_name here, since the filename
5760 is not a source language identifier. */
5761 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5763 name
= DW_STRING (attr
);
5765 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5767 comp_dir
= DW_STRING (attr
);
5768 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
5770 comp_dir
= ldirname (name
);
5771 if (comp_dir
!= NULL
)
5772 make_cleanup (xfree
, comp_dir
);
5778 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5780 set_cu_language (DW_UNSND (attr
), cu
);
5782 /* This isn't technically needed today. It is done for symmetry
5783 with read_file_scope. */
5784 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5786 cu
->producer
= DW_STRING (attr
);
5788 /* We assume that we're processing GCC output. */
5789 processing_gcc_compilation
= 2;
5791 processing_has_namespace_info
= 0;
5793 start_symtab (name
, comp_dir
, lowpc
);
5794 record_debugformat ("DWARF 2");
5795 record_producer (cu
->producer
);
5797 /* Decode line number information if present. We do this before
5798 processing child DIEs, so that the line header table is available
5799 for DW_AT_decl_file.
5800 We don't need the pc/line-number mapping for type units. */
5801 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, 0);
5803 /* Process the dies in the type unit. */
5804 if (die
->child
== NULL
)
5806 dump_die_for_error (die
);
5807 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5808 bfd_get_filename (abfd
));
5811 child_die
= die
->child
;
5813 while (child_die
&& child_die
->tag
)
5815 process_die (child_die
, cu
);
5817 child_die
= sibling_die (child_die
);
5820 do_cleanups (back_to
);
5823 /* qsort helper for inherit_abstract_dies. */
5826 unsigned_int_compar (const void *ap
, const void *bp
)
5828 unsigned int a
= *(unsigned int *) ap
;
5829 unsigned int b
= *(unsigned int *) bp
;
5831 return (a
> b
) - (b
> a
);
5834 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5835 Inherit only the children of the DW_AT_abstract_origin DIE not being
5836 already referenced by DW_AT_abstract_origin from the children of the
5840 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
5842 struct die_info
*child_die
;
5843 unsigned die_children_count
;
5844 /* CU offsets which were referenced by children of the current DIE. */
5846 unsigned *offsets_end
, *offsetp
;
5847 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5848 struct die_info
*origin_die
;
5849 /* Iterator of the ORIGIN_DIE children. */
5850 struct die_info
*origin_child_die
;
5851 struct cleanup
*cleanups
;
5852 struct attribute
*attr
;
5853 struct dwarf2_cu
*origin_cu
;
5854 struct pending
**origin_previous_list_in_scope
;
5856 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
5860 /* Note that following die references may follow to a die in a
5864 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
5866 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5868 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
5869 origin_cu
->list_in_scope
= cu
->list_in_scope
;
5871 if (die
->tag
!= origin_die
->tag
5872 && !(die
->tag
== DW_TAG_inlined_subroutine
5873 && origin_die
->tag
== DW_TAG_subprogram
))
5874 complaint (&symfile_complaints
,
5875 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5876 die
->offset
, origin_die
->offset
);
5878 child_die
= die
->child
;
5879 die_children_count
= 0;
5880 while (child_die
&& child_die
->tag
)
5882 child_die
= sibling_die (child_die
);
5883 die_children_count
++;
5885 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
5886 cleanups
= make_cleanup (xfree
, offsets
);
5888 offsets_end
= offsets
;
5889 child_die
= die
->child
;
5890 while (child_die
&& child_die
->tag
)
5892 /* For each CHILD_DIE, find the corresponding child of
5893 ORIGIN_DIE. If there is more than one layer of
5894 DW_AT_abstract_origin, follow them all; there shouldn't be,
5895 but GCC versions at least through 4.4 generate this (GCC PR
5897 struct die_info
*child_origin_die
= child_die
;
5898 struct dwarf2_cu
*child_origin_cu
= cu
;
5902 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
5906 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
5910 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5911 counterpart may exist. */
5912 if (child_origin_die
!= child_die
)
5914 if (child_die
->tag
!= child_origin_die
->tag
5915 && !(child_die
->tag
== DW_TAG_inlined_subroutine
5916 && child_origin_die
->tag
== DW_TAG_subprogram
))
5917 complaint (&symfile_complaints
,
5918 _("Child DIE 0x%x and its abstract origin 0x%x have "
5919 "different tags"), child_die
->offset
,
5920 child_origin_die
->offset
);
5921 if (child_origin_die
->parent
!= origin_die
)
5922 complaint (&symfile_complaints
,
5923 _("Child DIE 0x%x and its abstract origin 0x%x have "
5924 "different parents"), child_die
->offset
,
5925 child_origin_die
->offset
);
5927 *offsets_end
++ = child_origin_die
->offset
;
5929 child_die
= sibling_die (child_die
);
5931 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
5932 unsigned_int_compar
);
5933 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
5934 if (offsetp
[-1] == *offsetp
)
5935 complaint (&symfile_complaints
,
5936 _("Multiple children of DIE 0x%x refer "
5937 "to DIE 0x%x as their abstract origin"),
5938 die
->offset
, *offsetp
);
5941 origin_child_die
= origin_die
->child
;
5942 while (origin_child_die
&& origin_child_die
->tag
)
5944 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5945 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
5947 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
5949 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5950 process_die (origin_child_die
, origin_cu
);
5952 origin_child_die
= sibling_die (origin_child_die
);
5954 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
5956 do_cleanups (cleanups
);
5960 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5962 struct objfile
*objfile
= cu
->objfile
;
5963 struct context_stack
*new;
5966 struct die_info
*child_die
;
5967 struct attribute
*attr
, *call_line
, *call_file
;
5970 struct block
*block
;
5971 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
5972 VEC (symbolp
) *template_args
= NULL
;
5973 struct template_symbol
*templ_func
= NULL
;
5977 /* If we do not have call site information, we can't show the
5978 caller of this inlined function. That's too confusing, so
5979 only use the scope for local variables. */
5980 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
5981 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
5982 if (call_line
== NULL
|| call_file
== NULL
)
5984 read_lexical_block_scope (die
, cu
);
5989 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5991 name
= dwarf2_name (die
, cu
);
5993 /* Ignore functions with missing or empty names. These are actually
5994 illegal according to the DWARF standard. */
5997 complaint (&symfile_complaints
,
5998 _("missing name for subprogram DIE at %d"), die
->offset
);
6002 /* Ignore functions with missing or invalid low and high pc attributes. */
6003 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
6005 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
6006 if (!attr
|| !DW_UNSND (attr
))
6007 complaint (&symfile_complaints
,
6008 _("cannot get low and high bounds "
6009 "for subprogram DIE at %d"),
6017 /* If we have any template arguments, then we must allocate a
6018 different sort of symbol. */
6019 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
6021 if (child_die
->tag
== DW_TAG_template_type_param
6022 || child_die
->tag
== DW_TAG_template_value_param
)
6024 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6025 struct template_symbol
);
6026 templ_func
->base
.is_cplus_template_function
= 1;
6031 new = push_context (0, lowpc
);
6032 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
6033 (struct symbol
*) templ_func
);
6035 /* If there is a location expression for DW_AT_frame_base, record
6037 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
6039 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
6040 expression is being recorded directly in the function's symbol
6041 and not in a separate frame-base object. I guess this hack is
6042 to avoid adding some sort of frame-base adjunct/annex to the
6043 function's symbol :-(. The problem with doing this is that it
6044 results in a function symbol with a location expression that
6045 has nothing to do with the location of the function, ouch! The
6046 relationship should be: a function's symbol has-a frame base; a
6047 frame-base has-a location expression. */
6048 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
6050 cu
->list_in_scope
= &local_symbols
;
6052 if (die
->child
!= NULL
)
6054 child_die
= die
->child
;
6055 while (child_die
&& child_die
->tag
)
6057 if (child_die
->tag
== DW_TAG_template_type_param
6058 || child_die
->tag
== DW_TAG_template_value_param
)
6060 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
6063 VEC_safe_push (symbolp
, template_args
, arg
);
6066 process_die (child_die
, cu
);
6067 child_die
= sibling_die (child_die
);
6071 inherit_abstract_dies (die
, cu
);
6073 /* If we have a DW_AT_specification, we might need to import using
6074 directives from the context of the specification DIE. See the
6075 comment in determine_prefix. */
6076 if (cu
->language
== language_cplus
6077 && dwarf2_attr (die
, DW_AT_specification
, cu
))
6079 struct dwarf2_cu
*spec_cu
= cu
;
6080 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
6084 child_die
= spec_die
->child
;
6085 while (child_die
&& child_die
->tag
)
6087 if (child_die
->tag
== DW_TAG_imported_module
)
6088 process_die (child_die
, spec_cu
);
6089 child_die
= sibling_die (child_die
);
6092 /* In some cases, GCC generates specification DIEs that
6093 themselves contain DW_AT_specification attributes. */
6094 spec_die
= die_specification (spec_die
, &spec_cu
);
6098 new = pop_context ();
6099 /* Make a block for the local symbols within. */
6100 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
6101 lowpc
, highpc
, objfile
);
6103 /* For C++, set the block's scope. */
6104 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
6105 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
6106 determine_prefix (die
, cu
),
6107 processing_has_namespace_info
);
6109 /* If we have address ranges, record them. */
6110 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
6112 /* Attach template arguments to function. */
6113 if (! VEC_empty (symbolp
, template_args
))
6115 gdb_assert (templ_func
!= NULL
);
6117 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
6118 templ_func
->template_arguments
6119 = obstack_alloc (&objfile
->objfile_obstack
,
6120 (templ_func
->n_template_arguments
6121 * sizeof (struct symbol
*)));
6122 memcpy (templ_func
->template_arguments
,
6123 VEC_address (symbolp
, template_args
),
6124 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
6125 VEC_free (symbolp
, template_args
);
6128 /* In C++, we can have functions nested inside functions (e.g., when
6129 a function declares a class that has methods). This means that
6130 when we finish processing a function scope, we may need to go
6131 back to building a containing block's symbol lists. */
6132 local_symbols
= new->locals
;
6133 param_symbols
= new->params
;
6134 using_directives
= new->using_directives
;
6136 /* If we've finished processing a top-level function, subsequent
6137 symbols go in the file symbol list. */
6138 if (outermost_context_p ())
6139 cu
->list_in_scope
= &file_symbols
;
6142 /* Process all the DIES contained within a lexical block scope. Start
6143 a new scope, process the dies, and then close the scope. */
6146 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6148 struct objfile
*objfile
= cu
->objfile
;
6149 struct context_stack
*new;
6150 CORE_ADDR lowpc
, highpc
;
6151 struct die_info
*child_die
;
6154 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6156 /* Ignore blocks with missing or invalid low and high pc attributes. */
6157 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
6158 as multiple lexical blocks? Handling children in a sane way would
6159 be nasty. Might be easier to properly extend generic blocks to
6161 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
6166 push_context (0, lowpc
);
6167 if (die
->child
!= NULL
)
6169 child_die
= die
->child
;
6170 while (child_die
&& child_die
->tag
)
6172 process_die (child_die
, cu
);
6173 child_die
= sibling_die (child_die
);
6176 new = pop_context ();
6178 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
6181 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
6184 /* Note that recording ranges after traversing children, as we
6185 do here, means that recording a parent's ranges entails
6186 walking across all its children's ranges as they appear in
6187 the address map, which is quadratic behavior.
6189 It would be nicer to record the parent's ranges before
6190 traversing its children, simply overriding whatever you find
6191 there. But since we don't even decide whether to create a
6192 block until after we've traversed its children, that's hard
6194 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
6196 local_symbols
= new->locals
;
6197 using_directives
= new->using_directives
;
6200 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
6203 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6205 struct objfile
*objfile
= cu
->objfile
;
6206 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6207 CORE_ADDR pc
, baseaddr
;
6208 struct attribute
*attr
;
6209 struct call_site
*call_site
, call_site_local
;
6212 struct die_info
*child_die
;
6214 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6216 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6219 complaint (&symfile_complaints
,
6220 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
6221 "DIE 0x%x [in module %s]"),
6222 die
->offset
, objfile
->name
);
6225 pc
= DW_ADDR (attr
) + baseaddr
;
6227 if (cu
->call_site_htab
== NULL
)
6228 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
6229 NULL
, &objfile
->objfile_obstack
,
6230 hashtab_obstack_allocate
, NULL
);
6231 call_site_local
.pc
= pc
;
6232 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
6235 complaint (&symfile_complaints
,
6236 _("Duplicate PC %s for DW_TAG_GNU_call_site "
6237 "DIE 0x%x [in module %s]"),
6238 paddress (gdbarch
, pc
), die
->offset
, objfile
->name
);
6242 /* Count parameters at the caller. */
6245 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
6246 child_die
= sibling_die (child_die
))
6248 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
6250 complaint (&symfile_complaints
,
6251 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
6252 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6253 child_die
->tag
, child_die
->offset
, objfile
->name
);
6260 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
6261 (sizeof (*call_site
)
6262 + (sizeof (*call_site
->parameter
)
6265 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
6268 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
6270 struct die_info
*func_die
;
6272 /* Skip also over DW_TAG_inlined_subroutine. */
6273 for (func_die
= die
->parent
;
6274 func_die
&& func_die
->tag
!= DW_TAG_subprogram
6275 && func_die
->tag
!= DW_TAG_subroutine_type
;
6276 func_die
= func_die
->parent
);
6278 /* DW_AT_GNU_all_call_sites is a superset
6279 of DW_AT_GNU_all_tail_call_sites. */
6281 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
6282 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
6284 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
6285 not complete. But keep CALL_SITE for look ups via call_site_htab,
6286 both the initial caller containing the real return address PC and
6287 the final callee containing the current PC of a chain of tail
6288 calls do not need to have the tail call list complete. But any
6289 function candidate for a virtual tail call frame searched via
6290 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
6291 determined unambiguously. */
6295 struct type
*func_type
= NULL
;
6298 func_type
= get_die_type (func_die
, cu
);
6299 if (func_type
!= NULL
)
6301 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
6303 /* Enlist this call site to the function. */
6304 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
6305 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
6308 complaint (&symfile_complaints
,
6309 _("Cannot find function owning DW_TAG_GNU_call_site "
6310 "DIE 0x%x [in module %s]"),
6311 die
->offset
, objfile
->name
);
6315 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
6317 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
6318 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
6319 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
6320 /* Keep NULL DWARF_BLOCK. */;
6321 else if (attr_form_is_block (attr
))
6323 struct dwarf2_locexpr_baton
*dlbaton
;
6325 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
6326 dlbaton
->data
= DW_BLOCK (attr
)->data
;
6327 dlbaton
->size
= DW_BLOCK (attr
)->size
;
6328 dlbaton
->per_cu
= cu
->per_cu
;
6330 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
6332 else if (is_ref_attr (attr
))
6334 struct dwarf2_cu
*target_cu
= cu
;
6335 struct die_info
*target_die
;
6337 target_die
= follow_die_ref_or_sig (die
, attr
, &target_cu
);
6338 gdb_assert (target_cu
->objfile
== objfile
);
6339 if (die_is_declaration (target_die
, target_cu
))
6341 const char *target_physname
;
6343 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
6344 if (target_physname
== NULL
)
6345 complaint (&symfile_complaints
,
6346 _("DW_AT_GNU_call_site_target target DIE has invalid "
6347 "physname, for referencing DIE 0x%x [in module %s]"),
6348 die
->offset
, objfile
->name
);
6350 SET_FIELD_PHYSNAME (call_site
->target
, (char *) target_physname
);
6356 /* DW_AT_entry_pc should be preferred. */
6357 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
6358 complaint (&symfile_complaints
,
6359 _("DW_AT_GNU_call_site_target target DIE has invalid "
6360 "low pc, for referencing DIE 0x%x [in module %s]"),
6361 die
->offset
, objfile
->name
);
6363 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
6367 complaint (&symfile_complaints
,
6368 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
6369 "block nor reference, for DIE 0x%x [in module %s]"),
6370 die
->offset
, objfile
->name
);
6372 call_site
->per_cu
= cu
->per_cu
;
6374 for (child_die
= die
->child
;
6375 child_die
&& child_die
->tag
;
6376 child_die
= sibling_die (child_die
))
6378 struct dwarf2_locexpr_baton
*dlbaton
;
6379 struct call_site_parameter
*parameter
;
6381 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
6383 /* Already printed the complaint above. */
6387 gdb_assert (call_site
->parameter_count
< nparams
);
6388 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
6390 /* DW_AT_location specifies the register number. Value of the data
6391 assumed for the register is contained in DW_AT_GNU_call_site_value. */
6393 attr
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
6394 if (!attr
|| !attr_form_is_block (attr
))
6396 complaint (&symfile_complaints
,
6397 _("No DW_FORM_block* DW_AT_location for "
6398 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6399 child_die
->offset
, objfile
->name
);
6402 parameter
->dwarf_reg
= dwarf_block_to_dwarf_reg (DW_BLOCK (attr
)->data
,
6403 &DW_BLOCK (attr
)->data
[DW_BLOCK (attr
)->size
]);
6404 if (parameter
->dwarf_reg
== -1
6405 && !dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (attr
)->data
,
6406 &DW_BLOCK (attr
)->data
[DW_BLOCK (attr
)->size
],
6407 ¶meter
->fb_offset
))
6409 complaint (&symfile_complaints
,
6410 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
6411 "for DW_FORM_block* DW_AT_location for "
6412 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6413 child_die
->offset
, objfile
->name
);
6417 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
6418 if (!attr_form_is_block (attr
))
6420 complaint (&symfile_complaints
,
6421 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
6422 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6423 child_die
->offset
, objfile
->name
);
6426 parameter
->value
= DW_BLOCK (attr
)->data
;
6427 parameter
->value_size
= DW_BLOCK (attr
)->size
;
6429 /* Parameters are not pre-cleared by memset above. */
6430 parameter
->data_value
= NULL
;
6431 parameter
->data_value_size
= 0;
6432 call_site
->parameter_count
++;
6434 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
6437 if (!attr_form_is_block (attr
))
6438 complaint (&symfile_complaints
,
6439 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
6440 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6441 child_die
->offset
, objfile
->name
);
6444 parameter
->data_value
= DW_BLOCK (attr
)->data
;
6445 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
6451 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
6452 Return 1 if the attributes are present and valid, otherwise, return 0.
6453 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
6456 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
6457 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
6458 struct partial_symtab
*ranges_pst
)
6460 struct objfile
*objfile
= cu
->objfile
;
6461 struct comp_unit_head
*cu_header
= &cu
->header
;
6462 bfd
*obfd
= objfile
->obfd
;
6463 unsigned int addr_size
= cu_header
->addr_size
;
6464 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6465 /* Base address selection entry. */
6476 found_base
= cu
->base_known
;
6477 base
= cu
->base_address
;
6479 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
6480 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6482 complaint (&symfile_complaints
,
6483 _("Offset %d out of bounds for DW_AT_ranges attribute"),
6487 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6489 /* Read in the largest possible address. */
6490 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
6491 if ((marker
& mask
) == mask
)
6493 /* If we found the largest possible address, then
6494 read the base address. */
6495 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
6496 buffer
+= 2 * addr_size
;
6497 offset
+= 2 * addr_size
;
6503 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6507 CORE_ADDR range_beginning
, range_end
;
6509 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
6510 buffer
+= addr_size
;
6511 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
6512 buffer
+= addr_size
;
6513 offset
+= 2 * addr_size
;
6515 /* An end of list marker is a pair of zero addresses. */
6516 if (range_beginning
== 0 && range_end
== 0)
6517 /* Found the end of list entry. */
6520 /* Each base address selection entry is a pair of 2 values.
6521 The first is the largest possible address, the second is
6522 the base address. Check for a base address here. */
6523 if ((range_beginning
& mask
) == mask
)
6525 /* If we found the largest possible address, then
6526 read the base address. */
6527 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
6534 /* We have no valid base address for the ranges
6536 complaint (&symfile_complaints
,
6537 _("Invalid .debug_ranges data (no base address)"));
6541 if (range_beginning
> range_end
)
6543 /* Inverted range entries are invalid. */
6544 complaint (&symfile_complaints
,
6545 _("Invalid .debug_ranges data (inverted range)"));
6549 /* Empty range entries have no effect. */
6550 if (range_beginning
== range_end
)
6553 range_beginning
+= base
;
6556 if (ranges_pst
!= NULL
)
6557 addrmap_set_empty (objfile
->psymtabs_addrmap
,
6558 range_beginning
+ baseaddr
,
6559 range_end
- 1 + baseaddr
,
6562 /* FIXME: This is recording everything as a low-high
6563 segment of consecutive addresses. We should have a
6564 data structure for discontiguous block ranges
6568 low
= range_beginning
;
6574 if (range_beginning
< low
)
6575 low
= range_beginning
;
6576 if (range_end
> high
)
6582 /* If the first entry is an end-of-list marker, the range
6583 describes an empty scope, i.e. no instructions. */
6589 *high_return
= high
;
6593 /* Get low and high pc attributes from a die. Return 1 if the attributes
6594 are present and valid, otherwise, return 0. Return -1 if the range is
6595 discontinuous, i.e. derived from DW_AT_ranges information. */
6597 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
6598 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
6599 struct partial_symtab
*pst
)
6601 struct attribute
*attr
;
6606 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6609 high
= DW_ADDR (attr
);
6610 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6612 low
= DW_ADDR (attr
);
6614 /* Found high w/o low attribute. */
6617 /* Found consecutive range of addresses. */
6622 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6625 /* Value of the DW_AT_ranges attribute is the offset in the
6626 .debug_ranges section. */
6627 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
6629 /* Found discontinuous range of addresses. */
6634 /* read_partial_die has also the strict LOW < HIGH requirement. */
6638 /* When using the GNU linker, .gnu.linkonce. sections are used to
6639 eliminate duplicate copies of functions and vtables and such.
6640 The linker will arbitrarily choose one and discard the others.
6641 The AT_*_pc values for such functions refer to local labels in
6642 these sections. If the section from that file was discarded, the
6643 labels are not in the output, so the relocs get a value of 0.
6644 If this is a discarded function, mark the pc bounds as invalid,
6645 so that GDB will ignore it. */
6646 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
6655 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
6656 its low and high PC addresses. Do nothing if these addresses could not
6657 be determined. Otherwise, set LOWPC to the low address if it is smaller,
6658 and HIGHPC to the high address if greater than HIGHPC. */
6661 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
6662 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6663 struct dwarf2_cu
*cu
)
6665 CORE_ADDR low
, high
;
6666 struct die_info
*child
= die
->child
;
6668 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
6670 *lowpc
= min (*lowpc
, low
);
6671 *highpc
= max (*highpc
, high
);
6674 /* If the language does not allow nested subprograms (either inside
6675 subprograms or lexical blocks), we're done. */
6676 if (cu
->language
!= language_ada
)
6679 /* Check all the children of the given DIE. If it contains nested
6680 subprograms, then check their pc bounds. Likewise, we need to
6681 check lexical blocks as well, as they may also contain subprogram
6683 while (child
&& child
->tag
)
6685 if (child
->tag
== DW_TAG_subprogram
6686 || child
->tag
== DW_TAG_lexical_block
)
6687 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
6688 child
= sibling_die (child
);
6692 /* Get the low and high pc's represented by the scope DIE, and store
6693 them in *LOWPC and *HIGHPC. If the correct values can't be
6694 determined, set *LOWPC to -1 and *HIGHPC to 0. */
6697 get_scope_pc_bounds (struct die_info
*die
,
6698 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6699 struct dwarf2_cu
*cu
)
6701 CORE_ADDR best_low
= (CORE_ADDR
) -1;
6702 CORE_ADDR best_high
= (CORE_ADDR
) 0;
6703 CORE_ADDR current_low
, current_high
;
6705 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
6707 best_low
= current_low
;
6708 best_high
= current_high
;
6712 struct die_info
*child
= die
->child
;
6714 while (child
&& child
->tag
)
6716 switch (child
->tag
) {
6717 case DW_TAG_subprogram
:
6718 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
6720 case DW_TAG_namespace
:
6722 /* FIXME: carlton/2004-01-16: Should we do this for
6723 DW_TAG_class_type/DW_TAG_structure_type, too? I think
6724 that current GCC's always emit the DIEs corresponding
6725 to definitions of methods of classes as children of a
6726 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
6727 the DIEs giving the declarations, which could be
6728 anywhere). But I don't see any reason why the
6729 standards says that they have to be there. */
6730 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
6732 if (current_low
!= ((CORE_ADDR
) -1))
6734 best_low
= min (best_low
, current_low
);
6735 best_high
= max (best_high
, current_high
);
6743 child
= sibling_die (child
);
6748 *highpc
= best_high
;
6751 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
6754 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
6755 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
6757 struct objfile
*objfile
= cu
->objfile
;
6758 struct attribute
*attr
;
6760 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6763 CORE_ADDR high
= DW_ADDR (attr
);
6765 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6768 CORE_ADDR low
= DW_ADDR (attr
);
6770 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
6774 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6777 bfd
*obfd
= objfile
->obfd
;
6779 /* The value of the DW_AT_ranges attribute is the offset of the
6780 address range list in the .debug_ranges section. */
6781 unsigned long offset
= DW_UNSND (attr
);
6782 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6784 /* For some target architectures, but not others, the
6785 read_address function sign-extends the addresses it returns.
6786 To recognize base address selection entries, we need a
6788 unsigned int addr_size
= cu
->header
.addr_size
;
6789 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6791 /* The base address, to which the next pair is relative. Note
6792 that this 'base' is a DWARF concept: most entries in a range
6793 list are relative, to reduce the number of relocs against the
6794 debugging information. This is separate from this function's
6795 'baseaddr' argument, which GDB uses to relocate debugging
6796 information from a shared library based on the address at
6797 which the library was loaded. */
6798 CORE_ADDR base
= cu
->base_address
;
6799 int base_known
= cu
->base_known
;
6801 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
6802 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6804 complaint (&symfile_complaints
,
6805 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
6812 unsigned int bytes_read
;
6813 CORE_ADDR start
, end
;
6815 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6816 buffer
+= bytes_read
;
6817 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6818 buffer
+= bytes_read
;
6820 /* Did we find the end of the range list? */
6821 if (start
== 0 && end
== 0)
6824 /* Did we find a base address selection entry? */
6825 else if ((start
& base_select_mask
) == base_select_mask
)
6831 /* We found an ordinary address range. */
6836 complaint (&symfile_complaints
,
6837 _("Invalid .debug_ranges data "
6838 "(no base address)"));
6844 /* Inverted range entries are invalid. */
6845 complaint (&symfile_complaints
,
6846 _("Invalid .debug_ranges data "
6847 "(inverted range)"));
6851 /* Empty range entries have no effect. */
6855 record_block_range (block
,
6856 baseaddr
+ base
+ start
,
6857 baseaddr
+ base
+ end
- 1);
6863 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
6864 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
6865 during 4.6.0 experimental. */
6868 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
6871 int major
, minor
, release
;
6874 if (cu
->producer
== NULL
)
6876 /* For unknown compilers expect their behavior is DWARF version
6879 GCC started to support .debug_types sections by -gdwarf-4 since
6880 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
6881 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
6882 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
6883 interpreted incorrectly by GDB now - GCC PR debug/48229. */
6888 if (cu
->checked_producer
)
6889 return cu
->producer_is_gxx_lt_4_6
;
6891 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
6893 if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) != 0)
6895 /* For non-GCC compilers expect their behavior is DWARF version
6900 cs
= &cu
->producer
[strlen ("GNU ")];
6901 while (*cs
&& !isdigit (*cs
))
6903 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
6905 /* Not recognized as GCC. */
6908 result
= major
< 4 || (major
== 4 && minor
< 6);
6911 cu
->checked_producer
= 1;
6912 cu
->producer_is_gxx_lt_4_6
= result
;
6917 /* Return the default accessibility type if it is not overriden by
6918 DW_AT_accessibility. */
6920 static enum dwarf_access_attribute
6921 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
6923 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
6925 /* The default DWARF 2 accessibility for members is public, the default
6926 accessibility for inheritance is private. */
6928 if (die
->tag
!= DW_TAG_inheritance
)
6929 return DW_ACCESS_public
;
6931 return DW_ACCESS_private
;
6935 /* DWARF 3+ defines the default accessibility a different way. The same
6936 rules apply now for DW_TAG_inheritance as for the members and it only
6937 depends on the container kind. */
6939 if (die
->parent
->tag
== DW_TAG_class_type
)
6940 return DW_ACCESS_private
;
6942 return DW_ACCESS_public
;
6946 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
6947 offset. If the attribute was not found return 0, otherwise return
6948 1. If it was found but could not properly be handled, set *OFFSET
6952 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
6955 struct attribute
*attr
;
6957 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6962 /* Note that we do not check for a section offset first here.
6963 This is because DW_AT_data_member_location is new in DWARF 4,
6964 so if we see it, we can assume that a constant form is really
6965 a constant and not a section offset. */
6966 if (attr_form_is_constant (attr
))
6967 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
6968 else if (attr_form_is_section_offset (attr
))
6969 dwarf2_complex_location_expr_complaint ();
6970 else if (attr_form_is_block (attr
))
6971 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6973 dwarf2_complex_location_expr_complaint ();
6981 /* Add an aggregate field to the field list. */
6984 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
6985 struct dwarf2_cu
*cu
)
6987 struct objfile
*objfile
= cu
->objfile
;
6988 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6989 struct nextfield
*new_field
;
6990 struct attribute
*attr
;
6992 char *fieldname
= "";
6994 /* Allocate a new field list entry and link it in. */
6995 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
6996 make_cleanup (xfree
, new_field
);
6997 memset (new_field
, 0, sizeof (struct nextfield
));
6999 if (die
->tag
== DW_TAG_inheritance
)
7001 new_field
->next
= fip
->baseclasses
;
7002 fip
->baseclasses
= new_field
;
7006 new_field
->next
= fip
->fields
;
7007 fip
->fields
= new_field
;
7011 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
7013 new_field
->accessibility
= DW_UNSND (attr
);
7015 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
7016 if (new_field
->accessibility
!= DW_ACCESS_public
)
7017 fip
->non_public_fields
= 1;
7019 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
7021 new_field
->virtuality
= DW_UNSND (attr
);
7023 new_field
->virtuality
= DW_VIRTUALITY_none
;
7025 fp
= &new_field
->field
;
7027 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
7031 /* Data member other than a C++ static data member. */
7033 /* Get type of field. */
7034 fp
->type
= die_type (die
, cu
);
7036 SET_FIELD_BITPOS (*fp
, 0);
7038 /* Get bit size of field (zero if none). */
7039 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
7042 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
7046 FIELD_BITSIZE (*fp
) = 0;
7049 /* Get bit offset of field. */
7050 if (handle_data_member_location (die
, cu
, &offset
))
7051 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
7052 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
7055 if (gdbarch_bits_big_endian (gdbarch
))
7057 /* For big endian bits, the DW_AT_bit_offset gives the
7058 additional bit offset from the MSB of the containing
7059 anonymous object to the MSB of the field. We don't
7060 have to do anything special since we don't need to
7061 know the size of the anonymous object. */
7062 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
7066 /* For little endian bits, compute the bit offset to the
7067 MSB of the anonymous object, subtract off the number of
7068 bits from the MSB of the field to the MSB of the
7069 object, and then subtract off the number of bits of
7070 the field itself. The result is the bit offset of
7071 the LSB of the field. */
7073 int bit_offset
= DW_UNSND (attr
);
7075 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7078 /* The size of the anonymous object containing
7079 the bit field is explicit, so use the
7080 indicated size (in bytes). */
7081 anonymous_size
= DW_UNSND (attr
);
7085 /* The size of the anonymous object containing
7086 the bit field must be inferred from the type
7087 attribute of the data member containing the
7089 anonymous_size
= TYPE_LENGTH (fp
->type
);
7091 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
7092 - bit_offset
- FIELD_BITSIZE (*fp
);
7096 /* Get name of field. */
7097 fieldname
= dwarf2_name (die
, cu
);
7098 if (fieldname
== NULL
)
7101 /* The name is already allocated along with this objfile, so we don't
7102 need to duplicate it for the type. */
7103 fp
->name
= fieldname
;
7105 /* Change accessibility for artificial fields (e.g. virtual table
7106 pointer or virtual base class pointer) to private. */
7107 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
7109 FIELD_ARTIFICIAL (*fp
) = 1;
7110 new_field
->accessibility
= DW_ACCESS_private
;
7111 fip
->non_public_fields
= 1;
7114 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
7116 /* C++ static member. */
7118 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
7119 is a declaration, but all versions of G++ as of this writing
7120 (so through at least 3.2.1) incorrectly generate
7121 DW_TAG_variable tags. */
7123 const char *physname
;
7125 /* Get name of field. */
7126 fieldname
= dwarf2_name (die
, cu
);
7127 if (fieldname
== NULL
)
7130 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7132 /* Only create a symbol if this is an external value.
7133 new_symbol checks this and puts the value in the global symbol
7134 table, which we want. If it is not external, new_symbol
7135 will try to put the value in cu->list_in_scope which is wrong. */
7136 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
7138 /* A static const member, not much different than an enum as far as
7139 we're concerned, except that we can support more types. */
7140 new_symbol (die
, NULL
, cu
);
7143 /* Get physical name. */
7144 physname
= dwarf2_physname (fieldname
, die
, cu
);
7146 /* The name is already allocated along with this objfile, so we don't
7147 need to duplicate it for the type. */
7148 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
7149 FIELD_TYPE (*fp
) = die_type (die
, cu
);
7150 FIELD_NAME (*fp
) = fieldname
;
7152 else if (die
->tag
== DW_TAG_inheritance
)
7156 /* C++ base class field. */
7157 if (handle_data_member_location (die
, cu
, &offset
))
7158 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
7159 FIELD_BITSIZE (*fp
) = 0;
7160 FIELD_TYPE (*fp
) = die_type (die
, cu
);
7161 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
7162 fip
->nbaseclasses
++;
7166 /* Add a typedef defined in the scope of the FIP's class. */
7169 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
7170 struct dwarf2_cu
*cu
)
7172 struct objfile
*objfile
= cu
->objfile
;
7173 struct typedef_field_list
*new_field
;
7174 struct attribute
*attr
;
7175 struct typedef_field
*fp
;
7176 char *fieldname
= "";
7178 /* Allocate a new field list entry and link it in. */
7179 new_field
= xzalloc (sizeof (*new_field
));
7180 make_cleanup (xfree
, new_field
);
7182 gdb_assert (die
->tag
== DW_TAG_typedef
);
7184 fp
= &new_field
->field
;
7186 /* Get name of field. */
7187 fp
->name
= dwarf2_name (die
, cu
);
7188 if (fp
->name
== NULL
)
7191 fp
->type
= read_type_die (die
, cu
);
7193 new_field
->next
= fip
->typedef_field_list
;
7194 fip
->typedef_field_list
= new_field
;
7195 fip
->typedef_field_list_count
++;
7198 /* Create the vector of fields, and attach it to the type. */
7201 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
7202 struct dwarf2_cu
*cu
)
7204 int nfields
= fip
->nfields
;
7206 /* Record the field count, allocate space for the array of fields,
7207 and create blank accessibility bitfields if necessary. */
7208 TYPE_NFIELDS (type
) = nfields
;
7209 TYPE_FIELDS (type
) = (struct field
*)
7210 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
7211 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
7213 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
7215 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7217 TYPE_FIELD_PRIVATE_BITS (type
) =
7218 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7219 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
7221 TYPE_FIELD_PROTECTED_BITS (type
) =
7222 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7223 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
7225 TYPE_FIELD_IGNORE_BITS (type
) =
7226 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7227 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
7230 /* If the type has baseclasses, allocate and clear a bit vector for
7231 TYPE_FIELD_VIRTUAL_BITS. */
7232 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
7234 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
7235 unsigned char *pointer
;
7237 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7238 pointer
= TYPE_ALLOC (type
, num_bytes
);
7239 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
7240 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
7241 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
7244 /* Copy the saved-up fields into the field vector. Start from the head of
7245 the list, adding to the tail of the field array, so that they end up in
7246 the same order in the array in which they were added to the list. */
7247 while (nfields
-- > 0)
7249 struct nextfield
*fieldp
;
7253 fieldp
= fip
->fields
;
7254 fip
->fields
= fieldp
->next
;
7258 fieldp
= fip
->baseclasses
;
7259 fip
->baseclasses
= fieldp
->next
;
7262 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
7263 switch (fieldp
->accessibility
)
7265 case DW_ACCESS_private
:
7266 if (cu
->language
!= language_ada
)
7267 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
7270 case DW_ACCESS_protected
:
7271 if (cu
->language
!= language_ada
)
7272 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
7275 case DW_ACCESS_public
:
7279 /* Unknown accessibility. Complain and treat it as public. */
7281 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
7282 fieldp
->accessibility
);
7286 if (nfields
< fip
->nbaseclasses
)
7288 switch (fieldp
->virtuality
)
7290 case DW_VIRTUALITY_virtual
:
7291 case DW_VIRTUALITY_pure_virtual
:
7292 if (cu
->language
== language_ada
)
7293 error (_("unexpected virtuality in component of Ada type"));
7294 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
7301 /* Add a member function to the proper fieldlist. */
7304 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
7305 struct type
*type
, struct dwarf2_cu
*cu
)
7307 struct objfile
*objfile
= cu
->objfile
;
7308 struct attribute
*attr
;
7309 struct fnfieldlist
*flp
;
7311 struct fn_field
*fnp
;
7313 struct nextfnfield
*new_fnfield
;
7314 struct type
*this_type
;
7315 enum dwarf_access_attribute accessibility
;
7317 if (cu
->language
== language_ada
)
7318 error (_("unexpected member function in Ada type"));
7320 /* Get name of member function. */
7321 fieldname
= dwarf2_name (die
, cu
);
7322 if (fieldname
== NULL
)
7325 /* Look up member function name in fieldlist. */
7326 for (i
= 0; i
< fip
->nfnfields
; i
++)
7328 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
7332 /* Create new list element if necessary. */
7333 if (i
< fip
->nfnfields
)
7334 flp
= &fip
->fnfieldlists
[i
];
7337 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7339 fip
->fnfieldlists
= (struct fnfieldlist
*)
7340 xrealloc (fip
->fnfieldlists
,
7341 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
7342 * sizeof (struct fnfieldlist
));
7343 if (fip
->nfnfields
== 0)
7344 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
7346 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
7347 flp
->name
= fieldname
;
7350 i
= fip
->nfnfields
++;
7353 /* Create a new member function field and chain it to the field list
7355 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
7356 make_cleanup (xfree
, new_fnfield
);
7357 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
7358 new_fnfield
->next
= flp
->head
;
7359 flp
->head
= new_fnfield
;
7362 /* Fill in the member function field info. */
7363 fnp
= &new_fnfield
->fnfield
;
7365 /* Delay processing of the physname until later. */
7366 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
7368 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
7373 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
7374 fnp
->physname
= physname
? physname
: "";
7377 fnp
->type
= alloc_type (objfile
);
7378 this_type
= read_type_die (die
, cu
);
7379 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
7381 int nparams
= TYPE_NFIELDS (this_type
);
7383 /* TYPE is the domain of this method, and THIS_TYPE is the type
7384 of the method itself (TYPE_CODE_METHOD). */
7385 smash_to_method_type (fnp
->type
, type
,
7386 TYPE_TARGET_TYPE (this_type
),
7387 TYPE_FIELDS (this_type
),
7388 TYPE_NFIELDS (this_type
),
7389 TYPE_VARARGS (this_type
));
7391 /* Handle static member functions.
7392 Dwarf2 has no clean way to discern C++ static and non-static
7393 member functions. G++ helps GDB by marking the first
7394 parameter for non-static member functions (which is the this
7395 pointer) as artificial. We obtain this information from
7396 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
7397 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
7398 fnp
->voffset
= VOFFSET_STATIC
;
7401 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
7402 dwarf2_full_name (fieldname
, die
, cu
));
7404 /* Get fcontext from DW_AT_containing_type if present. */
7405 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7406 fnp
->fcontext
= die_containing_type (die
, cu
);
7408 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
7409 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
7411 /* Get accessibility. */
7412 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
7414 accessibility
= DW_UNSND (attr
);
7416 accessibility
= dwarf2_default_access_attribute (die
, cu
);
7417 switch (accessibility
)
7419 case DW_ACCESS_private
:
7420 fnp
->is_private
= 1;
7422 case DW_ACCESS_protected
:
7423 fnp
->is_protected
= 1;
7427 /* Check for artificial methods. */
7428 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
7429 if (attr
&& DW_UNSND (attr
) != 0)
7430 fnp
->is_artificial
= 1;
7432 /* Get index in virtual function table if it is a virtual member
7433 function. For older versions of GCC, this is an offset in the
7434 appropriate virtual table, as specified by DW_AT_containing_type.
7435 For everyone else, it is an expression to be evaluated relative
7436 to the object address. */
7438 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
7441 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
7443 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
7445 /* Old-style GCC. */
7446 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
7448 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
7449 || (DW_BLOCK (attr
)->size
> 1
7450 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
7451 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
7453 struct dwarf_block blk
;
7456 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
7458 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
7459 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
7460 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
7461 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
7462 dwarf2_complex_location_expr_complaint ();
7464 fnp
->voffset
/= cu
->header
.addr_size
;
7468 dwarf2_complex_location_expr_complaint ();
7471 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
7473 else if (attr_form_is_section_offset (attr
))
7475 dwarf2_complex_location_expr_complaint ();
7479 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
7485 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
7486 if (attr
&& DW_UNSND (attr
))
7488 /* GCC does this, as of 2008-08-25; PR debug/37237. */
7489 complaint (&symfile_complaints
,
7490 _("Member function \"%s\" (offset %d) is virtual "
7491 "but the vtable offset is not specified"),
7492 fieldname
, die
->offset
);
7493 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7494 TYPE_CPLUS_DYNAMIC (type
) = 1;
7499 /* Create the vector of member function fields, and attach it to the type. */
7502 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
7503 struct dwarf2_cu
*cu
)
7505 struct fnfieldlist
*flp
;
7508 if (cu
->language
== language_ada
)
7509 error (_("unexpected member functions in Ada type"));
7511 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7512 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
7513 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
7515 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
7517 struct nextfnfield
*nfp
= flp
->head
;
7518 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
7521 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
7522 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
7523 fn_flp
->fn_fields
= (struct fn_field
*)
7524 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
7525 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
7526 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
7529 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
7532 /* Returns non-zero if NAME is the name of a vtable member in CU's
7533 language, zero otherwise. */
7535 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
7537 static const char vptr
[] = "_vptr";
7538 static const char vtable
[] = "vtable";
7540 /* Look for the C++ and Java forms of the vtable. */
7541 if ((cu
->language
== language_java
7542 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
7543 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
7544 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
7550 /* GCC outputs unnamed structures that are really pointers to member
7551 functions, with the ABI-specified layout. If TYPE describes
7552 such a structure, smash it into a member function type.
7554 GCC shouldn't do this; it should just output pointer to member DIEs.
7555 This is GCC PR debug/28767. */
7558 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
7560 struct type
*pfn_type
, *domain_type
, *new_type
;
7562 /* Check for a structure with no name and two children. */
7563 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
7566 /* Check for __pfn and __delta members. */
7567 if (TYPE_FIELD_NAME (type
, 0) == NULL
7568 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
7569 || TYPE_FIELD_NAME (type
, 1) == NULL
7570 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
7573 /* Find the type of the method. */
7574 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
7575 if (pfn_type
== NULL
7576 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
7577 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
7580 /* Look for the "this" argument. */
7581 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
7582 if (TYPE_NFIELDS (pfn_type
) == 0
7583 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
7584 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
7587 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
7588 new_type
= alloc_type (objfile
);
7589 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
7590 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
7591 TYPE_VARARGS (pfn_type
));
7592 smash_to_methodptr_type (type
, new_type
);
7595 /* Called when we find the DIE that starts a structure or union scope
7596 (definition) to create a type for the structure or union. Fill in
7597 the type's name and general properties; the members will not be
7598 processed until process_structure_type.
7600 NOTE: we need to call these functions regardless of whether or not the
7601 DIE has a DW_AT_name attribute, since it might be an anonymous
7602 structure or union. This gets the type entered into our set of
7605 However, if the structure is incomplete (an opaque struct/union)
7606 then suppress creating a symbol table entry for it since gdb only
7607 wants to find the one with the complete definition. Note that if
7608 it is complete, we just call new_symbol, which does it's own
7609 checking about whether the struct/union is anonymous or not (and
7610 suppresses creating a symbol table entry itself). */
7612 static struct type
*
7613 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7615 struct objfile
*objfile
= cu
->objfile
;
7617 struct attribute
*attr
;
7620 /* If the definition of this type lives in .debug_types, read that type.
7621 Don't follow DW_AT_specification though, that will take us back up
7622 the chain and we want to go down. */
7623 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7626 struct dwarf2_cu
*type_cu
= cu
;
7627 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7629 /* We could just recurse on read_structure_type, but we need to call
7630 get_die_type to ensure only one type for this DIE is created.
7631 This is important, for example, because for c++ classes we need
7632 TYPE_NAME set which is only done by new_symbol. Blech. */
7633 type
= read_type_die (type_die
, type_cu
);
7635 /* TYPE_CU may not be the same as CU.
7636 Ensure TYPE is recorded in CU's type_hash table. */
7637 return set_die_type (die
, type
, cu
);
7640 type
= alloc_type (objfile
);
7641 INIT_CPLUS_SPECIFIC (type
);
7643 name
= dwarf2_name (die
, cu
);
7646 if (cu
->language
== language_cplus
7647 || cu
->language
== language_java
)
7649 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
7651 /* dwarf2_full_name might have already finished building the DIE's
7652 type. If so, there is no need to continue. */
7653 if (get_die_type (die
, cu
) != NULL
)
7654 return get_die_type (die
, cu
);
7656 TYPE_TAG_NAME (type
) = full_name
;
7657 if (die
->tag
== DW_TAG_structure_type
7658 || die
->tag
== DW_TAG_class_type
)
7659 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7663 /* The name is already allocated along with this objfile, so
7664 we don't need to duplicate it for the type. */
7665 TYPE_TAG_NAME (type
) = (char *) name
;
7666 if (die
->tag
== DW_TAG_class_type
)
7667 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7671 if (die
->tag
== DW_TAG_structure_type
)
7673 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
7675 else if (die
->tag
== DW_TAG_union_type
)
7677 TYPE_CODE (type
) = TYPE_CODE_UNION
;
7681 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
7684 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
7685 TYPE_DECLARED_CLASS (type
) = 1;
7687 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7690 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7694 TYPE_LENGTH (type
) = 0;
7697 TYPE_STUB_SUPPORTED (type
) = 1;
7698 if (die_is_declaration (die
, cu
))
7699 TYPE_STUB (type
) = 1;
7700 else if (attr
== NULL
&& die
->child
== NULL
7701 && producer_is_realview (cu
->producer
))
7702 /* RealView does not output the required DW_AT_declaration
7703 on incomplete types. */
7704 TYPE_STUB (type
) = 1;
7706 /* We need to add the type field to the die immediately so we don't
7707 infinitely recurse when dealing with pointers to the structure
7708 type within the structure itself. */
7709 set_die_type (die
, type
, cu
);
7711 /* set_die_type should be already done. */
7712 set_descriptive_type (type
, die
, cu
);
7717 /* Finish creating a structure or union type, including filling in
7718 its members and creating a symbol for it. */
7721 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7723 struct objfile
*objfile
= cu
->objfile
;
7724 struct die_info
*child_die
= die
->child
;
7727 type
= get_die_type (die
, cu
);
7729 type
= read_structure_type (die
, cu
);
7731 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
7733 struct field_info fi
;
7734 struct die_info
*child_die
;
7735 VEC (symbolp
) *template_args
= NULL
;
7736 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
7738 memset (&fi
, 0, sizeof (struct field_info
));
7740 child_die
= die
->child
;
7742 while (child_die
&& child_die
->tag
)
7744 if (child_die
->tag
== DW_TAG_member
7745 || child_die
->tag
== DW_TAG_variable
)
7747 /* NOTE: carlton/2002-11-05: A C++ static data member
7748 should be a DW_TAG_member that is a declaration, but
7749 all versions of G++ as of this writing (so through at
7750 least 3.2.1) incorrectly generate DW_TAG_variable
7751 tags for them instead. */
7752 dwarf2_add_field (&fi
, child_die
, cu
);
7754 else if (child_die
->tag
== DW_TAG_subprogram
)
7756 /* C++ member function. */
7757 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
7759 else if (child_die
->tag
== DW_TAG_inheritance
)
7761 /* C++ base class field. */
7762 dwarf2_add_field (&fi
, child_die
, cu
);
7764 else if (child_die
->tag
== DW_TAG_typedef
)
7765 dwarf2_add_typedef (&fi
, child_die
, cu
);
7766 else if (child_die
->tag
== DW_TAG_template_type_param
7767 || child_die
->tag
== DW_TAG_template_value_param
)
7769 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
7772 VEC_safe_push (symbolp
, template_args
, arg
);
7775 child_die
= sibling_die (child_die
);
7778 /* Attach template arguments to type. */
7779 if (! VEC_empty (symbolp
, template_args
))
7781 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7782 TYPE_N_TEMPLATE_ARGUMENTS (type
)
7783 = VEC_length (symbolp
, template_args
);
7784 TYPE_TEMPLATE_ARGUMENTS (type
)
7785 = obstack_alloc (&objfile
->objfile_obstack
,
7786 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7787 * sizeof (struct symbol
*)));
7788 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
7789 VEC_address (symbolp
, template_args
),
7790 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7791 * sizeof (struct symbol
*)));
7792 VEC_free (symbolp
, template_args
);
7795 /* Attach fields and member functions to the type. */
7797 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
7800 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
7802 /* Get the type which refers to the base class (possibly this
7803 class itself) which contains the vtable pointer for the current
7804 class from the DW_AT_containing_type attribute. This use of
7805 DW_AT_containing_type is a GNU extension. */
7807 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7809 struct type
*t
= die_containing_type (die
, cu
);
7811 TYPE_VPTR_BASETYPE (type
) = t
;
7816 /* Our own class provides vtbl ptr. */
7817 for (i
= TYPE_NFIELDS (t
) - 1;
7818 i
>= TYPE_N_BASECLASSES (t
);
7821 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
7823 if (is_vtable_name (fieldname
, cu
))
7825 TYPE_VPTR_FIELDNO (type
) = i
;
7830 /* Complain if virtual function table field not found. */
7831 if (i
< TYPE_N_BASECLASSES (t
))
7832 complaint (&symfile_complaints
,
7833 _("virtual function table pointer "
7834 "not found when defining class '%s'"),
7835 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
7840 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
7843 else if (cu
->producer
7844 && strncmp (cu
->producer
,
7845 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
7847 /* The IBM XLC compiler does not provide direct indication
7848 of the containing type, but the vtable pointer is
7849 always named __vfp. */
7853 for (i
= TYPE_NFIELDS (type
) - 1;
7854 i
>= TYPE_N_BASECLASSES (type
);
7857 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
7859 TYPE_VPTR_FIELDNO (type
) = i
;
7860 TYPE_VPTR_BASETYPE (type
) = type
;
7867 /* Copy fi.typedef_field_list linked list elements content into the
7868 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
7869 if (fi
.typedef_field_list
)
7871 int i
= fi
.typedef_field_list_count
;
7873 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7874 TYPE_TYPEDEF_FIELD_ARRAY (type
)
7875 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
7876 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
7878 /* Reverse the list order to keep the debug info elements order. */
7881 struct typedef_field
*dest
, *src
;
7883 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
7884 src
= &fi
.typedef_field_list
->field
;
7885 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
7890 do_cleanups (back_to
);
7892 if (HAVE_CPLUS_STRUCT (type
))
7893 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
7896 quirk_gcc_member_function_pointer (type
, objfile
);
7898 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
7899 snapshots) has been known to create a die giving a declaration
7900 for a class that has, as a child, a die giving a definition for a
7901 nested class. So we have to process our children even if the
7902 current die is a declaration. Normally, of course, a declaration
7903 won't have any children at all. */
7905 while (child_die
!= NULL
&& child_die
->tag
)
7907 if (child_die
->tag
== DW_TAG_member
7908 || child_die
->tag
== DW_TAG_variable
7909 || child_die
->tag
== DW_TAG_inheritance
7910 || child_die
->tag
== DW_TAG_template_value_param
7911 || child_die
->tag
== DW_TAG_template_type_param
)
7916 process_die (child_die
, cu
);
7918 child_die
= sibling_die (child_die
);
7921 /* Do not consider external references. According to the DWARF standard,
7922 these DIEs are identified by the fact that they have no byte_size
7923 attribute, and a declaration attribute. */
7924 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
7925 || !die_is_declaration (die
, cu
))
7926 new_symbol (die
, type
, cu
);
7929 /* Given a DW_AT_enumeration_type die, set its type. We do not
7930 complete the type's fields yet, or create any symbols. */
7932 static struct type
*
7933 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7935 struct objfile
*objfile
= cu
->objfile
;
7937 struct attribute
*attr
;
7940 /* If the definition of this type lives in .debug_types, read that type.
7941 Don't follow DW_AT_specification though, that will take us back up
7942 the chain and we want to go down. */
7943 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7946 struct dwarf2_cu
*type_cu
= cu
;
7947 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7949 type
= read_type_die (type_die
, type_cu
);
7951 /* TYPE_CU may not be the same as CU.
7952 Ensure TYPE is recorded in CU's type_hash table. */
7953 return set_die_type (die
, type
, cu
);
7956 type
= alloc_type (objfile
);
7958 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
7959 name
= dwarf2_full_name (NULL
, die
, cu
);
7961 TYPE_TAG_NAME (type
) = (char *) name
;
7963 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7966 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7970 TYPE_LENGTH (type
) = 0;
7973 /* The enumeration DIE can be incomplete. In Ada, any type can be
7974 declared as private in the package spec, and then defined only
7975 inside the package body. Such types are known as Taft Amendment
7976 Types. When another package uses such a type, an incomplete DIE
7977 may be generated by the compiler. */
7978 if (die_is_declaration (die
, cu
))
7979 TYPE_STUB (type
) = 1;
7981 return set_die_type (die
, type
, cu
);
7984 /* Given a pointer to a die which begins an enumeration, process all
7985 the dies that define the members of the enumeration, and create the
7986 symbol for the enumeration type.
7988 NOTE: We reverse the order of the element list. */
7991 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7993 struct type
*this_type
;
7995 this_type
= get_die_type (die
, cu
);
7996 if (this_type
== NULL
)
7997 this_type
= read_enumeration_type (die
, cu
);
7999 if (die
->child
!= NULL
)
8001 struct die_info
*child_die
;
8003 struct field
*fields
= NULL
;
8005 int unsigned_enum
= 1;
8010 child_die
= die
->child
;
8011 while (child_die
&& child_die
->tag
)
8013 if (child_die
->tag
!= DW_TAG_enumerator
)
8015 process_die (child_die
, cu
);
8019 name
= dwarf2_name (child_die
, cu
);
8022 sym
= new_symbol (child_die
, this_type
, cu
);
8023 if (SYMBOL_VALUE (sym
) < 0)
8028 else if ((mask
& SYMBOL_VALUE (sym
)) != 0)
8031 mask
|= SYMBOL_VALUE (sym
);
8033 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
8035 fields
= (struct field
*)
8037 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
8038 * sizeof (struct field
));
8041 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
8042 FIELD_TYPE (fields
[num_fields
]) = NULL
;
8043 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
8044 FIELD_BITSIZE (fields
[num_fields
]) = 0;
8050 child_die
= sibling_die (child_die
);
8055 TYPE_NFIELDS (this_type
) = num_fields
;
8056 TYPE_FIELDS (this_type
) = (struct field
*)
8057 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
8058 memcpy (TYPE_FIELDS (this_type
), fields
,
8059 sizeof (struct field
) * num_fields
);
8063 TYPE_UNSIGNED (this_type
) = 1;
8065 TYPE_FLAG_ENUM (this_type
) = 1;
8068 /* If we are reading an enum from a .debug_types unit, and the enum
8069 is a declaration, and the enum is not the signatured type in the
8070 unit, then we do not want to add a symbol for it. Adding a
8071 symbol would in some cases obscure the true definition of the
8072 enum, giving users an incomplete type when the definition is
8073 actually available. Note that we do not want to do this for all
8074 enums which are just declarations, because C++0x allows forward
8075 enum declarations. */
8076 if (cu
->per_cu
->debug_types_section
8077 && die_is_declaration (die
, cu
))
8079 struct signatured_type
*type_sig
;
8082 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
8083 cu
->per_cu
->debug_types_section
,
8084 cu
->per_cu
->offset
);
8085 if (type_sig
->per_cu
.offset
+ type_sig
->type_offset
8090 new_symbol (die
, this_type
, cu
);
8093 /* Extract all information from a DW_TAG_array_type DIE and put it in
8094 the DIE's type field. For now, this only handles one dimensional
8097 static struct type
*
8098 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8100 struct objfile
*objfile
= cu
->objfile
;
8101 struct die_info
*child_die
;
8103 struct type
*element_type
, *range_type
, *index_type
;
8104 struct type
**range_types
= NULL
;
8105 struct attribute
*attr
;
8107 struct cleanup
*back_to
;
8110 element_type
= die_type (die
, cu
);
8112 /* The die_type call above may have already set the type for this DIE. */
8113 type
= get_die_type (die
, cu
);
8117 /* Irix 6.2 native cc creates array types without children for
8118 arrays with unspecified length. */
8119 if (die
->child
== NULL
)
8121 index_type
= objfile_type (objfile
)->builtin_int
;
8122 range_type
= create_range_type (NULL
, index_type
, 0, -1);
8123 type
= create_array_type (NULL
, element_type
, range_type
);
8124 return set_die_type (die
, type
, cu
);
8127 back_to
= make_cleanup (null_cleanup
, NULL
);
8128 child_die
= die
->child
;
8129 while (child_die
&& child_die
->tag
)
8131 if (child_die
->tag
== DW_TAG_subrange_type
)
8133 struct type
*child_type
= read_type_die (child_die
, cu
);
8135 if (child_type
!= NULL
)
8137 /* The range type was succesfully read. Save it for the
8138 array type creation. */
8139 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
8141 range_types
= (struct type
**)
8142 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
8143 * sizeof (struct type
*));
8145 make_cleanup (free_current_contents
, &range_types
);
8147 range_types
[ndim
++] = child_type
;
8150 child_die
= sibling_die (child_die
);
8153 /* Dwarf2 dimensions are output from left to right, create the
8154 necessary array types in backwards order. */
8156 type
= element_type
;
8158 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
8163 type
= create_array_type (NULL
, type
, range_types
[i
++]);
8168 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
8171 /* Understand Dwarf2 support for vector types (like they occur on
8172 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
8173 array type. This is not part of the Dwarf2/3 standard yet, but a
8174 custom vendor extension. The main difference between a regular
8175 array and the vector variant is that vectors are passed by value
8177 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
8179 make_vector_type (type
);
8181 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
8182 implementation may choose to implement triple vectors using this
8184 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8187 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
8188 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8190 complaint (&symfile_complaints
,
8191 _("DW_AT_byte_size for array type smaller "
8192 "than the total size of elements"));
8195 name
= dwarf2_name (die
, cu
);
8197 TYPE_NAME (type
) = name
;
8199 /* Install the type in the die. */
8200 set_die_type (die
, type
, cu
);
8202 /* set_die_type should be already done. */
8203 set_descriptive_type (type
, die
, cu
);
8205 do_cleanups (back_to
);
8210 static enum dwarf_array_dim_ordering
8211 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
8213 struct attribute
*attr
;
8215 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
8217 if (attr
) return DW_SND (attr
);
8219 /* GNU F77 is a special case, as at 08/2004 array type info is the
8220 opposite order to the dwarf2 specification, but data is still
8221 laid out as per normal fortran.
8223 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
8224 version checking. */
8226 if (cu
->language
== language_fortran
8227 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
8229 return DW_ORD_row_major
;
8232 switch (cu
->language_defn
->la_array_ordering
)
8234 case array_column_major
:
8235 return DW_ORD_col_major
;
8236 case array_row_major
:
8238 return DW_ORD_row_major
;
8242 /* Extract all information from a DW_TAG_set_type DIE and put it in
8243 the DIE's type field. */
8245 static struct type
*
8246 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8248 struct type
*domain_type
, *set_type
;
8249 struct attribute
*attr
;
8251 domain_type
= die_type (die
, cu
);
8253 /* The die_type call above may have already set the type for this DIE. */
8254 set_type
= get_die_type (die
, cu
);
8258 set_type
= create_set_type (NULL
, domain_type
);
8260 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8262 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
8264 return set_die_type (die
, set_type
, cu
);
8267 /* First cut: install each common block member as a global variable. */
8270 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
8272 struct die_info
*child_die
;
8273 struct attribute
*attr
;
8275 CORE_ADDR base
= (CORE_ADDR
) 0;
8277 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
8280 /* Support the .debug_loc offsets. */
8281 if (attr_form_is_block (attr
))
8283 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
8285 else if (attr_form_is_section_offset (attr
))
8287 dwarf2_complex_location_expr_complaint ();
8291 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
8292 "common block member");
8295 if (die
->child
!= NULL
)
8297 child_die
= die
->child
;
8298 while (child_die
&& child_die
->tag
)
8302 sym
= new_symbol (child_die
, NULL
, cu
);
8304 && handle_data_member_location (child_die
, cu
, &offset
))
8306 SYMBOL_VALUE_ADDRESS (sym
) = base
+ offset
;
8307 add_symbol_to_list (sym
, &global_symbols
);
8309 child_die
= sibling_die (child_die
);
8314 /* Create a type for a C++ namespace. */
8316 static struct type
*
8317 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8319 struct objfile
*objfile
= cu
->objfile
;
8320 const char *previous_prefix
, *name
;
8324 /* For extensions, reuse the type of the original namespace. */
8325 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
8327 struct die_info
*ext_die
;
8328 struct dwarf2_cu
*ext_cu
= cu
;
8330 ext_die
= dwarf2_extension (die
, &ext_cu
);
8331 type
= read_type_die (ext_die
, ext_cu
);
8333 /* EXT_CU may not be the same as CU.
8334 Ensure TYPE is recorded in CU's type_hash table. */
8335 return set_die_type (die
, type
, cu
);
8338 name
= namespace_name (die
, &is_anonymous
, cu
);
8340 /* Now build the name of the current namespace. */
8342 previous_prefix
= determine_prefix (die
, cu
);
8343 if (previous_prefix
[0] != '\0')
8344 name
= typename_concat (&objfile
->objfile_obstack
,
8345 previous_prefix
, name
, 0, cu
);
8347 /* Create the type. */
8348 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
8350 TYPE_NAME (type
) = (char *) name
;
8351 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8353 return set_die_type (die
, type
, cu
);
8356 /* Read a C++ namespace. */
8359 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
8361 struct objfile
*objfile
= cu
->objfile
;
8364 /* Add a symbol associated to this if we haven't seen the namespace
8365 before. Also, add a using directive if it's an anonymous
8368 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
8372 type
= read_type_die (die
, cu
);
8373 new_symbol (die
, type
, cu
);
8375 namespace_name (die
, &is_anonymous
, cu
);
8378 const char *previous_prefix
= determine_prefix (die
, cu
);
8380 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
8381 NULL
, NULL
, &objfile
->objfile_obstack
);
8385 if (die
->child
!= NULL
)
8387 struct die_info
*child_die
= die
->child
;
8389 while (child_die
&& child_die
->tag
)
8391 process_die (child_die
, cu
);
8392 child_die
= sibling_die (child_die
);
8397 /* Read a Fortran module as type. This DIE can be only a declaration used for
8398 imported module. Still we need that type as local Fortran "use ... only"
8399 declaration imports depend on the created type in determine_prefix. */
8401 static struct type
*
8402 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8404 struct objfile
*objfile
= cu
->objfile
;
8408 module_name
= dwarf2_name (die
, cu
);
8410 complaint (&symfile_complaints
,
8411 _("DW_TAG_module has no name, offset 0x%x"),
8413 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
8415 /* determine_prefix uses TYPE_TAG_NAME. */
8416 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8418 return set_die_type (die
, type
, cu
);
8421 /* Read a Fortran module. */
8424 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
8426 struct die_info
*child_die
= die
->child
;
8428 while (child_die
&& child_die
->tag
)
8430 process_die (child_die
, cu
);
8431 child_die
= sibling_die (child_die
);
8435 /* Return the name of the namespace represented by DIE. Set
8436 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
8440 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
8442 struct die_info
*current_die
;
8443 const char *name
= NULL
;
8445 /* Loop through the extensions until we find a name. */
8447 for (current_die
= die
;
8448 current_die
!= NULL
;
8449 current_die
= dwarf2_extension (die
, &cu
))
8451 name
= dwarf2_name (current_die
, cu
);
8456 /* Is it an anonymous namespace? */
8458 *is_anonymous
= (name
== NULL
);
8460 name
= CP_ANONYMOUS_NAMESPACE_STR
;
8465 /* Extract all information from a DW_TAG_pointer_type DIE and add to
8466 the user defined type vector. */
8468 static struct type
*
8469 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8471 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
8472 struct comp_unit_head
*cu_header
= &cu
->header
;
8474 struct attribute
*attr_byte_size
;
8475 struct attribute
*attr_address_class
;
8476 int byte_size
, addr_class
;
8477 struct type
*target_type
;
8479 target_type
= die_type (die
, cu
);
8481 /* The die_type call above may have already set the type for this DIE. */
8482 type
= get_die_type (die
, cu
);
8486 type
= lookup_pointer_type (target_type
);
8488 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8490 byte_size
= DW_UNSND (attr_byte_size
);
8492 byte_size
= cu_header
->addr_size
;
8494 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
8495 if (attr_address_class
)
8496 addr_class
= DW_UNSND (attr_address_class
);
8498 addr_class
= DW_ADDR_none
;
8500 /* If the pointer size or address class is different than the
8501 default, create a type variant marked as such and set the
8502 length accordingly. */
8503 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
8505 if (gdbarch_address_class_type_flags_p (gdbarch
))
8509 type_flags
= gdbarch_address_class_type_flags
8510 (gdbarch
, byte_size
, addr_class
);
8511 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
8513 type
= make_type_with_address_space (type
, type_flags
);
8515 else if (TYPE_LENGTH (type
) != byte_size
)
8517 complaint (&symfile_complaints
,
8518 _("invalid pointer size %d"), byte_size
);
8522 /* Should we also complain about unhandled address classes? */
8526 TYPE_LENGTH (type
) = byte_size
;
8527 return set_die_type (die
, type
, cu
);
8530 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
8531 the user defined type vector. */
8533 static struct type
*
8534 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8537 struct type
*to_type
;
8538 struct type
*domain
;
8540 to_type
= die_type (die
, cu
);
8541 domain
= die_containing_type (die
, cu
);
8543 /* The calls above may have already set the type for this DIE. */
8544 type
= get_die_type (die
, cu
);
8548 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
8549 type
= lookup_methodptr_type (to_type
);
8551 type
= lookup_memberptr_type (to_type
, domain
);
8553 return set_die_type (die
, type
, cu
);
8556 /* Extract all information from a DW_TAG_reference_type DIE and add to
8557 the user defined type vector. */
8559 static struct type
*
8560 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8562 struct comp_unit_head
*cu_header
= &cu
->header
;
8563 struct type
*type
, *target_type
;
8564 struct attribute
*attr
;
8566 target_type
= die_type (die
, cu
);
8568 /* The die_type call above may have already set the type for this DIE. */
8569 type
= get_die_type (die
, cu
);
8573 type
= lookup_reference_type (target_type
);
8574 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8577 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8581 TYPE_LENGTH (type
) = cu_header
->addr_size
;
8583 return set_die_type (die
, type
, cu
);
8586 static struct type
*
8587 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8589 struct type
*base_type
, *cv_type
;
8591 base_type
= die_type (die
, cu
);
8593 /* The die_type call above may have already set the type for this DIE. */
8594 cv_type
= get_die_type (die
, cu
);
8598 /* In case the const qualifier is applied to an array type, the element type
8599 is so qualified, not the array type (section 6.7.3 of C99). */
8600 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
8602 struct type
*el_type
, *inner_array
;
8604 base_type
= copy_type (base_type
);
8605 inner_array
= base_type
;
8607 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
8609 TYPE_TARGET_TYPE (inner_array
) =
8610 copy_type (TYPE_TARGET_TYPE (inner_array
));
8611 inner_array
= TYPE_TARGET_TYPE (inner_array
);
8614 el_type
= TYPE_TARGET_TYPE (inner_array
);
8615 TYPE_TARGET_TYPE (inner_array
) =
8616 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
8618 return set_die_type (die
, base_type
, cu
);
8621 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
8622 return set_die_type (die
, cv_type
, cu
);
8625 static struct type
*
8626 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8628 struct type
*base_type
, *cv_type
;
8630 base_type
= die_type (die
, cu
);
8632 /* The die_type call above may have already set the type for this DIE. */
8633 cv_type
= get_die_type (die
, cu
);
8637 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
8638 return set_die_type (die
, cv_type
, cu
);
8641 /* Extract all information from a DW_TAG_string_type DIE and add to
8642 the user defined type vector. It isn't really a user defined type,
8643 but it behaves like one, with other DIE's using an AT_user_def_type
8644 attribute to reference it. */
8646 static struct type
*
8647 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8649 struct objfile
*objfile
= cu
->objfile
;
8650 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8651 struct type
*type
, *range_type
, *index_type
, *char_type
;
8652 struct attribute
*attr
;
8653 unsigned int length
;
8655 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
8658 length
= DW_UNSND (attr
);
8662 /* Check for the DW_AT_byte_size attribute. */
8663 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8666 length
= DW_UNSND (attr
);
8674 index_type
= objfile_type (objfile
)->builtin_int
;
8675 range_type
= create_range_type (NULL
, index_type
, 1, length
);
8676 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
8677 type
= create_string_type (NULL
, char_type
, range_type
);
8679 return set_die_type (die
, type
, cu
);
8682 /* Handle DIES due to C code like:
8686 int (*funcp)(int a, long l);
8690 ('funcp' generates a DW_TAG_subroutine_type DIE). */
8692 static struct type
*
8693 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8695 struct objfile
*objfile
= cu
->objfile
;
8696 struct type
*type
; /* Type that this function returns. */
8697 struct type
*ftype
; /* Function that returns above type. */
8698 struct attribute
*attr
;
8700 type
= die_type (die
, cu
);
8702 /* The die_type call above may have already set the type for this DIE. */
8703 ftype
= get_die_type (die
, cu
);
8707 ftype
= lookup_function_type (type
);
8709 /* All functions in C++, Pascal and Java have prototypes. */
8710 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
8711 if ((attr
&& (DW_UNSND (attr
) != 0))
8712 || cu
->language
== language_cplus
8713 || cu
->language
== language_java
8714 || cu
->language
== language_pascal
)
8715 TYPE_PROTOTYPED (ftype
) = 1;
8716 else if (producer_is_realview (cu
->producer
))
8717 /* RealView does not emit DW_AT_prototyped. We can not
8718 distinguish prototyped and unprototyped functions; default to
8719 prototyped, since that is more common in modern code (and
8720 RealView warns about unprototyped functions). */
8721 TYPE_PROTOTYPED (ftype
) = 1;
8723 /* Store the calling convention in the type if it's available in
8724 the subroutine die. Otherwise set the calling convention to
8725 the default value DW_CC_normal. */
8726 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
8728 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
8729 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
8730 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
8732 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
8734 /* We need to add the subroutine type to the die immediately so
8735 we don't infinitely recurse when dealing with parameters
8736 declared as the same subroutine type. */
8737 set_die_type (die
, ftype
, cu
);
8739 if (die
->child
!= NULL
)
8741 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
8742 struct die_info
*child_die
;
8743 int nparams
, iparams
;
8745 /* Count the number of parameters.
8746 FIXME: GDB currently ignores vararg functions, but knows about
8747 vararg member functions. */
8749 child_die
= die
->child
;
8750 while (child_die
&& child_die
->tag
)
8752 if (child_die
->tag
== DW_TAG_formal_parameter
)
8754 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
8755 TYPE_VARARGS (ftype
) = 1;
8756 child_die
= sibling_die (child_die
);
8759 /* Allocate storage for parameters and fill them in. */
8760 TYPE_NFIELDS (ftype
) = nparams
;
8761 TYPE_FIELDS (ftype
) = (struct field
*)
8762 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
8764 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
8765 even if we error out during the parameters reading below. */
8766 for (iparams
= 0; iparams
< nparams
; iparams
++)
8767 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
8770 child_die
= die
->child
;
8771 while (child_die
&& child_die
->tag
)
8773 if (child_die
->tag
== DW_TAG_formal_parameter
)
8775 struct type
*arg_type
;
8777 /* DWARF version 2 has no clean way to discern C++
8778 static and non-static member functions. G++ helps
8779 GDB by marking the first parameter for non-static
8780 member functions (which is the this pointer) as
8781 artificial. We pass this information to
8782 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
8784 DWARF version 3 added DW_AT_object_pointer, which GCC
8785 4.5 does not yet generate. */
8786 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
8788 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
8791 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
8793 /* GCC/43521: In java, the formal parameter
8794 "this" is sometimes not marked with DW_AT_artificial. */
8795 if (cu
->language
== language_java
)
8797 const char *name
= dwarf2_name (child_die
, cu
);
8799 if (name
&& !strcmp (name
, "this"))
8800 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
8803 arg_type
= die_type (child_die
, cu
);
8805 /* RealView does not mark THIS as const, which the testsuite
8806 expects. GCC marks THIS as const in method definitions,
8807 but not in the class specifications (GCC PR 43053). */
8808 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
8809 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
8812 struct dwarf2_cu
*arg_cu
= cu
;
8813 const char *name
= dwarf2_name (child_die
, cu
);
8815 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
8818 /* If the compiler emits this, use it. */
8819 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
8822 else if (name
&& strcmp (name
, "this") == 0)
8823 /* Function definitions will have the argument names. */
8825 else if (name
== NULL
&& iparams
== 0)
8826 /* Declarations may not have the names, so like
8827 elsewhere in GDB, assume an artificial first
8828 argument is "this". */
8832 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
8836 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
8839 child_die
= sibling_die (child_die
);
8846 static struct type
*
8847 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
8849 struct objfile
*objfile
= cu
->objfile
;
8850 const char *name
= NULL
;
8851 struct type
*this_type
, *target_type
;
8853 name
= dwarf2_full_name (NULL
, die
, cu
);
8854 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
8855 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
8856 TYPE_NAME (this_type
) = (char *) name
;
8857 set_die_type (die
, this_type
, cu
);
8858 target_type
= die_type (die
, cu
);
8859 if (target_type
!= this_type
)
8860 TYPE_TARGET_TYPE (this_type
) = target_type
;
8863 /* Self-referential typedefs are, it seems, not allowed by the DWARF
8864 spec and cause infinite loops in GDB. */
8865 complaint (&symfile_complaints
,
8866 _("Self-referential DW_TAG_typedef "
8867 "- DIE at 0x%x [in module %s]"),
8868 die
->offset
, objfile
->name
);
8869 TYPE_TARGET_TYPE (this_type
) = NULL
;
8874 /* Find a representation of a given base type and install
8875 it in the TYPE field of the die. */
8877 static struct type
*
8878 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8880 struct objfile
*objfile
= cu
->objfile
;
8882 struct attribute
*attr
;
8883 int encoding
= 0, size
= 0;
8885 enum type_code code
= TYPE_CODE_INT
;
8887 struct type
*target_type
= NULL
;
8889 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
8892 encoding
= DW_UNSND (attr
);
8894 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8897 size
= DW_UNSND (attr
);
8899 name
= dwarf2_name (die
, cu
);
8902 complaint (&symfile_complaints
,
8903 _("DW_AT_name missing from DW_TAG_base_type"));
8908 case DW_ATE_address
:
8909 /* Turn DW_ATE_address into a void * pointer. */
8910 code
= TYPE_CODE_PTR
;
8911 type_flags
|= TYPE_FLAG_UNSIGNED
;
8912 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
8914 case DW_ATE_boolean
:
8915 code
= TYPE_CODE_BOOL
;
8916 type_flags
|= TYPE_FLAG_UNSIGNED
;
8918 case DW_ATE_complex_float
:
8919 code
= TYPE_CODE_COMPLEX
;
8920 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
8922 case DW_ATE_decimal_float
:
8923 code
= TYPE_CODE_DECFLOAT
;
8926 code
= TYPE_CODE_FLT
;
8930 case DW_ATE_unsigned
:
8931 type_flags
|= TYPE_FLAG_UNSIGNED
;
8932 if (cu
->language
== language_fortran
8934 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
8935 code
= TYPE_CODE_CHAR
;
8937 case DW_ATE_signed_char
:
8938 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8939 || cu
->language
== language_pascal
8940 || cu
->language
== language_fortran
)
8941 code
= TYPE_CODE_CHAR
;
8943 case DW_ATE_unsigned_char
:
8944 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8945 || cu
->language
== language_pascal
8946 || cu
->language
== language_fortran
)
8947 code
= TYPE_CODE_CHAR
;
8948 type_flags
|= TYPE_FLAG_UNSIGNED
;
8951 /* We just treat this as an integer and then recognize the
8952 type by name elsewhere. */
8956 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
8957 dwarf_type_encoding_name (encoding
));
8961 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
8962 TYPE_NAME (type
) = name
;
8963 TYPE_TARGET_TYPE (type
) = target_type
;
8965 if (name
&& strcmp (name
, "char") == 0)
8966 TYPE_NOSIGN (type
) = 1;
8968 return set_die_type (die
, type
, cu
);
8971 /* Read the given DW_AT_subrange DIE. */
8973 static struct type
*
8974 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8976 struct type
*base_type
;
8977 struct type
*range_type
;
8978 struct attribute
*attr
;
8982 LONGEST negative_mask
;
8984 base_type
= die_type (die
, cu
);
8985 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
8986 check_typedef (base_type
);
8988 /* The die_type call above may have already set the type for this DIE. */
8989 range_type
= get_die_type (die
, cu
);
8993 if (cu
->language
== language_fortran
)
8995 /* FORTRAN implies a lower bound of 1, if not given. */
8999 /* FIXME: For variable sized arrays either of these could be
9000 a variable rather than a constant value. We'll allow it,
9001 but we don't know how to handle it. */
9002 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
9004 low
= dwarf2_get_attr_constant_value (attr
, 0);
9006 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
9009 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
9011 /* GCC encodes arrays with unspecified or dynamic length
9012 with a DW_FORM_block1 attribute or a reference attribute.
9013 FIXME: GDB does not yet know how to handle dynamic
9014 arrays properly, treat them as arrays with unspecified
9017 FIXME: jimb/2003-09-22: GDB does not really know
9018 how to handle arrays of unspecified length
9019 either; we just represent them as zero-length
9020 arrays. Choose an appropriate upper bound given
9021 the lower bound we've computed above. */
9025 high
= dwarf2_get_attr_constant_value (attr
, 1);
9029 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
9032 int count
= dwarf2_get_attr_constant_value (attr
, 1);
9033 high
= low
+ count
- 1;
9037 /* Unspecified array length. */
9042 /* Dwarf-2 specifications explicitly allows to create subrange types
9043 without specifying a base type.
9044 In that case, the base type must be set to the type of
9045 the lower bound, upper bound or count, in that order, if any of these
9046 three attributes references an object that has a type.
9047 If no base type is found, the Dwarf-2 specifications say that
9048 a signed integer type of size equal to the size of an address should
9050 For the following C code: `extern char gdb_int [];'
9051 GCC produces an empty range DIE.
9052 FIXME: muller/2010-05-28: Possible references to object for low bound,
9053 high bound or count are not yet handled by this code. */
9054 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
9056 struct objfile
*objfile
= cu
->objfile
;
9057 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9058 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
9059 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
9061 /* Test "int", "long int", and "long long int" objfile types,
9062 and select the first one having a size above or equal to the
9063 architecture address size. */
9064 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
9065 base_type
= int_type
;
9068 int_type
= objfile_type (objfile
)->builtin_long
;
9069 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
9070 base_type
= int_type
;
9073 int_type
= objfile_type (objfile
)->builtin_long_long
;
9074 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
9075 base_type
= int_type
;
9081 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
9082 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
9083 low
|= negative_mask
;
9084 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
9085 high
|= negative_mask
;
9087 range_type
= create_range_type (NULL
, base_type
, low
, high
);
9089 /* Mark arrays with dynamic length at least as an array of unspecified
9090 length. GDB could check the boundary but before it gets implemented at
9091 least allow accessing the array elements. */
9092 if (attr
&& attr_form_is_block (attr
))
9093 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
9095 /* Ada expects an empty array on no boundary attributes. */
9096 if (attr
== NULL
&& cu
->language
!= language_ada
)
9097 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
9099 name
= dwarf2_name (die
, cu
);
9101 TYPE_NAME (range_type
) = name
;
9103 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9105 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
9107 set_die_type (die
, range_type
, cu
);
9109 /* set_die_type should be already done. */
9110 set_descriptive_type (range_type
, die
, cu
);
9115 static struct type
*
9116 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9120 /* For now, we only support the C meaning of an unspecified type: void. */
9122 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
9123 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
9125 return set_die_type (die
, type
, cu
);
9128 /* Trivial hash function for die_info: the hash value of a DIE
9129 is its offset in .debug_info for this objfile. */
9132 die_hash (const void *item
)
9134 const struct die_info
*die
= item
;
9139 /* Trivial comparison function for die_info structures: two DIEs
9140 are equal if they have the same offset. */
9143 die_eq (const void *item_lhs
, const void *item_rhs
)
9145 const struct die_info
*die_lhs
= item_lhs
;
9146 const struct die_info
*die_rhs
= item_rhs
;
9148 return die_lhs
->offset
== die_rhs
->offset
;
9151 /* Read a whole compilation unit into a linked list of dies. */
9153 static struct die_info
*
9154 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
9156 struct die_reader_specs reader_specs
;
9157 int read_abbrevs
= 0;
9158 struct cleanup
*back_to
= NULL
;
9159 struct die_info
*die
;
9161 if (cu
->dwarf2_abbrevs
== NULL
)
9163 dwarf2_read_abbrevs (cu
);
9164 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
9168 gdb_assert (cu
->die_hash
== NULL
);
9170 = htab_create_alloc_ex (cu
->header
.length
/ 12,
9174 &cu
->comp_unit_obstack
,
9175 hashtab_obstack_allocate
,
9176 dummy_obstack_deallocate
);
9178 init_cu_die_reader (&reader_specs
, cu
);
9180 die
= read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
9183 do_cleanups (back_to
);
9188 /* Main entry point for reading a DIE and all children.
9189 Read the DIE and dump it if requested. */
9191 static struct die_info
*
9192 read_die_and_children (const struct die_reader_specs
*reader
,
9194 gdb_byte
**new_info_ptr
,
9195 struct die_info
*parent
)
9197 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
9198 new_info_ptr
, parent
);
9200 if (dwarf2_die_debug
)
9202 fprintf_unfiltered (gdb_stdlog
,
9203 "\nRead die from %s of %s:\n",
9204 (reader
->cu
->per_cu
->debug_types_section
9207 reader
->abfd
->filename
);
9208 dump_die (result
, dwarf2_die_debug
);
9214 /* Read a single die and all its descendents. Set the die's sibling
9215 field to NULL; set other fields in the die correctly, and set all
9216 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
9217 location of the info_ptr after reading all of those dies. PARENT
9218 is the parent of the die in question. */
9220 static struct die_info
*
9221 read_die_and_children_1 (const struct die_reader_specs
*reader
,
9223 gdb_byte
**new_info_ptr
,
9224 struct die_info
*parent
)
9226 struct die_info
*die
;
9230 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
9233 *new_info_ptr
= cur_ptr
;
9236 store_in_ref_table (die
, reader
->cu
);
9239 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
9243 *new_info_ptr
= cur_ptr
;
9246 die
->sibling
= NULL
;
9247 die
->parent
= parent
;
9251 /* Read a die, all of its descendents, and all of its siblings; set
9252 all of the fields of all of the dies correctly. Arguments are as
9253 in read_die_and_children. */
9255 static struct die_info
*
9256 read_die_and_siblings (const struct die_reader_specs
*reader
,
9258 gdb_byte
**new_info_ptr
,
9259 struct die_info
*parent
)
9261 struct die_info
*first_die
, *last_sibling
;
9265 first_die
= last_sibling
= NULL
;
9269 struct die_info
*die
9270 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
9274 *new_info_ptr
= cur_ptr
;
9281 last_sibling
->sibling
= die
;
9287 /* Read the die from the .debug_info section buffer. Set DIEP to
9288 point to a newly allocated die with its information, except for its
9289 child, sibling, and parent fields. Set HAS_CHILDREN to tell
9290 whether the die has children or not. */
9293 read_full_die (const struct die_reader_specs
*reader
,
9294 struct die_info
**diep
, gdb_byte
*info_ptr
,
9297 unsigned int abbrev_number
, bytes_read
, i
, offset
;
9298 struct abbrev_info
*abbrev
;
9299 struct die_info
*die
;
9300 struct dwarf2_cu
*cu
= reader
->cu
;
9301 bfd
*abfd
= reader
->abfd
;
9303 offset
= info_ptr
- reader
->buffer
;
9304 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9305 info_ptr
+= bytes_read
;
9313 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
9315 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
9317 bfd_get_filename (abfd
));
9319 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
9320 die
->offset
= offset
;
9321 die
->tag
= abbrev
->tag
;
9322 die
->abbrev
= abbrev_number
;
9324 die
->num_attrs
= abbrev
->num_attrs
;
9326 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9327 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
9328 abfd
, info_ptr
, cu
);
9331 *has_children
= abbrev
->has_children
;
9335 /* In DWARF version 2, the description of the debugging information is
9336 stored in a separate .debug_abbrev section. Before we read any
9337 dies from a section we read in all abbreviations and install them
9338 in a hash table. This function also sets flags in CU describing
9339 the data found in the abbrev table. */
9342 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
)
9344 bfd
*abfd
= cu
->objfile
->obfd
;
9345 struct comp_unit_head
*cu_header
= &cu
->header
;
9346 gdb_byte
*abbrev_ptr
;
9347 struct abbrev_info
*cur_abbrev
;
9348 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
9349 unsigned int abbrev_form
, hash_number
;
9350 struct attr_abbrev
*cur_attrs
;
9351 unsigned int allocated_attrs
;
9353 /* Initialize dwarf2 abbrevs. */
9354 obstack_init (&cu
->abbrev_obstack
);
9355 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
9357 * sizeof (struct abbrev_info
*)));
9358 memset (cu
->dwarf2_abbrevs
, 0,
9359 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
9361 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
9362 &dwarf2_per_objfile
->abbrev
);
9363 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
9364 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9365 abbrev_ptr
+= bytes_read
;
9367 allocated_attrs
= ATTR_ALLOC_CHUNK
;
9368 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
9370 /* Loop until we reach an abbrev number of 0. */
9371 while (abbrev_number
)
9373 cur_abbrev
= dwarf_alloc_abbrev (cu
);
9375 /* read in abbrev header */
9376 cur_abbrev
->number
= abbrev_number
;
9377 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9378 abbrev_ptr
+= bytes_read
;
9379 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
9382 /* now read in declarations */
9383 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9384 abbrev_ptr
+= bytes_read
;
9385 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9386 abbrev_ptr
+= bytes_read
;
9389 if (cur_abbrev
->num_attrs
== allocated_attrs
)
9391 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
9393 = xrealloc (cur_attrs
, (allocated_attrs
9394 * sizeof (struct attr_abbrev
)));
9397 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
9398 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
9399 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9400 abbrev_ptr
+= bytes_read
;
9401 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9402 abbrev_ptr
+= bytes_read
;
9405 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
9406 (cur_abbrev
->num_attrs
9407 * sizeof (struct attr_abbrev
)));
9408 memcpy (cur_abbrev
->attrs
, cur_attrs
,
9409 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
9411 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
9412 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
9413 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
9415 /* Get next abbreviation.
9416 Under Irix6 the abbreviations for a compilation unit are not
9417 always properly terminated with an abbrev number of 0.
9418 Exit loop if we encounter an abbreviation which we have
9419 already read (which means we are about to read the abbreviations
9420 for the next compile unit) or if the end of the abbreviation
9421 table is reached. */
9422 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
9423 >= dwarf2_per_objfile
->abbrev
.size
)
9425 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9426 abbrev_ptr
+= bytes_read
;
9427 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
9434 /* Release the memory used by the abbrev table for a compilation unit. */
9437 dwarf2_free_abbrev_table (void *ptr_to_cu
)
9439 struct dwarf2_cu
*cu
= ptr_to_cu
;
9441 obstack_free (&cu
->abbrev_obstack
, NULL
);
9442 cu
->dwarf2_abbrevs
= NULL
;
9445 /* Lookup an abbrev_info structure in the abbrev hash table. */
9447 static struct abbrev_info
*
9448 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
9450 unsigned int hash_number
;
9451 struct abbrev_info
*abbrev
;
9453 hash_number
= number
% ABBREV_HASH_SIZE
;
9454 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
9458 if (abbrev
->number
== number
)
9461 abbrev
= abbrev
->next
;
9466 /* Returns nonzero if TAG represents a type that we might generate a partial
9470 is_type_tag_for_partial (int tag
)
9475 /* Some types that would be reasonable to generate partial symbols for,
9476 that we don't at present. */
9477 case DW_TAG_array_type
:
9478 case DW_TAG_file_type
:
9479 case DW_TAG_ptr_to_member_type
:
9480 case DW_TAG_set_type
:
9481 case DW_TAG_string_type
:
9482 case DW_TAG_subroutine_type
:
9484 case DW_TAG_base_type
:
9485 case DW_TAG_class_type
:
9486 case DW_TAG_interface_type
:
9487 case DW_TAG_enumeration_type
:
9488 case DW_TAG_structure_type
:
9489 case DW_TAG_subrange_type
:
9490 case DW_TAG_typedef
:
9491 case DW_TAG_union_type
:
9498 /* Load all DIEs that are interesting for partial symbols into memory. */
9500 static struct partial_die_info
*
9501 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9502 int building_psymtab
, struct dwarf2_cu
*cu
)
9504 struct objfile
*objfile
= cu
->objfile
;
9505 struct partial_die_info
*part_die
;
9506 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
9507 struct abbrev_info
*abbrev
;
9508 unsigned int bytes_read
;
9509 unsigned int load_all
= 0;
9511 int nesting_level
= 1;
9516 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
9520 = htab_create_alloc_ex (cu
->header
.length
/ 12,
9524 &cu
->comp_unit_obstack
,
9525 hashtab_obstack_allocate
,
9526 dummy_obstack_deallocate
);
9528 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9529 sizeof (struct partial_die_info
));
9533 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
9535 /* A NULL abbrev means the end of a series of children. */
9538 if (--nesting_level
== 0)
9540 /* PART_DIE was probably the last thing allocated on the
9541 comp_unit_obstack, so we could call obstack_free
9542 here. We don't do that because the waste is small,
9543 and will be cleaned up when we're done with this
9544 compilation unit. This way, we're also more robust
9545 against other users of the comp_unit_obstack. */
9548 info_ptr
+= bytes_read
;
9549 last_die
= parent_die
;
9550 parent_die
= parent_die
->die_parent
;
9554 /* Check for template arguments. We never save these; if
9555 they're seen, we just mark the parent, and go on our way. */
9556 if (parent_die
!= NULL
9557 && cu
->language
== language_cplus
9558 && (abbrev
->tag
== DW_TAG_template_type_param
9559 || abbrev
->tag
== DW_TAG_template_value_param
))
9561 parent_die
->has_template_arguments
= 1;
9565 /* We don't need a partial DIE for the template argument. */
9566 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
,
9572 /* We only recurse into subprograms looking for template arguments.
9573 Skip their other children. */
9575 && cu
->language
== language_cplus
9576 && parent_die
!= NULL
9577 && parent_die
->tag
== DW_TAG_subprogram
)
9579 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
9583 /* Check whether this DIE is interesting enough to save. Normally
9584 we would not be interested in members here, but there may be
9585 later variables referencing them via DW_AT_specification (for
9588 && !is_type_tag_for_partial (abbrev
->tag
)
9589 && abbrev
->tag
!= DW_TAG_constant
9590 && abbrev
->tag
!= DW_TAG_enumerator
9591 && abbrev
->tag
!= DW_TAG_subprogram
9592 && abbrev
->tag
!= DW_TAG_lexical_block
9593 && abbrev
->tag
!= DW_TAG_variable
9594 && abbrev
->tag
!= DW_TAG_namespace
9595 && abbrev
->tag
!= DW_TAG_module
9596 && abbrev
->tag
!= DW_TAG_member
)
9598 /* Otherwise we skip to the next sibling, if any. */
9599 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
9603 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
9604 buffer
, info_ptr
, cu
);
9606 /* This two-pass algorithm for processing partial symbols has a
9607 high cost in cache pressure. Thus, handle some simple cases
9608 here which cover the majority of C partial symbols. DIEs
9609 which neither have specification tags in them, nor could have
9610 specification tags elsewhere pointing at them, can simply be
9611 processed and discarded.
9613 This segment is also optional; scan_partial_symbols and
9614 add_partial_symbol will handle these DIEs if we chain
9615 them in normally. When compilers which do not emit large
9616 quantities of duplicate debug information are more common,
9617 this code can probably be removed. */
9619 /* Any complete simple types at the top level (pretty much all
9620 of them, for a language without namespaces), can be processed
9622 if (parent_die
== NULL
9623 && part_die
->has_specification
== 0
9624 && part_die
->is_declaration
== 0
9625 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
9626 || part_die
->tag
== DW_TAG_base_type
9627 || part_die
->tag
== DW_TAG_subrange_type
))
9629 if (building_psymtab
&& part_die
->name
!= NULL
)
9630 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9631 VAR_DOMAIN
, LOC_TYPEDEF
,
9632 &objfile
->static_psymbols
,
9633 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
9634 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9638 /* The exception for DW_TAG_typedef with has_children above is
9639 a workaround of GCC PR debug/47510. In the case of this complaint
9640 type_name_no_tag_or_error will error on such types later.
9642 GDB skipped children of DW_TAG_typedef by the shortcut above and then
9643 it could not find the child DIEs referenced later, this is checked
9644 above. In correct DWARF DW_TAG_typedef should have no children. */
9646 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
9647 complaint (&symfile_complaints
,
9648 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
9649 "- DIE at 0x%x [in module %s]"),
9650 part_die
->offset
, objfile
->name
);
9652 /* If we're at the second level, and we're an enumerator, and
9653 our parent has no specification (meaning possibly lives in a
9654 namespace elsewhere), then we can add the partial symbol now
9655 instead of queueing it. */
9656 if (part_die
->tag
== DW_TAG_enumerator
9657 && parent_die
!= NULL
9658 && parent_die
->die_parent
== NULL
9659 && parent_die
->tag
== DW_TAG_enumeration_type
9660 && parent_die
->has_specification
== 0)
9662 if (part_die
->name
== NULL
)
9663 complaint (&symfile_complaints
,
9664 _("malformed enumerator DIE ignored"));
9665 else if (building_psymtab
)
9666 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9667 VAR_DOMAIN
, LOC_CONST
,
9668 (cu
->language
== language_cplus
9669 || cu
->language
== language_java
)
9670 ? &objfile
->global_psymbols
9671 : &objfile
->static_psymbols
,
9672 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
9674 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9678 /* We'll save this DIE so link it in. */
9679 part_die
->die_parent
= parent_die
;
9680 part_die
->die_sibling
= NULL
;
9681 part_die
->die_child
= NULL
;
9683 if (last_die
&& last_die
== parent_die
)
9684 last_die
->die_child
= part_die
;
9686 last_die
->die_sibling
= part_die
;
9688 last_die
= part_die
;
9690 if (first_die
== NULL
)
9691 first_die
= part_die
;
9693 /* Maybe add the DIE to the hash table. Not all DIEs that we
9694 find interesting need to be in the hash table, because we
9695 also have the parent/sibling/child chains; only those that we
9696 might refer to by offset later during partial symbol reading.
9698 For now this means things that might have be the target of a
9699 DW_AT_specification, DW_AT_abstract_origin, or
9700 DW_AT_extension. DW_AT_extension will refer only to
9701 namespaces; DW_AT_abstract_origin refers to functions (and
9702 many things under the function DIE, but we do not recurse
9703 into function DIEs during partial symbol reading) and
9704 possibly variables as well; DW_AT_specification refers to
9705 declarations. Declarations ought to have the DW_AT_declaration
9706 flag. It happens that GCC forgets to put it in sometimes, but
9707 only for functions, not for types.
9709 Adding more things than necessary to the hash table is harmless
9710 except for the performance cost. Adding too few will result in
9711 wasted time in find_partial_die, when we reread the compilation
9712 unit with load_all_dies set. */
9715 || abbrev
->tag
== DW_TAG_constant
9716 || abbrev
->tag
== DW_TAG_subprogram
9717 || abbrev
->tag
== DW_TAG_variable
9718 || abbrev
->tag
== DW_TAG_namespace
9719 || part_die
->is_declaration
)
9723 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
9724 part_die
->offset
, INSERT
);
9728 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9729 sizeof (struct partial_die_info
));
9731 /* For some DIEs we want to follow their children (if any). For C
9732 we have no reason to follow the children of structures; for other
9733 languages we have to, so that we can get at method physnames
9734 to infer fully qualified class names, for DW_AT_specification,
9735 and for C++ template arguments. For C++, we also look one level
9736 inside functions to find template arguments (if the name of the
9737 function does not already contain the template arguments).
9739 For Ada, we need to scan the children of subprograms and lexical
9740 blocks as well because Ada allows the definition of nested
9741 entities that could be interesting for the debugger, such as
9742 nested subprograms for instance. */
9743 if (last_die
->has_children
9745 || last_die
->tag
== DW_TAG_namespace
9746 || last_die
->tag
== DW_TAG_module
9747 || last_die
->tag
== DW_TAG_enumeration_type
9748 || (cu
->language
== language_cplus
9749 && last_die
->tag
== DW_TAG_subprogram
9750 && (last_die
->name
== NULL
9751 || strchr (last_die
->name
, '<') == NULL
))
9752 || (cu
->language
!= language_c
9753 && (last_die
->tag
== DW_TAG_class_type
9754 || last_die
->tag
== DW_TAG_interface_type
9755 || last_die
->tag
== DW_TAG_structure_type
9756 || last_die
->tag
== DW_TAG_union_type
))
9757 || (cu
->language
== language_ada
9758 && (last_die
->tag
== DW_TAG_subprogram
9759 || last_die
->tag
== DW_TAG_lexical_block
))))
9762 parent_die
= last_die
;
9766 /* Otherwise we skip to the next sibling, if any. */
9767 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
9769 /* Back to the top, do it again. */
9773 /* Read a minimal amount of information into the minimal die structure. */
9776 read_partial_die (struct partial_die_info
*part_die
,
9777 struct abbrev_info
*abbrev
,
9778 unsigned int abbrev_len
, bfd
*abfd
,
9779 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9780 struct dwarf2_cu
*cu
)
9782 struct objfile
*objfile
= cu
->objfile
;
9784 struct attribute attr
;
9785 int has_low_pc_attr
= 0;
9786 int has_high_pc_attr
= 0;
9788 memset (part_die
, 0, sizeof (struct partial_die_info
));
9790 part_die
->offset
= info_ptr
- buffer
;
9792 info_ptr
+= abbrev_len
;
9797 part_die
->tag
= abbrev
->tag
;
9798 part_die
->has_children
= abbrev
->has_children
;
9800 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9802 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
9804 /* Store the data if it is of an attribute we want to keep in a
9805 partial symbol table. */
9809 switch (part_die
->tag
)
9811 case DW_TAG_compile_unit
:
9812 case DW_TAG_type_unit
:
9813 /* Compilation units have a DW_AT_name that is a filename, not
9814 a source language identifier. */
9815 case DW_TAG_enumeration_type
:
9816 case DW_TAG_enumerator
:
9817 /* These tags always have simple identifiers already; no need
9818 to canonicalize them. */
9819 part_die
->name
= DW_STRING (&attr
);
9823 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
9824 &objfile
->objfile_obstack
);
9828 case DW_AT_linkage_name
:
9829 case DW_AT_MIPS_linkage_name
:
9830 /* Note that both forms of linkage name might appear. We
9831 assume they will be the same, and we only store the last
9833 if (cu
->language
== language_ada
)
9834 part_die
->name
= DW_STRING (&attr
);
9835 part_die
->linkage_name
= DW_STRING (&attr
);
9838 has_low_pc_attr
= 1;
9839 part_die
->lowpc
= DW_ADDR (&attr
);
9842 has_high_pc_attr
= 1;
9843 part_die
->highpc
= DW_ADDR (&attr
);
9845 case DW_AT_location
:
9846 /* Support the .debug_loc offsets. */
9847 if (attr_form_is_block (&attr
))
9849 part_die
->locdesc
= DW_BLOCK (&attr
);
9851 else if (attr_form_is_section_offset (&attr
))
9853 dwarf2_complex_location_expr_complaint ();
9857 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9858 "partial symbol information");
9861 case DW_AT_external
:
9862 part_die
->is_external
= DW_UNSND (&attr
);
9864 case DW_AT_declaration
:
9865 part_die
->is_declaration
= DW_UNSND (&attr
);
9868 part_die
->has_type
= 1;
9870 case DW_AT_abstract_origin
:
9871 case DW_AT_specification
:
9872 case DW_AT_extension
:
9873 part_die
->has_specification
= 1;
9874 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
9877 /* Ignore absolute siblings, they might point outside of
9878 the current compile unit. */
9879 if (attr
.form
== DW_FORM_ref_addr
)
9880 complaint (&symfile_complaints
,
9881 _("ignoring absolute DW_AT_sibling"));
9883 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
9885 case DW_AT_byte_size
:
9886 part_die
->has_byte_size
= 1;
9888 case DW_AT_calling_convention
:
9889 /* DWARF doesn't provide a way to identify a program's source-level
9890 entry point. DW_AT_calling_convention attributes are only meant
9891 to describe functions' calling conventions.
9893 However, because it's a necessary piece of information in
9894 Fortran, and because DW_CC_program is the only piece of debugging
9895 information whose definition refers to a 'main program' at all,
9896 several compilers have begun marking Fortran main programs with
9897 DW_CC_program --- even when those functions use the standard
9898 calling conventions.
9900 So until DWARF specifies a way to provide this information and
9901 compilers pick up the new representation, we'll support this
9903 if (DW_UNSND (&attr
) == DW_CC_program
9904 && cu
->language
== language_fortran
)
9906 set_main_name (part_die
->name
);
9908 /* As this DIE has a static linkage the name would be difficult
9909 to look up later. */
9910 language_of_main
= language_fortran
;
9914 if (DW_UNSND (&attr
) == DW_INL_inlined
9915 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
9916 part_die
->may_be_inlined
= 1;
9923 if (has_low_pc_attr
&& has_high_pc_attr
)
9925 /* When using the GNU linker, .gnu.linkonce. sections are used to
9926 eliminate duplicate copies of functions and vtables and such.
9927 The linker will arbitrarily choose one and discard the others.
9928 The AT_*_pc values for such functions refer to local labels in
9929 these sections. If the section from that file was discarded, the
9930 labels are not in the output, so the relocs get a value of 0.
9931 If this is a discarded function, mark the pc bounds as invalid,
9932 so that GDB will ignore it. */
9933 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
9935 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9937 complaint (&symfile_complaints
,
9938 _("DW_AT_low_pc %s is zero "
9939 "for DIE at 0x%x [in module %s]"),
9940 paddress (gdbarch
, part_die
->lowpc
),
9941 part_die
->offset
, objfile
->name
);
9943 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
9944 else if (part_die
->lowpc
>= part_die
->highpc
)
9946 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9948 complaint (&symfile_complaints
,
9949 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
9950 "for DIE at 0x%x [in module %s]"),
9951 paddress (gdbarch
, part_die
->lowpc
),
9952 paddress (gdbarch
, part_die
->highpc
),
9953 part_die
->offset
, objfile
->name
);
9956 part_die
->has_pc_info
= 1;
9962 /* Find a cached partial DIE at OFFSET in CU. */
9964 static struct partial_die_info
*
9965 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
9967 struct partial_die_info
*lookup_die
= NULL
;
9968 struct partial_die_info part_die
;
9970 part_die
.offset
= offset
;
9971 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
9976 /* Find a partial DIE at OFFSET, which may or may not be in CU,
9977 except in the case of .debug_types DIEs which do not reference
9978 outside their CU (they do however referencing other types via
9979 DW_FORM_ref_sig8). */
9981 static struct partial_die_info
*
9982 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
9984 struct objfile
*objfile
= cu
->objfile
;
9985 struct dwarf2_per_cu_data
*per_cu
= NULL
;
9986 struct partial_die_info
*pd
= NULL
;
9988 if (cu
->per_cu
->debug_types_section
)
9990 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9996 if (offset_in_cu_p (&cu
->header
, offset
))
9998 pd
= find_partial_die_in_comp_unit (offset
, cu
);
10003 per_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
10005 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
10006 load_partial_comp_unit (per_cu
);
10008 per_cu
->cu
->last_used
= 0;
10009 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
10011 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
10013 struct cleanup
*back_to
;
10014 struct partial_die_info comp_unit_die
;
10015 struct abbrev_info
*abbrev
;
10016 unsigned int bytes_read
;
10019 per_cu
->load_all_dies
= 1;
10021 /* Re-read the DIEs. */
10022 back_to
= make_cleanup (null_cleanup
, 0);
10023 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
10025 dwarf2_read_abbrevs (per_cu
->cu
);
10026 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
10028 info_ptr
= (dwarf2_per_objfile
->info
.buffer
10029 + per_cu
->cu
->header
.offset
10030 + per_cu
->cu
->header
.first_die_offset
);
10031 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
10032 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
10034 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
10036 if (comp_unit_die
.has_children
)
10037 load_partial_dies (objfile
->obfd
,
10038 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
10040 do_cleanups (back_to
);
10042 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
10048 internal_error (__FILE__
, __LINE__
,
10049 _("could not find partial DIE 0x%x "
10050 "in cache [from module %s]\n"),
10051 offset
, bfd_get_filename (objfile
->obfd
));
10055 /* See if we can figure out if the class lives in a namespace. We do
10056 this by looking for a member function; its demangled name will
10057 contain namespace info, if there is any. */
10060 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
10061 struct dwarf2_cu
*cu
)
10063 /* NOTE: carlton/2003-10-07: Getting the info this way changes
10064 what template types look like, because the demangler
10065 frequently doesn't give the same name as the debug info. We
10066 could fix this by only using the demangled name to get the
10067 prefix (but see comment in read_structure_type). */
10069 struct partial_die_info
*real_pdi
;
10070 struct partial_die_info
*child_pdi
;
10072 /* If this DIE (this DIE's specification, if any) has a parent, then
10073 we should not do this. We'll prepend the parent's fully qualified
10074 name when we create the partial symbol. */
10076 real_pdi
= struct_pdi
;
10077 while (real_pdi
->has_specification
)
10078 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
10080 if (real_pdi
->die_parent
!= NULL
)
10083 for (child_pdi
= struct_pdi
->die_child
;
10085 child_pdi
= child_pdi
->die_sibling
)
10087 if (child_pdi
->tag
== DW_TAG_subprogram
10088 && child_pdi
->linkage_name
!= NULL
)
10090 char *actual_class_name
10091 = language_class_name_from_physname (cu
->language_defn
,
10092 child_pdi
->linkage_name
);
10093 if (actual_class_name
!= NULL
)
10096 = obsavestring (actual_class_name
,
10097 strlen (actual_class_name
),
10098 &cu
->objfile
->objfile_obstack
);
10099 xfree (actual_class_name
);
10106 /* Adjust PART_DIE before generating a symbol for it. This function
10107 may set the is_external flag or change the DIE's name. */
10110 fixup_partial_die (struct partial_die_info
*part_die
,
10111 struct dwarf2_cu
*cu
)
10113 /* Once we've fixed up a die, there's no point in doing so again.
10114 This also avoids a memory leak if we were to call
10115 guess_partial_die_structure_name multiple times. */
10116 if (part_die
->fixup_called
)
10119 /* If we found a reference attribute and the DIE has no name, try
10120 to find a name in the referred to DIE. */
10122 if (part_die
->name
== NULL
&& part_die
->has_specification
)
10124 struct partial_die_info
*spec_die
;
10126 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
10128 fixup_partial_die (spec_die
, cu
);
10130 if (spec_die
->name
)
10132 part_die
->name
= spec_die
->name
;
10134 /* Copy DW_AT_external attribute if it is set. */
10135 if (spec_die
->is_external
)
10136 part_die
->is_external
= spec_die
->is_external
;
10140 /* Set default names for some unnamed DIEs. */
10142 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
10143 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
10145 /* If there is no parent die to provide a namespace, and there are
10146 children, see if we can determine the namespace from their linkage
10148 if (cu
->language
== language_cplus
10149 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
10150 && part_die
->die_parent
== NULL
10151 && part_die
->has_children
10152 && (part_die
->tag
== DW_TAG_class_type
10153 || part_die
->tag
== DW_TAG_structure_type
10154 || part_die
->tag
== DW_TAG_union_type
))
10155 guess_partial_die_structure_name (part_die
, cu
);
10157 /* GCC might emit a nameless struct or union that has a linkage
10158 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
10159 if (part_die
->name
== NULL
10160 && (part_die
->tag
== DW_TAG_class_type
10161 || part_die
->tag
== DW_TAG_interface_type
10162 || part_die
->tag
== DW_TAG_structure_type
10163 || part_die
->tag
== DW_TAG_union_type
)
10164 && part_die
->linkage_name
!= NULL
)
10168 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
10173 /* Strip any leading namespaces/classes, keep only the base name.
10174 DW_AT_name for named DIEs does not contain the prefixes. */
10175 base
= strrchr (demangled
, ':');
10176 if (base
&& base
> demangled
&& base
[-1] == ':')
10181 part_die
->name
= obsavestring (base
, strlen (base
),
10182 &cu
->objfile
->objfile_obstack
);
10187 part_die
->fixup_called
= 1;
10190 /* Read an attribute value described by an attribute form. */
10193 read_attribute_value (struct attribute
*attr
, unsigned form
,
10194 bfd
*abfd
, gdb_byte
*info_ptr
,
10195 struct dwarf2_cu
*cu
)
10197 struct comp_unit_head
*cu_header
= &cu
->header
;
10198 unsigned int bytes_read
;
10199 struct dwarf_block
*blk
;
10204 case DW_FORM_ref_addr
:
10205 if (cu
->header
.version
== 2)
10206 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
10208 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
,
10209 &cu
->header
, &bytes_read
);
10210 info_ptr
+= bytes_read
;
10213 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
10214 info_ptr
+= bytes_read
;
10216 case DW_FORM_block2
:
10217 blk
= dwarf_alloc_block (cu
);
10218 blk
->size
= read_2_bytes (abfd
, info_ptr
);
10220 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10221 info_ptr
+= blk
->size
;
10222 DW_BLOCK (attr
) = blk
;
10224 case DW_FORM_block4
:
10225 blk
= dwarf_alloc_block (cu
);
10226 blk
->size
= read_4_bytes (abfd
, info_ptr
);
10228 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10229 info_ptr
+= blk
->size
;
10230 DW_BLOCK (attr
) = blk
;
10232 case DW_FORM_data2
:
10233 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
10236 case DW_FORM_data4
:
10237 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
10240 case DW_FORM_data8
:
10241 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
10244 case DW_FORM_sec_offset
:
10245 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
10246 info_ptr
+= bytes_read
;
10248 case DW_FORM_string
:
10249 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
10250 DW_STRING_IS_CANONICAL (attr
) = 0;
10251 info_ptr
+= bytes_read
;
10254 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
10256 DW_STRING_IS_CANONICAL (attr
) = 0;
10257 info_ptr
+= bytes_read
;
10259 case DW_FORM_exprloc
:
10260 case DW_FORM_block
:
10261 blk
= dwarf_alloc_block (cu
);
10262 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10263 info_ptr
+= bytes_read
;
10264 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10265 info_ptr
+= blk
->size
;
10266 DW_BLOCK (attr
) = blk
;
10268 case DW_FORM_block1
:
10269 blk
= dwarf_alloc_block (cu
);
10270 blk
->size
= read_1_byte (abfd
, info_ptr
);
10272 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10273 info_ptr
+= blk
->size
;
10274 DW_BLOCK (attr
) = blk
;
10276 case DW_FORM_data1
:
10277 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
10281 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
10284 case DW_FORM_flag_present
:
10285 DW_UNSND (attr
) = 1;
10287 case DW_FORM_sdata
:
10288 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
10289 info_ptr
+= bytes_read
;
10291 case DW_FORM_udata
:
10292 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10293 info_ptr
+= bytes_read
;
10296 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
10300 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
10304 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
10308 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
10311 case DW_FORM_ref_sig8
:
10312 /* Convert the signature to something we can record in DW_UNSND
10314 NOTE: This is NULL if the type wasn't found. */
10315 DW_SIGNATURED_TYPE (attr
) =
10316 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
10319 case DW_FORM_ref_udata
:
10320 DW_ADDR (attr
) = (cu
->header
.offset
10321 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
10322 info_ptr
+= bytes_read
;
10324 case DW_FORM_indirect
:
10325 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10326 info_ptr
+= bytes_read
;
10327 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
10330 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
10331 dwarf_form_name (form
),
10332 bfd_get_filename (abfd
));
10335 /* We have seen instances where the compiler tried to emit a byte
10336 size attribute of -1 which ended up being encoded as an unsigned
10337 0xffffffff. Although 0xffffffff is technically a valid size value,
10338 an object of this size seems pretty unlikely so we can relatively
10339 safely treat these cases as if the size attribute was invalid and
10340 treat them as zero by default. */
10341 if (attr
->name
== DW_AT_byte_size
10342 && form
== DW_FORM_data4
10343 && DW_UNSND (attr
) >= 0xffffffff)
10346 (&symfile_complaints
,
10347 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
10348 hex_string (DW_UNSND (attr
)));
10349 DW_UNSND (attr
) = 0;
10355 /* Read an attribute described by an abbreviated attribute. */
10358 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
10359 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
10361 attr
->name
= abbrev
->name
;
10362 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
10365 /* Read dwarf information from a buffer. */
10367 static unsigned int
10368 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
10370 return bfd_get_8 (abfd
, buf
);
10374 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
10376 return bfd_get_signed_8 (abfd
, buf
);
10379 static unsigned int
10380 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
10382 return bfd_get_16 (abfd
, buf
);
10386 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
10388 return bfd_get_signed_16 (abfd
, buf
);
10391 static unsigned int
10392 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
10394 return bfd_get_32 (abfd
, buf
);
10398 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
10400 return bfd_get_signed_32 (abfd
, buf
);
10404 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
10406 return bfd_get_64 (abfd
, buf
);
10410 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
10411 unsigned int *bytes_read
)
10413 struct comp_unit_head
*cu_header
= &cu
->header
;
10414 CORE_ADDR retval
= 0;
10416 if (cu_header
->signed_addr_p
)
10418 switch (cu_header
->addr_size
)
10421 retval
= bfd_get_signed_16 (abfd
, buf
);
10424 retval
= bfd_get_signed_32 (abfd
, buf
);
10427 retval
= bfd_get_signed_64 (abfd
, buf
);
10430 internal_error (__FILE__
, __LINE__
,
10431 _("read_address: bad switch, signed [in module %s]"),
10432 bfd_get_filename (abfd
));
10437 switch (cu_header
->addr_size
)
10440 retval
= bfd_get_16 (abfd
, buf
);
10443 retval
= bfd_get_32 (abfd
, buf
);
10446 retval
= bfd_get_64 (abfd
, buf
);
10449 internal_error (__FILE__
, __LINE__
,
10450 _("read_address: bad switch, "
10451 "unsigned [in module %s]"),
10452 bfd_get_filename (abfd
));
10456 *bytes_read
= cu_header
->addr_size
;
10460 /* Read the initial length from a section. The (draft) DWARF 3
10461 specification allows the initial length to take up either 4 bytes
10462 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
10463 bytes describe the length and all offsets will be 8 bytes in length
10466 An older, non-standard 64-bit format is also handled by this
10467 function. The older format in question stores the initial length
10468 as an 8-byte quantity without an escape value. Lengths greater
10469 than 2^32 aren't very common which means that the initial 4 bytes
10470 is almost always zero. Since a length value of zero doesn't make
10471 sense for the 32-bit format, this initial zero can be considered to
10472 be an escape value which indicates the presence of the older 64-bit
10473 format. As written, the code can't detect (old format) lengths
10474 greater than 4GB. If it becomes necessary to handle lengths
10475 somewhat larger than 4GB, we could allow other small values (such
10476 as the non-sensical values of 1, 2, and 3) to also be used as
10477 escape values indicating the presence of the old format.
10479 The value returned via bytes_read should be used to increment the
10480 relevant pointer after calling read_initial_length().
10482 [ Note: read_initial_length() and read_offset() are based on the
10483 document entitled "DWARF Debugging Information Format", revision
10484 3, draft 8, dated November 19, 2001. This document was obtained
10487 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
10489 This document is only a draft and is subject to change. (So beware.)
10491 Details regarding the older, non-standard 64-bit format were
10492 determined empirically by examining 64-bit ELF files produced by
10493 the SGI toolchain on an IRIX 6.5 machine.
10495 - Kevin, July 16, 2002
10499 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
10501 LONGEST length
= bfd_get_32 (abfd
, buf
);
10503 if (length
== 0xffffffff)
10505 length
= bfd_get_64 (abfd
, buf
+ 4);
10508 else if (length
== 0)
10510 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
10511 length
= bfd_get_64 (abfd
, buf
);
10522 /* Cover function for read_initial_length.
10523 Returns the length of the object at BUF, and stores the size of the
10524 initial length in *BYTES_READ and stores the size that offsets will be in
10526 If the initial length size is not equivalent to that specified in
10527 CU_HEADER then issue a complaint.
10528 This is useful when reading non-comp-unit headers. */
10531 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
10532 const struct comp_unit_head
*cu_header
,
10533 unsigned int *bytes_read
,
10534 unsigned int *offset_size
)
10536 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
10538 gdb_assert (cu_header
->initial_length_size
== 4
10539 || cu_header
->initial_length_size
== 8
10540 || cu_header
->initial_length_size
== 12);
10542 if (cu_header
->initial_length_size
!= *bytes_read
)
10543 complaint (&symfile_complaints
,
10544 _("intermixed 32-bit and 64-bit DWARF sections"));
10546 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
10550 /* Read an offset from the data stream. The size of the offset is
10551 given by cu_header->offset_size. */
10554 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
10555 unsigned int *bytes_read
)
10557 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
10559 *bytes_read
= cu_header
->offset_size
;
10563 /* Read an offset from the data stream. */
10566 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
10568 LONGEST retval
= 0;
10570 switch (offset_size
)
10573 retval
= bfd_get_32 (abfd
, buf
);
10576 retval
= bfd_get_64 (abfd
, buf
);
10579 internal_error (__FILE__
, __LINE__
,
10580 _("read_offset_1: bad switch [in module %s]"),
10581 bfd_get_filename (abfd
));
10588 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
10590 /* If the size of a host char is 8 bits, we can return a pointer
10591 to the buffer, otherwise we have to copy the data to a buffer
10592 allocated on the temporary obstack. */
10593 gdb_assert (HOST_CHAR_BIT
== 8);
10598 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10600 /* If the size of a host char is 8 bits, we can return a pointer
10601 to the string, otherwise we have to copy the string to a buffer
10602 allocated on the temporary obstack. */
10603 gdb_assert (HOST_CHAR_BIT
== 8);
10606 *bytes_read_ptr
= 1;
10609 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
10610 return (char *) buf
;
10614 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
10616 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
10617 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
10618 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
10619 bfd_get_filename (abfd
));
10620 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
10621 error (_("DW_FORM_strp pointing outside of "
10622 ".debug_str section [in module %s]"),
10623 bfd_get_filename (abfd
));
10624 gdb_assert (HOST_CHAR_BIT
== 8);
10625 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
10627 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
10631 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
10632 const struct comp_unit_head
*cu_header
,
10633 unsigned int *bytes_read_ptr
)
10635 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
10637 return read_indirect_string_at_offset (abfd
, str_offset
);
10640 static unsigned long
10641 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10643 unsigned long result
;
10644 unsigned int num_read
;
10646 unsigned char byte
;
10654 byte
= bfd_get_8 (abfd
, buf
);
10657 result
|= ((unsigned long)(byte
& 127) << shift
);
10658 if ((byte
& 128) == 0)
10664 *bytes_read_ptr
= num_read
;
10669 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10672 int i
, shift
, num_read
;
10673 unsigned char byte
;
10681 byte
= bfd_get_8 (abfd
, buf
);
10684 result
|= ((long)(byte
& 127) << shift
);
10686 if ((byte
& 128) == 0)
10691 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
10692 result
|= -(((long)1) << shift
);
10693 *bytes_read_ptr
= num_read
;
10697 /* Return a pointer to just past the end of an LEB128 number in BUF. */
10700 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
10706 byte
= bfd_get_8 (abfd
, buf
);
10708 if ((byte
& 128) == 0)
10714 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
10721 cu
->language
= language_c
;
10723 case DW_LANG_C_plus_plus
:
10724 cu
->language
= language_cplus
;
10727 cu
->language
= language_d
;
10729 case DW_LANG_Fortran77
:
10730 case DW_LANG_Fortran90
:
10731 case DW_LANG_Fortran95
:
10732 cu
->language
= language_fortran
;
10734 case DW_LANG_Mips_Assembler
:
10735 cu
->language
= language_asm
;
10738 cu
->language
= language_java
;
10740 case DW_LANG_Ada83
:
10741 case DW_LANG_Ada95
:
10742 cu
->language
= language_ada
;
10744 case DW_LANG_Modula2
:
10745 cu
->language
= language_m2
;
10747 case DW_LANG_Pascal83
:
10748 cu
->language
= language_pascal
;
10751 cu
->language
= language_objc
;
10753 case DW_LANG_Cobol74
:
10754 case DW_LANG_Cobol85
:
10756 cu
->language
= language_minimal
;
10759 cu
->language_defn
= language_def (cu
->language
);
10762 /* Return the named attribute or NULL if not there. */
10764 static struct attribute
*
10765 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
10770 struct attribute
*spec
= NULL
;
10772 for (i
= 0; i
< die
->num_attrs
; ++i
)
10774 if (die
->attrs
[i
].name
== name
)
10775 return &die
->attrs
[i
];
10776 if (die
->attrs
[i
].name
== DW_AT_specification
10777 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
10778 spec
= &die
->attrs
[i
];
10784 die
= follow_die_ref (die
, spec
, &cu
);
10790 /* Return the named attribute or NULL if not there,
10791 but do not follow DW_AT_specification, etc.
10792 This is for use in contexts where we're reading .debug_types dies.
10793 Following DW_AT_specification, DW_AT_abstract_origin will take us
10794 back up the chain, and we want to go down. */
10796 static struct attribute
*
10797 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
10798 struct dwarf2_cu
*cu
)
10802 for (i
= 0; i
< die
->num_attrs
; ++i
)
10803 if (die
->attrs
[i
].name
== name
)
10804 return &die
->attrs
[i
];
10809 /* Return non-zero iff the attribute NAME is defined for the given DIE,
10810 and holds a non-zero value. This function should only be used for
10811 DW_FORM_flag or DW_FORM_flag_present attributes. */
10814 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
10816 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
10818 return (attr
&& DW_UNSND (attr
));
10822 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
10824 /* A DIE is a declaration if it has a DW_AT_declaration attribute
10825 which value is non-zero. However, we have to be careful with
10826 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
10827 (via dwarf2_flag_true_p) follows this attribute. So we may
10828 end up accidently finding a declaration attribute that belongs
10829 to a different DIE referenced by the specification attribute,
10830 even though the given DIE does not have a declaration attribute. */
10831 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
10832 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
10835 /* Return the die giving the specification for DIE, if there is
10836 one. *SPEC_CU is the CU containing DIE on input, and the CU
10837 containing the return value on output. If there is no
10838 specification, but there is an abstract origin, that is
10841 static struct die_info
*
10842 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
10844 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
10847 if (spec_attr
== NULL
)
10848 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
10850 if (spec_attr
== NULL
)
10853 return follow_die_ref (die
, spec_attr
, spec_cu
);
10856 /* Free the line_header structure *LH, and any arrays and strings it
10858 NOTE: This is also used as a "cleanup" function. */
10861 free_line_header (struct line_header
*lh
)
10863 if (lh
->standard_opcode_lengths
)
10864 xfree (lh
->standard_opcode_lengths
);
10866 /* Remember that all the lh->file_names[i].name pointers are
10867 pointers into debug_line_buffer, and don't need to be freed. */
10868 if (lh
->file_names
)
10869 xfree (lh
->file_names
);
10871 /* Similarly for the include directory names. */
10872 if (lh
->include_dirs
)
10873 xfree (lh
->include_dirs
);
10878 /* Add an entry to LH's include directory table. */
10881 add_include_dir (struct line_header
*lh
, char *include_dir
)
10883 /* Grow the array if necessary. */
10884 if (lh
->include_dirs_size
== 0)
10886 lh
->include_dirs_size
= 1; /* for testing */
10887 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
10888 * sizeof (*lh
->include_dirs
));
10890 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
10892 lh
->include_dirs_size
*= 2;
10893 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
10894 (lh
->include_dirs_size
10895 * sizeof (*lh
->include_dirs
)));
10898 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
10901 /* Add an entry to LH's file name table. */
10904 add_file_name (struct line_header
*lh
,
10906 unsigned int dir_index
,
10907 unsigned int mod_time
,
10908 unsigned int length
)
10910 struct file_entry
*fe
;
10912 /* Grow the array if necessary. */
10913 if (lh
->file_names_size
== 0)
10915 lh
->file_names_size
= 1; /* for testing */
10916 lh
->file_names
= xmalloc (lh
->file_names_size
10917 * sizeof (*lh
->file_names
));
10919 else if (lh
->num_file_names
>= lh
->file_names_size
)
10921 lh
->file_names_size
*= 2;
10922 lh
->file_names
= xrealloc (lh
->file_names
,
10923 (lh
->file_names_size
10924 * sizeof (*lh
->file_names
)));
10927 fe
= &lh
->file_names
[lh
->num_file_names
++];
10929 fe
->dir_index
= dir_index
;
10930 fe
->mod_time
= mod_time
;
10931 fe
->length
= length
;
10932 fe
->included_p
= 0;
10936 /* Read the statement program header starting at OFFSET in
10937 .debug_line, according to the endianness of ABFD. Return a pointer
10938 to a struct line_header, allocated using xmalloc.
10940 NOTE: the strings in the include directory and file name tables of
10941 the returned object point into debug_line_buffer, and must not be
10944 static struct line_header
*
10945 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
10946 struct dwarf2_cu
*cu
)
10948 struct cleanup
*back_to
;
10949 struct line_header
*lh
;
10950 gdb_byte
*line_ptr
;
10951 unsigned int bytes_read
, offset_size
;
10953 char *cur_dir
, *cur_file
;
10955 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
10956 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
10958 complaint (&symfile_complaints
, _("missing .debug_line section"));
10962 /* Make sure that at least there's room for the total_length field.
10963 That could be 12 bytes long, but we're just going to fudge that. */
10964 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
10966 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10970 lh
= xmalloc (sizeof (*lh
));
10971 memset (lh
, 0, sizeof (*lh
));
10972 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
10975 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
10977 /* Read in the header. */
10979 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
10980 &bytes_read
, &offset_size
);
10981 line_ptr
+= bytes_read
;
10982 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
10983 + dwarf2_per_objfile
->line
.size
))
10985 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10988 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
10989 lh
->version
= read_2_bytes (abfd
, line_ptr
);
10991 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
10992 line_ptr
+= offset_size
;
10993 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
10995 if (lh
->version
>= 4)
10997 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
11001 lh
->maximum_ops_per_instruction
= 1;
11003 if (lh
->maximum_ops_per_instruction
== 0)
11005 lh
->maximum_ops_per_instruction
= 1;
11006 complaint (&symfile_complaints
,
11007 _("invalid maximum_ops_per_instruction "
11008 "in `.debug_line' section"));
11011 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
11013 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
11015 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
11017 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
11019 lh
->standard_opcode_lengths
11020 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
11022 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
11023 for (i
= 1; i
< lh
->opcode_base
; ++i
)
11025 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
11029 /* Read directory table. */
11030 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
11032 line_ptr
+= bytes_read
;
11033 add_include_dir (lh
, cur_dir
);
11035 line_ptr
+= bytes_read
;
11037 /* Read file name table. */
11038 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
11040 unsigned int dir_index
, mod_time
, length
;
11042 line_ptr
+= bytes_read
;
11043 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11044 line_ptr
+= bytes_read
;
11045 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11046 line_ptr
+= bytes_read
;
11047 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11048 line_ptr
+= bytes_read
;
11050 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
11052 line_ptr
+= bytes_read
;
11053 lh
->statement_program_start
= line_ptr
;
11055 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
11056 + dwarf2_per_objfile
->line
.size
))
11057 complaint (&symfile_complaints
,
11058 _("line number info header doesn't "
11059 "fit in `.debug_line' section"));
11061 discard_cleanups (back_to
);
11065 /* Subroutine of dwarf_decode_lines to simplify it.
11066 Return the file name of the psymtab for included file FILE_INDEX
11067 in line header LH of PST.
11068 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
11069 If space for the result is malloc'd, it will be freed by a cleanup.
11070 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
11073 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
11074 const struct partial_symtab
*pst
,
11075 const char *comp_dir
)
11077 const struct file_entry fe
= lh
->file_names
[file_index
];
11078 char *include_name
= fe
.name
;
11079 char *include_name_to_compare
= include_name
;
11080 char *dir_name
= NULL
;
11081 const char *pst_filename
;
11082 char *copied_name
= NULL
;
11086 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
11088 if (!IS_ABSOLUTE_PATH (include_name
)
11089 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
11091 /* Avoid creating a duplicate psymtab for PST.
11092 We do this by comparing INCLUDE_NAME and PST_FILENAME.
11093 Before we do the comparison, however, we need to account
11094 for DIR_NAME and COMP_DIR.
11095 First prepend dir_name (if non-NULL). If we still don't
11096 have an absolute path prepend comp_dir (if non-NULL).
11097 However, the directory we record in the include-file's
11098 psymtab does not contain COMP_DIR (to match the
11099 corresponding symtab(s)).
11104 bash$ gcc -g ./hello.c
11105 include_name = "hello.c"
11107 DW_AT_comp_dir = comp_dir = "/tmp"
11108 DW_AT_name = "./hello.c" */
11110 if (dir_name
!= NULL
)
11112 include_name
= concat (dir_name
, SLASH_STRING
,
11113 include_name
, (char *)NULL
);
11114 include_name_to_compare
= include_name
;
11115 make_cleanup (xfree
, include_name
);
11117 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
11119 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
11120 include_name
, (char *)NULL
);
11124 pst_filename
= pst
->filename
;
11125 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
11127 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
11128 pst_filename
, (char *)NULL
);
11129 pst_filename
= copied_name
;
11132 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
11134 if (include_name_to_compare
!= include_name
)
11135 xfree (include_name_to_compare
);
11136 if (copied_name
!= NULL
)
11137 xfree (copied_name
);
11141 return include_name
;
11144 /* Ignore this record_line request. */
11147 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
11152 /* Subroutine of dwarf_decode_lines to simplify it.
11153 Process the line number information in LH. */
11156 dwarf_decode_lines_1 (struct line_header
*lh
, const char *comp_dir
,
11157 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
11159 gdb_byte
*line_ptr
, *extended_end
;
11160 gdb_byte
*line_end
;
11161 unsigned int bytes_read
, extended_len
;
11162 unsigned char op_code
, extended_op
, adj_opcode
;
11163 CORE_ADDR baseaddr
;
11164 struct objfile
*objfile
= cu
->objfile
;
11165 bfd
*abfd
= objfile
->obfd
;
11166 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11167 const int decode_for_pst_p
= (pst
!= NULL
);
11168 struct subfile
*last_subfile
= NULL
;
11169 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
11172 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11174 line_ptr
= lh
->statement_program_start
;
11175 line_end
= lh
->statement_program_end
;
11177 /* Read the statement sequences until there's nothing left. */
11178 while (line_ptr
< line_end
)
11180 /* state machine registers */
11181 CORE_ADDR address
= 0;
11182 unsigned int file
= 1;
11183 unsigned int line
= 1;
11184 unsigned int column
= 0;
11185 int is_stmt
= lh
->default_is_stmt
;
11186 int basic_block
= 0;
11187 int end_sequence
= 0;
11189 unsigned char op_index
= 0;
11191 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
11193 /* Start a subfile for the current file of the state machine. */
11194 /* lh->include_dirs and lh->file_names are 0-based, but the
11195 directory and file name numbers in the statement program
11197 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
11201 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11203 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11206 /* Decode the table. */
11207 while (!end_sequence
)
11209 op_code
= read_1_byte (abfd
, line_ptr
);
11211 if (line_ptr
> line_end
)
11213 dwarf2_debug_line_missing_end_sequence_complaint ();
11217 if (op_code
>= lh
->opcode_base
)
11219 /* Special operand. */
11220 adj_opcode
= op_code
- lh
->opcode_base
;
11221 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
11222 / lh
->maximum_ops_per_instruction
)
11223 * lh
->minimum_instruction_length
);
11224 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
11225 % lh
->maximum_ops_per_instruction
);
11226 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
11227 if (lh
->num_file_names
< file
|| file
== 0)
11228 dwarf2_debug_line_missing_file_complaint ();
11229 /* For now we ignore lines not starting on an
11230 instruction boundary. */
11231 else if (op_index
== 0)
11233 lh
->file_names
[file
- 1].included_p
= 1;
11234 if (!decode_for_pst_p
&& is_stmt
)
11236 if (last_subfile
!= current_subfile
)
11238 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11240 (*p_record_line
) (last_subfile
, 0, addr
);
11241 last_subfile
= current_subfile
;
11243 /* Append row to matrix using current values. */
11244 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11245 (*p_record_line
) (current_subfile
, line
, addr
);
11250 else switch (op_code
)
11252 case DW_LNS_extended_op
:
11253 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
11255 line_ptr
+= bytes_read
;
11256 extended_end
= line_ptr
+ extended_len
;
11257 extended_op
= read_1_byte (abfd
, line_ptr
);
11259 switch (extended_op
)
11261 case DW_LNE_end_sequence
:
11262 p_record_line
= record_line
;
11265 case DW_LNE_set_address
:
11266 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
11268 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
11270 /* This line table is for a function which has been
11271 GCd by the linker. Ignore it. PR gdb/12528 */
11274 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
11276 complaint (&symfile_complaints
,
11277 _(".debug_line address at offset 0x%lx is 0 "
11279 line_offset
, objfile
->name
);
11280 p_record_line
= noop_record_line
;
11284 line_ptr
+= bytes_read
;
11285 address
+= baseaddr
;
11287 case DW_LNE_define_file
:
11290 unsigned int dir_index
, mod_time
, length
;
11292 cur_file
= read_direct_string (abfd
, line_ptr
,
11294 line_ptr
+= bytes_read
;
11296 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11297 line_ptr
+= bytes_read
;
11299 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11300 line_ptr
+= bytes_read
;
11302 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11303 line_ptr
+= bytes_read
;
11304 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
11307 case DW_LNE_set_discriminator
:
11308 /* The discriminator is not interesting to the debugger;
11310 line_ptr
= extended_end
;
11313 complaint (&symfile_complaints
,
11314 _("mangled .debug_line section"));
11317 /* Make sure that we parsed the extended op correctly. If e.g.
11318 we expected a different address size than the producer used,
11319 we may have read the wrong number of bytes. */
11320 if (line_ptr
!= extended_end
)
11322 complaint (&symfile_complaints
,
11323 _("mangled .debug_line section"));
11328 if (lh
->num_file_names
< file
|| file
== 0)
11329 dwarf2_debug_line_missing_file_complaint ();
11332 lh
->file_names
[file
- 1].included_p
= 1;
11333 if (!decode_for_pst_p
&& is_stmt
)
11335 if (last_subfile
!= current_subfile
)
11337 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11339 (*p_record_line
) (last_subfile
, 0, addr
);
11340 last_subfile
= current_subfile
;
11342 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11343 (*p_record_line
) (current_subfile
, line
, addr
);
11348 case DW_LNS_advance_pc
:
11351 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11353 address
+= (((op_index
+ adjust
)
11354 / lh
->maximum_ops_per_instruction
)
11355 * lh
->minimum_instruction_length
);
11356 op_index
= ((op_index
+ adjust
)
11357 % lh
->maximum_ops_per_instruction
);
11358 line_ptr
+= bytes_read
;
11361 case DW_LNS_advance_line
:
11362 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
11363 line_ptr
+= bytes_read
;
11365 case DW_LNS_set_file
:
11367 /* The arrays lh->include_dirs and lh->file_names are
11368 0-based, but the directory and file name numbers in
11369 the statement program are 1-based. */
11370 struct file_entry
*fe
;
11373 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11374 line_ptr
+= bytes_read
;
11375 if (lh
->num_file_names
< file
|| file
== 0)
11376 dwarf2_debug_line_missing_file_complaint ();
11379 fe
= &lh
->file_names
[file
- 1];
11381 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11382 if (!decode_for_pst_p
)
11384 last_subfile
= current_subfile
;
11385 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11390 case DW_LNS_set_column
:
11391 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11392 line_ptr
+= bytes_read
;
11394 case DW_LNS_negate_stmt
:
11395 is_stmt
= (!is_stmt
);
11397 case DW_LNS_set_basic_block
:
11400 /* Add to the address register of the state machine the
11401 address increment value corresponding to special opcode
11402 255. I.e., this value is scaled by the minimum
11403 instruction length since special opcode 255 would have
11404 scaled the increment. */
11405 case DW_LNS_const_add_pc
:
11407 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
11409 address
+= (((op_index
+ adjust
)
11410 / lh
->maximum_ops_per_instruction
)
11411 * lh
->minimum_instruction_length
);
11412 op_index
= ((op_index
+ adjust
)
11413 % lh
->maximum_ops_per_instruction
);
11416 case DW_LNS_fixed_advance_pc
:
11417 address
+= read_2_bytes (abfd
, line_ptr
);
11423 /* Unknown standard opcode, ignore it. */
11426 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
11428 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11429 line_ptr
+= bytes_read
;
11434 if (lh
->num_file_names
< file
|| file
== 0)
11435 dwarf2_debug_line_missing_file_complaint ();
11438 lh
->file_names
[file
- 1].included_p
= 1;
11439 if (!decode_for_pst_p
)
11441 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11442 (*p_record_line
) (current_subfile
, 0, addr
);
11448 /* Decode the Line Number Program (LNP) for the given line_header
11449 structure and CU. The actual information extracted and the type
11450 of structures created from the LNP depends on the value of PST.
11452 1. If PST is NULL, then this procedure uses the data from the program
11453 to create all necessary symbol tables, and their linetables.
11455 2. If PST is not NULL, this procedure reads the program to determine
11456 the list of files included by the unit represented by PST, and
11457 builds all the associated partial symbol tables.
11459 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
11460 It is used for relative paths in the line table.
11461 NOTE: When processing partial symtabs (pst != NULL),
11462 comp_dir == pst->dirname.
11464 NOTE: It is important that psymtabs have the same file name (via strcmp)
11465 as the corresponding symtab. Since COMP_DIR is not used in the name of the
11466 symtab we don't use it in the name of the psymtabs we create.
11467 E.g. expand_line_sal requires this when finding psymtabs to expand.
11468 A good testcase for this is mb-inline.exp. */
11471 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
11472 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
11473 int want_line_info
)
11475 struct objfile
*objfile
= cu
->objfile
;
11476 const int decode_for_pst_p
= (pst
!= NULL
);
11477 struct subfile
*first_subfile
= current_subfile
;
11479 if (want_line_info
)
11480 dwarf_decode_lines_1 (lh
, comp_dir
, cu
, pst
);
11482 if (decode_for_pst_p
)
11486 /* Now that we're done scanning the Line Header Program, we can
11487 create the psymtab of each included file. */
11488 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
11489 if (lh
->file_names
[file_index
].included_p
== 1)
11491 char *include_name
=
11492 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
11493 if (include_name
!= NULL
)
11494 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
11499 /* Make sure a symtab is created for every file, even files
11500 which contain only variables (i.e. no code with associated
11504 for (i
= 0; i
< lh
->num_file_names
; i
++)
11507 struct file_entry
*fe
;
11509 fe
= &lh
->file_names
[i
];
11511 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11512 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11514 /* Skip the main file; we don't need it, and it must be
11515 allocated last, so that it will show up before the
11516 non-primary symtabs in the objfile's symtab list. */
11517 if (current_subfile
== first_subfile
)
11520 if (current_subfile
->symtab
== NULL
)
11521 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
11523 fe
->symtab
= current_subfile
->symtab
;
11528 /* Start a subfile for DWARF. FILENAME is the name of the file and
11529 DIRNAME the name of the source directory which contains FILENAME
11530 or NULL if not known. COMP_DIR is the compilation directory for the
11531 linetable's compilation unit or NULL if not known.
11532 This routine tries to keep line numbers from identical absolute and
11533 relative file names in a common subfile.
11535 Using the `list' example from the GDB testsuite, which resides in
11536 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
11537 of /srcdir/list0.c yields the following debugging information for list0.c:
11539 DW_AT_name: /srcdir/list0.c
11540 DW_AT_comp_dir: /compdir
11541 files.files[0].name: list0.h
11542 files.files[0].dir: /srcdir
11543 files.files[1].name: list0.c
11544 files.files[1].dir: /srcdir
11546 The line number information for list0.c has to end up in a single
11547 subfile, so that `break /srcdir/list0.c:1' works as expected.
11548 start_subfile will ensure that this happens provided that we pass the
11549 concatenation of files.files[1].dir and files.files[1].name as the
11553 dwarf2_start_subfile (char *filename
, const char *dirname
,
11554 const char *comp_dir
)
11558 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
11559 `start_symtab' will always pass the contents of DW_AT_comp_dir as
11560 second argument to start_subfile. To be consistent, we do the
11561 same here. In order not to lose the line information directory,
11562 we concatenate it to the filename when it makes sense.
11563 Note that the Dwarf3 standard says (speaking of filenames in line
11564 information): ``The directory index is ignored for file names
11565 that represent full path names''. Thus ignoring dirname in the
11566 `else' branch below isn't an issue. */
11568 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
11569 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
11571 fullname
= filename
;
11573 start_subfile (fullname
, comp_dir
);
11575 if (fullname
!= filename
)
11580 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
11581 struct dwarf2_cu
*cu
)
11583 struct objfile
*objfile
= cu
->objfile
;
11584 struct comp_unit_head
*cu_header
= &cu
->header
;
11586 /* NOTE drow/2003-01-30: There used to be a comment and some special
11587 code here to turn a symbol with DW_AT_external and a
11588 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
11589 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
11590 with some versions of binutils) where shared libraries could have
11591 relocations against symbols in their debug information - the
11592 minimal symbol would have the right address, but the debug info
11593 would not. It's no longer necessary, because we will explicitly
11594 apply relocations when we read in the debug information now. */
11596 /* A DW_AT_location attribute with no contents indicates that a
11597 variable has been optimized away. */
11598 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
11600 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11604 /* Handle one degenerate form of location expression specially, to
11605 preserve GDB's previous behavior when section offsets are
11606 specified. If this is just a DW_OP_addr then mark this symbol
11609 if (attr_form_is_block (attr
)
11610 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
11611 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
11613 unsigned int dummy
;
11615 SYMBOL_VALUE_ADDRESS (sym
) =
11616 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
11617 SYMBOL_CLASS (sym
) = LOC_STATIC
;
11618 fixup_symbol_section (sym
, objfile
);
11619 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
11620 SYMBOL_SECTION (sym
));
11624 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
11625 expression evaluator, and use LOC_COMPUTED only when necessary
11626 (i.e. when the value of a register or memory location is
11627 referenced, or a thread-local block, etc.). Then again, it might
11628 not be worthwhile. I'm assuming that it isn't unless performance
11629 or memory numbers show me otherwise. */
11631 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
11632 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11634 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
11635 cu
->has_loclist
= 1;
11638 /* Given a pointer to a DWARF information entry, figure out if we need
11639 to make a symbol table entry for it, and if so, create a new entry
11640 and return a pointer to it.
11641 If TYPE is NULL, determine symbol type from the die, otherwise
11642 used the passed type.
11643 If SPACE is not NULL, use it to hold the new symbol. If it is
11644 NULL, allocate a new symbol on the objfile's obstack. */
11646 static struct symbol
*
11647 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
11648 struct symbol
*space
)
11650 struct objfile
*objfile
= cu
->objfile
;
11651 struct symbol
*sym
= NULL
;
11653 struct attribute
*attr
= NULL
;
11654 struct attribute
*attr2
= NULL
;
11655 CORE_ADDR baseaddr
;
11656 struct pending
**list_to_add
= NULL
;
11658 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
11660 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11662 name
= dwarf2_name (die
, cu
);
11665 const char *linkagename
;
11666 int suppress_add
= 0;
11671 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
11672 OBJSTAT (objfile
, n_syms
++);
11674 /* Cache this symbol's name and the name's demangled form (if any). */
11675 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
11676 linkagename
= dwarf2_physname (name
, die
, cu
);
11677 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
11679 /* Fortran does not have mangling standard and the mangling does differ
11680 between gfortran, iFort etc. */
11681 if (cu
->language
== language_fortran
11682 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
11683 symbol_set_demangled_name (&(sym
->ginfo
),
11684 (char *) dwarf2_full_name (name
, die
, cu
),
11687 /* Default assumptions.
11688 Use the passed type or decode it from the die. */
11689 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11690 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11692 SYMBOL_TYPE (sym
) = type
;
11694 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
11695 attr
= dwarf2_attr (die
,
11696 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
11700 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
11703 attr
= dwarf2_attr (die
,
11704 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
11708 int file_index
= DW_UNSND (attr
);
11710 if (cu
->line_header
== NULL
11711 || file_index
> cu
->line_header
->num_file_names
)
11712 complaint (&symfile_complaints
,
11713 _("file index out of range"));
11714 else if (file_index
> 0)
11716 struct file_entry
*fe
;
11718 fe
= &cu
->line_header
->file_names
[file_index
- 1];
11719 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
11726 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11729 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
11731 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
11732 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
11733 SYMBOL_CLASS (sym
) = LOC_LABEL
;
11734 add_symbol_to_list (sym
, cu
->list_in_scope
);
11736 case DW_TAG_subprogram
:
11737 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11739 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11740 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11741 if ((attr2
&& (DW_UNSND (attr2
) != 0))
11742 || cu
->language
== language_ada
)
11744 /* Subprograms marked external are stored as a global symbol.
11745 Ada subprograms, whether marked external or not, are always
11746 stored as a global symbol, because we want to be able to
11747 access them globally. For instance, we want to be able
11748 to break on a nested subprogram without having to
11749 specify the context. */
11750 list_to_add
= &global_symbols
;
11754 list_to_add
= cu
->list_in_scope
;
11757 case DW_TAG_inlined_subroutine
:
11758 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11760 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11761 SYMBOL_INLINED (sym
) = 1;
11762 list_to_add
= cu
->list_in_scope
;
11764 case DW_TAG_template_value_param
:
11766 /* Fall through. */
11767 case DW_TAG_constant
:
11768 case DW_TAG_variable
:
11769 case DW_TAG_member
:
11770 /* Compilation with minimal debug info may result in
11771 variables with missing type entries. Change the
11772 misleading `void' type to something sensible. */
11773 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
11775 = objfile_type (objfile
)->nodebug_data_symbol
;
11777 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11778 /* In the case of DW_TAG_member, we should only be called for
11779 static const members. */
11780 if (die
->tag
== DW_TAG_member
)
11782 /* dwarf2_add_field uses die_is_declaration,
11783 so we do the same. */
11784 gdb_assert (die_is_declaration (die
, cu
));
11789 dwarf2_const_value (attr
, sym
, cu
);
11790 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11793 if (attr2
&& (DW_UNSND (attr2
) != 0))
11794 list_to_add
= &global_symbols
;
11796 list_to_add
= cu
->list_in_scope
;
11800 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11803 var_decode_location (attr
, sym
, cu
);
11804 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11805 if (SYMBOL_CLASS (sym
) == LOC_STATIC
11806 && SYMBOL_VALUE_ADDRESS (sym
) == 0
11807 && !dwarf2_per_objfile
->has_section_at_zero
)
11809 /* When a static variable is eliminated by the linker,
11810 the corresponding debug information is not stripped
11811 out, but the variable address is set to null;
11812 do not add such variables into symbol table. */
11814 else if (attr2
&& (DW_UNSND (attr2
) != 0))
11816 /* Workaround gfortran PR debug/40040 - it uses
11817 DW_AT_location for variables in -fPIC libraries which may
11818 get overriden by other libraries/executable and get
11819 a different address. Resolve it by the minimal symbol
11820 which may come from inferior's executable using copy
11821 relocation. Make this workaround only for gfortran as for
11822 other compilers GDB cannot guess the minimal symbol
11823 Fortran mangling kind. */
11824 if (cu
->language
== language_fortran
&& die
->parent
11825 && die
->parent
->tag
== DW_TAG_module
11827 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
11828 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11830 /* A variable with DW_AT_external is never static,
11831 but it may be block-scoped. */
11832 list_to_add
= (cu
->list_in_scope
== &file_symbols
11833 ? &global_symbols
: cu
->list_in_scope
);
11836 list_to_add
= cu
->list_in_scope
;
11840 /* We do not know the address of this symbol.
11841 If it is an external symbol and we have type information
11842 for it, enter the symbol as a LOC_UNRESOLVED symbol.
11843 The address of the variable will then be determined from
11844 the minimal symbol table whenever the variable is
11846 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11847 if (attr2
&& (DW_UNSND (attr2
) != 0)
11848 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
11850 /* A variable with DW_AT_external is never static, but it
11851 may be block-scoped. */
11852 list_to_add
= (cu
->list_in_scope
== &file_symbols
11853 ? &global_symbols
: cu
->list_in_scope
);
11855 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11857 else if (!die_is_declaration (die
, cu
))
11859 /* Use the default LOC_OPTIMIZED_OUT class. */
11860 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
11862 list_to_add
= cu
->list_in_scope
;
11866 case DW_TAG_formal_parameter
:
11867 /* If we are inside a function, mark this as an argument. If
11868 not, we might be looking at an argument to an inlined function
11869 when we do not have enough information to show inlined frames;
11870 pretend it's a local variable in that case so that the user can
11872 if (context_stack_depth
> 0
11873 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
11874 SYMBOL_IS_ARGUMENT (sym
) = 1;
11875 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11878 var_decode_location (attr
, sym
, cu
);
11880 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11883 dwarf2_const_value (attr
, sym
, cu
);
11886 list_to_add
= cu
->list_in_scope
;
11888 case DW_TAG_unspecified_parameters
:
11889 /* From varargs functions; gdb doesn't seem to have any
11890 interest in this information, so just ignore it for now.
11893 case DW_TAG_template_type_param
:
11895 /* Fall through. */
11896 case DW_TAG_class_type
:
11897 case DW_TAG_interface_type
:
11898 case DW_TAG_structure_type
:
11899 case DW_TAG_union_type
:
11900 case DW_TAG_set_type
:
11901 case DW_TAG_enumeration_type
:
11902 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11903 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
11906 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
11907 really ever be static objects: otherwise, if you try
11908 to, say, break of a class's method and you're in a file
11909 which doesn't mention that class, it won't work unless
11910 the check for all static symbols in lookup_symbol_aux
11911 saves you. See the OtherFileClass tests in
11912 gdb.c++/namespace.exp. */
11916 list_to_add
= (cu
->list_in_scope
== &file_symbols
11917 && (cu
->language
== language_cplus
11918 || cu
->language
== language_java
)
11919 ? &global_symbols
: cu
->list_in_scope
);
11921 /* The semantics of C++ state that "struct foo {
11922 ... }" also defines a typedef for "foo". A Java
11923 class declaration also defines a typedef for the
11925 if (cu
->language
== language_cplus
11926 || cu
->language
== language_java
11927 || cu
->language
== language_ada
)
11929 /* The symbol's name is already allocated along
11930 with this objfile, so we don't need to
11931 duplicate it for the type. */
11932 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
11933 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
11938 case DW_TAG_typedef
:
11939 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11940 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11941 list_to_add
= cu
->list_in_scope
;
11943 case DW_TAG_base_type
:
11944 case DW_TAG_subrange_type
:
11945 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11946 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11947 list_to_add
= cu
->list_in_scope
;
11949 case DW_TAG_enumerator
:
11950 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11953 dwarf2_const_value (attr
, sym
, cu
);
11956 /* NOTE: carlton/2003-11-10: See comment above in the
11957 DW_TAG_class_type, etc. block. */
11959 list_to_add
= (cu
->list_in_scope
== &file_symbols
11960 && (cu
->language
== language_cplus
11961 || cu
->language
== language_java
)
11962 ? &global_symbols
: cu
->list_in_scope
);
11965 case DW_TAG_namespace
:
11966 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11967 list_to_add
= &global_symbols
;
11970 /* Not a tag we recognize. Hopefully we aren't processing
11971 trash data, but since we must specifically ignore things
11972 we don't recognize, there is nothing else we should do at
11974 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
11975 dwarf_tag_name (die
->tag
));
11981 sym
->hash_next
= objfile
->template_symbols
;
11982 objfile
->template_symbols
= sym
;
11983 list_to_add
= NULL
;
11986 if (list_to_add
!= NULL
)
11987 add_symbol_to_list (sym
, list_to_add
);
11989 /* For the benefit of old versions of GCC, check for anonymous
11990 namespaces based on the demangled name. */
11991 if (!processing_has_namespace_info
11992 && cu
->language
== language_cplus
)
11993 cp_scan_for_anonymous_namespaces (sym
, objfile
);
11998 /* A wrapper for new_symbol_full that always allocates a new symbol. */
12000 static struct symbol
*
12001 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
12003 return new_symbol_full (die
, type
, cu
, NULL
);
12006 /* Given an attr with a DW_FORM_dataN value in host byte order,
12007 zero-extend it as appropriate for the symbol's type. The DWARF
12008 standard (v4) is not entirely clear about the meaning of using
12009 DW_FORM_dataN for a constant with a signed type, where the type is
12010 wider than the data. The conclusion of a discussion on the DWARF
12011 list was that this is unspecified. We choose to always zero-extend
12012 because that is the interpretation long in use by GCC. */
12015 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
12016 const char *name
, struct obstack
*obstack
,
12017 struct dwarf2_cu
*cu
, long *value
, int bits
)
12019 struct objfile
*objfile
= cu
->objfile
;
12020 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
12021 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
12022 LONGEST l
= DW_UNSND (attr
);
12024 if (bits
< sizeof (*value
) * 8)
12026 l
&= ((LONGEST
) 1 << bits
) - 1;
12029 else if (bits
== sizeof (*value
) * 8)
12033 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
12034 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
12041 /* Read a constant value from an attribute. Either set *VALUE, or if
12042 the value does not fit in *VALUE, set *BYTES - either already
12043 allocated on the objfile obstack, or newly allocated on OBSTACK,
12044 or, set *BATON, if we translated the constant to a location
12048 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
12049 const char *name
, struct obstack
*obstack
,
12050 struct dwarf2_cu
*cu
,
12051 long *value
, gdb_byte
**bytes
,
12052 struct dwarf2_locexpr_baton
**baton
)
12054 struct objfile
*objfile
= cu
->objfile
;
12055 struct comp_unit_head
*cu_header
= &cu
->header
;
12056 struct dwarf_block
*blk
;
12057 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
12058 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
12064 switch (attr
->form
)
12070 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
12071 dwarf2_const_value_length_mismatch_complaint (name
,
12072 cu_header
->addr_size
,
12073 TYPE_LENGTH (type
));
12074 /* Symbols of this form are reasonably rare, so we just
12075 piggyback on the existing location code rather than writing
12076 a new implementation of symbol_computed_ops. */
12077 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
12078 sizeof (struct dwarf2_locexpr_baton
));
12079 (*baton
)->per_cu
= cu
->per_cu
;
12080 gdb_assert ((*baton
)->per_cu
);
12082 (*baton
)->size
= 2 + cu_header
->addr_size
;
12083 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
12084 (*baton
)->data
= data
;
12086 data
[0] = DW_OP_addr
;
12087 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
12088 byte_order
, DW_ADDR (attr
));
12089 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
12092 case DW_FORM_string
:
12094 /* DW_STRING is already allocated on the objfile obstack, point
12096 *bytes
= (gdb_byte
*) DW_STRING (attr
);
12098 case DW_FORM_block1
:
12099 case DW_FORM_block2
:
12100 case DW_FORM_block4
:
12101 case DW_FORM_block
:
12102 case DW_FORM_exprloc
:
12103 blk
= DW_BLOCK (attr
);
12104 if (TYPE_LENGTH (type
) != blk
->size
)
12105 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
12106 TYPE_LENGTH (type
));
12107 *bytes
= blk
->data
;
12110 /* The DW_AT_const_value attributes are supposed to carry the
12111 symbol's value "represented as it would be on the target
12112 architecture." By the time we get here, it's already been
12113 converted to host endianness, so we just need to sign- or
12114 zero-extend it as appropriate. */
12115 case DW_FORM_data1
:
12116 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12117 obstack
, cu
, value
, 8);
12119 case DW_FORM_data2
:
12120 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12121 obstack
, cu
, value
, 16);
12123 case DW_FORM_data4
:
12124 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12125 obstack
, cu
, value
, 32);
12127 case DW_FORM_data8
:
12128 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12129 obstack
, cu
, value
, 64);
12132 case DW_FORM_sdata
:
12133 *value
= DW_SND (attr
);
12136 case DW_FORM_udata
:
12137 *value
= DW_UNSND (attr
);
12141 complaint (&symfile_complaints
,
12142 _("unsupported const value attribute form: '%s'"),
12143 dwarf_form_name (attr
->form
));
12150 /* Copy constant value from an attribute to a symbol. */
12153 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
12154 struct dwarf2_cu
*cu
)
12156 struct objfile
*objfile
= cu
->objfile
;
12157 struct comp_unit_head
*cu_header
= &cu
->header
;
12160 struct dwarf2_locexpr_baton
*baton
;
12162 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
12163 SYMBOL_PRINT_NAME (sym
),
12164 &objfile
->objfile_obstack
, cu
,
12165 &value
, &bytes
, &baton
);
12169 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
12170 SYMBOL_LOCATION_BATON (sym
) = baton
;
12171 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
12173 else if (bytes
!= NULL
)
12175 SYMBOL_VALUE_BYTES (sym
) = bytes
;
12176 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
12180 SYMBOL_VALUE (sym
) = value
;
12181 SYMBOL_CLASS (sym
) = LOC_CONST
;
12185 /* Return the type of the die in question using its DW_AT_type attribute. */
12187 static struct type
*
12188 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12190 struct attribute
*type_attr
;
12192 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
12195 /* A missing DW_AT_type represents a void type. */
12196 return objfile_type (cu
->objfile
)->builtin_void
;
12199 return lookup_die_type (die
, type_attr
, cu
);
12202 /* True iff CU's producer generates GNAT Ada auxiliary information
12203 that allows to find parallel types through that information instead
12204 of having to do expensive parallel lookups by type name. */
12207 need_gnat_info (struct dwarf2_cu
*cu
)
12209 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
12210 of GNAT produces this auxiliary information, without any indication
12211 that it is produced. Part of enhancing the FSF version of GNAT
12212 to produce that information will be to put in place an indicator
12213 that we can use in order to determine whether the descriptive type
12214 info is available or not. One suggestion that has been made is
12215 to use a new attribute, attached to the CU die. For now, assume
12216 that the descriptive type info is not available. */
12220 /* Return the auxiliary type of the die in question using its
12221 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
12222 attribute is not present. */
12224 static struct type
*
12225 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12227 struct attribute
*type_attr
;
12229 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
12233 return lookup_die_type (die
, type_attr
, cu
);
12236 /* If DIE has a descriptive_type attribute, then set the TYPE's
12237 descriptive type accordingly. */
12240 set_descriptive_type (struct type
*type
, struct die_info
*die
,
12241 struct dwarf2_cu
*cu
)
12243 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
12245 if (descriptive_type
)
12247 ALLOCATE_GNAT_AUX_TYPE (type
);
12248 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
12252 /* Return the containing type of the die in question using its
12253 DW_AT_containing_type attribute. */
12255 static struct type
*
12256 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12258 struct attribute
*type_attr
;
12260 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
12262 error (_("Dwarf Error: Problem turning containing type into gdb type "
12263 "[in module %s]"), cu
->objfile
->name
);
12265 return lookup_die_type (die
, type_attr
, cu
);
12268 /* Look up the type of DIE in CU using its type attribute ATTR.
12269 If there is no type substitute an error marker. */
12271 static struct type
*
12272 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
12273 struct dwarf2_cu
*cu
)
12275 struct objfile
*objfile
= cu
->objfile
;
12276 struct type
*this_type
;
12278 /* First see if we have it cached. */
12280 if (is_ref_attr (attr
))
12282 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
12284 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
12286 else if (attr
->form
== DW_FORM_ref_sig8
)
12288 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
12289 struct dwarf2_cu
*sig_cu
;
12290 unsigned int offset
;
12292 /* sig_type will be NULL if the signatured type is missing from
12294 if (sig_type
== NULL
)
12295 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
12296 "at 0x%x [in module %s]"),
12297 die
->offset
, objfile
->name
);
12299 gdb_assert (sig_type
->per_cu
.debug_types_section
);
12300 offset
= sig_type
->per_cu
.offset
+ sig_type
->type_offset
;
12301 this_type
= get_die_type_at_offset (offset
, &sig_type
->per_cu
);
12305 dump_die_for_error (die
);
12306 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
12307 dwarf_attr_name (attr
->name
), objfile
->name
);
12310 /* If not cached we need to read it in. */
12312 if (this_type
== NULL
)
12314 struct die_info
*type_die
;
12315 struct dwarf2_cu
*type_cu
= cu
;
12317 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
12318 /* If the type is cached, we should have found it above. */
12319 gdb_assert (get_die_type (type_die
, type_cu
) == NULL
);
12320 this_type
= read_type_die_1 (type_die
, type_cu
);
12323 /* If we still don't have a type use an error marker. */
12325 if (this_type
== NULL
)
12327 char *message
, *saved
;
12329 /* read_type_die already issued a complaint. */
12330 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
12334 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
12335 message
, strlen (message
));
12338 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
12344 /* Return the type in DIE, CU.
12345 Returns NULL for invalid types.
12347 This first does a lookup in the appropriate type_hash table,
12348 and only reads the die in if necessary.
12350 NOTE: This can be called when reading in partial or full symbols. */
12352 static struct type
*
12353 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
12355 struct type
*this_type
;
12357 this_type
= get_die_type (die
, cu
);
12361 return read_type_die_1 (die
, cu
);
12364 /* Read the type in DIE, CU.
12365 Returns NULL for invalid types. */
12367 static struct type
*
12368 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
12370 struct type
*this_type
= NULL
;
12374 case DW_TAG_class_type
:
12375 case DW_TAG_interface_type
:
12376 case DW_TAG_structure_type
:
12377 case DW_TAG_union_type
:
12378 this_type
= read_structure_type (die
, cu
);
12380 case DW_TAG_enumeration_type
:
12381 this_type
= read_enumeration_type (die
, cu
);
12383 case DW_TAG_subprogram
:
12384 case DW_TAG_subroutine_type
:
12385 case DW_TAG_inlined_subroutine
:
12386 this_type
= read_subroutine_type (die
, cu
);
12388 case DW_TAG_array_type
:
12389 this_type
= read_array_type (die
, cu
);
12391 case DW_TAG_set_type
:
12392 this_type
= read_set_type (die
, cu
);
12394 case DW_TAG_pointer_type
:
12395 this_type
= read_tag_pointer_type (die
, cu
);
12397 case DW_TAG_ptr_to_member_type
:
12398 this_type
= read_tag_ptr_to_member_type (die
, cu
);
12400 case DW_TAG_reference_type
:
12401 this_type
= read_tag_reference_type (die
, cu
);
12403 case DW_TAG_const_type
:
12404 this_type
= read_tag_const_type (die
, cu
);
12406 case DW_TAG_volatile_type
:
12407 this_type
= read_tag_volatile_type (die
, cu
);
12409 case DW_TAG_string_type
:
12410 this_type
= read_tag_string_type (die
, cu
);
12412 case DW_TAG_typedef
:
12413 this_type
= read_typedef (die
, cu
);
12415 case DW_TAG_subrange_type
:
12416 this_type
= read_subrange_type (die
, cu
);
12418 case DW_TAG_base_type
:
12419 this_type
= read_base_type (die
, cu
);
12421 case DW_TAG_unspecified_type
:
12422 this_type
= read_unspecified_type (die
, cu
);
12424 case DW_TAG_namespace
:
12425 this_type
= read_namespace_type (die
, cu
);
12427 case DW_TAG_module
:
12428 this_type
= read_module_type (die
, cu
);
12431 complaint (&symfile_complaints
,
12432 _("unexpected tag in read_type_die: '%s'"),
12433 dwarf_tag_name (die
->tag
));
12440 /* See if we can figure out if the class lives in a namespace. We do
12441 this by looking for a member function; its demangled name will
12442 contain namespace info, if there is any.
12443 Return the computed name or NULL.
12444 Space for the result is allocated on the objfile's obstack.
12445 This is the full-die version of guess_partial_die_structure_name.
12446 In this case we know DIE has no useful parent. */
12449 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12451 struct die_info
*spec_die
;
12452 struct dwarf2_cu
*spec_cu
;
12453 struct die_info
*child
;
12456 spec_die
= die_specification (die
, &spec_cu
);
12457 if (spec_die
!= NULL
)
12463 for (child
= die
->child
;
12465 child
= child
->sibling
)
12467 if (child
->tag
== DW_TAG_subprogram
)
12469 struct attribute
*attr
;
12471 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
12473 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
12477 = language_class_name_from_physname (cu
->language_defn
,
12481 if (actual_name
!= NULL
)
12483 char *die_name
= dwarf2_name (die
, cu
);
12485 if (die_name
!= NULL
12486 && strcmp (die_name
, actual_name
) != 0)
12488 /* Strip off the class name from the full name.
12489 We want the prefix. */
12490 int die_name_len
= strlen (die_name
);
12491 int actual_name_len
= strlen (actual_name
);
12493 /* Test for '::' as a sanity check. */
12494 if (actual_name_len
> die_name_len
+ 2
12495 && actual_name
[actual_name_len
12496 - die_name_len
- 1] == ':')
12498 obsavestring (actual_name
,
12499 actual_name_len
- die_name_len
- 2,
12500 &cu
->objfile
->objfile_obstack
);
12503 xfree (actual_name
);
12512 /* GCC might emit a nameless typedef that has a linkage name. Determine the
12513 prefix part in such case. See
12514 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12517 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
12519 struct attribute
*attr
;
12522 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
12523 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
12526 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
12527 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
12530 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
12532 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
12533 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
12536 /* dwarf2_name had to be already called. */
12537 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
12539 /* Strip the base name, keep any leading namespaces/classes. */
12540 base
= strrchr (DW_STRING (attr
), ':');
12541 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
12544 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
12545 &cu
->objfile
->objfile_obstack
);
12548 /* Return the name of the namespace/class that DIE is defined within,
12549 or "" if we can't tell. The caller should not xfree the result.
12551 For example, if we're within the method foo() in the following
12561 then determine_prefix on foo's die will return "N::C". */
12563 static const char *
12564 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
12566 struct die_info
*parent
, *spec_die
;
12567 struct dwarf2_cu
*spec_cu
;
12568 struct type
*parent_type
;
12571 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
12572 && cu
->language
!= language_fortran
)
12575 retval
= anonymous_struct_prefix (die
, cu
);
12579 /* We have to be careful in the presence of DW_AT_specification.
12580 For example, with GCC 3.4, given the code
12584 // Definition of N::foo.
12588 then we'll have a tree of DIEs like this:
12590 1: DW_TAG_compile_unit
12591 2: DW_TAG_namespace // N
12592 3: DW_TAG_subprogram // declaration of N::foo
12593 4: DW_TAG_subprogram // definition of N::foo
12594 DW_AT_specification // refers to die #3
12596 Thus, when processing die #4, we have to pretend that we're in
12597 the context of its DW_AT_specification, namely the contex of die
12600 spec_die
= die_specification (die
, &spec_cu
);
12601 if (spec_die
== NULL
)
12602 parent
= die
->parent
;
12605 parent
= spec_die
->parent
;
12609 if (parent
== NULL
)
12611 else if (parent
->building_fullname
)
12614 const char *parent_name
;
12616 /* It has been seen on RealView 2.2 built binaries,
12617 DW_TAG_template_type_param types actually _defined_ as
12618 children of the parent class:
12621 template class <class Enum> Class{};
12622 Class<enum E> class_e;
12624 1: DW_TAG_class_type (Class)
12625 2: DW_TAG_enumeration_type (E)
12626 3: DW_TAG_enumerator (enum1:0)
12627 3: DW_TAG_enumerator (enum2:1)
12629 2: DW_TAG_template_type_param
12630 DW_AT_type DW_FORM_ref_udata (E)
12632 Besides being broken debug info, it can put GDB into an
12633 infinite loop. Consider:
12635 When we're building the full name for Class<E>, we'll start
12636 at Class, and go look over its template type parameters,
12637 finding E. We'll then try to build the full name of E, and
12638 reach here. We're now trying to build the full name of E,
12639 and look over the parent DIE for containing scope. In the
12640 broken case, if we followed the parent DIE of E, we'd again
12641 find Class, and once again go look at its template type
12642 arguments, etc., etc. Simply don't consider such parent die
12643 as source-level parent of this die (it can't be, the language
12644 doesn't allow it), and break the loop here. */
12645 name
= dwarf2_name (die
, cu
);
12646 parent_name
= dwarf2_name (parent
, cu
);
12647 complaint (&symfile_complaints
,
12648 _("template param type '%s' defined within parent '%s'"),
12649 name
? name
: "<unknown>",
12650 parent_name
? parent_name
: "<unknown>");
12654 switch (parent
->tag
)
12656 case DW_TAG_namespace
:
12657 parent_type
= read_type_die (parent
, cu
);
12658 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
12659 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
12660 Work around this problem here. */
12661 if (cu
->language
== language_cplus
12662 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
12664 /* We give a name to even anonymous namespaces. */
12665 return TYPE_TAG_NAME (parent_type
);
12666 case DW_TAG_class_type
:
12667 case DW_TAG_interface_type
:
12668 case DW_TAG_structure_type
:
12669 case DW_TAG_union_type
:
12670 case DW_TAG_module
:
12671 parent_type
= read_type_die (parent
, cu
);
12672 if (TYPE_TAG_NAME (parent_type
) != NULL
)
12673 return TYPE_TAG_NAME (parent_type
);
12675 /* An anonymous structure is only allowed non-static data
12676 members; no typedefs, no member functions, et cetera.
12677 So it does not need a prefix. */
12679 case DW_TAG_compile_unit
:
12680 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
12681 if (cu
->language
== language_cplus
12682 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
12683 && die
->child
!= NULL
12684 && (die
->tag
== DW_TAG_class_type
12685 || die
->tag
== DW_TAG_structure_type
12686 || die
->tag
== DW_TAG_union_type
))
12688 char *name
= guess_full_die_structure_name (die
, cu
);
12694 return determine_prefix (parent
, cu
);
12698 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
12699 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
12700 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
12701 an obconcat, otherwise allocate storage for the result. The CU argument is
12702 used to determine the language and hence, the appropriate separator. */
12704 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
12707 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
12708 int physname
, struct dwarf2_cu
*cu
)
12710 const char *lead
= "";
12713 if (suffix
== NULL
|| suffix
[0] == '\0'
12714 || prefix
== NULL
|| prefix
[0] == '\0')
12716 else if (cu
->language
== language_java
)
12718 else if (cu
->language
== language_fortran
&& physname
)
12720 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
12721 DW_AT_MIPS_linkage_name is preferred and used instead. */
12729 if (prefix
== NULL
)
12731 if (suffix
== NULL
)
12737 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
12739 strcpy (retval
, lead
);
12740 strcat (retval
, prefix
);
12741 strcat (retval
, sep
);
12742 strcat (retval
, suffix
);
12747 /* We have an obstack. */
12748 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
12752 /* Return sibling of die, NULL if no sibling. */
12754 static struct die_info
*
12755 sibling_die (struct die_info
*die
)
12757 return die
->sibling
;
12760 /* Get name of a die, return NULL if not found. */
12763 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
12764 struct obstack
*obstack
)
12766 if (name
&& cu
->language
== language_cplus
)
12768 char *canon_name
= cp_canonicalize_string (name
);
12770 if (canon_name
!= NULL
)
12772 if (strcmp (canon_name
, name
) != 0)
12773 name
= obsavestring (canon_name
, strlen (canon_name
),
12775 xfree (canon_name
);
12782 /* Get name of a die, return NULL if not found. */
12785 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12787 struct attribute
*attr
;
12789 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
12790 if ((!attr
|| !DW_STRING (attr
))
12791 && die
->tag
!= DW_TAG_class_type
12792 && die
->tag
!= DW_TAG_interface_type
12793 && die
->tag
!= DW_TAG_structure_type
12794 && die
->tag
!= DW_TAG_union_type
)
12799 case DW_TAG_compile_unit
:
12800 /* Compilation units have a DW_AT_name that is a filename, not
12801 a source language identifier. */
12802 case DW_TAG_enumeration_type
:
12803 case DW_TAG_enumerator
:
12804 /* These tags always have simple identifiers already; no need
12805 to canonicalize them. */
12806 return DW_STRING (attr
);
12808 case DW_TAG_subprogram
:
12809 /* Java constructors will all be named "<init>", so return
12810 the class name when we see this special case. */
12811 if (cu
->language
== language_java
12812 && DW_STRING (attr
) != NULL
12813 && strcmp (DW_STRING (attr
), "<init>") == 0)
12815 struct dwarf2_cu
*spec_cu
= cu
;
12816 struct die_info
*spec_die
;
12818 /* GCJ will output '<init>' for Java constructor names.
12819 For this special case, return the name of the parent class. */
12821 /* GCJ may output suprogram DIEs with AT_specification set.
12822 If so, use the name of the specified DIE. */
12823 spec_die
= die_specification (die
, &spec_cu
);
12824 if (spec_die
!= NULL
)
12825 return dwarf2_name (spec_die
, spec_cu
);
12830 if (die
->tag
== DW_TAG_class_type
)
12831 return dwarf2_name (die
, cu
);
12833 while (die
->tag
!= DW_TAG_compile_unit
);
12837 case DW_TAG_class_type
:
12838 case DW_TAG_interface_type
:
12839 case DW_TAG_structure_type
:
12840 case DW_TAG_union_type
:
12841 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
12842 structures or unions. These were of the form "._%d" in GCC 4.1,
12843 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
12844 and GCC 4.4. We work around this problem by ignoring these. */
12845 if (attr
&& DW_STRING (attr
)
12846 && (strncmp (DW_STRING (attr
), "._", 2) == 0
12847 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
12850 /* GCC might emit a nameless typedef that has a linkage name. See
12851 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12852 if (!attr
|| DW_STRING (attr
) == NULL
)
12854 char *demangled
= NULL
;
12856 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
12858 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
12860 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
12863 /* Avoid demangling DW_STRING (attr) the second time on a second
12864 call for the same DIE. */
12865 if (!DW_STRING_IS_CANONICAL (attr
))
12866 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
12872 /* FIXME: we already did this for the partial symbol... */
12873 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
12874 &cu
->objfile
->objfile_obstack
);
12875 DW_STRING_IS_CANONICAL (attr
) = 1;
12878 /* Strip any leading namespaces/classes, keep only the base name.
12879 DW_AT_name for named DIEs does not contain the prefixes. */
12880 base
= strrchr (DW_STRING (attr
), ':');
12881 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
12884 return DW_STRING (attr
);
12893 if (!DW_STRING_IS_CANONICAL (attr
))
12896 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
12897 &cu
->objfile
->objfile_obstack
);
12898 DW_STRING_IS_CANONICAL (attr
) = 1;
12900 return DW_STRING (attr
);
12903 /* Return the die that this die in an extension of, or NULL if there
12904 is none. *EXT_CU is the CU containing DIE on input, and the CU
12905 containing the return value on output. */
12907 static struct die_info
*
12908 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
12910 struct attribute
*attr
;
12912 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
12916 return follow_die_ref (die
, attr
, ext_cu
);
12919 /* Convert a DIE tag into its string name. */
12922 dwarf_tag_name (unsigned tag
)
12926 case DW_TAG_padding
:
12927 return "DW_TAG_padding";
12928 case DW_TAG_array_type
:
12929 return "DW_TAG_array_type";
12930 case DW_TAG_class_type
:
12931 return "DW_TAG_class_type";
12932 case DW_TAG_entry_point
:
12933 return "DW_TAG_entry_point";
12934 case DW_TAG_enumeration_type
:
12935 return "DW_TAG_enumeration_type";
12936 case DW_TAG_formal_parameter
:
12937 return "DW_TAG_formal_parameter";
12938 case DW_TAG_imported_declaration
:
12939 return "DW_TAG_imported_declaration";
12941 return "DW_TAG_label";
12942 case DW_TAG_lexical_block
:
12943 return "DW_TAG_lexical_block";
12944 case DW_TAG_member
:
12945 return "DW_TAG_member";
12946 case DW_TAG_pointer_type
:
12947 return "DW_TAG_pointer_type";
12948 case DW_TAG_reference_type
:
12949 return "DW_TAG_reference_type";
12950 case DW_TAG_compile_unit
:
12951 return "DW_TAG_compile_unit";
12952 case DW_TAG_string_type
:
12953 return "DW_TAG_string_type";
12954 case DW_TAG_structure_type
:
12955 return "DW_TAG_structure_type";
12956 case DW_TAG_subroutine_type
:
12957 return "DW_TAG_subroutine_type";
12958 case DW_TAG_typedef
:
12959 return "DW_TAG_typedef";
12960 case DW_TAG_union_type
:
12961 return "DW_TAG_union_type";
12962 case DW_TAG_unspecified_parameters
:
12963 return "DW_TAG_unspecified_parameters";
12964 case DW_TAG_variant
:
12965 return "DW_TAG_variant";
12966 case DW_TAG_common_block
:
12967 return "DW_TAG_common_block";
12968 case DW_TAG_common_inclusion
:
12969 return "DW_TAG_common_inclusion";
12970 case DW_TAG_inheritance
:
12971 return "DW_TAG_inheritance";
12972 case DW_TAG_inlined_subroutine
:
12973 return "DW_TAG_inlined_subroutine";
12974 case DW_TAG_module
:
12975 return "DW_TAG_module";
12976 case DW_TAG_ptr_to_member_type
:
12977 return "DW_TAG_ptr_to_member_type";
12978 case DW_TAG_set_type
:
12979 return "DW_TAG_set_type";
12980 case DW_TAG_subrange_type
:
12981 return "DW_TAG_subrange_type";
12982 case DW_TAG_with_stmt
:
12983 return "DW_TAG_with_stmt";
12984 case DW_TAG_access_declaration
:
12985 return "DW_TAG_access_declaration";
12986 case DW_TAG_base_type
:
12987 return "DW_TAG_base_type";
12988 case DW_TAG_catch_block
:
12989 return "DW_TAG_catch_block";
12990 case DW_TAG_const_type
:
12991 return "DW_TAG_const_type";
12992 case DW_TAG_constant
:
12993 return "DW_TAG_constant";
12994 case DW_TAG_enumerator
:
12995 return "DW_TAG_enumerator";
12996 case DW_TAG_file_type
:
12997 return "DW_TAG_file_type";
12998 case DW_TAG_friend
:
12999 return "DW_TAG_friend";
13000 case DW_TAG_namelist
:
13001 return "DW_TAG_namelist";
13002 case DW_TAG_namelist_item
:
13003 return "DW_TAG_namelist_item";
13004 case DW_TAG_packed_type
:
13005 return "DW_TAG_packed_type";
13006 case DW_TAG_subprogram
:
13007 return "DW_TAG_subprogram";
13008 case DW_TAG_template_type_param
:
13009 return "DW_TAG_template_type_param";
13010 case DW_TAG_template_value_param
:
13011 return "DW_TAG_template_value_param";
13012 case DW_TAG_thrown_type
:
13013 return "DW_TAG_thrown_type";
13014 case DW_TAG_try_block
:
13015 return "DW_TAG_try_block";
13016 case DW_TAG_variant_part
:
13017 return "DW_TAG_variant_part";
13018 case DW_TAG_variable
:
13019 return "DW_TAG_variable";
13020 case DW_TAG_volatile_type
:
13021 return "DW_TAG_volatile_type";
13022 case DW_TAG_dwarf_procedure
:
13023 return "DW_TAG_dwarf_procedure";
13024 case DW_TAG_restrict_type
:
13025 return "DW_TAG_restrict_type";
13026 case DW_TAG_interface_type
:
13027 return "DW_TAG_interface_type";
13028 case DW_TAG_namespace
:
13029 return "DW_TAG_namespace";
13030 case DW_TAG_imported_module
:
13031 return "DW_TAG_imported_module";
13032 case DW_TAG_unspecified_type
:
13033 return "DW_TAG_unspecified_type";
13034 case DW_TAG_partial_unit
:
13035 return "DW_TAG_partial_unit";
13036 case DW_TAG_imported_unit
:
13037 return "DW_TAG_imported_unit";
13038 case DW_TAG_condition
:
13039 return "DW_TAG_condition";
13040 case DW_TAG_shared_type
:
13041 return "DW_TAG_shared_type";
13042 case DW_TAG_type_unit
:
13043 return "DW_TAG_type_unit";
13044 case DW_TAG_MIPS_loop
:
13045 return "DW_TAG_MIPS_loop";
13046 case DW_TAG_HP_array_descriptor
:
13047 return "DW_TAG_HP_array_descriptor";
13048 case DW_TAG_format_label
:
13049 return "DW_TAG_format_label";
13050 case DW_TAG_function_template
:
13051 return "DW_TAG_function_template";
13052 case DW_TAG_class_template
:
13053 return "DW_TAG_class_template";
13054 case DW_TAG_GNU_BINCL
:
13055 return "DW_TAG_GNU_BINCL";
13056 case DW_TAG_GNU_EINCL
:
13057 return "DW_TAG_GNU_EINCL";
13058 case DW_TAG_upc_shared_type
:
13059 return "DW_TAG_upc_shared_type";
13060 case DW_TAG_upc_strict_type
:
13061 return "DW_TAG_upc_strict_type";
13062 case DW_TAG_upc_relaxed_type
:
13063 return "DW_TAG_upc_relaxed_type";
13064 case DW_TAG_PGI_kanji_type
:
13065 return "DW_TAG_PGI_kanji_type";
13066 case DW_TAG_PGI_interface_block
:
13067 return "DW_TAG_PGI_interface_block";
13068 case DW_TAG_GNU_call_site
:
13069 return "DW_TAG_GNU_call_site";
13071 return "DW_TAG_<unknown>";
13075 /* Convert a DWARF attribute code into its string name. */
13078 dwarf_attr_name (unsigned attr
)
13082 case DW_AT_sibling
:
13083 return "DW_AT_sibling";
13084 case DW_AT_location
:
13085 return "DW_AT_location";
13087 return "DW_AT_name";
13088 case DW_AT_ordering
:
13089 return "DW_AT_ordering";
13090 case DW_AT_subscr_data
:
13091 return "DW_AT_subscr_data";
13092 case DW_AT_byte_size
:
13093 return "DW_AT_byte_size";
13094 case DW_AT_bit_offset
:
13095 return "DW_AT_bit_offset";
13096 case DW_AT_bit_size
:
13097 return "DW_AT_bit_size";
13098 case DW_AT_element_list
:
13099 return "DW_AT_element_list";
13100 case DW_AT_stmt_list
:
13101 return "DW_AT_stmt_list";
13103 return "DW_AT_low_pc";
13104 case DW_AT_high_pc
:
13105 return "DW_AT_high_pc";
13106 case DW_AT_language
:
13107 return "DW_AT_language";
13109 return "DW_AT_member";
13111 return "DW_AT_discr";
13112 case DW_AT_discr_value
:
13113 return "DW_AT_discr_value";
13114 case DW_AT_visibility
:
13115 return "DW_AT_visibility";
13117 return "DW_AT_import";
13118 case DW_AT_string_length
:
13119 return "DW_AT_string_length";
13120 case DW_AT_common_reference
:
13121 return "DW_AT_common_reference";
13122 case DW_AT_comp_dir
:
13123 return "DW_AT_comp_dir";
13124 case DW_AT_const_value
:
13125 return "DW_AT_const_value";
13126 case DW_AT_containing_type
:
13127 return "DW_AT_containing_type";
13128 case DW_AT_default_value
:
13129 return "DW_AT_default_value";
13131 return "DW_AT_inline";
13132 case DW_AT_is_optional
:
13133 return "DW_AT_is_optional";
13134 case DW_AT_lower_bound
:
13135 return "DW_AT_lower_bound";
13136 case DW_AT_producer
:
13137 return "DW_AT_producer";
13138 case DW_AT_prototyped
:
13139 return "DW_AT_prototyped";
13140 case DW_AT_return_addr
:
13141 return "DW_AT_return_addr";
13142 case DW_AT_start_scope
:
13143 return "DW_AT_start_scope";
13144 case DW_AT_bit_stride
:
13145 return "DW_AT_bit_stride";
13146 case DW_AT_upper_bound
:
13147 return "DW_AT_upper_bound";
13148 case DW_AT_abstract_origin
:
13149 return "DW_AT_abstract_origin";
13150 case DW_AT_accessibility
:
13151 return "DW_AT_accessibility";
13152 case DW_AT_address_class
:
13153 return "DW_AT_address_class";
13154 case DW_AT_artificial
:
13155 return "DW_AT_artificial";
13156 case DW_AT_base_types
:
13157 return "DW_AT_base_types";
13158 case DW_AT_calling_convention
:
13159 return "DW_AT_calling_convention";
13161 return "DW_AT_count";
13162 case DW_AT_data_member_location
:
13163 return "DW_AT_data_member_location";
13164 case DW_AT_decl_column
:
13165 return "DW_AT_decl_column";
13166 case DW_AT_decl_file
:
13167 return "DW_AT_decl_file";
13168 case DW_AT_decl_line
:
13169 return "DW_AT_decl_line";
13170 case DW_AT_declaration
:
13171 return "DW_AT_declaration";
13172 case DW_AT_discr_list
:
13173 return "DW_AT_discr_list";
13174 case DW_AT_encoding
:
13175 return "DW_AT_encoding";
13176 case DW_AT_external
:
13177 return "DW_AT_external";
13178 case DW_AT_frame_base
:
13179 return "DW_AT_frame_base";
13181 return "DW_AT_friend";
13182 case DW_AT_identifier_case
:
13183 return "DW_AT_identifier_case";
13184 case DW_AT_macro_info
:
13185 return "DW_AT_macro_info";
13186 case DW_AT_namelist_items
:
13187 return "DW_AT_namelist_items";
13188 case DW_AT_priority
:
13189 return "DW_AT_priority";
13190 case DW_AT_segment
:
13191 return "DW_AT_segment";
13192 case DW_AT_specification
:
13193 return "DW_AT_specification";
13194 case DW_AT_static_link
:
13195 return "DW_AT_static_link";
13197 return "DW_AT_type";
13198 case DW_AT_use_location
:
13199 return "DW_AT_use_location";
13200 case DW_AT_variable_parameter
:
13201 return "DW_AT_variable_parameter";
13202 case DW_AT_virtuality
:
13203 return "DW_AT_virtuality";
13204 case DW_AT_vtable_elem_location
:
13205 return "DW_AT_vtable_elem_location";
13206 /* DWARF 3 values. */
13207 case DW_AT_allocated
:
13208 return "DW_AT_allocated";
13209 case DW_AT_associated
:
13210 return "DW_AT_associated";
13211 case DW_AT_data_location
:
13212 return "DW_AT_data_location";
13213 case DW_AT_byte_stride
:
13214 return "DW_AT_byte_stride";
13215 case DW_AT_entry_pc
:
13216 return "DW_AT_entry_pc";
13217 case DW_AT_use_UTF8
:
13218 return "DW_AT_use_UTF8";
13219 case DW_AT_extension
:
13220 return "DW_AT_extension";
13222 return "DW_AT_ranges";
13223 case DW_AT_trampoline
:
13224 return "DW_AT_trampoline";
13225 case DW_AT_call_column
:
13226 return "DW_AT_call_column";
13227 case DW_AT_call_file
:
13228 return "DW_AT_call_file";
13229 case DW_AT_call_line
:
13230 return "DW_AT_call_line";
13231 case DW_AT_description
:
13232 return "DW_AT_description";
13233 case DW_AT_binary_scale
:
13234 return "DW_AT_binary_scale";
13235 case DW_AT_decimal_scale
:
13236 return "DW_AT_decimal_scale";
13238 return "DW_AT_small";
13239 case DW_AT_decimal_sign
:
13240 return "DW_AT_decimal_sign";
13241 case DW_AT_digit_count
:
13242 return "DW_AT_digit_count";
13243 case DW_AT_picture_string
:
13244 return "DW_AT_picture_string";
13245 case DW_AT_mutable
:
13246 return "DW_AT_mutable";
13247 case DW_AT_threads_scaled
:
13248 return "DW_AT_threads_scaled";
13249 case DW_AT_explicit
:
13250 return "DW_AT_explicit";
13251 case DW_AT_object_pointer
:
13252 return "DW_AT_object_pointer";
13253 case DW_AT_endianity
:
13254 return "DW_AT_endianity";
13255 case DW_AT_elemental
:
13256 return "DW_AT_elemental";
13258 return "DW_AT_pure";
13259 case DW_AT_recursive
:
13260 return "DW_AT_recursive";
13261 /* DWARF 4 values. */
13262 case DW_AT_signature
:
13263 return "DW_AT_signature";
13264 case DW_AT_linkage_name
:
13265 return "DW_AT_linkage_name";
13266 /* SGI/MIPS extensions. */
13267 #ifdef MIPS /* collides with DW_AT_HP_block_index */
13268 case DW_AT_MIPS_fde
:
13269 return "DW_AT_MIPS_fde";
13271 case DW_AT_MIPS_loop_begin
:
13272 return "DW_AT_MIPS_loop_begin";
13273 case DW_AT_MIPS_tail_loop_begin
:
13274 return "DW_AT_MIPS_tail_loop_begin";
13275 case DW_AT_MIPS_epilog_begin
:
13276 return "DW_AT_MIPS_epilog_begin";
13277 case DW_AT_MIPS_loop_unroll_factor
:
13278 return "DW_AT_MIPS_loop_unroll_factor";
13279 case DW_AT_MIPS_software_pipeline_depth
:
13280 return "DW_AT_MIPS_software_pipeline_depth";
13281 case DW_AT_MIPS_linkage_name
:
13282 return "DW_AT_MIPS_linkage_name";
13283 case DW_AT_MIPS_stride
:
13284 return "DW_AT_MIPS_stride";
13285 case DW_AT_MIPS_abstract_name
:
13286 return "DW_AT_MIPS_abstract_name";
13287 case DW_AT_MIPS_clone_origin
:
13288 return "DW_AT_MIPS_clone_origin";
13289 case DW_AT_MIPS_has_inlines
:
13290 return "DW_AT_MIPS_has_inlines";
13291 /* HP extensions. */
13292 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
13293 case DW_AT_HP_block_index
:
13294 return "DW_AT_HP_block_index";
13296 case DW_AT_HP_unmodifiable
:
13297 return "DW_AT_HP_unmodifiable";
13298 case DW_AT_HP_actuals_stmt_list
:
13299 return "DW_AT_HP_actuals_stmt_list";
13300 case DW_AT_HP_proc_per_section
:
13301 return "DW_AT_HP_proc_per_section";
13302 case DW_AT_HP_raw_data_ptr
:
13303 return "DW_AT_HP_raw_data_ptr";
13304 case DW_AT_HP_pass_by_reference
:
13305 return "DW_AT_HP_pass_by_reference";
13306 case DW_AT_HP_opt_level
:
13307 return "DW_AT_HP_opt_level";
13308 case DW_AT_HP_prof_version_id
:
13309 return "DW_AT_HP_prof_version_id";
13310 case DW_AT_HP_opt_flags
:
13311 return "DW_AT_HP_opt_flags";
13312 case DW_AT_HP_cold_region_low_pc
:
13313 return "DW_AT_HP_cold_region_low_pc";
13314 case DW_AT_HP_cold_region_high_pc
:
13315 return "DW_AT_HP_cold_region_high_pc";
13316 case DW_AT_HP_all_variables_modifiable
:
13317 return "DW_AT_HP_all_variables_modifiable";
13318 case DW_AT_HP_linkage_name
:
13319 return "DW_AT_HP_linkage_name";
13320 case DW_AT_HP_prof_flags
:
13321 return "DW_AT_HP_prof_flags";
13322 /* GNU extensions. */
13323 case DW_AT_sf_names
:
13324 return "DW_AT_sf_names";
13325 case DW_AT_src_info
:
13326 return "DW_AT_src_info";
13327 case DW_AT_mac_info
:
13328 return "DW_AT_mac_info";
13329 case DW_AT_src_coords
:
13330 return "DW_AT_src_coords";
13331 case DW_AT_body_begin
:
13332 return "DW_AT_body_begin";
13333 case DW_AT_body_end
:
13334 return "DW_AT_body_end";
13335 case DW_AT_GNU_vector
:
13336 return "DW_AT_GNU_vector";
13337 case DW_AT_GNU_odr_signature
:
13338 return "DW_AT_GNU_odr_signature";
13339 /* VMS extensions. */
13340 case DW_AT_VMS_rtnbeg_pd_address
:
13341 return "DW_AT_VMS_rtnbeg_pd_address";
13342 /* UPC extension. */
13343 case DW_AT_upc_threads_scaled
:
13344 return "DW_AT_upc_threads_scaled";
13345 /* PGI (STMicroelectronics) extensions. */
13346 case DW_AT_PGI_lbase
:
13347 return "DW_AT_PGI_lbase";
13348 case DW_AT_PGI_soffset
:
13349 return "DW_AT_PGI_soffset";
13350 case DW_AT_PGI_lstride
:
13351 return "DW_AT_PGI_lstride";
13353 return "DW_AT_<unknown>";
13357 /* Convert a DWARF value form code into its string name. */
13360 dwarf_form_name (unsigned form
)
13365 return "DW_FORM_addr";
13366 case DW_FORM_block2
:
13367 return "DW_FORM_block2";
13368 case DW_FORM_block4
:
13369 return "DW_FORM_block4";
13370 case DW_FORM_data2
:
13371 return "DW_FORM_data2";
13372 case DW_FORM_data4
:
13373 return "DW_FORM_data4";
13374 case DW_FORM_data8
:
13375 return "DW_FORM_data8";
13376 case DW_FORM_string
:
13377 return "DW_FORM_string";
13378 case DW_FORM_block
:
13379 return "DW_FORM_block";
13380 case DW_FORM_block1
:
13381 return "DW_FORM_block1";
13382 case DW_FORM_data1
:
13383 return "DW_FORM_data1";
13385 return "DW_FORM_flag";
13386 case DW_FORM_sdata
:
13387 return "DW_FORM_sdata";
13389 return "DW_FORM_strp";
13390 case DW_FORM_udata
:
13391 return "DW_FORM_udata";
13392 case DW_FORM_ref_addr
:
13393 return "DW_FORM_ref_addr";
13395 return "DW_FORM_ref1";
13397 return "DW_FORM_ref2";
13399 return "DW_FORM_ref4";
13401 return "DW_FORM_ref8";
13402 case DW_FORM_ref_udata
:
13403 return "DW_FORM_ref_udata";
13404 case DW_FORM_indirect
:
13405 return "DW_FORM_indirect";
13406 case DW_FORM_sec_offset
:
13407 return "DW_FORM_sec_offset";
13408 case DW_FORM_exprloc
:
13409 return "DW_FORM_exprloc";
13410 case DW_FORM_flag_present
:
13411 return "DW_FORM_flag_present";
13412 case DW_FORM_ref_sig8
:
13413 return "DW_FORM_ref_sig8";
13415 return "DW_FORM_<unknown>";
13419 /* Convert a DWARF stack opcode into its string name. */
13422 dwarf_stack_op_name (unsigned op
)
13427 return "DW_OP_addr";
13429 return "DW_OP_deref";
13430 case DW_OP_const1u
:
13431 return "DW_OP_const1u";
13432 case DW_OP_const1s
:
13433 return "DW_OP_const1s";
13434 case DW_OP_const2u
:
13435 return "DW_OP_const2u";
13436 case DW_OP_const2s
:
13437 return "DW_OP_const2s";
13438 case DW_OP_const4u
:
13439 return "DW_OP_const4u";
13440 case DW_OP_const4s
:
13441 return "DW_OP_const4s";
13442 case DW_OP_const8u
:
13443 return "DW_OP_const8u";
13444 case DW_OP_const8s
:
13445 return "DW_OP_const8s";
13447 return "DW_OP_constu";
13449 return "DW_OP_consts";
13451 return "DW_OP_dup";
13453 return "DW_OP_drop";
13455 return "DW_OP_over";
13457 return "DW_OP_pick";
13459 return "DW_OP_swap";
13461 return "DW_OP_rot";
13463 return "DW_OP_xderef";
13465 return "DW_OP_abs";
13467 return "DW_OP_and";
13469 return "DW_OP_div";
13471 return "DW_OP_minus";
13473 return "DW_OP_mod";
13475 return "DW_OP_mul";
13477 return "DW_OP_neg";
13479 return "DW_OP_not";
13483 return "DW_OP_plus";
13484 case DW_OP_plus_uconst
:
13485 return "DW_OP_plus_uconst";
13487 return "DW_OP_shl";
13489 return "DW_OP_shr";
13491 return "DW_OP_shra";
13493 return "DW_OP_xor";
13495 return "DW_OP_bra";
13509 return "DW_OP_skip";
13511 return "DW_OP_lit0";
13513 return "DW_OP_lit1";
13515 return "DW_OP_lit2";
13517 return "DW_OP_lit3";
13519 return "DW_OP_lit4";
13521 return "DW_OP_lit5";
13523 return "DW_OP_lit6";
13525 return "DW_OP_lit7";
13527 return "DW_OP_lit8";
13529 return "DW_OP_lit9";
13531 return "DW_OP_lit10";
13533 return "DW_OP_lit11";
13535 return "DW_OP_lit12";
13537 return "DW_OP_lit13";
13539 return "DW_OP_lit14";
13541 return "DW_OP_lit15";
13543 return "DW_OP_lit16";
13545 return "DW_OP_lit17";
13547 return "DW_OP_lit18";
13549 return "DW_OP_lit19";
13551 return "DW_OP_lit20";
13553 return "DW_OP_lit21";
13555 return "DW_OP_lit22";
13557 return "DW_OP_lit23";
13559 return "DW_OP_lit24";
13561 return "DW_OP_lit25";
13563 return "DW_OP_lit26";
13565 return "DW_OP_lit27";
13567 return "DW_OP_lit28";
13569 return "DW_OP_lit29";
13571 return "DW_OP_lit30";
13573 return "DW_OP_lit31";
13575 return "DW_OP_reg0";
13577 return "DW_OP_reg1";
13579 return "DW_OP_reg2";
13581 return "DW_OP_reg3";
13583 return "DW_OP_reg4";
13585 return "DW_OP_reg5";
13587 return "DW_OP_reg6";
13589 return "DW_OP_reg7";
13591 return "DW_OP_reg8";
13593 return "DW_OP_reg9";
13595 return "DW_OP_reg10";
13597 return "DW_OP_reg11";
13599 return "DW_OP_reg12";
13601 return "DW_OP_reg13";
13603 return "DW_OP_reg14";
13605 return "DW_OP_reg15";
13607 return "DW_OP_reg16";
13609 return "DW_OP_reg17";
13611 return "DW_OP_reg18";
13613 return "DW_OP_reg19";
13615 return "DW_OP_reg20";
13617 return "DW_OP_reg21";
13619 return "DW_OP_reg22";
13621 return "DW_OP_reg23";
13623 return "DW_OP_reg24";
13625 return "DW_OP_reg25";
13627 return "DW_OP_reg26";
13629 return "DW_OP_reg27";
13631 return "DW_OP_reg28";
13633 return "DW_OP_reg29";
13635 return "DW_OP_reg30";
13637 return "DW_OP_reg31";
13639 return "DW_OP_breg0";
13641 return "DW_OP_breg1";
13643 return "DW_OP_breg2";
13645 return "DW_OP_breg3";
13647 return "DW_OP_breg4";
13649 return "DW_OP_breg5";
13651 return "DW_OP_breg6";
13653 return "DW_OP_breg7";
13655 return "DW_OP_breg8";
13657 return "DW_OP_breg9";
13659 return "DW_OP_breg10";
13661 return "DW_OP_breg11";
13663 return "DW_OP_breg12";
13665 return "DW_OP_breg13";
13667 return "DW_OP_breg14";
13669 return "DW_OP_breg15";
13671 return "DW_OP_breg16";
13673 return "DW_OP_breg17";
13675 return "DW_OP_breg18";
13677 return "DW_OP_breg19";
13679 return "DW_OP_breg20";
13681 return "DW_OP_breg21";
13683 return "DW_OP_breg22";
13685 return "DW_OP_breg23";
13687 return "DW_OP_breg24";
13689 return "DW_OP_breg25";
13691 return "DW_OP_breg26";
13693 return "DW_OP_breg27";
13695 return "DW_OP_breg28";
13697 return "DW_OP_breg29";
13699 return "DW_OP_breg30";
13701 return "DW_OP_breg31";
13703 return "DW_OP_regx";
13705 return "DW_OP_fbreg";
13707 return "DW_OP_bregx";
13709 return "DW_OP_piece";
13710 case DW_OP_deref_size
:
13711 return "DW_OP_deref_size";
13712 case DW_OP_xderef_size
:
13713 return "DW_OP_xderef_size";
13715 return "DW_OP_nop";
13716 /* DWARF 3 extensions. */
13717 case DW_OP_push_object_address
:
13718 return "DW_OP_push_object_address";
13720 return "DW_OP_call2";
13722 return "DW_OP_call4";
13723 case DW_OP_call_ref
:
13724 return "DW_OP_call_ref";
13725 case DW_OP_form_tls_address
:
13726 return "DW_OP_form_tls_address";
13727 case DW_OP_call_frame_cfa
:
13728 return "DW_OP_call_frame_cfa";
13729 case DW_OP_bit_piece
:
13730 return "DW_OP_bit_piece";
13731 /* DWARF 4 extensions. */
13732 case DW_OP_implicit_value
:
13733 return "DW_OP_implicit_value";
13734 case DW_OP_stack_value
:
13735 return "DW_OP_stack_value";
13736 /* GNU extensions. */
13737 case DW_OP_GNU_push_tls_address
:
13738 return "DW_OP_GNU_push_tls_address";
13739 case DW_OP_GNU_uninit
:
13740 return "DW_OP_GNU_uninit";
13741 case DW_OP_GNU_encoded_addr
:
13742 return "DW_OP_GNU_encoded_addr";
13743 case DW_OP_GNU_implicit_pointer
:
13744 return "DW_OP_GNU_implicit_pointer";
13745 case DW_OP_GNU_entry_value
:
13746 return "DW_OP_GNU_entry_value";
13747 case DW_OP_GNU_const_type
:
13748 return "DW_OP_GNU_const_type";
13749 case DW_OP_GNU_regval_type
:
13750 return "DW_OP_GNU_regval_type";
13751 case DW_OP_GNU_deref_type
:
13752 return "DW_OP_GNU_deref_type";
13753 case DW_OP_GNU_convert
:
13754 return "DW_OP_GNU_convert";
13755 case DW_OP_GNU_reinterpret
:
13756 return "DW_OP_GNU_reinterpret";
13757 case DW_OP_GNU_parameter_ref
:
13758 return "DW_OP_GNU_parameter_ref";
13765 dwarf_bool_name (unsigned mybool
)
13773 /* Convert a DWARF type code into its string name. */
13776 dwarf_type_encoding_name (unsigned enc
)
13781 return "DW_ATE_void";
13782 case DW_ATE_address
:
13783 return "DW_ATE_address";
13784 case DW_ATE_boolean
:
13785 return "DW_ATE_boolean";
13786 case DW_ATE_complex_float
:
13787 return "DW_ATE_complex_float";
13789 return "DW_ATE_float";
13790 case DW_ATE_signed
:
13791 return "DW_ATE_signed";
13792 case DW_ATE_signed_char
:
13793 return "DW_ATE_signed_char";
13794 case DW_ATE_unsigned
:
13795 return "DW_ATE_unsigned";
13796 case DW_ATE_unsigned_char
:
13797 return "DW_ATE_unsigned_char";
13799 case DW_ATE_imaginary_float
:
13800 return "DW_ATE_imaginary_float";
13801 case DW_ATE_packed_decimal
:
13802 return "DW_ATE_packed_decimal";
13803 case DW_ATE_numeric_string
:
13804 return "DW_ATE_numeric_string";
13805 case DW_ATE_edited
:
13806 return "DW_ATE_edited";
13807 case DW_ATE_signed_fixed
:
13808 return "DW_ATE_signed_fixed";
13809 case DW_ATE_unsigned_fixed
:
13810 return "DW_ATE_unsigned_fixed";
13811 case DW_ATE_decimal_float
:
13812 return "DW_ATE_decimal_float";
13815 return "DW_ATE_UTF";
13816 /* HP extensions. */
13817 case DW_ATE_HP_float80
:
13818 return "DW_ATE_HP_float80";
13819 case DW_ATE_HP_complex_float80
:
13820 return "DW_ATE_HP_complex_float80";
13821 case DW_ATE_HP_float128
:
13822 return "DW_ATE_HP_float128";
13823 case DW_ATE_HP_complex_float128
:
13824 return "DW_ATE_HP_complex_float128";
13825 case DW_ATE_HP_floathpintel
:
13826 return "DW_ATE_HP_floathpintel";
13827 case DW_ATE_HP_imaginary_float80
:
13828 return "DW_ATE_HP_imaginary_float80";
13829 case DW_ATE_HP_imaginary_float128
:
13830 return "DW_ATE_HP_imaginary_float128";
13832 return "DW_ATE_<unknown>";
13836 /* Convert a DWARF call frame info operation to its string name. */
13840 dwarf_cfi_name (unsigned cfi_opc
)
13844 case DW_CFA_advance_loc
:
13845 return "DW_CFA_advance_loc";
13846 case DW_CFA_offset
:
13847 return "DW_CFA_offset";
13848 case DW_CFA_restore
:
13849 return "DW_CFA_restore";
13851 return "DW_CFA_nop";
13852 case DW_CFA_set_loc
:
13853 return "DW_CFA_set_loc";
13854 case DW_CFA_advance_loc1
:
13855 return "DW_CFA_advance_loc1";
13856 case DW_CFA_advance_loc2
:
13857 return "DW_CFA_advance_loc2";
13858 case DW_CFA_advance_loc4
:
13859 return "DW_CFA_advance_loc4";
13860 case DW_CFA_offset_extended
:
13861 return "DW_CFA_offset_extended";
13862 case DW_CFA_restore_extended
:
13863 return "DW_CFA_restore_extended";
13864 case DW_CFA_undefined
:
13865 return "DW_CFA_undefined";
13866 case DW_CFA_same_value
:
13867 return "DW_CFA_same_value";
13868 case DW_CFA_register
:
13869 return "DW_CFA_register";
13870 case DW_CFA_remember_state
:
13871 return "DW_CFA_remember_state";
13872 case DW_CFA_restore_state
:
13873 return "DW_CFA_restore_state";
13874 case DW_CFA_def_cfa
:
13875 return "DW_CFA_def_cfa";
13876 case DW_CFA_def_cfa_register
:
13877 return "DW_CFA_def_cfa_register";
13878 case DW_CFA_def_cfa_offset
:
13879 return "DW_CFA_def_cfa_offset";
13881 case DW_CFA_def_cfa_expression
:
13882 return "DW_CFA_def_cfa_expression";
13883 case DW_CFA_expression
:
13884 return "DW_CFA_expression";
13885 case DW_CFA_offset_extended_sf
:
13886 return "DW_CFA_offset_extended_sf";
13887 case DW_CFA_def_cfa_sf
:
13888 return "DW_CFA_def_cfa_sf";
13889 case DW_CFA_def_cfa_offset_sf
:
13890 return "DW_CFA_def_cfa_offset_sf";
13891 case DW_CFA_val_offset
:
13892 return "DW_CFA_val_offset";
13893 case DW_CFA_val_offset_sf
:
13894 return "DW_CFA_val_offset_sf";
13895 case DW_CFA_val_expression
:
13896 return "DW_CFA_val_expression";
13897 /* SGI/MIPS specific. */
13898 case DW_CFA_MIPS_advance_loc8
:
13899 return "DW_CFA_MIPS_advance_loc8";
13900 /* GNU extensions. */
13901 case DW_CFA_GNU_window_save
:
13902 return "DW_CFA_GNU_window_save";
13903 case DW_CFA_GNU_args_size
:
13904 return "DW_CFA_GNU_args_size";
13905 case DW_CFA_GNU_negative_offset_extended
:
13906 return "DW_CFA_GNU_negative_offset_extended";
13908 return "DW_CFA_<unknown>";
13914 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
13918 print_spaces (indent
, f
);
13919 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
13920 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
13922 if (die
->parent
!= NULL
)
13924 print_spaces (indent
, f
);
13925 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
13926 die
->parent
->offset
);
13929 print_spaces (indent
, f
);
13930 fprintf_unfiltered (f
, " has children: %s\n",
13931 dwarf_bool_name (die
->child
!= NULL
));
13933 print_spaces (indent
, f
);
13934 fprintf_unfiltered (f
, " attributes:\n");
13936 for (i
= 0; i
< die
->num_attrs
; ++i
)
13938 print_spaces (indent
, f
);
13939 fprintf_unfiltered (f
, " %s (%s) ",
13940 dwarf_attr_name (die
->attrs
[i
].name
),
13941 dwarf_form_name (die
->attrs
[i
].form
));
13943 switch (die
->attrs
[i
].form
)
13945 case DW_FORM_ref_addr
:
13947 fprintf_unfiltered (f
, "address: ");
13948 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
13950 case DW_FORM_block2
:
13951 case DW_FORM_block4
:
13952 case DW_FORM_block
:
13953 case DW_FORM_block1
:
13954 fprintf_unfiltered (f
, "block: size %d",
13955 DW_BLOCK (&die
->attrs
[i
])->size
);
13957 case DW_FORM_exprloc
:
13958 fprintf_unfiltered (f
, "expression: size %u",
13959 DW_BLOCK (&die
->attrs
[i
])->size
);
13964 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
13965 (long) (DW_ADDR (&die
->attrs
[i
])));
13967 case DW_FORM_data1
:
13968 case DW_FORM_data2
:
13969 case DW_FORM_data4
:
13970 case DW_FORM_data8
:
13971 case DW_FORM_udata
:
13972 case DW_FORM_sdata
:
13973 fprintf_unfiltered (f
, "constant: %s",
13974 pulongest (DW_UNSND (&die
->attrs
[i
])));
13976 case DW_FORM_sec_offset
:
13977 fprintf_unfiltered (f
, "section offset: %s",
13978 pulongest (DW_UNSND (&die
->attrs
[i
])));
13980 case DW_FORM_ref_sig8
:
13981 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
13982 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
13983 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
);
13985 fprintf_unfiltered (f
, "signatured type, offset: unknown");
13987 case DW_FORM_string
:
13989 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
13990 DW_STRING (&die
->attrs
[i
])
13991 ? DW_STRING (&die
->attrs
[i
]) : "",
13992 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
13995 if (DW_UNSND (&die
->attrs
[i
]))
13996 fprintf_unfiltered (f
, "flag: TRUE");
13998 fprintf_unfiltered (f
, "flag: FALSE");
14000 case DW_FORM_flag_present
:
14001 fprintf_unfiltered (f
, "flag: TRUE");
14003 case DW_FORM_indirect
:
14004 /* The reader will have reduced the indirect form to
14005 the "base form" so this form should not occur. */
14006 fprintf_unfiltered (f
,
14007 "unexpected attribute form: DW_FORM_indirect");
14010 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
14011 die
->attrs
[i
].form
);
14014 fprintf_unfiltered (f
, "\n");
14019 dump_die_for_error (struct die_info
*die
)
14021 dump_die_shallow (gdb_stderr
, 0, die
);
14025 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
14027 int indent
= level
* 4;
14029 gdb_assert (die
!= NULL
);
14031 if (level
>= max_level
)
14034 dump_die_shallow (f
, indent
, die
);
14036 if (die
->child
!= NULL
)
14038 print_spaces (indent
, f
);
14039 fprintf_unfiltered (f
, " Children:");
14040 if (level
+ 1 < max_level
)
14042 fprintf_unfiltered (f
, "\n");
14043 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
14047 fprintf_unfiltered (f
,
14048 " [not printed, max nesting level reached]\n");
14052 if (die
->sibling
!= NULL
&& level
> 0)
14054 dump_die_1 (f
, level
, max_level
, die
->sibling
);
14058 /* This is called from the pdie macro in gdbinit.in.
14059 It's not static so gcc will keep a copy callable from gdb. */
14062 dump_die (struct die_info
*die
, int max_level
)
14064 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
14068 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
14072 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
14078 is_ref_attr (struct attribute
*attr
)
14080 switch (attr
->form
)
14082 case DW_FORM_ref_addr
:
14087 case DW_FORM_ref_udata
:
14094 static unsigned int
14095 dwarf2_get_ref_die_offset (struct attribute
*attr
)
14097 if (is_ref_attr (attr
))
14098 return DW_ADDR (attr
);
14100 complaint (&symfile_complaints
,
14101 _("unsupported die ref attribute form: '%s'"),
14102 dwarf_form_name (attr
->form
));
14106 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
14107 * the value held by the attribute is not constant. */
14110 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
14112 if (attr
->form
== DW_FORM_sdata
)
14113 return DW_SND (attr
);
14114 else if (attr
->form
== DW_FORM_udata
14115 || attr
->form
== DW_FORM_data1
14116 || attr
->form
== DW_FORM_data2
14117 || attr
->form
== DW_FORM_data4
14118 || attr
->form
== DW_FORM_data8
)
14119 return DW_UNSND (attr
);
14122 complaint (&symfile_complaints
,
14123 _("Attribute value is not a constant (%s)"),
14124 dwarf_form_name (attr
->form
));
14125 return default_value
;
14129 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
14130 unit and add it to our queue.
14131 The result is non-zero if PER_CU was queued, otherwise the result is zero
14132 meaning either PER_CU is already queued or it is already loaded. */
14135 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
14136 struct dwarf2_per_cu_data
*per_cu
)
14138 /* We may arrive here during partial symbol reading, if we need full
14139 DIEs to process an unusual case (e.g. template arguments). Do
14140 not queue PER_CU, just tell our caller to load its DIEs. */
14141 if (dwarf2_per_objfile
->reading_partial_symbols
)
14143 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
14148 /* Mark the dependence relation so that we don't flush PER_CU
14150 dwarf2_add_dependence (this_cu
, per_cu
);
14152 /* If it's already on the queue, we have nothing to do. */
14153 if (per_cu
->queued
)
14156 /* If the compilation unit is already loaded, just mark it as
14158 if (per_cu
->cu
!= NULL
)
14160 per_cu
->cu
->last_used
= 0;
14164 /* Add it to the queue. */
14165 queue_comp_unit (per_cu
);
14170 /* Follow reference or signature attribute ATTR of SRC_DIE.
14171 On entry *REF_CU is the CU of SRC_DIE.
14172 On exit *REF_CU is the CU of the result. */
14174 static struct die_info
*
14175 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
14176 struct dwarf2_cu
**ref_cu
)
14178 struct die_info
*die
;
14180 if (is_ref_attr (attr
))
14181 die
= follow_die_ref (src_die
, attr
, ref_cu
);
14182 else if (attr
->form
== DW_FORM_ref_sig8
)
14183 die
= follow_die_sig (src_die
, attr
, ref_cu
);
14186 dump_die_for_error (src_die
);
14187 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
14188 (*ref_cu
)->objfile
->name
);
14194 /* Follow reference OFFSET.
14195 On entry *REF_CU is the CU of the source die referencing OFFSET.
14196 On exit *REF_CU is the CU of the result.
14197 Returns NULL if OFFSET is invalid. */
14199 static struct die_info
*
14200 follow_die_offset (unsigned int offset
, struct dwarf2_cu
**ref_cu
)
14202 struct die_info temp_die
;
14203 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
14205 gdb_assert (cu
->per_cu
!= NULL
);
14209 if (cu
->per_cu
->debug_types_section
)
14211 /* .debug_types CUs cannot reference anything outside their CU.
14212 If they need to, they have to reference a signatured type via
14213 DW_FORM_ref_sig8. */
14214 if (! offset_in_cu_p (&cu
->header
, offset
))
14217 else if (! offset_in_cu_p (&cu
->header
, offset
))
14219 struct dwarf2_per_cu_data
*per_cu
;
14221 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
14223 /* If necessary, add it to the queue and load its DIEs. */
14224 if (maybe_queue_comp_unit (cu
, per_cu
))
14225 load_full_comp_unit (per_cu
);
14227 target_cu
= per_cu
->cu
;
14229 else if (cu
->dies
== NULL
)
14231 /* We're loading full DIEs during partial symbol reading. */
14232 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
14233 load_full_comp_unit (cu
->per_cu
);
14236 *ref_cu
= target_cu
;
14237 temp_die
.offset
= offset
;
14238 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
14241 /* Follow reference attribute ATTR of SRC_DIE.
14242 On entry *REF_CU is the CU of SRC_DIE.
14243 On exit *REF_CU is the CU of the result. */
14245 static struct die_info
*
14246 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
14247 struct dwarf2_cu
**ref_cu
)
14249 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
14250 struct dwarf2_cu
*cu
= *ref_cu
;
14251 struct die_info
*die
;
14253 die
= follow_die_offset (offset
, ref_cu
);
14255 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
14256 "at 0x%x [in module %s]"),
14257 offset
, src_die
->offset
, cu
->objfile
->name
);
14262 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
14263 Returned value is intended for DW_OP_call*. Returned
14264 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
14266 struct dwarf2_locexpr_baton
14267 dwarf2_fetch_die_location_block (unsigned int offset_in_cu
,
14268 struct dwarf2_per_cu_data
*per_cu
,
14269 CORE_ADDR (*get_frame_pc
) (void *baton
),
14272 unsigned int offset
= per_cu
->offset
+ offset_in_cu
;
14273 struct dwarf2_cu
*cu
;
14274 struct die_info
*die
;
14275 struct attribute
*attr
;
14276 struct dwarf2_locexpr_baton retval
;
14278 dw2_setup (per_cu
->objfile
);
14280 if (per_cu
->cu
== NULL
)
14284 die
= follow_die_offset (offset
, &cu
);
14286 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
14287 offset
, per_cu
->objfile
->name
);
14289 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
14292 /* DWARF: "If there is no such attribute, then there is no effect.".
14293 DATA is ignored if SIZE is 0. */
14295 retval
.data
= NULL
;
14298 else if (attr_form_is_section_offset (attr
))
14300 struct dwarf2_loclist_baton loclist_baton
;
14301 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
14304 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
14306 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
14308 retval
.size
= size
;
14312 if (!attr_form_is_block (attr
))
14313 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
14314 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
14315 offset
, per_cu
->objfile
->name
);
14317 retval
.data
= DW_BLOCK (attr
)->data
;
14318 retval
.size
= DW_BLOCK (attr
)->size
;
14320 retval
.per_cu
= cu
->per_cu
;
14322 age_cached_comp_units ();
14327 /* Return the type of the DIE at DIE_OFFSET in the CU named by
14331 dwarf2_get_die_type (unsigned int die_offset
,
14332 struct dwarf2_per_cu_data
*per_cu
)
14334 dw2_setup (per_cu
->objfile
);
14335 return get_die_type_at_offset (per_cu
->offset
+ die_offset
, per_cu
);
14338 /* Follow the signature attribute ATTR in SRC_DIE.
14339 On entry *REF_CU is the CU of SRC_DIE.
14340 On exit *REF_CU is the CU of the result. */
14342 static struct die_info
*
14343 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
14344 struct dwarf2_cu
**ref_cu
)
14346 struct objfile
*objfile
= (*ref_cu
)->objfile
;
14347 struct die_info temp_die
;
14348 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
14349 struct dwarf2_cu
*sig_cu
;
14350 struct die_info
*die
;
14352 /* sig_type will be NULL if the signatured type is missing from
14354 if (sig_type
== NULL
)
14355 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
14356 "at 0x%x [in module %s]"),
14357 src_die
->offset
, objfile
->name
);
14359 /* If necessary, add it to the queue and load its DIEs. */
14361 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
14362 read_signatured_type (sig_type
);
14364 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
14366 sig_cu
= sig_type
->per_cu
.cu
;
14367 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
14368 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
14375 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
14376 "from DIE at 0x%x [in module %s]"),
14377 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
14380 /* Given an offset of a signatured type, return its signatured_type. */
14382 static struct signatured_type
*
14383 lookup_signatured_type_at_offset (struct objfile
*objfile
,
14384 struct dwarf2_section_info
*section
,
14385 unsigned int offset
)
14387 gdb_byte
*info_ptr
= section
->buffer
+ offset
;
14388 unsigned int length
, initial_length_size
;
14389 unsigned int sig_offset
;
14390 struct signatured_type find_entry
, *type_sig
;
14392 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
14393 sig_offset
= (initial_length_size
14395 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
14396 + 1 /*address_size*/);
14397 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
14398 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
14400 /* This is only used to lookup previously recorded types.
14401 If we didn't find it, it's our bug. */
14402 gdb_assert (type_sig
!= NULL
);
14403 gdb_assert (offset
== type_sig
->per_cu
.offset
);
14408 /* Load the DIEs associated with type unit PER_CU into memory. */
14411 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
14413 struct objfile
*objfile
= per_cu
->objfile
;
14414 struct dwarf2_section_info
*sect
= per_cu
->debug_types_section
;
14415 unsigned int offset
= per_cu
->offset
;
14416 struct signatured_type
*type_sig
;
14418 dwarf2_read_section (objfile
, sect
);
14420 /* We have the section offset, but we need the signature to do the
14421 hash table lookup. */
14422 /* FIXME: This is sorta unnecessary, read_signatured_type only uses
14423 the signature to assert we found the right one.
14424 Ok, but it's a lot of work. We should simplify things so any needed
14425 assert doesn't require all this clumsiness. */
14426 type_sig
= lookup_signatured_type_at_offset (objfile
, sect
, offset
);
14428 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
14430 read_signatured_type (type_sig
);
14432 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
14435 /* Read in a signatured type and build its CU and DIEs. */
14438 read_signatured_type (struct signatured_type
*type_sig
)
14440 struct objfile
*objfile
= type_sig
->per_cu
.objfile
;
14441 gdb_byte
*types_ptr
;
14442 struct die_reader_specs reader_specs
;
14443 struct dwarf2_cu
*cu
;
14444 ULONGEST signature
;
14445 struct cleanup
*back_to
, *free_cu_cleanup
;
14446 struct dwarf2_section_info
*section
= type_sig
->per_cu
.debug_types_section
;
14448 dwarf2_read_section (objfile
, section
);
14449 types_ptr
= section
->buffer
+ type_sig
->per_cu
.offset
;
14451 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
14453 cu
= xmalloc (sizeof (*cu
));
14454 init_one_comp_unit (cu
, &type_sig
->per_cu
);
14456 /* If an error occurs while loading, release our storage. */
14457 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
14459 types_ptr
= read_and_check_type_unit_head (&cu
->header
, section
, types_ptr
,
14461 gdb_assert (signature
== type_sig
->signature
);
14464 = htab_create_alloc_ex (cu
->header
.length
/ 12,
14468 &cu
->comp_unit_obstack
,
14469 hashtab_obstack_allocate
,
14470 dummy_obstack_deallocate
);
14472 dwarf2_read_abbrevs (cu
);
14473 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
14475 init_cu_die_reader (&reader_specs
, cu
);
14477 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
14480 /* We try not to read any attributes in this function, because not
14481 all CUs needed for references have been loaded yet, and symbol
14482 table processing isn't initialized. But we have to set the CU language,
14483 or we won't be able to build types correctly. */
14484 prepare_one_comp_unit (cu
, cu
->dies
);
14486 do_cleanups (back_to
);
14488 /* We've successfully allocated this compilation unit. Let our caller
14489 clean it up when finished with it. */
14490 discard_cleanups (free_cu_cleanup
);
14492 /* Link this TU into read_in_chain. */
14493 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
14494 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
14497 /* Decode simple location descriptions.
14498 Given a pointer to a dwarf block that defines a location, compute
14499 the location and return the value.
14501 NOTE drow/2003-11-18: This function is called in two situations
14502 now: for the address of static or global variables (partial symbols
14503 only) and for offsets into structures which are expected to be
14504 (more or less) constant. The partial symbol case should go away,
14505 and only the constant case should remain. That will let this
14506 function complain more accurately. A few special modes are allowed
14507 without complaint for global variables (for instance, global
14508 register values and thread-local values).
14510 A location description containing no operations indicates that the
14511 object is optimized out. The return value is 0 for that case.
14512 FIXME drow/2003-11-16: No callers check for this case any more; soon all
14513 callers will only want a very basic result and this can become a
14516 Note that stack[0] is unused except as a default error return. */
14519 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
14521 struct objfile
*objfile
= cu
->objfile
;
14523 int size
= blk
->size
;
14524 gdb_byte
*data
= blk
->data
;
14525 CORE_ADDR stack
[64];
14527 unsigned int bytes_read
, unsnd
;
14533 stack
[++stacki
] = 0;
14572 stack
[++stacki
] = op
- DW_OP_lit0
;
14607 stack
[++stacki
] = op
- DW_OP_reg0
;
14609 dwarf2_complex_location_expr_complaint ();
14613 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
14615 stack
[++stacki
] = unsnd
;
14617 dwarf2_complex_location_expr_complaint ();
14621 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
14626 case DW_OP_const1u
:
14627 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
14631 case DW_OP_const1s
:
14632 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
14636 case DW_OP_const2u
:
14637 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
14641 case DW_OP_const2s
:
14642 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
14646 case DW_OP_const4u
:
14647 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
14651 case DW_OP_const4s
:
14652 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
14656 case DW_OP_const8u
:
14657 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
14662 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
14668 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
14673 stack
[stacki
+ 1] = stack
[stacki
];
14678 stack
[stacki
- 1] += stack
[stacki
];
14682 case DW_OP_plus_uconst
:
14683 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
14689 stack
[stacki
- 1] -= stack
[stacki
];
14694 /* If we're not the last op, then we definitely can't encode
14695 this using GDB's address_class enum. This is valid for partial
14696 global symbols, although the variable's address will be bogus
14699 dwarf2_complex_location_expr_complaint ();
14702 case DW_OP_GNU_push_tls_address
:
14703 /* The top of the stack has the offset from the beginning
14704 of the thread control block at which the variable is located. */
14705 /* Nothing should follow this operator, so the top of stack would
14707 /* This is valid for partial global symbols, but the variable's
14708 address will be bogus in the psymtab. Make it always at least
14709 non-zero to not look as a variable garbage collected by linker
14710 which have DW_OP_addr 0. */
14712 dwarf2_complex_location_expr_complaint ();
14716 case DW_OP_GNU_uninit
:
14721 const char *name
= dwarf_stack_op_name (op
);
14724 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
14727 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
14731 return (stack
[stacki
]);
14734 /* Enforce maximum stack depth of SIZE-1 to avoid writing
14735 outside of the allocated space. Also enforce minimum>0. */
14736 if (stacki
>= ARRAY_SIZE (stack
) - 1)
14738 complaint (&symfile_complaints
,
14739 _("location description stack overflow"));
14745 complaint (&symfile_complaints
,
14746 _("location description stack underflow"));
14750 return (stack
[stacki
]);
14753 /* memory allocation interface */
14755 static struct dwarf_block
*
14756 dwarf_alloc_block (struct dwarf2_cu
*cu
)
14758 struct dwarf_block
*blk
;
14760 blk
= (struct dwarf_block
*)
14761 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
14765 static struct abbrev_info
*
14766 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
14768 struct abbrev_info
*abbrev
;
14770 abbrev
= (struct abbrev_info
*)
14771 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
14772 memset (abbrev
, 0, sizeof (struct abbrev_info
));
14776 static struct die_info
*
14777 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
14779 struct die_info
*die
;
14780 size_t size
= sizeof (struct die_info
);
14783 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
14785 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
14786 memset (die
, 0, sizeof (struct die_info
));
14791 /* Macro support. */
14793 /* Return the full name of file number I in *LH's file name table.
14794 Use COMP_DIR as the name of the current directory of the
14795 compilation. The result is allocated using xmalloc; the caller is
14796 responsible for freeing it. */
14798 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
14800 /* Is the file number a valid index into the line header's file name
14801 table? Remember that file numbers start with one, not zero. */
14802 if (1 <= file
&& file
<= lh
->num_file_names
)
14804 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
14806 if (IS_ABSOLUTE_PATH (fe
->name
))
14807 return xstrdup (fe
->name
);
14815 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14821 dir_len
= strlen (dir
);
14822 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
14823 strcpy (full_name
, dir
);
14824 full_name
[dir_len
] = '/';
14825 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
14829 return xstrdup (fe
->name
);
14834 /* The compiler produced a bogus file number. We can at least
14835 record the macro definitions made in the file, even if we
14836 won't be able to find the file by name. */
14837 char fake_name
[80];
14839 sprintf (fake_name
, "<bad macro file number %d>", file
);
14841 complaint (&symfile_complaints
,
14842 _("bad file number in macro information (%d)"),
14845 return xstrdup (fake_name
);
14850 static struct macro_source_file
*
14851 macro_start_file (int file
, int line
,
14852 struct macro_source_file
*current_file
,
14853 const char *comp_dir
,
14854 struct line_header
*lh
, struct objfile
*objfile
)
14856 /* The full name of this source file. */
14857 char *full_name
= file_full_name (file
, lh
, comp_dir
);
14859 /* We don't create a macro table for this compilation unit
14860 at all until we actually get a filename. */
14861 if (! pending_macros
)
14862 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
14863 objfile
->macro_cache
);
14865 if (! current_file
)
14866 /* If we have no current file, then this must be the start_file
14867 directive for the compilation unit's main source file. */
14868 current_file
= macro_set_main (pending_macros
, full_name
);
14870 current_file
= macro_include (current_file
, line
, full_name
);
14874 return current_file
;
14878 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
14879 followed by a null byte. */
14881 copy_string (const char *buf
, int len
)
14883 char *s
= xmalloc (len
+ 1);
14885 memcpy (s
, buf
, len
);
14891 static const char *
14892 consume_improper_spaces (const char *p
, const char *body
)
14896 complaint (&symfile_complaints
,
14897 _("macro definition contains spaces "
14898 "in formal argument list:\n`%s'"),
14910 parse_macro_definition (struct macro_source_file
*file
, int line
,
14915 /* The body string takes one of two forms. For object-like macro
14916 definitions, it should be:
14918 <macro name> " " <definition>
14920 For function-like macro definitions, it should be:
14922 <macro name> "() " <definition>
14924 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
14926 Spaces may appear only where explicitly indicated, and in the
14929 The Dwarf 2 spec says that an object-like macro's name is always
14930 followed by a space, but versions of GCC around March 2002 omit
14931 the space when the macro's definition is the empty string.
14933 The Dwarf 2 spec says that there should be no spaces between the
14934 formal arguments in a function-like macro's formal argument list,
14935 but versions of GCC around March 2002 include spaces after the
14939 /* Find the extent of the macro name. The macro name is terminated
14940 by either a space or null character (for an object-like macro) or
14941 an opening paren (for a function-like macro). */
14942 for (p
= body
; *p
; p
++)
14943 if (*p
== ' ' || *p
== '(')
14946 if (*p
== ' ' || *p
== '\0')
14948 /* It's an object-like macro. */
14949 int name_len
= p
- body
;
14950 char *name
= copy_string (body
, name_len
);
14951 const char *replacement
;
14954 replacement
= body
+ name_len
+ 1;
14957 dwarf2_macro_malformed_definition_complaint (body
);
14958 replacement
= body
+ name_len
;
14961 macro_define_object (file
, line
, name
, replacement
);
14965 else if (*p
== '(')
14967 /* It's a function-like macro. */
14968 char *name
= copy_string (body
, p
- body
);
14971 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
14975 p
= consume_improper_spaces (p
, body
);
14977 /* Parse the formal argument list. */
14978 while (*p
&& *p
!= ')')
14980 /* Find the extent of the current argument name. */
14981 const char *arg_start
= p
;
14983 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
14986 if (! *p
|| p
== arg_start
)
14987 dwarf2_macro_malformed_definition_complaint (body
);
14990 /* Make sure argv has room for the new argument. */
14991 if (argc
>= argv_size
)
14994 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
14997 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
15000 p
= consume_improper_spaces (p
, body
);
15002 /* Consume the comma, if present. */
15007 p
= consume_improper_spaces (p
, body
);
15016 /* Perfectly formed definition, no complaints. */
15017 macro_define_function (file
, line
, name
,
15018 argc
, (const char **) argv
,
15020 else if (*p
== '\0')
15022 /* Complain, but do define it. */
15023 dwarf2_macro_malformed_definition_complaint (body
);
15024 macro_define_function (file
, line
, name
,
15025 argc
, (const char **) argv
,
15029 /* Just complain. */
15030 dwarf2_macro_malformed_definition_complaint (body
);
15033 /* Just complain. */
15034 dwarf2_macro_malformed_definition_complaint (body
);
15040 for (i
= 0; i
< argc
; i
++)
15046 dwarf2_macro_malformed_definition_complaint (body
);
15049 /* Skip some bytes from BYTES according to the form given in FORM.
15050 Returns the new pointer. */
15053 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
,
15054 enum dwarf_form form
,
15055 unsigned int offset_size
,
15056 struct dwarf2_section_info
*section
)
15058 unsigned int bytes_read
;
15062 case DW_FORM_data1
:
15067 case DW_FORM_data2
:
15071 case DW_FORM_data4
:
15075 case DW_FORM_data8
:
15079 case DW_FORM_string
:
15080 read_direct_string (abfd
, bytes
, &bytes_read
);
15081 bytes
+= bytes_read
;
15084 case DW_FORM_sec_offset
:
15086 bytes
+= offset_size
;
15089 case DW_FORM_block
:
15090 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
15091 bytes
+= bytes_read
;
15094 case DW_FORM_block1
:
15095 bytes
+= 1 + read_1_byte (abfd
, bytes
);
15097 case DW_FORM_block2
:
15098 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
15100 case DW_FORM_block4
:
15101 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
15104 case DW_FORM_sdata
:
15105 case DW_FORM_udata
:
15106 bytes
= skip_leb128 (abfd
, bytes
);
15112 complaint (&symfile_complaints
,
15113 _("invalid form 0x%x in `%s'"),
15115 section
->asection
->name
);
15123 /* A helper for dwarf_decode_macros that handles skipping an unknown
15124 opcode. Returns an updated pointer to the macro data buffer; or,
15125 on error, issues a complaint and returns NULL. */
15128 skip_unknown_opcode (unsigned int opcode
,
15129 gdb_byte
**opcode_definitions
,
15132 unsigned int offset_size
,
15133 struct dwarf2_section_info
*section
)
15135 unsigned int bytes_read
, i
;
15139 if (opcode_definitions
[opcode
] == NULL
)
15141 complaint (&symfile_complaints
,
15142 _("unrecognized DW_MACFINO opcode 0x%x"),
15147 defn
= opcode_definitions
[opcode
];
15148 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
15149 defn
+= bytes_read
;
15151 for (i
= 0; i
< arg
; ++i
)
15153 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, defn
[i
], offset_size
, section
);
15154 if (mac_ptr
== NULL
)
15156 /* skip_form_bytes already issued the complaint. */
15164 /* A helper function which parses the header of a macro section.
15165 If the macro section is the extended (for now called "GNU") type,
15166 then this updates *OFFSET_SIZE. Returns a pointer to just after
15167 the header, or issues a complaint and returns NULL on error. */
15170 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
15173 unsigned int *offset_size
,
15174 int section_is_gnu
)
15176 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
15178 if (section_is_gnu
)
15180 unsigned int version
, flags
;
15182 version
= read_2_bytes (abfd
, mac_ptr
);
15185 complaint (&symfile_complaints
,
15186 _("unrecognized version `%d' in .debug_macro section"),
15192 flags
= read_1_byte (abfd
, mac_ptr
);
15194 *offset_size
= (flags
& 1) ? 8 : 4;
15196 if ((flags
& 2) != 0)
15197 /* We don't need the line table offset. */
15198 mac_ptr
+= *offset_size
;
15200 /* Vendor opcode descriptions. */
15201 if ((flags
& 4) != 0)
15203 unsigned int i
, count
;
15205 count
= read_1_byte (abfd
, mac_ptr
);
15207 for (i
= 0; i
< count
; ++i
)
15209 unsigned int opcode
, bytes_read
;
15212 opcode
= read_1_byte (abfd
, mac_ptr
);
15214 opcode_definitions
[opcode
] = mac_ptr
;
15215 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15216 mac_ptr
+= bytes_read
;
15225 /* A helper for dwarf_decode_macros that handles the GNU extensions,
15226 including DW_MACRO_GNU_transparent_include. */
15229 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
15230 struct macro_source_file
*current_file
,
15231 struct line_header
*lh
, char *comp_dir
,
15232 struct dwarf2_section_info
*section
,
15233 int section_is_gnu
,
15234 unsigned int offset_size
,
15235 struct objfile
*objfile
,
15236 htab_t include_hash
)
15238 enum dwarf_macro_record_type macinfo_type
;
15239 int at_commandline
;
15240 gdb_byte
*opcode_definitions
[256];
15242 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
15243 &offset_size
, section_is_gnu
);
15244 if (mac_ptr
== NULL
)
15246 /* We already issued a complaint. */
15250 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
15251 GDB is still reading the definitions from command line. First
15252 DW_MACINFO_start_file will need to be ignored as it was already executed
15253 to create CURRENT_FILE for the main source holding also the command line
15254 definitions. On first met DW_MACINFO_start_file this flag is reset to
15255 normally execute all the remaining DW_MACINFO_start_file macinfos. */
15257 at_commandline
= 1;
15261 /* Do we at least have room for a macinfo type byte? */
15262 if (mac_ptr
>= mac_end
)
15264 dwarf2_macros_too_long_complaint (section
);
15268 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
15271 /* Note that we rely on the fact that the corresponding GNU and
15272 DWARF constants are the same. */
15273 switch (macinfo_type
)
15275 /* A zero macinfo type indicates the end of the macro
15280 case DW_MACRO_GNU_define
:
15281 case DW_MACRO_GNU_undef
:
15282 case DW_MACRO_GNU_define_indirect
:
15283 case DW_MACRO_GNU_undef_indirect
:
15285 unsigned int bytes_read
;
15290 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15291 mac_ptr
+= bytes_read
;
15293 if (macinfo_type
== DW_MACRO_GNU_define
15294 || macinfo_type
== DW_MACRO_GNU_undef
)
15296 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15297 mac_ptr
+= bytes_read
;
15301 LONGEST str_offset
;
15303 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
15304 mac_ptr
+= offset_size
;
15306 body
= read_indirect_string_at_offset (abfd
, str_offset
);
15309 is_define
= (macinfo_type
== DW_MACRO_GNU_define
15310 || macinfo_type
== DW_MACRO_GNU_define_indirect
);
15311 if (! current_file
)
15313 /* DWARF violation as no main source is present. */
15314 complaint (&symfile_complaints
,
15315 _("debug info with no main source gives macro %s "
15317 is_define
? _("definition") : _("undefinition"),
15321 if ((line
== 0 && !at_commandline
)
15322 || (line
!= 0 && at_commandline
))
15323 complaint (&symfile_complaints
,
15324 _("debug info gives %s macro %s with %s line %d: %s"),
15325 at_commandline
? _("command-line") : _("in-file"),
15326 is_define
? _("definition") : _("undefinition"),
15327 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
15330 parse_macro_definition (current_file
, line
, body
);
15333 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
15334 || macinfo_type
== DW_MACRO_GNU_undef_indirect
);
15335 macro_undef (current_file
, line
, body
);
15340 case DW_MACRO_GNU_start_file
:
15342 unsigned int bytes_read
;
15345 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15346 mac_ptr
+= bytes_read
;
15347 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15348 mac_ptr
+= bytes_read
;
15350 if ((line
== 0 && !at_commandline
)
15351 || (line
!= 0 && at_commandline
))
15352 complaint (&symfile_complaints
,
15353 _("debug info gives source %d included "
15354 "from %s at %s line %d"),
15355 file
, at_commandline
? _("command-line") : _("file"),
15356 line
== 0 ? _("zero") : _("non-zero"), line
);
15358 if (at_commandline
)
15360 /* This DW_MACRO_GNU_start_file was executed in the
15362 at_commandline
= 0;
15365 current_file
= macro_start_file (file
, line
,
15366 current_file
, comp_dir
,
15371 case DW_MACRO_GNU_end_file
:
15372 if (! current_file
)
15373 complaint (&symfile_complaints
,
15374 _("macro debug info has an unmatched "
15375 "`close_file' directive"));
15378 current_file
= current_file
->included_by
;
15379 if (! current_file
)
15381 enum dwarf_macro_record_type next_type
;
15383 /* GCC circa March 2002 doesn't produce the zero
15384 type byte marking the end of the compilation
15385 unit. Complain if it's not there, but exit no
15388 /* Do we at least have room for a macinfo type byte? */
15389 if (mac_ptr
>= mac_end
)
15391 dwarf2_macros_too_long_complaint (section
);
15395 /* We don't increment mac_ptr here, so this is just
15397 next_type
= read_1_byte (abfd
, mac_ptr
);
15398 if (next_type
!= 0)
15399 complaint (&symfile_complaints
,
15400 _("no terminating 0-type entry for "
15401 "macros in `.debug_macinfo' section"));
15408 case DW_MACRO_GNU_transparent_include
:
15413 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
15414 mac_ptr
+= offset_size
;
15416 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
15419 /* This has actually happened; see
15420 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
15421 complaint (&symfile_complaints
,
15422 _("recursive DW_MACRO_GNU_transparent_include in "
15423 ".debug_macro section"));
15429 dwarf_decode_macro_bytes (abfd
,
15430 section
->buffer
+ offset
,
15431 mac_end
, current_file
,
15433 section
, section_is_gnu
,
15434 offset_size
, objfile
, include_hash
);
15436 htab_remove_elt (include_hash
, mac_ptr
);
15441 case DW_MACINFO_vendor_ext
:
15442 if (!section_is_gnu
)
15444 unsigned int bytes_read
;
15447 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15448 mac_ptr
+= bytes_read
;
15449 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15450 mac_ptr
+= bytes_read
;
15452 /* We don't recognize any vendor extensions. */
15458 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
15459 mac_ptr
, abfd
, offset_size
,
15461 if (mac_ptr
== NULL
)
15465 } while (macinfo_type
!= 0);
15469 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
15470 char *comp_dir
, bfd
*abfd
,
15471 struct dwarf2_cu
*cu
,
15472 struct dwarf2_section_info
*section
,
15473 int section_is_gnu
)
15475 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15476 gdb_byte
*mac_ptr
, *mac_end
;
15477 struct macro_source_file
*current_file
= 0;
15478 enum dwarf_macro_record_type macinfo_type
;
15479 unsigned int offset_size
= cu
->header
.offset_size
;
15480 gdb_byte
*opcode_definitions
[256];
15481 struct cleanup
*cleanup
;
15482 htab_t include_hash
;
15485 dwarf2_read_section (objfile
, section
);
15486 if (section
->buffer
== NULL
)
15488 complaint (&symfile_complaints
, _("missing %s section"),
15489 section
->asection
->name
);
15493 /* First pass: Find the name of the base filename.
15494 This filename is needed in order to process all macros whose definition
15495 (or undefinition) comes from the command line. These macros are defined
15496 before the first DW_MACINFO_start_file entry, and yet still need to be
15497 associated to the base file.
15499 To determine the base file name, we scan the macro definitions until we
15500 reach the first DW_MACINFO_start_file entry. We then initialize
15501 CURRENT_FILE accordingly so that any macro definition found before the
15502 first DW_MACINFO_start_file can still be associated to the base file. */
15504 mac_ptr
= section
->buffer
+ offset
;
15505 mac_end
= section
->buffer
+ section
->size
;
15507 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
15508 &offset_size
, section_is_gnu
);
15509 if (mac_ptr
== NULL
)
15511 /* We already issued a complaint. */
15517 /* Do we at least have room for a macinfo type byte? */
15518 if (mac_ptr
>= mac_end
)
15520 /* Complaint is printed during the second pass as GDB will probably
15521 stop the first pass earlier upon finding
15522 DW_MACINFO_start_file. */
15526 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
15529 /* Note that we rely on the fact that the corresponding GNU and
15530 DWARF constants are the same. */
15531 switch (macinfo_type
)
15533 /* A zero macinfo type indicates the end of the macro
15538 case DW_MACRO_GNU_define
:
15539 case DW_MACRO_GNU_undef
:
15540 /* Only skip the data by MAC_PTR. */
15542 unsigned int bytes_read
;
15544 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15545 mac_ptr
+= bytes_read
;
15546 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15547 mac_ptr
+= bytes_read
;
15551 case DW_MACRO_GNU_start_file
:
15553 unsigned int bytes_read
;
15556 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15557 mac_ptr
+= bytes_read
;
15558 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15559 mac_ptr
+= bytes_read
;
15561 current_file
= macro_start_file (file
, line
, current_file
,
15562 comp_dir
, lh
, objfile
);
15566 case DW_MACRO_GNU_end_file
:
15567 /* No data to skip by MAC_PTR. */
15570 case DW_MACRO_GNU_define_indirect
:
15571 case DW_MACRO_GNU_undef_indirect
:
15573 unsigned int bytes_read
;
15575 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15576 mac_ptr
+= bytes_read
;
15577 mac_ptr
+= offset_size
;
15581 case DW_MACRO_GNU_transparent_include
:
15582 /* Note that, according to the spec, a transparent include
15583 chain cannot call DW_MACRO_GNU_start_file. So, we can just
15584 skip this opcode. */
15585 mac_ptr
+= offset_size
;
15588 case DW_MACINFO_vendor_ext
:
15589 /* Only skip the data by MAC_PTR. */
15590 if (!section_is_gnu
)
15592 unsigned int bytes_read
;
15594 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15595 mac_ptr
+= bytes_read
;
15596 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15597 mac_ptr
+= bytes_read
;
15602 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
15603 mac_ptr
, abfd
, offset_size
,
15605 if (mac_ptr
== NULL
)
15609 } while (macinfo_type
!= 0 && current_file
== NULL
);
15611 /* Second pass: Process all entries.
15613 Use the AT_COMMAND_LINE flag to determine whether we are still processing
15614 command-line macro definitions/undefinitions. This flag is unset when we
15615 reach the first DW_MACINFO_start_file entry. */
15617 include_hash
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
15618 NULL
, xcalloc
, xfree
);
15619 cleanup
= make_cleanup_htab_delete (include_hash
);
15620 mac_ptr
= section
->buffer
+ offset
;
15621 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
15623 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
15624 current_file
, lh
, comp_dir
, section
, section_is_gnu
,
15625 offset_size
, objfile
, include_hash
);
15626 do_cleanups (cleanup
);
15629 /* Check if the attribute's form is a DW_FORM_block*
15630 if so return true else false. */
15632 attr_form_is_block (struct attribute
*attr
)
15634 return (attr
== NULL
? 0 :
15635 attr
->form
== DW_FORM_block1
15636 || attr
->form
== DW_FORM_block2
15637 || attr
->form
== DW_FORM_block4
15638 || attr
->form
== DW_FORM_block
15639 || attr
->form
== DW_FORM_exprloc
);
15642 /* Return non-zero if ATTR's value is a section offset --- classes
15643 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
15644 You may use DW_UNSND (attr) to retrieve such offsets.
15646 Section 7.5.4, "Attribute Encodings", explains that no attribute
15647 may have a value that belongs to more than one of these classes; it
15648 would be ambiguous if we did, because we use the same forms for all
15651 attr_form_is_section_offset (struct attribute
*attr
)
15653 return (attr
->form
== DW_FORM_data4
15654 || attr
->form
== DW_FORM_data8
15655 || attr
->form
== DW_FORM_sec_offset
);
15659 /* Return non-zero if ATTR's value falls in the 'constant' class, or
15660 zero otherwise. When this function returns true, you can apply
15661 dwarf2_get_attr_constant_value to it.
15663 However, note that for some attributes you must check
15664 attr_form_is_section_offset before using this test. DW_FORM_data4
15665 and DW_FORM_data8 are members of both the constant class, and of
15666 the classes that contain offsets into other debug sections
15667 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
15668 that, if an attribute's can be either a constant or one of the
15669 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
15670 taken as section offsets, not constants. */
15672 attr_form_is_constant (struct attribute
*attr
)
15674 switch (attr
->form
)
15676 case DW_FORM_sdata
:
15677 case DW_FORM_udata
:
15678 case DW_FORM_data1
:
15679 case DW_FORM_data2
:
15680 case DW_FORM_data4
:
15681 case DW_FORM_data8
:
15688 /* A helper function that fills in a dwarf2_loclist_baton. */
15691 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
15692 struct dwarf2_loclist_baton
*baton
,
15693 struct attribute
*attr
)
15695 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
15696 &dwarf2_per_objfile
->loc
);
15698 baton
->per_cu
= cu
->per_cu
;
15699 gdb_assert (baton
->per_cu
);
15700 /* We don't know how long the location list is, but make sure we
15701 don't run off the edge of the section. */
15702 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
15703 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
15704 baton
->base_address
= cu
->base_address
;
15708 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
15709 struct dwarf2_cu
*cu
)
15711 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15713 if (attr_form_is_section_offset (attr
)
15714 /* ".debug_loc" may not exist at all, or the offset may be outside
15715 the section. If so, fall through to the complaint in the
15717 && DW_UNSND (attr
) < dwarf2_section_size (objfile
,
15718 &dwarf2_per_objfile
->loc
))
15720 struct dwarf2_loclist_baton
*baton
;
15722 baton
= obstack_alloc (&objfile
->objfile_obstack
,
15723 sizeof (struct dwarf2_loclist_baton
));
15725 fill_in_loclist_baton (cu
, baton
, attr
);
15727 if (cu
->base_known
== 0)
15728 complaint (&symfile_complaints
,
15729 _("Location list used without "
15730 "specifying the CU base address."));
15732 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
15733 SYMBOL_LOCATION_BATON (sym
) = baton
;
15737 struct dwarf2_locexpr_baton
*baton
;
15739 baton
= obstack_alloc (&objfile
->objfile_obstack
,
15740 sizeof (struct dwarf2_locexpr_baton
));
15741 baton
->per_cu
= cu
->per_cu
;
15742 gdb_assert (baton
->per_cu
);
15744 if (attr_form_is_block (attr
))
15746 /* Note that we're just copying the block's data pointer
15747 here, not the actual data. We're still pointing into the
15748 info_buffer for SYM's objfile; right now we never release
15749 that buffer, but when we do clean up properly this may
15751 baton
->size
= DW_BLOCK (attr
)->size
;
15752 baton
->data
= DW_BLOCK (attr
)->data
;
15756 dwarf2_invalid_attrib_class_complaint ("location description",
15757 SYMBOL_NATURAL_NAME (sym
));
15761 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
15762 SYMBOL_LOCATION_BATON (sym
) = baton
;
15766 /* Return the OBJFILE associated with the compilation unit CU. If CU
15767 came from a separate debuginfo file, then the master objfile is
15771 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
15773 struct objfile
*objfile
= per_cu
->objfile
;
15775 /* Return the master objfile, so that we can report and look up the
15776 correct file containing this variable. */
15777 if (objfile
->separate_debug_objfile_backlink
)
15778 objfile
= objfile
->separate_debug_objfile_backlink
;
15783 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
15784 (CU_HEADERP is unused in such case) or prepare a temporary copy at
15785 CU_HEADERP first. */
15787 static const struct comp_unit_head
*
15788 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
15789 struct dwarf2_per_cu_data
*per_cu
)
15791 struct objfile
*objfile
;
15792 struct dwarf2_per_objfile
*per_objfile
;
15793 gdb_byte
*info_ptr
;
15796 return &per_cu
->cu
->header
;
15798 objfile
= per_cu
->objfile
;
15799 per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
15800 info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
15802 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
15803 read_comp_unit_head (cu_headerp
, info_ptr
, objfile
->obfd
);
15808 /* Return the address size given in the compilation unit header for CU. */
15811 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
15813 struct comp_unit_head cu_header_local
;
15814 const struct comp_unit_head
*cu_headerp
;
15816 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
15818 return cu_headerp
->addr_size
;
15821 /* Return the offset size given in the compilation unit header for CU. */
15824 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
15826 struct comp_unit_head cu_header_local
;
15827 const struct comp_unit_head
*cu_headerp
;
15829 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
15831 return cu_headerp
->offset_size
;
15834 /* See its dwarf2loc.h declaration. */
15837 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
15839 struct comp_unit_head cu_header_local
;
15840 const struct comp_unit_head
*cu_headerp
;
15842 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
15844 if (cu_headerp
->version
== 2)
15845 return cu_headerp
->addr_size
;
15847 return cu_headerp
->offset_size
;
15850 /* Return the text offset of the CU. The returned offset comes from
15851 this CU's objfile. If this objfile came from a separate debuginfo
15852 file, then the offset may be different from the corresponding
15853 offset in the parent objfile. */
15856 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
15858 struct objfile
*objfile
= per_cu
->objfile
;
15860 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15863 /* Locate the .debug_info compilation unit from CU's objfile which contains
15864 the DIE at OFFSET. Raises an error on failure. */
15866 static struct dwarf2_per_cu_data
*
15867 dwarf2_find_containing_comp_unit (unsigned int offset
,
15868 struct objfile
*objfile
)
15870 struct dwarf2_per_cu_data
*this_cu
;
15874 high
= dwarf2_per_objfile
->n_comp_units
- 1;
15877 int mid
= low
+ (high
- low
) / 2;
15879 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
15884 gdb_assert (low
== high
);
15885 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
15888 error (_("Dwarf Error: could not find partial DIE containing "
15889 "offset 0x%lx [in module %s]"),
15890 (long) offset
, bfd_get_filename (objfile
->obfd
));
15892 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
15893 return dwarf2_per_objfile
->all_comp_units
[low
-1];
15897 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
15898 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
15899 && offset
>= this_cu
->offset
+ this_cu
->length
)
15900 error (_("invalid dwarf2 offset %u"), offset
);
15901 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
15906 /* Initialize dwarf2_cu CU, owned by PER_CU. */
15909 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
15911 memset (cu
, 0, sizeof (*cu
));
15913 cu
->per_cu
= per_cu
;
15914 cu
->objfile
= per_cu
->objfile
;
15915 obstack_init (&cu
->comp_unit_obstack
);
15918 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
15921 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
)
15923 struct attribute
*attr
;
15925 /* Set the language we're debugging. */
15926 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
15928 set_cu_language (DW_UNSND (attr
), cu
);
15931 cu
->language
= language_minimal
;
15932 cu
->language_defn
= language_def (cu
->language
);
15936 /* Release one cached compilation unit, CU. We unlink it from the tree
15937 of compilation units, but we don't remove it from the read_in_chain;
15938 the caller is responsible for that.
15939 NOTE: DATA is a void * because this function is also used as a
15940 cleanup routine. */
15943 free_heap_comp_unit (void *data
)
15945 struct dwarf2_cu
*cu
= data
;
15947 gdb_assert (cu
->per_cu
!= NULL
);
15948 cu
->per_cu
->cu
= NULL
;
15951 obstack_free (&cu
->comp_unit_obstack
, NULL
);
15956 /* This cleanup function is passed the address of a dwarf2_cu on the stack
15957 when we're finished with it. We can't free the pointer itself, but be
15958 sure to unlink it from the cache. Also release any associated storage
15959 and perform cache maintenance.
15961 Only used during partial symbol parsing. */
15964 free_stack_comp_unit (void *data
)
15966 struct dwarf2_cu
*cu
= data
;
15968 gdb_assert (cu
->per_cu
!= NULL
);
15969 cu
->per_cu
->cu
= NULL
;
15972 obstack_free (&cu
->comp_unit_obstack
, NULL
);
15973 cu
->partial_dies
= NULL
;
15975 /* The previous code only did this if per_cu != NULL.
15976 But that would always succeed, so now we just unconditionally do
15977 the aging. This seems like the wrong place to do such aging,
15978 but cleaning that up is left for later. */
15979 age_cached_comp_units ();
15982 /* Free all cached compilation units. */
15985 free_cached_comp_units (void *data
)
15987 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15989 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15990 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15991 while (per_cu
!= NULL
)
15993 struct dwarf2_per_cu_data
*next_cu
;
15995 next_cu
= per_cu
->cu
->read_in_chain
;
15997 free_heap_comp_unit (per_cu
->cu
);
15998 *last_chain
= next_cu
;
16004 /* Increase the age counter on each cached compilation unit, and free
16005 any that are too old. */
16008 age_cached_comp_units (void)
16010 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
16012 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
16013 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16014 while (per_cu
!= NULL
)
16016 per_cu
->cu
->last_used
++;
16017 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
16018 dwarf2_mark (per_cu
->cu
);
16019 per_cu
= per_cu
->cu
->read_in_chain
;
16022 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16023 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
16024 while (per_cu
!= NULL
)
16026 struct dwarf2_per_cu_data
*next_cu
;
16028 next_cu
= per_cu
->cu
->read_in_chain
;
16030 if (!per_cu
->cu
->mark
)
16032 free_heap_comp_unit (per_cu
->cu
);
16033 *last_chain
= next_cu
;
16036 last_chain
= &per_cu
->cu
->read_in_chain
;
16042 /* Remove a single compilation unit from the cache. */
16045 free_one_cached_comp_unit (void *target_cu
)
16047 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
16049 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16050 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
16051 while (per_cu
!= NULL
)
16053 struct dwarf2_per_cu_data
*next_cu
;
16055 next_cu
= per_cu
->cu
->read_in_chain
;
16057 if (per_cu
->cu
== target_cu
)
16059 free_heap_comp_unit (per_cu
->cu
);
16060 *last_chain
= next_cu
;
16064 last_chain
= &per_cu
->cu
->read_in_chain
;
16070 /* Release all extra memory associated with OBJFILE. */
16073 dwarf2_free_objfile (struct objfile
*objfile
)
16075 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
16077 if (dwarf2_per_objfile
== NULL
)
16080 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
16081 free_cached_comp_units (NULL
);
16083 if (dwarf2_per_objfile
->quick_file_names_table
)
16084 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
16086 /* Everything else should be on the objfile obstack. */
16089 /* A pair of DIE offset and GDB type pointer. We store these
16090 in a hash table separate from the DIEs, and preserve them
16091 when the DIEs are flushed out of cache. */
16093 struct dwarf2_offset_and_type
16095 unsigned int offset
;
16099 /* Hash function for a dwarf2_offset_and_type. */
16102 offset_and_type_hash (const void *item
)
16104 const struct dwarf2_offset_and_type
*ofs
= item
;
16106 return ofs
->offset
;
16109 /* Equality function for a dwarf2_offset_and_type. */
16112 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
16114 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
16115 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
16117 return ofs_lhs
->offset
== ofs_rhs
->offset
;
16120 /* Set the type associated with DIE to TYPE. Save it in CU's hash
16121 table if necessary. For convenience, return TYPE.
16123 The DIEs reading must have careful ordering to:
16124 * Not cause infite loops trying to read in DIEs as a prerequisite for
16125 reading current DIE.
16126 * Not trying to dereference contents of still incompletely read in types
16127 while reading in other DIEs.
16128 * Enable referencing still incompletely read in types just by a pointer to
16129 the type without accessing its fields.
16131 Therefore caller should follow these rules:
16132 * Try to fetch any prerequisite types we may need to build this DIE type
16133 before building the type and calling set_die_type.
16134 * After building type call set_die_type for current DIE as soon as
16135 possible before fetching more types to complete the current type.
16136 * Make the type as complete as possible before fetching more types. */
16138 static struct type
*
16139 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
16141 struct dwarf2_offset_and_type
**slot
, ofs
;
16142 struct objfile
*objfile
= cu
->objfile
;
16143 htab_t
*type_hash_ptr
;
16145 /* For Ada types, make sure that the gnat-specific data is always
16146 initialized (if not already set). There are a few types where
16147 we should not be doing so, because the type-specific area is
16148 already used to hold some other piece of info (eg: TYPE_CODE_FLT
16149 where the type-specific area is used to store the floatformat).
16150 But this is not a problem, because the gnat-specific information
16151 is actually not needed for these types. */
16152 if (need_gnat_info (cu
)
16153 && TYPE_CODE (type
) != TYPE_CODE_FUNC
16154 && TYPE_CODE (type
) != TYPE_CODE_FLT
16155 && !HAVE_GNAT_AUX_INFO (type
))
16156 INIT_GNAT_SPECIFIC (type
);
16158 if (cu
->per_cu
->debug_types_section
)
16159 type_hash_ptr
= &dwarf2_per_objfile
->debug_types_type_hash
;
16161 type_hash_ptr
= &dwarf2_per_objfile
->debug_info_type_hash
;
16163 if (*type_hash_ptr
== NULL
)
16166 = htab_create_alloc_ex (127,
16167 offset_and_type_hash
,
16168 offset_and_type_eq
,
16170 &objfile
->objfile_obstack
,
16171 hashtab_obstack_allocate
,
16172 dummy_obstack_deallocate
);
16175 ofs
.offset
= die
->offset
;
16177 slot
= (struct dwarf2_offset_and_type
**)
16178 htab_find_slot_with_hash (*type_hash_ptr
, &ofs
, ofs
.offset
, INSERT
);
16180 complaint (&symfile_complaints
,
16181 _("A problem internal to GDB: DIE 0x%x has type already set"),
16183 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
16188 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
16189 table, or return NULL if the die does not have a saved type. */
16191 static struct type
*
16192 get_die_type_at_offset (unsigned int offset
,
16193 struct dwarf2_per_cu_data
*per_cu
)
16195 struct dwarf2_offset_and_type
*slot
, ofs
;
16198 if (per_cu
->debug_types_section
)
16199 type_hash
= dwarf2_per_objfile
->debug_types_type_hash
;
16201 type_hash
= dwarf2_per_objfile
->debug_info_type_hash
;
16202 if (type_hash
== NULL
)
16205 ofs
.offset
= offset
;
16206 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
16213 /* Look up the type for DIE in the appropriate type_hash table,
16214 or return NULL if DIE does not have a saved type. */
16216 static struct type
*
16217 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16219 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
16222 /* Add a dependence relationship from CU to REF_PER_CU. */
16225 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
16226 struct dwarf2_per_cu_data
*ref_per_cu
)
16230 if (cu
->dependencies
== NULL
)
16232 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
16233 NULL
, &cu
->comp_unit_obstack
,
16234 hashtab_obstack_allocate
,
16235 dummy_obstack_deallocate
);
16237 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
16239 *slot
= ref_per_cu
;
16242 /* Subroutine of dwarf2_mark to pass to htab_traverse.
16243 Set the mark field in every compilation unit in the
16244 cache that we must keep because we are keeping CU. */
16247 dwarf2_mark_helper (void **slot
, void *data
)
16249 struct dwarf2_per_cu_data
*per_cu
;
16251 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
16253 /* cu->dependencies references may not yet have been ever read if QUIT aborts
16254 reading of the chain. As such dependencies remain valid it is not much
16255 useful to track and undo them during QUIT cleanups. */
16256 if (per_cu
->cu
== NULL
)
16259 if (per_cu
->cu
->mark
)
16261 per_cu
->cu
->mark
= 1;
16263 if (per_cu
->cu
->dependencies
!= NULL
)
16264 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
16269 /* Set the mark field in CU and in every other compilation unit in the
16270 cache that we must keep because we are keeping CU. */
16273 dwarf2_mark (struct dwarf2_cu
*cu
)
16278 if (cu
->dependencies
!= NULL
)
16279 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
16283 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
16287 per_cu
->cu
->mark
= 0;
16288 per_cu
= per_cu
->cu
->read_in_chain
;
16292 /* Trivial hash function for partial_die_info: the hash value of a DIE
16293 is its offset in .debug_info for this objfile. */
16296 partial_die_hash (const void *item
)
16298 const struct partial_die_info
*part_die
= item
;
16300 return part_die
->offset
;
16303 /* Trivial comparison function for partial_die_info structures: two DIEs
16304 are equal if they have the same offset. */
16307 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
16309 const struct partial_die_info
*part_die_lhs
= item_lhs
;
16310 const struct partial_die_info
*part_die_rhs
= item_rhs
;
16312 return part_die_lhs
->offset
== part_die_rhs
->offset
;
16315 static struct cmd_list_element
*set_dwarf2_cmdlist
;
16316 static struct cmd_list_element
*show_dwarf2_cmdlist
;
16319 set_dwarf2_cmd (char *args
, int from_tty
)
16321 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
16325 show_dwarf2_cmd (char *args
, int from_tty
)
16327 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
16330 /* If section described by INFO was mmapped, munmap it now. */
16333 munmap_section_buffer (struct dwarf2_section_info
*info
)
16335 if (info
->map_addr
!= NULL
)
16340 res
= munmap (info
->map_addr
, info
->map_len
);
16341 gdb_assert (res
== 0);
16343 /* Without HAVE_MMAP, we should never be here to begin with. */
16344 gdb_assert_not_reached ("no mmap support");
16349 /* munmap debug sections for OBJFILE, if necessary. */
16352 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
16354 struct dwarf2_per_objfile
*data
= d
;
16356 struct dwarf2_section_info
*section
;
16358 /* This is sorted according to the order they're defined in to make it easier
16359 to keep in sync. */
16360 munmap_section_buffer (&data
->info
);
16361 munmap_section_buffer (&data
->abbrev
);
16362 munmap_section_buffer (&data
->line
);
16363 munmap_section_buffer (&data
->loc
);
16364 munmap_section_buffer (&data
->macinfo
);
16365 munmap_section_buffer (&data
->macro
);
16366 munmap_section_buffer (&data
->str
);
16367 munmap_section_buffer (&data
->ranges
);
16368 munmap_section_buffer (&data
->frame
);
16369 munmap_section_buffer (&data
->eh_frame
);
16370 munmap_section_buffer (&data
->gdb_index
);
16373 VEC_iterate (dwarf2_section_info_def
, data
->types
, ix
, section
);
16375 munmap_section_buffer (section
);
16377 VEC_free (dwarf2_section_info_def
, data
->types
);
16381 /* The "save gdb-index" command. */
16383 /* The contents of the hash table we create when building the string
16385 struct strtab_entry
16387 offset_type offset
;
16391 /* Hash function for a strtab_entry.
16393 Function is used only during write_hash_table so no index format backward
16394 compatibility is needed. */
16397 hash_strtab_entry (const void *e
)
16399 const struct strtab_entry
*entry
= e
;
16400 return mapped_index_string_hash (INT_MAX
, entry
->str
);
16403 /* Equality function for a strtab_entry. */
16406 eq_strtab_entry (const void *a
, const void *b
)
16408 const struct strtab_entry
*ea
= a
;
16409 const struct strtab_entry
*eb
= b
;
16410 return !strcmp (ea
->str
, eb
->str
);
16413 /* Create a strtab_entry hash table. */
16416 create_strtab (void)
16418 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
16419 xfree
, xcalloc
, xfree
);
16422 /* Add a string to the constant pool. Return the string's offset in
16426 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
16429 struct strtab_entry entry
;
16430 struct strtab_entry
*result
;
16433 slot
= htab_find_slot (table
, &entry
, INSERT
);
16438 result
= XNEW (struct strtab_entry
);
16439 result
->offset
= obstack_object_size (cpool
);
16441 obstack_grow_str0 (cpool
, str
);
16444 return result
->offset
;
16447 /* An entry in the symbol table. */
16448 struct symtab_index_entry
16450 /* The name of the symbol. */
16452 /* The offset of the name in the constant pool. */
16453 offset_type index_offset
;
16454 /* A sorted vector of the indices of all the CUs that hold an object
16456 VEC (offset_type
) *cu_indices
;
16459 /* The symbol table. This is a power-of-2-sized hash table. */
16460 struct mapped_symtab
16462 offset_type n_elements
;
16464 struct symtab_index_entry
**data
;
16467 /* Hash function for a symtab_index_entry. */
16470 hash_symtab_entry (const void *e
)
16472 const struct symtab_index_entry
*entry
= e
;
16473 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
16474 sizeof (offset_type
) * VEC_length (offset_type
,
16475 entry
->cu_indices
),
16479 /* Equality function for a symtab_index_entry. */
16482 eq_symtab_entry (const void *a
, const void *b
)
16484 const struct symtab_index_entry
*ea
= a
;
16485 const struct symtab_index_entry
*eb
= b
;
16486 int len
= VEC_length (offset_type
, ea
->cu_indices
);
16487 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
16489 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
16490 VEC_address (offset_type
, eb
->cu_indices
),
16491 sizeof (offset_type
) * len
);
16494 /* Destroy a symtab_index_entry. */
16497 delete_symtab_entry (void *p
)
16499 struct symtab_index_entry
*entry
= p
;
16500 VEC_free (offset_type
, entry
->cu_indices
);
16504 /* Create a hash table holding symtab_index_entry objects. */
16507 create_symbol_hash_table (void)
16509 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
16510 delete_symtab_entry
, xcalloc
, xfree
);
16513 /* Create a new mapped symtab object. */
16515 static struct mapped_symtab
*
16516 create_mapped_symtab (void)
16518 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
16519 symtab
->n_elements
= 0;
16520 symtab
->size
= 1024;
16521 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
16525 /* Destroy a mapped_symtab. */
16528 cleanup_mapped_symtab (void *p
)
16530 struct mapped_symtab
*symtab
= p
;
16531 /* The contents of the array are freed when the other hash table is
16533 xfree (symtab
->data
);
16537 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
16540 Function is used only during write_hash_table so no index format backward
16541 compatibility is needed. */
16543 static struct symtab_index_entry
**
16544 find_slot (struct mapped_symtab
*symtab
, const char *name
)
16546 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
16548 index
= hash
& (symtab
->size
- 1);
16549 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
16553 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
16554 return &symtab
->data
[index
];
16555 index
= (index
+ step
) & (symtab
->size
- 1);
16559 /* Expand SYMTAB's hash table. */
16562 hash_expand (struct mapped_symtab
*symtab
)
16564 offset_type old_size
= symtab
->size
;
16566 struct symtab_index_entry
**old_entries
= symtab
->data
;
16569 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
16571 for (i
= 0; i
< old_size
; ++i
)
16573 if (old_entries
[i
])
16575 struct symtab_index_entry
**slot
= find_slot (symtab
,
16576 old_entries
[i
]->name
);
16577 *slot
= old_entries
[i
];
16581 xfree (old_entries
);
16584 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
16585 is the index of the CU in which the symbol appears. */
16588 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
16589 offset_type cu_index
)
16591 struct symtab_index_entry
**slot
;
16593 ++symtab
->n_elements
;
16594 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
16595 hash_expand (symtab
);
16597 slot
= find_slot (symtab
, name
);
16600 *slot
= XNEW (struct symtab_index_entry
);
16601 (*slot
)->name
= name
;
16602 (*slot
)->cu_indices
= NULL
;
16604 /* Don't push an index twice. Due to how we add entries we only
16605 have to check the last one. */
16606 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
16607 || VEC_last (offset_type
, (*slot
)->cu_indices
) != cu_index
)
16608 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
16611 /* Add a vector of indices to the constant pool. */
16614 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
16615 struct symtab_index_entry
*entry
)
16619 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
16622 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
16623 offset_type val
= MAYBE_SWAP (len
);
16628 entry
->index_offset
= obstack_object_size (cpool
);
16630 obstack_grow (cpool
, &val
, sizeof (val
));
16632 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
16635 val
= MAYBE_SWAP (iter
);
16636 obstack_grow (cpool
, &val
, sizeof (val
));
16641 struct symtab_index_entry
*old_entry
= *slot
;
16642 entry
->index_offset
= old_entry
->index_offset
;
16645 return entry
->index_offset
;
16648 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
16649 constant pool entries going into the obstack CPOOL. */
16652 write_hash_table (struct mapped_symtab
*symtab
,
16653 struct obstack
*output
, struct obstack
*cpool
)
16656 htab_t symbol_hash_table
;
16659 symbol_hash_table
= create_symbol_hash_table ();
16660 str_table
= create_strtab ();
16662 /* We add all the index vectors to the constant pool first, to
16663 ensure alignment is ok. */
16664 for (i
= 0; i
< symtab
->size
; ++i
)
16666 if (symtab
->data
[i
])
16667 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
16670 /* Now write out the hash table. */
16671 for (i
= 0; i
< symtab
->size
; ++i
)
16673 offset_type str_off
, vec_off
;
16675 if (symtab
->data
[i
])
16677 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
16678 vec_off
= symtab
->data
[i
]->index_offset
;
16682 /* While 0 is a valid constant pool index, it is not valid
16683 to have 0 for both offsets. */
16688 str_off
= MAYBE_SWAP (str_off
);
16689 vec_off
= MAYBE_SWAP (vec_off
);
16691 obstack_grow (output
, &str_off
, sizeof (str_off
));
16692 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
16695 htab_delete (str_table
);
16696 htab_delete (symbol_hash_table
);
16699 /* Struct to map psymtab to CU index in the index file. */
16700 struct psymtab_cu_index_map
16702 struct partial_symtab
*psymtab
;
16703 unsigned int cu_index
;
16707 hash_psymtab_cu_index (const void *item
)
16709 const struct psymtab_cu_index_map
*map
= item
;
16711 return htab_hash_pointer (map
->psymtab
);
16715 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
16717 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
16718 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
16720 return lhs
->psymtab
== rhs
->psymtab
;
16723 /* Helper struct for building the address table. */
16724 struct addrmap_index_data
16726 struct objfile
*objfile
;
16727 struct obstack
*addr_obstack
;
16728 htab_t cu_index_htab
;
16730 /* Non-zero if the previous_* fields are valid.
16731 We can't write an entry until we see the next entry (since it is only then
16732 that we know the end of the entry). */
16733 int previous_valid
;
16734 /* Index of the CU in the table of all CUs in the index file. */
16735 unsigned int previous_cu_index
;
16736 /* Start address of the CU. */
16737 CORE_ADDR previous_cu_start
;
16740 /* Write an address entry to OBSTACK. */
16743 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
16744 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
16746 offset_type cu_index_to_write
;
16748 CORE_ADDR baseaddr
;
16750 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
16752 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
16753 obstack_grow (obstack
, addr
, 8);
16754 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
16755 obstack_grow (obstack
, addr
, 8);
16756 cu_index_to_write
= MAYBE_SWAP (cu_index
);
16757 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
16760 /* Worker function for traversing an addrmap to build the address table. */
16763 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
16765 struct addrmap_index_data
*data
= datap
;
16766 struct partial_symtab
*pst
= obj
;
16767 offset_type cu_index
;
16770 if (data
->previous_valid
)
16771 add_address_entry (data
->objfile
, data
->addr_obstack
,
16772 data
->previous_cu_start
, start_addr
,
16773 data
->previous_cu_index
);
16775 data
->previous_cu_start
= start_addr
;
16778 struct psymtab_cu_index_map find_map
, *map
;
16779 find_map
.psymtab
= pst
;
16780 map
= htab_find (data
->cu_index_htab
, &find_map
);
16781 gdb_assert (map
!= NULL
);
16782 data
->previous_cu_index
= map
->cu_index
;
16783 data
->previous_valid
= 1;
16786 data
->previous_valid
= 0;
16791 /* Write OBJFILE's address map to OBSTACK.
16792 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
16793 in the index file. */
16796 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
16797 htab_t cu_index_htab
)
16799 struct addrmap_index_data addrmap_index_data
;
16801 /* When writing the address table, we have to cope with the fact that
16802 the addrmap iterator only provides the start of a region; we have to
16803 wait until the next invocation to get the start of the next region. */
16805 addrmap_index_data
.objfile
= objfile
;
16806 addrmap_index_data
.addr_obstack
= obstack
;
16807 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
16808 addrmap_index_data
.previous_valid
= 0;
16810 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
16811 &addrmap_index_data
);
16813 /* It's highly unlikely the last entry (end address = 0xff...ff)
16814 is valid, but we should still handle it.
16815 The end address is recorded as the start of the next region, but that
16816 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
16818 if (addrmap_index_data
.previous_valid
)
16819 add_address_entry (objfile
, obstack
,
16820 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
16821 addrmap_index_data
.previous_cu_index
);
16824 /* Add a list of partial symbols to SYMTAB. */
16827 write_psymbols (struct mapped_symtab
*symtab
,
16829 struct partial_symbol
**psymp
,
16831 offset_type cu_index
,
16834 for (; count
-- > 0; ++psymp
)
16836 void **slot
, *lookup
;
16838 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
16839 error (_("Ada is not currently supported by the index"));
16841 /* We only want to add a given psymbol once. However, we also
16842 want to account for whether it is global or static. So, we
16843 may add it twice, using slightly different values. */
16846 uintptr_t val
= 1 | (uintptr_t) *psymp
;
16848 lookup
= (void *) val
;
16853 /* Only add a given psymbol once. */
16854 slot
= htab_find_slot (psyms_seen
, lookup
, INSERT
);
16858 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (*psymp
), cu_index
);
16863 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
16864 exception if there is an error. */
16867 write_obstack (FILE *file
, struct obstack
*obstack
)
16869 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
16871 != obstack_object_size (obstack
))
16872 error (_("couldn't data write to file"));
16875 /* Unlink a file if the argument is not NULL. */
16878 unlink_if_set (void *p
)
16880 char **filename
= p
;
16882 unlink (*filename
);
16885 /* A helper struct used when iterating over debug_types. */
16886 struct signatured_type_index_data
16888 struct objfile
*objfile
;
16889 struct mapped_symtab
*symtab
;
16890 struct obstack
*types_list
;
16895 /* A helper function that writes a single signatured_type to an
16899 write_one_signatured_type (void **slot
, void *d
)
16901 struct signatured_type_index_data
*info
= d
;
16902 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
16903 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
16904 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
16907 write_psymbols (info
->symtab
,
16909 info
->objfile
->global_psymbols
.list
16910 + psymtab
->globals_offset
,
16911 psymtab
->n_global_syms
, info
->cu_index
,
16913 write_psymbols (info
->symtab
,
16915 info
->objfile
->static_psymbols
.list
16916 + psymtab
->statics_offset
,
16917 psymtab
->n_static_syms
, info
->cu_index
,
16920 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->per_cu
.offset
);
16921 obstack_grow (info
->types_list
, val
, 8);
16922 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->type_offset
);
16923 obstack_grow (info
->types_list
, val
, 8);
16924 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
16925 obstack_grow (info
->types_list
, val
, 8);
16932 /* Create an index file for OBJFILE in the directory DIR. */
16935 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
16937 struct cleanup
*cleanup
;
16938 char *filename
, *cleanup_filename
;
16939 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
16940 struct obstack cu_list
, types_cu_list
;
16943 struct mapped_symtab
*symtab
;
16944 offset_type val
, size_of_contents
, total_len
;
16948 htab_t cu_index_htab
;
16949 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
16951 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
16954 if (dwarf2_per_objfile
->using_index
)
16955 error (_("Cannot use an index to create the index"));
16957 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
16958 error (_("Cannot make an index when the file has multiple .debug_types sections"));
16960 if (stat (objfile
->name
, &st
) < 0)
16961 perror_with_name (objfile
->name
);
16963 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
16964 INDEX_SUFFIX
, (char *) NULL
);
16965 cleanup
= make_cleanup (xfree
, filename
);
16967 out_file
= fopen (filename
, "wb");
16969 error (_("Can't open `%s' for writing"), filename
);
16971 cleanup_filename
= filename
;
16972 make_cleanup (unlink_if_set
, &cleanup_filename
);
16974 symtab
= create_mapped_symtab ();
16975 make_cleanup (cleanup_mapped_symtab
, symtab
);
16977 obstack_init (&addr_obstack
);
16978 make_cleanup_obstack_free (&addr_obstack
);
16980 obstack_init (&cu_list
);
16981 make_cleanup_obstack_free (&cu_list
);
16983 obstack_init (&types_cu_list
);
16984 make_cleanup_obstack_free (&types_cu_list
);
16986 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
16987 NULL
, xcalloc
, xfree
);
16988 make_cleanup_htab_delete (psyms_seen
);
16990 /* While we're scanning CU's create a table that maps a psymtab pointer
16991 (which is what addrmap records) to its index (which is what is recorded
16992 in the index file). This will later be needed to write the address
16994 cu_index_htab
= htab_create_alloc (100,
16995 hash_psymtab_cu_index
,
16996 eq_psymtab_cu_index
,
16997 NULL
, xcalloc
, xfree
);
16998 make_cleanup_htab_delete (cu_index_htab
);
16999 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
17000 xmalloc (sizeof (struct psymtab_cu_index_map
)
17001 * dwarf2_per_objfile
->n_comp_units
);
17002 make_cleanup (xfree
, psymtab_cu_index_map
);
17004 /* The CU list is already sorted, so we don't need to do additional
17005 work here. Also, the debug_types entries do not appear in
17006 all_comp_units, but only in their own hash table. */
17007 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
17009 struct dwarf2_per_cu_data
*per_cu
17010 = dwarf2_per_objfile
->all_comp_units
[i
];
17011 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
17013 struct psymtab_cu_index_map
*map
;
17016 write_psymbols (symtab
,
17018 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
17019 psymtab
->n_global_syms
, i
,
17021 write_psymbols (symtab
,
17023 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
17024 psymtab
->n_static_syms
, i
,
17027 map
= &psymtab_cu_index_map
[i
];
17028 map
->psymtab
= psymtab
;
17030 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
17031 gdb_assert (slot
!= NULL
);
17032 gdb_assert (*slot
== NULL
);
17035 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->offset
);
17036 obstack_grow (&cu_list
, val
, 8);
17037 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
17038 obstack_grow (&cu_list
, val
, 8);
17041 /* Dump the address map. */
17042 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
17044 /* Write out the .debug_type entries, if any. */
17045 if (dwarf2_per_objfile
->signatured_types
)
17047 struct signatured_type_index_data sig_data
;
17049 sig_data
.objfile
= objfile
;
17050 sig_data
.symtab
= symtab
;
17051 sig_data
.types_list
= &types_cu_list
;
17052 sig_data
.psyms_seen
= psyms_seen
;
17053 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
17054 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
17055 write_one_signatured_type
, &sig_data
);
17058 obstack_init (&constant_pool
);
17059 make_cleanup_obstack_free (&constant_pool
);
17060 obstack_init (&symtab_obstack
);
17061 make_cleanup_obstack_free (&symtab_obstack
);
17062 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
17064 obstack_init (&contents
);
17065 make_cleanup_obstack_free (&contents
);
17066 size_of_contents
= 6 * sizeof (offset_type
);
17067 total_len
= size_of_contents
;
17069 /* The version number. */
17070 val
= MAYBE_SWAP (6);
17071 obstack_grow (&contents
, &val
, sizeof (val
));
17073 /* The offset of the CU list from the start of the file. */
17074 val
= MAYBE_SWAP (total_len
);
17075 obstack_grow (&contents
, &val
, sizeof (val
));
17076 total_len
+= obstack_object_size (&cu_list
);
17078 /* The offset of the types CU list from the start of the file. */
17079 val
= MAYBE_SWAP (total_len
);
17080 obstack_grow (&contents
, &val
, sizeof (val
));
17081 total_len
+= obstack_object_size (&types_cu_list
);
17083 /* The offset of the address table from the start of the file. */
17084 val
= MAYBE_SWAP (total_len
);
17085 obstack_grow (&contents
, &val
, sizeof (val
));
17086 total_len
+= obstack_object_size (&addr_obstack
);
17088 /* The offset of the symbol table from the start of the file. */
17089 val
= MAYBE_SWAP (total_len
);
17090 obstack_grow (&contents
, &val
, sizeof (val
));
17091 total_len
+= obstack_object_size (&symtab_obstack
);
17093 /* The offset of the constant pool from the start of the file. */
17094 val
= MAYBE_SWAP (total_len
);
17095 obstack_grow (&contents
, &val
, sizeof (val
));
17096 total_len
+= obstack_object_size (&constant_pool
);
17098 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
17100 write_obstack (out_file
, &contents
);
17101 write_obstack (out_file
, &cu_list
);
17102 write_obstack (out_file
, &types_cu_list
);
17103 write_obstack (out_file
, &addr_obstack
);
17104 write_obstack (out_file
, &symtab_obstack
);
17105 write_obstack (out_file
, &constant_pool
);
17109 /* We want to keep the file, so we set cleanup_filename to NULL
17110 here. See unlink_if_set. */
17111 cleanup_filename
= NULL
;
17113 do_cleanups (cleanup
);
17116 /* Implementation of the `save gdb-index' command.
17118 Note that the file format used by this command is documented in the
17119 GDB manual. Any changes here must be documented there. */
17122 save_gdb_index_command (char *arg
, int from_tty
)
17124 struct objfile
*objfile
;
17127 error (_("usage: save gdb-index DIRECTORY"));
17129 ALL_OBJFILES (objfile
)
17133 /* If the objfile does not correspond to an actual file, skip it. */
17134 if (stat (objfile
->name
, &st
) < 0)
17137 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
17138 if (dwarf2_per_objfile
)
17140 volatile struct gdb_exception except
;
17142 TRY_CATCH (except
, RETURN_MASK_ERROR
)
17144 write_psymtabs_to_index (objfile
, arg
);
17146 if (except
.reason
< 0)
17147 exception_fprintf (gdb_stderr
, except
,
17148 _("Error while writing index for `%s': "),
17156 int dwarf2_always_disassemble
;
17159 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
17160 struct cmd_list_element
*c
, const char *value
)
17162 fprintf_filtered (file
,
17163 _("Whether to always disassemble "
17164 "DWARF expressions is %s.\n"),
17169 show_check_physname (struct ui_file
*file
, int from_tty
,
17170 struct cmd_list_element
*c
, const char *value
)
17172 fprintf_filtered (file
,
17173 _("Whether to check \"physname\" is %s.\n"),
17177 void _initialize_dwarf2_read (void);
17180 _initialize_dwarf2_read (void)
17182 struct cmd_list_element
*c
;
17184 dwarf2_objfile_data_key
17185 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
17187 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
17188 Set DWARF 2 specific variables.\n\
17189 Configure DWARF 2 variables such as the cache size"),
17190 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
17191 0/*allow-unknown*/, &maintenance_set_cmdlist
);
17193 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
17194 Show DWARF 2 specific variables\n\
17195 Show DWARF 2 variables such as the cache size"),
17196 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
17197 0/*allow-unknown*/, &maintenance_show_cmdlist
);
17199 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
17200 &dwarf2_max_cache_age
, _("\
17201 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
17202 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
17203 A higher limit means that cached compilation units will be stored\n\
17204 in memory longer, and more total memory will be used. Zero disables\n\
17205 caching, which can slow down startup."),
17207 show_dwarf2_max_cache_age
,
17208 &set_dwarf2_cmdlist
,
17209 &show_dwarf2_cmdlist
);
17211 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
17212 &dwarf2_always_disassemble
, _("\
17213 Set whether `info address' always disassembles DWARF expressions."), _("\
17214 Show whether `info address' always disassembles DWARF expressions."), _("\
17215 When enabled, DWARF expressions are always printed in an assembly-like\n\
17216 syntax. When disabled, expressions will be printed in a more\n\
17217 conversational style, when possible."),
17219 show_dwarf2_always_disassemble
,
17220 &set_dwarf2_cmdlist
,
17221 &show_dwarf2_cmdlist
);
17223 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
17224 Set debugging of the dwarf2 DIE reader."), _("\
17225 Show debugging of the dwarf2 DIE reader."), _("\
17226 When enabled (non-zero), DIEs are dumped after they are read in.\n\
17227 The value is the maximum depth to print."),
17230 &setdebuglist
, &showdebuglist
);
17232 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
17233 Set cross-checking of \"physname\" code against demangler."), _("\
17234 Show cross-checking of \"physname\" code against demangler."), _("\
17235 When enabled, GDB's internal \"physname\" code is checked against\n\
17237 NULL
, show_check_physname
,
17238 &setdebuglist
, &showdebuglist
);
17240 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
17242 Save a gdb-index file.\n\
17243 Usage: save gdb-index DIRECTORY"),
17245 set_cmd_completer (c
, filename_completer
);