1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2012 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
39 #include "gdb-demangle.h"
40 #include "expression.h"
41 #include "filenames.h" /* for DOSish file names */
44 #include "complaints.h"
46 #include "dwarf2expr.h"
47 #include "dwarf2loc.h"
48 #include "cp-support.h"
54 #include "typeprint.h"
57 #include "exceptions.h"
59 #include "completer.h"
66 #include "gdb_string.h"
67 #include "gdb_assert.h"
68 #include <sys/types.h>
75 #define MAP_FAILED ((void *) -1)
79 typedef struct symbol
*symbolp
;
82 /* When non-zero, dump DIEs after they are read in. */
83 static int dwarf2_die_debug
= 0;
85 /* When non-zero, cross-check physname against demangler. */
86 static int check_physname
= 0;
90 /* When set, the file that we're processing is known to have debugging
91 info for C++ namespaces. GCC 3.3.x did not produce this information,
92 but later versions do. */
94 static int processing_has_namespace_info
;
96 static const struct objfile_data
*dwarf2_objfile_data_key
;
98 struct dwarf2_section_info
103 /* Not NULL if the section was actually mmapped. */
105 /* Page aligned size of mmapped area. */
106 bfd_size_type map_len
;
107 /* True if we have tried to read this section. */
111 typedef struct dwarf2_section_info dwarf2_section_info_def
;
112 DEF_VEC_O (dwarf2_section_info_def
);
114 /* All offsets in the index are of this type. It must be
115 architecture-independent. */
116 typedef uint32_t offset_type
;
118 DEF_VEC_I (offset_type
);
120 /* A description of the mapped index. The file format is described in
121 a comment by the code that writes the index. */
124 /* Index data format version. */
127 /* The total length of the buffer. */
130 /* A pointer to the address table data. */
131 const gdb_byte
*address_table
;
133 /* Size of the address table data in bytes. */
134 offset_type address_table_size
;
136 /* The symbol table, implemented as a hash table. */
137 const offset_type
*symbol_table
;
139 /* Size in slots, each slot is 2 offset_types. */
140 offset_type symbol_table_slots
;
142 /* A pointer to the constant pool. */
143 const char *constant_pool
;
146 /* Collection of data recorded per objfile.
147 This hangs off of dwarf2_objfile_data_key. */
149 struct dwarf2_per_objfile
151 struct dwarf2_section_info info
;
152 struct dwarf2_section_info abbrev
;
153 struct dwarf2_section_info line
;
154 struct dwarf2_section_info loc
;
155 struct dwarf2_section_info macinfo
;
156 struct dwarf2_section_info macro
;
157 struct dwarf2_section_info str
;
158 struct dwarf2_section_info ranges
;
159 struct dwarf2_section_info frame
;
160 struct dwarf2_section_info eh_frame
;
161 struct dwarf2_section_info gdb_index
;
163 VEC (dwarf2_section_info_def
) *types
;
166 struct objfile
*objfile
;
168 /* Table of all the compilation units. This is used to locate
169 the target compilation unit of a particular reference. */
170 struct dwarf2_per_cu_data
**all_comp_units
;
172 /* The number of compilation units in ALL_COMP_UNITS. */
175 /* The number of .debug_types-related CUs. */
178 /* The .debug_types-related CUs (TUs). */
179 struct dwarf2_per_cu_data
**all_type_units
;
181 /* A chain of compilation units that are currently read in, so that
182 they can be freed later. */
183 struct dwarf2_per_cu_data
*read_in_chain
;
185 /* A table mapping .debug_types signatures to its signatured_type entry.
186 This is NULL if the .debug_types section hasn't been read in yet. */
187 htab_t signatured_types
;
189 /* A flag indicating wether this objfile has a section loaded at a
191 int has_section_at_zero
;
193 /* True if we are using the mapped index,
194 or we are faking it for OBJF_READNOW's sake. */
195 unsigned char using_index
;
197 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
198 struct mapped_index
*index_table
;
200 /* When using index_table, this keeps track of all quick_file_names entries.
201 TUs can share line table entries with CUs or other TUs, and there can be
202 a lot more TUs than unique line tables, so we maintain a separate table
203 of all line table entries to support the sharing. */
204 htab_t quick_file_names_table
;
206 /* Set during partial symbol reading, to prevent queueing of full
208 int reading_partial_symbols
;
210 /* Table mapping type .debug_info DIE offsets to types.
211 This is NULL if not allocated yet.
212 It (currently) makes sense to allocate debug_types_type_hash lazily.
213 To keep things simple we allocate both lazily. */
214 htab_t debug_info_type_hash
;
216 /* Table mapping type .debug_types DIE offsets to types.
217 This is NULL if not allocated yet. */
218 htab_t debug_types_type_hash
;
221 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
223 /* Default names of the debugging sections. */
225 /* Note that if the debugging section has been compressed, it might
226 have a name like .zdebug_info. */
228 static const struct dwarf2_debug_sections dwarf2_elf_names
=
230 { ".debug_info", ".zdebug_info" },
231 { ".debug_abbrev", ".zdebug_abbrev" },
232 { ".debug_line", ".zdebug_line" },
233 { ".debug_loc", ".zdebug_loc" },
234 { ".debug_macinfo", ".zdebug_macinfo" },
235 { ".debug_macro", ".zdebug_macro" },
236 { ".debug_str", ".zdebug_str" },
237 { ".debug_ranges", ".zdebug_ranges" },
238 { ".debug_types", ".zdebug_types" },
239 { ".debug_frame", ".zdebug_frame" },
240 { ".eh_frame", NULL
},
241 { ".gdb_index", ".zgdb_index" },
245 /* local data types */
247 /* We hold several abbreviation tables in memory at the same time. */
248 #ifndef ABBREV_HASH_SIZE
249 #define ABBREV_HASH_SIZE 121
252 /* The data in a compilation unit header, after target2host
253 translation, looks like this. */
254 struct comp_unit_head
258 unsigned char addr_size
;
259 unsigned char signed_addr_p
;
260 unsigned int abbrev_offset
;
262 /* Size of file offsets; either 4 or 8. */
263 unsigned int offset_size
;
265 /* Size of the length field; either 4 or 12. */
266 unsigned int initial_length_size
;
268 /* Offset to the first byte of this compilation unit header in the
269 .debug_info section, for resolving relative reference dies. */
272 /* Offset to first die in this cu from the start of the cu.
273 This will be the first byte following the compilation unit header. */
274 unsigned int first_die_offset
;
277 /* Type used for delaying computation of method physnames.
278 See comments for compute_delayed_physnames. */
279 struct delayed_method_info
281 /* The type to which the method is attached, i.e., its parent class. */
284 /* The index of the method in the type's function fieldlists. */
287 /* The index of the method in the fieldlist. */
290 /* The name of the DIE. */
293 /* The DIE associated with this method. */
294 struct die_info
*die
;
297 typedef struct delayed_method_info delayed_method_info
;
298 DEF_VEC_O (delayed_method_info
);
300 /* Internal state when decoding a particular compilation unit. */
303 /* The objfile containing this compilation unit. */
304 struct objfile
*objfile
;
306 /* The header of the compilation unit. */
307 struct comp_unit_head header
;
309 /* Base address of this compilation unit. */
310 CORE_ADDR base_address
;
312 /* Non-zero if base_address has been set. */
315 /* The language we are debugging. */
316 enum language language
;
317 const struct language_defn
*language_defn
;
319 const char *producer
;
321 /* The generic symbol table building routines have separate lists for
322 file scope symbols and all all other scopes (local scopes). So
323 we need to select the right one to pass to add_symbol_to_list().
324 We do it by keeping a pointer to the correct list in list_in_scope.
326 FIXME: The original dwarf code just treated the file scope as the
327 first local scope, and all other local scopes as nested local
328 scopes, and worked fine. Check to see if we really need to
329 distinguish these in buildsym.c. */
330 struct pending
**list_in_scope
;
332 /* DWARF abbreviation table associated with this compilation unit. */
333 struct abbrev_info
**dwarf2_abbrevs
;
335 /* Storage for the abbrev table. */
336 struct obstack abbrev_obstack
;
338 /* Hash table holding all the loaded partial DIEs. */
341 /* Storage for things with the same lifetime as this read-in compilation
342 unit, including partial DIEs. */
343 struct obstack comp_unit_obstack
;
345 /* When multiple dwarf2_cu structures are living in memory, this field
346 chains them all together, so that they can be released efficiently.
347 We will probably also want a generation counter so that most-recently-used
348 compilation units are cached... */
349 struct dwarf2_per_cu_data
*read_in_chain
;
351 /* Backchain to our per_cu entry if the tree has been built. */
352 struct dwarf2_per_cu_data
*per_cu
;
354 /* How many compilation units ago was this CU last referenced? */
357 /* A hash table of die offsets for following references. */
360 /* Full DIEs if read in. */
361 struct die_info
*dies
;
363 /* A set of pointers to dwarf2_per_cu_data objects for compilation
364 units referenced by this one. Only set during full symbol processing;
365 partial symbol tables do not have dependencies. */
368 /* Header data from the line table, during full symbol processing. */
369 struct line_header
*line_header
;
371 /* A list of methods which need to have physnames computed
372 after all type information has been read. */
373 VEC (delayed_method_info
) *method_list
;
375 /* To be copied to symtab->call_site_htab. */
376 htab_t call_site_htab
;
378 /* Mark used when releasing cached dies. */
379 unsigned int mark
: 1;
381 /* This flag will be set if this compilation unit might include
382 inter-compilation-unit references. */
383 unsigned int has_form_ref_addr
: 1;
385 /* This flag will be set if this compilation unit includes any
386 DW_TAG_namespace DIEs. If we know that there are explicit
387 DIEs for namespaces, we don't need to try to infer them
388 from mangled names. */
389 unsigned int has_namespace_info
: 1;
391 /* This CU references .debug_loc. See the symtab->locations_valid field.
392 This test is imperfect as there may exist optimized debug code not using
393 any location list and still facing inlining issues if handled as
394 unoptimized code. For a future better test see GCC PR other/32998. */
395 unsigned int has_loclist
: 1;
398 /* Persistent data held for a compilation unit, even when not
399 processing it. We put a pointer to this structure in the
400 read_symtab_private field of the psymtab. */
402 struct dwarf2_per_cu_data
404 /* The start offset and length of this compilation unit. 2**29-1
405 bytes should suffice to store the length of any compilation unit
406 - if it doesn't, GDB will fall over anyway.
407 NOTE: Unlike comp_unit_head.length, this length includes
408 initial_length_size. */
410 unsigned int length
: 29;
412 /* Flag indicating this compilation unit will be read in before
413 any of the current compilation units are processed. */
414 unsigned int queued
: 1;
416 /* This flag will be set if we need to load absolutely all DIEs
417 for this compilation unit, instead of just the ones we think
418 are interesting. It gets set if we look for a DIE in the
419 hash table and don't find it. */
420 unsigned int load_all_dies
: 1;
422 /* Non-null if this CU is from .debug_types; in which case it points
423 to the section. Otherwise it's from .debug_info. */
424 struct dwarf2_section_info
*debug_types_section
;
426 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
427 of the CU cache it gets reset to NULL again. */
428 struct dwarf2_cu
*cu
;
430 /* The corresponding objfile.
431 Normally we can get the objfile from dwarf2_per_objfile.
432 However we can enter this file with just a "per_cu" handle. */
433 struct objfile
*objfile
;
435 /* When using partial symbol tables, the 'psymtab' field is active.
436 Otherwise the 'quick' field is active. */
439 /* The partial symbol table associated with this compilation unit,
440 or NULL for partial units (which do not have an associated
442 struct partial_symtab
*psymtab
;
444 /* Data needed by the "quick" functions. */
445 struct dwarf2_per_cu_quick_data
*quick
;
449 /* Entry in the signatured_types hash table. */
451 struct signatured_type
455 /* Offset in .debug_types of the type defined by this TU. */
456 unsigned int type_offset
;
458 /* The CU(/TU) of this type. */
459 struct dwarf2_per_cu_data per_cu
;
462 /* Struct used to pass misc. parameters to read_die_and_children, et
463 al. which are used for both .debug_info and .debug_types dies.
464 All parameters here are unchanging for the life of the call. This
465 struct exists to abstract away the constant parameters of die
468 struct die_reader_specs
470 /* The bfd of this objfile. */
473 /* The CU of the DIE we are parsing. */
474 struct dwarf2_cu
*cu
;
476 /* Pointer to start of section buffer.
477 This is either the start of .debug_info or .debug_types. */
478 const gdb_byte
*buffer
;
481 /* The line number information for a compilation unit (found in the
482 .debug_line section) begins with a "statement program header",
483 which contains the following information. */
486 unsigned int total_length
;
487 unsigned short version
;
488 unsigned int header_length
;
489 unsigned char minimum_instruction_length
;
490 unsigned char maximum_ops_per_instruction
;
491 unsigned char default_is_stmt
;
493 unsigned char line_range
;
494 unsigned char opcode_base
;
496 /* standard_opcode_lengths[i] is the number of operands for the
497 standard opcode whose value is i. This means that
498 standard_opcode_lengths[0] is unused, and the last meaningful
499 element is standard_opcode_lengths[opcode_base - 1]. */
500 unsigned char *standard_opcode_lengths
;
502 /* The include_directories table. NOTE! These strings are not
503 allocated with xmalloc; instead, they are pointers into
504 debug_line_buffer. If you try to free them, `free' will get
506 unsigned int num_include_dirs
, include_dirs_size
;
509 /* The file_names table. NOTE! These strings are not allocated
510 with xmalloc; instead, they are pointers into debug_line_buffer.
511 Don't try to free them directly. */
512 unsigned int num_file_names
, file_names_size
;
516 unsigned int dir_index
;
517 unsigned int mod_time
;
519 int included_p
; /* Non-zero if referenced by the Line Number Program. */
520 struct symtab
*symtab
; /* The associated symbol table, if any. */
523 /* The start and end of the statement program following this
524 header. These point into dwarf2_per_objfile->line_buffer. */
525 gdb_byte
*statement_program_start
, *statement_program_end
;
528 /* When we construct a partial symbol table entry we only
529 need this much information. */
530 struct partial_die_info
532 /* Offset of this DIE. */
535 /* DWARF-2 tag for this DIE. */
536 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
538 /* Assorted flags describing the data found in this DIE. */
539 unsigned int has_children
: 1;
540 unsigned int is_external
: 1;
541 unsigned int is_declaration
: 1;
542 unsigned int has_type
: 1;
543 unsigned int has_specification
: 1;
544 unsigned int has_pc_info
: 1;
546 /* Flag set if the SCOPE field of this structure has been
548 unsigned int scope_set
: 1;
550 /* Flag set if the DIE has a byte_size attribute. */
551 unsigned int has_byte_size
: 1;
553 /* Flag set if any of the DIE's children are template arguments. */
554 unsigned int has_template_arguments
: 1;
556 /* Flag set if fixup_partial_die has been called on this die. */
557 unsigned int fixup_called
: 1;
559 /* The name of this DIE. Normally the value of DW_AT_name, but
560 sometimes a default name for unnamed DIEs. */
563 /* The linkage name, if present. */
564 const char *linkage_name
;
566 /* The scope to prepend to our children. This is generally
567 allocated on the comp_unit_obstack, so will disappear
568 when this compilation unit leaves the cache. */
571 /* The location description associated with this DIE, if any. */
572 struct dwarf_block
*locdesc
;
574 /* If HAS_PC_INFO, the PC range associated with this DIE. */
578 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
579 DW_AT_sibling, if any. */
580 /* NOTE: This member isn't strictly necessary, read_partial_die could
581 return DW_AT_sibling values to its caller load_partial_dies. */
584 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
585 DW_AT_specification (or DW_AT_abstract_origin or
587 unsigned int spec_offset
;
589 /* Pointers to this DIE's parent, first child, and next sibling,
591 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
594 /* This data structure holds the information of an abbrev. */
597 unsigned int number
; /* number identifying abbrev */
598 enum dwarf_tag tag
; /* dwarf tag */
599 unsigned short has_children
; /* boolean */
600 unsigned short num_attrs
; /* number of attributes */
601 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
602 struct abbrev_info
*next
; /* next in chain */
607 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
608 ENUM_BITFIELD(dwarf_form
) form
: 16;
611 /* Attributes have a name and a value. */
614 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
615 ENUM_BITFIELD(dwarf_form
) form
: 15;
617 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
618 field should be in u.str (existing only for DW_STRING) but it is kept
619 here for better struct attribute alignment. */
620 unsigned int string_is_canonical
: 1;
625 struct dwarf_block
*blk
;
629 struct signatured_type
*signatured_type
;
634 /* This data structure holds a complete die structure. */
637 /* DWARF-2 tag for this DIE. */
638 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
640 /* Number of attributes */
641 unsigned char num_attrs
;
643 /* True if we're presently building the full type name for the
644 type derived from this DIE. */
645 unsigned char building_fullname
: 1;
650 /* Offset in .debug_info or .debug_types section. */
653 /* The dies in a compilation unit form an n-ary tree. PARENT
654 points to this die's parent; CHILD points to the first child of
655 this node; and all the children of a given node are chained
656 together via their SIBLING fields. */
657 struct die_info
*child
; /* Its first child, if any. */
658 struct die_info
*sibling
; /* Its next sibling, if any. */
659 struct die_info
*parent
; /* Its parent, if any. */
661 /* An array of attributes, with NUM_ATTRS elements. There may be
662 zero, but it's not common and zero-sized arrays are not
663 sufficiently portable C. */
664 struct attribute attrs
[1];
667 /* Get at parts of an attribute structure. */
669 #define DW_STRING(attr) ((attr)->u.str)
670 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
671 #define DW_UNSND(attr) ((attr)->u.unsnd)
672 #define DW_BLOCK(attr) ((attr)->u.blk)
673 #define DW_SND(attr) ((attr)->u.snd)
674 #define DW_ADDR(attr) ((attr)->u.addr)
675 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
677 /* Blocks are a bunch of untyped bytes. */
682 /* Valid only if SIZE is not zero. */
686 #ifndef ATTR_ALLOC_CHUNK
687 #define ATTR_ALLOC_CHUNK 4
690 /* Allocate fields for structs, unions and enums in this size. */
691 #ifndef DW_FIELD_ALLOC_CHUNK
692 #define DW_FIELD_ALLOC_CHUNK 4
695 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
696 but this would require a corresponding change in unpack_field_as_long
698 static int bits_per_byte
= 8;
700 /* The routines that read and process dies for a C struct or C++ class
701 pass lists of data member fields and lists of member function fields
702 in an instance of a field_info structure, as defined below. */
705 /* List of data member and baseclasses fields. */
708 struct nextfield
*next
;
713 *fields
, *baseclasses
;
715 /* Number of fields (including baseclasses). */
718 /* Number of baseclasses. */
721 /* Set if the accesibility of one of the fields is not public. */
722 int non_public_fields
;
724 /* Member function fields array, entries are allocated in the order they
725 are encountered in the object file. */
728 struct nextfnfield
*next
;
729 struct fn_field fnfield
;
733 /* Member function fieldlist array, contains name of possibly overloaded
734 member function, number of overloaded member functions and a pointer
735 to the head of the member function field chain. */
740 struct nextfnfield
*head
;
744 /* Number of entries in the fnfieldlists array. */
747 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
748 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
749 struct typedef_field_list
751 struct typedef_field field
;
752 struct typedef_field_list
*next
;
755 unsigned typedef_field_list_count
;
758 /* One item on the queue of compilation units to read in full symbols
760 struct dwarf2_queue_item
762 struct dwarf2_per_cu_data
*per_cu
;
763 struct dwarf2_queue_item
*next
;
766 /* The current queue. */
767 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
769 /* Loaded secondary compilation units are kept in memory until they
770 have not been referenced for the processing of this many
771 compilation units. Set this to zero to disable caching. Cache
772 sizes of up to at least twenty will improve startup time for
773 typical inter-CU-reference binaries, at an obvious memory cost. */
774 static int dwarf2_max_cache_age
= 5;
776 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
777 struct cmd_list_element
*c
, const char *value
)
779 fprintf_filtered (file
, _("The upper bound on the age of cached "
780 "dwarf2 compilation units is %s.\n"),
785 /* Various complaints about symbol reading that don't abort the process. */
788 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
790 complaint (&symfile_complaints
,
791 _("statement list doesn't fit in .debug_line section"));
795 dwarf2_debug_line_missing_file_complaint (void)
797 complaint (&symfile_complaints
,
798 _(".debug_line section has line data without a file"));
802 dwarf2_debug_line_missing_end_sequence_complaint (void)
804 complaint (&symfile_complaints
,
805 _(".debug_line section has line "
806 "program sequence without an end"));
810 dwarf2_complex_location_expr_complaint (void)
812 complaint (&symfile_complaints
, _("location expression too complex"));
816 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
819 complaint (&symfile_complaints
,
820 _("const value length mismatch for '%s', got %d, expected %d"),
825 dwarf2_macros_too_long_complaint (struct dwarf2_section_info
*section
)
827 complaint (&symfile_complaints
,
828 _("macro info runs off end of `%s' section"),
829 section
->asection
->name
);
833 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
835 complaint (&symfile_complaints
,
836 _("macro debug info contains a "
837 "malformed macro definition:\n`%s'"),
842 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
844 complaint (&symfile_complaints
,
845 _("invalid attribute class or form for '%s' in '%s'"),
849 /* local function prototypes */
851 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
853 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
856 static void dwarf2_find_base_address (struct die_info
*die
,
857 struct dwarf2_cu
*cu
);
859 static void dwarf2_build_psymtabs_hard (struct objfile
*);
861 static void scan_partial_symbols (struct partial_die_info
*,
862 CORE_ADDR
*, CORE_ADDR
*,
863 int, struct dwarf2_cu
*);
865 static void add_partial_symbol (struct partial_die_info
*,
868 static void add_partial_namespace (struct partial_die_info
*pdi
,
869 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
870 int need_pc
, struct dwarf2_cu
*cu
);
872 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
873 CORE_ADDR
*highpc
, int need_pc
,
874 struct dwarf2_cu
*cu
);
876 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
877 struct dwarf2_cu
*cu
);
879 static void add_partial_subprogram (struct partial_die_info
*pdi
,
880 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
881 int need_pc
, struct dwarf2_cu
*cu
);
883 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
884 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
885 bfd
*abfd
, struct dwarf2_cu
*cu
);
887 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
889 static void psymtab_to_symtab_1 (struct partial_symtab
*);
891 static void dwarf2_read_abbrevs (struct dwarf2_cu
*cu
);
893 static void dwarf2_free_abbrev_table (void *);
895 static unsigned int peek_abbrev_code (bfd
*, gdb_byte
*);
897 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
900 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
903 static struct partial_die_info
*load_partial_dies (bfd
*,
904 gdb_byte
*, gdb_byte
*,
905 int, struct dwarf2_cu
*);
907 static gdb_byte
*read_partial_die (struct partial_die_info
*,
908 struct abbrev_info
*abbrev
,
910 gdb_byte
*, gdb_byte
*,
913 static struct partial_die_info
*find_partial_die (unsigned int,
916 static void fixup_partial_die (struct partial_die_info
*,
919 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
920 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
922 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
923 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
925 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
927 static int read_1_signed_byte (bfd
*, gdb_byte
*);
929 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
931 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
933 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
935 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
938 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
940 static LONGEST read_checked_initial_length_and_offset
941 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
942 unsigned int *, unsigned int *);
944 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
947 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
949 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
951 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
953 static char *read_indirect_string (bfd
*, gdb_byte
*,
954 const struct comp_unit_head
*,
957 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
959 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
961 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
963 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
965 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
968 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
972 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
973 struct dwarf2_cu
*cu
);
975 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
977 static struct die_info
*die_specification (struct die_info
*die
,
978 struct dwarf2_cu
**);
980 static void free_line_header (struct line_header
*lh
);
982 static void add_file_name (struct line_header
*, char *, unsigned int,
983 unsigned int, unsigned int);
985 static struct line_header
*(dwarf_decode_line_header
986 (unsigned int offset
,
987 bfd
*abfd
, struct dwarf2_cu
*cu
));
989 static void dwarf_decode_lines (struct line_header
*, const char *,
990 struct dwarf2_cu
*, struct partial_symtab
*,
993 static void dwarf2_start_subfile (char *, const char *, const char *);
995 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
998 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
999 struct dwarf2_cu
*, struct symbol
*);
1001 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1002 struct dwarf2_cu
*);
1004 static void dwarf2_const_value_attr (struct attribute
*attr
,
1007 struct obstack
*obstack
,
1008 struct dwarf2_cu
*cu
, long *value
,
1010 struct dwarf2_locexpr_baton
**baton
);
1012 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1014 static int need_gnat_info (struct dwarf2_cu
*);
1016 static struct type
*die_descriptive_type (struct die_info
*,
1017 struct dwarf2_cu
*);
1019 static void set_descriptive_type (struct type
*, struct die_info
*,
1020 struct dwarf2_cu
*);
1022 static struct type
*die_containing_type (struct die_info
*,
1023 struct dwarf2_cu
*);
1025 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1026 struct dwarf2_cu
*);
1028 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1030 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1032 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1034 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1035 const char *suffix
, int physname
,
1036 struct dwarf2_cu
*cu
);
1038 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1040 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1042 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1044 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1046 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1048 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1049 struct dwarf2_cu
*, struct partial_symtab
*);
1051 static int dwarf2_get_pc_bounds (struct die_info
*,
1052 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1053 struct partial_symtab
*);
1055 static void get_scope_pc_bounds (struct die_info
*,
1056 CORE_ADDR
*, CORE_ADDR
*,
1057 struct dwarf2_cu
*);
1059 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1060 CORE_ADDR
, struct dwarf2_cu
*);
1062 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1063 struct dwarf2_cu
*);
1065 static void dwarf2_attach_fields_to_type (struct field_info
*,
1066 struct type
*, struct dwarf2_cu
*);
1068 static void dwarf2_add_member_fn (struct field_info
*,
1069 struct die_info
*, struct type
*,
1070 struct dwarf2_cu
*);
1072 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1074 struct dwarf2_cu
*);
1076 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1078 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1080 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1082 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1084 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1086 static struct type
*read_module_type (struct die_info
*die
,
1087 struct dwarf2_cu
*cu
);
1089 static const char *namespace_name (struct die_info
*die
,
1090 int *is_anonymous
, struct dwarf2_cu
*);
1092 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1094 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1096 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1097 struct dwarf2_cu
*);
1099 static struct die_info
*read_comp_unit (gdb_byte
*, struct dwarf2_cu
*);
1101 static struct die_info
*read_die_and_children_1 (const struct die_reader_specs
*reader
,
1103 gdb_byte
**new_info_ptr
,
1104 struct die_info
*parent
);
1106 static struct die_info
*read_die_and_children (const struct die_reader_specs
*reader
,
1108 gdb_byte
**new_info_ptr
,
1109 struct die_info
*parent
);
1111 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*reader
,
1113 gdb_byte
**new_info_ptr
,
1114 struct die_info
*parent
);
1116 static gdb_byte
*read_full_die (const struct die_reader_specs
*reader
,
1117 struct die_info
**, gdb_byte
*,
1120 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1122 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1125 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1127 static const char *dwarf2_full_name (char *name
,
1128 struct die_info
*die
,
1129 struct dwarf2_cu
*cu
);
1131 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1132 struct dwarf2_cu
**);
1134 static char *dwarf_tag_name (unsigned int);
1136 static char *dwarf_attr_name (unsigned int);
1138 static char *dwarf_form_name (unsigned int);
1140 static char *dwarf_bool_name (unsigned int);
1142 static char *dwarf_type_encoding_name (unsigned int);
1145 static char *dwarf_cfi_name (unsigned int);
1148 static struct die_info
*sibling_die (struct die_info
*);
1150 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1152 static void dump_die_for_error (struct die_info
*);
1154 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1157 /*static*/ void dump_die (struct die_info
*, int max_level
);
1159 static void store_in_ref_table (struct die_info
*,
1160 struct dwarf2_cu
*);
1162 static int is_ref_attr (struct attribute
*);
1164 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1166 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1168 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1170 struct dwarf2_cu
**);
1172 static struct die_info
*follow_die_ref (struct die_info
*,
1174 struct dwarf2_cu
**);
1176 static struct die_info
*follow_die_sig (struct die_info
*,
1178 struct dwarf2_cu
**);
1180 static struct signatured_type
*lookup_signatured_type_at_offset
1181 (struct objfile
*objfile
,
1182 struct dwarf2_section_info
*section
,
1183 unsigned int offset
);
1185 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1187 static void read_signatured_type (struct signatured_type
*type_sig
);
1189 /* memory allocation interface */
1191 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1193 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1195 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1197 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1198 char *, bfd
*, struct dwarf2_cu
*,
1199 struct dwarf2_section_info
*,
1202 static int attr_form_is_block (struct attribute
*);
1204 static int attr_form_is_section_offset (struct attribute
*);
1206 static int attr_form_is_constant (struct attribute
*);
1208 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1209 struct dwarf2_loclist_baton
*baton
,
1210 struct attribute
*attr
);
1212 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1214 struct dwarf2_cu
*cu
);
1216 static gdb_byte
*skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1217 struct abbrev_info
*abbrev
,
1218 struct dwarf2_cu
*cu
);
1220 static void free_stack_comp_unit (void *);
1222 static hashval_t
partial_die_hash (const void *item
);
1224 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1226 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1227 (unsigned int offset
, struct objfile
*objfile
);
1229 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1230 struct dwarf2_per_cu_data
*per_cu
);
1232 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1233 struct die_info
*comp_unit_die
);
1235 static void free_heap_comp_unit (void *);
1237 static void free_cached_comp_units (void *);
1239 static void age_cached_comp_units (void);
1241 static void free_one_cached_comp_unit (void *);
1243 static struct type
*set_die_type (struct die_info
*, struct type
*,
1244 struct dwarf2_cu
*);
1246 static void create_all_comp_units (struct objfile
*);
1248 static int create_debug_types_hash_table (struct objfile
*objfile
);
1250 static void load_full_comp_unit (struct dwarf2_per_cu_data
*);
1252 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1254 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1255 struct dwarf2_per_cu_data
*);
1257 static void dwarf2_mark (struct dwarf2_cu
*);
1259 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1261 static struct type
*get_die_type_at_offset (unsigned int,
1262 struct dwarf2_per_cu_data
*per_cu
);
1264 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1266 static void dwarf2_release_queue (void *dummy
);
1268 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
);
1270 static void process_queue (void);
1272 static void find_file_and_directory (struct die_info
*die
,
1273 struct dwarf2_cu
*cu
,
1274 char **name
, char **comp_dir
);
1276 static char *file_full_name (int file
, struct line_header
*lh
,
1277 const char *comp_dir
);
1279 static gdb_byte
*read_and_check_comp_unit_head
1280 (struct comp_unit_head
*header
,
1281 struct dwarf2_section_info
*section
, gdb_byte
*info_ptr
,
1282 int is_debug_types_section
);
1284 static void init_cu_die_reader (struct die_reader_specs
*reader
,
1285 struct dwarf2_cu
*cu
);
1287 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1291 /* Convert VALUE between big- and little-endian. */
1293 byte_swap (offset_type value
)
1297 result
= (value
& 0xff) << 24;
1298 result
|= (value
& 0xff00) << 8;
1299 result
|= (value
& 0xff0000) >> 8;
1300 result
|= (value
& 0xff000000) >> 24;
1304 #define MAYBE_SWAP(V) byte_swap (V)
1307 #define MAYBE_SWAP(V) (V)
1308 #endif /* WORDS_BIGENDIAN */
1310 /* The suffix for an index file. */
1311 #define INDEX_SUFFIX ".gdb-index"
1313 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1314 struct dwarf2_cu
*cu
);
1316 /* Try to locate the sections we need for DWARF 2 debugging
1317 information and return true if we have enough to do something.
1318 NAMES points to the dwarf2 section names, or is NULL if the standard
1319 ELF names are used. */
1322 dwarf2_has_info (struct objfile
*objfile
,
1323 const struct dwarf2_debug_sections
*names
)
1325 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1326 if (!dwarf2_per_objfile
)
1328 /* Initialize per-objfile state. */
1329 struct dwarf2_per_objfile
*data
1330 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1332 memset (data
, 0, sizeof (*data
));
1333 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1334 dwarf2_per_objfile
= data
;
1336 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1338 dwarf2_per_objfile
->objfile
= objfile
;
1340 return (dwarf2_per_objfile
->info
.asection
!= NULL
1341 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1344 /* When loading sections, we look either for uncompressed section or for
1345 compressed section names. */
1348 section_is_p (const char *section_name
,
1349 const struct dwarf2_section_names
*names
)
1351 if (names
->normal
!= NULL
1352 && strcmp (section_name
, names
->normal
) == 0)
1354 if (names
->compressed
!= NULL
1355 && strcmp (section_name
, names
->compressed
) == 0)
1360 /* This function is mapped across the sections and remembers the
1361 offset and size of each of the debugging sections we are interested
1365 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1367 const struct dwarf2_debug_sections
*names
;
1370 names
= &dwarf2_elf_names
;
1372 names
= (const struct dwarf2_debug_sections
*) vnames
;
1374 if (section_is_p (sectp
->name
, &names
->info
))
1376 dwarf2_per_objfile
->info
.asection
= sectp
;
1377 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1379 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1381 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1382 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1384 else if (section_is_p (sectp
->name
, &names
->line
))
1386 dwarf2_per_objfile
->line
.asection
= sectp
;
1387 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1389 else if (section_is_p (sectp
->name
, &names
->loc
))
1391 dwarf2_per_objfile
->loc
.asection
= sectp
;
1392 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1394 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1396 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1397 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1399 else if (section_is_p (sectp
->name
, &names
->macro
))
1401 dwarf2_per_objfile
->macro
.asection
= sectp
;
1402 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
1404 else if (section_is_p (sectp
->name
, &names
->str
))
1406 dwarf2_per_objfile
->str
.asection
= sectp
;
1407 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1409 else if (section_is_p (sectp
->name
, &names
->frame
))
1411 dwarf2_per_objfile
->frame
.asection
= sectp
;
1412 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1414 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1416 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1418 if (aflag
& SEC_HAS_CONTENTS
)
1420 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1421 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1424 else if (section_is_p (sectp
->name
, &names
->ranges
))
1426 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1427 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1429 else if (section_is_p (sectp
->name
, &names
->types
))
1431 struct dwarf2_section_info type_section
;
1433 memset (&type_section
, 0, sizeof (type_section
));
1434 type_section
.asection
= sectp
;
1435 type_section
.size
= bfd_get_section_size (sectp
);
1437 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
1440 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1442 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1443 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1446 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1447 && bfd_section_vma (abfd
, sectp
) == 0)
1448 dwarf2_per_objfile
->has_section_at_zero
= 1;
1451 /* Decompress a section that was compressed using zlib. Store the
1452 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1455 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1456 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1458 bfd
*abfd
= objfile
->obfd
;
1460 error (_("Support for zlib-compressed DWARF data (from '%s') "
1461 "is disabled in this copy of GDB"),
1462 bfd_get_filename (abfd
));
1464 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1465 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1466 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1467 bfd_size_type uncompressed_size
;
1468 gdb_byte
*uncompressed_buffer
;
1471 int header_size
= 12;
1473 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1474 || bfd_bread (compressed_buffer
,
1475 compressed_size
, abfd
) != compressed_size
)
1476 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1477 bfd_get_filename (abfd
));
1479 /* Read the zlib header. In this case, it should be "ZLIB" followed
1480 by the uncompressed section size, 8 bytes in big-endian order. */
1481 if (compressed_size
< header_size
1482 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1483 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1484 bfd_get_filename (abfd
));
1485 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1486 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1487 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1488 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1489 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1490 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1491 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1492 uncompressed_size
+= compressed_buffer
[11];
1494 /* It is possible the section consists of several compressed
1495 buffers concatenated together, so we uncompress in a loop. */
1499 strm
.avail_in
= compressed_size
- header_size
;
1500 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1501 strm
.avail_out
= uncompressed_size
;
1502 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1504 rc
= inflateInit (&strm
);
1505 while (strm
.avail_in
> 0)
1508 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1509 bfd_get_filename (abfd
), rc
);
1510 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1511 + (uncompressed_size
- strm
.avail_out
));
1512 rc
= inflate (&strm
, Z_FINISH
);
1513 if (rc
!= Z_STREAM_END
)
1514 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1515 bfd_get_filename (abfd
), rc
);
1516 rc
= inflateReset (&strm
);
1518 rc
= inflateEnd (&strm
);
1520 || strm
.avail_out
!= 0)
1521 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1522 bfd_get_filename (abfd
), rc
);
1524 do_cleanups (cleanup
);
1525 *outbuf
= uncompressed_buffer
;
1526 *outsize
= uncompressed_size
;
1530 /* A helper function that decides whether a section is empty. */
1533 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1535 return info
->asection
== NULL
|| info
->size
== 0;
1538 /* Read the contents of the section INFO from object file specified by
1539 OBJFILE, store info about the section into INFO.
1540 If the section is compressed, uncompress it before returning. */
1543 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1545 bfd
*abfd
= objfile
->obfd
;
1546 asection
*sectp
= info
->asection
;
1547 gdb_byte
*buf
, *retbuf
;
1548 unsigned char header
[4];
1552 info
->buffer
= NULL
;
1553 info
->map_addr
= NULL
;
1556 if (dwarf2_section_empty_p (info
))
1559 /* Check if the file has a 4-byte header indicating compression. */
1560 if (info
->size
> sizeof (header
)
1561 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1562 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1564 /* Upon decompression, update the buffer and its size. */
1565 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1567 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1575 pagesize
= getpagesize ();
1577 /* Only try to mmap sections which are large enough: we don't want to
1578 waste space due to fragmentation. Also, only try mmap for sections
1579 without relocations. */
1581 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1583 info
->buffer
= bfd_mmap (abfd
, 0, info
->size
, PROT_READ
,
1584 MAP_PRIVATE
, sectp
->filepos
,
1585 &info
->map_addr
, &info
->map_len
);
1587 if ((caddr_t
)info
->buffer
!= MAP_FAILED
)
1589 #if HAVE_POSIX_MADVISE
1590 posix_madvise (info
->map_addr
, info
->map_len
, POSIX_MADV_WILLNEED
);
1597 /* If we get here, we are a normal, not-compressed section. */
1599 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1601 /* When debugging .o files, we may need to apply relocations; see
1602 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1603 We never compress sections in .o files, so we only need to
1604 try this when the section is not compressed. */
1605 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1608 info
->buffer
= retbuf
;
1612 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1613 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1614 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1615 bfd_get_filename (abfd
));
1618 /* A helper function that returns the size of a section in a safe way.
1619 If you are positive that the section has been read before using the
1620 size, then it is safe to refer to the dwarf2_section_info object's
1621 "size" field directly. In other cases, you must call this
1622 function, because for compressed sections the size field is not set
1623 correctly until the section has been read. */
1625 static bfd_size_type
1626 dwarf2_section_size (struct objfile
*objfile
,
1627 struct dwarf2_section_info
*info
)
1630 dwarf2_read_section (objfile
, info
);
1634 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1638 dwarf2_get_section_info (struct objfile
*objfile
,
1639 enum dwarf2_section_enum sect
,
1640 asection
**sectp
, gdb_byte
**bufp
,
1641 bfd_size_type
*sizep
)
1643 struct dwarf2_per_objfile
*data
1644 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1645 struct dwarf2_section_info
*info
;
1647 /* We may see an objfile without any DWARF, in which case we just
1658 case DWARF2_DEBUG_FRAME
:
1659 info
= &data
->frame
;
1661 case DWARF2_EH_FRAME
:
1662 info
= &data
->eh_frame
;
1665 gdb_assert_not_reached ("unexpected section");
1668 dwarf2_read_section (objfile
, info
);
1670 *sectp
= info
->asection
;
1671 *bufp
= info
->buffer
;
1672 *sizep
= info
->size
;
1676 /* DWARF quick_symbols_functions support. */
1678 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1679 unique line tables, so we maintain a separate table of all .debug_line
1680 derived entries to support the sharing.
1681 All the quick functions need is the list of file names. We discard the
1682 line_header when we're done and don't need to record it here. */
1683 struct quick_file_names
1685 /* The offset in .debug_line of the line table. We hash on this. */
1686 unsigned int offset
;
1688 /* The number of entries in file_names, real_names. */
1689 unsigned int num_file_names
;
1691 /* The file names from the line table, after being run through
1693 const char **file_names
;
1695 /* The file names from the line table after being run through
1696 gdb_realpath. These are computed lazily. */
1697 const char **real_names
;
1700 /* When using the index (and thus not using psymtabs), each CU has an
1701 object of this type. This is used to hold information needed by
1702 the various "quick" methods. */
1703 struct dwarf2_per_cu_quick_data
1705 /* The file table. This can be NULL if there was no file table
1706 or it's currently not read in.
1707 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1708 struct quick_file_names
*file_names
;
1710 /* The corresponding symbol table. This is NULL if symbols for this
1711 CU have not yet been read. */
1712 struct symtab
*symtab
;
1714 /* A temporary mark bit used when iterating over all CUs in
1715 expand_symtabs_matching. */
1716 unsigned int mark
: 1;
1718 /* True if we've tried to read the file table and found there isn't one.
1719 There will be no point in trying to read it again next time. */
1720 unsigned int no_file_data
: 1;
1723 /* Hash function for a quick_file_names. */
1726 hash_file_name_entry (const void *e
)
1728 const struct quick_file_names
*file_data
= e
;
1730 return file_data
->offset
;
1733 /* Equality function for a quick_file_names. */
1736 eq_file_name_entry (const void *a
, const void *b
)
1738 const struct quick_file_names
*ea
= a
;
1739 const struct quick_file_names
*eb
= b
;
1741 return ea
->offset
== eb
->offset
;
1744 /* Delete function for a quick_file_names. */
1747 delete_file_name_entry (void *e
)
1749 struct quick_file_names
*file_data
= e
;
1752 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
1754 xfree ((void*) file_data
->file_names
[i
]);
1755 if (file_data
->real_names
)
1756 xfree ((void*) file_data
->real_names
[i
]);
1759 /* The space for the struct itself lives on objfile_obstack,
1760 so we don't free it here. */
1763 /* Create a quick_file_names hash table. */
1766 create_quick_file_names_table (unsigned int nr_initial_entries
)
1768 return htab_create_alloc (nr_initial_entries
,
1769 hash_file_name_entry
, eq_file_name_entry
,
1770 delete_file_name_entry
, xcalloc
, xfree
);
1773 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
1774 have to be created afterwards. You should call age_cached_comp_units after
1775 processing PER_CU->CU. dw2_setup must have been already called. */
1778 load_cu (struct dwarf2_per_cu_data
*per_cu
)
1780 if (per_cu
->debug_types_section
)
1781 load_full_type_unit (per_cu
);
1783 load_full_comp_unit (per_cu
);
1785 gdb_assert (per_cu
->cu
!= NULL
);
1787 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
1790 /* Read in the symbols for PER_CU. */
1793 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
1795 struct cleanup
*back_to
;
1797 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
1799 queue_comp_unit (per_cu
);
1805 /* Age the cache, releasing compilation units that have not
1806 been used recently. */
1807 age_cached_comp_units ();
1809 do_cleanups (back_to
);
1812 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1813 the objfile from which this CU came. Returns the resulting symbol
1816 static struct symtab
*
1817 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
1819 if (!per_cu
->v
.quick
->symtab
)
1821 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1822 increment_reading_symtab ();
1823 dw2_do_instantiate_symtab (per_cu
);
1824 do_cleanups (back_to
);
1826 return per_cu
->v
.quick
->symtab
;
1829 /* Return the CU given its index. */
1831 static struct dwarf2_per_cu_data
*
1832 dw2_get_cu (int index
)
1834 if (index
>= dwarf2_per_objfile
->n_comp_units
)
1836 index
-= dwarf2_per_objfile
->n_comp_units
;
1837 return dwarf2_per_objfile
->all_type_units
[index
];
1839 return dwarf2_per_objfile
->all_comp_units
[index
];
1842 /* A helper function that knows how to read a 64-bit value in a way
1843 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1847 extract_cu_value (const char *bytes
, ULONGEST
*result
)
1849 if (sizeof (ULONGEST
) < 8)
1853 /* Ignore the upper 4 bytes if they are all zero. */
1854 for (i
= 0; i
< 4; ++i
)
1855 if (bytes
[i
+ 4] != 0)
1858 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
1861 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
1865 /* Read the CU list from the mapped index, and use it to create all
1866 the CU objects for this objfile. Return 0 if something went wrong,
1867 1 if everything went ok. */
1870 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
1871 offset_type cu_list_elements
)
1875 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
1876 dwarf2_per_objfile
->all_comp_units
1877 = obstack_alloc (&objfile
->objfile_obstack
,
1878 dwarf2_per_objfile
->n_comp_units
1879 * sizeof (struct dwarf2_per_cu_data
*));
1881 for (i
= 0; i
< cu_list_elements
; i
+= 2)
1883 struct dwarf2_per_cu_data
*the_cu
;
1884 ULONGEST offset
, length
;
1886 if (!extract_cu_value (cu_list
, &offset
)
1887 || !extract_cu_value (cu_list
+ 8, &length
))
1891 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1892 struct dwarf2_per_cu_data
);
1893 the_cu
->offset
= offset
;
1894 the_cu
->length
= length
;
1895 the_cu
->objfile
= objfile
;
1896 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1897 struct dwarf2_per_cu_quick_data
);
1898 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
1904 /* Create the signatured type hash table from the index. */
1907 create_signatured_type_table_from_index (struct objfile
*objfile
,
1908 struct dwarf2_section_info
*section
,
1909 const gdb_byte
*bytes
,
1910 offset_type elements
)
1913 htab_t sig_types_hash
;
1915 dwarf2_per_objfile
->n_type_units
= elements
/ 3;
1916 dwarf2_per_objfile
->all_type_units
1917 = obstack_alloc (&objfile
->objfile_obstack
,
1918 dwarf2_per_objfile
->n_type_units
1919 * sizeof (struct dwarf2_per_cu_data
*));
1921 sig_types_hash
= allocate_signatured_type_table (objfile
);
1923 for (i
= 0; i
< elements
; i
+= 3)
1925 struct signatured_type
*type_sig
;
1926 ULONGEST offset
, type_offset
, signature
;
1929 if (!extract_cu_value (bytes
, &offset
)
1930 || !extract_cu_value (bytes
+ 8, &type_offset
))
1932 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
1935 type_sig
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1936 struct signatured_type
);
1937 type_sig
->signature
= signature
;
1938 type_sig
->type_offset
= type_offset
;
1939 type_sig
->per_cu
.debug_types_section
= section
;
1940 type_sig
->per_cu
.offset
= offset
;
1941 type_sig
->per_cu
.objfile
= objfile
;
1942 type_sig
->per_cu
.v
.quick
1943 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1944 struct dwarf2_per_cu_quick_data
);
1946 slot
= htab_find_slot (sig_types_hash
, type_sig
, INSERT
);
1949 dwarf2_per_objfile
->all_type_units
[i
/ 3] = &type_sig
->per_cu
;
1952 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
1957 /* Read the address map data from the mapped index, and use it to
1958 populate the objfile's psymtabs_addrmap. */
1961 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
1963 const gdb_byte
*iter
, *end
;
1964 struct obstack temp_obstack
;
1965 struct addrmap
*mutable_map
;
1966 struct cleanup
*cleanup
;
1969 obstack_init (&temp_obstack
);
1970 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
1971 mutable_map
= addrmap_create_mutable (&temp_obstack
);
1973 iter
= index
->address_table
;
1974 end
= iter
+ index
->address_table_size
;
1976 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1980 ULONGEST hi
, lo
, cu_index
;
1981 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1983 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1985 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
1988 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
1989 dw2_get_cu (cu_index
));
1992 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
1993 &objfile
->objfile_obstack
);
1994 do_cleanups (cleanup
);
1997 /* The hash function for strings in the mapped index. This is the same as
1998 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
1999 implementation. This is necessary because the hash function is tied to the
2000 format of the mapped index file. The hash values do not have to match with
2003 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2006 mapped_index_string_hash (int index_version
, const void *p
)
2008 const unsigned char *str
= (const unsigned char *) p
;
2012 while ((c
= *str
++) != 0)
2014 if (index_version
>= 5)
2016 r
= r
* 67 + c
- 113;
2022 /* Find a slot in the mapped index INDEX for the object named NAME.
2023 If NAME is found, set *VEC_OUT to point to the CU vector in the
2024 constant pool and return 1. If NAME cannot be found, return 0. */
2027 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2028 offset_type
**vec_out
)
2030 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2032 offset_type slot
, step
;
2033 int (*cmp
) (const char *, const char *);
2035 if (current_language
->la_language
== language_cplus
2036 || current_language
->la_language
== language_java
2037 || current_language
->la_language
== language_fortran
)
2039 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2041 const char *paren
= strchr (name
, '(');
2047 dup
= xmalloc (paren
- name
+ 1);
2048 memcpy (dup
, name
, paren
- name
);
2049 dup
[paren
- name
] = 0;
2051 make_cleanup (xfree
, dup
);
2056 /* Index version 4 did not support case insensitive searches. But the
2057 indexes for case insensitive languages are built in lowercase, therefore
2058 simulate our NAME being searched is also lowercased. */
2059 hash
= mapped_index_string_hash ((index
->version
== 4
2060 && case_sensitivity
== case_sensitive_off
2061 ? 5 : index
->version
),
2064 slot
= hash
& (index
->symbol_table_slots
- 1);
2065 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2066 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2070 /* Convert a slot number to an offset into the table. */
2071 offset_type i
= 2 * slot
;
2073 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2075 do_cleanups (back_to
);
2079 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2080 if (!cmp (name
, str
))
2082 *vec_out
= (offset_type
*) (index
->constant_pool
2083 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2084 do_cleanups (back_to
);
2088 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2092 /* Read the index file. If everything went ok, initialize the "quick"
2093 elements of all the CUs and return 1. Otherwise, return 0. */
2096 dwarf2_read_index (struct objfile
*objfile
)
2099 struct mapped_index
*map
;
2100 offset_type
*metadata
;
2101 const gdb_byte
*cu_list
;
2102 const gdb_byte
*types_list
= NULL
;
2103 offset_type version
, cu_list_elements
;
2104 offset_type types_list_elements
= 0;
2107 if (dwarf2_section_empty_p (&dwarf2_per_objfile
->gdb_index
))
2110 /* Older elfutils strip versions could keep the section in the main
2111 executable while splitting it for the separate debug info file. */
2112 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
2113 & SEC_HAS_CONTENTS
) == 0)
2116 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
2118 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
2119 /* Version check. */
2120 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2121 /* Versions earlier than 3 emitted every copy of a psymbol. This
2122 causes the index to behave very poorly for certain requests. Version 3
2123 contained incomplete addrmap. So, it seems better to just ignore such
2124 indices. Index version 4 uses a different hash function than index
2125 version 5 and later. */
2128 /* Indexes with higher version than the one supported by GDB may be no
2129 longer backward compatible. */
2133 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
2134 map
->version
= version
;
2135 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
2137 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2140 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2141 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2145 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2146 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2147 - MAYBE_SWAP (metadata
[i
]))
2151 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2152 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2153 - MAYBE_SWAP (metadata
[i
]));
2156 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2157 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2158 - MAYBE_SWAP (metadata
[i
]))
2159 / (2 * sizeof (offset_type
)));
2162 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2164 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
2167 if (types_list_elements
)
2169 struct dwarf2_section_info
*section
;
2171 /* We can only handle a single .debug_types when we have an
2173 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2176 section
= VEC_index (dwarf2_section_info_def
,
2177 dwarf2_per_objfile
->types
, 0);
2179 if (!create_signatured_type_table_from_index (objfile
, section
,
2181 types_list_elements
))
2185 create_addrmap_from_index (objfile
, map
);
2187 dwarf2_per_objfile
->index_table
= map
;
2188 dwarf2_per_objfile
->using_index
= 1;
2189 dwarf2_per_objfile
->quick_file_names_table
=
2190 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2195 /* A helper for the "quick" functions which sets the global
2196 dwarf2_per_objfile according to OBJFILE. */
2199 dw2_setup (struct objfile
*objfile
)
2201 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2202 gdb_assert (dwarf2_per_objfile
);
2205 /* A helper for the "quick" functions which attempts to read the line
2206 table for THIS_CU. */
2208 static struct quick_file_names
*
2209 dw2_get_file_names (struct objfile
*objfile
,
2210 struct dwarf2_per_cu_data
*this_cu
)
2212 bfd
*abfd
= objfile
->obfd
;
2213 struct line_header
*lh
;
2214 struct attribute
*attr
;
2215 struct cleanup
*cleanups
;
2216 struct die_info
*comp_unit_die
;
2217 struct dwarf2_section_info
* sec
;
2219 int has_children
, i
;
2220 struct dwarf2_cu cu
;
2221 unsigned int bytes_read
;
2222 struct die_reader_specs reader_specs
;
2223 char *name
, *comp_dir
;
2225 struct quick_file_names
*qfn
;
2226 unsigned int line_offset
;
2228 if (this_cu
->v
.quick
->file_names
!= NULL
)
2229 return this_cu
->v
.quick
->file_names
;
2230 /* If we know there is no line data, no point in looking again. */
2231 if (this_cu
->v
.quick
->no_file_data
)
2234 init_one_comp_unit (&cu
, this_cu
);
2235 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
2237 if (this_cu
->debug_types_section
)
2238 sec
= this_cu
->debug_types_section
;
2240 sec
= &dwarf2_per_objfile
->info
;
2241 dwarf2_read_section (objfile
, sec
);
2242 info_ptr
= sec
->buffer
+ this_cu
->offset
;
2244 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, sec
, info_ptr
,
2245 this_cu
->debug_types_section
!= NULL
);
2247 /* Skip dummy compilation units. */
2248 if (info_ptr
>= (sec
->buffer
+ sec
->size
)
2249 || peek_abbrev_code (abfd
, info_ptr
) == 0)
2251 do_cleanups (cleanups
);
2255 dwarf2_read_abbrevs (&cu
);
2256 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2258 init_cu_die_reader (&reader_specs
, &cu
);
2259 read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2265 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, &cu
);
2268 struct quick_file_names find_entry
;
2270 line_offset
= DW_UNSND (attr
);
2272 /* We may have already read in this line header (TU line header sharing).
2273 If we have we're done. */
2274 find_entry
.offset
= line_offset
;
2275 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2276 &find_entry
, INSERT
);
2279 do_cleanups (cleanups
);
2280 this_cu
->v
.quick
->file_names
= *slot
;
2284 lh
= dwarf_decode_line_header (line_offset
, abfd
, &cu
);
2288 do_cleanups (cleanups
);
2289 this_cu
->v
.quick
->no_file_data
= 1;
2293 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2294 qfn
->offset
= line_offset
;
2295 gdb_assert (slot
!= NULL
);
2298 find_file_and_directory (comp_unit_die
, &cu
, &name
, &comp_dir
);
2300 qfn
->num_file_names
= lh
->num_file_names
;
2301 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2302 lh
->num_file_names
* sizeof (char *));
2303 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2304 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2305 qfn
->real_names
= NULL
;
2307 free_line_header (lh
);
2308 do_cleanups (cleanups
);
2310 this_cu
->v
.quick
->file_names
= qfn
;
2314 /* A helper for the "quick" functions which computes and caches the
2315 real path for a given file name from the line table. */
2318 dw2_get_real_path (struct objfile
*objfile
,
2319 struct quick_file_names
*qfn
, int index
)
2321 if (qfn
->real_names
== NULL
)
2322 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2323 qfn
->num_file_names
, sizeof (char *));
2325 if (qfn
->real_names
[index
] == NULL
)
2326 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2328 return qfn
->real_names
[index
];
2331 static struct symtab
*
2332 dw2_find_last_source_symtab (struct objfile
*objfile
)
2336 dw2_setup (objfile
);
2337 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2338 return dw2_instantiate_symtab (dw2_get_cu (index
));
2341 /* Traversal function for dw2_forget_cached_source_info. */
2344 dw2_free_cached_file_names (void **slot
, void *info
)
2346 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2348 if (file_data
->real_names
)
2352 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2354 xfree ((void*) file_data
->real_names
[i
]);
2355 file_data
->real_names
[i
] = NULL
;
2363 dw2_forget_cached_source_info (struct objfile
*objfile
)
2365 dw2_setup (objfile
);
2367 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2368 dw2_free_cached_file_names
, NULL
);
2371 /* Helper function for dw2_map_symtabs_matching_filename that expands
2372 the symtabs and calls the iterator. */
2375 dw2_map_expand_apply (struct objfile
*objfile
,
2376 struct dwarf2_per_cu_data
*per_cu
,
2378 const char *full_path
, const char *real_path
,
2379 int (*callback
) (struct symtab
*, void *),
2382 struct symtab
*last_made
= objfile
->symtabs
;
2384 /* Don't visit already-expanded CUs. */
2385 if (per_cu
->v
.quick
->symtab
)
2388 /* This may expand more than one symtab, and we want to iterate over
2390 dw2_instantiate_symtab (per_cu
);
2392 return iterate_over_some_symtabs (name
, full_path
, real_path
, callback
, data
,
2393 objfile
->symtabs
, last_made
);
2396 /* Implementation of the map_symtabs_matching_filename method. */
2399 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
2400 const char *full_path
, const char *real_path
,
2401 int (*callback
) (struct symtab
*, void *),
2405 const char *name_basename
= lbasename (name
);
2406 int name_len
= strlen (name
);
2407 int is_abs
= IS_ABSOLUTE_PATH (name
);
2409 dw2_setup (objfile
);
2411 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2412 + dwarf2_per_objfile
->n_type_units
); ++i
)
2415 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2416 struct quick_file_names
*file_data
;
2418 /* We only need to look at symtabs not already expanded. */
2419 if (per_cu
->v
.quick
->symtab
)
2422 file_data
= dw2_get_file_names (objfile
, per_cu
);
2423 if (file_data
== NULL
)
2426 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2428 const char *this_name
= file_data
->file_names
[j
];
2430 if (FILENAME_CMP (name
, this_name
) == 0
2431 || (!is_abs
&& compare_filenames_for_search (this_name
,
2434 if (dw2_map_expand_apply (objfile
, per_cu
,
2435 name
, full_path
, real_path
,
2440 /* Before we invoke realpath, which can get expensive when many
2441 files are involved, do a quick comparison of the basenames. */
2442 if (! basenames_may_differ
2443 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
2446 if (full_path
!= NULL
)
2448 const char *this_real_name
= dw2_get_real_path (objfile
,
2451 if (this_real_name
!= NULL
2452 && (FILENAME_CMP (full_path
, this_real_name
) == 0
2454 && compare_filenames_for_search (this_real_name
,
2457 if (dw2_map_expand_apply (objfile
, per_cu
,
2458 name
, full_path
, real_path
,
2464 if (real_path
!= NULL
)
2466 const char *this_real_name
= dw2_get_real_path (objfile
,
2469 if (this_real_name
!= NULL
2470 && (FILENAME_CMP (real_path
, this_real_name
) == 0
2472 && compare_filenames_for_search (this_real_name
,
2475 if (dw2_map_expand_apply (objfile
, per_cu
,
2476 name
, full_path
, real_path
,
2487 static struct symtab
*
2488 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2489 const char *name
, domain_enum domain
)
2491 /* We do all the work in the pre_expand_symtabs_matching hook
2496 /* A helper function that expands all symtabs that hold an object
2500 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2502 dw2_setup (objfile
);
2504 /* index_table is NULL if OBJF_READNOW. */
2505 if (dwarf2_per_objfile
->index_table
)
2509 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2512 offset_type i
, len
= MAYBE_SWAP (*vec
);
2513 for (i
= 0; i
< len
; ++i
)
2515 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2516 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2518 dw2_instantiate_symtab (per_cu
);
2525 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2526 enum block_enum block_kind
, const char *name
,
2529 dw2_do_expand_symtabs_matching (objfile
, name
);
2533 dw2_print_stats (struct objfile
*objfile
)
2537 dw2_setup (objfile
);
2539 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2540 + dwarf2_per_objfile
->n_type_units
); ++i
)
2542 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2544 if (!per_cu
->v
.quick
->symtab
)
2547 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2551 dw2_dump (struct objfile
*objfile
)
2553 /* Nothing worth printing. */
2557 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2558 struct section_offsets
*delta
)
2560 /* There's nothing to relocate here. */
2564 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2565 const char *func_name
)
2567 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2571 dw2_expand_all_symtabs (struct objfile
*objfile
)
2575 dw2_setup (objfile
);
2577 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2578 + dwarf2_per_objfile
->n_type_units
); ++i
)
2580 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2582 dw2_instantiate_symtab (per_cu
);
2587 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2588 const char *filename
)
2592 dw2_setup (objfile
);
2594 /* We don't need to consider type units here.
2595 This is only called for examining code, e.g. expand_line_sal.
2596 There can be an order of magnitude (or more) more type units
2597 than comp units, and we avoid them if we can. */
2599 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2602 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2603 struct quick_file_names
*file_data
;
2605 /* We only need to look at symtabs not already expanded. */
2606 if (per_cu
->v
.quick
->symtab
)
2609 file_data
= dw2_get_file_names (objfile
, per_cu
);
2610 if (file_data
== NULL
)
2613 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2615 const char *this_name
= file_data
->file_names
[j
];
2616 if (FILENAME_CMP (this_name
, filename
) == 0)
2618 dw2_instantiate_symtab (per_cu
);
2626 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2628 struct dwarf2_per_cu_data
*per_cu
;
2630 struct quick_file_names
*file_data
;
2632 dw2_setup (objfile
);
2634 /* index_table is NULL if OBJF_READNOW. */
2635 if (!dwarf2_per_objfile
->index_table
)
2639 ALL_OBJFILE_SYMTABS (objfile
, s
)
2642 struct blockvector
*bv
= BLOCKVECTOR (s
);
2643 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2644 struct symbol
*sym
= lookup_block_symbol (block
, name
, VAR_DOMAIN
);
2647 return sym
->symtab
->filename
;
2652 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2656 /* Note that this just looks at the very first one named NAME -- but
2657 actually we are looking for a function. find_main_filename
2658 should be rewritten so that it doesn't require a custom hook. It
2659 could just use the ordinary symbol tables. */
2660 /* vec[0] is the length, which must always be >0. */
2661 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[1]));
2663 file_data
= dw2_get_file_names (objfile
, per_cu
);
2664 if (file_data
== NULL
)
2667 return file_data
->file_names
[file_data
->num_file_names
- 1];
2671 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
2672 struct objfile
*objfile
, int global
,
2673 int (*callback
) (struct block
*,
2674 struct symbol
*, void *),
2675 void *data
, symbol_compare_ftype
*match
,
2676 symbol_compare_ftype
*ordered_compare
)
2678 /* Currently unimplemented; used for Ada. The function can be called if the
2679 current language is Ada for a non-Ada objfile using GNU index. As Ada
2680 does not look for non-Ada symbols this function should just return. */
2684 dw2_expand_symtabs_matching
2685 (struct objfile
*objfile
,
2686 int (*file_matcher
) (const char *, void *),
2687 int (*name_matcher
) (const char *, void *),
2688 enum search_domain kind
,
2693 struct mapped_index
*index
;
2695 dw2_setup (objfile
);
2697 /* index_table is NULL if OBJF_READNOW. */
2698 if (!dwarf2_per_objfile
->index_table
)
2700 index
= dwarf2_per_objfile
->index_table
;
2702 if (file_matcher
!= NULL
)
2703 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2704 + dwarf2_per_objfile
->n_type_units
); ++i
)
2707 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2708 struct quick_file_names
*file_data
;
2710 per_cu
->v
.quick
->mark
= 0;
2712 /* We only need to look at symtabs not already expanded. */
2713 if (per_cu
->v
.quick
->symtab
)
2716 file_data
= dw2_get_file_names (objfile
, per_cu
);
2717 if (file_data
== NULL
)
2720 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2722 if (file_matcher (file_data
->file_names
[j
], data
))
2724 per_cu
->v
.quick
->mark
= 1;
2730 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2732 offset_type idx
= 2 * iter
;
2734 offset_type
*vec
, vec_len
, vec_idx
;
2736 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2739 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
2741 if (! (*name_matcher
) (name
, data
))
2744 /* The name was matched, now expand corresponding CUs that were
2746 vec
= (offset_type
*) (index
->constant_pool
2747 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
2748 vec_len
= MAYBE_SWAP (vec
[0]);
2749 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2751 struct dwarf2_per_cu_data
*per_cu
;
2753 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[vec_idx
+ 1]));
2754 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
2755 dw2_instantiate_symtab (per_cu
);
2760 static struct symtab
*
2761 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
2762 struct minimal_symbol
*msymbol
,
2764 struct obj_section
*section
,
2767 struct dwarf2_per_cu_data
*data
;
2769 dw2_setup (objfile
);
2771 if (!objfile
->psymtabs_addrmap
)
2774 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
2778 if (warn_if_readin
&& data
->v
.quick
->symtab
)
2779 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2780 paddress (get_objfile_arch (objfile
), pc
));
2782 return dw2_instantiate_symtab (data
);
2786 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
2787 void *data
, int need_fullname
)
2791 dw2_setup (objfile
);
2793 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2794 + dwarf2_per_objfile
->n_type_units
); ++i
)
2797 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2798 struct quick_file_names
*file_data
;
2800 /* We only need to look at symtabs not already expanded. */
2801 if (per_cu
->v
.quick
->symtab
)
2804 file_data
= dw2_get_file_names (objfile
, per_cu
);
2805 if (file_data
== NULL
)
2808 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2810 const char *this_real_name
;
2813 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
2815 this_real_name
= NULL
;
2816 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
2822 dw2_has_symbols (struct objfile
*objfile
)
2827 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
2830 dw2_find_last_source_symtab
,
2831 dw2_forget_cached_source_info
,
2832 dw2_map_symtabs_matching_filename
,
2834 dw2_pre_expand_symtabs_matching
,
2838 dw2_expand_symtabs_for_function
,
2839 dw2_expand_all_symtabs
,
2840 dw2_expand_symtabs_with_filename
,
2841 dw2_find_symbol_file
,
2842 dw2_map_matching_symbols
,
2843 dw2_expand_symtabs_matching
,
2844 dw2_find_pc_sect_symtab
,
2845 dw2_map_symbol_filenames
2848 /* Initialize for reading DWARF for this objfile. Return 0 if this
2849 file will use psymtabs, or 1 if using the GNU index. */
2852 dwarf2_initialize_objfile (struct objfile
*objfile
)
2854 /* If we're about to read full symbols, don't bother with the
2855 indices. In this case we also don't care if some other debug
2856 format is making psymtabs, because they are all about to be
2858 if ((objfile
->flags
& OBJF_READNOW
))
2862 dwarf2_per_objfile
->using_index
= 1;
2863 create_all_comp_units (objfile
);
2864 create_debug_types_hash_table (objfile
);
2865 dwarf2_per_objfile
->quick_file_names_table
=
2866 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2868 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2869 + dwarf2_per_objfile
->n_type_units
); ++i
)
2871 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2873 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2874 struct dwarf2_per_cu_quick_data
);
2877 /* Return 1 so that gdb sees the "quick" functions. However,
2878 these functions will be no-ops because we will have expanded
2883 if (dwarf2_read_index (objfile
))
2891 /* Build a partial symbol table. */
2894 dwarf2_build_psymtabs (struct objfile
*objfile
)
2896 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2898 init_psymbol_list (objfile
, 1024);
2901 dwarf2_build_psymtabs_hard (objfile
);
2904 /* Return TRUE if OFFSET is within CU_HEADER. */
2907 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
2909 unsigned int bottom
= cu_header
->offset
;
2910 unsigned int top
= (cu_header
->offset
2912 + cu_header
->initial_length_size
);
2914 return (offset
>= bottom
&& offset
< top
);
2917 /* Read in the comp unit header information from the debug_info at info_ptr.
2918 NOTE: This leaves members offset, first_die_offset to be filled in
2922 read_comp_unit_head (struct comp_unit_head
*cu_header
,
2923 gdb_byte
*info_ptr
, bfd
*abfd
)
2926 unsigned int bytes_read
;
2928 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
2929 cu_header
->initial_length_size
= bytes_read
;
2930 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
2931 info_ptr
+= bytes_read
;
2932 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
2934 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
2936 info_ptr
+= bytes_read
;
2937 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
2939 signed_addr
= bfd_get_sign_extend_vma (abfd
);
2940 if (signed_addr
< 0)
2941 internal_error (__FILE__
, __LINE__
,
2942 _("read_comp_unit_head: dwarf from non elf file"));
2943 cu_header
->signed_addr_p
= signed_addr
;
2948 /* Subroutine of read_and_check_comp_unit_head and
2949 read_and_check_type_unit_head to simplify them.
2950 Perform various error checking on the header. */
2953 error_check_comp_unit_head (struct comp_unit_head
*header
,
2954 struct dwarf2_section_info
*section
)
2956 bfd
*abfd
= section
->asection
->owner
;
2957 const char *filename
= bfd_get_filename (abfd
);
2959 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
2960 error (_("Dwarf Error: wrong version in compilation unit header "
2961 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
2964 if (header
->abbrev_offset
2965 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
2966 &dwarf2_per_objfile
->abbrev
))
2967 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
2968 "(offset 0x%lx + 6) [in module %s]"),
2969 (long) header
->abbrev_offset
, (long) header
->offset
,
2972 /* Cast to unsigned long to use 64-bit arithmetic when possible to
2973 avoid potential 32-bit overflow. */
2974 if (((unsigned long) header
->offset
2975 + header
->length
+ header
->initial_length_size
)
2977 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
2978 "(offset 0x%lx + 0) [in module %s]"),
2979 (long) header
->length
, (long) header
->offset
,
2983 /* Read in a CU/TU header and perform some basic error checking.
2984 The contents of the header are stored in HEADER.
2985 The result is a pointer to the start of the first DIE. */
2988 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
2989 struct dwarf2_section_info
*section
,
2991 int is_debug_types_section
)
2993 gdb_byte
*beg_of_comp_unit
= info_ptr
;
2994 bfd
*abfd
= section
->asection
->owner
;
2996 header
->offset
= beg_of_comp_unit
- section
->buffer
;
2998 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3000 /* If we're reading a type unit, skip over the signature and
3001 type_offset fields. */
3002 if (is_debug_types_section
)
3003 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
3005 header
->first_die_offset
= info_ptr
- beg_of_comp_unit
;
3007 error_check_comp_unit_head (header
, section
);
3012 /* Read in the types comp unit header information from .debug_types entry at
3013 types_ptr. The result is a pointer to one past the end of the header. */
3016 read_and_check_type_unit_head (struct comp_unit_head
*header
,
3017 struct dwarf2_section_info
*section
,
3019 ULONGEST
*signature
, unsigned int *type_offset
)
3021 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3022 bfd
*abfd
= section
->asection
->owner
;
3024 header
->offset
= beg_of_comp_unit
- section
->buffer
;
3026 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3028 /* If we're reading a type unit, skip over the signature and
3029 type_offset fields. */
3030 if (signature
!= NULL
)
3031 *signature
= read_8_bytes (abfd
, info_ptr
);
3033 if (type_offset
!= NULL
)
3034 *type_offset
= read_offset_1 (abfd
, info_ptr
, header
->offset_size
);
3035 info_ptr
+= header
->offset_size
;
3037 header
->first_die_offset
= info_ptr
- beg_of_comp_unit
;
3039 error_check_comp_unit_head (header
, section
);
3044 /* Allocate a new partial symtab for file named NAME and mark this new
3045 partial symtab as being an include of PST. */
3048 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
3049 struct objfile
*objfile
)
3051 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
3053 subpst
->section_offsets
= pst
->section_offsets
;
3054 subpst
->textlow
= 0;
3055 subpst
->texthigh
= 0;
3057 subpst
->dependencies
= (struct partial_symtab
**)
3058 obstack_alloc (&objfile
->objfile_obstack
,
3059 sizeof (struct partial_symtab
*));
3060 subpst
->dependencies
[0] = pst
;
3061 subpst
->number_of_dependencies
= 1;
3063 subpst
->globals_offset
= 0;
3064 subpst
->n_global_syms
= 0;
3065 subpst
->statics_offset
= 0;
3066 subpst
->n_static_syms
= 0;
3067 subpst
->symtab
= NULL
;
3068 subpst
->read_symtab
= pst
->read_symtab
;
3071 /* No private part is necessary for include psymtabs. This property
3072 can be used to differentiate between such include psymtabs and
3073 the regular ones. */
3074 subpst
->read_symtab_private
= NULL
;
3077 /* Read the Line Number Program data and extract the list of files
3078 included by the source file represented by PST. Build an include
3079 partial symtab for each of these included files. */
3082 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
3083 struct die_info
*die
,
3084 struct partial_symtab
*pst
)
3086 struct objfile
*objfile
= cu
->objfile
;
3087 bfd
*abfd
= objfile
->obfd
;
3088 struct line_header
*lh
= NULL
;
3089 struct attribute
*attr
;
3091 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3094 unsigned int line_offset
= DW_UNSND (attr
);
3096 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
3099 return; /* No linetable, so no includes. */
3101 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3102 dwarf_decode_lines (lh
, pst
->dirname
, cu
, pst
, 1);
3104 free_line_header (lh
);
3108 hash_type_signature (const void *item
)
3110 const struct signatured_type
*type_sig
= item
;
3112 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3113 return type_sig
->signature
;
3117 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
3119 const struct signatured_type
*lhs
= item_lhs
;
3120 const struct signatured_type
*rhs
= item_rhs
;
3122 return lhs
->signature
== rhs
->signature
;
3125 /* Allocate a hash table for signatured types. */
3128 allocate_signatured_type_table (struct objfile
*objfile
)
3130 return htab_create_alloc_ex (41,
3131 hash_type_signature
,
3134 &objfile
->objfile_obstack
,
3135 hashtab_obstack_allocate
,
3136 dummy_obstack_deallocate
);
3139 /* A helper function to add a signatured type CU to a table. */
3142 add_signatured_type_cu_to_table (void **slot
, void *datum
)
3144 struct signatured_type
*sigt
= *slot
;
3145 struct dwarf2_per_cu_data
***datap
= datum
;
3147 **datap
= &sigt
->per_cu
;
3153 /* Create the hash table of all entries in the .debug_types section(s).
3154 The result is zero if there is an error (e.g. missing .debug_types section),
3155 otherwise non-zero. */
3158 create_debug_types_hash_table (struct objfile
*objfile
)
3160 htab_t types_htab
= NULL
;
3161 struct dwarf2_per_cu_data
**iter
;
3163 struct dwarf2_section_info
*section
;
3165 if (VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
))
3167 dwarf2_per_objfile
->signatured_types
= NULL
;
3172 VEC_iterate (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
3176 gdb_byte
*info_ptr
, *end_ptr
;
3178 dwarf2_read_section (objfile
, section
);
3179 info_ptr
= section
->buffer
;
3181 if (info_ptr
== NULL
)
3184 if (types_htab
== NULL
)
3185 types_htab
= allocate_signatured_type_table (objfile
);
3187 if (dwarf2_die_debug
)
3188 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
3190 end_ptr
= info_ptr
+ section
->size
;
3191 while (info_ptr
< end_ptr
)
3193 unsigned int offset
;
3194 unsigned int type_offset
;
3196 struct signatured_type
*type_sig
;
3198 gdb_byte
*ptr
= info_ptr
;
3199 struct comp_unit_head header
;
3201 offset
= ptr
- section
->buffer
;
3203 /* We need to read the type's signature in order to build the hash
3204 table, but we don't need anything else just yet. */
3206 ptr
= read_and_check_type_unit_head (&header
, section
, ptr
,
3207 &signature
, &type_offset
);
3209 /* Skip dummy type units. */
3210 if (ptr
>= end_ptr
|| peek_abbrev_code (objfile
->obfd
, ptr
) == 0)
3212 info_ptr
= info_ptr
+ header
.initial_length_size
+ header
.length
;
3216 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
3217 memset (type_sig
, 0, sizeof (*type_sig
));
3218 type_sig
->signature
= signature
;
3219 type_sig
->type_offset
= type_offset
;
3220 type_sig
->per_cu
.objfile
= objfile
;
3221 type_sig
->per_cu
.debug_types_section
= section
;
3222 type_sig
->per_cu
.offset
= offset
;
3224 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
3225 gdb_assert (slot
!= NULL
);
3228 const struct signatured_type
*dup_sig
= *slot
;
3230 complaint (&symfile_complaints
,
3231 _("debug type entry at offset 0x%x is duplicate to the "
3232 "entry at offset 0x%x, signature 0x%s"),
3233 offset
, dup_sig
->per_cu
.offset
,
3234 phex (signature
, sizeof (signature
)));
3235 gdb_assert (signature
== dup_sig
->signature
);
3239 if (dwarf2_die_debug
)
3240 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3241 offset
, phex (signature
, sizeof (signature
)));
3243 info_ptr
= info_ptr
+ header
.initial_length_size
+ header
.length
;
3247 dwarf2_per_objfile
->signatured_types
= types_htab
;
3249 dwarf2_per_objfile
->n_type_units
= htab_elements (types_htab
);
3250 dwarf2_per_objfile
->all_type_units
3251 = obstack_alloc (&objfile
->objfile_obstack
,
3252 dwarf2_per_objfile
->n_type_units
3253 * sizeof (struct dwarf2_per_cu_data
*));
3254 iter
= &dwarf2_per_objfile
->all_type_units
[0];
3255 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
3256 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
3257 == dwarf2_per_objfile
->n_type_units
);
3262 /* Lookup a signature based type.
3263 Returns NULL if SIG is not present in the table. */
3265 static struct signatured_type
*
3266 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
3268 struct signatured_type find_entry
, *entry
;
3270 if (dwarf2_per_objfile
->signatured_types
== NULL
)
3272 complaint (&symfile_complaints
,
3273 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3277 find_entry
.signature
= sig
;
3278 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
3282 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3285 init_cu_die_reader (struct die_reader_specs
*reader
,
3286 struct dwarf2_cu
*cu
)
3288 reader
->abfd
= cu
->objfile
->obfd
;
3290 if (cu
->per_cu
->debug_types_section
)
3292 gdb_assert (cu
->per_cu
->debug_types_section
->readin
);
3293 reader
->buffer
= cu
->per_cu
->debug_types_section
->buffer
;
3297 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3298 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
3302 /* Find the base address of the compilation unit for range lists and
3303 location lists. It will normally be specified by DW_AT_low_pc.
3304 In DWARF-3 draft 4, the base address could be overridden by
3305 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3306 compilation units with discontinuous ranges. */
3309 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3311 struct attribute
*attr
;
3314 cu
->base_address
= 0;
3316 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3319 cu
->base_address
= DW_ADDR (attr
);
3324 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3327 cu
->base_address
= DW_ADDR (attr
);
3333 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
3334 to combine the common parts.
3335 Process compilation unit THIS_CU for a psymtab.
3336 SECTION is the section the CU/TU comes from,
3337 either .debug_info or .debug_types. */
3340 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
3341 struct dwarf2_section_info
*section
,
3342 int is_debug_types_section
)
3344 struct objfile
*objfile
= this_cu
->objfile
;
3345 bfd
*abfd
= objfile
->obfd
;
3346 gdb_byte
*buffer
= section
->buffer
;
3347 gdb_byte
*info_ptr
= buffer
+ this_cu
->offset
;
3348 unsigned int buffer_size
= section
->size
;
3349 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3350 struct die_info
*comp_unit_die
;
3351 struct partial_symtab
*pst
;
3353 struct cleanup
*back_to_inner
;
3354 struct dwarf2_cu cu
;
3355 int has_children
, has_pc_info
;
3356 struct attribute
*attr
;
3357 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
3358 struct die_reader_specs reader_specs
;
3359 const char *filename
;
3361 /* If this compilation unit was already read in, free the
3362 cached copy in order to read it in again. This is
3363 necessary because we skipped some symbols when we first
3364 read in the compilation unit (see load_partial_dies).
3365 This problem could be avoided, but the benefit is
3367 if (this_cu
->cu
!= NULL
)
3368 free_one_cached_comp_unit (this_cu
->cu
);
3370 /* Note that this is a pointer to our stack frame, being
3371 added to a global data structure. It will be cleaned up
3372 in free_stack_comp_unit when we finish with this
3373 compilation unit. */
3374 init_one_comp_unit (&cu
, this_cu
);
3375 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
3377 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
, info_ptr
,
3378 is_debug_types_section
);
3380 /* Skip dummy compilation units. */
3381 if (info_ptr
>= buffer
+ buffer_size
3382 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3384 do_cleanups (back_to_inner
);
3388 cu
.list_in_scope
= &file_symbols
;
3390 /* Read the abbrevs for this compilation unit into a table. */
3391 dwarf2_read_abbrevs (&cu
);
3392 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
3394 /* Read the compilation unit die. */
3395 init_cu_die_reader (&reader_specs
, &cu
);
3396 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3399 if (is_debug_types_section
)
3401 /* LENGTH has not been set yet for type units. */
3402 gdb_assert (this_cu
->offset
== cu
.header
.offset
);
3403 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
3405 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3407 do_cleanups (back_to_inner
);
3411 prepare_one_comp_unit (&cu
, comp_unit_die
);
3413 /* Allocate a new partial symbol table structure. */
3414 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
3415 if (attr
== NULL
|| !DW_STRING (attr
))
3418 filename
= DW_STRING (attr
);
3419 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
3421 /* TEXTLOW and TEXTHIGH are set below. */
3423 objfile
->global_psymbols
.next
,
3424 objfile
->static_psymbols
.next
);
3425 pst
->psymtabs_addrmap_supported
= 1;
3427 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
3429 pst
->dirname
= DW_STRING (attr
);
3431 pst
->read_symtab_private
= this_cu
;
3433 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3435 /* Store the function that reads in the rest of the symbol table. */
3436 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
3438 this_cu
->v
.psymtab
= pst
;
3440 dwarf2_find_base_address (comp_unit_die
, &cu
);
3442 /* Possibly set the default values of LOWPC and HIGHPC from
3444 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
3445 &best_highpc
, &cu
, pst
);
3446 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
3447 /* Store the contiguous range if it is not empty; it can be empty for
3448 CUs with no code. */
3449 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3450 best_lowpc
+ baseaddr
,
3451 best_highpc
+ baseaddr
- 1, pst
);
3453 /* Check if comp unit has_children.
3454 If so, read the rest of the partial symbols from this comp unit.
3455 If not, there's no more debug_info for this comp unit. */
3458 struct partial_die_info
*first_die
;
3459 CORE_ADDR lowpc
, highpc
;
3461 lowpc
= ((CORE_ADDR
) -1);
3462 highpc
= ((CORE_ADDR
) 0);
3464 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
3466 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
3467 ! has_pc_info
, &cu
);
3469 /* If we didn't find a lowpc, set it to highpc to avoid
3470 complaints from `maint check'. */
3471 if (lowpc
== ((CORE_ADDR
) -1))
3474 /* If the compilation unit didn't have an explicit address range,
3475 then use the information extracted from its child dies. */
3479 best_highpc
= highpc
;
3482 pst
->textlow
= best_lowpc
+ baseaddr
;
3483 pst
->texthigh
= best_highpc
+ baseaddr
;
3485 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
3486 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
3487 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
3488 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
3489 sort_pst_symbols (pst
);
3491 if (is_debug_types_section
)
3493 /* It's not clear we want to do anything with stmt lists here.
3494 Waiting to see what gcc ultimately does. */
3498 /* Get the list of files included in the current compilation unit,
3499 and build a psymtab for each of them. */
3500 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
3503 do_cleanups (back_to_inner
);
3506 /* Traversal function for htab_traverse_noresize.
3507 Process one .debug_types comp-unit. */
3510 process_type_comp_unit (void **slot
, void *info
)
3512 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
3513 struct dwarf2_per_cu_data
*this_cu
;
3515 gdb_assert (info
== NULL
);
3516 this_cu
= &entry
->per_cu
;
3518 gdb_assert (this_cu
->debug_types_section
->readin
);
3519 process_psymtab_comp_unit (this_cu
, this_cu
->debug_types_section
, 1);
3524 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3525 Build partial symbol tables for the .debug_types comp-units. */
3528 build_type_psymtabs (struct objfile
*objfile
)
3530 if (! create_debug_types_hash_table (objfile
))
3533 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
3534 process_type_comp_unit
, NULL
);
3537 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3540 psymtabs_addrmap_cleanup (void *o
)
3542 struct objfile
*objfile
= o
;
3544 objfile
->psymtabs_addrmap
= NULL
;
3547 /* Build the partial symbol table by doing a quick pass through the
3548 .debug_info and .debug_abbrev sections. */
3551 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
3553 struct cleanup
*back_to
, *addrmap_cleanup
;
3554 struct obstack temp_obstack
;
3557 dwarf2_per_objfile
->reading_partial_symbols
= 1;
3559 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3561 /* Any cached compilation units will be linked by the per-objfile
3562 read_in_chain. Make sure to free them when we're done. */
3563 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
3565 build_type_psymtabs (objfile
);
3567 create_all_comp_units (objfile
);
3569 /* Create a temporary address map on a temporary obstack. We later
3570 copy this to the final obstack. */
3571 obstack_init (&temp_obstack
);
3572 make_cleanup_obstack_free (&temp_obstack
);
3573 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
3574 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
3576 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3578 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3580 process_psymtab_comp_unit (per_cu
, &dwarf2_per_objfile
->info
, 0);
3583 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
3584 &objfile
->objfile_obstack
);
3585 discard_cleanups (addrmap_cleanup
);
3587 do_cleanups (back_to
);
3590 /* Load the partial DIEs for a secondary CU into memory. */
3593 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
3595 struct objfile
*objfile
= this_cu
->objfile
;
3596 bfd
*abfd
= objfile
->obfd
;
3598 struct die_info
*comp_unit_die
;
3599 struct dwarf2_cu
*cu
;
3600 struct cleanup
*free_abbrevs_cleanup
, *free_cu_cleanup
= NULL
;
3602 struct die_reader_specs reader_specs
;
3604 struct dwarf2_section_info
*section
= &dwarf2_per_objfile
->info
;
3606 gdb_assert (! this_cu
->debug_types_section
);
3608 gdb_assert (section
->readin
);
3609 info_ptr
= section
->buffer
+ this_cu
->offset
;
3611 if (this_cu
->cu
== NULL
)
3613 cu
= xmalloc (sizeof (*cu
));
3614 init_one_comp_unit (cu
, this_cu
);
3618 /* If an error occurs while loading, release our storage. */
3619 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
3621 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
, info_ptr
,
3624 /* Skip dummy compilation units. */
3625 if (info_ptr
>= (section
->buffer
+ section
->size
)
3626 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3628 do_cleanups (free_cu_cleanup
);
3632 /* Link this CU into read_in_chain. */
3633 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3634 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3639 info_ptr
+= cu
->header
.first_die_offset
;
3642 /* Read the abbrevs for this compilation unit into a table. */
3643 gdb_assert (cu
->dwarf2_abbrevs
== NULL
);
3644 dwarf2_read_abbrevs (cu
);
3645 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3647 /* Read the compilation unit die. */
3648 init_cu_die_reader (&reader_specs
, cu
);
3649 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3652 prepare_one_comp_unit (cu
, comp_unit_die
);
3654 /* Check if comp unit has_children.
3655 If so, read the rest of the partial symbols from this comp unit.
3656 If not, there's no more debug_info for this comp unit. */
3658 load_partial_dies (abfd
, section
->buffer
, info_ptr
, 0, cu
);
3660 do_cleanups (free_abbrevs_cleanup
);
3664 /* We've successfully allocated this compilation unit. Let our
3665 caller clean it up when finished with it. */
3666 discard_cleanups (free_cu_cleanup
);
3670 /* Create a list of all compilation units in OBJFILE.
3671 This is only done for -readnow and building partial symtabs. */
3674 create_all_comp_units (struct objfile
*objfile
)
3678 struct dwarf2_per_cu_data
**all_comp_units
;
3681 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3682 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3686 all_comp_units
= xmalloc (n_allocated
3687 * sizeof (struct dwarf2_per_cu_data
*));
3689 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
3690 + dwarf2_per_objfile
->info
.size
)
3692 unsigned int length
, initial_length_size
;
3693 struct dwarf2_per_cu_data
*this_cu
;
3694 unsigned int offset
;
3696 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
3698 /* Read just enough information to find out where the next
3699 compilation unit is. */
3700 length
= read_initial_length (objfile
->obfd
, info_ptr
,
3701 &initial_length_size
);
3703 /* Save the compilation unit for later lookup. */
3704 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
3705 sizeof (struct dwarf2_per_cu_data
));
3706 memset (this_cu
, 0, sizeof (*this_cu
));
3707 this_cu
->offset
= offset
;
3708 this_cu
->length
= length
+ initial_length_size
;
3709 this_cu
->objfile
= objfile
;
3711 if (n_comp_units
== n_allocated
)
3714 all_comp_units
= xrealloc (all_comp_units
,
3716 * sizeof (struct dwarf2_per_cu_data
*));
3718 all_comp_units
[n_comp_units
++] = this_cu
;
3720 info_ptr
= info_ptr
+ this_cu
->length
;
3723 dwarf2_per_objfile
->all_comp_units
3724 = obstack_alloc (&objfile
->objfile_obstack
,
3725 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3726 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
3727 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3728 xfree (all_comp_units
);
3729 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
3732 /* Process all loaded DIEs for compilation unit CU, starting at
3733 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3734 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3735 DW_AT_ranges). If NEED_PC is set, then this function will set
3736 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3737 and record the covered ranges in the addrmap. */
3740 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
3741 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3743 struct partial_die_info
*pdi
;
3745 /* Now, march along the PDI's, descending into ones which have
3746 interesting children but skipping the children of the other ones,
3747 until we reach the end of the compilation unit. */
3753 fixup_partial_die (pdi
, cu
);
3755 /* Anonymous namespaces or modules have no name but have interesting
3756 children, so we need to look at them. Ditto for anonymous
3759 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
3760 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
3764 case DW_TAG_subprogram
:
3765 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3767 case DW_TAG_constant
:
3768 case DW_TAG_variable
:
3769 case DW_TAG_typedef
:
3770 case DW_TAG_union_type
:
3771 if (!pdi
->is_declaration
)
3773 add_partial_symbol (pdi
, cu
);
3776 case DW_TAG_class_type
:
3777 case DW_TAG_interface_type
:
3778 case DW_TAG_structure_type
:
3779 if (!pdi
->is_declaration
)
3781 add_partial_symbol (pdi
, cu
);
3784 case DW_TAG_enumeration_type
:
3785 if (!pdi
->is_declaration
)
3786 add_partial_enumeration (pdi
, cu
);
3788 case DW_TAG_base_type
:
3789 case DW_TAG_subrange_type
:
3790 /* File scope base type definitions are added to the partial
3792 add_partial_symbol (pdi
, cu
);
3794 case DW_TAG_namespace
:
3795 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
3798 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
3805 /* If the die has a sibling, skip to the sibling. */
3807 pdi
= pdi
->die_sibling
;
3811 /* Functions used to compute the fully scoped name of a partial DIE.
3813 Normally, this is simple. For C++, the parent DIE's fully scoped
3814 name is concatenated with "::" and the partial DIE's name. For
3815 Java, the same thing occurs except that "." is used instead of "::".
3816 Enumerators are an exception; they use the scope of their parent
3817 enumeration type, i.e. the name of the enumeration type is not
3818 prepended to the enumerator.
3820 There are two complexities. One is DW_AT_specification; in this
3821 case "parent" means the parent of the target of the specification,
3822 instead of the direct parent of the DIE. The other is compilers
3823 which do not emit DW_TAG_namespace; in this case we try to guess
3824 the fully qualified name of structure types from their members'
3825 linkage names. This must be done using the DIE's children rather
3826 than the children of any DW_AT_specification target. We only need
3827 to do this for structures at the top level, i.e. if the target of
3828 any DW_AT_specification (if any; otherwise the DIE itself) does not
3831 /* Compute the scope prefix associated with PDI's parent, in
3832 compilation unit CU. The result will be allocated on CU's
3833 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3834 field. NULL is returned if no prefix is necessary. */
3836 partial_die_parent_scope (struct partial_die_info
*pdi
,
3837 struct dwarf2_cu
*cu
)
3839 char *grandparent_scope
;
3840 struct partial_die_info
*parent
, *real_pdi
;
3842 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3843 then this means the parent of the specification DIE. */
3846 while (real_pdi
->has_specification
)
3847 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3849 parent
= real_pdi
->die_parent
;
3853 if (parent
->scope_set
)
3854 return parent
->scope
;
3856 fixup_partial_die (parent
, cu
);
3858 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
3860 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3861 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3862 Work around this problem here. */
3863 if (cu
->language
== language_cplus
3864 && parent
->tag
== DW_TAG_namespace
3865 && strcmp (parent
->name
, "::") == 0
3866 && grandparent_scope
== NULL
)
3868 parent
->scope
= NULL
;
3869 parent
->scope_set
= 1;
3873 if (pdi
->tag
== DW_TAG_enumerator
)
3874 /* Enumerators should not get the name of the enumeration as a prefix. */
3875 parent
->scope
= grandparent_scope
;
3876 else if (parent
->tag
== DW_TAG_namespace
3877 || parent
->tag
== DW_TAG_module
3878 || parent
->tag
== DW_TAG_structure_type
3879 || parent
->tag
== DW_TAG_class_type
3880 || parent
->tag
== DW_TAG_interface_type
3881 || parent
->tag
== DW_TAG_union_type
3882 || parent
->tag
== DW_TAG_enumeration_type
)
3884 if (grandparent_scope
== NULL
)
3885 parent
->scope
= parent
->name
;
3887 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
3889 parent
->name
, 0, cu
);
3893 /* FIXME drow/2004-04-01: What should we be doing with
3894 function-local names? For partial symbols, we should probably be
3896 complaint (&symfile_complaints
,
3897 _("unhandled containing DIE tag %d for DIE at %d"),
3898 parent
->tag
, pdi
->offset
);
3899 parent
->scope
= grandparent_scope
;
3902 parent
->scope_set
= 1;
3903 return parent
->scope
;
3906 /* Return the fully scoped name associated with PDI, from compilation unit
3907 CU. The result will be allocated with malloc. */
3909 partial_die_full_name (struct partial_die_info
*pdi
,
3910 struct dwarf2_cu
*cu
)
3914 /* If this is a template instantiation, we can not work out the
3915 template arguments from partial DIEs. So, unfortunately, we have
3916 to go through the full DIEs. At least any work we do building
3917 types here will be reused if full symbols are loaded later. */
3918 if (pdi
->has_template_arguments
)
3920 fixup_partial_die (pdi
, cu
);
3922 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
3924 struct die_info
*die
;
3925 struct attribute attr
;
3926 struct dwarf2_cu
*ref_cu
= cu
;
3929 attr
.form
= DW_FORM_ref_addr
;
3930 attr
.u
.addr
= pdi
->offset
;
3931 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
3933 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
3937 parent_scope
= partial_die_parent_scope (pdi
, cu
);
3938 if (parent_scope
== NULL
)
3941 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
3945 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
3947 struct objfile
*objfile
= cu
->objfile
;
3949 char *actual_name
= NULL
;
3951 int built_actual_name
= 0;
3953 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3955 actual_name
= partial_die_full_name (pdi
, cu
);
3957 built_actual_name
= 1;
3959 if (actual_name
== NULL
)
3960 actual_name
= pdi
->name
;
3964 case DW_TAG_subprogram
:
3965 if (pdi
->is_external
|| cu
->language
== language_ada
)
3967 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
3968 of the global scope. But in Ada, we want to be able to access
3969 nested procedures globally. So all Ada subprograms are stored
3970 in the global scope. */
3971 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3972 mst_text, objfile); */
3973 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3975 VAR_DOMAIN
, LOC_BLOCK
,
3976 &objfile
->global_psymbols
,
3977 0, pdi
->lowpc
+ baseaddr
,
3978 cu
->language
, objfile
);
3982 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3983 mst_file_text, objfile); */
3984 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3986 VAR_DOMAIN
, LOC_BLOCK
,
3987 &objfile
->static_psymbols
,
3988 0, pdi
->lowpc
+ baseaddr
,
3989 cu
->language
, objfile
);
3992 case DW_TAG_constant
:
3994 struct psymbol_allocation_list
*list
;
3996 if (pdi
->is_external
)
3997 list
= &objfile
->global_psymbols
;
3999 list
= &objfile
->static_psymbols
;
4000 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4001 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
4002 list
, 0, 0, cu
->language
, objfile
);
4005 case DW_TAG_variable
:
4007 addr
= decode_locdesc (pdi
->locdesc
, cu
);
4011 && !dwarf2_per_objfile
->has_section_at_zero
)
4013 /* A global or static variable may also have been stripped
4014 out by the linker if unused, in which case its address
4015 will be nullified; do not add such variables into partial
4016 symbol table then. */
4018 else if (pdi
->is_external
)
4021 Don't enter into the minimal symbol tables as there is
4022 a minimal symbol table entry from the ELF symbols already.
4023 Enter into partial symbol table if it has a location
4024 descriptor or a type.
4025 If the location descriptor is missing, new_symbol will create
4026 a LOC_UNRESOLVED symbol, the address of the variable will then
4027 be determined from the minimal symbol table whenever the variable
4029 The address for the partial symbol table entry is not
4030 used by GDB, but it comes in handy for debugging partial symbol
4033 if (pdi
->locdesc
|| pdi
->has_type
)
4034 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4036 VAR_DOMAIN
, LOC_STATIC
,
4037 &objfile
->global_psymbols
,
4039 cu
->language
, objfile
);
4043 /* Static Variable. Skip symbols without location descriptors. */
4044 if (pdi
->locdesc
== NULL
)
4046 if (built_actual_name
)
4047 xfree (actual_name
);
4050 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
4051 mst_file_data, objfile); */
4052 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4054 VAR_DOMAIN
, LOC_STATIC
,
4055 &objfile
->static_psymbols
,
4057 cu
->language
, objfile
);
4060 case DW_TAG_typedef
:
4061 case DW_TAG_base_type
:
4062 case DW_TAG_subrange_type
:
4063 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4065 VAR_DOMAIN
, LOC_TYPEDEF
,
4066 &objfile
->static_psymbols
,
4067 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4069 case DW_TAG_namespace
:
4070 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4072 VAR_DOMAIN
, LOC_TYPEDEF
,
4073 &objfile
->global_psymbols
,
4074 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4076 case DW_TAG_class_type
:
4077 case DW_TAG_interface_type
:
4078 case DW_TAG_structure_type
:
4079 case DW_TAG_union_type
:
4080 case DW_TAG_enumeration_type
:
4081 /* Skip external references. The DWARF standard says in the section
4082 about "Structure, Union, and Class Type Entries": "An incomplete
4083 structure, union or class type is represented by a structure,
4084 union or class entry that does not have a byte size attribute
4085 and that has a DW_AT_declaration attribute." */
4086 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
4088 if (built_actual_name
)
4089 xfree (actual_name
);
4093 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
4094 static vs. global. */
4095 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4097 STRUCT_DOMAIN
, LOC_TYPEDEF
,
4098 (cu
->language
== language_cplus
4099 || cu
->language
== language_java
)
4100 ? &objfile
->global_psymbols
4101 : &objfile
->static_psymbols
,
4102 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4105 case DW_TAG_enumerator
:
4106 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4108 VAR_DOMAIN
, LOC_CONST
,
4109 (cu
->language
== language_cplus
4110 || cu
->language
== language_java
)
4111 ? &objfile
->global_psymbols
4112 : &objfile
->static_psymbols
,
4113 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4119 if (built_actual_name
)
4120 xfree (actual_name
);
4123 /* Read a partial die corresponding to a namespace; also, add a symbol
4124 corresponding to that namespace to the symbol table. NAMESPACE is
4125 the name of the enclosing namespace. */
4128 add_partial_namespace (struct partial_die_info
*pdi
,
4129 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4130 int need_pc
, struct dwarf2_cu
*cu
)
4132 /* Add a symbol for the namespace. */
4134 add_partial_symbol (pdi
, cu
);
4136 /* Now scan partial symbols in that namespace. */
4138 if (pdi
->has_children
)
4139 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4142 /* Read a partial die corresponding to a Fortran module. */
4145 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
4146 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4148 /* Now scan partial symbols in that module. */
4150 if (pdi
->has_children
)
4151 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4154 /* Read a partial die corresponding to a subprogram and create a partial
4155 symbol for that subprogram. When the CU language allows it, this
4156 routine also defines a partial symbol for each nested subprogram
4157 that this subprogram contains.
4159 DIE my also be a lexical block, in which case we simply search
4160 recursively for suprograms defined inside that lexical block.
4161 Again, this is only performed when the CU language allows this
4162 type of definitions. */
4165 add_partial_subprogram (struct partial_die_info
*pdi
,
4166 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4167 int need_pc
, struct dwarf2_cu
*cu
)
4169 if (pdi
->tag
== DW_TAG_subprogram
)
4171 if (pdi
->has_pc_info
)
4173 if (pdi
->lowpc
< *lowpc
)
4174 *lowpc
= pdi
->lowpc
;
4175 if (pdi
->highpc
> *highpc
)
4176 *highpc
= pdi
->highpc
;
4180 struct objfile
*objfile
= cu
->objfile
;
4182 baseaddr
= ANOFFSET (objfile
->section_offsets
,
4183 SECT_OFF_TEXT (objfile
));
4184 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4185 pdi
->lowpc
+ baseaddr
,
4186 pdi
->highpc
- 1 + baseaddr
,
4187 cu
->per_cu
->v
.psymtab
);
4189 if (!pdi
->is_declaration
)
4190 /* Ignore subprogram DIEs that do not have a name, they are
4191 illegal. Do not emit a complaint at this point, we will
4192 do so when we convert this psymtab into a symtab. */
4194 add_partial_symbol (pdi
, cu
);
4198 if (! pdi
->has_children
)
4201 if (cu
->language
== language_ada
)
4203 pdi
= pdi
->die_child
;
4206 fixup_partial_die (pdi
, cu
);
4207 if (pdi
->tag
== DW_TAG_subprogram
4208 || pdi
->tag
== DW_TAG_lexical_block
)
4209 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4210 pdi
= pdi
->die_sibling
;
4215 /* Read a partial die corresponding to an enumeration type. */
4218 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
4219 struct dwarf2_cu
*cu
)
4221 struct partial_die_info
*pdi
;
4223 if (enum_pdi
->name
!= NULL
)
4224 add_partial_symbol (enum_pdi
, cu
);
4226 pdi
= enum_pdi
->die_child
;
4229 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
4230 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
4232 add_partial_symbol (pdi
, cu
);
4233 pdi
= pdi
->die_sibling
;
4237 /* Return the initial uleb128 in the die at INFO_PTR. */
4240 peek_abbrev_code (bfd
*abfd
, gdb_byte
*info_ptr
)
4242 unsigned int bytes_read
;
4244 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4247 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4248 Return the corresponding abbrev, or NULL if the number is zero (indicating
4249 an empty DIE). In either case *BYTES_READ will be set to the length of
4250 the initial number. */
4252 static struct abbrev_info
*
4253 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
4254 struct dwarf2_cu
*cu
)
4256 bfd
*abfd
= cu
->objfile
->obfd
;
4257 unsigned int abbrev_number
;
4258 struct abbrev_info
*abbrev
;
4260 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
4262 if (abbrev_number
== 0)
4265 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4268 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4269 abbrev_number
, bfd_get_filename (abfd
));
4275 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4276 Returns a pointer to the end of a series of DIEs, terminated by an empty
4277 DIE. Any children of the skipped DIEs will also be skipped. */
4280 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
4282 struct abbrev_info
*abbrev
;
4283 unsigned int bytes_read
;
4287 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
4289 return info_ptr
+ bytes_read
;
4291 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
4295 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4296 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4297 abbrev corresponding to that skipped uleb128 should be passed in
4298 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4302 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4303 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
4305 unsigned int bytes_read
;
4306 struct attribute attr
;
4307 bfd
*abfd
= cu
->objfile
->obfd
;
4308 unsigned int form
, i
;
4310 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
4312 /* The only abbrev we care about is DW_AT_sibling. */
4313 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
4315 read_attribute (&attr
, &abbrev
->attrs
[i
],
4316 abfd
, info_ptr
, cu
);
4317 if (attr
.form
== DW_FORM_ref_addr
)
4318 complaint (&symfile_complaints
,
4319 _("ignoring absolute DW_AT_sibling"));
4321 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
4324 /* If it isn't DW_AT_sibling, skip this attribute. */
4325 form
= abbrev
->attrs
[i
].form
;
4329 case DW_FORM_ref_addr
:
4330 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4331 and later it is offset sized. */
4332 if (cu
->header
.version
== 2)
4333 info_ptr
+= cu
->header
.addr_size
;
4335 info_ptr
+= cu
->header
.offset_size
;
4338 info_ptr
+= cu
->header
.addr_size
;
4345 case DW_FORM_flag_present
:
4357 case DW_FORM_ref_sig8
:
4360 case DW_FORM_string
:
4361 read_direct_string (abfd
, info_ptr
, &bytes_read
);
4362 info_ptr
+= bytes_read
;
4364 case DW_FORM_sec_offset
:
4366 info_ptr
+= cu
->header
.offset_size
;
4368 case DW_FORM_exprloc
:
4370 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4371 info_ptr
+= bytes_read
;
4373 case DW_FORM_block1
:
4374 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
4376 case DW_FORM_block2
:
4377 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
4379 case DW_FORM_block4
:
4380 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
4384 case DW_FORM_ref_udata
:
4385 info_ptr
= skip_leb128 (abfd
, info_ptr
);
4387 case DW_FORM_indirect
:
4388 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4389 info_ptr
+= bytes_read
;
4390 /* We need to continue parsing from here, so just go back to
4392 goto skip_attribute
;
4395 error (_("Dwarf Error: Cannot handle %s "
4396 "in DWARF reader [in module %s]"),
4397 dwarf_form_name (form
),
4398 bfd_get_filename (abfd
));
4402 if (abbrev
->has_children
)
4403 return skip_children (buffer
, info_ptr
, cu
);
4408 /* Locate ORIG_PDI's sibling.
4409 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4413 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
4414 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4415 bfd
*abfd
, struct dwarf2_cu
*cu
)
4417 /* Do we know the sibling already? */
4419 if (orig_pdi
->sibling
)
4420 return orig_pdi
->sibling
;
4422 /* Are there any children to deal with? */
4424 if (!orig_pdi
->has_children
)
4427 /* Skip the children the long way. */
4429 return skip_children (buffer
, info_ptr
, cu
);
4432 /* Expand this partial symbol table into a full symbol table. */
4435 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
4441 warning (_("bug: psymtab for %s is already read in."),
4448 printf_filtered (_("Reading in symbols for %s..."),
4450 gdb_flush (gdb_stdout
);
4453 /* Restore our global data. */
4454 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
4455 dwarf2_objfile_data_key
);
4457 /* If this psymtab is constructed from a debug-only objfile, the
4458 has_section_at_zero flag will not necessarily be correct. We
4459 can get the correct value for this flag by looking at the data
4460 associated with the (presumably stripped) associated objfile. */
4461 if (pst
->objfile
->separate_debug_objfile_backlink
)
4463 struct dwarf2_per_objfile
*dpo_backlink
4464 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
4465 dwarf2_objfile_data_key
);
4467 dwarf2_per_objfile
->has_section_at_zero
4468 = dpo_backlink
->has_section_at_zero
;
4471 dwarf2_per_objfile
->reading_partial_symbols
= 0;
4473 psymtab_to_symtab_1 (pst
);
4475 /* Finish up the debug error message. */
4477 printf_filtered (_("done.\n"));
4482 /* Reading in full CUs. */
4484 /* Add PER_CU to the queue. */
4487 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4489 struct dwarf2_queue_item
*item
;
4492 item
= xmalloc (sizeof (*item
));
4493 item
->per_cu
= per_cu
;
4496 if (dwarf2_queue
== NULL
)
4497 dwarf2_queue
= item
;
4499 dwarf2_queue_tail
->next
= item
;
4501 dwarf2_queue_tail
= item
;
4504 /* Process the queue. */
4507 process_queue (void)
4509 struct dwarf2_queue_item
*item
, *next_item
;
4511 /* The queue starts out with one item, but following a DIE reference
4512 may load a new CU, adding it to the end of the queue. */
4513 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
4515 if (dwarf2_per_objfile
->using_index
4516 ? !item
->per_cu
->v
.quick
->symtab
4517 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
4518 process_full_comp_unit (item
->per_cu
);
4520 item
->per_cu
->queued
= 0;
4521 next_item
= item
->next
;
4525 dwarf2_queue_tail
= NULL
;
4528 /* Free all allocated queue entries. This function only releases anything if
4529 an error was thrown; if the queue was processed then it would have been
4530 freed as we went along. */
4533 dwarf2_release_queue (void *dummy
)
4535 struct dwarf2_queue_item
*item
, *last
;
4537 item
= dwarf2_queue
;
4540 /* Anything still marked queued is likely to be in an
4541 inconsistent state, so discard it. */
4542 if (item
->per_cu
->queued
)
4544 if (item
->per_cu
->cu
!= NULL
)
4545 free_one_cached_comp_unit (item
->per_cu
->cu
);
4546 item
->per_cu
->queued
= 0;
4554 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
4557 /* Read in full symbols for PST, and anything it depends on. */
4560 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
4562 struct dwarf2_per_cu_data
*per_cu
;
4563 struct cleanup
*back_to
;
4566 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
4567 if (!pst
->dependencies
[i
]->readin
)
4569 /* Inform about additional files that need to be read in. */
4572 /* FIXME: i18n: Need to make this a single string. */
4573 fputs_filtered (" ", gdb_stdout
);
4575 fputs_filtered ("and ", gdb_stdout
);
4577 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
4578 wrap_here (""); /* Flush output. */
4579 gdb_flush (gdb_stdout
);
4581 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
4584 per_cu
= pst
->read_symtab_private
;
4588 /* It's an include file, no symbols to read for it.
4589 Everything is in the parent symtab. */
4594 dw2_do_instantiate_symtab (per_cu
);
4597 /* Load the DIEs associated with PER_CU into memory. */
4600 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4602 struct objfile
*objfile
= per_cu
->objfile
;
4603 bfd
*abfd
= objfile
->obfd
;
4604 struct dwarf2_cu
*cu
;
4605 unsigned int offset
;
4606 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
4607 struct cleanup
*free_abbrevs_cleanup
= NULL
, *free_cu_cleanup
= NULL
;
4608 struct attribute
*attr
;
4611 gdb_assert (! per_cu
->debug_types_section
);
4613 /* Set local variables from the partial symbol table info. */
4614 offset
= per_cu
->offset
;
4616 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4617 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
4618 beg_of_comp_unit
= info_ptr
;
4620 if (per_cu
->cu
== NULL
)
4622 cu
= xmalloc (sizeof (*cu
));
4623 init_one_comp_unit (cu
, per_cu
);
4627 /* If an error occurs while loading, release our storage. */
4628 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
4630 /* Read in the comp_unit header. */
4631 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
4633 /* Skip dummy compilation units. */
4634 if (info_ptr
>= (dwarf2_per_objfile
->info
.buffer
4635 + dwarf2_per_objfile
->info
.size
)
4636 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4638 do_cleanups (free_cu_cleanup
);
4642 /* Complete the cu_header. */
4643 cu
->header
.offset
= offset
;
4644 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
4646 /* Read the abbrevs for this compilation unit. */
4647 dwarf2_read_abbrevs (cu
);
4648 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
4650 /* Link this CU into read_in_chain. */
4651 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4652 dwarf2_per_objfile
->read_in_chain
= per_cu
;
4657 info_ptr
+= cu
->header
.first_die_offset
;
4660 cu
->dies
= read_comp_unit (info_ptr
, cu
);
4662 /* We try not to read any attributes in this function, because not
4663 all CUs needed for references have been loaded yet, and symbol
4664 table processing isn't initialized. But we have to set the CU language,
4665 or we won't be able to build types correctly. */
4666 prepare_one_comp_unit (cu
, cu
->dies
);
4668 /* Similarly, if we do not read the producer, we can not apply
4669 producer-specific interpretation. */
4670 attr
= dwarf2_attr (cu
->dies
, DW_AT_producer
, cu
);
4672 cu
->producer
= DW_STRING (attr
);
4676 do_cleanups (free_abbrevs_cleanup
);
4678 /* We've successfully allocated this compilation unit. Let our
4679 caller clean it up when finished with it. */
4680 discard_cleanups (free_cu_cleanup
);
4684 /* Add a DIE to the delayed physname list. */
4687 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
4688 const char *name
, struct die_info
*die
,
4689 struct dwarf2_cu
*cu
)
4691 struct delayed_method_info mi
;
4693 mi
.fnfield_index
= fnfield_index
;
4697 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
4700 /* A cleanup for freeing the delayed method list. */
4703 free_delayed_list (void *ptr
)
4705 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
4706 if (cu
->method_list
!= NULL
)
4708 VEC_free (delayed_method_info
, cu
->method_list
);
4709 cu
->method_list
= NULL
;
4713 /* Compute the physnames of any methods on the CU's method list.
4715 The computation of method physnames is delayed in order to avoid the
4716 (bad) condition that one of the method's formal parameters is of an as yet
4720 compute_delayed_physnames (struct dwarf2_cu
*cu
)
4723 struct delayed_method_info
*mi
;
4724 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
4726 const char *physname
;
4727 struct fn_fieldlist
*fn_flp
4728 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
4729 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
4730 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
4734 /* Generate full symbol information for PER_CU, whose DIEs have
4735 already been loaded into memory. */
4738 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4740 struct dwarf2_cu
*cu
= per_cu
->cu
;
4741 struct objfile
*objfile
= per_cu
->objfile
;
4742 CORE_ADDR lowpc
, highpc
;
4743 struct symtab
*symtab
;
4744 struct cleanup
*back_to
, *delayed_list_cleanup
;
4747 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4750 back_to
= make_cleanup (really_free_pendings
, NULL
);
4751 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
4753 cu
->list_in_scope
= &file_symbols
;
4755 /* Do line number decoding in read_file_scope () */
4756 process_die (cu
->dies
, cu
);
4758 /* Now that we have processed all the DIEs in the CU, all the types
4759 should be complete, and it should now be safe to compute all of the
4761 compute_delayed_physnames (cu
);
4762 do_cleanups (delayed_list_cleanup
);
4764 /* Some compilers don't define a DW_AT_high_pc attribute for the
4765 compilation unit. If the DW_AT_high_pc is missing, synthesize
4766 it, by scanning the DIE's below the compilation unit. */
4767 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
4769 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
4773 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
4775 /* Set symtab language to language from DW_AT_language. If the
4776 compilation is from a C file generated by language preprocessors, do
4777 not set the language if it was already deduced by start_subfile. */
4778 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
4779 symtab
->language
= cu
->language
;
4781 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
4782 produce DW_AT_location with location lists but it can be possibly
4783 invalid without -fvar-tracking.
4785 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
4786 needed, it would be wrong due to missing DW_AT_producer there.
4788 Still one can confuse GDB by using non-standard GCC compilation
4789 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
4791 if (cu
->has_loclist
&& gcc_4_minor
>= 0)
4792 symtab
->locations_valid
= 1;
4794 if (gcc_4_minor
>= 5)
4795 symtab
->epilogue_unwind_valid
= 1;
4797 symtab
->call_site_htab
= cu
->call_site_htab
;
4800 if (dwarf2_per_objfile
->using_index
)
4801 per_cu
->v
.quick
->symtab
= symtab
;
4804 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4805 pst
->symtab
= symtab
;
4809 do_cleanups (back_to
);
4812 /* Process a die and its children. */
4815 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
4819 case DW_TAG_padding
:
4821 case DW_TAG_compile_unit
:
4822 read_file_scope (die
, cu
);
4824 case DW_TAG_type_unit
:
4825 read_type_unit_scope (die
, cu
);
4827 case DW_TAG_subprogram
:
4828 case DW_TAG_inlined_subroutine
:
4829 read_func_scope (die
, cu
);
4831 case DW_TAG_lexical_block
:
4832 case DW_TAG_try_block
:
4833 case DW_TAG_catch_block
:
4834 read_lexical_block_scope (die
, cu
);
4836 case DW_TAG_GNU_call_site
:
4837 read_call_site_scope (die
, cu
);
4839 case DW_TAG_class_type
:
4840 case DW_TAG_interface_type
:
4841 case DW_TAG_structure_type
:
4842 case DW_TAG_union_type
:
4843 process_structure_scope (die
, cu
);
4845 case DW_TAG_enumeration_type
:
4846 process_enumeration_scope (die
, cu
);
4849 /* These dies have a type, but processing them does not create
4850 a symbol or recurse to process the children. Therefore we can
4851 read them on-demand through read_type_die. */
4852 case DW_TAG_subroutine_type
:
4853 case DW_TAG_set_type
:
4854 case DW_TAG_array_type
:
4855 case DW_TAG_pointer_type
:
4856 case DW_TAG_ptr_to_member_type
:
4857 case DW_TAG_reference_type
:
4858 case DW_TAG_string_type
:
4861 case DW_TAG_base_type
:
4862 case DW_TAG_subrange_type
:
4863 case DW_TAG_typedef
:
4864 /* Add a typedef symbol for the type definition, if it has a
4866 new_symbol (die
, read_type_die (die
, cu
), cu
);
4868 case DW_TAG_common_block
:
4869 read_common_block (die
, cu
);
4871 case DW_TAG_common_inclusion
:
4873 case DW_TAG_namespace
:
4874 processing_has_namespace_info
= 1;
4875 read_namespace (die
, cu
);
4878 processing_has_namespace_info
= 1;
4879 read_module (die
, cu
);
4881 case DW_TAG_imported_declaration
:
4882 case DW_TAG_imported_module
:
4883 processing_has_namespace_info
= 1;
4884 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
4885 || cu
->language
!= language_fortran
))
4886 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
4887 dwarf_tag_name (die
->tag
));
4888 read_import_statement (die
, cu
);
4891 new_symbol (die
, NULL
, cu
);
4896 /* A helper function for dwarf2_compute_name which determines whether DIE
4897 needs to have the name of the scope prepended to the name listed in the
4901 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4903 struct attribute
*attr
;
4907 case DW_TAG_namespace
:
4908 case DW_TAG_typedef
:
4909 case DW_TAG_class_type
:
4910 case DW_TAG_interface_type
:
4911 case DW_TAG_structure_type
:
4912 case DW_TAG_union_type
:
4913 case DW_TAG_enumeration_type
:
4914 case DW_TAG_enumerator
:
4915 case DW_TAG_subprogram
:
4919 case DW_TAG_variable
:
4920 case DW_TAG_constant
:
4921 /* We only need to prefix "globally" visible variables. These include
4922 any variable marked with DW_AT_external or any variable that
4923 lives in a namespace. [Variables in anonymous namespaces
4924 require prefixing, but they are not DW_AT_external.] */
4926 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
4928 struct dwarf2_cu
*spec_cu
= cu
;
4930 return die_needs_namespace (die_specification (die
, &spec_cu
),
4934 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
4935 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
4936 && die
->parent
->tag
!= DW_TAG_module
)
4938 /* A variable in a lexical block of some kind does not need a
4939 namespace, even though in C++ such variables may be external
4940 and have a mangled name. */
4941 if (die
->parent
->tag
== DW_TAG_lexical_block
4942 || die
->parent
->tag
== DW_TAG_try_block
4943 || die
->parent
->tag
== DW_TAG_catch_block
4944 || die
->parent
->tag
== DW_TAG_subprogram
)
4953 /* Retrieve the last character from a mem_file. */
4956 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
4958 char *last_char_p
= (char *) object
;
4961 *last_char_p
= buffer
[length
- 1];
4964 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
4965 compute the physname for the object, which include a method's
4966 formal parameters (C++/Java) and return type (Java).
4968 For Ada, return the DIE's linkage name rather than the fully qualified
4969 name. PHYSNAME is ignored..
4971 The result is allocated on the objfile_obstack and canonicalized. */
4974 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
4977 struct objfile
*objfile
= cu
->objfile
;
4980 name
= dwarf2_name (die
, cu
);
4982 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
4983 compute it by typename_concat inside GDB. */
4984 if (cu
->language
== language_ada
4985 || (cu
->language
== language_fortran
&& physname
))
4987 /* For Ada unit, we prefer the linkage name over the name, as
4988 the former contains the exported name, which the user expects
4989 to be able to reference. Ideally, we want the user to be able
4990 to reference this entity using either natural or linkage name,
4991 but we haven't started looking at this enhancement yet. */
4992 struct attribute
*attr
;
4994 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
4996 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
4997 if (attr
&& DW_STRING (attr
))
4998 return DW_STRING (attr
);
5001 /* These are the only languages we know how to qualify names in. */
5003 && (cu
->language
== language_cplus
|| cu
->language
== language_java
5004 || cu
->language
== language_fortran
))
5006 if (die_needs_namespace (die
, cu
))
5010 struct ui_file
*buf
;
5012 prefix
= determine_prefix (die
, cu
);
5013 buf
= mem_fileopen ();
5014 if (*prefix
!= '\0')
5016 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
5019 fputs_unfiltered (prefixed_name
, buf
);
5020 xfree (prefixed_name
);
5023 fputs_unfiltered (name
, buf
);
5025 /* Template parameters may be specified in the DIE's DW_AT_name, or
5026 as children with DW_TAG_template_type_param or
5027 DW_TAG_value_type_param. If the latter, add them to the name
5028 here. If the name already has template parameters, then
5029 skip this step; some versions of GCC emit both, and
5030 it is more efficient to use the pre-computed name.
5032 Something to keep in mind about this process: it is very
5033 unlikely, or in some cases downright impossible, to produce
5034 something that will match the mangled name of a function.
5035 If the definition of the function has the same debug info,
5036 we should be able to match up with it anyway. But fallbacks
5037 using the minimal symbol, for instance to find a method
5038 implemented in a stripped copy of libstdc++, will not work.
5039 If we do not have debug info for the definition, we will have to
5040 match them up some other way.
5042 When we do name matching there is a related problem with function
5043 templates; two instantiated function templates are allowed to
5044 differ only by their return types, which we do not add here. */
5046 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
5048 struct attribute
*attr
;
5049 struct die_info
*child
;
5052 die
->building_fullname
= 1;
5054 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
5059 struct dwarf2_locexpr_baton
*baton
;
5062 if (child
->tag
!= DW_TAG_template_type_param
5063 && child
->tag
!= DW_TAG_template_value_param
)
5068 fputs_unfiltered ("<", buf
);
5072 fputs_unfiltered (", ", buf
);
5074 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
5077 complaint (&symfile_complaints
,
5078 _("template parameter missing DW_AT_type"));
5079 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
5082 type
= die_type (child
, cu
);
5084 if (child
->tag
== DW_TAG_template_type_param
)
5086 c_print_type (type
, "", buf
, -1, 0);
5090 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
5093 complaint (&symfile_complaints
,
5094 _("template parameter missing "
5095 "DW_AT_const_value"));
5096 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
5100 dwarf2_const_value_attr (attr
, type
, name
,
5101 &cu
->comp_unit_obstack
, cu
,
5102 &value
, &bytes
, &baton
);
5104 if (TYPE_NOSIGN (type
))
5105 /* GDB prints characters as NUMBER 'CHAR'. If that's
5106 changed, this can use value_print instead. */
5107 c_printchar (value
, type
, buf
);
5110 struct value_print_options opts
;
5113 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
5117 else if (bytes
!= NULL
)
5119 v
= allocate_value (type
);
5120 memcpy (value_contents_writeable (v
), bytes
,
5121 TYPE_LENGTH (type
));
5124 v
= value_from_longest (type
, value
);
5126 /* Specify decimal so that we do not depend on
5128 get_formatted_print_options (&opts
, 'd');
5130 value_print (v
, buf
, &opts
);
5136 die
->building_fullname
= 0;
5140 /* Close the argument list, with a space if necessary
5141 (nested templates). */
5142 char last_char
= '\0';
5143 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
5144 if (last_char
== '>')
5145 fputs_unfiltered (" >", buf
);
5147 fputs_unfiltered (">", buf
);
5151 /* For Java and C++ methods, append formal parameter type
5152 information, if PHYSNAME. */
5154 if (physname
&& die
->tag
== DW_TAG_subprogram
5155 && (cu
->language
== language_cplus
5156 || cu
->language
== language_java
))
5158 struct type
*type
= read_type_die (die
, cu
);
5160 c_type_print_args (type
, buf
, 1, cu
->language
);
5162 if (cu
->language
== language_java
)
5164 /* For java, we must append the return type to method
5166 if (die
->tag
== DW_TAG_subprogram
)
5167 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
5170 else if (cu
->language
== language_cplus
)
5172 /* Assume that an artificial first parameter is
5173 "this", but do not crash if it is not. RealView
5174 marks unnamed (and thus unused) parameters as
5175 artificial; there is no way to differentiate
5177 if (TYPE_NFIELDS (type
) > 0
5178 && TYPE_FIELD_ARTIFICIAL (type
, 0)
5179 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
5180 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
5182 fputs_unfiltered (" const", buf
);
5186 name
= ui_file_obsavestring (buf
, &objfile
->objfile_obstack
,
5188 ui_file_delete (buf
);
5190 if (cu
->language
== language_cplus
)
5193 = dwarf2_canonicalize_name (name
, cu
,
5194 &objfile
->objfile_obstack
);
5205 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5206 If scope qualifiers are appropriate they will be added. The result
5207 will be allocated on the objfile_obstack, or NULL if the DIE does
5208 not have a name. NAME may either be from a previous call to
5209 dwarf2_name or NULL.
5211 The output string will be canonicalized (if C++/Java). */
5214 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5216 return dwarf2_compute_name (name
, die
, cu
, 0);
5219 /* Construct a physname for the given DIE in CU. NAME may either be
5220 from a previous call to dwarf2_name or NULL. The result will be
5221 allocated on the objfile_objstack or NULL if the DIE does not have a
5224 The output string will be canonicalized (if C++/Java). */
5227 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5229 struct objfile
*objfile
= cu
->objfile
;
5230 struct attribute
*attr
;
5231 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
5232 struct cleanup
*back_to
;
5235 /* In this case dwarf2_compute_name is just a shortcut not building anything
5237 if (!die_needs_namespace (die
, cu
))
5238 return dwarf2_compute_name (name
, die
, cu
, 1);
5240 back_to
= make_cleanup (null_cleanup
, NULL
);
5242 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5244 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5246 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
5248 if (attr
&& DW_STRING (attr
))
5252 mangled
= DW_STRING (attr
);
5254 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
5255 type. It is easier for GDB users to search for such functions as
5256 `name(params)' than `long name(params)'. In such case the minimal
5257 symbol names do not match the full symbol names but for template
5258 functions there is never a need to look up their definition from their
5259 declaration so the only disadvantage remains the minimal symbol
5260 variant `long name(params)' does not have the proper inferior type.
5263 demangled
= cplus_demangle (mangled
, (DMGL_PARAMS
| DMGL_ANSI
5264 | (cu
->language
== language_java
5265 ? DMGL_JAVA
| DMGL_RET_POSTFIX
5269 make_cleanup (xfree
, demangled
);
5279 if (canon
== NULL
|| check_physname
)
5281 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
5283 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
5285 /* It may not mean a bug in GDB. The compiler could also
5286 compute DW_AT_linkage_name incorrectly. But in such case
5287 GDB would need to be bug-to-bug compatible. */
5289 complaint (&symfile_complaints
,
5290 _("Computed physname <%s> does not match demangled <%s> "
5291 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
5292 physname
, canon
, mangled
, die
->offset
, objfile
->name
);
5294 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
5295 is available here - over computed PHYSNAME. It is safer
5296 against both buggy GDB and buggy compilers. */
5310 retval
= obsavestring (retval
, strlen (retval
),
5311 &objfile
->objfile_obstack
);
5313 do_cleanups (back_to
);
5317 /* Read the import statement specified by the given die and record it. */
5320 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
5322 struct objfile
*objfile
= cu
->objfile
;
5323 struct attribute
*import_attr
;
5324 struct die_info
*imported_die
, *child_die
;
5325 struct dwarf2_cu
*imported_cu
;
5326 const char *imported_name
;
5327 const char *imported_name_prefix
;
5328 const char *canonical_name
;
5329 const char *import_alias
;
5330 const char *imported_declaration
= NULL
;
5331 const char *import_prefix
;
5332 VEC (const_char_ptr
) *excludes
= NULL
;
5333 struct cleanup
*cleanups
;
5337 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
5338 if (import_attr
== NULL
)
5340 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5341 dwarf_tag_name (die
->tag
));
5346 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
5347 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5348 if (imported_name
== NULL
)
5350 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
5352 The import in the following code:
5366 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
5367 <52> DW_AT_decl_file : 1
5368 <53> DW_AT_decl_line : 6
5369 <54> DW_AT_import : <0x75>
5370 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
5372 <5b> DW_AT_decl_file : 1
5373 <5c> DW_AT_decl_line : 2
5374 <5d> DW_AT_type : <0x6e>
5376 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
5377 <76> DW_AT_byte_size : 4
5378 <77> DW_AT_encoding : 5 (signed)
5380 imports the wrong die ( 0x75 instead of 0x58 ).
5381 This case will be ignored until the gcc bug is fixed. */
5385 /* Figure out the local name after import. */
5386 import_alias
= dwarf2_name (die
, cu
);
5388 /* Figure out where the statement is being imported to. */
5389 import_prefix
= determine_prefix (die
, cu
);
5391 /* Figure out what the scope of the imported die is and prepend it
5392 to the name of the imported die. */
5393 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
5395 if (imported_die
->tag
!= DW_TAG_namespace
5396 && imported_die
->tag
!= DW_TAG_module
)
5398 imported_declaration
= imported_name
;
5399 canonical_name
= imported_name_prefix
;
5401 else if (strlen (imported_name_prefix
) > 0)
5403 temp
= alloca (strlen (imported_name_prefix
)
5404 + 2 + strlen (imported_name
) + 1);
5405 strcpy (temp
, imported_name_prefix
);
5406 strcat (temp
, "::");
5407 strcat (temp
, imported_name
);
5408 canonical_name
= temp
;
5411 canonical_name
= imported_name
;
5413 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
5415 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
5416 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
5417 child_die
= sibling_die (child_die
))
5419 /* DWARF-4: A Fortran use statement with a “rename list” may be
5420 represented by an imported module entry with an import attribute
5421 referring to the module and owned entries corresponding to those
5422 entities that are renamed as part of being imported. */
5424 if (child_die
->tag
!= DW_TAG_imported_declaration
)
5426 complaint (&symfile_complaints
,
5427 _("child DW_TAG_imported_declaration expected "
5428 "- DIE at 0x%x [in module %s]"),
5429 child_die
->offset
, objfile
->name
);
5433 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
5434 if (import_attr
== NULL
)
5436 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5437 dwarf_tag_name (child_die
->tag
));
5442 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
5444 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5445 if (imported_name
== NULL
)
5447 complaint (&symfile_complaints
,
5448 _("child DW_TAG_imported_declaration has unknown "
5449 "imported name - DIE at 0x%x [in module %s]"),
5450 child_die
->offset
, objfile
->name
);
5454 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
5456 process_die (child_die
, cu
);
5459 cp_add_using_directive (import_prefix
,
5462 imported_declaration
,
5464 &objfile
->objfile_obstack
);
5466 do_cleanups (cleanups
);
5469 /* Cleanup function for read_file_scope. */
5472 free_cu_line_header (void *arg
)
5474 struct dwarf2_cu
*cu
= arg
;
5476 free_line_header (cu
->line_header
);
5477 cu
->line_header
= NULL
;
5481 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
5482 char **name
, char **comp_dir
)
5484 struct attribute
*attr
;
5489 /* Find the filename. Do not use dwarf2_name here, since the filename
5490 is not a source language identifier. */
5491 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5494 *name
= DW_STRING (attr
);
5497 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5499 *comp_dir
= DW_STRING (attr
);
5500 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
5502 *comp_dir
= ldirname (*name
);
5503 if (*comp_dir
!= NULL
)
5504 make_cleanup (xfree
, *comp_dir
);
5506 if (*comp_dir
!= NULL
)
5508 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5509 directory, get rid of it. */
5510 char *cp
= strchr (*comp_dir
, ':');
5512 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
5517 *name
= "<unknown>";
5520 /* Handle DW_AT_stmt_list for a compilation unit or type unit.
5521 DIE is the DW_TAG_compile_unit or DW_TAG_type_unit die for CU.
5522 COMP_DIR is the compilation directory.
5523 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
5526 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
5527 const char *comp_dir
, int want_line_info
)
5529 struct attribute
*attr
;
5530 struct objfile
*objfile
= cu
->objfile
;
5531 bfd
*abfd
= objfile
->obfd
;
5533 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5536 unsigned int line_offset
= DW_UNSND (attr
);
5537 struct line_header
*line_header
5538 = dwarf_decode_line_header (line_offset
, abfd
, cu
);
5542 cu
->line_header
= line_header
;
5543 make_cleanup (free_cu_line_header
, cu
);
5544 dwarf_decode_lines (line_header
, comp_dir
, cu
, NULL
, want_line_info
);
5549 /* Process DW_TAG_compile_unit. */
5552 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5554 struct objfile
*objfile
= cu
->objfile
;
5555 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5556 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
5557 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
5558 struct attribute
*attr
;
5560 char *comp_dir
= NULL
;
5561 struct die_info
*child_die
;
5562 bfd
*abfd
= objfile
->obfd
;
5565 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5567 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
5569 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5570 from finish_block. */
5571 if (lowpc
== ((CORE_ADDR
) -1))
5576 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
5578 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5581 set_cu_language (DW_UNSND (attr
), cu
);
5584 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5586 cu
->producer
= DW_STRING (attr
);
5588 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
5589 standardised yet. As a workaround for the language detection we fall
5590 back to the DW_AT_producer string. */
5591 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
5592 cu
->language
= language_opencl
;
5594 /* We assume that we're processing GCC output. */
5595 processing_gcc_compilation
= 2;
5597 processing_has_namespace_info
= 0;
5599 start_symtab (name
, comp_dir
, lowpc
);
5600 record_debugformat ("DWARF 2");
5601 record_producer (cu
->producer
);
5603 /* Decode line number information if present. We do this before
5604 processing child DIEs, so that the line header table is available
5605 for DW_AT_decl_file. */
5606 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, 1);
5608 /* Process all dies in compilation unit. */
5609 if (die
->child
!= NULL
)
5611 child_die
= die
->child
;
5612 while (child_die
&& child_die
->tag
)
5614 process_die (child_die
, cu
);
5615 child_die
= sibling_die (child_die
);
5619 /* Decode macro information, if present. Dwarf 2 macro information
5620 refers to information in the line number info statement program
5621 header, so we can only read it if we've read the header
5623 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
5624 if (attr
&& cu
->line_header
)
5626 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
5627 complaint (&symfile_complaints
,
5628 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
5630 dwarf_decode_macros (cu
->line_header
, DW_UNSND (attr
),
5632 &dwarf2_per_objfile
->macro
, 1);
5636 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
5637 if (attr
&& cu
->line_header
)
5639 unsigned int macro_offset
= DW_UNSND (attr
);
5641 dwarf_decode_macros (cu
->line_header
, macro_offset
,
5643 &dwarf2_per_objfile
->macinfo
, 0);
5647 do_cleanups (back_to
);
5650 /* Process DW_TAG_type_unit.
5651 For TUs we want to skip the first top level sibling if it's not the
5652 actual type being defined by this TU. In this case the first top
5653 level sibling is there to provide context only. */
5656 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5658 struct objfile
*objfile
= cu
->objfile
;
5659 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5661 struct attribute
*attr
;
5663 char *comp_dir
= NULL
;
5664 struct die_info
*child_die
;
5665 bfd
*abfd
= objfile
->obfd
;
5667 /* start_symtab needs a low pc, but we don't really have one.
5668 Do what read_file_scope would do in the absence of such info. */
5669 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5671 /* Find the filename. Do not use dwarf2_name here, since the filename
5672 is not a source language identifier. */
5673 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5675 name
= DW_STRING (attr
);
5677 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5679 comp_dir
= DW_STRING (attr
);
5680 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
5682 comp_dir
= ldirname (name
);
5683 if (comp_dir
!= NULL
)
5684 make_cleanup (xfree
, comp_dir
);
5690 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5692 set_cu_language (DW_UNSND (attr
), cu
);
5694 /* This isn't technically needed today. It is done for symmetry
5695 with read_file_scope. */
5696 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5698 cu
->producer
= DW_STRING (attr
);
5700 /* We assume that we're processing GCC output. */
5701 processing_gcc_compilation
= 2;
5703 processing_has_namespace_info
= 0;
5705 start_symtab (name
, comp_dir
, lowpc
);
5706 record_debugformat ("DWARF 2");
5707 record_producer (cu
->producer
);
5709 /* Decode line number information if present. We do this before
5710 processing child DIEs, so that the line header table is available
5711 for DW_AT_decl_file.
5712 We don't need the pc/line-number mapping for type units. */
5713 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, 0);
5715 /* Process the dies in the type unit. */
5716 if (die
->child
== NULL
)
5718 dump_die_for_error (die
);
5719 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5720 bfd_get_filename (abfd
));
5723 child_die
= die
->child
;
5725 while (child_die
&& child_die
->tag
)
5727 process_die (child_die
, cu
);
5729 child_die
= sibling_die (child_die
);
5732 do_cleanups (back_to
);
5735 /* qsort helper for inherit_abstract_dies. */
5738 unsigned_int_compar (const void *ap
, const void *bp
)
5740 unsigned int a
= *(unsigned int *) ap
;
5741 unsigned int b
= *(unsigned int *) bp
;
5743 return (a
> b
) - (b
> a
);
5746 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5747 Inherit only the children of the DW_AT_abstract_origin DIE not being
5748 already referenced by DW_AT_abstract_origin from the children of the
5752 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
5754 struct die_info
*child_die
;
5755 unsigned die_children_count
;
5756 /* CU offsets which were referenced by children of the current DIE. */
5758 unsigned *offsets_end
, *offsetp
;
5759 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5760 struct die_info
*origin_die
;
5761 /* Iterator of the ORIGIN_DIE children. */
5762 struct die_info
*origin_child_die
;
5763 struct cleanup
*cleanups
;
5764 struct attribute
*attr
;
5765 struct dwarf2_cu
*origin_cu
;
5766 struct pending
**origin_previous_list_in_scope
;
5768 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
5772 /* Note that following die references may follow to a die in a
5776 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
5778 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5780 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
5781 origin_cu
->list_in_scope
= cu
->list_in_scope
;
5783 if (die
->tag
!= origin_die
->tag
5784 && !(die
->tag
== DW_TAG_inlined_subroutine
5785 && origin_die
->tag
== DW_TAG_subprogram
))
5786 complaint (&symfile_complaints
,
5787 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5788 die
->offset
, origin_die
->offset
);
5790 child_die
= die
->child
;
5791 die_children_count
= 0;
5792 while (child_die
&& child_die
->tag
)
5794 child_die
= sibling_die (child_die
);
5795 die_children_count
++;
5797 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
5798 cleanups
= make_cleanup (xfree
, offsets
);
5800 offsets_end
= offsets
;
5801 child_die
= die
->child
;
5802 while (child_die
&& child_die
->tag
)
5804 /* For each CHILD_DIE, find the corresponding child of
5805 ORIGIN_DIE. If there is more than one layer of
5806 DW_AT_abstract_origin, follow them all; there shouldn't be,
5807 but GCC versions at least through 4.4 generate this (GCC PR
5809 struct die_info
*child_origin_die
= child_die
;
5810 struct dwarf2_cu
*child_origin_cu
= cu
;
5814 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
5818 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
5822 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5823 counterpart may exist. */
5824 if (child_origin_die
!= child_die
)
5826 if (child_die
->tag
!= child_origin_die
->tag
5827 && !(child_die
->tag
== DW_TAG_inlined_subroutine
5828 && child_origin_die
->tag
== DW_TAG_subprogram
))
5829 complaint (&symfile_complaints
,
5830 _("Child DIE 0x%x and its abstract origin 0x%x have "
5831 "different tags"), child_die
->offset
,
5832 child_origin_die
->offset
);
5833 if (child_origin_die
->parent
!= origin_die
)
5834 complaint (&symfile_complaints
,
5835 _("Child DIE 0x%x and its abstract origin 0x%x have "
5836 "different parents"), child_die
->offset
,
5837 child_origin_die
->offset
);
5839 *offsets_end
++ = child_origin_die
->offset
;
5841 child_die
= sibling_die (child_die
);
5843 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
5844 unsigned_int_compar
);
5845 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
5846 if (offsetp
[-1] == *offsetp
)
5847 complaint (&symfile_complaints
,
5848 _("Multiple children of DIE 0x%x refer "
5849 "to DIE 0x%x as their abstract origin"),
5850 die
->offset
, *offsetp
);
5853 origin_child_die
= origin_die
->child
;
5854 while (origin_child_die
&& origin_child_die
->tag
)
5856 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5857 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
5859 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
5861 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5862 process_die (origin_child_die
, origin_cu
);
5864 origin_child_die
= sibling_die (origin_child_die
);
5866 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
5868 do_cleanups (cleanups
);
5872 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5874 struct objfile
*objfile
= cu
->objfile
;
5875 struct context_stack
*new;
5878 struct die_info
*child_die
;
5879 struct attribute
*attr
, *call_line
, *call_file
;
5882 struct block
*block
;
5883 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
5884 VEC (symbolp
) *template_args
= NULL
;
5885 struct template_symbol
*templ_func
= NULL
;
5889 /* If we do not have call site information, we can't show the
5890 caller of this inlined function. That's too confusing, so
5891 only use the scope for local variables. */
5892 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
5893 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
5894 if (call_line
== NULL
|| call_file
== NULL
)
5896 read_lexical_block_scope (die
, cu
);
5901 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5903 name
= dwarf2_name (die
, cu
);
5905 /* Ignore functions with missing or empty names. These are actually
5906 illegal according to the DWARF standard. */
5909 complaint (&symfile_complaints
,
5910 _("missing name for subprogram DIE at %d"), die
->offset
);
5914 /* Ignore functions with missing or invalid low and high pc attributes. */
5915 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5917 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5918 if (!attr
|| !DW_UNSND (attr
))
5919 complaint (&symfile_complaints
,
5920 _("cannot get low and high bounds "
5921 "for subprogram DIE at %d"),
5929 /* If we have any template arguments, then we must allocate a
5930 different sort of symbol. */
5931 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
5933 if (child_die
->tag
== DW_TAG_template_type_param
5934 || child_die
->tag
== DW_TAG_template_value_param
)
5936 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5937 struct template_symbol
);
5938 templ_func
->base
.is_cplus_template_function
= 1;
5943 new = push_context (0, lowpc
);
5944 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
5945 (struct symbol
*) templ_func
);
5947 /* If there is a location expression for DW_AT_frame_base, record
5949 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
5951 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
5952 expression is being recorded directly in the function's symbol
5953 and not in a separate frame-base object. I guess this hack is
5954 to avoid adding some sort of frame-base adjunct/annex to the
5955 function's symbol :-(. The problem with doing this is that it
5956 results in a function symbol with a location expression that
5957 has nothing to do with the location of the function, ouch! The
5958 relationship should be: a function's symbol has-a frame base; a
5959 frame-base has-a location expression. */
5960 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
5962 cu
->list_in_scope
= &local_symbols
;
5964 if (die
->child
!= NULL
)
5966 child_die
= die
->child
;
5967 while (child_die
&& child_die
->tag
)
5969 if (child_die
->tag
== DW_TAG_template_type_param
5970 || child_die
->tag
== DW_TAG_template_value_param
)
5972 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
5975 VEC_safe_push (symbolp
, template_args
, arg
);
5978 process_die (child_die
, cu
);
5979 child_die
= sibling_die (child_die
);
5983 inherit_abstract_dies (die
, cu
);
5985 /* If we have a DW_AT_specification, we might need to import using
5986 directives from the context of the specification DIE. See the
5987 comment in determine_prefix. */
5988 if (cu
->language
== language_cplus
5989 && dwarf2_attr (die
, DW_AT_specification
, cu
))
5991 struct dwarf2_cu
*spec_cu
= cu
;
5992 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
5996 child_die
= spec_die
->child
;
5997 while (child_die
&& child_die
->tag
)
5999 if (child_die
->tag
== DW_TAG_imported_module
)
6000 process_die (child_die
, spec_cu
);
6001 child_die
= sibling_die (child_die
);
6004 /* In some cases, GCC generates specification DIEs that
6005 themselves contain DW_AT_specification attributes. */
6006 spec_die
= die_specification (spec_die
, &spec_cu
);
6010 new = pop_context ();
6011 /* Make a block for the local symbols within. */
6012 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
6013 lowpc
, highpc
, objfile
);
6015 /* For C++, set the block's scope. */
6016 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
6017 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
6018 determine_prefix (die
, cu
),
6019 processing_has_namespace_info
);
6021 /* If we have address ranges, record them. */
6022 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
6024 /* Attach template arguments to function. */
6025 if (! VEC_empty (symbolp
, template_args
))
6027 gdb_assert (templ_func
!= NULL
);
6029 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
6030 templ_func
->template_arguments
6031 = obstack_alloc (&objfile
->objfile_obstack
,
6032 (templ_func
->n_template_arguments
6033 * sizeof (struct symbol
*)));
6034 memcpy (templ_func
->template_arguments
,
6035 VEC_address (symbolp
, template_args
),
6036 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
6037 VEC_free (symbolp
, template_args
);
6040 /* In C++, we can have functions nested inside functions (e.g., when
6041 a function declares a class that has methods). This means that
6042 when we finish processing a function scope, we may need to go
6043 back to building a containing block's symbol lists. */
6044 local_symbols
= new->locals
;
6045 param_symbols
= new->params
;
6046 using_directives
= new->using_directives
;
6048 /* If we've finished processing a top-level function, subsequent
6049 symbols go in the file symbol list. */
6050 if (outermost_context_p ())
6051 cu
->list_in_scope
= &file_symbols
;
6054 /* Process all the DIES contained within a lexical block scope. Start
6055 a new scope, process the dies, and then close the scope. */
6058 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6060 struct objfile
*objfile
= cu
->objfile
;
6061 struct context_stack
*new;
6062 CORE_ADDR lowpc
, highpc
;
6063 struct die_info
*child_die
;
6066 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6068 /* Ignore blocks with missing or invalid low and high pc attributes. */
6069 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
6070 as multiple lexical blocks? Handling children in a sane way would
6071 be nasty. Might be easier to properly extend generic blocks to
6073 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
6078 push_context (0, lowpc
);
6079 if (die
->child
!= NULL
)
6081 child_die
= die
->child
;
6082 while (child_die
&& child_die
->tag
)
6084 process_die (child_die
, cu
);
6085 child_die
= sibling_die (child_die
);
6088 new = pop_context ();
6090 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
6093 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
6096 /* Note that recording ranges after traversing children, as we
6097 do here, means that recording a parent's ranges entails
6098 walking across all its children's ranges as they appear in
6099 the address map, which is quadratic behavior.
6101 It would be nicer to record the parent's ranges before
6102 traversing its children, simply overriding whatever you find
6103 there. But since we don't even decide whether to create a
6104 block until after we've traversed its children, that's hard
6106 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
6108 local_symbols
= new->locals
;
6109 using_directives
= new->using_directives
;
6112 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
6115 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6117 struct objfile
*objfile
= cu
->objfile
;
6118 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6119 CORE_ADDR pc
, baseaddr
;
6120 struct attribute
*attr
;
6121 struct call_site
*call_site
, call_site_local
;
6124 struct die_info
*child_die
;
6126 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6128 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6131 complaint (&symfile_complaints
,
6132 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
6133 "DIE 0x%x [in module %s]"),
6134 die
->offset
, objfile
->name
);
6137 pc
= DW_ADDR (attr
) + baseaddr
;
6139 if (cu
->call_site_htab
== NULL
)
6140 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
6141 NULL
, &objfile
->objfile_obstack
,
6142 hashtab_obstack_allocate
, NULL
);
6143 call_site_local
.pc
= pc
;
6144 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
6147 complaint (&symfile_complaints
,
6148 _("Duplicate PC %s for DW_TAG_GNU_call_site "
6149 "DIE 0x%x [in module %s]"),
6150 paddress (gdbarch
, pc
), die
->offset
, objfile
->name
);
6154 /* Count parameters at the caller. */
6157 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
6158 child_die
= sibling_die (child_die
))
6160 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
6162 complaint (&symfile_complaints
,
6163 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
6164 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6165 child_die
->tag
, child_die
->offset
, objfile
->name
);
6172 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
6173 (sizeof (*call_site
)
6174 + (sizeof (*call_site
->parameter
)
6177 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
6180 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
6182 struct die_info
*func_die
;
6184 /* Skip also over DW_TAG_inlined_subroutine. */
6185 for (func_die
= die
->parent
;
6186 func_die
&& func_die
->tag
!= DW_TAG_subprogram
6187 && func_die
->tag
!= DW_TAG_subroutine_type
;
6188 func_die
= func_die
->parent
);
6190 /* DW_AT_GNU_all_call_sites is a superset
6191 of DW_AT_GNU_all_tail_call_sites. */
6193 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
6194 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
6196 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
6197 not complete. But keep CALL_SITE for look ups via call_site_htab,
6198 both the initial caller containing the real return address PC and
6199 the final callee containing the current PC of a chain of tail
6200 calls do not need to have the tail call list complete. But any
6201 function candidate for a virtual tail call frame searched via
6202 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
6203 determined unambiguously. */
6207 struct type
*func_type
= NULL
;
6210 func_type
= get_die_type (func_die
, cu
);
6211 if (func_type
!= NULL
)
6213 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
6215 /* Enlist this call site to the function. */
6216 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
6217 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
6220 complaint (&symfile_complaints
,
6221 _("Cannot find function owning DW_TAG_GNU_call_site "
6222 "DIE 0x%x [in module %s]"),
6223 die
->offset
, objfile
->name
);
6227 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
6229 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
6230 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
6231 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
6232 /* Keep NULL DWARF_BLOCK. */;
6233 else if (attr_form_is_block (attr
))
6235 struct dwarf2_locexpr_baton
*dlbaton
;
6237 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
6238 dlbaton
->data
= DW_BLOCK (attr
)->data
;
6239 dlbaton
->size
= DW_BLOCK (attr
)->size
;
6240 dlbaton
->per_cu
= cu
->per_cu
;
6242 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
6244 else if (is_ref_attr (attr
))
6246 struct dwarf2_cu
*target_cu
= cu
;
6247 struct die_info
*target_die
;
6249 target_die
= follow_die_ref_or_sig (die
, attr
, &target_cu
);
6250 gdb_assert (target_cu
->objfile
== objfile
);
6251 if (die_is_declaration (target_die
, target_cu
))
6253 const char *target_physname
;
6255 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
6256 if (target_physname
== NULL
)
6257 complaint (&symfile_complaints
,
6258 _("DW_AT_GNU_call_site_target target DIE has invalid "
6259 "physname, for referencing DIE 0x%x [in module %s]"),
6260 die
->offset
, objfile
->name
);
6262 SET_FIELD_PHYSNAME (call_site
->target
, (char *) target_physname
);
6268 /* DW_AT_entry_pc should be preferred. */
6269 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
6270 complaint (&symfile_complaints
,
6271 _("DW_AT_GNU_call_site_target target DIE has invalid "
6272 "low pc, for referencing DIE 0x%x [in module %s]"),
6273 die
->offset
, objfile
->name
);
6275 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
6279 complaint (&symfile_complaints
,
6280 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
6281 "block nor reference, for DIE 0x%x [in module %s]"),
6282 die
->offset
, objfile
->name
);
6284 call_site
->per_cu
= cu
->per_cu
;
6286 for (child_die
= die
->child
;
6287 child_die
&& child_die
->tag
;
6288 child_die
= sibling_die (child_die
))
6290 struct dwarf2_locexpr_baton
*dlbaton
;
6291 struct call_site_parameter
*parameter
;
6293 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
6295 /* Already printed the complaint above. */
6299 gdb_assert (call_site
->parameter_count
< nparams
);
6300 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
6302 /* DW_AT_location specifies the register number. Value of the data
6303 assumed for the register is contained in DW_AT_GNU_call_site_value. */
6305 attr
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
6306 if (!attr
|| !attr_form_is_block (attr
))
6308 complaint (&symfile_complaints
,
6309 _("No DW_FORM_block* DW_AT_location for "
6310 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6311 child_die
->offset
, objfile
->name
);
6314 parameter
->dwarf_reg
= dwarf_block_to_dwarf_reg (DW_BLOCK (attr
)->data
,
6315 &DW_BLOCK (attr
)->data
[DW_BLOCK (attr
)->size
]);
6316 if (parameter
->dwarf_reg
== -1
6317 && !dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (attr
)->data
,
6318 &DW_BLOCK (attr
)->data
[DW_BLOCK (attr
)->size
],
6319 ¶meter
->fb_offset
))
6321 complaint (&symfile_complaints
,
6322 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
6323 "for DW_FORM_block* DW_AT_location for "
6324 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6325 child_die
->offset
, objfile
->name
);
6329 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
6330 if (!attr_form_is_block (attr
))
6332 complaint (&symfile_complaints
,
6333 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
6334 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6335 child_die
->offset
, objfile
->name
);
6338 parameter
->value
= DW_BLOCK (attr
)->data
;
6339 parameter
->value_size
= DW_BLOCK (attr
)->size
;
6341 /* Parameters are not pre-cleared by memset above. */
6342 parameter
->data_value
= NULL
;
6343 parameter
->data_value_size
= 0;
6344 call_site
->parameter_count
++;
6346 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
6349 if (!attr_form_is_block (attr
))
6350 complaint (&symfile_complaints
,
6351 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
6352 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6353 child_die
->offset
, objfile
->name
);
6356 parameter
->data_value
= DW_BLOCK (attr
)->data
;
6357 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
6363 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
6364 Return 1 if the attributes are present and valid, otherwise, return 0.
6365 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
6368 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
6369 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
6370 struct partial_symtab
*ranges_pst
)
6372 struct objfile
*objfile
= cu
->objfile
;
6373 struct comp_unit_head
*cu_header
= &cu
->header
;
6374 bfd
*obfd
= objfile
->obfd
;
6375 unsigned int addr_size
= cu_header
->addr_size
;
6376 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6377 /* Base address selection entry. */
6388 found_base
= cu
->base_known
;
6389 base
= cu
->base_address
;
6391 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
6392 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6394 complaint (&symfile_complaints
,
6395 _("Offset %d out of bounds for DW_AT_ranges attribute"),
6399 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6401 /* Read in the largest possible address. */
6402 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
6403 if ((marker
& mask
) == mask
)
6405 /* If we found the largest possible address, then
6406 read the base address. */
6407 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
6408 buffer
+= 2 * addr_size
;
6409 offset
+= 2 * addr_size
;
6415 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6419 CORE_ADDR range_beginning
, range_end
;
6421 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
6422 buffer
+= addr_size
;
6423 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
6424 buffer
+= addr_size
;
6425 offset
+= 2 * addr_size
;
6427 /* An end of list marker is a pair of zero addresses. */
6428 if (range_beginning
== 0 && range_end
== 0)
6429 /* Found the end of list entry. */
6432 /* Each base address selection entry is a pair of 2 values.
6433 The first is the largest possible address, the second is
6434 the base address. Check for a base address here. */
6435 if ((range_beginning
& mask
) == mask
)
6437 /* If we found the largest possible address, then
6438 read the base address. */
6439 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
6446 /* We have no valid base address for the ranges
6448 complaint (&symfile_complaints
,
6449 _("Invalid .debug_ranges data (no base address)"));
6453 if (range_beginning
> range_end
)
6455 /* Inverted range entries are invalid. */
6456 complaint (&symfile_complaints
,
6457 _("Invalid .debug_ranges data (inverted range)"));
6461 /* Empty range entries have no effect. */
6462 if (range_beginning
== range_end
)
6465 range_beginning
+= base
;
6468 if (ranges_pst
!= NULL
)
6469 addrmap_set_empty (objfile
->psymtabs_addrmap
,
6470 range_beginning
+ baseaddr
,
6471 range_end
- 1 + baseaddr
,
6474 /* FIXME: This is recording everything as a low-high
6475 segment of consecutive addresses. We should have a
6476 data structure for discontiguous block ranges
6480 low
= range_beginning
;
6486 if (range_beginning
< low
)
6487 low
= range_beginning
;
6488 if (range_end
> high
)
6494 /* If the first entry is an end-of-list marker, the range
6495 describes an empty scope, i.e. no instructions. */
6501 *high_return
= high
;
6505 /* Get low and high pc attributes from a die. Return 1 if the attributes
6506 are present and valid, otherwise, return 0. Return -1 if the range is
6507 discontinuous, i.e. derived from DW_AT_ranges information. */
6509 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
6510 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
6511 struct partial_symtab
*pst
)
6513 struct attribute
*attr
;
6518 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6521 high
= DW_ADDR (attr
);
6522 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6524 low
= DW_ADDR (attr
);
6526 /* Found high w/o low attribute. */
6529 /* Found consecutive range of addresses. */
6534 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6537 /* Value of the DW_AT_ranges attribute is the offset in the
6538 .debug_ranges section. */
6539 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
6541 /* Found discontinuous range of addresses. */
6546 /* read_partial_die has also the strict LOW < HIGH requirement. */
6550 /* When using the GNU linker, .gnu.linkonce. sections are used to
6551 eliminate duplicate copies of functions and vtables and such.
6552 The linker will arbitrarily choose one and discard the others.
6553 The AT_*_pc values for such functions refer to local labels in
6554 these sections. If the section from that file was discarded, the
6555 labels are not in the output, so the relocs get a value of 0.
6556 If this is a discarded function, mark the pc bounds as invalid,
6557 so that GDB will ignore it. */
6558 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
6567 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
6568 its low and high PC addresses. Do nothing if these addresses could not
6569 be determined. Otherwise, set LOWPC to the low address if it is smaller,
6570 and HIGHPC to the high address if greater than HIGHPC. */
6573 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
6574 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6575 struct dwarf2_cu
*cu
)
6577 CORE_ADDR low
, high
;
6578 struct die_info
*child
= die
->child
;
6580 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
6582 *lowpc
= min (*lowpc
, low
);
6583 *highpc
= max (*highpc
, high
);
6586 /* If the language does not allow nested subprograms (either inside
6587 subprograms or lexical blocks), we're done. */
6588 if (cu
->language
!= language_ada
)
6591 /* Check all the children of the given DIE. If it contains nested
6592 subprograms, then check their pc bounds. Likewise, we need to
6593 check lexical blocks as well, as they may also contain subprogram
6595 while (child
&& child
->tag
)
6597 if (child
->tag
== DW_TAG_subprogram
6598 || child
->tag
== DW_TAG_lexical_block
)
6599 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
6600 child
= sibling_die (child
);
6604 /* Get the low and high pc's represented by the scope DIE, and store
6605 them in *LOWPC and *HIGHPC. If the correct values can't be
6606 determined, set *LOWPC to -1 and *HIGHPC to 0. */
6609 get_scope_pc_bounds (struct die_info
*die
,
6610 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6611 struct dwarf2_cu
*cu
)
6613 CORE_ADDR best_low
= (CORE_ADDR
) -1;
6614 CORE_ADDR best_high
= (CORE_ADDR
) 0;
6615 CORE_ADDR current_low
, current_high
;
6617 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
6619 best_low
= current_low
;
6620 best_high
= current_high
;
6624 struct die_info
*child
= die
->child
;
6626 while (child
&& child
->tag
)
6628 switch (child
->tag
) {
6629 case DW_TAG_subprogram
:
6630 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
6632 case DW_TAG_namespace
:
6634 /* FIXME: carlton/2004-01-16: Should we do this for
6635 DW_TAG_class_type/DW_TAG_structure_type, too? I think
6636 that current GCC's always emit the DIEs corresponding
6637 to definitions of methods of classes as children of a
6638 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
6639 the DIEs giving the declarations, which could be
6640 anywhere). But I don't see any reason why the
6641 standards says that they have to be there. */
6642 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
6644 if (current_low
!= ((CORE_ADDR
) -1))
6646 best_low
= min (best_low
, current_low
);
6647 best_high
= max (best_high
, current_high
);
6655 child
= sibling_die (child
);
6660 *highpc
= best_high
;
6663 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
6666 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
6667 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
6669 struct objfile
*objfile
= cu
->objfile
;
6670 struct attribute
*attr
;
6672 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6675 CORE_ADDR high
= DW_ADDR (attr
);
6677 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6680 CORE_ADDR low
= DW_ADDR (attr
);
6682 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
6686 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6689 bfd
*obfd
= objfile
->obfd
;
6691 /* The value of the DW_AT_ranges attribute is the offset of the
6692 address range list in the .debug_ranges section. */
6693 unsigned long offset
= DW_UNSND (attr
);
6694 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6696 /* For some target architectures, but not others, the
6697 read_address function sign-extends the addresses it returns.
6698 To recognize base address selection entries, we need a
6700 unsigned int addr_size
= cu
->header
.addr_size
;
6701 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6703 /* The base address, to which the next pair is relative. Note
6704 that this 'base' is a DWARF concept: most entries in a range
6705 list are relative, to reduce the number of relocs against the
6706 debugging information. This is separate from this function's
6707 'baseaddr' argument, which GDB uses to relocate debugging
6708 information from a shared library based on the address at
6709 which the library was loaded. */
6710 CORE_ADDR base
= cu
->base_address
;
6711 int base_known
= cu
->base_known
;
6713 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
6714 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6716 complaint (&symfile_complaints
,
6717 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
6724 unsigned int bytes_read
;
6725 CORE_ADDR start
, end
;
6727 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6728 buffer
+= bytes_read
;
6729 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6730 buffer
+= bytes_read
;
6732 /* Did we find the end of the range list? */
6733 if (start
== 0 && end
== 0)
6736 /* Did we find a base address selection entry? */
6737 else if ((start
& base_select_mask
) == base_select_mask
)
6743 /* We found an ordinary address range. */
6748 complaint (&symfile_complaints
,
6749 _("Invalid .debug_ranges data "
6750 "(no base address)"));
6756 /* Inverted range entries are invalid. */
6757 complaint (&symfile_complaints
,
6758 _("Invalid .debug_ranges data "
6759 "(inverted range)"));
6763 /* Empty range entries have no effect. */
6767 record_block_range (block
,
6768 baseaddr
+ base
+ start
,
6769 baseaddr
+ base
+ end
- 1);
6775 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
6776 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
6777 during 4.6.0 experimental. */
6780 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
6783 int major
, minor
, release
;
6785 if (cu
->producer
== NULL
)
6787 /* For unknown compilers expect their behavior is DWARF version
6790 GCC started to support .debug_types sections by -gdwarf-4 since
6791 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
6792 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
6793 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
6794 interpreted incorrectly by GDB now - GCC PR debug/48229. */
6799 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
6801 if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) != 0)
6803 /* For non-GCC compilers expect their behavior is DWARF version
6808 cs
= &cu
->producer
[strlen ("GNU ")];
6809 while (*cs
&& !isdigit (*cs
))
6811 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
6813 /* Not recognized as GCC. */
6818 return major
< 4 || (major
== 4 && minor
< 6);
6821 /* Return the default accessibility type if it is not overriden by
6822 DW_AT_accessibility. */
6824 static enum dwarf_access_attribute
6825 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
6827 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
6829 /* The default DWARF 2 accessibility for members is public, the default
6830 accessibility for inheritance is private. */
6832 if (die
->tag
!= DW_TAG_inheritance
)
6833 return DW_ACCESS_public
;
6835 return DW_ACCESS_private
;
6839 /* DWARF 3+ defines the default accessibility a different way. The same
6840 rules apply now for DW_TAG_inheritance as for the members and it only
6841 depends on the container kind. */
6843 if (die
->parent
->tag
== DW_TAG_class_type
)
6844 return DW_ACCESS_private
;
6846 return DW_ACCESS_public
;
6850 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
6851 offset. If the attribute was not found return 0, otherwise return
6852 1. If it was found but could not properly be handled, set *OFFSET
6856 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
6859 struct attribute
*attr
;
6861 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6866 /* Note that we do not check for a section offset first here.
6867 This is because DW_AT_data_member_location is new in DWARF 4,
6868 so if we see it, we can assume that a constant form is really
6869 a constant and not a section offset. */
6870 if (attr_form_is_constant (attr
))
6871 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
6872 else if (attr_form_is_section_offset (attr
))
6873 dwarf2_complex_location_expr_complaint ();
6874 else if (attr_form_is_block (attr
))
6875 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6877 dwarf2_complex_location_expr_complaint ();
6885 /* Add an aggregate field to the field list. */
6888 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
6889 struct dwarf2_cu
*cu
)
6891 struct objfile
*objfile
= cu
->objfile
;
6892 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6893 struct nextfield
*new_field
;
6894 struct attribute
*attr
;
6896 char *fieldname
= "";
6898 /* Allocate a new field list entry and link it in. */
6899 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
6900 make_cleanup (xfree
, new_field
);
6901 memset (new_field
, 0, sizeof (struct nextfield
));
6903 if (die
->tag
== DW_TAG_inheritance
)
6905 new_field
->next
= fip
->baseclasses
;
6906 fip
->baseclasses
= new_field
;
6910 new_field
->next
= fip
->fields
;
6911 fip
->fields
= new_field
;
6915 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6917 new_field
->accessibility
= DW_UNSND (attr
);
6919 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
6920 if (new_field
->accessibility
!= DW_ACCESS_public
)
6921 fip
->non_public_fields
= 1;
6923 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6925 new_field
->virtuality
= DW_UNSND (attr
);
6927 new_field
->virtuality
= DW_VIRTUALITY_none
;
6929 fp
= &new_field
->field
;
6931 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
6935 /* Data member other than a C++ static data member. */
6937 /* Get type of field. */
6938 fp
->type
= die_type (die
, cu
);
6940 SET_FIELD_BITPOS (*fp
, 0);
6942 /* Get bit size of field (zero if none). */
6943 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
6946 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
6950 FIELD_BITSIZE (*fp
) = 0;
6953 /* Get bit offset of field. */
6954 if (handle_data_member_location (die
, cu
, &offset
))
6955 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
6956 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
6959 if (gdbarch_bits_big_endian (gdbarch
))
6961 /* For big endian bits, the DW_AT_bit_offset gives the
6962 additional bit offset from the MSB of the containing
6963 anonymous object to the MSB of the field. We don't
6964 have to do anything special since we don't need to
6965 know the size of the anonymous object. */
6966 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
6970 /* For little endian bits, compute the bit offset to the
6971 MSB of the anonymous object, subtract off the number of
6972 bits from the MSB of the field to the MSB of the
6973 object, and then subtract off the number of bits of
6974 the field itself. The result is the bit offset of
6975 the LSB of the field. */
6977 int bit_offset
= DW_UNSND (attr
);
6979 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6982 /* The size of the anonymous object containing
6983 the bit field is explicit, so use the
6984 indicated size (in bytes). */
6985 anonymous_size
= DW_UNSND (attr
);
6989 /* The size of the anonymous object containing
6990 the bit field must be inferred from the type
6991 attribute of the data member containing the
6993 anonymous_size
= TYPE_LENGTH (fp
->type
);
6995 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
6996 - bit_offset
- FIELD_BITSIZE (*fp
);
7000 /* Get name of field. */
7001 fieldname
= dwarf2_name (die
, cu
);
7002 if (fieldname
== NULL
)
7005 /* The name is already allocated along with this objfile, so we don't
7006 need to duplicate it for the type. */
7007 fp
->name
= fieldname
;
7009 /* Change accessibility for artificial fields (e.g. virtual table
7010 pointer or virtual base class pointer) to private. */
7011 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
7013 FIELD_ARTIFICIAL (*fp
) = 1;
7014 new_field
->accessibility
= DW_ACCESS_private
;
7015 fip
->non_public_fields
= 1;
7018 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
7020 /* C++ static member. */
7022 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
7023 is a declaration, but all versions of G++ as of this writing
7024 (so through at least 3.2.1) incorrectly generate
7025 DW_TAG_variable tags. */
7027 const char *physname
;
7029 /* Get name of field. */
7030 fieldname
= dwarf2_name (die
, cu
);
7031 if (fieldname
== NULL
)
7034 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7036 /* Only create a symbol if this is an external value.
7037 new_symbol checks this and puts the value in the global symbol
7038 table, which we want. If it is not external, new_symbol
7039 will try to put the value in cu->list_in_scope which is wrong. */
7040 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
7042 /* A static const member, not much different than an enum as far as
7043 we're concerned, except that we can support more types. */
7044 new_symbol (die
, NULL
, cu
);
7047 /* Get physical name. */
7048 physname
= dwarf2_physname (fieldname
, die
, cu
);
7050 /* The name is already allocated along with this objfile, so we don't
7051 need to duplicate it for the type. */
7052 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
7053 FIELD_TYPE (*fp
) = die_type (die
, cu
);
7054 FIELD_NAME (*fp
) = fieldname
;
7056 else if (die
->tag
== DW_TAG_inheritance
)
7060 /* C++ base class field. */
7061 if (handle_data_member_location (die
, cu
, &offset
))
7062 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
7063 FIELD_BITSIZE (*fp
) = 0;
7064 FIELD_TYPE (*fp
) = die_type (die
, cu
);
7065 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
7066 fip
->nbaseclasses
++;
7070 /* Add a typedef defined in the scope of the FIP's class. */
7073 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
7074 struct dwarf2_cu
*cu
)
7076 struct objfile
*objfile
= cu
->objfile
;
7077 struct typedef_field_list
*new_field
;
7078 struct attribute
*attr
;
7079 struct typedef_field
*fp
;
7080 char *fieldname
= "";
7082 /* Allocate a new field list entry and link it in. */
7083 new_field
= xzalloc (sizeof (*new_field
));
7084 make_cleanup (xfree
, new_field
);
7086 gdb_assert (die
->tag
== DW_TAG_typedef
);
7088 fp
= &new_field
->field
;
7090 /* Get name of field. */
7091 fp
->name
= dwarf2_name (die
, cu
);
7092 if (fp
->name
== NULL
)
7095 fp
->type
= read_type_die (die
, cu
);
7097 new_field
->next
= fip
->typedef_field_list
;
7098 fip
->typedef_field_list
= new_field
;
7099 fip
->typedef_field_list_count
++;
7102 /* Create the vector of fields, and attach it to the type. */
7105 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
7106 struct dwarf2_cu
*cu
)
7108 int nfields
= fip
->nfields
;
7110 /* Record the field count, allocate space for the array of fields,
7111 and create blank accessibility bitfields if necessary. */
7112 TYPE_NFIELDS (type
) = nfields
;
7113 TYPE_FIELDS (type
) = (struct field
*)
7114 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
7115 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
7117 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
7119 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7121 TYPE_FIELD_PRIVATE_BITS (type
) =
7122 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7123 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
7125 TYPE_FIELD_PROTECTED_BITS (type
) =
7126 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7127 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
7129 TYPE_FIELD_IGNORE_BITS (type
) =
7130 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7131 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
7134 /* If the type has baseclasses, allocate and clear a bit vector for
7135 TYPE_FIELD_VIRTUAL_BITS. */
7136 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
7138 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
7139 unsigned char *pointer
;
7141 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7142 pointer
= TYPE_ALLOC (type
, num_bytes
);
7143 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
7144 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
7145 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
7148 /* Copy the saved-up fields into the field vector. Start from the head of
7149 the list, adding to the tail of the field array, so that they end up in
7150 the same order in the array in which they were added to the list. */
7151 while (nfields
-- > 0)
7153 struct nextfield
*fieldp
;
7157 fieldp
= fip
->fields
;
7158 fip
->fields
= fieldp
->next
;
7162 fieldp
= fip
->baseclasses
;
7163 fip
->baseclasses
= fieldp
->next
;
7166 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
7167 switch (fieldp
->accessibility
)
7169 case DW_ACCESS_private
:
7170 if (cu
->language
!= language_ada
)
7171 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
7174 case DW_ACCESS_protected
:
7175 if (cu
->language
!= language_ada
)
7176 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
7179 case DW_ACCESS_public
:
7183 /* Unknown accessibility. Complain and treat it as public. */
7185 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
7186 fieldp
->accessibility
);
7190 if (nfields
< fip
->nbaseclasses
)
7192 switch (fieldp
->virtuality
)
7194 case DW_VIRTUALITY_virtual
:
7195 case DW_VIRTUALITY_pure_virtual
:
7196 if (cu
->language
== language_ada
)
7197 error (_("unexpected virtuality in component of Ada type"));
7198 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
7205 /* Add a member function to the proper fieldlist. */
7208 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
7209 struct type
*type
, struct dwarf2_cu
*cu
)
7211 struct objfile
*objfile
= cu
->objfile
;
7212 struct attribute
*attr
;
7213 struct fnfieldlist
*flp
;
7215 struct fn_field
*fnp
;
7217 struct nextfnfield
*new_fnfield
;
7218 struct type
*this_type
;
7219 enum dwarf_access_attribute accessibility
;
7221 if (cu
->language
== language_ada
)
7222 error (_("unexpected member function in Ada type"));
7224 /* Get name of member function. */
7225 fieldname
= dwarf2_name (die
, cu
);
7226 if (fieldname
== NULL
)
7229 /* Look up member function name in fieldlist. */
7230 for (i
= 0; i
< fip
->nfnfields
; i
++)
7232 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
7236 /* Create new list element if necessary. */
7237 if (i
< fip
->nfnfields
)
7238 flp
= &fip
->fnfieldlists
[i
];
7241 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7243 fip
->fnfieldlists
= (struct fnfieldlist
*)
7244 xrealloc (fip
->fnfieldlists
,
7245 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
7246 * sizeof (struct fnfieldlist
));
7247 if (fip
->nfnfields
== 0)
7248 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
7250 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
7251 flp
->name
= fieldname
;
7254 i
= fip
->nfnfields
++;
7257 /* Create a new member function field and chain it to the field list
7259 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
7260 make_cleanup (xfree
, new_fnfield
);
7261 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
7262 new_fnfield
->next
= flp
->head
;
7263 flp
->head
= new_fnfield
;
7266 /* Fill in the member function field info. */
7267 fnp
= &new_fnfield
->fnfield
;
7269 /* Delay processing of the physname until later. */
7270 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
7272 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
7277 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
7278 fnp
->physname
= physname
? physname
: "";
7281 fnp
->type
= alloc_type (objfile
);
7282 this_type
= read_type_die (die
, cu
);
7283 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
7285 int nparams
= TYPE_NFIELDS (this_type
);
7287 /* TYPE is the domain of this method, and THIS_TYPE is the type
7288 of the method itself (TYPE_CODE_METHOD). */
7289 smash_to_method_type (fnp
->type
, type
,
7290 TYPE_TARGET_TYPE (this_type
),
7291 TYPE_FIELDS (this_type
),
7292 TYPE_NFIELDS (this_type
),
7293 TYPE_VARARGS (this_type
));
7295 /* Handle static member functions.
7296 Dwarf2 has no clean way to discern C++ static and non-static
7297 member functions. G++ helps GDB by marking the first
7298 parameter for non-static member functions (which is the this
7299 pointer) as artificial. We obtain this information from
7300 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
7301 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
7302 fnp
->voffset
= VOFFSET_STATIC
;
7305 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
7306 dwarf2_full_name (fieldname
, die
, cu
));
7308 /* Get fcontext from DW_AT_containing_type if present. */
7309 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7310 fnp
->fcontext
= die_containing_type (die
, cu
);
7312 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
7313 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
7315 /* Get accessibility. */
7316 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
7318 accessibility
= DW_UNSND (attr
);
7320 accessibility
= dwarf2_default_access_attribute (die
, cu
);
7321 switch (accessibility
)
7323 case DW_ACCESS_private
:
7324 fnp
->is_private
= 1;
7326 case DW_ACCESS_protected
:
7327 fnp
->is_protected
= 1;
7331 /* Check for artificial methods. */
7332 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
7333 if (attr
&& DW_UNSND (attr
) != 0)
7334 fnp
->is_artificial
= 1;
7336 /* Get index in virtual function table if it is a virtual member
7337 function. For older versions of GCC, this is an offset in the
7338 appropriate virtual table, as specified by DW_AT_containing_type.
7339 For everyone else, it is an expression to be evaluated relative
7340 to the object address. */
7342 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
7345 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
7347 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
7349 /* Old-style GCC. */
7350 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
7352 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
7353 || (DW_BLOCK (attr
)->size
> 1
7354 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
7355 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
7357 struct dwarf_block blk
;
7360 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
7362 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
7363 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
7364 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
7365 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
7366 dwarf2_complex_location_expr_complaint ();
7368 fnp
->voffset
/= cu
->header
.addr_size
;
7372 dwarf2_complex_location_expr_complaint ();
7375 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
7377 else if (attr_form_is_section_offset (attr
))
7379 dwarf2_complex_location_expr_complaint ();
7383 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
7389 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
7390 if (attr
&& DW_UNSND (attr
))
7392 /* GCC does this, as of 2008-08-25; PR debug/37237. */
7393 complaint (&symfile_complaints
,
7394 _("Member function \"%s\" (offset %d) is virtual "
7395 "but the vtable offset is not specified"),
7396 fieldname
, die
->offset
);
7397 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7398 TYPE_CPLUS_DYNAMIC (type
) = 1;
7403 /* Create the vector of member function fields, and attach it to the type. */
7406 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
7407 struct dwarf2_cu
*cu
)
7409 struct fnfieldlist
*flp
;
7412 if (cu
->language
== language_ada
)
7413 error (_("unexpected member functions in Ada type"));
7415 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7416 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
7417 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
7419 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
7421 struct nextfnfield
*nfp
= flp
->head
;
7422 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
7425 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
7426 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
7427 fn_flp
->fn_fields
= (struct fn_field
*)
7428 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
7429 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
7430 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
7433 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
7436 /* Returns non-zero if NAME is the name of a vtable member in CU's
7437 language, zero otherwise. */
7439 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
7441 static const char vptr
[] = "_vptr";
7442 static const char vtable
[] = "vtable";
7444 /* Look for the C++ and Java forms of the vtable. */
7445 if ((cu
->language
== language_java
7446 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
7447 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
7448 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
7454 /* GCC outputs unnamed structures that are really pointers to member
7455 functions, with the ABI-specified layout. If TYPE describes
7456 such a structure, smash it into a member function type.
7458 GCC shouldn't do this; it should just output pointer to member DIEs.
7459 This is GCC PR debug/28767. */
7462 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
7464 struct type
*pfn_type
, *domain_type
, *new_type
;
7466 /* Check for a structure with no name and two children. */
7467 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
7470 /* Check for __pfn and __delta members. */
7471 if (TYPE_FIELD_NAME (type
, 0) == NULL
7472 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
7473 || TYPE_FIELD_NAME (type
, 1) == NULL
7474 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
7477 /* Find the type of the method. */
7478 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
7479 if (pfn_type
== NULL
7480 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
7481 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
7484 /* Look for the "this" argument. */
7485 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
7486 if (TYPE_NFIELDS (pfn_type
) == 0
7487 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
7488 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
7491 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
7492 new_type
= alloc_type (objfile
);
7493 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
7494 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
7495 TYPE_VARARGS (pfn_type
));
7496 smash_to_methodptr_type (type
, new_type
);
7499 /* Called when we find the DIE that starts a structure or union scope
7500 (definition) to create a type for the structure or union. Fill in
7501 the type's name and general properties; the members will not be
7502 processed until process_structure_type.
7504 NOTE: we need to call these functions regardless of whether or not the
7505 DIE has a DW_AT_name attribute, since it might be an anonymous
7506 structure or union. This gets the type entered into our set of
7509 However, if the structure is incomplete (an opaque struct/union)
7510 then suppress creating a symbol table entry for it since gdb only
7511 wants to find the one with the complete definition. Note that if
7512 it is complete, we just call new_symbol, which does it's own
7513 checking about whether the struct/union is anonymous or not (and
7514 suppresses creating a symbol table entry itself). */
7516 static struct type
*
7517 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7519 struct objfile
*objfile
= cu
->objfile
;
7521 struct attribute
*attr
;
7524 /* If the definition of this type lives in .debug_types, read that type.
7525 Don't follow DW_AT_specification though, that will take us back up
7526 the chain and we want to go down. */
7527 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7530 struct dwarf2_cu
*type_cu
= cu
;
7531 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7533 /* We could just recurse on read_structure_type, but we need to call
7534 get_die_type to ensure only one type for this DIE is created.
7535 This is important, for example, because for c++ classes we need
7536 TYPE_NAME set which is only done by new_symbol. Blech. */
7537 type
= read_type_die (type_die
, type_cu
);
7539 /* TYPE_CU may not be the same as CU.
7540 Ensure TYPE is recorded in CU's type_hash table. */
7541 return set_die_type (die
, type
, cu
);
7544 type
= alloc_type (objfile
);
7545 INIT_CPLUS_SPECIFIC (type
);
7547 name
= dwarf2_name (die
, cu
);
7550 if (cu
->language
== language_cplus
7551 || cu
->language
== language_java
)
7553 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
7555 /* dwarf2_full_name might have already finished building the DIE's
7556 type. If so, there is no need to continue. */
7557 if (get_die_type (die
, cu
) != NULL
)
7558 return get_die_type (die
, cu
);
7560 TYPE_TAG_NAME (type
) = full_name
;
7561 if (die
->tag
== DW_TAG_structure_type
7562 || die
->tag
== DW_TAG_class_type
)
7563 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7567 /* The name is already allocated along with this objfile, so
7568 we don't need to duplicate it for the type. */
7569 TYPE_TAG_NAME (type
) = (char *) name
;
7570 if (die
->tag
== DW_TAG_class_type
)
7571 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7575 if (die
->tag
== DW_TAG_structure_type
)
7577 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
7579 else if (die
->tag
== DW_TAG_union_type
)
7581 TYPE_CODE (type
) = TYPE_CODE_UNION
;
7585 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
7588 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
7589 TYPE_DECLARED_CLASS (type
) = 1;
7591 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7594 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7598 TYPE_LENGTH (type
) = 0;
7601 TYPE_STUB_SUPPORTED (type
) = 1;
7602 if (die_is_declaration (die
, cu
))
7603 TYPE_STUB (type
) = 1;
7604 else if (attr
== NULL
&& die
->child
== NULL
7605 && producer_is_realview (cu
->producer
))
7606 /* RealView does not output the required DW_AT_declaration
7607 on incomplete types. */
7608 TYPE_STUB (type
) = 1;
7610 /* We need to add the type field to the die immediately so we don't
7611 infinitely recurse when dealing with pointers to the structure
7612 type within the structure itself. */
7613 set_die_type (die
, type
, cu
);
7615 /* set_die_type should be already done. */
7616 set_descriptive_type (type
, die
, cu
);
7621 /* Finish creating a structure or union type, including filling in
7622 its members and creating a symbol for it. */
7625 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7627 struct objfile
*objfile
= cu
->objfile
;
7628 struct die_info
*child_die
= die
->child
;
7631 type
= get_die_type (die
, cu
);
7633 type
= read_structure_type (die
, cu
);
7635 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
7637 struct field_info fi
;
7638 struct die_info
*child_die
;
7639 VEC (symbolp
) *template_args
= NULL
;
7640 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
7642 memset (&fi
, 0, sizeof (struct field_info
));
7644 child_die
= die
->child
;
7646 while (child_die
&& child_die
->tag
)
7648 if (child_die
->tag
== DW_TAG_member
7649 || child_die
->tag
== DW_TAG_variable
)
7651 /* NOTE: carlton/2002-11-05: A C++ static data member
7652 should be a DW_TAG_member that is a declaration, but
7653 all versions of G++ as of this writing (so through at
7654 least 3.2.1) incorrectly generate DW_TAG_variable
7655 tags for them instead. */
7656 dwarf2_add_field (&fi
, child_die
, cu
);
7658 else if (child_die
->tag
== DW_TAG_subprogram
)
7660 /* C++ member function. */
7661 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
7663 else if (child_die
->tag
== DW_TAG_inheritance
)
7665 /* C++ base class field. */
7666 dwarf2_add_field (&fi
, child_die
, cu
);
7668 else if (child_die
->tag
== DW_TAG_typedef
)
7669 dwarf2_add_typedef (&fi
, child_die
, cu
);
7670 else if (child_die
->tag
== DW_TAG_template_type_param
7671 || child_die
->tag
== DW_TAG_template_value_param
)
7673 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
7676 VEC_safe_push (symbolp
, template_args
, arg
);
7679 child_die
= sibling_die (child_die
);
7682 /* Attach template arguments to type. */
7683 if (! VEC_empty (symbolp
, template_args
))
7685 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7686 TYPE_N_TEMPLATE_ARGUMENTS (type
)
7687 = VEC_length (symbolp
, template_args
);
7688 TYPE_TEMPLATE_ARGUMENTS (type
)
7689 = obstack_alloc (&objfile
->objfile_obstack
,
7690 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7691 * sizeof (struct symbol
*)));
7692 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
7693 VEC_address (symbolp
, template_args
),
7694 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7695 * sizeof (struct symbol
*)));
7696 VEC_free (symbolp
, template_args
);
7699 /* Attach fields and member functions to the type. */
7701 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
7704 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
7706 /* Get the type which refers to the base class (possibly this
7707 class itself) which contains the vtable pointer for the current
7708 class from the DW_AT_containing_type attribute. This use of
7709 DW_AT_containing_type is a GNU extension. */
7711 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7713 struct type
*t
= die_containing_type (die
, cu
);
7715 TYPE_VPTR_BASETYPE (type
) = t
;
7720 /* Our own class provides vtbl ptr. */
7721 for (i
= TYPE_NFIELDS (t
) - 1;
7722 i
>= TYPE_N_BASECLASSES (t
);
7725 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
7727 if (is_vtable_name (fieldname
, cu
))
7729 TYPE_VPTR_FIELDNO (type
) = i
;
7734 /* Complain if virtual function table field not found. */
7735 if (i
< TYPE_N_BASECLASSES (t
))
7736 complaint (&symfile_complaints
,
7737 _("virtual function table pointer "
7738 "not found when defining class '%s'"),
7739 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
7744 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
7747 else if (cu
->producer
7748 && strncmp (cu
->producer
,
7749 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
7751 /* The IBM XLC compiler does not provide direct indication
7752 of the containing type, but the vtable pointer is
7753 always named __vfp. */
7757 for (i
= TYPE_NFIELDS (type
) - 1;
7758 i
>= TYPE_N_BASECLASSES (type
);
7761 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
7763 TYPE_VPTR_FIELDNO (type
) = i
;
7764 TYPE_VPTR_BASETYPE (type
) = type
;
7771 /* Copy fi.typedef_field_list linked list elements content into the
7772 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
7773 if (fi
.typedef_field_list
)
7775 int i
= fi
.typedef_field_list_count
;
7777 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7778 TYPE_TYPEDEF_FIELD_ARRAY (type
)
7779 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
7780 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
7782 /* Reverse the list order to keep the debug info elements order. */
7785 struct typedef_field
*dest
, *src
;
7787 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
7788 src
= &fi
.typedef_field_list
->field
;
7789 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
7794 do_cleanups (back_to
);
7796 if (HAVE_CPLUS_STRUCT (type
))
7797 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
7800 quirk_gcc_member_function_pointer (type
, objfile
);
7802 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
7803 snapshots) has been known to create a die giving a declaration
7804 for a class that has, as a child, a die giving a definition for a
7805 nested class. So we have to process our children even if the
7806 current die is a declaration. Normally, of course, a declaration
7807 won't have any children at all. */
7809 while (child_die
!= NULL
&& child_die
->tag
)
7811 if (child_die
->tag
== DW_TAG_member
7812 || child_die
->tag
== DW_TAG_variable
7813 || child_die
->tag
== DW_TAG_inheritance
7814 || child_die
->tag
== DW_TAG_template_value_param
7815 || child_die
->tag
== DW_TAG_template_type_param
)
7820 process_die (child_die
, cu
);
7822 child_die
= sibling_die (child_die
);
7825 /* Do not consider external references. According to the DWARF standard,
7826 these DIEs are identified by the fact that they have no byte_size
7827 attribute, and a declaration attribute. */
7828 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
7829 || !die_is_declaration (die
, cu
))
7830 new_symbol (die
, type
, cu
);
7833 /* Given a DW_AT_enumeration_type die, set its type. We do not
7834 complete the type's fields yet, or create any symbols. */
7836 static struct type
*
7837 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7839 struct objfile
*objfile
= cu
->objfile
;
7841 struct attribute
*attr
;
7844 /* If the definition of this type lives in .debug_types, read that type.
7845 Don't follow DW_AT_specification though, that will take us back up
7846 the chain and we want to go down. */
7847 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7850 struct dwarf2_cu
*type_cu
= cu
;
7851 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7853 type
= read_type_die (type_die
, type_cu
);
7855 /* TYPE_CU may not be the same as CU.
7856 Ensure TYPE is recorded in CU's type_hash table. */
7857 return set_die_type (die
, type
, cu
);
7860 type
= alloc_type (objfile
);
7862 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
7863 name
= dwarf2_full_name (NULL
, die
, cu
);
7865 TYPE_TAG_NAME (type
) = (char *) name
;
7867 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7870 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7874 TYPE_LENGTH (type
) = 0;
7877 /* The enumeration DIE can be incomplete. In Ada, any type can be
7878 declared as private in the package spec, and then defined only
7879 inside the package body. Such types are known as Taft Amendment
7880 Types. When another package uses such a type, an incomplete DIE
7881 may be generated by the compiler. */
7882 if (die_is_declaration (die
, cu
))
7883 TYPE_STUB (type
) = 1;
7885 return set_die_type (die
, type
, cu
);
7888 /* Given a pointer to a die which begins an enumeration, process all
7889 the dies that define the members of the enumeration, and create the
7890 symbol for the enumeration type.
7892 NOTE: We reverse the order of the element list. */
7895 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7897 struct type
*this_type
;
7899 this_type
= get_die_type (die
, cu
);
7900 if (this_type
== NULL
)
7901 this_type
= read_enumeration_type (die
, cu
);
7903 if (die
->child
!= NULL
)
7905 struct die_info
*child_die
;
7907 struct field
*fields
= NULL
;
7909 int unsigned_enum
= 1;
7914 child_die
= die
->child
;
7915 while (child_die
&& child_die
->tag
)
7917 if (child_die
->tag
!= DW_TAG_enumerator
)
7919 process_die (child_die
, cu
);
7923 name
= dwarf2_name (child_die
, cu
);
7926 sym
= new_symbol (child_die
, this_type
, cu
);
7927 if (SYMBOL_VALUE (sym
) < 0)
7932 else if ((mask
& SYMBOL_VALUE (sym
)) != 0)
7935 mask
|= SYMBOL_VALUE (sym
);
7937 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7939 fields
= (struct field
*)
7941 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
7942 * sizeof (struct field
));
7945 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
7946 FIELD_TYPE (fields
[num_fields
]) = NULL
;
7947 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
7948 FIELD_BITSIZE (fields
[num_fields
]) = 0;
7954 child_die
= sibling_die (child_die
);
7959 TYPE_NFIELDS (this_type
) = num_fields
;
7960 TYPE_FIELDS (this_type
) = (struct field
*)
7961 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
7962 memcpy (TYPE_FIELDS (this_type
), fields
,
7963 sizeof (struct field
) * num_fields
);
7967 TYPE_UNSIGNED (this_type
) = 1;
7969 TYPE_FLAG_ENUM (this_type
) = 1;
7972 /* If we are reading an enum from a .debug_types unit, and the enum
7973 is a declaration, and the enum is not the signatured type in the
7974 unit, then we do not want to add a symbol for it. Adding a
7975 symbol would in some cases obscure the true definition of the
7976 enum, giving users an incomplete type when the definition is
7977 actually available. Note that we do not want to do this for all
7978 enums which are just declarations, because C++0x allows forward
7979 enum declarations. */
7980 if (cu
->per_cu
->debug_types_section
7981 && die_is_declaration (die
, cu
))
7983 struct signatured_type
*type_sig
;
7986 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
7987 cu
->per_cu
->debug_types_section
,
7988 cu
->per_cu
->offset
);
7989 if (type_sig
->type_offset
!= die
->offset
)
7993 new_symbol (die
, this_type
, cu
);
7996 /* Extract all information from a DW_TAG_array_type DIE and put it in
7997 the DIE's type field. For now, this only handles one dimensional
8000 static struct type
*
8001 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8003 struct objfile
*objfile
= cu
->objfile
;
8004 struct die_info
*child_die
;
8006 struct type
*element_type
, *range_type
, *index_type
;
8007 struct type
**range_types
= NULL
;
8008 struct attribute
*attr
;
8010 struct cleanup
*back_to
;
8013 element_type
= die_type (die
, cu
);
8015 /* The die_type call above may have already set the type for this DIE. */
8016 type
= get_die_type (die
, cu
);
8020 /* Irix 6.2 native cc creates array types without children for
8021 arrays with unspecified length. */
8022 if (die
->child
== NULL
)
8024 index_type
= objfile_type (objfile
)->builtin_int
;
8025 range_type
= create_range_type (NULL
, index_type
, 0, -1);
8026 type
= create_array_type (NULL
, element_type
, range_type
);
8027 return set_die_type (die
, type
, cu
);
8030 back_to
= make_cleanup (null_cleanup
, NULL
);
8031 child_die
= die
->child
;
8032 while (child_die
&& child_die
->tag
)
8034 if (child_die
->tag
== DW_TAG_subrange_type
)
8036 struct type
*child_type
= read_type_die (child_die
, cu
);
8038 if (child_type
!= NULL
)
8040 /* The range type was succesfully read. Save it for the
8041 array type creation. */
8042 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
8044 range_types
= (struct type
**)
8045 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
8046 * sizeof (struct type
*));
8048 make_cleanup (free_current_contents
, &range_types
);
8050 range_types
[ndim
++] = child_type
;
8053 child_die
= sibling_die (child_die
);
8056 /* Dwarf2 dimensions are output from left to right, create the
8057 necessary array types in backwards order. */
8059 type
= element_type
;
8061 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
8066 type
= create_array_type (NULL
, type
, range_types
[i
++]);
8071 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
8074 /* Understand Dwarf2 support for vector types (like they occur on
8075 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
8076 array type. This is not part of the Dwarf2/3 standard yet, but a
8077 custom vendor extension. The main difference between a regular
8078 array and the vector variant is that vectors are passed by value
8080 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
8082 make_vector_type (type
);
8084 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
8085 implementation may choose to implement triple vectors using this
8087 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8090 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
8091 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8093 complaint (&symfile_complaints
,
8094 _("DW_AT_byte_size for array type smaller "
8095 "than the total size of elements"));
8098 name
= dwarf2_name (die
, cu
);
8100 TYPE_NAME (type
) = name
;
8102 /* Install the type in the die. */
8103 set_die_type (die
, type
, cu
);
8105 /* set_die_type should be already done. */
8106 set_descriptive_type (type
, die
, cu
);
8108 do_cleanups (back_to
);
8113 static enum dwarf_array_dim_ordering
8114 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
8116 struct attribute
*attr
;
8118 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
8120 if (attr
) return DW_SND (attr
);
8122 /* GNU F77 is a special case, as at 08/2004 array type info is the
8123 opposite order to the dwarf2 specification, but data is still
8124 laid out as per normal fortran.
8126 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
8127 version checking. */
8129 if (cu
->language
== language_fortran
8130 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
8132 return DW_ORD_row_major
;
8135 switch (cu
->language_defn
->la_array_ordering
)
8137 case array_column_major
:
8138 return DW_ORD_col_major
;
8139 case array_row_major
:
8141 return DW_ORD_row_major
;
8145 /* Extract all information from a DW_TAG_set_type DIE and put it in
8146 the DIE's type field. */
8148 static struct type
*
8149 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8151 struct type
*domain_type
, *set_type
;
8152 struct attribute
*attr
;
8154 domain_type
= die_type (die
, cu
);
8156 /* The die_type call above may have already set the type for this DIE. */
8157 set_type
= get_die_type (die
, cu
);
8161 set_type
= create_set_type (NULL
, domain_type
);
8163 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8165 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
8167 return set_die_type (die
, set_type
, cu
);
8170 /* First cut: install each common block member as a global variable. */
8173 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
8175 struct die_info
*child_die
;
8176 struct attribute
*attr
;
8178 CORE_ADDR base
= (CORE_ADDR
) 0;
8180 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
8183 /* Support the .debug_loc offsets. */
8184 if (attr_form_is_block (attr
))
8186 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
8188 else if (attr_form_is_section_offset (attr
))
8190 dwarf2_complex_location_expr_complaint ();
8194 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
8195 "common block member");
8198 if (die
->child
!= NULL
)
8200 child_die
= die
->child
;
8201 while (child_die
&& child_die
->tag
)
8205 sym
= new_symbol (child_die
, NULL
, cu
);
8207 && handle_data_member_location (child_die
, cu
, &offset
))
8209 SYMBOL_VALUE_ADDRESS (sym
) = base
+ offset
;
8210 add_symbol_to_list (sym
, &global_symbols
);
8212 child_die
= sibling_die (child_die
);
8217 /* Create a type for a C++ namespace. */
8219 static struct type
*
8220 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8222 struct objfile
*objfile
= cu
->objfile
;
8223 const char *previous_prefix
, *name
;
8227 /* For extensions, reuse the type of the original namespace. */
8228 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
8230 struct die_info
*ext_die
;
8231 struct dwarf2_cu
*ext_cu
= cu
;
8233 ext_die
= dwarf2_extension (die
, &ext_cu
);
8234 type
= read_type_die (ext_die
, ext_cu
);
8236 /* EXT_CU may not be the same as CU.
8237 Ensure TYPE is recorded in CU's type_hash table. */
8238 return set_die_type (die
, type
, cu
);
8241 name
= namespace_name (die
, &is_anonymous
, cu
);
8243 /* Now build the name of the current namespace. */
8245 previous_prefix
= determine_prefix (die
, cu
);
8246 if (previous_prefix
[0] != '\0')
8247 name
= typename_concat (&objfile
->objfile_obstack
,
8248 previous_prefix
, name
, 0, cu
);
8250 /* Create the type. */
8251 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
8253 TYPE_NAME (type
) = (char *) name
;
8254 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8256 return set_die_type (die
, type
, cu
);
8259 /* Read a C++ namespace. */
8262 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
8264 struct objfile
*objfile
= cu
->objfile
;
8267 /* Add a symbol associated to this if we haven't seen the namespace
8268 before. Also, add a using directive if it's an anonymous
8271 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
8275 type
= read_type_die (die
, cu
);
8276 new_symbol (die
, type
, cu
);
8278 namespace_name (die
, &is_anonymous
, cu
);
8281 const char *previous_prefix
= determine_prefix (die
, cu
);
8283 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
8284 NULL
, NULL
, &objfile
->objfile_obstack
);
8288 if (die
->child
!= NULL
)
8290 struct die_info
*child_die
= die
->child
;
8292 while (child_die
&& child_die
->tag
)
8294 process_die (child_die
, cu
);
8295 child_die
= sibling_die (child_die
);
8300 /* Read a Fortran module as type. This DIE can be only a declaration used for
8301 imported module. Still we need that type as local Fortran "use ... only"
8302 declaration imports depend on the created type in determine_prefix. */
8304 static struct type
*
8305 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8307 struct objfile
*objfile
= cu
->objfile
;
8311 module_name
= dwarf2_name (die
, cu
);
8313 complaint (&symfile_complaints
,
8314 _("DW_TAG_module has no name, offset 0x%x"),
8316 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
8318 /* determine_prefix uses TYPE_TAG_NAME. */
8319 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8321 return set_die_type (die
, type
, cu
);
8324 /* Read a Fortran module. */
8327 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
8329 struct die_info
*child_die
= die
->child
;
8331 while (child_die
&& child_die
->tag
)
8333 process_die (child_die
, cu
);
8334 child_die
= sibling_die (child_die
);
8338 /* Return the name of the namespace represented by DIE. Set
8339 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
8343 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
8345 struct die_info
*current_die
;
8346 const char *name
= NULL
;
8348 /* Loop through the extensions until we find a name. */
8350 for (current_die
= die
;
8351 current_die
!= NULL
;
8352 current_die
= dwarf2_extension (die
, &cu
))
8354 name
= dwarf2_name (current_die
, cu
);
8359 /* Is it an anonymous namespace? */
8361 *is_anonymous
= (name
== NULL
);
8363 name
= CP_ANONYMOUS_NAMESPACE_STR
;
8368 /* Extract all information from a DW_TAG_pointer_type DIE and add to
8369 the user defined type vector. */
8371 static struct type
*
8372 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8374 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
8375 struct comp_unit_head
*cu_header
= &cu
->header
;
8377 struct attribute
*attr_byte_size
;
8378 struct attribute
*attr_address_class
;
8379 int byte_size
, addr_class
;
8380 struct type
*target_type
;
8382 target_type
= die_type (die
, cu
);
8384 /* The die_type call above may have already set the type for this DIE. */
8385 type
= get_die_type (die
, cu
);
8389 type
= lookup_pointer_type (target_type
);
8391 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8393 byte_size
= DW_UNSND (attr_byte_size
);
8395 byte_size
= cu_header
->addr_size
;
8397 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
8398 if (attr_address_class
)
8399 addr_class
= DW_UNSND (attr_address_class
);
8401 addr_class
= DW_ADDR_none
;
8403 /* If the pointer size or address class is different than the
8404 default, create a type variant marked as such and set the
8405 length accordingly. */
8406 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
8408 if (gdbarch_address_class_type_flags_p (gdbarch
))
8412 type_flags
= gdbarch_address_class_type_flags
8413 (gdbarch
, byte_size
, addr_class
);
8414 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
8416 type
= make_type_with_address_space (type
, type_flags
);
8418 else if (TYPE_LENGTH (type
) != byte_size
)
8420 complaint (&symfile_complaints
,
8421 _("invalid pointer size %d"), byte_size
);
8425 /* Should we also complain about unhandled address classes? */
8429 TYPE_LENGTH (type
) = byte_size
;
8430 return set_die_type (die
, type
, cu
);
8433 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
8434 the user defined type vector. */
8436 static struct type
*
8437 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8440 struct type
*to_type
;
8441 struct type
*domain
;
8443 to_type
= die_type (die
, cu
);
8444 domain
= die_containing_type (die
, cu
);
8446 /* The calls above may have already set the type for this DIE. */
8447 type
= get_die_type (die
, cu
);
8451 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
8452 type
= lookup_methodptr_type (to_type
);
8454 type
= lookup_memberptr_type (to_type
, domain
);
8456 return set_die_type (die
, type
, cu
);
8459 /* Extract all information from a DW_TAG_reference_type DIE and add to
8460 the user defined type vector. */
8462 static struct type
*
8463 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8465 struct comp_unit_head
*cu_header
= &cu
->header
;
8466 struct type
*type
, *target_type
;
8467 struct attribute
*attr
;
8469 target_type
= die_type (die
, cu
);
8471 /* The die_type call above may have already set the type for this DIE. */
8472 type
= get_die_type (die
, cu
);
8476 type
= lookup_reference_type (target_type
);
8477 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8480 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8484 TYPE_LENGTH (type
) = cu_header
->addr_size
;
8486 return set_die_type (die
, type
, cu
);
8489 static struct type
*
8490 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8492 struct type
*base_type
, *cv_type
;
8494 base_type
= die_type (die
, cu
);
8496 /* The die_type call above may have already set the type for this DIE. */
8497 cv_type
= get_die_type (die
, cu
);
8501 /* In case the const qualifier is applied to an array type, the element type
8502 is so qualified, not the array type (section 6.7.3 of C99). */
8503 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
8505 struct type
*el_type
, *inner_array
;
8507 base_type
= copy_type (base_type
);
8508 inner_array
= base_type
;
8510 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
8512 TYPE_TARGET_TYPE (inner_array
) =
8513 copy_type (TYPE_TARGET_TYPE (inner_array
));
8514 inner_array
= TYPE_TARGET_TYPE (inner_array
);
8517 el_type
= TYPE_TARGET_TYPE (inner_array
);
8518 TYPE_TARGET_TYPE (inner_array
) =
8519 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
8521 return set_die_type (die
, base_type
, cu
);
8524 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
8525 return set_die_type (die
, cv_type
, cu
);
8528 static struct type
*
8529 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8531 struct type
*base_type
, *cv_type
;
8533 base_type
= die_type (die
, cu
);
8535 /* The die_type call above may have already set the type for this DIE. */
8536 cv_type
= get_die_type (die
, cu
);
8540 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
8541 return set_die_type (die
, cv_type
, cu
);
8544 /* Extract all information from a DW_TAG_string_type DIE and add to
8545 the user defined type vector. It isn't really a user defined type,
8546 but it behaves like one, with other DIE's using an AT_user_def_type
8547 attribute to reference it. */
8549 static struct type
*
8550 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8552 struct objfile
*objfile
= cu
->objfile
;
8553 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8554 struct type
*type
, *range_type
, *index_type
, *char_type
;
8555 struct attribute
*attr
;
8556 unsigned int length
;
8558 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
8561 length
= DW_UNSND (attr
);
8565 /* Check for the DW_AT_byte_size attribute. */
8566 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8569 length
= DW_UNSND (attr
);
8577 index_type
= objfile_type (objfile
)->builtin_int
;
8578 range_type
= create_range_type (NULL
, index_type
, 1, length
);
8579 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
8580 type
= create_string_type (NULL
, char_type
, range_type
);
8582 return set_die_type (die
, type
, cu
);
8585 /* Handle DIES due to C code like:
8589 int (*funcp)(int a, long l);
8593 ('funcp' generates a DW_TAG_subroutine_type DIE). */
8595 static struct type
*
8596 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8598 struct objfile
*objfile
= cu
->objfile
;
8599 struct type
*type
; /* Type that this function returns. */
8600 struct type
*ftype
; /* Function that returns above type. */
8601 struct attribute
*attr
;
8603 type
= die_type (die
, cu
);
8605 /* The die_type call above may have already set the type for this DIE. */
8606 ftype
= get_die_type (die
, cu
);
8610 ftype
= lookup_function_type (type
);
8612 /* All functions in C++, Pascal and Java have prototypes. */
8613 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
8614 if ((attr
&& (DW_UNSND (attr
) != 0))
8615 || cu
->language
== language_cplus
8616 || cu
->language
== language_java
8617 || cu
->language
== language_pascal
)
8618 TYPE_PROTOTYPED (ftype
) = 1;
8619 else if (producer_is_realview (cu
->producer
))
8620 /* RealView does not emit DW_AT_prototyped. We can not
8621 distinguish prototyped and unprototyped functions; default to
8622 prototyped, since that is more common in modern code (and
8623 RealView warns about unprototyped functions). */
8624 TYPE_PROTOTYPED (ftype
) = 1;
8626 /* Store the calling convention in the type if it's available in
8627 the subroutine die. Otherwise set the calling convention to
8628 the default value DW_CC_normal. */
8629 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
8631 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
8632 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
8633 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
8635 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
8637 /* We need to add the subroutine type to the die immediately so
8638 we don't infinitely recurse when dealing with parameters
8639 declared as the same subroutine type. */
8640 set_die_type (die
, ftype
, cu
);
8642 if (die
->child
!= NULL
)
8644 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
8645 struct die_info
*child_die
;
8646 int nparams
, iparams
;
8648 /* Count the number of parameters.
8649 FIXME: GDB currently ignores vararg functions, but knows about
8650 vararg member functions. */
8652 child_die
= die
->child
;
8653 while (child_die
&& child_die
->tag
)
8655 if (child_die
->tag
== DW_TAG_formal_parameter
)
8657 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
8658 TYPE_VARARGS (ftype
) = 1;
8659 child_die
= sibling_die (child_die
);
8662 /* Allocate storage for parameters and fill them in. */
8663 TYPE_NFIELDS (ftype
) = nparams
;
8664 TYPE_FIELDS (ftype
) = (struct field
*)
8665 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
8667 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
8668 even if we error out during the parameters reading below. */
8669 for (iparams
= 0; iparams
< nparams
; iparams
++)
8670 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
8673 child_die
= die
->child
;
8674 while (child_die
&& child_die
->tag
)
8676 if (child_die
->tag
== DW_TAG_formal_parameter
)
8678 struct type
*arg_type
;
8680 /* DWARF version 2 has no clean way to discern C++
8681 static and non-static member functions. G++ helps
8682 GDB by marking the first parameter for non-static
8683 member functions (which is the this pointer) as
8684 artificial. We pass this information to
8685 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
8687 DWARF version 3 added DW_AT_object_pointer, which GCC
8688 4.5 does not yet generate. */
8689 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
8691 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
8694 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
8696 /* GCC/43521: In java, the formal parameter
8697 "this" is sometimes not marked with DW_AT_artificial. */
8698 if (cu
->language
== language_java
)
8700 const char *name
= dwarf2_name (child_die
, cu
);
8702 if (name
&& !strcmp (name
, "this"))
8703 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
8706 arg_type
= die_type (child_die
, cu
);
8708 /* RealView does not mark THIS as const, which the testsuite
8709 expects. GCC marks THIS as const in method definitions,
8710 but not in the class specifications (GCC PR 43053). */
8711 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
8712 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
8715 struct dwarf2_cu
*arg_cu
= cu
;
8716 const char *name
= dwarf2_name (child_die
, cu
);
8718 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
8721 /* If the compiler emits this, use it. */
8722 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
8725 else if (name
&& strcmp (name
, "this") == 0)
8726 /* Function definitions will have the argument names. */
8728 else if (name
== NULL
&& iparams
== 0)
8729 /* Declarations may not have the names, so like
8730 elsewhere in GDB, assume an artificial first
8731 argument is "this". */
8735 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
8739 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
8742 child_die
= sibling_die (child_die
);
8749 static struct type
*
8750 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
8752 struct objfile
*objfile
= cu
->objfile
;
8753 const char *name
= NULL
;
8754 struct type
*this_type
, *target_type
;
8756 name
= dwarf2_full_name (NULL
, die
, cu
);
8757 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
8758 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
8759 TYPE_NAME (this_type
) = (char *) name
;
8760 set_die_type (die
, this_type
, cu
);
8761 target_type
= die_type (die
, cu
);
8762 if (target_type
!= this_type
)
8763 TYPE_TARGET_TYPE (this_type
) = target_type
;
8766 /* Self-referential typedefs are, it seems, not allowed by the DWARF
8767 spec and cause infinite loops in GDB. */
8768 complaint (&symfile_complaints
,
8769 _("Self-referential DW_TAG_typedef "
8770 "- DIE at 0x%x [in module %s]"),
8771 die
->offset
, objfile
->name
);
8772 TYPE_TARGET_TYPE (this_type
) = NULL
;
8777 /* Find a representation of a given base type and install
8778 it in the TYPE field of the die. */
8780 static struct type
*
8781 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8783 struct objfile
*objfile
= cu
->objfile
;
8785 struct attribute
*attr
;
8786 int encoding
= 0, size
= 0;
8788 enum type_code code
= TYPE_CODE_INT
;
8790 struct type
*target_type
= NULL
;
8792 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
8795 encoding
= DW_UNSND (attr
);
8797 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8800 size
= DW_UNSND (attr
);
8802 name
= dwarf2_name (die
, cu
);
8805 complaint (&symfile_complaints
,
8806 _("DW_AT_name missing from DW_TAG_base_type"));
8811 case DW_ATE_address
:
8812 /* Turn DW_ATE_address into a void * pointer. */
8813 code
= TYPE_CODE_PTR
;
8814 type_flags
|= TYPE_FLAG_UNSIGNED
;
8815 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
8817 case DW_ATE_boolean
:
8818 code
= TYPE_CODE_BOOL
;
8819 type_flags
|= TYPE_FLAG_UNSIGNED
;
8821 case DW_ATE_complex_float
:
8822 code
= TYPE_CODE_COMPLEX
;
8823 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
8825 case DW_ATE_decimal_float
:
8826 code
= TYPE_CODE_DECFLOAT
;
8829 code
= TYPE_CODE_FLT
;
8833 case DW_ATE_unsigned
:
8834 type_flags
|= TYPE_FLAG_UNSIGNED
;
8835 if (cu
->language
== language_fortran
8837 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
8838 code
= TYPE_CODE_CHAR
;
8840 case DW_ATE_signed_char
:
8841 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8842 || cu
->language
== language_pascal
8843 || cu
->language
== language_fortran
)
8844 code
= TYPE_CODE_CHAR
;
8846 case DW_ATE_unsigned_char
:
8847 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8848 || cu
->language
== language_pascal
8849 || cu
->language
== language_fortran
)
8850 code
= TYPE_CODE_CHAR
;
8851 type_flags
|= TYPE_FLAG_UNSIGNED
;
8854 /* We just treat this as an integer and then recognize the
8855 type by name elsewhere. */
8859 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
8860 dwarf_type_encoding_name (encoding
));
8864 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
8865 TYPE_NAME (type
) = name
;
8866 TYPE_TARGET_TYPE (type
) = target_type
;
8868 if (name
&& strcmp (name
, "char") == 0)
8869 TYPE_NOSIGN (type
) = 1;
8871 return set_die_type (die
, type
, cu
);
8874 /* Read the given DW_AT_subrange DIE. */
8876 static struct type
*
8877 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8879 struct type
*base_type
;
8880 struct type
*range_type
;
8881 struct attribute
*attr
;
8885 LONGEST negative_mask
;
8887 base_type
= die_type (die
, cu
);
8888 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
8889 check_typedef (base_type
);
8891 /* The die_type call above may have already set the type for this DIE. */
8892 range_type
= get_die_type (die
, cu
);
8896 if (cu
->language
== language_fortran
)
8898 /* FORTRAN implies a lower bound of 1, if not given. */
8902 /* FIXME: For variable sized arrays either of these could be
8903 a variable rather than a constant value. We'll allow it,
8904 but we don't know how to handle it. */
8905 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
8907 low
= dwarf2_get_attr_constant_value (attr
, 0);
8909 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
8912 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
8914 /* GCC encodes arrays with unspecified or dynamic length
8915 with a DW_FORM_block1 attribute or a reference attribute.
8916 FIXME: GDB does not yet know how to handle dynamic
8917 arrays properly, treat them as arrays with unspecified
8920 FIXME: jimb/2003-09-22: GDB does not really know
8921 how to handle arrays of unspecified length
8922 either; we just represent them as zero-length
8923 arrays. Choose an appropriate upper bound given
8924 the lower bound we've computed above. */
8928 high
= dwarf2_get_attr_constant_value (attr
, 1);
8932 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
8935 int count
= dwarf2_get_attr_constant_value (attr
, 1);
8936 high
= low
+ count
- 1;
8940 /* Unspecified array length. */
8945 /* Dwarf-2 specifications explicitly allows to create subrange types
8946 without specifying a base type.
8947 In that case, the base type must be set to the type of
8948 the lower bound, upper bound or count, in that order, if any of these
8949 three attributes references an object that has a type.
8950 If no base type is found, the Dwarf-2 specifications say that
8951 a signed integer type of size equal to the size of an address should
8953 For the following C code: `extern char gdb_int [];'
8954 GCC produces an empty range DIE.
8955 FIXME: muller/2010-05-28: Possible references to object for low bound,
8956 high bound or count are not yet handled by this code. */
8957 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
8959 struct objfile
*objfile
= cu
->objfile
;
8960 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8961 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
8962 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
8964 /* Test "int", "long int", and "long long int" objfile types,
8965 and select the first one having a size above or equal to the
8966 architecture address size. */
8967 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8968 base_type
= int_type
;
8971 int_type
= objfile_type (objfile
)->builtin_long
;
8972 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8973 base_type
= int_type
;
8976 int_type
= objfile_type (objfile
)->builtin_long_long
;
8977 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8978 base_type
= int_type
;
8984 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
8985 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
8986 low
|= negative_mask
;
8987 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
8988 high
|= negative_mask
;
8990 range_type
= create_range_type (NULL
, base_type
, low
, high
);
8992 /* Mark arrays with dynamic length at least as an array of unspecified
8993 length. GDB could check the boundary but before it gets implemented at
8994 least allow accessing the array elements. */
8995 if (attr
&& attr_form_is_block (attr
))
8996 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
8998 /* Ada expects an empty array on no boundary attributes. */
8999 if (attr
== NULL
&& cu
->language
!= language_ada
)
9000 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
9002 name
= dwarf2_name (die
, cu
);
9004 TYPE_NAME (range_type
) = name
;
9006 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9008 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
9010 set_die_type (die
, range_type
, cu
);
9012 /* set_die_type should be already done. */
9013 set_descriptive_type (range_type
, die
, cu
);
9018 static struct type
*
9019 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9023 /* For now, we only support the C meaning of an unspecified type: void. */
9025 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
9026 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
9028 return set_die_type (die
, type
, cu
);
9031 /* Trivial hash function for die_info: the hash value of a DIE
9032 is its offset in .debug_info for this objfile. */
9035 die_hash (const void *item
)
9037 const struct die_info
*die
= item
;
9042 /* Trivial comparison function for die_info structures: two DIEs
9043 are equal if they have the same offset. */
9046 die_eq (const void *item_lhs
, const void *item_rhs
)
9048 const struct die_info
*die_lhs
= item_lhs
;
9049 const struct die_info
*die_rhs
= item_rhs
;
9051 return die_lhs
->offset
== die_rhs
->offset
;
9054 /* Read a whole compilation unit into a linked list of dies. */
9056 static struct die_info
*
9057 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
9059 struct die_reader_specs reader_specs
;
9060 int read_abbrevs
= 0;
9061 struct cleanup
*back_to
= NULL
;
9062 struct die_info
*die
;
9064 if (cu
->dwarf2_abbrevs
== NULL
)
9066 dwarf2_read_abbrevs (cu
);
9067 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
9071 gdb_assert (cu
->die_hash
== NULL
);
9073 = htab_create_alloc_ex (cu
->header
.length
/ 12,
9077 &cu
->comp_unit_obstack
,
9078 hashtab_obstack_allocate
,
9079 dummy_obstack_deallocate
);
9081 init_cu_die_reader (&reader_specs
, cu
);
9083 die
= read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
9086 do_cleanups (back_to
);
9091 /* Main entry point for reading a DIE and all children.
9092 Read the DIE and dump it if requested. */
9094 static struct die_info
*
9095 read_die_and_children (const struct die_reader_specs
*reader
,
9097 gdb_byte
**new_info_ptr
,
9098 struct die_info
*parent
)
9100 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
9101 new_info_ptr
, parent
);
9103 if (dwarf2_die_debug
)
9105 fprintf_unfiltered (gdb_stdlog
,
9106 "\nRead die from %s of %s:\n",
9107 (reader
->cu
->per_cu
->debug_types_section
9110 reader
->abfd
->filename
);
9111 dump_die (result
, dwarf2_die_debug
);
9117 /* Read a single die and all its descendents. Set the die's sibling
9118 field to NULL; set other fields in the die correctly, and set all
9119 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
9120 location of the info_ptr after reading all of those dies. PARENT
9121 is the parent of the die in question. */
9123 static struct die_info
*
9124 read_die_and_children_1 (const struct die_reader_specs
*reader
,
9126 gdb_byte
**new_info_ptr
,
9127 struct die_info
*parent
)
9129 struct die_info
*die
;
9133 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
9136 *new_info_ptr
= cur_ptr
;
9139 store_in_ref_table (die
, reader
->cu
);
9142 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
9146 *new_info_ptr
= cur_ptr
;
9149 die
->sibling
= NULL
;
9150 die
->parent
= parent
;
9154 /* Read a die, all of its descendents, and all of its siblings; set
9155 all of the fields of all of the dies correctly. Arguments are as
9156 in read_die_and_children. */
9158 static struct die_info
*
9159 read_die_and_siblings (const struct die_reader_specs
*reader
,
9161 gdb_byte
**new_info_ptr
,
9162 struct die_info
*parent
)
9164 struct die_info
*first_die
, *last_sibling
;
9168 first_die
= last_sibling
= NULL
;
9172 struct die_info
*die
9173 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
9177 *new_info_ptr
= cur_ptr
;
9184 last_sibling
->sibling
= die
;
9190 /* Read the die from the .debug_info section buffer. Set DIEP to
9191 point to a newly allocated die with its information, except for its
9192 child, sibling, and parent fields. Set HAS_CHILDREN to tell
9193 whether the die has children or not. */
9196 read_full_die (const struct die_reader_specs
*reader
,
9197 struct die_info
**diep
, gdb_byte
*info_ptr
,
9200 unsigned int abbrev_number
, bytes_read
, i
, offset
;
9201 struct abbrev_info
*abbrev
;
9202 struct die_info
*die
;
9203 struct dwarf2_cu
*cu
= reader
->cu
;
9204 bfd
*abfd
= reader
->abfd
;
9206 offset
= info_ptr
- reader
->buffer
;
9207 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9208 info_ptr
+= bytes_read
;
9216 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
9218 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
9220 bfd_get_filename (abfd
));
9222 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
9223 die
->offset
= offset
;
9224 die
->tag
= abbrev
->tag
;
9225 die
->abbrev
= abbrev_number
;
9227 die
->num_attrs
= abbrev
->num_attrs
;
9229 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9230 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
9231 abfd
, info_ptr
, cu
);
9234 *has_children
= abbrev
->has_children
;
9238 /* In DWARF version 2, the description of the debugging information is
9239 stored in a separate .debug_abbrev section. Before we read any
9240 dies from a section we read in all abbreviations and install them
9241 in a hash table. This function also sets flags in CU describing
9242 the data found in the abbrev table. */
9245 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
)
9247 bfd
*abfd
= cu
->objfile
->obfd
;
9248 struct comp_unit_head
*cu_header
= &cu
->header
;
9249 gdb_byte
*abbrev_ptr
;
9250 struct abbrev_info
*cur_abbrev
;
9251 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
9252 unsigned int abbrev_form
, hash_number
;
9253 struct attr_abbrev
*cur_attrs
;
9254 unsigned int allocated_attrs
;
9256 /* Initialize dwarf2 abbrevs. */
9257 obstack_init (&cu
->abbrev_obstack
);
9258 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
9260 * sizeof (struct abbrev_info
*)));
9261 memset (cu
->dwarf2_abbrevs
, 0,
9262 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
9264 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
9265 &dwarf2_per_objfile
->abbrev
);
9266 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
9267 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9268 abbrev_ptr
+= bytes_read
;
9270 allocated_attrs
= ATTR_ALLOC_CHUNK
;
9271 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
9273 /* Loop until we reach an abbrev number of 0. */
9274 while (abbrev_number
)
9276 cur_abbrev
= dwarf_alloc_abbrev (cu
);
9278 /* read in abbrev header */
9279 cur_abbrev
->number
= abbrev_number
;
9280 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9281 abbrev_ptr
+= bytes_read
;
9282 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
9285 if (cur_abbrev
->tag
== DW_TAG_namespace
)
9286 cu
->has_namespace_info
= 1;
9288 /* now read in declarations */
9289 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9290 abbrev_ptr
+= bytes_read
;
9291 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9292 abbrev_ptr
+= bytes_read
;
9295 if (cur_abbrev
->num_attrs
== allocated_attrs
)
9297 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
9299 = xrealloc (cur_attrs
, (allocated_attrs
9300 * sizeof (struct attr_abbrev
)));
9303 /* Record whether this compilation unit might have
9304 inter-compilation-unit references. If we don't know what form
9305 this attribute will have, then it might potentially be a
9306 DW_FORM_ref_addr, so we conservatively expect inter-CU
9309 if (abbrev_form
== DW_FORM_ref_addr
9310 || abbrev_form
== DW_FORM_indirect
)
9311 cu
->has_form_ref_addr
= 1;
9313 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
9314 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
9315 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9316 abbrev_ptr
+= bytes_read
;
9317 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9318 abbrev_ptr
+= bytes_read
;
9321 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
9322 (cur_abbrev
->num_attrs
9323 * sizeof (struct attr_abbrev
)));
9324 memcpy (cur_abbrev
->attrs
, cur_attrs
,
9325 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
9327 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
9328 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
9329 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
9331 /* Get next abbreviation.
9332 Under Irix6 the abbreviations for a compilation unit are not
9333 always properly terminated with an abbrev number of 0.
9334 Exit loop if we encounter an abbreviation which we have
9335 already read (which means we are about to read the abbreviations
9336 for the next compile unit) or if the end of the abbreviation
9337 table is reached. */
9338 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
9339 >= dwarf2_per_objfile
->abbrev
.size
)
9341 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9342 abbrev_ptr
+= bytes_read
;
9343 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
9350 /* Release the memory used by the abbrev table for a compilation unit. */
9353 dwarf2_free_abbrev_table (void *ptr_to_cu
)
9355 struct dwarf2_cu
*cu
= ptr_to_cu
;
9357 obstack_free (&cu
->abbrev_obstack
, NULL
);
9358 cu
->dwarf2_abbrevs
= NULL
;
9361 /* Lookup an abbrev_info structure in the abbrev hash table. */
9363 static struct abbrev_info
*
9364 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
9366 unsigned int hash_number
;
9367 struct abbrev_info
*abbrev
;
9369 hash_number
= number
% ABBREV_HASH_SIZE
;
9370 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
9374 if (abbrev
->number
== number
)
9377 abbrev
= abbrev
->next
;
9382 /* Returns nonzero if TAG represents a type that we might generate a partial
9386 is_type_tag_for_partial (int tag
)
9391 /* Some types that would be reasonable to generate partial symbols for,
9392 that we don't at present. */
9393 case DW_TAG_array_type
:
9394 case DW_TAG_file_type
:
9395 case DW_TAG_ptr_to_member_type
:
9396 case DW_TAG_set_type
:
9397 case DW_TAG_string_type
:
9398 case DW_TAG_subroutine_type
:
9400 case DW_TAG_base_type
:
9401 case DW_TAG_class_type
:
9402 case DW_TAG_interface_type
:
9403 case DW_TAG_enumeration_type
:
9404 case DW_TAG_structure_type
:
9405 case DW_TAG_subrange_type
:
9406 case DW_TAG_typedef
:
9407 case DW_TAG_union_type
:
9414 /* Load all DIEs that are interesting for partial symbols into memory. */
9416 static struct partial_die_info
*
9417 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9418 int building_psymtab
, struct dwarf2_cu
*cu
)
9420 struct objfile
*objfile
= cu
->objfile
;
9421 struct partial_die_info
*part_die
;
9422 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
9423 struct abbrev_info
*abbrev
;
9424 unsigned int bytes_read
;
9425 unsigned int load_all
= 0;
9427 int nesting_level
= 1;
9432 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
9436 = htab_create_alloc_ex (cu
->header
.length
/ 12,
9440 &cu
->comp_unit_obstack
,
9441 hashtab_obstack_allocate
,
9442 dummy_obstack_deallocate
);
9444 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9445 sizeof (struct partial_die_info
));
9449 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
9451 /* A NULL abbrev means the end of a series of children. */
9454 if (--nesting_level
== 0)
9456 /* PART_DIE was probably the last thing allocated on the
9457 comp_unit_obstack, so we could call obstack_free
9458 here. We don't do that because the waste is small,
9459 and will be cleaned up when we're done with this
9460 compilation unit. This way, we're also more robust
9461 against other users of the comp_unit_obstack. */
9464 info_ptr
+= bytes_read
;
9465 last_die
= parent_die
;
9466 parent_die
= parent_die
->die_parent
;
9470 /* Check for template arguments. We never save these; if
9471 they're seen, we just mark the parent, and go on our way. */
9472 if (parent_die
!= NULL
9473 && cu
->language
== language_cplus
9474 && (abbrev
->tag
== DW_TAG_template_type_param
9475 || abbrev
->tag
== DW_TAG_template_value_param
))
9477 parent_die
->has_template_arguments
= 1;
9481 /* We don't need a partial DIE for the template argument. */
9482 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
,
9488 /* We only recurse into subprograms looking for template arguments.
9489 Skip their other children. */
9491 && cu
->language
== language_cplus
9492 && parent_die
!= NULL
9493 && parent_die
->tag
== DW_TAG_subprogram
)
9495 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
9499 /* Check whether this DIE is interesting enough to save. Normally
9500 we would not be interested in members here, but there may be
9501 later variables referencing them via DW_AT_specification (for
9504 && !is_type_tag_for_partial (abbrev
->tag
)
9505 && abbrev
->tag
!= DW_TAG_constant
9506 && abbrev
->tag
!= DW_TAG_enumerator
9507 && abbrev
->tag
!= DW_TAG_subprogram
9508 && abbrev
->tag
!= DW_TAG_lexical_block
9509 && abbrev
->tag
!= DW_TAG_variable
9510 && abbrev
->tag
!= DW_TAG_namespace
9511 && abbrev
->tag
!= DW_TAG_module
9512 && abbrev
->tag
!= DW_TAG_member
)
9514 /* Otherwise we skip to the next sibling, if any. */
9515 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
9519 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
9520 buffer
, info_ptr
, cu
);
9522 /* This two-pass algorithm for processing partial symbols has a
9523 high cost in cache pressure. Thus, handle some simple cases
9524 here which cover the majority of C partial symbols. DIEs
9525 which neither have specification tags in them, nor could have
9526 specification tags elsewhere pointing at them, can simply be
9527 processed and discarded.
9529 This segment is also optional; scan_partial_symbols and
9530 add_partial_symbol will handle these DIEs if we chain
9531 them in normally. When compilers which do not emit large
9532 quantities of duplicate debug information are more common,
9533 this code can probably be removed. */
9535 /* Any complete simple types at the top level (pretty much all
9536 of them, for a language without namespaces), can be processed
9538 if (parent_die
== NULL
9539 && part_die
->has_specification
== 0
9540 && part_die
->is_declaration
== 0
9541 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
9542 || part_die
->tag
== DW_TAG_base_type
9543 || part_die
->tag
== DW_TAG_subrange_type
))
9545 if (building_psymtab
&& part_die
->name
!= NULL
)
9546 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9547 VAR_DOMAIN
, LOC_TYPEDEF
,
9548 &objfile
->static_psymbols
,
9549 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
9550 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9554 /* The exception for DW_TAG_typedef with has_children above is
9555 a workaround of GCC PR debug/47510. In the case of this complaint
9556 type_name_no_tag_or_error will error on such types later.
9558 GDB skipped children of DW_TAG_typedef by the shortcut above and then
9559 it could not find the child DIEs referenced later, this is checked
9560 above. In correct DWARF DW_TAG_typedef should have no children. */
9562 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
9563 complaint (&symfile_complaints
,
9564 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
9565 "- DIE at 0x%x [in module %s]"),
9566 part_die
->offset
, objfile
->name
);
9568 /* If we're at the second level, and we're an enumerator, and
9569 our parent has no specification (meaning possibly lives in a
9570 namespace elsewhere), then we can add the partial symbol now
9571 instead of queueing it. */
9572 if (part_die
->tag
== DW_TAG_enumerator
9573 && parent_die
!= NULL
9574 && parent_die
->die_parent
== NULL
9575 && parent_die
->tag
== DW_TAG_enumeration_type
9576 && parent_die
->has_specification
== 0)
9578 if (part_die
->name
== NULL
)
9579 complaint (&symfile_complaints
,
9580 _("malformed enumerator DIE ignored"));
9581 else if (building_psymtab
)
9582 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9583 VAR_DOMAIN
, LOC_CONST
,
9584 (cu
->language
== language_cplus
9585 || cu
->language
== language_java
)
9586 ? &objfile
->global_psymbols
9587 : &objfile
->static_psymbols
,
9588 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
9590 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9594 /* We'll save this DIE so link it in. */
9595 part_die
->die_parent
= parent_die
;
9596 part_die
->die_sibling
= NULL
;
9597 part_die
->die_child
= NULL
;
9599 if (last_die
&& last_die
== parent_die
)
9600 last_die
->die_child
= part_die
;
9602 last_die
->die_sibling
= part_die
;
9604 last_die
= part_die
;
9606 if (first_die
== NULL
)
9607 first_die
= part_die
;
9609 /* Maybe add the DIE to the hash table. Not all DIEs that we
9610 find interesting need to be in the hash table, because we
9611 also have the parent/sibling/child chains; only those that we
9612 might refer to by offset later during partial symbol reading.
9614 For now this means things that might have be the target of a
9615 DW_AT_specification, DW_AT_abstract_origin, or
9616 DW_AT_extension. DW_AT_extension will refer only to
9617 namespaces; DW_AT_abstract_origin refers to functions (and
9618 many things under the function DIE, but we do not recurse
9619 into function DIEs during partial symbol reading) and
9620 possibly variables as well; DW_AT_specification refers to
9621 declarations. Declarations ought to have the DW_AT_declaration
9622 flag. It happens that GCC forgets to put it in sometimes, but
9623 only for functions, not for types.
9625 Adding more things than necessary to the hash table is harmless
9626 except for the performance cost. Adding too few will result in
9627 wasted time in find_partial_die, when we reread the compilation
9628 unit with load_all_dies set. */
9631 || abbrev
->tag
== DW_TAG_constant
9632 || abbrev
->tag
== DW_TAG_subprogram
9633 || abbrev
->tag
== DW_TAG_variable
9634 || abbrev
->tag
== DW_TAG_namespace
9635 || part_die
->is_declaration
)
9639 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
9640 part_die
->offset
, INSERT
);
9644 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9645 sizeof (struct partial_die_info
));
9647 /* For some DIEs we want to follow their children (if any). For C
9648 we have no reason to follow the children of structures; for other
9649 languages we have to, so that we can get at method physnames
9650 to infer fully qualified class names, for DW_AT_specification,
9651 and for C++ template arguments. For C++, we also look one level
9652 inside functions to find template arguments (if the name of the
9653 function does not already contain the template arguments).
9655 For Ada, we need to scan the children of subprograms and lexical
9656 blocks as well because Ada allows the definition of nested
9657 entities that could be interesting for the debugger, such as
9658 nested subprograms for instance. */
9659 if (last_die
->has_children
9661 || last_die
->tag
== DW_TAG_namespace
9662 || last_die
->tag
== DW_TAG_module
9663 || last_die
->tag
== DW_TAG_enumeration_type
9664 || (cu
->language
== language_cplus
9665 && last_die
->tag
== DW_TAG_subprogram
9666 && (last_die
->name
== NULL
9667 || strchr (last_die
->name
, '<') == NULL
))
9668 || (cu
->language
!= language_c
9669 && (last_die
->tag
== DW_TAG_class_type
9670 || last_die
->tag
== DW_TAG_interface_type
9671 || last_die
->tag
== DW_TAG_structure_type
9672 || last_die
->tag
== DW_TAG_union_type
))
9673 || (cu
->language
== language_ada
9674 && (last_die
->tag
== DW_TAG_subprogram
9675 || last_die
->tag
== DW_TAG_lexical_block
))))
9678 parent_die
= last_die
;
9682 /* Otherwise we skip to the next sibling, if any. */
9683 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
9685 /* Back to the top, do it again. */
9689 /* Read a minimal amount of information into the minimal die structure. */
9692 read_partial_die (struct partial_die_info
*part_die
,
9693 struct abbrev_info
*abbrev
,
9694 unsigned int abbrev_len
, bfd
*abfd
,
9695 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9696 struct dwarf2_cu
*cu
)
9698 struct objfile
*objfile
= cu
->objfile
;
9700 struct attribute attr
;
9701 int has_low_pc_attr
= 0;
9702 int has_high_pc_attr
= 0;
9704 memset (part_die
, 0, sizeof (struct partial_die_info
));
9706 part_die
->offset
= info_ptr
- buffer
;
9708 info_ptr
+= abbrev_len
;
9713 part_die
->tag
= abbrev
->tag
;
9714 part_die
->has_children
= abbrev
->has_children
;
9716 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9718 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
9720 /* Store the data if it is of an attribute we want to keep in a
9721 partial symbol table. */
9725 switch (part_die
->tag
)
9727 case DW_TAG_compile_unit
:
9728 case DW_TAG_type_unit
:
9729 /* Compilation units have a DW_AT_name that is a filename, not
9730 a source language identifier. */
9731 case DW_TAG_enumeration_type
:
9732 case DW_TAG_enumerator
:
9733 /* These tags always have simple identifiers already; no need
9734 to canonicalize them. */
9735 part_die
->name
= DW_STRING (&attr
);
9739 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
9740 &objfile
->objfile_obstack
);
9744 case DW_AT_linkage_name
:
9745 case DW_AT_MIPS_linkage_name
:
9746 /* Note that both forms of linkage name might appear. We
9747 assume they will be the same, and we only store the last
9749 if (cu
->language
== language_ada
)
9750 part_die
->name
= DW_STRING (&attr
);
9751 part_die
->linkage_name
= DW_STRING (&attr
);
9754 has_low_pc_attr
= 1;
9755 part_die
->lowpc
= DW_ADDR (&attr
);
9758 has_high_pc_attr
= 1;
9759 part_die
->highpc
= DW_ADDR (&attr
);
9761 case DW_AT_location
:
9762 /* Support the .debug_loc offsets. */
9763 if (attr_form_is_block (&attr
))
9765 part_die
->locdesc
= DW_BLOCK (&attr
);
9767 else if (attr_form_is_section_offset (&attr
))
9769 dwarf2_complex_location_expr_complaint ();
9773 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9774 "partial symbol information");
9777 case DW_AT_external
:
9778 part_die
->is_external
= DW_UNSND (&attr
);
9780 case DW_AT_declaration
:
9781 part_die
->is_declaration
= DW_UNSND (&attr
);
9784 part_die
->has_type
= 1;
9786 case DW_AT_abstract_origin
:
9787 case DW_AT_specification
:
9788 case DW_AT_extension
:
9789 part_die
->has_specification
= 1;
9790 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
9793 /* Ignore absolute siblings, they might point outside of
9794 the current compile unit. */
9795 if (attr
.form
== DW_FORM_ref_addr
)
9796 complaint (&symfile_complaints
,
9797 _("ignoring absolute DW_AT_sibling"));
9799 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
9801 case DW_AT_byte_size
:
9802 part_die
->has_byte_size
= 1;
9804 case DW_AT_calling_convention
:
9805 /* DWARF doesn't provide a way to identify a program's source-level
9806 entry point. DW_AT_calling_convention attributes are only meant
9807 to describe functions' calling conventions.
9809 However, because it's a necessary piece of information in
9810 Fortran, and because DW_CC_program is the only piece of debugging
9811 information whose definition refers to a 'main program' at all,
9812 several compilers have begun marking Fortran main programs with
9813 DW_CC_program --- even when those functions use the standard
9814 calling conventions.
9816 So until DWARF specifies a way to provide this information and
9817 compilers pick up the new representation, we'll support this
9819 if (DW_UNSND (&attr
) == DW_CC_program
9820 && cu
->language
== language_fortran
)
9822 set_main_name (part_die
->name
);
9824 /* As this DIE has a static linkage the name would be difficult
9825 to look up later. */
9826 language_of_main
= language_fortran
;
9834 if (has_low_pc_attr
&& has_high_pc_attr
)
9836 /* When using the GNU linker, .gnu.linkonce. sections are used to
9837 eliminate duplicate copies of functions and vtables and such.
9838 The linker will arbitrarily choose one and discard the others.
9839 The AT_*_pc values for such functions refer to local labels in
9840 these sections. If the section from that file was discarded, the
9841 labels are not in the output, so the relocs get a value of 0.
9842 If this is a discarded function, mark the pc bounds as invalid,
9843 so that GDB will ignore it. */
9844 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
9846 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9848 complaint (&symfile_complaints
,
9849 _("DW_AT_low_pc %s is zero "
9850 "for DIE at 0x%x [in module %s]"),
9851 paddress (gdbarch
, part_die
->lowpc
),
9852 part_die
->offset
, objfile
->name
);
9854 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
9855 else if (part_die
->lowpc
>= part_die
->highpc
)
9857 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9859 complaint (&symfile_complaints
,
9860 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
9861 "for DIE at 0x%x [in module %s]"),
9862 paddress (gdbarch
, part_die
->lowpc
),
9863 paddress (gdbarch
, part_die
->highpc
),
9864 part_die
->offset
, objfile
->name
);
9867 part_die
->has_pc_info
= 1;
9873 /* Find a cached partial DIE at OFFSET in CU. */
9875 static struct partial_die_info
*
9876 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
9878 struct partial_die_info
*lookup_die
= NULL
;
9879 struct partial_die_info part_die
;
9881 part_die
.offset
= offset
;
9882 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
9887 /* Find a partial DIE at OFFSET, which may or may not be in CU,
9888 except in the case of .debug_types DIEs which do not reference
9889 outside their CU (they do however referencing other types via
9890 DW_FORM_ref_sig8). */
9892 static struct partial_die_info
*
9893 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
9895 struct objfile
*objfile
= cu
->objfile
;
9896 struct dwarf2_per_cu_data
*per_cu
= NULL
;
9897 struct partial_die_info
*pd
= NULL
;
9899 if (cu
->per_cu
->debug_types_section
)
9901 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9907 if (offset_in_cu_p (&cu
->header
, offset
))
9909 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9914 per_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
9916 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
9917 load_partial_comp_unit (per_cu
);
9919 per_cu
->cu
->last_used
= 0;
9920 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
9922 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
9924 struct cleanup
*back_to
;
9925 struct partial_die_info comp_unit_die
;
9926 struct abbrev_info
*abbrev
;
9927 unsigned int bytes_read
;
9930 per_cu
->load_all_dies
= 1;
9932 /* Re-read the DIEs. */
9933 back_to
= make_cleanup (null_cleanup
, 0);
9934 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
9936 dwarf2_read_abbrevs (per_cu
->cu
);
9937 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
9939 info_ptr
= (dwarf2_per_objfile
->info
.buffer
9940 + per_cu
->cu
->header
.offset
9941 + per_cu
->cu
->header
.first_die_offset
);
9942 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
9943 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
9945 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
9947 if (comp_unit_die
.has_children
)
9948 load_partial_dies (objfile
->obfd
,
9949 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
9951 do_cleanups (back_to
);
9953 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
9959 internal_error (__FILE__
, __LINE__
,
9960 _("could not find partial DIE 0x%x "
9961 "in cache [from module %s]\n"),
9962 offset
, bfd_get_filename (objfile
->obfd
));
9966 /* See if we can figure out if the class lives in a namespace. We do
9967 this by looking for a member function; its demangled name will
9968 contain namespace info, if there is any. */
9971 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
9972 struct dwarf2_cu
*cu
)
9974 /* NOTE: carlton/2003-10-07: Getting the info this way changes
9975 what template types look like, because the demangler
9976 frequently doesn't give the same name as the debug info. We
9977 could fix this by only using the demangled name to get the
9978 prefix (but see comment in read_structure_type). */
9980 struct partial_die_info
*real_pdi
;
9981 struct partial_die_info
*child_pdi
;
9983 /* If this DIE (this DIE's specification, if any) has a parent, then
9984 we should not do this. We'll prepend the parent's fully qualified
9985 name when we create the partial symbol. */
9987 real_pdi
= struct_pdi
;
9988 while (real_pdi
->has_specification
)
9989 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
9991 if (real_pdi
->die_parent
!= NULL
)
9994 for (child_pdi
= struct_pdi
->die_child
;
9996 child_pdi
= child_pdi
->die_sibling
)
9998 if (child_pdi
->tag
== DW_TAG_subprogram
9999 && child_pdi
->linkage_name
!= NULL
)
10001 char *actual_class_name
10002 = language_class_name_from_physname (cu
->language_defn
,
10003 child_pdi
->linkage_name
);
10004 if (actual_class_name
!= NULL
)
10007 = obsavestring (actual_class_name
,
10008 strlen (actual_class_name
),
10009 &cu
->objfile
->objfile_obstack
);
10010 xfree (actual_class_name
);
10017 /* Adjust PART_DIE before generating a symbol for it. This function
10018 may set the is_external flag or change the DIE's name. */
10021 fixup_partial_die (struct partial_die_info
*part_die
,
10022 struct dwarf2_cu
*cu
)
10024 /* Once we've fixed up a die, there's no point in doing so again.
10025 This also avoids a memory leak if we were to call
10026 guess_partial_die_structure_name multiple times. */
10027 if (part_die
->fixup_called
)
10030 /* If we found a reference attribute and the DIE has no name, try
10031 to find a name in the referred to DIE. */
10033 if (part_die
->name
== NULL
&& part_die
->has_specification
)
10035 struct partial_die_info
*spec_die
;
10037 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
10039 fixup_partial_die (spec_die
, cu
);
10041 if (spec_die
->name
)
10043 part_die
->name
= spec_die
->name
;
10045 /* Copy DW_AT_external attribute if it is set. */
10046 if (spec_die
->is_external
)
10047 part_die
->is_external
= spec_die
->is_external
;
10051 /* Set default names for some unnamed DIEs. */
10053 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
10054 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
10056 /* If there is no parent die to provide a namespace, and there are
10057 children, see if we can determine the namespace from their linkage
10059 NOTE: We need to do this even if cu->has_namespace_info != 0.
10060 gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */
10061 if (cu
->language
== language_cplus
10062 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
10063 && part_die
->die_parent
== NULL
10064 && part_die
->has_children
10065 && (part_die
->tag
== DW_TAG_class_type
10066 || part_die
->tag
== DW_TAG_structure_type
10067 || part_die
->tag
== DW_TAG_union_type
))
10068 guess_partial_die_structure_name (part_die
, cu
);
10070 /* GCC might emit a nameless struct or union that has a linkage
10071 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
10072 if (part_die
->name
== NULL
10073 && (part_die
->tag
== DW_TAG_class_type
10074 || part_die
->tag
== DW_TAG_interface_type
10075 || part_die
->tag
== DW_TAG_structure_type
10076 || part_die
->tag
== DW_TAG_union_type
)
10077 && part_die
->linkage_name
!= NULL
)
10081 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
10086 /* Strip any leading namespaces/classes, keep only the base name.
10087 DW_AT_name for named DIEs does not contain the prefixes. */
10088 base
= strrchr (demangled
, ':');
10089 if (base
&& base
> demangled
&& base
[-1] == ':')
10094 part_die
->name
= obsavestring (base
, strlen (base
),
10095 &cu
->objfile
->objfile_obstack
);
10100 part_die
->fixup_called
= 1;
10103 /* Read an attribute value described by an attribute form. */
10106 read_attribute_value (struct attribute
*attr
, unsigned form
,
10107 bfd
*abfd
, gdb_byte
*info_ptr
,
10108 struct dwarf2_cu
*cu
)
10110 struct comp_unit_head
*cu_header
= &cu
->header
;
10111 unsigned int bytes_read
;
10112 struct dwarf_block
*blk
;
10117 case DW_FORM_ref_addr
:
10118 if (cu
->header
.version
== 2)
10119 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
10121 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
,
10122 &cu
->header
, &bytes_read
);
10123 info_ptr
+= bytes_read
;
10126 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
10127 info_ptr
+= bytes_read
;
10129 case DW_FORM_block2
:
10130 blk
= dwarf_alloc_block (cu
);
10131 blk
->size
= read_2_bytes (abfd
, info_ptr
);
10133 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10134 info_ptr
+= blk
->size
;
10135 DW_BLOCK (attr
) = blk
;
10137 case DW_FORM_block4
:
10138 blk
= dwarf_alloc_block (cu
);
10139 blk
->size
= read_4_bytes (abfd
, info_ptr
);
10141 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10142 info_ptr
+= blk
->size
;
10143 DW_BLOCK (attr
) = blk
;
10145 case DW_FORM_data2
:
10146 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
10149 case DW_FORM_data4
:
10150 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
10153 case DW_FORM_data8
:
10154 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
10157 case DW_FORM_sec_offset
:
10158 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
10159 info_ptr
+= bytes_read
;
10161 case DW_FORM_string
:
10162 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
10163 DW_STRING_IS_CANONICAL (attr
) = 0;
10164 info_ptr
+= bytes_read
;
10167 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
10169 DW_STRING_IS_CANONICAL (attr
) = 0;
10170 info_ptr
+= bytes_read
;
10172 case DW_FORM_exprloc
:
10173 case DW_FORM_block
:
10174 blk
= dwarf_alloc_block (cu
);
10175 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10176 info_ptr
+= bytes_read
;
10177 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10178 info_ptr
+= blk
->size
;
10179 DW_BLOCK (attr
) = blk
;
10181 case DW_FORM_block1
:
10182 blk
= dwarf_alloc_block (cu
);
10183 blk
->size
= read_1_byte (abfd
, info_ptr
);
10185 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10186 info_ptr
+= blk
->size
;
10187 DW_BLOCK (attr
) = blk
;
10189 case DW_FORM_data1
:
10190 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
10194 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
10197 case DW_FORM_flag_present
:
10198 DW_UNSND (attr
) = 1;
10200 case DW_FORM_sdata
:
10201 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
10202 info_ptr
+= bytes_read
;
10204 case DW_FORM_udata
:
10205 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10206 info_ptr
+= bytes_read
;
10209 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
10213 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
10217 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
10221 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
10224 case DW_FORM_ref_sig8
:
10225 /* Convert the signature to something we can record in DW_UNSND
10227 NOTE: This is NULL if the type wasn't found. */
10228 DW_SIGNATURED_TYPE (attr
) =
10229 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
10232 case DW_FORM_ref_udata
:
10233 DW_ADDR (attr
) = (cu
->header
.offset
10234 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
10235 info_ptr
+= bytes_read
;
10237 case DW_FORM_indirect
:
10238 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10239 info_ptr
+= bytes_read
;
10240 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
10243 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
10244 dwarf_form_name (form
),
10245 bfd_get_filename (abfd
));
10248 /* We have seen instances where the compiler tried to emit a byte
10249 size attribute of -1 which ended up being encoded as an unsigned
10250 0xffffffff. Although 0xffffffff is technically a valid size value,
10251 an object of this size seems pretty unlikely so we can relatively
10252 safely treat these cases as if the size attribute was invalid and
10253 treat them as zero by default. */
10254 if (attr
->name
== DW_AT_byte_size
10255 && form
== DW_FORM_data4
10256 && DW_UNSND (attr
) >= 0xffffffff)
10259 (&symfile_complaints
,
10260 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
10261 hex_string (DW_UNSND (attr
)));
10262 DW_UNSND (attr
) = 0;
10268 /* Read an attribute described by an abbreviated attribute. */
10271 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
10272 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
10274 attr
->name
= abbrev
->name
;
10275 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
10278 /* Read dwarf information from a buffer. */
10280 static unsigned int
10281 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
10283 return bfd_get_8 (abfd
, buf
);
10287 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
10289 return bfd_get_signed_8 (abfd
, buf
);
10292 static unsigned int
10293 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
10295 return bfd_get_16 (abfd
, buf
);
10299 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
10301 return bfd_get_signed_16 (abfd
, buf
);
10304 static unsigned int
10305 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
10307 return bfd_get_32 (abfd
, buf
);
10311 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
10313 return bfd_get_signed_32 (abfd
, buf
);
10317 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
10319 return bfd_get_64 (abfd
, buf
);
10323 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
10324 unsigned int *bytes_read
)
10326 struct comp_unit_head
*cu_header
= &cu
->header
;
10327 CORE_ADDR retval
= 0;
10329 if (cu_header
->signed_addr_p
)
10331 switch (cu_header
->addr_size
)
10334 retval
= bfd_get_signed_16 (abfd
, buf
);
10337 retval
= bfd_get_signed_32 (abfd
, buf
);
10340 retval
= bfd_get_signed_64 (abfd
, buf
);
10343 internal_error (__FILE__
, __LINE__
,
10344 _("read_address: bad switch, signed [in module %s]"),
10345 bfd_get_filename (abfd
));
10350 switch (cu_header
->addr_size
)
10353 retval
= bfd_get_16 (abfd
, buf
);
10356 retval
= bfd_get_32 (abfd
, buf
);
10359 retval
= bfd_get_64 (abfd
, buf
);
10362 internal_error (__FILE__
, __LINE__
,
10363 _("read_address: bad switch, "
10364 "unsigned [in module %s]"),
10365 bfd_get_filename (abfd
));
10369 *bytes_read
= cu_header
->addr_size
;
10373 /* Read the initial length from a section. The (draft) DWARF 3
10374 specification allows the initial length to take up either 4 bytes
10375 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
10376 bytes describe the length and all offsets will be 8 bytes in length
10379 An older, non-standard 64-bit format is also handled by this
10380 function. The older format in question stores the initial length
10381 as an 8-byte quantity without an escape value. Lengths greater
10382 than 2^32 aren't very common which means that the initial 4 bytes
10383 is almost always zero. Since a length value of zero doesn't make
10384 sense for the 32-bit format, this initial zero can be considered to
10385 be an escape value which indicates the presence of the older 64-bit
10386 format. As written, the code can't detect (old format) lengths
10387 greater than 4GB. If it becomes necessary to handle lengths
10388 somewhat larger than 4GB, we could allow other small values (such
10389 as the non-sensical values of 1, 2, and 3) to also be used as
10390 escape values indicating the presence of the old format.
10392 The value returned via bytes_read should be used to increment the
10393 relevant pointer after calling read_initial_length().
10395 [ Note: read_initial_length() and read_offset() are based on the
10396 document entitled "DWARF Debugging Information Format", revision
10397 3, draft 8, dated November 19, 2001. This document was obtained
10400 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
10402 This document is only a draft and is subject to change. (So beware.)
10404 Details regarding the older, non-standard 64-bit format were
10405 determined empirically by examining 64-bit ELF files produced by
10406 the SGI toolchain on an IRIX 6.5 machine.
10408 - Kevin, July 16, 2002
10412 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
10414 LONGEST length
= bfd_get_32 (abfd
, buf
);
10416 if (length
== 0xffffffff)
10418 length
= bfd_get_64 (abfd
, buf
+ 4);
10421 else if (length
== 0)
10423 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
10424 length
= bfd_get_64 (abfd
, buf
);
10435 /* Cover function for read_initial_length.
10436 Returns the length of the object at BUF, and stores the size of the
10437 initial length in *BYTES_READ and stores the size that offsets will be in
10439 If the initial length size is not equivalent to that specified in
10440 CU_HEADER then issue a complaint.
10441 This is useful when reading non-comp-unit headers. */
10444 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
10445 const struct comp_unit_head
*cu_header
,
10446 unsigned int *bytes_read
,
10447 unsigned int *offset_size
)
10449 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
10451 gdb_assert (cu_header
->initial_length_size
== 4
10452 || cu_header
->initial_length_size
== 8
10453 || cu_header
->initial_length_size
== 12);
10455 if (cu_header
->initial_length_size
!= *bytes_read
)
10456 complaint (&symfile_complaints
,
10457 _("intermixed 32-bit and 64-bit DWARF sections"));
10459 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
10463 /* Read an offset from the data stream. The size of the offset is
10464 given by cu_header->offset_size. */
10467 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
10468 unsigned int *bytes_read
)
10470 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
10472 *bytes_read
= cu_header
->offset_size
;
10476 /* Read an offset from the data stream. */
10479 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
10481 LONGEST retval
= 0;
10483 switch (offset_size
)
10486 retval
= bfd_get_32 (abfd
, buf
);
10489 retval
= bfd_get_64 (abfd
, buf
);
10492 internal_error (__FILE__
, __LINE__
,
10493 _("read_offset_1: bad switch [in module %s]"),
10494 bfd_get_filename (abfd
));
10501 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
10503 /* If the size of a host char is 8 bits, we can return a pointer
10504 to the buffer, otherwise we have to copy the data to a buffer
10505 allocated on the temporary obstack. */
10506 gdb_assert (HOST_CHAR_BIT
== 8);
10511 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10513 /* If the size of a host char is 8 bits, we can return a pointer
10514 to the string, otherwise we have to copy the string to a buffer
10515 allocated on the temporary obstack. */
10516 gdb_assert (HOST_CHAR_BIT
== 8);
10519 *bytes_read_ptr
= 1;
10522 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
10523 return (char *) buf
;
10527 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
10529 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
10530 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
10531 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
10532 bfd_get_filename (abfd
));
10533 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
10534 error (_("DW_FORM_strp pointing outside of "
10535 ".debug_str section [in module %s]"),
10536 bfd_get_filename (abfd
));
10537 gdb_assert (HOST_CHAR_BIT
== 8);
10538 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
10540 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
10544 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
10545 const struct comp_unit_head
*cu_header
,
10546 unsigned int *bytes_read_ptr
)
10548 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
10550 return read_indirect_string_at_offset (abfd
, str_offset
);
10553 static unsigned long
10554 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10556 unsigned long result
;
10557 unsigned int num_read
;
10559 unsigned char byte
;
10567 byte
= bfd_get_8 (abfd
, buf
);
10570 result
|= ((unsigned long)(byte
& 127) << shift
);
10571 if ((byte
& 128) == 0)
10577 *bytes_read_ptr
= num_read
;
10582 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10585 int i
, shift
, num_read
;
10586 unsigned char byte
;
10594 byte
= bfd_get_8 (abfd
, buf
);
10597 result
|= ((long)(byte
& 127) << shift
);
10599 if ((byte
& 128) == 0)
10604 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
10605 result
|= -(((long)1) << shift
);
10606 *bytes_read_ptr
= num_read
;
10610 /* Return a pointer to just past the end of an LEB128 number in BUF. */
10613 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
10619 byte
= bfd_get_8 (abfd
, buf
);
10621 if ((byte
& 128) == 0)
10627 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
10634 cu
->language
= language_c
;
10636 case DW_LANG_C_plus_plus
:
10637 cu
->language
= language_cplus
;
10640 cu
->language
= language_d
;
10642 case DW_LANG_Fortran77
:
10643 case DW_LANG_Fortran90
:
10644 case DW_LANG_Fortran95
:
10645 cu
->language
= language_fortran
;
10647 case DW_LANG_Mips_Assembler
:
10648 cu
->language
= language_asm
;
10651 cu
->language
= language_java
;
10653 case DW_LANG_Ada83
:
10654 case DW_LANG_Ada95
:
10655 cu
->language
= language_ada
;
10657 case DW_LANG_Modula2
:
10658 cu
->language
= language_m2
;
10660 case DW_LANG_Pascal83
:
10661 cu
->language
= language_pascal
;
10664 cu
->language
= language_objc
;
10666 case DW_LANG_Cobol74
:
10667 case DW_LANG_Cobol85
:
10669 cu
->language
= language_minimal
;
10672 cu
->language_defn
= language_def (cu
->language
);
10675 /* Return the named attribute or NULL if not there. */
10677 static struct attribute
*
10678 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
10681 struct attribute
*spec
= NULL
;
10683 for (i
= 0; i
< die
->num_attrs
; ++i
)
10685 if (die
->attrs
[i
].name
== name
)
10686 return &die
->attrs
[i
];
10687 if (die
->attrs
[i
].name
== DW_AT_specification
10688 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
10689 spec
= &die
->attrs
[i
];
10694 die
= follow_die_ref (die
, spec
, &cu
);
10695 return dwarf2_attr (die
, name
, cu
);
10701 /* Return the named attribute or NULL if not there,
10702 but do not follow DW_AT_specification, etc.
10703 This is for use in contexts where we're reading .debug_types dies.
10704 Following DW_AT_specification, DW_AT_abstract_origin will take us
10705 back up the chain, and we want to go down. */
10707 static struct attribute
*
10708 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
10709 struct dwarf2_cu
*cu
)
10713 for (i
= 0; i
< die
->num_attrs
; ++i
)
10714 if (die
->attrs
[i
].name
== name
)
10715 return &die
->attrs
[i
];
10720 /* Return non-zero iff the attribute NAME is defined for the given DIE,
10721 and holds a non-zero value. This function should only be used for
10722 DW_FORM_flag or DW_FORM_flag_present attributes. */
10725 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
10727 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
10729 return (attr
&& DW_UNSND (attr
));
10733 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
10735 /* A DIE is a declaration if it has a DW_AT_declaration attribute
10736 which value is non-zero. However, we have to be careful with
10737 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
10738 (via dwarf2_flag_true_p) follows this attribute. So we may
10739 end up accidently finding a declaration attribute that belongs
10740 to a different DIE referenced by the specification attribute,
10741 even though the given DIE does not have a declaration attribute. */
10742 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
10743 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
10746 /* Return the die giving the specification for DIE, if there is
10747 one. *SPEC_CU is the CU containing DIE on input, and the CU
10748 containing the return value on output. If there is no
10749 specification, but there is an abstract origin, that is
10752 static struct die_info
*
10753 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
10755 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
10758 if (spec_attr
== NULL
)
10759 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
10761 if (spec_attr
== NULL
)
10764 return follow_die_ref (die
, spec_attr
, spec_cu
);
10767 /* Free the line_header structure *LH, and any arrays and strings it
10769 NOTE: This is also used as a "cleanup" function. */
10772 free_line_header (struct line_header
*lh
)
10774 if (lh
->standard_opcode_lengths
)
10775 xfree (lh
->standard_opcode_lengths
);
10777 /* Remember that all the lh->file_names[i].name pointers are
10778 pointers into debug_line_buffer, and don't need to be freed. */
10779 if (lh
->file_names
)
10780 xfree (lh
->file_names
);
10782 /* Similarly for the include directory names. */
10783 if (lh
->include_dirs
)
10784 xfree (lh
->include_dirs
);
10789 /* Add an entry to LH's include directory table. */
10792 add_include_dir (struct line_header
*lh
, char *include_dir
)
10794 /* Grow the array if necessary. */
10795 if (lh
->include_dirs_size
== 0)
10797 lh
->include_dirs_size
= 1; /* for testing */
10798 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
10799 * sizeof (*lh
->include_dirs
));
10801 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
10803 lh
->include_dirs_size
*= 2;
10804 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
10805 (lh
->include_dirs_size
10806 * sizeof (*lh
->include_dirs
)));
10809 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
10812 /* Add an entry to LH's file name table. */
10815 add_file_name (struct line_header
*lh
,
10817 unsigned int dir_index
,
10818 unsigned int mod_time
,
10819 unsigned int length
)
10821 struct file_entry
*fe
;
10823 /* Grow the array if necessary. */
10824 if (lh
->file_names_size
== 0)
10826 lh
->file_names_size
= 1; /* for testing */
10827 lh
->file_names
= xmalloc (lh
->file_names_size
10828 * sizeof (*lh
->file_names
));
10830 else if (lh
->num_file_names
>= lh
->file_names_size
)
10832 lh
->file_names_size
*= 2;
10833 lh
->file_names
= xrealloc (lh
->file_names
,
10834 (lh
->file_names_size
10835 * sizeof (*lh
->file_names
)));
10838 fe
= &lh
->file_names
[lh
->num_file_names
++];
10840 fe
->dir_index
= dir_index
;
10841 fe
->mod_time
= mod_time
;
10842 fe
->length
= length
;
10843 fe
->included_p
= 0;
10847 /* Read the statement program header starting at OFFSET in
10848 .debug_line, according to the endianness of ABFD. Return a pointer
10849 to a struct line_header, allocated using xmalloc.
10851 NOTE: the strings in the include directory and file name tables of
10852 the returned object point into debug_line_buffer, and must not be
10855 static struct line_header
*
10856 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
10857 struct dwarf2_cu
*cu
)
10859 struct cleanup
*back_to
;
10860 struct line_header
*lh
;
10861 gdb_byte
*line_ptr
;
10862 unsigned int bytes_read
, offset_size
;
10864 char *cur_dir
, *cur_file
;
10866 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
10867 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
10869 complaint (&symfile_complaints
, _("missing .debug_line section"));
10873 /* Make sure that at least there's room for the total_length field.
10874 That could be 12 bytes long, but we're just going to fudge that. */
10875 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
10877 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10881 lh
= xmalloc (sizeof (*lh
));
10882 memset (lh
, 0, sizeof (*lh
));
10883 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
10886 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
10888 /* Read in the header. */
10890 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
10891 &bytes_read
, &offset_size
);
10892 line_ptr
+= bytes_read
;
10893 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
10894 + dwarf2_per_objfile
->line
.size
))
10896 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10899 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
10900 lh
->version
= read_2_bytes (abfd
, line_ptr
);
10902 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
10903 line_ptr
+= offset_size
;
10904 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
10906 if (lh
->version
>= 4)
10908 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
10912 lh
->maximum_ops_per_instruction
= 1;
10914 if (lh
->maximum_ops_per_instruction
== 0)
10916 lh
->maximum_ops_per_instruction
= 1;
10917 complaint (&symfile_complaints
,
10918 _("invalid maximum_ops_per_instruction "
10919 "in `.debug_line' section"));
10922 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
10924 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
10926 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
10928 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
10930 lh
->standard_opcode_lengths
10931 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
10933 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
10934 for (i
= 1; i
< lh
->opcode_base
; ++i
)
10936 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
10940 /* Read directory table. */
10941 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
10943 line_ptr
+= bytes_read
;
10944 add_include_dir (lh
, cur_dir
);
10946 line_ptr
+= bytes_read
;
10948 /* Read file name table. */
10949 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
10951 unsigned int dir_index
, mod_time
, length
;
10953 line_ptr
+= bytes_read
;
10954 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10955 line_ptr
+= bytes_read
;
10956 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10957 line_ptr
+= bytes_read
;
10958 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10959 line_ptr
+= bytes_read
;
10961 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
10963 line_ptr
+= bytes_read
;
10964 lh
->statement_program_start
= line_ptr
;
10966 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
10967 + dwarf2_per_objfile
->line
.size
))
10968 complaint (&symfile_complaints
,
10969 _("line number info header doesn't "
10970 "fit in `.debug_line' section"));
10972 discard_cleanups (back_to
);
10976 /* Subroutine of dwarf_decode_lines to simplify it.
10977 Return the file name of the psymtab for included file FILE_INDEX
10978 in line header LH of PST.
10979 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10980 If space for the result is malloc'd, it will be freed by a cleanup.
10981 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
10984 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
10985 const struct partial_symtab
*pst
,
10986 const char *comp_dir
)
10988 const struct file_entry fe
= lh
->file_names
[file_index
];
10989 char *include_name
= fe
.name
;
10990 char *include_name_to_compare
= include_name
;
10991 char *dir_name
= NULL
;
10992 const char *pst_filename
;
10993 char *copied_name
= NULL
;
10997 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
10999 if (!IS_ABSOLUTE_PATH (include_name
)
11000 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
11002 /* Avoid creating a duplicate psymtab for PST.
11003 We do this by comparing INCLUDE_NAME and PST_FILENAME.
11004 Before we do the comparison, however, we need to account
11005 for DIR_NAME and COMP_DIR.
11006 First prepend dir_name (if non-NULL). If we still don't
11007 have an absolute path prepend comp_dir (if non-NULL).
11008 However, the directory we record in the include-file's
11009 psymtab does not contain COMP_DIR (to match the
11010 corresponding symtab(s)).
11015 bash$ gcc -g ./hello.c
11016 include_name = "hello.c"
11018 DW_AT_comp_dir = comp_dir = "/tmp"
11019 DW_AT_name = "./hello.c" */
11021 if (dir_name
!= NULL
)
11023 include_name
= concat (dir_name
, SLASH_STRING
,
11024 include_name
, (char *)NULL
);
11025 include_name_to_compare
= include_name
;
11026 make_cleanup (xfree
, include_name
);
11028 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
11030 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
11031 include_name
, (char *)NULL
);
11035 pst_filename
= pst
->filename
;
11036 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
11038 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
11039 pst_filename
, (char *)NULL
);
11040 pst_filename
= copied_name
;
11043 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
11045 if (include_name_to_compare
!= include_name
)
11046 xfree (include_name_to_compare
);
11047 if (copied_name
!= NULL
)
11048 xfree (copied_name
);
11052 return include_name
;
11055 /* Ignore this record_line request. */
11058 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
11063 /* Subroutine of dwarf_decode_lines to simplify it.
11064 Process the line number information in LH. */
11067 dwarf_decode_lines_1 (struct line_header
*lh
, const char *comp_dir
,
11068 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
11070 gdb_byte
*line_ptr
, *extended_end
;
11071 gdb_byte
*line_end
;
11072 unsigned int bytes_read
, extended_len
;
11073 unsigned char op_code
, extended_op
, adj_opcode
;
11074 CORE_ADDR baseaddr
;
11075 struct objfile
*objfile
= cu
->objfile
;
11076 bfd
*abfd
= objfile
->obfd
;
11077 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11078 const int decode_for_pst_p
= (pst
!= NULL
);
11079 struct subfile
*last_subfile
= NULL
;
11080 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
11083 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11085 line_ptr
= lh
->statement_program_start
;
11086 line_end
= lh
->statement_program_end
;
11088 /* Read the statement sequences until there's nothing left. */
11089 while (line_ptr
< line_end
)
11091 /* state machine registers */
11092 CORE_ADDR address
= 0;
11093 unsigned int file
= 1;
11094 unsigned int line
= 1;
11095 unsigned int column
= 0;
11096 int is_stmt
= lh
->default_is_stmt
;
11097 int basic_block
= 0;
11098 int end_sequence
= 0;
11100 unsigned char op_index
= 0;
11102 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
11104 /* Start a subfile for the current file of the state machine. */
11105 /* lh->include_dirs and lh->file_names are 0-based, but the
11106 directory and file name numbers in the statement program
11108 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
11112 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11114 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11117 /* Decode the table. */
11118 while (!end_sequence
)
11120 op_code
= read_1_byte (abfd
, line_ptr
);
11122 if (line_ptr
> line_end
)
11124 dwarf2_debug_line_missing_end_sequence_complaint ();
11128 if (op_code
>= lh
->opcode_base
)
11130 /* Special operand. */
11131 adj_opcode
= op_code
- lh
->opcode_base
;
11132 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
11133 / lh
->maximum_ops_per_instruction
)
11134 * lh
->minimum_instruction_length
);
11135 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
11136 % lh
->maximum_ops_per_instruction
);
11137 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
11138 if (lh
->num_file_names
< file
|| file
== 0)
11139 dwarf2_debug_line_missing_file_complaint ();
11140 /* For now we ignore lines not starting on an
11141 instruction boundary. */
11142 else if (op_index
== 0)
11144 lh
->file_names
[file
- 1].included_p
= 1;
11145 if (!decode_for_pst_p
&& is_stmt
)
11147 if (last_subfile
!= current_subfile
)
11149 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11151 (*p_record_line
) (last_subfile
, 0, addr
);
11152 last_subfile
= current_subfile
;
11154 /* Append row to matrix using current values. */
11155 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11156 (*p_record_line
) (current_subfile
, line
, addr
);
11161 else switch (op_code
)
11163 case DW_LNS_extended_op
:
11164 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
11166 line_ptr
+= bytes_read
;
11167 extended_end
= line_ptr
+ extended_len
;
11168 extended_op
= read_1_byte (abfd
, line_ptr
);
11170 switch (extended_op
)
11172 case DW_LNE_end_sequence
:
11173 p_record_line
= record_line
;
11176 case DW_LNE_set_address
:
11177 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
11179 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
11181 /* This line table is for a function which has been
11182 GCd by the linker. Ignore it. PR gdb/12528 */
11185 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
11187 complaint (&symfile_complaints
,
11188 _(".debug_line address at offset 0x%lx is 0 "
11190 line_offset
, objfile
->name
);
11191 p_record_line
= noop_record_line
;
11195 line_ptr
+= bytes_read
;
11196 address
+= baseaddr
;
11198 case DW_LNE_define_file
:
11201 unsigned int dir_index
, mod_time
, length
;
11203 cur_file
= read_direct_string (abfd
, line_ptr
,
11205 line_ptr
+= bytes_read
;
11207 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11208 line_ptr
+= bytes_read
;
11210 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11211 line_ptr
+= bytes_read
;
11213 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11214 line_ptr
+= bytes_read
;
11215 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
11218 case DW_LNE_set_discriminator
:
11219 /* The discriminator is not interesting to the debugger;
11221 line_ptr
= extended_end
;
11224 complaint (&symfile_complaints
,
11225 _("mangled .debug_line section"));
11228 /* Make sure that we parsed the extended op correctly. If e.g.
11229 we expected a different address size than the producer used,
11230 we may have read the wrong number of bytes. */
11231 if (line_ptr
!= extended_end
)
11233 complaint (&symfile_complaints
,
11234 _("mangled .debug_line section"));
11239 if (lh
->num_file_names
< file
|| file
== 0)
11240 dwarf2_debug_line_missing_file_complaint ();
11243 lh
->file_names
[file
- 1].included_p
= 1;
11244 if (!decode_for_pst_p
&& is_stmt
)
11246 if (last_subfile
!= current_subfile
)
11248 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11250 (*p_record_line
) (last_subfile
, 0, addr
);
11251 last_subfile
= current_subfile
;
11253 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11254 (*p_record_line
) (current_subfile
, line
, addr
);
11259 case DW_LNS_advance_pc
:
11262 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11264 address
+= (((op_index
+ adjust
)
11265 / lh
->maximum_ops_per_instruction
)
11266 * lh
->minimum_instruction_length
);
11267 op_index
= ((op_index
+ adjust
)
11268 % lh
->maximum_ops_per_instruction
);
11269 line_ptr
+= bytes_read
;
11272 case DW_LNS_advance_line
:
11273 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
11274 line_ptr
+= bytes_read
;
11276 case DW_LNS_set_file
:
11278 /* The arrays lh->include_dirs and lh->file_names are
11279 0-based, but the directory and file name numbers in
11280 the statement program are 1-based. */
11281 struct file_entry
*fe
;
11284 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11285 line_ptr
+= bytes_read
;
11286 if (lh
->num_file_names
< file
|| file
== 0)
11287 dwarf2_debug_line_missing_file_complaint ();
11290 fe
= &lh
->file_names
[file
- 1];
11292 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11293 if (!decode_for_pst_p
)
11295 last_subfile
= current_subfile
;
11296 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11301 case DW_LNS_set_column
:
11302 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11303 line_ptr
+= bytes_read
;
11305 case DW_LNS_negate_stmt
:
11306 is_stmt
= (!is_stmt
);
11308 case DW_LNS_set_basic_block
:
11311 /* Add to the address register of the state machine the
11312 address increment value corresponding to special opcode
11313 255. I.e., this value is scaled by the minimum
11314 instruction length since special opcode 255 would have
11315 scaled the increment. */
11316 case DW_LNS_const_add_pc
:
11318 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
11320 address
+= (((op_index
+ adjust
)
11321 / lh
->maximum_ops_per_instruction
)
11322 * lh
->minimum_instruction_length
);
11323 op_index
= ((op_index
+ adjust
)
11324 % lh
->maximum_ops_per_instruction
);
11327 case DW_LNS_fixed_advance_pc
:
11328 address
+= read_2_bytes (abfd
, line_ptr
);
11334 /* Unknown standard opcode, ignore it. */
11337 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
11339 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11340 line_ptr
+= bytes_read
;
11345 if (lh
->num_file_names
< file
|| file
== 0)
11346 dwarf2_debug_line_missing_file_complaint ();
11349 lh
->file_names
[file
- 1].included_p
= 1;
11350 if (!decode_for_pst_p
)
11352 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11353 (*p_record_line
) (current_subfile
, 0, addr
);
11359 /* Decode the Line Number Program (LNP) for the given line_header
11360 structure and CU. The actual information extracted and the type
11361 of structures created from the LNP depends on the value of PST.
11363 1. If PST is NULL, then this procedure uses the data from the program
11364 to create all necessary symbol tables, and their linetables.
11366 2. If PST is not NULL, this procedure reads the program to determine
11367 the list of files included by the unit represented by PST, and
11368 builds all the associated partial symbol tables.
11370 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
11371 It is used for relative paths in the line table.
11372 NOTE: When processing partial symtabs (pst != NULL),
11373 comp_dir == pst->dirname.
11375 NOTE: It is important that psymtabs have the same file name (via strcmp)
11376 as the corresponding symtab. Since COMP_DIR is not used in the name of the
11377 symtab we don't use it in the name of the psymtabs we create.
11378 E.g. expand_line_sal requires this when finding psymtabs to expand.
11379 A good testcase for this is mb-inline.exp. */
11382 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
11383 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
11384 int want_line_info
)
11386 struct objfile
*objfile
= cu
->objfile
;
11387 const int decode_for_pst_p
= (pst
!= NULL
);
11388 struct subfile
*first_subfile
= current_subfile
;
11390 if (want_line_info
)
11391 dwarf_decode_lines_1 (lh
, comp_dir
, cu
, pst
);
11393 if (decode_for_pst_p
)
11397 /* Now that we're done scanning the Line Header Program, we can
11398 create the psymtab of each included file. */
11399 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
11400 if (lh
->file_names
[file_index
].included_p
== 1)
11402 char *include_name
=
11403 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
11404 if (include_name
!= NULL
)
11405 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
11410 /* Make sure a symtab is created for every file, even files
11411 which contain only variables (i.e. no code with associated
11415 for (i
= 0; i
< lh
->num_file_names
; i
++)
11418 struct file_entry
*fe
;
11420 fe
= &lh
->file_names
[i
];
11422 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11423 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11425 /* Skip the main file; we don't need it, and it must be
11426 allocated last, so that it will show up before the
11427 non-primary symtabs in the objfile's symtab list. */
11428 if (current_subfile
== first_subfile
)
11431 if (current_subfile
->symtab
== NULL
)
11432 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
11434 fe
->symtab
= current_subfile
->symtab
;
11439 /* Start a subfile for DWARF. FILENAME is the name of the file and
11440 DIRNAME the name of the source directory which contains FILENAME
11441 or NULL if not known. COMP_DIR is the compilation directory for the
11442 linetable's compilation unit or NULL if not known.
11443 This routine tries to keep line numbers from identical absolute and
11444 relative file names in a common subfile.
11446 Using the `list' example from the GDB testsuite, which resides in
11447 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
11448 of /srcdir/list0.c yields the following debugging information for list0.c:
11450 DW_AT_name: /srcdir/list0.c
11451 DW_AT_comp_dir: /compdir
11452 files.files[0].name: list0.h
11453 files.files[0].dir: /srcdir
11454 files.files[1].name: list0.c
11455 files.files[1].dir: /srcdir
11457 The line number information for list0.c has to end up in a single
11458 subfile, so that `break /srcdir/list0.c:1' works as expected.
11459 start_subfile will ensure that this happens provided that we pass the
11460 concatenation of files.files[1].dir and files.files[1].name as the
11464 dwarf2_start_subfile (char *filename
, const char *dirname
,
11465 const char *comp_dir
)
11469 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
11470 `start_symtab' will always pass the contents of DW_AT_comp_dir as
11471 second argument to start_subfile. To be consistent, we do the
11472 same here. In order not to lose the line information directory,
11473 we concatenate it to the filename when it makes sense.
11474 Note that the Dwarf3 standard says (speaking of filenames in line
11475 information): ``The directory index is ignored for file names
11476 that represent full path names''. Thus ignoring dirname in the
11477 `else' branch below isn't an issue. */
11479 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
11480 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
11482 fullname
= filename
;
11484 start_subfile (fullname
, comp_dir
);
11486 if (fullname
!= filename
)
11491 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
11492 struct dwarf2_cu
*cu
)
11494 struct objfile
*objfile
= cu
->objfile
;
11495 struct comp_unit_head
*cu_header
= &cu
->header
;
11497 /* NOTE drow/2003-01-30: There used to be a comment and some special
11498 code here to turn a symbol with DW_AT_external and a
11499 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
11500 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
11501 with some versions of binutils) where shared libraries could have
11502 relocations against symbols in their debug information - the
11503 minimal symbol would have the right address, but the debug info
11504 would not. It's no longer necessary, because we will explicitly
11505 apply relocations when we read in the debug information now. */
11507 /* A DW_AT_location attribute with no contents indicates that a
11508 variable has been optimized away. */
11509 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
11511 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11515 /* Handle one degenerate form of location expression specially, to
11516 preserve GDB's previous behavior when section offsets are
11517 specified. If this is just a DW_OP_addr then mark this symbol
11520 if (attr_form_is_block (attr
)
11521 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
11522 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
11524 unsigned int dummy
;
11526 SYMBOL_VALUE_ADDRESS (sym
) =
11527 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
11528 SYMBOL_CLASS (sym
) = LOC_STATIC
;
11529 fixup_symbol_section (sym
, objfile
);
11530 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
11531 SYMBOL_SECTION (sym
));
11535 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
11536 expression evaluator, and use LOC_COMPUTED only when necessary
11537 (i.e. when the value of a register or memory location is
11538 referenced, or a thread-local block, etc.). Then again, it might
11539 not be worthwhile. I'm assuming that it isn't unless performance
11540 or memory numbers show me otherwise. */
11542 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
11543 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11545 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
11546 cu
->has_loclist
= 1;
11549 /* Given a pointer to a DWARF information entry, figure out if we need
11550 to make a symbol table entry for it, and if so, create a new entry
11551 and return a pointer to it.
11552 If TYPE is NULL, determine symbol type from the die, otherwise
11553 used the passed type.
11554 If SPACE is not NULL, use it to hold the new symbol. If it is
11555 NULL, allocate a new symbol on the objfile's obstack. */
11557 static struct symbol
*
11558 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
11559 struct symbol
*space
)
11561 struct objfile
*objfile
= cu
->objfile
;
11562 struct symbol
*sym
= NULL
;
11564 struct attribute
*attr
= NULL
;
11565 struct attribute
*attr2
= NULL
;
11566 CORE_ADDR baseaddr
;
11567 struct pending
**list_to_add
= NULL
;
11569 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
11571 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11573 name
= dwarf2_name (die
, cu
);
11576 const char *linkagename
;
11577 int suppress_add
= 0;
11582 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
11583 OBJSTAT (objfile
, n_syms
++);
11585 /* Cache this symbol's name and the name's demangled form (if any). */
11586 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
11587 linkagename
= dwarf2_physname (name
, die
, cu
);
11588 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
11590 /* Fortran does not have mangling standard and the mangling does differ
11591 between gfortran, iFort etc. */
11592 if (cu
->language
== language_fortran
11593 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
11594 symbol_set_demangled_name (&(sym
->ginfo
),
11595 (char *) dwarf2_full_name (name
, die
, cu
),
11598 /* Default assumptions.
11599 Use the passed type or decode it from the die. */
11600 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11601 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11603 SYMBOL_TYPE (sym
) = type
;
11605 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
11606 attr
= dwarf2_attr (die
,
11607 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
11611 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
11614 attr
= dwarf2_attr (die
,
11615 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
11619 int file_index
= DW_UNSND (attr
);
11621 if (cu
->line_header
== NULL
11622 || file_index
> cu
->line_header
->num_file_names
)
11623 complaint (&symfile_complaints
,
11624 _("file index out of range"));
11625 else if (file_index
> 0)
11627 struct file_entry
*fe
;
11629 fe
= &cu
->line_header
->file_names
[file_index
- 1];
11630 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
11637 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11640 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
11642 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
11643 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
11644 SYMBOL_CLASS (sym
) = LOC_LABEL
;
11645 add_symbol_to_list (sym
, cu
->list_in_scope
);
11647 case DW_TAG_subprogram
:
11648 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11650 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11651 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11652 if ((attr2
&& (DW_UNSND (attr2
) != 0))
11653 || cu
->language
== language_ada
)
11655 /* Subprograms marked external are stored as a global symbol.
11656 Ada subprograms, whether marked external or not, are always
11657 stored as a global symbol, because we want to be able to
11658 access them globally. For instance, we want to be able
11659 to break on a nested subprogram without having to
11660 specify the context. */
11661 list_to_add
= &global_symbols
;
11665 list_to_add
= cu
->list_in_scope
;
11668 case DW_TAG_inlined_subroutine
:
11669 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11671 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11672 SYMBOL_INLINED (sym
) = 1;
11673 /* Do not add the symbol to any lists. It will be found via
11674 BLOCK_FUNCTION from the blockvector. */
11676 case DW_TAG_template_value_param
:
11678 /* Fall through. */
11679 case DW_TAG_constant
:
11680 case DW_TAG_variable
:
11681 case DW_TAG_member
:
11682 /* Compilation with minimal debug info may result in
11683 variables with missing type entries. Change the
11684 misleading `void' type to something sensible. */
11685 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
11687 = objfile_type (objfile
)->nodebug_data_symbol
;
11689 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11690 /* In the case of DW_TAG_member, we should only be called for
11691 static const members. */
11692 if (die
->tag
== DW_TAG_member
)
11694 /* dwarf2_add_field uses die_is_declaration,
11695 so we do the same. */
11696 gdb_assert (die_is_declaration (die
, cu
));
11701 dwarf2_const_value (attr
, sym
, cu
);
11702 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11705 if (attr2
&& (DW_UNSND (attr2
) != 0))
11706 list_to_add
= &global_symbols
;
11708 list_to_add
= cu
->list_in_scope
;
11712 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11715 var_decode_location (attr
, sym
, cu
);
11716 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11717 if (SYMBOL_CLASS (sym
) == LOC_STATIC
11718 && SYMBOL_VALUE_ADDRESS (sym
) == 0
11719 && !dwarf2_per_objfile
->has_section_at_zero
)
11721 /* When a static variable is eliminated by the linker,
11722 the corresponding debug information is not stripped
11723 out, but the variable address is set to null;
11724 do not add such variables into symbol table. */
11726 else if (attr2
&& (DW_UNSND (attr2
) != 0))
11728 /* Workaround gfortran PR debug/40040 - it uses
11729 DW_AT_location for variables in -fPIC libraries which may
11730 get overriden by other libraries/executable and get
11731 a different address. Resolve it by the minimal symbol
11732 which may come from inferior's executable using copy
11733 relocation. Make this workaround only for gfortran as for
11734 other compilers GDB cannot guess the minimal symbol
11735 Fortran mangling kind. */
11736 if (cu
->language
== language_fortran
&& die
->parent
11737 && die
->parent
->tag
== DW_TAG_module
11739 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
11740 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11742 /* A variable with DW_AT_external is never static,
11743 but it may be block-scoped. */
11744 list_to_add
= (cu
->list_in_scope
== &file_symbols
11745 ? &global_symbols
: cu
->list_in_scope
);
11748 list_to_add
= cu
->list_in_scope
;
11752 /* We do not know the address of this symbol.
11753 If it is an external symbol and we have type information
11754 for it, enter the symbol as a LOC_UNRESOLVED symbol.
11755 The address of the variable will then be determined from
11756 the minimal symbol table whenever the variable is
11758 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11759 if (attr2
&& (DW_UNSND (attr2
) != 0)
11760 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
11762 /* A variable with DW_AT_external is never static, but it
11763 may be block-scoped. */
11764 list_to_add
= (cu
->list_in_scope
== &file_symbols
11765 ? &global_symbols
: cu
->list_in_scope
);
11767 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11769 else if (!die_is_declaration (die
, cu
))
11771 /* Use the default LOC_OPTIMIZED_OUT class. */
11772 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
11774 list_to_add
= cu
->list_in_scope
;
11778 case DW_TAG_formal_parameter
:
11779 /* If we are inside a function, mark this as an argument. If
11780 not, we might be looking at an argument to an inlined function
11781 when we do not have enough information to show inlined frames;
11782 pretend it's a local variable in that case so that the user can
11784 if (context_stack_depth
> 0
11785 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
11786 SYMBOL_IS_ARGUMENT (sym
) = 1;
11787 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11790 var_decode_location (attr
, sym
, cu
);
11792 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11795 dwarf2_const_value (attr
, sym
, cu
);
11798 list_to_add
= cu
->list_in_scope
;
11800 case DW_TAG_unspecified_parameters
:
11801 /* From varargs functions; gdb doesn't seem to have any
11802 interest in this information, so just ignore it for now.
11805 case DW_TAG_template_type_param
:
11807 /* Fall through. */
11808 case DW_TAG_class_type
:
11809 case DW_TAG_interface_type
:
11810 case DW_TAG_structure_type
:
11811 case DW_TAG_union_type
:
11812 case DW_TAG_set_type
:
11813 case DW_TAG_enumeration_type
:
11814 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11815 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
11818 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
11819 really ever be static objects: otherwise, if you try
11820 to, say, break of a class's method and you're in a file
11821 which doesn't mention that class, it won't work unless
11822 the check for all static symbols in lookup_symbol_aux
11823 saves you. See the OtherFileClass tests in
11824 gdb.c++/namespace.exp. */
11828 list_to_add
= (cu
->list_in_scope
== &file_symbols
11829 && (cu
->language
== language_cplus
11830 || cu
->language
== language_java
)
11831 ? &global_symbols
: cu
->list_in_scope
);
11833 /* The semantics of C++ state that "struct foo {
11834 ... }" also defines a typedef for "foo". A Java
11835 class declaration also defines a typedef for the
11837 if (cu
->language
== language_cplus
11838 || cu
->language
== language_java
11839 || cu
->language
== language_ada
)
11841 /* The symbol's name is already allocated along
11842 with this objfile, so we don't need to
11843 duplicate it for the type. */
11844 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
11845 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
11850 case DW_TAG_typedef
:
11851 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11852 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11853 list_to_add
= cu
->list_in_scope
;
11855 case DW_TAG_base_type
:
11856 case DW_TAG_subrange_type
:
11857 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11858 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11859 list_to_add
= cu
->list_in_scope
;
11861 case DW_TAG_enumerator
:
11862 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11865 dwarf2_const_value (attr
, sym
, cu
);
11868 /* NOTE: carlton/2003-11-10: See comment above in the
11869 DW_TAG_class_type, etc. block. */
11871 list_to_add
= (cu
->list_in_scope
== &file_symbols
11872 && (cu
->language
== language_cplus
11873 || cu
->language
== language_java
)
11874 ? &global_symbols
: cu
->list_in_scope
);
11877 case DW_TAG_namespace
:
11878 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11879 list_to_add
= &global_symbols
;
11882 /* Not a tag we recognize. Hopefully we aren't processing
11883 trash data, but since we must specifically ignore things
11884 we don't recognize, there is nothing else we should do at
11886 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
11887 dwarf_tag_name (die
->tag
));
11893 sym
->hash_next
= objfile
->template_symbols
;
11894 objfile
->template_symbols
= sym
;
11895 list_to_add
= NULL
;
11898 if (list_to_add
!= NULL
)
11899 add_symbol_to_list (sym
, list_to_add
);
11901 /* For the benefit of old versions of GCC, check for anonymous
11902 namespaces based on the demangled name. */
11903 if (!processing_has_namespace_info
11904 && cu
->language
== language_cplus
)
11905 cp_scan_for_anonymous_namespaces (sym
, objfile
);
11910 /* A wrapper for new_symbol_full that always allocates a new symbol. */
11912 static struct symbol
*
11913 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
11915 return new_symbol_full (die
, type
, cu
, NULL
);
11918 /* Given an attr with a DW_FORM_dataN value in host byte order,
11919 zero-extend it as appropriate for the symbol's type. The DWARF
11920 standard (v4) is not entirely clear about the meaning of using
11921 DW_FORM_dataN for a constant with a signed type, where the type is
11922 wider than the data. The conclusion of a discussion on the DWARF
11923 list was that this is unspecified. We choose to always zero-extend
11924 because that is the interpretation long in use by GCC. */
11927 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
11928 const char *name
, struct obstack
*obstack
,
11929 struct dwarf2_cu
*cu
, long *value
, int bits
)
11931 struct objfile
*objfile
= cu
->objfile
;
11932 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
11933 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
11934 LONGEST l
= DW_UNSND (attr
);
11936 if (bits
< sizeof (*value
) * 8)
11938 l
&= ((LONGEST
) 1 << bits
) - 1;
11941 else if (bits
== sizeof (*value
) * 8)
11945 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
11946 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
11953 /* Read a constant value from an attribute. Either set *VALUE, or if
11954 the value does not fit in *VALUE, set *BYTES - either already
11955 allocated on the objfile obstack, or newly allocated on OBSTACK,
11956 or, set *BATON, if we translated the constant to a location
11960 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
11961 const char *name
, struct obstack
*obstack
,
11962 struct dwarf2_cu
*cu
,
11963 long *value
, gdb_byte
**bytes
,
11964 struct dwarf2_locexpr_baton
**baton
)
11966 struct objfile
*objfile
= cu
->objfile
;
11967 struct comp_unit_head
*cu_header
= &cu
->header
;
11968 struct dwarf_block
*blk
;
11969 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
11970 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
11976 switch (attr
->form
)
11982 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
11983 dwarf2_const_value_length_mismatch_complaint (name
,
11984 cu_header
->addr_size
,
11985 TYPE_LENGTH (type
));
11986 /* Symbols of this form are reasonably rare, so we just
11987 piggyback on the existing location code rather than writing
11988 a new implementation of symbol_computed_ops. */
11989 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
11990 sizeof (struct dwarf2_locexpr_baton
));
11991 (*baton
)->per_cu
= cu
->per_cu
;
11992 gdb_assert ((*baton
)->per_cu
);
11994 (*baton
)->size
= 2 + cu_header
->addr_size
;
11995 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
11996 (*baton
)->data
= data
;
11998 data
[0] = DW_OP_addr
;
11999 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
12000 byte_order
, DW_ADDR (attr
));
12001 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
12004 case DW_FORM_string
:
12006 /* DW_STRING is already allocated on the objfile obstack, point
12008 *bytes
= (gdb_byte
*) DW_STRING (attr
);
12010 case DW_FORM_block1
:
12011 case DW_FORM_block2
:
12012 case DW_FORM_block4
:
12013 case DW_FORM_block
:
12014 case DW_FORM_exprloc
:
12015 blk
= DW_BLOCK (attr
);
12016 if (TYPE_LENGTH (type
) != blk
->size
)
12017 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
12018 TYPE_LENGTH (type
));
12019 *bytes
= blk
->data
;
12022 /* The DW_AT_const_value attributes are supposed to carry the
12023 symbol's value "represented as it would be on the target
12024 architecture." By the time we get here, it's already been
12025 converted to host endianness, so we just need to sign- or
12026 zero-extend it as appropriate. */
12027 case DW_FORM_data1
:
12028 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12029 obstack
, cu
, value
, 8);
12031 case DW_FORM_data2
:
12032 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12033 obstack
, cu
, value
, 16);
12035 case DW_FORM_data4
:
12036 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12037 obstack
, cu
, value
, 32);
12039 case DW_FORM_data8
:
12040 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12041 obstack
, cu
, value
, 64);
12044 case DW_FORM_sdata
:
12045 *value
= DW_SND (attr
);
12048 case DW_FORM_udata
:
12049 *value
= DW_UNSND (attr
);
12053 complaint (&symfile_complaints
,
12054 _("unsupported const value attribute form: '%s'"),
12055 dwarf_form_name (attr
->form
));
12062 /* Copy constant value from an attribute to a symbol. */
12065 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
12066 struct dwarf2_cu
*cu
)
12068 struct objfile
*objfile
= cu
->objfile
;
12069 struct comp_unit_head
*cu_header
= &cu
->header
;
12072 struct dwarf2_locexpr_baton
*baton
;
12074 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
12075 SYMBOL_PRINT_NAME (sym
),
12076 &objfile
->objfile_obstack
, cu
,
12077 &value
, &bytes
, &baton
);
12081 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
12082 SYMBOL_LOCATION_BATON (sym
) = baton
;
12083 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
12085 else if (bytes
!= NULL
)
12087 SYMBOL_VALUE_BYTES (sym
) = bytes
;
12088 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
12092 SYMBOL_VALUE (sym
) = value
;
12093 SYMBOL_CLASS (sym
) = LOC_CONST
;
12097 /* Return the type of the die in question using its DW_AT_type attribute. */
12099 static struct type
*
12100 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12102 struct attribute
*type_attr
;
12104 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
12107 /* A missing DW_AT_type represents a void type. */
12108 return objfile_type (cu
->objfile
)->builtin_void
;
12111 return lookup_die_type (die
, type_attr
, cu
);
12114 /* True iff CU's producer generates GNAT Ada auxiliary information
12115 that allows to find parallel types through that information instead
12116 of having to do expensive parallel lookups by type name. */
12119 need_gnat_info (struct dwarf2_cu
*cu
)
12121 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
12122 of GNAT produces this auxiliary information, without any indication
12123 that it is produced. Part of enhancing the FSF version of GNAT
12124 to produce that information will be to put in place an indicator
12125 that we can use in order to determine whether the descriptive type
12126 info is available or not. One suggestion that has been made is
12127 to use a new attribute, attached to the CU die. For now, assume
12128 that the descriptive type info is not available. */
12132 /* Return the auxiliary type of the die in question using its
12133 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
12134 attribute is not present. */
12136 static struct type
*
12137 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12139 struct attribute
*type_attr
;
12141 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
12145 return lookup_die_type (die
, type_attr
, cu
);
12148 /* If DIE has a descriptive_type attribute, then set the TYPE's
12149 descriptive type accordingly. */
12152 set_descriptive_type (struct type
*type
, struct die_info
*die
,
12153 struct dwarf2_cu
*cu
)
12155 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
12157 if (descriptive_type
)
12159 ALLOCATE_GNAT_AUX_TYPE (type
);
12160 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
12164 /* Return the containing type of the die in question using its
12165 DW_AT_containing_type attribute. */
12167 static struct type
*
12168 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12170 struct attribute
*type_attr
;
12172 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
12174 error (_("Dwarf Error: Problem turning containing type into gdb type "
12175 "[in module %s]"), cu
->objfile
->name
);
12177 return lookup_die_type (die
, type_attr
, cu
);
12180 /* Look up the type of DIE in CU using its type attribute ATTR.
12181 If there is no type substitute an error marker. */
12183 static struct type
*
12184 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
12185 struct dwarf2_cu
*cu
)
12187 struct objfile
*objfile
= cu
->objfile
;
12188 struct type
*this_type
;
12190 /* First see if we have it cached. */
12192 if (is_ref_attr (attr
))
12194 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
12196 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
12198 else if (attr
->form
== DW_FORM_ref_sig8
)
12200 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
12201 struct dwarf2_cu
*sig_cu
;
12202 unsigned int offset
;
12204 /* sig_type will be NULL if the signatured type is missing from
12206 if (sig_type
== NULL
)
12207 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
12208 "at 0x%x [in module %s]"),
12209 die
->offset
, objfile
->name
);
12211 gdb_assert (sig_type
->per_cu
.debug_types_section
);
12212 offset
= sig_type
->per_cu
.offset
+ sig_type
->type_offset
;
12213 this_type
= get_die_type_at_offset (offset
, &sig_type
->per_cu
);
12217 dump_die_for_error (die
);
12218 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
12219 dwarf_attr_name (attr
->name
), objfile
->name
);
12222 /* If not cached we need to read it in. */
12224 if (this_type
== NULL
)
12226 struct die_info
*type_die
;
12227 struct dwarf2_cu
*type_cu
= cu
;
12229 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
12230 /* If the type is cached, we should have found it above. */
12231 gdb_assert (get_die_type (type_die
, type_cu
) == NULL
);
12232 this_type
= read_type_die_1 (type_die
, type_cu
);
12235 /* If we still don't have a type use an error marker. */
12237 if (this_type
== NULL
)
12239 char *message
, *saved
;
12241 /* read_type_die already issued a complaint. */
12242 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
12246 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
12247 message
, strlen (message
));
12250 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
12256 /* Return the type in DIE, CU.
12257 Returns NULL for invalid types.
12259 This first does a lookup in the appropriate type_hash table,
12260 and only reads the die in if necessary.
12262 NOTE: This can be called when reading in partial or full symbols. */
12264 static struct type
*
12265 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
12267 struct type
*this_type
;
12269 this_type
= get_die_type (die
, cu
);
12273 return read_type_die_1 (die
, cu
);
12276 /* Read the type in DIE, CU.
12277 Returns NULL for invalid types. */
12279 static struct type
*
12280 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
12282 struct type
*this_type
= NULL
;
12286 case DW_TAG_class_type
:
12287 case DW_TAG_interface_type
:
12288 case DW_TAG_structure_type
:
12289 case DW_TAG_union_type
:
12290 this_type
= read_structure_type (die
, cu
);
12292 case DW_TAG_enumeration_type
:
12293 this_type
= read_enumeration_type (die
, cu
);
12295 case DW_TAG_subprogram
:
12296 case DW_TAG_subroutine_type
:
12297 case DW_TAG_inlined_subroutine
:
12298 this_type
= read_subroutine_type (die
, cu
);
12300 case DW_TAG_array_type
:
12301 this_type
= read_array_type (die
, cu
);
12303 case DW_TAG_set_type
:
12304 this_type
= read_set_type (die
, cu
);
12306 case DW_TAG_pointer_type
:
12307 this_type
= read_tag_pointer_type (die
, cu
);
12309 case DW_TAG_ptr_to_member_type
:
12310 this_type
= read_tag_ptr_to_member_type (die
, cu
);
12312 case DW_TAG_reference_type
:
12313 this_type
= read_tag_reference_type (die
, cu
);
12315 case DW_TAG_const_type
:
12316 this_type
= read_tag_const_type (die
, cu
);
12318 case DW_TAG_volatile_type
:
12319 this_type
= read_tag_volatile_type (die
, cu
);
12321 case DW_TAG_string_type
:
12322 this_type
= read_tag_string_type (die
, cu
);
12324 case DW_TAG_typedef
:
12325 this_type
= read_typedef (die
, cu
);
12327 case DW_TAG_subrange_type
:
12328 this_type
= read_subrange_type (die
, cu
);
12330 case DW_TAG_base_type
:
12331 this_type
= read_base_type (die
, cu
);
12333 case DW_TAG_unspecified_type
:
12334 this_type
= read_unspecified_type (die
, cu
);
12336 case DW_TAG_namespace
:
12337 this_type
= read_namespace_type (die
, cu
);
12339 case DW_TAG_module
:
12340 this_type
= read_module_type (die
, cu
);
12343 complaint (&symfile_complaints
,
12344 _("unexpected tag in read_type_die: '%s'"),
12345 dwarf_tag_name (die
->tag
));
12352 /* See if we can figure out if the class lives in a namespace. We do
12353 this by looking for a member function; its demangled name will
12354 contain namespace info, if there is any.
12355 Return the computed name or NULL.
12356 Space for the result is allocated on the objfile's obstack.
12357 This is the full-die version of guess_partial_die_structure_name.
12358 In this case we know DIE has no useful parent. */
12361 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12363 struct die_info
*spec_die
;
12364 struct dwarf2_cu
*spec_cu
;
12365 struct die_info
*child
;
12368 spec_die
= die_specification (die
, &spec_cu
);
12369 if (spec_die
!= NULL
)
12375 for (child
= die
->child
;
12377 child
= child
->sibling
)
12379 if (child
->tag
== DW_TAG_subprogram
)
12381 struct attribute
*attr
;
12383 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
12385 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
12389 = language_class_name_from_physname (cu
->language_defn
,
12393 if (actual_name
!= NULL
)
12395 char *die_name
= dwarf2_name (die
, cu
);
12397 if (die_name
!= NULL
12398 && strcmp (die_name
, actual_name
) != 0)
12400 /* Strip off the class name from the full name.
12401 We want the prefix. */
12402 int die_name_len
= strlen (die_name
);
12403 int actual_name_len
= strlen (actual_name
);
12405 /* Test for '::' as a sanity check. */
12406 if (actual_name_len
> die_name_len
+ 2
12407 && actual_name
[actual_name_len
12408 - die_name_len
- 1] == ':')
12410 obsavestring (actual_name
,
12411 actual_name_len
- die_name_len
- 2,
12412 &cu
->objfile
->objfile_obstack
);
12415 xfree (actual_name
);
12424 /* GCC might emit a nameless typedef that has a linkage name. Determine the
12425 prefix part in such case. See
12426 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12429 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
12431 struct attribute
*attr
;
12434 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
12435 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
12438 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
12439 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
12442 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
12444 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
12445 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
12448 /* dwarf2_name had to be already called. */
12449 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
12451 /* Strip the base name, keep any leading namespaces/classes. */
12452 base
= strrchr (DW_STRING (attr
), ':');
12453 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
12456 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
12457 &cu
->objfile
->objfile_obstack
);
12460 /* Return the name of the namespace/class that DIE is defined within,
12461 or "" if we can't tell. The caller should not xfree the result.
12463 For example, if we're within the method foo() in the following
12473 then determine_prefix on foo's die will return "N::C". */
12475 static const char *
12476 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
12478 struct die_info
*parent
, *spec_die
;
12479 struct dwarf2_cu
*spec_cu
;
12480 struct type
*parent_type
;
12483 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
12484 && cu
->language
!= language_fortran
)
12487 retval
= anonymous_struct_prefix (die
, cu
);
12491 /* We have to be careful in the presence of DW_AT_specification.
12492 For example, with GCC 3.4, given the code
12496 // Definition of N::foo.
12500 then we'll have a tree of DIEs like this:
12502 1: DW_TAG_compile_unit
12503 2: DW_TAG_namespace // N
12504 3: DW_TAG_subprogram // declaration of N::foo
12505 4: DW_TAG_subprogram // definition of N::foo
12506 DW_AT_specification // refers to die #3
12508 Thus, when processing die #4, we have to pretend that we're in
12509 the context of its DW_AT_specification, namely the contex of die
12512 spec_die
= die_specification (die
, &spec_cu
);
12513 if (spec_die
== NULL
)
12514 parent
= die
->parent
;
12517 parent
= spec_die
->parent
;
12521 if (parent
== NULL
)
12523 else if (parent
->building_fullname
)
12526 const char *parent_name
;
12528 /* It has been seen on RealView 2.2 built binaries,
12529 DW_TAG_template_type_param types actually _defined_ as
12530 children of the parent class:
12533 template class <class Enum> Class{};
12534 Class<enum E> class_e;
12536 1: DW_TAG_class_type (Class)
12537 2: DW_TAG_enumeration_type (E)
12538 3: DW_TAG_enumerator (enum1:0)
12539 3: DW_TAG_enumerator (enum2:1)
12541 2: DW_TAG_template_type_param
12542 DW_AT_type DW_FORM_ref_udata (E)
12544 Besides being broken debug info, it can put GDB into an
12545 infinite loop. Consider:
12547 When we're building the full name for Class<E>, we'll start
12548 at Class, and go look over its template type parameters,
12549 finding E. We'll then try to build the full name of E, and
12550 reach here. We're now trying to build the full name of E,
12551 and look over the parent DIE for containing scope. In the
12552 broken case, if we followed the parent DIE of E, we'd again
12553 find Class, and once again go look at its template type
12554 arguments, etc., etc. Simply don't consider such parent die
12555 as source-level parent of this die (it can't be, the language
12556 doesn't allow it), and break the loop here. */
12557 name
= dwarf2_name (die
, cu
);
12558 parent_name
= dwarf2_name (parent
, cu
);
12559 complaint (&symfile_complaints
,
12560 _("template param type '%s' defined within parent '%s'"),
12561 name
? name
: "<unknown>",
12562 parent_name
? parent_name
: "<unknown>");
12566 switch (parent
->tag
)
12568 case DW_TAG_namespace
:
12569 parent_type
= read_type_die (parent
, cu
);
12570 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
12571 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
12572 Work around this problem here. */
12573 if (cu
->language
== language_cplus
12574 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
12576 /* We give a name to even anonymous namespaces. */
12577 return TYPE_TAG_NAME (parent_type
);
12578 case DW_TAG_class_type
:
12579 case DW_TAG_interface_type
:
12580 case DW_TAG_structure_type
:
12581 case DW_TAG_union_type
:
12582 case DW_TAG_module
:
12583 parent_type
= read_type_die (parent
, cu
);
12584 if (TYPE_TAG_NAME (parent_type
) != NULL
)
12585 return TYPE_TAG_NAME (parent_type
);
12587 /* An anonymous structure is only allowed non-static data
12588 members; no typedefs, no member functions, et cetera.
12589 So it does not need a prefix. */
12591 case DW_TAG_compile_unit
:
12592 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
12593 if (cu
->language
== language_cplus
12594 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
12595 && die
->child
!= NULL
12596 && (die
->tag
== DW_TAG_class_type
12597 || die
->tag
== DW_TAG_structure_type
12598 || die
->tag
== DW_TAG_union_type
))
12600 char *name
= guess_full_die_structure_name (die
, cu
);
12606 return determine_prefix (parent
, cu
);
12610 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
12611 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
12612 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
12613 an obconcat, otherwise allocate storage for the result. The CU argument is
12614 used to determine the language and hence, the appropriate separator. */
12616 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
12619 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
12620 int physname
, struct dwarf2_cu
*cu
)
12622 const char *lead
= "";
12625 if (suffix
== NULL
|| suffix
[0] == '\0'
12626 || prefix
== NULL
|| prefix
[0] == '\0')
12628 else if (cu
->language
== language_java
)
12630 else if (cu
->language
== language_fortran
&& physname
)
12632 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
12633 DW_AT_MIPS_linkage_name is preferred and used instead. */
12641 if (prefix
== NULL
)
12643 if (suffix
== NULL
)
12649 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
12651 strcpy (retval
, lead
);
12652 strcat (retval
, prefix
);
12653 strcat (retval
, sep
);
12654 strcat (retval
, suffix
);
12659 /* We have an obstack. */
12660 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
12664 /* Return sibling of die, NULL if no sibling. */
12666 static struct die_info
*
12667 sibling_die (struct die_info
*die
)
12669 return die
->sibling
;
12672 /* Get name of a die, return NULL if not found. */
12675 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
12676 struct obstack
*obstack
)
12678 if (name
&& cu
->language
== language_cplus
)
12680 char *canon_name
= cp_canonicalize_string (name
);
12682 if (canon_name
!= NULL
)
12684 if (strcmp (canon_name
, name
) != 0)
12685 name
= obsavestring (canon_name
, strlen (canon_name
),
12687 xfree (canon_name
);
12694 /* Get name of a die, return NULL if not found. */
12697 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12699 struct attribute
*attr
;
12701 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
12702 if ((!attr
|| !DW_STRING (attr
))
12703 && die
->tag
!= DW_TAG_class_type
12704 && die
->tag
!= DW_TAG_interface_type
12705 && die
->tag
!= DW_TAG_structure_type
12706 && die
->tag
!= DW_TAG_union_type
)
12711 case DW_TAG_compile_unit
:
12712 /* Compilation units have a DW_AT_name that is a filename, not
12713 a source language identifier. */
12714 case DW_TAG_enumeration_type
:
12715 case DW_TAG_enumerator
:
12716 /* These tags always have simple identifiers already; no need
12717 to canonicalize them. */
12718 return DW_STRING (attr
);
12720 case DW_TAG_subprogram
:
12721 /* Java constructors will all be named "<init>", so return
12722 the class name when we see this special case. */
12723 if (cu
->language
== language_java
12724 && DW_STRING (attr
) != NULL
12725 && strcmp (DW_STRING (attr
), "<init>") == 0)
12727 struct dwarf2_cu
*spec_cu
= cu
;
12728 struct die_info
*spec_die
;
12730 /* GCJ will output '<init>' for Java constructor names.
12731 For this special case, return the name of the parent class. */
12733 /* GCJ may output suprogram DIEs with AT_specification set.
12734 If so, use the name of the specified DIE. */
12735 spec_die
= die_specification (die
, &spec_cu
);
12736 if (spec_die
!= NULL
)
12737 return dwarf2_name (spec_die
, spec_cu
);
12742 if (die
->tag
== DW_TAG_class_type
)
12743 return dwarf2_name (die
, cu
);
12745 while (die
->tag
!= DW_TAG_compile_unit
);
12749 case DW_TAG_class_type
:
12750 case DW_TAG_interface_type
:
12751 case DW_TAG_structure_type
:
12752 case DW_TAG_union_type
:
12753 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
12754 structures or unions. These were of the form "._%d" in GCC 4.1,
12755 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
12756 and GCC 4.4. We work around this problem by ignoring these. */
12757 if (attr
&& DW_STRING (attr
)
12758 && (strncmp (DW_STRING (attr
), "._", 2) == 0
12759 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
12762 /* GCC might emit a nameless typedef that has a linkage name. See
12763 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12764 if (!attr
|| DW_STRING (attr
) == NULL
)
12766 char *demangled
= NULL
;
12768 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
12770 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
12772 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
12775 /* Avoid demangling DW_STRING (attr) the second time on a second
12776 call for the same DIE. */
12777 if (!DW_STRING_IS_CANONICAL (attr
))
12778 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
12784 /* FIXME: we already did this for the partial symbol... */
12785 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
12786 &cu
->objfile
->objfile_obstack
);
12787 DW_STRING_IS_CANONICAL (attr
) = 1;
12790 /* Strip any leading namespaces/classes, keep only the base name.
12791 DW_AT_name for named DIEs does not contain the prefixes. */
12792 base
= strrchr (DW_STRING (attr
), ':');
12793 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
12796 return DW_STRING (attr
);
12805 if (!DW_STRING_IS_CANONICAL (attr
))
12808 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
12809 &cu
->objfile
->objfile_obstack
);
12810 DW_STRING_IS_CANONICAL (attr
) = 1;
12812 return DW_STRING (attr
);
12815 /* Return the die that this die in an extension of, or NULL if there
12816 is none. *EXT_CU is the CU containing DIE on input, and the CU
12817 containing the return value on output. */
12819 static struct die_info
*
12820 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
12822 struct attribute
*attr
;
12824 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
12828 return follow_die_ref (die
, attr
, ext_cu
);
12831 /* Convert a DIE tag into its string name. */
12834 dwarf_tag_name (unsigned tag
)
12838 case DW_TAG_padding
:
12839 return "DW_TAG_padding";
12840 case DW_TAG_array_type
:
12841 return "DW_TAG_array_type";
12842 case DW_TAG_class_type
:
12843 return "DW_TAG_class_type";
12844 case DW_TAG_entry_point
:
12845 return "DW_TAG_entry_point";
12846 case DW_TAG_enumeration_type
:
12847 return "DW_TAG_enumeration_type";
12848 case DW_TAG_formal_parameter
:
12849 return "DW_TAG_formal_parameter";
12850 case DW_TAG_imported_declaration
:
12851 return "DW_TAG_imported_declaration";
12853 return "DW_TAG_label";
12854 case DW_TAG_lexical_block
:
12855 return "DW_TAG_lexical_block";
12856 case DW_TAG_member
:
12857 return "DW_TAG_member";
12858 case DW_TAG_pointer_type
:
12859 return "DW_TAG_pointer_type";
12860 case DW_TAG_reference_type
:
12861 return "DW_TAG_reference_type";
12862 case DW_TAG_compile_unit
:
12863 return "DW_TAG_compile_unit";
12864 case DW_TAG_string_type
:
12865 return "DW_TAG_string_type";
12866 case DW_TAG_structure_type
:
12867 return "DW_TAG_structure_type";
12868 case DW_TAG_subroutine_type
:
12869 return "DW_TAG_subroutine_type";
12870 case DW_TAG_typedef
:
12871 return "DW_TAG_typedef";
12872 case DW_TAG_union_type
:
12873 return "DW_TAG_union_type";
12874 case DW_TAG_unspecified_parameters
:
12875 return "DW_TAG_unspecified_parameters";
12876 case DW_TAG_variant
:
12877 return "DW_TAG_variant";
12878 case DW_TAG_common_block
:
12879 return "DW_TAG_common_block";
12880 case DW_TAG_common_inclusion
:
12881 return "DW_TAG_common_inclusion";
12882 case DW_TAG_inheritance
:
12883 return "DW_TAG_inheritance";
12884 case DW_TAG_inlined_subroutine
:
12885 return "DW_TAG_inlined_subroutine";
12886 case DW_TAG_module
:
12887 return "DW_TAG_module";
12888 case DW_TAG_ptr_to_member_type
:
12889 return "DW_TAG_ptr_to_member_type";
12890 case DW_TAG_set_type
:
12891 return "DW_TAG_set_type";
12892 case DW_TAG_subrange_type
:
12893 return "DW_TAG_subrange_type";
12894 case DW_TAG_with_stmt
:
12895 return "DW_TAG_with_stmt";
12896 case DW_TAG_access_declaration
:
12897 return "DW_TAG_access_declaration";
12898 case DW_TAG_base_type
:
12899 return "DW_TAG_base_type";
12900 case DW_TAG_catch_block
:
12901 return "DW_TAG_catch_block";
12902 case DW_TAG_const_type
:
12903 return "DW_TAG_const_type";
12904 case DW_TAG_constant
:
12905 return "DW_TAG_constant";
12906 case DW_TAG_enumerator
:
12907 return "DW_TAG_enumerator";
12908 case DW_TAG_file_type
:
12909 return "DW_TAG_file_type";
12910 case DW_TAG_friend
:
12911 return "DW_TAG_friend";
12912 case DW_TAG_namelist
:
12913 return "DW_TAG_namelist";
12914 case DW_TAG_namelist_item
:
12915 return "DW_TAG_namelist_item";
12916 case DW_TAG_packed_type
:
12917 return "DW_TAG_packed_type";
12918 case DW_TAG_subprogram
:
12919 return "DW_TAG_subprogram";
12920 case DW_TAG_template_type_param
:
12921 return "DW_TAG_template_type_param";
12922 case DW_TAG_template_value_param
:
12923 return "DW_TAG_template_value_param";
12924 case DW_TAG_thrown_type
:
12925 return "DW_TAG_thrown_type";
12926 case DW_TAG_try_block
:
12927 return "DW_TAG_try_block";
12928 case DW_TAG_variant_part
:
12929 return "DW_TAG_variant_part";
12930 case DW_TAG_variable
:
12931 return "DW_TAG_variable";
12932 case DW_TAG_volatile_type
:
12933 return "DW_TAG_volatile_type";
12934 case DW_TAG_dwarf_procedure
:
12935 return "DW_TAG_dwarf_procedure";
12936 case DW_TAG_restrict_type
:
12937 return "DW_TAG_restrict_type";
12938 case DW_TAG_interface_type
:
12939 return "DW_TAG_interface_type";
12940 case DW_TAG_namespace
:
12941 return "DW_TAG_namespace";
12942 case DW_TAG_imported_module
:
12943 return "DW_TAG_imported_module";
12944 case DW_TAG_unspecified_type
:
12945 return "DW_TAG_unspecified_type";
12946 case DW_TAG_partial_unit
:
12947 return "DW_TAG_partial_unit";
12948 case DW_TAG_imported_unit
:
12949 return "DW_TAG_imported_unit";
12950 case DW_TAG_condition
:
12951 return "DW_TAG_condition";
12952 case DW_TAG_shared_type
:
12953 return "DW_TAG_shared_type";
12954 case DW_TAG_type_unit
:
12955 return "DW_TAG_type_unit";
12956 case DW_TAG_MIPS_loop
:
12957 return "DW_TAG_MIPS_loop";
12958 case DW_TAG_HP_array_descriptor
:
12959 return "DW_TAG_HP_array_descriptor";
12960 case DW_TAG_format_label
:
12961 return "DW_TAG_format_label";
12962 case DW_TAG_function_template
:
12963 return "DW_TAG_function_template";
12964 case DW_TAG_class_template
:
12965 return "DW_TAG_class_template";
12966 case DW_TAG_GNU_BINCL
:
12967 return "DW_TAG_GNU_BINCL";
12968 case DW_TAG_GNU_EINCL
:
12969 return "DW_TAG_GNU_EINCL";
12970 case DW_TAG_upc_shared_type
:
12971 return "DW_TAG_upc_shared_type";
12972 case DW_TAG_upc_strict_type
:
12973 return "DW_TAG_upc_strict_type";
12974 case DW_TAG_upc_relaxed_type
:
12975 return "DW_TAG_upc_relaxed_type";
12976 case DW_TAG_PGI_kanji_type
:
12977 return "DW_TAG_PGI_kanji_type";
12978 case DW_TAG_PGI_interface_block
:
12979 return "DW_TAG_PGI_interface_block";
12980 case DW_TAG_GNU_call_site
:
12981 return "DW_TAG_GNU_call_site";
12983 return "DW_TAG_<unknown>";
12987 /* Convert a DWARF attribute code into its string name. */
12990 dwarf_attr_name (unsigned attr
)
12994 case DW_AT_sibling
:
12995 return "DW_AT_sibling";
12996 case DW_AT_location
:
12997 return "DW_AT_location";
12999 return "DW_AT_name";
13000 case DW_AT_ordering
:
13001 return "DW_AT_ordering";
13002 case DW_AT_subscr_data
:
13003 return "DW_AT_subscr_data";
13004 case DW_AT_byte_size
:
13005 return "DW_AT_byte_size";
13006 case DW_AT_bit_offset
:
13007 return "DW_AT_bit_offset";
13008 case DW_AT_bit_size
:
13009 return "DW_AT_bit_size";
13010 case DW_AT_element_list
:
13011 return "DW_AT_element_list";
13012 case DW_AT_stmt_list
:
13013 return "DW_AT_stmt_list";
13015 return "DW_AT_low_pc";
13016 case DW_AT_high_pc
:
13017 return "DW_AT_high_pc";
13018 case DW_AT_language
:
13019 return "DW_AT_language";
13021 return "DW_AT_member";
13023 return "DW_AT_discr";
13024 case DW_AT_discr_value
:
13025 return "DW_AT_discr_value";
13026 case DW_AT_visibility
:
13027 return "DW_AT_visibility";
13029 return "DW_AT_import";
13030 case DW_AT_string_length
:
13031 return "DW_AT_string_length";
13032 case DW_AT_common_reference
:
13033 return "DW_AT_common_reference";
13034 case DW_AT_comp_dir
:
13035 return "DW_AT_comp_dir";
13036 case DW_AT_const_value
:
13037 return "DW_AT_const_value";
13038 case DW_AT_containing_type
:
13039 return "DW_AT_containing_type";
13040 case DW_AT_default_value
:
13041 return "DW_AT_default_value";
13043 return "DW_AT_inline";
13044 case DW_AT_is_optional
:
13045 return "DW_AT_is_optional";
13046 case DW_AT_lower_bound
:
13047 return "DW_AT_lower_bound";
13048 case DW_AT_producer
:
13049 return "DW_AT_producer";
13050 case DW_AT_prototyped
:
13051 return "DW_AT_prototyped";
13052 case DW_AT_return_addr
:
13053 return "DW_AT_return_addr";
13054 case DW_AT_start_scope
:
13055 return "DW_AT_start_scope";
13056 case DW_AT_bit_stride
:
13057 return "DW_AT_bit_stride";
13058 case DW_AT_upper_bound
:
13059 return "DW_AT_upper_bound";
13060 case DW_AT_abstract_origin
:
13061 return "DW_AT_abstract_origin";
13062 case DW_AT_accessibility
:
13063 return "DW_AT_accessibility";
13064 case DW_AT_address_class
:
13065 return "DW_AT_address_class";
13066 case DW_AT_artificial
:
13067 return "DW_AT_artificial";
13068 case DW_AT_base_types
:
13069 return "DW_AT_base_types";
13070 case DW_AT_calling_convention
:
13071 return "DW_AT_calling_convention";
13073 return "DW_AT_count";
13074 case DW_AT_data_member_location
:
13075 return "DW_AT_data_member_location";
13076 case DW_AT_decl_column
:
13077 return "DW_AT_decl_column";
13078 case DW_AT_decl_file
:
13079 return "DW_AT_decl_file";
13080 case DW_AT_decl_line
:
13081 return "DW_AT_decl_line";
13082 case DW_AT_declaration
:
13083 return "DW_AT_declaration";
13084 case DW_AT_discr_list
:
13085 return "DW_AT_discr_list";
13086 case DW_AT_encoding
:
13087 return "DW_AT_encoding";
13088 case DW_AT_external
:
13089 return "DW_AT_external";
13090 case DW_AT_frame_base
:
13091 return "DW_AT_frame_base";
13093 return "DW_AT_friend";
13094 case DW_AT_identifier_case
:
13095 return "DW_AT_identifier_case";
13096 case DW_AT_macro_info
:
13097 return "DW_AT_macro_info";
13098 case DW_AT_namelist_items
:
13099 return "DW_AT_namelist_items";
13100 case DW_AT_priority
:
13101 return "DW_AT_priority";
13102 case DW_AT_segment
:
13103 return "DW_AT_segment";
13104 case DW_AT_specification
:
13105 return "DW_AT_specification";
13106 case DW_AT_static_link
:
13107 return "DW_AT_static_link";
13109 return "DW_AT_type";
13110 case DW_AT_use_location
:
13111 return "DW_AT_use_location";
13112 case DW_AT_variable_parameter
:
13113 return "DW_AT_variable_parameter";
13114 case DW_AT_virtuality
:
13115 return "DW_AT_virtuality";
13116 case DW_AT_vtable_elem_location
:
13117 return "DW_AT_vtable_elem_location";
13118 /* DWARF 3 values. */
13119 case DW_AT_allocated
:
13120 return "DW_AT_allocated";
13121 case DW_AT_associated
:
13122 return "DW_AT_associated";
13123 case DW_AT_data_location
:
13124 return "DW_AT_data_location";
13125 case DW_AT_byte_stride
:
13126 return "DW_AT_byte_stride";
13127 case DW_AT_entry_pc
:
13128 return "DW_AT_entry_pc";
13129 case DW_AT_use_UTF8
:
13130 return "DW_AT_use_UTF8";
13131 case DW_AT_extension
:
13132 return "DW_AT_extension";
13134 return "DW_AT_ranges";
13135 case DW_AT_trampoline
:
13136 return "DW_AT_trampoline";
13137 case DW_AT_call_column
:
13138 return "DW_AT_call_column";
13139 case DW_AT_call_file
:
13140 return "DW_AT_call_file";
13141 case DW_AT_call_line
:
13142 return "DW_AT_call_line";
13143 case DW_AT_description
:
13144 return "DW_AT_description";
13145 case DW_AT_binary_scale
:
13146 return "DW_AT_binary_scale";
13147 case DW_AT_decimal_scale
:
13148 return "DW_AT_decimal_scale";
13150 return "DW_AT_small";
13151 case DW_AT_decimal_sign
:
13152 return "DW_AT_decimal_sign";
13153 case DW_AT_digit_count
:
13154 return "DW_AT_digit_count";
13155 case DW_AT_picture_string
:
13156 return "DW_AT_picture_string";
13157 case DW_AT_mutable
:
13158 return "DW_AT_mutable";
13159 case DW_AT_threads_scaled
:
13160 return "DW_AT_threads_scaled";
13161 case DW_AT_explicit
:
13162 return "DW_AT_explicit";
13163 case DW_AT_object_pointer
:
13164 return "DW_AT_object_pointer";
13165 case DW_AT_endianity
:
13166 return "DW_AT_endianity";
13167 case DW_AT_elemental
:
13168 return "DW_AT_elemental";
13170 return "DW_AT_pure";
13171 case DW_AT_recursive
:
13172 return "DW_AT_recursive";
13173 /* DWARF 4 values. */
13174 case DW_AT_signature
:
13175 return "DW_AT_signature";
13176 case DW_AT_linkage_name
:
13177 return "DW_AT_linkage_name";
13178 /* SGI/MIPS extensions. */
13179 #ifdef MIPS /* collides with DW_AT_HP_block_index */
13180 case DW_AT_MIPS_fde
:
13181 return "DW_AT_MIPS_fde";
13183 case DW_AT_MIPS_loop_begin
:
13184 return "DW_AT_MIPS_loop_begin";
13185 case DW_AT_MIPS_tail_loop_begin
:
13186 return "DW_AT_MIPS_tail_loop_begin";
13187 case DW_AT_MIPS_epilog_begin
:
13188 return "DW_AT_MIPS_epilog_begin";
13189 case DW_AT_MIPS_loop_unroll_factor
:
13190 return "DW_AT_MIPS_loop_unroll_factor";
13191 case DW_AT_MIPS_software_pipeline_depth
:
13192 return "DW_AT_MIPS_software_pipeline_depth";
13193 case DW_AT_MIPS_linkage_name
:
13194 return "DW_AT_MIPS_linkage_name";
13195 case DW_AT_MIPS_stride
:
13196 return "DW_AT_MIPS_stride";
13197 case DW_AT_MIPS_abstract_name
:
13198 return "DW_AT_MIPS_abstract_name";
13199 case DW_AT_MIPS_clone_origin
:
13200 return "DW_AT_MIPS_clone_origin";
13201 case DW_AT_MIPS_has_inlines
:
13202 return "DW_AT_MIPS_has_inlines";
13203 /* HP extensions. */
13204 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
13205 case DW_AT_HP_block_index
:
13206 return "DW_AT_HP_block_index";
13208 case DW_AT_HP_unmodifiable
:
13209 return "DW_AT_HP_unmodifiable";
13210 case DW_AT_HP_actuals_stmt_list
:
13211 return "DW_AT_HP_actuals_stmt_list";
13212 case DW_AT_HP_proc_per_section
:
13213 return "DW_AT_HP_proc_per_section";
13214 case DW_AT_HP_raw_data_ptr
:
13215 return "DW_AT_HP_raw_data_ptr";
13216 case DW_AT_HP_pass_by_reference
:
13217 return "DW_AT_HP_pass_by_reference";
13218 case DW_AT_HP_opt_level
:
13219 return "DW_AT_HP_opt_level";
13220 case DW_AT_HP_prof_version_id
:
13221 return "DW_AT_HP_prof_version_id";
13222 case DW_AT_HP_opt_flags
:
13223 return "DW_AT_HP_opt_flags";
13224 case DW_AT_HP_cold_region_low_pc
:
13225 return "DW_AT_HP_cold_region_low_pc";
13226 case DW_AT_HP_cold_region_high_pc
:
13227 return "DW_AT_HP_cold_region_high_pc";
13228 case DW_AT_HP_all_variables_modifiable
:
13229 return "DW_AT_HP_all_variables_modifiable";
13230 case DW_AT_HP_linkage_name
:
13231 return "DW_AT_HP_linkage_name";
13232 case DW_AT_HP_prof_flags
:
13233 return "DW_AT_HP_prof_flags";
13234 /* GNU extensions. */
13235 case DW_AT_sf_names
:
13236 return "DW_AT_sf_names";
13237 case DW_AT_src_info
:
13238 return "DW_AT_src_info";
13239 case DW_AT_mac_info
:
13240 return "DW_AT_mac_info";
13241 case DW_AT_src_coords
:
13242 return "DW_AT_src_coords";
13243 case DW_AT_body_begin
:
13244 return "DW_AT_body_begin";
13245 case DW_AT_body_end
:
13246 return "DW_AT_body_end";
13247 case DW_AT_GNU_vector
:
13248 return "DW_AT_GNU_vector";
13249 case DW_AT_GNU_odr_signature
:
13250 return "DW_AT_GNU_odr_signature";
13251 /* VMS extensions. */
13252 case DW_AT_VMS_rtnbeg_pd_address
:
13253 return "DW_AT_VMS_rtnbeg_pd_address";
13254 /* UPC extension. */
13255 case DW_AT_upc_threads_scaled
:
13256 return "DW_AT_upc_threads_scaled";
13257 /* PGI (STMicroelectronics) extensions. */
13258 case DW_AT_PGI_lbase
:
13259 return "DW_AT_PGI_lbase";
13260 case DW_AT_PGI_soffset
:
13261 return "DW_AT_PGI_soffset";
13262 case DW_AT_PGI_lstride
:
13263 return "DW_AT_PGI_lstride";
13265 return "DW_AT_<unknown>";
13269 /* Convert a DWARF value form code into its string name. */
13272 dwarf_form_name (unsigned form
)
13277 return "DW_FORM_addr";
13278 case DW_FORM_block2
:
13279 return "DW_FORM_block2";
13280 case DW_FORM_block4
:
13281 return "DW_FORM_block4";
13282 case DW_FORM_data2
:
13283 return "DW_FORM_data2";
13284 case DW_FORM_data4
:
13285 return "DW_FORM_data4";
13286 case DW_FORM_data8
:
13287 return "DW_FORM_data8";
13288 case DW_FORM_string
:
13289 return "DW_FORM_string";
13290 case DW_FORM_block
:
13291 return "DW_FORM_block";
13292 case DW_FORM_block1
:
13293 return "DW_FORM_block1";
13294 case DW_FORM_data1
:
13295 return "DW_FORM_data1";
13297 return "DW_FORM_flag";
13298 case DW_FORM_sdata
:
13299 return "DW_FORM_sdata";
13301 return "DW_FORM_strp";
13302 case DW_FORM_udata
:
13303 return "DW_FORM_udata";
13304 case DW_FORM_ref_addr
:
13305 return "DW_FORM_ref_addr";
13307 return "DW_FORM_ref1";
13309 return "DW_FORM_ref2";
13311 return "DW_FORM_ref4";
13313 return "DW_FORM_ref8";
13314 case DW_FORM_ref_udata
:
13315 return "DW_FORM_ref_udata";
13316 case DW_FORM_indirect
:
13317 return "DW_FORM_indirect";
13318 case DW_FORM_sec_offset
:
13319 return "DW_FORM_sec_offset";
13320 case DW_FORM_exprloc
:
13321 return "DW_FORM_exprloc";
13322 case DW_FORM_flag_present
:
13323 return "DW_FORM_flag_present";
13324 case DW_FORM_ref_sig8
:
13325 return "DW_FORM_ref_sig8";
13327 return "DW_FORM_<unknown>";
13331 /* Convert a DWARF stack opcode into its string name. */
13334 dwarf_stack_op_name (unsigned op
)
13339 return "DW_OP_addr";
13341 return "DW_OP_deref";
13342 case DW_OP_const1u
:
13343 return "DW_OP_const1u";
13344 case DW_OP_const1s
:
13345 return "DW_OP_const1s";
13346 case DW_OP_const2u
:
13347 return "DW_OP_const2u";
13348 case DW_OP_const2s
:
13349 return "DW_OP_const2s";
13350 case DW_OP_const4u
:
13351 return "DW_OP_const4u";
13352 case DW_OP_const4s
:
13353 return "DW_OP_const4s";
13354 case DW_OP_const8u
:
13355 return "DW_OP_const8u";
13356 case DW_OP_const8s
:
13357 return "DW_OP_const8s";
13359 return "DW_OP_constu";
13361 return "DW_OP_consts";
13363 return "DW_OP_dup";
13365 return "DW_OP_drop";
13367 return "DW_OP_over";
13369 return "DW_OP_pick";
13371 return "DW_OP_swap";
13373 return "DW_OP_rot";
13375 return "DW_OP_xderef";
13377 return "DW_OP_abs";
13379 return "DW_OP_and";
13381 return "DW_OP_div";
13383 return "DW_OP_minus";
13385 return "DW_OP_mod";
13387 return "DW_OP_mul";
13389 return "DW_OP_neg";
13391 return "DW_OP_not";
13395 return "DW_OP_plus";
13396 case DW_OP_plus_uconst
:
13397 return "DW_OP_plus_uconst";
13399 return "DW_OP_shl";
13401 return "DW_OP_shr";
13403 return "DW_OP_shra";
13405 return "DW_OP_xor";
13407 return "DW_OP_bra";
13421 return "DW_OP_skip";
13423 return "DW_OP_lit0";
13425 return "DW_OP_lit1";
13427 return "DW_OP_lit2";
13429 return "DW_OP_lit3";
13431 return "DW_OP_lit4";
13433 return "DW_OP_lit5";
13435 return "DW_OP_lit6";
13437 return "DW_OP_lit7";
13439 return "DW_OP_lit8";
13441 return "DW_OP_lit9";
13443 return "DW_OP_lit10";
13445 return "DW_OP_lit11";
13447 return "DW_OP_lit12";
13449 return "DW_OP_lit13";
13451 return "DW_OP_lit14";
13453 return "DW_OP_lit15";
13455 return "DW_OP_lit16";
13457 return "DW_OP_lit17";
13459 return "DW_OP_lit18";
13461 return "DW_OP_lit19";
13463 return "DW_OP_lit20";
13465 return "DW_OP_lit21";
13467 return "DW_OP_lit22";
13469 return "DW_OP_lit23";
13471 return "DW_OP_lit24";
13473 return "DW_OP_lit25";
13475 return "DW_OP_lit26";
13477 return "DW_OP_lit27";
13479 return "DW_OP_lit28";
13481 return "DW_OP_lit29";
13483 return "DW_OP_lit30";
13485 return "DW_OP_lit31";
13487 return "DW_OP_reg0";
13489 return "DW_OP_reg1";
13491 return "DW_OP_reg2";
13493 return "DW_OP_reg3";
13495 return "DW_OP_reg4";
13497 return "DW_OP_reg5";
13499 return "DW_OP_reg6";
13501 return "DW_OP_reg7";
13503 return "DW_OP_reg8";
13505 return "DW_OP_reg9";
13507 return "DW_OP_reg10";
13509 return "DW_OP_reg11";
13511 return "DW_OP_reg12";
13513 return "DW_OP_reg13";
13515 return "DW_OP_reg14";
13517 return "DW_OP_reg15";
13519 return "DW_OP_reg16";
13521 return "DW_OP_reg17";
13523 return "DW_OP_reg18";
13525 return "DW_OP_reg19";
13527 return "DW_OP_reg20";
13529 return "DW_OP_reg21";
13531 return "DW_OP_reg22";
13533 return "DW_OP_reg23";
13535 return "DW_OP_reg24";
13537 return "DW_OP_reg25";
13539 return "DW_OP_reg26";
13541 return "DW_OP_reg27";
13543 return "DW_OP_reg28";
13545 return "DW_OP_reg29";
13547 return "DW_OP_reg30";
13549 return "DW_OP_reg31";
13551 return "DW_OP_breg0";
13553 return "DW_OP_breg1";
13555 return "DW_OP_breg2";
13557 return "DW_OP_breg3";
13559 return "DW_OP_breg4";
13561 return "DW_OP_breg5";
13563 return "DW_OP_breg6";
13565 return "DW_OP_breg7";
13567 return "DW_OP_breg8";
13569 return "DW_OP_breg9";
13571 return "DW_OP_breg10";
13573 return "DW_OP_breg11";
13575 return "DW_OP_breg12";
13577 return "DW_OP_breg13";
13579 return "DW_OP_breg14";
13581 return "DW_OP_breg15";
13583 return "DW_OP_breg16";
13585 return "DW_OP_breg17";
13587 return "DW_OP_breg18";
13589 return "DW_OP_breg19";
13591 return "DW_OP_breg20";
13593 return "DW_OP_breg21";
13595 return "DW_OP_breg22";
13597 return "DW_OP_breg23";
13599 return "DW_OP_breg24";
13601 return "DW_OP_breg25";
13603 return "DW_OP_breg26";
13605 return "DW_OP_breg27";
13607 return "DW_OP_breg28";
13609 return "DW_OP_breg29";
13611 return "DW_OP_breg30";
13613 return "DW_OP_breg31";
13615 return "DW_OP_regx";
13617 return "DW_OP_fbreg";
13619 return "DW_OP_bregx";
13621 return "DW_OP_piece";
13622 case DW_OP_deref_size
:
13623 return "DW_OP_deref_size";
13624 case DW_OP_xderef_size
:
13625 return "DW_OP_xderef_size";
13627 return "DW_OP_nop";
13628 /* DWARF 3 extensions. */
13629 case DW_OP_push_object_address
:
13630 return "DW_OP_push_object_address";
13632 return "DW_OP_call2";
13634 return "DW_OP_call4";
13635 case DW_OP_call_ref
:
13636 return "DW_OP_call_ref";
13637 case DW_OP_form_tls_address
:
13638 return "DW_OP_form_tls_address";
13639 case DW_OP_call_frame_cfa
:
13640 return "DW_OP_call_frame_cfa";
13641 case DW_OP_bit_piece
:
13642 return "DW_OP_bit_piece";
13643 /* DWARF 4 extensions. */
13644 case DW_OP_implicit_value
:
13645 return "DW_OP_implicit_value";
13646 case DW_OP_stack_value
:
13647 return "DW_OP_stack_value";
13648 /* GNU extensions. */
13649 case DW_OP_GNU_push_tls_address
:
13650 return "DW_OP_GNU_push_tls_address";
13651 case DW_OP_GNU_uninit
:
13652 return "DW_OP_GNU_uninit";
13653 case DW_OP_GNU_implicit_pointer
:
13654 return "DW_OP_GNU_implicit_pointer";
13655 case DW_OP_GNU_entry_value
:
13656 return "DW_OP_GNU_entry_value";
13657 case DW_OP_GNU_const_type
:
13658 return "DW_OP_GNU_const_type";
13659 case DW_OP_GNU_regval_type
:
13660 return "DW_OP_GNU_regval_type";
13661 case DW_OP_GNU_deref_type
:
13662 return "DW_OP_GNU_deref_type";
13663 case DW_OP_GNU_convert
:
13664 return "DW_OP_GNU_convert";
13665 case DW_OP_GNU_reinterpret
:
13666 return "DW_OP_GNU_reinterpret";
13673 dwarf_bool_name (unsigned mybool
)
13681 /* Convert a DWARF type code into its string name. */
13684 dwarf_type_encoding_name (unsigned enc
)
13689 return "DW_ATE_void";
13690 case DW_ATE_address
:
13691 return "DW_ATE_address";
13692 case DW_ATE_boolean
:
13693 return "DW_ATE_boolean";
13694 case DW_ATE_complex_float
:
13695 return "DW_ATE_complex_float";
13697 return "DW_ATE_float";
13698 case DW_ATE_signed
:
13699 return "DW_ATE_signed";
13700 case DW_ATE_signed_char
:
13701 return "DW_ATE_signed_char";
13702 case DW_ATE_unsigned
:
13703 return "DW_ATE_unsigned";
13704 case DW_ATE_unsigned_char
:
13705 return "DW_ATE_unsigned_char";
13707 case DW_ATE_imaginary_float
:
13708 return "DW_ATE_imaginary_float";
13709 case DW_ATE_packed_decimal
:
13710 return "DW_ATE_packed_decimal";
13711 case DW_ATE_numeric_string
:
13712 return "DW_ATE_numeric_string";
13713 case DW_ATE_edited
:
13714 return "DW_ATE_edited";
13715 case DW_ATE_signed_fixed
:
13716 return "DW_ATE_signed_fixed";
13717 case DW_ATE_unsigned_fixed
:
13718 return "DW_ATE_unsigned_fixed";
13719 case DW_ATE_decimal_float
:
13720 return "DW_ATE_decimal_float";
13723 return "DW_ATE_UTF";
13724 /* HP extensions. */
13725 case DW_ATE_HP_float80
:
13726 return "DW_ATE_HP_float80";
13727 case DW_ATE_HP_complex_float80
:
13728 return "DW_ATE_HP_complex_float80";
13729 case DW_ATE_HP_float128
:
13730 return "DW_ATE_HP_float128";
13731 case DW_ATE_HP_complex_float128
:
13732 return "DW_ATE_HP_complex_float128";
13733 case DW_ATE_HP_floathpintel
:
13734 return "DW_ATE_HP_floathpintel";
13735 case DW_ATE_HP_imaginary_float80
:
13736 return "DW_ATE_HP_imaginary_float80";
13737 case DW_ATE_HP_imaginary_float128
:
13738 return "DW_ATE_HP_imaginary_float128";
13740 return "DW_ATE_<unknown>";
13744 /* Convert a DWARF call frame info operation to its string name. */
13748 dwarf_cfi_name (unsigned cfi_opc
)
13752 case DW_CFA_advance_loc
:
13753 return "DW_CFA_advance_loc";
13754 case DW_CFA_offset
:
13755 return "DW_CFA_offset";
13756 case DW_CFA_restore
:
13757 return "DW_CFA_restore";
13759 return "DW_CFA_nop";
13760 case DW_CFA_set_loc
:
13761 return "DW_CFA_set_loc";
13762 case DW_CFA_advance_loc1
:
13763 return "DW_CFA_advance_loc1";
13764 case DW_CFA_advance_loc2
:
13765 return "DW_CFA_advance_loc2";
13766 case DW_CFA_advance_loc4
:
13767 return "DW_CFA_advance_loc4";
13768 case DW_CFA_offset_extended
:
13769 return "DW_CFA_offset_extended";
13770 case DW_CFA_restore_extended
:
13771 return "DW_CFA_restore_extended";
13772 case DW_CFA_undefined
:
13773 return "DW_CFA_undefined";
13774 case DW_CFA_same_value
:
13775 return "DW_CFA_same_value";
13776 case DW_CFA_register
:
13777 return "DW_CFA_register";
13778 case DW_CFA_remember_state
:
13779 return "DW_CFA_remember_state";
13780 case DW_CFA_restore_state
:
13781 return "DW_CFA_restore_state";
13782 case DW_CFA_def_cfa
:
13783 return "DW_CFA_def_cfa";
13784 case DW_CFA_def_cfa_register
:
13785 return "DW_CFA_def_cfa_register";
13786 case DW_CFA_def_cfa_offset
:
13787 return "DW_CFA_def_cfa_offset";
13789 case DW_CFA_def_cfa_expression
:
13790 return "DW_CFA_def_cfa_expression";
13791 case DW_CFA_expression
:
13792 return "DW_CFA_expression";
13793 case DW_CFA_offset_extended_sf
:
13794 return "DW_CFA_offset_extended_sf";
13795 case DW_CFA_def_cfa_sf
:
13796 return "DW_CFA_def_cfa_sf";
13797 case DW_CFA_def_cfa_offset_sf
:
13798 return "DW_CFA_def_cfa_offset_sf";
13799 case DW_CFA_val_offset
:
13800 return "DW_CFA_val_offset";
13801 case DW_CFA_val_offset_sf
:
13802 return "DW_CFA_val_offset_sf";
13803 case DW_CFA_val_expression
:
13804 return "DW_CFA_val_expression";
13805 /* SGI/MIPS specific. */
13806 case DW_CFA_MIPS_advance_loc8
:
13807 return "DW_CFA_MIPS_advance_loc8";
13808 /* GNU extensions. */
13809 case DW_CFA_GNU_window_save
:
13810 return "DW_CFA_GNU_window_save";
13811 case DW_CFA_GNU_args_size
:
13812 return "DW_CFA_GNU_args_size";
13813 case DW_CFA_GNU_negative_offset_extended
:
13814 return "DW_CFA_GNU_negative_offset_extended";
13816 return "DW_CFA_<unknown>";
13822 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
13826 print_spaces (indent
, f
);
13827 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
13828 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
13830 if (die
->parent
!= NULL
)
13832 print_spaces (indent
, f
);
13833 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
13834 die
->parent
->offset
);
13837 print_spaces (indent
, f
);
13838 fprintf_unfiltered (f
, " has children: %s\n",
13839 dwarf_bool_name (die
->child
!= NULL
));
13841 print_spaces (indent
, f
);
13842 fprintf_unfiltered (f
, " attributes:\n");
13844 for (i
= 0; i
< die
->num_attrs
; ++i
)
13846 print_spaces (indent
, f
);
13847 fprintf_unfiltered (f
, " %s (%s) ",
13848 dwarf_attr_name (die
->attrs
[i
].name
),
13849 dwarf_form_name (die
->attrs
[i
].form
));
13851 switch (die
->attrs
[i
].form
)
13853 case DW_FORM_ref_addr
:
13855 fprintf_unfiltered (f
, "address: ");
13856 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
13858 case DW_FORM_block2
:
13859 case DW_FORM_block4
:
13860 case DW_FORM_block
:
13861 case DW_FORM_block1
:
13862 fprintf_unfiltered (f
, "block: size %d",
13863 DW_BLOCK (&die
->attrs
[i
])->size
);
13865 case DW_FORM_exprloc
:
13866 fprintf_unfiltered (f
, "expression: size %u",
13867 DW_BLOCK (&die
->attrs
[i
])->size
);
13872 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
13873 (long) (DW_ADDR (&die
->attrs
[i
])));
13875 case DW_FORM_data1
:
13876 case DW_FORM_data2
:
13877 case DW_FORM_data4
:
13878 case DW_FORM_data8
:
13879 case DW_FORM_udata
:
13880 case DW_FORM_sdata
:
13881 fprintf_unfiltered (f
, "constant: %s",
13882 pulongest (DW_UNSND (&die
->attrs
[i
])));
13884 case DW_FORM_sec_offset
:
13885 fprintf_unfiltered (f
, "section offset: %s",
13886 pulongest (DW_UNSND (&die
->attrs
[i
])));
13888 case DW_FORM_ref_sig8
:
13889 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
13890 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
13891 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
);
13893 fprintf_unfiltered (f
, "signatured type, offset: unknown");
13895 case DW_FORM_string
:
13897 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
13898 DW_STRING (&die
->attrs
[i
])
13899 ? DW_STRING (&die
->attrs
[i
]) : "",
13900 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
13903 if (DW_UNSND (&die
->attrs
[i
]))
13904 fprintf_unfiltered (f
, "flag: TRUE");
13906 fprintf_unfiltered (f
, "flag: FALSE");
13908 case DW_FORM_flag_present
:
13909 fprintf_unfiltered (f
, "flag: TRUE");
13911 case DW_FORM_indirect
:
13912 /* The reader will have reduced the indirect form to
13913 the "base form" so this form should not occur. */
13914 fprintf_unfiltered (f
,
13915 "unexpected attribute form: DW_FORM_indirect");
13918 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
13919 die
->attrs
[i
].form
);
13922 fprintf_unfiltered (f
, "\n");
13927 dump_die_for_error (struct die_info
*die
)
13929 dump_die_shallow (gdb_stderr
, 0, die
);
13933 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
13935 int indent
= level
* 4;
13937 gdb_assert (die
!= NULL
);
13939 if (level
>= max_level
)
13942 dump_die_shallow (f
, indent
, die
);
13944 if (die
->child
!= NULL
)
13946 print_spaces (indent
, f
);
13947 fprintf_unfiltered (f
, " Children:");
13948 if (level
+ 1 < max_level
)
13950 fprintf_unfiltered (f
, "\n");
13951 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
13955 fprintf_unfiltered (f
,
13956 " [not printed, max nesting level reached]\n");
13960 if (die
->sibling
!= NULL
&& level
> 0)
13962 dump_die_1 (f
, level
, max_level
, die
->sibling
);
13966 /* This is called from the pdie macro in gdbinit.in.
13967 It's not static so gcc will keep a copy callable from gdb. */
13970 dump_die (struct die_info
*die
, int max_level
)
13972 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
13976 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
13980 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
13986 is_ref_attr (struct attribute
*attr
)
13988 switch (attr
->form
)
13990 case DW_FORM_ref_addr
:
13995 case DW_FORM_ref_udata
:
14002 static unsigned int
14003 dwarf2_get_ref_die_offset (struct attribute
*attr
)
14005 if (is_ref_attr (attr
))
14006 return DW_ADDR (attr
);
14008 complaint (&symfile_complaints
,
14009 _("unsupported die ref attribute form: '%s'"),
14010 dwarf_form_name (attr
->form
));
14014 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
14015 * the value held by the attribute is not constant. */
14018 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
14020 if (attr
->form
== DW_FORM_sdata
)
14021 return DW_SND (attr
);
14022 else if (attr
->form
== DW_FORM_udata
14023 || attr
->form
== DW_FORM_data1
14024 || attr
->form
== DW_FORM_data2
14025 || attr
->form
== DW_FORM_data4
14026 || attr
->form
== DW_FORM_data8
)
14027 return DW_UNSND (attr
);
14030 complaint (&symfile_complaints
,
14031 _("Attribute value is not a constant (%s)"),
14032 dwarf_form_name (attr
->form
));
14033 return default_value
;
14037 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
14038 unit and add it to our queue.
14039 The result is non-zero if PER_CU was queued, otherwise the result is zero
14040 meaning either PER_CU is already queued or it is already loaded. */
14043 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
14044 struct dwarf2_per_cu_data
*per_cu
)
14046 /* We may arrive here during partial symbol reading, if we need full
14047 DIEs to process an unusual case (e.g. template arguments). Do
14048 not queue PER_CU, just tell our caller to load its DIEs. */
14049 if (dwarf2_per_objfile
->reading_partial_symbols
)
14051 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
14056 /* Mark the dependence relation so that we don't flush PER_CU
14058 dwarf2_add_dependence (this_cu
, per_cu
);
14060 /* If it's already on the queue, we have nothing to do. */
14061 if (per_cu
->queued
)
14064 /* If the compilation unit is already loaded, just mark it as
14066 if (per_cu
->cu
!= NULL
)
14068 per_cu
->cu
->last_used
= 0;
14072 /* Add it to the queue. */
14073 queue_comp_unit (per_cu
);
14078 /* Follow reference or signature attribute ATTR of SRC_DIE.
14079 On entry *REF_CU is the CU of SRC_DIE.
14080 On exit *REF_CU is the CU of the result. */
14082 static struct die_info
*
14083 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
14084 struct dwarf2_cu
**ref_cu
)
14086 struct die_info
*die
;
14088 if (is_ref_attr (attr
))
14089 die
= follow_die_ref (src_die
, attr
, ref_cu
);
14090 else if (attr
->form
== DW_FORM_ref_sig8
)
14091 die
= follow_die_sig (src_die
, attr
, ref_cu
);
14094 dump_die_for_error (src_die
);
14095 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
14096 (*ref_cu
)->objfile
->name
);
14102 /* Follow reference OFFSET.
14103 On entry *REF_CU is the CU of the source die referencing OFFSET.
14104 On exit *REF_CU is the CU of the result.
14105 Returns NULL if OFFSET is invalid. */
14107 static struct die_info
*
14108 follow_die_offset (unsigned int offset
, struct dwarf2_cu
**ref_cu
)
14110 struct die_info temp_die
;
14111 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
14113 gdb_assert (cu
->per_cu
!= NULL
);
14117 if (cu
->per_cu
->debug_types_section
)
14119 /* .debug_types CUs cannot reference anything outside their CU.
14120 If they need to, they have to reference a signatured type via
14121 DW_FORM_ref_sig8. */
14122 if (! offset_in_cu_p (&cu
->header
, offset
))
14125 else if (! offset_in_cu_p (&cu
->header
, offset
))
14127 struct dwarf2_per_cu_data
*per_cu
;
14129 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
14131 /* If necessary, add it to the queue and load its DIEs. */
14132 if (maybe_queue_comp_unit (cu
, per_cu
))
14133 load_full_comp_unit (per_cu
);
14135 target_cu
= per_cu
->cu
;
14137 else if (cu
->dies
== NULL
)
14139 /* We're loading full DIEs during partial symbol reading. */
14140 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
14141 load_full_comp_unit (cu
->per_cu
);
14144 *ref_cu
= target_cu
;
14145 temp_die
.offset
= offset
;
14146 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
14149 /* Follow reference attribute ATTR of SRC_DIE.
14150 On entry *REF_CU is the CU of SRC_DIE.
14151 On exit *REF_CU is the CU of the result. */
14153 static struct die_info
*
14154 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
14155 struct dwarf2_cu
**ref_cu
)
14157 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
14158 struct dwarf2_cu
*cu
= *ref_cu
;
14159 struct die_info
*die
;
14161 die
= follow_die_offset (offset
, ref_cu
);
14163 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
14164 "at 0x%x [in module %s]"),
14165 offset
, src_die
->offset
, cu
->objfile
->name
);
14170 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
14171 Returned value is intended for DW_OP_call*. Returned
14172 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
14174 struct dwarf2_locexpr_baton
14175 dwarf2_fetch_die_location_block (unsigned int offset
,
14176 struct dwarf2_per_cu_data
*per_cu
,
14177 CORE_ADDR (*get_frame_pc
) (void *baton
),
14180 struct dwarf2_cu
*cu
;
14181 struct die_info
*die
;
14182 struct attribute
*attr
;
14183 struct dwarf2_locexpr_baton retval
;
14185 dw2_setup (per_cu
->objfile
);
14187 if (per_cu
->cu
== NULL
)
14191 die
= follow_die_offset (offset
, &cu
);
14193 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
14194 offset
, per_cu
->objfile
->name
);
14196 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
14199 /* DWARF: "If there is no such attribute, then there is no effect.".
14200 DATA is ignored if SIZE is 0. */
14202 retval
.data
= NULL
;
14205 else if (attr_form_is_section_offset (attr
))
14207 struct dwarf2_loclist_baton loclist_baton
;
14208 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
14211 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
14213 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
14215 retval
.size
= size
;
14219 if (!attr_form_is_block (attr
))
14220 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
14221 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
14222 offset
, per_cu
->objfile
->name
);
14224 retval
.data
= DW_BLOCK (attr
)->data
;
14225 retval
.size
= DW_BLOCK (attr
)->size
;
14227 retval
.per_cu
= cu
->per_cu
;
14229 age_cached_comp_units ();
14234 /* Return the type of the DIE at DIE_OFFSET in the CU named by
14238 dwarf2_get_die_type (unsigned int die_offset
,
14239 struct dwarf2_per_cu_data
*per_cu
)
14241 dw2_setup (per_cu
->objfile
);
14242 return get_die_type_at_offset (die_offset
, per_cu
);
14245 /* Follow the signature attribute ATTR in SRC_DIE.
14246 On entry *REF_CU is the CU of SRC_DIE.
14247 On exit *REF_CU is the CU of the result. */
14249 static struct die_info
*
14250 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
14251 struct dwarf2_cu
**ref_cu
)
14253 struct objfile
*objfile
= (*ref_cu
)->objfile
;
14254 struct die_info temp_die
;
14255 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
14256 struct dwarf2_cu
*sig_cu
;
14257 struct die_info
*die
;
14259 /* sig_type will be NULL if the signatured type is missing from
14261 if (sig_type
== NULL
)
14262 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
14263 "at 0x%x [in module %s]"),
14264 src_die
->offset
, objfile
->name
);
14266 /* If necessary, add it to the queue and load its DIEs. */
14268 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
14269 read_signatured_type (sig_type
);
14271 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
14273 sig_cu
= sig_type
->per_cu
.cu
;
14274 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
14275 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
14282 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
14283 "from DIE at 0x%x [in module %s]"),
14284 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
14287 /* Given an offset of a signatured type, return its signatured_type. */
14289 static struct signatured_type
*
14290 lookup_signatured_type_at_offset (struct objfile
*objfile
,
14291 struct dwarf2_section_info
*section
,
14292 unsigned int offset
)
14294 gdb_byte
*info_ptr
= section
->buffer
+ offset
;
14295 unsigned int length
, initial_length_size
;
14296 unsigned int sig_offset
;
14297 struct signatured_type find_entry
, *type_sig
;
14299 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
14300 sig_offset
= (initial_length_size
14302 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
14303 + 1 /*address_size*/);
14304 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
14305 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
14307 /* This is only used to lookup previously recorded types.
14308 If we didn't find it, it's our bug. */
14309 gdb_assert (type_sig
!= NULL
);
14310 gdb_assert (offset
== type_sig
->per_cu
.offset
);
14315 /* Load the DIEs associated with type unit PER_CU into memory. */
14318 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
14320 struct objfile
*objfile
= per_cu
->objfile
;
14321 struct dwarf2_section_info
*sect
= per_cu
->debug_types_section
;
14322 unsigned int offset
= per_cu
->offset
;
14323 struct signatured_type
*type_sig
;
14325 dwarf2_read_section (objfile
, sect
);
14327 /* We have the section offset, but we need the signature to do the
14328 hash table lookup. */
14329 /* FIXME: This is sorta unnecessary, read_signatured_type only uses
14330 the signature to assert we found the right one.
14331 Ok, but it's a lot of work. We should simplify things so any needed
14332 assert doesn't require all this clumsiness. */
14333 type_sig
= lookup_signatured_type_at_offset (objfile
, sect
, offset
);
14335 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
14337 read_signatured_type (type_sig
);
14339 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
14342 /* Read in a signatured type and build its CU and DIEs. */
14345 read_signatured_type (struct signatured_type
*type_sig
)
14347 struct objfile
*objfile
= type_sig
->per_cu
.objfile
;
14348 gdb_byte
*types_ptr
;
14349 struct die_reader_specs reader_specs
;
14350 struct dwarf2_cu
*cu
;
14351 ULONGEST signature
;
14352 struct cleanup
*back_to
, *free_cu_cleanup
;
14353 struct dwarf2_section_info
*section
= type_sig
->per_cu
.debug_types_section
;
14355 dwarf2_read_section (objfile
, section
);
14356 types_ptr
= section
->buffer
+ type_sig
->per_cu
.offset
;
14358 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
14360 cu
= xmalloc (sizeof (*cu
));
14361 init_one_comp_unit (cu
, &type_sig
->per_cu
);
14363 /* If an error occurs while loading, release our storage. */
14364 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
14366 types_ptr
= read_and_check_type_unit_head (&cu
->header
, section
, types_ptr
,
14368 gdb_assert (signature
== type_sig
->signature
);
14371 = htab_create_alloc_ex (cu
->header
.length
/ 12,
14375 &cu
->comp_unit_obstack
,
14376 hashtab_obstack_allocate
,
14377 dummy_obstack_deallocate
);
14379 dwarf2_read_abbrevs (cu
);
14380 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
14382 init_cu_die_reader (&reader_specs
, cu
);
14384 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
14387 /* We try not to read any attributes in this function, because not
14388 all CUs needed for references have been loaded yet, and symbol
14389 table processing isn't initialized. But we have to set the CU language,
14390 or we won't be able to build types correctly. */
14391 prepare_one_comp_unit (cu
, cu
->dies
);
14393 do_cleanups (back_to
);
14395 /* We've successfully allocated this compilation unit. Let our caller
14396 clean it up when finished with it. */
14397 discard_cleanups (free_cu_cleanup
);
14399 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
14400 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
14403 /* Decode simple location descriptions.
14404 Given a pointer to a dwarf block that defines a location, compute
14405 the location and return the value.
14407 NOTE drow/2003-11-18: This function is called in two situations
14408 now: for the address of static or global variables (partial symbols
14409 only) and for offsets into structures which are expected to be
14410 (more or less) constant. The partial symbol case should go away,
14411 and only the constant case should remain. That will let this
14412 function complain more accurately. A few special modes are allowed
14413 without complaint for global variables (for instance, global
14414 register values and thread-local values).
14416 A location description containing no operations indicates that the
14417 object is optimized out. The return value is 0 for that case.
14418 FIXME drow/2003-11-16: No callers check for this case any more; soon all
14419 callers will only want a very basic result and this can become a
14422 Note that stack[0] is unused except as a default error return. */
14425 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
14427 struct objfile
*objfile
= cu
->objfile
;
14429 int size
= blk
->size
;
14430 gdb_byte
*data
= blk
->data
;
14431 CORE_ADDR stack
[64];
14433 unsigned int bytes_read
, unsnd
;
14439 stack
[++stacki
] = 0;
14478 stack
[++stacki
] = op
- DW_OP_lit0
;
14513 stack
[++stacki
] = op
- DW_OP_reg0
;
14515 dwarf2_complex_location_expr_complaint ();
14519 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
14521 stack
[++stacki
] = unsnd
;
14523 dwarf2_complex_location_expr_complaint ();
14527 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
14532 case DW_OP_const1u
:
14533 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
14537 case DW_OP_const1s
:
14538 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
14542 case DW_OP_const2u
:
14543 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
14547 case DW_OP_const2s
:
14548 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
14552 case DW_OP_const4u
:
14553 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
14557 case DW_OP_const4s
:
14558 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
14562 case DW_OP_const8u
:
14563 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
14568 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
14574 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
14579 stack
[stacki
+ 1] = stack
[stacki
];
14584 stack
[stacki
- 1] += stack
[stacki
];
14588 case DW_OP_plus_uconst
:
14589 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
14595 stack
[stacki
- 1] -= stack
[stacki
];
14600 /* If we're not the last op, then we definitely can't encode
14601 this using GDB's address_class enum. This is valid for partial
14602 global symbols, although the variable's address will be bogus
14605 dwarf2_complex_location_expr_complaint ();
14608 case DW_OP_GNU_push_tls_address
:
14609 /* The top of the stack has the offset from the beginning
14610 of the thread control block at which the variable is located. */
14611 /* Nothing should follow this operator, so the top of stack would
14613 /* This is valid for partial global symbols, but the variable's
14614 address will be bogus in the psymtab. Make it always at least
14615 non-zero to not look as a variable garbage collected by linker
14616 which have DW_OP_addr 0. */
14618 dwarf2_complex_location_expr_complaint ();
14622 case DW_OP_GNU_uninit
:
14627 const char *name
= dwarf_stack_op_name (op
);
14630 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
14633 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
14637 return (stack
[stacki
]);
14640 /* Enforce maximum stack depth of SIZE-1 to avoid writing
14641 outside of the allocated space. Also enforce minimum>0. */
14642 if (stacki
>= ARRAY_SIZE (stack
) - 1)
14644 complaint (&symfile_complaints
,
14645 _("location description stack overflow"));
14651 complaint (&symfile_complaints
,
14652 _("location description stack underflow"));
14656 return (stack
[stacki
]);
14659 /* memory allocation interface */
14661 static struct dwarf_block
*
14662 dwarf_alloc_block (struct dwarf2_cu
*cu
)
14664 struct dwarf_block
*blk
;
14666 blk
= (struct dwarf_block
*)
14667 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
14671 static struct abbrev_info
*
14672 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
14674 struct abbrev_info
*abbrev
;
14676 abbrev
= (struct abbrev_info
*)
14677 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
14678 memset (abbrev
, 0, sizeof (struct abbrev_info
));
14682 static struct die_info
*
14683 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
14685 struct die_info
*die
;
14686 size_t size
= sizeof (struct die_info
);
14689 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
14691 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
14692 memset (die
, 0, sizeof (struct die_info
));
14697 /* Macro support. */
14699 /* Return the full name of file number I in *LH's file name table.
14700 Use COMP_DIR as the name of the current directory of the
14701 compilation. The result is allocated using xmalloc; the caller is
14702 responsible for freeing it. */
14704 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
14706 /* Is the file number a valid index into the line header's file name
14707 table? Remember that file numbers start with one, not zero. */
14708 if (1 <= file
&& file
<= lh
->num_file_names
)
14710 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
14712 if (IS_ABSOLUTE_PATH (fe
->name
))
14713 return xstrdup (fe
->name
);
14721 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14727 dir_len
= strlen (dir
);
14728 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
14729 strcpy (full_name
, dir
);
14730 full_name
[dir_len
] = '/';
14731 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
14735 return xstrdup (fe
->name
);
14740 /* The compiler produced a bogus file number. We can at least
14741 record the macro definitions made in the file, even if we
14742 won't be able to find the file by name. */
14743 char fake_name
[80];
14745 sprintf (fake_name
, "<bad macro file number %d>", file
);
14747 complaint (&symfile_complaints
,
14748 _("bad file number in macro information (%d)"),
14751 return xstrdup (fake_name
);
14756 static struct macro_source_file
*
14757 macro_start_file (int file
, int line
,
14758 struct macro_source_file
*current_file
,
14759 const char *comp_dir
,
14760 struct line_header
*lh
, struct objfile
*objfile
)
14762 /* The full name of this source file. */
14763 char *full_name
= file_full_name (file
, lh
, comp_dir
);
14765 /* We don't create a macro table for this compilation unit
14766 at all until we actually get a filename. */
14767 if (! pending_macros
)
14768 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
14769 objfile
->macro_cache
);
14771 if (! current_file
)
14772 /* If we have no current file, then this must be the start_file
14773 directive for the compilation unit's main source file. */
14774 current_file
= macro_set_main (pending_macros
, full_name
);
14776 current_file
= macro_include (current_file
, line
, full_name
);
14780 return current_file
;
14784 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
14785 followed by a null byte. */
14787 copy_string (const char *buf
, int len
)
14789 char *s
= xmalloc (len
+ 1);
14791 memcpy (s
, buf
, len
);
14797 static const char *
14798 consume_improper_spaces (const char *p
, const char *body
)
14802 complaint (&symfile_complaints
,
14803 _("macro definition contains spaces "
14804 "in formal argument list:\n`%s'"),
14816 parse_macro_definition (struct macro_source_file
*file
, int line
,
14821 /* The body string takes one of two forms. For object-like macro
14822 definitions, it should be:
14824 <macro name> " " <definition>
14826 For function-like macro definitions, it should be:
14828 <macro name> "() " <definition>
14830 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
14832 Spaces may appear only where explicitly indicated, and in the
14835 The Dwarf 2 spec says that an object-like macro's name is always
14836 followed by a space, but versions of GCC around March 2002 omit
14837 the space when the macro's definition is the empty string.
14839 The Dwarf 2 spec says that there should be no spaces between the
14840 formal arguments in a function-like macro's formal argument list,
14841 but versions of GCC around March 2002 include spaces after the
14845 /* Find the extent of the macro name. The macro name is terminated
14846 by either a space or null character (for an object-like macro) or
14847 an opening paren (for a function-like macro). */
14848 for (p
= body
; *p
; p
++)
14849 if (*p
== ' ' || *p
== '(')
14852 if (*p
== ' ' || *p
== '\0')
14854 /* It's an object-like macro. */
14855 int name_len
= p
- body
;
14856 char *name
= copy_string (body
, name_len
);
14857 const char *replacement
;
14860 replacement
= body
+ name_len
+ 1;
14863 dwarf2_macro_malformed_definition_complaint (body
);
14864 replacement
= body
+ name_len
;
14867 macro_define_object (file
, line
, name
, replacement
);
14871 else if (*p
== '(')
14873 /* It's a function-like macro. */
14874 char *name
= copy_string (body
, p
- body
);
14877 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
14881 p
= consume_improper_spaces (p
, body
);
14883 /* Parse the formal argument list. */
14884 while (*p
&& *p
!= ')')
14886 /* Find the extent of the current argument name. */
14887 const char *arg_start
= p
;
14889 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
14892 if (! *p
|| p
== arg_start
)
14893 dwarf2_macro_malformed_definition_complaint (body
);
14896 /* Make sure argv has room for the new argument. */
14897 if (argc
>= argv_size
)
14900 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
14903 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
14906 p
= consume_improper_spaces (p
, body
);
14908 /* Consume the comma, if present. */
14913 p
= consume_improper_spaces (p
, body
);
14922 /* Perfectly formed definition, no complaints. */
14923 macro_define_function (file
, line
, name
,
14924 argc
, (const char **) argv
,
14926 else if (*p
== '\0')
14928 /* Complain, but do define it. */
14929 dwarf2_macro_malformed_definition_complaint (body
);
14930 macro_define_function (file
, line
, name
,
14931 argc
, (const char **) argv
,
14935 /* Just complain. */
14936 dwarf2_macro_malformed_definition_complaint (body
);
14939 /* Just complain. */
14940 dwarf2_macro_malformed_definition_complaint (body
);
14946 for (i
= 0; i
< argc
; i
++)
14952 dwarf2_macro_malformed_definition_complaint (body
);
14955 /* Skip some bytes from BYTES according to the form given in FORM.
14956 Returns the new pointer. */
14959 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
,
14960 enum dwarf_form form
,
14961 unsigned int offset_size
,
14962 struct dwarf2_section_info
*section
)
14964 unsigned int bytes_read
;
14968 case DW_FORM_data1
:
14973 case DW_FORM_data2
:
14977 case DW_FORM_data4
:
14981 case DW_FORM_data8
:
14985 case DW_FORM_string
:
14986 read_direct_string (abfd
, bytes
, &bytes_read
);
14987 bytes
+= bytes_read
;
14990 case DW_FORM_sec_offset
:
14992 bytes
+= offset_size
;
14995 case DW_FORM_block
:
14996 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
14997 bytes
+= bytes_read
;
15000 case DW_FORM_block1
:
15001 bytes
+= 1 + read_1_byte (abfd
, bytes
);
15003 case DW_FORM_block2
:
15004 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
15006 case DW_FORM_block4
:
15007 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
15010 case DW_FORM_sdata
:
15011 case DW_FORM_udata
:
15012 bytes
= skip_leb128 (abfd
, bytes
);
15018 complaint (&symfile_complaints
,
15019 _("invalid form 0x%x in `%s'"),
15021 section
->asection
->name
);
15029 /* A helper for dwarf_decode_macros that handles skipping an unknown
15030 opcode. Returns an updated pointer to the macro data buffer; or,
15031 on error, issues a complaint and returns NULL. */
15034 skip_unknown_opcode (unsigned int opcode
,
15035 gdb_byte
**opcode_definitions
,
15038 unsigned int offset_size
,
15039 struct dwarf2_section_info
*section
)
15041 unsigned int bytes_read
, i
;
15045 if (opcode_definitions
[opcode
] == NULL
)
15047 complaint (&symfile_complaints
,
15048 _("unrecognized DW_MACFINO opcode 0x%x"),
15053 defn
= opcode_definitions
[opcode
];
15054 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
15055 defn
+= bytes_read
;
15057 for (i
= 0; i
< arg
; ++i
)
15059 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, defn
[i
], offset_size
, section
);
15060 if (mac_ptr
== NULL
)
15062 /* skip_form_bytes already issued the complaint. */
15070 /* A helper function which parses the header of a macro section.
15071 If the macro section is the extended (for now called "GNU") type,
15072 then this updates *OFFSET_SIZE. Returns a pointer to just after
15073 the header, or issues a complaint and returns NULL on error. */
15076 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
15079 unsigned int *offset_size
,
15080 int section_is_gnu
)
15082 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
15084 if (section_is_gnu
)
15086 unsigned int version
, flags
;
15088 version
= read_2_bytes (abfd
, mac_ptr
);
15091 complaint (&symfile_complaints
,
15092 _("unrecognized version `%d' in .debug_macro section"),
15098 flags
= read_1_byte (abfd
, mac_ptr
);
15100 *offset_size
= (flags
& 1) ? 8 : 4;
15102 if ((flags
& 2) != 0)
15103 /* We don't need the line table offset. */
15104 mac_ptr
+= *offset_size
;
15106 /* Vendor opcode descriptions. */
15107 if ((flags
& 4) != 0)
15109 unsigned int i
, count
;
15111 count
= read_1_byte (abfd
, mac_ptr
);
15113 for (i
= 0; i
< count
; ++i
)
15115 unsigned int opcode
, bytes_read
;
15118 opcode
= read_1_byte (abfd
, mac_ptr
);
15120 opcode_definitions
[opcode
] = mac_ptr
;
15121 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15122 mac_ptr
+= bytes_read
;
15131 /* A helper for dwarf_decode_macros that handles the GNU extensions,
15132 including DW_MACRO_GNU_transparent_include. */
15135 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
15136 struct macro_source_file
*current_file
,
15137 struct line_header
*lh
, char *comp_dir
,
15138 struct dwarf2_section_info
*section
,
15139 int section_is_gnu
,
15140 unsigned int offset_size
,
15141 struct objfile
*objfile
,
15142 htab_t include_hash
)
15144 enum dwarf_macro_record_type macinfo_type
;
15145 int at_commandline
;
15146 gdb_byte
*opcode_definitions
[256];
15148 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
15149 &offset_size
, section_is_gnu
);
15150 if (mac_ptr
== NULL
)
15152 /* We already issued a complaint. */
15156 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
15157 GDB is still reading the definitions from command line. First
15158 DW_MACINFO_start_file will need to be ignored as it was already executed
15159 to create CURRENT_FILE for the main source holding also the command line
15160 definitions. On first met DW_MACINFO_start_file this flag is reset to
15161 normally execute all the remaining DW_MACINFO_start_file macinfos. */
15163 at_commandline
= 1;
15167 /* Do we at least have room for a macinfo type byte? */
15168 if (mac_ptr
>= mac_end
)
15170 dwarf2_macros_too_long_complaint (section
);
15174 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
15177 /* Note that we rely on the fact that the corresponding GNU and
15178 DWARF constants are the same. */
15179 switch (macinfo_type
)
15181 /* A zero macinfo type indicates the end of the macro
15186 case DW_MACRO_GNU_define
:
15187 case DW_MACRO_GNU_undef
:
15188 case DW_MACRO_GNU_define_indirect
:
15189 case DW_MACRO_GNU_undef_indirect
:
15191 unsigned int bytes_read
;
15196 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15197 mac_ptr
+= bytes_read
;
15199 if (macinfo_type
== DW_MACRO_GNU_define
15200 || macinfo_type
== DW_MACRO_GNU_undef
)
15202 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15203 mac_ptr
+= bytes_read
;
15207 LONGEST str_offset
;
15209 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
15210 mac_ptr
+= offset_size
;
15212 body
= read_indirect_string_at_offset (abfd
, str_offset
);
15215 is_define
= (macinfo_type
== DW_MACRO_GNU_define
15216 || macinfo_type
== DW_MACRO_GNU_define_indirect
);
15217 if (! current_file
)
15219 /* DWARF violation as no main source is present. */
15220 complaint (&symfile_complaints
,
15221 _("debug info with no main source gives macro %s "
15223 is_define
? _("definition") : _("undefinition"),
15227 if ((line
== 0 && !at_commandline
)
15228 || (line
!= 0 && at_commandline
))
15229 complaint (&symfile_complaints
,
15230 _("debug info gives %s macro %s with %s line %d: %s"),
15231 at_commandline
? _("command-line") : _("in-file"),
15232 is_define
? _("definition") : _("undefinition"),
15233 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
15236 parse_macro_definition (current_file
, line
, body
);
15239 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
15240 || macinfo_type
== DW_MACRO_GNU_undef_indirect
);
15241 macro_undef (current_file
, line
, body
);
15246 case DW_MACRO_GNU_start_file
:
15248 unsigned int bytes_read
;
15251 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15252 mac_ptr
+= bytes_read
;
15253 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15254 mac_ptr
+= bytes_read
;
15256 if ((line
== 0 && !at_commandline
)
15257 || (line
!= 0 && at_commandline
))
15258 complaint (&symfile_complaints
,
15259 _("debug info gives source %d included "
15260 "from %s at %s line %d"),
15261 file
, at_commandline
? _("command-line") : _("file"),
15262 line
== 0 ? _("zero") : _("non-zero"), line
);
15264 if (at_commandline
)
15266 /* This DW_MACRO_GNU_start_file was executed in the
15268 at_commandline
= 0;
15271 current_file
= macro_start_file (file
, line
,
15272 current_file
, comp_dir
,
15277 case DW_MACRO_GNU_end_file
:
15278 if (! current_file
)
15279 complaint (&symfile_complaints
,
15280 _("macro debug info has an unmatched "
15281 "`close_file' directive"));
15284 current_file
= current_file
->included_by
;
15285 if (! current_file
)
15287 enum dwarf_macro_record_type next_type
;
15289 /* GCC circa March 2002 doesn't produce the zero
15290 type byte marking the end of the compilation
15291 unit. Complain if it's not there, but exit no
15294 /* Do we at least have room for a macinfo type byte? */
15295 if (mac_ptr
>= mac_end
)
15297 dwarf2_macros_too_long_complaint (section
);
15301 /* We don't increment mac_ptr here, so this is just
15303 next_type
= read_1_byte (abfd
, mac_ptr
);
15304 if (next_type
!= 0)
15305 complaint (&symfile_complaints
,
15306 _("no terminating 0-type entry for "
15307 "macros in `.debug_macinfo' section"));
15314 case DW_MACRO_GNU_transparent_include
:
15319 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
15320 mac_ptr
+= offset_size
;
15322 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
15325 /* This has actually happened; see
15326 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
15327 complaint (&symfile_complaints
,
15328 _("recursive DW_MACRO_GNU_transparent_include in "
15329 ".debug_macro section"));
15335 dwarf_decode_macro_bytes (abfd
,
15336 section
->buffer
+ offset
,
15337 mac_end
, current_file
,
15339 section
, section_is_gnu
,
15340 offset_size
, objfile
, include_hash
);
15342 htab_remove_elt (include_hash
, mac_ptr
);
15347 case DW_MACINFO_vendor_ext
:
15348 if (!section_is_gnu
)
15350 unsigned int bytes_read
;
15353 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15354 mac_ptr
+= bytes_read
;
15355 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15356 mac_ptr
+= bytes_read
;
15358 /* We don't recognize any vendor extensions. */
15364 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
15365 mac_ptr
, abfd
, offset_size
,
15367 if (mac_ptr
== NULL
)
15371 } while (macinfo_type
!= 0);
15375 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
15376 char *comp_dir
, bfd
*abfd
,
15377 struct dwarf2_cu
*cu
,
15378 struct dwarf2_section_info
*section
,
15379 int section_is_gnu
)
15381 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15382 gdb_byte
*mac_ptr
, *mac_end
;
15383 struct macro_source_file
*current_file
= 0;
15384 enum dwarf_macro_record_type macinfo_type
;
15385 unsigned int offset_size
= cu
->header
.offset_size
;
15386 gdb_byte
*opcode_definitions
[256];
15387 struct cleanup
*cleanup
;
15388 htab_t include_hash
;
15391 dwarf2_read_section (objfile
, section
);
15392 if (section
->buffer
== NULL
)
15394 complaint (&symfile_complaints
, _("missing %s section"),
15395 section
->asection
->name
);
15399 /* First pass: Find the name of the base filename.
15400 This filename is needed in order to process all macros whose definition
15401 (or undefinition) comes from the command line. These macros are defined
15402 before the first DW_MACINFO_start_file entry, and yet still need to be
15403 associated to the base file.
15405 To determine the base file name, we scan the macro definitions until we
15406 reach the first DW_MACINFO_start_file entry. We then initialize
15407 CURRENT_FILE accordingly so that any macro definition found before the
15408 first DW_MACINFO_start_file can still be associated to the base file. */
15410 mac_ptr
= section
->buffer
+ offset
;
15411 mac_end
= section
->buffer
+ section
->size
;
15413 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
15414 &offset_size
, section_is_gnu
);
15415 if (mac_ptr
== NULL
)
15417 /* We already issued a complaint. */
15423 /* Do we at least have room for a macinfo type byte? */
15424 if (mac_ptr
>= mac_end
)
15426 /* Complaint is printed during the second pass as GDB will probably
15427 stop the first pass earlier upon finding
15428 DW_MACINFO_start_file. */
15432 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
15435 /* Note that we rely on the fact that the corresponding GNU and
15436 DWARF constants are the same. */
15437 switch (macinfo_type
)
15439 /* A zero macinfo type indicates the end of the macro
15444 case DW_MACRO_GNU_define
:
15445 case DW_MACRO_GNU_undef
:
15446 /* Only skip the data by MAC_PTR. */
15448 unsigned int bytes_read
;
15450 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15451 mac_ptr
+= bytes_read
;
15452 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15453 mac_ptr
+= bytes_read
;
15457 case DW_MACRO_GNU_start_file
:
15459 unsigned int bytes_read
;
15462 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15463 mac_ptr
+= bytes_read
;
15464 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15465 mac_ptr
+= bytes_read
;
15467 current_file
= macro_start_file (file
, line
, current_file
,
15468 comp_dir
, lh
, objfile
);
15472 case DW_MACRO_GNU_end_file
:
15473 /* No data to skip by MAC_PTR. */
15476 case DW_MACRO_GNU_define_indirect
:
15477 case DW_MACRO_GNU_undef_indirect
:
15479 unsigned int bytes_read
;
15481 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15482 mac_ptr
+= bytes_read
;
15483 mac_ptr
+= offset_size
;
15487 case DW_MACRO_GNU_transparent_include
:
15488 /* Note that, according to the spec, a transparent include
15489 chain cannot call DW_MACRO_GNU_start_file. So, we can just
15490 skip this opcode. */
15491 mac_ptr
+= offset_size
;
15494 case DW_MACINFO_vendor_ext
:
15495 /* Only skip the data by MAC_PTR. */
15496 if (!section_is_gnu
)
15498 unsigned int bytes_read
;
15500 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15501 mac_ptr
+= bytes_read
;
15502 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15503 mac_ptr
+= bytes_read
;
15508 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
15509 mac_ptr
, abfd
, offset_size
,
15511 if (mac_ptr
== NULL
)
15515 } while (macinfo_type
!= 0 && current_file
== NULL
);
15517 /* Second pass: Process all entries.
15519 Use the AT_COMMAND_LINE flag to determine whether we are still processing
15520 command-line macro definitions/undefinitions. This flag is unset when we
15521 reach the first DW_MACINFO_start_file entry. */
15523 include_hash
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
15524 NULL
, xcalloc
, xfree
);
15525 cleanup
= make_cleanup_htab_delete (include_hash
);
15526 mac_ptr
= section
->buffer
+ offset
;
15527 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
15529 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
15530 current_file
, lh
, comp_dir
, section
, section_is_gnu
,
15531 offset_size
, objfile
, include_hash
);
15532 do_cleanups (cleanup
);
15535 /* Check if the attribute's form is a DW_FORM_block*
15536 if so return true else false. */
15538 attr_form_is_block (struct attribute
*attr
)
15540 return (attr
== NULL
? 0 :
15541 attr
->form
== DW_FORM_block1
15542 || attr
->form
== DW_FORM_block2
15543 || attr
->form
== DW_FORM_block4
15544 || attr
->form
== DW_FORM_block
15545 || attr
->form
== DW_FORM_exprloc
);
15548 /* Return non-zero if ATTR's value is a section offset --- classes
15549 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
15550 You may use DW_UNSND (attr) to retrieve such offsets.
15552 Section 7.5.4, "Attribute Encodings", explains that no attribute
15553 may have a value that belongs to more than one of these classes; it
15554 would be ambiguous if we did, because we use the same forms for all
15557 attr_form_is_section_offset (struct attribute
*attr
)
15559 return (attr
->form
== DW_FORM_data4
15560 || attr
->form
== DW_FORM_data8
15561 || attr
->form
== DW_FORM_sec_offset
);
15565 /* Return non-zero if ATTR's value falls in the 'constant' class, or
15566 zero otherwise. When this function returns true, you can apply
15567 dwarf2_get_attr_constant_value to it.
15569 However, note that for some attributes you must check
15570 attr_form_is_section_offset before using this test. DW_FORM_data4
15571 and DW_FORM_data8 are members of both the constant class, and of
15572 the classes that contain offsets into other debug sections
15573 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
15574 that, if an attribute's can be either a constant or one of the
15575 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
15576 taken as section offsets, not constants. */
15578 attr_form_is_constant (struct attribute
*attr
)
15580 switch (attr
->form
)
15582 case DW_FORM_sdata
:
15583 case DW_FORM_udata
:
15584 case DW_FORM_data1
:
15585 case DW_FORM_data2
:
15586 case DW_FORM_data4
:
15587 case DW_FORM_data8
:
15594 /* A helper function that fills in a dwarf2_loclist_baton. */
15597 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
15598 struct dwarf2_loclist_baton
*baton
,
15599 struct attribute
*attr
)
15601 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
15602 &dwarf2_per_objfile
->loc
);
15604 baton
->per_cu
= cu
->per_cu
;
15605 gdb_assert (baton
->per_cu
);
15606 /* We don't know how long the location list is, but make sure we
15607 don't run off the edge of the section. */
15608 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
15609 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
15610 baton
->base_address
= cu
->base_address
;
15614 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
15615 struct dwarf2_cu
*cu
)
15617 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15619 if (attr_form_is_section_offset (attr
)
15620 /* ".debug_loc" may not exist at all, or the offset may be outside
15621 the section. If so, fall through to the complaint in the
15623 && DW_UNSND (attr
) < dwarf2_section_size (objfile
,
15624 &dwarf2_per_objfile
->loc
))
15626 struct dwarf2_loclist_baton
*baton
;
15628 baton
= obstack_alloc (&objfile
->objfile_obstack
,
15629 sizeof (struct dwarf2_loclist_baton
));
15631 fill_in_loclist_baton (cu
, baton
, attr
);
15633 if (cu
->base_known
== 0)
15634 complaint (&symfile_complaints
,
15635 _("Location list used without "
15636 "specifying the CU base address."));
15638 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
15639 SYMBOL_LOCATION_BATON (sym
) = baton
;
15643 struct dwarf2_locexpr_baton
*baton
;
15645 baton
= obstack_alloc (&objfile
->objfile_obstack
,
15646 sizeof (struct dwarf2_locexpr_baton
));
15647 baton
->per_cu
= cu
->per_cu
;
15648 gdb_assert (baton
->per_cu
);
15650 if (attr_form_is_block (attr
))
15652 /* Note that we're just copying the block's data pointer
15653 here, not the actual data. We're still pointing into the
15654 info_buffer for SYM's objfile; right now we never release
15655 that buffer, but when we do clean up properly this may
15657 baton
->size
= DW_BLOCK (attr
)->size
;
15658 baton
->data
= DW_BLOCK (attr
)->data
;
15662 dwarf2_invalid_attrib_class_complaint ("location description",
15663 SYMBOL_NATURAL_NAME (sym
));
15667 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
15668 SYMBOL_LOCATION_BATON (sym
) = baton
;
15672 /* Return the OBJFILE associated with the compilation unit CU. If CU
15673 came from a separate debuginfo file, then the master objfile is
15677 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
15679 struct objfile
*objfile
= per_cu
->objfile
;
15681 /* Return the master objfile, so that we can report and look up the
15682 correct file containing this variable. */
15683 if (objfile
->separate_debug_objfile_backlink
)
15684 objfile
= objfile
->separate_debug_objfile_backlink
;
15689 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
15690 (CU_HEADERP is unused in such case) or prepare a temporary copy at
15691 CU_HEADERP first. */
15693 static const struct comp_unit_head
*
15694 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
15695 struct dwarf2_per_cu_data
*per_cu
)
15697 struct objfile
*objfile
;
15698 struct dwarf2_per_objfile
*per_objfile
;
15699 gdb_byte
*info_ptr
;
15702 return &per_cu
->cu
->header
;
15704 objfile
= per_cu
->objfile
;
15705 per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
15706 info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
15708 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
15709 read_comp_unit_head (cu_headerp
, info_ptr
, objfile
->obfd
);
15714 /* Return the address size given in the compilation unit header for CU. */
15717 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
15719 struct comp_unit_head cu_header_local
;
15720 const struct comp_unit_head
*cu_headerp
;
15722 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
15724 return cu_headerp
->addr_size
;
15727 /* Return the offset size given in the compilation unit header for CU. */
15730 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
15732 struct comp_unit_head cu_header_local
;
15733 const struct comp_unit_head
*cu_headerp
;
15735 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
15737 return cu_headerp
->offset_size
;
15740 /* See its dwarf2loc.h declaration. */
15743 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
15745 struct comp_unit_head cu_header_local
;
15746 const struct comp_unit_head
*cu_headerp
;
15748 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
15750 if (cu_headerp
->version
== 2)
15751 return cu_headerp
->addr_size
;
15753 return cu_headerp
->offset_size
;
15756 /* Return the text offset of the CU. The returned offset comes from
15757 this CU's objfile. If this objfile came from a separate debuginfo
15758 file, then the offset may be different from the corresponding
15759 offset in the parent objfile. */
15762 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
15764 struct objfile
*objfile
= per_cu
->objfile
;
15766 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15769 /* Locate the .debug_info compilation unit from CU's objfile which contains
15770 the DIE at OFFSET. Raises an error on failure. */
15772 static struct dwarf2_per_cu_data
*
15773 dwarf2_find_containing_comp_unit (unsigned int offset
,
15774 struct objfile
*objfile
)
15776 struct dwarf2_per_cu_data
*this_cu
;
15780 high
= dwarf2_per_objfile
->n_comp_units
- 1;
15783 int mid
= low
+ (high
- low
) / 2;
15785 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
15790 gdb_assert (low
== high
);
15791 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
15794 error (_("Dwarf Error: could not find partial DIE containing "
15795 "offset 0x%lx [in module %s]"),
15796 (long) offset
, bfd_get_filename (objfile
->obfd
));
15798 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
15799 return dwarf2_per_objfile
->all_comp_units
[low
-1];
15803 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
15804 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
15805 && offset
>= this_cu
->offset
+ this_cu
->length
)
15806 error (_("invalid dwarf2 offset %u"), offset
);
15807 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
15812 /* Initialize dwarf2_cu CU, owned by PER_CU. */
15815 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
15817 memset (cu
, 0, sizeof (*cu
));
15819 cu
->per_cu
= per_cu
;
15820 cu
->objfile
= per_cu
->objfile
;
15821 obstack_init (&cu
->comp_unit_obstack
);
15824 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
15827 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
)
15829 struct attribute
*attr
;
15831 /* Set the language we're debugging. */
15832 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
15834 set_cu_language (DW_UNSND (attr
), cu
);
15837 cu
->language
= language_minimal
;
15838 cu
->language_defn
= language_def (cu
->language
);
15842 /* Release one cached compilation unit, CU. We unlink it from the tree
15843 of compilation units, but we don't remove it from the read_in_chain;
15844 the caller is responsible for that.
15845 NOTE: DATA is a void * because this function is also used as a
15846 cleanup routine. */
15849 free_heap_comp_unit (void *data
)
15851 struct dwarf2_cu
*cu
= data
;
15853 gdb_assert (cu
->per_cu
!= NULL
);
15854 cu
->per_cu
->cu
= NULL
;
15857 obstack_free (&cu
->comp_unit_obstack
, NULL
);
15862 /* This cleanup function is passed the address of a dwarf2_cu on the stack
15863 when we're finished with it. We can't free the pointer itself, but be
15864 sure to unlink it from the cache. Also release any associated storage
15865 and perform cache maintenance.
15867 Only used during partial symbol parsing. */
15870 free_stack_comp_unit (void *data
)
15872 struct dwarf2_cu
*cu
= data
;
15874 gdb_assert (cu
->per_cu
!= NULL
);
15875 cu
->per_cu
->cu
= NULL
;
15878 obstack_free (&cu
->comp_unit_obstack
, NULL
);
15879 cu
->partial_dies
= NULL
;
15881 /* The previous code only did this if per_cu != NULL.
15882 But that would always succeed, so now we just unconditionally do
15883 the aging. This seems like the wrong place to do such aging,
15884 but cleaning that up is left for later. */
15885 age_cached_comp_units ();
15888 /* Free all cached compilation units. */
15891 free_cached_comp_units (void *data
)
15893 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15895 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15896 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15897 while (per_cu
!= NULL
)
15899 struct dwarf2_per_cu_data
*next_cu
;
15901 next_cu
= per_cu
->cu
->read_in_chain
;
15903 free_heap_comp_unit (per_cu
->cu
);
15904 *last_chain
= next_cu
;
15910 /* Increase the age counter on each cached compilation unit, and free
15911 any that are too old. */
15914 age_cached_comp_units (void)
15916 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15918 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
15919 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15920 while (per_cu
!= NULL
)
15922 per_cu
->cu
->last_used
++;
15923 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
15924 dwarf2_mark (per_cu
->cu
);
15925 per_cu
= per_cu
->cu
->read_in_chain
;
15928 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15929 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15930 while (per_cu
!= NULL
)
15932 struct dwarf2_per_cu_data
*next_cu
;
15934 next_cu
= per_cu
->cu
->read_in_chain
;
15936 if (!per_cu
->cu
->mark
)
15938 free_heap_comp_unit (per_cu
->cu
);
15939 *last_chain
= next_cu
;
15942 last_chain
= &per_cu
->cu
->read_in_chain
;
15948 /* Remove a single compilation unit from the cache. */
15951 free_one_cached_comp_unit (void *target_cu
)
15953 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15955 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15956 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15957 while (per_cu
!= NULL
)
15959 struct dwarf2_per_cu_data
*next_cu
;
15961 next_cu
= per_cu
->cu
->read_in_chain
;
15963 if (per_cu
->cu
== target_cu
)
15965 free_heap_comp_unit (per_cu
->cu
);
15966 *last_chain
= next_cu
;
15970 last_chain
= &per_cu
->cu
->read_in_chain
;
15976 /* Release all extra memory associated with OBJFILE. */
15979 dwarf2_free_objfile (struct objfile
*objfile
)
15981 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
15983 if (dwarf2_per_objfile
== NULL
)
15986 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
15987 free_cached_comp_units (NULL
);
15989 if (dwarf2_per_objfile
->quick_file_names_table
)
15990 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
15992 /* Everything else should be on the objfile obstack. */
15995 /* A pair of DIE offset and GDB type pointer. We store these
15996 in a hash table separate from the DIEs, and preserve them
15997 when the DIEs are flushed out of cache. */
15999 struct dwarf2_offset_and_type
16001 unsigned int offset
;
16005 /* Hash function for a dwarf2_offset_and_type. */
16008 offset_and_type_hash (const void *item
)
16010 const struct dwarf2_offset_and_type
*ofs
= item
;
16012 return ofs
->offset
;
16015 /* Equality function for a dwarf2_offset_and_type. */
16018 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
16020 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
16021 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
16023 return ofs_lhs
->offset
== ofs_rhs
->offset
;
16026 /* Set the type associated with DIE to TYPE. Save it in CU's hash
16027 table if necessary. For convenience, return TYPE.
16029 The DIEs reading must have careful ordering to:
16030 * Not cause infite loops trying to read in DIEs as a prerequisite for
16031 reading current DIE.
16032 * Not trying to dereference contents of still incompletely read in types
16033 while reading in other DIEs.
16034 * Enable referencing still incompletely read in types just by a pointer to
16035 the type without accessing its fields.
16037 Therefore caller should follow these rules:
16038 * Try to fetch any prerequisite types we may need to build this DIE type
16039 before building the type and calling set_die_type.
16040 * After building type call set_die_type for current DIE as soon as
16041 possible before fetching more types to complete the current type.
16042 * Make the type as complete as possible before fetching more types. */
16044 static struct type
*
16045 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
16047 struct dwarf2_offset_and_type
**slot
, ofs
;
16048 struct objfile
*objfile
= cu
->objfile
;
16049 htab_t
*type_hash_ptr
;
16051 /* For Ada types, make sure that the gnat-specific data is always
16052 initialized (if not already set). There are a few types where
16053 we should not be doing so, because the type-specific area is
16054 already used to hold some other piece of info (eg: TYPE_CODE_FLT
16055 where the type-specific area is used to store the floatformat).
16056 But this is not a problem, because the gnat-specific information
16057 is actually not needed for these types. */
16058 if (need_gnat_info (cu
)
16059 && TYPE_CODE (type
) != TYPE_CODE_FUNC
16060 && TYPE_CODE (type
) != TYPE_CODE_FLT
16061 && !HAVE_GNAT_AUX_INFO (type
))
16062 INIT_GNAT_SPECIFIC (type
);
16064 if (cu
->per_cu
->debug_types_section
)
16065 type_hash_ptr
= &dwarf2_per_objfile
->debug_types_type_hash
;
16067 type_hash_ptr
= &dwarf2_per_objfile
->debug_info_type_hash
;
16069 if (*type_hash_ptr
== NULL
)
16072 = htab_create_alloc_ex (127,
16073 offset_and_type_hash
,
16074 offset_and_type_eq
,
16076 &objfile
->objfile_obstack
,
16077 hashtab_obstack_allocate
,
16078 dummy_obstack_deallocate
);
16081 ofs
.offset
= die
->offset
;
16083 slot
= (struct dwarf2_offset_and_type
**)
16084 htab_find_slot_with_hash (*type_hash_ptr
, &ofs
, ofs
.offset
, INSERT
);
16086 complaint (&symfile_complaints
,
16087 _("A problem internal to GDB: DIE 0x%x has type already set"),
16089 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
16094 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
16095 table, or return NULL if the die does not have a saved type. */
16097 static struct type
*
16098 get_die_type_at_offset (unsigned int offset
,
16099 struct dwarf2_per_cu_data
*per_cu
)
16101 struct dwarf2_offset_and_type
*slot
, ofs
;
16104 if (per_cu
->debug_types_section
)
16105 type_hash
= dwarf2_per_objfile
->debug_types_type_hash
;
16107 type_hash
= dwarf2_per_objfile
->debug_info_type_hash
;
16108 if (type_hash
== NULL
)
16111 ofs
.offset
= offset
;
16112 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
16119 /* Look up the type for DIE in the appropriate type_hash table,
16120 or return NULL if DIE does not have a saved type. */
16122 static struct type
*
16123 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16125 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
16128 /* Add a dependence relationship from CU to REF_PER_CU. */
16131 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
16132 struct dwarf2_per_cu_data
*ref_per_cu
)
16136 if (cu
->dependencies
== NULL
)
16138 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
16139 NULL
, &cu
->comp_unit_obstack
,
16140 hashtab_obstack_allocate
,
16141 dummy_obstack_deallocate
);
16143 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
16145 *slot
= ref_per_cu
;
16148 /* Subroutine of dwarf2_mark to pass to htab_traverse.
16149 Set the mark field in every compilation unit in the
16150 cache that we must keep because we are keeping CU. */
16153 dwarf2_mark_helper (void **slot
, void *data
)
16155 struct dwarf2_per_cu_data
*per_cu
;
16157 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
16159 /* cu->dependencies references may not yet have been ever read if QUIT aborts
16160 reading of the chain. As such dependencies remain valid it is not much
16161 useful to track and undo them during QUIT cleanups. */
16162 if (per_cu
->cu
== NULL
)
16165 if (per_cu
->cu
->mark
)
16167 per_cu
->cu
->mark
= 1;
16169 if (per_cu
->cu
->dependencies
!= NULL
)
16170 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
16175 /* Set the mark field in CU and in every other compilation unit in the
16176 cache that we must keep because we are keeping CU. */
16179 dwarf2_mark (struct dwarf2_cu
*cu
)
16184 if (cu
->dependencies
!= NULL
)
16185 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
16189 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
16193 per_cu
->cu
->mark
= 0;
16194 per_cu
= per_cu
->cu
->read_in_chain
;
16198 /* Trivial hash function for partial_die_info: the hash value of a DIE
16199 is its offset in .debug_info for this objfile. */
16202 partial_die_hash (const void *item
)
16204 const struct partial_die_info
*part_die
= item
;
16206 return part_die
->offset
;
16209 /* Trivial comparison function for partial_die_info structures: two DIEs
16210 are equal if they have the same offset. */
16213 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
16215 const struct partial_die_info
*part_die_lhs
= item_lhs
;
16216 const struct partial_die_info
*part_die_rhs
= item_rhs
;
16218 return part_die_lhs
->offset
== part_die_rhs
->offset
;
16221 static struct cmd_list_element
*set_dwarf2_cmdlist
;
16222 static struct cmd_list_element
*show_dwarf2_cmdlist
;
16225 set_dwarf2_cmd (char *args
, int from_tty
)
16227 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
16231 show_dwarf2_cmd (char *args
, int from_tty
)
16233 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
16236 /* If section described by INFO was mmapped, munmap it now. */
16239 munmap_section_buffer (struct dwarf2_section_info
*info
)
16241 if (info
->map_addr
!= NULL
)
16246 res
= munmap (info
->map_addr
, info
->map_len
);
16247 gdb_assert (res
== 0);
16249 /* Without HAVE_MMAP, we should never be here to begin with. */
16250 gdb_assert_not_reached ("no mmap support");
16255 /* munmap debug sections for OBJFILE, if necessary. */
16258 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
16260 struct dwarf2_per_objfile
*data
= d
;
16262 struct dwarf2_section_info
*section
;
16264 /* This is sorted according to the order they're defined in to make it easier
16265 to keep in sync. */
16266 munmap_section_buffer (&data
->info
);
16267 munmap_section_buffer (&data
->abbrev
);
16268 munmap_section_buffer (&data
->line
);
16269 munmap_section_buffer (&data
->loc
);
16270 munmap_section_buffer (&data
->macinfo
);
16271 munmap_section_buffer (&data
->macro
);
16272 munmap_section_buffer (&data
->str
);
16273 munmap_section_buffer (&data
->ranges
);
16274 munmap_section_buffer (&data
->frame
);
16275 munmap_section_buffer (&data
->eh_frame
);
16276 munmap_section_buffer (&data
->gdb_index
);
16279 VEC_iterate (dwarf2_section_info_def
, data
->types
, ix
, section
);
16281 munmap_section_buffer (section
);
16283 VEC_free (dwarf2_section_info_def
, data
->types
);
16287 /* The "save gdb-index" command. */
16289 /* The contents of the hash table we create when building the string
16291 struct strtab_entry
16293 offset_type offset
;
16297 /* Hash function for a strtab_entry.
16299 Function is used only during write_hash_table so no index format backward
16300 compatibility is needed. */
16303 hash_strtab_entry (const void *e
)
16305 const struct strtab_entry
*entry
= e
;
16306 return mapped_index_string_hash (INT_MAX
, entry
->str
);
16309 /* Equality function for a strtab_entry. */
16312 eq_strtab_entry (const void *a
, const void *b
)
16314 const struct strtab_entry
*ea
= a
;
16315 const struct strtab_entry
*eb
= b
;
16316 return !strcmp (ea
->str
, eb
->str
);
16319 /* Create a strtab_entry hash table. */
16322 create_strtab (void)
16324 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
16325 xfree
, xcalloc
, xfree
);
16328 /* Add a string to the constant pool. Return the string's offset in
16332 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
16335 struct strtab_entry entry
;
16336 struct strtab_entry
*result
;
16339 slot
= htab_find_slot (table
, &entry
, INSERT
);
16344 result
= XNEW (struct strtab_entry
);
16345 result
->offset
= obstack_object_size (cpool
);
16347 obstack_grow_str0 (cpool
, str
);
16350 return result
->offset
;
16353 /* An entry in the symbol table. */
16354 struct symtab_index_entry
16356 /* The name of the symbol. */
16358 /* The offset of the name in the constant pool. */
16359 offset_type index_offset
;
16360 /* A sorted vector of the indices of all the CUs that hold an object
16362 VEC (offset_type
) *cu_indices
;
16365 /* The symbol table. This is a power-of-2-sized hash table. */
16366 struct mapped_symtab
16368 offset_type n_elements
;
16370 struct symtab_index_entry
**data
;
16373 /* Hash function for a symtab_index_entry. */
16376 hash_symtab_entry (const void *e
)
16378 const struct symtab_index_entry
*entry
= e
;
16379 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
16380 sizeof (offset_type
) * VEC_length (offset_type
,
16381 entry
->cu_indices
),
16385 /* Equality function for a symtab_index_entry. */
16388 eq_symtab_entry (const void *a
, const void *b
)
16390 const struct symtab_index_entry
*ea
= a
;
16391 const struct symtab_index_entry
*eb
= b
;
16392 int len
= VEC_length (offset_type
, ea
->cu_indices
);
16393 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
16395 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
16396 VEC_address (offset_type
, eb
->cu_indices
),
16397 sizeof (offset_type
) * len
);
16400 /* Destroy a symtab_index_entry. */
16403 delete_symtab_entry (void *p
)
16405 struct symtab_index_entry
*entry
= p
;
16406 VEC_free (offset_type
, entry
->cu_indices
);
16410 /* Create a hash table holding symtab_index_entry objects. */
16413 create_symbol_hash_table (void)
16415 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
16416 delete_symtab_entry
, xcalloc
, xfree
);
16419 /* Create a new mapped symtab object. */
16421 static struct mapped_symtab
*
16422 create_mapped_symtab (void)
16424 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
16425 symtab
->n_elements
= 0;
16426 symtab
->size
= 1024;
16427 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
16431 /* Destroy a mapped_symtab. */
16434 cleanup_mapped_symtab (void *p
)
16436 struct mapped_symtab
*symtab
= p
;
16437 /* The contents of the array are freed when the other hash table is
16439 xfree (symtab
->data
);
16443 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
16446 Function is used only during write_hash_table so no index format backward
16447 compatibility is needed. */
16449 static struct symtab_index_entry
**
16450 find_slot (struct mapped_symtab
*symtab
, const char *name
)
16452 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
16454 index
= hash
& (symtab
->size
- 1);
16455 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
16459 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
16460 return &symtab
->data
[index
];
16461 index
= (index
+ step
) & (symtab
->size
- 1);
16465 /* Expand SYMTAB's hash table. */
16468 hash_expand (struct mapped_symtab
*symtab
)
16470 offset_type old_size
= symtab
->size
;
16472 struct symtab_index_entry
**old_entries
= symtab
->data
;
16475 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
16477 for (i
= 0; i
< old_size
; ++i
)
16479 if (old_entries
[i
])
16481 struct symtab_index_entry
**slot
= find_slot (symtab
,
16482 old_entries
[i
]->name
);
16483 *slot
= old_entries
[i
];
16487 xfree (old_entries
);
16490 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
16491 is the index of the CU in which the symbol appears. */
16494 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
16495 offset_type cu_index
)
16497 struct symtab_index_entry
**slot
;
16499 ++symtab
->n_elements
;
16500 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
16501 hash_expand (symtab
);
16503 slot
= find_slot (symtab
, name
);
16506 *slot
= XNEW (struct symtab_index_entry
);
16507 (*slot
)->name
= name
;
16508 (*slot
)->cu_indices
= NULL
;
16510 /* Don't push an index twice. Due to how we add entries we only
16511 have to check the last one. */
16512 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
16513 || VEC_last (offset_type
, (*slot
)->cu_indices
) != cu_index
)
16514 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
16517 /* Add a vector of indices to the constant pool. */
16520 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
16521 struct symtab_index_entry
*entry
)
16525 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
16528 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
16529 offset_type val
= MAYBE_SWAP (len
);
16534 entry
->index_offset
= obstack_object_size (cpool
);
16536 obstack_grow (cpool
, &val
, sizeof (val
));
16538 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
16541 val
= MAYBE_SWAP (iter
);
16542 obstack_grow (cpool
, &val
, sizeof (val
));
16547 struct symtab_index_entry
*old_entry
= *slot
;
16548 entry
->index_offset
= old_entry
->index_offset
;
16551 return entry
->index_offset
;
16554 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
16555 constant pool entries going into the obstack CPOOL. */
16558 write_hash_table (struct mapped_symtab
*symtab
,
16559 struct obstack
*output
, struct obstack
*cpool
)
16562 htab_t symbol_hash_table
;
16565 symbol_hash_table
= create_symbol_hash_table ();
16566 str_table
= create_strtab ();
16568 /* We add all the index vectors to the constant pool first, to
16569 ensure alignment is ok. */
16570 for (i
= 0; i
< symtab
->size
; ++i
)
16572 if (symtab
->data
[i
])
16573 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
16576 /* Now write out the hash table. */
16577 for (i
= 0; i
< symtab
->size
; ++i
)
16579 offset_type str_off
, vec_off
;
16581 if (symtab
->data
[i
])
16583 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
16584 vec_off
= symtab
->data
[i
]->index_offset
;
16588 /* While 0 is a valid constant pool index, it is not valid
16589 to have 0 for both offsets. */
16594 str_off
= MAYBE_SWAP (str_off
);
16595 vec_off
= MAYBE_SWAP (vec_off
);
16597 obstack_grow (output
, &str_off
, sizeof (str_off
));
16598 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
16601 htab_delete (str_table
);
16602 htab_delete (symbol_hash_table
);
16605 /* Struct to map psymtab to CU index in the index file. */
16606 struct psymtab_cu_index_map
16608 struct partial_symtab
*psymtab
;
16609 unsigned int cu_index
;
16613 hash_psymtab_cu_index (const void *item
)
16615 const struct psymtab_cu_index_map
*map
= item
;
16617 return htab_hash_pointer (map
->psymtab
);
16621 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
16623 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
16624 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
16626 return lhs
->psymtab
== rhs
->psymtab
;
16629 /* Helper struct for building the address table. */
16630 struct addrmap_index_data
16632 struct objfile
*objfile
;
16633 struct obstack
*addr_obstack
;
16634 htab_t cu_index_htab
;
16636 /* Non-zero if the previous_* fields are valid.
16637 We can't write an entry until we see the next entry (since it is only then
16638 that we know the end of the entry). */
16639 int previous_valid
;
16640 /* Index of the CU in the table of all CUs in the index file. */
16641 unsigned int previous_cu_index
;
16642 /* Start address of the CU. */
16643 CORE_ADDR previous_cu_start
;
16646 /* Write an address entry to OBSTACK. */
16649 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
16650 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
16652 offset_type cu_index_to_write
;
16654 CORE_ADDR baseaddr
;
16656 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
16658 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
16659 obstack_grow (obstack
, addr
, 8);
16660 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
16661 obstack_grow (obstack
, addr
, 8);
16662 cu_index_to_write
= MAYBE_SWAP (cu_index
);
16663 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
16666 /* Worker function for traversing an addrmap to build the address table. */
16669 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
16671 struct addrmap_index_data
*data
= datap
;
16672 struct partial_symtab
*pst
= obj
;
16673 offset_type cu_index
;
16676 if (data
->previous_valid
)
16677 add_address_entry (data
->objfile
, data
->addr_obstack
,
16678 data
->previous_cu_start
, start_addr
,
16679 data
->previous_cu_index
);
16681 data
->previous_cu_start
= start_addr
;
16684 struct psymtab_cu_index_map find_map
, *map
;
16685 find_map
.psymtab
= pst
;
16686 map
= htab_find (data
->cu_index_htab
, &find_map
);
16687 gdb_assert (map
!= NULL
);
16688 data
->previous_cu_index
= map
->cu_index
;
16689 data
->previous_valid
= 1;
16692 data
->previous_valid
= 0;
16697 /* Write OBJFILE's address map to OBSTACK.
16698 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
16699 in the index file. */
16702 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
16703 htab_t cu_index_htab
)
16705 struct addrmap_index_data addrmap_index_data
;
16707 /* When writing the address table, we have to cope with the fact that
16708 the addrmap iterator only provides the start of a region; we have to
16709 wait until the next invocation to get the start of the next region. */
16711 addrmap_index_data
.objfile
= objfile
;
16712 addrmap_index_data
.addr_obstack
= obstack
;
16713 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
16714 addrmap_index_data
.previous_valid
= 0;
16716 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
16717 &addrmap_index_data
);
16719 /* It's highly unlikely the last entry (end address = 0xff...ff)
16720 is valid, but we should still handle it.
16721 The end address is recorded as the start of the next region, but that
16722 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
16724 if (addrmap_index_data
.previous_valid
)
16725 add_address_entry (objfile
, obstack
,
16726 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
16727 addrmap_index_data
.previous_cu_index
);
16730 /* Add a list of partial symbols to SYMTAB. */
16733 write_psymbols (struct mapped_symtab
*symtab
,
16735 struct partial_symbol
**psymp
,
16737 offset_type cu_index
,
16740 for (; count
-- > 0; ++psymp
)
16742 void **slot
, *lookup
;
16744 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
16745 error (_("Ada is not currently supported by the index"));
16747 /* We only want to add a given psymbol once. However, we also
16748 want to account for whether it is global or static. So, we
16749 may add it twice, using slightly different values. */
16752 uintptr_t val
= 1 | (uintptr_t) *psymp
;
16754 lookup
= (void *) val
;
16759 /* Only add a given psymbol once. */
16760 slot
= htab_find_slot (psyms_seen
, lookup
, INSERT
);
16764 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (*psymp
), cu_index
);
16769 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
16770 exception if there is an error. */
16773 write_obstack (FILE *file
, struct obstack
*obstack
)
16775 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
16777 != obstack_object_size (obstack
))
16778 error (_("couldn't data write to file"));
16781 /* Unlink a file if the argument is not NULL. */
16784 unlink_if_set (void *p
)
16786 char **filename
= p
;
16788 unlink (*filename
);
16791 /* A helper struct used when iterating over debug_types. */
16792 struct signatured_type_index_data
16794 struct objfile
*objfile
;
16795 struct mapped_symtab
*symtab
;
16796 struct obstack
*types_list
;
16801 /* A helper function that writes a single signatured_type to an
16805 write_one_signatured_type (void **slot
, void *d
)
16807 struct signatured_type_index_data
*info
= d
;
16808 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
16809 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
16810 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
16813 write_psymbols (info
->symtab
,
16815 info
->objfile
->global_psymbols
.list
16816 + psymtab
->globals_offset
,
16817 psymtab
->n_global_syms
, info
->cu_index
,
16819 write_psymbols (info
->symtab
,
16821 info
->objfile
->static_psymbols
.list
16822 + psymtab
->statics_offset
,
16823 psymtab
->n_static_syms
, info
->cu_index
,
16826 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->per_cu
.offset
);
16827 obstack_grow (info
->types_list
, val
, 8);
16828 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->type_offset
);
16829 obstack_grow (info
->types_list
, val
, 8);
16830 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
16831 obstack_grow (info
->types_list
, val
, 8);
16838 /* Create an index file for OBJFILE in the directory DIR. */
16841 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
16843 struct cleanup
*cleanup
;
16844 char *filename
, *cleanup_filename
;
16845 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
16846 struct obstack cu_list
, types_cu_list
;
16849 struct mapped_symtab
*symtab
;
16850 offset_type val
, size_of_contents
, total_len
;
16854 htab_t cu_index_htab
;
16855 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
16857 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
16860 if (dwarf2_per_objfile
->using_index
)
16861 error (_("Cannot use an index to create the index"));
16863 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
16864 error (_("Cannot make an index when the file has multiple .debug_types sections"));
16866 if (stat (objfile
->name
, &st
) < 0)
16867 perror_with_name (objfile
->name
);
16869 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
16870 INDEX_SUFFIX
, (char *) NULL
);
16871 cleanup
= make_cleanup (xfree
, filename
);
16873 out_file
= fopen (filename
, "wb");
16875 error (_("Can't open `%s' for writing"), filename
);
16877 cleanup_filename
= filename
;
16878 make_cleanup (unlink_if_set
, &cleanup_filename
);
16880 symtab
= create_mapped_symtab ();
16881 make_cleanup (cleanup_mapped_symtab
, symtab
);
16883 obstack_init (&addr_obstack
);
16884 make_cleanup_obstack_free (&addr_obstack
);
16886 obstack_init (&cu_list
);
16887 make_cleanup_obstack_free (&cu_list
);
16889 obstack_init (&types_cu_list
);
16890 make_cleanup_obstack_free (&types_cu_list
);
16892 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
16893 NULL
, xcalloc
, xfree
);
16894 make_cleanup_htab_delete (psyms_seen
);
16896 /* While we're scanning CU's create a table that maps a psymtab pointer
16897 (which is what addrmap records) to its index (which is what is recorded
16898 in the index file). This will later be needed to write the address
16900 cu_index_htab
= htab_create_alloc (100,
16901 hash_psymtab_cu_index
,
16902 eq_psymtab_cu_index
,
16903 NULL
, xcalloc
, xfree
);
16904 make_cleanup_htab_delete (cu_index_htab
);
16905 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
16906 xmalloc (sizeof (struct psymtab_cu_index_map
)
16907 * dwarf2_per_objfile
->n_comp_units
);
16908 make_cleanup (xfree
, psymtab_cu_index_map
);
16910 /* The CU list is already sorted, so we don't need to do additional
16911 work here. Also, the debug_types entries do not appear in
16912 all_comp_units, but only in their own hash table. */
16913 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
16915 struct dwarf2_per_cu_data
*per_cu
16916 = dwarf2_per_objfile
->all_comp_units
[i
];
16917 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
16919 struct psymtab_cu_index_map
*map
;
16922 write_psymbols (symtab
,
16924 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
16925 psymtab
->n_global_syms
, i
,
16927 write_psymbols (symtab
,
16929 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
16930 psymtab
->n_static_syms
, i
,
16933 map
= &psymtab_cu_index_map
[i
];
16934 map
->psymtab
= psymtab
;
16936 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
16937 gdb_assert (slot
!= NULL
);
16938 gdb_assert (*slot
== NULL
);
16941 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->offset
);
16942 obstack_grow (&cu_list
, val
, 8);
16943 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
16944 obstack_grow (&cu_list
, val
, 8);
16947 /* Dump the address map. */
16948 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
16950 /* Write out the .debug_type entries, if any. */
16951 if (dwarf2_per_objfile
->signatured_types
)
16953 struct signatured_type_index_data sig_data
;
16955 sig_data
.objfile
= objfile
;
16956 sig_data
.symtab
= symtab
;
16957 sig_data
.types_list
= &types_cu_list
;
16958 sig_data
.psyms_seen
= psyms_seen
;
16959 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
16960 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
16961 write_one_signatured_type
, &sig_data
);
16964 obstack_init (&constant_pool
);
16965 make_cleanup_obstack_free (&constant_pool
);
16966 obstack_init (&symtab_obstack
);
16967 make_cleanup_obstack_free (&symtab_obstack
);
16968 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
16970 obstack_init (&contents
);
16971 make_cleanup_obstack_free (&contents
);
16972 size_of_contents
= 6 * sizeof (offset_type
);
16973 total_len
= size_of_contents
;
16975 /* The version number. */
16976 val
= MAYBE_SWAP (5);
16977 obstack_grow (&contents
, &val
, sizeof (val
));
16979 /* The offset of the CU list from the start of the file. */
16980 val
= MAYBE_SWAP (total_len
);
16981 obstack_grow (&contents
, &val
, sizeof (val
));
16982 total_len
+= obstack_object_size (&cu_list
);
16984 /* The offset of the types CU list from the start of the file. */
16985 val
= MAYBE_SWAP (total_len
);
16986 obstack_grow (&contents
, &val
, sizeof (val
));
16987 total_len
+= obstack_object_size (&types_cu_list
);
16989 /* The offset of the address table from the start of the file. */
16990 val
= MAYBE_SWAP (total_len
);
16991 obstack_grow (&contents
, &val
, sizeof (val
));
16992 total_len
+= obstack_object_size (&addr_obstack
);
16994 /* The offset of the symbol table from the start of the file. */
16995 val
= MAYBE_SWAP (total_len
);
16996 obstack_grow (&contents
, &val
, sizeof (val
));
16997 total_len
+= obstack_object_size (&symtab_obstack
);
16999 /* The offset of the constant pool from the start of the file. */
17000 val
= MAYBE_SWAP (total_len
);
17001 obstack_grow (&contents
, &val
, sizeof (val
));
17002 total_len
+= obstack_object_size (&constant_pool
);
17004 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
17006 write_obstack (out_file
, &contents
);
17007 write_obstack (out_file
, &cu_list
);
17008 write_obstack (out_file
, &types_cu_list
);
17009 write_obstack (out_file
, &addr_obstack
);
17010 write_obstack (out_file
, &symtab_obstack
);
17011 write_obstack (out_file
, &constant_pool
);
17015 /* We want to keep the file, so we set cleanup_filename to NULL
17016 here. See unlink_if_set. */
17017 cleanup_filename
= NULL
;
17019 do_cleanups (cleanup
);
17022 /* Implementation of the `save gdb-index' command.
17024 Note that the file format used by this command is documented in the
17025 GDB manual. Any changes here must be documented there. */
17028 save_gdb_index_command (char *arg
, int from_tty
)
17030 struct objfile
*objfile
;
17033 error (_("usage: save gdb-index DIRECTORY"));
17035 ALL_OBJFILES (objfile
)
17039 /* If the objfile does not correspond to an actual file, skip it. */
17040 if (stat (objfile
->name
, &st
) < 0)
17043 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
17044 if (dwarf2_per_objfile
)
17046 volatile struct gdb_exception except
;
17048 TRY_CATCH (except
, RETURN_MASK_ERROR
)
17050 write_psymtabs_to_index (objfile
, arg
);
17052 if (except
.reason
< 0)
17053 exception_fprintf (gdb_stderr
, except
,
17054 _("Error while writing index for `%s': "),
17062 int dwarf2_always_disassemble
;
17065 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
17066 struct cmd_list_element
*c
, const char *value
)
17068 fprintf_filtered (file
,
17069 _("Whether to always disassemble "
17070 "DWARF expressions is %s.\n"),
17075 show_check_physname (struct ui_file
*file
, int from_tty
,
17076 struct cmd_list_element
*c
, const char *value
)
17078 fprintf_filtered (file
,
17079 _("Whether to check \"physname\" is %s.\n"),
17083 void _initialize_dwarf2_read (void);
17086 _initialize_dwarf2_read (void)
17088 struct cmd_list_element
*c
;
17090 dwarf2_objfile_data_key
17091 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
17093 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
17094 Set DWARF 2 specific variables.\n\
17095 Configure DWARF 2 variables such as the cache size"),
17096 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
17097 0/*allow-unknown*/, &maintenance_set_cmdlist
);
17099 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
17100 Show DWARF 2 specific variables\n\
17101 Show DWARF 2 variables such as the cache size"),
17102 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
17103 0/*allow-unknown*/, &maintenance_show_cmdlist
);
17105 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
17106 &dwarf2_max_cache_age
, _("\
17107 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
17108 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
17109 A higher limit means that cached compilation units will be stored\n\
17110 in memory longer, and more total memory will be used. Zero disables\n\
17111 caching, which can slow down startup."),
17113 show_dwarf2_max_cache_age
,
17114 &set_dwarf2_cmdlist
,
17115 &show_dwarf2_cmdlist
);
17117 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
17118 &dwarf2_always_disassemble
, _("\
17119 Set whether `info address' always disassembles DWARF expressions."), _("\
17120 Show whether `info address' always disassembles DWARF expressions."), _("\
17121 When enabled, DWARF expressions are always printed in an assembly-like\n\
17122 syntax. When disabled, expressions will be printed in a more\n\
17123 conversational style, when possible."),
17125 show_dwarf2_always_disassemble
,
17126 &set_dwarf2_cmdlist
,
17127 &show_dwarf2_cmdlist
);
17129 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
17130 Set debugging of the dwarf2 DIE reader."), _("\
17131 Show debugging of the dwarf2 DIE reader."), _("\
17132 When enabled (non-zero), DIEs are dumped after they are read in.\n\
17133 The value is the maximum depth to print."),
17136 &setdebuglist
, &showdebuglist
);
17138 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
17139 Set cross-checking of \"physname\" code against demangler."), _("\
17140 Show cross-checking of \"physname\" code against demangler."), _("\
17141 When enabled, GDB's internal \"physname\" code is checked against\n\
17143 NULL
, show_check_physname
,
17144 &setdebuglist
, &showdebuglist
);
17146 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
17148 Save a gdb-index file.\n\
17149 Usage: save gdb-index DIRECTORY"),
17151 set_cmd_completer (c
, filename_completer
);