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;
124 /* When set, the file that we're processing is known to have debugging
125 info for C++ namespaces. GCC 3.3.x did not produce this information,
126 but later versions do. */
128 static int processing_has_namespace_info
;
130 static const struct objfile_data
*dwarf2_objfile_data_key
;
132 struct dwarf2_section_info
137 /* Not NULL if the section was actually mmapped. */
139 /* Page aligned size of mmapped area. */
140 bfd_size_type map_len
;
141 /* True if we have tried to read this section. */
145 /* All offsets in the index are of this type. It must be
146 architecture-independent. */
147 typedef uint32_t offset_type
;
149 DEF_VEC_I (offset_type
);
151 /* A description of the mapped index. The file format is described in
152 a comment by the code that writes the index. */
155 /* Index data format version. */
158 /* The total length of the buffer. */
161 /* A pointer to the address table data. */
162 const gdb_byte
*address_table
;
164 /* Size of the address table data in bytes. */
165 offset_type address_table_size
;
167 /* The symbol table, implemented as a hash table. */
168 const offset_type
*symbol_table
;
170 /* Size in slots, each slot is 2 offset_types. */
171 offset_type symbol_table_slots
;
173 /* A pointer to the constant pool. */
174 const char *constant_pool
;
177 struct dwarf2_per_objfile
179 struct dwarf2_section_info info
;
180 struct dwarf2_section_info abbrev
;
181 struct dwarf2_section_info line
;
182 struct dwarf2_section_info loc
;
183 struct dwarf2_section_info macinfo
;
184 struct dwarf2_section_info str
;
185 struct dwarf2_section_info ranges
;
186 struct dwarf2_section_info types
;
187 struct dwarf2_section_info frame
;
188 struct dwarf2_section_info eh_frame
;
189 struct dwarf2_section_info gdb_index
;
192 struct objfile
*objfile
;
194 /* A list of all the compilation units. This is used to locate
195 the target compilation unit of a particular reference. */
196 struct dwarf2_per_cu_data
**all_comp_units
;
198 /* The number of compilation units in ALL_COMP_UNITS. */
201 /* The number of .debug_types-related CUs. */
202 int n_type_comp_units
;
204 /* The .debug_types-related CUs. */
205 struct dwarf2_per_cu_data
**type_comp_units
;
207 /* A chain of compilation units that are currently read in, so that
208 they can be freed later. */
209 struct dwarf2_per_cu_data
*read_in_chain
;
211 /* A table mapping .debug_types signatures to its signatured_type entry.
212 This is NULL if the .debug_types section hasn't been read in yet. */
213 htab_t signatured_types
;
215 /* A flag indicating wether this objfile has a section loaded at a
217 int has_section_at_zero
;
219 /* True if we are using the mapped index,
220 or we are faking it for OBJF_READNOW's sake. */
221 unsigned char using_index
;
223 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
224 struct mapped_index
*index_table
;
226 /* When using index_table, this keeps track of all quick_file_names entries.
227 TUs can share line table entries with CUs or other TUs, and there can be
228 a lot more TUs than unique line tables, so we maintain a separate table
229 of all line table entries to support the sharing. */
230 htab_t quick_file_names_table
;
232 /* Set during partial symbol reading, to prevent queueing of full
234 int reading_partial_symbols
;
236 /* Table mapping type .debug_info DIE offsets to types.
237 This is NULL if not allocated yet.
238 It (currently) makes sense to allocate debug_types_type_hash lazily.
239 To keep things simple we allocate both lazily. */
240 htab_t debug_info_type_hash
;
242 /* Table mapping type .debug_types DIE offsets to types.
243 This is NULL if not allocated yet. */
244 htab_t debug_types_type_hash
;
247 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
249 /* Default names of the debugging sections. */
251 /* Note that if the debugging section has been compressed, it might
252 have a name like .zdebug_info. */
254 static const struct dwarf2_debug_sections dwarf2_elf_names
= {
255 { ".debug_info", ".zdebug_info" },
256 { ".debug_abbrev", ".zdebug_abbrev" },
257 { ".debug_line", ".zdebug_line" },
258 { ".debug_loc", ".zdebug_loc" },
259 { ".debug_macinfo", ".zdebug_macinfo" },
260 { ".debug_str", ".zdebug_str" },
261 { ".debug_ranges", ".zdebug_ranges" },
262 { ".debug_types", ".zdebug_types" },
263 { ".debug_frame", ".zdebug_frame" },
264 { ".eh_frame", NULL
},
265 { ".gdb_index", ".zgdb_index" }
268 /* local data types */
270 /* We hold several abbreviation tables in memory at the same time. */
271 #ifndef ABBREV_HASH_SIZE
272 #define ABBREV_HASH_SIZE 121
275 /* The data in a compilation unit header, after target2host
276 translation, looks like this. */
277 struct comp_unit_head
281 unsigned char addr_size
;
282 unsigned char signed_addr_p
;
283 unsigned int abbrev_offset
;
285 /* Size of file offsets; either 4 or 8. */
286 unsigned int offset_size
;
288 /* Size of the length field; either 4 or 12. */
289 unsigned int initial_length_size
;
291 /* Offset to the first byte of this compilation unit header in the
292 .debug_info section, for resolving relative reference dies. */
295 /* Offset to first die in this cu from the start of the cu.
296 This will be the first byte following the compilation unit header. */
297 unsigned int first_die_offset
;
300 /* Type used for delaying computation of method physnames.
301 See comments for compute_delayed_physnames. */
302 struct delayed_method_info
304 /* The type to which the method is attached, i.e., its parent class. */
307 /* The index of the method in the type's function fieldlists. */
310 /* The index of the method in the fieldlist. */
313 /* The name of the DIE. */
316 /* The DIE associated with this method. */
317 struct die_info
*die
;
320 typedef struct delayed_method_info delayed_method_info
;
321 DEF_VEC_O (delayed_method_info
);
323 /* Internal state when decoding a particular compilation unit. */
326 /* The objfile containing this compilation unit. */
327 struct objfile
*objfile
;
329 /* The header of the compilation unit. */
330 struct comp_unit_head header
;
332 /* Base address of this compilation unit. */
333 CORE_ADDR base_address
;
335 /* Non-zero if base_address has been set. */
338 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
340 /* The language we are debugging. */
341 enum language language
;
342 const struct language_defn
*language_defn
;
344 const char *producer
;
346 /* The generic symbol table building routines have separate lists for
347 file scope symbols and all all other scopes (local scopes). So
348 we need to select the right one to pass to add_symbol_to_list().
349 We do it by keeping a pointer to the correct list in list_in_scope.
351 FIXME: The original dwarf code just treated the file scope as the
352 first local scope, and all other local scopes as nested local
353 scopes, and worked fine. Check to see if we really need to
354 distinguish these in buildsym.c. */
355 struct pending
**list_in_scope
;
357 /* DWARF abbreviation table associated with this compilation unit. */
358 struct abbrev_info
**dwarf2_abbrevs
;
360 /* Storage for the abbrev table. */
361 struct obstack abbrev_obstack
;
363 /* Hash table holding all the loaded partial DIEs. */
366 /* Storage for things with the same lifetime as this read-in compilation
367 unit, including partial DIEs. */
368 struct obstack comp_unit_obstack
;
370 /* When multiple dwarf2_cu structures are living in memory, this field
371 chains them all together, so that they can be released efficiently.
372 We will probably also want a generation counter so that most-recently-used
373 compilation units are cached... */
374 struct dwarf2_per_cu_data
*read_in_chain
;
376 /* Backchain to our per_cu entry if the tree has been built. */
377 struct dwarf2_per_cu_data
*per_cu
;
379 /* How many compilation units ago was this CU last referenced? */
382 /* A hash table of die offsets for following references. */
385 /* Full DIEs if read in. */
386 struct die_info
*dies
;
388 /* A set of pointers to dwarf2_per_cu_data objects for compilation
389 units referenced by this one. Only set during full symbol processing;
390 partial symbol tables do not have dependencies. */
393 /* Header data from the line table, during full symbol processing. */
394 struct line_header
*line_header
;
396 /* A list of methods which need to have physnames computed
397 after all type information has been read. */
398 VEC (delayed_method_info
) *method_list
;
400 /* Mark used when releasing cached dies. */
401 unsigned int mark
: 1;
403 /* This flag will be set if this compilation unit might include
404 inter-compilation-unit references. */
405 unsigned int has_form_ref_addr
: 1;
407 /* This flag will be set if this compilation unit includes any
408 DW_TAG_namespace DIEs. If we know that there are explicit
409 DIEs for namespaces, we don't need to try to infer them
410 from mangled names. */
411 unsigned int has_namespace_info
: 1;
413 /* This CU references .debug_loc. See the symtab->locations_valid field.
414 This test is imperfect as there may exist optimized debug code not using
415 any location list and still facing inlining issues if handled as
416 unoptimized code. For a future better test see GCC PR other/32998. */
418 unsigned int has_loclist
: 1;
421 /* Persistent data held for a compilation unit, even when not
422 processing it. We put a pointer to this structure in the
423 read_symtab_private field of the psymtab. If we encounter
424 inter-compilation-unit references, we also maintain a sorted
425 list of all compilation units. */
427 struct dwarf2_per_cu_data
429 /* The start offset and length of this compilation unit. 2**29-1
430 bytes should suffice to store the length of any compilation unit
431 - if it doesn't, GDB will fall over anyway.
432 NOTE: Unlike comp_unit_head.length, this length includes
433 initial_length_size. */
435 unsigned int length
: 29;
437 /* Flag indicating this compilation unit will be read in before
438 any of the current compilation units are processed. */
439 unsigned int queued
: 1;
441 /* This flag will be set if we need to load absolutely all DIEs
442 for this compilation unit, instead of just the ones we think
443 are interesting. It gets set if we look for a DIE in the
444 hash table and don't find it. */
445 unsigned int load_all_dies
: 1;
447 /* Non-zero if this CU is from .debug_types.
448 Otherwise it's from .debug_info. */
449 unsigned int from_debug_types
: 1;
451 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
452 of the CU cache it gets reset to NULL again. */
453 struct dwarf2_cu
*cu
;
455 /* The corresponding objfile. */
456 struct objfile
*objfile
;
458 /* When using partial symbol tables, the 'psymtab' field is active.
459 Otherwise the 'quick' field is active. */
462 /* The partial symbol table associated with this compilation unit,
463 or NULL for partial units (which do not have an associated
465 struct partial_symtab
*psymtab
;
467 /* Data needed by the "quick" functions. */
468 struct dwarf2_per_cu_quick_data
*quick
;
472 /* Entry in the signatured_types hash table. */
474 struct signatured_type
478 /* Offset in .debug_types of the type defined by this TU. */
479 unsigned int type_offset
;
481 /* The CU(/TU) of this type. */
482 struct dwarf2_per_cu_data per_cu
;
485 /* Struct used to pass misc. parameters to read_die_and_children, et
486 al. which are used for both .debug_info and .debug_types dies.
487 All parameters here are unchanging for the life of the call. This
488 struct exists to abstract away the constant parameters of die
491 struct die_reader_specs
493 /* The bfd of this objfile. */
496 /* The CU of the DIE we are parsing. */
497 struct dwarf2_cu
*cu
;
499 /* Pointer to start of section buffer.
500 This is either the start of .debug_info or .debug_types. */
501 const gdb_byte
*buffer
;
504 /* The line number information for a compilation unit (found in the
505 .debug_line section) begins with a "statement program header",
506 which contains the following information. */
509 unsigned int total_length
;
510 unsigned short version
;
511 unsigned int header_length
;
512 unsigned char minimum_instruction_length
;
513 unsigned char maximum_ops_per_instruction
;
514 unsigned char default_is_stmt
;
516 unsigned char line_range
;
517 unsigned char opcode_base
;
519 /* standard_opcode_lengths[i] is the number of operands for the
520 standard opcode whose value is i. This means that
521 standard_opcode_lengths[0] is unused, and the last meaningful
522 element is standard_opcode_lengths[opcode_base - 1]. */
523 unsigned char *standard_opcode_lengths
;
525 /* The include_directories table. NOTE! These strings are not
526 allocated with xmalloc; instead, they are pointers into
527 debug_line_buffer. If you try to free them, `free' will get
529 unsigned int num_include_dirs
, include_dirs_size
;
532 /* The file_names table. NOTE! These strings are not allocated
533 with xmalloc; instead, they are pointers into debug_line_buffer.
534 Don't try to free them directly. */
535 unsigned int num_file_names
, file_names_size
;
539 unsigned int dir_index
;
540 unsigned int mod_time
;
542 int included_p
; /* Non-zero if referenced by the Line Number Program. */
543 struct symtab
*symtab
; /* The associated symbol table, if any. */
546 /* The start and end of the statement program following this
547 header. These point into dwarf2_per_objfile->line_buffer. */
548 gdb_byte
*statement_program_start
, *statement_program_end
;
551 /* When we construct a partial symbol table entry we only
552 need this much information. */
553 struct partial_die_info
555 /* Offset of this DIE. */
558 /* DWARF-2 tag for this DIE. */
559 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
561 /* Assorted flags describing the data found in this DIE. */
562 unsigned int has_children
: 1;
563 unsigned int is_external
: 1;
564 unsigned int is_declaration
: 1;
565 unsigned int has_type
: 1;
566 unsigned int has_specification
: 1;
567 unsigned int has_pc_info
: 1;
569 /* Flag set if the SCOPE field of this structure has been
571 unsigned int scope_set
: 1;
573 /* Flag set if the DIE has a byte_size attribute. */
574 unsigned int has_byte_size
: 1;
576 /* Flag set if any of the DIE's children are template arguments. */
577 unsigned int has_template_arguments
: 1;
579 /* Flag set if fixup_partial_die has been called on this die. */
580 unsigned int fixup_called
: 1;
582 /* The name of this DIE. Normally the value of DW_AT_name, but
583 sometimes a default name for unnamed DIEs. */
586 /* The linkage name, if present. */
587 const char *linkage_name
;
589 /* The scope to prepend to our children. This is generally
590 allocated on the comp_unit_obstack, so will disappear
591 when this compilation unit leaves the cache. */
594 /* The location description associated with this DIE, if any. */
595 struct dwarf_block
*locdesc
;
597 /* If HAS_PC_INFO, the PC range associated with this DIE. */
601 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
602 DW_AT_sibling, if any. */
603 /* NOTE: This member isn't strictly necessary, read_partial_die could
604 return DW_AT_sibling values to its caller load_partial_dies. */
607 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
608 DW_AT_specification (or DW_AT_abstract_origin or
610 unsigned int spec_offset
;
612 /* Pointers to this DIE's parent, first child, and next sibling,
614 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
617 /* This data structure holds the information of an abbrev. */
620 unsigned int number
; /* number identifying abbrev */
621 enum dwarf_tag tag
; /* dwarf tag */
622 unsigned short has_children
; /* boolean */
623 unsigned short num_attrs
; /* number of attributes */
624 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
625 struct abbrev_info
*next
; /* next in chain */
630 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
631 ENUM_BITFIELD(dwarf_form
) form
: 16;
634 /* Attributes have a name and a value. */
637 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
638 ENUM_BITFIELD(dwarf_form
) form
: 15;
640 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
641 field should be in u.str (existing only for DW_STRING) but it is kept
642 here for better struct attribute alignment. */
643 unsigned int string_is_canonical
: 1;
648 struct dwarf_block
*blk
;
652 struct signatured_type
*signatured_type
;
657 /* This data structure holds a complete die structure. */
660 /* DWARF-2 tag for this DIE. */
661 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
663 /* Number of attributes */
664 unsigned char num_attrs
;
666 /* True if we're presently building the full type name for the
667 type derived from this DIE. */
668 unsigned char building_fullname
: 1;
673 /* Offset in .debug_info or .debug_types section. */
676 /* The dies in a compilation unit form an n-ary tree. PARENT
677 points to this die's parent; CHILD points to the first child of
678 this node; and all the children of a given node are chained
679 together via their SIBLING fields. */
680 struct die_info
*child
; /* Its first child, if any. */
681 struct die_info
*sibling
; /* Its next sibling, if any. */
682 struct die_info
*parent
; /* Its parent, if any. */
684 /* An array of attributes, with NUM_ATTRS elements. There may be
685 zero, but it's not common and zero-sized arrays are not
686 sufficiently portable C. */
687 struct attribute attrs
[1];
690 struct function_range
693 CORE_ADDR lowpc
, highpc
;
695 struct function_range
*next
;
698 /* Get at parts of an attribute structure. */
700 #define DW_STRING(attr) ((attr)->u.str)
701 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
702 #define DW_UNSND(attr) ((attr)->u.unsnd)
703 #define DW_BLOCK(attr) ((attr)->u.blk)
704 #define DW_SND(attr) ((attr)->u.snd)
705 #define DW_ADDR(attr) ((attr)->u.addr)
706 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
708 /* Blocks are a bunch of untyped bytes. */
715 #ifndef ATTR_ALLOC_CHUNK
716 #define ATTR_ALLOC_CHUNK 4
719 /* Allocate fields for structs, unions and enums in this size. */
720 #ifndef DW_FIELD_ALLOC_CHUNK
721 #define DW_FIELD_ALLOC_CHUNK 4
724 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
725 but this would require a corresponding change in unpack_field_as_long
727 static int bits_per_byte
= 8;
729 /* The routines that read and process dies for a C struct or C++ class
730 pass lists of data member fields and lists of member function fields
731 in an instance of a field_info structure, as defined below. */
734 /* List of data member and baseclasses fields. */
737 struct nextfield
*next
;
742 *fields
, *baseclasses
;
744 /* Number of fields (including baseclasses). */
747 /* Number of baseclasses. */
750 /* Set if the accesibility of one of the fields is not public. */
751 int non_public_fields
;
753 /* Member function fields array, entries are allocated in the order they
754 are encountered in the object file. */
757 struct nextfnfield
*next
;
758 struct fn_field fnfield
;
762 /* Member function fieldlist array, contains name of possibly overloaded
763 member function, number of overloaded member functions and a pointer
764 to the head of the member function field chain. */
769 struct nextfnfield
*head
;
773 /* Number of entries in the fnfieldlists array. */
776 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
777 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
778 struct typedef_field_list
780 struct typedef_field field
;
781 struct typedef_field_list
*next
;
784 unsigned typedef_field_list_count
;
787 /* One item on the queue of compilation units to read in full symbols
789 struct dwarf2_queue_item
791 struct dwarf2_per_cu_data
*per_cu
;
792 struct dwarf2_queue_item
*next
;
795 /* The current queue. */
796 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
798 /* Loaded secondary compilation units are kept in memory until they
799 have not been referenced for the processing of this many
800 compilation units. Set this to zero to disable caching. Cache
801 sizes of up to at least twenty will improve startup time for
802 typical inter-CU-reference binaries, at an obvious memory cost. */
803 static int dwarf2_max_cache_age
= 5;
805 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
806 struct cmd_list_element
*c
, const char *value
)
808 fprintf_filtered (file
, _("The upper bound on the age of cached "
809 "dwarf2 compilation units is %s.\n"),
814 /* Various complaints about symbol reading that don't abort the process. */
817 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
819 complaint (&symfile_complaints
,
820 _("statement list doesn't fit in .debug_line section"));
824 dwarf2_debug_line_missing_file_complaint (void)
826 complaint (&symfile_complaints
,
827 _(".debug_line section has line data without a file"));
831 dwarf2_debug_line_missing_end_sequence_complaint (void)
833 complaint (&symfile_complaints
,
834 _(".debug_line section has line "
835 "program sequence without an end"));
839 dwarf2_complex_location_expr_complaint (void)
841 complaint (&symfile_complaints
, _("location expression too complex"));
845 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
848 complaint (&symfile_complaints
,
849 _("const value length mismatch for '%s', got %d, expected %d"),
854 dwarf2_macros_too_long_complaint (void)
856 complaint (&symfile_complaints
,
857 _("macro info runs off end of `.debug_macinfo' section"));
861 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
863 complaint (&symfile_complaints
,
864 _("macro debug info contains a "
865 "malformed macro definition:\n`%s'"),
870 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
872 complaint (&symfile_complaints
,
873 _("invalid attribute class or form for '%s' in '%s'"),
877 /* local function prototypes */
879 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
881 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
884 static void dwarf2_build_psymtabs_hard (struct objfile
*);
886 static void scan_partial_symbols (struct partial_die_info
*,
887 CORE_ADDR
*, CORE_ADDR
*,
888 int, struct dwarf2_cu
*);
890 static void add_partial_symbol (struct partial_die_info
*,
893 static void add_partial_namespace (struct partial_die_info
*pdi
,
894 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
895 int need_pc
, struct dwarf2_cu
*cu
);
897 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
898 CORE_ADDR
*highpc
, int need_pc
,
899 struct dwarf2_cu
*cu
);
901 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
902 struct dwarf2_cu
*cu
);
904 static void add_partial_subprogram (struct partial_die_info
*pdi
,
905 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
906 int need_pc
, struct dwarf2_cu
*cu
);
908 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
909 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
910 bfd
*abfd
, struct dwarf2_cu
*cu
);
912 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
914 static void psymtab_to_symtab_1 (struct partial_symtab
*);
916 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
918 static void dwarf2_free_abbrev_table (void *);
920 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
923 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
926 static struct partial_die_info
*load_partial_dies (bfd
*,
927 gdb_byte
*, gdb_byte
*,
928 int, struct dwarf2_cu
*);
930 static gdb_byte
*read_partial_die (struct partial_die_info
*,
931 struct abbrev_info
*abbrev
,
933 gdb_byte
*, gdb_byte
*,
936 static struct partial_die_info
*find_partial_die (unsigned int,
939 static void fixup_partial_die (struct partial_die_info
*,
942 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
943 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
945 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
946 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
948 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
950 static int read_1_signed_byte (bfd
*, gdb_byte
*);
952 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
954 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
956 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
958 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
961 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
963 static LONGEST read_checked_initial_length_and_offset
964 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
965 unsigned int *, unsigned int *);
967 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
970 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
972 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
974 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
976 static char *read_indirect_string (bfd
*, gdb_byte
*,
977 const struct comp_unit_head
*,
980 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
982 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
984 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
986 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
988 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
991 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
995 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
996 struct dwarf2_cu
*cu
);
998 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1000 static struct die_info
*die_specification (struct die_info
*die
,
1001 struct dwarf2_cu
**);
1003 static void free_line_header (struct line_header
*lh
);
1005 static void add_file_name (struct line_header
*, char *, unsigned int,
1006 unsigned int, unsigned int);
1008 static struct line_header
*(dwarf_decode_line_header
1009 (unsigned int offset
,
1010 bfd
*abfd
, struct dwarf2_cu
*cu
));
1012 static void dwarf_decode_lines (struct line_header
*, const char *, bfd
*,
1013 struct dwarf2_cu
*, struct partial_symtab
*);
1015 static void dwarf2_start_subfile (char *, const char *, const char *);
1017 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1018 struct dwarf2_cu
*);
1020 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1021 struct dwarf2_cu
*, struct symbol
*);
1023 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1024 struct dwarf2_cu
*);
1026 static void dwarf2_const_value_attr (struct attribute
*attr
,
1029 struct obstack
*obstack
,
1030 struct dwarf2_cu
*cu
, long *value
,
1032 struct dwarf2_locexpr_baton
**baton
);
1034 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1036 static int need_gnat_info (struct dwarf2_cu
*);
1038 static struct type
*die_descriptive_type (struct die_info
*,
1039 struct dwarf2_cu
*);
1041 static void set_descriptive_type (struct type
*, struct die_info
*,
1042 struct dwarf2_cu
*);
1044 static struct type
*die_containing_type (struct die_info
*,
1045 struct dwarf2_cu
*);
1047 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1048 struct dwarf2_cu
*);
1050 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1052 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1054 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1056 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1057 const char *suffix
, int physname
,
1058 struct dwarf2_cu
*cu
);
1060 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1062 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1064 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1066 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1068 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1069 struct dwarf2_cu
*, struct partial_symtab
*);
1071 static int dwarf2_get_pc_bounds (struct die_info
*,
1072 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1073 struct partial_symtab
*);
1075 static void get_scope_pc_bounds (struct die_info
*,
1076 CORE_ADDR
*, CORE_ADDR
*,
1077 struct dwarf2_cu
*);
1079 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1080 CORE_ADDR
, struct dwarf2_cu
*);
1082 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1083 struct dwarf2_cu
*);
1085 static void dwarf2_attach_fields_to_type (struct field_info
*,
1086 struct type
*, struct dwarf2_cu
*);
1088 static void dwarf2_add_member_fn (struct field_info
*,
1089 struct die_info
*, struct type
*,
1090 struct dwarf2_cu
*);
1092 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1094 struct dwarf2_cu
*);
1096 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1098 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1100 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1102 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1104 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1106 static struct type
*read_module_type (struct die_info
*die
,
1107 struct dwarf2_cu
*cu
);
1109 static const char *namespace_name (struct die_info
*die
,
1110 int *is_anonymous
, struct dwarf2_cu
*);
1112 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1114 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1116 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1117 struct dwarf2_cu
*);
1119 static struct die_info
*read_comp_unit (gdb_byte
*, struct dwarf2_cu
*);
1121 static struct die_info
*read_die_and_children_1 (const struct die_reader_specs
*reader
,
1123 gdb_byte
**new_info_ptr
,
1124 struct die_info
*parent
);
1126 static struct die_info
*read_die_and_children (const struct die_reader_specs
*reader
,
1128 gdb_byte
**new_info_ptr
,
1129 struct die_info
*parent
);
1131 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*reader
,
1133 gdb_byte
**new_info_ptr
,
1134 struct die_info
*parent
);
1136 static gdb_byte
*read_full_die (const struct die_reader_specs
*reader
,
1137 struct die_info
**, gdb_byte
*,
1140 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1142 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1145 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1147 static const char *dwarf2_full_name (char *name
,
1148 struct die_info
*die
,
1149 struct dwarf2_cu
*cu
);
1151 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1152 struct dwarf2_cu
**);
1154 static char *dwarf_tag_name (unsigned int);
1156 static char *dwarf_attr_name (unsigned int);
1158 static char *dwarf_form_name (unsigned int);
1160 static char *dwarf_bool_name (unsigned int);
1162 static char *dwarf_type_encoding_name (unsigned int);
1165 static char *dwarf_cfi_name (unsigned int);
1168 static struct die_info
*sibling_die (struct die_info
*);
1170 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1172 static void dump_die_for_error (struct die_info
*);
1174 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1177 /*static*/ void dump_die (struct die_info
*, int max_level
);
1179 static void store_in_ref_table (struct die_info
*,
1180 struct dwarf2_cu
*);
1182 static int is_ref_attr (struct attribute
*);
1184 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1186 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1188 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1190 struct dwarf2_cu
**);
1192 static struct die_info
*follow_die_ref (struct die_info
*,
1194 struct dwarf2_cu
**);
1196 static struct die_info
*follow_die_sig (struct die_info
*,
1198 struct dwarf2_cu
**);
1200 static void read_signatured_type_at_offset (struct objfile
*objfile
,
1201 unsigned int offset
);
1203 static void read_signatured_type (struct objfile
*,
1204 struct signatured_type
*type_sig
);
1206 /* memory allocation interface */
1208 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1210 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1212 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1214 static void initialize_cu_func_list (struct dwarf2_cu
*);
1216 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1217 struct dwarf2_cu
*);
1219 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1220 char *, bfd
*, struct dwarf2_cu
*);
1222 static int attr_form_is_block (struct attribute
*);
1224 static int attr_form_is_section_offset (struct attribute
*);
1226 static int attr_form_is_constant (struct attribute
*);
1228 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1229 struct dwarf2_loclist_baton
*baton
,
1230 struct attribute
*attr
);
1232 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1234 struct dwarf2_cu
*cu
);
1236 static gdb_byte
*skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1237 struct abbrev_info
*abbrev
,
1238 struct dwarf2_cu
*cu
);
1240 static void free_stack_comp_unit (void *);
1242 static hashval_t
partial_die_hash (const void *item
);
1244 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1246 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1247 (unsigned int offset
, struct objfile
*objfile
);
1249 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1250 (unsigned int offset
, struct objfile
*objfile
);
1252 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1253 struct objfile
*objfile
);
1255 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1256 struct die_info
*comp_unit_die
);
1258 static void free_one_comp_unit (void *);
1260 static void free_cached_comp_units (void *);
1262 static void age_cached_comp_units (void);
1264 static void free_one_cached_comp_unit (void *);
1266 static struct type
*set_die_type (struct die_info
*, struct type
*,
1267 struct dwarf2_cu
*);
1269 static void create_all_comp_units (struct objfile
*);
1271 static int create_debug_types_hash_table (struct objfile
*objfile
);
1273 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1276 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1278 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1279 struct dwarf2_per_cu_data
*);
1281 static void dwarf2_mark (struct dwarf2_cu
*);
1283 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1285 static struct type
*get_die_type_at_offset (unsigned int,
1286 struct dwarf2_per_cu_data
*per_cu
);
1288 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1290 static void dwarf2_release_queue (void *dummy
);
1292 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1293 struct objfile
*objfile
);
1295 static void process_queue (struct objfile
*objfile
);
1297 static void find_file_and_directory (struct die_info
*die
,
1298 struct dwarf2_cu
*cu
,
1299 char **name
, char **comp_dir
);
1301 static char *file_full_name (int file
, struct line_header
*lh
,
1302 const char *comp_dir
);
1304 static gdb_byte
*partial_read_comp_unit_head (struct comp_unit_head
*header
,
1307 unsigned int buffer_size
,
1310 static void init_cu_die_reader (struct die_reader_specs
*reader
,
1311 struct dwarf2_cu
*cu
);
1313 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1317 /* Convert VALUE between big- and little-endian. */
1319 byte_swap (offset_type value
)
1323 result
= (value
& 0xff) << 24;
1324 result
|= (value
& 0xff00) << 8;
1325 result
|= (value
& 0xff0000) >> 8;
1326 result
|= (value
& 0xff000000) >> 24;
1330 #define MAYBE_SWAP(V) byte_swap (V)
1333 #define MAYBE_SWAP(V) (V)
1334 #endif /* WORDS_BIGENDIAN */
1336 /* The suffix for an index file. */
1337 #define INDEX_SUFFIX ".gdb-index"
1339 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1340 struct dwarf2_cu
*cu
);
1342 /* Try to locate the sections we need for DWARF 2 debugging
1343 information and return true if we have enough to do something.
1344 NAMES points to the dwarf2 section names, or is NULL if the standard
1345 ELF names are used. */
1348 dwarf2_has_info (struct objfile
*objfile
,
1349 const struct dwarf2_debug_sections
*names
)
1351 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1352 if (!dwarf2_per_objfile
)
1354 /* Initialize per-objfile state. */
1355 struct dwarf2_per_objfile
*data
1356 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1358 memset (data
, 0, sizeof (*data
));
1359 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1360 dwarf2_per_objfile
= data
;
1362 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1364 dwarf2_per_objfile
->objfile
= objfile
;
1366 return (dwarf2_per_objfile
->info
.asection
!= NULL
1367 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1370 /* When loading sections, we look either for uncompressed section or for
1371 compressed section names. */
1374 section_is_p (const char *section_name
,
1375 const struct dwarf2_section_names
*names
)
1377 if (names
->normal
!= NULL
1378 && strcmp (section_name
, names
->normal
) == 0)
1380 if (names
->compressed
!= NULL
1381 && strcmp (section_name
, names
->compressed
) == 0)
1386 /* This function is mapped across the sections and remembers the
1387 offset and size of each of the debugging sections we are interested
1391 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1393 const struct dwarf2_debug_sections
*names
;
1396 names
= &dwarf2_elf_names
;
1398 names
= (const struct dwarf2_debug_sections
*) vnames
;
1400 if (section_is_p (sectp
->name
, &names
->info
))
1402 dwarf2_per_objfile
->info
.asection
= sectp
;
1403 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1405 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1407 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1408 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1410 else if (section_is_p (sectp
->name
, &names
->line
))
1412 dwarf2_per_objfile
->line
.asection
= sectp
;
1413 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1415 else if (section_is_p (sectp
->name
, &names
->loc
))
1417 dwarf2_per_objfile
->loc
.asection
= sectp
;
1418 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1420 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1422 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1423 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1425 else if (section_is_p (sectp
->name
, &names
->str
))
1427 dwarf2_per_objfile
->str
.asection
= sectp
;
1428 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1430 else if (section_is_p (sectp
->name
, &names
->frame
))
1432 dwarf2_per_objfile
->frame
.asection
= sectp
;
1433 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1435 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1437 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1439 if (aflag
& SEC_HAS_CONTENTS
)
1441 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1442 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1445 else if (section_is_p (sectp
->name
, &names
->ranges
))
1447 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1448 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1450 else if (section_is_p (sectp
->name
, &names
->types
))
1452 dwarf2_per_objfile
->types
.asection
= sectp
;
1453 dwarf2_per_objfile
->types
.size
= bfd_get_section_size (sectp
);
1455 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1457 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1458 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1461 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1462 && bfd_section_vma (abfd
, sectp
) == 0)
1463 dwarf2_per_objfile
->has_section_at_zero
= 1;
1466 /* Decompress a section that was compressed using zlib. Store the
1467 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1470 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1471 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1473 bfd
*abfd
= objfile
->obfd
;
1475 error (_("Support for zlib-compressed DWARF data (from '%s') "
1476 "is disabled in this copy of GDB"),
1477 bfd_get_filename (abfd
));
1479 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1480 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1481 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1482 bfd_size_type uncompressed_size
;
1483 gdb_byte
*uncompressed_buffer
;
1486 int header_size
= 12;
1488 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1489 || bfd_bread (compressed_buffer
,
1490 compressed_size
, abfd
) != compressed_size
)
1491 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1492 bfd_get_filename (abfd
));
1494 /* Read the zlib header. In this case, it should be "ZLIB" followed
1495 by the uncompressed section size, 8 bytes in big-endian order. */
1496 if (compressed_size
< header_size
1497 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1498 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1499 bfd_get_filename (abfd
));
1500 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1501 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1502 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1503 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1504 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1505 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1506 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1507 uncompressed_size
+= compressed_buffer
[11];
1509 /* It is possible the section consists of several compressed
1510 buffers concatenated together, so we uncompress in a loop. */
1514 strm
.avail_in
= compressed_size
- header_size
;
1515 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1516 strm
.avail_out
= uncompressed_size
;
1517 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1519 rc
= inflateInit (&strm
);
1520 while (strm
.avail_in
> 0)
1523 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1524 bfd_get_filename (abfd
), rc
);
1525 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1526 + (uncompressed_size
- strm
.avail_out
));
1527 rc
= inflate (&strm
, Z_FINISH
);
1528 if (rc
!= Z_STREAM_END
)
1529 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1530 bfd_get_filename (abfd
), rc
);
1531 rc
= inflateReset (&strm
);
1533 rc
= inflateEnd (&strm
);
1535 || strm
.avail_out
!= 0)
1536 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1537 bfd_get_filename (abfd
), rc
);
1539 do_cleanups (cleanup
);
1540 *outbuf
= uncompressed_buffer
;
1541 *outsize
= uncompressed_size
;
1545 /* A helper function that decides whether a section is empty. */
1548 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1550 return info
->asection
== NULL
|| info
->size
== 0;
1553 /* Read the contents of the section SECTP from object file specified by
1554 OBJFILE, store info about the section into INFO.
1555 If the section is compressed, uncompress it before returning. */
1558 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1560 bfd
*abfd
= objfile
->obfd
;
1561 asection
*sectp
= info
->asection
;
1562 gdb_byte
*buf
, *retbuf
;
1563 unsigned char header
[4];
1567 info
->buffer
= NULL
;
1568 info
->map_addr
= NULL
;
1571 if (dwarf2_section_empty_p (info
))
1574 /* Check if the file has a 4-byte header indicating compression. */
1575 if (info
->size
> sizeof (header
)
1576 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1577 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1579 /* Upon decompression, update the buffer and its size. */
1580 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1582 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1590 pagesize
= getpagesize ();
1592 /* Only try to mmap sections which are large enough: we don't want to
1593 waste space due to fragmentation. Also, only try mmap for sections
1594 without relocations. */
1596 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1598 info
->buffer
= bfd_mmap (abfd
, 0, info
->size
, PROT_READ
,
1599 MAP_PRIVATE
, sectp
->filepos
,
1600 &info
->map_addr
, &info
->map_len
);
1602 if ((caddr_t
)info
->buffer
!= MAP_FAILED
)
1604 #if HAVE_POSIX_MADVISE
1605 posix_madvise (info
->map_addr
, info
->map_len
, POSIX_MADV_WILLNEED
);
1612 /* If we get here, we are a normal, not-compressed section. */
1614 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1616 /* When debugging .o files, we may need to apply relocations; see
1617 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1618 We never compress sections in .o files, so we only need to
1619 try this when the section is not compressed. */
1620 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1623 info
->buffer
= retbuf
;
1627 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1628 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1629 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1630 bfd_get_filename (abfd
));
1633 /* A helper function that returns the size of a section in a safe way.
1634 If you are positive that the section has been read before using the
1635 size, then it is safe to refer to the dwarf2_section_info object's
1636 "size" field directly. In other cases, you must call this
1637 function, because for compressed sections the size field is not set
1638 correctly until the section has been read. */
1640 static bfd_size_type
1641 dwarf2_section_size (struct objfile
*objfile
,
1642 struct dwarf2_section_info
*info
)
1645 dwarf2_read_section (objfile
, info
);
1649 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1653 dwarf2_get_section_info (struct objfile
*objfile
,
1654 enum dwarf2_section_enum sect
,
1655 asection
**sectp
, gdb_byte
**bufp
,
1656 bfd_size_type
*sizep
)
1658 struct dwarf2_per_objfile
*data
1659 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1660 struct dwarf2_section_info
*info
;
1662 /* We may see an objfile without any DWARF, in which case we just
1673 case DWARF2_DEBUG_FRAME
:
1674 info
= &data
->frame
;
1676 case DWARF2_EH_FRAME
:
1677 info
= &data
->eh_frame
;
1680 gdb_assert_not_reached ("unexpected section");
1683 dwarf2_read_section (objfile
, info
);
1685 *sectp
= info
->asection
;
1686 *bufp
= info
->buffer
;
1687 *sizep
= info
->size
;
1691 /* DWARF quick_symbols_functions support. */
1693 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1694 unique line tables, so we maintain a separate table of all .debug_line
1695 derived entries to support the sharing.
1696 All the quick functions need is the list of file names. We discard the
1697 line_header when we're done and don't need to record it here. */
1698 struct quick_file_names
1700 /* The offset in .debug_line of the line table. We hash on this. */
1701 unsigned int offset
;
1703 /* The number of entries in file_names, real_names. */
1704 unsigned int num_file_names
;
1706 /* The file names from the line table, after being run through
1708 const char **file_names
;
1710 /* The file names from the line table after being run through
1711 gdb_realpath. These are computed lazily. */
1712 const char **real_names
;
1715 /* When using the index (and thus not using psymtabs), each CU has an
1716 object of this type. This is used to hold information needed by
1717 the various "quick" methods. */
1718 struct dwarf2_per_cu_quick_data
1720 /* The file table. This can be NULL if there was no file table
1721 or it's currently not read in.
1722 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1723 struct quick_file_names
*file_names
;
1725 /* The corresponding symbol table. This is NULL if symbols for this
1726 CU have not yet been read. */
1727 struct symtab
*symtab
;
1729 /* A temporary mark bit used when iterating over all CUs in
1730 expand_symtabs_matching. */
1731 unsigned int mark
: 1;
1733 /* True if we've tried to read the file table and found there isn't one.
1734 There will be no point in trying to read it again next time. */
1735 unsigned int no_file_data
: 1;
1738 /* Hash function for a quick_file_names. */
1741 hash_file_name_entry (const void *e
)
1743 const struct quick_file_names
*file_data
= e
;
1745 return file_data
->offset
;
1748 /* Equality function for a quick_file_names. */
1751 eq_file_name_entry (const void *a
, const void *b
)
1753 const struct quick_file_names
*ea
= a
;
1754 const struct quick_file_names
*eb
= b
;
1756 return ea
->offset
== eb
->offset
;
1759 /* Delete function for a quick_file_names. */
1762 delete_file_name_entry (void *e
)
1764 struct quick_file_names
*file_data
= e
;
1767 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
1769 xfree ((void*) file_data
->file_names
[i
]);
1770 if (file_data
->real_names
)
1771 xfree ((void*) file_data
->real_names
[i
]);
1774 /* The space for the struct itself lives on objfile_obstack,
1775 so we don't free it here. */
1778 /* Create a quick_file_names hash table. */
1781 create_quick_file_names_table (unsigned int nr_initial_entries
)
1783 return htab_create_alloc (nr_initial_entries
,
1784 hash_file_name_entry
, eq_file_name_entry
,
1785 delete_file_name_entry
, xcalloc
, xfree
);
1788 /* Read in the symbols for PER_CU. OBJFILE is the objfile from which
1792 dw2_do_instantiate_symtab (struct objfile
*objfile
,
1793 struct dwarf2_per_cu_data
*per_cu
)
1795 struct cleanup
*back_to
;
1797 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
1799 queue_comp_unit (per_cu
, objfile
);
1801 if (per_cu
->from_debug_types
)
1802 read_signatured_type_at_offset (objfile
, per_cu
->offset
);
1804 load_full_comp_unit (per_cu
, objfile
);
1806 process_queue (objfile
);
1808 /* Age the cache, releasing compilation units that have not
1809 been used recently. */
1810 age_cached_comp_units ();
1812 do_cleanups (back_to
);
1815 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1816 the objfile from which this CU came. Returns the resulting symbol
1819 static struct symtab
*
1820 dw2_instantiate_symtab (struct objfile
*objfile
,
1821 struct dwarf2_per_cu_data
*per_cu
)
1823 if (!per_cu
->v
.quick
->symtab
)
1825 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1826 increment_reading_symtab ();
1827 dw2_do_instantiate_symtab (objfile
, per_cu
);
1828 do_cleanups (back_to
);
1830 return per_cu
->v
.quick
->symtab
;
1833 /* Return the CU given its index. */
1835 static struct dwarf2_per_cu_data
*
1836 dw2_get_cu (int index
)
1838 if (index
>= dwarf2_per_objfile
->n_comp_units
)
1840 index
-= dwarf2_per_objfile
->n_comp_units
;
1841 return dwarf2_per_objfile
->type_comp_units
[index
];
1843 return dwarf2_per_objfile
->all_comp_units
[index
];
1846 /* A helper function that knows how to read a 64-bit value in a way
1847 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1851 extract_cu_value (const char *bytes
, ULONGEST
*result
)
1853 if (sizeof (ULONGEST
) < 8)
1857 /* Ignore the upper 4 bytes if they are all zero. */
1858 for (i
= 0; i
< 4; ++i
)
1859 if (bytes
[i
+ 4] != 0)
1862 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
1865 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
1869 /* Read the CU list from the mapped index, and use it to create all
1870 the CU objects for this objfile. Return 0 if something went wrong,
1871 1 if everything went ok. */
1874 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
1875 offset_type cu_list_elements
)
1879 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
1880 dwarf2_per_objfile
->all_comp_units
1881 = obstack_alloc (&objfile
->objfile_obstack
,
1882 dwarf2_per_objfile
->n_comp_units
1883 * sizeof (struct dwarf2_per_cu_data
*));
1885 for (i
= 0; i
< cu_list_elements
; i
+= 2)
1887 struct dwarf2_per_cu_data
*the_cu
;
1888 ULONGEST offset
, length
;
1890 if (!extract_cu_value (cu_list
, &offset
)
1891 || !extract_cu_value (cu_list
+ 8, &length
))
1895 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1896 struct dwarf2_per_cu_data
);
1897 the_cu
->offset
= offset
;
1898 the_cu
->length
= length
;
1899 the_cu
->objfile
= objfile
;
1900 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1901 struct dwarf2_per_cu_quick_data
);
1902 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
1908 /* Create the signatured type hash table from the index. */
1911 create_signatured_type_table_from_index (struct objfile
*objfile
,
1912 const gdb_byte
*bytes
,
1913 offset_type elements
)
1916 htab_t sig_types_hash
;
1918 dwarf2_per_objfile
->n_type_comp_units
= elements
/ 3;
1919 dwarf2_per_objfile
->type_comp_units
1920 = obstack_alloc (&objfile
->objfile_obstack
,
1921 dwarf2_per_objfile
->n_type_comp_units
1922 * sizeof (struct dwarf2_per_cu_data
*));
1924 sig_types_hash
= allocate_signatured_type_table (objfile
);
1926 for (i
= 0; i
< elements
; i
+= 3)
1928 struct signatured_type
*type_sig
;
1929 ULONGEST offset
, type_offset
, signature
;
1932 if (!extract_cu_value (bytes
, &offset
)
1933 || !extract_cu_value (bytes
+ 8, &type_offset
))
1935 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
1938 type_sig
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1939 struct signatured_type
);
1940 type_sig
->signature
= signature
;
1941 type_sig
->type_offset
= type_offset
;
1942 type_sig
->per_cu
.from_debug_types
= 1;
1943 type_sig
->per_cu
.offset
= offset
;
1944 type_sig
->per_cu
.objfile
= objfile
;
1945 type_sig
->per_cu
.v
.quick
1946 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1947 struct dwarf2_per_cu_quick_data
);
1949 slot
= htab_find_slot (sig_types_hash
, type_sig
, INSERT
);
1952 dwarf2_per_objfile
->type_comp_units
[i
/ 3] = &type_sig
->per_cu
;
1955 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
1960 /* Read the address map data from the mapped index, and use it to
1961 populate the objfile's psymtabs_addrmap. */
1964 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
1966 const gdb_byte
*iter
, *end
;
1967 struct obstack temp_obstack
;
1968 struct addrmap
*mutable_map
;
1969 struct cleanup
*cleanup
;
1972 obstack_init (&temp_obstack
);
1973 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
1974 mutable_map
= addrmap_create_mutable (&temp_obstack
);
1976 iter
= index
->address_table
;
1977 end
= iter
+ index
->address_table_size
;
1979 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1983 ULONGEST hi
, lo
, cu_index
;
1984 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1986 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1988 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
1991 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
1992 dw2_get_cu (cu_index
));
1995 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
1996 &objfile
->objfile_obstack
);
1997 do_cleanups (cleanup
);
2000 /* The hash function for strings in the mapped index. This is the same as
2001 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2002 implementation. This is necessary because the hash function is tied to the
2003 format of the mapped index file. The hash values do not have to match with
2006 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2009 mapped_index_string_hash (int index_version
, const void *p
)
2011 const unsigned char *str
= (const unsigned char *) p
;
2015 while ((c
= *str
++) != 0)
2017 if (index_version
>= 5)
2019 r
= r
* 67 + c
- 113;
2025 /* Find a slot in the mapped index INDEX for the object named NAME.
2026 If NAME is found, set *VEC_OUT to point to the CU vector in the
2027 constant pool and return 1. If NAME cannot be found, return 0. */
2030 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2031 offset_type
**vec_out
)
2033 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2035 offset_type slot
, step
;
2036 int (*cmp
) (const char *, const char *);
2038 if (current_language
->la_language
== language_cplus
2039 || current_language
->la_language
== language_java
2040 || current_language
->la_language
== language_fortran
)
2042 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2044 const char *paren
= strchr (name
, '(');
2050 dup
= xmalloc (paren
- name
+ 1);
2051 memcpy (dup
, name
, paren
- name
);
2052 dup
[paren
- name
] = 0;
2054 make_cleanup (xfree
, dup
);
2059 /* Index version 4 did not support case insensitive searches. But the
2060 indexes for case insensitive languages are built in lowercase, therefore
2061 simulate our NAME being searched is also lowercased. */
2062 hash
= mapped_index_string_hash ((index
->version
== 4
2063 && case_sensitivity
== case_sensitive_off
2064 ? 5 : index
->version
),
2067 slot
= hash
& (index
->symbol_table_slots
- 1);
2068 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2069 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2073 /* Convert a slot number to an offset into the table. */
2074 offset_type i
= 2 * slot
;
2076 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2078 do_cleanups (back_to
);
2082 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2083 if (!cmp (name
, str
))
2085 *vec_out
= (offset_type
*) (index
->constant_pool
2086 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2087 do_cleanups (back_to
);
2091 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2095 /* Read the index file. If everything went ok, initialize the "quick"
2096 elements of all the CUs and return 1. Otherwise, return 0. */
2099 dwarf2_read_index (struct objfile
*objfile
)
2102 struct mapped_index
*map
;
2103 offset_type
*metadata
;
2104 const gdb_byte
*cu_list
;
2105 const gdb_byte
*types_list
= NULL
;
2106 offset_type version
, cu_list_elements
;
2107 offset_type types_list_elements
= 0;
2110 if (dwarf2_section_empty_p (&dwarf2_per_objfile
->gdb_index
))
2113 /* Older elfutils strip versions could keep the section in the main
2114 executable while splitting it for the separate debug info file. */
2115 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
2116 & SEC_HAS_CONTENTS
) == 0)
2119 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
2121 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
2122 /* Version check. */
2123 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2124 /* Versions earlier than 3 emitted every copy of a psymbol. This
2125 causes the index to behave very poorly for certain requests. Version 3
2126 contained incomplete addrmap. So, it seems better to just ignore such
2127 indices. Index version 4 uses a different hash function than index
2128 version 5 and later. */
2131 /* Indexes with higher version than the one supported by GDB may be no
2132 longer backward compatible. */
2136 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
2137 map
->version
= version
;
2138 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
2140 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2143 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2144 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2148 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2149 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2150 - MAYBE_SWAP (metadata
[i
]))
2154 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2155 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2156 - MAYBE_SWAP (metadata
[i
]));
2159 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2160 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2161 - MAYBE_SWAP (metadata
[i
]))
2162 / (2 * sizeof (offset_type
)));
2165 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2167 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
2170 if (types_list_elements
2171 && !create_signatured_type_table_from_index (objfile
, types_list
,
2172 types_list_elements
))
2175 create_addrmap_from_index (objfile
, map
);
2177 dwarf2_per_objfile
->index_table
= map
;
2178 dwarf2_per_objfile
->using_index
= 1;
2179 dwarf2_per_objfile
->quick_file_names_table
=
2180 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2185 /* A helper for the "quick" functions which sets the global
2186 dwarf2_per_objfile according to OBJFILE. */
2189 dw2_setup (struct objfile
*objfile
)
2191 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2192 gdb_assert (dwarf2_per_objfile
);
2195 /* A helper for the "quick" functions which attempts to read the line
2196 table for THIS_CU. */
2198 static struct quick_file_names
*
2199 dw2_get_file_names (struct objfile
*objfile
,
2200 struct dwarf2_per_cu_data
*this_cu
)
2202 bfd
*abfd
= objfile
->obfd
;
2203 struct line_header
*lh
;
2204 struct attribute
*attr
;
2205 struct cleanup
*cleanups
;
2206 struct die_info
*comp_unit_die
;
2207 struct dwarf2_section_info
* sec
;
2208 gdb_byte
*beg_of_comp_unit
, *info_ptr
, *buffer
;
2209 int has_children
, i
;
2210 struct dwarf2_cu cu
;
2211 unsigned int bytes_read
, buffer_size
;
2212 struct die_reader_specs reader_specs
;
2213 char *name
, *comp_dir
;
2215 struct quick_file_names
*qfn
;
2216 unsigned int line_offset
;
2218 if (this_cu
->v
.quick
->file_names
!= NULL
)
2219 return this_cu
->v
.quick
->file_names
;
2220 /* If we know there is no line data, no point in looking again. */
2221 if (this_cu
->v
.quick
->no_file_data
)
2224 init_one_comp_unit (&cu
, objfile
);
2225 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
2227 if (this_cu
->from_debug_types
)
2228 sec
= &dwarf2_per_objfile
->types
;
2230 sec
= &dwarf2_per_objfile
->info
;
2231 dwarf2_read_section (objfile
, sec
);
2232 buffer_size
= sec
->size
;
2233 buffer
= sec
->buffer
;
2234 info_ptr
= buffer
+ this_cu
->offset
;
2235 beg_of_comp_unit
= info_ptr
;
2237 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
2238 buffer
, buffer_size
,
2241 /* Complete the cu_header. */
2242 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
2243 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
2246 cu
.per_cu
= this_cu
;
2248 dwarf2_read_abbrevs (abfd
, &cu
);
2249 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2251 if (this_cu
->from_debug_types
)
2252 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
2253 init_cu_die_reader (&reader_specs
, &cu
);
2254 read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2260 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, &cu
);
2263 struct quick_file_names find_entry
;
2265 line_offset
= DW_UNSND (attr
);
2267 /* We may have already read in this line header (TU line header sharing).
2268 If we have we're done. */
2269 find_entry
.offset
= line_offset
;
2270 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2271 &find_entry
, INSERT
);
2274 do_cleanups (cleanups
);
2275 this_cu
->v
.quick
->file_names
= *slot
;
2279 lh
= dwarf_decode_line_header (line_offset
, abfd
, &cu
);
2283 do_cleanups (cleanups
);
2284 this_cu
->v
.quick
->no_file_data
= 1;
2288 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2289 qfn
->offset
= line_offset
;
2290 gdb_assert (slot
!= NULL
);
2293 find_file_and_directory (comp_unit_die
, &cu
, &name
, &comp_dir
);
2295 qfn
->num_file_names
= lh
->num_file_names
;
2296 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2297 lh
->num_file_names
* sizeof (char *));
2298 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2299 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2300 qfn
->real_names
= NULL
;
2302 free_line_header (lh
);
2303 do_cleanups (cleanups
);
2305 this_cu
->v
.quick
->file_names
= qfn
;
2309 /* A helper for the "quick" functions which computes and caches the
2310 real path for a given file name from the line table. */
2313 dw2_get_real_path (struct objfile
*objfile
,
2314 struct quick_file_names
*qfn
, int index
)
2316 if (qfn
->real_names
== NULL
)
2317 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2318 qfn
->num_file_names
, sizeof (char *));
2320 if (qfn
->real_names
[index
] == NULL
)
2321 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2323 return qfn
->real_names
[index
];
2326 static struct symtab
*
2327 dw2_find_last_source_symtab (struct objfile
*objfile
)
2331 dw2_setup (objfile
);
2332 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2333 return dw2_instantiate_symtab (objfile
, dw2_get_cu (index
));
2336 /* Traversal function for dw2_forget_cached_source_info. */
2339 dw2_free_cached_file_names (void **slot
, void *info
)
2341 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2343 if (file_data
->real_names
)
2347 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2349 xfree ((void*) file_data
->real_names
[i
]);
2350 file_data
->real_names
[i
] = NULL
;
2358 dw2_forget_cached_source_info (struct objfile
*objfile
)
2360 dw2_setup (objfile
);
2362 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2363 dw2_free_cached_file_names
, NULL
);
2367 dw2_lookup_symtab (struct objfile
*objfile
, const char *name
,
2368 const char *full_path
, const char *real_path
,
2369 struct symtab
**result
)
2372 int check_basename
= lbasename (name
) == name
;
2373 struct dwarf2_per_cu_data
*base_cu
= NULL
;
2375 dw2_setup (objfile
);
2377 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2378 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2381 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2382 struct quick_file_names
*file_data
;
2384 if (per_cu
->v
.quick
->symtab
)
2387 file_data
= dw2_get_file_names (objfile
, per_cu
);
2388 if (file_data
== NULL
)
2391 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2393 const char *this_name
= file_data
->file_names
[j
];
2395 if (FILENAME_CMP (name
, this_name
) == 0)
2397 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2401 if (check_basename
&& ! base_cu
2402 && FILENAME_CMP (lbasename (this_name
), name
) == 0)
2405 if (full_path
!= NULL
)
2407 const char *this_real_name
= dw2_get_real_path (objfile
,
2410 if (this_real_name
!= NULL
2411 && FILENAME_CMP (full_path
, this_real_name
) == 0)
2413 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2418 if (real_path
!= NULL
)
2420 const char *this_real_name
= dw2_get_real_path (objfile
,
2423 if (this_real_name
!= NULL
2424 && FILENAME_CMP (real_path
, this_real_name
) == 0)
2426 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2435 *result
= dw2_instantiate_symtab (objfile
, base_cu
);
2442 static struct symtab
*
2443 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2444 const char *name
, domain_enum domain
)
2446 /* We do all the work in the pre_expand_symtabs_matching hook
2451 /* A helper function that expands all symtabs that hold an object
2455 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2457 dw2_setup (objfile
);
2459 /* index_table is NULL if OBJF_READNOW. */
2460 if (dwarf2_per_objfile
->index_table
)
2464 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2467 offset_type i
, len
= MAYBE_SWAP (*vec
);
2468 for (i
= 0; i
< len
; ++i
)
2470 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2471 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2473 dw2_instantiate_symtab (objfile
, per_cu
);
2480 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2481 enum block_enum block_kind
, const char *name
,
2484 dw2_do_expand_symtabs_matching (objfile
, name
);
2488 dw2_print_stats (struct objfile
*objfile
)
2492 dw2_setup (objfile
);
2494 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2495 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2497 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2499 if (!per_cu
->v
.quick
->symtab
)
2502 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2506 dw2_dump (struct objfile
*objfile
)
2508 /* Nothing worth printing. */
2512 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2513 struct section_offsets
*delta
)
2515 /* There's nothing to relocate here. */
2519 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2520 const char *func_name
)
2522 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2526 dw2_expand_all_symtabs (struct objfile
*objfile
)
2530 dw2_setup (objfile
);
2532 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2533 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2535 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2537 dw2_instantiate_symtab (objfile
, per_cu
);
2542 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2543 const char *filename
)
2547 dw2_setup (objfile
);
2549 /* We don't need to consider type units here.
2550 This is only called for examining code, e.g. expand_line_sal.
2551 There can be an order of magnitude (or more) more type units
2552 than comp units, and we avoid them if we can. */
2554 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2557 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2558 struct quick_file_names
*file_data
;
2560 if (per_cu
->v
.quick
->symtab
)
2563 file_data
= dw2_get_file_names (objfile
, per_cu
);
2564 if (file_data
== NULL
)
2567 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2569 const char *this_name
= file_data
->file_names
[j
];
2570 if (FILENAME_CMP (this_name
, filename
) == 0)
2572 dw2_instantiate_symtab (objfile
, per_cu
);
2580 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2582 struct dwarf2_per_cu_data
*per_cu
;
2584 struct quick_file_names
*file_data
;
2586 dw2_setup (objfile
);
2588 /* index_table is NULL if OBJF_READNOW. */
2589 if (!dwarf2_per_objfile
->index_table
)
2592 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2596 /* Note that this just looks at the very first one named NAME -- but
2597 actually we are looking for a function. find_main_filename
2598 should be rewritten so that it doesn't require a custom hook. It
2599 could just use the ordinary symbol tables. */
2600 /* vec[0] is the length, which must always be >0. */
2601 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[1]));
2603 file_data
= dw2_get_file_names (objfile
, per_cu
);
2604 if (file_data
== NULL
)
2607 return file_data
->file_names
[file_data
->num_file_names
- 1];
2611 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
2612 struct objfile
*objfile
, int global
,
2613 int (*callback
) (struct block
*,
2614 struct symbol
*, void *),
2615 void *data
, symbol_compare_ftype
*match
,
2616 symbol_compare_ftype
*ordered_compare
)
2618 /* Currently unimplemented; used for Ada. The function can be called if the
2619 current language is Ada for a non-Ada objfile using GNU index. As Ada
2620 does not look for non-Ada symbols this function should just return. */
2624 dw2_expand_symtabs_matching (struct objfile
*objfile
,
2625 int (*file_matcher
) (const char *, void *),
2626 int (*name_matcher
) (const char *, void *),
2627 enum search_domain kind
,
2632 struct mapped_index
*index
;
2634 dw2_setup (objfile
);
2636 /* index_table is NULL if OBJF_READNOW. */
2637 if (!dwarf2_per_objfile
->index_table
)
2639 index
= dwarf2_per_objfile
->index_table
;
2641 if (file_matcher
!= NULL
)
2642 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2643 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2646 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2647 struct quick_file_names
*file_data
;
2649 per_cu
->v
.quick
->mark
= 0;
2650 if (per_cu
->v
.quick
->symtab
)
2653 file_data
= dw2_get_file_names (objfile
, per_cu
);
2654 if (file_data
== NULL
)
2657 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2659 if (file_matcher (file_data
->file_names
[j
], data
))
2661 per_cu
->v
.quick
->mark
= 1;
2667 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2669 offset_type idx
= 2 * iter
;
2671 offset_type
*vec
, vec_len
, vec_idx
;
2673 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2676 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
2678 if (! (*name_matcher
) (name
, data
))
2681 /* The name was matched, now expand corresponding CUs that were
2683 vec
= (offset_type
*) (index
->constant_pool
2684 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
2685 vec_len
= MAYBE_SWAP (vec
[0]);
2686 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2688 struct dwarf2_per_cu_data
*per_cu
;
2690 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[vec_idx
+ 1]));
2691 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
2692 dw2_instantiate_symtab (objfile
, per_cu
);
2697 static struct symtab
*
2698 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
2699 struct minimal_symbol
*msymbol
,
2701 struct obj_section
*section
,
2704 struct dwarf2_per_cu_data
*data
;
2706 dw2_setup (objfile
);
2708 if (!objfile
->psymtabs_addrmap
)
2711 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
2715 if (warn_if_readin
&& data
->v
.quick
->symtab
)
2716 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2717 paddress (get_objfile_arch (objfile
), pc
));
2719 return dw2_instantiate_symtab (objfile
, data
);
2723 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
2728 dw2_setup (objfile
);
2730 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2731 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2734 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2735 struct quick_file_names
*file_data
;
2737 if (per_cu
->v
.quick
->symtab
)
2740 file_data
= dw2_get_file_names (objfile
, per_cu
);
2741 if (file_data
== NULL
)
2744 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2746 const char *this_real_name
= dw2_get_real_path (objfile
, file_data
,
2748 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
2754 dw2_has_symbols (struct objfile
*objfile
)
2759 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
2762 dw2_find_last_source_symtab
,
2763 dw2_forget_cached_source_info
,
2766 dw2_pre_expand_symtabs_matching
,
2770 dw2_expand_symtabs_for_function
,
2771 dw2_expand_all_symtabs
,
2772 dw2_expand_symtabs_with_filename
,
2773 dw2_find_symbol_file
,
2774 dw2_map_matching_symbols
,
2775 dw2_expand_symtabs_matching
,
2776 dw2_find_pc_sect_symtab
,
2777 dw2_map_symbol_filenames
2780 /* Initialize for reading DWARF for this objfile. Return 0 if this
2781 file will use psymtabs, or 1 if using the GNU index. */
2784 dwarf2_initialize_objfile (struct objfile
*objfile
)
2786 /* If we're about to read full symbols, don't bother with the
2787 indices. In this case we also don't care if some other debug
2788 format is making psymtabs, because they are all about to be
2790 if ((objfile
->flags
& OBJF_READNOW
))
2794 dwarf2_per_objfile
->using_index
= 1;
2795 create_all_comp_units (objfile
);
2796 create_debug_types_hash_table (objfile
);
2797 dwarf2_per_objfile
->quick_file_names_table
=
2798 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2800 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2801 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2803 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2805 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2806 struct dwarf2_per_cu_quick_data
);
2809 /* Return 1 so that gdb sees the "quick" functions. However,
2810 these functions will be no-ops because we will have expanded
2815 if (dwarf2_read_index (objfile
))
2823 /* Build a partial symbol table. */
2826 dwarf2_build_psymtabs (struct objfile
*objfile
)
2828 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2830 init_psymbol_list (objfile
, 1024);
2833 dwarf2_build_psymtabs_hard (objfile
);
2836 /* Return TRUE if OFFSET is within CU_HEADER. */
2839 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
2841 unsigned int bottom
= cu_header
->offset
;
2842 unsigned int top
= (cu_header
->offset
2844 + cu_header
->initial_length_size
);
2846 return (offset
>= bottom
&& offset
< top
);
2849 /* Read in the comp unit header information from the debug_info at info_ptr.
2850 NOTE: This leaves members offset, first_die_offset to be filled in
2854 read_comp_unit_head (struct comp_unit_head
*cu_header
,
2855 gdb_byte
*info_ptr
, bfd
*abfd
)
2858 unsigned int bytes_read
;
2860 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
2861 cu_header
->initial_length_size
= bytes_read
;
2862 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
2863 info_ptr
+= bytes_read
;
2864 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
2866 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
2868 info_ptr
+= bytes_read
;
2869 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
2871 signed_addr
= bfd_get_sign_extend_vma (abfd
);
2872 if (signed_addr
< 0)
2873 internal_error (__FILE__
, __LINE__
,
2874 _("read_comp_unit_head: dwarf from non elf file"));
2875 cu_header
->signed_addr_p
= signed_addr
;
2881 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
2882 gdb_byte
*buffer
, unsigned int buffer_size
,
2885 gdb_byte
*beg_of_comp_unit
= info_ptr
;
2887 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
2889 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
2890 error (_("Dwarf Error: wrong version in compilation unit header "
2891 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
2892 bfd_get_filename (abfd
));
2894 if (header
->abbrev_offset
2895 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
2896 &dwarf2_per_objfile
->abbrev
))
2897 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
2898 "(offset 0x%lx + 6) [in module %s]"),
2899 (long) header
->abbrev_offset
,
2900 (long) (beg_of_comp_unit
- buffer
),
2901 bfd_get_filename (abfd
));
2903 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
2904 > buffer
+ buffer_size
)
2905 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
2906 "(offset 0x%lx + 0) [in module %s]"),
2907 (long) header
->length
,
2908 (long) (beg_of_comp_unit
- buffer
),
2909 bfd_get_filename (abfd
));
2914 /* Read in the types comp unit header information from .debug_types entry at
2915 types_ptr. The result is a pointer to one past the end of the header. */
2918 read_type_comp_unit_head (struct comp_unit_head
*cu_header
,
2919 ULONGEST
*signature
,
2920 gdb_byte
*types_ptr
, bfd
*abfd
)
2922 gdb_byte
*initial_types_ptr
= types_ptr
;
2924 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
2925 &dwarf2_per_objfile
->types
);
2926 cu_header
->offset
= types_ptr
- dwarf2_per_objfile
->types
.buffer
;
2928 types_ptr
= read_comp_unit_head (cu_header
, types_ptr
, abfd
);
2930 *signature
= read_8_bytes (abfd
, types_ptr
);
2932 types_ptr
+= cu_header
->offset_size
;
2933 cu_header
->first_die_offset
= types_ptr
- initial_types_ptr
;
2938 /* Allocate a new partial symtab for file named NAME and mark this new
2939 partial symtab as being an include of PST. */
2942 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
2943 struct objfile
*objfile
)
2945 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
2947 subpst
->section_offsets
= pst
->section_offsets
;
2948 subpst
->textlow
= 0;
2949 subpst
->texthigh
= 0;
2951 subpst
->dependencies
= (struct partial_symtab
**)
2952 obstack_alloc (&objfile
->objfile_obstack
,
2953 sizeof (struct partial_symtab
*));
2954 subpst
->dependencies
[0] = pst
;
2955 subpst
->number_of_dependencies
= 1;
2957 subpst
->globals_offset
= 0;
2958 subpst
->n_global_syms
= 0;
2959 subpst
->statics_offset
= 0;
2960 subpst
->n_static_syms
= 0;
2961 subpst
->symtab
= NULL
;
2962 subpst
->read_symtab
= pst
->read_symtab
;
2965 /* No private part is necessary for include psymtabs. This property
2966 can be used to differentiate between such include psymtabs and
2967 the regular ones. */
2968 subpst
->read_symtab_private
= NULL
;
2971 /* Read the Line Number Program data and extract the list of files
2972 included by the source file represented by PST. Build an include
2973 partial symtab for each of these included files. */
2976 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
2977 struct die_info
*die
,
2978 struct partial_symtab
*pst
)
2980 struct objfile
*objfile
= cu
->objfile
;
2981 bfd
*abfd
= objfile
->obfd
;
2982 struct line_header
*lh
= NULL
;
2983 struct attribute
*attr
;
2985 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2988 unsigned int line_offset
= DW_UNSND (attr
);
2990 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2993 return; /* No linetable, so no includes. */
2995 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
2996 dwarf_decode_lines (lh
, pst
->dirname
, abfd
, cu
, pst
);
2998 free_line_header (lh
);
3002 hash_type_signature (const void *item
)
3004 const struct signatured_type
*type_sig
= item
;
3006 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3007 return type_sig
->signature
;
3011 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
3013 const struct signatured_type
*lhs
= item_lhs
;
3014 const struct signatured_type
*rhs
= item_rhs
;
3016 return lhs
->signature
== rhs
->signature
;
3019 /* Allocate a hash table for signatured types. */
3022 allocate_signatured_type_table (struct objfile
*objfile
)
3024 return htab_create_alloc_ex (41,
3025 hash_type_signature
,
3028 &objfile
->objfile_obstack
,
3029 hashtab_obstack_allocate
,
3030 dummy_obstack_deallocate
);
3033 /* A helper function to add a signatured type CU to a list. */
3036 add_signatured_type_cu_to_list (void **slot
, void *datum
)
3038 struct signatured_type
*sigt
= *slot
;
3039 struct dwarf2_per_cu_data
***datap
= datum
;
3041 **datap
= &sigt
->per_cu
;
3047 /* Create the hash table of all entries in the .debug_types section.
3048 The result is zero if there is an error (e.g. missing .debug_types section),
3049 otherwise non-zero. */
3052 create_debug_types_hash_table (struct objfile
*objfile
)
3056 struct dwarf2_per_cu_data
**iter
;
3058 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
3059 info_ptr
= dwarf2_per_objfile
->types
.buffer
;
3061 if (info_ptr
== NULL
)
3063 dwarf2_per_objfile
->signatured_types
= NULL
;
3067 types_htab
= allocate_signatured_type_table (objfile
);
3069 if (dwarf2_die_debug
)
3070 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
3072 while (info_ptr
< dwarf2_per_objfile
->types
.buffer
3073 + dwarf2_per_objfile
->types
.size
)
3075 unsigned int offset
;
3076 unsigned int offset_size
;
3077 unsigned int type_offset
;
3078 unsigned int length
, initial_length_size
;
3079 unsigned short version
;
3081 struct signatured_type
*type_sig
;
3083 gdb_byte
*ptr
= info_ptr
;
3085 offset
= ptr
- dwarf2_per_objfile
->types
.buffer
;
3087 /* We need to read the type's signature in order to build the hash
3088 table, but we don't need to read anything else just yet. */
3090 /* Sanity check to ensure entire cu is present. */
3091 length
= read_initial_length (objfile
->obfd
, ptr
, &initial_length_size
);
3092 if (ptr
+ length
+ initial_length_size
3093 > dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
3095 complaint (&symfile_complaints
,
3096 _("debug type entry runs off end "
3097 "of `.debug_types' section, ignored"));
3101 offset_size
= initial_length_size
== 4 ? 4 : 8;
3102 ptr
+= initial_length_size
;
3103 version
= bfd_get_16 (objfile
->obfd
, ptr
);
3105 ptr
+= offset_size
; /* abbrev offset */
3106 ptr
+= 1; /* address size */
3107 signature
= bfd_get_64 (objfile
->obfd
, ptr
);
3109 type_offset
= read_offset_1 (objfile
->obfd
, ptr
, offset_size
);
3111 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
3112 memset (type_sig
, 0, sizeof (*type_sig
));
3113 type_sig
->signature
= signature
;
3114 type_sig
->type_offset
= type_offset
;
3115 type_sig
->per_cu
.objfile
= objfile
;
3116 type_sig
->per_cu
.from_debug_types
= 1;
3117 type_sig
->per_cu
.offset
= offset
;
3119 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
3120 gdb_assert (slot
!= NULL
);
3123 const struct signatured_type
*dup_sig
= *slot
;
3125 complaint (&symfile_complaints
,
3126 _("debug type entry at offset 0x%x is duplicate to the "
3127 "entry at offset 0x%x, signature 0x%s"),
3128 offset
, dup_sig
->per_cu
.offset
,
3129 phex (signature
, sizeof (signature
)));
3130 gdb_assert (signature
== dup_sig
->signature
);
3134 if (dwarf2_die_debug
)
3135 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3136 offset
, phex (signature
, sizeof (signature
)));
3138 info_ptr
= info_ptr
+ initial_length_size
+ length
;
3141 dwarf2_per_objfile
->signatured_types
= types_htab
;
3143 dwarf2_per_objfile
->n_type_comp_units
= htab_elements (types_htab
);
3144 dwarf2_per_objfile
->type_comp_units
3145 = obstack_alloc (&objfile
->objfile_obstack
,
3146 dwarf2_per_objfile
->n_type_comp_units
3147 * sizeof (struct dwarf2_per_cu_data
*));
3148 iter
= &dwarf2_per_objfile
->type_comp_units
[0];
3149 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_list
, &iter
);
3150 gdb_assert (iter
- &dwarf2_per_objfile
->type_comp_units
[0]
3151 == dwarf2_per_objfile
->n_type_comp_units
);
3156 /* Lookup a signature based type.
3157 Returns NULL if SIG is not present in the table. */
3159 static struct signatured_type
*
3160 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
3162 struct signatured_type find_entry
, *entry
;
3164 if (dwarf2_per_objfile
->signatured_types
== NULL
)
3166 complaint (&symfile_complaints
,
3167 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3171 find_entry
.signature
= sig
;
3172 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
3176 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3179 init_cu_die_reader (struct die_reader_specs
*reader
,
3180 struct dwarf2_cu
*cu
)
3182 reader
->abfd
= cu
->objfile
->obfd
;
3184 if (cu
->per_cu
->from_debug_types
)
3186 gdb_assert (dwarf2_per_objfile
->types
.readin
);
3187 reader
->buffer
= dwarf2_per_objfile
->types
.buffer
;
3191 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3192 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
3196 /* Find the base address of the compilation unit for range lists and
3197 location lists. It will normally be specified by DW_AT_low_pc.
3198 In DWARF-3 draft 4, the base address could be overridden by
3199 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3200 compilation units with discontinuous ranges. */
3203 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3205 struct attribute
*attr
;
3208 cu
->base_address
= 0;
3210 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3213 cu
->base_address
= DW_ADDR (attr
);
3218 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3221 cu
->base_address
= DW_ADDR (attr
);
3227 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
3228 to combine the common parts.
3229 Process a compilation unit for a psymtab.
3230 BUFFER is a pointer to the beginning of the dwarf section buffer,
3231 either .debug_info or debug_types.
3232 INFO_PTR is a pointer to the start of the CU.
3233 Returns a pointer to the next CU. */
3236 process_psymtab_comp_unit (struct objfile
*objfile
,
3237 struct dwarf2_per_cu_data
*this_cu
,
3238 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
3239 unsigned int buffer_size
)
3241 bfd
*abfd
= objfile
->obfd
;
3242 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3243 struct die_info
*comp_unit_die
;
3244 struct partial_symtab
*pst
;
3246 struct cleanup
*back_to_inner
;
3247 struct dwarf2_cu cu
;
3248 int has_children
, has_pc_info
;
3249 struct attribute
*attr
;
3250 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
3251 struct die_reader_specs reader_specs
;
3252 const char *filename
;
3254 init_one_comp_unit (&cu
, objfile
);
3255 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
3257 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
3258 buffer
, buffer_size
,
3261 /* Complete the cu_header. */
3262 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
3263 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3265 cu
.list_in_scope
= &file_symbols
;
3267 /* If this compilation unit was already read in, free the
3268 cached copy in order to read it in again. This is
3269 necessary because we skipped some symbols when we first
3270 read in the compilation unit (see load_partial_dies).
3271 This problem could be avoided, but the benefit is
3273 if (this_cu
->cu
!= NULL
)
3274 free_one_cached_comp_unit (this_cu
->cu
);
3276 /* Note that this is a pointer to our stack frame, being
3277 added to a global data structure. It will be cleaned up
3278 in free_stack_comp_unit when we finish with this
3279 compilation unit. */
3281 cu
.per_cu
= this_cu
;
3283 /* Read the abbrevs for this compilation unit into a table. */
3284 dwarf2_read_abbrevs (abfd
, &cu
);
3285 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
3287 /* Read the compilation unit die. */
3288 if (this_cu
->from_debug_types
)
3289 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
3290 init_cu_die_reader (&reader_specs
, &cu
);
3291 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3294 if (this_cu
->from_debug_types
)
3296 /* LENGTH has not been set yet for type units. */
3297 gdb_assert (this_cu
->offset
== cu
.header
.offset
);
3298 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
3300 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3302 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3303 + cu
.header
.initial_length_size
);
3304 do_cleanups (back_to_inner
);
3308 prepare_one_comp_unit (&cu
, comp_unit_die
);
3310 /* Allocate a new partial symbol table structure. */
3311 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
3312 if (attr
== NULL
|| !DW_STRING (attr
))
3315 filename
= DW_STRING (attr
);
3316 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
3318 /* TEXTLOW and TEXTHIGH are set below. */
3320 objfile
->global_psymbols
.next
,
3321 objfile
->static_psymbols
.next
);
3323 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
3325 pst
->dirname
= DW_STRING (attr
);
3327 pst
->read_symtab_private
= this_cu
;
3329 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3331 /* Store the function that reads in the rest of the symbol table. */
3332 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
3334 this_cu
->v
.psymtab
= pst
;
3336 dwarf2_find_base_address (comp_unit_die
, &cu
);
3338 /* Possibly set the default values of LOWPC and HIGHPC from
3340 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
3341 &best_highpc
, &cu
, pst
);
3342 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
3343 /* Store the contiguous range if it is not empty; it can be empty for
3344 CUs with no code. */
3345 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3346 best_lowpc
+ baseaddr
,
3347 best_highpc
+ baseaddr
- 1, pst
);
3349 /* Check if comp unit has_children.
3350 If so, read the rest of the partial symbols from this comp unit.
3351 If not, there's no more debug_info for this comp unit. */
3354 struct partial_die_info
*first_die
;
3355 CORE_ADDR lowpc
, highpc
;
3357 lowpc
= ((CORE_ADDR
) -1);
3358 highpc
= ((CORE_ADDR
) 0);
3360 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
3362 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
3363 ! has_pc_info
, &cu
);
3365 /* If we didn't find a lowpc, set it to highpc to avoid
3366 complaints from `maint check'. */
3367 if (lowpc
== ((CORE_ADDR
) -1))
3370 /* If the compilation unit didn't have an explicit address range,
3371 then use the information extracted from its child dies. */
3375 best_highpc
= highpc
;
3378 pst
->textlow
= best_lowpc
+ baseaddr
;
3379 pst
->texthigh
= best_highpc
+ baseaddr
;
3381 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
3382 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
3383 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
3384 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
3385 sort_pst_symbols (pst
);
3387 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3388 + cu
.header
.initial_length_size
);
3390 if (this_cu
->from_debug_types
)
3392 /* It's not clear we want to do anything with stmt lists here.
3393 Waiting to see what gcc ultimately does. */
3397 /* Get the list of files included in the current compilation unit,
3398 and build a psymtab for each of them. */
3399 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
3402 do_cleanups (back_to_inner
);
3407 /* Traversal function for htab_traverse_noresize.
3408 Process one .debug_types comp-unit. */
3411 process_type_comp_unit (void **slot
, void *info
)
3413 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
3414 struct objfile
*objfile
= (struct objfile
*) info
;
3415 struct dwarf2_per_cu_data
*this_cu
;
3417 this_cu
= &entry
->per_cu
;
3419 gdb_assert (dwarf2_per_objfile
->types
.readin
);
3420 process_psymtab_comp_unit (objfile
, this_cu
,
3421 dwarf2_per_objfile
->types
.buffer
,
3422 dwarf2_per_objfile
->types
.buffer
+ this_cu
->offset
,
3423 dwarf2_per_objfile
->types
.size
);
3428 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3429 Build partial symbol tables for the .debug_types comp-units. */
3432 build_type_psymtabs (struct objfile
*objfile
)
3434 if (! create_debug_types_hash_table (objfile
))
3437 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
3438 process_type_comp_unit
, objfile
);
3441 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3444 psymtabs_addrmap_cleanup (void *o
)
3446 struct objfile
*objfile
= o
;
3448 objfile
->psymtabs_addrmap
= NULL
;
3451 /* Build the partial symbol table by doing a quick pass through the
3452 .debug_info and .debug_abbrev sections. */
3455 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
3458 struct cleanup
*back_to
, *addrmap_cleanup
;
3459 struct obstack temp_obstack
;
3461 dwarf2_per_objfile
->reading_partial_symbols
= 1;
3463 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3464 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3466 /* Any cached compilation units will be linked by the per-objfile
3467 read_in_chain. Make sure to free them when we're done. */
3468 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
3470 build_type_psymtabs (objfile
);
3472 create_all_comp_units (objfile
);
3474 /* Create a temporary address map on a temporary obstack. We later
3475 copy this to the final obstack. */
3476 obstack_init (&temp_obstack
);
3477 make_cleanup_obstack_free (&temp_obstack
);
3478 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
3479 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
3481 /* Since the objects we're extracting from .debug_info vary in
3482 length, only the individual functions to extract them (like
3483 read_comp_unit_head and load_partial_die) can really know whether
3484 the buffer is large enough to hold another complete object.
3486 At the moment, they don't actually check that. If .debug_info
3487 holds just one extra byte after the last compilation unit's dies,
3488 then read_comp_unit_head will happily read off the end of the
3489 buffer. read_partial_die is similarly casual. Those functions
3492 For this loop condition, simply checking whether there's any data
3493 left at all should be sufficient. */
3495 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
3496 + dwarf2_per_objfile
->info
.size
))
3498 struct dwarf2_per_cu_data
*this_cu
;
3500 this_cu
= dwarf2_find_comp_unit (info_ptr
3501 - dwarf2_per_objfile
->info
.buffer
,
3504 info_ptr
= process_psymtab_comp_unit (objfile
, this_cu
,
3505 dwarf2_per_objfile
->info
.buffer
,
3507 dwarf2_per_objfile
->info
.size
);
3510 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
3511 &objfile
->objfile_obstack
);
3512 discard_cleanups (addrmap_cleanup
);
3514 do_cleanups (back_to
);
3517 /* Load the partial DIEs for a secondary CU into memory. */
3520 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
3521 struct objfile
*objfile
)
3523 bfd
*abfd
= objfile
->obfd
;
3524 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
3525 struct die_info
*comp_unit_die
;
3526 struct dwarf2_cu
*cu
;
3527 struct cleanup
*free_abbrevs_cleanup
, *free_cu_cleanup
= NULL
;
3529 struct die_reader_specs reader_specs
;
3532 gdb_assert (! this_cu
->from_debug_types
);
3534 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3535 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
3536 beg_of_comp_unit
= info_ptr
;
3538 if (this_cu
->cu
== NULL
)
3540 cu
= xmalloc (sizeof (*cu
));
3541 init_one_comp_unit (cu
, objfile
);
3545 /* If an error occurs while loading, release our storage. */
3546 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
3548 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
,
3549 dwarf2_per_objfile
->info
.buffer
,
3550 dwarf2_per_objfile
->info
.size
,
3553 /* Complete the cu_header. */
3554 cu
->header
.offset
= this_cu
->offset
;
3555 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3557 /* Link this compilation unit into the compilation unit tree. */
3559 cu
->per_cu
= this_cu
;
3561 /* Link this CU into read_in_chain. */
3562 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3563 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3568 info_ptr
+= cu
->header
.first_die_offset
;
3571 /* Read the abbrevs for this compilation unit into a table. */
3572 gdb_assert (cu
->dwarf2_abbrevs
== NULL
);
3573 dwarf2_read_abbrevs (abfd
, cu
);
3574 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3576 /* Read the compilation unit die. */
3577 init_cu_die_reader (&reader_specs
, cu
);
3578 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3581 prepare_one_comp_unit (cu
, comp_unit_die
);
3583 /* Check if comp unit has_children.
3584 If so, read the rest of the partial symbols from this comp unit.
3585 If not, there's no more debug_info for this comp unit. */
3587 load_partial_dies (abfd
, dwarf2_per_objfile
->info
.buffer
, info_ptr
, 0, cu
);
3589 do_cleanups (free_abbrevs_cleanup
);
3593 /* We've successfully allocated this compilation unit. Let our
3594 caller clean it up when finished with it. */
3595 discard_cleanups (free_cu_cleanup
);
3599 /* Create a list of all compilation units in OBJFILE. We do this only
3600 if an inter-comp-unit reference is found; presumably if there is one,
3601 there will be many, and one will occur early in the .debug_info section.
3602 So there's no point in building this list incrementally. */
3605 create_all_comp_units (struct objfile
*objfile
)
3609 struct dwarf2_per_cu_data
**all_comp_units
;
3612 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3613 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3617 all_comp_units
= xmalloc (n_allocated
3618 * sizeof (struct dwarf2_per_cu_data
*));
3620 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
3621 + dwarf2_per_objfile
->info
.size
)
3623 unsigned int length
, initial_length_size
;
3624 struct dwarf2_per_cu_data
*this_cu
;
3625 unsigned int offset
;
3627 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
3629 /* Read just enough information to find out where the next
3630 compilation unit is. */
3631 length
= read_initial_length (objfile
->obfd
, info_ptr
,
3632 &initial_length_size
);
3634 /* Save the compilation unit for later lookup. */
3635 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
3636 sizeof (struct dwarf2_per_cu_data
));
3637 memset (this_cu
, 0, sizeof (*this_cu
));
3638 this_cu
->offset
= offset
;
3639 this_cu
->length
= length
+ initial_length_size
;
3640 this_cu
->objfile
= objfile
;
3642 if (n_comp_units
== n_allocated
)
3645 all_comp_units
= xrealloc (all_comp_units
,
3647 * sizeof (struct dwarf2_per_cu_data
*));
3649 all_comp_units
[n_comp_units
++] = this_cu
;
3651 info_ptr
= info_ptr
+ this_cu
->length
;
3654 dwarf2_per_objfile
->all_comp_units
3655 = obstack_alloc (&objfile
->objfile_obstack
,
3656 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3657 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
3658 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3659 xfree (all_comp_units
);
3660 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
3663 /* Process all loaded DIEs for compilation unit CU, starting at
3664 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3665 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3666 DW_AT_ranges). If NEED_PC is set, then this function will set
3667 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3668 and record the covered ranges in the addrmap. */
3671 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
3672 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3674 struct partial_die_info
*pdi
;
3676 /* Now, march along the PDI's, descending into ones which have
3677 interesting children but skipping the children of the other ones,
3678 until we reach the end of the compilation unit. */
3684 fixup_partial_die (pdi
, cu
);
3686 /* Anonymous namespaces or modules have no name but have interesting
3687 children, so we need to look at them. Ditto for anonymous
3690 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
3691 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
3695 case DW_TAG_subprogram
:
3696 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3698 case DW_TAG_constant
:
3699 case DW_TAG_variable
:
3700 case DW_TAG_typedef
:
3701 case DW_TAG_union_type
:
3702 if (!pdi
->is_declaration
)
3704 add_partial_symbol (pdi
, cu
);
3707 case DW_TAG_class_type
:
3708 case DW_TAG_interface_type
:
3709 case DW_TAG_structure_type
:
3710 if (!pdi
->is_declaration
)
3712 add_partial_symbol (pdi
, cu
);
3715 case DW_TAG_enumeration_type
:
3716 if (!pdi
->is_declaration
)
3717 add_partial_enumeration (pdi
, cu
);
3719 case DW_TAG_base_type
:
3720 case DW_TAG_subrange_type
:
3721 /* File scope base type definitions are added to the partial
3723 add_partial_symbol (pdi
, cu
);
3725 case DW_TAG_namespace
:
3726 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
3729 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
3736 /* If the die has a sibling, skip to the sibling. */
3738 pdi
= pdi
->die_sibling
;
3742 /* Functions used to compute the fully scoped name of a partial DIE.
3744 Normally, this is simple. For C++, the parent DIE's fully scoped
3745 name is concatenated with "::" and the partial DIE's name. For
3746 Java, the same thing occurs except that "." is used instead of "::".
3747 Enumerators are an exception; they use the scope of their parent
3748 enumeration type, i.e. the name of the enumeration type is not
3749 prepended to the enumerator.
3751 There are two complexities. One is DW_AT_specification; in this
3752 case "parent" means the parent of the target of the specification,
3753 instead of the direct parent of the DIE. The other is compilers
3754 which do not emit DW_TAG_namespace; in this case we try to guess
3755 the fully qualified name of structure types from their members'
3756 linkage names. This must be done using the DIE's children rather
3757 than the children of any DW_AT_specification target. We only need
3758 to do this for structures at the top level, i.e. if the target of
3759 any DW_AT_specification (if any; otherwise the DIE itself) does not
3762 /* Compute the scope prefix associated with PDI's parent, in
3763 compilation unit CU. The result will be allocated on CU's
3764 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3765 field. NULL is returned if no prefix is necessary. */
3767 partial_die_parent_scope (struct partial_die_info
*pdi
,
3768 struct dwarf2_cu
*cu
)
3770 char *grandparent_scope
;
3771 struct partial_die_info
*parent
, *real_pdi
;
3773 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3774 then this means the parent of the specification DIE. */
3777 while (real_pdi
->has_specification
)
3778 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3780 parent
= real_pdi
->die_parent
;
3784 if (parent
->scope_set
)
3785 return parent
->scope
;
3787 fixup_partial_die (parent
, cu
);
3789 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
3791 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3792 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3793 Work around this problem here. */
3794 if (cu
->language
== language_cplus
3795 && parent
->tag
== DW_TAG_namespace
3796 && strcmp (parent
->name
, "::") == 0
3797 && grandparent_scope
== NULL
)
3799 parent
->scope
= NULL
;
3800 parent
->scope_set
= 1;
3804 if (parent
->tag
== DW_TAG_namespace
3805 || parent
->tag
== DW_TAG_module
3806 || parent
->tag
== DW_TAG_structure_type
3807 || parent
->tag
== DW_TAG_class_type
3808 || parent
->tag
== DW_TAG_interface_type
3809 || parent
->tag
== DW_TAG_union_type
3810 || parent
->tag
== DW_TAG_enumeration_type
)
3812 if (grandparent_scope
== NULL
)
3813 parent
->scope
= parent
->name
;
3815 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
3817 parent
->name
, 0, cu
);
3819 else if (parent
->tag
== DW_TAG_enumerator
)
3820 /* Enumerators should not get the name of the enumeration as a prefix. */
3821 parent
->scope
= grandparent_scope
;
3824 /* FIXME drow/2004-04-01: What should we be doing with
3825 function-local names? For partial symbols, we should probably be
3827 complaint (&symfile_complaints
,
3828 _("unhandled containing DIE tag %d for DIE at %d"),
3829 parent
->tag
, pdi
->offset
);
3830 parent
->scope
= grandparent_scope
;
3833 parent
->scope_set
= 1;
3834 return parent
->scope
;
3837 /* Return the fully scoped name associated with PDI, from compilation unit
3838 CU. The result will be allocated with malloc. */
3840 partial_die_full_name (struct partial_die_info
*pdi
,
3841 struct dwarf2_cu
*cu
)
3845 /* If this is a template instantiation, we can not work out the
3846 template arguments from partial DIEs. So, unfortunately, we have
3847 to go through the full DIEs. At least any work we do building
3848 types here will be reused if full symbols are loaded later. */
3849 if (pdi
->has_template_arguments
)
3851 fixup_partial_die (pdi
, cu
);
3853 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
3855 struct die_info
*die
;
3856 struct attribute attr
;
3857 struct dwarf2_cu
*ref_cu
= cu
;
3860 attr
.form
= DW_FORM_ref_addr
;
3861 attr
.u
.addr
= pdi
->offset
;
3862 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
3864 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
3868 parent_scope
= partial_die_parent_scope (pdi
, cu
);
3869 if (parent_scope
== NULL
)
3872 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
3876 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
3878 struct objfile
*objfile
= cu
->objfile
;
3880 char *actual_name
= NULL
;
3881 const struct partial_symbol
*psym
= NULL
;
3883 int built_actual_name
= 0;
3885 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3887 actual_name
= partial_die_full_name (pdi
, cu
);
3889 built_actual_name
= 1;
3891 if (actual_name
== NULL
)
3892 actual_name
= pdi
->name
;
3896 case DW_TAG_subprogram
:
3897 if (pdi
->is_external
|| cu
->language
== language_ada
)
3899 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
3900 of the global scope. But in Ada, we want to be able to access
3901 nested procedures globally. So all Ada subprograms are stored
3902 in the global scope. */
3903 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3904 mst_text, objfile); */
3905 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3907 VAR_DOMAIN
, LOC_BLOCK
,
3908 &objfile
->global_psymbols
,
3909 0, pdi
->lowpc
+ baseaddr
,
3910 cu
->language
, objfile
);
3914 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3915 mst_file_text, objfile); */
3916 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3918 VAR_DOMAIN
, LOC_BLOCK
,
3919 &objfile
->static_psymbols
,
3920 0, pdi
->lowpc
+ baseaddr
,
3921 cu
->language
, objfile
);
3924 case DW_TAG_constant
:
3926 struct psymbol_allocation_list
*list
;
3928 if (pdi
->is_external
)
3929 list
= &objfile
->global_psymbols
;
3931 list
= &objfile
->static_psymbols
;
3932 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3933 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
3934 list
, 0, 0, cu
->language
, objfile
);
3937 case DW_TAG_variable
:
3939 addr
= decode_locdesc (pdi
->locdesc
, cu
);
3943 && !dwarf2_per_objfile
->has_section_at_zero
)
3945 /* A global or static variable may also have been stripped
3946 out by the linker if unused, in which case its address
3947 will be nullified; do not add such variables into partial
3948 symbol table then. */
3950 else if (pdi
->is_external
)
3953 Don't enter into the minimal symbol tables as there is
3954 a minimal symbol table entry from the ELF symbols already.
3955 Enter into partial symbol table if it has a location
3956 descriptor or a type.
3957 If the location descriptor is missing, new_symbol will create
3958 a LOC_UNRESOLVED symbol, the address of the variable will then
3959 be determined from the minimal symbol table whenever the variable
3961 The address for the partial symbol table entry is not
3962 used by GDB, but it comes in handy for debugging partial symbol
3965 if (pdi
->locdesc
|| pdi
->has_type
)
3966 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3968 VAR_DOMAIN
, LOC_STATIC
,
3969 &objfile
->global_psymbols
,
3971 cu
->language
, objfile
);
3975 /* Static Variable. Skip symbols without location descriptors. */
3976 if (pdi
->locdesc
== NULL
)
3978 if (built_actual_name
)
3979 xfree (actual_name
);
3982 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
3983 mst_file_data, objfile); */
3984 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3986 VAR_DOMAIN
, LOC_STATIC
,
3987 &objfile
->static_psymbols
,
3989 cu
->language
, objfile
);
3992 case DW_TAG_typedef
:
3993 case DW_TAG_base_type
:
3994 case DW_TAG_subrange_type
:
3995 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3997 VAR_DOMAIN
, LOC_TYPEDEF
,
3998 &objfile
->static_psymbols
,
3999 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4001 case DW_TAG_namespace
:
4002 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4004 VAR_DOMAIN
, LOC_TYPEDEF
,
4005 &objfile
->global_psymbols
,
4006 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4008 case DW_TAG_class_type
:
4009 case DW_TAG_interface_type
:
4010 case DW_TAG_structure_type
:
4011 case DW_TAG_union_type
:
4012 case DW_TAG_enumeration_type
:
4013 /* Skip external references. The DWARF standard says in the section
4014 about "Structure, Union, and Class Type Entries": "An incomplete
4015 structure, union or class type is represented by a structure,
4016 union or class entry that does not have a byte size attribute
4017 and that has a DW_AT_declaration attribute." */
4018 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
4020 if (built_actual_name
)
4021 xfree (actual_name
);
4025 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
4026 static vs. global. */
4027 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4029 STRUCT_DOMAIN
, LOC_TYPEDEF
,
4030 (cu
->language
== language_cplus
4031 || cu
->language
== language_java
)
4032 ? &objfile
->global_psymbols
4033 : &objfile
->static_psymbols
,
4034 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4037 case DW_TAG_enumerator
:
4038 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4040 VAR_DOMAIN
, LOC_CONST
,
4041 (cu
->language
== language_cplus
4042 || cu
->language
== language_java
)
4043 ? &objfile
->global_psymbols
4044 : &objfile
->static_psymbols
,
4045 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4051 if (built_actual_name
)
4052 xfree (actual_name
);
4055 /* Read a partial die corresponding to a namespace; also, add a symbol
4056 corresponding to that namespace to the symbol table. NAMESPACE is
4057 the name of the enclosing namespace. */
4060 add_partial_namespace (struct partial_die_info
*pdi
,
4061 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4062 int need_pc
, struct dwarf2_cu
*cu
)
4064 /* Add a symbol for the namespace. */
4066 add_partial_symbol (pdi
, cu
);
4068 /* Now scan partial symbols in that namespace. */
4070 if (pdi
->has_children
)
4071 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4074 /* Read a partial die corresponding to a Fortran module. */
4077 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
4078 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4080 /* Now scan partial symbols in that module. */
4082 if (pdi
->has_children
)
4083 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4086 /* Read a partial die corresponding to a subprogram and create a partial
4087 symbol for that subprogram. When the CU language allows it, this
4088 routine also defines a partial symbol for each nested subprogram
4089 that this subprogram contains.
4091 DIE my also be a lexical block, in which case we simply search
4092 recursively for suprograms defined inside that lexical block.
4093 Again, this is only performed when the CU language allows this
4094 type of definitions. */
4097 add_partial_subprogram (struct partial_die_info
*pdi
,
4098 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4099 int need_pc
, struct dwarf2_cu
*cu
)
4101 if (pdi
->tag
== DW_TAG_subprogram
)
4103 if (pdi
->has_pc_info
)
4105 if (pdi
->lowpc
< *lowpc
)
4106 *lowpc
= pdi
->lowpc
;
4107 if (pdi
->highpc
> *highpc
)
4108 *highpc
= pdi
->highpc
;
4112 struct objfile
*objfile
= cu
->objfile
;
4114 baseaddr
= ANOFFSET (objfile
->section_offsets
,
4115 SECT_OFF_TEXT (objfile
));
4116 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4117 pdi
->lowpc
+ baseaddr
,
4118 pdi
->highpc
- 1 + baseaddr
,
4119 cu
->per_cu
->v
.psymtab
);
4121 if (!pdi
->is_declaration
)
4122 /* Ignore subprogram DIEs that do not have a name, they are
4123 illegal. Do not emit a complaint at this point, we will
4124 do so when we convert this psymtab into a symtab. */
4126 add_partial_symbol (pdi
, cu
);
4130 if (! pdi
->has_children
)
4133 if (cu
->language
== language_ada
)
4135 pdi
= pdi
->die_child
;
4138 fixup_partial_die (pdi
, cu
);
4139 if (pdi
->tag
== DW_TAG_subprogram
4140 || pdi
->tag
== DW_TAG_lexical_block
)
4141 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4142 pdi
= pdi
->die_sibling
;
4147 /* Read a partial die corresponding to an enumeration type. */
4150 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
4151 struct dwarf2_cu
*cu
)
4153 struct partial_die_info
*pdi
;
4155 if (enum_pdi
->name
!= NULL
)
4156 add_partial_symbol (enum_pdi
, cu
);
4158 pdi
= enum_pdi
->die_child
;
4161 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
4162 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
4164 add_partial_symbol (pdi
, cu
);
4165 pdi
= pdi
->die_sibling
;
4169 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4170 Return the corresponding abbrev, or NULL if the number is zero (indicating
4171 an empty DIE). In either case *BYTES_READ will be set to the length of
4172 the initial number. */
4174 static struct abbrev_info
*
4175 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
4176 struct dwarf2_cu
*cu
)
4178 bfd
*abfd
= cu
->objfile
->obfd
;
4179 unsigned int abbrev_number
;
4180 struct abbrev_info
*abbrev
;
4182 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
4184 if (abbrev_number
== 0)
4187 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4190 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4191 abbrev_number
, bfd_get_filename (abfd
));
4197 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4198 Returns a pointer to the end of a series of DIEs, terminated by an empty
4199 DIE. Any children of the skipped DIEs will also be skipped. */
4202 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
4204 struct abbrev_info
*abbrev
;
4205 unsigned int bytes_read
;
4209 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
4211 return info_ptr
+ bytes_read
;
4213 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
4217 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4218 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4219 abbrev corresponding to that skipped uleb128 should be passed in
4220 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4224 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4225 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
4227 unsigned int bytes_read
;
4228 struct attribute attr
;
4229 bfd
*abfd
= cu
->objfile
->obfd
;
4230 unsigned int form
, i
;
4232 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
4234 /* The only abbrev we care about is DW_AT_sibling. */
4235 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
4237 read_attribute (&attr
, &abbrev
->attrs
[i
],
4238 abfd
, info_ptr
, cu
);
4239 if (attr
.form
== DW_FORM_ref_addr
)
4240 complaint (&symfile_complaints
,
4241 _("ignoring absolute DW_AT_sibling"));
4243 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
4246 /* If it isn't DW_AT_sibling, skip this attribute. */
4247 form
= abbrev
->attrs
[i
].form
;
4251 case DW_FORM_ref_addr
:
4252 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4253 and later it is offset sized. */
4254 if (cu
->header
.version
== 2)
4255 info_ptr
+= cu
->header
.addr_size
;
4257 info_ptr
+= cu
->header
.offset_size
;
4260 info_ptr
+= cu
->header
.addr_size
;
4267 case DW_FORM_flag_present
:
4279 case DW_FORM_ref_sig8
:
4282 case DW_FORM_string
:
4283 read_direct_string (abfd
, info_ptr
, &bytes_read
);
4284 info_ptr
+= bytes_read
;
4286 case DW_FORM_sec_offset
:
4288 info_ptr
+= cu
->header
.offset_size
;
4290 case DW_FORM_exprloc
:
4292 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4293 info_ptr
+= bytes_read
;
4295 case DW_FORM_block1
:
4296 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
4298 case DW_FORM_block2
:
4299 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
4301 case DW_FORM_block4
:
4302 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
4306 case DW_FORM_ref_udata
:
4307 info_ptr
= skip_leb128 (abfd
, info_ptr
);
4309 case DW_FORM_indirect
:
4310 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4311 info_ptr
+= bytes_read
;
4312 /* We need to continue parsing from here, so just go back to
4314 goto skip_attribute
;
4317 error (_("Dwarf Error: Cannot handle %s "
4318 "in DWARF reader [in module %s]"),
4319 dwarf_form_name (form
),
4320 bfd_get_filename (abfd
));
4324 if (abbrev
->has_children
)
4325 return skip_children (buffer
, info_ptr
, cu
);
4330 /* Locate ORIG_PDI's sibling.
4331 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4335 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
4336 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4337 bfd
*abfd
, struct dwarf2_cu
*cu
)
4339 /* Do we know the sibling already? */
4341 if (orig_pdi
->sibling
)
4342 return orig_pdi
->sibling
;
4344 /* Are there any children to deal with? */
4346 if (!orig_pdi
->has_children
)
4349 /* Skip the children the long way. */
4351 return skip_children (buffer
, info_ptr
, cu
);
4354 /* Expand this partial symbol table into a full symbol table. */
4357 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
4363 warning (_("bug: psymtab for %s is already read in."),
4370 printf_filtered (_("Reading in symbols for %s..."),
4372 gdb_flush (gdb_stdout
);
4375 /* Restore our global data. */
4376 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
4377 dwarf2_objfile_data_key
);
4379 /* If this psymtab is constructed from a debug-only objfile, the
4380 has_section_at_zero flag will not necessarily be correct. We
4381 can get the correct value for this flag by looking at the data
4382 associated with the (presumably stripped) associated objfile. */
4383 if (pst
->objfile
->separate_debug_objfile_backlink
)
4385 struct dwarf2_per_objfile
*dpo_backlink
4386 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
4387 dwarf2_objfile_data_key
);
4389 dwarf2_per_objfile
->has_section_at_zero
4390 = dpo_backlink
->has_section_at_zero
;
4393 dwarf2_per_objfile
->reading_partial_symbols
= 0;
4395 psymtab_to_symtab_1 (pst
);
4397 /* Finish up the debug error message. */
4399 printf_filtered (_("done.\n"));
4404 /* Add PER_CU to the queue. */
4407 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
4409 struct dwarf2_queue_item
*item
;
4412 item
= xmalloc (sizeof (*item
));
4413 item
->per_cu
= per_cu
;
4416 if (dwarf2_queue
== NULL
)
4417 dwarf2_queue
= item
;
4419 dwarf2_queue_tail
->next
= item
;
4421 dwarf2_queue_tail
= item
;
4424 /* Process the queue. */
4427 process_queue (struct objfile
*objfile
)
4429 struct dwarf2_queue_item
*item
, *next_item
;
4431 /* The queue starts out with one item, but following a DIE reference
4432 may load a new CU, adding it to the end of the queue. */
4433 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
4435 if (dwarf2_per_objfile
->using_index
4436 ? !item
->per_cu
->v
.quick
->symtab
4437 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
4438 process_full_comp_unit (item
->per_cu
);
4440 item
->per_cu
->queued
= 0;
4441 next_item
= item
->next
;
4445 dwarf2_queue_tail
= NULL
;
4448 /* Free all allocated queue entries. This function only releases anything if
4449 an error was thrown; if the queue was processed then it would have been
4450 freed as we went along. */
4453 dwarf2_release_queue (void *dummy
)
4455 struct dwarf2_queue_item
*item
, *last
;
4457 item
= dwarf2_queue
;
4460 /* Anything still marked queued is likely to be in an
4461 inconsistent state, so discard it. */
4462 if (item
->per_cu
->queued
)
4464 if (item
->per_cu
->cu
!= NULL
)
4465 free_one_cached_comp_unit (item
->per_cu
->cu
);
4466 item
->per_cu
->queued
= 0;
4474 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
4477 /* Read in full symbols for PST, and anything it depends on. */
4480 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
4482 struct dwarf2_per_cu_data
*per_cu
;
4483 struct cleanup
*back_to
;
4486 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
4487 if (!pst
->dependencies
[i
]->readin
)
4489 /* Inform about additional files that need to be read in. */
4492 /* FIXME: i18n: Need to make this a single string. */
4493 fputs_filtered (" ", gdb_stdout
);
4495 fputs_filtered ("and ", gdb_stdout
);
4497 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
4498 wrap_here (""); /* Flush output. */
4499 gdb_flush (gdb_stdout
);
4501 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
4504 per_cu
= pst
->read_symtab_private
;
4508 /* It's an include file, no symbols to read for it.
4509 Everything is in the parent symtab. */
4514 dw2_do_instantiate_symtab (pst
->objfile
, per_cu
);
4517 /* Load the DIEs associated with PER_CU into memory. */
4520 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
4521 struct objfile
*objfile
)
4523 bfd
*abfd
= objfile
->obfd
;
4524 struct dwarf2_cu
*cu
;
4525 unsigned int offset
;
4526 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
4527 struct cleanup
*free_abbrevs_cleanup
= NULL
, *free_cu_cleanup
= NULL
;
4528 struct attribute
*attr
;
4531 gdb_assert (! per_cu
->from_debug_types
);
4533 /* Set local variables from the partial symbol table info. */
4534 offset
= per_cu
->offset
;
4536 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4537 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
4538 beg_of_comp_unit
= info_ptr
;
4540 if (per_cu
->cu
== NULL
)
4542 cu
= xmalloc (sizeof (*cu
));
4543 init_one_comp_unit (cu
, objfile
);
4547 /* If an error occurs while loading, release our storage. */
4548 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
4550 /* Read in the comp_unit header. */
4551 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
4553 /* Complete the cu_header. */
4554 cu
->header
.offset
= offset
;
4555 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
4557 /* Read the abbrevs for this compilation unit. */
4558 dwarf2_read_abbrevs (abfd
, cu
);
4559 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
4561 /* Link this compilation unit into the compilation unit tree. */
4563 cu
->per_cu
= per_cu
;
4565 /* Link this CU into read_in_chain. */
4566 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4567 dwarf2_per_objfile
->read_in_chain
= per_cu
;
4572 info_ptr
+= cu
->header
.first_die_offset
;
4575 cu
->dies
= read_comp_unit (info_ptr
, cu
);
4577 /* We try not to read any attributes in this function, because not
4578 all objfiles needed for references have been loaded yet, and symbol
4579 table processing isn't initialized. But we have to set the CU language,
4580 or we won't be able to build types correctly. */
4581 prepare_one_comp_unit (cu
, cu
->dies
);
4583 /* Similarly, if we do not read the producer, we can not apply
4584 producer-specific interpretation. */
4585 attr
= dwarf2_attr (cu
->dies
, DW_AT_producer
, cu
);
4587 cu
->producer
= DW_STRING (attr
);
4591 do_cleanups (free_abbrevs_cleanup
);
4593 /* We've successfully allocated this compilation unit. Let our
4594 caller clean it up when finished with it. */
4595 discard_cleanups (free_cu_cleanup
);
4599 /* Add a DIE to the delayed physname list. */
4602 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
4603 const char *name
, struct die_info
*die
,
4604 struct dwarf2_cu
*cu
)
4606 struct delayed_method_info mi
;
4608 mi
.fnfield_index
= fnfield_index
;
4612 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
4615 /* A cleanup for freeing the delayed method list. */
4618 free_delayed_list (void *ptr
)
4620 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
4621 if (cu
->method_list
!= NULL
)
4623 VEC_free (delayed_method_info
, cu
->method_list
);
4624 cu
->method_list
= NULL
;
4628 /* Compute the physnames of any methods on the CU's method list.
4630 The computation of method physnames is delayed in order to avoid the
4631 (bad) condition that one of the method's formal parameters is of an as yet
4635 compute_delayed_physnames (struct dwarf2_cu
*cu
)
4638 struct delayed_method_info
*mi
;
4639 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
4641 const char *physname
;
4642 struct fn_fieldlist
*fn_flp
4643 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
4644 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
4645 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
4649 /* Check for GCC >= 4.x. Return minor version (x) of 4.x in such case. If it
4650 is not GCC or it is GCC older than 4.x return -1. If it is GCC 5.x or
4651 higher return INT_MAX. */
4654 producer_is_gcc_ge_4 (struct dwarf2_cu
*cu
)
4659 if (cu
->producer
== NULL
)
4661 /* For unknown compilers expect their behavior is not compliant. For GCC
4662 this case can also happen for -gdwarf-4 type units supported since
4668 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
4670 if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) != 0)
4672 /* For non-GCC compilers expect their behavior is not compliant. */
4676 cs
= &cu
->producer
[strlen ("GNU ")];
4677 while (*cs
&& !isdigit (*cs
))
4679 if (sscanf (cs
, "%d.%d", &major
, &minor
) != 2)
4681 /* Not recognized as GCC. */
4693 /* Generate full symbol information for PST and CU, whose DIEs have
4694 already been loaded into memory. */
4697 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4699 struct dwarf2_cu
*cu
= per_cu
->cu
;
4700 struct objfile
*objfile
= per_cu
->objfile
;
4701 CORE_ADDR lowpc
, highpc
;
4702 struct symtab
*symtab
;
4703 struct cleanup
*back_to
, *delayed_list_cleanup
;
4706 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4709 back_to
= make_cleanup (really_free_pendings
, NULL
);
4710 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
4712 cu
->list_in_scope
= &file_symbols
;
4714 dwarf2_find_base_address (cu
->dies
, cu
);
4716 /* Do line number decoding in read_file_scope () */
4717 process_die (cu
->dies
, cu
);
4719 /* Now that we have processed all the DIEs in the CU, all the types
4720 should be complete, and it should now be safe to compute all of the
4722 compute_delayed_physnames (cu
);
4723 do_cleanups (delayed_list_cleanup
);
4725 /* Some compilers don't define a DW_AT_high_pc attribute for the
4726 compilation unit. If the DW_AT_high_pc is missing, synthesize
4727 it, by scanning the DIE's below the compilation unit. */
4728 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
4730 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
4734 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
);
4736 /* Set symtab language to language from DW_AT_language. If the
4737 compilation is from a C file generated by language preprocessors, do
4738 not set the language if it was already deduced by start_subfile. */
4739 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
4740 symtab
->language
= cu
->language
;
4742 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
4743 produce DW_AT_location with location lists but it can be possibly
4744 invalid without -fvar-tracking.
4746 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
4747 needed, it would be wrong due to missing DW_AT_producer there.
4749 Still one can confuse GDB by using non-standard GCC compilation
4750 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
4752 if (cu
->has_loclist
&& gcc_4_minor
>= 0)
4753 symtab
->locations_valid
= 1;
4755 if (gcc_4_minor
>= 5)
4756 symtab
->epilogue_unwind_valid
= 1;
4759 if (dwarf2_per_objfile
->using_index
)
4760 per_cu
->v
.quick
->symtab
= symtab
;
4763 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4764 pst
->symtab
= symtab
;
4768 do_cleanups (back_to
);
4771 /* Process a die and its children. */
4774 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
4778 case DW_TAG_padding
:
4780 case DW_TAG_compile_unit
:
4781 read_file_scope (die
, cu
);
4783 case DW_TAG_type_unit
:
4784 read_type_unit_scope (die
, cu
);
4786 case DW_TAG_subprogram
:
4787 case DW_TAG_inlined_subroutine
:
4788 read_func_scope (die
, cu
);
4790 case DW_TAG_lexical_block
:
4791 case DW_TAG_try_block
:
4792 case DW_TAG_catch_block
:
4793 read_lexical_block_scope (die
, cu
);
4795 case DW_TAG_class_type
:
4796 case DW_TAG_interface_type
:
4797 case DW_TAG_structure_type
:
4798 case DW_TAG_union_type
:
4799 process_structure_scope (die
, cu
);
4801 case DW_TAG_enumeration_type
:
4802 process_enumeration_scope (die
, cu
);
4805 /* These dies have a type, but processing them does not create
4806 a symbol or recurse to process the children. Therefore we can
4807 read them on-demand through read_type_die. */
4808 case DW_TAG_subroutine_type
:
4809 case DW_TAG_set_type
:
4810 case DW_TAG_array_type
:
4811 case DW_TAG_pointer_type
:
4812 case DW_TAG_ptr_to_member_type
:
4813 case DW_TAG_reference_type
:
4814 case DW_TAG_string_type
:
4817 case DW_TAG_base_type
:
4818 case DW_TAG_subrange_type
:
4819 case DW_TAG_typedef
:
4820 /* Add a typedef symbol for the type definition, if it has a
4822 new_symbol (die
, read_type_die (die
, cu
), cu
);
4824 case DW_TAG_common_block
:
4825 read_common_block (die
, cu
);
4827 case DW_TAG_common_inclusion
:
4829 case DW_TAG_namespace
:
4830 processing_has_namespace_info
= 1;
4831 read_namespace (die
, cu
);
4834 processing_has_namespace_info
= 1;
4835 read_module (die
, cu
);
4837 case DW_TAG_imported_declaration
:
4838 case DW_TAG_imported_module
:
4839 processing_has_namespace_info
= 1;
4840 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
4841 || cu
->language
!= language_fortran
))
4842 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
4843 dwarf_tag_name (die
->tag
));
4844 read_import_statement (die
, cu
);
4847 new_symbol (die
, NULL
, cu
);
4852 /* A helper function for dwarf2_compute_name which determines whether DIE
4853 needs to have the name of the scope prepended to the name listed in the
4857 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4859 struct attribute
*attr
;
4863 case DW_TAG_namespace
:
4864 case DW_TAG_typedef
:
4865 case DW_TAG_class_type
:
4866 case DW_TAG_interface_type
:
4867 case DW_TAG_structure_type
:
4868 case DW_TAG_union_type
:
4869 case DW_TAG_enumeration_type
:
4870 case DW_TAG_enumerator
:
4871 case DW_TAG_subprogram
:
4875 case DW_TAG_variable
:
4876 case DW_TAG_constant
:
4877 /* We only need to prefix "globally" visible variables. These include
4878 any variable marked with DW_AT_external or any variable that
4879 lives in a namespace. [Variables in anonymous namespaces
4880 require prefixing, but they are not DW_AT_external.] */
4882 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
4884 struct dwarf2_cu
*spec_cu
= cu
;
4886 return die_needs_namespace (die_specification (die
, &spec_cu
),
4890 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
4891 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
4892 && die
->parent
->tag
!= DW_TAG_module
)
4894 /* A variable in a lexical block of some kind does not need a
4895 namespace, even though in C++ such variables may be external
4896 and have a mangled name. */
4897 if (die
->parent
->tag
== DW_TAG_lexical_block
4898 || die
->parent
->tag
== DW_TAG_try_block
4899 || die
->parent
->tag
== DW_TAG_catch_block
4900 || die
->parent
->tag
== DW_TAG_subprogram
)
4909 /* Retrieve the last character from a mem_file. */
4912 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
4914 char *last_char_p
= (char *) object
;
4917 *last_char_p
= buffer
[length
- 1];
4920 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
4921 compute the physname for the object, which include a method's
4922 formal parameters (C++/Java) and return type (Java).
4924 For Ada, return the DIE's linkage name rather than the fully qualified
4925 name. PHYSNAME is ignored..
4927 The result is allocated on the objfile_obstack and canonicalized. */
4930 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
4934 name
= dwarf2_name (die
, cu
);
4936 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
4937 compute it by typename_concat inside GDB. */
4938 if (cu
->language
== language_ada
4939 || (cu
->language
== language_fortran
&& physname
))
4941 /* For Ada unit, we prefer the linkage name over the name, as
4942 the former contains the exported name, which the user expects
4943 to be able to reference. Ideally, we want the user to be able
4944 to reference this entity using either natural or linkage name,
4945 but we haven't started looking at this enhancement yet. */
4946 struct attribute
*attr
;
4948 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
4950 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
4951 if (attr
&& DW_STRING (attr
))
4952 return DW_STRING (attr
);
4955 /* These are the only languages we know how to qualify names in. */
4957 && (cu
->language
== language_cplus
|| cu
->language
== language_java
4958 || cu
->language
== language_fortran
))
4960 if (die_needs_namespace (die
, cu
))
4964 struct ui_file
*buf
;
4966 prefix
= determine_prefix (die
, cu
);
4967 buf
= mem_fileopen ();
4968 if (*prefix
!= '\0')
4970 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
4973 fputs_unfiltered (prefixed_name
, buf
);
4974 xfree (prefixed_name
);
4977 fputs_unfiltered (name
, buf
);
4979 /* Template parameters may be specified in the DIE's DW_AT_name, or
4980 as children with DW_TAG_template_type_param or
4981 DW_TAG_value_type_param. If the latter, add them to the name
4982 here. If the name already has template parameters, then
4983 skip this step; some versions of GCC emit both, and
4984 it is more efficient to use the pre-computed name.
4986 Something to keep in mind about this process: it is very
4987 unlikely, or in some cases downright impossible, to produce
4988 something that will match the mangled name of a function.
4989 If the definition of the function has the same debug info,
4990 we should be able to match up with it anyway. But fallbacks
4991 using the minimal symbol, for instance to find a method
4992 implemented in a stripped copy of libstdc++, will not work.
4993 If we do not have debug info for the definition, we will have to
4994 match them up some other way.
4996 When we do name matching there is a related problem with function
4997 templates; two instantiated function templates are allowed to
4998 differ only by their return types, which we do not add here. */
5000 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
5002 struct attribute
*attr
;
5003 struct die_info
*child
;
5006 die
->building_fullname
= 1;
5008 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
5013 struct dwarf2_locexpr_baton
*baton
;
5016 if (child
->tag
!= DW_TAG_template_type_param
5017 && child
->tag
!= DW_TAG_template_value_param
)
5022 fputs_unfiltered ("<", buf
);
5026 fputs_unfiltered (", ", buf
);
5028 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
5031 complaint (&symfile_complaints
,
5032 _("template parameter missing DW_AT_type"));
5033 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
5036 type
= die_type (child
, cu
);
5038 if (child
->tag
== DW_TAG_template_type_param
)
5040 c_print_type (type
, "", buf
, -1, 0);
5044 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
5047 complaint (&symfile_complaints
,
5048 _("template parameter missing "
5049 "DW_AT_const_value"));
5050 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
5054 dwarf2_const_value_attr (attr
, type
, name
,
5055 &cu
->comp_unit_obstack
, cu
,
5056 &value
, &bytes
, &baton
);
5058 if (TYPE_NOSIGN (type
))
5059 /* GDB prints characters as NUMBER 'CHAR'. If that's
5060 changed, this can use value_print instead. */
5061 c_printchar (value
, type
, buf
);
5064 struct value_print_options opts
;
5067 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
5071 else if (bytes
!= NULL
)
5073 v
= allocate_value (type
);
5074 memcpy (value_contents_writeable (v
), bytes
,
5075 TYPE_LENGTH (type
));
5078 v
= value_from_longest (type
, value
);
5080 /* Specify decimal so that we do not depend on
5082 get_formatted_print_options (&opts
, 'd');
5084 value_print (v
, buf
, &opts
);
5090 die
->building_fullname
= 0;
5094 /* Close the argument list, with a space if necessary
5095 (nested templates). */
5096 char last_char
= '\0';
5097 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
5098 if (last_char
== '>')
5099 fputs_unfiltered (" >", buf
);
5101 fputs_unfiltered (">", buf
);
5105 /* For Java and C++ methods, append formal parameter type
5106 information, if PHYSNAME. */
5108 if (physname
&& die
->tag
== DW_TAG_subprogram
5109 && (cu
->language
== language_cplus
5110 || cu
->language
== language_java
))
5112 struct type
*type
= read_type_die (die
, cu
);
5114 c_type_print_args (type
, buf
, 1, cu
->language
);
5116 if (cu
->language
== language_java
)
5118 /* For java, we must append the return type to method
5120 if (die
->tag
== DW_TAG_subprogram
)
5121 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
5124 else if (cu
->language
== language_cplus
)
5126 /* Assume that an artificial first parameter is
5127 "this", but do not crash if it is not. RealView
5128 marks unnamed (and thus unused) parameters as
5129 artificial; there is no way to differentiate
5131 if (TYPE_NFIELDS (type
) > 0
5132 && TYPE_FIELD_ARTIFICIAL (type
, 0)
5133 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
5134 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
5136 fputs_unfiltered (" const", buf
);
5140 name
= ui_file_obsavestring (buf
, &cu
->objfile
->objfile_obstack
,
5142 ui_file_delete (buf
);
5144 if (cu
->language
== language_cplus
)
5147 = dwarf2_canonicalize_name (name
, cu
,
5148 &cu
->objfile
->objfile_obstack
);
5159 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5160 If scope qualifiers are appropriate they will be added. The result
5161 will be allocated on the objfile_obstack, or NULL if the DIE does
5162 not have a name. NAME may either be from a previous call to
5163 dwarf2_name or NULL.
5165 The output string will be canonicalized (if C++/Java). */
5168 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5170 return dwarf2_compute_name (name
, die
, cu
, 0);
5173 /* Construct a physname for the given DIE in CU. NAME may either be
5174 from a previous call to dwarf2_name or NULL. The result will be
5175 allocated on the objfile_objstack or NULL if the DIE does not have a
5178 The output string will be canonicalized (if C++/Java). */
5181 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5183 return dwarf2_compute_name (name
, die
, cu
, 1);
5186 /* Read the import statement specified by the given die and record it. */
5189 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
5191 struct attribute
*import_attr
;
5192 struct die_info
*imported_die
, *child_die
;
5193 struct dwarf2_cu
*imported_cu
;
5194 const char *imported_name
;
5195 const char *imported_name_prefix
;
5196 const char *canonical_name
;
5197 const char *import_alias
;
5198 const char *imported_declaration
= NULL
;
5199 const char *import_prefix
;
5200 VEC (const_char_ptr
) *excludes
= NULL
;
5201 struct cleanup
*cleanups
;
5205 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
5206 if (import_attr
== NULL
)
5208 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5209 dwarf_tag_name (die
->tag
));
5214 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
5215 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5216 if (imported_name
== NULL
)
5218 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
5220 The import in the following code:
5234 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
5235 <52> DW_AT_decl_file : 1
5236 <53> DW_AT_decl_line : 6
5237 <54> DW_AT_import : <0x75>
5238 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
5240 <5b> DW_AT_decl_file : 1
5241 <5c> DW_AT_decl_line : 2
5242 <5d> DW_AT_type : <0x6e>
5244 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
5245 <76> DW_AT_byte_size : 4
5246 <77> DW_AT_encoding : 5 (signed)
5248 imports the wrong die ( 0x75 instead of 0x58 ).
5249 This case will be ignored until the gcc bug is fixed. */
5253 /* Figure out the local name after import. */
5254 import_alias
= dwarf2_name (die
, cu
);
5256 /* Figure out where the statement is being imported to. */
5257 import_prefix
= determine_prefix (die
, cu
);
5259 /* Figure out what the scope of the imported die is and prepend it
5260 to the name of the imported die. */
5261 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
5263 if (imported_die
->tag
!= DW_TAG_namespace
5264 && imported_die
->tag
!= DW_TAG_module
)
5266 imported_declaration
= imported_name
;
5267 canonical_name
= imported_name_prefix
;
5269 else if (strlen (imported_name_prefix
) > 0)
5271 temp
= alloca (strlen (imported_name_prefix
)
5272 + 2 + strlen (imported_name
) + 1);
5273 strcpy (temp
, imported_name_prefix
);
5274 strcat (temp
, "::");
5275 strcat (temp
, imported_name
);
5276 canonical_name
= temp
;
5279 canonical_name
= imported_name
;
5281 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
5283 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
5284 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
5285 child_die
= sibling_die (child_die
))
5287 /* DWARF-4: A Fortran use statement with a “rename list” may be
5288 represented by an imported module entry with an import attribute
5289 referring to the module and owned entries corresponding to those
5290 entities that are renamed as part of being imported. */
5292 if (child_die
->tag
!= DW_TAG_imported_declaration
)
5294 complaint (&symfile_complaints
,
5295 _("child DW_TAG_imported_declaration expected "
5296 "- DIE at 0x%x [in module %s]"),
5297 child_die
->offset
, cu
->objfile
->name
);
5301 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
5302 if (import_attr
== NULL
)
5304 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5305 dwarf_tag_name (child_die
->tag
));
5310 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
5312 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5313 if (imported_name
== NULL
)
5315 complaint (&symfile_complaints
,
5316 _("child DW_TAG_imported_declaration has unknown "
5317 "imported name - DIE at 0x%x [in module %s]"),
5318 child_die
->offset
, cu
->objfile
->name
);
5322 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
5324 process_die (child_die
, cu
);
5327 cp_add_using_directive (import_prefix
,
5330 imported_declaration
,
5332 &cu
->objfile
->objfile_obstack
);
5334 do_cleanups (cleanups
);
5338 initialize_cu_func_list (struct dwarf2_cu
*cu
)
5340 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
5343 /* Cleanup function for read_file_scope. */
5346 free_cu_line_header (void *arg
)
5348 struct dwarf2_cu
*cu
= arg
;
5350 free_line_header (cu
->line_header
);
5351 cu
->line_header
= NULL
;
5355 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
5356 char **name
, char **comp_dir
)
5358 struct attribute
*attr
;
5363 /* Find the filename. Do not use dwarf2_name here, since the filename
5364 is not a source language identifier. */
5365 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5368 *name
= DW_STRING (attr
);
5371 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5373 *comp_dir
= DW_STRING (attr
);
5374 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
5376 *comp_dir
= ldirname (*name
);
5377 if (*comp_dir
!= NULL
)
5378 make_cleanup (xfree
, *comp_dir
);
5380 if (*comp_dir
!= NULL
)
5382 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5383 directory, get rid of it. */
5384 char *cp
= strchr (*comp_dir
, ':');
5386 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
5391 *name
= "<unknown>";
5394 /* Process DW_TAG_compile_unit. */
5397 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5399 struct objfile
*objfile
= cu
->objfile
;
5400 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5401 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
5402 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
5403 struct attribute
*attr
;
5405 char *comp_dir
= NULL
;
5406 struct die_info
*child_die
;
5407 bfd
*abfd
= objfile
->obfd
;
5408 struct line_header
*line_header
= 0;
5411 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5413 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
5415 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5416 from finish_block. */
5417 if (lowpc
== ((CORE_ADDR
) -1))
5422 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
5424 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5427 set_cu_language (DW_UNSND (attr
), cu
);
5430 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5432 cu
->producer
= DW_STRING (attr
);
5434 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
5435 standardised yet. As a workaround for the language detection we fall
5436 back to the DW_AT_producer string. */
5437 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
5438 cu
->language
= language_opencl
;
5440 /* We assume that we're processing GCC output. */
5441 processing_gcc_compilation
= 2;
5443 processing_has_namespace_info
= 0;
5445 start_symtab (name
, comp_dir
, lowpc
);
5446 record_debugformat ("DWARF 2");
5447 record_producer (cu
->producer
);
5449 initialize_cu_func_list (cu
);
5451 /* Decode line number information if present. We do this before
5452 processing child DIEs, so that the line header table is available
5453 for DW_AT_decl_file. */
5454 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5457 unsigned int line_offset
= DW_UNSND (attr
);
5458 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
5461 cu
->line_header
= line_header
;
5462 make_cleanup (free_cu_line_header
, cu
);
5463 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
5467 /* Process all dies in compilation unit. */
5468 if (die
->child
!= NULL
)
5470 child_die
= die
->child
;
5471 while (child_die
&& child_die
->tag
)
5473 process_die (child_die
, cu
);
5474 child_die
= sibling_die (child_die
);
5478 /* Decode macro information, if present. Dwarf 2 macro information
5479 refers to information in the line number info statement program
5480 header, so we can only read it if we've read the header
5482 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
5483 if (attr
&& line_header
)
5485 unsigned int macro_offset
= DW_UNSND (attr
);
5487 dwarf_decode_macros (line_header
, macro_offset
,
5488 comp_dir
, abfd
, cu
);
5490 do_cleanups (back_to
);
5493 /* Process DW_TAG_type_unit.
5494 For TUs we want to skip the first top level sibling if it's not the
5495 actual type being defined by this TU. In this case the first top
5496 level sibling is there to provide context only. */
5499 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5501 struct objfile
*objfile
= cu
->objfile
;
5502 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5504 struct attribute
*attr
;
5506 char *comp_dir
= NULL
;
5507 struct die_info
*child_die
;
5508 bfd
*abfd
= objfile
->obfd
;
5510 /* start_symtab needs a low pc, but we don't really have one.
5511 Do what read_file_scope would do in the absence of such info. */
5512 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5514 /* Find the filename. Do not use dwarf2_name here, since the filename
5515 is not a source language identifier. */
5516 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5518 name
= DW_STRING (attr
);
5520 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5522 comp_dir
= DW_STRING (attr
);
5523 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
5525 comp_dir
= ldirname (name
);
5526 if (comp_dir
!= NULL
)
5527 make_cleanup (xfree
, comp_dir
);
5533 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5535 set_cu_language (DW_UNSND (attr
), cu
);
5537 /* This isn't technically needed today. It is done for symmetry
5538 with read_file_scope. */
5539 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5541 cu
->producer
= DW_STRING (attr
);
5543 /* We assume that we're processing GCC output. */
5544 processing_gcc_compilation
= 2;
5546 processing_has_namespace_info
= 0;
5548 start_symtab (name
, comp_dir
, lowpc
);
5549 record_debugformat ("DWARF 2");
5550 record_producer (cu
->producer
);
5552 /* Process the dies in the type unit. */
5553 if (die
->child
== NULL
)
5555 dump_die_for_error (die
);
5556 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5557 bfd_get_filename (abfd
));
5560 child_die
= die
->child
;
5562 while (child_die
&& child_die
->tag
)
5564 process_die (child_die
, cu
);
5566 child_die
= sibling_die (child_die
);
5569 do_cleanups (back_to
);
5573 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
5574 struct dwarf2_cu
*cu
)
5576 struct function_range
*thisfn
;
5578 thisfn
= (struct function_range
*)
5579 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
5580 thisfn
->name
= name
;
5581 thisfn
->lowpc
= lowpc
;
5582 thisfn
->highpc
= highpc
;
5583 thisfn
->seen_line
= 0;
5584 thisfn
->next
= NULL
;
5586 if (cu
->last_fn
== NULL
)
5587 cu
->first_fn
= thisfn
;
5589 cu
->last_fn
->next
= thisfn
;
5591 cu
->last_fn
= thisfn
;
5594 /* qsort helper for inherit_abstract_dies. */
5597 unsigned_int_compar (const void *ap
, const void *bp
)
5599 unsigned int a
= *(unsigned int *) ap
;
5600 unsigned int b
= *(unsigned int *) bp
;
5602 return (a
> b
) - (b
> a
);
5605 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5606 Inherit only the children of the DW_AT_abstract_origin DIE not being
5607 already referenced by DW_AT_abstract_origin from the children of the
5611 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
5613 struct die_info
*child_die
;
5614 unsigned die_children_count
;
5615 /* CU offsets which were referenced by children of the current DIE. */
5617 unsigned *offsets_end
, *offsetp
;
5618 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5619 struct die_info
*origin_die
;
5620 /* Iterator of the ORIGIN_DIE children. */
5621 struct die_info
*origin_child_die
;
5622 struct cleanup
*cleanups
;
5623 struct attribute
*attr
;
5624 struct dwarf2_cu
*origin_cu
;
5625 struct pending
**origin_previous_list_in_scope
;
5627 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
5631 /* Note that following die references may follow to a die in a
5635 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
5637 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5639 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
5640 origin_cu
->list_in_scope
= cu
->list_in_scope
;
5642 if (die
->tag
!= origin_die
->tag
5643 && !(die
->tag
== DW_TAG_inlined_subroutine
5644 && origin_die
->tag
== DW_TAG_subprogram
))
5645 complaint (&symfile_complaints
,
5646 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5647 die
->offset
, origin_die
->offset
);
5649 child_die
= die
->child
;
5650 die_children_count
= 0;
5651 while (child_die
&& child_die
->tag
)
5653 child_die
= sibling_die (child_die
);
5654 die_children_count
++;
5656 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
5657 cleanups
= make_cleanup (xfree
, offsets
);
5659 offsets_end
= offsets
;
5660 child_die
= die
->child
;
5661 while (child_die
&& child_die
->tag
)
5663 /* For each CHILD_DIE, find the corresponding child of
5664 ORIGIN_DIE. If there is more than one layer of
5665 DW_AT_abstract_origin, follow them all; there shouldn't be,
5666 but GCC versions at least through 4.4 generate this (GCC PR
5668 struct die_info
*child_origin_die
= child_die
;
5669 struct dwarf2_cu
*child_origin_cu
= cu
;
5673 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
5677 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
5681 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5682 counterpart may exist. */
5683 if (child_origin_die
!= child_die
)
5685 if (child_die
->tag
!= child_origin_die
->tag
5686 && !(child_die
->tag
== DW_TAG_inlined_subroutine
5687 && child_origin_die
->tag
== DW_TAG_subprogram
))
5688 complaint (&symfile_complaints
,
5689 _("Child DIE 0x%x and its abstract origin 0x%x have "
5690 "different tags"), child_die
->offset
,
5691 child_origin_die
->offset
);
5692 if (child_origin_die
->parent
!= origin_die
)
5693 complaint (&symfile_complaints
,
5694 _("Child DIE 0x%x and its abstract origin 0x%x have "
5695 "different parents"), child_die
->offset
,
5696 child_origin_die
->offset
);
5698 *offsets_end
++ = child_origin_die
->offset
;
5700 child_die
= sibling_die (child_die
);
5702 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
5703 unsigned_int_compar
);
5704 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
5705 if (offsetp
[-1] == *offsetp
)
5706 complaint (&symfile_complaints
,
5707 _("Multiple children of DIE 0x%x refer "
5708 "to DIE 0x%x as their abstract origin"),
5709 die
->offset
, *offsetp
);
5712 origin_child_die
= origin_die
->child
;
5713 while (origin_child_die
&& origin_child_die
->tag
)
5715 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5716 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
5718 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
5720 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5721 process_die (origin_child_die
, origin_cu
);
5723 origin_child_die
= sibling_die (origin_child_die
);
5725 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
5727 do_cleanups (cleanups
);
5731 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5733 struct objfile
*objfile
= cu
->objfile
;
5734 struct context_stack
*new;
5737 struct die_info
*child_die
;
5738 struct attribute
*attr
, *call_line
, *call_file
;
5741 struct block
*block
;
5742 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
5743 VEC (symbolp
) *template_args
= NULL
;
5744 struct template_symbol
*templ_func
= NULL
;
5748 /* If we do not have call site information, we can't show the
5749 caller of this inlined function. That's too confusing, so
5750 only use the scope for local variables. */
5751 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
5752 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
5753 if (call_line
== NULL
|| call_file
== NULL
)
5755 read_lexical_block_scope (die
, cu
);
5760 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5762 name
= dwarf2_name (die
, cu
);
5764 /* Ignore functions with missing or empty names. These are actually
5765 illegal according to the DWARF standard. */
5768 complaint (&symfile_complaints
,
5769 _("missing name for subprogram DIE at %d"), die
->offset
);
5773 /* Ignore functions with missing or invalid low and high pc attributes. */
5774 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5776 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5777 if (!attr
|| !DW_UNSND (attr
))
5778 complaint (&symfile_complaints
,
5779 _("cannot get low and high bounds "
5780 "for subprogram DIE at %d"),
5788 /* Record the function range for dwarf_decode_lines. */
5789 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
5791 /* If we have any template arguments, then we must allocate a
5792 different sort of symbol. */
5793 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
5795 if (child_die
->tag
== DW_TAG_template_type_param
5796 || child_die
->tag
== DW_TAG_template_value_param
)
5798 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5799 struct template_symbol
);
5800 templ_func
->base
.is_cplus_template_function
= 1;
5805 new = push_context (0, lowpc
);
5806 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
5807 (struct symbol
*) templ_func
);
5809 /* If there is a location expression for DW_AT_frame_base, record
5811 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
5813 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
5814 expression is being recorded directly in the function's symbol
5815 and not in a separate frame-base object. I guess this hack is
5816 to avoid adding some sort of frame-base adjunct/annex to the
5817 function's symbol :-(. The problem with doing this is that it
5818 results in a function symbol with a location expression that
5819 has nothing to do with the location of the function, ouch! The
5820 relationship should be: a function's symbol has-a frame base; a
5821 frame-base has-a location expression. */
5822 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
5824 cu
->list_in_scope
= &local_symbols
;
5826 if (die
->child
!= NULL
)
5828 child_die
= die
->child
;
5829 while (child_die
&& child_die
->tag
)
5831 if (child_die
->tag
== DW_TAG_template_type_param
5832 || child_die
->tag
== DW_TAG_template_value_param
)
5834 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
5837 VEC_safe_push (symbolp
, template_args
, arg
);
5840 process_die (child_die
, cu
);
5841 child_die
= sibling_die (child_die
);
5845 inherit_abstract_dies (die
, cu
);
5847 /* If we have a DW_AT_specification, we might need to import using
5848 directives from the context of the specification DIE. See the
5849 comment in determine_prefix. */
5850 if (cu
->language
== language_cplus
5851 && dwarf2_attr (die
, DW_AT_specification
, cu
))
5853 struct dwarf2_cu
*spec_cu
= cu
;
5854 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
5858 child_die
= spec_die
->child
;
5859 while (child_die
&& child_die
->tag
)
5861 if (child_die
->tag
== DW_TAG_imported_module
)
5862 process_die (child_die
, spec_cu
);
5863 child_die
= sibling_die (child_die
);
5866 /* In some cases, GCC generates specification DIEs that
5867 themselves contain DW_AT_specification attributes. */
5868 spec_die
= die_specification (spec_die
, &spec_cu
);
5872 new = pop_context ();
5873 /* Make a block for the local symbols within. */
5874 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
5875 lowpc
, highpc
, objfile
);
5877 /* For C++, set the block's scope. */
5878 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
5879 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
5880 determine_prefix (die
, cu
),
5881 processing_has_namespace_info
);
5883 /* If we have address ranges, record them. */
5884 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5886 /* Attach template arguments to function. */
5887 if (! VEC_empty (symbolp
, template_args
))
5889 gdb_assert (templ_func
!= NULL
);
5891 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
5892 templ_func
->template_arguments
5893 = obstack_alloc (&objfile
->objfile_obstack
,
5894 (templ_func
->n_template_arguments
5895 * sizeof (struct symbol
*)));
5896 memcpy (templ_func
->template_arguments
,
5897 VEC_address (symbolp
, template_args
),
5898 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
5899 VEC_free (symbolp
, template_args
);
5902 /* In C++, we can have functions nested inside functions (e.g., when
5903 a function declares a class that has methods). This means that
5904 when we finish processing a function scope, we may need to go
5905 back to building a containing block's symbol lists. */
5906 local_symbols
= new->locals
;
5907 param_symbols
= new->params
;
5908 using_directives
= new->using_directives
;
5910 /* If we've finished processing a top-level function, subsequent
5911 symbols go in the file symbol list. */
5912 if (outermost_context_p ())
5913 cu
->list_in_scope
= &file_symbols
;
5916 /* Process all the DIES contained within a lexical block scope. Start
5917 a new scope, process the dies, and then close the scope. */
5920 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5922 struct objfile
*objfile
= cu
->objfile
;
5923 struct context_stack
*new;
5924 CORE_ADDR lowpc
, highpc
;
5925 struct die_info
*child_die
;
5928 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5930 /* Ignore blocks with missing or invalid low and high pc attributes. */
5931 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
5932 as multiple lexical blocks? Handling children in a sane way would
5933 be nasty. Might be easier to properly extend generic blocks to
5935 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5940 push_context (0, lowpc
);
5941 if (die
->child
!= NULL
)
5943 child_die
= die
->child
;
5944 while (child_die
&& child_die
->tag
)
5946 process_die (child_die
, cu
);
5947 child_die
= sibling_die (child_die
);
5950 new = pop_context ();
5952 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
5955 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
5958 /* Note that recording ranges after traversing children, as we
5959 do here, means that recording a parent's ranges entails
5960 walking across all its children's ranges as they appear in
5961 the address map, which is quadratic behavior.
5963 It would be nicer to record the parent's ranges before
5964 traversing its children, simply overriding whatever you find
5965 there. But since we don't even decide whether to create a
5966 block until after we've traversed its children, that's hard
5968 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5970 local_symbols
= new->locals
;
5971 using_directives
= new->using_directives
;
5974 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
5975 Return 1 if the attributes are present and valid, otherwise, return 0.
5976 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
5979 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
5980 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
5981 struct partial_symtab
*ranges_pst
)
5983 struct objfile
*objfile
= cu
->objfile
;
5984 struct comp_unit_head
*cu_header
= &cu
->header
;
5985 bfd
*obfd
= objfile
->obfd
;
5986 unsigned int addr_size
= cu_header
->addr_size
;
5987 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
5988 /* Base address selection entry. */
5999 found_base
= cu
->base_known
;
6000 base
= cu
->base_address
;
6002 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
6003 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6005 complaint (&symfile_complaints
,
6006 _("Offset %d out of bounds for DW_AT_ranges attribute"),
6010 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6012 /* Read in the largest possible address. */
6013 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
6014 if ((marker
& mask
) == mask
)
6016 /* If we found the largest possible address, then
6017 read the base address. */
6018 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
6019 buffer
+= 2 * addr_size
;
6020 offset
+= 2 * addr_size
;
6026 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6030 CORE_ADDR range_beginning
, range_end
;
6032 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
6033 buffer
+= addr_size
;
6034 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
6035 buffer
+= addr_size
;
6036 offset
+= 2 * addr_size
;
6038 /* An end of list marker is a pair of zero addresses. */
6039 if (range_beginning
== 0 && range_end
== 0)
6040 /* Found the end of list entry. */
6043 /* Each base address selection entry is a pair of 2 values.
6044 The first is the largest possible address, the second is
6045 the base address. Check for a base address here. */
6046 if ((range_beginning
& mask
) == mask
)
6048 /* If we found the largest possible address, then
6049 read the base address. */
6050 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
6057 /* We have no valid base address for the ranges
6059 complaint (&symfile_complaints
,
6060 _("Invalid .debug_ranges data (no base address)"));
6064 if (range_beginning
> range_end
)
6066 /* Inverted range entries are invalid. */
6067 complaint (&symfile_complaints
,
6068 _("Invalid .debug_ranges data (inverted range)"));
6072 /* Empty range entries have no effect. */
6073 if (range_beginning
== range_end
)
6076 range_beginning
+= base
;
6079 if (ranges_pst
!= NULL
)
6080 addrmap_set_empty (objfile
->psymtabs_addrmap
,
6081 range_beginning
+ baseaddr
,
6082 range_end
- 1 + baseaddr
,
6085 /* FIXME: This is recording everything as a low-high
6086 segment of consecutive addresses. We should have a
6087 data structure for discontiguous block ranges
6091 low
= range_beginning
;
6097 if (range_beginning
< low
)
6098 low
= range_beginning
;
6099 if (range_end
> high
)
6105 /* If the first entry is an end-of-list marker, the range
6106 describes an empty scope, i.e. no instructions. */
6112 *high_return
= high
;
6116 /* Get low and high pc attributes from a die. Return 1 if the attributes
6117 are present and valid, otherwise, return 0. Return -1 if the range is
6118 discontinuous, i.e. derived from DW_AT_ranges information. */
6120 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
6121 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
6122 struct partial_symtab
*pst
)
6124 struct attribute
*attr
;
6129 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6132 high
= DW_ADDR (attr
);
6133 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6135 low
= DW_ADDR (attr
);
6137 /* Found high w/o low attribute. */
6140 /* Found consecutive range of addresses. */
6145 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6148 /* Value of the DW_AT_ranges attribute is the offset in the
6149 .debug_ranges section. */
6150 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
6152 /* Found discontinuous range of addresses. */
6157 /* read_partial_die has also the strict LOW < HIGH requirement. */
6161 /* When using the GNU linker, .gnu.linkonce. sections are used to
6162 eliminate duplicate copies of functions and vtables and such.
6163 The linker will arbitrarily choose one and discard the others.
6164 The AT_*_pc values for such functions refer to local labels in
6165 these sections. If the section from that file was discarded, the
6166 labels are not in the output, so the relocs get a value of 0.
6167 If this is a discarded function, mark the pc bounds as invalid,
6168 so that GDB will ignore it. */
6169 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
6177 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
6178 its low and high PC addresses. Do nothing if these addresses could not
6179 be determined. Otherwise, set LOWPC to the low address if it is smaller,
6180 and HIGHPC to the high address if greater than HIGHPC. */
6183 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
6184 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6185 struct dwarf2_cu
*cu
)
6187 CORE_ADDR low
, high
;
6188 struct die_info
*child
= die
->child
;
6190 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
6192 *lowpc
= min (*lowpc
, low
);
6193 *highpc
= max (*highpc
, high
);
6196 /* If the language does not allow nested subprograms (either inside
6197 subprograms or lexical blocks), we're done. */
6198 if (cu
->language
!= language_ada
)
6201 /* Check all the children of the given DIE. If it contains nested
6202 subprograms, then check their pc bounds. Likewise, we need to
6203 check lexical blocks as well, as they may also contain subprogram
6205 while (child
&& child
->tag
)
6207 if (child
->tag
== DW_TAG_subprogram
6208 || child
->tag
== DW_TAG_lexical_block
)
6209 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
6210 child
= sibling_die (child
);
6214 /* Get the low and high pc's represented by the scope DIE, and store
6215 them in *LOWPC and *HIGHPC. If the correct values can't be
6216 determined, set *LOWPC to -1 and *HIGHPC to 0. */
6219 get_scope_pc_bounds (struct die_info
*die
,
6220 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6221 struct dwarf2_cu
*cu
)
6223 CORE_ADDR best_low
= (CORE_ADDR
) -1;
6224 CORE_ADDR best_high
= (CORE_ADDR
) 0;
6225 CORE_ADDR current_low
, current_high
;
6227 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
6229 best_low
= current_low
;
6230 best_high
= current_high
;
6234 struct die_info
*child
= die
->child
;
6236 while (child
&& child
->tag
)
6238 switch (child
->tag
) {
6239 case DW_TAG_subprogram
:
6240 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
6242 case DW_TAG_namespace
:
6244 /* FIXME: carlton/2004-01-16: Should we do this for
6245 DW_TAG_class_type/DW_TAG_structure_type, too? I think
6246 that current GCC's always emit the DIEs corresponding
6247 to definitions of methods of classes as children of a
6248 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
6249 the DIEs giving the declarations, which could be
6250 anywhere). But I don't see any reason why the
6251 standards says that they have to be there. */
6252 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
6254 if (current_low
!= ((CORE_ADDR
) -1))
6256 best_low
= min (best_low
, current_low
);
6257 best_high
= max (best_high
, current_high
);
6265 child
= sibling_die (child
);
6270 *highpc
= best_high
;
6273 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
6276 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
6277 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
6279 struct attribute
*attr
;
6281 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6284 CORE_ADDR high
= DW_ADDR (attr
);
6286 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6289 CORE_ADDR low
= DW_ADDR (attr
);
6291 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
6295 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6298 bfd
*obfd
= cu
->objfile
->obfd
;
6300 /* The value of the DW_AT_ranges attribute is the offset of the
6301 address range list in the .debug_ranges section. */
6302 unsigned long offset
= DW_UNSND (attr
);
6303 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6305 /* For some target architectures, but not others, the
6306 read_address function sign-extends the addresses it returns.
6307 To recognize base address selection entries, we need a
6309 unsigned int addr_size
= cu
->header
.addr_size
;
6310 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6312 /* The base address, to which the next pair is relative. Note
6313 that this 'base' is a DWARF concept: most entries in a range
6314 list are relative, to reduce the number of relocs against the
6315 debugging information. This is separate from this function's
6316 'baseaddr' argument, which GDB uses to relocate debugging
6317 information from a shared library based on the address at
6318 which the library was loaded. */
6319 CORE_ADDR base
= cu
->base_address
;
6320 int base_known
= cu
->base_known
;
6322 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
6323 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6325 complaint (&symfile_complaints
,
6326 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
6333 unsigned int bytes_read
;
6334 CORE_ADDR start
, end
;
6336 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6337 buffer
+= bytes_read
;
6338 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6339 buffer
+= bytes_read
;
6341 /* Did we find the end of the range list? */
6342 if (start
== 0 && end
== 0)
6345 /* Did we find a base address selection entry? */
6346 else if ((start
& base_select_mask
) == base_select_mask
)
6352 /* We found an ordinary address range. */
6357 complaint (&symfile_complaints
,
6358 _("Invalid .debug_ranges data "
6359 "(no base address)"));
6365 /* Inverted range entries are invalid. */
6366 complaint (&symfile_complaints
,
6367 _("Invalid .debug_ranges data "
6368 "(inverted range)"));
6372 /* Empty range entries have no effect. */
6376 record_block_range (block
,
6377 baseaddr
+ base
+ start
,
6378 baseaddr
+ base
+ end
- 1);
6384 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
6385 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
6386 during 4.6.0 experimental. */
6389 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
6392 int major
, minor
, release
;
6394 if (cu
->producer
== NULL
)
6396 /* For unknown compilers expect their behavior is DWARF version
6399 GCC started to support .debug_types sections by -gdwarf-4 since
6400 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
6401 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
6402 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
6403 interpreted incorrectly by GDB now - GCC PR debug/48229. */
6408 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
6410 if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) != 0)
6412 /* For non-GCC compilers expect their behavior is DWARF version
6417 cs
= &cu
->producer
[strlen ("GNU ")];
6418 while (*cs
&& !isdigit (*cs
))
6420 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
6422 /* Not recognized as GCC. */
6427 return major
< 4 || (major
== 4 && minor
< 6);
6430 /* Return the default accessibility type if it is not overriden by
6431 DW_AT_accessibility. */
6433 static enum dwarf_access_attribute
6434 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
6436 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
6438 /* The default DWARF 2 accessibility for members is public, the default
6439 accessibility for inheritance is private. */
6441 if (die
->tag
!= DW_TAG_inheritance
)
6442 return DW_ACCESS_public
;
6444 return DW_ACCESS_private
;
6448 /* DWARF 3+ defines the default accessibility a different way. The same
6449 rules apply now for DW_TAG_inheritance as for the members and it only
6450 depends on the container kind. */
6452 if (die
->parent
->tag
== DW_TAG_class_type
)
6453 return DW_ACCESS_private
;
6455 return DW_ACCESS_public
;
6459 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
6460 offset. If the attribute was not found return 0, otherwise return
6461 1. If it was found but could not properly be handled, set *OFFSET
6465 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
6468 struct attribute
*attr
;
6470 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6475 /* Note that we do not check for a section offset first here.
6476 This is because DW_AT_data_member_location is new in DWARF 4,
6477 so if we see it, we can assume that a constant form is really
6478 a constant and not a section offset. */
6479 if (attr_form_is_constant (attr
))
6480 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
6481 else if (attr_form_is_section_offset (attr
))
6482 dwarf2_complex_location_expr_complaint ();
6483 else if (attr_form_is_block (attr
))
6484 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6486 dwarf2_complex_location_expr_complaint ();
6494 /* Add an aggregate field to the field list. */
6497 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
6498 struct dwarf2_cu
*cu
)
6500 struct objfile
*objfile
= cu
->objfile
;
6501 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6502 struct nextfield
*new_field
;
6503 struct attribute
*attr
;
6505 char *fieldname
= "";
6507 /* Allocate a new field list entry and link it in. */
6508 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
6509 make_cleanup (xfree
, new_field
);
6510 memset (new_field
, 0, sizeof (struct nextfield
));
6512 if (die
->tag
== DW_TAG_inheritance
)
6514 new_field
->next
= fip
->baseclasses
;
6515 fip
->baseclasses
= new_field
;
6519 new_field
->next
= fip
->fields
;
6520 fip
->fields
= new_field
;
6524 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6526 new_field
->accessibility
= DW_UNSND (attr
);
6528 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
6529 if (new_field
->accessibility
!= DW_ACCESS_public
)
6530 fip
->non_public_fields
= 1;
6532 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6534 new_field
->virtuality
= DW_UNSND (attr
);
6536 new_field
->virtuality
= DW_VIRTUALITY_none
;
6538 fp
= &new_field
->field
;
6540 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
6544 /* Data member other than a C++ static data member. */
6546 /* Get type of field. */
6547 fp
->type
= die_type (die
, cu
);
6549 SET_FIELD_BITPOS (*fp
, 0);
6551 /* Get bit size of field (zero if none). */
6552 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
6555 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
6559 FIELD_BITSIZE (*fp
) = 0;
6562 /* Get bit offset of field. */
6563 if (handle_data_member_location (die
, cu
, &offset
))
6564 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
6565 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
6568 if (gdbarch_bits_big_endian (gdbarch
))
6570 /* For big endian bits, the DW_AT_bit_offset gives the
6571 additional bit offset from the MSB of the containing
6572 anonymous object to the MSB of the field. We don't
6573 have to do anything special since we don't need to
6574 know the size of the anonymous object. */
6575 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
6579 /* For little endian bits, compute the bit offset to the
6580 MSB of the anonymous object, subtract off the number of
6581 bits from the MSB of the field to the MSB of the
6582 object, and then subtract off the number of bits of
6583 the field itself. The result is the bit offset of
6584 the LSB of the field. */
6586 int bit_offset
= DW_UNSND (attr
);
6588 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6591 /* The size of the anonymous object containing
6592 the bit field is explicit, so use the
6593 indicated size (in bytes). */
6594 anonymous_size
= DW_UNSND (attr
);
6598 /* The size of the anonymous object containing
6599 the bit field must be inferred from the type
6600 attribute of the data member containing the
6602 anonymous_size
= TYPE_LENGTH (fp
->type
);
6604 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
6605 - bit_offset
- FIELD_BITSIZE (*fp
);
6609 /* Get name of field. */
6610 fieldname
= dwarf2_name (die
, cu
);
6611 if (fieldname
== NULL
)
6614 /* The name is already allocated along with this objfile, so we don't
6615 need to duplicate it for the type. */
6616 fp
->name
= fieldname
;
6618 /* Change accessibility for artificial fields (e.g. virtual table
6619 pointer or virtual base class pointer) to private. */
6620 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
6622 FIELD_ARTIFICIAL (*fp
) = 1;
6623 new_field
->accessibility
= DW_ACCESS_private
;
6624 fip
->non_public_fields
= 1;
6627 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
6629 /* C++ static member. */
6631 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
6632 is a declaration, but all versions of G++ as of this writing
6633 (so through at least 3.2.1) incorrectly generate
6634 DW_TAG_variable tags. */
6636 const char *physname
;
6638 /* Get name of field. */
6639 fieldname
= dwarf2_name (die
, cu
);
6640 if (fieldname
== NULL
)
6643 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6645 /* Only create a symbol if this is an external value.
6646 new_symbol checks this and puts the value in the global symbol
6647 table, which we want. If it is not external, new_symbol
6648 will try to put the value in cu->list_in_scope which is wrong. */
6649 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
6651 /* A static const member, not much different than an enum as far as
6652 we're concerned, except that we can support more types. */
6653 new_symbol (die
, NULL
, cu
);
6656 /* Get physical name. */
6657 physname
= dwarf2_physname (fieldname
, die
, cu
);
6659 /* The name is already allocated along with this objfile, so we don't
6660 need to duplicate it for the type. */
6661 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
6662 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6663 FIELD_NAME (*fp
) = fieldname
;
6665 else if (die
->tag
== DW_TAG_inheritance
)
6669 /* C++ base class field. */
6670 if (handle_data_member_location (die
, cu
, &offset
))
6671 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
6672 FIELD_BITSIZE (*fp
) = 0;
6673 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6674 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
6675 fip
->nbaseclasses
++;
6679 /* Add a typedef defined in the scope of the FIP's class. */
6682 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
6683 struct dwarf2_cu
*cu
)
6685 struct objfile
*objfile
= cu
->objfile
;
6686 struct typedef_field_list
*new_field
;
6687 struct attribute
*attr
;
6688 struct typedef_field
*fp
;
6689 char *fieldname
= "";
6691 /* Allocate a new field list entry and link it in. */
6692 new_field
= xzalloc (sizeof (*new_field
));
6693 make_cleanup (xfree
, new_field
);
6695 gdb_assert (die
->tag
== DW_TAG_typedef
);
6697 fp
= &new_field
->field
;
6699 /* Get name of field. */
6700 fp
->name
= dwarf2_name (die
, cu
);
6701 if (fp
->name
== NULL
)
6704 fp
->type
= read_type_die (die
, cu
);
6706 new_field
->next
= fip
->typedef_field_list
;
6707 fip
->typedef_field_list
= new_field
;
6708 fip
->typedef_field_list_count
++;
6711 /* Create the vector of fields, and attach it to the type. */
6714 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
6715 struct dwarf2_cu
*cu
)
6717 int nfields
= fip
->nfields
;
6719 /* Record the field count, allocate space for the array of fields,
6720 and create blank accessibility bitfields if necessary. */
6721 TYPE_NFIELDS (type
) = nfields
;
6722 TYPE_FIELDS (type
) = (struct field
*)
6723 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
6724 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
6726 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
6728 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6730 TYPE_FIELD_PRIVATE_BITS (type
) =
6731 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6732 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
6734 TYPE_FIELD_PROTECTED_BITS (type
) =
6735 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6736 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
6738 TYPE_FIELD_IGNORE_BITS (type
) =
6739 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6740 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
6743 /* If the type has baseclasses, allocate and clear a bit vector for
6744 TYPE_FIELD_VIRTUAL_BITS. */
6745 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
6747 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
6748 unsigned char *pointer
;
6750 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6751 pointer
= TYPE_ALLOC (type
, num_bytes
);
6752 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
6753 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
6754 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
6757 /* Copy the saved-up fields into the field vector. Start from the head of
6758 the list, adding to the tail of the field array, so that they end up in
6759 the same order in the array in which they were added to the list. */
6760 while (nfields
-- > 0)
6762 struct nextfield
*fieldp
;
6766 fieldp
= fip
->fields
;
6767 fip
->fields
= fieldp
->next
;
6771 fieldp
= fip
->baseclasses
;
6772 fip
->baseclasses
= fieldp
->next
;
6775 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
6776 switch (fieldp
->accessibility
)
6778 case DW_ACCESS_private
:
6779 if (cu
->language
!= language_ada
)
6780 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
6783 case DW_ACCESS_protected
:
6784 if (cu
->language
!= language_ada
)
6785 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
6788 case DW_ACCESS_public
:
6792 /* Unknown accessibility. Complain and treat it as public. */
6794 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
6795 fieldp
->accessibility
);
6799 if (nfields
< fip
->nbaseclasses
)
6801 switch (fieldp
->virtuality
)
6803 case DW_VIRTUALITY_virtual
:
6804 case DW_VIRTUALITY_pure_virtual
:
6805 if (cu
->language
== language_ada
)
6806 error (_("unexpected virtuality in component of Ada type"));
6807 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
6814 /* Add a member function to the proper fieldlist. */
6817 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
6818 struct type
*type
, struct dwarf2_cu
*cu
)
6820 struct objfile
*objfile
= cu
->objfile
;
6821 struct attribute
*attr
;
6822 struct fnfieldlist
*flp
;
6824 struct fn_field
*fnp
;
6826 struct nextfnfield
*new_fnfield
;
6827 struct type
*this_type
;
6828 enum dwarf_access_attribute accessibility
;
6830 if (cu
->language
== language_ada
)
6831 error (_("unexpected member function in Ada type"));
6833 /* Get name of member function. */
6834 fieldname
= dwarf2_name (die
, cu
);
6835 if (fieldname
== NULL
)
6838 /* Look up member function name in fieldlist. */
6839 for (i
= 0; i
< fip
->nfnfields
; i
++)
6841 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
6845 /* Create new list element if necessary. */
6846 if (i
< fip
->nfnfields
)
6847 flp
= &fip
->fnfieldlists
[i
];
6850 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
6852 fip
->fnfieldlists
= (struct fnfieldlist
*)
6853 xrealloc (fip
->fnfieldlists
,
6854 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
6855 * sizeof (struct fnfieldlist
));
6856 if (fip
->nfnfields
== 0)
6857 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
6859 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
6860 flp
->name
= fieldname
;
6863 i
= fip
->nfnfields
++;
6866 /* Create a new member function field and chain it to the field list
6868 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
6869 make_cleanup (xfree
, new_fnfield
);
6870 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
6871 new_fnfield
->next
= flp
->head
;
6872 flp
->head
= new_fnfield
;
6875 /* Fill in the member function field info. */
6876 fnp
= &new_fnfield
->fnfield
;
6878 /* Delay processing of the physname until later. */
6879 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
6881 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
6886 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
6887 fnp
->physname
= physname
? physname
: "";
6890 fnp
->type
= alloc_type (objfile
);
6891 this_type
= read_type_die (die
, cu
);
6892 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
6894 int nparams
= TYPE_NFIELDS (this_type
);
6896 /* TYPE is the domain of this method, and THIS_TYPE is the type
6897 of the method itself (TYPE_CODE_METHOD). */
6898 smash_to_method_type (fnp
->type
, type
,
6899 TYPE_TARGET_TYPE (this_type
),
6900 TYPE_FIELDS (this_type
),
6901 TYPE_NFIELDS (this_type
),
6902 TYPE_VARARGS (this_type
));
6904 /* Handle static member functions.
6905 Dwarf2 has no clean way to discern C++ static and non-static
6906 member functions. G++ helps GDB by marking the first
6907 parameter for non-static member functions (which is the this
6908 pointer) as artificial. We obtain this information from
6909 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
6910 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
6911 fnp
->voffset
= VOFFSET_STATIC
;
6914 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
6915 dwarf2_full_name (fieldname
, die
, cu
));
6917 /* Get fcontext from DW_AT_containing_type if present. */
6918 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
6919 fnp
->fcontext
= die_containing_type (die
, cu
);
6921 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
6922 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
6924 /* Get accessibility. */
6925 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6927 accessibility
= DW_UNSND (attr
);
6929 accessibility
= dwarf2_default_access_attribute (die
, cu
);
6930 switch (accessibility
)
6932 case DW_ACCESS_private
:
6933 fnp
->is_private
= 1;
6935 case DW_ACCESS_protected
:
6936 fnp
->is_protected
= 1;
6940 /* Check for artificial methods. */
6941 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
6942 if (attr
&& DW_UNSND (attr
) != 0)
6943 fnp
->is_artificial
= 1;
6945 /* Get index in virtual function table if it is a virtual member
6946 function. For older versions of GCC, this is an offset in the
6947 appropriate virtual table, as specified by DW_AT_containing_type.
6948 For everyone else, it is an expression to be evaluated relative
6949 to the object address. */
6951 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
6954 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
6956 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
6958 /* Old-style GCC. */
6959 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
6961 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
6962 || (DW_BLOCK (attr
)->size
> 1
6963 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
6964 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
6966 struct dwarf_block blk
;
6969 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
6971 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
6972 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
6973 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6974 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
6975 dwarf2_complex_location_expr_complaint ();
6977 fnp
->voffset
/= cu
->header
.addr_size
;
6981 dwarf2_complex_location_expr_complaint ();
6984 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
6986 else if (attr_form_is_section_offset (attr
))
6988 dwarf2_complex_location_expr_complaint ();
6992 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
6998 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6999 if (attr
&& DW_UNSND (attr
))
7001 /* GCC does this, as of 2008-08-25; PR debug/37237. */
7002 complaint (&symfile_complaints
,
7003 _("Member function \"%s\" (offset %d) is virtual "
7004 "but the vtable offset is not specified"),
7005 fieldname
, die
->offset
);
7006 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7007 TYPE_CPLUS_DYNAMIC (type
) = 1;
7012 /* Create the vector of member function fields, and attach it to the type. */
7015 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
7016 struct dwarf2_cu
*cu
)
7018 struct fnfieldlist
*flp
;
7019 int total_length
= 0;
7022 if (cu
->language
== language_ada
)
7023 error (_("unexpected member functions in Ada type"));
7025 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7026 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
7027 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
7029 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
7031 struct nextfnfield
*nfp
= flp
->head
;
7032 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
7035 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
7036 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
7037 fn_flp
->fn_fields
= (struct fn_field
*)
7038 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
7039 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
7040 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
7042 total_length
+= flp
->length
;
7045 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
7046 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
7049 /* Returns non-zero if NAME is the name of a vtable member in CU's
7050 language, zero otherwise. */
7052 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
7054 static const char vptr
[] = "_vptr";
7055 static const char vtable
[] = "vtable";
7057 /* Look for the C++ and Java forms of the vtable. */
7058 if ((cu
->language
== language_java
7059 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
7060 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
7061 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
7067 /* GCC outputs unnamed structures that are really pointers to member
7068 functions, with the ABI-specified layout. If TYPE describes
7069 such a structure, smash it into a member function type.
7071 GCC shouldn't do this; it should just output pointer to member DIEs.
7072 This is GCC PR debug/28767. */
7075 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
7077 struct type
*pfn_type
, *domain_type
, *new_type
;
7079 /* Check for a structure with no name and two children. */
7080 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
7083 /* Check for __pfn and __delta members. */
7084 if (TYPE_FIELD_NAME (type
, 0) == NULL
7085 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
7086 || TYPE_FIELD_NAME (type
, 1) == NULL
7087 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
7090 /* Find the type of the method. */
7091 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
7092 if (pfn_type
== NULL
7093 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
7094 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
7097 /* Look for the "this" argument. */
7098 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
7099 if (TYPE_NFIELDS (pfn_type
) == 0
7100 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
7101 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
7104 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
7105 new_type
= alloc_type (objfile
);
7106 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
7107 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
7108 TYPE_VARARGS (pfn_type
));
7109 smash_to_methodptr_type (type
, new_type
);
7112 /* Called when we find the DIE that starts a structure or union scope
7113 (definition) to create a type for the structure or union. Fill in
7114 the type's name and general properties; the members will not be
7115 processed until process_structure_type.
7117 NOTE: we need to call these functions regardless of whether or not the
7118 DIE has a DW_AT_name attribute, since it might be an anonymous
7119 structure or union. This gets the type entered into our set of
7122 However, if the structure is incomplete (an opaque struct/union)
7123 then suppress creating a symbol table entry for it since gdb only
7124 wants to find the one with the complete definition. Note that if
7125 it is complete, we just call new_symbol, which does it's own
7126 checking about whether the struct/union is anonymous or not (and
7127 suppresses creating a symbol table entry itself). */
7129 static struct type
*
7130 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7132 struct objfile
*objfile
= cu
->objfile
;
7134 struct attribute
*attr
;
7137 /* If the definition of this type lives in .debug_types, read that type.
7138 Don't follow DW_AT_specification though, that will take us back up
7139 the chain and we want to go down. */
7140 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7143 struct dwarf2_cu
*type_cu
= cu
;
7144 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7146 /* We could just recurse on read_structure_type, but we need to call
7147 get_die_type to ensure only one type for this DIE is created.
7148 This is important, for example, because for c++ classes we need
7149 TYPE_NAME set which is only done by new_symbol. Blech. */
7150 type
= read_type_die (type_die
, type_cu
);
7152 /* TYPE_CU may not be the same as CU.
7153 Ensure TYPE is recorded in CU's type_hash table. */
7154 return set_die_type (die
, type
, cu
);
7157 type
= alloc_type (objfile
);
7158 INIT_CPLUS_SPECIFIC (type
);
7160 name
= dwarf2_name (die
, cu
);
7163 if (cu
->language
== language_cplus
7164 || cu
->language
== language_java
)
7166 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
7168 /* dwarf2_full_name might have already finished building the DIE's
7169 type. If so, there is no need to continue. */
7170 if (get_die_type (die
, cu
) != NULL
)
7171 return get_die_type (die
, cu
);
7173 TYPE_TAG_NAME (type
) = full_name
;
7174 if (die
->tag
== DW_TAG_structure_type
7175 || die
->tag
== DW_TAG_class_type
)
7176 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7180 /* The name is already allocated along with this objfile, so
7181 we don't need to duplicate it for the type. */
7182 TYPE_TAG_NAME (type
) = (char *) name
;
7183 if (die
->tag
== DW_TAG_class_type
)
7184 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7188 if (die
->tag
== DW_TAG_structure_type
)
7190 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
7192 else if (die
->tag
== DW_TAG_union_type
)
7194 TYPE_CODE (type
) = TYPE_CODE_UNION
;
7198 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
7201 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
7202 TYPE_DECLARED_CLASS (type
) = 1;
7204 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7207 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7211 TYPE_LENGTH (type
) = 0;
7214 TYPE_STUB_SUPPORTED (type
) = 1;
7215 if (die_is_declaration (die
, cu
))
7216 TYPE_STUB (type
) = 1;
7217 else if (attr
== NULL
&& die
->child
== NULL
7218 && producer_is_realview (cu
->producer
))
7219 /* RealView does not output the required DW_AT_declaration
7220 on incomplete types. */
7221 TYPE_STUB (type
) = 1;
7223 /* We need to add the type field to the die immediately so we don't
7224 infinitely recurse when dealing with pointers to the structure
7225 type within the structure itself. */
7226 set_die_type (die
, type
, cu
);
7228 /* set_die_type should be already done. */
7229 set_descriptive_type (type
, die
, cu
);
7234 /* Finish creating a structure or union type, including filling in
7235 its members and creating a symbol for it. */
7238 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7240 struct objfile
*objfile
= cu
->objfile
;
7241 struct die_info
*child_die
= die
->child
;
7244 type
= get_die_type (die
, cu
);
7246 type
= read_structure_type (die
, cu
);
7248 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
7250 struct field_info fi
;
7251 struct die_info
*child_die
;
7252 VEC (symbolp
) *template_args
= NULL
;
7253 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
7255 memset (&fi
, 0, sizeof (struct field_info
));
7257 child_die
= die
->child
;
7259 while (child_die
&& child_die
->tag
)
7261 if (child_die
->tag
== DW_TAG_member
7262 || child_die
->tag
== DW_TAG_variable
)
7264 /* NOTE: carlton/2002-11-05: A C++ static data member
7265 should be a DW_TAG_member that is a declaration, but
7266 all versions of G++ as of this writing (so through at
7267 least 3.2.1) incorrectly generate DW_TAG_variable
7268 tags for them instead. */
7269 dwarf2_add_field (&fi
, child_die
, cu
);
7271 else if (child_die
->tag
== DW_TAG_subprogram
)
7273 /* C++ member function. */
7274 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
7276 else if (child_die
->tag
== DW_TAG_inheritance
)
7278 /* C++ base class field. */
7279 dwarf2_add_field (&fi
, child_die
, cu
);
7281 else if (child_die
->tag
== DW_TAG_typedef
)
7282 dwarf2_add_typedef (&fi
, child_die
, cu
);
7283 else if (child_die
->tag
== DW_TAG_template_type_param
7284 || child_die
->tag
== DW_TAG_template_value_param
)
7286 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
7289 VEC_safe_push (symbolp
, template_args
, arg
);
7292 child_die
= sibling_die (child_die
);
7295 /* Attach template arguments to type. */
7296 if (! VEC_empty (symbolp
, template_args
))
7298 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7299 TYPE_N_TEMPLATE_ARGUMENTS (type
)
7300 = VEC_length (symbolp
, template_args
);
7301 TYPE_TEMPLATE_ARGUMENTS (type
)
7302 = obstack_alloc (&objfile
->objfile_obstack
,
7303 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7304 * sizeof (struct symbol
*)));
7305 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
7306 VEC_address (symbolp
, template_args
),
7307 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7308 * sizeof (struct symbol
*)));
7309 VEC_free (symbolp
, template_args
);
7312 /* Attach fields and member functions to the type. */
7314 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
7317 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
7319 /* Get the type which refers to the base class (possibly this
7320 class itself) which contains the vtable pointer for the current
7321 class from the DW_AT_containing_type attribute. This use of
7322 DW_AT_containing_type is a GNU extension. */
7324 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7326 struct type
*t
= die_containing_type (die
, cu
);
7328 TYPE_VPTR_BASETYPE (type
) = t
;
7333 /* Our own class provides vtbl ptr. */
7334 for (i
= TYPE_NFIELDS (t
) - 1;
7335 i
>= TYPE_N_BASECLASSES (t
);
7338 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
7340 if (is_vtable_name (fieldname
, cu
))
7342 TYPE_VPTR_FIELDNO (type
) = i
;
7347 /* Complain if virtual function table field not found. */
7348 if (i
< TYPE_N_BASECLASSES (t
))
7349 complaint (&symfile_complaints
,
7350 _("virtual function table pointer "
7351 "not found when defining class '%s'"),
7352 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
7357 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
7360 else if (cu
->producer
7361 && strncmp (cu
->producer
,
7362 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
7364 /* The IBM XLC compiler does not provide direct indication
7365 of the containing type, but the vtable pointer is
7366 always named __vfp. */
7370 for (i
= TYPE_NFIELDS (type
) - 1;
7371 i
>= TYPE_N_BASECLASSES (type
);
7374 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
7376 TYPE_VPTR_FIELDNO (type
) = i
;
7377 TYPE_VPTR_BASETYPE (type
) = type
;
7384 /* Copy fi.typedef_field_list linked list elements content into the
7385 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
7386 if (fi
.typedef_field_list
)
7388 int i
= fi
.typedef_field_list_count
;
7390 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7391 TYPE_TYPEDEF_FIELD_ARRAY (type
)
7392 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
7393 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
7395 /* Reverse the list order to keep the debug info elements order. */
7398 struct typedef_field
*dest
, *src
;
7400 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
7401 src
= &fi
.typedef_field_list
->field
;
7402 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
7407 do_cleanups (back_to
);
7410 quirk_gcc_member_function_pointer (type
, cu
->objfile
);
7412 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
7413 snapshots) has been known to create a die giving a declaration
7414 for a class that has, as a child, a die giving a definition for a
7415 nested class. So we have to process our children even if the
7416 current die is a declaration. Normally, of course, a declaration
7417 won't have any children at all. */
7419 while (child_die
!= NULL
&& child_die
->tag
)
7421 if (child_die
->tag
== DW_TAG_member
7422 || child_die
->tag
== DW_TAG_variable
7423 || child_die
->tag
== DW_TAG_inheritance
7424 || child_die
->tag
== DW_TAG_template_value_param
7425 || child_die
->tag
== DW_TAG_template_type_param
)
7430 process_die (child_die
, cu
);
7432 child_die
= sibling_die (child_die
);
7435 /* Do not consider external references. According to the DWARF standard,
7436 these DIEs are identified by the fact that they have no byte_size
7437 attribute, and a declaration attribute. */
7438 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
7439 || !die_is_declaration (die
, cu
))
7440 new_symbol (die
, type
, cu
);
7443 /* Given a DW_AT_enumeration_type die, set its type. We do not
7444 complete the type's fields yet, or create any symbols. */
7446 static struct type
*
7447 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7449 struct objfile
*objfile
= cu
->objfile
;
7451 struct attribute
*attr
;
7454 /* If the definition of this type lives in .debug_types, read that type.
7455 Don't follow DW_AT_specification though, that will take us back up
7456 the chain and we want to go down. */
7457 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7460 struct dwarf2_cu
*type_cu
= cu
;
7461 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7463 type
= read_type_die (type_die
, type_cu
);
7465 /* TYPE_CU may not be the same as CU.
7466 Ensure TYPE is recorded in CU's type_hash table. */
7467 return set_die_type (die
, type
, cu
);
7470 type
= alloc_type (objfile
);
7472 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
7473 name
= dwarf2_full_name (NULL
, die
, cu
);
7475 TYPE_TAG_NAME (type
) = (char *) name
;
7477 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7480 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7484 TYPE_LENGTH (type
) = 0;
7487 /* The enumeration DIE can be incomplete. In Ada, any type can be
7488 declared as private in the package spec, and then defined only
7489 inside the package body. Such types are known as Taft Amendment
7490 Types. When another package uses such a type, an incomplete DIE
7491 may be generated by the compiler. */
7492 if (die_is_declaration (die
, cu
))
7493 TYPE_STUB (type
) = 1;
7495 return set_die_type (die
, type
, cu
);
7498 /* Given a pointer to a die which begins an enumeration, process all
7499 the dies that define the members of the enumeration, and create the
7500 symbol for the enumeration type.
7502 NOTE: We reverse the order of the element list. */
7505 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7507 struct type
*this_type
;
7509 this_type
= get_die_type (die
, cu
);
7510 if (this_type
== NULL
)
7511 this_type
= read_enumeration_type (die
, cu
);
7513 if (die
->child
!= NULL
)
7515 struct die_info
*child_die
;
7517 struct field
*fields
= NULL
;
7519 int unsigned_enum
= 1;
7522 child_die
= die
->child
;
7523 while (child_die
&& child_die
->tag
)
7525 if (child_die
->tag
!= DW_TAG_enumerator
)
7527 process_die (child_die
, cu
);
7531 name
= dwarf2_name (child_die
, cu
);
7534 sym
= new_symbol (child_die
, this_type
, cu
);
7535 if (SYMBOL_VALUE (sym
) < 0)
7538 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7540 fields
= (struct field
*)
7542 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
7543 * sizeof (struct field
));
7546 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
7547 FIELD_TYPE (fields
[num_fields
]) = NULL
;
7548 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
7549 FIELD_BITSIZE (fields
[num_fields
]) = 0;
7555 child_die
= sibling_die (child_die
);
7560 TYPE_NFIELDS (this_type
) = num_fields
;
7561 TYPE_FIELDS (this_type
) = (struct field
*)
7562 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
7563 memcpy (TYPE_FIELDS (this_type
), fields
,
7564 sizeof (struct field
) * num_fields
);
7568 TYPE_UNSIGNED (this_type
) = 1;
7571 new_symbol (die
, this_type
, cu
);
7574 /* Extract all information from a DW_TAG_array_type DIE and put it in
7575 the DIE's type field. For now, this only handles one dimensional
7578 static struct type
*
7579 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7581 struct objfile
*objfile
= cu
->objfile
;
7582 struct die_info
*child_die
;
7584 struct type
*element_type
, *range_type
, *index_type
;
7585 struct type
**range_types
= NULL
;
7586 struct attribute
*attr
;
7588 struct cleanup
*back_to
;
7591 element_type
= die_type (die
, cu
);
7593 /* The die_type call above may have already set the type for this DIE. */
7594 type
= get_die_type (die
, cu
);
7598 /* Irix 6.2 native cc creates array types without children for
7599 arrays with unspecified length. */
7600 if (die
->child
== NULL
)
7602 index_type
= objfile_type (objfile
)->builtin_int
;
7603 range_type
= create_range_type (NULL
, index_type
, 0, -1);
7604 type
= create_array_type (NULL
, element_type
, range_type
);
7605 return set_die_type (die
, type
, cu
);
7608 back_to
= make_cleanup (null_cleanup
, NULL
);
7609 child_die
= die
->child
;
7610 while (child_die
&& child_die
->tag
)
7612 if (child_die
->tag
== DW_TAG_subrange_type
)
7614 struct type
*child_type
= read_type_die (child_die
, cu
);
7616 if (child_type
!= NULL
)
7618 /* The range type was succesfully read. Save it for the
7619 array type creation. */
7620 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
7622 range_types
= (struct type
**)
7623 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
7624 * sizeof (struct type
*));
7626 make_cleanup (free_current_contents
, &range_types
);
7628 range_types
[ndim
++] = child_type
;
7631 child_die
= sibling_die (child_die
);
7634 /* Dwarf2 dimensions are output from left to right, create the
7635 necessary array types in backwards order. */
7637 type
= element_type
;
7639 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
7644 type
= create_array_type (NULL
, type
, range_types
[i
++]);
7649 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
7652 /* Understand Dwarf2 support for vector types (like they occur on
7653 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
7654 array type. This is not part of the Dwarf2/3 standard yet, but a
7655 custom vendor extension. The main difference between a regular
7656 array and the vector variant is that vectors are passed by value
7658 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
7660 make_vector_type (type
);
7662 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
7663 implementation may choose to implement triple vectors using this
7665 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7668 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
7669 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7671 complaint (&symfile_complaints
,
7672 _("DW_AT_byte_size for array type smaller "
7673 "than the total size of elements"));
7676 name
= dwarf2_name (die
, cu
);
7678 TYPE_NAME (type
) = name
;
7680 /* Install the type in the die. */
7681 set_die_type (die
, type
, cu
);
7683 /* set_die_type should be already done. */
7684 set_descriptive_type (type
, die
, cu
);
7686 do_cleanups (back_to
);
7691 static enum dwarf_array_dim_ordering
7692 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
7694 struct attribute
*attr
;
7696 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
7698 if (attr
) return DW_SND (attr
);
7700 /* GNU F77 is a special case, as at 08/2004 array type info is the
7701 opposite order to the dwarf2 specification, but data is still
7702 laid out as per normal fortran.
7704 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
7705 version checking. */
7707 if (cu
->language
== language_fortran
7708 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
7710 return DW_ORD_row_major
;
7713 switch (cu
->language_defn
->la_array_ordering
)
7715 case array_column_major
:
7716 return DW_ORD_col_major
;
7717 case array_row_major
:
7719 return DW_ORD_row_major
;
7723 /* Extract all information from a DW_TAG_set_type DIE and put it in
7724 the DIE's type field. */
7726 static struct type
*
7727 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7729 struct type
*domain_type
, *set_type
;
7730 struct attribute
*attr
;
7732 domain_type
= die_type (die
, cu
);
7734 /* The die_type call above may have already set the type for this DIE. */
7735 set_type
= get_die_type (die
, cu
);
7739 set_type
= create_set_type (NULL
, domain_type
);
7741 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7743 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
7745 return set_die_type (die
, set_type
, cu
);
7748 /* First cut: install each common block member as a global variable. */
7751 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
7753 struct die_info
*child_die
;
7754 struct attribute
*attr
;
7756 CORE_ADDR base
= (CORE_ADDR
) 0;
7758 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7761 /* Support the .debug_loc offsets. */
7762 if (attr_form_is_block (attr
))
7764 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
7766 else if (attr_form_is_section_offset (attr
))
7768 dwarf2_complex_location_expr_complaint ();
7772 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
7773 "common block member");
7776 if (die
->child
!= NULL
)
7778 child_die
= die
->child
;
7779 while (child_die
&& child_die
->tag
)
7783 sym
= new_symbol (child_die
, NULL
, cu
);
7785 && handle_data_member_location (child_die
, cu
, &offset
))
7787 SYMBOL_VALUE_ADDRESS (sym
) = base
+ offset
;
7788 add_symbol_to_list (sym
, &global_symbols
);
7790 child_die
= sibling_die (child_die
);
7795 /* Create a type for a C++ namespace. */
7797 static struct type
*
7798 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7800 struct objfile
*objfile
= cu
->objfile
;
7801 const char *previous_prefix
, *name
;
7805 /* For extensions, reuse the type of the original namespace. */
7806 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
7808 struct die_info
*ext_die
;
7809 struct dwarf2_cu
*ext_cu
= cu
;
7811 ext_die
= dwarf2_extension (die
, &ext_cu
);
7812 type
= read_type_die (ext_die
, ext_cu
);
7814 /* EXT_CU may not be the same as CU.
7815 Ensure TYPE is recorded in CU's type_hash table. */
7816 return set_die_type (die
, type
, cu
);
7819 name
= namespace_name (die
, &is_anonymous
, cu
);
7821 /* Now build the name of the current namespace. */
7823 previous_prefix
= determine_prefix (die
, cu
);
7824 if (previous_prefix
[0] != '\0')
7825 name
= typename_concat (&objfile
->objfile_obstack
,
7826 previous_prefix
, name
, 0, cu
);
7828 /* Create the type. */
7829 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
7831 TYPE_NAME (type
) = (char *) name
;
7832 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7834 return set_die_type (die
, type
, cu
);
7837 /* Read a C++ namespace. */
7840 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
7842 struct objfile
*objfile
= cu
->objfile
;
7845 /* Add a symbol associated to this if we haven't seen the namespace
7846 before. Also, add a using directive if it's an anonymous
7849 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
7853 type
= read_type_die (die
, cu
);
7854 new_symbol (die
, type
, cu
);
7856 namespace_name (die
, &is_anonymous
, cu
);
7859 const char *previous_prefix
= determine_prefix (die
, cu
);
7861 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
7862 NULL
, NULL
, &objfile
->objfile_obstack
);
7866 if (die
->child
!= NULL
)
7868 struct die_info
*child_die
= die
->child
;
7870 while (child_die
&& child_die
->tag
)
7872 process_die (child_die
, cu
);
7873 child_die
= sibling_die (child_die
);
7878 /* Read a Fortran module as type. This DIE can be only a declaration used for
7879 imported module. Still we need that type as local Fortran "use ... only"
7880 declaration imports depend on the created type in determine_prefix. */
7882 static struct type
*
7883 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7885 struct objfile
*objfile
= cu
->objfile
;
7889 module_name
= dwarf2_name (die
, cu
);
7891 complaint (&symfile_complaints
,
7892 _("DW_TAG_module has no name, offset 0x%x"),
7894 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
7896 /* determine_prefix uses TYPE_TAG_NAME. */
7897 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7899 return set_die_type (die
, type
, cu
);
7902 /* Read a Fortran module. */
7905 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
7907 struct die_info
*child_die
= die
->child
;
7909 while (child_die
&& child_die
->tag
)
7911 process_die (child_die
, cu
);
7912 child_die
= sibling_die (child_die
);
7916 /* Return the name of the namespace represented by DIE. Set
7917 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
7921 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
7923 struct die_info
*current_die
;
7924 const char *name
= NULL
;
7926 /* Loop through the extensions until we find a name. */
7928 for (current_die
= die
;
7929 current_die
!= NULL
;
7930 current_die
= dwarf2_extension (die
, &cu
))
7932 name
= dwarf2_name (current_die
, cu
);
7937 /* Is it an anonymous namespace? */
7939 *is_anonymous
= (name
== NULL
);
7941 name
= CP_ANONYMOUS_NAMESPACE_STR
;
7946 /* Extract all information from a DW_TAG_pointer_type DIE and add to
7947 the user defined type vector. */
7949 static struct type
*
7950 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7952 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7953 struct comp_unit_head
*cu_header
= &cu
->header
;
7955 struct attribute
*attr_byte_size
;
7956 struct attribute
*attr_address_class
;
7957 int byte_size
, addr_class
;
7958 struct type
*target_type
;
7960 target_type
= die_type (die
, cu
);
7962 /* The die_type call above may have already set the type for this DIE. */
7963 type
= get_die_type (die
, cu
);
7967 type
= lookup_pointer_type (target_type
);
7969 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7971 byte_size
= DW_UNSND (attr_byte_size
);
7973 byte_size
= cu_header
->addr_size
;
7975 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
7976 if (attr_address_class
)
7977 addr_class
= DW_UNSND (attr_address_class
);
7979 addr_class
= DW_ADDR_none
;
7981 /* If the pointer size or address class is different than the
7982 default, create a type variant marked as such and set the
7983 length accordingly. */
7984 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
7986 if (gdbarch_address_class_type_flags_p (gdbarch
))
7990 type_flags
= gdbarch_address_class_type_flags
7991 (gdbarch
, byte_size
, addr_class
);
7992 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
7994 type
= make_type_with_address_space (type
, type_flags
);
7996 else if (TYPE_LENGTH (type
) != byte_size
)
7998 complaint (&symfile_complaints
,
7999 _("invalid pointer size %d"), byte_size
);
8003 /* Should we also complain about unhandled address classes? */
8007 TYPE_LENGTH (type
) = byte_size
;
8008 return set_die_type (die
, type
, cu
);
8011 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
8012 the user defined type vector. */
8014 static struct type
*
8015 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8018 struct type
*to_type
;
8019 struct type
*domain
;
8021 to_type
= die_type (die
, cu
);
8022 domain
= die_containing_type (die
, cu
);
8024 /* The calls above may have already set the type for this DIE. */
8025 type
= get_die_type (die
, cu
);
8029 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
8030 type
= lookup_methodptr_type (to_type
);
8032 type
= lookup_memberptr_type (to_type
, domain
);
8034 return set_die_type (die
, type
, cu
);
8037 /* Extract all information from a DW_TAG_reference_type DIE and add to
8038 the user defined type vector. */
8040 static struct type
*
8041 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8043 struct comp_unit_head
*cu_header
= &cu
->header
;
8044 struct type
*type
, *target_type
;
8045 struct attribute
*attr
;
8047 target_type
= die_type (die
, cu
);
8049 /* The die_type call above may have already set the type for this DIE. */
8050 type
= get_die_type (die
, cu
);
8054 type
= lookup_reference_type (target_type
);
8055 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8058 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8062 TYPE_LENGTH (type
) = cu_header
->addr_size
;
8064 return set_die_type (die
, type
, cu
);
8067 static struct type
*
8068 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8070 struct type
*base_type
, *cv_type
;
8072 base_type
= die_type (die
, cu
);
8074 /* The die_type call above may have already set the type for this DIE. */
8075 cv_type
= get_die_type (die
, cu
);
8079 /* In case the const qualifier is applied to an array type, the element type
8080 is so qualified, not the array type (section 6.7.3 of C99). */
8081 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
8083 struct type
*el_type
, *inner_array
;
8085 base_type
= copy_type (base_type
);
8086 inner_array
= base_type
;
8088 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
8090 TYPE_TARGET_TYPE (inner_array
) =
8091 copy_type (TYPE_TARGET_TYPE (inner_array
));
8092 inner_array
= TYPE_TARGET_TYPE (inner_array
);
8095 el_type
= TYPE_TARGET_TYPE (inner_array
);
8096 TYPE_TARGET_TYPE (inner_array
) =
8097 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
8099 return set_die_type (die
, base_type
, cu
);
8102 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
8103 return set_die_type (die
, cv_type
, cu
);
8106 static struct type
*
8107 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8109 struct type
*base_type
, *cv_type
;
8111 base_type
= die_type (die
, cu
);
8113 /* The die_type call above may have already set the type for this DIE. */
8114 cv_type
= get_die_type (die
, cu
);
8118 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
8119 return set_die_type (die
, cv_type
, cu
);
8122 /* Extract all information from a DW_TAG_string_type DIE and add to
8123 the user defined type vector. It isn't really a user defined type,
8124 but it behaves like one, with other DIE's using an AT_user_def_type
8125 attribute to reference it. */
8127 static struct type
*
8128 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8130 struct objfile
*objfile
= cu
->objfile
;
8131 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8132 struct type
*type
, *range_type
, *index_type
, *char_type
;
8133 struct attribute
*attr
;
8134 unsigned int length
;
8136 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
8139 length
= DW_UNSND (attr
);
8143 /* Check for the DW_AT_byte_size attribute. */
8144 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8147 length
= DW_UNSND (attr
);
8155 index_type
= objfile_type (objfile
)->builtin_int
;
8156 range_type
= create_range_type (NULL
, index_type
, 1, length
);
8157 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
8158 type
= create_string_type (NULL
, char_type
, range_type
);
8160 return set_die_type (die
, type
, cu
);
8163 /* Handle DIES due to C code like:
8167 int (*funcp)(int a, long l);
8171 ('funcp' generates a DW_TAG_subroutine_type DIE). */
8173 static struct type
*
8174 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8176 struct type
*type
; /* Type that this function returns. */
8177 struct type
*ftype
; /* Function that returns above type. */
8178 struct attribute
*attr
;
8180 type
= die_type (die
, cu
);
8182 /* The die_type call above may have already set the type for this DIE. */
8183 ftype
= get_die_type (die
, cu
);
8187 ftype
= lookup_function_type (type
);
8189 /* All functions in C++, Pascal and Java have prototypes. */
8190 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
8191 if ((attr
&& (DW_UNSND (attr
) != 0))
8192 || cu
->language
== language_cplus
8193 || cu
->language
== language_java
8194 || cu
->language
== language_pascal
)
8195 TYPE_PROTOTYPED (ftype
) = 1;
8196 else if (producer_is_realview (cu
->producer
))
8197 /* RealView does not emit DW_AT_prototyped. We can not
8198 distinguish prototyped and unprototyped functions; default to
8199 prototyped, since that is more common in modern code (and
8200 RealView warns about unprototyped functions). */
8201 TYPE_PROTOTYPED (ftype
) = 1;
8203 /* Store the calling convention in the type if it's available in
8204 the subroutine die. Otherwise set the calling convention to
8205 the default value DW_CC_normal. */
8206 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
8208 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
8209 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
8210 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
8212 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
8214 /* We need to add the subroutine type to the die immediately so
8215 we don't infinitely recurse when dealing with parameters
8216 declared as the same subroutine type. */
8217 set_die_type (die
, ftype
, cu
);
8219 if (die
->child
!= NULL
)
8221 struct type
*void_type
= objfile_type (cu
->objfile
)->builtin_void
;
8222 struct die_info
*child_die
;
8223 int nparams
, iparams
;
8225 /* Count the number of parameters.
8226 FIXME: GDB currently ignores vararg functions, but knows about
8227 vararg member functions. */
8229 child_die
= die
->child
;
8230 while (child_die
&& child_die
->tag
)
8232 if (child_die
->tag
== DW_TAG_formal_parameter
)
8234 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
8235 TYPE_VARARGS (ftype
) = 1;
8236 child_die
= sibling_die (child_die
);
8239 /* Allocate storage for parameters and fill them in. */
8240 TYPE_NFIELDS (ftype
) = nparams
;
8241 TYPE_FIELDS (ftype
) = (struct field
*)
8242 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
8244 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
8245 even if we error out during the parameters reading below. */
8246 for (iparams
= 0; iparams
< nparams
; iparams
++)
8247 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
8250 child_die
= die
->child
;
8251 while (child_die
&& child_die
->tag
)
8253 if (child_die
->tag
== DW_TAG_formal_parameter
)
8255 struct type
*arg_type
;
8257 /* DWARF version 2 has no clean way to discern C++
8258 static and non-static member functions. G++ helps
8259 GDB by marking the first parameter for non-static
8260 member functions (which is the this pointer) as
8261 artificial. We pass this information to
8262 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
8264 DWARF version 3 added DW_AT_object_pointer, which GCC
8265 4.5 does not yet generate. */
8266 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
8268 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
8271 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
8273 /* GCC/43521: In java, the formal parameter
8274 "this" is sometimes not marked with DW_AT_artificial. */
8275 if (cu
->language
== language_java
)
8277 const char *name
= dwarf2_name (child_die
, cu
);
8279 if (name
&& !strcmp (name
, "this"))
8280 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
8283 arg_type
= die_type (child_die
, cu
);
8285 /* RealView does not mark THIS as const, which the testsuite
8286 expects. GCC marks THIS as const in method definitions,
8287 but not in the class specifications (GCC PR 43053). */
8288 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
8289 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
8292 struct dwarf2_cu
*arg_cu
= cu
;
8293 const char *name
= dwarf2_name (child_die
, cu
);
8295 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
8298 /* If the compiler emits this, use it. */
8299 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
8302 else if (name
&& strcmp (name
, "this") == 0)
8303 /* Function definitions will have the argument names. */
8305 else if (name
== NULL
&& iparams
== 0)
8306 /* Declarations may not have the names, so like
8307 elsewhere in GDB, assume an artificial first
8308 argument is "this". */
8312 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
8316 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
8319 child_die
= sibling_die (child_die
);
8326 static struct type
*
8327 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
8329 struct objfile
*objfile
= cu
->objfile
;
8330 const char *name
= NULL
;
8331 struct type
*this_type
;
8333 name
= dwarf2_full_name (NULL
, die
, cu
);
8334 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
8335 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
8336 TYPE_NAME (this_type
) = (char *) name
;
8337 set_die_type (die
, this_type
, cu
);
8338 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
8342 /* Find a representation of a given base type and install
8343 it in the TYPE field of the die. */
8345 static struct type
*
8346 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8348 struct objfile
*objfile
= cu
->objfile
;
8350 struct attribute
*attr
;
8351 int encoding
= 0, size
= 0;
8353 enum type_code code
= TYPE_CODE_INT
;
8355 struct type
*target_type
= NULL
;
8357 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
8360 encoding
= DW_UNSND (attr
);
8362 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8365 size
= DW_UNSND (attr
);
8367 name
= dwarf2_name (die
, cu
);
8370 complaint (&symfile_complaints
,
8371 _("DW_AT_name missing from DW_TAG_base_type"));
8376 case DW_ATE_address
:
8377 /* Turn DW_ATE_address into a void * pointer. */
8378 code
= TYPE_CODE_PTR
;
8379 type_flags
|= TYPE_FLAG_UNSIGNED
;
8380 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
8382 case DW_ATE_boolean
:
8383 code
= TYPE_CODE_BOOL
;
8384 type_flags
|= TYPE_FLAG_UNSIGNED
;
8386 case DW_ATE_complex_float
:
8387 code
= TYPE_CODE_COMPLEX
;
8388 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
8390 case DW_ATE_decimal_float
:
8391 code
= TYPE_CODE_DECFLOAT
;
8394 code
= TYPE_CODE_FLT
;
8398 case DW_ATE_unsigned
:
8399 type_flags
|= TYPE_FLAG_UNSIGNED
;
8400 if (cu
->language
== language_fortran
8402 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
8403 code
= TYPE_CODE_CHAR
;
8405 case DW_ATE_signed_char
:
8406 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8407 || cu
->language
== language_pascal
8408 || cu
->language
== language_fortran
)
8409 code
= TYPE_CODE_CHAR
;
8411 case DW_ATE_unsigned_char
:
8412 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8413 || cu
->language
== language_pascal
8414 || cu
->language
== language_fortran
)
8415 code
= TYPE_CODE_CHAR
;
8416 type_flags
|= TYPE_FLAG_UNSIGNED
;
8419 /* We just treat this as an integer and then recognize the
8420 type by name elsewhere. */
8424 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
8425 dwarf_type_encoding_name (encoding
));
8429 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
8430 TYPE_NAME (type
) = name
;
8431 TYPE_TARGET_TYPE (type
) = target_type
;
8433 if (name
&& strcmp (name
, "char") == 0)
8434 TYPE_NOSIGN (type
) = 1;
8436 return set_die_type (die
, type
, cu
);
8439 /* Read the given DW_AT_subrange DIE. */
8441 static struct type
*
8442 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8444 struct type
*base_type
;
8445 struct type
*range_type
;
8446 struct attribute
*attr
;
8450 LONGEST negative_mask
;
8452 base_type
= die_type (die
, cu
);
8453 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
8454 check_typedef (base_type
);
8456 /* The die_type call above may have already set the type for this DIE. */
8457 range_type
= get_die_type (die
, cu
);
8461 if (cu
->language
== language_fortran
)
8463 /* FORTRAN implies a lower bound of 1, if not given. */
8467 /* FIXME: For variable sized arrays either of these could be
8468 a variable rather than a constant value. We'll allow it,
8469 but we don't know how to handle it. */
8470 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
8472 low
= dwarf2_get_attr_constant_value (attr
, 0);
8474 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
8477 if (attr
->form
== DW_FORM_block1
|| is_ref_attr (attr
))
8479 /* GCC encodes arrays with unspecified or dynamic length
8480 with a DW_FORM_block1 attribute or a reference attribute.
8481 FIXME: GDB does not yet know how to handle dynamic
8482 arrays properly, treat them as arrays with unspecified
8485 FIXME: jimb/2003-09-22: GDB does not really know
8486 how to handle arrays of unspecified length
8487 either; we just represent them as zero-length
8488 arrays. Choose an appropriate upper bound given
8489 the lower bound we've computed above. */
8493 high
= dwarf2_get_attr_constant_value (attr
, 1);
8497 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
8500 int count
= dwarf2_get_attr_constant_value (attr
, 1);
8501 high
= low
+ count
- 1;
8505 /* Unspecified array length. */
8510 /* Dwarf-2 specifications explicitly allows to create subrange types
8511 without specifying a base type.
8512 In that case, the base type must be set to the type of
8513 the lower bound, upper bound or count, in that order, if any of these
8514 three attributes references an object that has a type.
8515 If no base type is found, the Dwarf-2 specifications say that
8516 a signed integer type of size equal to the size of an address should
8518 For the following C code: `extern char gdb_int [];'
8519 GCC produces an empty range DIE.
8520 FIXME: muller/2010-05-28: Possible references to object for low bound,
8521 high bound or count are not yet handled by this code. */
8522 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
8524 struct objfile
*objfile
= cu
->objfile
;
8525 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8526 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
8527 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
8529 /* Test "int", "long int", and "long long int" objfile types,
8530 and select the first one having a size above or equal to the
8531 architecture address size. */
8532 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8533 base_type
= int_type
;
8536 int_type
= objfile_type (objfile
)->builtin_long
;
8537 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8538 base_type
= int_type
;
8541 int_type
= objfile_type (objfile
)->builtin_long_long
;
8542 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8543 base_type
= int_type
;
8549 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
8550 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
8551 low
|= negative_mask
;
8552 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
8553 high
|= negative_mask
;
8555 range_type
= create_range_type (NULL
, base_type
, low
, high
);
8557 /* Mark arrays with dynamic length at least as an array of unspecified
8558 length. GDB could check the boundary but before it gets implemented at
8559 least allow accessing the array elements. */
8560 if (attr
&& attr
->form
== DW_FORM_block1
)
8561 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
8563 /* Ada expects an empty array on no boundary attributes. */
8564 if (attr
== NULL
&& cu
->language
!= language_ada
)
8565 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
8567 name
= dwarf2_name (die
, cu
);
8569 TYPE_NAME (range_type
) = name
;
8571 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8573 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
8575 set_die_type (die
, range_type
, cu
);
8577 /* set_die_type should be already done. */
8578 set_descriptive_type (range_type
, die
, cu
);
8583 static struct type
*
8584 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8588 /* For now, we only support the C meaning of an unspecified type: void. */
8590 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
8591 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
8593 return set_die_type (die
, type
, cu
);
8596 /* Trivial hash function for die_info: the hash value of a DIE
8597 is its offset in .debug_info for this objfile. */
8600 die_hash (const void *item
)
8602 const struct die_info
*die
= item
;
8607 /* Trivial comparison function for die_info structures: two DIEs
8608 are equal if they have the same offset. */
8611 die_eq (const void *item_lhs
, const void *item_rhs
)
8613 const struct die_info
*die_lhs
= item_lhs
;
8614 const struct die_info
*die_rhs
= item_rhs
;
8616 return die_lhs
->offset
== die_rhs
->offset
;
8619 /* Read a whole compilation unit into a linked list of dies. */
8621 static struct die_info
*
8622 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
8624 struct die_reader_specs reader_specs
;
8625 int read_abbrevs
= 0;
8626 struct cleanup
*back_to
= NULL
;
8627 struct die_info
*die
;
8629 if (cu
->dwarf2_abbrevs
== NULL
)
8631 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
8632 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
8636 gdb_assert (cu
->die_hash
== NULL
);
8638 = htab_create_alloc_ex (cu
->header
.length
/ 12,
8642 &cu
->comp_unit_obstack
,
8643 hashtab_obstack_allocate
,
8644 dummy_obstack_deallocate
);
8646 init_cu_die_reader (&reader_specs
, cu
);
8648 die
= read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
8651 do_cleanups (back_to
);
8656 /* Main entry point for reading a DIE and all children.
8657 Read the DIE and dump it if requested. */
8659 static struct die_info
*
8660 read_die_and_children (const struct die_reader_specs
*reader
,
8662 gdb_byte
**new_info_ptr
,
8663 struct die_info
*parent
)
8665 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
8666 new_info_ptr
, parent
);
8668 if (dwarf2_die_debug
)
8670 fprintf_unfiltered (gdb_stdlog
,
8671 "\nRead die from %s of %s:\n",
8672 reader
->buffer
== dwarf2_per_objfile
->info
.buffer
8674 : reader
->buffer
== dwarf2_per_objfile
->types
.buffer
8676 : "unknown section",
8677 reader
->abfd
->filename
);
8678 dump_die (result
, dwarf2_die_debug
);
8684 /* Read a single die and all its descendents. Set the die's sibling
8685 field to NULL; set other fields in the die correctly, and set all
8686 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
8687 location of the info_ptr after reading all of those dies. PARENT
8688 is the parent of the die in question. */
8690 static struct die_info
*
8691 read_die_and_children_1 (const struct die_reader_specs
*reader
,
8693 gdb_byte
**new_info_ptr
,
8694 struct die_info
*parent
)
8696 struct die_info
*die
;
8700 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
8703 *new_info_ptr
= cur_ptr
;
8706 store_in_ref_table (die
, reader
->cu
);
8709 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
8713 *new_info_ptr
= cur_ptr
;
8716 die
->sibling
= NULL
;
8717 die
->parent
= parent
;
8721 /* Read a die, all of its descendents, and all of its siblings; set
8722 all of the fields of all of the dies correctly. Arguments are as
8723 in read_die_and_children. */
8725 static struct die_info
*
8726 read_die_and_siblings (const struct die_reader_specs
*reader
,
8728 gdb_byte
**new_info_ptr
,
8729 struct die_info
*parent
)
8731 struct die_info
*first_die
, *last_sibling
;
8735 first_die
= last_sibling
= NULL
;
8739 struct die_info
*die
8740 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
8744 *new_info_ptr
= cur_ptr
;
8751 last_sibling
->sibling
= die
;
8757 /* Read the die from the .debug_info section buffer. Set DIEP to
8758 point to a newly allocated die with its information, except for its
8759 child, sibling, and parent fields. Set HAS_CHILDREN to tell
8760 whether the die has children or not. */
8763 read_full_die (const struct die_reader_specs
*reader
,
8764 struct die_info
**diep
, gdb_byte
*info_ptr
,
8767 unsigned int abbrev_number
, bytes_read
, i
, offset
;
8768 struct abbrev_info
*abbrev
;
8769 struct die_info
*die
;
8770 struct dwarf2_cu
*cu
= reader
->cu
;
8771 bfd
*abfd
= reader
->abfd
;
8773 offset
= info_ptr
- reader
->buffer
;
8774 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8775 info_ptr
+= bytes_read
;
8783 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
8785 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
8787 bfd_get_filename (abfd
));
8789 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
8790 die
->offset
= offset
;
8791 die
->tag
= abbrev
->tag
;
8792 die
->abbrev
= abbrev_number
;
8794 die
->num_attrs
= abbrev
->num_attrs
;
8796 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
8797 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
8798 abfd
, info_ptr
, cu
);
8801 *has_children
= abbrev
->has_children
;
8805 /* In DWARF version 2, the description of the debugging information is
8806 stored in a separate .debug_abbrev section. Before we read any
8807 dies from a section we read in all abbreviations and install them
8808 in a hash table. This function also sets flags in CU describing
8809 the data found in the abbrev table. */
8812 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
8814 struct comp_unit_head
*cu_header
= &cu
->header
;
8815 gdb_byte
*abbrev_ptr
;
8816 struct abbrev_info
*cur_abbrev
;
8817 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
8818 unsigned int abbrev_form
, hash_number
;
8819 struct attr_abbrev
*cur_attrs
;
8820 unsigned int allocated_attrs
;
8822 /* Initialize dwarf2 abbrevs. */
8823 obstack_init (&cu
->abbrev_obstack
);
8824 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
8826 * sizeof (struct abbrev_info
*)));
8827 memset (cu
->dwarf2_abbrevs
, 0,
8828 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
8830 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
8831 &dwarf2_per_objfile
->abbrev
);
8832 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
8833 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8834 abbrev_ptr
+= bytes_read
;
8836 allocated_attrs
= ATTR_ALLOC_CHUNK
;
8837 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
8839 /* Loop until we reach an abbrev number of 0. */
8840 while (abbrev_number
)
8842 cur_abbrev
= dwarf_alloc_abbrev (cu
);
8844 /* read in abbrev header */
8845 cur_abbrev
->number
= abbrev_number
;
8846 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8847 abbrev_ptr
+= bytes_read
;
8848 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
8851 if (cur_abbrev
->tag
== DW_TAG_namespace
)
8852 cu
->has_namespace_info
= 1;
8854 /* now read in declarations */
8855 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8856 abbrev_ptr
+= bytes_read
;
8857 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8858 abbrev_ptr
+= bytes_read
;
8861 if (cur_abbrev
->num_attrs
== allocated_attrs
)
8863 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
8865 = xrealloc (cur_attrs
, (allocated_attrs
8866 * sizeof (struct attr_abbrev
)));
8869 /* Record whether this compilation unit might have
8870 inter-compilation-unit references. If we don't know what form
8871 this attribute will have, then it might potentially be a
8872 DW_FORM_ref_addr, so we conservatively expect inter-CU
8875 if (abbrev_form
== DW_FORM_ref_addr
8876 || abbrev_form
== DW_FORM_indirect
)
8877 cu
->has_form_ref_addr
= 1;
8879 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
8880 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
8881 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8882 abbrev_ptr
+= bytes_read
;
8883 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8884 abbrev_ptr
+= bytes_read
;
8887 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
8888 (cur_abbrev
->num_attrs
8889 * sizeof (struct attr_abbrev
)));
8890 memcpy (cur_abbrev
->attrs
, cur_attrs
,
8891 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
8893 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
8894 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
8895 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
8897 /* Get next abbreviation.
8898 Under Irix6 the abbreviations for a compilation unit are not
8899 always properly terminated with an abbrev number of 0.
8900 Exit loop if we encounter an abbreviation which we have
8901 already read (which means we are about to read the abbreviations
8902 for the next compile unit) or if the end of the abbreviation
8903 table is reached. */
8904 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
8905 >= dwarf2_per_objfile
->abbrev
.size
)
8907 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8908 abbrev_ptr
+= bytes_read
;
8909 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
8916 /* Release the memory used by the abbrev table for a compilation unit. */
8919 dwarf2_free_abbrev_table (void *ptr_to_cu
)
8921 struct dwarf2_cu
*cu
= ptr_to_cu
;
8923 obstack_free (&cu
->abbrev_obstack
, NULL
);
8924 cu
->dwarf2_abbrevs
= NULL
;
8927 /* Lookup an abbrev_info structure in the abbrev hash table. */
8929 static struct abbrev_info
*
8930 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
8932 unsigned int hash_number
;
8933 struct abbrev_info
*abbrev
;
8935 hash_number
= number
% ABBREV_HASH_SIZE
;
8936 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
8940 if (abbrev
->number
== number
)
8943 abbrev
= abbrev
->next
;
8948 /* Returns nonzero if TAG represents a type that we might generate a partial
8952 is_type_tag_for_partial (int tag
)
8957 /* Some types that would be reasonable to generate partial symbols for,
8958 that we don't at present. */
8959 case DW_TAG_array_type
:
8960 case DW_TAG_file_type
:
8961 case DW_TAG_ptr_to_member_type
:
8962 case DW_TAG_set_type
:
8963 case DW_TAG_string_type
:
8964 case DW_TAG_subroutine_type
:
8966 case DW_TAG_base_type
:
8967 case DW_TAG_class_type
:
8968 case DW_TAG_interface_type
:
8969 case DW_TAG_enumeration_type
:
8970 case DW_TAG_structure_type
:
8971 case DW_TAG_subrange_type
:
8972 case DW_TAG_typedef
:
8973 case DW_TAG_union_type
:
8980 /* Load all DIEs that are interesting for partial symbols into memory. */
8982 static struct partial_die_info
*
8983 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
8984 int building_psymtab
, struct dwarf2_cu
*cu
)
8986 struct partial_die_info
*part_die
;
8987 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
8988 struct abbrev_info
*abbrev
;
8989 unsigned int bytes_read
;
8990 unsigned int load_all
= 0;
8992 int nesting_level
= 1;
8997 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
9001 = htab_create_alloc_ex (cu
->header
.length
/ 12,
9005 &cu
->comp_unit_obstack
,
9006 hashtab_obstack_allocate
,
9007 dummy_obstack_deallocate
);
9009 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9010 sizeof (struct partial_die_info
));
9014 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
9016 /* A NULL abbrev means the end of a series of children. */
9019 if (--nesting_level
== 0)
9021 /* PART_DIE was probably the last thing allocated on the
9022 comp_unit_obstack, so we could call obstack_free
9023 here. We don't do that because the waste is small,
9024 and will be cleaned up when we're done with this
9025 compilation unit. This way, we're also more robust
9026 against other users of the comp_unit_obstack. */
9029 info_ptr
+= bytes_read
;
9030 last_die
= parent_die
;
9031 parent_die
= parent_die
->die_parent
;
9035 /* Check for template arguments. We never save these; if
9036 they're seen, we just mark the parent, and go on our way. */
9037 if (parent_die
!= NULL
9038 && cu
->language
== language_cplus
9039 && (abbrev
->tag
== DW_TAG_template_type_param
9040 || abbrev
->tag
== DW_TAG_template_value_param
))
9042 parent_die
->has_template_arguments
= 1;
9046 /* We don't need a partial DIE for the template argument. */
9047 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
,
9053 /* We only recurse into subprograms looking for template arguments.
9054 Skip their other children. */
9056 && cu
->language
== language_cplus
9057 && parent_die
!= NULL
9058 && parent_die
->tag
== DW_TAG_subprogram
)
9060 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
9064 /* Check whether this DIE is interesting enough to save. Normally
9065 we would not be interested in members here, but there may be
9066 later variables referencing them via DW_AT_specification (for
9069 && !is_type_tag_for_partial (abbrev
->tag
)
9070 && abbrev
->tag
!= DW_TAG_constant
9071 && abbrev
->tag
!= DW_TAG_enumerator
9072 && abbrev
->tag
!= DW_TAG_subprogram
9073 && abbrev
->tag
!= DW_TAG_lexical_block
9074 && abbrev
->tag
!= DW_TAG_variable
9075 && abbrev
->tag
!= DW_TAG_namespace
9076 && abbrev
->tag
!= DW_TAG_module
9077 && abbrev
->tag
!= DW_TAG_member
)
9079 /* Otherwise we skip to the next sibling, if any. */
9080 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
9084 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
9085 buffer
, info_ptr
, cu
);
9087 /* This two-pass algorithm for processing partial symbols has a
9088 high cost in cache pressure. Thus, handle some simple cases
9089 here which cover the majority of C partial symbols. DIEs
9090 which neither have specification tags in them, nor could have
9091 specification tags elsewhere pointing at them, can simply be
9092 processed and discarded.
9094 This segment is also optional; scan_partial_symbols and
9095 add_partial_symbol will handle these DIEs if we chain
9096 them in normally. When compilers which do not emit large
9097 quantities of duplicate debug information are more common,
9098 this code can probably be removed. */
9100 /* Any complete simple types at the top level (pretty much all
9101 of them, for a language without namespaces), can be processed
9103 if (parent_die
== NULL
9104 && part_die
->has_specification
== 0
9105 && part_die
->is_declaration
== 0
9106 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
9107 || part_die
->tag
== DW_TAG_base_type
9108 || part_die
->tag
== DW_TAG_subrange_type
))
9110 if (building_psymtab
&& part_die
->name
!= NULL
)
9111 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9112 VAR_DOMAIN
, LOC_TYPEDEF
,
9113 &cu
->objfile
->static_psymbols
,
9114 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
9115 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9119 /* The exception for DW_TAG_typedef with has_children above is
9120 a workaround of GCC PR debug/47510. In the case of this complaint
9121 type_name_no_tag_or_error will error on such types later.
9123 GDB skipped children of DW_TAG_typedef by the shortcut above and then
9124 it could not find the child DIEs referenced later, this is checked
9125 above. In correct DWARF DW_TAG_typedef should have no children. */
9127 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
9128 complaint (&symfile_complaints
,
9129 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
9130 "- DIE at 0x%x [in module %s]"),
9131 part_die
->offset
, cu
->objfile
->name
);
9133 /* If we're at the second level, and we're an enumerator, and
9134 our parent has no specification (meaning possibly lives in a
9135 namespace elsewhere), then we can add the partial symbol now
9136 instead of queueing it. */
9137 if (part_die
->tag
== DW_TAG_enumerator
9138 && parent_die
!= NULL
9139 && parent_die
->die_parent
== NULL
9140 && parent_die
->tag
== DW_TAG_enumeration_type
9141 && parent_die
->has_specification
== 0)
9143 if (part_die
->name
== NULL
)
9144 complaint (&symfile_complaints
,
9145 _("malformed enumerator DIE ignored"));
9146 else if (building_psymtab
)
9147 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
9148 VAR_DOMAIN
, LOC_CONST
,
9149 (cu
->language
== language_cplus
9150 || cu
->language
== language_java
)
9151 ? &cu
->objfile
->global_psymbols
9152 : &cu
->objfile
->static_psymbols
,
9153 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
9155 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
9159 /* We'll save this DIE so link it in. */
9160 part_die
->die_parent
= parent_die
;
9161 part_die
->die_sibling
= NULL
;
9162 part_die
->die_child
= NULL
;
9164 if (last_die
&& last_die
== parent_die
)
9165 last_die
->die_child
= part_die
;
9167 last_die
->die_sibling
= part_die
;
9169 last_die
= part_die
;
9171 if (first_die
== NULL
)
9172 first_die
= part_die
;
9174 /* Maybe add the DIE to the hash table. Not all DIEs that we
9175 find interesting need to be in the hash table, because we
9176 also have the parent/sibling/child chains; only those that we
9177 might refer to by offset later during partial symbol reading.
9179 For now this means things that might have be the target of a
9180 DW_AT_specification, DW_AT_abstract_origin, or
9181 DW_AT_extension. DW_AT_extension will refer only to
9182 namespaces; DW_AT_abstract_origin refers to functions (and
9183 many things under the function DIE, but we do not recurse
9184 into function DIEs during partial symbol reading) and
9185 possibly variables as well; DW_AT_specification refers to
9186 declarations. Declarations ought to have the DW_AT_declaration
9187 flag. It happens that GCC forgets to put it in sometimes, but
9188 only for functions, not for types.
9190 Adding more things than necessary to the hash table is harmless
9191 except for the performance cost. Adding too few will result in
9192 wasted time in find_partial_die, when we reread the compilation
9193 unit with load_all_dies set. */
9196 || abbrev
->tag
== DW_TAG_constant
9197 || abbrev
->tag
== DW_TAG_subprogram
9198 || abbrev
->tag
== DW_TAG_variable
9199 || abbrev
->tag
== DW_TAG_namespace
9200 || part_die
->is_declaration
)
9204 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
9205 part_die
->offset
, INSERT
);
9209 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9210 sizeof (struct partial_die_info
));
9212 /* For some DIEs we want to follow their children (if any). For C
9213 we have no reason to follow the children of structures; for other
9214 languages we have to, so that we can get at method physnames
9215 to infer fully qualified class names, for DW_AT_specification,
9216 and for C++ template arguments. For C++, we also look one level
9217 inside functions to find template arguments (if the name of the
9218 function does not already contain the template arguments).
9220 For Ada, we need to scan the children of subprograms and lexical
9221 blocks as well because Ada allows the definition of nested
9222 entities that could be interesting for the debugger, such as
9223 nested subprograms for instance. */
9224 if (last_die
->has_children
9226 || last_die
->tag
== DW_TAG_namespace
9227 || last_die
->tag
== DW_TAG_module
9228 || last_die
->tag
== DW_TAG_enumeration_type
9229 || (cu
->language
== language_cplus
9230 && last_die
->tag
== DW_TAG_subprogram
9231 && (last_die
->name
== NULL
9232 || strchr (last_die
->name
, '<') == NULL
))
9233 || (cu
->language
!= language_c
9234 && (last_die
->tag
== DW_TAG_class_type
9235 || last_die
->tag
== DW_TAG_interface_type
9236 || last_die
->tag
== DW_TAG_structure_type
9237 || last_die
->tag
== DW_TAG_union_type
))
9238 || (cu
->language
== language_ada
9239 && (last_die
->tag
== DW_TAG_subprogram
9240 || last_die
->tag
== DW_TAG_lexical_block
))))
9243 parent_die
= last_die
;
9247 /* Otherwise we skip to the next sibling, if any. */
9248 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
9250 /* Back to the top, do it again. */
9254 /* Read a minimal amount of information into the minimal die structure. */
9257 read_partial_die (struct partial_die_info
*part_die
,
9258 struct abbrev_info
*abbrev
,
9259 unsigned int abbrev_len
, bfd
*abfd
,
9260 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9261 struct dwarf2_cu
*cu
)
9264 struct attribute attr
;
9265 int has_low_pc_attr
= 0;
9266 int has_high_pc_attr
= 0;
9268 memset (part_die
, 0, sizeof (struct partial_die_info
));
9270 part_die
->offset
= info_ptr
- buffer
;
9272 info_ptr
+= abbrev_len
;
9277 part_die
->tag
= abbrev
->tag
;
9278 part_die
->has_children
= abbrev
->has_children
;
9280 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9282 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
9284 /* Store the data if it is of an attribute we want to keep in a
9285 partial symbol table. */
9289 switch (part_die
->tag
)
9291 case DW_TAG_compile_unit
:
9292 case DW_TAG_type_unit
:
9293 /* Compilation units have a DW_AT_name that is a filename, not
9294 a source language identifier. */
9295 case DW_TAG_enumeration_type
:
9296 case DW_TAG_enumerator
:
9297 /* These tags always have simple identifiers already; no need
9298 to canonicalize them. */
9299 part_die
->name
= DW_STRING (&attr
);
9303 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
9304 &cu
->objfile
->objfile_obstack
);
9308 case DW_AT_linkage_name
:
9309 case DW_AT_MIPS_linkage_name
:
9310 /* Note that both forms of linkage name might appear. We
9311 assume they will be the same, and we only store the last
9313 if (cu
->language
== language_ada
)
9314 part_die
->name
= DW_STRING (&attr
);
9315 part_die
->linkage_name
= DW_STRING (&attr
);
9318 has_low_pc_attr
= 1;
9319 part_die
->lowpc
= DW_ADDR (&attr
);
9322 has_high_pc_attr
= 1;
9323 part_die
->highpc
= DW_ADDR (&attr
);
9325 case DW_AT_location
:
9326 /* Support the .debug_loc offsets. */
9327 if (attr_form_is_block (&attr
))
9329 part_die
->locdesc
= DW_BLOCK (&attr
);
9331 else if (attr_form_is_section_offset (&attr
))
9333 dwarf2_complex_location_expr_complaint ();
9337 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9338 "partial symbol information");
9341 case DW_AT_external
:
9342 part_die
->is_external
= DW_UNSND (&attr
);
9344 case DW_AT_declaration
:
9345 part_die
->is_declaration
= DW_UNSND (&attr
);
9348 part_die
->has_type
= 1;
9350 case DW_AT_abstract_origin
:
9351 case DW_AT_specification
:
9352 case DW_AT_extension
:
9353 part_die
->has_specification
= 1;
9354 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
9357 /* Ignore absolute siblings, they might point outside of
9358 the current compile unit. */
9359 if (attr
.form
== DW_FORM_ref_addr
)
9360 complaint (&symfile_complaints
,
9361 _("ignoring absolute DW_AT_sibling"));
9363 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
9365 case DW_AT_byte_size
:
9366 part_die
->has_byte_size
= 1;
9368 case DW_AT_calling_convention
:
9369 /* DWARF doesn't provide a way to identify a program's source-level
9370 entry point. DW_AT_calling_convention attributes are only meant
9371 to describe functions' calling conventions.
9373 However, because it's a necessary piece of information in
9374 Fortran, and because DW_CC_program is the only piece of debugging
9375 information whose definition refers to a 'main program' at all,
9376 several compilers have begun marking Fortran main programs with
9377 DW_CC_program --- even when those functions use the standard
9378 calling conventions.
9380 So until DWARF specifies a way to provide this information and
9381 compilers pick up the new representation, we'll support this
9383 if (DW_UNSND (&attr
) == DW_CC_program
9384 && cu
->language
== language_fortran
)
9386 set_main_name (part_die
->name
);
9388 /* As this DIE has a static linkage the name would be difficult
9389 to look up later. */
9390 language_of_main
= language_fortran
;
9398 if (has_low_pc_attr
&& has_high_pc_attr
)
9400 /* When using the GNU linker, .gnu.linkonce. sections are used to
9401 eliminate duplicate copies of functions and vtables and such.
9402 The linker will arbitrarily choose one and discard the others.
9403 The AT_*_pc values for such functions refer to local labels in
9404 these sections. If the section from that file was discarded, the
9405 labels are not in the output, so the relocs get a value of 0.
9406 If this is a discarded function, mark the pc bounds as invalid,
9407 so that GDB will ignore it. */
9408 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
9410 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
9412 complaint (&symfile_complaints
,
9413 _("DW_AT_low_pc %s is zero "
9414 "for DIE at 0x%x [in module %s]"),
9415 paddress (gdbarch
, part_die
->lowpc
),
9416 part_die
->offset
, cu
->objfile
->name
);
9418 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
9419 else if (part_die
->lowpc
>= part_die
->highpc
)
9421 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
9423 complaint (&symfile_complaints
,
9424 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
9425 "for DIE at 0x%x [in module %s]"),
9426 paddress (gdbarch
, part_die
->lowpc
),
9427 paddress (gdbarch
, part_die
->highpc
),
9428 part_die
->offset
, cu
->objfile
->name
);
9431 part_die
->has_pc_info
= 1;
9437 /* Find a cached partial DIE at OFFSET in CU. */
9439 static struct partial_die_info
*
9440 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
9442 struct partial_die_info
*lookup_die
= NULL
;
9443 struct partial_die_info part_die
;
9445 part_die
.offset
= offset
;
9446 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
9451 /* Find a partial DIE at OFFSET, which may or may not be in CU,
9452 except in the case of .debug_types DIEs which do not reference
9453 outside their CU (they do however referencing other types via
9454 DW_FORM_ref_sig8). */
9456 static struct partial_die_info
*
9457 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
9459 struct dwarf2_per_cu_data
*per_cu
= NULL
;
9460 struct partial_die_info
*pd
= NULL
;
9462 if (cu
->per_cu
->from_debug_types
)
9464 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9470 if (offset_in_cu_p (&cu
->header
, offset
))
9472 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9477 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
9479 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
9480 load_partial_comp_unit (per_cu
, cu
->objfile
);
9482 per_cu
->cu
->last_used
= 0;
9483 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
9485 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
9487 struct cleanup
*back_to
;
9488 struct partial_die_info comp_unit_die
;
9489 struct abbrev_info
*abbrev
;
9490 unsigned int bytes_read
;
9493 per_cu
->load_all_dies
= 1;
9495 /* Re-read the DIEs. */
9496 back_to
= make_cleanup (null_cleanup
, 0);
9497 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
9499 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
9500 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
9502 info_ptr
= (dwarf2_per_objfile
->info
.buffer
9503 + per_cu
->cu
->header
.offset
9504 + per_cu
->cu
->header
.first_die_offset
);
9505 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
9506 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
9507 per_cu
->cu
->objfile
->obfd
,
9508 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
9510 if (comp_unit_die
.has_children
)
9511 load_partial_dies (per_cu
->cu
->objfile
->obfd
,
9512 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
9514 do_cleanups (back_to
);
9516 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
9522 internal_error (__FILE__
, __LINE__
,
9523 _("could not find partial DIE 0x%x "
9524 "in cache [from module %s]\n"),
9525 offset
, bfd_get_filename (cu
->objfile
->obfd
));
9529 /* See if we can figure out if the class lives in a namespace. We do
9530 this by looking for a member function; its demangled name will
9531 contain namespace info, if there is any. */
9534 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
9535 struct dwarf2_cu
*cu
)
9537 /* NOTE: carlton/2003-10-07: Getting the info this way changes
9538 what template types look like, because the demangler
9539 frequently doesn't give the same name as the debug info. We
9540 could fix this by only using the demangled name to get the
9541 prefix (but see comment in read_structure_type). */
9543 struct partial_die_info
*real_pdi
;
9544 struct partial_die_info
*child_pdi
;
9546 /* If this DIE (this DIE's specification, if any) has a parent, then
9547 we should not do this. We'll prepend the parent's fully qualified
9548 name when we create the partial symbol. */
9550 real_pdi
= struct_pdi
;
9551 while (real_pdi
->has_specification
)
9552 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
9554 if (real_pdi
->die_parent
!= NULL
)
9557 for (child_pdi
= struct_pdi
->die_child
;
9559 child_pdi
= child_pdi
->die_sibling
)
9561 if (child_pdi
->tag
== DW_TAG_subprogram
9562 && child_pdi
->linkage_name
!= NULL
)
9564 char *actual_class_name
9565 = language_class_name_from_physname (cu
->language_defn
,
9566 child_pdi
->linkage_name
);
9567 if (actual_class_name
!= NULL
)
9570 = obsavestring (actual_class_name
,
9571 strlen (actual_class_name
),
9572 &cu
->objfile
->objfile_obstack
);
9573 xfree (actual_class_name
);
9580 /* Adjust PART_DIE before generating a symbol for it. This function
9581 may set the is_external flag or change the DIE's name. */
9584 fixup_partial_die (struct partial_die_info
*part_die
,
9585 struct dwarf2_cu
*cu
)
9587 /* Once we've fixed up a die, there's no point in doing so again.
9588 This also avoids a memory leak if we were to call
9589 guess_partial_die_structure_name multiple times. */
9590 if (part_die
->fixup_called
)
9593 /* If we found a reference attribute and the DIE has no name, try
9594 to find a name in the referred to DIE. */
9596 if (part_die
->name
== NULL
&& part_die
->has_specification
)
9598 struct partial_die_info
*spec_die
;
9600 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
9602 fixup_partial_die (spec_die
, cu
);
9606 part_die
->name
= spec_die
->name
;
9608 /* Copy DW_AT_external attribute if it is set. */
9609 if (spec_die
->is_external
)
9610 part_die
->is_external
= spec_die
->is_external
;
9614 /* Set default names for some unnamed DIEs. */
9616 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
9617 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
9619 /* If there is no parent die to provide a namespace, and there are
9620 children, see if we can determine the namespace from their linkage
9622 NOTE: We need to do this even if cu->has_namespace_info != 0.
9623 gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */
9624 if (cu
->language
== language_cplus
9625 && dwarf2_per_objfile
->types
.asection
!= NULL
9626 && part_die
->die_parent
== NULL
9627 && part_die
->has_children
9628 && (part_die
->tag
== DW_TAG_class_type
9629 || part_die
->tag
== DW_TAG_structure_type
9630 || part_die
->tag
== DW_TAG_union_type
))
9631 guess_partial_die_structure_name (part_die
, cu
);
9633 /* GCC might emit a nameless struct or union that has a linkage
9634 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
9635 if (part_die
->name
== NULL
9636 && (part_die
->tag
== DW_TAG_structure_type
9637 || part_die
->tag
== DW_TAG_union_type
9638 || part_die
->tag
== DW_TAG_class_type
)
9639 && part_die
->linkage_name
!= NULL
)
9643 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
9646 part_die
->name
= obsavestring (demangled
, strlen (demangled
),
9647 &cu
->objfile
->objfile_obstack
);
9652 part_die
->fixup_called
= 1;
9655 /* Read an attribute value described by an attribute form. */
9658 read_attribute_value (struct attribute
*attr
, unsigned form
,
9659 bfd
*abfd
, gdb_byte
*info_ptr
,
9660 struct dwarf2_cu
*cu
)
9662 struct comp_unit_head
*cu_header
= &cu
->header
;
9663 unsigned int bytes_read
;
9664 struct dwarf_block
*blk
;
9669 case DW_FORM_ref_addr
:
9670 if (cu
->header
.version
== 2)
9671 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9673 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
,
9674 &cu
->header
, &bytes_read
);
9675 info_ptr
+= bytes_read
;
9678 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9679 info_ptr
+= bytes_read
;
9681 case DW_FORM_block2
:
9682 blk
= dwarf_alloc_block (cu
);
9683 blk
->size
= read_2_bytes (abfd
, info_ptr
);
9685 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9686 info_ptr
+= blk
->size
;
9687 DW_BLOCK (attr
) = blk
;
9689 case DW_FORM_block4
:
9690 blk
= dwarf_alloc_block (cu
);
9691 blk
->size
= read_4_bytes (abfd
, info_ptr
);
9693 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9694 info_ptr
+= blk
->size
;
9695 DW_BLOCK (attr
) = blk
;
9698 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
9702 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
9706 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
9709 case DW_FORM_sec_offset
:
9710 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
9711 info_ptr
+= bytes_read
;
9713 case DW_FORM_string
:
9714 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
9715 DW_STRING_IS_CANONICAL (attr
) = 0;
9716 info_ptr
+= bytes_read
;
9719 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
9721 DW_STRING_IS_CANONICAL (attr
) = 0;
9722 info_ptr
+= bytes_read
;
9724 case DW_FORM_exprloc
:
9726 blk
= dwarf_alloc_block (cu
);
9727 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9728 info_ptr
+= bytes_read
;
9729 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9730 info_ptr
+= blk
->size
;
9731 DW_BLOCK (attr
) = blk
;
9733 case DW_FORM_block1
:
9734 blk
= dwarf_alloc_block (cu
);
9735 blk
->size
= read_1_byte (abfd
, info_ptr
);
9737 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9738 info_ptr
+= blk
->size
;
9739 DW_BLOCK (attr
) = blk
;
9742 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9746 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9749 case DW_FORM_flag_present
:
9750 DW_UNSND (attr
) = 1;
9753 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
9754 info_ptr
+= bytes_read
;
9757 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9758 info_ptr
+= bytes_read
;
9761 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
9765 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
9769 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
9773 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
9776 case DW_FORM_ref_sig8
:
9777 /* Convert the signature to something we can record in DW_UNSND
9779 NOTE: This is NULL if the type wasn't found. */
9780 DW_SIGNATURED_TYPE (attr
) =
9781 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
9784 case DW_FORM_ref_udata
:
9785 DW_ADDR (attr
) = (cu
->header
.offset
9786 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
9787 info_ptr
+= bytes_read
;
9789 case DW_FORM_indirect
:
9790 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9791 info_ptr
+= bytes_read
;
9792 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
9795 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
9796 dwarf_form_name (form
),
9797 bfd_get_filename (abfd
));
9800 /* We have seen instances where the compiler tried to emit a byte
9801 size attribute of -1 which ended up being encoded as an unsigned
9802 0xffffffff. Although 0xffffffff is technically a valid size value,
9803 an object of this size seems pretty unlikely so we can relatively
9804 safely treat these cases as if the size attribute was invalid and
9805 treat them as zero by default. */
9806 if (attr
->name
== DW_AT_byte_size
9807 && form
== DW_FORM_data4
9808 && DW_UNSND (attr
) >= 0xffffffff)
9811 (&symfile_complaints
,
9812 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
9813 hex_string (DW_UNSND (attr
)));
9814 DW_UNSND (attr
) = 0;
9820 /* Read an attribute described by an abbreviated attribute. */
9823 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
9824 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
9826 attr
->name
= abbrev
->name
;
9827 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
9830 /* Read dwarf information from a buffer. */
9833 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
9835 return bfd_get_8 (abfd
, buf
);
9839 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
9841 return bfd_get_signed_8 (abfd
, buf
);
9845 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
9847 return bfd_get_16 (abfd
, buf
);
9851 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
9853 return bfd_get_signed_16 (abfd
, buf
);
9857 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
9859 return bfd_get_32 (abfd
, buf
);
9863 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
9865 return bfd_get_signed_32 (abfd
, buf
);
9869 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
9871 return bfd_get_64 (abfd
, buf
);
9875 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
9876 unsigned int *bytes_read
)
9878 struct comp_unit_head
*cu_header
= &cu
->header
;
9879 CORE_ADDR retval
= 0;
9881 if (cu_header
->signed_addr_p
)
9883 switch (cu_header
->addr_size
)
9886 retval
= bfd_get_signed_16 (abfd
, buf
);
9889 retval
= bfd_get_signed_32 (abfd
, buf
);
9892 retval
= bfd_get_signed_64 (abfd
, buf
);
9895 internal_error (__FILE__
, __LINE__
,
9896 _("read_address: bad switch, signed [in module %s]"),
9897 bfd_get_filename (abfd
));
9902 switch (cu_header
->addr_size
)
9905 retval
= bfd_get_16 (abfd
, buf
);
9908 retval
= bfd_get_32 (abfd
, buf
);
9911 retval
= bfd_get_64 (abfd
, buf
);
9914 internal_error (__FILE__
, __LINE__
,
9915 _("read_address: bad switch, "
9916 "unsigned [in module %s]"),
9917 bfd_get_filename (abfd
));
9921 *bytes_read
= cu_header
->addr_size
;
9925 /* Read the initial length from a section. The (draft) DWARF 3
9926 specification allows the initial length to take up either 4 bytes
9927 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
9928 bytes describe the length and all offsets will be 8 bytes in length
9931 An older, non-standard 64-bit format is also handled by this
9932 function. The older format in question stores the initial length
9933 as an 8-byte quantity without an escape value. Lengths greater
9934 than 2^32 aren't very common which means that the initial 4 bytes
9935 is almost always zero. Since a length value of zero doesn't make
9936 sense for the 32-bit format, this initial zero can be considered to
9937 be an escape value which indicates the presence of the older 64-bit
9938 format. As written, the code can't detect (old format) lengths
9939 greater than 4GB. If it becomes necessary to handle lengths
9940 somewhat larger than 4GB, we could allow other small values (such
9941 as the non-sensical values of 1, 2, and 3) to also be used as
9942 escape values indicating the presence of the old format.
9944 The value returned via bytes_read should be used to increment the
9945 relevant pointer after calling read_initial_length().
9947 [ Note: read_initial_length() and read_offset() are based on the
9948 document entitled "DWARF Debugging Information Format", revision
9949 3, draft 8, dated November 19, 2001. This document was obtained
9952 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
9954 This document is only a draft and is subject to change. (So beware.)
9956 Details regarding the older, non-standard 64-bit format were
9957 determined empirically by examining 64-bit ELF files produced by
9958 the SGI toolchain on an IRIX 6.5 machine.
9960 - Kevin, July 16, 2002
9964 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
9966 LONGEST length
= bfd_get_32 (abfd
, buf
);
9968 if (length
== 0xffffffff)
9970 length
= bfd_get_64 (abfd
, buf
+ 4);
9973 else if (length
== 0)
9975 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
9976 length
= bfd_get_64 (abfd
, buf
);
9987 /* Cover function for read_initial_length.
9988 Returns the length of the object at BUF, and stores the size of the
9989 initial length in *BYTES_READ and stores the size that offsets will be in
9991 If the initial length size is not equivalent to that specified in
9992 CU_HEADER then issue a complaint.
9993 This is useful when reading non-comp-unit headers. */
9996 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
9997 const struct comp_unit_head
*cu_header
,
9998 unsigned int *bytes_read
,
9999 unsigned int *offset_size
)
10001 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
10003 gdb_assert (cu_header
->initial_length_size
== 4
10004 || cu_header
->initial_length_size
== 8
10005 || cu_header
->initial_length_size
== 12);
10007 if (cu_header
->initial_length_size
!= *bytes_read
)
10008 complaint (&symfile_complaints
,
10009 _("intermixed 32-bit and 64-bit DWARF sections"));
10011 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
10015 /* Read an offset from the data stream. The size of the offset is
10016 given by cu_header->offset_size. */
10019 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
10020 unsigned int *bytes_read
)
10022 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
10024 *bytes_read
= cu_header
->offset_size
;
10028 /* Read an offset from the data stream. */
10031 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
10033 LONGEST retval
= 0;
10035 switch (offset_size
)
10038 retval
= bfd_get_32 (abfd
, buf
);
10041 retval
= bfd_get_64 (abfd
, buf
);
10044 internal_error (__FILE__
, __LINE__
,
10045 _("read_offset_1: bad switch [in module %s]"),
10046 bfd_get_filename (abfd
));
10053 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
10055 /* If the size of a host char is 8 bits, we can return a pointer
10056 to the buffer, otherwise we have to copy the data to a buffer
10057 allocated on the temporary obstack. */
10058 gdb_assert (HOST_CHAR_BIT
== 8);
10063 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10065 /* If the size of a host char is 8 bits, we can return a pointer
10066 to the string, otherwise we have to copy the string to a buffer
10067 allocated on the temporary obstack. */
10068 gdb_assert (HOST_CHAR_BIT
== 8);
10071 *bytes_read_ptr
= 1;
10074 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
10075 return (char *) buf
;
10079 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
10080 const struct comp_unit_head
*cu_header
,
10081 unsigned int *bytes_read_ptr
)
10083 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
10085 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
10086 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
10088 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
10089 bfd_get_filename (abfd
));
10092 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
10094 error (_("DW_FORM_strp pointing outside of "
10095 ".debug_str section [in module %s]"),
10096 bfd_get_filename (abfd
));
10099 gdb_assert (HOST_CHAR_BIT
== 8);
10100 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
10102 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
10105 static unsigned long
10106 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10108 unsigned long result
;
10109 unsigned int num_read
;
10111 unsigned char byte
;
10119 byte
= bfd_get_8 (abfd
, buf
);
10122 result
|= ((unsigned long)(byte
& 127) << shift
);
10123 if ((byte
& 128) == 0)
10129 *bytes_read_ptr
= num_read
;
10134 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
10137 int i
, shift
, num_read
;
10138 unsigned char byte
;
10146 byte
= bfd_get_8 (abfd
, buf
);
10149 result
|= ((long)(byte
& 127) << shift
);
10151 if ((byte
& 128) == 0)
10156 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
10157 result
|= -(((long)1) << shift
);
10158 *bytes_read_ptr
= num_read
;
10162 /* Return a pointer to just past the end of an LEB128 number in BUF. */
10165 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
10171 byte
= bfd_get_8 (abfd
, buf
);
10173 if ((byte
& 128) == 0)
10179 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
10186 cu
->language
= language_c
;
10188 case DW_LANG_C_plus_plus
:
10189 cu
->language
= language_cplus
;
10192 cu
->language
= language_d
;
10194 case DW_LANG_Fortran77
:
10195 case DW_LANG_Fortran90
:
10196 case DW_LANG_Fortran95
:
10197 cu
->language
= language_fortran
;
10199 case DW_LANG_Mips_Assembler
:
10200 cu
->language
= language_asm
;
10203 cu
->language
= language_java
;
10205 case DW_LANG_Ada83
:
10206 case DW_LANG_Ada95
:
10207 cu
->language
= language_ada
;
10209 case DW_LANG_Modula2
:
10210 cu
->language
= language_m2
;
10212 case DW_LANG_Pascal83
:
10213 cu
->language
= language_pascal
;
10216 cu
->language
= language_objc
;
10218 case DW_LANG_Cobol74
:
10219 case DW_LANG_Cobol85
:
10221 cu
->language
= language_minimal
;
10224 cu
->language_defn
= language_def (cu
->language
);
10227 /* Return the named attribute or NULL if not there. */
10229 static struct attribute
*
10230 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
10233 struct attribute
*spec
= NULL
;
10235 for (i
= 0; i
< die
->num_attrs
; ++i
)
10237 if (die
->attrs
[i
].name
== name
)
10238 return &die
->attrs
[i
];
10239 if (die
->attrs
[i
].name
== DW_AT_specification
10240 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
10241 spec
= &die
->attrs
[i
];
10246 die
= follow_die_ref (die
, spec
, &cu
);
10247 return dwarf2_attr (die
, name
, cu
);
10253 /* Return the named attribute or NULL if not there,
10254 but do not follow DW_AT_specification, etc.
10255 This is for use in contexts where we're reading .debug_types dies.
10256 Following DW_AT_specification, DW_AT_abstract_origin will take us
10257 back up the chain, and we want to go down. */
10259 static struct attribute
*
10260 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
10261 struct dwarf2_cu
*cu
)
10265 for (i
= 0; i
< die
->num_attrs
; ++i
)
10266 if (die
->attrs
[i
].name
== name
)
10267 return &die
->attrs
[i
];
10272 /* Return non-zero iff the attribute NAME is defined for the given DIE,
10273 and holds a non-zero value. This function should only be used for
10274 DW_FORM_flag or DW_FORM_flag_present attributes. */
10277 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
10279 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
10281 return (attr
&& DW_UNSND (attr
));
10285 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
10287 /* A DIE is a declaration if it has a DW_AT_declaration attribute
10288 which value is non-zero. However, we have to be careful with
10289 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
10290 (via dwarf2_flag_true_p) follows this attribute. So we may
10291 end up accidently finding a declaration attribute that belongs
10292 to a different DIE referenced by the specification attribute,
10293 even though the given DIE does not have a declaration attribute. */
10294 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
10295 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
10298 /* Return the die giving the specification for DIE, if there is
10299 one. *SPEC_CU is the CU containing DIE on input, and the CU
10300 containing the return value on output. If there is no
10301 specification, but there is an abstract origin, that is
10304 static struct die_info
*
10305 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
10307 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
10310 if (spec_attr
== NULL
)
10311 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
10313 if (spec_attr
== NULL
)
10316 return follow_die_ref (die
, spec_attr
, spec_cu
);
10319 /* Free the line_header structure *LH, and any arrays and strings it
10321 NOTE: This is also used as a "cleanup" function. */
10324 free_line_header (struct line_header
*lh
)
10326 if (lh
->standard_opcode_lengths
)
10327 xfree (lh
->standard_opcode_lengths
);
10329 /* Remember that all the lh->file_names[i].name pointers are
10330 pointers into debug_line_buffer, and don't need to be freed. */
10331 if (lh
->file_names
)
10332 xfree (lh
->file_names
);
10334 /* Similarly for the include directory names. */
10335 if (lh
->include_dirs
)
10336 xfree (lh
->include_dirs
);
10341 /* Add an entry to LH's include directory table. */
10344 add_include_dir (struct line_header
*lh
, char *include_dir
)
10346 /* Grow the array if necessary. */
10347 if (lh
->include_dirs_size
== 0)
10349 lh
->include_dirs_size
= 1; /* for testing */
10350 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
10351 * sizeof (*lh
->include_dirs
));
10353 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
10355 lh
->include_dirs_size
*= 2;
10356 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
10357 (lh
->include_dirs_size
10358 * sizeof (*lh
->include_dirs
)));
10361 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
10364 /* Add an entry to LH's file name table. */
10367 add_file_name (struct line_header
*lh
,
10369 unsigned int dir_index
,
10370 unsigned int mod_time
,
10371 unsigned int length
)
10373 struct file_entry
*fe
;
10375 /* Grow the array if necessary. */
10376 if (lh
->file_names_size
== 0)
10378 lh
->file_names_size
= 1; /* for testing */
10379 lh
->file_names
= xmalloc (lh
->file_names_size
10380 * sizeof (*lh
->file_names
));
10382 else if (lh
->num_file_names
>= lh
->file_names_size
)
10384 lh
->file_names_size
*= 2;
10385 lh
->file_names
= xrealloc (lh
->file_names
,
10386 (lh
->file_names_size
10387 * sizeof (*lh
->file_names
)));
10390 fe
= &lh
->file_names
[lh
->num_file_names
++];
10392 fe
->dir_index
= dir_index
;
10393 fe
->mod_time
= mod_time
;
10394 fe
->length
= length
;
10395 fe
->included_p
= 0;
10399 /* Read the statement program header starting at OFFSET in
10400 .debug_line, according to the endianness of ABFD. Return a pointer
10401 to a struct line_header, allocated using xmalloc.
10403 NOTE: the strings in the include directory and file name tables of
10404 the returned object point into debug_line_buffer, and must not be
10407 static struct line_header
*
10408 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
10409 struct dwarf2_cu
*cu
)
10411 struct cleanup
*back_to
;
10412 struct line_header
*lh
;
10413 gdb_byte
*line_ptr
;
10414 unsigned int bytes_read
, offset_size
;
10416 char *cur_dir
, *cur_file
;
10418 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
10419 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
10421 complaint (&symfile_complaints
, _("missing .debug_line section"));
10425 /* Make sure that at least there's room for the total_length field.
10426 That could be 12 bytes long, but we're just going to fudge that. */
10427 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
10429 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10433 lh
= xmalloc (sizeof (*lh
));
10434 memset (lh
, 0, sizeof (*lh
));
10435 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
10438 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
10440 /* Read in the header. */
10442 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
10443 &bytes_read
, &offset_size
);
10444 line_ptr
+= bytes_read
;
10445 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
10446 + dwarf2_per_objfile
->line
.size
))
10448 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10451 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
10452 lh
->version
= read_2_bytes (abfd
, line_ptr
);
10454 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
10455 line_ptr
+= offset_size
;
10456 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
10458 if (lh
->version
>= 4)
10460 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
10464 lh
->maximum_ops_per_instruction
= 1;
10466 if (lh
->maximum_ops_per_instruction
== 0)
10468 lh
->maximum_ops_per_instruction
= 1;
10469 complaint (&symfile_complaints
,
10470 _("invalid maximum_ops_per_instruction "
10471 "in `.debug_line' section"));
10474 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
10476 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
10478 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
10480 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
10482 lh
->standard_opcode_lengths
10483 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
10485 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
10486 for (i
= 1; i
< lh
->opcode_base
; ++i
)
10488 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
10492 /* Read directory table. */
10493 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
10495 line_ptr
+= bytes_read
;
10496 add_include_dir (lh
, cur_dir
);
10498 line_ptr
+= bytes_read
;
10500 /* Read file name table. */
10501 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
10503 unsigned int dir_index
, mod_time
, length
;
10505 line_ptr
+= bytes_read
;
10506 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10507 line_ptr
+= bytes_read
;
10508 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10509 line_ptr
+= bytes_read
;
10510 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10511 line_ptr
+= bytes_read
;
10513 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
10515 line_ptr
+= bytes_read
;
10516 lh
->statement_program_start
= line_ptr
;
10518 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
10519 + dwarf2_per_objfile
->line
.size
))
10520 complaint (&symfile_complaints
,
10521 _("line number info header doesn't "
10522 "fit in `.debug_line' section"));
10524 discard_cleanups (back_to
);
10528 /* This function exists to work around a bug in certain compilers
10529 (particularly GCC 2.95), in which the first line number marker of a
10530 function does not show up until after the prologue, right before
10531 the second line number marker. This function shifts ADDRESS down
10532 to the beginning of the function if necessary, and is called on
10533 addresses passed to record_line. */
10536 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
10538 struct function_range
*fn
;
10540 /* Find the function_range containing address. */
10544 if (!cu
->cached_fn
)
10545 cu
->cached_fn
= cu
->first_fn
;
10547 fn
= cu
->cached_fn
;
10549 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
10555 while (fn
&& fn
!= cu
->cached_fn
)
10556 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
10566 if (address
!= fn
->lowpc
)
10567 complaint (&symfile_complaints
,
10568 _("misplaced first line number at 0x%lx for '%s'"),
10569 (unsigned long) address
, fn
->name
);
10574 /* Subroutine of dwarf_decode_lines to simplify it.
10575 Return the file name of the psymtab for included file FILE_INDEX
10576 in line header LH of PST.
10577 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10578 If space for the result is malloc'd, it will be freed by a cleanup.
10579 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
10582 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
10583 const struct partial_symtab
*pst
,
10584 const char *comp_dir
)
10586 const struct file_entry fe
= lh
->file_names
[file_index
];
10587 char *include_name
= fe
.name
;
10588 char *include_name_to_compare
= include_name
;
10589 char *dir_name
= NULL
;
10590 const char *pst_filename
;
10591 char *copied_name
= NULL
;
10595 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
10597 if (!IS_ABSOLUTE_PATH (include_name
)
10598 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
10600 /* Avoid creating a duplicate psymtab for PST.
10601 We do this by comparing INCLUDE_NAME and PST_FILENAME.
10602 Before we do the comparison, however, we need to account
10603 for DIR_NAME and COMP_DIR.
10604 First prepend dir_name (if non-NULL). If we still don't
10605 have an absolute path prepend comp_dir (if non-NULL).
10606 However, the directory we record in the include-file's
10607 psymtab does not contain COMP_DIR (to match the
10608 corresponding symtab(s)).
10613 bash$ gcc -g ./hello.c
10614 include_name = "hello.c"
10616 DW_AT_comp_dir = comp_dir = "/tmp"
10617 DW_AT_name = "./hello.c" */
10619 if (dir_name
!= NULL
)
10621 include_name
= concat (dir_name
, SLASH_STRING
,
10622 include_name
, (char *)NULL
);
10623 include_name_to_compare
= include_name
;
10624 make_cleanup (xfree
, include_name
);
10626 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
10628 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
10629 include_name
, (char *)NULL
);
10633 pst_filename
= pst
->filename
;
10634 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
10636 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
10637 pst_filename
, (char *)NULL
);
10638 pst_filename
= copied_name
;
10641 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
10643 if (include_name_to_compare
!= include_name
)
10644 xfree (include_name_to_compare
);
10645 if (copied_name
!= NULL
)
10646 xfree (copied_name
);
10650 return include_name
;
10653 /* Ignore this record_line request. */
10656 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
10661 /* Decode the Line Number Program (LNP) for the given line_header
10662 structure and CU. The actual information extracted and the type
10663 of structures created from the LNP depends on the value of PST.
10665 1. If PST is NULL, then this procedure uses the data from the program
10666 to create all necessary symbol tables, and their linetables.
10668 2. If PST is not NULL, this procedure reads the program to determine
10669 the list of files included by the unit represented by PST, and
10670 builds all the associated partial symbol tables.
10672 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10673 It is used for relative paths in the line table.
10674 NOTE: When processing partial symtabs (pst != NULL),
10675 comp_dir == pst->dirname.
10677 NOTE: It is important that psymtabs have the same file name (via strcmp)
10678 as the corresponding symtab. Since COMP_DIR is not used in the name of the
10679 symtab we don't use it in the name of the psymtabs we create.
10680 E.g. expand_line_sal requires this when finding psymtabs to expand.
10681 A good testcase for this is mb-inline.exp. */
10684 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
, bfd
*abfd
,
10685 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
10687 gdb_byte
*line_ptr
, *extended_end
;
10688 gdb_byte
*line_end
;
10689 unsigned int bytes_read
, extended_len
;
10690 unsigned char op_code
, extended_op
, adj_opcode
;
10691 CORE_ADDR baseaddr
;
10692 struct objfile
*objfile
= cu
->objfile
;
10693 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10694 const int decode_for_pst_p
= (pst
!= NULL
);
10695 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
10696 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
10699 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10701 line_ptr
= lh
->statement_program_start
;
10702 line_end
= lh
->statement_program_end
;
10704 /* Read the statement sequences until there's nothing left. */
10705 while (line_ptr
< line_end
)
10707 /* state machine registers */
10708 CORE_ADDR address
= 0;
10709 unsigned int file
= 1;
10710 unsigned int line
= 1;
10711 unsigned int column
= 0;
10712 int is_stmt
= lh
->default_is_stmt
;
10713 int basic_block
= 0;
10714 int end_sequence
= 0;
10716 unsigned char op_index
= 0;
10718 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
10720 /* Start a subfile for the current file of the state machine. */
10721 /* lh->include_dirs and lh->file_names are 0-based, but the
10722 directory and file name numbers in the statement program
10724 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
10728 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10730 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10733 /* Decode the table. */
10734 while (!end_sequence
)
10736 op_code
= read_1_byte (abfd
, line_ptr
);
10738 if (line_ptr
> line_end
)
10740 dwarf2_debug_line_missing_end_sequence_complaint ();
10744 if (op_code
>= lh
->opcode_base
)
10746 /* Special operand. */
10747 adj_opcode
= op_code
- lh
->opcode_base
;
10748 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
10749 / lh
->maximum_ops_per_instruction
)
10750 * lh
->minimum_instruction_length
);
10751 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
10752 % lh
->maximum_ops_per_instruction
);
10753 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
10754 if (lh
->num_file_names
< file
|| file
== 0)
10755 dwarf2_debug_line_missing_file_complaint ();
10756 /* For now we ignore lines not starting on an
10757 instruction boundary. */
10758 else if (op_index
== 0)
10760 lh
->file_names
[file
- 1].included_p
= 1;
10761 if (!decode_for_pst_p
&& is_stmt
)
10763 if (last_subfile
!= current_subfile
)
10765 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10767 (*p_record_line
) (last_subfile
, 0, addr
);
10768 last_subfile
= current_subfile
;
10770 /* Append row to matrix using current values. */
10771 addr
= check_cu_functions (address
, cu
);
10772 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
10773 (*p_record_line
) (current_subfile
, line
, addr
);
10778 else switch (op_code
)
10780 case DW_LNS_extended_op
:
10781 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
10783 line_ptr
+= bytes_read
;
10784 extended_end
= line_ptr
+ extended_len
;
10785 extended_op
= read_1_byte (abfd
, line_ptr
);
10787 switch (extended_op
)
10789 case DW_LNE_end_sequence
:
10790 p_record_line
= record_line
;
10793 case DW_LNE_set_address
:
10794 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
10796 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
10798 /* This line table is for a function which has been
10799 GCd by the linker. Ignore it. PR gdb/12528 */
10802 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
10804 complaint (&symfile_complaints
,
10805 _(".debug_line address at offset 0x%lx is 0 "
10807 line_offset
, cu
->objfile
->name
);
10808 p_record_line
= noop_record_line
;
10812 line_ptr
+= bytes_read
;
10813 address
+= baseaddr
;
10815 case DW_LNE_define_file
:
10818 unsigned int dir_index
, mod_time
, length
;
10820 cur_file
= read_direct_string (abfd
, line_ptr
,
10822 line_ptr
+= bytes_read
;
10824 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10825 line_ptr
+= bytes_read
;
10827 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10828 line_ptr
+= bytes_read
;
10830 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10831 line_ptr
+= bytes_read
;
10832 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
10835 case DW_LNE_set_discriminator
:
10836 /* The discriminator is not interesting to the debugger;
10838 line_ptr
= extended_end
;
10841 complaint (&symfile_complaints
,
10842 _("mangled .debug_line section"));
10845 /* Make sure that we parsed the extended op correctly. If e.g.
10846 we expected a different address size than the producer used,
10847 we may have read the wrong number of bytes. */
10848 if (line_ptr
!= extended_end
)
10850 complaint (&symfile_complaints
,
10851 _("mangled .debug_line section"));
10856 if (lh
->num_file_names
< file
|| file
== 0)
10857 dwarf2_debug_line_missing_file_complaint ();
10860 lh
->file_names
[file
- 1].included_p
= 1;
10861 if (!decode_for_pst_p
&& is_stmt
)
10863 if (last_subfile
!= current_subfile
)
10865 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10867 (*p_record_line
) (last_subfile
, 0, addr
);
10868 last_subfile
= current_subfile
;
10870 addr
= check_cu_functions (address
, cu
);
10871 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
10872 (*p_record_line
) (current_subfile
, line
, addr
);
10877 case DW_LNS_advance_pc
:
10880 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10882 address
+= (((op_index
+ adjust
)
10883 / lh
->maximum_ops_per_instruction
)
10884 * lh
->minimum_instruction_length
);
10885 op_index
= ((op_index
+ adjust
)
10886 % lh
->maximum_ops_per_instruction
);
10887 line_ptr
+= bytes_read
;
10890 case DW_LNS_advance_line
:
10891 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
10892 line_ptr
+= bytes_read
;
10894 case DW_LNS_set_file
:
10896 /* The arrays lh->include_dirs and lh->file_names are
10897 0-based, but the directory and file name numbers in
10898 the statement program are 1-based. */
10899 struct file_entry
*fe
;
10902 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10903 line_ptr
+= bytes_read
;
10904 if (lh
->num_file_names
< file
|| file
== 0)
10905 dwarf2_debug_line_missing_file_complaint ();
10908 fe
= &lh
->file_names
[file
- 1];
10910 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10911 if (!decode_for_pst_p
)
10913 last_subfile
= current_subfile
;
10914 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10919 case DW_LNS_set_column
:
10920 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10921 line_ptr
+= bytes_read
;
10923 case DW_LNS_negate_stmt
:
10924 is_stmt
= (!is_stmt
);
10926 case DW_LNS_set_basic_block
:
10929 /* Add to the address register of the state machine the
10930 address increment value corresponding to special opcode
10931 255. I.e., this value is scaled by the minimum
10932 instruction length since special opcode 255 would have
10933 scaled the increment. */
10934 case DW_LNS_const_add_pc
:
10936 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
10938 address
+= (((op_index
+ adjust
)
10939 / lh
->maximum_ops_per_instruction
)
10940 * lh
->minimum_instruction_length
);
10941 op_index
= ((op_index
+ adjust
)
10942 % lh
->maximum_ops_per_instruction
);
10945 case DW_LNS_fixed_advance_pc
:
10946 address
+= read_2_bytes (abfd
, line_ptr
);
10952 /* Unknown standard opcode, ignore it. */
10955 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
10957 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10958 line_ptr
+= bytes_read
;
10963 if (lh
->num_file_names
< file
|| file
== 0)
10964 dwarf2_debug_line_missing_file_complaint ();
10967 lh
->file_names
[file
- 1].included_p
= 1;
10968 if (!decode_for_pst_p
)
10970 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10971 (*p_record_line
) (current_subfile
, 0, addr
);
10976 if (decode_for_pst_p
)
10980 /* Now that we're done scanning the Line Header Program, we can
10981 create the psymtab of each included file. */
10982 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
10983 if (lh
->file_names
[file_index
].included_p
== 1)
10985 char *include_name
=
10986 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
10987 if (include_name
!= NULL
)
10988 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
10993 /* Make sure a symtab is created for every file, even files
10994 which contain only variables (i.e. no code with associated
10998 struct file_entry
*fe
;
11000 for (i
= 0; i
< lh
->num_file_names
; i
++)
11004 fe
= &lh
->file_names
[i
];
11006 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11007 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
11009 /* Skip the main file; we don't need it, and it must be
11010 allocated last, so that it will show up before the
11011 non-primary symtabs in the objfile's symtab list. */
11012 if (current_subfile
== first_subfile
)
11015 if (current_subfile
->symtab
== NULL
)
11016 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
11018 fe
->symtab
= current_subfile
->symtab
;
11023 /* Start a subfile for DWARF. FILENAME is the name of the file and
11024 DIRNAME the name of the source directory which contains FILENAME
11025 or NULL if not known. COMP_DIR is the compilation directory for the
11026 linetable's compilation unit or NULL if not known.
11027 This routine tries to keep line numbers from identical absolute and
11028 relative file names in a common subfile.
11030 Using the `list' example from the GDB testsuite, which resides in
11031 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
11032 of /srcdir/list0.c yields the following debugging information for list0.c:
11034 DW_AT_name: /srcdir/list0.c
11035 DW_AT_comp_dir: /compdir
11036 files.files[0].name: list0.h
11037 files.files[0].dir: /srcdir
11038 files.files[1].name: list0.c
11039 files.files[1].dir: /srcdir
11041 The line number information for list0.c has to end up in a single
11042 subfile, so that `break /srcdir/list0.c:1' works as expected.
11043 start_subfile will ensure that this happens provided that we pass the
11044 concatenation of files.files[1].dir and files.files[1].name as the
11048 dwarf2_start_subfile (char *filename
, const char *dirname
,
11049 const char *comp_dir
)
11053 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
11054 `start_symtab' will always pass the contents of DW_AT_comp_dir as
11055 second argument to start_subfile. To be consistent, we do the
11056 same here. In order not to lose the line information directory,
11057 we concatenate it to the filename when it makes sense.
11058 Note that the Dwarf3 standard says (speaking of filenames in line
11059 information): ``The directory index is ignored for file names
11060 that represent full path names''. Thus ignoring dirname in the
11061 `else' branch below isn't an issue. */
11063 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
11064 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
11066 fullname
= filename
;
11068 start_subfile (fullname
, comp_dir
);
11070 if (fullname
!= filename
)
11075 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
11076 struct dwarf2_cu
*cu
)
11078 struct objfile
*objfile
= cu
->objfile
;
11079 struct comp_unit_head
*cu_header
= &cu
->header
;
11081 /* NOTE drow/2003-01-30: There used to be a comment and some special
11082 code here to turn a symbol with DW_AT_external and a
11083 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
11084 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
11085 with some versions of binutils) where shared libraries could have
11086 relocations against symbols in their debug information - the
11087 minimal symbol would have the right address, but the debug info
11088 would not. It's no longer necessary, because we will explicitly
11089 apply relocations when we read in the debug information now. */
11091 /* A DW_AT_location attribute with no contents indicates that a
11092 variable has been optimized away. */
11093 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
11095 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11099 /* Handle one degenerate form of location expression specially, to
11100 preserve GDB's previous behavior when section offsets are
11101 specified. If this is just a DW_OP_addr then mark this symbol
11104 if (attr_form_is_block (attr
)
11105 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
11106 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
11108 unsigned int dummy
;
11110 SYMBOL_VALUE_ADDRESS (sym
) =
11111 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
11112 SYMBOL_CLASS (sym
) = LOC_STATIC
;
11113 fixup_symbol_section (sym
, objfile
);
11114 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
11115 SYMBOL_SECTION (sym
));
11119 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
11120 expression evaluator, and use LOC_COMPUTED only when necessary
11121 (i.e. when the value of a register or memory location is
11122 referenced, or a thread-local block, etc.). Then again, it might
11123 not be worthwhile. I'm assuming that it isn't unless performance
11124 or memory numbers show me otherwise. */
11126 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
11127 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11129 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
11130 cu
->has_loclist
= 1;
11133 /* Given a pointer to a DWARF information entry, figure out if we need
11134 to make a symbol table entry for it, and if so, create a new entry
11135 and return a pointer to it.
11136 If TYPE is NULL, determine symbol type from the die, otherwise
11137 used the passed type.
11138 If SPACE is not NULL, use it to hold the new symbol. If it is
11139 NULL, allocate a new symbol on the objfile's obstack. */
11141 static struct symbol
*
11142 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
11143 struct symbol
*space
)
11145 struct objfile
*objfile
= cu
->objfile
;
11146 struct symbol
*sym
= NULL
;
11148 struct attribute
*attr
= NULL
;
11149 struct attribute
*attr2
= NULL
;
11150 CORE_ADDR baseaddr
;
11151 struct pending
**list_to_add
= NULL
;
11153 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
11155 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11157 name
= dwarf2_name (die
, cu
);
11160 const char *linkagename
;
11161 int suppress_add
= 0;
11166 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
11167 OBJSTAT (objfile
, n_syms
++);
11169 /* Cache this symbol's name and the name's demangled form (if any). */
11170 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
11171 linkagename
= dwarf2_physname (name
, die
, cu
);
11172 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
11174 /* Fortran does not have mangling standard and the mangling does differ
11175 between gfortran, iFort etc. */
11176 if (cu
->language
== language_fortran
11177 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
11178 symbol_set_demangled_name (&(sym
->ginfo
),
11179 (char *) dwarf2_full_name (name
, die
, cu
),
11182 /* Default assumptions.
11183 Use the passed type or decode it from the die. */
11184 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11185 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11187 SYMBOL_TYPE (sym
) = type
;
11189 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
11190 attr
= dwarf2_attr (die
,
11191 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
11195 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
11198 attr
= dwarf2_attr (die
,
11199 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
11203 int file_index
= DW_UNSND (attr
);
11205 if (cu
->line_header
== NULL
11206 || file_index
> cu
->line_header
->num_file_names
)
11207 complaint (&symfile_complaints
,
11208 _("file index out of range"));
11209 else if (file_index
> 0)
11211 struct file_entry
*fe
;
11213 fe
= &cu
->line_header
->file_names
[file_index
- 1];
11214 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
11221 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11224 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
11226 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
11227 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
11228 SYMBOL_CLASS (sym
) = LOC_LABEL
;
11229 add_symbol_to_list (sym
, cu
->list_in_scope
);
11231 case DW_TAG_subprogram
:
11232 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11234 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11235 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11236 if ((attr2
&& (DW_UNSND (attr2
) != 0))
11237 || cu
->language
== language_ada
)
11239 /* Subprograms marked external are stored as a global symbol.
11240 Ada subprograms, whether marked external or not, are always
11241 stored as a global symbol, because we want to be able to
11242 access them globally. For instance, we want to be able
11243 to break on a nested subprogram without having to
11244 specify the context. */
11245 list_to_add
= &global_symbols
;
11249 list_to_add
= cu
->list_in_scope
;
11252 case DW_TAG_inlined_subroutine
:
11253 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11255 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11256 SYMBOL_INLINED (sym
) = 1;
11257 /* Do not add the symbol to any lists. It will be found via
11258 BLOCK_FUNCTION from the blockvector. */
11260 case DW_TAG_template_value_param
:
11262 /* Fall through. */
11263 case DW_TAG_constant
:
11264 case DW_TAG_variable
:
11265 case DW_TAG_member
:
11266 /* Compilation with minimal debug info may result in
11267 variables with missing type entries. Change the
11268 misleading `void' type to something sensible. */
11269 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
11271 = objfile_type (objfile
)->nodebug_data_symbol
;
11273 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11274 /* In the case of DW_TAG_member, we should only be called for
11275 static const members. */
11276 if (die
->tag
== DW_TAG_member
)
11278 /* dwarf2_add_field uses die_is_declaration,
11279 so we do the same. */
11280 gdb_assert (die_is_declaration (die
, cu
));
11285 dwarf2_const_value (attr
, sym
, cu
);
11286 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11289 if (attr2
&& (DW_UNSND (attr2
) != 0))
11290 list_to_add
= &global_symbols
;
11292 list_to_add
= cu
->list_in_scope
;
11296 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11299 var_decode_location (attr
, sym
, cu
);
11300 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11301 if (SYMBOL_CLASS (sym
) == LOC_STATIC
11302 && SYMBOL_VALUE_ADDRESS (sym
) == 0
11303 && !dwarf2_per_objfile
->has_section_at_zero
)
11305 /* When a static variable is eliminated by the linker,
11306 the corresponding debug information is not stripped
11307 out, but the variable address is set to null;
11308 do not add such variables into symbol table. */
11310 else if (attr2
&& (DW_UNSND (attr2
) != 0))
11312 /* Workaround gfortran PR debug/40040 - it uses
11313 DW_AT_location for variables in -fPIC libraries which may
11314 get overriden by other libraries/executable and get
11315 a different address. Resolve it by the minimal symbol
11316 which may come from inferior's executable using copy
11317 relocation. Make this workaround only for gfortran as for
11318 other compilers GDB cannot guess the minimal symbol
11319 Fortran mangling kind. */
11320 if (cu
->language
== language_fortran
&& die
->parent
11321 && die
->parent
->tag
== DW_TAG_module
11323 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
11324 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11326 /* A variable with DW_AT_external is never static,
11327 but it may be block-scoped. */
11328 list_to_add
= (cu
->list_in_scope
== &file_symbols
11329 ? &global_symbols
: cu
->list_in_scope
);
11332 list_to_add
= cu
->list_in_scope
;
11336 /* We do not know the address of this symbol.
11337 If it is an external symbol and we have type information
11338 for it, enter the symbol as a LOC_UNRESOLVED symbol.
11339 The address of the variable will then be determined from
11340 the minimal symbol table whenever the variable is
11342 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11343 if (attr2
&& (DW_UNSND (attr2
) != 0)
11344 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
11346 /* A variable with DW_AT_external is never static, but it
11347 may be block-scoped. */
11348 list_to_add
= (cu
->list_in_scope
== &file_symbols
11349 ? &global_symbols
: cu
->list_in_scope
);
11351 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11353 else if (!die_is_declaration (die
, cu
))
11355 /* Use the default LOC_OPTIMIZED_OUT class. */
11356 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
11358 list_to_add
= cu
->list_in_scope
;
11362 case DW_TAG_formal_parameter
:
11363 /* If we are inside a function, mark this as an argument. If
11364 not, we might be looking at an argument to an inlined function
11365 when we do not have enough information to show inlined frames;
11366 pretend it's a local variable in that case so that the user can
11368 if (context_stack_depth
> 0
11369 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
11370 SYMBOL_IS_ARGUMENT (sym
) = 1;
11371 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11374 var_decode_location (attr
, sym
, cu
);
11376 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11379 dwarf2_const_value (attr
, sym
, cu
);
11381 attr
= dwarf2_attr (die
, DW_AT_variable_parameter
, cu
);
11382 if (attr
&& DW_UNSND (attr
))
11384 struct type
*ref_type
;
11386 ref_type
= lookup_reference_type (SYMBOL_TYPE (sym
));
11387 SYMBOL_TYPE (sym
) = ref_type
;
11390 list_to_add
= cu
->list_in_scope
;
11392 case DW_TAG_unspecified_parameters
:
11393 /* From varargs functions; gdb doesn't seem to have any
11394 interest in this information, so just ignore it for now.
11397 case DW_TAG_template_type_param
:
11399 /* Fall through. */
11400 case DW_TAG_class_type
:
11401 case DW_TAG_interface_type
:
11402 case DW_TAG_structure_type
:
11403 case DW_TAG_union_type
:
11404 case DW_TAG_set_type
:
11405 case DW_TAG_enumeration_type
:
11406 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11407 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
11410 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
11411 really ever be static objects: otherwise, if you try
11412 to, say, break of a class's method and you're in a file
11413 which doesn't mention that class, it won't work unless
11414 the check for all static symbols in lookup_symbol_aux
11415 saves you. See the OtherFileClass tests in
11416 gdb.c++/namespace.exp. */
11420 list_to_add
= (cu
->list_in_scope
== &file_symbols
11421 && (cu
->language
== language_cplus
11422 || cu
->language
== language_java
)
11423 ? &global_symbols
: cu
->list_in_scope
);
11425 /* The semantics of C++ state that "struct foo {
11426 ... }" also defines a typedef for "foo". A Java
11427 class declaration also defines a typedef for the
11429 if (cu
->language
== language_cplus
11430 || cu
->language
== language_java
11431 || cu
->language
== language_ada
)
11433 /* The symbol's name is already allocated along
11434 with this objfile, so we don't need to
11435 duplicate it for the type. */
11436 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
11437 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
11442 case DW_TAG_typedef
:
11443 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11444 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11445 list_to_add
= cu
->list_in_scope
;
11447 case DW_TAG_base_type
:
11448 case DW_TAG_subrange_type
:
11449 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11450 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11451 list_to_add
= cu
->list_in_scope
;
11453 case DW_TAG_enumerator
:
11454 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11457 dwarf2_const_value (attr
, sym
, cu
);
11460 /* NOTE: carlton/2003-11-10: See comment above in the
11461 DW_TAG_class_type, etc. block. */
11463 list_to_add
= (cu
->list_in_scope
== &file_symbols
11464 && (cu
->language
== language_cplus
11465 || cu
->language
== language_java
)
11466 ? &global_symbols
: cu
->list_in_scope
);
11469 case DW_TAG_namespace
:
11470 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11471 list_to_add
= &global_symbols
;
11474 /* Not a tag we recognize. Hopefully we aren't processing
11475 trash data, but since we must specifically ignore things
11476 we don't recognize, there is nothing else we should do at
11478 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
11479 dwarf_tag_name (die
->tag
));
11485 sym
->hash_next
= objfile
->template_symbols
;
11486 objfile
->template_symbols
= sym
;
11487 list_to_add
= NULL
;
11490 if (list_to_add
!= NULL
)
11491 add_symbol_to_list (sym
, list_to_add
);
11493 /* For the benefit of old versions of GCC, check for anonymous
11494 namespaces based on the demangled name. */
11495 if (!processing_has_namespace_info
11496 && cu
->language
== language_cplus
)
11497 cp_scan_for_anonymous_namespaces (sym
);
11502 /* A wrapper for new_symbol_full that always allocates a new symbol. */
11504 static struct symbol
*
11505 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
11507 return new_symbol_full (die
, type
, cu
, NULL
);
11510 /* Given an attr with a DW_FORM_dataN value in host byte order,
11511 zero-extend it as appropriate for the symbol's type. The DWARF
11512 standard (v4) is not entirely clear about the meaning of using
11513 DW_FORM_dataN for a constant with a signed type, where the type is
11514 wider than the data. The conclusion of a discussion on the DWARF
11515 list was that this is unspecified. We choose to always zero-extend
11516 because that is the interpretation long in use by GCC. */
11519 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
11520 const char *name
, struct obstack
*obstack
,
11521 struct dwarf2_cu
*cu
, long *value
, int bits
)
11523 struct objfile
*objfile
= cu
->objfile
;
11524 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
11525 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
11526 LONGEST l
= DW_UNSND (attr
);
11528 if (bits
< sizeof (*value
) * 8)
11530 l
&= ((LONGEST
) 1 << bits
) - 1;
11533 else if (bits
== sizeof (*value
) * 8)
11537 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
11538 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
11545 /* Read a constant value from an attribute. Either set *VALUE, or if
11546 the value does not fit in *VALUE, set *BYTES - either already
11547 allocated on the objfile obstack, or newly allocated on OBSTACK,
11548 or, set *BATON, if we translated the constant to a location
11552 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
11553 const char *name
, struct obstack
*obstack
,
11554 struct dwarf2_cu
*cu
,
11555 long *value
, gdb_byte
**bytes
,
11556 struct dwarf2_locexpr_baton
**baton
)
11558 struct objfile
*objfile
= cu
->objfile
;
11559 struct comp_unit_head
*cu_header
= &cu
->header
;
11560 struct dwarf_block
*blk
;
11561 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
11562 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
11568 switch (attr
->form
)
11574 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
11575 dwarf2_const_value_length_mismatch_complaint (name
,
11576 cu_header
->addr_size
,
11577 TYPE_LENGTH (type
));
11578 /* Symbols of this form are reasonably rare, so we just
11579 piggyback on the existing location code rather than writing
11580 a new implementation of symbol_computed_ops. */
11581 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
11582 sizeof (struct dwarf2_locexpr_baton
));
11583 (*baton
)->per_cu
= cu
->per_cu
;
11584 gdb_assert ((*baton
)->per_cu
);
11586 (*baton
)->size
= 2 + cu_header
->addr_size
;
11587 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
11588 (*baton
)->data
= data
;
11590 data
[0] = DW_OP_addr
;
11591 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
11592 byte_order
, DW_ADDR (attr
));
11593 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
11596 case DW_FORM_string
:
11598 /* DW_STRING is already allocated on the objfile obstack, point
11600 *bytes
= (gdb_byte
*) DW_STRING (attr
);
11602 case DW_FORM_block1
:
11603 case DW_FORM_block2
:
11604 case DW_FORM_block4
:
11605 case DW_FORM_block
:
11606 case DW_FORM_exprloc
:
11607 blk
= DW_BLOCK (attr
);
11608 if (TYPE_LENGTH (type
) != blk
->size
)
11609 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
11610 TYPE_LENGTH (type
));
11611 *bytes
= blk
->data
;
11614 /* The DW_AT_const_value attributes are supposed to carry the
11615 symbol's value "represented as it would be on the target
11616 architecture." By the time we get here, it's already been
11617 converted to host endianness, so we just need to sign- or
11618 zero-extend it as appropriate. */
11619 case DW_FORM_data1
:
11620 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11621 obstack
, cu
, value
, 8);
11623 case DW_FORM_data2
:
11624 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11625 obstack
, cu
, value
, 16);
11627 case DW_FORM_data4
:
11628 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11629 obstack
, cu
, value
, 32);
11631 case DW_FORM_data8
:
11632 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11633 obstack
, cu
, value
, 64);
11636 case DW_FORM_sdata
:
11637 *value
= DW_SND (attr
);
11640 case DW_FORM_udata
:
11641 *value
= DW_UNSND (attr
);
11645 complaint (&symfile_complaints
,
11646 _("unsupported const value attribute form: '%s'"),
11647 dwarf_form_name (attr
->form
));
11654 /* Copy constant value from an attribute to a symbol. */
11657 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
11658 struct dwarf2_cu
*cu
)
11660 struct objfile
*objfile
= cu
->objfile
;
11661 struct comp_unit_head
*cu_header
= &cu
->header
;
11664 struct dwarf2_locexpr_baton
*baton
;
11666 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
11667 SYMBOL_PRINT_NAME (sym
),
11668 &objfile
->objfile_obstack
, cu
,
11669 &value
, &bytes
, &baton
);
11673 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
11674 SYMBOL_LOCATION_BATON (sym
) = baton
;
11675 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11677 else if (bytes
!= NULL
)
11679 SYMBOL_VALUE_BYTES (sym
) = bytes
;
11680 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
11684 SYMBOL_VALUE (sym
) = value
;
11685 SYMBOL_CLASS (sym
) = LOC_CONST
;
11689 /* Return the type of the die in question using its DW_AT_type attribute. */
11691 static struct type
*
11692 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11694 struct attribute
*type_attr
;
11696 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
11699 /* A missing DW_AT_type represents a void type. */
11700 return objfile_type (cu
->objfile
)->builtin_void
;
11703 return lookup_die_type (die
, type_attr
, cu
);
11706 /* True iff CU's producer generates GNAT Ada auxiliary information
11707 that allows to find parallel types through that information instead
11708 of having to do expensive parallel lookups by type name. */
11711 need_gnat_info (struct dwarf2_cu
*cu
)
11713 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
11714 of GNAT produces this auxiliary information, without any indication
11715 that it is produced. Part of enhancing the FSF version of GNAT
11716 to produce that information will be to put in place an indicator
11717 that we can use in order to determine whether the descriptive type
11718 info is available or not. One suggestion that has been made is
11719 to use a new attribute, attached to the CU die. For now, assume
11720 that the descriptive type info is not available. */
11724 /* Return the auxiliary type of the die in question using its
11725 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
11726 attribute is not present. */
11728 static struct type
*
11729 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11731 struct attribute
*type_attr
;
11733 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
11737 return lookup_die_type (die
, type_attr
, cu
);
11740 /* If DIE has a descriptive_type attribute, then set the TYPE's
11741 descriptive type accordingly. */
11744 set_descriptive_type (struct type
*type
, struct die_info
*die
,
11745 struct dwarf2_cu
*cu
)
11747 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
11749 if (descriptive_type
)
11751 ALLOCATE_GNAT_AUX_TYPE (type
);
11752 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
11756 /* Return the containing type of the die in question using its
11757 DW_AT_containing_type attribute. */
11759 static struct type
*
11760 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11762 struct attribute
*type_attr
;
11764 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
11766 error (_("Dwarf Error: Problem turning containing type into gdb type "
11767 "[in module %s]"), cu
->objfile
->name
);
11769 return lookup_die_type (die
, type_attr
, cu
);
11772 /* Look up the type of DIE in CU using its type attribute ATTR.
11773 If there is no type substitute an error marker. */
11775 static struct type
*
11776 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
11777 struct dwarf2_cu
*cu
)
11779 struct type
*this_type
;
11781 /* First see if we have it cached. */
11783 if (is_ref_attr (attr
))
11785 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
11787 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
11789 else if (attr
->form
== DW_FORM_ref_sig8
)
11791 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
11792 struct dwarf2_cu
*sig_cu
;
11793 unsigned int offset
;
11795 /* sig_type will be NULL if the signatured type is missing from
11797 if (sig_type
== NULL
)
11798 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
11799 "at 0x%x [in module %s]"),
11800 die
->offset
, cu
->objfile
->name
);
11802 gdb_assert (sig_type
->per_cu
.from_debug_types
);
11803 offset
= sig_type
->per_cu
.offset
+ sig_type
->type_offset
;
11804 this_type
= get_die_type_at_offset (offset
, &sig_type
->per_cu
);
11808 dump_die_for_error (die
);
11809 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
11810 dwarf_attr_name (attr
->name
), cu
->objfile
->name
);
11813 /* If not cached we need to read it in. */
11815 if (this_type
== NULL
)
11817 struct die_info
*type_die
;
11818 struct dwarf2_cu
*type_cu
= cu
;
11820 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
11821 /* If the type is cached, we should have found it above. */
11822 gdb_assert (get_die_type (type_die
, type_cu
) == NULL
);
11823 this_type
= read_type_die_1 (type_die
, type_cu
);
11826 /* If we still don't have a type use an error marker. */
11828 if (this_type
== NULL
)
11830 char *message
, *saved
;
11832 /* read_type_die already issued a complaint. */
11833 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
11837 saved
= obstack_copy0 (&cu
->objfile
->objfile_obstack
,
11838 message
, strlen (message
));
11841 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, cu
->objfile
);
11847 /* Return the type in DIE, CU.
11848 Returns NULL for invalid types.
11850 This first does a lookup in the appropriate type_hash table,
11851 and only reads the die in if necessary.
11853 NOTE: This can be called when reading in partial or full symbols. */
11855 static struct type
*
11856 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
11858 struct type
*this_type
;
11860 this_type
= get_die_type (die
, cu
);
11864 return read_type_die_1 (die
, cu
);
11867 /* Read the type in DIE, CU.
11868 Returns NULL for invalid types. */
11870 static struct type
*
11871 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
11873 struct type
*this_type
= NULL
;
11877 case DW_TAG_class_type
:
11878 case DW_TAG_interface_type
:
11879 case DW_TAG_structure_type
:
11880 case DW_TAG_union_type
:
11881 this_type
= read_structure_type (die
, cu
);
11883 case DW_TAG_enumeration_type
:
11884 this_type
= read_enumeration_type (die
, cu
);
11886 case DW_TAG_subprogram
:
11887 case DW_TAG_subroutine_type
:
11888 case DW_TAG_inlined_subroutine
:
11889 this_type
= read_subroutine_type (die
, cu
);
11891 case DW_TAG_array_type
:
11892 this_type
= read_array_type (die
, cu
);
11894 case DW_TAG_set_type
:
11895 this_type
= read_set_type (die
, cu
);
11897 case DW_TAG_pointer_type
:
11898 this_type
= read_tag_pointer_type (die
, cu
);
11900 case DW_TAG_ptr_to_member_type
:
11901 this_type
= read_tag_ptr_to_member_type (die
, cu
);
11903 case DW_TAG_reference_type
:
11904 this_type
= read_tag_reference_type (die
, cu
);
11906 case DW_TAG_const_type
:
11907 this_type
= read_tag_const_type (die
, cu
);
11909 case DW_TAG_volatile_type
:
11910 this_type
= read_tag_volatile_type (die
, cu
);
11912 case DW_TAG_string_type
:
11913 this_type
= read_tag_string_type (die
, cu
);
11915 case DW_TAG_typedef
:
11916 this_type
= read_typedef (die
, cu
);
11918 case DW_TAG_subrange_type
:
11919 this_type
= read_subrange_type (die
, cu
);
11921 case DW_TAG_base_type
:
11922 this_type
= read_base_type (die
, cu
);
11924 case DW_TAG_unspecified_type
:
11925 this_type
= read_unspecified_type (die
, cu
);
11927 case DW_TAG_namespace
:
11928 this_type
= read_namespace_type (die
, cu
);
11930 case DW_TAG_module
:
11931 this_type
= read_module_type (die
, cu
);
11934 complaint (&symfile_complaints
,
11935 _("unexpected tag in read_type_die: '%s'"),
11936 dwarf_tag_name (die
->tag
));
11943 /* See if we can figure out if the class lives in a namespace. We do
11944 this by looking for a member function; its demangled name will
11945 contain namespace info, if there is any.
11946 Return the computed name or NULL.
11947 Space for the result is allocated on the objfile's obstack.
11948 This is the full-die version of guess_partial_die_structure_name.
11949 In this case we know DIE has no useful parent. */
11952 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
11954 struct die_info
*spec_die
;
11955 struct dwarf2_cu
*spec_cu
;
11956 struct die_info
*child
;
11959 spec_die
= die_specification (die
, &spec_cu
);
11960 if (spec_die
!= NULL
)
11966 for (child
= die
->child
;
11968 child
= child
->sibling
)
11970 if (child
->tag
== DW_TAG_subprogram
)
11972 struct attribute
*attr
;
11974 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
11976 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
11980 = language_class_name_from_physname (cu
->language_defn
,
11984 if (actual_name
!= NULL
)
11986 char *die_name
= dwarf2_name (die
, cu
);
11988 if (die_name
!= NULL
11989 && strcmp (die_name
, actual_name
) != 0)
11991 /* Strip off the class name from the full name.
11992 We want the prefix. */
11993 int die_name_len
= strlen (die_name
);
11994 int actual_name_len
= strlen (actual_name
);
11996 /* Test for '::' as a sanity check. */
11997 if (actual_name_len
> die_name_len
+ 2
11998 && actual_name
[actual_name_len
11999 - die_name_len
- 1] == ':')
12001 obsavestring (actual_name
,
12002 actual_name_len
- die_name_len
- 2,
12003 &cu
->objfile
->objfile_obstack
);
12006 xfree (actual_name
);
12015 /* Return the name of the namespace/class that DIE is defined within,
12016 or "" if we can't tell. The caller should not xfree the result.
12018 For example, if we're within the method foo() in the following
12028 then determine_prefix on foo's die will return "N::C". */
12031 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
12033 struct die_info
*parent
, *spec_die
;
12034 struct dwarf2_cu
*spec_cu
;
12035 struct type
*parent_type
;
12037 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
12038 && cu
->language
!= language_fortran
)
12041 /* We have to be careful in the presence of DW_AT_specification.
12042 For example, with GCC 3.4, given the code
12046 // Definition of N::foo.
12050 then we'll have a tree of DIEs like this:
12052 1: DW_TAG_compile_unit
12053 2: DW_TAG_namespace // N
12054 3: DW_TAG_subprogram // declaration of N::foo
12055 4: DW_TAG_subprogram // definition of N::foo
12056 DW_AT_specification // refers to die #3
12058 Thus, when processing die #4, we have to pretend that we're in
12059 the context of its DW_AT_specification, namely the contex of die
12062 spec_die
= die_specification (die
, &spec_cu
);
12063 if (spec_die
== NULL
)
12064 parent
= die
->parent
;
12067 parent
= spec_die
->parent
;
12071 if (parent
== NULL
)
12073 else if (parent
->building_fullname
)
12076 const char *parent_name
;
12078 /* It has been seen on RealView 2.2 built binaries,
12079 DW_TAG_template_type_param types actually _defined_ as
12080 children of the parent class:
12083 template class <class Enum> Class{};
12084 Class<enum E> class_e;
12086 1: DW_TAG_class_type (Class)
12087 2: DW_TAG_enumeration_type (E)
12088 3: DW_TAG_enumerator (enum1:0)
12089 3: DW_TAG_enumerator (enum2:1)
12091 2: DW_TAG_template_type_param
12092 DW_AT_type DW_FORM_ref_udata (E)
12094 Besides being broken debug info, it can put GDB into an
12095 infinite loop. Consider:
12097 When we're building the full name for Class<E>, we'll start
12098 at Class, and go look over its template type parameters,
12099 finding E. We'll then try to build the full name of E, and
12100 reach here. We're now trying to build the full name of E,
12101 and look over the parent DIE for containing scope. In the
12102 broken case, if we followed the parent DIE of E, we'd again
12103 find Class, and once again go look at its template type
12104 arguments, etc., etc. Simply don't consider such parent die
12105 as source-level parent of this die (it can't be, the language
12106 doesn't allow it), and break the loop here. */
12107 name
= dwarf2_name (die
, cu
);
12108 parent_name
= dwarf2_name (parent
, cu
);
12109 complaint (&symfile_complaints
,
12110 _("template param type '%s' defined within parent '%s'"),
12111 name
? name
: "<unknown>",
12112 parent_name
? parent_name
: "<unknown>");
12116 switch (parent
->tag
)
12118 case DW_TAG_namespace
:
12119 parent_type
= read_type_die (parent
, cu
);
12120 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
12121 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
12122 Work around this problem here. */
12123 if (cu
->language
== language_cplus
12124 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
12126 /* We give a name to even anonymous namespaces. */
12127 return TYPE_TAG_NAME (parent_type
);
12128 case DW_TAG_class_type
:
12129 case DW_TAG_interface_type
:
12130 case DW_TAG_structure_type
:
12131 case DW_TAG_union_type
:
12132 case DW_TAG_module
:
12133 parent_type
= read_type_die (parent
, cu
);
12134 if (TYPE_TAG_NAME (parent_type
) != NULL
)
12135 return TYPE_TAG_NAME (parent_type
);
12137 /* An anonymous structure is only allowed non-static data
12138 members; no typedefs, no member functions, et cetera.
12139 So it does not need a prefix. */
12141 case DW_TAG_compile_unit
:
12142 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
12143 if (cu
->language
== language_cplus
12144 && dwarf2_per_objfile
->types
.asection
!= NULL
12145 && die
->child
!= NULL
12146 && (die
->tag
== DW_TAG_class_type
12147 || die
->tag
== DW_TAG_structure_type
12148 || die
->tag
== DW_TAG_union_type
))
12150 char *name
= guess_full_die_structure_name (die
, cu
);
12156 return determine_prefix (parent
, cu
);
12160 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
12161 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
12162 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
12163 an obconcat, otherwise allocate storage for the result. The CU argument is
12164 used to determine the language and hence, the appropriate separator. */
12166 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
12169 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
12170 int physname
, struct dwarf2_cu
*cu
)
12172 const char *lead
= "";
12175 if (suffix
== NULL
|| suffix
[0] == '\0'
12176 || prefix
== NULL
|| prefix
[0] == '\0')
12178 else if (cu
->language
== language_java
)
12180 else if (cu
->language
== language_fortran
&& physname
)
12182 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
12183 DW_AT_MIPS_linkage_name is preferred and used instead. */
12191 if (prefix
== NULL
)
12193 if (suffix
== NULL
)
12199 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
12201 strcpy (retval
, lead
);
12202 strcat (retval
, prefix
);
12203 strcat (retval
, sep
);
12204 strcat (retval
, suffix
);
12209 /* We have an obstack. */
12210 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
12214 /* Return sibling of die, NULL if no sibling. */
12216 static struct die_info
*
12217 sibling_die (struct die_info
*die
)
12219 return die
->sibling
;
12222 /* Get name of a die, return NULL if not found. */
12225 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
12226 struct obstack
*obstack
)
12228 if (name
&& cu
->language
== language_cplus
)
12230 char *canon_name
= cp_canonicalize_string (name
);
12232 if (canon_name
!= NULL
)
12234 if (strcmp (canon_name
, name
) != 0)
12235 name
= obsavestring (canon_name
, strlen (canon_name
),
12237 xfree (canon_name
);
12244 /* Get name of a die, return NULL if not found. */
12247 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12249 struct attribute
*attr
;
12251 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
12252 if ((!attr
|| !DW_STRING (attr
))
12253 && die
->tag
!= DW_TAG_class_type
12254 && die
->tag
!= DW_TAG_interface_type
12255 && die
->tag
!= DW_TAG_structure_type
12256 && die
->tag
!= DW_TAG_union_type
)
12261 case DW_TAG_compile_unit
:
12262 /* Compilation units have a DW_AT_name that is a filename, not
12263 a source language identifier. */
12264 case DW_TAG_enumeration_type
:
12265 case DW_TAG_enumerator
:
12266 /* These tags always have simple identifiers already; no need
12267 to canonicalize them. */
12268 return DW_STRING (attr
);
12270 case DW_TAG_subprogram
:
12271 /* Java constructors will all be named "<init>", so return
12272 the class name when we see this special case. */
12273 if (cu
->language
== language_java
12274 && DW_STRING (attr
) != NULL
12275 && strcmp (DW_STRING (attr
), "<init>") == 0)
12277 struct dwarf2_cu
*spec_cu
= cu
;
12278 struct die_info
*spec_die
;
12280 /* GCJ will output '<init>' for Java constructor names.
12281 For this special case, return the name of the parent class. */
12283 /* GCJ may output suprogram DIEs with AT_specification set.
12284 If so, use the name of the specified DIE. */
12285 spec_die
= die_specification (die
, &spec_cu
);
12286 if (spec_die
!= NULL
)
12287 return dwarf2_name (spec_die
, spec_cu
);
12292 if (die
->tag
== DW_TAG_class_type
)
12293 return dwarf2_name (die
, cu
);
12295 while (die
->tag
!= DW_TAG_compile_unit
);
12299 case DW_TAG_class_type
:
12300 case DW_TAG_interface_type
:
12301 case DW_TAG_structure_type
:
12302 case DW_TAG_union_type
:
12303 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
12304 structures or unions. These were of the form "._%d" in GCC 4.1,
12305 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
12306 and GCC 4.4. We work around this problem by ignoring these. */
12307 if (attr
&& DW_STRING (attr
)
12308 && (strncmp (DW_STRING (attr
), "._", 2) == 0
12309 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
12312 /* GCC might emit a nameless typedef that has a linkage name. See
12313 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12314 if (!attr
|| DW_STRING (attr
) == NULL
)
12316 char *demangled
= NULL
;
12318 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
12320 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
12322 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
12325 /* Avoid demangling DW_STRING (attr) the second time on a second
12326 call for the same DIE. */
12327 if (!DW_STRING_IS_CANONICAL (attr
))
12328 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
12332 /* FIXME: we already did this for the partial symbol... */
12334 = obsavestring (demangled
, strlen (demangled
),
12335 &cu
->objfile
->objfile_obstack
);
12336 DW_STRING_IS_CANONICAL (attr
) = 1;
12346 if (!DW_STRING_IS_CANONICAL (attr
))
12349 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
12350 &cu
->objfile
->objfile_obstack
);
12351 DW_STRING_IS_CANONICAL (attr
) = 1;
12353 return DW_STRING (attr
);
12356 /* Return the die that this die in an extension of, or NULL if there
12357 is none. *EXT_CU is the CU containing DIE on input, and the CU
12358 containing the return value on output. */
12360 static struct die_info
*
12361 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
12363 struct attribute
*attr
;
12365 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
12369 return follow_die_ref (die
, attr
, ext_cu
);
12372 /* Convert a DIE tag into its string name. */
12375 dwarf_tag_name (unsigned tag
)
12379 case DW_TAG_padding
:
12380 return "DW_TAG_padding";
12381 case DW_TAG_array_type
:
12382 return "DW_TAG_array_type";
12383 case DW_TAG_class_type
:
12384 return "DW_TAG_class_type";
12385 case DW_TAG_entry_point
:
12386 return "DW_TAG_entry_point";
12387 case DW_TAG_enumeration_type
:
12388 return "DW_TAG_enumeration_type";
12389 case DW_TAG_formal_parameter
:
12390 return "DW_TAG_formal_parameter";
12391 case DW_TAG_imported_declaration
:
12392 return "DW_TAG_imported_declaration";
12394 return "DW_TAG_label";
12395 case DW_TAG_lexical_block
:
12396 return "DW_TAG_lexical_block";
12397 case DW_TAG_member
:
12398 return "DW_TAG_member";
12399 case DW_TAG_pointer_type
:
12400 return "DW_TAG_pointer_type";
12401 case DW_TAG_reference_type
:
12402 return "DW_TAG_reference_type";
12403 case DW_TAG_compile_unit
:
12404 return "DW_TAG_compile_unit";
12405 case DW_TAG_string_type
:
12406 return "DW_TAG_string_type";
12407 case DW_TAG_structure_type
:
12408 return "DW_TAG_structure_type";
12409 case DW_TAG_subroutine_type
:
12410 return "DW_TAG_subroutine_type";
12411 case DW_TAG_typedef
:
12412 return "DW_TAG_typedef";
12413 case DW_TAG_union_type
:
12414 return "DW_TAG_union_type";
12415 case DW_TAG_unspecified_parameters
:
12416 return "DW_TAG_unspecified_parameters";
12417 case DW_TAG_variant
:
12418 return "DW_TAG_variant";
12419 case DW_TAG_common_block
:
12420 return "DW_TAG_common_block";
12421 case DW_TAG_common_inclusion
:
12422 return "DW_TAG_common_inclusion";
12423 case DW_TAG_inheritance
:
12424 return "DW_TAG_inheritance";
12425 case DW_TAG_inlined_subroutine
:
12426 return "DW_TAG_inlined_subroutine";
12427 case DW_TAG_module
:
12428 return "DW_TAG_module";
12429 case DW_TAG_ptr_to_member_type
:
12430 return "DW_TAG_ptr_to_member_type";
12431 case DW_TAG_set_type
:
12432 return "DW_TAG_set_type";
12433 case DW_TAG_subrange_type
:
12434 return "DW_TAG_subrange_type";
12435 case DW_TAG_with_stmt
:
12436 return "DW_TAG_with_stmt";
12437 case DW_TAG_access_declaration
:
12438 return "DW_TAG_access_declaration";
12439 case DW_TAG_base_type
:
12440 return "DW_TAG_base_type";
12441 case DW_TAG_catch_block
:
12442 return "DW_TAG_catch_block";
12443 case DW_TAG_const_type
:
12444 return "DW_TAG_const_type";
12445 case DW_TAG_constant
:
12446 return "DW_TAG_constant";
12447 case DW_TAG_enumerator
:
12448 return "DW_TAG_enumerator";
12449 case DW_TAG_file_type
:
12450 return "DW_TAG_file_type";
12451 case DW_TAG_friend
:
12452 return "DW_TAG_friend";
12453 case DW_TAG_namelist
:
12454 return "DW_TAG_namelist";
12455 case DW_TAG_namelist_item
:
12456 return "DW_TAG_namelist_item";
12457 case DW_TAG_packed_type
:
12458 return "DW_TAG_packed_type";
12459 case DW_TAG_subprogram
:
12460 return "DW_TAG_subprogram";
12461 case DW_TAG_template_type_param
:
12462 return "DW_TAG_template_type_param";
12463 case DW_TAG_template_value_param
:
12464 return "DW_TAG_template_value_param";
12465 case DW_TAG_thrown_type
:
12466 return "DW_TAG_thrown_type";
12467 case DW_TAG_try_block
:
12468 return "DW_TAG_try_block";
12469 case DW_TAG_variant_part
:
12470 return "DW_TAG_variant_part";
12471 case DW_TAG_variable
:
12472 return "DW_TAG_variable";
12473 case DW_TAG_volatile_type
:
12474 return "DW_TAG_volatile_type";
12475 case DW_TAG_dwarf_procedure
:
12476 return "DW_TAG_dwarf_procedure";
12477 case DW_TAG_restrict_type
:
12478 return "DW_TAG_restrict_type";
12479 case DW_TAG_interface_type
:
12480 return "DW_TAG_interface_type";
12481 case DW_TAG_namespace
:
12482 return "DW_TAG_namespace";
12483 case DW_TAG_imported_module
:
12484 return "DW_TAG_imported_module";
12485 case DW_TAG_unspecified_type
:
12486 return "DW_TAG_unspecified_type";
12487 case DW_TAG_partial_unit
:
12488 return "DW_TAG_partial_unit";
12489 case DW_TAG_imported_unit
:
12490 return "DW_TAG_imported_unit";
12491 case DW_TAG_condition
:
12492 return "DW_TAG_condition";
12493 case DW_TAG_shared_type
:
12494 return "DW_TAG_shared_type";
12495 case DW_TAG_type_unit
:
12496 return "DW_TAG_type_unit";
12497 case DW_TAG_MIPS_loop
:
12498 return "DW_TAG_MIPS_loop";
12499 case DW_TAG_HP_array_descriptor
:
12500 return "DW_TAG_HP_array_descriptor";
12501 case DW_TAG_format_label
:
12502 return "DW_TAG_format_label";
12503 case DW_TAG_function_template
:
12504 return "DW_TAG_function_template";
12505 case DW_TAG_class_template
:
12506 return "DW_TAG_class_template";
12507 case DW_TAG_GNU_BINCL
:
12508 return "DW_TAG_GNU_BINCL";
12509 case DW_TAG_GNU_EINCL
:
12510 return "DW_TAG_GNU_EINCL";
12511 case DW_TAG_upc_shared_type
:
12512 return "DW_TAG_upc_shared_type";
12513 case DW_TAG_upc_strict_type
:
12514 return "DW_TAG_upc_strict_type";
12515 case DW_TAG_upc_relaxed_type
:
12516 return "DW_TAG_upc_relaxed_type";
12517 case DW_TAG_PGI_kanji_type
:
12518 return "DW_TAG_PGI_kanji_type";
12519 case DW_TAG_PGI_interface_block
:
12520 return "DW_TAG_PGI_interface_block";
12522 return "DW_TAG_<unknown>";
12526 /* Convert a DWARF attribute code into its string name. */
12529 dwarf_attr_name (unsigned attr
)
12533 case DW_AT_sibling
:
12534 return "DW_AT_sibling";
12535 case DW_AT_location
:
12536 return "DW_AT_location";
12538 return "DW_AT_name";
12539 case DW_AT_ordering
:
12540 return "DW_AT_ordering";
12541 case DW_AT_subscr_data
:
12542 return "DW_AT_subscr_data";
12543 case DW_AT_byte_size
:
12544 return "DW_AT_byte_size";
12545 case DW_AT_bit_offset
:
12546 return "DW_AT_bit_offset";
12547 case DW_AT_bit_size
:
12548 return "DW_AT_bit_size";
12549 case DW_AT_element_list
:
12550 return "DW_AT_element_list";
12551 case DW_AT_stmt_list
:
12552 return "DW_AT_stmt_list";
12554 return "DW_AT_low_pc";
12555 case DW_AT_high_pc
:
12556 return "DW_AT_high_pc";
12557 case DW_AT_language
:
12558 return "DW_AT_language";
12560 return "DW_AT_member";
12562 return "DW_AT_discr";
12563 case DW_AT_discr_value
:
12564 return "DW_AT_discr_value";
12565 case DW_AT_visibility
:
12566 return "DW_AT_visibility";
12568 return "DW_AT_import";
12569 case DW_AT_string_length
:
12570 return "DW_AT_string_length";
12571 case DW_AT_common_reference
:
12572 return "DW_AT_common_reference";
12573 case DW_AT_comp_dir
:
12574 return "DW_AT_comp_dir";
12575 case DW_AT_const_value
:
12576 return "DW_AT_const_value";
12577 case DW_AT_containing_type
:
12578 return "DW_AT_containing_type";
12579 case DW_AT_default_value
:
12580 return "DW_AT_default_value";
12582 return "DW_AT_inline";
12583 case DW_AT_is_optional
:
12584 return "DW_AT_is_optional";
12585 case DW_AT_lower_bound
:
12586 return "DW_AT_lower_bound";
12587 case DW_AT_producer
:
12588 return "DW_AT_producer";
12589 case DW_AT_prototyped
:
12590 return "DW_AT_prototyped";
12591 case DW_AT_return_addr
:
12592 return "DW_AT_return_addr";
12593 case DW_AT_start_scope
:
12594 return "DW_AT_start_scope";
12595 case DW_AT_bit_stride
:
12596 return "DW_AT_bit_stride";
12597 case DW_AT_upper_bound
:
12598 return "DW_AT_upper_bound";
12599 case DW_AT_abstract_origin
:
12600 return "DW_AT_abstract_origin";
12601 case DW_AT_accessibility
:
12602 return "DW_AT_accessibility";
12603 case DW_AT_address_class
:
12604 return "DW_AT_address_class";
12605 case DW_AT_artificial
:
12606 return "DW_AT_artificial";
12607 case DW_AT_base_types
:
12608 return "DW_AT_base_types";
12609 case DW_AT_calling_convention
:
12610 return "DW_AT_calling_convention";
12612 return "DW_AT_count";
12613 case DW_AT_data_member_location
:
12614 return "DW_AT_data_member_location";
12615 case DW_AT_decl_column
:
12616 return "DW_AT_decl_column";
12617 case DW_AT_decl_file
:
12618 return "DW_AT_decl_file";
12619 case DW_AT_decl_line
:
12620 return "DW_AT_decl_line";
12621 case DW_AT_declaration
:
12622 return "DW_AT_declaration";
12623 case DW_AT_discr_list
:
12624 return "DW_AT_discr_list";
12625 case DW_AT_encoding
:
12626 return "DW_AT_encoding";
12627 case DW_AT_external
:
12628 return "DW_AT_external";
12629 case DW_AT_frame_base
:
12630 return "DW_AT_frame_base";
12632 return "DW_AT_friend";
12633 case DW_AT_identifier_case
:
12634 return "DW_AT_identifier_case";
12635 case DW_AT_macro_info
:
12636 return "DW_AT_macro_info";
12637 case DW_AT_namelist_items
:
12638 return "DW_AT_namelist_items";
12639 case DW_AT_priority
:
12640 return "DW_AT_priority";
12641 case DW_AT_segment
:
12642 return "DW_AT_segment";
12643 case DW_AT_specification
:
12644 return "DW_AT_specification";
12645 case DW_AT_static_link
:
12646 return "DW_AT_static_link";
12648 return "DW_AT_type";
12649 case DW_AT_use_location
:
12650 return "DW_AT_use_location";
12651 case DW_AT_variable_parameter
:
12652 return "DW_AT_variable_parameter";
12653 case DW_AT_virtuality
:
12654 return "DW_AT_virtuality";
12655 case DW_AT_vtable_elem_location
:
12656 return "DW_AT_vtable_elem_location";
12657 /* DWARF 3 values. */
12658 case DW_AT_allocated
:
12659 return "DW_AT_allocated";
12660 case DW_AT_associated
:
12661 return "DW_AT_associated";
12662 case DW_AT_data_location
:
12663 return "DW_AT_data_location";
12664 case DW_AT_byte_stride
:
12665 return "DW_AT_byte_stride";
12666 case DW_AT_entry_pc
:
12667 return "DW_AT_entry_pc";
12668 case DW_AT_use_UTF8
:
12669 return "DW_AT_use_UTF8";
12670 case DW_AT_extension
:
12671 return "DW_AT_extension";
12673 return "DW_AT_ranges";
12674 case DW_AT_trampoline
:
12675 return "DW_AT_trampoline";
12676 case DW_AT_call_column
:
12677 return "DW_AT_call_column";
12678 case DW_AT_call_file
:
12679 return "DW_AT_call_file";
12680 case DW_AT_call_line
:
12681 return "DW_AT_call_line";
12682 case DW_AT_description
:
12683 return "DW_AT_description";
12684 case DW_AT_binary_scale
:
12685 return "DW_AT_binary_scale";
12686 case DW_AT_decimal_scale
:
12687 return "DW_AT_decimal_scale";
12689 return "DW_AT_small";
12690 case DW_AT_decimal_sign
:
12691 return "DW_AT_decimal_sign";
12692 case DW_AT_digit_count
:
12693 return "DW_AT_digit_count";
12694 case DW_AT_picture_string
:
12695 return "DW_AT_picture_string";
12696 case DW_AT_mutable
:
12697 return "DW_AT_mutable";
12698 case DW_AT_threads_scaled
:
12699 return "DW_AT_threads_scaled";
12700 case DW_AT_explicit
:
12701 return "DW_AT_explicit";
12702 case DW_AT_object_pointer
:
12703 return "DW_AT_object_pointer";
12704 case DW_AT_endianity
:
12705 return "DW_AT_endianity";
12706 case DW_AT_elemental
:
12707 return "DW_AT_elemental";
12709 return "DW_AT_pure";
12710 case DW_AT_recursive
:
12711 return "DW_AT_recursive";
12712 /* DWARF 4 values. */
12713 case DW_AT_signature
:
12714 return "DW_AT_signature";
12715 case DW_AT_linkage_name
:
12716 return "DW_AT_linkage_name";
12717 /* SGI/MIPS extensions. */
12718 #ifdef MIPS /* collides with DW_AT_HP_block_index */
12719 case DW_AT_MIPS_fde
:
12720 return "DW_AT_MIPS_fde";
12722 case DW_AT_MIPS_loop_begin
:
12723 return "DW_AT_MIPS_loop_begin";
12724 case DW_AT_MIPS_tail_loop_begin
:
12725 return "DW_AT_MIPS_tail_loop_begin";
12726 case DW_AT_MIPS_epilog_begin
:
12727 return "DW_AT_MIPS_epilog_begin";
12728 case DW_AT_MIPS_loop_unroll_factor
:
12729 return "DW_AT_MIPS_loop_unroll_factor";
12730 case DW_AT_MIPS_software_pipeline_depth
:
12731 return "DW_AT_MIPS_software_pipeline_depth";
12732 case DW_AT_MIPS_linkage_name
:
12733 return "DW_AT_MIPS_linkage_name";
12734 case DW_AT_MIPS_stride
:
12735 return "DW_AT_MIPS_stride";
12736 case DW_AT_MIPS_abstract_name
:
12737 return "DW_AT_MIPS_abstract_name";
12738 case DW_AT_MIPS_clone_origin
:
12739 return "DW_AT_MIPS_clone_origin";
12740 case DW_AT_MIPS_has_inlines
:
12741 return "DW_AT_MIPS_has_inlines";
12742 /* HP extensions. */
12743 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
12744 case DW_AT_HP_block_index
:
12745 return "DW_AT_HP_block_index";
12747 case DW_AT_HP_unmodifiable
:
12748 return "DW_AT_HP_unmodifiable";
12749 case DW_AT_HP_actuals_stmt_list
:
12750 return "DW_AT_HP_actuals_stmt_list";
12751 case DW_AT_HP_proc_per_section
:
12752 return "DW_AT_HP_proc_per_section";
12753 case DW_AT_HP_raw_data_ptr
:
12754 return "DW_AT_HP_raw_data_ptr";
12755 case DW_AT_HP_pass_by_reference
:
12756 return "DW_AT_HP_pass_by_reference";
12757 case DW_AT_HP_opt_level
:
12758 return "DW_AT_HP_opt_level";
12759 case DW_AT_HP_prof_version_id
:
12760 return "DW_AT_HP_prof_version_id";
12761 case DW_AT_HP_opt_flags
:
12762 return "DW_AT_HP_opt_flags";
12763 case DW_AT_HP_cold_region_low_pc
:
12764 return "DW_AT_HP_cold_region_low_pc";
12765 case DW_AT_HP_cold_region_high_pc
:
12766 return "DW_AT_HP_cold_region_high_pc";
12767 case DW_AT_HP_all_variables_modifiable
:
12768 return "DW_AT_HP_all_variables_modifiable";
12769 case DW_AT_HP_linkage_name
:
12770 return "DW_AT_HP_linkage_name";
12771 case DW_AT_HP_prof_flags
:
12772 return "DW_AT_HP_prof_flags";
12773 /* GNU extensions. */
12774 case DW_AT_sf_names
:
12775 return "DW_AT_sf_names";
12776 case DW_AT_src_info
:
12777 return "DW_AT_src_info";
12778 case DW_AT_mac_info
:
12779 return "DW_AT_mac_info";
12780 case DW_AT_src_coords
:
12781 return "DW_AT_src_coords";
12782 case DW_AT_body_begin
:
12783 return "DW_AT_body_begin";
12784 case DW_AT_body_end
:
12785 return "DW_AT_body_end";
12786 case DW_AT_GNU_vector
:
12787 return "DW_AT_GNU_vector";
12788 case DW_AT_GNU_odr_signature
:
12789 return "DW_AT_GNU_odr_signature";
12790 /* VMS extensions. */
12791 case DW_AT_VMS_rtnbeg_pd_address
:
12792 return "DW_AT_VMS_rtnbeg_pd_address";
12793 /* UPC extension. */
12794 case DW_AT_upc_threads_scaled
:
12795 return "DW_AT_upc_threads_scaled";
12796 /* PGI (STMicroelectronics) extensions. */
12797 case DW_AT_PGI_lbase
:
12798 return "DW_AT_PGI_lbase";
12799 case DW_AT_PGI_soffset
:
12800 return "DW_AT_PGI_soffset";
12801 case DW_AT_PGI_lstride
:
12802 return "DW_AT_PGI_lstride";
12804 return "DW_AT_<unknown>";
12808 /* Convert a DWARF value form code into its string name. */
12811 dwarf_form_name (unsigned form
)
12816 return "DW_FORM_addr";
12817 case DW_FORM_block2
:
12818 return "DW_FORM_block2";
12819 case DW_FORM_block4
:
12820 return "DW_FORM_block4";
12821 case DW_FORM_data2
:
12822 return "DW_FORM_data2";
12823 case DW_FORM_data4
:
12824 return "DW_FORM_data4";
12825 case DW_FORM_data8
:
12826 return "DW_FORM_data8";
12827 case DW_FORM_string
:
12828 return "DW_FORM_string";
12829 case DW_FORM_block
:
12830 return "DW_FORM_block";
12831 case DW_FORM_block1
:
12832 return "DW_FORM_block1";
12833 case DW_FORM_data1
:
12834 return "DW_FORM_data1";
12836 return "DW_FORM_flag";
12837 case DW_FORM_sdata
:
12838 return "DW_FORM_sdata";
12840 return "DW_FORM_strp";
12841 case DW_FORM_udata
:
12842 return "DW_FORM_udata";
12843 case DW_FORM_ref_addr
:
12844 return "DW_FORM_ref_addr";
12846 return "DW_FORM_ref1";
12848 return "DW_FORM_ref2";
12850 return "DW_FORM_ref4";
12852 return "DW_FORM_ref8";
12853 case DW_FORM_ref_udata
:
12854 return "DW_FORM_ref_udata";
12855 case DW_FORM_indirect
:
12856 return "DW_FORM_indirect";
12857 case DW_FORM_sec_offset
:
12858 return "DW_FORM_sec_offset";
12859 case DW_FORM_exprloc
:
12860 return "DW_FORM_exprloc";
12861 case DW_FORM_flag_present
:
12862 return "DW_FORM_flag_present";
12863 case DW_FORM_ref_sig8
:
12864 return "DW_FORM_ref_sig8";
12866 return "DW_FORM_<unknown>";
12870 /* Convert a DWARF stack opcode into its string name. */
12873 dwarf_stack_op_name (unsigned op
)
12878 return "DW_OP_addr";
12880 return "DW_OP_deref";
12881 case DW_OP_const1u
:
12882 return "DW_OP_const1u";
12883 case DW_OP_const1s
:
12884 return "DW_OP_const1s";
12885 case DW_OP_const2u
:
12886 return "DW_OP_const2u";
12887 case DW_OP_const2s
:
12888 return "DW_OP_const2s";
12889 case DW_OP_const4u
:
12890 return "DW_OP_const4u";
12891 case DW_OP_const4s
:
12892 return "DW_OP_const4s";
12893 case DW_OP_const8u
:
12894 return "DW_OP_const8u";
12895 case DW_OP_const8s
:
12896 return "DW_OP_const8s";
12898 return "DW_OP_constu";
12900 return "DW_OP_consts";
12902 return "DW_OP_dup";
12904 return "DW_OP_drop";
12906 return "DW_OP_over";
12908 return "DW_OP_pick";
12910 return "DW_OP_swap";
12912 return "DW_OP_rot";
12914 return "DW_OP_xderef";
12916 return "DW_OP_abs";
12918 return "DW_OP_and";
12920 return "DW_OP_div";
12922 return "DW_OP_minus";
12924 return "DW_OP_mod";
12926 return "DW_OP_mul";
12928 return "DW_OP_neg";
12930 return "DW_OP_not";
12934 return "DW_OP_plus";
12935 case DW_OP_plus_uconst
:
12936 return "DW_OP_plus_uconst";
12938 return "DW_OP_shl";
12940 return "DW_OP_shr";
12942 return "DW_OP_shra";
12944 return "DW_OP_xor";
12946 return "DW_OP_bra";
12960 return "DW_OP_skip";
12962 return "DW_OP_lit0";
12964 return "DW_OP_lit1";
12966 return "DW_OP_lit2";
12968 return "DW_OP_lit3";
12970 return "DW_OP_lit4";
12972 return "DW_OP_lit5";
12974 return "DW_OP_lit6";
12976 return "DW_OP_lit7";
12978 return "DW_OP_lit8";
12980 return "DW_OP_lit9";
12982 return "DW_OP_lit10";
12984 return "DW_OP_lit11";
12986 return "DW_OP_lit12";
12988 return "DW_OP_lit13";
12990 return "DW_OP_lit14";
12992 return "DW_OP_lit15";
12994 return "DW_OP_lit16";
12996 return "DW_OP_lit17";
12998 return "DW_OP_lit18";
13000 return "DW_OP_lit19";
13002 return "DW_OP_lit20";
13004 return "DW_OP_lit21";
13006 return "DW_OP_lit22";
13008 return "DW_OP_lit23";
13010 return "DW_OP_lit24";
13012 return "DW_OP_lit25";
13014 return "DW_OP_lit26";
13016 return "DW_OP_lit27";
13018 return "DW_OP_lit28";
13020 return "DW_OP_lit29";
13022 return "DW_OP_lit30";
13024 return "DW_OP_lit31";
13026 return "DW_OP_reg0";
13028 return "DW_OP_reg1";
13030 return "DW_OP_reg2";
13032 return "DW_OP_reg3";
13034 return "DW_OP_reg4";
13036 return "DW_OP_reg5";
13038 return "DW_OP_reg6";
13040 return "DW_OP_reg7";
13042 return "DW_OP_reg8";
13044 return "DW_OP_reg9";
13046 return "DW_OP_reg10";
13048 return "DW_OP_reg11";
13050 return "DW_OP_reg12";
13052 return "DW_OP_reg13";
13054 return "DW_OP_reg14";
13056 return "DW_OP_reg15";
13058 return "DW_OP_reg16";
13060 return "DW_OP_reg17";
13062 return "DW_OP_reg18";
13064 return "DW_OP_reg19";
13066 return "DW_OP_reg20";
13068 return "DW_OP_reg21";
13070 return "DW_OP_reg22";
13072 return "DW_OP_reg23";
13074 return "DW_OP_reg24";
13076 return "DW_OP_reg25";
13078 return "DW_OP_reg26";
13080 return "DW_OP_reg27";
13082 return "DW_OP_reg28";
13084 return "DW_OP_reg29";
13086 return "DW_OP_reg30";
13088 return "DW_OP_reg31";
13090 return "DW_OP_breg0";
13092 return "DW_OP_breg1";
13094 return "DW_OP_breg2";
13096 return "DW_OP_breg3";
13098 return "DW_OP_breg4";
13100 return "DW_OP_breg5";
13102 return "DW_OP_breg6";
13104 return "DW_OP_breg7";
13106 return "DW_OP_breg8";
13108 return "DW_OP_breg9";
13110 return "DW_OP_breg10";
13112 return "DW_OP_breg11";
13114 return "DW_OP_breg12";
13116 return "DW_OP_breg13";
13118 return "DW_OP_breg14";
13120 return "DW_OP_breg15";
13122 return "DW_OP_breg16";
13124 return "DW_OP_breg17";
13126 return "DW_OP_breg18";
13128 return "DW_OP_breg19";
13130 return "DW_OP_breg20";
13132 return "DW_OP_breg21";
13134 return "DW_OP_breg22";
13136 return "DW_OP_breg23";
13138 return "DW_OP_breg24";
13140 return "DW_OP_breg25";
13142 return "DW_OP_breg26";
13144 return "DW_OP_breg27";
13146 return "DW_OP_breg28";
13148 return "DW_OP_breg29";
13150 return "DW_OP_breg30";
13152 return "DW_OP_breg31";
13154 return "DW_OP_regx";
13156 return "DW_OP_fbreg";
13158 return "DW_OP_bregx";
13160 return "DW_OP_piece";
13161 case DW_OP_deref_size
:
13162 return "DW_OP_deref_size";
13163 case DW_OP_xderef_size
:
13164 return "DW_OP_xderef_size";
13166 return "DW_OP_nop";
13167 /* DWARF 3 extensions. */
13168 case DW_OP_push_object_address
:
13169 return "DW_OP_push_object_address";
13171 return "DW_OP_call2";
13173 return "DW_OP_call4";
13174 case DW_OP_call_ref
:
13175 return "DW_OP_call_ref";
13176 case DW_OP_form_tls_address
:
13177 return "DW_OP_form_tls_address";
13178 case DW_OP_call_frame_cfa
:
13179 return "DW_OP_call_frame_cfa";
13180 case DW_OP_bit_piece
:
13181 return "DW_OP_bit_piece";
13182 /* DWARF 4 extensions. */
13183 case DW_OP_implicit_value
:
13184 return "DW_OP_implicit_value";
13185 case DW_OP_stack_value
:
13186 return "DW_OP_stack_value";
13187 /* GNU extensions. */
13188 case DW_OP_GNU_push_tls_address
:
13189 return "DW_OP_GNU_push_tls_address";
13190 case DW_OP_GNU_uninit
:
13191 return "DW_OP_GNU_uninit";
13192 case DW_OP_GNU_implicit_pointer
:
13193 return "DW_OP_GNU_implicit_pointer";
13194 case DW_OP_GNU_entry_value
:
13195 return "DW_OP_GNU_entry_value";
13196 case DW_OP_GNU_const_type
:
13197 return "DW_OP_GNU_const_type";
13198 case DW_OP_GNU_regval_type
:
13199 return "DW_OP_GNU_regval_type";
13200 case DW_OP_GNU_deref_type
:
13201 return "DW_OP_GNU_deref_type";
13202 case DW_OP_GNU_convert
:
13203 return "DW_OP_GNU_convert";
13204 case DW_OP_GNU_reinterpret
:
13205 return "DW_OP_GNU_reinterpret";
13212 dwarf_bool_name (unsigned mybool
)
13220 /* Convert a DWARF type code into its string name. */
13223 dwarf_type_encoding_name (unsigned enc
)
13228 return "DW_ATE_void";
13229 case DW_ATE_address
:
13230 return "DW_ATE_address";
13231 case DW_ATE_boolean
:
13232 return "DW_ATE_boolean";
13233 case DW_ATE_complex_float
:
13234 return "DW_ATE_complex_float";
13236 return "DW_ATE_float";
13237 case DW_ATE_signed
:
13238 return "DW_ATE_signed";
13239 case DW_ATE_signed_char
:
13240 return "DW_ATE_signed_char";
13241 case DW_ATE_unsigned
:
13242 return "DW_ATE_unsigned";
13243 case DW_ATE_unsigned_char
:
13244 return "DW_ATE_unsigned_char";
13246 case DW_ATE_imaginary_float
:
13247 return "DW_ATE_imaginary_float";
13248 case DW_ATE_packed_decimal
:
13249 return "DW_ATE_packed_decimal";
13250 case DW_ATE_numeric_string
:
13251 return "DW_ATE_numeric_string";
13252 case DW_ATE_edited
:
13253 return "DW_ATE_edited";
13254 case DW_ATE_signed_fixed
:
13255 return "DW_ATE_signed_fixed";
13256 case DW_ATE_unsigned_fixed
:
13257 return "DW_ATE_unsigned_fixed";
13258 case DW_ATE_decimal_float
:
13259 return "DW_ATE_decimal_float";
13262 return "DW_ATE_UTF";
13263 /* HP extensions. */
13264 case DW_ATE_HP_float80
:
13265 return "DW_ATE_HP_float80";
13266 case DW_ATE_HP_complex_float80
:
13267 return "DW_ATE_HP_complex_float80";
13268 case DW_ATE_HP_float128
:
13269 return "DW_ATE_HP_float128";
13270 case DW_ATE_HP_complex_float128
:
13271 return "DW_ATE_HP_complex_float128";
13272 case DW_ATE_HP_floathpintel
:
13273 return "DW_ATE_HP_floathpintel";
13274 case DW_ATE_HP_imaginary_float80
:
13275 return "DW_ATE_HP_imaginary_float80";
13276 case DW_ATE_HP_imaginary_float128
:
13277 return "DW_ATE_HP_imaginary_float128";
13279 return "DW_ATE_<unknown>";
13283 /* Convert a DWARF call frame info operation to its string name. */
13287 dwarf_cfi_name (unsigned cfi_opc
)
13291 case DW_CFA_advance_loc
:
13292 return "DW_CFA_advance_loc";
13293 case DW_CFA_offset
:
13294 return "DW_CFA_offset";
13295 case DW_CFA_restore
:
13296 return "DW_CFA_restore";
13298 return "DW_CFA_nop";
13299 case DW_CFA_set_loc
:
13300 return "DW_CFA_set_loc";
13301 case DW_CFA_advance_loc1
:
13302 return "DW_CFA_advance_loc1";
13303 case DW_CFA_advance_loc2
:
13304 return "DW_CFA_advance_loc2";
13305 case DW_CFA_advance_loc4
:
13306 return "DW_CFA_advance_loc4";
13307 case DW_CFA_offset_extended
:
13308 return "DW_CFA_offset_extended";
13309 case DW_CFA_restore_extended
:
13310 return "DW_CFA_restore_extended";
13311 case DW_CFA_undefined
:
13312 return "DW_CFA_undefined";
13313 case DW_CFA_same_value
:
13314 return "DW_CFA_same_value";
13315 case DW_CFA_register
:
13316 return "DW_CFA_register";
13317 case DW_CFA_remember_state
:
13318 return "DW_CFA_remember_state";
13319 case DW_CFA_restore_state
:
13320 return "DW_CFA_restore_state";
13321 case DW_CFA_def_cfa
:
13322 return "DW_CFA_def_cfa";
13323 case DW_CFA_def_cfa_register
:
13324 return "DW_CFA_def_cfa_register";
13325 case DW_CFA_def_cfa_offset
:
13326 return "DW_CFA_def_cfa_offset";
13328 case DW_CFA_def_cfa_expression
:
13329 return "DW_CFA_def_cfa_expression";
13330 case DW_CFA_expression
:
13331 return "DW_CFA_expression";
13332 case DW_CFA_offset_extended_sf
:
13333 return "DW_CFA_offset_extended_sf";
13334 case DW_CFA_def_cfa_sf
:
13335 return "DW_CFA_def_cfa_sf";
13336 case DW_CFA_def_cfa_offset_sf
:
13337 return "DW_CFA_def_cfa_offset_sf";
13338 case DW_CFA_val_offset
:
13339 return "DW_CFA_val_offset";
13340 case DW_CFA_val_offset_sf
:
13341 return "DW_CFA_val_offset_sf";
13342 case DW_CFA_val_expression
:
13343 return "DW_CFA_val_expression";
13344 /* SGI/MIPS specific. */
13345 case DW_CFA_MIPS_advance_loc8
:
13346 return "DW_CFA_MIPS_advance_loc8";
13347 /* GNU extensions. */
13348 case DW_CFA_GNU_window_save
:
13349 return "DW_CFA_GNU_window_save";
13350 case DW_CFA_GNU_args_size
:
13351 return "DW_CFA_GNU_args_size";
13352 case DW_CFA_GNU_negative_offset_extended
:
13353 return "DW_CFA_GNU_negative_offset_extended";
13355 return "DW_CFA_<unknown>";
13361 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
13365 print_spaces (indent
, f
);
13366 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
13367 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
13369 if (die
->parent
!= NULL
)
13371 print_spaces (indent
, f
);
13372 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
13373 die
->parent
->offset
);
13376 print_spaces (indent
, f
);
13377 fprintf_unfiltered (f
, " has children: %s\n",
13378 dwarf_bool_name (die
->child
!= NULL
));
13380 print_spaces (indent
, f
);
13381 fprintf_unfiltered (f
, " attributes:\n");
13383 for (i
= 0; i
< die
->num_attrs
; ++i
)
13385 print_spaces (indent
, f
);
13386 fprintf_unfiltered (f
, " %s (%s) ",
13387 dwarf_attr_name (die
->attrs
[i
].name
),
13388 dwarf_form_name (die
->attrs
[i
].form
));
13390 switch (die
->attrs
[i
].form
)
13392 case DW_FORM_ref_addr
:
13394 fprintf_unfiltered (f
, "address: ");
13395 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
13397 case DW_FORM_block2
:
13398 case DW_FORM_block4
:
13399 case DW_FORM_block
:
13400 case DW_FORM_block1
:
13401 fprintf_unfiltered (f
, "block: size %d",
13402 DW_BLOCK (&die
->attrs
[i
])->size
);
13404 case DW_FORM_exprloc
:
13405 fprintf_unfiltered (f
, "expression: size %u",
13406 DW_BLOCK (&die
->attrs
[i
])->size
);
13411 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
13412 (long) (DW_ADDR (&die
->attrs
[i
])));
13414 case DW_FORM_data1
:
13415 case DW_FORM_data2
:
13416 case DW_FORM_data4
:
13417 case DW_FORM_data8
:
13418 case DW_FORM_udata
:
13419 case DW_FORM_sdata
:
13420 fprintf_unfiltered (f
, "constant: %s",
13421 pulongest (DW_UNSND (&die
->attrs
[i
])));
13423 case DW_FORM_sec_offset
:
13424 fprintf_unfiltered (f
, "section offset: %s",
13425 pulongest (DW_UNSND (&die
->attrs
[i
])));
13427 case DW_FORM_ref_sig8
:
13428 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
13429 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
13430 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
);
13432 fprintf_unfiltered (f
, "signatured type, offset: unknown");
13434 case DW_FORM_string
:
13436 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
13437 DW_STRING (&die
->attrs
[i
])
13438 ? DW_STRING (&die
->attrs
[i
]) : "",
13439 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
13442 if (DW_UNSND (&die
->attrs
[i
]))
13443 fprintf_unfiltered (f
, "flag: TRUE");
13445 fprintf_unfiltered (f
, "flag: FALSE");
13447 case DW_FORM_flag_present
:
13448 fprintf_unfiltered (f
, "flag: TRUE");
13450 case DW_FORM_indirect
:
13451 /* The reader will have reduced the indirect form to
13452 the "base form" so this form should not occur. */
13453 fprintf_unfiltered (f
,
13454 "unexpected attribute form: DW_FORM_indirect");
13457 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
13458 die
->attrs
[i
].form
);
13461 fprintf_unfiltered (f
, "\n");
13466 dump_die_for_error (struct die_info
*die
)
13468 dump_die_shallow (gdb_stderr
, 0, die
);
13472 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
13474 int indent
= level
* 4;
13476 gdb_assert (die
!= NULL
);
13478 if (level
>= max_level
)
13481 dump_die_shallow (f
, indent
, die
);
13483 if (die
->child
!= NULL
)
13485 print_spaces (indent
, f
);
13486 fprintf_unfiltered (f
, " Children:");
13487 if (level
+ 1 < max_level
)
13489 fprintf_unfiltered (f
, "\n");
13490 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
13494 fprintf_unfiltered (f
,
13495 " [not printed, max nesting level reached]\n");
13499 if (die
->sibling
!= NULL
&& level
> 0)
13501 dump_die_1 (f
, level
, max_level
, die
->sibling
);
13505 /* This is called from the pdie macro in gdbinit.in.
13506 It's not static so gcc will keep a copy callable from gdb. */
13509 dump_die (struct die_info
*die
, int max_level
)
13511 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
13515 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
13519 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
13525 is_ref_attr (struct attribute
*attr
)
13527 switch (attr
->form
)
13529 case DW_FORM_ref_addr
:
13534 case DW_FORM_ref_udata
:
13541 static unsigned int
13542 dwarf2_get_ref_die_offset (struct attribute
*attr
)
13544 if (is_ref_attr (attr
))
13545 return DW_ADDR (attr
);
13547 complaint (&symfile_complaints
,
13548 _("unsupported die ref attribute form: '%s'"),
13549 dwarf_form_name (attr
->form
));
13553 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
13554 * the value held by the attribute is not constant. */
13557 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
13559 if (attr
->form
== DW_FORM_sdata
)
13560 return DW_SND (attr
);
13561 else if (attr
->form
== DW_FORM_udata
13562 || attr
->form
== DW_FORM_data1
13563 || attr
->form
== DW_FORM_data2
13564 || attr
->form
== DW_FORM_data4
13565 || attr
->form
== DW_FORM_data8
)
13566 return DW_UNSND (attr
);
13569 complaint (&symfile_complaints
,
13570 _("Attribute value is not a constant (%s)"),
13571 dwarf_form_name (attr
->form
));
13572 return default_value
;
13576 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
13577 unit and add it to our queue.
13578 The result is non-zero if PER_CU was queued, otherwise the result is zero
13579 meaning either PER_CU is already queued or it is already loaded. */
13582 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
13583 struct dwarf2_per_cu_data
*per_cu
)
13585 /* We may arrive here during partial symbol reading, if we need full
13586 DIEs to process an unusual case (e.g. template arguments). Do
13587 not queue PER_CU, just tell our caller to load its DIEs. */
13588 if (dwarf2_per_objfile
->reading_partial_symbols
)
13590 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
13595 /* Mark the dependence relation so that we don't flush PER_CU
13597 dwarf2_add_dependence (this_cu
, per_cu
);
13599 /* If it's already on the queue, we have nothing to do. */
13600 if (per_cu
->queued
)
13603 /* If the compilation unit is already loaded, just mark it as
13605 if (per_cu
->cu
!= NULL
)
13607 per_cu
->cu
->last_used
= 0;
13611 /* Add it to the queue. */
13612 queue_comp_unit (per_cu
, this_cu
->objfile
);
13617 /* Follow reference or signature attribute ATTR of SRC_DIE.
13618 On entry *REF_CU is the CU of SRC_DIE.
13619 On exit *REF_CU is the CU of the result. */
13621 static struct die_info
*
13622 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
13623 struct dwarf2_cu
**ref_cu
)
13625 struct die_info
*die
;
13627 if (is_ref_attr (attr
))
13628 die
= follow_die_ref (src_die
, attr
, ref_cu
);
13629 else if (attr
->form
== DW_FORM_ref_sig8
)
13630 die
= follow_die_sig (src_die
, attr
, ref_cu
);
13633 dump_die_for_error (src_die
);
13634 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
13635 (*ref_cu
)->objfile
->name
);
13641 /* Follow reference OFFSET.
13642 On entry *REF_CU is the CU of the source die referencing OFFSET.
13643 On exit *REF_CU is the CU of the result.
13644 Returns NULL if OFFSET is invalid. */
13646 static struct die_info
*
13647 follow_die_offset (unsigned int offset
, struct dwarf2_cu
**ref_cu
)
13649 struct die_info temp_die
;
13650 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
13652 gdb_assert (cu
->per_cu
!= NULL
);
13656 if (cu
->per_cu
->from_debug_types
)
13658 /* .debug_types CUs cannot reference anything outside their CU.
13659 If they need to, they have to reference a signatured type via
13660 DW_FORM_ref_sig8. */
13661 if (! offset_in_cu_p (&cu
->header
, offset
))
13664 else if (! offset_in_cu_p (&cu
->header
, offset
))
13666 struct dwarf2_per_cu_data
*per_cu
;
13668 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
13670 /* If necessary, add it to the queue and load its DIEs. */
13671 if (maybe_queue_comp_unit (cu
, per_cu
))
13672 load_full_comp_unit (per_cu
, cu
->objfile
);
13674 target_cu
= per_cu
->cu
;
13676 else if (cu
->dies
== NULL
)
13678 /* We're loading full DIEs during partial symbol reading. */
13679 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
13680 load_full_comp_unit (cu
->per_cu
, cu
->objfile
);
13683 *ref_cu
= target_cu
;
13684 temp_die
.offset
= offset
;
13685 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
13688 /* Follow reference attribute ATTR of SRC_DIE.
13689 On entry *REF_CU is the CU of SRC_DIE.
13690 On exit *REF_CU is the CU of the result. */
13692 static struct die_info
*
13693 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
13694 struct dwarf2_cu
**ref_cu
)
13696 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
13697 struct dwarf2_cu
*cu
= *ref_cu
;
13698 struct die_info
*die
;
13700 die
= follow_die_offset (offset
, ref_cu
);
13702 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
13703 "at 0x%x [in module %s]"),
13704 offset
, src_die
->offset
, cu
->objfile
->name
);
13709 /* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned
13710 value is intended for DW_OP_call*. */
13712 struct dwarf2_locexpr_baton
13713 dwarf2_fetch_die_location_block (unsigned int offset
,
13714 struct dwarf2_per_cu_data
*per_cu
,
13715 CORE_ADDR (*get_frame_pc
) (void *baton
),
13718 struct dwarf2_cu
*cu
= per_cu
->cu
;
13719 struct die_info
*die
;
13720 struct attribute
*attr
;
13721 struct dwarf2_locexpr_baton retval
;
13723 dw2_setup (per_cu
->objfile
);
13725 die
= follow_die_offset (offset
, &cu
);
13727 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
13728 offset
, per_cu
->cu
->objfile
->name
);
13730 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13733 /* DWARF: "If there is no such attribute, then there is no effect.". */
13735 retval
.data
= NULL
;
13738 else if (attr_form_is_section_offset (attr
))
13740 struct dwarf2_loclist_baton loclist_baton
;
13741 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
13744 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
13746 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
13748 retval
.size
= size
;
13752 if (!attr_form_is_block (attr
))
13753 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
13754 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
13755 offset
, per_cu
->cu
->objfile
->name
);
13757 retval
.data
= DW_BLOCK (attr
)->data
;
13758 retval
.size
= DW_BLOCK (attr
)->size
;
13760 retval
.per_cu
= cu
->per_cu
;
13764 /* Return the type of the DIE at DIE_OFFSET in the CU named by
13768 dwarf2_get_die_type (unsigned int die_offset
,
13769 struct dwarf2_per_cu_data
*per_cu
)
13771 dw2_setup (per_cu
->objfile
);
13772 return get_die_type_at_offset (die_offset
, per_cu
);
13775 /* Follow the signature attribute ATTR in SRC_DIE.
13776 On entry *REF_CU is the CU of SRC_DIE.
13777 On exit *REF_CU is the CU of the result. */
13779 static struct die_info
*
13780 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
13781 struct dwarf2_cu
**ref_cu
)
13783 struct objfile
*objfile
= (*ref_cu
)->objfile
;
13784 struct die_info temp_die
;
13785 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
13786 struct dwarf2_cu
*sig_cu
;
13787 struct die_info
*die
;
13789 /* sig_type will be NULL if the signatured type is missing from
13791 if (sig_type
== NULL
)
13792 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
13793 "at 0x%x [in module %s]"),
13794 src_die
->offset
, objfile
->name
);
13796 /* If necessary, add it to the queue and load its DIEs. */
13798 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
13799 read_signatured_type (objfile
, sig_type
);
13801 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
13803 sig_cu
= sig_type
->per_cu
.cu
;
13804 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
13805 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
13812 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
13813 "from DIE at 0x%x [in module %s]"),
13814 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
13817 /* Given an offset of a signatured type, return its signatured_type. */
13819 static struct signatured_type
*
13820 lookup_signatured_type_at_offset (struct objfile
*objfile
, unsigned int offset
)
13822 gdb_byte
*info_ptr
= dwarf2_per_objfile
->types
.buffer
+ offset
;
13823 unsigned int length
, initial_length_size
;
13824 unsigned int sig_offset
;
13825 struct signatured_type find_entry
, *type_sig
;
13827 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
13828 sig_offset
= (initial_length_size
13830 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
13831 + 1 /*address_size*/);
13832 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
13833 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
13835 /* This is only used to lookup previously recorded types.
13836 If we didn't find it, it's our bug. */
13837 gdb_assert (type_sig
!= NULL
);
13838 gdb_assert (offset
== type_sig
->per_cu
.offset
);
13843 /* Read in signatured type at OFFSET and build its CU and die(s). */
13846 read_signatured_type_at_offset (struct objfile
*objfile
,
13847 unsigned int offset
)
13849 struct signatured_type
*type_sig
;
13851 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
13853 /* We have the section offset, but we need the signature to do the
13854 hash table lookup. */
13855 type_sig
= lookup_signatured_type_at_offset (objfile
, offset
);
13857 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
13859 read_signatured_type (objfile
, type_sig
);
13861 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
13864 /* Read in a signatured type and build its CU and DIEs. */
13867 read_signatured_type (struct objfile
*objfile
,
13868 struct signatured_type
*type_sig
)
13870 gdb_byte
*types_ptr
;
13871 struct die_reader_specs reader_specs
;
13872 struct dwarf2_cu
*cu
;
13873 ULONGEST signature
;
13874 struct cleanup
*back_to
, *free_cu_cleanup
;
13876 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
13877 types_ptr
= dwarf2_per_objfile
->types
.buffer
+ type_sig
->per_cu
.offset
;
13879 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
13881 cu
= xmalloc (sizeof (*cu
));
13882 init_one_comp_unit (cu
, objfile
);
13884 type_sig
->per_cu
.cu
= cu
;
13885 cu
->per_cu
= &type_sig
->per_cu
;
13887 /* If an error occurs while loading, release our storage. */
13888 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
13890 types_ptr
= read_type_comp_unit_head (&cu
->header
, &signature
,
13891 types_ptr
, objfile
->obfd
);
13892 gdb_assert (signature
== type_sig
->signature
);
13895 = htab_create_alloc_ex (cu
->header
.length
/ 12,
13899 &cu
->comp_unit_obstack
,
13900 hashtab_obstack_allocate
,
13901 dummy_obstack_deallocate
);
13903 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
13904 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
13906 init_cu_die_reader (&reader_specs
, cu
);
13908 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
13911 /* We try not to read any attributes in this function, because not
13912 all objfiles needed for references have been loaded yet, and symbol
13913 table processing isn't initialized. But we have to set the CU language,
13914 or we won't be able to build types correctly. */
13915 prepare_one_comp_unit (cu
, cu
->dies
);
13917 do_cleanups (back_to
);
13919 /* We've successfully allocated this compilation unit. Let our caller
13920 clean it up when finished with it. */
13921 discard_cleanups (free_cu_cleanup
);
13923 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
13924 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
13927 /* Decode simple location descriptions.
13928 Given a pointer to a dwarf block that defines a location, compute
13929 the location and return the value.
13931 NOTE drow/2003-11-18: This function is called in two situations
13932 now: for the address of static or global variables (partial symbols
13933 only) and for offsets into structures which are expected to be
13934 (more or less) constant. The partial symbol case should go away,
13935 and only the constant case should remain. That will let this
13936 function complain more accurately. A few special modes are allowed
13937 without complaint for global variables (for instance, global
13938 register values and thread-local values).
13940 A location description containing no operations indicates that the
13941 object is optimized out. The return value is 0 for that case.
13942 FIXME drow/2003-11-16: No callers check for this case any more; soon all
13943 callers will only want a very basic result and this can become a
13946 Note that stack[0] is unused except as a default error return. */
13949 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
13951 struct objfile
*objfile
= cu
->objfile
;
13953 int size
= blk
->size
;
13954 gdb_byte
*data
= blk
->data
;
13955 CORE_ADDR stack
[64];
13957 unsigned int bytes_read
, unsnd
;
13963 stack
[++stacki
] = 0;
14002 stack
[++stacki
] = op
- DW_OP_lit0
;
14037 stack
[++stacki
] = op
- DW_OP_reg0
;
14039 dwarf2_complex_location_expr_complaint ();
14043 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
14045 stack
[++stacki
] = unsnd
;
14047 dwarf2_complex_location_expr_complaint ();
14051 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
14056 case DW_OP_const1u
:
14057 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
14061 case DW_OP_const1s
:
14062 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
14066 case DW_OP_const2u
:
14067 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
14071 case DW_OP_const2s
:
14072 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
14076 case DW_OP_const4u
:
14077 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
14081 case DW_OP_const4s
:
14082 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
14087 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
14093 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
14098 stack
[stacki
+ 1] = stack
[stacki
];
14103 stack
[stacki
- 1] += stack
[stacki
];
14107 case DW_OP_plus_uconst
:
14108 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
14114 stack
[stacki
- 1] -= stack
[stacki
];
14119 /* If we're not the last op, then we definitely can't encode
14120 this using GDB's address_class enum. This is valid for partial
14121 global symbols, although the variable's address will be bogus
14124 dwarf2_complex_location_expr_complaint ();
14127 case DW_OP_GNU_push_tls_address
:
14128 /* The top of the stack has the offset from the beginning
14129 of the thread control block at which the variable is located. */
14130 /* Nothing should follow this operator, so the top of stack would
14132 /* This is valid for partial global symbols, but the variable's
14133 address will be bogus in the psymtab. */
14135 dwarf2_complex_location_expr_complaint ();
14138 case DW_OP_GNU_uninit
:
14143 const char *name
= dwarf_stack_op_name (op
);
14146 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
14149 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
14153 return (stack
[stacki
]);
14156 /* Enforce maximum stack depth of SIZE-1 to avoid writing
14157 outside of the allocated space. Also enforce minimum>0. */
14158 if (stacki
>= ARRAY_SIZE (stack
) - 1)
14160 complaint (&symfile_complaints
,
14161 _("location description stack overflow"));
14167 complaint (&symfile_complaints
,
14168 _("location description stack underflow"));
14172 return (stack
[stacki
]);
14175 /* memory allocation interface */
14177 static struct dwarf_block
*
14178 dwarf_alloc_block (struct dwarf2_cu
*cu
)
14180 struct dwarf_block
*blk
;
14182 blk
= (struct dwarf_block
*)
14183 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
14187 static struct abbrev_info
*
14188 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
14190 struct abbrev_info
*abbrev
;
14192 abbrev
= (struct abbrev_info
*)
14193 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
14194 memset (abbrev
, 0, sizeof (struct abbrev_info
));
14198 static struct die_info
*
14199 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
14201 struct die_info
*die
;
14202 size_t size
= sizeof (struct die_info
);
14205 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
14207 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
14208 memset (die
, 0, sizeof (struct die_info
));
14213 /* Macro support. */
14215 /* Return the full name of file number I in *LH's file name table.
14216 Use COMP_DIR as the name of the current directory of the
14217 compilation. The result is allocated using xmalloc; the caller is
14218 responsible for freeing it. */
14220 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
14222 /* Is the file number a valid index into the line header's file name
14223 table? Remember that file numbers start with one, not zero. */
14224 if (1 <= file
&& file
<= lh
->num_file_names
)
14226 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
14228 if (IS_ABSOLUTE_PATH (fe
->name
))
14229 return xstrdup (fe
->name
);
14237 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14243 dir_len
= strlen (dir
);
14244 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
14245 strcpy (full_name
, dir
);
14246 full_name
[dir_len
] = '/';
14247 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
14251 return xstrdup (fe
->name
);
14256 /* The compiler produced a bogus file number. We can at least
14257 record the macro definitions made in the file, even if we
14258 won't be able to find the file by name. */
14259 char fake_name
[80];
14261 sprintf (fake_name
, "<bad macro file number %d>", file
);
14263 complaint (&symfile_complaints
,
14264 _("bad file number in macro information (%d)"),
14267 return xstrdup (fake_name
);
14272 static struct macro_source_file
*
14273 macro_start_file (int file
, int line
,
14274 struct macro_source_file
*current_file
,
14275 const char *comp_dir
,
14276 struct line_header
*lh
, struct objfile
*objfile
)
14278 /* The full name of this source file. */
14279 char *full_name
= file_full_name (file
, lh
, comp_dir
);
14281 /* We don't create a macro table for this compilation unit
14282 at all until we actually get a filename. */
14283 if (! pending_macros
)
14284 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
14285 objfile
->macro_cache
);
14287 if (! current_file
)
14288 /* If we have no current file, then this must be the start_file
14289 directive for the compilation unit's main source file. */
14290 current_file
= macro_set_main (pending_macros
, full_name
);
14292 current_file
= macro_include (current_file
, line
, full_name
);
14296 return current_file
;
14300 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
14301 followed by a null byte. */
14303 copy_string (const char *buf
, int len
)
14305 char *s
= xmalloc (len
+ 1);
14307 memcpy (s
, buf
, len
);
14313 static const char *
14314 consume_improper_spaces (const char *p
, const char *body
)
14318 complaint (&symfile_complaints
,
14319 _("macro definition contains spaces "
14320 "in formal argument list:\n`%s'"),
14332 parse_macro_definition (struct macro_source_file
*file
, int line
,
14337 /* The body string takes one of two forms. For object-like macro
14338 definitions, it should be:
14340 <macro name> " " <definition>
14342 For function-like macro definitions, it should be:
14344 <macro name> "() " <definition>
14346 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
14348 Spaces may appear only where explicitly indicated, and in the
14351 The Dwarf 2 spec says that an object-like macro's name is always
14352 followed by a space, but versions of GCC around March 2002 omit
14353 the space when the macro's definition is the empty string.
14355 The Dwarf 2 spec says that there should be no spaces between the
14356 formal arguments in a function-like macro's formal argument list,
14357 but versions of GCC around March 2002 include spaces after the
14361 /* Find the extent of the macro name. The macro name is terminated
14362 by either a space or null character (for an object-like macro) or
14363 an opening paren (for a function-like macro). */
14364 for (p
= body
; *p
; p
++)
14365 if (*p
== ' ' || *p
== '(')
14368 if (*p
== ' ' || *p
== '\0')
14370 /* It's an object-like macro. */
14371 int name_len
= p
- body
;
14372 char *name
= copy_string (body
, name_len
);
14373 const char *replacement
;
14376 replacement
= body
+ name_len
+ 1;
14379 dwarf2_macro_malformed_definition_complaint (body
);
14380 replacement
= body
+ name_len
;
14383 macro_define_object (file
, line
, name
, replacement
);
14387 else if (*p
== '(')
14389 /* It's a function-like macro. */
14390 char *name
= copy_string (body
, p
- body
);
14393 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
14397 p
= consume_improper_spaces (p
, body
);
14399 /* Parse the formal argument list. */
14400 while (*p
&& *p
!= ')')
14402 /* Find the extent of the current argument name. */
14403 const char *arg_start
= p
;
14405 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
14408 if (! *p
|| p
== arg_start
)
14409 dwarf2_macro_malformed_definition_complaint (body
);
14412 /* Make sure argv has room for the new argument. */
14413 if (argc
>= argv_size
)
14416 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
14419 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
14422 p
= consume_improper_spaces (p
, body
);
14424 /* Consume the comma, if present. */
14429 p
= consume_improper_spaces (p
, body
);
14438 /* Perfectly formed definition, no complaints. */
14439 macro_define_function (file
, line
, name
,
14440 argc
, (const char **) argv
,
14442 else if (*p
== '\0')
14444 /* Complain, but do define it. */
14445 dwarf2_macro_malformed_definition_complaint (body
);
14446 macro_define_function (file
, line
, name
,
14447 argc
, (const char **) argv
,
14451 /* Just complain. */
14452 dwarf2_macro_malformed_definition_complaint (body
);
14455 /* Just complain. */
14456 dwarf2_macro_malformed_definition_complaint (body
);
14462 for (i
= 0; i
< argc
; i
++)
14468 dwarf2_macro_malformed_definition_complaint (body
);
14473 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
14474 char *comp_dir
, bfd
*abfd
,
14475 struct dwarf2_cu
*cu
)
14477 gdb_byte
*mac_ptr
, *mac_end
;
14478 struct macro_source_file
*current_file
= 0;
14479 enum dwarf_macinfo_record_type macinfo_type
;
14480 int at_commandline
;
14482 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
14483 &dwarf2_per_objfile
->macinfo
);
14484 if (dwarf2_per_objfile
->macinfo
.buffer
== NULL
)
14486 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
14490 /* First pass: Find the name of the base filename.
14491 This filename is needed in order to process all macros whose definition
14492 (or undefinition) comes from the command line. These macros are defined
14493 before the first DW_MACINFO_start_file entry, and yet still need to be
14494 associated to the base file.
14496 To determine the base file name, we scan the macro definitions until we
14497 reach the first DW_MACINFO_start_file entry. We then initialize
14498 CURRENT_FILE accordingly so that any macro definition found before the
14499 first DW_MACINFO_start_file can still be associated to the base file. */
14501 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
14502 mac_end
= dwarf2_per_objfile
->macinfo
.buffer
14503 + dwarf2_per_objfile
->macinfo
.size
;
14507 /* Do we at least have room for a macinfo type byte? */
14508 if (mac_ptr
>= mac_end
)
14510 /* Complaint is printed during the second pass as GDB will probably
14511 stop the first pass earlier upon finding
14512 DW_MACINFO_start_file. */
14516 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
14519 switch (macinfo_type
)
14521 /* A zero macinfo type indicates the end of the macro
14526 case DW_MACINFO_define
:
14527 case DW_MACINFO_undef
:
14528 /* Only skip the data by MAC_PTR. */
14530 unsigned int bytes_read
;
14532 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14533 mac_ptr
+= bytes_read
;
14534 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14535 mac_ptr
+= bytes_read
;
14539 case DW_MACINFO_start_file
:
14541 unsigned int bytes_read
;
14544 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14545 mac_ptr
+= bytes_read
;
14546 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14547 mac_ptr
+= bytes_read
;
14549 current_file
= macro_start_file (file
, line
, current_file
,
14550 comp_dir
, lh
, cu
->objfile
);
14554 case DW_MACINFO_end_file
:
14555 /* No data to skip by MAC_PTR. */
14558 case DW_MACINFO_vendor_ext
:
14559 /* Only skip the data by MAC_PTR. */
14561 unsigned int bytes_read
;
14563 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14564 mac_ptr
+= bytes_read
;
14565 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14566 mac_ptr
+= bytes_read
;
14573 } while (macinfo_type
!= 0 && current_file
== NULL
);
14575 /* Second pass: Process all entries.
14577 Use the AT_COMMAND_LINE flag to determine whether we are still processing
14578 command-line macro definitions/undefinitions. This flag is unset when we
14579 reach the first DW_MACINFO_start_file entry. */
14581 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
14583 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
14584 GDB is still reading the definitions from command line. First
14585 DW_MACINFO_start_file will need to be ignored as it was already executed
14586 to create CURRENT_FILE for the main source holding also the command line
14587 definitions. On first met DW_MACINFO_start_file this flag is reset to
14588 normally execute all the remaining DW_MACINFO_start_file macinfos. */
14590 at_commandline
= 1;
14594 /* Do we at least have room for a macinfo type byte? */
14595 if (mac_ptr
>= mac_end
)
14597 dwarf2_macros_too_long_complaint ();
14601 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
14604 switch (macinfo_type
)
14606 /* A zero macinfo type indicates the end of the macro
14611 case DW_MACINFO_define
:
14612 case DW_MACINFO_undef
:
14614 unsigned int bytes_read
;
14618 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14619 mac_ptr
+= bytes_read
;
14620 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14621 mac_ptr
+= bytes_read
;
14623 if (! current_file
)
14625 /* DWARF violation as no main source is present. */
14626 complaint (&symfile_complaints
,
14627 _("debug info with no main source gives macro %s "
14629 macinfo_type
== DW_MACINFO_define
?
14631 macinfo_type
== DW_MACINFO_undef
?
14632 _("undefinition") :
14633 _("something-or-other"), line
, body
);
14636 if ((line
== 0 && !at_commandline
)
14637 || (line
!= 0 && at_commandline
))
14638 complaint (&symfile_complaints
,
14639 _("debug info gives %s macro %s with %s line %d: %s"),
14640 at_commandline
? _("command-line") : _("in-file"),
14641 macinfo_type
== DW_MACINFO_define
?
14643 macinfo_type
== DW_MACINFO_undef
?
14644 _("undefinition") :
14645 _("something-or-other"),
14646 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
14648 if (macinfo_type
== DW_MACINFO_define
)
14649 parse_macro_definition (current_file
, line
, body
);
14650 else if (macinfo_type
== DW_MACINFO_undef
)
14651 macro_undef (current_file
, line
, body
);
14655 case DW_MACINFO_start_file
:
14657 unsigned int bytes_read
;
14660 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14661 mac_ptr
+= bytes_read
;
14662 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14663 mac_ptr
+= bytes_read
;
14665 if ((line
== 0 && !at_commandline
)
14666 || (line
!= 0 && at_commandline
))
14667 complaint (&symfile_complaints
,
14668 _("debug info gives source %d included "
14669 "from %s at %s line %d"),
14670 file
, at_commandline
? _("command-line") : _("file"),
14671 line
== 0 ? _("zero") : _("non-zero"), line
);
14673 if (at_commandline
)
14675 /* This DW_MACINFO_start_file was executed in the pass one. */
14676 at_commandline
= 0;
14679 current_file
= macro_start_file (file
, line
,
14680 current_file
, comp_dir
,
14685 case DW_MACINFO_end_file
:
14686 if (! current_file
)
14687 complaint (&symfile_complaints
,
14688 _("macro debug info has an unmatched "
14689 "`close_file' directive"));
14692 current_file
= current_file
->included_by
;
14693 if (! current_file
)
14695 enum dwarf_macinfo_record_type next_type
;
14697 /* GCC circa March 2002 doesn't produce the zero
14698 type byte marking the end of the compilation
14699 unit. Complain if it's not there, but exit no
14702 /* Do we at least have room for a macinfo type byte? */
14703 if (mac_ptr
>= mac_end
)
14705 dwarf2_macros_too_long_complaint ();
14709 /* We don't increment mac_ptr here, so this is just
14711 next_type
= read_1_byte (abfd
, mac_ptr
);
14712 if (next_type
!= 0)
14713 complaint (&symfile_complaints
,
14714 _("no terminating 0-type entry for "
14715 "macros in `.debug_macinfo' section"));
14722 case DW_MACINFO_vendor_ext
:
14724 unsigned int bytes_read
;
14727 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14728 mac_ptr
+= bytes_read
;
14729 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14730 mac_ptr
+= bytes_read
;
14732 /* We don't recognize any vendor extensions. */
14736 } while (macinfo_type
!= 0);
14739 /* Check if the attribute's form is a DW_FORM_block*
14740 if so return true else false. */
14742 attr_form_is_block (struct attribute
*attr
)
14744 return (attr
== NULL
? 0 :
14745 attr
->form
== DW_FORM_block1
14746 || attr
->form
== DW_FORM_block2
14747 || attr
->form
== DW_FORM_block4
14748 || attr
->form
== DW_FORM_block
14749 || attr
->form
== DW_FORM_exprloc
);
14752 /* Return non-zero if ATTR's value is a section offset --- classes
14753 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
14754 You may use DW_UNSND (attr) to retrieve such offsets.
14756 Section 7.5.4, "Attribute Encodings", explains that no attribute
14757 may have a value that belongs to more than one of these classes; it
14758 would be ambiguous if we did, because we use the same forms for all
14761 attr_form_is_section_offset (struct attribute
*attr
)
14763 return (attr
->form
== DW_FORM_data4
14764 || attr
->form
== DW_FORM_data8
14765 || attr
->form
== DW_FORM_sec_offset
);
14769 /* Return non-zero if ATTR's value falls in the 'constant' class, or
14770 zero otherwise. When this function returns true, you can apply
14771 dwarf2_get_attr_constant_value to it.
14773 However, note that for some attributes you must check
14774 attr_form_is_section_offset before using this test. DW_FORM_data4
14775 and DW_FORM_data8 are members of both the constant class, and of
14776 the classes that contain offsets into other debug sections
14777 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
14778 that, if an attribute's can be either a constant or one of the
14779 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
14780 taken as section offsets, not constants. */
14782 attr_form_is_constant (struct attribute
*attr
)
14784 switch (attr
->form
)
14786 case DW_FORM_sdata
:
14787 case DW_FORM_udata
:
14788 case DW_FORM_data1
:
14789 case DW_FORM_data2
:
14790 case DW_FORM_data4
:
14791 case DW_FORM_data8
:
14798 /* A helper function that fills in a dwarf2_loclist_baton. */
14801 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
14802 struct dwarf2_loclist_baton
*baton
,
14803 struct attribute
*attr
)
14805 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
14806 &dwarf2_per_objfile
->loc
);
14808 baton
->per_cu
= cu
->per_cu
;
14809 gdb_assert (baton
->per_cu
);
14810 /* We don't know how long the location list is, but make sure we
14811 don't run off the edge of the section. */
14812 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
14813 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
14814 baton
->base_address
= cu
->base_address
;
14818 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
14819 struct dwarf2_cu
*cu
)
14821 if (attr_form_is_section_offset (attr
)
14822 /* ".debug_loc" may not exist at all, or the offset may be outside
14823 the section. If so, fall through to the complaint in the
14825 && DW_UNSND (attr
) < dwarf2_section_size (dwarf2_per_objfile
->objfile
,
14826 &dwarf2_per_objfile
->loc
))
14828 struct dwarf2_loclist_baton
*baton
;
14830 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
14831 sizeof (struct dwarf2_loclist_baton
));
14833 fill_in_loclist_baton (cu
, baton
, attr
);
14835 if (cu
->base_known
== 0)
14836 complaint (&symfile_complaints
,
14837 _("Location list used without "
14838 "specifying the CU base address."));
14840 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
14841 SYMBOL_LOCATION_BATON (sym
) = baton
;
14845 struct dwarf2_locexpr_baton
*baton
;
14847 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
14848 sizeof (struct dwarf2_locexpr_baton
));
14849 baton
->per_cu
= cu
->per_cu
;
14850 gdb_assert (baton
->per_cu
);
14852 if (attr_form_is_block (attr
))
14854 /* Note that we're just copying the block's data pointer
14855 here, not the actual data. We're still pointing into the
14856 info_buffer for SYM's objfile; right now we never release
14857 that buffer, but when we do clean up properly this may
14859 baton
->size
= DW_BLOCK (attr
)->size
;
14860 baton
->data
= DW_BLOCK (attr
)->data
;
14864 dwarf2_invalid_attrib_class_complaint ("location description",
14865 SYMBOL_NATURAL_NAME (sym
));
14867 baton
->data
= NULL
;
14870 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
14871 SYMBOL_LOCATION_BATON (sym
) = baton
;
14875 /* Return the OBJFILE associated with the compilation unit CU. If CU
14876 came from a separate debuginfo file, then the master objfile is
14880 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
14882 struct objfile
*objfile
= per_cu
->objfile
;
14884 /* Return the master objfile, so that we can report and look up the
14885 correct file containing this variable. */
14886 if (objfile
->separate_debug_objfile_backlink
)
14887 objfile
= objfile
->separate_debug_objfile_backlink
;
14892 /* Return the address size given in the compilation unit header for CU. */
14895 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
14898 return per_cu
->cu
->header
.addr_size
;
14901 /* If the CU is not currently read in, we re-read its header. */
14902 struct objfile
*objfile
= per_cu
->objfile
;
14903 struct dwarf2_per_objfile
*per_objfile
14904 = objfile_data (objfile
, dwarf2_objfile_data_key
);
14905 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
14906 struct comp_unit_head cu_header
;
14908 memset (&cu_header
, 0, sizeof cu_header
);
14909 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
14910 return cu_header
.addr_size
;
14914 /* Return the offset size given in the compilation unit header for CU. */
14917 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
14920 return per_cu
->cu
->header
.offset_size
;
14923 /* If the CU is not currently read in, we re-read its header. */
14924 struct objfile
*objfile
= per_cu
->objfile
;
14925 struct dwarf2_per_objfile
*per_objfile
14926 = objfile_data (objfile
, dwarf2_objfile_data_key
);
14927 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
14928 struct comp_unit_head cu_header
;
14930 memset (&cu_header
, 0, sizeof cu_header
);
14931 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
14932 return cu_header
.offset_size
;
14936 /* Return the text offset of the CU. The returned offset comes from
14937 this CU's objfile. If this objfile came from a separate debuginfo
14938 file, then the offset may be different from the corresponding
14939 offset in the parent objfile. */
14942 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
14944 struct objfile
*objfile
= per_cu
->objfile
;
14946 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14949 /* Locate the .debug_info compilation unit from CU's objfile which contains
14950 the DIE at OFFSET. Raises an error on failure. */
14952 static struct dwarf2_per_cu_data
*
14953 dwarf2_find_containing_comp_unit (unsigned int offset
,
14954 struct objfile
*objfile
)
14956 struct dwarf2_per_cu_data
*this_cu
;
14960 high
= dwarf2_per_objfile
->n_comp_units
- 1;
14963 int mid
= low
+ (high
- low
) / 2;
14965 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
14970 gdb_assert (low
== high
);
14971 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
14974 error (_("Dwarf Error: could not find partial DIE containing "
14975 "offset 0x%lx [in module %s]"),
14976 (long) offset
, bfd_get_filename (objfile
->obfd
));
14978 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
14979 return dwarf2_per_objfile
->all_comp_units
[low
-1];
14983 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
14984 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
14985 && offset
>= this_cu
->offset
+ this_cu
->length
)
14986 error (_("invalid dwarf2 offset %u"), offset
);
14987 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
14992 /* Locate the compilation unit from OBJFILE which is located at exactly
14993 OFFSET. Raises an error on failure. */
14995 static struct dwarf2_per_cu_data
*
14996 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
14998 struct dwarf2_per_cu_data
*this_cu
;
15000 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
15001 if (this_cu
->offset
!= offset
)
15002 error (_("no compilation unit with offset %u."), offset
);
15006 /* Initialize dwarf2_cu CU for OBJFILE in a pre-allocated space. */
15009 init_one_comp_unit (struct dwarf2_cu
*cu
, struct objfile
*objfile
)
15011 memset (cu
, 0, sizeof (*cu
));
15012 cu
->objfile
= objfile
;
15013 obstack_init (&cu
->comp_unit_obstack
);
15016 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
15019 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
)
15021 struct attribute
*attr
;
15023 /* Set the language we're debugging. */
15024 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
15026 set_cu_language (DW_UNSND (attr
), cu
);
15029 cu
->language
= language_minimal
;
15030 cu
->language_defn
= language_def (cu
->language
);
15034 /* Release one cached compilation unit, CU. We unlink it from the tree
15035 of compilation units, but we don't remove it from the read_in_chain;
15036 the caller is responsible for that.
15037 NOTE: DATA is a void * because this function is also used as a
15038 cleanup routine. */
15041 free_one_comp_unit (void *data
)
15043 struct dwarf2_cu
*cu
= data
;
15045 if (cu
->per_cu
!= NULL
)
15046 cu
->per_cu
->cu
= NULL
;
15049 obstack_free (&cu
->comp_unit_obstack
, NULL
);
15054 /* This cleanup function is passed the address of a dwarf2_cu on the stack
15055 when we're finished with it. We can't free the pointer itself, but be
15056 sure to unlink it from the cache. Also release any associated storage
15057 and perform cache maintenance.
15059 Only used during partial symbol parsing. */
15062 free_stack_comp_unit (void *data
)
15064 struct dwarf2_cu
*cu
= data
;
15066 obstack_free (&cu
->comp_unit_obstack
, NULL
);
15067 cu
->partial_dies
= NULL
;
15069 if (cu
->per_cu
!= NULL
)
15071 /* This compilation unit is on the stack in our caller, so we
15072 should not xfree it. Just unlink it. */
15073 cu
->per_cu
->cu
= NULL
;
15076 /* If we had a per-cu pointer, then we may have other compilation
15077 units loaded, so age them now. */
15078 age_cached_comp_units ();
15082 /* Free all cached compilation units. */
15085 free_cached_comp_units (void *data
)
15087 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15089 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15090 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15091 while (per_cu
!= NULL
)
15093 struct dwarf2_per_cu_data
*next_cu
;
15095 next_cu
= per_cu
->cu
->read_in_chain
;
15097 free_one_comp_unit (per_cu
->cu
);
15098 *last_chain
= next_cu
;
15104 /* Increase the age counter on each cached compilation unit, and free
15105 any that are too old. */
15108 age_cached_comp_units (void)
15110 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15112 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
15113 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15114 while (per_cu
!= NULL
)
15116 per_cu
->cu
->last_used
++;
15117 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
15118 dwarf2_mark (per_cu
->cu
);
15119 per_cu
= per_cu
->cu
->read_in_chain
;
15122 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15123 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15124 while (per_cu
!= NULL
)
15126 struct dwarf2_per_cu_data
*next_cu
;
15128 next_cu
= per_cu
->cu
->read_in_chain
;
15130 if (!per_cu
->cu
->mark
)
15132 free_one_comp_unit (per_cu
->cu
);
15133 *last_chain
= next_cu
;
15136 last_chain
= &per_cu
->cu
->read_in_chain
;
15142 /* Remove a single compilation unit from the cache. */
15145 free_one_cached_comp_unit (void *target_cu
)
15147 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
15149 per_cu
= dwarf2_per_objfile
->read_in_chain
;
15150 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
15151 while (per_cu
!= NULL
)
15153 struct dwarf2_per_cu_data
*next_cu
;
15155 next_cu
= per_cu
->cu
->read_in_chain
;
15157 if (per_cu
->cu
== target_cu
)
15159 free_one_comp_unit (per_cu
->cu
);
15160 *last_chain
= next_cu
;
15164 last_chain
= &per_cu
->cu
->read_in_chain
;
15170 /* Release all extra memory associated with OBJFILE. */
15173 dwarf2_free_objfile (struct objfile
*objfile
)
15175 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
15177 if (dwarf2_per_objfile
== NULL
)
15180 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
15181 free_cached_comp_units (NULL
);
15183 if (dwarf2_per_objfile
->quick_file_names_table
)
15184 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
15186 /* Everything else should be on the objfile obstack. */
15189 /* A pair of DIE offset and GDB type pointer. We store these
15190 in a hash table separate from the DIEs, and preserve them
15191 when the DIEs are flushed out of cache. */
15193 struct dwarf2_offset_and_type
15195 unsigned int offset
;
15199 /* Hash function for a dwarf2_offset_and_type. */
15202 offset_and_type_hash (const void *item
)
15204 const struct dwarf2_offset_and_type
*ofs
= item
;
15206 return ofs
->offset
;
15209 /* Equality function for a dwarf2_offset_and_type. */
15212 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
15214 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
15215 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
15217 return ofs_lhs
->offset
== ofs_rhs
->offset
;
15220 /* Set the type associated with DIE to TYPE. Save it in CU's hash
15221 table if necessary. For convenience, return TYPE.
15223 The DIEs reading must have careful ordering to:
15224 * Not cause infite loops trying to read in DIEs as a prerequisite for
15225 reading current DIE.
15226 * Not trying to dereference contents of still incompletely read in types
15227 while reading in other DIEs.
15228 * Enable referencing still incompletely read in types just by a pointer to
15229 the type without accessing its fields.
15231 Therefore caller should follow these rules:
15232 * Try to fetch any prerequisite types we may need to build this DIE type
15233 before building the type and calling set_die_type.
15234 * After building type call set_die_type for current DIE as soon as
15235 possible before fetching more types to complete the current type.
15236 * Make the type as complete as possible before fetching more types. */
15238 static struct type
*
15239 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
15241 struct dwarf2_offset_and_type
**slot
, ofs
;
15242 struct objfile
*objfile
= cu
->objfile
;
15243 htab_t
*type_hash_ptr
;
15245 /* For Ada types, make sure that the gnat-specific data is always
15246 initialized (if not already set). There are a few types where
15247 we should not be doing so, because the type-specific area is
15248 already used to hold some other piece of info (eg: TYPE_CODE_FLT
15249 where the type-specific area is used to store the floatformat).
15250 But this is not a problem, because the gnat-specific information
15251 is actually not needed for these types. */
15252 if (need_gnat_info (cu
)
15253 && TYPE_CODE (type
) != TYPE_CODE_FUNC
15254 && TYPE_CODE (type
) != TYPE_CODE_FLT
15255 && !HAVE_GNAT_AUX_INFO (type
))
15256 INIT_GNAT_SPECIFIC (type
);
15258 if (cu
->per_cu
->from_debug_types
)
15259 type_hash_ptr
= &dwarf2_per_objfile
->debug_types_type_hash
;
15261 type_hash_ptr
= &dwarf2_per_objfile
->debug_info_type_hash
;
15263 if (*type_hash_ptr
== NULL
)
15266 = htab_create_alloc_ex (127,
15267 offset_and_type_hash
,
15268 offset_and_type_eq
,
15270 &objfile
->objfile_obstack
,
15271 hashtab_obstack_allocate
,
15272 dummy_obstack_deallocate
);
15275 ofs
.offset
= die
->offset
;
15277 slot
= (struct dwarf2_offset_and_type
**)
15278 htab_find_slot_with_hash (*type_hash_ptr
, &ofs
, ofs
.offset
, INSERT
);
15280 complaint (&symfile_complaints
,
15281 _("A problem internal to GDB: DIE 0x%x has type already set"),
15283 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
15288 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
15289 table, or return NULL if the die does not have a saved type. */
15291 static struct type
*
15292 get_die_type_at_offset (unsigned int offset
,
15293 struct dwarf2_per_cu_data
*per_cu
)
15295 struct dwarf2_offset_and_type
*slot
, ofs
;
15298 if (per_cu
->from_debug_types
)
15299 type_hash
= dwarf2_per_objfile
->debug_types_type_hash
;
15301 type_hash
= dwarf2_per_objfile
->debug_info_type_hash
;
15302 if (type_hash
== NULL
)
15305 ofs
.offset
= offset
;
15306 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
15313 /* Look up the type for DIE in the appropriate type_hash table,
15314 or return NULL if DIE does not have a saved type. */
15316 static struct type
*
15317 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15319 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
15322 /* Add a dependence relationship from CU to REF_PER_CU. */
15325 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
15326 struct dwarf2_per_cu_data
*ref_per_cu
)
15330 if (cu
->dependencies
== NULL
)
15332 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
15333 NULL
, &cu
->comp_unit_obstack
,
15334 hashtab_obstack_allocate
,
15335 dummy_obstack_deallocate
);
15337 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
15339 *slot
= ref_per_cu
;
15342 /* Subroutine of dwarf2_mark to pass to htab_traverse.
15343 Set the mark field in every compilation unit in the
15344 cache that we must keep because we are keeping CU. */
15347 dwarf2_mark_helper (void **slot
, void *data
)
15349 struct dwarf2_per_cu_data
*per_cu
;
15351 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
15352 if (per_cu
->cu
->mark
)
15354 per_cu
->cu
->mark
= 1;
15356 if (per_cu
->cu
->dependencies
!= NULL
)
15357 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
15362 /* Set the mark field in CU and in every other compilation unit in the
15363 cache that we must keep because we are keeping CU. */
15366 dwarf2_mark (struct dwarf2_cu
*cu
)
15371 if (cu
->dependencies
!= NULL
)
15372 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
15376 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
15380 per_cu
->cu
->mark
= 0;
15381 per_cu
= per_cu
->cu
->read_in_chain
;
15385 /* Trivial hash function for partial_die_info: the hash value of a DIE
15386 is its offset in .debug_info for this objfile. */
15389 partial_die_hash (const void *item
)
15391 const struct partial_die_info
*part_die
= item
;
15393 return part_die
->offset
;
15396 /* Trivial comparison function for partial_die_info structures: two DIEs
15397 are equal if they have the same offset. */
15400 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
15402 const struct partial_die_info
*part_die_lhs
= item_lhs
;
15403 const struct partial_die_info
*part_die_rhs
= item_rhs
;
15405 return part_die_lhs
->offset
== part_die_rhs
->offset
;
15408 static struct cmd_list_element
*set_dwarf2_cmdlist
;
15409 static struct cmd_list_element
*show_dwarf2_cmdlist
;
15412 set_dwarf2_cmd (char *args
, int from_tty
)
15414 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
15418 show_dwarf2_cmd (char *args
, int from_tty
)
15420 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
15423 /* If section described by INFO was mmapped, munmap it now. */
15426 munmap_section_buffer (struct dwarf2_section_info
*info
)
15428 if (info
->map_addr
!= NULL
)
15433 res
= munmap (info
->map_addr
, info
->map_len
);
15434 gdb_assert (res
== 0);
15436 /* Without HAVE_MMAP, we should never be here to begin with. */
15437 gdb_assert_not_reached ("no mmap support");
15442 /* munmap debug sections for OBJFILE, if necessary. */
15445 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
15447 struct dwarf2_per_objfile
*data
= d
;
15449 /* This is sorted according to the order they're defined in to make it easier
15450 to keep in sync. */
15451 munmap_section_buffer (&data
->info
);
15452 munmap_section_buffer (&data
->abbrev
);
15453 munmap_section_buffer (&data
->line
);
15454 munmap_section_buffer (&data
->loc
);
15455 munmap_section_buffer (&data
->macinfo
);
15456 munmap_section_buffer (&data
->str
);
15457 munmap_section_buffer (&data
->ranges
);
15458 munmap_section_buffer (&data
->types
);
15459 munmap_section_buffer (&data
->frame
);
15460 munmap_section_buffer (&data
->eh_frame
);
15461 munmap_section_buffer (&data
->gdb_index
);
15465 /* The "save gdb-index" command. */
15467 /* The contents of the hash table we create when building the string
15469 struct strtab_entry
15471 offset_type offset
;
15475 /* Hash function for a strtab_entry.
15477 Function is used only during write_hash_table so no index format backward
15478 compatibility is needed. */
15481 hash_strtab_entry (const void *e
)
15483 const struct strtab_entry
*entry
= e
;
15484 return mapped_index_string_hash (INT_MAX
, entry
->str
);
15487 /* Equality function for a strtab_entry. */
15490 eq_strtab_entry (const void *a
, const void *b
)
15492 const struct strtab_entry
*ea
= a
;
15493 const struct strtab_entry
*eb
= b
;
15494 return !strcmp (ea
->str
, eb
->str
);
15497 /* Create a strtab_entry hash table. */
15500 create_strtab (void)
15502 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
15503 xfree
, xcalloc
, xfree
);
15506 /* Add a string to the constant pool. Return the string's offset in
15510 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
15513 struct strtab_entry entry
;
15514 struct strtab_entry
*result
;
15517 slot
= htab_find_slot (table
, &entry
, INSERT
);
15522 result
= XNEW (struct strtab_entry
);
15523 result
->offset
= obstack_object_size (cpool
);
15525 obstack_grow_str0 (cpool
, str
);
15528 return result
->offset
;
15531 /* An entry in the symbol table. */
15532 struct symtab_index_entry
15534 /* The name of the symbol. */
15536 /* The offset of the name in the constant pool. */
15537 offset_type index_offset
;
15538 /* A sorted vector of the indices of all the CUs that hold an object
15540 VEC (offset_type
) *cu_indices
;
15543 /* The symbol table. This is a power-of-2-sized hash table. */
15544 struct mapped_symtab
15546 offset_type n_elements
;
15548 struct symtab_index_entry
**data
;
15551 /* Hash function for a symtab_index_entry. */
15554 hash_symtab_entry (const void *e
)
15556 const struct symtab_index_entry
*entry
= e
;
15557 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
15558 sizeof (offset_type
) * VEC_length (offset_type
,
15559 entry
->cu_indices
),
15563 /* Equality function for a symtab_index_entry. */
15566 eq_symtab_entry (const void *a
, const void *b
)
15568 const struct symtab_index_entry
*ea
= a
;
15569 const struct symtab_index_entry
*eb
= b
;
15570 int len
= VEC_length (offset_type
, ea
->cu_indices
);
15571 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
15573 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
15574 VEC_address (offset_type
, eb
->cu_indices
),
15575 sizeof (offset_type
) * len
);
15578 /* Destroy a symtab_index_entry. */
15581 delete_symtab_entry (void *p
)
15583 struct symtab_index_entry
*entry
= p
;
15584 VEC_free (offset_type
, entry
->cu_indices
);
15588 /* Create a hash table holding symtab_index_entry objects. */
15591 create_symbol_hash_table (void)
15593 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
15594 delete_symtab_entry
, xcalloc
, xfree
);
15597 /* Create a new mapped symtab object. */
15599 static struct mapped_symtab
*
15600 create_mapped_symtab (void)
15602 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
15603 symtab
->n_elements
= 0;
15604 symtab
->size
= 1024;
15605 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
15609 /* Destroy a mapped_symtab. */
15612 cleanup_mapped_symtab (void *p
)
15614 struct mapped_symtab
*symtab
= p
;
15615 /* The contents of the array are freed when the other hash table is
15617 xfree (symtab
->data
);
15621 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
15624 Function is used only during write_hash_table so no index format backward
15625 compatibility is needed. */
15627 static struct symtab_index_entry
**
15628 find_slot (struct mapped_symtab
*symtab
, const char *name
)
15630 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
15632 index
= hash
& (symtab
->size
- 1);
15633 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
15637 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
15638 return &symtab
->data
[index
];
15639 index
= (index
+ step
) & (symtab
->size
- 1);
15643 /* Expand SYMTAB's hash table. */
15646 hash_expand (struct mapped_symtab
*symtab
)
15648 offset_type old_size
= symtab
->size
;
15650 struct symtab_index_entry
**old_entries
= symtab
->data
;
15653 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
15655 for (i
= 0; i
< old_size
; ++i
)
15657 if (old_entries
[i
])
15659 struct symtab_index_entry
**slot
= find_slot (symtab
,
15660 old_entries
[i
]->name
);
15661 *slot
= old_entries
[i
];
15665 xfree (old_entries
);
15668 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
15669 is the index of the CU in which the symbol appears. */
15672 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
15673 offset_type cu_index
)
15675 struct symtab_index_entry
**slot
;
15677 ++symtab
->n_elements
;
15678 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
15679 hash_expand (symtab
);
15681 slot
= find_slot (symtab
, name
);
15684 *slot
= XNEW (struct symtab_index_entry
);
15685 (*slot
)->name
= name
;
15686 (*slot
)->cu_indices
= NULL
;
15688 /* Don't push an index twice. Due to how we add entries we only
15689 have to check the last one. */
15690 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
15691 || VEC_last (offset_type
, (*slot
)->cu_indices
) != cu_index
)
15692 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
15695 /* Add a vector of indices to the constant pool. */
15698 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
15699 struct symtab_index_entry
*entry
)
15703 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
15706 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
15707 offset_type val
= MAYBE_SWAP (len
);
15712 entry
->index_offset
= obstack_object_size (cpool
);
15714 obstack_grow (cpool
, &val
, sizeof (val
));
15716 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
15719 val
= MAYBE_SWAP (iter
);
15720 obstack_grow (cpool
, &val
, sizeof (val
));
15725 struct symtab_index_entry
*old_entry
= *slot
;
15726 entry
->index_offset
= old_entry
->index_offset
;
15729 return entry
->index_offset
;
15732 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
15733 constant pool entries going into the obstack CPOOL. */
15736 write_hash_table (struct mapped_symtab
*symtab
,
15737 struct obstack
*output
, struct obstack
*cpool
)
15740 htab_t symbol_hash_table
;
15743 symbol_hash_table
= create_symbol_hash_table ();
15744 str_table
= create_strtab ();
15746 /* We add all the index vectors to the constant pool first, to
15747 ensure alignment is ok. */
15748 for (i
= 0; i
< symtab
->size
; ++i
)
15750 if (symtab
->data
[i
])
15751 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
15754 /* Now write out the hash table. */
15755 for (i
= 0; i
< symtab
->size
; ++i
)
15757 offset_type str_off
, vec_off
;
15759 if (symtab
->data
[i
])
15761 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
15762 vec_off
= symtab
->data
[i
]->index_offset
;
15766 /* While 0 is a valid constant pool index, it is not valid
15767 to have 0 for both offsets. */
15772 str_off
= MAYBE_SWAP (str_off
);
15773 vec_off
= MAYBE_SWAP (vec_off
);
15775 obstack_grow (output
, &str_off
, sizeof (str_off
));
15776 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
15779 htab_delete (str_table
);
15780 htab_delete (symbol_hash_table
);
15783 /* Struct to map psymtab to CU index in the index file. */
15784 struct psymtab_cu_index_map
15786 struct partial_symtab
*psymtab
;
15787 unsigned int cu_index
;
15791 hash_psymtab_cu_index (const void *item
)
15793 const struct psymtab_cu_index_map
*map
= item
;
15795 return htab_hash_pointer (map
->psymtab
);
15799 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
15801 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
15802 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
15804 return lhs
->psymtab
== rhs
->psymtab
;
15807 /* Helper struct for building the address table. */
15808 struct addrmap_index_data
15810 struct objfile
*objfile
;
15811 struct obstack
*addr_obstack
;
15812 htab_t cu_index_htab
;
15814 /* Non-zero if the previous_* fields are valid.
15815 We can't write an entry until we see the next entry (since it is only then
15816 that we know the end of the entry). */
15817 int previous_valid
;
15818 /* Index of the CU in the table of all CUs in the index file. */
15819 unsigned int previous_cu_index
;
15820 /* Start address of the CU. */
15821 CORE_ADDR previous_cu_start
;
15824 /* Write an address entry to OBSTACK. */
15827 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
15828 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
15830 offset_type cu_index_to_write
;
15832 CORE_ADDR baseaddr
;
15834 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15836 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
15837 obstack_grow (obstack
, addr
, 8);
15838 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
15839 obstack_grow (obstack
, addr
, 8);
15840 cu_index_to_write
= MAYBE_SWAP (cu_index
);
15841 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
15844 /* Worker function for traversing an addrmap to build the address table. */
15847 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
15849 struct addrmap_index_data
*data
= datap
;
15850 struct partial_symtab
*pst
= obj
;
15851 offset_type cu_index
;
15854 if (data
->previous_valid
)
15855 add_address_entry (data
->objfile
, data
->addr_obstack
,
15856 data
->previous_cu_start
, start_addr
,
15857 data
->previous_cu_index
);
15859 data
->previous_cu_start
= start_addr
;
15862 struct psymtab_cu_index_map find_map
, *map
;
15863 find_map
.psymtab
= pst
;
15864 map
= htab_find (data
->cu_index_htab
, &find_map
);
15865 gdb_assert (map
!= NULL
);
15866 data
->previous_cu_index
= map
->cu_index
;
15867 data
->previous_valid
= 1;
15870 data
->previous_valid
= 0;
15875 /* Write OBJFILE's address map to OBSTACK.
15876 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
15877 in the index file. */
15880 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
15881 htab_t cu_index_htab
)
15883 struct addrmap_index_data addrmap_index_data
;
15885 /* When writing the address table, we have to cope with the fact that
15886 the addrmap iterator only provides the start of a region; we have to
15887 wait until the next invocation to get the start of the next region. */
15889 addrmap_index_data
.objfile
= objfile
;
15890 addrmap_index_data
.addr_obstack
= obstack
;
15891 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
15892 addrmap_index_data
.previous_valid
= 0;
15894 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
15895 &addrmap_index_data
);
15897 /* It's highly unlikely the last entry (end address = 0xff...ff)
15898 is valid, but we should still handle it.
15899 The end address is recorded as the start of the next region, but that
15900 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
15902 if (addrmap_index_data
.previous_valid
)
15903 add_address_entry (objfile
, obstack
,
15904 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
15905 addrmap_index_data
.previous_cu_index
);
15908 /* Add a list of partial symbols to SYMTAB. */
15911 write_psymbols (struct mapped_symtab
*symtab
,
15913 struct partial_symbol
**psymp
,
15915 offset_type cu_index
,
15918 for (; count
-- > 0; ++psymp
)
15920 void **slot
, *lookup
;
15922 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
15923 error (_("Ada is not currently supported by the index"));
15925 /* We only want to add a given psymbol once. However, we also
15926 want to account for whether it is global or static. So, we
15927 may add it twice, using slightly different values. */
15930 uintptr_t val
= 1 | (uintptr_t) *psymp
;
15932 lookup
= (void *) val
;
15937 /* Only add a given psymbol once. */
15938 slot
= htab_find_slot (psyms_seen
, lookup
, INSERT
);
15942 add_index_entry (symtab
, SYMBOL_NATURAL_NAME (*psymp
), cu_index
);
15947 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
15948 exception if there is an error. */
15951 write_obstack (FILE *file
, struct obstack
*obstack
)
15953 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
15955 != obstack_object_size (obstack
))
15956 error (_("couldn't data write to file"));
15959 /* Unlink a file if the argument is not NULL. */
15962 unlink_if_set (void *p
)
15964 char **filename
= p
;
15966 unlink (*filename
);
15969 /* A helper struct used when iterating over debug_types. */
15970 struct signatured_type_index_data
15972 struct objfile
*objfile
;
15973 struct mapped_symtab
*symtab
;
15974 struct obstack
*types_list
;
15979 /* A helper function that writes a single signatured_type to an
15983 write_one_signatured_type (void **slot
, void *d
)
15985 struct signatured_type_index_data
*info
= d
;
15986 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
15987 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
15988 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
15991 write_psymbols (info
->symtab
,
15993 info
->objfile
->global_psymbols
.list
15994 + psymtab
->globals_offset
,
15995 psymtab
->n_global_syms
, info
->cu_index
,
15997 write_psymbols (info
->symtab
,
15999 info
->objfile
->static_psymbols
.list
16000 + psymtab
->statics_offset
,
16001 psymtab
->n_static_syms
, info
->cu_index
,
16004 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->per_cu
.offset
);
16005 obstack_grow (info
->types_list
, val
, 8);
16006 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->type_offset
);
16007 obstack_grow (info
->types_list
, val
, 8);
16008 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
16009 obstack_grow (info
->types_list
, val
, 8);
16016 /* A cleanup function for an htab_t. */
16019 cleanup_htab (void *arg
)
16024 /* Create an index file for OBJFILE in the directory DIR. */
16027 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
16029 struct cleanup
*cleanup
;
16030 char *filename
, *cleanup_filename
;
16031 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
16032 struct obstack cu_list
, types_cu_list
;
16035 struct mapped_symtab
*symtab
;
16036 offset_type val
, size_of_contents
, total_len
;
16040 htab_t cu_index_htab
;
16041 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
16043 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
16046 if (dwarf2_per_objfile
->using_index
)
16047 error (_("Cannot use an index to create the index"));
16049 if (stat (objfile
->name
, &st
) < 0)
16050 perror_with_name (objfile
->name
);
16052 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
16053 INDEX_SUFFIX
, (char *) NULL
);
16054 cleanup
= make_cleanup (xfree
, filename
);
16056 out_file
= fopen (filename
, "wb");
16058 error (_("Can't open `%s' for writing"), filename
);
16060 cleanup_filename
= filename
;
16061 make_cleanup (unlink_if_set
, &cleanup_filename
);
16063 symtab
= create_mapped_symtab ();
16064 make_cleanup (cleanup_mapped_symtab
, symtab
);
16066 obstack_init (&addr_obstack
);
16067 make_cleanup_obstack_free (&addr_obstack
);
16069 obstack_init (&cu_list
);
16070 make_cleanup_obstack_free (&cu_list
);
16072 obstack_init (&types_cu_list
);
16073 make_cleanup_obstack_free (&types_cu_list
);
16075 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
16076 NULL
, xcalloc
, xfree
);
16077 make_cleanup (cleanup_htab
, psyms_seen
);
16079 /* While we're scanning CU's create a table that maps a psymtab pointer
16080 (which is what addrmap records) to its index (which is what is recorded
16081 in the index file). This will later be needed to write the address
16083 cu_index_htab
= htab_create_alloc (100,
16084 hash_psymtab_cu_index
,
16085 eq_psymtab_cu_index
,
16086 NULL
, xcalloc
, xfree
);
16087 make_cleanup (cleanup_htab
, cu_index_htab
);
16088 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
16089 xmalloc (sizeof (struct psymtab_cu_index_map
)
16090 * dwarf2_per_objfile
->n_comp_units
);
16091 make_cleanup (xfree
, psymtab_cu_index_map
);
16093 /* The CU list is already sorted, so we don't need to do additional
16094 work here. Also, the debug_types entries do not appear in
16095 all_comp_units, but only in their own hash table. */
16096 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
16098 struct dwarf2_per_cu_data
*per_cu
16099 = dwarf2_per_objfile
->all_comp_units
[i
];
16100 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
16102 struct psymtab_cu_index_map
*map
;
16105 write_psymbols (symtab
,
16107 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
16108 psymtab
->n_global_syms
, i
,
16110 write_psymbols (symtab
,
16112 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
16113 psymtab
->n_static_syms
, i
,
16116 map
= &psymtab_cu_index_map
[i
];
16117 map
->psymtab
= psymtab
;
16119 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
16120 gdb_assert (slot
!= NULL
);
16121 gdb_assert (*slot
== NULL
);
16124 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->offset
);
16125 obstack_grow (&cu_list
, val
, 8);
16126 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
16127 obstack_grow (&cu_list
, val
, 8);
16130 /* Dump the address map. */
16131 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
16133 /* Write out the .debug_type entries, if any. */
16134 if (dwarf2_per_objfile
->signatured_types
)
16136 struct signatured_type_index_data sig_data
;
16138 sig_data
.objfile
= objfile
;
16139 sig_data
.symtab
= symtab
;
16140 sig_data
.types_list
= &types_cu_list
;
16141 sig_data
.psyms_seen
= psyms_seen
;
16142 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
16143 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
16144 write_one_signatured_type
, &sig_data
);
16147 obstack_init (&constant_pool
);
16148 make_cleanup_obstack_free (&constant_pool
);
16149 obstack_init (&symtab_obstack
);
16150 make_cleanup_obstack_free (&symtab_obstack
);
16151 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
16153 obstack_init (&contents
);
16154 make_cleanup_obstack_free (&contents
);
16155 size_of_contents
= 6 * sizeof (offset_type
);
16156 total_len
= size_of_contents
;
16158 /* The version number. */
16159 val
= MAYBE_SWAP (5);
16160 obstack_grow (&contents
, &val
, sizeof (val
));
16162 /* The offset of the CU list from the start of the file. */
16163 val
= MAYBE_SWAP (total_len
);
16164 obstack_grow (&contents
, &val
, sizeof (val
));
16165 total_len
+= obstack_object_size (&cu_list
);
16167 /* The offset of the types CU list from the start of the file. */
16168 val
= MAYBE_SWAP (total_len
);
16169 obstack_grow (&contents
, &val
, sizeof (val
));
16170 total_len
+= obstack_object_size (&types_cu_list
);
16172 /* The offset of the address table from the start of the file. */
16173 val
= MAYBE_SWAP (total_len
);
16174 obstack_grow (&contents
, &val
, sizeof (val
));
16175 total_len
+= obstack_object_size (&addr_obstack
);
16177 /* The offset of the symbol table from the start of the file. */
16178 val
= MAYBE_SWAP (total_len
);
16179 obstack_grow (&contents
, &val
, sizeof (val
));
16180 total_len
+= obstack_object_size (&symtab_obstack
);
16182 /* The offset of the constant pool from the start of the file. */
16183 val
= MAYBE_SWAP (total_len
);
16184 obstack_grow (&contents
, &val
, sizeof (val
));
16185 total_len
+= obstack_object_size (&constant_pool
);
16187 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
16189 write_obstack (out_file
, &contents
);
16190 write_obstack (out_file
, &cu_list
);
16191 write_obstack (out_file
, &types_cu_list
);
16192 write_obstack (out_file
, &addr_obstack
);
16193 write_obstack (out_file
, &symtab_obstack
);
16194 write_obstack (out_file
, &constant_pool
);
16198 /* We want to keep the file, so we set cleanup_filename to NULL
16199 here. See unlink_if_set. */
16200 cleanup_filename
= NULL
;
16202 do_cleanups (cleanup
);
16205 /* Implementation of the `save gdb-index' command.
16207 Note that the file format used by this command is documented in the
16208 GDB manual. Any changes here must be documented there. */
16211 save_gdb_index_command (char *arg
, int from_tty
)
16213 struct objfile
*objfile
;
16216 error (_("usage: save gdb-index DIRECTORY"));
16218 ALL_OBJFILES (objfile
)
16222 /* If the objfile does not correspond to an actual file, skip it. */
16223 if (stat (objfile
->name
, &st
) < 0)
16226 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
16227 if (dwarf2_per_objfile
)
16229 volatile struct gdb_exception except
;
16231 TRY_CATCH (except
, RETURN_MASK_ERROR
)
16233 write_psymtabs_to_index (objfile
, arg
);
16235 if (except
.reason
< 0)
16236 exception_fprintf (gdb_stderr
, except
,
16237 _("Error while writing index for `%s': "),
16245 int dwarf2_always_disassemble
;
16248 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
16249 struct cmd_list_element
*c
, const char *value
)
16251 fprintf_filtered (file
,
16252 _("Whether to always disassemble "
16253 "DWARF expressions is %s.\n"),
16257 void _initialize_dwarf2_read (void);
16260 _initialize_dwarf2_read (void)
16262 struct cmd_list_element
*c
;
16264 dwarf2_objfile_data_key
16265 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
16267 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
16268 Set DWARF 2 specific variables.\n\
16269 Configure DWARF 2 variables such as the cache size"),
16270 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
16271 0/*allow-unknown*/, &maintenance_set_cmdlist
);
16273 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
16274 Show DWARF 2 specific variables\n\
16275 Show DWARF 2 variables such as the cache size"),
16276 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
16277 0/*allow-unknown*/, &maintenance_show_cmdlist
);
16279 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
16280 &dwarf2_max_cache_age
, _("\
16281 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
16282 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
16283 A higher limit means that cached compilation units will be stored\n\
16284 in memory longer, and more total memory will be used. Zero disables\n\
16285 caching, which can slow down startup."),
16287 show_dwarf2_max_cache_age
,
16288 &set_dwarf2_cmdlist
,
16289 &show_dwarf2_cmdlist
);
16291 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
16292 &dwarf2_always_disassemble
, _("\
16293 Set whether `info address' always disassembles DWARF expressions."), _("\
16294 Show whether `info address' always disassembles DWARF expressions."), _("\
16295 When enabled, DWARF expressions are always printed in an assembly-like\n\
16296 syntax. When disabled, expressions will be printed in a more\n\
16297 conversational style, when possible."),
16299 show_dwarf2_always_disassemble
,
16300 &set_dwarf2_cmdlist
,
16301 &show_dwarf2_cmdlist
);
16303 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
16304 Set debugging of the dwarf2 DIE reader."), _("\
16305 Show debugging of the dwarf2 DIE reader."), _("\
16306 When enabled (non-zero), DIEs are dumped after they are read in.\n\
16307 The value is the maximum depth to print."),
16310 &setdebuglist
, &showdebuglist
);
16312 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
16314 Save a gdb-index file.\n\
16315 Usage: save gdb-index DIRECTORY"),
16317 set_cmd_completer (c
, filename_completer
);