1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
5 Free Software Foundation, Inc.
7 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
8 Inc. with support from Florida State University (under contract
9 with the Ada Joint Program Office), and Silicon Graphics, Inc.
10 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
11 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
14 This file is part of GDB.
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 3 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>. */
37 #include "expression.h"
38 #include "filenames.h" /* for DOSish file names */
41 #include "complaints.h"
43 #include "dwarf2expr.h"
44 #include "dwarf2loc.h"
45 #include "cp-support.h"
51 #include "typeprint.h"
54 #include "exceptions.h"
56 #include "completer.h"
63 #include "gdb_string.h"
64 #include "gdb_assert.h"
65 #include <sys/types.h>
72 #define MAP_FAILED ((void *) -1)
76 typedef struct symbol
*symbolp
;
80 /* .debug_info header for a compilation unit
81 Because of alignment constraints, this structure has padding and cannot
82 be mapped directly onto the beginning of the .debug_info section. */
83 typedef struct comp_unit_header
85 unsigned int length
; /* length of the .debug_info
87 unsigned short version
; /* version number -- 2 for DWARF
89 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
90 unsigned char addr_size
; /* byte size of an address -- 4 */
93 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
96 /* .debug_line statement program prologue
97 Because of alignment constraints, this structure has padding and cannot
98 be mapped directly onto the beginning of the .debug_info section. */
99 typedef struct statement_prologue
101 unsigned int total_length
; /* byte length of the statement
103 unsigned short version
; /* version number -- 2 for DWARF
105 unsigned int prologue_length
; /* # bytes between prologue &
107 unsigned char minimum_instruction_length
; /* byte size of
109 unsigned char default_is_stmt
; /* initial value of is_stmt
112 unsigned char line_range
;
113 unsigned char opcode_base
; /* number assigned to first special
115 unsigned char *standard_opcode_lengths
;
119 /* When non-zero, dump DIEs after they are read in. */
120 static int dwarf2_die_debug
= 0;
122 /* When non-zero, cross-check physname against demangler. */
123 static int check_physname
= 0;
127 /* When set, the file that we're processing is known to have debugging
128 info for C++ namespaces. GCC 3.3.x did not produce this information,
129 but later versions do. */
131 static int processing_has_namespace_info
;
133 static const struct objfile_data
*dwarf2_objfile_data_key
;
135 struct dwarf2_section_info
140 /* Not NULL if the section was actually mmapped. */
142 /* Page aligned size of mmapped area. */
143 bfd_size_type map_len
;
144 /* True if we have tried to read this section. */
148 typedef struct dwarf2_section_info dwarf2_section_info_def
;
149 DEF_VEC_O (dwarf2_section_info_def
);
151 /* All offsets in the index are of this type. It must be
152 architecture-independent. */
153 typedef uint32_t offset_type
;
155 DEF_VEC_I (offset_type
);
157 /* A description of the mapped index. The file format is described in
158 a comment by the code that writes the index. */
161 /* Index data format version. */
164 /* The total length of the buffer. */
167 /* A pointer to the address table data. */
168 const gdb_byte
*address_table
;
170 /* Size of the address table data in bytes. */
171 offset_type address_table_size
;
173 /* The symbol table, implemented as a hash table. */
174 const offset_type
*symbol_table
;
176 /* Size in slots, each slot is 2 offset_types. */
177 offset_type symbol_table_slots
;
179 /* A pointer to the constant pool. */
180 const char *constant_pool
;
183 struct dwarf2_per_objfile
185 struct dwarf2_section_info info
;
186 struct dwarf2_section_info abbrev
;
187 struct dwarf2_section_info line
;
188 struct dwarf2_section_info loc
;
189 struct dwarf2_section_info macinfo
;
190 struct dwarf2_section_info macro
;
191 struct dwarf2_section_info str
;
192 struct dwarf2_section_info ranges
;
193 struct dwarf2_section_info frame
;
194 struct dwarf2_section_info eh_frame
;
195 struct dwarf2_section_info gdb_index
;
197 VEC (dwarf2_section_info_def
) *types
;
200 struct objfile
*objfile
;
202 /* A list of all the compilation units. This is used to locate
203 the target compilation unit of a particular reference. */
204 struct dwarf2_per_cu_data
**all_comp_units
;
206 /* The number of compilation units in ALL_COMP_UNITS. */
209 /* The number of .debug_types-related CUs. */
210 int n_type_comp_units
;
212 /* The .debug_types-related CUs. */
213 struct dwarf2_per_cu_data
**type_comp_units
;
215 /* A chain of compilation units that are currently read in, so that
216 they can be freed later. */
217 struct dwarf2_per_cu_data
*read_in_chain
;
219 /* A table mapping .debug_types signatures to its signatured_type entry.
220 This is NULL if the .debug_types section hasn't been read in yet. */
221 htab_t signatured_types
;
223 /* A flag indicating wether this objfile has a section loaded at a
225 int has_section_at_zero
;
227 /* True if we are using the mapped index,
228 or we are faking it for OBJF_READNOW's sake. */
229 unsigned char using_index
;
231 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
232 struct mapped_index
*index_table
;
234 /* When using index_table, this keeps track of all quick_file_names entries.
235 TUs can share line table entries with CUs or other TUs, and there can be
236 a lot more TUs than unique line tables, so we maintain a separate table
237 of all line table entries to support the sharing. */
238 htab_t quick_file_names_table
;
240 /* Set during partial symbol reading, to prevent queueing of full
242 int reading_partial_symbols
;
244 /* Table mapping type .debug_info DIE offsets to types.
245 This is NULL if not allocated yet.
246 It (currently) makes sense to allocate debug_types_type_hash lazily.
247 To keep things simple we allocate both lazily. */
248 htab_t debug_info_type_hash
;
250 /* Table mapping type .debug_types DIE offsets to types.
251 This is NULL if not allocated yet. */
252 htab_t debug_types_type_hash
;
255 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
257 /* Default names of the debugging sections. */
259 /* Note that if the debugging section has been compressed, it might
260 have a name like .zdebug_info. */
262 static const struct dwarf2_debug_sections dwarf2_elf_names
= {
263 { ".debug_info", ".zdebug_info" },
264 { ".debug_abbrev", ".zdebug_abbrev" },
265 { ".debug_line", ".zdebug_line" },
266 { ".debug_loc", ".zdebug_loc" },
267 { ".debug_macinfo", ".zdebug_macinfo" },
268 { ".debug_macro", ".zdebug_macro" },
269 { ".debug_str", ".zdebug_str" },
270 { ".debug_ranges", ".zdebug_ranges" },
271 { ".debug_types", ".zdebug_types" },
272 { ".debug_frame", ".zdebug_frame" },
273 { ".eh_frame", NULL
},
274 { ".gdb_index", ".zgdb_index" },
278 /* local data types */
280 /* We hold several abbreviation tables in memory at the same time. */
281 #ifndef ABBREV_HASH_SIZE
282 #define ABBREV_HASH_SIZE 121
285 /* The data in a compilation unit header, after target2host
286 translation, looks like this. */
287 struct comp_unit_head
291 unsigned char addr_size
;
292 unsigned char signed_addr_p
;
293 unsigned int abbrev_offset
;
295 /* Size of file offsets; either 4 or 8. */
296 unsigned int offset_size
;
298 /* Size of the length field; either 4 or 12. */
299 unsigned int initial_length_size
;
301 /* Offset to the first byte of this compilation unit header in the
302 .debug_info section, for resolving relative reference dies. */
305 /* Offset to first die in this cu from the start of the cu.
306 This will be the first byte following the compilation unit header. */
307 unsigned int first_die_offset
;
310 /* Type used for delaying computation of method physnames.
311 See comments for compute_delayed_physnames. */
312 struct delayed_method_info
314 /* The type to which the method is attached, i.e., its parent class. */
317 /* The index of the method in the type's function fieldlists. */
320 /* The index of the method in the fieldlist. */
323 /* The name of the DIE. */
326 /* The DIE associated with this method. */
327 struct die_info
*die
;
330 typedef struct delayed_method_info delayed_method_info
;
331 DEF_VEC_O (delayed_method_info
);
333 /* Internal state when decoding a particular compilation unit. */
336 /* The objfile containing this compilation unit. */
337 struct objfile
*objfile
;
339 /* The header of the compilation unit. */
340 struct comp_unit_head header
;
342 /* Base address of this compilation unit. */
343 CORE_ADDR base_address
;
345 /* Non-zero if base_address has been set. */
348 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
350 /* The language we are debugging. */
351 enum language language
;
352 const struct language_defn
*language_defn
;
354 const char *producer
;
356 /* The generic symbol table building routines have separate lists for
357 file scope symbols and all all other scopes (local scopes). So
358 we need to select the right one to pass to add_symbol_to_list().
359 We do it by keeping a pointer to the correct list in list_in_scope.
361 FIXME: The original dwarf code just treated the file scope as the
362 first local scope, and all other local scopes as nested local
363 scopes, and worked fine. Check to see if we really need to
364 distinguish these in buildsym.c. */
365 struct pending
**list_in_scope
;
367 /* DWARF abbreviation table associated with this compilation unit. */
368 struct abbrev_info
**dwarf2_abbrevs
;
370 /* Storage for the abbrev table. */
371 struct obstack abbrev_obstack
;
373 /* Hash table holding all the loaded partial DIEs. */
376 /* Storage for things with the same lifetime as this read-in compilation
377 unit, including partial DIEs. */
378 struct obstack comp_unit_obstack
;
380 /* When multiple dwarf2_cu structures are living in memory, this field
381 chains them all together, so that they can be released efficiently.
382 We will probably also want a generation counter so that most-recently-used
383 compilation units are cached... */
384 struct dwarf2_per_cu_data
*read_in_chain
;
386 /* Backchain to our per_cu entry if the tree has been built. */
387 struct dwarf2_per_cu_data
*per_cu
;
389 /* How many compilation units ago was this CU last referenced? */
392 /* A hash table of die offsets for following references. */
395 /* Full DIEs if read in. */
396 struct die_info
*dies
;
398 /* A set of pointers to dwarf2_per_cu_data objects for compilation
399 units referenced by this one. Only set during full symbol processing;
400 partial symbol tables do not have dependencies. */
403 /* Header data from the line table, during full symbol processing. */
404 struct line_header
*line_header
;
406 /* A list of methods which need to have physnames computed
407 after all type information has been read. */
408 VEC (delayed_method_info
) *method_list
;
410 /* To be copied to symtab->call_site_htab. */
411 htab_t call_site_htab
;
413 /* Mark used when releasing cached dies. */
414 unsigned int mark
: 1;
416 /* This flag will be set if this compilation unit might include
417 inter-compilation-unit references. */
418 unsigned int has_form_ref_addr
: 1;
420 /* This flag will be set if this compilation unit includes any
421 DW_TAG_namespace DIEs. If we know that there are explicit
422 DIEs for namespaces, we don't need to try to infer them
423 from mangled names. */
424 unsigned int has_namespace_info
: 1;
426 /* This CU references .debug_loc. See the symtab->locations_valid field.
427 This test is imperfect as there may exist optimized debug code not using
428 any location list and still facing inlining issues if handled as
429 unoptimized code. For a future better test see GCC PR other/32998. */
431 unsigned int has_loclist
: 1;
434 /* Persistent data held for a compilation unit, even when not
435 processing it. We put a pointer to this structure in the
436 read_symtab_private field of the psymtab. If we encounter
437 inter-compilation-unit references, we also maintain a sorted
438 list of all compilation units. */
440 struct dwarf2_per_cu_data
442 /* The start offset and length of this compilation unit. 2**29-1
443 bytes should suffice to store the length of any compilation unit
444 - if it doesn't, GDB will fall over anyway.
445 NOTE: Unlike comp_unit_head.length, this length includes
446 initial_length_size. */
448 unsigned int length
: 29;
450 /* Flag indicating this compilation unit will be read in before
451 any of the current compilation units are processed. */
452 unsigned int queued
: 1;
454 /* This flag will be set if we need to load absolutely all DIEs
455 for this compilation unit, instead of just the ones we think
456 are interesting. It gets set if we look for a DIE in the
457 hash table and don't find it. */
458 unsigned int load_all_dies
: 1;
460 /* Non-null if this CU is from .debug_types; in which case it points
461 to the section. Otherwise it's from .debug_info. */
462 struct dwarf2_section_info
*debug_type_section
;
464 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
465 of the CU cache it gets reset to NULL again. */
466 struct dwarf2_cu
*cu
;
468 /* The corresponding objfile. */
469 struct objfile
*objfile
;
471 /* When using partial symbol tables, the 'psymtab' field is active.
472 Otherwise the 'quick' field is active. */
475 /* The partial symbol table associated with this compilation unit,
476 or NULL for partial units (which do not have an associated
478 struct partial_symtab
*psymtab
;
480 /* Data needed by the "quick" functions. */
481 struct dwarf2_per_cu_quick_data
*quick
;
485 /* Entry in the signatured_types hash table. */
487 struct signatured_type
491 /* Offset in .debug_types of the type defined by this TU. */
492 unsigned int type_offset
;
494 /* The CU(/TU) of this type. */
495 struct dwarf2_per_cu_data per_cu
;
498 /* Struct used to pass misc. parameters to read_die_and_children, et
499 al. which are used for both .debug_info and .debug_types dies.
500 All parameters here are unchanging for the life of the call. This
501 struct exists to abstract away the constant parameters of die
504 struct die_reader_specs
506 /* The bfd of this objfile. */
509 /* The CU of the DIE we are parsing. */
510 struct dwarf2_cu
*cu
;
512 /* Pointer to start of section buffer.
513 This is either the start of .debug_info or .debug_types. */
514 const gdb_byte
*buffer
;
517 /* The line number information for a compilation unit (found in the
518 .debug_line section) begins with a "statement program header",
519 which contains the following information. */
522 unsigned int total_length
;
523 unsigned short version
;
524 unsigned int header_length
;
525 unsigned char minimum_instruction_length
;
526 unsigned char maximum_ops_per_instruction
;
527 unsigned char default_is_stmt
;
529 unsigned char line_range
;
530 unsigned char opcode_base
;
532 /* standard_opcode_lengths[i] is the number of operands for the
533 standard opcode whose value is i. This means that
534 standard_opcode_lengths[0] is unused, and the last meaningful
535 element is standard_opcode_lengths[opcode_base - 1]. */
536 unsigned char *standard_opcode_lengths
;
538 /* The include_directories table. NOTE! These strings are not
539 allocated with xmalloc; instead, they are pointers into
540 debug_line_buffer. If you try to free them, `free' will get
542 unsigned int num_include_dirs
, include_dirs_size
;
545 /* The file_names table. NOTE! These strings are not allocated
546 with xmalloc; instead, they are pointers into debug_line_buffer.
547 Don't try to free them directly. */
548 unsigned int num_file_names
, file_names_size
;
552 unsigned int dir_index
;
553 unsigned int mod_time
;
555 int included_p
; /* Non-zero if referenced by the Line Number Program. */
556 struct symtab
*symtab
; /* The associated symbol table, if any. */
559 /* The start and end of the statement program following this
560 header. These point into dwarf2_per_objfile->line_buffer. */
561 gdb_byte
*statement_program_start
, *statement_program_end
;
564 /* When we construct a partial symbol table entry we only
565 need this much information. */
566 struct partial_die_info
568 /* Offset of this DIE. */
571 /* DWARF-2 tag for this DIE. */
572 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
574 /* Assorted flags describing the data found in this DIE. */
575 unsigned int has_children
: 1;
576 unsigned int is_external
: 1;
577 unsigned int is_declaration
: 1;
578 unsigned int has_type
: 1;
579 unsigned int has_specification
: 1;
580 unsigned int has_pc_info
: 1;
582 /* Flag set if the SCOPE field of this structure has been
584 unsigned int scope_set
: 1;
586 /* Flag set if the DIE has a byte_size attribute. */
587 unsigned int has_byte_size
: 1;
589 /* Flag set if any of the DIE's children are template arguments. */
590 unsigned int has_template_arguments
: 1;
592 /* Flag set if fixup_partial_die has been called on this die. */
593 unsigned int fixup_called
: 1;
595 /* The name of this DIE. Normally the value of DW_AT_name, but
596 sometimes a default name for unnamed DIEs. */
599 /* The linkage name, if present. */
600 const char *linkage_name
;
602 /* The scope to prepend to our children. This is generally
603 allocated on the comp_unit_obstack, so will disappear
604 when this compilation unit leaves the cache. */
607 /* The location description associated with this DIE, if any. */
608 struct dwarf_block
*locdesc
;
610 /* If HAS_PC_INFO, the PC range associated with this DIE. */
614 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
615 DW_AT_sibling, if any. */
616 /* NOTE: This member isn't strictly necessary, read_partial_die could
617 return DW_AT_sibling values to its caller load_partial_dies. */
620 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
621 DW_AT_specification (or DW_AT_abstract_origin or
623 unsigned int spec_offset
;
625 /* Pointers to this DIE's parent, first child, and next sibling,
627 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
630 /* This data structure holds the information of an abbrev. */
633 unsigned int number
; /* number identifying abbrev */
634 enum dwarf_tag tag
; /* dwarf tag */
635 unsigned short has_children
; /* boolean */
636 unsigned short num_attrs
; /* number of attributes */
637 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
638 struct abbrev_info
*next
; /* next in chain */
643 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
644 ENUM_BITFIELD(dwarf_form
) form
: 16;
647 /* Attributes have a name and a value. */
650 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
651 ENUM_BITFIELD(dwarf_form
) form
: 15;
653 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
654 field should be in u.str (existing only for DW_STRING) but it is kept
655 here for better struct attribute alignment. */
656 unsigned int string_is_canonical
: 1;
661 struct dwarf_block
*blk
;
665 struct signatured_type
*signatured_type
;
670 /* This data structure holds a complete die structure. */
673 /* DWARF-2 tag for this DIE. */
674 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
676 /* Number of attributes */
677 unsigned char num_attrs
;
679 /* True if we're presently building the full type name for the
680 type derived from this DIE. */
681 unsigned char building_fullname
: 1;
686 /* Offset in .debug_info or .debug_types section. */
689 /* The dies in a compilation unit form an n-ary tree. PARENT
690 points to this die's parent; CHILD points to the first child of
691 this node; and all the children of a given node are chained
692 together via their SIBLING fields. */
693 struct die_info
*child
; /* Its first child, if any. */
694 struct die_info
*sibling
; /* Its next sibling, if any. */
695 struct die_info
*parent
; /* Its parent, if any. */
697 /* An array of attributes, with NUM_ATTRS elements. There may be
698 zero, but it's not common and zero-sized arrays are not
699 sufficiently portable C. */
700 struct attribute attrs
[1];
703 struct function_range
706 CORE_ADDR lowpc
, highpc
;
708 struct function_range
*next
;
711 /* Get at parts of an attribute structure. */
713 #define DW_STRING(attr) ((attr)->u.str)
714 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
715 #define DW_UNSND(attr) ((attr)->u.unsnd)
716 #define DW_BLOCK(attr) ((attr)->u.blk)
717 #define DW_SND(attr) ((attr)->u.snd)
718 #define DW_ADDR(attr) ((attr)->u.addr)
719 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
721 /* Blocks are a bunch of untyped bytes. */
726 /* Valid only if SIZE is not zero. */
730 #ifndef ATTR_ALLOC_CHUNK
731 #define ATTR_ALLOC_CHUNK 4
734 /* Allocate fields for structs, unions and enums in this size. */
735 #ifndef DW_FIELD_ALLOC_CHUNK
736 #define DW_FIELD_ALLOC_CHUNK 4
739 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
740 but this would require a corresponding change in unpack_field_as_long
742 static int bits_per_byte
= 8;
744 /* The routines that read and process dies for a C struct or C++ class
745 pass lists of data member fields and lists of member function fields
746 in an instance of a field_info structure, as defined below. */
749 /* List of data member and baseclasses fields. */
752 struct nextfield
*next
;
757 *fields
, *baseclasses
;
759 /* Number of fields (including baseclasses). */
762 /* Number of baseclasses. */
765 /* Set if the accesibility of one of the fields is not public. */
766 int non_public_fields
;
768 /* Member function fields array, entries are allocated in the order they
769 are encountered in the object file. */
772 struct nextfnfield
*next
;
773 struct fn_field fnfield
;
777 /* Member function fieldlist array, contains name of possibly overloaded
778 member function, number of overloaded member functions and a pointer
779 to the head of the member function field chain. */
784 struct nextfnfield
*head
;
788 /* Number of entries in the fnfieldlists array. */
791 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
792 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
793 struct typedef_field_list
795 struct typedef_field field
;
796 struct typedef_field_list
*next
;
799 unsigned typedef_field_list_count
;
802 /* One item on the queue of compilation units to read in full symbols
804 struct dwarf2_queue_item
806 struct dwarf2_per_cu_data
*per_cu
;
807 struct dwarf2_queue_item
*next
;
810 /* The current queue. */
811 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
813 /* Loaded secondary compilation units are kept in memory until they
814 have not been referenced for the processing of this many
815 compilation units. Set this to zero to disable caching. Cache
816 sizes of up to at least twenty will improve startup time for
817 typical inter-CU-reference binaries, at an obvious memory cost. */
818 static int dwarf2_max_cache_age
= 5;
820 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
821 struct cmd_list_element
*c
, const char *value
)
823 fprintf_filtered (file
, _("The upper bound on the age of cached "
824 "dwarf2 compilation units is %s.\n"),
829 /* Various complaints about symbol reading that don't abort the process. */
832 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
834 complaint (&symfile_complaints
,
835 _("statement list doesn't fit in .debug_line section"));
839 dwarf2_debug_line_missing_file_complaint (void)
841 complaint (&symfile_complaints
,
842 _(".debug_line section has line data without a file"));
846 dwarf2_debug_line_missing_end_sequence_complaint (void)
848 complaint (&symfile_complaints
,
849 _(".debug_line section has line "
850 "program sequence without an end"));
854 dwarf2_complex_location_expr_complaint (void)
856 complaint (&symfile_complaints
, _("location expression too complex"));
860 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
863 complaint (&symfile_complaints
,
864 _("const value length mismatch for '%s', got %d, expected %d"),
869 dwarf2_macros_too_long_complaint (struct dwarf2_section_info
*section
)
871 complaint (&symfile_complaints
,
872 _("macro info runs off end of `%s' section"),
873 section
->asection
->name
);
877 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
879 complaint (&symfile_complaints
,
880 _("macro debug info contains a "
881 "malformed macro definition:\n`%s'"),
886 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
888 complaint (&symfile_complaints
,
889 _("invalid attribute class or form for '%s' in '%s'"),
893 /* local function prototypes */
895 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
897 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
900 static void dwarf2_find_base_address (struct die_info
*die
,
901 struct dwarf2_cu
*cu
);
903 static void dwarf2_build_psymtabs_hard (struct objfile
*);
905 static void scan_partial_symbols (struct partial_die_info
*,
906 CORE_ADDR
*, CORE_ADDR
*,
907 int, struct dwarf2_cu
*);
909 static void add_partial_symbol (struct partial_die_info
*,
912 static void add_partial_namespace (struct partial_die_info
*pdi
,
913 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
914 int need_pc
, struct dwarf2_cu
*cu
);
916 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
917 CORE_ADDR
*highpc
, int need_pc
,
918 struct dwarf2_cu
*cu
);
920 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
921 struct dwarf2_cu
*cu
);
923 static void add_partial_subprogram (struct partial_die_info
*pdi
,
924 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
925 int need_pc
, struct dwarf2_cu
*cu
);
927 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
928 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
929 bfd
*abfd
, struct dwarf2_cu
*cu
);
931 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
933 static void psymtab_to_symtab_1 (struct partial_symtab
*);
935 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
937 static void dwarf2_free_abbrev_table (void *);
939 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
942 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
945 static struct partial_die_info
*load_partial_dies (bfd
*,
946 gdb_byte
*, gdb_byte
*,
947 int, struct dwarf2_cu
*);
949 static gdb_byte
*read_partial_die (struct partial_die_info
*,
950 struct abbrev_info
*abbrev
,
952 gdb_byte
*, gdb_byte
*,
955 static struct partial_die_info
*find_partial_die (unsigned int,
958 static void fixup_partial_die (struct partial_die_info
*,
961 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
962 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
964 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
965 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
967 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
969 static int read_1_signed_byte (bfd
*, gdb_byte
*);
971 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
973 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
975 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
977 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
980 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
982 static LONGEST read_checked_initial_length_and_offset
983 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
984 unsigned int *, unsigned int *);
986 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
989 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
991 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
993 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
995 static char *read_indirect_string (bfd
*, gdb_byte
*,
996 const struct comp_unit_head
*,
999 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1001 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1003 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
1005 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1007 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1008 struct dwarf2_cu
*);
1010 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1012 struct dwarf2_cu
*);
1014 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1015 struct dwarf2_cu
*cu
);
1017 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1019 static struct die_info
*die_specification (struct die_info
*die
,
1020 struct dwarf2_cu
**);
1022 static void free_line_header (struct line_header
*lh
);
1024 static void add_file_name (struct line_header
*, char *, unsigned int,
1025 unsigned int, unsigned int);
1027 static struct line_header
*(dwarf_decode_line_header
1028 (unsigned int offset
,
1029 bfd
*abfd
, struct dwarf2_cu
*cu
));
1031 static void dwarf_decode_lines (struct line_header
*, const char *, bfd
*,
1032 struct dwarf2_cu
*, struct partial_symtab
*);
1034 static void dwarf2_start_subfile (char *, const char *, const char *);
1036 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1037 struct dwarf2_cu
*);
1039 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1040 struct dwarf2_cu
*, struct symbol
*);
1042 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1043 struct dwarf2_cu
*);
1045 static void dwarf2_const_value_attr (struct attribute
*attr
,
1048 struct obstack
*obstack
,
1049 struct dwarf2_cu
*cu
, long *value
,
1051 struct dwarf2_locexpr_baton
**baton
);
1053 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1055 static int need_gnat_info (struct dwarf2_cu
*);
1057 static struct type
*die_descriptive_type (struct die_info
*,
1058 struct dwarf2_cu
*);
1060 static void set_descriptive_type (struct type
*, struct die_info
*,
1061 struct dwarf2_cu
*);
1063 static struct type
*die_containing_type (struct die_info
*,
1064 struct dwarf2_cu
*);
1066 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1067 struct dwarf2_cu
*);
1069 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1071 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1073 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1075 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1076 const char *suffix
, int physname
,
1077 struct dwarf2_cu
*cu
);
1079 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1081 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1083 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1085 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1087 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1089 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1090 struct dwarf2_cu
*, struct partial_symtab
*);
1092 static int dwarf2_get_pc_bounds (struct die_info
*,
1093 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1094 struct partial_symtab
*);
1096 static void get_scope_pc_bounds (struct die_info
*,
1097 CORE_ADDR
*, CORE_ADDR
*,
1098 struct dwarf2_cu
*);
1100 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1101 CORE_ADDR
, struct dwarf2_cu
*);
1103 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1104 struct dwarf2_cu
*);
1106 static void dwarf2_attach_fields_to_type (struct field_info
*,
1107 struct type
*, struct dwarf2_cu
*);
1109 static void dwarf2_add_member_fn (struct field_info
*,
1110 struct die_info
*, struct type
*,
1111 struct dwarf2_cu
*);
1113 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1115 struct dwarf2_cu
*);
1117 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1119 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1121 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1123 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1125 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1127 static struct type
*read_module_type (struct die_info
*die
,
1128 struct dwarf2_cu
*cu
);
1130 static const char *namespace_name (struct die_info
*die
,
1131 int *is_anonymous
, struct dwarf2_cu
*);
1133 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1135 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1137 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1138 struct dwarf2_cu
*);
1140 static struct die_info
*read_comp_unit (gdb_byte
*, struct dwarf2_cu
*);
1142 static struct die_info
*read_die_and_children_1 (const struct die_reader_specs
*reader
,
1144 gdb_byte
**new_info_ptr
,
1145 struct die_info
*parent
);
1147 static struct die_info
*read_die_and_children (const struct die_reader_specs
*reader
,
1149 gdb_byte
**new_info_ptr
,
1150 struct die_info
*parent
);
1152 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*reader
,
1154 gdb_byte
**new_info_ptr
,
1155 struct die_info
*parent
);
1157 static gdb_byte
*read_full_die (const struct die_reader_specs
*reader
,
1158 struct die_info
**, gdb_byte
*,
1161 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1163 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1166 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1168 static const char *dwarf2_full_name (char *name
,
1169 struct die_info
*die
,
1170 struct dwarf2_cu
*cu
);
1172 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1173 struct dwarf2_cu
**);
1175 static char *dwarf_tag_name (unsigned int);
1177 static char *dwarf_attr_name (unsigned int);
1179 static char *dwarf_form_name (unsigned int);
1181 static char *dwarf_bool_name (unsigned int);
1183 static char *dwarf_type_encoding_name (unsigned int);
1186 static char *dwarf_cfi_name (unsigned int);
1189 static struct die_info
*sibling_die (struct die_info
*);
1191 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1193 static void dump_die_for_error (struct die_info
*);
1195 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1198 /*static*/ void dump_die (struct die_info
*, int max_level
);
1200 static void store_in_ref_table (struct die_info
*,
1201 struct dwarf2_cu
*);
1203 static int is_ref_attr (struct attribute
*);
1205 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1207 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1209 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1211 struct dwarf2_cu
**);
1213 static struct die_info
*follow_die_ref (struct die_info
*,
1215 struct dwarf2_cu
**);
1217 static struct die_info
*follow_die_sig (struct die_info
*,
1219 struct dwarf2_cu
**);
1221 static struct signatured_type
*lookup_signatured_type_at_offset
1222 (struct objfile
*objfile
,
1223 struct dwarf2_section_info
*section
,
1224 unsigned int offset
);
1226 static void read_signatured_type_at_offset (struct objfile
*objfile
,
1227 struct dwarf2_section_info
*sect
,
1228 unsigned int offset
);
1230 static void read_signatured_type (struct objfile
*,
1231 struct signatured_type
*type_sig
);
1233 /* memory allocation interface */
1235 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1237 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1239 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1241 static void initialize_cu_func_list (struct dwarf2_cu
*);
1243 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1244 struct dwarf2_cu
*);
1246 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1247 char *, bfd
*, struct dwarf2_cu
*,
1248 struct dwarf2_section_info
*,
1251 static int attr_form_is_block (struct attribute
*);
1253 static int attr_form_is_section_offset (struct attribute
*);
1255 static int attr_form_is_constant (struct attribute
*);
1257 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1258 struct dwarf2_loclist_baton
*baton
,
1259 struct attribute
*attr
);
1261 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1263 struct dwarf2_cu
*cu
);
1265 static gdb_byte
*skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1266 struct abbrev_info
*abbrev
,
1267 struct dwarf2_cu
*cu
);
1269 static void free_stack_comp_unit (void *);
1271 static hashval_t
partial_die_hash (const void *item
);
1273 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1275 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1276 (unsigned int offset
, struct objfile
*objfile
);
1278 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1279 (unsigned int offset
, struct objfile
*objfile
);
1281 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1282 struct objfile
*objfile
);
1284 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1285 struct die_info
*comp_unit_die
);
1287 static void free_one_comp_unit (void *);
1289 static void free_cached_comp_units (void *);
1291 static void age_cached_comp_units (void);
1293 static void free_one_cached_comp_unit (void *);
1295 static struct type
*set_die_type (struct die_info
*, struct type
*,
1296 struct dwarf2_cu
*);
1298 static void create_all_comp_units (struct objfile
*);
1300 static int create_debug_types_hash_table (struct objfile
*objfile
);
1302 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1305 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1307 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1308 struct dwarf2_per_cu_data
*);
1310 static void dwarf2_mark (struct dwarf2_cu
*);
1312 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1314 static struct type
*get_die_type_at_offset (unsigned int,
1315 struct dwarf2_per_cu_data
*per_cu
);
1317 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1319 static void dwarf2_release_queue (void *dummy
);
1321 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1322 struct objfile
*objfile
);
1324 static void process_queue (struct objfile
*objfile
);
1326 static void find_file_and_directory (struct die_info
*die
,
1327 struct dwarf2_cu
*cu
,
1328 char **name
, char **comp_dir
);
1330 static char *file_full_name (int file
, struct line_header
*lh
,
1331 const char *comp_dir
);
1333 static gdb_byte
*partial_read_comp_unit_head (struct comp_unit_head
*header
,
1336 unsigned int buffer_size
,
1339 static void init_cu_die_reader (struct die_reader_specs
*reader
,
1340 struct dwarf2_cu
*cu
);
1342 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1346 /* Convert VALUE between big- and little-endian. */
1348 byte_swap (offset_type value
)
1352 result
= (value
& 0xff) << 24;
1353 result
|= (value
& 0xff00) << 8;
1354 result
|= (value
& 0xff0000) >> 8;
1355 result
|= (value
& 0xff000000) >> 24;
1359 #define MAYBE_SWAP(V) byte_swap (V)
1362 #define MAYBE_SWAP(V) (V)
1363 #endif /* WORDS_BIGENDIAN */
1365 /* The suffix for an index file. */
1366 #define INDEX_SUFFIX ".gdb-index"
1368 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1369 struct dwarf2_cu
*cu
);
1371 /* Try to locate the sections we need for DWARF 2 debugging
1372 information and return true if we have enough to do something.
1373 NAMES points to the dwarf2 section names, or is NULL if the standard
1374 ELF names are used. */
1377 dwarf2_has_info (struct objfile
*objfile
,
1378 const struct dwarf2_debug_sections
*names
)
1380 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1381 if (!dwarf2_per_objfile
)
1383 /* Initialize per-objfile state. */
1384 struct dwarf2_per_objfile
*data
1385 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1387 memset (data
, 0, sizeof (*data
));
1388 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1389 dwarf2_per_objfile
= data
;
1391 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1393 dwarf2_per_objfile
->objfile
= objfile
;
1395 return (dwarf2_per_objfile
->info
.asection
!= NULL
1396 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1399 /* When loading sections, we look either for uncompressed section or for
1400 compressed section names. */
1403 section_is_p (const char *section_name
,
1404 const struct dwarf2_section_names
*names
)
1406 if (names
->normal
!= NULL
1407 && strcmp (section_name
, names
->normal
) == 0)
1409 if (names
->compressed
!= NULL
1410 && strcmp (section_name
, names
->compressed
) == 0)
1415 /* This function is mapped across the sections and remembers the
1416 offset and size of each of the debugging sections we are interested
1420 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1422 const struct dwarf2_debug_sections
*names
;
1425 names
= &dwarf2_elf_names
;
1427 names
= (const struct dwarf2_debug_sections
*) vnames
;
1429 if (section_is_p (sectp
->name
, &names
->info
))
1431 dwarf2_per_objfile
->info
.asection
= sectp
;
1432 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1434 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1436 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1437 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1439 else if (section_is_p (sectp
->name
, &names
->line
))
1441 dwarf2_per_objfile
->line
.asection
= sectp
;
1442 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1444 else if (section_is_p (sectp
->name
, &names
->loc
))
1446 dwarf2_per_objfile
->loc
.asection
= sectp
;
1447 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1449 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1451 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1452 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1454 else if (section_is_p (sectp
->name
, &names
->macro
))
1456 dwarf2_per_objfile
->macro
.asection
= sectp
;
1457 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
1459 else if (section_is_p (sectp
->name
, &names
->str
))
1461 dwarf2_per_objfile
->str
.asection
= sectp
;
1462 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1464 else if (section_is_p (sectp
->name
, &names
->frame
))
1466 dwarf2_per_objfile
->frame
.asection
= sectp
;
1467 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1469 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1471 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1473 if (aflag
& SEC_HAS_CONTENTS
)
1475 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1476 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1479 else if (section_is_p (sectp
->name
, &names
->ranges
))
1481 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1482 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1484 else if (section_is_p (sectp
->name
, &names
->types
))
1486 struct dwarf2_section_info type_section
;
1488 memset (&type_section
, 0, sizeof (type_section
));
1489 type_section
.asection
= sectp
;
1490 type_section
.size
= bfd_get_section_size (sectp
);
1492 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
1495 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1497 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1498 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1501 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1502 && bfd_section_vma (abfd
, sectp
) == 0)
1503 dwarf2_per_objfile
->has_section_at_zero
= 1;
1506 /* Decompress a section that was compressed using zlib. Store the
1507 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1510 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1511 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1513 bfd
*abfd
= objfile
->obfd
;
1515 error (_("Support for zlib-compressed DWARF data (from '%s') "
1516 "is disabled in this copy of GDB"),
1517 bfd_get_filename (abfd
));
1519 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1520 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1521 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1522 bfd_size_type uncompressed_size
;
1523 gdb_byte
*uncompressed_buffer
;
1526 int header_size
= 12;
1528 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1529 || bfd_bread (compressed_buffer
,
1530 compressed_size
, abfd
) != compressed_size
)
1531 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1532 bfd_get_filename (abfd
));
1534 /* Read the zlib header. In this case, it should be "ZLIB" followed
1535 by the uncompressed section size, 8 bytes in big-endian order. */
1536 if (compressed_size
< header_size
1537 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1538 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1539 bfd_get_filename (abfd
));
1540 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1541 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1542 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1543 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1544 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1545 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1546 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1547 uncompressed_size
+= compressed_buffer
[11];
1549 /* It is possible the section consists of several compressed
1550 buffers concatenated together, so we uncompress in a loop. */
1554 strm
.avail_in
= compressed_size
- header_size
;
1555 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1556 strm
.avail_out
= uncompressed_size
;
1557 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1559 rc
= inflateInit (&strm
);
1560 while (strm
.avail_in
> 0)
1563 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1564 bfd_get_filename (abfd
), rc
);
1565 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1566 + (uncompressed_size
- strm
.avail_out
));
1567 rc
= inflate (&strm
, Z_FINISH
);
1568 if (rc
!= Z_STREAM_END
)
1569 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1570 bfd_get_filename (abfd
), rc
);
1571 rc
= inflateReset (&strm
);
1573 rc
= inflateEnd (&strm
);
1575 || strm
.avail_out
!= 0)
1576 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1577 bfd_get_filename (abfd
), rc
);
1579 do_cleanups (cleanup
);
1580 *outbuf
= uncompressed_buffer
;
1581 *outsize
= uncompressed_size
;
1585 /* A helper function that decides whether a section is empty. */
1588 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1590 return info
->asection
== NULL
|| info
->size
== 0;
1593 /* Read the contents of the section SECTP from object file specified by
1594 OBJFILE, store info about the section into INFO.
1595 If the section is compressed, uncompress it before returning. */
1598 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1600 bfd
*abfd
= objfile
->obfd
;
1601 asection
*sectp
= info
->asection
;
1602 gdb_byte
*buf
, *retbuf
;
1603 unsigned char header
[4];
1607 info
->buffer
= NULL
;
1608 info
->map_addr
= NULL
;
1611 if (dwarf2_section_empty_p (info
))
1614 /* Check if the file has a 4-byte header indicating compression. */
1615 if (info
->size
> sizeof (header
)
1616 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1617 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1619 /* Upon decompression, update the buffer and its size. */
1620 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1622 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1630 pagesize
= getpagesize ();
1632 /* Only try to mmap sections which are large enough: we don't want to
1633 waste space due to fragmentation. Also, only try mmap for sections
1634 without relocations. */
1636 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1638 info
->buffer
= bfd_mmap (abfd
, 0, info
->size
, PROT_READ
,
1639 MAP_PRIVATE
, sectp
->filepos
,
1640 &info
->map_addr
, &info
->map_len
);
1642 if ((caddr_t
)info
->buffer
!= MAP_FAILED
)
1644 #if HAVE_POSIX_MADVISE
1645 posix_madvise (info
->map_addr
, info
->map_len
, POSIX_MADV_WILLNEED
);
1652 /* If we get here, we are a normal, not-compressed section. */
1654 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1656 /* When debugging .o files, we may need to apply relocations; see
1657 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1658 We never compress sections in .o files, so we only need to
1659 try this when the section is not compressed. */
1660 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1663 info
->buffer
= retbuf
;
1667 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1668 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1669 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1670 bfd_get_filename (abfd
));
1673 /* A helper function that returns the size of a section in a safe way.
1674 If you are positive that the section has been read before using the
1675 size, then it is safe to refer to the dwarf2_section_info object's
1676 "size" field directly. In other cases, you must call this
1677 function, because for compressed sections the size field is not set
1678 correctly until the section has been read. */
1680 static bfd_size_type
1681 dwarf2_section_size (struct objfile
*objfile
,
1682 struct dwarf2_section_info
*info
)
1685 dwarf2_read_section (objfile
, info
);
1689 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1693 dwarf2_get_section_info (struct objfile
*objfile
,
1694 enum dwarf2_section_enum sect
,
1695 asection
**sectp
, gdb_byte
**bufp
,
1696 bfd_size_type
*sizep
)
1698 struct dwarf2_per_objfile
*data
1699 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1700 struct dwarf2_section_info
*info
;
1702 /* We may see an objfile without any DWARF, in which case we just
1713 case DWARF2_DEBUG_FRAME
:
1714 info
= &data
->frame
;
1716 case DWARF2_EH_FRAME
:
1717 info
= &data
->eh_frame
;
1720 gdb_assert_not_reached ("unexpected section");
1723 dwarf2_read_section (objfile
, info
);
1725 *sectp
= info
->asection
;
1726 *bufp
= info
->buffer
;
1727 *sizep
= info
->size
;
1731 /* DWARF quick_symbols_functions support. */
1733 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1734 unique line tables, so we maintain a separate table of all .debug_line
1735 derived entries to support the sharing.
1736 All the quick functions need is the list of file names. We discard the
1737 line_header when we're done and don't need to record it here. */
1738 struct quick_file_names
1740 /* The offset in .debug_line of the line table. We hash on this. */
1741 unsigned int offset
;
1743 /* The number of entries in file_names, real_names. */
1744 unsigned int num_file_names
;
1746 /* The file names from the line table, after being run through
1748 const char **file_names
;
1750 /* The file names from the line table after being run through
1751 gdb_realpath. These are computed lazily. */
1752 const char **real_names
;
1755 /* When using the index (and thus not using psymtabs), each CU has an
1756 object of this type. This is used to hold information needed by
1757 the various "quick" methods. */
1758 struct dwarf2_per_cu_quick_data
1760 /* The file table. This can be NULL if there was no file table
1761 or it's currently not read in.
1762 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1763 struct quick_file_names
*file_names
;
1765 /* The corresponding symbol table. This is NULL if symbols for this
1766 CU have not yet been read. */
1767 struct symtab
*symtab
;
1769 /* A temporary mark bit used when iterating over all CUs in
1770 expand_symtabs_matching. */
1771 unsigned int mark
: 1;
1773 /* True if we've tried to read the file table and found there isn't one.
1774 There will be no point in trying to read it again next time. */
1775 unsigned int no_file_data
: 1;
1778 /* Hash function for a quick_file_names. */
1781 hash_file_name_entry (const void *e
)
1783 const struct quick_file_names
*file_data
= e
;
1785 return file_data
->offset
;
1788 /* Equality function for a quick_file_names. */
1791 eq_file_name_entry (const void *a
, const void *b
)
1793 const struct quick_file_names
*ea
= a
;
1794 const struct quick_file_names
*eb
= b
;
1796 return ea
->offset
== eb
->offset
;
1799 /* Delete function for a quick_file_names. */
1802 delete_file_name_entry (void *e
)
1804 struct quick_file_names
*file_data
= e
;
1807 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
1809 xfree ((void*) file_data
->file_names
[i
]);
1810 if (file_data
->real_names
)
1811 xfree ((void*) file_data
->real_names
[i
]);
1814 /* The space for the struct itself lives on objfile_obstack,
1815 so we don't free it here. */
1818 /* Create a quick_file_names hash table. */
1821 create_quick_file_names_table (unsigned int nr_initial_entries
)
1823 return htab_create_alloc (nr_initial_entries
,
1824 hash_file_name_entry
, eq_file_name_entry
,
1825 delete_file_name_entry
, xcalloc
, xfree
);
1828 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
1829 have to be created afterwards. You should call age_cached_comp_units after
1830 processing PER_CU->CU. dw2_setup must have been already called. */
1833 load_cu (struct dwarf2_per_cu_data
*per_cu
)
1835 if (per_cu
->debug_type_section
)
1836 read_signatured_type_at_offset (per_cu
->objfile
,
1837 per_cu
->debug_type_section
,
1840 load_full_comp_unit (per_cu
, per_cu
->objfile
);
1842 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
1844 gdb_assert (per_cu
->cu
!= NULL
);
1847 /* Read in the symbols for PER_CU. OBJFILE is the objfile from which
1851 dw2_do_instantiate_symtab (struct objfile
*objfile
,
1852 struct dwarf2_per_cu_data
*per_cu
)
1854 struct cleanup
*back_to
;
1856 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
1858 queue_comp_unit (per_cu
, objfile
);
1862 process_queue (objfile
);
1864 /* Age the cache, releasing compilation units that have not
1865 been used recently. */
1866 age_cached_comp_units ();
1868 do_cleanups (back_to
);
1871 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1872 the objfile from which this CU came. Returns the resulting symbol
1875 static struct symtab
*
1876 dw2_instantiate_symtab (struct objfile
*objfile
,
1877 struct dwarf2_per_cu_data
*per_cu
)
1879 if (!per_cu
->v
.quick
->symtab
)
1881 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1882 increment_reading_symtab ();
1883 dw2_do_instantiate_symtab (objfile
, per_cu
);
1884 do_cleanups (back_to
);
1886 return per_cu
->v
.quick
->symtab
;
1889 /* Return the CU given its index. */
1891 static struct dwarf2_per_cu_data
*
1892 dw2_get_cu (int index
)
1894 if (index
>= dwarf2_per_objfile
->n_comp_units
)
1896 index
-= dwarf2_per_objfile
->n_comp_units
;
1897 return dwarf2_per_objfile
->type_comp_units
[index
];
1899 return dwarf2_per_objfile
->all_comp_units
[index
];
1902 /* A helper function that knows how to read a 64-bit value in a way
1903 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1907 extract_cu_value (const char *bytes
, ULONGEST
*result
)
1909 if (sizeof (ULONGEST
) < 8)
1913 /* Ignore the upper 4 bytes if they are all zero. */
1914 for (i
= 0; i
< 4; ++i
)
1915 if (bytes
[i
+ 4] != 0)
1918 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
1921 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
1925 /* Read the CU list from the mapped index, and use it to create all
1926 the CU objects for this objfile. Return 0 if something went wrong,
1927 1 if everything went ok. */
1930 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
1931 offset_type cu_list_elements
)
1935 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
1936 dwarf2_per_objfile
->all_comp_units
1937 = obstack_alloc (&objfile
->objfile_obstack
,
1938 dwarf2_per_objfile
->n_comp_units
1939 * sizeof (struct dwarf2_per_cu_data
*));
1941 for (i
= 0; i
< cu_list_elements
; i
+= 2)
1943 struct dwarf2_per_cu_data
*the_cu
;
1944 ULONGEST offset
, length
;
1946 if (!extract_cu_value (cu_list
, &offset
)
1947 || !extract_cu_value (cu_list
+ 8, &length
))
1951 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1952 struct dwarf2_per_cu_data
);
1953 the_cu
->offset
= offset
;
1954 the_cu
->length
= length
;
1955 the_cu
->objfile
= objfile
;
1956 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1957 struct dwarf2_per_cu_quick_data
);
1958 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
1964 /* Create the signatured type hash table from the index. */
1967 create_signatured_type_table_from_index (struct objfile
*objfile
,
1968 struct dwarf2_section_info
*section
,
1969 const gdb_byte
*bytes
,
1970 offset_type elements
)
1973 htab_t sig_types_hash
;
1975 dwarf2_per_objfile
->n_type_comp_units
= elements
/ 3;
1976 dwarf2_per_objfile
->type_comp_units
1977 = obstack_alloc (&objfile
->objfile_obstack
,
1978 dwarf2_per_objfile
->n_type_comp_units
1979 * sizeof (struct dwarf2_per_cu_data
*));
1981 sig_types_hash
= allocate_signatured_type_table (objfile
);
1983 for (i
= 0; i
< elements
; i
+= 3)
1985 struct signatured_type
*type_sig
;
1986 ULONGEST offset
, type_offset
, signature
;
1989 if (!extract_cu_value (bytes
, &offset
)
1990 || !extract_cu_value (bytes
+ 8, &type_offset
))
1992 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
1995 type_sig
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1996 struct signatured_type
);
1997 type_sig
->signature
= signature
;
1998 type_sig
->type_offset
= type_offset
;
1999 type_sig
->per_cu
.debug_type_section
= section
;
2000 type_sig
->per_cu
.offset
= offset
;
2001 type_sig
->per_cu
.objfile
= objfile
;
2002 type_sig
->per_cu
.v
.quick
2003 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2004 struct dwarf2_per_cu_quick_data
);
2006 slot
= htab_find_slot (sig_types_hash
, type_sig
, INSERT
);
2009 dwarf2_per_objfile
->type_comp_units
[i
/ 3] = &type_sig
->per_cu
;
2012 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2017 /* Read the address map data from the mapped index, and use it to
2018 populate the objfile's psymtabs_addrmap. */
2021 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
2023 const gdb_byte
*iter
, *end
;
2024 struct obstack temp_obstack
;
2025 struct addrmap
*mutable_map
;
2026 struct cleanup
*cleanup
;
2029 obstack_init (&temp_obstack
);
2030 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2031 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2033 iter
= index
->address_table
;
2034 end
= iter
+ index
->address_table_size
;
2036 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2040 ULONGEST hi
, lo
, cu_index
;
2041 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2043 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2045 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2048 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
2049 dw2_get_cu (cu_index
));
2052 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
2053 &objfile
->objfile_obstack
);
2054 do_cleanups (cleanup
);
2057 /* The hash function for strings in the mapped index. This is the same as
2058 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2059 implementation. This is necessary because the hash function is tied to the
2060 format of the mapped index file. The hash values do not have to match with
2063 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2066 mapped_index_string_hash (int index_version
, const void *p
)
2068 const unsigned char *str
= (const unsigned char *) p
;
2072 while ((c
= *str
++) != 0)
2074 if (index_version
>= 5)
2076 r
= r
* 67 + c
- 113;
2082 /* Find a slot in the mapped index INDEX for the object named NAME.
2083 If NAME is found, set *VEC_OUT to point to the CU vector in the
2084 constant pool and return 1. If NAME cannot be found, return 0. */
2087 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2088 offset_type
**vec_out
)
2090 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2092 offset_type slot
, step
;
2093 int (*cmp
) (const char *, const char *);
2095 if (current_language
->la_language
== language_cplus
2096 || current_language
->la_language
== language_java
2097 || current_language
->la_language
== language_fortran
)
2099 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2101 const char *paren
= strchr (name
, '(');
2107 dup
= xmalloc (paren
- name
+ 1);
2108 memcpy (dup
, name
, paren
- name
);
2109 dup
[paren
- name
] = 0;
2111 make_cleanup (xfree
, dup
);
2116 /* Index version 4 did not support case insensitive searches. But the
2117 indexes for case insensitive languages are built in lowercase, therefore
2118 simulate our NAME being searched is also lowercased. */
2119 hash
= mapped_index_string_hash ((index
->version
== 4
2120 && case_sensitivity
== case_sensitive_off
2121 ? 5 : index
->version
),
2124 slot
= hash
& (index
->symbol_table_slots
- 1);
2125 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2126 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2130 /* Convert a slot number to an offset into the table. */
2131 offset_type i
= 2 * slot
;
2133 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2135 do_cleanups (back_to
);
2139 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2140 if (!cmp (name
, str
))
2142 *vec_out
= (offset_type
*) (index
->constant_pool
2143 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2144 do_cleanups (back_to
);
2148 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2152 /* Read the index file. If everything went ok, initialize the "quick"
2153 elements of all the CUs and return 1. Otherwise, return 0. */
2156 dwarf2_read_index (struct objfile
*objfile
)
2159 struct mapped_index
*map
;
2160 offset_type
*metadata
;
2161 const gdb_byte
*cu_list
;
2162 const gdb_byte
*types_list
= NULL
;
2163 offset_type version
, cu_list_elements
;
2164 offset_type types_list_elements
= 0;
2167 if (dwarf2_section_empty_p (&dwarf2_per_objfile
->gdb_index
))
2170 /* Older elfutils strip versions could keep the section in the main
2171 executable while splitting it for the separate debug info file. */
2172 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
2173 & SEC_HAS_CONTENTS
) == 0)
2176 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
2178 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
2179 /* Version check. */
2180 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2181 /* Versions earlier than 3 emitted every copy of a psymbol. This
2182 causes the index to behave very poorly for certain requests. Version 3
2183 contained incomplete addrmap. So, it seems better to just ignore such
2184 indices. Index version 4 uses a different hash function than index
2185 version 5 and later. */
2188 /* Indexes with higher version than the one supported by GDB may be no
2189 longer backward compatible. */
2193 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
2194 map
->version
= version
;
2195 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
2197 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2200 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2201 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2205 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2206 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2207 - MAYBE_SWAP (metadata
[i
]))
2211 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2212 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2213 - MAYBE_SWAP (metadata
[i
]));
2216 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2217 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2218 - MAYBE_SWAP (metadata
[i
]))
2219 / (2 * sizeof (offset_type
)));
2222 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2224 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
2227 if (types_list_elements
)
2229 struct dwarf2_section_info
*section
;
2231 /* We can only handle a single .debug_types when we have an
2233 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2236 section
= VEC_index (dwarf2_section_info_def
,
2237 dwarf2_per_objfile
->types
, 0);
2239 if (!create_signatured_type_table_from_index (objfile
, section
,
2241 types_list_elements
))
2245 create_addrmap_from_index (objfile
, map
);
2247 dwarf2_per_objfile
->index_table
= map
;
2248 dwarf2_per_objfile
->using_index
= 1;
2249 dwarf2_per_objfile
->quick_file_names_table
=
2250 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2255 /* A helper for the "quick" functions which sets the global
2256 dwarf2_per_objfile according to OBJFILE. */
2259 dw2_setup (struct objfile
*objfile
)
2261 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2262 gdb_assert (dwarf2_per_objfile
);
2265 /* A helper for the "quick" functions which attempts to read the line
2266 table for THIS_CU. */
2268 static struct quick_file_names
*
2269 dw2_get_file_names (struct objfile
*objfile
,
2270 struct dwarf2_per_cu_data
*this_cu
)
2272 bfd
*abfd
= objfile
->obfd
;
2273 struct line_header
*lh
;
2274 struct attribute
*attr
;
2275 struct cleanup
*cleanups
;
2276 struct die_info
*comp_unit_die
;
2277 struct dwarf2_section_info
* sec
;
2278 gdb_byte
*info_ptr
, *buffer
;
2279 int has_children
, i
;
2280 struct dwarf2_cu cu
;
2281 unsigned int bytes_read
, buffer_size
;
2282 struct die_reader_specs reader_specs
;
2283 char *name
, *comp_dir
;
2285 struct quick_file_names
*qfn
;
2286 unsigned int line_offset
;
2288 if (this_cu
->v
.quick
->file_names
!= NULL
)
2289 return this_cu
->v
.quick
->file_names
;
2290 /* If we know there is no line data, no point in looking again. */
2291 if (this_cu
->v
.quick
->no_file_data
)
2294 init_one_comp_unit (&cu
, objfile
);
2295 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
2297 if (this_cu
->debug_type_section
)
2298 sec
= this_cu
->debug_type_section
;
2300 sec
= &dwarf2_per_objfile
->info
;
2301 dwarf2_read_section (objfile
, sec
);
2302 buffer_size
= sec
->size
;
2303 buffer
= sec
->buffer
;
2304 info_ptr
= buffer
+ this_cu
->offset
;
2306 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
2307 buffer
, buffer_size
,
2311 cu
.per_cu
= this_cu
;
2313 dwarf2_read_abbrevs (abfd
, &cu
);
2314 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2316 if (this_cu
->debug_type_section
)
2317 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
2318 init_cu_die_reader (&reader_specs
, &cu
);
2319 read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2325 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, &cu
);
2328 struct quick_file_names find_entry
;
2330 line_offset
= DW_UNSND (attr
);
2332 /* We may have already read in this line header (TU line header sharing).
2333 If we have we're done. */
2334 find_entry
.offset
= line_offset
;
2335 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2336 &find_entry
, INSERT
);
2339 do_cleanups (cleanups
);
2340 this_cu
->v
.quick
->file_names
= *slot
;
2344 lh
= dwarf_decode_line_header (line_offset
, abfd
, &cu
);
2348 do_cleanups (cleanups
);
2349 this_cu
->v
.quick
->no_file_data
= 1;
2353 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2354 qfn
->offset
= line_offset
;
2355 gdb_assert (slot
!= NULL
);
2358 find_file_and_directory (comp_unit_die
, &cu
, &name
, &comp_dir
);
2360 qfn
->num_file_names
= lh
->num_file_names
;
2361 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2362 lh
->num_file_names
* sizeof (char *));
2363 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2364 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2365 qfn
->real_names
= NULL
;
2367 free_line_header (lh
);
2368 do_cleanups (cleanups
);
2370 this_cu
->v
.quick
->file_names
= qfn
;
2374 /* A helper for the "quick" functions which computes and caches the
2375 real path for a given file name from the line table. */
2378 dw2_get_real_path (struct objfile
*objfile
,
2379 struct quick_file_names
*qfn
, int index
)
2381 if (qfn
->real_names
== NULL
)
2382 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2383 qfn
->num_file_names
, sizeof (char *));
2385 if (qfn
->real_names
[index
] == NULL
)
2386 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2388 return qfn
->real_names
[index
];
2391 static struct symtab
*
2392 dw2_find_last_source_symtab (struct objfile
*objfile
)
2396 dw2_setup (objfile
);
2397 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2398 return dw2_instantiate_symtab (objfile
, dw2_get_cu (index
));
2401 /* Traversal function for dw2_forget_cached_source_info. */
2404 dw2_free_cached_file_names (void **slot
, void *info
)
2406 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2408 if (file_data
->real_names
)
2412 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2414 xfree ((void*) file_data
->real_names
[i
]);
2415 file_data
->real_names
[i
] = NULL
;
2423 dw2_forget_cached_source_info (struct objfile
*objfile
)
2425 dw2_setup (objfile
);
2427 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2428 dw2_free_cached_file_names
, NULL
);
2432 dw2_lookup_symtab (struct objfile
*objfile
, const char *name
,
2433 const char *full_path
, const char *real_path
,
2434 struct symtab
**result
)
2437 int check_basename
= lbasename (name
) == name
;
2438 struct dwarf2_per_cu_data
*base_cu
= NULL
;
2440 dw2_setup (objfile
);
2442 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2443 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2446 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2447 struct quick_file_names
*file_data
;
2449 if (per_cu
->v
.quick
->symtab
)
2452 file_data
= dw2_get_file_names (objfile
, per_cu
);
2453 if (file_data
== NULL
)
2456 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2458 const char *this_name
= file_data
->file_names
[j
];
2460 if (FILENAME_CMP (name
, this_name
) == 0)
2462 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2466 if (check_basename
&& ! base_cu
2467 && FILENAME_CMP (lbasename (this_name
), name
) == 0)
2470 if (full_path
!= NULL
)
2472 const char *this_real_name
= dw2_get_real_path (objfile
,
2475 if (this_real_name
!= NULL
2476 && FILENAME_CMP (full_path
, this_real_name
) == 0)
2478 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2483 if (real_path
!= NULL
)
2485 const char *this_real_name
= dw2_get_real_path (objfile
,
2488 if (this_real_name
!= NULL
2489 && FILENAME_CMP (real_path
, this_real_name
) == 0)
2491 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2500 *result
= dw2_instantiate_symtab (objfile
, base_cu
);
2507 static struct symtab
*
2508 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2509 const char *name
, domain_enum domain
)
2511 /* We do all the work in the pre_expand_symtabs_matching hook
2516 /* A helper function that expands all symtabs that hold an object
2520 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2522 dw2_setup (objfile
);
2524 /* index_table is NULL if OBJF_READNOW. */
2525 if (dwarf2_per_objfile
->index_table
)
2529 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2532 offset_type i
, len
= MAYBE_SWAP (*vec
);
2533 for (i
= 0; i
< len
; ++i
)
2535 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2536 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2538 dw2_instantiate_symtab (objfile
, per_cu
);
2545 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2546 enum block_enum block_kind
, const char *name
,
2549 dw2_do_expand_symtabs_matching (objfile
, name
);
2553 dw2_print_stats (struct objfile
*objfile
)
2557 dw2_setup (objfile
);
2559 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2560 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2562 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2564 if (!per_cu
->v
.quick
->symtab
)
2567 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2571 dw2_dump (struct objfile
*objfile
)
2573 /* Nothing worth printing. */
2577 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2578 struct section_offsets
*delta
)
2580 /* There's nothing to relocate here. */
2584 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2585 const char *func_name
)
2587 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2591 dw2_expand_all_symtabs (struct objfile
*objfile
)
2595 dw2_setup (objfile
);
2597 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2598 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2600 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2602 dw2_instantiate_symtab (objfile
, per_cu
);
2607 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2608 const char *filename
)
2612 dw2_setup (objfile
);
2614 /* We don't need to consider type units here.
2615 This is only called for examining code, e.g. expand_line_sal.
2616 There can be an order of magnitude (or more) more type units
2617 than comp units, and we avoid them if we can. */
2619 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2622 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2623 struct quick_file_names
*file_data
;
2625 if (per_cu
->v
.quick
->symtab
)
2628 file_data
= dw2_get_file_names (objfile
, per_cu
);
2629 if (file_data
== NULL
)
2632 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2634 const char *this_name
= file_data
->file_names
[j
];
2635 if (FILENAME_CMP (this_name
, filename
) == 0)
2637 dw2_instantiate_symtab (objfile
, per_cu
);
2645 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2647 struct dwarf2_per_cu_data
*per_cu
;
2649 struct quick_file_names
*file_data
;
2651 dw2_setup (objfile
);
2653 /* index_table is NULL if OBJF_READNOW. */
2654 if (!dwarf2_per_objfile
->index_table
)
2658 ALL_OBJFILE_SYMTABS (objfile
, s
)
2661 struct blockvector
*bv
= BLOCKVECTOR (s
);
2662 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2663 struct symbol
*sym
= lookup_block_symbol (block
, name
, VAR_DOMAIN
);
2666 return sym
->symtab
->filename
;
2671 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2675 /* Note that this just looks at the very first one named NAME -- but
2676 actually we are looking for a function. find_main_filename
2677 should be rewritten so that it doesn't require a custom hook. It
2678 could just use the ordinary symbol tables. */
2679 /* vec[0] is the length, which must always be >0. */
2680 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[1]));
2682 file_data
= dw2_get_file_names (objfile
, per_cu
);
2683 if (file_data
== NULL
)
2686 return file_data
->file_names
[file_data
->num_file_names
- 1];
2690 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
2691 struct objfile
*objfile
, int global
,
2692 int (*callback
) (struct block
*,
2693 struct symbol
*, void *),
2694 void *data
, symbol_compare_ftype
*match
,
2695 symbol_compare_ftype
*ordered_compare
)
2697 /* Currently unimplemented; used for Ada. The function can be called if the
2698 current language is Ada for a non-Ada objfile using GNU index. As Ada
2699 does not look for non-Ada symbols this function should just return. */
2703 dw2_expand_symtabs_matching (struct objfile
*objfile
,
2704 int (*file_matcher
) (const char *, void *),
2705 int (*name_matcher
) (const char *, void *),
2706 enum search_domain kind
,
2711 struct mapped_index
*index
;
2713 dw2_setup (objfile
);
2715 /* index_table is NULL if OBJF_READNOW. */
2716 if (!dwarf2_per_objfile
->index_table
)
2718 index
= dwarf2_per_objfile
->index_table
;
2720 if (file_matcher
!= NULL
)
2721 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2722 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2725 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2726 struct quick_file_names
*file_data
;
2728 per_cu
->v
.quick
->mark
= 0;
2729 if (per_cu
->v
.quick
->symtab
)
2732 file_data
= dw2_get_file_names (objfile
, per_cu
);
2733 if (file_data
== NULL
)
2736 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2738 if (file_matcher (file_data
->file_names
[j
], data
))
2740 per_cu
->v
.quick
->mark
= 1;
2746 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2748 offset_type idx
= 2 * iter
;
2750 offset_type
*vec
, vec_len
, vec_idx
;
2752 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2755 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
2757 if (! (*name_matcher
) (name
, data
))
2760 /* The name was matched, now expand corresponding CUs that were
2762 vec
= (offset_type
*) (index
->constant_pool
2763 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
2764 vec_len
= MAYBE_SWAP (vec
[0]);
2765 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2767 struct dwarf2_per_cu_data
*per_cu
;
2769 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[vec_idx
+ 1]));
2770 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
2771 dw2_instantiate_symtab (objfile
, per_cu
);
2776 static struct symtab
*
2777 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
2778 struct minimal_symbol
*msymbol
,
2780 struct obj_section
*section
,
2783 struct dwarf2_per_cu_data
*data
;
2785 dw2_setup (objfile
);
2787 if (!objfile
->psymtabs_addrmap
)
2790 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
2794 if (warn_if_readin
&& data
->v
.quick
->symtab
)
2795 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2796 paddress (get_objfile_arch (objfile
), pc
));
2798 return dw2_instantiate_symtab (objfile
, data
);
2802 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
2807 dw2_setup (objfile
);
2809 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2810 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2813 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2814 struct quick_file_names
*file_data
;
2816 if (per_cu
->v
.quick
->symtab
)
2819 file_data
= dw2_get_file_names (objfile
, per_cu
);
2820 if (file_data
== NULL
)
2823 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2825 const char *this_real_name
= dw2_get_real_path (objfile
, file_data
,
2827 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
2833 dw2_has_symbols (struct objfile
*objfile
)
2838 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
2841 dw2_find_last_source_symtab
,
2842 dw2_forget_cached_source_info
,
2845 dw2_pre_expand_symtabs_matching
,
2849 dw2_expand_symtabs_for_function
,
2850 dw2_expand_all_symtabs
,
2851 dw2_expand_symtabs_with_filename
,
2852 dw2_find_symbol_file
,
2853 dw2_map_matching_symbols
,
2854 dw2_expand_symtabs_matching
,
2855 dw2_find_pc_sect_symtab
,
2856 dw2_map_symbol_filenames
2859 /* Initialize for reading DWARF for this objfile. Return 0 if this
2860 file will use psymtabs, or 1 if using the GNU index. */
2863 dwarf2_initialize_objfile (struct objfile
*objfile
)
2865 /* If we're about to read full symbols, don't bother with the
2866 indices. In this case we also don't care if some other debug
2867 format is making psymtabs, because they are all about to be
2869 if ((objfile
->flags
& OBJF_READNOW
))
2873 dwarf2_per_objfile
->using_index
= 1;
2874 create_all_comp_units (objfile
);
2875 create_debug_types_hash_table (objfile
);
2876 dwarf2_per_objfile
->quick_file_names_table
=
2877 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2879 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2880 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2882 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2884 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2885 struct dwarf2_per_cu_quick_data
);
2888 /* Return 1 so that gdb sees the "quick" functions. However,
2889 these functions will be no-ops because we will have expanded
2894 if (dwarf2_read_index (objfile
))
2902 /* Build a partial symbol table. */
2905 dwarf2_build_psymtabs (struct objfile
*objfile
)
2907 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2909 init_psymbol_list (objfile
, 1024);
2912 dwarf2_build_psymtabs_hard (objfile
);
2915 /* Return TRUE if OFFSET is within CU_HEADER. */
2918 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
2920 unsigned int bottom
= cu_header
->offset
;
2921 unsigned int top
= (cu_header
->offset
2923 + cu_header
->initial_length_size
);
2925 return (offset
>= bottom
&& offset
< top
);
2928 /* Read in the comp unit header information from the debug_info at info_ptr.
2929 NOTE: This leaves members offset, first_die_offset to be filled in
2933 read_comp_unit_head (struct comp_unit_head
*cu_header
,
2934 gdb_byte
*info_ptr
, bfd
*abfd
)
2937 unsigned int bytes_read
;
2939 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
2940 cu_header
->initial_length_size
= bytes_read
;
2941 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
2942 info_ptr
+= bytes_read
;
2943 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
2945 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
2947 info_ptr
+= bytes_read
;
2948 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
2950 signed_addr
= bfd_get_sign_extend_vma (abfd
);
2951 if (signed_addr
< 0)
2952 internal_error (__FILE__
, __LINE__
,
2953 _("read_comp_unit_head: dwarf from non elf file"));
2954 cu_header
->signed_addr_p
= signed_addr
;
2959 /* Read in a CU header and perform some basic error checking. */
2962 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
2963 gdb_byte
*buffer
, unsigned int buffer_size
,
2966 gdb_byte
*beg_of_comp_unit
= info_ptr
;
2968 header
->offset
= beg_of_comp_unit
- buffer
;
2970 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
2972 header
->first_die_offset
= info_ptr
- beg_of_comp_unit
;
2974 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
2975 error (_("Dwarf Error: wrong version in compilation unit header "
2976 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
2977 bfd_get_filename (abfd
));
2979 if (header
->abbrev_offset
2980 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
2981 &dwarf2_per_objfile
->abbrev
))
2982 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
2983 "(offset 0x%lx + 6) [in module %s]"),
2984 (long) header
->abbrev_offset
,
2985 (long) (beg_of_comp_unit
- buffer
),
2986 bfd_get_filename (abfd
));
2988 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
2989 > buffer
+ buffer_size
)
2990 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
2991 "(offset 0x%lx + 0) [in module %s]"),
2992 (long) header
->length
,
2993 (long) (beg_of_comp_unit
- buffer
),
2994 bfd_get_filename (abfd
));
2999 /* Read in the types comp unit header information from .debug_types entry at
3000 types_ptr. The result is a pointer to one past the end of the header. */
3003 read_type_comp_unit_head (struct comp_unit_head
*cu_header
,
3004 struct dwarf2_section_info
*section
,
3005 ULONGEST
*signature
,
3006 gdb_byte
*types_ptr
, bfd
*abfd
)
3008 gdb_byte
*initial_types_ptr
= types_ptr
;
3010 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
3011 cu_header
->offset
= types_ptr
- section
->buffer
;
3013 types_ptr
= read_comp_unit_head (cu_header
, types_ptr
, abfd
);
3015 *signature
= read_8_bytes (abfd
, types_ptr
);
3017 types_ptr
+= cu_header
->offset_size
;
3018 cu_header
->first_die_offset
= types_ptr
- initial_types_ptr
;
3023 /* Allocate a new partial symtab for file named NAME and mark this new
3024 partial symtab as being an include of PST. */
3027 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
3028 struct objfile
*objfile
)
3030 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
3032 subpst
->section_offsets
= pst
->section_offsets
;
3033 subpst
->textlow
= 0;
3034 subpst
->texthigh
= 0;
3036 subpst
->dependencies
= (struct partial_symtab
**)
3037 obstack_alloc (&objfile
->objfile_obstack
,
3038 sizeof (struct partial_symtab
*));
3039 subpst
->dependencies
[0] = pst
;
3040 subpst
->number_of_dependencies
= 1;
3042 subpst
->globals_offset
= 0;
3043 subpst
->n_global_syms
= 0;
3044 subpst
->statics_offset
= 0;
3045 subpst
->n_static_syms
= 0;
3046 subpst
->symtab
= NULL
;
3047 subpst
->read_symtab
= pst
->read_symtab
;
3050 /* No private part is necessary for include psymtabs. This property
3051 can be used to differentiate between such include psymtabs and
3052 the regular ones. */
3053 subpst
->read_symtab_private
= NULL
;
3056 /* Read the Line Number Program data and extract the list of files
3057 included by the source file represented by PST. Build an include
3058 partial symtab for each of these included files. */
3061 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
3062 struct die_info
*die
,
3063 struct partial_symtab
*pst
)
3065 struct objfile
*objfile
= cu
->objfile
;
3066 bfd
*abfd
= objfile
->obfd
;
3067 struct line_header
*lh
= NULL
;
3068 struct attribute
*attr
;
3070 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3073 unsigned int line_offset
= DW_UNSND (attr
);
3075 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
3078 return; /* No linetable, so no includes. */
3080 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3081 dwarf_decode_lines (lh
, pst
->dirname
, abfd
, cu
, pst
);
3083 free_line_header (lh
);
3087 hash_type_signature (const void *item
)
3089 const struct signatured_type
*type_sig
= item
;
3091 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3092 return type_sig
->signature
;
3096 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
3098 const struct signatured_type
*lhs
= item_lhs
;
3099 const struct signatured_type
*rhs
= item_rhs
;
3101 return lhs
->signature
== rhs
->signature
;
3104 /* Allocate a hash table for signatured types. */
3107 allocate_signatured_type_table (struct objfile
*objfile
)
3109 return htab_create_alloc_ex (41,
3110 hash_type_signature
,
3113 &objfile
->objfile_obstack
,
3114 hashtab_obstack_allocate
,
3115 dummy_obstack_deallocate
);
3118 /* A helper function to add a signatured type CU to a list. */
3121 add_signatured_type_cu_to_list (void **slot
, void *datum
)
3123 struct signatured_type
*sigt
= *slot
;
3124 struct dwarf2_per_cu_data
***datap
= datum
;
3126 **datap
= &sigt
->per_cu
;
3132 /* Create the hash table of all entries in the .debug_types section.
3133 The result is zero if there is an error (e.g. missing .debug_types section),
3134 otherwise non-zero. */
3137 create_debug_types_hash_table (struct objfile
*objfile
)
3139 htab_t types_htab
= NULL
;
3140 struct dwarf2_per_cu_data
**iter
;
3142 struct dwarf2_section_info
*section
;
3144 if (VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
))
3146 dwarf2_per_objfile
->signatured_types
= NULL
;
3151 VEC_iterate (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
3155 gdb_byte
*info_ptr
, *end_ptr
;
3157 dwarf2_read_section (objfile
, section
);
3158 info_ptr
= section
->buffer
;
3160 if (info_ptr
== NULL
)
3163 if (types_htab
== NULL
)
3164 types_htab
= allocate_signatured_type_table (objfile
);
3166 if (dwarf2_die_debug
)
3167 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
3169 end_ptr
= info_ptr
+ section
->size
;
3170 while (info_ptr
< end_ptr
)
3172 unsigned int offset
;
3173 unsigned int offset_size
;
3174 unsigned int type_offset
;
3175 unsigned int length
, initial_length_size
;
3176 unsigned short version
;
3178 struct signatured_type
*type_sig
;
3180 gdb_byte
*ptr
= info_ptr
;
3182 offset
= ptr
- section
->buffer
;
3184 /* We need to read the type's signature in order to build the hash
3185 table, but we don't need to read anything else just yet. */
3187 /* Sanity check to ensure entire cu is present. */
3188 length
= read_initial_length (objfile
->obfd
, ptr
,
3189 &initial_length_size
);
3190 if (ptr
+ length
+ initial_length_size
> end_ptr
)
3192 complaint (&symfile_complaints
,
3193 _("debug type entry runs off end "
3194 "of `.debug_types' section, ignored"));
3198 offset_size
= initial_length_size
== 4 ? 4 : 8;
3199 ptr
+= initial_length_size
;
3200 version
= bfd_get_16 (objfile
->obfd
, ptr
);
3202 ptr
+= offset_size
; /* abbrev offset */
3203 ptr
+= 1; /* address size */
3204 signature
= bfd_get_64 (objfile
->obfd
, ptr
);
3206 type_offset
= read_offset_1 (objfile
->obfd
, ptr
, offset_size
);
3208 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
3209 memset (type_sig
, 0, sizeof (*type_sig
));
3210 type_sig
->signature
= signature
;
3211 type_sig
->type_offset
= type_offset
;
3212 type_sig
->per_cu
.objfile
= objfile
;
3213 type_sig
->per_cu
.debug_type_section
= section
;
3214 type_sig
->per_cu
.offset
= offset
;
3216 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
3217 gdb_assert (slot
!= NULL
);
3220 const struct signatured_type
*dup_sig
= *slot
;
3222 complaint (&symfile_complaints
,
3223 _("debug type entry at offset 0x%x is duplicate to the "
3224 "entry at offset 0x%x, signature 0x%s"),
3225 offset
, dup_sig
->per_cu
.offset
,
3226 phex (signature
, sizeof (signature
)));
3227 gdb_assert (signature
== dup_sig
->signature
);
3231 if (dwarf2_die_debug
)
3232 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3233 offset
, phex (signature
, sizeof (signature
)));
3235 info_ptr
= info_ptr
+ initial_length_size
+ length
;
3239 dwarf2_per_objfile
->signatured_types
= types_htab
;
3241 dwarf2_per_objfile
->n_type_comp_units
= htab_elements (types_htab
);
3242 dwarf2_per_objfile
->type_comp_units
3243 = obstack_alloc (&objfile
->objfile_obstack
,
3244 dwarf2_per_objfile
->n_type_comp_units
3245 * sizeof (struct dwarf2_per_cu_data
*));
3246 iter
= &dwarf2_per_objfile
->type_comp_units
[0];
3247 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_list
, &iter
);
3248 gdb_assert (iter
- &dwarf2_per_objfile
->type_comp_units
[0]
3249 == dwarf2_per_objfile
->n_type_comp_units
);
3254 /* Lookup a signature based type.
3255 Returns NULL if SIG is not present in the table. */
3257 static struct signatured_type
*
3258 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
3260 struct signatured_type find_entry
, *entry
;
3262 if (dwarf2_per_objfile
->signatured_types
== NULL
)
3264 complaint (&symfile_complaints
,
3265 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3269 find_entry
.signature
= sig
;
3270 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
3274 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3277 init_cu_die_reader (struct die_reader_specs
*reader
,
3278 struct dwarf2_cu
*cu
)
3280 reader
->abfd
= cu
->objfile
->obfd
;
3282 if (cu
->per_cu
->debug_type_section
)
3284 gdb_assert (cu
->per_cu
->debug_type_section
->readin
);
3285 reader
->buffer
= cu
->per_cu
->debug_type_section
->buffer
;
3289 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3290 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
3294 /* Find the base address of the compilation unit for range lists and
3295 location lists. It will normally be specified by DW_AT_low_pc.
3296 In DWARF-3 draft 4, the base address could be overridden by
3297 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3298 compilation units with discontinuous ranges. */
3301 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3303 struct attribute
*attr
;
3306 cu
->base_address
= 0;
3308 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3311 cu
->base_address
= DW_ADDR (attr
);
3316 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3319 cu
->base_address
= DW_ADDR (attr
);
3325 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
3326 to combine the common parts.
3327 Process a compilation unit for a psymtab.
3328 BUFFER is a pointer to the beginning of the dwarf section buffer,
3329 either .debug_info or debug_types.
3330 INFO_PTR is a pointer to the start of the CU.
3331 Returns a pointer to the next CU. */
3334 process_psymtab_comp_unit (struct objfile
*objfile
,
3335 struct dwarf2_per_cu_data
*this_cu
,
3336 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
3337 unsigned int buffer_size
)
3339 bfd
*abfd
= objfile
->obfd
;
3340 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3341 struct die_info
*comp_unit_die
;
3342 struct partial_symtab
*pst
;
3344 struct cleanup
*back_to_inner
;
3345 struct dwarf2_cu cu
;
3346 int has_children
, has_pc_info
;
3347 struct attribute
*attr
;
3348 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
3349 struct die_reader_specs reader_specs
;
3350 const char *filename
;
3352 init_one_comp_unit (&cu
, objfile
);
3353 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
3355 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
3356 buffer
, buffer_size
,
3359 cu
.list_in_scope
= &file_symbols
;
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. */
3375 cu
.per_cu
= this_cu
;
3377 /* Read the abbrevs for this compilation unit into a table. */
3378 dwarf2_read_abbrevs (abfd
, &cu
);
3379 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
3381 /* Read the compilation unit die. */
3382 if (this_cu
->debug_type_section
)
3383 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
3384 init_cu_die_reader (&reader_specs
, &cu
);
3385 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3388 if (this_cu
->debug_type_section
)
3390 /* LENGTH has not been set yet for type units. */
3391 gdb_assert (this_cu
->offset
== cu
.header
.offset
);
3392 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
3394 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3396 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3397 + cu
.header
.initial_length_size
);
3398 do_cleanups (back_to_inner
);
3402 prepare_one_comp_unit (&cu
, comp_unit_die
);
3404 /* Allocate a new partial symbol table structure. */
3405 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
3406 if (attr
== NULL
|| !DW_STRING (attr
))
3409 filename
= DW_STRING (attr
);
3410 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
3412 /* TEXTLOW and TEXTHIGH are set below. */
3414 objfile
->global_psymbols
.next
,
3415 objfile
->static_psymbols
.next
);
3417 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
3419 pst
->dirname
= DW_STRING (attr
);
3421 pst
->read_symtab_private
= this_cu
;
3423 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3425 /* Store the function that reads in the rest of the symbol table. */
3426 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
3428 this_cu
->v
.psymtab
= pst
;
3430 dwarf2_find_base_address (comp_unit_die
, &cu
);
3432 /* Possibly set the default values of LOWPC and HIGHPC from
3434 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
3435 &best_highpc
, &cu
, pst
);
3436 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
3437 /* Store the contiguous range if it is not empty; it can be empty for
3438 CUs with no code. */
3439 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3440 best_lowpc
+ baseaddr
,
3441 best_highpc
+ baseaddr
- 1, pst
);
3443 /* Check if comp unit has_children.
3444 If so, read the rest of the partial symbols from this comp unit.
3445 If not, there's no more debug_info for this comp unit. */
3448 struct partial_die_info
*first_die
;
3449 CORE_ADDR lowpc
, highpc
;
3451 lowpc
= ((CORE_ADDR
) -1);
3452 highpc
= ((CORE_ADDR
) 0);
3454 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
3456 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
3457 ! has_pc_info
, &cu
);
3459 /* If we didn't find a lowpc, set it to highpc to avoid
3460 complaints from `maint check'. */
3461 if (lowpc
== ((CORE_ADDR
) -1))
3464 /* If the compilation unit didn't have an explicit address range,
3465 then use the information extracted from its child dies. */
3469 best_highpc
= highpc
;
3472 pst
->textlow
= best_lowpc
+ baseaddr
;
3473 pst
->texthigh
= best_highpc
+ baseaddr
;
3475 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
3476 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
3477 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
3478 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
3479 sort_pst_symbols (pst
);
3481 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3482 + cu
.header
.initial_length_size
);
3484 if (this_cu
->debug_type_section
)
3486 /* It's not clear we want to do anything with stmt lists here.
3487 Waiting to see what gcc ultimately does. */
3491 /* Get the list of files included in the current compilation unit,
3492 and build a psymtab for each of them. */
3493 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
3496 do_cleanups (back_to_inner
);
3501 /* Traversal function for htab_traverse_noresize.
3502 Process one .debug_types comp-unit. */
3505 process_type_comp_unit (void **slot
, void *info
)
3507 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
3508 struct objfile
*objfile
= (struct objfile
*) info
;
3509 struct dwarf2_per_cu_data
*this_cu
;
3511 this_cu
= &entry
->per_cu
;
3513 gdb_assert (this_cu
->debug_type_section
->readin
);
3514 process_psymtab_comp_unit (objfile
, this_cu
,
3515 this_cu
->debug_type_section
->buffer
,
3516 (this_cu
->debug_type_section
->buffer
3518 this_cu
->debug_type_section
->size
);
3523 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3524 Build partial symbol tables for the .debug_types comp-units. */
3527 build_type_psymtabs (struct objfile
*objfile
)
3529 if (! create_debug_types_hash_table (objfile
))
3532 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
3533 process_type_comp_unit
, objfile
);
3536 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3539 psymtabs_addrmap_cleanup (void *o
)
3541 struct objfile
*objfile
= o
;
3543 objfile
->psymtabs_addrmap
= NULL
;
3546 /* Build the partial symbol table by doing a quick pass through the
3547 .debug_info and .debug_abbrev sections. */
3550 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
3553 struct cleanup
*back_to
, *addrmap_cleanup
;
3554 struct obstack temp_obstack
;
3556 dwarf2_per_objfile
->reading_partial_symbols
= 1;
3558 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3559 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
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 /* Since the objects we're extracting from .debug_info vary in
3577 length, only the individual functions to extract them (like
3578 read_comp_unit_head and load_partial_die) can really know whether
3579 the buffer is large enough to hold another complete object.
3581 At the moment, they don't actually check that. If .debug_info
3582 holds just one extra byte after the last compilation unit's dies,
3583 then read_comp_unit_head will happily read off the end of the
3584 buffer. read_partial_die is similarly casual. Those functions
3587 For this loop condition, simply checking whether there's any data
3588 left at all should be sufficient. */
3590 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
3591 + dwarf2_per_objfile
->info
.size
))
3593 struct dwarf2_per_cu_data
*this_cu
;
3595 this_cu
= dwarf2_find_comp_unit (info_ptr
3596 - dwarf2_per_objfile
->info
.buffer
,
3599 info_ptr
= process_psymtab_comp_unit (objfile
, this_cu
,
3600 dwarf2_per_objfile
->info
.buffer
,
3602 dwarf2_per_objfile
->info
.size
);
3605 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
3606 &objfile
->objfile_obstack
);
3607 discard_cleanups (addrmap_cleanup
);
3609 do_cleanups (back_to
);
3612 /* Load the partial DIEs for a secondary CU into memory. */
3615 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
3616 struct objfile
*objfile
)
3618 bfd
*abfd
= objfile
->obfd
;
3620 struct die_info
*comp_unit_die
;
3621 struct dwarf2_cu
*cu
;
3622 struct cleanup
*free_abbrevs_cleanup
, *free_cu_cleanup
= NULL
;
3624 struct die_reader_specs reader_specs
;
3627 gdb_assert (! this_cu
->debug_type_section
);
3629 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3630 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
3632 if (this_cu
->cu
== NULL
)
3634 cu
= xmalloc (sizeof (*cu
));
3635 init_one_comp_unit (cu
, objfile
);
3639 /* If an error occurs while loading, release our storage. */
3640 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
3642 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
,
3643 dwarf2_per_objfile
->info
.buffer
,
3644 dwarf2_per_objfile
->info
.size
,
3647 /* Link this compilation unit into the compilation unit tree. */
3649 cu
->per_cu
= this_cu
;
3651 /* Link this CU into read_in_chain. */
3652 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3653 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3658 info_ptr
+= cu
->header
.first_die_offset
;
3661 /* Read the abbrevs for this compilation unit into a table. */
3662 gdb_assert (cu
->dwarf2_abbrevs
== NULL
);
3663 dwarf2_read_abbrevs (abfd
, cu
);
3664 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3666 /* Read the compilation unit die. */
3667 init_cu_die_reader (&reader_specs
, cu
);
3668 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3671 prepare_one_comp_unit (cu
, comp_unit_die
);
3673 /* Check if comp unit has_children.
3674 If so, read the rest of the partial symbols from this comp unit.
3675 If not, there's no more debug_info for this comp unit. */
3677 load_partial_dies (abfd
, dwarf2_per_objfile
->info
.buffer
, info_ptr
, 0, cu
);
3679 do_cleanups (free_abbrevs_cleanup
);
3683 /* We've successfully allocated this compilation unit. Let our
3684 caller clean it up when finished with it. */
3685 discard_cleanups (free_cu_cleanup
);
3689 /* Create a list of all compilation units in OBJFILE. We do this only
3690 if an inter-comp-unit reference is found; presumably if there is one,
3691 there will be many, and one will occur early in the .debug_info section.
3692 So there's no point in building this list incrementally. */
3695 create_all_comp_units (struct objfile
*objfile
)
3699 struct dwarf2_per_cu_data
**all_comp_units
;
3702 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3703 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3707 all_comp_units
= xmalloc (n_allocated
3708 * sizeof (struct dwarf2_per_cu_data
*));
3710 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
3711 + dwarf2_per_objfile
->info
.size
)
3713 unsigned int length
, initial_length_size
;
3714 struct dwarf2_per_cu_data
*this_cu
;
3715 unsigned int offset
;
3717 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
3719 /* Read just enough information to find out where the next
3720 compilation unit is. */
3721 length
= read_initial_length (objfile
->obfd
, info_ptr
,
3722 &initial_length_size
);
3724 /* Save the compilation unit for later lookup. */
3725 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
3726 sizeof (struct dwarf2_per_cu_data
));
3727 memset (this_cu
, 0, sizeof (*this_cu
));
3728 this_cu
->offset
= offset
;
3729 this_cu
->length
= length
+ initial_length_size
;
3730 this_cu
->objfile
= objfile
;
3732 if (n_comp_units
== n_allocated
)
3735 all_comp_units
= xrealloc (all_comp_units
,
3737 * sizeof (struct dwarf2_per_cu_data
*));
3739 all_comp_units
[n_comp_units
++] = this_cu
;
3741 info_ptr
= info_ptr
+ this_cu
->length
;
3744 dwarf2_per_objfile
->all_comp_units
3745 = obstack_alloc (&objfile
->objfile_obstack
,
3746 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3747 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
3748 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3749 xfree (all_comp_units
);
3750 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
3753 /* Process all loaded DIEs for compilation unit CU, starting at
3754 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3755 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3756 DW_AT_ranges). If NEED_PC is set, then this function will set
3757 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3758 and record the covered ranges in the addrmap. */
3761 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
3762 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3764 struct partial_die_info
*pdi
;
3766 /* Now, march along the PDI's, descending into ones which have
3767 interesting children but skipping the children of the other ones,
3768 until we reach the end of the compilation unit. */
3774 fixup_partial_die (pdi
, cu
);
3776 /* Anonymous namespaces or modules have no name but have interesting
3777 children, so we need to look at them. Ditto for anonymous
3780 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
3781 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
3785 case DW_TAG_subprogram
:
3786 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3788 case DW_TAG_constant
:
3789 case DW_TAG_variable
:
3790 case DW_TAG_typedef
:
3791 case DW_TAG_union_type
:
3792 if (!pdi
->is_declaration
)
3794 add_partial_symbol (pdi
, cu
);
3797 case DW_TAG_class_type
:
3798 case DW_TAG_interface_type
:
3799 case DW_TAG_structure_type
:
3800 if (!pdi
->is_declaration
)
3802 add_partial_symbol (pdi
, cu
);
3805 case DW_TAG_enumeration_type
:
3806 if (!pdi
->is_declaration
)
3807 add_partial_enumeration (pdi
, cu
);
3809 case DW_TAG_base_type
:
3810 case DW_TAG_subrange_type
:
3811 /* File scope base type definitions are added to the partial
3813 add_partial_symbol (pdi
, cu
);
3815 case DW_TAG_namespace
:
3816 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
3819 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
3826 /* If the die has a sibling, skip to the sibling. */
3828 pdi
= pdi
->die_sibling
;
3832 /* Functions used to compute the fully scoped name of a partial DIE.
3834 Normally, this is simple. For C++, the parent DIE's fully scoped
3835 name is concatenated with "::" and the partial DIE's name. For
3836 Java, the same thing occurs except that "." is used instead of "::".
3837 Enumerators are an exception; they use the scope of their parent
3838 enumeration type, i.e. the name of the enumeration type is not
3839 prepended to the enumerator.
3841 There are two complexities. One is DW_AT_specification; in this
3842 case "parent" means the parent of the target of the specification,
3843 instead of the direct parent of the DIE. The other is compilers
3844 which do not emit DW_TAG_namespace; in this case we try to guess
3845 the fully qualified name of structure types from their members'
3846 linkage names. This must be done using the DIE's children rather
3847 than the children of any DW_AT_specification target. We only need
3848 to do this for structures at the top level, i.e. if the target of
3849 any DW_AT_specification (if any; otherwise the DIE itself) does not
3852 /* Compute the scope prefix associated with PDI's parent, in
3853 compilation unit CU. The result will be allocated on CU's
3854 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3855 field. NULL is returned if no prefix is necessary. */
3857 partial_die_parent_scope (struct partial_die_info
*pdi
,
3858 struct dwarf2_cu
*cu
)
3860 char *grandparent_scope
;
3861 struct partial_die_info
*parent
, *real_pdi
;
3863 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3864 then this means the parent of the specification DIE. */
3867 while (real_pdi
->has_specification
)
3868 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3870 parent
= real_pdi
->die_parent
;
3874 if (parent
->scope_set
)
3875 return parent
->scope
;
3877 fixup_partial_die (parent
, cu
);
3879 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
3881 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3882 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3883 Work around this problem here. */
3884 if (cu
->language
== language_cplus
3885 && parent
->tag
== DW_TAG_namespace
3886 && strcmp (parent
->name
, "::") == 0
3887 && grandparent_scope
== NULL
)
3889 parent
->scope
= NULL
;
3890 parent
->scope_set
= 1;
3894 if (pdi
->tag
== DW_TAG_enumerator
)
3895 /* Enumerators should not get the name of the enumeration as a prefix. */
3896 parent
->scope
= grandparent_scope
;
3897 else if (parent
->tag
== DW_TAG_namespace
3898 || parent
->tag
== DW_TAG_module
3899 || parent
->tag
== DW_TAG_structure_type
3900 || parent
->tag
== DW_TAG_class_type
3901 || parent
->tag
== DW_TAG_interface_type
3902 || parent
->tag
== DW_TAG_union_type
3903 || parent
->tag
== DW_TAG_enumeration_type
)
3905 if (grandparent_scope
== NULL
)
3906 parent
->scope
= parent
->name
;
3908 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
3910 parent
->name
, 0, cu
);
3914 /* FIXME drow/2004-04-01: What should we be doing with
3915 function-local names? For partial symbols, we should probably be
3917 complaint (&symfile_complaints
,
3918 _("unhandled containing DIE tag %d for DIE at %d"),
3919 parent
->tag
, pdi
->offset
);
3920 parent
->scope
= grandparent_scope
;
3923 parent
->scope_set
= 1;
3924 return parent
->scope
;
3927 /* Return the fully scoped name associated with PDI, from compilation unit
3928 CU. The result will be allocated with malloc. */
3930 partial_die_full_name (struct partial_die_info
*pdi
,
3931 struct dwarf2_cu
*cu
)
3935 /* If this is a template instantiation, we can not work out the
3936 template arguments from partial DIEs. So, unfortunately, we have
3937 to go through the full DIEs. At least any work we do building
3938 types here will be reused if full symbols are loaded later. */
3939 if (pdi
->has_template_arguments
)
3941 fixup_partial_die (pdi
, cu
);
3943 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
3945 struct die_info
*die
;
3946 struct attribute attr
;
3947 struct dwarf2_cu
*ref_cu
= cu
;
3950 attr
.form
= DW_FORM_ref_addr
;
3951 attr
.u
.addr
= pdi
->offset
;
3952 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
3954 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
3958 parent_scope
= partial_die_parent_scope (pdi
, cu
);
3959 if (parent_scope
== NULL
)
3962 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
3966 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
3968 struct objfile
*objfile
= cu
->objfile
;
3970 char *actual_name
= NULL
;
3971 const struct partial_symbol
*psym
= NULL
;
3973 int built_actual_name
= 0;
3975 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3977 actual_name
= partial_die_full_name (pdi
, cu
);
3979 built_actual_name
= 1;
3981 if (actual_name
== NULL
)
3982 actual_name
= pdi
->name
;
3986 case DW_TAG_subprogram
:
3987 if (pdi
->is_external
|| cu
->language
== language_ada
)
3989 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
3990 of the global scope. But in Ada, we want to be able to access
3991 nested procedures globally. So all Ada subprograms are stored
3992 in the global scope. */
3993 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3994 mst_text, objfile); */
3995 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3997 VAR_DOMAIN
, LOC_BLOCK
,
3998 &objfile
->global_psymbols
,
3999 0, pdi
->lowpc
+ baseaddr
,
4000 cu
->language
, objfile
);
4004 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4005 mst_file_text, objfile); */
4006 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4008 VAR_DOMAIN
, LOC_BLOCK
,
4009 &objfile
->static_psymbols
,
4010 0, pdi
->lowpc
+ baseaddr
,
4011 cu
->language
, objfile
);
4014 case DW_TAG_constant
:
4016 struct psymbol_allocation_list
*list
;
4018 if (pdi
->is_external
)
4019 list
= &objfile
->global_psymbols
;
4021 list
= &objfile
->static_psymbols
;
4022 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4023 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
4024 list
, 0, 0, cu
->language
, objfile
);
4027 case DW_TAG_variable
:
4029 addr
= decode_locdesc (pdi
->locdesc
, cu
);
4033 && !dwarf2_per_objfile
->has_section_at_zero
)
4035 /* A global or static variable may also have been stripped
4036 out by the linker if unused, in which case its address
4037 will be nullified; do not add such variables into partial
4038 symbol table then. */
4040 else if (pdi
->is_external
)
4043 Don't enter into the minimal symbol tables as there is
4044 a minimal symbol table entry from the ELF symbols already.
4045 Enter into partial symbol table if it has a location
4046 descriptor or a type.
4047 If the location descriptor is missing, new_symbol will create
4048 a LOC_UNRESOLVED symbol, the address of the variable will then
4049 be determined from the minimal symbol table whenever the variable
4051 The address for the partial symbol table entry is not
4052 used by GDB, but it comes in handy for debugging partial symbol
4055 if (pdi
->locdesc
|| pdi
->has_type
)
4056 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4058 VAR_DOMAIN
, LOC_STATIC
,
4059 &objfile
->global_psymbols
,
4061 cu
->language
, objfile
);
4065 /* Static Variable. Skip symbols without location descriptors. */
4066 if (pdi
->locdesc
== NULL
)
4068 if (built_actual_name
)
4069 xfree (actual_name
);
4072 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
4073 mst_file_data, objfile); */
4074 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4076 VAR_DOMAIN
, LOC_STATIC
,
4077 &objfile
->static_psymbols
,
4079 cu
->language
, objfile
);
4082 case DW_TAG_typedef
:
4083 case DW_TAG_base_type
:
4084 case DW_TAG_subrange_type
:
4085 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4087 VAR_DOMAIN
, LOC_TYPEDEF
,
4088 &objfile
->static_psymbols
,
4089 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4091 case DW_TAG_namespace
:
4092 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4094 VAR_DOMAIN
, LOC_TYPEDEF
,
4095 &objfile
->global_psymbols
,
4096 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4098 case DW_TAG_class_type
:
4099 case DW_TAG_interface_type
:
4100 case DW_TAG_structure_type
:
4101 case DW_TAG_union_type
:
4102 case DW_TAG_enumeration_type
:
4103 /* Skip external references. The DWARF standard says in the section
4104 about "Structure, Union, and Class Type Entries": "An incomplete
4105 structure, union or class type is represented by a structure,
4106 union or class entry that does not have a byte size attribute
4107 and that has a DW_AT_declaration attribute." */
4108 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
4110 if (built_actual_name
)
4111 xfree (actual_name
);
4115 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
4116 static vs. global. */
4117 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4119 STRUCT_DOMAIN
, LOC_TYPEDEF
,
4120 (cu
->language
== language_cplus
4121 || cu
->language
== language_java
)
4122 ? &objfile
->global_psymbols
4123 : &objfile
->static_psymbols
,
4124 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4127 case DW_TAG_enumerator
:
4128 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4130 VAR_DOMAIN
, LOC_CONST
,
4131 (cu
->language
== language_cplus
4132 || cu
->language
== language_java
)
4133 ? &objfile
->global_psymbols
4134 : &objfile
->static_psymbols
,
4135 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4141 if (built_actual_name
)
4142 xfree (actual_name
);
4145 /* Read a partial die corresponding to a namespace; also, add a symbol
4146 corresponding to that namespace to the symbol table. NAMESPACE is
4147 the name of the enclosing namespace. */
4150 add_partial_namespace (struct partial_die_info
*pdi
,
4151 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4152 int need_pc
, struct dwarf2_cu
*cu
)
4154 /* Add a symbol for the namespace. */
4156 add_partial_symbol (pdi
, cu
);
4158 /* Now scan partial symbols in that namespace. */
4160 if (pdi
->has_children
)
4161 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4164 /* Read a partial die corresponding to a Fortran module. */
4167 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
4168 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4170 /* Now scan partial symbols in that module. */
4172 if (pdi
->has_children
)
4173 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4176 /* Read a partial die corresponding to a subprogram and create a partial
4177 symbol for that subprogram. When the CU language allows it, this
4178 routine also defines a partial symbol for each nested subprogram
4179 that this subprogram contains.
4181 DIE my also be a lexical block, in which case we simply search
4182 recursively for suprograms defined inside that lexical block.
4183 Again, this is only performed when the CU language allows this
4184 type of definitions. */
4187 add_partial_subprogram (struct partial_die_info
*pdi
,
4188 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4189 int need_pc
, struct dwarf2_cu
*cu
)
4191 if (pdi
->tag
== DW_TAG_subprogram
)
4193 if (pdi
->has_pc_info
)
4195 if (pdi
->lowpc
< *lowpc
)
4196 *lowpc
= pdi
->lowpc
;
4197 if (pdi
->highpc
> *highpc
)
4198 *highpc
= pdi
->highpc
;
4202 struct objfile
*objfile
= cu
->objfile
;
4204 baseaddr
= ANOFFSET (objfile
->section_offsets
,
4205 SECT_OFF_TEXT (objfile
));
4206 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4207 pdi
->lowpc
+ baseaddr
,
4208 pdi
->highpc
- 1 + baseaddr
,
4209 cu
->per_cu
->v
.psymtab
);
4211 if (!pdi
->is_declaration
)
4212 /* Ignore subprogram DIEs that do not have a name, they are
4213 illegal. Do not emit a complaint at this point, we will
4214 do so when we convert this psymtab into a symtab. */
4216 add_partial_symbol (pdi
, cu
);
4220 if (! pdi
->has_children
)
4223 if (cu
->language
== language_ada
)
4225 pdi
= pdi
->die_child
;
4228 fixup_partial_die (pdi
, cu
);
4229 if (pdi
->tag
== DW_TAG_subprogram
4230 || pdi
->tag
== DW_TAG_lexical_block
)
4231 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4232 pdi
= pdi
->die_sibling
;
4237 /* Read a partial die corresponding to an enumeration type. */
4240 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
4241 struct dwarf2_cu
*cu
)
4243 struct partial_die_info
*pdi
;
4245 if (enum_pdi
->name
!= NULL
)
4246 add_partial_symbol (enum_pdi
, cu
);
4248 pdi
= enum_pdi
->die_child
;
4251 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
4252 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
4254 add_partial_symbol (pdi
, cu
);
4255 pdi
= pdi
->die_sibling
;
4259 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4260 Return the corresponding abbrev, or NULL if the number is zero (indicating
4261 an empty DIE). In either case *BYTES_READ will be set to the length of
4262 the initial number. */
4264 static struct abbrev_info
*
4265 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
4266 struct dwarf2_cu
*cu
)
4268 bfd
*abfd
= cu
->objfile
->obfd
;
4269 unsigned int abbrev_number
;
4270 struct abbrev_info
*abbrev
;
4272 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
4274 if (abbrev_number
== 0)
4277 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4280 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4281 abbrev_number
, bfd_get_filename (abfd
));
4287 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4288 Returns a pointer to the end of a series of DIEs, terminated by an empty
4289 DIE. Any children of the skipped DIEs will also be skipped. */
4292 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
4294 struct abbrev_info
*abbrev
;
4295 unsigned int bytes_read
;
4299 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
4301 return info_ptr
+ bytes_read
;
4303 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
4307 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4308 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4309 abbrev corresponding to that skipped uleb128 should be passed in
4310 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4314 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4315 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
4317 unsigned int bytes_read
;
4318 struct attribute attr
;
4319 bfd
*abfd
= cu
->objfile
->obfd
;
4320 unsigned int form
, i
;
4322 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
4324 /* The only abbrev we care about is DW_AT_sibling. */
4325 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
4327 read_attribute (&attr
, &abbrev
->attrs
[i
],
4328 abfd
, info_ptr
, cu
);
4329 if (attr
.form
== DW_FORM_ref_addr
)
4330 complaint (&symfile_complaints
,
4331 _("ignoring absolute DW_AT_sibling"));
4333 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
4336 /* If it isn't DW_AT_sibling, skip this attribute. */
4337 form
= abbrev
->attrs
[i
].form
;
4341 case DW_FORM_ref_addr
:
4342 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4343 and later it is offset sized. */
4344 if (cu
->header
.version
== 2)
4345 info_ptr
+= cu
->header
.addr_size
;
4347 info_ptr
+= cu
->header
.offset_size
;
4350 info_ptr
+= cu
->header
.addr_size
;
4357 case DW_FORM_flag_present
:
4369 case DW_FORM_ref_sig8
:
4372 case DW_FORM_string
:
4373 read_direct_string (abfd
, info_ptr
, &bytes_read
);
4374 info_ptr
+= bytes_read
;
4376 case DW_FORM_sec_offset
:
4378 info_ptr
+= cu
->header
.offset_size
;
4380 case DW_FORM_exprloc
:
4382 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4383 info_ptr
+= bytes_read
;
4385 case DW_FORM_block1
:
4386 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
4388 case DW_FORM_block2
:
4389 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
4391 case DW_FORM_block4
:
4392 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
4396 case DW_FORM_ref_udata
:
4397 info_ptr
= skip_leb128 (abfd
, info_ptr
);
4399 case DW_FORM_indirect
:
4400 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4401 info_ptr
+= bytes_read
;
4402 /* We need to continue parsing from here, so just go back to
4404 goto skip_attribute
;
4407 error (_("Dwarf Error: Cannot handle %s "
4408 "in DWARF reader [in module %s]"),
4409 dwarf_form_name (form
),
4410 bfd_get_filename (abfd
));
4414 if (abbrev
->has_children
)
4415 return skip_children (buffer
, info_ptr
, cu
);
4420 /* Locate ORIG_PDI's sibling.
4421 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4425 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
4426 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4427 bfd
*abfd
, struct dwarf2_cu
*cu
)
4429 /* Do we know the sibling already? */
4431 if (orig_pdi
->sibling
)
4432 return orig_pdi
->sibling
;
4434 /* Are there any children to deal with? */
4436 if (!orig_pdi
->has_children
)
4439 /* Skip the children the long way. */
4441 return skip_children (buffer
, info_ptr
, cu
);
4444 /* Expand this partial symbol table into a full symbol table. */
4447 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
4453 warning (_("bug: psymtab for %s is already read in."),
4460 printf_filtered (_("Reading in symbols for %s..."),
4462 gdb_flush (gdb_stdout
);
4465 /* Restore our global data. */
4466 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
4467 dwarf2_objfile_data_key
);
4469 /* If this psymtab is constructed from a debug-only objfile, the
4470 has_section_at_zero flag will not necessarily be correct. We
4471 can get the correct value for this flag by looking at the data
4472 associated with the (presumably stripped) associated objfile. */
4473 if (pst
->objfile
->separate_debug_objfile_backlink
)
4475 struct dwarf2_per_objfile
*dpo_backlink
4476 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
4477 dwarf2_objfile_data_key
);
4479 dwarf2_per_objfile
->has_section_at_zero
4480 = dpo_backlink
->has_section_at_zero
;
4483 dwarf2_per_objfile
->reading_partial_symbols
= 0;
4485 psymtab_to_symtab_1 (pst
);
4487 /* Finish up the debug error message. */
4489 printf_filtered (_("done.\n"));
4494 /* Add PER_CU to the queue. */
4497 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
4499 struct dwarf2_queue_item
*item
;
4502 item
= xmalloc (sizeof (*item
));
4503 item
->per_cu
= per_cu
;
4506 if (dwarf2_queue
== NULL
)
4507 dwarf2_queue
= item
;
4509 dwarf2_queue_tail
->next
= item
;
4511 dwarf2_queue_tail
= item
;
4514 /* Process the queue. */
4517 process_queue (struct objfile
*objfile
)
4519 struct dwarf2_queue_item
*item
, *next_item
;
4521 /* The queue starts out with one item, but following a DIE reference
4522 may load a new CU, adding it to the end of the queue. */
4523 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
4525 if (dwarf2_per_objfile
->using_index
4526 ? !item
->per_cu
->v
.quick
->symtab
4527 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
4528 process_full_comp_unit (item
->per_cu
);
4530 item
->per_cu
->queued
= 0;
4531 next_item
= item
->next
;
4535 dwarf2_queue_tail
= NULL
;
4538 /* Free all allocated queue entries. This function only releases anything if
4539 an error was thrown; if the queue was processed then it would have been
4540 freed as we went along. */
4543 dwarf2_release_queue (void *dummy
)
4545 struct dwarf2_queue_item
*item
, *last
;
4547 item
= dwarf2_queue
;
4550 /* Anything still marked queued is likely to be in an
4551 inconsistent state, so discard it. */
4552 if (item
->per_cu
->queued
)
4554 if (item
->per_cu
->cu
!= NULL
)
4555 free_one_cached_comp_unit (item
->per_cu
->cu
);
4556 item
->per_cu
->queued
= 0;
4564 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
4567 /* Read in full symbols for PST, and anything it depends on. */
4570 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
4572 struct dwarf2_per_cu_data
*per_cu
;
4573 struct cleanup
*back_to
;
4576 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
4577 if (!pst
->dependencies
[i
]->readin
)
4579 /* Inform about additional files that need to be read in. */
4582 /* FIXME: i18n: Need to make this a single string. */
4583 fputs_filtered (" ", gdb_stdout
);
4585 fputs_filtered ("and ", gdb_stdout
);
4587 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
4588 wrap_here (""); /* Flush output. */
4589 gdb_flush (gdb_stdout
);
4591 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
4594 per_cu
= pst
->read_symtab_private
;
4598 /* It's an include file, no symbols to read for it.
4599 Everything is in the parent symtab. */
4604 dw2_do_instantiate_symtab (pst
->objfile
, per_cu
);
4607 /* Load the DIEs associated with PER_CU into memory. */
4610 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
4611 struct objfile
*objfile
)
4613 bfd
*abfd
= objfile
->obfd
;
4614 struct dwarf2_cu
*cu
;
4615 unsigned int offset
;
4616 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
4617 struct cleanup
*free_abbrevs_cleanup
= NULL
, *free_cu_cleanup
= NULL
;
4618 struct attribute
*attr
;
4621 gdb_assert (! per_cu
->debug_type_section
);
4623 /* Set local variables from the partial symbol table info. */
4624 offset
= per_cu
->offset
;
4626 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4627 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
4628 beg_of_comp_unit
= info_ptr
;
4630 if (per_cu
->cu
== NULL
)
4632 cu
= xmalloc (sizeof (*cu
));
4633 init_one_comp_unit (cu
, objfile
);
4637 /* If an error occurs while loading, release our storage. */
4638 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
4640 /* Read in the comp_unit header. */
4641 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
4643 /* Complete the cu_header. */
4644 cu
->header
.offset
= offset
;
4645 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
4647 /* Read the abbrevs for this compilation unit. */
4648 dwarf2_read_abbrevs (abfd
, cu
);
4649 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
4651 /* Link this compilation unit into the compilation unit tree. */
4653 cu
->per_cu
= per_cu
;
4655 /* Link this CU into read_in_chain. */
4656 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4657 dwarf2_per_objfile
->read_in_chain
= per_cu
;
4662 info_ptr
+= cu
->header
.first_die_offset
;
4665 cu
->dies
= read_comp_unit (info_ptr
, cu
);
4667 /* We try not to read any attributes in this function, because not
4668 all objfiles needed for references have been loaded yet, and symbol
4669 table processing isn't initialized. But we have to set the CU language,
4670 or we won't be able to build types correctly. */
4671 prepare_one_comp_unit (cu
, cu
->dies
);
4673 /* Similarly, if we do not read the producer, we can not apply
4674 producer-specific interpretation. */
4675 attr
= dwarf2_attr (cu
->dies
, DW_AT_producer
, cu
);
4677 cu
->producer
= DW_STRING (attr
);
4681 do_cleanups (free_abbrevs_cleanup
);
4683 /* We've successfully allocated this compilation unit. Let our
4684 caller clean it up when finished with it. */
4685 discard_cleanups (free_cu_cleanup
);
4689 /* Add a DIE to the delayed physname list. */
4692 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
4693 const char *name
, struct die_info
*die
,
4694 struct dwarf2_cu
*cu
)
4696 struct delayed_method_info mi
;
4698 mi
.fnfield_index
= fnfield_index
;
4702 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
4705 /* A cleanup for freeing the delayed method list. */
4708 free_delayed_list (void *ptr
)
4710 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
4711 if (cu
->method_list
!= NULL
)
4713 VEC_free (delayed_method_info
, cu
->method_list
);
4714 cu
->method_list
= NULL
;
4718 /* Compute the physnames of any methods on the CU's method list.
4720 The computation of method physnames is delayed in order to avoid the
4721 (bad) condition that one of the method's formal parameters is of an as yet
4725 compute_delayed_physnames (struct dwarf2_cu
*cu
)
4728 struct delayed_method_info
*mi
;
4729 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
4731 const char *physname
;
4732 struct fn_fieldlist
*fn_flp
4733 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
4734 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
4735 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
4739 /* Generate full symbol information for PST and CU, whose DIEs have
4740 already been loaded into memory. */
4743 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4745 struct dwarf2_cu
*cu
= per_cu
->cu
;
4746 struct objfile
*objfile
= per_cu
->objfile
;
4747 CORE_ADDR lowpc
, highpc
;
4748 struct symtab
*symtab
;
4749 struct cleanup
*back_to
, *delayed_list_cleanup
;
4752 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4755 back_to
= make_cleanup (really_free_pendings
, NULL
);
4756 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
4758 cu
->list_in_scope
= &file_symbols
;
4760 /* Do line number decoding in read_file_scope () */
4761 process_die (cu
->dies
, cu
);
4763 /* Now that we have processed all the DIEs in the CU, all the types
4764 should be complete, and it should now be safe to compute all of the
4766 compute_delayed_physnames (cu
);
4767 do_cleanups (delayed_list_cleanup
);
4769 /* Some compilers don't define a DW_AT_high_pc attribute for the
4770 compilation unit. If the DW_AT_high_pc is missing, synthesize
4771 it, by scanning the DIE's below the compilation unit. */
4772 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
4774 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
4778 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
4780 /* Set symtab language to language from DW_AT_language. If the
4781 compilation is from a C file generated by language preprocessors, do
4782 not set the language if it was already deduced by start_subfile. */
4783 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
4784 symtab
->language
= cu
->language
;
4786 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
4787 produce DW_AT_location with location lists but it can be possibly
4788 invalid without -fvar-tracking.
4790 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
4791 needed, it would be wrong due to missing DW_AT_producer there.
4793 Still one can confuse GDB by using non-standard GCC compilation
4794 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
4796 if (cu
->has_loclist
&& gcc_4_minor
>= 0)
4797 symtab
->locations_valid
= 1;
4799 if (gcc_4_minor
>= 5)
4800 symtab
->epilogue_unwind_valid
= 1;
4802 symtab
->call_site_htab
= cu
->call_site_htab
;
4805 if (dwarf2_per_objfile
->using_index
)
4806 per_cu
->v
.quick
->symtab
= symtab
;
4809 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4810 pst
->symtab
= symtab
;
4814 do_cleanups (back_to
);
4817 /* Process a die and its children. */
4820 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
4824 case DW_TAG_padding
:
4826 case DW_TAG_compile_unit
:
4827 read_file_scope (die
, cu
);
4829 case DW_TAG_type_unit
:
4830 read_type_unit_scope (die
, cu
);
4832 case DW_TAG_subprogram
:
4833 case DW_TAG_inlined_subroutine
:
4834 read_func_scope (die
, cu
);
4836 case DW_TAG_lexical_block
:
4837 case DW_TAG_try_block
:
4838 case DW_TAG_catch_block
:
4839 read_lexical_block_scope (die
, cu
);
4841 case DW_TAG_GNU_call_site
:
4842 read_call_site_scope (die
, cu
);
4844 case DW_TAG_class_type
:
4845 case DW_TAG_interface_type
:
4846 case DW_TAG_structure_type
:
4847 case DW_TAG_union_type
:
4848 process_structure_scope (die
, cu
);
4850 case DW_TAG_enumeration_type
:
4851 process_enumeration_scope (die
, cu
);
4854 /* These dies have a type, but processing them does not create
4855 a symbol or recurse to process the children. Therefore we can
4856 read them on-demand through read_type_die. */
4857 case DW_TAG_subroutine_type
:
4858 case DW_TAG_set_type
:
4859 case DW_TAG_array_type
:
4860 case DW_TAG_pointer_type
:
4861 case DW_TAG_ptr_to_member_type
:
4862 case DW_TAG_reference_type
:
4863 case DW_TAG_string_type
:
4866 case DW_TAG_base_type
:
4867 case DW_TAG_subrange_type
:
4868 case DW_TAG_typedef
:
4869 /* Add a typedef symbol for the type definition, if it has a
4871 new_symbol (die
, read_type_die (die
, cu
), cu
);
4873 case DW_TAG_common_block
:
4874 read_common_block (die
, cu
);
4876 case DW_TAG_common_inclusion
:
4878 case DW_TAG_namespace
:
4879 processing_has_namespace_info
= 1;
4880 read_namespace (die
, cu
);
4883 processing_has_namespace_info
= 1;
4884 read_module (die
, cu
);
4886 case DW_TAG_imported_declaration
:
4887 case DW_TAG_imported_module
:
4888 processing_has_namespace_info
= 1;
4889 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
4890 || cu
->language
!= language_fortran
))
4891 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
4892 dwarf_tag_name (die
->tag
));
4893 read_import_statement (die
, cu
);
4896 new_symbol (die
, NULL
, cu
);
4901 /* A helper function for dwarf2_compute_name which determines whether DIE
4902 needs to have the name of the scope prepended to the name listed in the
4906 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4908 struct attribute
*attr
;
4912 case DW_TAG_namespace
:
4913 case DW_TAG_typedef
:
4914 case DW_TAG_class_type
:
4915 case DW_TAG_interface_type
:
4916 case DW_TAG_structure_type
:
4917 case DW_TAG_union_type
:
4918 case DW_TAG_enumeration_type
:
4919 case DW_TAG_enumerator
:
4920 case DW_TAG_subprogram
:
4924 case DW_TAG_variable
:
4925 case DW_TAG_constant
:
4926 /* We only need to prefix "globally" visible variables. These include
4927 any variable marked with DW_AT_external or any variable that
4928 lives in a namespace. [Variables in anonymous namespaces
4929 require prefixing, but they are not DW_AT_external.] */
4931 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
4933 struct dwarf2_cu
*spec_cu
= cu
;
4935 return die_needs_namespace (die_specification (die
, &spec_cu
),
4939 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
4940 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
4941 && die
->parent
->tag
!= DW_TAG_module
)
4943 /* A variable in a lexical block of some kind does not need a
4944 namespace, even though in C++ such variables may be external
4945 and have a mangled name. */
4946 if (die
->parent
->tag
== DW_TAG_lexical_block
4947 || die
->parent
->tag
== DW_TAG_try_block
4948 || die
->parent
->tag
== DW_TAG_catch_block
4949 || die
->parent
->tag
== DW_TAG_subprogram
)
4958 /* Retrieve the last character from a mem_file. */
4961 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
4963 char *last_char_p
= (char *) object
;
4966 *last_char_p
= buffer
[length
- 1];
4969 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
4970 compute the physname for the object, which include a method's
4971 formal parameters (C++/Java) and return type (Java).
4973 For Ada, return the DIE's linkage name rather than the fully qualified
4974 name. PHYSNAME is ignored..
4976 The result is allocated on the objfile_obstack and canonicalized. */
4979 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
4983 name
= dwarf2_name (die
, cu
);
4985 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
4986 compute it by typename_concat inside GDB. */
4987 if (cu
->language
== language_ada
4988 || (cu
->language
== language_fortran
&& physname
))
4990 /* For Ada unit, we prefer the linkage name over the name, as
4991 the former contains the exported name, which the user expects
4992 to be able to reference. Ideally, we want the user to be able
4993 to reference this entity using either natural or linkage name,
4994 but we haven't started looking at this enhancement yet. */
4995 struct attribute
*attr
;
4997 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
4999 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5000 if (attr
&& DW_STRING (attr
))
5001 return DW_STRING (attr
);
5004 /* These are the only languages we know how to qualify names in. */
5006 && (cu
->language
== language_cplus
|| cu
->language
== language_java
5007 || cu
->language
== language_fortran
))
5009 if (die_needs_namespace (die
, cu
))
5013 struct ui_file
*buf
;
5015 prefix
= determine_prefix (die
, cu
);
5016 buf
= mem_fileopen ();
5017 if (*prefix
!= '\0')
5019 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
5022 fputs_unfiltered (prefixed_name
, buf
);
5023 xfree (prefixed_name
);
5026 fputs_unfiltered (name
, buf
);
5028 /* Template parameters may be specified in the DIE's DW_AT_name, or
5029 as children with DW_TAG_template_type_param or
5030 DW_TAG_value_type_param. If the latter, add them to the name
5031 here. If the name already has template parameters, then
5032 skip this step; some versions of GCC emit both, and
5033 it is more efficient to use the pre-computed name.
5035 Something to keep in mind about this process: it is very
5036 unlikely, or in some cases downright impossible, to produce
5037 something that will match the mangled name of a function.
5038 If the definition of the function has the same debug info,
5039 we should be able to match up with it anyway. But fallbacks
5040 using the minimal symbol, for instance to find a method
5041 implemented in a stripped copy of libstdc++, will not work.
5042 If we do not have debug info for the definition, we will have to
5043 match them up some other way.
5045 When we do name matching there is a related problem with function
5046 templates; two instantiated function templates are allowed to
5047 differ only by their return types, which we do not add here. */
5049 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
5051 struct attribute
*attr
;
5052 struct die_info
*child
;
5055 die
->building_fullname
= 1;
5057 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
5062 struct dwarf2_locexpr_baton
*baton
;
5065 if (child
->tag
!= DW_TAG_template_type_param
5066 && child
->tag
!= DW_TAG_template_value_param
)
5071 fputs_unfiltered ("<", buf
);
5075 fputs_unfiltered (", ", buf
);
5077 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
5080 complaint (&symfile_complaints
,
5081 _("template parameter missing DW_AT_type"));
5082 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
5085 type
= die_type (child
, cu
);
5087 if (child
->tag
== DW_TAG_template_type_param
)
5089 c_print_type (type
, "", buf
, -1, 0);
5093 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
5096 complaint (&symfile_complaints
,
5097 _("template parameter missing "
5098 "DW_AT_const_value"));
5099 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
5103 dwarf2_const_value_attr (attr
, type
, name
,
5104 &cu
->comp_unit_obstack
, cu
,
5105 &value
, &bytes
, &baton
);
5107 if (TYPE_NOSIGN (type
))
5108 /* GDB prints characters as NUMBER 'CHAR'. If that's
5109 changed, this can use value_print instead. */
5110 c_printchar (value
, type
, buf
);
5113 struct value_print_options opts
;
5116 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
5120 else if (bytes
!= NULL
)
5122 v
= allocate_value (type
);
5123 memcpy (value_contents_writeable (v
), bytes
,
5124 TYPE_LENGTH (type
));
5127 v
= value_from_longest (type
, value
);
5129 /* Specify decimal so that we do not depend on
5131 get_formatted_print_options (&opts
, 'd');
5133 value_print (v
, buf
, &opts
);
5139 die
->building_fullname
= 0;
5143 /* Close the argument list, with a space if necessary
5144 (nested templates). */
5145 char last_char
= '\0';
5146 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
5147 if (last_char
== '>')
5148 fputs_unfiltered (" >", buf
);
5150 fputs_unfiltered (">", buf
);
5154 /* For Java and C++ methods, append formal parameter type
5155 information, if PHYSNAME. */
5157 if (physname
&& die
->tag
== DW_TAG_subprogram
5158 && (cu
->language
== language_cplus
5159 || cu
->language
== language_java
))
5161 struct type
*type
= read_type_die (die
, cu
);
5163 c_type_print_args (type
, buf
, 1, cu
->language
);
5165 if (cu
->language
== language_java
)
5167 /* For java, we must append the return type to method
5169 if (die
->tag
== DW_TAG_subprogram
)
5170 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
5173 else if (cu
->language
== language_cplus
)
5175 /* Assume that an artificial first parameter is
5176 "this", but do not crash if it is not. RealView
5177 marks unnamed (and thus unused) parameters as
5178 artificial; there is no way to differentiate
5180 if (TYPE_NFIELDS (type
) > 0
5181 && TYPE_FIELD_ARTIFICIAL (type
, 0)
5182 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
5183 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
5185 fputs_unfiltered (" const", buf
);
5189 name
= ui_file_obsavestring (buf
, &cu
->objfile
->objfile_obstack
,
5191 ui_file_delete (buf
);
5193 if (cu
->language
== language_cplus
)
5196 = dwarf2_canonicalize_name (name
, cu
,
5197 &cu
->objfile
->objfile_obstack
);
5208 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5209 If scope qualifiers are appropriate they will be added. The result
5210 will be allocated on the objfile_obstack, or NULL if the DIE does
5211 not have a name. NAME may either be from a previous call to
5212 dwarf2_name or NULL.
5214 The output string will be canonicalized (if C++/Java). */
5217 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5219 return dwarf2_compute_name (name
, die
, cu
, 0);
5222 /* Construct a physname for the given DIE in CU. NAME may either be
5223 from a previous call to dwarf2_name or NULL. The result will be
5224 allocated on the objfile_objstack or NULL if the DIE does not have a
5227 The output string will be canonicalized (if C++/Java). */
5230 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5232 struct attribute
*attr
;
5233 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
5234 struct cleanup
*back_to
;
5237 /* In this case dwarf2_compute_name is just a shortcut not building anything
5239 if (!die_needs_namespace (die
, cu
))
5240 return dwarf2_compute_name (name
, die
, cu
, 1);
5242 back_to
= make_cleanup (null_cleanup
, NULL
);
5244 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5246 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5248 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
5250 if (attr
&& DW_STRING (attr
))
5254 mangled
= DW_STRING (attr
);
5256 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
5257 type. It is easier for GDB users to search for such functions as
5258 `name(params)' than `long name(params)'. In such case the minimal
5259 symbol names do not match the full symbol names but for template
5260 functions there is never a need to look up their definition from their
5261 declaration so the only disadvantage remains the minimal symbol
5262 variant `long name(params)' does not have the proper inferior type.
5265 demangled
= cplus_demangle (mangled
, (DMGL_PARAMS
| DMGL_ANSI
5266 | (cu
->language
== language_java
5267 ? DMGL_JAVA
| DMGL_RET_POSTFIX
5271 make_cleanup (xfree
, demangled
);
5281 if (canon
== NULL
|| check_physname
)
5283 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
5285 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
5287 /* It may not mean a bug in GDB. The compiler could also
5288 compute DW_AT_linkage_name incorrectly. But in such case
5289 GDB would need to be bug-to-bug compatible. */
5291 complaint (&symfile_complaints
,
5292 _("Computed physname <%s> does not match demangled <%s> "
5293 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
5294 physname
, canon
, mangled
, die
->offset
, cu
->objfile
->name
);
5296 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
5297 is available here - over computed PHYSNAME. It is safer
5298 against both buggy GDB and buggy compilers. */
5312 retval
= obsavestring (retval
, strlen (retval
),
5313 &cu
->objfile
->objfile_obstack
);
5315 do_cleanups (back_to
);
5319 /* Read the import statement specified by the given die and record it. */
5322 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
5324 struct attribute
*import_attr
;
5325 struct die_info
*imported_die
, *child_die
;
5326 struct dwarf2_cu
*imported_cu
;
5327 const char *imported_name
;
5328 const char *imported_name_prefix
;
5329 const char *canonical_name
;
5330 const char *import_alias
;
5331 const char *imported_declaration
= NULL
;
5332 const char *import_prefix
;
5333 VEC (const_char_ptr
) *excludes
= NULL
;
5334 struct cleanup
*cleanups
;
5338 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
5339 if (import_attr
== NULL
)
5341 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5342 dwarf_tag_name (die
->tag
));
5347 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
5348 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5349 if (imported_name
== NULL
)
5351 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
5353 The import in the following code:
5367 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
5368 <52> DW_AT_decl_file : 1
5369 <53> DW_AT_decl_line : 6
5370 <54> DW_AT_import : <0x75>
5371 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
5373 <5b> DW_AT_decl_file : 1
5374 <5c> DW_AT_decl_line : 2
5375 <5d> DW_AT_type : <0x6e>
5377 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
5378 <76> DW_AT_byte_size : 4
5379 <77> DW_AT_encoding : 5 (signed)
5381 imports the wrong die ( 0x75 instead of 0x58 ).
5382 This case will be ignored until the gcc bug is fixed. */
5386 /* Figure out the local name after import. */
5387 import_alias
= dwarf2_name (die
, cu
);
5389 /* Figure out where the statement is being imported to. */
5390 import_prefix
= determine_prefix (die
, cu
);
5392 /* Figure out what the scope of the imported die is and prepend it
5393 to the name of the imported die. */
5394 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
5396 if (imported_die
->tag
!= DW_TAG_namespace
5397 && imported_die
->tag
!= DW_TAG_module
)
5399 imported_declaration
= imported_name
;
5400 canonical_name
= imported_name_prefix
;
5402 else if (strlen (imported_name_prefix
) > 0)
5404 temp
= alloca (strlen (imported_name_prefix
)
5405 + 2 + strlen (imported_name
) + 1);
5406 strcpy (temp
, imported_name_prefix
);
5407 strcat (temp
, "::");
5408 strcat (temp
, imported_name
);
5409 canonical_name
= temp
;
5412 canonical_name
= imported_name
;
5414 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
5416 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
5417 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
5418 child_die
= sibling_die (child_die
))
5420 /* DWARF-4: A Fortran use statement with a “rename list” may be
5421 represented by an imported module entry with an import attribute
5422 referring to the module and owned entries corresponding to those
5423 entities that are renamed as part of being imported. */
5425 if (child_die
->tag
!= DW_TAG_imported_declaration
)
5427 complaint (&symfile_complaints
,
5428 _("child DW_TAG_imported_declaration expected "
5429 "- DIE at 0x%x [in module %s]"),
5430 child_die
->offset
, cu
->objfile
->name
);
5434 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
5435 if (import_attr
== NULL
)
5437 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5438 dwarf_tag_name (child_die
->tag
));
5443 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
5445 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5446 if (imported_name
== NULL
)
5448 complaint (&symfile_complaints
,
5449 _("child DW_TAG_imported_declaration has unknown "
5450 "imported name - DIE at 0x%x [in module %s]"),
5451 child_die
->offset
, cu
->objfile
->name
);
5455 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
5457 process_die (child_die
, cu
);
5460 cp_add_using_directive (import_prefix
,
5463 imported_declaration
,
5465 &cu
->objfile
->objfile_obstack
);
5467 do_cleanups (cleanups
);
5471 initialize_cu_func_list (struct dwarf2_cu
*cu
)
5473 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
5476 /* Cleanup function for read_file_scope. */
5479 free_cu_line_header (void *arg
)
5481 struct dwarf2_cu
*cu
= arg
;
5483 free_line_header (cu
->line_header
);
5484 cu
->line_header
= NULL
;
5488 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
5489 char **name
, char **comp_dir
)
5491 struct attribute
*attr
;
5496 /* Find the filename. Do not use dwarf2_name here, since the filename
5497 is not a source language identifier. */
5498 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5501 *name
= DW_STRING (attr
);
5504 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5506 *comp_dir
= DW_STRING (attr
);
5507 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
5509 *comp_dir
= ldirname (*name
);
5510 if (*comp_dir
!= NULL
)
5511 make_cleanup (xfree
, *comp_dir
);
5513 if (*comp_dir
!= NULL
)
5515 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5516 directory, get rid of it. */
5517 char *cp
= strchr (*comp_dir
, ':');
5519 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
5524 *name
= "<unknown>";
5527 /* Handle DW_AT_stmt_list for a compilation unit. */
5530 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
5531 const char *comp_dir
)
5533 struct attribute
*attr
;
5534 struct objfile
*objfile
= cu
->objfile
;
5535 bfd
*abfd
= objfile
->obfd
;
5537 /* Decode line number information if present. We do this before
5538 processing child DIEs, so that the line header table is available
5539 for DW_AT_decl_file. */
5540 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5543 unsigned int line_offset
= DW_UNSND (attr
);
5544 struct line_header
*line_header
5545 = dwarf_decode_line_header (line_offset
, abfd
, cu
);
5549 cu
->line_header
= line_header
;
5550 make_cleanup (free_cu_line_header
, cu
);
5551 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
5556 /* Process DW_TAG_compile_unit. */
5559 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5561 struct objfile
*objfile
= cu
->objfile
;
5562 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5563 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
5564 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
5565 struct attribute
*attr
;
5567 char *comp_dir
= NULL
;
5568 struct die_info
*child_die
;
5569 bfd
*abfd
= objfile
->obfd
;
5572 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5574 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
5576 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5577 from finish_block. */
5578 if (lowpc
== ((CORE_ADDR
) -1))
5583 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
5585 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5588 set_cu_language (DW_UNSND (attr
), cu
);
5591 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5593 cu
->producer
= DW_STRING (attr
);
5595 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
5596 standardised yet. As a workaround for the language detection we fall
5597 back to the DW_AT_producer string. */
5598 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
5599 cu
->language
= language_opencl
;
5601 /* We assume that we're processing GCC output. */
5602 processing_gcc_compilation
= 2;
5604 processing_has_namespace_info
= 0;
5606 start_symtab (name
, comp_dir
, lowpc
);
5607 record_debugformat ("DWARF 2");
5608 record_producer (cu
->producer
);
5610 initialize_cu_func_list (cu
);
5612 handle_DW_AT_stmt_list (die
, cu
, comp_dir
);
5614 /* Process all dies in compilation unit. */
5615 if (die
->child
!= NULL
)
5617 child_die
= die
->child
;
5618 while (child_die
&& child_die
->tag
)
5620 process_die (child_die
, cu
);
5621 child_die
= sibling_die (child_die
);
5625 /* Decode macro information, if present. Dwarf 2 macro information
5626 refers to information in the line number info statement program
5627 header, so we can only read it if we've read the header
5629 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
5630 if (attr
&& cu
->line_header
)
5632 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
5633 complaint (&symfile_complaints
,
5634 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
5636 dwarf_decode_macros (cu
->line_header
, DW_UNSND (attr
),
5638 &dwarf2_per_objfile
->macro
, 1);
5642 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
5643 if (attr
&& cu
->line_header
)
5645 unsigned int macro_offset
= DW_UNSND (attr
);
5647 dwarf_decode_macros (cu
->line_header
, macro_offset
,
5649 &dwarf2_per_objfile
->macinfo
, 0);
5652 do_cleanups (back_to
);
5655 /* Process DW_TAG_type_unit.
5656 For TUs we want to skip the first top level sibling if it's not the
5657 actual type being defined by this TU. In this case the first top
5658 level sibling is there to provide context only. */
5661 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5663 struct objfile
*objfile
= cu
->objfile
;
5664 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5666 struct attribute
*attr
;
5668 char *comp_dir
= NULL
;
5669 struct die_info
*child_die
;
5670 bfd
*abfd
= objfile
->obfd
;
5672 /* start_symtab needs a low pc, but we don't really have one.
5673 Do what read_file_scope would do in the absence of such info. */
5674 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5676 /* Find the filename. Do not use dwarf2_name here, since the filename
5677 is not a source language identifier. */
5678 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5680 name
= DW_STRING (attr
);
5682 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5684 comp_dir
= DW_STRING (attr
);
5685 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
5687 comp_dir
= ldirname (name
);
5688 if (comp_dir
!= NULL
)
5689 make_cleanup (xfree
, comp_dir
);
5695 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5697 set_cu_language (DW_UNSND (attr
), cu
);
5699 /* This isn't technically needed today. It is done for symmetry
5700 with read_file_scope. */
5701 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5703 cu
->producer
= DW_STRING (attr
);
5705 /* We assume that we're processing GCC output. */
5706 processing_gcc_compilation
= 2;
5708 processing_has_namespace_info
= 0;
5710 start_symtab (name
, comp_dir
, lowpc
);
5711 record_debugformat ("DWARF 2");
5712 record_producer (cu
->producer
);
5714 handle_DW_AT_stmt_list (die
, cu
, comp_dir
);
5716 /* Process the dies in the type unit. */
5717 if (die
->child
== NULL
)
5719 dump_die_for_error (die
);
5720 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5721 bfd_get_filename (abfd
));
5724 child_die
= die
->child
;
5726 while (child_die
&& child_die
->tag
)
5728 process_die (child_die
, cu
);
5730 child_die
= sibling_die (child_die
);
5733 do_cleanups (back_to
);
5737 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
5738 struct dwarf2_cu
*cu
)
5740 struct function_range
*thisfn
;
5742 thisfn
= (struct function_range
*)
5743 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
5744 thisfn
->name
= name
;
5745 thisfn
->lowpc
= lowpc
;
5746 thisfn
->highpc
= highpc
;
5747 thisfn
->seen_line
= 0;
5748 thisfn
->next
= NULL
;
5750 if (cu
->last_fn
== NULL
)
5751 cu
->first_fn
= thisfn
;
5753 cu
->last_fn
->next
= thisfn
;
5755 cu
->last_fn
= thisfn
;
5758 /* qsort helper for inherit_abstract_dies. */
5761 unsigned_int_compar (const void *ap
, const void *bp
)
5763 unsigned int a
= *(unsigned int *) ap
;
5764 unsigned int b
= *(unsigned int *) bp
;
5766 return (a
> b
) - (b
> a
);
5769 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5770 Inherit only the children of the DW_AT_abstract_origin DIE not being
5771 already referenced by DW_AT_abstract_origin from the children of the
5775 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
5777 struct die_info
*child_die
;
5778 unsigned die_children_count
;
5779 /* CU offsets which were referenced by children of the current DIE. */
5781 unsigned *offsets_end
, *offsetp
;
5782 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5783 struct die_info
*origin_die
;
5784 /* Iterator of the ORIGIN_DIE children. */
5785 struct die_info
*origin_child_die
;
5786 struct cleanup
*cleanups
;
5787 struct attribute
*attr
;
5788 struct dwarf2_cu
*origin_cu
;
5789 struct pending
**origin_previous_list_in_scope
;
5791 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
5795 /* Note that following die references may follow to a die in a
5799 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
5801 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5803 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
5804 origin_cu
->list_in_scope
= cu
->list_in_scope
;
5806 if (die
->tag
!= origin_die
->tag
5807 && !(die
->tag
== DW_TAG_inlined_subroutine
5808 && origin_die
->tag
== DW_TAG_subprogram
))
5809 complaint (&symfile_complaints
,
5810 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5811 die
->offset
, origin_die
->offset
);
5813 child_die
= die
->child
;
5814 die_children_count
= 0;
5815 while (child_die
&& child_die
->tag
)
5817 child_die
= sibling_die (child_die
);
5818 die_children_count
++;
5820 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
5821 cleanups
= make_cleanup (xfree
, offsets
);
5823 offsets_end
= offsets
;
5824 child_die
= die
->child
;
5825 while (child_die
&& child_die
->tag
)
5827 /* For each CHILD_DIE, find the corresponding child of
5828 ORIGIN_DIE. If there is more than one layer of
5829 DW_AT_abstract_origin, follow them all; there shouldn't be,
5830 but GCC versions at least through 4.4 generate this (GCC PR
5832 struct die_info
*child_origin_die
= child_die
;
5833 struct dwarf2_cu
*child_origin_cu
= cu
;
5837 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
5841 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
5845 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5846 counterpart may exist. */
5847 if (child_origin_die
!= child_die
)
5849 if (child_die
->tag
!= child_origin_die
->tag
5850 && !(child_die
->tag
== DW_TAG_inlined_subroutine
5851 && child_origin_die
->tag
== DW_TAG_subprogram
))
5852 complaint (&symfile_complaints
,
5853 _("Child DIE 0x%x and its abstract origin 0x%x have "
5854 "different tags"), child_die
->offset
,
5855 child_origin_die
->offset
);
5856 if (child_origin_die
->parent
!= origin_die
)
5857 complaint (&symfile_complaints
,
5858 _("Child DIE 0x%x and its abstract origin 0x%x have "
5859 "different parents"), child_die
->offset
,
5860 child_origin_die
->offset
);
5862 *offsets_end
++ = child_origin_die
->offset
;
5864 child_die
= sibling_die (child_die
);
5866 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
5867 unsigned_int_compar
);
5868 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
5869 if (offsetp
[-1] == *offsetp
)
5870 complaint (&symfile_complaints
,
5871 _("Multiple children of DIE 0x%x refer "
5872 "to DIE 0x%x as their abstract origin"),
5873 die
->offset
, *offsetp
);
5876 origin_child_die
= origin_die
->child
;
5877 while (origin_child_die
&& origin_child_die
->tag
)
5879 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5880 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
5882 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
5884 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5885 process_die (origin_child_die
, origin_cu
);
5887 origin_child_die
= sibling_die (origin_child_die
);
5889 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
5891 do_cleanups (cleanups
);
5895 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5897 struct objfile
*objfile
= cu
->objfile
;
5898 struct context_stack
*new;
5901 struct die_info
*child_die
;
5902 struct attribute
*attr
, *call_line
, *call_file
;
5905 struct block
*block
;
5906 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
5907 VEC (symbolp
) *template_args
= NULL
;
5908 struct template_symbol
*templ_func
= NULL
;
5912 /* If we do not have call site information, we can't show the
5913 caller of this inlined function. That's too confusing, so
5914 only use the scope for local variables. */
5915 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
5916 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
5917 if (call_line
== NULL
|| call_file
== NULL
)
5919 read_lexical_block_scope (die
, cu
);
5924 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5926 name
= dwarf2_name (die
, cu
);
5928 /* Ignore functions with missing or empty names. These are actually
5929 illegal according to the DWARF standard. */
5932 complaint (&symfile_complaints
,
5933 _("missing name for subprogram DIE at %d"), die
->offset
);
5937 /* Ignore functions with missing or invalid low and high pc attributes. */
5938 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5940 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5941 if (!attr
|| !DW_UNSND (attr
))
5942 complaint (&symfile_complaints
,
5943 _("cannot get low and high bounds "
5944 "for subprogram DIE at %d"),
5952 /* Record the function range for dwarf_decode_lines. */
5953 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
5955 /* If we have any template arguments, then we must allocate a
5956 different sort of symbol. */
5957 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
5959 if (child_die
->tag
== DW_TAG_template_type_param
5960 || child_die
->tag
== DW_TAG_template_value_param
)
5962 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5963 struct template_symbol
);
5964 templ_func
->base
.is_cplus_template_function
= 1;
5969 new = push_context (0, lowpc
);
5970 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
5971 (struct symbol
*) templ_func
);
5973 /* If there is a location expression for DW_AT_frame_base, record
5975 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
5977 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
5978 expression is being recorded directly in the function's symbol
5979 and not in a separate frame-base object. I guess this hack is
5980 to avoid adding some sort of frame-base adjunct/annex to the
5981 function's symbol :-(. The problem with doing this is that it
5982 results in a function symbol with a location expression that
5983 has nothing to do with the location of the function, ouch! The
5984 relationship should be: a function's symbol has-a frame base; a
5985 frame-base has-a location expression. */
5986 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
5988 cu
->list_in_scope
= &local_symbols
;
5990 if (die
->child
!= NULL
)
5992 child_die
= die
->child
;
5993 while (child_die
&& child_die
->tag
)
5995 if (child_die
->tag
== DW_TAG_template_type_param
5996 || child_die
->tag
== DW_TAG_template_value_param
)
5998 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
6001 VEC_safe_push (symbolp
, template_args
, arg
);
6004 process_die (child_die
, cu
);
6005 child_die
= sibling_die (child_die
);
6009 inherit_abstract_dies (die
, cu
);
6011 /* If we have a DW_AT_specification, we might need to import using
6012 directives from the context of the specification DIE. See the
6013 comment in determine_prefix. */
6014 if (cu
->language
== language_cplus
6015 && dwarf2_attr (die
, DW_AT_specification
, cu
))
6017 struct dwarf2_cu
*spec_cu
= cu
;
6018 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
6022 child_die
= spec_die
->child
;
6023 while (child_die
&& child_die
->tag
)
6025 if (child_die
->tag
== DW_TAG_imported_module
)
6026 process_die (child_die
, spec_cu
);
6027 child_die
= sibling_die (child_die
);
6030 /* In some cases, GCC generates specification DIEs that
6031 themselves contain DW_AT_specification attributes. */
6032 spec_die
= die_specification (spec_die
, &spec_cu
);
6036 new = pop_context ();
6037 /* Make a block for the local symbols within. */
6038 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
6039 lowpc
, highpc
, objfile
);
6041 /* For C++, set the block's scope. */
6042 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
6043 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
6044 determine_prefix (die
, cu
),
6045 processing_has_namespace_info
);
6047 /* If we have address ranges, record them. */
6048 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
6050 /* Attach template arguments to function. */
6051 if (! VEC_empty (symbolp
, template_args
))
6053 gdb_assert (templ_func
!= NULL
);
6055 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
6056 templ_func
->template_arguments
6057 = obstack_alloc (&objfile
->objfile_obstack
,
6058 (templ_func
->n_template_arguments
6059 * sizeof (struct symbol
*)));
6060 memcpy (templ_func
->template_arguments
,
6061 VEC_address (symbolp
, template_args
),
6062 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
6063 VEC_free (symbolp
, template_args
);
6066 /* In C++, we can have functions nested inside functions (e.g., when
6067 a function declares a class that has methods). This means that
6068 when we finish processing a function scope, we may need to go
6069 back to building a containing block's symbol lists. */
6070 local_symbols
= new->locals
;
6071 param_symbols
= new->params
;
6072 using_directives
= new->using_directives
;
6074 /* If we've finished processing a top-level function, subsequent
6075 symbols go in the file symbol list. */
6076 if (outermost_context_p ())
6077 cu
->list_in_scope
= &file_symbols
;
6080 /* Process all the DIES contained within a lexical block scope. Start
6081 a new scope, process the dies, and then close the scope. */
6084 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6086 struct objfile
*objfile
= cu
->objfile
;
6087 struct context_stack
*new;
6088 CORE_ADDR lowpc
, highpc
;
6089 struct die_info
*child_die
;
6092 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6094 /* Ignore blocks with missing or invalid low and high pc attributes. */
6095 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
6096 as multiple lexical blocks? Handling children in a sane way would
6097 be nasty. Might be easier to properly extend generic blocks to
6099 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
6104 push_context (0, lowpc
);
6105 if (die
->child
!= NULL
)
6107 child_die
= die
->child
;
6108 while (child_die
&& child_die
->tag
)
6110 process_die (child_die
, cu
);
6111 child_die
= sibling_die (child_die
);
6114 new = pop_context ();
6116 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
6119 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
6122 /* Note that recording ranges after traversing children, as we
6123 do here, means that recording a parent's ranges entails
6124 walking across all its children's ranges as they appear in
6125 the address map, which is quadratic behavior.
6127 It would be nicer to record the parent's ranges before
6128 traversing its children, simply overriding whatever you find
6129 there. But since we don't even decide whether to create a
6130 block until after we've traversed its children, that's hard
6132 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
6134 local_symbols
= new->locals
;
6135 using_directives
= new->using_directives
;
6138 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
6141 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6143 struct objfile
*objfile
= cu
->objfile
;
6144 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6145 CORE_ADDR pc
, baseaddr
;
6146 struct attribute
*attr
;
6147 struct call_site
*call_site
, call_site_local
;
6150 struct die_info
*child_die
;
6152 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6154 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6157 complaint (&symfile_complaints
,
6158 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
6159 "DIE 0x%x [in module %s]"),
6160 die
->offset
, cu
->objfile
->name
);
6163 pc
= DW_ADDR (attr
) + baseaddr
;
6165 if (cu
->call_site_htab
== NULL
)
6166 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
6167 NULL
, &objfile
->objfile_obstack
,
6168 hashtab_obstack_allocate
, NULL
);
6169 call_site_local
.pc
= pc
;
6170 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
6173 complaint (&symfile_complaints
,
6174 _("Duplicate PC %s for DW_TAG_GNU_call_site "
6175 "DIE 0x%x [in module %s]"),
6176 paddress (gdbarch
, pc
), die
->offset
, cu
->objfile
->name
);
6180 /* Count parameters at the caller. */
6183 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
6184 child_die
= sibling_die (child_die
))
6186 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
6188 complaint (&symfile_complaints
,
6189 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
6190 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6191 child_die
->tag
, child_die
->offset
, cu
->objfile
->name
);
6198 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
6199 (sizeof (*call_site
)
6200 + (sizeof (*call_site
->parameter
)
6203 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
6206 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
6208 struct die_info
*func_die
;
6210 /* Skip also over DW_TAG_inlined_subroutine. */
6211 for (func_die
= die
->parent
;
6212 func_die
&& func_die
->tag
!= DW_TAG_subprogram
6213 && func_die
->tag
!= DW_TAG_subroutine_type
;
6214 func_die
= func_die
->parent
);
6216 /* DW_AT_GNU_all_call_sites is a superset
6217 of DW_AT_GNU_all_tail_call_sites. */
6219 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
6220 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
6222 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
6223 not complete. But keep CALL_SITE for look ups via call_site_htab,
6224 both the initial caller containing the real return address PC and
6225 the final callee containing the current PC of a chain of tail
6226 calls do not need to have the tail call list complete. But any
6227 function candidate for a virtual tail call frame searched via
6228 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
6229 determined unambiguously. */
6233 struct type
*func_type
= NULL
;
6236 func_type
= get_die_type (func_die
, cu
);
6237 if (func_type
!= NULL
)
6239 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
6241 /* Enlist this call site to the function. */
6242 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
6243 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
6246 complaint (&symfile_complaints
,
6247 _("Cannot find function owning DW_TAG_GNU_call_site "
6248 "DIE 0x%x [in module %s]"),
6249 die
->offset
, cu
->objfile
->name
);
6253 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
6255 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
6256 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
6257 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
6258 /* Keep NULL DWARF_BLOCK. */;
6259 else if (attr_form_is_block (attr
))
6261 struct dwarf2_locexpr_baton
*dlbaton
;
6263 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
6264 dlbaton
->data
= DW_BLOCK (attr
)->data
;
6265 dlbaton
->size
= DW_BLOCK (attr
)->size
;
6266 dlbaton
->per_cu
= cu
->per_cu
;
6268 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
6270 else if (is_ref_attr (attr
))
6272 struct objfile
*objfile
= cu
->objfile
;
6273 struct dwarf2_cu
*target_cu
= cu
;
6274 struct die_info
*target_die
;
6276 target_die
= follow_die_ref_or_sig (die
, attr
, &target_cu
);
6277 gdb_assert (target_cu
->objfile
== objfile
);
6278 if (die_is_declaration (target_die
, target_cu
))
6280 const char *target_physname
;
6282 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
6283 if (target_physname
== NULL
)
6284 complaint (&symfile_complaints
,
6285 _("DW_AT_GNU_call_site_target target DIE has invalid "
6286 "physname, for referencing DIE 0x%x [in module %s]"),
6287 die
->offset
, cu
->objfile
->name
);
6289 SET_FIELD_PHYSNAME (call_site
->target
, (char *) target_physname
);
6295 /* DW_AT_entry_pc should be preferred. */
6296 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
6297 complaint (&symfile_complaints
,
6298 _("DW_AT_GNU_call_site_target target DIE has invalid "
6299 "low pc, for referencing DIE 0x%x [in module %s]"),
6300 die
->offset
, cu
->objfile
->name
);
6302 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
6306 complaint (&symfile_complaints
,
6307 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
6308 "block nor reference, for DIE 0x%x [in module %s]"),
6309 die
->offset
, cu
->objfile
->name
);
6311 call_site
->per_cu
= cu
->per_cu
;
6313 for (child_die
= die
->child
;
6314 child_die
&& child_die
->tag
;
6315 child_die
= sibling_die (child_die
))
6317 struct dwarf2_locexpr_baton
*dlbaton
;
6318 struct call_site_parameter
*parameter
;
6320 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
6322 /* Already printed the complaint above. */
6326 gdb_assert (call_site
->parameter_count
< nparams
);
6327 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
6329 /* DW_AT_location specifies the register number. Value of the data
6330 assumed for the register is contained in DW_AT_GNU_call_site_value. */
6332 attr
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
6333 if (!attr
|| !attr_form_is_block (attr
))
6335 complaint (&symfile_complaints
,
6336 _("No DW_FORM_block* DW_AT_location for "
6337 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6338 child_die
->offset
, cu
->objfile
->name
);
6341 parameter
->dwarf_reg
= dwarf_block_to_dwarf_reg (DW_BLOCK (attr
)->data
,
6342 &DW_BLOCK (attr
)->data
[DW_BLOCK (attr
)->size
]);
6343 if (parameter
->dwarf_reg
== -1
6344 && !dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (attr
)->data
,
6345 &DW_BLOCK (attr
)->data
[DW_BLOCK (attr
)->size
],
6346 ¶meter
->fb_offset
))
6348 complaint (&symfile_complaints
,
6349 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
6350 "for DW_FORM_block* DW_AT_location for "
6351 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6352 child_die
->offset
, cu
->objfile
->name
);
6356 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
6357 if (!attr_form_is_block (attr
))
6359 complaint (&symfile_complaints
,
6360 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
6361 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6362 child_die
->offset
, cu
->objfile
->name
);
6365 parameter
->value
= DW_BLOCK (attr
)->data
;
6366 parameter
->value_size
= DW_BLOCK (attr
)->size
;
6368 /* Parameters are not pre-cleared by memset above. */
6369 parameter
->data_value
= NULL
;
6370 parameter
->data_value_size
= 0;
6371 call_site
->parameter_count
++;
6373 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
6376 if (!attr_form_is_block (attr
))
6377 complaint (&symfile_complaints
,
6378 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
6379 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
6380 child_die
->offset
, cu
->objfile
->name
);
6383 parameter
->data_value
= DW_BLOCK (attr
)->data
;
6384 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
6390 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
6391 Return 1 if the attributes are present and valid, otherwise, return 0.
6392 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
6395 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
6396 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
6397 struct partial_symtab
*ranges_pst
)
6399 struct objfile
*objfile
= cu
->objfile
;
6400 struct comp_unit_head
*cu_header
= &cu
->header
;
6401 bfd
*obfd
= objfile
->obfd
;
6402 unsigned int addr_size
= cu_header
->addr_size
;
6403 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6404 /* Base address selection entry. */
6415 found_base
= cu
->base_known
;
6416 base
= cu
->base_address
;
6418 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
6419 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6421 complaint (&symfile_complaints
,
6422 _("Offset %d out of bounds for DW_AT_ranges attribute"),
6426 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6428 /* Read in the largest possible address. */
6429 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
6430 if ((marker
& mask
) == mask
)
6432 /* If we found the largest possible address, then
6433 read the base address. */
6434 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
6435 buffer
+= 2 * addr_size
;
6436 offset
+= 2 * addr_size
;
6442 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6446 CORE_ADDR range_beginning
, range_end
;
6448 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
6449 buffer
+= addr_size
;
6450 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
6451 buffer
+= addr_size
;
6452 offset
+= 2 * addr_size
;
6454 /* An end of list marker is a pair of zero addresses. */
6455 if (range_beginning
== 0 && range_end
== 0)
6456 /* Found the end of list entry. */
6459 /* Each base address selection entry is a pair of 2 values.
6460 The first is the largest possible address, the second is
6461 the base address. Check for a base address here. */
6462 if ((range_beginning
& mask
) == mask
)
6464 /* If we found the largest possible address, then
6465 read the base address. */
6466 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
6473 /* We have no valid base address for the ranges
6475 complaint (&symfile_complaints
,
6476 _("Invalid .debug_ranges data (no base address)"));
6480 if (range_beginning
> range_end
)
6482 /* Inverted range entries are invalid. */
6483 complaint (&symfile_complaints
,
6484 _("Invalid .debug_ranges data (inverted range)"));
6488 /* Empty range entries have no effect. */
6489 if (range_beginning
== range_end
)
6492 range_beginning
+= base
;
6495 if (ranges_pst
!= NULL
)
6496 addrmap_set_empty (objfile
->psymtabs_addrmap
,
6497 range_beginning
+ baseaddr
,
6498 range_end
- 1 + baseaddr
,
6501 /* FIXME: This is recording everything as a low-high
6502 segment of consecutive addresses. We should have a
6503 data structure for discontiguous block ranges
6507 low
= range_beginning
;
6513 if (range_beginning
< low
)
6514 low
= range_beginning
;
6515 if (range_end
> high
)
6521 /* If the first entry is an end-of-list marker, the range
6522 describes an empty scope, i.e. no instructions. */
6528 *high_return
= high
;
6532 /* Get low and high pc attributes from a die. Return 1 if the attributes
6533 are present and valid, otherwise, return 0. Return -1 if the range is
6534 discontinuous, i.e. derived from DW_AT_ranges information. */
6536 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
6537 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
6538 struct partial_symtab
*pst
)
6540 struct attribute
*attr
;
6545 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6548 high
= DW_ADDR (attr
);
6549 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6551 low
= DW_ADDR (attr
);
6553 /* Found high w/o low attribute. */
6556 /* Found consecutive range of addresses. */
6561 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6564 /* Value of the DW_AT_ranges attribute is the offset in the
6565 .debug_ranges section. */
6566 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
6568 /* Found discontinuous range of addresses. */
6573 /* read_partial_die has also the strict LOW < HIGH requirement. */
6577 /* When using the GNU linker, .gnu.linkonce. sections are used to
6578 eliminate duplicate copies of functions and vtables and such.
6579 The linker will arbitrarily choose one and discard the others.
6580 The AT_*_pc values for such functions refer to local labels in
6581 these sections. If the section from that file was discarded, the
6582 labels are not in the output, so the relocs get a value of 0.
6583 If this is a discarded function, mark the pc bounds as invalid,
6584 so that GDB will ignore it. */
6585 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
6594 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
6595 its low and high PC addresses. Do nothing if these addresses could not
6596 be determined. Otherwise, set LOWPC to the low address if it is smaller,
6597 and HIGHPC to the high address if greater than HIGHPC. */
6600 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
6601 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6602 struct dwarf2_cu
*cu
)
6604 CORE_ADDR low
, high
;
6605 struct die_info
*child
= die
->child
;
6607 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
6609 *lowpc
= min (*lowpc
, low
);
6610 *highpc
= max (*highpc
, high
);
6613 /* If the language does not allow nested subprograms (either inside
6614 subprograms or lexical blocks), we're done. */
6615 if (cu
->language
!= language_ada
)
6618 /* Check all the children of the given DIE. If it contains nested
6619 subprograms, then check their pc bounds. Likewise, we need to
6620 check lexical blocks as well, as they may also contain subprogram
6622 while (child
&& child
->tag
)
6624 if (child
->tag
== DW_TAG_subprogram
6625 || child
->tag
== DW_TAG_lexical_block
)
6626 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
6627 child
= sibling_die (child
);
6631 /* Get the low and high pc's represented by the scope DIE, and store
6632 them in *LOWPC and *HIGHPC. If the correct values can't be
6633 determined, set *LOWPC to -1 and *HIGHPC to 0. */
6636 get_scope_pc_bounds (struct die_info
*die
,
6637 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6638 struct dwarf2_cu
*cu
)
6640 CORE_ADDR best_low
= (CORE_ADDR
) -1;
6641 CORE_ADDR best_high
= (CORE_ADDR
) 0;
6642 CORE_ADDR current_low
, current_high
;
6644 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
6646 best_low
= current_low
;
6647 best_high
= current_high
;
6651 struct die_info
*child
= die
->child
;
6653 while (child
&& child
->tag
)
6655 switch (child
->tag
) {
6656 case DW_TAG_subprogram
:
6657 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
6659 case DW_TAG_namespace
:
6661 /* FIXME: carlton/2004-01-16: Should we do this for
6662 DW_TAG_class_type/DW_TAG_structure_type, too? I think
6663 that current GCC's always emit the DIEs corresponding
6664 to definitions of methods of classes as children of a
6665 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
6666 the DIEs giving the declarations, which could be
6667 anywhere). But I don't see any reason why the
6668 standards says that they have to be there. */
6669 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
6671 if (current_low
!= ((CORE_ADDR
) -1))
6673 best_low
= min (best_low
, current_low
);
6674 best_high
= max (best_high
, current_high
);
6682 child
= sibling_die (child
);
6687 *highpc
= best_high
;
6690 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
6693 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
6694 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
6696 struct attribute
*attr
;
6698 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6701 CORE_ADDR high
= DW_ADDR (attr
);
6703 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6706 CORE_ADDR low
= DW_ADDR (attr
);
6708 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
6712 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6715 bfd
*obfd
= cu
->objfile
->obfd
;
6717 /* The value of the DW_AT_ranges attribute is the offset of the
6718 address range list in the .debug_ranges section. */
6719 unsigned long offset
= DW_UNSND (attr
);
6720 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6722 /* For some target architectures, but not others, the
6723 read_address function sign-extends the addresses it returns.
6724 To recognize base address selection entries, we need a
6726 unsigned int addr_size
= cu
->header
.addr_size
;
6727 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6729 /* The base address, to which the next pair is relative. Note
6730 that this 'base' is a DWARF concept: most entries in a range
6731 list are relative, to reduce the number of relocs against the
6732 debugging information. This is separate from this function's
6733 'baseaddr' argument, which GDB uses to relocate debugging
6734 information from a shared library based on the address at
6735 which the library was loaded. */
6736 CORE_ADDR base
= cu
->base_address
;
6737 int base_known
= cu
->base_known
;
6739 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
6740 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6742 complaint (&symfile_complaints
,
6743 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
6750 unsigned int bytes_read
;
6751 CORE_ADDR start
, end
;
6753 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6754 buffer
+= bytes_read
;
6755 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6756 buffer
+= bytes_read
;
6758 /* Did we find the end of the range list? */
6759 if (start
== 0 && end
== 0)
6762 /* Did we find a base address selection entry? */
6763 else if ((start
& base_select_mask
) == base_select_mask
)
6769 /* We found an ordinary address range. */
6774 complaint (&symfile_complaints
,
6775 _("Invalid .debug_ranges data "
6776 "(no base address)"));
6782 /* Inverted range entries are invalid. */
6783 complaint (&symfile_complaints
,
6784 _("Invalid .debug_ranges data "
6785 "(inverted range)"));
6789 /* Empty range entries have no effect. */
6793 record_block_range (block
,
6794 baseaddr
+ base
+ start
,
6795 baseaddr
+ base
+ end
- 1);
6801 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
6802 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
6803 during 4.6.0 experimental. */
6806 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
6809 int major
, minor
, release
;
6811 if (cu
->producer
== NULL
)
6813 /* For unknown compilers expect their behavior is DWARF version
6816 GCC started to support .debug_types sections by -gdwarf-4 since
6817 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
6818 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
6819 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
6820 interpreted incorrectly by GDB now - GCC PR debug/48229. */
6825 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
6827 if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) != 0)
6829 /* For non-GCC compilers expect their behavior is DWARF version
6834 cs
= &cu
->producer
[strlen ("GNU ")];
6835 while (*cs
&& !isdigit (*cs
))
6837 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
6839 /* Not recognized as GCC. */
6844 return major
< 4 || (major
== 4 && minor
< 6);
6847 /* Return the default accessibility type if it is not overriden by
6848 DW_AT_accessibility. */
6850 static enum dwarf_access_attribute
6851 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
6853 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
6855 /* The default DWARF 2 accessibility for members is public, the default
6856 accessibility for inheritance is private. */
6858 if (die
->tag
!= DW_TAG_inheritance
)
6859 return DW_ACCESS_public
;
6861 return DW_ACCESS_private
;
6865 /* DWARF 3+ defines the default accessibility a different way. The same
6866 rules apply now for DW_TAG_inheritance as for the members and it only
6867 depends on the container kind. */
6869 if (die
->parent
->tag
== DW_TAG_class_type
)
6870 return DW_ACCESS_private
;
6872 return DW_ACCESS_public
;
6876 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
6877 offset. If the attribute was not found return 0, otherwise return
6878 1. If it was found but could not properly be handled, set *OFFSET
6882 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
6885 struct attribute
*attr
;
6887 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6892 /* Note that we do not check for a section offset first here.
6893 This is because DW_AT_data_member_location is new in DWARF 4,
6894 so if we see it, we can assume that a constant form is really
6895 a constant and not a section offset. */
6896 if (attr_form_is_constant (attr
))
6897 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
6898 else if (attr_form_is_section_offset (attr
))
6899 dwarf2_complex_location_expr_complaint ();
6900 else if (attr_form_is_block (attr
))
6901 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6903 dwarf2_complex_location_expr_complaint ();
6911 /* Add an aggregate field to the field list. */
6914 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
6915 struct dwarf2_cu
*cu
)
6917 struct objfile
*objfile
= cu
->objfile
;
6918 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6919 struct nextfield
*new_field
;
6920 struct attribute
*attr
;
6922 char *fieldname
= "";
6924 /* Allocate a new field list entry and link it in. */
6925 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
6926 make_cleanup (xfree
, new_field
);
6927 memset (new_field
, 0, sizeof (struct nextfield
));
6929 if (die
->tag
== DW_TAG_inheritance
)
6931 new_field
->next
= fip
->baseclasses
;
6932 fip
->baseclasses
= new_field
;
6936 new_field
->next
= fip
->fields
;
6937 fip
->fields
= new_field
;
6941 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6943 new_field
->accessibility
= DW_UNSND (attr
);
6945 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
6946 if (new_field
->accessibility
!= DW_ACCESS_public
)
6947 fip
->non_public_fields
= 1;
6949 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6951 new_field
->virtuality
= DW_UNSND (attr
);
6953 new_field
->virtuality
= DW_VIRTUALITY_none
;
6955 fp
= &new_field
->field
;
6957 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
6961 /* Data member other than a C++ static data member. */
6963 /* Get type of field. */
6964 fp
->type
= die_type (die
, cu
);
6966 SET_FIELD_BITPOS (*fp
, 0);
6968 /* Get bit size of field (zero if none). */
6969 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
6972 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
6976 FIELD_BITSIZE (*fp
) = 0;
6979 /* Get bit offset of field. */
6980 if (handle_data_member_location (die
, cu
, &offset
))
6981 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
6982 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
6985 if (gdbarch_bits_big_endian (gdbarch
))
6987 /* For big endian bits, the DW_AT_bit_offset gives the
6988 additional bit offset from the MSB of the containing
6989 anonymous object to the MSB of the field. We don't
6990 have to do anything special since we don't need to
6991 know the size of the anonymous object. */
6992 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
6996 /* For little endian bits, compute the bit offset to the
6997 MSB of the anonymous object, subtract off the number of
6998 bits from the MSB of the field to the MSB of the
6999 object, and then subtract off the number of bits of
7000 the field itself. The result is the bit offset of
7001 the LSB of the field. */
7003 int bit_offset
= DW_UNSND (attr
);
7005 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7008 /* The size of the anonymous object containing
7009 the bit field is explicit, so use the
7010 indicated size (in bytes). */
7011 anonymous_size
= DW_UNSND (attr
);
7015 /* The size of the anonymous object containing
7016 the bit field must be inferred from the type
7017 attribute of the data member containing the
7019 anonymous_size
= TYPE_LENGTH (fp
->type
);
7021 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
7022 - bit_offset
- FIELD_BITSIZE (*fp
);
7026 /* Get name of field. */
7027 fieldname
= dwarf2_name (die
, cu
);
7028 if (fieldname
== NULL
)
7031 /* The name is already allocated along with this objfile, so we don't
7032 need to duplicate it for the type. */
7033 fp
->name
= fieldname
;
7035 /* Change accessibility for artificial fields (e.g. virtual table
7036 pointer or virtual base class pointer) to private. */
7037 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
7039 FIELD_ARTIFICIAL (*fp
) = 1;
7040 new_field
->accessibility
= DW_ACCESS_private
;
7041 fip
->non_public_fields
= 1;
7044 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
7046 /* C++ static member. */
7048 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
7049 is a declaration, but all versions of G++ as of this writing
7050 (so through at least 3.2.1) incorrectly generate
7051 DW_TAG_variable tags. */
7053 const char *physname
;
7055 /* Get name of field. */
7056 fieldname
= dwarf2_name (die
, cu
);
7057 if (fieldname
== NULL
)
7060 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7062 /* Only create a symbol if this is an external value.
7063 new_symbol checks this and puts the value in the global symbol
7064 table, which we want. If it is not external, new_symbol
7065 will try to put the value in cu->list_in_scope which is wrong. */
7066 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
7068 /* A static const member, not much different than an enum as far as
7069 we're concerned, except that we can support more types. */
7070 new_symbol (die
, NULL
, cu
);
7073 /* Get physical name. */
7074 physname
= dwarf2_physname (fieldname
, die
, cu
);
7076 /* The name is already allocated along with this objfile, so we don't
7077 need to duplicate it for the type. */
7078 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
7079 FIELD_TYPE (*fp
) = die_type (die
, cu
);
7080 FIELD_NAME (*fp
) = fieldname
;
7082 else if (die
->tag
== DW_TAG_inheritance
)
7086 /* C++ base class field. */
7087 if (handle_data_member_location (die
, cu
, &offset
))
7088 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
7089 FIELD_BITSIZE (*fp
) = 0;
7090 FIELD_TYPE (*fp
) = die_type (die
, cu
);
7091 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
7092 fip
->nbaseclasses
++;
7096 /* Add a typedef defined in the scope of the FIP's class. */
7099 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
7100 struct dwarf2_cu
*cu
)
7102 struct objfile
*objfile
= cu
->objfile
;
7103 struct typedef_field_list
*new_field
;
7104 struct attribute
*attr
;
7105 struct typedef_field
*fp
;
7106 char *fieldname
= "";
7108 /* Allocate a new field list entry and link it in. */
7109 new_field
= xzalloc (sizeof (*new_field
));
7110 make_cleanup (xfree
, new_field
);
7112 gdb_assert (die
->tag
== DW_TAG_typedef
);
7114 fp
= &new_field
->field
;
7116 /* Get name of field. */
7117 fp
->name
= dwarf2_name (die
, cu
);
7118 if (fp
->name
== NULL
)
7121 fp
->type
= read_type_die (die
, cu
);
7123 new_field
->next
= fip
->typedef_field_list
;
7124 fip
->typedef_field_list
= new_field
;
7125 fip
->typedef_field_list_count
++;
7128 /* Create the vector of fields, and attach it to the type. */
7131 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
7132 struct dwarf2_cu
*cu
)
7134 int nfields
= fip
->nfields
;
7136 /* Record the field count, allocate space for the array of fields,
7137 and create blank accessibility bitfields if necessary. */
7138 TYPE_NFIELDS (type
) = nfields
;
7139 TYPE_FIELDS (type
) = (struct field
*)
7140 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
7141 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
7143 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
7145 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7147 TYPE_FIELD_PRIVATE_BITS (type
) =
7148 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7149 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
7151 TYPE_FIELD_PROTECTED_BITS (type
) =
7152 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7153 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
7155 TYPE_FIELD_IGNORE_BITS (type
) =
7156 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
7157 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
7160 /* If the type has baseclasses, allocate and clear a bit vector for
7161 TYPE_FIELD_VIRTUAL_BITS. */
7162 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
7164 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
7165 unsigned char *pointer
;
7167 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7168 pointer
= TYPE_ALLOC (type
, num_bytes
);
7169 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
7170 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
7171 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
7174 /* Copy the saved-up fields into the field vector. Start from the head of
7175 the list, adding to the tail of the field array, so that they end up in
7176 the same order in the array in which they were added to the list. */
7177 while (nfields
-- > 0)
7179 struct nextfield
*fieldp
;
7183 fieldp
= fip
->fields
;
7184 fip
->fields
= fieldp
->next
;
7188 fieldp
= fip
->baseclasses
;
7189 fip
->baseclasses
= fieldp
->next
;
7192 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
7193 switch (fieldp
->accessibility
)
7195 case DW_ACCESS_private
:
7196 if (cu
->language
!= language_ada
)
7197 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
7200 case DW_ACCESS_protected
:
7201 if (cu
->language
!= language_ada
)
7202 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
7205 case DW_ACCESS_public
:
7209 /* Unknown accessibility. Complain and treat it as public. */
7211 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
7212 fieldp
->accessibility
);
7216 if (nfields
< fip
->nbaseclasses
)
7218 switch (fieldp
->virtuality
)
7220 case DW_VIRTUALITY_virtual
:
7221 case DW_VIRTUALITY_pure_virtual
:
7222 if (cu
->language
== language_ada
)
7223 error (_("unexpected virtuality in component of Ada type"));
7224 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
7231 /* Add a member function to the proper fieldlist. */
7234 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
7235 struct type
*type
, struct dwarf2_cu
*cu
)
7237 struct objfile
*objfile
= cu
->objfile
;
7238 struct attribute
*attr
;
7239 struct fnfieldlist
*flp
;
7241 struct fn_field
*fnp
;
7243 struct nextfnfield
*new_fnfield
;
7244 struct type
*this_type
;
7245 enum dwarf_access_attribute accessibility
;
7247 if (cu
->language
== language_ada
)
7248 error (_("unexpected member function in Ada type"));
7250 /* Get name of member function. */
7251 fieldname
= dwarf2_name (die
, cu
);
7252 if (fieldname
== NULL
)
7255 /* Look up member function name in fieldlist. */
7256 for (i
= 0; i
< fip
->nfnfields
; i
++)
7258 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
7262 /* Create new list element if necessary. */
7263 if (i
< fip
->nfnfields
)
7264 flp
= &fip
->fnfieldlists
[i
];
7267 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7269 fip
->fnfieldlists
= (struct fnfieldlist
*)
7270 xrealloc (fip
->fnfieldlists
,
7271 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
7272 * sizeof (struct fnfieldlist
));
7273 if (fip
->nfnfields
== 0)
7274 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
7276 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
7277 flp
->name
= fieldname
;
7280 i
= fip
->nfnfields
++;
7283 /* Create a new member function field and chain it to the field list
7285 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
7286 make_cleanup (xfree
, new_fnfield
);
7287 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
7288 new_fnfield
->next
= flp
->head
;
7289 flp
->head
= new_fnfield
;
7292 /* Fill in the member function field info. */
7293 fnp
= &new_fnfield
->fnfield
;
7295 /* Delay processing of the physname until later. */
7296 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
7298 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
7303 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
7304 fnp
->physname
= physname
? physname
: "";
7307 fnp
->type
= alloc_type (objfile
);
7308 this_type
= read_type_die (die
, cu
);
7309 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
7311 int nparams
= TYPE_NFIELDS (this_type
);
7313 /* TYPE is the domain of this method, and THIS_TYPE is the type
7314 of the method itself (TYPE_CODE_METHOD). */
7315 smash_to_method_type (fnp
->type
, type
,
7316 TYPE_TARGET_TYPE (this_type
),
7317 TYPE_FIELDS (this_type
),
7318 TYPE_NFIELDS (this_type
),
7319 TYPE_VARARGS (this_type
));
7321 /* Handle static member functions.
7322 Dwarf2 has no clean way to discern C++ static and non-static
7323 member functions. G++ helps GDB by marking the first
7324 parameter for non-static member functions (which is the this
7325 pointer) as artificial. We obtain this information from
7326 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
7327 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
7328 fnp
->voffset
= VOFFSET_STATIC
;
7331 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
7332 dwarf2_full_name (fieldname
, die
, cu
));
7334 /* Get fcontext from DW_AT_containing_type if present. */
7335 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7336 fnp
->fcontext
= die_containing_type (die
, cu
);
7338 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
7339 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
7341 /* Get accessibility. */
7342 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
7344 accessibility
= DW_UNSND (attr
);
7346 accessibility
= dwarf2_default_access_attribute (die
, cu
);
7347 switch (accessibility
)
7349 case DW_ACCESS_private
:
7350 fnp
->is_private
= 1;
7352 case DW_ACCESS_protected
:
7353 fnp
->is_protected
= 1;
7357 /* Check for artificial methods. */
7358 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
7359 if (attr
&& DW_UNSND (attr
) != 0)
7360 fnp
->is_artificial
= 1;
7362 /* Get index in virtual function table if it is a virtual member
7363 function. For older versions of GCC, this is an offset in the
7364 appropriate virtual table, as specified by DW_AT_containing_type.
7365 For everyone else, it is an expression to be evaluated relative
7366 to the object address. */
7368 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
7371 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
7373 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
7375 /* Old-style GCC. */
7376 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
7378 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
7379 || (DW_BLOCK (attr
)->size
> 1
7380 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
7381 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
7383 struct dwarf_block blk
;
7386 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
7388 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
7389 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
7390 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
7391 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
7392 dwarf2_complex_location_expr_complaint ();
7394 fnp
->voffset
/= cu
->header
.addr_size
;
7398 dwarf2_complex_location_expr_complaint ();
7401 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
7403 else if (attr_form_is_section_offset (attr
))
7405 dwarf2_complex_location_expr_complaint ();
7409 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
7415 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
7416 if (attr
&& DW_UNSND (attr
))
7418 /* GCC does this, as of 2008-08-25; PR debug/37237. */
7419 complaint (&symfile_complaints
,
7420 _("Member function \"%s\" (offset %d) is virtual "
7421 "but the vtable offset is not specified"),
7422 fieldname
, die
->offset
);
7423 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7424 TYPE_CPLUS_DYNAMIC (type
) = 1;
7429 /* Create the vector of member function fields, and attach it to the type. */
7432 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
7433 struct dwarf2_cu
*cu
)
7435 struct fnfieldlist
*flp
;
7436 int total_length
= 0;
7439 if (cu
->language
== language_ada
)
7440 error (_("unexpected member functions in Ada type"));
7442 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7443 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
7444 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
7446 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
7448 struct nextfnfield
*nfp
= flp
->head
;
7449 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
7452 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
7453 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
7454 fn_flp
->fn_fields
= (struct fn_field
*)
7455 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
7456 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
7457 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
7459 total_length
+= flp
->length
;
7462 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
7463 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
7466 /* Returns non-zero if NAME is the name of a vtable member in CU's
7467 language, zero otherwise. */
7469 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
7471 static const char vptr
[] = "_vptr";
7472 static const char vtable
[] = "vtable";
7474 /* Look for the C++ and Java forms of the vtable. */
7475 if ((cu
->language
== language_java
7476 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
7477 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
7478 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
7484 /* GCC outputs unnamed structures that are really pointers to member
7485 functions, with the ABI-specified layout. If TYPE describes
7486 such a structure, smash it into a member function type.
7488 GCC shouldn't do this; it should just output pointer to member DIEs.
7489 This is GCC PR debug/28767. */
7492 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
7494 struct type
*pfn_type
, *domain_type
, *new_type
;
7496 /* Check for a structure with no name and two children. */
7497 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
7500 /* Check for __pfn and __delta members. */
7501 if (TYPE_FIELD_NAME (type
, 0) == NULL
7502 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
7503 || TYPE_FIELD_NAME (type
, 1) == NULL
7504 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
7507 /* Find the type of the method. */
7508 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
7509 if (pfn_type
== NULL
7510 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
7511 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
7514 /* Look for the "this" argument. */
7515 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
7516 if (TYPE_NFIELDS (pfn_type
) == 0
7517 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
7518 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
7521 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
7522 new_type
= alloc_type (objfile
);
7523 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
7524 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
7525 TYPE_VARARGS (pfn_type
));
7526 smash_to_methodptr_type (type
, new_type
);
7529 /* Called when we find the DIE that starts a structure or union scope
7530 (definition) to create a type for the structure or union. Fill in
7531 the type's name and general properties; the members will not be
7532 processed until process_structure_type.
7534 NOTE: we need to call these functions regardless of whether or not the
7535 DIE has a DW_AT_name attribute, since it might be an anonymous
7536 structure or union. This gets the type entered into our set of
7539 However, if the structure is incomplete (an opaque struct/union)
7540 then suppress creating a symbol table entry for it since gdb only
7541 wants to find the one with the complete definition. Note that if
7542 it is complete, we just call new_symbol, which does it's own
7543 checking about whether the struct/union is anonymous or not (and
7544 suppresses creating a symbol table entry itself). */
7546 static struct type
*
7547 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7549 struct objfile
*objfile
= cu
->objfile
;
7551 struct attribute
*attr
;
7554 /* If the definition of this type lives in .debug_types, read that type.
7555 Don't follow DW_AT_specification though, that will take us back up
7556 the chain and we want to go down. */
7557 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7560 struct dwarf2_cu
*type_cu
= cu
;
7561 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7563 /* We could just recurse on read_structure_type, but we need to call
7564 get_die_type to ensure only one type for this DIE is created.
7565 This is important, for example, because for c++ classes we need
7566 TYPE_NAME set which is only done by new_symbol. Blech. */
7567 type
= read_type_die (type_die
, type_cu
);
7569 /* TYPE_CU may not be the same as CU.
7570 Ensure TYPE is recorded in CU's type_hash table. */
7571 return set_die_type (die
, type
, cu
);
7574 type
= alloc_type (objfile
);
7575 INIT_CPLUS_SPECIFIC (type
);
7577 name
= dwarf2_name (die
, cu
);
7580 if (cu
->language
== language_cplus
7581 || cu
->language
== language_java
)
7583 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
7585 /* dwarf2_full_name might have already finished building the DIE's
7586 type. If so, there is no need to continue. */
7587 if (get_die_type (die
, cu
) != NULL
)
7588 return get_die_type (die
, cu
);
7590 TYPE_TAG_NAME (type
) = full_name
;
7591 if (die
->tag
== DW_TAG_structure_type
7592 || die
->tag
== DW_TAG_class_type
)
7593 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7597 /* The name is already allocated along with this objfile, so
7598 we don't need to duplicate it for the type. */
7599 TYPE_TAG_NAME (type
) = (char *) name
;
7600 if (die
->tag
== DW_TAG_class_type
)
7601 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7605 if (die
->tag
== DW_TAG_structure_type
)
7607 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
7609 else if (die
->tag
== DW_TAG_union_type
)
7611 TYPE_CODE (type
) = TYPE_CODE_UNION
;
7615 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
7618 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
7619 TYPE_DECLARED_CLASS (type
) = 1;
7621 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7624 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7628 TYPE_LENGTH (type
) = 0;
7631 TYPE_STUB_SUPPORTED (type
) = 1;
7632 if (die_is_declaration (die
, cu
))
7633 TYPE_STUB (type
) = 1;
7634 else if (attr
== NULL
&& die
->child
== NULL
7635 && producer_is_realview (cu
->producer
))
7636 /* RealView does not output the required DW_AT_declaration
7637 on incomplete types. */
7638 TYPE_STUB (type
) = 1;
7640 /* We need to add the type field to the die immediately so we don't
7641 infinitely recurse when dealing with pointers to the structure
7642 type within the structure itself. */
7643 set_die_type (die
, type
, cu
);
7645 /* set_die_type should be already done. */
7646 set_descriptive_type (type
, die
, cu
);
7651 /* Finish creating a structure or union type, including filling in
7652 its members and creating a symbol for it. */
7655 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7657 struct objfile
*objfile
= cu
->objfile
;
7658 struct die_info
*child_die
= die
->child
;
7661 type
= get_die_type (die
, cu
);
7663 type
= read_structure_type (die
, cu
);
7665 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
7667 struct field_info fi
;
7668 struct die_info
*child_die
;
7669 VEC (symbolp
) *template_args
= NULL
;
7670 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
7672 memset (&fi
, 0, sizeof (struct field_info
));
7674 child_die
= die
->child
;
7676 while (child_die
&& child_die
->tag
)
7678 if (child_die
->tag
== DW_TAG_member
7679 || child_die
->tag
== DW_TAG_variable
)
7681 /* NOTE: carlton/2002-11-05: A C++ static data member
7682 should be a DW_TAG_member that is a declaration, but
7683 all versions of G++ as of this writing (so through at
7684 least 3.2.1) incorrectly generate DW_TAG_variable
7685 tags for them instead. */
7686 dwarf2_add_field (&fi
, child_die
, cu
);
7688 else if (child_die
->tag
== DW_TAG_subprogram
)
7690 /* C++ member function. */
7691 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
7693 else if (child_die
->tag
== DW_TAG_inheritance
)
7695 /* C++ base class field. */
7696 dwarf2_add_field (&fi
, child_die
, cu
);
7698 else if (child_die
->tag
== DW_TAG_typedef
)
7699 dwarf2_add_typedef (&fi
, child_die
, cu
);
7700 else if (child_die
->tag
== DW_TAG_template_type_param
7701 || child_die
->tag
== DW_TAG_template_value_param
)
7703 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
7706 VEC_safe_push (symbolp
, template_args
, arg
);
7709 child_die
= sibling_die (child_die
);
7712 /* Attach template arguments to type. */
7713 if (! VEC_empty (symbolp
, template_args
))
7715 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7716 TYPE_N_TEMPLATE_ARGUMENTS (type
)
7717 = VEC_length (symbolp
, template_args
);
7718 TYPE_TEMPLATE_ARGUMENTS (type
)
7719 = obstack_alloc (&objfile
->objfile_obstack
,
7720 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7721 * sizeof (struct symbol
*)));
7722 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
7723 VEC_address (symbolp
, template_args
),
7724 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7725 * sizeof (struct symbol
*)));
7726 VEC_free (symbolp
, template_args
);
7729 /* Attach fields and member functions to the type. */
7731 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
7734 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
7736 /* Get the type which refers to the base class (possibly this
7737 class itself) which contains the vtable pointer for the current
7738 class from the DW_AT_containing_type attribute. This use of
7739 DW_AT_containing_type is a GNU extension. */
7741 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7743 struct type
*t
= die_containing_type (die
, cu
);
7745 TYPE_VPTR_BASETYPE (type
) = t
;
7750 /* Our own class provides vtbl ptr. */
7751 for (i
= TYPE_NFIELDS (t
) - 1;
7752 i
>= TYPE_N_BASECLASSES (t
);
7755 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
7757 if (is_vtable_name (fieldname
, cu
))
7759 TYPE_VPTR_FIELDNO (type
) = i
;
7764 /* Complain if virtual function table field not found. */
7765 if (i
< TYPE_N_BASECLASSES (t
))
7766 complaint (&symfile_complaints
,
7767 _("virtual function table pointer "
7768 "not found when defining class '%s'"),
7769 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
7774 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
7777 else if (cu
->producer
7778 && strncmp (cu
->producer
,
7779 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
7781 /* The IBM XLC compiler does not provide direct indication
7782 of the containing type, but the vtable pointer is
7783 always named __vfp. */
7787 for (i
= TYPE_NFIELDS (type
) - 1;
7788 i
>= TYPE_N_BASECLASSES (type
);
7791 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
7793 TYPE_VPTR_FIELDNO (type
) = i
;
7794 TYPE_VPTR_BASETYPE (type
) = type
;
7801 /* Copy fi.typedef_field_list linked list elements content into the
7802 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
7803 if (fi
.typedef_field_list
)
7805 int i
= fi
.typedef_field_list_count
;
7807 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7808 TYPE_TYPEDEF_FIELD_ARRAY (type
)
7809 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
7810 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
7812 /* Reverse the list order to keep the debug info elements order. */
7815 struct typedef_field
*dest
, *src
;
7817 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
7818 src
= &fi
.typedef_field_list
->field
;
7819 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
7824 do_cleanups (back_to
);
7826 if (HAVE_CPLUS_STRUCT (type
))
7827 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
7830 quirk_gcc_member_function_pointer (type
, cu
->objfile
);
7832 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
7833 snapshots) has been known to create a die giving a declaration
7834 for a class that has, as a child, a die giving a definition for a
7835 nested class. So we have to process our children even if the
7836 current die is a declaration. Normally, of course, a declaration
7837 won't have any children at all. */
7839 while (child_die
!= NULL
&& child_die
->tag
)
7841 if (child_die
->tag
== DW_TAG_member
7842 || child_die
->tag
== DW_TAG_variable
7843 || child_die
->tag
== DW_TAG_inheritance
7844 || child_die
->tag
== DW_TAG_template_value_param
7845 || child_die
->tag
== DW_TAG_template_type_param
)
7850 process_die (child_die
, cu
);
7852 child_die
= sibling_die (child_die
);
7855 /* Do not consider external references. According to the DWARF standard,
7856 these DIEs are identified by the fact that they have no byte_size
7857 attribute, and a declaration attribute. */
7858 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
7859 || !die_is_declaration (die
, cu
))
7860 new_symbol (die
, type
, cu
);
7863 /* Given a DW_AT_enumeration_type die, set its type. We do not
7864 complete the type's fields yet, or create any symbols. */
7866 static struct type
*
7867 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7869 struct objfile
*objfile
= cu
->objfile
;
7871 struct attribute
*attr
;
7874 /* If the definition of this type lives in .debug_types, read that type.
7875 Don't follow DW_AT_specification though, that will take us back up
7876 the chain and we want to go down. */
7877 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7880 struct dwarf2_cu
*type_cu
= cu
;
7881 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7883 type
= read_type_die (type_die
, type_cu
);
7885 /* TYPE_CU may not be the same as CU.
7886 Ensure TYPE is recorded in CU's type_hash table. */
7887 return set_die_type (die
, type
, cu
);
7890 type
= alloc_type (objfile
);
7892 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
7893 name
= dwarf2_full_name (NULL
, die
, cu
);
7895 TYPE_TAG_NAME (type
) = (char *) name
;
7897 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7900 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7904 TYPE_LENGTH (type
) = 0;
7907 /* The enumeration DIE can be incomplete. In Ada, any type can be
7908 declared as private in the package spec, and then defined only
7909 inside the package body. Such types are known as Taft Amendment
7910 Types. When another package uses such a type, an incomplete DIE
7911 may be generated by the compiler. */
7912 if (die_is_declaration (die
, cu
))
7913 TYPE_STUB (type
) = 1;
7915 return set_die_type (die
, type
, cu
);
7918 /* Given a pointer to a die which begins an enumeration, process all
7919 the dies that define the members of the enumeration, and create the
7920 symbol for the enumeration type.
7922 NOTE: We reverse the order of the element list. */
7925 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7927 struct type
*this_type
;
7929 this_type
= get_die_type (die
, cu
);
7930 if (this_type
== NULL
)
7931 this_type
= read_enumeration_type (die
, cu
);
7933 if (die
->child
!= NULL
)
7935 struct die_info
*child_die
;
7937 struct field
*fields
= NULL
;
7939 int unsigned_enum
= 1;
7942 child_die
= die
->child
;
7943 while (child_die
&& child_die
->tag
)
7945 if (child_die
->tag
!= DW_TAG_enumerator
)
7947 process_die (child_die
, cu
);
7951 name
= dwarf2_name (child_die
, cu
);
7954 sym
= new_symbol (child_die
, this_type
, cu
);
7955 if (SYMBOL_VALUE (sym
) < 0)
7958 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7960 fields
= (struct field
*)
7962 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
7963 * sizeof (struct field
));
7966 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
7967 FIELD_TYPE (fields
[num_fields
]) = NULL
;
7968 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
7969 FIELD_BITSIZE (fields
[num_fields
]) = 0;
7975 child_die
= sibling_die (child_die
);
7980 TYPE_NFIELDS (this_type
) = num_fields
;
7981 TYPE_FIELDS (this_type
) = (struct field
*)
7982 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
7983 memcpy (TYPE_FIELDS (this_type
), fields
,
7984 sizeof (struct field
) * num_fields
);
7988 TYPE_UNSIGNED (this_type
) = 1;
7991 /* If we are reading an enum from a .debug_types unit, and the enum
7992 is a declaration, and the enum is not the signatured type in the
7993 unit, then we do not want to add a symbol for it. Adding a
7994 symbol would in some cases obscure the true definition of the
7995 enum, giving users an incomplete type when the definition is
7996 actually available. Note that we do not want to do this for all
7997 enums which are just declarations, because C++0x allows forward
7998 enum declarations. */
7999 if (cu
->per_cu
->debug_type_section
8000 && die_is_declaration (die
, cu
))
8002 struct signatured_type
*type_sig
;
8005 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
8006 cu
->per_cu
->debug_type_section
,
8007 cu
->per_cu
->offset
);
8008 if (type_sig
->type_offset
!= die
->offset
)
8012 new_symbol (die
, this_type
, cu
);
8015 /* Extract all information from a DW_TAG_array_type DIE and put it in
8016 the DIE's type field. For now, this only handles one dimensional
8019 static struct type
*
8020 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8022 struct objfile
*objfile
= cu
->objfile
;
8023 struct die_info
*child_die
;
8025 struct type
*element_type
, *range_type
, *index_type
;
8026 struct type
**range_types
= NULL
;
8027 struct attribute
*attr
;
8029 struct cleanup
*back_to
;
8032 element_type
= die_type (die
, cu
);
8034 /* The die_type call above may have already set the type for this DIE. */
8035 type
= get_die_type (die
, cu
);
8039 /* Irix 6.2 native cc creates array types without children for
8040 arrays with unspecified length. */
8041 if (die
->child
== NULL
)
8043 index_type
= objfile_type (objfile
)->builtin_int
;
8044 range_type
= create_range_type (NULL
, index_type
, 0, -1);
8045 type
= create_array_type (NULL
, element_type
, range_type
);
8046 return set_die_type (die
, type
, cu
);
8049 back_to
= make_cleanup (null_cleanup
, NULL
);
8050 child_die
= die
->child
;
8051 while (child_die
&& child_die
->tag
)
8053 if (child_die
->tag
== DW_TAG_subrange_type
)
8055 struct type
*child_type
= read_type_die (child_die
, cu
);
8057 if (child_type
!= NULL
)
8059 /* The range type was succesfully read. Save it for the
8060 array type creation. */
8061 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
8063 range_types
= (struct type
**)
8064 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
8065 * sizeof (struct type
*));
8067 make_cleanup (free_current_contents
, &range_types
);
8069 range_types
[ndim
++] = child_type
;
8072 child_die
= sibling_die (child_die
);
8075 /* Dwarf2 dimensions are output from left to right, create the
8076 necessary array types in backwards order. */
8078 type
= element_type
;
8080 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
8085 type
= create_array_type (NULL
, type
, range_types
[i
++]);
8090 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
8093 /* Understand Dwarf2 support for vector types (like they occur on
8094 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
8095 array type. This is not part of the Dwarf2/3 standard yet, but a
8096 custom vendor extension. The main difference between a regular
8097 array and the vector variant is that vectors are passed by value
8099 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
8101 make_vector_type (type
);
8103 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
8104 implementation may choose to implement triple vectors using this
8106 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8109 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
8110 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8112 complaint (&symfile_complaints
,
8113 _("DW_AT_byte_size for array type smaller "
8114 "than the total size of elements"));
8117 name
= dwarf2_name (die
, cu
);
8119 TYPE_NAME (type
) = name
;
8121 /* Install the type in the die. */
8122 set_die_type (die
, type
, cu
);
8124 /* set_die_type should be already done. */
8125 set_descriptive_type (type
, die
, cu
);
8127 do_cleanups (back_to
);
8132 static enum dwarf_array_dim_ordering
8133 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
8135 struct attribute
*attr
;
8137 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
8139 if (attr
) return DW_SND (attr
);
8141 /* GNU F77 is a special case, as at 08/2004 array type info is the
8142 opposite order to the dwarf2 specification, but data is still
8143 laid out as per normal fortran.
8145 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
8146 version checking. */
8148 if (cu
->language
== language_fortran
8149 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
8151 return DW_ORD_row_major
;
8154 switch (cu
->language_defn
->la_array_ordering
)
8156 case array_column_major
:
8157 return DW_ORD_col_major
;
8158 case array_row_major
:
8160 return DW_ORD_row_major
;
8164 /* Extract all information from a DW_TAG_set_type DIE and put it in
8165 the DIE's type field. */
8167 static struct type
*
8168 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8170 struct type
*domain_type
, *set_type
;
8171 struct attribute
*attr
;
8173 domain_type
= die_type (die
, cu
);
8175 /* The die_type call above may have already set the type for this DIE. */
8176 set_type
= get_die_type (die
, cu
);
8180 set_type
= create_set_type (NULL
, domain_type
);
8182 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8184 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
8186 return set_die_type (die
, set_type
, cu
);
8189 /* First cut: install each common block member as a global variable. */
8192 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
8194 struct die_info
*child_die
;
8195 struct attribute
*attr
;
8197 CORE_ADDR base
= (CORE_ADDR
) 0;
8199 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
8202 /* Support the .debug_loc offsets. */
8203 if (attr_form_is_block (attr
))
8205 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
8207 else if (attr_form_is_section_offset (attr
))
8209 dwarf2_complex_location_expr_complaint ();
8213 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
8214 "common block member");
8217 if (die
->child
!= NULL
)
8219 child_die
= die
->child
;
8220 while (child_die
&& child_die
->tag
)
8224 sym
= new_symbol (child_die
, NULL
, cu
);
8226 && handle_data_member_location (child_die
, cu
, &offset
))
8228 SYMBOL_VALUE_ADDRESS (sym
) = base
+ offset
;
8229 add_symbol_to_list (sym
, &global_symbols
);
8231 child_die
= sibling_die (child_die
);
8236 /* Create a type for a C++ namespace. */
8238 static struct type
*
8239 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8241 struct objfile
*objfile
= cu
->objfile
;
8242 const char *previous_prefix
, *name
;
8246 /* For extensions, reuse the type of the original namespace. */
8247 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
8249 struct die_info
*ext_die
;
8250 struct dwarf2_cu
*ext_cu
= cu
;
8252 ext_die
= dwarf2_extension (die
, &ext_cu
);
8253 type
= read_type_die (ext_die
, ext_cu
);
8255 /* EXT_CU may not be the same as CU.
8256 Ensure TYPE is recorded in CU's type_hash table. */
8257 return set_die_type (die
, type
, cu
);
8260 name
= namespace_name (die
, &is_anonymous
, cu
);
8262 /* Now build the name of the current namespace. */
8264 previous_prefix
= determine_prefix (die
, cu
);
8265 if (previous_prefix
[0] != '\0')
8266 name
= typename_concat (&objfile
->objfile_obstack
,
8267 previous_prefix
, name
, 0, cu
);
8269 /* Create the type. */
8270 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
8272 TYPE_NAME (type
) = (char *) name
;
8273 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8275 return set_die_type (die
, type
, cu
);
8278 /* Read a C++ namespace. */
8281 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
8283 struct objfile
*objfile
= cu
->objfile
;
8286 /* Add a symbol associated to this if we haven't seen the namespace
8287 before. Also, add a using directive if it's an anonymous
8290 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
8294 type
= read_type_die (die
, cu
);
8295 new_symbol (die
, type
, cu
);
8297 namespace_name (die
, &is_anonymous
, cu
);
8300 const char *previous_prefix
= determine_prefix (die
, cu
);
8302 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
8303 NULL
, NULL
, &objfile
->objfile_obstack
);
8307 if (die
->child
!= NULL
)
8309 struct die_info
*child_die
= die
->child
;
8311 while (child_die
&& child_die
->tag
)
8313 process_die (child_die
, cu
);
8314 child_die
= sibling_die (child_die
);
8319 /* Read a Fortran module as type. This DIE can be only a declaration used for
8320 imported module. Still we need that type as local Fortran "use ... only"
8321 declaration imports depend on the created type in determine_prefix. */
8323 static struct type
*
8324 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8326 struct objfile
*objfile
= cu
->objfile
;
8330 module_name
= dwarf2_name (die
, cu
);
8332 complaint (&symfile_complaints
,
8333 _("DW_TAG_module has no name, offset 0x%x"),
8335 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
8337 /* determine_prefix uses TYPE_TAG_NAME. */
8338 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
8340 return set_die_type (die
, type
, cu
);
8343 /* Read a Fortran module. */
8346 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
8348 struct die_info
*child_die
= die
->child
;
8350 while (child_die
&& child_die
->tag
)
8352 process_die (child_die
, cu
);
8353 child_die
= sibling_die (child_die
);
8357 /* Return the name of the namespace represented by DIE. Set
8358 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
8362 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
8364 struct die_info
*current_die
;
8365 const char *name
= NULL
;
8367 /* Loop through the extensions until we find a name. */
8369 for (current_die
= die
;
8370 current_die
!= NULL
;
8371 current_die
= dwarf2_extension (die
, &cu
))
8373 name
= dwarf2_name (current_die
, cu
);
8378 /* Is it an anonymous namespace? */
8380 *is_anonymous
= (name
== NULL
);
8382 name
= CP_ANONYMOUS_NAMESPACE_STR
;
8387 /* Extract all information from a DW_TAG_pointer_type DIE and add to
8388 the user defined type vector. */
8390 static struct type
*
8391 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8393 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
8394 struct comp_unit_head
*cu_header
= &cu
->header
;
8396 struct attribute
*attr_byte_size
;
8397 struct attribute
*attr_address_class
;
8398 int byte_size
, addr_class
;
8399 struct type
*target_type
;
8401 target_type
= die_type (die
, cu
);
8403 /* The die_type call above may have already set the type for this DIE. */
8404 type
= get_die_type (die
, cu
);
8408 type
= lookup_pointer_type (target_type
);
8410 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8412 byte_size
= DW_UNSND (attr_byte_size
);
8414 byte_size
= cu_header
->addr_size
;
8416 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
8417 if (attr_address_class
)
8418 addr_class
= DW_UNSND (attr_address_class
);
8420 addr_class
= DW_ADDR_none
;
8422 /* If the pointer size or address class is different than the
8423 default, create a type variant marked as such and set the
8424 length accordingly. */
8425 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
8427 if (gdbarch_address_class_type_flags_p (gdbarch
))
8431 type_flags
= gdbarch_address_class_type_flags
8432 (gdbarch
, byte_size
, addr_class
);
8433 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
8435 type
= make_type_with_address_space (type
, type_flags
);
8437 else if (TYPE_LENGTH (type
) != byte_size
)
8439 complaint (&symfile_complaints
,
8440 _("invalid pointer size %d"), byte_size
);
8444 /* Should we also complain about unhandled address classes? */
8448 TYPE_LENGTH (type
) = byte_size
;
8449 return set_die_type (die
, type
, cu
);
8452 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
8453 the user defined type vector. */
8455 static struct type
*
8456 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8459 struct type
*to_type
;
8460 struct type
*domain
;
8462 to_type
= die_type (die
, cu
);
8463 domain
= die_containing_type (die
, cu
);
8465 /* The calls above may have already set the type for this DIE. */
8466 type
= get_die_type (die
, cu
);
8470 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
8471 type
= lookup_methodptr_type (to_type
);
8473 type
= lookup_memberptr_type (to_type
, domain
);
8475 return set_die_type (die
, type
, cu
);
8478 /* Extract all information from a DW_TAG_reference_type DIE and add to
8479 the user defined type vector. */
8481 static struct type
*
8482 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8484 struct comp_unit_head
*cu_header
= &cu
->header
;
8485 struct type
*type
, *target_type
;
8486 struct attribute
*attr
;
8488 target_type
= die_type (die
, cu
);
8490 /* The die_type call above may have already set the type for this DIE. */
8491 type
= get_die_type (die
, cu
);
8495 type
= lookup_reference_type (target_type
);
8496 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8499 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8503 TYPE_LENGTH (type
) = cu_header
->addr_size
;
8505 return set_die_type (die
, type
, cu
);
8508 static struct type
*
8509 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8511 struct type
*base_type
, *cv_type
;
8513 base_type
= die_type (die
, cu
);
8515 /* The die_type call above may have already set the type for this DIE. */
8516 cv_type
= get_die_type (die
, cu
);
8520 /* In case the const qualifier is applied to an array type, the element type
8521 is so qualified, not the array type (section 6.7.3 of C99). */
8522 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
8524 struct type
*el_type
, *inner_array
;
8526 base_type
= copy_type (base_type
);
8527 inner_array
= base_type
;
8529 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
8531 TYPE_TARGET_TYPE (inner_array
) =
8532 copy_type (TYPE_TARGET_TYPE (inner_array
));
8533 inner_array
= TYPE_TARGET_TYPE (inner_array
);
8536 el_type
= TYPE_TARGET_TYPE (inner_array
);
8537 TYPE_TARGET_TYPE (inner_array
) =
8538 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
8540 return set_die_type (die
, base_type
, cu
);
8543 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
8544 return set_die_type (die
, cv_type
, cu
);
8547 static struct type
*
8548 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8550 struct type
*base_type
, *cv_type
;
8552 base_type
= die_type (die
, cu
);
8554 /* The die_type call above may have already set the type for this DIE. */
8555 cv_type
= get_die_type (die
, cu
);
8559 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
8560 return set_die_type (die
, cv_type
, cu
);
8563 /* Extract all information from a DW_TAG_string_type DIE and add to
8564 the user defined type vector. It isn't really a user defined type,
8565 but it behaves like one, with other DIE's using an AT_user_def_type
8566 attribute to reference it. */
8568 static struct type
*
8569 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8571 struct objfile
*objfile
= cu
->objfile
;
8572 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8573 struct type
*type
, *range_type
, *index_type
, *char_type
;
8574 struct attribute
*attr
;
8575 unsigned int length
;
8577 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
8580 length
= DW_UNSND (attr
);
8584 /* Check for the DW_AT_byte_size attribute. */
8585 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8588 length
= DW_UNSND (attr
);
8596 index_type
= objfile_type (objfile
)->builtin_int
;
8597 range_type
= create_range_type (NULL
, index_type
, 1, length
);
8598 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
8599 type
= create_string_type (NULL
, char_type
, range_type
);
8601 return set_die_type (die
, type
, cu
);
8604 /* Handle DIES due to C code like:
8608 int (*funcp)(int a, long l);
8612 ('funcp' generates a DW_TAG_subroutine_type DIE). */
8614 static struct type
*
8615 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8617 struct type
*type
; /* Type that this function returns. */
8618 struct type
*ftype
; /* Function that returns above type. */
8619 struct attribute
*attr
;
8621 type
= die_type (die
, cu
);
8623 /* The die_type call above may have already set the type for this DIE. */
8624 ftype
= get_die_type (die
, cu
);
8628 ftype
= lookup_function_type (type
);
8630 /* All functions in C++, Pascal and Java have prototypes. */
8631 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
8632 if ((attr
&& (DW_UNSND (attr
) != 0))
8633 || cu
->language
== language_cplus
8634 || cu
->language
== language_java
8635 || cu
->language
== language_pascal
)
8636 TYPE_PROTOTYPED (ftype
) = 1;
8637 else if (producer_is_realview (cu
->producer
))
8638 /* RealView does not emit DW_AT_prototyped. We can not
8639 distinguish prototyped and unprototyped functions; default to
8640 prototyped, since that is more common in modern code (and
8641 RealView warns about unprototyped functions). */
8642 TYPE_PROTOTYPED (ftype
) = 1;
8644 /* Store the calling convention in the type if it's available in
8645 the subroutine die. Otherwise set the calling convention to
8646 the default value DW_CC_normal. */
8647 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
8649 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
8650 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
8651 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
8653 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
8655 /* We need to add the subroutine type to the die immediately so
8656 we don't infinitely recurse when dealing with parameters
8657 declared as the same subroutine type. */
8658 set_die_type (die
, ftype
, cu
);
8660 if (die
->child
!= NULL
)
8662 struct type
*void_type
= objfile_type (cu
->objfile
)->builtin_void
;
8663 struct die_info
*child_die
;
8664 int nparams
, iparams
;
8666 /* Count the number of parameters.
8667 FIXME: GDB currently ignores vararg functions, but knows about
8668 vararg member functions. */
8670 child_die
= die
->child
;
8671 while (child_die
&& child_die
->tag
)
8673 if (child_die
->tag
== DW_TAG_formal_parameter
)
8675 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
8676 TYPE_VARARGS (ftype
) = 1;
8677 child_die
= sibling_die (child_die
);
8680 /* Allocate storage for parameters and fill them in. */
8681 TYPE_NFIELDS (ftype
) = nparams
;
8682 TYPE_FIELDS (ftype
) = (struct field
*)
8683 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
8685 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
8686 even if we error out during the parameters reading below. */
8687 for (iparams
= 0; iparams
< nparams
; iparams
++)
8688 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
8691 child_die
= die
->child
;
8692 while (child_die
&& child_die
->tag
)
8694 if (child_die
->tag
== DW_TAG_formal_parameter
)
8696 struct type
*arg_type
;
8698 /* DWARF version 2 has no clean way to discern C++
8699 static and non-static member functions. G++ helps
8700 GDB by marking the first parameter for non-static
8701 member functions (which is the this pointer) as
8702 artificial. We pass this information to
8703 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
8705 DWARF version 3 added DW_AT_object_pointer, which GCC
8706 4.5 does not yet generate. */
8707 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
8709 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
8712 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
8714 /* GCC/43521: In java, the formal parameter
8715 "this" is sometimes not marked with DW_AT_artificial. */
8716 if (cu
->language
== language_java
)
8718 const char *name
= dwarf2_name (child_die
, cu
);
8720 if (name
&& !strcmp (name
, "this"))
8721 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
8724 arg_type
= die_type (child_die
, cu
);
8726 /* RealView does not mark THIS as const, which the testsuite
8727 expects. GCC marks THIS as const in method definitions,
8728 but not in the class specifications (GCC PR 43053). */
8729 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
8730 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
8733 struct dwarf2_cu
*arg_cu
= cu
;
8734 const char *name
= dwarf2_name (child_die
, cu
);
8736 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
8739 /* If the compiler emits this, use it. */
8740 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
8743 else if (name
&& strcmp (name
, "this") == 0)
8744 /* Function definitions will have the argument names. */
8746 else if (name
== NULL
&& iparams
== 0)
8747 /* Declarations may not have the names, so like
8748 elsewhere in GDB, assume an artificial first
8749 argument is "this". */
8753 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
8757 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
8760 child_die
= sibling_die (child_die
);
8767 static struct type
*
8768 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
8770 struct objfile
*objfile
= cu
->objfile
;
8771 const char *name
= NULL
;
8772 struct type
*this_type
;
8774 name
= dwarf2_full_name (NULL
, die
, cu
);
8775 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
8776 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
8777 TYPE_NAME (this_type
) = (char *) name
;
8778 set_die_type (die
, this_type
, cu
);
8779 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
8783 /* Find a representation of a given base type and install
8784 it in the TYPE field of the die. */
8786 static struct type
*
8787 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8789 struct objfile
*objfile
= cu
->objfile
;
8791 struct attribute
*attr
;
8792 int encoding
= 0, size
= 0;
8794 enum type_code code
= TYPE_CODE_INT
;
8796 struct type
*target_type
= NULL
;
8798 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
8801 encoding
= DW_UNSND (attr
);
8803 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8806 size
= DW_UNSND (attr
);
8808 name
= dwarf2_name (die
, cu
);
8811 complaint (&symfile_complaints
,
8812 _("DW_AT_name missing from DW_TAG_base_type"));
8817 case DW_ATE_address
:
8818 /* Turn DW_ATE_address into a void * pointer. */
8819 code
= TYPE_CODE_PTR
;
8820 type_flags
|= TYPE_FLAG_UNSIGNED
;
8821 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
8823 case DW_ATE_boolean
:
8824 code
= TYPE_CODE_BOOL
;
8825 type_flags
|= TYPE_FLAG_UNSIGNED
;
8827 case DW_ATE_complex_float
:
8828 code
= TYPE_CODE_COMPLEX
;
8829 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
8831 case DW_ATE_decimal_float
:
8832 code
= TYPE_CODE_DECFLOAT
;
8835 code
= TYPE_CODE_FLT
;
8839 case DW_ATE_unsigned
:
8840 type_flags
|= TYPE_FLAG_UNSIGNED
;
8841 if (cu
->language
== language_fortran
8843 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
8844 code
= TYPE_CODE_CHAR
;
8846 case DW_ATE_signed_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
;
8852 case DW_ATE_unsigned_char
:
8853 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8854 || cu
->language
== language_pascal
8855 || cu
->language
== language_fortran
)
8856 code
= TYPE_CODE_CHAR
;
8857 type_flags
|= TYPE_FLAG_UNSIGNED
;
8860 /* We just treat this as an integer and then recognize the
8861 type by name elsewhere. */
8865 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
8866 dwarf_type_encoding_name (encoding
));
8870 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
8871 TYPE_NAME (type
) = name
;
8872 TYPE_TARGET_TYPE (type
) = target_type
;
8874 if (name
&& strcmp (name
, "char") == 0)
8875 TYPE_NOSIGN (type
) = 1;
8877 return set_die_type (die
, type
, cu
);
8880 /* Read the given DW_AT_subrange DIE. */
8882 static struct type
*
8883 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8885 struct type
*base_type
;
8886 struct type
*range_type
;
8887 struct attribute
*attr
;
8891 LONGEST negative_mask
;
8893 base_type
= die_type (die
, cu
);
8894 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
8895 check_typedef (base_type
);
8897 /* The die_type call above may have already set the type for this DIE. */
8898 range_type
= get_die_type (die
, cu
);
8902 if (cu
->language
== language_fortran
)
8904 /* FORTRAN implies a lower bound of 1, if not given. */
8908 /* FIXME: For variable sized arrays either of these could be
8909 a variable rather than a constant value. We'll allow it,
8910 but we don't know how to handle it. */
8911 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
8913 low
= dwarf2_get_attr_constant_value (attr
, 0);
8915 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
8918 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
8920 /* GCC encodes arrays with unspecified or dynamic length
8921 with a DW_FORM_block1 attribute or a reference attribute.
8922 FIXME: GDB does not yet know how to handle dynamic
8923 arrays properly, treat them as arrays with unspecified
8926 FIXME: jimb/2003-09-22: GDB does not really know
8927 how to handle arrays of unspecified length
8928 either; we just represent them as zero-length
8929 arrays. Choose an appropriate upper bound given
8930 the lower bound we've computed above. */
8934 high
= dwarf2_get_attr_constant_value (attr
, 1);
8938 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
8941 int count
= dwarf2_get_attr_constant_value (attr
, 1);
8942 high
= low
+ count
- 1;
8946 /* Unspecified array length. */
8951 /* Dwarf-2 specifications explicitly allows to create subrange types
8952 without specifying a base type.
8953 In that case, the base type must be set to the type of
8954 the lower bound, upper bound or count, in that order, if any of these
8955 three attributes references an object that has a type.
8956 If no base type is found, the Dwarf-2 specifications say that
8957 a signed integer type of size equal to the size of an address should
8959 For the following C code: `extern char gdb_int [];'
8960 GCC produces an empty range DIE.
8961 FIXME: muller/2010-05-28: Possible references to object for low bound,
8962 high bound or count are not yet handled by this code. */
8963 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
8965 struct objfile
*objfile
= cu
->objfile
;
8966 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8967 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
8968 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
8970 /* Test "int", "long int", and "long long int" objfile types,
8971 and select the first one having a size above or equal to the
8972 architecture address size. */
8973 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8974 base_type
= int_type
;
8977 int_type
= objfile_type (objfile
)->builtin_long
;
8978 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8979 base_type
= int_type
;
8982 int_type
= objfile_type (objfile
)->builtin_long_long
;
8983 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8984 base_type
= int_type
;
8990 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
8991 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
8992 low
|= negative_mask
;
8993 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
8994 high
|= negative_mask
;
8996 range_type
= create_range_type (NULL
, base_type
, low
, high
);
8998 /* Mark arrays with dynamic length at least as an array of unspecified
8999 length. GDB could check the boundary but before it gets implemented at
9000 least allow accessing the array elements. */
9001 if (attr
&& attr_form_is_block (attr
))
9002 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
9004 /* Ada expects an empty array on no boundary attributes. */
9005 if (attr
== NULL
&& cu
->language
!= language_ada
)
9006 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
9008 name
= dwarf2_name (die
, cu
);
9010 TYPE_NAME (range_type
) = name
;
9012 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9014 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
9016 set_die_type (die
, range_type
, cu
);
9018 /* set_die_type should be already done. */
9019 set_descriptive_type (range_type
, die
, cu
);
9024 static struct type
*
9025 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9029 /* For now, we only support the C meaning of an unspecified type: void. */
9031 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
9032 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
9034 return set_die_type (die
, type
, cu
);
9037 /* Trivial hash function for die_info: the hash value of a DIE
9038 is its offset in .debug_info for this objfile. */
9041 die_hash (const void *item
)
9043 const struct die_info
*die
= item
;
9048 /* Trivial comparison function for die_info structures: two DIEs
9049 are equal if they have the same offset. */
9052 die_eq (const void *item_lhs
, const void *item_rhs
)
9054 const struct die_info
*die_lhs
= item_lhs
;
9055 const struct die_info
*die_rhs
= item_rhs
;
9057 return die_lhs
->offset
== die_rhs
->offset
;
9060 /* Read a whole compilation unit into a linked list of dies. */
9062 static struct die_info
*
9063 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
9065 struct die_reader_specs reader_specs
;
9066 int read_abbrevs
= 0;
9067 struct cleanup
*back_to
= NULL
;
9068 struct die_info
*die
;
9070 if (cu
->dwarf2_abbrevs
== NULL
)
9072 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
9073 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
9077 gdb_assert (cu
->die_hash
== NULL
);
9079 = htab_create_alloc_ex (cu
->header
.length
/ 12,
9083 &cu
->comp_unit_obstack
,
9084 hashtab_obstack_allocate
,
9085 dummy_obstack_deallocate
);
9087 init_cu_die_reader (&reader_specs
, cu
);
9089 die
= read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
9092 do_cleanups (back_to
);
9097 /* Main entry point for reading a DIE and all children.
9098 Read the DIE and dump it if requested. */
9100 static struct die_info
*
9101 read_die_and_children (const struct die_reader_specs
*reader
,
9103 gdb_byte
**new_info_ptr
,
9104 struct die_info
*parent
)
9106 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
9107 new_info_ptr
, parent
);
9109 if (dwarf2_die_debug
)
9111 fprintf_unfiltered (gdb_stdlog
,
9112 "\nRead die from %s of %s:\n",
9113 (reader
->cu
->per_cu
->debug_type_section
9116 reader
->abfd
->filename
);
9117 dump_die (result
, dwarf2_die_debug
);
9123 /* Read a single die and all its descendents. Set the die's sibling
9124 field to NULL; set other fields in the die correctly, and set all
9125 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
9126 location of the info_ptr after reading all of those dies. PARENT
9127 is the parent of the die in question. */
9129 static struct die_info
*
9130 read_die_and_children_1 (const struct die_reader_specs
*reader
,
9132 gdb_byte
**new_info_ptr
,
9133 struct die_info
*parent
)
9135 struct die_info
*die
;
9139 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
9142 *new_info_ptr
= cur_ptr
;
9145 store_in_ref_table (die
, reader
->cu
);
9148 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
9152 *new_info_ptr
= cur_ptr
;
9155 die
->sibling
= NULL
;
9156 die
->parent
= parent
;
9160 /* Read a die, all of its descendents, and all of its siblings; set
9161 all of the fields of all of the dies correctly. Arguments are as
9162 in read_die_and_children. */
9164 static struct die_info
*
9165 read_die_and_siblings (const struct die_reader_specs
*reader
,
9167 gdb_byte
**new_info_ptr
,
9168 struct die_info
*parent
)
9170 struct die_info
*first_die
, *last_sibling
;
9174 first_die
= last_sibling
= NULL
;
9178 struct die_info
*die
9179 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
9183 *new_info_ptr
= cur_ptr
;
9190 last_sibling
->sibling
= die
;
9196 /* Read the die from the .debug_info section buffer. Set DIEP to
9197 point to a newly allocated die with its information, except for its
9198 child, sibling, and parent fields. Set HAS_CHILDREN to tell
9199 whether the die has children or not. */
9202 read_full_die (const struct die_reader_specs
*reader
,
9203 struct die_info
**diep
, gdb_byte
*info_ptr
,
9206 unsigned int abbrev_number
, bytes_read
, i
, offset
;
9207 struct abbrev_info
*abbrev
;
9208 struct die_info
*die
;
9209 struct dwarf2_cu
*cu
= reader
->cu
;
9210 bfd
*abfd
= reader
->abfd
;
9212 offset
= info_ptr
- reader
->buffer
;
9213 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9214 info_ptr
+= bytes_read
;
9222 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
9224 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
9226 bfd_get_filename (abfd
));
9228 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
9229 die
->offset
= offset
;
9230 die
->tag
= abbrev
->tag
;
9231 die
->abbrev
= abbrev_number
;
9233 die
->num_attrs
= abbrev
->num_attrs
;
9235 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9236 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
9237 abfd
, info_ptr
, cu
);
9240 *has_children
= abbrev
->has_children
;
9244 /* In DWARF version 2, the description of the debugging information is
9245 stored in a separate .debug_abbrev section. Before we read any
9246 dies from a section we read in all abbreviations and install them
9247 in a hash table. This function also sets flags in CU describing
9248 the data found in the abbrev table. */
9251 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
9253 struct comp_unit_head
*cu_header
= &cu
->header
;
9254 gdb_byte
*abbrev_ptr
;
9255 struct abbrev_info
*cur_abbrev
;
9256 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
9257 unsigned int abbrev_form
, hash_number
;
9258 struct attr_abbrev
*cur_attrs
;
9259 unsigned int allocated_attrs
;
9261 /* Initialize dwarf2 abbrevs. */
9262 obstack_init (&cu
->abbrev_obstack
);
9263 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
9265 * sizeof (struct abbrev_info
*)));
9266 memset (cu
->dwarf2_abbrevs
, 0,
9267 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
9269 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
9270 &dwarf2_per_objfile
->abbrev
);
9271 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
9272 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9273 abbrev_ptr
+= bytes_read
;
9275 allocated_attrs
= ATTR_ALLOC_CHUNK
;
9276 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
9278 /* Loop until we reach an abbrev number of 0. */
9279 while (abbrev_number
)
9281 cur_abbrev
= dwarf_alloc_abbrev (cu
);
9283 /* read in abbrev header */
9284 cur_abbrev
->number
= abbrev_number
;
9285 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9286 abbrev_ptr
+= bytes_read
;
9287 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
9290 if (cur_abbrev
->tag
== DW_TAG_namespace
)
9291 cu
->has_namespace_info
= 1;
9293 /* now read in declarations */
9294 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9295 abbrev_ptr
+= bytes_read
;
9296 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9297 abbrev_ptr
+= bytes_read
;
9300 if (cur_abbrev
->num_attrs
== allocated_attrs
)
9302 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
9304 = xrealloc (cur_attrs
, (allocated_attrs
9305 * sizeof (struct attr_abbrev
)));
9308 /* Record whether this compilation unit might have
9309 inter-compilation-unit references. If we don't know what form
9310 this attribute will have, then it might potentially be a
9311 DW_FORM_ref_addr, so we conservatively expect inter-CU
9314 if (abbrev_form
== DW_FORM_ref_addr
9315 || abbrev_form
== DW_FORM_indirect
)
9316 cu
->has_form_ref_addr
= 1;
9318 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
9319 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
9320 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9321 abbrev_ptr
+= bytes_read
;
9322 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9323 abbrev_ptr
+= bytes_read
;
9326 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
9327 (cur_abbrev
->num_attrs
9328 * sizeof (struct attr_abbrev
)));
9329 memcpy (cur_abbrev
->attrs
, cur_attrs
,
9330 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
9332 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
9333 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
9334 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
9336 /* Get next abbreviation.
9337 Under Irix6 the abbreviations for a compilation unit are not
9338 always properly terminated with an abbrev number of 0.
9339 Exit loop if we encounter an abbreviation which we have
9340 already read (which means we are about to read the abbreviations
9341 for the next compile unit) or if the end of the abbreviation
9342 table is reached. */
9343 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
9344 >= dwarf2_per_objfile
->abbrev
.size
)
9346 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
9347 abbrev_ptr
+= bytes_read
;
9348 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
9355 /* Release the memory used by the abbrev table for a compilation unit. */
9358 dwarf2_free_abbrev_table (void *ptr_to_cu
)
9360 struct dwarf2_cu
*cu
= ptr_to_cu
;
9362 obstack_free (&cu
->abbrev_obstack
, NULL
);
9363 cu
->dwarf2_abbrevs
= NULL
;
9366 /* Lookup an abbrev_info structure in the abbrev hash table. */
9368 static struct abbrev_info
*
9369 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
9371 unsigned int hash_number
;
9372 struct abbrev_info
*abbrev
;
9374 hash_number
= number
% ABBREV_HASH_SIZE
;
9375 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
9379 if (abbrev
->number
== number
)
9382 abbrev
= abbrev
->next
;
9387 /* Returns nonzero if TAG represents a type that we might generate a partial
9391 is_type_tag_for_partial (int tag
)
9396 /* Some types that would be reasonable to generate partial symbols for,
9397 that we don't at present. */
9398 case DW_TAG_array_type
:
9399 case DW_TAG_file_type
:
9400 case DW_TAG_ptr_to_member_type
:
9401 case DW_TAG_set_type
:
9402 case DW_TAG_string_type
:
9403 case DW_TAG_subroutine_type
:
9405 case DW_TAG_base_type
:
9406 case DW_TAG_class_type
:
9407 case DW_TAG_interface_type
:
9408 case DW_TAG_enumeration_type
:
9409 case DW_TAG_structure_type
:
9410 case DW_TAG_subrange_type
:
9411 case DW_TAG_typedef
:
9412 case DW_TAG_union_type
:
9419 /* Load all DIEs that are interesting for partial symbols into memory. */
9421 static struct partial_die_info
*
9422 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9423 int building_psymtab
, struct dwarf2_cu
*cu
)
9425 struct partial_die_info
*part_die
;
9426 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
9427 struct abbrev_info
*abbrev
;
9428 unsigned int bytes_read
;
9429 unsigned int load_all
= 0;
9431 int nesting_level
= 1;
9436 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
9440 = htab_create_alloc_ex (cu
->header
.length
/ 12,
9444 &cu
->comp_unit_obstack
,
9445 hashtab_obstack_allocate
,
9446 dummy_obstack_deallocate
);
9448 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9449 sizeof (struct partial_die_info
));
9453 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
9455 /* A NULL abbrev means the end of a series of children. */
9458 if (--nesting_level
== 0)
9460 /* PART_DIE was probably the last thing allocated on the
9461 comp_unit_obstack, so we could call obstack_free
9462 here. We don't do that because the waste is small,
9463 and will be cleaned up when we're done with this
9464 compilation unit. This way, we're also more robust
9465 against other users of the comp_unit_obstack. */
9468 info_ptr
+= bytes_read
;
9469 last_die
= parent_die
;
9470 parent_die
= parent_die
->die_parent
;
9474 /* Check for template arguments. We never save these; if
9475 they're seen, we just mark the parent, and go on our way. */
9476 if (parent_die
!= NULL
9477 && cu
->language
== language_cplus
9478 && (abbrev
->tag
== DW_TAG_template_type_param
9479 || abbrev
->tag
== DW_TAG_template_value_param
))
9481 parent_die
->has_template_arguments
= 1;
9485 /* We don't need a partial DIE for the template argument. */
9486 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
,
9492 /* We only recurse into subprograms looking for template arguments.
9493 Skip their other children. */
9495 && cu
->language
== language_cplus
9496 && parent_die
!= NULL
9497 && parent_die
->tag
== DW_TAG_subprogram
)
9499 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
9503 /* Check whether this DIE is interesting enough to save. Normally
9504 we would not be interested in members here, but there may be
9505 later variables referencing them via DW_AT_specification (for
9508 && !is_type_tag_for_partial (abbrev
->tag
)
9509 && abbrev
->tag
!= DW_TAG_constant
9510 && abbrev
->tag
!= DW_TAG_enumerator
9511 && abbrev
->tag
!= DW_TAG_subprogram
9512 && abbrev
->tag
!= DW_TAG_lexical_block
9513 && abbrev
->tag
!= DW_TAG_variable
9514 && abbrev
->tag
!= DW_TAG_namespace
9515 && abbrev
->tag
!= DW_TAG_module
9516 && abbrev
->tag
!= DW_TAG_member
)
9518 /* Otherwise we skip to the next sibling, if any. */
9519 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
9523 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
9524 buffer
, info_ptr
, cu
);
9526 /* This two-pass algorithm for processing partial symbols has a
9527 high cost in cache pressure. Thus, handle some simple cases
9528 here which cover the majority of C partial symbols. DIEs
9529 which neither have specification tags in them, nor could have
9530 specification tags elsewhere pointing at them, can simply be
9531 processed and discarded.
9533 This segment is also optional; scan_partial_symbols and
9534 add_partial_symbol will handle these DIEs if we chain
9535 them in normally. When compilers which do not emit large
9536 quantities of duplicate debug information are more common,
9537 this code can probably be removed. */
9539 /* Any complete simple types at the top level (pretty much all
9540 of them, for a language without namespaces), can be processed
9542 if (parent_die
== NULL
9543 && part_die
->has_specification
== 0
9544 && part_die
->is_declaration
== 0
9545 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
9546 || part_die
->tag
== DW_TAG_base_type
9547 || part_die
->tag
== DW_TAG_subrange_type
))
9549 if (building_psymtab
&& part_die
->name
!= NULL
)
9550 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9551 VAR_DOMAIN
, LOC_TYPEDEF
,
9552 &cu
->objfile
->static_psymbols
,
9553 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
9554 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9558 /* The exception for DW_TAG_typedef with has_children above is
9559 a workaround of GCC PR debug/47510. In the case of this complaint
9560 type_name_no_tag_or_error will error on such types later.
9562 GDB skipped children of DW_TAG_typedef by the shortcut above and then
9563 it could not find the child DIEs referenced later, this is checked
9564 above. In correct DWARF DW_TAG_typedef should have no children. */
9566 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
9567 complaint (&symfile_complaints
,
9568 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
9569 "- DIE at 0x%x [in module %s]"),
9570 part_die
->offset
, cu
->objfile
->name
);
9572 /* If we're at the second level, and we're an enumerator, and
9573 our parent has no specification (meaning possibly lives in a
9574 namespace elsewhere), then we can add the partial symbol now
9575 instead of queueing it. */
9576 if (part_die
->tag
== DW_TAG_enumerator
9577 && parent_die
!= NULL
9578 && parent_die
->die_parent
== NULL
9579 && parent_die
->tag
== DW_TAG_enumeration_type
9580 && parent_die
->has_specification
== 0)
9582 if (part_die
->name
== NULL
)
9583 complaint (&symfile_complaints
,
9584 _("malformed enumerator DIE ignored"));
9585 else if (building_psymtab
)
9586 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9587 VAR_DOMAIN
, LOC_CONST
,
9588 (cu
->language
== language_cplus
9589 || cu
->language
== language_java
)
9590 ? &cu
->objfile
->global_psymbols
9591 : &cu
->objfile
->static_psymbols
,
9592 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
9594 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9598 /* We'll save this DIE so link it in. */
9599 part_die
->die_parent
= parent_die
;
9600 part_die
->die_sibling
= NULL
;
9601 part_die
->die_child
= NULL
;
9603 if (last_die
&& last_die
== parent_die
)
9604 last_die
->die_child
= part_die
;
9606 last_die
->die_sibling
= part_die
;
9608 last_die
= part_die
;
9610 if (first_die
== NULL
)
9611 first_die
= part_die
;
9613 /* Maybe add the DIE to the hash table. Not all DIEs that we
9614 find interesting need to be in the hash table, because we
9615 also have the parent/sibling/child chains; only those that we
9616 might refer to by offset later during partial symbol reading.
9618 For now this means things that might have be the target of a
9619 DW_AT_specification, DW_AT_abstract_origin, or
9620 DW_AT_extension. DW_AT_extension will refer only to
9621 namespaces; DW_AT_abstract_origin refers to functions (and
9622 many things under the function DIE, but we do not recurse
9623 into function DIEs during partial symbol reading) and
9624 possibly variables as well; DW_AT_specification refers to
9625 declarations. Declarations ought to have the DW_AT_declaration
9626 flag. It happens that GCC forgets to put it in sometimes, but
9627 only for functions, not for types.
9629 Adding more things than necessary to the hash table is harmless
9630 except for the performance cost. Adding too few will result in
9631 wasted time in find_partial_die, when we reread the compilation
9632 unit with load_all_dies set. */
9635 || abbrev
->tag
== DW_TAG_constant
9636 || abbrev
->tag
== DW_TAG_subprogram
9637 || abbrev
->tag
== DW_TAG_variable
9638 || abbrev
->tag
== DW_TAG_namespace
9639 || part_die
->is_declaration
)
9643 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
9644 part_die
->offset
, INSERT
);
9648 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9649 sizeof (struct partial_die_info
));
9651 /* For some DIEs we want to follow their children (if any). For C
9652 we have no reason to follow the children of structures; for other
9653 languages we have to, so that we can get at method physnames
9654 to infer fully qualified class names, for DW_AT_specification,
9655 and for C++ template arguments. For C++, we also look one level
9656 inside functions to find template arguments (if the name of the
9657 function does not already contain the template arguments).
9659 For Ada, we need to scan the children of subprograms and lexical
9660 blocks as well because Ada allows the definition of nested
9661 entities that could be interesting for the debugger, such as
9662 nested subprograms for instance. */
9663 if (last_die
->has_children
9665 || last_die
->tag
== DW_TAG_namespace
9666 || last_die
->tag
== DW_TAG_module
9667 || last_die
->tag
== DW_TAG_enumeration_type
9668 || (cu
->language
== language_cplus
9669 && last_die
->tag
== DW_TAG_subprogram
9670 && (last_die
->name
== NULL
9671 || strchr (last_die
->name
, '<') == NULL
))
9672 || (cu
->language
!= language_c
9673 && (last_die
->tag
== DW_TAG_class_type
9674 || last_die
->tag
== DW_TAG_interface_type
9675 || last_die
->tag
== DW_TAG_structure_type
9676 || last_die
->tag
== DW_TAG_union_type
))
9677 || (cu
->language
== language_ada
9678 && (last_die
->tag
== DW_TAG_subprogram
9679 || last_die
->tag
== DW_TAG_lexical_block
))))
9682 parent_die
= last_die
;
9686 /* Otherwise we skip to the next sibling, if any. */
9687 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
9689 /* Back to the top, do it again. */
9693 /* Read a minimal amount of information into the minimal die structure. */
9696 read_partial_die (struct partial_die_info
*part_die
,
9697 struct abbrev_info
*abbrev
,
9698 unsigned int abbrev_len
, bfd
*abfd
,
9699 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9700 struct dwarf2_cu
*cu
)
9703 struct attribute attr
;
9704 int has_low_pc_attr
= 0;
9705 int has_high_pc_attr
= 0;
9707 memset (part_die
, 0, sizeof (struct partial_die_info
));
9709 part_die
->offset
= info_ptr
- buffer
;
9711 info_ptr
+= abbrev_len
;
9716 part_die
->tag
= abbrev
->tag
;
9717 part_die
->has_children
= abbrev
->has_children
;
9719 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9721 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
9723 /* Store the data if it is of an attribute we want to keep in a
9724 partial symbol table. */
9728 switch (part_die
->tag
)
9730 case DW_TAG_compile_unit
:
9731 case DW_TAG_type_unit
:
9732 /* Compilation units have a DW_AT_name that is a filename, not
9733 a source language identifier. */
9734 case DW_TAG_enumeration_type
:
9735 case DW_TAG_enumerator
:
9736 /* These tags always have simple identifiers already; no need
9737 to canonicalize them. */
9738 part_die
->name
= DW_STRING (&attr
);
9742 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
9743 &cu
->objfile
->objfile_obstack
);
9747 case DW_AT_linkage_name
:
9748 case DW_AT_MIPS_linkage_name
:
9749 /* Note that both forms of linkage name might appear. We
9750 assume they will be the same, and we only store the last
9752 if (cu
->language
== language_ada
)
9753 part_die
->name
= DW_STRING (&attr
);
9754 part_die
->linkage_name
= DW_STRING (&attr
);
9757 has_low_pc_attr
= 1;
9758 part_die
->lowpc
= DW_ADDR (&attr
);
9761 has_high_pc_attr
= 1;
9762 part_die
->highpc
= DW_ADDR (&attr
);
9764 case DW_AT_location
:
9765 /* Support the .debug_loc offsets. */
9766 if (attr_form_is_block (&attr
))
9768 part_die
->locdesc
= DW_BLOCK (&attr
);
9770 else if (attr_form_is_section_offset (&attr
))
9772 dwarf2_complex_location_expr_complaint ();
9776 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9777 "partial symbol information");
9780 case DW_AT_external
:
9781 part_die
->is_external
= DW_UNSND (&attr
);
9783 case DW_AT_declaration
:
9784 part_die
->is_declaration
= DW_UNSND (&attr
);
9787 part_die
->has_type
= 1;
9789 case DW_AT_abstract_origin
:
9790 case DW_AT_specification
:
9791 case DW_AT_extension
:
9792 part_die
->has_specification
= 1;
9793 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
9796 /* Ignore absolute siblings, they might point outside of
9797 the current compile unit. */
9798 if (attr
.form
== DW_FORM_ref_addr
)
9799 complaint (&symfile_complaints
,
9800 _("ignoring absolute DW_AT_sibling"));
9802 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
9804 case DW_AT_byte_size
:
9805 part_die
->has_byte_size
= 1;
9807 case DW_AT_calling_convention
:
9808 /* DWARF doesn't provide a way to identify a program's source-level
9809 entry point. DW_AT_calling_convention attributes are only meant
9810 to describe functions' calling conventions.
9812 However, because it's a necessary piece of information in
9813 Fortran, and because DW_CC_program is the only piece of debugging
9814 information whose definition refers to a 'main program' at all,
9815 several compilers have begun marking Fortran main programs with
9816 DW_CC_program --- even when those functions use the standard
9817 calling conventions.
9819 So until DWARF specifies a way to provide this information and
9820 compilers pick up the new representation, we'll support this
9822 if (DW_UNSND (&attr
) == DW_CC_program
9823 && cu
->language
== language_fortran
)
9825 set_main_name (part_die
->name
);
9827 /* As this DIE has a static linkage the name would be difficult
9828 to look up later. */
9829 language_of_main
= language_fortran
;
9837 if (has_low_pc_attr
&& has_high_pc_attr
)
9839 /* When using the GNU linker, .gnu.linkonce. sections are used to
9840 eliminate duplicate copies of functions and vtables and such.
9841 The linker will arbitrarily choose one and discard the others.
9842 The AT_*_pc values for such functions refer to local labels in
9843 these sections. If the section from that file was discarded, the
9844 labels are not in the output, so the relocs get a value of 0.
9845 If this is a discarded function, mark the pc bounds as invalid,
9846 so that GDB will ignore it. */
9847 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
9849 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
9851 complaint (&symfile_complaints
,
9852 _("DW_AT_low_pc %s is zero "
9853 "for DIE at 0x%x [in module %s]"),
9854 paddress (gdbarch
, part_die
->lowpc
),
9855 part_die
->offset
, cu
->objfile
->name
);
9857 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
9858 else if (part_die
->lowpc
>= part_die
->highpc
)
9860 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
9862 complaint (&symfile_complaints
,
9863 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
9864 "for DIE at 0x%x [in module %s]"),
9865 paddress (gdbarch
, part_die
->lowpc
),
9866 paddress (gdbarch
, part_die
->highpc
),
9867 part_die
->offset
, cu
->objfile
->name
);
9870 part_die
->has_pc_info
= 1;
9876 /* Find a cached partial DIE at OFFSET in CU. */
9878 static struct partial_die_info
*
9879 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
9881 struct partial_die_info
*lookup_die
= NULL
;
9882 struct partial_die_info part_die
;
9884 part_die
.offset
= offset
;
9885 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
9890 /* Find a partial DIE at OFFSET, which may or may not be in CU,
9891 except in the case of .debug_types DIEs which do not reference
9892 outside their CU (they do however referencing other types via
9893 DW_FORM_ref_sig8). */
9895 static struct partial_die_info
*
9896 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
9898 struct dwarf2_per_cu_data
*per_cu
= NULL
;
9899 struct partial_die_info
*pd
= NULL
;
9901 if (cu
->per_cu
->debug_type_section
)
9903 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9909 if (offset_in_cu_p (&cu
->header
, offset
))
9911 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9916 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
9918 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
9919 load_partial_comp_unit (per_cu
, cu
->objfile
);
9921 per_cu
->cu
->last_used
= 0;
9922 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
9924 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
9926 struct cleanup
*back_to
;
9927 struct partial_die_info comp_unit_die
;
9928 struct abbrev_info
*abbrev
;
9929 unsigned int bytes_read
;
9932 per_cu
->load_all_dies
= 1;
9934 /* Re-read the DIEs. */
9935 back_to
= make_cleanup (null_cleanup
, 0);
9936 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
9938 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
9939 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
9941 info_ptr
= (dwarf2_per_objfile
->info
.buffer
9942 + per_cu
->cu
->header
.offset
9943 + per_cu
->cu
->header
.first_die_offset
);
9944 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
9945 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
9946 per_cu
->cu
->objfile
->obfd
,
9947 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
9949 if (comp_unit_die
.has_children
)
9950 load_partial_dies (per_cu
->cu
->objfile
->obfd
,
9951 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
9953 do_cleanups (back_to
);
9955 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
9961 internal_error (__FILE__
, __LINE__
,
9962 _("could not find partial DIE 0x%x "
9963 "in cache [from module %s]\n"),
9964 offset
, bfd_get_filename (cu
->objfile
->obfd
));
9968 /* See if we can figure out if the class lives in a namespace. We do
9969 this by looking for a member function; its demangled name will
9970 contain namespace info, if there is any. */
9973 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
9974 struct dwarf2_cu
*cu
)
9976 /* NOTE: carlton/2003-10-07: Getting the info this way changes
9977 what template types look like, because the demangler
9978 frequently doesn't give the same name as the debug info. We
9979 could fix this by only using the demangled name to get the
9980 prefix (but see comment in read_structure_type). */
9982 struct partial_die_info
*real_pdi
;
9983 struct partial_die_info
*child_pdi
;
9985 /* If this DIE (this DIE's specification, if any) has a parent, then
9986 we should not do this. We'll prepend the parent's fully qualified
9987 name when we create the partial symbol. */
9989 real_pdi
= struct_pdi
;
9990 while (real_pdi
->has_specification
)
9991 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
9993 if (real_pdi
->die_parent
!= NULL
)
9996 for (child_pdi
= struct_pdi
->die_child
;
9998 child_pdi
= child_pdi
->die_sibling
)
10000 if (child_pdi
->tag
== DW_TAG_subprogram
10001 && child_pdi
->linkage_name
!= NULL
)
10003 char *actual_class_name
10004 = language_class_name_from_physname (cu
->language_defn
,
10005 child_pdi
->linkage_name
);
10006 if (actual_class_name
!= NULL
)
10009 = obsavestring (actual_class_name
,
10010 strlen (actual_class_name
),
10011 &cu
->objfile
->objfile_obstack
);
10012 xfree (actual_class_name
);
10019 /* Adjust PART_DIE before generating a symbol for it. This function
10020 may set the is_external flag or change the DIE's name. */
10023 fixup_partial_die (struct partial_die_info
*part_die
,
10024 struct dwarf2_cu
*cu
)
10026 /* Once we've fixed up a die, there's no point in doing so again.
10027 This also avoids a memory leak if we were to call
10028 guess_partial_die_structure_name multiple times. */
10029 if (part_die
->fixup_called
)
10032 /* If we found a reference attribute and the DIE has no name, try
10033 to find a name in the referred to DIE. */
10035 if (part_die
->name
== NULL
&& part_die
->has_specification
)
10037 struct partial_die_info
*spec_die
;
10039 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
10041 fixup_partial_die (spec_die
, cu
);
10043 if (spec_die
->name
)
10045 part_die
->name
= spec_die
->name
;
10047 /* Copy DW_AT_external attribute if it is set. */
10048 if (spec_die
->is_external
)
10049 part_die
->is_external
= spec_die
->is_external
;
10053 /* Set default names for some unnamed DIEs. */
10055 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
10056 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
10058 /* If there is no parent die to provide a namespace, and there are
10059 children, see if we can determine the namespace from their linkage
10061 NOTE: We need to do this even if cu->has_namespace_info != 0.
10062 gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */
10063 if (cu
->language
== language_cplus
10064 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
10065 && part_die
->die_parent
== NULL
10066 && part_die
->has_children
10067 && (part_die
->tag
== DW_TAG_class_type
10068 || part_die
->tag
== DW_TAG_structure_type
10069 || part_die
->tag
== DW_TAG_union_type
))
10070 guess_partial_die_structure_name (part_die
, cu
);
10072 /* GCC might emit a nameless struct or union that has a linkage
10073 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
10074 if (part_die
->name
== NULL
10075 && (part_die
->tag
== DW_TAG_class_type
10076 || part_die
->tag
== DW_TAG_interface_type
10077 || part_die
->tag
== DW_TAG_structure_type
10078 || part_die
->tag
== DW_TAG_union_type
)
10079 && part_die
->linkage_name
!= NULL
)
10083 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
10088 /* Strip any leading namespaces/classes, keep only the base name.
10089 DW_AT_name for named DIEs does not contain the prefixes. */
10090 base
= strrchr (demangled
, ':');
10091 if (base
&& base
> demangled
&& base
[-1] == ':')
10096 part_die
->name
= obsavestring (base
, strlen (base
),
10097 &cu
->objfile
->objfile_obstack
);
10102 part_die
->fixup_called
= 1;
10105 /* Read an attribute value described by an attribute form. */
10108 read_attribute_value (struct attribute
*attr
, unsigned form
,
10109 bfd
*abfd
, gdb_byte
*info_ptr
,
10110 struct dwarf2_cu
*cu
)
10112 struct comp_unit_head
*cu_header
= &cu
->header
;
10113 unsigned int bytes_read
;
10114 struct dwarf_block
*blk
;
10119 case DW_FORM_ref_addr
:
10120 if (cu
->header
.version
== 2)
10121 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
10123 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
,
10124 &cu
->header
, &bytes_read
);
10125 info_ptr
+= bytes_read
;
10128 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
10129 info_ptr
+= bytes_read
;
10131 case DW_FORM_block2
:
10132 blk
= dwarf_alloc_block (cu
);
10133 blk
->size
= read_2_bytes (abfd
, info_ptr
);
10135 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10136 info_ptr
+= blk
->size
;
10137 DW_BLOCK (attr
) = blk
;
10139 case DW_FORM_block4
:
10140 blk
= dwarf_alloc_block (cu
);
10141 blk
->size
= read_4_bytes (abfd
, info_ptr
);
10143 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10144 info_ptr
+= blk
->size
;
10145 DW_BLOCK (attr
) = blk
;
10147 case DW_FORM_data2
:
10148 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
10151 case DW_FORM_data4
:
10152 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
10155 case DW_FORM_data8
:
10156 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
10159 case DW_FORM_sec_offset
:
10160 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
10161 info_ptr
+= bytes_read
;
10163 case DW_FORM_string
:
10164 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
10165 DW_STRING_IS_CANONICAL (attr
) = 0;
10166 info_ptr
+= bytes_read
;
10169 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
10171 DW_STRING_IS_CANONICAL (attr
) = 0;
10172 info_ptr
+= bytes_read
;
10174 case DW_FORM_exprloc
:
10175 case DW_FORM_block
:
10176 blk
= dwarf_alloc_block (cu
);
10177 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10178 info_ptr
+= bytes_read
;
10179 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10180 info_ptr
+= blk
->size
;
10181 DW_BLOCK (attr
) = blk
;
10183 case DW_FORM_block1
:
10184 blk
= dwarf_alloc_block (cu
);
10185 blk
->size
= read_1_byte (abfd
, info_ptr
);
10187 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
10188 info_ptr
+= blk
->size
;
10189 DW_BLOCK (attr
) = blk
;
10191 case DW_FORM_data1
:
10192 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
10196 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
10199 case DW_FORM_flag_present
:
10200 DW_UNSND (attr
) = 1;
10202 case DW_FORM_sdata
:
10203 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
10204 info_ptr
+= bytes_read
;
10206 case DW_FORM_udata
:
10207 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10208 info_ptr
+= bytes_read
;
10211 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
10215 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
10219 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
10223 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
10226 case DW_FORM_ref_sig8
:
10227 /* Convert the signature to something we can record in DW_UNSND
10229 NOTE: This is NULL if the type wasn't found. */
10230 DW_SIGNATURED_TYPE (attr
) =
10231 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
10234 case DW_FORM_ref_udata
:
10235 DW_ADDR (attr
) = (cu
->header
.offset
10236 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
10237 info_ptr
+= bytes_read
;
10239 case DW_FORM_indirect
:
10240 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10241 info_ptr
+= bytes_read
;
10242 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
10245 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
10246 dwarf_form_name (form
),
10247 bfd_get_filename (abfd
));
10250 /* We have seen instances where the compiler tried to emit a byte
10251 size attribute of -1 which ended up being encoded as an unsigned
10252 0xffffffff. Although 0xffffffff is technically a valid size value,
10253 an object of this size seems pretty unlikely so we can relatively
10254 safely treat these cases as if the size attribute was invalid and
10255 treat them as zero by default. */
10256 if (attr
->name
== DW_AT_byte_size
10257 && form
== DW_FORM_data4
10258 && DW_UNSND (attr
) >= 0xffffffff)
10261 (&symfile_complaints
,
10262 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
10263 hex_string (DW_UNSND (attr
)));
10264 DW_UNSND (attr
) = 0;
10270 /* Read an attribute described by an abbreviated attribute. */
10273 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
10274 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
10276 attr
->name
= abbrev
->name
;
10277 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
10280 /* Read dwarf information from a buffer. */
10282 static unsigned int
10283 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
10285 return bfd_get_8 (abfd
, buf
);
10289 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
10291 return bfd_get_signed_8 (abfd
, buf
);
10294 static unsigned int
10295 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
10297 return bfd_get_16 (abfd
, buf
);
10301 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
10303 return bfd_get_signed_16 (abfd
, buf
);
10306 static unsigned int
10307 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
10309 return bfd_get_32 (abfd
, buf
);
10313 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
10315 return bfd_get_signed_32 (abfd
, buf
);
10319 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
10321 return bfd_get_64 (abfd
, buf
);
10325 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
10326 unsigned int *bytes_read
)
10328 struct comp_unit_head
*cu_header
= &cu
->header
;
10329 CORE_ADDR retval
= 0;
10331 if (cu_header
->signed_addr_p
)
10333 switch (cu_header
->addr_size
)
10336 retval
= bfd_get_signed_16 (abfd
, buf
);
10339 retval
= bfd_get_signed_32 (abfd
, buf
);
10342 retval
= bfd_get_signed_64 (abfd
, buf
);
10345 internal_error (__FILE__
, __LINE__
,
10346 _("read_address: bad switch, signed [in module %s]"),
10347 bfd_get_filename (abfd
));
10352 switch (cu_header
->addr_size
)
10355 retval
= bfd_get_16 (abfd
, buf
);
10358 retval
= bfd_get_32 (abfd
, buf
);
10361 retval
= bfd_get_64 (abfd
, buf
);
10364 internal_error (__FILE__
, __LINE__
,
10365 _("read_address: bad switch, "
10366 "unsigned [in module %s]"),
10367 bfd_get_filename (abfd
));
10371 *bytes_read
= cu_header
->addr_size
;
10375 /* Read the initial length from a section. The (draft) DWARF 3
10376 specification allows the initial length to take up either 4 bytes
10377 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
10378 bytes describe the length and all offsets will be 8 bytes in length
10381 An older, non-standard 64-bit format is also handled by this
10382 function. The older format in question stores the initial length
10383 as an 8-byte quantity without an escape value. Lengths greater
10384 than 2^32 aren't very common which means that the initial 4 bytes
10385 is almost always zero. Since a length value of zero doesn't make
10386 sense for the 32-bit format, this initial zero can be considered to
10387 be an escape value which indicates the presence of the older 64-bit
10388 format. As written, the code can't detect (old format) lengths
10389 greater than 4GB. If it becomes necessary to handle lengths
10390 somewhat larger than 4GB, we could allow other small values (such
10391 as the non-sensical values of 1, 2, and 3) to also be used as
10392 escape values indicating the presence of the old format.
10394 The value returned via bytes_read should be used to increment the
10395 relevant pointer after calling read_initial_length().
10397 [ Note: read_initial_length() and read_offset() are based on the
10398 document entitled "DWARF Debugging Information Format", revision
10399 3, draft 8, dated November 19, 2001. This document was obtained
10402 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
10404 This document is only a draft and is subject to change. (So beware.)
10406 Details regarding the older, non-standard 64-bit format were
10407 determined empirically by examining 64-bit ELF files produced by
10408 the SGI toolchain on an IRIX 6.5 machine.
10410 - Kevin, July 16, 2002
10414 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
10416 LONGEST length
= bfd_get_32 (abfd
, buf
);
10418 if (length
== 0xffffffff)
10420 length
= bfd_get_64 (abfd
, buf
+ 4);
10423 else if (length
== 0)
10425 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
10426 length
= bfd_get_64 (abfd
, buf
);
10437 /* Cover function for read_initial_length.
10438 Returns the length of the object at BUF, and stores the size of the
10439 initial length in *BYTES_READ and stores the size that offsets will be in
10441 If the initial length size is not equivalent to that specified in
10442 CU_HEADER then issue a complaint.
10443 This is useful when reading non-comp-unit headers. */
10446 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
10447 const struct comp_unit_head
*cu_header
,
10448 unsigned int *bytes_read
,
10449 unsigned int *offset_size
)
10451 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
10453 gdb_assert (cu_header
->initial_length_size
== 4
10454 || cu_header
->initial_length_size
== 8
10455 || cu_header
->initial_length_size
== 12);
10457 if (cu_header
->initial_length_size
!= *bytes_read
)
10458 complaint (&symfile_complaints
,
10459 _("intermixed 32-bit and 64-bit DWARF sections"));
10461 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
10465 /* Read an offset from the data stream. The size of the offset is
10466 given by cu_header->offset_size. */
10469 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
10470 unsigned int *bytes_read
)
10472 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
10474 *bytes_read
= cu_header
->offset_size
;
10478 /* Read an offset from the data stream. */
10481 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
10483 LONGEST retval
= 0;
10485 switch (offset_size
)
10488 retval
= bfd_get_32 (abfd
, buf
);
10491 retval
= bfd_get_64 (abfd
, buf
);
10494 internal_error (__FILE__
, __LINE__
,
10495 _("read_offset_1: bad switch [in module %s]"),
10496 bfd_get_filename (abfd
));
10503 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
10505 /* If the size of a host char is 8 bits, we can return a pointer
10506 to the buffer, otherwise we have to copy the data to a buffer
10507 allocated on the temporary obstack. */
10508 gdb_assert (HOST_CHAR_BIT
== 8);
10513 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10515 /* If the size of a host char is 8 bits, we can return a pointer
10516 to the string, otherwise we have to copy the string to a buffer
10517 allocated on the temporary obstack. */
10518 gdb_assert (HOST_CHAR_BIT
== 8);
10521 *bytes_read_ptr
= 1;
10524 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
10525 return (char *) buf
;
10529 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
10531 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
10532 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
10533 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
10534 bfd_get_filename (abfd
));
10535 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
10536 error (_("DW_FORM_strp pointing outside of "
10537 ".debug_str section [in module %s]"),
10538 bfd_get_filename (abfd
));
10539 gdb_assert (HOST_CHAR_BIT
== 8);
10540 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
10542 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
10546 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
10547 const struct comp_unit_head
*cu_header
,
10548 unsigned int *bytes_read_ptr
)
10550 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
10552 return read_indirect_string_at_offset (abfd
, str_offset
);
10555 static unsigned long
10556 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10558 unsigned long result
;
10559 unsigned int num_read
;
10561 unsigned char byte
;
10569 byte
= bfd_get_8 (abfd
, buf
);
10572 result
|= ((unsigned long)(byte
& 127) << shift
);
10573 if ((byte
& 128) == 0)
10579 *bytes_read_ptr
= num_read
;
10584 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10587 int i
, shift
, num_read
;
10588 unsigned char byte
;
10596 byte
= bfd_get_8 (abfd
, buf
);
10599 result
|= ((long)(byte
& 127) << shift
);
10601 if ((byte
& 128) == 0)
10606 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
10607 result
|= -(((long)1) << shift
);
10608 *bytes_read_ptr
= num_read
;
10612 /* Return a pointer to just past the end of an LEB128 number in BUF. */
10615 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
10621 byte
= bfd_get_8 (abfd
, buf
);
10623 if ((byte
& 128) == 0)
10629 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
10636 cu
->language
= language_c
;
10638 case DW_LANG_C_plus_plus
:
10639 cu
->language
= language_cplus
;
10642 cu
->language
= language_d
;
10644 case DW_LANG_Fortran77
:
10645 case DW_LANG_Fortran90
:
10646 case DW_LANG_Fortran95
:
10647 cu
->language
= language_fortran
;
10649 case DW_LANG_Mips_Assembler
:
10650 cu
->language
= language_asm
;
10653 cu
->language
= language_java
;
10655 case DW_LANG_Ada83
:
10656 case DW_LANG_Ada95
:
10657 cu
->language
= language_ada
;
10659 case DW_LANG_Modula2
:
10660 cu
->language
= language_m2
;
10662 case DW_LANG_Pascal83
:
10663 cu
->language
= language_pascal
;
10666 cu
->language
= language_objc
;
10668 case DW_LANG_Cobol74
:
10669 case DW_LANG_Cobol85
:
10671 cu
->language
= language_minimal
;
10674 cu
->language_defn
= language_def (cu
->language
);
10677 /* Return the named attribute or NULL if not there. */
10679 static struct attribute
*
10680 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
10683 struct attribute
*spec
= NULL
;
10685 for (i
= 0; i
< die
->num_attrs
; ++i
)
10687 if (die
->attrs
[i
].name
== name
)
10688 return &die
->attrs
[i
];
10689 if (die
->attrs
[i
].name
== DW_AT_specification
10690 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
10691 spec
= &die
->attrs
[i
];
10696 die
= follow_die_ref (die
, spec
, &cu
);
10697 return dwarf2_attr (die
, name
, cu
);
10703 /* Return the named attribute or NULL if not there,
10704 but do not follow DW_AT_specification, etc.
10705 This is for use in contexts where we're reading .debug_types dies.
10706 Following DW_AT_specification, DW_AT_abstract_origin will take us
10707 back up the chain, and we want to go down. */
10709 static struct attribute
*
10710 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
10711 struct dwarf2_cu
*cu
)
10715 for (i
= 0; i
< die
->num_attrs
; ++i
)
10716 if (die
->attrs
[i
].name
== name
)
10717 return &die
->attrs
[i
];
10722 /* Return non-zero iff the attribute NAME is defined for the given DIE,
10723 and holds a non-zero value. This function should only be used for
10724 DW_FORM_flag or DW_FORM_flag_present attributes. */
10727 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
10729 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
10731 return (attr
&& DW_UNSND (attr
));
10735 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
10737 /* A DIE is a declaration if it has a DW_AT_declaration attribute
10738 which value is non-zero. However, we have to be careful with
10739 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
10740 (via dwarf2_flag_true_p) follows this attribute. So we may
10741 end up accidently finding a declaration attribute that belongs
10742 to a different DIE referenced by the specification attribute,
10743 even though the given DIE does not have a declaration attribute. */
10744 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
10745 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
10748 /* Return the die giving the specification for DIE, if there is
10749 one. *SPEC_CU is the CU containing DIE on input, and the CU
10750 containing the return value on output. If there is no
10751 specification, but there is an abstract origin, that is
10754 static struct die_info
*
10755 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
10757 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
10760 if (spec_attr
== NULL
)
10761 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
10763 if (spec_attr
== NULL
)
10766 return follow_die_ref (die
, spec_attr
, spec_cu
);
10769 /* Free the line_header structure *LH, and any arrays and strings it
10771 NOTE: This is also used as a "cleanup" function. */
10774 free_line_header (struct line_header
*lh
)
10776 if (lh
->standard_opcode_lengths
)
10777 xfree (lh
->standard_opcode_lengths
);
10779 /* Remember that all the lh->file_names[i].name pointers are
10780 pointers into debug_line_buffer, and don't need to be freed. */
10781 if (lh
->file_names
)
10782 xfree (lh
->file_names
);
10784 /* Similarly for the include directory names. */
10785 if (lh
->include_dirs
)
10786 xfree (lh
->include_dirs
);
10791 /* Add an entry to LH's include directory table. */
10794 add_include_dir (struct line_header
*lh
, char *include_dir
)
10796 /* Grow the array if necessary. */
10797 if (lh
->include_dirs_size
== 0)
10799 lh
->include_dirs_size
= 1; /* for testing */
10800 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
10801 * sizeof (*lh
->include_dirs
));
10803 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
10805 lh
->include_dirs_size
*= 2;
10806 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
10807 (lh
->include_dirs_size
10808 * sizeof (*lh
->include_dirs
)));
10811 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
10814 /* Add an entry to LH's file name table. */
10817 add_file_name (struct line_header
*lh
,
10819 unsigned int dir_index
,
10820 unsigned int mod_time
,
10821 unsigned int length
)
10823 struct file_entry
*fe
;
10825 /* Grow the array if necessary. */
10826 if (lh
->file_names_size
== 0)
10828 lh
->file_names_size
= 1; /* for testing */
10829 lh
->file_names
= xmalloc (lh
->file_names_size
10830 * sizeof (*lh
->file_names
));
10832 else if (lh
->num_file_names
>= lh
->file_names_size
)
10834 lh
->file_names_size
*= 2;
10835 lh
->file_names
= xrealloc (lh
->file_names
,
10836 (lh
->file_names_size
10837 * sizeof (*lh
->file_names
)));
10840 fe
= &lh
->file_names
[lh
->num_file_names
++];
10842 fe
->dir_index
= dir_index
;
10843 fe
->mod_time
= mod_time
;
10844 fe
->length
= length
;
10845 fe
->included_p
= 0;
10849 /* Read the statement program header starting at OFFSET in
10850 .debug_line, according to the endianness of ABFD. Return a pointer
10851 to a struct line_header, allocated using xmalloc.
10853 NOTE: the strings in the include directory and file name tables of
10854 the returned object point into debug_line_buffer, and must not be
10857 static struct line_header
*
10858 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
10859 struct dwarf2_cu
*cu
)
10861 struct cleanup
*back_to
;
10862 struct line_header
*lh
;
10863 gdb_byte
*line_ptr
;
10864 unsigned int bytes_read
, offset_size
;
10866 char *cur_dir
, *cur_file
;
10868 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
10869 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
10871 complaint (&symfile_complaints
, _("missing .debug_line section"));
10875 /* Make sure that at least there's room for the total_length field.
10876 That could be 12 bytes long, but we're just going to fudge that. */
10877 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
10879 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10883 lh
= xmalloc (sizeof (*lh
));
10884 memset (lh
, 0, sizeof (*lh
));
10885 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
10888 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
10890 /* Read in the header. */
10892 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
10893 &bytes_read
, &offset_size
);
10894 line_ptr
+= bytes_read
;
10895 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
10896 + dwarf2_per_objfile
->line
.size
))
10898 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10901 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
10902 lh
->version
= read_2_bytes (abfd
, line_ptr
);
10904 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
10905 line_ptr
+= offset_size
;
10906 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
10908 if (lh
->version
>= 4)
10910 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
10914 lh
->maximum_ops_per_instruction
= 1;
10916 if (lh
->maximum_ops_per_instruction
== 0)
10918 lh
->maximum_ops_per_instruction
= 1;
10919 complaint (&symfile_complaints
,
10920 _("invalid maximum_ops_per_instruction "
10921 "in `.debug_line' section"));
10924 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
10926 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
10928 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
10930 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
10932 lh
->standard_opcode_lengths
10933 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
10935 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
10936 for (i
= 1; i
< lh
->opcode_base
; ++i
)
10938 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
10942 /* Read directory table. */
10943 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
10945 line_ptr
+= bytes_read
;
10946 add_include_dir (lh
, cur_dir
);
10948 line_ptr
+= bytes_read
;
10950 /* Read file name table. */
10951 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
10953 unsigned int dir_index
, mod_time
, length
;
10955 line_ptr
+= bytes_read
;
10956 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10957 line_ptr
+= bytes_read
;
10958 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10959 line_ptr
+= bytes_read
;
10960 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10961 line_ptr
+= bytes_read
;
10963 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
10965 line_ptr
+= bytes_read
;
10966 lh
->statement_program_start
= line_ptr
;
10968 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
10969 + dwarf2_per_objfile
->line
.size
))
10970 complaint (&symfile_complaints
,
10971 _("line number info header doesn't "
10972 "fit in `.debug_line' section"));
10974 discard_cleanups (back_to
);
10978 /* This function exists to work around a bug in certain compilers
10979 (particularly GCC 2.95), in which the first line number marker of a
10980 function does not show up until after the prologue, right before
10981 the second line number marker. This function shifts ADDRESS down
10982 to the beginning of the function if necessary, and is called on
10983 addresses passed to record_line. */
10986 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
10988 struct function_range
*fn
;
10990 /* Find the function_range containing address. */
10994 if (!cu
->cached_fn
)
10995 cu
->cached_fn
= cu
->first_fn
;
10997 fn
= cu
->cached_fn
;
10999 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
11005 while (fn
&& fn
!= cu
->cached_fn
)
11006 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
11016 if (address
!= fn
->lowpc
)
11017 complaint (&symfile_complaints
,
11018 _("misplaced first line number at 0x%lx for '%s'"),
11019 (unsigned long) address
, fn
->name
);
11024 /* Subroutine of dwarf_decode_lines to simplify it.
11025 Return the file name of the psymtab for included file FILE_INDEX
11026 in line header LH of PST.
11027 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
11028 If space for the result is malloc'd, it will be freed by a cleanup.
11029 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
11032 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
11033 const struct partial_symtab
*pst
,
11034 const char *comp_dir
)
11036 const struct file_entry fe
= lh
->file_names
[file_index
];
11037 char *include_name
= fe
.name
;
11038 char *include_name_to_compare
= include_name
;
11039 char *dir_name
= NULL
;
11040 const char *pst_filename
;
11041 char *copied_name
= NULL
;
11045 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
11047 if (!IS_ABSOLUTE_PATH (include_name
)
11048 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
11050 /* Avoid creating a duplicate psymtab for PST.
11051 We do this by comparing INCLUDE_NAME and PST_FILENAME.
11052 Before we do the comparison, however, we need to account
11053 for DIR_NAME and COMP_DIR.
11054 First prepend dir_name (if non-NULL). If we still don't
11055 have an absolute path prepend comp_dir (if non-NULL).
11056 However, the directory we record in the include-file's
11057 psymtab does not contain COMP_DIR (to match the
11058 corresponding symtab(s)).
11063 bash$ gcc -g ./hello.c
11064 include_name = "hello.c"
11066 DW_AT_comp_dir = comp_dir = "/tmp"
11067 DW_AT_name = "./hello.c" */
11069 if (dir_name
!= NULL
)
11071 include_name
= concat (dir_name
, SLASH_STRING
,
11072 include_name
, (char *)NULL
);
11073 include_name_to_compare
= include_name
;
11074 make_cleanup (xfree
, include_name
);
11076 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
11078 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
11079 include_name
, (char *)NULL
);
11083 pst_filename
= pst
->filename
;
11084 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
11086 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
11087 pst_filename
, (char *)NULL
);
11088 pst_filename
= copied_name
;
11091 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
11093 if (include_name_to_compare
!= include_name
)
11094 xfree (include_name_to_compare
);
11095 if (copied_name
!= NULL
)
11096 xfree (copied_name
);
11100 return include_name
;
11103 /* Ignore this record_line request. */
11106 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
11111 /* Decode the Line Number Program (LNP) for the given line_header
11112 structure and CU. The actual information extracted and the type
11113 of structures created from the LNP depends on the value of PST.
11115 1. If PST is NULL, then this procedure uses the data from the program
11116 to create all necessary symbol tables, and their linetables.
11118 2. If PST is not NULL, this procedure reads the program to determine
11119 the list of files included by the unit represented by PST, and
11120 builds all the associated partial symbol tables.
11122 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
11123 It is used for relative paths in the line table.
11124 NOTE: When processing partial symtabs (pst != NULL),
11125 comp_dir == pst->dirname.
11127 NOTE: It is important that psymtabs have the same file name (via strcmp)
11128 as the corresponding symtab. Since COMP_DIR is not used in the name of the
11129 symtab we don't use it in the name of the psymtabs we create.
11130 E.g. expand_line_sal requires this when finding psymtabs to expand.
11131 A good testcase for this is mb-inline.exp. */
11134 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
, bfd
*abfd
,
11135 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
11137 gdb_byte
*line_ptr
, *extended_end
;
11138 gdb_byte
*line_end
;
11139 unsigned int bytes_read
, extended_len
;
11140 unsigned char op_code
, extended_op
, adj_opcode
;
11141 CORE_ADDR baseaddr
;
11142 struct objfile
*objfile
= cu
->objfile
;
11143 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11144 const int decode_for_pst_p
= (pst
!= NULL
);
11145 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
11146 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
11149 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11151 line_ptr
= lh
->statement_program_start
;
11152 line_end
= lh
->statement_program_end
;
11154 /* Read the statement sequences until there's nothing left. */
11155 while (line_ptr
< line_end
)
11157 /* state machine registers */
11158 CORE_ADDR address
= 0;
11159 unsigned int file
= 1;
11160 unsigned int line
= 1;
11161 unsigned int column
= 0;
11162 int is_stmt
= lh
->default_is_stmt
;
11163 int basic_block
= 0;
11164 int end_sequence
= 0;
11166 unsigned char op_index
= 0;
11168 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
11170 /* Start a subfile for the current file of the state machine. */
11171 /* lh->include_dirs and lh->file_names are 0-based, but the
11172 directory and file name numbers in the statement program
11174 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
11178 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11180 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11183 /* Decode the table. */
11184 while (!end_sequence
)
11186 op_code
= read_1_byte (abfd
, line_ptr
);
11188 if (line_ptr
> line_end
)
11190 dwarf2_debug_line_missing_end_sequence_complaint ();
11194 if (op_code
>= lh
->opcode_base
)
11196 /* Special operand. */
11197 adj_opcode
= op_code
- lh
->opcode_base
;
11198 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
11199 / lh
->maximum_ops_per_instruction
)
11200 * lh
->minimum_instruction_length
);
11201 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
11202 % lh
->maximum_ops_per_instruction
);
11203 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
11204 if (lh
->num_file_names
< file
|| file
== 0)
11205 dwarf2_debug_line_missing_file_complaint ();
11206 /* For now we ignore lines not starting on an
11207 instruction boundary. */
11208 else if (op_index
== 0)
11210 lh
->file_names
[file
- 1].included_p
= 1;
11211 if (!decode_for_pst_p
&& is_stmt
)
11213 if (last_subfile
!= current_subfile
)
11215 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11217 (*p_record_line
) (last_subfile
, 0, addr
);
11218 last_subfile
= current_subfile
;
11220 /* Append row to matrix using current values. */
11221 addr
= check_cu_functions (address
, cu
);
11222 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
11223 (*p_record_line
) (current_subfile
, line
, addr
);
11228 else switch (op_code
)
11230 case DW_LNS_extended_op
:
11231 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
11233 line_ptr
+= bytes_read
;
11234 extended_end
= line_ptr
+ extended_len
;
11235 extended_op
= read_1_byte (abfd
, line_ptr
);
11237 switch (extended_op
)
11239 case DW_LNE_end_sequence
:
11240 p_record_line
= record_line
;
11243 case DW_LNE_set_address
:
11244 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
11246 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
11248 /* This line table is for a function which has been
11249 GCd by the linker. Ignore it. PR gdb/12528 */
11252 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
11254 complaint (&symfile_complaints
,
11255 _(".debug_line address at offset 0x%lx is 0 "
11257 line_offset
, cu
->objfile
->name
);
11258 p_record_line
= noop_record_line
;
11262 line_ptr
+= bytes_read
;
11263 address
+= baseaddr
;
11265 case DW_LNE_define_file
:
11268 unsigned int dir_index
, mod_time
, length
;
11270 cur_file
= read_direct_string (abfd
, line_ptr
,
11272 line_ptr
+= bytes_read
;
11274 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11275 line_ptr
+= bytes_read
;
11277 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11278 line_ptr
+= bytes_read
;
11280 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11281 line_ptr
+= bytes_read
;
11282 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
11285 case DW_LNE_set_discriminator
:
11286 /* The discriminator is not interesting to the debugger;
11288 line_ptr
= extended_end
;
11291 complaint (&symfile_complaints
,
11292 _("mangled .debug_line section"));
11295 /* Make sure that we parsed the extended op correctly. If e.g.
11296 we expected a different address size than the producer used,
11297 we may have read the wrong number of bytes. */
11298 if (line_ptr
!= extended_end
)
11300 complaint (&symfile_complaints
,
11301 _("mangled .debug_line section"));
11306 if (lh
->num_file_names
< file
|| file
== 0)
11307 dwarf2_debug_line_missing_file_complaint ();
11310 lh
->file_names
[file
- 1].included_p
= 1;
11311 if (!decode_for_pst_p
&& is_stmt
)
11313 if (last_subfile
!= current_subfile
)
11315 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11317 (*p_record_line
) (last_subfile
, 0, addr
);
11318 last_subfile
= current_subfile
;
11320 addr
= check_cu_functions (address
, cu
);
11321 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
11322 (*p_record_line
) (current_subfile
, line
, addr
);
11327 case DW_LNS_advance_pc
:
11330 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11332 address
+= (((op_index
+ adjust
)
11333 / lh
->maximum_ops_per_instruction
)
11334 * lh
->minimum_instruction_length
);
11335 op_index
= ((op_index
+ adjust
)
11336 % lh
->maximum_ops_per_instruction
);
11337 line_ptr
+= bytes_read
;
11340 case DW_LNS_advance_line
:
11341 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
11342 line_ptr
+= bytes_read
;
11344 case DW_LNS_set_file
:
11346 /* The arrays lh->include_dirs and lh->file_names are
11347 0-based, but the directory and file name numbers in
11348 the statement program are 1-based. */
11349 struct file_entry
*fe
;
11352 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11353 line_ptr
+= bytes_read
;
11354 if (lh
->num_file_names
< file
|| file
== 0)
11355 dwarf2_debug_line_missing_file_complaint ();
11358 fe
= &lh
->file_names
[file
- 1];
11360 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11361 if (!decode_for_pst_p
)
11363 last_subfile
= current_subfile
;
11364 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11369 case DW_LNS_set_column
:
11370 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11371 line_ptr
+= bytes_read
;
11373 case DW_LNS_negate_stmt
:
11374 is_stmt
= (!is_stmt
);
11376 case DW_LNS_set_basic_block
:
11379 /* Add to the address register of the state machine the
11380 address increment value corresponding to special opcode
11381 255. I.e., this value is scaled by the minimum
11382 instruction length since special opcode 255 would have
11383 scaled the increment. */
11384 case DW_LNS_const_add_pc
:
11386 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
11388 address
+= (((op_index
+ adjust
)
11389 / lh
->maximum_ops_per_instruction
)
11390 * lh
->minimum_instruction_length
);
11391 op_index
= ((op_index
+ adjust
)
11392 % lh
->maximum_ops_per_instruction
);
11395 case DW_LNS_fixed_advance_pc
:
11396 address
+= read_2_bytes (abfd
, line_ptr
);
11402 /* Unknown standard opcode, ignore it. */
11405 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
11407 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
11408 line_ptr
+= bytes_read
;
11413 if (lh
->num_file_names
< file
|| file
== 0)
11414 dwarf2_debug_line_missing_file_complaint ();
11417 lh
->file_names
[file
- 1].included_p
= 1;
11418 if (!decode_for_pst_p
)
11420 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
11421 (*p_record_line
) (current_subfile
, 0, addr
);
11426 if (decode_for_pst_p
)
11430 /* Now that we're done scanning the Line Header Program, we can
11431 create the psymtab of each included file. */
11432 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
11433 if (lh
->file_names
[file_index
].included_p
== 1)
11435 char *include_name
=
11436 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
11437 if (include_name
!= NULL
)
11438 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
11443 /* Make sure a symtab is created for every file, even files
11444 which contain only variables (i.e. no code with associated
11448 struct file_entry
*fe
;
11450 for (i
= 0; i
< lh
->num_file_names
; i
++)
11454 fe
= &lh
->file_names
[i
];
11456 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11457 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11459 /* Skip the main file; we don't need it, and it must be
11460 allocated last, so that it will show up before the
11461 non-primary symtabs in the objfile's symtab list. */
11462 if (current_subfile
== first_subfile
)
11465 if (current_subfile
->symtab
== NULL
)
11466 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
11468 fe
->symtab
= current_subfile
->symtab
;
11473 /* Start a subfile for DWARF. FILENAME is the name of the file and
11474 DIRNAME the name of the source directory which contains FILENAME
11475 or NULL if not known. COMP_DIR is the compilation directory for the
11476 linetable's compilation unit or NULL if not known.
11477 This routine tries to keep line numbers from identical absolute and
11478 relative file names in a common subfile.
11480 Using the `list' example from the GDB testsuite, which resides in
11481 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
11482 of /srcdir/list0.c yields the following debugging information for list0.c:
11484 DW_AT_name: /srcdir/list0.c
11485 DW_AT_comp_dir: /compdir
11486 files.files[0].name: list0.h
11487 files.files[0].dir: /srcdir
11488 files.files[1].name: list0.c
11489 files.files[1].dir: /srcdir
11491 The line number information for list0.c has to end up in a single
11492 subfile, so that `break /srcdir/list0.c:1' works as expected.
11493 start_subfile will ensure that this happens provided that we pass the
11494 concatenation of files.files[1].dir and files.files[1].name as the
11498 dwarf2_start_subfile (char *filename
, const char *dirname
,
11499 const char *comp_dir
)
11503 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
11504 `start_symtab' will always pass the contents of DW_AT_comp_dir as
11505 second argument to start_subfile. To be consistent, we do the
11506 same here. In order not to lose the line information directory,
11507 we concatenate it to the filename when it makes sense.
11508 Note that the Dwarf3 standard says (speaking of filenames in line
11509 information): ``The directory index is ignored for file names
11510 that represent full path names''. Thus ignoring dirname in the
11511 `else' branch below isn't an issue. */
11513 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
11514 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
11516 fullname
= filename
;
11518 start_subfile (fullname
, comp_dir
);
11520 if (fullname
!= filename
)
11525 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
11526 struct dwarf2_cu
*cu
)
11528 struct objfile
*objfile
= cu
->objfile
;
11529 struct comp_unit_head
*cu_header
= &cu
->header
;
11531 /* NOTE drow/2003-01-30: There used to be a comment and some special
11532 code here to turn a symbol with DW_AT_external and a
11533 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
11534 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
11535 with some versions of binutils) where shared libraries could have
11536 relocations against symbols in their debug information - the
11537 minimal symbol would have the right address, but the debug info
11538 would not. It's no longer necessary, because we will explicitly
11539 apply relocations when we read in the debug information now. */
11541 /* A DW_AT_location attribute with no contents indicates that a
11542 variable has been optimized away. */
11543 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
11545 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11549 /* Handle one degenerate form of location expression specially, to
11550 preserve GDB's previous behavior when section offsets are
11551 specified. If this is just a DW_OP_addr then mark this symbol
11554 if (attr_form_is_block (attr
)
11555 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
11556 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
11558 unsigned int dummy
;
11560 SYMBOL_VALUE_ADDRESS (sym
) =
11561 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
11562 SYMBOL_CLASS (sym
) = LOC_STATIC
;
11563 fixup_symbol_section (sym
, objfile
);
11564 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
11565 SYMBOL_SECTION (sym
));
11569 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
11570 expression evaluator, and use LOC_COMPUTED only when necessary
11571 (i.e. when the value of a register or memory location is
11572 referenced, or a thread-local block, etc.). Then again, it might
11573 not be worthwhile. I'm assuming that it isn't unless performance
11574 or memory numbers show me otherwise. */
11576 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
11577 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11579 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
11580 cu
->has_loclist
= 1;
11583 /* Given a pointer to a DWARF information entry, figure out if we need
11584 to make a symbol table entry for it, and if so, create a new entry
11585 and return a pointer to it.
11586 If TYPE is NULL, determine symbol type from the die, otherwise
11587 used the passed type.
11588 If SPACE is not NULL, use it to hold the new symbol. If it is
11589 NULL, allocate a new symbol on the objfile's obstack. */
11591 static struct symbol
*
11592 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
11593 struct symbol
*space
)
11595 struct objfile
*objfile
= cu
->objfile
;
11596 struct symbol
*sym
= NULL
;
11598 struct attribute
*attr
= NULL
;
11599 struct attribute
*attr2
= NULL
;
11600 CORE_ADDR baseaddr
;
11601 struct pending
**list_to_add
= NULL
;
11603 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
11605 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11607 name
= dwarf2_name (die
, cu
);
11610 const char *linkagename
;
11611 int suppress_add
= 0;
11616 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
11617 OBJSTAT (objfile
, n_syms
++);
11619 /* Cache this symbol's name and the name's demangled form (if any). */
11620 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
11621 linkagename
= dwarf2_physname (name
, die
, cu
);
11622 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
11624 /* Fortran does not have mangling standard and the mangling does differ
11625 between gfortran, iFort etc. */
11626 if (cu
->language
== language_fortran
11627 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
11628 symbol_set_demangled_name (&(sym
->ginfo
),
11629 (char *) dwarf2_full_name (name
, die
, cu
),
11632 /* Default assumptions.
11633 Use the passed type or decode it from the die. */
11634 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11635 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11637 SYMBOL_TYPE (sym
) = type
;
11639 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
11640 attr
= dwarf2_attr (die
,
11641 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
11645 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
11648 attr
= dwarf2_attr (die
,
11649 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
11653 int file_index
= DW_UNSND (attr
);
11655 if (cu
->line_header
== NULL
11656 || file_index
> cu
->line_header
->num_file_names
)
11657 complaint (&symfile_complaints
,
11658 _("file index out of range"));
11659 else if (file_index
> 0)
11661 struct file_entry
*fe
;
11663 fe
= &cu
->line_header
->file_names
[file_index
- 1];
11664 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
11671 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11674 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
11676 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
11677 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
11678 SYMBOL_CLASS (sym
) = LOC_LABEL
;
11679 add_symbol_to_list (sym
, cu
->list_in_scope
);
11681 case DW_TAG_subprogram
:
11682 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11684 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11685 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11686 if ((attr2
&& (DW_UNSND (attr2
) != 0))
11687 || cu
->language
== language_ada
)
11689 /* Subprograms marked external are stored as a global symbol.
11690 Ada subprograms, whether marked external or not, are always
11691 stored as a global symbol, because we want to be able to
11692 access them globally. For instance, we want to be able
11693 to break on a nested subprogram without having to
11694 specify the context. */
11695 list_to_add
= &global_symbols
;
11699 list_to_add
= cu
->list_in_scope
;
11702 case DW_TAG_inlined_subroutine
:
11703 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11705 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11706 SYMBOL_INLINED (sym
) = 1;
11707 /* Do not add the symbol to any lists. It will be found via
11708 BLOCK_FUNCTION from the blockvector. */
11710 case DW_TAG_template_value_param
:
11712 /* Fall through. */
11713 case DW_TAG_constant
:
11714 case DW_TAG_variable
:
11715 case DW_TAG_member
:
11716 /* Compilation with minimal debug info may result in
11717 variables with missing type entries. Change the
11718 misleading `void' type to something sensible. */
11719 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
11721 = objfile_type (objfile
)->nodebug_data_symbol
;
11723 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11724 /* In the case of DW_TAG_member, we should only be called for
11725 static const members. */
11726 if (die
->tag
== DW_TAG_member
)
11728 /* dwarf2_add_field uses die_is_declaration,
11729 so we do the same. */
11730 gdb_assert (die_is_declaration (die
, cu
));
11735 dwarf2_const_value (attr
, sym
, cu
);
11736 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11739 if (attr2
&& (DW_UNSND (attr2
) != 0))
11740 list_to_add
= &global_symbols
;
11742 list_to_add
= cu
->list_in_scope
;
11746 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11749 var_decode_location (attr
, sym
, cu
);
11750 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11751 if (SYMBOL_CLASS (sym
) == LOC_STATIC
11752 && SYMBOL_VALUE_ADDRESS (sym
) == 0
11753 && !dwarf2_per_objfile
->has_section_at_zero
)
11755 /* When a static variable is eliminated by the linker,
11756 the corresponding debug information is not stripped
11757 out, but the variable address is set to null;
11758 do not add such variables into symbol table. */
11760 else if (attr2
&& (DW_UNSND (attr2
) != 0))
11762 /* Workaround gfortran PR debug/40040 - it uses
11763 DW_AT_location for variables in -fPIC libraries which may
11764 get overriden by other libraries/executable and get
11765 a different address. Resolve it by the minimal symbol
11766 which may come from inferior's executable using copy
11767 relocation. Make this workaround only for gfortran as for
11768 other compilers GDB cannot guess the minimal symbol
11769 Fortran mangling kind. */
11770 if (cu
->language
== language_fortran
&& die
->parent
11771 && die
->parent
->tag
== DW_TAG_module
11773 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
11774 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11776 /* A variable with DW_AT_external is never static,
11777 but it may be block-scoped. */
11778 list_to_add
= (cu
->list_in_scope
== &file_symbols
11779 ? &global_symbols
: cu
->list_in_scope
);
11782 list_to_add
= cu
->list_in_scope
;
11786 /* We do not know the address of this symbol.
11787 If it is an external symbol and we have type information
11788 for it, enter the symbol as a LOC_UNRESOLVED symbol.
11789 The address of the variable will then be determined from
11790 the minimal symbol table whenever the variable is
11792 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11793 if (attr2
&& (DW_UNSND (attr2
) != 0)
11794 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
11796 /* A variable with DW_AT_external is never static, but it
11797 may be block-scoped. */
11798 list_to_add
= (cu
->list_in_scope
== &file_symbols
11799 ? &global_symbols
: cu
->list_in_scope
);
11801 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11803 else if (!die_is_declaration (die
, cu
))
11805 /* Use the default LOC_OPTIMIZED_OUT class. */
11806 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
11808 list_to_add
= cu
->list_in_scope
;
11812 case DW_TAG_formal_parameter
:
11813 /* If we are inside a function, mark this as an argument. If
11814 not, we might be looking at an argument to an inlined function
11815 when we do not have enough information to show inlined frames;
11816 pretend it's a local variable in that case so that the user can
11818 if (context_stack_depth
> 0
11819 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
11820 SYMBOL_IS_ARGUMENT (sym
) = 1;
11821 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11824 var_decode_location (attr
, sym
, cu
);
11826 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11829 dwarf2_const_value (attr
, sym
, cu
);
11832 list_to_add
= cu
->list_in_scope
;
11834 case DW_TAG_unspecified_parameters
:
11835 /* From varargs functions; gdb doesn't seem to have any
11836 interest in this information, so just ignore it for now.
11839 case DW_TAG_template_type_param
:
11841 /* Fall through. */
11842 case DW_TAG_class_type
:
11843 case DW_TAG_interface_type
:
11844 case DW_TAG_structure_type
:
11845 case DW_TAG_union_type
:
11846 case DW_TAG_set_type
:
11847 case DW_TAG_enumeration_type
:
11848 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11849 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
11852 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
11853 really ever be static objects: otherwise, if you try
11854 to, say, break of a class's method and you're in a file
11855 which doesn't mention that class, it won't work unless
11856 the check for all static symbols in lookup_symbol_aux
11857 saves you. See the OtherFileClass tests in
11858 gdb.c++/namespace.exp. */
11862 list_to_add
= (cu
->list_in_scope
== &file_symbols
11863 && (cu
->language
== language_cplus
11864 || cu
->language
== language_java
)
11865 ? &global_symbols
: cu
->list_in_scope
);
11867 /* The semantics of C++ state that "struct foo {
11868 ... }" also defines a typedef for "foo". A Java
11869 class declaration also defines a typedef for the
11871 if (cu
->language
== language_cplus
11872 || cu
->language
== language_java
11873 || cu
->language
== language_ada
)
11875 /* The symbol's name is already allocated along
11876 with this objfile, so we don't need to
11877 duplicate it for the type. */
11878 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
11879 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
11884 case DW_TAG_typedef
:
11885 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11886 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11887 list_to_add
= cu
->list_in_scope
;
11889 case DW_TAG_base_type
:
11890 case DW_TAG_subrange_type
:
11891 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11892 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11893 list_to_add
= cu
->list_in_scope
;
11895 case DW_TAG_enumerator
:
11896 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11899 dwarf2_const_value (attr
, sym
, cu
);
11902 /* NOTE: carlton/2003-11-10: See comment above in the
11903 DW_TAG_class_type, etc. block. */
11905 list_to_add
= (cu
->list_in_scope
== &file_symbols
11906 && (cu
->language
== language_cplus
11907 || cu
->language
== language_java
)
11908 ? &global_symbols
: cu
->list_in_scope
);
11911 case DW_TAG_namespace
:
11912 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11913 list_to_add
= &global_symbols
;
11916 /* Not a tag we recognize. Hopefully we aren't processing
11917 trash data, but since we must specifically ignore things
11918 we don't recognize, there is nothing else we should do at
11920 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
11921 dwarf_tag_name (die
->tag
));
11927 sym
->hash_next
= objfile
->template_symbols
;
11928 objfile
->template_symbols
= sym
;
11929 list_to_add
= NULL
;
11932 if (list_to_add
!= NULL
)
11933 add_symbol_to_list (sym
, list_to_add
);
11935 /* For the benefit of old versions of GCC, check for anonymous
11936 namespaces based on the demangled name. */
11937 if (!processing_has_namespace_info
11938 && cu
->language
== language_cplus
)
11939 cp_scan_for_anonymous_namespaces (sym
);
11944 /* A wrapper for new_symbol_full that always allocates a new symbol. */
11946 static struct symbol
*
11947 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
11949 return new_symbol_full (die
, type
, cu
, NULL
);
11952 /* Given an attr with a DW_FORM_dataN value in host byte order,
11953 zero-extend it as appropriate for the symbol's type. The DWARF
11954 standard (v4) is not entirely clear about the meaning of using
11955 DW_FORM_dataN for a constant with a signed type, where the type is
11956 wider than the data. The conclusion of a discussion on the DWARF
11957 list was that this is unspecified. We choose to always zero-extend
11958 because that is the interpretation long in use by GCC. */
11961 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
11962 const char *name
, struct obstack
*obstack
,
11963 struct dwarf2_cu
*cu
, long *value
, int bits
)
11965 struct objfile
*objfile
= cu
->objfile
;
11966 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
11967 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
11968 LONGEST l
= DW_UNSND (attr
);
11970 if (bits
< sizeof (*value
) * 8)
11972 l
&= ((LONGEST
) 1 << bits
) - 1;
11975 else if (bits
== sizeof (*value
) * 8)
11979 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
11980 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
11987 /* Read a constant value from an attribute. Either set *VALUE, or if
11988 the value does not fit in *VALUE, set *BYTES - either already
11989 allocated on the objfile obstack, or newly allocated on OBSTACK,
11990 or, set *BATON, if we translated the constant to a location
11994 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
11995 const char *name
, struct obstack
*obstack
,
11996 struct dwarf2_cu
*cu
,
11997 long *value
, gdb_byte
**bytes
,
11998 struct dwarf2_locexpr_baton
**baton
)
12000 struct objfile
*objfile
= cu
->objfile
;
12001 struct comp_unit_head
*cu_header
= &cu
->header
;
12002 struct dwarf_block
*blk
;
12003 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
12004 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
12010 switch (attr
->form
)
12016 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
12017 dwarf2_const_value_length_mismatch_complaint (name
,
12018 cu_header
->addr_size
,
12019 TYPE_LENGTH (type
));
12020 /* Symbols of this form are reasonably rare, so we just
12021 piggyback on the existing location code rather than writing
12022 a new implementation of symbol_computed_ops. */
12023 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
12024 sizeof (struct dwarf2_locexpr_baton
));
12025 (*baton
)->per_cu
= cu
->per_cu
;
12026 gdb_assert ((*baton
)->per_cu
);
12028 (*baton
)->size
= 2 + cu_header
->addr_size
;
12029 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
12030 (*baton
)->data
= data
;
12032 data
[0] = DW_OP_addr
;
12033 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
12034 byte_order
, DW_ADDR (attr
));
12035 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
12038 case DW_FORM_string
:
12040 /* DW_STRING is already allocated on the objfile obstack, point
12042 *bytes
= (gdb_byte
*) DW_STRING (attr
);
12044 case DW_FORM_block1
:
12045 case DW_FORM_block2
:
12046 case DW_FORM_block4
:
12047 case DW_FORM_block
:
12048 case DW_FORM_exprloc
:
12049 blk
= DW_BLOCK (attr
);
12050 if (TYPE_LENGTH (type
) != blk
->size
)
12051 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
12052 TYPE_LENGTH (type
));
12053 *bytes
= blk
->data
;
12056 /* The DW_AT_const_value attributes are supposed to carry the
12057 symbol's value "represented as it would be on the target
12058 architecture." By the time we get here, it's already been
12059 converted to host endianness, so we just need to sign- or
12060 zero-extend it as appropriate. */
12061 case DW_FORM_data1
:
12062 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12063 obstack
, cu
, value
, 8);
12065 case DW_FORM_data2
:
12066 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12067 obstack
, cu
, value
, 16);
12069 case DW_FORM_data4
:
12070 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12071 obstack
, cu
, value
, 32);
12073 case DW_FORM_data8
:
12074 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
12075 obstack
, cu
, value
, 64);
12078 case DW_FORM_sdata
:
12079 *value
= DW_SND (attr
);
12082 case DW_FORM_udata
:
12083 *value
= DW_UNSND (attr
);
12087 complaint (&symfile_complaints
,
12088 _("unsupported const value attribute form: '%s'"),
12089 dwarf_form_name (attr
->form
));
12096 /* Copy constant value from an attribute to a symbol. */
12099 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
12100 struct dwarf2_cu
*cu
)
12102 struct objfile
*objfile
= cu
->objfile
;
12103 struct comp_unit_head
*cu_header
= &cu
->header
;
12106 struct dwarf2_locexpr_baton
*baton
;
12108 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
12109 SYMBOL_PRINT_NAME (sym
),
12110 &objfile
->objfile_obstack
, cu
,
12111 &value
, &bytes
, &baton
);
12115 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
12116 SYMBOL_LOCATION_BATON (sym
) = baton
;
12117 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
12119 else if (bytes
!= NULL
)
12121 SYMBOL_VALUE_BYTES (sym
) = bytes
;
12122 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
12126 SYMBOL_VALUE (sym
) = value
;
12127 SYMBOL_CLASS (sym
) = LOC_CONST
;
12131 /* Return the type of the die in question using its DW_AT_type attribute. */
12133 static struct type
*
12134 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12136 struct attribute
*type_attr
;
12138 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
12141 /* A missing DW_AT_type represents a void type. */
12142 return objfile_type (cu
->objfile
)->builtin_void
;
12145 return lookup_die_type (die
, type_attr
, cu
);
12148 /* True iff CU's producer generates GNAT Ada auxiliary information
12149 that allows to find parallel types through that information instead
12150 of having to do expensive parallel lookups by type name. */
12153 need_gnat_info (struct dwarf2_cu
*cu
)
12155 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
12156 of GNAT produces this auxiliary information, without any indication
12157 that it is produced. Part of enhancing the FSF version of GNAT
12158 to produce that information will be to put in place an indicator
12159 that we can use in order to determine whether the descriptive type
12160 info is available or not. One suggestion that has been made is
12161 to use a new attribute, attached to the CU die. For now, assume
12162 that the descriptive type info is not available. */
12166 /* Return the auxiliary type of the die in question using its
12167 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
12168 attribute is not present. */
12170 static struct type
*
12171 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12173 struct attribute
*type_attr
;
12175 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
12179 return lookup_die_type (die
, type_attr
, cu
);
12182 /* If DIE has a descriptive_type attribute, then set the TYPE's
12183 descriptive type accordingly. */
12186 set_descriptive_type (struct type
*type
, struct die_info
*die
,
12187 struct dwarf2_cu
*cu
)
12189 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
12191 if (descriptive_type
)
12193 ALLOCATE_GNAT_AUX_TYPE (type
);
12194 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
12198 /* Return the containing type of the die in question using its
12199 DW_AT_containing_type attribute. */
12201 static struct type
*
12202 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12204 struct attribute
*type_attr
;
12206 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
12208 error (_("Dwarf Error: Problem turning containing type into gdb type "
12209 "[in module %s]"), cu
->objfile
->name
);
12211 return lookup_die_type (die
, type_attr
, cu
);
12214 /* Look up the type of DIE in CU using its type attribute ATTR.
12215 If there is no type substitute an error marker. */
12217 static struct type
*
12218 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
12219 struct dwarf2_cu
*cu
)
12221 struct type
*this_type
;
12223 /* First see if we have it cached. */
12225 if (is_ref_attr (attr
))
12227 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
12229 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
12231 else if (attr
->form
== DW_FORM_ref_sig8
)
12233 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
12234 struct dwarf2_cu
*sig_cu
;
12235 unsigned int offset
;
12237 /* sig_type will be NULL if the signatured type is missing from
12239 if (sig_type
== NULL
)
12240 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
12241 "at 0x%x [in module %s]"),
12242 die
->offset
, cu
->objfile
->name
);
12244 gdb_assert (sig_type
->per_cu
.debug_type_section
);
12245 offset
= sig_type
->per_cu
.offset
+ sig_type
->type_offset
;
12246 this_type
= get_die_type_at_offset (offset
, &sig_type
->per_cu
);
12250 dump_die_for_error (die
);
12251 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
12252 dwarf_attr_name (attr
->name
), cu
->objfile
->name
);
12255 /* If not cached we need to read it in. */
12257 if (this_type
== NULL
)
12259 struct die_info
*type_die
;
12260 struct dwarf2_cu
*type_cu
= cu
;
12262 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
12263 /* If the type is cached, we should have found it above. */
12264 gdb_assert (get_die_type (type_die
, type_cu
) == NULL
);
12265 this_type
= read_type_die_1 (type_die
, type_cu
);
12268 /* If we still don't have a type use an error marker. */
12270 if (this_type
== NULL
)
12272 char *message
, *saved
;
12274 /* read_type_die already issued a complaint. */
12275 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
12279 saved
= obstack_copy0 (&cu
->objfile
->objfile_obstack
,
12280 message
, strlen (message
));
12283 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, cu
->objfile
);
12289 /* Return the type in DIE, CU.
12290 Returns NULL for invalid types.
12292 This first does a lookup in the appropriate type_hash table,
12293 and only reads the die in if necessary.
12295 NOTE: This can be called when reading in partial or full symbols. */
12297 static struct type
*
12298 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
12300 struct type
*this_type
;
12302 this_type
= get_die_type (die
, cu
);
12306 return read_type_die_1 (die
, cu
);
12309 /* Read the type in DIE, CU.
12310 Returns NULL for invalid types. */
12312 static struct type
*
12313 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
12315 struct type
*this_type
= NULL
;
12319 case DW_TAG_class_type
:
12320 case DW_TAG_interface_type
:
12321 case DW_TAG_structure_type
:
12322 case DW_TAG_union_type
:
12323 this_type
= read_structure_type (die
, cu
);
12325 case DW_TAG_enumeration_type
:
12326 this_type
= read_enumeration_type (die
, cu
);
12328 case DW_TAG_subprogram
:
12329 case DW_TAG_subroutine_type
:
12330 case DW_TAG_inlined_subroutine
:
12331 this_type
= read_subroutine_type (die
, cu
);
12333 case DW_TAG_array_type
:
12334 this_type
= read_array_type (die
, cu
);
12336 case DW_TAG_set_type
:
12337 this_type
= read_set_type (die
, cu
);
12339 case DW_TAG_pointer_type
:
12340 this_type
= read_tag_pointer_type (die
, cu
);
12342 case DW_TAG_ptr_to_member_type
:
12343 this_type
= read_tag_ptr_to_member_type (die
, cu
);
12345 case DW_TAG_reference_type
:
12346 this_type
= read_tag_reference_type (die
, cu
);
12348 case DW_TAG_const_type
:
12349 this_type
= read_tag_const_type (die
, cu
);
12351 case DW_TAG_volatile_type
:
12352 this_type
= read_tag_volatile_type (die
, cu
);
12354 case DW_TAG_string_type
:
12355 this_type
= read_tag_string_type (die
, cu
);
12357 case DW_TAG_typedef
:
12358 this_type
= read_typedef (die
, cu
);
12360 case DW_TAG_subrange_type
:
12361 this_type
= read_subrange_type (die
, cu
);
12363 case DW_TAG_base_type
:
12364 this_type
= read_base_type (die
, cu
);
12366 case DW_TAG_unspecified_type
:
12367 this_type
= read_unspecified_type (die
, cu
);
12369 case DW_TAG_namespace
:
12370 this_type
= read_namespace_type (die
, cu
);
12372 case DW_TAG_module
:
12373 this_type
= read_module_type (die
, cu
);
12376 complaint (&symfile_complaints
,
12377 _("unexpected tag in read_type_die: '%s'"),
12378 dwarf_tag_name (die
->tag
));
12385 /* See if we can figure out if the class lives in a namespace. We do
12386 this by looking for a member function; its demangled name will
12387 contain namespace info, if there is any.
12388 Return the computed name or NULL.
12389 Space for the result is allocated on the objfile's obstack.
12390 This is the full-die version of guess_partial_die_structure_name.
12391 In this case we know DIE has no useful parent. */
12394 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12396 struct die_info
*spec_die
;
12397 struct dwarf2_cu
*spec_cu
;
12398 struct die_info
*child
;
12401 spec_die
= die_specification (die
, &spec_cu
);
12402 if (spec_die
!= NULL
)
12408 for (child
= die
->child
;
12410 child
= child
->sibling
)
12412 if (child
->tag
== DW_TAG_subprogram
)
12414 struct attribute
*attr
;
12416 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
12418 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
12422 = language_class_name_from_physname (cu
->language_defn
,
12426 if (actual_name
!= NULL
)
12428 char *die_name
= dwarf2_name (die
, cu
);
12430 if (die_name
!= NULL
12431 && strcmp (die_name
, actual_name
) != 0)
12433 /* Strip off the class name from the full name.
12434 We want the prefix. */
12435 int die_name_len
= strlen (die_name
);
12436 int actual_name_len
= strlen (actual_name
);
12438 /* Test for '::' as a sanity check. */
12439 if (actual_name_len
> die_name_len
+ 2
12440 && actual_name
[actual_name_len
12441 - die_name_len
- 1] == ':')
12443 obsavestring (actual_name
,
12444 actual_name_len
- die_name_len
- 2,
12445 &cu
->objfile
->objfile_obstack
);
12448 xfree (actual_name
);
12457 /* GCC might emit a nameless typedef that has a linkage name. Determine the
12458 prefix part in such case. See
12459 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12462 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
12464 struct attribute
*attr
;
12467 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
12468 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
12471 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
12472 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
12475 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
12477 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
12478 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
12481 /* dwarf2_name had to be already called. */
12482 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
12484 /* Strip the base name, keep any leading namespaces/classes. */
12485 base
= strrchr (DW_STRING (attr
), ':');
12486 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
12489 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
12490 &cu
->objfile
->objfile_obstack
);
12493 /* Return the name of the namespace/class that DIE is defined within,
12494 or "" if we can't tell. The caller should not xfree the result.
12496 For example, if we're within the method foo() in the following
12506 then determine_prefix on foo's die will return "N::C". */
12509 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
12511 struct die_info
*parent
, *spec_die
;
12512 struct dwarf2_cu
*spec_cu
;
12513 struct type
*parent_type
;
12516 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
12517 && cu
->language
!= language_fortran
)
12520 retval
= anonymous_struct_prefix (die
, cu
);
12524 /* We have to be careful in the presence of DW_AT_specification.
12525 For example, with GCC 3.4, given the code
12529 // Definition of N::foo.
12533 then we'll have a tree of DIEs like this:
12535 1: DW_TAG_compile_unit
12536 2: DW_TAG_namespace // N
12537 3: DW_TAG_subprogram // declaration of N::foo
12538 4: DW_TAG_subprogram // definition of N::foo
12539 DW_AT_specification // refers to die #3
12541 Thus, when processing die #4, we have to pretend that we're in
12542 the context of its DW_AT_specification, namely the contex of die
12545 spec_die
= die_specification (die
, &spec_cu
);
12546 if (spec_die
== NULL
)
12547 parent
= die
->parent
;
12550 parent
= spec_die
->parent
;
12554 if (parent
== NULL
)
12556 else if (parent
->building_fullname
)
12559 const char *parent_name
;
12561 /* It has been seen on RealView 2.2 built binaries,
12562 DW_TAG_template_type_param types actually _defined_ as
12563 children of the parent class:
12566 template class <class Enum> Class{};
12567 Class<enum E> class_e;
12569 1: DW_TAG_class_type (Class)
12570 2: DW_TAG_enumeration_type (E)
12571 3: DW_TAG_enumerator (enum1:0)
12572 3: DW_TAG_enumerator (enum2:1)
12574 2: DW_TAG_template_type_param
12575 DW_AT_type DW_FORM_ref_udata (E)
12577 Besides being broken debug info, it can put GDB into an
12578 infinite loop. Consider:
12580 When we're building the full name for Class<E>, we'll start
12581 at Class, and go look over its template type parameters,
12582 finding E. We'll then try to build the full name of E, and
12583 reach here. We're now trying to build the full name of E,
12584 and look over the parent DIE for containing scope. In the
12585 broken case, if we followed the parent DIE of E, we'd again
12586 find Class, and once again go look at its template type
12587 arguments, etc., etc. Simply don't consider such parent die
12588 as source-level parent of this die (it can't be, the language
12589 doesn't allow it), and break the loop here. */
12590 name
= dwarf2_name (die
, cu
);
12591 parent_name
= dwarf2_name (parent
, cu
);
12592 complaint (&symfile_complaints
,
12593 _("template param type '%s' defined within parent '%s'"),
12594 name
? name
: "<unknown>",
12595 parent_name
? parent_name
: "<unknown>");
12599 switch (parent
->tag
)
12601 case DW_TAG_namespace
:
12602 parent_type
= read_type_die (parent
, cu
);
12603 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
12604 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
12605 Work around this problem here. */
12606 if (cu
->language
== language_cplus
12607 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
12609 /* We give a name to even anonymous namespaces. */
12610 return TYPE_TAG_NAME (parent_type
);
12611 case DW_TAG_class_type
:
12612 case DW_TAG_interface_type
:
12613 case DW_TAG_structure_type
:
12614 case DW_TAG_union_type
:
12615 case DW_TAG_module
:
12616 parent_type
= read_type_die (parent
, cu
);
12617 if (TYPE_TAG_NAME (parent_type
) != NULL
)
12618 return TYPE_TAG_NAME (parent_type
);
12620 /* An anonymous structure is only allowed non-static data
12621 members; no typedefs, no member functions, et cetera.
12622 So it does not need a prefix. */
12624 case DW_TAG_compile_unit
:
12625 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
12626 if (cu
->language
== language_cplus
12627 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
12628 && die
->child
!= NULL
12629 && (die
->tag
== DW_TAG_class_type
12630 || die
->tag
== DW_TAG_structure_type
12631 || die
->tag
== DW_TAG_union_type
))
12633 char *name
= guess_full_die_structure_name (die
, cu
);
12639 return determine_prefix (parent
, cu
);
12643 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
12644 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
12645 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
12646 an obconcat, otherwise allocate storage for the result. The CU argument is
12647 used to determine the language and hence, the appropriate separator. */
12649 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
12652 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
12653 int physname
, struct dwarf2_cu
*cu
)
12655 const char *lead
= "";
12658 if (suffix
== NULL
|| suffix
[0] == '\0'
12659 || prefix
== NULL
|| prefix
[0] == '\0')
12661 else if (cu
->language
== language_java
)
12663 else if (cu
->language
== language_fortran
&& physname
)
12665 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
12666 DW_AT_MIPS_linkage_name is preferred and used instead. */
12674 if (prefix
== NULL
)
12676 if (suffix
== NULL
)
12682 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
12684 strcpy (retval
, lead
);
12685 strcat (retval
, prefix
);
12686 strcat (retval
, sep
);
12687 strcat (retval
, suffix
);
12692 /* We have an obstack. */
12693 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
12697 /* Return sibling of die, NULL if no sibling. */
12699 static struct die_info
*
12700 sibling_die (struct die_info
*die
)
12702 return die
->sibling
;
12705 /* Get name of a die, return NULL if not found. */
12708 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
12709 struct obstack
*obstack
)
12711 if (name
&& cu
->language
== language_cplus
)
12713 char *canon_name
= cp_canonicalize_string (name
);
12715 if (canon_name
!= NULL
)
12717 if (strcmp (canon_name
, name
) != 0)
12718 name
= obsavestring (canon_name
, strlen (canon_name
),
12720 xfree (canon_name
);
12727 /* Get name of a die, return NULL if not found. */
12730 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12732 struct attribute
*attr
;
12734 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
12735 if ((!attr
|| !DW_STRING (attr
))
12736 && die
->tag
!= DW_TAG_class_type
12737 && die
->tag
!= DW_TAG_interface_type
12738 && die
->tag
!= DW_TAG_structure_type
12739 && die
->tag
!= DW_TAG_union_type
)
12744 case DW_TAG_compile_unit
:
12745 /* Compilation units have a DW_AT_name that is a filename, not
12746 a source language identifier. */
12747 case DW_TAG_enumeration_type
:
12748 case DW_TAG_enumerator
:
12749 /* These tags always have simple identifiers already; no need
12750 to canonicalize them. */
12751 return DW_STRING (attr
);
12753 case DW_TAG_subprogram
:
12754 /* Java constructors will all be named "<init>", so return
12755 the class name when we see this special case. */
12756 if (cu
->language
== language_java
12757 && DW_STRING (attr
) != NULL
12758 && strcmp (DW_STRING (attr
), "<init>") == 0)
12760 struct dwarf2_cu
*spec_cu
= cu
;
12761 struct die_info
*spec_die
;
12763 /* GCJ will output '<init>' for Java constructor names.
12764 For this special case, return the name of the parent class. */
12766 /* GCJ may output suprogram DIEs with AT_specification set.
12767 If so, use the name of the specified DIE. */
12768 spec_die
= die_specification (die
, &spec_cu
);
12769 if (spec_die
!= NULL
)
12770 return dwarf2_name (spec_die
, spec_cu
);
12775 if (die
->tag
== DW_TAG_class_type
)
12776 return dwarf2_name (die
, cu
);
12778 while (die
->tag
!= DW_TAG_compile_unit
);
12782 case DW_TAG_class_type
:
12783 case DW_TAG_interface_type
:
12784 case DW_TAG_structure_type
:
12785 case DW_TAG_union_type
:
12786 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
12787 structures or unions. These were of the form "._%d" in GCC 4.1,
12788 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
12789 and GCC 4.4. We work around this problem by ignoring these. */
12790 if (attr
&& DW_STRING (attr
)
12791 && (strncmp (DW_STRING (attr
), "._", 2) == 0
12792 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
12795 /* GCC might emit a nameless typedef that has a linkage name. See
12796 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12797 if (!attr
|| DW_STRING (attr
) == NULL
)
12799 char *demangled
= NULL
;
12801 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
12803 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
12805 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
12808 /* Avoid demangling DW_STRING (attr) the second time on a second
12809 call for the same DIE. */
12810 if (!DW_STRING_IS_CANONICAL (attr
))
12811 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
12817 /* FIXME: we already did this for the partial symbol... */
12818 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
12819 &cu
->objfile
->objfile_obstack
);
12820 DW_STRING_IS_CANONICAL (attr
) = 1;
12823 /* Strip any leading namespaces/classes, keep only the base name.
12824 DW_AT_name for named DIEs does not contain the prefixes. */
12825 base
= strrchr (DW_STRING (attr
), ':');
12826 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
12829 return DW_STRING (attr
);
12838 if (!DW_STRING_IS_CANONICAL (attr
))
12841 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
12842 &cu
->objfile
->objfile_obstack
);
12843 DW_STRING_IS_CANONICAL (attr
) = 1;
12845 return DW_STRING (attr
);
12848 /* Return the die that this die in an extension of, or NULL if there
12849 is none. *EXT_CU is the CU containing DIE on input, and the CU
12850 containing the return value on output. */
12852 static struct die_info
*
12853 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
12855 struct attribute
*attr
;
12857 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
12861 return follow_die_ref (die
, attr
, ext_cu
);
12864 /* Convert a DIE tag into its string name. */
12867 dwarf_tag_name (unsigned tag
)
12871 case DW_TAG_padding
:
12872 return "DW_TAG_padding";
12873 case DW_TAG_array_type
:
12874 return "DW_TAG_array_type";
12875 case DW_TAG_class_type
:
12876 return "DW_TAG_class_type";
12877 case DW_TAG_entry_point
:
12878 return "DW_TAG_entry_point";
12879 case DW_TAG_enumeration_type
:
12880 return "DW_TAG_enumeration_type";
12881 case DW_TAG_formal_parameter
:
12882 return "DW_TAG_formal_parameter";
12883 case DW_TAG_imported_declaration
:
12884 return "DW_TAG_imported_declaration";
12886 return "DW_TAG_label";
12887 case DW_TAG_lexical_block
:
12888 return "DW_TAG_lexical_block";
12889 case DW_TAG_member
:
12890 return "DW_TAG_member";
12891 case DW_TAG_pointer_type
:
12892 return "DW_TAG_pointer_type";
12893 case DW_TAG_reference_type
:
12894 return "DW_TAG_reference_type";
12895 case DW_TAG_compile_unit
:
12896 return "DW_TAG_compile_unit";
12897 case DW_TAG_string_type
:
12898 return "DW_TAG_string_type";
12899 case DW_TAG_structure_type
:
12900 return "DW_TAG_structure_type";
12901 case DW_TAG_subroutine_type
:
12902 return "DW_TAG_subroutine_type";
12903 case DW_TAG_typedef
:
12904 return "DW_TAG_typedef";
12905 case DW_TAG_union_type
:
12906 return "DW_TAG_union_type";
12907 case DW_TAG_unspecified_parameters
:
12908 return "DW_TAG_unspecified_parameters";
12909 case DW_TAG_variant
:
12910 return "DW_TAG_variant";
12911 case DW_TAG_common_block
:
12912 return "DW_TAG_common_block";
12913 case DW_TAG_common_inclusion
:
12914 return "DW_TAG_common_inclusion";
12915 case DW_TAG_inheritance
:
12916 return "DW_TAG_inheritance";
12917 case DW_TAG_inlined_subroutine
:
12918 return "DW_TAG_inlined_subroutine";
12919 case DW_TAG_module
:
12920 return "DW_TAG_module";
12921 case DW_TAG_ptr_to_member_type
:
12922 return "DW_TAG_ptr_to_member_type";
12923 case DW_TAG_set_type
:
12924 return "DW_TAG_set_type";
12925 case DW_TAG_subrange_type
:
12926 return "DW_TAG_subrange_type";
12927 case DW_TAG_with_stmt
:
12928 return "DW_TAG_with_stmt";
12929 case DW_TAG_access_declaration
:
12930 return "DW_TAG_access_declaration";
12931 case DW_TAG_base_type
:
12932 return "DW_TAG_base_type";
12933 case DW_TAG_catch_block
:
12934 return "DW_TAG_catch_block";
12935 case DW_TAG_const_type
:
12936 return "DW_TAG_const_type";
12937 case DW_TAG_constant
:
12938 return "DW_TAG_constant";
12939 case DW_TAG_enumerator
:
12940 return "DW_TAG_enumerator";
12941 case DW_TAG_file_type
:
12942 return "DW_TAG_file_type";
12943 case DW_TAG_friend
:
12944 return "DW_TAG_friend";
12945 case DW_TAG_namelist
:
12946 return "DW_TAG_namelist";
12947 case DW_TAG_namelist_item
:
12948 return "DW_TAG_namelist_item";
12949 case DW_TAG_packed_type
:
12950 return "DW_TAG_packed_type";
12951 case DW_TAG_subprogram
:
12952 return "DW_TAG_subprogram";
12953 case DW_TAG_template_type_param
:
12954 return "DW_TAG_template_type_param";
12955 case DW_TAG_template_value_param
:
12956 return "DW_TAG_template_value_param";
12957 case DW_TAG_thrown_type
:
12958 return "DW_TAG_thrown_type";
12959 case DW_TAG_try_block
:
12960 return "DW_TAG_try_block";
12961 case DW_TAG_variant_part
:
12962 return "DW_TAG_variant_part";
12963 case DW_TAG_variable
:
12964 return "DW_TAG_variable";
12965 case DW_TAG_volatile_type
:
12966 return "DW_TAG_volatile_type";
12967 case DW_TAG_dwarf_procedure
:
12968 return "DW_TAG_dwarf_procedure";
12969 case DW_TAG_restrict_type
:
12970 return "DW_TAG_restrict_type";
12971 case DW_TAG_interface_type
:
12972 return "DW_TAG_interface_type";
12973 case DW_TAG_namespace
:
12974 return "DW_TAG_namespace";
12975 case DW_TAG_imported_module
:
12976 return "DW_TAG_imported_module";
12977 case DW_TAG_unspecified_type
:
12978 return "DW_TAG_unspecified_type";
12979 case DW_TAG_partial_unit
:
12980 return "DW_TAG_partial_unit";
12981 case DW_TAG_imported_unit
:
12982 return "DW_TAG_imported_unit";
12983 case DW_TAG_condition
:
12984 return "DW_TAG_condition";
12985 case DW_TAG_shared_type
:
12986 return "DW_TAG_shared_type";
12987 case DW_TAG_type_unit
:
12988 return "DW_TAG_type_unit";
12989 case DW_TAG_MIPS_loop
:
12990 return "DW_TAG_MIPS_loop";
12991 case DW_TAG_HP_array_descriptor
:
12992 return "DW_TAG_HP_array_descriptor";
12993 case DW_TAG_format_label
:
12994 return "DW_TAG_format_label";
12995 case DW_TAG_function_template
:
12996 return "DW_TAG_function_template";
12997 case DW_TAG_class_template
:
12998 return "DW_TAG_class_template";
12999 case DW_TAG_GNU_BINCL
:
13000 return "DW_TAG_GNU_BINCL";
13001 case DW_TAG_GNU_EINCL
:
13002 return "DW_TAG_GNU_EINCL";
13003 case DW_TAG_upc_shared_type
:
13004 return "DW_TAG_upc_shared_type";
13005 case DW_TAG_upc_strict_type
:
13006 return "DW_TAG_upc_strict_type";
13007 case DW_TAG_upc_relaxed_type
:
13008 return "DW_TAG_upc_relaxed_type";
13009 case DW_TAG_PGI_kanji_type
:
13010 return "DW_TAG_PGI_kanji_type";
13011 case DW_TAG_PGI_interface_block
:
13012 return "DW_TAG_PGI_interface_block";
13013 case DW_TAG_GNU_call_site
:
13014 return "DW_TAG_GNU_call_site";
13016 return "DW_TAG_<unknown>";
13020 /* Convert a DWARF attribute code into its string name. */
13023 dwarf_attr_name (unsigned attr
)
13027 case DW_AT_sibling
:
13028 return "DW_AT_sibling";
13029 case DW_AT_location
:
13030 return "DW_AT_location";
13032 return "DW_AT_name";
13033 case DW_AT_ordering
:
13034 return "DW_AT_ordering";
13035 case DW_AT_subscr_data
:
13036 return "DW_AT_subscr_data";
13037 case DW_AT_byte_size
:
13038 return "DW_AT_byte_size";
13039 case DW_AT_bit_offset
:
13040 return "DW_AT_bit_offset";
13041 case DW_AT_bit_size
:
13042 return "DW_AT_bit_size";
13043 case DW_AT_element_list
:
13044 return "DW_AT_element_list";
13045 case DW_AT_stmt_list
:
13046 return "DW_AT_stmt_list";
13048 return "DW_AT_low_pc";
13049 case DW_AT_high_pc
:
13050 return "DW_AT_high_pc";
13051 case DW_AT_language
:
13052 return "DW_AT_language";
13054 return "DW_AT_member";
13056 return "DW_AT_discr";
13057 case DW_AT_discr_value
:
13058 return "DW_AT_discr_value";
13059 case DW_AT_visibility
:
13060 return "DW_AT_visibility";
13062 return "DW_AT_import";
13063 case DW_AT_string_length
:
13064 return "DW_AT_string_length";
13065 case DW_AT_common_reference
:
13066 return "DW_AT_common_reference";
13067 case DW_AT_comp_dir
:
13068 return "DW_AT_comp_dir";
13069 case DW_AT_const_value
:
13070 return "DW_AT_const_value";
13071 case DW_AT_containing_type
:
13072 return "DW_AT_containing_type";
13073 case DW_AT_default_value
:
13074 return "DW_AT_default_value";
13076 return "DW_AT_inline";
13077 case DW_AT_is_optional
:
13078 return "DW_AT_is_optional";
13079 case DW_AT_lower_bound
:
13080 return "DW_AT_lower_bound";
13081 case DW_AT_producer
:
13082 return "DW_AT_producer";
13083 case DW_AT_prototyped
:
13084 return "DW_AT_prototyped";
13085 case DW_AT_return_addr
:
13086 return "DW_AT_return_addr";
13087 case DW_AT_start_scope
:
13088 return "DW_AT_start_scope";
13089 case DW_AT_bit_stride
:
13090 return "DW_AT_bit_stride";
13091 case DW_AT_upper_bound
:
13092 return "DW_AT_upper_bound";
13093 case DW_AT_abstract_origin
:
13094 return "DW_AT_abstract_origin";
13095 case DW_AT_accessibility
:
13096 return "DW_AT_accessibility";
13097 case DW_AT_address_class
:
13098 return "DW_AT_address_class";
13099 case DW_AT_artificial
:
13100 return "DW_AT_artificial";
13101 case DW_AT_base_types
:
13102 return "DW_AT_base_types";
13103 case DW_AT_calling_convention
:
13104 return "DW_AT_calling_convention";
13106 return "DW_AT_count";
13107 case DW_AT_data_member_location
:
13108 return "DW_AT_data_member_location";
13109 case DW_AT_decl_column
:
13110 return "DW_AT_decl_column";
13111 case DW_AT_decl_file
:
13112 return "DW_AT_decl_file";
13113 case DW_AT_decl_line
:
13114 return "DW_AT_decl_line";
13115 case DW_AT_declaration
:
13116 return "DW_AT_declaration";
13117 case DW_AT_discr_list
:
13118 return "DW_AT_discr_list";
13119 case DW_AT_encoding
:
13120 return "DW_AT_encoding";
13121 case DW_AT_external
:
13122 return "DW_AT_external";
13123 case DW_AT_frame_base
:
13124 return "DW_AT_frame_base";
13126 return "DW_AT_friend";
13127 case DW_AT_identifier_case
:
13128 return "DW_AT_identifier_case";
13129 case DW_AT_macro_info
:
13130 return "DW_AT_macro_info";
13131 case DW_AT_namelist_items
:
13132 return "DW_AT_namelist_items";
13133 case DW_AT_priority
:
13134 return "DW_AT_priority";
13135 case DW_AT_segment
:
13136 return "DW_AT_segment";
13137 case DW_AT_specification
:
13138 return "DW_AT_specification";
13139 case DW_AT_static_link
:
13140 return "DW_AT_static_link";
13142 return "DW_AT_type";
13143 case DW_AT_use_location
:
13144 return "DW_AT_use_location";
13145 case DW_AT_variable_parameter
:
13146 return "DW_AT_variable_parameter";
13147 case DW_AT_virtuality
:
13148 return "DW_AT_virtuality";
13149 case DW_AT_vtable_elem_location
:
13150 return "DW_AT_vtable_elem_location";
13151 /* DWARF 3 values. */
13152 case DW_AT_allocated
:
13153 return "DW_AT_allocated";
13154 case DW_AT_associated
:
13155 return "DW_AT_associated";
13156 case DW_AT_data_location
:
13157 return "DW_AT_data_location";
13158 case DW_AT_byte_stride
:
13159 return "DW_AT_byte_stride";
13160 case DW_AT_entry_pc
:
13161 return "DW_AT_entry_pc";
13162 case DW_AT_use_UTF8
:
13163 return "DW_AT_use_UTF8";
13164 case DW_AT_extension
:
13165 return "DW_AT_extension";
13167 return "DW_AT_ranges";
13168 case DW_AT_trampoline
:
13169 return "DW_AT_trampoline";
13170 case DW_AT_call_column
:
13171 return "DW_AT_call_column";
13172 case DW_AT_call_file
:
13173 return "DW_AT_call_file";
13174 case DW_AT_call_line
:
13175 return "DW_AT_call_line";
13176 case DW_AT_description
:
13177 return "DW_AT_description";
13178 case DW_AT_binary_scale
:
13179 return "DW_AT_binary_scale";
13180 case DW_AT_decimal_scale
:
13181 return "DW_AT_decimal_scale";
13183 return "DW_AT_small";
13184 case DW_AT_decimal_sign
:
13185 return "DW_AT_decimal_sign";
13186 case DW_AT_digit_count
:
13187 return "DW_AT_digit_count";
13188 case DW_AT_picture_string
:
13189 return "DW_AT_picture_string";
13190 case DW_AT_mutable
:
13191 return "DW_AT_mutable";
13192 case DW_AT_threads_scaled
:
13193 return "DW_AT_threads_scaled";
13194 case DW_AT_explicit
:
13195 return "DW_AT_explicit";
13196 case DW_AT_object_pointer
:
13197 return "DW_AT_object_pointer";
13198 case DW_AT_endianity
:
13199 return "DW_AT_endianity";
13200 case DW_AT_elemental
:
13201 return "DW_AT_elemental";
13203 return "DW_AT_pure";
13204 case DW_AT_recursive
:
13205 return "DW_AT_recursive";
13206 /* DWARF 4 values. */
13207 case DW_AT_signature
:
13208 return "DW_AT_signature";
13209 case DW_AT_linkage_name
:
13210 return "DW_AT_linkage_name";
13211 /* SGI/MIPS extensions. */
13212 #ifdef MIPS /* collides with DW_AT_HP_block_index */
13213 case DW_AT_MIPS_fde
:
13214 return "DW_AT_MIPS_fde";
13216 case DW_AT_MIPS_loop_begin
:
13217 return "DW_AT_MIPS_loop_begin";
13218 case DW_AT_MIPS_tail_loop_begin
:
13219 return "DW_AT_MIPS_tail_loop_begin";
13220 case DW_AT_MIPS_epilog_begin
:
13221 return "DW_AT_MIPS_epilog_begin";
13222 case DW_AT_MIPS_loop_unroll_factor
:
13223 return "DW_AT_MIPS_loop_unroll_factor";
13224 case DW_AT_MIPS_software_pipeline_depth
:
13225 return "DW_AT_MIPS_software_pipeline_depth";
13226 case DW_AT_MIPS_linkage_name
:
13227 return "DW_AT_MIPS_linkage_name";
13228 case DW_AT_MIPS_stride
:
13229 return "DW_AT_MIPS_stride";
13230 case DW_AT_MIPS_abstract_name
:
13231 return "DW_AT_MIPS_abstract_name";
13232 case DW_AT_MIPS_clone_origin
:
13233 return "DW_AT_MIPS_clone_origin";
13234 case DW_AT_MIPS_has_inlines
:
13235 return "DW_AT_MIPS_has_inlines";
13236 /* HP extensions. */
13237 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
13238 case DW_AT_HP_block_index
:
13239 return "DW_AT_HP_block_index";
13241 case DW_AT_HP_unmodifiable
:
13242 return "DW_AT_HP_unmodifiable";
13243 case DW_AT_HP_actuals_stmt_list
:
13244 return "DW_AT_HP_actuals_stmt_list";
13245 case DW_AT_HP_proc_per_section
:
13246 return "DW_AT_HP_proc_per_section";
13247 case DW_AT_HP_raw_data_ptr
:
13248 return "DW_AT_HP_raw_data_ptr";
13249 case DW_AT_HP_pass_by_reference
:
13250 return "DW_AT_HP_pass_by_reference";
13251 case DW_AT_HP_opt_level
:
13252 return "DW_AT_HP_opt_level";
13253 case DW_AT_HP_prof_version_id
:
13254 return "DW_AT_HP_prof_version_id";
13255 case DW_AT_HP_opt_flags
:
13256 return "DW_AT_HP_opt_flags";
13257 case DW_AT_HP_cold_region_low_pc
:
13258 return "DW_AT_HP_cold_region_low_pc";
13259 case DW_AT_HP_cold_region_high_pc
:
13260 return "DW_AT_HP_cold_region_high_pc";
13261 case DW_AT_HP_all_variables_modifiable
:
13262 return "DW_AT_HP_all_variables_modifiable";
13263 case DW_AT_HP_linkage_name
:
13264 return "DW_AT_HP_linkage_name";
13265 case DW_AT_HP_prof_flags
:
13266 return "DW_AT_HP_prof_flags";
13267 /* GNU extensions. */
13268 case DW_AT_sf_names
:
13269 return "DW_AT_sf_names";
13270 case DW_AT_src_info
:
13271 return "DW_AT_src_info";
13272 case DW_AT_mac_info
:
13273 return "DW_AT_mac_info";
13274 case DW_AT_src_coords
:
13275 return "DW_AT_src_coords";
13276 case DW_AT_body_begin
:
13277 return "DW_AT_body_begin";
13278 case DW_AT_body_end
:
13279 return "DW_AT_body_end";
13280 case DW_AT_GNU_vector
:
13281 return "DW_AT_GNU_vector";
13282 case DW_AT_GNU_odr_signature
:
13283 return "DW_AT_GNU_odr_signature";
13284 /* VMS extensions. */
13285 case DW_AT_VMS_rtnbeg_pd_address
:
13286 return "DW_AT_VMS_rtnbeg_pd_address";
13287 /* UPC extension. */
13288 case DW_AT_upc_threads_scaled
:
13289 return "DW_AT_upc_threads_scaled";
13290 /* PGI (STMicroelectronics) extensions. */
13291 case DW_AT_PGI_lbase
:
13292 return "DW_AT_PGI_lbase";
13293 case DW_AT_PGI_soffset
:
13294 return "DW_AT_PGI_soffset";
13295 case DW_AT_PGI_lstride
:
13296 return "DW_AT_PGI_lstride";
13298 return "DW_AT_<unknown>";
13302 /* Convert a DWARF value form code into its string name. */
13305 dwarf_form_name (unsigned form
)
13310 return "DW_FORM_addr";
13311 case DW_FORM_block2
:
13312 return "DW_FORM_block2";
13313 case DW_FORM_block4
:
13314 return "DW_FORM_block4";
13315 case DW_FORM_data2
:
13316 return "DW_FORM_data2";
13317 case DW_FORM_data4
:
13318 return "DW_FORM_data4";
13319 case DW_FORM_data8
:
13320 return "DW_FORM_data8";
13321 case DW_FORM_string
:
13322 return "DW_FORM_string";
13323 case DW_FORM_block
:
13324 return "DW_FORM_block";
13325 case DW_FORM_block1
:
13326 return "DW_FORM_block1";
13327 case DW_FORM_data1
:
13328 return "DW_FORM_data1";
13330 return "DW_FORM_flag";
13331 case DW_FORM_sdata
:
13332 return "DW_FORM_sdata";
13334 return "DW_FORM_strp";
13335 case DW_FORM_udata
:
13336 return "DW_FORM_udata";
13337 case DW_FORM_ref_addr
:
13338 return "DW_FORM_ref_addr";
13340 return "DW_FORM_ref1";
13342 return "DW_FORM_ref2";
13344 return "DW_FORM_ref4";
13346 return "DW_FORM_ref8";
13347 case DW_FORM_ref_udata
:
13348 return "DW_FORM_ref_udata";
13349 case DW_FORM_indirect
:
13350 return "DW_FORM_indirect";
13351 case DW_FORM_sec_offset
:
13352 return "DW_FORM_sec_offset";
13353 case DW_FORM_exprloc
:
13354 return "DW_FORM_exprloc";
13355 case DW_FORM_flag_present
:
13356 return "DW_FORM_flag_present";
13357 case DW_FORM_ref_sig8
:
13358 return "DW_FORM_ref_sig8";
13360 return "DW_FORM_<unknown>";
13364 /* Convert a DWARF stack opcode into its string name. */
13367 dwarf_stack_op_name (unsigned op
)
13372 return "DW_OP_addr";
13374 return "DW_OP_deref";
13375 case DW_OP_const1u
:
13376 return "DW_OP_const1u";
13377 case DW_OP_const1s
:
13378 return "DW_OP_const1s";
13379 case DW_OP_const2u
:
13380 return "DW_OP_const2u";
13381 case DW_OP_const2s
:
13382 return "DW_OP_const2s";
13383 case DW_OP_const4u
:
13384 return "DW_OP_const4u";
13385 case DW_OP_const4s
:
13386 return "DW_OP_const4s";
13387 case DW_OP_const8u
:
13388 return "DW_OP_const8u";
13389 case DW_OP_const8s
:
13390 return "DW_OP_const8s";
13392 return "DW_OP_constu";
13394 return "DW_OP_consts";
13396 return "DW_OP_dup";
13398 return "DW_OP_drop";
13400 return "DW_OP_over";
13402 return "DW_OP_pick";
13404 return "DW_OP_swap";
13406 return "DW_OP_rot";
13408 return "DW_OP_xderef";
13410 return "DW_OP_abs";
13412 return "DW_OP_and";
13414 return "DW_OP_div";
13416 return "DW_OP_minus";
13418 return "DW_OP_mod";
13420 return "DW_OP_mul";
13422 return "DW_OP_neg";
13424 return "DW_OP_not";
13428 return "DW_OP_plus";
13429 case DW_OP_plus_uconst
:
13430 return "DW_OP_plus_uconst";
13432 return "DW_OP_shl";
13434 return "DW_OP_shr";
13436 return "DW_OP_shra";
13438 return "DW_OP_xor";
13440 return "DW_OP_bra";
13454 return "DW_OP_skip";
13456 return "DW_OP_lit0";
13458 return "DW_OP_lit1";
13460 return "DW_OP_lit2";
13462 return "DW_OP_lit3";
13464 return "DW_OP_lit4";
13466 return "DW_OP_lit5";
13468 return "DW_OP_lit6";
13470 return "DW_OP_lit7";
13472 return "DW_OP_lit8";
13474 return "DW_OP_lit9";
13476 return "DW_OP_lit10";
13478 return "DW_OP_lit11";
13480 return "DW_OP_lit12";
13482 return "DW_OP_lit13";
13484 return "DW_OP_lit14";
13486 return "DW_OP_lit15";
13488 return "DW_OP_lit16";
13490 return "DW_OP_lit17";
13492 return "DW_OP_lit18";
13494 return "DW_OP_lit19";
13496 return "DW_OP_lit20";
13498 return "DW_OP_lit21";
13500 return "DW_OP_lit22";
13502 return "DW_OP_lit23";
13504 return "DW_OP_lit24";
13506 return "DW_OP_lit25";
13508 return "DW_OP_lit26";
13510 return "DW_OP_lit27";
13512 return "DW_OP_lit28";
13514 return "DW_OP_lit29";
13516 return "DW_OP_lit30";
13518 return "DW_OP_lit31";
13520 return "DW_OP_reg0";
13522 return "DW_OP_reg1";
13524 return "DW_OP_reg2";
13526 return "DW_OP_reg3";
13528 return "DW_OP_reg4";
13530 return "DW_OP_reg5";
13532 return "DW_OP_reg6";
13534 return "DW_OP_reg7";
13536 return "DW_OP_reg8";
13538 return "DW_OP_reg9";
13540 return "DW_OP_reg10";
13542 return "DW_OP_reg11";
13544 return "DW_OP_reg12";
13546 return "DW_OP_reg13";
13548 return "DW_OP_reg14";
13550 return "DW_OP_reg15";
13552 return "DW_OP_reg16";
13554 return "DW_OP_reg17";
13556 return "DW_OP_reg18";
13558 return "DW_OP_reg19";
13560 return "DW_OP_reg20";
13562 return "DW_OP_reg21";
13564 return "DW_OP_reg22";
13566 return "DW_OP_reg23";
13568 return "DW_OP_reg24";
13570 return "DW_OP_reg25";
13572 return "DW_OP_reg26";
13574 return "DW_OP_reg27";
13576 return "DW_OP_reg28";
13578 return "DW_OP_reg29";
13580 return "DW_OP_reg30";
13582 return "DW_OP_reg31";
13584 return "DW_OP_breg0";
13586 return "DW_OP_breg1";
13588 return "DW_OP_breg2";
13590 return "DW_OP_breg3";
13592 return "DW_OP_breg4";
13594 return "DW_OP_breg5";
13596 return "DW_OP_breg6";
13598 return "DW_OP_breg7";
13600 return "DW_OP_breg8";
13602 return "DW_OP_breg9";
13604 return "DW_OP_breg10";
13606 return "DW_OP_breg11";
13608 return "DW_OP_breg12";
13610 return "DW_OP_breg13";
13612 return "DW_OP_breg14";
13614 return "DW_OP_breg15";
13616 return "DW_OP_breg16";
13618 return "DW_OP_breg17";
13620 return "DW_OP_breg18";
13622 return "DW_OP_breg19";
13624 return "DW_OP_breg20";
13626 return "DW_OP_breg21";
13628 return "DW_OP_breg22";
13630 return "DW_OP_breg23";
13632 return "DW_OP_breg24";
13634 return "DW_OP_breg25";
13636 return "DW_OP_breg26";
13638 return "DW_OP_breg27";
13640 return "DW_OP_breg28";
13642 return "DW_OP_breg29";
13644 return "DW_OP_breg30";
13646 return "DW_OP_breg31";
13648 return "DW_OP_regx";
13650 return "DW_OP_fbreg";
13652 return "DW_OP_bregx";
13654 return "DW_OP_piece";
13655 case DW_OP_deref_size
:
13656 return "DW_OP_deref_size";
13657 case DW_OP_xderef_size
:
13658 return "DW_OP_xderef_size";
13660 return "DW_OP_nop";
13661 /* DWARF 3 extensions. */
13662 case DW_OP_push_object_address
:
13663 return "DW_OP_push_object_address";
13665 return "DW_OP_call2";
13667 return "DW_OP_call4";
13668 case DW_OP_call_ref
:
13669 return "DW_OP_call_ref";
13670 case DW_OP_form_tls_address
:
13671 return "DW_OP_form_tls_address";
13672 case DW_OP_call_frame_cfa
:
13673 return "DW_OP_call_frame_cfa";
13674 case DW_OP_bit_piece
:
13675 return "DW_OP_bit_piece";
13676 /* DWARF 4 extensions. */
13677 case DW_OP_implicit_value
:
13678 return "DW_OP_implicit_value";
13679 case DW_OP_stack_value
:
13680 return "DW_OP_stack_value";
13681 /* GNU extensions. */
13682 case DW_OP_GNU_push_tls_address
:
13683 return "DW_OP_GNU_push_tls_address";
13684 case DW_OP_GNU_uninit
:
13685 return "DW_OP_GNU_uninit";
13686 case DW_OP_GNU_implicit_pointer
:
13687 return "DW_OP_GNU_implicit_pointer";
13688 case DW_OP_GNU_entry_value
:
13689 return "DW_OP_GNU_entry_value";
13690 case DW_OP_GNU_const_type
:
13691 return "DW_OP_GNU_const_type";
13692 case DW_OP_GNU_regval_type
:
13693 return "DW_OP_GNU_regval_type";
13694 case DW_OP_GNU_deref_type
:
13695 return "DW_OP_GNU_deref_type";
13696 case DW_OP_GNU_convert
:
13697 return "DW_OP_GNU_convert";
13698 case DW_OP_GNU_reinterpret
:
13699 return "DW_OP_GNU_reinterpret";
13706 dwarf_bool_name (unsigned mybool
)
13714 /* Convert a DWARF type code into its string name. */
13717 dwarf_type_encoding_name (unsigned enc
)
13722 return "DW_ATE_void";
13723 case DW_ATE_address
:
13724 return "DW_ATE_address";
13725 case DW_ATE_boolean
:
13726 return "DW_ATE_boolean";
13727 case DW_ATE_complex_float
:
13728 return "DW_ATE_complex_float";
13730 return "DW_ATE_float";
13731 case DW_ATE_signed
:
13732 return "DW_ATE_signed";
13733 case DW_ATE_signed_char
:
13734 return "DW_ATE_signed_char";
13735 case DW_ATE_unsigned
:
13736 return "DW_ATE_unsigned";
13737 case DW_ATE_unsigned_char
:
13738 return "DW_ATE_unsigned_char";
13740 case DW_ATE_imaginary_float
:
13741 return "DW_ATE_imaginary_float";
13742 case DW_ATE_packed_decimal
:
13743 return "DW_ATE_packed_decimal";
13744 case DW_ATE_numeric_string
:
13745 return "DW_ATE_numeric_string";
13746 case DW_ATE_edited
:
13747 return "DW_ATE_edited";
13748 case DW_ATE_signed_fixed
:
13749 return "DW_ATE_signed_fixed";
13750 case DW_ATE_unsigned_fixed
:
13751 return "DW_ATE_unsigned_fixed";
13752 case DW_ATE_decimal_float
:
13753 return "DW_ATE_decimal_float";
13756 return "DW_ATE_UTF";
13757 /* HP extensions. */
13758 case DW_ATE_HP_float80
:
13759 return "DW_ATE_HP_float80";
13760 case DW_ATE_HP_complex_float80
:
13761 return "DW_ATE_HP_complex_float80";
13762 case DW_ATE_HP_float128
:
13763 return "DW_ATE_HP_float128";
13764 case DW_ATE_HP_complex_float128
:
13765 return "DW_ATE_HP_complex_float128";
13766 case DW_ATE_HP_floathpintel
:
13767 return "DW_ATE_HP_floathpintel";
13768 case DW_ATE_HP_imaginary_float80
:
13769 return "DW_ATE_HP_imaginary_float80";
13770 case DW_ATE_HP_imaginary_float128
:
13771 return "DW_ATE_HP_imaginary_float128";
13773 return "DW_ATE_<unknown>";
13777 /* Convert a DWARF call frame info operation to its string name. */
13781 dwarf_cfi_name (unsigned cfi_opc
)
13785 case DW_CFA_advance_loc
:
13786 return "DW_CFA_advance_loc";
13787 case DW_CFA_offset
:
13788 return "DW_CFA_offset";
13789 case DW_CFA_restore
:
13790 return "DW_CFA_restore";
13792 return "DW_CFA_nop";
13793 case DW_CFA_set_loc
:
13794 return "DW_CFA_set_loc";
13795 case DW_CFA_advance_loc1
:
13796 return "DW_CFA_advance_loc1";
13797 case DW_CFA_advance_loc2
:
13798 return "DW_CFA_advance_loc2";
13799 case DW_CFA_advance_loc4
:
13800 return "DW_CFA_advance_loc4";
13801 case DW_CFA_offset_extended
:
13802 return "DW_CFA_offset_extended";
13803 case DW_CFA_restore_extended
:
13804 return "DW_CFA_restore_extended";
13805 case DW_CFA_undefined
:
13806 return "DW_CFA_undefined";
13807 case DW_CFA_same_value
:
13808 return "DW_CFA_same_value";
13809 case DW_CFA_register
:
13810 return "DW_CFA_register";
13811 case DW_CFA_remember_state
:
13812 return "DW_CFA_remember_state";
13813 case DW_CFA_restore_state
:
13814 return "DW_CFA_restore_state";
13815 case DW_CFA_def_cfa
:
13816 return "DW_CFA_def_cfa";
13817 case DW_CFA_def_cfa_register
:
13818 return "DW_CFA_def_cfa_register";
13819 case DW_CFA_def_cfa_offset
:
13820 return "DW_CFA_def_cfa_offset";
13822 case DW_CFA_def_cfa_expression
:
13823 return "DW_CFA_def_cfa_expression";
13824 case DW_CFA_expression
:
13825 return "DW_CFA_expression";
13826 case DW_CFA_offset_extended_sf
:
13827 return "DW_CFA_offset_extended_sf";
13828 case DW_CFA_def_cfa_sf
:
13829 return "DW_CFA_def_cfa_sf";
13830 case DW_CFA_def_cfa_offset_sf
:
13831 return "DW_CFA_def_cfa_offset_sf";
13832 case DW_CFA_val_offset
:
13833 return "DW_CFA_val_offset";
13834 case DW_CFA_val_offset_sf
:
13835 return "DW_CFA_val_offset_sf";
13836 case DW_CFA_val_expression
:
13837 return "DW_CFA_val_expression";
13838 /* SGI/MIPS specific. */
13839 case DW_CFA_MIPS_advance_loc8
:
13840 return "DW_CFA_MIPS_advance_loc8";
13841 /* GNU extensions. */
13842 case DW_CFA_GNU_window_save
:
13843 return "DW_CFA_GNU_window_save";
13844 case DW_CFA_GNU_args_size
:
13845 return "DW_CFA_GNU_args_size";
13846 case DW_CFA_GNU_negative_offset_extended
:
13847 return "DW_CFA_GNU_negative_offset_extended";
13849 return "DW_CFA_<unknown>";
13855 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
13859 print_spaces (indent
, f
);
13860 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
13861 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
13863 if (die
->parent
!= NULL
)
13865 print_spaces (indent
, f
);
13866 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
13867 die
->parent
->offset
);
13870 print_spaces (indent
, f
);
13871 fprintf_unfiltered (f
, " has children: %s\n",
13872 dwarf_bool_name (die
->child
!= NULL
));
13874 print_spaces (indent
, f
);
13875 fprintf_unfiltered (f
, " attributes:\n");
13877 for (i
= 0; i
< die
->num_attrs
; ++i
)
13879 print_spaces (indent
, f
);
13880 fprintf_unfiltered (f
, " %s (%s) ",
13881 dwarf_attr_name (die
->attrs
[i
].name
),
13882 dwarf_form_name (die
->attrs
[i
].form
));
13884 switch (die
->attrs
[i
].form
)
13886 case DW_FORM_ref_addr
:
13888 fprintf_unfiltered (f
, "address: ");
13889 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
13891 case DW_FORM_block2
:
13892 case DW_FORM_block4
:
13893 case DW_FORM_block
:
13894 case DW_FORM_block1
:
13895 fprintf_unfiltered (f
, "block: size %d",
13896 DW_BLOCK (&die
->attrs
[i
])->size
);
13898 case DW_FORM_exprloc
:
13899 fprintf_unfiltered (f
, "expression: size %u",
13900 DW_BLOCK (&die
->attrs
[i
])->size
);
13905 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
13906 (long) (DW_ADDR (&die
->attrs
[i
])));
13908 case DW_FORM_data1
:
13909 case DW_FORM_data2
:
13910 case DW_FORM_data4
:
13911 case DW_FORM_data8
:
13912 case DW_FORM_udata
:
13913 case DW_FORM_sdata
:
13914 fprintf_unfiltered (f
, "constant: %s",
13915 pulongest (DW_UNSND (&die
->attrs
[i
])));
13917 case DW_FORM_sec_offset
:
13918 fprintf_unfiltered (f
, "section offset: %s",
13919 pulongest (DW_UNSND (&die
->attrs
[i
])));
13921 case DW_FORM_ref_sig8
:
13922 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
13923 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
13924 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
);
13926 fprintf_unfiltered (f
, "signatured type, offset: unknown");
13928 case DW_FORM_string
:
13930 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
13931 DW_STRING (&die
->attrs
[i
])
13932 ? DW_STRING (&die
->attrs
[i
]) : "",
13933 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
13936 if (DW_UNSND (&die
->attrs
[i
]))
13937 fprintf_unfiltered (f
, "flag: TRUE");
13939 fprintf_unfiltered (f
, "flag: FALSE");
13941 case DW_FORM_flag_present
:
13942 fprintf_unfiltered (f
, "flag: TRUE");
13944 case DW_FORM_indirect
:
13945 /* The reader will have reduced the indirect form to
13946 the "base form" so this form should not occur. */
13947 fprintf_unfiltered (f
,
13948 "unexpected attribute form: DW_FORM_indirect");
13951 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
13952 die
->attrs
[i
].form
);
13955 fprintf_unfiltered (f
, "\n");
13960 dump_die_for_error (struct die_info
*die
)
13962 dump_die_shallow (gdb_stderr
, 0, die
);
13966 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
13968 int indent
= level
* 4;
13970 gdb_assert (die
!= NULL
);
13972 if (level
>= max_level
)
13975 dump_die_shallow (f
, indent
, die
);
13977 if (die
->child
!= NULL
)
13979 print_spaces (indent
, f
);
13980 fprintf_unfiltered (f
, " Children:");
13981 if (level
+ 1 < max_level
)
13983 fprintf_unfiltered (f
, "\n");
13984 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
13988 fprintf_unfiltered (f
,
13989 " [not printed, max nesting level reached]\n");
13993 if (die
->sibling
!= NULL
&& level
> 0)
13995 dump_die_1 (f
, level
, max_level
, die
->sibling
);
13999 /* This is called from the pdie macro in gdbinit.in.
14000 It's not static so gcc will keep a copy callable from gdb. */
14003 dump_die (struct die_info
*die
, int max_level
)
14005 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
14009 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
14013 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
14019 is_ref_attr (struct attribute
*attr
)
14021 switch (attr
->form
)
14023 case DW_FORM_ref_addr
:
14028 case DW_FORM_ref_udata
:
14035 static unsigned int
14036 dwarf2_get_ref_die_offset (struct attribute
*attr
)
14038 if (is_ref_attr (attr
))
14039 return DW_ADDR (attr
);
14041 complaint (&symfile_complaints
,
14042 _("unsupported die ref attribute form: '%s'"),
14043 dwarf_form_name (attr
->form
));
14047 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
14048 * the value held by the attribute is not constant. */
14051 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
14053 if (attr
->form
== DW_FORM_sdata
)
14054 return DW_SND (attr
);
14055 else if (attr
->form
== DW_FORM_udata
14056 || attr
->form
== DW_FORM_data1
14057 || attr
->form
== DW_FORM_data2
14058 || attr
->form
== DW_FORM_data4
14059 || attr
->form
== DW_FORM_data8
)
14060 return DW_UNSND (attr
);
14063 complaint (&symfile_complaints
,
14064 _("Attribute value is not a constant (%s)"),
14065 dwarf_form_name (attr
->form
));
14066 return default_value
;
14070 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
14071 unit and add it to our queue.
14072 The result is non-zero if PER_CU was queued, otherwise the result is zero
14073 meaning either PER_CU is already queued or it is already loaded. */
14076 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
14077 struct dwarf2_per_cu_data
*per_cu
)
14079 /* We may arrive here during partial symbol reading, if we need full
14080 DIEs to process an unusual case (e.g. template arguments). Do
14081 not queue PER_CU, just tell our caller to load its DIEs. */
14082 if (dwarf2_per_objfile
->reading_partial_symbols
)
14084 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
14089 /* Mark the dependence relation so that we don't flush PER_CU
14091 dwarf2_add_dependence (this_cu
, per_cu
);
14093 /* If it's already on the queue, we have nothing to do. */
14094 if (per_cu
->queued
)
14097 /* If the compilation unit is already loaded, just mark it as
14099 if (per_cu
->cu
!= NULL
)
14101 per_cu
->cu
->last_used
= 0;
14105 /* Add it to the queue. */
14106 queue_comp_unit (per_cu
, this_cu
->objfile
);
14111 /* Follow reference or signature attribute ATTR of SRC_DIE.
14112 On entry *REF_CU is the CU of SRC_DIE.
14113 On exit *REF_CU is the CU of the result. */
14115 static struct die_info
*
14116 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
14117 struct dwarf2_cu
**ref_cu
)
14119 struct die_info
*die
;
14121 if (is_ref_attr (attr
))
14122 die
= follow_die_ref (src_die
, attr
, ref_cu
);
14123 else if (attr
->form
== DW_FORM_ref_sig8
)
14124 die
= follow_die_sig (src_die
, attr
, ref_cu
);
14127 dump_die_for_error (src_die
);
14128 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
14129 (*ref_cu
)->objfile
->name
);
14135 /* Follow reference OFFSET.
14136 On entry *REF_CU is the CU of the source die referencing OFFSET.
14137 On exit *REF_CU is the CU of the result.
14138 Returns NULL if OFFSET is invalid. */
14140 static struct die_info
*
14141 follow_die_offset (unsigned int offset
, struct dwarf2_cu
**ref_cu
)
14143 struct die_info temp_die
;
14144 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
14146 gdb_assert (cu
->per_cu
!= NULL
);
14150 if (cu
->per_cu
->debug_type_section
)
14152 /* .debug_types CUs cannot reference anything outside their CU.
14153 If they need to, they have to reference a signatured type via
14154 DW_FORM_ref_sig8. */
14155 if (! offset_in_cu_p (&cu
->header
, offset
))
14158 else if (! offset_in_cu_p (&cu
->header
, offset
))
14160 struct dwarf2_per_cu_data
*per_cu
;
14162 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
14164 /* If necessary, add it to the queue and load its DIEs. */
14165 if (maybe_queue_comp_unit (cu
, per_cu
))
14166 load_full_comp_unit (per_cu
, cu
->objfile
);
14168 target_cu
= per_cu
->cu
;
14170 else if (cu
->dies
== NULL
)
14172 /* We're loading full DIEs during partial symbol reading. */
14173 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
14174 load_full_comp_unit (cu
->per_cu
, cu
->objfile
);
14177 *ref_cu
= target_cu
;
14178 temp_die
.offset
= offset
;
14179 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
14182 /* Follow reference attribute ATTR of SRC_DIE.
14183 On entry *REF_CU is the CU of SRC_DIE.
14184 On exit *REF_CU is the CU of the result. */
14186 static struct die_info
*
14187 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
14188 struct dwarf2_cu
**ref_cu
)
14190 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
14191 struct dwarf2_cu
*cu
= *ref_cu
;
14192 struct die_info
*die
;
14194 die
= follow_die_offset (offset
, ref_cu
);
14196 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
14197 "at 0x%x [in module %s]"),
14198 offset
, src_die
->offset
, cu
->objfile
->name
);
14203 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
14204 Returned value is intended for DW_OP_call*. Returned
14205 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
14207 struct dwarf2_locexpr_baton
14208 dwarf2_fetch_die_location_block (unsigned int offset
,
14209 struct dwarf2_per_cu_data
*per_cu
,
14210 CORE_ADDR (*get_frame_pc
) (void *baton
),
14213 struct dwarf2_cu
*cu
;
14214 struct die_info
*die
;
14215 struct attribute
*attr
;
14216 struct dwarf2_locexpr_baton retval
;
14218 dw2_setup (per_cu
->objfile
);
14220 if (per_cu
->cu
== NULL
)
14224 die
= follow_die_offset (offset
, &cu
);
14226 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
14227 offset
, per_cu
->cu
->objfile
->name
);
14229 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
14232 /* DWARF: "If there is no such attribute, then there is no effect.".
14233 DATA is ignored if SIZE is 0. */
14235 retval
.data
= NULL
;
14238 else if (attr_form_is_section_offset (attr
))
14240 struct dwarf2_loclist_baton loclist_baton
;
14241 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
14244 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
14246 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
14248 retval
.size
= size
;
14252 if (!attr_form_is_block (attr
))
14253 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
14254 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
14255 offset
, per_cu
->cu
->objfile
->name
);
14257 retval
.data
= DW_BLOCK (attr
)->data
;
14258 retval
.size
= DW_BLOCK (attr
)->size
;
14260 retval
.per_cu
= cu
->per_cu
;
14262 age_cached_comp_units ();
14267 /* Return the type of the DIE at DIE_OFFSET in the CU named by
14271 dwarf2_get_die_type (unsigned int die_offset
,
14272 struct dwarf2_per_cu_data
*per_cu
)
14274 dw2_setup (per_cu
->objfile
);
14275 return get_die_type_at_offset (die_offset
, per_cu
);
14278 /* Follow the signature attribute ATTR in SRC_DIE.
14279 On entry *REF_CU is the CU of SRC_DIE.
14280 On exit *REF_CU is the CU of the result. */
14282 static struct die_info
*
14283 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
14284 struct dwarf2_cu
**ref_cu
)
14286 struct objfile
*objfile
= (*ref_cu
)->objfile
;
14287 struct die_info temp_die
;
14288 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
14289 struct dwarf2_cu
*sig_cu
;
14290 struct die_info
*die
;
14292 /* sig_type will be NULL if the signatured type is missing from
14294 if (sig_type
== NULL
)
14295 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
14296 "at 0x%x [in module %s]"),
14297 src_die
->offset
, objfile
->name
);
14299 /* If necessary, add it to the queue and load its DIEs. */
14301 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
14302 read_signatured_type (objfile
, sig_type
);
14304 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
14306 sig_cu
= sig_type
->per_cu
.cu
;
14307 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
14308 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
14315 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
14316 "from DIE at 0x%x [in module %s]"),
14317 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
14320 /* Given an offset of a signatured type, return its signatured_type. */
14322 static struct signatured_type
*
14323 lookup_signatured_type_at_offset (struct objfile
*objfile
,
14324 struct dwarf2_section_info
*section
,
14325 unsigned int offset
)
14327 gdb_byte
*info_ptr
= section
->buffer
+ offset
;
14328 unsigned int length
, initial_length_size
;
14329 unsigned int sig_offset
;
14330 struct signatured_type find_entry
, *type_sig
;
14332 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
14333 sig_offset
= (initial_length_size
14335 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
14336 + 1 /*address_size*/);
14337 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
14338 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
14340 /* This is only used to lookup previously recorded types.
14341 If we didn't find it, it's our bug. */
14342 gdb_assert (type_sig
!= NULL
);
14343 gdb_assert (offset
== type_sig
->per_cu
.offset
);
14348 /* Read in signatured type at OFFSET and build its CU and die(s). */
14351 read_signatured_type_at_offset (struct objfile
*objfile
,
14352 struct dwarf2_section_info
*sect
,
14353 unsigned int offset
)
14355 struct signatured_type
*type_sig
;
14357 dwarf2_read_section (objfile
, sect
);
14359 /* We have the section offset, but we need the signature to do the
14360 hash table lookup. */
14361 type_sig
= lookup_signatured_type_at_offset (objfile
, sect
, offset
);
14363 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
14365 read_signatured_type (objfile
, type_sig
);
14367 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
14370 /* Read in a signatured type and build its CU and DIEs. */
14373 read_signatured_type (struct objfile
*objfile
,
14374 struct signatured_type
*type_sig
)
14376 gdb_byte
*types_ptr
;
14377 struct die_reader_specs reader_specs
;
14378 struct dwarf2_cu
*cu
;
14379 ULONGEST signature
;
14380 struct cleanup
*back_to
, *free_cu_cleanup
;
14381 struct dwarf2_section_info
*section
= type_sig
->per_cu
.debug_type_section
;
14383 dwarf2_read_section (objfile
, section
);
14384 types_ptr
= section
->buffer
+ type_sig
->per_cu
.offset
;
14386 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
14388 cu
= xmalloc (sizeof (*cu
));
14389 init_one_comp_unit (cu
, objfile
);
14391 type_sig
->per_cu
.cu
= cu
;
14392 cu
->per_cu
= &type_sig
->per_cu
;
14394 /* If an error occurs while loading, release our storage. */
14395 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
14397 types_ptr
= read_type_comp_unit_head (&cu
->header
, section
, &signature
,
14398 types_ptr
, objfile
->obfd
);
14399 gdb_assert (signature
== type_sig
->signature
);
14402 = htab_create_alloc_ex (cu
->header
.length
/ 12,
14406 &cu
->comp_unit_obstack
,
14407 hashtab_obstack_allocate
,
14408 dummy_obstack_deallocate
);
14410 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
14411 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
14413 init_cu_die_reader (&reader_specs
, cu
);
14415 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
14418 /* We try not to read any attributes in this function, because not
14419 all objfiles needed for references have been loaded yet, and symbol
14420 table processing isn't initialized. But we have to set the CU language,
14421 or we won't be able to build types correctly. */
14422 prepare_one_comp_unit (cu
, cu
->dies
);
14424 do_cleanups (back_to
);
14426 /* We've successfully allocated this compilation unit. Let our caller
14427 clean it up when finished with it. */
14428 discard_cleanups (free_cu_cleanup
);
14430 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
14431 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
14434 /* Decode simple location descriptions.
14435 Given a pointer to a dwarf block that defines a location, compute
14436 the location and return the value.
14438 NOTE drow/2003-11-18: This function is called in two situations
14439 now: for the address of static or global variables (partial symbols
14440 only) and for offsets into structures which are expected to be
14441 (more or less) constant. The partial symbol case should go away,
14442 and only the constant case should remain. That will let this
14443 function complain more accurately. A few special modes are allowed
14444 without complaint for global variables (for instance, global
14445 register values and thread-local values).
14447 A location description containing no operations indicates that the
14448 object is optimized out. The return value is 0 for that case.
14449 FIXME drow/2003-11-16: No callers check for this case any more; soon all
14450 callers will only want a very basic result and this can become a
14453 Note that stack[0] is unused except as a default error return. */
14456 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
14458 struct objfile
*objfile
= cu
->objfile
;
14460 int size
= blk
->size
;
14461 gdb_byte
*data
= blk
->data
;
14462 CORE_ADDR stack
[64];
14464 unsigned int bytes_read
, unsnd
;
14470 stack
[++stacki
] = 0;
14509 stack
[++stacki
] = op
- DW_OP_lit0
;
14544 stack
[++stacki
] = op
- DW_OP_reg0
;
14546 dwarf2_complex_location_expr_complaint ();
14550 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
14552 stack
[++stacki
] = unsnd
;
14554 dwarf2_complex_location_expr_complaint ();
14558 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
14563 case DW_OP_const1u
:
14564 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
14568 case DW_OP_const1s
:
14569 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
14573 case DW_OP_const2u
:
14574 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
14578 case DW_OP_const2s
:
14579 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
14583 case DW_OP_const4u
:
14584 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
14588 case DW_OP_const4s
:
14589 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
14594 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
14600 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
14605 stack
[stacki
+ 1] = stack
[stacki
];
14610 stack
[stacki
- 1] += stack
[stacki
];
14614 case DW_OP_plus_uconst
:
14615 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
14621 stack
[stacki
- 1] -= stack
[stacki
];
14626 /* If we're not the last op, then we definitely can't encode
14627 this using GDB's address_class enum. This is valid for partial
14628 global symbols, although the variable's address will be bogus
14631 dwarf2_complex_location_expr_complaint ();
14634 case DW_OP_GNU_push_tls_address
:
14635 /* The top of the stack has the offset from the beginning
14636 of the thread control block at which the variable is located. */
14637 /* Nothing should follow this operator, so the top of stack would
14639 /* This is valid for partial global symbols, but the variable's
14640 address will be bogus in the psymtab. */
14642 dwarf2_complex_location_expr_complaint ();
14645 case DW_OP_GNU_uninit
:
14650 const char *name
= dwarf_stack_op_name (op
);
14653 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
14656 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
14660 return (stack
[stacki
]);
14663 /* Enforce maximum stack depth of SIZE-1 to avoid writing
14664 outside of the allocated space. Also enforce minimum>0. */
14665 if (stacki
>= ARRAY_SIZE (stack
) - 1)
14667 complaint (&symfile_complaints
,
14668 _("location description stack overflow"));
14674 complaint (&symfile_complaints
,
14675 _("location description stack underflow"));
14679 return (stack
[stacki
]);
14682 /* memory allocation interface */
14684 static struct dwarf_block
*
14685 dwarf_alloc_block (struct dwarf2_cu
*cu
)
14687 struct dwarf_block
*blk
;
14689 blk
= (struct dwarf_block
*)
14690 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
14694 static struct abbrev_info
*
14695 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
14697 struct abbrev_info
*abbrev
;
14699 abbrev
= (struct abbrev_info
*)
14700 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
14701 memset (abbrev
, 0, sizeof (struct abbrev_info
));
14705 static struct die_info
*
14706 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
14708 struct die_info
*die
;
14709 size_t size
= sizeof (struct die_info
);
14712 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
14714 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
14715 memset (die
, 0, sizeof (struct die_info
));
14720 /* Macro support. */
14722 /* Return the full name of file number I in *LH's file name table.
14723 Use COMP_DIR as the name of the current directory of the
14724 compilation. The result is allocated using xmalloc; the caller is
14725 responsible for freeing it. */
14727 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
14729 /* Is the file number a valid index into the line header's file name
14730 table? Remember that file numbers start with one, not zero. */
14731 if (1 <= file
&& file
<= lh
->num_file_names
)
14733 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
14735 if (IS_ABSOLUTE_PATH (fe
->name
))
14736 return xstrdup (fe
->name
);
14744 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14750 dir_len
= strlen (dir
);
14751 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
14752 strcpy (full_name
, dir
);
14753 full_name
[dir_len
] = '/';
14754 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
14758 return xstrdup (fe
->name
);
14763 /* The compiler produced a bogus file number. We can at least
14764 record the macro definitions made in the file, even if we
14765 won't be able to find the file by name. */
14766 char fake_name
[80];
14768 sprintf (fake_name
, "<bad macro file number %d>", file
);
14770 complaint (&symfile_complaints
,
14771 _("bad file number in macro information (%d)"),
14774 return xstrdup (fake_name
);
14779 static struct macro_source_file
*
14780 macro_start_file (int file
, int line
,
14781 struct macro_source_file
*current_file
,
14782 const char *comp_dir
,
14783 struct line_header
*lh
, struct objfile
*objfile
)
14785 /* The full name of this source file. */
14786 char *full_name
= file_full_name (file
, lh
, comp_dir
);
14788 /* We don't create a macro table for this compilation unit
14789 at all until we actually get a filename. */
14790 if (! pending_macros
)
14791 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
14792 objfile
->macro_cache
);
14794 if (! current_file
)
14795 /* If we have no current file, then this must be the start_file
14796 directive for the compilation unit's main source file. */
14797 current_file
= macro_set_main (pending_macros
, full_name
);
14799 current_file
= macro_include (current_file
, line
, full_name
);
14803 return current_file
;
14807 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
14808 followed by a null byte. */
14810 copy_string (const char *buf
, int len
)
14812 char *s
= xmalloc (len
+ 1);
14814 memcpy (s
, buf
, len
);
14820 static const char *
14821 consume_improper_spaces (const char *p
, const char *body
)
14825 complaint (&symfile_complaints
,
14826 _("macro definition contains spaces "
14827 "in formal argument list:\n`%s'"),
14839 parse_macro_definition (struct macro_source_file
*file
, int line
,
14844 /* The body string takes one of two forms. For object-like macro
14845 definitions, it should be:
14847 <macro name> " " <definition>
14849 For function-like macro definitions, it should be:
14851 <macro name> "() " <definition>
14853 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
14855 Spaces may appear only where explicitly indicated, and in the
14858 The Dwarf 2 spec says that an object-like macro's name is always
14859 followed by a space, but versions of GCC around March 2002 omit
14860 the space when the macro's definition is the empty string.
14862 The Dwarf 2 spec says that there should be no spaces between the
14863 formal arguments in a function-like macro's formal argument list,
14864 but versions of GCC around March 2002 include spaces after the
14868 /* Find the extent of the macro name. The macro name is terminated
14869 by either a space or null character (for an object-like macro) or
14870 an opening paren (for a function-like macro). */
14871 for (p
= body
; *p
; p
++)
14872 if (*p
== ' ' || *p
== '(')
14875 if (*p
== ' ' || *p
== '\0')
14877 /* It's an object-like macro. */
14878 int name_len
= p
- body
;
14879 char *name
= copy_string (body
, name_len
);
14880 const char *replacement
;
14883 replacement
= body
+ name_len
+ 1;
14886 dwarf2_macro_malformed_definition_complaint (body
);
14887 replacement
= body
+ name_len
;
14890 macro_define_object (file
, line
, name
, replacement
);
14894 else if (*p
== '(')
14896 /* It's a function-like macro. */
14897 char *name
= copy_string (body
, p
- body
);
14900 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
14904 p
= consume_improper_spaces (p
, body
);
14906 /* Parse the formal argument list. */
14907 while (*p
&& *p
!= ')')
14909 /* Find the extent of the current argument name. */
14910 const char *arg_start
= p
;
14912 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
14915 if (! *p
|| p
== arg_start
)
14916 dwarf2_macro_malformed_definition_complaint (body
);
14919 /* Make sure argv has room for the new argument. */
14920 if (argc
>= argv_size
)
14923 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
14926 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
14929 p
= consume_improper_spaces (p
, body
);
14931 /* Consume the comma, if present. */
14936 p
= consume_improper_spaces (p
, body
);
14945 /* Perfectly formed definition, no complaints. */
14946 macro_define_function (file
, line
, name
,
14947 argc
, (const char **) argv
,
14949 else if (*p
== '\0')
14951 /* Complain, but do define it. */
14952 dwarf2_macro_malformed_definition_complaint (body
);
14953 macro_define_function (file
, line
, name
,
14954 argc
, (const char **) argv
,
14958 /* Just complain. */
14959 dwarf2_macro_malformed_definition_complaint (body
);
14962 /* Just complain. */
14963 dwarf2_macro_malformed_definition_complaint (body
);
14969 for (i
= 0; i
< argc
; i
++)
14975 dwarf2_macro_malformed_definition_complaint (body
);
14978 /* Skip some bytes from BYTES according to the form given in FORM.
14979 Returns the new pointer. */
14982 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
,
14983 enum dwarf_form form
,
14984 unsigned int offset_size
,
14985 struct dwarf2_section_info
*section
)
14987 unsigned int bytes_read
;
14991 case DW_FORM_data1
:
14996 case DW_FORM_data2
:
15000 case DW_FORM_data4
:
15004 case DW_FORM_data8
:
15008 case DW_FORM_string
:
15009 read_direct_string (abfd
, bytes
, &bytes_read
);
15010 bytes
+= bytes_read
;
15013 case DW_FORM_sec_offset
:
15015 bytes
+= offset_size
;
15018 case DW_FORM_block
:
15019 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
15020 bytes
+= bytes_read
;
15023 case DW_FORM_block1
:
15024 bytes
+= 1 + read_1_byte (abfd
, bytes
);
15026 case DW_FORM_block2
:
15027 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
15029 case DW_FORM_block4
:
15030 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
15033 case DW_FORM_sdata
:
15034 case DW_FORM_udata
:
15035 bytes
= skip_leb128 (abfd
, bytes
);
15041 complaint (&symfile_complaints
,
15042 _("invalid form 0x%x in `%s'"),
15044 section
->asection
->name
);
15052 /* A helper for dwarf_decode_macros that handles skipping an unknown
15053 opcode. Returns an updated pointer to the macro data buffer; or,
15054 on error, issues a complaint and returns NULL. */
15057 skip_unknown_opcode (unsigned int opcode
,
15058 gdb_byte
**opcode_definitions
,
15061 unsigned int offset_size
,
15062 struct dwarf2_section_info
*section
)
15064 unsigned int bytes_read
, i
;
15068 if (opcode_definitions
[opcode
] == NULL
)
15070 complaint (&symfile_complaints
,
15071 _("unrecognized DW_MACFINO opcode 0x%x"),
15076 defn
= opcode_definitions
[opcode
];
15077 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
15078 defn
+= bytes_read
;
15080 for (i
= 0; i
< arg
; ++i
)
15082 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, defn
[i
], offset_size
, section
);
15083 if (mac_ptr
== NULL
)
15085 /* skip_form_bytes already issued the complaint. */
15093 /* A helper function which parses the header of a macro section.
15094 If the macro section is the extended (for now called "GNU") type,
15095 then this updates *OFFSET_SIZE. Returns a pointer to just after
15096 the header, or issues a complaint and returns NULL on error. */
15099 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
15102 unsigned int *offset_size
,
15103 int section_is_gnu
)
15105 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
15107 if (section_is_gnu
)
15109 unsigned int version
, flags
;
15111 version
= read_2_bytes (abfd
, mac_ptr
);
15114 complaint (&symfile_complaints
,
15115 _("unrecognized version `%d' in .debug_macro section"),
15121 flags
= read_1_byte (abfd
, mac_ptr
);
15123 *offset_size
= (flags
& 1) ? 8 : 4;
15125 if ((flags
& 2) != 0)
15126 /* We don't need the line table offset. */
15127 mac_ptr
+= *offset_size
;
15129 /* Vendor opcode descriptions. */
15130 if ((flags
& 4) != 0)
15132 unsigned int i
, count
;
15134 count
= read_1_byte (abfd
, mac_ptr
);
15136 for (i
= 0; i
< count
; ++i
)
15138 unsigned int opcode
, bytes_read
;
15141 opcode
= read_1_byte (abfd
, mac_ptr
);
15143 opcode_definitions
[opcode
] = mac_ptr
;
15144 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15145 mac_ptr
+= bytes_read
;
15154 /* A helper for dwarf_decode_macros that handles the GNU extensions,
15155 including DW_GNU_MACINFO_transparent_include. */
15158 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
15159 struct macro_source_file
*current_file
,
15160 struct line_header
*lh
, char *comp_dir
,
15161 struct dwarf2_section_info
*section
,
15162 int section_is_gnu
,
15163 unsigned int offset_size
,
15164 struct objfile
*objfile
)
15166 enum dwarf_macro_record_type macinfo_type
;
15167 int at_commandline
;
15168 gdb_byte
*opcode_definitions
[256];
15170 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
15171 &offset_size
, section_is_gnu
);
15172 if (mac_ptr
== NULL
)
15174 /* We already issued a complaint. */
15178 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
15179 GDB is still reading the definitions from command line. First
15180 DW_MACINFO_start_file will need to be ignored as it was already executed
15181 to create CURRENT_FILE for the main source holding also the command line
15182 definitions. On first met DW_MACINFO_start_file this flag is reset to
15183 normally execute all the remaining DW_MACINFO_start_file macinfos. */
15185 at_commandline
= 1;
15189 /* Do we at least have room for a macinfo type byte? */
15190 if (mac_ptr
>= mac_end
)
15192 dwarf2_macros_too_long_complaint (section
);
15196 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
15199 /* Note that we rely on the fact that the corresponding GNU and
15200 DWARF constants are the same. */
15201 switch (macinfo_type
)
15203 /* A zero macinfo type indicates the end of the macro
15208 case DW_MACRO_GNU_define
:
15209 case DW_MACRO_GNU_undef
:
15210 case DW_MACRO_GNU_define_indirect
:
15211 case DW_MACRO_GNU_undef_indirect
:
15213 unsigned int bytes_read
;
15218 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15219 mac_ptr
+= bytes_read
;
15221 if (macinfo_type
== DW_MACRO_GNU_define
15222 || macinfo_type
== DW_MACRO_GNU_undef
)
15224 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15225 mac_ptr
+= bytes_read
;
15229 LONGEST str_offset
;
15231 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
15232 mac_ptr
+= offset_size
;
15234 body
= read_indirect_string_at_offset (abfd
, str_offset
);
15237 is_define
= (macinfo_type
== DW_MACRO_GNU_define
15238 || macinfo_type
== DW_MACRO_GNU_define_indirect
);
15239 if (! current_file
)
15241 /* DWARF violation as no main source is present. */
15242 complaint (&symfile_complaints
,
15243 _("debug info with no main source gives macro %s "
15245 is_define
? _("definition") : _("undefinition"),
15249 if ((line
== 0 && !at_commandline
)
15250 || (line
!= 0 && at_commandline
))
15251 complaint (&symfile_complaints
,
15252 _("debug info gives %s macro %s with %s line %d: %s"),
15253 at_commandline
? _("command-line") : _("in-file"),
15254 is_define
? _("definition") : _("undefinition"),
15255 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
15258 parse_macro_definition (current_file
, line
, body
);
15261 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
15262 || macinfo_type
== DW_MACRO_GNU_undef_indirect
);
15263 macro_undef (current_file
, line
, body
);
15268 case DW_MACRO_GNU_start_file
:
15270 unsigned int bytes_read
;
15273 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15274 mac_ptr
+= bytes_read
;
15275 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15276 mac_ptr
+= bytes_read
;
15278 if ((line
== 0 && !at_commandline
)
15279 || (line
!= 0 && at_commandline
))
15280 complaint (&symfile_complaints
,
15281 _("debug info gives source %d included "
15282 "from %s at %s line %d"),
15283 file
, at_commandline
? _("command-line") : _("file"),
15284 line
== 0 ? _("zero") : _("non-zero"), line
);
15286 if (at_commandline
)
15288 /* This DW_MACRO_GNU_start_file was executed in the
15290 at_commandline
= 0;
15293 current_file
= macro_start_file (file
, line
,
15294 current_file
, comp_dir
,
15299 case DW_MACRO_GNU_end_file
:
15300 if (! current_file
)
15301 complaint (&symfile_complaints
,
15302 _("macro debug info has an unmatched "
15303 "`close_file' directive"));
15306 current_file
= current_file
->included_by
;
15307 if (! current_file
)
15309 enum dwarf_macro_record_type next_type
;
15311 /* GCC circa March 2002 doesn't produce the zero
15312 type byte marking the end of the compilation
15313 unit. Complain if it's not there, but exit no
15316 /* Do we at least have room for a macinfo type byte? */
15317 if (mac_ptr
>= mac_end
)
15319 dwarf2_macros_too_long_complaint (section
);
15323 /* We don't increment mac_ptr here, so this is just
15325 next_type
= read_1_byte (abfd
, mac_ptr
);
15326 if (next_type
!= 0)
15327 complaint (&symfile_complaints
,
15328 _("no terminating 0-type entry for "
15329 "macros in `.debug_macinfo' section"));
15336 case DW_MACRO_GNU_transparent_include
:
15340 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
15341 mac_ptr
+= offset_size
;
15343 dwarf_decode_macro_bytes (abfd
,
15344 section
->buffer
+ offset
,
15345 mac_end
, current_file
,
15347 section
, section_is_gnu
,
15348 offset_size
, objfile
);
15352 case DW_MACINFO_vendor_ext
:
15353 if (!section_is_gnu
)
15355 unsigned int bytes_read
;
15358 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15359 mac_ptr
+= bytes_read
;
15360 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15361 mac_ptr
+= bytes_read
;
15363 /* We don't recognize any vendor extensions. */
15369 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
15370 mac_ptr
, abfd
, offset_size
,
15372 if (mac_ptr
== NULL
)
15376 } while (macinfo_type
!= 0);
15380 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
15381 char *comp_dir
, bfd
*abfd
,
15382 struct dwarf2_cu
*cu
,
15383 struct dwarf2_section_info
*section
,
15384 int section_is_gnu
)
15386 gdb_byte
*mac_ptr
, *mac_end
;
15387 struct macro_source_file
*current_file
= 0;
15388 enum dwarf_macro_record_type macinfo_type
;
15389 unsigned int offset_size
= cu
->header
.offset_size
;
15390 gdb_byte
*opcode_definitions
[256];
15392 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
15393 if (section
->buffer
== NULL
)
15395 complaint (&symfile_complaints
, _("missing %s section"),
15396 section
->asection
->name
);
15400 /* First pass: Find the name of the base filename.
15401 This filename is needed in order to process all macros whose definition
15402 (or undefinition) comes from the command line. These macros are defined
15403 before the first DW_MACINFO_start_file entry, and yet still need to be
15404 associated to the base file.
15406 To determine the base file name, we scan the macro definitions until we
15407 reach the first DW_MACINFO_start_file entry. We then initialize
15408 CURRENT_FILE accordingly so that any macro definition found before the
15409 first DW_MACINFO_start_file can still be associated to the base file. */
15411 mac_ptr
= section
->buffer
+ offset
;
15412 mac_end
= section
->buffer
+ section
->size
;
15414 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
15415 &offset_size
, section_is_gnu
);
15416 if (mac_ptr
== NULL
)
15418 /* We already issued a complaint. */
15424 /* Do we at least have room for a macinfo type byte? */
15425 if (mac_ptr
>= mac_end
)
15427 /* Complaint is printed during the second pass as GDB will probably
15428 stop the first pass earlier upon finding
15429 DW_MACINFO_start_file. */
15433 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
15436 /* Note that we rely on the fact that the corresponding GNU and
15437 DWARF constants are the same. */
15438 switch (macinfo_type
)
15440 /* A zero macinfo type indicates the end of the macro
15445 case DW_MACRO_GNU_define
:
15446 case DW_MACRO_GNU_undef
:
15447 /* Only skip the data by MAC_PTR. */
15449 unsigned int bytes_read
;
15451 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15452 mac_ptr
+= bytes_read
;
15453 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15454 mac_ptr
+= bytes_read
;
15458 case DW_MACRO_GNU_start_file
:
15460 unsigned int bytes_read
;
15463 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15464 mac_ptr
+= bytes_read
;
15465 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15466 mac_ptr
+= bytes_read
;
15468 current_file
= macro_start_file (file
, line
, current_file
,
15469 comp_dir
, lh
, cu
->objfile
);
15473 case DW_MACRO_GNU_end_file
:
15474 /* No data to skip by MAC_PTR. */
15477 case DW_MACRO_GNU_define_indirect
:
15478 case DW_MACRO_GNU_undef_indirect
:
15480 unsigned int bytes_read
;
15482 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15483 mac_ptr
+= bytes_read
;
15484 mac_ptr
+= offset_size
;
15488 case DW_MACRO_GNU_transparent_include
:
15489 /* Note that, according to the spec, a transparent include
15490 chain cannot call DW_MACRO_GNU_start_file. So, we can just
15491 skip this opcode. */
15492 mac_ptr
+= offset_size
;
15495 case DW_MACINFO_vendor_ext
:
15496 /* Only skip the data by MAC_PTR. */
15497 if (!section_is_gnu
)
15499 unsigned int bytes_read
;
15501 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15502 mac_ptr
+= bytes_read
;
15503 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15504 mac_ptr
+= bytes_read
;
15509 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
15510 mac_ptr
, abfd
, offset_size
,
15512 if (mac_ptr
== NULL
)
15516 } while (macinfo_type
!= 0 && current_file
== NULL
);
15518 /* Second pass: Process all entries.
15520 Use the AT_COMMAND_LINE flag to determine whether we are still processing
15521 command-line macro definitions/undefinitions. This flag is unset when we
15522 reach the first DW_MACINFO_start_file entry. */
15524 dwarf_decode_macro_bytes (abfd
, section
->buffer
+ offset
, mac_end
,
15525 current_file
, lh
, comp_dir
, section
, section_is_gnu
,
15526 offset_size
, cu
->objfile
);
15529 /* Check if the attribute's form is a DW_FORM_block*
15530 if so return true else false. */
15532 attr_form_is_block (struct attribute
*attr
)
15534 return (attr
== NULL
? 0 :
15535 attr
->form
== DW_FORM_block1
15536 || attr
->form
== DW_FORM_block2
15537 || attr
->form
== DW_FORM_block4
15538 || attr
->form
== DW_FORM_block
15539 || attr
->form
== DW_FORM_exprloc
);
15542 /* Return non-zero if ATTR's value is a section offset --- classes
15543 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
15544 You may use DW_UNSND (attr) to retrieve such offsets.
15546 Section 7.5.4, "Attribute Encodings", explains that no attribute
15547 may have a value that belongs to more than one of these classes; it
15548 would be ambiguous if we did, because we use the same forms for all
15551 attr_form_is_section_offset (struct attribute
*attr
)
15553 return (attr
->form
== DW_FORM_data4
15554 || attr
->form
== DW_FORM_data8
15555 || attr
->form
== DW_FORM_sec_offset
);
15559 /* Return non-zero if ATTR's value falls in the 'constant' class, or
15560 zero otherwise. When this function returns true, you can apply
15561 dwarf2_get_attr_constant_value to it.
15563 However, note that for some attributes you must check
15564 attr_form_is_section_offset before using this test. DW_FORM_data4
15565 and DW_FORM_data8 are members of both the constant class, and of
15566 the classes that contain offsets into other debug sections
15567 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
15568 that, if an attribute's can be either a constant or one of the
15569 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
15570 taken as section offsets, not constants. */
15572 attr_form_is_constant (struct attribute
*attr
)
15574 switch (attr
->form
)
15576 case DW_FORM_sdata
:
15577 case DW_FORM_udata
:
15578 case DW_FORM_data1
:
15579 case DW_FORM_data2
:
15580 case DW_FORM_data4
:
15581 case DW_FORM_data8
:
15588 /* A helper function that fills in a dwarf2_loclist_baton. */
15591 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
15592 struct dwarf2_loclist_baton
*baton
,
15593 struct attribute
*attr
)
15595 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
15596 &dwarf2_per_objfile
->loc
);
15598 baton
->per_cu
= cu
->per_cu
;
15599 gdb_assert (baton
->per_cu
);
15600 /* We don't know how long the location list is, but make sure we
15601 don't run off the edge of the section. */
15602 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
15603 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
15604 baton
->base_address
= cu
->base_address
;
15608 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
15609 struct dwarf2_cu
*cu
)
15611 if (attr_form_is_section_offset (attr
)
15612 /* ".debug_loc" may not exist at all, or the offset may be outside
15613 the section. If so, fall through to the complaint in the
15615 && DW_UNSND (attr
) < dwarf2_section_size (dwarf2_per_objfile
->objfile
,
15616 &dwarf2_per_objfile
->loc
))
15618 struct dwarf2_loclist_baton
*baton
;
15620 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
15621 sizeof (struct dwarf2_loclist_baton
));
15623 fill_in_loclist_baton (cu
, baton
, attr
);
15625 if (cu
->base_known
== 0)
15626 complaint (&symfile_complaints
,
15627 _("Location list used without "
15628 "specifying the CU base address."));
15630 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
15631 SYMBOL_LOCATION_BATON (sym
) = baton
;
15635 struct dwarf2_locexpr_baton
*baton
;
15637 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
15638 sizeof (struct dwarf2_locexpr_baton
));
15639 baton
->per_cu
= cu
->per_cu
;
15640 gdb_assert (baton
->per_cu
);
15642 if (attr_form_is_block (attr
))
15644 /* Note that we're just copying the block's data pointer
15645 here, not the actual data. We're still pointing into the
15646 info_buffer for SYM's objfile; right now we never release
15647 that buffer, but when we do clean up properly this may
15649 baton
->size
= DW_BLOCK (attr
)->size
;
15650 baton
->data
= DW_BLOCK (attr
)->data
;
15654 dwarf2_invalid_attrib_class_complaint ("location description",
15655 SYMBOL_NATURAL_NAME (sym
));
15659 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
15660 SYMBOL_LOCATION_BATON (sym
) = baton
;
15664 /* Return the OBJFILE associated with the compilation unit CU. If CU
15665 came from a separate debuginfo file, then the master objfile is
15669 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
15671 struct objfile
*objfile
= per_cu
->objfile
;
15673 /* Return the master objfile, so that we can report and look up the
15674 correct file containing this variable. */
15675 if (objfile
->separate_debug_objfile_backlink
)
15676 objfile
= objfile
->separate_debug_objfile_backlink
;
15681 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
15682 (CU_HEADERP is unused in such case) or prepare a temporary copy at
15683 CU_HEADERP first. */
15685 static const struct comp_unit_head
*
15686 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
15687 struct dwarf2_per_cu_data
*per_cu
)
15689 struct objfile
*objfile
;
15690 struct dwarf2_per_objfile
*per_objfile
;
15691 gdb_byte
*info_ptr
;
15694 return &per_cu
->cu
->header
;
15696 objfile
= per_cu
->objfile
;
15697 per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
15698 info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
15700 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
15701 read_comp_unit_head (cu_headerp
, info_ptr
, objfile
->obfd
);
15706 /* Return the address size given in the compilation unit header for CU. */
15709 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
15711 struct comp_unit_head cu_header_local
;
15712 const struct comp_unit_head
*cu_headerp
;
15714 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
15716 return cu_headerp
->addr_size
;
15719 /* Return the offset size given in the compilation unit header for CU. */
15722 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
15724 struct comp_unit_head cu_header_local
;
15725 const struct comp_unit_head
*cu_headerp
;
15727 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
15729 return cu_headerp
->offset_size
;
15732 /* See its dwarf2loc.h declaration. */
15735 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
15737 struct comp_unit_head cu_header_local
;
15738 const struct comp_unit_head
*cu_headerp
;
15740 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
15742 if (cu_headerp
->version
== 2)
15743 return cu_headerp
->addr_size
;
15745 return cu_headerp
->offset_size
;
15748 /* Return the text offset of the CU. The returned offset comes from
15749 this CU's objfile. If this objfile came from a separate debuginfo
15750 file, then the offset may be different from the corresponding
15751 offset in the parent objfile. */
15754 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
15756 struct objfile
*objfile
= per_cu
->objfile
;
15758 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15761 /* Locate the .debug_info compilation unit from CU's objfile which contains
15762 the DIE at OFFSET. Raises an error on failure. */
15764 static struct dwarf2_per_cu_data
*
15765 dwarf2_find_containing_comp_unit (unsigned int offset
,
15766 struct objfile
*objfile
)
15768 struct dwarf2_per_cu_data
*this_cu
;
15772 high
= dwarf2_per_objfile
->n_comp_units
- 1;
15775 int mid
= low
+ (high
- low
) / 2;
15777 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
15782 gdb_assert (low
== high
);
15783 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
15786 error (_("Dwarf Error: could not find partial DIE containing "
15787 "offset 0x%lx [in module %s]"),
15788 (long) offset
, bfd_get_filename (objfile
->obfd
));
15790 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
15791 return dwarf2_per_objfile
->all_comp_units
[low
-1];
15795 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
15796 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
15797 && offset
>= this_cu
->offset
+ this_cu
->length
)
15798 error (_("invalid dwarf2 offset %u"), offset
);
15799 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
15804 /* Locate the compilation unit from OBJFILE which is located at exactly
15805 OFFSET. Raises an error on failure. */
15807 static struct dwarf2_per_cu_data
*
15808 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
15810 struct dwarf2_per_cu_data
*this_cu
;
15812 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
15813 if (this_cu
->offset
!= offset
)
15814 error (_("no compilation unit with offset %u."), offset
);
15818 /* Initialize dwarf2_cu CU for OBJFILE in a pre-allocated space. */
15821 init_one_comp_unit (struct dwarf2_cu
*cu
, struct objfile
*objfile
)
15823 memset (cu
, 0, sizeof (*cu
));
15824 cu
->objfile
= objfile
;
15825 obstack_init (&cu
->comp_unit_obstack
);
15828 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
15831 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
)
15833 struct attribute
*attr
;
15835 /* Set the language we're debugging. */
15836 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
15838 set_cu_language (DW_UNSND (attr
), cu
);
15841 cu
->language
= language_minimal
;
15842 cu
->language_defn
= language_def (cu
->language
);
15846 /* Release one cached compilation unit, CU. We unlink it from the tree
15847 of compilation units, but we don't remove it from the read_in_chain;
15848 the caller is responsible for that.
15849 NOTE: DATA is a void * because this function is also used as a
15850 cleanup routine. */
15853 free_one_comp_unit (void *data
)
15855 struct dwarf2_cu
*cu
= data
;
15857 if (cu
->per_cu
!= NULL
)
15858 cu
->per_cu
->cu
= NULL
;
15861 obstack_free (&cu
->comp_unit_obstack
, NULL
);
15866 /* This cleanup function is passed the address of a dwarf2_cu on the stack
15867 when we're finished with it. We can't free the pointer itself, but be
15868 sure to unlink it from the cache. Also release any associated storage
15869 and perform cache maintenance.
15871 Only used during partial symbol parsing. */
15874 free_stack_comp_unit (void *data
)
15876 struct dwarf2_cu
*cu
= data
;
15878 obstack_free (&cu
->comp_unit_obstack
, NULL
);
15879 cu
->partial_dies
= NULL
;
15881 if (cu
->per_cu
!= NULL
)
15883 /* This compilation unit is on the stack in our caller, so we
15884 should not xfree it. Just unlink it. */
15885 cu
->per_cu
->cu
= NULL
;
15888 /* If we had a per-cu pointer, then we may have other compilation
15889 units loaded, so age them now. */
15890 age_cached_comp_units ();
15894 /* Free all cached compilation units. */
15897 free_cached_comp_units (void *data
)
15899 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15901 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15902 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15903 while (per_cu
!= NULL
)
15905 struct dwarf2_per_cu_data
*next_cu
;
15907 next_cu
= per_cu
->cu
->read_in_chain
;
15909 free_one_comp_unit (per_cu
->cu
);
15910 *last_chain
= next_cu
;
15916 /* Increase the age counter on each cached compilation unit, and free
15917 any that are too old. */
15920 age_cached_comp_units (void)
15922 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15924 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
15925 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15926 while (per_cu
!= NULL
)
15928 per_cu
->cu
->last_used
++;
15929 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
15930 dwarf2_mark (per_cu
->cu
);
15931 per_cu
= per_cu
->cu
->read_in_chain
;
15934 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15935 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15936 while (per_cu
!= NULL
)
15938 struct dwarf2_per_cu_data
*next_cu
;
15940 next_cu
= per_cu
->cu
->read_in_chain
;
15942 if (!per_cu
->cu
->mark
)
15944 free_one_comp_unit (per_cu
->cu
);
15945 *last_chain
= next_cu
;
15948 last_chain
= &per_cu
->cu
->read_in_chain
;
15954 /* Remove a single compilation unit from the cache. */
15957 free_one_cached_comp_unit (void *target_cu
)
15959 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15961 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15962 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15963 while (per_cu
!= NULL
)
15965 struct dwarf2_per_cu_data
*next_cu
;
15967 next_cu
= per_cu
->cu
->read_in_chain
;
15969 if (per_cu
->cu
== target_cu
)
15971 free_one_comp_unit (per_cu
->cu
);
15972 *last_chain
= next_cu
;
15976 last_chain
= &per_cu
->cu
->read_in_chain
;
15982 /* Release all extra memory associated with OBJFILE. */
15985 dwarf2_free_objfile (struct objfile
*objfile
)
15987 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
15989 if (dwarf2_per_objfile
== NULL
)
15992 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
15993 free_cached_comp_units (NULL
);
15995 if (dwarf2_per_objfile
->quick_file_names_table
)
15996 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
15998 /* Everything else should be on the objfile obstack. */
16001 /* A pair of DIE offset and GDB type pointer. We store these
16002 in a hash table separate from the DIEs, and preserve them
16003 when the DIEs are flushed out of cache. */
16005 struct dwarf2_offset_and_type
16007 unsigned int offset
;
16011 /* Hash function for a dwarf2_offset_and_type. */
16014 offset_and_type_hash (const void *item
)
16016 const struct dwarf2_offset_and_type
*ofs
= item
;
16018 return ofs
->offset
;
16021 /* Equality function for a dwarf2_offset_and_type. */
16024 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
16026 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
16027 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
16029 return ofs_lhs
->offset
== ofs_rhs
->offset
;
16032 /* Set the type associated with DIE to TYPE. Save it in CU's hash
16033 table if necessary. For convenience, return TYPE.
16035 The DIEs reading must have careful ordering to:
16036 * Not cause infite loops trying to read in DIEs as a prerequisite for
16037 reading current DIE.
16038 * Not trying to dereference contents of still incompletely read in types
16039 while reading in other DIEs.
16040 * Enable referencing still incompletely read in types just by a pointer to
16041 the type without accessing its fields.
16043 Therefore caller should follow these rules:
16044 * Try to fetch any prerequisite types we may need to build this DIE type
16045 before building the type and calling set_die_type.
16046 * After building type call set_die_type for current DIE as soon as
16047 possible before fetching more types to complete the current type.
16048 * Make the type as complete as possible before fetching more types. */
16050 static struct type
*
16051 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
16053 struct dwarf2_offset_and_type
**slot
, ofs
;
16054 struct objfile
*objfile
= cu
->objfile
;
16055 htab_t
*type_hash_ptr
;
16057 /* For Ada types, make sure that the gnat-specific data is always
16058 initialized (if not already set). There are a few types where
16059 we should not be doing so, because the type-specific area is
16060 already used to hold some other piece of info (eg: TYPE_CODE_FLT
16061 where the type-specific area is used to store the floatformat).
16062 But this is not a problem, because the gnat-specific information
16063 is actually not needed for these types. */
16064 if (need_gnat_info (cu
)
16065 && TYPE_CODE (type
) != TYPE_CODE_FUNC
16066 && TYPE_CODE (type
) != TYPE_CODE_FLT
16067 && !HAVE_GNAT_AUX_INFO (type
))
16068 INIT_GNAT_SPECIFIC (type
);
16070 if (cu
->per_cu
->debug_type_section
)
16071 type_hash_ptr
= &dwarf2_per_objfile
->debug_types_type_hash
;
16073 type_hash_ptr
= &dwarf2_per_objfile
->debug_info_type_hash
;
16075 if (*type_hash_ptr
== NULL
)
16078 = htab_create_alloc_ex (127,
16079 offset_and_type_hash
,
16080 offset_and_type_eq
,
16082 &objfile
->objfile_obstack
,
16083 hashtab_obstack_allocate
,
16084 dummy_obstack_deallocate
);
16087 ofs
.offset
= die
->offset
;
16089 slot
= (struct dwarf2_offset_and_type
**)
16090 htab_find_slot_with_hash (*type_hash_ptr
, &ofs
, ofs
.offset
, INSERT
);
16092 complaint (&symfile_complaints
,
16093 _("A problem internal to GDB: DIE 0x%x has type already set"),
16095 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
16100 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
16101 table, or return NULL if the die does not have a saved type. */
16103 static struct type
*
16104 get_die_type_at_offset (unsigned int offset
,
16105 struct dwarf2_per_cu_data
*per_cu
)
16107 struct dwarf2_offset_and_type
*slot
, ofs
;
16110 if (per_cu
->debug_type_section
)
16111 type_hash
= dwarf2_per_objfile
->debug_types_type_hash
;
16113 type_hash
= dwarf2_per_objfile
->debug_info_type_hash
;
16114 if (type_hash
== NULL
)
16117 ofs
.offset
= offset
;
16118 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
16125 /* Look up the type for DIE in the appropriate type_hash table,
16126 or return NULL if DIE does not have a saved type. */
16128 static struct type
*
16129 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16131 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
16134 /* Add a dependence relationship from CU to REF_PER_CU. */
16137 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
16138 struct dwarf2_per_cu_data
*ref_per_cu
)
16142 if (cu
->dependencies
== NULL
)
16144 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
16145 NULL
, &cu
->comp_unit_obstack
,
16146 hashtab_obstack_allocate
,
16147 dummy_obstack_deallocate
);
16149 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
16151 *slot
= ref_per_cu
;
16154 /* Subroutine of dwarf2_mark to pass to htab_traverse.
16155 Set the mark field in every compilation unit in the
16156 cache that we must keep because we are keeping CU. */
16159 dwarf2_mark_helper (void **slot
, void *data
)
16161 struct dwarf2_per_cu_data
*per_cu
;
16163 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
16165 /* cu->dependencies references may not yet have been ever read if QUIT aborts
16166 reading of the chain. As such dependencies remain valid it is not much
16167 useful to track and undo them during QUIT cleanups. */
16168 if (per_cu
->cu
== NULL
)
16171 if (per_cu
->cu
->mark
)
16173 per_cu
->cu
->mark
= 1;
16175 if (per_cu
->cu
->dependencies
!= NULL
)
16176 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
16181 /* Set the mark field in CU and in every other compilation unit in the
16182 cache that we must keep because we are keeping CU. */
16185 dwarf2_mark (struct dwarf2_cu
*cu
)
16190 if (cu
->dependencies
!= NULL
)
16191 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
16195 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
16199 per_cu
->cu
->mark
= 0;
16200 per_cu
= per_cu
->cu
->read_in_chain
;
16204 /* Trivial hash function for partial_die_info: the hash value of a DIE
16205 is its offset in .debug_info for this objfile. */
16208 partial_die_hash (const void *item
)
16210 const struct partial_die_info
*part_die
= item
;
16212 return part_die
->offset
;
16215 /* Trivial comparison function for partial_die_info structures: two DIEs
16216 are equal if they have the same offset. */
16219 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
16221 const struct partial_die_info
*part_die_lhs
= item_lhs
;
16222 const struct partial_die_info
*part_die_rhs
= item_rhs
;
16224 return part_die_lhs
->offset
== part_die_rhs
->offset
;
16227 static struct cmd_list_element
*set_dwarf2_cmdlist
;
16228 static struct cmd_list_element
*show_dwarf2_cmdlist
;
16231 set_dwarf2_cmd (char *args
, int from_tty
)
16233 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
16237 show_dwarf2_cmd (char *args
, int from_tty
)
16239 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
16242 /* If section described by INFO was mmapped, munmap it now. */
16245 munmap_section_buffer (struct dwarf2_section_info
*info
)
16247 if (info
->map_addr
!= NULL
)
16252 res
= munmap (info
->map_addr
, info
->map_len
);
16253 gdb_assert (res
== 0);
16255 /* Without HAVE_MMAP, we should never be here to begin with. */
16256 gdb_assert_not_reached ("no mmap support");
16261 /* munmap debug sections for OBJFILE, if necessary. */
16264 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
16266 struct dwarf2_per_objfile
*data
= d
;
16268 struct dwarf2_section_info
*section
;
16270 /* This is sorted according to the order they're defined in to make it easier
16271 to keep in sync. */
16272 munmap_section_buffer (&data
->info
);
16273 munmap_section_buffer (&data
->abbrev
);
16274 munmap_section_buffer (&data
->line
);
16275 munmap_section_buffer (&data
->loc
);
16276 munmap_section_buffer (&data
->macinfo
);
16277 munmap_section_buffer (&data
->macro
);
16278 munmap_section_buffer (&data
->str
);
16279 munmap_section_buffer (&data
->ranges
);
16280 munmap_section_buffer (&data
->frame
);
16281 munmap_section_buffer (&data
->eh_frame
);
16282 munmap_section_buffer (&data
->gdb_index
);
16285 VEC_iterate (dwarf2_section_info_def
, data
->types
, ix
, section
);
16287 munmap_section_buffer (section
);
16289 VEC_free (dwarf2_section_info_def
, data
->types
);
16293 /* The "save gdb-index" command. */
16295 /* The contents of the hash table we create when building the string
16297 struct strtab_entry
16299 offset_type offset
;
16303 /* Hash function for a strtab_entry.
16305 Function is used only during write_hash_table so no index format backward
16306 compatibility is needed. */
16309 hash_strtab_entry (const void *e
)
16311 const struct strtab_entry
*entry
= e
;
16312 return mapped_index_string_hash (INT_MAX
, entry
->str
);
16315 /* Equality function for a strtab_entry. */
16318 eq_strtab_entry (const void *a
, const void *b
)
16320 const struct strtab_entry
*ea
= a
;
16321 const struct strtab_entry
*eb
= b
;
16322 return !strcmp (ea
->str
, eb
->str
);
16325 /* Create a strtab_entry hash table. */
16328 create_strtab (void)
16330 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
16331 xfree
, xcalloc
, xfree
);
16334 /* Add a string to the constant pool. Return the string's offset in
16338 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
16341 struct strtab_entry entry
;
16342 struct strtab_entry
*result
;
16345 slot
= htab_find_slot (table
, &entry
, INSERT
);
16350 result
= XNEW (struct strtab_entry
);
16351 result
->offset
= obstack_object_size (cpool
);
16353 obstack_grow_str0 (cpool
, str
);
16356 return result
->offset
;
16359 /* An entry in the symbol table. */
16360 struct symtab_index_entry
16362 /* The name of the symbol. */
16364 /* The offset of the name in the constant pool. */
16365 offset_type index_offset
;
16366 /* A sorted vector of the indices of all the CUs that hold an object
16368 VEC (offset_type
) *cu_indices
;
16371 /* The symbol table. This is a power-of-2-sized hash table. */
16372 struct mapped_symtab
16374 offset_type n_elements
;
16376 struct symtab_index_entry
**data
;
16379 /* Hash function for a symtab_index_entry. */
16382 hash_symtab_entry (const void *e
)
16384 const struct symtab_index_entry
*entry
= e
;
16385 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
16386 sizeof (offset_type
) * VEC_length (offset_type
,
16387 entry
->cu_indices
),
16391 /* Equality function for a symtab_index_entry. */
16394 eq_symtab_entry (const void *a
, const void *b
)
16396 const struct symtab_index_entry
*ea
= a
;
16397 const struct symtab_index_entry
*eb
= b
;
16398 int len
= VEC_length (offset_type
, ea
->cu_indices
);
16399 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
16401 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
16402 VEC_address (offset_type
, eb
->cu_indices
),
16403 sizeof (offset_type
) * len
);
16406 /* Destroy a symtab_index_entry. */
16409 delete_symtab_entry (void *p
)
16411 struct symtab_index_entry
*entry
= p
;
16412 VEC_free (offset_type
, entry
->cu_indices
);
16416 /* Create a hash table holding symtab_index_entry objects. */
16419 create_symbol_hash_table (void)
16421 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
16422 delete_symtab_entry
, xcalloc
, xfree
);
16425 /* Create a new mapped symtab object. */
16427 static struct mapped_symtab
*
16428 create_mapped_symtab (void)
16430 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
16431 symtab
->n_elements
= 0;
16432 symtab
->size
= 1024;
16433 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
16437 /* Destroy a mapped_symtab. */
16440 cleanup_mapped_symtab (void *p
)
16442 struct mapped_symtab
*symtab
= p
;
16443 /* The contents of the array are freed when the other hash table is
16445 xfree (symtab
->data
);
16449 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
16452 Function is used only during write_hash_table so no index format backward
16453 compatibility is needed. */
16455 static struct symtab_index_entry
**
16456 find_slot (struct mapped_symtab
*symtab
, const char *name
)
16458 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
16460 index
= hash
& (symtab
->size
- 1);
16461 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
16465 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
16466 return &symtab
->data
[index
];
16467 index
= (index
+ step
) & (symtab
->size
- 1);
16471 /* Expand SYMTAB's hash table. */
16474 hash_expand (struct mapped_symtab
*symtab
)
16476 offset_type old_size
= symtab
->size
;
16478 struct symtab_index_entry
**old_entries
= symtab
->data
;
16481 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
16483 for (i
= 0; i
< old_size
; ++i
)
16485 if (old_entries
[i
])
16487 struct symtab_index_entry
**slot
= find_slot (symtab
,
16488 old_entries
[i
]->name
);
16489 *slot
= old_entries
[i
];
16493 xfree (old_entries
);
16496 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
16497 is the index of the CU in which the symbol appears. */
16500 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
16501 offset_type cu_index
)
16503 struct symtab_index_entry
**slot
;
16505 ++symtab
->n_elements
;
16506 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
16507 hash_expand (symtab
);
16509 slot
= find_slot (symtab
, name
);
16512 *slot
= XNEW (struct symtab_index_entry
);
16513 (*slot
)->name
= name
;
16514 (*slot
)->cu_indices
= NULL
;
16516 /* Don't push an index twice. Due to how we add entries we only
16517 have to check the last one. */
16518 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
16519 || VEC_last (offset_type
, (*slot
)->cu_indices
) != cu_index
)
16520 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
16523 /* Add a vector of indices to the constant pool. */
16526 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
16527 struct symtab_index_entry
*entry
)
16531 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
16534 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
16535 offset_type val
= MAYBE_SWAP (len
);
16540 entry
->index_offset
= obstack_object_size (cpool
);
16542 obstack_grow (cpool
, &val
, sizeof (val
));
16544 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
16547 val
= MAYBE_SWAP (iter
);
16548 obstack_grow (cpool
, &val
, sizeof (val
));
16553 struct symtab_index_entry
*old_entry
= *slot
;
16554 entry
->index_offset
= old_entry
->index_offset
;
16557 return entry
->index_offset
;
16560 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
16561 constant pool entries going into the obstack CPOOL. */
16564 write_hash_table (struct mapped_symtab
*symtab
,
16565 struct obstack
*output
, struct obstack
*cpool
)
16568 htab_t symbol_hash_table
;
16571 symbol_hash_table
= create_symbol_hash_table ();
16572 str_table
= create_strtab ();
16574 /* We add all the index vectors to the constant pool first, to
16575 ensure alignment is ok. */
16576 for (i
= 0; i
< symtab
->size
; ++i
)
16578 if (symtab
->data
[i
])
16579 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
16582 /* Now write out the hash table. */
16583 for (i
= 0; i
< symtab
->size
; ++i
)
16585 offset_type str_off
, vec_off
;
16587 if (symtab
->data
[i
])
16589 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
16590 vec_off
= symtab
->data
[i
]->index_offset
;
16594 /* While 0 is a valid constant pool index, it is not valid
16595 to have 0 for both offsets. */
16600 str_off
= MAYBE_SWAP (str_off
);
16601 vec_off
= MAYBE_SWAP (vec_off
);
16603 obstack_grow (output
, &str_off
, sizeof (str_off
));
16604 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
16607 htab_delete (str_table
);
16608 htab_delete (symbol_hash_table
);
16611 /* Struct to map psymtab to CU index in the index file. */
16612 struct psymtab_cu_index_map
16614 struct partial_symtab
*psymtab
;
16615 unsigned int cu_index
;
16619 hash_psymtab_cu_index (const void *item
)
16621 const struct psymtab_cu_index_map
*map
= item
;
16623 return htab_hash_pointer (map
->psymtab
);
16627 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
16629 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
16630 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
16632 return lhs
->psymtab
== rhs
->psymtab
;
16635 /* Helper struct for building the address table. */
16636 struct addrmap_index_data
16638 struct objfile
*objfile
;
16639 struct obstack
*addr_obstack
;
16640 htab_t cu_index_htab
;
16642 /* Non-zero if the previous_* fields are valid.
16643 We can't write an entry until we see the next entry (since it is only then
16644 that we know the end of the entry). */
16645 int previous_valid
;
16646 /* Index of the CU in the table of all CUs in the index file. */
16647 unsigned int previous_cu_index
;
16648 /* Start address of the CU. */
16649 CORE_ADDR previous_cu_start
;
16652 /* Write an address entry to OBSTACK. */
16655 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
16656 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
16658 offset_type cu_index_to_write
;
16660 CORE_ADDR baseaddr
;
16662 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
16664 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
16665 obstack_grow (obstack
, addr
, 8);
16666 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
16667 obstack_grow (obstack
, addr
, 8);
16668 cu_index_to_write
= MAYBE_SWAP (cu_index
);
16669 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
16672 /* Worker function for traversing an addrmap to build the address table. */
16675 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
16677 struct addrmap_index_data
*data
= datap
;
16678 struct partial_symtab
*pst
= obj
;
16679 offset_type cu_index
;
16682 if (data
->previous_valid
)
16683 add_address_entry (data
->objfile
, data
->addr_obstack
,
16684 data
->previous_cu_start
, start_addr
,
16685 data
->previous_cu_index
);
16687 data
->previous_cu_start
= start_addr
;
16690 struct psymtab_cu_index_map find_map
, *map
;
16691 find_map
.psymtab
= pst
;
16692 map
= htab_find (data
->cu_index_htab
, &find_map
);
16693 gdb_assert (map
!= NULL
);
16694 data
->previous_cu_index
= map
->cu_index
;
16695 data
->previous_valid
= 1;
16698 data
->previous_valid
= 0;
16703 /* Write OBJFILE's address map to OBSTACK.
16704 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
16705 in the index file. */
16708 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
16709 htab_t cu_index_htab
)
16711 struct addrmap_index_data addrmap_index_data
;
16713 /* When writing the address table, we have to cope with the fact that
16714 the addrmap iterator only provides the start of a region; we have to
16715 wait until the next invocation to get the start of the next region. */
16717 addrmap_index_data
.objfile
= objfile
;
16718 addrmap_index_data
.addr_obstack
= obstack
;
16719 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
16720 addrmap_index_data
.previous_valid
= 0;
16722 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
16723 &addrmap_index_data
);
16725 /* It's highly unlikely the last entry (end address = 0xff...ff)
16726 is valid, but we should still handle it.
16727 The end address is recorded as the start of the next region, but that
16728 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
16730 if (addrmap_index_data
.previous_valid
)
16731 add_address_entry (objfile
, obstack
,
16732 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
16733 addrmap_index_data
.previous_cu_index
);
16736 /* Add a list of partial symbols to SYMTAB. */
16739 write_psymbols (struct mapped_symtab
*symtab
,
16741 struct partial_symbol
**psymp
,
16743 offset_type cu_index
,
16746 for (; count
-- > 0; ++psymp
)
16748 void **slot
, *lookup
;
16750 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
16751 error (_("Ada is not currently supported by the index"));
16753 /* We only want to add a given psymbol once. However, we also
16754 want to account for whether it is global or static. So, we
16755 may add it twice, using slightly different values. */
16758 uintptr_t val
= 1 | (uintptr_t) *psymp
;
16760 lookup
= (void *) val
;
16765 /* Only add a given psymbol once. */
16766 slot
= htab_find_slot (psyms_seen
, lookup
, INSERT
);
16770 add_index_entry (symtab
, SYMBOL_NATURAL_NAME (*psymp
), cu_index
);
16775 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
16776 exception if there is an error. */
16779 write_obstack (FILE *file
, struct obstack
*obstack
)
16781 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
16783 != obstack_object_size (obstack
))
16784 error (_("couldn't data write to file"));
16787 /* Unlink a file if the argument is not NULL. */
16790 unlink_if_set (void *p
)
16792 char **filename
= p
;
16794 unlink (*filename
);
16797 /* A helper struct used when iterating over debug_types. */
16798 struct signatured_type_index_data
16800 struct objfile
*objfile
;
16801 struct mapped_symtab
*symtab
;
16802 struct obstack
*types_list
;
16807 /* A helper function that writes a single signatured_type to an
16811 write_one_signatured_type (void **slot
, void *d
)
16813 struct signatured_type_index_data
*info
= d
;
16814 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
16815 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
16816 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
16819 write_psymbols (info
->symtab
,
16821 info
->objfile
->global_psymbols
.list
16822 + psymtab
->globals_offset
,
16823 psymtab
->n_global_syms
, info
->cu_index
,
16825 write_psymbols (info
->symtab
,
16827 info
->objfile
->static_psymbols
.list
16828 + psymtab
->statics_offset
,
16829 psymtab
->n_static_syms
, info
->cu_index
,
16832 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->per_cu
.offset
);
16833 obstack_grow (info
->types_list
, val
, 8);
16834 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->type_offset
);
16835 obstack_grow (info
->types_list
, val
, 8);
16836 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
16837 obstack_grow (info
->types_list
, val
, 8);
16844 /* Create an index file for OBJFILE in the directory DIR. */
16847 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
16849 struct cleanup
*cleanup
;
16850 char *filename
, *cleanup_filename
;
16851 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
16852 struct obstack cu_list
, types_cu_list
;
16855 struct mapped_symtab
*symtab
;
16856 offset_type val
, size_of_contents
, total_len
;
16860 htab_t cu_index_htab
;
16861 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
16863 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
16866 if (dwarf2_per_objfile
->using_index
)
16867 error (_("Cannot use an index to create the index"));
16869 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
16870 error (_("Cannot make an index when the file has multiple .debug_types sections"));
16872 if (stat (objfile
->name
, &st
) < 0)
16873 perror_with_name (objfile
->name
);
16875 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
16876 INDEX_SUFFIX
, (char *) NULL
);
16877 cleanup
= make_cleanup (xfree
, filename
);
16879 out_file
= fopen (filename
, "wb");
16881 error (_("Can't open `%s' for writing"), filename
);
16883 cleanup_filename
= filename
;
16884 make_cleanup (unlink_if_set
, &cleanup_filename
);
16886 symtab
= create_mapped_symtab ();
16887 make_cleanup (cleanup_mapped_symtab
, symtab
);
16889 obstack_init (&addr_obstack
);
16890 make_cleanup_obstack_free (&addr_obstack
);
16892 obstack_init (&cu_list
);
16893 make_cleanup_obstack_free (&cu_list
);
16895 obstack_init (&types_cu_list
);
16896 make_cleanup_obstack_free (&types_cu_list
);
16898 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
16899 NULL
, xcalloc
, xfree
);
16900 make_cleanup_htab_delete (psyms_seen
);
16902 /* While we're scanning CU's create a table that maps a psymtab pointer
16903 (which is what addrmap records) to its index (which is what is recorded
16904 in the index file). This will later be needed to write the address
16906 cu_index_htab
= htab_create_alloc (100,
16907 hash_psymtab_cu_index
,
16908 eq_psymtab_cu_index
,
16909 NULL
, xcalloc
, xfree
);
16910 make_cleanup_htab_delete (cu_index_htab
);
16911 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
16912 xmalloc (sizeof (struct psymtab_cu_index_map
)
16913 * dwarf2_per_objfile
->n_comp_units
);
16914 make_cleanup (xfree
, psymtab_cu_index_map
);
16916 /* The CU list is already sorted, so we don't need to do additional
16917 work here. Also, the debug_types entries do not appear in
16918 all_comp_units, but only in their own hash table. */
16919 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
16921 struct dwarf2_per_cu_data
*per_cu
16922 = dwarf2_per_objfile
->all_comp_units
[i
];
16923 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
16925 struct psymtab_cu_index_map
*map
;
16928 write_psymbols (symtab
,
16930 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
16931 psymtab
->n_global_syms
, i
,
16933 write_psymbols (symtab
,
16935 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
16936 psymtab
->n_static_syms
, i
,
16939 map
= &psymtab_cu_index_map
[i
];
16940 map
->psymtab
= psymtab
;
16942 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
16943 gdb_assert (slot
!= NULL
);
16944 gdb_assert (*slot
== NULL
);
16947 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->offset
);
16948 obstack_grow (&cu_list
, val
, 8);
16949 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
16950 obstack_grow (&cu_list
, val
, 8);
16953 /* Dump the address map. */
16954 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
16956 /* Write out the .debug_type entries, if any. */
16957 if (dwarf2_per_objfile
->signatured_types
)
16959 struct signatured_type_index_data sig_data
;
16961 sig_data
.objfile
= objfile
;
16962 sig_data
.symtab
= symtab
;
16963 sig_data
.types_list
= &types_cu_list
;
16964 sig_data
.psyms_seen
= psyms_seen
;
16965 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
16966 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
16967 write_one_signatured_type
, &sig_data
);
16970 obstack_init (&constant_pool
);
16971 make_cleanup_obstack_free (&constant_pool
);
16972 obstack_init (&symtab_obstack
);
16973 make_cleanup_obstack_free (&symtab_obstack
);
16974 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
16976 obstack_init (&contents
);
16977 make_cleanup_obstack_free (&contents
);
16978 size_of_contents
= 6 * sizeof (offset_type
);
16979 total_len
= size_of_contents
;
16981 /* The version number. */
16982 val
= MAYBE_SWAP (5);
16983 obstack_grow (&contents
, &val
, sizeof (val
));
16985 /* The offset of the CU list from the start of the file. */
16986 val
= MAYBE_SWAP (total_len
);
16987 obstack_grow (&contents
, &val
, sizeof (val
));
16988 total_len
+= obstack_object_size (&cu_list
);
16990 /* The offset of the types CU list from the start of the file. */
16991 val
= MAYBE_SWAP (total_len
);
16992 obstack_grow (&contents
, &val
, sizeof (val
));
16993 total_len
+= obstack_object_size (&types_cu_list
);
16995 /* The offset of the address table from the start of the file. */
16996 val
= MAYBE_SWAP (total_len
);
16997 obstack_grow (&contents
, &val
, sizeof (val
));
16998 total_len
+= obstack_object_size (&addr_obstack
);
17000 /* The offset of the symbol table from the start of the file. */
17001 val
= MAYBE_SWAP (total_len
);
17002 obstack_grow (&contents
, &val
, sizeof (val
));
17003 total_len
+= obstack_object_size (&symtab_obstack
);
17005 /* The offset of the constant pool from the start of the file. */
17006 val
= MAYBE_SWAP (total_len
);
17007 obstack_grow (&contents
, &val
, sizeof (val
));
17008 total_len
+= obstack_object_size (&constant_pool
);
17010 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
17012 write_obstack (out_file
, &contents
);
17013 write_obstack (out_file
, &cu_list
);
17014 write_obstack (out_file
, &types_cu_list
);
17015 write_obstack (out_file
, &addr_obstack
);
17016 write_obstack (out_file
, &symtab_obstack
);
17017 write_obstack (out_file
, &constant_pool
);
17021 /* We want to keep the file, so we set cleanup_filename to NULL
17022 here. See unlink_if_set. */
17023 cleanup_filename
= NULL
;
17025 do_cleanups (cleanup
);
17028 /* Implementation of the `save gdb-index' command.
17030 Note that the file format used by this command is documented in the
17031 GDB manual. Any changes here must be documented there. */
17034 save_gdb_index_command (char *arg
, int from_tty
)
17036 struct objfile
*objfile
;
17039 error (_("usage: save gdb-index DIRECTORY"));
17041 ALL_OBJFILES (objfile
)
17045 /* If the objfile does not correspond to an actual file, skip it. */
17046 if (stat (objfile
->name
, &st
) < 0)
17049 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
17050 if (dwarf2_per_objfile
)
17052 volatile struct gdb_exception except
;
17054 TRY_CATCH (except
, RETURN_MASK_ERROR
)
17056 write_psymtabs_to_index (objfile
, arg
);
17058 if (except
.reason
< 0)
17059 exception_fprintf (gdb_stderr
, except
,
17060 _("Error while writing index for `%s': "),
17068 int dwarf2_always_disassemble
;
17071 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
17072 struct cmd_list_element
*c
, const char *value
)
17074 fprintf_filtered (file
,
17075 _("Whether to always disassemble "
17076 "DWARF expressions is %s.\n"),
17081 show_check_physname (struct ui_file
*file
, int from_tty
,
17082 struct cmd_list_element
*c
, const char *value
)
17084 fprintf_filtered (file
,
17085 _("Whether to check \"physname\" is %s.\n"),
17089 void _initialize_dwarf2_read (void);
17092 _initialize_dwarf2_read (void)
17094 struct cmd_list_element
*c
;
17096 dwarf2_objfile_data_key
17097 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
17099 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
17100 Set DWARF 2 specific variables.\n\
17101 Configure DWARF 2 variables such as the cache size"),
17102 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
17103 0/*allow-unknown*/, &maintenance_set_cmdlist
);
17105 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
17106 Show DWARF 2 specific variables\n\
17107 Show DWARF 2 variables such as the cache size"),
17108 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
17109 0/*allow-unknown*/, &maintenance_show_cmdlist
);
17111 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
17112 &dwarf2_max_cache_age
, _("\
17113 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
17114 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
17115 A higher limit means that cached compilation units will be stored\n\
17116 in memory longer, and more total memory will be used. Zero disables\n\
17117 caching, which can slow down startup."),
17119 show_dwarf2_max_cache_age
,
17120 &set_dwarf2_cmdlist
,
17121 &show_dwarf2_cmdlist
);
17123 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
17124 &dwarf2_always_disassemble
, _("\
17125 Set whether `info address' always disassembles DWARF expressions."), _("\
17126 Show whether `info address' always disassembles DWARF expressions."), _("\
17127 When enabled, DWARF expressions are always printed in an assembly-like\n\
17128 syntax. When disabled, expressions will be printed in a more\n\
17129 conversational style, when possible."),
17131 show_dwarf2_always_disassemble
,
17132 &set_dwarf2_cmdlist
,
17133 &show_dwarf2_cmdlist
);
17135 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
17136 Set debugging of the dwarf2 DIE reader."), _("\
17137 Show debugging of the dwarf2 DIE reader."), _("\
17138 When enabled (non-zero), DIEs are dumped after they are read in.\n\
17139 The value is the maximum depth to print."),
17142 &setdebuglist
, &showdebuglist
);
17144 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
17145 Set cross-checking of \"physname\" code against demangler."), _("\
17146 Show cross-checking of \"physname\" code against demangler."), _("\
17147 When enabled, GDB's internal \"physname\" code is checked against\n\
17149 NULL
, show_check_physname
,
17150 &setdebuglist
, &showdebuglist
);
17152 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
17154 Save a gdb-index file.\n\
17155 Usage: save gdb-index DIRECTORY"),
17157 set_cmd_completer (c
, filename_completer
);